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