Subversion Repositories Scribus

Rev

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