LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - fillhatchprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 65 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx>
      21             : #include <drawinglayer/texture/texture.hxx>
      22             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      23             : #include <basegfx/polygon/b2dpolygontools.hxx>
      24             : #include <basegfx/polygon/b2dpolygon.hxx>
      25             : #include <basegfx/tools/canvastools.hxx>
      26             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      27             : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      28             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      29             : 
      30             : 
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : 
      35             : 
      36             : namespace drawinglayer
      37             : {
      38             :     namespace primitive2d
      39             :     {
      40           0 :         Primitive2DSequence FillHatchPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      41             :         {
      42           0 :             Primitive2DSequence aRetval;
      43             : 
      44           0 :             if(!getFillHatch().isDefault())
      45             :             {
      46             :                 // create hatch
      47           0 :                 const basegfx::BColor aHatchColor(getFillHatch().getColor());
      48           0 :                 const double fAngle(getFillHatch().getAngle());
      49           0 :                 ::std::vector< basegfx::B2DHomMatrix > aMatrices;
      50           0 :                 double fDistance(getFillHatch().getDistance());
      51           0 :                 const bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
      52             : 
      53             :                 // #i120230# evtl. adapt distance
      54           0 :                 if(bAdaptDistance)
      55             :                 {
      56           0 :                     const double fDiscreteDistance(getFillHatch().getDistance() / getDiscreteUnit());
      57             : 
      58           0 :                     if(fDiscreteDistance < (double)getFillHatch().getMinimalDiscreteDistance())
      59             :                     {
      60           0 :                         fDistance = (double)getFillHatch().getMinimalDiscreteDistance() * getDiscreteUnit();
      61             :                     }
      62             :                 }
      63             : 
      64             :                 // get hatch transformations
      65           0 :                 switch(getFillHatch().getStyle())
      66             :                 {
      67             :                     case attribute::HATCHSTYLE_TRIPLE:
      68             :                     {
      69             :                         // rotated 45 degrees
      70             :                         texture::GeoTexSvxHatch aHatch(
      71           0 :                             getDefinitionRange(),
      72           0 :                             getOutputRange(),
      73             :                             fDistance,
      74           0 :                             fAngle - F_PI4);
      75             : 
      76           0 :                         aHatch.appendTransformations(aMatrices);
      77             : 
      78             :                         // fall-through by purpose
      79             :                     }
      80             :                     case attribute::HATCHSTYLE_DOUBLE:
      81             :                     {
      82             :                         // rotated 90 degrees
      83             :                         texture::GeoTexSvxHatch aHatch(
      84           0 :                             getDefinitionRange(),
      85           0 :                             getOutputRange(),
      86             :                             fDistance,
      87           0 :                             fAngle - F_PI2);
      88             : 
      89           0 :                         aHatch.appendTransformations(aMatrices);
      90             : 
      91             :                         // fall-through by purpose
      92             :                     }
      93             :                     case attribute::HATCHSTYLE_SINGLE:
      94             :                     {
      95             :                         // angle as given
      96             :                         texture::GeoTexSvxHatch aHatch(
      97           0 :                             getDefinitionRange(),
      98           0 :                             getOutputRange(),
      99             :                             fDistance,
     100           0 :                             fAngle);
     101             : 
     102           0 :                         aHatch.appendTransformations(aMatrices);
     103             :                     }
     104             :                 }
     105             : 
     106             :                 // prepare return value
     107           0 :                 const bool bFillBackground(getFillHatch().isFillBackground());
     108           0 :                 aRetval.realloc(bFillBackground ? aMatrices.size() + 1L : aMatrices.size());
     109             : 
     110             :                 // evtl. create filled background
     111           0 :                 if(bFillBackground)
     112             :                 {
     113             :                     // create primitive for background
     114             :                     const Primitive2DReference xRef(
     115             :                         new PolyPolygonColorPrimitive2D(
     116             :                             basegfx::B2DPolyPolygon(
     117           0 :                                 basegfx::tools::createPolygonFromRect(getOutputRange())), getBColor()));
     118           0 :                     aRetval[0] = xRef;
     119             :                 }
     120             : 
     121             :                 // create primitives
     122           0 :                 const basegfx::B2DPoint aStart(0.0, 0.0);
     123           0 :                 const basegfx::B2DPoint aEnd(1.0, 0.0);
     124             : 
     125           0 :                 for(sal_uInt32 a(0L); a < aMatrices.size(); a++)
     126             :                 {
     127           0 :                     const basegfx::B2DHomMatrix& rMatrix = aMatrices[a];
     128           0 :                     basegfx::B2DPolygon aNewLine;
     129             : 
     130           0 :                     aNewLine.append(rMatrix * aStart);
     131           0 :                     aNewLine.append(rMatrix * aEnd);
     132             : 
     133             :                     // create hairline
     134           0 :                     const Primitive2DReference xRef(new PolygonHairlinePrimitive2D(aNewLine, aHatchColor));
     135           0 :                     aRetval[bFillBackground ? (a + 1) : a] = xRef;
     136           0 :                 }
     137             :             }
     138             : 
     139           0 :             return aRetval;
     140             :         }
     141             : 
     142           0 :         FillHatchPrimitive2D::FillHatchPrimitive2D(
     143             :             const basegfx::B2DRange& rOutputRange,
     144             :             const basegfx::BColor& rBColor,
     145             :             const attribute::FillHatchAttribute& rFillHatch)
     146             :         :   DiscreteMetricDependentPrimitive2D(),
     147             :             maOutputRange(rOutputRange),
     148             :             maDefinitionRange(rOutputRange),
     149             :             maFillHatch(rFillHatch),
     150           0 :             maBColor(rBColor)
     151             :         {
     152           0 :         }
     153             : 
     154           0 :         FillHatchPrimitive2D::FillHatchPrimitive2D(
     155             :             const basegfx::B2DRange& rOutputRange,
     156             :             const basegfx::B2DRange& rDefinitionRange,
     157             :             const basegfx::BColor& rBColor,
     158             :             const attribute::FillHatchAttribute& rFillHatch)
     159             :         :   DiscreteMetricDependentPrimitive2D(),
     160             :             maOutputRange(rOutputRange),
     161             :             maDefinitionRange(rDefinitionRange),
     162             :             maFillHatch(rFillHatch),
     163           0 :             maBColor(rBColor)
     164             :         {
     165           0 :         }
     166             : 
     167           0 :         bool FillHatchPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     168             :         {
     169           0 :             if(DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
     170             :             {
     171           0 :                 const FillHatchPrimitive2D& rCompare = (FillHatchPrimitive2D&)rPrimitive;
     172             : 
     173           0 :                 return (getOutputRange() == rCompare.getOutputRange()
     174           0 :                     && getDefinitionRange() == rCompare.getDefinitionRange()
     175           0 :                     && getFillHatch() == rCompare.getFillHatch()
     176           0 :                     && getBColor() == rCompare.getBColor());
     177             :             }
     178             : 
     179           0 :             return false;
     180             :         }
     181             : 
     182           0 :         basegfx::B2DRange FillHatchPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
     183             :         {
     184             :             // return the geometrically visible area
     185           0 :             return getOutputRange();
     186             :         }
     187             : 
     188           0 :         Primitive2DSequence FillHatchPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
     189             :         {
     190           0 :             ::osl::MutexGuard aGuard( m_aMutex );
     191           0 :             bool bAdaptDistance(0 != getFillHatch().getMinimalDiscreteDistance());
     192             : 
     193           0 :             if(bAdaptDistance)
     194             :             {
     195             :                 // behave view-dependent
     196           0 :                 return DiscreteMetricDependentPrimitive2D::get2DDecomposition(rViewInformation);
     197             :             }
     198             :             else
     199             :             {
     200             :                 // behave view-independent
     201           0 :                 return BufferedDecompositionPrimitive2D::get2DDecomposition(rViewInformation);
     202           0 :             }
     203             :         }
     204             : 
     205             :         // provide unique ID
     206           0 :         ImplPrimitive2DIDBlock(FillHatchPrimitive2D, PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D)
     207             : 
     208             :     } // end of namespace primitive2d
     209             : } // end of namespace drawinglayer
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10