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

Round box position to integer when pasting embedded color #6517

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Merge branch 'main' into multiline_centered_embedded_color
  • Loading branch information
radarhere committed Sep 16, 2022
commit 166654d985b64c8a084dc9cf9cb574f685ed3dc3
158 changes: 22 additions & 136 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,153 +935,39 @@ def test_standard_embedded_color(layout_engine):
d = ImageDraw.Draw(im)
d.text((10, 10), txt, font=ttf, fill="#fa6", embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/standard_embedded.png", 6.2)
assert_image_similar_tofile(im, "Tests/images/standard_embedded.png", 3.1)


def test_cbdt(layout_engine):
try:
font = ImageFont.truetype(
"Tests/fonts/NotoColorEmoji.ttf", size=109, layout_engine=layout_engine
)

im = Image.new("RGB", (160, 35), "white")
draw = ImageDraw.Draw(im)
draw.text((2, 2), text, "black", font)

assert_image_equal_tofile(im, target)

def test_bitmap_font_stroke(self):
text = "Bitmap Font"
layout_name = ["basic", "raqm"][self.LAYOUT_ENGINE]
target = f"Tests/images/bitmap_font_stroke_{layout_name}.png"
font = ImageFont.truetype(
"Tests/fonts/DejaVuSans/DejaVuSans-24-8-stripped.ttf",
24,
layout_engine=self.LAYOUT_ENGINE,
)

im = Image.new("RGB", (160, 35), "white")
draw = ImageDraw.Draw(im)
draw.text((2, 2), text, "black", font, stroke_width=2, stroke_fill="red")

assert_image_similar_tofile(im, target, 0.03)

def test_standard_embedded_color(self):
txt = "Hello World!"
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE)
ttf.getbbox(txt)

im = Image.new("RGB", (300, 64), "white")
d = ImageDraw.Draw(im)
d.text((10, 10), txt, font=ttf, fill="#fa6", embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/standard_embedded.png", 3.1)

@pytest.mark.parametrize("fontmode", ("1", "L", "RGBA"))
def test_float_coord(self, fontmode):
txt = "Hello World!"
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=self.LAYOUT_ENGINE)

im = Image.new("RGB", (300, 64), "white")
d = ImageDraw.Draw(im)
if fontmode == "1":
d.fontmode = "1"

embedded_color = fontmode == "RGBA"
d.text((9.5, 9.5), txt, font=ttf, fill="#fa6", embedded_color=embedded_color)
try:
assert_image_similar_tofile(im, "Tests/images/text_float_coord.png", 3.9)
except AssertionError:
if fontmode == "1" and self.LAYOUT_ENGINE == ImageFont.Layout.BASIC:
assert_image_similar_tofile(
im, "Tests/images/text_float_coord_1_alt.png", 1
)
else:
raise

def test_cbdt(self):
try:
font = ImageFont.truetype(
"Tests/fonts/NotoColorEmoji.ttf",
size=109,
layout_engine=self.LAYOUT_ENGINE,
)

im = Image.new("RGB", (150, 150), "white")
d = ImageDraw.Draw(im)

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

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

def test_cbdt_mask(self):
try:
font = ImageFont.truetype(
"Tests/fonts/NotoColorEmoji.ttf",
size=109,
layout_engine=self.LAYOUT_ENGINE,
)

im = Image.new("RGB", (150, 150), "white")
d = ImageDraw.Draw(im)
@pytest.mark.parametrize("fontmode", ("1", "L", "RGBA"))
def test_float_coord(layout_engine, fontmode):
txt = "Hello World!"
ttf = ImageFont.truetype(FONT_PATH, 40, layout_engine=layout_engine)

d.text((10, 10), "\U0001f469", "black", font=font)
im = Image.new("RGB", (300, 64), "white")
d = ImageDraw.Draw(im)
if fontmode == "1":
d.fontmode = "1"

embedded_color = fontmode == "RGBA"
d.text((9.5, 9.5), txt, font=ttf, fill="#fa6", embedded_color=embedded_color)
try:
assert_image_similar_tofile(im, "Tests/images/text_float_coord.png", 3.9)
except AssertionError:
if fontmode == "1" and layout_engine == ImageFont.Layout.BASIC:
assert_image_similar_tofile(
im, "Tests/images/cbdt_notocoloremoji_mask.png", 6.2
im, "Tests/images/text_float_coord_1_alt.png", 1
)
except OSError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or CBDT support")

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 OSError as e: # pragma: no cover
assert str(e) in ("unimplemented feature", "unknown file format")
pytest.skip("freetype compiled without libpng or SBIX support")

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)
else:
raise

assert_image_similar_tofile(im, "Tests/images/chromacheck-sbix_mask.png", 1)
except OSError 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):
def test_cbdt(layout_engine):
try:
font = ImageFont.truetype(
"Tests/fonts/BungeeColor-Regular_colr_Windows.ttf",
size=64,
layout_engine=self.LAYOUT_ENGINE,
"Tests/fonts/NotoColorEmoji.ttf", size=109, layout_engine=layout_engine
)

im = Image.new("RGB", (300, 75), "white")
im = Image.new("RGB", (150, 150), "white")
d = ImageDraw.Draw(im)

d.text((10, 10), "\U0001f469", font=font, embedded_color=True)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.