Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / xestyle.hxx
blob8c3493d352f38bc3aed94014eddbae869b397371
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <map>
23 #include <svl/zforlist.hxx>
24 #include <svl/nfkeytab.hxx>
25 #include <editeng/svxfont.hxx>
26 #include "xerecord.hxx"
27 #include "xlstyle.hxx"
28 #include "xeroot.hxx"
29 #include <fonthelper.hxx>
30 #include <memory>
31 #include <utility>
32 #include <vector>
34 /* ============================================================================
35 - Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
36 ============================================================================ */
38 const sal_uInt16 EXC_ID_FONTLIST = 0x8031; /// For internal use only.
39 const sal_uInt16 EXC_ID_FORMATLIST = 0x801E; /// For internal use only.
40 const sal_uInt16 EXC_ID_XFLIST = 0x8043; /// For internal use only.
41 const sal_uInt16 EXC_ID_DXFS = 0x9999; /// For internal use only. TODO:moggi: find a better/correct value
43 // PALETTE record - color information =========================================
45 /** Different types of colors in a document. */
46 enum XclExpColorType
48 EXC_COLOR_CELLTEXT, /// Text in a cell.
49 EXC_COLOR_CELLBORDER, /// Border of a cell.
50 EXC_COLOR_CELLAREA, /// Background area of a cell.
51 EXC_COLOR_CHARTTEXT, /// Text color in a chart.
52 EXC_COLOR_CHARTLINE, /// Line in a chart.
53 EXC_COLOR_CHARTAREA, /// Area in a chart.
54 EXC_COLOR_CTRLTEXT, /// Text color in a form control.
55 EXC_COLOR_GRID, /// Spreadsheet grid color.
56 EXC_COLOR_TABBG /// Spreadsheet tab bg color.
59 class XclExpPaletteImpl;
61 /** Stores all used colors in the document.
63 Supports color reduction to the maximum count of the current BIFF version.
64 An instance of this class collects all colors in the conversion phase of
65 the export, using the InsertColor() function. It returns a unique
66 identifier for each passed color.
68 After the entire document is converted, the Finalize() function will reduce
69 the palette to the number of colors supported by the current BIFF version.
71 Then, in the streaming phase, the functions GetColorIndex() and
72 GetMixedColors() return the real Excel palette index for all color
73 identifiers.
75 class XclExpPalette : public XclDefaultPalette, public XclExpRecord
77 public:
78 explicit XclExpPalette( const XclExpRoot& rRoot );
79 virtual ~XclExpPalette() override;
81 /** Inserts the color into the list and updates weighting.
82 @param nAutoDefault The Excel palette index for automatic color.
83 @return A unique ID for this color. */
84 sal_uInt32 InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault = 0 );
85 /** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
86 static sal_uInt32 GetColorIdFromIndex( sal_uInt16 nIndex );
88 /** Reduces the color list to the maximum count of the current BIFF version. */
89 void Finalize();
91 /** Returns the Excel palette index of the color with passed color ID. */
92 sal_uInt16 GetColorIndex( sal_uInt32 nColorId ) const;
94 /** Returns a foreground and background color for the two passed color IDs.
95 @descr If rnXclPattern contains a solid pattern, this function tries to find
96 the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
97 This will result in a better approximation to the passed foreground color. */
98 void GetMixedColors(
99 sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
100 sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const;
102 /** Returns the color for a (non-zero-based) Excel palette entry.
103 @return The color from current or default palette or COL_AUTO, if nothing else found. */
104 Color GetColor( sal_uInt16 nXclIndex ) const;
106 /** Saves the PALETTE record, if it differs from the default palette. */
107 virtual void Save( XclExpStream& rStrm ) override;
108 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
110 private:
111 /** Writes the contents of the PALETTE record. */
112 virtual void WriteBody( XclExpStream& rStrm ) override;
114 private:
115 typedef std::shared_ptr< XclExpPaletteImpl > XclExpPaletteImplRef;
116 XclExpPaletteImplRef mxImpl;
119 // FONT record - font information =============================================
121 const size_t EXC_FONTLIST_NOTFOUND = static_cast< size_t >( -1 );
123 /** Helper functions for font export. */
124 namespace XclExpFontHelper
126 /** Returns the script type of the first font item found in the item set and its parents. */
127 sal_Int16 GetFirstUsedScript(
128 const XclExpRoot& rRoot,
129 const SfxItemSet& rItemSet );
131 /** Returns a VCL font object filled from the passed item set. */
132 vcl::Font GetFontFromItemSet(
133 const XclExpRoot& rRoot,
134 const SfxItemSet& rItemSet,
135 sal_Int16 nScript );
138 * Get a dxf related font object from the item set.
139 * Only items that are explicitly set in the item set
140 * are also set in the returned object.
142 ScDxfFont GetDxfFontFromItemSet(const XclExpRoot& rRoot, const SfxItemSet& rSet);
144 /** Returns true, if at least one font related item is set in the passed item set.
145 @param bDeep true = Searches in parent item sets too. */
146 bool CheckItems(
147 const XclExpRoot& rRoot,
148 const SfxItemSet& rItemSet,
149 sal_Int16 nScript,
150 bool bDeep );
153 /** Stores all data of an Excel font and provides export of FONT records. */
154 class XclExpFont : public XclExpRecord, protected XclExpRoot
156 public:
157 explicit XclExpFont( const XclExpRoot& rRoot,
158 const XclFontData& rFontData, XclExpColorType eColorType );
160 /** Returns read-only access to font data. */
161 const XclFontData& GetFontData() const { return maData; }
162 /** Returns the font color identifier. */
163 sal_uInt32 GetFontColorId() const { return mnColorId; }
164 /** Compares this font with the passed font data.
165 @param nHash The hash value calculated from the font data. */
166 virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
168 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
170 private:
171 /** Writes the contents of the FONT record. */
172 virtual void WriteBody( XclExpStream& rStrm ) override;
174 private:
175 XclFontData maData; /// All font attributes.
176 sal_uInt32 mnColorId; /// Unique color ID for text color.
177 sal_uInt32 mnHash; /// Hash value for fast comparison.
180 class XclExpDxfFont : public XclExpRecordBase, protected XclExpRoot
182 public:
183 XclExpDxfFont(const XclExpRoot& rRoot, const SfxItemSet& rItemSet);
185 virtual void SaveXml(XclExpXmlStream& rStrm) override;
186 private:
188 ScDxfFont maDxfData;
191 /** Used as placeholder for font index 4, which is not used in Excel. */
192 class XclExpBlindFont : public XclExpFont
194 public:
195 explicit XclExpBlindFont( const XclExpRoot& rRoot );
197 /** Returns always false to never find this font while searching the font list. */
198 virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const override;
200 /** Skips writing this record. */
201 virtual void Save( XclExpStream& rStrm ) override;
204 class ScPatternAttr;
206 /** Stores the data of all fonts used in the document. */
207 class XclExpFontBuffer : public XclExpRecordBase, protected XclExpRoot
209 public:
210 explicit XclExpFontBuffer( const XclExpRoot& rRoot );
212 /** Returns the specified font from font list. */
213 const XclExpFont* GetFont( sal_uInt16 nXclFont ) const;
214 /** Returns the application font data of this file, needed e.g. for column width. */
215 const XclFontData& GetAppFontData() const;
217 /** Inserts a new font with the passed font data into the buffer if not present.
218 @param bAppFont true = Sets the application font; false = Inserts a new font.
219 @return The resulting Excel font index. */
220 sal_uInt16 Insert( const XclFontData& rFontData,
221 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,
225 XclExpColorType eColorType );
226 /** Inserts the font contained in the passed item set into the buffer, if not present.
227 @param nScript The script type of the font properties to be used.
228 @param bAppFont true = Sets the application font; false = Inserts a new font.
229 @return The resulting Excel font index. */
230 sal_uInt16 Insert( const SfxItemSet& rItemSet, sal_Int16 nScript,
231 XclExpColorType eColorType, bool bAppFont );
233 /** Writes all FONT records contained in this buffer. */
234 virtual void Save( XclExpStream& rStrm ) override;
235 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
237 private:
238 /** Initializes the default fonts for the current BIFF version. */
239 void InitDefaultFonts();
240 /** Tries to find the passed font and returns the current list index. */
241 size_t Find( const XclFontData& rFontData );
243 private:
244 typedef XclExpRecordList< XclExpFont > XclExpFontList;
245 typedef XclExpFontList::RecordRefType XclExpFontRef;
247 XclExpFontList maFontList; /// List of all FONT records.
248 size_t mnXclMaxSize; /// Maximum number of fonts.
251 // FORMAT record - number formats =============================================
253 /** Stores a core number format index with corresponding Excel format index. */
254 struct XclExpNumFmt
256 sal_uInt32 mnScNumFmt; /// Core index of the number format.
257 sal_uInt16 mnXclNumFmt; /// Resulting Excel format index.
258 OUString maNumFmtString; /// format string
260 explicit XclExpNumFmt( sal_uInt32 nScNumFmt, sal_uInt16 nXclNumFmt, OUString aFrmt ) :
261 mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ), maNumFmtString(std::move( aFrmt )) {}
263 void SaveXml( XclExpXmlStream& rStrm );
266 typedef ::std::unique_ptr< SvNumberFormatter > SvNumberFormatterPtr;
268 /** Stores all number formats used in the document. */
269 class XclExpNumFmtBuffer : public XclExpRecordBase, protected XclExpRoot
271 public:
272 explicit XclExpNumFmtBuffer( const XclExpRoot& rRoot );
273 virtual ~XclExpNumFmtBuffer() override;
275 /** Returns the core index of the current standard number format. */
276 sal_uInt32 GetStandardFormat() const { return mnStdFmt; }
278 /** Inserts a number format into the format buffer.
279 @param nScNumFmt The core index of the number format.
280 @return The resulting Excel format index. */
281 sal_uInt16 Insert( sal_uInt32 nScNumFmt );
283 /** Writes all FORMAT records contained in this buffer. */
284 virtual void Save( XclExpStream& rStrm ) override;
285 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
287 OUString GetFormatCode ( sal_uInt32 nScNumFmt );
289 private:
290 /** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
291 void WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXclNumFmt, const OUString& rFormatStr );
292 /** Writes the FORMAT record represented by rFormat. */
293 void WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat );
295 private:
296 typedef ::std::vector< XclExpNumFmt > XclExpNumFmtVec;
298 SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion.
299 XclExpNumFmtVec maFormatMap; /// Maps core formats to Excel indexes.
300 std::unique_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table.
301 sal_uInt32 mnStdFmt; /// Key for standard number format.
302 sal_uInt16 mnXclOffset; /// Offset to first user defined format.
305 // XF, STYLE record - Cell formatting =========================================
307 /** Extends the XclCellProt struct for export.
308 @descr Provides functions to fill from item sets and to fill to Excel record data. */
309 struct XclExpCellProt : public XclCellProt
311 /** Fills the protection attributes from the passed item set.
312 @return true = At least one protection item is set. */
313 bool FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle = false );
315 /** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
316 void FillToXF3( sal_uInt16& rnProt ) const;
318 void SaveXml( XclExpXmlStream& rStrm ) const;
321 /** Extends the XclCellAlign struct for export.
322 @descr Provides functions to fill from item sets and to fill to Excel record data. */
323 struct XclExpCellAlign : public XclCellAlign
325 /** Fills the alignment attributes from the passed item set.
326 @descr Fills only the attributes exported in the passed BIFF version.
327 @param bForceLineBreak true = Set line break flag unconditionally.
328 @return true = At least one alignment item is set. */
329 bool FillFromItemSet(const XclRoot& rRoot, const SfxItemSet& rItemSet,
330 bool bForceLineBreak, XclBiff eBiff, bool bStyle = false );
332 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
333 void FillToXF5( sal_uInt16& rnAlign ) const;
334 /** Fills the data to the passed fields of a BIFF8 XF record. */
335 void FillToXF8( sal_uInt16& rnAlign, sal_uInt16& rnMiscAttrib ) const;
337 void SaveXml( XclExpXmlStream& rStrm ) const;
340 /** Extends the XclCellBorder struct for export.
341 @descr Provides functions to fill from item sets and to fill to Excel record data. */
342 struct XclExpCellBorder : public XclCellBorder
344 sal_uInt32 mnLeftColorId; /// Color ID for left line.
345 sal_uInt32 mnRightColorId; /// Color ID for right line.
346 sal_uInt32 mnTopColorId; /// Color ID for top line.
347 sal_uInt32 mnBottomColorId; /// Color ID for bottom line.
348 sal_uInt32 mnDiagColorId; /// Color ID for diagonal line(s).
350 explicit XclExpCellBorder();
352 /** Fills the border attributes from the passed item set.
353 @descr Fills only the attributes exported in the passed BIFF version.
354 @return true = At least one border item is set. */
355 bool FillFromItemSet( const SfxItemSet& rItemSet,
356 XclExpPalette& rPalette, XclBiff eBiff, bool bStyle = false );
357 /** Fills the mn***Color base members from the mn***ColorId members. */
358 void SetFinalColors( const XclExpPalette& rPalette );
360 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
361 void FillToXF5( sal_uInt32& rnBorder, sal_uInt32& rnArea ) const;
362 /** Fills the data to the passed fields of a BIFF8 XF record. */
363 void FillToXF8( sal_uInt32& rnBorder1, sal_uInt32& rnBorder2 ) const;
365 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
366 void FillToCF8( sal_uInt16& rnLine, sal_uInt32& rnColor ) const;
368 void SaveXml( XclExpXmlStream& rStrm ) const;
371 /** Extends the XclCellArea struct for export.
372 @descr Provides functions to fill from item sets and to fill to Excel record data. */
373 struct XclExpCellArea : public XclCellArea
375 sal_uInt32 mnForeColorId; /// Foreground color ID.
376 sal_uInt32 mnBackColorId; /// Background color ID.
377 Color maForeColor; // Actual foreground color
378 Color maBackColor; // Actual background color
380 explicit XclExpCellArea();
381 explicit XclExpCellArea(Color aForeColor, Color aBackColor);
383 /** Fills the area attributes from the passed item set.
384 @return true = At least one area item is set. */
385 bool FillFromItemSet(
386 const SfxItemSet& rItemSet, XclExpPalette& rPalette,
387 bool bStyle );
388 /** Fills the mn***Color base members from the mn***ColorId members. */
389 void SetFinalColors( const XclExpPalette& rPalette );
391 /** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
392 void FillToXF5( sal_uInt32& rnArea ) const;
393 /** Fills the data to the passed fields of a BIFF8 XF record. */
394 void FillToXF8( sal_uInt32& rnBorder2, sal_uInt16& rnArea ) const;
396 /** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
397 void FillToCF8( sal_uInt16& rnPattern, sal_uInt16& rnColor ) const;
399 void SaveXml( XclExpXmlStream& rStrm ) const;
402 struct XclExpColor
404 Color maColor;
406 bool FillFromItemSet( const SfxItemSet& rItemSet );
408 void SaveXml( XclExpXmlStream& rStrm ) const;
411 /** A combination of unique XF identifier with real Excel XF index. */
412 struct XclExpXFId
414 sal_uInt32 mnXFId; /// Temporary XF identifier.
415 sal_uInt16 mnXFIndex; /// Real Excel XF index.
417 explicit XclExpXFId();
418 explicit XclExpXFId( sal_uInt32 nXFId )
419 : mnXFId( nXFId ), mnXFIndex( EXC_XF_DEFAULTCELL ) {}
421 /** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
422 void ConvertXFIndex( const XclExpRoot& rRoot );
425 class SfxStyleSheetBase;
427 /** Represents an XF record which contains all formatting data of a cell or cell style. */
428 class XclExpXF : public XclXFBase, public XclExpRecord, protected XclExpRoot
430 public:
431 /** Constructs a cell XF record from the passed Calc cell formatting. */
432 explicit XclExpXF(
433 const XclExpRoot& rRoot,
434 const ScPatternAttr& rPattern,
435 sal_Int16 nScript,
436 sal_uInt32 nScForceNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND,
437 sal_uInt16 nForceXclFont = EXC_FONT_NOTFOUND,
438 bool bForceLineBreak = false );
439 /** Constructs a style XF record from the passed cell style sheet. */
440 explicit XclExpXF(
441 const XclExpRoot& rRoot,
442 const SfxStyleSheetBase& rStyleSheet );
444 /** Returns the cell protection settings of this XF. */
445 const XclExpCellProt& GetProtectionData() const { return maProtection; }
446 /** Returns the alignment settings of this XF. */
447 const XclExpCellAlign& GetAlignmentData() const { return maAlignment; }
448 /** Returns the cell border settings of this XF. */
449 const XclExpCellBorder& GetBorderData() const { return maBorder; }
450 /** Returns the cell fill settings of this XF. */
451 const XclExpCellArea& GetAreaData() const { return maArea; }
453 /** Returns true, if this XF record represents the passed cell formatting.
454 @descr Searches for cell XFs only. */
455 bool Equals(
456 const ScPatternAttr& rPattern,
457 sal_uInt32 nScForceNumFmt,
458 sal_uInt16 nForceXclFont,
459 bool bForceLineBreak ) const;
461 /** Returns true, if this XF record represents the passed style.
462 @descr Searches for style XFs only. */
463 bool Equals( const SfxStyleSheetBase& rStyleSheet ) const;
465 /** Sets the resulting Excel palette index from all used color IDs (border and area). */
466 void SetFinalColors();
468 /** Returns true, if this XF record is completely equal to the passed. */
469 bool Equals( const XclExpXF& rCmpXF ) const;
471 void SetXmlIds( sal_uInt32 nBorderId, sal_uInt32 nFillId );
473 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
475 const SfxItemSet* GetItemSet() const { return mpItemSet; }
477 sal_uInt32 GetScNumFmt() const { return mnScNumFmt; }
478 sal_uInt16 GetXclFont() const { return mnXclFont; }
480 protected:
481 explicit XclExpXF( const XclExpRoot& rRoot, bool bCellXF );
483 protected: // access for XclExpDefaultXF
484 const SfxItemSet* mpItemSet; /// Pointer to the item set (we do not own it).
486 XclExpCellProt maProtection; /// Cell protection flags.
487 XclExpCellAlign maAlignment; /// All alignment attributes.
488 XclExpCellBorder maBorder; /// Border line style.
489 XclExpCellArea maArea; /// Background area style.
490 sal_uInt32 mnParentXFId; /// XF ID of parent XF record.
491 sal_uInt32 mnScNumFmt; /// Calc number format index.
492 sal_uInt16 mnXclFont; /// Excel font index.
493 sal_uInt16 mnXclNumFmt; /// Excel number format index.
494 sal_Int32 mnBorderId; /// OOXML Border Index
495 sal_Int32 mnFillId; /// OOXML Fill Index
497 private:
498 using XclXFBase::Equals;
500 /** Initializes with default values. */
501 void InitDefault();
502 /** Fills all members from the passed item set.
503 @param bDefStyle true = This is the "Default"/"Normal" style - needs special handling. */
504 void Init(
505 const SfxItemSet& rItemSet,
506 sal_Int16 nScript,
507 sal_uInt32 nForceScNumFmt,
508 sal_uInt16 nForceXclFont,
509 bool bForceLineBreak,
510 bool bDefStyle );
512 /** Returns the bits specifying the used attributes.
513 @descr In cell XFs a set bit means a used attribute, in style XF a cleared
514 bit means a used attribute. This method regards the cell/style state.
515 @return The mask based on bit 0 (not yet bit-shifted as needed for export). */
516 sal_uInt8 GetUsedFlags() const;
518 void WriteBody5( XclExpStream& rStrm );
519 void WriteBody8( XclExpStream& rStrm );
521 /** Writes the contents of the XF record. */
522 virtual void WriteBody( XclExpStream& rStrm ) override;
525 /** Represents a default XF record. Supports methods to set attributes directly. */
526 class XclExpDefaultXF : public XclExpXF
528 public:
529 explicit XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF );
531 /** Sets the Excel font index. */
532 void SetFont( sal_uInt16 nXclFont );
533 /** Sets the Excel number format index. */
534 void SetNumFmt( sal_uInt16 nXclNumFmt );
537 /** Represents a STYLE record containing the data of a cell style.
538 @descr The class is able to store built-in and user-defined styles. */
539 class XclExpStyle : public XclExpRecord
541 public:
542 explicit XclExpStyle( sal_uInt32 nXFId, OUString aStyleName );
543 explicit XclExpStyle( sal_uInt32 nXFId, sal_uInt8 nStyleId, sal_uInt8 nLevel );
545 /** Returns true, if this record represents an Excel built-in style. */
546 bool IsBuiltIn() const { return mnStyleId != EXC_STYLE_USERDEF; }
548 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
550 private:
551 /** Writes the contents of the STYLE record. */
552 virtual void WriteBody( XclExpStream& rStrm ) override;
554 private:
555 OUString maName; /// Name of the cell style.
556 XclExpXFId maXFId; /// XF identifier for style formatting.
557 sal_uInt8 mnStyleId; /// Built-in style identifier.
558 sal_uInt8 mnLevel; /// Outline level for RowLevel and ColLevel styles.
561 /** Stores all XF records (cell formats and cell styles) in the document.
563 Stores also the names of user defined cell styles (STYLE records). Supports
564 reduction to the maximum count of XF records of the current BIFF version.
566 An instance of this class collects all XF records in the conversion phase
567 of the export, using the Insert() and InsertStyle() functions. It returns a
568 unique identifier for each XF record.
570 After the entire document is converted, the Finalize() function will reduce
571 the list to the number of XF records supported by the current BIFF version.
573 Then, in the streaming phase, the function GetXFIndex() returns the real
574 Excel XF index for all XF identifiers.
576 class XclExpXFBuffer : public XclExpRecordBase, protected XclExpRoot
578 public:
579 explicit XclExpXFBuffer( const XclExpRoot& rRoot );
581 /** Inserts predefined built-in styles and user-defined styles. */
582 void Initialize();
584 /** Finds or creates a cell XF record for the passed item set.
585 @return A unique XF record ID. */
586 sal_uInt32 Insert( const ScPatternAttr* pPattern, sal_Int16 nScript );
587 /** Finds or creates a cell XF record for the passed item set.
588 @param nForceXclFont The font to be exported. If not equal to EXC_FONT_NOTFOUND,
589 this font index will be used unconditionally and the cell font will be ignored.
590 @param bForceLineBreak true = Set line break flag unconditionally.
591 This is required for cells that contain multi-line text.
592 @return A unique XF record ID. */
593 sal_uInt32 InsertWithFont(
594 const ScPatternAttr* pPattern, sal_Int16 nScript,
595 sal_uInt16 nForceXclFont,
596 bool bForceLineBreak );
597 /** Finds or creates a cell XF record for the passed item set, with custom number format.
598 @param nXFFlags Additional flags allowing to control the creation of an XF.
599 @param nForceScNumFmt The number format to be exported, e.g. formula
600 result type. This format will always overwrite the cell's number format.
601 @param bForceLineBreak true = Set line break flag unconditionally.
602 This is required for cells that contain multi-line text.
603 @return A unique XF record ID. */
604 sal_uInt32 InsertWithNumFmt(
605 const ScPatternAttr* pPattern, sal_Int16 nScript,
606 sal_uInt32 nForceScNumFmt,
607 bool bForceLineBreak );
608 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
609 @return A unique XF record ID. */
610 sal_uInt32 InsertStyle( const SfxStyleSheetBase* pStyleSheet );
611 /** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
612 static sal_uInt32 GetXFIdFromIndex( sal_uInt16 nXFIndex );
613 /** Returns the XF identifier representing the default cell XF. */
614 static sal_uInt32 GetDefCellXFId();
616 /** Returns an XF record by its unique identifier. */
617 const XclExpXF* GetXFById( sal_uInt32 nXFId ) const;
619 /** Reduces the XF record list to the maximum allowed number of records. */
620 void Finalize();
622 /** Returns the Excel XF index of the XF record with passed XF ID. */
623 sal_uInt16 GetXFIndex( sal_uInt32 nXFId ) const;
625 sal_Int32 GetXmlStyleIndex( sal_uInt32 nXFId ) const;
626 sal_Int32 GetXmlCellIndex( sal_uInt32 nXFId ) const;
628 /** Writes all XF records contained in this buffer. */
629 virtual void Save( XclExpStream& rStrm ) override;
630 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
632 private:
633 typedef XclExpRecordList< XclExpXF > XclExpXFList;
634 typedef XclExpXFList::RecordRefType XclExpXFRef;
636 private:
637 /** Returns the XF ID of the cell XF containing the passed format. */
638 sal_uInt32 FindXF( const ScPatternAttr& rPattern, sal_uInt32 nForceScNumFmt,
639 sal_uInt16 nForceXclFont, bool bForceLineBreak ) const;
640 /** Returns the XF ID of the style XF containing the passed style. */
641 sal_uInt32 FindXF( const SfxStyleSheetBase& rStyleSheet ) const;
643 /** Returns the XF ID of a built-in style XF, searches by style identifier. */
644 sal_uInt32 FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel ) const;
646 /** Tries to find the XF record containing the passed format or inserts a new record.
647 @return The XF record ID. */
648 sal_uInt32 InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript,
649 sal_uInt32 nForceScNumFmt,
650 sal_uInt16 nForceXclFont, bool bForceLineBreak );
651 /** Inserts the passed cell style. Creates a style XF record and a STYLE record.
652 @return The XF record ID. */
653 sal_uInt32 InsertStyleXF( const SfxStyleSheetBase& rStyleSheet );
655 /** Inserts an XF and a STYLE record for all user defined style sheets. */
656 void InsertUserStyles();
658 /** Inserts a built-in XF record without a STYLE record and returns the XF ID.
659 @param bCreateStyleRec true = Creates the related STYLE record. */
660 sal_uInt32 AppendBuiltInXF( XclExpXFRef const & xXF,
661 sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
662 /** Inserts a built-in XF and STYLE record and returns the XF ID.
663 @param bCreateStyleRec true = Creates the related STYLE record. */
664 sal_uInt32 AppendBuiltInXFWithStyle( XclExpXFRef const & xXF,
665 sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
667 /** Inserts all default XF and STYLE records. */
668 void InsertDefaultRecords();
670 /** Appends a XF index to the internal ID<->index maps. */
671 void AppendXFIndex( sal_uInt32 nXFId );
673 void AddBorderAndFill( const XclExpXF& rXF );
674 void SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF );
676 private:
677 /** Extended info about a built-in XF. */
678 struct XclExpBuiltInInfo
680 sal_uInt8 mnStyleId; /// Built-in style identifier.
681 sal_uInt8 mnLevel; /// Level for RowLevel/ColLevel styles.
682 bool mbPredefined; /// true = XF still predefined.
683 bool mbHasStyleRec; /// true = STYLE record created.
684 explicit XclExpBuiltInInfo();
686 typedef ::std::map< sal_uInt32, XclExpBuiltInInfo > XclExpBuiltInMap;
687 typedef ::std::vector< XclExpCellBorder > XclExpBorderList;
688 typedef ::std::vector< XclExpCellArea > XclExpFillList;
690 /** composite key for the find-map, so we can do partial key searching */
691 struct FindKey
693 bool mbCellXF; // is this a hard cell format, or a cell style
694 const SfxItemSet* mpItemSet;
695 sal_uInt32 mnScNumFmt;
696 sal_uInt16 mnXclFont;
698 bool operator<(const FindKey& other) const
700 if (mbCellXF != other.mbCellXF)
701 return mbCellXF < other.mbCellXF;
702 if (mpItemSet != other.mpItemSet)
703 return mpItemSet < other.mpItemSet;
704 if (mnScNumFmt != other.mnScNumFmt)
705 return mnScNumFmt < other.mnScNumFmt;
706 return mnXclFont < other.mnXclFont;
709 static FindKey ToFindKey(XclExpXF const &);
711 XclExpXFList maXFList; /// List of all XF records.
712 std::map<FindKey, std::vector<sal_uInt32>>
713 maXFFindMap; /// map of itemset to vector of positions, to speed up find
714 XclExpRecordList< XclExpStyle >
715 maStyleList; /// List of all STYLE records.
716 XclExpBuiltInMap maBuiltInMap; /// Contained elements describe built-in XFs.
717 ScfUInt16Vec maXFIndexVec; /// Maps XF IDs to XF indexes.
718 ScfUInt16Vec maStyleIndexes; /// Maps XF IDs to OOXML Style indexes
719 ScfUInt16Vec maCellIndexes; /// Maps XF IDs to OOXML Cell indexes
720 XclExpXFList maSortedXFList; /// List of XF records in XF index order.
721 XclExpBorderList maBorders; /// List of borders used by XF records
722 XclExpFillList maFills; /// List of fills used by XF records
726 class XclExpDxf : public XclExpRecordBase, protected XclExpRoot
728 public:
729 XclExpDxf( const XclExpRoot& rRoot, std::unique_ptr<XclExpCellAlign> pAlign, std::unique_ptr<XclExpCellBorder> pBorder,
730 std::unique_ptr<XclExpDxfFont> pFont, std::unique_ptr<XclExpNumFmt> pNumberFmt,
731 std::unique_ptr<XclExpCellProt> pProt, std::unique_ptr<XclExpColor> pColor);
732 XclExpDxf( const XclExpRoot& rRoot, std::unique_ptr<XclExpCellArea> pCellArea);
733 virtual ~XclExpDxf() override;
735 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
736 void SaveXmlExt( XclExpXmlStream& rStrm);
737 void SetFinalColors();
739 private:
740 std::unique_ptr<XclExpCellAlign> mpAlign;
741 std::unique_ptr<XclExpCellBorder> mpBorder;
742 std::unique_ptr<XclExpDxfFont> mpFont;
743 std::unique_ptr<XclExpNumFmt> mpNumberFmt;
744 std::unique_ptr<XclExpCellProt> mpProt;
745 std::unique_ptr<XclExpColor> mpColor;
746 std::unique_ptr<XclExpCellArea> mpCellArea;
749 class XclExpDxfs : public XclExpRecordBase, protected XclExpRoot
751 public:
752 XclExpDxfs( const XclExpRoot& rRoot );
754 sal_Int32 GetDxfId(const OUString& rName) const;
755 sal_Int32 GetDxfByColor(Color aColor) const;
756 void AddColor(Color aColor);
758 virtual void SaveXml( XclExpXmlStream& rStrm) override;
759 void Finalize();
761 private:
762 typedef std::vector< std::unique_ptr<XclExpDxf> > DxfContainer;
763 std::map<OUString, sal_Int32> maStyleNameToDxfId;
764 std::map<Color, sal_Int32> maColorToDxfId;
765 DxfContainer maDxf;
766 std::unique_ptr<NfKeywordTable> mpKeywordTable; /// Replacement table.
769 class XclExpXmlStyleSheet : public XclExpRecordBase, protected XclExpRoot
771 public:
772 explicit XclExpXmlStyleSheet( const XclExpRoot& rRoot );
774 virtual void SaveXml( XclExpXmlStream& rStrm ) override;
777 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */