1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
50 // helper to get line, stroke and transparence attributes from SfxItemSet
54 basegfx::B2DLineJoin
impGetB2DLineJoin(css::drawing::LineJoint eLineJoint
)
58 case css::drawing::LineJoint_BEVEL
:
60 return basegfx::B2DLineJoin::Bevel
;
62 case css::drawing::LineJoint_MIDDLE
:
63 case css::drawing::LineJoint_MITER
:
65 return basegfx::B2DLineJoin::Miter
;
67 case css::drawing::LineJoint_ROUND
:
69 return basegfx::B2DLineJoin::Round
;
71 default : // css::drawing::LineJoint_NONE
73 return basegfx::B2DLineJoin::NONE
; // XLINEJOINT_NONE
78 sal_uInt8
impGetStrokeTransparence(bool bShadow
, const SfxItemSet
& rSet
)
84 nRetval
= static_cast<sal_uInt8
>((rSet
.Get(SDRATTR_SHADOWTRANSPARENCE
).GetValue() * 255) / 100);
88 nRetval
= static_cast<sal_uInt8
>((rSet
.Get(XATTR_LINETRANSPARENCE
).GetValue() * 255) / 100);
94 drawinglayer::attribute::LineAttribute
impGetLineAttribute(bool bShadow
, const SfxItemSet
& rSet
)
96 basegfx::BColor aColorAttribute
;
100 const Color
aShadowColor(rSet
.Get(SDRATTR_SHADOWCOLOR
).GetColorValue());
101 aColorAttribute
= aShadowColor
.getBColor();
105 const Color
aLineColor(rSet
.Get(XATTR_LINECOLOR
).GetColorValue());
106 aColorAttribute
= aLineColor
.getBColor();
109 const sal_uInt32 nLineWidth
= rSet
.Get(XATTR_LINEWIDTH
).GetValue();
110 const css::drawing::LineJoint eLineJoint
= rSet
.Get(XATTR_LINEJOINT
).GetValue();
111 const css::drawing::LineCap eLineCap
= rSet
.Get(XATTR_LINECAP
).GetValue();
113 return drawinglayer::attribute::LineAttribute(
115 static_cast<double>(nLineWidth
),
116 impGetB2DLineJoin(eLineJoint
),
120 drawinglayer::attribute::StrokeAttribute
impGetStrokeAttribute(const SfxItemSet
& rSet
)
122 const css::drawing::LineStyle eLineStyle
= rSet
.Get(XATTR_LINESTYLE
).GetValue();
123 double fFullDotDashLen(0.0);
124 ::std::vector
< double > aDotDashArray
;
126 if(css::drawing::LineStyle_DASH
== eLineStyle
)
128 const XDash
& rDash
= rSet
.Get(XATTR_LINEDASH
).GetDashValue();
130 if(rDash
.GetDots() || rDash
.GetDashes())
132 const sal_uInt32 nLineWidth
= rSet
.Get(XATTR_LINEWIDTH
).GetValue();
133 fFullDotDashLen
= rDash
.CreateDotDashArray(aDotDashArray
, static_cast<double>(nLineWidth
));
137 return drawinglayer::attribute::StrokeAttribute(std::move(aDotDashArray
), fFullDotDashLen
);
139 } // end of anonymous namespace
142 namespace drawinglayer::attribute
144 class ImpSdrFormTextAttribute
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
158 // outline attributes; used when getFormTextOutline() is true and (for
159 // shadow) when getFormTextShadow() != XFormTextShadow::NONE
160 SdrFormTextOutlineAttribute maOutline
;
161 SdrFormTextOutlineAttribute maShadowOutline
;
163 bool mbFormTextMirror
: 1; // change orientation
164 bool mbFormTextOutline
: 1; // show contour of objects
166 explicit ImpSdrFormTextAttribute(const SfxItemSet
& rSet
)
167 : mnFormTextDistance(rSet
.Get(XATTR_FORMTXTDISTANCE
).GetValue()),
168 mnFormTextStart(rSet
.Get(XATTR_FORMTXTSTART
).GetValue()),
169 mnFormTextShdwXVal(rSet
.Get(XATTR_FORMTXTSHDWXVAL
).GetValue()),
170 mnFormTextShdwYVal(rSet
.Get(XATTR_FORMTXTSHDWYVAL
).GetValue()),
171 mnFormTextShdwTransp(rSet
.Get(XATTR_FORMTXTSHDWTRANSP
).GetValue()),
172 meFormTextStyle(rSet
.Get(XATTR_FORMTXTSTYLE
).GetValue()),
173 meFormTextAdjust(rSet
.Get(XATTR_FORMTXTADJUST
).GetValue()),
174 meFormTextShadow(rSet
.Get(XATTR_FORMTXTSHADOW
).GetValue()),
175 maFormTextShdwColor(rSet
.Get(XATTR_FORMTXTSHDWCOLOR
).GetColorValue()),
176 mbFormTextMirror(rSet
.Get(XATTR_FORMTXTMIRROR
).GetValue()),
177 mbFormTextOutline(rSet
.Get(XATTR_FORMTXTOUTLINE
).GetValue())
179 if(!getFormTextOutline())
182 const StrokeAttribute
aStrokeAttribute(impGetStrokeAttribute(rSet
));
184 // also need to prepare attributes for outlines
186 const LineAttribute
aLineAttribute(impGetLineAttribute(false, rSet
));
187 const sal_uInt8
nTransparence(impGetStrokeTransparence(false, rSet
));
189 maOutline
= SdrFormTextOutlineAttribute(
190 aLineAttribute
, aStrokeAttribute
, nTransparence
);
193 if(XFormTextShadow::NONE
!= getFormTextShadow())
195 // also need to prepare attributes for shadow outlines
196 const LineAttribute
aLineAttribute(impGetLineAttribute(true, rSet
));
197 const sal_uInt8
nTransparence(impGetStrokeTransparence(true, rSet
));
199 maShadowOutline
= SdrFormTextOutlineAttribute(
200 aLineAttribute
, aStrokeAttribute
, nTransparence
);
204 ImpSdrFormTextAttribute()
205 : mnFormTextDistance(0),
207 mnFormTextShdwXVal(0),
208 mnFormTextShdwYVal(0),
209 mnFormTextShdwTransp(0),
210 meFormTextStyle(XFormTextStyle::NONE
),
211 meFormTextAdjust(XFormTextAdjust::Center
),
212 meFormTextShadow(XFormTextShadow::NONE
),
213 mbFormTextMirror(false),
214 mbFormTextOutline(false)
219 sal_Int32
getFormTextDistance() const { return mnFormTextDistance
; }
220 sal_Int32
getFormTextStart() const { return mnFormTextStart
; }
221 sal_Int32
getFormTextShdwXVal() const { return mnFormTextShdwXVal
; }
222 sal_Int32
getFormTextShdwYVal() const { return mnFormTextShdwYVal
; }
223 XFormTextStyle
getFormTextStyle() const { return meFormTextStyle
; }
224 XFormTextAdjust
getFormTextAdjust() const { return meFormTextAdjust
; }
225 XFormTextShadow
getFormTextShadow() const { return meFormTextShadow
; }
226 const Color
& getFormTextShdwColor() const { return maFormTextShdwColor
; }
227 const SdrFormTextOutlineAttribute
& getOutline() const { return maOutline
; }
228 const SdrFormTextOutlineAttribute
& getShadowOutline() const { return maShadowOutline
; }
229 bool getFormTextMirror() const { return mbFormTextMirror
; }
230 bool getFormTextOutline() const { return mbFormTextOutline
; }
233 bool operator==(const ImpSdrFormTextAttribute
& rCandidate
) const
235 return (getFormTextDistance() == rCandidate
.getFormTextDistance()
236 && getFormTextStart() == rCandidate
.getFormTextStart()
237 && getFormTextShdwXVal() == rCandidate
.getFormTextShdwXVal()
238 && getFormTextShdwYVal() == rCandidate
.getFormTextShdwYVal()
239 && mnFormTextShdwTransp
== rCandidate
.mnFormTextShdwTransp
240 && getFormTextStyle() == rCandidate
.getFormTextStyle()
241 && getFormTextAdjust() == rCandidate
.getFormTextAdjust()
242 && getFormTextShadow() == rCandidate
.getFormTextShadow()
243 && getFormTextShdwColor() == rCandidate
.getFormTextShdwColor()
244 && getOutline() == rCandidate
.getOutline()
245 && getShadowOutline() == rCandidate
.getShadowOutline()
246 && getFormTextMirror() == rCandidate
.getFormTextMirror()
247 && getFormTextOutline() == rCandidate
.getFormTextOutline());
253 SdrFormTextAttribute::ImplType
& theGlobalDefault()
255 static SdrFormTextAttribute::ImplType SINGLETON
;
260 SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet
& rSet
)
261 : mpSdrFormTextAttribute(ImpSdrFormTextAttribute(rSet
))
265 SdrFormTextAttribute::SdrFormTextAttribute()
266 : mpSdrFormTextAttribute(theGlobalDefault())
270 SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute
& rCandidate
)
271 : mpSdrFormTextAttribute(rCandidate
.mpSdrFormTextAttribute
)
275 SdrFormTextAttribute::SdrFormTextAttribute(SdrFormTextAttribute
&& rCandidate
) noexcept
276 : mpSdrFormTextAttribute(std::move(rCandidate
.mpSdrFormTextAttribute
))
280 SdrFormTextAttribute::~SdrFormTextAttribute()
284 bool SdrFormTextAttribute::isDefault() const
286 return mpSdrFormTextAttribute
.same_object(theGlobalDefault());
289 SdrFormTextAttribute
& SdrFormTextAttribute::operator=(const SdrFormTextAttribute
& rCandidate
)
291 mpSdrFormTextAttribute
= rCandidate
.mpSdrFormTextAttribute
;
295 SdrFormTextAttribute
& SdrFormTextAttribute::operator=(SdrFormTextAttribute
&& rCandidate
) noexcept
297 mpSdrFormTextAttribute
= std::move(rCandidate
.mpSdrFormTextAttribute
);
301 bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute
& rCandidate
) const
303 // tdf#87509 default attr is always != non-default attr, even with same values
304 if(rCandidate
.isDefault() != isDefault())
307 return rCandidate
.mpSdrFormTextAttribute
== mpSdrFormTextAttribute
;
310 sal_Int32
SdrFormTextAttribute::getFormTextDistance() const
312 return mpSdrFormTextAttribute
->getFormTextDistance();
315 sal_Int32
SdrFormTextAttribute::getFormTextStart() const
317 return mpSdrFormTextAttribute
->getFormTextStart();
320 sal_Int32
SdrFormTextAttribute::getFormTextShdwXVal() const
322 return mpSdrFormTextAttribute
->getFormTextShdwXVal();
325 sal_Int32
SdrFormTextAttribute::getFormTextShdwYVal() const
327 return mpSdrFormTextAttribute
->getFormTextShdwYVal();
330 XFormTextStyle
SdrFormTextAttribute::getFormTextStyle() const
332 return mpSdrFormTextAttribute
->getFormTextStyle();
335 XFormTextAdjust
SdrFormTextAttribute::getFormTextAdjust() const
337 return mpSdrFormTextAttribute
->getFormTextAdjust();
340 XFormTextShadow
SdrFormTextAttribute::getFormTextShadow() const
342 return mpSdrFormTextAttribute
->getFormTextShadow();
345 Color
const & SdrFormTextAttribute::getFormTextShdwColor() const
347 return mpSdrFormTextAttribute
->getFormTextShdwColor();
350 const SdrFormTextOutlineAttribute
& SdrFormTextAttribute::getOutline() const
352 return mpSdrFormTextAttribute
->getOutline();
355 const SdrFormTextOutlineAttribute
& SdrFormTextAttribute::getShadowOutline() const
357 return mpSdrFormTextAttribute
->getShadowOutline();
360 bool SdrFormTextAttribute::getFormTextMirror() const
362 return mpSdrFormTextAttribute
->getFormTextMirror();
365 bool SdrFormTextAttribute::getFormTextOutline() const
367 return mpSdrFormTextAttribute
->getFormTextOutline();
370 } // end of namespace
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */