Changeset 114032 in webkit
- Timestamp:
- Apr 12, 2012, 2:06:50 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r114031 r114032 1 2012-04-12 David Hyatt <hyatt@apple.com> 2 3 https://bugs.webkit.org/show_bug.cgi?id=83817 4 5 This patch modifies RenderText so that it scans all of its characters up front to 6 determine whether or not the simple code path can be used for measurement/rendering 7 of the text for the whole run. 8 9 TextRun now has an additional field that indicates that the character scan is not 10 required, since the entire RenderText is known to be simple. This boolean is set 11 when constructing the TextRun from the places that make TextRuns from RenderTexts. 12 13 The character scan has been refactored into a static Font method so that it can be 14 called by RenderText. The scan of individual TextRuns is also done using the same method 15 so that the code is shared. 16 17 Reviewed by Dan Bernstein. 18 19 * platform/graphics/Font.cpp: 20 (WebCore::Font::codePath): 21 (WebCore::Font::characterRangeCodePath): 22 * platform/graphics/Font.h: 23 * platform/graphics/TextRun.h: 24 (WebCore::TextRun::TextRun): 25 (WebCore::TextRun::characterScanForCodePath): 26 (WebCore::TextRun::setCharacterScanForCodePath): 27 (TextRun): 28 * rendering/InlineTextBox.cpp: 29 (WebCore::InlineTextBox::constructTextRun): 30 * rendering/RenderBlockLineLayout.cpp: 31 (WebCore::textWidth): 32 * rendering/RenderText.cpp: 33 (WebCore::RenderText::RenderText): 34 (WebCore::RenderText::widthFromCache): 35 (WebCore::RenderText::setTextInternal): 36 (WebCore::RenderText::width): 37 (WebCore::RenderText::computeCanUseSimpleFontCodePath): 38 (WebCore): 39 * rendering/RenderText.h: 40 (RenderText): 41 (WebCore::RenderText::canUseSimpleFontCodePath): 42 1 43 2012-04-12 Levi Weintraub <leviw@chromium.org> 2 44 -
trunk/Source/WebCore/platform/graphics/Font.cpp
r113968 r114032 267 267 if (m_fontDescription.featureSettings() && m_fontDescription.featureSettings()->size() > 0) 268 268 return Complex; 269 270 CodePath result = Simple; 271 272 // Start from 0 since drawing and highlighting also measure the characters before run->from 269 270 if (run.length() > 1 && typesettingFeatures()) 271 return Complex; 272 273 if (!run.characterScanForCodePath()) 274 return Simple; 275 276 // Start from 0 since drawing and highlighting also measure the characters before run->from. 277 return characterRangeCodePath(run.characters(), run.length()); 278 } 279 280 Font::CodePath Font::characterRangeCodePath(const UChar* characters, unsigned len) 281 { 273 282 // FIXME: Should use a UnicodeSet in ports where ICU is used. Note that we 274 283 // can't simply use UnicodeCharacter Property/class because some characters … … 276 285 // Alternatively, we may as well consider binary search over a sorted 277 286 // list of ranges. 278 for (int i = 0; i < run.length(); i++) { 279 const UChar c = run[i]; 287 CodePath result = Simple; 288 for (unsigned i = 0; i < len; i++) { 289 const UChar c = characters[i]; 280 290 if (c < 0x2E5) // U+02E5 through U+02E9 (Modifier Letters : Tone letters) 281 291 continue; … … 384 394 // High surrogate 385 395 386 if (i == run.length()- 1)387 continue; 388 389 UChar next = run[++i];396 if (i == len - 1) 397 continue; 398 399 UChar next = characters[++i]; 390 400 if (!U16_IS_TRAIL(next)) 391 401 continue; … … 419 429 return Complex; 420 430 } 421 422 if (run.length() > 1 && typesettingFeatures())423 return Complex;424 425 431 return result; 426 432 } -
trunk/Source/WebCore/platform/graphics/Font.h
r113968 r114032 194 194 enum CodePath { Auto, Simple, Complex, SimpleWithGlyphOverflow }; 195 195 CodePath codePath(const TextRun&) const; 196 196 static CodePath characterRangeCodePath(const UChar*, unsigned len); 197 197 198 private: 198 199 enum ForTextEmphasisOrNot { NotForTextEmphasis, ForTextEmphasis }; -
trunk/Source/WebCore/platform/graphics/TextRun.h
r95901 r114032 59 59 typedef unsigned RoundingHacks; 60 60 61 TextRun(const UChar* c, int len, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, RoundingHacks roundingHacks = RunRounding | WordRounding)61 TextRun(const UChar* c, int len, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding) 62 62 : m_characters(c) 63 63 , m_charactersLength(len) … … 72 72 , m_direction(direction) 73 73 , m_directionalOverride(directionalOverride) 74 , m_characterScanForCodePath(characterScanForCodePath) 74 75 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHacks) 75 76 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks) … … 78 79 } 79 80 80 TextRun(const String& s, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, RoundingHacks roundingHacks = RunRounding | WordRounding)81 TextRun(const String& s, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, TextDirection direction = LTR, bool directionalOverride = false, bool characterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding) 81 82 : m_characters(s.characters()) 82 83 , m_charactersLength(s.length()) … … 91 92 , m_direction(direction) 92 93 , m_directionalOverride(directionalOverride) 94 , m_characterScanForCodePath(characterScanForCodePath) 93 95 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHacks) 94 96 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRoundingHacks) … … 123 125 bool ltr() const { return m_direction == LTR; } 124 126 bool directionalOverride() const { return m_directionalOverride; } 127 bool characterScanForCodePath() const { return m_characterScanForCodePath; } 125 128 bool applyRunRounding() const { return m_applyRunRounding; } 126 129 bool applyWordRounding() const { return m_applyWordRounding; } … … 131 134 void setDirection(TextDirection direction) { m_direction = direction; } 132 135 void setDirectionalOverride(bool override) { m_directionalOverride = override; } 136 void setCharacterScanForCodePath(bool scan) { m_characterScanForCodePath = scan; } 133 137 134 138 class RenderingContext : public RefCounted<RenderingContext> { … … 168 172 TextDirection m_direction; 169 173 bool m_directionalOverride; // Was this direction set by an override character. 174 bool m_characterScanForCodePath; 170 175 bool m_applyRunRounding; 171 176 bool m_applyWordRounding; -
trunk/Source/WebCore/rendering/InlineTextBox.cpp
r113059 r114032 1326 1326 ASSERT(maximumLength >= length); 1327 1327 1328 TextRun run(characters, length, textRenderer->allowTabs(), textPos(), expansion(), expansionBehavior(), direction(), dirOverride() || style->rtlOrdering() == VisualOrder );1328 TextRun run(characters, length, textRenderer->allowTabs(), textPos(), expansion(), expansionBehavior(), direction(), dirOverride() || style->rtlOrdering() == VisualOrder, !textRenderer->canUseSimpleFontCodePath()); 1329 1329 if (textRunNeedsRenderingContext(font)) 1330 1330 run.setRenderingContext(SVGTextRunRenderingContext::create(textRenderer)); -
trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp
r113665 r114032 1948 1948 ASSERT(run.charactersLength() >= run.length()); 1949 1949 1950 run.setCharacterScanForCodePath(!text->canUseSimpleFontCodePath()); 1950 1951 run.setAllowTabs(!collapseWhiteSpace); 1951 1952 run.setXPos(xPos); -
trunk/Source/WebCore/rendering/RenderText.cpp
r113665 r114032 147 147 , m_containsReversedText(false) 148 148 , m_isAllASCII(m_text.containsOnlyASCII()) 149 , m_canUseSimpleFontCodePath(computeCanUseSimpleFontCodePath()) 149 150 , m_knownToHaveNoOverflowAndNoFallbackFonts(false) 150 151 , m_needsTranscoding(false) … … 761 762 ASSERT(run.charactersLength() >= run.length()); 762 763 764 run.setCharacterScanForCodePath(!canUseSimpleFontCodePath()); 763 765 run.setAllowTabs(allowTabs()); 764 766 run.setXPos(xPos); … … 1331 1333 1332 1334 m_isAllASCII = m_text.containsOnlyASCII(); 1335 m_canUseSimpleFontCodePath = computeCanUseSimpleFontCodePath(); 1333 1336 } 1334 1337 … … 1474 1477 ASSERT(run.charactersLength() >= run.length()); 1475 1478 1479 run.setCharacterScanForCodePath(!canUseSimpleFontCodePath()); 1476 1480 run.setAllowTabs(allowTabs()); 1477 1481 run.setXPos(xPos); … … 1794 1798 } 1795 1799 1800 bool RenderText::computeCanUseSimpleFontCodePath() const 1801 { 1802 if (isAllASCII()) 1803 return true; 1804 return Font::characterRangeCodePath(characters(), length()) == Font::Simple; 1805 } 1806 1796 1807 #ifndef NDEBUG 1797 1808 -
trunk/Source/WebCore/rendering/RenderText.h
r112776 r114032 130 130 virtual void computePreferredLogicalWidths(float leadWidth); 131 131 bool isAllCollapsibleWhitespace(); 132 132 133 bool canUseSimpleFontCodePath() const { return m_canUseSimpleFontCodePath; } 133 134 bool knownToHaveNoOverflowAndNoFallbackFonts() const { return m_knownToHaveNoOverflowAndNoFallbackFonts; } 134 135 … … 149 150 void computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow&); 150 151 152 bool computeCanUseSimpleFontCodePath() const; 153 151 154 // Make length() private so that callers that have a RenderText* 152 155 // will use the more efficient textLength() instead, while … … 187 190 bool m_containsReversedText : 1; 188 191 bool m_isAllASCII : 1; 192 bool m_canUseSimpleFontCodePath : 1; 189 193 mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1; 190 194 bool m_needsTranscoding : 1;
Note:
See TracChangeset
for help on using the changeset viewer.