Title: [289151] trunk
Revision
289151
Author
mmaxfi...@apple.com
Date
2022-02-04 22:38:33 -0800 (Fri, 04 Feb 2022)

Log Message

ch unit fallback size doesn't match the spec
https://bugs.webkit.org/show_bug.cgi?id=236073
<rdar://problem/88513297>

Reviewed by Cameron McCormack.

Source/WebCore:

The spec (https://drafts.csswg.org/css-values-4/#ch) says:
> In the cases where it is impossible or impractical to determine the measure of the “0” glyph, it must be assumed to be 0.5em wide

Test: fast/text/ch-unit-without-zero-glyph.html

* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble):
(WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):
* platform/graphics/Font.cpp:
(WebCore::Font::platformGlyphInit):
* platform/graphics/FontMetrics.h:
(WebCore::FontMetrics::zeroWidth const):
(WebCore::FontMetrics::reset):

LayoutTests:

This can't be a WPT test because it uses an SVG font which we're the only browser to support.

* fast/text/ch-unit-without-zero-glyph-expected.html: Added.
* fast/text/ch-unit-without-zero-glyph.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (289150 => 289151)


--- trunk/LayoutTests/ChangeLog	2022-02-05 06:11:55 UTC (rev 289150)
+++ trunk/LayoutTests/ChangeLog	2022-02-05 06:38:33 UTC (rev 289151)
@@ -1,3 +1,16 @@
+2022-02-04  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        ch unit fallback size doesn't match the spec
+        https://bugs.webkit.org/show_bug.cgi?id=236073
+        <rdar://problem/88513297>
+
+        Reviewed by Cameron McCormack.
+
+        This can't be a WPT test because it uses an SVG font which we're the only browser to support.
+
+        * fast/text/ch-unit-without-zero-glyph-expected.html: Added.
+        * fast/text/ch-unit-without-zero-glyph.html: Added.
+
 2022-02-04  Arcady Goldmints-Orlov  <agoldmi...@igalia.com>
 
         REGRESSION(r280077): [GTK] It caused 155 new test failures

Added: trunk/LayoutTests/fast/text/ch-unit-without-zero-glyph-expected.html (0 => 289151)


--- trunk/LayoutTests/fast/text/ch-unit-without-zero-glyph-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/ch-unit-without-zero-glyph-expected.html	2022-02-05 06:38:33 UTC (rev 289151)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "WebFont";
+    src: url("resources/tiny-ligature-font.svg") format("svg");
+}
+</style>
+</head>
+<body>
+This test makes sure that the <code>ch</code> unit falls back to 0.5em on fonts that don't support the 0 character. The test passes if the green box below has the correct width.
+<div style="font: 48px 'WebFont'; width: calc(10em / 2); background: green; color: transparent;">AAAA</div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/text/ch-unit-without-zero-glyph.html (0 => 289151)


--- trunk/LayoutTests/fast/text/ch-unit-without-zero-glyph.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/ch-unit-without-zero-glyph.html	2022-02-05 06:38:33 UTC (rev 289151)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "WebFont";
+    src: url("resources/tiny-ligature-font.svg") format("svg");
+}
+</style>
+</head>
+<body>
+This test makes sure that the <code>ch</code> unit falls back to 0.5em on fonts that don't support the 0 character. The test passes if the green box below has the correct width.
+<div style="font: 48px 'WebFont'; width: 10ch; background: green; color: transparent;">AAAA</div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (289150 => 289151)


