LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - gridmerg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 60 62 96.8 %
Date: 2013-07-09 Functions: 8 8 100.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        2024 : ScGridMerger::ScGridMerger( OutputDevice* pOutDev, long nOnePixelX, long nOnePixelY ) :
      27             :     pDev( pOutDev ),
      28             :     nOneX( nOnePixelX ),
      29             :     nOneY( nOnePixelY ),
      30             :     nCount( 0 ),
      31        2024 :     bVertical( false )
      32             : {
      33             :     //  optimize (DrawGrid) only for pixel MapMode,
      34             :     //  to avoid rounding errors
      35             : 
      36        2024 :     bOptimize = ( pDev->GetMapMode().GetMapUnit() == MAP_PIXEL );
      37        2024 : }
      38             : 
      39        2024 : ScGridMerger::~ScGridMerger()
      40             : {
      41        2024 :     Flush();
      42        2024 : }
      43             : 
      44       46858 : void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
      45             : {
      46       46858 :     if ( nCount )
      47             :     {
      48             :         //  not first line - test fix position
      49             :         //  more than one previous line - test distance
      50             : 
      51       42986 :         if ( nStart != nFixStart || nEnd != nFixEnd )
      52             :         {
      53        3612 :             if ( nCount == 1 && nPos == nVarStart &&
      54        2288 :                     ( nStart == nFixEnd ||
      55        1144 :                         nStart == nFixEnd + ( bVertical ? nOneY : nOneX ) ) )
      56             :             {
      57             :                 //  additional optimization: extend connected lines
      58             :                 //  keep nCount at 1
      59        1100 :                 nFixEnd = nEnd;
      60             :             }
      61             :             else
      62         134 :                 Flush();
      63             :         }
      64       41752 :         else if ( nCount == 1 )
      65             :         {
      66        4137 :             nVarDiff = nPos - nVarStart;
      67        4137 :             ++nCount;
      68             :         }
      69       37615 :         else if ( nPos != nVarStart + nCount * nVarDiff )       //! keep VarEnd?
      70         931 :             Flush();
      71             :         else
      72       36684 :             ++nCount;
      73             :     }
      74             : 
      75       46858 :     if ( !nCount )
      76             :     {
      77             :         //  first line (or flushed above) - just store
      78             : 
      79        4937 :         nFixStart = nStart;
      80        4937 :         nFixEnd   = nEnd;
      81        4937 :         nVarStart = nPos;
      82        4937 :         nVarDiff  = 0;
      83        4937 :         nCount    = 1;
      84             :     }
      85       46858 : }
      86             : 
      87       32318 : void ScGridMerger::AddHorLine( long nX1, long nX2, long nY )
      88             : {
      89       32318 :     if ( bOptimize )
      90             :     {
      91       32318 :         if ( bVertical )
      92             :         {
      93        1140 :             Flush();
      94        1140 :             bVertical = false;
      95             :         }
      96       32318 :         AddLine( nX1, nX2, nY );
      97             :     }
      98             :     else
      99           0 :         pDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
     100       32318 : }
     101             : 
     102       14540 : void ScGridMerger::AddVerLine( long nX, long nY1, long nY2 )
     103             : {
     104       14540 :     if ( bOptimize )
     105             :     {
     106       14540 :         if ( !bVertical )
     107             :         {
     108        1477 :             Flush();
     109        1477 :             bVertical = sal_True;
     110             :         }
     111       14540 :         AddLine( nY1, nY2, nX );
     112             :     }
     113             :     else
     114           0 :         pDev->DrawLine( Point( nX, nY1 ), Point( nX, nY2 ) );
     115       14540 : }
     116             : 
     117        8359 : void ScGridMerger::Flush()
     118             : {
     119        8359 :     if (nCount)
     120             :     {
     121        4937 :         if (bVertical)
     122             :         {
     123        2151 :             if ( nCount == 1 )
     124         252 :                 pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
     125             :             else
     126             :             {
     127        1899 :                 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
     128        1899 :                 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           2 :                     nVarDiff = -nVarDiff;
     135           2 :                     long nTemp = nVarStart;
     136           2 :                     nVarStart = nVarEnd;
     137           2 :                     nVarEnd = nTemp;
     138             :                 }
     139             :                 pDev->DrawGrid( Rectangle( nVarStart, nFixStart, nVarEnd, nFixEnd ),
     140             :                                 Size( nVarDiff, nFixEnd - nFixStart ),
     141        1899 :                                 GRID_VERTLINES );
     142             :             }
     143             :         }
     144             :         else
     145             :         {
     146        2786 :             if ( nCount == 1 )
     147         548 :                 pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
     148             :             else
     149             :             {
     150        2238 :                 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
     151             :                 pDev->DrawGrid( Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
     152             :                                 Size( nFixEnd - nFixStart, nVarDiff ),
     153        2238 :                                 GRID_HORZLINES );
     154             :             }
     155             :         }
     156        4937 :         nCount = 0;
     157             :     }
     158        8452 : }
     159             : 
     160             : 
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10