Skip to content

Commit

Permalink
Rename widthForSimpleText, floatWidthForSimpleText, floatWidthForComp…
Browse files Browse the repository at this point in the history
…lexText

https://bugs.webkit.org/show_bug.cgi?id=271729
rdar://problem/125440731

Reviewed by Alan Baradlay.

We currently have 3 functions for width calculation named:

1. widthForSimpleText
2. floatWidthForSimpleText
3. floatWidthForComplexText

These functions all do something similar but their names are a bit confusing, specially by the different meanings of the word "simple" here.
They scale in level of complexity:

1. widthForSimpleText: does not use any width iterator, but has to pass "computeCanUseSimplifiedTextMeasuring" to be used.
2. floatWidthForSimpleText: It is used when we have a CodePath::Simple (calculated on FontCascade). It uses iterator WidthIterator
3. floatWidthForComplexText: It is used when we have a CodePath::Complex (calculated on FontCascade). It uses the ComplexTextControler, a more complete and slower iterator (supports kerning and ligaments, for example, which are currently not supported by WidthIterator).

We are renaming them to:

1. widthForSimpleText -> widthForTextUsingSimplifiedMeasuring
2. floatWidthForSimpleText -> widthForTextUsingWidthIterator
3. floatWidthForComplexText -> floatWidthForTextUsingComplexTextController

* Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:
(WebCore::Layout::TextUtil::width):
* Source/WebCore/platform/graphics/FontCascade.cpp:
(WebCore::FontCascade::width const):
(WebCore::FontCascade::widthForTextUsingWidthIterator const):
(WebCore::FontCascade::widthForTextUsingComplexTextController const):
(WebCore::FontCascade::offsetForPositionForSimpleText const):
(WebCore::FontCascade::floatWidthForSimpleText const): Deleted.
(WebCore::FontCascade::floatWidthForComplexText const): Deleted.
* Source/WebCore/platform/graphics/FontCascade.h:
(WebCore::FontCascade::widthForTextUsingSimplifiedMeasuring const):
(WebCore::FontCascade::widthForSimpleText const): Deleted.
* Source/WebCore/platform/graphics/WidthIterator.cpp:
(WebCore::WidthIterator::advanceInternal):
* Tools/TestWebKitAPI/Tests/WebCore/MonospaceFontTests.cpp:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/276716@main
  • Loading branch information
