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 #include "precompiled_svx.hxx" 25 #include <svx/sdr/primitive2d/sdrole2primitive2d.hxx> 26 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> 27 #include <basegfx/polygon/b2dpolygontools.hxx> 28 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx> 29 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx> 30 #include <basegfx/polygon/b2dpolygon.hxx> 31 32 ////////////////////////////////////////////////////////////////////////////// 33 34 using namespace com::sun::star; 35 36 ////////////////////////////////////////////////////////////////////////////// 37 38 namespace drawinglayer 39 { 40 namespace primitive2d 41 { SdrOle2Primitive2D(const Primitive2DSequence & rOLEContent,const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute)42 SdrOle2Primitive2D::SdrOle2Primitive2D( 43 const Primitive2DSequence& rOLEContent, 44 const basegfx::B2DHomMatrix& rTransform, 45 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute) 46 : BasePrimitive2D(), 47 maOLEContent(rOLEContent), 48 maTransform(rTransform), 49 maSdrLFSTAttribute(rSdrLFSTAttribute) 50 { 51 } 52 operator ==(const BasePrimitive2D & rPrimitive) const53 bool SdrOle2Primitive2D::operator==(const BasePrimitive2D& rPrimitive) const 54 { 55 if(BasePrimitive2D::operator==(rPrimitive)) 56 { 57 const SdrOle2Primitive2D& rCompare = (SdrOle2Primitive2D&)rPrimitive; 58 59 // #i108636# The standard operator== on two UNO sequences did not work as i 60 // would have expected; it just checks the .is() states and the data type 61 // of the sequence. What i need here is detection of equality of the whole 62 // sequence content, thus i need to use the arePrimitive2DSequencesEqual helper 63 // here instead of the operator== which lead to always returning false and thus 64 // always re-decompositions of the subcontent. 65 if(arePrimitive2DSequencesEqual(getOLEContent(), rCompare.getOLEContent()) 66 && getTransform() == rCompare.getTransform() 67 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()) 68 { 69 return true; 70 } 71 } 72 73 return false; 74 } 75 get2DDecomposition(const geometry::ViewInformation2D &) const76 Primitive2DSequence SdrOle2Primitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const 77 { 78 // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::create2DDecomposition 79 // should happen. For the moment we only need the OLE itself 80 // Added complete primitive preparation using getSdrLFSTAttribute() now. To not do stuff which is not needed now, it 81 // may be suppressed by using a static bool. The paint version only supported text. 82 static bool bBehaveCompatibleToPaintVersion(false); 83 Primitive2DSequence aRetval; 84 85 // create unit outline polygon 86 const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon()); 87 88 // add fill 89 if(!bBehaveCompatibleToPaintVersion 90 && !getSdrLFSTAttribute().getFill().isDefault()) 91 { 92 basegfx::B2DPolyPolygon aTransformed(aUnitOutline); 93 94 aTransformed.transform(getTransform()); 95 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 96 createPolyPolygonFillPrimitive( 97 aTransformed, 98 getSdrLFSTAttribute().getFill(), 99 getSdrLFSTAttribute().getFillFloatTransGradient())); 100 } 101 102 // add line 103 // #i97981# condition was inverse to purpose. When being compatible to paint version, 104 // border needs to be suppressed 105 if(!bBehaveCompatibleToPaintVersion 106 && !getSdrLFSTAttribute().getLine().isDefault()) 107 { 108 // if line width is given, polygon needs to be grown by half of it to make the 109 // outline to be outside of the bitmap 110 if(0.0 != getSdrLFSTAttribute().getLine().getWidth()) 111 { 112 // decompose to get scale 113 basegfx::B2DVector aScale, aTranslate; 114 double fRotate, fShearX; 115 getTransform().decompose(aScale, aTranslate, fRotate, fShearX); 116 117 // create expanded range (add relative half line width to unit rectangle) 118 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5); 119 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0); 120 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0); 121 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY); 122 basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange)); 123 124 aExpandedUnitOutline.transform(getTransform()); 125 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 126 createPolygonLinePrimitive( 127 aExpandedUnitOutline, 128 getSdrLFSTAttribute().getLine(), 129 attribute::SdrLineStartEndAttribute())); 130 } 131 else 132 { 133 basegfx::B2DPolygon aTransformed(aUnitOutline); 134 135 aTransformed.transform(getTransform()); 136 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 137 createPolygonLinePrimitive( 138 aTransformed, 139 getSdrLFSTAttribute().getLine(), 140 attribute::SdrLineStartEndAttribute())); 141 } 142 } 143 else 144 { 145 // if initially no line is defined, create one for HitTest and BoundRect 146 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 147 createHiddenGeometryPrimitives2D( 148 false, 149 basegfx::B2DPolyPolygon(aUnitOutline), 150 getTransform())); 151 } 152 153 // add graphic content 154 appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, getOLEContent()); 155 156 // add text, no need to suppress to stay compatible since text was 157 // always supported by the old paints, too 158 if(!getSdrLFSTAttribute().getText().isDefault()) 159 { 160 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 161 createTextPrimitive( 162 basegfx::B2DPolyPolygon(aUnitOutline), 163 getTransform(), 164 getSdrLFSTAttribute().getText(), 165 getSdrLFSTAttribute().getLine(), 166 false, 167 false, 168 false)); 169 } 170 171 // add shadow 172 if(!bBehaveCompatibleToPaintVersion 173 && !getSdrLFSTAttribute().getShadow().isDefault()) 174 { 175 aRetval = createEmbeddedShadowPrimitive( 176 aRetval, 177 getSdrLFSTAttribute().getShadow()); 178 } 179 180 return aRetval; 181 } 182 183 // provide unique ID 184 ImplPrimitrive2DIDBlock(SdrOle2Primitive2D, PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D) 185 186 } // end of namespace primitive2d 187 } // end of namespace drawinglayer 188 189 ////////////////////////////////////////////////////////////////////////////// 190 // eof 191