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 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 , m_normalizedBufferLength(0) | 375 , m_normalizedBufferLength(0) |
376 , m_run(run) | 376 , m_run(run) |
377 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing()) | 377 , m_wordSpacingAdjustment(font->fontDescription().wordSpacing()) |
378 , m_padding(0) | 378 , m_padding(0) |
379 , m_padPerWordBreak(0) | 379 , m_padPerWordBreak(0) |
380 , m_padError(0) | 380 , m_padError(0) |
381 , m_letterSpacing(font->fontDescription().letterSpacing()) | 381 , m_letterSpacing(font->fontDescription().letterSpacing()) |
382 , m_fromIndex(0) | 382 , m_fromIndex(0) |
383 , m_toIndex(m_run.length()) | 383 , m_toIndex(m_run.length()) |
384 , m_forTextEmphasis(forTextEmphasis) | 384 , m_forTextEmphasis(forTextEmphasis) |
| 385 , m_minGlyphBoundingBoxX(std::numeric_limits<float>::max()) |
| 386 , m_maxGlyphBoundingBoxX(std::numeric_limits<float>::min()) |
| 387 , m_minGlyphBoundingBoxY(std::numeric_limits<float>::max()) |
| 388 , m_maxGlyphBoundingBoxY(std::numeric_limits<float>::min()) |
385 { | 389 { |
386 m_normalizedBuffer = adoptArrayPtr(new UChar[m_run.length() + 1]); | 390 m_normalizedBuffer = adoptArrayPtr(new UChar[m_run.length() + 1]); |
387 normalizeCharacters(m_run, m_run.length(), m_normalizedBuffer.get(), &m_norm
alizedBufferLength); | 391 normalizeCharacters(m_run, m_run.length(), m_normalizedBuffer.get(), &m_norm
alizedBufferLength); |
388 setPadding(m_run.expansion()); | 392 setPadding(m_run.expansion()); |
389 setFontFeatures(); | 393 setFontFeatures(); |
390 } | 394 } |
391 | 395 |
392 bool HarfBuzzShaper::isWordEnd(unsigned index) | 396 bool HarfBuzzShaper::isWordEnd(unsigned index) |
393 { | 397 { |
394 // This could refer a high-surrogate, but should work. | 398 // This could refer a high-surrogate, but should work. |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 | 862 |
859 if (!currentRun->hasGlyphToCharacterIndexes()) { | 863 if (!currentRun->hasGlyphToCharacterIndexes()) { |
860 // FIXME: https://crbug.com/337886 | 864 // FIXME: https://crbug.com/337886 |
861 ASSERT_NOT_REACHED(); | 865 ASSERT_NOT_REACHED(); |
862 return; | 866 return; |
863 } | 867 } |
864 | 868 |
865 unsigned numGlyphs = currentRun->numGlyphs(); | 869 unsigned numGlyphs = currentRun->numGlyphs(); |
866 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); | 870 uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); |
867 float totalAdvance = 0; | 871 float totalAdvance = 0; |
| 872 FloatPoint glyphOrigin; |
868 | 873 |
869 // HarfBuzz returns the shaping result in visual order. We need not to flip
for RTL. | 874 // HarfBuzz returns the shaping result in visual order. We need not to flip
for RTL. |
870 for (size_t i = 0; i < numGlyphs; ++i) { | 875 for (size_t i = 0; i < numGlyphs; ++i) { |
871 bool runEnd = i + 1 == numGlyphs; | 876 bool runEnd = i + 1 == numGlyphs; |
872 uint16_t glyph = glyphInfos[i].codepoint; | 877 uint16_t glyph = glyphInfos[i].codepoint; |
873 float offsetX = harfBuzzPositionToFloat(glyphPositions[i].x_offset); | 878 float offsetX = harfBuzzPositionToFloat(glyphPositions[i].x_offset); |
874 float offsetY = -harfBuzzPositionToFloat(glyphPositions[i].y_offset); | 879 float offsetY = -harfBuzzPositionToFloat(glyphPositions[i].y_offset); |
875 float advance = harfBuzzPositionToFloat(glyphPositions[i].x_advance); | 880 float advance = harfBuzzPositionToFloat(glyphPositions[i].x_advance); |
876 | 881 |
877 unsigned currentCharacterIndex = currentRun->startIndex() + glyphInfos[i
].cluster; | 882 unsigned currentCharacterIndex = currentRun->startIndex() + glyphInfos[i
].cluster; |
(...skipping 16 matching lines...) Expand all Loading... |
894 advance += spacing; | 899 advance += spacing; |
895 if (m_run.rtl()) { | 900 if (m_run.rtl()) { |
896 // In RTL, spacing should be added to left side of glyphs. | 901 // In RTL, spacing should be added to left side of glyphs. |
897 offsetX += spacing; | 902 offsetX += spacing; |
898 if (!isClusterEnd) | 903 if (!isClusterEnd) |
899 offsetX += m_letterSpacing; | 904 offsetX += m_letterSpacing; |
900 } | 905 } |
901 | 906 |
902 currentRun->setGlyphAndPositions(i, glyph, advance, offsetX, offsetY); | 907 currentRun->setGlyphAndPositions(i, glyph, advance, offsetX, offsetY); |
903 | 908 |
| 909 FloatRect glyphBounds = currentFontData->boundsForGlyph(glyph); |
| 910 glyphBounds.move(glyphOrigin.x(), glyphOrigin.y()); |
| 911 m_minGlyphBoundingBoxX = std::min(m_minGlyphBoundingBoxX, glyphBounds.x(
)); |
| 912 m_maxGlyphBoundingBoxX = std::max(m_maxGlyphBoundingBoxX, glyphBounds.ma
xX()); |
| 913 m_minGlyphBoundingBoxY = std::min(m_minGlyphBoundingBoxY, glyphBounds.y(
)); |
| 914 m_maxGlyphBoundingBoxY = std::max(m_maxGlyphBoundingBoxY, glyphBounds.ma
xY()); |
| 915 glyphOrigin += FloatSize(advance + offsetX, offsetY); |
| 916 |
904 totalAdvance += advance; | 917 totalAdvance += advance; |
905 } | 918 } |
906 currentRun->setWidth(totalAdvance > 0.0 ? totalAdvance : 0.0); | 919 currentRun->setWidth(totalAdvance > 0.0 ? totalAdvance : 0.0); |
907 m_totalWidth += currentRun->width(); | 920 m_totalWidth += currentRun->width(); |
908 } | 921 } |
909 | 922 |
910 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun, FloatPoint& firstOffsetOfNextRun) | 923 void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha
rfBuzzRun* currentRun, FloatPoint& firstOffsetOfNextRun) |
911 { | 924 { |
912 FloatPoint* offsets = currentRun->offsets(); | 925 FloatPoint* offsets = currentRun->offsets(); |
913 uint16_t* glyphs = currentRun->glyphs(); | 926 uint16_t* glyphs = currentRun->glyphs(); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 if (!foundToX) | 1100 if (!foundToX) |
1088 toX = m_run.rtl() ? 0 : m_totalWidth; | 1101 toX = m_run.rtl() ? 0 : m_totalWidth; |
1089 | 1102 |
1090 // Using floorf() and roundf() as the same as mac port. | 1103 // Using floorf() and roundf() as the same as mac port. |
1091 if (fromX < toX) | 1104 if (fromX < toX) |
1092 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from
X), height); | 1105 return FloatRect(floorf(point.x() + fromX), point.y(), roundf(toX - from
X), height); |
1093 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he
ight); | 1106 return FloatRect(floorf(point.x() + toX), point.y(), roundf(fromX - toX), he
ight); |
1094 } | 1107 } |
1095 | 1108 |
1096 } // namespace WebCore | 1109 } // namespace WebCore |
OLD | NEW |