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