1464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5464702f4SAndrew Rist * distributed with this work for additional information 6464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14464702f4SAndrew Rist * software distributed under the License is distributed on an 15464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17464702f4SAndrew Rist * specific language governing permissions and limitations 18464702f4SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20464702f4SAndrew Rist *************************************************************/ 21464702f4SAndrew Rist 22464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx> 28cdf0e10cSrcweir #include <drawinglayer/texture/texture.hxx> 29cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 31cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 32cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx> 33cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 34cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 350702bc67SArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 38cdf0e10cSrcweir 39cdf0e10cSrcweir using namespace com::sun::star; 40cdf0e10cSrcweir 41cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 42cdf0e10cSrcweir 43cdf0e10cSrcweir namespace drawinglayer 44cdf0e10cSrcweir { 45cdf0e10cSrcweir namespace primitive2d 46cdf0e10cSrcweir { create2DDecomposition(const geometry::ViewInformation2D &) const47cdf0e10cSrcweir Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 48cdf0e10cSrcweir { 49cdf0e10cSrcweir Primitive2DSequence aRetval; 500702bc67SArmin Le Grand 51cdf0e10cSrcweir if(!getFillHatch().isDefault()) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir // create hatch 54cdf0e10cSrcweir const basegfx::BColor aHatchColor(getFillHatch().getColor()); 55cdf0e10cSrcweir const double fAngle(getFillHatch().getAngle()); 56cdf0e10cSrcweir ::std::vector< basegfx::B2DHomMatrix > aMatrices; 570702bc67SArmin Le Grand double fDistance(getFillHatch().getDistance()); 580702bc67SArmin Le Grand const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance()); 590702bc67SArmin Le Grand 600702bc67SArmin Le Grand // #120230# evtl. adapt distance 610702bc67SArmin Le Grand if(bAdaptDistance) 620702bc67SArmin Le Grand { 630702bc67SArmin Le Grand const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit()); 640702bc67SArmin Le Grand 650702bc67SArmin Le Grand if(fDiscreteDistance < (double)getFillHatch().getMinimalDiscreteDistance()) 660702bc67SArmin Le Grand { 670702bc67SArmin Le Grand fDistance = (double)getFillHatch().getMinimalDiscreteDistance() * getDiscreteUnit(); 680702bc67SArmin Le Grand } 690702bc67SArmin Le Grand } 70cdf0e10cSrcweir 71cdf0e10cSrcweir // get hatch transformations 72cdf0e10cSrcweir switch(getFillHatch().getStyle()) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir case attribute::HATCHSTYLE_TRIPLE: 75cdf0e10cSrcweir { 76cdf0e10cSrcweir // rotated 45 degrees 77*64b14621SArmin Le Grand texture::GeoTexSvxHatch aHatch( 78*64b14621SArmin Le Grand getDefinitionRange(), 79*64b14621SArmin Le Grand getOutputRange(), 80*64b14621SArmin Le Grand fDistance, 81*64b14621SArmin Le Grand fAngle - F_PI4); 82*64b14621SArmin Le Grand 83cdf0e10cSrcweir aHatch.appendTransformations(aMatrices); 84cdf0e10cSrcweir 85cdf0e10cSrcweir // fall-through by purpose 86cdf0e10cSrcweir } 87cdf0e10cSrcweir case attribute::HATCHSTYLE_DOUBLE: 88cdf0e10cSrcweir { 89cdf0e10cSrcweir // rotated 90 degrees 90*64b14621SArmin Le Grand texture::GeoTexSvxHatch aHatch( 91*64b14621SArmin Le Grand getDefinitionRange(), 92*64b14621SArmin Le Grand getOutputRange(), 93*64b14621SArmin Le Grand fDistance, 94*64b14621SArmin Le Grand fAngle - F_PI2); 95*64b14621SArmin Le Grand 96cdf0e10cSrcweir aHatch.appendTransformations(aMatrices); 97cdf0e10cSrcweir 98cdf0e10cSrcweir // fall-through by purpose 99cdf0e10cSrcweir } 100cdf0e10cSrcweir case attribute::HATCHSTYLE_SINGLE: 101cdf0e10cSrcweir { 102cdf0e10cSrcweir // angle as given 103*64b14621SArmin Le Grand texture::GeoTexSvxHatch aHatch( 104*64b14621SArmin Le Grand getDefinitionRange(), 105*64b14621SArmin Le Grand getOutputRange(), 106*64b14621SArmin Le Grand fDistance, 107*64b14621SArmin Le Grand fAngle); 108*64b14621SArmin Le Grand 109cdf0e10cSrcweir aHatch.appendTransformations(aMatrices); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir // prepare return value 114cdf0e10cSrcweir const bool bFillBackground(getFillHatch().isFillBackground()); 115cdf0e10cSrcweir aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size()); 116cdf0e10cSrcweir 117cdf0e10cSrcweir // evtl. create filled background 118cdf0e10cSrcweir if(bFillBackground) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir // create primitive for background 121cdf0e10cSrcweir const Primitive2DReference xRef( 122cdf0e10cSrcweir new PolyPolygonColorPrimitive2D( 123cdf0e10cSrcweir basegfx::B2DPolyPolygon( 124*64b14621SArmin Le Grand basegfx::tools::createPolygonFromRect(getOutputRange())), getBColor())); 125cdf0e10cSrcweir aRetval[0] = xRef; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir // create primitives 129cdf0e10cSrcweir const basegfx::B2DPoint aStart(0.0, 0.0); 130cdf0e10cSrcweir const basegfx::B2DPoint aEnd(1.0, 0.0); 131cdf0e10cSrcweir 132cdf0e10cSrcweir for(sal_uInt32 a(0L); a < aMatrices.size(); a++) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir const basegfx::B2DHomMatrix& rMatrix = aMatrices[a]; 135cdf0e10cSrcweir basegfx::B2DPolygon aNewLine; 136cdf0e10cSrcweir 137cdf0e10cSrcweir aNewLine.append(rMatrix * aStart); 138cdf0e10cSrcweir aNewLine.append(rMatrix * aEnd); 139cdf0e10cSrcweir 140cdf0e10cSrcweir // create hairline 141cdf0e10cSrcweir const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor)); 142cdf0e10cSrcweir aRetval[bFillBackground ? (a + 1) : a] = xRef; 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir return aRetval; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir FillHatchPrimitive2D(const basegfx::B2DRange & rOutputRange,const basegfx::BColor & rBColor,const attribute::FillHatchAttribute & rFillHatch)149cdf0e10cSrcweir FillHatchPrimitive2D::FillHatchPrimitive2D( 150*64b14621SArmin Le Grand const basegfx::B2DRange& rOutputRange, 151cdf0e10cSrcweir const basegfx::BColor& rBColor, 152cdf0e10cSrcweir const attribute::FillHatchAttribute& rFillHatch) 1530702bc67SArmin Le Grand : DiscreteMetricDependentPrimitive2D(), 154*64b14621SArmin Le Grand maOutputRange(rOutputRange), 155*64b14621SArmin Le Grand maDefinitionRange(rOutputRange), 156*64b14621SArmin Le Grand maFillHatch(rFillHatch), 157*64b14621SArmin Le Grand maBColor(rBColor) 158*64b14621SArmin Le Grand { 159*64b14621SArmin Le Grand } 160*64b14621SArmin Le Grand FillHatchPrimitive2D(const basegfx::B2DRange & rOutputRange,const basegfx::B2DRange & rDefinitionRange,const basegfx::BColor & rBColor,const attribute::FillHatchAttribute & rFillHatch)161*64b14621SArmin Le Grand FillHatchPrimitive2D::FillHatchPrimitive2D( 162*64b14621SArmin Le Grand const basegfx::B2DRange& rOutputRange, 163*64b14621SArmin Le Grand const basegfx::B2DRange& rDefinitionRange, 164*64b14621SArmin Le Grand const basegfx::BColor& rBColor, 165*64b14621SArmin Le Grand const attribute::FillHatchAttribute& rFillHatch) 166*64b14621SArmin Le Grand : DiscreteMetricDependentPrimitive2D(), 167*64b14621SArmin Le Grand maOutputRange(rOutputRange), 168*64b14621SArmin Le Grand maDefinitionRange(rDefinitionRange), 169cdf0e10cSrcweir maFillHatch(rFillHatch), 170cdf0e10cSrcweir maBColor(rBColor) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir } 173cdf0e10cSrcweir operator ==(const BasePrimitive2D & rPrimitive) const174cdf0e10cSrcweir bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 175cdf0e10cSrcweir { 1760702bc67SArmin Le Grand if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive)) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive; 179cdf0e10cSrcweir 180*64b14621SArmin Le Grand return (getOutputRange() == rCompare.getOutputRange() 181*64b14621SArmin Le Grand && getDefinitionRange() == rCompare.getDefinitionRange() 182cdf0e10cSrcweir && getFillHatch() == rCompare.getFillHatch() 183cdf0e10cSrcweir && getBColor() == rCompare.getBColor()); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir return false; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir getB2DRange(const geometry::ViewInformation2D &) const189cdf0e10cSrcweir basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 190cdf0e10cSrcweir { 191*64b14621SArmin Le Grand // return the geometrically visible area 192*64b14621SArmin Le Grand return getOutputRange(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir get2DDecomposition(const geometry::ViewInformation2D & rViewInformation) const1950702bc67SArmin Le Grand Primitive2DSequence FillHatchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const 1960702bc67SArmin Le Grand { 1970702bc67SArmin Le Grand ::osl::MutexGuard aGuard( m_aMutex ); 1980702bc67SArmin Le Grand bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance()); 1990702bc67SArmin Le Grand 2000702bc67SArmin Le Grand if(bAdaptDistance) 2010702bc67SArmin Le Grand { 2020702bc67SArmin Le Grand // behave view-dependent 2030702bc67SArmin Le Grand return DiscreteMetricDependentPrimitive2D::get2DDecomposition(rViewInformation); 2040702bc67SArmin Le Grand } 2050702bc67SArmin Le Grand else 2060702bc67SArmin Le Grand { 2070702bc67SArmin Le Grand // behave view-independent 2080702bc67SArmin Le Grand return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation); 2090702bc67SArmin Le Grand } 2100702bc67SArmin Le Grand } 2110702bc67SArmin Le Grand 212cdf0e10cSrcweir // provide unique ID 213cdf0e10cSrcweir ImplPrimitrive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D) 214cdf0e10cSrcweir 215cdf0e10cSrcweir } // end of namespace primitive2d 216cdf0e10cSrcweir } // end of namespace drawinglayer 217cdf0e10cSrcweir 218cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 219cdf0e10cSrcweir // eof 220