Subversion Repositories Scribus

Rev

Rev 16863 | Rev 21237 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6443 avox 1
/*
2
 For general Scribus (>=1.3.2) copyright and licensing information please refer
3
 to the COPYING file provided with the program. Following this notice may exist
4
 a copyright and/or license notice that predates the release of Scribus 1.3.2
5
 for which a new license (GPL+exception) is in place.
6
 */
7
/***************************************************************************
8
*                                                                         *
9
*   This program is free software; you can redistribute it and/or modify  *
10
*   it under the terms of the GNU General Public License as published by  *
11
*   the Free Software Foundation; either version 2 of the License, or     *
12
*   (at your option) any later version.                                   *
13
*                                                                         *
14
***************************************************************************/
15
 
8337 avox 16
#ifndef CHARSTYLE_H
17
#define CHARSTYLE_H
6443 avox 18
 
19
 
8337 avox 20
#include "style.h"
6443 avox 21
 
8455 avox 22
class ResourceCollection;
23
 
7456 jghali 24
enum StyleFlagValue {
18524 avox 25
    ScStyle_None          = 0,
26
    ScStyle_Default       = 0,
6443 avox 27
    ScStyle_Superscript   = 1,
28
    ScStyle_Subscript     = 2,
29
    ScStyle_Outline       = 4,
30
    ScStyle_Underline     = 8,
31
    ScStyle_Strikethrough = 16,
32
    ScStyle_AllCaps       = 32,
33
    ScStyle_SmallCaps     = 64,
15009 jghali 34
    ScStyle_HyphenationPossible=128, //Hyphenation possible here (Soft Hyphen)
6443 avox 35
    ScStyle_Shadowed      = 256,
36
    ScStyle_UnderlineWords= 512,
18524 avox 37
        xScStyle_Reserved01    = 1024, //free, not used in the moment
38
        xScStyle_DropCap       = 2048,
39
        xScStyle_SuppressSpace = 4096,//internal use in PageItem (Suppresses spaces when in Block alignment)
40
        xScStyle_SoftHyphenVisible=8192, //Soft Hyphen visible at line end
41
        xScStyle_StartOfLine   = 16384,
9645 avox 42
        ScStyle_UserStyles    = 1919, // == 1024 + 512 + 256 + 64 + 32 + 16 + 8 + 4 + 2 + 1
18524 avox 43
    ScStyle_NonUserStyles = 30848, // == 128 + 2048 + 4096 + 8192 + 16384
44
    ScStyle_All           = 65535
6443 avox 45
};
46
 
7456 jghali 47
class SCRIBUS_API StyleFlag
48
{
49
public:
6443 avox 50
 
7456 jghali 51
        StyleFlagValue value;
6443 avox 52
 
7456 jghali 53
        StyleFlag(void) { value = ScStyle_Default; }
54
        StyleFlag(StyleFlagValue val) { value = val; }
55
        StyleFlag(int val) { value = static_cast<StyleFlagValue>(val); }
6443 avox 56
 
7456 jghali 57
        operator StyleFlagValue() const { return value; }
6443 avox 58
 
9607 avox 59
        QStringList featureList() const;
60
 
7456 jghali 61
        StyleFlag& operator=  (StyleFlagValue val) { value = val; return *this;}
62
        StyleFlag& operator&= (const StyleFlag& right);
63
        StyleFlag& operator|= (const StyleFlag& right);
64
        StyleFlag  operator&  (const StyleFlag& right);
65
        StyleFlag  operator&  (int right);
66
        StyleFlag  operator|  (const StyleFlag& right);
67
        StyleFlag  operator^  (const StyleFlag& right);
68
        StyleFlag  operator^  (int right);
69
        StyleFlag  operator~  ();
6443 avox 70
 
7456 jghali 71
        bool operator== (const StyleFlag& right) const;
72
        bool operator== (const StyleFlagValue right) const;
73
        bool operator== (int right) const;
74
        bool operator!= (const StyleFlag& right) const;
75
        bool operator!= (const StyleFlagValue right) const;
76
};
6443 avox 77
 
