/src/libreoffice/svx/source/sdr/attribute/sdrtextattribute.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
21 | | #include <sdr/attribute/sdrtextattribute.hxx> |
22 | | #include <sdr/attribute/sdrformtextattribute.hxx> |
23 | | #include <svx/svdotext.hxx> |
24 | | #include <editeng/outlobj.hxx> |
25 | | #include <svx/sdr/properties/properties.hxx> |
26 | | |
27 | | |
28 | | namespace drawinglayer::attribute |
29 | | { |
30 | | class ImpSdrTextAttribute |
31 | | { |
32 | | public: |
33 | | // all-text attributes. The SdrText itself and a copy |
34 | | // of the OPO |
35 | | const SdrText* mpSdrText; |
36 | | std::shared_ptr<OutlinerParaObject> mxOutlinerParaObject; |
37 | | |
38 | | // Set when it's a FormText; contains all FormText attributes |
39 | | SdrFormTextAttribute maSdrFormTextAttribute; |
40 | | |
41 | | // text distances |
42 | | sal_Int32 maTextLeftDistance; |
43 | | sal_Int32 maTextUpperDistance; |
44 | | sal_Int32 maTextRightDistance; |
45 | | sal_Int32 maTextLowerDistance; |
46 | | |
47 | | // #i101556# use versioning from text attributes to detect changes |
48 | | sal_uInt32 maPropertiesVersion; |
49 | | |
50 | | // text alignments |
51 | | SdrTextHorzAdjust maSdrTextHorzAdjust; |
52 | | SdrTextVertAdjust maSdrTextVertAdjust; |
53 | | |
54 | | bool mbContour : 1; |
55 | | bool mbFitToSize : 1; |
56 | | bool mbAutoFit : 1; |
57 | | bool mbHideContour : 1; |
58 | | bool mbBlink : 1; |
59 | | bool mbScroll : 1; |
60 | | bool mbInEditMode : 1; |
61 | | bool mbFixedCellHeight : 1; |
62 | | bool mbWrongSpell : 1; |
63 | | |
64 | | bool mbChainable : 1; |
65 | | |
66 | | |
67 | | public: |
68 | | ImpSdrTextAttribute( |
69 | | const SdrText* pSdrText, |
70 | | const OutlinerParaObject& rOutlinerParaObject, |
71 | | XFormTextStyle eFormTextStyle, |
72 | | sal_Int32 aTextLeftDistance, |
73 | | sal_Int32 aTextUpperDistance, |
74 | | sal_Int32 aTextRightDistance, |
75 | | sal_Int32 aTextLowerDistance, |
76 | | SdrTextHorzAdjust aSdrTextHorzAdjust, |
77 | | SdrTextVertAdjust aSdrTextVertAdjust, |
78 | | bool bContour, |
79 | | bool bFitToSize, |
80 | | bool bAutoFit, |
81 | | bool bHideContour, |
82 | | bool bBlink, |
83 | | bool bScroll, |
84 | | bool bInEditMode, |
85 | | bool bFixedCellHeight, |
86 | | bool bWrongSpell, |
87 | | bool bChainable) |
88 | 929 | : mpSdrText(pSdrText), |
89 | 929 | mxOutlinerParaObject(std::make_shared<OutlinerParaObject>(rOutlinerParaObject)), |
90 | 929 | maTextLeftDistance(aTextLeftDistance), |
91 | 929 | maTextUpperDistance(aTextUpperDistance), |
92 | 929 | maTextRightDistance(aTextRightDistance), |
93 | 929 | maTextLowerDistance(aTextLowerDistance), |
94 | 929 | maPropertiesVersion(0), |
95 | 929 | maSdrTextHorzAdjust(aSdrTextHorzAdjust), |
96 | 929 | maSdrTextVertAdjust(aSdrTextVertAdjust), |
97 | 929 | mbContour(bContour), |
98 | 929 | mbFitToSize(bFitToSize), |
99 | 929 | mbAutoFit(bAutoFit), |
100 | 929 | mbHideContour(bHideContour), |
101 | 929 | mbBlink(bBlink), |
102 | 929 | mbScroll(bScroll), |
103 | 929 | mbInEditMode(bInEditMode), |
104 | 929 | mbFixedCellHeight(bFixedCellHeight), |
105 | 929 | mbWrongSpell(bWrongSpell), |
106 | 929 | mbChainable(bChainable) |
107 | 929 | { |
108 | 929 | if(!pSdrText) |
109 | 0 | return; |
110 | | |
111 | 929 | if(XFormTextStyle::NONE != eFormTextStyle) |
112 | 0 | { |
113 | | // text on path. Create FormText attribute |
114 | 0 | const SfxItemSet& rSet = pSdrText->GetItemSet(); |
115 | 0 | maSdrFormTextAttribute = SdrFormTextAttribute(rSet); |
116 | 0 | } |
117 | | |
118 | | // #i101556# init with version number to detect changes of single text |
119 | | // attribute and/or style sheets in primitive data without having to |
120 | | // copy that data locally (which would be better from principle) |
121 | 929 | maPropertiesVersion = pSdrText->GetObject().GetProperties().getVersion(); |
122 | 929 | } |
123 | | |
124 | | ImpSdrTextAttribute() |
125 | 5 | : mpSdrText(nullptr), |
126 | 5 | maTextLeftDistance(0), |
127 | 5 | maTextUpperDistance(0), |
128 | 5 | maTextRightDistance(0), |
129 | 5 | maTextLowerDistance(0), |
130 | 5 | maPropertiesVersion(0), |
131 | 5 | maSdrTextHorzAdjust(SDRTEXTHORZADJUST_LEFT), |
132 | 5 | maSdrTextVertAdjust(SDRTEXTVERTADJUST_TOP), |
133 | 5 | mbContour(false), |
134 | 5 | mbFitToSize(false), |
135 | 5 | mbAutoFit(false), |
136 | 5 | mbHideContour(false), |
137 | 5 | mbBlink(false), |
138 | 5 | mbScroll(false), |
139 | 5 | mbInEditMode(false), |
140 | 5 | mbFixedCellHeight(false), |
141 | 5 | mbWrongSpell(false), |
142 | 5 | mbChainable(false) |
143 | 5 | { |
144 | 5 | } |
145 | | |
146 | | // data read access |
147 | | const SdrText& getSdrText() const |
148 | 467 | { |
149 | 467 | assert(mpSdrText && "Access to text of default version of ImpSdrTextAttribute (!)"); |
150 | 467 | return *mpSdrText; |
151 | 467 | } |
152 | | |
153 | | const OutlinerParaObject& getOutlinerParaObject() const |
154 | 2.78k | { |
155 | 2.78k | assert(mxOutlinerParaObject && "Access to OutlinerParaObject of default version of ImpSdrTextAttribute (!)"); |
156 | 2.78k | return *mxOutlinerParaObject; |
157 | 2.78k | } |
158 | | |
159 | 1.39k | bool isContour() const { return mbContour; } |
160 | 1.39k | bool isFitToSize() const { return mbFitToSize; } |
161 | 1.39k | bool isAutoFit() const { return mbAutoFit; } |
162 | 924 | bool isHideContour() const { return mbHideContour; } |
163 | 1.39k | bool isBlink() const { return mbBlink; } |
164 | 1.63k | bool isScroll() const { return mbScroll; } |
165 | 1.39k | bool isInEditMode() const { return mbInEditMode; } |
166 | 1.39k | bool isFixedCellHeight() const { return mbFixedCellHeight; } |
167 | 241 | bool isChainable() const { return mbChainable; } |
168 | 1.88k | const SdrFormTextAttribute& getSdrFormTextAttribute() const { return maSdrFormTextAttribute; } |
169 | 1.39k | sal_Int32 getTextLeftDistance() const { return maTextLeftDistance; } |
170 | 1.39k | sal_Int32 getTextUpperDistance() const { return maTextUpperDistance; } |
171 | 1.39k | sal_Int32 getTextRightDistance() const { return maTextRightDistance; } |
172 | 1.39k | sal_Int32 getTextLowerDistance() const { return maTextLowerDistance; } |
173 | 1.16k | SdrTextHorzAdjust getSdrTextHorzAdjust() const { return maSdrTextHorzAdjust; } |
174 | 1.16k | SdrTextVertAdjust getSdrTextVertAdjust() const { return maSdrTextVertAdjust; } |
175 | | |
176 | | // compare operator |
177 | | bool operator==(const ImpSdrTextAttribute& rCandidate) const |
178 | 462 | { |
179 | 462 | if (mxOutlinerParaObject.get() != rCandidate.mxOutlinerParaObject.get()) |
180 | 462 | { |
181 | 462 | if (mxOutlinerParaObject && rCandidate.mxOutlinerParaObject) |
182 | 462 | { |
183 | | // compares OPO and it's contents, but traditionally not the RedLining |
184 | | // which is not seen as model, but as temporary information |
185 | 462 | if(getOutlinerParaObject() != rCandidate.getOutlinerParaObject()) |
186 | 0 | { |
187 | 0 | return false; |
188 | 0 | } |
189 | | |
190 | | // #i102062# for primitive visualisation, the WrongList (SpellChecking) |
191 | | // is important, too, so use isWrongListEqual since there is no WrongList |
192 | | // comparison in the regular OutlinerParaObject compare (since it's |
193 | | // not-persistent data) |
194 | 462 | if(!(getOutlinerParaObject().isWrongListEqual(rCandidate.getOutlinerParaObject()))) |
195 | 0 | { |
196 | 0 | return false; |
197 | 0 | } |
198 | 462 | } |
199 | 0 | else |
200 | 0 | { |
201 | | // only one is zero; not equal |
202 | 0 | return false; |
203 | 0 | } |
204 | 462 | } |
205 | | |
206 | 462 | return ( |
207 | 462 | getSdrFormTextAttribute() == rCandidate.getSdrFormTextAttribute() |
208 | 462 | && getTextLeftDistance() == rCandidate.getTextLeftDistance() |
209 | 462 | && getTextUpperDistance() == rCandidate.getTextUpperDistance() |
210 | 462 | && getTextRightDistance() == rCandidate.getTextRightDistance() |
211 | 462 | && getTextLowerDistance() == rCandidate.getTextLowerDistance() |
212 | 462 | && maPropertiesVersion == rCandidate.maPropertiesVersion |
213 | | |
214 | 462 | && getSdrTextHorzAdjust() == rCandidate.getSdrTextHorzAdjust() |
215 | 462 | && getSdrTextVertAdjust() == rCandidate.getSdrTextVertAdjust() |
216 | | |
217 | 462 | && isContour() == rCandidate.isContour() |
218 | 462 | && isFitToSize() == rCandidate.isFitToSize() |
219 | 462 | && isAutoFit() == rCandidate.isAutoFit() |
220 | 462 | && isHideContour() == rCandidate.isHideContour() |
221 | 462 | && isBlink() == rCandidate.isBlink() |
222 | 462 | && isScroll() == rCandidate.isScroll() |
223 | 462 | && isInEditMode() == rCandidate.isInEditMode() |
224 | 462 | && isFixedCellHeight() == rCandidate.isFixedCellHeight() |
225 | 462 | && mbWrongSpell == rCandidate.mbWrongSpell ); |
226 | 462 | } |
227 | | }; |
228 | | |
229 | | namespace |
230 | | { |
231 | | SdrTextAttribute::ImplType& theGlobalDefault() |
232 | 10.0k | { |
233 | 10.0k | static SdrTextAttribute::ImplType SINGLETON; |
234 | 10.0k | return SINGLETON; |
235 | 10.0k | } |
236 | | } |
237 | | |
238 | | SdrTextAttribute::SdrTextAttribute( |
239 | | const SdrText& rSdrText, |
240 | | const OutlinerParaObject& rOutlinerParaObject, |
241 | | XFormTextStyle eFormTextStyle, |
242 | | sal_Int32 aTextLeftDistance, |
243 | | sal_Int32 aTextUpperDistance, |
244 | | sal_Int32 aTextRightDistance, |
245 | | sal_Int32 aTextLowerDistance, |
246 | | SdrTextHorzAdjust aSdrTextHorzAdjust, |
247 | | SdrTextVertAdjust aSdrTextVertAdjust, |
248 | | bool bContour, |
249 | | bool bFitToSize, |
250 | | bool bAutoFit, |
251 | | bool bHideContour, |
252 | | bool bBlink, |
253 | | bool bScroll, |
254 | | bool bInEditMode, |
255 | | bool bFixedCellHeight, |
256 | | bool bWrongSpell, |
257 | | bool bChainable) |
258 | 929 | : mpSdrTextAttribute( |
259 | 929 | ImpSdrTextAttribute( |
260 | 929 | &rSdrText, rOutlinerParaObject, eFormTextStyle, aTextLeftDistance, |
261 | 929 | aTextUpperDistance, aTextRightDistance, aTextLowerDistance, |
262 | 929 | aSdrTextHorzAdjust, aSdrTextVertAdjust, bContour, bFitToSize, bAutoFit, |
263 | 929 | bHideContour, bBlink, bScroll, bInEditMode, bFixedCellHeight, bWrongSpell, |
264 | 929 | bChainable)) |
265 | 929 | { |
266 | 929 | } |
267 | | |
268 | | SdrTextAttribute::SdrTextAttribute() |
269 | 4.83k | : mpSdrTextAttribute(theGlobalDefault()) |
270 | 4.83k | { |
271 | 4.83k | } |
272 | | |
273 | | SdrTextAttribute::SdrTextAttribute(const SdrTextAttribute& rCandidate) |
274 | 2.00k | : mpSdrTextAttribute(rCandidate.mpSdrTextAttribute) |
275 | 2.00k | { |
276 | 2.00k | } |
277 | | |
278 | | SdrTextAttribute::SdrTextAttribute(SdrTextAttribute&& rCandidate) noexcept |
279 | 3.83k | : mpSdrTextAttribute(std::move(rCandidate.mpSdrTextAttribute)) |
280 | 3.83k | { |
281 | 3.83k | } |
282 | | |
283 | | SdrTextAttribute::~SdrTextAttribute() |
284 | 11.6k | { |
285 | 11.6k | } |
286 | | |
287 | | bool SdrTextAttribute::isDefault() const |
288 | 5.24k | { |
289 | 5.24k | return mpSdrTextAttribute.same_object(theGlobalDefault()); |
290 | 5.24k | } |
291 | | |
292 | | SdrTextAttribute& SdrTextAttribute::operator=(const SdrTextAttribute& rCandidate) |
293 | 0 | { |
294 | 0 | mpSdrTextAttribute = rCandidate.mpSdrTextAttribute; |
295 | 0 | return *this; |
296 | 0 | } |
297 | | |
298 | | SdrTextAttribute& SdrTextAttribute::operator=(SdrTextAttribute&& rCandidate) noexcept |
299 | 2.16k | { |
300 | 2.16k | mpSdrTextAttribute = std::move(rCandidate.mpSdrTextAttribute); |
301 | 2.16k | return *this; |
302 | 2.16k | } |
303 | | |
304 | | bool SdrTextAttribute::operator==(const SdrTextAttribute& rCandidate) const |
305 | 594 | { |
306 | | // tdf#87509 default attr is always != non-default attr, even with same values |
307 | 594 | if(rCandidate.isDefault() != isDefault()) |
308 | 0 | return false; |
309 | | |
310 | 594 | return rCandidate.mpSdrTextAttribute == mpSdrTextAttribute; |
311 | 594 | } |
312 | | |
313 | | const SdrText& SdrTextAttribute::getSdrText() const |
314 | 467 | { |
315 | 467 | return mpSdrTextAttribute->getSdrText(); |
316 | 467 | } |
317 | | |
318 | | const OutlinerParaObject& SdrTextAttribute::getOutlinerParaObject() const |
319 | 934 | { |
320 | 934 | return mpSdrTextAttribute->getOutlinerParaObject(); |
321 | 934 | } |
322 | | |
323 | | bool SdrTextAttribute::isContour() const |
324 | 467 | { |
325 | 467 | return mpSdrTextAttribute->isContour(); |
326 | 467 | } |
327 | | |
328 | | bool SdrTextAttribute::isFitToSize() const |
329 | 467 | { |
330 | 467 | return mpSdrTextAttribute->isFitToSize(); |
331 | 467 | } |
332 | | |
333 | | bool SdrTextAttribute::isAutoFit() const |
334 | 467 | { |
335 | 467 | return mpSdrTextAttribute->isAutoFit(); |
336 | 467 | } |
337 | | |
338 | | bool SdrTextAttribute::isHideContour() const |
339 | 0 | { |
340 | 0 | return mpSdrTextAttribute->isHideContour(); |
341 | 0 | } |
342 | | |
343 | | bool SdrTextAttribute::isBlink() const |
344 | 467 | { |
345 | 467 | return mpSdrTextAttribute->isBlink(); |
346 | 467 | } |
347 | | |
348 | | bool SdrTextAttribute::isScroll() const |
349 | 708 | { |
350 | 708 | return mpSdrTextAttribute->isScroll(); |
351 | 708 | } |
352 | | |
353 | | bool SdrTextAttribute::isInEditMode() const |
354 | 467 | { |
355 | 467 | return mpSdrTextAttribute->isInEditMode(); |
356 | 467 | } |
357 | | |
358 | | bool SdrTextAttribute::isChainable() const |
359 | 241 | { |
360 | 241 | return mpSdrTextAttribute->isChainable(); |
361 | 241 | } |
362 | | |
363 | | |
364 | | bool SdrTextAttribute::isFixedCellHeight() const |
365 | 467 | { |
366 | 467 | return mpSdrTextAttribute->isFixedCellHeight(); |
367 | 467 | } |
368 | | |
369 | | const SdrFormTextAttribute& SdrTextAttribute::getSdrFormTextAttribute() const |
370 | 962 | { |
371 | 962 | return mpSdrTextAttribute->getSdrFormTextAttribute(); |
372 | 962 | } |
373 | | |
374 | | sal_Int32 SdrTextAttribute::getTextLeftDistance() const |
375 | 467 | { |
376 | 467 | return mpSdrTextAttribute->getTextLeftDistance(); |
377 | 467 | } |
378 | | |
379 | | sal_Int32 SdrTextAttribute::getTextUpperDistance() const |
380 | 467 | { |
381 | 467 | return mpSdrTextAttribute->getTextUpperDistance(); |
382 | 467 | } |
383 | | |
384 | | sal_Int32 SdrTextAttribute::getTextRightDistance() const |
385 | 467 | { |
386 | 467 | return mpSdrTextAttribute->getTextRightDistance(); |
387 | 467 | } |
388 | | |
389 | | sal_Int32 SdrTextAttribute::getTextLowerDistance() const |
390 | 467 | { |
391 | 467 | return mpSdrTextAttribute->getTextLowerDistance(); |
392 | 467 | } |
393 | | |
394 | | SdrTextHorzAdjust SdrTextAttribute::getSdrTextHorzAdjust() const |
395 | 241 | { |
396 | 241 | return mpSdrTextAttribute->getSdrTextHorzAdjust(); |
397 | 241 | } |
398 | | |
399 | | SdrTextVertAdjust SdrTextAttribute::getSdrTextVertAdjust() const |
400 | 241 | { |
401 | 241 | return mpSdrTextAttribute->getSdrTextVertAdjust(); |
402 | 241 | } |
403 | | |
404 | | void SdrTextAttribute::getBlinkTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList) const |
405 | 0 | { |
406 | 0 | if(isBlink()) |
407 | 0 | { |
408 | 0 | getSdrText().GetObject().impGetBlinkTextTiming(rAnimList); |
409 | 0 | } |
410 | 0 | } |
411 | | |
412 | | void SdrTextAttribute::getScrollTextTiming(drawinglayer::animation::AnimationEntryList& rAnimList, double fFrameLength, double fTextLength) const |
413 | 0 | { |
414 | 0 | if(isScroll()) |
415 | 0 | { |
416 | 0 | getSdrText().GetObject().impGetScrollTextTiming(rAnimList, fFrameLength, fTextLength); |
417 | 0 | } |
418 | 0 | } |
419 | | |
420 | | } // end of namespace |
421 | | |
422 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |