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 supressed 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 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 93 createPolyPolygonFillPrimitive( 94 basegfx::B2DPolyPolygon(aUnitOutline), 95 getTransform(), 96 getSdrLFSTAttribute().getFill(), 97 getSdrLFSTAttribute().getFillFloatTransGradient())); 98 } 99 100 // add line 101 // #i97981# condition was inverse to purpose. When being compatible to paint version, 102 // border needs to be suppressed 103 if(!bBehaveCompatibleToPaintVersion 104 && !getSdrLFSTAttribute().getLine().isDefault()) 105 { 106 // if line width is given, polygon needs to be grown by half of it to make the 107 // outline to be outside of the bitmap 108 if(0.0 != getSdrLFSTAttribute().getLine().getWidth()) 109 { 110 // decompose to get scale 111 basegfx::B2DVector aScale, aTranslate; 112 double fRotate, fShearX; 113 getTransform().decompose(aScale, aTranslate, fRotate, fShearX); 114 115 // create expanded range (add relative half line width to unit rectangle) 116 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5); 117 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0); 118 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0); 119 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY); 120 basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange)); 121 122 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 123 createPolygonLinePrimitive( 124 aExpandedUnitOutline, 125 getTransform(), 126 getSdrLFSTAttribute().getLine(), 127 attribute::SdrLineStartEndAttribute())); 128 } 129 else 130 { 131 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 132 createPolygonLinePrimitive( 133 aUnitOutline, 134 getTransform(), 135 getSdrLFSTAttribute().getLine(), 136 attribute::SdrLineStartEndAttribute())); 137 } 138 } 139 else 140 { 141 // if initially no line is defined, create one for HitTest and BoundRect 142 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 143 createHiddenGeometryPrimitives2D( 144 false, 145 basegfx::B2DPolyPolygon(aUnitOutline), 146 getTransform())); 147 } 148 149 // add graphic content 150 appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, getOLEContent()); 151 152 // add text, no need to supress to stay compatible since text was 153 // always supported by the old paints, too 154 if(!getSdrLFSTAttribute().getText().isDefault()) 155 { 156 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 157 createTextPrimitive( 158 basegfx::B2DPolyPolygon(aUnitOutline), 159 getTransform(), 160 getSdrLFSTAttribute().getText(), 161 getSdrLFSTAttribute().getLine(), 162 false, 163 false, 164 false)); 165 } 166 167 // add shadow 168 if(!bBehaveCompatibleToPaintVersion 169 && !getSdrLFSTAttribute().getShadow().isDefault()) 170 { 171 aRetval = createEmbeddedShadowPrimitive( 172 aRetval, 173 getSdrLFSTAttribute().getShadow()); 174 } 175 176 return aRetval; 177 } 178 179 // provide unique ID 180 ImplPrimitrive2DIDBlock(SdrOle2Primitive2D, PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D) 181 182 } // end of namespace primitive2d 183 } // end of namespace drawinglayer 184 185 ////////////////////////////////////////////////////////////////////////////// 186 // eof 187