Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: Source/core/rendering/svg/SVGTextLayoutEngineSpacing.cpp

Issue 181443002: Use glyph-ids for lookups of SVG font kerning-pairs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Vector<...>::append -> Vector<...>::appendVector. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 19 matching lines...) Expand all
30 #include "core/svg/SVGFontData.h" 30 #include "core/svg/SVGFontData.h"
31 #include "core/svg/SVGFontElement.h" 31 #include "core/svg/SVGFontElement.h"
32 #include "core/svg/SVGFontFaceElement.h" 32 #include "core/svg/SVGFontFaceElement.h"
33 #endif 33 #endif
34 34
35 namespace WebCore { 35 namespace WebCore {
36 36
37 SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font) 37 SVGTextLayoutEngineSpacing::SVGTextLayoutEngineSpacing(const Font& font)
38 : m_font(font) 38 : m_font(font)
39 , m_lastCharacter(0) 39 , m_lastCharacter(0)
40 #if ENABLE(SVG_FONTS)
41 , m_lastGlyph(0)
42 #endif
40 { 43 {
41 } 44 }
42 45
43 float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, const SVGTextMetrics::Glyph& currentGlyph) 46 float SVGTextLayoutEngineSpacing::calculateSVGKerning(bool isVerticalText, Glyph currentGlyph)
44 { 47 {
45 #if ENABLE(SVG_FONTS) 48 #if ENABLE(SVG_FONTS)
46 const SimpleFontData* fontData = m_font.primaryFont(); 49 const SimpleFontData* fontData = m_font.primaryFont();
47 if (!fontData->isSVGFont()) { 50 if (!fontData->isSVGFont()) {
48 m_lastGlyph.isValid = false; 51 m_lastGlyph = 0;
49 return 0; 52 return 0;
50 } 53 }
51 54
52 ASSERT(fontData->isCustomFont()); 55 ASSERT(fontData->isCustomFont());
53 ASSERT(fontData->isSVGFont()); 56 ASSERT(fontData->isSVGFont());
54 57
55 RefPtr<CustomFontData> customFontData = fontData->customFontData(); 58 RefPtr<CustomFontData> customFontData = fontData->customFontData();
56 const SVGFontData* svgFontData = static_cast<const SVGFontData*>(customFontD ata.get()); 59 const SVGFontData* svgFontData = static_cast<const SVGFontData*>(customFontD ata.get());
57 SVGFontFaceElement* svgFontFace = svgFontData->svgFontFaceElement(); 60 SVGFontFaceElement* svgFontFace = svgFontData->svgFontFaceElement();
58 ASSERT(svgFontFace); 61 ASSERT(svgFontFace);
59 62
60 SVGFontElement* svgFont = svgFontFace->associatedFontElement(); 63 SVGFontElement* svgFont = svgFontFace->associatedFontElement();
61 if (!svgFont) { 64 if (!svgFont) {
62 m_lastGlyph.isValid = false; 65 m_lastGlyph = 0;
63 return 0; 66 return 0;
64 } 67 }
65 68
66 float kerning = 0; 69 float kerning = 0;
67 if (m_lastGlyph.isValid) { 70 if (m_lastGlyph) {
68 if (isVerticalText) 71 if (isVerticalText)
69 kerning = svgFont->verticalKerningForPairOfStringsAndGlyphs(m_lastGl yph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph.na me); 72 kerning = svgFont->verticalKerningForPairOfGlyphs(m_lastGlyph, curre ntGlyph);
70 else 73 else
71 kerning = svgFont->horizontalKerningForPairOfStringsAndGlyphs(m_last Glyph.unicodeString, m_lastGlyph.name, currentGlyph.unicodeString, currentGlyph. name); 74 kerning = svgFont->horizontalKerningForPairOfGlyphs(m_lastGlyph, cur rentGlyph);
75
76 kerning *= m_font.fontDescription().computedSize() / m_font.fontMetrics( ).unitsPerEm();
72 } 77 }
73 78
74 m_lastGlyph = currentGlyph; 79 m_lastGlyph = currentGlyph;
75 m_lastGlyph.isValid = true;
76 kerning *= m_font.fontDescription().computedSize() / m_font.fontMetrics().un itsPerEm();
77 return kerning; 80 return kerning;
78 #else 81 #else
79 return false; 82 return 0;
80 #endif 83 #endif
81 } 84 }
82 85
83 float SVGTextLayoutEngineSpacing::calculateCSSKerningAndSpacing(const SVGRenderS tyle* style, SVGElement* contextElement, UChar currentCharacter) 86 float SVGTextLayoutEngineSpacing::calculateCSSKerningAndSpacing(const SVGRenderS tyle* style, SVGElement* contextElement, UChar currentCharacter)
84 { 87 {
85 float kerning = 0; 88 float kerning = 0;
86 RefPtr<SVGLength> kerningLength = style->kerning(); 89 RefPtr<SVGLength> kerningLength = style->kerning();
87 if (kerningLength->unitType() == LengthTypePercentage) 90 if (kerningLength->unitType() == LengthTypePercentage)
88 kerning = kerningLength->valueAsPercentage() * m_font.fontDescription(). computedPixelSize(); 91 kerning = kerningLength->valueAsPercentage() * m_font.fontDescription(). computedPixelSize();
89 else { 92 else {
(...skipping 10 matching lines...) Expand all
100 float spacing = m_font.fontDescription().letterSpacing() + kerning; 103 float spacing = m_font.fontDescription().letterSpacing() + kerning;
101 if (currentCharacter && lastCharacter && m_font.fontDescription().wordSpacin g()) { 104 if (currentCharacter && lastCharacter && m_font.fontDescription().wordSpacin g()) {
102 if (Character::treatAsSpace(currentCharacter) && !Character::treatAsSpac e(lastCharacter)) 105 if (Character::treatAsSpace(currentCharacter) && !Character::treatAsSpac e(lastCharacter))
103 spacing += m_font.fontDescription().wordSpacing(); 106 spacing += m_font.fontDescription().wordSpacing();
104 } 107 }
105 108
106 return spacing; 109 return spacing;
107 } 110 }
108 111
109 } 112 }
OLDNEW
« no previous file with comments | « Source/core/rendering/svg/SVGTextLayoutEngineSpacing.h ('k') | Source/core/rendering/svg/SVGTextMetrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698