vitorroriz committed Mar 26, 2024
1 parent bee5958 commit 31aadb0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ InlineLayoutUnit TextUtil::width(const InlineTextBox& inlineTextBox, const FontC
if (fontCascade.canTakeFixedPitchFastContentMeasuring())
width = fontCascade.widthForSimpleTextWithFixedPitch(view, inlineTextBox.style().collapseWhiteSpace());
else
width = fontCascade.widthForSimpleText(view);
width = fontCascade.widthForTextUsingSimplifiedMeasuring(view);
} else {
auto& style = inlineTextBox.style();
auto directionalOverride = style.unicodeBidi() == UnicodeBidi::Override;
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/platform/graphics/FontCascade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ float FontCascade::width(const TextRun& run, SingleThreadWeakHashSet<const Font>

float result;
if (codePathToUse == CodePath::Complex)
result = floatWidthForComplexText(run, fallbackFonts, glyphOverflow);
result = widthForTextUsingComplexTextController(run, fallbackFonts, glyphOverflow);
else
result = floatWidthForSimpleText(run, fallbackFonts, glyphOverflow);
result = widthForTextUsingWidthIterator(run, fallbackFonts, glyphOverflow);

if (cacheEntry && fallbackFonts->isEmptyIgnoringNullReferences())
*cacheEntry = result;
Expand Down Expand Up @@ -1541,7 +1541,7 @@ void FontCascade::drawEmphasisMarks(GraphicsContext& context, const GlyphBuffer&
drawGlyphBuffer(context, markBuffer, startPoint, CustomFontNotReadyAction::DoNotPaintIfFontNotReady);
}

float FontCascade::floatWidthForSimpleText(const TextRun& run, SingleThreadWeakHashSet<const Font>* fallbackFonts, GlyphOverflow* glyphOverflow) const
float FontCascade::widthForTextUsingWidthIterator(const TextRun& run, SingleThreadWeakHashSet<const Font>* fallbackFonts, GlyphOverflow* glyphOverflow) const
{
WidthIterator it(*this, run, fallbackFonts, glyphOverflow);
GlyphBuffer glyphBuffer;
Expand All @@ -1558,7 +1558,7 @@ float FontCascade::floatWidthForSimpleText(const TextRun& run, SingleThreadWeakH
return it.runWidthSoFar();
}

float FontCascade::floatWidthForComplexText(const TextRun& run, SingleThreadWeakHashSet<const Font>* fallbackFonts, GlyphOverflow* glyphOverflow) const
float FontCascade::widthForTextUsingComplexTextController(const TextRun& run, SingleThreadWeakHashSet<const Font>* fallbackFonts, GlyphOverflow* glyphOverflow) const
{
ComplexTextController controller(*this, run, true, fallbackFonts);
if (glyphOverflow) {
Expand Down Expand Up @@ -1614,7 +1614,7 @@ int FontCascade::offsetForPositionForSimpleText(const TextRun& run, float x, boo
GlyphBuffer localGlyphBuffer;
unsigned offset;
if (run.rtl()) {
delta -= floatWidthForSimpleText(run);
delta -= widthForTextUsingWidthIterator(run);
while (1) {
offset = it.currentCharacterIndex();
float w;
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/graphics/FontCascade.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class FontCascade : public CanMakeWeakPtr<FontCascade>, public CanMakeCheckedPtr

float widthOfTextRange(const TextRun&, unsigned from, unsigned to, SingleThreadWeakHashSet<const Font>* fallbackFonts = nullptr, float* outWidthBeforeRange = nullptr, float* outWidthAfterRange = nullptr) const;
WEBCORE_EXPORT float width(const TextRun&, SingleThreadWeakHashSet<const Font>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
float widthForSimpleText(StringView text, TextDirection = TextDirection::LTR) const;
float widthForTextUsingSimplifiedMeasuring(StringView text, TextDirection = TextDirection::LTR) const;
WEBCORE_EXPORT float widthForSimpleTextWithFixedPitch(StringView text, bool whitespaceIsCollapsed) const;

std::unique_ptr<TextLayout, TextLayoutDeleter> createLayout(RenderText&, float xPos, bool collapseWhiteSpace) const;
Expand Down Expand Up @@ -232,7 +232,7 @@ class FontCascade : public CanMakeWeakPtr<FontCascade>, public CanMakeCheckedPtr
GlyphBuffer layoutSimpleText(const TextRun&, unsigned from, unsigned to, ForTextEmphasisOrNot = NotForTextEmphasis) const;
void drawGlyphBuffer(GraphicsContext&, const GlyphBuffer&, FloatPoint&, CustomFontNotReadyAction) const;
void drawEmphasisMarks(GraphicsContext&, const GlyphBuffer&, const AtomString&, const FloatPoint&) const;
float floatWidthForSimpleText(const TextRun&, SingleThreadWeakHashSet<const Font>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
float widthForTextUsingWidthIterator(const TextRun&, SingleThreadWeakHashSet<const Font>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
int offsetForPositionForSimpleText(const TextRun&, float position, bool includePartialGlyphs) const;
void adjustSelectionRectForSimpleText(const TextRun&, LayoutRect& selectionRect, unsigned from, unsigned to) const;
WEBCORE_EXPORT float widthForSimpleTextSlow(StringView text, TextDirection, float*) const;
Expand All @@ -244,7 +244,7 @@ class FontCascade : public CanMakeWeakPtr<FontCascade>, public CanMakeCheckedPtr
static bool canExpandAroundIdeographsInComplexText();

GlyphBuffer layoutComplexText(const TextRun&, unsigned from, unsigned to, ForTextEmphasisOrNot = NotForTextEmphasis) const;
float floatWidthForComplexText(const TextRun&, SingleThreadWeakHashSet<const Font>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
float widthForTextUsingComplexTextController(const TextRun&, SingleThreadWeakHashSet<const Font>* fallbackFonts = nullptr, GlyphOverflow* = nullptr) const;
int offsetForPositionForComplexText(const TextRun&, float position, bool includePartialGlyphs) const;
void adjustSelectionRectForComplexText(const TextRun&, LayoutRect& selectionRect, unsigned from, unsigned to) const;

Expand Down Expand Up @@ -406,7 +406,7 @@ inline float FontCascade::tabWidth(const Font& font, const TabSize& tabSize, flo
return result - (syntheticBoldInclusion == Font::SyntheticBoldInclusion::Exclude ? font.syntheticBoldOffset() : 0);
}

inline float FontCascade::widthForSimpleText(StringView text, TextDirection textDirection) const
inline float FontCascade::widthForTextUsingSimplifiedMeasuring(StringView text, TextDirection textDirection) const
{
if (text.isNull() || text.isEmpty())
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/WidthIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static void updateCharacterAndSmallCapsIfNeeded(SmallCapsState& smallCapsState,
template <typename TextIterator>
inline void WidthIterator::advanceInternal(TextIterator& textIterator, GlyphBuffer& glyphBuffer)
{
// The core logic here needs to match FontCascade::widthForSimpleText()
// The core logic here needs to match FontCascade::widthForTextUsingSimplifiedMeasuring()
FloatRect bounds;
auto fontDescription = m_font->fontDescription();
Ref primaryFont = m_font->primaryFont();
Expand Down
4 changes: 2 additions & 2 deletions Tools/TestWebKitAPI/Tests/WebCore/MonospaceFontTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ TEST(MonospaceFontsTest, EnsureMonospaceFontInvariants)
fontCascade.fonts()->widthCache().clear();
float width = fontCascade.widthForSimpleTextWithFixedPitch(content, whitespaceIsCollapsed);
fontCascade.fonts()->widthCache().clear();
float originalWidth = fontCascade.widthForSimpleText(content);
float originalWidth = fontCascade.widthForTextUsingSimplifiedMeasuring(content);
EXPECT_EQ(originalWidth , width);
}
{
Expand All @@ -80,7 +80,7 @@ TEST(MonospaceFontsTest, EnsureMonospaceFontInvariants)
fontCascade.fonts()->widthCache().clear();
float width = fontCascade.widthForSimpleTextWithFixedPitch(content, whitespaceIsCollapsed);
fontCascade.fonts()->widthCache().clear();
float originalWidth = fontCascade.widthForSimpleText(content);
float originalWidth = fontCascade.widthForTextUsingSimplifiedMeasuring(content);
EXPECT_EQ(originalWidth , width);
}
}
Expand Down

0 comments on commit 31aadb0

Please sign in to comment.