Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Unified Diff: third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.cpp

Issue 2153643003: Change ShapeResultShaping::computeSpacing to use TextRun::operator[] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.cpp b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.cpp
index 40f2d909d8a87f4b6c6c326ba7ba11e982aad2fe..d5290a1cc4b48031a98c27a49367e1825abb1196 100644
--- a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.cpp
+++ b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.cpp
@@ -70,12 +70,63 @@ float ShapeResultSpacing::nextExpansion()
return m_expansionPerOpportunity;
}
+bool ShapeResultSpacing::isFirstRun(const TextRun& run) const
+{
+ if (&run == &m_textRun)
+ return true;
+ return run.is8Bit()
+ ? run.characters8() == m_textRun.characters8()
+ : run.characters16() == m_textRun.characters16();
+}
+
float ShapeResultSpacing::computeSpacing(const TextRun& run, size_t index,
float& offset)
{
- if (run.is8Bit())
- return computeSpacing(run.characters8(), run.length(), index, offset);
- return computeSpacing(run.characters16(), run.length(), index, offset);
+ UChar32 character = run[index];
+ bool treatAsSpace = (Character::treatAsSpace(character)
+ || (m_normalizeSpace && Character::isNormalizedCanvasSpaceCharacter(character)))
+ && (character != '\t' || !m_allowTabs);
+ if (treatAsSpace && character != noBreakSpaceCharacter)
+ character = spaceCharacter;
+
+ float spacing = 0;
+ if (m_letterSpacing && !Character::treatAsZeroWidthSpace(character))
+ spacing += m_letterSpacing;
+
+ if (treatAsSpace && (index || !isFirstRun(run) || character == noBreakSpaceCharacter))
+ spacing += m_wordSpacing;
+
+ if (!hasExpansion())
+ return spacing;
+
+ if (treatAsSpace)
+ return spacing + nextExpansion();
+
+ if (run.is8Bit() || m_textJustify != TextJustify::TextJustifyAuto)
+ return spacing;
+
+ // isCJKIdeographOrSymbol() has expansion opportunities both before and
+ // after each character.
+ // http://www.w3.org/TR/jlreq/#line_adjustment
+ if (U16_IS_LEAD(character) && index + 1 < run.length() && U16_IS_TRAIL(run[index + 1]))
+ character = U16_GET_SUPPLEMENTARY(character, run[index + 1]);
+ if (!Character::isCJKIdeographOrSymbol(character)) {
+ m_isAfterExpansion = false;
+ return spacing;
+ }
+
+ if (!m_isAfterExpansion) {
+ // Take the expansion opportunity before this ideograph.
+ float expandBefore = nextExpansion();
+ if (expandBefore) {
+ offset += expandBefore;
+ spacing += expandBefore;
+ }
+ if (!hasExpansion())
+ return spacing;
+ }
+
+ return spacing + nextExpansion();
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/ShapeResultSpacing.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698