00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef CHARSTYLE_H
00017 #define CHARSTYLE_H
00018
00019
00020 #include "style.h"
00021
00022 class ResourceCollection;
00023
00024 enum StyleFlagValue {
00025 ScStyle_Default = 0,
00026 ScStyle_Superscript = 1,
00027 ScStyle_Subscript = 2,
00028 ScStyle_Outline = 4,
00029 ScStyle_Underline = 8,
00030 ScStyle_Strikethrough = 16,
00031 ScStyle_AllCaps = 32,
00032 ScStyle_SmallCaps = 64,
00033 ScStyle_HyphenationPossible=128,
00034 ScStyle_Shadowed = 256,
00035 ScStyle_UnderlineWords= 512,
00036 ScStyle_Reserved01 = 1024,
00037 ScStyle_DropCap = 2048,
00038 ScStyle_SuppressSpace = 4096,
00039 ScStyle_SmartHyphenVisible=8192,
00040 ScStyle_StartOfLine = 16384,
00041 ScStyle_UserStyles = 1919,
00042 ScStyle_None = 65535
00043 };
00044
00045 class SCRIBUS_API StyleFlag
00046 {
00047 public:
00048
00049 StyleFlagValue value;
00050
00051 StyleFlag(void) { value = ScStyle_Default; }
00052 StyleFlag(StyleFlagValue val) { value = val; }
00053 StyleFlag(int val) { value = static_cast<StyleFlagValue>(val); }
00054
00055 operator StyleFlagValue() const { return value; }
00056
00057 QStringList featureList() const;
00058
00059 StyleFlag& operator= (StyleFlagValue val) { value = val; return *this;}
00060 StyleFlag& operator&= (const StyleFlag& right);
00061 StyleFlag& operator|= (const StyleFlag& right);
00062 StyleFlag operator& (const StyleFlag& right);
00063 StyleFlag operator& (int right);
00064 StyleFlag operator| (const StyleFlag& right);
00065 StyleFlag operator^ (const StyleFlag& right);
00066 StyleFlag operator^ (int right);
00067 StyleFlag operator~ ();
00068
00069 bool operator== (const StyleFlag& right) const;
00070 bool operator== (const StyleFlagValue right) const;
00071 bool operator== (int right) const;
00072 bool operator!= (const StyleFlag& right) const;
00073 bool operator!= (const StyleFlagValue right) const;
00074 };
00075
00076 class SCRIBUS_API CharStyle : public Style {
00077 public:
00078
00079 static const QString INHERIT;
00080 static const QString BOLD;
00081 static const QString ITALIC;
00082 static const QString UNDERLINE;
00083 static const QString UNDERLINEWORDS;
00084 static const QString STRIKETHROUGH;
00085 static const QString SUPERSCRIPT;
00086 static const QString SUBSCRIPT;
00087 static const QString OUTLINE;
00088 static const QString SHADOWED;
00089 static const QString ALLCAPS;
00090 static const QString SMALLCAPS;
00091
00092 CharStyle() : Style() {
00093 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00094 m_##attr_NAME = attr_DEFAULT; \
00095 inh_##attr_NAME = true;
00096 #include "charstyle.attrdefs.cxx"
00097 #undef ATTRDEF
00098 };
00099
00100 CharStyle(const ScFace& font, int size, StyleFlag style = ScStyle_Default) : Style() {
00101 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00102 m_##attr_NAME = attr_DEFAULT; \
00103 inh_##attr_NAME = true;
00104 #include "charstyle.attrdefs.cxx"
00105 #undef ATTRDEF
00106 setFont(font);
00107 setFontSize(size);
00108 setEffects(style);
00109 };
00110
00111 CharStyle(const CharStyle & other);
00112
00113 CharStyle & operator=(const CharStyle & other);
00114
00115 static const Xml_string saxxDefaultElem;
00116 static void desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
00117
00118 virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
00119 virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
00120
00121
00122 void getNamedResources(ResourceCollection& lists) const;
00123 void replaceNamedResources(ResourceCollection& newNames);
00124
00125 QString displayName() const;
00126
00127 void update(const StyleContext * b);
00128
00131 void updateFeatures();
00132
00133 bool equiv(const Style& other) const;
00134
00135 void applyCharStyle(const CharStyle & other);
00136 void eraseCharStyle(const CharStyle & other);
00137 void setStyle(const CharStyle & other);
00138 void erase() { eraseCharStyle(*this); }
00139
00140 QString asString() const;
00141
00143 const StyleFlag effects() const { validate(); return m_Effects; }
00144 void setEffects(StyleFlag flags) { m_Effects = flags; }
00145
00146
00149 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00150 attr_TYPE attr_GETTER() const { validate(); return m_##attr_NAME; }
00151 #include "charstyle.attrdefs.cxx"
00152 #undef ATTRDEF
00153
00156 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00157 void set##attr_NAME(attr_TYPE v) { m_##attr_NAME = v; inh_##attr_NAME = false; }
00158 #include "charstyle.attrdefs.cxx"
00159 #undef ATTRDEF
00160
00163 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00164 void reset##attr_NAME() { m_##attr_NAME = attr_DEFAULT; inh_##attr_NAME = true; }
00165 #include "charstyle.attrdefs.cxx"
00166 #undef ATTRDEF
00167
00169 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00170 bool isInh##attr_NAME() const { return inh_##attr_NAME; }
00171 #include "charstyle.attrdefs.cxx"
00172 #undef ATTRDEF
00173
00174
00176 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00177 bool isDef##attr_NAME() const { \
00178 if ( !inh_##attr_NAME ) return true; \
00179 const CharStyle * par = dynamic_cast<const CharStyle*>(parentStyle()); \
00180 return par && par->isDef##attr_NAME(); \
00181 }
00182 #include "charstyle.attrdefs.cxx"
00183 #undef ATTRDEF
00184
00185
00186 private:
00187
00188 void runFeatures(const QStringList& featurelist, const CharStyle* parent);
00189
00190 StyleFlag m_Effects;
00191
00192
00193 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00194 attr_TYPE m_##attr_NAME; \
00195 bool inh_##attr_NAME;
00196 #include "charstyle.attrdefs.cxx"
00197 #undef ATTRDEF
00198 };
00199
00200
00201 inline CharStyle & CharStyle::operator=(const CharStyle & other)
00202 {
00203 static_cast<Style&>(*this) = static_cast<const Style&>(other);
00204 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00205 m_##attr_NAME = other.m_##attr_NAME; \
00206 inh_##attr_NAME = other.inh_##attr_NAME;
00207 #include "charstyle.attrdefs.cxx"
00208 #undef ATTRDEF
00209 m_Effects = other.m_Effects;
00210
00211 m_contextversion = -1;
00212 return *this;
00213 }
00214
00215 inline CharStyle::CharStyle(const CharStyle & other) : Style(other)
00216 {
00217 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00218 m_##attr_NAME = other.m_##attr_NAME; \
00219 inh_##attr_NAME = other.inh_##attr_NAME;
00220 #include "charstyle.attrdefs.cxx"
00221 #undef ATTRDEF
00222 m_Effects = other.m_Effects;
00223
00224 m_contextversion = -1;
00225 }
00226
00227 #endif