LibreOffice Module svx (master) 1
sdrformtextattribute.cxx
Go to the documentation of this file.
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
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>
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
52namespace
53{
54 basegfx::B2DLineJoin impGetB2DLineJoin(css::drawing::LineJoint eLineJoint)
55 {
56 switch(eLineJoint)
57 {
58 case css::drawing::LineJoint_BEVEL :
59 {
61 }
62 case css::drawing::LineJoint_MIDDLE :
63 case css::drawing::LineJoint_MITER :
64 {
66 }
67 case css::drawing::LineJoint_ROUND :
68 {
70 }
71 default : // css::drawing::LineJoint_NONE
72 {
73 return basegfx::B2DLineJoin::NONE; // XLINEJOINT_NONE
74 }
75 }
76 }
77
78 sal_uInt8 impGetStrokeTransparence(bool bShadow, const SfxItemSet& rSet)
79 {
80 sal_uInt8 nRetval;
81
82 if(bShadow)
83 {
84 nRetval = static_cast<sal_uInt8>((rSet.Get(SDRATTR_SHADOWTRANSPARENCE).GetValue() * 255) / 100);
85 }
86 else
87 {
88 nRetval = static_cast<sal_uInt8>((rSet.Get(XATTR_LINETRANSPARENCE).GetValue() * 255) / 100);
89 }
90
91 return nRetval;
92 }
93
94 drawinglayer::attribute::LineAttribute impGetLineAttribute(bool bShadow, const SfxItemSet& rSet)
95 {
96 basegfx::BColor aColorAttribute;
97
98 if(bShadow)
99 {
100 const Color aShadowColor(rSet.Get(SDRATTR_SHADOWCOLOR).GetColorValue());
101 aColorAttribute = aShadowColor.getBColor();
102 }
103 else
104 {
105 const Color aLineColor(rSet.Get(XATTR_LINECOLOR).GetColorValue());
106 aColorAttribute = aLineColor.getBColor();
107 }
108
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();
112
114 aColorAttribute,
115 static_cast<double>(nLineWidth),
116 impGetB2DLineJoin(eLineJoint),
117 eLineCap);
118 }
119
120 drawinglayer::attribute::StrokeAttribute impGetStrokeAttribute(const SfxItemSet& rSet)
121 {
122 const css::drawing::LineStyle eLineStyle = rSet.Get(XATTR_LINESTYLE).GetValue();
123 double fFullDotDashLen(0.0);
124 ::std::vector< double > aDotDashArray;
125
126 if(css::drawing::LineStyle_DASH == eLineStyle)
127 {
128 const XDash& rDash = rSet.Get(XATTR_LINEDASH).GetDashValue();
129
130 if(rDash.GetDots() || rDash.GetDashes())
131 {
132 const sal_uInt32 nLineWidth = rSet.Get(XATTR_LINEWIDTH).GetValue();
133 fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, static_cast<double>(nLineWidth));
134 }
135 }
136
137 return drawinglayer::attribute::StrokeAttribute(std::move(aDotDashArray), fFullDotDashLen);
138 }
139} // end of anonymous namespace
140
141
143{
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
156 Color maFormTextShdwColor; // shadow color
157
158 // outline attributes; used when getFormTextOutline() is true and (for
159 // shadow) when getFormTextShadow() != XFormTextShadow::NONE
162
163 bool mbFormTextMirror : 1; // change orientation
164 bool mbFormTextOutline : 1; // show contour of objects
165
178 {
179 if(!getFormTextOutline())
180 return;
181
182 const StrokeAttribute aStrokeAttribute(impGetStrokeAttribute(rSet));
183
184 // also need to prepare attributes for outlines
185 {
186 const LineAttribute aLineAttribute(impGetLineAttribute(false, rSet));
187 const sal_uInt8 nTransparence(impGetStrokeTransparence(false, rSet));
188
190 aLineAttribute, aStrokeAttribute, nTransparence);
191 }
192
194 {
195 // also need to prepare attributes for shadow outlines
196 const LineAttribute aLineAttribute(impGetLineAttribute(true, rSet));
197 const sal_uInt8 nTransparence(impGetStrokeTransparence(true, rSet));
198
200 aLineAttribute, aStrokeAttribute, nTransparence);
201 }
202 }
203
213 mbFormTextMirror(false),
214 mbFormTextOutline(false)
215 {
216 }
217
218 // data read access
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; }
229 bool getFormTextMirror() const { return mbFormTextMirror; }
230 bool getFormTextOutline() const { return mbFormTextOutline; }
231
232 // compare operator
233 bool operator==(const ImpSdrFormTextAttribute& rCandidate) const
234 {
235 return (getFormTextDistance() == rCandidate.getFormTextDistance()
236 && getFormTextStart() == rCandidate.getFormTextStart()
237 && getFormTextShdwXVal() == rCandidate.getFormTextShdwXVal()
238 && getFormTextShdwYVal() == rCandidate.getFormTextShdwYVal()
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());
248 }
249 };
250
251 namespace
252 {
253 SdrFormTextAttribute::ImplType& theGlobalDefault()
254 {
255 static SdrFormTextAttribute::ImplType SINGLETON;
256 return SINGLETON;
257 }
258 }
259
261 : mpSdrFormTextAttribute(ImpSdrFormTextAttribute(rSet))
262 {
263 }
264
266 : mpSdrFormTextAttribute(theGlobalDefault())
267 {
268 }
269
271 : mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute)
272 {
273 }
274
276 : mpSdrFormTextAttribute(std::move(rCandidate.mpSdrFormTextAttribute))
277 {
278 }
279
281 {
282 }
283
285 {
286 return mpSdrFormTextAttribute.same_object(theGlobalDefault());
287 }
288
290 {
292 return *this;
293 }
294
296 {
297 mpSdrFormTextAttribute = std::move(rCandidate.mpSdrFormTextAttribute);
298 return *this;
299 }
300
302 {
303 // tdf#87509 default attr is always != non-default attr, even with same values
304 if(rCandidate.isDefault() != isDefault())
305 return false;
306
308 }
309
311 {
312 return mpSdrFormTextAttribute->getFormTextDistance();
313 }
314
316 {
317 return mpSdrFormTextAttribute->getFormTextStart();
318 }
319
321 {
322 return mpSdrFormTextAttribute->getFormTextShdwXVal();
323 }
324
326 {
327 return mpSdrFormTextAttribute->getFormTextShdwYVal();
328 }
329
331 {
332 return mpSdrFormTextAttribute->getFormTextStyle();
333 }
334
336 {
337 return mpSdrFormTextAttribute->getFormTextAdjust();
338 }
339
341 {
342 return mpSdrFormTextAttribute->getFormTextShadow();
343 }
344
346 {
347 return mpSdrFormTextAttribute->getFormTextShdwColor();
348 }
349
351 {
352 return mpSdrFormTextAttribute->getOutline();
353 }
354
356 {
357 return mpSdrFormTextAttribute->getShadowOutline();
358 }
359
361 {
362 return mpSdrFormTextAttribute->getFormTextMirror();
363 }
364
366 {
367 return mpSdrFormTextAttribute->getFormTextOutline();
368 }
369
370} // end of namespace
371
372/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nLineWidth
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
Definition: xdash.hxx:32
double CreateDotDashArray(::std::vector< double > &rDotDashArray, double fLineWidth) const
Definition: xattr.cxx:509
sal_uInt16 GetDots() const
Definition: xdash.hxx:55
sal_uInt16 GetDashes() const
Definition: xdash.hxx:57
bool operator==(const ImpSdrFormTextAttribute &rCandidate) const
const SdrFormTextOutlineAttribute & getShadowOutline() const
const SdrFormTextOutlineAttribute & getOutline() const
bool operator==(const SdrFormTextAttribute &rCandidate) const
o3tl::cow_wrapper< ImpSdrFormTextAttribute > ImplType
const SdrFormTextOutlineAttribute & getShadowOutline() const
SdrFormTextAttribute & operator=(const SdrFormTextAttribute &rCandidate)
const SdrFormTextOutlineAttribute & getOutline() const
bool same_object(const cow_wrapper &rOther) const
STDMETHOD() Get(VARIANT *val)=0
NONE
const char GetValue[]
static SfxItemSet & rSet
constexpr TypedWhichId< SdrPercentItem > SDRATTR_SHADOWTRANSPARENCE(SDRATTR_SHADOW_FIRST+4)
constexpr TypedWhichId< XColorItem > SDRATTR_SHADOWCOLOR(SDRATTR_SHADOW_FIRST+1)
Center
unsigned char sal_uInt8
constexpr TypedWhichId< XLineJointItem > XATTR_LINEJOINT(XATTR_LINE_FIRST+11)
constexpr TypedWhichId< XFormTextMirrorItem > XATTR_FORMTXTMIRROR(XATTR_TEXT_FIRST+4)
constexpr TypedWhichId< XFormTextStyleItem > XATTR_FORMTXTSTYLE(XATTR_TEXT_FIRST)
constexpr TypedWhichId< XFormTextStartItem > XATTR_FORMTXTSTART(XATTR_TEXT_FIRST+3)
constexpr TypedWhichId< XLineColorItem > XATTR_LINECOLOR(XATTR_LINE_FIRST+3)
constexpr TypedWhichId< XFormTextShadowTranspItem > XATTR_FORMTXTSHDWTRANSP(XATTR_TEXT_FIRST+11)
constexpr TypedWhichId< XFormTextShadowYValItem > XATTR_FORMTXTSHDWYVAL(XATTR_TEXT_FIRST+9)
constexpr TypedWhichId< XLineCapItem > XATTR_LINECAP(XATTR_LINE_FIRST+12)
constexpr TypedWhichId< XLineDashItem > XATTR_LINEDASH(XATTR_LINE_FIRST+1)
constexpr TypedWhichId< XFormTextDistanceItem > XATTR_FORMTXTDISTANCE(XATTR_TEXT_FIRST+2)
constexpr TypedWhichId< XLineWidthItem > XATTR_LINEWIDTH(XATTR_LINE_FIRST+2)
constexpr TypedWhichId< XFormTextShadowItem > XATTR_FORMTXTSHADOW(XATTR_TEXT_FIRST+6)
constexpr TypedWhichId< XFormTextOutlineItem > XATTR_FORMTXTOUTLINE(XATTR_TEXT_FIRST+5)
constexpr TypedWhichId< XFormTextShadowXValItem > XATTR_FORMTXTSHDWXVAL(XATTR_TEXT_FIRST+8)
constexpr TypedWhichId< XFormTextShadowColorItem > XATTR_FORMTXTSHDWCOLOR(XATTR_TEXT_FIRST+7)
constexpr TypedWhichId< XLineStyleItem > XATTR_LINESTYLE(XATTR_LINE_FIRST)
constexpr TypedWhichId< XFormTextAdjustItem > XATTR_FORMTXTADJUST(XATTR_TEXT_FIRST+1)
constexpr TypedWhichId< XLineTransparenceItem > XATTR_LINETRANSPARENCE(XATTR_LINE_FIRST+10)
XFormTextStyle
Definition: xenum.hxx:24
XFormTextAdjust
Definition: xenum.hxx:25
XFormTextShadow
Definition: xenum.hxx:26