@@ -202,22 +202,27 @@ def draw_lines(self, gc, x, y, transform=None):
202
202
203
203
204
204
def draw_markers (self , gc , path , x , y , transform ):
205
- #def _draw_markers(self, gc, path, x, y, transform):
206
205
if DEBUG : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
207
206
207
+ ctx = gc .ctx
208
+
208
209
if transform .need_nonlinear ():
209
210
x ,y = transform .nonlinear_only_numerix (x , y )
210
- x , y = transform .numerix_x_y (x , y ) # todo - use cairo transform
211
-
211
8000
+ x , y = transform .numerix_x_y (x , y )
212
+
212
213
# the a,b,c,d,tx,ty affine which transforms x and y
213
214
#vec6 = transform.as_vec6_val() # not used (yet)
214
215
215
- ctx = gc .ctx
216
+ # todo - use cairo transform
217
+ # matrix worked for dotted lines, but not markers in line_styles.py
218
+ # it upsets/transforms generate_path() ?
219
+ #matrix_old = ctx.matrix
220
+ #matrix = cairo.Matrix (*vec6)
221
+ #ctx.set_matrix (matrix)
216
222
217
- def draw_path ():
218
- # could trace path just once, then save/restore() ?
219
- # need to remember/store fill and fill_rgb
220
- fill = False
223
+ def generate_path (path ):
224
+ """trace path and return fill_rgb
225
+ """
221
226
for p in path :
222
227
code = p [0 ]
223
228
if code == MOVETO :
@@ -226,31 +231,29 @@ def draw_path():
226
231
ctx .line_to (p [1 ], - p [2 ])
227
232
elif code == ENDPOLY :
228
233
ctx .close_path ()
229
- fill = p [1 ]
230
- if fill :
234
+ if p [1 ]: # fill
231
235
#rgba = p[2:]
232
- fill_rgb = p [2 :5 ]
236
+ return p [2 :5 ] # don't really want to read the same fill_rgb every time we generate_path()
237
+ return None
233
238
234
- # draw marker
235
- if fill :
239
+ for x ,y in izip (x ,y ):
240
+ ctx .save ()
241
+ ctx .new_path ()
242
+ ctx .translate (x , self .height - y )
243
+
244
+ fill_rgb = generate_path (path )
245
+ if fill_rgb :
236
246
ctx .save ()
237
247
ctx .set_rgb_color (* fill_rgb )
238
248
# later - set alpha also?
239
249
ctx .fill ()
240
- ctx .restore ()
250
+ ctx .restore () # undo colour change and restore path
241
251
242
252
ctx .stroke ()
243
-
244
- for x ,y in izip (x ,y ):
245
- # TODO
246
- # use Cairo transform
247
- # look to writing in a more efficient way - trace path once only - see above
248
- ctx .save ()
249
- ctx .new_path ()
250
- ctx .translate (x , self .height - y )
251
- draw_path ()
252
253
ctx .restore () # undo translate()
253
254
255
+ #ctx.set_matrix(matrix_old)
256
+
254
257
255
258
def draw_point (self , gc , x , y ):
256
259
if DEBUG : print 'backend_cairo.RendererCairo.%s()' % _fn_name ()
@@ -457,11 +460,13 @@ def set_capstyle(self, cs):
457
460
458
461
459
462
def set_clip_rectangle (self , rectangle ):
460
- # Cairo clipping is currently extremely slow
461
- # cairo/BUGS lists it as a known bug
463
+ # Cairo < 0.4.0: clipping is currently extremely slow
464
+ # Cairo 0.4.0 : pixel-aligned rectangular clip-regions are now faster
462
465
self ._cliprect = rectangle
463
466
464
467
x ,y ,w ,h = rectangle
468
+ # pixel-aligned clip-regions are faster
469
+ x ,y ,w ,h = round (x ), round (y ), round (w ), round (h )
465
470
ctx = self .ctx
466
471
ctx .new_path ()
467
472
ctx .rectangle (x , self .renderer .height - h - y , w , h )
@@ -472,6 +477,9 @@ def set_clip_rectangle(self, rectangle):
472
477
#ctx.stroke()
473
478
#ctx.restore()
474
479
480
+ #ctx.init_clip() # not needed? used unsuccessfully to fix clip problem
481
+ # when uncomment ctx.clip() it causes problems in line_styles.py
482
+ # - multiple axes, only the first one has its background drawn
475
483
#ctx.clip ()
476
484
477
485
0 commit comments