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 #include "precompiled_svx.hxx" 23 #include <svx/sdr/primitive2d/sdrgrafprimitive2d.hxx> 24 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> 25 #include <basegfx/polygon/b2dpolygontools.hxx> 26 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx> 27 #include <drawinglayer/primitive2d/groupprimitive2d.hxx> 28 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> 29 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx> 30 #include <basegfx/polygon/b2dpolygon.hxx> 31 #include <basegfx/matrix/b2dhommatrixtools.hxx> 32 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 33 34 ////////////////////////////////////////////////////////////////////////////// 35 36 namespace drawinglayer 37 { 38 namespace primitive2d 39 { create2DDecomposition(const geometry::ViewInformation2D &) const40 Primitive2DSequence SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const 41 { 42 Primitive2DSequence aRetval; 43 44 // create unit outline polygon 45 basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon()); 46 47 // add fill, but only when graphic ist transparent 48 if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent()) 49 { 50 basegfx::B2DPolyPolygon aTransformed(aUnitOutline); 51 52 aTransformed.transform(getTransform()); 53 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 54 createPolyPolygonFillPrimitive( 55 aTransformed, 56 getSdrLFSTAttribute().getFill(), 57 getSdrLFSTAttribute().getFillFloatTransGradient())); 58 } 59 60 // add graphic content 61 if(255L != getGraphicAttr().GetTransparency()) 62 { 63 // standard graphic fill 64 const Primitive2DReference xGraphicContentPrimitive( 65 new GraphicPrimitive2D( 66 getTransform(), 67 getGraphicObject(), 68 getGraphicAttr())); 69 70 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive); 71 } 72 73 // add line 74 if(!getSdrLFSTAttribute().getLine().isDefault()) 75 { 76 // if line width is given, polygon needs to be grown by half of it to make the 77 // outline to be outside of the bitmap 78 if(0.0 != getSdrLFSTAttribute().getLine().getWidth()) 79 { 80 // decompose to get scale 81 basegfx::B2DVector aScale, aTranslate; 82 double fRotate, fShearX; 83 getTransform().decompose(aScale, aTranslate, fRotate, fShearX); 84 85 // create expanded range (add relative half line width to unit rectangle) 86 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5); 87 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0); 88 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0); 89 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY); 90 basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange)); 91 92 aExpandedUnitOutline.transform(getTransform()); 93 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 94 createPolygonLinePrimitive( 95 aExpandedUnitOutline, 96 getSdrLFSTAttribute().getLine(), 97 attribute::SdrLineStartEndAttribute())); 98 } 99 else 100 { 101 basegfx::B2DPolygon aTransformed(aUnitOutline); 102 103 aTransformed.transform(getTransform()); 104 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 105 createPolygonLinePrimitive( 106 aTransformed, 107 getSdrLFSTAttribute().getLine(), 108 attribute::SdrLineStartEndAttribute())); 109 } 110 } 111 112 // add text 113 if(!getSdrLFSTAttribute().getText().isDefault()) 114 { 115 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 116 createTextPrimitive( 117 basegfx::B2DPolyPolygon(aUnitOutline), 118 getTransform(), 119 getSdrLFSTAttribute().getText(), 120 getSdrLFSTAttribute().getLine(), 121 false, 122 false, 123 false)); 124 } 125 126 // add shadow 127 if(!getSdrLFSTAttribute().getShadow().isDefault()) 128 { 129 aRetval = createEmbeddedShadowPrimitive( 130 aRetval, 131 getSdrLFSTAttribute().getShadow()); 132 } 133 134 return aRetval; 135 } 136 SdrGrafPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,const GraphicObject & rGraphicObject,const GraphicAttr & rGraphicAttr)137 SdrGrafPrimitive2D::SdrGrafPrimitive2D( 138 const basegfx::B2DHomMatrix& rTransform, 139 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute, 140 const GraphicObject& rGraphicObject, 141 const GraphicAttr& rGraphicAttr) 142 : BufferedDecompositionPrimitive2D(), 143 maTransform(rTransform), 144 maSdrLFSTAttribute(rSdrLFSTAttribute), 145 maGraphicObject(rGraphicObject), 146 maGraphicAttr(rGraphicAttr) 147 { 148 // reset some values from GraphicAttr which are part of transformation already 149 maGraphicAttr.SetRotation(0L); 150 } 151 operator ==(const BasePrimitive2D & rPrimitive) const152 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 153 { 154 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 155 { 156 const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive; 157 158 return (getTransform() == rCompare.getTransform() 159 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute() 160 && getGraphicObject() == rCompare.getGraphicObject() 161 && getGraphicAttr() == rCompare.getGraphicAttr()); 162 } 163 164 return false; 165 } 166 isTransparent() const167 bool SdrGrafPrimitive2D::isTransparent() const 168 { 169 return ((0L != getGraphicAttr().GetTransparency()) 170 || (getGraphicObject().IsTransparent())); 171 } 172 173 // provide unique ID 174 ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D) 175 176 } // end of namespace primitive2d 177 } // end of namespace drawinglayer 178 179 ////////////////////////////////////////////////////////////////////////////// 180 // eof 181