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/sdrcaptionprimitive2d.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 32 ////////////////////////////////////////////////////////////////////////////// 33 34 using namespace com::sun::star; 35 36 ////////////////////////////////////////////////////////////////////////////// 37 38 namespace drawinglayer 39 { 40 namespace primitive2d 41 { create2DDecomposition(const geometry::ViewInformation2D &) const42 Primitive2DSequence SdrCaptionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const 43 { 44 Primitive2DSequence aRetval; 45 46 // create unit outline polygon 47 const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect( 48 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), 49 getCornerRadiusX(), 50 getCornerRadiusY())); 51 52 // add fill 53 if(getSdrLFSTAttribute().getFill().isDefault()) 54 { 55 // create invisible fill for HitTest 56 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 57 createHiddenGeometryPrimitives2D( 58 true, 59 basegfx::B2DPolyPolygon(aUnitOutline), 60 getTransform())); 61 } 62 else 63 { 64 basegfx::B2DPolyPolygon aTransformed(aUnitOutline); 65 66 aTransformed.transform(getTransform()); 67 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 68 createPolyPolygonFillPrimitive( 69 aTransformed, 70 getSdrLFSTAttribute().getFill(), 71 getSdrLFSTAttribute().getFillFloatTransGradient())); 72 } 73 74 // add line 75 if(getSdrLFSTAttribute().getLine().isDefault()) 76 { 77 // create invisible line for HitTest/BoundRect 78 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 79 createHiddenGeometryPrimitives2D( 80 false, 81 basegfx::B2DPolyPolygon(aUnitOutline), 82 getTransform())); 83 84 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 85 createHiddenGeometryPrimitives2D( 86 false, 87 basegfx::B2DPolyPolygon(getTail()), 88 getTransform())); 89 } 90 else 91 { 92 basegfx::B2DPolygon aTransformed(aUnitOutline); 93 94 aTransformed.transform(getTransform()); 95 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 96 createPolygonLinePrimitive( 97 aTransformed, 98 getSdrLFSTAttribute().getLine(), 99 attribute::SdrLineStartEndAttribute())); 100 101 aTransformed = getTail(); 102 aTransformed.transform(getTransform()); 103 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 104 createPolygonLinePrimitive( 105 aTransformed, 106 getSdrLFSTAttribute().getLine(), 107 getSdrLFSTAttribute().getLineStartEnd())); 108 } 109 110 // add text 111 if(!getSdrLFSTAttribute().getText().isDefault()) 112 { 113 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 114 createTextPrimitive( 115 basegfx::B2DPolyPolygon(aUnitOutline), 116 getTransform(), 117 getSdrLFSTAttribute().getText(), 118 getSdrLFSTAttribute().getLine(), 119 false, 120 false, 121 false)); 122 } 123 124 // add shadow 125 if(!getSdrLFSTAttribute().getShadow().isDefault()) 126 { 127 aRetval = createEmbeddedShadowPrimitive(aRetval, getSdrLFSTAttribute().getShadow()); 128 } 129 130 return aRetval; 131 } 132 SdrCaptionPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,const basegfx::B2DPolygon & rTail,double fCornerRadiusX,double fCornerRadiusY)133 SdrCaptionPrimitive2D::SdrCaptionPrimitive2D( 134 const basegfx::B2DHomMatrix& rTransform, 135 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute, 136 const basegfx::B2DPolygon& rTail, 137 double fCornerRadiusX, 138 double fCornerRadiusY) 139 : BufferedDecompositionPrimitive2D(), 140 maTransform(rTransform), 141 maSdrLFSTAttribute(rSdrLFSTAttribute), 142 maTail(rTail), 143 mfCornerRadiusX(fCornerRadiusX), 144 mfCornerRadiusY(fCornerRadiusY) 145 { 146 // transform maTail to unit polygon 147 if(getTail().count()) 148 { 149 basegfx::B2DHomMatrix aInverse(getTransform()); 150 aInverse.invert(); 151 maTail.transform(aInverse); 152 } 153 } 154 operator ==(const BasePrimitive2D & rPrimitive) const155 bool SdrCaptionPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 156 { 157 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 158 { 159 const SdrCaptionPrimitive2D& rCompare = (SdrCaptionPrimitive2D&)rPrimitive; 160 161 return (getCornerRadiusX() == rCompare.getCornerRadiusX() 162 && getCornerRadiusY() == rCompare.getCornerRadiusY() 163 && getTail() == rCompare.getTail() 164 && getTransform() == rCompare.getTransform() 165 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()); 166 } 167 168 return false; 169 } 170 171 // provide unique ID 172 ImplPrimitrive2DIDBlock(SdrCaptionPrimitive2D, PRIMITIVE2D_ID_SDRCAPTIONPRIMITIVE2D) 173 174 } // end of namespace primitive2d 175 } // end of namespace drawinglayer 176 177 ////////////////////////////////////////////////////////////////////////////// 178 // eof 179