diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-10-17 16:21:14 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-10-17 16:21:14 +0200 |
commit | 8995b83bcbfbb68245f779b64e5517627c6cc6ea (patch) | |
tree | 17985605dab9263cc2444bd4d45f189e142cca7c /Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp | |
parent | b9c9652036d5e9f1e29c574f40bc73a35c81ace6 (diff) |
Imported WebKit commit cf4f8fc6f19b0629f51860cb2d4b25e139d07e00 (http://svn.webkit.org/repository/webkit/trunk@131592)
New snapshot that includes the build fixes for Mac OS X 10.6 and earlier as well
as the previously cherry-picked changes
Diffstat (limited to 'Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp')
-rw-r--r-- | Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp b/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp index 9e55fc411..796b37c95 100644 --- a/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp +++ b/Source/WebCore/platform/graphics/harfbuzz/ng/HarfBuzzShaper.cpp @@ -87,10 +87,6 @@ void HarfBuzzShaper::HarfBuzzRun::applyShapeResult(hb_buffer_t* harfbuzzBuffer) m_advances.resize(m_numGlyphs); m_glyphToCharacterIndexes.resize(m_numGlyphs); m_offsets.resize(m_numGlyphs); - - hb_glyph_info_t* infos = hb_buffer_get_glyph_infos(harfbuzzBuffer, 0); - for (unsigned i = 0; i < m_numGlyphs; ++i) - m_glyphToCharacterIndexes[i] = infos[i].cluster; } void HarfBuzzShaper::HarfBuzzRun::setGlyphAndPositions(unsigned index, uint16_t glyphId, float advance, float offsetX, float offsetY) @@ -204,18 +200,27 @@ void HarfBuzzShaper::setDrawRange(int from, int to) void HarfBuzzShaper::setFontFeatures() { - FontFeatureSettings* settings = m_font->fontDescription().featureSettings(); + const FontDescription& description = m_font->fontDescription(); + if (description.orientation() == Vertical) { + static hb_feature_t vert = { HarfBuzzNGFace::vertTag, 1, 0, static_cast<unsigned>(-1) }; + static hb_feature_t vrt2 = { HarfBuzzNGFace::vrt2Tag, 1, 0, static_cast<unsigned>(-1) }; + m_features.append(vert); + m_features.append(vrt2); + } + + FontFeatureSettings* settings = description.featureSettings(); if (!settings) return; unsigned numFeatures = settings->size(); - m_features.resize(numFeatures); for (unsigned i = 0; i < numFeatures; ++i) { + hb_feature_t feature; const UChar* tag = settings->at(i).tag().characters(); - m_features[i].tag = HB_TAG(tag[0], tag[1], tag[2], tag[3]); - m_features[i].value = settings->at(i).value(); - m_features[i].start = 0; - m_features[i].end = static_cast<unsigned>(-1); + feature.tag = HB_TAG(tag[0], tag[1], tag[2], tag[3]); + feature.value = settings->at(i).value(); + feature.start = 0; + feature.end = static_cast<unsigned>(-1); + m_features.append(feature); } } @@ -240,20 +245,6 @@ FloatPoint HarfBuzzShaper::adjustStartPoint(const FloatPoint& point) return point + m_startOffset; } -static const SimpleFontData* fontDataForCombiningCharacterSequence(const Font* font, const UChar* characters, size_t length) -{ - UErrorCode error = U_ZERO_ERROR; - Vector<UChar, 4> normalizedCharacters(length); - int32_t normalizedLength = unorm_normalize(characters, length, UNORM_NFC, UNORM_UNICODE_3_2, &normalizedCharacters[0], length, &error); - // Should fallback if we have an error or no composition occurred. - if (U_FAILURE(error) || (static_cast<size_t>(normalizedLength) == length)) - return 0; - UChar32 normalizedCharacter; - size_t index = 0; - U16_NEXT(&normalizedCharacters[0], index, static_cast<size_t>(normalizedLength), normalizedCharacter); - return font->glyphDataForCharacter(normalizedCharacter, false).fontData; -} - bool HarfBuzzShaper::collectHarfBuzzRuns() { const UChar* normalizedBufferEnd = m_normalizedBuffer.get() + m_normalizedBufferLength; @@ -278,6 +269,7 @@ bool HarfBuzzShaper::collectHarfBuzzRuns() for (iterator.advance(clusterLength); iterator.consume(character, clusterLength); iterator.advance(clusterLength)) { if (Font::treatAsZeroWidthSpace(character)) continue; + if (U_GET_GC_MASK(character) & U_GC_M_MASK) { int markLength = clusterLength; const UChar* markCharactersEnd = iterator.characters() + clusterLength; @@ -290,11 +282,12 @@ bool HarfBuzzShaper::collectHarfBuzzRuns() markLength += nextCharacterLength; markCharactersEnd += nextCharacterLength; } - nextFontData = fontDataForCombiningCharacterSequence(m_font, currentCharacterPosition, markCharactersEnd - currentCharacterPosition); - if (nextFontData) + + if (currentFontData->canRenderCombiningCharacterSequence(currentCharacterPosition, markCharactersEnd - currentCharacterPosition)) { clusterLength = markLength; - else - nextFontData = m_font->glyphDataForCharacter(character, false).fontData; + continue; + } + nextFontData = m_font->glyphDataForCharacter(character, false).fontData; } else nextFontData = m_font->glyphDataForCharacter(character, false).fontData; @@ -305,6 +298,7 @@ bool HarfBuzzShaper::collectHarfBuzzRuns() break; if (nextScript == USCRIPT_INHERITED) nextScript = currentScript; + currentCharacterPosition = iterator.characters(); } unsigned numCharactersOfCurrentRun = iterator.currentCharacter() - startIndexOfCurrentRun; m_harfbuzzRuns.append(HarfBuzzRun::create(currentFontData, startIndexOfCurrentRun, numCharactersOfCurrentRun, m_run.direction())); @@ -340,7 +334,12 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns() HarfBuzzNGFace* face = platformData->harfbuzzFace(); if (!face) return false; + + if (m_font->fontDescription().orientation() == Vertical) + face->setScriptForVerticalGlyphSubstitution(harfbuzzBuffer.get()); + HarfBuzzScopedPtr<hb_font_t> harfbuzzFont(face->createFont(), hb_font_destroy); + hb_shape(harfbuzzFont.get(), harfbuzzBuffer.get(), m_features.isEmpty() ? 0 : m_features.data(), m_features.size()); currentRun->applyShapeResult(harfbuzzBuffer.get()); @@ -361,6 +360,7 @@ void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb hb_glyph_position_t* glyphPositions = hb_buffer_get_glyph_positions(harfbuzzBuffer, 0); unsigned numGlyphs = currentRun->numGlyphs(); + uint16_t* glyphToCharacterIndexes = currentRun->glyphToCharacterIndexes(); float totalAdvance = 0; // HarfBuzz returns the shaping result in visual order. We need not to flip for RTL. @@ -374,6 +374,9 @@ void HarfBuzzShaper::setGlyphPositionsForHarfBuzzRun(HarfBuzzRun* currentRun, hb unsigned currentCharacterIndex = currentRun->startIndex() + glyphInfos[i].cluster; bool isClusterEnd = runEnd || glyphInfos[i].cluster != glyphInfos[i + 1].cluster; float spacing = 0; + + glyphToCharacterIndexes[i] = glyphInfos[i].cluster; + if (isClusterEnd && !Font::treatAsZeroWidthSpace(m_normalizedBuffer[currentCharacterIndex])) spacing += m_letterSpacing; |