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