Skip to content

Commit

Permalink
Merge pull request #134 from kyamagu/implement-svgdom
Browse files Browse the repository at this point in the history
Implement SVGDOM API
  • Loading branch information
kyamagu authored Jan 6, 2021
2 parents c39b6c5 + 5a11a84 commit 5ddcfbf
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 34 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ jobs:
- name: Build Skia
run: |
cd skia
patch -p1 < ../patch/git-sync-deps.patch
python tools/git-sync-deps
cp -f ../gn/out/gn bin/gn # Replace gn.
bin/gn gen out/Release --args='is_official_build=true skia_enable_tools=true skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_system_libpng=false skia_use_system_icu=false skia_use_system_harfbuzz=false extra_cflags_cc=["-frtti"] extra_ldflags=["-lrt"]'
ninja -C out/Release skia skia.h
rm -rf out/Release/obj
ninja -C out/Release skia skia.h experimental_svg_model
cd ..
if: steps.cache.outputs.cache-hit != 'true'
- name: Set up Python
Expand Down Expand Up @@ -98,8 +98,7 @@ jobs:
cd skia
python tools/git-sync-deps
bin/gn gen out/Release --args='is_official_build=true skia_enable_tools=true skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_system_libpng=false skia_use_system_icu=false skia_use_system_harfbuzz=false extra_cflags_cc=["-frtti", "-mmacosx-version-min=10.9"]'
ninja -C out/Release skia skia.h
rm -rf out/Release/obj
ninja -C out/Release skia skia.h experimental_svg_model
cd ..
if: steps.cache.outputs.cache-hit != 'true'
- name: Set up Python
Expand Down Expand Up @@ -160,8 +159,7 @@ jobs:
cd skia
python tools\git-sync-deps
bin\gn gen out\Release --args='is_official_build=true skia_enable_tools=true skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_system_libpng=false skia_use_system_icu=false skia_use_system_harfbuzz=false skia_use_system_expat=false skia_use_system_zlib=false extra_cflags_cc=[\"/GR\", \"/EHsc\", \"/MD\"] target_cpu=\"${{ matrix.arch }}\"'
ninja -C out\Release skia skia.h
rm out\Release\obj -r -fo
ninja -C out\Release skia skia.h experimental_svg_model
cd ..
if: steps.cache.outputs.cache-hit != 'true'
- name: Set up Python
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ jobs:
- name: Build Skia
run: |
cd skia
patch -p1 < ../patch/git-sync-deps.patch
python tools/git-sync-deps
cp -f ../gn/out/gn bin/gn # Replace gn.
bin/gn gen out/Release --args='is_official_build=true skia_enable_tools=true skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_system_libpng=false skia_use_system_icu=false skia_use_system_harfbuzz=false extra_cflags_cc=["-frtti"] extra_ldflags=["-lrt"]'
ninja -C out/Release skia skia.h
rm -rf out/Release/obj
ninja -C out/Release skia skia.h experimental_svg_model
cd ..
- name: Set up Python
run: echo "/opt/python/${{ matrix.python-version }}/bin" >> $GITHUB_PATH
Expand Down Expand Up @@ -85,8 +85,7 @@ jobs:
cd skia
python tools/git-sync-deps
bin/gn gen out/Release --args='is_official_build=true skia_enable_tools=true skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_system_libpng=false skia_use_system_icu=false skia_use_system_harfbuzz=false extra_cflags_cc=["-frtti", "-mmacosx-version-min=10.9"]'
ninja -C out/Release skia skia.h
rm -rf out/Release/obj
ninja -C out/Release skia skia.h experimental_svg_model
cd ..
- name: Set up Python
uses: actions/setup-python@v1
Expand Down Expand Up @@ -127,8 +126,7 @@ jobs:
cd skia
python tools\git-sync-deps
bin\gn gen out\Release --args='is_official_build=true skia_enable_tools=true skia_use_system_libjpeg_turbo=false skia_use_system_libwebp=false skia_use_system_libpng=false skia_use_system_icu=false skia_use_system_harfbuzz=false skia_use_system_expat=false skia_use_system_zlib=false extra_cflags_cc=[\"/GR\", \"/EHsc\", \"/MD\"] target_cpu=\"${{ matrix.arch }}\"'
ninja -C out\Release skia skia.h
rm out\Release\obj -r -fo
ninja -C out\Release skia skia.h experimental_svg_model
cd ..
- name: Set up Python
uses: actions/setup-python@v1
Expand Down
17 changes: 17 additions & 0 deletions patch/git-sync-deps.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/tools/git-sync-deps b/tools/git-sync-deps
index ca1ba47a75..92ff8ef7bc 100755
--- a/tools/git-sync-deps
+++ b/tools/git-sync-deps
@@ -235,9 +235,9 @@ def git_sync_deps(deps_file_path, command_line_os_requests, verbose):


