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 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 51 createPolyPolygonFillPrimitive( 52 basegfx::B2DPolyPolygon(aUnitOutline), 53 getTransform(), 54 getSdrLFSTAttribute().getFill(), 55 getSdrLFSTAttribute().getFillFloatTransGradient())); 56 } 57 58 // add graphic content 59 if(255L != getGraphicAttr().GetTransparency()) 60 { 61 // standard graphic fill 62 const Primitive2DReference xGraphicContentPrimitive( 63 new GraphicPrimitive2D( 64 getTransform(), 65 getGraphicObject(), 66 getGraphicAttr())); 67 68 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive); 69 } 70 71 // add line 72 if(!getSdrLFSTAttribute().getLine().isDefault()) 73 { 74 // if line width is given, polygon needs to be grown by half of it to make the 75 // outline to be outside of the bitmap 76 if(0.0 != getSdrLFSTAttribute().getLine().getWidth()) 77 { 78 // decompose to get scale 79 basegfx::B2DVector aScale, aTranslate; 80 double fRotate, fShearX; 81 getTransform().decompose(aScale, aTranslate, fRotate, fShearX); 82 83 // create expanded range (add relative half line width to unit rectangle) 84 double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5); 85 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0); 86 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0); 87 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY); 88 basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange)); 89 90 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 91 createPolygonLinePrimitive( 92 aExpandedUnitOutline, 93 getTransform(), 94 getSdrLFSTAttribute().getLine(), 95 attribute::SdrLineStartEndAttribute())); 96 } 97 else 98 { 99 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 100 createPolygonLinePrimitive( 101 aUnitOutline, getTransform(), 102 getSdrLFSTAttribute().getLine(), 103 attribute::SdrLineStartEndAttribute())); 104 } 105 } 106 107 // add text 108 if(!getSdrLFSTAttribute().getText().isDefault()) 109 { 110 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, 111 createTextPrimitive( 112 basegfx::B2DPolyPolygon(aUnitOutline), 113 getTransform(), 114 getSdrLFSTAttribute().getText(), 115 getSdrLFSTAttribute().getLine(), 116 false, 117 false, 118 false)); 119 } 120 121 // add shadow 122 if(!getSdrLFSTAttribute().getShadow().isDefault()) 123 { 124 aRetval = createEmbeddedShadowPrimitive( 125 aRetval, 126 getSdrLFSTAttribute().getShadow()); 127 } 128 129 return aRetval; 130 } 131 SdrGrafPrimitive2D(const basegfx::B2DHomMatrix & rTransform,const attribute::SdrLineFillShadowTextAttribute & rSdrLFSTAttribute,const GraphicObject & rGraphicObject,const GraphicAttr & rGraphicAttr)132 SdrGrafPrimitive2D::SdrGrafPrimitive2D( 133 const basegfx::B2DHomMatrix& rTransform, 134 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute, 135 const GraphicObject& rGraphicObject, 136 const GraphicAttr& rGraphicAttr) 137 : BufferedDecompositionPrimitive2D(), 138 maTransform(rTransform), 139 maSdrLFSTAttribute(rSdrLFSTAttribute), 140 maGraphicObject(rGraphicObject), 141 maGraphicAttr(rGraphicAttr) 142 { 143 // reset some values from GraphicAttr which are part of transformation already 144 maGraphicAttr.SetRotation(0L); 145 } 146 operator ==(const BasePrimitive2D & rPrimitive) const147 bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 148 { 149 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 150 { 151 const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive; 152 153 return (getTransform() == rCompare.getTransform() 154 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute() 155 && getGraphicObject() == rCompare.getGraphicObject() 156 && getGraphicAttr() == rCompare.getGraphicAttr()); 157 } 158 159 return false; 160 } 161 isTransparent() const162 bool SdrGrafPrimitive2D::isTransparent() const 163 { 164 return ((0L != getGraphicAttr().GetTransparency()) 165 || (getGraphicObject().IsTransparent())); 166 } 167 168 // provide unique ID 169 ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D) 170 171 } // end of namespace primitive2d 172 } // end of namespace drawinglayer 173 174 ////////////////////////////////////////////////////////////////////////////// 175 // eof 176