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 /* ============================================================================
34 - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
35 ============================================================================ */
37 const sal_uInt16 EXC_ID_FONTLIST
= 0x8031; /// For internal use only.
38 const sal_uInt16 EXC_ID_FORMATLIST
= 0x801E; /// For internal use only.
39 const sal_uInt16 EXC_ID_XFLIST
= 0x8043; /// For internal use only.
40 const sal_uInt16 EXC_ID_DXFS
= 0x9999; /// For internal use only. TODO:moggi: find a better/correct value
42 // PALETTE record - color information =========================================
44 /** Different types of colors in a document. */
47 EXC_COLOR_CELLTEXT
, /// Text in a cell.
48 EXC_COLOR_CELLBORDER
, /// Border of a cell.
49 EXC_COLOR_CELLAREA
, /// Background area of a cell.
50 EXC_COLOR_CHARTTEXT
, /// Text color in a chart.
51 EXC_COLOR_CHARTLINE
, /// Line in a chart.
52 EXC_COLOR_CHARTAREA
, /// Area in a chart.
53 EXC_COLOR_CTRLTEXT
, /// Text color in a form control.
54 EXC_COLOR_GRID
, /// Spreadsheet grid color.
55 EXC_COLOR_TABBG
/// Spreadsheet tab bg color.
58 class XclExpPaletteImpl
;
60 /** Stores all used colors in the document.
62 Supports color reduction to the maximum count of the current BIFF version.
63 An instance of this class collects all colors in the conversion phase of
64 the export, using the InsertColor() function. It returns a unique
65 identifier for each passed color.
67 After the entire document is converted, the Finalize() function will reduce
68 the palette to the number of colors supported by the current BIFF version.
70 Then, in the streaming phase, the functions GetColorIndex() and
71 GetMixedColors() return the real Excel palette index for all color
74 class XclExpPalette
: public XclDefaultPalette
, public XclExpRecord
77 explicit XclExpPalette( const XclExpRoot
& rRoot
);
78 virtual ~XclExpPalette() override
;
80 /** Inserts the color into the list and updates weighting.
81 @param nAutoDefault The Excel palette index for automatic color.
82 @return A unique ID for this color. */
83 sal_uInt32
InsertColor( const Color
& rColor
, XclExpColorType eType
, sal_uInt16 nAutoDefault
= 0 );
84 /** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
85 static sal_uInt32
GetColorIdFromIndex( sal_uInt16 nIndex
);
87 /** Reduces the color list to the maximum count of the current BIFF version. */
90 /** Returns the Excel palette index of the color with passed color ID. */
91 sal_uInt16
GetColorIndex( sal_uInt32 nColorId
) const;
93 /** Returns a foreground and background color for the two passed color IDs.
94 @descr If rnXclPattern contains a solid pattern, this function tries to find
95 the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
96 This will result in a better approximation to the passed foreground color. */
98 sal_uInt16
& rnXclForeIx
, sal_uInt16
& rnXclBackIx
, sal_uInt8
& rnXclPattern
,
99 sal_uInt32 nForeColorId
, sal_uInt32 nBackColorId
) const;
101 /** Returns the color for a (non-zero-based) Excel palette entry.
102 @return The color from current or default palette or COL_AUTO, if nothing else found. */
103 Color
GetColor( sal_uInt16 nXclIndex
) const;
105 /** Saves the PALETTE record, if it differs from the default palette. */
106 virtual void Save( XclExpStream
& rStrm
) override
;
107 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
110 /** Writes the contents of the PALETTE record. */
111 virtual void WriteBody( XclExpStream
& rStrm
) override
;
114 typedef std::shared_ptr
< XclExpPaletteImpl
> XclExpPaletteImplRef
;
115 XclExpPaletteImplRef mxImpl
;
118 // FONT record - font information =============================================
120 const size_t EXC_FONTLIST_NOTFOUND
= static_cast< size_t >( -1 );
122 /** Helper functions for font export. */
123 namespace XclExpFontHelper
125 /** Returns the script type of the first font item found in the item set and its parents. */
126 sal_Int16
GetFirstUsedScript(
127 const XclExpRoot
& rRoot
,
128 const SfxItemSet
& rItemSet
);
130 /** Returns a VCL font object filled from the passed item set. */
131 vcl::Font
GetFontFromItemSet(
132 const XclExpRoot
& rRoot
,
133 const SfxItemSet
& rItemSet
,
137 * Get a dxf related font object from the item set.
138 * Only items that are explicitly set in the item set
139 * are also set in the returned object.
141 ScDxfFont
GetDxfFontFromItemSet(const XclExpRoot
& rRoot
, const SfxItemSet
& rSet
);
143 /** Returns true, if at least one font related item is set in the passed item set.
144 @param bDeep true = Searches in parent item sets too. */
146 const XclExpRoot
& rRoot
,
147 const SfxItemSet
& rItemSet
,
152 /** Stores all data of an Excel font and provides export of FONT records. */
153 class XclExpFont
: public XclExpRecord
, protected XclExpRoot
156 explicit XclExpFont( const XclExpRoot
& rRoot
,
157 const XclFontData
& rFontData
, XclExpColorType eColorType
);
159 /** Returns read-only access to font data. */
160 const XclFontData
& GetFontData() const { return maData
; }
161 /** Returns the font color identifier. */
162 sal_uInt32
GetFontColorId() const { return mnColorId
; }
163 /** Compares this font with the passed font data.
164 @param nHash The hash value calculated from the font data. */
165 virtual bool Equals( const XclFontData
& rFontData
, sal_uInt32 nHash
) const;
167 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
170 /** Writes the contents of the FONT record. */
171 virtual void WriteBody( XclExpStream
& rStrm
) override
;
174 XclFontData maData
; /// All font attributes.
175 sal_uInt32 mnColorId
; /// Unique color ID for text color.
176 sal_uInt32 mnHash
; /// Hash value for fast comparison.
179 class XclExpDxfFont
: public XclExpRecordBase
, protected XclExpRoot
182 XclExpDxfFont(const XclExpRoot
& rRoot
, const SfxItemSet
& rItemSet
);
184 virtual void SaveXml(XclExpXmlStream
& rStrm
) override
;
190 /** Used as placeholder for font index 4, which is not used in Excel. */
191 class XclExpBlindFont
: public XclExpFont
194 explicit XclExpBlindFont( const XclExpRoot
& rRoot
);
196 /** Returns always false to never find this font while searching the font list. */
197 virtual bool Equals( const XclFontData
& rFontData
, sal_uInt32 nHash
) const override
;
199 /** Skips writing this record. */
200 virtual void Save( XclExpStream
& rStrm
) override
;
205 /** Stores the data of all fonts used in the document. */
206 class XclExpFontBuffer
: public XclExpRecordBase
, protected XclExpRoot
209 explicit XclExpFontBuffer( const XclExpRoot
& rRoot
);
211 /** Returns the specified font from font list. */
212 const XclExpFont
* GetFont( sal_uInt16 nXclFont
) const;
213 /** Returns the application font data of this file, needed e.g. for column width. */
214 const XclFontData
& GetAppFontData() const;
216 /** Inserts a new font with the passed font data into the buffer if not present.
217 @param bAppFont true = Sets the application font; false = Inserts a new font.
218 @return The resulting Excel font index. */
219 sal_uInt16
Insert( const XclFontData
& rFontData
,
220 XclExpColorType eColorType
, bool bAppFont
= false );
221 /** Inserts the SvxFont into the buffer if not present, e.g. where escapements are used.
222 @return The resulting Excel font index. */
223 sal_uInt16
Insert( const SvxFont
& rFont
,
224 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
,
230 XclExpColorType eColorType
, bool bAppFont
);
232 /** Writes all FONT records contained in this buffer. */
233 virtual void Save( XclExpStream
& rStrm
) override
;
234 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
237 /** Initializes the default fonts for the current BIFF version. */
238 void InitDefaultFonts();
239 /** Tries to find the passed font and returns the current list index. */
240 size_t Find( const XclFontData
& rFontData
);
243 typedef XclExpRecordList
< XclExpFont
> XclExpFontList
;
244 typedef XclExpFontList::RecordRefType XclExpFontRef
;
246 XclExpFontList maFontList
; /// List of all FONT records.
247 size_t mnXclMaxSize
; /// Maximum number of fonts.
250 // FORMAT record - number formats =============================================
252 /** Stores a core number format index with corresponding Excel format index. */
255 sal_uInt32 mnScNumFmt
; /// Core index of the number format.
256 sal_uInt16 mnXclNumFmt
; /// Resulting Excel format index.
257 OUString maNumFmtString
; /// format string
259 explicit XclExpNumFmt( sal_uInt32 nScNumFmt
, sal_uInt16 nXclNumFmt
, const OUString
& rFrmt
) :
260 mnScNumFmt( nScNumFmt
), mnXclNumFmt( nXclNumFmt
), maNumFmtString( rFrmt
) {}
262 void SaveXml( XclExpXmlStream
& rStrm
);
265 typedef ::std::unique_ptr
< SvNumberFormatter
> SvNumberFormatterPtr
;
267 /** Stores all number formats used in the document. */
268 class XclExpNumFmtBuffer
: public XclExpRecordBase
, protected XclExpRoot
271 explicit XclExpNumFmtBuffer( const XclExpRoot
& rRoot
);
272 virtual ~XclExpNumFmtBuffer() override
;
274 /** Returns the core index of the current standard number format. */
275 sal_uInt32
GetStandardFormat() const { return mnStdFmt
; }
277 /** Inserts a number format into the format buffer.
278 @param nScNumFmt The core index of the number format.
279 @return The resulting Excel format index. */
280 sal_uInt16
Insert( sal_uInt32 nScNumFmt
);
282 /** Writes all FORMAT records contained in this buffer. */
283 virtual void Save( XclExpStream
& rStrm
) override
;
284 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
286 OUString
GetFormatCode ( sal_uInt32 nScNumFmt
);
289 /** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
290 void WriteFormatRecord( XclExpStream
& rStrm
, sal_uInt16 nXclNumFmt
, const OUString
& rFormatStr
);
291 /** Writes the FORMAT record represented by rFormat. */
292 void WriteFormatRecord( XclExpStream
& rStrm
, const XclExpNumFmt
& rFormat
);
295 typedef ::std::vector
< XclExpNumFmt
> XclExpNumFmtVec
;
297 SvNumberFormatterPtr mxFormatter
; /// Special number formatter for conversion.
298 XclExpNumFmtVec maFormatMap
; /// Maps core formats to Excel indexes.
299 std::unique_ptr
<NfKeywordTable
> mpKeywordTable
; /// Replacement table.
300 sal_uInt32 mnStdFmt
; /// Key for standard number format.
301 sal_uInt16 mnXclOffset
; /// Offset to first user defined format.
304 // XF, STYLE record - Cell formatting =========================================
306 /** Extends the XclCellProt struct for export.
307 @descr Provides functions to fill from item sets and to fill to Excel record data. */
308 struct XclExpCellProt
: public XclCellProt
310 /** Fills the protection attributes from the passed item set.
311 @return true = At least one protection item is set. */
312 bool FillFromItemSet( const SfxItemSet
& rItemSet
, bool bStyle
= false );
314 /** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
315 void FillToXF3( sal_uInt16
& rnProt
) const;
317 void SaveXml( XclExpXmlStream
& rStrm
) const;
320 /** Extends the XclCellAlign struct for export.
321 @descr Provides functions to fill from item sets and to fill to Excel record data. */
322 struct XclExpCellAlign
: public XclCellAlign
324 /** Fills the alignment attributes from the passed item set.
325 @descr Fills only the attributes exported in the passed BIFF version.
326 @param bForceLineBreak true = Set line break flag unconditionally.
327 @return true = At least one alignment item is set. */
328 bool FillFromItemSet(const XclRoot
& rRoot
, const SfxItemSet
& rItemSet
,
329 bool bForceLineBreak
, XclBiff eBiff
, bool bStyle
= false );
331 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
332 void FillToXF5( sal_uInt16
& rnAlign
) const;
333 /** Fills the data to the passed fields of a BIFF8 XF record. */
334 void FillToXF8( sal_uInt16
& rnAlign
, sal_uInt16
& rnMiscAttrib
) const;
336 void SaveXml( XclExpXmlStream
& rStrm
) const;
339 /** Extends the XclCellBorder struct for export.
340 @descr Provides functions to fill from item sets and to fill to Excel record data. */
341 struct XclExpCellBorder
: public XclCellBorder
343 sal_uInt32 mnLeftColorId
; /// Color ID for left line.
344 sal_uInt32 mnRightColorId
; /// Color ID for right line.
345 sal_uInt32 mnTopColorId
; /// Color ID for top line.
346 sal_uInt32 mnBottomColorId
; /// Color ID for bottom line.
347 sal_uInt32 mnDiagColorId
; /// Color ID for diagonal line(s).
349 explicit XclExpCellBorder();
351 /** Fills the border attributes from the passed item set.
352 @descr Fills only the attributes exported in the passed BIFF version.
353 @return true = At least one border item is set. */
354 bool FillFromItemSet( const SfxItemSet
& rItemSet
,
355 XclExpPalette
& rPalette
, XclBiff eBiff
, bool bStyle
= false );
356 /** Fills the mn***Color base members from the mn***ColorId members. */
357 void SetFinalColors( const XclExpPalette
& rPalette
);
359 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
360 void FillToXF5( sal_uInt32
& rnBorder
, sal_uInt32
& rnArea
) const;
361 /** Fills the data to the passed fields of a BIFF8 XF record. */
362 void FillToXF8( sal_uInt32
& rnBorder1
, sal_uInt32
& rnBorder2
) const;
364 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
365 void FillToCF8( sal_uInt16
& rnLine
, sal_uInt32
& rnColor
) const;
367 void SaveXml( XclExpXmlStream
& rStrm
) const;
370 /** Extends the XclCellArea struct for export.
371 @descr Provides functions to fill from item sets and to fill to Excel record data. */
372 struct XclExpCellArea
: public XclCellArea
374 sal_uInt32 mnForeColorId
; /// Foreground color ID.
375 sal_uInt32 mnBackColorId
; /// Background color ID.
376 Color maForeColor
; // Actual foreground color
377 Color maBackColor
; // Actual background color
379 explicit XclExpCellArea();
380 explicit XclExpCellArea(Color aForeColor
, Color aBackColor
);
382 /** Fills the area attributes from the passed item set.
383 @return true = At least one area item is set. */
384 bool FillFromItemSet(
385 const SfxItemSet
& rItemSet
, XclExpPalette
& rPalette
,
387 /** Fills the mn***Color base members from the mn***ColorId members. */
388 void SetFinalColors( const XclExpPalette
& rPalette
);
390 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
391 void FillToXF5( sal_uInt32
& rnArea
) const;
392 /** Fills the data to the passed fields of a BIFF8 XF record. */
393 void FillToXF8( sal_uInt32
& rnBorder2
, sal_uInt16
& rnArea
) const;
395 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
396 void FillToCF8( sal_uInt16
& rnPattern
, sal_uInt16
& rnColor
) const;
398 void SaveXml( XclExpXmlStream
& rStrm
) const;
405 bool FillFromItemSet( const SfxItemSet
& rItemSet
);
407 void SaveXml( XclExpXmlStream
& rStrm
) const;
410 /** A combination of unique XF identifier with real Excel XF index. */
413 sal_uInt32 mnXFId
; /// Temporary XF identifier.
414 sal_uInt16 mnXFIndex
; /// Real Excel XF index.
416 explicit XclExpXFId();
417 explicit XclExpXFId( sal_uInt32 nXFId
)
418 : mnXFId( nXFId
), mnXFIndex( EXC_XF_DEFAULTCELL
) {}
420 /** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
421 void ConvertXFIndex( const XclExpRoot
& rRoot
);
424 class SfxStyleSheetBase
;
426 /** Represents an XF record which contains all formatting data of a cell or cell style. */
427 class XclExpXF
: public XclXFBase
, public XclExpRecord
, protected XclExpRoot
430 /** Constructs a cell XF record from the passed Calc cell formatting. */
432 const XclExpRoot
& rRoot
,
433 const ScPatternAttr
& rPattern
,
435 sal_uInt32 nScForceNumFmt
= NUMBERFORMAT_ENTRY_NOT_FOUND
,
436 sal_uInt16 nForceXclFont
= EXC_FONT_NOTFOUND
,
437 bool bForceLineBreak
= false );
438 /** Constructs a style XF record from the passed cell style sheet. */
440 const XclExpRoot
& rRoot
,
441 const SfxStyleSheetBase
& rStyleSheet
);
443 /** Returns the cell protection settings of this XF. */
444 const XclExpCellProt
& GetProtectionData() const { return maProtection
; }
445 /** Returns the alignment settings of this XF. */
446 const XclExpCellAlign
& GetAlignmentData() const { return maAlignment
; }
447 /** Returns the cell border settings of this XF. */
448 const XclExpCellBorder
& GetBorderData() const { return maBorder
; }
449 /** Returns the cell fill settings of this XF. */
450 const XclExpCellArea
& GetAreaData() const { return maArea
; }
452 /** Returns true, if this XF record represents the passed cell formatting.
453 @descr Searches for cell XFs only. */
455 const ScPatternAttr
& rPattern
,
456 sal_uInt32 nScForceNumFmt
,
457 sal_uInt16 nForceXclFont
,
458 bool bForceLineBreak
) const;
460 /** Returns true, if this XF record represents the passed style.
461 @descr Searches for style XFs only. */
462 bool Equals( const SfxStyleSheetBase
& rStyleSheet
) const;
464 /** Sets the resulting Excel palette index from all used color IDs (border and area). */
465 void SetFinalColors();
467 /** Returns true, if this XF record is completely equal to the passed. */
468 bool Equals( const XclExpXF
& rCmpXF
) const;
470 void SetXmlIds( sal_uInt32 nBorderId
, sal_uInt32 nFillId
);
472 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
474 const SfxItemSet
* GetItemSet() const { return mpItemSet
; }
476 sal_uInt32
GetScNumFmt() const { return mnScNumFmt
; }
477 sal_uInt16
GetXclFont() const { return mnXclFont
; }
480 explicit XclExpXF( const XclExpRoot
& rRoot
, bool bCellXF
);
482 protected: // access for XclExpDefaultXF
483 const SfxItemSet
* mpItemSet
; /// Pointer to the item set (we do not own it).
485 XclExpCellProt maProtection
; /// Cell protection flags.
486 XclExpCellAlign maAlignment
; /// All alignment attributes.
487 XclExpCellBorder maBorder
; /// Border line style.
488 XclExpCellArea maArea
; /// Background area style.
489 sal_uInt32 mnParentXFId
; /// XF ID of parent XF record.
490 sal_uInt32 mnScNumFmt
; /// Calc number format index.
491 sal_uInt16 mnXclFont
; /// Excel font index.
492 sal_uInt16 mnXclNumFmt
; /// Excel number format index.
493 sal_Int32 mnBorderId
; /// OOXML Border Index
494 sal_Int32 mnFillId
; /// OOXML Fill Index
497 using XclXFBase::Equals
;
499 /** Initializes with default values. */
501 /** Fills all members from the passed item set.
502 @param bDefStyle true = This is the "Default"/"Normal" style - needs special handling. */
504 const SfxItemSet
& rItemSet
,
506 sal_uInt32 nForceScNumFmt
,
507 sal_uInt16 nForceXclFont
,
508 bool bForceLineBreak
,
511 /** Returns the bits specifying the used attributes.
512 @descr In cell XFs a set bit means a used attribute, in style XF a cleared
513 bit means a used attribute. This method regards the cell/style state.
514 @return The mask based on bit 0 (not yet bit-shifted as needed for export). */
515 sal_uInt8
GetUsedFlags() const;
517 void WriteBody5( XclExpStream
& rStrm
);
518 void WriteBody8( XclExpStream
& rStrm
);
520 /** Writes the contents of the XF record. */
521 virtual void WriteBody( XclExpStream
& rStrm
) override
;
524 /** Represents a default XF record. Supports methods to set attributes directly. */
525 class XclExpDefaultXF
: public XclExpXF
528 explicit XclExpDefaultXF( const XclExpRoot
& rRoot
, bool bCellXF
);
530 /** Sets the Excel font index. */
531 void SetFont( sal_uInt16 nXclFont
);
532 /** Sets the Excel number format index. */
533 void SetNumFmt( sal_uInt16 nXclNumFmt
);
536 /** Represents a STYLE record containing the data of a cell style.
537 @descr The class is able to store built-in and user-defined styles. */
538 class XclExpStyle
: public XclExpRecord
541 explicit XclExpStyle( sal_uInt32 nXFId
, const OUString
& rStyleName
);
542 explicit XclExpStyle( sal_uInt32 nXFId
, sal_uInt8 nStyleId
, sal_uInt8 nLevel
);
544 /** Returns true, if this record represents an Excel built-in style. */
545 bool IsBuiltIn() const { return mnStyleId
!= EXC_STYLE_USERDEF
; }
547 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
550 /** Writes the contents of the STYLE record. */
551 virtual void WriteBody( XclExpStream
& rStrm
) override
;
554 OUString maName
; /// Name of the cell style.
555 XclExpXFId maXFId
; /// XF identifier for style formatting.
556 sal_uInt8 mnStyleId
; /// Built-in style identifier.
557 sal_uInt8 mnLevel
; /// Outline level for RowLevel and ColLevel styles.
560 /** Stores all XF records (cell formats and cell styles) in the document.
562 Stores also the names of user defined cell styles (STYLE records). Supports
563 reduction to the maximum count of XF records of the current BIFF version.
565 An instance of this class collects all XF records in the conversion phase
566 of the export, using the Insert() and InsertStyle() functions. It returns a
567 unique identifier for each XF record.
569 After the entire document is converted, the Finalize() function will reduce
570 the list to the number of XF records supported by the current BIFF version.
572 Then, in the streaming phase, the function GetXFIndex() returns the real
573 Excel XF index for all XF identifiers.
575 class XclExpXFBuffer
: public XclExpRecordBase
, protected XclExpRoot
578 explicit XclExpXFBuffer( const XclExpRoot
& rRoot
);
580 /** Inserts predefined built-in styles and user-defined styles. */
583 /** Finds or creates a cell XF record for the passed item set.
584 @return A unique XF record ID. */
585 sal_uInt32
Insert( const ScPatternAttr
* pPattern
, sal_Int16 nScript
);
586 /** Finds or creates a cell XF record for the passed item set.
587 @param nForceXclFont The font to be exported. If not equal to EXC_FONT_NOTFOUND,
588 this font index will be used unconditionally and the cell font will be ignored.
589 @param bForceLineBreak true = Set line break flag unconditionally.
590 This is required for cells that contain multi-line text.
591 @return A unique XF record ID. */
592 sal_uInt32
InsertWithFont(
593 const ScPatternAttr
* pPattern
, sal_Int16 nScript
,
594 sal_uInt16 nForceXclFont
,
595 bool bForceLineBreak
);
596 /** Finds or creates a cell XF record for the passed item set, with custom number format.
597 @param nXFFlags Additional flags allowing to control the creation of an XF.
598 @param nForceScNumFmt The number format to be exported, e.g. formula
599 result type. This format will always overwrite the cell's number format.
600 @param bForceLineBreak true = Set line break flag unconditionally.
601 This is required for cells that contain multi-line text.
602 @return A unique XF record ID. */
603 sal_uInt32
InsertWithNumFmt(
604 const ScPatternAttr
* pPattern
, sal_Int16 nScript
,
605 sal_uInt32 nForceScNumFmt
,
606 bool bForceLineBreak
);
607 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
608 @return A unique XF record ID. */
609 sal_uInt32
InsertStyle( const SfxStyleSheetBase
* pStyleSheet
);
610 /** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
611 static sal_uInt32
GetXFIdFromIndex( sal_uInt16 nXFIndex
);
612 /** Returns the XF identifier representing the default cell XF. */
613 static sal_uInt32
GetDefCellXFId();
615 /** Returns an XF record by its unique identifier. */
616 const XclExpXF
* GetXFById( sal_uInt32 nXFId
) const;
618 /** Reduces the XF record list to the maximum allowed number of records. */
621 /** Returns the Excel XF index of the XF record with passed XF ID. */
622 sal_uInt16
GetXFIndex( sal_uInt32 nXFId
) const;
624 sal_Int32
GetXmlStyleIndex( sal_uInt32 nXFId
) const;
625 sal_Int32
GetXmlCellIndex( sal_uInt32 nXFId
) const;
627 /** Writes all XF records contained in this buffer. */
628 virtual void Save( XclExpStream
& rStrm
) override
;
629 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
632 typedef XclExpRecordList
< XclExpXF
> XclExpXFList
;
633 typedef XclExpXFList::RecordRefType XclExpXFRef
;
636 /** Returns the XF ID of the cell XF containing the passed format. */
637 sal_uInt32
FindXF( const ScPatternAttr
& rPattern
, sal_uInt32 nForceScNumFmt
,
638 sal_uInt16 nForceXclFont
, bool bForceLineBreak
) const;
639 /** Returns the XF ID of the style XF containing the passed style. */
640 sal_uInt32
FindXF( const SfxStyleSheetBase
& rStyleSheet
) const;
642 /** Returns the XF ID of a built-in style XF, searches by style identifier. */
643 sal_uInt32
FindBuiltInXF( sal_uInt8 nStyleId
, sal_uInt8 nLevel
) const;
645 /** Tries to find the XF record containing the passed format or inserts a new record.
646 @return The XF record ID. */
647 sal_uInt32
InsertCellXF( const ScPatternAttr
* pPattern
, sal_Int16 nScript
,
648 sal_uInt32 nForceScNumFmt
,
649 sal_uInt16 nForceXclFont
, bool bForceLineBreak
);
650 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
651 @return The XF record ID. */
652 sal_uInt32
InsertStyleXF( const SfxStyleSheetBase
& rStyleSheet
);
654 /** Inserts an XF and a STYLE record for all user defined style sheets. */
655 void InsertUserStyles();
657 /** Inserts a built-in XF record without a STYLE record and returns the XF ID.
658 @param bCreateStyleRec true = Creates the related STYLE record. */
659 sal_uInt32
AppendBuiltInXF( XclExpXFRef
const & xXF
,
660 sal_uInt8 nStyleId
, sal_uInt8 nLevel
= EXC_STYLE_NOLEVEL
);
661 /** Inserts a built-in XF and STYLE record and returns the XF ID.
662 @param bCreateStyleRec true = Creates the related STYLE record. */
663 sal_uInt32
AppendBuiltInXFWithStyle( XclExpXFRef
const & xXF
,
664 sal_uInt8 nStyleId
, sal_uInt8 nLevel
= EXC_STYLE_NOLEVEL
);
666 /** Inserts all default XF and STYLE records. */
667 void InsertDefaultRecords();
669 /** Appends a XF index to the internal ID<->index maps. */
670 void AppendXFIndex( sal_uInt32 nXFId
);
672 void AddBorderAndFill( const XclExpXF
& rXF
);
673 void SaveXFXml( XclExpXmlStream
& rStrm
, XclExpXF
& rXF
);
676 /** Extended info about a built-in XF. */
677 struct XclExpBuiltInInfo
679 sal_uInt8 mnStyleId
; /// Built-in style identifier.
680 sal_uInt8 mnLevel
; /// Level for RowLevel/ColLevel styles.
681 bool mbPredefined
; /// true = XF still predefined.
682 bool mbHasStyleRec
; /// true = STYLE record created.
683 explicit XclExpBuiltInInfo();
685 typedef ::std::map
< sal_uInt32
, XclExpBuiltInInfo
> XclExpBuiltInMap
;
686 typedef ::std::vector
< XclExpCellBorder
> XclExpBorderList
;
687 typedef ::std::vector
< XclExpCellArea
> XclExpFillList
;
689 /** composite key for the find-map, so we can do partial key searching */
692 bool mbCellXF
; // is this a hard cell format, or a cell style
693 const SfxItemSet
* mpItemSet
;
694 sal_uInt32 mnScNumFmt
;
695 sal_uInt16 mnXclFont
;
697 bool operator<(const FindKey
& other
) const
699 if (mbCellXF
!= other
.mbCellXF
)
700 return mbCellXF
< other
.mbCellXF
;
701 if (mpItemSet
!= other
.mpItemSet
)
702 return mpItemSet
< other
.mpItemSet
;
703 if (mnScNumFmt
!= other
.mnScNumFmt
)
704 return mnScNumFmt
< other
.mnScNumFmt
;
705 return mnXclFont
< other
.mnXclFont
;
708 static FindKey
ToFindKey(XclExpXF
const &);
710 XclExpXFList maXFList
; /// List of all XF records.
711 std::map
<FindKey
, std::vector
<sal_uInt32
>>
712 maXFFindMap
; /// map of itemset to vector of positions, to speed up find
713 XclExpRecordList
< XclExpStyle
>
714 maStyleList
; /// List of all STYLE records.
715 XclExpBuiltInMap maBuiltInMap
; /// Contained elements describe built-in XFs.
716 ScfUInt16Vec maXFIndexVec
; /// Maps XF IDs to XF indexes.
717 ScfUInt16Vec maStyleIndexes
; /// Maps XF IDs to OOXML Style indexes
718 ScfUInt16Vec maCellIndexes
; /// Maps XF IDs to OOXML Cell indexes
719 XclExpXFList maSortedXFList
; /// List of XF records in XF index order.
720 XclExpBorderList maBorders
; /// List of borders used by XF records
721 XclExpFillList maFills
; /// List of fills used by XF records
725 class XclExpDxf
: public XclExpRecordBase
, protected XclExpRoot
728 XclExpDxf( const XclExpRoot
& rRoot
, std::unique_ptr
<XclExpCellAlign
> pAlign
, std::unique_ptr
<XclExpCellBorder
> pBorder
,
729 std::unique_ptr
<XclExpDxfFont
> pFont
, std::unique_ptr
<XclExpNumFmt
> pNumberFmt
,
730 std::unique_ptr
<XclExpCellProt
> pProt
, std::unique_ptr
<XclExpColor
> pColor
);
731 XclExpDxf( const XclExpRoot
& rRoot
, std::unique_ptr
<XclExpCellArea
> pCellArea
);
732 virtual ~XclExpDxf() override
;
734 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
735 void SaveXmlExt( XclExpXmlStream
& rStrm
);
738 std::unique_ptr
<XclExpCellAlign
> mpAlign
;
739 std::unique_ptr
<XclExpCellBorder
> mpBorder
;
740 std::unique_ptr
<XclExpDxfFont
> mpFont
;
741 std::unique_ptr
<XclExpNumFmt
> mpNumberFmt
;
742 std::unique_ptr
<XclExpCellProt
> mpProt
;
743 std::unique_ptr
<XclExpColor
> mpColor
;
744 std::unique_ptr
<XclExpCellArea
> mpCellArea
;
747 class XclExpDxfs
: public XclExpRecordBase
, protected XclExpRoot
750 XclExpDxfs( const XclExpRoot
& rRoot
);
752 sal_Int32
GetDxfId(const OUString
& rName
) const;
753 sal_Int32
GetDxfByColor(Color aColor
) const;
754 void AddColor(Color aColor
);
756 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
758 typedef std::vector
< std::unique_ptr
<XclExpDxf
> > DxfContainer
;
759 std::map
<OUString
, sal_Int32
> maStyleNameToDxfId
;
760 std::map
<Color
, sal_Int32
> maColorToDxfId
;
762 std::unique_ptr
<NfKeywordTable
> mpKeywordTable
; /// Replacement table.
765 class XclExpXmlStyleSheet
: public XclExpRecordBase
, protected XclExpRoot
768 explicit XclExpXmlStyleSheet( const XclExpRoot
& rRoot
);
770 virtual void SaveXml( XclExpXmlStream
& rStrm
) override
;
773 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */