24#include <com/sun/star/awt/Size.hpp>
25#include <com/sun/star/container/XNamed.hpp>
26#include <com/sun/star/sheet/XHeaderFooterContent.hpp>
27#include <com/sun/star/sheet/XSpreadsheet.hpp>
28#include <com/sun/star/style/GraphicLocation.hpp>
29#include <com/sun/star/style/XStyle.hpp>
30#include <com/sun/star/text/FilenameDisplayFormat.hpp>
31#include <com/sun/star/text/XText.hpp>
32#include <com/sun/star/text/XTextCursor.hpp>
33#include <com/sun/star/lang/XMultiServiceFactory.hpp>
34#include <osl/diagnose.h>
35#include <rtl/strbuf.hxx>
36#include <rtl/ustrbuf.hxx>
43#include <oox/token/namespaces.hxx>
44#include <oox/token/properties.hxx>
45#include <oox/token/tokens.hxx>
49#include <document.hxx>
60using ::oox::core::Relations;
64const double OOX_MARGIN_DEFAULT_LR = 0.748;
65const double OOX_MARGIN_DEFAULT_TB = 0.984;
66const double OOX_MARGIN_DEFAULT_HF = 0.512;
68const sal_uInt16 BIFF12_PRINTOPT_HORCENTER = 0x0001;
69const sal_uInt16 BIFF12_PRINTOPT_VERCENTER = 0x0002;
70const sal_uInt16 BIFF12_PRINTOPT_PRINTHEADING = 0x0004;
71const sal_uInt16 BIFF12_PRINTOPT_PRINTGRID = 0x0008;
73const sal_uInt16 BIFF12_HEADERFOOTER_DIFFEVEN = 0x0001;
74const sal_uInt16 BIFF12_HEADERFOOTER_DIFFFIRST = 0x0002;
76const sal_uInt16 BIFF12_PAGESETUP_INROWS = 0x0001;
77const sal_uInt16 BIFF12_PAGESETUP_LANDSCAPE = 0x0002;
78const sal_uInt16 BIFF12_PAGESETUP_INVALID = 0x0004;
79const sal_uInt16 BIFF12_PAGESETUP_BLACKWHITE = 0x0008;
80const sal_uInt16 BIFF12_PAGESETUP_DRAFTQUALITY = 0x0010;
81const sal_uInt16 BIFF12_PAGESETUP_PRINTNOTES = 0x0020;
82const sal_uInt16 BIFF12_PAGESETUP_DEFAULTORIENT = 0x0040;
83const sal_uInt16 BIFF12_PAGESETUP_USEFIRSTPAGE = 0x0080;
84const sal_uInt16 BIFF12_PAGESETUP_NOTES_END = 0x0100;
86const sal_uInt16 BIFF12_CHARTPAGESETUP_LANDSCAPE = 0x0001;
87const sal_uInt16 BIFF12_CHARTPAGESETUP_INVALID = 0x0002;
88const sal_uInt16 BIFF12_CHARTPAGESETUP_BLACKWHITE = 0x0004;
89const sal_uInt16 BIFF12_CHARTPAGESETUP_DEFAULTORIENT= 0x0008;
90const sal_uInt16 BIFF12_CHARTPAGESETUP_USEFIRSTPAGE = 0x0010;
91const sal_uInt16 BIFF12_CHARTPAGESETUP_DRAFTQUALITY = 0x0020;
96 mfLeftMargin( OOX_MARGIN_DEFAULT_LR ),
97 mfRightMargin( OOX_MARGIN_DEFAULT_LR ),
98 mfTopMargin( OOX_MARGIN_DEFAULT_TB ),
99 mfBottomMargin( OOX_MARGIN_DEFAULT_TB ),
100 mfHeaderMargin( OOX_MARGIN_DEFAULT_HF ),
101 mfFooterMargin( OOX_MARGIN_DEFAULT_HF ),
110 mnHorPrintRes( 600 ),
111 mnVerPrintRes( 600 ),
112 mnOrientation( XML_default ),
113 mnPageOrder( XML_downThenOver ),
115 mnPrintErrors( XML_displayed ),
116 mbUseEvenHF( false ),
117 mbUseFirstHF( false ),
118 mbValidSettings( true ),
119 mbUseFirstPage( false ),
120 mbBlackWhite( false ),
121 mbDraftQuality( false ),
122 mbFitToPages( false ),
123 mbHorCenter( false ),
124 mbVerCenter( false ),
125 mbPrintGrid( false ),
126 mbPrintHeadings( false )
132 static const sal_Int32 spnErrorIds[] = { XML_displayed,
XML_none, XML_dash, XML_NA };
246 nFlags =
rStrm.readuInt16();
265 nFlags =
rStrm.readuInt16();
281 sal_uInt16 nFirstPage, nFlags;
286 nFirstPage =
rStrm.readuInt16();
287 nFlags =
rStrm.readuInt16();
301 nFlags =
rStrm.readuInt16();
321 OUStringBuffer aStyleNameBuffer(
"PageStyle_" );
322 Reference<container::XNamed> xSheetName(
getSheet(), UNO_QUERY);
323 if( xSheetName.is() )
324 aStyleNameBuffer.append( xSheetName->getName() );
326 aStyleNameBuffer.append(
static_cast< sal_Int32
>(
getSheetIndex() + 1 ) );
327 OUString aStyleName = aStyleNameBuffer.makeStringAndClear();
340 OUString aPicturePath = rRelations.getFragmentPathFromRelId(rRelId);
341 if (!aPicturePath.isEmpty())
365 bool initialize(
const Reference<text::XText>& rxText );
370bool HFPortionInfo::initialize(
const Reference<text::XText>& rxText )
380 OSL_ENSURE( bRet,
"HFPortionInfo::initialize - missing interfaces" );
392 const Reference<sheet::XHeaderFooterContent>& rxContext,
393 const OUString& rData );
419 Reference<text::XTextContent>
createField(
const OUString& rServiceName )
const;
421 void appendField(
const Reference<text::XTextContent>& rxContent );
449const char*
const sppcBoldNames[] =
457 "f\303\251lk\303\266v\303\251r"
461const char*
const sppcItalicNames[] =
481 maBoldNames( sppcBoldNames, sppcBoldNames +
SAL_N_ELEMENTS(sppcBoldNames) ),
482 maItalicNames( sppcItalicNames, sppcItalicNames +
SAL_N_ELEMENTS(sppcItalicNames) ),
483 maPortions( static_cast< size_t >( HF_COUNT ) ),
484 meCurrPortion( HF_CENTER )
490 if( !rxContext.is() || rData.isEmpty() ||
491 !
maPortions[ HF_LEFT ].initialize( rxContext->getLeftText() ) ||
492 !
maPortions[ HF_CENTER ].initialize( rxContext->getCenterText() ) ||
493 !
maPortions[ HF_RIGHT ].initialize( rxContext->getRightText() ) )
499 OUStringBuffer aFontName;
500 OUStringBuffer aFontStyle;
501 sal_Int32 nFontHeight = 0;
515 const sal_Unicode* pcEnd = pcChar + rData.getLength();
516 for( ; (pcChar != pcEnd) && (*pcChar != 0); ++pcChar )
527 eState = STATE_TOKEN;
544 if( (
'a' <= cChar) && (cChar <=
'z') )
545 cChar = (cChar -
'a') +
'A';
548 case '&':
maBuffer.append( cChar );
break;
568 aPropSet.
setProperty( PROP_FileFormat, css::text::FilenameDisplayFormat::NAME_AND_EXT );
577 aPropSet.
setProperty( PROP_FileFormat, css::text::FilenameDisplayFormat::FULL );
581 if( (pcChar + 2 < pcEnd) && (pcChar[ 1 ] ==
'&') && ((pcChar[ 2 ] ==
'f') || (pcChar[ 2 ] ==
'F')) )
640 if( pcChar + 6 < pcEnd )
650 aFontName.setLength( 0 );
651 aFontStyle.setLength( 0 );
652 eState = STATE_FONTNAME;
655 if( (
'0' <= cChar) && (cChar <=
'9') )
657 nFontHeight = cChar -
'0';
658 eState = STATE_FONTHEIGHT;
674 eState = STATE_FONTSTYLE;
677 aFontName.append( cChar );
682 case STATE_FONTSTYLE:
690 aFontStyle.setLength(0);
694 aFontStyle.append( cChar );
699 case STATE_FONTHEIGHT:
701 if( (
'0' <= cChar) && (cChar <=
'9') )
703 if( nFontHeight >= 0 )
706 nFontHeight += (cChar -
'0');
707 if( nFontHeight > 1000 )
713 if( nFontHeight > 0 )
740 double fMaxHt =
maPortions[ ePortion ].mfCurrHeight;
746 double& rfMaxHt =
maPortions[ ePortion ].mfCurrHeight;
757 Reference<text::XTextRange> xRange =
getStartPos();
784 getEndPos()->setString( OUString(
'\n' ) );
791 Reference<text::XTextContent> xContent;
798 OSL_FAIL( OStringBuffer(
"HeaderFooterParser::createField - error while creating text field \""
810 Reference<text::XTextRange> xRange(
getEndPos(), UNO_QUERY_THROW );
811 getPortion().mxText->insertTextContent( xRange, rxContent,
false );
821 if( !rName.isEmpty() )
824 if( (rName.getLength() == 1) && (rName[ 0 ] ==
'-') )
836 for( sal_Int32
nPos{ 0 };
nPos>=0; )
839 if( !aToken.isEmpty() )
851 OSL_ENSURE( aColor.size() == 6,
"HeaderFooterParser::convertFontColor - invalid font color code" );
852 if( (aColor[ 2 ] ==
'+') || (aColor[ 2 ] ==
'-') )
856 static_cast< double >(
o3tl::toInt32(aColor.substr( 2 )) ) / 100.0 );
879 mnLeftPropId( nLeftPropId ),
880 mnRightPropId( nRightPropId ),
881 mnFirstPropId( nFirstPropId ),
884 mbHasContent( false ),
885 mbShareOddEven( false ),
886 mbShareFirst( false ),
887 mbDynamicHeight( false )
894 maHeaderData( PROP_LeftPageHeaderContent, PROP_RightPageHeaderContent, PROP_FirstPageHeaderContent ),
895 maFooterData( PROP_LeftPageFooterContent, PROP_RightPageFooterContent, PROP_FirstPageFooterContent )
924 sal_Int16 nScale = (rModel.
mnScale > 0) ? getLimitedValue< sal_Int16, sal_Int32 >( rModel.
mnScale, 10, 400 ) : 100;
955 ::std::swap( aSize.Width, aSize.Height );
1004 const OUString& rOddContent,
const OUString& rEvenContent,
const OUString& rFirstContent,
1005 bool bUseEvenContent,
bool bUseFirstContent,
1006 double fPageMargin,
double fContentMargin )
1008 bool bHasOddContent = !rOddContent.isEmpty();
1009 bool bHasEvenContent = bUseEvenContent && !rEvenContent.isEmpty();
1010 bool bHasFirstContent = bUseFirstContent && !rFirstContent.isEmpty();
1018 orHFData.
mbHasContent = bHasOddContent || bHasEvenContent || bHasFirstContent;
1027 orHFData.
mnHeight = ::std::max( ::std::max( nOddHeight, nEvenHeight ), nFirstHeight );
1046 PropertySet& rPropSet, sal_Int32 nPropId,
const OUString& rContent )
1048 OSL_ENSURE( !rContent.isEmpty(),
"PageSettingsConverter::writeHeaderFooter - empty h/f string found" );
1049 sal_Int32 nHeight = 0;
1050 if( !rContent.isEmpty() )
1052 Reference<sheet::XHeaderFooterContent> xHFContent(rPropSet.
getAnyProperty(nPropId), UNO_QUERY);
1053 if( xHFContent.is() )
1055 double fTotalHeight =
mxHFParser->parse( xHFContent, rContent );
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
SC_DLLPUBLIC void SetPageStyle(SCTAB nTab, const OUString &rName)
static const ApiPaperSize & getApiSizeForMSPaperSizeIndex(sal_Int32 nMSOPaperIndex)
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
std::optional< bool > getBool(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
std::optional< double > getDouble(sal_Int32 nAttrToken) const
css::uno::Reference< css::graphic::XGraphic > importEmbeddedGraphic(const OUString &rStreamName, const WmfExternal *pExtHeader=nullptr) const
bool setProperty(sal_Int32 nPropId, Type &&rValue)
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
bool setProperty(sal_Int32 nPropId, const Type &rValue)
GraphicHelper & getGraphicHelper() const
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
void setRgb(::Color nRgbValue, double fTint=0.0)
Sets the color to the passed RGB value.
void setTheme(sal_Int32 nThemeIdx, double fTint=0.0)
Sets the color to the passed theme index.
void writeToPropertySet(PropertySet &rPropSet) const
Writes all font attributes to the passed property set.
void finalizeImport()
Final processing after import of all style settings.
HFHelperData maHeaderData
void writePageSettingsProperties(PropertySet &rPropSet, const PageSettingsModel &rModel, WorksheetType eSheetType)
Writes all properties to the passed property set of a page style object.
PageSettingsConverter(const WorkbookHelper &rHelper)
void convertHeaderFooterData(PropertySet &rPropSet, HFHelperData &orHFData, const OUString &rOddContent, const OUString &rEvenContent, const OUString &rFirstContent, bool bUseEvenContent, bool bUseFirstContent, double fPageMargin, double fContentMargin)
HeaderFooterParserPtr mxHFParser
virtual ~PageSettingsConverter() override
HFHelperData maFooterData
sal_Int32 writeHeaderFooter(PropertySet &rPropSet, sal_Int32 nPropId, const OUString &rContent)
void importChartPageSetup(const ::oox::core::Relations &rRelations, const AttributeList &rAttribs)
Imports pageSetup element for chart sheets.
void importPictureData(const ::oox::core::Relations &rRelations, const OUString &rRelId)
Imports the binary picture data from the fragment with the passed identifier.
void importPrintOptions(const AttributeList &rAttribs)
Imports printing options from a printOptions element.
void importPageSetup(const ::oox::core::Relations &rRelations, const AttributeList &rAttribs)
Imports pageSetup element for worksheets.
void importPicture(const ::oox::core::Relations &rRelations, const AttributeList &rAttribs)
Imports the picture element.
void importHeaderFooterCharacters(std::u16string_view rChars, sal_Int32 nElement)
Imports header/footer characters from a headerFooter element.
void importPageMargins(const AttributeList &rAttribs)
Imports pageMarings element containing page margins.
void importHeaderFooter(const AttributeList &rAttribs)
Imports header and footer settings from a headerFooter element.
void setFitToPagesMode(bool bFitToPages)
Sets whether percentual scaling or fit to width/height scaling is used.
PageSettingsModel maModel
void finalizeImport()
Creates a page style for the spreadsheet and sets all page properties.
PageSettings(const WorksheetHelper &rHelper)
const FontModel & getDefaultFontModel() const
Returns the model of the default application font (used in the "Normal" cell style).
Helper class to provide access to global workbook data.
css::uno::Reference< css::style::XStyle > createStyleObject(OUString &orStyleName, bool bPageStyle) const
Creates and returns a com.sun.star.style.Style object for cells or pages.
PageSettingsConverter & getPageSettingsConverter() const
Returns the page and print settings converter.
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
WorksheetType getSheetType() const
Returns the type of this sheet.
ScDocument & getScDocument()
SCTAB getSheetIndex() const
Returns the index of the current sheet.
const css::uno::Reference< css::sheet::XSpreadsheet > & getSheet() const
Returns the XSpreadsheet interface of the current sheet.
static bool convertMeasure(sal_Int32 &rValue, std::u16string_view rString, sal_Int16 nTargetUnit=css::util::MeasureUnit::MM_100TH, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
#define STATIC_ARRAY_SELECT(array, index, def)
#define SAL_N_ELEMENTS(arr)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
sal_uInt32 toUInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr OUStringLiteral gaDateTimeService(u"com.sun.star.text.TextField.DateTime")
constexpr OUStringLiteral gaSheetNameService(u"com.sun.star.text.TextField.SheetName")
constexpr OUStringLiteral gaPageCountService(u"com.sun.star.text.TextField.PageCount")
constexpr OUStringLiteral gaPageNumberService(u"com.sun.star.text.TextField.PageNumber")
constexpr OUStringLiteral gaFileNameService(u"com.sun.star.text.TextField.FileName")
WorksheetType
An enumeration for all types of sheets in a workbook.
ReturnType getFlagValue(Type nBitField, Type nMask, ReturnType nSet, ReturnType nUnset)
bool getFlag(Type nBitField, Type nMask)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Reference< text::XText > mxText
double mfTotalHeight
End position of current text range for formatting.
double mfCurrHeight
Sum of heights of previous lines in points.
Reference< text::XTextCursor > mxEnd
Start position of current text range for formatting.
Reference< text::XTextCursor > mxStart
XText interface of this portion.
Contains all XML font attributes, e.g.
bool mbShadow
True = outlined characters.
bool mbItalic
True = bold characters.
bool mbOutline
True = Strike out characters.
sal_Int32 mnEscapement
Underline style.
sal_Int32 mnUnderline
Font height in points.
bool mbBold
Escapement style.
double mfHeight
Windows font character set.
bool mbStrikeout
True = italic characters.
HFHelperData(sal_Int32 nLeftPropId, sal_Int32 nRightPropId, sal_Int32 nFirstPropId)
Holds page style data for a single sheet.
sal_Int32 mnFirstPage
Page scale (zoom in percent).
bool mbDraftQuality
True = print black and white.
sal_Int32 mnOrientation
Vertical printing resolution in DPI.
double mfLeftMargin
Footer string for first page of the sheet.
sal_Int32 mnCopies
Paper height in twips.
double mfTopMargin
Margin between end of sheet area and right edge of page.
void setBiffPrintErrors(sal_uInt8 nPrintErrors)
Sets the BIFF print errors mode.
bool mbPrintHeadings
True = print grid lines.
PageSettingsModel()
True = print column/row headings.
double mfFooterMargin
Margin between top edge of page and begin of header.
sal_Int32 mnHorPrintRes
Fit to number of pages in vertical direction.
sal_Int32 mnScale
Number of copies to print.
bool mbUseFirstHF
True = use maEvenHeader/maEvenFooter.
sal_Int32 mnFitToWidth
First page number.
double mfHeaderMargin
Margin between end of sheet area and bottom edge of page.
OUString maOddHeader
Relation identifier of binary printer settings.
bool mbHorCenter
True = Fit to width/height; false = scale in percent.
bool mbFitToPages
True = print in draft quality.
sal_Int32 mnPrintErrors
Cell comments printing mode.
OUString maEvenFooter
Header string for even pages.
sal_Int32 mnPaperSize
Margin between end of footer and bottom edge of page.
bool mbValidSettings
True = use maFirstHeader/maFirstFooter.
sal_Int32 mnPageOrder
Landscape or portrait.
OUString maFirstHeader
Footer string for even pages.
double mfBottomMargin
Margin between top edge of page and begin of sheet area.
OUString maFirstFooter
Header string for first page of the sheet.
OUString maEvenHeader
Footer string for odd pages.
sal_Int32 mnPaperHeight
Paper width in twips.
sal_Int32 mnPaperWidth
Paper size (enumeration).
bool mbBlackWhite
True = start page numbering with mnFirstPage.
sal_Int32 mnFitToHeight
Fit to number of pages in horizontal direction.
double mfRightMargin
Margin between left edge of page and begin of sheet area.
OUString maBinSettPath
Background Graphic.
sal_Int32 mnCellComments
Page order through sheet area (to left or down).
css::uno::Reference< css::graphic::XGraphic > mxGraphic
bool mbPrintGrid
True = vertically centered.
bool mbUseEvenHF
Cell error printing mode.
bool mbVerCenter
True = horizontally centered.
OUString maOddFooter
Header string for odd pages.
sal_Int32 mnVerPrintRes
Horizontal printing resolution in DPI.
bool mbUseFirstPage
True = use imported settings.
constexpr OUStringLiteral PROP_PageScale
constexpr OUStringLiteral PROP_TopMargin
constexpr OUStringLiteral PROP_BackGraphicLocation
constexpr OUStringLiteral PROP_PrintDownFirst
constexpr OUStringLiteral PROP_ScaleToPagesX
constexpr OUStringLiteral PROP_PrintGrid
constexpr OUStringLiteral PROP_CenterVertically
constexpr OUStringLiteral PROP_BottomMargin
constexpr OUStringLiteral PROP_HeaderBodyDistance
constexpr OUStringLiteral PROP_ScaleToPages
constexpr OUStringLiteral PROP_FooterIsDynamicHeight
constexpr OUStringLiteral PROP_PrintHeaders
constexpr OUStringLiteral PROP_HeaderIsDynamicHeight
constexpr OUStringLiteral PROP_PrintAnnotations
constexpr OUStringLiteral PROP_IsLandscape
constexpr OUStringLiteral PROP_LeftMargin
constexpr OUStringLiteral PROP_BackGraphic
constexpr OUStringLiteral PROP_HeaderHeight
constexpr OUStringLiteral PROP_ScaleToPagesY
constexpr OUStringLiteral PROP_FooterHeight
constexpr OUStringLiteral PROP_RightMargin
constexpr OUStringLiteral PROP_CenterHorizontally
constexpr OUStringLiteral PROP_FooterBodyDistance
constexpr OUStringLiteral PROP_FirstPageNumber