Skip to content

Commit

Permalink
Binding SkFontScanner_Make_FreeType & SkFontScanner
Browse files Browse the repository at this point in the history
FontScanner.MakeFromData, from upstream's SkFontScanner::MakeFromStream

Reference from Chromium m127's third_party/blink/renderer/platform/fonts/web_font_typeface_factory.cc

Fixes kyamagu#282
  • Loading branch information
HinTak committed Jan 2, 2025
1 parent b87ed1e commit add34b7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/skia/Font.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "common.h"
#include <include/core/SkFontMetrics.h>
#include <include/ports/SkFontMgr_empty.h>
#include <include/ports/SkFontScanner_FreeType.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
#include <pybind11/iostream.h>
Expand Down Expand Up @@ -369,6 +370,22 @@ fontarguments
&SkFontArguments::getVariationDesignPosition)
;

py::class_<SkFontScanner> 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<SkData> data, const SkFontArguments& args) {
std::unique_ptr<SkStreamAsset> stream(new SkMemoryStream(data));
return self.MakeFromStream(std::move(stream), args);
},
py::arg("data"), py::arg("args"))
;

py::class_<SkTypeface, sk_sp<SkTypeface>, SkRefCnt> typeface(
m, "Typeface", R"docstring(
The :py:class:`Typeface` class specifies the typeface and intrinsic style of
Expand Down

0 comments on commit add34b7

Please sign in to comment.