/src/libreoffice/editeng/source/items/paperinf.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <vcl/print.hxx> |
21 | | #include <editeng/paperinf.hxx> |
22 | | |
23 | | /*-------------------------------------------------------------------- |
24 | | Description: Is the printer valid |
25 | | --------------------------------------------------------------------*/ |
26 | | |
27 | | static bool IsValidPrinter( const Printer* pPtr ) |
28 | 923 | { |
29 | 923 | return !pPtr->GetName().isEmpty(); |
30 | 923 | } |
31 | | |
32 | | |
33 | | Size SvxPaperInfo::GetPaperSize( Paper ePaper, MapUnit eUnit ) |
34 | 104k | { |
35 | 104k | PaperInfo aInfo(ePaper); |
36 | 104k | Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM |
37 | 104k | return eUnit == MapUnit::Map100thMM |
38 | 104k | ? aRet |
39 | 104k | : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit)); |
40 | 104k | } |
41 | | |
42 | | /*------------------------------------------------------------------------ |
43 | | Description: Return the paper size of the printer, aligned to our |
44 | | own sizes. If no Printer is set in the system, A4 portrait |
45 | | will be delivered as the default paper size. |
46 | | ------------------------------------------------------------------------*/ |
47 | | |
48 | | //Is this method may be confused about the units it returns ? |
49 | | //Always returns TWIPS for known paper sizes or on failure. |
50 | | //But in the case of PAPER_USER paper and with a Printer with a mapmode set |
51 | | //will return in those printer units ? |
52 | | Size SvxPaperInfo::GetPaperSize( const Printer* pPrinter ) |
53 | 923 | { |
54 | 923 | if ( !IsValidPrinter(pPrinter) ) |
55 | 923 | return GetPaperSize( PAPER_A4 ); |
56 | 0 | const Paper ePaper = pPrinter->GetPaper(); |
57 | |
|
58 | 0 | if ( ePaper == PAPER_USER ) |
59 | 0 | { |
60 | | // Orientation not take into account, as the right size has |
61 | | // been already set by SV |
62 | 0 | Size aPaperSize = pPrinter->GetPaperSize(); |
63 | 0 | const Size aInvalidSize; |
64 | |
|
65 | 0 | if ( aPaperSize == aInvalidSize ) |
66 | 0 | return GetPaperSize(PAPER_A4); |
67 | 0 | const MapMode& aMap1 = pPrinter->GetMapMode(); |
68 | 0 | MapMode aMap2; |
69 | |
|
70 | 0 | if ( aMap1 == aMap2 ) |
71 | 0 | aPaperSize = |
72 | 0 | pPrinter->PixelToLogic( aPaperSize, MapMode( MapUnit::MapTwip ) ); |
73 | 0 | return aPaperSize; |
74 | 0 | } |
75 | | |
76 | 0 | const Orientation eOrient = pPrinter->GetOrientation(); |
77 | 0 | Size aSize( GetPaperSize( ePaper ) ); |
78 | | // for Landscape exchange the pages, has already been done by SV |
79 | 0 | if ( eOrient == Orientation::Landscape ) |
80 | 0 | Swap( aSize ); |
81 | 0 | return aSize; |
82 | 0 | } |
83 | | |
84 | | |
85 | | Paper SvxPaperInfo::GetSvxPaper( const Size &rSize, MapUnit eUnit ) |
86 | 0 | { |
87 | 0 | Size aSize(eUnit == MapUnit::Map100thMM ? rSize : OutputDevice::LogicToLogic(rSize, MapMode(eUnit), MapMode(MapUnit::Map100thMM))); |
88 | 0 | PaperInfo aInfo(aSize.Width(), aSize.Height()); |
89 | 0 | aInfo.doSloppyFit(); |
90 | 0 | return aInfo.getPaper(); |
91 | 0 | } |
92 | | |
93 | | |
94 | | tools::Long SvxPaperInfo::GetSloppyPaperDimension( tools::Long nSize ) |
95 | 77.5k | { |
96 | 77.5k | nSize = o3tl::convert(nSize, o3tl::Length::twip, o3tl::Length::mm100); |
97 | 77.5k | nSize = PaperInfo::sloppyFitPageDimension(nSize); |
98 | 77.5k | return o3tl::convert(nSize, o3tl::Length::mm100, o3tl::Length::twip); |
99 | 77.5k | } |
100 | | |
101 | | |
102 | | Size SvxPaperInfo::GetDefaultPaperSize( MapUnit eUnit ) |
103 | 232k | { |
104 | 232k | PaperInfo aInfo(PaperInfo::getSystemDefaultPaper()); |
105 | 232k | Size aRet(aInfo.getWidth(), aInfo.getHeight()); |
106 | 232k | return eUnit == MapUnit::Map100thMM |
107 | 232k | ? aRet |
108 | 232k | : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit)); |
109 | 232k | } |
110 | | |
111 | | /*------------------------------------------------------------------------ |
112 | | Description: String representation for the SV-defines of paper size |
113 | | ------------------------------------------------------------------------*/ |
114 | | |
115 | | OUString SvxPaperInfo::GetName( Paper ePaper ) |
116 | 0 | { |
117 | 0 | return Printer::GetPaperName( ePaper ); |
118 | 0 | } |
119 | | |
120 | | |
121 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |