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