bump product version to 6.4.0.3
[LibreOffice.git] / editeng / source / items / paperinf.cxx
blobb4d92ff45598a47bd01a3351b6e30a1073c746c1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <limits.h>
21 #include <vcl/print.hxx>
22 #include <vcl/svapp.hxx>
23 #include <editeng/paperinf.hxx>
25 /*--------------------------------------------------------------------
26 Description: Is the printer valid
27 --------------------------------------------------------------------*/
29 static bool IsValidPrinter( const Printer* pPtr )
31 return !pPtr->GetName().isEmpty();
35 Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit )
37 PaperInfo aInfo(ePaper);
38 Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
39 return eUnit == MapUnit::Map100thMM
40 ? aRet
41 : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit));
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 ------------------------------------------------------------------------*/
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 Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter )
56 if ( !IsValidPrinter(pPrinter) )
57 return GetPaperSize( PAPER_A4 );
58 const Paper ePaper = pPrinter->GetPaper();
60 if ( ePaper == PAPER_USER )
62 // Orientation not take into account, as the right size has
63 // been already set by SV
64 Size aPaperSize = pPrinter->GetPaperSize();
65 const Size aInvalidSize;
67 if ( aPaperSize == aInvalidSize )
68 return GetPaperSize(PAPER_A4);
69 const MapMode& aMap1 = pPrinter->GetMapMode();
70 MapMode aMap2;
72 if ( aMap1 == aMap2 )
73 aPaperSize =
74 pPrinter->PixelToLogic( aPaperSize, MapMode( MapUnit::MapTwip ) );
75 return aPaperSize;
78 const Orientation eOrient = pPrinter->GetOrientation();
79 Size aSize( GetPaperSize( ePaper ) );
80 // for Landscape exchange the pages, has already been done by SV
81 if ( eOrient == Orientation::Landscape )
82 Swap( aSize );
83 return aSize;
87 Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit )
89 Size aSize(eUnit == MapUnit::Map100thMM ? rSize : OutputDevice::LogicToLogic(rSize, MapMode(eUnit), MapMode(MapUnit::Map100thMM)));
90 PaperInfo aInfo(aSize.Width(), aSize.Height());
91 aInfo.doSloppyFit();
92 return aInfo.getPaper();
96 long SvxPaperInfo::GetSloppyPaperDimension( long nSize )
98 nSize = OutputDevice::LogicToLogic(nSize, MapUnit::MapTwip, MapUnit::Map100thMM);
99 nSize = PaperInfo::sloppyFitPageDimension(nSize);
100 return OutputDevice::LogicToLogic(nSize, MapUnit::Map100thMM, MapUnit::MapTwip);
104 Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit )
106 PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
107 Size aRet(aInfo.getWidth(), aInfo.getHeight());
108 return eUnit == MapUnit::Map100thMM
109 ? aRet
110 : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit));
113 /*------------------------------------------------------------------------
114 Description: String representation for the SV-defines of paper size
115 ------------------------------------------------------------------------*/
117 OUString SvxPaperInfo::GetName( Paper ePaper )
119 return Printer::GetPaperName( ePaper );
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */