@@ -94,15 +94,6 @@ def buffer_info(self):
9494_CAIRO_PATH_TYPE_SIZES [cairo .PATH_CLOSE_PATH ] = 1
9595
9696
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-
10697def _convert_paths_slow (ctx , paths , transforms , clip = None ):
10798 for path , transform in zip (paths , transforms ):
10899 for points , code in path .iter_segments (transform , clip = clip ):
@@ -123,7 +114,7 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
123114
124115def _convert_paths_fast (ctx , paths , transforms , clip = None ):
125116 # 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
127118 # --CODE(4)-- -LENGTH(4)- ---------PAD(8)---------
128119 # ----------X(8)---------- ----------Y(8)----------
129120 # 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):
154145 # Fill the buffer.
155146 buf = np .empty (cairo_num_data * 16 , np .uint8 )
156147 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 )
159148 as_int [::4 ][cairo_type_positions ] = codes
160149 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 )
161152 mask [::2 ][cairo_type_positions ] = mask [1 ::2 ][cairo_type_positions ] = False
162153 as_float [mask ] = vertices .ravel ()
163154
@@ -169,6 +160,13 @@ def _convert_paths_fast(ctx, paths, transforms, clip=None):
169160 cairo .cairo .cairo_append_path (ctx ._pointer , ptr )
170161
171162
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+
172170class RendererCairo (RendererBase ):
173171 fontweights = {
174172 100 : cairo .FONT_WEIGHT_NORMAL ,
@@ -247,8 +245,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform,
247245
248246 ctx .new_path ()
249247 # 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 ))
252249 marker_path = ctx .copy_path_flat ()
253250
254251 # Figure out whether the path has a fill
@@ -312,7 +309,7 @@ def _draw_paths():
312309 for k , v in gc_vars .items ():
313310 try :
314311 getattr (gc , "set" + k )(v )
315- except (AttributeError , TypeError ):
312+ except (AttributeError , TypeError ) as e :
316313 pass
317314 gc .ctx .new_path ()
318315 paths , transforms = zip (* grouped_draw )
@@ -326,8 +323,8 @@ def _draw_paths():
326323 offsetTrans , facecolors , edgecolors , linewidths , linestyles ,
327324 antialiaseds , urls , offset_position ):
328325 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 ))
331328 # rgb_fc could be a ndarray, for which equality is elementwise.
332329 new_key = vars (gc0 ), tuple (rgb_fc ) if rgb_fc is not None else None
333330 if new_key == reuse_key :
0 commit comments