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/fillhatchprimitive2d.hxx> 28 #include <drawinglayer/texture/texture.hxx> 29 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> 30 #include <basegfx/polygon/b2dpolygontools.hxx> 31 #include <basegfx/polygon/b2dpolygon.hxx> 32 #include <basegfx/tools/canvastools.hxx> 33 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 34 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 35 36 ////////////////////////////////////////////////////////////////////////////// 37 38 using namespace com::sun::star; 39 40 ////////////////////////////////////////////////////////////////////////////// 41 42 namespace drawinglayer 43 { 44 namespace primitive2d 45 { 46 Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const 47 { 48 Primitive2DSequence aRetval; 49 if(!getFillHatch().isDefault()) 50 { 51 // create hatch 52 const basegfx::BColor aHatchColor(getFillHatch().getColor()); 53 const double fAngle(getFillHatch().getAngle()); 54 ::std::vector< basegfx::B2DHomMatrix > aMatrices; 55 56 // get hatch transformations 57 switch(getFillHatch().getStyle()) 58 { 59 case attribute::HATCHSTYLE_TRIPLE: 60 { 61 // rotated 45 degrees 62 texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI4); 63 aHatch.appendTransformations(aMatrices); 64 65 // fall-through by purpose 66 } 67 case attribute::HATCHSTYLE_DOUBLE: 68 { 69 // rotated 90 degrees 70 texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle - F_PI2); 71 aHatch.appendTransformations(aMatrices); 72 73 // fall-through by purpose 74 } 75 case attribute::HATCHSTYLE_SINGLE: 76 { 77 // angle as given 78 texture::GeoTexSvxHatch aHatch(getObjectRange(), getFillHatch().getDistance(), fAngle); 79 aHatch.appendTransformations(aMatrices); 80 } 81 } 82 83 // prepare return value 84 const bool bFillBackground(getFillHatch().isFillBackground()); 85 aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size()); 86 87 // evtl. create filled background 88 if(bFillBackground) 89 { 90 // create primitive for background 91 const Primitive2DReference xRef( 92 new PolyPolygonColorPrimitive2D( 93 basegfx::B2DPolyPolygon( 94 basegfx::tools::createPolygonFromRect(getObjectRange())), getBColor())); 95 aRetval[0] = xRef; 96 } 97 98 // create primitives 99 const basegfx::B2DPoint aStart(0.0, 0.0); 100 const basegfx::B2DPoint aEnd(1.0, 0.0); 101 102 for(sal_uInt32 a(0L); a < aMatrices.size(); a++) 103 { 104 const basegfx::B2DHomMatrix& rMatrix = aMatrices[a]; 105 basegfx::B2DPolygon aNewLine; 106 107 aNewLine.append(rMatrix * aStart); 108 aNewLine.append(rMatrix * aEnd); 109 110 // create hairline 111 const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor)); 112 aRetval[bFillBackground ? (a + 1) : a] = xRef; 113 } 114 } 115 116 return aRetval; 117 } 118 119 FillHatchPrimitive2D::FillHatchPrimitive2D( 120 const basegfx::B2DRange& rObjectRange, 121 const basegfx::BColor& rBColor, 122 const attribute::FillHatchAttribute& rFillHatch) 123 : BufferedDecompositionPrimitive2D(), 124 maObjectRange(rObjectRange), 125 maFillHatch(rFillHatch), 126 maBColor(rBColor) 127 { 128 } 129 130 bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 131 { 132 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 133 { 134 const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive; 135 136 return (getObjectRange() == rCompare.getObjectRange() 137 && getFillHatch() == rCompare.getFillHatch() 138 && getBColor() == rCompare.getBColor()); 139 } 140 141 return false; 142 } 143 144 basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 145 { 146 // return ObjectRange 147 return getObjectRange(); 148 } 149 150 // provide unique ID 151 ImplPrimitrive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D) 152 153 } // end of namespace primitive2d 154 } // end of namespace drawinglayer 155 156 ////////////////////////////////////////////////////////////////////////////// 157 // eof 158