Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010. 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 SVGTextChunk_h
     21 #define SVGTextChunk_h
     22 
     23 #include "core/rendering/style/SVGRenderStyleDefs.h"
     24 #include "core/svg/SVGTextContentElement.h"
     25 
     26 namespace WebCore {
     27 
     28 class SVGInlineTextBox;
     29 
     30 // A SVGTextChunk describes a range of SVGTextFragments, see the SVG spec definition of a "text chunk".
     31 class SVGTextChunk {
     32 public:
     33     enum ChunkStyle {
     34         DefaultStyle = 1 << 0,
     35         MiddleAnchor = 1 << 1,
     36         EndAnchor = 1 << 2,
     37         RightToLeftText = 1 << 3,
     38         VerticalText = 1 << 4,
     39         LengthAdjustSpacing = 1 << 5,
     40         LengthAdjustSpacingAndGlyphs = 1 << 6
     41     };
     42 
     43     SVGTextChunk(unsigned chunkStyle, float desiredTextLength);
     44 
     45     void calculateLength(float& length, unsigned& characters) const;
     46     float calculateTextAnchorShift(float length) const;
     47 
     48     bool isVerticalText() const { return m_chunkStyle & VerticalText; }
     49     float desiredTextLength() const { return m_desiredTextLength; }
     50 
     51     Vector<SVGInlineTextBox*>& boxes() { return m_boxes; }
     52     const Vector<SVGInlineTextBox*>& boxes() const { return m_boxes; }
     53 
     54     bool hasDesiredTextLength() const { return m_desiredTextLength > 0 && ((m_chunkStyle & LengthAdjustSpacing) || (m_chunkStyle & LengthAdjustSpacingAndGlyphs)); }
     55     bool hasTextAnchor() const {  return m_chunkStyle & RightToLeftText ? !(m_chunkStyle & EndAnchor) : (m_chunkStyle & MiddleAnchor) || (m_chunkStyle & EndAnchor); }
     56     bool hasLengthAdjustSpacing() const { return m_chunkStyle & LengthAdjustSpacing; }
     57     bool hasLengthAdjustSpacingAndGlyphs() const { return m_chunkStyle & LengthAdjustSpacingAndGlyphs; }
     58 
     59 private:
     60     // Contains all SVGInlineTextBoxes this chunk spans.
     61     Vector<SVGInlineTextBox*> m_boxes;
     62 
     63     unsigned m_chunkStyle;
     64     float m_desiredTextLength;
     65 };
     66 
     67 } // namespace WebCore
     68 
     69 #endif
     70