Subversion Repositories Scribus

Rev

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