Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

The `set_variation_by_name` method of `FreeTypeFont` is inconsistent with the result

Open A-kirami opened this issue 3 years ago • 1 comments

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

A-kirami avatar Jul 15 '22 10:07 A-kirami

I've created PR #6445 to resolve this.

radarhere avatar Jul 16 '22 10:07 radarhere