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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } else if ((direction == RTL && currentCharacterIndex >= from) | 205 } else if ((direction == RTL && currentCharacterIndex >= from) |
206 || (direction == LTR && currentCharacterIndex < to)) { | 206 || (direction == LTR && currentCharacterIndex < to)) { |
207 addGlyphToBuffer(glyphBuffer, advanceSoFar, run->m_direction, | 207 addGlyphToBuffer(glyphBuffer, advanceSoFar, run->m_direction, |
208 run->m_fontData.get(), glyphData); | 208 run->m_fontData.get(), glyphData); |
209 advanceSoFar += glyphData.advance; | 209 advanceSoFar += glyphData.advance; |
210 } | 210 } |
211 } | 211 } |
212 return advanceSoFar - initialAdvance; | 212 return advanceSoFar - initialAdvance; |
213 } | 213 } |
214 | 214 |
| 215 static inline unsigned countGraphemesInCluster(const UChar* str, |
| 216 unsigned strLength, uint16_t startIndex, uint16_t endIndex) |
| 217 { |
| 218 if (startIndex > endIndex) { |
| 219 uint16_t tempIndex = startIndex; |
| 220 startIndex = endIndex; |
| 221 endIndex = tempIndex; |
| 222 } |
| 223 uint16_t length = endIndex - startIndex; |
| 224 ASSERT(static_cast<unsigned>(startIndex + length) <= strLength); |
| 225 TextBreakIterator* cursorPosIterator = cursorMovementIterator(&str[startInde
x], length); |
| 226 |
| 227 int cursorPos = cursorPosIterator->current(); |
| 228 int numGraphemes = -1; |
| 229 while (0 <= cursorPos) { |
| 230 cursorPos = cursorPosIterator->next(); |
| 231 numGraphemes++; |
| 232 } |
| 233 return numGraphemes < 0 ? 0 : numGraphemes; |
| 234 } |
| 235 |
215 static inline void addEmphasisMark(GlyphBuffer* buffer, | 236 static inline void addEmphasisMark(GlyphBuffer* buffer, |
216 const GlyphData* emphasisData, FloatPoint glyphCenter, | 237 const GlyphData* emphasisData, FloatPoint glyphCenter, |
217 float midGlyphOffset) | 238 float midGlyphOffset) |
218 { | 239 { |
219 ASSERT(buffer); | 240 ASSERT(buffer); |
220 ASSERT(emphasisData); | 241 ASSERT(emphasisData); |
221 | 242 |
222 const SimpleFontData* emphasisFontData = emphasisData->fontData; | 243 const SimpleFontData* emphasisFontData = emphasisData->fontData; |
223 ASSERT(emphasisFontData); | 244 ASSERT(emphasisFontData); |
224 | 245 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 addEmphasisMark(glyphBuffer, emphasisData, glyphCenter, advanceS
oFar + glyphAdvanceX / 2); | 303 addEmphasisMark(glyphBuffer, emphasisData, glyphCenter, advanceS
oFar + glyphAdvanceX / 2); |
283 } | 304 } |
284 advanceSoFar += glyphAdvanceX; | 305 advanceSoFar += glyphAdvanceX; |
285 } else if (isClusterEnd) { | 306 } else if (isClusterEnd) { |
286 uint16_t clusterEnd; | 307 uint16_t clusterEnd; |
287 if (direction == RTL) | 308 if (direction == RTL) |
288 clusterEnd = currentCharacterIndex; | 309 clusterEnd = currentCharacterIndex; |
289 else | 310 else |
290 clusterEnd = isRunEnd ? run->m_startIndex + run->m_numCharacters
+ runOffset : run->glyphToCharacterIndex(i + 1) + runOffset; | 311 clusterEnd = isRunEnd ? run->m_startIndex + run->m_numCharacters
+ runOffset : run->glyphToCharacterIndex(i + 1) + runOffset; |
291 | 312 |
292 graphemesInCluster = countCharactersAndGraphemesInCluster(textRun.ch
aracters16(), textRun.charactersLength(), clusterStart, clusterEnd).graphemes; | 313 graphemesInCluster = countGraphemesInCluster(textRun.characters16(),
textRun.charactersLength(), clusterStart, clusterEnd); |
293 if (!graphemesInCluster || !clusterAdvance) | 314 if (!graphemesInCluster || !clusterAdvance) |
294 continue; | 315 continue; |
295 | 316 |
296 float glyphAdvanceX = clusterAdvance / graphemesInCluster; | 317 float glyphAdvanceX = clusterAdvance / graphemesInCluster; |
297 for (unsigned j = 0; j < graphemesInCluster; ++j) { | 318 for (unsigned j = 0; j < graphemesInCluster; ++j) { |
298 // Do not put emphasis marks on space, separator, and control ch
aracters. | 319 // Do not put emphasis marks on space, separator, and control ch
aracters. |
299 if (Character::canReceiveTextEmphasis(textRun[currentCharacterIn
dex])) | 320 if (Character::canReceiveTextEmphasis(textRun[currentCharacterIn
dex])) |
300 addEmphasisMark(glyphBuffer, emphasisData, glyphCenter, adva
nceSoFar + glyphAdvanceX / 2); | 321 addEmphasisMark(glyphBuffer, emphasisData, glyphCenter, adva
nceSoFar + glyphAdvanceX / 2); |
301 advanceSoFar += glyphAdvanceX; | 322 advanceSoFar += glyphAdvanceX; |
302 } | 323 } |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 return spacing; | 1154 return spacing; |
1134 } | 1155 } |
1135 | 1156 |
1136 // Don't need to check m_textRun.allowsTrailingExpansion() since it's covere
d by !m_expansionOpportunityCount above | 1157 // Don't need to check m_textRun.allowsTrailingExpansion() since it's covere
d by !m_expansionOpportunityCount above |
1137 spacing += nextExpansionPerOpportunity(); | 1158 spacing += nextExpansionPerOpportunity(); |
1138 m_isAfterExpansion = true; | 1159 m_isAfterExpansion = true; |
1139 return spacing; | 1160 return spacing; |
1140 } | 1161 } |
1141 | 1162 |
1142 } // namespace blink | 1163 } // namespace blink |
OLD | NEW |