Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f6589d

Browse filesBrowse files
authored
Merge pull request #29973 from anntzer/ft2lambda
Use inline lambdas to define most FT2Font properties.
2 parents b95676a + 1091fd2 commit 2f6589d
Copy full SHA for 2f6589d

File tree

1 file changed

+98
-182
lines changed
Filter options

1 file changed

+98
-182
lines changed

‎src/ft2font_wrapper.cpp

Copy file name to clipboardExpand all lines: src/ft2font_wrapper.cpp
+98-182Lines changed: 98 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,144 +1474,6 @@ PyFT2Font__get_type1_encoding_vector(PyFT2Font *self)
14741474
return indices;
14751475
}
14761476

1477-
static const char *
1478-
PyFT2Font_postscript_name(PyFT2Font *self)
1479-
{
1480-
const char *ps_name = FT_Get_Postscript_Name(self->x->get_face());
1481-
if (ps_name == nullptr) {
1482-
ps_name = "UNAVAILABLE";
1483-
}
1484-
1485-
return ps_name;
1486-
}
1487-
1488-
static FT_Long
1489-
PyFT2Font_num_faces(PyFT2Font *self)
1490-
{
1491-
return self->x->get_face()->num_faces;
1492-
}
1493-
1494-
static const char *
1495-
PyFT2Font_family_name(PyFT2Font *self)
1496-
{
1497-
const char *name = self->x->get_face()->family_name;
1498-
if (name == nullptr) {
1499-
name = "UNAVAILABLE";
1500-
}
1501-
return name;
1502-
}
1503-
1504-
static const char *
1505-
PyFT2Font_style_name(PyFT2Font *self)
1506-
{
1507-
const char *name = self->x->get_face()->style_name;
1508-
if (name == nullptr) {
1509-
name = "UNAVAILABLE";
1510-
}
1511-
return name;
1512-
}
1513-
1514-
static FaceFlags
1515-
PyFT2Font_face_flags(PyFT2Font *self)
1516-
{
1517-
return static_cast<FaceFlags>(self->x->get_face()->face_flags);
1518-
}
1519-
1520-
static StyleFlags
1521-
PyFT2Font_style_flags(PyFT2Font *self)
1522-
{
1523-
return static_cast<StyleFlags>(self->x->get_face()->style_flags & 0xffff);
1524-
}
1525-
1526-
static FT_Long
1527-
PyFT2Font_num_named_instances(PyFT2Font *self)
1528-
{
1529-
return (self->x->get_face()->style_flags & 0x7fff0000) >> 16;
1530-
}
1531-
1532-
static FT_Long
1533-
PyFT2Font_num_glyphs(PyFT2Font *self)
1534-
{
1535-
return self->x->get_face()->num_glyphs;
1536-
}
1537-
1538-
static FT_Int
1539-
PyFT2Font_num_fixed_sizes(PyFT2Font *self)
1540-
{
1541-
return self->x->get_face()->num_fixed_sizes;
1542-
}
1543-
1544-
static FT_Int
1545-
PyFT2Font_num_charmaps(PyFT2Font *self)
1546-
{
1547-
return self->x->get_face()->num_charmaps;
1548-
}
1549-
1550-
static bool
1551-
PyFT2Font_scalable(PyFT2Font *self)
1552-
{
1553-
if (FT_IS_SCALABLE(self->x->get_face())) {
1554-
return true;
1555-
}
1556-
return false;
1557-
}
1558-
1559-
static FT_UShort
1560-
PyFT2Font_units_per_EM(PyFT2Font *self)
1561-
{
1562-
return self->x->get_face()->units_per_EM;
1563-
}
1564-
1565-
static py::tuple
1566-
PyFT2Font_get_bbox(PyFT2Font *self)
1567-
{
1568-
FT_BBox *bbox = &(self->x->get_face()->bbox);
1569-
1570-
return py::make_tuple(bbox->xMin, bbox->yMin, bbox->xMax, bbox->yMax);
1571-
}
1572-
1573-
static FT_Short
1574-
PyFT2Font_ascender(PyFT2Font *self)
1575-
{
1576-
return self->x->get_face()->ascender;
1577-
}
1578-
1579-
static FT_Short
1580-
PyFT2Font_descender(PyFT2Font *self)
1581-
{
1582-
return self->x->get_face()->descender;
1583-
}
1584-
1585-
static FT_Short
1586-
PyFT2Font_height(PyFT2Font *self)
1587-
{
1588-
return self->x->get_face()->height;
1589-
}
1590-
1591-
static FT_Short
1592-
PyFT2Font_max_advance_width(PyFT2Font *self)
1593-
{
1594-
return self->x->get_face()->max_advance_width;
1595-
}
1596-
1597-
static FT_Short
1598-
PyFT2Font_max_advance_height(PyFT2Font *self)
1599-
{
1600-
return self->x->get_face()->max_advance_height;
1601-
}
1602-
1603-
static FT_Short
1604-
PyFT2Font_underline_position(PyFT2Font *self)
1605-
{
1606-
return self->x->get_face()->underline_position;
1607-
}
1608-
1609-
static FT_Short
1610-
PyFT2Font_underline_thickness(PyFT2Font *self)
1611-
{
1612-
return self->x->get_face()->underline_thickness;
1613-
}
1614-
16151477
static py::object
16161478
ft2font__getattr__(std::string name) {
16171479
auto api = py::module_::import("matplotlib._api");
@@ -1798,50 +1660,104 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
17981660
.def("_get_type1_encoding_vector", &PyFT2Font__get_type1_encoding_vector,
17991661
PyFT2Font__get_type1_encoding_vector__doc__)
18001662

1801-
.def_property_readonly("postscript_name", &PyFT2Font_postscript_name,
1802-
"PostScript name of the font.")
1803-
.def_property_readonly("num_faces", &PyFT2Font_num_faces,
1804-
"Number of faces in file.")
1805-
.def_property_readonly("family_name", &PyFT2Font_family_name,
1806-
"Face family name.")
1807-
.def_property_readonly("style_name", &PyFT2Font_style_name,
1808-
"Style name.")
1809-
.def_property_readonly("face_flags", &PyFT2Font_face_flags,
1810-
"Face flags; see `.FaceFlags`.")
1811-
.def_property_readonly("style_flags", &PyFT2Font_style_flags,
1812-
"Style flags; see `.StyleFlags`.")
1813-
.def_property_readonly("num_named_instances", &PyFT2Font_num_named_instances,
1814-
"Number of named instances in the face.")
1815-
.def_property_readonly("num_glyphs", &PyFT2Font_num_glyphs,
1816-
"Number of glyphs in the face.")
1817-
.def_property_readonly("num_fixed_sizes", &PyFT2Font_num_fixed_sizes,
1818-
"Number of bitmap in the face.")
1819-
.def_property_readonly("num_charmaps", &PyFT2Font_num_charmaps,
1820-
"Number of charmaps in the face.")
1821-
.def_property_readonly("scalable", &PyFT2Font_scalable,
1822-
"Whether face is scalable; attributes after this one "
1823-
"are only defined for scalable faces.")
1824-
.def_property_readonly("units_per_EM", &PyFT2Font_units_per_EM,
1825-
"Number of font units covered by the EM.")
1826-
.def_property_readonly("bbox", &PyFT2Font_get_bbox,
1827-
"Face global bounding box (xmin, ymin, xmax, ymax).")
1828-
.def_property_readonly("ascender", &PyFT2Font_ascender,
1829-
"Ascender in 26.6 units.")
1830-
.def_property_readonly("descender", &PyFT2Font_descender,
1831-
"Descender in 26.6 units.")
1832-
.def_property_readonly("height", &PyFT2Font_height,
1833-
"Height in 26.6 units; used to compute a default line "
1834-
"spacing (baseline-to-baseline distance).")
1835-
.def_property_readonly("max_advance_width", &PyFT2Font_max_advance_width,
1836-
"Maximum horizontal cursor advance for all glyphs.")
1837-
.def_property_readonly("max_advance_height", &PyFT2Font_max_advance_height,
1838-
"Maximum vertical cursor advance for all glyphs.")
1839-
.def_property_readonly("underline_position", &PyFT2Font_underline_position,
1840-
"Vertical position of the underline bar.")
1841-
.def_property_readonly("underline_thickness", &PyFT2Font_underline_thickness,
1842-
"Thickness of the underline bar.")
1843-
.def_property_readonly("fname", &PyFT2Font_fname,
1844-
"The original filename for this object.")
1663+
.def_property_readonly(
1664+
"postscript_name", [](PyFT2Font *self) {
1665+
if (const char *name = FT_Get_Postscript_Name(self->x->get_face())) {
1666+
return name;
1667+
} else {
1668+
return "UNAVAILABLE";
1669+
}
1670+
}, "PostScript name of the font.")
1671+
.def_property_readonly(
1672+
"num_faces", [](PyFT2Font *self) {
1673+
return self->x->get_face()->num_faces;
1674+
}, "Number of faces in file.")
1675+
.def_property_readonly(
1676+
"family_name", [](PyFT2Font *self) {
1677+
if (const char *name = self->x->get_face()->family_name) {
1678+
return name;
1679+
} else {
1680+
return "UNAVAILABLE";
1681+
}
1682+
}, "Face family name.")
1683+
.def_property_readonly(
1684+
"style_name", [](PyFT2Font *self) {
1685+
if (const char *name = self->x->get_face()->style_name) {
1686+
return name;
1687+
} else {
1688+
return "UNAVAILABLE";
1689+
}
1690+
}, "Style name.")
1691+
.def_property_readonly(
1692+
"face_flags", [](PyFT2Font *self) {
1693+
return static_cast<FaceFlags>(self->x->get_face()->face_flags);
1694+
}, "Face flags; see `.FaceFlags`.")
1695+
.def_property_readonly(
1696+
"style_flags", [](PyFT2Font *self) {
1697+
return static_cast<StyleFlags>(self->x->get_face()->style_flags & 0xffff);
1698+
}, "Style flags; see `.StyleFlags`.")
1699+
.def_property_readonly(
1700+
"num_named_instances", [](PyFT2Font *self) {
1701+
return (self->x->get_face()->style_flags & 0x7fff0000) >> 16;
1702+
}, "Number of named instances in the face.")
1703+
.def_property_readonly(
1704+
"num_glyphs", [](PyFT2Font *self) {
1705+
return self->x->get_face()->num_glyphs;
1706+
}, "Number of glyphs in the face.")
1707+
.def_property_readonly(
1708+
"num_fixed_sizes", [](PyFT2Font *self) {
1709+
return self->x->get_face()->num_fixed_sizes;
1710+
}, "Number of bitmap in the face.")
1711+
.def_property_readonly(
1712+
"num_charmaps", [](PyFT2Font *self) {
1713+
return self->x->get_face()->num_charmaps;
1714+
}, "Number of charmaps in the face.")
1715+
.def_property_readonly(
1716+
"scalable", [](PyFT2Font *self) {
1717+
return bool(FT_IS_SCALABLE(self->x->get_face()));
1718+
}, "Whether face is scalable; attributes after this one "
1719+
"are only defined for scalable faces.")
1720+
.def_property_readonly(
1721+
"units_per_EM", [](PyFT2Font *self) {
1722+
return self->x->get_face()->units_per_EM;
1723+
}, "Number of font units covered by the EM.")
1724+
.def_property_readonly(
1725+
"bbox", [](PyFT2Font *self) {
1726+
FT_BBox bbox = self->x->get_face()->bbox;
1727+
return py::make_tuple(bbox.xMin, bbox.yMin, bbox.xMax, bbox.yMax);
1728+
}, "Face global bounding box (xmin, ymin, xmax, ymax).")
1729+
.def_property_readonly(
1730+
"ascender", [](PyFT2Font *self) {
1731+
return self->x->get_face()->ascender;
1732+
}, "Ascender in 26.6 units.")
1733+
.def_property_readonly(
1734+
"descender", [](PyFT2Font *self) {
1735+
return self->x->get_face()->descender;
1736+
}, "Descender in 26.6 units.")
1737+
.def_property_readonly(
1738+
"height", [](PyFT2Font *self) {
1739+
return self->x->get_face()->height;
1740+
}, "Height in 26.6 units; used to compute a default line spacing "
1741+
"(baseline-to-baseline distance).")
1742+
.def_property_readonly(
1743+
"max_advance_width", [](PyFT2Font *self) {
1744+
return self->x->get_face()->max_advance_width;
1745+
}, "Maximum horizontal cursor advance for all glyphs.")
1746+
.def_property_readonly(
1747+
"max_advance_height", [](PyFT2Font *self) {
1748+
return self->x->get_face()->max_advance_height;
1749+
}, "Maximum vertical cursor advance for all glyphs.")
1750+
.def_property_readonly(
1751+
"underline_position", [](PyFT2Font *self) {
1752+
return self->x->get_face()->underline_position;
1753+
}, "Vertical position of the underline bar.")
1754+
.def_property_readonly(
1755+
"underline_thickness", [](PyFT2Font *self) {
1756+
return self->x->get_face()->underline_thickness;
1757+
}, "Thickness of the underline bar.")
1758+
.def_property_readonly(
1759+
"fname", &PyFT2Font_fname,
1760+
"The original filename for this object.")
18451761

18461762
.def_buffer([](PyFT2Font &self) -> py::buffer_info {
18471763
FT2Image &im = self.x->get_image();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.