LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/view - drawutil.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 34 94.1 %
Date: 2013-07-09 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      28        1041 : void ScDrawUtil::CalcScale( ScDocument* pDoc, SCTAB nTab,
      29             :                             SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      30             :                             OutputDevice* pDev,
      31             :                             const Fraction& rZoomX, const Fraction& rZoomY,
      32             :                             double nPPTX, double nPPTY,
      33             :                             Fraction& rScaleX, Fraction& rScaleY )
      34             : {
      35        1041 :     long nPixelX = 0;
      36        1041 :     long nTwipsX = 0;
      37        1041 :     long nPixelY = 0;
      38        1041 :     long nTwipsY = 0;
      39       22127 :     for (SCCOL i=nStartCol; i<nEndCol; i++)
      40             :     {
      41       21086 :         sal_uInt16 nWidth = pDoc->GetColWidth(i,nTab);
      42       21086 :         nTwipsX += (long) nWidth;
      43       21086 :         nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
      44             :     }
      45             : 
      46      916499 :     for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
      47             :     {
      48      915458 :         SCROW nLastRow = nRow;
      49      915458 :         if (pDoc->RowHidden(nRow, nTab, NULL, &nLastRow))
      50             :         {
      51          27 :             nRow = nLastRow;
      52          27 :             continue;
      53             :         }
      54             : 
      55      915431 :         sal_uInt16 nHeight = pDoc->GetRowHeight(nRow, nTab);
      56      915431 :         nTwipsY += static_cast<long>(nHeight);
      57      915431 :         nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
      58             :     }
      59             : 
      60        1041 :     MapMode aHMMMode( MAP_100TH_MM, Point(), rZoomX, rZoomY );
      61        1041 :     Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
      62             : 
      63             :     //  Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
      64             :     //  because ReduceInaccurate is called later anyway.
      65             : 
      66        1041 :     if ( aPixelLog.X() && nTwipsX )
      67        4164 :         rScaleX = Fraction( ((double)aPixelLog.X()) *
      68        2082 :                             ((double)rZoomX.GetNumerator()) /
      69        1041 :                             ((double)nTwipsX) /
      70             :                             ((double)HMM_PER_TWIPS) /
      71        2082 :                             ((double)rZoomX.GetDenominator()) );
      72             :     else
      73           0 :         rScaleX = Fraction( 1, 1 );
      74             : 
      75        1041 :     if ( aPixelLog.Y() && nTwipsY )
      76        4164 :         rScaleY = Fraction( ((double)aPixelLog.Y()) *
      77        2082 :                             ((double)rZoomY.GetNumerator()) /
      78        1041 :                             ((double)nTwipsY) /
      79             :                             ((double)HMM_PER_TWIPS) /
      80        2082 :                             ((double)rZoomY.GetDenominator()) );
      81             :     else
      82           0 :         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        1041 :     rScaleX.ReduceInaccurate( 25 );
      87        1041 :     rScaleY.ReduceInaccurate( 25 );
      88        1134 : }
      89             : 
      90             : 
      91             : 
      92             : 
      93             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10