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 <docmodel/color/ComplexColor.hxx>
36 #include <attarray.hxx>
41 namespace oox
{ class SequenceInputStream
; }
43 namespace oox
{ class PropertySet
;
45 class AttributeList
; }
49 const sal_Int32 OOX_COLOR_WINDOWTEXT3
= 24; /// System window text color (BIFF3-BIFF4).
50 const sal_Int32 OOX_COLOR_WINDOWBACK3
= 25; /// System window background color (BIFF3-BIFF4).
51 const sal_Int32 OOX_COLOR_WINDOWTEXT
= 64; /// System window text color (BIFF5+).
52 const sal_Int32 OOX_COLOR_WINDOWBACK
= 65; /// System window background color (BIFF5+).
53 const sal_Int32 OOX_COLOR_BUTTONBACK
= 67; /// System button background color (face color).
54 const sal_Int32 OOX_COLOR_CHWINDOWTEXT
= 77; /// System window text color (BIFF8 charts).
55 const sal_Int32 OOX_COLOR_CHWINDOWBACK
= 78; /// System window background color (BIFF8 charts).
56 const sal_Int32 OOX_COLOR_CHBORDERAUTO
= 79; /// Automatic frame border (BIFF8 charts).
57 const sal_Int32 OOX_COLOR_NOTEBACK
= 80; /// Note background color.
58 const sal_Int32 OOX_COLOR_NOTETEXT
= 81; /// Note text color.
59 const sal_Int32 OOX_COLOR_FONTAUTO
= 0x7FFF; /// Font auto color (system window text color).
61 const sal_Int16 API_LINE_NONE
= 0;
62 const sal_Int16 API_LINE_HAIR
= 1;
63 const sal_Int16 API_LINE_THIN
= 15;
64 const sal_Int16 API_LINE_MEDIUM
= 35;
65 const sal_Int16 API_LINE_THICK
= 50;
67 const sal_Int16 API_ESCAPE_NONE
= 0; /// No escapement.
68 const sal_Int16 API_ESCAPE_SUPERSCRIPT
= 101; /// Superscript: raise characters automatically (magic value 101).
69 const sal_Int16 API_ESCAPE_SUBSCRIPT
= -101; /// Subscript: lower characters automatically (magic value -101).
71 const sal_Int8 API_ESCAPEHEIGHT_NONE
= 100; /// Relative character height if not escaped.
72 const sal_Int8 API_ESCAPEHEIGHT_DEFAULT
= 58; /// Relative character height if escaped.
74 /** Special implementation of the GraphicHelper for Excel palette and scheme
77 class ExcelGraphicHelper
: public GraphicHelper
, public WorkbookHelper
80 explicit ExcelGraphicHelper( const WorkbookHelper
& rHelper
);
82 /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
83 virtual ::Color
getSchemeColor( sal_Int32 nToken
) const override
;
84 /** Derived classes may implement to resolve a palette index to an RGB color. */
85 virtual ::Color
getPaletteColor( sal_Int32 nPaletteIdx
) const override
;
88 class XlsColor
: public ::oox::drawingml::Color
91 /** Sets the color to automatic. */
93 /** Sets the color to the passed RGB value. */
94 void setRgb( ::Color nRgbValue
, double fTint
= 0.0 );
95 /** Sets the color to the passed theme index. */
96 void setTheme( sal_Int32 nThemeIdx
, double fTint
= 0.0 );
97 /** Sets the color to the passed palette index. */
98 void setIndexed( sal_Int32 nPaletteIdx
, double fTint
= 0.0 );
100 /** Imports the color from the passed attribute list. */
101 void importColor( const AttributeList
& rAttribs
);
103 /** Imports a 64-bit color from the passed binary stream. */
104 void importColor( SequenceInputStream
& rStrm
);
105 /** Imports a 32-bit palette color identifier from the passed BIFF12 stream. */
106 void importColorId( SequenceInputStream
& rStrm
);
108 /** Returns true, if the color is set to automatic. */
109 bool isAuto() const { return isPlaceHolder(); }
112 SequenceInputStream
& operator>>( SequenceInputStream
& rStrm
, XlsColor
& orColor
);
114 /** Stores all colors of the color palette. */
115 class ColorPalette
: public WorkbookHelper
118 /** Constructs the color palette with predefined color values. */
119 explicit ColorPalette( const WorkbookHelper
& rHelper
);
121 /** Appends a new color from the passed attributes. */
122 void importPaletteColor( const AttributeList
& rAttribs
);
123 /** Appends a new color from the passed RGBCOLOR record. */
124 void importPaletteColor( SequenceInputStream
& rStrm
);
126 /** Returns the RGB value of the color with the passed index. */
127 ::Color
getColor( sal_Int32 nPaletteIdx
) const;
130 /** Appends the passed color. */
131 void appendColor( ::Color nRGBValue
);
134 ::std::vector
< ::Color
> maColors
; /// List of RGB values.
135 size_t mnAppendIndex
; /// Index to append a new color.
138 /** Contains all XML font attributes, e.g. from a font or rPr element. */
141 OUString maName
; /// Font name.
142 XlsColor maColor
; /// Font color.
143 sal_Int32 mnScheme
; /// Major/minor scheme font.
144 sal_Int32 mnFamily
; /// Font family.
145 sal_Int32 mnCharSet
; /// Windows font character set.
146 double mfHeight
; /// Font height in points.
147 sal_Int32 mnUnderline
; /// Underline style.
148 sal_Int32 mnEscapement
; /// Escapement style.
149 bool mbBold
; /// True = bold characters.
150 bool mbItalic
; /// True = italic characters.
151 bool mbStrikeout
; /// True = Strike out characters.
152 bool mbOutline
; /// True = outlined characters.
153 bool mbShadow
; /// True = shadowed chgaracters.
155 explicit FontModel();
157 void setBiff12Scheme( sal_uInt8 nScheme
);
158 void setBiffHeight( sal_uInt16 nHeight
);
159 void setBiffWeight( sal_uInt16 nWeight
);
160 void setBiffUnderline( sal_uInt16 nUnderline
);
161 void setBiffEscapement( sal_uInt16 nEscapement
);
164 /** Contains used flags for all API font attributes. */
165 struct ApiFontUsedFlags
167 bool mbNameUsed
; /// True = font name/family/char set are used.
168 bool mbColorUsed
; /// True = font color is used.
169 bool mbSchemeUsed
; /// True = font scheme is used.
170 bool mbHeightUsed
; /// True = font height is used.
171 bool mbUnderlineUsed
; /// True = underline style is used.
172 bool mbEscapementUsed
; /// True = escapement style is used.
173 bool mbWeightUsed
; /// True = font weight (boldness) is used.
174 bool mbPostureUsed
; /// True = font posture (italic) is used.
175 bool mbStrikeoutUsed
; /// True = strike out style is used.
176 bool mbOutlineUsed
; /// True = outline style is used.
177 bool mbShadowUsed
; /// True = shadow style is used.
179 explicit ApiFontUsedFlags( bool bAllUsed
);
182 /** Contains API font name, family, and charset for a script type. */
183 struct ApiScriptFontName
185 OUString maName
; /// Font name.
186 sal_Int16 mnFamily
; /// Font family.
187 sal_Int16 mnTextEnc
; /// Font text encoding.
189 explicit ApiScriptFontName();
192 /** Contains all API font attributes. */
195 ApiScriptFontName maLatinFont
; /// Font name for latin scripts.
196 ApiScriptFontName maAsianFont
; /// Font name for east-asian scripts.
197 ApiScriptFontName maCmplxFont
; /// Font name for complex scripts.
198 css::awt::FontDescriptor maDesc
; /// Font descriptor (height in twips, weight in %).
199 ::Color mnColor
; /// Font color.
200 model::ComplexColor maComplexColor
; /// Font complex color.
201 sal_Int16 mnEscapement
; /// Escapement style.
202 sal_Int8 mnEscapeHeight
; /// Escapement font height.
203 bool mbOutline
; /// True = outlined characters.
204 bool mbShadow
; /// True = shadowed chgaracters.
206 explicit ApiFontData();
209 class Font
: public WorkbookHelper
212 explicit Font( const WorkbookHelper
& rHelper
, bool bDxf
);
213 explicit Font( const WorkbookHelper
& rHelper
, FontModel aModel
);
215 /** Sets font formatting attributes for the passed element. */
216 void importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
);
218 /** Imports the FONT record from the passed stream. */
219 void importFont( SequenceInputStream
& rStrm
);
220 /** Imports the font name from a DXF record. */
221 void importDxfName( SequenceInputStream
& rStrm
);
222 /** Imports the font color from a DXF record. */
223 void importDxfColor( SequenceInputStream
& rStrm
);
224 /** Imports the font scheme from a DXF record. */
225 void importDxfScheme( SequenceInputStream
& rStrm
);
226 /** Imports the font height from a DXF record. */
227 void importDxfHeight( SequenceInputStream
& rStrm
);
228 /** Imports the font weight from a DXF record. */
229 void importDxfWeight( SequenceInputStream
& rStrm
);
230 /** Imports the font underline style from a DXF record. */
231 void importDxfUnderline( SequenceInputStream
& rStrm
);
232 /** Imports the font escapement style from a DXF record. */
233 void importDxfEscapement( SequenceInputStream
& rStrm
);
234 /** Imports a font style flag from a DXF record. */
235 void importDxfFlag( sal_Int32 nElement
, SequenceInputStream
& rStrm
);
237 /** Returns the font model structure. This function can be called before
238 finalizeImport() has been called. */
239 const FontModel
& getModel() const { return maModel
; }
241 /** Final processing after import of all style settings. */
242 void finalizeImport();
244 /** Returns an API font descriptor with own font information. */
245 const css::awt::FontDescriptor
& getFontDescriptor() const { return maApiData
.maDesc
;}
246 /** Returns true, if the font requires rich text formatting in Calc.
247 @descr Example: Font escapement is a cell attribute in Excel, but Calc
248 needs a rich text cell for this attribute. */
249 bool needsRichTextFormat() const;
251 void fillToItemSet( SfxItemSet
& rItemSet
, bool bEditEngineText
, bool bSkipPoolDefs
= false ) const;
252 /** Writes all font attributes to the passed property map. */
253 void writeToPropertyMap(
254 PropertyMap
& rPropMap
) const;
255 /** Writes all font attributes to the passed property set. */
256 void writeToPropertySet(
257 PropertySet
& rPropSet
) const;
261 ApiFontData maApiData
;
262 ApiFontUsedFlags maUsedFlags
;
266 typedef std::shared_ptr
< Font
> FontRef
;
268 /** Contains all XML cell alignment attributes, e.g. from an alignment element. */
269 struct AlignmentModel
271 sal_Int32 mnHorAlign
; /// Horizontal alignment.
272 sal_Int32 mnVerAlign
; /// Vertical alignment.
273 sal_Int32 mnTextDir
; /// CTL text direction.
274 sal_Int32 mnRotation
; /// Text rotation angle.
275 sal_Int32 mnIndent
; /// Indentation.
276 bool mbWrapText
; /// True = multi-line text.
277 bool mbShrink
; /// True = shrink to fit cell size.
278 bool mbJustLastLine
; /// True = justify last line in block text.
280 explicit AlignmentModel();
282 /** Sets horizontal alignment from the passed BIFF data. */
283 void setBiffHorAlign( sal_uInt8 nHorAlign
);
284 /** Sets vertical alignment from the passed BIFF data. */
285 void setBiffVerAlign( sal_uInt8 nVerAlign
);
288 /** Contains all API cell alignment attributes. */
289 struct ApiAlignmentData
291 css::table::CellHoriJustify meHorJustify
; /// Horizontal alignment.
292 sal_Int32 mnHorJustifyMethod
;
293 sal_Int32 mnVerJustify
; /// Vertical alignment.
294 sal_Int32 mnVerJustifyMethod
;
295 css::table::CellOrientation meOrientation
; /// Normal or stacked text.
296 Degree100 mnRotation
; /// Text rotation angle.
297 sal_Int16 mnWritingMode
; /// CTL text direction.
298 sal_Int16 mnIndent
; /// Indentation.
299 bool mbWrapText
; /// True = multi-line text.
300 bool mbShrink
; /// True = shrink to fit cell size.
302 explicit ApiAlignmentData();
305 bool operator==( const ApiAlignmentData
& rLeft
, const ApiAlignmentData
& rRight
);
307 class Alignment
: public WorkbookHelper
310 explicit Alignment( const WorkbookHelper
& rHelper
);
312 /** Sets all attributes from the alignment element. */
313 void importAlignment( const AttributeList
& rAttribs
);
315 /** Sets the alignment attributes from the passed BIFF12 XF record data. */
316 void setBiff12Data( sal_uInt32 nFlags
);
318 /** Final processing after import of all style settings. */
319 void finalizeImport();
321 /** Returns the alignment model structure. */
322 const AlignmentModel
& getModel() const { return maModel
; }
323 /** Returns the converted API alignment data struct. */
324 const ApiAlignmentData
& getApiData() const { return maApiData
; }
326 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
329 ::SvxCellHorJustify
GetScHorAlign() const;
330 ::SvxCellVerJustify
GetScVerAlign() const;
331 ::SvxFrameDirection
GetScFrameDir() const;
332 AlignmentModel maModel
; /// Alignment model data.
333 ApiAlignmentData maApiData
; /// Alignment data converted to API constants.
336 /** Contains all XML cell protection attributes, e.g. from a protection element. */
337 struct ProtectionModel
339 bool mbLocked
; /// True = locked against editing.
340 bool mbHidden
; /// True = formula is hidden.
342 explicit ProtectionModel();
345 /** Contains all API cell protection attributes. */
346 struct ApiProtectionData
348 typedef css::util::CellProtection ApiCellProtection
;
350 ApiCellProtection maCellProt
;
352 explicit ApiProtectionData();
355 bool operator==( const ApiProtectionData
& rLeft
, const ApiProtectionData
& rRight
);
357 class Protection
: public WorkbookHelper
360 explicit Protection( const WorkbookHelper
& rHelper
, bool bDxf
);
362 /** Sets all attributes from the protection element. */
363 void importProtection( const AttributeList
& rAttribs
);
365 /** Sets the protection attributes from the passed BIFF12 DXF record data. */
366 void importDxfProtection( sal_Int32 nElement
, SequenceInputStream
& rStrm
);
368 /** Sets the protection attributes from the passed BIFF12 XF record data. */
369 void setBiff12Data( sal_uInt32 nFlags
);
371 /** Final processing after import of all style settings. */
372 void finalizeImport();
374 /** Returns the converted API protection data struct. */
375 const ApiProtectionData
& getApiData() const { return maApiData
; }
377 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
379 ProtectionModel maModel
; /// Protection model data.
380 ApiProtectionData maApiData
; /// Protection data converted to API constants.
384 typedef std::shared_ptr
< Protection
> ProtectionRef
;
386 /** Contains XML attributes of a single border line. */
387 struct BorderLineModel
389 XlsColor maColor
; /// Borderline color.
390 sal_Int32 mnStyle
; /// Border line style.
391 bool mbUsed
; /// True = line format used.
393 explicit BorderLineModel( bool bDxf
);
395 /** Sets the passed BIFF line style. */
396 void setBiffStyle( sal_Int32 nLineStyle
);
399 /** Contains XML attributes of a complete cell border. */
402 BorderLineModel maLeft
; /// Left line format.
403 BorderLineModel maRight
; /// Right line format.
404 BorderLineModel maTop
; /// Top line format.
405 BorderLineModel maBottom
; /// Bottom line format.
406 BorderLineModel maDiagonal
; /// Diagonal line format.
407 bool mbDiagTLtoBR
; /// True = top-left to bottom-right on.
408 bool mbDiagBLtoTR
; /// True = bottom-left to top-right on.
410 explicit BorderModel( bool bDxf
);
413 /** Contains API attributes of a complete cell border. */
416 typedef css::table::BorderLine2 ApiBorderLine
;
418 ApiBorderLine maLeft
; /// Left line format
419 ApiBorderLine maRight
; /// Right line format
420 ApiBorderLine maTop
; /// Top line format
421 ApiBorderLine maBottom
; /// Bottom line format
422 model::ComplexColor maComplexColorLeft
;
423 model::ComplexColor maComplexColorRight
;
424 model::ComplexColor maComplexColorTop
;
425 model::ComplexColor maComplexColorBottom
;
426 ApiBorderLine maTLtoBR
; /// Diagonal top-left to bottom-right line format.
427 ApiBorderLine maBLtoTR
; /// Diagonal bottom-left to top-right line format.
428 bool mbBorderUsed
; /// True = left/right/top/bottom line format used.
429 bool mbDiagUsed
; /// True = diagonal line format used.
431 explicit ApiBorderData();
433 /** Returns true, if any of the outer border lines is visible. */
434 bool hasAnyOuterBorder() const;
437 class Border
: public WorkbookHelper
440 explicit Border( const WorkbookHelper
& rHelper
, bool bDxf
);
442 /** Sets global border attributes from the border element. */
443 void importBorder( const AttributeList
& rAttribs
);
444 /** Sets border attributes for the border line with the passed element identifier. */
445 void importStyle( sal_Int32 nElement
, const AttributeList
& rAttribs
);
446 /** Sets color attributes for the border line with the passed element identifier. */
447 void importColor( sal_Int32 nElement
, const AttributeList
& rAttribs
);
449 /** Imports the BORDER record from the passed stream. */
450 void importBorder( SequenceInputStream
& rStrm
);
451 /** Imports a border from a DXF record from the passed stream. */
452 void importDxfBorder( sal_Int32 nElement
, SequenceInputStream
& rStrm
);
454 /** Final processing after import of all style settings. */
455 void finalizeImport( bool bRTL
);
457 /** Returns the converted API border data struct. */
458 const ApiBorderData
& getApiData() const { return maApiData
; }
460 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
463 /** Returns the border line struct specified by the passed XML token identifier. */
464 BorderLineModel
* getBorderLine( sal_Int32 nElement
);
466 /** Converts border line data to an API struct, returns true, if the line is marked as used. */
467 bool convertBorderLine(
468 css::table::BorderLine2
& rBorderLine
,
469 const BorderLineModel
& rModel
);
473 ApiBorderData maApiData
;
477 typedef std::shared_ptr
< Border
> BorderRef
;
479 /** Contains XML pattern fill attributes from the patternFill element. */
480 struct PatternFillModel
482 XlsColor maPatternColor
; /// Pattern foreground color.
483 XlsColor maFilterPatternColor
; /// Pattern foreground for color filter.
484 XlsColor maFillColor
; /// Background fill color.
485 sal_Int32 mnPattern
; /// Pattern identifier (e.g. solid).
486 bool mbPattColorUsed
; /// True = pattern foreground color used.
487 bool mbFillColorUsed
; /// True = background fill color used.
488 bool mbPatternUsed
; /// True = pattern used.
490 explicit PatternFillModel( bool bDxf
);
492 /** Sets the passed BIFF pattern identifier. */
493 void setBiffPattern( sal_Int32 nPattern
);
496 /** Contains XML gradient fill attributes from the gradientFill element. */
497 struct GradientFillModel
499 typedef ::std::map
<double, XlsColor
> ColorMap
;
501 sal_Int32 mnType
; /// Gradient type, linear or path.
502 double mfAngle
; /// Rotation angle for type linear.
503 double mfLeft
; /// Left convergence for type path.
504 double mfRight
; /// Right convergence for type path.
505 double mfTop
; /// Top convergence for type path.
506 double mfBottom
; /// Bottom convergence for type path.
507 ColorMap maColors
; /// Gradient colors.
509 explicit GradientFillModel();
511 /** Reads BIFF12 gradient settings from a FILL or DXF record. */
512 void readGradient( SequenceInputStream
& rStrm
);
513 /** Reads BIFF12 gradient stop settings from a FILL or DXF record. */
514 void readGradientStop( SequenceInputStream
& rStrm
, bool bDxf
);
517 /** Contains API fill attributes. */
518 struct ApiSolidFillData
520 ::Color mnColor
; /// Fill color.
521 model::ComplexColor maComplexColor
;
522 ::Color mnFilterColor
; /// Fill color filtering.
523 bool mbTransparent
; /// True = transparent area.
524 bool mbUsed
; /// True = fill data is valid.
526 explicit ApiSolidFillData();
529 /** Contains cell fill attributes, either a pattern fill or a gradient fill. */
530 class Fill
: public WorkbookHelper
533 explicit Fill( const WorkbookHelper
& rHelper
, bool bDxf
);
535 /** Sets attributes of a patternFill element. */
536 void importPatternFill( const AttributeList
& rAttribs
);
537 /** Sets the pattern color from the fgColor element. */
538 void importFgColor( const AttributeList
& rAttribs
);
539 /** Sets the background color from the bgColor element. */
540 void importBgColor( const AttributeList
& rAttribs
);
541 /** Sets attributes of a gradientFill element. */
542 void importGradientFill( const AttributeList
& rAttribs
);
543 /** Sets a color from the color element in a gradient fill. */
544 void importColor( const AttributeList
& rAttribs
, double fPosition
);
546 /** Imports the FILL record from the passed stream. */
547 void importFill( SequenceInputStream
& rStrm
);
548 /** Imports the fill pattern from a DXF record. */
549 void importDxfPattern( SequenceInputStream
& rStrm
);
550 /** Imports the pattern color from a DXF record. */
551 void importDxfFgColor( SequenceInputStream
& rStrm
);
552 /** Imports the background color from a DXF record. */
553 void importDxfBgColor( SequenceInputStream
& rStrm
);
554 /** Imports gradient settings from a DXF record. */
555 void importDxfGradient( SequenceInputStream
& rStrm
);
556 /** Imports gradient stop settings from a DXF record. */
557 void importDxfStop( SequenceInputStream
& rStrm
);
559 /** Final processing after import of all style settings. */
560 void finalizeImport();
562 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
565 typedef std::shared_ptr
< PatternFillModel
> PatternModelRef
;
566 typedef std::shared_ptr
< GradientFillModel
> GradientModelRef
;
568 PatternModelRef mxPatternModel
;
569 GradientModelRef mxGradientModel
;
570 ApiSolidFillData maApiData
;
574 typedef std::shared_ptr
< Fill
> FillRef
;
576 /** Contains all data for a cell format or cell style. */
579 sal_Int32 mnStyleXfId
; /// Index to parent style XF.
580 sal_Int32 mnFontId
; /// Index to font data list.
581 sal_Int32 mnNumFmtId
; /// Index to number format list.
582 sal_Int32 mnBorderId
; /// Index to list of cell borders.
583 sal_Int32 mnFillId
; /// Index to list of cell areas.
584 bool mbCellXf
; /// True = cell XF, false = style XF.
585 bool mbFontUsed
; /// True = font index used.
586 bool mbNumFmtUsed
; /// True = number format used.
587 bool mbAlignUsed
; /// True = alignment used.
588 bool mbProtUsed
; /// True = cell protection used.
589 bool mbBorderUsed
; /// True = border data used.
590 bool mbAreaUsed
; /// True = area data used.
595 bool operator==( const XfModel
& rXfModel1
, const XfModel
& rXfModel2
);
597 /** Represents a cell format or a cell style (called XF, extended format).
599 This class stores the type (cell/style), the index to the parent style (if
600 it is a cell format) and all "attribute used" flags, which reflect the
601 state of specific attribute groups (true = user has changed the attributes)
602 and all formatting data.
604 class Xf
: public WorkbookHelper
606 friend bool operator==( const Xf
& rXf1
, const Xf
& rXf2
);
610 std::vector
<ScAttrEntry
> maAttrs
;
611 bool mbLatinNumFmtOnly
;
612 const ScPatternAttr
* mpDefPattern
;
614 AttrList(const ScPatternAttr
* pDefPatternAttr
);
617 explicit Xf( const WorkbookHelper
& rHelper
);
619 /** Sets all attributes from the xf element. */
620 void importXf( const AttributeList
& rAttribs
, bool bCellXf
);
621 /** Sets all attributes from the alignment element. */
622 void importAlignment( const AttributeList
& rAttribs
);
623 /** Sets all attributes from the protection element. */
624 void importProtection( const AttributeList
& rAttribs
);
626 /** Imports the XF record from the passed stream. */
627 void importXf( SequenceInputStream
& rStrm
, bool bCellXf
);
629 /** Final processing after import of all style settings. */
630 void finalizeImport();
632 /** Returns true, if the XF is a cell XF, and false, if it is a style XF. */
633 bool isCellXf() const { return maModel
.mbCellXf
; }
635 /** Returns the referred font object. */
636 FontRef
getFont() const;
637 /** Returns the alignment data of this style. */
638 const Alignment
& getAlignment() const { return maAlignment
; }
640 void applyPatternToAttrList(
641 AttrList
& rAttrs
, SCROW nRow1
, SCROW nRow2
, sal_Int32 nXfId
,
642 sal_Int32 nForceScNumFmt
, ScPatternCache
& rCache
);
644 void writeToDoc( ScDocumentImport
& rDoc
, const ScRange
& rRange
);
646 const ::ScPatternAttr
& createPattern( bool bSkipPoolDefs
= false );
649 typedef ::std::unique_ptr
< ::ScPatternAttr
> ScPatternAttrPtr
;
651 ScPatternAttrPtr mpPattern
; /// Calc item set.
652 sal_uInt32 mnScNumFmt
; /// Calc number format.
654 XfModel maModel
; /// Cell XF or style XF model data.
655 Alignment maAlignment
; /// Cell alignment data.
656 Protection maProtection
; /// Cell protection data.
657 sal_Int32 meRotationRef
; /// Rotation reference dependent on border.
658 ::ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
661 bool operator==( const Xf
& rXf1
, const Xf
& rXf2
);
663 typedef std::shared_ptr
< Xf
> XfRef
;
665 class Dxf
: public WorkbookHelper
668 explicit Dxf( const WorkbookHelper
& rHelper
);
670 /** Creates a new empty font object. */
671 FontRef
const & createFont( bool bAlwaysNew
= true );
672 /** Creates a new empty border object. */
673 BorderRef
const & createBorder( bool bAlwaysNew
= true );
674 /** Creates a new empty fill object. */
675 FillRef
const & createFill( bool bAlwaysNew
= true );
676 /** Creates a new empty protection object. */
677 ProtectionRef
const & createProtection( bool bAlwaysNew
= true );
679 /** Inserts a new number format code. */
680 void importNumFmt( const AttributeList
& rAttribs
);
682 /** Imports the DXF record from the passed stream. */
683 void importDxf( SequenceInputStream
& rStrm
);
685 /** Final processing after import of all style settings. */
686 void finalizeImport();
688 void fillToItemSet( SfxItemSet
& rSet
) const;
691 FontRef mxFont
; /// Font data.
692 NumberFormatRef mxNumFmt
; /// Number format data.
693 std::shared_ptr
< Alignment
>
694 mxAlignment
; /// Alignment data.
695 std::shared_ptr
< Protection
>
696 mxProtection
; /// Protection data.
697 BorderRef mxBorder
; /// Border data.
698 FillRef mxFill
; /// Fill data.
701 typedef std::shared_ptr
< Dxf
> DxfRef
;
703 /** Contains attributes of a cell style, e.g. from the cellStyle element. */
704 struct CellStyleModel
706 OUString maName
; /// Cell style name.
707 sal_Int32 mnXfId
; /// Formatting for this cell style.
708 sal_Int32 mnBuiltinId
; /// Identifier for builtin styles.
709 sal_Int32 mnLevel
; /// Level for builtin column/row styles.
710 bool mbBuiltin
; /// True = builtin style.
711 bool mbCustom
; /// True = customized builtin style.
712 bool mbHidden
; /// True = style not visible in GUI.
714 explicit CellStyleModel();
716 /** Returns true, if this style is a builtin style. */
717 bool isBuiltin() const;
718 /** Returns true, if this style represents the default document cell style. */
719 bool isDefaultStyle() const;
722 class CellStyle
: public WorkbookHelper
725 explicit CellStyle( const WorkbookHelper
& rHelper
);
727 /** Imports passed attributes from the cellStyle element. */
728 void importCellStyle( const AttributeList
& rAttribs
);
729 /** Imports style settings from a CELLSTYLE record. */
730 void importCellStyle( SequenceInputStream
& rStrm
);
732 /** Creates the style sheet in the document described by this cell style object. */
733 void createCellStyle();
734 /** Stores the passed final style name and creates the cell style, if it is
735 user-defined or modified built-in. */
736 void finalizeImport( const OUString
& rFinalName
);
738 /** Returns the cell style model structure. */
739 const CellStyleModel
& getModel() const { return maModel
; }
740 /** Returns the final style name used in the document. */
741 const OUString
& getFinalStyleName() const { return maFinalName
; }
742 ::ScStyleSheet
* getStyleSheet() { return mpStyleSheet
; }
744 CellStyleModel maModel
;
745 OUString maFinalName
; /// Final style name used in API.
746 bool mbCreated
; /// True = style sheet created.
747 ::ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
751 typedef std::shared_ptr
< CellStyle
> CellStyleRef
;
753 class CellStyleBuffer
: public WorkbookHelper
756 explicit CellStyleBuffer( const WorkbookHelper
& rHelper
);
758 /** Appends and returns a new named cell style object. */
759 CellStyleRef
importCellStyle( const AttributeList
& rAttribs
);
760 /** Imports the CELLSTYLE record from the passed stream. */
761 CellStyleRef
importCellStyle( SequenceInputStream
& rStrm
);
763 /** Final processing after import of all style settings. */
764 void finalizeImport();
766 /** Returns the XF identifier associated to the default cell style. */
767 sal_Int32
getDefaultXfId() const;
768 /** Returns the default style sheet for unused cells. */
769 OUString
getDefaultStyleName() const;
770 /** Creates the style sheet described by the style XF with the passed identifier. */
771 OUString
createCellStyle( sal_Int32 nXfId
) const;
772 ::ScStyleSheet
* getCellStyleSheet( sal_Int32 nXfId
) const;
775 /** Inserts the passed cell style object into the internal maps. */
776 void insertCellStyle( CellStyleRef
const & xCellStyle
);
777 /** Creates the style sheet described by the passed cell style object. */
778 static OUString
createCellStyle( const CellStyleRef
& rxCellStyle
);
779 static ::ScStyleSheet
* getCellStyleSheet( const CellStyleRef
& rxCellStyle
);
782 typedef RefVector
< CellStyle
> CellStyleVector
;
783 typedef RefMap
< sal_Int32
, CellStyle
> CellStyleXfIdMap
;
785 CellStyleVector maBuiltinStyles
; /// All built-in cell styles.
786 CellStyleVector maUserStyles
; /// All user defined cell styles.
787 CellStyleXfIdMap maStylesByXf
; /// All cell styles, mapped by XF identifier.
788 CellStyleRef mxDefStyle
; /// Default cell style.
791 struct AutoFormatModel
793 sal_Int32 mnAutoFormatId
; /// Index of predefined autoformatting.
794 bool mbApplyNumFmt
; /// True = apply number format from autoformatting.
795 bool mbApplyFont
; /// True = apply font from autoformatting.
796 bool mbApplyAlignment
; /// True = apply alignment from autoformatting.
797 bool mbApplyBorder
; /// True = apply border from autoformatting.
798 bool mbApplyFill
; /// True = apply fill from autoformatting.
799 bool mbApplyProtection
; /// True = apply protection from autoformatting.
801 explicit AutoFormatModel();
804 class StylesBuffer
: public WorkbookHelper
807 explicit StylesBuffer( const WorkbookHelper
& rHelper
);
809 /** Creates a new empty font object. */
810 FontRef
createFont();
811 /** Creates a number format. */
812 NumberFormatRef
createNumFmt( sal_Int32 nNumFmtId
, std::u16string_view aFmtCode
);
813 sal_Int32
nextFreeNumFmtId();
814 /** Creates a new empty border object. */
815 BorderRef
createBorder();
816 /** Creates a new empty fill object. */
817 FillRef
createFill();
818 /** Creates a new empty cell formatting object. */
819 XfRef
createCellXf();
820 /** Creates a new empty style formatting object. */
821 XfRef
createStyleXf();
822 /** Creates a new empty differential formatting object. */
824 DxfRef
createExtDxf();
826 /** Appends a new color to the color palette. */
827 void importPaletteColor( const AttributeList
& rAttribs
);
828 /** Inserts a new number format code. */
829 NumberFormatRef
importNumFmt( const AttributeList
& rAttribs
);
830 /** Appends and returns a new named cell style object. */
831 CellStyleRef
importCellStyle( const AttributeList
& rAttribs
);
833 /** Appends a new color to the color palette. */
834 void importPaletteColor( SequenceInputStream
& rStrm
);
835 /** Imports the NUMFMT record from the passed stream. */
836 void importNumFmt( SequenceInputStream
& rStrm
);
837 /** Imports the CELLSTYLE record from the passed stream. */
838 void importCellStyle( SequenceInputStream
& rStrm
);
840 /** Final processing after import of all style settings. */
841 void finalizeImport();
843 /** Returns the palette color with the specified index. */
844 ::Color
getPaletteColor( sal_Int32 nIndex
) const;
845 /** Returns the specified font object. */
846 FontRef
getFont( sal_Int32 nFontId
) const;
847 /** Returns the specified border object. */
848 BorderRef
getBorder( sal_Int32 nBorderId
) const;
849 /** Returns the specified cell format object. */
850 XfRef
getCellXf( sal_Int32 nXfId
) const;
851 /** Returns the specified style format object. */
852 XfRef
getStyleXf( sal_Int32 nXfId
) const;
854 /** Returns the font object of the specified cell XF. */
855 FontRef
getFontFromCellXf( sal_Int32 nXfId
) const;
856 /** Returns the default application font (used in the "Normal" cell style). */
857 FontRef
getDefaultFont() const;
858 /** Returns the model of the default application font (used in the "Normal" cell style). */
859 const FontModel
& getDefaultFontModel() const;
861 /** Returns true, if the specified borders are equal. */
862 static bool equalBorders( sal_Int32 nBorderId1
, sal_Int32 nBorderId2
);
863 /** Returns true, if the specified fills are equal. */
864 static bool equalFills( sal_Int32 nFillId1
, sal_Int32 nFillId2
);
866 /** Returns the default style sheet for unused cells. */
867 OUString
getDefaultStyleName() const;
868 /** Creates the style sheet described by the style XF with the passed identifier. */
869 OUString
createCellStyle( sal_Int32 nXfId
) const;
870 ::ScStyleSheet
* getCellStyleSheet( sal_Int32 nXfId
) const;
871 /** Creates the style sheet described by the DXF with the passed identifier. */
872 OUString
createDxfStyle( sal_Int32 nDxfId
) const;
873 OUString
createExtDxfStyle( sal_Int32 nDxfId
) const;
875 DxfRef
getDxf(sal_Int32 nDxfId
) const;
877 void writeFontToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nFontId
, bool bSkipPoolDefs
) const;
878 sal_uInt32
writeNumFmtToItemSet( SfxItemSet
& rItemSet
, sal_uInt32 nNumFmtId
, bool bSkipPoolDefs
) const;
879 /** Writes the specified number format to the passed property map. */
880 void writeBorderToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nBorderId
, bool bSkipPoolDefs
) const;
881 /** Writes the fill attributes of the specified fill data to the passed property map. */
882 void writeFillToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nFillId
, bool bSkipPoolDefs
) const;
884 /** Writes the cell formatting attributes of the specified XF to the passed property set. */
885 void writeCellXfToDoc( ScDocumentImport
& rDoc
, const ScRange
& rRange
, sal_Int32 nXfId
) const;
886 const RefVector
< Dxf
>& getExtDxfs() const { return maExtDxfs
; }
889 typedef RefVector
< Font
> FontVector
;
890 typedef RefVector
< Border
> BorderVector
;
891 typedef RefVector
< Fill
> FillVector
;
892 typedef RefVector
< Xf
> XfVector
;
893 typedef RefVector
< Dxf
> DxfVector
;
894 typedef ::std::map
< sal_Int32
, OUString
> DxfStyleMap
;
896 ColorPalette maPalette
; /// Color palette.
897 FontVector maFonts
; /// List of font objects.
898 NumberFormatsBuffer maNumFmts
; /// List of all number format codes.
899 BorderVector maBorders
; /// List of cell border objects.
900 FillVector maFills
; /// List of cell area fill objects.
901 XfVector maCellXfs
; /// List of cell formats.
902 XfVector maStyleXfs
; /// List of cell styles.
903 CellStyleBuffer maCellStyles
; /// All built-in and user defined cell styles.
904 DxfVector maDxfs
; /// List of differential cell styles.
905 DxfVector maExtDxfs
; /// List of differential extlst cell styles.
906 mutable DxfStyleMap maDxfStyles
; /// Maps DXF identifiers to Calc style sheet names.
909 } // namespace oox::xls
911 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */