@@ -94,15 +94,6 @@ def buffer_info(self):
94
94
_CAIRO_PATH_TYPE_SIZES [cairo .PATH_CLOSE_PATH ] = 1
95
95
96
96
97
- def _convert_path (ctx , path , transform , clip = None ):
98
- return _convert_paths (ctx , [path ], [transform ], clip )
99
-
100
-
101
- def _convert_paths (ctx , paths , transforms , clip = None ):
102
- return (_convert_paths_fast if HAS_CAIRO_CFFI else _convert_paths_slow )(
103
- ctx , paths , transforms , clip )
104
-
105
-
106
97
def _convert_paths_slow (ctx , paths , transforms , clip = None ):
107
98
for path , transform in zip (paths , transforms ):
108
99
for points , code in path .iter_segments (transform , clip = clip ):
@@ -123,7 +114,7 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
123
114
124
115
def _convert_paths_fast (ctx , paths , transforms , clip = None ):
125
116
# We directly convert to the internal representation used by cairo, for
126
- # which ABI compatibility is guaranteed. The layout is for each item is
117
+ # which ABI compatibility is guaranteed. The layout for each item is
127
118
# --CODE(4)-- -LENGTH(4)- ---------PAD(8)---------
128
119
# ----------X(8)---------- ----------Y(8)----------
129
120
# with the size in bytes in parentheses, and (X, Y) repeated as many times
@@ -154,10 +145,10 @@ def _convert_paths_fast(ctx, paths, transforms, clip=None):
154
145
# Fill the buffer.
155
146
buf = np .empty (cairo_num_data * 16 , np .uint8 )
156
147
as_int = np .frombuffer (buf .data , np .int32 )
157
- as_float = np .frombuffer (buf .data , np .float64 )
158
- mask = np .ones_like (as_float , bool )
159
148
as_int [::4 ][cairo_type_positions ] = codes
160
149
as_int [1 ::4 ][cairo_type_positions ] = cairo_type_sizes
150
+ as_float = np .frombuffer (buf .data , np .float64 )
151
+ mask = np .ones_like (as_float , bool )
161
152
mask [::2 ][cairo_type_positions ] = mask [1 ::2 ][cairo_type_positions ] = False
162
153
as_float [mask ] = vertices .ravel ()
163
154
@@ -169,6 +160,13 @@ def _convert_paths_fast(ctx, paths, transforms, clip=None):
169
160
cairo .cairo .cairo_append_path (ctx ._pointer , ptr )
170
161
171
162
163
+ _convert_paths = _convert_paths_fast if HAS_CAIRO_CFFI else _convert_paths_slow
164
+
165
+
166
+ def _convert_path (ctx , path , transform , clip = None ):
167
+ return _convert_paths (ctx , [path ], [transform ], clip )
168
+
169
+
172
170
class RendererCairo (RendererBase ):
173
171
fontweights = {
174
172
100 : cairo .FONT_WEIGHT_NORMAL ,
@@ -247,8 +245,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform,
247
245
248
246
ctx .new_path ()
249
247
# Create the path for the marker; it needs to be flipped here already!
250
- _convert_path (
251
- ctx , marker_path , marker_trans + Affine2D ().scale (1 , - 1 ))
248
+ _convert_path (ctx , marker_path , marker_trans + Affine2D ().scale (1 , - 1 ))
252
249
marker_path = ctx .copy_path_flat ()
253
250
254
251
# Figure out whether the path has a fill
@@ -312,7 +309,7 @@ def _draw_paths():
312
309
for k , v in gc_vars .items ():
313
310
try :
314
311
getattr (gc , "set" + k )(v )
315
- except (AttributeError , TypeError ):
312
+ except (AttributeError , TypeError ) as e :
316
313
pass
317
314
gc .ctx .new_path ()
318
315
paths , transforms = zip (* grouped_draw )
@@ -326,8 +323,8 @@ def _draw_paths():
326
323
offsetTrans , facecolors , edgecolors , linewidths , linestyles ,
327
324
antialiaseds , urls , offset_position ):
328
325
path , transform = path_id
329
- transform = (Affine2D (transform .get_matrix ()). translate ( xo , yo )
330
- + Affine2D (). scale ( 1 , - 1 ). translate ( 0 , self . height ))
326
+ transform = (Affine2D (transform .get_matrix ())
327
+ . translate ( xo , yo - self . height ). scale ( 1 , - 1 ))
331
328
# rgb_fc could be a ndarray, for which equality is elementwise.
332
329
new_key = vars (gc0 ), tuple (rgb_fc ) if rgb_fc is not None else None
333
330
if new_key == reuse_key :
0 commit comments