nss: upgrade to release 3.73
[LibreOffice.git] / editeng / source / items / paperinf.cxx
blobe8646bc55377bd98bb0aef42d31194099630caee
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 <vcl/print.hxx>
21 #include <editeng/paperinf.hxx>
23 /*--------------------------------------------------------------------
24 Description: Is the printer valid
25 --------------------------------------------------------------------*/
27 static bool IsValidPrinter( const Printer* pPtr )
29 return !pPtr->GetName().isEmpty();
33 Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit )
35 PaperInfo aInfo(ePaper);
36 Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
37 return eUnit == MapUnit::Map100thMM
38 ? aRet
39 : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit));
42 /*------------------------------------------------------------------------
43 Description: Return the paper size of the printer, aligned to our
44 own sizes. If no Printer is set in the system, A4 portrait
45 will be delivered as the default paper size.
46 ------------------------------------------------------------------------*/
48 //Is this method may be confused about the units it returns ?
49 //Always returns TWIPS for known paper sizes or on failure.
50 //But in the case of PAPER_USER paper and with a Printer with a mapmode set
51 //will return in those printer units ?
52 Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter )
54 if ( !IsValidPrinter(pPrinter) )
55 return GetPaperSize( PAPER_A4 );
56 const Paper ePaper = pPrinter->GetPaper();
58 if ( ePaper == PAPER_USER )
60 // Orientation not take into account, as the right size has
61 // been already set by SV
62 Size aPaperSize = pPrinter->GetPaperSize();
63 const Size aInvalidSize;
65 if ( aPaperSize == aInvalidSize )
66 return GetPaperSize(PAPER_A4);
67 const MapMode& aMap1 = pPrinter->GetMapMode();
68 MapMode aMap2;
70 if ( aMap1 == aMap2 )
71 aPaperSize =
72 pPrinter->PixelToLogic( aPaperSize, MapMode( MapUnit::MapTwip ) );
73 return aPaperSize;
76 const Orientation eOrient = pPrinter->GetOrientation();
77 Size aSize( GetPaperSize( ePaper ) );
78 // for Landscape exchange the pages, has already been done by SV
79 if ( eOrient == Orientation::Landscape )
80 Swap( aSize );
81 return aSize;
85 Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit )
87 Size aSize(eUnit == MapUnit::Map100thMM ? rSize : OutputDevice::LogicToLogic(rSize, MapMode(eUnit), MapMode(MapUnit::Map100thMM)));
88 PaperInfo aInfo(aSize.Width(), aSize.Height());
89 aInfo.doSloppyFit();
90 return aInfo.getPaper();
94 tools::Long SvxPaperInfo::GetSloppyPaperDimension( tools::Long nSize )
96 nSize = OutputDevice::LogicToLogic(nSize, MapUnit::MapTwip, MapUnit::Map100thMM);
97 nSize = PaperInfo::sloppyFitPageDimension(nSize);
98 return OutputDevice::LogicToLogic(nSize, MapUnit::Map100thMM, MapUnit::MapTwip);
102 Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit )
104 PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
105 Size aRet(aInfo.getWidth(), aInfo.getHeight());
106 return eUnit == MapUnit::Map100thMM
107 ? aRet
108 : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit));
111 /*------------------------------------------------------------------------
112 Description: String representation for the SV-defines of paper size
113 ------------------------------------------------------------------------*/
115 OUString SvxPaperInfo::GetName( Paper ePaper )
117 return Printer::GetPaperName( ePaper );
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */