1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <com/sun/star/awt/FontDescriptor.hpp>
24 #include <com/sun/star/table/CellHoriJustify.hpp>
25 #include <com/sun/star/table/CellOrientation.hpp>
26 #include <com/sun/star/table/BorderLine2.hpp>
27 #include <com/sun/star/util/CellProtection.hpp>
28 #include <oox/drawingml/color.hxx>
29 #include <oox/helper/graphichelper.hxx>
30 #include <oox/helper/refmap.hxx>
31 #include <oox/helper/refvector.hxx>
32 #include "numberformatsbuffer.hxx"
33 #include <editeng/svxenum.hxx>
34 #include <editeng/frmdir.hxx>
35 #include <attarray.hxx>
38 namespace oox
{ class SequenceInputStream
; }
40 namespace oox
{ class PropertySet
;
42 class AttributeList
; }
46 const sal_Int32 OOX_COLOR_WINDOWTEXT3
= 24; /// System window text color (BIFF3-BIFF4).
47 const sal_Int32 OOX_COLOR_WINDOWBACK3
= 25; /// System window background color (BIFF3-BIFF4).
48 const sal_Int32 OOX_COLOR_WINDOWTEXT
= 64; /// System window text color (BIFF5+).
49 const sal_Int32 OOX_COLOR_WINDOWBACK
= 65; /// System window background color (BIFF5+).
50 const sal_Int32 OOX_COLOR_BUTTONBACK
= 67; /// System button background color (face color).
51 const sal_Int32 OOX_COLOR_CHWINDOWTEXT
= 77; /// System window text color (BIFF8 charts).
52 const sal_Int32 OOX_COLOR_CHWINDOWBACK
= 78; /// System window background color (BIFF8 charts).
53 const sal_Int32 OOX_COLOR_CHBORDERAUTO
= 79; /// Automatic frame border (BIFF8 charts).
54 const sal_Int32 OOX_COLOR_NOTEBACK
= 80; /// Note background color.
55 const sal_Int32 OOX_COLOR_NOTETEXT
= 81; /// Note text color.
56 const sal_Int32 OOX_COLOR_FONTAUTO
= 0x7FFF; /// Font auto color (system window text color).
58 const sal_Int16 API_LINE_NONE
= 0;
59 const sal_Int16 API_LINE_HAIR
= 1;
60 const sal_Int16 API_LINE_THIN
= 15;
61 const sal_Int16 API_LINE_MEDIUM
= 35;
62 const sal_Int16 API_LINE_THICK
= 50;
64 const sal_Int16 API_ESCAPE_NONE
= 0; /// No escapement.
65 const sal_Int16 API_ESCAPE_SUPERSCRIPT
= 101; /// Superscript: raise characters automatically (magic value 101).
66 const sal_Int16 API_ESCAPE_SUBSCRIPT
= -101; /// Subscript: lower characters automatically (magic value -101).
68 const sal_Int8 API_ESCAPEHEIGHT_NONE
= 100; /// Relative character height if not escaped.
69 const sal_Int8 API_ESCAPEHEIGHT_DEFAULT
= 58; /// Relative character height if escaped.
71 /** Special implementation of the GraphicHelper for Excel palette and scheme
74 class ExcelGraphicHelper
: public GraphicHelper
, public WorkbookHelper
77 explicit ExcelGraphicHelper( const WorkbookHelper
& rHelper
);
79 /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
80 virtual ::Color
getSchemeColor( sal_Int32 nToken
) const override
;
81 /** Derived classes may implement to resolve a palette index to an RGB color. */
82 virtual ::Color
getPaletteColor( sal_Int32 nPaletteIdx
) const override
;
85 class Color
: public ::oox::drawingml::Color
88 /** Sets the color to automatic. */
90 /** Sets the color to the passed RGB value. */
91 void setRgb( ::Color nRgbValue
, double fTint
= 0.0 );
92 /** Sets the color to the passed theme index. */
93 void setTheme( sal_Int32 nThemeIdx
, double fTint
= 0.0 );
94 /** Sets the color to the passed palette index. */
95 void setIndexed( sal_Int32 nPaletteIdx
, double fTint
= 0.0 );
97 /** Imports the color from the passed attribute list. */
98 void importColor( const AttributeList
& rAttribs
);
100 /** Imports a 64-bit color from the passed binary stream. */
101 void importColor( SequenceInputStream
& rStrm
);
102 /** Imports a 32-bit palette color identifier from the passed BIFF12 stream. */
103 void importColorId( SequenceInputStream
& rStrm
);
105 /** Returns true, if the color is set to automatic. */
106 bool isAuto() const { return isPlaceHolder(); }
109 SequenceInputStream
& operator>>( SequenceInputStream
& rStrm
, Color
& orColor
);
111 /** Stores all colors of the color palette. */
112 class ColorPalette
: public WorkbookHelper
115 /** Constructs the color palette with predefined color values. */
116 explicit ColorPalette( const WorkbookHelper
& rHelper
);
118 /** Appends a new color from the passed attributes. */
119 void importPaletteColor( const AttributeList
& rAttribs
);
120 /** Appends a new color from the passed RGBCOLOR record. */
121 void importPaletteColor( SequenceInputStream
& rStrm
);
123 /** Returns the RGB value of the color with the passed index. */
124 ::Color
getColor( sal_Int32 nPaletteIdx
) const;
127 /** Appends the passed color. */
128 void appendColor( ::Color nRGBValue
);
131 ::std::vector
< ::Color
> maColors
; /// List of RGB values.
132 size_t mnAppendIndex
; /// Index to append a new color.
135 /** Contains all XML font attributes, e.g. from a font or rPr element. */
138 OUString maName
; /// Font name.
139 Color maColor
; /// Font color.
140 sal_Int32 mnScheme
; /// Major/minor scheme font.
141 sal_Int32 mnFamily
; /// Font family.
142 sal_Int32 mnCharSet
; /// Windows font character set.
143 double mfHeight
; /// Font height in points.
144 sal_Int32 mnUnderline
; /// Underline style.
145 sal_Int32 mnEscapement
; /// Escapement style.
146 bool mbBold
; /// True = bold characters.
147 bool mbItalic
; /// True = italic characters.
148 bool mbStrikeout
; /// True = Strike out characters.
149 bool mbOutline
; /// True = outlined characters.
150 bool mbShadow
; /// True = shadowed chgaracters.
152 explicit FontModel();
154 void setBiff12Scheme( sal_uInt8 nScheme
);
155 void setBiffHeight( sal_uInt16 nHeight
);
156 void setBiffWeight( sal_uInt16 nWeight
);
157 void setBiffUnderline( sal_uInt16 nUnderline
);
158 void setBiffEscapement( sal_uInt16 nEscapement
);
161 /** Contains used flags for all API font attributes. */
162 struct ApiFontUsedFlags
164 bool mbNameUsed
; /// True = font name/family/char set are used.
165 bool mbColorUsed
; /// True = font color is used.
166 bool mbSchemeUsed
; /// True = font scheme is used.
167 bool mbHeightUsed
; /// True = font height is used.
168 bool mbUnderlineUsed
; /// True = underline style is used.
169 bool mbEscapementUsed
; /// True = escapement style is used.
170 bool mbWeightUsed
; /// True = font weight (boldness) is used.
171 bool mbPostureUsed
; /// True = font posture (italic) is used.
172 bool mbStrikeoutUsed
; /// True = strike out style is used.
173 bool mbOutlineUsed
; /// True = outline style is used.
174 bool mbShadowUsed
; /// True = shadow style is used.
176 explicit ApiFontUsedFlags( bool bAllUsed
);
179 /** Contains API font name, family, and charset for a script type. */
180 struct ApiScriptFontName
182 OUString maName
; /// Font name.
183 sal_Int16 mnFamily
; /// Font family.
184 sal_Int16 mnTextEnc
; /// Font text encoding.
186 explicit ApiScriptFontName();
189 /** Contains all API font attributes. */
192 ApiScriptFontName maLatinFont
; /// Font name for latin scripts.
193 ApiScriptFontName maAsianFont
; /// Font name for east-asian scripts.
194 ApiScriptFontName maCmplxFont
; /// Font name for complex scripts.
195 css::awt::FontDescriptor maDesc
; /// Font descriptor (height in twips, weight in %).
196 ::Color mnColor
; /// Font color.
197 sal_Int16 mnEscapement
; /// Escapement style.
198 sal_Int8 mnEscapeHeight
; /// Escapement font height.
199 bool mbOutline
; /// True = outlined characters.
200 bool mbShadow
; /// True = shadowed chgaracters.
202 explicit ApiFontData();
205 class Font
: public WorkbookHelper
208 explicit Font( const WorkbookHelper
& rHelper
, bool bDxf
);
209 explicit Font( const WorkbookHelper
& rHelper
, FontModel aModel
);
211 /** Sets font formatting attributes for the passed element. */
212 void importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
);
214 /** Imports the FONT record from the passed stream. */
215 void importFont( SequenceInputStream
& rStrm
);
216 /** Imports the font name from a DXF record. */
217 void importDxfName( SequenceInputStream
& rStrm
);
218 /** Imports the font color from a DXF record. */
219 void importDxfColor( SequenceInputStream
& rStrm
);
220 /** Imports the font scheme from a DXF record. */
221 void importDxfScheme( SequenceInputStream
& rStrm
);
222 /** Imports the font height from a DXF record. */
223 void importDxfHeight( SequenceInputStream
& rStrm
);
224 /** Imports the font weight from a DXF record. */
225 void importDxfWeight( SequenceInputStream
& rStrm
);
226 /** Imports the font underline style from a DXF record. */
227 void importDxfUnderline( SequenceInputStream
& rStrm
);
228 /** Imports the font escapement style from a DXF record. */
229 void importDxfEscapement( SequenceInputStream
& rStrm
);
230 /** Imports a font style flag from a DXF record. */
231 void importDxfFlag( sal_Int32 nElement
, SequenceInputStream
& rStrm
);
233 /** Returns the font model structure. This function can be called before
234 finalizeImport() has been called. */
235 const FontModel
& getModel() const { return maModel
; }
237 /** Final processing after import of all style settings. */
238 void finalizeImport();
240 /** Returns an API font descriptor with own font information. */
241 const css::awt::FontDescriptor
& getFontDescriptor() const { return maApiData
.maDesc
;}
242 /** Returns true, if the font requires rich text formatting in Calc.
243 @descr Example: Font escapement is a cell attribute in Excel, but Calc
244 needs a rich text cell for this attribute. */
245 bool needsRichTextFormat() const;
247 void fillToItemSet( SfxItemSet
& rItemSet
, bool bEditEngineText
, bool bSkipPoolDefs
= false ) const;
248 /** Writes all font attributes to the passed property map. */
249 void writeToPropertyMap(
250 PropertyMap
& rPropMap
) const;
251 /** Writes all font attributes to the passed property set. */
252 void writeToPropertySet(
253 PropertySet
& rPropSet
) const;
257 ApiFontData maApiData
;
258 ApiFontUsedFlags maUsedFlags
;
262 typedef std::shared_ptr
< Font
> FontRef
;
264 /** Contains all XML cell alignment attributes, e.g. from an alignment element. */
265 struct AlignmentModel
267 sal_Int32 mnHorAlign
; /// Horizontal alignment.
268 sal_Int32 mnVerAlign
; /// Vertical alignment.
269 sal_Int32 mnTextDir
; /// CTL text direction.
270 sal_Int32 mnRotation
; /// Text rotation angle.
271 sal_Int32 mnIndent
; /// Indentation.
272 bool mbWrapText
; /// True = multi-line text.
273 bool mbShrink
; /// True = shrink to fit cell size.
274 bool mbJustLastLine
; /// True = justify last line in block text.
276 explicit AlignmentModel();
278 /** Sets horizontal alignment from the passed BIFF data. */
279 void setBiffHorAlign( sal_uInt8 nHorAlign
);
280 /** Sets vertical alignment from the passed BIFF data. */
281 void setBiffVerAlign( sal_uInt8 nVerAlign
);
284 /** Contains all API cell alignment attributes. */
285 struct ApiAlignmentData
287 css::table::CellHoriJustify meHorJustify
; /// Horizontal alignment.
288 sal_Int32 mnHorJustifyMethod
;
289 sal_Int32 mnVerJustify
; /// Vertical alignment.
290 sal_Int32 mnVerJustifyMethod
;
291 css::table::CellOrientation meOrientation
; /// Normal or stacked text.
292 Degree100 mnRotation
; /// Text rotation angle.
293 sal_Int16 mnWritingMode
; /// CTL text direction.
294 sal_Int16 mnIndent
; /// Indentation.
295 bool mbWrapText
; /// True = multi-line text.
296 bool mbShrink
; /// True = shrink to fit cell size.
298 explicit ApiAlignmentData();
301 bool operator==( const ApiAlignmentData
& rLeft
, const ApiAlignmentData
& rRight
);
303 class Alignment
: public WorkbookHelper
306 explicit Alignment( const WorkbookHelper
& rHelper
);
308 /** Sets all attributes from the alignment element. */
309 void importAlignment( const AttributeList
& rAttribs
);
311 /** Sets the alignment attributes from the passed BIFF12 XF record data. */
312 void setBiff12Data( sal_uInt32 nFlags
);
314 /** Final processing after import of all style settings. */
315 void finalizeImport();
317 /** Returns the alignment model structure. */
318 const AlignmentModel
& getModel() const { return maModel
; }
319 /** Returns the converted API alignment data struct. */
320 const ApiAlignmentData
& getApiData() const { return maApiData
; }
322 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
325 ::SvxCellHorJustify
GetScHorAlign() const;
326 ::SvxCellVerJustify
GetScVerAlign() const;
327 ::SvxFrameDirection
GetScFrameDir() const;
328 AlignmentModel maModel
; /// Alignment model data.
329 ApiAlignmentData maApiData
; /// Alignment data converted to API constants.
332 /** Contains all XML cell protection attributes, e.g. from a protection element. */
333 struct ProtectionModel
335 bool mbLocked
; /// True = locked against editing.
336 bool mbHidden
; /// True = formula is hidden.
338 explicit ProtectionModel();
341 /** Contains all API cell protection attributes. */
342 struct ApiProtectionData
344 typedef css::util::CellProtection ApiCellProtection
;
346 ApiCellProtection maCellProt
;
348 explicit ApiProtectionData();
351 bool operator==( const ApiProtectionData
& rLeft
, const ApiProtectionData
& rRight
);
353 class Protection
: public WorkbookHelper
356 explicit Protection( const WorkbookHelper
& rHelper
);
358 /** Sets all attributes from the protection element. */
359 void importProtection( const AttributeList
& rAttribs
);
361 /** Sets the protection attributes from the passed BIFF12 XF record data. */
362 void setBiff12Data( sal_uInt32 nFlags
);
364 /** Final processing after import of all style settings. */
365 void finalizeImport();
367 /** Returns the converted API protection data struct. */
368 const ApiProtectionData
& getApiData() const { return maApiData
; }
370 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
372 ProtectionModel maModel
; /// Protection model data.
373 ApiProtectionData maApiData
; /// Protection data converted to API constants.
376 /** Contains XML attributes of a single border line. */
377 struct BorderLineModel
379 Color maColor
; /// Borderline color.
380 sal_Int32 mnStyle
; /// Border line style.
381 bool mbUsed
; /// True = line format used.
383 explicit BorderLineModel( bool bDxf
);
385 /** Sets the passed BIFF line style. */
386 void setBiffStyle( sal_Int32 nLineStyle
);
389 /** Contains XML attributes of a complete cell border. */
392 BorderLineModel maLeft
; /// Left line format.
393 BorderLineModel maRight
; /// Right line format.
394 BorderLineModel maTop
; /// Top line format.
395 BorderLineModel maBottom
; /// Bottom line format.
396 BorderLineModel maDiagonal
; /// Diagonal line format.
397 bool mbDiagTLtoBR
; /// True = top-left to bottom-right on.
398 bool mbDiagBLtoTR
; /// True = bottom-left to top-right on.
400 explicit BorderModel( bool bDxf
);
403 /** Contains API attributes of a complete cell border. */
406 typedef css::table::BorderLine2 ApiBorderLine
;
408 ApiBorderLine maLeft
; /// Left line format
409 ApiBorderLine maRight
; /// Right line format
410 ApiBorderLine maTop
; /// Top line format
411 ApiBorderLine maBottom
; /// Bottom line format
412 ApiBorderLine maTLtoBR
; /// Diagonal top-left to bottom-right line format.
413 ApiBorderLine maBLtoTR
; /// Diagonal bottom-left to top-right line format.
414 bool mbBorderUsed
; /// True = left/right/top/bottom line format used.
415 bool mbDiagUsed
; /// True = diagonal line format used.
417 explicit ApiBorderData();
419 /** Returns true, if any of the outer border lines is visible. */
420 bool hasAnyOuterBorder() const;
423 class Border
: public WorkbookHelper
426 explicit Border( const WorkbookHelper
& rHelper
, bool bDxf
);
428 /** Sets global border attributes from the border element. */
429 void importBorder( const AttributeList
& rAttribs
);
430 /** Sets border attributes for the border line with the passed element identifier. */
431 void importStyle( sal_Int32 nElement
, const AttributeList
& rAttribs
);
432 /** Sets color attributes for the border line with the passed element identifier. */
433 void importColor( sal_Int32 nElement
, const AttributeList
& rAttribs
);
435 /** Imports the BORDER record from the passed stream. */
436 void importBorder( SequenceInputStream
& rStrm
);
437 /** Imports a border from a DXF record from the passed stream. */
438 void importDxfBorder( sal_Int32 nElement
, SequenceInputStream
& rStrm
);
440 /** Final processing after import of all style settings. */
441 void finalizeImport( bool bRTL
);
443 /** Returns the converted API border data struct. */
444 const ApiBorderData
& getApiData() const { return maApiData
; }
446 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
449 /** Returns the border line struct specified by the passed XML token identifier. */
450 BorderLineModel
* getBorderLine( sal_Int32 nElement
);
452 /** Converts border line data to an API struct, returns true, if the line is marked as used. */
453 bool convertBorderLine(
454 css::table::BorderLine2
& rBorderLine
,
455 const BorderLineModel
& rModel
);
459 ApiBorderData maApiData
;
463 typedef std::shared_ptr
< Border
> BorderRef
;
465 /** Contains XML pattern fill attributes from the patternFill element. */
466 struct PatternFillModel
468 Color maPatternColor
; /// Pattern foreground color.
469 Color maFilterPatternColor
; /// Pattern foreground for color filter.
470 Color maFillColor
; /// Background fill color.
471 sal_Int32 mnPattern
; /// Pattern identifier (e.g. solid).
472 bool mbPattColorUsed
; /// True = pattern foreground color used.
473 bool mbFillColorUsed
; /// True = background fill color used.
474 bool mbPatternUsed
; /// True = pattern used.
476 explicit PatternFillModel( bool bDxf
);
478 /** Sets the passed BIFF pattern identifier. */
479 void setBiffPattern( sal_Int32 nPattern
);
482 /** Contains XML gradient fill attributes from the gradientFill element. */
483 struct GradientFillModel
485 typedef ::std::map
< double, Color
> ColorMap
;
487 sal_Int32 mnType
; /// Gradient type, linear or path.
488 double mfAngle
; /// Rotation angle for type linear.
489 double mfLeft
; /// Left convergence for type path.
490 double mfRight
; /// Right convergence for type path.
491 double mfTop
; /// Top convergence for type path.
492 double mfBottom
; /// Bottom convergence for type path.
493 ColorMap maColors
; /// Gradient colors.
495 explicit GradientFillModel();
497 /** Reads BIFF12 gradient settings from a FILL or DXF record. */
498 void readGradient( SequenceInputStream
& rStrm
);
499 /** Reads BIFF12 gradient stop settings from a FILL or DXF record. */
500 void readGradientStop( SequenceInputStream
& rStrm
, bool bDxf
);
503 /** Contains API fill attributes. */
504 struct ApiSolidFillData
506 ::Color mnColor
; /// Fill color.
507 ::Color mnFilterColor
; /// Fill color filtering.
508 bool mbTransparent
; /// True = transparent area.
509 bool mbUsed
; /// True = fill data is valid.
511 explicit ApiSolidFillData();
514 /** Contains cell fill attributes, either a pattern fill or a gradient fill. */
515 class Fill
: public WorkbookHelper
518 explicit Fill( const WorkbookHelper
& rHelper
, bool bDxf
);
520 /** Sets attributes of a patternFill element. */
521 void importPatternFill( const AttributeList
& rAttribs
);
522 /** Sets the pattern color from the fgColor element. */
523 void importFgColor( const AttributeList
& rAttribs
);
524 /** Sets the background color from the bgColor element. */
525 void importBgColor( const AttributeList
& rAttribs
);
526 /** Sets attributes of a gradientFill element. */
527 void importGradientFill( const AttributeList
& rAttribs
);
528 /** Sets a color from the color element in a gradient fill. */
529 void importColor( const AttributeList
& rAttribs
, double fPosition
);
531 /** Imports the FILL record from the passed stream. */
532 void importFill( SequenceInputStream
& rStrm
);
533 /** Imports the fill pattern from a DXF record. */
534 void importDxfPattern( SequenceInputStream
& rStrm
);
535 /** Imports the pattern color from a DXF record. */
536 void importDxfFgColor( SequenceInputStream
& rStrm
);
537 /** Imports the background color from a DXF record. */
538 void importDxfBgColor( SequenceInputStream
& rStrm
);
539 /** Imports gradient settings from a DXF record. */
540 void importDxfGradient( SequenceInputStream
& rStrm
);
541 /** Imports gradient stop settings from a DXF record. */
542 void importDxfStop( SequenceInputStream
& rStrm
);
544 /** Final processing after import of all style settings. */
545 void finalizeImport();
547 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
550 typedef std::shared_ptr
< PatternFillModel
> PatternModelRef
;
551 typedef std::shared_ptr
< GradientFillModel
> GradientModelRef
;
553 PatternModelRef mxPatternModel
;
554 GradientModelRef mxGradientModel
;
555 ApiSolidFillData maApiData
;
559 typedef std::shared_ptr
< Fill
> FillRef
;
561 /** Contains all data for a cell format or cell style. */
564 sal_Int32 mnStyleXfId
; /// Index to parent style XF.
565 sal_Int32 mnFontId
; /// Index to font data list.
566 sal_Int32 mnNumFmtId
; /// Index to number format list.
567 sal_Int32 mnBorderId
; /// Index to list of cell borders.
568 sal_Int32 mnFillId
; /// Index to list of cell areas.
569 bool mbCellXf
; /// True = cell XF, false = style XF.
570 bool mbFontUsed
; /// True = font index used.
571 bool mbNumFmtUsed
; /// True = number format used.
572 bool mbAlignUsed
; /// True = alignment used.
573 bool mbProtUsed
; /// True = cell protection used.
574 bool mbBorderUsed
; /// True = border data used.
575 bool mbAreaUsed
; /// True = area data used.
580 bool operator==( const XfModel
& rXfModel1
, const XfModel
& rXfModel2
);
582 /** Represents a cell format or a cell style (called XF, extended format).
584 This class stores the type (cell/style), the index to the parent style (if
585 it is a cell format) and all "attribute used" flags, which reflect the
586 state of specific attribute groups (true = user has changed the attributes)
587 and all formatting data.
589 class Xf
: public WorkbookHelper
591 friend bool operator==( const Xf
& rXf1
, const Xf
& rXf2
);
595 std::vector
<ScAttrEntry
> maAttrs
;
596 bool mbLatinNumFmtOnly
;
597 const ScPatternAttr
* mpDefPattern
;
599 AttrList(const ScPatternAttr
* pDefPatternAttr
);
602 explicit Xf( const WorkbookHelper
& rHelper
);
604 /** Sets all attributes from the xf element. */
605 void importXf( const AttributeList
& rAttribs
, bool bCellXf
);
606 /** Sets all attributes from the alignment element. */
607 void importAlignment( const AttributeList
& rAttribs
);
608 /** Sets all attributes from the protection element. */
609 void importProtection( const AttributeList
& rAttribs
);
611 /** Imports the XF record from the passed stream. */
612 void importXf( SequenceInputStream
& rStrm
, bool bCellXf
);
614 /** Final processing after import of all style settings. */
615 void finalizeImport();
617 /** Returns true, if the XF is a cell XF, and false, if it is a style XF. */
618 bool isCellXf() const { return maModel
.mbCellXf
; }
620 /** Returns the referred font object. */
621 FontRef
getFont() const;
622 /** Returns the alignment data of this style. */
623 const Alignment
& getAlignment() const { return maAlignment
; }
625 void applyPatternToAttrList(
626 AttrList
& rAttrs
, SCROW nRow1
, SCROW nRow2
, sal_Int32 nForceScNumFmt
);
628 void writeToDoc( ScDocumentImport
& rDoc
, const ScRange
& rRange
);
630 const ::ScPatternAttr
& createPattern( bool bSkipPoolDefs
= false );
633 typedef ::std::unique_ptr
< ::ScPatternAttr
> ScPatternAttrPtr
;
635 ScPatternAttrPtr mpPattern
; /// Calc item set.
636 sal_uInt32 mnScNumFmt
; /// Calc number format.
638 XfModel maModel
; /// Cell XF or style XF model data.
639 Alignment maAlignment
; /// Cell alignment data.
640 Protection maProtection
; /// Cell protection data.
641 sal_Int32 meRotationRef
; /// Rotation reference dependent on border.
642 ::ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
645 bool operator==( const Xf
& rXf1
, const Xf
& rXf2
);
647 typedef std::shared_ptr
< Xf
> XfRef
;
649 class Dxf
: public WorkbookHelper
652 explicit Dxf( const WorkbookHelper
& rHelper
);
654 /** Creates a new empty font object. */
655 FontRef
const & createFont( bool bAlwaysNew
= true );
656 /** Creates a new empty border object. */
657 BorderRef
const & createBorder( bool bAlwaysNew
= true );
658 /** Creates a new empty fill object. */
659 FillRef
const & createFill( bool bAlwaysNew
= true );
661 /** Inserts a new number format code. */
662 void importNumFmt( const AttributeList
& rAttribs
);
664 /** Imports the DXF record from the passed stream. */
665 void importDxf( SequenceInputStream
& rStrm
);
667 /** Final processing after import of all style settings. */
668 void finalizeImport();
670 void fillToItemSet( SfxItemSet
& rSet
) const;
673 FontRef mxFont
; /// Font data.
674 NumberFormatRef mxNumFmt
; /// Number format data.
675 std::shared_ptr
< Alignment
>
676 mxAlignment
; /// Alignment data.
677 std::shared_ptr
< Protection
>
678 mxProtection
; /// Protection data.
679 BorderRef mxBorder
; /// Border data.
680 FillRef mxFill
; /// Fill data.
683 typedef std::shared_ptr
< Dxf
> DxfRef
;
685 /** Contains attributes of a cell style, e.g. from the cellStyle element. */
686 struct CellStyleModel
688 OUString maName
; /// Cell style name.
689 sal_Int32 mnXfId
; /// Formatting for this cell style.
690 sal_Int32 mnBuiltinId
; /// Identifier for builtin styles.
691 sal_Int32 mnLevel
; /// Level for builtin column/row styles.
692 bool mbBuiltin
; /// True = builtin style.
693 bool mbCustom
; /// True = customized builtin style.
694 bool mbHidden
; /// True = style not visible in GUI.
696 explicit CellStyleModel();
698 /** Returns true, if this style is a builtin style. */
699 bool isBuiltin() const;
700 /** Returns true, if this style represents the default document cell style. */
701 bool isDefaultStyle() const;
704 class CellStyle
: public WorkbookHelper
707 explicit CellStyle( const WorkbookHelper
& rHelper
);
709 /** Imports passed attributes from the cellStyle element. */
710 void importCellStyle( const AttributeList
& rAttribs
);
711 /** Imports style settings from a CELLSTYLE record. */
712 void importCellStyle( SequenceInputStream
& rStrm
);
714 /** Creates the style sheet in the document described by this cell style object. */
715 void createCellStyle();
716 /** Stores the passed final style name and creates the cell style, if it is
717 user-defined or modified built-in. */
718 void finalizeImport( const OUString
& rFinalName
);
720 /** Returns the cell style model structure. */
721 const CellStyleModel
& getModel() const { return maModel
; }
722 /** Returns the final style name used in the document. */
723 const OUString
& getFinalStyleName() const { return maFinalName
; }
724 ::ScStyleSheet
* getStyleSheet() { return mpStyleSheet
; }
726 CellStyleModel maModel
;
727 OUString maFinalName
; /// Final style name used in API.
728 bool mbCreated
; /// True = style sheet created.
729 ::ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
733 typedef std::shared_ptr
< CellStyle
> CellStyleRef
;
735 class CellStyleBuffer
: public WorkbookHelper
738 explicit CellStyleBuffer( const WorkbookHelper
& rHelper
);
740 /** Appends and returns a new named cell style object. */
741 CellStyleRef
importCellStyle( const AttributeList
& rAttribs
);
742 /** Imports the CELLSTYLE record from the passed stream. */
743 CellStyleRef
importCellStyle( SequenceInputStream
& rStrm
);
745 /** Final processing after import of all style settings. */
746 void finalizeImport();
748 /** Returns the XF identifier associated to the default cell style. */
749 sal_Int32
getDefaultXfId() const;
750 /** Returns the default style sheet for unused cells. */
751 OUString
getDefaultStyleName() const;
752 /** Creates the style sheet described by the style XF with the passed identifier. */
753 OUString
createCellStyle( sal_Int32 nXfId
) const;
754 ::ScStyleSheet
* getCellStyleSheet( sal_Int32 nXfId
) const;
757 /** Inserts the passed cell style object into the internal maps. */
758 void insertCellStyle( CellStyleRef
const & xCellStyle
);
759 /** Creates the style sheet described by the passed cell style object. */
760 static OUString
createCellStyle( const CellStyleRef
& rxCellStyle
);
761 static ::ScStyleSheet
* getCellStyleSheet( const CellStyleRef
& rxCellStyle
);
764 typedef RefVector
< CellStyle
> CellStyleVector
;
765 typedef RefMap
< sal_Int32
, CellStyle
> CellStyleXfIdMap
;
767 CellStyleVector maBuiltinStyles
; /// All built-in cell styles.
768 CellStyleVector maUserStyles
; /// All user defined cell styles.
769 CellStyleXfIdMap maStylesByXf
; /// All cell styles, mapped by XF identifier.
770 CellStyleRef mxDefStyle
; /// Default cell style.
773 struct AutoFormatModel
775 sal_Int32 mnAutoFormatId
; /// Index of predefined autoformatting.
776 bool mbApplyNumFmt
; /// True = apply number format from autoformatting.
777 bool mbApplyFont
; /// True = apply font from autoformatting.
778 bool mbApplyAlignment
; /// True = apply alignment from autoformatting.
779 bool mbApplyBorder
; /// True = apply border from autoformatting.
780 bool mbApplyFill
; /// True = apply fill from autoformatting.
781 bool mbApplyProtection
; /// True = apply protection from autoformatting.
783 explicit AutoFormatModel();
786 class StylesBuffer
: public WorkbookHelper
789 explicit StylesBuffer( const WorkbookHelper
& rHelper
);
791 /** Creates a new empty font object. */
792 FontRef
createFont();
793 /** Creates a number format. */
794 NumberFormatRef
createNumFmt( sal_Int32 nNumFmtId
, std::u16string_view aFmtCode
);
795 sal_Int32
nextFreeNumFmtId();
796 /** Creates a new empty border object. */
797 BorderRef
createBorder();
798 /** Creates a new empty fill object. */
799 FillRef
createFill();
800 /** Creates a new empty cell formatting object. */
801 XfRef
createCellXf();
802 /** Creates a new empty style formatting object. */
803 XfRef
createStyleXf();
804 /** Creates a new empty differential formatting object. */
806 DxfRef
createExtDxf();
808 /** Appends a new color to the color palette. */
809 void importPaletteColor( const AttributeList
& rAttribs
);
810 /** Inserts a new number format code. */
811 NumberFormatRef
importNumFmt( const AttributeList
& rAttribs
);
812 /** Appends and returns a new named cell style object. */
813 CellStyleRef
importCellStyle( const AttributeList
& rAttribs
);
815 /** Appends a new color to the color palette. */
816 void importPaletteColor( SequenceInputStream
& rStrm
);
817 /** Imports the NUMFMT record from the passed stream. */
818 void importNumFmt( SequenceInputStream
& rStrm
);
819 /** Imports the CELLSTYLE record from the passed stream. */
820 void importCellStyle( SequenceInputStream
& rStrm
);
822 /** Final processing after import of all style settings. */
823 void finalizeImport();
825 /** Returns the palette color with the specified index. */
826 ::Color
getPaletteColor( sal_Int32 nIndex
) const;
827 /** Returns the specified font object. */
828 FontRef
getFont( sal_Int32 nFontId
) const;
829 /** Returns the specified border object. */
830 BorderRef
getBorder( sal_Int32 nBorderId
) const;
831 /** Returns the specified cell format object. */
832 XfRef
getCellXf( sal_Int32 nXfId
) const;
833 /** Returns the specified style format object. */
834 XfRef
getStyleXf( sal_Int32 nXfId
) const;
836 /** Returns the font object of the specified cell XF. */
837 FontRef
getFontFromCellXf( sal_Int32 nXfId
) const;
838 /** Returns the default application font (used in the "Normal" cell style). */
839 FontRef
getDefaultFont() const;
840 /** Returns the model of the default application font (used in the "Normal" cell style). */
841 const FontModel
& getDefaultFontModel() const;
843 /** Returns true, if the specified borders are equal. */
844 static bool equalBorders( sal_Int32 nBorderId1
, sal_Int32 nBorderId2
);
845 /** Returns true, if the specified fills are equal. */
846 static bool equalFills( sal_Int32 nFillId1
, sal_Int32 nFillId2
);
848 /** Returns the default style sheet for unused cells. */
849 OUString
getDefaultStyleName() const;
850 /** Creates the style sheet described by the style XF with the passed identifier. */
851 OUString
createCellStyle( sal_Int32 nXfId
) const;
852 ::ScStyleSheet
* getCellStyleSheet( sal_Int32 nXfId
) const;
853 /** Creates the style sheet described by the DXF with the passed identifier. */
854 OUString
createDxfStyle( sal_Int32 nDxfId
) const;
855 OUString
createExtDxfStyle( sal_Int32 nDxfId
) const;
857 void writeFontToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nFontId
, bool bSkipPoolDefs
) const;
858 sal_uInt32
writeNumFmtToItemSet( SfxItemSet
& rItemSet
, sal_uInt32 nNumFmtId
, bool bSkipPoolDefs
) const;
859 /** Writes the specified number format to the passed property map. */
860 void writeBorderToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nBorderId
, bool bSkipPoolDefs
) const;
861 /** Writes the fill attributes of the specified fill data to the passed property map. */
862 void writeFillToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nFillId
, bool bSkipPoolDefs
) const;
864 /** Writes the cell formatting attributes of the specified XF to the passed property set. */
865 void writeCellXfToDoc( ScDocumentImport
& rDoc
, const ScRange
& rRange
, sal_Int32 nXfId
) const;
866 const RefVector
< Dxf
>& getExtDxfs() const { return maExtDxfs
; }
869 typedef RefVector
< Font
> FontVector
;
870 typedef RefVector
< Border
> BorderVector
;
871 typedef RefVector
< Fill
> FillVector
;
872 typedef RefVector
< Xf
> XfVector
;
873 typedef RefVector
< Dxf
> DxfVector
;
874 typedef ::std::map
< sal_Int32
, OUString
> DxfStyleMap
;
876 ColorPalette maPalette
; /// Color palette.
877 FontVector maFonts
; /// List of font objects.
878 NumberFormatsBuffer maNumFmts
; /// List of all number format codes.
879 BorderVector maBorders
; /// List of cell border objects.
880 FillVector maFills
; /// List of cell area fill objects.
881 XfVector maCellXfs
; /// List of cell formats.
882 XfVector maStyleXfs
; /// List of cell styles.
883 CellStyleBuffer maCellStyles
; /// All built-in and user defined cell styles.
884 DxfVector maDxfs
; /// List of differential cell styles.
885 DxfVector maExtDxfs
; /// List of differential extlst cell styles.
886 mutable DxfStyleMap maDxfStyles
; /// Maps DXF identifiers to Calc style sheet names.
889 } // namespace oox::xls
891 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */