| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/fonts/Character.h" | 32 #include "platform/fonts/Character.h" |
| 33 | 33 |
| 34 #include "platform/fonts/FontPlatformFeatures.h" | |
| 35 #include "wtf/StdLibExtras.h" | 34 #include "wtf/StdLibExtras.h" |
| 36 #include "wtf/text/StringBuilder.h" | 35 #include "wtf/text/StringBuilder.h" |
| 37 | 36 |
| 38 using namespace WTF; | 37 using namespace WTF; |
| 39 using namespace Unicode; | 38 using namespace Unicode; |
| 40 | 39 |
| 41 namespace blink { | 40 namespace blink { |
| 42 | 41 |
| 43 static const UChar32 cjkIsolatedSymbolsArray[] = { | 42 static const UChar32 cjkIsolatedSymbolsArray[] = { |
| 44 // 0x2C7 Caron, Mandarin Chinese 3rd Tone | 43 // 0x2C7 Caron, Mandarin Chinese 3rd Tone |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } else { | 280 } else { |
| 282 isAfterExpansion = false; | 281 isAfterExpansion = false; |
| 283 } | 282 } |
| 284 } | 283 } |
| 285 } | 284 } |
| 286 return count; | 285 return count; |
| 287 } | 286 } |
| 288 | 287 |
| 289 unsigned Character::expansionOpportunityCount(const UChar* characters, size_t le
ngth, TextDirection direction, bool& isAfterExpansion) | 288 unsigned Character::expansionOpportunityCount(const UChar* characters, size_t le
ngth, TextDirection direction, bool& isAfterExpansion) |
| 290 { | 289 { |
| 291 static bool expandAroundIdeographs = FontPlatformFeatures::canExpandAroundId
eographsInComplexText(); | |
| 292 unsigned count = 0; | 290 unsigned count = 0; |
| 293 if (direction == LTR) { | 291 if (direction == LTR) { |
| 294 for (size_t i = 0; i < length; ++i) { | 292 for (size_t i = 0; i < length; ++i) { |
| 295 UChar32 character = characters[i]; | 293 UChar32 character = characters[i]; |
| 296 if (treatAsSpace(character)) { | 294 if (treatAsSpace(character)) { |
| 297 count++; | 295 count++; |
| 298 isAfterExpansion = true; | 296 isAfterExpansion = true; |
| 299 continue; | 297 continue; |
| 300 } | 298 } |
| 301 if (U16_IS_LEAD(character) && i + 1 < length && U16_IS_TRAIL(charact
ers[i + 1])) { | 299 if (U16_IS_LEAD(character) && i + 1 < length && U16_IS_TRAIL(charact
ers[i + 1])) { |
| 302 character = U16_GET_SUPPLEMENTARY(character, characters[i + 1]); | 300 character = U16_GET_SUPPLEMENTARY(character, characters[i + 1]); |
| 303 i++; | 301 i++; |
| 304 } | 302 } |
| 305 if (expandAroundIdeographs && isCJKIdeographOrSymbol(character)) { | |
| 306 if (!isAfterExpansion) | |
| 307 count++; | |
| 308 count++; | |
| 309 isAfterExpansion = true; | |
| 310 continue; | |
| 311 } | |
| 312 isAfterExpansion = false; | 303 isAfterExpansion = false; |
| 313 } | 304 } |
| 314 } else { | 305 } else { |
| 315 for (size_t i = length; i > 0; --i) { | 306 for (size_t i = length; i > 0; --i) { |
| 316 UChar32 character = characters[i - 1]; | 307 UChar32 character = characters[i - 1]; |
| 317 if (treatAsSpace(character)) { | 308 if (treatAsSpace(character)) { |
| 318 count++; | 309 count++; |
| 319 isAfterExpansion = true; | 310 isAfterExpansion = true; |
| 320 continue; | 311 continue; |
| 321 } | 312 } |
| 322 if (U16_IS_TRAIL(character) && i > 1 && U16_IS_LEAD(characters[i - 2
])) { | 313 if (U16_IS_TRAIL(character) && i > 1 && U16_IS_LEAD(characters[i - 2
])) { |
| 323 character = U16_GET_SUPPLEMENTARY(characters[i - 2], character); | 314 character = U16_GET_SUPPLEMENTARY(characters[i - 2], character); |
| 324 i--; | 315 i--; |
| 325 } | 316 } |
| 326 if (expandAroundIdeographs && isCJKIdeographOrSymbol(character)) { | |
| 327 if (!isAfterExpansion) | |
| 328 count++; | |
| 329 count++; | |
| 330 isAfterExpansion = true; | |
| 331 continue; | |
| 332 } | |
| 333 isAfterExpansion = false; | 317 isAfterExpansion = false; |
| 334 } | 318 } |
| 335 } | 319 } |
| 336 return count; | 320 return count; |
| 337 } | 321 } |
| 338 | 322 |
| 339 bool Character::canReceiveTextEmphasis(UChar32 c) | 323 bool Character::canReceiveTextEmphasis(UChar32 c) |
| 340 { | 324 { |
| 341 CharCategory category = Unicode::category(c); | 325 CharCategory category = Unicode::category(c); |
| 342 if (category & (Separator_Space | Separator_Line | Separator_Paragraph | Oth
er_NotAssigned | Other_Control | Other_Format)) | 326 if (category & (Separator_Space | Separator_Line | Separator_Paragraph | Oth
er_NotAssigned | Other_Control | Other_Format)) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 366 { | 350 { |
| 367 return normalizeSpacesInternal(characters, length); | 351 return normalizeSpacesInternal(characters, length); |
| 368 } | 352 } |
| 369 | 353 |
| 370 String Character::normalizeSpaces(const UChar* characters, unsigned length) | 354 String Character::normalizeSpaces(const UChar* characters, unsigned length) |
| 371 { | 355 { |
| 372 return normalizeSpacesInternal(characters, length); | 356 return normalizeSpacesInternal(characters, length); |
| 373 } | 357 } |
| 374 | 358 |
| 375 } // namespace blink | 359 } // namespace blink |
| OLD | NEW |