1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*ca5ec200SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*ca5ec200SAndrew Rist * distributed with this work for additional information
6*ca5ec200SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*ca5ec200SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist * with the License. You may obtain a copy of the License at
10*ca5ec200SAndrew Rist *
11*ca5ec200SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist *
13*ca5ec200SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist * KIND, either express or implied. See the License for the
17*ca5ec200SAndrew Rist * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist * under the License.
19*ca5ec200SAndrew Rist *
20*ca5ec200SAndrew Rist *************************************************************/
21*ca5ec200SAndrew Rist
22*ca5ec200SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "oox/xls/pagesettings.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <algorithm>
27cdf0e10cSrcweir #include <set>
28cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
29cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
31cdf0e10cSrcweir #include <com/sun/star/style/GraphicLocation.hpp>
32cdf0e10cSrcweir #include <com/sun/star/text/FilenameDisplayFormat.hpp>
33cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
34cdf0e10cSrcweir #include <com/sun/star/text/XTextContent.hpp>
35cdf0e10cSrcweir #include <com/sun/star/text/XTextCursor.hpp>
36cdf0e10cSrcweir #include <rtl/strbuf.hxx>
37cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
38cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
39cdf0e10cSrcweir #include "oox/helper/attributelist.hxx"
40cdf0e10cSrcweir #include "oox/helper/graphichelper.hxx"
41cdf0e10cSrcweir #include "oox/helper/propertymap.hxx"
42cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
43cdf0e10cSrcweir #include "oox/xls/biffinputstream.hxx"
44cdf0e10cSrcweir #include "oox/xls/excelhandlers.hxx"
45cdf0e10cSrcweir #include "oox/xls/stylesbuffer.hxx"
46cdf0e10cSrcweir #include "oox/xls/unitconverter.hxx"
47cdf0e10cSrcweir
48cdf0e10cSrcweir namespace oox {
49cdf0e10cSrcweir namespace xls {
50cdf0e10cSrcweir
51cdf0e10cSrcweir // ============================================================================
52cdf0e10cSrcweir
53cdf0e10cSrcweir using namespace ::com::sun::star::awt;
54cdf0e10cSrcweir using namespace ::com::sun::star::container;
55cdf0e10cSrcweir using namespace ::com::sun::star::lang;
56cdf0e10cSrcweir using namespace ::com::sun::star::sheet;
57cdf0e10cSrcweir using namespace ::com::sun::star::style;
58cdf0e10cSrcweir using namespace ::com::sun::star::text;
59cdf0e10cSrcweir using namespace ::com::sun::star::uno;
60cdf0e10cSrcweir
61cdf0e10cSrcweir using ::oox::core::Relations;
62cdf0e10cSrcweir using ::rtl::OString;
63cdf0e10cSrcweir using ::rtl::OStringBuffer;
64cdf0e10cSrcweir using ::rtl::OUString;
65cdf0e10cSrcweir using ::rtl::OUStringBuffer;
66cdf0e10cSrcweir
67cdf0e10cSrcweir // ============================================================================
68cdf0e10cSrcweir
69cdf0e10cSrcweir namespace {
70cdf0e10cSrcweir
71cdf0e10cSrcweir const double OOX_MARGIN_DEFAULT_LR = 0.748; /// Left/right default margin in inches.
72cdf0e10cSrcweir const double OOX_MARGIN_DEFAULT_TB = 0.984; /// Top/bottom default margin in inches.
73cdf0e10cSrcweir const double OOX_MARGIN_DEFAULT_HF = 0.512; /// Header/footer default margin in inches.
74cdf0e10cSrcweir
75cdf0e10cSrcweir const sal_uInt16 BIFF12_PRINTOPT_HORCENTER = 0x0001;
76cdf0e10cSrcweir const sal_uInt16 BIFF12_PRINTOPT_VERCENTER = 0x0002;
77cdf0e10cSrcweir const sal_uInt16 BIFF12_PRINTOPT_PRINTHEADING = 0x0004;
78cdf0e10cSrcweir const sal_uInt16 BIFF12_PRINTOPT_PRINTGRID = 0x0008;
79cdf0e10cSrcweir
80cdf0e10cSrcweir const sal_uInt16 BIFF12_HEADERFOOTER_DIFFEVEN = 0x0001;
81cdf0e10cSrcweir const sal_uInt16 BIFF12_HEADERFOOTER_DIFFFIRST = 0x0002;
82cdf0e10cSrcweir const sal_uInt16 BIFF12_HEADERFOOTER_SCALEDOC = 0x0004;
83cdf0e10cSrcweir const sal_uInt16 BIFF12_HEADERFOOTER_ALIGNMARGIN = 0x0008;
84cdf0e10cSrcweir
85cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_INROWS = 0x0001;
86cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_LANDSCAPE = 0x0002;
87cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_INVALID = 0x0004;
88cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_BLACKWHITE = 0x0008;
89cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_DRAFTQUALITY = 0x0010;
90cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_PRINTNOTES = 0x0020;
91cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_DEFAULTORIENT = 0x0040;
92cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_USEFIRSTPAGE = 0x0080;
93cdf0e10cSrcweir const sal_uInt16 BIFF12_PAGESETUP_NOTES_END = 0x0100; // different to BIFF flag
94cdf0e10cSrcweir
95cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTPAGESETUP_LANDSCAPE = 0x0001;
96cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTPAGESETUP_INVALID = 0x0002;
97cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTPAGESETUP_BLACKWHITE = 0x0004;
98cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTPAGESETUP_DEFAULTORIENT= 0x0008;
99cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTPAGESETUP_USEFIRSTPAGE = 0x0010;
100cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTPAGESETUP_DRAFTQUALITY = 0x0020;
101cdf0e10cSrcweir
102cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_INROWS = 0x0001;
103cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_PORTRAIT = 0x0002;
104cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_INVALID = 0x0004;
105cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_BLACKWHITE = 0x0008;
106cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_DRAFTQUALITY = 0x0010;
107cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_PRINTNOTES = 0x0020;
108cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_DEFAULTORIENT = 0x0040;
109cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_USEFIRSTPAGE = 0x0080;
110cdf0e10cSrcweir const sal_uInt16 BIFF_PAGESETUP_NOTES_END = 0x0200;
111cdf0e10cSrcweir
112cdf0e10cSrcweir } // namespace
113cdf0e10cSrcweir
114cdf0e10cSrcweir // ============================================================================
115cdf0e10cSrcweir
PageSettingsModel()116cdf0e10cSrcweir PageSettingsModel::PageSettingsModel() :
117cdf0e10cSrcweir mfLeftMargin( OOX_MARGIN_DEFAULT_LR ),
118cdf0e10cSrcweir mfRightMargin( OOX_MARGIN_DEFAULT_LR ),
119cdf0e10cSrcweir mfTopMargin( OOX_MARGIN_DEFAULT_TB ),
120cdf0e10cSrcweir mfBottomMargin( OOX_MARGIN_DEFAULT_TB ),
121cdf0e10cSrcweir mfHeaderMargin( OOX_MARGIN_DEFAULT_HF ),
122cdf0e10cSrcweir mfFooterMargin( OOX_MARGIN_DEFAULT_HF ),
123cdf0e10cSrcweir mnPaperSize( 1 ),
124cdf0e10cSrcweir mnCopies( 1 ),
125cdf0e10cSrcweir mnScale( 100 ),
126cdf0e10cSrcweir mnFirstPage( 1 ),
127cdf0e10cSrcweir mnFitToWidth( 1 ),
128cdf0e10cSrcweir mnFitToHeight( 1 ),
129cdf0e10cSrcweir mnHorPrintRes( 600 ),
130cdf0e10cSrcweir mnVerPrintRes( 600 ),
131cdf0e10cSrcweir mnOrientation( XML_default ),
132cdf0e10cSrcweir mnPageOrder( XML_downThenOver ),
133cdf0e10cSrcweir mnCellComments( XML_none ),
134cdf0e10cSrcweir mnPrintErrors( XML_displayed ),
135cdf0e10cSrcweir mbUseEvenHF( false ),
136cdf0e10cSrcweir mbUseFirstHF( false ),
137cdf0e10cSrcweir mbValidSettings( true ),
138cdf0e10cSrcweir mbUseFirstPage( false ),
139cdf0e10cSrcweir mbBlackWhite( false ),
140cdf0e10cSrcweir mbDraftQuality( false ),
141cdf0e10cSrcweir mbFitToPages( false ),
142cdf0e10cSrcweir mbHorCenter( false ),
143cdf0e10cSrcweir mbVerCenter( false ),
144cdf0e10cSrcweir mbPrintGrid( false ),
145cdf0e10cSrcweir mbPrintHeadings( false )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
setBiffPrintErrors(sal_uInt8 nPrintErrors)149cdf0e10cSrcweir void PageSettingsModel::setBiffPrintErrors( sal_uInt8 nPrintErrors )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir static const sal_Int32 spnErrorIds[] = { XML_displayed, XML_none, XML_dash, XML_NA };
152cdf0e10cSrcweir mnPrintErrors = STATIC_ARRAY_SELECT( spnErrorIds, nPrintErrors, XML_none );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir // ============================================================================
156cdf0e10cSrcweir
PageSettings(const WorksheetHelper & rHelper)157cdf0e10cSrcweir PageSettings::PageSettings( const WorksheetHelper& rHelper ) :
158cdf0e10cSrcweir WorksheetHelper( rHelper )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
importPrintOptions(const AttributeList & rAttribs)162cdf0e10cSrcweir void PageSettings::importPrintOptions( const AttributeList& rAttribs )
163cdf0e10cSrcweir {
164cdf0e10cSrcweir maModel.mbHorCenter = rAttribs.getBool( XML_horizontalCentered, false );
165cdf0e10cSrcweir maModel.mbVerCenter = rAttribs.getBool( XML_verticalCentered, false );
166cdf0e10cSrcweir maModel.mbPrintGrid = rAttribs.getBool( XML_gridLines, false );
167cdf0e10cSrcweir maModel.mbPrintHeadings = rAttribs.getBool( XML_headings, false );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
importPageMargins(const AttributeList & rAttribs)170cdf0e10cSrcweir void PageSettings::importPageMargins( const AttributeList& rAttribs )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir maModel.mfLeftMargin = rAttribs.getDouble( XML_left, OOX_MARGIN_DEFAULT_LR );
173cdf0e10cSrcweir maModel.mfRightMargin = rAttribs.getDouble( XML_right, OOX_MARGIN_DEFAULT_LR );
174cdf0e10cSrcweir maModel.mfTopMargin = rAttribs.getDouble( XML_top, OOX_MARGIN_DEFAULT_TB );
175cdf0e10cSrcweir maModel.mfBottomMargin = rAttribs.getDouble( XML_bottom, OOX_MARGIN_DEFAULT_TB );
176cdf0e10cSrcweir maModel.mfHeaderMargin = rAttribs.getDouble( XML_header, OOX_MARGIN_DEFAULT_HF );
177cdf0e10cSrcweir maModel.mfFooterMargin = rAttribs.getDouble( XML_footer, OOX_MARGIN_DEFAULT_HF );
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
importPageSetup(const Relations & rRelations,const AttributeList & rAttribs)180cdf0e10cSrcweir void PageSettings::importPageSetup( const Relations& rRelations, const AttributeList& rAttribs )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir maModel.maBinSettPath = rRelations.getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
183cdf0e10cSrcweir maModel.mnPaperSize = rAttribs.getInteger( XML_paperSize, 1 );
184cdf0e10cSrcweir maModel.mnCopies = rAttribs.getInteger( XML_copies, 1 );
185cdf0e10cSrcweir maModel.mnScale = rAttribs.getInteger( XML_scale, 100 );
186cdf0e10cSrcweir maModel.mnFirstPage = rAttribs.getInteger( XML_firstPageNumber, 1 );
187cdf0e10cSrcweir maModel.mnFitToWidth = rAttribs.getInteger( XML_fitToWidth, 1 );
188cdf0e10cSrcweir maModel.mnFitToHeight = rAttribs.getInteger( XML_fitToHeight, 1 );
189cdf0e10cSrcweir maModel.mnHorPrintRes = rAttribs.getInteger( XML_horizontalDpi, 600 );
190cdf0e10cSrcweir maModel.mnVerPrintRes = rAttribs.getInteger( XML_verticalDpi, 600 );
191cdf0e10cSrcweir maModel.mnOrientation = rAttribs.getToken( XML_orientation, XML_default );
192cdf0e10cSrcweir maModel.mnPageOrder = rAttribs.getToken( XML_pageOrder, XML_downThenOver );
193cdf0e10cSrcweir maModel.mnCellComments = rAttribs.getToken( XML_cellComments, XML_none );
194cdf0e10cSrcweir maModel.mnPrintErrors = rAttribs.getToken( XML_errors, XML_displayed );
195cdf0e10cSrcweir maModel.mbValidSettings = rAttribs.getBool( XML_usePrinterDefaults, true );
196cdf0e10cSrcweir maModel.mbUseFirstPage = rAttribs.getBool( XML_useFirstPageNumber, false );
197cdf0e10cSrcweir maModel.mbBlackWhite = rAttribs.getBool( XML_blackAndWhite, false );
198cdf0e10cSrcweir maModel.mbDraftQuality = rAttribs.getBool( XML_draft, false );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
importChartPageSetup(const Relations & rRelations,const AttributeList & rAttribs)201cdf0e10cSrcweir void PageSettings::importChartPageSetup( const Relations& rRelations, const AttributeList& rAttribs )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir maModel.maBinSettPath = rRelations.getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
204cdf0e10cSrcweir maModel.mnPaperSize = rAttribs.getInteger( XML_paperSize, 1 );
205cdf0e10cSrcweir maModel.mnCopies = rAttribs.getInteger( XML_copies, 1 );
206cdf0e10cSrcweir maModel.mnFirstPage = rAttribs.getInteger( XML_firstPageNumber, 1 );
207cdf0e10cSrcweir maModel.mnHorPrintRes = rAttribs.getInteger( XML_horizontalDpi, 600 );
208cdf0e10cSrcweir maModel.mnVerPrintRes = rAttribs.getInteger( XML_verticalDpi, 600 );
209cdf0e10cSrcweir maModel.mnOrientation = rAttribs.getToken( XML_orientation, XML_default );
210cdf0e10cSrcweir maModel.mbValidSettings = rAttribs.getBool( XML_usePrinterDefaults, true );
211cdf0e10cSrcweir maModel.mbUseFirstPage = rAttribs.getBool( XML_useFirstPageNumber, false );
212cdf0e10cSrcweir maModel.mbBlackWhite = rAttribs.getBool( XML_blackAndWhite, false );
213cdf0e10cSrcweir maModel.mbDraftQuality = rAttribs.getBool( XML_draft, false );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir
importHeaderFooter(const AttributeList & rAttribs)216cdf0e10cSrcweir void PageSettings::importHeaderFooter( const AttributeList& rAttribs )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir maModel.mbUseEvenHF = rAttribs.getBool( XML_differentOddEven, false );
219cdf0e10cSrcweir maModel.mbUseFirstHF = rAttribs.getBool( XML_differentFirst, false );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
importHeaderFooterCharacters(const OUString & rChars,sal_Int32 nElement)222cdf0e10cSrcweir void PageSettings::importHeaderFooterCharacters( const OUString& rChars, sal_Int32 nElement )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir switch( nElement )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir case XLS_TOKEN( oddHeader ): maModel.maOddHeader += rChars; break;
227cdf0e10cSrcweir case XLS_TOKEN( oddFooter ): maModel.maOddFooter += rChars; break;
228cdf0e10cSrcweir case XLS_TOKEN( evenHeader ): maModel.maEvenHeader += rChars; break;
229cdf0e10cSrcweir case XLS_TOKEN( evenFooter ): maModel.maEvenFooter += rChars; break;
230cdf0e10cSrcweir case XLS_TOKEN( firstHeader ): maModel.maFirstHeader += rChars; break;
231cdf0e10cSrcweir case XLS_TOKEN( firstFooter ): maModel.maFirstFooter += rChars; break;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
importPicture(const Relations & rRelations,const AttributeList & rAttribs)235cdf0e10cSrcweir void PageSettings::importPicture( const Relations& rRelations, const AttributeList& rAttribs )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir importPictureData( rRelations, rAttribs.getString( R_TOKEN( id ), OUString() ) );
238cdf0e10cSrcweir }
239cdf0e10cSrcweir
importPageMargins(SequenceInputStream & rStrm)240cdf0e10cSrcweir void PageSettings::importPageMargins( SequenceInputStream& rStrm )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir rStrm >> maModel.mfLeftMargin >> maModel.mfRightMargin
243cdf0e10cSrcweir >> maModel.mfTopMargin >> maModel.mfBottomMargin
244cdf0e10cSrcweir >> maModel.mfHeaderMargin >> maModel.mfFooterMargin;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
importPrintOptions(SequenceInputStream & rStrm)247cdf0e10cSrcweir void PageSettings::importPrintOptions( SequenceInputStream& rStrm )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir sal_uInt16 nFlags;
250cdf0e10cSrcweir rStrm >> nFlags;
251cdf0e10cSrcweir maModel.mbHorCenter = getFlag( nFlags, BIFF12_PRINTOPT_HORCENTER );
252cdf0e10cSrcweir maModel.mbVerCenter = getFlag( nFlags, BIFF12_PRINTOPT_VERCENTER );
253cdf0e10cSrcweir maModel.mbPrintGrid = getFlag( nFlags, BIFF12_PRINTOPT_PRINTGRID );
254cdf0e10cSrcweir maModel.mbPrintHeadings = getFlag( nFlags, BIFF12_PRINTOPT_PRINTHEADING );
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
importPageSetup(const Relations & rRelations,SequenceInputStream & rStrm)257cdf0e10cSrcweir void PageSettings::importPageSetup( const Relations& rRelations, SequenceInputStream& rStrm )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir OUString aRelId;
260cdf0e10cSrcweir sal_uInt16 nFlags;
261cdf0e10cSrcweir rStrm >> maModel.mnPaperSize >> maModel.mnScale
262cdf0e10cSrcweir >> maModel.mnHorPrintRes >> maModel.mnVerPrintRes
263cdf0e10cSrcweir >> maModel.mnCopies >> maModel.mnFirstPage
264cdf0e10cSrcweir >> maModel.mnFitToWidth >> maModel.mnFitToHeight
265cdf0e10cSrcweir >> nFlags >> aRelId;
266cdf0e10cSrcweir maModel.setBiffPrintErrors( extractValue< sal_uInt8 >( nFlags, 9, 2 ) );
267cdf0e10cSrcweir maModel.maBinSettPath = rRelations.getFragmentPathFromRelId( aRelId );
268cdf0e10cSrcweir maModel.mnOrientation = getFlagValue( nFlags, BIFF12_PAGESETUP_DEFAULTORIENT, XML_default, getFlagValue( nFlags, BIFF12_PAGESETUP_LANDSCAPE, XML_landscape, XML_portrait ) );
269cdf0e10cSrcweir maModel.mnPageOrder = getFlagValue( nFlags, BIFF12_PAGESETUP_INROWS, XML_overThenDown, XML_downThenOver );
270cdf0e10cSrcweir maModel.mnCellComments = getFlagValue( nFlags, BIFF12_PAGESETUP_PRINTNOTES, getFlagValue( nFlags, BIFF12_PAGESETUP_NOTES_END, XML_atEnd, XML_asDisplayed ), XML_none );
271cdf0e10cSrcweir maModel.mbValidSettings = !getFlag( nFlags, BIFF12_PAGESETUP_INVALID );
272cdf0e10cSrcweir maModel.mbUseFirstPage = getFlag( nFlags, BIFF12_PAGESETUP_USEFIRSTPAGE );
273cdf0e10cSrcweir maModel.mbBlackWhite = getFlag( nFlags, BIFF12_PAGESETUP_BLACKWHITE );
274cdf0e10cSrcweir maModel.mbDraftQuality = getFlag( nFlags, BIFF12_PAGESETUP_DRAFTQUALITY );
275cdf0e10cSrcweir }
276cdf0e10cSrcweir
importChartPageSetup(const Relations & rRelations,SequenceInputStream & rStrm)277cdf0e10cSrcweir void PageSettings::importChartPageSetup( const Relations& rRelations, SequenceInputStream& rStrm )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir OUString aRelId;
280cdf0e10cSrcweir sal_uInt16 nFirstPage, nFlags;
281cdf0e10cSrcweir rStrm >> maModel.mnPaperSize >> maModel.mnHorPrintRes >> maModel.mnVerPrintRes
282cdf0e10cSrcweir >> maModel.mnCopies >> nFirstPage >> nFlags >> aRelId;
283cdf0e10cSrcweir maModel.maBinSettPath = rRelations.getFragmentPathFromRelId( aRelId );
284cdf0e10cSrcweir maModel.mnFirstPage = nFirstPage; // 16-bit in CHARTPAGESETUP
285cdf0e10cSrcweir maModel.mnOrientation = getFlagValue( nFlags, BIFF12_CHARTPAGESETUP_DEFAULTORIENT, XML_default, getFlagValue( nFlags, BIFF12_CHARTPAGESETUP_LANDSCAPE, XML_landscape, XML_portrait ) );
286cdf0e10cSrcweir maModel.mbValidSettings = !getFlag( nFlags, BIFF12_CHARTPAGESETUP_INVALID );
287cdf0e10cSrcweir maModel.mbUseFirstPage = getFlag( nFlags, BIFF12_CHARTPAGESETUP_USEFIRSTPAGE );
288cdf0e10cSrcweir maModel.mbBlackWhite = getFlag( nFlags, BIFF12_CHARTPAGESETUP_BLACKWHITE );
289cdf0e10cSrcweir maModel.mbDraftQuality = getFlag( nFlags, BIFF12_CHARTPAGESETUP_DRAFTQUALITY );
290cdf0e10cSrcweir }
291cdf0e10cSrcweir
importHeaderFooter(SequenceInputStream & rStrm)292cdf0e10cSrcweir void PageSettings::importHeaderFooter( SequenceInputStream& rStrm )
293cdf0e10cSrcweir {
294cdf0e10cSrcweir sal_uInt16 nFlags;
295cdf0e10cSrcweir rStrm >> nFlags
296cdf0e10cSrcweir >> maModel.maOddHeader >> maModel.maOddFooter
297cdf0e10cSrcweir >> maModel.maEvenHeader >> maModel.maEvenFooter
298cdf0e10cSrcweir >> maModel.maFirstHeader >> maModel.maFirstFooter;
299cdf0e10cSrcweir maModel.mbUseEvenHF = getFlag( nFlags, BIFF12_HEADERFOOTER_DIFFEVEN );
300cdf0e10cSrcweir maModel.mbUseFirstHF = getFlag( nFlags, BIFF12_HEADERFOOTER_DIFFFIRST );
301cdf0e10cSrcweir }
302cdf0e10cSrcweir
importPicture(const Relations & rRelations,SequenceInputStream & rStrm)303cdf0e10cSrcweir void PageSettings::importPicture( const Relations& rRelations, SequenceInputStream& rStrm )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir importPictureData( rRelations, BiffHelper::readString( rStrm ) );
306cdf0e10cSrcweir }
307cdf0e10cSrcweir
importLeftMargin(BiffInputStream & rStrm)308cdf0e10cSrcweir void PageSettings::importLeftMargin( BiffInputStream& rStrm )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir rStrm >> maModel.mfLeftMargin;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
importRightMargin(BiffInputStream & rStrm)313cdf0e10cSrcweir void PageSettings::importRightMargin( BiffInputStream& rStrm )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir rStrm >> maModel.mfRightMargin;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir
importTopMargin(BiffInputStream & rStrm)318cdf0e10cSrcweir void PageSettings::importTopMargin( BiffInputStream& rStrm )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir rStrm >> maModel.mfTopMargin;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir
importBottomMargin(BiffInputStream & rStrm)323cdf0e10cSrcweir void PageSettings::importBottomMargin( BiffInputStream& rStrm )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir rStrm >> maModel.mfBottomMargin;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
importPageSetup(BiffInputStream & rStrm)328cdf0e10cSrcweir void PageSettings::importPageSetup( BiffInputStream& rStrm )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir sal_uInt16 nPaperSize, nScale, nFirstPage, nFitToWidth, nFitToHeight, nFlags;
331cdf0e10cSrcweir rStrm >> nPaperSize >> nScale >> nFirstPage >> nFitToWidth >> nFitToHeight >> nFlags;
332cdf0e10cSrcweir
333cdf0e10cSrcweir maModel.mnPaperSize = nPaperSize; // equal in BIFF and OOX
334cdf0e10cSrcweir maModel.mnScale = nScale;
335cdf0e10cSrcweir maModel.mnFirstPage = nFirstPage;
336cdf0e10cSrcweir maModel.mnFitToWidth = nFitToWidth;
337cdf0e10cSrcweir maModel.mnFitToHeight = nFitToHeight;
338cdf0e10cSrcweir maModel.mnOrientation = getFlagValue( nFlags, BIFF_PAGESETUP_PORTRAIT, XML_portrait, XML_landscape );
339cdf0e10cSrcweir maModel.mnPageOrder = getFlagValue( nFlags, BIFF_PAGESETUP_INROWS, XML_overThenDown, XML_downThenOver );
340cdf0e10cSrcweir maModel.mbValidSettings = !getFlag( nFlags, BIFF_PAGESETUP_INVALID );
341cdf0e10cSrcweir maModel.mbUseFirstPage = true;
342cdf0e10cSrcweir maModel.mbBlackWhite = getFlag( nFlags, BIFF_PAGESETUP_BLACKWHITE );
343cdf0e10cSrcweir
344cdf0e10cSrcweir if( getBiff() >= BIFF5 )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir sal_uInt16 nHorPrintRes, nVerPrintRes, nCopies;
347cdf0e10cSrcweir rStrm >> nHorPrintRes >> nVerPrintRes >> maModel.mfHeaderMargin >> maModel.mfFooterMargin >> nCopies;
348cdf0e10cSrcweir
349cdf0e10cSrcweir maModel.mnCopies = nCopies;
350cdf0e10cSrcweir maModel.mnOrientation = getFlagValue( nFlags, BIFF_PAGESETUP_DEFAULTORIENT, XML_default, maModel.mnOrientation );
351cdf0e10cSrcweir maModel.mnHorPrintRes = nHorPrintRes;
352cdf0e10cSrcweir maModel.mnVerPrintRes = nVerPrintRes;
353cdf0e10cSrcweir maModel.mnCellComments = getFlagValue( nFlags, BIFF_PAGESETUP_PRINTNOTES, XML_asDisplayed, XML_none );
354cdf0e10cSrcweir maModel.mbUseFirstPage = getFlag( nFlags, BIFF_PAGESETUP_USEFIRSTPAGE );
355cdf0e10cSrcweir maModel.mbDraftQuality = getFlag( nFlags, BIFF_PAGESETUP_DRAFTQUALITY );
356cdf0e10cSrcweir
357cdf0e10cSrcweir if( getBiff() == BIFF8 )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir maModel.setBiffPrintErrors( extractValue< sal_uInt8 >( nFlags, 10, 2 ) );
360cdf0e10cSrcweir maModel.mnCellComments = getFlagValue( nFlags, BIFF_PAGESETUP_PRINTNOTES, getFlagValue( nFlags, BIFF_PAGESETUP_NOTES_END, XML_atEnd, XML_asDisplayed ), XML_none );
361cdf0e10cSrcweir }
362cdf0e10cSrcweir }
363cdf0e10cSrcweir }
364cdf0e10cSrcweir
importHorCenter(BiffInputStream & rStrm)365cdf0e10cSrcweir void PageSettings::importHorCenter( BiffInputStream& rStrm )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir maModel.mbHorCenter = rStrm.readuInt16() != 0;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir
importVerCenter(BiffInputStream & rStrm)370cdf0e10cSrcweir void PageSettings::importVerCenter( BiffInputStream& rStrm )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir maModel.mbVerCenter = rStrm.readuInt16() != 0;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
importPrintHeaders(BiffInputStream & rStrm)375cdf0e10cSrcweir void PageSettings::importPrintHeaders( BiffInputStream& rStrm )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir maModel.mbPrintHeadings = rStrm.readuInt16() != 0;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
importPrintGridLines(BiffInputStream & rStrm)380cdf0e10cSrcweir void PageSettings::importPrintGridLines( BiffInputStream& rStrm )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir maModel.mbPrintGrid = rStrm.readuInt16() != 0;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir
importHeader(BiffInputStream & rStrm)385cdf0e10cSrcweir void PageSettings::importHeader( BiffInputStream& rStrm )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir if( rStrm.getRemaining() > 0 )
388cdf0e10cSrcweir maModel.maOddHeader = (getBiff() == BIFF8) ? rStrm.readUniString() : rStrm.readByteStringUC( false, getTextEncoding() );
389cdf0e10cSrcweir else
390cdf0e10cSrcweir maModel.maOddHeader = OUString();
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
importFooter(BiffInputStream & rStrm)393cdf0e10cSrcweir void PageSettings::importFooter( BiffInputStream& rStrm )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir if( rStrm.getRemaining() > 0 )
396cdf0e10cSrcweir maModel.maOddFooter = (getBiff() == BIFF8) ? rStrm.readUniString() : rStrm.readByteStringUC( false, getTextEncoding() );
397cdf0e10cSrcweir else
398cdf0e10cSrcweir maModel.maOddFooter = OUString();
399cdf0e10cSrcweir }
400cdf0e10cSrcweir
importPicture(BiffInputStream & rStrm)401cdf0e10cSrcweir void PageSettings::importPicture( BiffInputStream& rStrm )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir StreamDataSequence aPictureData;
404cdf0e10cSrcweir BiffHelper::importImgData( aPictureData, rStrm, getBiff() );
405cdf0e10cSrcweir maModel.maGraphicUrl = getBaseFilter().getGraphicHelper().importGraphicObject( aPictureData );
406cdf0e10cSrcweir }
407cdf0e10cSrcweir
setFitToPagesMode(bool bFitToPages)408cdf0e10cSrcweir void PageSettings::setFitToPagesMode( bool bFitToPages )
409cdf0e10cSrcweir {
410cdf0e10cSrcweir maModel.mbFitToPages = bFitToPages;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
finalizeImport()413cdf0e10cSrcweir void PageSettings::finalizeImport()
414cdf0e10cSrcweir {
415cdf0e10cSrcweir OUStringBuffer aStyleNameBuffer( CREATE_OUSTRING( "PageStyle_" ) );
416cdf0e10cSrcweir Reference< XNamed > xSheetName( getSheet(), UNO_QUERY );
417cdf0e10cSrcweir if( xSheetName.is() )
418cdf0e10cSrcweir aStyleNameBuffer.append( xSheetName->getName() );
419cdf0e10cSrcweir else
420cdf0e10cSrcweir aStyleNameBuffer.append( static_cast< sal_Int32 >( getSheetIndex() + 1 ) );
421cdf0e10cSrcweir OUString aStyleName = aStyleNameBuffer.makeStringAndClear();
422cdf0e10cSrcweir
423cdf0e10cSrcweir Reference< XStyle > xStyle = createStyleObject( aStyleName, true );
424cdf0e10cSrcweir PropertySet aStyleProps( xStyle );
425cdf0e10cSrcweir getPageSettingsConverter().writePageSettingsProperties( aStyleProps, maModel, getSheetType() );
426cdf0e10cSrcweir
427cdf0e10cSrcweir PropertySet aSheetProps( getSheet() );
428cdf0e10cSrcweir aSheetProps.setProperty( PROP_PageStyle, aStyleName );
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
importPictureData(const Relations & rRelations,const OUString & rRelId)431cdf0e10cSrcweir void PageSettings::importPictureData( const Relations& rRelations, const OUString& rRelId )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir OUString aPicturePath = rRelations.getFragmentPathFromRelId( rRelId );
434cdf0e10cSrcweir if( aPicturePath.getLength() > 0 )
435cdf0e10cSrcweir maModel.maGraphicUrl = getBaseFilter().getGraphicHelper().importEmbeddedGraphicObject( aPicturePath );
436cdf0e10cSrcweir }
437cdf0e10cSrcweir
438cdf0e10cSrcweir // ============================================================================
439cdf0e10cSrcweir // ============================================================================
440cdf0e10cSrcweir
441cdf0e10cSrcweir enum HFPortionId
442cdf0e10cSrcweir {
443cdf0e10cSrcweir HF_LEFT,
444cdf0e10cSrcweir HF_CENTER,
445cdf0e10cSrcweir HF_RIGHT,
446cdf0e10cSrcweir HF_COUNT
447cdf0e10cSrcweir };
448cdf0e10cSrcweir
449cdf0e10cSrcweir // ----------------------------------------------------------------------------
450cdf0e10cSrcweir
451cdf0e10cSrcweir struct HFPortionInfo
452cdf0e10cSrcweir {
453cdf0e10cSrcweir Reference< XText > mxText; /// XText interface of this portion.
454cdf0e10cSrcweir Reference< XTextCursor > mxStart; /// Start position of current text range for formatting.
455cdf0e10cSrcweir Reference< XTextCursor > mxEnd; /// End position of current text range for formatting.
456cdf0e10cSrcweir double mfTotalHeight; /// Sum of heights of previous lines in points.
457cdf0e10cSrcweir double mfCurrHeight; /// Height of the current text line in points.
458cdf0e10cSrcweir
459cdf0e10cSrcweir bool initialize( const Reference< XText >& rxText );
460cdf0e10cSrcweir };
461cdf0e10cSrcweir
initialize(const Reference<XText> & rxText)462cdf0e10cSrcweir bool HFPortionInfo::initialize( const Reference< XText >& rxText )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir mfTotalHeight = mfCurrHeight = 0.0;
465cdf0e10cSrcweir mxText = rxText;
466cdf0e10cSrcweir if( mxText.is() )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir mxStart = mxText->createTextCursor();
469cdf0e10cSrcweir mxEnd = mxText->createTextCursor();
470cdf0e10cSrcweir }
471cdf0e10cSrcweir bool bRet = mxText.is() && mxStart.is() && mxEnd.is();
472cdf0e10cSrcweir OSL_ENSURE( bRet, "HFPortionInfo::initialize - missing interfaces" );
473cdf0e10cSrcweir return bRet;
474cdf0e10cSrcweir }
475cdf0e10cSrcweir
476cdf0e10cSrcweir // ============================================================================
477cdf0e10cSrcweir
478cdf0e10cSrcweir class HeaderFooterParser : public WorkbookHelper
479cdf0e10cSrcweir {
480cdf0e10cSrcweir public:
481cdf0e10cSrcweir explicit HeaderFooterParser( const WorkbookHelper& rHelper );
482cdf0e10cSrcweir
483cdf0e10cSrcweir /** Parses the passed string and creates the header/footer contents.
484cdf0e10cSrcweir @returns The total height of the converted header or footer in points. */
485cdf0e10cSrcweir double parse(
486cdf0e10cSrcweir const Reference< XHeaderFooterContent >& rxContext,
487cdf0e10cSrcweir const OUString& rData );
488cdf0e10cSrcweir
489cdf0e10cSrcweir private:
490cdf0e10cSrcweir /** Returns the current edit engine text object. */
getPortion()491cdf0e10cSrcweir inline HFPortionInfo& getPortion() { return maPortions[ meCurrPortion ]; }
492cdf0e10cSrcweir /** Returns the start cursor of the current text range. */
getStartPos()493cdf0e10cSrcweir inline const Reference< XTextCursor >& getStartPos() { return getPortion().mxStart; }
494cdf0e10cSrcweir /** Returns the end cursor of the current text range. */
getEndPos()495cdf0e10cSrcweir inline const Reference< XTextCursor >& getEndPos() { return getPortion().mxEnd; }
496cdf0e10cSrcweir
497cdf0e10cSrcweir /** Returns the current line height of the specified portion. */
498cdf0e10cSrcweir double getCurrHeight( HFPortionId ePortion ) const;
499cdf0e10cSrcweir /** Returns the current line height. */
500cdf0e10cSrcweir double getCurrHeight() const;
501cdf0e10cSrcweir
502cdf0e10cSrcweir /** Updates the current line height of the specified portion, using the current font size. */
503cdf0e10cSrcweir void updateCurrHeight( HFPortionId ePortion );
504cdf0e10cSrcweir /** Updates the current line height, using the current font size. */
505cdf0e10cSrcweir void updateCurrHeight();
506cdf0e10cSrcweir
507cdf0e10cSrcweir /** Sets the font attributes at the current selection. */
508cdf0e10cSrcweir void setAttributes();
509cdf0e10cSrcweir /** Appends and clears internal string buffer. */
510cdf0e10cSrcweir void appendText();
511cdf0e10cSrcweir /** Appends a line break and adjusts internal text height data. */
512cdf0e10cSrcweir void appendLineBreak();
513cdf0e10cSrcweir
514cdf0e10cSrcweir /** Creates a text field from the passed service name. */
515cdf0e10cSrcweir Reference< XTextContent > createField( const OUString& rServiceName ) const;
516cdf0e10cSrcweir /** Appends the passed text field. */
517cdf0e10cSrcweir void appendField( const Reference< XTextContent >& rxContent );
518cdf0e10cSrcweir
519cdf0e10cSrcweir /** Sets the passed font name if it is valid. */
520cdf0e10cSrcweir void convertFontName( const OUString& rStyle );
521cdf0e10cSrcweir /** Converts a font style given as string. */
522cdf0e10cSrcweir void convertFontStyle( const OUString& rStyle );
523cdf0e10cSrcweir /** Converts a font color given as string. */
524cdf0e10cSrcweir void convertFontColor( const OUString& rColor );
525cdf0e10cSrcweir
526cdf0e10cSrcweir /** Finalizes current portion: sets font attributes and updates text height data. */
527cdf0e10cSrcweir void finalizePortion();
528cdf0e10cSrcweir /** Changes current header/footer portion. */
529cdf0e10cSrcweir void setNewPortion( HFPortionId ePortion );
530cdf0e10cSrcweir
531cdf0e10cSrcweir private:
532cdf0e10cSrcweir typedef ::std::vector< HFPortionInfo > HFPortionInfoVec;
533cdf0e10cSrcweir typedef ::std::set< OString > OStringSet;
534cdf0e10cSrcweir
535cdf0e10cSrcweir const OUString maPageNumberService;
536cdf0e10cSrcweir const OUString maPageCountService;
537cdf0e10cSrcweir const OUString maSheetNameService;
538cdf0e10cSrcweir const OUString maFileNameService;
539cdf0e10cSrcweir const OUString maDateTimeService;
540cdf0e10cSrcweir const OStringSet maBoldNames; /// All names for bold font style in lowercase UTF-8.
541cdf0e10cSrcweir const OStringSet maItalicNames; /// All names for italic font style in lowercase UTF-8.
542cdf0e10cSrcweir HFPortionInfoVec maPortions;
543cdf0e10cSrcweir HFPortionId meCurrPortion; /// Identifier of current H/F portion.
544cdf0e10cSrcweir OUStringBuffer maBuffer; /// Text data to append to current text range.
545cdf0e10cSrcweir FontModel maFontModel; /// Font attributes of current text range.
546cdf0e10cSrcweir };
547cdf0e10cSrcweir
548cdf0e10cSrcweir // ----------------------------------------------------------------------------
549cdf0e10cSrcweir
550cdf0e10cSrcweir namespace {
551cdf0e10cSrcweir
552cdf0e10cSrcweir // different names for bold font style (lowercase)
553cdf0e10cSrcweir static const sal_Char* const sppcBoldNames[] =
554cdf0e10cSrcweir {
555cdf0e10cSrcweir "bold",
556cdf0e10cSrcweir "fett", // German 'bold'
557cdf0e10cSrcweir "demibold",
558cdf0e10cSrcweir "halbfett", // German 'demibold'
559cdf0e10cSrcweir "black",
560cdf0e10cSrcweir "heavy"
561cdf0e10cSrcweir };
562cdf0e10cSrcweir
563cdf0e10cSrcweir // different names for italic font style (lowercase)
564cdf0e10cSrcweir static const sal_Char* const sppcItalicNames[] =
565cdf0e10cSrcweir {
566cdf0e10cSrcweir "italic",
567cdf0e10cSrcweir "kursiv", // German 'italic'
568cdf0e10cSrcweir "oblique",
569cdf0e10cSrcweir "schr\303\204g", // German 'oblique' with uppercase A umlaut
570cdf0e10cSrcweir "schr\303\244g" // German 'oblique' with lowercase A umlaut
571cdf0e10cSrcweir };
572cdf0e10cSrcweir
573cdf0e10cSrcweir } // namespace
574cdf0e10cSrcweir
575cdf0e10cSrcweir // ----------------------------------------------------------------------------
576cdf0e10cSrcweir
HeaderFooterParser(const WorkbookHelper & rHelper)577cdf0e10cSrcweir HeaderFooterParser::HeaderFooterParser( const WorkbookHelper& rHelper ) :
578cdf0e10cSrcweir WorkbookHelper( rHelper ),
579cdf0e10cSrcweir maPageNumberService( CREATE_OUSTRING( "com.sun.star.text.TextField.PageNumber" ) ),
580cdf0e10cSrcweir maPageCountService( CREATE_OUSTRING( "com.sun.star.text.TextField.PageCount" ) ),
581cdf0e10cSrcweir maSheetNameService( CREATE_OUSTRING( "com.sun.star.text.TextField.SheetName" ) ),
582cdf0e10cSrcweir maFileNameService( CREATE_OUSTRING( "com.sun.star.text.TextField.FileName" ) ),
583cdf0e10cSrcweir maDateTimeService( CREATE_OUSTRING( "com.sun.star.text.TextField.DateTime" ) ),
584cdf0e10cSrcweir maBoldNames( sppcBoldNames, STATIC_ARRAY_END( sppcBoldNames ) ),
585cdf0e10cSrcweir maItalicNames( sppcItalicNames, STATIC_ARRAY_END( sppcItalicNames ) ),
586cdf0e10cSrcweir maPortions( static_cast< size_t >( HF_COUNT ) ),
587cdf0e10cSrcweir meCurrPortion( HF_CENTER )
588cdf0e10cSrcweir {
589cdf0e10cSrcweir }
590cdf0e10cSrcweir
parse(const Reference<XHeaderFooterContent> & rxContext,const OUString & rData)591cdf0e10cSrcweir double HeaderFooterParser::parse( const Reference< XHeaderFooterContent >& rxContext, const OUString& rData )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir if( !rxContext.is() || (rData.getLength() == 0) ||
594cdf0e10cSrcweir !maPortions[ HF_LEFT ].initialize( rxContext->getLeftText() ) ||
595cdf0e10cSrcweir !maPortions[ HF_CENTER ].initialize( rxContext->getCenterText() ) ||
596cdf0e10cSrcweir !maPortions[ HF_RIGHT ].initialize( rxContext->getRightText() ) )
597cdf0e10cSrcweir return 0.0;
598cdf0e10cSrcweir
599cdf0e10cSrcweir meCurrPortion = HF_CENTER;
600cdf0e10cSrcweir maBuffer.setLength( 0 );
601cdf0e10cSrcweir maFontModel = getStyles().getDefaultFontModel();
602cdf0e10cSrcweir OUStringBuffer aFontName; // current font name
603cdf0e10cSrcweir OUStringBuffer aFontStyle; // current font style
604cdf0e10cSrcweir sal_Int32 nFontHeight = 0; // current font height
605cdf0e10cSrcweir
606cdf0e10cSrcweir /** State of the parser. */
607cdf0e10cSrcweir enum
608cdf0e10cSrcweir {
609cdf0e10cSrcweir STATE_TEXT, /// Literal text data.
610cdf0e10cSrcweir STATE_TOKEN, /// Control token following a '&' character.
611cdf0e10cSrcweir STATE_FONTNAME, /// Font name ('&' is followed by '"', reads until next '"' or ',').
612cdf0e10cSrcweir STATE_FONTSTYLE, /// Font style name (font part after ',', reads until next '"').
613cdf0e10cSrcweir STATE_FONTHEIGHT /// Font height ('&' is followed by num. digits, reads until non-digit).
614cdf0e10cSrcweir }
615cdf0e10cSrcweir eState = STATE_TEXT;
616cdf0e10cSrcweir
617cdf0e10cSrcweir const sal_Unicode* pcChar = rData.getStr();
618cdf0e10cSrcweir const sal_Unicode* pcEnd = pcChar + rData.getLength();
619cdf0e10cSrcweir for( ; (pcChar != pcEnd) && (*pcChar != 0); ++pcChar )
620cdf0e10cSrcweir {
621cdf0e10cSrcweir sal_Unicode cChar = *pcChar;
622cdf0e10cSrcweir switch( eState )
623cdf0e10cSrcweir {
624cdf0e10cSrcweir case STATE_TEXT:
625cdf0e10cSrcweir {
626cdf0e10cSrcweir switch( cChar )
627cdf0e10cSrcweir {
628cdf0e10cSrcweir case '&': // new token
629cdf0e10cSrcweir appendText();
630cdf0e10cSrcweir eState = STATE_TOKEN;
631cdf0e10cSrcweir break;
632cdf0e10cSrcweir case '\n': // line break
633cdf0e10cSrcweir appendText();
634cdf0e10cSrcweir appendLineBreak();
635cdf0e10cSrcweir break;
636cdf0e10cSrcweir default:
637cdf0e10cSrcweir maBuffer.append( cChar );
638cdf0e10cSrcweir }
639cdf0e10cSrcweir }
640cdf0e10cSrcweir break;
641cdf0e10cSrcweir
642cdf0e10cSrcweir case STATE_TOKEN:
643cdf0e10cSrcweir {
644cdf0e10cSrcweir // default: back to text mode, may be changed in specific cases
645cdf0e10cSrcweir eState = STATE_TEXT;
646cdf0e10cSrcweir // ignore case of token codes
647cdf0e10cSrcweir if( ('a' <= cChar) && (cChar <= 'z') )
648cdf0e10cSrcweir (cChar -= 'a') += 'A';
649cdf0e10cSrcweir switch( cChar )
650cdf0e10cSrcweir {
651cdf0e10cSrcweir case '&': maBuffer.append( cChar ); break; // the '&' character
652cdf0e10cSrcweir
653cdf0e10cSrcweir case 'L': setNewPortion( HF_LEFT ); break; // left portion
654cdf0e10cSrcweir case 'C': setNewPortion( HF_CENTER ); break; // center portion
655cdf0e10cSrcweir case 'R': setNewPortion( HF_RIGHT ); break; // right portion
656cdf0e10cSrcweir
657cdf0e10cSrcweir case 'P': // page number
658cdf0e10cSrcweir appendField( createField( maPageNumberService ) );
659cdf0e10cSrcweir break;
660cdf0e10cSrcweir case 'N': // total page count
661cdf0e10cSrcweir appendField( createField( maPageCountService ) );
662cdf0e10cSrcweir break;
663cdf0e10cSrcweir case 'A': // current sheet name
664cdf0e10cSrcweir appendField( createField( maSheetNameService ) );
665cdf0e10cSrcweir break;
666cdf0e10cSrcweir
667cdf0e10cSrcweir case 'F': // file name
668cdf0e10cSrcweir {
669cdf0e10cSrcweir Reference< XTextContent > xContent = createField( maFileNameService );
670cdf0e10cSrcweir PropertySet aPropSet( xContent );
671cdf0e10cSrcweir aPropSet.setProperty( PROP_FileFormat, ::com::sun::star::text::FilenameDisplayFormat::NAME_AND_EXT );
672cdf0e10cSrcweir appendField( xContent );
673cdf0e10cSrcweir }
674cdf0e10cSrcweir break;
675cdf0e10cSrcweir case 'Z': // file path (without file name), OOXML, BIFF12, and BIFF8 only
676cdf0e10cSrcweir if( (getFilterType() == FILTER_OOXML) || ((getFilterType() == FILTER_BIFF) && (getBiff() == BIFF8)) )
677cdf0e10cSrcweir {
678cdf0e10cSrcweir Reference< XTextContent > xContent = createField( maFileNameService );
679cdf0e10cSrcweir PropertySet aPropSet( xContent );
680cdf0e10cSrcweir // FilenameDisplayFormat::PATH not supported by Calc
681cdf0e10cSrcweir aPropSet.setProperty( PROP_FileFormat, ::com::sun::star::text::FilenameDisplayFormat::FULL );
682cdf0e10cSrcweir appendField( xContent );
683cdf0e10cSrcweir /* path only is not supported -- if we find a '&Z&F'
684cdf0e10cSrcweir combination for path/name, skip the '&F' part */
685cdf0e10cSrcweir if( (pcChar + 2 < pcEnd) && (pcChar[ 1 ] == '&') && ((pcChar[ 2 ] == 'f') || (pcChar[ 2 ] == 'F')) )
686cdf0e10cSrcweir pcChar += 2;
687cdf0e10cSrcweir }
688cdf0e10cSrcweir break;
689cdf0e10cSrcweir case 'D': // date
690cdf0e10cSrcweir {
691cdf0e10cSrcweir Reference< XTextContent > xContent = createField( maDateTimeService );
692cdf0e10cSrcweir PropertySet aPropSet( xContent );
693cdf0e10cSrcweir aPropSet.setProperty( PROP_IsDate, true );
694cdf0e10cSrcweir appendField( xContent );
695cdf0e10cSrcweir }
696cdf0e10cSrcweir break;
697cdf0e10cSrcweir case 'T': // time
698cdf0e10cSrcweir {
699cdf0e10cSrcweir Reference< XTextContent > xContent = createField( maDateTimeService );
700cdf0e10cSrcweir PropertySet aPropSet( xContent );
701cdf0e10cSrcweir aPropSet.setProperty( PROP_IsDate, false );
702cdf0e10cSrcweir appendField( xContent );
703cdf0e10cSrcweir }
704cdf0e10cSrcweir break;
705cdf0e10cSrcweir
706cdf0e10cSrcweir case 'B': // bold
707cdf0e10cSrcweir setAttributes();
708cdf0e10cSrcweir maFontModel.mbBold = !maFontModel.mbBold;
709cdf0e10cSrcweir break;
710cdf0e10cSrcweir case 'I': // italic
711cdf0e10cSrcweir setAttributes();
712cdf0e10cSrcweir maFontModel.mbItalic = !maFontModel.mbItalic;
713cdf0e10cSrcweir break;
714cdf0e10cSrcweir case 'U': // underline
715cdf0e10cSrcweir setAttributes();
716cdf0e10cSrcweir maFontModel.mnUnderline = (maFontModel.mnUnderline == XML_single) ? XML_none : XML_single;
717cdf0e10cSrcweir break;
718cdf0e10cSrcweir case 'E': // double underline
719cdf0e10cSrcweir setAttributes();
720cdf0e10cSrcweir maFontModel.mnUnderline = (maFontModel.mnUnderline == XML_double) ? XML_none : XML_double;
721cdf0e10cSrcweir break;
722cdf0e10cSrcweir case 'S': // strikeout
723cdf0e10cSrcweir setAttributes();
724cdf0e10cSrcweir maFontModel.mbStrikeout = !maFontModel.mbStrikeout;
725cdf0e10cSrcweir break;
726cdf0e10cSrcweir case 'X': // superscript
727cdf0e10cSrcweir setAttributes();
728cdf0e10cSrcweir maFontModel.mnEscapement = (maFontModel.mnEscapement == XML_superscript) ? XML_baseline : XML_superscript;
729cdf0e10cSrcweir break;
730cdf0e10cSrcweir case 'Y': // subsrcipt
731cdf0e10cSrcweir setAttributes();
732cdf0e10cSrcweir maFontModel.mnEscapement = (maFontModel.mnEscapement == XML_subscript) ? XML_baseline : XML_subscript;
733cdf0e10cSrcweir break;
734cdf0e10cSrcweir case 'O': // outlined
735cdf0e10cSrcweir setAttributes();
736cdf0e10cSrcweir maFontModel.mbOutline = !maFontModel.mbOutline;
737cdf0e10cSrcweir break;
738cdf0e10cSrcweir case 'H': // shadow
739cdf0e10cSrcweir setAttributes();
740cdf0e10cSrcweir maFontModel.mbShadow = !maFontModel.mbShadow;
741cdf0e10cSrcweir break;
742cdf0e10cSrcweir
743cdf0e10cSrcweir case 'K': // text color (not in BIFF)
744cdf0e10cSrcweir if( (getFilterType() == FILTER_OOXML) && (pcChar + 6 < pcEnd) )
745cdf0e10cSrcweir {
746cdf0e10cSrcweir setAttributes();
747cdf0e10cSrcweir // eat the following 6 characters
748cdf0e10cSrcweir convertFontColor( OUString( pcChar + 1, 6 ) );
749cdf0e10cSrcweir pcChar += 6;
750cdf0e10cSrcweir }
751cdf0e10cSrcweir break;
752cdf0e10cSrcweir
753cdf0e10cSrcweir case '\"': // font name
754cdf0e10cSrcweir aFontName.setLength( 0 );
755cdf0e10cSrcweir aFontStyle.setLength( 0 );
756cdf0e10cSrcweir eState = STATE_FONTNAME;
757cdf0e10cSrcweir break;
758cdf0e10cSrcweir default:
759cdf0e10cSrcweir if( ('0' <= cChar) && (cChar <= '9') ) // font size
760cdf0e10cSrcweir {
761cdf0e10cSrcweir nFontHeight = cChar - '0';
762cdf0e10cSrcweir eState = STATE_FONTHEIGHT;
763cdf0e10cSrcweir }
764cdf0e10cSrcweir }
765cdf0e10cSrcweir }
766cdf0e10cSrcweir break;
767cdf0e10cSrcweir
768cdf0e10cSrcweir case STATE_FONTNAME:
769cdf0e10cSrcweir {
770cdf0e10cSrcweir switch( cChar )
771cdf0e10cSrcweir {
772cdf0e10cSrcweir case '\"':
773cdf0e10cSrcweir setAttributes();
774cdf0e10cSrcweir convertFontName( aFontName.makeStringAndClear() );
775cdf0e10cSrcweir eState = STATE_TEXT;
776cdf0e10cSrcweir break;
777cdf0e10cSrcweir case ',':
778cdf0e10cSrcweir eState = STATE_FONTSTYLE;
779cdf0e10cSrcweir break;
780cdf0e10cSrcweir default:
781cdf0e10cSrcweir aFontName.append( cChar );
782cdf0e10cSrcweir }
783cdf0e10cSrcweir }
784cdf0e10cSrcweir break;
785cdf0e10cSrcweir
786cdf0e10cSrcweir case STATE_FONTSTYLE:
787cdf0e10cSrcweir {
788cdf0e10cSrcweir switch( cChar )
789cdf0e10cSrcweir {
790cdf0e10cSrcweir case '\"':
791cdf0e10cSrcweir setAttributes();
792cdf0e10cSrcweir convertFontName( aFontName.makeStringAndClear() );
793cdf0e10cSrcweir convertFontStyle( aFontStyle.makeStringAndClear() );
794cdf0e10cSrcweir eState = STATE_TEXT;
795cdf0e10cSrcweir break;
796cdf0e10cSrcweir default:
797cdf0e10cSrcweir aFontStyle.append( cChar );
798cdf0e10cSrcweir }
799cdf0e10cSrcweir }
800cdf0e10cSrcweir break;
801cdf0e10cSrcweir
802cdf0e10cSrcweir case STATE_FONTHEIGHT:
803cdf0e10cSrcweir {
804cdf0e10cSrcweir if( ('0' <= cChar) && (cChar <= '9') )
805cdf0e10cSrcweir {
806cdf0e10cSrcweir if( nFontHeight >= 0 )
807cdf0e10cSrcweir {
808cdf0e10cSrcweir nFontHeight *= 10;
809cdf0e10cSrcweir nFontHeight += (cChar - '0');
810cdf0e10cSrcweir if( nFontHeight > 1000 )
811cdf0e10cSrcweir nFontHeight = -1;
812cdf0e10cSrcweir }
813cdf0e10cSrcweir }
814cdf0e10cSrcweir else
815cdf0e10cSrcweir {
816cdf0e10cSrcweir if( nFontHeight > 0 )
817cdf0e10cSrcweir {
818cdf0e10cSrcweir setAttributes();
819cdf0e10cSrcweir maFontModel.mfHeight = nFontHeight;
820cdf0e10cSrcweir }
821cdf0e10cSrcweir --pcChar;
822cdf0e10cSrcweir eState = STATE_TEXT;
823cdf0e10cSrcweir }
824cdf0e10cSrcweir }
825cdf0e10cSrcweir break;
826cdf0e10cSrcweir }
827cdf0e10cSrcweir }
828cdf0e10cSrcweir
829cdf0e10cSrcweir // finalize
830cdf0e10cSrcweir finalizePortion();
831cdf0e10cSrcweir maPortions[ HF_LEFT ].mfTotalHeight += getCurrHeight( HF_LEFT );
832cdf0e10cSrcweir maPortions[ HF_CENTER ].mfTotalHeight += getCurrHeight( HF_CENTER );
833cdf0e10cSrcweir maPortions[ HF_RIGHT ].mfTotalHeight += getCurrHeight( HF_RIGHT );
834cdf0e10cSrcweir
835cdf0e10cSrcweir return ::std::max( maPortions[ HF_LEFT ].mfTotalHeight,
836cdf0e10cSrcweir ::std::max( maPortions[ HF_CENTER ].mfTotalHeight, maPortions[ HF_RIGHT ].mfTotalHeight ) );
837cdf0e10cSrcweir }
838cdf0e10cSrcweir
839cdf0e10cSrcweir // private --------------------------------------------------------------------
840cdf0e10cSrcweir
getCurrHeight(HFPortionId ePortion) const841cdf0e10cSrcweir double HeaderFooterParser::getCurrHeight( HFPortionId ePortion ) const
842cdf0e10cSrcweir {
843cdf0e10cSrcweir double fMaxHt = maPortions[ ePortion ].mfCurrHeight;
844cdf0e10cSrcweir return (fMaxHt == 0.0) ? maFontModel.mfHeight : fMaxHt;
845cdf0e10cSrcweir }
846cdf0e10cSrcweir
getCurrHeight() const847cdf0e10cSrcweir double HeaderFooterParser::getCurrHeight() const
848cdf0e10cSrcweir {
849cdf0e10cSrcweir return getCurrHeight( meCurrPortion );
850cdf0e10cSrcweir }
851cdf0e10cSrcweir
updateCurrHeight(HFPortionId ePortion)852cdf0e10cSrcweir void HeaderFooterParser::updateCurrHeight( HFPortionId ePortion )
853cdf0e10cSrcweir {
854cdf0e10cSrcweir double& rfMaxHt = maPortions[ ePortion ].mfCurrHeight;
855cdf0e10cSrcweir rfMaxHt = ::std::max( rfMaxHt, maFontModel.mfHeight );
856cdf0e10cSrcweir }
857cdf0e10cSrcweir
updateCurrHeight()858cdf0e10cSrcweir void HeaderFooterParser::updateCurrHeight()
859cdf0e10cSrcweir {
860cdf0e10cSrcweir updateCurrHeight( meCurrPortion );
861cdf0e10cSrcweir }
862cdf0e10cSrcweir
setAttributes()863cdf0e10cSrcweir void HeaderFooterParser::setAttributes()
864cdf0e10cSrcweir {
865cdf0e10cSrcweir Reference< XTextRange > xRange( getStartPos(), UNO_QUERY );
866cdf0e10cSrcweir getEndPos()->gotoRange( xRange, sal_False );
867cdf0e10cSrcweir getEndPos()->gotoEnd( sal_True );
868cdf0e10cSrcweir if( !getEndPos()->isCollapsed() )
869cdf0e10cSrcweir {
870cdf0e10cSrcweir Font aFont( *this, maFontModel );
871cdf0e10cSrcweir aFont.finalizeImport();
872cdf0e10cSrcweir PropertySet aPropSet( getEndPos() );
873cdf0e10cSrcweir aFont.writeToPropertySet( aPropSet, FONT_PROPTYPE_TEXT );
874cdf0e10cSrcweir getStartPos()->gotoEnd( sal_False );
875cdf0e10cSrcweir getEndPos()->gotoEnd( sal_False );
876cdf0e10cSrcweir }
877cdf0e10cSrcweir }
878cdf0e10cSrcweir
appendText()879cdf0e10cSrcweir void HeaderFooterParser::appendText()
880cdf0e10cSrcweir {
881cdf0e10cSrcweir if( maBuffer.getLength() > 0 )
882cdf0e10cSrcweir {
883cdf0e10cSrcweir getEndPos()->gotoEnd( sal_False );
884cdf0e10cSrcweir getEndPos()->setString( maBuffer.makeStringAndClear() );
885cdf0e10cSrcweir updateCurrHeight();
886cdf0e10cSrcweir }
887cdf0e10cSrcweir }
888cdf0e10cSrcweir
appendLineBreak()889cdf0e10cSrcweir void HeaderFooterParser::appendLineBreak()
890cdf0e10cSrcweir {
891cdf0e10cSrcweir getEndPos()->gotoEnd( sal_False );
892cdf0e10cSrcweir getEndPos()->setString( OUString( sal_Unicode( '\n' ) ) );
893cdf0e10cSrcweir getPortion().mfTotalHeight += getCurrHeight();
894cdf0e10cSrcweir getPortion().mfCurrHeight = 0;
895cdf0e10cSrcweir }
896cdf0e10cSrcweir
createField(const OUString & rServiceName) const897cdf0e10cSrcweir Reference< XTextContent > HeaderFooterParser::createField( const OUString& rServiceName ) const
898cdf0e10cSrcweir {
899cdf0e10cSrcweir Reference< XTextContent > xContent;
900cdf0e10cSrcweir try
901cdf0e10cSrcweir {
902cdf0e10cSrcweir xContent.set( getBaseFilter().getModelFactory()->createInstance( rServiceName ), UNO_QUERY_THROW );
903cdf0e10cSrcweir }
904cdf0e10cSrcweir catch( Exception& )
905cdf0e10cSrcweir {
906cdf0e10cSrcweir OSL_ENSURE( false,
907cdf0e10cSrcweir OStringBuffer( "HeaderFooterParser::createField - error while creating text field \"" ).
908cdf0e10cSrcweir append( OUStringToOString( rServiceName, RTL_TEXTENCODING_ASCII_US ) ).
909cdf0e10cSrcweir append( '"' ).getStr() );
910cdf0e10cSrcweir }
911cdf0e10cSrcweir return xContent;
912cdf0e10cSrcweir }
913cdf0e10cSrcweir
appendField(const Reference<XTextContent> & rxContent)914cdf0e10cSrcweir void HeaderFooterParser::appendField( const Reference< XTextContent >& rxContent )
915cdf0e10cSrcweir {
916cdf0e10cSrcweir getEndPos()->gotoEnd( sal_False );
917cdf0e10cSrcweir try
918cdf0e10cSrcweir {
919cdf0e10cSrcweir Reference< XTextRange > xRange( getEndPos(), UNO_QUERY_THROW );
920cdf0e10cSrcweir getPortion().mxText->insertTextContent( xRange, rxContent, sal_False );
921cdf0e10cSrcweir updateCurrHeight();
922cdf0e10cSrcweir }
923cdf0e10cSrcweir catch( Exception& )
924cdf0e10cSrcweir {
925cdf0e10cSrcweir }
926cdf0e10cSrcweir }
927cdf0e10cSrcweir
convertFontName(const OUString & rName)928cdf0e10cSrcweir void HeaderFooterParser::convertFontName( const OUString& rName )
929cdf0e10cSrcweir {
930cdf0e10cSrcweir if( rName.getLength() > 0 )
931cdf0e10cSrcweir {
932cdf0e10cSrcweir // single dash is document default font
933cdf0e10cSrcweir if( (rName.getLength() == 1) && (rName[ 0 ] == '-') )
934cdf0e10cSrcweir maFontModel.maName = getStyles().getDefaultFontModel().maName;
935cdf0e10cSrcweir else
936cdf0e10cSrcweir maFontModel.maName = rName;
937cdf0e10cSrcweir }
938cdf0e10cSrcweir }
939cdf0e10cSrcweir
convertFontStyle(const OUString & rStyle)940cdf0e10cSrcweir void HeaderFooterParser::convertFontStyle( const OUString& rStyle )
941cdf0e10cSrcweir {
942cdf0e10cSrcweir maFontModel.mbBold = maFontModel.mbItalic = false;
943cdf0e10cSrcweir sal_Int32 nPos = 0;
944cdf0e10cSrcweir sal_Int32 nLen = rStyle.getLength();
945cdf0e10cSrcweir while( (0 <= nPos) && (nPos < nLen) )
946cdf0e10cSrcweir {
947cdf0e10cSrcweir OString aToken = OUStringToOString( rStyle.getToken( 0, ' ', nPos ), RTL_TEXTENCODING_UTF8 ).toAsciiLowerCase();
948cdf0e10cSrcweir if( aToken.getLength() > 0 )
949cdf0e10cSrcweir {
950cdf0e10cSrcweir if( maBoldNames.count( aToken ) > 0 )
951cdf0e10cSrcweir maFontModel.mbBold = true;
952cdf0e10cSrcweir else if( maItalicNames.count( aToken ) > 0 )
953cdf0e10cSrcweir maFontModel.mbItalic = true;
954cdf0e10cSrcweir }
955cdf0e10cSrcweir }
956cdf0e10cSrcweir }
957cdf0e10cSrcweir
convertFontColor(const OUString & rColor)958cdf0e10cSrcweir void HeaderFooterParser::convertFontColor( const OUString& rColor )
959cdf0e10cSrcweir {
960cdf0e10cSrcweir OSL_ENSURE( rColor.getLength() == 6, "HeaderFooterParser::convertFontColor - invalid font color code" );
961cdf0e10cSrcweir if( (rColor[ 2 ] == '+') || (rColor[ 2 ] == '-') )
962cdf0e10cSrcweir // theme color: TTSNNN (TT = decimal theme index, S = +/-, NNN = decimal tint/shade in percent)
963cdf0e10cSrcweir maFontModel.maColor.setTheme(
964cdf0e10cSrcweir rColor.copy( 0, 2 ).toInt32(),
965cdf0e10cSrcweir static_cast< double >( rColor.copy( 2 ).toInt32() ) / 100.0 );
966cdf0e10cSrcweir else
967cdf0e10cSrcweir // RGB color: RRGGBB
968cdf0e10cSrcweir maFontModel.maColor.setRgb( rColor.toInt32( 16 ) );
969cdf0e10cSrcweir }
970cdf0e10cSrcweir
finalizePortion()971cdf0e10cSrcweir void HeaderFooterParser::finalizePortion()
972cdf0e10cSrcweir {
973cdf0e10cSrcweir appendText();
974cdf0e10cSrcweir setAttributes();
975cdf0e10cSrcweir }
976cdf0e10cSrcweir
setNewPortion(HFPortionId ePortion)977cdf0e10cSrcweir void HeaderFooterParser::setNewPortion( HFPortionId ePortion )
978cdf0e10cSrcweir {
979cdf0e10cSrcweir if( ePortion != meCurrPortion )
980cdf0e10cSrcweir {
981cdf0e10cSrcweir finalizePortion();
982cdf0e10cSrcweir meCurrPortion = ePortion;
983cdf0e10cSrcweir maFontModel = getStyles().getDefaultFontModel();
984cdf0e10cSrcweir }
985cdf0e10cSrcweir }
986cdf0e10cSrcweir
987cdf0e10cSrcweir // ============================================================================
988cdf0e10cSrcweir
989cdf0e10cSrcweir namespace {
990cdf0e10cSrcweir
991cdf0e10cSrcweir /** Paper size in 1/100 millimeters. */
992cdf0e10cSrcweir struct ApiPaperSize
993cdf0e10cSrcweir {
994cdf0e10cSrcweir sal_Int32 mnWidth;
995cdf0e10cSrcweir sal_Int32 mnHeight;
996cdf0e10cSrcweir };
997cdf0e10cSrcweir
998cdf0e10cSrcweir #define IN2MM100( v ) static_cast< sal_Int32 >( (v) * 2540.0 + 0.5 )
999cdf0e10cSrcweir #define MM2MM100( v ) static_cast< sal_Int32 >( (v) * 100.0 + 0.5 )
1000cdf0e10cSrcweir
1001cdf0e10cSrcweir static const ApiPaperSize spPaperSizeTable[] =
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir { 0, 0 }, // 0 - (undefined)
1004cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 11 ) }, // 1 - Letter paper
1005cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 11 ) }, // 2 - Letter small paper
1006cdf0e10cSrcweir { IN2MM100( 11 ), IN2MM100( 17 ) }, // 3 - Tabloid paper
1007cdf0e10cSrcweir { IN2MM100( 17 ), IN2MM100( 11 ) }, // 4 - Ledger paper
1008cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 14 ) }, // 5 - Legal paper
1009cdf0e10cSrcweir { IN2MM100( 5.5 ), IN2MM100( 8.5 ) }, // 6 - Statement paper
1010cdf0e10cSrcweir { IN2MM100( 7.25 ), IN2MM100( 10.5 ) }, // 7 - Executive paper
1011cdf0e10cSrcweir { MM2MM100( 297 ), MM2MM100( 420 ) }, // 8 - A3 paper
1012cdf0e10cSrcweir { MM2MM100( 210 ), MM2MM100( 297 ) }, // 9 - A4 paper
1013cdf0e10cSrcweir { MM2MM100( 210 ), MM2MM100( 297 ) }, // 10 - A4 small paper
1014cdf0e10cSrcweir { MM2MM100( 148 ), MM2MM100( 210 ) }, // 11 - A5 paper
1015cdf0e10cSrcweir { MM2MM100( 250 ), MM2MM100( 353 ) }, // 12 - B4 paper
1016cdf0e10cSrcweir { MM2MM100( 176 ), MM2MM100( 250 ) }, // 13 - B5 paper
1017cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 13 ) }, // 14 - Folio paper
1018cdf0e10cSrcweir { MM2MM100( 215 ), MM2MM100( 275 ) }, // 15 - Quarto paper
1019cdf0e10cSrcweir { IN2MM100( 10 ), IN2MM100( 14 ) }, // 16 - Standard paper
1020cdf0e10cSrcweir { IN2MM100( 11 ), IN2MM100( 17 ) }, // 17 - Standard paper
1021cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 11 ) }, // 18 - Note paper
1022cdf0e10cSrcweir { IN2MM100( 3.875 ), IN2MM100( 8.875 ) }, // 19 - #9 envelope
1023cdf0e10cSrcweir { IN2MM100( 4.125 ), IN2MM100( 9.5 ) }, // 20 - #10 envelope
1024cdf0e10cSrcweir { IN2MM100( 4.5 ), IN2MM100( 10.375 ) }, // 21 - #11 envelope
1025cdf0e10cSrcweir { IN2MM100( 4.75 ), IN2MM100( 11 ) }, // 22 - #12 envelope
1026cdf0e10cSrcweir { IN2MM100( 5 ), IN2MM100( 11.5 ) }, // 23 - #14 envelope
1027cdf0e10cSrcweir { IN2MM100( 17 ), IN2MM100( 22 ) }, // 24 - C paper
1028cdf0e10cSrcweir { IN2MM100( 22 ), IN2MM100( 34 ) }, // 25 - D paper
1029cdf0e10cSrcweir { IN2MM100( 34 ), IN2MM100( 44 ) }, // 26 - E paper
1030cdf0e10cSrcweir { MM2MM100( 110 ), MM2MM100( 220 ) }, // 27 - DL envelope
1031cdf0e10cSrcweir { MM2MM100( 162 ), MM2MM100( 229 ) }, // 28 - C5 envelope
1032cdf0e10cSrcweir { MM2MM100( 324 ), MM2MM100( 458 ) }, // 29 - C3 envelope
1033cdf0e10cSrcweir { MM2MM100( 229 ), MM2MM100( 324 ) }, // 30 - C4 envelope
1034cdf0e10cSrcweir { MM2MM100( 114 ), MM2MM100( 162 ) }, // 31 - C6 envelope
1035cdf0e10cSrcweir { MM2MM100( 114 ), MM2MM100( 229 ) }, // 32 - C65 envelope
1036cdf0e10cSrcweir { MM2MM100( 250 ), MM2MM100( 353 ) }, // 33 - B4 envelope
1037cdf0e10cSrcweir { MM2MM100( 176 ), MM2MM100( 250 ) }, // 34 - B5 envelope
1038cdf0e10cSrcweir { MM2MM100( 176 ), MM2MM100( 125 ) }, // 35 - B6 envelope
1039cdf0e10cSrcweir { MM2MM100( 110 ), MM2MM100( 230 ) }, // 36 - Italy envelope
1040cdf0e10cSrcweir { IN2MM100( 3.875 ), IN2MM100( 7.5 ) }, // 37 - Monarch envelope
1041cdf0e10cSrcweir { IN2MM100( 3.625 ), IN2MM100( 6.5 ) }, // 38 - 6 3/4 envelope
1042cdf0e10cSrcweir { IN2MM100( 14.875 ), IN2MM100( 11 ) }, // 39 - US standard fanfold
1043cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 12 ) }, // 40 - German standard fanfold
1044cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 13 ) }, // 41 - German legal fanfold
1045cdf0e10cSrcweir { MM2MM100( 250 ), MM2MM100( 353 ) }, // 42 - ISO B4
1046cdf0e10cSrcweir { MM2MM100( 200 ), MM2MM100( 148 ) }, // 43 - Japanese double postcard
1047cdf0e10cSrcweir { IN2MM100( 9 ), IN2MM100( 11 ) }, // 44 - Standard paper
1048cdf0e10cSrcweir { IN2MM100( 10 ), IN2MM100( 11 ) }, // 45 - Standard paper
1049cdf0e10cSrcweir { IN2MM100( 15 ), IN2MM100( 11 ) }, // 46 - Standard paper
1050cdf0e10cSrcweir { MM2MM100( 220 ), MM2MM100( 220 ) }, // 47 - Invite envelope
1051cdf0e10cSrcweir { 0, 0 }, // 48 - (undefined)
1052cdf0e10cSrcweir { 0, 0 }, // 49 - (undefined)
1053cdf0e10cSrcweir { IN2MM100( 9.275 ), IN2MM100( 12 ) }, // 50 - Letter extra paper
1054cdf0e10cSrcweir { IN2MM100( 9.275 ), IN2MM100( 15 ) }, // 51 - Legal extra paper
1055cdf0e10cSrcweir { IN2MM100( 11.69 ), IN2MM100( 18 ) }, // 52 - Tabloid extra paper
1056cdf0e10cSrcweir { MM2MM100( 236 ), MM2MM100( 322 ) }, // 53 - A4 extra paper
1057cdf0e10cSrcweir { IN2MM100( 8.275 ), IN2MM100( 11 ) }, // 54 - Letter transverse paper
1058cdf0e10cSrcweir { MM2MM100( 210 ), MM2MM100( 297 ) }, // 55 - A4 transverse paper
1059cdf0e10cSrcweir { IN2MM100( 9.275 ), IN2MM100( 12 ) }, // 56 - Letter extra transverse paper
1060cdf0e10cSrcweir { MM2MM100( 227 ), MM2MM100( 356 ) }, // 57 - SuperA/SuperA/A4 paper
1061cdf0e10cSrcweir { MM2MM100( 305 ), MM2MM100( 487 ) }, // 58 - SuperB/SuperB/A3 paper
1062cdf0e10cSrcweir { IN2MM100( 8.5 ), IN2MM100( 12.69 ) }, // 59 - Letter plus paper
1063cdf0e10cSrcweir { MM2MM100( 210 ), MM2MM100( 330 ) }, // 60 - A4 plus paper
1064cdf0e10cSrcweir { MM2MM100( 148 ), MM2MM100( 210 ) }, // 61 - A5 transverse paper
1065cdf0e10cSrcweir { MM2MM100( 182 ), MM2MM100( 257 ) }, // 62 - JIS B5 transverse paper
1066cdf0e10cSrcweir { MM2MM100( 322 ), MM2MM100( 445 ) }, // 63 - A3 extra paper
1067cdf0e10cSrcweir { MM2MM100( 174 ), MM2MM100( 235 ) }, // 64 - A5 extra paper
1068cdf0e10cSrcweir { MM2MM100( 201 ), MM2MM100( 276 ) }, // 65 - ISO B5 extra paper
1069cdf0e10cSrcweir { MM2MM100( 420 ), MM2MM100( 594 ) }, // 66 - A2 paper
1070cdf0e10cSrcweir { MM2MM100( 297 ), MM2MM100( 420 ) }, // 67 - A3 transverse paper
1071cdf0e10cSrcweir { MM2MM100( 322 ), MM2MM100( 445 ) } // 68 - A3 extra transverse paper
1072cdf0e10cSrcweir };
1073cdf0e10cSrcweir
1074cdf0e10cSrcweir } // namespace
1075cdf0e10cSrcweir
1076cdf0e10cSrcweir // ----------------------------------------------------------------------------
1077cdf0e10cSrcweir
HFHelperData(sal_Int32 nLeftPropId,sal_Int32 nRightPropId)1078cdf0e10cSrcweir PageSettingsConverter::HFHelperData::HFHelperData( sal_Int32 nLeftPropId, sal_Int32 nRightPropId ) :
1079cdf0e10cSrcweir mnLeftPropId( nLeftPropId ),
1080cdf0e10cSrcweir mnRightPropId( nRightPropId ),
1081cdf0e10cSrcweir mnHeight( 0 ),
1082cdf0e10cSrcweir mnBodyDist( 0 ),
1083cdf0e10cSrcweir mbHasContent( false ),
1084cdf0e10cSrcweir mbShareOddEven( false ),
1085cdf0e10cSrcweir mbDynamicHeight( false )
1086cdf0e10cSrcweir {
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir
1089cdf0e10cSrcweir // ----------------------------------------------------------------------------
1090cdf0e10cSrcweir
PageSettingsConverter(const WorkbookHelper & rHelper)1091cdf0e10cSrcweir PageSettingsConverter::PageSettingsConverter( const WorkbookHelper& rHelper ) :
1092cdf0e10cSrcweir WorkbookHelper( rHelper ),
1093cdf0e10cSrcweir mxHFParser( new HeaderFooterParser( rHelper ) ),
1094cdf0e10cSrcweir maHeaderData( PROP_LeftPageHeaderContent, PROP_RightPageHeaderContent ),
1095cdf0e10cSrcweir maFooterData( PROP_LeftPageFooterContent, PROP_RightPageFooterContent )
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir }
1098cdf0e10cSrcweir
~PageSettingsConverter()1099cdf0e10cSrcweir PageSettingsConverter::~PageSettingsConverter()
1100cdf0e10cSrcweir {
1101cdf0e10cSrcweir }
1102cdf0e10cSrcweir
writePageSettingsProperties(PropertySet & rPropSet,const PageSettingsModel & rModel,WorksheetType eSheetType)1103cdf0e10cSrcweir void PageSettingsConverter::writePageSettingsProperties(
1104cdf0e10cSrcweir PropertySet& rPropSet, const PageSettingsModel& rModel, WorksheetType eSheetType )
1105cdf0e10cSrcweir {
1106cdf0e10cSrcweir // special handling for chart sheets
1107cdf0e10cSrcweir bool bChartSheet = eSheetType == SHEETTYPE_CHARTSHEET;
1108cdf0e10cSrcweir
1109cdf0e10cSrcweir // printout scaling
1110cdf0e10cSrcweir if( bChartSheet )
1111cdf0e10cSrcweir {
1112cdf0e10cSrcweir // always fit chart sheet to 1 page
1113cdf0e10cSrcweir rPropSet.setProperty< sal_Int16 >( PROP_ScaleToPages, 1 );
1114cdf0e10cSrcweir }
1115cdf0e10cSrcweir else if( rModel.mbFitToPages )
1116cdf0e10cSrcweir {
1117cdf0e10cSrcweir // fit to number of pages
1118cdf0e10cSrcweir rPropSet.setProperty( PROP_ScaleToPagesX, getLimitedValue< sal_Int16, sal_Int32 >( rModel.mnFitToWidth, 0, 1000 ) );
1119cdf0e10cSrcweir rPropSet.setProperty( PROP_ScaleToPagesY, getLimitedValue< sal_Int16, sal_Int32 >( rModel.mnFitToHeight, 0, 1000 ) );
1120cdf0e10cSrcweir }
1121cdf0e10cSrcweir else
1122cdf0e10cSrcweir {
1123cdf0e10cSrcweir // scale may be 0 which indicates uninitialized
1124cdf0e10cSrcweir sal_Int16 nScale = (rModel.mbValidSettings && (rModel.mnScale > 0)) ? getLimitedValue< sal_Int16, sal_Int32 >( rModel.mnScale, 10, 400 ) : 100;
1125cdf0e10cSrcweir rPropSet.setProperty( PROP_PageScale, nScale );
1126cdf0e10cSrcweir }
1127cdf0e10cSrcweir
1128cdf0e10cSrcweir // paper orientation
1129cdf0e10cSrcweir bool bLandscape = rModel.mnOrientation == XML_landscape;
1130cdf0e10cSrcweir // default orientation for current sheet type (chart sheets default to landscape)
1131cdf0e10cSrcweir if( !rModel.mbValidSettings || (rModel.mnOrientation == XML_default) )
1132cdf0e10cSrcweir bLandscape = bChartSheet;
1133cdf0e10cSrcweir
1134cdf0e10cSrcweir // paper size
1135cdf0e10cSrcweir if( rModel.mbValidSettings && (0 < rModel.mnPaperSize) && (rModel.mnPaperSize < static_cast< sal_Int32 >( STATIC_ARRAY_SIZE( spPaperSizeTable ) )) )
1136cdf0e10cSrcweir {
1137cdf0e10cSrcweir const ApiPaperSize& rPaperSize = spPaperSizeTable[ rModel.mnPaperSize ];
1138cdf0e10cSrcweir Size aSize( rPaperSize.mnWidth, rPaperSize.mnHeight );
1139cdf0e10cSrcweir if( bLandscape )
1140cdf0e10cSrcweir ::std::swap( aSize.Width, aSize.Height );
1141cdf0e10cSrcweir rPropSet.setProperty( PROP_Size, aSize );
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir
1144cdf0e10cSrcweir // header/footer
1145cdf0e10cSrcweir convertHeaderFooterData( rPropSet, maHeaderData, rModel.maOddHeader, rModel.maEvenHeader, rModel.mbUseEvenHF, rModel.mfTopMargin, rModel.mfHeaderMargin );
1146cdf0e10cSrcweir convertHeaderFooterData( rPropSet, maFooterData, rModel.maOddFooter, rModel.maEvenFooter, rModel.mbUseEvenHF, rModel.mfBottomMargin, rModel.mfFooterMargin );
1147cdf0e10cSrcweir
1148cdf0e10cSrcweir // write all properties to property set
1149cdf0e10cSrcweir const UnitConverter& rUnitConv = getUnitConverter();
1150cdf0e10cSrcweir PropertyMap aPropMap;
1151cdf0e10cSrcweir aPropMap[ PROP_IsLandscape ] <<= bLandscape;
1152cdf0e10cSrcweir aPropMap[ PROP_FirstPageNumber ] <<= getLimitedValue< sal_Int16, sal_Int32 >( rModel.mbUseFirstPage ? rModel.mnFirstPage : 0, 0, 9999 );
1153cdf0e10cSrcweir aPropMap[ PROP_PrintDownFirst ] <<= (rModel.mnPageOrder == XML_downThenOver);
1154cdf0e10cSrcweir aPropMap[ PROP_PrintAnnotations ] <<= (rModel.mnCellComments == XML_asDisplayed);
1155cdf0e10cSrcweir aPropMap[ PROP_CenterHorizontally ] <<= rModel.mbHorCenter;
1156cdf0e10cSrcweir aPropMap[ PROP_CenterVertically ] <<= rModel.mbVerCenter;
1157cdf0e10cSrcweir aPropMap[ PROP_PrintGrid ] <<= (!bChartSheet && rModel.mbPrintGrid); // no gridlines in chart sheets
1158cdf0e10cSrcweir aPropMap[ PROP_PrintHeaders ] <<= (!bChartSheet && rModel.mbPrintHeadings); // no column/row headings in chart sheets
1159cdf0e10cSrcweir aPropMap[ PROP_LeftMargin ] <<= rUnitConv.scaleToMm100( rModel.mfLeftMargin, UNIT_INCH );
1160cdf0e10cSrcweir aPropMap[ PROP_RightMargin ] <<= rUnitConv.scaleToMm100( rModel.mfRightMargin, UNIT_INCH );
1161cdf0e10cSrcweir // #i23296# In Calc, "TopMargin" property is distance to top of header if enabled
1162cdf0e10cSrcweir aPropMap[ PROP_TopMargin ] <<= rUnitConv.scaleToMm100( maHeaderData.mbHasContent ? rModel.mfHeaderMargin : rModel.mfTopMargin, UNIT_INCH );
1163cdf0e10cSrcweir // #i23296# In Calc, "BottomMargin" property is distance to bottom of footer if enabled
1164cdf0e10cSrcweir aPropMap[ PROP_BottomMargin ] <<= rUnitConv.scaleToMm100( maFooterData.mbHasContent ? rModel.mfFooterMargin : rModel.mfBottomMargin, UNIT_INCH );
1165cdf0e10cSrcweir aPropMap[ PROP_HeaderIsOn ] <<= maHeaderData.mbHasContent;
1166cdf0e10cSrcweir aPropMap[ PROP_HeaderIsShared ] <<= maHeaderData.mbShareOddEven;
1167cdf0e10cSrcweir aPropMap[ PROP_HeaderIsDynamicHeight ] <<= maHeaderData.mbDynamicHeight;
1168cdf0e10cSrcweir aPropMap[ PROP_HeaderHeight ] <<= maHeaderData.mnHeight;
1169cdf0e10cSrcweir aPropMap[ PROP_HeaderBodyDistance ] <<= maHeaderData.mnBodyDist;
1170cdf0e10cSrcweir aPropMap[ PROP_FooterIsOn ] <<= maFooterData.mbHasContent;
1171cdf0e10cSrcweir aPropMap[ PROP_FooterIsShared ] <<= maFooterData.mbShareOddEven;
1172cdf0e10cSrcweir aPropMap[ PROP_FooterIsDynamicHeight ] <<= maFooterData.mbDynamicHeight;
1173cdf0e10cSrcweir aPropMap[ PROP_FooterHeight ] <<= maFooterData.mnHeight;
1174cdf0e10cSrcweir aPropMap[ PROP_FooterBodyDistance ] <<= maFooterData.mnBodyDist;
1175cdf0e10cSrcweir // background image
1176cdf0e10cSrcweir if( rModel.maGraphicUrl.getLength() > 0 )
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir aPropMap[ PROP_BackGraphicURL ] <<= rModel.maGraphicUrl;
1179cdf0e10cSrcweir aPropMap[ PROP_BackGraphicLocation ] <<= ::com::sun::star::style::GraphicLocation_TILED;
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir
1182cdf0e10cSrcweir rPropSet.setProperties( aPropMap );
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir
convertHeaderFooterData(PropertySet & rPropSet,HFHelperData & orHFData,const OUString rOddContent,const OUString rEvenContent,bool bUseEvenContent,double fPageMargin,double fContentMargin)1185cdf0e10cSrcweir void PageSettingsConverter::convertHeaderFooterData(
1186cdf0e10cSrcweir PropertySet& rPropSet, HFHelperData& orHFData,
1187cdf0e10cSrcweir const OUString rOddContent, const OUString rEvenContent, bool bUseEvenContent,
1188cdf0e10cSrcweir double fPageMargin, double fContentMargin )
1189cdf0e10cSrcweir {
1190cdf0e10cSrcweir bool bHasOddContent = rOddContent.getLength() > 0;
1191cdf0e10cSrcweir bool bHasEvenContent = bUseEvenContent && (rEvenContent.getLength() > 0);
1192cdf0e10cSrcweir
1193cdf0e10cSrcweir sal_Int32 nOddHeight = bHasOddContent ? writeHeaderFooter( rPropSet, orHFData.mnRightPropId, rOddContent ) : 0;
1194cdf0e10cSrcweir sal_Int32 nEvenHeight = bHasEvenContent ? writeHeaderFooter( rPropSet, orHFData.mnLeftPropId, rEvenContent ) : 0;
1195cdf0e10cSrcweir
1196cdf0e10cSrcweir orHFData.mnHeight = 750;
1197cdf0e10cSrcweir orHFData.mnBodyDist = 250;
1198cdf0e10cSrcweir orHFData.mbHasContent = bHasOddContent || bHasEvenContent;
1199cdf0e10cSrcweir orHFData.mbShareOddEven = !bUseEvenContent;
1200cdf0e10cSrcweir orHFData.mbDynamicHeight = true;
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir if( orHFData.mbHasContent )
1203cdf0e10cSrcweir {
1204cdf0e10cSrcweir // use maximum height of odd/even header/footer
1205cdf0e10cSrcweir orHFData.mnHeight = ::std::max( nOddHeight, nEvenHeight );
1206cdf0e10cSrcweir /* Calc contains distance between bottom of header and top of page
1207cdf0e10cSrcweir body in "HeaderBodyDistance" property, and distance between bottom
1208cdf0e10cSrcweir of page body and top of footer in "FooterBodyDistance" property */
1209cdf0e10cSrcweir orHFData.mnBodyDist = getUnitConverter().scaleToMm100( fPageMargin - fContentMargin, UNIT_INCH ) - orHFData.mnHeight;
1210cdf0e10cSrcweir /* #i23296# Distance less than 0 means, header or footer overlays page
1211cdf0e10cSrcweir body. As this is not possible in Calc, set fixed header or footer
1212cdf0e10cSrcweir height (crop header/footer) to get correct top position of page body. */
1213cdf0e10cSrcweir orHFData.mbDynamicHeight = orHFData.mnBodyDist >= 0;
1214cdf0e10cSrcweir /* "HeaderHeight" property is in fact distance from top of header to
1215cdf0e10cSrcweir top of page body (including "HeaderBodyDistance").
1216cdf0e10cSrcweir "FooterHeight" property is in fact distance from bottom of page
1217cdf0e10cSrcweir body to bottom of footer (including "FooterBodyDistance"). */
1218cdf0e10cSrcweir orHFData.mnHeight += orHFData.mnBodyDist;
1219cdf0e10cSrcweir // negative body distance not allowed
1220cdf0e10cSrcweir orHFData.mnBodyDist = ::std::max< sal_Int32 >( orHFData.mnBodyDist, 0 );
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir
writeHeaderFooter(PropertySet & rPropSet,sal_Int32 nPropId,const OUString & rContent)1224cdf0e10cSrcweir sal_Int32 PageSettingsConverter::writeHeaderFooter(
1225cdf0e10cSrcweir PropertySet& rPropSet, sal_Int32 nPropId, const OUString& rContent )
1226cdf0e10cSrcweir {
1227cdf0e10cSrcweir OSL_ENSURE( rContent.getLength() > 0, "PageSettingsConverter::writeHeaderFooter - empty h/f string found" );
1228cdf0e10cSrcweir sal_Int32 nHeight = 0;
1229cdf0e10cSrcweir if( rContent.getLength() > 0 )
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir Reference< XHeaderFooterContent > xHFContent( rPropSet.getAnyProperty( nPropId ), UNO_QUERY );
1232cdf0e10cSrcweir if( xHFContent.is() )
1233cdf0e10cSrcweir {
1234cdf0e10cSrcweir double fTotalHeight = mxHFParser->parse( xHFContent, rContent );
1235cdf0e10cSrcweir rPropSet.setProperty( nPropId, xHFContent );
1236cdf0e10cSrcweir nHeight = getUnitConverter().scaleToMm100( fTotalHeight, UNIT_POINT );
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir }
1239cdf0e10cSrcweir return nHeight;
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir
1242cdf0e10cSrcweir // ============================================================================
1243cdf0e10cSrcweir
1244cdf0e10cSrcweir } // namespace xls
1245cdf0e10cSrcweir } // namespace oox
1246