Skip to content

fonts: Add font variations support for macOS - #38760

Merged
simonwuelker merged 1 commit into
servo:mainfrom
mrobinson:font-variations-macos
Aug 19, 2025
Merged

simonwuelker merged 1 commit into
servo:mainfrom
mrobinson:font-variations-macos

Conversation

@mrobinson

@mrobinson mrobinson commented Aug 18, 2025 •

Copy link
Copy Markdown
Member

This change adds font variation support for macOS. The main bulk of the
change is reading the default, min, and max values for each variation
axis from the font and instantiating a new CoreText font with the
appropriate values.

In addition, fonts with variations are now properly cached in the
CoreText font cache.

Testing: There are no tests for this change as we do not run WPT tests for
macOS and font variations are currently turned off by default. Eventually,
when the feature is turned on there will be test for it. These changes
are just laying the groundwork for the full implementation.

@mrobinson
mrobinson requested a review from simonwuelker August 18, 2025 17:46
@nicoburns nicoburns mentioned this pull request Aug 18, 2025
4 tasks done

@simonwuelker simonwuelker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me.
I wonder if some of the optimizations you did (VARIATION_AXIS_INFORMATION_CACHE, checking if specified variation values are different from the default) are worth having in the freetype version as well.

Comment on lines +228 to +233
let cache = VARIATION_AXIS_INFORMATION_CACHE
.0
.get_or_init(Default::default);
if let Some(information) = cache.read().get(font_identifier) {
return information.clone();
}

@simonwuelker simonwuelker Aug 19, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is reading the variation axes on a font really expensive enough to warrant a cache? It doesn't look very expensive and we only read the variations once when instantiating the same font with different variation parameters.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Perhaps it isn't very expensive. I'm happy to remove the cache for now if you think it isn't necessary. We can always add it back later. Is there anything else you'd like before landing this? (noticing that you said LGTM, but didn't approve the change). I'm happy to make whatever changes you like.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's remove the cache for now and add it back if querying the axes becomes expensive.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay. I've removed the new cache now. PTAL.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +80 to +71
let core_text_font_no_variations =
Self::core_text_font(font_identifier.clone(), data, clamped_pt_size, &[])?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could save some locking here by acquiring the write lock before the call and replacing it with a manual lookup, but that seems like premature optimization...

This change adds font variation support for macOS. The main bulk of the
change is reading the default, min, and max values for each variation
axis from the font and instantiating a new CoreText font with the
appropriate values. As part of this process, there is a new cache for
storing these values from each font loaded.

In addition, fonts with variations are now properly cached in the
CoreText font cache.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
@mrobinson
mrobinson force-pushed the font-variations-macos branch from dee464b to 97d4f5d Compare August 19, 2025 13:42
@simonwuelker
simonwuelker enabled auto-merge August 19, 2025 14:12
@nicoburns

Copy link
Copy Markdown
Contributor

@simonwuelker You've enabled auto-merge but not actually approved the PR. Was that intentional? It won't be merged until it has an approving review.

@simonwuelker
simonwuelker added this pull request to the merge queue Aug 19, 2025
@simonwuelker

Copy link
Copy Markdown
Member

@simonwuelker You've enabled auto-merge but not actually approved the PR. Was that intentional? It won't be merged until it has an approving review.

thanks

Merged via the queue into servo:main with commit 2022831 Aug 19, 2025
PotatoCP pushed a commit to PotatoCP/servo that referenced this pull request Aug 20, 2025
This change adds font variation support for macOS. The main bulk of the
change is reading the default, min, and max values for each variation
axis from the font and instantiating a new CoreText font with the
appropriate values. 

In addition, fonts with variations are now properly cached in the
CoreText font cache.

Testing: There are no tests for this change as we do not run WPT tests
for
macOS and font variations are currently turned off by default.
Eventually,
when the feature is turned on there will be test for it. These changes
are just laying the groundwork for the full implementation.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
PotatoCP pushed a commit to PotatoCP/servo that referenced this pull request Aug 20, 2025
This change adds font variation support for macOS. The main bulk of the
change is reading the default, min, and max values for each variation
axis from the font and instantiating a new CoreText font with the
appropriate values. 

In addition, fonts with variations are now properly cached in the
CoreText font cache.

Testing: There are no tests for this change as we do not run WPT tests
for
macOS and font variations are currently turned off by default.
Eventually,
when the feature is turned on there will be test for it. These changes
are just laying the groundwork for the full implementation.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
PotatoCP pushed a commit to PotatoCP/servo that referenced this pull request Aug 20, 2025
This change adds font variation support for macOS. The main bulk of the
change is reading the default, min, and max values for each variation
axis from the font and instantiating a new CoreText font with the
appropriate values. 

In addition, fonts with variations are now properly cached in the
CoreText font cache.

Testing: There are no tests for this change as we do not run WPT tests
for
macOS and font variations are currently turned off by default.
Eventually,
when the feature is turned on there will be test for it. These changes
are just laying the groundwork for the full implementation.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
@mrobinson mrobinson changed the title fonts: Add font variation support for macOS fonts: Add font variations support for macOS Aug 21, 2025
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

Successfully merging this pull request may close these issues.

3 participants