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/patternfillprimitive2d.hxx> 28 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 29 #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 30 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 31 #include <basegfx/polygon/b2dpolygontools.hxx> 32 #include <basegfx/matrix/b2dhommatrixtools.hxx> 33 #include <drawinglayer/texture/texture.hxx> 34 #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 35 36 ////////////////////////////////////////////////////////////////////////////// 37 38 using namespace com::sun::star; 39 40 ////////////////////////////////////////////////////////////////////////////// 41 42 namespace drawinglayer 43 { 44 namespace primitive2d 45 { 46 Primitive2DSequence PatternFillPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 47 { 48 Primitive2DSequence aRetval; 49 50 if(getChildren().hasElements()) 51 { 52 if(!getReferenceRange().isEmpty() && getReferenceRange().getWidth() > 0.0 && getReferenceRange().getHeight() > 0.0) 53 { 54 const basegfx::B2DRange aMaskRange(getMask().getB2DRange()); 55 56 if(!aMaskRange.isEmpty() && aMaskRange.getWidth() > 0.0 && aMaskRange.getHeight() > 0.0) 57 { 58 // create tiling matrices 59 ::std::vector< basegfx::B2DHomMatrix > aMatrices; 60 texture::GeoTexSvxTiled aTiling(getReferenceRange().getMinimum(), getReferenceRange().getRange()); 61 aTiling.appendTransformations(aMatrices); 62 63 // check if content needs to be clipped 64 const basegfx::B2DRange aUnitRange(0.0, 0.0, 1.0, 1.0); 65 const basegfx::B2DRange aContentRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation)); 66 Primitive2DSequence aContent(getChildren()); 67 68 if(!aUnitRange.isInside(aContentRange)) 69 { 70 const Primitive2DReference xRef( 71 new MaskPrimitive2D( 72 basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aUnitRange)), 73 aContent)); 74 75 aContent = Primitive2DSequence(&xRef, 1); 76 } 77 78 // resize result 79 aRetval.realloc(aMatrices.size()); 80 81 // create one primitive for each matrix 82 for(sal_uInt32 a(0); a < aMatrices.size(); a++) 83 { 84 aRetval[a] = new TransformPrimitive2D( 85 aMatrices[a], 86 aContent); 87 } 88 89 // transform result which is in unit coordinates to mask's object coordiantes 90 { 91 const basegfx::B2DHomMatrix aMaskTransform( 92 basegfx::tools::createScaleTranslateB2DHomMatrix( 93 aMaskRange.getRange(), 94 aMaskRange.getMinimum())); 95 96 const Primitive2DReference xRef( 97 new TransformPrimitive2D( 98 aMaskTransform, 99 aRetval)); 100 101 aRetval = Primitive2DSequence(&xRef, 1); 102 } 103 104 // embed result in mask 105 { 106 const Primitive2DReference xRef( 107 new MaskPrimitive2D( 108 getMask(), 109 aRetval)); 110 111 aRetval = Primitive2DSequence(&xRef, 1); 112 } 113 114 } 115 } 116 } 117 118 return aRetval; 119 } 120 121 PatternFillPrimitive2D::PatternFillPrimitive2D( 122 const basegfx::B2DPolyPolygon& rMask, 123 const Primitive2DSequence& rChildren, 124 const basegfx::B2DRange& rReferenceRange) 125 : BufferedDecompositionPrimitive2D(), 126 maMask(rMask), 127 maChildren(rChildren), 128 maReferenceRange(rReferenceRange) 129 { 130 } 131 132 bool PatternFillPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 133 { 134 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 135 { 136 const PatternFillPrimitive2D& rCompare = static_cast< const PatternFillPrimitive2D& >(rPrimitive); 137 138 return (getMask() == rCompare.getMask() 139 && getChildren() == rCompare.getChildren() 140 && getReferenceRange() == rCompare.getReferenceRange()); 141 } 142 143 return false; 144 } 145 146 basegfx::B2DRange PatternFillPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const 147 { 148 return getMask().getB2DRange(); 149 } 150 151 // provide unique ID 152 ImplPrimitrive2DIDBlock(PatternFillPrimitive2D, PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D) 153 154 } // end of namespace primitive2d 155 } // end of namespace drawinglayer 156 157 ////////////////////////////////////////////////////////////////////////////// 158 // eof 159