Subversion Repositories Scribus

Rev

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