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 69 // take unrotated snap rect (direct model data) for position and size 70 const Rectangle& rRectangle = rCaptionObj.GetGeoRect(); 71 const ::basegfx::B2DRange aObjectRange( 72 rRectangle.Left(), rRectangle.Top(), 73 rRectangle.Right(), rRectangle.Bottom()); 74 const GeoStat& rGeoStat(rCaptionObj.GetGeoStat()); 75 76 // fill object matrix 77 basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix( 78 aObjectRange.getWidth(), aObjectRange.getHeight(), 79 rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0, 80 rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0, 81 aObjectRange.getMinX(), aObjectRange.getMinY())); 82 83 // calculate corner radius 84 double fCornerRadiusX; 85 double fCornerRadiusY; 86 drawinglayer::primitive2d::calculateRelativeCornerRadius( 87 rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY); 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 91 const drawinglayer::primitive2d::Primitive2DReference xReference( 92 new drawinglayer::primitive2d::SdrCaptionPrimitive2D( 93 aObjectMatrix, 94 aAttribute, 95 rCaptionObj.getTailPolygon(), 96 fCornerRadiusX, 97 fCornerRadiusY)); 98 99 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1); 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 SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR)); 106 const sal_uInt16 nTransp(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue()); 107 const Color aShadCol(rShadColItem.GetColorValue()); 108 const XFillStyle eStyle = ((XFillStyleItem&)(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(XLINE_NONE)); 114 115 if(XFILL_HATCH == eStyle) 116 { 117 // #41666# Hatch color is set hard to shadow color 118 XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue(); 119 aHatch.SetColor(aShadCol); 120 aSet.Put(XFillHatchItem(String(),aHatch)); 121 } 122 else 123 { 124 if(XFILL_NONE != eStyle && XFILL_SOLID != eStyle) 125 { 126 // force fill to solid (for Gradient and Bitmap) 127 aSet.Put(XFillStyleItem(XFILL_SOLID)); 128 } 129 130 aSet.Put(XFillColorItem(String(),aShadCol)); 131 aSet.Put(XFillTransparenceItem(nTransp)); 132 } 133 134 // crete FillAttribute from modified ItemSet 135 const drawinglayer::attribute::SdrFillAttribute aFill( 136 drawinglayer::primitive2d::createNewSdrFillAttribute(aSet)); 137 drawinglayer::primitive2d::Primitive2DReference xSpecialShadow; 138 139 if(!aFill.isDefault() && 1.0 != aFill.getTransparence()) 140 { 141 // add shadow offset to object matrix 142 const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue()); 143 const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue()); 144 aObjectMatrix.translate(nXDist, nYDist); 145 146 // create unit outline polygon as geometry (see SdrCaptionPrimitive2D::create2DDecomposition) 147 basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect( 148 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), fCornerRadiusX, fCornerRadiusY)); 149 150 // create the specialized shadow primitive 151 xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive( 152 basegfx::B2DPolyPolygon(aUnitOutline), 153 aObjectMatrix, 154 aFill, 155 drawinglayer::attribute::FillGradientAttribute()); 156 } 157 158 if(xSpecialShadow.is()) 159 { 160 // if we really got a special shadow, create a two-element retval with the shadow 161 // behind the standard object's geometry 162 xRetval.realloc(2); 163 164 xRetval[0] = xSpecialShadow; 165 xRetval[1] = xReference; 166 } 167 } 168 169 return xRetval; 170 } 171 } // end of namespace contact 172 } // end of namespace sdr 173 174 ////////////////////////////////////////////////////////////////////////////// 175 // eof 176