--- a PPN by Garber Painting Akron. With Image Size Reduction included!URL: http://github.com/matplotlib/matplotlib/pull/31434.diff
default_, maximum, tag, name_id, int_flags) = info;
+ flags = static_cast(int_flags);
+ }
+};
+
+const char *PyVariationNamedStyle__doc__ = R"""(
+ A description of a named style.
+
+ For more information, see `the FreeType documentation
+ `_.
+
+ .. versionadded:: 3.11
+
+ Attributes
+ ----------
+ names: dict
+ The (possibly localized) names for the style. The dictionary is keyed by
+ (platform_id, encoding_id, language_id) with values of the names. Names are
+ decoded to strings on a best effort basis, otherwise kept as bytes.
+ psnames: dict, optional
+ The (possibly localized) PostScript names for the style. The dictionary is keyed
+ by (platform_id, encoding_id, language_id) with values of the names. Names are
+ decoded to strings on a best effort basis, otherwise kept as bytes.
+)""";
+
+struct PyVariationNamedStyle {
+ py::dict names;
+ py::object psnames;
+
+ PyVariationNamedStyle(const FT2Font::VariationNamedStyle &style) {
+ auto psid = std::get<1>(style);
+ if (psid != 65535) {
+ psnames = py::dict();
+ } else {
+ psnames = py::none();
+ }
+ }
+};
+
+const char *PyFT2Font_get_variation_descriptor__doc__ = R"""(
+ Return the variation information of the font.
+
+ .. note::
+ This function only works on fonts that have `.FaceFlags.MULTIPLE_MASTERS` set in
+ their `.face_flags`.
+
+ .. versionadded:: 3.11
+
+ Returns
+ -------
+ axes : list of VariationAxis
+ A model of each axis in design space for Adobe MM fonts, TrueType GX, and
+ OpenType Font Variations.
+ styles : list of VariationNamedStyle
+ A model of each named instance in a TrueType GX or OpenType Font Variations.
+)""";
+
+static auto
+PyFT2Font_get_variation_descriptor(PyFT2Font *self)
+{
+ auto [axes, styles] = self->get_variation_descriptor();
+
+ std::map> all_names;
+
+ std::vector py_axes;
+ py_axes.reserve(axes.size());
+ for (const auto &axis : axes) {
+ const auto &py_axis = py_axes.emplace_back(axis);
+ all_names[std::get<5>(axis)].push_back(py_axis.names);
+ }
+
+ std::vector py_styles;
+ py_styles.reserve(styles.size());
+ for (const auto &style : styles) {
+ const auto &py_style = py_styles.emplace_back(style);
+ all_names[std::get<0>(style)].push_back(py_style.names);
+ if (!py_style.psnames.is_none()) {
+ all_names[std::get<1>(style)].push_back(py_style.psnames);
+ }
+ }
+
+ auto encodingTools = py::module_::import("fontTools.misc.encodingTools");
+ auto getEncoding = encodingTools.attr("getEncoding");
+ size_t count = FT_Get_Sfnt_Name_Count(self->get_face());
+ for (FT_UInt i = 0; i < count; ++i) {
+ FT_SfntName sfnt;
+ FT_CHECK(FT_Get_Sfnt_Name, self->get_face(), i, &sfnt);
+
+ const auto &names = all_names.find(sfnt.name_id);
+ if (names == all_names.end()) {
+ continue;
+ }
+
+ auto key = py::make_tuple(sfnt.platform_id, sfnt.encoding_id, sfnt.language_id);
+ auto valb = py::bytes(reinterpret_cast(sfnt.string),
+ sfnt.string_len);
+ auto encoding = getEncoding(sfnt.platform_id, sfnt.encoding_id, sfnt.language_id);
+ py::object val = encoding.is_none() ? valb : valb.attr("decode")(encoding);
+ for (const auto &n : names->second) {
+ n[key] = val;
+ }
+ }
+
+ return std::make_tuple(py_axes, py_styles);
+}
+
+const char *PyFT2Font_get_default_variation_style__doc__ = R"""(
+ Return the default variation style.
+
+ .. note::
+ This function only works on fonts that have `.FaceFlags.MULTIPLE_MASTERS` set in
+ their `.face_flags`.
+
+ .. versionadded:: 3.11
+
+ Returns
+ -------
+ int
+ The index of the default variation style.
+)""";
+
+const char *PyFT2Font_get_variations__doc__ = R"""(
+ Return the current variation settings.
+
+ .. note::
+ This function only works on fonts that have `.FaceFlags.MULTIPLE_MASTERS` set in
+ their `.face_flags`.
+
+ .. versionadded:: 3.11
+
+ Returns
+ -------
+ list of float
+ The current settings, in the same order as the axes returned from
+ `.get_variation_descriptor`.
+)""";
+
+const char *PyFT2Font_set_variations_index__doc__ = R"""(
+ Set the variations from a named style index.
+
+ .. note::
+ This function only works on fonts that have `.FaceFlags.MULTIPLE_MASTERS` set in
+ their `.face_flags`.
+
+ Parameters
+ ----------
+ index: int
+ The index of the named style, in the same order of the styles from
+ `.get_variation_descriptor`.
+)""";
+
+const char *PyFT2Font_set_variations_vector__doc__ = R"""(
+ Set the variations from a list of axis values.
+
+ .. note::
+ This function only works on fonts that have `.FaceFlags.MULTIPLE_MASTERS` set in
+ their `.face_flags`.
+
+ Parameters
+ ----------
+ coords: list of float
+ The variation settings, in the same order as the axes returned from
+ `.get_variation_descriptor`.
+)""";
+
/**********************************************************************
* Layout items
* */
@@ -1664,6 +1894,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
p11x::enums["RenderMode"].attr("__doc__") = RenderMode__doc__;
p11x::enums["FaceFlags"].attr("__doc__") = FaceFlags__doc__;
p11x::enums["StyleFlags"].attr("__doc__") = StyleFlags__doc__;
+ p11x::enums["VarAxisFlags"].attr("__doc__") = VarAxisFlags__doc__;
py::class_(m, "FT2Image", py::is_final(), py::buffer_protocol(),
PyFT2Image__doc__)
@@ -1749,6 +1980,45 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
item.glyph_index, item.x, item.y, item.prev_kern);
});
+ py::class_(m, "VariationAxis", py::is_final())
+ .def(py::init<>([]() -> PyVariationAxis {
+ // VariationAxis is not useful from Python, so mark it as not constructible.
+ throw std::runtime_error("VariationAxis is not constructible");
+ }))
+ .def_readonly("name", &PyVariationAxis::name, "The axis's name.")
+ .def_readonly("minimum", &PyVariationAxis::minimum,
+ "The axis's minimum design coordinate.")
+ .def_readonly("default", &PyVariationAxis::default_,
+ "The axis's default design coordinate.")
+ .def_readonly("maximum", &PyVariationAxis::maximum,
+ "The axis's maximum design coordinate.")
+ .def_readonly("tag", &PyVariationAxis::tag, "The axis's tag.")
+ .def_readonly("names", &PyVariationAxis::names,
+ "The axis's names from the name table (may be better than .name).")
+ .def_readonly("flags", &PyVariationAxis::flags, "The axis's flags.")
+ .def("__repr__",
+ [](const PyVariationAxis& info) {
+ return
+ "VariationAxis(name={!r}, minimum={}, default={}, "_s
+ "maximum={}, tag={}, names={}, flags={})"_s.format(
+ info.name, info.minimum, info.default_, info.maximum, info.tag,
+ info.names, info.flags);
+ });
+
+ py::class_(m, "VariationNamedStyle", py::is_final())
+ .def(py::init<>([]() -> PyVariationNamedStyle {
+ // VariationNamedStyle is not useful from Python, so mark it as not constructible.
+ throw std::runtime_error("VariationNamedStyle is not constructible");
+ }))
+ .def_readonly("names", &PyVariationNamedStyle::names)
+ .def_readonly("psnames", &PyVariationNamedStyle::psnames)
+ .def("__repr__",
+ [](const PyVariationNamedStyle& style) {
+ return
+ "VariationNamedStyle(names={!r}, psnames={!r})"_s.format(
+ style.names, style.psnames);
+ });
+
auto cls = py::class_(m, "FT2Font", py::is_final(), py::buffer_protocol(),
PyFT2Font__doc__)
.def(py::init(&PyFT2Font_init),
@@ -1820,6 +2090,19 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
.def("get_image", &PyFT2Font::get_image, PyFT2Font_get_image__doc__)
.def("_get_type1_encoding_vector", &PyFT2Font__get_type1_encoding_vector,
PyFT2Font__get_type1_encoding_vector__doc__)
+ .def("get_variation_descriptor", &PyFT2Font_get_variation_descriptor,
+ PyFT2Font_get_variation_descriptor__doc__)
+ .def("get_default_variation_style", &PyFT2Font::get_default_variation_style,
+ PyFT2Font_get_default_variation_style__doc__)
+ .def("get_variations", &PyFT2Font::get_variations,
+ PyFT2Font_get_variations__doc__)
+ .def("set_variations",
+ py::overload_cast(&PyFT2Font::set_variations), "index"_a,
+ PyFT2Font_set_variations_index__doc__)
+ .def("set_variations",
+ py::overload_cast>(&PyFT2Font::set_variations),
+ "coords"_a,
+ PyFT2Font_set_variations_vector__doc__)
.def_property_readonly(
"postscript_name", [](PyFT2Font *self) {
pFad - Phonifier reborn
Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy