Subversion Repositories Scribus

Rev

Rev 21378 | Rev 21816 | 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
21563 jghali 43
        ScStyle_NonUserStyles = 30848, // == 128 + 2048 + 4096 + 8192 + 16384
44
        ScStyle_RunBreakingStyles = 99,   // == 1 + 2 + 32 + 64
18524 avox 45
    ScStyle_All           = 65535
6443 avox 46
};
47
 
7456 jghali 48
class SCRIBUS_API StyleFlag
49
{
50
public:
6443 avox 51
 
7456 jghali 52
        StyleFlagValue value;
6443 avox 53
 
7456 jghali 54
        StyleFlag(void) { value = ScStyle_Default; }
55
        StyleFlag(StyleFlagValue val) { value = val; }
56
        StyleFlag(int val) { value = static_cast<StyleFlagValue>(val); }
6443 avox 57
 
7456 jghali 58
        operator StyleFlagValue() const { return value; }
6443 avox 59
 
9607 avox 60
        QStringList featureList() const;
21563 jghali 61
 
7456 jghali 62
        StyleFlag& operator=  (StyleFlagValue val) { value = val; return *this;}
63
        StyleFlag& operator&= (const StyleFlag& right);
64
        StyleFlag& operator|= (const StyleFlag& right);
65
        StyleFlag  operator&  (const StyleFlag& right);
66
        StyleFlag  operator&  (int right);
67
        StyleFlag  operator|  (const StyleFlag& right);
68
        StyleFlag  operator^  (const StyleFlag& right);
69
        StyleFlag  operator^  (int right);
70
        StyleFlag  operator~  ();
6443 avox 71
 
21563 jghali 72
        bool equivForShaping(const StyleFlag& right) const;
7456 jghali 73
        bool operator== (const StyleFlag& right) const;
74
        bool operator== (const StyleFlagValue right) const;
75
        bool operator== (int right) const;
76
        bool operator!= (const StyleFlag& right) const;
77
        bool operator!= (const StyleFlagValue right) const;
78
};
6443 avox 79
 
