1/* 2 * Copyright (C) Research In Motion Limited 2010-2011. 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 SVGTextLayoutAttributesBuilder_h 21#define SVGTextLayoutAttributesBuilder_h 22 23#if ENABLE(SVG) 24#include "SVGTextLayoutAttributes.h" 25#include <wtf/Vector.h> 26 27namespace WebCore { 28 29class RenderObject; 30class RenderSVGText; 31class SVGTextPositioningElement; 32 33// SVGTextLayoutAttributesBuilder performs the first layout phase for SVG text. 34// 35// It extracts the x/y/dx/dy/rotate values from the SVGTextPositioningElements in the DOM, 36// measures all characters in the RenderSVGText subtree and extracts kerning/ligature information. 37// These values are propagated to the corresponding RenderSVGInlineText renderers. 38// The first layout phase only extracts the relevant information needed in RenderBlockLineLayout 39// to create the InlineBox tree based on text chunk boundaries & BiDi information. 40// The second layout phase is carried out by SVGTextLayoutEngine. 41 42class SVGTextLayoutAttributesBuilder { 43 WTF_MAKE_NONCOPYABLE(SVGTextLayoutAttributesBuilder); 44public: 45 SVGTextLayoutAttributesBuilder(); 46 void buildLayoutAttributesForTextSubtree(RenderSVGText*); 47 48private: 49 struct TextPosition { 50 TextPosition(SVGTextPositioningElement* newElement = 0, unsigned newStart = 0, unsigned newLength = 0) 51 : element(newElement) 52 , start(newStart) 53 , length(newLength) 54 { 55 } 56 57 SVGTextPositioningElement* element; 58 unsigned start; 59 unsigned length; 60 }; 61 62 void collectTextPositioningElements(RenderObject*, unsigned& atCharacter, UChar& lastCharacter); 63 void buildLayoutAttributesForAllCharacters(RenderSVGText*, unsigned textLength); 64 void propagateLayoutAttributes(RenderObject*, Vector<SVGTextLayoutAttributes>& allAttributes, unsigned& atCharacter, UChar& lastCharacter) const; 65 void fillAttributesAtPosition(const TextPosition&); 66 67private: 68 Vector<TextPosition> m_textPositions; 69 SVGTextLayoutAttributes::PositioningLists m_positioningLists; 70}; 71 72} // namespace WebCore 73 74#endif // ENABLE(SVG) 75#endif 76