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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 public: | 43 public: |
44 CachingWordShapeIterator(ShapeCache* cache, | 44 CachingWordShapeIterator(ShapeCache* cache, |
45 const TextRun& run, | 45 const TextRun& run, |
46 const Font* font) | 46 const Font* font) |
47 : m_shapeCache(cache), | 47 : m_shapeCache(cache), |
48 m_textRun(run), | 48 m_textRun(run), |
49 m_font(font), | 49 m_font(font), |
50 m_spacing(run, font->getFontDescription()), | 50 m_spacing(run, font->getFontDescription()), |
51 m_widthSoFar(0), | 51 m_widthSoFar(0), |
52 m_startIndex(0) { | 52 m_startIndex(0) { |
53 ASSERT(font); | 53 DCHECK(font); |
54 | 54 |
55 // Shaping word by word is faster as each word is cached. If we cannot | 55 // Shaping word by word is faster as each word is cached. If we cannot |
56 // use the cache or if the font doesn't support word by word shaping | 56 // use the cache or if the font doesn't support word by word shaping |
57 // fall back on shaping the entire run. | 57 // fall back on shaping the entire run. |
58 m_shapeByWord = m_font->canShapeWordByWord(); | 58 m_shapeByWord = m_font->canShapeWordByWord(); |
59 } | 59 } |
60 | 60 |
61 bool next(RefPtr<const ShapeResult>* wordResult) { | 61 bool next(RefPtr<const ShapeResult>* wordResult) { |
62 if (UNLIKELY(m_textRun.allowTabs())) | 62 if (UNLIKELY(m_textRun.allowTabs())) |
63 return nextForAllowTabs(wordResult); | 63 return nextForAllowTabs(wordResult); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 | 149 |
150 bool shapeToEndIndex(RefPtr<const ShapeResult>* result, unsigned endIndex) { | 150 bool shapeToEndIndex(RefPtr<const ShapeResult>* result, unsigned endIndex) { |
151 if (!endIndex || endIndex <= m_startIndex) | 151 if (!endIndex || endIndex <= m_startIndex) |
152 return false; | 152 return false; |
153 | 153 |
154 const unsigned length = m_textRun.length(); | 154 const unsigned length = m_textRun.length(); |
155 if (!m_startIndex && endIndex == length) { | 155 if (!m_startIndex && endIndex == length) { |
156 *result = shapeWord(m_textRun, m_font); | 156 *result = shapeWord(m_textRun, m_font); |
157 } else { | 157 } else { |
158 ASSERT(endIndex <= length); | 158 DCHECK_LE(endIndex, length); |
159 TextRun subRun = m_textRun.subRun(m_startIndex, endIndex - m_startIndex); | 159 TextRun subRun = m_textRun.subRun(m_startIndex, endIndex - m_startIndex); |
160 *result = shapeWord(subRun, m_font); | 160 *result = shapeWord(subRun, m_font); |
161 } | 161 } |
162 m_startIndex = endIndex; | 162 m_startIndex = endIndex; |
163 return result->get(); | 163 return result->get(); |
164 } | 164 } |
165 | 165 |
166 unsigned endIndexUntil(UChar ch) const { | 166 unsigned endIndexUntil(UChar ch) const { |
167 unsigned length = m_textRun.length(); | 167 unsigned length = m_textRun.length(); |
168 ASSERT(m_startIndex < length); | 168 DCHECK_LT(m_startIndex, length); |
169 for (unsigned i = m_startIndex + 1;; i++) { | 169 for (unsigned i = m_startIndex + 1;; i++) { |
170 if (i == length || m_textRun[i] == ch) | 170 if (i == length || m_textRun[i] == ch) |
171 return i; | 171 return i; |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 bool nextForAllowTabs(RefPtr<const ShapeResult>* wordResult) { | 175 bool nextForAllowTabs(RefPtr<const ShapeResult>* wordResult) { |
176 unsigned length = m_textRun.length(); | 176 unsigned length = m_textRun.length(); |
177 if (m_startIndex >= length) | 177 if (m_startIndex >= length) |
178 return false; | 178 return false; |
179 | 179 |
180 if (UNLIKELY(m_textRun[m_startIndex] == tabulationCharacter)) { | 180 if (UNLIKELY(m_textRun[m_startIndex] == tabulationCharacter)) { |
181 for (unsigned i = m_startIndex + 1;; i++) { | 181 for (unsigned i = m_startIndex + 1;; i++) { |
182 if (i == length || m_textRun[i] != tabulationCharacter) { | 182 if (i == length || m_textRun[i] != tabulationCharacter) { |
183 *wordResult = ShapeResult::createForTabulationCharacters( | 183 *wordResult = ShapeResult::createForTabulationCharacters( |
184 m_font, m_textRun, m_widthSoFar, i - m_startIndex); | 184 m_font, m_textRun, m_widthSoFar, i - m_startIndex); |
185 m_startIndex = i; | 185 m_startIndex = i; |
186 break; | 186 break; |
187 } | 187 } |
188 } | 188 } |
189 } else if (!m_shapeByWord) { | 189 } else if (!m_shapeByWord) { |
190 if (!shapeToEndIndex(wordResult, endIndexUntil(tabulationCharacter))) | 190 if (!shapeToEndIndex(wordResult, endIndexUntil(tabulationCharacter))) |
191 return false; | 191 return false; |
192 } else { | 192 } else { |
193 if (!nextWord(wordResult)) | 193 if (!nextWord(wordResult)) |
194 return false; | 194 return false; |
195 } | 195 } |
196 ASSERT(*wordResult); | 196 DCHECK(*wordResult); |
197 m_widthSoFar += (*wordResult)->width(); | 197 m_widthSoFar += (*wordResult)->width(); |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 ShapeCache* m_shapeCache; | 201 ShapeCache* m_shapeCache; |
202 const TextRun& m_textRun; | 202 const TextRun& m_textRun; |
203 const Font* m_font; | 203 const Font* m_font; |
204 ShapeResultSpacing m_spacing; | 204 ShapeResultSpacing m_spacing; |
205 float m_widthSoFar; // Used only when allowTabs() | 205 float m_widthSoFar; // Used only when allowTabs() |
206 unsigned m_startIndex : 31; | 206 unsigned m_startIndex : 31; |
207 unsigned m_shapeByWord : 1; | 207 unsigned m_shapeByWord : 1; |
208 }; | 208 }; |
209 | 209 |
210 } // namespace blink | 210 } // namespace blink |
211 | 211 |
212 #endif // CachingWordShapeIterator_h | 212 #endif // CachingWordShapeIterator_h |
OLD | NEW |