--- trunk/Source/WebCore/ChangeLog	2022-02-05 06:11:55 UTC (rev 289150)
+++ trunk/Source/WebCore/ChangeLog	2022-02-05 06:38:33 UTC (rev 289151)
@@ -1,3 +1,25 @@
+2022-02-04  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        ch unit fallback size doesn't match the spec
+        https://bugs.webkit.org/show_bug.cgi?id=236073
+        <rdar://problem/88513297>
+
+        Reviewed by Cameron McCormack.
+
+        The spec (https://drafts.csswg.org/css-values-4/#ch) says:
+        > In the cases where it is impossible or impractical to determine the measure of the “0” glyph, it must be assumed to be 0.5em wide
+
+        Test: fast/text/ch-unit-without-zero-glyph.html
+
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::computeUnzoomedNonCalcLengthDouble):
+        (WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::platformGlyphInit):
+        * platform/graphics/FontMetrics.h:
+        (WebCore::FontMetrics::zeroWidth const):
+        (WebCore::FontMetrics::reset):
+
 2022-02-04  Eric Carlson  <eric.carl...@apple.com>
 
         Update MediaStreamTrack understanding of source type

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.cpp (289150 => 289151)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2022-02-05 06:11:55 UTC (rev 289150)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.cpp	2022-02-05 06:38:33 UTC (rev 289151)
@@ -719,7 +719,8 @@
         return ((propertyToCompute == CSSPropertyFontSize) ? rootFontDescription->specifiedSize() : rootFontDescription->computedSize()) * value;
     case CSSUnitType::CSS_CHS:
         ASSERT(fontMetrics);
-        return fontMetrics->zeroWidth() * value;
+        ASSERT(fontDescription);
+        return fontMetrics->zeroWidth().value_or(fontDescription->computedSize() / 2) * value;
     case CSSUnitType::CSS_IC:
         ASSERT(fontMetrics);
         return fontMetrics->ideogramWidth() * value;
@@ -824,7 +825,7 @@
     case CSSUnitType::CSS_CHS:
     case CSSUnitType::CSS_IC:
         ASSERT(conversionData.style());
-        value = computeUnzoomedNonCalcLengthDouble(primitiveType, value, conversionData.propertyToCompute(), &conversionData.style()->metricsOfPrimaryFont());
+        value = computeUnzoomedNonCalcLengthDouble(primitiveType, value, conversionData.propertyToCompute(), &conversionData.style()->metricsOfPrimaryFont(), &conversionData.style()->fontDescription());
         break;
 
     case CSSUnitType::CSS_PX:

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (289150 => 289151)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2022-02-05 06:11:55 UTC (rev 289150)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2022-02-05 06:38:33 UTC (rev 289151)
@@ -151,7 +151,8 @@
     Glyph zeroGlyph = { 0 };
     if (auto* page = glyphPage(GlyphPage::pageNumberForCodePoint('0')))
         zeroGlyph = page->glyphDataForCharacter('0').glyph;
-    m_fontMetrics.setZeroWidth(widthForGlyph(zeroGlyph));
+    if (zeroGlyph)
+        m_fontMetrics.setZeroWidth(widthForGlyph(zeroGlyph));
 
     // Use the width of the CJK water ideogram (U+6C34) as the
     // approximated width of ideograms in the font, as mentioned in

Modified: trunk/Source/WebCore/platform/graphics/FontMetrics.h (289150 => 289151)


--- trunk/Source/WebCore/platform/graphics/FontMetrics.h	2022-02-05 06:11:55 UTC (rev 289150)
+++ trunk/Source/WebCore/platform/graphics/FontMetrics.h	2022-02-05 06:38:33 UTC (rev 289151)
@@ -119,7 +119,7 @@
         return ascent() == other.ascent() && descent() == other.descent() && lineGap() == other.lineGap();
     }
 
-    float zeroWidth() const { return m_zeroWidth; }
+    std::optional<float> zeroWidth() const { return m_zeroWidth; }
     void setZeroWidth(float zeroWidth) { m_zeroWidth = zeroWidth; }
 
     float ideogramWidth() const { return m_ideogramWidth; }
@@ -148,7 +148,7 @@
         m_intLineSpacing = 0;
         m_intCapHeight = 0;
         m_xHeight = 0;
-        m_zeroWidth = 0;
+        m_zeroWidth = std::nullopt;
         m_ideogramWidth = 0;
         m_underlinePosition = 0;
         m_underlineThickness = 0;
@@ -169,7 +169,7 @@
     int m_intLineSpacing { 0 };
     int m_intCapHeight { 0 };
 
-    float m_zeroWidth { 0 };
+    std::optional<float> m_zeroWidth;
     float m_ideogramWidth { 0 };
     float m_xHeight { 0 };
     float m_underlinePosition { 0 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to