Skip to content

Add CFF2 and TrueType Variation Font Support#342

Merged
JimBobSquarePants merged 73 commits intomainfrom
bp/cff2
Mar 11, 2026
Merged

Add CFF2 and TrueType Variation Font Support#342
JimBobSquarePants merged 73 commits intomainfrom
bp/cff2

Conversation

@brianpopow
Copy link
Copy Markdown
Contributor

@brianpopow brianpopow commented Jul 14, 2023

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Fixes #5
Fixes #247
Fixes #331

PR adds support for TrueType and CFF2 variable fonts

Loading a variation is simple.

FontFamily family = new FontCollection().Add(TestFonts.NotoEmojiVariableFont);
Font font = family.CreateFont(48, new FontVariation(KnownVariationAxes.Weight, 700));

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 16, 2023

Codecov Report

❌ Patch coverage is 80.13732% with 405 lines in your changes missing coverage. Please review.
✅ Project coverage is 83%. Comparing base (1ac46b2) to head (59b5173).
⚠️ Report is 74 commits behind head on main.

Files with missing lines Patch % Lines
...dTypographic/Variations/GlyphVariationProcessor.cs 76% 69 Missing and 19 partials ⚠️
...c/SixLabors.Fonts/Tables/General/Colr/ColrTable.cs 25% 51 Missing and 2 partials ⚠️
...s.Fonts/Tables/General/Colr/ColrGlyphSourceBase.cs 0% 42 Missing ⚠️
src/SixLabors.Fonts/Tables/Cff/CffParserBase.cs 76% 27 Missing and 10 partials ⚠️
src/SixLabors.Fonts/Tables/Cff/Cff2Parser.cs 71% 14 Missing and 11 partials ⚠️
src/SixLabors.Fonts/StreamFontMetrics.cs 85% 12 Missing and 7 partials ⚠️
...Tables/AdvancedTypographic/Variations/CVarTable.cs 79% 7 Missing and 5 partials ⚠️
...bles/AdvancedTypographic/FeatureVariationsTable.cs 90% 4 Missing and 5 partials ⚠️
...ancedTypographic/Variations/VariationRegionList.cs 71% 6 Missing and 3 partials ⚠️
.../SixLabors.Fonts/Tables/Cff/CffEvaluationEngine.cs 68% 6 Missing and 3 partials ⚠️
... and 32 more
Additional details and impacted files
@@           Coverage Diff           @@
##            main    #342     +/-   ##
=======================================
- Coverage     83%     83%     -1%     
=======================================
  Files        274     302     +28     
  Lines      19169   20884   +1715     
  Branches    2714    3026    +312     
=======================================
+ Hits       16049   17462   +1413     
- Misses      2442    2658    +216     
- Partials     678     764     +86     
Flag Coverage Δ
unittests 83% <80%> (-1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JimBobSquarePants
Copy link
Copy Markdown
Member

JimBobSquarePants commented Aug 9, 2023

@brianpopow I had a quick look at the ItemVariationData and spotted an issue with the longwords check however I'm not sure how you tested the values here. How did you compare the values?

@brianpopow
Copy link
Copy Markdown
Contributor Author

@brianpopow I had a quick look at the ItemVariationData and spotted an issue with the longwords check however I'm not sure how you tested the values here. How did you compare the values?

I use the tagged version 1.8.0 of fontkit and the CFF2 font RobotoFlex.ttf linked above.
To debug fontkit, I use a unit test. As IDE, I do use webstorm. For example create a new file example.js in test folder of fontkit with the following code:

import fontkit from '../src';
import assert from 'assert';
import fs from 'fs';

describe('metadata', function() {
    it('fontkit test', function() {
        let font = fontkit.openSync(__dirname + '/data/RobotoFlex.ttf');
        var variationFont = font.getVariation({wght: 300})
        var run = font.layout("hello");
    });
});

This creates a new font variation with the weight 300 as an option. Then add a breakpoint, when the font is loaded and inspect font or variationFont. Look into the HVAR table and then into itemVariationStore -> itemVariationData.
For easier reading I usually do right click and Copy Json and past into into a text file.

@JimBobSquarePants
Copy link
Copy Markdown
Member

@brianpopow Thanks for the tests. I'm gonna go all in on this over the next few days so please hold off with any other changes.

@JimBobSquarePants JimBobSquarePants changed the title WIP: Compact Font Format (CFF) Version 2 Add CFF2 and TrueType Variation Font Support Mar 11, 2026
Copy link
Copy Markdown
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all seems to work now. Fantastic!

@JimBobSquarePants JimBobSquarePants merged commit 0be32b2 into main Mar 11, 2026
9 of 10 checks passed
@JimBobSquarePants JimBobSquarePants deleted the bp/cff2 branch March 11, 2026 13:09
@brianpopow
Copy link
Copy Markdown
Contributor Author

This all seems to work now. Fantastic!

@JimBobSquarePants : great to see, that you managed to finish this!

@JimBobSquarePants
Copy link
Copy Markdown
Member

This all seems to work now. Fantastic!

@JimBobSquarePants : great to see, that you managed to finish this!

Only with your help mate!!! 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants