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
23#include <vcl/outdev.hxx>
24
25#include <drawutil.hxx>
26#include <document.hxx>
27#include <viewdata.hxx>
28
29void ScDrawUtil::CalcScale( const ScDocument& rDoc, SCTAB nTab,
30 SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
31 const OutputDevice* pDev,
32 const Fraction& rZoomX, const Fraction& rZoomY,
33 double nPPTX, double nPPTY,
34 Fraction& rScaleX, Fraction& rScaleY )
35{
36 tools::Long nPixelX = 0;
37 tools::Long nTwipsX = 0;
38 tools::Long nPixelY = 0;
39 tools::Long nTwipsY = 0;
40 for (SCCOL i=nStartCol; i<nEndCol; i++)
41 {
42 sal_uInt16 nWidth = rDoc.GetColWidth(i,nTab);
43 nTwipsX += static_cast<tools::Long>(nWidth);
44 nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
45 }
46
47 for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
48 {
49 SCROW nLastRow = nRow;
50 if (rDoc.RowHidden(nRow, nTab, nullptr, &nLastRow))
51 {
52 nRow = nLastRow;
53 continue;
54 }
55
56 sal_uInt16 nHeight = rDoc.GetRowHeight(nRow, nTab);
57 nTwipsY += static_cast<tools::Long>(nHeight);
58 nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
59 }
60
61 MapMode aHMMMode( MapUnit::Map100thMM, Point(), rZoomX, rZoomY );
62 Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
63
64 // Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
65 // because ReduceInaccurate is called later anyway.
66
67 if ( aPixelLog.X() && nTwipsX )
68 rScaleX = Fraction( static_cast<double>(aPixelLog.X()) *
69 static_cast<double>(rZoomX.GetNumerator()) /
70 o3tl::convert<double>(nTwipsX, o3tl::Length::twip, o3tl::Length::mm100) /
71 static_cast<double>(rZoomX.GetDenominator()) );
72 else
73 rScaleX = Fraction( 1, 1 );
74
75 if ( aPixelLog.Y() && nTwipsY )
76 rScaleY = Fraction( static_cast<double>(aPixelLog.Y()) *
77 static_cast<double>(rZoomY.GetNumerator()) /
78 o3tl::convert<double>(nTwipsY, o3tl::Length::twip, o3tl::Length::mm100) /
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: */
sal_Int32 GetNumerator() const
void ReduceInaccurate(unsigned nSignificantBits)
sal_Int32 GetDenominator() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
constexpr tools::Long Y() const
constexpr tools::Long X() const
SC_DLLPUBLIC sal_uInt16 GetRowHeight(SCROW nRow, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4161
SC_DLLPUBLIC sal_uInt16 GetColWidth(SCCOL nCol, SCTAB nTab, bool bHiddenAsZero=true) const
Definition: document.cxx:4122
SC_DLLPUBLIC bool RowHidden(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: document.cxx:4416
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:29
static tools::Long ToPixel(sal_uInt16 nTwips, double nFactor)
Definition: viewdata.hxx:700
constexpr double nPPTX
constexpr double nPPTY
int i
long Long
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17