xref: /aoo41x/main/sc/source/ui/view/drawutil.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <vcl/outdev.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "drawutil.hxx"
34cdf0e10cSrcweir #include "document.hxx"
35cdf0e10cSrcweir #include "global.hxx"
36cdf0e10cSrcweir #include "viewdata.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // -----------------------------------------------------------------------
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
MakeFraction(long nA,long nB)43cdf0e10cSrcweir inline Fraction MakeFraction( long nA, long nB )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	return ( nA && nB ) ? Fraction(nA,nB) : Fraction(1,1);
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
CalcScale(ScDocument * pDoc,SCTAB nTab,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,OutputDevice * pDev,const Fraction & rZoomX,const Fraction & rZoomY,double nPPTX,double nPPTY,Fraction & rScaleX,Fraction & rScaleY)48cdf0e10cSrcweir void ScDrawUtil::CalcScale( ScDocument* pDoc, SCTAB nTab,
49cdf0e10cSrcweir 							SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
50cdf0e10cSrcweir 							OutputDevice* pDev,
51cdf0e10cSrcweir 							const Fraction& rZoomX, const Fraction& rZoomY,
52cdf0e10cSrcweir 							double nPPTX, double nPPTY,
53cdf0e10cSrcweir 							Fraction& rScaleX, Fraction& rScaleY )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	long nPixelX = 0;
56cdf0e10cSrcweir 	long nTwipsX = 0;
57cdf0e10cSrcweir 	long nPixelY = 0;
58cdf0e10cSrcweir 	long nTwipsY = 0;
59cdf0e10cSrcweir 	for (SCCOL i=nStartCol; i<nEndCol; i++)
60cdf0e10cSrcweir 	{
61cdf0e10cSrcweir 		sal_uInt16 nWidth = pDoc->GetColWidth(i,nTab);
62cdf0e10cSrcweir 		nTwipsX += (long) nWidth;
63cdf0e10cSrcweir 		nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
64cdf0e10cSrcweir 	}
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir         SCROW nLastRow = nRow;
69cdf0e10cSrcweir         if (pDoc->RowHidden(nRow, nTab, NULL, &nLastRow))
70cdf0e10cSrcweir         {
71cdf0e10cSrcweir             nRow = nLastRow;
72cdf0e10cSrcweir             continue;
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         sal_uInt16 nHeight = pDoc->GetRowHeight(nRow, nTab);
76cdf0e10cSrcweir         nTwipsY += static_cast<long>(nHeight);
77cdf0e10cSrcweir         nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
78cdf0e10cSrcweir 	}
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     // #i116848# To get a large-enough number for PixelToLogic, multiply the integer values
81cdf0e10cSrcweir     // instead of using a larger number of rows
82d70dcc85SMichael Stahl     if ( nTwipsY )
83cdf0e10cSrcweir     {
84d70dcc85SMichael Stahl         long nMultiply = 2000000 / nTwipsY;
85d70dcc85SMichael Stahl         if ( nMultiply > 1 )
86d70dcc85SMichael Stahl         {
87d70dcc85SMichael Stahl             nTwipsY *= nMultiply;
88d70dcc85SMichael Stahl             nPixelY *= nMultiply;
89d70dcc85SMichael Stahl         }
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	MapMode aHMMMode( MAP_100TH_MM, Point(), rZoomX, rZoomY );
93cdf0e10cSrcweir 	Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	//	Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
96cdf0e10cSrcweir 	//	because ReduceInaccurate is called later anyway.
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	if ( aPixelLog.X() && nTwipsX )
99cdf0e10cSrcweir 		rScaleX = Fraction( ((double)aPixelLog.X()) *
100cdf0e10cSrcweir 							((double)rZoomX.GetNumerator()) /
101cdf0e10cSrcweir 							((double)nTwipsX) /
102cdf0e10cSrcweir 							((double)HMM_PER_TWIPS) /
103cdf0e10cSrcweir 							((double)rZoomX.GetDenominator()) );
104cdf0e10cSrcweir 	else
105cdf0e10cSrcweir 		rScaleX = Fraction( 1, 1 );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	if ( aPixelLog.Y() && nTwipsY )
108cdf0e10cSrcweir 		rScaleY = Fraction( ((double)aPixelLog.Y()) *
109cdf0e10cSrcweir 							((double)rZoomY.GetNumerator()) /
110cdf0e10cSrcweir 							((double)nTwipsY) /
111cdf0e10cSrcweir 							((double)HMM_PER_TWIPS) /
112cdf0e10cSrcweir 							((double)rZoomY.GetDenominator()) );
113cdf0e10cSrcweir 	else
114cdf0e10cSrcweir 		rScaleY = Fraction( 1, 1 );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     //	25 bits of accuracy are needed to always hit the right part of
117cdf0e10cSrcweir     //	cells in the last rows (was 17 before 1M rows).
118cdf0e10cSrcweir 	rScaleX.ReduceInaccurate( 25 );
119cdf0e10cSrcweir 	rScaleY.ReduceInaccurate( 25 );
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 
125