2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
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.
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.
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.
20 #ifndef SVGTextLayoutEngine_h
21 #define SVGTextLayoutEngine_h
25 #include "SVGTextChunkBuilder.h"
26 #include "SVGTextFragment.h"
27 #include "SVGTextLayoutAttributes.h"
28 #include "SVGTextMetrics.h"
29 #include <wtf/Vector.h>
35 class RenderSVGInlineText;
37 class SVGInlineTextBox;
40 // SVGTextLayoutEngine performs the second layout phase for SVG text.
42 // The InlineBox tree was created, containing the text chunk information, necessary to apply
43 // certain SVG specific text layout properties (text-length adjustments and text-anchor).
44 // The second layout phase uses the SVGTextLayoutAttributes stored in the individual
45 // RenderSVGInlineText renderers to compute the final positions for each character
46 // which are stored in the SVGInlineTextBox objects.
48 class SVGTextLayoutEngine {
49 WTF_MAKE_NONCOPYABLE(SVGTextLayoutEngine);
51 SVGTextLayoutEngine(Vector<SVGTextLayoutAttributes>&);
52 SVGTextChunkBuilder& chunkLayoutBuilder() { return m_chunkLayoutBuilder; }
54 void beginTextPathLayout(RenderObject*, SVGTextLayoutEngine& lineLayout);
55 void endTextPathLayout();
57 void layoutInlineTextBox(SVGInlineTextBox*);
61 void updateCharacerPositionIfNeeded(float& x, float& y);
62 void updateCurrentTextPosition(float x, float y, float glyphAdvance);
63 void updateRelativePositionAdjustmentsIfNeeded(Vector<float>& dxValues, Vector<float>& dyValues);
65 void recordTextFragment(SVGInlineTextBox*, Vector<SVGTextMetrics>& textMetricValues);
66 bool parentDefinesTextLength(RenderObject*) const;
68 void layoutTextOnLineOrPath(SVGInlineTextBox*, RenderSVGInlineText*, const RenderStyle*);
69 void finalizeTransformMatrices(Vector<SVGInlineTextBox*>&);
71 bool currentLogicalCharacterAttributes(SVGTextLayoutAttributes&);
72 bool currentLogicalCharacterMetrics(SVGTextLayoutAttributes&, SVGTextMetrics&);
73 bool currentVisualCharacterMetrics(SVGInlineTextBox*, RenderSVGInlineText*, SVGTextMetrics&);
75 void advanceToNextLogicalCharacter(const SVGTextMetrics&);
76 void advanceToNextVisualCharacter(const SVGTextMetrics&);
79 Vector<SVGTextLayoutAttributes> m_layoutAttributes;
80 Vector<SVGInlineTextBox*> m_lineLayoutBoxes;
81 Vector<SVGInlineTextBox*> m_pathLayoutBoxes;
82 SVGTextChunkBuilder m_chunkLayoutBuilder;
84 SVGTextFragment m_currentTextFragment;
85 unsigned m_logicalCharacterOffset;
86 unsigned m_logicalMetricsListOffset;
87 unsigned m_visualCharacterOffset;
88 unsigned m_visualMetricsListOffset;
93 bool m_isVerticalText;
96 // Text on path layout
98 float m_textPathLength;
99 float m_textPathStartOffset;
100 float m_textPathCurrentOffset;
101 float m_textPathSpacing;
102 float m_textPathScaling;
105 } // namespace WebCore
107 #endif // ENABLE(SVG)