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(GlyphBufferWithOffsets* glyp
hBuffer, HarfBuzzRun* 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(); |
959 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); | 954 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); |
960 for (unsigned i = 0; i < numGlyphs; ++i) { | 955 float advanceSoFar = 0; |
961 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToChara
cterIndexes[i]; | 956 if (m_run.rtl()) { |
962 FloatPoint& currentOffset = offsets[i]; | 957 for (unsigned i = 0; i < numGlyphs; ++i) { |
963 FloatPoint& nextOffset = (i == numGlyphs - 1) ? firstOffsetOfNextRun : o
ffsets[i + 1]; | 958 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) | 959 if (currentCharacterIndex >= m_toIndex) |
968 m_startOffset.move(glyphAdvanceX, glyphAdvanceY); | 960 advanceSoFar += advances[i]; |
969 else if (currentCharacterIndex >= m_fromIndex) | 961 else if (currentCharacterIndex >= m_fromIndex) |
970 glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(gl
yphAdvanceX, glyphAdvanceY)); | 962 glyphBuffer->add(glyphs[i], currentRun->fontData(), offsets[i] +
FloatSize(advanceSoFar, 0), advances[i]); |
971 } else { | 963 } |
| 964 } else { |
| 965 for (unsigned i = 0; i < numGlyphs; ++i) { |
| 966 uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToC
haracterIndexes[i]; |
972 if (currentCharacterIndex < m_fromIndex) | 967 if (currentCharacterIndex < m_fromIndex) |
973 m_startOffset.move(glyphAdvanceX, glyphAdvanceY); | 968 advanceSoFar += advances[i]; |
974 else if (currentCharacterIndex < m_toIndex) | 969 else if (currentCharacterIndex < m_toIndex) |
975 glyphBuffer->add(glyphs[i], currentRun->fontData(), FloatSize(gl
yphAdvanceX, glyphAdvanceY)); | 970 glyphBuffer->add(glyphs[i], currentRun->fontData(), offsets[i] +
FloatSize(advanceSoFar, 0), advances[i]); |
976 } | 971 } |
977 } | 972 } |
978 } | 973 } |
979 | 974 |
980 void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun) | 975 void HarfBuzzShaper::fillGlyphBufferForTextEmphasis(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun) |
981 { | 976 { |
982 // FIXME: Instead of generating a synthetic GlyphBuffer here which is then u
sed by the | 977 // 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. | 978 // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis
mark drawing function. |
984 | 979 |
985 float* advances = currentRun->advances(); | 980 float* advances = currentRun->advances(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 clusterStart = clusterEnd; | 1023 clusterStart = clusterEnd; |
1029 clusterAdvance = 0; | 1024 clusterAdvance = 0; |
1030 } | 1025 } |
1031 } | 1026 } |
1032 } | 1027 } |
1033 | 1028 |
1034 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) | 1029 bool HarfBuzzShaper::fillGlyphBuffer(GlyphBuffer* glyphBuffer) |
1035 { | 1030 { |
1036 unsigned numRuns = m_harfBuzzRuns.size(); | 1031 unsigned numRuns = m_harfBuzzRuns.size(); |
1037 if (m_run.rtl()) { | 1032 if (m_run.rtl()) { |
1038 m_startOffset = m_harfBuzzRuns.last()->offsets()[0]; | |
1039 for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) { | 1033 for (int runIndex = numRuns - 1; runIndex >= 0; --runIndex) { |
1040 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 1034 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
1041 if (!currentRun->hasGlyphToCharacterIndexes()) { | 1035 if (!currentRun->hasGlyphToCharacterIndexes()) { |
1042 // FIXME: bug 337886, 359664 | 1036 // FIXME: bug 337886, 359664 |
1043 continue; | 1037 continue; |
1044 } | 1038 } |
1045 FloatPoint firstOffsetOfNextRun = !runIndex ? FloatPoint() : m_harfB
uzzRuns[runIndex - 1]->offsets()[0]; | 1039 if (m_forTextEmphasis == ForTextEmphasis) { |
1046 if (m_forTextEmphasis == ForTextEmphasis) | 1040 ASSERT(!glyphBuffer->hasOffsets()); |
1047 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); | 1041 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); |
1048 else | 1042 } else { |
1049 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOff
setOfNextRun); | 1043 ASSERT(glyphBuffer->hasOffsets()); |
| 1044 fillGlyphBufferFromHarfBuzzRun( |
| 1045 static_cast<GlyphBufferWithOffsets*>(glyphBuffer), currentRu
n); |
| 1046 } |
1050 } | 1047 } |
1051 } else { | 1048 } else { |
1052 m_startOffset = m_harfBuzzRuns.first()->offsets()[0]; | |
1053 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { | 1049 for (unsigned runIndex = 0; runIndex < numRuns; ++runIndex) { |
1054 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); | 1050 HarfBuzzRun* currentRun = m_harfBuzzRuns[runIndex].get(); |
1055 if (!currentRun->hasGlyphToCharacterIndexes()) { | 1051 if (!currentRun->hasGlyphToCharacterIndexes()) { |
1056 // FIXME: bug 337886, 359664 | 1052 // FIXME: bug 337886, 359664 |
1057 continue; | 1053 continue; |
1058 } | 1054 } |
1059 FloatPoint firstOffsetOfNextRun = runIndex == numRuns - 1 ? FloatPoi
nt() : m_harfBuzzRuns[runIndex + 1]->offsets()[0]; | 1055 if (m_forTextEmphasis == ForTextEmphasis) { |
1060 if (m_forTextEmphasis == ForTextEmphasis) | 1056 ASSERT(!glyphBuffer->hasOffsets()); |
1061 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); | 1057 fillGlyphBufferForTextEmphasis(glyphBuffer, currentRun); |
1062 else | 1058 } else { |
1063 fillGlyphBufferFromHarfBuzzRun(glyphBuffer, currentRun, firstOff
setOfNextRun); | 1059 ASSERT(glyphBuffer->hasOffsets()); |
| 1060 fillGlyphBufferFromHarfBuzzRun( |
| 1061 static_cast<GlyphBufferWithOffsets*>(glyphBuffer), currentRu
n); |
| 1062 } |
1064 } | 1063 } |
1065 } | 1064 } |
1066 return glyphBuffer->size(); | 1065 return glyphBuffer->size(); |
1067 } | 1066 } |
1068 | 1067 |
1069 int HarfBuzzShaper::offsetForPosition(float targetX) | 1068 int HarfBuzzShaper::offsetForPosition(float targetX) |
1070 { | 1069 { |
1071 int charactersSoFar = 0; | 1070 int charactersSoFar = 0; |
1072 float currentX = 0; | 1071 float currentX = 0; |
1073 | 1072 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 point.x() + fromX, point.x() + toX, | 1142 point.x() + fromX, point.x() + toX, |
1144 point.y(), height); | 1143 point.y(), height); |
1145 } | 1144 } |
1146 | 1145 |
1147 return Font::pixelSnappedSelectionRect( | 1146 return Font::pixelSnappedSelectionRect( |
1148 point.x() + toX, point.x() + fromX, | 1147 point.x() + toX, point.x() + fromX, |
1149 point.y(), height); | 1148 point.y(), height); |
1150 } | 1149 } |
1151 | 1150 |
1152 } // namespace blink | 1151 } // namespace blink |
OLD | NEW |