Subversion Repositories Scribus

Rev

Rev 8266 | Rev 8347 | 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
 
7456 jghali 22
enum StyleFlagValue {
6443 avox 23
        ScStyle_Default       = 0,
24
    ScStyle_Superscript   = 1,
25
    ScStyle_Subscript     = 2,
26
    ScStyle_Outline       = 4,
27
    ScStyle_Underline     = 8,
28
    ScStyle_Strikethrough = 16,
29
    ScStyle_AllCaps       = 32,
30
    ScStyle_SmallCaps     = 64,
31
    ScStyle_HyphenationPossible=128, //Hyphenation possible here (Smart Hyphen)
32
    ScStyle_Shadowed      = 256,
33
    ScStyle_UnderlineWords= 512,
34
    ScStyle_Reserved01    = 1024, //free, not used in the moment
35
    ScStyle_DropCap       = 2048,
36
    ScStyle_SuppressSpace = 4096,//internal use in PageItem (Suppresses spaces when in Block alignment)
37
    ScStyle_SmartHyphenVisible=8192, //Smart Hyphen visible at line end
38
    ScStyle_StartOfLine   = 16384,
7017 avox 39
        ScStyle_UserStyles    = 2047, // 1919, // == 1024 + 512 + 256 + 64 + 32 + 16 + 8 + 4 + 2 + 1
6443 avox 40
        ScStyle_None          = 65535
41
};
42
 
7456 jghali 43
class SCRIBUS_API StyleFlag
44
{
45
public:
6443 avox 46
 
7456 jghali 47
        StyleFlagValue value;
6443 avox 48
 
7456 jghali 49
        StyleFlag(void) { value = ScStyle_Default; }
50
        StyleFlag(StyleFlagValue val) { value = val; }
51
        StyleFlag(int val) { value = static_cast<StyleFlagValue>(val); }
6443 avox 52
 
7456 jghali 53
        operator StyleFlagValue() const { return value; }
6443 avox 54
 
7456 jghali 55
        StyleFlag& operator=  (StyleFlagValue val) { value = val; return *this;}
56
        StyleFlag& operator&= (const StyleFlag& right);
57
        StyleFlag& operator|= (const StyleFlag& right);
58
        StyleFlag  operator&  (const StyleFlag& right);
59
        StyleFlag  operator&  (int right);
60
        StyleFlag  operator|  (const StyleFlag& right);
61
        StyleFlag  operator^  (const StyleFlag& right);
62
        StyleFlag  operator^  (int right);
63
        StyleFlag  operator~  ();
6443 avox 64
 
7456 jghali 65
        bool operator== (const StyleFlag& right) const;
66
        bool operator== (const StyleFlagValue right) const;
67
        bool operator== (int right) const;
68
        bool operator!= (const StyleFlag& right) const;
69
        bool operator!= (const StyleFlagValue right) const;
70
};
6443 avox 71
 
7005 avox 72
class SCRIBUS_API CharStyle : public Style {
6443 avox 73
public:
74
 
75
 
76
    CharStyle() : Style() {
77
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
78
                m_##attr_NAME = attr_DEFAULT; \
79
                inh_##attr_NAME = true;
80
#include "charstyle.attrdefs.cxx"
81
#undef ATTRDEF
82
    };
83
 
84
    CharStyle(const ScFace& font, int size, StyleFlag style = ScStyle_Default) : Style() {
85
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
86
                m_##attr_NAME = attr_DEFAULT; \
87
                inh_##attr_NAME = true;
88
#include "charstyle.attrdefs.cxx"
89
#undef ATTRDEF
8337 avox 90
                setFont(font);
91
        setFontSize(size);
92
                setEffects(style);
6443 avox 93
    };
94
 
95
        CharStyle(const CharStyle & other);
96
 
97
        CharStyle & operator=(const CharStyle & other);
98
 
8266 avox 99
        static const Xml_string saxxDefaultElem;
100
        static void  desaxeRules(Xml_string prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
8193 avox 101
 
8266 avox 102
        virtual void saxx(SaxHandler& handler, Xml_string elemtag) const;
103
        virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
104
 
6443 avox 105
        QString displayName() const;
106
 
8134 avox 107
        void update(const StyleContext * b);
6443 avox 108
 
109
        bool equiv(const Style& other) const;  
110
 
111
        void applyCharStyle(const CharStyle & other);
112
        void eraseCharStyle(const CharStyle & other);
7242 avox 113
        void setStyle(const CharStyle & other);
6443 avox 114
        void erase() { eraseCharStyle(*this); }
115
 
116
        QString asString() const;
117
 
118
        /** getter: validates and returns the attribute's value */
119
 
120
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
121
        const attr_TYPE attr_GETTER() const { validate(); return m_##attr_NAME; }
122
#include "charstyle.attrdefs.cxx"
123
#undef ATTRDEF
124
 
125
        /** setter: sets the attribute's value and clears inherited flag */
126
 
127
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
128
        void set##attr_NAME(attr_TYPE v) { m_##attr_NAME = v; inh_##attr_NAME = false; }
129
#include "charstyle.attrdefs.cxx"
130
#undef ATTRDEF
131
 
132
        /** setter: resets the attribute's value and sets inherited flag */
133
 
134
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
135
        void reset##attr_NAME() { m_##attr_NAME = attr_DEFAULT; inh_##attr_NAME = true; }
136
#include "charstyle.attrdefs.cxx"
137
#undef ATTRDEF
138
 
6733 avox 139
        /** isInherited: returns true if the attribute is inherited */
6443 avox 140
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 141
        bool isInh##attr_NAME() const { return inh_##attr_NAME; }
6443 avox 142
#include "charstyle.attrdefs.cxx"
143
#undef ATTRDEF
144
 
145
 
6733 avox 146
        /** isDefined: returns true if the attribute is defined in this style or any parent */
147
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
148
        bool isDef##attr_NAME() const { \
6805 avox 149
                if ( !inh_##attr_NAME ) return true; \
6733 avox 150
                const CharStyle * par = dynamic_cast<const CharStyle*>(parentStyle()); \
151
                return par && par->isDef##attr_NAME(); \
152
        }
153
#include "charstyle.attrdefs.cxx"
154
#undef ATTRDEF
155
 
156
 
6443 avox 157
private:
158
 
159
        // member declarations:
160
 
161
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
162
        attr_TYPE m_##attr_NAME; \
163
        bool inh_##attr_NAME;
164
#include "charstyle.attrdefs.cxx"
165
#undef ATTRDEF
166
};
167
 
168
 
169
inline CharStyle & CharStyle::operator=(const CharStyle & other)
170
{
171
        static_cast<Style&>(*this) = static_cast<const Style&>(other);
172
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
173
        m_##attr_NAME = other.m_##attr_NAME; \
174
        inh_##attr_NAME = other.inh_##attr_NAME;
175
#include "charstyle.attrdefs.cxx"
176
#undef ATTRDEF
8134 avox 177
//      m_context = NULL;
178
        m_contextversion = -1;
6443 avox 179
        return *this;
180
}
181
 
182
inline CharStyle::CharStyle(const CharStyle & other) : Style(other)
183
{
184
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
185
        m_##attr_NAME = other.m_##attr_NAME; \
186
        inh_##attr_NAME = other.inh_##attr_NAME;
187
#include "charstyle.attrdefs.cxx"
188
#undef ATTRDEF
8134 avox 189
//      m_context = NULL;
190
        m_contextversion = -1;
6443 avox 191
}
192
 
8337 avox 193
#endif