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 <svx/sdr/attribute/sdrformtextattribute.hxx>
21 #include <basegfx/vector/b2enums.hxx>
22 #include <svl/itemset.hxx>
23 #include <svx/xftdiit.hxx>
24 #include <svx/xftstit.hxx>
25 #include <svx/xftshxy.hxx>
26 #include <svx/xftshtit.hxx>
27 #include <svx/xtextit0.hxx>
28 #include <svx/xftadit.hxx>
29 #include <svx/xftshit.hxx>
30 #include <svx/xftshcit.hxx>
31 #include <svx/xftmrit.hxx>
32 #include <svx/xftouit.hxx>
33 #include <svx/sdshtitm.hxx>
34 #include <svx/xlntrit.hxx>
35 #include <svx/sdshcitm.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 <svx/sdr/attribute/sdrformtextoutlineattribute.hxx>
46 #include <com/sun/star/drawing/LineCap.hpp>
48 //////////////////////////////////////////////////////////////////////////////
49 // helper to get line, stroke and transparence attributes from SfxItemSet
53 basegfx::B2DLineJoin
impGetB2DLineJoin(com::sun::star::drawing::LineJoint eLineJoint
)
57 case com::sun::star::drawing::LineJoint_MIDDLE
:
59 return basegfx::B2DLINEJOIN_MIDDLE
;
61 case com::sun::star::drawing::LineJoint_BEVEL
:
63 return basegfx::B2DLINEJOIN_BEVEL
;
65 case com::sun::star::drawing::LineJoint_MITER
:
67 return basegfx::B2DLINEJOIN_MITER
;
69 case com::sun::star::drawing::LineJoint_ROUND
:
71 return basegfx::B2DLINEJOIN_ROUND
;
73 default : // com::sun::star::drawing::LineJoint_NONE
75 return basegfx::B2DLINEJOIN_NONE
; // XLINEJOINT_NONE
80 sal_uInt8
impGetStrokeTransparence(bool bShadow
, const SfxItemSet
& rSet
)
86 nRetval
= (sal_uInt8
)((((SdrShadowTransparenceItem
&)(rSet
.Get(SDRATTR_SHADOWTRANSPARENCE
))).GetValue() * 255) / 100);
90 nRetval
= (sal_uInt8
)((((XLineTransparenceItem
&)(rSet
.Get(XATTR_LINETRANSPARENCE
))).GetValue() * 255) / 100);
96 drawinglayer::attribute::LineAttribute
impGetLineAttribute(bool bShadow
, const SfxItemSet
& rSet
)
98 basegfx::BColor aColorAttribute
;
102 const Color
aShadowColor(((SdrShadowColorItem
&)(rSet
.Get(SDRATTR_SHADOWCOLOR
))).GetColorValue());
103 aColorAttribute
= aShadowColor
.getBColor();
107 const Color
aLineColor(((XLineColorItem
&)(rSet
.Get(XATTR_LINECOLOR
))).GetColorValue());
108 aColorAttribute
= aLineColor
.getBColor();
111 const sal_uInt32 nLineWidth
= ((const XLineWidthItem
&)(rSet
.Get(XATTR_LINEWIDTH
))).GetValue();
112 const com::sun::star::drawing::LineJoint eLineJoint
= ((const XLineJointItem
&)(rSet
.Get(XATTR_LINEJOINT
))).GetValue();
113 const com::sun::star::drawing::LineCap eLineCap
= ((const XLineCapItem
&)(rSet
.Get(XATTR_LINECAP
))).GetValue();
115 return drawinglayer::attribute::LineAttribute(
118 impGetB2DLineJoin(eLineJoint
),
122 drawinglayer::attribute::StrokeAttribute
impGetStrokeAttribute(const SfxItemSet
& rSet
)
124 const XLineStyle eLineStyle
= ((XLineStyleItem
&)(rSet
.Get(XATTR_LINESTYLE
))).GetValue();
125 double fFullDotDashLen(0.0);
126 ::std::vector
< double > aDotDashArray
;
128 if(XLINE_DASH
== eLineStyle
)
130 const XDash
& rDash
= ((const XLineDashItem
&)(rSet
.Get(XATTR_LINEDASH
))).GetDashValue();
132 if(rDash
.GetDots() || rDash
.GetDashes())
134 const sal_uInt32 nLineWidth
= ((const XLineWidthItem
&)(rSet
.Get(XATTR_LINEWIDTH
))).GetValue();
135 fFullDotDashLen
= rDash
.CreateDotDashArray(aDotDashArray
, (double)nLineWidth
);
139 return drawinglayer::attribute::StrokeAttribute(aDotDashArray
, fFullDotDashLen
);
141 } // end of anonymous namespace
143 //////////////////////////////////////////////////////////////////////////////
145 namespace drawinglayer
149 class ImpSdrFormTextAttribute
153 sal_uInt32 mnRefCount
;
155 // FormText (FontWork) Attributes
156 sal_Int32 mnFormTextDistance
; // distance from line in upright direction
157 sal_Int32 mnFormTextStart
; // shift from polygon start
158 sal_Int32 mnFormTextShdwXVal
; // shadow distance or 10th degrees
159 sal_Int32 mnFormTextShdwYVal
; // shadow distance or scaling
160 sal_uInt16 mnFormTextShdwTransp
; // shadow transparence
161 XFormTextStyle meFormTextStyle
; // on/off and char orientation
162 XFormTextAdjust meFormTextAdjust
; // adjustment (left/right/center) and scale
163 XFormTextShadow meFormTextShadow
; // shadow mode
164 Color maFormTextShdwColor
; // shadow color
166 // outline attributes; used when getFormTextOutline() is true and (for
167 // shadow) when getFormTextShadow() != XFTSHADOW_NONE
168 SdrFormTextOutlineAttribute maOutline
;
169 SdrFormTextOutlineAttribute maShadowOutline
;
172 unsigned mbFormTextMirror
: 1; // change orientation
173 unsigned mbFormTextOutline
: 1; // show contour of objects
175 explicit ImpSdrFormTextAttribute(const SfxItemSet
& rSet
)
177 mnFormTextDistance(((const XFormTextDistanceItem
&)rSet
.Get(XATTR_FORMTXTDISTANCE
)).GetValue()),
178 mnFormTextStart(((const XFormTextStartItem
&)rSet
.Get(XATTR_FORMTXTSTART
)).GetValue()),
179 mnFormTextShdwXVal(((const XFormTextShadowXValItem
&)rSet
.Get(XATTR_FORMTXTSHDWXVAL
)).GetValue()),
180 mnFormTextShdwYVal(((const XFormTextShadowYValItem
&)rSet
.Get(XATTR_FORMTXTSHDWYVAL
)).GetValue()),
181 mnFormTextShdwTransp(((const XFormTextShadowTranspItem
&)rSet
.Get(XATTR_FORMTXTSHDWTRANSP
)).GetValue()),
182 meFormTextStyle(((const XFormTextStyleItem
&)rSet
.Get(XATTR_FORMTXTSTYLE
)).GetValue()),
183 meFormTextAdjust(((const XFormTextAdjustItem
&)rSet
.Get(XATTR_FORMTXTADJUST
)).GetValue()),
184 meFormTextShadow(((const XFormTextShadowItem
&)rSet
.Get(XATTR_FORMTXTSHADOW
)).GetValue()),
185 maFormTextShdwColor(((const XFormTextShadowColorItem
&)rSet
.Get(XATTR_FORMTXTSHDWCOLOR
)).GetColorValue()),
188 mbFormTextMirror(((const XFormTextMirrorItem
&)rSet
.Get(XATTR_FORMTXTMIRROR
)).GetValue()),
189 mbFormTextOutline(((const XFormTextOutlineItem
&)rSet
.Get(XATTR_FORMTXTOUTLINE
)).GetValue())
191 if(getFormTextOutline())
193 const StrokeAttribute
aStrokeAttribute(impGetStrokeAttribute(rSet
));
195 // also need to prepare attributes for outlines
197 const LineAttribute
aLineAttribute(impGetLineAttribute(false, rSet
));
198 const sal_uInt8
nTransparence(impGetStrokeTransparence(false, rSet
));
200 maOutline
= SdrFormTextOutlineAttribute(
201 aLineAttribute
, aStrokeAttribute
, nTransparence
);
204 if(XFTSHADOW_NONE
!= getFormTextShadow())
206 // also need to prepare attributes for shadow outlines
207 const LineAttribute
aLineAttribute(impGetLineAttribute(true, rSet
));
208 const sal_uInt8
nTransparence(impGetStrokeTransparence(true, rSet
));
210 maShadowOutline
= SdrFormTextOutlineAttribute(
211 aLineAttribute
, aStrokeAttribute
, nTransparence
);
216 ImpSdrFormTextAttribute()
218 mnFormTextDistance(0),
220 mnFormTextShdwXVal(0),
221 mnFormTextShdwYVal(0),
222 mnFormTextShdwTransp(0),
223 meFormTextStyle(XFT_NONE
),
224 meFormTextAdjust(XFT_CENTER
),
225 meFormTextShadow(XFTSHADOW_NONE
),
226 maFormTextShdwColor(),
229 mbFormTextMirror(false),
230 mbFormTextOutline(false)
235 sal_Int32
getFormTextDistance() const { return mnFormTextDistance
; }
236 sal_Int32
getFormTextStart() const { return mnFormTextStart
; }
237 sal_Int32
getFormTextShdwXVal() const { return mnFormTextShdwXVal
; }
238 sal_Int32
getFormTextShdwYVal() const { return mnFormTextShdwYVal
; }
239 sal_uInt16
getFormTextShdwTransp() const { return mnFormTextShdwTransp
; }
240 XFormTextStyle
getFormTextStyle() const { return meFormTextStyle
; }
241 XFormTextAdjust
getFormTextAdjust() const { return meFormTextAdjust
; }
242 XFormTextShadow
getFormTextShadow() const { return meFormTextShadow
; }
243 Color
getFormTextShdwColor() const { return maFormTextShdwColor
; }
244 const SdrFormTextOutlineAttribute
& getOutline() const { return maOutline
; }
245 const SdrFormTextOutlineAttribute
& getShadowOutline() const { return maShadowOutline
; }
246 bool getFormTextMirror() const { return mbFormTextMirror
; }
247 bool getFormTextOutline() const { return mbFormTextOutline
; }
250 bool operator==(const ImpSdrFormTextAttribute
& rCandidate
) const
252 return (getFormTextDistance() == rCandidate
.getFormTextDistance()
253 && getFormTextStart() == rCandidate
.getFormTextStart()
254 && getFormTextShdwXVal() == rCandidate
.getFormTextShdwXVal()
255 && getFormTextShdwYVal() == rCandidate
.getFormTextShdwYVal()
256 && getFormTextShdwTransp() == rCandidate
.getFormTextShdwTransp()
257 && getFormTextStyle() == rCandidate
.getFormTextStyle()
258 && getFormTextAdjust() == rCandidate
.getFormTextAdjust()
259 && getFormTextShadow() == rCandidate
.getFormTextShadow()
260 && getFormTextShdwColor() == rCandidate
.getFormTextShdwColor()
261 && getOutline() == rCandidate
.getOutline()
262 && getShadowOutline() == rCandidate
.getShadowOutline()
263 && getFormTextMirror() == rCandidate
.getFormTextMirror()
264 && getFormTextOutline() == rCandidate
.getFormTextOutline());
267 static ImpSdrFormTextAttribute
* get_global_default()
269 static ImpSdrFormTextAttribute
* pDefault
= 0;
273 pDefault
= new ImpSdrFormTextAttribute();
275 // never delete; start with RefCount 1, not 0
276 pDefault
->mnRefCount
++;
283 SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet
& rSet
)
284 : mpSdrFormTextAttribute(new ImpSdrFormTextAttribute(rSet
))
288 SdrFormTextAttribute::SdrFormTextAttribute()
289 : mpSdrFormTextAttribute(ImpSdrFormTextAttribute::get_global_default())
291 mpSdrFormTextAttribute
->mnRefCount
++;
294 SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute
& rCandidate
)
295 : mpSdrFormTextAttribute(rCandidate
.mpSdrFormTextAttribute
)
297 mpSdrFormTextAttribute
->mnRefCount
++;
300 SdrFormTextAttribute::~SdrFormTextAttribute()
302 if(mpSdrFormTextAttribute
->mnRefCount
)
304 mpSdrFormTextAttribute
->mnRefCount
--;
308 delete mpSdrFormTextAttribute
;
312 bool SdrFormTextAttribute::isDefault() const
314 return mpSdrFormTextAttribute
== ImpSdrFormTextAttribute::get_global_default();
317 SdrFormTextAttribute
& SdrFormTextAttribute::operator=(const SdrFormTextAttribute
& rCandidate
)
319 if(rCandidate
.mpSdrFormTextAttribute
!= mpSdrFormTextAttribute
)
321 if(mpSdrFormTextAttribute
->mnRefCount
)
323 mpSdrFormTextAttribute
->mnRefCount
--;
327 delete mpSdrFormTextAttribute
;
330 mpSdrFormTextAttribute
= rCandidate
.mpSdrFormTextAttribute
;
331 mpSdrFormTextAttribute
->mnRefCount
++;
337 bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute
& rCandidate
) const
339 if(rCandidate
.mpSdrFormTextAttribute
== mpSdrFormTextAttribute
)
344 if(rCandidate
.isDefault() != isDefault())
349 return (*rCandidate
.mpSdrFormTextAttribute
== *mpSdrFormTextAttribute
);
352 sal_Int32
SdrFormTextAttribute::getFormTextDistance() const
354 return mpSdrFormTextAttribute
->getFormTextDistance();
357 sal_Int32
SdrFormTextAttribute::getFormTextStart() const
359 return mpSdrFormTextAttribute
->getFormTextStart();
362 sal_Int32
SdrFormTextAttribute::getFormTextShdwXVal() const
364 return mpSdrFormTextAttribute
->getFormTextShdwXVal();
367 sal_Int32
SdrFormTextAttribute::getFormTextShdwYVal() const
369 return mpSdrFormTextAttribute
->getFormTextShdwYVal();
372 XFormTextStyle
SdrFormTextAttribute::getFormTextStyle() const
374 return mpSdrFormTextAttribute
->getFormTextStyle();
377 XFormTextAdjust
SdrFormTextAttribute::getFormTextAdjust() const
379 return mpSdrFormTextAttribute
->getFormTextAdjust();
382 XFormTextShadow
SdrFormTextAttribute::getFormTextShadow() const
384 return mpSdrFormTextAttribute
->getFormTextShadow();
387 Color
SdrFormTextAttribute::getFormTextShdwColor() const
389 return mpSdrFormTextAttribute
->getFormTextShdwColor();
392 const SdrFormTextOutlineAttribute
& SdrFormTextAttribute::getOutline() const
394 return mpSdrFormTextAttribute
->getOutline();
397 const SdrFormTextOutlineAttribute
& SdrFormTextAttribute::getShadowOutline() const
399 return mpSdrFormTextAttribute
->getShadowOutline();
402 bool SdrFormTextAttribute::getFormTextMirror() const
404 return mpSdrFormTextAttribute
->getFormTextMirror();
407 bool SdrFormTextAttribute::getFormTextOutline() const
409 return mpSdrFormTextAttribute
->getFormTextOutline();
411 } // end of namespace attribute
412 } // end of namespace drawinglayer
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */