1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridmerg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include <vcl/outdev.hxx>
38 #include "gridmerg.hxx"
40 //------------------------------------------------------------------
42 ScGridMerger::ScGridMerger( OutputDevice
* pOutDev
, long nOnePixelX
, long nOnePixelY
) :
49 // optimize (DrawGrid) only for pixel MapMode,
50 // to avoid rounding errors
52 bOptimize
= ( pDev
->GetMapMode().GetMapUnit() == MAP_PIXEL
);
55 ScGridMerger::~ScGridMerger()
60 void ScGridMerger::AddLine( long nStart
, long nEnd
, long nPos
)
64 // not first line - test fix position
65 // more than one previous line - test distance
67 if ( nStart
!= nFixStart
|| nEnd
!= nFixEnd
)
69 if ( nCount
== 1 && nPos
== nVarStart
&&
70 ( nStart
== nFixEnd
||
71 nStart
== nFixEnd
+ ( bVertical
? nOneY
: nOneX
) ) )
73 // additional optimization: extend connected lines
80 else if ( nCount
== 1 )
82 nVarDiff
= nPos
- nVarStart
;
85 else if ( nPos
!= nVarStart
+ nCount
* nVarDiff
) //! keep VarEnd?
93 // first line (or flushed above) - just store
103 void ScGridMerger::AddHorLine( long nX1
, long nX2
, long nY
)
112 AddLine( nX1
, nX2
, nY
);
115 pDev
->DrawLine( Point( nX1
, nY
), Point( nX2
, nY
) );
118 void ScGridMerger::AddVerLine( long nX
, long nY1
, long nY2
)
127 AddLine( nY1
, nY2
, nX
);
130 pDev
->DrawLine( Point( nX
, nY1
), Point( nX
, nY2
) );
133 void ScGridMerger::Flush()
140 pDev
->DrawLine( Point( nVarStart
, nFixStart
), Point( nVarStart
, nFixEnd
) );
143 long nVarEnd
= nVarStart
+ ( nCount
- 1 ) * nVarDiff
;
146 // nVarDiff is negative in RTL layout mode
147 // Change the positions so DrawGrid is called with a positive distance
148 // (nVarStart / nVarDiff can be modified, aren't used after Flush)
150 nVarDiff
= -nVarDiff
;
151 long nTemp
= nVarStart
;
155 pDev
->DrawGrid( Rectangle( nVarStart
, nFixStart
, nVarEnd
, nFixEnd
),
156 Size( nVarDiff
, nFixEnd
- nFixStart
),
163 pDev
->DrawLine( Point( nFixStart
, nVarStart
), Point( nFixEnd
, nVarStart
) );
166 long nVarEnd
= nVarStart
+ ( nCount
- 1 ) * nVarDiff
;
167 pDev
->DrawGrid( Rectangle( nFixStart
, nVarStart
, nFixEnd
, nVarEnd
),
168 Size( nFixEnd
- nFixStart
, nVarDiff
),