~ubuntu-branches/ubuntu/maverick/scribus-ng/maverick-backports

« back to all changes in this revision

Viewing changes to scribus/styles/charstyle.h

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2007-08-11 17:41:51 UTC
  • mfrom: (0.1.1 upstream) (4.1.2 feisty)
  • Revision ID: james.westby@ubuntu.com-20070811174151-tmkgjvjuc0mtk8ul
Tags: 1.3.4.dfsg+svn20071115-1
* Upstream svn update (Closes: #447480, #448949).
* debian/NEWS: Added a note for users wanting stable Scribus to switch to
  the "scribus" package (Closes: #427638).
* debian/watch: Updated the watch regex to properly track sourceforge
  releases for this branch (Closes: #449700).

Show diffs side-by-side

added added

removed removed

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