| 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 | #pragma once |
| 21 | |
| 22 | #include "Path.h" |
| 23 | #include "SVGTextChunkBuilder.h" |
| 24 | #include "SVGTextFragment.h" |
| 25 | #include "SVGTextLayoutAttributes.h" |
| 26 | |
| 27 | namespace WebCore { |
| 28 | |
| 29 | class RenderObject; |
| 30 | class RenderStyle; |
| 31 | class RenderSVGInlineText; |
| 32 | class RenderSVGTextPath; |
| 33 | class SVGElement; |
| 34 | class SVGInlineTextBox; |
| 35 | class SVGRenderStyle; |
| 36 | |
| 37 | // SVGTextLayoutEngine performs the second layout phase for SVG text. |
| 38 | // |
| 39 | // The InlineBox tree was created, containing the text chunk information, necessary to apply |
| 40 | // certain SVG specific text layout properties (text-length adjustments and text-anchor). |
| 41 | // The second layout phase uses the SVGTextLayoutAttributes stored in the individual |
| 42 | // RenderSVGInlineText renderers to compute the final positions for each character |
| 43 | // which are stored in the SVGInlineTextBox objects. |
| 44 | |
| 45 | class SVGTextLayoutEngine { |
| 46 | WTF_MAKE_NONCOPYABLE(SVGTextLayoutEngine); |
| 47 | public: |
| 48 | SVGTextLayoutEngine(Vector<SVGTextLayoutAttributes*>&); |
| 49 | |
| 50 | Vector<SVGTextLayoutAttributes*>& layoutAttributes() { return m_layoutAttributes; } |
| 51 | SVGTextChunkBuilder& chunkLayoutBuilder() { return m_chunkLayoutBuilder; } |
| 52 | |
| 53 | void beginTextPathLayout(RenderSVGTextPath&, SVGTextLayoutEngine& lineLayout); |
| 54 | void endTextPathLayout(); |
| 55 | |
| 56 | void layoutInlineTextBox(SVGInlineTextBox&); |
| 57 | void finishLayout(); |
| 58 | |
| 59 | private: |
| 60 | void updateCharacerPositionIfNeeded(float& x, float& y); |
| 61 | void updateCurrentTextPosition(float x, float y, float glyphAdvance); |
| 62 | void updateRelativePositionAdjustmentsIfNeeded(float dx, float dy); |
| 63 | |
| 64 | void recordTextFragment(SVGInlineTextBox&, Vector<SVGTextMetrics>&); |
| 65 | bool parentDefinesTextLength(RenderObject*) const; |
| 66 | |
| 67 | void layoutTextOnLineOrPath(SVGInlineTextBox&, RenderSVGInlineText&, const RenderStyle&); |
| 68 | void finalizeTransformMatrices(Vector<SVGInlineTextBox*>&); |
| 69 | |
| 70 | bool currentLogicalCharacterAttributes(SVGTextLayoutAttributes*&); |
| 71 | bool currentLogicalCharacterMetrics(SVGTextLayoutAttributes*&, SVGTextMetrics&); |
| 72 | bool currentVisualCharacterMetrics(const SVGInlineTextBox&, Vector<SVGTextMetrics>&, SVGTextMetrics&); |
| 73 | |
| 74 | void advanceToNextLogicalCharacter(const SVGTextMetrics&); |
| 75 | void advanceToNextVisualCharacter(const SVGTextMetrics&); |
| 76 | |
| 77 | private: |
| 78 | Vector<SVGTextLayoutAttributes*>& m_layoutAttributes; |
| 79 | |
| 80 | Vector<SVGInlineTextBox*> m_lineLayoutBoxes; |
| 81 | Vector<SVGInlineTextBox*> m_pathLayoutBoxes; |
| 82 | SVGTextChunkBuilder m_chunkLayoutBuilder; |
| 83 | |
| 84 | SVGTextFragment m_currentTextFragment; |
| 85 | unsigned m_layoutAttributesPosition; |
| 86 | unsigned m_logicalCharacterOffset; |
| 87 | unsigned m_logicalMetricsListOffset; |
| 88 | unsigned m_visualCharacterOffset; |
| 89 | unsigned m_visualMetricsListOffset; |
| 90 | float m_x; |
| 91 | float m_y; |
| 92 | float m_dx; |
| 93 | float m_dy; |
| 94 | bool m_isVerticalText; |
| 95 | bool m_inPathLayout; |
| 96 | |
| 97 | // Text on path layout |
| 98 | Path m_textPath; |
| 99 | float m_textPathLength; |
| 100 | float m_textPathStartOffset; |
| 101 | float m_textPathCurrentOffset; |
| 102 | float m_textPathSpacing; |
| 103 | float m_textPathScaling; |
| 104 | }; |
| 105 | |
| 106 | } // namespace WebCore |
| 107 | |