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 #ifndef SVGTextLayoutEngine_h 21 #define SVGTextLayoutEngine_h 22 23 #include "core/rendering/svg/SVGTextChunkBuilder.h" 24 #include "core/rendering/svg/SVGTextFragment.h" 25 #include "core/rendering/svg/SVGTextLayoutAttributes.h" 26 #include "core/rendering/svg/SVGTextMetrics.h" 27 #include "platform/graphics/Path.h" 28 #include "wtf/Vector.h" 29 30 namespace WebCore { 31 32 class RenderObject; 33 class RenderStyle; 34 class RenderSVGInlineText; 35 class SVGElement; 36 class SVGInlineTextBox; 37 class SVGRenderStyle; 38 39 // SVGTextLayoutEngine performs the second layout phase for SVG text. 40 // 41 // The InlineBox tree was created, containing the text chunk information, necessary to apply 42 // certain SVG specific text layout properties (text-length adjustments and text-anchor). 43 // The second layout phase uses the SVGTextLayoutAttributes stored in the individual 44 // RenderSVGInlineText renderers to compute the final positions for each character 45 // which are stored in the SVGInlineTextBox objects. 46 47 class SVGTextLayoutEngine { 48 WTF_MAKE_NONCOPYABLE(SVGTextLayoutEngine); 49 public: 50 SVGTextLayoutEngine(Vector<SVGTextLayoutAttributes*>&); 51 52 Vector<SVGTextLayoutAttributes*>& layoutAttributes() { return m_layoutAttributes; } 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(float dx, float dy); 64 65 void recordTextFragment(SVGInlineTextBox*, Vector<SVGTextMetrics>&); 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*, Vector<SVGTextMetrics>&, SVGTextMetrics&); 74 75 void advanceToNextLogicalCharacter(const SVGTextMetrics&); 76 void advanceToNextVisualCharacter(const SVGTextMetrics&); 77 78 private: 79 Vector<SVGTextLayoutAttributes*>& m_layoutAttributes; 80 81 Vector<SVGInlineTextBox*> m_lineLayoutBoxes; 82 Vector<SVGInlineTextBox*> m_pathLayoutBoxes; 83 SVGTextChunkBuilder m_chunkLayoutBuilder; 84 85 SVGTextFragment m_currentTextFragment; 86 unsigned m_layoutAttributesPosition; 87 unsigned m_logicalCharacterOffset; 88 unsigned m_logicalMetricsListOffset; 89 unsigned m_visualCharacterOffset; 90 unsigned m_visualMetricsListOffset; 91 float m_x; 92 float m_y; 93 float m_dx; 94 float m_dy; 95 bool m_isVerticalText; 96 bool m_inPathLayout; 97 98 // Text on path layout 99 Path m_textPath; 100 float m_textPathLength; 101 float m_textPathStartOffset; 102 float m_textPathCurrentOffset; 103 float m_textPathSpacing; 104 float m_textPathScaling; 105 }; 106 107 } // namespace WebCore 108 109 #endif 110