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