1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_scfilt.hxx"
24 #include "xlpage.hxx"
25 #include <sfx2/printer.hxx>
26 #include <editeng/svxenum.hxx>
27 #include <editeng/paperinf.hxx>
28 #include <vcl/svapp.hxx>
29 #include "scitems.hxx"
30 #include <editeng/brshitem.hxx>
31 #include "global.hxx"
32 #include "xlconst.hxx"
33
34 // Paper size =================================================================
35
36 struct XclPaperSize
37 {
38 Paper mePaper; // SVX paper size identifier.
39 long mnWidth; // Paper width in twips.
40 long mnHeight; // Paper height in twips.
41 };
42
43 #define IN2TWIPS( v ) ((long)((v) * EXC_TWIPS_PER_INCH + 0.5))
44 #define MM2TWIPS( v ) ((long)((v) * EXC_TWIPS_PER_INCH / CM_PER_INCH / 10.0 + 0.5))
45
46 static const XclPaperSize pPaperSizeTable[] =
47 {
48 /* 0*/ { PAPER_USER, 0, 0 }, // undefined
49 { PAPER_LETTER, IN2TWIPS( 8.5 ), IN2TWIPS( 11 ) }, // Letter
50 { PAPER_USER, IN2TWIPS( 8.5 ), IN2TWIPS( 11 ) }, // Letter Small
51 { PAPER_TABLOID, IN2TWIPS( 11 ), IN2TWIPS( 17 ) }, // Tabloid
52 { PAPER_LEDGER, IN2TWIPS( 17 ), IN2TWIPS( 11 ) }, // Ledger
53 /* 5*/ { PAPER_LEGAL, IN2TWIPS( 8.5 ), IN2TWIPS( 14 ) }, // Legal
54 { PAPER_STATEMENT, IN2TWIPS( 5.5 ), IN2TWIPS( 8.5 ) }, // Statement
55 { PAPER_EXECUTIVE, IN2TWIPS( 7.25 ), IN2TWIPS( 10.5 ) }, // Executive
56 { PAPER_A3, MM2TWIPS( 297 ), MM2TWIPS( 420 ) }, // A3
57 { PAPER_A4, MM2TWIPS( 210 ), MM2TWIPS( 297 ) }, // A4
58 /* 10*/ { PAPER_USER, MM2TWIPS( 210 ), MM2TWIPS( 297 ) }, // A4 Small
59 { PAPER_A5, MM2TWIPS( 148 ), MM2TWIPS( 210 ) }, // A5
60 //See: https://wiki.openoffice.org/wiki/DefaultPaperSize comments
61 //near DMPAPER_B4 in vcl
62 //i.e.
63 //http://msdn.microsoft.com/en-us/library/bb241398.aspx makes the claim:
64 //xlPaperB4 12 B4 (250 mm x 354 mm)
65 //xlPaperB5 13 A5 (148 mm x 210 mm)
66 //but, a paper enum called B5 is surely not actually "A5", and furthermore
67 //the XlPaperSize enumeration otherwise follows the DMPAPER values
68 //http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx
69 //which has
70 //DMPAPER_B4 12 B4 (JIS) 250 x 354
71 //DMPAPER_B5 13 B5 (JIS) 182 x 257 mm
72 //which claim them to be the JIS sizes. Though that document then gives
73 //"B4 (JIS)" an *ISO* B4 size in the text, but
74 //http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf
75 //claims that the MS DMPAPER_B4 and DMPAPER_B5 truly are the JIS sizes
76 //which at least makes some sort of sense. (cmc)
77 { PAPER_B4_JIS, MM2TWIPS( 257 ), MM2TWIPS( 364 ) }, // B4 (JIS)
78 { PAPER_B5_JIS, MM2TWIPS( 182 ), MM2TWIPS( 257 ) }, // B5 (JIS)
79 { PAPER_USER, IN2TWIPS( 8.5 ), IN2TWIPS( 13 ) }, // Folio
80 /* 15*/ { PAPER_QUARTO, MM2TWIPS( 215 ), MM2TWIPS( 275 ) }, // Quarto
81 { PAPER_10x14, IN2TWIPS( 10 ), IN2TWIPS( 14 ) }, // 10x14
82 { PAPER_USER, IN2TWIPS( 11 ), IN2TWIPS( 17 ) }, // 11x17
83 { PAPER_USER, IN2TWIPS( 8.5 ), IN2TWIPS( 11 ) }, // Note
84 { PAPER_ENV_9, IN2TWIPS( 3.875 ), IN2TWIPS( 8.875 ) }, // Envelope #9
85 /* 20*/ { PAPER_ENV_10, IN2TWIPS( 4.125 ), IN2TWIPS( 9.5 ) }, // Envelope #10
86 { PAPER_ENV_11, IN2TWIPS( 4.5 ), IN2TWIPS( 10.375 ) }, // Envelope #11
87 { PAPER_ENV_12, IN2TWIPS( 4.75 ), IN2TWIPS( 11 ) }, // Envelope #12
88 { PAPER_ENV_14, IN2TWIPS( 5 ), IN2TWIPS( 11.5 ) }, // Envelope #14
89 { PAPER_C, IN2TWIPS( 17 ), IN2TWIPS( 22 ) }, // ANSI-C
90 /* 25*/ { PAPER_D, IN2TWIPS( 22 ), IN2TWIPS( 34 ) }, // ANSI-D
91 { PAPER_E, IN2TWIPS( 34 ), IN2TWIPS( 44 ) }, // ANSI-E
92 { PAPER_ENV_DL, MM2TWIPS( 110 ), MM2TWIPS( 220 ) }, // Envelope DL
93 { PAPER_ENV_C5, MM2TWIPS( 162 ), MM2TWIPS( 229 ) }, // Envelope C5
94 { PAPER_ENV_C3, MM2TWIPS( 324 ), MM2TWIPS( 458 ) }, // Envelope C3
95 /* 30*/ { PAPER_ENV_C4, MM2TWIPS( 229 ), MM2TWIPS( 324 ) }, // Envelope C4
96 { PAPER_ENV_C6, MM2TWIPS( 114 ), MM2TWIPS( 162 ) }, // Envelope C6
97 { PAPER_ENV_C65, MM2TWIPS( 114 ), MM2TWIPS( 229 ) }, // Envelope C65
98 { PAPER_B4_ISO, MM2TWIPS( 250 ), MM2TWIPS( 353 ) }, // B4 (ISO)
99 { PAPER_B5_ISO, MM2TWIPS( 176 ), MM2TWIPS( 250 ) }, // B5 (ISO)
100 /* 35*/ { PAPER_B6_ISO, MM2TWIPS( 125 ), MM2TWIPS( 176 ) }, // B6 (ISO)
101 { PAPER_ENV_ITALY, MM2TWIPS( 110 ), MM2TWIPS( 230 ) }, // Envelope Italy
102 { PAPER_ENV_MONARCH, IN2TWIPS( 3.875 ), IN2TWIPS( 7.5 ) }, // Envelope Monarch
103 { PAPER_ENV_PERSONAL, IN2TWIPS( 3.625 ), IN2TWIPS( 6.5 ) }, // 6 3/4 Envelope
104 { PAPER_FANFOLD_US, IN2TWIPS( 14.875 ), IN2TWIPS( 11 ) }, // US Std Fanfold
105 /* 40*/ { PAPER_FANFOLD_DE, IN2TWIPS( 8.5 ), IN2TWIPS( 12 ) }, // German Std Fanfold
106 { PAPER_FANFOLD_LEGAL_DE, IN2TWIPS( 8.5 ), IN2TWIPS( 13 ) }, // German Legal Fanfold
107 { PAPER_B4_ISO, MM2TWIPS( 250 ), MM2TWIPS( 353 ) }, // B4 (ISO)
108 { PAPER_POSTCARD_JP,MM2TWIPS( 100 ), MM2TWIPS( 148 ) }, // Japanese Postcard
109 { PAPER_9x11, IN2TWIPS( 9 ), IN2TWIPS( 11 ) }, // 9x11
110 /* 45*/ { PAPER_10x11, IN2TWIPS( 10 ), IN2TWIPS( 11 ) }, // 10x11
111 { PAPER_15x11, IN2TWIPS( 15 ), IN2TWIPS( 11 ) }, // 15x11
112 { PAPER_ENV_INVITE, MM2TWIPS( 220 ), MM2TWIPS( 220 ) }, // Envelope Invite
113 { PAPER_USER, 0, 0 }, // undefined
114 { PAPER_USER, 0, 0 }, // undefined
115 /* 50*/ { PAPER_USER, IN2TWIPS( 9.5 ), IN2TWIPS( 12 ) }, // Letter Extra
116 { PAPER_USER, IN2TWIPS( 9.5 ), IN2TWIPS( 15 ) }, // Legal Extra
117 { PAPER_USER, IN2TWIPS( 11.69 ), IN2TWIPS( 18 ) }, // Tabloid Extra
118 { PAPER_USER, MM2TWIPS( 235 ), MM2TWIPS( 322 ) }, // A4 Extra
119 { PAPER_USER, IN2TWIPS( 8.5 ), IN2TWIPS( 11 ) }, // Letter Transverse
120 /* 55*/ { PAPER_USER, MM2TWIPS( 210 ), MM2TWIPS( 297 ) }, // A4 Transverse
121 { PAPER_USER, IN2TWIPS( 9.5 ), IN2TWIPS( 12 ) }, // Letter Extra Transverse
122 { PAPER_A_PLUS, MM2TWIPS( 227 ), MM2TWIPS( 356 ) }, // Super A/A4
123 { PAPER_B_PLUS, MM2TWIPS( 305 ), MM2TWIPS( 487 ) }, // Super B/A3
124 { PAPER_LETTER_PLUS,IN2TWIPS( 8.5 ), IN2TWIPS( 12.69 ) }, // Letter Plus
125 /* 60*/ { PAPER_A4_PLUS, MM2TWIPS( 210 ), MM2TWIPS( 330 ) }, // A4 Plus
126 { PAPER_USER, MM2TWIPS( 148 ), MM2TWIPS( 210 ) }, // A5 Transverse
127 { PAPER_USER, MM2TWIPS( 182 ), MM2TWIPS( 257 ) }, // B5 (JIS) Transverse
128 { PAPER_USER, MM2TWIPS( 322 ), MM2TWIPS( 445 ) }, // A3 Extra
129 { PAPER_USER, MM2TWIPS( 174 ), MM2TWIPS( 235 ) }, // A5 Extra
130 /* 65*/ { PAPER_USER, MM2TWIPS( 201 ), MM2TWIPS( 276 ) }, // B5 (ISO) Extra
131 { PAPER_A2, MM2TWIPS( 420 ), MM2TWIPS( 594 ) }, // A2
132 { PAPER_USER, MM2TWIPS( 297 ), MM2TWIPS( 420 ) }, // A3 Transverse
133 { PAPER_USER, MM2TWIPS( 322 ), MM2TWIPS( 445 ) }, // A3 Extra Transverse
134 { PAPER_DOUBLEPOSTCARD_JP, MM2TWIPS( 200 ), MM2TWIPS( 148 ) }, // Double Japanese Postcard
135 /* 70*/ { PAPER_A6, MM2TWIPS( 105 ), MM2TWIPS( 148 ) }, // A6
136 { PAPER_USER, 0, 0 }, // undefined
137 { PAPER_USER, 0, 0 }, // undefined
138 { PAPER_USER, 0, 0 }, // undefined
139 { PAPER_USER, 0, 0 }, // undefined
140 /* 75*/ { PAPER_USER, IN2TWIPS( 11 ), IN2TWIPS( 8.5 ) }, // Letter Rotated
141 { PAPER_USER, MM2TWIPS( 420 ), MM2TWIPS( 297 ) }, // A3 Rotated
142 { PAPER_USER, MM2TWIPS( 297 ), MM2TWIPS( 210 ) }, // A4 Rotated
143 { PAPER_USER, MM2TWIPS( 210 ), MM2TWIPS( 148 ) }, // A5 Rotated
144 { PAPER_USER, MM2TWIPS( 364 ), MM2TWIPS( 257 ) }, // B4 (JIS) Rotated
145 /* 80*/ { PAPER_USER, MM2TWIPS( 257 ), MM2TWIPS( 182 ) }, // B5 (JIS) Rotated
146 { PAPER_USER, MM2TWIPS( 148 ), MM2TWIPS( 100 ) }, // Japanese Postcard Rotated
147 { PAPER_USER, MM2TWIPS( 148 ), MM2TWIPS( 200 ) }, // Double Japanese Postcard Rotated
148 { PAPER_USER, MM2TWIPS( 148 ), MM2TWIPS( 105 ) }, // A6 Rotated
149 { PAPER_USER, 0, 0 }, // undefined
150 /* 85*/ { PAPER_USER, 0, 0 }, // undefined
151 { PAPER_USER, 0, 0 }, // undefined
152 { PAPER_USER, 0, 0 }, // undefined
153 { PAPER_B6_JIS, MM2TWIPS( 128 ), MM2TWIPS( 182 ) }, // B6 (JIS)
154 { PAPER_USER, MM2TWIPS( 182 ), MM2TWIPS( 128 ) }, // B6 (JIS) Rotated
155 /* 90*/ { PAPER_12x11, IN2TWIPS( 12 ), IN2TWIPS( 11 ) } // 12x11
156 };
157
158 #undef IN2TWIPS
159 #undef MM2TWIPS
160
161 // Page settings ==============================================================
162
XclPageData()163 XclPageData::XclPageData()
164 {
165 SetDefaults();
166 }
167
~XclPageData()168 XclPageData::~XclPageData()
169 {
170 // SvxBrushItem incomplete in header
171 }
172
SetDefaults()173 void XclPageData::SetDefaults()
174 {
175 maHorPageBreaks.clear();
176 maVerPageBreaks.clear();
177 mxBrushItem.reset();
178 maHeader.Erase();
179 maFooter.Erase();
180 mfLeftMargin = mfRightMargin = XclTools::GetInchFromHmm( EXC_MARGIN_DEFAULT_LR );
181 mfTopMargin = mfBottomMargin = XclTools::GetInchFromHmm( EXC_MARGIN_DEFAULT_TB );
182 mfHeaderMargin = mfFooterMargin = XclTools::GetInchFromHmm( EXC_MARGIN_DEFAULT_HF );
183 mfHdrLeftMargin = mfHdrRightMargin = XclTools::GetInchFromHmm( EXC_MARGIN_DEFAULT_HLR );
184 mfFtrLeftMargin = mfFtrRightMargin = XclTools::GetInchFromHmm( EXC_MARGIN_DEFAULT_FLR );
185 mnPaperSize = EXC_PAPERSIZE_DEFAULT;
186 mnCopies = 1;
187 mnStartPage = 0;
188 mnScaling = 100;
189 mnFitToWidth = mnFitToHeight = 1;
190 mnHorPrintRes = mnVerPrintRes = 300;
191 mbValid = false;
192 mbPortrait = true;
193 mbPrintInRows = mbBlackWhite = mbDraftQuality = mbPrintNotes = mbManualStart = mbFitToPages = false;
194 mbHorCenter = mbVerCenter = mbPrintHeadings = mbPrintGrid = false;
195 }
196
GetScPaperSize() const197 Size XclPageData::GetScPaperSize() const
198 {
199 const XclPaperSize* pEntry = pPaperSizeTable;
200 if( mnPaperSize < STATIC_ARRAY_SIZE( pPaperSizeTable ) )
201 pEntry += mnPaperSize;
202
203 Size aSize;
204 if( pEntry->mePaper == PAPER_USER )
205 aSize = Size( pEntry->mnWidth, pEntry->mnHeight );
206 else
207 aSize = SvxPaperInfo::GetPaperSize( pEntry->mePaper );
208
209 // invalid size -> back to default
210 if( !aSize.Width() || !aSize.Height() )
211 aSize = SvxPaperInfo::GetDefaultPaperSize();
212
213 if( !mbPortrait )
214 ::std::swap( aSize.Width(), aSize.Height() );
215
216 return aSize;
217 }
218
SetScPaperSize(const Size & rSize,bool bPortrait)219 void XclPageData::SetScPaperSize( const Size& rSize, bool bPortrait )
220 {
221 mbPortrait = bPortrait;
222 mnPaperSize = 0;
223 long nWidth = bPortrait ? rSize.Width() : rSize.Height();
224 long nHeight = bPortrait ? rSize.Height() : rSize.Width();
225 long nMaxWDiff = 80;
226 long nMaxHDiff = 50;
227 for( const XclPaperSize* pEntry = pPaperSizeTable; pEntry != STATIC_ARRAY_END( pPaperSizeTable ); ++pEntry )
228 {
229 long nWDiff = Abs( pEntry->mnWidth - nWidth );
230 long nHDiff = Abs( pEntry->mnHeight - nHeight );
231 if( ((nWDiff <= nMaxWDiff) && (nHDiff < nMaxHDiff)) ||
232 ((nWDiff < nMaxWDiff) && (nHDiff <= nMaxHDiff)) )
233 {
234 mnPaperSize = static_cast< sal_uInt16 >( pEntry - pPaperSizeTable );
235 nMaxWDiff = nWDiff;
236 nMaxHDiff = nHDiff;
237 }
238 }
239 }
240
241 /* vim: set noet sw=4 ts=4: */
242