LibreOffice Module editeng (master) 1
paperinf.cxx
Go to the documentation of this file.
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
27static bool IsValidPrinter( const Printer* pPtr )
28{
29 return !pPtr->GetName().isEmpty();
30}
31
32
34{
35 PaperInfo aInfo(ePaper);
36 Size aRet(aInfo.getWidth(), aInfo.getHeight()); // in 100thMM
37 return eUnit == MapUnit::Map100thMM
38 ? aRet
39 : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit));
40}
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 ?
53{
54 if ( !IsValidPrinter(pPrinter) )
55 return GetPaperSize( PAPER_A4 );
56 const Paper ePaper = pPrinter->GetPaper();
57
58 if ( ePaper == PAPER_USER )
59 {
60 // Orientation not take into account, as the right size has
61 // been already set by SV
62 Size aPaperSize = pPrinter->GetPaperSize();
63 const Size aInvalidSize;
64
65 if ( aPaperSize == aInvalidSize )
66 return GetPaperSize(PAPER_A4);
67 const MapMode& aMap1 = pPrinter->GetMapMode();
68 MapMode aMap2;
69
70 if ( aMap1 == aMap2 )
71 aPaperSize =
72 pPrinter->PixelToLogic( aPaperSize, MapMode( MapUnit::MapTwip ) );
73 return aPaperSize;
74 }
75
76 const Orientation eOrient = pPrinter->GetOrientation();
77 Size aSize( GetPaperSize( ePaper ) );
78 // for Landscape exchange the pages, has already been done by SV
79 if ( eOrient == Orientation::Landscape )
80 Swap( aSize );
81 return aSize;
82}
83
84
86{
87 Size aSize(eUnit == MapUnit::Map100thMM ? rSize : OutputDevice::LogicToLogic(rSize, MapMode(eUnit), MapMode(MapUnit::Map100thMM)));
88 PaperInfo aInfo(aSize.Width(), aSize.Height());
89 aInfo.doSloppyFit();
90 return aInfo.getPaper();
91}
92
93
95{
99}
100
101
103{
105 Size aRet(aInfo.getWidth(), aInfo.getHeight());
106 return eUnit == MapUnit::Map100thMM
107 ? aRet
108 : OutputDevice::LogicToLogic(aRet, MapMode(MapUnit::Map100thMM), MapMode(eUnit));
109}
110
111/*------------------------------------------------------------------------
112 Description: String representation for the SV-defines of paper size
113------------------------------------------------------------------------*/
114
115OUString SvxPaperInfo::GetName( Paper ePaper )
116{
117 return Printer::GetPaperName( ePaper );
118}
119
120
121/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const MapMode & GetMapMode() const
static PaperInfo getSystemDefaultPaper()
tools::Long getWidth() const
Paper getPaper() const
static tools::Long sloppyFitPageDimension(tools::Long nDimension)
void doSloppyFit(bool bAlsoTryRotated=false)
tools::Long getHeight() const
Size GetPaperSize() const
static OUString GetPaperName(Paper ePaper)
const OUString & GetName() const
Orientation GetOrientation() const
Paper GetPaper() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static OUString GetName(Paper ePaper)
Definition: paperinf.cxx:115
static Size GetDefaultPaperSize(MapUnit eUnit=MapUnit::MapTwip)
Definition: paperinf.cxx:102
static Paper GetSvxPaper(const Size &rSize, MapUnit eUnit)
Definition: paperinf.cxx:85
static tools::Long GetSloppyPaperDimension(tools::Long nSize)
Definition: paperinf.cxx:94
static Size GetPaperSize(Paper ePaper, MapUnit eUnit=MapUnit::MapTwip)
Definition: paperinf.cxx:33
MapUnit
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
long Long
Paper
PAPER_A4
PAPER_USER
static bool IsValidPrinter(const Printer *pPtr)
Definition: paperinf.cxx:27
Size & Swap(Size &rSize)
Definition: paperinf.hxx:49
Orientation