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

Generated by: LCOV version 1.10