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