mirror of
https://github.com/python-pillow/Pillow.git
synced 2026-01-10 18:51:26 +03:00
Allow for duplicate font variation styles (#9362)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
2ebfe30ae3
commit
d62955031b
BIN
Tests/fonts/AdobeVFPrototypeDuplicates.ttf
Normal file
BIN
Tests/fonts/AdobeVFPrototypeDuplicates.ttf
Normal file
Binary file not shown.
|
|
@ -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/
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -675,8 +675,12 @@ class FreeTypeFont:
|
|||
: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:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1287,7 +1287,6 @@ font_getvarnames(FontObject *self) {
|
|||
}
|
||||
PyList_SetItem(list_names, j, list_name);
|
||||
list_names_filled[j] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user