Subversion Repositories Scribus

Rev

Rev 5775 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5698 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"
13
 
14
 
15
const QString CharStyle::NOCOLOR;
16
const QString CharStyle::NOLANG;
17
 
18
StyleFlag& operator&= (StyleFlag& left, StyleFlag right){        
19
        int result = static_cast<int>(left) & static_cast<int>(right);        
20
        left = static_cast<StyleFlag>(result);
21
        return left;
22
}
23
 
24
StyleFlag& operator|= (StyleFlag& left, StyleFlag right)
25
{
26
        int result = static_cast<int>(left) | static_cast<int>(right);
27
        left = static_cast<StyleFlag>(result);
28
        return left;
29
}
30
 
31
StyleFlag operator& (StyleFlag left, StyleFlag right)
32
{
33
        int result = static_cast<int>(left) & static_cast<int>(right);        
34
        return static_cast<StyleFlag>(result);
35
}
36
 
37
StyleFlag operator| (StyleFlag left, StyleFlag right)
38
{        
39
        int result = static_cast<int>(left) | static_cast<int>(right);
40
        return static_cast<StyleFlag>(result);
41
}
42
 
43
StyleFlag operator^ (StyleFlag left, StyleFlag right){
44
        int result = static_cast<int>(left) ^ static_cast<int>(right);
45
        return static_cast<StyleFlag>(result);
46
}
47
 
48
StyleFlag operator~ (StyleFlag arg)
49
{
50
        int result = ~ static_cast<int>(arg);
51
        return static_cast<StyleFlag>(result);
52
}
53
 
54
 
55
void CharStyle::applyCharStyle(const CharStyle & other)
56
{
5774 avox 57
        if (other.parent() != NULL)
58
                setParent(other.parent());
5698 avox 59
        if (other.csize != NOVALUE)
60
                csize = other.csize;
61
        if (other.cshade != NOVALUE)
62
                cshade = other.cshade;
63
        if (other.cshade2 != NOVALUE)
64
                cshade2 = other.cshade2;
65
        if (other.cstyle != ScStyle_None)
66
                cstyle = static_cast<StyleFlag>((cstyle & ~ScStyle_UserStyles) | (other.cstyle & ScStyle_UserStyles));
67
        if (other.cscale != NOVALUE)
68
                cscale = other.cscale;
69
        if (other.cscalev != NOVALUE)
70
                cscalev = other.cscalev;
71
        if (other.cbase != NOVALUE)
72
                cbase = other.cbase;
73
        if (other.cshadowx != NOVALUE)
74
                cshadowx = other.cshadowx;
75
        if (other.cshadowy != NOVALUE)
76
                cshadowy = other.cshadowy;
77
        if (other.coutline != NOVALUE)
78
                coutline = other.coutline;
79
        if (other.cunderpos != NOVALUE)
80
                cunderpos = other.cunderpos;
81
        if (other.cunderwidth != NOVALUE)
82
                cunderwidth = other.cunderwidth;
83
        if (other.cstrikepos != NOVALUE)
84
                cstrikepos = other.cstrikepos;
85
        if (other.cstrikewidth != NOVALUE)
86
                cstrikewidth = other.cstrikewidth;
87
        if (other.cextra != NOVALUE)
88
                cextra = other.cextra;
89
        if (other.cfont != &Foi::NONE)
90
                cfont = other.cfont;
91
        if (other.ccolor != NOCOLOR)
92
                ccolor = other.ccolor;
93
        if (other.cstroke != NOCOLOR)
94
                cstroke = other.cstroke;
95
        if (other.language_ != NOLANG)
96
                language_ = other.language_;
97
}
98
 
99
 
