Skip to content

Commit

Permalink
Merge pull request #6445 from radarhere/set_variation_by_name
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 28, 2022
2 parents fb0e7cd + 17b56b9 commit 31f66ea
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
Binary file modified Tests/images/variation_adobe_name.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/images/variation_adobe_older_harfbuzz_name.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Tests/test_imagefont.py
Expand Up @@ -746,12 +746,14 @@ def test_variation_set_by_name(font):
_check_text(font, "Tests/images/variation_adobe.png", 11)
for name in ["Bold", b"Bold"]:
font.set_variation_by_name(name)
_check_text(font, "Tests/images/variation_adobe_name.png", 11)
assert font.getname()[1] == "Bold"
_check_text(font, "Tests/images/variation_adobe_name.png", 16)

font = ImageFont.truetype("Tests/fonts/TINY5x3GX.ttf", 36)
_check_text(font, "Tests/images/variation_tiny.png", 40)
for name in ["200", b"200"]:
font.set_variation_by_name(name)
assert font.getname()[1] == "200"
_check_text(font, "Tests/images/variation_tiny_name.png", 40)


Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFont.py
Expand Up @@ -803,7 +803,7 @@ def set_variation_by_name(self, name):
names = self.get_variation_names()
if not isinstance(name, bytes):
name = name.encode()
index = names.index(name)
index = names.index(name) + 1

if index == getattr(self, "_last_variation_index", None):
# When the same name is set twice in a row,
Expand Down

0 comments on commit 31f66ea

Please sign in to comment.