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 <svl/zforlist.hxx>
24 #include <svl/nfkeytab.hxx>
25 #include <editeng/svxfont.hxx>
26 #include "xerecord.hxx"
27 #include "xlstyle.hxx"
29 #include <fonthelper.hxx>
33 #include <docmodel/color/ComplexColor.hxx>
35 /* ============================================================================
36 - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
37 ============================================================================ */
39 const sal_uInt16 EXC_ID_FONTLIST
= 0x8031; /// For internal use only.
40 const sal_uInt16 EXC_ID_FORMATLIST
= 0x801E; /// For internal use only.
41 const sal_uInt16 EXC_ID_XFLIST
= 0x8043; /// For internal use only.
42 const sal_uInt16 EXC_ID_DXFS
= 0x9999; /// For internal use only. TODO:moggi: find a better/correct value
44 // PALETTE record - color information =========================================
46 /** Different types of colors in a document. */
49 EXC_COLOR_CELLTEXT
, /// Text in a cell.
50 EXC_COLOR_CELLBORDER
, /// Border of a cell.
51 EXC_COLOR_CELLAREA
, /// Background area of a cell.
52 EXC_COLOR_CHARTTEXT
, /// Text color in a chart.
53 EXC_COLOR_CHARTLINE
, /// Line in a chart.
54 EXC_COLOR_CHARTAREA
, /// Area in a chart.
55 EXC_COLOR_CTRLTEXT
, /// Text color in a form control.
56 EXC_COLOR_GRID
, /// Spreadsheet grid color.
57 EXC_COLOR_TABBG
/// Spreadsheet tab bg color.
60 class XclExpPaletteImpl
;
62 /** Stores all used colors in the document.
64 Supports color reduction to the maximum count of the current BIFF version.
65 An instance of this class collects all colors in the conversion phase of
66 the export, using the InsertColor() function. It returns a unique
67 identifier for each passed color.
69 After the entire document is converted, the Finalize() function will reduce
70 the palette to the number of colors supported by the current BIFF version.
72 Then, in the streaming phase, the functions GetColorIndex() and
73 GetMixedColors() return the real Excel palette index for all color
76 class XclExpPalette
: public XclDefaultPalette
, public XclExpRecord
79 explicit XclExpPalette( const XclExpRoot
& rRoot
);
80 virtual ~XclExpPalette() override
;
82 /** Inserts the color into the list and updates weighting.
83 @param nAutoDefault The Excel palette index for automatic color.
84 @return A unique ID for this color. */
85 sal_uInt32
InsertColor( const Color
& rColor
, XclExpColorType eType
, sal_uInt16 nAutoDefault
= 0 );
86 /** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
87 static sal_uInt32
GetColorIdFromIndex( sal_uInt16 nIndex
);
89 /** Reduces the color list to the maximum count of the current BIFF version. */
92 /** Returns the Excel palette index of the color with passed color ID. */
93 sal_uInt16
GetColorIndex( sal_uInt32 nColorId
) const;
95 /** Returns a foreground and background color for the two passed color IDs.
96 @descr If rnXclPattern contains a solid pattern, this function tries to find
97 the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
98 This will result in a better approximation to the passed foreground color. */
100 sal_uInt16
& rnXclForeIx
, sal_uInt16
& rnXclBackIx
, sal_uInt8
& rnXclPattern
,
101 sal_uInt32 nForeColorId
, sal_uInt32 nBackColorId
) const;
103 /** Returns the color for a (non-zero-based) Excel palette entry.
104 @return The color from current or default palette or COL_AUTO, if nothing else found. */
105 Color
GetColor( sal_uInt16 nXclIndex
) const;
107 /** Saves the PALETTE record, if it differs from the default palette. */
108 virtual void Save( XclExpStream
& rStrm
) override
;
109 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
112 /** Writes the contents of the PALETTE record. */
113 virtual void WriteBody( XclExpStream
& rStrm
) override
;
116 typedef std::shared_ptr
< XclExpPaletteImpl
> XclExpPaletteImplRef
;
117 XclExpPaletteImplRef mxImpl
;
120 // FONT record - font information =============================================
122 const size_t EXC_FONTLIST_NOTFOUND
= static_cast< size_t >( -1 );
124 /** Helper functions for font export. */
125 namespace XclExpFontHelper
127 /** Returns the script type of the first font item found in the item set and its parents. */
128 sal_Int16
GetFirstUsedScript(
129 const XclExpRoot
& rRoot
,
130 const SfxItemSet
& rItemSet
);
132 /** Returns a VCL font object filled from the passed item set. */
133 vcl::Font
GetFontFromItemSet(
134 const XclExpRoot
& rRoot
,
135 const SfxItemSet
& rItemSet
,
139 * Get a dxf related font object from the item set.
140 * Only items that are explicitly set in the item set
141 * are also set in the returned object.
143 ScDxfFont
GetDxfFontFromItemSet(const XclExpRoot
& rRoot
, const SfxItemSet
& rSet
);
145 /** Returns true, if at least one font related item is set in the passed item set.
146 @param bDeep true = Searches in parent item sets too. */
148 const XclExpRoot
& rRoot
,
149 const SfxItemSet
& rItemSet
,
154 /** Stores all data of an Excel font and provides export of FONT records. */
155 class XclExpFont
: public XclExpRecord
, protected XclExpRoot
158 explicit XclExpFont( const XclExpRoot
& rRoot
,
159 const XclFontData
& rFontData
, XclExpColorType eColorType
);
161 /** Returns read-only access to font data. */
162 const XclFontData
& GetFontData() const { return maData
; }
163 /** Returns the font color identifier. */
164 sal_uInt32
GetFontColorId() const { return mnColorId
; }
165 /** Compares this font with the passed font data.
166 @param nHash The hash value calculated from the font data. */
167 virtual bool Equals( const XclFontData
& rFontData
, sal_uInt32 nHash
) const;
169 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
172 /** Writes the contents of the FONT record. */
173 virtual void WriteBody( XclExpStream
& rStrm
) override
;
176 XclFontData maData
; /// All font attributes.
177 sal_uInt32 mnColorId
; /// Unique color ID for text color.
178 sal_uInt32 mnHash
; /// Hash value for fast comparison.
181 class XclExpDxfFont
: public XclExpRecordBase
, protected XclExpRoot
184 XclExpDxfFont(const XclExpRoot
& rRoot
, const SfxItemSet
& rItemSet
);
186 virtual void SaveXml(XclExpXmlStream
& rStrm
) override
;
192 /** Used as placeholder for font index 4, which is not used in Excel. */
193 class XclExpBlindFont
: public XclExpFont
196 explicit XclExpBlindFont( const XclExpRoot
& rRoot
);
198 /** Returns always false to never find this font while searching the font list. */
199 virtual bool Equals( const XclFontData
& rFontData
, sal_uInt32 nHash
) const override
;
201 /** Skips writing this record. */
202 virtual void Save( XclExpStream
& rStrm
) override
;
207 /** Stores the data of all fonts used in the document. */
208 class XclExpFontBuffer
: public XclExpRecordBase
, protected XclExpRoot
211 explicit XclExpFontBuffer( const XclExpRoot
& rRoot
);
213 /** Returns the specified font from font list. */
214 const XclExpFont
* GetFont( sal_uInt16 nXclFont
) const;
215 /** Returns the application font data of this file, needed e.g. for column width. */
216 const XclFontData
& GetAppFontData() const;
218 /** Inserts a new font with the passed font data into the buffer if not present.
219 @param bAppFont true = Sets the application font; false = Inserts a new font.
220 @return The resulting Excel font index. */
221 sal_uInt16
Insert(const XclFontData
& rFontData
, XclExpColorType eColorType
, bool bAppFont
= false );
222 /** Inserts the SvxFont into the buffer if not present, e.g. where escapements are used.
223 @return The resulting Excel font index. */
224 sal_uInt16
Insert(const SvxFont
& rFont
, model::ComplexColor
const& rComplexColor
, XclExpColorType eColorType
);
225 /** Inserts the font contained in the passed item set into the buffer, if not present.
226 @param nScript The script type of the font properties to be used.
227 @param bAppFont true = Sets the application font; false = Inserts a new font.
228 @return The resulting Excel font index. */
229 sal_uInt16
Insert(const SfxItemSet
& rItemSet
, sal_Int16 nScript
, XclExpColorType eColorType
, bool bAppFont
);
231 /** Writes all FONT records contained in this buffer. */
232 virtual void Save( XclExpStream
& rStrm
) override
;
233 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
236 /** Initializes the default fonts for the current BIFF version. */
237 void InitDefaultFonts();
238 /** Tries to find the passed font and returns the current list index. */
239 size_t Find( const XclFontData
& rFontData
);
242 typedef XclExpRecordList
< XclExpFont
> XclExpFontList
;
243 typedef XclExpFontList::RecordRefType XclExpFontRef
;
245 XclExpFontList maFontList
; /// List of all FONT records.
246 size_t mnXclMaxSize
; /// Maximum number of fonts.
249 // FORMAT record - number formats =============================================
251 /** Stores a core number format index with corresponding Excel format index. */
254 sal_uInt32 mnScNumFmt
; /// Core index of the number format.
255 sal_uInt16 mnXclNumFmt
; /// Resulting Excel format index.
256 OUString maNumFmtString
; /// format string
258 explicit XclExpNumFmt( sal_uInt32 nScNumFmt
, sal_uInt16 nXclNumFmt
, OUString aFrmt
) :
259 mnScNumFmt( nScNumFmt
), mnXclNumFmt( nXclNumFmt
), maNumFmtString(std::move( aFrmt
)) {}
261 void SaveXml( XclExpXmlStream
& rStrm
);
264 typedef ::std::unique_ptr
< SvNumberFormatter
> SvNumberFormatterPtr
;
266 /** Stores all number formats used in the document. */
267 class XclExpNumFmtBuffer
: public XclExpRecordBase
, protected XclExpRoot
270 explicit XclExpNumFmtBuffer( const XclExpRoot
& rRoot
);
271 virtual ~XclExpNumFmtBuffer() override
;
273 /** Returns the core index of the current standard number format. */
274 sal_uInt32
GetStandardFormat() const { return mnStdFmt
; }
276 /** Inserts a number format into the format buffer.
277 @param nScNumFmt The core index of the number format.
278 @return The resulting Excel format index. */
279 sal_uInt16
Insert( sal_uInt32 nScNumFmt
);
281 /** Writes all FORMAT records contained in this buffer. */
282 virtual void Save( XclExpStream
& rStrm
) override
;
283 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
285 OUString
GetFormatCode ( sal_uInt32 nScNumFmt
);
288 /** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
289 void WriteFormatRecord( XclExpStream
& rStrm
, sal_uInt16 nXclNumFmt
, const OUString
& rFormatStr
);
290 /** Writes the FORMAT record represented by rFormat. */
291 void WriteFormatRecord( XclExpStream
& rStrm
, const XclExpNumFmt
& rFormat
);
294 typedef ::std::vector
< XclExpNumFmt
> XclExpNumFmtVec
;
296 SvNumberFormatterPtr mxFormatter
; /// Special number formatter for conversion.
297 XclExpNumFmtVec maFormatMap
; /// Maps core formats to Excel indexes.
298 std::unique_ptr
<NfKeywordTable
> mpKeywordTable
; /// Replacement table.
299 sal_uInt32 mnStdFmt
; /// Key for standard number format.
300 sal_uInt16 mnXclOffset
; /// Offset to first user defined format.
303 // XF, STYLE record - Cell formatting =========================================
305 /** Extends the XclCellProt struct for export.
306 @descr Provides functions to fill from item sets and to fill to Excel record data. */
307 struct XclExpCellProt
: public XclCellProt
309 /** Fills the protection attributes from the passed item set.
310 @return true = At least one protection item is set. */
311 bool FillFromItemSet( const SfxItemSet
& rItemSet
, bool bStyle
= false );
313 /** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
314 void FillToXF3( sal_uInt16
& rnProt
) const;
316 void SaveXml( XclExpXmlStream
& rStrm
) const;
319 /** Extends the XclCellAlign struct for export.
320 @descr Provides functions to fill from item sets and to fill to Excel record data. */
321 struct XclExpCellAlign
: public XclCellAlign
323 /** Fills the alignment attributes from the passed item set.
324 @descr Fills only the attributes exported in the passed BIFF version.
325 @param bForceLineBreak true = Set line break flag unconditionally.
326 @return true = At least one alignment item is set. */
327 bool FillFromItemSet(const XclRoot
& rRoot
, const SfxItemSet
& rItemSet
,
328 bool bForceLineBreak
, XclBiff eBiff
, bool bStyle
= false );
330 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
331 void FillToXF5( sal_uInt16
& rnAlign
) const;
332 /** Fills the data to the passed fields of a BIFF8 XF record. */
333 void FillToXF8( sal_uInt16
& rnAlign
, sal_uInt16
& rnMiscAttrib
) const;
335 void SaveXml( XclExpXmlStream
& rStrm
) const;
338 /** Extends the XclCellBorder struct for export.
339 @descr Provides functions to fill from item sets and to fill to Excel record data. */
340 struct XclExpCellBorder
: public XclCellBorder
342 sal_uInt32 mnLeftColorId
; /// Color ID for left line.
343 sal_uInt32 mnRightColorId
; /// Color ID for right line.
344 sal_uInt32 mnTopColorId
; /// Color ID for top line.
345 sal_uInt32 mnBottomColorId
; /// Color ID for bottom line.
346 sal_uInt32 mnDiagColorId
; /// Color ID for diagonal line(s).
348 model::ComplexColor maComplexColorLeft
;
349 model::ComplexColor maComplexColorRight
;
350 model::ComplexColor maComplexColorTop
;
351 model::ComplexColor maComplexColorBottom
;
352 model::ComplexColor maComplexColorDiagonal
;
354 explicit XclExpCellBorder();
356 /** Fills the border attributes from the passed item set.
357 @descr Fills only the attributes exported in the passed BIFF version.
358 @return true = At least one border item is set. */
359 bool FillFromItemSet( const SfxItemSet
& rItemSet
,
360 XclExpPalette
& rPalette
, XclBiff eBiff
, bool bStyle
= false );
361 /** Fills the mn***Color base members from the mn***ColorId members. */
362 void SetFinalColors( const XclExpPalette
& rPalette
);
364 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
365 void FillToXF5( sal_uInt32
& rnBorder
, sal_uInt32
& rnArea
) const;
366 /** Fills the data to the passed fields of a BIFF8 XF record. */
367 void FillToXF8( sal_uInt32
& rnBorder1
, sal_uInt32
& rnBorder2
) const;
369 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
370 void FillToCF8( sal_uInt16
& rnLine
, sal_uInt32
& rnColor
) const;
372 void SaveXml( XclExpXmlStream
& rStrm
) const;
375 /** Extends the XclCellArea struct for export.
376 @descr Provides functions to fill from item sets and to fill to Excel record data. */
377 struct XclExpCellArea
: public XclCellArea
379 sal_uInt32 mnForeColorId
; /// Foreground color ID.
380 sal_uInt32 mnBackColorId
; /// Background color ID.
382 Color maForeColor
; // Actual foreground color
383 Color maBackColor
; // Actual background color
385 model::ComplexColor maForegroundComplexColor
;
386 model::ComplexColor maBackgroundComplexColor
;
388 explicit XclExpCellArea();
389 explicit XclExpCellArea(Color aForeColor
, Color aBackColor
);
391 /** Fills the area attributes from the passed item set.
392 @return true = At least one area item is set. */
393 bool FillFromItemSet(
394 const SfxItemSet
& rItemSet
, XclExpPalette
& rPalette
,
396 /** Fills the mn***Color base members from the mn***ColorId members. */
397 void SetFinalColors( const XclExpPalette
& rPalette
);
399 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
400 void FillToXF5( sal_uInt32
& rnArea
) const;
401 /** Fills the data to the passed fields of a BIFF8 XF record. */
402 void FillToXF8( sal_uInt32
& rnBorder2
, sal_uInt16
& rnArea
) const;
404 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
405 void FillToCF8( sal_uInt16
& rnPattern
, sal_uInt16
& rnColor
) const;
407 void SaveXml( XclExpXmlStream
& rStrm
) const;
413 model::ComplexColor maComplexColor
;
415 bool FillFromItemSet( const SfxItemSet
& rItemSet
);
417 void SaveXml( XclExpXmlStream
& rStrm
) const;
420 /** A combination of unique XF identifier with real Excel XF index. */
423 sal_uInt32 mnXFId
; /// Temporary XF identifier.
424 sal_uInt16 mnXFIndex
; /// Real Excel XF index.
426 explicit XclExpXFId();
427 explicit XclExpXFId( sal_uInt32 nXFId
)
428 : mnXFId( nXFId
), mnXFIndex( EXC_XF_DEFAULTCELL
) {}
430 /** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
431 void ConvertXFIndex( const XclExpRoot
& rRoot
);
434 class SfxStyleSheetBase
;
436 /** Represents an XF record which contains all formatting data of a cell or cell style. */
437 class XclExpXF
: public XclXFBase
, public XclExpRecord
, protected XclExpRoot
440 /** Constructs a cell XF record from the passed Calc cell formatting. */
442 const XclExpRoot
& rRoot
,
443 const ScPatternAttr
& rPattern
,
445 sal_uInt32 nScForceNumFmt
= NUMBERFORMAT_ENTRY_NOT_FOUND
,
446 sal_uInt16 nForceXclFont
= EXC_FONT_NOTFOUND
,
447 bool bForceLineBreak
= false );
448 /** Constructs a style XF record from the passed cell style sheet. */
450 const XclExpRoot
& rRoot
,
451 const SfxStyleSheetBase
& rStyleSheet
);
453 /** Returns the cell protection settings of this XF. */
454 const XclExpCellProt
& GetProtectionData() const { return maProtection
; }
455 /** Returns the alignment settings of this XF. */
456 const XclExpCellAlign
& GetAlignmentData() const { return maAlignment
; }
457 /** Returns the cell border settings of this XF. */
458 const XclExpCellBorder
& GetBorderData() const { return maBorder
; }
459 /** Returns the cell fill settings of this XF. */
460 const XclExpCellArea
& GetAreaData() const { return maArea
; }
462 /** Returns true, if this XF record represents the passed cell formatting.
463 @descr Searches for cell XFs only. */
465 const ScPatternAttr
& rPattern
,
466 sal_uInt32 nScForceNumFmt
,
467 sal_uInt16 nForceXclFont
,
468 bool bForceLineBreak
) const;
470 /** Returns true, if this XF record represents the passed style.
471 @descr Searches for style XFs only. */
472 bool Equals( const SfxStyleSheetBase
& rStyleSheet
) const;
474 /** Sets the resulting Excel palette index from all used color IDs (border and area). */
475 void SetFinalColors();
477 /** Returns true, if this XF record is completely equal to the passed. */
478 bool Equals( const XclExpXF
& rCmpXF
) const;
480 void SetXmlIds( sal_uInt32 nBorderId
, sal_uInt32 nFillId
);
482 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
484 const SfxItemSet
* GetItemSet() const { return mpItemSet
; }
486 sal_uInt32
GetScNumFmt() const { return mnScNumFmt
; }
487 sal_uInt16
GetXclFont() const { return mnXclFont
; }
490 explicit XclExpXF( const XclExpRoot
& rRoot
, bool bCellXF
);
492 protected: // access for XclExpDefaultXF
493 const SfxItemSet
* mpItemSet
; /// Pointer to the item set (we do not own it).
495 XclExpCellProt maProtection
; /// Cell protection flags.
496 XclExpCellAlign maAlignment
; /// All alignment attributes.
497 XclExpCellBorder maBorder
; /// Border line style.
498 XclExpCellArea maArea
; /// Background area style.
499 sal_uInt32 mnParentXFId
; /// XF ID of parent XF record.
500 sal_uInt32 mnScNumFmt
; /// Calc number format index.
501 sal_uInt16 mnXclFont
; /// Excel font index.
502 sal_uInt16 mnXclNumFmt
; /// Excel number format index.
503 sal_Int32 mnBorderId
; /// OOXML Border Index
504 sal_Int32 mnFillId
; /// OOXML Fill Index
507 using XclXFBase::Equals
;
509 /** Initializes with default values. */
511 /** Fills all members from the passed item set.
512 @param bDefStyle true = This is the "Default"/"Normal" style - needs special handling. */
514 const SfxItemSet
& rItemSet
,
516 sal_uInt32 nForceScNumFmt
,
517 sal_uInt16 nForceXclFont
,
518 bool bForceLineBreak
,
521 /** Returns the bits specifying the used attributes.
522 @descr In cell XFs a set bit means a used attribute, in style XF a cleared
523 bit means a used attribute. This method regards the cell/style state.
524 @return The mask based on bit 0 (not yet bit-shifted as needed for export). */
525 sal_uInt8
GetUsedFlags() const;
527 void WriteBody5( XclExpStream
& rStrm
);
528 void WriteBody8( XclExpStream
& rStrm
);
530 /** Writes the contents of the XF record. */
531 virtual void WriteBody( XclExpStream
& rStrm
) override
;
534 /** Represents a default XF record. Supports methods to set attributes directly. */
535 class XclExpDefaultXF
: public XclExpXF
538 explicit XclExpDefaultXF( const XclExpRoot
& rRoot
, bool bCellXF
);
540 /** Sets the Excel font index. */
541 void SetFont( sal_uInt16 nXclFont
);
542 /** Sets the Excel number format index. */
543 void SetNumFmt( sal_uInt16 nXclNumFmt
);
546 /** Represents a STYLE record containing the data of a cell style.
547 @descr The class is able to store built-in and user-defined styles. */
548 class XclExpStyle
: public XclExpRecord
551 explicit XclExpStyle( sal_uInt32 nXFId
, OUString aStyleName
);
552 explicit XclExpStyle( sal_uInt32 nXFId
, sal_uInt8 nStyleId
, sal_uInt8 nLevel
);
554 /** Returns true, if this record represents an Excel built-in style. */
555 bool IsBuiltIn() const { return mnStyleId
!= EXC_STYLE_USERDEF
; }
557 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
560 /** Writes the contents of the STYLE record. */
561 virtual void WriteBody( XclExpStream
& rStrm
) override
;
564 OUString maName
; /// Name of the cell style.
565 XclExpXFId maXFId
; /// XF identifier for style formatting.
566 sal_uInt8 mnStyleId
; /// Built-in style identifier.
567 sal_uInt8 mnLevel
; /// Outline level for RowLevel and ColLevel styles.
570 /** Stores all XF records (cell formats and cell styles) in the document.
572 Stores also the names of user defined cell styles (STYLE records). Supports
573 reduction to the maximum count of XF records of the current BIFF version.
575 An instance of this class collects all XF records in the conversion phase
576 of the export, using the Insert() and InsertStyle() functions. It returns a
577 unique identifier for each XF record.
579 After the entire document is converted, the Finalize() function will reduce
580 the list to the number of XF records supported by the current BIFF version.
582 Then, in the streaming phase, the function GetXFIndex() returns the real
583 Excel XF index for all XF identifiers.
585 class XclExpXFBuffer
: public XclExpRecordBase
, protected XclExpRoot
588 explicit XclExpXFBuffer( const XclExpRoot
& rRoot
);
590 /** Inserts predefined built-in styles and user-defined styles. */
593 /** Finds or creates a cell XF record for the passed item set.
594 @return A unique XF record ID. */
595 sal_uInt32
Insert( const ScPatternAttr
* pPattern
, sal_Int16 nScript
);
596 /** Finds or creates a cell XF record for the passed item set.
597 @param nForceXclFont The font to be exported. If not equal to EXC_FONT_NOTFOUND,
598 this font index will be used unconditionally and the cell font will be ignored.
599 @param bForceLineBreak true = Set line break flag unconditionally.
600 This is required for cells that contain multi-line text.
601 @return A unique XF record ID. */
602 sal_uInt32
InsertWithFont(
603 const ScPatternAttr
* pPattern
, sal_Int16 nScript
,
604 sal_uInt16 nForceXclFont
,
605 bool bForceLineBreak
);
606 /** Finds or creates a cell XF record for the passed item set, with custom number format.
607 @param nXFFlags Additional flags allowing to control the creation of an XF.
608 @param nForceScNumFmt The number format to be exported, e.g. formula
609 result type. This format will always overwrite the cell's number format.
610 @param bForceLineBreak true = Set line break flag unconditionally.
611 This is required for cells that contain multi-line text.
612 @return A unique XF record ID. */
613 sal_uInt32
InsertWithNumFmt(
614 const ScPatternAttr
* pPattern
, sal_Int16 nScript
,
615 sal_uInt32 nForceScNumFmt
,
616 bool bForceLineBreak
);
617 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
618 @return A unique XF record ID. */
619 sal_uInt32
InsertStyle( const SfxStyleSheetBase
* pStyleSheet
);
620 /** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
621 static sal_uInt32
GetXFIdFromIndex( sal_uInt16 nXFIndex
);
622 /** Returns the XF identifier representing the default cell XF. */
623 static sal_uInt32
GetDefCellXFId();
625 /** Returns an XF record by its unique identifier. */
626 const XclExpXF
* GetXFById( sal_uInt32 nXFId
) const;
628 /** Reduces the XF record list to the maximum allowed number of records. */
631 /** Returns the Excel XF index of the XF record with passed XF ID. */
632 sal_uInt16
GetXFIndex( sal_uInt32 nXFId
) const;
634 sal_Int32
GetXmlStyleIndex( sal_uInt32 nXFId
) const;
635 sal_Int32
GetXmlCellIndex( sal_uInt32 nXFId
) const;
637 /** Writes all XF records contained in this buffer. */
638 virtual void Save( XclExpStream
& rStrm
) override
;
639 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
642 typedef XclExpRecordList
< XclExpXF
> XclExpXFList
;
643 typedef XclExpXFList::RecordRefType XclExpXFRef
;
646 /** Returns the XF ID of the cell XF containing the passed format. */
647 sal_uInt32
FindXF( const ScPatternAttr
& rPattern
, sal_uInt32 nForceScNumFmt
,
648 sal_uInt16 nForceXclFont
, bool bForceLineBreak
) const;
649 /** Returns the XF ID of the style XF containing the passed style. */
650 sal_uInt32
FindXF( const SfxStyleSheetBase
& rStyleSheet
) const;
652 /** Returns the XF ID of a built-in style XF, searches by style identifier. */
653 sal_uInt32
FindBuiltInXF( sal_uInt8 nStyleId
, sal_uInt8 nLevel
) const;
655 /** Tries to find the XF record containing the passed format or inserts a new record.
656 @return The XF record ID. */
657 sal_uInt32
InsertCellXF( const ScPatternAttr
* pPattern
, sal_Int16 nScript
,
658 sal_uInt32 nForceScNumFmt
,
659 sal_uInt16 nForceXclFont
, bool bForceLineBreak
);
660 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
661 @return The XF record ID. */
662 sal_uInt32
InsertStyleXF( const SfxStyleSheetBase
& rStyleSheet
);
664 /** Inserts an XF and a STYLE record for all user defined style sheets. */
665 void InsertUserStyles();
667 /** Inserts a built-in XF record without a STYLE record and returns the XF ID.
668 @param bCreateStyleRec true = Creates the related STYLE record. */
669 sal_uInt32
AppendBuiltInXF( XclExpXFRef
const & xXF
,
670 sal_uInt8 nStyleId
, sal_uInt8 nLevel
= EXC_STYLE_NOLEVEL
);
671 /** Inserts a built-in XF and STYLE record and returns the XF ID.
672 @param bCreateStyleRec true = Creates the related STYLE record. */
673 sal_uInt32
AppendBuiltInXFWithStyle( XclExpXFRef
const & xXF
,
674 sal_uInt8 nStyleId
, sal_uInt8 nLevel
= EXC_STYLE_NOLEVEL
);
676 /** Inserts all default XF and STYLE records. */
677 void InsertDefaultRecords();
679 /** Appends a XF index to the internal ID<->index maps. */
680 void AppendXFIndex( sal_uInt32 nXFId
);
682 void AddBorderAndFill( const XclExpXF
& rXF
);
683 void SaveXFXml( XclExpXmlStream
& rStrm
, XclExpXF
& rXF
);
686 /** Extended info about a built-in XF. */
687 struct XclExpBuiltInInfo
689 sal_uInt8 mnStyleId
; /// Built-in style identifier.
690 sal_uInt8 mnLevel
; /// Level for RowLevel/ColLevel styles.
691 bool mbPredefined
; /// true = XF still predefined.
692 bool mbHasStyleRec
; /// true = STYLE record created.
693 explicit XclExpBuiltInInfo();
695 typedef ::std::map
< sal_uInt32
, XclExpBuiltInInfo
> XclExpBuiltInMap
;
696 typedef ::std::vector
< XclExpCellBorder
> XclExpBorderList
;
697 typedef ::std::vector
< XclExpCellArea
> XclExpFillList
;
699 /** composite key for the find-map, so we can do partial key searching */
702 bool mbCellXF
; // is this a hard cell format, or a cell style
703 const SfxItemSet
* mpItemSet
;
704 sal_uInt32 mnScNumFmt
;
705 sal_uInt16 mnXclFont
;
707 bool operator<(const FindKey
& other
) const
709 if (mbCellXF
!= other
.mbCellXF
)
710 return mbCellXF
< other
.mbCellXF
;
711 if (mpItemSet
!= other
.mpItemSet
)
712 return mpItemSet
< other
.mpItemSet
;
713 if (mnScNumFmt
!= other
.mnScNumFmt
)
714 return mnScNumFmt
< other
.mnScNumFmt
;
715 return mnXclFont
< other
.mnXclFont
;
718 static FindKey
ToFindKey(XclExpXF
const &);
720 XclExpXFList maXFList
; /// List of all XF records.
721 std::map
<FindKey
, std::vector
<sal_uInt32
>>
722 maXFFindMap
; /// map of itemset to vector of positions, to speed up find
723 XclExpRecordList
< XclExpStyle
>
724 maStyleList
; /// List of all STYLE records.
725 XclExpBuiltInMap maBuiltInMap
; /// Contained elements describe built-in XFs.
726 ScfUInt16Vec maXFIndexVec
; /// Maps XF IDs to XF indexes.
727 ScfUInt16Vec maStyleIndexes
; /// Maps XF IDs to OOXML Style indexes
728 ScfUInt16Vec maCellIndexes
; /// Maps XF IDs to OOXML Cell indexes
729 XclExpXFList maSortedXFList
; /// List of XF records in XF index order.
730 XclExpBorderList maBorders
; /// List of borders used by XF records
731 XclExpFillList maFills
; /// List of fills used by XF records
735 class XclExpDxf
: public XclExpRecordBase
, protected XclExpRoot
738 XclExpDxf( const XclExpRoot
& rRoot
, std::unique_ptr
<XclExpCellAlign
> pAlign
, std::unique_ptr
<XclExpCellBorder
> pBorder
,
739 std::unique_ptr
<XclExpDxfFont
> pFont
, std::unique_ptr
<XclExpNumFmt
> pNumberFmt
,
740 std::unique_ptr
<XclExpCellProt
> pProt
, std::unique_ptr
<XclExpColor
> pColor
);
741 XclExpDxf( const XclExpRoot
& rRoot
, std::unique_ptr
<XclExpCellArea
> pCellArea
);
742 virtual ~XclExpDxf() override
;
744 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
745 void SaveXmlExt( XclExpXmlStream
& rStrm
);
746 void SetFinalColors();
749 std::unique_ptr
<XclExpCellAlign
> mpAlign
;
750 std::unique_ptr
<XclExpCellBorder
> mpBorder
;
751 std::unique_ptr
<XclExpDxfFont
> mpFont
;
752 std::unique_ptr
<XclExpNumFmt
> mpNumberFmt
;
753 std::unique_ptr
<XclExpCellProt
> mpProt
;
754 std::unique_ptr
<XclExpColor
> mpColor
;
755 std::unique_ptr
<XclExpCellArea
> mpCellArea
;
758 class XclExpDxfs
: public XclExpRecordBase
, protected XclExpRoot
761 XclExpDxfs(const XclExpRoot
& rRoot
);
763 sal_Int32
GetDxfId(const OUString
& rName
) const;
764 sal_Int32
GetDxfIdForPattern(ScPatternAttr
* pPattern
) const;
765 sal_Int32
GetDxfByColor(Color aColor
) const;
766 void addColor(Color aColor
);
768 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
772 typedef std::vector
< std::unique_ptr
<XclExpDxf
> > DxfContainer
;
773 std::map
<OUString
, sal_Int32
> maStyleNameToDxfId
;
774 std::map
<Color
, sal_Int32
> maColorToDxfId
;
775 std::map
<ScPatternAttr
*, sal_Int32
> maPatternToDxfId
;
777 std::unique_ptr
<NfKeywordTable
> mpKeywordTable
; /// Replacement table.
779 void fillDxfFrom(SfxItemSet
& rItemSet
, SvNumberFormatterPtr
& xFormatter
);
783 class XclExpXmlStyleSheet
: public XclExpRecordBase
, protected XclExpRoot
786 explicit XclExpXmlStyleSheet( const XclExpRoot
& rRoot
);
788 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
791 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */