1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org) 3 * (C) 2000 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Dirk Mueller (mueller (at) 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 ExpansionBehaviorFlags { 37 ForbidTrailingExpansion = 0 << 0, 38 AllowTrailingExpansion = 1 << 0, 39 ForbidLeadingExpansion = 0 << 1, 40 AllowLeadingExpansion = 1 << 1, 41 }; 42 43 typedef unsigned ExpansionBehavior; 44 45 TextRun(const UChar* c, int len, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, bool rtl = false, bool directionalOverride = false) 46 : m_characters(c) 47 , m_len(len) 48 , m_xpos(xpos) 49 , m_expansion(expansion) 50 , m_expansionBehavior(expansionBehavior) 51 #if ENABLE(SVG) 52 , m_horizontalGlyphStretch(1) 53 #endif 54 , m_allowTabs(allowTabs) 55 , m_rtl(rtl) 56 , m_directionalOverride(directionalOverride) 57 , m_disableSpacing(false) 58 #if ENABLE(SVG_FONTS) 59 , m_referencingRenderObject(0) 60 , m_activePaintingResource(0) 61 #endif 62 { 63 } 64 65 TextRun(const String& s, bool allowTabs = false, float xpos = 0, float expansion = 0, ExpansionBehavior expansionBehavior = AllowTrailingExpansion | ForbidLeadingExpansion, bool rtl = false, bool directionalOverride = false) 66 : m_characters(s.characters()) 67 , m_len(s.length()) 68 , m_xpos(xpos) 69 , m_expansion(expansion) 70 , m_expansionBehavior(expansionBehavior) 71 #if ENABLE(SVG) 72 , m_horizontalGlyphStretch(1) 73 #endif 74 , m_allowTabs(allowTabs) 75 , m_rtl(rtl) 76 , m_directionalOverride(directionalOverride) 77 , m_disableSpacing(false) 78 #if ENABLE(SVG_FONTS) 79 , m_referencingRenderObject(0) 80 , m_activePaintingResource(0) 81 #endif 82 { 83 } 84 85 UChar operator[](int i) const { return m_characters[i]; } 86 const UChar* data(int i) const { return &m_characters[i]; } 87 88 const UChar* characters() const { return m_characters; } 89 int length() const { return m_len; } 90 91 void setText(const UChar* c, int len) { m_characters = c; m_len = len; } 92 93 #if ENABLE(SVG) 94 float horizontalGlyphStretch() const { return m_horizontalGlyphStretch; } 95 void setHorizontalGlyphStretch(float scale) { m_horizontalGlyphStretch = scale; } 96 #endif 97 98 bool allowTabs() const { return m_allowTabs; } 99 float xPos() const { return m_xpos; } 100 float expansion() const { return m_expansion; } 101 bool allowsLeadingExpansion() const { return m_expansionBehavior & AllowLeadingExpansion; } 102 bool allowsTrailingExpansion() const { return m_expansionBehavior & AllowTrailingExpansion; } 103 bool rtl() const { return m_rtl; } 104 bool ltr() const { return !m_rtl; } 105 bool directionalOverride() const { return m_directionalOverride; } 106 bool spacingDisabled() const { return m_disableSpacing; } 107 108 void disableSpacing() { m_disableSpacing = true; } 109 void setRTL(bool b) { m_rtl = b; } 110 void setDirectionalOverride(bool override) { m_directionalOverride = override; } 111 112 #if ENABLE(SVG_FONTS) 113 RenderObject* referencingRenderObject() const { return m_referencingRenderObject; } 114 void setReferencingRenderObject(RenderObject* object) { m_referencingRenderObject = object; } 115 116 RenderSVGResource* activePaintingResource() const { return m_activePaintingResource; } 117 void setActivePaintingResource(RenderSVGResource* object) { m_activePaintingResource = object; } 118 #endif 119 120 private: 121 const UChar* m_characters; 122 int m_len; 123 124 // m_xpos is the x position relative to the left start of the text line, not relative to the left 125 // start of the containing block. In the case of right alignment or center alignment, left start of 126 // the text line is not the same as left start of the containing block. 127 float m_xpos; 128 float m_expansion; 129 ExpansionBehavior m_expansionBehavior; 130 #if ENABLE(SVG) 131 float m_horizontalGlyphStretch; 132 #endif 133 bool m_allowTabs; 134 bool m_rtl; 135 bool m_directionalOverride; 136 bool m_disableSpacing; 137 138 #if ENABLE(SVG_FONTS) 139 RenderObject* m_referencingRenderObject; 140 RenderSVGResource* m_activePaintingResource; 141 #endif 142 }; 143 144 } 145 146 #endif 147