Skip to content

Commit de8799d

Browse files
committed
Only return unique names
1 parent eaf71b2 commit de8799d

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed
43.8 KB
Binary file not shown.

Tests/fonts/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
NotoNastaliqUrdu-Regular.ttf and NotoSansSymbols-Regular.ttf, from https://github.com/googlei18n/noto-fonts
33
NotoSans-Regular.ttf, from https://www.google.com/get/noto/
44
NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/
5-
AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype
5+
AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype. AdobeVFPrototypeDuplicates.ttf is a modified version of this
66
TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny
77
ArefRuqaa-Regular.ttf, from https://github.com/google/fonts/tree/master/ofl/arefruqaa
88
ter-x20b.pcf, from http://terminus-font.sourceforge.net/

Tests/test_imagefont.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,21 @@ def test_variation_get(font: ImageFont.FreeTypeFont) -> None:
742742
]
743743

744744

745+
def test_variation_duplicates() -> None:
746+
font = ImageFont.truetype("Tests/fonts/AdobeVFPrototypeDuplicates.ttf")
747+
assert font.get_variation_names(), [
748+
b"ExtraLight",
749+
b"Light",
750+
b"Regular",
751+
b"Semibold",
752+
b"Bold",
753+
b"Black",
754+
b"Black Medium Contrast",
755+
b"Black High Contrast",
756+
b"Default",
757+
]
758+
759+
745760
def _check_text(font: ImageFont.FreeTypeFont, path: str, epsilon: float) -> None:
746761
im = Image.new("RGB", (100, 75), "white")
747762
d = ImageDraw.Draw(im)

src/PIL/ImageFont.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,12 @@ def get_variation_names(self) -> list[bytes]:
675675
:returns: A list of the named styles in a variation font.
676676
:exception OSError: If the font is not a variation font.
677677
"""
678-
names = self.font.getvarnames()
679-
return [name.replace(b"\x00", b"") for name in names]
678+
names = []
679+
for name in self.font.getvarnames():
680+
name = name.replace(b"\x00", b"")
681+
if name not in names:
682+
names.append(name)
683+
return names
680684

681685
def set_variation_by_name(self, name: str | bytes) -> None:
682686
"""

0 commit comments

Comments
 (0)