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 "drawutil.hxx"
32 : : #include "document.hxx"
33 : : #include "global.hxx"
34 : : #include "viewdata.hxx"
35 : :
36 : : // STATIC DATA -----------------------------------------------------------
37 : :
38 : : // -----------------------------------------------------------------------
39 : :
40 : :
41 : : inline Fraction MakeFraction( long nA, long nB )
42 : : {
43 : : return ( nA && nB ) ? Fraction(nA,nB) : Fraction(1,1);
44 : : }
45 : :
46 : 1083 : void ScDrawUtil::CalcScale( ScDocument* pDoc, SCTAB nTab,
47 : : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
48 : : OutputDevice* pDev,
49 : : const Fraction& rZoomX, const Fraction& rZoomY,
50 : : double nPPTX, double nPPTY,
51 : : Fraction& rScaleX, Fraction& rScaleY )
52 : : {
53 : 1083 : long nPixelX = 0;
54 : 1083 : long nTwipsX = 0;
55 : 1083 : long nPixelY = 0;
56 : 1083 : long nTwipsY = 0;
57 [ + + ]: 22743 : for (SCCOL i=nStartCol; i<nEndCol; i++)
58 : : {
59 [ + - ]: 21660 : sal_uInt16 nWidth = pDoc->GetColWidth(i,nTab);
60 : 21660 : nTwipsX += (long) nWidth;
61 : 21660 : nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
62 : : }
63 : :
64 [ + + ]: 1006395 : for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
65 : : {
66 : 1005312 : SCROW nLastRow = nRow;
67 [ + - ][ + + ]: 1005312 : if (pDoc->RowHidden(nRow, nTab, NULL, &nLastRow))
68 : : {
69 : 40 : nRow = nLastRow;
70 : 40 : continue;
71 : : }
72 : :
73 [ + - ]: 1005272 : sal_uInt16 nHeight = pDoc->GetRowHeight(nRow, nTab);
74 : 1005272 : nTwipsY += static_cast<long>(nHeight);
75 : 1005272 : nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
76 : : }
77 : :
78 [ + - ]: 1083 : MapMode aHMMMode( MAP_100TH_MM, Point(), rZoomX, rZoomY );
79 [ + - ]: 1083 : Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
80 : :
81 : : // Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
82 : : // because ReduceInaccurate is called later anyway.
83 : :
84 [ + - ][ + - ]: 1083 : if ( aPixelLog.X() && nTwipsX )
[ + - ]
85 : 1083 : rScaleX = Fraction( ((double)aPixelLog.X()) *
86 : 1083 : ((double)rZoomX.GetNumerator()) /
87 : : ((double)nTwipsX) /
88 : : ((double)HMM_PER_TWIPS) /
89 [ + - ][ + - ]: 1083 : ((double)rZoomX.GetDenominator()) );
90 : : else
91 [ # # ][ # # ]: 0 : rScaleX = Fraction( 1, 1 );
92 : :
93 [ + - ][ + - ]: 1083 : if ( aPixelLog.Y() && nTwipsY )
[ + - ]
94 : 1083 : rScaleY = Fraction( ((double)aPixelLog.Y()) *
95 : 1083 : ((double)rZoomY.GetNumerator()) /
96 : : ((double)nTwipsY) /
97 : : ((double)HMM_PER_TWIPS) /
98 [ + - ][ + - ]: 1083 : ((double)rZoomY.GetDenominator()) );
99 : : else
100 [ # # ][ # # ]: 0 : rScaleY = Fraction( 1, 1 );
101 : :
102 : : // 25 bits of accuracy are needed to always hit the right part of
103 : : // cells in the last rows (was 17 before 1M rows).
104 [ + - ]: 1083 : rScaleX.ReduceInaccurate( 25 );
105 [ + - ][ + - ]: 1083 : rScaleY.ReduceInaccurate( 25 );
106 : 1083 : }
107 : :
108 : :
109 : :
110 : :
111 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|