xref: /trunk/main/svx/source/sdr/contact/viewcontactofsdrcaptionobj.cxx (revision 796936d9d7acb35dc23ec9ca24086d860c86d46c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/sdr/contact/viewcontactofsdrcaptionobj.hxx>
28 #include <svx/svdocapt.hxx>
29 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
30 #include <svx/sdr/primitive2d/sdrcaptionprimitive2d.hxx>
31 #include <basegfx/matrix/b2dhommatrixtools.hxx>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 // includes for special text box shadow (SC)
35 
36 #include <svl/itemset.hxx>
37 #include <svx/xhatch.hxx>
38 #include <svx/xflhtit.hxx>
39 #include <svx/xflclit.hxx>
40 #include <svx/xfltrit.hxx>
41 #include <basegfx/polygon/b2dpolygontools.hxx>
42 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
43 
44 //////////////////////////////////////////////////////////////////////////////
45 
46 namespace sdr
47 {
48     namespace contact
49     {
50         ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
51         :   ViewContactOfSdrRectObj(rCaptionObj)
52         {
53         }
54 
55         ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
56         {
57         }
58 
59         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
60         {
61             drawinglayer::primitive2d::Primitive2DSequence xRetval;
62             const SdrCaptionObj& rCaptionObj(GetCaptionObj());
63             const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
64             const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
65                 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
66                     rItemSet,
67                     rCaptionObj.getText(0),
68                     false));
69 
70             // take unrotated snap rect (direct model data) for position and size
71             const Rectangle& rRectangle = rCaptionObj.GetGeoRect();
72             const ::basegfx::B2DRange aObjectRange(
73                 rRectangle.Left(), rRectangle.Top(),
74                 rRectangle.Right(), rRectangle.Bottom());
75             const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
76 
77             // fill object matrix
78             basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
79                 aObjectRange.getWidth(), aObjectRange.getHeight(),
80                 rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
81                 rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
82                 aObjectRange.getMinX(), aObjectRange.getMinY()));
83 
84             // calculate corner radius
85             double fCornerRadiusX;
86             double fCornerRadiusY;
87             drawinglayer::primitive2d::calculateRelativeCornerRadius(
88                 rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
89 
90             // create primitive. Always create one (even if invisible) to let the decomposition
91             // of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
92             const drawinglayer::primitive2d::Primitive2DReference xReference(
93                 new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
94                     aObjectMatrix,
95                     aAttribute,
96                     rCaptionObj.getTailPolygon(),
97                     fCornerRadiusX,
98                     fCornerRadiusY));
99 
100             xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
101 
102             if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
103             {
104                 // for SC, the caption object may have a specialized shadow. The usual object shadow is off
105                 // and a specialized shadow gets created here (see old paint)
106                 const SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR));
107                 const sal_uInt16 nTransp(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
108                 const Color aShadCol(rShadColItem.GetColorValue());
109                 const XFillStyle eStyle = ((XFillStyleItem&)(rItemSet.Get(XATTR_FILLSTYLE))).GetValue();
110 
111                 // Create own ItemSet and modify as needed
112                 // Always hide lines for special calc shadow
113                 SfxItemSet aSet(rItemSet);
114                 aSet.Put(XLineStyleItem(XLINE_NONE));
115 
116                 if(XFILL_HATCH == eStyle)
117                 {
118                     // #41666# Hatch color is set hard to shadow color
119                     XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue();
120                     aHatch.SetColor(aShadCol);
121                     aSet.Put(XFillHatchItem(String(),aHatch));
122                 }
123                 else
124                 {
125                     if(XFILL_NONE != eStyle && XFILL_SOLID != eStyle)
126                     {
127                         // force fill to solid (for Gradient and Bitmap)
128                         aSet.Put(XFillStyleItem(XFILL_SOLID));
129                     }
130 
131                     aSet.Put(XFillColorItem(String(),aShadCol));
132                     aSet.Put(XFillTransparenceItem(nTransp));
133                 }
134 
135                 // crete FillAttribute from modified ItemSet
136                 const drawinglayer::attribute::SdrFillAttribute aFill(
137                     drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
138                 drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
139 
140                 if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
141                 {
142                     // add shadow offset to object matrix
143                     const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
144                     const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
145                     aObjectMatrix.translate(nXDist, nYDist);
146 
147                     // create unit outline polygon as geometry (see SdrCaptionPrimitive2D::create2DDecomposition)
148                     basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
149                         basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), fCornerRadiusX, fCornerRadiusY));
150 
151                     // create the specialized shadow primitive
152                     xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
153                         basegfx::B2DPolyPolygon(aUnitOutline),
154                         aObjectMatrix,
155                         aFill,
156                         drawinglayer::attribute::FillGradientAttribute());
157                 }
158 
159                 if(xSpecialShadow.is())
160                 {
161                     // if we really got a special shadow, create a two-element retval with the shadow
162                     // behind the standard object's geometry
163                     xRetval.realloc(2);
164 
165                     xRetval[0] = xSpecialShadow;
166                     xRetval[1] = xReference;
167                 }
168             }
169 
170             return xRetval;
171         }
172     } // end of namespace contact
173 } // end of namespace sdr
174 
175 //////////////////////////////////////////////////////////////////////////////
176 // eof
177