@@ -359,12 +359,12 @@ const char *PyFT2Font_get_kerning__doc__ = R"""(
359
359
The glyph indices. Note these are not characters nor character codes.
360
360
Use `.get_char_index` to convert character codes to glyph indices.
361
361
362
- mode : int
362
+ mode : Kerning
363
363
A kerning mode constant:
364
364
365
- - ``KERNING_DEFAULT `` - Return scaled and grid-fitted kerning distances
366
- - ``KERNING_UNFITTED `` - Return scaled but un-grid-fitted kerning distances
367
- - ``KERNING_UNSCALED `` - Return the kerning vector in original font units
365
+ - ``DEFAULT `` - Return scaled and grid-fitted kerning distances.
366
+ - ``UNFITTED `` - Return scaled but un-grid-fitted kerning distances.
367
+ - ``UNSCALED `` - Return the kerning vector in original font units.
368
368
369
369
Returns
370
370
-------
@@ -373,9 +373,21 @@ const char *PyFT2Font_get_kerning__doc__ = R"""(
373
373
)""" ;
374
374
375
375
static int
376
- PyFT2Font_get_kerning (PyFT2Font *self, FT_UInt left, FT_UInt right, FT_UInt mode)
376
+ PyFT2Font_get_kerning (PyFT2Font *self, FT_UInt left, FT_UInt right,
377
+ std::variant<FT_Kerning_Mode, FT_UInt> mode_or_int)
377
378
{
378
379
bool fallback = true ;
380
+ FT_Kerning_Mode mode;
381
+
382
+ if (auto value = std::get_if<FT_UInt>(&mode_or_int)) {
383
+ auto api = py::module_::import (" matplotlib._api" );
384
+ auto warn = api.attr (" warn_deprecated" );
385
+ warn (" since" _a=" 3.10" , " name" _a=" mode" , " obj_type" _a=" parameter as int" ,
386
+ " alternative" _a=" Kerning enum values" );
387
+ mode = static_cast <FT_Kerning_Mode>(*value);
388
+ } else {
389
+ mode = std::get<0 >(mode_or_int);
390
+ }
379
391
380
392
return self->x ->get_kerning (left, right, mode, fallback);
381
393
}
@@ -1270,6 +1282,29 @@ PyFT2Font_fname(PyFT2Font *self)
1270
1282
}
1271
1283
}
1272
1284
1285
+ static py::object
1286
+ ft2font__getattr__ (std::string name) {
1287
+ auto api = py::module_::import (" matplotlib._api" );
1288
+ auto warn = api.attr (" warn_deprecated" );
1289
+
1290
+ #define DEPRECATE_ATTR_FROM_ENUM (attr_, alternative_, real_value_ ) \
1291
+ do { \
1292
+ if (name == #attr_) { \
1293
+ warn (" since" _a=" 3.10" , " name" _a=#attr_, " obj_type" _a=" attribute" , \
1294
+ " alternative" _a=#alternative_); \
1295
+ return py::cast (real_value_); \
1296
+ } \
1297
+ } while (0 )
1298
+ DEPRECATE_ATTR_FROM_ENUM (KERNING_DEFAULT, Kerning.DEFAULT , FT_KERNING_DEFAULT);
1299
+ DEPRECATE_ATTR_FROM_ENUM (KERNING_UNFITTED, Kerning.UNFITTED , FT_KERNING_UNFITTED);
1300
+ DEPRECATE_ATTR_FROM_ENUM (KERNING_UNSCALED, Kerning.UNSCALED , FT_KERNING_UNSCALED);
1301
+
1302
+ #undef DEPRECATE_ATTR_FROM_ENUM
1303
+
1304
+ throw py::attribute_error (
1305
+ " module 'matplotlib.ft2font' has no attribute {!r}" _s.format (name));
1306
+ }
1307
+
1273
1308
PYBIND11_MODULE (ft2font, m)
1274
1309
{
1275
1310
auto ia = [m]() -> const void * {
@@ -1288,6 +1323,22 @@ PYBIND11_MODULE(ft2font, m)
1288
1323
FT_Library_Version (_ft2Library, &major, &minor, &patch);
1289
1324
snprintf (version_string, sizeof (version_string), " %d.%d.%d" , major, minor, patch);
1290
1325
1326
+ py::options options;
1327
+ options.disable_enum_members_docstring ();
1328
+
1329
+ py::enum_<FT_Kerning_Mode>(m, " Kerning" , R"""(
1330
+ Kerning modes for `.FT2Font.get_kerning`.
1331
+
1332
+ For more information, see `the FreeType documentation
1333
+ <https://freetype.org/freetype2/docs/reference/ft2-glyph_retrieval.html#ft_kerning_mode>`_.
1334
+ )""" )
1335
+ #define DECLARE_ENUM (name ) .value(#name, FT_KERNING_##name)
1336
+ DECLARE_ENUM (DEFAULT)
1337
+ DECLARE_ENUM (UNFITTED)
1338
+ DECLARE_ENUM (UNSCALED)
1339
+ #undef DECLARE_ENUM
1340
+ ;
1341
+
1291
1342
py::class_<FT2Image>(m, " FT2Image" , py::is_final (), py::buffer_protocol (),
1292
1343
PyFT2Image__doc__)
1293
1344
.def (py::init<double , double >(), " width" _a, " height" _a, PyFT2Image_init__doc__)
@@ -1429,6 +1480,7 @@ PYBIND11_MODULE(ft2font, m)
1429
1480
1430
1481
m.attr (" __freetype_version__" ) = version_string;
1431
1482
m.attr (" __freetype_build_type__" ) = FREETYPE_BUILD_TYPE;
1483
+ m.def (" __getattr__" , ft2font__getattr__);
1432
1484
m.attr (" SCALABLE" ) = FT_FACE_FLAG_SCALABLE;
1433
1485
m.attr (" FIXED_SIZES" ) = FT_FACE_FLAG_FIXED_SIZES;
1434
1486
m.attr (" FIXED_WIDTH" ) = FT_FACE_FLAG_FIXED_WIDTH;
@@ -1442,9 +1494,6 @@ PYBIND11_MODULE(ft2font, m)
1442
1494
m.attr (" EXTERNAL_STREAM" ) = FT_FACE_FLAG_EXTERNAL_STREAM;
1443
1495
m.attr (" ITALIC" ) = FT_STYLE_FLAG_ITALIC;
1444
1496
m.attr (" BOLD" ) = FT_STYLE_FLAG_BOLD;
1445
- m.attr (" KERNING_DEFAULT" ) = (int )FT_KERNING_DEFAULT;
1446
- m.attr (" KERNING_UNFITTED" ) = (int )FT_KERNING_UNFITTED;
1447
- m.attr (" KERNING_UNSCALED" ) = (int )FT_KERNING_UNSCALED;
1448
1497
m.attr (" LOAD_DEFAULT" ) = FT_LOAD_DEFAULT;
1449
1498
m.attr (" LOAD_NO_SCALE" ) = FT_LOAD_NO_SCALE;
1450
1499
m.attr (" LOAD_NO_HINTING" ) = FT_LOAD_NO_HINTING;
0 commit comments