typemytype / drawbot

http://www.drawbot.com
Other
398 stars 61 forks source link

listNamedInstances return wrong value #495

Open HugoJourdan opened 1 year ago

HugoJourdan commented 1 year ago

Hi,

I tried recently to get instances name of a variable using listNamedInstances(fontPath) I tried different variable font (mine and some from Google Font) and the function always return an OrderedDict which contain only the first instance.

Here are some results with Google Fonts :

OpenSans OrderedDict([('OpenSansRoman-Light', {'wght': 800.0, 'wdth': 75.0})])

Montserrat OrderedDict([('Montserrat-Thin', {'wght': 900.0})])

Raleway OrderedDict([('Raleway-Thin', {'wght': 900.0})])

Inter OrderedDict([('Inter-Regular_Thin', {'wght': 900.0, 'slnt': -10.0})])

justvanrossum commented 1 year ago

I can't reproduce this on macOS 10.15. Which OS are you on?

HugoJourdan commented 1 year ago

I'm under macOS Ventura 13.0 and I'm pretty sure it's because of it. It was working fine before this update.

typemytype commented 1 year ago

works fine on Ventura..

image

did you install the fonts? and you dont have any duplicates installed?

HugoJourdan commented 1 year ago

There is something strange, print(platform.mac_ver()), return me 10.16 instead of 13.0

[image: Capture d’écran 2022-12-19 à 14.16.44.png]

Le lun. 19 déc. 2022 à 14:10, Frederik Berlaen @.***> a écrit :

works fine on Ventura..

[image: image] https://user-images.githubusercontent.com/1190358/208433139-28658e0d-a5fd-4473-8462-9cc6ac960895.png

did you install the fonts? and you dont have any duplicates installed?

— Reply to this email directly, view it on GitHub https://github.com/typemytype/drawbot/issues/495#issuecomment-1357644602, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASJ4QX4BCMRM5WNKKOEXVE3WOBNCTANCNFSM6AAAAAATCBUGPA . You are receiving this because you authored the thread.Message ID: @.***>

-- Hugo Jourdan [ Type Designer ] & [ Font Engineer ] Paris, France Instagram https://www.instagram.com/hjxdesign – Behance https://www.behance.net/Hugo_Jourdan – GitHub https://github.com/HugoJourdan

HugoJourdan commented 1 year ago

I tried to run the same command in VSCode and in Terminal both return me correct OS Version:

[image: Capture d’écran 2022-12-19 à 14.42.22.png]

Le lun. 19 déc. 2022 à 14:18, Hugo Jourdan @.***> a écrit :

There is something strange, print(platform.mac_ver()), return me 10.16 instead of 13.0

[image: Capture d’écran 2022-12-19 à 14.16.44.png]

Le lun. 19 déc. 2022 à 14:10, Frederik Berlaen @.***> a écrit :

works fine on Ventura..

[image: image] https://user-images.githubusercontent.com/1190358/208433139-28658e0d-a5fd-4473-8462-9cc6ac960895.png

did you install the fonts? and you dont have any duplicates installed?

— Reply to this email directly, view it on GitHub https://github.com/typemytype/drawbot/issues/495#issuecomment-1357644602, or unsubscribe https://github.com/notifications/unsubscribe-auth/ASJ4QX4BCMRM5WNKKOEXVE3WOBNCTANCNFSM6AAAAAATCBUGPA . You are receiving this because you authored the thread.Message ID: @.***>

-- Hugo Jourdan [ Type Designer ] & [ Font Engineer ] Paris, France Instagram https://www.instagram.com/hjxdesign – Behance https://www.behance.net/Hugo_Jourdan – GitHub https://github.com/HugoJourdan

-- Hugo Jourdan [ Type Designer ] & [ Font Engineer ] Paris, France Instagram https://www.instagram.com/hjxdesign – Behance https://www.behance.net/Hugo_Jourdan – GitHub https://github.com/HugoJourdan

HugoJourdan commented 1 year ago

Any news about this issue ? Why print(platform.mac_ver()) return me wrong value ?

justvanrossum commented 1 year ago

Don't worry about the "10.16" oddity that is unlikely to be related. (11 came after 10.15, so in some weird internal way, 10.16 is 11.)

Can you try with a font by using its file path? Like so:

font("/path/to/font/file.ttf")
HugoJourdan commented 1 year ago

I did this with every font I tested. None of them were installed.

Capture d’écran 2023-01-10 à 15 15 05

HugoJourdan commented 1 year ago

