Subversion Repositories Scribus

Rev

Rev 7242 | Rev 7993 | 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"
6443 avox 14
 
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
 
6443 avox 99
void CharStyle::applyCharStyle(const CharStyle & other)
100
{
6805 avox 101
        other.validate();
6443 avox 102
        Style::applyStyle(other);
103
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
104
        if (! other.inh_##attr_NAME) \
105
                set##attr_NAME(other.m_##attr_NAME);
106
#include "charstyle.attrdefs.cxx"
107
#undef ATTRDEF
108
}
109
 
110
 
111
void CharStyle::eraseCharStyle(const CharStyle & other)
112
{
6805 avox 113
        other.validate();
6443 avox 114
        Style::eraseStyle(other);
115
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6936 avox 116
        if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
6443 avox 117
                reset##attr_NAME();
118
#include "charstyle.attrdefs.cxx"
119
#undef ATTRDEF
120
}
121
 
122
bool CharStyle::equiv(const Style & other) const
123
{
6805 avox 124
        other.validate();
6443 avox 125
        const CharStyle * oth = dynamic_cast<const CharStyle*> ( & other );
126
        return  oth &&
6733 avox 127
                parent() == oth->parent()
6443 avox 128
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 129
                && (inh_##attr_NAME == oth->inh_##attr_NAME) \
130
                && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
6443 avox 131
#include "charstyle.attrdefs.cxx"
132
#undef ATTRDEF
133
                ;      
134
}
135
 
136
 
137
QString CharStyle::displayName() const
138
{
139
        if ( hasName() || !hasParent() || ! m_base)
140
                return name();
141
//      else if ( inheritsAll() )
142
//              return parent()->displayName();
143
        else
144
                return parentStyle()->displayName() + "+";
145
}
146
 
147
 
148
 
149
QString CharStyle::asString() const
150
{
151
        QString result;
152
        if ( !inh_Font )
153
                result += QObject::tr("font %1 ").arg(font().scName());
154
        if ( !inh_FontSize )
155
                result += QObject::tr("size %1 ").arg(fontSize());
156
        if ( !inh_Effects )
157
                result += QObject::tr("+style ");
158
        if ( !inh_StrokeColor  ||  !inh_StrokeShade  ||  !inh_FillColor || !inh_FillShade )
159
                result += QObject::tr("+color ");
160
        if ( !inh_UnderlineWidth  ||  !inh_UnderlineOffset )
161
                result += underlineWidth() > 0 ? QObject::tr("+underline ") : QObject::tr("-underline ");
6733 avox 162
        if ( !inh_StrikethruWidth || !inh_StrikethruOffset )
6443 avox 163
                result += strikethruWidth() > 0 ? QObject::tr("+strikeout ") : QObject::tr("-strikeout ");
164
        if ( !inh_ShadowXOffset || !inh_ShadowYOffset )
6733 avox 165
                result += shadowXOffset() != 0 || shadowYOffset() != 0 ? QObject::tr("+shadow ") : QObject::tr("-shadow ");
6443 avox 166
        if ( !inh_OutlineWidth )
167
                result += outlineWidth() > 0 ? QObject::tr("+outline ") : QObject::tr("-outline ");
168
        if ( !inh_Tracking )
169
                result += tracking() > 0 ? QObject::tr("+tracking %1 ").arg(tracking()) : QObject::tr("-tracking ");
170
        if ( !inh_BaselineOffset )
171
                result += QObject::tr("+baseline %1 ").arg(baselineOffset());
172
        if ( !inh_ScaleH || !inh_ScaleV )
173
                result += QObject::tr("+stretch ");
174
        if ( hasParent() )
175
                result += QObject::tr("parent= %1").arg(parent());
176
        return result.stripWhiteSpace();
177
}
178
 
179
 
6805 avox 180
void CharStyle::update(const StyleBase* base)
6443 avox 181
{
182
        Style::update(base);
183
        const CharStyle * oth = dynamic_cast<const CharStyle*> ( parentStyle() );
184
        if (oth) {
185
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
186
                if (inh_##attr_NAME) \
6733 avox 187
                        m_##attr_NAME = oth->attr_GETTER();
6443 avox 188
#include "charstyle.attrdefs.cxx"
189
#undef ATTRDEF
190
        }
191
}
192
 
193
 
7242 avox 194
void CharStyle::setStyle(const CharStyle& other)
195
{
196
        other.validate();
197
        setParent("");
198
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
199
        inh_##attr_NAME = false; \
200
        m_##attr_NAME = other.m_##attr_NAME;
201
#include "charstyle.attrdefs.cxx"
202
#undef ATTRDEF
203
}
6443 avox 204
 
205
 
7242 avox 206
 
6443 avox 207
/*
208
bool CharStyle::definesAll() const
209
{
210
        return definesLineSpacing() &&
211
        definesLeftMargin() &&
212
        definesRightMargin() &&
213
        definesFirstIndent() &&
214
        definesAlignment() &&
215
        definesGapBefore()  &&
216
        definesLineSpacingMode()  &&
217
        definesGapAfter()  &&
218
        definesHasDropCap() &&
219
        definesDropCapOffset() &&
220
        definesDropCapLines() &&
221
        definesUseBaselineGrid() &&
222
        charStyle().definesAll() ;
223
 
224
}
225
 
7242 avox 226
// equiv. to "*this == CharStyle()"
6443 avox 227
bool CharStyle::inheritsAll() const
228
{
229
        return inheritsLineSpacing() &&
230
        inheritsLeftMargin() &&
231
        inheritsRightMargin() &&
232
        inheritsFirstIndent() &&
233
        inheritsAlignment() &&
234
        inheritsGapBefore()  &&
235
        inheritsLineSpacingMode()  &&
236
        inheritsGapAfter()  &&
237
        inheritsHasDropCap() &&
238
        inheritsDropCapOffset() &&
239
        inheritsDropCapLines() &&
240
        inheritsUseBaselineGrid() &&
241
        charStyle().inheritsAll() ;
242
}
243
*/
244