1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrtextattribute.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
34 #include <svx/sdr/attribute/sdrformtextattribute.hxx>
35 #include <svtools/itemset.hxx>
37 #include <svx/xftdiit.hxx>
38 #include <svx/xftstit.hxx>
39 #include <svx/xftshxy.hxx>
40 #include <svx/xftshtit.hxx>
41 #include <svx/xtextit0.hxx>
42 #include <svx/xftadit.hxx>
43 #include <svx/xftshit.hxx>
44 #include <svx/xftshcit.hxx>
45 #include <svx/xftmrit.hxx>
46 #include <svx/xftouit.hxx>
48 #include <svx/sdshtitm.hxx>
49 #include <svx/xlntrit.hxx>
50 #include <drawinglayer/attribute/lineattribute.hxx>
51 #include <drawinglayer/attribute/strokeattribute.hxx>
52 #include <svx/sdshcitm.hxx>
53 #include <svx/xlnclit.hxx>
54 #include <svx/xlnwtit.hxx>
55 #include <xlinjoit.hxx>
56 #include <svx/xlineit0.hxx>
57 #include <svx/xdash.hxx>
58 #include <svx/xlndsit.hxx>
59 #include <svx/sdr/attribute/sdrformtextoutlineattribute.hxx>
61 //////////////////////////////////////////////////////////////////////////////
62 // pointer compare define
63 #define pointerOrContentEqual(p, q) ((p == q) || (p && q && *p == *q))
65 //////////////////////////////////////////////////////////////////////////////
66 // helper to get line, stroke and transparence attributes from SfxItemSet
70 basegfx::B2DLineJoin
impGetB2DLineJoin(XLineJoint eLineJoint
)
74 case XLINEJOINT_MIDDLE
:
76 return basegfx::B2DLINEJOIN_MIDDLE
;
78 case XLINEJOINT_BEVEL
:
80 return basegfx::B2DLINEJOIN_BEVEL
;
82 case XLINEJOINT_MITER
:
84 return basegfx::B2DLINEJOIN_MITER
;
86 case XLINEJOINT_ROUND
:
88 return basegfx::B2DLINEJOIN_ROUND
;
92 return basegfx::B2DLINEJOIN_NONE
; // XLINEJOINT_NONE
97 sal_uInt8
impGetStrokeTransparence(bool bShadow
, const SfxItemSet
& rSet
)
103 nRetval
= (sal_uInt8
)((((SdrShadowTransparenceItem
&)(rSet
.Get(SDRATTR_SHADOWTRANSPARENCE
))).GetValue() * 255) / 100);
107 nRetval
= (sal_uInt8
)((((XLineTransparenceItem
&)(rSet
.Get(XATTR_LINETRANSPARENCE
))).GetValue() * 255) / 100);
113 drawinglayer::attribute::LineAttribute
impGetLineAttribute(bool bShadow
, const SfxItemSet
& rSet
)
115 basegfx::BColor aColorAttribute
;
119 const Color
aShadowColor(((SdrShadowColorItem
&)(rSet
.Get(SDRATTR_SHADOWCOLOR
))).GetColorValue());
120 aColorAttribute
= aShadowColor
.getBColor();
124 const Color
aLineColor(((XLineColorItem
&)(rSet
.Get(XATTR_LINECOLOR
))).GetColorValue());
125 aColorAttribute
= aLineColor
.getBColor();
128 const sal_uInt32 nLineWidth
= ((const XLineWidthItem
&)(rSet
.Get(XATTR_LINEWIDTH
))).GetValue();
129 const XLineJoint eLineJoint
= ((const XLineJointItem
&)(rSet
.Get(XATTR_LINEJOINT
))).GetValue();
131 return drawinglayer::attribute::LineAttribute(aColorAttribute
, (double)nLineWidth
, impGetB2DLineJoin(eLineJoint
));
134 drawinglayer::attribute::StrokeAttribute
impGetStrokeAttribute(const SfxItemSet
& rSet
)
136 const XLineStyle eLineStyle
= ((XLineStyleItem
&)(rSet
.Get(XATTR_LINESTYLE
))).GetValue();
137 double fFullDotDashLen(0.0);
138 ::std::vector
< double > aDotDashArray
;
140 if(XLINE_DASH
== eLineStyle
)
142 const XDash
& rDash
= ((const XLineDashItem
&)(rSet
.Get(XATTR_LINEDASH
))).GetDashValue();
144 if(rDash
.GetDots() || rDash
.GetDashes())
146 const sal_uInt32 nLineWidth
= ((const XLineWidthItem
&)(rSet
.Get(XATTR_LINEWIDTH
))).GetValue();
147 fFullDotDashLen
= rDash
.CreateDotDashArray(aDotDashArray
, (double)nLineWidth
);
151 return drawinglayer::attribute::StrokeAttribute(aDotDashArray
, fFullDotDashLen
);
153 } // end of anonymous namespace
155 //////////////////////////////////////////////////////////////////////////////
157 namespace drawinglayer
161 SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet
& rSet
)
162 : mnFormTextDistance(((const XFormTextDistanceItem
&)rSet
.Get(XATTR_FORMTXTDISTANCE
)).GetValue()),
163 mnFormTextStart(((const XFormTextStartItem
&)rSet
.Get(XATTR_FORMTXTSTART
)).GetValue()),
164 mnFormTextShdwXVal(((const XFormTextShadowXValItem
&)rSet
.Get(XATTR_FORMTXTSHDWXVAL
)).GetValue()),
165 mnFormTextShdwYVal(((const XFormTextShadowYValItem
&)rSet
.Get(XATTR_FORMTXTSHDWYVAL
)).GetValue()),
166 mnFormTextShdwTransp(((const XFormTextShadowTranspItem
&)rSet
.Get(XATTR_FORMTXTSHDWTRANSP
)).GetValue()),
167 meFormTextStyle(((const XFormTextStyleItem
&)rSet
.Get(XATTR_FORMTXTSTYLE
)).GetValue()),
168 meFormTextAdjust(((const XFormTextAdjustItem
&)rSet
.Get(XATTR_FORMTXTADJUST
)).GetValue()),
169 meFormTextShadow(((const XFormTextShadowItem
&)rSet
.Get(XATTR_FORMTXTSHADOW
)).GetValue()),
170 maFormTextShdwColor(((const XFormTextShadowColorItem
&)rSet
.Get(XATTR_FORMTXTSHDWCOLOR
)).GetColorValue()),
173 mbFormTextMirror(((const XFormTextMirrorItem
&)rSet
.Get(XATTR_FORMTXTMIRROR
)).GetValue()),
174 mbFormTextOutline(((const XFormTextOutlineItem
&)rSet
.Get(XATTR_FORMTXTOUTLINE
)).GetValue())
176 if(getFormTextOutline())
178 const StrokeAttribute
aStrokeAttribute(impGetStrokeAttribute(rSet
));
180 // also need to prepare attributes for outlines
182 const LineAttribute
aLineAttribute(impGetLineAttribute(false, rSet
));
183 const sal_uInt8
nTransparence(impGetStrokeTransparence(false, rSet
));
185 mpOutline
= new SdrFormTextOutlineAttribute(
186 aLineAttribute
, aStrokeAttribute
, nTransparence
);
189 if(XFTSHADOW_NONE
!= getFormTextShadow())
191 // also need to prepare attributes for shadow outlines
192 const LineAttribute
aLineAttribute(impGetLineAttribute(true, rSet
));
193 const sal_uInt8
nTransparence(impGetStrokeTransparence(true, rSet
));
195 mpShadowOutline
= new SdrFormTextOutlineAttribute(
196 aLineAttribute
, aStrokeAttribute
, nTransparence
);
201 SdrFormTextAttribute::~SdrFormTextAttribute()
211 delete mpShadowOutline
;
216 SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute
& rCandidate
)
217 : mnFormTextDistance(rCandidate
.getFormTextDistance()),
218 mnFormTextStart(rCandidate
.getFormTextStart()),
219 mnFormTextShdwXVal(rCandidate
.getFormTextShdwXVal()),
220 mnFormTextShdwYVal(rCandidate
.getFormTextShdwYVal()),
221 mnFormTextShdwTransp(rCandidate
.getFormTextShdwTransp()),
222 meFormTextStyle(rCandidate
.getFormTextStyle()),
223 meFormTextAdjust(rCandidate
.getFormTextAdjust()),
224 meFormTextShadow(rCandidate
.getFormTextShadow()),
225 maFormTextShdwColor(rCandidate
.getFormTextShdwColor()),
228 mbFormTextMirror(rCandidate
.getFormTextMirror()),
229 mbFormTextOutline(rCandidate
.getFormTextOutline())
231 if(rCandidate
.getOutline())
233 mpOutline
= new SdrFormTextOutlineAttribute(*rCandidate
.getOutline());
236 if(rCandidate
.getShadowOutline())
238 mpShadowOutline
= new SdrFormTextOutlineAttribute(*rCandidate
.getShadowOutline());
242 SdrFormTextAttribute
& SdrFormTextAttribute::operator=(const SdrFormTextAttribute
& rCandidate
)
244 mnFormTextDistance
= rCandidate
.getFormTextDistance();
245 mnFormTextStart
= rCandidate
.getFormTextStart();
246 mnFormTextShdwXVal
= rCandidate
.getFormTextShdwXVal();
247 mnFormTextShdwYVal
= rCandidate
.getFormTextShdwYVal();
248 mnFormTextShdwTransp
= rCandidate
.getFormTextShdwTransp();
249 meFormTextStyle
= rCandidate
.getFormTextStyle();
250 meFormTextAdjust
= rCandidate
.getFormTextAdjust();
251 meFormTextShadow
= rCandidate
.getFormTextShadow();
252 maFormTextShdwColor
= rCandidate
.getFormTextShdwColor();
261 if(rCandidate
.getOutline())
263 mpOutline
= new SdrFormTextOutlineAttribute(*rCandidate
.getOutline());
268 delete mpShadowOutline
;
273 if(rCandidate
.getShadowOutline())
275 mpShadowOutline
= new SdrFormTextOutlineAttribute(*rCandidate
.getShadowOutline());
278 mbFormTextMirror
= rCandidate
.getFormTextMirror();
279 mbFormTextOutline
= rCandidate
.getFormTextOutline();
284 bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute
& rCandidate
) const
286 return (getFormTextDistance() == rCandidate
.getFormTextDistance()
287 && getFormTextStart() == rCandidate
.getFormTextStart()
288 && getFormTextShdwXVal() == rCandidate
.getFormTextShdwXVal()
289 && getFormTextShdwYVal() == rCandidate
.getFormTextShdwYVal()
290 && getFormTextShdwTransp() == rCandidate
.getFormTextShdwTransp()
291 && getFormTextStyle() == rCandidate
.getFormTextStyle()
292 && getFormTextAdjust() == rCandidate
.getFormTextAdjust()
293 && getFormTextShadow() == rCandidate
.getFormTextShadow()
294 && getFormTextShdwColor() == rCandidate
.getFormTextShdwColor()
295 && pointerOrContentEqual(getOutline(), rCandidate
.getOutline())
296 && pointerOrContentEqual(getShadowOutline(), rCandidate
.getShadowOutline())
297 && getFormTextMirror() == rCandidate
.getFormTextMirror()
298 && getFormTextOutline() == rCandidate
.getFormTextOutline());
300 } // end of namespace attribute
301 } // end of namespace drawinglayer
303 //////////////////////////////////////////////////////////////////////////////