Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/outdev.hxx>
30 : :
31 : : #include "gridmerg.hxx"
32 : :
33 : : //------------------------------------------------------------------
34 : :
35 : 1907 : ScGridMerger::ScGridMerger( OutputDevice* pOutDev, long nOnePixelX, long nOnePixelY ) :
36 : : pDev( pOutDev ),
37 : : nOneX( nOnePixelX ),
38 : : nOneY( nOnePixelY ),
39 : : nCount( 0 ),
40 : 1907 : bVertical( false )
41 : : {
42 : : // optimize (DrawGrid) only for pixel MapMode,
43 : : // to avoid rounding errors
44 : :
45 : 1907 : bOptimize = ( pDev->GetMapMode().GetMapUnit() == MAP_PIXEL );
46 : 1907 : }
47 : :
48 : 1907 : ScGridMerger::~ScGridMerger()
49 : : {
50 : 1907 : Flush();
51 : 1907 : }
52 : :
53 : 39075 : void ScGridMerger::AddLine( long nStart, long nEnd, long nPos )
54 : : {
55 [ + + ]: 39075 : if ( nCount )
56 : : {
57 : : // not first line - test fix position
58 : : // more than one previous line - test distance
59 : :
60 [ + + ][ + + ]: 35354 : if ( nStart != nFixStart || nEnd != nFixEnd )
61 : : {
62 [ + - ][ + + ]: 642 : if ( nCount == 1 && nPos == nVarStart &&
[ + - ][ + + ]
[ + - ]
63 : : ( nStart == nFixEnd ||
64 : : nStart == nFixEnd + ( bVertical ? nOneY : nOneX ) ) )
65 : : {
66 : : // additional optimization: extend connected lines
67 : : // keep nCount at 1
68 : 308 : nFixEnd = nEnd;
69 : : }
70 : : else
71 : 13 : Flush();
72 : : }
73 [ + + ]: 35033 : else if ( nCount == 1 )
74 : : {
75 : 3374 : nVarDiff = nPos - nVarStart;
76 : 3374 : ++nCount;
77 : : }
78 [ + + ]: 31659 : else if ( nPos != nVarStart + nCount * nVarDiff ) //! keep VarEnd?
79 : 289 : Flush();
80 : : else
81 : 35354 : ++nCount;
82 : : }
83 : :
84 [ + + ]: 39075 : if ( !nCount )
85 : : {
86 : : // first line (or flushed above) - just store
87 : :
88 : 4023 : nFixStart = nStart;
89 : 4023 : nFixEnd = nEnd;
90 : 4023 : nVarStart = nPos;
91 : 4023 : nVarDiff = 0;
92 : 4023 : nCount = 1;
93 : : }
94 : 39075 : }
95 : :
96 : 24606 : void ScGridMerger::AddHorLine( long nX1, long nX2, long nY )
97 : : {
98 [ + - ]: 24606 : if ( bOptimize )
99 : : {
100 [ + + ]: 24606 : if ( bVertical )
101 : : {
102 : 1275 : Flush();
103 : 1275 : bVertical = false;
104 : : }
105 : 24606 : AddLine( nX1, nX2, nY );
106 : : }
107 : : else
108 [ # # ]: 0 : pDev->DrawLine( Point( nX1, nY ), Point( nX2, nY ) );
109 : 24606 : }
110 : :
111 : 14469 : void ScGridMerger::AddVerLine( long nX, long nY1, long nY2 )
112 : : {
113 [ + - ]: 14469 : if ( bOptimize )
114 : : {
115 [ + + ]: 14469 : if ( !bVertical )
116 : : {
117 : 1548 : Flush();
118 : 1548 : bVertical = sal_True;
119 : : }
120 : 14469 : AddLine( nY1, nY2, nX );
121 : : }
122 : : else
123 [ # # ]: 0 : pDev->DrawLine( Point( nX, nY1 ), Point( nX, nY2 ) );
124 : 14469 : }
125 : :
126 : 6923 : void ScGridMerger::Flush()
127 : : {
128 [ + + ]: 6923 : if (nCount)
129 : : {
130 [ + + ]: 4023 : if (bVertical)
131 : : {
132 [ + + ]: 1803 : if ( nCount == 1 )
133 [ + - ]: 232 : pDev->DrawLine( Point( nVarStart, nFixStart ), Point( nVarStart, nFixEnd ) );
134 : : else
135 : : {
136 : 1571 : long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
137 [ + + ]: 1571 : if ( nVarDiff < 0 )
138 : : {
139 : : // nVarDiff is negative in RTL layout mode
140 : : // Change the positions so DrawGrid is called with a positive distance
141 : : // (nVarStart / nVarDiff can be modified, aren't used after Flush)
142 : :
143 : 4 : nVarDiff = -nVarDiff;
144 : 4 : long nTemp = nVarStart;
145 : 4 : nVarStart = nVarEnd;
146 : 4 : nVarEnd = nTemp;
147 : : }
148 : : pDev->DrawGrid( Rectangle( nVarStart, nFixStart, nVarEnd, nFixEnd ),
149 : : Size( nVarDiff, nFixEnd - nFixStart ),
150 [ + - ][ + - ]: 1571 : GRID_VERTLINES );
151 : : }
152 : : }
153 : : else
154 : : {
155 [ + + ]: 2220 : if ( nCount == 1 )
156 [ + - ]: 417 : pDev->DrawLine( Point( nFixStart, nVarStart ), Point( nFixEnd, nVarStart ) );
157 : : else
158 : : {
159 : 1803 : long nVarEnd = nVarStart + ( nCount - 1 ) * nVarDiff;
160 : : pDev->DrawGrid( Rectangle( nFixStart, nVarStart, nFixEnd, nVarEnd ),
161 : : Size( nFixEnd - nFixStart, nVarDiff ),
162 [ + - ][ + - ]: 1803 : GRID_HORZLINES );
163 : : }
164 : : }
165 : 4023 : nCount = 0;
166 : : }
167 : 6923 : }
168 : :
169 : :
170 : :
171 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|