document and add tests for SBIX color font support

This commit is contained in:
nulano 2020-12-30 03:27:28 +01:00 committed by Andrew Murray
parent 058b8d3d12
commit 61ee8ec03c
8 changed files with 50 additions and 7 deletions

View File

@ -110,7 +110,7 @@ jobs:
if: steps.build-cache.outputs.cache-hit != 'true' if: steps.build-cache.outputs.cache-hit != 'true'
run: "& winbuild\\build\\build_dep_libwebp.cmd" run: "& winbuild\\build\\build_dep_libwebp.cmd"
# for FreeType CBDT font support # for FreeType CBDT/SBIX font support
- name: Build dependencies / libpng - name: Build dependencies / libpng
if: steps.build-cache.outputs.cache-hit != 'true' if: steps.build-cache.outputs.cache-hit != 'true'
run: "& winbuild\\build\\build_dep_libpng.cmd" run: "& winbuild\\build\\build_dep_libpng.cmd"

View File

@ -15,6 +15,8 @@ FreeMono.ttf is licensed under GPLv3, with the GPL font exception.
OpenSansCondensed-LightItalic.tt, from https://fonts.google.com/specimen/Open+Sans, under Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) OpenSansCondensed-LightItalic.tt, from https://fonts.google.com/specimen/Open+Sans, under Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
chromacheck-sbix.woff, from https://github.com/RoelN/ChromaCheck, under The MIT License (MIT), Copyright (c) 2018 Roel Nieskens, https://pixelambacht.nl Copyright (c) 2018 Google LLC
DejaVuSans-24-{1,2,4,8}-stripped.ttf are based on DejaVuSans.ttf converted using FontForge to add bitmap strikes and keep only the ASCII range. DejaVuSans-24-{1,2,4,8}-stripped.ttf are based on DejaVuSans.ttf converted using FontForge to add bitmap strikes and keep only the ASCII range.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -897,6 +897,46 @@ class TestImageFont:
assert str(e) in ("unimplemented feature", "unknown file format") assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or unsupported") pytest.skip("freetype compiled without libpng or unsupported")
@skip_unless_feature_version("freetype2", "2.5.1")
def test_sbix(self):
try:
font = ImageFont.truetype(
"Tests/fonts/chromacheck-sbix.woff",
size=300,
layout_engine=self.LAYOUT_ENGINE,
)
im = Image.new("RGB", (400, 400), "white")
d = ImageDraw.Draw(im)
d.text((50, 50), "\uE901", embedded_color=True, font=font)
with Image.open("Tests/images/chromacheck-sbix.png") as expected:
assert_image_similar(im, expected, 1)
except IOError as e:
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or unsupported")
@skip_unless_feature_version("freetype2", "2.5.1")
def test_sbix_mask(self):
try:
font = ImageFont.truetype(
"Tests/fonts/chromacheck-sbix.woff",
size=300,
layout_engine=self.LAYOUT_ENGINE,
)
im = Image.new("RGB", (400, 400), "white")
d = ImageDraw.Draw(im)
d.text((50, 50), "\uE901", (100, 0, 0), font=font)
with Image.open("Tests/images/chromacheck-sbix_mask.png") as expected:
assert_image_similar(im, expected, 1)
except IOError as e:
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or unsupported")
@skip_unless_feature_version("freetype2", "2.10.0") @skip_unless_feature_version("freetype2", "2.10.0")
def test_colr(self): def test_colr(self):
font = ImageFont.truetype( font = ImageFont.truetype(

View File

@ -352,7 +352,7 @@ Methods
.. versionadded:: 6.2.0 .. versionadded:: 6.2.0
:param embedded_color: Whether to use font embedded color glyphs (COLR or CBDT). :param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
.. versionadded:: 8.0.0 .. versionadded:: 8.0.0
@ -413,7 +413,7 @@ Methods
.. versionadded:: 6.2.0 .. versionadded:: 6.2.0
:param embedded_color: Whether to use font embedded color glyphs (COLR or CBDT). :param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
.. versionadded:: 8.0.0 .. versionadded:: 8.0.0
@ -577,7 +577,7 @@ Methods
correct substitutions as appropriate, if available. correct substitutions as appropriate, if available.
It should be a `BCP 47 language code`_. It should be a `BCP 47 language code`_.
Requires libraqm. Requires libraqm.
:param embedded_color: Whether to use font embedded color glyphs (COLR or CBDT). :param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
.. py:method:: ImageDraw.textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False) .. py:method:: ImageDraw.textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False)
@ -626,7 +626,7 @@ Methods
It should be a `BCP 47 language code`_. It should be a `BCP 47 language code`_.
Requires libraqm. Requires libraqm.
:param stroke_width: The width of the text stroke. :param stroke_width: The width of the text stroke.
:param embedded_color: Whether to use font embedded color glyphs (COLR or CBDT). :param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
.. py:method:: ImageDraw.multiline_textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False) .. py:method:: ImageDraw.multiline_textbbox(xy, text, font=None, anchor=None, spacing=4, align="left", direction=None, features=None, language=None, stroke_width=0, embedded_color=False)
@ -669,7 +669,7 @@ Methods
It should be a `BCP 47 language code`_. It should be a `BCP 47 language code`_.
Requires libraqm. Requires libraqm.
:param stroke_width: The width of the text stroke. :param stroke_width: The width of the text stroke.
:param embedded_color: Whether to use font embedded color glyphs (COLR or CBDT). :param embedded_color: Whether to use font embedded color glyphs (COLR, CBDT, SBIX).
.. py:method:: getdraw(im=None, hints=None) .. py:method:: getdraw(im=None, hints=None)

View File

@ -115,8 +115,9 @@ now support fonts with embedded color data.
To render text with embedded color data, use the parameter ``embedded_color=True``. To render text with embedded color data, use the parameter ``embedded_color=True``.
Support for CBDT fonts requires FreeType 2.5 compiled with libpng. Support for CBDT fonts requires FreeType 2.5 compiled with libpng.
Support for SBIX fonts requires FreeType 2.5.1 compiled with libpng.
Support for COLR fonts requires FreeType 2.10. Support for COLR fonts requires FreeType 2.10.
SBIX and SVG fonts are not yet supported. SVG fonts are not yet supported.
ImageDraw.textlength ImageDraw.textlength
^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^