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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 stringFor8BitRun = String::make16BitFrom8BitSource(run.characters8(), ru
n.length()); | 350 stringFor8BitRun = String::make16BitFrom8BitSource(run.characters8(), ru
n.length()); |
351 source = stringFor8BitRun.characters16(); | 351 source = stringFor8BitRun.characters16(); |
352 } else | 352 } else |
353 source = run.characters16(); | 353 source = run.characters16(); |
354 | 354 |
355 *destinationLength = 0; | 355 *destinationLength = 0; |
356 while (position < length) { | 356 while (position < length) { |
357 UChar32 character; | 357 UChar32 character; |
358 U16_NEXT(source, position, length, character); | 358 U16_NEXT(source, position, length, character); |
359 // Don't normalize tabs as they are not treated as spaces for word-end. | 359 // Don't normalize tabs as they are not treated as spaces for word-end. |
360 if (Character::treatAsSpace(character) && character != characterTabulati
on) | 360 if (run.normalizeSpace() && Character::isNormalizedCanvasSpaceCharacter(
character)) |
| 361 character = space; |
| 362 else if (Character::treatAsSpace(character) && character != characterTab
ulation) |
361 character = space; | 363 character = space; |
362 else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) | 364 else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) |
363 character = zeroWidthSpace; | 365 character = zeroWidthSpace; |
| 366 |
364 U16_APPEND(destination, *destinationLength, length, character, error); | 367 U16_APPEND(destination, *destinationLength, length, character, error); |
365 ASSERT_UNUSED(error, !error); | 368 ASSERT_UNUSED(error, !error); |
366 } | 369 } |
367 } | 370 } |
368 | 371 |
369 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, ForTextEmph
asisOrNot forTextEmphasis, HashSet<const SimpleFontData*>* fallbackFonts) | 372 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, ForTextEmph
asisOrNot forTextEmphasis, HashSet<const SimpleFontData*>* fallbackFonts) |
370 : m_font(font) | 373 : m_font(font) |
371 , m_normalizedBufferLength(0) | 374 , m_normalizedBufferLength(0) |
372 , m_run(run) | 375 , m_run(run) |
373 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing()) | 376 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing()) |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 | 608 |
606 struct CandidateRun { | 609 struct CandidateRun { |
607 UChar32 character; | 610 UChar32 character; |
608 unsigned start; | 611 unsigned start; |
609 unsigned end; | 612 unsigned end; |
610 const SimpleFontData* fontData; | 613 const SimpleFontData* fontData; |
611 UScriptCode script; | 614 UScriptCode script; |
612 }; | 615 }; |
613 | 616 |
614 static inline bool collectCandidateRuns(const UChar* normalizedBuffer, | 617 static inline bool collectCandidateRuns(const UChar* normalizedBuffer, |
615 size_t bufferLength, const Font* font, Vector<CandidateRun>* runs) | 618 size_t bufferLength, const Font* font, Vector<CandidateRun>* runs, bool isSp
aceNormalize) |
616 { | 619 { |
617 const UChar* normalizedBufferEnd = normalizedBuffer + bufferLength; | 620 const UChar* normalizedBufferEnd = normalizedBuffer + bufferLength; |
618 SurrogatePairAwareTextIterator iterator(normalizedBuffer, 0, bufferLength, b
ufferLength); | 621 SurrogatePairAwareTextIterator iterator(normalizedBuffer, 0, bufferLength, b
ufferLength); |
619 UChar32 character; | 622 UChar32 character; |
620 unsigned clusterLength = 0; | 623 unsigned clusterLength = 0; |
621 unsigned startIndexOfCurrentRun = 0; | 624 unsigned startIndexOfCurrentRun = 0; |
| 625 |
622 if (!iterator.consume(character, clusterLength)) | 626 if (!iterator.consume(character, clusterLength)) |
623 return false; | 627 return false; |
624 | 628 |
625 const SimpleFontData* nextFontData = font->glyphDataForCharacter(character,
false).fontData; | 629 const SimpleFontData* nextFontData = font->glyphDataForCharacter(character,
false, isSpaceNormalize).fontData; |
626 UErrorCode errorCode = U_ZERO_ERROR; | 630 UErrorCode errorCode = U_ZERO_ERROR; |
627 UScriptCode nextScript = uscript_getScript(character, &errorCode); | 631 UScriptCode nextScript = uscript_getScript(character, &errorCode); |
628 if (U_FAILURE(errorCode)) | 632 if (U_FAILURE(errorCode)) |
629 return false; | 633 return false; |
630 | 634 |
631 do { | 635 do { |
632 const UChar* currentCharacterPosition = iterator.characters(); | 636 const UChar* currentCharacterPosition = iterator.characters(); |
633 const SimpleFontData* currentFontData = nextFontData; | 637 const SimpleFontData* currentFontData = nextFontData; |
634 UScriptCode currentScript = nextScript; | 638 UScriptCode currentScript = nextScript; |
635 | 639 |
636 UChar32 lastCharacter = character; | 640 UChar32 lastCharacter = character; |
637 for (iterator.advance(clusterLength); iterator.consume(character, cluste
rLength); iterator.advance(clusterLength)) { | 641 for (iterator.advance(clusterLength); iterator.consume(character, cluste
rLength); iterator.advance(clusterLength)) { |
638 if (Character::treatAsZeroWidthSpace(character)) | 642 if (Character::treatAsZeroWidthSpace(character)) |
639 continue; | 643 continue; |
640 | 644 |
641 int length = handleMultipleUChar(character, clusterLength, currentFo
ntData, currentCharacterPosition, iterator.characters() + clusterLength, normali
zedBufferEnd); | 645 int length = handleMultipleUChar(character, clusterLength, currentFo
ntData, currentCharacterPosition, iterator.characters() + clusterLength, normali
zedBufferEnd); |
642 if (length) { | 646 if (length) { |
643 clusterLength = length; | 647 clusterLength = length; |
644 continue; | 648 continue; |
645 } | 649 } |
646 | 650 |
647 nextFontData = font->glyphDataForCharacter(character, false).fontDat
a; | 651 nextFontData = font->glyphDataForCharacter(character, false, isSpace
Normalize).fontData; |
648 nextScript = uscript_getScript(character, &errorCode); | 652 nextScript = uscript_getScript(character, &errorCode); |
649 if (U_FAILURE(errorCode)) | 653 if (U_FAILURE(errorCode)) |
650 return false; | 654 return false; |
651 if (lastCharacter == zeroWidthJoiner) | 655 if (lastCharacter == zeroWidthJoiner) |
652 currentFontData = nextFontData; | 656 currentFontData = nextFontData; |
653 if ((nextFontData != currentFontData) || ((currentScript != nextScri
pt) && (nextScript != USCRIPT_INHERITED) && (!uscript_hasScript(character, curre
ntScript)))) | 657 if ((nextFontData != currentFontData) || ((currentScript != nextScri
pt) && (nextScript != USCRIPT_INHERITED) && (!uscript_hasScript(character, curre
ntScript)))) |
654 break; | 658 break; |
655 currentCharacterPosition = iterator.characters(); | 659 currentCharacterPosition = iterator.characters(); |
656 lastCharacter = character; | 660 lastCharacter = character; |
657 } | 661 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 | 750 |
747 i = std::max(i, nextResolvedRun); | 751 i = std::max(i, nextResolvedRun); |
748 } | 752 } |
749 return true; | 753 return true; |
750 } | 754 } |
751 | 755 |
752 bool HarfBuzzShaper::createHarfBuzzRuns() | 756 bool HarfBuzzShaper::createHarfBuzzRuns() |
753 { | 757 { |
754 Vector<CandidateRun> candidateRuns; | 758 Vector<CandidateRun> candidateRuns; |
755 if (!collectCandidateRuns(m_normalizedBuffer.get(), | 759 if (!collectCandidateRuns(m_normalizedBuffer.get(), |
756 m_normalizedBufferLength, m_font, &candidateRuns)) | 760 m_normalizedBufferLength, m_font, &candidateRuns, m_run.normalizeSpace()
)) |
757 return false; | 761 return false; |
758 | 762 |
759 if (!resolveCandidateRuns(candidateRuns)) | 763 if (!resolveCandidateRuns(candidateRuns)) |
760 return false; | 764 return false; |
761 | 765 |
762 size_t length = candidateRuns.size(); | 766 size_t length = candidateRuns.size(); |
763 for (size_t i = 0; i < length; ) { | 767 for (size_t i = 0; i < length; ) { |
764 CandidateRun& run = candidateRuns[i]; | 768 CandidateRun& run = candidateRuns[i]; |
765 CandidateRun lastMatchingRun = run; | 769 CandidateRun lastMatchingRun = run; |
766 for (i++; i < length; i++) { | 770 for (i++; i < length; i++) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 runCache.moveToBack(cachedResults); | 856 runCache.moveToBack(cachedResults); |
853 | 857 |
854 continue; | 858 continue; |
855 } | 859 } |
856 | 860 |
857 runCache.remove(cachedResults); | 861 runCache.remove(cachedResults); |
858 } | 862 } |
859 | 863 |
860 // Add a space as pre-context to the buffer. This prevents showing dotte
d-circle | 864 // Add a space as pre-context to the buffer. This prevents showing dotte
d-circle |
861 // for combining marks at the beginning of runs. | 865 // for combining marks at the beginning of runs. |
862 static const uint16_t preContext = ' '; | 866 static const uint16_t preContext = space; |
863 hb_buffer_add_utf16(harfBuzzBuffer.get(), &preContext, 1, 1, 0); | 867 hb_buffer_add_utf16(harfBuzzBuffer.get(), &preContext, 1, 1, 0); |
864 | 868 |
865 if (fontDescription.variant() == FontVariantSmallCaps && u_islower(m_nor
malizedBuffer[currentRun->startIndex()])) { | 869 if (fontDescription.variant() == FontVariantSmallCaps && u_islower(m_nor
malizedBuffer[currentRun->startIndex()])) { |
866 String upperText = String(m_normalizedBuffer.get() + currentRun->sta
rtIndex(), currentRun->numCharacters()).upper(); | 870 String upperText = String(m_normalizedBuffer.get() + currentRun->sta
rtIndex(), currentRun->numCharacters()).upper(); |
867 ASSERT(!upperText.is8Bit()); // m_normalizedBuffer is 16 bit, theref
ore upperText is 16 bit, even after we call makeUpper(). | 871 ASSERT(!upperText.is8Bit()); // m_normalizedBuffer is 16 bit, theref
ore upperText is 16 bit, even after we call makeUpper(). |
868 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(upperText.charact
ers16()), currentRun->numCharacters(), 0, currentRun->numCharacters()); | 872 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(upperText.charact
ers16()), currentRun->numCharacters(), 0, currentRun->numCharacters()); |
869 } else { | 873 } else { |
870 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(m_normalizedBuffe
r.get() + currentRun->startIndex()), currentRun->numCharacters(), 0, currentRun-
>numCharacters()); | 874 hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(m_normalizedBuffe
r.get() + currentRun->startIndex()), currentRun->numCharacters(), 0, currentRun-
>numCharacters()); |
871 } | 875 } |
872 | 876 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 point.x() + fromX, point.x() + toX, | 1147 point.x() + fromX, point.x() + toX, |
1144 point.y(), height); | 1148 point.y(), height); |
1145 } | 1149 } |
1146 | 1150 |
1147 return Font::pixelSnappedSelectionRect( | 1151 return Font::pixelSnappedSelectionRect( |
1148 point.x() + toX, point.x() + fromX, | 1152 point.x() + toX, point.x() + fromX, |
1149 point.y(), height); | 1153 point.y(), height); |
1150 } | 1154 } |
1151 | 1155 |
1152 } // namespace blink | 1156 } // namespace blink |
OLD | NEW |