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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_drawinglayer.hxx" 26 27 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> 28 #include <drawinglayer/primitive2d/cropprimitive2d.hxx> 29 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 30 #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 31 #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx> 32 #include <basegfx/matrix/b2dhommatrixtools.hxx> 33 #include <vcl/svapp.hxx> 34 #include <vcl/outdev.hxx> 35 36 ////////////////////////////////////////////////////////////////////////////// 37 38 namespace drawinglayer 39 { 40 namespace primitive2d 41 { 42 Primitive2DSequence GraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& 43 #ifdef USE_DEBUG_CODE_TO_TEST_METAFILE_DECOMPOSE 44 rViewInformation 45 #else 46 /*rViewInformation*/ 47 #endif // USE_DEBUG_CODE_TO_TEST_METAFILE_DECOMPOSE 48 ) const 49 { 50 Primitive2DSequence aRetval; 51 52 if(255L != getGraphicAttr().GetTransparency()) 53 { 54 // do not apply mirroring from GraphicAttr to the Metafile by calling 55 // GetTransformedGraphic, this will try to mirror the Metafile using Scale() 56 // at the Metafile. This again calls Scale at the single MetaFile actions, 57 // but this implementation never worked. I reworked that implementations, 58 // but for security reasons i will try not to use it. 59 basegfx::B2DHomMatrix aTransform(getTransform()); 60 61 if(getGraphicAttr().IsMirrored()) 62 { 63 // content needs mirroring 64 const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_HORZ); 65 const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_VERT); 66 67 // mirror by applying negative scale to the unit primitive and 68 // applying the object transformation on it. 69 aTransform = basegfx::tools::createScaleB2DHomMatrix( 70 bHMirr ? -1.0 : 1.0, 71 bVMirr ? -1.0 : 1.0); 72 aTransform.translate( 73 bHMirr ? 1.0 : 0.0, 74 bVMirr ? 1.0 : 0.0); 75 aTransform = getTransform() * aTransform; 76 } 77 78 // Get transformed graphic. Suppress rotation and cropping, only filtering is needed 79 // here (and may be replaced later on). Cropping is handled below as mask primitive (if set). 80 // Also need to suppress mirroring, it is part of the transformation now (see above). 81 GraphicAttr aSuppressGraphicAttr(getGraphicAttr()); 82 aSuppressGraphicAttr.SetCrop(0, 0, 0, 0); 83 aSuppressGraphicAttr.SetRotation(0); 84 aSuppressGraphicAttr.SetMirrorFlags(0); 85 86 const GraphicObject& rGraphicObject = getGraphicObject(); 87 const Graphic aTransformedGraphic(rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr)); 88 89 aRetval = create2DDecompositionOfGraphic( 90 aTransformedGraphic, 91 aTransform); 92 93 if(aRetval.getLength()) 94 { 95 // check for cropping 96 if(getGraphicAttr().IsCropped()) 97 { 98 // calculate scalings between real image size and logic object size. This 99 // is necessary since the crop values are relative to original bitmap size 100 const basegfx::B2DVector aObjectScale(aTransform * basegfx::B2DVector(1.0, 1.0)); 101 const basegfx::B2DVector aCropScaleFactor( 102 rGraphicObject.calculateCropScaling( 103 aObjectScale.getX(), 104 aObjectScale.getY(), 105 getGraphicAttr().GetLeftCrop(), 106 getGraphicAttr().GetTopCrop(), 107 getGraphicAttr().GetRightCrop(), 108 getGraphicAttr().GetBottomCrop())); 109 110 // embed content in cropPrimitive 111 Primitive2DReference xPrimitive( 112 new CropPrimitive2D( 113 aRetval, 114 aTransform, 115 getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(), 116 getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(), 117 getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(), 118 getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY())); 119 120 aRetval = Primitive2DSequence(&xPrimitive, 1); 121 } 122 } 123 } 124 125 return aRetval; 126 } 127 128 GraphicPrimitive2D::GraphicPrimitive2D( 129 const basegfx::B2DHomMatrix& rTransform, 130 const GraphicObject& rGraphicObject, 131 const GraphicAttr& rGraphicAttr) 132 : BufferedDecompositionPrimitive2D(), 133 maTransform(rTransform), 134 maGraphicObject(rGraphicObject), 135 maGraphicAttr(rGraphicAttr) 136 { 137 } 138 139 GraphicPrimitive2D::GraphicPrimitive2D( 140 const basegfx::B2DHomMatrix& rTransform, 141 const GraphicObject& rGraphicObject) 142 : BufferedDecompositionPrimitive2D(), 143 maTransform(rTransform), 144 maGraphicObject(rGraphicObject), 145 maGraphicAttr() 146 { 147 } 148 149 bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 150 { 151 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 152 { 153 const GraphicPrimitive2D& rCompare = (GraphicPrimitive2D&)rPrimitive; 154 155 return (getTransform() == rCompare.getTransform() 156 && getGraphicObject() == rCompare.getGraphicObject() 157 && getGraphicAttr() == rCompare.getGraphicAttr()); 158 } 159 160 return false; 161 } 162 163 basegfx::B2DRange GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 164 { 165 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0); 166 aRetval.transform(getTransform()); 167 return aRetval; 168 } 169 170 // provide unique ID 171 ImplPrimitrive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D) 172 173 } // end of namespace primitive2d 174 } // end of namespace drawinglayer 175 176 ////////////////////////////////////////////////////////////////////////////// 177 // eof 178