Subversion Repositories Scribus

Rev

Rev 8193 | Rev 8289 | 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
#include <qvaluelist.h>
10
#include <qobject.h>
11
#include "sctextstruct.h"
12
#include "scfonts.h"
6733 avox 13
#include "style.h"
8193 avox 14
#include "desaxe/saxiohelper.h"
8266 avox 15
#include "desaxe/simple_actions.h"
16
#include "prefsmanager.h"
6443 avox 17
 
7456 jghali 18
StyleFlag& StyleFlag::operator&= (const StyleFlag& right){        
19
        int result = static_cast<int>(value) & static_cast<int>(right.value);        
20
        value = static_cast<StyleFlagValue>(result);
21
        return *this;
6443 avox 22
}
23
 
7456 jghali 24
StyleFlag& StyleFlag::operator|= (const StyleFlag& right)
6443 avox 25
{
7456 jghali 26
        int result = static_cast<int>(value) | static_cast<int>(right.value);
27
        value = static_cast<StyleFlagValue>(result);
28
        return *this;
6443 avox 29
}
30
 
7456 jghali 31
StyleFlag StyleFlag::operator& (const StyleFlag& right)
6443 avox 32
{
7456 jghali 33
        int val = static_cast<int>(value) & static_cast<int>(right.value);
34
        StyleFlag result(static_cast<StyleFlagValue>(val));
35
        return result;
6443 avox 36
}
37
 
7456 jghali 38
StyleFlag StyleFlag::operator& (int right)
39
{
40
        int val = static_cast<int>(value) & right;
41
        StyleFlag result(static_cast<StyleFlagValue>(val));
42
        return result;
43
}
44
 
45
StyleFlag StyleFlag::operator| (const StyleFlag& right)
6443 avox 46
{        
7456 jghali 47
        int val = static_cast<int>(value) | static_cast<int>(right.value);
48
        StyleFlag result(static_cast<StyleFlagValue>(val));
49
        return result;
6443 avox 50
}
51
 
7456 jghali 52
StyleFlag StyleFlag::operator^ (const StyleFlag& right)
53
{
54
        int val = static_cast<int>(value) ^ static_cast<int>(right.value);
55
        StyleFlag result(static_cast<StyleFlagValue>(val));
56
        return result;
6443 avox 57
}
58
 
7456 jghali 59
StyleFlag StyleFlag::operator^  (int right)
6443 avox 60
{
7456 jghali 61
        int val = static_cast<int>(value) ^ right;
62
        StyleFlag result(static_cast<StyleFlagValue>(val));
63
        return result;
6443 avox 64
}
65
 
7456 jghali 66
StyleFlag StyleFlag::operator~ ()
67
{
68
        int val = ~ static_cast<int>(value);
69
        StyleFlag result(static_cast<StyleFlagValue>(val));
70
        return result;
71
}
72
 
73
bool StyleFlag::operator== (const StyleFlag& right) const
7017 avox 74
{        
7456 jghali 75
        int result = static_cast<int>( (value ^ right.value) & ScStyle_UserStyles);
76
        return (result == 0);
7017 avox 77
}
6443 avox 78
 
7456 jghali 79
bool StyleFlag::operator== (const StyleFlagValue right) const
7017 avox 80
{
7456 jghali 81
        int result = static_cast<int>( (value ^ right) & ScStyle_UserStyles);
82
        return (result == 0);
7017 avox 83
}
84
 
7456 jghali 85
bool StyleFlag::operator== (int right) const
86
{
87
        int result = static_cast<int>( (value ^ right) & ScStyle_UserStyles);
88
        return (result == 0);
89
}
90
 
91
bool StyleFlag::operator!= (const StyleFlag& right) const
92
{
93
        return !(*this==right);
94
}
95
 
96
bool StyleFlag::operator!= (const StyleFlagValue right) const
97
{
98
        return !(*this==right);
99
}
100
 
8193 avox 101
 