100
void CharStyle::eraseCharStyle(const CharStyle & other)
101
{
5774 avox 102
        if (other.parent() == parent())
103
                setParent(NULL);
5698 avox 104
        if (other.csize == csize)
105
                csize = NOVALUE;
106
        if (other.cshade == cshade)
107
                cshade = NOVALUE;
108
        if (other.cshade2 == cshade2)
109
                cshade2 = NOVALUE;
110
        if ((other.cstyle  & ScStyle_UserStyles) == (cstyle & ScStyle_UserStyles))
111
                cstyle = ScStyle_None;
112
        if (other.cscale == cscale)
113
                cscale = NOVALUE;
114
        if (other.cscalev == cscalev)
115
                cscalev = NOVALUE;
116
        if (other.cbase == cbase)
117
                cbase = NOVALUE;
118
        if (other.cshadowx == cshadowx)
119
                cshadowx = NOVALUE;
120
        if (other.cshadowy == cshadowy)
121
                cshadowy = NOVALUE;
122
        if (other.coutline == coutline)
123
                coutline = NOVALUE;
124
        if (other.cunderpos == cunderpos)
125
                cunderpos = NOVALUE;
126
        if (other.cunderwidth == cunderwidth)
127
                cunderwidth = NOVALUE;
128
        if (other.cstrikepos == cstrikepos)
129
                cstrikepos = NOVALUE;
130
        if (other.cstrikewidth == cstrikewidth)
131
                cstrikewidth = NOVALUE;
132
        if (other.cextra == cextra)
133
                cextra = NOVALUE;
134
        if (other.cfont == cfont)
135
                cfont = const_cast<Foi*>(&Foi::NONE);
136
        if (other.ccolor == ccolor)
137
                ccolor = NOCOLOR;
138
        if (other.cstroke == cstroke)
139
                cstroke = NOCOLOR;
140
        if (other.language_ == language_)
141
                language_ = NOLANG;
142
}
143
 
144
 
145
 
5775 avox 146
ParagraphStyle::ParagraphStyle() : Style(), cstyle(),
5698 avox 147
                LineSpaMode(static_cast<LineSpacingMode>(NOVALUE)),
148
                LineSpa(NOVALUE - 0.1),
149
                textAlignment(NOVALUE),
150
                Indent(NOVALUE - 0.1),
151
                rightMargin_(NOVALUE - 0.1),
152
                First(NOVALUE - 0.1),
153
                gapBefore_(NOVALUE - 0.1),
154
                gapAfter_(NOVALUE - 0.1),
155
                TabValues(),
156
                haveTabs(false),
157
                Drop(NOVALUE),
158
                DropLin(NOVALUE),
159
                DropDist(NOVALUE - 0.1),
160
                BaseAdj(NOVALUE)
161
{}
162
 
163
 
5775 avox 164
ParagraphStyle::ParagraphStyle(const ParagraphStyle& other) : Style(other), cstyle(other.charStyle()),
5698 avox 165
                LineSpaMode(other.LineSpaMode),
166
                LineSpa(other.LineSpa),
167
                textAlignment(other.textAlignment),
168
                Indent(other.Indent),
169
                rightMargin_(other.rightMargin_),
170
                First(other.First),
171
                gapBefore_(other.gapBefore_),
172
                gapAfter_(other.gapAfter_),
173
                TabValues(other.TabValues),
174
                haveTabs(other.haveTabs),
175
                Drop(other.Drop),
176
                DropLin(other.DropLin),
177
                DropDist(other.DropDist),
178
                BaseAdj(other.BaseAdj)
179
{}
180
 
181
 
182
static bool sameTabs(const QValueList<ParagraphStyle::TabRecord>& tabs, const QValueList<ParagraphStyle::TabRecord>& other)
183
{
184
        ParagraphStyle::TabRecord tb;
185
        bool tabEQ = false;
186
        if ((other.count() == 0) && (tabs.count() == 0))
187
                tabEQ = true;
188
        else
189
        {
190
                for (uint t1 = 0; t1 < other.count(); t1++)
191
                {
192
                        tb.tabPosition = other[t1].tabPosition;
193
                        tb.tabType = other[t1].tabType;
194
                        tb.tabFillChar = other[t1].tabFillChar;
195
                        for (uint t2 = 0; t2 < tabs.count(); t2++)
196
                        {
197
                                ParagraphStyle::TabRecord tb2;
198
                                tb2.tabPosition = tabs[t2].tabPosition;
199
                                tb2.tabType = tabs[t2].tabType;
200
                                tb2.tabFillChar = tabs[t2].tabFillChar;
201
                                if ((tb2.tabFillChar == tb.tabFillChar) && (tb2.tabPosition == tb.tabPosition) && (tb2.tabType == tb.tabType))
202
                                {
203
                                        tabEQ = true;
204
                                        break;
205
                                }
206
                        }
207
                        if (tabEQ)
208
                                break;
209
                }
210
        }
211
        return tabEQ;
212
}
213
 
214
 
215
bool ParagraphStyle::equiv(const ParagraphStyle& other) const
216
{
217
        return sameTabs(tabValues(), other.tabValues()) &&
218
                (lineSpacing() == other.lineSpacing()) &&
219
                (leftMargin() == other.leftMargin()) &&
220
                (rightMargin() == other.rightMargin()) &&
221
                (firstIndent() == other.firstIndent()) &&
222
                (alignment() == other.alignment()) &&
223
                (gapBefore() == other.gapBefore()) &&
224
                (lineSpacingMode() == other.lineSpacingMode()) &&
225
                (gapAfter() == other.gapAfter()) &&
226
                (hasDropCap() == other.hasDropCap()) &&
227
                (dropCapOffset() == other.dropCapOffset()) &&
228
                (dropCapLines() == other.dropCapLines()) &&
229
                (useBaselineGrid() == other.useBaselineGrid()) &&
230
                (charStyle() == other.charStyle());
231
}      
232
 
