1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx> 32*cdf0e10cSrcweir #include <drawinglayer/texture/texture.hxx> 33*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 34*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 35*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 36*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 37*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 38*cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace com::sun::star; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir namespace drawinglayer 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir namespace primitive2d 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir Primitive2DSequence aRetval; 53*cdf0e10cSrcweir if(!getFillHatch().isDefault()) 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir // create hatch 56*cdf0e10cSrcweir const basegfx::BColor aHatchColor(getFillHatch().getColor()); 57*cdf0e10cSrcweir const double fAngle(getFillHatch().getAngle()); 58*cdf0e10cSrcweir ::std::vector< basegfx::B2DHomMatrix > aMatrices; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // get hatch transformations 61*cdf0e10cSrcweir switch(getFillHatch().getStyle()) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir case attribute::HATCHSTYLE_TRIPLE: 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir // rotated 45 degrees 66*cdf0e10cSrcweir texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI4); 67*cdf0e10cSrcweir aHatch.appendTransformations(aMatrices); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // fall-through by purpose 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir case attribute::HATCHSTYLE_DOUBLE: 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir // rotated 90 degrees 74*cdf0e10cSrcweir texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI2); 75*cdf0e10cSrcweir aHatch.appendTransformations(aMatrices); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // fall-through by purpose 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir case attribute::HATCHSTYLE_SINGLE: 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir // angle as given 82*cdf0e10cSrcweir texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle); 83*cdf0e10cSrcweir aHatch.appendTransformations(aMatrices); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // prepare return value 88*cdf0e10cSrcweir const bool bFillBackground(getFillHatch().isFillBackground()); 89*cdf0e10cSrcweir aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size()); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir // evtl. create filled background 92*cdf0e10cSrcweir if(bFillBackground) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir // create primitive for background 95*cdf0e10cSrcweir const Primitive2DReference xRef( 96*cdf0e10cSrcweir new PolyPolygonColorPrimitive2D( 97*cdf0e10cSrcweir basegfx::B2DPolyPolygon( 98*cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(getObjectRange())), getBColor())); 99*cdf0e10cSrcweir aRetval[0] = xRef; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // create primitives 103*cdf0e10cSrcweir const basegfx::B2DPoint aStart(0.0, 0.0); 104*cdf0e10cSrcweir const basegfx::B2DPoint aEnd(1.0, 0.0); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir for(sal_uInt32 a(0L); a < aMatrices.size(); a++) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir const basegfx::B2DHomMatrix& rMatrix = aMatrices[a]; 109*cdf0e10cSrcweir basegfx::B2DPolygon aNewLine; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir aNewLine.append(rMatrix * aStart); 112*cdf0e10cSrcweir aNewLine.append(rMatrix * aEnd); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // create hairline 115*cdf0e10cSrcweir const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor)); 116*cdf0e10cSrcweir aRetval[bFillBackground ? (a + 1) : a] = xRef; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir return aRetval; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir FillHatchPrimitive2D::FillHatchPrimitive2D( 124*cdf0e10cSrcweir const basegfx::B2DRange& rObjectRange, 125*cdf0e10cSrcweir const basegfx::BColor& rBColor, 126*cdf0e10cSrcweir const attribute::FillHatchAttribute& rFillHatch) 127*cdf0e10cSrcweir : BufferedDecompositionPrimitive2D(), 128*cdf0e10cSrcweir maObjectRange(rObjectRange), 129*cdf0e10cSrcweir maFillHatch(rFillHatch), 130*cdf0e10cSrcweir maBColor(rBColor) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir return (getObjectRange() == rCompare.getObjectRange() 141*cdf0e10cSrcweir && getFillHatch() == rCompare.getFillHatch() 142*cdf0e10cSrcweir && getBColor() == rCompare.getBColor()); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir return false; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir // return ObjectRange 151*cdf0e10cSrcweir return getObjectRange(); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // provide unique ID 155*cdf0e10cSrcweir ImplPrimitrive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D) 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir } // end of namespace primitive2d 158*cdf0e10cSrcweir } // end of namespace drawinglayer 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 161*cdf0e10cSrcweir // eof 162