6443 avox 102
void CharStyle::applyCharStyle(const CharStyle & other)
103
{
104
        Style::applyStyle(other);
105
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
106
        if (! other.inh_##attr_NAME) \
107
                set##attr_NAME(other.m_##attr_NAME);
108
#include "charstyle.attrdefs.cxx"
109
#undef ATTRDEF
110
}
111
 
112
 
113
void CharStyle::eraseCharStyle(const CharStyle & other)
114
{
6805 avox 115
        other.validate();
6443 avox 116
        Style::eraseStyle(other);
117
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6936 avox 118
        if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
6443 avox 119
                reset##attr_NAME();
120
#include "charstyle.attrdefs.cxx"
121
#undef ATTRDEF
122
}
123
 
124
bool CharStyle::equiv(const Style & other) const
125
{
6805 avox 126
        other.validate();
6443 avox 127
        const CharStyle * oth = dynamic_cast<const CharStyle*> ( & other );
128
        return  oth &&
6733 avox 129
                parent() == oth->parent()
6443 avox 130
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 131
                && (inh_##attr_NAME == oth->inh_##attr_NAME) \
132
                && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
6443 avox 133
#include "charstyle.attrdefs.cxx"
134
#undef ATTRDEF
135
                ;      
136
}
137
 
138
 
139
QString CharStyle::displayName() const
140
{
8134 avox 141
        if ( hasName() || !hasParent() || ! m_context)
6443 avox 142
                return name();
143
//      else if ( inheritsAll() )
144
//              return parent()->displayName();
145
        else
146
                return parentStyle()->displayName() + "+";
147
}
148
 
149
 
150
 
151
QString CharStyle::asString() const
152
{
153
        QString result;
154
        if ( !inh_Font )
155
                result += QObject::tr("font %1 ").arg(font().scName());
156
        if ( !inh_FontSize )
157
                result += QObject::tr("size %1 ").arg(fontSize());
158
        if ( !inh_Effects )
159
                result += QObject::tr("+style ");
160
        if ( !inh_StrokeColor  ||  !inh_StrokeShade  ||  !inh_FillColor || !inh_FillShade )
161
                result += QObject::tr("+color ");
162
        if ( !inh_UnderlineWidth  ||  !inh_UnderlineOffset )
163
                result += underlineWidth() > 0 ? QObject::tr("+underline ") : QObject::tr("-underline ");
6733 avox 164
        if ( !inh_StrikethruWidth || !inh_StrikethruOffset )
6443 avox 165
                result += strikethruWidth() > 0 ? QObject::tr("+strikeout ") : QObject::tr("-strikeout ");
166
        if ( !inh_ShadowXOffset || !inh_ShadowYOffset )
6733 avox 167
                result += shadowXOffset() != 0 || shadowYOffset() != 0 ? QObject::tr("+shadow ") : QObject::tr("-shadow ");
6443 avox 168
        if ( !inh_OutlineWidth )
169
                result += outlineWidth() > 0 ? QObject::tr("+outline ") : QObject::tr("-outline ");
170
        if ( !inh_Tracking )
171
                result += tracking() > 0 ? QObject::tr("+tracking %1 ").arg(tracking()) : QObject::tr("-tracking ");
172
        if ( !inh_BaselineOffset )
173
                result += QObject::tr("+baseline %1 ").arg(baselineOffset());
174
        if ( !inh_ScaleH || !inh_ScaleV )
175
                result += QObject::tr("+stretch ");
176
        if ( hasParent() )
177
                result += QObject::tr("parent= %1").arg(parent());
178
        return result.stripWhiteSpace();
179
}
180
 
181
 
8134 avox 182
void CharStyle::update(const StyleContext* context)
6443 avox 183
{
8134 avox 184
        Style::update(context);
6443 avox 185
        const CharStyle * oth = dynamic_cast<const CharStyle*> ( parentStyle() );
186
        if (oth) {
187
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
188
                if (inh_##attr_NAME) \
6733 avox 189
                        m_##attr_NAME = oth->attr_GETTER();
6443 avox 190
#include "charstyle.attrdefs.cxx"
191
#undef ATTRDEF
192
        }
193
}
194
 
195
 
7242 avox 196
void CharStyle::setStyle(const CharStyle& other)
197
{
198
        other.validate();
7993 avox 199
        setParent(other.parent());
7242 avox 200
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
7993 avox 201
        inh_##attr_NAME = other.inh_##attr_NAME; \
7242 avox 202
        m_##attr_NAME = other.m_##attr_NAME;
203
#include "charstyle.attrdefs.cxx"
204
#undef ATTRDEF
205
}
6443 avox 206
 
207
 
7242 avox 208
 
6443 avox 209
/*
210
bool CharStyle::definesAll() const
211
{
212
        return definesLineSpacing() &&
213
        definesLeftMargin() &&
214
        definesRightMargin() &&
215
        definesFirstIndent() &&
216
        definesAlignment() &&
217
        definesGapBefore()  &&
218
        definesLineSpacingMode()  &&
219
        definesGapAfter()  &&
220
        definesHasDropCap() &&
221
        definesDropCapOffset() &&
222
        definesDropCapLines() &&
223
        definesUseBaselineGrid() &&
224
        charStyle().definesAll() ;
225
 
226
}
227
 
7242 avox 228
// equiv. to "*this == CharStyle()"
6443 avox 229
bool CharStyle::inheritsAll() const
230
{
231
        return inheritsLineSpacing() &&
232
        inheritsLeftMargin() &&
233
        inheritsRightMargin() &&
234
        inheritsFirstIndent() &&
235
        inheritsAlignment() &&
236
        inheritsGapBefore()  &&
237
        inheritsLineSpacingMode()  &&
238
        inheritsGapAfter()  &&
239
        inheritsHasDropCap() &&
240
        inheritsDropCapOffset() &&
241
        inheritsDropCapLines() &&
242
        inheritsUseBaselineGrid() &&
243
        charStyle().inheritsAll() ;
244
}
245
*/
246
 
8266 avox 247
 
248
Xml_string toXMLString(StyleFlag val)
249
{
250
        return toXMLString(static_cast<unsigned int>(val & ScStyle_UserStyles));
251
}
252
 
253
 
254
void CharStyle::saxx(SaxHandler& handler, Xml_string elemtag) const
255
{
256
        Xml_attr att;
257
        if (!name().isEmpty())
258
                att.insert("name", name());
259
        if (!parent().isEmpty())
260
                att.insert("parent", parent());
261
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
262
        if (!inh_##attr_NAME) \
263
                att.insert(# attr_NAME, toXMLString(m_##attr_NAME));
264
#include "charstyle.attrdefs.cxx"
265
#undef ATTRDEF
266
        handler.beginEnd(elemtag, att);
267
}
268
 
269
 
270
 
271
template<>
272
StyleFlag parse(Xml_string str)
273
{
274
        return StyleFlag(parseInt(str));
275
}
276
 
277
template<>
278
ScFace parse(Xml_string str)
279
{
280
        // FIXME: enable font substitution here
281
        return PrefsManager::instance()->appPrefs.AvailFonts[str];
282
}
283
 
284
 
285
using namespace desaxe;
286
 
287
 
288
const Xml_string CharStyle::saxxDefaultElem("charstyle");
289
 
290
void CharStyle::desaxeRules(Xml_string prefixPattern, Digester& ruleset, Xml_string elemtag)
291
        {
292
                Xml_string stylePrefix(Digester::concat(prefixPattern, elemtag));
293
                ruleset.addRule(stylePrefix, Factory<CharStyle>());
294
                ruleset.addRule(stylePrefix, SetAttributeWithConversion<CharStyle, const QString&>( & CharStyle::setName, "name", &parse<const QString&>));
295
                ruleset.addRule(stylePrefix, SetAttributeWithConversion<CharStyle, const QString&>( & CharStyle::setParent, "parent", &parse<const QString&>));
296
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
297
                ruleset.addRule(stylePrefix, SetAttributeWithConversion<CharStyle, attr_TYPE> ( & CharStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> ));
298
#include "charstyle.attrdefs.cxx"
299
#undef ATTRDEF          
300
        }