1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "precompiled_svx.hxx" 29*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrole2primitive2d.hxx> 30*cdf0e10cSrcweir #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> 31*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 32*cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx> 33*cdf0e10cSrcweir #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx> 34*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using namespace com::sun::star; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace drawinglayer 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir namespace primitive2d 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir SdrOle2Primitive2D::SdrOle2Primitive2D( 47*cdf0e10cSrcweir const Primitive2DSequence& rOLEContent, 48*cdf0e10cSrcweir const basegfx::B2DHomMatrix& rTransform, 49*cdf0e10cSrcweir const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute) 50*cdf0e10cSrcweir : BasePrimitive2D(), 51*cdf0e10cSrcweir maOLEContent(rOLEContent), 52*cdf0e10cSrcweir maTransform(rTransform), 53*cdf0e10cSrcweir maSdrLFSTAttribute(rSdrLFSTAttribute) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir bool SdrOle2Primitive2D::operator==(const BasePrimitive2D& rPrimitive) const 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir if(BasePrimitive2D::operator==(rPrimitive)) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir const SdrOle2Primitive2D& rCompare = (SdrOle2Primitive2D&)rPrimitive; 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // #i108636# The standard operator== on two UNO sequences did not work as i 64*cdf0e10cSrcweir // would have expected; it just checks the .is() states and the data type 65*cdf0e10cSrcweir // of the sequence. What i need here is detection of equality of the whole 66*cdf0e10cSrcweir // sequence content, thus i need to use the arePrimitive2DSequencesEqual helper 67*cdf0e10cSrcweir // here instead of the operator== which lead to always returning false and thus 68*cdf0e10cSrcweir // always re-decompositions of the subcontent. 69*cdf0e10cSrcweir if(arePrimitive2DSequencesEqual(getOLEContent(), rCompare.getOLEContent()) 70*cdf0e10cSrcweir && getTransform() == rCompare.getTransform() 71*cdf0e10cSrcweir && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir return true; 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir return false; 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir Primitive2DSequence SdrOle2Primitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::create2DDecomposition 83*cdf0e10cSrcweir // should happen. For the moment we only need the OLE itself 84*cdf0e10cSrcweir // Added complete primitive preparation using getSdrLFSTAttribute() now. To not do stuff which is not needed now, it 85*cdf0e10cSrcweir // may be supressed by using a static bool. The paint version only supported text. 86*cdf0e10cSrcweir static bool bBehaveCompatibleToPaintVersion(true); 87*cdf0e10cSrcweir Primitive2DSequence aRetval; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir // create unit outline polygon 90*cdf0e10cSrcweir const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon()); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir // add fill 93*cdf0e10cSrcweir if(!bBehaveCompatibleToPaintVersion 94*cdf0e10cSrcweir && !getSdrLFSTAttribute().getFill().isDefault()) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 97*cdf0e10cSrcweir createPolyPolygonFillPrimitive( 98*cdf0e10cSrcweir basegfx::B2DPolyPolygon(aUnitOutline), 99*cdf0e10cSrcweir getTransform(), 100*cdf0e10cSrcweir getSdrLFSTAttribute().getFill(), 101*cdf0e10cSrcweir getSdrLFSTAttribute().getFillFloatTransGradient())); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // add line 105*cdf0e10cSrcweir // #i97981# condition was inverse to purpose. When being compatible to paint version, 106*cdf0e10cSrcweir // border needs to be suppressed 107*cdf0e10cSrcweir if(!bBehaveCompatibleToPaintVersion 108*cdf0e10cSrcweir && !getSdrLFSTAttribute().getLine().isDefault()) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir // if line width is given, polygon needs to be grown by half of it to make the 111*cdf0e10cSrcweir // outline to be outside of the bitmap 112*cdf0e10cSrcweir if(0.0 != getSdrLFSTAttribute().getLine().getWidth()) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir // decompose to get scale 115*cdf0e10cSrcweir basegfx::B2DVector aScale, aTranslate; 116*cdf0e10cSrcweir double fRotate, fShearX; 117*cdf0e10cSrcweir getTransform().decompose(aScale, aTranslate, fRotate, fShearX); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // create expanded range (add relative half line width to unit rectangle) 120*cdf0e10cSrcweir double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5); 121*cdf0e10cSrcweir double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0); 122*cdf0e10cSrcweir double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0); 123*cdf0e10cSrcweir const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY); 124*cdf0e10cSrcweir basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange)); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 127*cdf0e10cSrcweir createPolygonLinePrimitive( 128*cdf0e10cSrcweir aExpandedUnitOutline, 129*cdf0e10cSrcweir getTransform(), 130*cdf0e10cSrcweir getSdrLFSTAttribute().getLine(), 131*cdf0e10cSrcweir attribute::SdrLineStartEndAttribute())); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir else 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 136*cdf0e10cSrcweir createPolygonLinePrimitive( 137*cdf0e10cSrcweir aUnitOutline, 138*cdf0e10cSrcweir getTransform(), 139*cdf0e10cSrcweir getSdrLFSTAttribute().getLine(), 140*cdf0e10cSrcweir attribute::SdrLineStartEndAttribute())); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir else 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir // if initially no line is defined, create one for HitTest and BoundRect 146*cdf0e10cSrcweir appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 147*cdf0e10cSrcweir createHiddenGeometryPrimitives2D( 148*cdf0e10cSrcweir false, 149*cdf0e10cSrcweir basegfx::B2DPolyPolygon(aUnitOutline), 150*cdf0e10cSrcweir getTransform())); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // add graphic content 154*cdf0e10cSrcweir appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, getOLEContent()); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // add text, no need to supress to stay compatible since text was 157*cdf0e10cSrcweir // always supported by the old paints, too 158*cdf0e10cSrcweir if(!getSdrLFSTAttribute().getText().isDefault()) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 161*cdf0e10cSrcweir createTextPrimitive( 162*cdf0e10cSrcweir basegfx::B2DPolyPolygon(aUnitOutline), 163*cdf0e10cSrcweir getTransform(), 164*cdf0e10cSrcweir getSdrLFSTAttribute().getText(), 165*cdf0e10cSrcweir getSdrLFSTAttribute().getLine(), 166*cdf0e10cSrcweir false, 167*cdf0e10cSrcweir false, 168*cdf0e10cSrcweir false)); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // add shadow 172*cdf0e10cSrcweir if(!bBehaveCompatibleToPaintVersion 173*cdf0e10cSrcweir && !getSdrLFSTAttribute().getShadow().isDefault()) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir aRetval = createEmbeddedShadowPrimitive( 176*cdf0e10cSrcweir aRetval, 177*cdf0e10cSrcweir getSdrLFSTAttribute().getShadow()); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir return aRetval; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // provide unique ID 184*cdf0e10cSrcweir ImplPrimitrive2DIDBlock(SdrOle2Primitive2D, PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D) 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir } // end of namespace primitive2d 187*cdf0e10cSrcweir } // end of namespace drawinglayer 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 190*cdf0e10cSrcweir // eof 191