1
+ #include < cstddef>
1
2
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
2
3
#include < pybind11/pybind11.h>
3
4
#include < pybind11/numpy.h>
@@ -712,7 +713,8 @@ const char *PyFT2Font_set_text__doc__ = R"""(
712
713
713
714
static py::array_t <double >
714
715
PyFT2Font_set_text (PyFT2Font *self, std::u32string_view text, double angle = 0.0 ,
715
- std::variant<LoadFlags, FT_Int32> flags_or_int = LoadFlags::FORCE_AUTOHINT)
716
+ std::variant<LoadFlags, FT_Int32> flags_or_int = LoadFlags::FORCE_AUTOHINT,
717
+ std::variant<FT2Font::LanguageType, std::string> languages_or_str = nullptr )
716
718
{
717
719
std::vector<double > xys;
718
720
LoadFlags flags;
@@ -732,7 +734,21 @@ PyFT2Font_set_text(PyFT2Font *self, std::u32string_view text, double angle = 0.0
732
734
throw py::type_error (" flags must be LoadFlags or int" );
733
735
}
734
736
735
- self->x ->set_text (text, angle, static_cast <FT_Int32>(flags), xys);
737
+ FT2Font::LanguageType languages;
738
+ if (auto value = std::get_if<FT2Font::LanguageType>(&languages_or_str)) {
739
+ languages = std::move (*value);
740
+ } else if (auto value = std::get_if<std::string>(&languages_or_str)) {
741
+ languages = std::vector<FT2Font::LanguageRange>{
742
+ FT2Font::LanguageRange{*value, 0 , text.size ()}
743
+ };
744
+ } else {
745
+ // NOTE: this can never happen as pybind11 would have checked the type in the
746
+ // Python wrapper before calling this function, but we need to keep the
747
+ // std::get_if instead of std::get for macOS 10.12 compatibility.
748
+ throw py::type_error (" languages must be str or list of tuple" );
749
+ }
750
+
751
+ self->x ->set_text (text, angle, static_cast <FT_Int32>(flags), languages, xys);
736
752
737
753
py::ssize_t dims[] = { static_cast <py::ssize_t >(xys.size ()) / 2 , 2 };
738
754
py::array_t <double > result (dims);
@@ -1622,6 +1638,7 @@ PYBIND11_MODULE(ft2font, m, py::mod_gil_not_used())
1622
1638
PyFT2Font_get_kerning__doc__)
1623
1639
.def (" set_text" , &PyFT2Font_set_text,
1624
1640
" string" _a, " angle" _a=0.0 , " flags" _a=LoadFlags::FORCE_AUTOHINT,
1641
+ " language" _a=nullptr ,
1625
1642
PyFT2Font_set_text__doc__)
1626
1643
.def (" _get_fontmap" , &PyFT2Font_get_fontmap, " string" _a,
1627
1644
PyFT2Font_get_fontmap__doc__)
0 commit comments