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

Support for Variable fonts. #297

Open
stribor opened this issue Feb 26, 2025 · 1 comment
Open

Support for Variable fonts. #297

stribor opened this issue Feb 26, 2025 · 1 comment

Comments

@stribor
Copy link

stribor commented Feb 26, 2025

I'm trying to create PDF on macOS using variable font. I.e. New York font downloaded from https://developer.apple.com/fonts/

Once installed, otfinfo --variable /Library/Fonts/NewYork.ttf produces following info:

Axis 0:                 opsz
Axis 0 name:            Optical Size
Axis 0 range:           12 256
Axis 0 default:         256
Axis 1:                 wght
Axis 1 name:            Weight
Axis 1 range:           400 1000
Axis 1 default:         400
Instance 0 name:        Regular
Instance 0 position:    256 400
Instance 1 name:        Medium
Instance 1 position:    256 496
Instance 2 name:        Semibold
Instance 2 position:    256 568
Instance 3 name:        Bold
Instance 3 position:    256 674
Instance 4 name:        Heavy
Instance 4 position:    256 810
Instance 5 name:        Black
Instance 5 position:    256 934

When used in this font, passing index 0, font doesn't look like "Regular" but thinner.

According to FreeType documentation, I could pass in font index << 16 to get to named instance and i.e. pass 0x4000 to get to the Bold variant. So I tried passing this to PDFWriter::GetFontForFile("/Library/Fonts/NewYork.ttf", 0x4000);

Which almost worked. As it seems as correct style name/postscript name gets extracted and AAAAAB+NewYork-Bold resource gets added to generated PDF. But font looks odd or thin, (looks the same as if 0 was passed for fontIndex).

I tried to look into how it gets embedded and came to the TrueTypeEmbeddedFontWriter::WriteGlyf(const UIntVector& inSubsetGlyphIDs,std::vector<unsigned long> &inLocaTable) that from what I figured simply copies from the .ttf file glyph data without actually applying variable transformations and being able to use font properly.

I'm trying but seems way over my head so far:

I see there is code in FreeTypeFaceWrapper::GetGlyphOutline that uses FT_Outline_Decompose to extract the glyph data, and from what I understand this should already have the correct axis data set based on font index passed. And my idea is to use that somehow and write glyf data instead of copying raw data from font file, and this is where I'm stuck at the moment.

I was hoping you might have better idea/solution for the problem.

@galkahana
Copy link
Owner

There is no support for variable fonts with the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants