1 /* 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef SVGTextMetrics_h 21 #define SVGTextMetrics_h 22 23 #if ENABLE(SVG) 24 #include <wtf/text/WTFString.h> 25 26 namespace WebCore { 27 28 class RenderSVGInlineText; 29 class TextRun; 30 31 class SVGTextMetrics { 32 public: 33 static SVGTextMetrics emptyMetrics(); 34 static SVGTextMetrics measureCharacterRange(RenderSVGInlineText*, unsigned position, unsigned length); 35 36 bool operator==(const SVGTextMetrics&); 37 width()38 float width() const { return m_width; } height()39 float height() const { return m_height; } length()40 unsigned length() const { return m_length; } 41 42 struct Glyph { GlyphGlyph43 Glyph() 44 : isValid(false) 45 { 46 } 47 48 bool operator==(const Glyph& other) 49 { 50 return isValid == other.isValid 51 && name == other.name 52 && unicodeString == other.unicodeString; 53 } 54 55 bool isValid; 56 String name; 57 String unicodeString; 58 }; 59 60 // Only useful when measuring individual characters, to lookup ligatures. glyph()61 const Glyph& glyph() const { return m_glyph; } 62 63 private: 64 friend class SVGTextLayoutAttributesBuilder; setWidth(float width)65 void setWidth(float width) { m_width = width; } 66 67 private: 68 SVGTextMetrics(); 69 SVGTextMetrics(RenderSVGInlineText*, const TextRun&, unsigned position, unsigned textLength); 70 71 float m_width; 72 float m_height; 73 unsigned m_length; 74 Glyph m_glyph; 75 }; 76 77 } // namespace WebCore 78 79 #endif // ENABLE(SVG) 80 #endif 81