1/*
2 * Copyright (C) Research In Motion Limited 2010-2012. 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#pragma once
21
22#include <wtf/text/WTFString.h>
23
24namespace WebCore {
25
26class RenderSVGInlineText;
27class SVGTextLayoutAttributes;
28class TextRun;
29
30class SVGTextMetrics {
31public:
32 enum MetricsType { SkippedSpaceMetrics };
33
34 SVGTextMetrics();
35 explicit SVGTextMetrics(MetricsType);
36 SVGTextMetrics(RenderSVGInlineText&, unsigned length, float width);
37
38 static SVGTextMetrics measureCharacterRange(RenderSVGInlineText&, unsigned position, unsigned length);
39 static TextRun constructTextRun(RenderSVGInlineText&, unsigned position = 0, unsigned length = std::numeric_limits<unsigned>::max());
40
41 bool isEmpty() const { return !m_width && !m_height && !m_glyph.isValid && m_length == 1; }
42
43 float width() const { return m_width; }
44 void setWidth(float width) { m_width = width; }
45
46 float height() const { return m_height; }
47 unsigned length() const { return m_length; }
48
49 struct Glyph {
50 Glyph()
51 : isValid(false)
52 {
53 }
54
55 bool operator==(const Glyph& other)
56 {
57 return isValid == other.isValid
58 && name == other.name
59 && unicodeString == other.unicodeString;
60 }
61
62 bool isValid;
63 String name;
64 String unicodeString;
65 };
66
67 // Only useful when measuring individual characters, to lookup ligatures.
68 const Glyph& glyph() const { return m_glyph; }
69
70private:
71 SVGTextMetrics(RenderSVGInlineText&, const TextRun&);
72
73 float m_width;
74 float m_height;
75 unsigned m_length;
76 Glyph m_glyph;
77};
78
79} // namespace WebCore
80