Title: [289007] trunk
Revision
289007
Author
[email protected]
Date
2022-02-02 15:57:15 -0800 (Wed, 02 Feb 2022)

Log Message

Percentage word spacing doesn't incorporate synthetic bold expansion
https://bugs.webkit.org/show_bug.cgi?id=236007

Reviewed by Alan Bujtas.

Source/WebCore:

The solution is to copy the approach in https://trac.webkit.org/changeset/288944/webkit
to make sure the space glyph works correctly with synthetic bold and fallback fonts.

This also renames FontCascade::spaceWidth() to FontCascade::widthOfSpaceString(),
so it's more clear what it's actually doing.

Test: fast/text/synthetic-bold-percentage-word-spacing.html

* platform/graphics/FontCascade.h:
(WebCore::FontCascade::metricsOfPrimaryFont const):
(WebCore::FontCascade::spaceWidth const): Deleted.
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::setWordSpacing):

LayoutTests:

* fast/text/synthetic-bold-percentage-word-spacing-expected.html: Added.
* fast/text/synthetic-bold-percentage-word-spacing.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (289006 => 289007)


--- trunk/LayoutTests/ChangeLog	2022-02-02 23:55:33 UTC (rev 289006)
+++ trunk/LayoutTests/ChangeLog	2022-02-02 23:57:15 UTC (rev 289007)
@@ -1,3 +1,13 @@
+2022-02-02  Myles C. Maxfield  <[email protected]>
+
+        Percentage word spacing doesn't incorporate synthetic bold expansion
+        https://bugs.webkit.org/show_bug.cgi?id=236007
+
+        Reviewed by Alan Bujtas.
+
+        * fast/text/synthetic-bold-percentage-word-spacing-expected.html: Added.
+        * fast/text/synthetic-bold-percentage-word-spacing.html: Added.
+
 2022-02-02  Patrick Angle  <[email protected]>
 
         No breakpoints hit on github.com, and some are invalid

Added: trunk/LayoutTests/fast/text/synthetic-bold-percentage-word-spacing-expected.html (0 => 289007)


--- trunk/LayoutTests/fast/text/synthetic-bold-percentage-word-spacing-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/synthetic-bold-percentage-word-spacing-expected.html	2022-02-02 23:57:15 UTC (rev 289007)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that word spacing works correctly with synthetic bold. The test passes if the width of spaces in <code>word-spacing: 100%</code> is as wide as 2 spaces, when synthetic bold is enabled.
+<div style="font: bold 16px 'Monaco';">
+<div style="white-space: pre;">a  a  a  a  a  a  a  a  a  a  a  a  a  a  a  a</div>
+</div>
+</body>
+</html>

Added: trunk/LayoutTests/fast/text/synthetic-bold-percentage-word-spacing.html (0 => 289007)


--- trunk/LayoutTests/fast/text/synthetic-bold-percentage-word-spacing.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/synthetic-bold-percentage-word-spacing.html	2022-02-02 23:57:15 UTC (rev 289007)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that word spacing works correctly with synthetic bold. The test passes if the width of spaces in <code>word-spacing: 100%</code> is as wide as 2 spaces, when synthetic bold is enabled.
+<div style="font: bold 16px 'Monaco';">
+<div style="word-spacing: 100%;">a a a a a a a a a a a a a a a a</div>
+</div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (289006 => 289007)


--- trunk/Source/WebCore/ChangeLog	2022-02-02 23:55:33 UTC (rev 289006)
+++ trunk/Source/WebCore/ChangeLog	2022-02-02 23:57:15 UTC (rev 289007)
@@ -1,3 +1,24 @@
+2022-02-02  Myles C. Maxfield  <[email protected]>
+
+        Percentage word spacing doesn't incorporate synthetic bold expansion
+        https://bugs.webkit.org/show_bug.cgi?id=236007
+
+        Reviewed by Alan Bujtas.
+
+        The solution is to copy the approach in https://trac.webkit.org/changeset/288944/webkit
+        to make sure the space glyph works correctly with synthetic bold and fallback fonts.
+
+        This also renames FontCascade::spaceWidth() to FontCascade::widthOfSpaceString(),
+        so it's more clear what it's actually doing.
+
+        Test: fast/text/synthetic-bold-percentage-word-spacing.html
+
+        * platform/graphics/FontCascade.h:
+        (WebCore::FontCascade::metricsOfPrimaryFont const):
+        (WebCore::FontCascade::spaceWidth const): Deleted.
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::setWordSpacing):
+
 2022-02-02  Chris Dumez  <[email protected]>
 
         Move TransferredMessagePort to its own header

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp (289006 => 289007)


--- trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2022-02-02 23:55:33 UTC (rev 289006)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2022-02-02 23:57:15 UTC (rev 289007)
@@ -91,7 +91,7 @@
 
 InlineLayoutUnit TextUtil::spaceWidth(const FontCascade& fontCascade)
 {
-    return fontCascade.width(TextRun { String { &space, 1 } });
+    return fontCascade.widthOfSpaceString();
 }
 
 InlineLayoutUnit TextUtil::trailingWhitespaceWidth(const InlineTextBox& inlineTextBox, const FontCascade& fontCascade, size_t startPosition, size_t endPosition)

Modified: trunk/Source/WebCore/platform/graphics/FontCascade.h (289006 => 289007)


--- trunk/Source/WebCore/platform/graphics/FontCascade.h	2022-02-02 23:55:33 UTC (rev 289006)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.h	2022-02-02 23:57:15 UTC (rev 289007)
@@ -135,6 +135,10 @@
 
     std::unique_ptr<TextLayout, TextLayoutDeleter> createLayout(RenderText&, float xPos, bool collapseWhiteSpace) const;
     static float width(TextLayout&, unsigned from, unsigned len, HashSet<const Font*>* fallbackFonts = 0);
+    float widthOfSpaceString() const
+    {
+        return width(TextRun { String { &space, 1 } });
+    }
 
     int offsetForPosition(const TextRun&, float position, bool includePartialGlyphs) const;
     void adjustSelectionRectForText(const TextRun&, LayoutRect& selectionRect, unsigned from = 0, std::optional<unsigned> to = std::nullopt) const;
@@ -164,7 +168,6 @@
     bool isPlatformFont() const { return m_fonts->isForPlatformFont(); }
 
     const FontMetrics& metricsOfPrimaryFont() const { return primaryFont().fontMetrics(); }
-    float spaceWidth() const { return primaryFont().spaceWidth() + m_letterSpacing; }
     float tabWidth(const Font&, const TabSize&, float) const;
     float tabWidth(const TabSize& tabSize, float position) const { return tabWidth(primaryFont(), tabSize, position); }
     bool hasValidAverageCharWidth() const;

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (289006 => 289007)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2022-02-02 23:55:33 UTC (rev 289006)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2022-02-02 23:57:15 UTC (rev 289007)
@@ -1912,7 +1912,7 @@
         fontWordSpacing = 0;
         break;
     case LengthType::Percent:
-        fontWordSpacing = value.percent() * fontCascade().spaceWidth() / 100;
+        fontWordSpacing = value.percent() * fontCascade().widthOfSpaceString() / 100;
         break;
     case LengthType::Fixed:
         fontWordSpacing = value.value();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to