float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, const SVGTextMetrics::Glyph& currentGlyph) { #if ENABLE(SVG_FONTS) if (!m_font.isSVGFont()) { m_lastGlyph.isValid = false; return 0; } SVGFontElement* svgFont = m_font.svgFont(); ASSERT(svgFont); float kerning = 0; if (m_lastGlyph.isValid) { if (isVerticalText) kerning = svgFont->verticalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name); else kerning = svgFont->horizontalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name); } m_lastGlyph = currentGlyph; m_lastGlyph.isValid = true; kerning *= m_font.size() / m_font.primaryFont()->unitsPerEm(); return kerning; #else UNUSED_PARAM(isVerticalText); UNUSED_PARAM(currentGlyph); return false; #endif }
bool SVGTextRunRenderingContext::applySVGKerning(const SimpleFontData* fontData, WidthIterator& iterator, GlyphBuffer* glyphBuffer, int from) const { ASSERT(glyphBuffer); ASSERT(glyphBuffer->size() > 1); SVGFontElement* fontElement = 0; SVGFontFaceElement* fontFaceElement = 0; svgFontAndFontFaceElementForFontData(fontData, fontFaceElement, fontElement); if (!fontElement || !fontFaceElement) return false; if (fontElement->horizontalKerningMapIsEmpty()) return true; float scale = scaleEmToUnits(fontData->platformData().size(), fontFaceElement->unitsPerEm()); String lastGlyphName; String lastUnicodeString; int characterOffset = iterator.m_currentCharacter; String text = iterator.run().string(); const int glyphCount = glyphBuffer->size() - from; GlyphBufferAdvance* advances = glyphBuffer->advances(from); for (int i = 0; i < glyphCount; ++i) { Glyph glyph = glyphBuffer->glyphAt(from + i); if (!glyph) continue; float kerning = 0; SVGGlyph svgGlyph = fontElement->svgGlyphForGlyph(glyph); String unicodeString = text.substring(characterOffset, svgGlyph.unicodeStringLength); if (i >= 1) { // FIXME: Support vertical text. kerning = fontElement->horizontalKerningForPairOfStringsAndGlyphs(lastUnicodeString, lastGlyphName, unicodeString, svgGlyph.glyphName); advances[i - 1].setWidth(advances[i - 1].width() - kerning * scale); } lastGlyphName = svgGlyph.glyphName; lastUnicodeString = unicodeString; characterOffset += svgGlyph.unicodeStringLength; } return true; }
float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, const SVGTextMetrics::Glyph& currentGlyph) { #if ENABLE(SVG_FONTS) const SimpleFontData* fontData = m_font.primaryFont(); if (!fontData->isSVGFont()) { m_lastGlyph.isValid = false; return 0; } ASSERT(fontData->isCustomFont()); ASSERT(fontData->isSVGFont()); const SVGFontData* svgFontData = static_cast<const SVGFontData*>(fontData->fontData()); SVGFontFaceElement* svgFontFace = svgFontData->svgFontFaceElement(); ASSERT(svgFontFace); SVGFontElement* svgFont = svgFontFace->associatedFontElement(); if (!svgFont) { m_lastGlyph.isValid = false; return 0; } float kerning = 0; if (m_lastGlyph.isValid) { if (isVerticalText) kerning = svgFont->verticalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name); else kerning = svgFont->horizontalKerningForPairOfStringsAndGlyphs(m_lastGlyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.name); } m_lastGlyph = currentGlyph; m_lastGlyph.isValid = true; kerning *= m_font.size() / m_font.fontMetrics().unitsPerEm(); return kerning; #else UNUSED_PARAM(isVerticalText); UNUSED_PARAM(currentGlyph); return false; #endif }