7005 avox 80
class SCRIBUS_API CharStyle : public Style {
6443 avox 81
public:
82
 
9607 avox 83
        static const QString INHERIT;
84
        static const QString BOLD;
85
        static const QString ITALIC;
86
        static const QString UNDERLINE;
87
        static const QString UNDERLINEWORDS;
88
        static const QString STRIKETHROUGH;
89
        static const QString SUPERSCRIPT;
90
        static const QString SUBSCRIPT;
91
        static const QString OUTLINE;
92
        static const QString SHADOWED;
93
        static const QString ALLCAPS;
94
        static const QString SMALLCAPS;
95
 
6443 avox 96
    CharStyle() : Style() {
21563 jghali 97
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6443 avox 98
                m_##attr_NAME = attr_DEFAULT; \
99
                inh_##attr_NAME = true;
100
#include "charstyle.attrdefs.cxx"
101
#undef ATTRDEF
12283 cbradney 102
                m_isDefaultStyle=false;
21378 craig 103
        }
6443 avox 104
 
105
    CharStyle(const ScFace& font, int size, StyleFlag style = ScStyle_Default) : Style() {
21563 jghali 106
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6443 avox 107
                m_##attr_NAME = attr_DEFAULT; \
108
                inh_##attr_NAME = true;
109
#include "charstyle.attrdefs.cxx"
110
#undef ATTRDEF
12283 cbradney 111
                m_isDefaultStyle=false;
8337 avox 112
                setFont(font);
113
        setFontSize(size);
114
                setEffects(style);
21378 craig 115
        }
6443 avox 116
 
117
        CharStyle(const CharStyle & other);
118
 
119
        CharStyle & operator=(const CharStyle & other);
120
 
8266 avox 121
        static const Xml_string saxxDefaultElem;
8834 cbradney 122
        static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
8193 avox 123
 
8800 jghali 124
        virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
16863 craig 125
        virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
8266 avox 126
 
8455 avox 127
 
128
        void getNamedResources(ResourceCollection& lists) const;
129
        void replaceNamedResources(ResourceCollection& newNames);
130
 
6443 avox 131
        QString displayName() const;
132
 
8134 avox 133
        void update(const StyleContext * b);
6443 avox 134
 
9607 avox 135
        /** This method may alter any of the attributes depending on the value of 'features'.
136
                Used for font effects */
137
        void updateFeatures();
138
 
6443 avox 139
        bool equiv(const Style& other) const;  
21563 jghali 140
        bool equivForShaping(const CharStyle &other) const;
141
 
6443 avox 142
        void applyCharStyle(const CharStyle & other);
143
        void eraseCharStyle(const CharStyle & other);
7242 avox 144
        void setStyle(const CharStyle & other);
6443 avox 145
        void erase() { eraseCharStyle(*this); }
13290 jghali 146
        void eraseDirectFormatting();
6443 avox 147
 
148
        QString asString() const;
149
 
9607 avox 150
        /** This property will be evaluated at runtime and is not stored. See 'updateFeatures()' */
21237 jghali 151
        const StyleFlag& effects() const { validate(); return m_Effects; }
9607 avox 152
        void setEffects(StyleFlag flags) { m_Effects = flags; }
153
 
154
 
6443 avox 155
        /** getter: validates and returns the attribute's value */
156
 
21563 jghali 157
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
14455 cbradney 158
        const attr_TYPE &attr_GETTER() const { validate(); return m_##attr_NAME; }
6443 avox 159
#include "charstyle.attrdefs.cxx"
160
#undef ATTRDEF
161
 
162
        /** setter: sets the attribute's value and clears inherited flag */
163
 
21563 jghali 164
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6443 avox 165
        void set##attr_NAME(attr_TYPE v) { m_##attr_NAME = v; inh_##attr_NAME = false; }
166
#include "charstyle.attrdefs.cxx"
167
#undef ATTRDEF
168
 
169
        /** setter: resets the attribute's value and sets inherited flag */
170
 
21563 jghali 171
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6443 avox 172
        void reset##attr_NAME() { m_##attr_NAME = attr_DEFAULT; inh_##attr_NAME = true; }
173
#include "charstyle.attrdefs.cxx"
174
#undef ATTRDEF
175
 
6733 avox 176
        /** isInherited: returns true if the attribute is inherited */
21563 jghali 177
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6733 avox 178
        bool isInh##attr_NAME() const { return inh_##attr_NAME; }
6443 avox 179
#include "charstyle.attrdefs.cxx"
180
#undef ATTRDEF
181
 
182
 
6733 avox 183
        /** isDefined: returns true if the attribute is defined in this style or any parent */
21563 jghali 184
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6733 avox 185
        bool isDef##attr_NAME() const { \
6805 avox 186
                if ( !inh_##attr_NAME ) return true; \
6733 avox 187
                const CharStyle * par = dynamic_cast<const CharStyle*>(parentStyle()); \
188
                return par && par->isDef##attr_NAME(); \
189
        }
190
#include "charstyle.attrdefs.cxx"
191
#undef ATTRDEF
192
 
6443 avox 193
private:
194
 
9607 avox 195
        void runFeatures(const QStringList& featurelist, const CharStyle* parent);
196
 
197
        StyleFlag m_Effects;
6443 avox 198
        // member declarations:
199
 
21563 jghali 200
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6443 avox 201
        attr_TYPE m_##attr_NAME; \
202
        bool inh_##attr_NAME;
203
#include "charstyle.attrdefs.cxx"
204
#undef ATTRDEF
205
};
206
 
207
 
208
inline CharStyle & CharStyle::operator=(const CharStyle & other)
209
{
210
        static_cast<Style&>(*this) = static_cast<const Style&>(other);
21563 jghali 211
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6443 avox 212
        m_##attr_NAME = other.m_##attr_NAME; \
213
        inh_##attr_NAME = other.inh_##attr_NAME;
214
#include "charstyle.attrdefs.cxx"
215
#undef ATTRDEF
9607 avox 216
        m_Effects = other.m_Effects;
8134 avox 217
//      m_context = NULL;
218
        m_contextversion = -1;
6443 avox 219
        return *this;
220
}
221
 
222
inline CharStyle::CharStyle(const CharStyle & other) : Style(other)
223
{
21563 jghali 224
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT, attr_BREAKSHAPING) \
6443 avox 225
        m_##attr_NAME = other.m_##attr_NAME; \
226
        inh_##attr_NAME = other.inh_##attr_NAME;
227
#include "charstyle.attrdefs.cxx"
228
#undef ATTRDEF
9607 avox 229
        m_Effects = other.m_Effects;
8134 avox 230
//      m_context = NULL;
231
        m_contextversion = -1;
6443 avox 232
}
233
 
8337 avox 234
#endif