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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 return charactersSoFar + index; | 474 return charactersSoFar + index; |
475 } | 475 } |
476 charactersSoFar += m_runs[i]->m_numCharacters; | 476 charactersSoFar += m_runs[i]->m_numCharacters; |
477 currentX = nextX; | 477 currentX = nextX; |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
481 return charactersSoFar; | 481 return charactersSoFar; |
482 } | 482 } |
483 | 483 |
484 void ShapeResult::fallbackFonts(HashSet<const SimpleFontData*>* fallback) const | |
485 { | |
486 ASSERT(fallback); | |
487 for (unsigned i = 0; i < m_runs.size(); ++i) { | |
488 if (m_runs[i] && m_runs[i]->m_fontData != m_primaryFont) | |
489 fallback->add(m_runs[i]->m_fontData); | |
490 } | |
491 } | |
492 | |
493 unsigned ShapeResult::numberOfRunsForTesting() const | 484 unsigned ShapeResult::numberOfRunsForTesting() const |
494 { | 485 { |
495 return m_runs.size(); | 486 return m_runs.size(); |
496 } | 487 } |
497 | 488 |
498 bool ShapeResult::runInfoForTesting(unsigned runIndex, unsigned& startIndex, | 489 bool ShapeResult::runInfoForTesting(unsigned runIndex, unsigned& startIndex, |
499 unsigned& numGlyphs, hb_script_t& script) | 490 unsigned& numGlyphs, hb_script_t& script) |
500 { | 491 { |
501 if (runIndex < m_runs.size() && m_runs[runIndex]) { | 492 if (runIndex < m_runs.size() && m_runs[runIndex]) { |
502 startIndex = m_runs[runIndex]->m_startIndex; | 493 startIndex = m_runs[runIndex]->m_startIndex; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 else if (Character::treatAsSpace(character) && character != tabulationCh
aracter) | 560 else if (Character::treatAsSpace(character) && character != tabulationCh
aracter) |
570 character = spaceCharacter; | 561 character = spaceCharacter; |
571 else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) | 562 else if (Character::treatAsZeroWidthSpaceInComplexScript(character)) |
572 character = zeroWidthSpaceCharacter; | 563 character = zeroWidthSpaceCharacter; |
573 | 564 |
574 U16_APPEND(destination, *destinationLength, length, character, error); | 565 U16_APPEND(destination, *destinationLength, length, character, error); |
575 ASSERT_UNUSED(error, !error); | 566 ASSERT_UNUSED(error, !error); |
576 } | 567 } |
577 } | 568 } |
578 | 569 |
579 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) | 570 HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, |
580 : Shaper(font, run) | 571 HashSet<const SimpleFontData*>* fallbackFonts) |
| 572 : Shaper(font, run, nullptr, fallbackFonts) |
581 , m_normalizedBufferLength(0) | 573 , m_normalizedBufferLength(0) |
582 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing()) | 574 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing()) |
583 , m_letterSpacing(font->fontDescription().letterSpacing()) | 575 , m_letterSpacing(font->fontDescription().letterSpacing()) |
584 , m_expansionOpportunityCount(0) | 576 , m_expansionOpportunityCount(0) |
585 { | 577 { |
| 578 // TODO(eae): Once SimpleShaper is gone the ownership of this should shift |
| 579 // to HarfBuzzShaper. |
| 580 ASSERT(fallbackFonts); |
586 m_normalizedBuffer = adoptArrayPtr(new UChar[m_textRun.length() + 1]); | 581 m_normalizedBuffer = adoptArrayPtr(new UChar[m_textRun.length() + 1]); |
587 normalizeCharacters(m_textRun, m_textRun.length(), m_normalizedBuffer.get(),
&m_normalizedBufferLength); | 582 normalizeCharacters(m_textRun, m_textRun.length(), m_normalizedBuffer.get(),
&m_normalizedBufferLength); |
588 setExpansion(m_textRun.expansion()); | 583 setExpansion(m_textRun.expansion()); |
589 setFontFeatures(); | 584 setFontFeatures(); |
590 } | 585 } |
591 | 586 |
592 float HarfBuzzShaper::nextExpansionPerOpportunity() | 587 float HarfBuzzShaper::nextExpansionPerOpportunity() |
593 { | 588 { |
594 if (!m_expansionOpportunityCount) { | 589 if (!m_expansionOpportunityCount) { |
595 ASSERT_NOT_REACHED(); // failures indicate that the logic in HarfBuzzSha
per does not match to the one in expansionOpportunityCount() | 590 ASSERT_NOT_REACHED(); // failures indicate that the logic in HarfBuzzSha
per does not match to the one in expansionOpportunityCount() |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 hb_direction_t harfBuzzDirection = isVerticalAnyUpright(orientation) && !fon
tData->isTextOrientationFallback() ? HB_DIRECTION_TTB : HB_DIRECTION_LTR; | 932 hb_direction_t harfBuzzDirection = isVerticalAnyUpright(orientation) && !fon
tData->isTextOrientationFallback() ? HB_DIRECTION_TTB : HB_DIRECTION_LTR; |
938 return dir == RTL ? HB_DIRECTION_REVERSE(harfBuzzDirection) : harfBuzzDirect
ion; | 933 return dir == RTL ? HB_DIRECTION_REVERSE(harfBuzzDirection) : harfBuzzDirect
ion; |
939 } | 934 } |
940 | 935 |
941 void HarfBuzzShaper::addHarfBuzzRun(unsigned startCharacter, | 936 void HarfBuzzShaper::addHarfBuzzRun(unsigned startCharacter, |
942 unsigned endCharacter, const SimpleFontData* fontData, | 937 unsigned endCharacter, const SimpleFontData* fontData, |
943 UScriptCode script) | 938 UScriptCode script) |
944 { | 939 { |
945 ASSERT(endCharacter > startCharacter); | 940 ASSERT(endCharacter > startCharacter); |
946 ASSERT(script != USCRIPT_INVALID_CODE); | 941 ASSERT(script != USCRIPT_INVALID_CODE); |
| 942 if (m_fallbackFonts) |
| 943 trackNonPrimaryFallbackFont(fontData); |
947 | 944 |
948 hb_direction_t direction = TextDirectionToHBDirection(m_textRun.direction(), | 945 hb_direction_t direction = TextDirectionToHBDirection(m_textRun.direction(), |
949 m_font->fontDescription().orientation(), fontData); | 946 m_font->fontDescription().orientation(), fontData); |
950 HarfBuzzRun harfBuzzRun = { | 947 HarfBuzzRun harfBuzzRun = { |
951 fontData, startCharacter, endCharacter - startCharacter, | 948 fontData, startCharacter, endCharacter - startCharacter, |
952 direction, ICUScriptToHBScript(script) | 949 direction, ICUScriptToHBScript(script) |
953 }; | 950 }; |
954 m_harfBuzzRuns.append(harfBuzzRun); | 951 m_harfBuzzRuns.append(harfBuzzRun); |
955 } | 952 } |
956 | 953 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 totalAdvance += advance; | 1095 totalAdvance += advance; |
1099 | 1096 |
1100 FloatRect glyphBounds = currentFontData->boundsForGlyph(glyph); | 1097 FloatRect glyphBounds = currentFontData->boundsForGlyph(glyph); |
1101 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); | 1098 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); |
1102 result->m_glyphBoundingBox.unite(glyphBounds); | 1099 result->m_glyphBoundingBox.unite(glyphBounds); |
1103 glyphOrigin += FloatSize(advance + offsetX, offsetY); | 1100 glyphOrigin += FloatSize(advance + offsetX, offsetY); |
1104 } | 1101 } |
1105 | 1102 |
1106 run->m_width = totalAdvance > 0.0 ? totalAdvance : 0.0; | 1103 run->m_width = totalAdvance > 0.0 ? totalAdvance : 0.0; |
1107 result->m_width += run->m_width; | 1104 result->m_width += run->m_width; |
| 1105 result->m_fallbackFonts = *m_fallbackFonts; |
1108 } | 1106 } |
1109 | 1107 |
1110 float HarfBuzzShaper::adjustSpacing(ShapeResult::RunInfo* run, size_t glyphIndex
, unsigned currentCharacterIndex, float& offset, float& totalAdvance) | 1108 float HarfBuzzShaper::adjustSpacing(ShapeResult::RunInfo* run, size_t glyphIndex
, unsigned currentCharacterIndex, float& offset, float& totalAdvance) |
1111 { | 1109 { |
1112 float spacing = 0; | 1110 float spacing = 0; |
1113 UChar32 character = m_normalizedBuffer[currentCharacterIndex]; | 1111 UChar32 character = m_normalizedBuffer[currentCharacterIndex]; |
1114 if (m_letterSpacing && !Character::treatAsZeroWidthSpace(character)) | 1112 if (m_letterSpacing && !Character::treatAsZeroWidthSpace(character)) |
1115 spacing += m_letterSpacing; | 1113 spacing += m_letterSpacing; |
1116 | 1114 |
1117 bool treatAsSpace = Character::treatAsSpace(character); | 1115 bool treatAsSpace = Character::treatAsSpace(character); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 return spacing; | 1155 return spacing; |
1158 } | 1156 } |
1159 | 1157 |
1160 // Don't need to check m_textRun.allowsTrailingExpansion() since it's covere
d by !m_expansionOpportunityCount above | 1158 // Don't need to check m_textRun.allowsTrailingExpansion() since it's covere
d by !m_expansionOpportunityCount above |
1161 spacing += nextExpansionPerOpportunity(); | 1159 spacing += nextExpansionPerOpportunity(); |
1162 m_isAfterExpansion = true; | 1160 m_isAfterExpansion = true; |
1163 return spacing; | 1161 return spacing; |
1164 } | 1162 } |
1165 | 1163 |
1166 } // namespace blink | 1164 } // namespace blink |
OLD | NEW |