| 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 if (!RuntimeEnabledFeatures::subpixelFontScalingEnabled()) | 567 if (!RuntimeEnabledFeatures::subpixelFontScalingEnabled()) |
| 568 m_totalWidth = roundf(m_totalWidth); | 568 m_totalWidth = roundf(m_totalWidth); |
| 569 | 569 |
| 570 if (m_harfBuzzRuns.last()->hasGlyphToCharacterIndexes() | 570 if (m_harfBuzzRuns.last()->hasGlyphToCharacterIndexes() |
| 571 && glyphBuffer && !fillGlyphBuffer(glyphBuffer)) | 571 && glyphBuffer && !fillGlyphBuffer(glyphBuffer)) |
| 572 return false; | 572 return false; |
| 573 | 573 |
| 574 return true; | 574 return true; |
| 575 } | 575 } |
| 576 | 576 |
| 577 FloatPoint HarfBuzzShaper::adjustStartPoint(const FloatPoint& point) | |
| 578 { | |
| 579 return point + m_startOffset; | |
| 580 } | |
| 581 | |
| 582 static inline int handleMultipleUChar( | 577 static inline int handleMultipleUChar( |
| 583 UChar32 character, | 578 UChar32 character, |
| 584 unsigned clusterLength, | 579 unsigned clusterLength, |
| 585 const SimpleFontData* currentFontData, | 580 const SimpleFontData* currentFontData, |
| 586 const UChar* currentCharacterPosition, | 581 const UChar* currentCharacterPosition, |
| 587 const UChar* markCharactersEnd, | 582 const UChar* markCharactersEnd, |
| 588 const UChar* normalizedBufferEnd) | 583 const UChar* normalizedBufferEnd) |
| 589 { | 584 { |
| 590 if (U_GET_GC_MASK(character) & U_GC_M_MASK) { | 585 if (U_GET_GC_MASK(character) & U_GC_M_MASK) { |
| 591 int markLength = clusterLength; | 586 int markLength = clusterLength; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); | 941 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); |
| 947 m_glyphBoundingBox.unite(glyphBounds); | 942 m_glyphBoundingBox.unite(glyphBounds); |
| 948 glyphOrigin += FloatSize(advance + offsetX, offsetY); | 943 glyphOrigin += FloatSize(advance + offsetX, offsetY); |
| 949 | 944 |
| 950 totalAdvance += advance; | 945 totalAdvance += advance; |
| 951 } | 946 } |
| 952 currentRun->setWidth(totalAdvance > 0.0 ? totalAdvance : 0.0); | 947 currentRun->setWidth(totalAdvance > 0.0 ? totalAdvance : 0.0); |
| 953 m_totalWidth += currentRun->width(); | 948 m_totalWidth += currentRun->width(); |
| 954 } | 949 } |
| 955 | 950 |
| 956 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun, FloatPoint& firstOffsetOfNextRun) | 951 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBufferWithOffsets* glyp
hBuffer, HarfBuzzRun* currentRun) |
| 957 { | 952 { |
| 958 FloatPoint* offsets = currentRun->offsets(); | 953 FloatSize* offsets = currentRun->offsets(); |
| 959 uint16_t* glyphs = currentRun->glyphs(); | 954 uint16_t* glyphs = currentRun->glyphs(); |
| 960 float* advances = currentRun->advances(); | 955 float* advances = currentRun->advances(); |
| 961 unsigned numGlyphs = currentRun->numGlyphs(); | 956 unsigned numGlyphs = currentRun->numGlyphs(); |
| 962 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); | 957 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); |
| 963 for (unsigned i = 0; i < numGlyphs; ++i) { | 958 float advanceSoFar = 0; |
| 964 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToChara
cterIndexes[i]; | 959 if (m_run.rtl()) { |
| 965 FloatPoint& currentOffset = offsets[i]; | 960 for (unsigned i = 0; i < numGlyphs; ++i) { |
| 966 FloatPoint& nextOffset = (i == numGlyphs - 1) ? firstOffsetOfNextRun : o
ffsets[i + 1]; | 961 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToC
haracterIndexes[i]; |
| 967 float glyphAdvanceX = advances[i] + nextOffset.x() - currentOffset.x(); | |
| 968 float glyphAdvanceY = nextOffset.y() - currentOffset.y(); | |
| 969 if (m_run.rtl()) { | |
| 970 if (currentCharacterIndex >= m_toIndex) | 962 if (currentCharacterIndex >= m_toIndex) |
| 971 m_startOffset.move(glyphAdvanceX, glyphAdvanceY); | 963 advanceSoFar += advances[i]; |
| 972 else if (currentCharacterIndex >= m_fromIndex) | 964 else if (currentCharacterIndex >= m_fromIndex) |
| 973 glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(gl
yphAdvanceX, glyphAdvanceY)); | 965 glyphBuffer->add(glyphs[i], currentRun->fontData(), offsets[i] +
FloatSize(advanceSoFar, 0), advances[i]); |
| 974 } else { | 966 } |
| 967 } else { |
| 968 for (unsigned i = 0; i < numGlyphs; ++i) { |
| 969 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToC
haracterIndexes[i]; |
| 975 if (currentCharacterIndex < m_fromIndex) | 970 if (currentCharacterIndex < m_fromIndex) |
| 976 m_startOffset.move(glyphAdvanceX, glyphAdvanceY); | 971 advanceSoFar += advances[i]; |
| 977 else if (currentCharacterIndex < m_toIndex) | 972 else if (currentCharacterIndex < m_toIndex) |
| 978 glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(gl
yphAdvanceX, glyphAdvanceY)); | 973 glyphBuffer->add(glyphs[i], currentRun->fontData(), offsets[i] +
FloatSize(advanceSoFar, 0), advances[i]); |
| 979 } | 974 } |
| 980 } | 975 } |
| 981 } | 976 } |
| 982 | 977 |
| 983 void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun) | 978 void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun) |
| 984 { | 979 { |
| 985 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u
sed by the | 980 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u
sed by the |
| 986 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis
mark drawing function. | 981 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis
mark drawing function. |
| 987 | 982 |
| 988 float* advances = currentRun->advances(); | 983 float* advances = currentRun->advances(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 clusterStart = clusterEnd; | 1026 clusterStart = clusterEnd; |
| 1032 clusterAdvance = 0; | 1027 clusterAdvance = 0; |
| 1033 } | 1028 } |
| 1034 } | 1029 } |
| 1035 } | 1030 } |
| 1036 | 1031 |
| 1037 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) | 1032 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) |
| 1038 { | 1033 { |
| 1039 unsigned numRuns = m_harfBuzzRuns.size(); | 1034 unsigned numRuns = m_harfBuzzRuns.size(); |
| 1040 if (m_run.rtl()) { | 1035 if (m_run.rtl()) { |
| 1041 m_startOffset = m_harfBuzzRuns.last()->offsets()[0]; | |
| 1042 for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) { | 1036 for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) { |
| 1043 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 1037 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
| 1044 if (!currentRun->hasGlyphToCharacterIndexes()) { | 1038 if (!currentRun->hasGlyphToCharacterIndexes()) { |
| 1045 // FIXME: bug 337886, 359664 | 1039 // FIXME: bug 337886, 359664 |
| 1046 continue; | 1040 continue; |
| 1047 } | 1041 } |
| 1048 FloatPoint firstOffsetOfNextRun = !runIndex ? FloatPoint() : m_harfB
uzzRuns[runIndex - 1]->offsets()[0]; | 1042 if (m_forTextEmphasis == ForTextEmphasis) { |
| 1049 if (m_forTextEmphasis == ForTextEmphasis) | 1043 ASSERT(!glyphBuffer->hasOffsets()); |
| 1050 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); | 1044 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); |
| 1051 else | 1045 } else { |
| 1052 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOff
setOfNextRun); | 1046 ASSERT(glyphBuffer->hasOffsets()); |
| 1047 fillGlyphBufferFromHarfBuzzRun( |
| 1048 static_cast<GlyphBufferWithOffsets*>(glyphBuffer), currentRu
n); |
| 1049 } |
| 1053 } | 1050 } |
| 1054 } else { | 1051 } else { |
| 1055 m_startOffset = m_harfBuzzRuns.first()->offsets()[0]; | |
| 1056 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { | 1052 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { |
| 1057 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 1053 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
| 1058 if (!currentRun->hasGlyphToCharacterIndexes()) { | 1054 if (!currentRun->hasGlyphToCharacterIndexes()) { |
| 1059 // FIXME: bug 337886, 359664 | 1055 // FIXME: bug 337886, 359664 |
| 1060 continue; | 1056 continue; |
| 1061 } | 1057 } |
| 1062 FloatPoint firstOffsetOfNextRun = runIndex == numRuns - 1 ? FloatPoi
nt() : m_harfBuzzRuns[runIndex + 1]->offsets()[0]; | 1058 if (m_forTextEmphasis == ForTextEmphasis) { |
| 1063 if (m_forTextEmphasis == ForTextEmphasis) | 1059 ASSERT(!glyphBuffer->hasOffsets()); |
| 1064 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); | 1060 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); |
| 1065 else | 1061 } else { |
| 1066 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOff
setOfNextRun); | 1062 ASSERT(glyphBuffer->hasOffsets()); |
| 1063 fillGlyphBufferFromHarfBuzzRun( |
| 1064 static_cast<GlyphBufferWithOffsets*>(glyphBuffer), currentRu
n); |
| 1065 } |
| 1067 } | 1066 } |
| 1068 } | 1067 } |
| 1069 return glyphBuffer->size(); | 1068 return glyphBuffer->size(); |
| 1070 } | 1069 } |
| 1071 | 1070 |
| 1072 int HarfBuzzShaper::offsetForPosition(float targetX) | 1071 int HarfBuzzShaper::offsetForPosition(float targetX) |
| 1073 { | 1072 { |
| 1074 int charactersSoFar = 0; | 1073 int charactersSoFar = 0; |
| 1075 float currentX = 0; | 1074 float currentX = 0; |
| 1076 | 1075 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 point.x() + fromX, point.x() + toX, | 1145 point.x() + fromX, point.x() + toX, |
| 1147 point.y(), height); | 1146 point.y(), height); |
| 1148 } | 1147 } |
| 1149 | 1148 |
| 1150 return Font::pixelSnappedSelectionRect( | 1149 return Font::pixelSnappedSelectionRect( |
| 1151 point.x() + toX, point.x() + fromX, | 1150 point.x() + toX, point.x() + fromX, |
| 1152 point.y(), height); | 1151 point.y(), height); |
| 1153 } | 1152 } |
| 1154 | 1153 |
| 1155 } // namespace blink | 1154 } // namespace blink |
| OLD | NEW |