LCOV - code coverage report
Current view: top level - sdext/source/presenter - PresenterCanvasHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 85 0.0 %
Date: 2012-08-25 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 228 0.0 %

           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 "PresenterCanvasHelper.hxx"
      30                 :            : 
      31                 :            : #include "PresenterController.hxx"
      32                 :            : #include "PresenterGeometryHelper.hxx"
      33                 :            : #include <com/sun/star/rendering/CompositeOperation.hpp>
      34                 :            : #include <com/sun/star/rendering/TextDirection.hpp>
      35                 :            : #include <com/sun/star/rendering/TexturingMode.hpp>
      36                 :            : 
      37                 :            : using namespace ::com::sun::star;
      38                 :            : using namespace ::com::sun::star::uno;
      39                 :            : 
      40                 :            : namespace sdext { namespace presenter {
      41                 :            : 
      42                 :          0 : PresenterCanvasHelper::PresenterCanvasHelper (void)
      43                 :            :     : maDefaultViewState(
      44                 :            :         geometry::AffineMatrix2D(1,0,0, 0,1,0),
      45                 :            :         NULL),
      46                 :            :       maDefaultRenderState(
      47                 :            :           geometry::AffineMatrix2D(1,0,0, 0,1,0),
      48                 :            :           NULL,
      49                 :            :           Sequence<double>(4),
      50 [ #  # ][ #  # ]:          0 :           rendering::CompositeOperation::SOURCE)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      51                 :            : {
      52                 :          0 : }
      53                 :            : 
      54 [ #  # ][ #  # ]:          0 : PresenterCanvasHelper::~PresenterCanvasHelper (void)
      55                 :            : {
      56                 :          0 : }
      57                 :            : 
      58                 :          0 : void PresenterCanvasHelper::Paint (
      59                 :            :     const SharedBitmapDescriptor& rpBitmap,
      60                 :            :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
      61                 :            :     const css::awt::Rectangle& rRepaintBox,
      62                 :            :     const css::awt::Rectangle& rOuterBoundingBox,
      63                 :            :     const css::awt::Rectangle& rContentBoundingBox) const
      64                 :            : {
      65                 :            :     PaintRectangle(rpBitmap,rxCanvas,rRepaintBox,rOuterBoundingBox,rContentBoundingBox,
      66                 :          0 :         maDefaultViewState, maDefaultRenderState);
      67                 :          0 : }
      68                 :            : 
      69                 :          0 : void PresenterCanvasHelper::PaintRectangle (
      70                 :            :     const SharedBitmapDescriptor& rpBitmap,
      71                 :            :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
      72                 :            :     const css::awt::Rectangle& rRepaintBox,
      73                 :            :     const css::awt::Rectangle& rOuterBoundingBox,
      74                 :            :     const css::awt::Rectangle& rContentBoundingBox,
      75                 :            :     const css::rendering::ViewState& rDefaultViewState,
      76                 :            :     const css::rendering::RenderState& rDefaultRenderState)
      77                 :            : {
      78         [ #  # ]:          0 :     if (rpBitmap.get() == NULL)
      79                 :            :         return;
      80                 :            : 
      81 [ #  # ][ #  # ]:          0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
      82                 :            :         return;
      83                 :            : 
      84                 :            :     // Create a clip polypolygon that has the content box as hole.
      85         [ #  # ]:          0 :     ::std::vector<awt::Rectangle> aRectangles;
      86         [ #  # ]:          0 :     aRectangles.reserve(2);
      87                 :            :     aRectangles.push_back(
      88 [ #  # ][ #  # ]:          0 :         PresenterGeometryHelper::Intersection(rRepaintBox, rOuterBoundingBox));
      89 [ #  # ][ #  # ]:          0 :     if (rContentBoundingBox.Width > 0 && rContentBoundingBox.Height > 0)
      90                 :            :         aRectangles.push_back(
      91 [ #  # ][ #  # ]:          0 :             PresenterGeometryHelper::Intersection(rRepaintBox, rContentBoundingBox));
      92                 :            :     Reference<rendering::XPolyPolygon2D> xPolyPolygon (
      93                 :            :         PresenterGeometryHelper::CreatePolygon(
      94                 :            :             aRectangles,
      95 [ #  # ][ #  # ]:          0 :             rxCanvas->getDevice()));
                 [ #  # ]
      96         [ #  # ]:          0 :     if ( ! xPolyPolygon.is())
      97                 :            :         return;
      98 [ #  # ][ #  # ]:          0 :     xPolyPolygon->setFillRule(rendering::FillRule_EVEN_ODD);
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 :     if (rpBitmap->GetNormalBitmap().is())
     101                 :            :     {
     102   [ #  #  #  # ]:          0 :         if (rpBitmap->meHorizontalTexturingMode == PresenterBitmapDescriptor::Repeat
                 [ #  # ]
     103                 :          0 :             || rpBitmap->meVerticalTexturingMode == PresenterBitmapDescriptor::Repeat)
     104                 :            :         {
     105                 :            :             PaintTiledBitmap(
     106                 :            :                 Reference<rendering::XBitmap>(rpBitmap->GetNormalBitmap(), UNO_QUERY),
     107                 :            :                 rxCanvas,
     108                 :            :                 rRepaintBox,
     109                 :            :                 xPolyPolygon,
     110                 :            :                 rContentBoundingBox,
     111                 :            :                 rDefaultViewState,
     112 [ #  # ][ #  # ]:          0 :                 rDefaultRenderState);
                 [ #  # ]
     113                 :            :         }
     114                 :            :         else
     115                 :            :         {
     116                 :            :             PaintBitmap(
     117                 :            :                 Reference<rendering::XBitmap>(rpBitmap->GetNormalBitmap(), UNO_QUERY),
     118                 :            :                 awt::Point(rOuterBoundingBox.X, rOuterBoundingBox.Y),
     119                 :            :                 rxCanvas,
     120                 :            :                 rRepaintBox,
     121                 :            :                 xPolyPolygon,
     122                 :            :                 rDefaultViewState,
     123 [ #  # ][ #  # ]:          0 :                 rDefaultRenderState);
                 [ #  # ]
     124                 :            :         }
     125                 :            :     }
     126                 :            :     else
     127                 :            :     {
     128                 :            :         PaintColor(
     129                 :          0 :             rpBitmap->maReplacementColor,
     130                 :            :             rxCanvas,
     131                 :            :             rRepaintBox,
     132                 :            :             xPolyPolygon,
     133                 :            :             rDefaultViewState,
     134         [ #  # ]:          0 :             rDefaultRenderState);
     135 [ #  # ][ #  # ]:          0 :     }
     136                 :            : }
     137                 :            : 
     138                 :          0 : void PresenterCanvasHelper::PaintTiledBitmap (
     139                 :            :     const css::uno::Reference<css::rendering::XBitmap>& rxTexture,
     140                 :            :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     141                 :            :     const css::awt::Rectangle& rRepaintBox,
     142                 :            :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     143                 :            :     const css::awt::Rectangle& rHole,
     144                 :            :     const css::rendering::ViewState& rDefaultViewState,
     145                 :            :     const css::rendering::RenderState& rDefaultRenderState)
     146                 :            : {
     147 [ #  # ][ #  # ]:          0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     148                 :            :         return;
     149                 :            : 
     150         [ #  # ]:          0 :     if ( ! rxTexture.is())
     151                 :            :         return;
     152                 :            : 
     153         [ #  # ]:          0 :     if ( ! rxPolygon.is())
     154                 :            :         return;
     155                 :            : 
     156         [ #  # ]:          0 :     rendering::ViewState aViewState (rDefaultViewState);
     157         [ #  # ]:          0 :     aViewState.Clip = rxPolygon;
     158                 :            : 
     159                 :            :     // Create a local render state at which the location of the bitmap is
     160                 :            :     // set.
     161         [ #  # ]:          0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     162                 :            : 
     163                 :            :     // Tile the bitmap over the repaint box.
     164 [ #  # ][ #  # ]:          0 :     const geometry::IntegerSize2D aBitmapSize (rxTexture->getSize());
     165                 :          0 :     const sal_Int32 nLeft = (rRepaintBox.X / aBitmapSize.Width) * aBitmapSize.Width;
     166                 :          0 :     const sal_Int32 nTop = (rRepaintBox.Y / aBitmapSize.Height) * aBitmapSize.Height;
     167                 :            :     const sal_Int32 nRight = ((rRepaintBox.X + rRepaintBox.Width - 1 + aBitmapSize.Width - 1)
     168                 :          0 :         / aBitmapSize.Width) * aBitmapSize.Width;
     169                 :            :     const sal_Int32 nBottom = ((rRepaintBox.Y + rRepaintBox.Height - 1 + aBitmapSize.Height - 1)
     170                 :          0 :         / aBitmapSize.Height) * aBitmapSize.Height;
     171                 :            : 
     172         [ #  # ]:          0 :     for (sal_Int32 nY=nTop; nY<=nBottom; nY+=aBitmapSize.Height)
     173         [ #  # ]:          0 :         for (sal_Int32 nX=nLeft; nX<=nRight; nX+=aBitmapSize.Width)
     174                 :            :         {
     175 [ #  # ][ #  # ]:          0 :             if (PresenterGeometryHelper::IsInside(
     176                 :            :                 awt::Rectangle(nX,nY,aBitmapSize.Width,aBitmapSize.Height),
     177                 :          0 :                 rHole))
     178                 :            :             {
     179                 :          0 :                 continue;
     180                 :            :             }
     181                 :          0 :             aRenderState.AffineTransform.m02 = nX;
     182                 :          0 :             aRenderState.AffineTransform.m12 = nY;
     183         [ #  # ]:          0 :             rxCanvas->drawBitmap(
     184                 :            :                 rxTexture,
     185                 :            :                 aViewState,
     186         [ #  # ]:          0 :                 aRenderState);
     187 [ #  # ][ #  # ]:          0 :         }
     188                 :            : }
     189                 :            : 
     190                 :          0 : void PresenterCanvasHelper::PaintBitmap (
     191                 :            :     const css::uno::Reference<css::rendering::XBitmap>& rxBitmap,
     192                 :            :     const awt::Point& rLocation,
     193                 :            :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     194                 :            :     const css::awt::Rectangle& rRepaintBox,
     195                 :            :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     196                 :            :     const css::rendering::ViewState& rDefaultViewState,
     197                 :            :     const css::rendering::RenderState& rDefaultRenderState)
     198                 :            : {
     199 [ #  # ][ #  # ]:          0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     200                 :            :         return;
     201                 :            : 
     202         [ #  # ]:          0 :     if ( ! rxBitmap.is())
     203                 :            :         return;
     204                 :            : 
     205         [ #  # ]:          0 :     if ( ! rxPolygon.is())
     206                 :            :         return;
     207                 :            : 
     208                 :            :     // Set the repaint box as clip rectangle at the view state.
     209         [ #  # ]:          0 :     rendering::ViewState aViewState (rDefaultViewState);
     210 [ #  # ][ #  # ]:          0 :     aViewState.Clip = PresenterGeometryHelper::CreatePolygon(rRepaintBox, rxCanvas->getDevice());
         [ #  # ][ #  # ]
     211                 :            : 
     212                 :            :     // Setup the rendering state so that the bitmap is painted top left in
     213                 :            :     // the polygon bounding box.
     214         [ #  # ]:          0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     215                 :          0 :     aRenderState.AffineTransform = geometry::AffineMatrix2D(1,0, rLocation.X, 0,1,rLocation.Y);
     216         [ #  # ]:          0 :     aRenderState.Clip = rxPolygon;
     217                 :            : 
     218         [ #  # ]:          0 :     rxCanvas->drawBitmap(
     219                 :            :         rxBitmap,
     220                 :            :         aViewState,
     221 [ #  # ][ #  # ]:          0 :         aRenderState);
                 [ #  # ]
     222                 :            : }
     223                 :            : 
     224                 :          0 : void PresenterCanvasHelper::PaintColor (
     225                 :            :     const css::util::Color nColor,
     226                 :            :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     227                 :            :     const css::awt::Rectangle& rRepaintBox,
     228                 :            :     const css::uno::Reference<css::rendering::XPolyPolygon2D>& rxPolygon,
     229                 :            :     const css::rendering::ViewState& rDefaultViewState,
     230                 :            :     const css::rendering::RenderState& rDefaultRenderState)
     231                 :            : {
     232 [ #  # ][ #  # ]:          0 :     if ( ! rxCanvas.is() || ! rxCanvas->getDevice().is())
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     233                 :            :         return;
     234                 :            : 
     235         [ #  # ]:          0 :     if ( ! rxPolygon.is())
     236                 :            :         return;
     237                 :            : 
     238                 :            :     // Set the repaint box as clip rectangle at the view state.
     239         [ #  # ]:          0 :     rendering::ViewState aViewState (rDefaultViewState);
     240 [ #  # ][ #  # ]:          0 :     aViewState.Clip = PresenterGeometryHelper::CreatePolygon(rRepaintBox, rxCanvas->getDevice());
         [ #  # ][ #  # ]
     241                 :            : 
     242                 :            :     // Setup the rendering state to use the given color.
     243         [ #  # ]:          0 :     rendering::RenderState aRenderState (rDefaultRenderState);
     244         [ #  # ]:          0 :     SetDeviceColor(aRenderState, nColor);
     245                 :            : 
     246         [ #  # ]:          0 :     rxCanvas->fillPolyPolygon(
     247                 :            :         rxPolygon,
     248                 :            :         aViewState,
     249 [ #  # ][ #  # ]:          0 :         aRenderState);
                 [ #  # ]
     250                 :            : }
     251                 :            : 
     252                 :          0 : void PresenterCanvasHelper::SetDeviceColor(
     253                 :            :     rendering::RenderState& rRenderState,
     254                 :            :     const util::Color aColor)
     255                 :            : {
     256                 :            :     // Other component counts then 4 (RGBA) are not accepted (anymore).
     257                 :            : 
     258                 :            :     OSL_ASSERT(rRenderState.DeviceColor.getLength() == 4);
     259         [ #  # ]:          0 :     if (rRenderState.DeviceColor.getLength() == 4)
     260                 :            :     {
     261                 :          0 :         rRenderState.DeviceColor[0] = ((aColor >> 16) & 0x0ff) / 255.0;
     262                 :          0 :         rRenderState.DeviceColor[1] = ((aColor >> 8) & 0x0ff) / 255.0;
     263                 :          0 :         rRenderState.DeviceColor[2] = ((aColor >> 0) & 0x0ff) / 255.0;
     264                 :          0 :         rRenderState.DeviceColor[3] = 1.0 - ((aColor >> 24) & 0x0ff) / 255.0;
     265                 :            :     }
     266                 :          0 : }
     267                 :            : 
     268                 :          0 : css::geometry::RealRectangle2D PresenterCanvasHelper::GetTextBoundingBox (
     269                 :            :     const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
     270                 :            :     const ::rtl::OUString& rsText,
     271                 :            :     const sal_Int8 nTextDirection)
     272                 :            : {
     273 [ #  # ][ #  # ]:          0 :     if (rxFont.is() && !rsText.isEmpty())
                 [ #  # ]
     274                 :            :     {
     275                 :          0 :         rendering::StringContext aContext (rsText, 0, rsText.getLength());
     276                 :            :         Reference<rendering::XTextLayout> xLayout (
     277 [ #  # ][ #  # ]:          0 :             rxFont->createTextLayout(aContext, nTextDirection, 0));
     278 [ #  # ][ #  # ]:          0 :         return xLayout->queryTextBounds();
     279                 :            :     }
     280                 :            :     else
     281                 :            :     {
     282                 :          0 :         return geometry::RealRectangle2D(0,0,0,0);
     283                 :            :     }
     284                 :            : }
     285                 :            : 
     286                 :          0 : css::geometry::RealSize2D PresenterCanvasHelper::GetTextSize (
     287                 :            :     const css::uno::Reference<css::rendering::XCanvasFont>& rxFont,
     288                 :            :     const ::rtl::OUString& rsText,
     289                 :            :     const sal_Int8 nTextDirection)
     290                 :            : {
     291         [ #  # ]:          0 :     const geometry::RealRectangle2D aTextBBox (GetTextBoundingBox(rxFont, rsText, nTextDirection));
     292                 :          0 :     return css::geometry::RealSize2D(aTextBBox.X2 - aTextBBox.X1, aTextBBox.Y2 - aTextBBox.Y1);
     293                 :            : }
     294                 :            : 
     295                 :            : } } // end of namespace sdext::presenter
     296                 :            : 
     297                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10