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::contact
47 {
48  ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
49  : ViewContactOfSdrRectObj(rCaptionObj)
50  {
51  }
52 
54  {
55  }
56 
58  {
60  const SdrCaptionObj& rCaptionObj(static_cast<const SdrCaptionObj&>(GetSdrObject()));
61  const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
64  rItemSet,
65  rCaptionObj.getText(0),
66  false));
67 
68  // take unrotated snap rect (direct model data) for position and size
69  const tools::Rectangle aRectangle(rCaptionObj.GetGeoRect());
70  const ::basegfx::B2DRange aObjectRange = vcl::unotools::b2DRectangleFromRectangle(aRectangle);
71  const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
72 
73  // fill object matrix
75  aObjectRange.getWidth(), aObjectRange.getHeight(),
76  rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0,
77  rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0,
78  aObjectRange.getMinX(), aObjectRange.getMinY()));
79 
80  // calculate corner radius
81  double fCornerRadiusX;
82  double fCornerRadiusY;
84  rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
85  const basegfx::B2DPolygon aTail(rCaptionObj.getTailPolygon());
86 
87  // create primitive. Always create one (even if invisible) to let the decomposition
88  // of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
91  aObjectMatrix,
92  aAttribute,
93  aTail,
94  fCornerRadiusX,
95  fCornerRadiusY));
96 
97  xRetval = drawinglayer::primitive2d::Primitive2DContainer { xReference };
98 
99  if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
100  {
101  // for SC, the caption object may have a specialized shadow. The usual object shadow is off
102  // and a specialized shadow gets created here (see old paint)
103  const XColorItem& rShadColItem = rItemSet.Get(SDRATTR_SHADOWCOLOR);
104  const sal_uInt16 nShadowTransparence(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE).GetValue());
105  const Color aShadowColor(rShadColItem.GetColorValue());
106  const drawing::FillStyle eShadowStyle = rItemSet.Get(XATTR_FILLSTYLE).GetValue();
107 
108  // Create own ItemSet and modify as needed
109  // Always hide lines for special calc shadow
110  SfxItemSet aSet(rItemSet);
111  aSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
112 
113  if(drawing::FillStyle_HATCH == eShadowStyle)
114  {
115  // #41666# Hatch color is set hard to shadow color
116  XHatch aHatch = rItemSet.Get(XATTR_FILLHATCH).GetHatchValue();
117  aHatch.SetColor(aShadowColor);
118  aSet.Put(XFillHatchItem(OUString(),aHatch));
119  }
120  else
121  {
122  if(drawing::FillStyle_SOLID != eShadowStyle)
123  {
124  // force fill to solid (for Gradient, Bitmap and *no* fill (#119750# not filled comments *have* shadow))
125  aSet.Put(XFillStyleItem(drawing::FillStyle_SOLID));
126  }
127 
128  aSet.Put(XFillColorItem(OUString(),aShadowColor));
129  aSet.Put(XFillTransparenceItem(nShadowTransparence));
130  }
131 
132  // create FillAttribute from modified ItemSet
136 
137  if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
138  {
139  // add shadow offset to object matrix
140  const sal_uInt32 nXDist(rItemSet.Get(SDRATTR_SHADOWXDIST).GetValue());
141  const sal_uInt32 nYDist(rItemSet.Get(SDRATTR_SHADOWYDIST).GetValue());
142 
143  if(nXDist || nYDist)
144  {
145  // #119750# create object and shadow outline, clip shadow outline
146  // on object outline. If there is a rest, create shadow. Do this to
147  // emulate that shadow is *not* visible behind the object for
148  // transparent object fill for comments in excel
149  basegfx::B2DPolygon aObjectOutline(
151  basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
152  fCornerRadiusX,
153  fCornerRadiusY));
154  aObjectOutline.transform(aObjectMatrix);
155 
156  // create shadow outline
157  basegfx::B2DPolygon aShadowOutline(aObjectOutline);
158  aShadowOutline.transform(
160 
161  // clip shadow outline against object outline
162  const basegfx::B2DPolyPolygon aClippedShadow(
164  aShadowOutline,
165  basegfx::B2DPolyPolygon(aObjectOutline),
166  false, // take the outside
167  false));
168 
169  if(aClippedShadow.count())
170  {
171  // if there is shadow, create the specialized shadow primitive
173  aClippedShadow,
174  aFill,
176  }
177  }
178  }
179 
180  if(xSpecialShadow.is())
181  {
182  // if we really got a special shadow, create a two-element retval with the shadow
183  // behind the standard object's geometry
184  xRetval.resize(2);
185 
186  xRetval[0] = xSpecialShadow;
187  xRetval[1] = xReference;
188  }
189  }
190 
191  return xRetval;
192  }
193 
194 } // end of namespace
195 
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define XATTR_FILLHATCH
Definition: xdef.hxx:110
attribute::SdrFillAttribute createNewSdrFillAttribute(const SfxItemSet &rSet)
virtual SdrText * getText(sal_Int32 nIndex) const override
returns the nth available text.
Definition: svdotext.cxx:2066
#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
void SetColor(const Color &rColor)
Definition: xhatch.hxx:45
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
const GeoStat & GetGeoStat() const
Definition: svdotext.hxx:399
const Color & GetColorValue() const
Definition: xattr.cxx:318
#define SDRATTR_SHADOWYDIST
Definition: svddef.hxx:174
attribute::SdrLineFillShadowTextAttribute createNewSdrLineFillShadowTextAttribute(const SfxItemSet &rSet, const SdrText *pText, bool bHasContent)
long GetEckenradius() const
Definition: svdotext.cxx:1716
#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)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
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:1908
#define F_PI18000
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
const tools::Rectangle & GetGeoRect() const
Definition: svdotext.cxx:1476
Primitive2DReference createPolyPolygonFillPrimitive(const basegfx::B2DPolyPolygon &rPolyPolygon, const attribute::SdrFillAttribute &rFill, const attribute::FillGradientAttribute &rFillGradient)