fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / invmerge.cxx
blob8ac68bffeec51ff18b556514b8758cd38660553e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/window.hxx>
22 #include "invmerge.hxx"
24 ScInvertMerger::ScInvertMerger( ::std::vector< Rectangle >* pRectangles ) :
25 pRects( pRectangles )
27 // collect rectangles instead of inverting
30 ScInvertMerger::~ScInvertMerger()
32 Flush();
35 void ScInvertMerger::Flush()
37 FlushLine();
38 FlushTotal();
40 OSL_ENSURE( aLineRect.IsEmpty() && aTotalRect.IsEmpty(), "Flush: not empty" );
42 if ( pRects )
45 // also join vertically if there are non-adjacent columns involved
47 size_t nComparePos = 0;
48 while ( nComparePos < pRects->size() )
50 Rectangle aCompRect = (*pRects)[nComparePos];
51 sal_Int32 nBottom = aCompRect.Bottom();
52 size_t nOtherPos = nComparePos + 1;
54 while ( nOtherPos < pRects->size() )
56 Rectangle aOtherRect = (*pRects)[nOtherPos];
57 if ( aOtherRect.Top() > nBottom + 1 )
59 // rectangles are sorted, so we can stop searching
60 break;
62 if ( aOtherRect.Top() == nBottom + 1 &&
63 aOtherRect.Left() == aCompRect.Left() &&
64 aOtherRect.Right() == aCompRect.Right() )
66 // extend first rectangle
67 nBottom = aOtherRect.Bottom();
68 aCompRect.Bottom() = nBottom;
69 (*pRects)[nComparePos].Bottom() = nBottom;
71 // remove second rectangle
72 pRects->erase( pRects->begin() + nOtherPos );
74 // continue at unmodified nOtherPos
76 else
77 ++nOtherPos;
80 ++nComparePos;
85 void ScInvertMerger::FlushTotal()
87 if( aTotalRect.IsEmpty() )
88 return; // nothing to do
90 if ( pRects )
91 pRects->push_back( aTotalRect );
93 aTotalRect.SetEmpty();
96 void ScInvertMerger::FlushLine()
98 if( aLineRect.IsEmpty() )
99 return; // nothing to do
101 if ( aTotalRect.IsEmpty() )
103 aTotalRect = aLineRect; // start new total rect
105 else
107 if ( aLineRect.Left() == aTotalRect.Left() &&
108 aLineRect.Right() == aTotalRect.Right() &&
109 aLineRect.Top() == aTotalRect.Bottom() + 1 )
111 // extend total rect
112 aTotalRect.Bottom() = aLineRect.Bottom();
114 else
116 FlushTotal(); // draw old total rect
117 aTotalRect = aLineRect; // and start new one
121 aLineRect.SetEmpty();
124 void ScInvertMerger::AddRect( const Rectangle& rRect )
126 Rectangle aJustified = rRect;
127 if ( rRect.Left() > rRect.Right() ) // switch for RTL layout
129 aJustified.Left() = rRect.Right();
130 aJustified.Right() = rRect.Left();
133 if ( aLineRect.IsEmpty() )
135 aLineRect = aJustified; // start new line rect
137 else
139 bool bDone = false;
140 if ( aJustified.Top() == aLineRect.Top() &&
141 aJustified.Bottom() == aLineRect.Bottom() )
143 // try to extend line rect
144 if ( aJustified.Left() == aLineRect.Right() + 1 )
146 aLineRect.Right() = aJustified.Right();
147 bDone = true;
149 else if ( aJustified.Right() + 1 == aLineRect.Left() ) // for RTL layout
151 aLineRect.Left() = aJustified.Left();
152 bDone = true;
155 if (!bDone)
157 FlushLine(); // use old line rect for total rect
158 aLineRect = aJustified; // and start new one
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */