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