Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 RefPtr<ShapeResult> shapeResult = shaper.shapeResult(); | 91 RefPtr<ShapeResult> shapeResult = shaper.shapeResult(); |
| 92 if (!shapeResult) | 92 if (!shapeResult) |
| 93 return nullptr; | 93 return nullptr; |
| 94 | 94 |
| 95 if (cacheEntry) | 95 if (cacheEntry) |
| 96 cacheEntry->m_shapeResult = shapeResult; | 96 cacheEntry->m_shapeResult = shapeResult; |
| 97 | 97 |
| 98 return shapeResult.release(); | 98 return shapeResult.release(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 bool shapeRange(RefPtr<ShapeResult>* result, std::pair<unsigned, unsigned> r ange) | |
| 102 { | |
| 103 if (!range.second) | |
| 104 return false; | |
| 105 | |
| 106 if (!range.first && range.second == static_cast<unsigned>(m_textRun.leng th())) { | |
| 107 *result = shapeWord(m_textRun, m_font); | |
| 108 return *result; | |
| 109 } | |
| 110 | |
| 111 TextRun subRun = m_textRun.subRun(range.first, range.second); | |
| 112 *result = shapeWord(subRun, m_font); | |
| 113 return *result; | |
| 114 } | |
| 115 | |
| 116 std::pair<unsigned, unsigned> nextWordRange() | |
|
drott
2015/12/16 12:40:58
I'd suggest making std::pair<unsigned, unsigned> a
kojii
2015/12/16 12:53:34
That one I was wondering, thank you for pointing i
| |
| 117 { | |
| 118 const unsigned start = m_startIndex; | |
| 119 const unsigned length = m_textRun.length(); | |
| 120 if (start >= length) | |
| 121 return std::make_pair(0, 0); | |
| 122 | |
| 123 if (m_textRun[start] == spaceCharacter | |
| 124 || m_textRun[start] == tabulationCharacter) { | |
| 125 m_startIndex++; | |
| 126 return std::make_pair(start, 1); | |
| 127 } | |
| 128 | |
| 129 for (unsigned i = start + 1; ; i++) { | |
|
drott
2015/12/16 12:40:59
Can this loop and use nextRangeUntil as well?
kojii
2015/12/16 12:53:34
This needs two characters, and possibly more other
| |
| 130 if (i == length || m_textRun[i] == spaceCharacter | |
| 131 || m_textRun[i] == tabulationCharacter) { | |
| 132 m_startIndex = i; | |
| 133 return std::make_pair(start, i - start); | |
| 134 } | |
| 135 } | |
| 136 } | |
| 137 | |
| 101 bool nextWord(RefPtr<ShapeResult>* wordResult) | 138 bool nextWord(RefPtr<ShapeResult>* wordResult) |
| 102 { | 139 { |
| 103 unsigned length = m_textRun.length(); | 140 return shapeRange(wordResult, nextWordRange()); |
| 104 if (m_startIndex < length) { | |
| 105 if (m_textRun[m_startIndex] == spaceCharacter | |
| 106 || m_textRun[m_startIndex] == tabulationCharacter) { | |
| 107 TextRun wordRun = m_textRun.subRun(m_startIndex, 1); | |
| 108 *wordResult = shapeWord(wordRun, m_font); | |
| 109 m_startIndex++; | |
| 110 return *wordResult; | |
| 111 } | |
| 112 | |
| 113 return nextUntilCharacterOrTab(wordResult, spaceCharacter); | |
| 114 } | |
| 115 return false; | |
| 116 } | 141 } |
| 117 | 142 |
| 118 bool nextUntilCharacterOrTab(RefPtr<ShapeResult>* wordResult, UChar delimite r) | 143 std::pair<unsigned, unsigned> nextRangeUntil(UChar ch) |
|
drott
2015/12/16 12:40:59
What's the difference between nextRangeUntil and n
kojii
2015/12/16 12:53:34
"Until" exists loop when "==" while "While" exists
| |
| 119 { | 144 { |
| 120 unsigned length = m_textRun.length(); | 145 const unsigned start = m_startIndex; |
| 146 const unsigned length = m_textRun.length(); | |
| 121 ASSERT(m_startIndex < length); | 147 ASSERT(m_startIndex < length); |
| 122 for (unsigned i = m_startIndex + 1; ; i++) { | 148 for (unsigned i = start + 1; ; i++) { |
| 123 if (i == length || m_textRun[i] == delimiter | 149 if (i == length || m_textRun[i] == ch) { |
| 124 || m_textRun[i] == tabulationCharacter) { | |
| 125 TextRun wordRun = m_textRun.subRun(m_startIndex, | |
| 126 i - m_startIndex); | |
| 127 m_startIndex = i; | 150 m_startIndex = i; |
| 128 *wordResult = shapeWord(wordRun, m_font); | 151 return std::make_pair(start, i - start); |
| 129 return *wordResult; | |
| 130 } | 152 } |
| 131 } | 153 } |
| 132 } | 154 } |
| 155 | |
| 156 std::pair<unsigned, unsigned> nextRangeWhile(UChar ch) | |
| 157 { | |
| 158 const unsigned start = m_startIndex; | |
| 159 const unsigned length = m_textRun.length(); | |
| 160 ASSERT(m_startIndex < length); | |
| 161 for (unsigned i = start + 1; ; i++) { | |
| 162 if (i == length || m_textRun[i] != ch) { | |
| 163 m_startIndex = i; | |
| 164 return std::make_pair(start, i - start); | |
| 165 } | |
| 166 } | |
| 167 } | |
| 133 | 168 |
| 134 bool nextForAllowTabs(RefPtr<ShapeResult>* wordResult) | 169 bool nextForAllowTabs(RefPtr<ShapeResult>* wordResult) |
| 135 { | 170 { |
| 136 unsigned length = m_textRun.length(); | 171 unsigned length = m_textRun.length(); |
| 137 if (m_startIndex >= length) | 172 if (m_startIndex >= length) |
| 138 return false; | 173 return false; |
| 139 | 174 |
| 140 if (UNLIKELY(m_textRun[m_startIndex] == tabulationCharacter)) { | 175 if (UNLIKELY(m_textRun[m_startIndex] == tabulationCharacter)) { |
| 141 for (unsigned i = m_startIndex + 1; ; i++) { | 176 *wordResult = ShapeResult::createForTabulationCharacters( |
| 142 if (i == length || m_textRun[i] != tabulationCharacter) { | 177 m_font, m_textRun, m_widthSoFar, |
| 143 *wordResult = ShapeResult::createForTabulationCharacters( | 178 nextRangeWhile(tabulationCharacter).second); |
| 144 m_font, m_textRun, m_widthSoFar, i - m_startIndex); | |
| 145 m_startIndex = i; | |
| 146 break; | |
| 147 } | |
| 148 } | |
| 149 } else if (!m_shapeByWord) { | 179 } else if (!m_shapeByWord) { |
| 150 if (!nextUntilCharacterOrTab(wordResult, 0)) | 180 if (!shapeRange(wordResult, nextRangeUntil(tabulationCharacter))) |
| 151 return false; | 181 return false; |
| 152 } else { | 182 } else { |
| 153 if (!nextWord(wordResult)) | 183 if (!nextWord(wordResult)) |
| 154 return false; | 184 return false; |
| 155 } | 185 } |
| 156 if (!*wordResult) | 186 ASSERT(*wordResult); |
|
drott
2015/12/16 12:40:59
What has changed to be able upgrade this to an ass
kojii
2015/12/16 12:53:34
Actually, nothing; even before the patch, this sho
| |
| 157 return false; | |
| 158 m_widthSoFar += (*wordResult)->width(); | 187 m_widthSoFar += (*wordResult)->width(); |
| 159 return true; | 188 return true; |
| 160 } | 189 } |
| 161 | 190 |
| 162 ShapeCache* m_shapeCache; | 191 ShapeCache* m_shapeCache; |
| 163 const TextRun& m_textRun; | 192 const TextRun& m_textRun; |
| 164 const Font* m_font; | 193 const Font* m_font; |
| 165 float m_widthSoFar; // Used only when allowTabs() | 194 float m_widthSoFar; // Used only when allowTabs() |
| 166 unsigned m_startIndex : 30; | 195 unsigned m_startIndex : 30; |
| 167 unsigned m_wordResultCachable : 1; | 196 unsigned m_wordResultCachable : 1; |
| 168 unsigned m_shapeByWord : 1; | 197 unsigned m_shapeByWord : 1; |
| 169 }; | 198 }; |
| 170 | 199 |
| 171 } // namespace blink | 200 } // namespace blink |
| 172 | 201 |
| 173 #endif // CachingWordShapeIterator_h | 202 #endif // CachingWordShapeIterator_h |
| OLD | NEW |