-
-
Notifications
You must be signed in to change notification settings - Fork 64
remove FontTools to list named instances #587
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
base: master
Are you sure you want to change the base?
Conversation
|
Alternatively, we could try to use drawbot/drawBot/context/baseContext.py Line 3033 in 5936dd4
|
|
I tried that but did not succeed to add the url in a font descriptor... some attributes are lost while converting from CTFonts to fontDescriptors: # run the script once
# edit the font on disk (different mod time is enough)
path = 'pathToFont.ttf'
from drawBot.context.baseContext import getFontDescriptorsFromPath
import CoreText
descriptors = getFontDescriptorsFromPath(path)
url = CoreText.CTFontDescriptorCopyAttribute(descriptors[0], CoreText.kCTFontURLAttribute)
print(url)
# convert to CTFont
ctfont = CoreText.CTFontCreateWithFontDescriptor(descriptors[0], 10, None)
# convert back to a font descriptor
url = CoreText.CTFontDescriptorCopyAttribute(ctfont.fontDescriptor(), CoreText.kCTFontURLAttribute)
print(url) |
|
That's not what I see happening with this snippet. On the first run it prints the path in both cases, and when I change the font, it prints None for both. Or did you mean I should run this in your branch? |
|
Ok, after poking around, I see what you mean. Odd! |
|
a full example without using the caching DrawBot provides: import AppKit
import CoreText
path = 'pathToFont.ttf'
# create font descriptors from data, so no url available
data = AppKit.NSData.dataWithContentsOfFile_(path)
descriptors = CoreText.CTFontManagerCreateFontDescriptorsFromData(data)
attributes = {
CoreText.kCTFontURLAttribute: AppKit.NSURL.fileURLWithPath_(path)
}
# make a copy with adding attributes
descriptors = [CoreText.CTFontDescriptorCreateCopyWithAttributes(descriptor, attributes) for descriptor in descriptors]
# test attributes
url = CoreText.CTFontDescriptorCopyAttribute(descriptors[0], CoreText.kCTFontURLAttribute)
print(url)
# convert to CTFont
ctfont = CoreText.CTFontCreateWithFontDescriptor(descriptors[0], 10, None)
# convert back to a font descriptor
url = CoreText.CTFontDescriptorCopyAttribute(ctfont.fontDescriptor(), CoreText.kCTFontURLAttribute)
# url is gone
print(url) |
| path = fontNameOrPath | ||
|
|
||
| descriptors = getFontDescriptorsFromPath(path) | ||
| return variation.getNamedInstancesForDescriptors(descriptors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're somehow ignoring fontNumber here.
Yet I don't know what to do, since CTFontManagerCreateFontDescriptorsFromData() does not (can not?) distinguish between "multiple instances in a VF", "multiple statics in a TTC" or even "multiple instances for multiple VFs in a TTC".
fixing #584