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

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: New Rebase patch Created 5 years, 7 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
« no previous file with comments | « LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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. In most of the fon t, OTF rules
363 // for diacritical marks are missing. Using ICU calls to convert to final fo rm and then pass
364 // updated Unicode string to Harfbuzz.
365 icu::UnicodeString normalizedString;
366 UErrorCode errorICU = U_ZERO_ERROR;
367 bool isDiacriticalMarkPresent = false;
368
362 *destinationLength = 0; 369 *destinationLength = 0;
363 while (position < length) { 370 while (position < length) {
364 UChar32 character; 371 UChar32 character;
365 U16_NEXT(source, position, length, character); 372 U16_NEXT(source, position, length, character);
366 // Don't normalize tabs as they are not treated as spaces for word-end. 373 // Don't normalize tabs as they are not treated as spaces for word-end.
367 if (run.normalizeSpace() && Character::isNormalizedCanvasSpaceCharacter( character)) 374 if (run.normalizeSpace() && Character::isNormalizedCanvasSpaceCharacter( character)) {
368 character = spaceCharacter; 375 character = spaceCharacter;
369 else if (Character::treatAsSpace(character) && character != tabulationCh aracter) 376 } else if (Character::treatAsSpace(character) && character != tabulation Character) {
370 character = spaceCharacter; 377 character = spaceCharacter;
371 else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) 378 } else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) {
372 character = zeroWidthSpaceCharacter; 379 character = zeroWidthSpaceCharacter;
380 } else if (!isDiacriticalMarkPresent && ::ublock_getCode(character) == U BLOCK_COMBINING_DIACRITICAL_MARKS) {
381 isDiacriticalMarkPresent = true;
382 icu::Normalizer::normalize(icu::UnicodeString(source, length), UNORM _NFC, 0 , normalizedString, errorICU);
383 if (U_FAILURE(errorICU)) {
384 normalizedString.remove();
385 } else if (!normalizedString.isEmpty()) {
386 *destinationLength = 0;
387 position = 0;
388 length = static_cast<int>(normalizedString.length());
389 source = normalizedString.getBuffer();
390 continue;
391 }
392 }
373 393
374 U16_APPEND(destination, *destinationLength, length, character, error); 394 U16_APPEND(destination, *destinationLength, length, character, error);
375 ASSERT_UNUSED(error, !error); 395 ASSERT_UNUSED(error, !error);
376 } 396 }
377 } 397 }
378 398
379 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, const Glyph Data* emphasisData, 399 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, const Glyph Data* emphasisData,
380 HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* bounds) 400 HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* bounds)
381 : Shaper(font, run, emphasisData, fallbackFonts, bounds) 401 : Shaper(font, run, emphasisData, fallbackFonts, bounds)
382 , m_normalizedBufferLength(0) 402 , m_normalizedBufferLength(0)
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 // possibly invalid from, to arguments. 1227 // possibly invalid from, to arguments.
1208 if (!foundToX && !foundFromX) 1228 if (!foundToX && !foundFromX)
1209 fromX = toX = 0; 1229 fromX = toX = 0;
1210 1230
1211 if (fromX < toX) 1231 if (fromX < toX)
1212 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height); 1232 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height);
1213 return FloatRect(point.x() + toX, point.y(), fromX - toX, height); 1233 return FloatRect(point.x() + toX, point.y(), fromX - toX, height);
1214 } 1234 }
1215 1235
1216 } // namespace blink 1236 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698