LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - wallpaperprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 92 1.1 %
Date: 2014-11-03 Functions: 2 7 28.6 %
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 <drawinglayer/primitive2d/wallpaperprimitive2d.hxx>
      21             : #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
      22             : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      23             : #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
      24             : #include <basegfx/polygon/b2dpolygontools.hxx>
      25             : #include <basegfx/polygon/b2dpolygon.hxx>
      26             : #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
      27             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      28             : #include <vcl/graph.hxx>
      29             : 
      30             : 
      31             : 
      32             : namespace drawinglayer
      33             : {
      34             :     namespace primitive2d
      35             :     {
      36           0 :         Primitive2DSequence WallpaperBitmapPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      37             :         {
      38           0 :             Primitive2DSequence aRetval;
      39             : 
      40           0 :             if(!getLocalObjectRange().isEmpty() && !getBitmapEx().IsEmpty())
      41             :             {
      42             :                 // get bitmap PIXEL size
      43           0 :                 const Size& rPixelSize = getBitmapEx().GetSizePixel();
      44             : 
      45           0 :                 if(rPixelSize.Width() > 0 && rPixelSize.Height() > 0)
      46             :                 {
      47           0 :                     if(WALLPAPER_SCALE == getWallpaperStyle())
      48             :                     {
      49             :                         // shortcut for scale; use simple BitmapPrimitive2D
      50           0 :                         basegfx::B2DHomMatrix aObjectTransform;
      51             : 
      52           0 :                         aObjectTransform.set(0, 0, getLocalObjectRange().getWidth());
      53           0 :                         aObjectTransform.set(1, 1, getLocalObjectRange().getHeight());
      54           0 :                         aObjectTransform.set(0, 2, getLocalObjectRange().getMinX());
      55           0 :                         aObjectTransform.set(1, 2, getLocalObjectRange().getMinY());
      56             : 
      57             :                         Primitive2DReference xReference(
      58             :                             new BitmapPrimitive2D(
      59             :                                 getBitmapEx(),
      60           0 :                                 aObjectTransform));
      61             : 
      62           0 :                         aRetval = Primitive2DSequence(&xReference, 1);
      63             :                     }
      64             :                     else
      65             :                     {
      66             :                         // transform to logic size
      67           0 :                         basegfx::B2DHomMatrix aInverseViewTransformation(getViewTransformation());
      68           0 :                         aInverseViewTransformation.invert();
      69           0 :                         basegfx::B2DVector aLogicSize(rPixelSize.Width(), rPixelSize.Height());
      70           0 :                         aLogicSize = aInverseViewTransformation * aLogicSize;
      71             : 
      72             :                         // apply laout
      73           0 :                         basegfx::B2DPoint aTargetTopLeft(getLocalObjectRange().getMinimum());
      74           0 :                         bool bUseTargetTopLeft(true);
      75           0 :                         bool bNeedsClipping(false);
      76             : 
      77           0 :                         switch(getWallpaperStyle())
      78             :                         {
      79             :                             default: //case WALLPAPER_TILE :, also WALLPAPER_NULL and WALLPAPER_APPLICATIONGRADIENT
      80             :                             {
      81           0 :                                 bUseTargetTopLeft = false;
      82           0 :                                 break;
      83             :                             }
      84             :                             case WALLPAPER_SCALE :
      85             :                             {
      86             :                                 // handled by shortcut above
      87           0 :                                 break;
      88             :                             }
      89             :                             case WALLPAPER_TOPLEFT :
      90             :                             {
      91             :                                 // nothing to do
      92           0 :                                 break;
      93             :                             }
      94             :                             case WALLPAPER_TOP :
      95             :                             {
      96           0 :                                 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
      97           0 :                                 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
      98           0 :                                 break;
      99             :                             }
     100             :                             case WALLPAPER_TOPRIGHT :
     101             :                             {
     102           0 :                                 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
     103           0 :                                 break;
     104             :                             }
     105             :                             case WALLPAPER_LEFT :
     106             :                             {
     107           0 :                                 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
     108           0 :                                 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
     109           0 :                                 break;
     110             :                             }
     111             :                             case WALLPAPER_CENTER :
     112             :                             {
     113           0 :                                 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
     114           0 :                                 aTargetTopLeft = aCenter - (aLogicSize * 0.5);
     115           0 :                                 break;
     116             :                             }
     117             :                             case WALLPAPER_RIGHT :
     118             :                             {
     119           0 :                                 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
     120           0 :                                 aTargetTopLeft.setX(getLocalObjectRange().getMaxX() - aLogicSize.getX());
     121           0 :                                 aTargetTopLeft.setY(aCenter.getY() - (aLogicSize.getY() * 0.5));
     122           0 :                                 break;
     123             :                             }
     124             :                             case WALLPAPER_BOTTOMLEFT :
     125             :                             {
     126           0 :                                 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
     127           0 :                                 break;
     128             :                             }
     129             :                             case WALLPAPER_BOTTOM :
     130             :                             {
     131           0 :                                 const basegfx::B2DPoint aCenter(getLocalObjectRange().getCenter());
     132           0 :                                 aTargetTopLeft.setX(aCenter.getX() - (aLogicSize.getX() * 0.5));
     133           0 :                                 aTargetTopLeft.setY(getLocalObjectRange().getMaxY() - aLogicSize.getY());
     134           0 :                                 break;
     135             :                             }
     136             :                             case WALLPAPER_BOTTOMRIGHT :
     137             :                             {
     138           0 :                                 aTargetTopLeft = getLocalObjectRange().getMaximum() - aLogicSize;
     139           0 :                                 break;
     140             :                             }
     141             :                         }
     142             : 
     143           0 :                         if(bUseTargetTopLeft)
     144             :                         {
     145             :                             // fill target range
     146           0 :                             const basegfx::B2DRange aTargetRange(aTargetTopLeft, aTargetTopLeft + aLogicSize);
     147             : 
     148             :                             // create aligned, single BitmapPrimitive2D
     149           0 :                             basegfx::B2DHomMatrix aObjectTransform;
     150             : 
     151           0 :                             aObjectTransform.set(0, 0, aTargetRange.getWidth());
     152           0 :                             aObjectTransform.set(1, 1, aTargetRange.getHeight());
     153           0 :                             aObjectTransform.set(0, 2, aTargetRange.getMinX());
     154           0 :                             aObjectTransform.set(1, 2, aTargetRange.getMinY());
     155             : 
     156             :                             Primitive2DReference xReference(
     157             :                                 new BitmapPrimitive2D(
     158             :                                     getBitmapEx(),
     159           0 :                                     aObjectTransform));
     160           0 :                             aRetval = Primitive2DSequence(&xReference, 1);
     161             : 
     162             :                             // clip when not completely inside object range
     163           0 :                             bNeedsClipping = !getLocalObjectRange().isInside(aTargetRange);
     164             :                         }
     165             :                         else
     166             :                         {
     167             :                             // WALLPAPER_TILE, WALLPAPER_NULL, WALLPAPER_APPLICATIONGRADIENT
     168             :                             // convert to relative positions
     169             :                             const basegfx::B2DVector aRelativeSize(
     170           0 :                                 aLogicSize.getX() / (getLocalObjectRange().getWidth() ? getLocalObjectRange().getWidth() : 1.0),
     171           0 :                                 aLogicSize.getY() / (getLocalObjectRange().getHeight() ? getLocalObjectRange().getHeight() : 1.0));
     172           0 :                             basegfx::B2DPoint aRelativeTopLeft(0.0, 0.0);
     173             : 
     174           0 :                             if(WALLPAPER_TILE != getWallpaperStyle())
     175             :                             {
     176           0 :                                 aRelativeTopLeft.setX(0.5 - aRelativeSize.getX());
     177           0 :                                 aRelativeTopLeft.setY(0.5 - aRelativeSize.getY());
     178             :                             }
     179             : 
     180             :                             // prepare FillGraphicAttribute
     181             :                             const attribute::FillGraphicAttribute aFillGraphicAttribute(
     182           0 :                                 Graphic(getBitmapEx()),
     183           0 :                                 basegfx::B2DRange(aRelativeTopLeft, aRelativeTopLeft+ aRelativeSize),
     184           0 :                                 true);
     185             : 
     186             :                             // create ObjectTransform
     187             :                             const basegfx::B2DHomMatrix aObjectTransform(
     188             :                                 basegfx::tools::createScaleTranslateB2DHomMatrix(
     189           0 :                                     getLocalObjectRange().getRange(),
     190           0 :                                     getLocalObjectRange().getMinimum()));
     191             : 
     192             :                             // create FillBitmapPrimitive
     193             :                             const drawinglayer::primitive2d::Primitive2DReference xFillBitmap(
     194             :                                 new drawinglayer::primitive2d::FillGraphicPrimitive2D(
     195             :                                     aObjectTransform,
     196           0 :                                     aFillGraphicAttribute));
     197           0 :                             aRetval = Primitive2DSequence(&xFillBitmap, 1);
     198             : 
     199             :                             // always embed tiled fill to clipping
     200           0 :                             bNeedsClipping = true;
     201             :                         }
     202             : 
     203           0 :                         if(bNeedsClipping)
     204             :                         {
     205             :                             // embed to clipping; this is necessary for tiled fills
     206             :                             const basegfx::B2DPolyPolygon aPolyPolygon(
     207           0 :                                 basegfx::tools::createPolygonFromRect(getLocalObjectRange()));
     208             :                             const drawinglayer::primitive2d::Primitive2DReference xClippedFill(
     209             :                                 new drawinglayer::primitive2d::MaskPrimitive2D(
     210             :                                     aPolyPolygon,
     211           0 :                                     aRetval));
     212           0 :                             aRetval = Primitive2DSequence(&xClippedFill, 1);
     213           0 :                         }
     214             :                     }
     215             :                 }
     216             :             }
     217             : 
     218           0 :             return aRetval;
     219             :         }
     220             : 
     221           0 :         WallpaperBitmapPrimitive2D::WallpaperBitmapPrimitive2D(
     222             :             const basegfx::B2DRange& rObjectRange,
     223             :             const BitmapEx& rBitmapEx,
     224             :             WallpaperStyle eWallpaperStyle)
     225             :         :   ViewTransformationDependentPrimitive2D(),
     226             :             maObjectRange(rObjectRange),
     227             :             maBitmapEx(rBitmapEx),
     228           0 :             meWallpaperStyle(eWallpaperStyle)
     229             :         {
     230           0 :         }
     231             : 
     232           0 :         bool WallpaperBitmapPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
     233             :         {
     234           0 :             if(ViewTransformationDependentPrimitive2D::operator==(rPrimitive))
     235             :             {
     236           0 :                 const WallpaperBitmapPrimitive2D& rCompare = static_cast<const WallpaperBitmapPrimitive2D&>(rPrimitive);
     237             : 
     238           0 :                 return (getLocalObjectRange() == rCompare.getLocalObjectRange()
     239           0 :                     && getBitmapEx() == rCompare.getBitmapEx()
     240           0 :                     && getWallpaperStyle() == rCompare.getWallpaperStyle());
     241             :             }
     242             : 
     243           0 :             return false;
     244             :         }
     245             : 
     246           0 :         basegfx::B2DRange WallpaperBitmapPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
     247             :         {
     248           0 :             return getLocalObjectRange();
     249             :         }
     250             : 
     251             :         // provide unique ID
     252           0 :         ImplPrimitive2DIDBlock(WallpaperBitmapPrimitive2D, PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D)
     253             :     } // end of namespace primitive2d
     254        1143 : } // end of namespace drawinglayer
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10