@@ -99,12 +99,8 @@ def _convert_path(ctx, path, transform, clip=None):
99
99
100
100
101
101
def _convert_paths (ctx , paths , transforms , clip = None ):
102
- if HAS_CAIRO_CFFI :
103
- try :
104
- return _convert_paths_fast (ctx , paths , transforms , clip )
105
- except NotImplementedError :
106
- pass
107
- return _convert_paths_slow (ctx , paths , transforms , clip )
102
+ return (_convert_paths_fast if HAS_CAIRO_CFFI else _convert_paths_slow )(
103
+ ctx , paths , transforms , clip )
108
104
109
105
110
106
def _convert_paths_slow (ctx , paths , transforms , clip = None ):
@@ -117,9 +113,10 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
117
113
elif code == Path .LINETO :
118
114
ctx .line_to (* points )
119
115
elif code == Path .CURVE3 :
120
- ctx .curve_to (points [0 ], points [1 ],
121
- points [0 ], points [1 ],
122
- points [2 ], points [3 ])
116
+ cur = ctx .get_current_point ()
117
+ ctx .curve_to (
118
+ * np .concatenate ([cur / 3 + points [:2 ] * 2 / 3 ,
119
+ points [:2 ] * 2 / 3 + points [- 2 :] / 3 ]))
123
120
elif code == Path .CURVE4 :
124
121
ctx .curve_to (* points )
125
122
@@ -132,17 +129,15 @@ def _convert_paths_fast(ctx, paths, transforms, clip=None):
132
129
# with the size in bytes in parentheses, and (X, Y) repeated as many times
133
130
# as there are points for the current code.
134
131
ffi = cairo .ffi
135
- cleaneds = [path .cleaned (transform = transform , clip = clip )
132
+
133
+ # Convert curves to segment, so that 1. we don't have to handle
134
+ # variable-sized CURVE-n codes, and 2. we don't have to implement degree
135
+ # elevation for quadratic Beziers.
136
+ cleaneds = [path .cleaned (transform = transform , clip = clip , curves = False )
136
137
for path , transform in zip (paths , transforms )]
137
138
vertices = np .concatenate ([cleaned .vertices for cleaned in cleaneds ])
138
139
codes = np .concatenate ([cleaned .codes for cleaned in cleaneds ])
139
140
140
- # TODO: Implement Bezier degree elevation formula. For now, fall back to
141
- # the "slow" implementation, though note that that implementation is, in
142
- # fact, also incorrect...
143
- if np .any (codes == Path .CURVE3 ):
144
- raise NotImplementedError ("Quadratic Bezier curves are not supported" )
145
-
146
141
# Remove unused vertices and convert to cairo codes. Note that unlike
147
142
# cairo_close_path, we do not explicitly insert an extraneous MOVE_TO after
148
143
# CLOSE_PATH, so our resulting buffer may be smaller.
0 commit comments