1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 31 #include <svx/sdr/contact/viewcontactofsdrcaptionobj.hxx> 32 #include <svx/svdocapt.hxx> 33 #include <svx/sdr/primitive2d/sdrattributecreator.hxx> 34 #include <svx/sdr/primitive2d/sdrcaptionprimitive2d.hxx> 35 #include <basegfx/matrix/b2dhommatrixtools.hxx> 36 37 ////////////////////////////////////////////////////////////////////////////// 38 // includes for special text box shadow (SC) 39 40 #include <svl/itemset.hxx> 41 #include <svx/xhatch.hxx> 42 #include <svx/xflhtit.hxx> 43 #include <svx/xflclit.hxx> 44 #include <svx/xfltrit.hxx> 45 #include <basegfx/polygon/b2dpolygontools.hxx> 46 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx> 47 48 ////////////////////////////////////////////////////////////////////////////// 49 50 namespace sdr 51 { 52 namespace contact 53 { 54 ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj) 55 : ViewContactOfSdrRectObj(rCaptionObj) 56 { 57 } 58 59 ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj() 60 { 61 } 62 63 drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const 64 { 65 drawinglayer::primitive2d::Primitive2DSequence xRetval; 66 const SdrCaptionObj& rCaptionObj(GetCaptionObj()); 67 const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet(); 68 const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute( 69 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute( 70 rItemSet, 71 rCaptionObj.getText(0))); 72 73 // take unrotated snap rect (direct model data) for position and size 74 const Rectangle& rRectangle = rCaptionObj.GetGeoRect(); 75 const ::basegfx::B2DRange aObjectRange( 76 rRectangle.Left(), rRectangle.Top(), 77 rRectangle.Right(), rRectangle.Bottom()); 78 const GeoStat& rGeoStat(rCaptionObj.GetGeoStat()); 79 80 // fill object matrix 81 basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix( 82 aObjectRange.getWidth(), aObjectRange.getHeight(), 83 rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0, 84 rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0, 85 aObjectRange.getMinX(), aObjectRange.getMinY())); 86 87 // calculate corner radius 88 double fCornerRadiusX; 89 double fCornerRadiusY; 90 drawinglayer::primitive2d::calculateRelativeCornerRadius( 91 rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY); 92 93 // create primitive. Always create one (even if invisible) to let the decomposition 94 // of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect 95 const drawinglayer::primitive2d::Primitive2DReference xReference( 96 new drawinglayer::primitive2d::SdrCaptionPrimitive2D( 97 aObjectMatrix, 98 aAttribute, 99 rCaptionObj.getTailPolygon(), 100 fCornerRadiusX, 101 fCornerRadiusY)); 102 103 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1); 104 105 if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow()) 106 { 107 // for SC, the caption object may have a specialized shadow. The usual object shadow is off 108 // and a specialized shadow gets created here (see old paint) 109 const SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR)); 110 const sal_uInt16 nTransp(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue()); 111 const Color aShadCol(rShadColItem.GetColorValue()); 112 const XFillStyle eStyle = ((XFillStyleItem&)(rItemSet.Get(XATTR_FILLSTYLE))).GetValue(); 113 114 // Create own ItemSet and modify as needed 115 // Always hide lines for special calc shadow 116 SfxItemSet aSet(rItemSet); 117 aSet.Put(XLineStyleItem(XLINE_NONE)); 118 119 if(XFILL_HATCH == eStyle) 120 { 121 // #41666# Hatch color is set hard to shadow color 122 XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue(); 123 aHatch.SetColor(aShadCol); 124 aSet.Put(XFillHatchItem(String(),aHatch)); 125 } 126 else 127 { 128 if(XFILL_NONE != eStyle && XFILL_SOLID != eStyle) 129 { 130 // force fill to solid (for Gradient and Bitmap) 131 aSet.Put(XFillStyleItem(XFILL_SOLID)); 132 } 133 134 aSet.Put(XFillColorItem(String(),aShadCol)); 135 aSet.Put(XFillTransparenceItem(nTransp)); 136 } 137 138 // crete FillAttribute from modified ItemSet 139 const drawinglayer::attribute::SdrFillAttribute aFill( 140 drawinglayer::primitive2d::createNewSdrFillAttribute(aSet)); 141 drawinglayer::primitive2d::Primitive2DReference xSpecialShadow; 142 143 if(!aFill.isDefault() && 1.0 != aFill.getTransparence()) 144 { 145 // add shadow offset to object matrix 146 const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue()); 147 const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue()); 148 aObjectMatrix.translate(nXDist, nYDist); 149 150 // create unit outline polygon as geometry (see SdrCaptionPrimitive2D::create2DDecomposition) 151 basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect( 152 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), fCornerRadiusX, fCornerRadiusY)); 153 154 // create the specialized shadow primitive 155 xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive( 156 basegfx::B2DPolyPolygon(aUnitOutline), 157 aObjectMatrix, 158 aFill, 159 drawinglayer::attribute::FillGradientAttribute()); 160 } 161 162 if(xSpecialShadow.is()) 163 { 164 // if we really got a special shadow, create a two-element retval with the shadow 165 // behind the standard object's geometry 166 xRetval.realloc(2); 167 168 xRetval[0] = xSpecialShadow; 169 xRetval[1] = xReference; 170 } 171 } 172 173 return xRetval; 174 } 175 } // end of namespace contact 176 } // end of namespace sdr 177 178 ////////////////////////////////////////////////////////////////////////////// 179 // eof 180