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/sdrrectangleprimitive2d.hxx> 26 #include <basegfx/polygon/b2dpolygontools.hxx> 27 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx> 28 #include <drawinglayer/primitive2d/groupprimitive2d.hxx> 29 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> 30 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx> 31 #include <basegfx/polygon/b2dpolygon.hxx> 32 33 ////////////////////////////////////////////////////////////////////////////// 34 35 using namespace com::sun::star; 36 37 ////////////////////////////////////////////////////////////////////////////// 38 39 namespace drawinglayer 40 { 41 namespace primitive2d 42 { create2DDecomposition(const geometry::ViewInformation2D &) const43 Primitive2DSequence SdrRectanglePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const 44 { 45 Primitive2DSequence aRetval; 46 47 // create unit outline polygon 48 const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect( 49 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), 50 getCornerRadiusX(), 51 getCornerRadiusY())); 52 53 // add fill 54 if(!getSdrLFSTAttribute().getFill().isDefault()) 55 { 56 basegfx::B2DPolyPolygon aTransformed(aUnitOutline); 57 58 aTransformed.transform(getTransform()); 59 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 60 createPolyPolygonFillPrimitive( 61 aTransformed, 62 getSdrLFSTAttribute().getFill(), 63 getSdrLFSTAttribute().getFillFloatTransGradient())); 64 } 65 else if(getForceFillForHitTest()) 66 { 67 // if no fill and it's a text frame, create a fill for HitTest and 68 // BoundRect fallback 69 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 70 createHiddenGeometryPrimitives2D( 71 true, 72 basegfx::B2DPolyPolygon(aUnitOutline), 73 getTransform())); 74 } 75 76 // add line 77 if(!getSdrLFSTAttribute().getLine().isDefault()) 78 { 79 basegfx::B2DPolygon aTransformed(aUnitOutline); 80 81 aTransformed.transform(getTransform()); 82 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 83 createPolygonLinePrimitive( 84 aTransformed, 85 getSdrLFSTAttribute().getLine(), 86 attribute::SdrLineStartEndAttribute())); 87 } 88 else if(!getForceFillForHitTest()) 89 { 90 // if initially no line is defined and it's not a text frame, create 91 // a line for HitTest and BoundRect 92 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 93 createHiddenGeometryPrimitives2D( 94 false, 95 basegfx::B2DPolyPolygon(aUnitOutline), 96 getTransform())); 97 } 98 99 // add text 100 if(!getSdrLFSTAttribute().getText().isDefault()) 101 { 102 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 103 createTextPrimitive( 104 basegfx::B2DPolyPolygon(aUnitOutline), 105 getTransform(), 106 getSdrLFSTAttribute().getText(), 107 getSdrLFSTAttribute().getLine(), 108 false, 109 false, 110 false)); 111 } 112 113 // add shadow 114 if(!getSdrLFSTAttribute().getShadow().isDefault()) 115 { 116 aRetval = createEmbeddedShadowPrimitive( 117 aRetval, 118 getSdrLFSTAttribute().getShadow()); 119 } 120 121 return aRetval; 122 } 123 SdrRectanglePrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,double fCornerRadiusX,double fCornerRadiusY,bool bForceFillForHitTest)124 SdrRectanglePrimitive2D::SdrRectanglePrimitive2D( 125 const basegfx::B2DHomMatrix& rTransform, 126 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute, 127 double fCornerRadiusX, 128 double fCornerRadiusY, 129 bool bForceFillForHitTest) 130 : BufferedDecompositionPrimitive2D(), 131 maTransform(rTransform), 132 maSdrLFSTAttribute(rSdrLFSTAttribute), 133 mfCornerRadiusX(fCornerRadiusX), 134 mfCornerRadiusY(fCornerRadiusY), 135 mbForceFillForHitTest(bForceFillForHitTest) 136 { 137 } 138 operator ==(const BasePrimitive2D & rPrimitive) const139 bool SdrRectanglePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 140 { 141 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 142 { 143 const SdrRectanglePrimitive2D& rCompare = (SdrRectanglePrimitive2D&)rPrimitive; 144 145 return (getCornerRadiusX() == rCompare.getCornerRadiusX() 146 && getCornerRadiusY() == rCompare.getCornerRadiusY() 147 && getTransform() == rCompare.getTransform() 148 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute() 149 && getForceFillForHitTest() == rCompare.getForceFillForHitTest()); 150 } 151 152 return false; 153 } 154 155 // provide unique ID 156 ImplPrimitrive2DIDBlock(SdrRectanglePrimitive2D, PRIMITIVE2D_ID_SDRRECTANGLEPRIMITIVE2D) 157 158 } // end of namespace primitive2d 159 } // end of namespace drawinglayer 160 161 ////////////////////////////////////////////////////////////////////////////// 162 // eof 163