1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 //------------------------------------------------------------------
26 ScGridMerger::ScGridMerger( OutputDevice
* pOutDev
, long nOnePixelX
, long nOnePixelY
) :
33 // optimize (DrawGrid) only for pixel MapMode,
34 // to avoid rounding errors
36 bOptimize
= ( pDev
->GetMapMode().GetMapUnit() == MAP_PIXEL
);
39 ScGridMerger::~ScGridMerger()
44 void ScGridMerger::AddLine( long nStart
, long nEnd
, long nPos
)
48 // not first line - test fix position
49 // more than one previous line - test distance
51 if ( nStart
!= nFixStart
|| nEnd
!= nFixEnd
)
53 if ( nCount
== 1 && nPos
== nVarStart
&&
54 ( nStart
== nFixEnd
||
55 nStart
== nFixEnd
+ ( bVertical
? nOneY
: nOneX
) ) )
57 // additional optimization: extend connected lines
64 else if ( nCount
== 1 )
66 nVarDiff
= nPos
- nVarStart
;
69 else if ( nPos
!= nVarStart
+ nCount
* nVarDiff
) //! keep VarEnd?
77 // first line (or flushed above) - just store
87 void ScGridMerger::AddHorLine( long nX1
, long nX2
, long nY
)
96 AddLine( nX1
, nX2
, nY
);
99 pDev
->DrawLine( Point( nX1
, nY
), Point( nX2
, nY
) );
102 void ScGridMerger::AddVerLine( long nX
, long nY1
, long nY2
)
109 bVertical
= sal_True
;
111 AddLine( nY1
, nY2
, nX
);
114 pDev
->DrawLine( Point( nX
, nY1
), Point( nX
, nY2
) );
117 void ScGridMerger::Flush()
124 pDev
->DrawLine( Point( nVarStart
, nFixStart
), Point( nVarStart
, nFixEnd
) );
127 long nVarEnd
= nVarStart
+ ( nCount
- 1 ) * nVarDiff
;
130 // nVarDiff is negative in RTL layout mode
131 // Change the positions so DrawGrid is called with a positive distance
132 // (nVarStart / nVarDiff can be modified, aren't used after Flush)
134 nVarDiff
= -nVarDiff
;
135 long nTemp
= nVarStart
;
139 pDev
->DrawGrid( Rectangle( nVarStart
, nFixStart
, nVarEnd
, nFixEnd
),
140 Size( nVarDiff
, nFixEnd
- nFixStart
),
147 pDev
->DrawLine( Point( nFixStart
, nVarStart
), Point( nFixEnd
, nVarStart
) );
150 long nVarEnd
= nVarStart
+ ( nCount
- 1 ) * nVarDiff
;
151 pDev
->DrawGrid( Rectangle( nFixStart
, nVarStart
, nFixEnd
, nVarEnd
),
152 Size( nFixEnd
- nFixStart
, nVarDiff
),
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */