Skip to content
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

The set_variation_by_name method of FreeTypeFont is inconsistent with the result #6439

Closed
A-kirami opened this issue Jul 15, 2022 · 1 comment · Fixed by #6445
Closed

The set_variation_by_name method of FreeTypeFont is inconsistent with the result #6439

A-kirami opened this issue Jul 15, 2022 · 1 comment · Fixed by #6445
Labels

Comments

@A-kirami
Copy link

What did you do?

Traverse the font style of setting variation font.

What did you expect to happen?

The style changes every time you set it.

What actually happened?

The first one is visually the same as the second one. At the same time, the style obtained by getname() is inconsistent with the setting of set_variation_by_name().

variation_axes = [{'minimum': 300, 'default': 300, 'maximum': 700, 'name': b'Weight'}]
variation_names = [b'Light', b'Regular', b'Medium', b'SemiBold', b'Bold']
initial:  ('Fira Code', 'Light')
set_variation_by_name: b'Light', get_name:  ('Fira Code', 'Light')
set_variation_by_name: b'Regular', get_name:  ('Fira Code', 'Light')
set_variation_by_name: b'Medium', get_name:  ('Fira Code', 'Regular')
set_variation_by_name: b'SemiBold', get_name:  ('Fira Code', 'Medium')
set_variation_by_name: b'Bold', get_name:  ('Fira Code', 'SemiBold')

For comparison, I used Photoshop.

image

What are your OS, Python and Pillow versions?

  • OS: Windows11
  • Python: 3.10.0
  • Pillow: 9.2.0
from PIL import Image, ImageDraw, ImageFont

VF = ImageFont.FreeTypeFont("FiraCode-VF.ttf", size=72)

variation_axes = VF.get_variation_axes()
variation_names = VF.get_variation_names()

print(f"{variation_axes = }")
print(f"{variation_names = }")
print("initial: ", VF.getname())

img = Image.new("RGBA", (260, 100 * len(variation_names)))
draw = ImageDraw.Draw(img)

for i, name in enumerate(VF.get_variation_names()):
    VF.set_variation_by_name(name)
    print(f"set_variation_by_name: {name}, get_name: ", VF.getname())
    draw.text((0, i * 80), "Hello", font=VF, fill="#000000")

img.show()

Font files can be found here: tonsky/FiraCode

@radarhere
Copy link
Member

I've created PR #6445 to resolve this.

@A-kirami A-kirami changed the title The get_variation_names method of FreeTypeFont is inconsistent with the result The set_variation_by_name method of FreeTypeFont is inconsistent with the result Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants