LibreOffice Module svx (master)  1
viewcontactofsdrcaptionobj.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 
20 
22 #include <svx/svdocapt.hxx>
26 
27 
28 // includes for special text box shadow (SC)
29 
30 #include <svl/itemset.hxx>
31 #include <svx/xhatch.hxx>
32 #include <svx/xfillit0.hxx>
33 #include <svx/xflhtit.hxx>
34 #include <svx/xflclit.hxx>
35 #include <svx/xfltrit.hxx>
36 #include <svx/xlineit0.hxx>
37 #include <svx/sdmetitm.hxx>
38 #include <svx/sdprcitm.hxx>
42 #include <vcl/canvastools.hxx>
43 
44 using namespace com::sun::star;
45 
46 namespace sdr
47 {
48  namespace contact
49  {
50  ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
51  : ViewContactOfSdrRectObj(rCaptionObj)
52  {
53  }
54 
56  {
57  }
58 
60  {
62  const SdrCaptionObj& rCaptionObj(static_cast<const SdrCaptionObj&>(GetSdrObject()));
63  const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
66  rItemSet,
67  rCaptionObj.getText(0),
68  false));
69 
70  // take unrotated snap rect (direct model data) for position and size
71  const tools::Rectangle aRectangle(rCaptionObj.GetGeoRect());
72  const ::basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(aRectangle);
73  const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
74 
75  // fill object matrix
77  aObjectRange.getWidth(), aObjectRange.getHeight(),
78  rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0,
79  rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0,
80  aObjectRange.getMinX(), aObjectRange.getMinY()));
81 
82  // calculate corner radius
83  double fCornerRadiusX;
84  double fCornerRadiusY;
86  rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
87  const basegfx::B2DPolygon aTail(rCaptionObj.getTailPolygon());
88 
89  // create primitive. Always create one (even if invisible) to let the decomposition
90  // of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
93  aObjectMatrix,
94  aAttribute,
95  aTail,
96  fCornerRadiusX,
97  fCornerRadiusY));
98 
99  xRetval = drawinglayer::primitive2d::Primitive2DContainer { xReference };
100 
101  if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
102  {
103  // for SC, the caption object may have a specialized shadow. The usual object shadow is off
104  // and a specialized shadow gets created here (see old paint)
105  const XColorItem& rShadColItem = rItemSet.Get(SDRATTR_SHADOWCOLOR);
106  const sal_uInt16 nShadowTransparence(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE).GetValue());
107  const Color aShadowColor(rShadColItem.GetColorValue());
108  const drawing::FillStyle eShadowStyle = rItemSet.Get(XATTR_FILLSTYLE).GetValue();
109 
110  // Create own ItemSet and modify as needed
111  // Always hide lines for special calc shadow
112  SfxItemSet aSet(rItemSet);
113  aSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
114 
115  if(drawing::FillStyle_HATCH == eShadowStyle)
116  {
117  // #41666# Hatch color is set hard to shadow color
118  XHatch aHatch = rItemSet.Get(XATTR_FILLHATCH).GetHatchValue();
119  aHatch.SetColor(aShadowColor);
120  aSet.Put(XFillHatchItem(OUString(),aHatch));
121  }
122  else
123  {
124  if(drawing::FillStyle_SOLID != eShadowStyle)
125  {
126  // force fill to solid (for Gradient, Bitmap and *no* fill (#119750# not filled comments *have* shadow))
127  aSet.Put(XFillStyleItem(drawing::FillStyle_SOLID));
128  }
129 
130  aSet.Put(XFillColorItem(OUString(),aShadowColor));
131  aSet.Put(XFillTransparenceItem(nShadowTransparence));
132  }
133 
134  // create FillAttribute from modified ItemSet
138 
139  if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
140  {
141  // add shadow offset to object matrix
142  const sal_uInt32 nXDist(rItemSet.Get(SDRATTR_SHADOWXDIST).GetValue());
143  const sal_uInt32 nYDist(rItemSet.Get(SDRATTR_SHADOWYDIST).GetValue());
144 
145  if(nXDist || nYDist)
146  {
147  // #119750# create object and shadow outline, clip shadow outline
148  // on object outline. If there is a rest, create shadow. Do this to
149  // emulate that shadow is *not* visible behind the object for
150  // transparent object fill for comments in excel
151  basegfx::B2DPolygon aObjectOutline(
153  basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
154  fCornerRadiusX,
155  fCornerRadiusY));
156  aObjectOutline.transform(aObjectMatrix);
157 
158  // create shadow outline
159  basegfx::B2DPolygon aShadowOutline(aObjectOutline);
160  aShadowOutline.transform(
162 
163  // clip shadow outline against object outline
164  const basegfx::B2DPolyPolygon aClippedShadow(
166  aShadowOutline,
167  basegfx::B2DPolyPolygon(aObjectOutline),
168  false, // take the outside
169  false));
170 
171  if(aClippedShadow.count())
172  {
173  // if there is shadow, create the specialized shadow primitive
175  aClippedShadow,
176  aFill,
178  }
179  }
180  }
181 
182  if(xSpecialShadow.is())
183  {
184  // if we really got a special shadow, create a two-element retval with the shadow
185  // behind the standard object's geometry
186  xRetval.resize(2);
187 
188  xRetval[0] = xSpecialShadow;
189  xRetval[1] = xReference;
190  }
191  }
192 
193  return xRetval;
194  }
195  } // end of namespace contact
196 } // end of namespace sdr
197 
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define XATTR_FILLHATCH
Definition: xdef.hxx:110
virtual SdrText * getText(sal_Int32 nIndex) const override
returns the nth available text.
Definition: svdotext.cxx:2057
#define SDRATTR_SHADOWTRANSPARENCE
Definition: svddef.hxx:175
#define SDRATTR_SHADOWCOLOR
Definition: svddef.hxx:172
virtual drawinglayer::primitive2d::Primitive2DContainer createViewIndependentPrimitive2DSequence() const override
::basegfx::B2DPolygon getTailPolygon() const
Definition: svdocapt.cxx:773
attribute::SdrFillAttribute createNewSdrFillAttribute(const SfxItemSet &rSet)
void SetColor(const Color &rColor)
Definition: xhatch.hxx:46
B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
bool GetSpecialTextBoxShadow() const
Definition: svdocapt.hxx:94
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:214
Primitive2DReference createPolyPolygonFillPrimitive(const basegfx::B2DPolyPolygon &rPolyPolygon, const attribute::SdrFillAttribute &rFill, const attribute::FillGradientAttribute &rFillGradient)
const GeoStat & GetGeoStat() const
Definition: svdotext.hxx:399
const Color & GetColorValue() const
Definition: xattr.cxx:317
#define SDRATTR_SHADOWYDIST
Definition: svddef.hxx:174
attribute::SdrLineFillShadowTextAttribute createNewSdrLineFillShadowTextAttribute(const SfxItemSet &rSet, const SdrText *pText, bool bHasContent)
long GetEckenradius() const
Definition: svdotext.cxx:1707
#define SDRATTR_SHADOWXDIST
Definition: svddef.hxx:173
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
#define XATTR_FILLSTYLE
Definition: xdef.hxx:107
void calculateRelativeCornerRadius(sal_Int32 nRadius, const basegfx::B2DRange &rObjectRange, double &rfCornerRadiusX, double &rfCornerRadiusY)
void transform(const basegfx::B2DHomMatrix &rMatrix)
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt32 count() const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
B2DPolyPolygon clipPolygonOnPolyPolygon(const B2DPolygon &rCandidate, const B2DPolyPolygon &rClip, bool bInside, bool bStroke)
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1911
#define F_PI18000
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
const tools::Rectangle & GetGeoRect() const
Definition: svdotext.cxx:1467