def multithread(function, list_of_arg_lists):
- # for args in list_of_arg_lists:
- # function(*args)
- # return
+ for args in list_of_arg_lists:
+ function(*args)
+ return
threads = []
for args in list_of_arg_lists:
thread = threading.Thread(None, function, None, args)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
testpaths = tests

[tox:tox]
envlist = py35,py36,py37,py38
envlist = py36,py37,py38,py39

[testenv]
changedir = tests
Expand Down
57 changes: 46 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
pass

NAME = 'skia-python'
__version__ = '87.0'
__version__ = '87.1'

SKIA_PATH = os.getenv('SKIA_PATH', 'skia')
SKIA_OUT_PATH = os.getenv(
'SKIA_OUT_PATH', os.path.join(SKIA_PATH, 'out', 'Release'))
'SKIA_OUT_PATH', os.path.join(SKIA_PATH, 'out', 'Release')
)

if sys.platform == 'win32':
DEFINE_MACROS = [] # doesn't work for cl.exe
Expand All @@ -29,7 +30,18 @@
'OpenGL32',
'Gdi32',
]
EXTRA_OBJECTS = [os.path.join(SKIA_OUT_PATH, 'skia.lib')]
EXTRA_OBJECTS = list(
glob.glob(
os.path.join(
SKIA_OUT_PATH,
'obj',
'experimental',
'svg',
'model',
'*.obj',
)
)
) + [os.path.join(SKIA_OUT_PATH, 'skia.lib')]
EXTRA_COMPILE_ARGS = [
'/std:c++17', # c++20 fails.
'/DVERSION_INFO=%s' % __version__,
Expand All @@ -41,7 +53,7 @@
'/wd4267', # Conversion from 'size_t' to 'int', possible loss of data.
'/wd4800', # Forcing value to bool 'true' or 'false'.
'/wd4180', # Qualifier applied to function type has no meaning.
'/MD', # Bugfix: https://bugs.python.org/issue38597
'/MD', # Bugfix: https://bugs.python.org/issue38597
]
EXTRA_LINK_ARGS = [
'/OPT:ICF',
Expand All @@ -55,7 +67,18 @@
LIBRARIES = [
'dl',
]
EXTRA_OBJECTS = [os.path.join(SKIA_OUT_PATH, 'libskia.a')]
EXTRA_OBJECTS = list(
glob.glob(
os.path.join(
SKIA_OUT_PATH,
'obj',
'experimental',
'svg',
'model',
'*.o',
)
)
) + [os.path.join(SKIA_OUT_PATH, 'libskia.a')]
EXTRA_COMPILE_ARGS = [
'-std=c++14',
'-stdlib=libc++',
Expand All @@ -66,9 +89,12 @@
'-stdlib=libc++',
'-mmacosx-version-min=10.9',
'-dead_strip',
'-framework', 'AppKit',
'-framework', 'ApplicationServices',
'-framework', 'OpenGL',
'-framework',
'AppKit',
'-framework',
'ApplicationServices',
'-framework',
'OpenGL',
]
else:
DEFINE_MACROS = [
Expand All @@ -81,7 +107,18 @@
'freetype',
'GL',
]
EXTRA_OBJECTS = [os.path.join(SKIA_OUT_PATH, 'libskia.a')]
EXTRA_OBJECTS = list(
glob.glob(
os.path.join(
SKIA_OUT_PATH,
'obj',
'experimental',
'svg',
'model',
'*.o',
)
)
) + [os.path.join(SKIA_OUT_PATH, 'libskia.a')]
EXTRA_COMPILE_ARGS = [
'-std=c++14',
'-fvisibility=hidden',
Expand All @@ -102,7 +139,6 @@ class get_pybind_include(object):
The purpose of this class is to postpone importing pybind11
until it is actually installed, so that the ``get_include()``
method can be invoked. """

def __init__(self, user=False):
self.user = user

Expand Down Expand Up @@ -141,7 +177,6 @@ def build_extensions(self):
language='c++',
)


setup(
name=NAME,
version=__version__,
Expand Down
2 changes: 1 addition & 1 deletion skia
Submodule skia updated from 489348 to 73c703
17 changes: 17 additions & 0 deletions src/skia/SVGDOM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "common.h"
#include "experimental/svg/model/SkSVGDOM.h"
#include "experimental/svg/model/SkSVGNode.h"

void initSVGDOM(py::module &m) {
py::class_<SkSVGDOM, sk_sp<SkSVGDOM>, SkRefCnt> SVGDOM(m, "SVGDOM");

SVGDOM.def(py::init<>())
// .def_static("MakeFromDOM", &SkSVGDOM::MakeFromDOM, py::arg("dom"))
.def_static("MakeFromStream", &SkSVGDOM::MakeFromStream, py::arg("stream"))
.def("containerSize", &SkSVGDOM::containerSize)
.def("setContainerSize", &SkSVGDOM::setContainerSize)
// .def("setRoot", &SkSVGDOM::setRoot)
// .def("findNodeById", &SkSVGDOM::findNodeById)
.def("render", &SkSVGDOM::render)
;
}
2 changes: 2 additions & 0 deletions src/skia/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void initString(py::module &);
void initSurface(py::module &);
void initTextBlob(py::module &);
void initVertices(py::module &);
void initSVGDOM(py::module &);

// Main entry point.
PYBIND11_MODULE(skia, m) {
Expand Down Expand Up @@ -68,6 +69,7 @@ PYBIND11_MODULE(skia, m) {

initCanvas(m);
initSurface(m);
initSVGDOM(m);

#ifdef VERSION_INFO
m.attr("__version__") = XSTRING(VERSION_INFO);
Expand Down
19 changes: 10 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import contextlib
import skia
import os
import pytest
import sys
import logging
Expand Down Expand Up @@ -79,11 +80,14 @@ def canvas(surface):


@pytest.fixture(scope='session')
def png_path():
import os
def resource_path():
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(
root_dir, 'skia', 'resources', 'images', 'color_wheel.png')
return os.path.join(root_dir, 'skia', 'resources')


@pytest.fixture(scope='session')
def png_path(resource_path):
return os.path.join(resource_path, 'images', 'color_wheel.png')


@pytest.fixture(scope='session')
Expand Down Expand Up @@ -123,8 +127,5 @@ def vertices():


@pytest.fixture(scope='session')
def ttf_path():
import os
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
return os.path.join(
root_dir, 'skia', 'resources', 'fonts', 'Distortable.ttf')
def ttf_path(resource_path):
return os.path.join(resource_path, 'fonts', 'Distortable.ttf')
26 changes: 26 additions & 0 deletions tests/test_svgdom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import pytest
import skia


@pytest.fixture
def svgdom(resource_path):
stream = skia.FILEStream(os.path.join(resource_path, 'Cowboy.svg'))
return skia.SVGDOM.MakeFromStream(stream)


def test_SVGDOM_MakeFromStream(resource_path):
stream = skia.FILEStream(os.path.join(resource_path, 'Cowboy.svg'))
assert isinstance(skia.SVGDOM.MakeFromStream(stream), skia.SVGDOM)


def test_SVGDOM_containerSize(svgdom):
assert isinstance(svgdom.containerSize(), skia.Size)


def test_SVGDOM_setContainerSize(svgdom):
svgdom.setContainerSize((100, 100))


def test_SVGDOM_render(svgdom, canvas):
svgdom.render(canvas)

0 comments on commit 5ddcfbf

Please sign in to comment.