1ddde725dSArmin Le Grand /************************************************************** 2*a6c67450Smseidel * 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 10*a6c67450Smseidel * 11ddde725dSArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 12*a6c67450Smseidel * 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. 19*a6c67450Smseidel * 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 { create2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const46ddde725dSArmin 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; 60035a2f44SArmin Le Grand texture::GeoTexSvxTiled aTiling(getReferenceRange()); 61*a6c67450Smseidel 62ddde725dSArmin Le Grand aTiling.appendTransformations(aMatrices); 63ddde725dSArmin Le Grand 64ddde725dSArmin Le Grand // check if content needs to be clipped 65ddde725dSArmin Le Grand const basegfx::B2DRange aUnitRange(0.0, 0.0, 1.0, 1.0); 66ddde725dSArmin Le Grand const basegfx::B2DRange aContentRange(getB2DRangeFromPrimitive2DSequence(getChildren(), rViewInformation)); 67ddde725dSArmin Le Grand Primitive2DSequence aContent(getChildren()); 68ddde725dSArmin Le Grand 69ddde725dSArmin Le Grand if(!aUnitRange.isInside(aContentRange)) 70ddde725dSArmin Le Grand { 71ddde725dSArmin Le Grand const Primitive2DReference xRef( 72ddde725dSArmin Le Grand new MaskPrimitive2D( 73ddde725dSArmin Le Grand basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aUnitRange)), 74ddde725dSArmin Le Grand aContent)); 75ddde725dSArmin Le Grand 76ddde725dSArmin Le Grand aContent = Primitive2DSequence(&xRef, 1); 77ddde725dSArmin Le Grand } 78ddde725dSArmin Le Grand 79ddde725dSArmin Le Grand // resize result 80ddde725dSArmin Le Grand aRetval.realloc(aMatrices.size()); 81ddde725dSArmin Le Grand 82ddde725dSArmin Le Grand // create one primitive for each matrix 83ddde725dSArmin Le Grand for(sal_uInt32 a(0); a < aMatrices.size(); a++) 84ddde725dSArmin Le Grand { 85ddde725dSArmin Le Grand aRetval[a] = new TransformPrimitive2D( 86ddde725dSArmin Le Grand aMatrices[a], 87ddde725dSArmin Le Grand aContent); 88ddde725dSArmin Le Grand } 89ddde725dSArmin Le Grand 90*a6c67450Smseidel // transform result which is in unit coordinates to mask's object coordinates 91ddde725dSArmin Le Grand { 92ddde725dSArmin Le Grand const basegfx::B2DHomMatrix aMaskTransform( 93ddde725dSArmin Le Grand basegfx::tools::createScaleTranslateB2DHomMatrix( 94*a6c67450Smseidel aMaskRange.getRange(), 95ddde725dSArmin Le Grand aMaskRange.getMinimum())); 96ddde725dSArmin Le Grand 97ddde725dSArmin Le Grand const Primitive2DReference xRef( 98ddde725dSArmin Le Grand new TransformPrimitive2D( 99ddde725dSArmin Le Grand aMaskTransform, 100ddde725dSArmin Le Grand aRetval)); 101ddde725dSArmin Le Grand 102ddde725dSArmin Le Grand aRetval = Primitive2DSequence(&xRef, 1); 103ddde725dSArmin Le Grand } 104ddde725dSArmin Le Grand 105ddde725dSArmin Le Grand // embed result in mask 106ddde725dSArmin Le Grand { 107ddde725dSArmin Le Grand const Primitive2DReference xRef( 108ddde725dSArmin Le Grand new MaskPrimitive2D( 109ddde725dSArmin Le Grand getMask(), 110ddde725dSArmin Le Grand aRetval)); 111ddde725dSArmin Le Grand 112ddde725dSArmin Le Grand aRetval = Primitive2DSequence(&xRef, 1); 113ddde725dSArmin Le Grand } 114ddde725dSArmin Le Grand 115ddde725dSArmin Le Grand } 116ddde725dSArmin Le Grand } 117ddde725dSArmin Le Grand } 118ddde725dSArmin Le Grand 119ddde725dSArmin Le Grand return aRetval; 120ddde725dSArmin Le Grand } 121ddde725dSArmin Le Grand PatternFillPrimitive2D(const basegfx::B2DPolyPolygon & rMask,const Primitive2DSequence & rChildren,const basegfx::B2DRange & rReferenceRange)122ddde725dSArmin Le Grand PatternFillPrimitive2D::PatternFillPrimitive2D( 123ddde725dSArmin Le Grand const basegfx::B2DPolyPolygon& rMask, 124ddde725dSArmin Le Grand const Primitive2DSequence& rChildren, 125ddde725dSArmin Le Grand const basegfx::B2DRange& rReferenceRange) 126ddde725dSArmin Le Grand : BufferedDecompositionPrimitive2D(), 127e2bf1e9dSArmin Le Grand maMask(rMask), 128e2bf1e9dSArmin Le Grand maChildren(rChildren), 129ddde725dSArmin Le Grand maReferenceRange(rReferenceRange) 130ddde725dSArmin Le Grand { 131ddde725dSArmin Le Grand } 132ddde725dSArmin Le Grand operator ==(const BasePrimitive2D & rPrimitive) const133ddde725dSArmin Le Grand bool PatternFillPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 134ddde725dSArmin Le Grand { 135ddde725dSArmin Le Grand if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 136ddde725dSArmin Le Grand { 137ddde725dSArmin Le Grand const PatternFillPrimitive2D& rCompare = static_cast< const PatternFillPrimitive2D& >(rPrimitive); 138ddde725dSArmin Le Grand 139ddde725dSArmin Le Grand return (getMask() == rCompare.getMask() 140ddde725dSArmin Le Grand && getChildren() == rCompare.getChildren() 141ddde725dSArmin Le Grand && getReferenceRange() == rCompare.getReferenceRange()); 142ddde725dSArmin Le Grand } 143ddde725dSArmin Le Grand 144ddde725dSArmin Le Grand return false; 145ddde725dSArmin Le Grand } 146ddde725dSArmin Le Grand getB2DRange(const geometry::ViewInformation2D &) const147e2bf1e9dSArmin Le Grand basegfx::B2DRange PatternFillPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 148ddde725dSArmin Le Grand { 149ddde725dSArmin Le Grand return getMask().getB2DRange(); 150ddde725dSArmin Le Grand } 151ddde725dSArmin Le Grand 152ddde725dSArmin Le Grand // provide unique ID 153ddde725dSArmin Le Grand ImplPrimitrive2DIDBlock(PatternFillPrimitive2D, PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D) 154ddde725dSArmin Le Grand 155ddde725dSArmin Le Grand } // end of namespace primitive2d 156ddde725dSArmin Le Grand } // end of namespace drawinglayer 157ddde725dSArmin Le Grand 158*a6c67450Smseidel /* vim: set noet sw=4 ts=4: */ 159