LCOV - code coverage report
Current view: top level - slideshow/source/engine/transitions - clippingfunctor.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 66 0.0 %
Date: 2014-11-03 Functions: 0 2 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             : 
      21             : #include <canvas/debug.hxx>
      22             : #include <tools/diagnose_ex.h>
      23             : #include "clippingfunctor.hxx"
      24             : #include "transitiontools.hxx"
      25             : 
      26             : #include <basegfx/polygon/b2dpolypolygoncutter.hxx>
      27             : #include <basegfx/polygon/b2dpolygonclipper.hxx>
      28             : #include <basegfx/polygon/b2dpolygontools.hxx>
      29             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      30             : 
      31             : namespace slideshow
      32             : {
      33             :     namespace internal
      34             :     {
      35           0 :         ClippingFunctor::ClippingFunctor(const ParametricPolyPolygonSharedPtr&   rPolygon,
      36             :                                          const TransitionInfo&                   rTransitionInfo,
      37             :                                          bool                                    bDirectionForward,
      38             :                                          bool                                    bModeIn ) :
      39             :             mpParametricPoly( rPolygon ),
      40             :             maStaticTransformation(),
      41             :             mbForwardParameterSweep( true ),
      42             :             mbSubtractPolygon( false ),
      43             :             mbScaleIsotrophically( rTransitionInfo.mbScaleIsotrophically ),
      44           0 :             mbFlip(false)
      45             :         {
      46           0 :             ENSURE_OR_THROW( rPolygon,
      47             :                               "ClippingFunctor::ClippingFunctor(): Invalid parametric polygon" );
      48             : 
      49             :             // maBackgroundRect serves as the minuent when
      50             :             // subtracting a given clip polygon from the
      51             :             // background. To speed up the clipper algo, avoid
      52             :             // actual intersections of the generated
      53             :             // poly-polygon with the minuent - i.e. choose the
      54             :             // polygon to subtract from sufficiently large.
      55             : 
      56             :             // blow up unit rect to (-1,-1),(2,2)
      57             :             // AW: Not needed, just use range
      58             :             // ::basegfx::B2DHomMatrix aMatrix;
      59             :             // aMatrix.scale(3.0,3.0);
      60             :             // aMatrix.translate(-1.0,-1.0);
      61             :             // maBackgroundRect.transform( aMatrix );
      62             : 
      63             :             // extract modification info from maTransitionInfo
      64             : 
      65             : 
      66             :             // perform general transformations _before_ the reverse
      67             :             // mode changes. This allows the Transition table to be
      68             :             // filled more constitently (otherwise, when e.g. rotating
      69             :             // a clip 90 degrees, the REVERSEMETHOD_FLIP_X becomes
      70             :             // REVERSEMETHOD_FLIP_Y instead)
      71           0 :             if (rTransitionInfo.mnRotationAngle != 0.0 ||
      72           0 :                 rTransitionInfo.mnScaleX != 1.0 ||
      73           0 :                 rTransitionInfo.mnScaleY != 1.0)
      74             :             {
      75           0 :                 maStaticTransformation.translate( -0.5, -0.5 );
      76             :                 // apply further transformations:
      77           0 :                 if (rTransitionInfo.mnRotationAngle != 0.0)
      78             :                 {
      79             :                     maStaticTransformation.rotate(
      80           0 :                         basegfx::deg2rad(rTransitionInfo.mnRotationAngle) );
      81             :                 }
      82           0 :                 if (rTransitionInfo.mnScaleX != 1.0 ||
      83           0 :                     rTransitionInfo.mnScaleY != 1.0)
      84             :                 {
      85             :                     maStaticTransformation.scale(
      86             :                         rTransitionInfo.mnScaleX,
      87           0 :                         rTransitionInfo.mnScaleY );
      88             :                 }
      89           0 :                 maStaticTransformation.translate( 0.5, 0.5 );
      90             :             }
      91             : 
      92           0 :             if( !bDirectionForward )
      93             :             {
      94             :                 // Client has requested reversed
      95             :                 // direction. Apply TransitionInfo's choice
      96             :                 // for that
      97           0 :                 switch( rTransitionInfo.meReverseMethod )
      98             :                 {
      99             :                     default:
     100           0 :                         ENSURE_OR_THROW(
     101             :                             false,
     102             :                             "TransitionFactory::TransitionFactory(): Unexpected reverse method" );
     103             :                         break;
     104             : 
     105             :                     case TransitionInfo::REVERSEMETHOD_IGNORE:
     106           0 :                         break;
     107             : 
     108             :                     case TransitionInfo::REVERSEMETHOD_INVERT_SWEEP:
     109           0 :                         mbForwardParameterSweep = !mbForwardParameterSweep;
     110           0 :                         break;
     111             : 
     112             :                     case TransitionInfo::REVERSEMETHOD_SUBTRACT_POLYGON:
     113           0 :                         mbSubtractPolygon = !mbSubtractPolygon;
     114           0 :                         break;
     115             : 
     116             :                     case TransitionInfo::REVERSEMETHOD_SUBTRACT_AND_INVERT:
     117           0 :                         mbForwardParameterSweep = !mbForwardParameterSweep;
     118           0 :                         mbSubtractPolygon = !mbSubtractPolygon;
     119           0 :                         break;
     120             : 
     121             :                     case TransitionInfo::REVERSEMETHOD_ROTATE_180:
     122           0 :                         maStaticTransformation = basegfx::tools::createRotateAroundPoint(0.5, 0.5, M_PI)
     123           0 :                             * maStaticTransformation;
     124           0 :                         break;
     125             : 
     126             :                     case TransitionInfo::REVERSEMETHOD_FLIP_X:
     127           0 :                         maStaticTransformation = basegfx::tools::createScaleTranslateB2DHomMatrix(-1.0, 1.0, 1.0, 0.0)
     128           0 :                             * maStaticTransformation;
     129           0 :                         mbFlip = true;
     130           0 :                         break;
     131             : 
     132             :                     case TransitionInfo::REVERSEMETHOD_FLIP_Y:
     133           0 :                         maStaticTransformation = basegfx::tools::createScaleTranslateB2DHomMatrix(1.0, -1.0, 0.0, 1.0)
     134           0 :                             * maStaticTransformation;
     135           0 :                         mbFlip = true;
     136           0 :                         break;
     137             :                 }
     138             :             }
     139             : 
     140           0 :             if( !bModeIn )
     141             :             {
     142             :                 // client has requested 'out' mode. Apply
     143             :                 // TransitionInfo's method of choice
     144           0 :                 if( rTransitionInfo.mbOutInvertsSweep )
     145           0 :                     mbForwardParameterSweep = !mbForwardParameterSweep;
     146             :                 else
     147           0 :                     mbSubtractPolygon = !mbSubtractPolygon;
     148             :             }
     149           0 :         }
     150             : 
     151           0 :         ::basegfx::B2DPolyPolygon ClippingFunctor::operator()( double                       nValue,
     152             :                                                                const ::basegfx::B2DSize&    rTargetSize )
     153             :         {
     154             :             // modify clip polygon according to static
     155             :             // transformation plus current shape size
     156           0 :             ::basegfx::B2DHomMatrix aMatrix( maStaticTransformation );
     157             : 
     158             :             // retrieve current clip polygon
     159           0 :             ::basegfx::B2DPolyPolygon aClipPoly = (*mpParametricPoly)(
     160           0 :                 mbForwardParameterSweep ? nValue : 1.0 - nValue );
     161             : 
     162             :             // TODO(Q4): workaround here, better be fixed in cppcanvas
     163           0 :             if (aClipPoly.count() == 0)
     164           0 :                 aClipPoly.append( basegfx::B2DPolygon() );
     165             : 
     166           0 :             if (mbFlip)
     167           0 :                 aClipPoly.flip();
     168             : 
     169             :             // currently, clipper cannot cope with curves. Subdivide first
     170             :             // AW: Should be no longer necessary; clipping tools are now bezier-safe
     171             :             // if( aClipPoly.areControlPointsUsed() )
     172             :             //    aClipPoly = ::basegfx::tools::adaptiveSubdivideByAngle(aClipPoly);
     173             : 
     174           0 :             if( mbSubtractPolygon )
     175             :             {
     176             :                 // subtract given polygon from background
     177             :                 // rect. Do that before any transformations.
     178             : 
     179             :                 // calc maBackgroundRect \ aClipPoly
     180             :                 // =================================
     181             : 
     182             :                 // AW: Simplified
     183             :                 // use a range with fixed size (-1,-1),(2,2)
     184           0 :                 const basegfx::B2DRange aBackgroundRange(-1, -1, 2, 2);
     185           0 :                 const basegfx::B2DRange aClipPolyRange(aClipPoly.getB2DRange());
     186             : 
     187           0 :                 if(aBackgroundRange.isInside(aClipPolyRange))
     188             :                 {
     189             :                     // combine polygons; make the clip polygon the hole
     190           0 :                     aClipPoly = ::basegfx::tools::correctOrientations(aClipPoly);
     191           0 :                     aClipPoly.flip();
     192           0 :                     aClipPoly.insert(0, basegfx::tools::createPolygonFromRect(aBackgroundRange));
     193             :                 }
     194             :                 else
     195             :                 {
     196             :                     // when not completely inside aBackgroundRange clipping is needed
     197             :                     // subtract aClipPoly from aBackgroundRange
     198           0 :                     const basegfx::B2DPolyPolygon aBackgroundPolyPoly(basegfx::tools::createPolygonFromRect(aBackgroundRange));
     199           0 :                     aClipPoly = basegfx::tools::solvePolygonOperationDiff(aBackgroundPolyPoly, aClipPoly);
     200             :                 }
     201             :             }
     202             : 
     203             :             // scale polygon up to current shape size
     204           0 :             if( mbScaleIsotrophically )
     205             :             {
     206           0 :                 const double nScale( ::std::max( rTargetSize.getX(),
     207           0 :                                                  rTargetSize.getY() ) );
     208           0 :                 aMatrix.scale( nScale, nScale );
     209           0 :                 aMatrix.translate( -(nScale-rTargetSize.getX())/2.0,
     210           0 :                                    -(nScale-rTargetSize.getY())/2.0 );
     211             :             }
     212             :             else
     213             :             {
     214             :                 aMatrix.scale( rTargetSize.getX(),
     215           0 :                                rTargetSize.getY() );
     216             :             }
     217             : 
     218             :             // apply cumulative transformation to clip polygon
     219           0 :             aClipPoly.transform( aMatrix );
     220             : 
     221           0 :             return aClipPoly;
     222             :         }
     223             : 
     224             :     }
     225             : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10