Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <limits.h>
30 : : #include <tools/shl.hxx>
31 : : #include <vcl/svapp.hxx>
32 : : #include <editeng/editrids.hrc>
33 : : #include <editeng/paperinf.hxx>
34 : : #include <editeng/eerdll.hxx>
35 : :
36 : : /*--------------------------------------------------------------------
37 : : Description: Is the printer valid
38 : : --------------------------------------------------------------------*/
39 : :
40 : 19 : inline sal_Bool IsValidPrinter( const Printer* pPtr )
41 : : {
42 [ + + ]: 19 : return pPtr->GetName().isEmpty() ? sal_False : sal_True;
43 : : }
44 : :
45 : : //------------------------------------------------------------------------
46 : :
47 : 365 : Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit )
48 : : {
49 [ + - ]: 365 : PaperInfo aInfo(ePaper);
50 : 365 : Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
51 [ + - ][ + - ]: 365 : return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
[ + - ][ + + ]
[ + - ][ + + ]
[ + - ]
[ # # # # ]
[ + + ]
52 : : }
53 : :
54 : : /*------------------------------------------------------------------------
55 : : Description: Return the paper size of the printer, aligned to our
56 : : own sizes. If no Printer is set in the system, A4 portrait
57 : : will be delivered as the default paper size.
58 : : ------------------------------------------------------------------------*/
59 : :
60 : : //Is this method may be confused about the units it returns ?
61 : : //Always returns TWIPS for known paper sizes or on failure.
62 : : //But in the case of PAPER_USER paper and with a Printer with a mapmode set
63 : : //will return in those printer units ?
64 : 19 : Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter )
65 : : {
66 [ + + ]: 19 : if ( !IsValidPrinter(pPrinter) )
67 [ + - ]: 6 : return GetPaperSize( PAPER_A4 );
68 [ + - ]: 13 : const Paper ePaper = pPrinter->GetPaper();
69 : :
70 [ - + ]: 13 : if ( ePaper == PAPER_USER )
71 : : {
72 : : // Orientation not take into account, as the right size has
73 : : // been already set by SV
74 [ # # ]: 0 : Size aPaperSize = pPrinter->GetPaperSize();
75 : 0 : const Size aInvalidSize;
76 : :
77 [ # # ]: 0 : if ( aPaperSize == aInvalidSize )
78 [ # # ]: 0 : return GetPaperSize(PAPER_A4);
79 [ # # ]: 0 : MapMode aMap1 = pPrinter->GetMapMode();
80 [ # # ]: 0 : MapMode aMap2;
81 : :
82 [ # # ][ # # ]: 0 : if ( aMap1 == aMap2 )
83 : : aPaperSize =
84 [ # # ][ # # ]: 0 : pPrinter->PixelToLogic( aPaperSize, MapMode( MAP_TWIP ) );
[ # # ]
85 [ # # ][ # # ]: 0 : return aPaperSize;
86 : : }
87 : :
88 [ + - ]: 13 : const Orientation eOrient = pPrinter->GetOrientation();
89 [ + - ]: 13 : Size aSize( GetPaperSize( ePaper ) );
90 : : // for Landscape exchange the pages, has already been done by SV
91 [ - + ]: 13 : if ( eOrient == ORIENTATION_LANDSCAPE )
92 : 0 : Swap( aSize );
93 : 19 : return aSize;
94 : : }
95 : :
96 : : // -----------------------------------------------------------------------
97 : :
98 : 0 : Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit, bool bSloppy )
99 : : {
100 [ # # ][ # # ]: 0 : Size aSize(eUnit == MAP_100TH_MM ? rSize : OutputDevice::LogicToLogic(rSize, eUnit, MAP_100TH_MM));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
101 [ # # ]: 0 : PaperInfo aInfo(aSize.Width(), aSize.Height());
102 [ # # ]: 0 : if (bSloppy)
103 [ # # ]: 0 : aInfo.doSloppyFit();
104 : 0 : return aInfo.getPaper();
105 : : }
106 : :
107 : : // -----------------------------------------------------------------------
108 : :
109 : 453 : long SvxPaperInfo::GetSloppyPaperDimension( long nSize, MapUnit eUnit )
110 : : {
111 [ + - ]: 453 : nSize = eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, eUnit, MAP_100TH_MM);
112 : 453 : nSize = PaperInfo::sloppyFitPageDimension(nSize);
113 [ + - ]: 453 : return eUnit == MAP_100TH_MM ? nSize : OutputDevice::LogicToLogic(nSize, MAP_100TH_MM, eUnit);
114 : : }
115 : :
116 : : // -----------------------------------------------------------------------
117 : :
118 : 3147 : Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit )
119 : : {
120 [ + - ]: 3147 : PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
121 : 3147 : Size aRet(aInfo.getWidth(), aInfo.getHeight());
122 [ + - ][ + - ]: 3147 : return eUnit == MAP_100TH_MM ? aRet : OutputDevice::LogicToLogic(aRet, MAP_100TH_MM, eUnit);
[ + - ][ + + ]
[ + - ][ + + ]
[ + - ]
[ # # # # ]
[ + + ]
123 : : }
124 : :
125 : : /*------------------------------------------------------------------------
126 : : Description: String representation for the SV-defines of paper size
127 : : ------------------------------------------------------------------------*/
128 : :
129 : 0 : String SvxPaperInfo::GetName( Paper ePaper )
130 : : {
131 [ # # ]: 0 : return String( Printer::GetPaperName( ePaper ) );
132 : : }
133 : :
134 : :
135 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|