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 
52 namespace
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 
142 namespace drawinglayer::attribute
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 
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()),
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 
189  maOutline = SdrFormTextOutlineAttribute(
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 
199  maShadowOutline = SdrFormTextOutlineAttribute(
200  aLineAttribute, aStrokeAttribute, nTransparence);
201  }
202  }
203 
205  : mnFormTextDistance(0),
206  mnFormTextStart(0),
207  mnFormTextShdwXVal(0),
208  mnFormTextShdwYVal(0),
209  mnFormTextShdwTransp(0),
210  meFormTextStyle(XFormTextStyle::NONE),
211  meFormTextAdjust(XFormTextAdjust::Center),
212  meFormTextShadow(XFormTextShadow::NONE),
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; }
226  const Color& getFormTextShdwColor() const { return maFormTextShdwColor; }
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()
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());
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 
307  return rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute;
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: */
constexpr TypedWhichId< SdrPercentItem > SDRATTR_SHADOWTRANSPARENCE(SDRATTR_SHADOW_FIRST+4)
XFormTextStyle
Definition: xenum.hxx:24
constexpr TypedWhichId< XLineJointItem > XATTR_LINEJOINT(XATTR_LINE_FIRST+11)
std::string GetValue
constexpr TypedWhichId< XFormTextOutlineItem > XATTR_FORMTXTOUTLINE(XATTR_TEXT_FIRST+5)
bool operator==(const SdrFormTextAttribute &rCandidate) const
constexpr TypedWhichId< XLineWidthItem > XATTR_LINEWIDTH(XATTR_LINE_FIRST+2)
constexpr TypedWhichId< XFormTextShadowTranspItem > XATTR_FORMTXTSHDWTRANSP(XATTR_TEXT_FIRST+11)
constexpr TypedWhichId< XLineStyleItem > XATTR_LINESTYLE(XATTR_LINE_FIRST)
constexpr TypedWhichId< XLineDashItem > XATTR_LINEDASH(XATTR_LINE_FIRST+1)
Center
const SdrFormTextOutlineAttribute & getShadowOutline() const
constexpr TypedWhichId< XFormTextDistanceItem > XATTR_FORMTXTDISTANCE(XATTR_TEXT_FIRST+2)
NONE
constexpr TypedWhichId< XLineTransparenceItem > XATTR_LINETRANSPARENCE(XATTR_LINE_FIRST+10)
Definition: xdash.hxx:31
constexpr TypedWhichId< XColorItem > SDRATTR_SHADOWCOLOR(SDRATTR_SHADOW_FIRST+1)
sal_uInt16 GetDots() const
Definition: xdash.hxx:55
const SdrFormTextOutlineAttribute & getOutline() const
SdrFormTextAttribute & operator=(const SdrFormTextAttribute &rCandidate)
constexpr TypedWhichId< XFormTextStyleItem > XATTR_FORMTXTSTYLE(XATTR_TEXT_FIRST)
bool same_object(const cow_wrapper &rOther) const
XFormTextShadow
Definition: xenum.hxx:26
constexpr TypedWhichId< XFormTextShadowXValItem > XATTR_FORMTXTSHDWXVAL(XATTR_TEXT_FIRST+8)
constexpr TypedWhichId< XFormTextShadowItem > XATTR_FORMTXTSHADOW(XATTR_TEXT_FIRST+6)
constexpr TypedWhichId< XFormTextAdjustItem > XATTR_FORMTXTADJUST(XATTR_TEXT_FIRST+1)
double CreateDotDashArray(::std::vector< double > &rDotDashArray, double fLineWidth) const
Definition: xattr.cxx:440
sal_Int32 nLineWidth
const SdrFormTextOutlineAttribute & getShadowOutline() const
constexpr TypedWhichId< XFormTextStartItem > XATTR_FORMTXTSTART(XATTR_TEXT_FIRST+3)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
unsigned char sal_uInt8
constexpr TypedWhichId< XFormTextShadowYValItem > XATTR_FORMTXTSHDWYVAL(XATTR_TEXT_FIRST+9)
constexpr TypedWhichId< XLineCapItem > XATTR_LINECAP(XATTR_LINE_FIRST+12)
basegfx::BColor getBColor() const
o3tl::cow_wrapper< ImpSdrFormTextAttribute > ImplType
constexpr TypedWhichId< XFormTextMirrorItem > XATTR_FORMTXTMIRROR(XATTR_TEXT_FIRST+4)
bool operator==(const ImpSdrFormTextAttribute &rCandidate) const
constexpr TypedWhichId< XLineColorItem > XATTR_LINECOLOR(XATTR_LINE_FIRST+3)
STDMETHOD() Get(VARIANT *val)=0
XFormTextAdjust
Definition: xenum.hxx:25
const SdrFormTextOutlineAttribute & getOutline() const
constexpr TypedWhichId< XFormTextShadowColorItem > XATTR_FORMTXTSHDWCOLOR(XATTR_TEXT_FIRST+7)
sal_uInt16 GetDashes() const
Definition: xdash.hxx:57
bool m_bDetectedRangeSegmentation false