xref: /trunk/main/editeng/source/items/paperinf.cxx (revision 190118d0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 #include <limits.h>
30 #include <tools/shl.hxx>
31 #include <tools/debug.hxx>
32 #include <vcl/svapp.hxx>
33 #include <editeng/editrids.hrc>
34 #include <editeng/paperinf.hxx>
35 #include <editeng/eerdll.hxx>
36 
37 /*--------------------------------------------------------------------
38 	Beschreibung:	Ist der Printer gueltig
39  --------------------------------------------------------------------*/
40 
IsValidPrinter(const Printer * pPtr)41 inline sal_Bool IsValidPrinter( const Printer* pPtr )
42 {
43 	return pPtr->GetName().Len() ? sal_True : sal_False;
44 }
45 
46 //------------------------------------------------------------------------
47 
GetPaperSize(Paper ePaper,MapUnit eUnit)48 Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit )
49 {
50     PaperInfo aInfo(ePaper);
51     Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
52     return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
53 }
54 
55 /*------------------------------------------------------------------------
56  Beschreibung:	Papiergroesse der Druckers liefern, aligned auf
57 				die eigenen Groessen.
58 				Falls kein Printer im System eingestellt ist,
59 				wird DIN A4 Portrait als Defaultpapiergroesse geliefert.
60 ------------------------------------------------------------------------*/
61 
62 //Is this method may be confused about the units it returns ?
63 //Always returns TWIPS for known paper sizes or on failure.
64 //But in the case of PAPER_USER paper and with a Printer with a mapmode set
65 //will return in those printer units ?
GetPaperSize(const Printer * pPrinter)66 Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter )
67 {
68 	if ( !IsValidPrinter(pPrinter) )
69 		return GetPaperSize( PAPER_A4 );
70 	const Paper ePaper = pPrinter->GetPaper();
71 
72 	if ( ePaper == PAPER_USER )
73 	{
74 		// Orientation nicht beruecksichtigen, da durch SV bereits
75 		// die richtigen Masze eingestellt worden sind.
76 		Size aPaperSize = pPrinter->GetPaperSize();
77 		const Size aInvalidSize;
78 
79 		if ( aPaperSize == aInvalidSize )
80 			return GetPaperSize(PAPER_A4);
81 		MapMode aMap1 = pPrinter->GetMapMode();
82 		MapMode aMap2;
83 
84 		if ( aMap1 == aMap2 )
85 			aPaperSize =
86 				pPrinter->PixelToLogic( aPaperSize, MapMode( MAP_TWIP ) );
87 		return aPaperSize;
88 	}
89 
90 	const Orientation eOrient = pPrinter->GetOrientation();
91 	Size aSize( GetPaperSize( ePaper ) );
92 		// bei Landscape die Seiten tauschen, ist bei SV schon geschehen
93 	if ( eOrient == ORIENTATION_LANDSCAPE )
94 		Swap( aSize );
95 	return aSize;
96 }
97 
98 // -----------------------------------------------------------------------
99 
GetSvxPaper(const Size & rSize,MapUnit eUnit,bool bSloppy)100 Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit, bool bSloppy )
101 {
102     Size aSize(eUnit == MAP_100TH_MM ? rSize : OutputDevice::LogicToLogic(rSize, eUnit, MAP_100TH_MM));
103     PaperInfo aInfo(aSize.Width(), aSize.Height());
104     if (bSloppy)
105         aInfo.doSloppyFit();
106     return aInfo.getPaper();
107 }
108 
109 // -----------------------------------------------------------------------
110 
GetSloppyPaperDimension(long nSize,MapUnit eUnit)111 long SvxPaperInfo::GetSloppyPaperDimension( long nSize, MapUnit eUnit )
112 {
113     nSize = eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, eUnit, MAP_100TH_MM);
114     nSize = PaperInfo::sloppyFitPageDimension(nSize);
115     return eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, MAP_100TH_MM, eUnit);
116 }
117 
118 // -----------------------------------------------------------------------
119 
GetDefaultPaperSize(MapUnit eUnit)120 Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit )
121 {
122     PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
123     Size aRet(aInfo.getWidth(), aInfo.getHeight());
124     return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
125 }
126 
127 /*------------------------------------------------------------------------
128  Beschreibung:	String Repr"asentation f"ur die SV-Defines f"ur
129 				Papiergroessen.
130 ------------------------------------------------------------------------*/
131 
GetName(Paper ePaper)132 String SvxPaperInfo::GetName( Paper ePaper )
133 {
134     return String( Printer::GetPaperName( ePaper ) );
135 }
136 
137 
138