fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / gridmerg.cxx
blobd2d434f898116c5b4264cab451fbeee1b41f1448
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/outdev.hxx>
22 #include "gridmerg.hxx"
24 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 , bVertical(false)
35 // optimize (DrawGrid) only for pixel MapMode,
36 // to avoid rounding errors
38 bOptimize = ( pDev->GetMapMode().GetMapUnit() == MAP_PIXEL );
41 ScGridMerger::~ScGridMerger()
43 Flush();
46 void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
48 if ( nCount )
50 // not first line - test fix position
51 // more than one previous line - test distance
53 if ( nStart != nFixStart || nEnd != nFixEnd )
55 if ( nCount == 1 && nPos == nVarStart &&
56 ( nStart == nFixEnd ||
57 nStart == nFixEnd + ( bVertical ? nOneY : nOneX ) ) )
59 // additional optimization: extend connected lines
60 // keep nCount at 1
61 nFixEnd = nEnd;
63 else
64 Flush();
66 else if ( nCount == 1 )
68 nVarDiff = nPos - nVarStart;
69 ++nCount;
71 else if ( nPos != nVarStart + nCount * nVarDiff ) //! keep VarEnd?
72 Flush();
73 else
74 ++nCount;
77 if ( !nCount )
79 // first line (or flushed above) - just store
81 nFixStart = nStart;
82 nFixEnd = nEnd;
83 nVarStart = nPos;
84 nVarDiff = 0;
85 nCount = 1;
89 void ScGridMerger::AddHorLine( long nX1, long nX2, long nY )
91 if ( bOptimize )
93 if ( bVertical )
95 Flush();
96 bVertical = false;
98 AddLine( nX1, nX2, nY );
100 else
101 pDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
104 void ScGridMerger::AddVerLine( long nX, long nY1, long nY2 )
106 if ( bOptimize )
108 if ( !bVertical )
110 Flush();
111 bVertical = true;
113 AddLine( nY1, nY2, nX );
115 else
116 pDev->DrawLine( Point( nX, nY1 ), Point( nX, nY2 ) );
119 void ScGridMerger::Flush()
121 if (nCount)
123 if (bVertical)
125 if ( nCount == 1 )
126 pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
127 else
129 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
130 if ( nVarDiff < 0 )
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)
136 nVarDiff = -nVarDiff;
137 long nTemp = nVarStart;
138 nVarStart = nVarEnd;
139 nVarEnd = nTemp;
141 pDev->DrawGrid( Rectangle( nVarStart, nFixStart, nVarEnd, nFixEnd ),
142 Size( nVarDiff, nFixEnd - nFixStart ),
143 DrawGridFlags::VertLines );
146 else
148 if ( nCount == 1 )
149 pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
150 else
152 long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
153 pDev->DrawGrid( Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
154 Size( nFixEnd - nFixStart, nVarDiff ),
155 DrawGridFlags::HorzLines );
158 nCount = 0;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */