Rev 5703 | Rev 5775 | Go to most recent revision | 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 | |||
146 | ParagraphStyle::ParagraphStyle() : Style(), CharStyle(), |
||
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 | |||
5703 | avox | 164 | ParagraphStyle::ParagraphStyle(const ParagraphStyle& other) : Style(other), CharStyle(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 | { |
||
237 | static_cast<CharStyle&>(*this) = other.charStyle(); |
||
238 | LineSpaMode = other.LineSpaMode; |
||
239 | LineSpa = (other.LineSpa); |
||
240 | textAlignment = (other.textAlignment); |
||
241 | Indent = (other.Indent); |
||
242 | rightMargin_ = (other.rightMargin_); |
||
243 | First = (other.First); |
||
244 | gapBefore_ = (other.gapBefore_); |
||
245 | gapAfter_ = (other.gapAfter_); |
||
246 | TabValues = (other.TabValues); |
||
247 | haveTabs = other.haveTabs; |
||
248 | Drop = (other.Drop); |
||
249 | DropLin = (other.DropLin); |
||
250 | DropDist = (other.DropDist); |
||
251 | BaseAdj = (other.BaseAdj); |
||
252 | return *this; |
||
253 | } |
||
254 | |||
255 | |||
256 | void ParagraphStyle::applyStyle(const ParagraphStyle& other) |
||
257 | { |
||
258 | applyCharStyle(other.charStyle()); |
||
259 | if (other.LineSpaMode != NOVALUE) |
||
260 | LineSpaMode = other.LineSpaMode; |
||
261 | if (other.LineSpa >= 0) |
||
262 | LineSpa = (other.LineSpa); |
||
263 | if (other.textAlignment != NOVALUE) |
||
264 | textAlignment = (other.textAlignment); |
||
265 | if (other.Indent >= NOVALUE) |
||
266 | Indent = (other.Indent); |
||
267 | if (other.rightMargin_ >= NOVALUE) |
||
268 | rightMargin_ = (other.rightMargin_); |
||
269 | if (other.First >= NOVALUE) |
||
270 | First = (other.First); |
||
271 | if (other.gapBefore_ >= NOVALUE) |
||
272 | gapBefore_ = (other.gapBefore_); |
||
273 | if (other.gapAfter_ >= NOVALUE) |
||
274 | gapAfter_ = (other.gapAfter_); |
||
275 | if (other.haveTabs) { |
||
276 | TabValues = other.TabValues; |
||
277 | haveTabs = true; |
||
278 | } |
||
279 | if (other.Drop != NOVALUE) |
||
280 | Drop = (other.Drop); |
||
281 | if (other.DropLin != NOVALUE) |
||
282 | DropLin = (other.DropLin); |
||
283 | if (other.DropDist >= NOVALUE) |
||
284 | DropDist = (other.DropDist); |
||
285 | if (other.BaseAdj != NOVALUE) |
||
286 | BaseAdj = (other.BaseAdj); |
||
287 | } |
||
288 | |||
289 | |||
290 | void ParagraphStyle::eraseStyle(const ParagraphStyle& other) |
||
291 | { |
||
292 | eraseCharStyle(other.charStyle()); |
||
293 | if (other.LineSpaMode == LineSpaMode) |
||
294 | LineSpaMode = static_cast<LineSpacingMode>(NOVALUE); |
||
295 | if (other.LineSpa == LineSpa) |
||
296 | LineSpa = NOVALUE - 0.1; |
||
297 | if (other.textAlignment == textAlignment) |
||
298 | textAlignment = NOVALUE; |
||
299 | if (other.Indent == Indent) |
||
300 | Indent = NOVALUE - 0.1; |
||
301 | if (other.rightMargin_ == rightMargin_) |
||
302 | rightMargin_ = NOVALUE - 0.1; |
||
303 | if (other.First == gapBefore_) |
||
304 | gapBefore_ = NOVALUE - 0.1; |
||
305 | if (other.gapBefore_ == gapBefore_) |
||
306 | gapBefore_ = NOVALUE - 0.1; |
||
307 | if (other.gapAfter_ == gapAfter_) |
||
308 | gapAfter_ = NOVALUE - 0.1; |
||
309 | if (sameTabs(other.TabValues, TabValues)) { |
||
310 | TabValues.clear(); |
||
311 | haveTabs = false; |
||
312 | } |
||
313 | if (other.Drop == Drop) |
||
314 | Drop = NOVALUE; |
||
315 | if (other.DropLin == DropLin) |
||
316 | DropLin = NOVALUE; |
||
317 | if (other.DropDist == DropDist) |
||
318 | DropDist = NOVALUE - 0.1; |
||
319 | if (other.BaseAdj == BaseAdj) |
||
320 | BaseAdj = NOVALUE; |
||
321 | } |
||
322 | |||
323 |