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