OSDN Git Service

Merge "merge from honeycomb mr2"
[android-x86/external-webkit.git] / Source / WebCore / platform / graphics / TextRun.h
1 /*
2  * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3  *           (C) 2000 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Dirk Mueller (mueller@kde.org)
5  * Copyright (C) 2003, 2006, 2007, 2011 Apple Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23
24 #ifndef TextRun_h
25 #define TextRun_h
26
27 #include "PlatformString.h"
28
29 namespace WebCore {
30
31 class RenderObject;
32 class RenderSVGResource;
33
34 class TextRun {
35 public:
36     enum TrailingExpansionBehavior {
37         AllowTrailingExpansion,
38         ForbidTrailingExpansion
39     };
40
41     TextRun(const UChar* c, int len, bool allowTabs = false, int xpos = 0, int expansion = 0, TrailingExpansionBehavior trailingExpansionBehavior = AllowTrailingExpansion, bool rtl = false, bool directionalOverride = false,
42               bool applyRunRounding = true, bool applyWordRounding = true)
43         : m_characters(c)
44         , m_len(len)
45         , m_xpos(xpos)
46         , m_expansion(expansion)
47         , m_trailingExpansionBehavior(trailingExpansionBehavior)
48 #if ENABLE(SVG)
49         , m_horizontalGlyphStretch(1)
50 #endif
51         , m_allowTabs(allowTabs)
52         , m_rtl(rtl)
53         , m_directionalOverride(directionalOverride)
54         , m_applyRunRounding(applyRunRounding)
55         , m_applyWordRounding(applyWordRounding)
56         , m_disableSpacing(false)
57 #if ENABLE(SVG_FONTS)
58         , m_referencingRenderObject(0)
59         , m_activePaintingResource(0)
60 #endif
61     {
62     }
63
64     TextRun(const String& s, bool allowTabs = false, int xpos = 0, int expansion = 0, TrailingExpansionBehavior trailingExpansionBehavior = AllowTrailingExpansion, bool rtl = false, bool directionalOverride = false,
65               bool applyRunRounding = true, bool applyWordRounding = true)
66         : m_characters(s.characters())
67         , m_len(s.length())
68         , m_xpos(xpos)
69         , m_expansion(expansion)
70         , m_trailingExpansionBehavior(trailingExpansionBehavior)
71 #if ENABLE(SVG)
72         , m_horizontalGlyphStretch(1)
73 #endif
74         , m_allowTabs(allowTabs)
75         , m_rtl(rtl)
76         , m_directionalOverride(directionalOverride)
77         , m_applyRunRounding(applyRunRounding)
78         , m_applyWordRounding(applyWordRounding)
79         , m_disableSpacing(false)
80 #if ENABLE(SVG_FONTS)
81         , m_referencingRenderObject(0)
82         , m_activePaintingResource(0)
83 #endif
84     {
85     }
86
87     UChar operator[](int i) const { return m_characters[i]; }
88     const UChar* data(int i) const { return &m_characters[i]; }
89
90     const UChar* characters() const { return m_characters; }
91     int length() const { return m_len; }
92
93     void setText(const UChar* c, int len) { m_characters = c; m_len = len; }
94
95 #if ENABLE(SVG)
96     float horizontalGlyphStretch() const { return m_horizontalGlyphStretch; }
97     void setHorizontalGlyphStretch(float scale) { m_horizontalGlyphStretch = scale; }
98 #endif
99
100     bool allowTabs() const { return m_allowTabs; }
101     int xPos() const { return m_xpos; }
102     int expansion() const { return m_expansion; }
103     bool allowsTrailingExpansion() const { return m_trailingExpansionBehavior == AllowTrailingExpansion; }
104     bool rtl() const { return m_rtl; }
105     bool ltr() const { return !m_rtl; }
106     bool directionalOverride() const { return m_directionalOverride; }
107     bool applyRunRounding() const { return m_applyRunRounding; }
108     bool applyWordRounding() const { return m_applyWordRounding; }
109     bool spacingDisabled() const { return m_disableSpacing; }
110
111     void disableSpacing() { m_disableSpacing = true; }
112     void disableRoundingHacks() { m_applyRunRounding = m_applyWordRounding = false; }
113     void setRTL(bool b) { m_rtl = b; }
114     void setDirectionalOverride(bool override) { m_directionalOverride = override; }
115
116 #if ENABLE(SVG_FONTS)
117     RenderObject* referencingRenderObject() const { return m_referencingRenderObject; }
118     void setReferencingRenderObject(RenderObject* object) { m_referencingRenderObject = object; }
119
120     RenderSVGResource* activePaintingResource() const { return m_activePaintingResource; }
121     void setActivePaintingResource(RenderSVGResource* object) { m_activePaintingResource = object; }
122 #endif
123
124 private:
125     const UChar* m_characters;
126     int m_len;
127
128     // m_xpos is the x position relative to the left start of the text line, not relative to the left
129     // start of the containing block. In the case of right alignment or center alignment, left start of
130     // the text line is not the same as left start of the containing block.
131     int m_xpos;  
132     int m_expansion;
133     TrailingExpansionBehavior m_trailingExpansionBehavior;
134 #if ENABLE(SVG)
135     float m_horizontalGlyphStretch;
136 #endif
137     bool m_allowTabs;
138     bool m_rtl;
139     bool m_directionalOverride;
140     bool m_applyRunRounding;
141     bool m_applyWordRounding;
142     bool m_disableSpacing;
143
144 #if ENABLE(SVG_FONTS)
145     RenderObject* m_referencingRenderObject;
146     RenderSVGResource* m_activePaintingResource;
147 #endif
148 };
149
150 }
151
152 #endif