Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot draw an element whose fill is a Surface object #14

Open
PMende opened this issue Feb 19, 2015 · 3 comments
Open

Cannot draw an element whose fill is a Surface object #14

PMende opened this issue Feb 19, 2015 · 3 comments

Comments

@PMende
Copy link
Contributor

PMende commented Feb 19, 2015

I've been trying to make instances of surfaces for drawing onto other surfaces (I want to make drawings piecewise, then assemble the whole thing in a modular fashion). However, when I fill a rectangle (for example) with a surface, then attempt to draw that rectangle, I get an error.

Here's my test script:

import gizeh as gz

w,h =256,256
surface_a = gz.Surface(width=w, height=h, bg_color=(1,0,0))
surface_b = gz.Surface(width=w, height=h, bg_color=(1,1,0))

rect = gz.rectangle(lx=2_w, ly=2_h, fill=surface_a)
rect.draw(surface_b)

surface_b.write_to_png('test1.png')

This is the resulting output:

Traceback (most recent call last):
File "D:\Data\test1.py", line 9, in
rect.draw(surface_b)
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 137, in draw
self.draw_method(ctx)
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 387, in new_draw
_set_source(ctx, fill)
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 331, in _set_source
elif len(src)==4: # RGBA
TypeError: object of type 'Surface' has no len()

I wrote this in imitation of the write_to_png() method of the Surface class. This method also fails if I specify: y_origin='bottom'. Here is an example script:

import gizeh as gz

w,h =256,256
surface_a = gz.Surface(width=w, height=h, bg_color=(1,0,0))

surface_a.write_to_png('test1.png', y_origin='bottom')

And here is the output:

Traceback (most recent call last):
File "D:\Data\test2.py", line 7, in
surface_a.write_to_png('test2.png', y_origin='bottom')
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 62, in write_to_png
rect.draw(new_surface)
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 137, in draw
self.draw_method(ctx)
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 387, in new_draw
_set_source(ctx, fill)
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 326, in _set_source
ctx.set_source(src.make_cairo_pattern())
File "C:\Python34\lib\site-packages\gizeh\gizeh.py", line 293, in make_cairo_pattern
pat = cairo.SurfacePattern(self._cairo_surface)
File "C:\Python34\lib\site-packages\cairocffi\patterns.py", line 198, in init
self, cairo.cairo_pattern_create_for_surface(surface._pointer))
AttributeError: 'Surface' object has no attribute '_pointer'

Am I doing something incorrectly?

@seanodonnell
Copy link

It looks like the the surface object (surface._pointer) should be set to a _cairo_surface, but is not in this case. I tried messing around in the Surface class, and while I could fix it, I could'nt manage it without breaking other things. ( I don't know much about cairo).

@seanodonnell
Copy link

actually, looks like The pull request above fixes things

@PMende
Copy link
Contributor Author

PMende commented Jun 6, 2015

Thanks for checking this out! I actually wound up writing a Cairo wrapper for myself (using this package as inspiration), and have everything working, but I appreciate the effort. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants