LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/view - gridmerg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 60 0.0 %
Date: 2012-12-27 Functions: 0 6 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 <vcl/outdev.hxx>
      21             : 
      22             : #include "gridmerg.hxx"
      23             : 
      24             : //------------------------------------------------------------------
      25             : 
      26           0 : ScGridMerger::ScGridMerger( OutputDevice* pOutDev, long nOnePixelX, long nOnePixelY ) :
      27             :     pDev( pOutDev ),
      28             :     nOneX( nOnePixelX ),
      29             :     nOneY( nOnePixelY ),
      30             :     nCount( 0 ),
      31           0 :     bVertical( false )
      32             : {
      33             :     //  optimize (DrawGrid) only for pixel MapMode,
      34             :     //  to avoid rounding errors
      35             : 
      36           0 :     bOptimize = ( pDev->GetMapMode().GetMapUnit() == MAP_PIXEL );
      37           0 : }
      38             : 
      39           0 : ScGridMerger::~ScGridMerger()
      40             : {
      41           0 :     Flush();
      42           0 : }
      43             : 
      44           0 : void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
      45             : {
      46           0 :     if ( nCount )
      47             :     {
      48             :         //  not first line - test fix position
      49             :         //  more than one previous line - test distance
      50             : 
      51           0 :         if ( nStart != nFixStart || nEnd != nFixEnd )
      52             :         {
      53           0 :             if ( nCount == 1 && nPos == nVarStart &&
      54             :                     ( nStart == nFixEnd ||
      55             :                         nStart == nFixEnd + ( bVertical ? nOneY : nOneX ) ) )
      56             :             {
      57             :                 //  additional optimization: extend connected lines
      58             :                 //  keep nCount at 1
      59           0 :                 nFixEnd = nEnd;
      60             :             }
      61             :             else
      62           0 :                 Flush();
      63             :         }
      64           0 :         else if ( nCount == 1 )
      65             :         {
      66           0 :             nVarDiff = nPos - nVarStart;
      67           0 :             ++nCount;
      68             :         }
      69           0 :         else if ( nPos != nVarStart + nCount * nVarDiff )       //! keep VarEnd?
      70           0 :             Flush();
      71             :         else
      72           0 :             ++nCount;
      73             :     }
      74             : 
      75           0 :     if ( !nCount )
      76             :     {
      77             :         //  first line (or flushed above) - just store
      78             : 
      79           0 :         nFixStart = nStart;
      80           0 :         nFixEnd   = nEnd;
      81           0 :         nVarStart = nPos;
      82           0 :         nVarDiff  = 0;
      83           0 :         nCount    = 1;
      84             :     }
      85           0 : }
      86             : 
      87           0 : void ScGridMerger::AddHorLine( long nX1, long nX2, long nY )
      88             : {
      89           0 :     if ( bOptimize )
      90             :     {
      91           0 :         if ( bVertical )
      92             :         {
      93           0 :             Flush();
      94           0 :             bVertical = false;
      95             :         }
      96           0 :         AddLine( nX1, nX2, nY );
      97             :     }
      98             :     else
      99           0 :         pDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
     100           0 : }
     101             : 
     102           0 : void ScGridMerger::AddVerLine( long nX, long nY1, long nY2 )
     103             : {
     104           0 :     if ( bOptimize )
     105             :     {
     106           0 :         if ( !bVertical )
     107             :         {
     108           0 :             Flush();
     109           0 :             bVertical = sal_True;
     110             :         }
     111           0 :         AddLine( nY1, nY2, nX );
     112             :     }
     113             :     else
     114           0 :         pDev->DrawLine( Point( nX, nY1 ), Point( nX, nY2 ) );
     115           0 : }
     116             : 
     117           0 : void ScGridMerger::Flush()
     118             : {
     119           0 :     if (nCount)
     120             :     {
     121           0 :         if (bVertical)
     122             :         {
     123           0 :             if ( nCount == 1 )
     124           0 :                 pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
     125             :             else
     126             :             {
     127           0 :                 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
     128           0 :                 if ( nVarDiff < 0 )
     129             :                 {
     130             :                     //  nVarDiff is negative in RTL layout mode
     131             :                     //  Change the positions so DrawGrid is called with a positive distance
     132             :                     //  (nVarStart / nVarDiff can be modified, aren't used after Flush)
     133             : 
     134           0 :                     nVarDiff = -nVarDiff;
     135           0 :                     long nTemp = nVarStart;
     136           0 :                     nVarStart = nVarEnd;
     137           0 :                     nVarEnd = nTemp;
     138             :                 }
     139             :                 pDev->DrawGrid( Rectangle( nVarStart, nFixStart, nVarEnd, nFixEnd ),
     140             :                                 Size( nVarDiff, nFixEnd - nFixStart ),
     141           0 :                                 GRID_VERTLINES );
     142             :             }
     143             :         }
     144             :         else
     145             :         {
     146           0 :             if ( nCount == 1 )
     147           0 :                 pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
     148             :             else
     149             :             {
     150           0 :                 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
     151             :                 pDev->DrawGrid( Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
     152             :                                 Size( nFixEnd - nFixStart, nVarDiff ),
     153           0 :                                 GRID_HORZLINES );
     154             :             }
     155             :         }
     156           0 :         nCount = 0;
     157             :     }
     158           0 : }
     159             : 
     160             : 
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10