From b87ed1eec758239f9255853106e17ea569244f4b Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Sun, 29 Dec 2024 00:43:40 +0000 Subject: [PATCH 1/2] Adding a __iter__ method to skia.Iter See https://github.com/python/cpython/issues/128161 "Defining iterator in a separate class no longer works in 3.13" We have iterator for SkTextBlob defined by SkTextBlob::Iter(textblob), which is the c++/pybind11 equivalent of the same situation. Following the suggestion: https://github.com/python/cpython/issues/128161#issuecomment-2560846703 Also see https://github.com/actions/runner-images/issues/11241 Fixes #295 --- src/skia/TextBlob.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/skia/TextBlob.cpp b/src/skia/TextBlob.cpp index 8ff1fa709..8994b6424 100644 --- a/src/skia/TextBlob.cpp +++ b/src/skia/TextBlob.cpp @@ -65,6 +65,10 @@ py::class_(iter, "Run") iter .def(py::init()) + .def("__iter__", + [] (SkTextBlob::Iter& it) { + return it; + }) .def("__next__", [] (SkTextBlob::Iter& it) { SkTextBlob::Iter::Run run; From add34b7d93dfdf160902eca7504fba177b39d20d Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 23 Dec 2024 02:52:35 +0000 Subject: [PATCH 2/2] Binding SkFontScanner_Make_FreeType & SkFontScanner FontScanner.MakeFromData, from upstream's SkFontScanner::MakeFromStream Reference from Chromium m127's third_party/blink/renderer/platform/fonts/web_font_typeface_factory.cc Fixes #282 --- src/skia/Font.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/skia/Font.cpp b/src/skia/Font.cpp index 307ff1009..0b5b42ba9 100644 --- a/src/skia/Font.cpp +++ b/src/skia/Font.cpp @@ -1,6 +1,7 @@ #include "common.h" #include #include +#include #include #include #include @@ -369,6 +370,22 @@ fontarguments &SkFontArguments::getVariationDesignPosition) ; +py::class_ font_scanner(m, "FontScanner"); + +font_scanner + .def(py::init(&SkFontScanner_Make_FreeType)) + .def("scanFile", &SkFontScanner::scanFile, + py::arg("stream"), py::arg("numFaces")) + .def("scanFace", &SkFontScanner::scanFace, + py::arg("stream"), py::arg("faceIndex"), py::arg("numInstances")) + .def("MakeFromData", + [] (const SkFontScanner& self, sk_sp data, const SkFontArguments& args) { + std::unique_ptr stream(new SkMemoryStream(data)); + return self.MakeFromStream(std::move(stream), args); + }, + py::arg("data"), py::arg("args")) + ; + py::class_, SkRefCnt> typeface( m, "Typeface", R"docstring( The :py:class:`Typeface` class specifies the typeface and intrinsic style of