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

Generated by: LCOV version 1.11