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/platform/graphics/Path.h" 24 #include "core/rendering/svg/SVGTextChunkBuilder.h" 25 #include "core/rendering/svg/SVGTextFragment.h" 26 #include "core/rendering/svg/SVGTextLayoutAttributes.h" 27 #include "core/rendering/svg/SVGTextMetrics.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 SVGTextChunkBuilder& chunkLayoutBuilder() { return m_chunkLayoutBuilder; } 54 55 void beginTextPathLayout(RenderObject*, SVGTextLayoutEngine& lineLayout); 56 void endTextPathLayout(); 57 58 void layoutInlineTextBox(SVGInlineTextBox*); 59 void finishLayout(); 60 61 private: 62 void updateCharacerPositionIfNeeded(float& x, float& y); 63 void updateCurrentTextPosition(float x, float y, float glyphAdvance); 64 void updateRelativePositionAdjustmentsIfNeeded(float dx, float dy); 65 66 void recordTextFragment(SVGInlineTextBox*, Vector<SVGTextMetrics>&); 67 bool parentDefinesTextLength(RenderObject*) const; 68 69 void layoutTextOnLineOrPath(SVGInlineTextBox*, RenderSVGInlineText*, const RenderStyle*); 70 void finalizeTransformMatrices(Vector<SVGInlineTextBox*>&); 71 72 bool currentLogicalCharacterAttributes(SVGTextLayoutAttributes*&); 73 bool currentLogicalCharacterMetrics(SVGTextLayoutAttributes*&, SVGTextMetrics&); 74 bool currentVisualCharacterMetrics(SVGInlineTextBox*, Vector<SVGTextMetrics>&, SVGTextMetrics&); 75 76 void advanceToNextLogicalCharacter(const SVGTextMetrics&); 77 void advanceToNextVisualCharacter(const SVGTextMetrics&); 78 79 private: 80 Vector<SVGTextLayoutAttributes*>& m_layoutAttributes; 81 82 Vector<SVGInlineTextBox*> m_lineLayoutBoxes; 83 Vector<SVGInlineTextBox*> m_pathLayoutBoxes; 84 SVGTextChunkBuilder m_chunkLayoutBuilder; 85 86 SVGTextFragment m_currentTextFragment; 87 unsigned m_layoutAttributesPosition; 88 unsigned m_logicalCharacterOffset; 89 unsigned m_logicalMetricsListOffset; 90 unsigned m_visualCharacterOffset; 91 unsigned m_visualMetricsListOffset; 92 float m_x; 93 float m_y; 94 float m_dx; 95 float m_dy; 96 bool m_isVerticalText; 97 bool m_inPathLayout; 98 99 // Text on path layout 100 Path m_textPath; 101 float m_textPathLength; 102 float m_textPathStartOffset; 103 float m_textPathCurrentOffset; 104 float m_textPathSpacing; 105 float m_textPathScaling; 106 }; 107 108 } // namespace WebCore 109 110 #endif 111