LCOV - code coverage report
Current view: top level - libreoffice/svx/source/sdr/primitive2d - sdrgrafprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 49 46.9 %
Date: 2012-12-27 Functions: 4 5 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 <svx/sdr/primitive2d/sdrgrafprimitive2d.hxx>
      21             : #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
      22             : #include <basegfx/polygon/b2dpolygontools.hxx>
      23             : #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
      24             : #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
      25             : #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
      26             : #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
      27             : #include <basegfx/polygon/b2dpolygon.hxx>
      28             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      29             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      30             : 
      31             : namespace drawinglayer
      32             : {
      33             :     namespace primitive2d
      34             :     {
      35          35 :         Primitive2DSequence SdrGrafPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
      36             :         {
      37          35 :             Primitive2DSequence  aRetval;
      38             : 
      39             :             // create unit outline polygon
      40          35 :             basegfx::B2DPolygon aUnitOutline(basegfx::tools::createUnitPolygon());
      41             : 
      42             :             // add fill, but only when graphic ist transparent
      43          35 :             if(!getSdrLFSTAttribute().getFill().isDefault() && isTransparent())
      44             :             {
      45             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      46             :                     createPolyPolygonFillPrimitive(
      47             :                         basegfx::B2DPolyPolygon(aUnitOutline),
      48           0 :                         getTransform(),
      49           0 :                         getSdrLFSTAttribute().getFill(),
      50           0 :                         getSdrLFSTAttribute().getFillFloatTransGradient()));
      51             :             }
      52             : 
      53             :             // add line
      54          35 :             if(!getSdrLFSTAttribute().getLine().isDefault())
      55             :             {
      56             :                 // if line width is given, polygon needs to be grown by half of it to make the
      57             :                 // outline to be outside of the bitmap
      58           0 :                 if(0.0 != getSdrLFSTAttribute().getLine().getWidth())
      59             :                 {
      60             :                     // decompose to get scale
      61           0 :                     basegfx::B2DVector aScale, aTranslate;
      62             :                     double fRotate, fShearX;
      63           0 :                     getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
      64             : 
      65             :                     // create expanded range (add relative half line width to unit rectangle)
      66           0 :                     double fHalfLineWidth(getSdrLFSTAttribute().getLine().getWidth() * 0.5);
      67           0 :                     double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
      68           0 :                     double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
      69           0 :                     const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
      70           0 :                     basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
      71             : 
      72             :                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      73             :                         createPolygonLinePrimitive(
      74             :                             aExpandedUnitOutline,
      75           0 :                             getTransform(),
      76           0 :                             getSdrLFSTAttribute().getLine(),
      77           0 :                             attribute::SdrLineStartEndAttribute()));
      78             :                 }
      79             :                 else
      80             :                 {
      81             :                     appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      82             :                         createPolygonLinePrimitive(
      83           0 :                             aUnitOutline, getTransform(),
      84           0 :                             getSdrLFSTAttribute().getLine(),
      85           0 :                             attribute::SdrLineStartEndAttribute()));
      86             :                 }
      87             :             }
      88             : 
      89             :             // add graphic content
      90          35 :             if(255L != getGraphicAttr().GetTransparency())
      91             :             {
      92             :                 // standard graphic fill
      93             :                 const Primitive2DReference xGraphicContentPrimitive(
      94             :                     new GraphicPrimitive2D(
      95             :                         getTransform(),
      96             :                         getGraphicObject(),
      97          35 :                         getGraphicAttr()));
      98             : 
      99          35 :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xGraphicContentPrimitive);
     100             :             }
     101             : 
     102             :             // add text
     103          35 :             if(!getSdrLFSTAttribute().getText().isDefault())
     104             :             {
     105             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     106             :                     createTextPrimitive(
     107             :                         basegfx::B2DPolyPolygon(aUnitOutline),
     108           0 :                         getTransform(),
     109           0 :                         getSdrLFSTAttribute().getText(),
     110           0 :                         getSdrLFSTAttribute().getLine(),
     111             :                         false,
     112             :                         false,
     113           0 :                         false));
     114             :             }
     115             : 
     116             :             // add shadow
     117          35 :             if(!getSdrLFSTAttribute().getShadow().isDefault())
     118             :             {
     119             :                 aRetval = createEmbeddedShadowPrimitive(
     120             :                     aRetval,
     121           0 :                     getSdrLFSTAttribute().getShadow());
     122             :             }
     123             : 
     124          35 :             return aRetval;
     125             :         }
     126             : 
     127          46 :         SdrGrafPrimitive2D::SdrGrafPrimitive2D(
     128             :             const basegfx::B2DHomMatrix& rTransform,
     129             :             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
     130             :             const GraphicObject& rGraphicObject,
     131             :             const GraphicAttr& rGraphicAttr)
     132             :         :   BufferedDecompositionPrimitive2D(),
     133             :             maTransform(rTransform),
     134             :             maSdrLFSTAttribute(rSdrLFSTAttribute),
     135             :             maGraphicObject(rGraphicObject),
     136          46 :             maGraphicAttr(rGraphicAttr)
     137             :         {
     138             :             // reset some values from GraphicAttr which are part of transformation already
     139          46 :             maGraphicAttr.SetRotation(0L);
     140          46 :         }
     141             : 
     142          15 :         bool SdrGrafPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     143             :         {
     144          15 :             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
     145             :             {
     146          15 :                 const SdrGrafPrimitive2D& rCompare = (SdrGrafPrimitive2D&)rPrimitive;
     147             : 
     148          15 :                 return (getTransform() == rCompare.getTransform()
     149          11 :                     && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
     150          11 :                     && getGraphicObject() == rCompare.getGraphicObject()
     151          37 :                     && getGraphicAttr() == rCompare.getGraphicAttr());
     152             :             }
     153             : 
     154           0 :             return false;
     155             :         }
     156             : 
     157           0 :         bool SdrGrafPrimitive2D::isTransparent() const
     158             :         {
     159           0 :             return ((0L != getGraphicAttr().GetTransparency())
     160           0 :                 || (getGraphicObject().IsTransparent()));
     161             :         }
     162             : 
     163             :         // provide unique ID
     164          46 :         ImplPrimitrive2DIDBlock(SdrGrafPrimitive2D, PRIMITIVE2D_ID_SDRGRAFPRIMITIVE2D)
     165             : 
     166             :     } // end of namespace primitive2d
     167             : } // end of namespace drawinglayer
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10