Skip to content

Commit b9f401b

Browse files
committed
REGRESSION(r281389): canUseSimplifiedTextMeasuring() needs to match with WidthIterator::applyCSSVisibilityRules()
https://bugs.webkit.org/show_bug.cgi?id=229388 Reviewed by Alan Bujtas. WidthIterator::applyCSSVisibilityRules() has some special handling for specific characters. If those characters are present, we need to make sure we actually use WidthIterator::applyCSSVisibilityRules() instead of taking the fast path in FontCascade::widthForSimpleText(). This is split out from https://bugs.webkit.org/show_bug.cgi?id=215643, and will be tested by that bug's test. * layout/layouttree/LayoutTreeBuilder.cpp: (WebCore::Layout::canUseSimplifiedTextMeasuring): * platform/graphics/WidthIterator.cpp: (WebCore::WidthIterator::characterCanUseSimplifiedTextMeasuring): (WebCore::WidthIterator::applyCSSVisibilityRules): * platform/graphics/WidthIterator.h: * rendering/RenderText.cpp: (WebCore::RenderText::computeCanUseSimplifiedTextMeasuring const): Canonical link: https://commits.webkit.org/240813@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281423 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 50a5b12 commit b9f401b

5 files changed

Lines changed: 71 additions & 2 deletions

File tree

Source/WebCore/ChangeLog

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2021-08-22 Myles C. Maxfield <mmaxfield@apple.com>
2+
3+
REGRESSION(r281389): canUseSimplifiedTextMeasuring() needs to match with WidthIterator::applyCSSVisibilityRules()
4+
https://bugs.webkit.org/show_bug.cgi?id=229388
5+
6+
Reviewed by Alan Bujtas.
7+
8+
WidthIterator::applyCSSVisibilityRules() has some special handling for specific characters.
9+
If those characters are present, we need to make sure we actually use WidthIterator::applyCSSVisibilityRules()
10+
instead of taking the fast path in FontCascade::widthForSimpleText().
11+
12+
This is split out from https://bugs.webkit.org/show_bug.cgi?id=215643, and will be tested by that bug's test.
13+
14+
* layout/layouttree/LayoutTreeBuilder.cpp:
15+
(WebCore::Layout::canUseSimplifiedTextMeasuring):
16+
* platform/graphics/WidthIterator.cpp:
17+
(WebCore::WidthIterator::characterCanUseSimplifiedTextMeasuring):
18+
(WebCore::WidthIterator::applyCSSVisibilityRules):
19+
* platform/graphics/WidthIterator.h:
20+
* rendering/RenderText.cpp:
21+
(WebCore::RenderText::computeCanUseSimplifiedTextMeasuring const):
22+
123
2021-08-22 Alan Bujtas <zalan@apple.com>
224

325
[LFC][IFC] Add support for vertical-align: sub

Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "RenderTableCaption.h"
6262
#include "RenderTableCell.h"
6363
#include "RenderView.h"
64+
#include "WidthIterator.h"
6465
#include <wtf/IsoMallocInlines.h>
6566
#include <wtf/text/TextStream.h>
6667

@@ -106,7 +107,7 @@ static bool canUseSimplifiedTextMeasuring(const StringView& content, const FontC
106107
return false;
107108

108109
for (unsigned i = 0; i < content.length(); ++i) {
109-
if ((!whitespaceIsCollapsed && content[i] == '\t') || content[i] == noBreakSpace || content[i] == softHyphen || content[i] >= HiraganaLetterSmallA)
110+
if (!WidthIterator::characterCanUseSimplifiedTextMeasuring(content[i], whitespaceIsCollapsed))
110111
return false;
111112
}
112113
return true;

Source/WebCore/platform/graphics/WidthIterator.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,51 @@ void WidthIterator::applyExtraSpacingAfterShaping(GlyphBuffer& glyphBuffer, unsi
515515
}
516516
}
517517

518+
bool WidthIterator::characterCanUseSimplifiedTextMeasuring(UChar character, bool whitespaceIsCollapsed)
519+
{
520+
// This function needs to be kept in sync with applyCSSVisibilityRules().
521+
522+
switch (character) {
523+
case tabCharacter:
524+
if (!whitespaceIsCollapsed)
525+
return false;
526+
break;
527+
case noBreakSpace:
528+
case softHyphen:
529+
case newlineCharacter:
530+
case carriageReturn:
531+
case leftToRightMark:
532+
case rightToLeftMark:
533+
case leftToRightEmbed:
534+
case rightToLeftEmbed:
535+
case leftToRightOverride:
536+
case rightToLeftOverride:
537+
case leftToRightIsolate:
538+
case rightToLeftIsolate:
539+
case zeroWidthNonJoiner:
540+
case zeroWidthJoiner:
541+
case popDirectionalFormatting:
542+
case popDirectionalIsolate:
543+
case firstStrongIsolate:
544+
case objectReplacementCharacter:
545+
case zeroWidthNoBreakSpace:
546+
return false;
547+
break;
548+
}
549+
550+
if (character >= HiraganaLetterSmallA
551+
|| u_charType(character) == U_CONTROL_CHAR
552+
|| (character >= nullCharacter && character < space)
553+
|| (character >= deleteCharacter && character < noBreakSpace))
554+
return false;
555+
556+
return true;
557+
}
558+
518559
void WidthIterator::applyCSSVisibilityRules(GlyphBuffer& glyphBuffer, unsigned glyphBufferStartIndex)
519560
{
561+
// This function needs to be kept in sync with characterCanUseSimplifiedTextMeasuring().
562+
520563
Vector<unsigned> glyphsIndicesToBeDeleted;
521564

522565
float yPosition = height(glyphBuffer.initialAdvance());

Source/WebCore/platform/graphics/WidthIterator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ struct WidthIterator {
5656
float runWidthSoFar() const { return m_runWidthSoFar; }
5757
unsigned currentCharacterIndex() const { return m_currentCharacterIndex; }
5858

59+
static bool characterCanUseSimplifiedTextMeasuring(UChar, bool whitespaceIsCollapsed);
60+
5961
private:
6062
GlyphData glyphDataForCharacter(UChar32, bool mirror);
6163
template <typename TextIterator>

Source/WebCore/rendering/RenderText.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "Text.h"
5353
#include "TextResourceDecoder.h"
5454
#include "VisiblePosition.h"
55+
#include "WidthIterator.h"
5556
#include <wtf/IsoMallocInlines.h>
5657
#include <wtf/NeverDestroyed.h>
5758
#include <wtf/text/StringBuilder.h>
@@ -1433,7 +1434,7 @@ bool RenderText::computeCanUseSimplifiedTextMeasuring() const
14331434

14341435
auto whitespaceIsCollapsed = style().collapseWhiteSpace();
14351436
for (unsigned i = 0; i < text().length(); ++i) {
1436-
if ((!whitespaceIsCollapsed && text()[i] == '\t') || text()[i] == noBreakSpace || text()[i] == softHyphen || text()[i] >= HiraganaLetterSmallA)
1437+
if (!WidthIterator::characterCanUseSimplifiedTextMeasuring(text()[i], whitespaceIsCollapsed))
14371438
return false;
14381439
}
14391440
return true;

0 commit comments

Comments
 (0)