LCOV - code coverage report
Current view: top level - sc/source/ui/view - invmerge.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 67 94.0 %
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/window.hxx>
      21             : 
      22             : #include "invmerge.hxx"
      23             : 
      24         394 : ScInvertMerger::ScInvertMerger( ::std::vector< Rectangle >* pRectangles ) :
      25         394 :     pRects( pRectangles )
      26             : {
      27             :     //  collect rectangles instead of inverting
      28         394 : }
      29             : 
      30         394 : ScInvertMerger::~ScInvertMerger()
      31             : {
      32         394 :     Flush();
      33         394 : }
      34             : 
      35         394 : void ScInvertMerger::Flush()
      36             : {
      37         394 :     FlushLine();
      38         394 :     FlushTotal();
      39             : 
      40             :     OSL_ENSURE( aLineRect.IsEmpty() && aTotalRect.IsEmpty(), "Flush: not empty" );
      41             : 
      42         394 :     if ( pRects )
      43             :     {
      44             : 
      45             :         // also join vertically if there are non-adjacent columns involved
      46             : 
      47         394 :         size_t nComparePos = 0;
      48        1232 :         while ( nComparePos < pRects->size() )
      49             :         {
      50         444 :             Rectangle aCompRect = (*pRects)[nComparePos];
      51         444 :             sal_Int32 nBottom = aCompRect.Bottom();
      52         444 :             size_t nOtherPos = nComparePos + 1;
      53             : 
      54        1076 :             while ( nOtherPos < pRects->size() )
      55             :             {
      56         210 :                 Rectangle aOtherRect = (*pRects)[nOtherPos];
      57         210 :                 if ( aOtherRect.Top() > nBottom + 1 )
      58             :                 {
      59             :                     // rectangles are sorted, so we can stop searching
      60          22 :                     break;
      61             :                 }
      62         516 :                 if ( aOtherRect.Top() == nBottom + 1 &&
      63         304 :                      aOtherRect.Left() == aCompRect.Left() &&
      64         116 :                      aOtherRect.Right() == aCompRect.Right() )
      65             :                 {
      66             :                     // extend first rectangle
      67          92 :                     nBottom = aOtherRect.Bottom();
      68          92 :                     aCompRect.Bottom() = nBottom;
      69          92 :                     (*pRects)[nComparePos].Bottom() = nBottom;
      70             : 
      71             :                     // remove second rectangle
      72          92 :                     pRects->erase( pRects->begin() + nOtherPos );
      73             : 
      74             :                     // continue at unmodified nOtherPos
      75             :                 }
      76             :                 else
      77          96 :                     ++nOtherPos;
      78             :             }
      79             : 
      80         444 :             ++nComparePos;
      81             :         }
      82             :     }
      83         394 : }
      84             : 
      85         536 : void ScInvertMerger::FlushTotal()
      86             : {
      87         536 :     if( aTotalRect.IsEmpty() )
      88         536 :         return;                         // nothing to do
      89             : 
      90         536 :     if ( pRects )
      91         536 :         pRects->push_back( aTotalRect );
      92             : 
      93         536 :     aTotalRect.SetEmpty();
      94             : }
      95             : 
      96        1106 : void ScInvertMerger::FlushLine()
      97             : {
      98        1106 :     if( aLineRect.IsEmpty() )
      99        1106 :         return;                         // nothing to do
     100             : 
     101        1106 :     if ( aTotalRect.IsEmpty() )
     102             :     {
     103         394 :         aTotalRect = aLineRect;         // start new total rect
     104             :     }
     105             :     else
     106             :     {
     107        2018 :         if ( aLineRect.Left()  == aTotalRect.Left()  &&
     108        1282 :              aLineRect.Right() == aTotalRect.Right() &&
     109         570 :              aLineRect.Top()   == aTotalRect.Bottom() + 1 )
     110             :         {
     111             :             // extend total rect
     112         570 :             aTotalRect.Bottom() = aLineRect.Bottom();
     113             :         }
     114             :         else
     115             :         {
     116         142 :             FlushTotal();                   // draw old total rect
     117         142 :             aTotalRect = aLineRect;         // and start new one
     118             :         }
     119             :     }
     120             : 
     121        1106 :     aLineRect.SetEmpty();
     122             : }
     123             : 
     124        3092 : void ScInvertMerger::AddRect( const Rectangle& rRect )
     125             : {
     126        3092 :     Rectangle aJustified = rRect;
     127        3092 :     if ( rRect.Left() > rRect.Right() )     // switch for RTL layout
     128             :     {
     129           0 :         aJustified.Left() = rRect.Right();
     130           0 :         aJustified.Right() = rRect.Left();
     131             :     }
     132             : 
     133        3092 :     if ( aLineRect.IsEmpty() )
     134             :     {
     135         394 :         aLineRect = aJustified;             // start new line rect
     136             :     }
     137             :     else
     138             :     {
     139        2698 :         bool bDone = false;
     140        4732 :         if ( aJustified.Top()    == aLineRect.Top()    &&
     141        2034 :              aJustified.Bottom() == aLineRect.Bottom() )
     142             :         {
     143             :             // try to extend line rect
     144        2034 :             if ( aJustified.Left() == aLineRect.Right() + 1 )
     145             :             {
     146        1986 :                 aLineRect.Right() = aJustified.Right();
     147        1986 :                 bDone = true;
     148             :             }
     149          48 :             else if ( aJustified.Right() + 1 == aLineRect.Left() )  // for RTL layout
     150             :             {
     151           0 :                 aLineRect.Left() = aJustified.Left();
     152           0 :                 bDone = true;
     153             :             }
     154             :         }
     155        2698 :         if (!bDone)
     156             :         {
     157         712 :             FlushLine();                // use old line rect for total rect
     158         712 :             aLineRect = aJustified;     // and start new one
     159             :         }
     160             :     }
     161        3320 : }
     162             : 
     163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10