LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - graphicprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 168 22.6 %
Date: 2012-08-25 Functions: 4 15 26.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 418 8.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
      30                 :            : #include <drawinglayer/animation/animationtiming.hxx>
      31                 :            : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
      32                 :            : #include <drawinglayer/primitive2d/rendergraphicprimitive2d.hxx>
      33                 :            : #include <drawinglayer/primitive2d/animatedprimitive2d.hxx>
      34                 :            : #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
      35                 :            : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      36                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      37                 :            : #include <basegfx/polygon/b2dpolygontools.hxx>
      38                 :            : #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
      39                 :            : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      40                 :            : 
      41                 :            : //////////////////////////////////////////////////////////////////////////////
      42                 :            : // helper class for animated graphics
      43                 :            : 
      44                 :            : #include <vcl/animate.hxx>
      45                 :            : #include <vcl/graph.hxx>
      46                 :            : #include <vcl/virdev.hxx>
      47                 :            : #include <vcl/svapp.hxx>
      48                 :            : #include <vcl/metaact.hxx>
      49                 :            : 
      50                 :            : //////////////////////////////////////////////////////////////////////////////
      51                 :            : // includes for testing MetafilePrimitive2D::create2DDecomposition
      52                 :            : 
      53                 :            : //////////////////////////////////////////////////////////////////////////////
      54                 :            : 
      55                 :            : namespace
      56                 :            : {
      57                 :          0 :     struct animationStep
      58                 :            :     {
      59                 :            :         BitmapEx                                maBitmapEx;
      60                 :            :         sal_uInt32                              mnTime;
      61                 :            :     };
      62                 :            : 
      63                 :          0 :     class animatedBitmapExPreparator
      64                 :            :     {
      65                 :            :         ::Animation                             maAnimation;
      66                 :            :         ::std::vector< animationStep >          maSteps;
      67                 :            : 
      68                 :            :         sal_uInt32 generateStepTime(sal_uInt32 nIndex) const;
      69                 :            : 
      70                 :            :     public:
      71                 :            :         explicit animatedBitmapExPreparator(const Graphic& rGraphic);
      72                 :            : 
      73                 :          0 :         sal_uInt32 count() const { return maSteps.size(); }
      74                 :          0 :         sal_uInt32 loopCount() const { return (sal_uInt32)maAnimation.GetLoopCount(); }
      75                 :          0 :         sal_uInt32 stepTime(sal_uInt32 a) const { return maSteps[a].mnTime; }
      76                 :          0 :         const BitmapEx& stepBitmapEx(sal_uInt32 a) const { return maSteps[a].maBitmapEx; }
      77                 :            :     };
      78                 :            : 
      79                 :          0 :     sal_uInt32 animatedBitmapExPreparator::generateStepTime(sal_uInt32 nIndex) const
      80                 :            :     {
      81                 :          0 :         const AnimationBitmap& rAnimBitmap = maAnimation.Get(sal_uInt16(nIndex));
      82                 :          0 :         sal_uInt32 nWaitTime(rAnimBitmap.nWait * 10);
      83                 :            : 
      84                 :            :         // #115934#
      85                 :            :         // Take care of special value for MultiPage TIFFs. ATM these shall just
      86                 :            :         // show their first page. Later we will offer some switching when object
      87                 :            :         // is selected.
      88         [ #  # ]:          0 :         if(ANIMATION_TIMEOUT_ON_CLICK == rAnimBitmap.nWait)
      89                 :            :         {
      90                 :            :             // ATM the huge value would block the timer, so
      91                 :            :             // use a long time to show first page (whole day)
      92                 :          0 :             nWaitTime = 100 * 60 * 60 * 24;
      93                 :            :         }
      94                 :            : 
      95                 :            :         // Bad trap: There are animated gifs with no set WaitTime (!).
      96                 :            :         // In that case use a default value.
      97         [ #  # ]:          0 :         if(0L == nWaitTime)
      98                 :            :         {
      99                 :          0 :             nWaitTime = 100L;
     100                 :            :         }
     101                 :            : 
     102                 :          0 :         return nWaitTime;
     103                 :            :     }
     104                 :            : 
     105                 :          0 :     animatedBitmapExPreparator::animatedBitmapExPreparator(const Graphic& rGraphic)
     106         [ #  # ]:          0 :     :   maAnimation(rGraphic.GetAnimation())
     107                 :            :     {
     108                 :            :         OSL_ENSURE(GRAPHIC_BITMAP == rGraphic.GetType() && rGraphic.IsAnimated(), "animatedBitmapExPreparator: graphic is not animated (!)");
     109                 :            : 
     110                 :            :         // #128539# secure access to Animation, looks like there exist animated GIFs out there
     111                 :            :         // with a step count of zero
     112         [ #  # ]:          0 :         if(maAnimation.Count())
     113                 :            :         {
     114 [ #  # ][ #  # ]:          0 :             VirtualDevice aVirtualDevice(*Application::GetDefaultDevice());
     115 [ #  # ][ #  # ]:          0 :             VirtualDevice aVirtualDeviceMask(*Application::GetDefaultDevice(), 1L);
     116                 :            : 
     117                 :            :             // Prepare VirtualDevices and their states
     118         [ #  # ]:          0 :             aVirtualDevice.EnableMapMode(sal_False);
     119         [ #  # ]:          0 :             aVirtualDeviceMask.EnableMapMode(sal_False);
     120         [ #  # ]:          0 :             aVirtualDevice.SetOutputSizePixel(maAnimation.GetDisplaySizePixel());
     121         [ #  # ]:          0 :             aVirtualDeviceMask.SetOutputSizePixel(maAnimation.GetDisplaySizePixel());
     122         [ #  # ]:          0 :             aVirtualDevice.Erase();
     123         [ #  # ]:          0 :             aVirtualDeviceMask.Erase();
     124                 :            : 
     125         [ #  # ]:          0 :             for(sal_uInt16 a(0L); a < maAnimation.Count(); a++)
     126                 :            :             {
     127         [ #  # ]:          0 :                 animationStep aNextStep;
     128         [ #  # ]:          0 :                 aNextStep.mnTime = generateStepTime(a);
     129                 :            : 
     130                 :            :                 // prepare step
     131         [ #  # ]:          0 :                 const AnimationBitmap& rAnimBitmap = maAnimation.Get(sal_uInt16(a));
     132                 :            : 
     133   [ #  #  #  #  :          0 :                 switch(rAnimBitmap.eDisposal)
                      # ]
     134                 :            :                 {
     135                 :            :                     case DISPOSE_NOT:
     136                 :            :                     {
     137         [ #  # ]:          0 :                         aVirtualDevice.DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
     138         [ #  # ]:          0 :                         Bitmap aMask = rAnimBitmap.aBmpEx.GetMask();
     139                 :            : 
     140         [ #  # ]:          0 :                         if(aMask.IsEmpty())
     141                 :            :                         {
     142                 :          0 :                             const Point aEmpty;
     143         [ #  # ]:          0 :                             const Rectangle aRect(aEmpty, aVirtualDeviceMask.GetOutputSizePixel());
     144         [ #  # ]:          0 :                             const Wallpaper aWallpaper(COL_BLACK);
     145 [ #  # ][ #  # ]:          0 :                             aVirtualDeviceMask.DrawWallpaper(aRect, aWallpaper);
     146                 :            :                         }
     147                 :            :                         else
     148                 :            :                         {
     149         [ #  # ]:          0 :                             BitmapEx aExpandVisibilityMask = BitmapEx(aMask, aMask);
     150 [ #  # ][ #  # ]:          0 :                             aVirtualDeviceMask.DrawBitmapEx(rAnimBitmap.aPosPix, aExpandVisibilityMask);
     151                 :            :                         }
     152                 :            : 
     153         [ #  # ]:          0 :                         break;
     154                 :            :                     }
     155                 :            :                     case DISPOSE_BACK:
     156                 :            :                     {
     157                 :            :                         // #i70772# react on no mask, for primitives, too.
     158         [ #  # ]:          0 :                         const Bitmap aMask(rAnimBitmap.aBmpEx.GetMask());
     159         [ #  # ]:          0 :                         const Bitmap aContent(rAnimBitmap.aBmpEx.GetBitmap());
     160                 :            : 
     161         [ #  # ]:          0 :                         aVirtualDeviceMask.Erase();
     162         [ #  # ]:          0 :                         aVirtualDevice.DrawBitmap(rAnimBitmap.aPosPix, aContent);
     163                 :            : 
     164         [ #  # ]:          0 :                         if(aMask.IsEmpty())
     165                 :            :                         {
     166 [ #  # ][ #  # ]:          0 :                             const Rectangle aRect(rAnimBitmap.aPosPix, aContent.GetSizePixel());
     167         [ #  # ]:          0 :                             aVirtualDeviceMask.SetFillColor(COL_BLACK);
     168         [ #  # ]:          0 :                             aVirtualDeviceMask.SetLineColor();
     169         [ #  # ]:          0 :                             aVirtualDeviceMask.DrawRect(aRect);
     170                 :            :                         }
     171                 :            :                         else
     172                 :            :                         {
     173         [ #  # ]:          0 :                             aVirtualDeviceMask.DrawBitmap(rAnimBitmap.aPosPix, aMask);
     174                 :            :                         }
     175                 :            : 
     176 [ #  # ][ #  # ]:          0 :                         break;
     177                 :            :                     }
     178                 :            :                     case DISPOSE_FULL:
     179                 :            :                     {
     180         [ #  # ]:          0 :                         aVirtualDevice.DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
     181                 :          0 :                         break;
     182                 :            :                     }
     183                 :            :                     case DISPOSE_PREVIOUS :
     184                 :            :                     {
     185         [ #  # ]:          0 :                         aVirtualDevice.DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
     186 [ #  # ][ #  # ]:          0 :                         aVirtualDeviceMask.DrawBitmap(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx.GetMask());
                 [ #  # ]
     187                 :          0 :                         break;
     188                 :            :                     }
     189                 :            :                 }
     190                 :            : 
     191                 :            :                 // create BitmapEx
     192         [ #  # ]:          0 :                 Bitmap aMainBitmap = aVirtualDevice.GetBitmap(Point(), aVirtualDevice.GetOutputSizePixel());
     193         [ #  # ]:          0 :                 Bitmap aMaskBitmap = aVirtualDeviceMask.GetBitmap(Point(), aVirtualDeviceMask.GetOutputSizePixel());
     194 [ #  # ][ #  # ]:          0 :                 aNextStep.maBitmapEx = BitmapEx(aMainBitmap, aMaskBitmap);
                 [ #  # ]
     195                 :            : 
     196                 :            :                 // add to vector
     197         [ #  # ]:          0 :                 maSteps.push_back(aNextStep);
     198 [ #  # ][ #  # ]:          0 :             }
         [ #  # ][ #  # ]
                 [ #  # ]
     199                 :            :         }
     200                 :          0 :     }
     201                 :            : } // end of anonymous namespace
     202                 :            : 
     203                 :            : //////////////////////////////////////////////////////////////////////////////
     204                 :            : 
     205                 :            : namespace drawinglayer
     206                 :            : {
     207                 :            :     namespace primitive2d
     208                 :            :     {
     209                 :         80 :         Primitive2DSequence GraphicPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D&
     210                 :            :             ) const
     211                 :            :         {
     212                 :         80 :             Primitive2DSequence aRetval;
     213                 :            : 
     214         [ +  - ]:         80 :             if(255L != getGraphicAttr().GetTransparency())
     215                 :            :             {
     216                 :         80 :                 Primitive2DReference xPrimitive;
     217                 :            : 
     218                 :            :                 // do not apply mirroring from GraphicAttr to the Metafile by calling
     219                 :            :                 // GetTransformedGraphic, this will try to mirror the Metafile using Scale()
     220                 :            :                 // at the Metafile. This again calls Scale at the single MetaFile actions,
     221                 :            :                 // but this implementation never worked. I reworked that implementations,
     222                 :            :                 // but for security reasons i will try not to use it.
     223         [ +  - ]:         80 :                 basegfx::B2DHomMatrix aTransform(getTransform());
     224                 :            : 
     225         [ -  + ]:         80 :                 if(getGraphicAttr().IsMirrored())
     226                 :            :                 {
     227                 :            :                     // content needs mirroring
     228                 :          0 :                     const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_HORZ);
     229                 :          0 :                     const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_VERT);
     230                 :            : 
     231                 :            :                     // mirror by applying negative scale to the unit primitive and
     232                 :            :                     // applying the object transformation on it.
     233                 :            :                     aTransform = basegfx::tools::createScaleB2DHomMatrix(
     234                 :            :                         bHMirr ? -1.0 : 1.0,
     235 [ #  # ][ #  # ]:          0 :                         bVMirr ? -1.0 : 1.0);
         [ #  # ][ #  # ]
                 [ #  # ]
     236                 :            :                     aTransform.translate(
     237                 :            :                         bHMirr ? 1.0 : 0.0,
     238 [ #  # ][ #  # ]:          0 :                         bVMirr ? 1.0 : 0.0);
                 [ #  # ]
     239 [ #  # ][ #  # ]:          0 :                     aTransform = getTransform() * aTransform;
                 [ #  # ]
     240                 :            :                 }
     241                 :            : 
     242                 :            :                 // Get transformed graphic. Suppress rotation and cropping, only filtering is needed
     243                 :            :                 // here (and may be replaced later on). Cropping is handled below as mask primitive (if set).
     244                 :            :                 // Also need to suppress mirroring, it is part of the transformation now (see above).
     245                 :         80 :                 GraphicAttr aSuppressGraphicAttr(getGraphicAttr());
     246                 :         80 :                 aSuppressGraphicAttr.SetCrop(0, 0, 0, 0);
     247                 :         80 :                 aSuppressGraphicAttr.SetRotation(0);
     248                 :         80 :                 aSuppressGraphicAttr.SetMirrorFlags(0);
     249                 :            : 
     250                 :         80 :                 const GraphicObject&    rGraphicObject = getGraphicObject();
     251         [ +  - ]:         80 :                 const Graphic           aTransformedGraphic(rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr));
     252                 :            : 
     253         [ +  - ]:         80 :                 switch(aTransformedGraphic.GetType())
              [ +  +  - ]
     254                 :            :                 {
     255                 :            :                     case GRAPHIC_BITMAP :
     256                 :            :                     {
     257 [ +  - ][ -  + ]:         15 :                         if(aTransformedGraphic.IsAnimated())
     258                 :            :                         {
     259                 :            :                             // prepare animation data
     260         [ #  # ]:          0 :                             animatedBitmapExPreparator aData(aTransformedGraphic);
     261                 :            : 
     262         [ #  # ]:          0 :                             if(aData.count())
     263                 :            :                             {
     264                 :            :                                 // create sub-primitives for animated bitmap and the needed animation loop
     265 [ #  # ][ #  # ]:          0 :                                 animation::AnimationEntryLoop aAnimationLoop(aData.loopCount() ? aData.loopCount() : 0xffff);
     266         [ #  # ]:          0 :                                 Primitive2DSequence aBitmapPrimitives(aData.count());
     267                 :            : 
     268         [ #  # ]:          0 :                                 for(sal_uInt32 a(0L); a < aData.count(); a++)
     269                 :            :                                 {
     270 [ #  # ][ #  # ]:          0 :                                     animation::AnimationEntryFixed aTime((double)aData.stepTime(a), (double)a / (double)aData.count());
     271         [ #  # ]:          0 :                                     aAnimationLoop.append(aTime);
     272 [ #  # ][ #  # ]:          0 :                                     const Primitive2DReference xRef(new BitmapPrimitive2D(aData.stepBitmapEx(a), aTransform));
         [ #  # ][ #  # ]
     273 [ #  # ][ #  # ]:          0 :                                     aBitmapPrimitives[a] = xRef;
     274         [ #  # ]:          0 :                                 }
     275                 :            : 
     276                 :            :                                 // prepare animation list
     277         [ #  # ]:          0 :                                 animation::AnimationEntryList aAnimationList;
     278         [ #  # ]:          0 :                                 aAnimationList.append(aAnimationLoop);
     279                 :            : 
     280                 :            :                                 // create and add animated switch primitive
     281 [ #  # ][ #  # ]:          0 :                                 xPrimitive = Primitive2DReference(new AnimatedSwitchPrimitive2D(aAnimationList, aBitmapPrimitives, false));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     282         [ #  # ]:          0 :                             }
     283                 :            :                         }
     284                 :            :                         else
     285                 :            :                         {
     286 [ +  - ][ +  - ]:         15 :                             xPrimitive = Primitive2DReference(new BitmapPrimitive2D(aTransformedGraphic.GetBitmapEx(), aTransform));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     287                 :            :                         }
     288                 :            : 
     289                 :         15 :                         break;
     290                 :            :                     }
     291                 :            : 
     292                 :            :                     case GRAPHIC_GDIMETAFILE :
     293                 :            :                     {
     294                 :            :                             // create MetafilePrimitive2D
     295         [ +  - ]:         65 :                             const GDIMetaFile& rMetafile = aTransformedGraphic.GetGDIMetaFile();
     296                 :            : 
     297 [ +  - ][ -  + ]:         65 :                             if( aTransformedGraphic.IsRenderGraphic() )
     298                 :            :                             {
     299                 :            :                                 xPrimitive = Primitive2DReference(
     300                 :            :                                     new RenderGraphicPrimitive2D(
     301         [ #  # ]:          0 :                                         static_cast< MetaRenderGraphicAction* >(rMetafile.GetAction(0))->GetRenderGraphic(),
     302 [ #  # ][ #  # ]:          0 :                                         aTransform));
         [ #  # ][ #  # ]
     303                 :            :                             }
     304                 :            :                             else
     305                 :            :                             {
     306                 :            :                                 xPrimitive = Primitive2DReference(
     307                 :            :                                     new MetafilePrimitive2D(
     308                 :            :                                         aTransform,
     309 [ +  - ][ +  - ]:         65 :                                         rMetafile));
         [ +  - ][ +  - ]
     310                 :            : 
     311                 :            :                                 // #i100357# find out if clipping is needed for this primitive. Unfortunately,
     312                 :            :                                 // there exist Metafiles who's content is bigger than the proposed PrefSize set
     313                 :            :                                 // at them. This is an error, but we need to work around this
     314                 :         65 :                                 const Size aMetaFilePrefSize(rMetafile.GetPrefSize());
     315                 :            :                                 const Size aMetaFileRealSize(
     316                 :            :                                     const_cast< GDIMetaFile& >(rMetafile).GetBoundRect(
     317 [ +  - ][ +  - ]:         65 :                                         *Application::GetDefaultDevice()).GetSize());
                 [ +  - ]
     318                 :            : 
     319   [ +  -  -  + ]:        130 :                                 if(aMetaFileRealSize.getWidth() > aMetaFilePrefSize.getWidth()
                 [ -  + ]
     320                 :         65 :                                     || aMetaFileRealSize.getHeight() > aMetaFilePrefSize.getHeight())
     321                 :            :                                 {
     322                 :            :                                     // clipping needed. Embed to MaskPrimitive2D. Create children and mask polygon
     323         [ #  # ]:          0 :                                     const primitive2d::Primitive2DSequence aChildContent(&xPrimitive, 1);
     324         [ #  # ]:          0 :                                     basegfx::B2DPolygon aMaskPolygon(basegfx::tools::createUnitPolygon());
     325         [ #  # ]:          0 :                                     aMaskPolygon.transform(aTransform);
     326                 :            : 
     327                 :            :                                     xPrimitive = Primitive2DReference(
     328                 :            :                                         new MaskPrimitive2D(
     329                 :            :                                             basegfx::B2DPolyPolygon(aMaskPolygon),
     330 [ #  # ][ #  # ]:         65 :                                             aChildContent));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     331                 :            :                                 }
     332                 :            :                             }
     333                 :            : 
     334                 :         65 :                         break;
     335                 :            :                     }
     336                 :            : 
     337                 :            :                     default:
     338                 :            :                     {
     339                 :            :                         // nothing to create
     340                 :          0 :                         break;
     341                 :            :                     }
     342                 :            :                 }
     343                 :            : 
     344         [ +  - ]:         80 :                 if(xPrimitive.is())
     345                 :            :                 {
     346                 :            :                     // check for cropping
     347         [ -  + ]:         80 :                     if(getGraphicAttr().IsCropped())
     348                 :            :                     {
     349                 :            :                         // decompose to get current pos and size
     350                 :          0 :                         basegfx::B2DVector aScale, aTranslate;
     351                 :            :                         double fRotate, fShearX;
     352         [ #  # ]:          0 :                         getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
     353                 :            : 
     354                 :            :                         // create ranges. The current object range is just scale and translate
     355                 :            :                         const basegfx::B2DRange aCurrent(
     356                 :            :                             aTranslate.getX(), aTranslate.getY(),
     357         [ #  # ]:          0 :                             aTranslate.getX() + aScale.getX(), aTranslate.getY() + aScale.getY());
     358                 :            : 
     359                 :            :                         // calculate scalings between real image size and logic object size. This
     360                 :            :                         // is necessary since the crop values are relative to original bitmap size
     361                 :          0 :                         double fFactorX(1.0);
     362                 :          0 :                         double fFactorY(1.0);
     363                 :            : 
     364                 :            :                         {
     365         [ #  # ]:          0 :                             const MapMode aMapMode100thmm(MAP_100TH_MM);
     366                 :          0 :                             Size aBitmapSize(rGraphicObject.GetPrefSize());
     367                 :            : 
     368                 :            :                             // #i95968# better support PrefMapMode; special for MAP_PIXEL was missing
     369         [ #  # ]:          0 :                             if(MAP_PIXEL == rGraphicObject.GetPrefMapMode().GetMapUnit())
     370                 :            :                             {
     371 [ #  # ][ #  # ]:          0 :                                 aBitmapSize = Application::GetDefaultDevice()->PixelToLogic(aBitmapSize, aMapMode100thmm);
     372                 :            :                             }
     373                 :            :                             else
     374                 :            :                             {
     375 [ #  # ][ #  # ]:          0 :                                 aBitmapSize = Application::GetDefaultDevice()->LogicToLogic(aBitmapSize, rGraphicObject.GetPrefMapMode(), aMapMode100thmm);
     376                 :            :                             }
     377                 :            : 
     378                 :          0 :                             const double fDivX(aBitmapSize.Width() - getGraphicAttr().GetLeftCrop() - getGraphicAttr().GetRightCrop());
     379                 :          0 :                             const double fDivY(aBitmapSize.Height() - getGraphicAttr().GetTopCrop() - getGraphicAttr().GetBottomCrop());
     380                 :            : 
     381         [ #  # ]:          0 :                             if(!basegfx::fTools::equalZero(fDivX))
     382                 :            :                             {
     383                 :          0 :                                 fFactorX = aScale.getX() / fDivX;
     384                 :            :                             }
     385                 :            : 
     386         [ #  # ]:          0 :                             if(!basegfx::fTools::equalZero(fDivY))
     387                 :            :                             {
     388                 :          0 :                                 fFactorY = aScale.getY() / fDivY;
     389         [ #  # ]:          0 :                             }
     390                 :            :                         }
     391                 :            : 
     392                 :            :                         // Create cropped range, describes the bounds of the original graphic
     393         [ #  # ]:          0 :                         basegfx::B2DRange aCropped;
     394 [ #  # ][ #  # ]:          0 :                         aCropped.expand(aCurrent.getMinimum() - basegfx::B2DPoint(getGraphicAttr().GetLeftCrop() * fFactorX, getGraphicAttr().GetTopCrop() * fFactorY));
     395 [ #  # ][ #  # ]:          0 :                         aCropped.expand(aCurrent.getMaximum() + basegfx::B2DPoint(getGraphicAttr().GetRightCrop() * fFactorX, getGraphicAttr().GetBottomCrop() * fFactorY));
     396                 :            : 
     397 [ #  # ][ #  # ]:          0 :                         if(aCropped.isEmpty())
     398                 :            :                         {
     399                 :            :                             // nothing to add since cropped bitmap is completely empty
     400                 :            :                             // xPrimitive will not be used
     401                 :            :                         }
     402                 :            :                         else
     403                 :            :                         {
     404                 :            :                             // build new object transformation for transform primitive which contains xPrimitive
     405         [ #  # ]:          0 :                             basegfx::B2DHomMatrix aNewObjectTransform(getTransform());
     406         [ #  # ]:          0 :                             aNewObjectTransform.invert();
     407                 :            :                             aNewObjectTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
     408                 :            :                                 aCropped.getWidth(), aCropped.getHeight(),
     409 [ #  # ][ #  # ]:          0 :                                 aCropped.getMinX() - aCurrent.getMinX(), aCropped.getMinY() - aCurrent.getMinY())
         [ #  # ][ #  # ]
     410 [ #  # ][ #  # ]:          0 :                                 * aNewObjectTransform;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     411                 :            : 
     412                 :            :                             // add shear, rotate and translate using combined matrix to speedup
     413                 :            :                             const basegfx::B2DHomMatrix aCombinedMatrix(basegfx::tools::createShearXRotateTranslateB2DHomMatrix(
     414         [ #  # ]:          0 :                                 fShearX, fRotate, aTranslate.getX(), aTranslate.getY()));
     415 [ #  # ][ #  # ]:          0 :                             aNewObjectTransform = aCombinedMatrix * aNewObjectTransform;
                 [ #  # ]
     416                 :            : 
     417                 :            :                             // prepare TransformPrimitive2D with xPrimitive
     418 [ #  # ][ #  # ]:          0 :                             const Primitive2DReference xTransformPrimitive(new TransformPrimitive2D(aNewObjectTransform, Primitive2DSequence(&xPrimitive, 1L)));
         [ #  # ][ #  # ]
                 [ #  # ]
     419                 :            : 
     420 [ #  # ][ #  # ]:          0 :                             if(aCurrent.isInside(aCropped))
     421                 :            :                             {
     422                 :            :                                 // cropped just got smaller, no need to really use a mask. Add to destination directly
     423         [ #  # ]:          0 :                                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xTransformPrimitive);
     424                 :            :                             }
     425                 :            :                             else
     426                 :            :                             {
     427                 :            :                                 // cropped got bigger, mask it with original object's bounds
     428 [ #  # ][ #  # ]:          0 :                                 basegfx::B2DPolyPolygon aMaskPolyPolygon(basegfx::tools::createUnitPolygon());
                 [ #  # ]
     429         [ #  # ]:          0 :                                 aMaskPolyPolygon.transform(getTransform());
     430                 :            : 
     431                 :            :                                 // create maskPrimitive with aMaskPolyPolygon and aMaskContentVector
     432 [ #  # ][ #  # ]:          0 :                                 const Primitive2DReference xRefB(new MaskPrimitive2D(aMaskPolyPolygon, Primitive2DSequence(&xTransformPrimitive, 1L)));
         [ #  # ][ #  # ]
                 [ #  # ]
     433 [ #  # ][ #  # ]:          0 :                                 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xRefB);
     434 [ #  # ][ #  # ]:          0 :                             }
     435                 :          0 :                         }
     436                 :            :                     }
     437                 :            :                     else
     438                 :            :                     {
     439                 :            :                         // add to decomposition
     440         [ +  - ]:         80 :                         appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xPrimitive);
     441                 :            :                     }
     442 [ +  - ][ +  - ]:         80 :                 }
                 [ +  - ]
     443                 :            :             }
     444                 :            : 
     445                 :         80 :             return aRetval;
     446                 :            :         }
     447                 :            : 
     448                 :        143 :         GraphicPrimitive2D::GraphicPrimitive2D(
     449                 :            :             const basegfx::B2DHomMatrix& rTransform,
     450                 :            :             const GraphicObject& rGraphicObject,
     451                 :            :             const GraphicAttr& rGraphicAttr)
     452                 :            :         :   BufferedDecompositionPrimitive2D(),
     453                 :            :             maTransform(rTransform),
     454                 :            :             maGraphicObject(rGraphicObject),
     455 [ +  - ][ +  - ]:        143 :             maGraphicAttr(rGraphicAttr)
     456                 :            :         {
     457                 :        143 :         }
     458                 :            : 
     459                 :          0 :         bool GraphicPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     460                 :            :         {
     461         [ #  # ]:          0 :             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
     462                 :            :             {
     463                 :          0 :                 const GraphicPrimitive2D& rCompare = (GraphicPrimitive2D&)rPrimitive;
     464                 :            : 
     465                 :          0 :                 return (getTransform() == rCompare.getTransform()
     466                 :          0 :                     && getGraphicObject() == rCompare.getGraphicObject()
     467         [ #  # ]:          0 :                     && getGraphicAttr() == rCompare.getGraphicAttr());
           [ #  #  #  # ]
     468                 :            :             }
     469                 :            : 
     470                 :          0 :             return false;
     471                 :            :         }
     472                 :            : 
     473                 :        111 :         basegfx::B2DRange GraphicPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
     474                 :            :         {
     475                 :        111 :             basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
     476                 :        111 :             aRetval.transform(getTransform());
     477                 :        111 :             return aRetval;
     478                 :            :         }
     479                 :            : 
     480                 :            :         // provide unique ID
     481                 :         95 :         ImplPrimitrive2DIDBlock(GraphicPrimitive2D, PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D)
     482                 :            : 
     483                 :            :     } // end of namespace primitive2d
     484                 :            : } // end of namespace drawinglayer
     485                 :            : 
     486                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10