LCOV - code coverage report
Current view: top level - svx/source/sdr/primitive2d - sdrellipseprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 27 77 35.1 %
Date: 2014-04-11 Functions: 4 8 50.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/sdrellipseprimitive2d.hxx>
      21             : #include <basegfx/polygon/b2dpolygon.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 <basegfx/color/bcolor.hxx>
      27             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      28             : #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
      29             : 
      30             : 
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : 
      35             : 
      36             : namespace drawinglayer
      37             : {
      38             :     namespace primitive2d
      39             :     {
      40          37 :         Primitive2DSequence SdrEllipsePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
      41             :         {
      42          37 :             Primitive2DSequence aRetval;
      43             : 
      44             :             // create unit outline polygon
      45             :             // Do use createPolygonFromUnitCircle, but let create from first quadrant to mimic old geometry creation.
      46             :             // This is needed to have the same look when stroke is used since the polygon start point defines the
      47             :             // stroke start, too.
      48          74 :             basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromUnitCircle(1));
      49             : 
      50             :             // scale and move UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
      51             :             const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
      52          74 :                 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
      53             : 
      54             :             // apply to the geometry
      55          37 :             aUnitOutline.transform(aUnitCorrectionMatrix);
      56             : 
      57             :             // add fill
      58          37 :             if(!getSdrLFSTAttribute().getFill().isDefault())
      59             :             {
      60          36 :                 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
      61             : 
      62          36 :                 aTransformed.transform(getTransform());
      63             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      64             :                     createPolyPolygonFillPrimitive(
      65             :                         aTransformed,
      66          36 :                         getSdrLFSTAttribute().getFill(),
      67          72 :                         getSdrLFSTAttribute().getFillFloatTransGradient()));
      68             :             }
      69             : 
      70             :             // add line
      71          37 :             if(getSdrLFSTAttribute().getLine().isDefault())
      72             :             {
      73             :                 // create invisible line for HitTest/BoundRect
      74             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      75             :                     createHiddenGeometryPrimitives2D(
      76             :                         false,
      77             :                         basegfx::B2DPolyPolygon(aUnitOutline),
      78           0 :                         getTransform()));
      79             :             }
      80             :             else
      81             :             {
      82          37 :                 basegfx::B2DPolygon aTransformed(aUnitOutline);
      83             : 
      84          37 :                 aTransformed.transform(getTransform());
      85             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      86             :                     createPolygonLinePrimitive(
      87             :                         aTransformed,
      88          37 :                         getSdrLFSTAttribute().getLine(),
      89          74 :                         attribute::SdrLineStartEndAttribute()));
      90             :             }
      91             : 
      92             :             // add text
      93          37 :             if(!getSdrLFSTAttribute().getText().isDefault())
      94             :             {
      95             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      96             :                     createTextPrimitive(
      97             :                         basegfx::B2DPolyPolygon(aUnitOutline),
      98           0 :                         getTransform(),
      99           0 :                         getSdrLFSTAttribute().getText(),
     100           0 :                         getSdrLFSTAttribute().getLine(),
     101             :                         false,
     102             :                         false,
     103           0 :                         false));
     104             :             }
     105             : 
     106             :             // add shadow
     107          37 :             if(!getSdrLFSTAttribute().getShadow().isDefault())
     108             :             {
     109           0 :                 aRetval = createEmbeddedShadowPrimitive(
     110             :                     aRetval,
     111           0 :                     getSdrLFSTAttribute().getShadow());
     112             :             }
     113             : 
     114          74 :             return aRetval;
     115             :         }
     116             : 
     117         183 :         SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
     118             :             const basegfx::B2DHomMatrix& rTransform,
     119             :             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
     120             :         :   BufferedDecompositionPrimitive2D(),
     121             :             maTransform(rTransform),
     122         183 :             maSdrLFSTAttribute(rSdrLFSTAttribute)
     123             :         {
     124         183 :         }
     125             : 
     126         251 :         bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     127             :         {
     128         251 :             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
     129             :             {
     130         251 :                 const SdrEllipsePrimitive2D& rCompare = (SdrEllipsePrimitive2D&)rPrimitive;
     131             : 
     132         251 :                 return (getTransform() == rCompare.getTransform()
     133         251 :                     && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
     134             :             }
     135             : 
     136           0 :             return false;
     137             :         }
     138             : 
     139             :         // provide unique ID
     140         656 :         ImplPrimitive2DIDBlock(SdrEllipsePrimitive2D, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D)
     141             : 
     142             :     } // end of namespace primitive2d
     143             : } // end of namespace drawinglayer
     144             : 
     145             : 
     146             : 
     147             : namespace drawinglayer
     148             : {
     149             :     namespace primitive2d
     150             :     {
     151           0 :         Primitive2DSequence SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
     152             :         {
     153           0 :             Primitive2DSequence aRetval;
     154             : 
     155             :             // create unit outline polygon
     156           0 :             basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
     157             : 
     158           0 :             if(mbCloseSegment)
     159             :             {
     160           0 :                 if(mbCloseUsingCenter)
     161             :                 {
     162             :                     // for compatibility, insert the center point at polygon start to get the same
     163             :                     // line stroking pattern as the old painting mechanisms.
     164           0 :                     aUnitOutline.insert(0L, basegfx::B2DPoint(0.0, 0.0));
     165             :                 }
     166             : 
     167           0 :                 aUnitOutline.setClosed(true);
     168             :             }
     169             : 
     170             :             // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
     171             :             const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
     172           0 :                 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
     173             : 
     174             :             // apply to the geometry
     175           0 :             aUnitOutline.transform(aUnitCorrectionMatrix);
     176             : 
     177             :             // add fill
     178           0 :             if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
     179             :             {
     180           0 :                 basegfx::B2DPolyPolygon aTransformed(aUnitOutline);
     181             : 
     182           0 :                 aTransformed.transform(getTransform());
     183             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     184             :                     createPolyPolygonFillPrimitive(
     185             :                         aTransformed,
     186           0 :                         getSdrLFSTAttribute().getFill(),
     187           0 :                         getSdrLFSTAttribute().getFillFloatTransGradient()));
     188             :             }
     189             : 
     190             :             // add line
     191           0 :             if(getSdrLFSTAttribute().getLine().isDefault())
     192             :             {
     193             :                 // create invisible line for HitTest/BoundRect
     194             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     195             :                     createHiddenGeometryPrimitives2D(
     196             :                         false,
     197             :                         basegfx::B2DPolyPolygon(aUnitOutline),
     198           0 :                         getTransform()));
     199             :             }
     200             :             else
     201             :             {
     202           0 :                 basegfx::B2DPolygon aTransformed(aUnitOutline);
     203             : 
     204           0 :                 aTransformed.transform(getTransform());
     205             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     206             :                     createPolygonLinePrimitive(
     207             :                         aTransformed,
     208           0 :                         getSdrLFSTAttribute().getLine(),
     209           0 :                         getSdrLFSTAttribute().getLineStartEnd()));
     210             :             }
     211             : 
     212             :             // add text
     213           0 :             if(!getSdrLFSTAttribute().getText().isDefault())
     214             :             {
     215             :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     216             :                     createTextPrimitive(
     217             :                         basegfx::B2DPolyPolygon(aUnitOutline),
     218           0 :                         getTransform(),
     219           0 :                         getSdrLFSTAttribute().getText(),
     220           0 :                         getSdrLFSTAttribute().getLine(),
     221             :                         false,
     222             :                         false,
     223           0 :                         false));
     224             :             }
     225             : 
     226             :             // add shadow
     227           0 :             if(!getSdrLFSTAttribute().getShadow().isDefault())
     228             :             {
     229           0 :                 aRetval = createEmbeddedShadowPrimitive(
     230             :                     aRetval,
     231           0 :                     getSdrLFSTAttribute().getShadow());
     232             :             }
     233             : 
     234           0 :             return aRetval;
     235             :         }
     236             : 
     237           0 :         SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
     238             :             const basegfx::B2DHomMatrix& rTransform,
     239             :             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
     240             :             double fStartAngle,
     241             :             double fEndAngle,
     242             :             bool bCloseSegment,
     243             :             bool bCloseUsingCenter)
     244             :         :   SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
     245             :             mfStartAngle(fStartAngle),
     246             :             mfEndAngle(fEndAngle),
     247             :             mbCloseSegment(bCloseSegment),
     248           0 :             mbCloseUsingCenter(bCloseUsingCenter)
     249             :         {
     250           0 :         }
     251             : 
     252           0 :         bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     253             :         {
     254           0 :             if(SdrEllipsePrimitive2D::operator==(rPrimitive))
     255             :             {
     256           0 :                 const SdrEllipseSegmentPrimitive2D& rCompare = (SdrEllipseSegmentPrimitive2D&)rPrimitive;
     257             : 
     258           0 :                 if( mfStartAngle == rCompare.mfStartAngle
     259           0 :                     && mfEndAngle == rCompare.mfEndAngle
     260           0 :                     && mbCloseSegment == rCompare.mbCloseSegment
     261           0 :                     && mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
     262             :                 {
     263           0 :                     return true;
     264             :                 }
     265             :             }
     266             : 
     267           0 :             return false;
     268             :         }
     269             : 
     270             :         // provide unique ID
     271           0 :         ImplPrimitive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
     272             : 
     273             :     } // end of namespace primitive2d
     274             : } // end of namespace drawinglayer
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10