| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) | 3 * (C) 2000 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2003, 2006, 2007, 2011 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2006, 2007, 2011 Apple Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #ifndef TextRun_h | 24 #ifndef TextRun_h |
| 25 #define TextRun_h | 25 #define TextRun_h |
| 26 | 26 |
| 27 #include "platform/PlatformExport.h" | 27 #include "platform/PlatformExport.h" |
| 28 #include "platform/geometry/FloatRect.h" | 28 #include "platform/geometry/FloatRect.h" |
| 29 #include "platform/text/TextDirection.h" | 29 #include "platform/text/TextDirection.h" |
| 30 #include "platform/text/TextPath.h" |
| 30 #include "wtf/RefCounted.h" | 31 #include "wtf/RefCounted.h" |
| 31 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
| 32 | 33 |
| 33 namespace WebCore { | 34 namespace WebCore { |
| 34 | 35 |
| 35 class FloatPoint; | 36 class FloatPoint; |
| 36 class Font; | 37 class Font; |
| 37 class GraphicsContext; | 38 class GraphicsContext; |
| 38 class GlyphBuffer; | 39 class GlyphBuffer; |
| 39 class SimpleFontData; | 40 class SimpleFontData; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 69 , m_expansionBehavior(expansionBehavior) | 70 , m_expansionBehavior(expansionBehavior) |
| 70 , m_is8Bit(true) | 71 , m_is8Bit(true) |
| 71 , m_allowTabs(false) | 72 , m_allowTabs(false) |
| 72 , m_direction(direction) | 73 , m_direction(direction) |
| 73 , m_directionalOverride(directionalOverride) | 74 , m_directionalOverride(directionalOverride) |
| 74 , m_characterScanForCodePath(characterScanForCodePath) | 75 , m_characterScanForCodePath(characterScanForCodePath) |
| 75 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) | 76 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) |
| 76 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) | 77 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) |
| 77 , m_disableSpacing(false) | 78 , m_disableSpacing(false) |
| 78 , m_tabSize(0) | 79 , m_tabSize(0) |
| 80 , m_textCodePath(AutoPath) |
| 79 { | 81 { |
| 80 m_data.characters8 = c; | 82 m_data.characters8 = c; |
| 81 } | 83 } |
| 82 | 84 |
| 83 TextRun(const UChar* c, unsigned len, float xpos = 0, float expansion = 0, E
xpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpan
sion, TextDirection direction = LTR, bool directionalOverride = false, bool char
acterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRou
nding) | 85 TextRun(const UChar* c, unsigned len, float xpos = 0, float expansion = 0, E
xpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpan
sion, TextDirection direction = LTR, bool directionalOverride = false, bool char
acterScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRou
nding) |
| 84 : m_charactersLength(len) | 86 : m_charactersLength(len) |
| 85 , m_len(len) | 87 , m_len(len) |
| 86 , m_xpos(xpos) | 88 , m_xpos(xpos) |
| 87 , m_horizontalGlyphStretch(1) | 89 , m_horizontalGlyphStretch(1) |
| 88 , m_expansion(expansion) | 90 , m_expansion(expansion) |
| 89 , m_expansionBehavior(expansionBehavior) | 91 , m_expansionBehavior(expansionBehavior) |
| 90 , m_is8Bit(false) | 92 , m_is8Bit(false) |
| 91 , m_allowTabs(false) | 93 , m_allowTabs(false) |
| 92 , m_direction(direction) | 94 , m_direction(direction) |
| 93 , m_directionalOverride(directionalOverride) | 95 , m_directionalOverride(directionalOverride) |
| 94 , m_characterScanForCodePath(characterScanForCodePath) | 96 , m_characterScanForCodePath(characterScanForCodePath) |
| 95 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) | 97 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) |
| 96 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) | 98 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) |
| 97 , m_disableSpacing(false) | 99 , m_disableSpacing(false) |
| 98 , m_tabSize(0) | 100 , m_tabSize(0) |
| 101 , m_textCodePath(AutoPath) |
| 99 { | 102 { |
| 100 m_data.characters16 = c; | 103 m_data.characters16 = c; |
| 101 } | 104 } |
| 102 | 105 |
| 103 TextRun(const String& string, float xpos = 0, float expansion = 0, Expansion
Behavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, Te
xtDirection direction = LTR, bool directionalOverride = false, bool characterSca
nForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding) | 106 TextRun(const String& string, float xpos = 0, float expansion = 0, Expansion
Behavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, Te
xtDirection direction = LTR, bool directionalOverride = false, bool characterSca
nForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRounding) |
| 104 : m_charactersLength(string.length()) | 107 : m_charactersLength(string.length()) |
| 105 , m_len(string.length()) | 108 , m_len(string.length()) |
| 106 , m_xpos(xpos) | 109 , m_xpos(xpos) |
| 107 , m_horizontalGlyphStretch(1) | 110 , m_horizontalGlyphStretch(1) |
| 108 , m_expansion(expansion) | 111 , m_expansion(expansion) |
| 109 , m_expansionBehavior(expansionBehavior) | 112 , m_expansionBehavior(expansionBehavior) |
| 110 , m_allowTabs(false) | 113 , m_allowTabs(false) |
| 111 , m_direction(direction) | 114 , m_direction(direction) |
| 112 , m_directionalOverride(directionalOverride) | 115 , m_directionalOverride(directionalOverride) |
| 113 , m_characterScanForCodePath(characterScanForCodePath) | 116 , m_characterScanForCodePath(characterScanForCodePath) |
| 114 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) | 117 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) |
| 115 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) | 118 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) |
| 116 , m_disableSpacing(false) | 119 , m_disableSpacing(false) |
| 117 , m_tabSize(0) | 120 , m_tabSize(0) |
| 121 , m_textCodePath(AutoPath) |
| 118 { | 122 { |
| 119 if (!m_charactersLength) { | 123 if (!m_charactersLength) { |
| 120 m_is8Bit = true; | 124 m_is8Bit = true; |
| 121 m_data.characters8 = 0; | 125 m_data.characters8 = 0; |
| 122 } else if (string.is8Bit()) { | 126 } else if (string.is8Bit()) { |
| 123 m_data.characters8 = string.characters8(); | 127 m_data.characters8 = string.characters8(); |
| 124 m_is8Bit = true; | 128 m_is8Bit = true; |
| 125 } else { | 129 } else { |
| 126 m_data.characters16 = string.characters16(); | 130 m_data.characters16 = string.characters16(); |
| 127 m_is8Bit = false; | 131 m_is8Bit = false; |
| 128 } | 132 } |
| 129 } | 133 } |
| 130 | 134 |
| 131 TextRun(const StringView& string, float xpos = 0, float expansion = 0, Expan
sionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion
, TextDirection direction = LTR, bool directionalOverride = false, bool characte
rScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRoundin
g) | 135 TextRun(const StringView& string, float xpos = 0, float expansion = 0, Expan
sionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion
, TextDirection direction = LTR, bool directionalOverride = false, bool characte
rScanForCodePath = true, RoundingHacks roundingHacks = RunRounding | WordRoundin
g) |
| 132 : m_charactersLength(string.length()) | 136 : m_charactersLength(string.length()) |
| 133 , m_len(string.length()) | 137 , m_len(string.length()) |
| 134 , m_xpos(xpos) | 138 , m_xpos(xpos) |
| 135 , m_horizontalGlyphStretch(1) | 139 , m_horizontalGlyphStretch(1) |
| 136 , m_expansion(expansion) | 140 , m_expansion(expansion) |
| 137 , m_expansionBehavior(expansionBehavior) | 141 , m_expansionBehavior(expansionBehavior) |
| 138 , m_allowTabs(false) | 142 , m_allowTabs(false) |
| 139 , m_direction(direction) | 143 , m_direction(direction) |
| 140 , m_directionalOverride(directionalOverride) | 144 , m_directionalOverride(directionalOverride) |
| 141 , m_characterScanForCodePath(characterScanForCodePath) | 145 , m_characterScanForCodePath(characterScanForCodePath) |
| 142 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) | 146 , m_applyRunRounding((roundingHacks & RunRounding) && s_allowsRoundingHa
cks) |
| 143 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) | 147 , m_applyWordRounding((roundingHacks & WordRounding) && s_allowsRounding
Hacks) |
| 144 , m_disableSpacing(false) | 148 , m_disableSpacing(false) |
| 145 , m_tabSize(0) | 149 , m_tabSize(0) |
| 150 , m_textCodePath(AutoPath) |
| 146 { | 151 { |
| 147 if (!m_charactersLength) { | 152 if (!m_charactersLength) { |
| 148 m_is8Bit = true; | 153 m_is8Bit = true; |
| 149 m_data.characters8 = 0; | 154 m_data.characters8 = 0; |
| 150 } else if (string.is8Bit()) { | 155 } else if (string.is8Bit()) { |
| 151 m_data.characters8 = string.characters8(); | 156 m_data.characters8 = string.characters8(); |
| 152 m_is8Bit = true; | 157 m_is8Bit = true; |
| 153 } else { | 158 } else { |
| 154 m_data.characters16 = string.characters16(); | 159 m_data.characters16 = string.characters16(); |
| 155 m_is8Bit = false; | 160 m_is8Bit = false; |
| 156 } | 161 } |
| 157 } | 162 } |
| 158 | 163 |
| 159 TextRun subRun(unsigned startOffset, unsigned length) const | 164 TextRun subRun(unsigned startOffset, unsigned length) const |
| 160 { | 165 { |
| 161 ASSERT(startOffset < m_len); | 166 ASSERT(startOffset < m_len); |
| 162 | 167 |
| 163 TextRun result = *this; | 168 TextRun result = *this; |
| 164 | 169 |
| 165 if (is8Bit()) { | 170 if (is8Bit()) { |
| 166 result.setText(data8(startOffset), length); | 171 result.setText(data8(startOffset), length); |
| 167 return result; | 172 return result; |
| 168 } | 173 } |
| 169 result.setText(data16(startOffset), length); | 174 result.setText(data16(startOffset), length); |
| 170 return result; | 175 return result; |
| 171 } | 176 } |
| 172 | 177 |
| 178 void setCharacterScanForCodePathValue(CodePath textCodePath) |
| 179 { |
| 180 m_textCodePath = textCodePath; |
| 181 |
| 182 #if ENABLE(SVG_FONTS) |
| 183 if (renderingContext()) |
| 184 m_textCodePath = SimplePath; |
| 185 #endif |
| 186 } |
| 187 |
| 173 UChar operator[](unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i < m_
len); return is8Bit() ? m_data.characters8[i] :m_data.characters16[i]; } | 188 UChar operator[](unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i < m_
len); return is8Bit() ? m_data.characters8[i] :m_data.characters16[i]; } |
| 174 const LChar* data8(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i <
m_len); ASSERT(is8Bit()); return &m_data.characters8[i]; } | 189 const LChar* data8(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i <
m_len); ASSERT(is8Bit()); return &m_data.characters8[i]; } |
| 175 const UChar* data16(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i <
m_len); ASSERT(!is8Bit()); return &m_data.characters16[i]; } | 190 const UChar* data16(unsigned i) const { ASSERT_WITH_SECURITY_IMPLICATION(i <
m_len); ASSERT(!is8Bit()); return &m_data.characters16[i]; } |
| 176 | 191 |
| 177 const LChar* characters8() const { ASSERT(is8Bit()); return m_data.character
s8; } | 192 const LChar* characters8() const { ASSERT(is8Bit()); return m_data.character
s8; } |
| 178 const UChar* characters16() const { ASSERT(!is8Bit()); return m_data.charact
ers16; } | 193 const UChar* characters16() const { ASSERT(!is8Bit()); return m_data.charact
ers16; } |
| 179 | 194 |
| 180 bool is8Bit() const { return m_is8Bit; } | 195 bool is8Bit() const { return m_is8Bit; } |
| 181 int length() const { return m_len; } | 196 int length() const { return m_len; } |
| 182 int charactersLength() const { return m_charactersLength; } | 197 int charactersLength() const { return m_charactersLength; } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 196 float xPos() const { return m_xpos; } | 211 float xPos() const { return m_xpos; } |
| 197 void setXPos(float xPos) { m_xpos = xPos; } | 212 void setXPos(float xPos) { m_xpos = xPos; } |
| 198 float expansion() const { return m_expansion; } | 213 float expansion() const { return m_expansion; } |
| 199 bool allowsLeadingExpansion() const { return m_expansionBehavior & AllowLead
ingExpansion; } | 214 bool allowsLeadingExpansion() const { return m_expansionBehavior & AllowLead
ingExpansion; } |
| 200 bool allowsTrailingExpansion() const { return m_expansionBehavior & AllowTra
ilingExpansion; } | 215 bool allowsTrailingExpansion() const { return m_expansionBehavior & AllowTra
ilingExpansion; } |
| 201 TextDirection direction() const { return static_cast<TextDirection>(m_direct
ion); } | 216 TextDirection direction() const { return static_cast<TextDirection>(m_direct
ion); } |
| 202 bool rtl() const { return m_direction == RTL; } | 217 bool rtl() const { return m_direction == RTL; } |
| 203 bool ltr() const { return m_direction == LTR; } | 218 bool ltr() const { return m_direction == LTR; } |
| 204 bool directionalOverride() const { return m_directionalOverride; } | 219 bool directionalOverride() const { return m_directionalOverride; } |
| 205 bool characterScanForCodePath() const { return m_characterScanForCodePath; } | 220 bool characterScanForCodePath() const { return m_characterScanForCodePath; } |
| 221 CodePath characterScanForCodePathValue() const { return m_textCodePath; } |
| 206 bool applyRunRounding() const { return m_applyRunRounding; } | 222 bool applyRunRounding() const { return m_applyRunRounding; } |
| 207 bool applyWordRounding() const { return m_applyWordRounding; } | 223 bool applyWordRounding() const { return m_applyWordRounding; } |
| 208 bool spacingDisabled() const { return m_disableSpacing; } | 224 bool spacingDisabled() const { return m_disableSpacing; } |
| 209 | 225 |
| 210 void disableSpacing() { m_disableSpacing = true; } | 226 void disableSpacing() { m_disableSpacing = true; } |
| 211 void disableRoundingHacks() { m_applyRunRounding = m_applyWordRounding = fal
se; } | 227 void disableRoundingHacks() { m_applyRunRounding = m_applyWordRounding = fal
se; } |
| 212 void setDirection(TextDirection direction) { m_direction = direction; } | 228 void setDirection(TextDirection direction) { m_direction = direction; } |
| 213 void setDirectionalOverride(bool override) { m_directionalOverride = overrid
e; } | 229 void setDirectionalOverride(bool override) { m_directionalOverride = overrid
e; } |
| 214 void setCharacterScanForCodePath(bool scan) { m_characterScanForCodePath = s
can; } | 230 void setCharacterScanForCodePath(bool scan) { m_characterScanForCodePath = s
can; } |
| 215 | 231 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 ExpansionBehavior m_expansionBehavior : 2; | 264 ExpansionBehavior m_expansionBehavior : 2; |
| 249 unsigned m_is8Bit : 1; | 265 unsigned m_is8Bit : 1; |
| 250 unsigned m_allowTabs : 1; | 266 unsigned m_allowTabs : 1; |
| 251 unsigned m_direction : 1; | 267 unsigned m_direction : 1; |
| 252 unsigned m_directionalOverride : 1; // Was this direction set by an override
character. | 268 unsigned m_directionalOverride : 1; // Was this direction set by an override
character. |
| 253 unsigned m_characterScanForCodePath : 1; | 269 unsigned m_characterScanForCodePath : 1; |
| 254 unsigned m_applyRunRounding : 1; | 270 unsigned m_applyRunRounding : 1; |
| 255 unsigned m_applyWordRounding : 1; | 271 unsigned m_applyWordRounding : 1; |
| 256 unsigned m_disableSpacing : 1; | 272 unsigned m_disableSpacing : 1; |
| 257 unsigned m_tabSize; | 273 unsigned m_tabSize; |
| 274 CodePath m_textCodePath; |
| 258 RefPtr<RenderingContext> m_renderingContext; | 275 RefPtr<RenderingContext> m_renderingContext; |
| 259 }; | 276 }; |
| 260 | 277 |
| 261 inline void TextRun::setTabSize(bool allow, unsigned size) | 278 inline void TextRun::setTabSize(bool allow, unsigned size) |
| 262 { | 279 { |
| 263 m_allowTabs = allow; | 280 m_allowTabs = allow; |
| 264 m_tabSize = size; | 281 m_tabSize = size; |
| 265 } | 282 } |
| 266 | 283 |
| 267 // Container for parameters needed to paint TextRun. | 284 // Container for parameters needed to paint TextRun. |
| 268 struct TextRunPaintInfo { | 285 struct TextRunPaintInfo { |
| 269 explicit TextRunPaintInfo(const TextRun& r) | 286 explicit TextRunPaintInfo(const TextRun& r) |
| 270 : run(r) | 287 : run(r) |
| 271 , from(0) | 288 , from(0) |
| 272 , to(r.length()) | 289 , to(r.length()) |
| 273 { | 290 { |
| 274 } | 291 } |
| 275 | 292 |
| 276 const TextRun& run; | 293 const TextRun& run; |
| 277 int from; | 294 int from; |
| 278 int to; | 295 int to; |
| 279 FloatRect bounds; | 296 FloatRect bounds; |
| 280 }; | 297 }; |
| 281 | 298 |
| 282 } | 299 } |
| 283 #endif | 300 #endif |
| OLD | NEW |