Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <vcl/outdev.hxx>
21 :
22 : #include "drawutil.hxx"
23 : #include "document.hxx"
24 : #include "global.hxx"
25 : #include "viewdata.hxx"
26 :
27 : // STATIC DATA -----------------------------------------------------------
28 :
29 : // -----------------------------------------------------------------------
30 :
31 :
32 : inline Fraction MakeFraction( long nA, long nB )
33 : {
34 : return ( nA && nB ) ? Fraction(nA,nB) : Fraction(1,1);
35 : }
36 :
37 0 : void ScDrawUtil::CalcScale( ScDocument* pDoc, SCTAB nTab,
38 : SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
39 : OutputDevice* pDev,
40 : const Fraction& rZoomX, const Fraction& rZoomY,
41 : double nPPTX, double nPPTY,
42 : Fraction& rScaleX, Fraction& rScaleY )
43 : {
44 0 : long nPixelX = 0;
45 0 : long nTwipsX = 0;
46 0 : long nPixelY = 0;
47 0 : long nTwipsY = 0;
48 0 : for (SCCOL i=nStartCol; i<nEndCol; i++)
49 : {
50 0 : sal_uInt16 nWidth = pDoc->GetColWidth(i,nTab);
51 0 : nTwipsX += (long) nWidth;
52 0 : nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
53 : }
54 :
55 0 : for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
56 : {
57 0 : SCROW nLastRow = nRow;
58 0 : if (pDoc->RowHidden(nRow, nTab, NULL, &nLastRow))
59 : {
60 0 : nRow = nLastRow;
61 0 : continue;
62 : }
63 :
64 0 : sal_uInt16 nHeight = pDoc->GetRowHeight(nRow, nTab);
65 0 : nTwipsY += static_cast<long>(nHeight);
66 0 : nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
67 : }
68 :
69 0 : MapMode aHMMMode( MAP_100TH_MM, Point(), rZoomX, rZoomY );
70 0 : Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
71 :
72 : // Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
73 : // because ReduceInaccurate is called later anyway.
74 :
75 0 : if ( aPixelLog.X() && nTwipsX )
76 0 : rScaleX = Fraction( ((double)aPixelLog.X()) *
77 0 : ((double)rZoomX.GetNumerator()) /
78 : ((double)nTwipsX) /
79 : ((double)HMM_PER_TWIPS) /
80 0 : ((double)rZoomX.GetDenominator()) );
81 : else
82 0 : rScaleX = Fraction( 1, 1 );
83 :
84 0 : if ( aPixelLog.Y() && nTwipsY )
85 0 : rScaleY = Fraction( ((double)aPixelLog.Y()) *
86 0 : ((double)rZoomY.GetNumerator()) /
87 : ((double)nTwipsY) /
88 : ((double)HMM_PER_TWIPS) /
89 0 : ((double)rZoomY.GetDenominator()) );
90 : else
91 0 : rScaleY = Fraction( 1, 1 );
92 :
93 : // 25 bits of accuracy are needed to always hit the right part of
94 : // cells in the last rows (was 17 before 1M rows).
95 0 : rScaleX.ReduceInaccurate( 25 );
96 0 : rScaleY.ReduceInaccurate( 25 );
97 15 : }
98 :
99 :
100 :
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|