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/xftdiit.hxx>
24 #include <svx/xftstit.hxx>
25 #include <svx/xftshxy.hxx>
26 #include <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>
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 const mnFormTextDistance; // distance from line in upright direction
150  sal_Int32 const mnFormTextStart; // shift from polygon start
151  sal_Int32 const mnFormTextShdwXVal; // shadow distance or 10th degrees
152  sal_Int32 const mnFormTextShdwYVal; // shadow distance or scaling
153  sal_uInt16 const mnFormTextShdwTransp; // shadow transparence
154  XFormTextStyle const meFormTextStyle; // on/off and char orientation
155  XFormTextAdjust const meFormTextAdjust; // adjustment (left/right/center) and scale
156  XFormTextShadow const meFormTextShadow; // shadow mode
157  Color const maFormTextShdwColor; // shadow color
158 
159  // outline attributes; used when getFormTextOutline() is true and (for
160  // shadow) when getFormTextShadow() != XFormTextShadow::NONE
163 
164  bool const mbFormTextMirror : 1; // change orientation
165  bool const 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()),
177  maOutline(),
178  maShadowOutline(),
181  {
182  if(getFormTextOutline())
183  {
184  const StrokeAttribute aStrokeAttribute(impGetStrokeAttribute(rSet));
185 
186  // also need to prepare attributes for outlines
187  {
188  const LineAttribute aLineAttribute(impGetLineAttribute(false, rSet));
189  const sal_uInt8 nTransparence(impGetStrokeTransparence(false, rSet));
190 
191  maOutline = SdrFormTextOutlineAttribute(
192  aLineAttribute, aStrokeAttribute, nTransparence);
193  }
194 
196  {
197  // also need to prepare attributes for shadow outlines
198  const LineAttribute aLineAttribute(impGetLineAttribute(true, rSet));
199  const sal_uInt8 nTransparence(impGetStrokeTransparence(true, rSet));
200 
201  maShadowOutline = SdrFormTextOutlineAttribute(
202  aLineAttribute, aStrokeAttribute, nTransparence);
203  }
204  }
205  }
206 
208  : mnFormTextDistance(0),
209  mnFormTextStart(0),
210  mnFormTextShdwXVal(0),
211  mnFormTextShdwYVal(0),
212  mnFormTextShdwTransp(0),
213  meFormTextStyle(XFormTextStyle::NONE),
214  meFormTextAdjust(XFormTextAdjust::Center),
215  meFormTextShadow(XFormTextShadow::NONE),
216  maFormTextShdwColor(),
217  maOutline(),
218  maShadowOutline(),
219  mbFormTextMirror(false),
220  mbFormTextOutline(false)
221  {
222  }
223 
224  // data read access
225  sal_Int32 getFormTextDistance() const { return mnFormTextDistance; }
226  sal_Int32 getFormTextStart() const { return mnFormTextStart; }
227  sal_Int32 getFormTextShdwXVal() const { return mnFormTextShdwXVal; }
228  sal_Int32 getFormTextShdwYVal() const { return mnFormTextShdwYVal; }
232  const Color& getFormTextShdwColor() const { return maFormTextShdwColor; }
235  bool getFormTextMirror() const { return mbFormTextMirror; }
236  bool getFormTextOutline() const { return mbFormTextOutline; }
237 
238  // compare operator
239  bool operator==(const ImpSdrFormTextAttribute& rCandidate) const
240  {
241  return (getFormTextDistance() == rCandidate.getFormTextDistance()
242  && getFormTextStart() == rCandidate.getFormTextStart()
243  && getFormTextShdwXVal() == rCandidate.getFormTextShdwXVal()
244  && getFormTextShdwYVal() == rCandidate.getFormTextShdwYVal()
245  && mnFormTextShdwTransp == rCandidate.mnFormTextShdwTransp
246  && getFormTextStyle() == rCandidate.getFormTextStyle()
247  && getFormTextAdjust() == rCandidate.getFormTextAdjust()
248  && getFormTextShadow() == rCandidate.getFormTextShadow()
249  && getFormTextShdwColor() == rCandidate.getFormTextShdwColor()
250  && getOutline() == rCandidate.getOutline()
251  && getShadowOutline() == rCandidate.getShadowOutline()
252  && getFormTextMirror() == rCandidate.getFormTextMirror()
253  && getFormTextOutline() == rCandidate.getFormTextOutline());
254  }
255  };
256 
257  namespace
258  {
259  struct theGlobalDefault :
260  public rtl::Static< SdrFormTextAttribute::ImplType, theGlobalDefault > {};
261  }
262 
264  : mpSdrFormTextAttribute(ImpSdrFormTextAttribute(rSet))
265  {
266  }
267 
269  : mpSdrFormTextAttribute(theGlobalDefault::get())
270  {
271  }
272 
274  : mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute)
275  {
276  }
277 
279  : mpSdrFormTextAttribute(std::move(rCandidate.mpSdrFormTextAttribute))
280  {
281  }
282 
284  {
285  }
286 
288  {
289  return mpSdrFormTextAttribute.same_object(theGlobalDefault::get());
290  }
291 
293  {
295  return *this;
296  }
297 
299  {
300  mpSdrFormTextAttribute = std::move(rCandidate.mpSdrFormTextAttribute);
301  return *this;
302  }
303 
305  {
306  // tdf#87509 default attr is always != non-default attr, even with same values
307  if(rCandidate.isDefault() != isDefault())
308  return false;
309 
310  return rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute;
311  }
312 
314  {
315  return mpSdrFormTextAttribute->getFormTextDistance();
316  }
317 
319  {
320  return mpSdrFormTextAttribute->getFormTextStart();
321  }
322 
324  {
325  return mpSdrFormTextAttribute->getFormTextShdwXVal();
326  }
327 
329  {
330  return mpSdrFormTextAttribute->getFormTextShdwYVal();
331  }
332 
334  {
335  return mpSdrFormTextAttribute->getFormTextStyle();
336  }
337 
339  {
340  return mpSdrFormTextAttribute->getFormTextAdjust();
341  }
342 
344  {
345  return mpSdrFormTextAttribute->getFormTextShadow();
346  }
347 
349  {
350  return mpSdrFormTextAttribute->getFormTextShdwColor();
351  }
352 
354  {
355  return mpSdrFormTextAttribute->getOutline();
356  }
357 
359  {
360  return mpSdrFormTextAttribute->getShadowOutline();
361  }
362 
364  {
365  return mpSdrFormTextAttribute->getFormTextMirror();
366  }
367 
369  {
370  return mpSdrFormTextAttribute->getFormTextOutline();
371  }
372 
373 } // end of namespace
374 
375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
XFormTextStyle
Definition: xenum.hxx:24
std::string GetValue
bool operator==(const SdrFormTextAttribute &rCandidate) const
#define SDRATTR_SHADOWTRANSPARENCE
Definition: svddef.hxx:175
#define SDRATTR_SHADOWCOLOR
Definition: svddef.hxx:172
Center
const SdrFormTextOutlineAttribute & getShadowOutline() const
NONE
#define XATTR_LINECAP
Definition: xdef.hxx:102
#define XATTR_LINEJOINT
Definition: xdef.hxx:101
Definition: xdash.hxx:31
#define XATTR_FORMTXTSHADOW
Definition: xdef.hxx:137
sal_uInt16 GetDots() const
Definition: xdash.hxx:55
const SdrFormTextOutlineAttribute & getOutline() const
#define XATTR_FORMTXTSHDWXVAL
Definition: xdef.hxx:139
SdrFormTextAttribute & operator=(const SdrFormTextAttribute &rCandidate)
#define XATTR_FORMTXTADJUST
Definition: xdef.hxx:132
#define XATTR_FORMTXTSTART
Definition: xdef.hxx:134
bool same_object(const cow_wrapper &rOther) const
#define XATTR_FORMTXTOUTLINE
Definition: xdef.hxx:136
#define XATTR_LINESTYLE
Definition: xdef.hxx:90
XFormTextShadow
Definition: xenum.hxx:26
#define XATTR_FORMTXTSHDWYVAL
Definition: xdef.hxx:140
#define XATTR_FORMTXTSHDWCOLOR
Definition: xdef.hxx:138
double CreateDotDashArray(::std::vector< double > &rDotDashArray, double fLineWidth) const
Definition: xattr.cxx:437
#define XATTR_LINEDASH
Definition: xdef.hxx:91
sal_Int32 nLineWidth
#define XATTR_LINEWIDTH
Definition: xdef.hxx:92
#define XATTR_FORMTXTDISTANCE
Definition: xdef.hxx:133
const SdrFormTextOutlineAttribute & getShadowOutline() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
unsigned char sal_uInt8
basegfx::BColor getBColor() const
#define XATTR_FORMTXTSTYLE
Definition: xdef.hxx:131
#define XATTR_FORMTXTMIRROR
Definition: xdef.hxx:135
#define XATTR_LINECOLOR
Definition: xdef.hxx:93
bool operator==(const ImpSdrFormTextAttribute &rCandidate) const
#define XATTR_FORMTXTSHDWTRANSP
Definition: xdef.hxx:142
#define XATTR_LINETRANSPARENCE
Definition: xdef.hxx:100
STDMETHOD() Get(VARIANT *val)=0
XFormTextAdjust
Definition: xenum.hxx:25
const SdrFormTextOutlineAttribute & getOutline() const
sal_uInt16 GetDashes() const
Definition: xdash.hxx:57