233
 
234
 
235
ParagraphStyle& ParagraphStyle::operator=(const ParagraphStyle& other)
236
{
5778 avox 237
        setParent(other.parent());
5775 avox 238
        cstyle = other.charStyle();
5698 avox 239
        LineSpaMode = other.LineSpaMode;
240
        LineSpa = (other.LineSpa);
241
        textAlignment = (other.textAlignment);
242
        Indent = (other.Indent);
243
        rightMargin_ = (other.rightMargin_);
244
        First = (other.First);
245
        gapBefore_ = (other.gapBefore_);
246
        gapAfter_ = (other.gapAfter_);
247
        TabValues = (other.TabValues);
248
        haveTabs = other.haveTabs;
249
        Drop = (other.Drop);
250
        DropLin = (other.DropLin);
251
        DropDist = (other.DropDist);
252
        BaseAdj = (other.BaseAdj);
253
        return *this;
254
}
255
 
256
 
257
void ParagraphStyle::applyStyle(const ParagraphStyle& other)
258
{
5775 avox 259
        if (other.parent() != NULL)
260
                setParent(other.parent());
261
        cstyle.applyCharStyle(other.charStyle());
5698 avox 262
        if (other.LineSpaMode != NOVALUE)
263
                LineSpaMode = other.LineSpaMode;
264
        if (other.LineSpa >= 0)
265
                LineSpa = (other.LineSpa);
266
        if (other.textAlignment != NOVALUE)
267
                textAlignment = (other.textAlignment);
268
        if (other.Indent >= NOVALUE)
269
                Indent = (other.Indent);
270
        if (other.rightMargin_ >= NOVALUE)
271
                rightMargin_ = (other.rightMargin_);
272
        if (other.First >= NOVALUE)
273
                First = (other.First);
274
        if (other.gapBefore_ >= NOVALUE)
275
                gapBefore_ = (other.gapBefore_);
276
        if (other.gapAfter_ >= NOVALUE)
277
                gapAfter_ = (other.gapAfter_);
278
        if (other.haveTabs) {
279
                TabValues = other.TabValues;
280
                haveTabs = true;
281
        }
282
        if (other.Drop != NOVALUE)
283
                Drop = (other.Drop);
284
        if (other.DropLin != NOVALUE)
285
                DropLin = (other.DropLin);
286
        if (other.DropDist >= NOVALUE)
287
                DropDist = (other.DropDist);
288
        if (other.BaseAdj != NOVALUE)
289
                BaseAdj = (other.BaseAdj);
290
}
291
 
292
 
293
void ParagraphStyle::eraseStyle(const ParagraphStyle& other)
294
{
5775 avox 295
        if (other.parent() == parent())
296
                setParent(NULL);
297
        cstyle.eraseCharStyle(other.charStyle());
5698 avox 298
        if (other.LineSpaMode == LineSpaMode)
299
                LineSpaMode = static_cast<LineSpacingMode>(NOVALUE);
300
        if (other.LineSpa == LineSpa)
301
                LineSpa = NOVALUE - 0.1;
302
        if (other.textAlignment == textAlignment)
303
                textAlignment = NOVALUE;
304
        if (other.Indent == Indent)
305
                Indent = NOVALUE - 0.1;
306
        if (other.rightMargin_ == rightMargin_)
307
                rightMargin_ = NOVALUE - 0.1;
308
        if (other.First == gapBefore_)
309
                gapBefore_ = NOVALUE - 0.1;
310
        if (other.gapBefore_ == gapBefore_)
311
                gapBefore_ = NOVALUE - 0.1;
312
        if (other.gapAfter_ == gapAfter_)
313
                gapAfter_ = NOVALUE - 0.1;
314
        if (sameTabs(other.TabValues, TabValues)) {
315
                TabValues.clear();
316
                haveTabs = false;
317
        }
318
        if (other.Drop == Drop)
319
                Drop = NOVALUE;
320
        if (other.DropLin == DropLin)
321
                DropLin = NOVALUE;
322
        if (other.DropDist == DropDist)
323
                DropDist = NOVALUE - 0.1;
324
        if (other.BaseAdj == BaseAdj)
325
                BaseAdj = NOVALUE;
326
}
327
 
328