Skip to content

Commit

Permalink
Fix font-size-adjust toggling font sizes for 'system-ui' font.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259895
rdar://111709567

Reviewed by Tim Nguyen.

When using 'system-ui' font, we will end up calling FontFamilySpecificationCoreText::fontRanges for obtaining FontRanges
with an appended font.

Before this patch, ::fontRanges() was updating the font's size for the
font-size-adjust everytime fontRange was called. The update would mutate
the font that is cached. After the page is refreshed and this function
was called again, we would retrieve the cached font, and execute the
size adjustment again, what would cause the bug.

This patch moves the call to updateSizeWithFontSizeAdjust to the lambda
function invoked when the Font is being cached, guaranteeing it will be
called just once.

 * LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-size-adjust-reload-expected.html: Added.
 * LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-size-adjust-reload-ref.html: Added.
 * LayoutTests/imported/w3c/web-platform-tests/css/css-fonts/font-size-adjust-reload.html: Added.
 * Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:
 (WebCore::FontFamilySpecificationCoreText::fontRanges const):

Canonical link: https://commits.webkit.org/266771@main
  • Loading branch information
vitorroriz committed Aug 10, 2023
1 parent b94dfac commit 04c2e0b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<link rel="author" title="Vitor Roriz" href="https://github.com/vitorroriz">
<link rel="help" href="http://www.w3.org/TR/css-fonts-3/#font-size-adjust-prop">
<style>
html {
margin: 0;
padding: 0;
}
body {
font-family: system-ui;
font-size: 100px;
font-size-adjust: 0.528;
border: 0;
padding: 0;
margin: 0;
height: 200px;
width: 200px;
}
</style>
</head>
<body>
<div id="target">A</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<link rel="author" title="Vitor Roriz" href="https://github.com/vitorroriz">
<link rel="help" href="http://www.w3.org/TR/css-fonts-3/#font-size-adjust-prop">
<style>
html {
margin: 0;
padding: 0;
}
body {
font-family: system-ui;
font-size: 100px;
font-size-adjust: 0.528;
border: 0;
padding: 0;
margin: 0;
height: 200px;
width: 200px;
}
</style>
</head>
<body>
<div id="target">A</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html class="reftest-wait">
<head>
<link rel="author" title="Vitor Roriz" href="https://github.com/vitorroriz">
<link rel="help" href="http://www.w3.org/TR/css-fonts-3/#font-size-adjust-prop">
<link rel="match" href="font-size-adjust-reload-ref.html">
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<iframe id="iframe" width=400 height=400 frameBorder=0 src="font-size-adjust-reload-ref.html"></iframe>
</body>
<script>
const iframe = document.getElementById('iframe');
// Forcing reload
iframe.src += '';
iframe.contentWindow.onload = function(){
document.documentElement.classList.remove("reftest-wait");
};
</script>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ FontRanges FontFamilySpecificationCoreText::fontRanges(const FontDescription& fo

auto [syntheticBold, syntheticOblique] = computeNecessarySynthesis(font.get(), fontDescription, ShouldComputePhysicalTraits::Yes).boldObliquePair();

return makeUnique<FontPlatformData>(font.get(), size, false, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode());
auto platformData = makeUnique<FontPlatformData>(font.get(), size, false, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode());
platformData->updateSizeWithFontSizeAdjust(fontDescription.fontSizeAdjust(), fontDescription.computedSize());
return platformData;
});

originalPlatformData.updateSizeWithFontSizeAdjust(fontDescription.fontSizeAdjust(), fontDescription.computedSize());
return FontRanges(FontCache::forCurrentThread().fontForPlatformData(originalPlatformData));
}

Expand Down

0 comments on commit 04c2e0b

Please sign in to comment.