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 "SVGTextLayoutAttributes.h"
23#include "TextRun.h"
24#include "WidthIterator.h"
25
26namespace WebCore {
27
28class RenderElement;
29class RenderSVGInlineText;
30class RenderSVGText;
31struct MeasureTextData;
32
33class SVGTextMetricsBuilder {
34 WTF_MAKE_NONCOPYABLE(SVGTextMetricsBuilder);
35public:
36 SVGTextMetricsBuilder();
37 void measureTextRenderer(RenderSVGInlineText&);
38 void buildMetricsAndLayoutAttributes(RenderSVGText&, RenderSVGInlineText* stopAtLeaf, SVGCharacterDataMap& allCharactersMap);
39
40private:
41 bool advance();
42 void advanceSimpleText();
43 void advanceComplexText();
44 bool currentCharacterStartsSurrogatePair() const;
45
46 void initializeMeasurementWithTextRenderer(RenderSVGInlineText&);
47 void walkTree(RenderElement&, RenderSVGInlineText* stopAtLeaf, MeasureTextData*);
48 void measureTextRenderer(RenderSVGInlineText&, MeasureTextData*);
49
50 RenderSVGInlineText* m_text;
51 TextRun m_run;
52 unsigned m_textPosition;
53 bool m_isComplexText;
54 SVGTextMetrics m_currentMetrics;
55 float m_totalWidth;
56
57 // Simple text only.
58 std::unique_ptr<WidthIterator> m_simpleWidthIterator;
59
60 // Complex text only.
61 SVGTextMetrics m_complexStartToCurrentMetrics;
62};
63
64} // namespace WebCore
65