1/*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#pragma once
22
23#include "SVGTextChunk.h"
24#include <wtf/Vector.h>
25
26namespace WebCore {
27
28class SVGInlineTextBox;
29struct SVGTextFragment;
30
31// SVGTextChunkBuilder performs the third layout phase for SVG text.
32//
33// Phase one built the layout information from the SVG DOM stored in the RenderSVGInlineText objects (SVGTextLayoutAttributes).
34// Phase two performed the actual per-character layout, computing the final positions for each character, stored in the SVGInlineTextBox objects (SVGTextFragment).
35// Phase three performs all modifications that have to be applied to each individual text chunk (text-anchor & textLength).
36
37class SVGTextChunkBuilder {
38 WTF_MAKE_NONCOPYABLE(SVGTextChunkBuilder);
39public:
40 SVGTextChunkBuilder();
41
42 const Vector<SVGTextChunk>& textChunks() const { return m_textChunks; }
43 unsigned totalCharacters() const;
44 float totalLength() const;
45 float totalAnchorShift() const;
46 AffineTransform transformationForTextBox(SVGInlineTextBox*) const;
47
48 void buildTextChunks(const Vector<SVGInlineTextBox*>& lineLayoutBoxes);
49 void layoutTextChunks(const Vector<SVGInlineTextBox*>& lineLayoutBoxes);
50
51private:
52 Vector<SVGTextChunk> m_textChunks;
53 HashMap<SVGInlineTextBox*, AffineTransform> m_textBoxTransformations;
54};
55
56} // namespace WebCore
57