xref: /aoo42x/main/editeng/source/items/paperinf.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_editeng.hxx"
30 
31 // include ---------------------------------------------------------------
32 
33 #include <limits.h>
34 #include <tools/shl.hxx>
35 #include <tools/debug.hxx>
36 #include <vcl/svapp.hxx>
37 #include <editeng/editrids.hrc>
38 #include <editeng/paperinf.hxx>
39 #include <editeng/eerdll.hxx>
40 
41 /*--------------------------------------------------------------------
42 	Beschreibung:	Ist der Printer gueltig
43  --------------------------------------------------------------------*/
44 
45 inline sal_Bool IsValidPrinter( const Printer* pPtr )
46 {
47 	return pPtr->GetName().Len() ? sal_True : sal_False;
48 }
49 
50 //------------------------------------------------------------------------
51 
52 Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit )
53 {
54     PaperInfo aInfo(ePaper);
55     Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
56     return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
57 }
58 
59 /*------------------------------------------------------------------------
60  Beschreibung:	Papiergroesse der Druckers liefern, aligned auf
61 				die eigenen Groessen.
62 				Falls kein Printer im System eingestellt ist,
63 				wird DIN A4 Portrait als Defaultpapiergroesse geliefert.
64 ------------------------------------------------------------------------*/
65 
66 //Is this method may be confused about the units it returns ?
67 //Always returns TWIPS for known paper sizes or on failure.
68 //But in the case of PAPER_USER paper and with a Printer with a mapmode set
69 //will return in those printer units ?
70 Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter )
71 {
72 	if ( !IsValidPrinter(pPrinter) )
73 		return GetPaperSize( PAPER_A4 );
74 	const Paper ePaper = pPrinter->GetPaper();
75 
76 	if ( ePaper == PAPER_USER )
77 	{
78 		// Orientation nicht beruecksichtigen, da durch SV bereits
79 		// die richtigen Masze eingestellt worden sind.
80 		Size aPaperSize = pPrinter->GetPaperSize();
81 		const Size aInvalidSize;
82 
83 		if ( aPaperSize == aInvalidSize )
84 			return GetPaperSize(PAPER_A4);
85 		MapMode aMap1 = pPrinter->GetMapMode();
86 		MapMode aMap2;
87 
88 		if ( aMap1 == aMap2 )
89 			aPaperSize =
90 				pPrinter->PixelToLogic( aPaperSize, MapMode( MAP_TWIP ) );
91 		return aPaperSize;
92 	}
93 
94 	const Orientation eOrient = pPrinter->GetOrientation();
95 	Size aSize( GetPaperSize( ePaper ) );
96 		// bei Landscape die Seiten tauschen, ist bei SV schon geschehen
97 	if ( eOrient == ORIENTATION_LANDSCAPE )
98 		Swap( aSize );
99 	return aSize;
100 }
101 
102 // -----------------------------------------------------------------------
103 
104 Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit, bool bSloppy )
105 {
106     Size aSize(eUnit == MAP_100TH_MM ? rSize : OutputDevice::LogicToLogic(rSize, eUnit, MAP_100TH_MM));
107     PaperInfo aInfo(aSize.Width(), aSize.Height());
108     if (bSloppy)
109         aInfo.doSloppyFit();
110     return aInfo.getPaper();
111 }
112 
113 // -----------------------------------------------------------------------
114 
115 long SvxPaperInfo::GetSloppyPaperDimension( long nSize, MapUnit eUnit )
116 {
117     nSize = eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, eUnit, MAP_100TH_MM);
118     nSize = PaperInfo::sloppyFitPageDimension(nSize);
119     return eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, MAP_100TH_MM, eUnit);
120 }
121 
122 // -----------------------------------------------------------------------
123 
124 Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit )
125 {
126     PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
127     Size aRet(aInfo.getWidth(), aInfo.getHeight());
128     return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
129 }
130 
131 /*------------------------------------------------------------------------
132  Beschreibung:	String Repr"asentation f"ur die SV-Defines f"ur
133 				Papiergroessen.
134 ------------------------------------------------------------------------*/
135 
136 String SvxPaperInfo::GetName( Paper ePaper )
137 {
138     return String( Printer::GetPaperName( ePaper ) );
139 }
140 
141 
142