2010-10-12 15:59:00 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-30 12:23:25 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#include <vcl/outdev.hxx>
|
|
|
|
|
|
|
|
#include "drawutil.hxx"
|
|
|
|
#include "document.hxx"
|
|
|
|
#include "global.hxx"
|
2001-04-18 09:42:15 +00:00
|
|
|
#include "viewdata.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2004-06-04 10:59:44 +00:00
|
|
|
void ScDrawUtil::CalcScale( ScDocument* pDoc, SCTAB nTab,
|
|
|
|
SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
|
2000-09-18 16:07:07 +00:00
|
|
|
OutputDevice* pDev,
|
2014-10-23 17:41:47 +02:00
|
|
|
const Fraction& rZoomX, const Fraction& rZoomY,
|
2000-09-18 16:07:07 +00:00
|
|
|
double nPPTX, double nPPTY,
|
2014-10-23 17:41:47 +02:00
|
|
|
Fraction& rScaleX, Fraction& rScaleY )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
long nPixelX = 0;
|
|
|
|
long nTwipsX = 0;
|
|
|
|
long nPixelY = 0;
|
|
|
|
long nTwipsY = 0;
|
2004-06-04 10:59:44 +00:00
|
|
|
for (SCCOL i=nStartCol; i<nEndCol; i++)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nWidth = pDoc->GetColWidth(i,nTab);
|
2001-04-18 09:42:15 +00:00
|
|
|
nTwipsX += (long) nWidth;
|
|
|
|
nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2010-06-23 13:38:34 +02:00
|
|
|
|
|
|
|
for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2010-06-23 13:38:34 +02:00
|
|
|
SCROW nLastRow = nRow;
|
|
|
|
if (pDoc->RowHidden(nRow, nTab, NULL, &nLastRow))
|
|
|
|
{
|
|
|
|
nRow = nLastRow;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:20:22 +01:00
|
|
|
sal_uInt16 nHeight = pDoc->GetRowHeight(nRow, nTab);
|
2010-06-23 13:38:34 +02:00
|
|
|
nTwipsY += static_cast<long>(nHeight);
|
|
|
|
nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MapMode aHMMMode( MAP_100TH_MM, Point(), rZoomX, rZoomY );
|
|
|
|
Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
|
|
|
|
|
2001-10-16 13:43:14 +00:00
|
|
|
// Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
|
|
|
|
// because ReduceInaccurate is called later anyway.
|
|
|
|
|
|
|
|
if ( aPixelLog.X() && nTwipsX )
|
2014-10-23 17:41:47 +02:00
|
|
|
rScaleX = Fraction( ((double)aPixelLog.X()) *
|
|
|
|
((double)rZoomX.GetNumerator()) /
|
2001-10-16 13:43:14 +00:00
|
|
|
((double)nTwipsX) /
|
|
|
|
((double)HMM_PER_TWIPS) /
|
2014-10-23 17:41:47 +02:00
|
|
|
((double)rZoomX.GetDenominator()) );
|
2001-10-16 13:43:14 +00:00
|
|
|
else
|
2014-10-23 17:41:47 +02:00
|
|
|
rScaleX = Fraction( 1, 1 );
|
2001-10-16 13:43:14 +00:00
|
|
|
|
|
|
|
if ( aPixelLog.Y() && nTwipsY )
|
2014-10-23 17:41:47 +02:00
|
|
|
rScaleY = Fraction( ((double)aPixelLog.Y()) *
|
|
|
|
((double)rZoomY.GetNumerator()) /
|
2001-10-16 13:43:14 +00:00
|
|
|
((double)nTwipsY) /
|
|
|
|
((double)HMM_PER_TWIPS) /
|
2014-10-23 17:41:47 +02:00
|
|
|
((double)rZoomY.GetDenominator()) );
|
2001-10-16 13:43:14 +00:00
|
|
|
else
|
2014-10-23 17:41:47 +02:00
|
|
|
rScaleY = Fraction( 1, 1 );
|
2001-10-16 13:43:14 +00:00
|
|
|
|
2010-06-23 13:38:34 +02:00
|
|
|
// 25 bits of accuracy are needed to always hit the right part of
|
|
|
|
// cells in the last rows (was 17 before 1M rows).
|
2014-10-23 17:41:47 +02:00
|
|
|
rScaleX.ReduceInaccurate( 25 );
|
|
|
|
rScaleY.ReduceInaccurate( 25 );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:59:00 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|