7005 avox 78
class SCRIBUS_API CharStyle : public Style {
6443 avox 79
public:
80
 
9607 avox 81
        static const QString INHERIT;
82
        static const QString BOLD;
83
        static const QString ITALIC;
84
        static const QString UNDERLINE;
85
        static const QString UNDERLINEWORDS;
86
        static const QString STRIKETHROUGH;
87
        static const QString SUPERSCRIPT;
88
        static const QString SUBSCRIPT;
89
        static const QString OUTLINE;
90
        static const QString SHADOWED;
91
        static const QString ALLCAPS;
92
        static const QString SMALLCAPS;
93
 
6443 avox 94
    CharStyle() : Style() {
95
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
96
                m_##attr_NAME = attr_DEFAULT; \
97
                inh_##attr_NAME = true;
98
#include "charstyle.attrdefs.cxx"
99
#undef ATTRDEF
12283 cbradney 100
                m_isDefaultStyle=false;
6443 avox 101
    };
102
 
103
    CharStyle(const ScFace& font, int size, StyleFlag style = ScStyle_Default) : Style() {
104
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
105
                m_##attr_NAME = attr_DEFAULT; \
106
                inh_##attr_NAME = true;
107
#include "charstyle.attrdefs.cxx"
108
#undef ATTRDEF
12283 cbradney 109
                m_isDefaultStyle=false;
8337 avox 110
                setFont(font);
111
        setFontSize(size);
112
                setEffects(style);
6443 avox 113
    };
114
 
115
        CharStyle(const CharStyle & other);
116
 
117
        CharStyle & operator=(const CharStyle & other);
118
 
8266 avox 119
        static const Xml_string saxxDefaultElem;
8834 cbradney 120
        static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
8193 avox 121
 
8800 jghali 122
        virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
16863 craig 123
        virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
8266 avox 124
 
8455 avox 125
 
126
        void getNamedResources(ResourceCollection& lists) const;
127
        void replaceNamedResources(ResourceCollection& newNames);
128
 
6443 avox 129
        QString displayName() const;
130
 
8134 avox 131
        void update(const StyleContext * b);
6443 avox 132
 
9607 avox 133
        /** This method may alter any of the attributes depending on the value of 'features'.
134
                Used for font effects */
135
        void updateFeatures();
136
 
6443 avox 137
        bool equiv(const Style& other) const;  
138
 
139
        void applyCharStyle(const CharStyle & other);
140
        void eraseCharStyle(const CharStyle & other);
7242 avox 141
        void setStyle(const CharStyle & other);
6443 avox 142
        void erase() { eraseCharStyle(*this); }
13290 jghali 143
        void eraseDirectFormatting();
6443 avox 144
 
145
        QString asString() const;
146
 
9607 avox 147
        /** This property will be evaluated at runtime and is not stored. See 'updateFeatures()' */
148
        const StyleFlag effects() const { validate(); return m_Effects; }
149
        void setEffects(StyleFlag flags) { m_Effects = flags; }
150
 
151
 
6443 avox 152
        /** getter: validates and returns the attribute's value */
153
 
154
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
14455 cbradney 155
        const attr_TYPE &attr_GETTER() const { validate(); return m_##attr_NAME; }
6443 avox 156
#include "charstyle.attrdefs.cxx"
157
#undef ATTRDEF
158
 
159
        /** setter: sets the attribute's value and clears inherited flag */
160
 
161
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
162
        void set##attr_NAME(attr_TYPE v) { m_##attr_NAME = v; inh_##attr_NAME = false; }
163
#include "charstyle.attrdefs.cxx"
164
#undef ATTRDEF
165
 
166
        /** setter: resets the attribute's value and sets inherited flag */
167
 
168
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
169
        void reset##attr_NAME() { m_##attr_NAME = attr_DEFAULT; inh_##attr_NAME = true; }
170
#include "charstyle.attrdefs.cxx"
171
#undef ATTRDEF
172
 
6733 avox 173
        /** isInherited: returns true if the attribute is inherited */
6443 avox 174
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 175
        bool isInh##attr_NAME() const { return inh_##attr_NAME; }
6443 avox 176
#include "charstyle.attrdefs.cxx"
177
#undef ATTRDEF
178
 
179
 
6733 avox 180
        /** isDefined: returns true if the attribute is defined in this style or any parent */
181
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
182
        bool isDef##attr_NAME() const { \
6805 avox 183
                if ( !inh_##attr_NAME ) return true; \
6733 avox 184
                const CharStyle * par = dynamic_cast<const CharStyle*>(parentStyle()); \
185
                return par && par->isDef##attr_NAME(); \
186
        }
187
#include "charstyle.attrdefs.cxx"
188
#undef ATTRDEF
189
 
190
 
6443 avox 191
private:
192
 
9607 avox 193
        void runFeatures(const QStringList& featurelist, const CharStyle* parent);
194
 
195
        StyleFlag m_Effects;
6443 avox 196
        // member declarations:
197
 
198
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
199
        attr_TYPE m_##attr_NAME; \
200
        bool inh_##attr_NAME;
201
#include "charstyle.attrdefs.cxx"
202
#undef ATTRDEF
203
};
204
 
205
 
206
inline CharStyle & CharStyle::operator=(const CharStyle & other)
207
{
208
        static_cast<Style&>(*this) = static_cast<const Style&>(other);
209
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
210
        m_##attr_NAME = other.m_##attr_NAME; \
211
        inh_##attr_NAME = other.inh_##attr_NAME;
212
#include "charstyle.attrdefs.cxx"
213
#undef ATTRDEF
9607 avox 214
        m_Effects = other.m_Effects;
8134 avox 215
//      m_context = NULL;
216
        m_contextversion = -1;
6443 avox 217
        return *this;
218
}
219
 
220
inline CharStyle::CharStyle(const CharStyle & other) : Style(other)
221
{
222
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
223
        m_##attr_NAME = other.m_##attr_NAME; \
224
        inh_##attr_NAME = other.inh_##attr_NAME;
225
#include "charstyle.attrdefs.cxx"
226
#undef ATTRDEF
9607 avox 227
        m_Effects = other.m_Effects;
8134 avox 228
//      m_context = NULL;
229
        m_contextversion = -1;
6443 avox 230
}
231
 
8337 avox 232
#endif