Truly independent web browser
LibWeb: Synthesize bold for a variable face declared lighter than bold
sideshowbarkerec69cad3d6ab
diff --git a/Libraries/LibWeb/CSS/FontResolution.cpp b/Libraries/LibWeb/CSS/FontResolution.cppindex 66e8b5fcaf9..99ca6253f3a 100644--- a/Libraries/LibWeb/CSS/FontResolution.cpp+++ b/Libraries/LibWeb/CSS/FontResolution.cpp@@ -82,11 +82,13 @@ static Optional<Gfx::SystemUIFontKind> macos_system_ui_font_kind_from_family_nam// https://drafts.csswg.org/css-fonts-4/#font-synthesis-weight// How a face of the snapshot registered under `key` is synthesized for the request: never bolder where its font-weight// descriptor claims bold weights, nor slanted where its font-style descriptor claims a slant, whatever its file holds.+// And always bolder for a bold request where its font-weight descriptor claims only weights lighter than bold, since the+// family as declared then has no bold face, even where its file has a weight axis that goes further.static Gfx::FontSynthesis synthesis_for_face(FontFaceSnapshot::Face const& face, FontFaceKey const& key, Gfx::Typeface const& typeface, Gfx::FontSynthesisRequest const& request, Gfx::FontVariationSettings const& variations){auto synthesis = typeface.synthesis_for(request, variations);- if (!face.weight_descriptor_is_auto && key.weight.max >= 600)- synthesis.bold = false;+ if (!face.weight_descriptor_is_auto)+ synthesis.bold = key.weight.max < 600 && request.allows_weight && request.weight >= 600;if (key.slope != 0)synthesis.oblique_angle = 0;return synthesis;diff --git a/Tests/LibWeb/Ref/expected/font-synthesis-weight-of-variable-web-font-with-light-weights-notref.html b/Tests/LibWeb/Ref/expected/font-synthesis-weight-of-variable-web-font-with-light-weights-notref.htmlnew file mode 100644index 00000000000..03b84888400--- /dev/null+++ b/Tests/LibWeb/Ref/expected/font-synthesis-weight-of-variable-web-font-with-light-weights-notref.html@@ -0,0 +1,10 @@+<!DOCTYPE html>+<style>+ @font-face {+ font-family: "LightWeightsOnly";+ src: url(../input/wpt-import/css/css-fonts/support/fonts/Inter-VF.subset.ttf);+ font-weight: 500;+ }+ p { font: 60px LightWeightsOnly; font-weight: bold; font-synthesis: none; margin: 0; }+</style>+<p>text</p>diff --git a/Tests/LibWeb/Ref/input/font-synthesis-weight-of-variable-web-font-with-light-weights.html b/Tests/LibWeb/Ref/input/font-synthesis-weight-of-variable-web-font-with-light-weights.htmlnew file mode 100644index 00000000000..cdbcd9c9519--- /dev/null+++ b/Tests/LibWeb/Ref/input/font-synthesis-weight-of-variable-web-font-with-light-weights.html@@ -0,0 +1,13 @@+<!DOCTYPE html>+<link rel="mismatch" href="../expected/font-synthesis-weight-of-variable-web-font-with-light-weights-notref.html">+<style>+ /* The font's weight axis goes up to 900, but the face as declared has only the weight 500, so the family has no+ bold face, and bold text is synthesized. */+ @font-face {+ font-family: "LightWeightsOnly";+ src: url(wpt-import/css/css-fonts/support/fonts/Inter-VF.subset.ttf);+ font-weight: 500;+ }+ p { font: 60px LightWeightsOnly; font-weight: bold; margin: 0; }+</style>+<p>text</p>