11#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
22#include < pybind11/pybind11.h>
3+ #include < pybind11/native_enum.h>
34#include < pybind11/numpy.h>
45#include < pybind11/stl.h>
56
67#include " ft2font.h"
7- #include " _enums.h"
88
99#include < set>
1010#include < sstream>
@@ -50,13 +50,6 @@ const char *Kerning__doc__ = R"""(
5050 .. versionadded:: 3.10
5151)""" ;
5252
53- P11X_DECLARE_ENUM (
54- " Kerning" , " Enum" ,
55- {" DEFAULT" , FT_KERNING_DEFAULT},
56- {" UNFITTED" , FT_KERNING_UNFITTED},
57- {" UNSCALED" , FT_KERNING_UNSCALED},
58- );
59-
6053const char *FaceFlags__doc__ = R"""(
6154 Flags returned by `FT2Font.face_flags`.
6255
@@ -103,29 +96,6 @@ enum class FaceFlags : FT_Long {
10396#undef DECLARE_FLAG
10497};
10598
106- P11X_DECLARE_ENUM (
107- " FaceFlags" , " Flag" ,
108- {" SCALABLE" , FaceFlags::SCALABLE},
109- {" FIXED_SIZES" , FaceFlags::FIXED_SIZES},
110- {" FIXED_WIDTH" , FaceFlags::FIXED_WIDTH},
111- {" SFNT" , FaceFlags::SFNT},
112- {" HORIZONTAL" , FaceFlags::HORIZONTAL},
113- {" VERTICAL" , FaceFlags::VERTICAL},
114- {" KERNING" , FaceFlags::KERNING},
115- {" FAST_GLYPHS" , FaceFlags::FAST_GLYPHS},
116- {" MULTIPLE_MASTERS" , FaceFlags::MULTIPLE_MASTERS},
117- {" GLYPH_NAMES" , FaceFlags::GLYPH_NAMES},
118- {" EXTERNAL_STREAM" , FaceFlags::EXTERNAL_STREAM},
119- {" HINTER" , FaceFlags::HINTER},
120- {" CID_KEYED" , FaceFlags::CID_KEYED},
121- {" TRICKY" , FaceFlags::TRICKY},
122- {" COLOR" , FaceFlags::COLOR},
123- {" VARIATION" , FaceFlags::VARIATION},
124- {" SVG" , FaceFlags::SVG},
125- {" SBIX" , FaceFlags::SBIX},
126- {" SBIX_OVERLAY" , FaceFlags::SBIX_OVERLAY},
127- );
128-
12999const char *LoadFlags__doc__ = R"""(
130100 Flags for `FT2Font.load_char`, `FT2Font.load_glyph`, and `FT2Font.set_text`.
131101
@@ -174,36 +144,6 @@ enum class LoadFlags : FT_Int32 {
174144#undef DECLARE_FLAG
175145};
176146
177- P11X_DECLARE_ENUM (
178- " LoadFlags" , " Flag" ,
179- {" DEFAULT" , LoadFlags::DEFAULT},
180- {" NO_SCALE" , LoadFlags::NO_SCALE},
181- {" NO_HINTING" , LoadFlags::NO_HINTING},
182- {" RENDER" , LoadFlags::RENDER},
183- {" NO_BITMAP" , LoadFlags::NO_BITMAP},
184- {" VERTICAL_LAYOUT" , LoadFlags::VERTICAL_LAYOUT},
185- {" FORCE_AUTOHINT" , LoadFlags::FORCE_AUTOHINT},
186- {" CROP_BITMAP" , LoadFlags::CROP_BITMAP},
187- {" PEDANTIC" , LoadFlags::PEDANTIC},
188- {" IGNORE_GLOBAL_ADVANCE_WIDTH" , LoadFlags::IGNORE_GLOBAL_ADVANCE_WIDTH},
189- {" NO_RECURSE" , LoadFlags::NO_RECURSE},
190- {" IGNORE_TRANSFORM" , LoadFlags::IGNORE_TRANSFORM},
191- {" MONOCHROME" , LoadFlags::MONOCHROME},
192- {" LINEAR_DESIGN" , LoadFlags::LINEAR_DESIGN},
193- {" NO_AUTOHINT" , LoadFlags::NO_AUTOHINT},
194- {" COLOR" , LoadFlags::COLOR},
195- {" COMPUTE_METRICS" , LoadFlags::COMPUTE_METRICS},
196- {" BITMAP_METRICS_ONLY" , LoadFlags::BITMAP_METRICS_ONLY},
197- {" NO_SVG" , LoadFlags::NO_SVG},
198- // These must be unique, but the others can be OR'd together; I don't know if
199- // there's any way to really enforce that.
200- {" TARGET_NORMAL" , LoadFlags::TARGET_NORMAL},
201- {" TARGET_LIGHT" , LoadFlags::TARGET_LIGHT},
202- {" TARGET_MONO" , LoadFlags::TARGET_MONO},
203- {" TARGET_LCD" , LoadFlags::TARGET_LCD},
204- {" TARGET_LCD_V" , LoadFlags::TARGET_LCD_V},
205- );
206-
207147const char *StyleFlags__doc__ = R"""(
208148 Flags returned by `FT2Font.style_flags`.
209149
@@ -221,13 +161,6 @@ enum class StyleFlags : FT_Long {
221161#undef DECLARE_FLAG
222162};
223163
224- P11X_DECLARE_ENUM (
225- " StyleFlags" , " Flag" ,
226- {" NORMAL" , StyleFlags::NORMAL},
227- {" ITALIC" , StyleFlags::ITALIC},
228- {" BOLD" , StyleFlags::BOLD},
229- );
230-
231164/* *********************************************************************
232165 * FT2Image
233166 * */
@@ -1552,11 +1485,68 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
15521485 FT_Library_Version (_ft2Library, &major, &minor, &patch);
15531486 snprintf (version_string, sizeof (version_string), " %d.%d.%d" , major, minor, patch);
15541487
1555- p11x::bind_enums (m);
1556- p11x::enums[" Kerning" ].attr (" __doc__" ) = Kerning__doc__;
1557- p11x::enums[" LoadFlags" ].attr (" __doc__" ) = LoadFlags__doc__;
1558- p11x::enums[" FaceFlags" ].attr (" __doc__" ) = FaceFlags__doc__;
1559- p11x::enums[" StyleFlags" ].attr (" __doc__" ) = StyleFlags__doc__;
1488+ py::native_enum<FT_Kerning_Mode>(m, " Kerning" , " enum.Enum" , Kerning__doc__)
1489+ .value (" DEFAULT" , FT_KERNING_DEFAULT)
1490+ .value (" UNFITTED" , FT_KERNING_UNFITTED)
1491+ .value (" UNSCALED" , FT_KERNING_UNSCALED)
1492+ .finalize ();
1493+
1494+ py::native_enum<LoadFlags>(m, " LoadFlags" , " enum.Flag" , LoadFlags__doc__)
1495+ .value (" DEFAULT" , LoadFlags::DEFAULT)
1496+ .value (" NO_SCALE" , LoadFlags::NO_SCALE)
1497+ .value (" NO_HINTING" , LoadFlags::NO_HINTING)
1498+ .value (" RENDER" , LoadFlags::RENDER)
1499+ .value (" NO_BITMAP" , LoadFlags::NO_BITMAP)
1500+ .value (" VERTICAL_LAYOUT" , LoadFlags::VERTICAL_LAYOUT)
1501+ .value (" FORCE_AUTOHINT" , LoadFlags::FORCE_AUTOHINT)
1502+ .value (" CROP_BITMAP" , LoadFlags::CROP_BITMAP)
1503+ .value (" PEDANTIC" , LoadFlags::PEDANTIC)
1504+ .value (" IGNORE_GLOBAL_ADVANCE_WIDTH" , LoadFlags::IGNORE_GLOBAL_ADVANCE_WIDTH)
1505+ .value (" NO_RECURSE" , LoadFlags::NO_RECURSE)
1506+ .value (" IGNORE_TRANSFORM" , LoadFlags::IGNORE_TRANSFORM)
1507+ .value (" MONOCHROME" , LoadFlags::MONOCHROME)
1508+ .value (" LINEAR_DESIGN" , LoadFlags::LINEAR_DESIGN)
1509+ .value (" NO_AUTOHINT" , LoadFlags::NO_AUTOHINT)
1510+ .value (" COLOR" , LoadFlags::COLOR)
1511+ .value (" COMPUTE_METRICS" , LoadFlags::COMPUTE_METRICS)
1512+ .value (" BITMAP_METRICS_ONLY" , LoadFlags::BITMAP_METRICS_ONLY)
1513+ .value (" NO_SVG" , LoadFlags::NO_SVG)
1514+ // These must be unique, but the others can be OR'd together; I don't know if
1515+ // there's any way to really enforce that.
1516+ .value (" TARGET_NORMAL" , LoadFlags::TARGET_NORMAL)
1517+ .value (" TARGET_LIGHT" , LoadFlags::TARGET_LIGHT)
1518+ .value (" TARGET_MONO" , LoadFlags::TARGET_MONO)
1519+ .value (" TARGET_LCD" , LoadFlags::TARGET_LCD)
1520+ .value (" TARGET_LCD_V" , LoadFlags::TARGET_LCD_V)
1521+ .finalize ();
1522+
1523+ py::native_enum<FaceFlags>(m, " FaceFlags" , " enum.Flag" , FaceFlags__doc__)
1524+ .value (" SCALABLE" , FaceFlags::SCALABLE)
1525+ .value (" FIXED_SIZES" , FaceFlags::FIXED_SIZES)
1526+ .value (" FIXED_WIDTH" , FaceFlags::FIXED_WIDTH)
1527+ .value (" SFNT" , FaceFlags::SFNT)
1528+ .value (" HORIZONTAL" , FaceFlags::HORIZONTAL)
1529+ .value (" VERTICAL" , FaceFlags::VERTICAL)
1530+ .value (" KERNING" , FaceFlags::KERNING)
1531+ .value (" FAST_GLYPHS" , FaceFlags::FAST_GLYPHS)
1532+ .value (" MULTIPLE_MASTERS" , FaceFlags::MULTIPLE_MASTERS)
1533+ .value (" GLYPH_NAMES" , FaceFlags::GLYPH_NAMES)
1534+ .value (" EXTERNAL_STREAM" , FaceFlags::EXTERNAL_STREAM)
1535+ .value (" HINTER" , FaceFlags::HINTER)
1536+ .value (" CID_KEYED" , FaceFlags::CID_KEYED)
1537+ .value (" TRICKY" , FaceFlags::TRICKY)
1538+ .value (" COLOR" , FaceFlags::COLOR)
1539+ .value (" VARIATION" , FaceFlags::VARIATION)
1540+ .value (" SVG" , FaceFlags::SVG)
1541+ .value (" SBIX" , FaceFlags::SBIX)
1542+ .value (" SBIX_OVERLAY" , FaceFlags::SBIX_OVERLAY)
1543+ .finalize ();
1544+
1545+ py::native_enum<StyleFlags>(m, " StyleFlags" , " enum.Flag" , StyleFlags__doc__)
1546+ .value (" NORMAL" , StyleFlags::NORMAL)
1547+ .value (" ITALIC" , StyleFlags::ITALIC)
1548+ .value (" BOLD" , StyleFlags::BOLD)
1549+ .finalize ();
15601550
15611551 py::class_<FT2Image>(m, " FT2Image" , py::is_final (), py::buffer_protocol (),
15621552 PyFT2Image__doc__)
0 commit comments