Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding SkFontMgr_New_Custom_Directory #292

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/skia/Font.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "common.h"
#include <include/core/SkFontMetrics.h>
#include <include/ports/SkFontMgr_directory.h>
#include <include/ports/SkFontMgr_empty.h>
#include <pybind11/stl.h>
#include <pybind11/stl_bind.h>
Expand Down Expand Up @@ -808,6 +809,12 @@ py::class_<SkFontMgr, sk_sp<SkFontMgr>, SkRefCnt>(m, "FontMgr",

)docstring")
.def(py::init([] () { return SkFontMgr_RefDefault(); }))
.def_static("New_Custom_Directory", &SkFontMgr_New_Custom_Directory,
R"docstring(
Create a custom font manager which scans a given directory for font files.
This font manager uses FreeType for rendering.
)docstring",
py::arg("dir"))
.def_static("New_Custom_Empty", &SkFontMgr_New_Custom_Empty)
.def_static("New_Custom_Empty", py::overload_cast<char*>(&OneFontMgr_New_Custom_Empty),
py::arg("filename"))
Expand Down
14 changes: 14 additions & 0 deletions tests/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,20 @@ def test_FontMgr_New_Custom_Empty2(ttf_path):
assert isinstance(skia.FontMgr.New_Custom_Empty(font_data), skia.FontMgr)


@pytest.fixture(scope='module')
def fontmgr_new_custom_directory(resource_path):
return skia.FontMgr.New_Custom_Directory(os.path.join(resource_path, 'fonts'))


def test_FontMgr_new_custom_directory_init(fontmgr_new_custom_directory):
assert isinstance(fontmgr_new_custom_directory, skia.FontMgr)


def test_FontMgr_new_custom_directory_countFamilies(fontmgr_new_custom_directory):
# Recursive valid font count in skia/resources/fonts/ as of skia m132
assert fontmgr_new_custom_directory.countFamilies() == 33


# Strickly speaking, we do not need/want this no-arg one.
def test_FontMgr_OneFontMgr0():
assert isinstance(skia.FontMgr.OneFontMgr(), skia.FontMgr)
Expand Down
Loading