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 #include <rtl/instance.hxx>
49 
50 
51 // helper to get line, stroke and transparence attributes from SfxItemSet
52 
53 namespace
54 {
55  basegfx::B2DLineJoin impGetB2DLineJoin(css::drawing::LineJoint eLineJoint)
56  {
57  switch(eLineJoint)
58  {
59  case css::drawing::LineJoint_BEVEL :
60  {
62  }
63  case css::drawing::LineJoint_MIDDLE :
64  case css::drawing::LineJoint_MITER :
65  {
67  }
68  case css::drawing::LineJoint_ROUND :
69  {
71  }
72  default : // css::drawing::LineJoint_NONE
73  {
74  return basegfx::B2DLineJoin::NONE; // XLINEJOINT_NONE
75  }
76  }
77  }
78 
79  sal_uInt8 impGetStrokeTransparence(bool bShadow, const SfxItemSet& rSet)
80  {
81  sal_uInt8 nRetval;
82 
83  if(bShadow)
84  {
85  nRetval = static_cast<sal_uInt8>((rSet.Get(SDRATTR_SHADOWTRANSPARENCE).GetValue() * 255) / 100);
86  }
87  else
88  {
89  nRetval = static_cast<sal_uInt8>((rSet.Get(XATTR_LINETRANSPARENCE).GetValue() * 255) / 100);
90  }
91 
92  return nRetval;
93  }
94 
95  drawinglayer::attribute::LineAttribute impGetLineAttribute(bool bShadow, const SfxItemSet& rSet)
96  {
97  basegfx::BColor aColorAttribute;
98 
99  if(bShadow)
100  {
101  const Color aShadowColor(rSet.Get(SDRATTR_SHADOWCOLOR).GetColorValue());
102  aColorAttribute = aShadowColor.getBColor();
103  }
104  else
105  {
106  const Color aLineColor(rSet.Get(XATTR_LINECOLOR).GetColorValue());
107  aColorAttribute = aLineColor.getBColor();
108  }
109 
110  const sal_uInt32 nLineWidth = rSet.Get(XATTR_LINEWIDTH).GetValue();
111  const css::drawing::LineJoint eLineJoint = rSet.Get(XATTR_LINEJOINT).GetValue();
112  const css::drawing::LineCap eLineCap = rSet.Get(XATTR_LINECAP).GetValue();
113 
115  aColorAttribute,
116  static_cast<double>(nLineWidth),
117  impGetB2DLineJoin(eLineJoint),
118  eLineCap);
119  }
120 
121  drawinglayer::attribute::StrokeAttribute impGetStrokeAttribute(const SfxItemSet& rSet)
122  {
123  const css::drawing::LineStyle eLineStyle = rSet.Get(XATTR_LINESTYLE).GetValue();
124  double fFullDotDashLen(0.0);
125  ::std::vector< double > aDotDashArray;
126 
127  if(css::drawing::LineStyle_DASH == eLineStyle)
128  {
129  const XDash& rDash = rSet.Get(XATTR_LINEDASH).GetDashValue();
130 
131  if(rDash.GetDots() || rDash.GetDashes())
132  {
133  const sal_uInt32 nLineWidth = rSet.Get(XATTR_LINEWIDTH).GetValue();
134  fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, static_cast<double>(nLineWidth));
135  }
136  }
137 
138  return drawinglayer::attribute::StrokeAttribute(aDotDashArray, fFullDotDashLen);
139  }
140 } // end of anonymous namespace
141 
142 
143 namespace drawinglayer::attribute
144 {
146  {
147  public:
148  // FormText (FontWork) Attributes
149  sal_Int32 mnFormTextDistance; // distance from line in upright direction
150  sal_Int32 mnFormTextStart; // shift from polygon start
151  sal_Int32 mnFormTextShdwXVal; // shadow distance or 10th degrees
152  sal_Int32 mnFormTextShdwYVal; // shadow distance or scaling
153  sal_uInt16 mnFormTextShdwTransp; // shadow transparence
154  XFormTextStyle meFormTextStyle; // on/off and char orientation
155  XFormTextAdjust meFormTextAdjust; // adjustment (left/right/center) and scale
157  Color maFormTextShdwColor; // shadow color
158 
159  // outline attributes; used when getFormTextOutline() is true and (for
160  // shadow) when getFormTextShadow() != XFormTextShadow::NONE
163 
164  bool mbFormTextMirror : 1; // change orientation
165  bool mbFormTextOutline : 1; // show contour of objects
166 
167  explicit ImpSdrFormTextAttribute(const SfxItemSet& rSet)
168  : mnFormTextDistance(rSet.Get(XATTR_FORMTXTDISTANCE).GetValue()),
169  mnFormTextStart(rSet.Get(XATTR_FORMTXTSTART).GetValue()),
170  mnFormTextShdwXVal(rSet.Get(XATTR_FORMTXTSHDWXVAL).GetValue()),
171  mnFormTextShdwYVal(rSet.Get(XATTR_FORMTXTSHDWYVAL).GetValue()),
172  mnFormTextShdwTransp(rSet.Get(XATTR_FORMTXTSHDWTRANSP).GetValue()),
173  meFormTextStyle(rSet.Get(XATTR_FORMTXTSTYLE).GetValue()),
174  meFormTextAdjust(rSet.Get(XATTR_FORMTXTADJUST).GetValue()),
175  meFormTextShadow(rSet.Get(XATTR_FORMTXTSHADOW).GetValue()),
176  maFormTextShdwColor(rSet.Get(XATTR_FORMTXTSHDWCOLOR).GetColorValue()),
179  {
180  if(!getFormTextOutline())
181  return;
182 
183  const StrokeAttribute aStrokeAttribute(impGetStrokeAttribute(rSet));
184 
185  // also need to prepare attributes for outlines
186  {
187  const LineAttribute aLineAttribute(impGetLineAttribute(false, rSet));
188  const sal_uInt8 nTransparence(impGetStrokeTransparence(false, rSet));
189 
190  maOutline = SdrFormTextOutlineAttribute(
191  aLineAttribute, aStrokeAttribute, nTransparence);
192  }
193 
195  {
196  // also need to prepare attributes for shadow outlines
197  const LineAttribute aLineAttribute(impGetLineAttribute(true, rSet));
198  const sal_uInt8 nTransparence(impGetStrokeTransparence(true, rSet));
199 
200  maShadowOutline = SdrFormTextOutlineAttribute(
201  aLineAttribute, aStrokeAttribute, nTransparence);
202  }
203  }
204 
206  : mnFormTextDistance(0),
207  mnFormTextStart(0),
208  mnFormTextShdwXVal(0),
209  mnFormTextShdwYVal(0),
210  mnFormTextShdwTransp(0),
211  meFormTextStyle(XFormTextStyle::NONE),
212  meFormTextAdjust(XFormTextAdjust::Center),
213  meFormTextShadow(XFormTextShadow::NONE),
214  mbFormTextMirror(false),
215  mbFormTextOutline(false)
216  {
217  }
218 
219  // data read access
220  sal_Int32 getFormTextDistance() const { return mnFormTextDistance; }
221  sal_Int32 getFormTextStart() const { return mnFormTextStart; }
222  sal_Int32 getFormTextShdwXVal() const { return mnFormTextShdwXVal; }
223  sal_Int32 getFormTextShdwYVal() const { return mnFormTextShdwYVal; }
227  const Color& getFormTextShdwColor() const { return maFormTextShdwColor; }
230  bool getFormTextMirror() const { return mbFormTextMirror; }
231  bool getFormTextOutline() const { return mbFormTextOutline; }
232 
233  // compare operator
234  bool operator==(const ImpSdrFormTextAttribute& rCandidate) const
235  {
236  return (getFormTextDistance() == rCandidate.getFormTextDistance()
237  && getFormTextStart() == rCandidate.getFormTextStart()
238  && getFormTextShdwXVal() == rCandidate.getFormTextShdwXVal()
239  && getFormTextShdwYVal() == rCandidate.getFormTextShdwYVal()
240  && mnFormTextShdwTransp == rCandidate.mnFormTextShdwTransp
241  && getFormTextStyle() == rCandidate.getFormTextStyle()
242  && getFormTextAdjust() == rCandidate.getFormTextAdjust()
243  && getFormTextShadow() == rCandidate.getFormTextShadow()
244  && getFormTextShdwColor() == rCandidate.getFormTextShdwColor()
245  && getOutline() == rCandidate.getOutline()
246  && getShadowOutline() == rCandidate.getShadowOutline()
247  && getFormTextMirror() == rCandidate.getFormTextMirror()
248  && getFormTextOutline() == rCandidate.getFormTextOutline());
249  }
250  };
251 
252  namespace
253  {
254  struct theGlobalDefault :
255  public rtl::Static< SdrFormTextAttribute::ImplType, theGlobalDefault > {};
256  }
257 
259  : mpSdrFormTextAttribute(ImpSdrFormTextAttribute(rSet))
260  {
261  }
262 
264  : mpSdrFormTextAttribute(theGlobalDefault::get())
265  {
266  }
267 
269  : mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute)
270  {
271  }
272 
274  : mpSdrFormTextAttribute(std::move(rCandidate.mpSdrFormTextAttribute))
275  {
276  }
277 
279  {
280  }
281 
283  {
284  return mpSdrFormTextAttribute.same_object(theGlobalDefault::get());
285  }
286 
288  {
290  return *this;
291  }
292 
294  {
295  mpSdrFormTextAttribute = std::move(rCandidate.mpSdrFormTextAttribute);
296  return *this;
297  }
298 
300  {
301  // tdf#87509 default attr is always != non-default attr, even with same values
302  if(rCandidate.isDefault() != isDefault())
303  return false;
304 
305  return rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute;
306  }
307 
309  {
310  return mpSdrFormTextAttribute->getFormTextDistance();
311  }
312 
314  {
315  return mpSdrFormTextAttribute->getFormTextStart();
316  }
317 
319  {
320  return mpSdrFormTextAttribute->getFormTextShdwXVal();
321  }
322 
324  {
325  return mpSdrFormTextAttribute->getFormTextShdwYVal();
326  }
327 
329  {
330  return mpSdrFormTextAttribute->getFormTextStyle();
331  }
332 
334  {
335  return mpSdrFormTextAttribute->getFormTextAdjust();
336  }
337 
339  {
340  return mpSdrFormTextAttribute->getFormTextShadow();
341  }
342 
344  {
345  return mpSdrFormTextAttribute->getFormTextShdwColor();
346  }
347 
349  {
350  return mpSdrFormTextAttribute->getOutline();
351  }
352 
354  {
355  return mpSdrFormTextAttribute->getShadowOutline();
356  }
357 
359  {
360  return mpSdrFormTextAttribute->getFormTextMirror();
361  }
362 
364  {
365  return mpSdrFormTextAttribute->getFormTextOutline();
366  }
367 
368 } // end of namespace
369 
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
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:429
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
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