Index: Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
diff --git a/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp b/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
index 8f4915a54c0bf6776e9c2654246d666bb0bb5363..b14fbedebd79b180edeaf4f25197ef9a1e5334e2 100644 |
--- a/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
+++ b/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
@@ -38,6 +38,7 @@ |
#include "platform/fonts/Font.h" |
#include "platform/fonts/harfbuzz/HarfBuzzFace.h" |
#include "platform/text/SurrogatePairAwareTextIterator.h" |
+#include "platform/text/TextBreakIterator.h" |
#include "wtf/MathExtras.h" |
#include "wtf/unicode/Unicode.h" |
#include <unicode/normlzr.h> |
@@ -208,6 +209,28 @@ static inline float harfBuzzPositionToFloat(hb_position_t value) |
return static_cast<float>(value) / (1 << 16); |
} |
+static inline uint16_t countGraphemesInCluster(const TextRun& run, uint16_t startIndex, uint16_t endIndex) |
+{ |
+ if (startIndex > endIndex) { |
+ uint16_t tempIndex = startIndex; |
+ startIndex = endIndex; |
+ endIndex = tempIndex; |
+ } |
+ uint16_t length = endIndex - startIndex; |
+ TextRun subRun = run.subRun(startIndex, length); |
+ |
+ // FIXME: Perhaps turn this into a classic character break iterator? |
behdad
2014/02/08 02:45:10
What does this mean?
|
+ TextBreakIterator* cursorPosIterator = cursorMovementIterator(subRun.characters16(), length); |
+ |
+ int cursorPos = cursorPosIterator->current(); |
+ uint16_t numGraphemes = -1; // Assumption |
+ while (0 <= cursorPos) { |
+ cursorPos = cursorPosIterator->next(); |
+ numGraphemes++; |
+ } |
+ return numGraphemes; |
+} |
+ |
inline HarfBuzzShaper::HarfBuzzRun::HarfBuzzRun(const SimpleFontData* fontData, unsigned startIndex, unsigned numCharacters, TextDirection direction, hb_script_t script) |
: m_fontData(fontData) |
, m_startIndex(startIndex) |
@@ -349,7 +372,7 @@ static void normalizeCharacters(const TextRun& run, unsigned length, UChar* dest |
} |
} |
-HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) |
+HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run, bool forTextEmphasis) |
: m_font(font) |
, m_normalizedBufferLength(0) |
, m_run(run) |
@@ -360,6 +383,7 @@ HarfBuzzShaper::HarfBuzzShaper(const Font* font, const TextRun& run) |
, m_letterSpacing(font->letterSpacing()) |
, m_fromIndex(0) |
, m_toIndex(m_run.length()) |
+ , m_forTextEmphasis(forTextEmphasis) |
{ |
m_normalizedBuffer = adoptArrayPtr(new UChar[m_run.length() + 1]); |
normalizeCharacters(m_run, m_run.length(), m_normalizedBuffer.get(), &m_normalizedBufferLength); |
@@ -916,22 +940,58 @@ void HarfBuzzShaper::fillGlyphBufferFromHarfBuzzRun(GlyphBuffer* glyphBuffer, Ha |
unsigned numGlyphs = currentRun->numGlyphs(); |
uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); |
- for (unsigned i = 0; i < numGlyphs; ++i) { |
- uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToCharacterIndexes[i]; |
- FloatPoint& currentOffset = offsets[i]; |
- FloatPoint& nextOffset = (i == numGlyphs - 1) ? firstOffsetOfNextRun : offsets[i + 1]; |
- float glyphAdvanceX = advances[i] + nextOffset.x() - currentOffset.x(); |
- float glyphAdvanceY = nextOffset.y() - currentOffset.y(); |
- if (m_run.rtl()) { |
- if (currentCharacterIndex >= m_toIndex) |
- m_startOffset.move(glyphAdvanceX, glyphAdvanceY); |
- else if (currentCharacterIndex >= m_fromIndex) |
- glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); |
- } else { |
- if (currentCharacterIndex < m_fromIndex) |
- m_startOffset.move(glyphAdvanceX, glyphAdvanceY); |
- else if (currentCharacterIndex < m_toIndex) |
- glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); |
+ // FIXME: Instead of generating a synthetic GlyphBuffer here which is then used by the |
+ // drawEmphasisMarks method of FontFastPath, we should roll our own emphasis mark drawing function. |
+ if (m_forTextEmphasis) { |
+ uint16_t graphemesInCluster = 1; |
+ uint16_t clusterStart; |
+ float clusterAdvance = 0; |
+ if (m_run.rtl()) |
+ clusterStart = currentRun->startIndex() + currentRun->numCharacters(); |
+ else |
+ clusterStart = currentRun->startIndex() + glyphToCharacterIndexes[0]; |
+ |
+ for (unsigned i = 0; i < numGlyphs; ++i) { |
+ uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToCharacterIndexes[i]; |
+ bool runEnd = (i + 1 == numGlyphs); |
+ bool isClusterEnd = runEnd || (currentRun->startIndex() + glyphToCharacterIndexes[i + 1] != currentCharacterIndex); |
+ clusterAdvance += advances[i]; |
+ |
+ if (isClusterEnd) { |
+ uint16_t clusterEnd; |
+ if (m_run.rtl()) |
+ clusterEnd = currentRun->startIndex() + glyphToCharacterIndexes[i]; |
+ else |
+ clusterEnd = runEnd ? currentRun->startIndex() + currentRun->numCharacters() : currentRun->startIndex() + glyphToCharacterIndexes[i + 1]; |
behdad
2014/02/08 02:45:10
Looks to me like you can easily merge lines 962..9
|
+ graphemesInCluster = countGraphemesInCluster(m_run, clusterStart, clusterEnd); |
+ float glyphAdvanceX = clusterAdvance / graphemesInCluster; |
+ for (unsigned j = 0; j < graphemesInCluster; ++j) { |
+ GlyphBufferGlyph glyphToAdd = Character::canReceiveTextEmphasis(m_run[currentCharacterIndex]) ? 1 : 0; |
+ glyphBuffer->add(glyphToAdd, currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, 0)); |
behdad
2014/02/08 02:45:10
I think we should try to horizontally center the e
|
+ } |
+ clusterStart = clusterEnd; |
+ clusterAdvance = 0; |
+ } |
+ } |
+ } else { |
+ for (unsigned i = 0; i < numGlyphs; ++i) { |
+ uint16_t currentCharacterIndex = currentRun->startIndex() + glyphToCharacterIndexes[i]; |
+ FloatPoint& currentOffset = offsets[i]; |
+ FloatPoint& nextOffset = (i == numGlyphs - 1) ? firstOffsetOfNextRun : offsets[i + 1]; |
+ float glyphAdvanceX = advances[i] + nextOffset.x() - currentOffset.x(); |
+ float glyphAdvanceY = nextOffset.y() - currentOffset.y(); |
+ |
+ if (m_run.rtl()) { |
+ if (currentCharacterIndex >= m_toIndex) |
+ m_startOffset.move(glyphAdvanceX, glyphAdvanceY); |
+ else if (currentCharacterIndex >= m_fromIndex) |
+ glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); |
+ } else { |
+ if (currentCharacterIndex < m_fromIndex) |
+ m_startOffset.move(glyphAdvanceX, glyphAdvanceY); |
+ else if (currentCharacterIndex < m_toIndex) |
+ glyphBuffer->add(glyphs[i], currentRun->fontData(), createGlyphBufferAdvance(glyphAdvanceX, glyphAdvanceY)); |
+ } |
} |
} |
} |