Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
if: steps.build-cache.outputs.cache-hit != 'true'
run: "& winbuild\\build\\build_dep_libwebp.cmd"

# for FreeType CBDT font support
# for FreeType CBDT/SBIX font support
- name: Build dependencies / libpng
if: steps.build-cache.outputs.cache-hit != 'true'
run: "& winbuild\\build\\build_dep_libpng.cmd"
Expand Down
2 changes: 2 additions & 0 deletions Tests/fonts/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

KhmerOSBattambang-Regular.ttf is licensed under LGPL-2.1 or later.

FreeMono.ttf is licensed under GPLv3.
Expand Down
Binary file added Tests/fonts/chromacheck-sbix.woff
Binary file not shown.
Binary file added Tests/images/chromacheck-sbix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tests/images/chromacheck-sbix_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 44 additions & 6 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,12 +869,12 @@ def test_cbdt(self):
im = Image.new("RGB", (150, 150), "white")
d = ImageDraw.Draw(im)

d.text((10, 10), "\U0001f469", embedded_color=True, font=font)
d.text((10, 10), "\U0001f469", font=font, embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/cbdt_notocoloremoji.png", 6.2)
except IOError as e:
except IOError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or unsupported")
pytest.skip("freetype compiled without libpng or CBDT support")

@skip_unless_feature_version("freetype2", "2.5.0")
def test_cbdt_mask(self):
Expand All @@ -893,9 +893,47 @@ def test_cbdt_mask(self):
assert_image_similar_tofile(
im, "Tests/images/cbdt_notocoloremoji_mask.png", 6.2
)
except IOError as e:
except IOError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or unsupported")
pytest.skip("freetype compiled without libpng or CBDT support")

@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", font=font, embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/chromacheck-sbix.png", 1)
except IOError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or SBIX support")

@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)

assert_image_similar_tofile(im, "Tests/images/chromacheck-sbix_mask.png", 1)
except IOError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or SBIX support")

@skip_unless_feature_version("freetype2", "2.10.0")
def test_colr(self):
Expand All @@ -908,7 +946,7 @@ def test_colr(self):
im = Image.new("RGB", (300, 75), "white")
d = ImageDraw.Draw(im)

d.text((15, 5), "Bungee", embedded_color=True, font=font)
d.text((15, 5), "Bungee", font=font, embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/colr_bungee.png", 21)

Expand Down
10 changes: 5 additions & 5 deletions docs/reference/ImageDraw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ Methods

.. 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

Expand Down Expand Up @@ -413,7 +413,7 @@ Methods

.. 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

Expand Down Expand Up @@ -577,7 +577,7 @@ Methods
correct substitutions as appropriate, if available.
It should be a `BCP 47 language code`_.
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)

Expand Down Expand Up @@ -626,7 +626,7 @@ Methods
It should be a `BCP 47 language code`_.
Requires libraqm.
: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)

Expand Down Expand Up @@ -669,7 +669,7 @@ Methods
It should be a `BCP 47 language code`_.
Requires libraqm.
: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)

Expand Down
3 changes: 2 additions & 1 deletion docs/releasenotes/8.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ now support fonts with embedded color data.
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 SBIX fonts requires FreeType 2.5.1 compiled with libpng.
Support for COLR fonts requires FreeType 2.10.
SBIX and SVG fonts are not yet supported.
SVG fonts are not yet supported.

ImageDraw.textlength
^^^^^^^^^^^^^^^^^^^^
Expand Down