/src/libreoffice/sc/source/ui/view/drawutil.cxx
Line | Count | Source |
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 <tools/mapunit.hxx> |
24 | | #include <vcl/outdev.hxx> |
25 | | |
26 | | #include <drawutil.hxx> |
27 | | #include <document.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 | | double fZoomX, double fZoomY, |
34 | | double nPPTX, double nPPTY, |
35 | | double& rScaleX, double& rScaleY ) |
36 | 0 | { |
37 | 0 | tools::Long nPixelX = 0; |
38 | 0 | tools::Long nTwipsX = 0; |
39 | 0 | tools::Long nPixelY = 0; |
40 | 0 | tools::Long nTwipsY = 0; |
41 | 0 | for (SCCOL i=nStartCol; i<nEndCol; i++) |
42 | 0 | { |
43 | 0 | sal_uInt16 nWidth = rDoc.GetColWidth(i,nTab); |
44 | 0 | nTwipsX += static_cast<tools::Long>(nWidth); |
45 | 0 | nPixelX += ScViewData::ToPixel( nWidth, nPPTX ); |
46 | 0 | } |
47 | |
|
48 | 0 | for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow) |
49 | 0 | { |
50 | 0 | SCROW nLastRow = nRow; |
51 | 0 | if (rDoc.RowHidden(nRow, nTab, nullptr, &nLastRow)) |
52 | 0 | { |
53 | 0 | nRow = nLastRow; |
54 | 0 | continue; |
55 | 0 | } |
56 | | |
57 | 0 | sal_uInt16 nHeight = rDoc.GetRowHeight(nRow, nTab); |
58 | 0 | nTwipsY += static_cast<tools::Long>(nHeight); |
59 | 0 | nPixelY += ScViewData::ToPixel(nHeight, nPPTY); |
60 | 0 | } |
61 | |
|
62 | 0 | MapMode aHMMMode( MapUnit::Map100thMM, Point(), fZoomX, fZoomY ); |
63 | 0 | 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 | 0 | if ( aPixelLog.X() && nTwipsX ) |
69 | 0 | rScaleX = static_cast<double>(aPixelLog.X()) * fZoomX / |
70 | 0 | o3tl::convert<double>(nTwipsX, o3tl::Length::twip, o3tl::Length::mm100); |
71 | 0 | else |
72 | 0 | rScaleX = 1.0; |
73 | |
|
74 | 0 | if ( aPixelLog.Y() && nTwipsY ) |
75 | 0 | rScaleY = static_cast<double>(aPixelLog.Y()) * fZoomY / |
76 | 0 | o3tl::convert<double>(nTwipsY, o3tl::Length::twip, o3tl::Length::mm100); |
77 | 0 | else |
78 | 0 | rScaleY = 1.0; |
79 | 0 | } |
80 | | |
81 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |