|
8 | 8 |
|
9 | 9 | namespace py = pybind11; |
10 | 10 |
|
11 | | -#include <unordered_map> |
12 | | - |
13 | 11 | #include "agg_basics.h" |
14 | 12 | #include "agg_color_rgba.h" |
15 | 13 | #include "agg_trans_affine.h" |
16 | | -#include "path_converters.h" |
| 14 | +#include "mplutils.h" |
17 | 15 |
|
18 | 16 | void convert_trans_affine(const py::object& transform, agg::trans_affine& affine); |
19 | 17 |
|
@@ -150,161 +148,6 @@ namespace PYBIND11_NAMESPACE { namespace detail { |
150 | 148 | return true; |
151 | 149 | } |
152 | 150 | }; |
153 | | - |
154 | | - template <> struct type_caster<e_snap_mode> { |
155 | | - public: |
156 | | - PYBIND11_TYPE_CASTER(e_snap_mode, const_name("e_snap_mode")); |
157 | | - |
158 | | - bool load(handle src, bool) { |
159 | | - if (src.is_none()) { |
160 | | - value = SNAP_AUTO; |
161 | | - return true; |
162 | | - } |
163 | | - |
164 | | - value = src.cast<bool>() ? SNAP_TRUE : SNAP_FALSE; |
165 | | - |
166 | | - return true; |
167 | | - } |
168 | | - }; |
169 | | - |
170 | | -/* Remove all this macro magic after dropping NumPy usage and just include `py_adaptors.h`. */ |
171 | | -#ifdef MPL_PY_ADAPTORS_H |
172 | | - template <> struct type_caster<agg::line_cap_e> { |
173 | | - public: |
174 | | - PYBIND11_TYPE_CASTER(agg::line_cap_e, const_name("line_cap_e")); |
175 | | - |
176 | | - bool load(handle src, bool) { |
177 | | - const std::unordered_map<std::string, agg::line_cap_e> enum_values = { |
178 | | - {"butt", agg::butt_cap}, |
179 | | - {"round", agg::round_cap}, |
180 | | - {"projecting", agg::square_cap}, |
181 | | - }; |
182 | | - value = enum_values.at(src.cast<std::string>()); |
183 | | - return true; |
184 | | - } |
185 | | - }; |
186 | | - |
187 | | - template <> struct type_caster<agg::line_join_e> { |
188 | | - public: |
189 | | - PYBIND11_TYPE_CASTER(agg::line_join_e, const_name("line_join_e")); |
190 | | - |
191 | | - bool load(handle src, bool) { |
192 | | - const std::unordered_map<std::string, agg::line_join_e> enum_values = { |
193 | | - {"miter", agg::miter_join_revert}, |
194 | | - {"round", agg::round_join}, |
195 | | - {"bevel", agg::bevel_join}, |
196 | | - }; |
197 | | - value = agg::miter_join_revert; |
198 | | - value = enum_values.at(src.cast<std::string>()); |
199 | | - return true; |
200 | | - } |
201 | | - }; |
202 | | -#endif |
203 | | - |
204 | | -/* Remove all this macro magic after dropping NumPy usage and just include `_backend_agg_basic_types.h`. */ |
205 | | -#ifdef MPL_BACKEND_AGG_BASIC_TYPES_H |
206 | | -# ifndef MPL_PY_ADAPTORS_H |
207 | | -# error "py_adaptors.h must be included to get Agg type casters" |
208 | | -# endif |
209 | | - |
210 | | - template <> struct type_caster<ClipPath> { |
211 | | - public: |
212 | | - PYBIND11_TYPE_CASTER(ClipPath, const_name("ClipPath")); |
213 | | - |
214 | | - bool load(handle src, bool) { |
215 | | - if (src.is_none()) { |
216 | | - return true; |
217 | | - } |
218 | | - |
219 | | - auto clippath_tuple = src.cast<py::tuple>(); |
220 | | - |
221 | | - auto path = clippath_tuple[0]; |
222 | | - if (!path.is_none()) { |
223 | | - value.path = path.cast<mpl::PathIterator>(); |
224 | | - } |
225 | | - value.trans = clippath_tuple[1].cast<agg::trans_affine>(); |
226 | | - |
227 | | - return true; |
228 | | - } |
229 | | - }; |
230 | | - |
231 | | - template <> struct type_caster<Dashes> { |
232 | | - public: |
233 | | - PYBIND11_TYPE_CASTER(Dashes, const_name("Dashes")); |
234 | | - |
235 | | - bool load(handle src, bool) { |
236 | | - auto dash_tuple = src.cast<py::tuple>(); |
237 | | - auto dash_offset = dash_tuple[0].cast<double>(); |
238 | | - auto dashes_seq_or_none = dash_tuple[1]; |
239 | | - |
240 | | - if (dashes_seq_or_none.is_none()) { |
241 | | - return true; |
242 | | - } |
243 | | - |
244 | | - auto dashes_seq = dashes_seq_or_none.cast<py::sequence>(); |
245 | | - |
246 | | - auto nentries = dashes_seq.size(); |
247 | | - // If the dashpattern has odd length, iterate through it twice (in |
248 | | - // accordance with the pdf/ps/svg specs). |
249 | | - auto dash_pattern_length = (nentries % 2) ? 2 * nentries : nentries; |
250 | | - |
251 | | - for (py::size_t i = 0; i < dash_pattern_length; i += 2) { |
252 | | - auto length = dashes_seq[i % nentries].cast<double>(); |
253 | | - auto skip = dashes_seq[(i + 1) % nentries].cast<double>(); |
254 | | - |
255 | | - value.add_dash_pair(length, skip); |
256 | | - } |
257 | | - |
258 | | - value.set_dash_offset(dash_offset); |
259 | | - |
260 | | - return true; |
261 | | - } |
262 | | - }; |
263 | | - |
264 | | - template <> struct type_caster<SketchParams> { |
265 | | - public: |
266 | | - PYBIND11_TYPE_CASTER(SketchParams, const_name("SketchParams")); |
267 | | - |
268 | | - bool load(handle src, bool) { |
269 | | - if (src.is_none()) { |
270 | | - value.scale = 0.0; |
271 | | - value.length = 0.0; |
272 | | - value.randomness = 0.0; |
273 | | - return true; |
274 | | - } |
275 | | - |
276 | | - auto params = src.cast<std::tuple<double, double, double>>(); |
277 | | - std::tie(value.scale, value.length, value.randomness) = params; |
278 | | - |
279 | | - return true; |
280 | | - } |
281 | | - }; |
282 | | - |
283 | | - template <> struct type_caster<GCAgg> { |
284 | | - public: |
285 | | - PYBIND11_TYPE_CASTER(GCAgg, const_name("GCAgg")); |
286 | | - |
287 | | - bool load(handle src, bool) { |
288 | | - value.linewidth = src.attr("_linewidth").cast<double>(); |
289 | | - value.alpha = src.attr("_alpha").cast<double>(); |
290 | | - value.forced_alpha = src.attr("_forced_alpha").cast<bool>(); |
291 | | - value.color = src.attr("_rgb").cast<agg::rgba>(); |
292 | | - value.isaa = src.attr("_antialiased").cast<bool>(); |
293 | | - value.cap = src.attr("_capstyle").cast<agg::line_cap_e>(); |
294 | | - value.join = src.attr("_joinstyle").cast<agg::line_join_e>(); |
295 | | - value.dashes = src.attr("get_dashes")().cast<Dashes>(); |
296 | | - value.cliprect = src.attr("_cliprect").cast<agg::rect_d>(); |
297 | | - value.clippath = src.attr("get_clip_path")().cast<ClipPath>(); |
298 | | - value.snap_mode = src.attr("get_snap")().cast<e_snap_mode>(); |
299 | | - value.hatchpath = src.attr("get_hatch_path")().cast<mpl::PathIterator>(); |
300 | | - value.hatch_color = src.attr("get_hatch_color")().cast<agg::rgba>(); |
301 | | - value.hatch_linewidth = src.attr("get_hatch_linewidth")().cast<double>(); |
302 | | - value.sketch = src.attr("get_sketch_params")().cast<SketchParams>(); |
303 | | - |
304 | | - return true; |
305 | | - } |
306 | | - }; |
307 | | -#endif |
308 | 151 | }} // namespace PYBIND11_NAMESPACE::detail |
309 | 152 |
|
310 | 153 | #endif /* MPL_PY_CONVERTERS_11_H */ |
0 commit comments