-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Allow for duplicate font variation styles #9362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9fc7d10 to
de8799d
Compare
de8799d to
b2b7dc2
Compare
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
|
Hmmm, I've worked with the TTF file a bit now, and I think the variants are different - even though they have a same name - and it might be necessary to number them (#1, #2, ...) similar to how Gimp does it or so, otherwise selecting them becomes possible only by using the index number, which isn't returned either. That font is file is properly horrible. :-/ |
|
The idea of adding variation name suffixes is a bit concerning from a theoretical standpoint - there's nothing stopping the font from already having both Would it help if I provided a modified version of the font file, that uses |
|
Thanks, a bit - but finding a solution working generically would be better, I think. sigh .. what a beepshow. I've scanned the font with #!/usr/bin/env python3
from PIL import ImageFont
import pprint
ttf = ImageFont.truetype(font='Kario39C3Var-Roman.ttf', index=0)
#pprint.pp(ttf.font.getvarnames())
for i in range(4294967296+1):
try:
print("{} (face={}): {}".format('Kario39C3Var-Roman.ttf', i, ttf.font_variant(index=i).getname()), flush=True)
except IOError as e:
pass(yeah yeah I know about the const being ridiculous, and I cancelled early) this way, I could identify the right fonts and use the indicies in a hardcoded for what I need. |
|
While I do still think that this font is flawed, I've created #9376 to offer a solution. It would show the duplicates in from PIL import ImageFont
font = ImageFont.truetype('Kario39C3Var-Roman.ttf')
for i, name in enumerate(font.get_variation_names()):
print("Index", i, "Name", name)
font.set_variation_by_name_index(i) |
|
Yupp, that font is horribly flawed, but said fix would help me and potential other running problems with similar fonts. Thanks for the super quick and helpful interactions, and a happy, healthy new year! 😍 |
|
I'm not sure if it's worth adding (and maintaining) extra APIs to support horribly flawed fonts. |
|
If you're willing to accept a solution using our private APIs (with the disclaimer that we feel the freedom to change them in the future without warning), then with Pillow 12.1.0, you could use the following code. from PIL import ImageFont
font = ImageFont.truetype('Kario39C3Var-Roman.ttf')
names = [name.replace(b"\x00", b"") for name in font.font.getvarnames()]
for i, name in enumerate(names):
print("Index", i, "Name", name)
font.font.setvarname(i+1) |
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [pillow](https://github.com/python-pillow/Pillow) ([changelog](https://github.com/python-pillow/Pillow/releases)) | `<12.0.1,>=12.0.0` → `<12.1.1,>=12.1.0` |  |  | --- ### Release Notes <details> <summary>python-pillow/Pillow (pillow)</summary> ### [`v12.1.0`](https://github.com/python-pillow/Pillow/releases/tag/12.1.0) [Compare Source](python-pillow/Pillow@12.0.0...12.1.0) <https://pillow.readthedocs.io/en/stable/releasenotes/12.1.0.html> #### Deprecations - Deprecate getdata(), in favour of new get\_flattened\_data() [#​9292](python-pillow/Pillow#9292) \[[@​radarhere](https://github.com/radarhere)] #### Documentation - Specify APNG duration type when opening [#​9368](python-pillow/Pillow#9368) \[[@​radarhere](https://github.com/radarhere)] - Added release notes for [#​9350](python-pillow/Pillow#9350) [#​9366](python-pillow/Pillow#9366) \[[@​radarhere](https://github.com/radarhere)] - Update ImageMorph documentation [#​9349](python-pillow/Pillow#9349) \[[@​radarhere](https://github.com/radarhere)] - Docs: update major bump cadence [#​9334](python-pillow/Pillow#9334) \[[@​hugovk](https://github.com/hugovk)] - Add release notes for [#​9070](python-pillow/Pillow#9070) [#​9320](python-pillow/Pillow#9320) \[[@​radarhere](https://github.com/radarhere)] - Updated Ubuntu version [#​9306](python-pillow/Pillow#9306) \[[@​radarhere](https://github.com/radarhere)] - Update macOS tested Pillow versions [#​9265](python-pillow/Pillow#9265) \[[@​radarhere](https://github.com/radarhere)] #### Dependencies - Update harfbuzz to 12.3.0 [#​9355](python-pillow/Pillow#9355) \[[@​radarhere](https://github.com/radarhere)] - Update xz to 5.8.2 [#​9343](python-pillow/Pillow#9343) \[[@​radarhere](https://github.com/radarhere)] - Updated libjpeg-turbo to 3.1.3 [#​9333](python-pillow/Pillow#9333) \[[@​radarhere](https://github.com/radarhere)] - Updated zlib-ng to 2.3.2 [#​9324](python-pillow/Pillow#9324) \[[@​radarhere](https://github.com/radarhere)] - Updated libpng to 1.6.53 [#​9325](python-pillow/Pillow#9325) \[[@​radarhere](https://github.com/radarhere)] - Update actions/checkout action to v6 [#​9323](python-pillow/Pillow#9323) \[@​[renovate\[bot\]](https://github.com/apps/renovate)] - Update dependency mypy to v1.19.0 [#​9322](python-pillow/Pillow#9322) \[@​[renovate\[bot\]](https://github.com/apps/renovate)] - Updated libpng to 1.6.51 [#​9305](python-pillow/Pillow#9305) \[[@​radarhere](https://github.com/radarhere)] - Updated brotli to 1.2.0 [#​9284](python-pillow/Pillow#9284) \[[@​radarhere](https://github.com/radarhere)] - Update libimagequant to 4.4.1 [#​9301](python-pillow/Pillow#9301) \[[@​radarhere](https://github.com/radarhere)] - Update zlib-ng to 2.3.1, except on manylinux2014 aarch64 [#​9312](python-pillow/Pillow#9312) \[[@​radarhere](https://github.com/radarhere)] - Updated harfbuzz to 12.2.0 [#​9289](python-pillow/Pillow#9289) \[[@​radarhere](https://github.com/radarhere)] - Update github-actions [#​9277](python-pillow/Pillow#9277) \[@​[renovate\[bot\]](https://github.com/apps/renovate)] #### Testing - Replace pre-commit with prek [#​9360](python-pillow/Pillow#9360) \[[@​hugovk](https://github.com/hugovk)] - Test PyQt6 on Python 3.14 on Windows [#​9353](python-pillow/Pillow#9353) \[[@​radarhere](https://github.com/radarhere)] - Test 32-bit Windows on Windows Server 2022 [#​9345](python-pillow/Pillow#9345) \[[@​radarhere](https://github.com/radarhere)] - Correct variable type [#​9335](python-pillow/Pillow#9335) \[[@​radarhere](https://github.com/radarhere)] - Fix `ResourceWarning`s in `selftest.py` [#​9332](python-pillow/Pillow#9332) \[[@​hugovk](https://github.com/hugovk)] - Fix testing good P mode BMP images [#​9319](python-pillow/Pillow#9319) \[[@​radarhere](https://github.com/radarhere)] - Test Python 3.15 pre-release [#​9331](python-pillow/Pillow#9331) \[[@​hugovk](https://github.com/hugovk)] - Test ImageFont.ImageFont, in case freetype2 is not supported [#​9287](python-pillow/Pillow#9287) \[[@​radarhere](https://github.com/radarhere)] - Add Fedora 43 [#​9290](python-pillow/Pillow#9290) \[[@​radarhere](https://github.com/radarhere)] - Remove Fedora 41 [#​9260](python-pillow/Pillow#9260) \[[@​radarhere](https://github.com/radarhere)] #### Type hints - Add ImageFile context manager [#​9367](python-pillow/Pillow#9367) \[[@​radarhere](https://github.com/radarhere)] - Assert fp is not None [#​8617](python-pillow/Pillow#8617) \[[@​radarhere](https://github.com/radarhere)] - Added return type to ImageFile \_close\_fp() [#​9356](python-pillow/Pillow#9356) \[[@​radarhere](https://github.com/radarhere)] - Use different variables for Image and ImageFile instances [#​9316](python-pillow/Pillow#9316) \[[@​radarhere](https://github.com/radarhere)] - Correct variable type [#​9335](python-pillow/Pillow#9335) \[[@​radarhere](https://github.com/radarhere)] - Improve type hints [#​9317](python-pillow/Pillow#9317) \[[@​radarhere](https://github.com/radarhere)] - Use different variables for Image and ImageFile instances [#​9268](python-pillow/Pillow#9268) \[[@​radarhere](https://github.com/radarhere)] - Added type hints [#​9269](python-pillow/Pillow#9269) \[[@​radarhere](https://github.com/radarhere)] - Correct **getitem** return type [#​9264](python-pillow/Pillow#9264) \[[@​radarhere](https://github.com/radarhere)] #### Other changes - Simplify band splitting [#​9291](python-pillow/Pillow#9291) \[[@​radarhere](https://github.com/radarhere)] - Support saving APNG float durations [#​9365](python-pillow/Pillow#9365) \[[@​radarhere](https://github.com/radarhere)] - Allow 1 mode images in MorphOp [#​9348](python-pillow/Pillow#9348) \[[@​radarhere](https://github.com/radarhere)] - Use minimum supported Python version for Lint [#​9364](python-pillow/Pillow#9364) \[[@​radarhere](https://github.com/radarhere)] - Allow for duplicate font variation styles [#​9362](python-pillow/Pillow#9362) \[[@​radarhere](https://github.com/radarhere)] - Call parent verify method [#​9357](python-pillow/Pillow#9357) \[[@​radarhere](https://github.com/radarhere)] - Return LUT from LutBuilder build\_default\_lut() [#​9350](python-pillow/Pillow#9350) \[[@​radarhere](https://github.com/radarhere)] - Simplify WebP code [#​9329](python-pillow/Pillow#9329) \[[@​radarhere](https://github.com/radarhere)] - Use unsigned long for DWORD [#​9352](python-pillow/Pillow#9352) \[[@​radarhere](https://github.com/radarhere)] - Cast to UINT32 before shifting bits [#​9347](python-pillow/Pillow#9347) \[[@​radarhere](https://github.com/radarhere)] - \[pre-commit.ci] pre-commit autoupdate [#​9318](python-pillow/Pillow#9318) \[@​[pre-commit-ci\[bot\]](https://github.com/apps/pre-commit-ci)] - Allow window ID to be passed to ImageGrab.grab() on macOS [#​9070](python-pillow/Pillow#9070) \[[@​yankeguo](https://github.com/yankeguo)] - Apply encoder options when saving multiple PNG frames [#​9300](python-pillow/Pillow#9300) \[[@​radarhere](https://github.com/radarhere)] - Read all non-zero transparency from mode 1 PNG images as 255 [#​9282](python-pillow/Pillow#9282) \[[@​radarhere](https://github.com/radarhere)] - Support writing IFD, SIGNED\_RATIONAL and InkNames TIFF tags [#​9276](python-pillow/Pillow#9276) \[[@​radarhere](https://github.com/radarhere)] - Remove unused modes [#​9275](python-pillow/Pillow#9275) \[[@​radarhere](https://github.com/radarhere)] - Correct allocating new color to RGBA palette [#​9313](python-pillow/Pillow#9313) \[[@​radarhere](https://github.com/radarhere)] - Close image on ImageFont exception [#​9304](python-pillow/Pillow#9304) \[[@​radarhere](https://github.com/radarhere)] - Reapply "Use macos-latest for iOS arm64 simulator" [#​9259](python-pillow/Pillow#9259) \[[@​radarhere](https://github.com/radarhere)] - Escape period in pre-commit-config [#​9036](python-pillow/Pillow#9036) \[[@​radarhere](https://github.com/radarhere)] - Add Apache-2.0 notice to IcoImagePlugin [#​8947](python-pillow/Pillow#8947) \[[@​stefan6419846](https://github.com/stefan6419846)] - \[pre-commit.ci] pre-commit autoupdate [#​9288](python-pillow/Pillow#9288) \[@​[pre-commit-ci\[bot\]](https://github.com/apps/pre-commit-ci)] - Simplify code now that I;16\* modes are the only IMAGING\_TYPE\_SPECIAL [#​9263](python-pillow/Pillow#9263) \[[@​radarhere](https://github.com/radarhere)] - Remove BytesIO from DdsImagePlugin [#​9273](python-pillow/Pillow#9273) \[[@​radarhere](https://github.com/radarhere)] - Fix ZeroDivisionError in DdsImagePlugin [#​9272](python-pillow/Pillow#9272) \[[@​radarhere](https://github.com/radarhere)] - Fix warnings [#​9257](python-pillow/Pillow#9257) \[[@​radarhere](https://github.com/radarhere)] </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi42OS4yIiwidXBkYXRlZEluVmVyIjoiNDIuNjkuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsidHlwZS9kZXBlbmRlbmNpZXMiXX0=--> Reviewed-on: https://git.tainton.uk/repos/webexmemebot/pulls/542 Co-authored-by: renovate[bot] <renovate-bot@git.tainton.uk> Co-committed-by: renovate[bot] <renovate-bot@git.tainton.uk>
Resolves #9361
Within
font_getvarnames(), our code goes through the names, and once the ID of a name matches the ID of a style, it breaks. It presumes that eachmaster->namedstylewould have a unique ID.Pillow/src/_imagingft.c
Lines 1280 to 1291 in 2ebb3e9
The font found in the issue has two styles with the same ID. To allow for this, we should no longer break and continue to go through the loop. Once the list has been populated in C, Python can remove the duplicate result.
I created a test font here from our existing AdobeVFPrototype.ttf using ttx.