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