Note that same font return 2 instances :

Capture d’écran 2023-01-10 à 15 16 41

HugoJourdan commented 1 year ago

But @typemytype under Ventura, has the right OS version with the command. And this bug has appeared after switching on Ventura.

justvanrossum commented 1 year ago

But @typemytype under Ventura, has the right OS version with the command. And this bug has appeared after switching on Ventura.

You're right, I missed that, and that is very curious after all.

I'm assuming you are using DrawBot 3.128, as downloaded from drawbot.com? Can you see if you get any different results with 3.129?

HugoJourdan commented 1 year ago

I already installed DrawBot 3.129. I tried to uninstall/re-install but nothing changed.

HugoJourdan commented 1 year ago

Something also strange if I run :

print(open('/System/Library/CoreServices/SystemVersion.plist').read())

I got this :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ProductBuildVersion</key>
    <string>22C65</string>
    <key>ProductCopyright</key>
    <string>1983-2022 Apple Inc.</string>
    <key>ProductName</key>
    <string>Mac OS X</string>
    <key>ProductUserVisibleVersion</key>
    <string>10.16</string>
    <key>ProductVersion</key>
    <string>10.16</string>
    <key>iOSSupportVersion</key>
    <string>16.2</string>
</dict>
</plist>

But these infos are wrong. This is a screenshot of this .plist file with Xcode: Capture d’écran 2023-01-10 à 15 25 40

typemytype commented 1 year ago

I have no idea, sorry..

10.16 was Big Sur macOS 11.0 beta at some point

HugoJourdan commented 1 year ago

In drawBot, print(sys.version), return :

3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:23:25) 
[Clang 6.0 (clang-600.0.57)]

Where terminal or VSCode return :

3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23) 
[Clang 13.0.0 (clang-1300.0.29.30)]

Clang version is not the same.

HugoJourdan commented 1 year ago

I friend under MacOS Monterey (12.5.1) got the same problem.

import sys
import platform

print(sys.version)
print(platform.mac_ver())

FONT = pathtoOpenSans
print(listNamedInstances(FONT))

RETURN

3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:23:25) 
[Clang 6.0 (clang-600.0.57)]
('10.16', ('', '', ''), 'x86_64')
OrderedDict([('OpenSans-Italic', {'wght': 800.0, 'wdth': 75.0})])

We are both using a MacBook Pro M1. @typemytype are on M1 or Intel ?

HugoJourdan commented 1 year ago

Using ttLib, I can have access to all instances :

from fontTools import ttLib

FONT = pathToVariableFont
ft = ttLib.TTFont(FONT, lazy=True, fontNumber=0)
if "fvar" in ft:
    fvar = ft["fvar"]

tagNameMap = {"wght":"Weight", "wdth":"Width"}

for instance in fvar.instances:
    fontVariations = dict()
    for axis, value in instance.coordinates.items():
        fontVariations[tagNameMap[axis]] = value
    print(fontVariations)

Maybe the problem come from CoreText ?

HugoJourdan commented 1 year ago

I tested it with another Mac Intel, and I got the same issue.

Capture d’écran 2023-01-10 à 18 21 12

typemytype commented 1 year ago

yes M1,

really sorry, I cannot reproduce it... I just re-tested with the latest DrawBot with a fresh download of OpenSans https://fonts.google.com/download?family=Open%20Sans

image
typemytype commented 1 year ago

something really silly: My systems language is set to English

do you see the named instances in other apps when the font is installed?

image
HugoJourdan commented 1 year ago

I see named instances in other apps... It's very weird bug :/

For now, I will manually get the names with fontTools

justvanrossum commented 1 year ago

I just got a second report for the same problem (Cc @martelahaie)

Perhaps CoreText.CGFontCopyPostScriptName is not returning a unique name for each instance, so each instance uses the same key in the instances dict, leaving us with a single entry.

https://github.com/typemytype/drawbot/blob/60952e5db162aaae260ac83c3f7838c94771b2e2/drawBot/context/tools/variation.py#L85-L86

typemytype commented 1 year ago

did some digging with @martelahaie and we found out that the OS system language setting seems to be responsible... When she switches from Dutch to English all named instances appear in DrawBot.

@HugoJourdan I assume your system language is French..

this is so silly and I have no idea how to even support this...

typemytype commented 1 year ago

@martelahaie is on 12.6 and Im on 13.1 and its is reproducible on both systems

HugoJourdan commented 1 year ago

Yes, I'm using French. Switching to "English" work for me too.