Skip to content
Open
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
Binary file added Tests/fonts/AdobeVFPrototypeDuplicates.ttf
Binary file not shown.
2 changes: 1 addition & 1 deletion Tests/fonts/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
NotoNastaliqUrdu-Regular.ttf and NotoSansSymbols-Regular.ttf, from https://github.com/googlei18n/noto-fonts
NotoSans-Regular.ttf, from https://www.google.com/get/noto/
NotoSansJP-Thin.otf, from https://www.google.com/get/noto/help/cjk/
AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype
AdobeVFPrototype.ttf, from https://github.com/adobe-fonts/adobe-variable-font-prototype. AdobeVFPrototypeDuplicates.ttf is a modified version of this
TINY5x3GX.ttf, from http://velvetyne.fr/fonts/tiny
ArefRuqaa-Regular.ttf, from https://github.com/google/fonts/tree/master/ofl/arefruqaa
ter-x20b.pcf, from http://terminus-font.sourceforge.net/
Expand Down
17 changes: 16 additions & 1 deletion Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ def test_variation_get(font: ImageFont.FreeTypeFont) -> None:
font.get_variation_axes()

font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf")
assert font.get_variation_names(), [
assert font.get_variation_names() == [
b"ExtraLight",
b"Light",
b"Regular",
Expand Down Expand Up @@ -742,6 +742,21 @@ def test_variation_get(font: ImageFont.FreeTypeFont) -> None:
]


def test_variation_duplicates() -> None:
font = ImageFont.truetype("Tests/fonts/AdobeVFPrototypeDuplicates.ttf")
assert font.get_variation_names() == [
b"ExtraLight",
b"Light",
b"Regular",
b"Semibold",
b"Bold",
b"Black",
b"Black Medium Contrast",
b"Black High Contrast",
b"Default",
]


def _check_text(font: ImageFont.FreeTypeFont, path: str, epsilon: float) -> None:
im = Image.new("RGB", (100, 75), "white")
d = ImageDraw.Draw(im)
Expand Down
8 changes: 6 additions & 2 deletions src/PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,12 @@ def get_variation_names(self) -> list[bytes]:
:returns: A list of the named styles in a variation font.
:exception OSError: If the font is not a variation font.
"""
names = self.font.getvarnames()
return [name.replace(b"\x00", b"") for name in names]
names = []
for name in self.font.getvarnames():
name = name.replace(b"\x00", b"")
if name not in names:
names.append(name)
return names

def set_variation_by_name(self, name: str | bytes) -> None:
"""
Expand Down
1 change: 0 additions & 1 deletion src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,6 @@ font_getvarnames(FontObject *self) {
}
PyList_SetItem(list_names, j, list_name);
list_names_filled[j] = 1;
break;
}
}
}
Expand Down
Loading