| 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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 m_glyphs.resize(m_numGlyphs); | 271 m_glyphs.resize(m_numGlyphs); |
| 272 m_advances.resize(m_numGlyphs); | 272 m_advances.resize(m_numGlyphs); |
| 273 m_glyphToCharacterIndexes.resize(m_numGlyphs); | 273 m_glyphToCharacterIndexes.resize(m_numGlyphs); |
| 274 m_offsets.resize(m_numGlyphs); | 274 m_offsets.resize(m_numGlyphs); |
| 275 } | 275 } |
| 276 | 276 |
| 277 inline void HarfBuzzShaper::HarfBuzzRun::setGlyphAndPositions(unsigned index, ui
nt16_t glyphId, float advance, float offsetX, float offsetY) | 277 inline void HarfBuzzShaper::HarfBuzzRun::setGlyphAndPositions(unsigned index, ui
nt16_t glyphId, float advance, float offsetX, float offsetY) |
| 278 { | 278 { |
| 279 m_glyphs[index] = glyphId; | 279 m_glyphs[index] = glyphId; |
| 280 m_advances[index] = advance; | 280 m_advances[index] = advance; |
| 281 m_offsets[index] = FloatPoint(offsetX, offsetY); | 281 m_offsets[index] = FloatSize(offsetX, offsetY); |
| 282 } | 282 } |
| 283 | 283 |
| 284 int HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition(float targetX) | 284 int HarfBuzzShaper::HarfBuzzRun::characterIndexForXPosition(float targetX) |
| 285 { | 285 { |
| 286 ASSERT(targetX <= m_width); | 286 ASSERT(targetX <= m_width); |
| 287 float currentX = 0; | 287 float currentX = 0; |
| 288 float currentAdvance = m_advances[0]; | 288 float currentAdvance = m_advances[0]; |
| 289 unsigned glyphIndex = 0; | 289 unsigned glyphIndex = 0; |
| 290 | 290 |
| 291 // Sum up advances that belong to a character. | 291 // Sum up advances that belong to a character. |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 if (!RuntimeEnabledFeatures::subpixelFontScalingEnabled()) | 564 if (!RuntimeEnabledFeatures::subpixelFontScalingEnabled()) |
| 565 m_totalWidth = roundf(m_totalWidth); | 565 m_totalWidth = roundf(m_totalWidth); |
| 566 | 566 |
| 567 if (m_harfBuzzRuns.last()->hasGlyphToCharacterIndexes() | 567 if (m_harfBuzzRuns.last()->hasGlyphToCharacterIndexes() |
| 568 && glyphBuffer && !fillGlyphBuffer(glyphBuffer)) | 568 && glyphBuffer && !fillGlyphBuffer(glyphBuffer)) |
| 569 return false; | 569 return false; |
| 570 | 570 |
| 571 return true; | 571 return true; |
| 572 } | 572 } |
| 573 | 573 |
| 574 FloatPoint HarfBuzzShaper::adjustStartPoint(const FloatPoint& point) | |
| 575 { | |
| 576 return point + m_startOffset; | |
| 577 } | |
| 578 | |
| 579 static inline int handleMultipleUChar( | 574 static inline int handleMultipleUChar( |
| 580 UChar32 character, | 575 UChar32 character, |
| 581 unsigned clusterLength, | 576 unsigned clusterLength, |
| 582 const SimpleFontData* currentFontData, | 577 const SimpleFontData* currentFontData, |
| 583 const UChar* currentCharacterPosition, | 578 const UChar* currentCharacterPosition, |
| 584 const UChar* markCharactersEnd, | 579 const UChar* markCharactersEnd, |
| 585 const UChar* normalizedBufferEnd) | 580 const UChar* normalizedBufferEnd) |
| 586 { | 581 { |
| 587 if (U_GET_GC_MASK(character) & U_GC_M_MASK) { | 582 if (U_GET_GC_MASK(character) & U_GC_M_MASK) { |
| 588 int markLength = clusterLength; | 583 int markLength = clusterLength; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); | 938 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); |
| 944 m_glyphBoundingBox.unite(glyphBounds); | 939 m_glyphBoundingBox.unite(glyphBounds); |
| 945 glyphOrigin += FloatSize(advance + offsetX, offsetY); | 940 glyphOrigin += FloatSize(advance + offsetX, offsetY); |
| 946 | 941 |
| 947 totalAdvance += advance; | 942 totalAdvance += advance; |
| 948 } | 943 } |
| 949 currentRun->setWidth(totalAdvance > 0.0 ? totalAdvance : 0.0); | 944 currentRun->setWidth(totalAdvance > 0.0 ? totalAdvance : 0.0); |
| 950 m_totalWidth += currentRun->width(); | 945 m_totalWidth += currentRun->width(); |
| 951 } | 946 } |
| 952 | 947 |
| 953 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun, FloatPoint& firstOffsetOfNextRun) | 948 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun) |
| 954 { | 949 { |
| 955 FloatPoint* offsets = currentRun->offsets(); | 950 FloatSize* offsets = currentRun->offsets(); |
| 956 uint16_t* glyphs = currentRun->glyphs(); | 951 uint16_t* glyphs = currentRun->glyphs(); |
| 957 float* advances = currentRun->advances(); | 952 float* advances = currentRun->advances(); |
| 958 unsigned numGlyphs = currentRun->numGlyphs(); | 953 unsigned numGlyphs = currentRun->numGlyphs(); |
| 954 glyphBuffer->reserveOffsetsCapacity(numGlyphs); |
| 959 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); | 955 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); |
| 960 for (unsigned i = 0; i < numGlyphs; ++i) { | 956 float advanceSoFar = 0; |
| 961 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToChara
cterIndexes[i]; | 957 if (m_run.rtl()) { |
| 962 FloatPoint& currentOffset = offsets[i]; | 958 for (unsigned i = 0; i < numGlyphs; ++i) { |
| 963 FloatPoint& nextOffset = (i == numGlyphs - 1) ? firstOffsetOfNextRun : o
ffsets[i + 1]; | 959 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToC
haracterIndexes[i]; |
| 964 float glyphAdvanceX = advances[i] + nextOffset.x() - currentOffset.x(); | |
| 965 float glyphAdvanceY = nextOffset.y() - currentOffset.y(); | |
| 966 if (m_run.rtl()) { | |
| 967 if (currentCharacterIndex >= m_toIndex) | 960 if (currentCharacterIndex >= m_toIndex) |
| 968 m_startOffset.move(glyphAdvanceX, glyphAdvanceY); | 961 advanceSoFar += advances[i]; |
| 969 else if (currentCharacterIndex >= m_fromIndex) | 962 else if (currentCharacterIndex >= m_fromIndex) |
| 970 glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(gl
yphAdvanceX, glyphAdvanceY)); | 963 glyphBuffer->add(glyphs[i], currentRun->fontData(), offsets[i] +
FloatSize(advanceSoFar, 0), advances[i]); |
| 971 } else { | 964 } |
| 965 } else { |
| 966 for (unsigned i = 0; i < numGlyphs; ++i) { |
| 967 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToC
haracterIndexes[i]; |
| 972 if (currentCharacterIndex < m_fromIndex) | 968 if (currentCharacterIndex < m_fromIndex) |
| 973 m_startOffset.move(glyphAdvanceX, glyphAdvanceY); | 969 advanceSoFar += advances[i]; |
| 974 else if (currentCharacterIndex < m_toIndex) | 970 else if (currentCharacterIndex < m_toIndex) |
| 975 glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(gl
yphAdvanceX, glyphAdvanceY)); | 971 glyphBuffer->add(glyphs[i], currentRun->fontData(), offsets[i] +
FloatSize(advanceSoFar, 0), advances[i]); |
| 976 } | 972 } |
| 977 } | 973 } |
| 978 } | 974 } |
| 979 | 975 |
| 980 void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun) | 976 void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun) |
| 981 { | 977 { |
| 982 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u
sed by the | 978 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u
sed by the |
| 983 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis
mark drawing function. | 979 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis
mark drawing function. |
| 984 | 980 |
| 985 float* advances = currentRun->advances(); | 981 float* advances = currentRun->advances(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 clusterStart = clusterEnd; | 1024 clusterStart = clusterEnd; |
| 1029 clusterAdvance = 0; | 1025 clusterAdvance = 0; |
| 1030 } | 1026 } |
| 1031 } | 1027 } |
| 1032 } | 1028 } |
| 1033 | 1029 |
| 1034 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) | 1030 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) |
| 1035 { | 1031 { |
| 1036 unsigned numRuns = m_harfBuzzRuns.size(); | 1032 unsigned numRuns = m_harfBuzzRuns.size(); |
| 1037 if (m_run.rtl()) { | 1033 if (m_run.rtl()) { |
| 1038 m_startOffset = m_harfBuzzRuns.last()->offsets()[0]; | |
| 1039 for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) { | 1034 for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) { |
| 1040 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 1035 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
| 1041 if (!currentRun->hasGlyphToCharacterIndexes()) { | 1036 if (!currentRun->hasGlyphToCharacterIndexes()) { |
| 1042 // FIXME: bug 337886, 359664 | 1037 // FIXME: bug 337886, 359664 |
| 1043 continue; | 1038 continue; |
| 1044 } | 1039 } |
| 1045 FloatPoint firstOffsetOfNextRun = !runIndex ? FloatPoint() : m_harfB
uzzRuns[runIndex - 1]->offsets()[0]; | |
| 1046 if (m_forTextEmphasis == ForTextEmphasis) | 1040 if (m_forTextEmphasis == ForTextEmphasis) |
| 1047 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); | 1041 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); |
| 1048 else | 1042 else |
| 1049 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOff
setOfNextRun); | 1043 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun); |
| 1050 } | 1044 } |
| 1051 } else { | 1045 } else { |
| 1052 m_startOffset = m_harfBuzzRuns.first()->offsets()[0]; | |
| 1053 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { | 1046 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { |
| 1054 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 1047 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
| 1055 if (!currentRun->hasGlyphToCharacterIndexes()) { | 1048 if (!currentRun->hasGlyphToCharacterIndexes()) { |
| 1056 // FIXME: bug 337886, 359664 | 1049 // FIXME: bug 337886, 359664 |
| 1057 continue; | 1050 continue; |
| 1058 } | 1051 } |
| 1059 FloatPoint firstOffsetOfNextRun = runIndex == numRuns - 1 ? FloatPoi
nt() : m_harfBuzzRuns[runIndex + 1]->offsets()[0]; | |
| 1060 if (m_forTextEmphasis == ForTextEmphasis) | 1052 if (m_forTextEmphasis == ForTextEmphasis) |
| 1061 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); | 1053 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); |
| 1062 else | 1054 else |
| 1063 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOff
setOfNextRun); | 1055 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun); |
| 1064 } | 1056 } |
| 1065 } | 1057 } |
| 1066 return glyphBuffer->size(); | 1058 return glyphBuffer->size(); |
| 1067 } | 1059 } |
| 1068 | 1060 |
| 1069 int HarfBuzzShaper::offsetForPosition(float targetX) | 1061 int HarfBuzzShaper::offsetForPosition(float targetX) |
| 1070 { | 1062 { |
| 1071 int charactersSoFar = 0; | 1063 int charactersSoFar = 0; |
| 1072 float currentX = 0; | 1064 float currentX = 0; |
| 1073 | 1065 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1143 point.x() + fromX, point.x() + toX, | 1135 point.x() + fromX, point.x() + toX, |
| 1144 point.y(), height); | 1136 point.y(), height); |
| 1145 } | 1137 } |
| 1146 | 1138 |
| 1147 return Font::pixelSnappedSelectionRect( | 1139 return Font::pixelSnappedSelectionRect( |
| 1148 point.x() + toX, point.x() + fromX, | 1140 point.x() + toX, point.x() + fromX, |
| 1149 point.y(), height); | 1141 point.y(), height); |
| 1150 } | 1142 } |
| 1151 | 1143 |
| 1152 } // namespace blink | 1144 } // namespace blink |
| OLD | NEW |