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

Generated by: LCOV version 1.10