Skip to content

Commit

Permalink
Fixed set_variation_by_name offset
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 16, 2022
1 parent d53344b commit 3b9f7d7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
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.
2 changes: 2 additions & 0 deletions Tests/test_imagefont.py
Expand Up @@ -769,12 +769,14 @@ def test_variation_set_by_name(self):
self._check_text(font, "Tests/images/variation_adobe.png", 11)
for name in ["Bold", b"Bold"]:
font.set_variation_by_name(name)
assert font.getname()[1] == "Bold"
self._check_text(font, "Tests/images/variation_adobe_name.png", 11)

font = ImageFont.truetype("Tests/fonts/TINY5x3GX.ttf", 36)
self._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"
self._check_text(font, "Tests/images/variation_tiny_name.png", 40)

def test_variation_set_by_axes(self):
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFont.py
Expand Up @@ -795,7 +795,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 3b9f7d7

Please sign in to comment.