Open PMende opened 9 years ago
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).
actually, looks like The pull request above fixes things
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. :)
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?