Title: [290204] trunk/Source/WebCore
Revision
290204
Author
za...@apple.com
Date
2022-02-19 05:30:26 -0800 (Sat, 19 Feb 2022)

Log Message

[LFC][IFC] Introduce LineBoxBuilder::collectFallbackFonts
https://bugs.webkit.org/show_bug.cgi?id=236866

Reviewed by Antti Koivisto.

Let's move fallback font collect to a dedicated function and stop leaking internal line types to TextUtil.

* layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
(WebCore::Layout::LineBoxBuilder::collectFallbackFonts):
(WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):
(WebCore::Layout::fallbackFontHasVerticalGlyph): Deleted.
* layout/formattingContexts/inline/InlineLineBoxBuilder.h:
* layout/formattingContexts/inline/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::fallbackFontsForText):
(WebCore::Layout::TextUtil::fallbackFontsForRun): Deleted.
* layout/formattingContexts/inline/text/TextUtil.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290203 => 290204)


--- trunk/Source/WebCore/ChangeLog	2022-02-19 12:36:54 UTC (rev 290203)
+++ trunk/Source/WebCore/ChangeLog	2022-02-19 13:30:26 UTC (rev 290204)
@@ -1,5 +1,24 @@
 2022-02-19  Alan Bujtas  <za...@apple.com>
 
