Subversion Repositories Scribus

Rev

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