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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_STYLESBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_STYLESBUFFER_HXX
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/CellVertJustify2.hpp>
27 #include <com/sun/star/table/BorderLine2.hpp>
28 #include <com/sun/star/util/CellProtection.hpp>
29 #include <oox/drawingml/color.hxx>
30 #include <oox/helper/graphichelper.hxx>
31 #include <oox/helper/refmap.hxx>
32 #include <oox/helper/refvector.hxx>
33 #include "numberformatsbuffer.hxx"
34 #include "patattr.hxx"
35 #include "stlsheet.hxx"
36 #include <editeng/svxenum.hxx>
37 #include <editeng/frmdir.hxx>
38 #include "attarray.hxx"
42 namespace com
{ namespace sun
{ namespace star
{
43 namespace awt
{ struct FontDescrtiptor
; }
46 namespace oox
{ class PropertySet
; }
51 const sal_Int32 OOX_COLOR_WINDOWTEXT3
= 24; /// System window text color (BIFF3-BIFF4).
52 const sal_Int32 OOX_COLOR_WINDOWBACK3
= 25; /// System window background color (BIFF3-BIFF4).
53 const sal_Int32 OOX_COLOR_WINDOWTEXT
= 64; /// System window text color (BIFF5+).
54 const sal_Int32 OOX_COLOR_WINDOWBACK
= 65; /// System window background color (BIFF5+).
55 const sal_Int32 OOX_COLOR_BUTTONBACK
= 67; /// System button background color (face color).
56 const sal_Int32 OOX_COLOR_CHWINDOWTEXT
= 77; /// System window text color (BIFF8 charts).
57 const sal_Int32 OOX_COLOR_CHWINDOWBACK
= 78; /// System window background color (BIFF8 charts).
58 const sal_Int32 OOX_COLOR_CHBORDERAUTO
= 79; /// Automatic frame border (BIFF8 charts).
59 const sal_Int32 OOX_COLOR_NOTEBACK
= 80; /// Note background color.
60 const sal_Int32 OOX_COLOR_NOTETEXT
= 81; /// Note text color.
61 const sal_Int32 OOX_COLOR_FONTAUTO
= 0x7FFF; /// Font auto color (system window text color).
63 const sal_Int16 API_LINE_NONE
= 0;
64 const sal_Int16 API_LINE_HAIR
= 1;
65 const sal_Int16 API_LINE_THIN
= 15;
66 const sal_Int16 API_LINE_MEDIUM
= 35;
67 const sal_Int16 API_LINE_THICK
= 50;
69 const sal_Int16 API_ESCAPE_NONE
= 0; /// No escapement.
70 const sal_Int16 API_ESCAPE_SUPERSCRIPT
= 101; /// Superscript: raise characters automatically (magic value 101).
71 const sal_Int16 API_ESCAPE_SUBSCRIPT
= -101; /// Subscript: lower characters automatically (magic value -101).
73 const sal_Int8 API_ESCAPEHEIGHT_NONE
= 100; /// Relative character height if not escaped.
74 const sal_Int8 API_ESCAPEHEIGHT_DEFAULT
= 58; /// Relative character height if escaped.
76 /** Special implementation of the GraphicHelper for Excel palette and scheme
79 class ExcelGraphicHelper
: public GraphicHelper
, public WorkbookHelper
82 explicit ExcelGraphicHelper( const WorkbookHelper
& rHelper
);
84 /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
85 virtual sal_Int32
getSchemeColor( sal_Int32 nToken
) const SAL_OVERRIDE
;
86 /** Derived classes may implement to resolve a palette index to an RGB color. */
87 virtual sal_Int32
getPaletteColor( sal_Int32 nPaletteIdx
) const SAL_OVERRIDE
;
90 class Color
: public ::oox::drawingml::Color
93 /** Sets the color to automatic. */
95 /** Sets the color to the passed RGB value. */
96 void setRgb( sal_Int32 nRgbValue
, double fTint
= 0.0 );
97 /** Sets the color to the passed theme index. */
98 void setTheme( sal_Int32 nThemeIdx
, double fTint
= 0.0 );
99 /** Sets the color to the passed palette index. */
100 void setIndexed( sal_Int32 nPaletteIdx
, double fTint
= 0.0 );
102 /** Imports the color from the passed attribute list. */
103 void importColor( const AttributeList
& rAttribs
);
105 /** Imports a 64-bit color from the passed binary stream. */
106 void importColor( SequenceInputStream
& rStrm
);
107 /** Imports a 32-bit palette color identifier from the passed BIFF12 stream. */
108 void importColorId( SequenceInputStream
& rStrm
);
110 /** Returns true, if the color is set to automatic. */
111 inline bool isAuto() const { return isPlaceHolder(); }
114 SequenceInputStream
& operator>>( SequenceInputStream
& rStrm
, Color
& orColor
);
116 /** Stores all colors of the color palette. */
117 class ColorPalette
: public WorkbookHelper
120 /** Constructs the color palette with predefined color values. */
121 explicit ColorPalette( const WorkbookHelper
& rHelper
);
123 /** Appends a new color from the passed attributes. */
124 void importPaletteColor( const AttributeList
& rAttribs
);
125 /** Appends a new color from the passed RGBCOLOR record. */
126 void importPaletteColor( SequenceInputStream
& rStrm
);
128 /** Rturns the RGB value of the color with the passed index. */
129 sal_Int32
getColor( sal_Int32 nPaletteIdx
) const;
132 /** Appends the passed color. */
133 void appendColor( sal_Int32 nRGBValue
);
136 ::std::vector
< sal_Int32
> maColors
; /// List of RGB values.
137 size_t mnAppendIndex
; /// Index to append a new color.
140 /** Contains all XML font attributes, e.g. from a font or rPr element. */
143 OUString maName
; /// Font name.
144 Color maColor
; /// Font color.
145 sal_Int32 mnScheme
; /// Major/minor scheme font.
146 sal_Int32 mnFamily
; /// Font family.
147 sal_Int32 mnCharSet
; /// Windows font character set.
148 double mfHeight
; /// Font height in points.
149 sal_Int32 mnUnderline
; /// Underline style.
150 sal_Int32 mnEscapement
; /// Escapement style.
151 bool mbBold
; /// True = bold characters.
152 bool mbItalic
; /// True = italic characters.
153 bool mbStrikeout
; /// True = Strike out characters.
154 bool mbOutline
; /// True = outlined characters.
155 bool mbShadow
; /// True = shadowed chgaracters.
157 explicit FontModel();
159 void setBiff12Scheme( sal_uInt8 nScheme
);
160 void setBiffHeight( sal_uInt16 nHeight
);
161 void setBiffWeight( sal_uInt16 nWeight
);
162 void setBiffUnderline( sal_uInt16 nUnderline
);
163 void setBiffEscapement( sal_uInt16 nEscapement
);
166 /** Enumerates different types of API font property sets. */
167 enum FontPropertyType
169 FONT_PROPTYPE_CELL
, /// Font properties in a spreadsheet cell (table::Cell service).
170 FONT_PROPTYPE_TEXT
/// Font properties in a text object (text::Text service).
173 /** Contains used flags for all API font attributes. */
174 struct ApiFontUsedFlags
176 bool mbNameUsed
; /// True = font name/family/char set are used.
177 bool mbColorUsed
; /// True = font color is used.
178 bool mbSchemeUsed
; /// True = font scheme is used.
179 bool mbHeightUsed
; /// True = font height is used.
180 bool mbUnderlineUsed
; /// True = underline style is used.
181 bool mbEscapementUsed
; /// True = escapement style is used.
182 bool mbWeightUsed
; /// True = font weight (boldness) is used.
183 bool mbPostureUsed
; /// True = font posture (italic) is used.
184 bool mbStrikeoutUsed
; /// True = strike out style is used.
185 bool mbOutlineUsed
; /// True = outline style is used.
186 bool mbShadowUsed
; /// True = shadow style is used.
188 explicit ApiFontUsedFlags( bool bAllUsed
);
191 /** Contains API font name, family, and charset for a script type. */
192 struct ApiScriptFontName
194 OUString maName
; /// Font name.
195 sal_Int16 mnFamily
; /// Font family.
196 sal_Int16 mnTextEnc
; /// Font text encoding.
198 explicit ApiScriptFontName();
201 /** Contains all API font attributes. */
204 typedef ::com::sun::star::awt::FontDescriptor ApiFontDescriptor
;
206 ApiScriptFontName maLatinFont
; /// Font name for latin scripts.
207 ApiScriptFontName maAsianFont
; /// Font name for east-asian scripts.
208 ApiScriptFontName maCmplxFont
; /// Font name for complex scripts.
209 ApiFontDescriptor maDesc
; /// Font descriptor (height in twips, weight in %).
210 sal_Int32 mnColor
; /// Font color.
211 sal_Int16 mnEscapement
; /// Escapement style.
212 sal_Int8 mnEscapeHeight
; /// Escapement font height.
213 bool mbOutline
; /// True = outlined characters.
214 bool mbShadow
; /// True = shadowed chgaracters.
216 explicit ApiFontData();
219 class Font
: public WorkbookHelper
222 explicit Font( const WorkbookHelper
& rHelper
, bool bDxf
);
223 explicit Font( const WorkbookHelper
& rHelper
, const FontModel
& rModel
);
225 /** Sets font formatting attributes for the passed element. */
226 void importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
);
228 /** Imports the FONT record from the passed stream. */
229 void importFont( SequenceInputStream
& rStrm
);
230 /** Imports the font name from a DXF record. */
231 void importDxfName( SequenceInputStream
& rStrm
);
232 /** Imports the font color from a DXF record. */
233 void importDxfColor( SequenceInputStream
& rStrm
);
234 /** Imports the font scheme from a DXF record. */
235 void importDxfScheme( SequenceInputStream
& rStrm
);
236 /** Imports the font height from a DXF record. */
237 void importDxfHeight( SequenceInputStream
& rStrm
);
238 /** Imports the font weight from a DXF record. */
239 void importDxfWeight( SequenceInputStream
& rStrm
);
240 /** Imports the font underline style from a DXF record. */
241 void importDxfUnderline( SequenceInputStream
& rStrm
);
242 /** Imports the font escapement style from a DXF record. */
243 void importDxfEscapement( SequenceInputStream
& rStrm
);
244 /** Imports a font style flag from a DXF record. */
245 void importDxfFlag( sal_Int32 nElement
, SequenceInputStream
& rStrm
);
247 /** Returns the font model structure. This function can be called before
248 finalizeImport() has been called. */
249 inline const FontModel
& getModel() const { return maModel
; }
251 /** Final processing after import of all style settings. */
252 void finalizeImport();
254 /** Returns an API font descriptor with own font information. */
255 const ::com::sun::star::awt::FontDescriptor
& getFontDescriptor() const { return maApiData
.maDesc
;}
256 /** Returns true, if the font requires rich text formatting in Calc.
257 @descr Example: Font escapement is a cell attribute in Excel, but Calc
258 needs an rich text cell for this attribute. */
259 bool needsRichTextFormat() const;
261 void fillToItemSet( SfxItemSet
& rItemSet
, bool bEditEngineText
, bool bSkipPoolDefs
= false ) const;
262 /** Writes all font attributes to the passed property map. */
263 void writeToPropertyMap(
264 PropertyMap
& rPropMap
,
265 FontPropertyType ePropType
) const;
266 /** Writes all font attributes to the passed property set. */
267 void writeToPropertySet(
268 PropertySet
& rPropSet
,
269 FontPropertyType ePropType
) const;
273 ApiFontData maApiData
;
274 ApiFontUsedFlags maUsedFlags
;
278 typedef std::shared_ptr
< Font
> FontRef
;
280 /** Contains all XML cell alignment attributes, e.g. from an alignment element. */
281 struct AlignmentModel
283 sal_Int32 mnHorAlign
; /// Horizontal alignment.
284 sal_Int32 mnVerAlign
; /// Vertical alignment.
285 sal_Int32 mnTextDir
; /// CTL text direction.
286 sal_Int32 mnRotation
; /// Text rotation angle.
287 sal_Int32 mnIndent
; /// Indentation.
288 bool mbWrapText
; /// True = multi-line text.
289 bool mbShrink
; /// True = shrink to fit cell size.
290 bool mbJustLastLine
; /// True = justify last line in block text.
292 explicit AlignmentModel();
294 /** Sets horizontal alignment from the passed BIFF data. */
295 void setBiffHorAlign( sal_uInt8 nHorAlign
);
296 /** Sets vertical alignment from the passed BIFF data. */
297 void setBiffVerAlign( sal_uInt8 nVerAlign
);
300 /** Contains all API cell alignment attributes. */
301 struct ApiAlignmentData
303 typedef ::com::sun::star::table::CellHoriJustify ApiCellHoriJustify
;
304 typedef ::com::sun::star::table::CellOrientation ApiCellOrientation
;
306 ApiCellHoriJustify meHorJustify
; /// Horizontal alignment.
307 sal_Int32 mnHorJustifyMethod
;
308 sal_Int32 mnVerJustify
; /// Vertical alignment.
309 sal_Int32 mnVerJustifyMethod
;
310 ApiCellOrientation meOrientation
; /// Normal or stacked text.
311 sal_Int32 mnRotation
; /// Text rotation angle.
312 sal_Int16 mnWritingMode
; /// CTL text direction.
313 sal_Int16 mnIndent
; /// Indentation.
314 bool mbWrapText
; /// True = multi-line text.
315 bool mbShrink
; /// True = shrink to fit cell size.
317 explicit ApiAlignmentData();
320 bool operator==( const ApiAlignmentData
& rLeft
, const ApiAlignmentData
& rRight
);
322 class Alignment
: public WorkbookHelper
325 explicit Alignment( const WorkbookHelper
& rHelper
);
327 /** Sets all attributes from the alignment element. */
328 void importAlignment( const AttributeList
& rAttribs
);
330 /** Sets the alignment attributes from the passed BIFF12 XF record data. */
331 void setBiff12Data( sal_uInt32 nFlags
);
333 /** Final processing after import of all style settings. */
334 void finalizeImport();
336 /** Returns the alignment model structure. */
337 inline const AlignmentModel
& getModel() const { return maModel
; }
338 /** Returns the converted API alignment data struct. */
339 inline const ApiAlignmentData
& getApiData() const { return maApiData
; }
341 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
342 /** Writes all alignment attributes to the passed property map. */
343 void writeToPropertyMap( PropertyMap
& rPropMap
) const;
346 ::SvxCellHorJustify
GetScHorAlign() const;
347 ::SvxCellVerJustify
GetScVerAlign() const;
348 ::SvxFrameDirection
GetScFrameDir() const;
349 AlignmentModel maModel
; /// Alignment model data.
350 ApiAlignmentData maApiData
; /// Alignment data converted to API constants.
353 typedef std::shared_ptr
< Alignment
> AlignmentRef
;
355 /** Contains all XML cell protection attributes, e.g. from a protection element. */
356 struct ProtectionModel
358 bool mbLocked
; /// True = locked against editing.
359 bool mbHidden
; /// True = formula is hidden.
361 explicit ProtectionModel();
364 /** Contains all API cell protection attributes. */
365 struct ApiProtectionData
367 typedef ::com::sun::star::util::CellProtection ApiCellProtection
;
369 ApiCellProtection maCellProt
;
371 explicit ApiProtectionData();
374 bool operator==( const ApiProtectionData
& rLeft
, const ApiProtectionData
& rRight
);
376 class Protection
: public WorkbookHelper
379 explicit Protection( const WorkbookHelper
& rHelper
);
381 /** Sets all attributes from the protection element. */
382 void importProtection( const AttributeList
& rAttribs
);
384 /** Sets the protection attributes from the passed BIFF12 XF record data. */
385 void setBiff12Data( sal_uInt32 nFlags
);
387 /** Final processing after import of all style settings. */
388 void finalizeImport();
390 /** Returns the protection model structure. */
391 inline const ProtectionModel
& getModel() const { return maModel
; }
392 /** Returns the converted API protection data struct. */
393 inline const ApiProtectionData
& getApiData() const { return maApiData
; }
395 /** Writes all protection attributes to the passed property map. */
396 void writeToPropertyMap( PropertyMap
& rPropMap
) const;
397 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
399 ProtectionModel maModel
; /// Protection model data.
400 ApiProtectionData maApiData
; /// Protection data converted to API constants.
403 typedef std::shared_ptr
< Protection
> ProtectionRef
;
405 /** Contains XML attributes of a single border line. */
406 struct BorderLineModel
408 Color maColor
; /// Borderline color.
409 sal_Int32 mnStyle
; /// Border line style.
410 bool mbUsed
; /// True = line format used.
412 explicit BorderLineModel( bool bDxf
);
414 /** Sets the passed BIFF line style. */
415 void setBiffStyle( sal_Int32 nLineStyle
);
418 /** Contains XML attributes of a complete cell border. */
421 BorderLineModel maLeft
; /// Left line format.
422 BorderLineModel maRight
; /// Right line format.
423 BorderLineModel maTop
; /// Top line format.
424 BorderLineModel maBottom
; /// Bottom line format.
425 BorderLineModel maDiagonal
; /// Diagonal line format.
426 bool mbDiagTLtoBR
; /// True = top-left to bottom-right on.
427 bool mbDiagBLtoTR
; /// True = bottom-left to top-right on.
429 explicit BorderModel( bool bDxf
);
432 /** Contains API attributes of a complete cell border. */
435 typedef ::com::sun::star::table::BorderLine2 ApiBorderLine
;
437 ApiBorderLine maLeft
; /// Left line format
438 ApiBorderLine maRight
; /// Right line format
439 ApiBorderLine maTop
; /// Top line format
440 ApiBorderLine maBottom
; /// Bottom line format
441 ApiBorderLine maTLtoBR
; /// Diagonal top-left to bottom-right line format.
442 ApiBorderLine maBLtoTR
; /// Diagonal bottom-left to top-right line format.
443 bool mbBorderUsed
; /// True = left/right/top/bottom line format used.
444 bool mbDiagUsed
; /// True = diagonal line format used.
446 explicit ApiBorderData();
448 /** Returns true, if any of the outer border lines is visible. */
449 bool hasAnyOuterBorder() const;
452 bool operator==( const ApiBorderData
& rLeft
, const ApiBorderData
& rRight
);
454 class Border
: public WorkbookHelper
457 explicit Border( const WorkbookHelper
& rHelper
, bool bDxf
);
459 /** Sets global border attributes from the border element. */
460 void importBorder( const AttributeList
& rAttribs
);
461 /** Sets border attributes for the border line with the passed element identifier. */
462 void importStyle( sal_Int32 nElement
, const AttributeList
& rAttribs
);
463 /** Sets color attributes for the border line with the passed element identifier. */
464 void importColor( sal_Int32 nElement
, const AttributeList
& rAttribs
);
466 /** Imports the BORDER record from the passed stream. */
467 void importBorder( SequenceInputStream
& rStrm
);
468 /** Imports a border from a DXF record from the passed stream. */
469 void importDxfBorder( sal_Int32 nElement
, SequenceInputStream
& rStrm
);
471 /** Final processing after import of all style settings. */
472 void finalizeImport( bool bRTL
);
474 /** Returns the border model structure. */
475 inline const BorderModel
& getModel() const { return maModel
; }
476 /** Returns the converted API border data struct. */
477 inline const ApiBorderData
& getApiData() const { return maApiData
; }
479 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
481 /** Writes all border attributes to the passed property map. */
482 void writeToPropertyMap( PropertyMap
& rPropMap
) const;
484 bool hasBorder() const;
487 /** Returns the border line struct specified by the passed XML token identifier. */
488 BorderLineModel
* getBorderLine( sal_Int32 nElement
);
490 /** Converts border line data to an API struct, returns true, if the line is marked as used. */
491 bool convertBorderLine(
492 ::com::sun::star::table::BorderLine2
& rBorderLine
,
493 const BorderLineModel
& rModel
);
497 ApiBorderData maApiData
;
501 typedef std::shared_ptr
< Border
> BorderRef
;
503 /** Contains XML pattern fill attributes from the patternFill element. */
504 struct PatternFillModel
506 Color maPatternColor
; /// Pattern foreground color.
507 Color maFillColor
; /// Background fill color.
508 sal_Int32 mnPattern
; /// Pattern identifier (e.g. solid).
509 bool mbPattColorUsed
; /// True = pattern foreground color used.
510 bool mbFillColorUsed
; /// True = background fill color used.
511 bool mbPatternUsed
; /// True = pattern used.
513 explicit PatternFillModel( bool bDxf
);
515 /** Sets the passed BIFF pattern identifier. */
516 void setBiffPattern( sal_Int32 nPattern
);
519 /** Contains XML gradient fill attributes from the gradientFill element. */
520 struct GradientFillModel
522 typedef ::std::map
< double, Color
> ColorMap
;
524 sal_Int32 mnType
; /// Gradient type, linear or path.
525 double mfAngle
; /// Rotation angle for type linear.
526 double mfLeft
; /// Left convergence for type path.
527 double mfRight
; /// Right convergence for type path.
528 double mfTop
; /// Top convergence for type path.
529 double mfBottom
; /// Bottom convergence for type path.
530 ColorMap maColors
; /// Gradient colors.
532 explicit GradientFillModel();
534 /** Reads BIFF12 gradient settings from a FILL or DXF record. */
535 void readGradient( SequenceInputStream
& rStrm
);
536 /** Reads BIFF12 gradient stop settings from a FILL or DXF record. */
537 void readGradientStop( SequenceInputStream
& rStrm
, bool bDxf
);
540 /** Contains API fill attributes. */
541 struct ApiSolidFillData
543 sal_Int32 mnColor
; /// Fill color.
544 bool mbTransparent
; /// True = transparent area.
545 bool mbUsed
; /// True = fill data is valid.
547 explicit ApiSolidFillData();
550 bool operator==( const ApiSolidFillData
& rLeft
, const ApiSolidFillData
& rRight
);
552 /** Contains cell fill attributes, either a pattern fill or a gradient fill. */
553 class Fill
: public WorkbookHelper
556 explicit Fill( const WorkbookHelper
& rHelper
, bool bDxf
);
558 /** Sets attributes of a patternFill element. */
559 void importPatternFill( const AttributeList
& rAttribs
);
560 /** Sets the pattern color from the fgColor element. */
561 void importFgColor( const AttributeList
& rAttribs
);
562 /** Sets the background color from the bgColor element. */
563 void importBgColor( const AttributeList
& rAttribs
);
564 /** Sets attributes of a gradientFill element. */
565 void importGradientFill( const AttributeList
& rAttribs
);
566 /** Sets a color from the color element in a gradient fill. */
567 void importColor( const AttributeList
& rAttribs
, double fPosition
);
569 /** Imports the FILL record from the passed stream. */
570 void importFill( SequenceInputStream
& rStrm
);
571 /** Imports the fill pattern from a DXF record. */
572 void importDxfPattern( SequenceInputStream
& rStrm
);
573 /** Imports the pattern color from a DXF record. */
574 void importDxfFgColor( SequenceInputStream
& rStrm
);
575 /** Imports the background color from a DXF record. */
576 void importDxfBgColor( SequenceInputStream
& rStrm
);
577 /** Imports gradient settings from a DXF record. */
578 void importDxfGradient( SequenceInputStream
& rStrm
);
579 /** Imports gradient stop settings from a DXF record. */
580 void importDxfStop( SequenceInputStream
& rStrm
);
582 /** Final processing after import of all style settings. */
583 void finalizeImport();
585 /** Returns the fill pattern model structure, if extant. */
586 inline const PatternFillModel
* getPatternModel() const { return mxPatternModel
.get(); }
587 /** Returns the fill gradient model structure, if extant. */
588 inline const GradientFillModel
* getGradientModel() const { return mxGradientModel
.get(); }
589 /** Returns the converted API fill data struct. */
590 inline const ApiSolidFillData
& getApiData() const { return maApiData
; }
592 void fillToItemSet( SfxItemSet
& rItemSet
, bool bSkipPoolDefs
= false ) const;
593 /** Writes all fill attributes to the passed property map. */
594 void writeToPropertyMap( PropertyMap
& rPropMap
) const;
597 typedef std::shared_ptr
< PatternFillModel
> PatternModelRef
;
598 typedef std::shared_ptr
< GradientFillModel
> GradientModelRef
;
600 PatternModelRef mxPatternModel
;
601 GradientModelRef mxGradientModel
;
602 ApiSolidFillData maApiData
;
606 typedef std::shared_ptr
< Fill
> FillRef
;
608 /** Contains all data for a cell format or cell style. */
611 sal_Int32 mnStyleXfId
; /// Index to parent style XF.
612 sal_Int32 mnFontId
; /// Index to font data list.
613 sal_Int32 mnNumFmtId
; /// Index to number format list.
614 sal_Int32 mnBorderId
; /// Index to list of cell borders.
615 sal_Int32 mnFillId
; /// Index to list of cell areas.
616 bool mbCellXf
; /// True = cell XF, false = style XF.
617 bool mbFontUsed
; /// True = font index used.
618 bool mbNumFmtUsed
; /// True = number format used.
619 bool mbAlignUsed
; /// True = alignment used.
620 bool mbProtUsed
; /// True = cell protection used.
621 bool mbBorderUsed
; /// True = border data used.
622 bool mbAreaUsed
; /// True = area data used.
627 bool operator==( const XfModel
& rXfModel1
, const XfModel
& rXfModel2
);
629 /** Represents a cell format or a cell style (called XF, extended format).
631 This class stores the type (cell/style), the index to the parent style (if
632 it is a cell format) and all "attribute used" flags, which reflect the
633 state of specific attribute groups (true = user has changed the attributes)
634 and all formatting data.
636 class Xf
: public WorkbookHelper
638 friend bool operator==( const Xf
& rXf1
, const Xf
& rXf2
);
642 std::list
<ScAttrEntry
> maAttrs
;
643 bool mbLatinNumFmtOnly
;
648 explicit Xf( const WorkbookHelper
& rHelper
);
650 /** Sets all attributes from the xf element. */
651 void importXf( const AttributeList
& rAttribs
, bool bCellXf
);
652 /** Sets all attributes from the alignment element. */
653 void importAlignment( const AttributeList
& rAttribs
);
654 /** Sets all attributes from the protection element. */
655 void importProtection( const AttributeList
& rAttribs
);
657 /** Imports the XF record from the passed stream. */
658 void importXf( SequenceInputStream
& rStrm
, bool bCellXf
);
660 /** Final processing after import of all style settings. */
661 void finalizeImport();
663 /** Returns true, if the XF is a cell XF, and false, if it is a style XF. */
664 inline bool isCellXf() const { return maModel
.mbCellXf
; }
666 /** Returns the referred font object. */
667 FontRef
getFont() const;
668 /** Returns the alignment data of this style. */
669 inline const Alignment
& getAlignment() const { return maAlignment
; }
670 /** Returns the cell protection data of this style. */
671 inline const Protection
& getProtection() const { return maProtection
; }
673 void applyPatternToAttrList(
674 AttrList
& rAttrs
, SCROW nRow1
, SCROW nRow2
, sal_Int32 nForceScNumFmt
);
676 /** Writes all formatting attributes to the passed property map. */
677 void writeToPropertyMap( PropertyMap
& rPropMap
) const;
678 /** Writes all formatting attributes to the passed property set. */
679 void writeToPropertySet( PropertySet
& rPropSet
) const;
681 void writeToDoc( ScDocumentImport
& rDoc
, const css::table::CellRangeAddress
& rRange
) const;
683 const ::ScPatternAttr
& createPattern( bool bSkipPoolDefs
= false );
686 typedef ::std::unique_ptr
< ::ScPatternAttr
> ScPatternAttrPtr
;
688 ScPatternAttrPtr mpPattern
; /// Calc item set.
689 sal_uLong mnScNumFmt
; /// Calc number format.
691 XfModel maModel
; /// Cell XF or style XF model data.
692 Alignment maAlignment
; /// Cell alignment data.
693 Protection maProtection
; /// Cell protection data.
694 sal_Int32 meRotationRef
; /// Rotation reference dependent on border.
695 ::ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
698 bool operator==( const Xf
& rXf1
, const Xf
& rXf2
);
700 typedef std::shared_ptr
< Xf
> XfRef
;
702 class Dxf
: public WorkbookHelper
705 explicit Dxf( const WorkbookHelper
& rHelper
);
707 /** Creates a new empty font object. */
708 FontRef
createFont( bool bAlwaysNew
= true );
709 /** Creates a new empty border object. */
710 BorderRef
createBorder( bool bAlwaysNew
= true );
711 /** Creates a new empty fill object. */
712 FillRef
createFill( bool bAlwaysNew
= true );
714 /** Inserts a new number format code. */
715 void importNumFmt( const AttributeList
& rAttribs
);
717 /** Imports the DXF record from the passed stream. */
718 void importDxf( SequenceInputStream
& rStrm
);
720 /** Final processing after import of all style settings. */
721 void finalizeImport();
723 void fillToItemSet( SfxItemSet
& rSet
) const;
726 FontRef mxFont
; /// Font data.
727 NumberFormatRef mxNumFmt
; /// Number format data.
728 AlignmentRef mxAlignment
; /// Alignment data.
729 ProtectionRef mxProtection
; /// Protection data.
730 BorderRef mxBorder
; /// Border data.
731 FillRef mxFill
; /// Fill data.
734 typedef std::shared_ptr
< Dxf
> DxfRef
;
736 /** Contains attributes of a cell style, e.g. from the cellStyle element. */
737 struct CellStyleModel
739 OUString maName
; /// Cell style name.
740 sal_Int32 mnXfId
; /// Formatting for this cell style.
741 sal_Int32 mnBuiltinId
; /// Identifier for builtin styles.
742 sal_Int32 mnLevel
; /// Level for builtin column/row styles.
743 bool mbBuiltin
; /// True = builtin style.
744 bool mbCustom
; /// True = customized builtin style.
745 bool mbHidden
; /// True = style not visible in GUI.
747 explicit CellStyleModel();
749 /** Returns true, if this style is a builtin style. */
750 bool isBuiltin() const;
751 /** Returns true, if this style represents the default document cell style. */
752 bool isDefaultStyle() const;
755 class CellStyle
: public WorkbookHelper
758 explicit CellStyle( const WorkbookHelper
& rHelper
);
760 /** Imports passed attributes from the cellStyle element. */
761 void importCellStyle( const AttributeList
& rAttribs
);
762 /** Imports style settings from a CELLSTYLE record. */
763 void importCellStyle( SequenceInputStream
& rStrm
);
765 /** Creates the style sheet in the document described by this cell style object. */
766 void createCellStyle();
767 /** Stores tha passed final style name and creates the cell style, if it is
768 user-defined or modified built-in. */
769 void finalizeImport( const OUString
& rFinalName
);
771 /** Returns the cell style model structure. */
772 inline const CellStyleModel
& getModel() const { return maModel
; }
773 /** Returns the final style name used in the document. */
774 inline const OUString
& getFinalStyleName() const { return maFinalName
; }
775 inline ::ScStyleSheet
* getStyleSheet() { return mpStyleSheet
; }
777 CellStyleModel maModel
;
778 OUString maFinalName
; /// Final style name used in API.
779 bool mbCreated
; /// True = style sheet created.
780 ::ScStyleSheet
* mpStyleSheet
; /// Calc cell style sheet.
784 typedef std::shared_ptr
< CellStyle
> CellStyleRef
;
786 class CellStyleBuffer
: public WorkbookHelper
789 explicit CellStyleBuffer( const WorkbookHelper
& rHelper
);
791 /** Appends and returns a new named cell style object. */
792 CellStyleRef
importCellStyle( const AttributeList
& rAttribs
);
793 /** Imports the CELLSTYLE record from the passed stream. */
794 CellStyleRef
importCellStyle( SequenceInputStream
& rStrm
);
796 /** Final processing after import of all style settings. */
797 void finalizeImport();
799 /** Returns the XF identifier associated to the default cell style. */
800 sal_Int32
getDefaultXfId() const;
801 /** Returns the default style sheet for unused cells. */
802 OUString
getDefaultStyleName() const;
803 /** Creates the style sheet described by the style XF with the passed identifier. */
804 OUString
createCellStyle( sal_Int32 nXfId
) const;
805 ::ScStyleSheet
* getCellStyleSheet( sal_Int32 nXfId
) const;
808 /** Inserts the passed cell style object into the internal maps. */
809 void insertCellStyle( CellStyleRef xCellStyle
);
810 /** Creates the style sheet described by the passed cell style object. */
811 static OUString
createCellStyle( const CellStyleRef
& rxCellStyle
);
812 static ::ScStyleSheet
* getCellStyleSheet( const CellStyleRef
& rxCellStyle
);
815 typedef RefVector
< CellStyle
> CellStyleVector
;
816 typedef RefMap
< sal_Int32
, CellStyle
> CellStyleXfIdMap
;
818 CellStyleVector maBuiltinStyles
; /// All built-in cell styles.
819 CellStyleVector maUserStyles
; /// All user defined cell styles.
820 CellStyleXfIdMap maStylesByXf
; /// All cell styles, mapped by XF identifier.
821 CellStyleRef mxDefStyle
; /// Default cell style.
824 struct AutoFormatModel
826 sal_Int32 mnAutoFormatId
; /// Index of predefined autoformatting.
827 bool mbApplyNumFmt
; /// True = apply number format from autoformatting.
828 bool mbApplyFont
; /// True = apply font from autoformatting.
829 bool mbApplyAlignment
; /// True = apply alignment from autoformatting.
830 bool mbApplyBorder
; /// True = apply border from autoformatting.
831 bool mbApplyFill
; /// True = apply fill from autoformatting.
832 bool mbApplyProtection
; /// True = apply protection from autoformatting.
834 explicit AutoFormatModel();
837 class StylesBuffer
: public WorkbookHelper
840 explicit StylesBuffer( const WorkbookHelper
& rHelper
);
842 /** Creates a new empty font object.
843 @param opnFontId (out-param) The identifier of the new font object. */
844 FontRef
createFont( sal_Int32
* opnFontId
= 0 );
845 /** Creates a number format. */
846 NumberFormatRef
createNumFmt( sal_Int32 nNumFmtId
, const OUString
& rFmtCode
);
847 sal_Int32
nextFreeNumFmtId();
848 /** Creates a new empty border object.
849 @param opnBorderId (out-param) The identifier of the new border object. */
850 BorderRef
createBorder( sal_Int32
* opnBorderId
= 0 );
851 /** Creates a new empty fill object.
852 @param opnFillId (out-param) The identifier of the new fill object. */
853 FillRef
createFill( sal_Int32
* opnFillId
= 0 );
854 /** Creates a new empty cell formatting object.
855 @param opnXfId (out-param) The identifier of the new XF object. */
856 XfRef
createCellXf( sal_Int32
* opnXfId
= 0 );
857 /** Creates a new empty style formatting object.
858 @param opnXfId (out-param) The identifier of the new XF object. */
859 XfRef
createStyleXf( sal_Int32
* opnXfId
= 0 );
860 /** Creates a new empty differential formatting object.
861 @param opnDxfId (out-param) The identifier of the new DXF object. */
862 DxfRef
createDxf( sal_Int32
* opnDxfId
= 0 );
864 /** Appends a new color to the color palette. */
865 void importPaletteColor( const AttributeList
& rAttribs
);
866 /** Inserts a new number format code. */
867 NumberFormatRef
importNumFmt( const AttributeList
& rAttribs
);
868 /** Appends and returns a new named cell style object. */
869 CellStyleRef
importCellStyle( const AttributeList
& rAttribs
);
871 /** Appends a new color to the color palette. */
872 void importPaletteColor( SequenceInputStream
& rStrm
);
873 /** Imports the NUMFMT record from the passed stream. */
874 void importNumFmt( SequenceInputStream
& rStrm
);
875 /** Imports the CELLSTYLE record from the passed stream. */
876 void importCellStyle( SequenceInputStream
& rStrm
);
878 /** Final processing after import of all style settings. */
879 void finalizeImport();
881 /** Returns the palette color with the specified index. */
882 sal_Int32
getPaletteColor( sal_Int32 nIndex
) const;
883 /** Returns the specified font object. */
884 FontRef
getFont( sal_Int32 nFontId
) const;
885 /** Returns the specified border object. */
886 BorderRef
getBorder( sal_Int32 nBorderId
) const;
887 /** Returns the specified cell format object. */
888 XfRef
getCellXf( sal_Int32 nXfId
) const;
889 /** Returns the specified style format object. */
890 XfRef
getStyleXf( sal_Int32 nXfId
) const;
892 /** Returns the font object of the specified cell XF. */
893 FontRef
getFontFromCellXf( sal_Int32 nXfId
) const;
894 /** Returns the default application font (used in the "Normal" cell style). */
895 FontRef
getDefaultFont() const;
896 /** Returns the model of the default application font (used in the "Normal" cell style). */
897 const FontModel
& getDefaultFontModel() const;
899 /** Returns true, if the specified borders are equal. */
900 bool equalBorders( sal_Int32 nBorderId1
, sal_Int32 nBorderId2
) const;
901 /** Returns true, if the specified fills are equal. */
902 bool equalFills( sal_Int32 nFillId1
, sal_Int32 nFillId2
) const;
904 /** Returns the default style sheet for unused cells. */
905 OUString
getDefaultStyleName() const;
906 /** Creates the style sheet described by the style XF with the passed identifier. */
907 OUString
createCellStyle( sal_Int32 nXfId
) const;
908 ::ScStyleSheet
* getCellStyleSheet( sal_Int32 nXfId
) const;
909 /** Creates the style sheet described by the DXF with the passed identifier. */
910 OUString
createDxfStyle( sal_Int32 nDxfId
) const;
912 void writeFontToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nFontId
, bool bSkipPoolDefs
= false ) const;
913 /** Writes the font attributes of the specified font data to the passed property map. */
914 void writeFontToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nFontId
) const;
915 sal_uLong
writeNumFmtToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nNumFmtId
, bool bSkipPoolDefs
= false ) const;
916 /** Writes the specified number format to the passed property map. */
917 void writeNumFmtToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nNumFmtId
) const;
918 void writeBorderToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nBorderId
, bool bSkipPoolDefs
= false ) const;
919 /** Writes the border attributes of the specified border data to the passed property map. */
920 void writeBorderToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nBorderId
) const;
921 /** Writes the fill attributes of the specified fill data to the passed property map. */
922 void writeFillToItemSet( SfxItemSet
& rItemSet
, sal_Int32 nFillId
, bool bSkipPoolDefs
= false ) const;
923 void writeFillToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nFillId
) const;
925 /** Writes the cell formatting attributes of the specified XF to the passed property set. */
926 void writeCellXfToPropertySet( PropertySet
& rPropSet
, sal_Int32 nXfId
) const;
927 void writeCellXfToDoc( ScDocumentImport
& rDoc
, const css::table::CellRangeAddress
& rRange
, sal_Int32 nXfId
) const;
929 bool hasBorder( sal_Int32 nBorderId
) const;
931 typedef RefVector
< Font
> FontVector
;
932 typedef RefVector
< Border
> BorderVector
;
933 typedef RefVector
< Fill
> FillVector
;
934 typedef RefVector
< Xf
> XfVector
;
935 typedef RefVector
< Dxf
> DxfVector
;
936 typedef ::std::map
< sal_Int32
, OUString
> DxfStyleMap
;
938 ColorPalette maPalette
; /// Color palette.
939 FontVector maFonts
; /// List of font objects.
940 NumberFormatsBuffer maNumFmts
; /// List of all number format codes.
941 BorderVector maBorders
; /// List of cell border objects.
942 FillVector maFills
; /// List of cell area fill objects.
943 XfVector maCellXfs
; /// List of cell formats.
944 XfVector maStyleXfs
; /// List of cell styles.
945 CellStyleBuffer maCellStyles
; /// All built-in and user defined cell styles.
946 DxfVector maDxfs
; /// List of differential cell styles.
947 mutable DxfStyleMap maDxfStyles
; /// Maps DXF identifiers to Calc style sheet names.
955 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */