Index: Source/platform/fonts/shaping/CachingWordShapeIterator.h |
diff --git a/Source/platform/fonts/shaping/CachingWordShapeIterator.h b/Source/platform/fonts/shaping/CachingWordShapeIterator.h |
index 2321d81c85b47ea976ea3c5a79578111c3cab5fe..dbaafbc886f7109313ae61ee5ab6c3f345aae669 100644 |
--- a/Source/platform/fonts/shaping/CachingWordShapeIterator.h |
+++ b/Source/platform/fonts/shaping/CachingWordShapeIterator.h |
@@ -38,7 +38,8 @@ class CachingWordShapeIterator { |
public: |
CachingWordShapeIterator(ShapeCache* cache, const TextRun& run, |
const Font* font) |
- : m_shapeCache(cache), m_textRun(run), m_font(font), m_startIndex(0) |
+ : m_shapeCache(cache), m_textRun(run), m_font(font) |
+ , m_widthSoFar(0), m_startIndex(0) |
{ |
ASSERT(font); |
const FontDescription& fontDescription = font->fontDescription(); |
@@ -60,6 +61,8 @@ public: |
bool next(RefPtr<ShapeResult>* wordResult) |
{ |
if (!m_shapeByWord) { |
+ if (UNLIKELY(m_textRun.allowTabs())) |
+ return nextForAllowTabs(wordResult); |
if (m_startIndex) |
return false; |
*wordResult = shapeWord(m_textRun, m_font); |
@@ -76,16 +79,10 @@ public: |
return true; |
} |
- for (unsigned i = m_startIndex; ; i++) { |
- if (i == length || m_textRun[i] == spaceCharacter) { |
- TextRun wordRun = m_textRun.subRun(m_startIndex, |
- i - m_startIndex); |
- *wordResult = shapeWord(wordRun, m_font); |
- m_startIndex = i; |
- return true; |
- } |
- } |
+ *wordResult = shapeWordUntilCharacter(spaceCharacter); |
+ return true; |
eae
2015/08/10 17:24:07
Shouldn't this be "return *wordResult != nullptr;"
kojii
2015/08/11 07:22:21
Done. The fix was moved to nextUntilCharacterOrTab
|
} |
+ |
return false; |
} |
@@ -109,9 +106,46 @@ private: |
return shapeResult.release(); |
} |
+ PassRefPtr<ShapeResult> shapeWordUntilCharacter(UChar delimiter) |
+ { |
+ unsigned length = m_textRun.length(); |
+ ASSERT(m_startIndex < length); |
+ for (unsigned i = m_startIndex + 1;; i++) { |
+ if (i == length || m_textRun[i] == delimiter) { |
+ TextRun wordRun = m_textRun.subRun(m_startIndex, |
+ i - m_startIndex); |
+ m_startIndex = i; |
+ return shapeWord(wordRun, m_font); |
+ } |
+ } |
eae
2015/08/10 17:24:07
Missing "return nullptr"?
kojii
2015/08/11 07:22:20
The loop exits only with "return", so it's not nec
|
+ } |
+ |
+ bool nextForAllowTabs(RefPtr<ShapeResult>* wordResult) |
+ { |
+ unsigned length = m_textRun.length(); |
+ if (m_startIndex >= length) |
+ return false; |
+ |
+ if (UNLIKELY(m_textRun[m_startIndex] == tabulationCharacter)) { |
+ for (unsigned i = m_startIndex + 1;; i++) { |
+ if (i == length || m_textRun[i] != tabulationCharacter) { |
+ *wordResult = ShapeResult::createForTabulationCharacters( |
+ m_font, m_textRun, m_widthSoFar, i - m_startIndex); |
+ m_startIndex = i; |
+ break; |
+ } |
+ } |
+ } else { |
+ *wordResult = shapeWordUntilCharacter(tabulationCharacter); |
eae
2015/08/10 17:24:07
Shouldn't this still segment on space? I.e. shape
kojii
2015/08/11 07:22:21
Good point, we need to do that if we want to cache
|
+ } |
+ m_widthSoFar += (*wordResult)->width(); |
+ return true; |
+ } |
+ |
ShapeCache* m_shapeCache; |
const TextRun& m_textRun; |
const Font* m_font; |
+ float m_widthSoFar; // Used only when allowTabs() |
unsigned m_startIndex : 30; |
unsigned m_wordResultCachable : 1; |
unsigned m_shapeByWord : 1; |