@@ -232,11 +232,9 @@ def draw_image(self, gc, x, y, im):
232
232
# the array.array functionality here to get cross version support.
233
233
imbuffer = ArrayWrapper (im .flatten ())
234
234
else :
235
- # py2cairo uses PyObject_AsWriteBuffer
236
- # to get a pointer to the numpy array this works correctly
237
- # on a regular numpy array but not on a memory view.
238
- # At the time of writing the latest release version of
239
- # py3cairo still does not support create_for_data
235
+ # pycairo uses PyObject_AsWriteBuffer to get a pointer to the
236
+ # numpy array; this works correctly on a regular numpy array but
237
+ # not on a py2 memoryview.
240
238
imbuffer = im .flatten ()
241
239
surface = cairo .ImageSurface .create_for_data (
242
240
imbuffer , cairo .FORMAT_ARGB32 ,
@@ -277,7 +275,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
277
275
if not isinstance (s , six .text_type ):
278
276
s = six .text_type (s )
279
277
else :
280
- if not six .PY3 and isinstance (s , six .text_type ):
278
+ if six .PY2 and isinstance (s , six .text_type ):
281
279
s = s .encode ("utf-8" )
282
280
283
281
ctx .show_text (s )
@@ -328,8 +326,8 @@ def get_canvas_width_height(self):
328
326
329
327
def get_text_width_height_descent (self , s , prop , ismath ):
330
328
if ismath :
331
- width , height , descent , fonts , used_characters = self . mathtext_parser . parse (
332
- s , self .dpi , prop )
329
+ width , height , descent , fonts , used_characters = \
330
+ self . mathtext_parser . parse ( s , self .dpi , prop )
333
331
return width , height , descent
334
332
335
333
ctx = self .text_ctx
@@ -354,7 +352,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
354
352
355
353
def new_gc (self ):
356
354
self .gc .ctx .save ()
357
- self .gc ._alpha = 1.0
355
+ self .gc ._alpha = 1
358
356
self .gc ._forced_alpha = False # if True, _alpha overrides A from RGBA
359
357
return self .gc
360
358
@@ -391,8 +389,9 @@ def set_alpha(self, alpha):
391
389
else :
392
390
self .ctx .set_source_rgba (rgb [0 ], rgb [1 ], rgb [2 ], rgb [3 ])
393
391
394
- #def set_antialiased(self, b):
395
- # enable/disable anti-aliasing is not (yet) supported by Cairo
392
+ # def set_antialiased(self, b):
393
+ # cairo has many antialiasing modes, we need to pick one for True and
394
+ # one for False.
396
395
397
396
def set_capstyle (self , cs ):
398
397
if cs in ('butt' , 'round' , 'projecting' ):
@@ -404,9 +403,7 @@ def set_capstyle(self, cs):
404
403
def set_clip_rectangle (self , rectangle ):
405
404
if not rectangle :
406
405
return
407
- x , y , w , h = rectangle .bounds
408
- # pixel-aligned clip-regions are faster
409
- x ,y ,w ,h = np .round (x ), np .round (y ), np .round (w ), np .round (h )
406
+ x , y , w , h = np .round (rectangle .bounds )
410
407
ctx = self .ctx
411
408
ctx .new_path ()
412
409
ctx .rectangle (x , self .renderer .height - h - y , w , h )
@@ -522,14 +519,9 @@ def _save(self, fo, fmt, **kwargs):
522
519
ctx = renderer .gc .ctx
523
520
524
521
if orientation == 'landscape' :
525
- ctx .rotate (np .pi / 2 )
522
+ ctx .rotate (np .pi / 2 )
526
523
ctx .translate (0 , - height_in_points )
527
- # cairo/src/cairo_ps_surface.c
528
- # '%%Orientation: Portrait' is always written to the file header
529
- # '%%Orientation: Landscape' would possibly cause problems
530
- # since some printers would rotate again ?
531
- # TODO:
532
- # add portrait/landscape checkbox to FileChooser
524
+ # Perhaps add an '%%Orientation: Landscape' comment?
533
525
534
526
self .figure .draw (renderer )
535
527
0 commit comments