1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <tools/shl.hxx>
22 #include <vcl/svapp.hxx>
23 #include <editeng/editrids.hrc>
24 #include <editeng/paperinf.hxx>
25 #include <editeng/eerdll.hxx>
27 /*--------------------------------------------------------------------
28 Description: Is the printer valid
29 --------------------------------------------------------------------*/
31 inline sal_Bool
IsValidPrinter( const Printer
* pPtr
)
33 return pPtr
->GetName().isEmpty() ? sal_False
: sal_True
;
36 //------------------------------------------------------------------------
38 Size
SvxPaperInfo::GetPaperSize( Paper ePaper
, MapUnit eUnit
)
40 PaperInfo
aInfo(ePaper
);
41 Size
aRet(aInfo
.getWidth(), aInfo
.getHeight()); // in 100thMM
42 return eUnit
== MAP_100TH_MM
? aRet
: OutputDevice::LogicToLogic(aRet
, MAP_100TH_MM
, eUnit
);
45 /*------------------------------------------------------------------------
46 Description: Return the paper size of the printer, aligned to our
47 own sizes. If no Printer is set in the system, A4 portrait
48 will be delivered as the default paper size.
49 ------------------------------------------------------------------------*/
51 //Is this method may be confused about the units it returns ?
52 //Always returns TWIPS for known paper sizes or on failure.
53 //But in the case of PAPER_USER paper and with a Printer with a mapmode set
54 //will return in those printer units ?
55 Size
SvxPaperInfo::GetPaperSize( const Printer
* pPrinter
)
57 if ( !IsValidPrinter(pPrinter
) )
58 return GetPaperSize( PAPER_A4
);
59 const Paper ePaper
= pPrinter
->GetPaper();
61 if ( ePaper
== PAPER_USER
)
63 // Orientation not take into account, as the right size has
64 // been already set by SV
65 Size aPaperSize
= pPrinter
->GetPaperSize();
66 const Size aInvalidSize
;
68 if ( aPaperSize
== aInvalidSize
)
69 return GetPaperSize(PAPER_A4
);
70 MapMode aMap1
= pPrinter
->GetMapMode();
75 pPrinter
->PixelToLogic( aPaperSize
, MapMode( MAP_TWIP
) );
79 const Orientation eOrient
= pPrinter
->GetOrientation();
80 Size
aSize( GetPaperSize( ePaper
) );
81 // for Landscape exchange the pages, has already been done by SV
82 if ( eOrient
== ORIENTATION_LANDSCAPE
)
87 // -----------------------------------------------------------------------
89 Paper
SvxPaperInfo::GetSvxPaper( const Size
&rSize
, MapUnit eUnit
, bool bSloppy
)
91 Size
aSize(eUnit
== MAP_100TH_MM
? rSize
: OutputDevice::LogicToLogic(rSize
, eUnit
, MAP_100TH_MM
));
92 PaperInfo
aInfo(aSize
.Width(), aSize
.Height());
95 return aInfo
.getPaper();
98 // -----------------------------------------------------------------------
100 long SvxPaperInfo::GetSloppyPaperDimension( long nSize
, MapUnit eUnit
)
102 nSize
= eUnit
== MAP_100TH_MM
? nSize
: OutputDevice::LogicToLogic(nSize
, eUnit
, MAP_100TH_MM
);
103 nSize
= PaperInfo::sloppyFitPageDimension(nSize
);
104 return eUnit
== MAP_100TH_MM
? nSize
: OutputDevice::LogicToLogic(nSize
, MAP_100TH_MM
, eUnit
);
107 // -----------------------------------------------------------------------
109 Size
SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit
)
111 PaperInfo
aInfo(PaperInfo::getSystemDefaultPaper());
112 Size
aRet(aInfo
.getWidth(), aInfo
.getHeight());
113 return eUnit
== MAP_100TH_MM
? aRet
: OutputDevice::LogicToLogic(aRet
, MAP_100TH_MM
, eUnit
);
116 /*------------------------------------------------------------------------
117 Description: String representation for the SV-defines of paper size
118 ------------------------------------------------------------------------*/
120 String
SvxPaperInfo::GetName( Paper ePaper
)
122 return String( Printer::GetPaperName( ePaper
) );
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */