LCOV - code coverage report
Current view: top level - editeng/source/items - paperinf.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 29 42 69.0 %
Date: 2014-11-03 Functions: 8 9 88.9 %
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 <limits.h>
      21             : #include <vcl/svapp.hxx>
      22             : #include <editeng/editrids.hrc>
      23             : #include <editeng/paperinf.hxx>
      24             : #include <editeng/eerdll.hxx>
      25             : 
      26             : /*--------------------------------------------------------------------
      27             :     Description:    Is the printer valid
      28             :  --------------------------------------------------------------------*/
      29             : 
      30         178 : inline bool IsValidPrinter( const Printer* pPtr )
      31             : {
      32         178 :     return pPtr->GetName().isEmpty() ? sal_False : sal_True;
      33             : }
      34             : 
      35             : 
      36             : 
      37         966 : Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit )
      38             : {
      39         966 :     PaperInfo aInfo(ePaper);
      40         966 :     Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
      41         966 :     return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
      42             : }
      43             : 
      44             : /*------------------------------------------------------------------------
      45             :  Description:   Return the paper size of the printer, aligned to our
      46             :                 own sizes. If no Printer is set in the system, A4 portrait
      47             :                 will be delivered as the default paper size.
      48             : ------------------------------------------------------------------------*/
      49             : 
      50             : //Is this method may be confused about the units it returns ?
      51             : //Always returns TWIPS for known paper sizes or on failure.
      52             : //But in the case of PAPER_USER paper and with a Printer with a mapmode set
      53             : //will return in those printer units ?
      54         178 : Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter )
      55             : {
      56         178 :     if ( !IsValidPrinter(pPrinter) )
      57           0 :         return GetPaperSize( PAPER_A4 );
      58         178 :     const Paper ePaper = pPrinter->GetPaper();
      59             : 
      60         178 :     if ( ePaper == PAPER_USER )
      61             :     {
      62             :         // Orientation not take into account, as the right size has
      63             :         // been already set by SV
      64           0 :         Size aPaperSize = pPrinter->GetPaperSize();
      65           0 :         const Size aInvalidSize;
      66             : 
      67           0 :         if ( aPaperSize == aInvalidSize )
      68           0 :             return GetPaperSize(PAPER_A4);
      69           0 :         MapMode aMap1 = pPrinter->GetMapMode();
      70           0 :         MapMode aMap2;
      71             : 
      72           0 :         if ( aMap1 == aMap2 )
      73             :             aPaperSize =
      74           0 :                 pPrinter->PixelToLogic( aPaperSize, MapMode( MAP_TWIP ) );
      75           0 :         return aPaperSize;
      76             :     }
      77             : 
      78         178 :     const Orientation eOrient = pPrinter->GetOrientation();
      79         178 :     Size aSize( GetPaperSize( ePaper ) );
      80             :         // for Landscape exchange the pages, has already been done by SV
      81         178 :     if ( eOrient == ORIENTATION_LANDSCAPE )
      82           0 :         Swap( aSize );
      83         178 :     return aSize;
      84             : }
      85             : 
      86             : 
      87             : 
      88        1484 : Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit, bool bSloppy )
      89             : {
      90        1484 :     Size aSize(eUnit == MAP_100TH_MM ? rSize : OutputDevice::LogicToLogic(rSize, eUnit, MAP_100TH_MM));
      91        1484 :     PaperInfo aInfo(aSize.Width(), aSize.Height());
      92        1484 :     if (bSloppy)
      93        1484 :         aInfo.doSloppyFit();
      94        1484 :     return aInfo.getPaper();
      95             : }
      96             : 
      97             : 
      98             : 
      99         522 : long SvxPaperInfo::GetSloppyPaperDimension( long nSize, MapUnit eUnit )
     100             : {
     101         522 :     nSize = eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, eUnit, MAP_100TH_MM);
     102         522 :     nSize = PaperInfo::sloppyFitPageDimension(nSize);
     103         522 :     return eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, MAP_100TH_MM, eUnit);
     104             : }
     105             : 
     106             : 
     107             : 
     108       10034 : Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit )
     109             : {
     110       10034 :     PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
     111       10034 :     Size aRet(aInfo.getWidth(), aInfo.getHeight());
     112       10034 :     return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
     113             : }
     114             : 
     115             : /*------------------------------------------------------------------------
     116             :  Description:   String representation for the SV-defines of paper size
     117             : ------------------------------------------------------------------------*/
     118             : 
     119           0 : OUString SvxPaperInfo::GetName( Paper ePaper )
     120             : {
     121           0 :     return Printer::GetPaperName( ePaper );
     122         669 : }
     123             : 
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10