OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 ShapeResult::~ShapeResult() {} | 174 ShapeResult::~ShapeResult() {} |
175 | 175 |
176 size_t ShapeResult::byteSize() const { | 176 size_t ShapeResult::byteSize() const { |
177 size_t selfByteSize = sizeof(this); | 177 size_t selfByteSize = sizeof(this); |
178 for (unsigned i = 0; i < m_runs.size(); ++i) { | 178 for (unsigned i = 0; i < m_runs.size(); ++i) { |
179 selfByteSize += m_runs[i]->byteSize(); | 179 selfByteSize += m_runs[i]->byteSize(); |
180 } | 180 } |
181 return selfByteSize; | 181 return selfByteSize; |
182 } | 182 } |
183 | 183 |
184 int ShapeResult::offsetForPosition(float targetX, | 184 unsigned ShapeResult::offsetForPosition(float targetX, |
185 bool includePartialGlyphs) const { | 185 bool includePartialGlyphs) const { |
186 int charactersSoFar = 0; | 186 unsigned charactersSoFar = 0; |
187 float currentX = 0; | 187 float currentX = 0; |
188 | 188 |
189 if (rtl()) { | 189 if (rtl()) { |
190 charactersSoFar = m_numCharacters; | 190 charactersSoFar = m_numCharacters; |
191 for (unsigned i = 0; i < m_runs.size(); ++i) { | 191 for (unsigned i = 0; i < m_runs.size(); ++i) { |
192 if (!m_runs[i]) | 192 if (!m_runs[i]) |
193 continue; | 193 continue; |
194 charactersSoFar -= m_runs[i]->m_numCharacters; | 194 charactersSoFar -= m_runs[i]->m_numCharacters; |
195 float nextX = currentX + m_runs[i]->m_width; | 195 float nextX = currentX + m_runs[i]->m_width; |
196 float offsetForRun = targetX - currentX; | 196 float offsetForRun = targetX - currentX; |
(...skipping 17 matching lines...) Expand all Loading... | |
214 return charactersSoFar + index; | 214 return charactersSoFar + index; |
215 } | 215 } |
216 charactersSoFar += m_runs[i]->m_numCharacters; | 216 charactersSoFar += m_runs[i]->m_numCharacters; |
217 currentX = nextX; | 217 currentX = nextX; |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 return charactersSoFar; | 221 return charactersSoFar; |
222 } | 222 } |
223 | 223 |
224 float ShapeResult::positionForOffset(unsigned absoluteOffset) const { | |
eae
2017/03/09 05:16:32
This is similar to how ShapeResultBuffer::getChara
| |
225 float x = 0; | |
226 float offsetX = 0; | |
227 | |
228 // The absoluteOffset argument represents the offset for the entire | |
229 // ShapeResult while offset is continuously updated to be relative to the | |
230 // current run. | |
231 unsigned offset = absoluteOffset; | |
232 | |
233 if (rtl()) { | |
234 // Convert logical offsets to visual offsets, because results are in | |
235 // logical order while runs are in visual order. | |
236 x = m_width; | |
237 if (offset < numCharacters()) | |
238 offset = numCharacters() - offset - 1; | |
239 x -= width(); | |
240 } | |
241 | |
242 for (unsigned i = 0; i < m_runs.size(); i++) { | |
243 if (!m_runs[i]) | |
244 continue; | |
245 DCHECK_EQ(rtl(), m_runs[i]->rtl()); | |
246 unsigned numCharacters = m_runs[i]->m_numCharacters; | |
247 | |
248 if (!offsetX && offset < numCharacters) { | |
249 offsetX = m_runs[i]->xPositionForVisualOffset(offset, AdjustToEnd) + x; | |
250 break; | |
251 } | |
252 | |
253 offset -= numCharacters; | |
254 x += m_runs[i]->m_width; | |
255 } | |
256 | |
257 if (rtl()) | |
258 x -= width(); | |
259 | |
260 // The position in question might be just after the text. | |
261 if (!offsetX && absoluteOffset == numCharacters()) | |
262 return rtl() ? 0 : m_width; | |
263 | |
264 return offsetX; | |
265 } | |
266 | |
224 void ShapeResult::fallbackFonts( | 267 void ShapeResult::fallbackFonts( |
225 HashSet<const SimpleFontData*>* fallback) const { | 268 HashSet<const SimpleFontData*>* fallback) const { |
226 ASSERT(fallback); | 269 ASSERT(fallback); |
227 ASSERT(m_primaryFont); | 270 ASSERT(m_primaryFont); |
228 for (unsigned i = 0; i < m_runs.size(); ++i) { | 271 for (unsigned i = 0; i < m_runs.size(); ++i) { |
229 if (m_runs[i] && m_runs[i]->m_fontData && | 272 if (m_runs[i] && m_runs[i]->m_fontData && |
230 m_runs[i]->m_fontData != m_primaryFont && | 273 m_runs[i]->m_fontData != m_primaryFont && |
231 !m_runs[i]->m_fontData->isTextOrientationFallbackOf( | 274 !m_runs[i]->m_fontData->isTextOrientationFallbackOf( |
232 m_primaryFont.get())) { | 275 m_primaryFont.get())) { |
233 fallback->insert(m_runs[i]->m_fontData.get()); | 276 fallback->insert(m_runs[i]->m_fontData.get()); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 result->m_width = run->m_width; | 444 result->m_width = run->m_width; |
402 result->m_numGlyphs = count; | 445 result->m_numGlyphs = count; |
403 DCHECK_EQ(result->m_numGlyphs, count); // no overflow | 446 DCHECK_EQ(result->m_numGlyphs, count); // no overflow |
404 result->m_hasVerticalOffsets = | 447 result->m_hasVerticalOffsets = |
405 fontData->platformData().isVerticalAnyUpright(); | 448 fontData->platformData().isVerticalAnyUpright(); |
406 result->m_runs.push_back(std::move(run)); | 449 result->m_runs.push_back(std::move(run)); |
407 return result.release(); | 450 return result.release(); |
408 } | 451 } |
409 | 452 |
410 } // namespace blink | 453 } // namespace blink |
OLD | NEW |