+        [LFC][IFC] Introduce LineBoxBuilder::collectFallbackFonts
+        https://bugs.webkit.org/show_bug.cgi?id=236866
+
+        Reviewed by Antti Koivisto.
+
+        Let's move fallback font collect to a dedicated function and stop leaking internal line types to TextUtil.
+
+        * layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
+        (WebCore::Layout::LineBoxBuilder::collectFallbackFonts):
+        (WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):
+        (WebCore::Layout::fallbackFontHasVerticalGlyph): Deleted.
+        * layout/formattingContexts/inline/InlineLineBoxBuilder.h:
+        * layout/formattingContexts/inline/text/TextUtil.cpp:
+        (WebCore::Layout::TextUtil::fallbackFontsForText):
+        (WebCore::Layout::TextUtil::fallbackFontsForRun): Deleted.
+        * layout/formattingContexts/inline/text/TextUtil.h:
+
+2022-02-19  Alan Bujtas  <za...@apple.com>
+
         [LFC][IFC] layoutBoundsForInlineBox should read layoutBoundsPrimaryMetricsForInlineBox
         https://bugs.webkit.org/show_bug.cgi?id=236864
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp (290203 => 290204)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2022-02-19 12:36:54 UTC (rev 290203)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp	2022-02-19 13:30:26 UTC (rev 290204)
@@ -36,15 +36,6 @@
 namespace WebCore {
 namespace Layout {
 
-static bool fallbackFontHasVerticalGlyph(const TextUtil::FallbackFontList& fallbackFontList)
-{
-    for (auto* font : fallbackFontList) {
-        if (font->hasVerticalGlyphs())
-            return true;
-    }
-    return false;
-}
-
 static std::optional<InlineLayoutUnit> horizontalAlignmentOffset(TextAlignMode textAlign, const LineBuilder::LineContent& lineContent, bool isLeftToRightDirection)
 {
     // Depending on the line’s alignment/justification, the hanging glyph can be placed outside the line box.
@@ -160,6 +151,30 @@
     inlineBox.setLayoutBounds({ std::max(layoutBounds.ascent, floorf(maxAscent)), std::max(layoutBounds.descent, ceilf(maxDescent)) });
 }
 
+TextUtil::FallbackFontList LineBoxBuilder::collectFallbackFonts(const Line::Run& run, const RenderStyle& style)
+{
+    auto& inlineTextBox = downcast<InlineTextBox>(run.layoutBox());
+    if (inlineTextBox.canUseSimplifiedContentMeasuring()) {
+        // Simplified text measuring works with primary font only.
+        return { };
+    }
+    auto text = *run.textContent();
+    auto fallbackFonts = TextUtil::fallbackFontsForText(StringView(inlineTextBox.content()).substring(text.start, text.length), style, text.needsHyphen ? TextUtil::IncludeHyphen::Yes : TextUtil::IncludeHyphen::No);
+    if (fallbackFonts.isEmpty())
+        return { };
+
+    auto fallbackFontsHaveVerticalGlyph = [&] {
+        for (auto* font : fallbackFonts) {
+            if (font->hasVerticalGlyphs())
+                return true;
+        }
+        return false;
+    };
+    // Adjust non-empty inline box height when glyphs from the non-primary font stretch the box.
+    m_fallbackFontRequiresIdeographicBaseline = m_fallbackFontRequiresIdeographicBaseline || fallbackFontsHaveVerticalGlyph();
+    return fallbackFonts;
+}
+
 struct LayoutBoundsMetrics {
     InlineLayoutUnit ascent { 0 };
     InlineLayoutUnit descent { 0 };
@@ -316,10 +331,8 @@
         if (run.isText()) {
             auto& parentInlineBox = lineBox.inlineLevelBoxForLayoutBox(layoutBox.parent());
             parentInlineBox.setHasContent();
-            auto fallbackFonts = TextUtil::fallbackFontsForRun(run, style);
-            if (!fallbackFonts.isEmpty()) {
+            if (auto fallbackFonts = collectFallbackFonts(run, style); !fallbackFonts.isEmpty()) {
                 // Adjust non-empty inline box height when glyphs from the non-primary font stretch the box.
-                m_fallbackFontRequiresIdeographicBaseline = m_fallbackFontRequiresIdeographicBaseline || fallbackFontHasVerticalGlyph(fallbackFonts);
                 adjustLayoutBoundsWithFallbackFonts(parentInlineBox, fallbackFonts);
             }
             continue;

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.h (290203 => 290204)


--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.h	2022-02-19 12:36:54 UTC (rev 290203)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.h	2022-02-19 13:30:26 UTC (rev 290204)
@@ -48,6 +48,7 @@
 private:
     void setBaselineAndLayoutBounds(InlineLevelBox&, const LayoutBoundsMetrics&) const;
     void adjustLayoutBoundsWithFallbackFonts(InlineLevelBox&, const TextUtil::FallbackFontList&) const;
+    TextUtil::FallbackFontList collectFallbackFonts(const Line::Run&, const RenderStyle&);
 
     void constructInlineLevelBoxes(LineBox&, const LineBuilder::LineContent&, size_t lineIndex);
     void adjustIdeographicBaselineIfApplicable(LineBox&, size_t lineIndex);

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


--- trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2022-02-19 12:36:54 UTC (rev 290203)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp	2022-02-19 13:30:26 UTC (rev 290204)
@@ -131,15 +131,8 @@
     }
 }
 
-TextUtil::FallbackFontList TextUtil::fallbackFontsForRun(const Line::Run& run, const RenderStyle& style)
+TextUtil::FallbackFontList TextUtil::fallbackFontsForText(StringView textContent, const RenderStyle& style, IncludeHyphen includeHyphen)
 {
-    ASSERT(run.isText());
-    auto& inlineTextBox = downcast<InlineTextBox>(run.layoutBox());
-    if (inlineTextBox.canUseSimplifiedContentMeasuring()) {
-        // Simplified text measuring works with primary font only.
-        return { };
-    }
-
     TextUtil::FallbackFontList fallbackFonts;
 
     auto collectFallbackFonts = [&](const auto& textRun) {
@@ -155,10 +148,9 @@
         fallbackFontsForRunWithIterator(fallbackFonts, style.fontCascade(), textRun, textIterator);
     };
 
-    auto text = *run.textContent();
-    if (text.needsHyphen)
+    if (includeHyphen == IncludeHyphen::Yes)
         collectFallbackFonts(TextRun { StringView(style.hyphenString().string()), { }, { }, DefaultExpansion, style.direction() });
-    collectFallbackFonts(TextRun { StringView(inlineTextBox.content()).substring(text.start, text.length), { }, { }, DefaultExpansion, style.direction() });
+    collectFallbackFonts(TextRun { textContent, { }, { }, DefaultExpansion, style.direction() });
     return fallbackFonts;
 }
 

Modified: trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h (290203 => 290204)


--- trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h	2022-02-19 12:36:54 UTC (rev 290203)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/text/TextUtil.h	2022-02-19 13:30:26 UTC (rev 290204)
@@ -54,7 +54,8 @@
     static InlineLayoutUnit trailingWhitespaceWidth(const InlineTextBox&, const FontCascade&, size_t startPosition, size_t endPosition);
 
     using FallbackFontList = HashSet<const Font*>;
-    static FallbackFontList fallbackFontsForRun(const Line::Run&, const RenderStyle&);
+    enum class IncludeHyphen : uint8_t { No, Yes };
+    static FallbackFontList fallbackFontsForText(StringView, const RenderStyle&, IncludeHyphen);
 
     struct WordBreakLeft {
         size_t length { 0 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to