LCOV - code coverage report
Current view: top level - svx/source/sdr/primitive2d - sdrellipseprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 68 38.2 %
Date: 2012-08-25 Functions: 4 8 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 29 162 17.9 %

           Branch data     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                 :         69 :         Primitive2DSequence SdrEllipsePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
      41                 :            :         {
      42         [ +  - ]:         69 :             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         [ +  - ]:         69 :             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         [ +  - ]:         69 :                 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
      53                 :            : 
      54                 :            :             // apply to the geometry
      55         [ +  - ]:         69 :             aUnitOutline.transform(aUnitCorrectionMatrix);
      56                 :            : 
      57                 :            :             // add fill
      58 [ +  - ][ +  - ]:         69 :             if(!getSdrLFSTAttribute().getFill().isDefault())
      59                 :            :             {
      60                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      61                 :            :                     createPolyPolygonFillPrimitive(
      62                 :            :                         basegfx::B2DPolyPolygon(aUnitOutline),
      63                 :         69 :                         getTransform(),
      64                 :         69 :                         getSdrLFSTAttribute().getFill(),
      65 [ +  - ][ +  - ]:        138 :                         getSdrLFSTAttribute().getFillFloatTransGradient()));
         [ +  - ][ +  - ]
      66                 :            :             }
      67                 :            : 
      68                 :            :             // add line
      69 [ +  - ][ -  + ]:         69 :             if(getSdrLFSTAttribute().getLine().isDefault())
      70                 :            :             {
      71                 :            :                 // create invisible line for HitTest/BoundRect
      72                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      73                 :            :                     createHiddenGeometryPrimitives2D(
      74                 :            :                         false,
      75                 :            :                         basegfx::B2DPolyPolygon(aUnitOutline),
      76 [ #  # ][ #  # ]:          0 :                         getTransform()));
         [ #  # ][ #  # ]
      77                 :            :             }
      78                 :            :             else
      79                 :            :             {
      80                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      81                 :            :                     createPolygonLinePrimitive(
      82                 :            :                         aUnitOutline,
      83                 :         69 :                         getTransform(),
      84                 :         69 :                         getSdrLFSTAttribute().getLine(),
      85   [ +  -  +  - ]:        138 :                         attribute::SdrLineStartEndAttribute()));
         [ +  - ][ +  - ]
      86                 :            :             }
      87                 :            : 
      88                 :            :             // add text
      89 [ +  - ][ -  + ]:         69 :             if(!getSdrLFSTAttribute().getText().isDefault())
      90                 :            :             {
      91                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
      92                 :            :                     createTextPrimitive(
      93                 :            :                         basegfx::B2DPolyPolygon(aUnitOutline),
      94                 :          0 :                         getTransform(),
      95                 :          0 :                         getSdrLFSTAttribute().getText(),
      96                 :          0 :                         getSdrLFSTAttribute().getLine(),
      97                 :            :                         false,
      98                 :            :                         false,
      99 [ #  # ][ #  # ]:          0 :                         false));
         [ #  # ][ #  # ]
     100                 :            :             }
     101                 :            : 
     102                 :            :             // add shadow
     103 [ +  - ][ -  + ]:         69 :             if(!getSdrLFSTAttribute().getShadow().isDefault())
     104                 :            :             {
     105                 :            :                 aRetval = createEmbeddedShadowPrimitive(
     106                 :            :                     aRetval,
     107 [ #  # ][ #  # ]:          0 :                     getSdrLFSTAttribute().getShadow());
                 [ #  # ]
     108                 :            :             }
     109                 :            : 
     110 [ +  - ][ +  - ]:         69 :             return aRetval;
     111                 :            :         }
     112                 :            : 
     113                 :        358 :         SdrEllipsePrimitive2D::SdrEllipsePrimitive2D(
     114                 :            :             const basegfx::B2DHomMatrix& rTransform,
     115                 :            :             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
     116                 :            :         :   BufferedDecompositionPrimitive2D(),
     117                 :            :             maTransform(rTransform),
     118 [ +  - ][ +  - ]:        358 :             maSdrLFSTAttribute(rSdrLFSTAttribute)
     119                 :            :         {
     120                 :        358 :         }
     121                 :            : 
     122                 :        497 :         bool SdrEllipsePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     123                 :            :         {
     124         [ +  - ]:        497 :             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
     125                 :            :             {
     126                 :        497 :                 const SdrEllipsePrimitive2D& rCompare = (SdrEllipsePrimitive2D&)rPrimitive;
     127                 :            : 
     128                 :        497 :                 return (getTransform() == rCompare.getTransform()
     129 [ +  + ][ +  + ]:        497 :                     && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute());
     130                 :            :             }
     131                 :            : 
     132                 :        497 :             return false;
     133                 :            :         }
     134                 :            : 
     135                 :            :         // provide unique ID
     136                 :       1294 :         ImplPrimitrive2DIDBlock(SdrEllipsePrimitive2D, PRIMITIVE2D_ID_SDRELLIPSEPRIMITIVE2D)
     137                 :            : 
     138                 :            :     } // end of namespace primitive2d
     139                 :            : } // end of namespace drawinglayer
     140                 :            : 
     141                 :            : //////////////////////////////////////////////////////////////////////////////
     142                 :            : 
     143                 :            : namespace drawinglayer
     144                 :            : {
     145                 :            :     namespace primitive2d
     146                 :            :     {
     147                 :          0 :         Primitive2DSequence SdrEllipseSegmentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
     148                 :            :         {
     149         [ #  # ]:          0 :             Primitive2DSequence aRetval;
     150                 :            : 
     151                 :            :             // create unit outline polygon
     152         [ #  # ]:          0 :             basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromUnitEllipseSegment(mfStartAngle, mfEndAngle));
     153                 :            : 
     154         [ #  # ]:          0 :             if(mbCloseSegment)
     155                 :            :             {
     156         [ #  # ]:          0 :                 if(mbCloseUsingCenter)
     157                 :            :                 {
     158                 :            :                     // for compatibility, insert the center point at polygon start to get the same
     159                 :            :                     // line stroking pattern as the old painting mechanisms.
     160         [ #  # ]:          0 :                     aUnitOutline.insert(0L, basegfx::B2DPoint(0.0, 0.0));
     161                 :            :                 }
     162                 :            : 
     163         [ #  # ]:          0 :                 aUnitOutline.setClosed(true);
     164                 :            :             }
     165                 :            : 
     166                 :            :             // move and scale UnitEllipse to UnitObject (-1,-1 1,1) -> (0,0 1,1)
     167                 :            :             const basegfx::B2DHomMatrix aUnitCorrectionMatrix(
     168         [ #  # ]:          0 :                 basegfx::tools::createScaleTranslateB2DHomMatrix(0.5, 0.5, 0.5, 0.5));
     169                 :            : 
     170                 :            :             // apply to the geometry
     171         [ #  # ]:          0 :             aUnitOutline.transform(aUnitCorrectionMatrix);
     172                 :            : 
     173                 :            :             // add fill
     174 [ #  # ][ #  # ]:          0 :             if(!getSdrLFSTAttribute().getFill().isDefault() && aUnitOutline.isClosed())
         [ #  # ][ #  # ]
                 [ #  # ]
     175                 :            :             {
     176                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     177                 :            :                     createPolyPolygonFillPrimitive(
     178                 :            :                         basegfx::B2DPolyPolygon(aUnitOutline),
     179                 :          0 :                         getTransform(),
     180                 :          0 :                         getSdrLFSTAttribute().getFill(),
     181 [ #  # ][ #  # ]:          0 :                         getSdrLFSTAttribute().getFillFloatTransGradient()));
         [ #  # ][ #  # ]
     182                 :            :             }
     183                 :            : 
     184                 :            :             // add line
     185 [ #  # ][ #  # ]:          0 :             if(getSdrLFSTAttribute().getLine().isDefault())
     186                 :            :             {
     187                 :            :                 // create invisible line for HitTest/BoundRect
     188                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     189                 :            :                     createHiddenGeometryPrimitives2D(
     190                 :            :                         false,
     191                 :            :                         basegfx::B2DPolyPolygon(aUnitOutline),
     192 [ #  # ][ #  # ]:          0 :                         getTransform()));
         [ #  # ][ #  # ]
     193                 :            :             }
     194                 :            :             else
     195                 :            :             {
     196                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     197                 :            :                     createPolygonLinePrimitive(
     198                 :            :                         aUnitOutline,
     199                 :          0 :                         getTransform(),
     200                 :          0 :                         getSdrLFSTAttribute().getLine(),
     201 [ #  # ][ #  # ]:          0 :                         getSdrLFSTAttribute().getLineStartEnd()));
     202                 :            :             }
     203                 :            : 
     204                 :            :             // add text
     205 [ #  # ][ #  # ]:          0 :             if(!getSdrLFSTAttribute().getText().isDefault())
     206                 :            :             {
     207                 :            :                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
     208                 :            :                     createTextPrimitive(
     209                 :            :                         basegfx::B2DPolyPolygon(aUnitOutline),
     210                 :          0 :                         getTransform(),
     211                 :          0 :                         getSdrLFSTAttribute().getText(),
     212                 :          0 :                         getSdrLFSTAttribute().getLine(),
     213                 :            :                         false,
     214                 :            :                         false,
     215 [ #  # ][ #  # ]:          0 :                         false));
         [ #  # ][ #  # ]
     216                 :            :             }
     217                 :            : 
     218                 :            :             // add shadow
     219 [ #  # ][ #  # ]:          0 :             if(!getSdrLFSTAttribute().getShadow().isDefault())
     220                 :            :             {
     221                 :            :                 aRetval = createEmbeddedShadowPrimitive(
     222                 :            :                     aRetval,
     223 [ #  # ][ #  # ]:          0 :                     getSdrLFSTAttribute().getShadow());
                 [ #  # ]
     224                 :            :             }
     225                 :            : 
     226 [ #  # ][ #  # ]:          0 :             return aRetval;
     227                 :            :         }
     228                 :            : 
     229                 :          0 :         SdrEllipseSegmentPrimitive2D::SdrEllipseSegmentPrimitive2D(
     230                 :            :             const basegfx::B2DHomMatrix& rTransform,
     231                 :            :             const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
     232                 :            :             double fStartAngle,
     233                 :            :             double fEndAngle,
     234                 :            :             bool bCloseSegment,
     235                 :            :             bool bCloseUsingCenter)
     236                 :            :         :   SdrEllipsePrimitive2D(rTransform, rSdrLFSTAttribute),
     237                 :            :             mfStartAngle(fStartAngle),
     238                 :            :             mfEndAngle(fEndAngle),
     239                 :            :             mbCloseSegment(bCloseSegment),
     240                 :          0 :             mbCloseUsingCenter(bCloseUsingCenter)
     241                 :            :         {
     242                 :          0 :         }
     243                 :            : 
     244                 :          0 :         bool SdrEllipseSegmentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     245                 :            :         {
     246         [ #  # ]:          0 :             if(SdrEllipsePrimitive2D::operator==(rPrimitive))
     247                 :            :             {
     248                 :          0 :                 const SdrEllipseSegmentPrimitive2D& rCompare = (SdrEllipseSegmentPrimitive2D&)rPrimitive;
     249                 :            : 
     250 [ #  # ][ #  # ]:          0 :                 if( mfStartAngle == rCompare.mfStartAngle
         [ #  # ][ #  # ]
     251                 :            :                     && mfEndAngle == rCompare.mfEndAngle
     252                 :            :                     && mbCloseSegment == rCompare.mbCloseSegment
     253                 :            :                     && mbCloseUsingCenter == rCompare.mbCloseUsingCenter)
     254                 :            :                 {
     255                 :          0 :                     return true;
     256                 :            :                 }
     257                 :            :             }
     258                 :            : 
     259                 :          0 :             return false;
     260                 :            :         }
     261                 :            : 
     262                 :            :         // provide unique ID
     263                 :          0 :         ImplPrimitrive2DIDBlock(SdrEllipseSegmentPrimitive2D, PRIMITIVE2D_ID_SDRELLIPSESEGMENTPRIMITIVE2D)
     264                 :            : 
     265                 :            :     } // end of namespace primitive2d
     266                 :            : } // end of namespace drawinglayer
     267                 :            : 
     268                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10