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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/SimpleFontData.cpp

Issue 1397423004: Improve shaping segmentation for grapheme cluster based font fallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge TestExpectations with the HarfBuzz rebaselines Created 5 years, 1 month 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) 2005, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2006 Alexey Proskuryakov 3 * Copyright (C) 2006 Alexey Proskuryakov
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 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. 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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 445
446 m_platformData.setupPaint(&paint); 446 m_platformData.setupPaint(&paint);
447 447
448 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 448 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
449 SkScalar width = paint.measureText(&glyph, 2); 449 SkScalar width = paint.measureText(&glyph, 2);
450 if (!paint.isSubpixelText()) 450 if (!paint.isSubpixelText())
451 width = SkScalarRoundToInt(width); 451 width = SkScalarRoundToInt(width);
452 return SkScalarToFloat(width); 452 return SkScalarToFloat(width);
453 } 453 }
454 454
455 bool SimpleFontData::canRenderCombiningCharacterSequence(const UChar* characters , size_t length) const
456 {
457 if (!m_combiningCharacterSequenceSupport)
458 m_combiningCharacterSequenceSupport = adoptPtr(new HashMap<String, bool> );
459
460 WTF::HashMap<String, bool>::AddResult addResult = m_combiningCharacterSequen ceSupport->add(String(characters, length), false);
461 if (!addResult.isNewEntry)
462 return addResult.storedValue->value;
463
464 UErrorCode error = U_ZERO_ERROR;
465 Vector<UChar, 4> normalizedCharacters(length);
466 size_t normalizedLength = unorm_normalize(characters, length, UNORM_NFC, UNO RM_UNICODE_3_2, &normalizedCharacters[0], length, &error);
467 // Can't render if we have an error or no composition occurred.
468 if (U_FAILURE(error) || normalizedLength == length)
469 return false;
470
471 for (size_t offset = 0; offset < normalizedLength;) {
472 UChar32 character;
473 U16_NEXT(normalizedCharacters, offset, normalizedLength, character);
474 if (!glyphForCharacter(character))
475 return false;
476 }
477
478 addResult.storedValue->value = true;
479 return true;
480 }
481
482 bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill, unsigned offset, unsig ned length, UChar* buffer, unsigned bufferLength) const 455 bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill, unsigned offset, unsig ned length, UChar* buffer, unsigned bufferLength) const
483 { 456 {
484 if (SkUTF16_IsHighSurrogate(buffer[bufferLength-1])) { 457 if (SkUTF16_IsHighSurrogate(buffer[bufferLength-1])) {
485 SkDebugf("%s last char is high-surrogate", __FUNCTION__); 458 SkDebugf("%s last char is high-surrogate", __FUNCTION__);
486 return false; 459 return false;
487 } 460 }
488 461
489 SkTypeface* typeface = platformData().typeface(); 462 SkTypeface* typeface = platformData().typeface();
490 if (!typeface) { 463 if (!typeface) {
491 WTF_LOG_ERROR("fillGlyphPage called on an empty Skia typeface."); 464 WTF_LOG_ERROR("fillGlyphPage called on an empty Skia typeface.");
492 return false; 465 return false;
493 } 466 }
494 467
495 SkAutoSTMalloc<GlyphPage::size, uint16_t> glyphStorage(length); 468 SkAutoSTMalloc<GlyphPage::size, uint16_t> glyphStorage(length);
496 uint16_t* glyphs = glyphStorage.get(); 469 uint16_t* glyphs = glyphStorage.get();
497 typeface->charsToGlyphs(buffer, SkTypeface::kUTF16_Encoding, glyphs, length) ; 470 typeface->charsToGlyphs(buffer, SkTypeface::kUTF16_Encoding, glyphs, length) ;
498 471
499 bool haveGlyphs = false; 472 bool haveGlyphs = false;
500 for (unsigned i = 0; i < length; i++) { 473 for (unsigned i = 0; i < length; i++) {
501 if (glyphs[i]) { 474 if (glyphs[i]) {
502 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this); 475 pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this);
503 haveGlyphs = true; 476 haveGlyphs = true;
504 } 477 }
505 } 478 }
506 479
507 return haveGlyphs; 480 return haveGlyphs;
508 } 481 }
509 482
510 } // namespace blink 483 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698