merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / view / drawutil.cxx
blobddb2f06b6bfe0c6cf004cbdec8eeeb6d0f9e5fb4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: drawutil.cxx,v $
10 * $Revision: 1.8 $
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 ---------------------------------------------------------------
38 #include <vcl/outdev.hxx>
40 #include "drawutil.hxx"
41 #include "document.hxx"
42 #include "global.hxx"
43 #include "viewdata.hxx"
45 // STATIC DATA -----------------------------------------------------------
47 // -----------------------------------------------------------------------
50 inline Fraction MakeFraction( long nA, long nB )
52 return ( nA && nB ) ? Fraction(nA,nB) : Fraction(1,1);
55 void ScDrawUtil::CalcScale( ScDocument* pDoc, SCTAB nTab,
56 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
57 OutputDevice* pDev,
58 const Fraction& rZoomX, const Fraction& rZoomY,
59 double nPPTX, double nPPTY,
60 Fraction& rScaleX, Fraction& rScaleY )
62 long nPixelX = 0;
63 long nTwipsX = 0;
64 long nPixelY = 0;
65 long nTwipsY = 0;
66 for (SCCOL i=nStartCol; i<nEndCol; i++)
68 USHORT nWidth = pDoc->GetColWidth(i,nTab);
69 nTwipsX += (long) nWidth;
70 nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
73 for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
75 SCROW nLastRow = nRow;
76 if (pDoc->RowHidden(nRow, nTab, NULL, &nLastRow))
78 nRow = nLastRow;
79 continue;
82 USHORT nHeight = pDoc->GetRowHeight(nRow, nTab);
83 nTwipsY += static_cast<long>(nHeight);
84 nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
87 MapMode aHMMMode( MAP_100TH_MM, Point(), rZoomX, rZoomY );
88 Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
90 // Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
91 // because ReduceInaccurate is called later anyway.
93 if ( aPixelLog.X() && nTwipsX )
94 rScaleX = Fraction( ((double)aPixelLog.X()) *
95 ((double)rZoomX.GetNumerator()) /
96 ((double)nTwipsX) /
97 ((double)HMM_PER_TWIPS) /
98 ((double)rZoomX.GetDenominator()) );
99 else
100 rScaleX = Fraction( 1, 1 );
102 if ( aPixelLog.Y() && nTwipsY )
103 rScaleY = Fraction( ((double)aPixelLog.Y()) *
104 ((double)rZoomY.GetNumerator()) /
105 ((double)nTwipsY) /
106 ((double)HMM_PER_TWIPS) /
107 ((double)rZoomY.GetDenominator()) );
108 else
109 rScaleY = Fraction( 1, 1 );
111 // 17 bits of accuracy are needed to always hit the right part of
112 // cells in the last rows
113 rScaleX.ReduceInaccurate( 17 );
114 rScaleY.ReduceInaccurate( 17 );