/src/libreoffice/svx/source/sdr/attribute/sdrformtextattribute.cxx
Line | Count | Source |
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 | | #include <sdr/attribute/sdrformtextattribute.hxx> |
21 | | #include <basegfx/vector/b2enums.hxx> |
22 | | #include <svl/itemset.hxx> |
23 | | #include <svx/sdprcitm.hxx> |
24 | | #include <svx/svddef.hxx> |
25 | | #include <svx/xftdiit.hxx> |
26 | | #include <svx/xftstit.hxx> |
27 | | #include <svx/xftshxy.hxx> |
28 | | #include <xftshtit.hxx> |
29 | | #include <svx/xtextit0.hxx> |
30 | | #include <svx/xftadit.hxx> |
31 | | #include <svx/xftshit.hxx> |
32 | | #include <svx/xftshcit.hxx> |
33 | | #include <svx/xftmrit.hxx> |
34 | | #include <svx/xftouit.hxx> |
35 | | #include <svx/xlntrit.hxx> |
36 | | #include <svx/xlnclit.hxx> |
37 | | #include <svx/xlnwtit.hxx> |
38 | | #include <svx/xlinjoit.hxx> |
39 | | #include <svx/xlncapit.hxx> |
40 | | #include <svx/xlineit0.hxx> |
41 | | #include <svx/xdash.hxx> |
42 | | #include <svx/xlndsit.hxx> |
43 | | #include <drawinglayer/attribute/lineattribute.hxx> |
44 | | #include <drawinglayer/attribute/strokeattribute.hxx> |
45 | | #include <sdr/attribute/sdrformtextoutlineattribute.hxx> |
46 | | #include <com/sun/star/drawing/LineCap.hpp> |
47 | | #include <com/sun/star/drawing/LineStyle.hpp> |
48 | | |
49 | | |
50 | | // helper to get line, stroke and transparence attributes from SfxItemSet |
51 | | |
52 | | namespace |
53 | | { |
54 | | basegfx::B2DLineJoin impGetB2DLineJoin(css::drawing::LineJoint eLineJoint) |
55 | 0 | { |
56 | 0 | switch(eLineJoint) |
57 | 0 | { |
58 | 0 | case css::drawing::LineJoint_BEVEL : |
59 | 0 | { |
60 | 0 | return basegfx::B2DLineJoin::Bevel; |
61 | 0 | } |
62 | 0 | case css::drawing::LineJoint_MIDDLE : |
63 | 0 | case css::drawing::LineJoint_MITER : |
64 | 0 | { |
65 | 0 | return basegfx::B2DLineJoin::Miter; |
66 | 0 | } |
67 | 0 | case css::drawing::LineJoint_ROUND : |
68 | 0 | { |
69 | 0 | return basegfx::B2DLineJoin::Round; |
70 | 0 | } |
71 | 0 | default : // css::drawing::LineJoint_NONE |
72 | 0 | { |
73 | 0 | return basegfx::B2DLineJoin::NONE; // XLINEJOINT_NONE |
74 | 0 | } |
75 | 0 | } |
76 | 0 | } |
77 | | |
78 | | sal_uInt8 impGetStrokeTransparence(bool bShadow, const SfxItemSet& rSet) |
79 | 0 | { |
80 | 0 | sal_uInt8 nRetval; |
81 | |
|
82 | 0 | if(bShadow) |
83 | 0 | { |
84 | 0 | nRetval = static_cast<sal_uInt8>((rSet.Get(SDRATTR_SHADOWTRANSPARENCE).GetValue() * 255) / 100); |
85 | 0 | } |
86 | 0 | else |
87 | 0 | { |
88 | 0 | nRetval = static_cast<sal_uInt8>((rSet.Get(XATTR_LINETRANSPARENCE).GetValue() * 255) / 100); |
89 | 0 | } |
90 | |
|
91 | 0 | return nRetval; |
92 | 0 | } |
93 | | |
94 | | drawinglayer::attribute::LineAttribute impGetLineAttribute(bool bShadow, const SfxItemSet& rSet) |
95 | 0 | { |
96 | 0 | basegfx::BColor aColorAttribute; |
97 | |
|
98 | 0 | if(bShadow) |
99 | 0 | { |
100 | 0 | const Color aShadowColor(rSet.Get(SDRATTR_SHADOWCOLOR).GetColorValue()); |
101 | 0 | aColorAttribute = aShadowColor.getBColor(); |
102 | 0 | } |
103 | 0 | else |
104 | 0 | { |
105 | 0 | const Color aLineColor(rSet.Get(XATTR_LINECOLOR).GetColorValue()); |
106 | 0 | aColorAttribute = aLineColor.getBColor(); |
107 | 0 | } |
108 | |
|
109 | 0 | const sal_uInt32 nLineWidth = rSet.Get(XATTR_LINEWIDTH).GetValue(); |
110 | 0 | const css::drawing::LineJoint eLineJoint = rSet.Get(XATTR_LINEJOINT).GetValue(); |
111 | 0 | const css::drawing::LineCap eLineCap = rSet.Get(XATTR_LINECAP).GetValue(); |
112 | |
|
113 | 0 | return drawinglayer::attribute::LineAttribute( |
114 | 0 | aColorAttribute, |
115 | 0 | static_cast<double>(nLineWidth), |
116 | 0 | impGetB2DLineJoin(eLineJoint), |
117 | 0 | eLineCap); |
118 | 0 | } |
119 | | |
120 | | drawinglayer::attribute::StrokeAttribute impGetStrokeAttribute(const SfxItemSet& rSet) |
121 | 0 | { |
122 | 0 | const css::drawing::LineStyle eLineStyle = rSet.Get(XATTR_LINESTYLE).GetValue(); |
123 | 0 | double fFullDotDashLen(0.0); |
124 | 0 | ::std::vector< double > aDotDashArray; |
125 | |
|
126 | 0 | if(css::drawing::LineStyle_DASH == eLineStyle) |
127 | 0 | { |
128 | 0 | const XDash& rDash = rSet.Get(XATTR_LINEDASH).GetDashValue(); |
129 | |
|
130 | 0 | if(rDash.GetDots() || rDash.GetDashes()) |
131 | 0 | { |
132 | 0 | const sal_uInt32 nLineWidth = rSet.Get(XATTR_LINEWIDTH).GetValue(); |
133 | 0 | fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, static_cast<double>(nLineWidth)); |
134 | 0 | } |
135 | 0 | } |
136 | |
|
137 | 0 | return drawinglayer::attribute::StrokeAttribute(std::move(aDotDashArray), fFullDotDashLen); |
138 | 0 | } |
139 | | } // end of anonymous namespace |
140 | | |
141 | | |
142 | | namespace drawinglayer::attribute |
143 | | { |
144 | | class ImpSdrFormTextAttribute |
145 | | { |
146 | | public: |
147 | | // FormText (FontWork) Attributes |
148 | | sal_Int32 mnFormTextDistance; // distance from line in upright direction |
149 | | sal_Int32 mnFormTextStart; // shift from polygon start |
150 | | sal_Int32 mnFormTextShdwXVal; // shadow distance or 10th degrees |
151 | | sal_Int32 mnFormTextShdwYVal; // shadow distance or scaling |
152 | | sal_uInt16 mnFormTextShdwTransp; // shadow transparence |
153 | | XFormTextStyle meFormTextStyle; // on/off and char orientation |
154 | | XFormTextAdjust meFormTextAdjust; // adjustment (left/right/center) and scale |
155 | | XFormTextShadow meFormTextShadow; // shadow mode |
156 | | Color maFormTextShdwColor; // shadow color |
157 | | |
158 | | // outline attributes; used when getFormTextOutline() is true and (for |
159 | | // shadow) when getFormTextShadow() != XFormTextShadow::NONE |
160 | | SdrFormTextOutlineAttribute maOutline; |
161 | | SdrFormTextOutlineAttribute maShadowOutline; |
162 | | |
163 | | bool mbFormTextMirror : 1; // change orientation |
164 | | bool mbFormTextOutline : 1; // show contour of objects |
165 | | |
166 | | explicit ImpSdrFormTextAttribute(const SfxItemSet& rSet) |
167 | 0 | : mnFormTextDistance(rSet.Get(XATTR_FORMTXTDISTANCE).GetValue()), |
168 | 0 | mnFormTextStart(rSet.Get(XATTR_FORMTXTSTART).GetValue()), |
169 | 0 | mnFormTextShdwXVal(rSet.Get(XATTR_FORMTXTSHDWXVAL).GetValue()), |
170 | 0 | mnFormTextShdwYVal(rSet.Get(XATTR_FORMTXTSHDWYVAL).GetValue()), |
171 | 0 | mnFormTextShdwTransp(rSet.Get(XATTR_FORMTXTSHDWTRANSP).GetValue()), |
172 | 0 | meFormTextStyle(rSet.Get(XATTR_FORMTXTSTYLE).GetValue()), |
173 | 0 | meFormTextAdjust(rSet.Get(XATTR_FORMTXTADJUST).GetValue()), |
174 | 0 | meFormTextShadow(rSet.Get(XATTR_FORMTXTSHADOW).GetValue()), |
175 | 0 | maFormTextShdwColor(rSet.Get(XATTR_FORMTXTSHDWCOLOR).GetColorValue()), |
176 | 0 | mbFormTextMirror(rSet.Get(XATTR_FORMTXTMIRROR).GetValue()), |
177 | 0 | mbFormTextOutline(rSet.Get(XATTR_FORMTXTOUTLINE).GetValue()) |
178 | 0 | { |
179 | 0 | if(!getFormTextOutline()) |
180 | 0 | return; |
181 | | |
182 | 0 | const StrokeAttribute aStrokeAttribute(impGetStrokeAttribute(rSet)); |
183 | | |
184 | | // also need to prepare attributes for outlines |
185 | 0 | { |
186 | 0 | const LineAttribute aLineAttribute(impGetLineAttribute(false, rSet)); |
187 | 0 | const sal_uInt8 nTransparence(impGetStrokeTransparence(false, rSet)); |
188 | |
|
189 | 0 | maOutline = SdrFormTextOutlineAttribute( |
190 | 0 | aLineAttribute, aStrokeAttribute, nTransparence); |
191 | 0 | } |
192 | |
|
193 | 0 | if(XFormTextShadow::NONE != getFormTextShadow()) |
194 | 0 | { |
195 | | // also need to prepare attributes for shadow outlines |
196 | 0 | const LineAttribute aLineAttribute(impGetLineAttribute(true, rSet)); |
197 | 0 | const sal_uInt8 nTransparence(impGetStrokeTransparence(true, rSet)); |
198 | |
|
199 | 0 | maShadowOutline = SdrFormTextOutlineAttribute( |
200 | 0 | aLineAttribute, aStrokeAttribute, nTransparence); |
201 | 0 | } |
202 | 0 | } |
203 | | |
204 | | ImpSdrFormTextAttribute() |
205 | 5 | : mnFormTextDistance(0), |
206 | 5 | mnFormTextStart(0), |
207 | 5 | mnFormTextShdwXVal(0), |
208 | 5 | mnFormTextShdwYVal(0), |
209 | 5 | mnFormTextShdwTransp(0), |
210 | 5 | meFormTextStyle(XFormTextStyle::NONE), |
211 | 5 | meFormTextAdjust(XFormTextAdjust::Center), |
212 | 5 | meFormTextShadow(XFormTextShadow::NONE), |
213 | 5 | mbFormTextMirror(false), |
214 | 5 | mbFormTextOutline(false) |
215 | 5 | { |
216 | 5 | } |
217 | | |
218 | | // data read access |
219 | 0 | sal_Int32 getFormTextDistance() const { return mnFormTextDistance; } |
220 | 0 | sal_Int32 getFormTextStart() const { return mnFormTextStart; } |
221 | 0 | sal_Int32 getFormTextShdwXVal() const { return mnFormTextShdwXVal; } |
222 | 0 | sal_Int32 getFormTextShdwYVal() const { return mnFormTextShdwYVal; } |
223 | 0 | XFormTextStyle getFormTextStyle() const { return meFormTextStyle; } |
224 | 0 | XFormTextAdjust getFormTextAdjust() const { return meFormTextAdjust; } |
225 | 0 | XFormTextShadow getFormTextShadow() const { return meFormTextShadow; } |
226 | 0 | const Color& getFormTextShdwColor() const { return maFormTextShdwColor; } |
227 | 0 | const SdrFormTextOutlineAttribute& getOutline() const { return maOutline; } |
228 | 0 | const SdrFormTextOutlineAttribute& getShadowOutline() const { return maShadowOutline; } |
229 | 0 | bool getFormTextMirror() const { return mbFormTextMirror; } |
230 | 0 | bool getFormTextOutline() const { return mbFormTextOutline; } |
231 | | |
232 | | // compare operator |
233 | | bool operator==(const ImpSdrFormTextAttribute& rCandidate) const |
234 | 0 | { |
235 | 0 | return (getFormTextDistance() == rCandidate.getFormTextDistance() |
236 | 0 | && getFormTextStart() == rCandidate.getFormTextStart() |
237 | 0 | && getFormTextShdwXVal() == rCandidate.getFormTextShdwXVal() |
238 | 0 | && getFormTextShdwYVal() == rCandidate.getFormTextShdwYVal() |
239 | 0 | && mnFormTextShdwTransp == rCandidate.mnFormTextShdwTransp |
240 | 0 | && getFormTextStyle() == rCandidate.getFormTextStyle() |
241 | 0 | && getFormTextAdjust() == rCandidate.getFormTextAdjust() |
242 | 0 | && getFormTextShadow() == rCandidate.getFormTextShadow() |
243 | 0 | && getFormTextShdwColor() == rCandidate.getFormTextShdwColor() |
244 | 0 | && getOutline() == rCandidate.getOutline() |
245 | 0 | && getShadowOutline() == rCandidate.getShadowOutline() |
246 | 0 | && getFormTextMirror() == rCandidate.getFormTextMirror() |
247 | 0 | && getFormTextOutline() == rCandidate.getFormTextOutline()); |
248 | 0 | } |
249 | | }; |
250 | | |
251 | | namespace |
252 | | { |
253 | | SdrFormTextAttribute::ImplType& theGlobalDefault() |
254 | 2.64k | { |
255 | 2.64k | static SdrFormTextAttribute::ImplType SINGLETON; |
256 | 2.64k | return SINGLETON; |
257 | 2.64k | } |
258 | | } |
259 | | |
260 | | SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet& rSet) |
261 | 0 | : mpSdrFormTextAttribute(ImpSdrFormTextAttribute(rSet)) |
262 | 0 | { |
263 | 0 | } |
264 | | |
265 | | SdrFormTextAttribute::SdrFormTextAttribute() |
266 | 845 | : mpSdrFormTextAttribute(theGlobalDefault()) |
267 | 845 | { |
268 | 845 | } |
269 | | |
270 | | SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute& rCandidate) |
271 | 0 | : mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute) |
272 | 0 | { |
273 | 0 | } |
274 | | |
275 | | SdrFormTextAttribute::SdrFormTextAttribute(SdrFormTextAttribute&& rCandidate) noexcept |
276 | 840 | : mpSdrFormTextAttribute(std::move(rCandidate.mpSdrFormTextAttribute)) |
277 | 840 | { |
278 | 840 | } |
279 | | |
280 | | SdrFormTextAttribute::~SdrFormTextAttribute() |
281 | 1.68k | { |
282 | 1.68k | } |
283 | | |
284 | | bool SdrFormTextAttribute::isDefault() const |
285 | 1.79k | { |
286 | 1.79k | return mpSdrFormTextAttribute.same_object(theGlobalDefault()); |
287 | 1.79k | } |
288 | | |
289 | | SdrFormTextAttribute& SdrFormTextAttribute::operator=(const SdrFormTextAttribute& rCandidate) |
290 | 0 | { |
291 | 0 | mpSdrFormTextAttribute = rCandidate.mpSdrFormTextAttribute; |
292 | 0 | return *this; |
293 | 0 | } |
294 | | |
295 | | SdrFormTextAttribute& SdrFormTextAttribute::operator=(SdrFormTextAttribute&& rCandidate) noexcept |
296 | 0 | { |
297 | 0 | mpSdrFormTextAttribute = std::move(rCandidate.mpSdrFormTextAttribute); |
298 | 0 | return *this; |
299 | 0 | } |
300 | | |
301 | | bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute& rCandidate) const |
302 | 417 | { |
303 | | // tdf#87509 default attr is always != non-default attr, even with same values |
304 | 417 | if(rCandidate.isDefault() != isDefault()) |
305 | 0 | return false; |
306 | | |
307 | 417 | return rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute; |
308 | 417 | } |
309 | | |
310 | | sal_Int32 SdrFormTextAttribute::getFormTextDistance() const |
311 | 0 | { |
312 | 0 | return mpSdrFormTextAttribute->getFormTextDistance(); |
313 | 0 | } |
314 | | |
315 | | sal_Int32 SdrFormTextAttribute::getFormTextStart() const |
316 | 0 | { |
317 | 0 | return mpSdrFormTextAttribute->getFormTextStart(); |
318 | 0 | } |
319 | | |
320 | | sal_Int32 SdrFormTextAttribute::getFormTextShdwXVal() const |
321 | 0 | { |
322 | 0 | return mpSdrFormTextAttribute->getFormTextShdwXVal(); |
323 | 0 | } |
324 | | |
325 | | sal_Int32 SdrFormTextAttribute::getFormTextShdwYVal() const |
326 | 0 | { |
327 | 0 | return mpSdrFormTextAttribute->getFormTextShdwYVal(); |
328 | 0 | } |
329 | | |
330 | | XFormTextStyle SdrFormTextAttribute::getFormTextStyle() const |
331 | 0 | { |
332 | 0 | return mpSdrFormTextAttribute->getFormTextStyle(); |
333 | 0 | } |
334 | | |
335 | | XFormTextAdjust SdrFormTextAttribute::getFormTextAdjust() const |
336 | 0 | { |
337 | 0 | return mpSdrFormTextAttribute->getFormTextAdjust(); |
338 | 0 | } |
339 | | |
340 | | XFormTextShadow SdrFormTextAttribute::getFormTextShadow() const |
341 | 0 | { |
342 | 0 | return mpSdrFormTextAttribute->getFormTextShadow(); |
343 | 0 | } |
344 | | |
345 | | Color const & SdrFormTextAttribute::getFormTextShdwColor() const |
346 | 0 | { |
347 | 0 | return mpSdrFormTextAttribute->getFormTextShdwColor(); |
348 | 0 | } |
349 | | |
350 | | const SdrFormTextOutlineAttribute& SdrFormTextAttribute::getOutline() const |
351 | 0 | { |
352 | 0 | return mpSdrFormTextAttribute->getOutline(); |
353 | 0 | } |
354 | | |
355 | | const SdrFormTextOutlineAttribute& SdrFormTextAttribute::getShadowOutline() const |
356 | 0 | { |
357 | 0 | return mpSdrFormTextAttribute->getShadowOutline(); |
358 | 0 | } |
359 | | |
360 | | bool SdrFormTextAttribute::getFormTextMirror() const |
361 | 0 | { |
362 | 0 | return mpSdrFormTextAttribute->getFormTextMirror(); |
363 | 0 | } |
364 | | |
365 | | bool SdrFormTextAttribute::getFormTextOutline() const |
366 | 0 | { |
367 | 0 | return mpSdrFormTextAttribute->getFormTextOutline(); |
368 | 0 | } |
369 | | |
370 | | } // end of namespace |
371 | | |
372 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |