LibreOffice Module sc (master) 1
xlpage.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 <xlpage.hxx>
21#include <xltools.hxx>
22#include <editeng/paperinf.hxx>
24#include <sal/macros.h>
25#include <editeng/brushitem.hxx>
26
27namespace{
28
29struct XclPaperSize
30{
31 Paper mePaper;
34};
35
36constexpr tools::Long in2twips(double n_inch)
37{
39}
40constexpr tools::Long mm2twips(double n_mm)
41{
43}
44constexpr tools::Long twips2mm(tools::Long n_twips)
45{
47}
48
49// see ApiPaperSize spPaperSizeTable in filter and aDinTab in i18nutil
50constexpr XclPaperSize pPaperSizeTable[] =
51{
52/* 0*/ { PAPER_USER, 0, 0 }, // undefined
53 { PAPER_LETTER, in2twips( 8.5 ), in2twips( 11 ) }, // Letter
54 { PAPER_USER, in2twips( 8.5 ), in2twips( 11 ) }, // Letter Small
55 { PAPER_TABLOID, in2twips( 11 ), in2twips( 17 ) }, // Tabloid
56 { PAPER_LEDGER, in2twips( 17 ), in2twips( 11 ) }, // Ledger
57/* 5*/ { PAPER_LEGAL, in2twips( 8.5 ), in2twips( 14 ) }, // Legal
58 { PAPER_STATEMENT, in2twips( 5.5 ), in2twips( 8.5 ) }, // Statement
59 { PAPER_EXECUTIVE, in2twips( 7.25 ), in2twips( 10.5 ) }, // Executive
60 { PAPER_A3, mm2twips( 297 ), mm2twips( 420 ) }, // A3
61 { PAPER_A4, mm2twips( 210 ), mm2twips( 297 ) }, // A4
62/* 10*/ { PAPER_USER, mm2twips( 210 ), mm2twips( 297 ) }, // A4 Small
63 { PAPER_A5, mm2twips( 148 ), mm2twips( 210 ) }, // A5
64 /* for JIS vs ISO B confusion see:
65 https://docs.microsoft.com/en-us/windows/win32/intl/paper-sizes
66 http://wiki.openoffice.org/wiki/DefaultPaperSize comments
67 http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf */
68 { PAPER_B4_JIS, mm2twips( 257 ), mm2twips( 364 ) }, // B4 (JIS)
69 { PAPER_B5_JIS, mm2twips( 182 ), mm2twips( 257 ) }, // B5 (JIS)
70 { PAPER_USER, in2twips( 8.5 ), in2twips( 13 ) }, // Folio
71/* 15*/ { PAPER_QUARTO, mm2twips( 215 ), mm2twips( 275 ) }, // Quarto
72 { PAPER_10x14, in2twips( 10 ), in2twips( 14 ) }, // 10x14
73 { PAPER_USER, in2twips( 11 ), in2twips( 17 ) }, // 11x17
74 { PAPER_USER, in2twips( 8.5 ), in2twips( 11 ) }, // Note
75 { PAPER_ENV_9, in2twips( 3.875 ), in2twips( 8.875 ) }, // Envelope #9
76/* 20*/ { PAPER_ENV_10, in2twips( 4.125 ), in2twips( 9.5 ) }, // Envelope #10
77 { PAPER_ENV_11, in2twips( 4.5 ), in2twips( 10.375 ) }, // Envelope #11
78 { PAPER_ENV_12, in2twips( 4.75 ), in2twips( 11 ) }, // Envelope #12
79 { PAPER_ENV_14, in2twips( 5 ), in2twips( 11.5 ) }, // Envelope #14
80 { PAPER_C, in2twips( 17 ), in2twips( 22 ) }, // ANSI-C
81/* 25*/ { PAPER_D, in2twips( 22 ), in2twips( 34 ) }, // ANSI-D
82 { PAPER_E, in2twips( 34 ), in2twips( 44 ) }, // ANSI-E
83 { PAPER_ENV_DL, mm2twips( 110 ), mm2twips( 220 ) }, // Envelope DL
84 { PAPER_ENV_C5, mm2twips( 162 ), mm2twips( 229 ) }, // Envelope C5
85 { PAPER_ENV_C3, mm2twips( 324 ), mm2twips( 458 ) }, // Envelope C3
86/* 30*/ { PAPER_ENV_C4, mm2twips( 229 ), mm2twips( 324 ) }, // Envelope C4
87 { PAPER_ENV_C6, mm2twips( 114 ), mm2twips( 162 ) }, // Envelope C6
88 { PAPER_ENV_C65, mm2twips( 114 ), mm2twips( 229 ) }, // Envelope C65
89 { PAPER_B4_ISO, mm2twips( 250 ), mm2twips( 353 ) }, // B4 (ISO)
90 { PAPER_B5_ISO, mm2twips( 176 ), mm2twips( 250 ) }, // B5 (ISO)
91/* 35*/ { PAPER_B6_ISO, mm2twips( 125 ), mm2twips( 176 ) }, // B6 (ISO)
92 { PAPER_ENV_ITALY, mm2twips( 110 ), mm2twips( 230 ) }, // Envelope Italy
93 { PAPER_ENV_MONARCH, in2twips( 3.875 ), in2twips( 7.5 ) }, // Envelope Monarch
94 { PAPER_ENV_PERSONAL, in2twips( 3.625 ), in2twips( 6.5 ) }, // 6 3/4 Envelope
95 { PAPER_FANFOLD_US, in2twips( 14.875 ), in2twips( 11 ) }, // US Std Fanfold
96/* 40*/ { PAPER_FANFOLD_DE, in2twips( 8.5 ), in2twips( 12 ) }, // German Std Fanfold
97 { PAPER_FANFOLD_LEGAL_DE, in2twips( 8.5 ), in2twips( 13 ) }, // German Legal Fanfold
98 { PAPER_B4_ISO, mm2twips( 250 ), mm2twips( 353 ) }, // B4 (ISO)
99 { PAPER_POSTCARD_JP,mm2twips( 100 ), mm2twips( 148 ) }, // Japanese Postcard
100 { PAPER_9x11, in2twips( 9 ), in2twips( 11 ) }, // 9x11
101/* 45*/ { PAPER_10x11, in2twips( 10 ), in2twips( 11 ) }, // 10x11
102 { PAPER_15x11, in2twips( 15 ), in2twips( 11 ) }, // 15x11
103 { PAPER_ENV_INVITE, mm2twips( 220 ), mm2twips( 220 ) }, // Envelope Invite
104 { PAPER_USER, 0, 0 }, // undefined
105 { PAPER_USER, 0, 0 }, // undefined
106 /* See: https://docs.microsoft.com/en-us/windows/win32/intl/paper-sizes */
107/* 50*/ { PAPER_USER, in2twips( 9.5 ), in2twips( 12 ) }, // Letter Extra
108 { PAPER_USER, in2twips( 9.5 ), in2twips( 15 ) }, // Legal Extra
109 { PAPER_USER, in2twips( 11.69 ), in2twips( 18 ) }, // Tabloid Extra
110 { PAPER_USER, mm2twips( 235 ), mm2twips( 322 ) }, // A4 Extra
111 { PAPER_USER, in2twips( 8.5 ), in2twips( 11 ) }, // Letter Transverse
112/* 55*/ { PAPER_USER, mm2twips( 210 ), mm2twips( 297 ) }, // A4 Transverse
113 { PAPER_USER, in2twips( 9.5 ), in2twips( 12 ) }, // Letter Extra Transverse
114 { PAPER_A_PLUS, mm2twips( 227 ), mm2twips( 356 ) }, // Super A/A4
115 { PAPER_B_PLUS, mm2twips( 305 ), mm2twips( 487 ) }, // Super B/A3
116 { PAPER_LETTER_PLUS,in2twips( 8.5 ), in2twips( 12.69 ) }, // Letter Plus
117/* 60*/ { PAPER_A4_PLUS, mm2twips( 210 ), mm2twips( 330 ) }, // A4 Plus
118 { PAPER_USER, mm2twips( 148 ), mm2twips( 210 ) }, // A5 Transverse
119 { PAPER_USER, mm2twips( 182 ), mm2twips( 257 ) }, // B5 (JIS) Transverse
120 { PAPER_USER, mm2twips( 322 ), mm2twips( 445 ) }, // A3 Extra
121 { PAPER_USER, mm2twips( 174 ), mm2twips( 235 ) }, // A5 Extra
122/* 65*/ { PAPER_USER, mm2twips( 201 ), mm2twips( 276 ) }, // B5 (ISO) Extra
123 { PAPER_A2, mm2twips( 420 ), mm2twips( 594 ) }, // A2
124 { PAPER_USER, mm2twips( 297 ), mm2twips( 420 ) }, // A3 Transverse
125 { PAPER_USER, mm2twips( 322 ), mm2twips( 445 ) }, // A3 Extra Transverse
126 { PAPER_DOUBLEPOSTCARD_JP, mm2twips( 200 ), mm2twips( 148 ) }, // Double Japanese Postcard
127/* 70*/ { PAPER_A6, mm2twips( 105 ), mm2twips( 148 ) }, // A6
128 { PAPER_USER, 0, 0 }, // Japanese Envelope Kaku #2
129 { PAPER_USER, 0, 0 }, // Japanese Envelope Kaku #3
130 { PAPER_USER, 0, 0 }, // Japanese Envelope Chou #3
131 { PAPER_USER, 0, 0 }, // Japanese Envelope Chou #4
132/* 75*/ { PAPER_USER, in2twips( 11 ), in2twips( 8.5 ) }, // Letter Rotated
133 { PAPER_USER, mm2twips( 420 ), mm2twips( 297 ) }, // A3 Rotated
134 { PAPER_USER, mm2twips( 297 ), mm2twips( 210 ) }, // A4 Rotated
135 { PAPER_USER, mm2twips( 210 ), mm2twips( 148 ) }, // A5 Rotated
136 { PAPER_USER, mm2twips( 364 ), mm2twips( 257 ) }, // B4 (JIS) Rotated
137/* 80*/ { PAPER_USER, mm2twips( 257 ), mm2twips( 182 ) }, // B5 (JIS) Rotated
138 { PAPER_USER, mm2twips( 148 ), mm2twips( 100 ) }, // Japanese Postcard Rotated
139 { PAPER_USER, mm2twips( 148 ), mm2twips( 200 ) }, // Double Japanese Postcard Rotated
140 { PAPER_USER, mm2twips( 148 ), mm2twips( 105 ) }, // A6 Rotated
141 { PAPER_USER, 0, 0 }, // Japanese Envelope Kaku #2 Rotated
142/* 85*/ { PAPER_USER, 0, 0 }, // Japanese Envelope Kaku #3 Rotated
143 { PAPER_USER, 0, 0 }, // Japanese Envelope Chou #3 Rotated
144 { PAPER_USER, 0, 0 }, // Japanese Envelope Chou #4 Rotated
145 { PAPER_B6_JIS, mm2twips( 128 ), mm2twips( 182 ) }, // B6 (JIS)
146 { PAPER_USER, mm2twips( 182 ), mm2twips( 128 ) }, // B6 (JIS) Rotated
147/* 90*/ { PAPER_12x11, in2twips( 12 ), in2twips( 11 ) } // 12x11
148};
149
150} //namespace
151
152// Page settings ==============================================================
153
155{
156 SetDefaults();
157}
158
160{
161 // SvxBrushItem incomplete in header
162}
163
165{
166 maHorPageBreaks.clear();
167 maVerPageBreaks.clear();
168 mxBrushItem.reset();
169 maHeader.clear();
170 maFooter.clear();
171 maHeaderEven.clear();
172 maFooterEven.clear();
179 mnPaperWidth = 0;
180 mnPaperHeight = 0;
181 mnCopies = 1;
182 mnStartPage = 0;
183 mnScaling = 100;
186 mbUseEvenHF = mbUseFirstHF = false;
187 mbValid = false;
188 mbPortrait = true;
191}
192
194{
195 const XclPaperSize* pEntry = pPaperSizeTable;
196 if( mnPaperSize < SAL_N_ELEMENTS( pPaperSizeTable ) )
197 pEntry += mnPaperSize;
198
199 Size aSize;
200 if( pEntry->mePaper == PAPER_USER )
201 aSize = Size( pEntry->mnWidth, pEntry->mnHeight );
202 else
203 aSize = SvxPaperInfo::GetPaperSize( pEntry->mePaper );
204
205 // invalid size -> back to default
206 if( !aSize.Width() || !aSize.Height() )
208
209 if( !mbPortrait )
210 {
211 // swap width and height
212 tools::Long n = aSize.Width();
213 aSize.setWidth(aSize.Height());
214 aSize.setHeight(n);
215 }
216
217 return aSize;
218}
219
220void XclPageData::SetScPaperSize( const Size& rSize, bool bPortrait, bool bStrictSize )
221{
222 mbPortrait = bPortrait;
223 mnPaperSize = 0;
224 tools::Long nWidth = bPortrait ? rSize.Width() : rSize.Height();
225 tools::Long nHeight = bPortrait ? rSize.Height() : rSize.Width();
226 tools::Long nMaxWDiff = 80;
227 tools::Long nMaxHDiff = 50;
228
229 mnPaperWidth = twips2mm( nWidth );
230 mnPaperHeight = twips2mm( nHeight );
231 if( bStrictSize )
232 {
233 nMaxWDiff = 5;
234 nMaxHDiff = 5;
236 }
237 else
238 {
240 }
241
242 for( const auto &rEntry : pPaperSizeTable)
243 {
244 tools::Long nWDiff = std::abs( rEntry.mnWidth - nWidth );
245 tools::Long nHDiff = std::abs( rEntry.mnHeight - nHeight );
246 if( ((nWDiff <= nMaxWDiff) && (nHDiff < nMaxHDiff)) ||
247 ((nWDiff < nMaxWDiff) && (nHDiff <= nMaxHDiff)) )
248 {
249 sal_uInt16 nIndex = static_cast< sal_uInt16 >( &rEntry - pPaperSizeTable );
251 if( bStrictSize )
253
254 nMaxWDiff = nWDiff;
255 nMaxHDiff = nHDiff;
256 }
257 }
258 if( !bStrictSize )
259 SetScPaperSize( rSize, bPortrait, true );
260}
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
static Size GetDefaultPaperSize(MapUnit eUnit=MapUnit::MapTwip)
static Size GetPaperSize(Paper ePaper, MapUnit eUnit=MapUnit::MapTwip)
static double GetInchFromHmm(sal_Int32 nHmm)
Returns the length in inches calculated from a length in 1/100 mm.
Definition: xltools.cxx:292
sal_Int32 nIndex
sal_Int64 n
#define SAL_N_ELEMENTS(arr)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
long Long
Paper
PAPER_QUARTO
PAPER_ENV_C3
PAPER_ENV_9
PAPER_ENV_MONARCH
PAPER_POSTCARD_JP
PAPER_LETTER
PAPER_ENV_DL
PAPER_ENV_12
PAPER_ENV_11
PAPER_ENV_C4
PAPER_ENV_10
PAPER_A5
PAPER_B5_JIS
PAPER_A4
PAPER_ENV_PERSONAL
PAPER_LETTER_PLUS
PAPER_ENV_14
PAPER_A4_PLUS
PAPER_10x11
PAPER_B_PLUS
PAPER_USER
PAPER_B6_ISO
PAPER_B5_ISO
PAPER_DOUBLEPOSTCARD_JP
PAPER_FANFOLD_US
PAPER_STATEMENT
PAPER_A3
PAPER_LEGAL
PAPER_10x14
PAPER_B6_JIS
PAPER_9x11
PAPER_FANFOLD_DE
PAPER_E
PAPER_A_PLUS
PAPER_EXECUTIVE
PAPER_A6
PAPER_D
PAPER_15x11
PAPER_TABLOID
PAPER_ENV_ITALY
PAPER_B4_ISO
PAPER_ENV_C65
PAPER_ENV_C6
PAPER_ENV_C5
PAPER_A2
PAPER_C
PAPER_B4_JIS
PAPER_12x11
PAPER_ENV_INVITE
PAPER_FANFOLD_LEGAL_DE
PAPER_LEDGER
double mnWidth
double mnHeight
sal_uInt16 mnPaperSize
Right margin to footer.
Definition: xlpage.hxx:128
sal_uInt16 mnVerPrintRes
Horizontal printing resolution.
Definition: xlpage.hxx:138
double mfHeaderMargin
Bottom margin in inches.
Definition: xlpage.hxx:122
sal_uInt16 mnScaling
Start page number.
Definition: xlpage.hxx:134
bool mbBlackWhite
true = in rows; false = in columns.
Definition: xlpage.hxx:144
SvxBrushItemPtr mxBrushItem
Vertical page breaks.
Definition: xlpage.hxx:111
sal_uInt16 mnPaperHeight
Paper Width in mm.
Definition: xlpage.hxx:131
bool mbUseEvenHF
Vertical printing resolution.
Definition: xlpage.hxx:139
bool mbPrintHeadings
true = centered vertically; false = top aligned.
Definition: xlpage.hxx:151
bool mbManualStart
true = print notes.
Definition: xlpage.hxx:147
ScfUInt16Vec maHorPageBreaks
Definition: xlpage.hxx:109
OUString maFooterEven
Excel header string for even pages (empty = off).
Definition: xlpage.hxx:115
sal_uInt16 mnFitToHeight
Fit to number of pages in width.
Definition: xlpage.hxx:136
double mfRightMargin
Left margin in inches.
Definition: xlpage.hxx:119
bool mbPortrait
false = some of the values are not valid.
Definition: xlpage.hxx:142
bool mbVerCenter
true = centered horizontally; false = left aligned.
Definition: xlpage.hxx:150
sal_uInt16 mnStrictPaperSize
Index into paper size table.
Definition: xlpage.hxx:129
void SetDefaults()
Sets Excel default page settings.
Definition: xlpage.cxx:164
double mfFooterMargin
Margin main page to header.
Definition: xlpage.hxx:123
bool mbValid
True = use maHeaderFirst/maFooterFirst.
Definition: xlpage.hxx:141
double mfFtrRightMargin
Left margin to footer.
Definition: xlpage.hxx:127
~XclPageData()
Definition: xlpage.cxx:159
XclPageData()
true = print grid lines.
Definition: xlpage.cxx:154
bool mbDraftQuality
true = black/white; false = colors.
Definition: xlpage.hxx:145
OUString maFooter
Excel header string (empty = off).
Definition: xlpage.hxx:113
bool mbPrintGrid
true = print column and row headings.
Definition: xlpage.hxx:152
sal_uInt16 mnFitToWidth
Scaling in percent.
Definition: xlpage.hxx:135
bool mbUseFirstHF
True = use maHeaderEven/maFooterEven.
Definition: xlpage.hxx:140
double mfHdrRightMargin
Left margin to header.
Definition: xlpage.hxx:125
sal_uInt16 mnPaperWidth
Same as papersize - but for ooxml (considering stricter dimensions)
Definition: xlpage.hxx:130
OUString maHeaderEven
Excel footer string (empty = off).
Definition: xlpage.hxx:114
void SetScPaperSize(const Size &rSize, bool bPortrait, bool bStrict=false)
Sets the Excel paper size index and paper orientation from Calc paper size (twips).
Definition: xlpage.cxx:220
sal_uInt16 mnCopies
Paper Height in mm.
Definition: xlpage.hxx:132
double mfBottomMargin
Top margin in inches.
Definition: xlpage.hxx:121
bool mbHorCenter
true = fit to pages; false = scale in percent.
Definition: xlpage.hxx:149
sal_uInt16 mnHorPrintRes
Fit to number of pages in height.
Definition: xlpage.hxx:137
bool mbPrintNotes
true = draft; false = default quality.
Definition: xlpage.hxx:146
double mfHdrLeftMargin
Margin main page to footer.
Definition: xlpage.hxx:124
ScfUInt16Vec maVerPageBreaks
Horizontal page breaks.
Definition: xlpage.hxx:110
Size GetScPaperSize() const
Returns the real paper size (twips) from the paper size index and paper orientation.
Definition: xlpage.cxx:193
double mfTopMargin
Right margin in inches.
Definition: xlpage.hxx:120
double mfFtrLeftMargin
Right margin to header.
Definition: xlpage.hxx:126
bool mbFitToPages
true = mnStartPage valid; false = automatic.
Definition: xlpage.hxx:148
bool mbPrintInRows
true = portrait; false = landscape.
Definition: xlpage.hxx:143
OUString maHeader
Background bitmap.
Definition: xlpage.hxx:112
sal_uInt16 mnStartPage
Number of copies.
Definition: xlpage.hxx:133
double mfLeftMargin
Excel footer string for first page (empty = off).
Definition: xlpage.hxx:118
const sal_Int32 EXC_MARGIN_DEFAULT_TB
Left/right default margin in 1/100mm.
Definition: xlpage.hxx:56
const sal_Int32 EXC_MARGIN_DEFAULT_LR
Definition: xlpage.hxx:55
const sal_uInt16 EXC_PAPERSIZE_DEFAULT
Definition: xlpage.hxx:93
const sal_uInt16 EXC_PAPERSIZE_USER
Definition: xlpage.hxx:94
const sal_Int32 EXC_MARGIN_DEFAULT_HF
Top/bottom default margin in 1/100mm.
Definition: xlpage.hxx:57
const sal_Int32 EXC_MARGIN_DEFAULT_FLR
Left/right header default margin in 1/100mm.
Definition: xlpage.hxx:59
const sal_Int32 EXC_MARGIN_DEFAULT_HLR
Header/footer default margin in 1/100mm.
Definition: xlpage.hxx:58