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 ScGridMerger::ScGridMerger( OutputDevice
* pOutDev
, long nOnePixelX
, long nOnePixelY
)
35 // optimize (DrawGrid) only for pixel MapMode,
36 // to avoid rounding errors
38 bOptimize
= ( pDev
->GetMapMode().GetMapUnit() == MAP_PIXEL
);
41 ScGridMerger::~ScGridMerger()
46 void ScGridMerger::AddLine( long nStart
, long nEnd
, long nPos
)
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
66 else if ( nCount
== 1 )
68 nVarDiff
= nPos
- nVarStart
;
71 else if ( nPos
!= nVarStart
+ nCount
* nVarDiff
) //! keep VarEnd?
79 // first line (or flushed above) - just store
89 void ScGridMerger::AddHorLine( long nX1
, long nX2
, long nY
)
98 AddLine( nX1
, nX2
, nY
);
101 pDev
->DrawLine( Point( nX1
, nY
), Point( nX2
, nY
) );
104 void ScGridMerger::AddVerLine( long nX
, long nY1
, long nY2
)
113 AddLine( nY1
, nY2
, nX
);
116 pDev
->DrawLine( Point( nX
, nY1
), Point( nX
, nY2
) );
119 void ScGridMerger::Flush()
126 pDev
->DrawLine( Point( nVarStart
, nFixStart
), Point( nVarStart
, nFixEnd
) );
129 long nVarEnd
= nVarStart
+ ( nCount
- 1 ) * nVarDiff
;
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
;
141 pDev
->DrawGrid( Rectangle( nVarStart
, nFixStart
, nVarEnd
, nFixEnd
),
142 Size( nVarDiff
, nFixEnd
- nFixStart
),
143 DrawGridFlags::VertLines
);
149 pDev
->DrawLine( Point( nFixStart
, nVarStart
), Point( nFixEnd
, nVarStart
) );
152 long nVarEnd
= nVarStart
+ ( nCount
- 1 ) * nVarDiff
;
153 pDev
->DrawGrid( Rectangle( nFixStart
, nVarStart
, nFixEnd
, nVarEnd
),
154 Size( nFixEnd
- nFixStart
, nVarDiff
),
155 DrawGridFlags::HorzLines
);
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */