LCOV - code coverage report
Current view: top level - sw/source/core/layout - fillattributes.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 48 70.8 %
Date: 2014-04-11 Functions: 8 10 80.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 <fillattributes.hxx>
      21             : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      22             : #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
      23             : #include <basegfx/polygon/b2dpolygontools.hxx>
      24             : #include <basegfx/matrix/b2dhommatrix.hxx>
      25             : #include <basegfx/polygon/b2dpolygon.hxx>
      26             : #include <drawinglayer/attribute/fillhatchattribute.hxx>
      27             : #include <drawinglayer/attribute/sdrfillgraphicattribute.hxx>
      28             : #include <svx/xfillit0.hxx>
      29             : #include <tools/color.hxx>
      30             : #include <vcl/graph.hxx>
      31             : 
      32         235 : void FillAttributes::createPrimitive2DSequence(
      33             :     const basegfx::B2DRange& rPaintRange,
      34             :     const basegfx::B2DRange& rDefineRange)
      35             : {
      36             :     // reset and remember new target range for object geometry
      37         235 :     maLastPaintRange = rPaintRange;
      38         235 :     maLastDefineRange = rDefineRange;
      39             : 
      40         235 :     if(isUsed())
      41             :     {
      42         235 :         maPrimitives.realloc(1);
      43        1007 :         maPrimitives[0] = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
      44             :             basegfx::B2DPolyPolygon(
      45             :                 basegfx::tools::createPolygonFromRect(
      46             :                     maLastPaintRange)),
      47             :                 maLastDefineRange,
      48         470 :             maFillAttribute.get() ? *maFillAttribute.get() : drawinglayer::attribute::SdrFillAttribute(),
      49         537 :             maFillGradientAttribute.get() ? *maFillGradientAttribute.get() : drawinglayer::attribute::FillGradientAttribute());
      50             :     }
      51         235 : }
      52             : 
      53           0 : FillAttributes::FillAttributes()
      54             : :   maLastPaintRange(),
      55             :     maLastDefineRange(),
      56             :     maFillAttribute(),
      57             :     maFillGradientAttribute(),
      58           0 :     maPrimitives()
      59             : {
      60           0 : }
      61             : 
      62         171 : FillAttributes::FillAttributes(const Color& rColor)
      63             : :   maLastPaintRange(),
      64             :     maLastDefineRange(),
      65             :     maFillAttribute(),
      66             :     maFillGradientAttribute(),
      67         171 :     maPrimitives()
      68             : {
      69             :     maFillAttribute.reset(
      70             :         new drawinglayer::attribute::SdrFillAttribute(
      71             :             0.0,
      72             :             Color(rColor.GetRGBColor()).getBColor(),
      73             :             drawinglayer::attribute::FillGradientAttribute(),
      74             :             drawinglayer::attribute::FillHatchAttribute(),
      75         171 :             drawinglayer::attribute::SdrFillGraphicAttribute()));
      76         171 : }
      77             : 
      78         295 : FillAttributes::FillAttributes(const SfxItemSet& rSet)
      79             : :   maLastPaintRange(),
      80             :     maLastDefineRange(),
      81             :     maFillAttribute(
      82             :         new drawinglayer::attribute::SdrFillAttribute(
      83           0 :             drawinglayer::primitive2d::createNewSdrFillAttribute(rSet))),
      84             :     maFillGradientAttribute(
      85             :         new drawinglayer::attribute::FillGradientAttribute(
      86           0 :             drawinglayer::primitive2d::createNewTransparenceGradientAttribute(rSet))),
      87         295 :     maPrimitives()
      88             : {
      89         295 : }
      90             : 
      91         466 : FillAttributes::~FillAttributes()
      92             : {
      93         466 : }
      94             : 
      95       14697 : bool FillAttributes::isUsed() const
      96             : {
      97             :     // only depends on fill, FillGradientAttribute alone defines no fill
      98       14697 :     return maFillAttribute.get() && !maFillAttribute->isDefault();
      99             : }
     100             : 
     101        8065 : bool FillAttributes::isTransparent() const
     102             : {
     103        8065 :     if(hasSdrFillAttribute() && 0.0 != maFillAttribute->getTransparence())
     104             :     {
     105           0 :         return true;
     106             :     }
     107             : 
     108        8065 :     if(hasFillGradientAttribute() && !maFillGradientAttribute->isDefault())
     109             :     {
     110           0 :         return true;
     111             :     }
     112             : 
     113        8065 :     if(hasSdrFillAttribute())
     114             :     {
     115        8065 :         const Graphic& rGraphic = getFillAttribute().getFillGraphic().getFillGraphic();
     116             : 
     117        8065 :         return rGraphic.IsSupportedGraphic() && rGraphic.IsTransparent();
     118             :     }
     119             : 
     120           0 :     return false;
     121             : }
     122             : 
     123        8065 : const drawinglayer::attribute::SdrFillAttribute& FillAttributes::getFillAttribute() const
     124             : {
     125        8065 :     if(!maFillAttribute.get())
     126             :     {
     127           0 :         const_cast< FillAttributes* >(this)->maFillAttribute.reset(new drawinglayer::attribute::SdrFillAttribute());
     128             :     }
     129             : 
     130        8065 :     return *maFillAttribute.get();
     131             : }
     132             : 
     133           0 : const drawinglayer::attribute::FillGradientAttribute& FillAttributes::getFillGradientAttribute() const
     134             : {
     135           0 :     if(!maFillGradientAttribute.get())
     136             :     {
     137           0 :         const_cast< FillAttributes* >(this)->maFillGradientAttribute.reset(new drawinglayer::attribute::FillGradientAttribute());
     138             :     }
     139             : 
     140           0 :     return *maFillGradientAttribute.get();
     141             : }
     142             : 
     143         235 : const drawinglayer::primitive2d::Primitive2DSequence& FillAttributes::getPrimitive2DSequence(
     144             :     const basegfx::B2DRange& rPaintRange,
     145             :     const basegfx::B2DRange& rDefineRange) const
     146             : {
     147         235 :     if(maPrimitives.getLength() && (maLastPaintRange != rPaintRange || maLastDefineRange != rDefineRange))
     148             :     {
     149           0 :         const_cast< FillAttributes* >(this)->maPrimitives.realloc(0);
     150             :     }
     151             : 
     152         235 :     if(!maPrimitives.getLength())
     153             :     {
     154         235 :         const_cast< FillAttributes* >(this)->createPrimitive2DSequence(rPaintRange, rDefineRange);
     155             :     }
     156             : 
     157         235 :     return maPrimitives;
     158             : }
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10