LibreOffice Module sc (master) 1
invmerge.cxx
Go to the documentation of this file.
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 <osl/diagnose.h>
21
22#include <invmerge.hxx>
23
24ScInvertMerger::ScInvertMerger( ::std::vector< tools::Rectangle >* pRectangles ) :
25 pRects( pRectangles )
26{
27 // collect rectangles instead of inverting
28}
29
31{
32 Flush();
33}
34
36{
37 FlushLine();
38 FlushTotal();
39
40 OSL_ENSURE( aLineRect.IsEmpty() && aTotalRect.IsEmpty(), "Flush: not empty" );
41
42 if ( !pRects )
43 return;
44
45 // also join vertically if there are non-adjacent columns involved
46
47 size_t nComparePos = 0;
48 while ( nComparePos < pRects->size() )
49 {
50 tools::Rectangle aCompRect = (*pRects)[nComparePos];
51 sal_Int32 nBottom = aCompRect.Bottom();
52 size_t nOtherPos = nComparePos + 1;
53
54 while ( nOtherPos < pRects->size() )
55 {
56 tools::Rectangle aOtherRect = (*pRects)[nOtherPos];
57 if ( aOtherRect.Top() > nBottom + 1 )
58 {
59 // rectangles are sorted, so we can stop searching
60 break;
61 }
62 if ( aOtherRect.Top() == nBottom + 1 &&
63 aOtherRect.Left() == aCompRect.Left() &&
64 aOtherRect.Right() == aCompRect.Right() )
65 {
66 // extend first rectangle
67 nBottom = aOtherRect.Bottom();
68 aCompRect.SetBottom( nBottom );
69 (*pRects)[nComparePos].SetBottom( nBottom );
70
71 // remove second rectangle
72 pRects->erase( pRects->begin() + nOtherPos );
73
74 // continue at unmodified nOtherPos
75 }
76 else
77 ++nOtherPos;
78 }
79
80 ++nComparePos;
81 }
82}
83
85{
86 if( aTotalRect.IsEmpty() )
87 return; // nothing to do
88
89 if ( pRects )
90 pRects->push_back( aTotalRect );
91
93}
94
96{
97 if( aLineRect.IsEmpty() )
98 return; // nothing to do
99
100 if ( aTotalRect.IsEmpty() )
101 {
102 aTotalRect = aLineRect; // start new total rect
103 }
104 else
105 {
106 if ( aLineRect.Left() == aTotalRect.Left() &&
108 aLineRect.Top() == aTotalRect.Bottom() + 1 )
109 {
110 // extend total rect
112 }
113 else
114 {
115 FlushTotal(); // draw old total rect
116 aTotalRect = aLineRect; // and start new one
117 }
118 }
119
121}
122
124{
125 tools::Rectangle aJustified = rRect;
126 if ( rRect.Left() > rRect.Right() ) // switch for RTL layout
127 {
128 aJustified.SetLeft( rRect.Right() );
129 aJustified.SetRight( rRect.Left() );
130 }
131
132 if ( aLineRect.IsEmpty() )
133 {
134 aLineRect = aJustified; // start new line rect
135 }
136 else
137 {
138 bool bDone = false;
139 if ( aJustified.Top() == aLineRect.Top() &&
140 aJustified.Bottom() == aLineRect.Bottom() )
141 {
142 // try to extend line rect
143 if ( aJustified.Left() == aLineRect.Right() + 1 )
144 {
145 aLineRect.SetRight( aJustified.Right() );
146 bDone = true;
147 }
148 else if ( aJustified.Right() + 1 == aLineRect.Left() ) // for RTL layout
149 {
150 aLineRect.SetLeft( aJustified.Left() );
151 bDone = true;
152 }
153 }
154 if (!bDone)
155 {
156 FlushLine(); // use old line rect for total rect
157 aLineRect = aJustified; // and start new one
158 }
159 }
160}
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void FlushLine()
Definition: invmerge.cxx:95
::std::vector< tools::Rectangle > * pRects
Definition: invmerge.hxx:29
tools::Rectangle aTotalRect
Definition: invmerge.hxx:30
void FlushTotal()
Definition: invmerge.cxx:84
void Flush()
Definition: invmerge.cxx:35
void AddRect(const tools::Rectangle &rRect)
Definition: invmerge.cxx:123
ScInvertMerger(::std::vector< tools::Rectangle > *pRectangles)
Definition: invmerge.cxx:24
tools::Rectangle aLineRect
Definition: invmerge.hxx:31
constexpr void SetLeft(tools::Long v)
constexpr tools::Long Top() const
constexpr void SetRight(tools::Long v)
constexpr tools::Long Right() const
constexpr void SetBottom(tools::Long v)
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
constexpr bool IsEmpty() const
size