Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: Source/platform/fonts/shaping/HarfBuzzShaper.cpp

Issue 870523003: Check for Unicode in Font before ICU call (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Test patch - Convert to NFC for if diacritical marks are present Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 bool error = false; 352 bool error = false;
353 const UChar* source; 353 const UChar* source;
354 String stringFor8BitRun; 354 String stringFor8BitRun;
355 if (run.is8Bit()) { 355 if (run.is8Bit()) {
356 stringFor8BitRun = String::make16BitFrom8BitSource(run.characters8(), ru n.length()); 356 stringFor8BitRun = String::make16BitFrom8BitSource(run.characters8(), ru n.length());
357 source = stringFor8BitRun.characters16(); 357 source = stringFor8BitRun.characters16();
358 } else { 358 } else {
359 source = run.characters16(); 359 source = run.characters16();
360 } 360 }
361 361
362 // Convert to NFC form if the text has diacritical marks.
363 icu::UnicodeString normalizedString;
364 UErrorCode errorICU = U_ZERO_ERROR;
365
366 for (unsigned i = 0; i < (unsigned)run.length(); ++i) {
eae 2015/02/10 15:40:12 Here and elsewhere, use static_cast instead of C-s
h.joshi 2015/02/17 03:44:47 Done.
367 UChar ch = source[i];
eae 2015/02/10 15:40:12 Only used once, no need for local variable.
h.joshi 2015/02/17 03:44:47 Done.
368 if (::ublock_getCode(ch) == UBLOCK_COMBINING_DIACRITICAL_MARKS) {
369 icu::Normalizer::normalize(icu::UnicodeString(source,
370 run.length()), UNORM_NFC, 0 /* no options */,
371 normalizedString, errorICU);
372 if (U_FAILURE(errorICU))
373 normalizedString.remove();
374 break;
375 }
376 }
377
378 if (normalizedString.isEmpty()) {
379 length = (unsigned)run.length();
380 } else {
381 length = (unsigned)normalizedString.length();
382 source = normalizedString.getBuffer();
383 }
384
362 *destinationLength = 0; 385 *destinationLength = 0;
363 while (position < length) { 386 while (position < length) {
364 UChar32 character; 387 UChar32 character;
365 U16_NEXT(source, position, length, character); 388 U16_NEXT(source, position, length, character);
366 // Don't normalize tabs as they are not treated as spaces for word-end. 389 // Don't normalize tabs as they are not treated as spaces for word-end.
367 if (run.normalizeSpace() && Character::isNormalizedCanvasSpaceCharacter( character)) 390 if (run.normalizeSpace() && Character::isNormalizedCanvasSpaceCharacter( character))
368 character = space; 391 character = space;
369 else if (Character::treatAsSpace(character) && character != characterTab ulation) 392 else if (Character::treatAsSpace(character) && character != characterTab ulation)
370 character = space; 393 character = space;
371 else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) 394 else if (Character::treatAsZeroWidthSpaceInComplexScript(character))
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 } 580 }
558 581
559 static inline int handleMultipleUChar( 582 static inline int handleMultipleUChar(
560 UChar32 character, 583 UChar32 character,
561 unsigned clusterLength, 584 unsigned clusterLength,
562 const SimpleFontData* currentFontData, 585 const SimpleFontData* currentFontData,
563 const UChar* currentCharacterPosition, 586 const UChar* currentCharacterPosition,
564 const UChar* markCharactersEnd, 587 const UChar* markCharactersEnd,
565 const UChar* normalizedBufferEnd) 588 const UChar* normalizedBufferEnd)
566 { 589 {
590 ASSERT(currentFontData);
567 if (U_GET_GC_MASK(character) & U_GC_M_MASK) { 591 if (U_GET_GC_MASK(character) & U_GC_M_MASK) {
592 /* If current font does not have Unicode, we should not go further.
593 Blink will fallback to some other font to display this Unicode.
594 */
595 if (!currentFontData->fontHasGlyphForCharacter(character))
596 return 0;
597
568 int markLength = clusterLength; 598 int markLength = clusterLength;
569 while (markCharactersEnd < normalizedBufferEnd) { 599 while (markCharactersEnd < normalizedBufferEnd) {
570 UChar32 nextCharacter; 600 UChar32 nextCharacter;
571 int nextCharacterLength = 0; 601 int nextCharacterLength = 0;
572 U16_NEXT(markCharactersEnd, nextCharacterLength, normalizedBufferEnd - markCharactersEnd, nextCharacter); 602 U16_NEXT(markCharactersEnd, nextCharacterLength, normalizedBufferEnd - markCharactersEnd, nextCharacter);
603 if (!currentFontData->fontHasGlyphForCharacter(nextCharacter))
604 return 0;
573 if (!(U_GET_GC_MASK(nextCharacter) & U_GC_M_MASK)) 605 if (!(U_GET_GC_MASK(nextCharacter) & U_GC_M_MASK))
574 break; 606 break;
575 markLength += nextCharacterLength; 607 markLength += nextCharacterLength;
576 markCharactersEnd += nextCharacterLength; 608 markCharactersEnd += nextCharacterLength;
577 } 609 }
578 610
579 if (currentFontData->canRenderCombiningCharacterSequence(currentCharacte rPosition, markCharactersEnd - currentCharacterPosition)) { 611 if (currentFontData->canRenderCombiningCharacterSequence(currentCharacte rPosition, markCharactersEnd - currentCharacterPosition)) {
580 return markLength; 612 return markLength;
581 } 613 }
582 } 614 }
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 // possibly invalid from, to arguments. 1232 // possibly invalid from, to arguments.
1201 if (!foundToX && !foundFromX) 1233 if (!foundToX && !foundFromX)
1202 fromX = toX = 0; 1234 fromX = toX = 0;
1203 1235
1204 if (fromX < toX) 1236 if (fromX < toX)
1205 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height); 1237 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height);
1206 return FloatRect(point.x() + toX, point.y(), fromX - toX, height); 1238 return FloatRect(point.x() + toX, point.y(), fromX - toX, height);
1207 } 1239 }
1208 1240
1209 } // namespace blink 1241 } // namespace blink
OLDNEW
« Source/platform/fonts/SimpleFontData.cpp ('K') | « Source/platform/fonts/SimpleFontData.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698