Subversion Repositories Scribus

Rev

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