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