LCOV - code coverage report
Current view: top level - sdext/source/presenter - PresenterGeometryHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 105 0.0 %
Date: 2012-08-25 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 210 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 "PresenterGeometryHelper.hxx"
      30                 :            : 
      31                 :            : #include <math.h>
      32                 :            : #include <algorithm>
      33                 :            : 
      34                 :            : using namespace ::com::sun::star;
      35                 :            : using namespace ::com::sun::star::uno;
      36                 :            : 
      37                 :            : namespace {
      38                 :            : 
      39                 :          0 : sal_Int32 Right (const awt::Rectangle& rBox)
      40                 :            : {
      41                 :          0 :     return rBox.X + rBox.Width - 1;
      42                 :            : }
      43                 :            : 
      44                 :          0 : sal_Int32 Bottom (const awt::Rectangle& rBox)
      45                 :            : {
      46                 :          0 :     return rBox.Y + rBox.Height - 1;
      47                 :            : }
      48                 :            : 
      49                 :          0 : sal_Int32 Width (const sal_Int32 nLeft, const sal_Int32 nRight)
      50                 :            : {
      51                 :          0 :     return nRight - nLeft + 1;
      52                 :            : }
      53                 :            : 
      54                 :          0 : sal_Int32 Height (const sal_Int32 nTop, const sal_Int32 nBottom)
      55                 :            : {
      56                 :          0 :     return nBottom - nTop + 1;
      57                 :            : }
      58                 :            : 
      59                 :            : } // end of anonymous namespace
      60                 :            : 
      61                 :            : namespace sdext { namespace presenter {
      62                 :            : 
      63                 :          0 : sal_Int32 PresenterGeometryHelper::Floor (const double nValue)
      64                 :            : {
      65                 :          0 :     return sal::static_int_cast<sal_Int32>(floor(nValue));
      66                 :            : }
      67                 :            : 
      68                 :          0 : sal_Int32 PresenterGeometryHelper::Ceil (const double nValue)
      69                 :            : {
      70                 :          0 :     return sal::static_int_cast<sal_Int32>(ceil(nValue));
      71                 :            : }
      72                 :            : 
      73                 :          0 : sal_Int32 PresenterGeometryHelper::Round (const double nValue)
      74                 :            : {
      75                 :          0 :     return sal::static_int_cast<sal_Int32>(floor(0.5 + nValue));
      76                 :            : }
      77                 :            : 
      78                 :          0 : awt::Rectangle PresenterGeometryHelper::ConvertRectangle (
      79                 :            :     const geometry::RealRectangle2D& rBox)
      80                 :            : {
      81         [ #  # ]:          0 :     const sal_Int32 nLeft (Floor(rBox.X1));
      82         [ #  # ]:          0 :     const sal_Int32 nTop (Floor(rBox.Y1));
      83         [ #  # ]:          0 :     const sal_Int32 nRight (Ceil(rBox.X2));
      84         [ #  # ]:          0 :     const sal_Int32 nBottom (Ceil(rBox.Y2));
      85                 :          0 :     return awt::Rectangle (nLeft,nTop,nRight-nLeft,nBottom-nTop);
      86                 :            : }
      87                 :            : 
      88                 :          0 : awt::Rectangle PresenterGeometryHelper::ConvertRectangleWithConstantSize (
      89                 :            :     const geometry::RealRectangle2D& rBox)
      90                 :            : {
      91                 :            :     return awt::Rectangle (
      92         [ #  # ]:          0 :         Round(rBox.X1),
      93         [ #  # ]:          0 :         Round(rBox.Y1),
      94         [ #  # ]:          0 :         Round(rBox.X2 - rBox.X1),
      95                 :          0 :         Round(rBox.Y2 - rBox.Y1));
      96                 :            : }
      97                 :            : 
      98                 :          0 : geometry::RealRectangle2D PresenterGeometryHelper::ConvertRectangle (
      99                 :            :     const css::awt::Rectangle& rBox)
     100                 :            : {
     101                 :            :     return geometry::RealRectangle2D(
     102                 :            :         rBox.X,
     103                 :            :         rBox.Y,
     104                 :            :         rBox.X + rBox.Width,
     105                 :          0 :         rBox.Y + rBox.Height);
     106                 :            : }
     107                 :            : 
     108                 :          0 : awt::Rectangle PresenterGeometryHelper::TranslateRectangle (
     109                 :            :     const css::awt::Rectangle& rBox,
     110                 :            :     const sal_Int32 nXOffset,
     111                 :            :     const sal_Int32 nYOffset)
     112                 :            : {
     113                 :          0 :     return awt::Rectangle(rBox.X + nXOffset, rBox.Y + nYOffset, rBox.Width, rBox.Height);
     114                 :            : }
     115                 :            : 
     116                 :          0 : awt::Rectangle PresenterGeometryHelper::Intersection (
     117                 :            :     const css::awt::Rectangle& rBox1,
     118                 :            :     const css::awt::Rectangle& rBox2)
     119                 :            : {
     120         [ #  # ]:          0 :     const sal_Int32 nLeft (::std::max(rBox1.X, rBox2.X));
     121         [ #  # ]:          0 :     const sal_Int32 nTop (::std::max(rBox1.Y, rBox2.Y));
     122         [ #  # ]:          0 :     const sal_Int32 nRight (::std::min(Right(rBox1), Right(rBox2)));
     123         [ #  # ]:          0 :     const sal_Int32 nBottom (::std::min(Bottom(rBox1), Bottom(rBox2)));
     124 [ #  # ][ #  # ]:          0 :     if (nLeft >= nRight || nTop >= nBottom)
     125                 :          0 :         return awt::Rectangle();
     126                 :            :     else
     127                 :          0 :         return awt::Rectangle(nLeft,nTop, Width(nLeft,nRight), Height(nTop,nBottom));
     128                 :            : }
     129                 :            : 
     130                 :          0 : geometry::RealRectangle2D PresenterGeometryHelper::Intersection (
     131                 :            :     const geometry::RealRectangle2D& rBox1,
     132                 :            :     const geometry::RealRectangle2D& rBox2)
     133                 :            : {
     134         [ #  # ]:          0 :     const double nLeft (::std::max(rBox1.X1, rBox2.X1));
     135         [ #  # ]:          0 :     const double nTop (::std::max(rBox1.Y1, rBox2.Y1));
     136         [ #  # ]:          0 :     const double nRight (::std::min(rBox1.X2, rBox2.X2));
     137         [ #  # ]:          0 :     const double nBottom (::std::min(rBox1.Y2, rBox2.Y2));
     138 [ #  # ][ #  # ]:          0 :     if (nLeft >= nRight || nTop >= nBottom)
     139                 :          0 :         return geometry::RealRectangle2D(0,0,0,0);
     140                 :            :     else
     141                 :          0 :         return geometry::RealRectangle2D(nLeft,nTop, nRight, nBottom);
     142                 :            : }
     143                 :            : 
     144                 :          0 : bool PresenterGeometryHelper::IsInside (
     145                 :            :     const css::geometry::RealRectangle2D& rBox,
     146                 :            :     const css::geometry::RealPoint2D& rPoint)
     147                 :            : {
     148                 :            :     return rBox.X1 <= rPoint.X
     149                 :            :         && rBox.Y1 <= rPoint.Y
     150                 :            :         && rBox.X2 >= rPoint.X
     151 [ #  # ][ #  # ]:          0 :         && rBox.Y2 >= rPoint.Y;
         [ #  # ][ #  # ]
     152                 :            : }
     153                 :            : 
     154                 :          0 : bool PresenterGeometryHelper::IsInside (
     155                 :            :     const css::awt::Rectangle& rBox1,
     156                 :            :     const css::awt::Rectangle& rBox2)
     157                 :            : {
     158                 :            :     return rBox1.X >= rBox2.X
     159                 :            :         && rBox1.Y >= rBox2.Y
     160                 :            :         && rBox1.X+rBox1.Width <= rBox2.X+rBox2.Width
     161 [ #  # ][ #  # ]:          0 :         && rBox1.Y+rBox1.Height <= rBox2.Y+rBox2.Height;
         [ #  # ][ #  # ]
     162                 :            : }
     163                 :            : 
     164                 :          0 : geometry::RealRectangle2D PresenterGeometryHelper::Union (
     165                 :            :     const geometry::RealRectangle2D& rBox1,
     166                 :            :     const geometry::RealRectangle2D& rBox2)
     167                 :            : {
     168         [ #  # ]:          0 :     const double nLeft (::std::min(rBox1.X1, rBox2.X1));
     169         [ #  # ]:          0 :     const double nTop (::std::min(rBox1.Y1, rBox2.Y1));
     170         [ #  # ]:          0 :     const double nRight (::std::max(rBox1.X2, rBox2.X2));
     171         [ #  # ]:          0 :     const double nBottom (::std::max(rBox1.Y2, rBox2.Y2));
     172 [ #  # ][ #  # ]:          0 :     if (nLeft >= nRight || nTop >= nBottom)
     173                 :          0 :         return geometry::RealRectangle2D(0,0,0,0);
     174                 :            :     else
     175                 :          0 :         return geometry::RealRectangle2D(nLeft,nTop, nRight, nBottom);
     176                 :            : }
     177                 :            : 
     178                 :          0 : bool PresenterGeometryHelper::AreRectanglesDisjoint (
     179                 :            :     const css::awt::Rectangle& rBox1,
     180                 :            :     const css::awt::Rectangle& rBox2)
     181                 :            : {
     182                 :            :     return rBox1.X+rBox1.Width <= rBox2.X
     183                 :            :         || rBox1.Y+rBox1.Height <= rBox2.Y
     184                 :            :         || rBox1.X >= rBox2.X+rBox2.Width
     185 [ #  # ][ #  # ]:          0 :         || rBox1.Y >= rBox2.Y+rBox2.Height;
         [ #  # ][ #  # ]
     186                 :            : }
     187                 :            : 
     188                 :          0 : Reference<rendering::XPolyPolygon2D> PresenterGeometryHelper::CreatePolygon(
     189                 :            :     const awt::Rectangle& rBox,
     190                 :            :     const Reference<rendering::XGraphicDevice>& rxDevice)
     191                 :            : {
     192         [ #  # ]:          0 :     if ( ! rxDevice.is())
     193         [ #  # ]:          0 :         return NULL;
     194                 :            : 
     195         [ #  # ]:          0 :     Sequence<Sequence<geometry::RealPoint2D> > aPoints(1);
     196 [ #  # ][ #  # ]:          0 :     aPoints[0] = Sequence<geometry::RealPoint2D>(4);
         [ #  # ][ #  # ]
     197 [ #  # ][ #  # ]:          0 :     aPoints[0][0] = geometry::RealPoint2D(rBox.X, rBox.Y);
     198 [ #  # ][ #  # ]:          0 :     aPoints[0][1] = geometry::RealPoint2D(rBox.X, rBox.Y+rBox.Height);
     199 [ #  # ][ #  # ]:          0 :     aPoints[0][2] = geometry::RealPoint2D(rBox.X+rBox.Width, rBox.Y+rBox.Height);
     200 [ #  # ][ #  # ]:          0 :     aPoints[0][3] = geometry::RealPoint2D(rBox.X+rBox.Width, rBox.Y);
     201                 :            :     Reference<rendering::XLinePolyPolygon2D> xPolygon (
     202 [ #  # ][ #  # ]:          0 :         rxDevice->createCompatibleLinePolyPolygon(aPoints));
     203         [ #  # ]:          0 :     Reference<rendering::XPolyPolygon2D> xRectangle (xPolygon, UNO_QUERY);
     204         [ #  # ]:          0 :     if (xRectangle.is())
     205 [ #  # ][ #  # ]:          0 :         xRectangle->setClosed(0, sal_True);
     206                 :            : 
     207         [ #  # ]:          0 :     return xRectangle;
     208                 :            : }
     209                 :            : 
     210                 :          0 : Reference<rendering::XPolyPolygon2D> PresenterGeometryHelper::CreatePolygon(
     211                 :            :     const geometry::RealRectangle2D& rBox,
     212                 :            :     const Reference<rendering::XGraphicDevice>& rxDevice)
     213                 :            : {
     214         [ #  # ]:          0 :     if ( ! rxDevice.is())
     215         [ #  # ]:          0 :         return NULL;
     216                 :            : 
     217         [ #  # ]:          0 :     Sequence<Sequence<geometry::RealPoint2D> > aPoints(1);
     218 [ #  # ][ #  # ]:          0 :     aPoints[0] = Sequence<geometry::RealPoint2D>(4);
         [ #  # ][ #  # ]
     219 [ #  # ][ #  # ]:          0 :     aPoints[0][0] = geometry::RealPoint2D(rBox.X1, rBox.Y1);
     220 [ #  # ][ #  # ]:          0 :     aPoints[0][1] = geometry::RealPoint2D(rBox.X1, rBox.Y2);
     221 [ #  # ][ #  # ]:          0 :     aPoints[0][2] = geometry::RealPoint2D(rBox.X2, rBox.Y2);
     222 [ #  # ][ #  # ]:          0 :     aPoints[0][3] = geometry::RealPoint2D(rBox.X2, rBox.Y1);
     223                 :            :     Reference<rendering::XLinePolyPolygon2D> xPolygon (
     224 [ #  # ][ #  # ]:          0 :         rxDevice->createCompatibleLinePolyPolygon(aPoints));
     225         [ #  # ]:          0 :     Reference<rendering::XPolyPolygon2D> xRectangle (xPolygon, UNO_QUERY);
     226         [ #  # ]:          0 :     if (xRectangle.is())
     227 [ #  # ][ #  # ]:          0 :         xRectangle->setClosed(0, sal_True);
     228                 :            : 
     229         [ #  # ]:          0 :     return xRectangle;
     230                 :            : }
     231                 :            : 
     232                 :          0 : Reference<rendering::XPolyPolygon2D> PresenterGeometryHelper::CreatePolygon(
     233                 :            :     const ::std::vector<css::awt::Rectangle>& rBoxes,
     234                 :            :     const Reference<rendering::XGraphicDevice>& rxDevice)
     235                 :            : {
     236         [ #  # ]:          0 :     if ( ! rxDevice.is())
     237         [ #  # ]:          0 :         return NULL;
     238                 :            : 
     239                 :          0 :     const sal_Int32 nCount (rBoxes.size());
     240         [ #  # ]:          0 :     Sequence<Sequence<geometry::RealPoint2D> > aPoints(nCount);
     241         [ #  # ]:          0 :     for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     242                 :            :     {
     243                 :          0 :         const awt::Rectangle& rBox (rBoxes[nIndex]);
     244 [ #  # ][ #  # ]:          0 :         aPoints[nIndex] = Sequence<geometry::RealPoint2D>(4);
         [ #  # ][ #  # ]
     245 [ #  # ][ #  # ]:          0 :         aPoints[nIndex][0] = geometry::RealPoint2D(rBox.X, rBox.Y);
     246 [ #  # ][ #  # ]:          0 :         aPoints[nIndex][1] = geometry::RealPoint2D(rBox.X, rBox.Y+rBox.Height);
     247 [ #  # ][ #  # ]:          0 :         aPoints[nIndex][2] = geometry::RealPoint2D(rBox.X+rBox.Width, rBox.Y+rBox.Height);
     248 [ #  # ][ #  # ]:          0 :         aPoints[nIndex][3] = geometry::RealPoint2D(rBox.X+rBox.Width, rBox.Y);
     249                 :            :     }
     250                 :            : 
     251                 :            :     Reference<rendering::XLinePolyPolygon2D> xPolygon (
     252 [ #  # ][ #  # ]:          0 :         rxDevice->createCompatibleLinePolyPolygon(aPoints));
     253         [ #  # ]:          0 :     Reference<rendering::XPolyPolygon2D> xRectangle (xPolygon, UNO_QUERY);
     254         [ #  # ]:          0 :     if (xRectangle.is())
     255         [ #  # ]:          0 :         for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     256 [ #  # ][ #  # ]:          0 :             xRectangle->setClosed(nIndex, sal_True);
     257                 :            : 
     258         [ #  # ]:          0 :     return xRectangle;
     259                 :            : }
     260                 :            : 
     261                 :            : } }
     262                 :            : 
     263                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10