LCOV - code coverage report
Current view: top level - sc/source/ui/view - drawutil.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 32 34 94.1 %
Date: 2015-06-13 12:38:46 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        2029 : void ScDrawUtil::CalcScale( ScDocument* pDoc, SCTAB nTab,
      28             :                             SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
      29             :                             OutputDevice* pDev,
      30             :                             const Fraction& rZoomX, const Fraction& rZoomY,
      31             :                             double nPPTX, double nPPTY,
      32             :                             Fraction& rScaleX, Fraction& rScaleY )
      33             : {
      34        2029 :     long nPixelX = 0;
      35        2029 :     long nTwipsX = 0;
      36        2029 :     long nPixelY = 0;
      37        2029 :     long nTwipsY = 0;
      38       76715 :     for (SCCOL i=nStartCol; i<nEndCol; i++)
      39             :     {
      40       74686 :         sal_uInt16 nWidth = pDoc->GetColWidth(i,nTab);
      41       74686 :         nTwipsX += (long) nWidth;
      42       74686 :         nPixelX += ScViewData::ToPixel( nWidth, nPPTX );
      43             :     }
      44             : 
      45     9478617 :     for (SCROW nRow = nStartRow; nRow <= nEndRow-1; ++nRow)
      46             :     {
      47     9476588 :         SCROW nLastRow = nRow;
      48     9476588 :         if (pDoc->RowHidden(nRow, nTab, NULL, &nLastRow))
      49             :         {
      50          42 :             nRow = nLastRow;
      51          42 :             continue;
      52             :         }
      53             : 
      54     9476546 :         sal_uInt16 nHeight = pDoc->GetRowHeight(nRow, nTab);
      55     9476546 :         nTwipsY += static_cast<long>(nHeight);
      56     9476546 :         nPixelY += ScViewData::ToPixel(nHeight, nPPTY);
      57             :     }
      58             : 
      59        2029 :     MapMode aHMMMode( MAP_100TH_MM, Point(), rZoomX, rZoomY );
      60        2029 :     Point aPixelLog = pDev->PixelToLogic( Point( nPixelX,nPixelY ), aHMMMode );
      61             : 
      62             :     //  Fraction(double) ctor can be used here (and avoid overflows of PixelLog * Zoom)
      63             :     //  because ReduceInaccurate is called later anyway.
      64             : 
      65        2029 :     if ( aPixelLog.X() && nTwipsX )
      66        8116 :         rScaleX = Fraction( ((double)aPixelLog.X()) *
      67        4058 :                             ((double)rZoomX.GetNumerator()) /
      68        2029 :                             ((double)nTwipsX) /
      69             :                             ((double)HMM_PER_TWIPS) /
      70        4058 :                             ((double)rZoomX.GetDenominator()) );
      71             :     else
      72           0 :         rScaleX = Fraction( 1, 1 );
      73             : 
      74        2029 :     if ( aPixelLog.Y() && nTwipsY )
      75        8116 :         rScaleY = Fraction( ((double)aPixelLog.Y()) *
      76        4058 :                             ((double)rZoomY.GetNumerator()) /
      77        2029 :                             ((double)nTwipsY) /
      78             :                             ((double)HMM_PER_TWIPS) /
      79        4058 :                             ((double)rZoomY.GetDenominator()) );
      80             :     else
      81           0 :         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        2029 :     rScaleX.ReduceInaccurate( 25 );
      86        2029 :     rScaleY.ReduceInaccurate( 25 );
      87        2185 : }
      88             : 
      89             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11