Home | History | Annotate | Download | only in svg
      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 blink {
     31 
     32 class RenderObject;
     33 class RenderStyle;
     34 class RenderSVGInlineText;
     35 class SVGInlineTextBox;
     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 
     52     void beginTextPathLayout(RenderObject*, SVGTextLayoutEngine& lineLayout);
     53     void endTextPathLayout();
     54 
     55     void layoutInlineTextBox(SVGInlineTextBox*);
     56     void finishLayout();
     57 
     58 private:
     59     void updateCharacterPositionIfNeeded(float& x, float& y);
     60     void updateCurrentTextPosition(float x, float y, float glyphAdvance);
     61     void updateRelativePositionAdjustmentsIfNeeded(float dx, float dy);
     62 
     63     void recordTextFragment(SVGInlineTextBox*, const Vector<SVGTextMetrics>&);
     64     bool parentDefinesTextLength(RenderObject*) const;
     65 
     66     void layoutTextOnLineOrPath(SVGInlineTextBox*, const RenderSVGInlineText&, const RenderStyle&);
     67     void finalizeTransformMatrices(Vector<SVGInlineTextBox*>&);
     68 
     69     bool currentLogicalCharacterAttributes(SVGTextLayoutAttributes*&);
     70     bool currentLogicalCharacterMetrics(SVGTextLayoutAttributes*&, SVGTextMetrics&);
     71     bool currentVisualCharacterMetrics(SVGInlineTextBox*, const Vector<SVGTextMetrics>&, SVGTextMetrics&);
     72 
     73     void advanceToNextLogicalCharacter(const SVGTextMetrics&);
     74     void advanceToNextVisualCharacter(const SVGTextMetrics&);
     75 
     76 private:
     77     Vector<SVGTextLayoutAttributes*>& m_layoutAttributes;
     78 
     79     Vector<SVGInlineTextBox*> m_lineLayoutBoxes;
     80     Vector<SVGInlineTextBox*> m_pathLayoutBoxes;
     81     SVGTextChunkBuilder m_chunkLayoutBuilder;
     82 
     83     SVGTextFragment m_currentTextFragment;
     84     unsigned m_layoutAttributesPosition;
     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::PositionCalculator* m_textPathCalculator;
     98     float m_textPathLength;
     99     float m_textPathStartOffset;
    100     float m_textPathCurrentOffset;
    101     float m_textPathSpacing;
    102     float m_textPathScaling;
    103 };
    104 
    105 } // namespace blink
    106 
    107 #endif
    108