1ddde725dSArmin Le Grand /************************************************************** 2ddde725dSArmin Le Grand * 3ddde725dSArmin Le Grand * Licensed to the Apache Software Foundation (ASF) under one 4ddde725dSArmin Le Grand * or more contributor license agreements. See the NOTICE file 5ddde725dSArmin Le Grand * distributed with this work for additional information 6ddde725dSArmin Le Grand * regarding copyright ownership. The ASF licenses this file 7ddde725dSArmin Le Grand * to you under the Apache License, Version 2.0 (the 8ddde725dSArmin Le Grand * "License"); you may not use this file except in compliance 9ddde725dSArmin Le Grand * with the License. You may obtain a copy of the License at 10ddde725dSArmin Le Grand * 11ddde725dSArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 12ddde725dSArmin Le Grand * 13ddde725dSArmin Le Grand * Unless required by applicable law or agreed to in writing, 14ddde725dSArmin Le Grand * software distributed under the License is distributed on an 15ddde725dSArmin Le Grand * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ddde725dSArmin Le Grand * KIND, either express or implied. See the License for the 17ddde725dSArmin Le Grand * specific language governing permissions and limitations 18ddde725dSArmin Le Grand * under the License. 19ddde725dSArmin Le Grand * 20ddde725dSArmin Le Grand *************************************************************/ 21ddde725dSArmin Le Grand 22ddde725dSArmin Le Grand 23ddde725dSArmin Le Grand 24ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove 25ddde725dSArmin Le Grand #include "precompiled_drawinglayer.hxx" 26ddde725dSArmin Le Grand 27ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/patternfillprimitive2d.hxx> 28ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 29ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx> 30ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 31ddde725dSArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx> 32ddde725dSArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx> 33ddde725dSArmin Le Grand #include <drawinglayer/texture/texture.hxx> 34ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/maskprimitive2d.hxx> 35ddde725dSArmin Le Grand 36ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 37ddde725dSArmin Le Grand 38ddde725dSArmin Le Grand using namespace com::sun::star; 39ddde725dSArmin Le Grand 40ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 41ddde725dSArmin Le Grand 42ddde725dSArmin Le Grand namespace drawinglayer 43ddde725dSArmin Le Grand { 44ddde725dSArmin Le Grand namespace primitive2d 45ddde725dSArmin Le Grand { 46ddde725dSArmin Le Grand Primitive2DSequence PatternFillPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 47ddde725dSArmin Le Grand { 48ddde725dSArmin Le Grand Primitive2DSequence aRetval; 49ddde725dSArmin Le Grand 50ddde725dSArmin Le Grand if(getChildren().hasElements()) 51ddde725dSArmin Le Grand { 52ddde725dSArmin Le Grand if(!getReferenceRange().isEmpty() && getReferenceRange().getWidth() > 0.0 && getReferenceRange().getHeight() > 0.0) 53ddde725dSArmin Le Grand { 54ddde725dSArmin Le Grand const basegfx::B2DRange aMaskRange(getMask().getB2DRange()); 55ddde725dSArmin Le Grand 56ddde725dSArmin Le Grand if(!aMaskRange.isEmpty() && aMaskRange.getWidth() > 0.0 && aMaskRange.getHeight() > 0.0) 57ddde725dSArmin Le Grand { 58ddde725dSArmin Le Grand // create tiling matrices 59ddde725dSArmin Le Grand ::std::vector< basegfx::B2DHomMatrix > aMatrices; 60ddde725dSArmin Le Grand texture::GeoTexSvxTiled aTiling(getReferenceRange().getMinimum(), getReferenceRange().getRange()); 61ddde725dSArmin Le Grand aTiling.appendTransformations(aMatrices); 62ddde725dSArmin Le Grand 63ddde725dSArmin Le Grand // check if content needs to be clipped 64ddde725dSArmin Le Grand const basegfx::B2DRange aUnitRange(0.0, 0.0, 1.0, 1.0); 65ddde725dSArmin Le Grand const basegfx::B2DRange aContentRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation)); 66ddde725dSArmin Le Grand Primitive2DSequence aContent(getChildren()); 67ddde725dSArmin Le Grand 68ddde725dSArmin Le Grand if(!aUnitRange.isInside(aContentRange)) 69ddde725dSArmin Le Grand { 70ddde725dSArmin Le Grand const Primitive2DReference xRef( 71ddde725dSArmin Le Grand new MaskPrimitive2D( 72ddde725dSArmin Le Grand basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aUnitRange)), 73ddde725dSArmin Le Grand aContent)); 74ddde725dSArmin Le Grand 75ddde725dSArmin Le Grand aContent = Primitive2DSequence(&xRef, 1); 76ddde725dSArmin Le Grand } 77ddde725dSArmin Le Grand 78ddde725dSArmin Le Grand // resize result 79ddde725dSArmin Le Grand aRetval.realloc(aMatrices.size()); 80ddde725dSArmin Le Grand 81ddde725dSArmin Le Grand // create one primitive for each matrix 82ddde725dSArmin Le Grand for(sal_uInt32 a(0); a < aMatrices.size(); a++) 83ddde725dSArmin Le Grand { 84ddde725dSArmin Le Grand aRetval[a] = new TransformPrimitive2D( 85ddde725dSArmin Le Grand aMatrices[a], 86ddde725dSArmin Le Grand aContent); 87ddde725dSArmin Le Grand } 88ddde725dSArmin Le Grand 89ddde725dSArmin Le Grand // transform result which is in unit coordinates to mask's object coordiantes 90ddde725dSArmin Le Grand { 91ddde725dSArmin Le Grand const basegfx::B2DHomMatrix aMaskTransform( 92ddde725dSArmin Le Grand basegfx::tools::createScaleTranslateB2DHomMatrix( 93ddde725dSArmin Le Grand aMaskRange.getRange(), 94ddde725dSArmin Le Grand aMaskRange.getMinimum())); 95ddde725dSArmin Le Grand 96ddde725dSArmin Le Grand const Primitive2DReference xRef( 97ddde725dSArmin Le Grand new TransformPrimitive2D( 98ddde725dSArmin Le Grand aMaskTransform, 99ddde725dSArmin Le Grand aRetval)); 100ddde725dSArmin Le Grand 101ddde725dSArmin Le Grand aRetval = Primitive2DSequence(&xRef, 1); 102ddde725dSArmin Le Grand } 103ddde725dSArmin Le Grand 104ddde725dSArmin Le Grand // embed result in mask 105ddde725dSArmin Le Grand { 106ddde725dSArmin Le Grand const Primitive2DReference xRef( 107ddde725dSArmin Le Grand new MaskPrimitive2D( 108ddde725dSArmin Le Grand getMask(), 109ddde725dSArmin Le Grand aRetval)); 110ddde725dSArmin Le Grand 111ddde725dSArmin Le Grand aRetval = Primitive2DSequence(&xRef, 1); 112ddde725dSArmin Le Grand } 113ddde725dSArmin Le Grand 114ddde725dSArmin Le Grand } 115ddde725dSArmin Le Grand } 116ddde725dSArmin Le Grand } 117ddde725dSArmin Le Grand 118ddde725dSArmin Le Grand return aRetval; 119ddde725dSArmin Le Grand } 120ddde725dSArmin Le Grand 121ddde725dSArmin Le Grand PatternFillPrimitive2D::PatternFillPrimitive2D( 122ddde725dSArmin Le Grand const basegfx::B2DPolyPolygon& rMask, 123ddde725dSArmin Le Grand const Primitive2DSequence& rChildren, 124ddde725dSArmin Le Grand const basegfx::B2DRange& rReferenceRange) 125ddde725dSArmin Le Grand : BufferedDecompositionPrimitive2D(), 126*e2bf1e9dSArmin Le Grand maMask(rMask), 127*e2bf1e9dSArmin Le Grand maChildren(rChildren), 128ddde725dSArmin Le Grand maReferenceRange(rReferenceRange) 129ddde725dSArmin Le Grand { 130ddde725dSArmin Le Grand } 131ddde725dSArmin Le Grand 132ddde725dSArmin Le Grand bool PatternFillPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 133ddde725dSArmin Le Grand { 134ddde725dSArmin Le Grand if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 135ddde725dSArmin Le Grand { 136ddde725dSArmin Le Grand const PatternFillPrimitive2D& rCompare = static_cast< const PatternFillPrimitive2D& >(rPrimitive); 137ddde725dSArmin Le Grand 138ddde725dSArmin Le Grand return (getMask() == rCompare.getMask() 139ddde725dSArmin Le Grand && getChildren() == rCompare.getChildren() 140ddde725dSArmin Le Grand && getReferenceRange() == rCompare.getReferenceRange()); 141ddde725dSArmin Le Grand } 142ddde725dSArmin Le Grand 143ddde725dSArmin Le Grand return false; 144ddde725dSArmin Le Grand } 145ddde725dSArmin Le Grand 146*e2bf1e9dSArmin Le Grand basegfx::B2DRange PatternFillPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 147ddde725dSArmin Le Grand { 148ddde725dSArmin Le Grand return getMask().getB2DRange(); 149ddde725dSArmin Le Grand } 150ddde725dSArmin Le Grand 151ddde725dSArmin Le Grand // provide unique ID 152ddde725dSArmin Le Grand ImplPrimitrive2DIDBlock(PatternFillPrimitive2D, PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D) 153ddde725dSArmin Le Grand 154ddde725dSArmin Le Grand } // end of namespace primitive2d 155ddde725dSArmin Le Grand } // end of namespace drawinglayer 156ddde725dSArmin Le Grand 157ddde725dSArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 158ddde725dSArmin Le Grand // eof 159