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

Generated by: LCOV version 1.11