Subversion Repositories Scribus

Rev

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