LibreOffice Module sc (master)  1
drawutil.cxx
Go to the documentation of this file.
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 void ScDrawUtil::CalcScale( const ScDocument& rDoc, SCTAB nTab,
28  SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
29  const OutputDevice* pDev,
30  const Fraction& rZoomX, const Fraction& rZoomY,
31  double nPPTX, double nPPTY,
32  Fraction& rScaleX, Fraction& rScaleY )
33 {
34  long nPixelX = 0;
35  long nTwipsX = 0;
36  long nPixelY = 0;
37  long nTwipsY = 0;
38  for (SCCOL i=nStartCol; i<nEndCol; i++)
39  {
40  sal_uInt16 nWidth = rDoc.GetColWidth(i,nTab);
41  nTwipsX += static_cast<long>(nWidth);
42  nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
43  }
44 
45  for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
46  {
47  SCROW nLastRow = nRow;
48  if (rDoc.RowHidden(nRow, nTab, nullptr, &nLastRow))
49  {
50  nRow = nLastRow;
51  continue;
52  }
53 
54  sal_uInt16 nHeight = rDoc.GetRowHeight(nRow, nTab);
55  nTwipsY += static_cast<long>(nHeight);
56  nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
57  }
58 
59  MapMode aHMMMode( MapUnit::Map100thMM, Point(), rZoomX, rZoomY );
60  Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
61 
62  // Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
63  // because ReduceInaccurate is called later anyway.
64 
65  if ( aPixelLog.X() && nTwipsX )
66  rScaleX = Fraction( static_cast<double>(aPixelLog.X()) *
67  static_cast<double>(rZoomX.GetNumerator()) /
68  static_cast<double>(nTwipsX) /
70  static_cast<double>(rZoomX.GetDenominator()) );
71  else
72  rScaleX = Fraction( 1, 1 );
73 
74  if ( aPixelLog.Y() && nTwipsY )
75  rScaleY = Fraction( static_cast<double>(aPixelLog.Y()) *
76  static_cast<double>(rZoomY.GetNumerator()) /
77  static_cast<double>(nTwipsY) /
79  static_cast<double>(rZoomY.GetDenominator()) );
80  else
81  rScaleY = Fraction( 1, 1 );
82 
83  // 25 bits of accuracy are needed to always hit the right part of
84  // cells in the last rows (was 17 before 1M rows).
85  rScaleX.ReduceInaccurate( 25 );
86  rScaleY.ReduceInaccurate( 25 );
87 }
88 
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr double nPPTY
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4161
#define HMM_PER_TWIPS
Definition: global.hxx:91
constexpr double nPPTX
void ReduceInaccurate(unsigned nSignificantBits)
int i
sal_Int16 SCCOL
Definition: types.hxx:22
Point PixelToLogic(const Point &rDevicePt) const
sal_Int32 SCROW
Definition: types.hxx:18
sal_Int32 GetDenominator() const
sal_Int32 GetNumerator() const
SC_DLLPUBLIC bool RowHidden(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: document.cxx:4429
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4120
static void CalcScale(const ScDocument &rDoc, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const OutputDevice *pDev, const Fraction &rZoomX, const Fraction &rZoomY, double nPPTX, double nPPTY, Fraction &rScaleX, Fraction &rScaleY)
Definition: drawutil.cxx:27
static long ToPixel(sal_uInt16 nTwips, double nFactor)
Definition: viewdata.hxx:682
sal_Int16 SCTAB
Definition: types.hxx:23