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 SVGTextLayoutEngine_h 21 #define SVGTextLayoutEngine_h 22 23 #if ENABLE(SVG) 24 #include "Path.h" 25 #include "SVGTextChunkBuilder.h" 26 #include "SVGTextFragment.h" 27 #include "SVGTextLayoutAttributes.h" 28 #include "SVGTextMetrics.h" 29 #include <wtf/Vector.h> 30 31 namespace WebCore { 32 33 class RenderObject; 34 class RenderStyle; 35 class RenderSVGInlineText; 36 class SVGElement; 37 class SVGInlineTextBox; 38 class SVGRenderStyle; 39 40 // SVGTextLayoutEngine performs the second layout phase for SVG text. 41 // 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. 47 48 class SVGTextLayoutEngine { 49 WTF_MAKE_NONCOPYABLE(SVGTextLayoutEngine); 50 public: 51 SVGTextLayoutEngine(Vector<SVGTextLayoutAttributes>&); chunkLayoutBuilder()52 SVGTextChunkBuilder& chunkLayoutBuilder() { return m_chunkLayoutBuilder; } 53 54 void beginTextPathLayout(RenderObject*, SVGTextLayoutEngine& lineLayout); 55 void endTextPathLayout(); 56 57 void layoutInlineTextBox(SVGInlineTextBox*); 58 void finishLayout(); 59 60 private: 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); 64 65 void recordTextFragment(SVGInlineTextBox*, Vector<SVGTextMetrics>& textMetricValues); 66 bool parentDefinesTextLength(RenderObject*) const; 67 68 void layoutTextOnLineOrPath(SVGInlineTextBox*, RenderSVGInlineText*, const RenderStyle*); 69 void finalizeTransformMatrices(Vector<SVGInlineTextBox*>&); 70 71 bool currentLogicalCharacterAttributes(SVGTextLayoutAttributes&); 72 bool currentLogicalCharacterMetrics(SVGTextLayoutAttributes&, SVGTextMetrics&); 73 bool currentVisualCharacterMetrics(SVGInlineTextBox*, RenderSVGInlineText*, SVGTextMetrics&); 74 75 void advanceToNextLogicalCharacter(const SVGTextMetrics&); 76 void advanceToNextVisualCharacter(const SVGTextMetrics&); 77 78 private: 79 Vector<SVGTextLayoutAttributes> m_layoutAttributes; 80 Vector<SVGInlineTextBox*> m_lineLayoutBoxes; 81 Vector<SVGInlineTextBox*> m_pathLayoutBoxes; 82 SVGTextChunkBuilder m_chunkLayoutBuilder; 83 84 SVGTextFragment m_currentTextFragment; 85 unsigned m_logicalCharacterOffset; 86 unsigned m_logicalMetricsListOffset; 87 unsigned m_visualCharacterOffset; 88 unsigned m_visualMetricsListOffset; 89 float m_x; 90 float m_y; 91 float m_dx; 92 float m_dy; 93 bool m_isVerticalText; 94 bool m_inPathLayout; 95 96 // Text on path layout 97 Path m_textPath; 98 float m_textPathLength; 99 float m_textPathStartOffset; 100 float m_textPathCurrentOffset; 101 float m_textPathSpacing; 102 float m_textPathScaling; 103 }; 104 105 } // namespace WebCore 106 107 #endif // ENABLE(SVG) 108 #endif 109