1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef SC_XESTYLE_HXX
#define SC_XESTYLE_HXX
#include <map>
#include <tools/mempool.hxx>
#include <tools/string.hxx>
#include <svl/zforlist.hxx>
#include <svl/nfkeytab.hxx>
#include <editeng/svxfont.hxx>
#include "xerecord.hxx"
#include "xlstyle.hxx"
#include "xeroot.hxx"
/* ============================================================================
- Buffers for style records (PALETTE, FONT, FORMAT, XF, STYLE).
============================================================================ */
const sal_uInt16 EXC_ID_FONTLIST = 0x8031; /// For internal use only.
const sal_uInt16 EXC_ID_FORMATLIST = 0x801E; /// For internal use only.
const sal_uInt16 EXC_ID_XFLIST = 0x8043; /// For internal use only.
// PALETTE record - color information =========================================
/** Different types of colors in a document. */
enum XclExpColorType
{
EXC_COLOR_CELLTEXT, /// Text in a cell.
EXC_COLOR_CELLBORDER, /// Border of a cell.
EXC_COLOR_CELLAREA, /// Background area of a cell.
EXC_COLOR_CHARTTEXT, /// Text color in a chart.
EXC_COLOR_CHARTLINE, /// Line in a chart.
EXC_COLOR_CHARTAREA, /// Area in a chart.
EXC_COLOR_CTRLTEXT, /// Text color in a form control.
EXC_COLOR_GRID /// Spreadsheet grid color.
};
// ----------------------------------------------------------------------------
class XclExpPaletteImpl;
/** Stores all used colors in the document.
Supports color reduction to the maximum count of the current BIFF version.
An instance of this class collects all colors in the conversion phase of
the export, using the InsertColor() function. It returns a unique
identidier for each passed color.
After the entire document is converted, the Finalize() function will reduce
the palette to the number of colors supported by the current BIFF version.
Then, in the streaming phase, the functions GetColorIndex() and
GetMixedColors() return the real Excel palette index for all color
identifiers.
*/
class XclExpPalette : public XclDefaultPalette, public XclExpRecord
{
public:
explicit XclExpPalette( const XclExpRoot& rRoot );
virtual ~XclExpPalette();
/** Inserts the color into the list and updates weighting.
@param nAutoDefault The Excel palette index for automatic color.
@return A unique ID for this color. */
sal_uInt32 InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault = 0 );
/** Returns the color ID representing a fixed Excel palette index (i.e. for auto colors). */
static sal_uInt32 GetColorIdFromIndex( sal_uInt16 nIndex );
/** Reduces the color list to the maximum count of the current BIFF version. */
void Finalize();
/** Returns the Excel palette index of the color with passed color ID. */
sal_uInt16 GetColorIndex( sal_uInt32 nColorId ) const;
/** Returns a foreground and background color for the two passed color IDs.
@descr If rnXclPattern contains a solid pattern, this function tries to find
the two best fitting colors and a mix pattern (25%, 50% or 75%) for nForeColorId.
This will result in a better approximation to the passed foreground color. */
void GetMixedColors(
sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const;
/** Returns the RGB color data for a (non-zero-based) Excel palette entry.
@return The color from current or default palette or COL_AUTO, if nothing else found. */
ColorData GetColorData( sal_uInt16 nXclIndex ) const;
/** Returns the color for a (non-zero-based) Excel palette entry.
@return The color from current or default palette or COL_AUTO, if nothing else found. */
inline Color GetColor( sal_uInt16 nXclIndex ) const
{ return Color( GetColorData( nXclIndex ) ); }
/** Saves the PALETTE record, if it differs from the default palette. */
virtual void Save( XclExpStream& rStrm );
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
/** Writes the contents of the PALETTE record. */
virtual void WriteBody( XclExpStream& rStrm );
private:
typedef ScfRef< XclExpPaletteImpl > XclExpPaletteImplRef;
XclExpPaletteImplRef mxImpl;
};
// FONT record - font information =============================================
class Font;
class SvxFont;
const size_t EXC_FONTLIST_NOTFOUND = static_cast< size_t >( -1 );
// ----------------------------------------------------------------------------
/** Static helper functions for font export. */
class XclExpFontHelper
{
public:
/** Returns the script type of the first font item found in the item set and its parents. */
static sal_Int16 GetFirstUsedScript(
const XclExpRoot& rRoot,
const SfxItemSet& rItemSet );
/** Returns a VCL font object filled from the passed item set. */
static Font GetFontFromItemSet(
const XclExpRoot& rRoot,
const SfxItemSet& rItemSet,
sal_Int16 nScript );
/** Returns true, if at least one font related item is set in the passed item set.
@param bDeep true = Searches in parent item sets too. */
static bool CheckItems(
const XclExpRoot& rRoot,
const SfxItemSet& rItemSet,
sal_Int16 nScript,
bool bDeep );
private:
XclExpFontHelper();
~XclExpFontHelper();
};
// ----------------------------------------------------------------------------
/** Stores all data of an Excel font and provides export of FONT records. */
class XclExpFont : public XclExpRecord, protected XclExpRoot
{
public:
explicit XclExpFont( const XclExpRoot& rRoot,
const XclFontData& rFontData, XclExpColorType eColorType );
/** Returns read-only access to font data. */
inline const XclFontData& GetFontData() const { return maData; }
/** Returns the font color identifier. */
inline sal_uInt32 GetFontColorId() const { return mnColorId; }
/** Compares this font with the passed font data.
@param nHash The hash value calculated from the font data. */
virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
/** Writes the contents of the FONT record. */
virtual void WriteBody( XclExpStream& rStrm );
private:
XclFontData maData; /// All font attributes.
sal_uInt32 mnColorId; /// Unique color ID for text color.
sal_uInt32 mnHash; /// Hash value for fast comparison.
};
// ----------------------------------------------------------------------------
/** Used as placeholder for font index 4, which is not used in Excel. */
class XclExpBlindFont : public XclExpFont
{
public:
explicit XclExpBlindFont( const XclExpRoot& rRoot );
/** Returns always false to never find this font while searching the font list. */
virtual bool Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const;
/** Skips writing this record. */
virtual void Save( XclExpStream& rStrm );
};
// ----------------------------------------------------------------------------
class ScPatternAttr;
/** Stores the data of all fonts used in the document. */
class XclExpFontBuffer : public XclExpRecordBase, protected XclExpRoot
{
public:
explicit XclExpFontBuffer( const XclExpRoot& rRoot );
/** Returns the specified font from font list. */
const XclExpFont* GetFont( sal_uInt16 nXclFont ) const;
/** Returns the application font data of this file, needed e.g. for column width. */
const XclFontData& GetAppFontData() const;
/** Inserts a new font with the passed font data into the buffer if not present.
@param bAppFont true = Sets the application font; false = Inserts a new font.
@return The resulting Excel font index. */
sal_uInt16 Insert( const XclFontData& rFontData,
XclExpColorType eColorType, bool bAppFont = false );
/** Inserts the font into the buffer if not present.
@param bAppFont true = Sets the application font; false = Inserts a new font.
@return The resulting Excel font index. */
sal_uInt16 Insert( const Font& rFont,
XclExpColorType eColorType, bool bAppFont = false );
/** Inserts the SvxFont into the buffer if not present, e.g. where escapements are used.
@param bAppFont true = Sets the application font; false = Inserts a new font.
@return The resulting Excel font index. */
sal_uInt16 Insert( const SvxFont& rFont,
XclExpColorType eColorType, bool bAppFont = false );
/** Inserts the font contained in the passed item set into the buffer, if not present.
@param nScript The script type of the font properties to be used.
@param bAppFont true = Sets the application font; false = Inserts a new font.
@return The resulting Excel font index. */
sal_uInt16 Insert( const SfxItemSet& rItemSet, sal_Int16 nScript,
XclExpColorType eColorType, bool bAppFont = false );
/** Inserts the font contained in rPattern into the buffer if not present.
@param nScript The script type of the font properties to be used.
@param bAppFont true = Sets the application font; false = Inserts a new font.
@return The resulting Excel font index. */
sal_uInt16 Insert( const ScPatternAttr& rPattern, sal_Int16 nScript,
XclExpColorType eColorType, bool bAppFont = false );
/** Writes all FONT records contained in this buffer. */
virtual void Save( XclExpStream& rStrm );
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
/** Initializes the default fonts for the current BIFF version. */
void InitDefaultFonts();
/** Tries to find the passed font and returns the current list index. */
size_t Find( const XclFontData& rFontData );
private:
typedef XclExpRecordList< XclExpFont > XclExpFontList;
typedef XclExpFontList::RecordRefType XclExpFontRef;
XclExpFontList maFontList; /// List of all FONT records.
size_t mnXclMaxSize; /// Maximum number of fonts.
};
// FORMAT record - number formats =============================================
/** Stores a core number format index with corresponding Excel format index. */
struct XclExpNumFmt
{
ULONG mnScNumFmt; /// Core index of the number format.
sal_uInt16 mnXclNumFmt; /// Resulting Excel format index.
inline explicit XclExpNumFmt( ULONG nScNumFmt, sal_uInt16 nXclNumFmt ) :
mnScNumFmt( nScNumFmt ), mnXclNumFmt( nXclNumFmt ) {}
};
// ----------------------------------------------------------------------------
class SvNumberFormatter;
/** Stores all number formats used in the document. */
class XclExpNumFmtBuffer : public XclExpRecordBase, protected XclExpRoot
{
public:
explicit XclExpNumFmtBuffer( const XclExpRoot& rRoot );
virtual ~XclExpNumFmtBuffer();
/** Returns the core index of the current standard number format. */
inline ULONG GetStandardFormat() const { return mnStdFmt; }
/** Inserts a number format into the format buffer.
@param nScNumFmt The core index of the number format.
@return The resulting Excel format index. */
sal_uInt16 Insert( ULONG nScNumFmt );
/** Writes all FORMAT records contained in this buffer. */
virtual void Save( XclExpStream& rStrm );
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
/** Writes the FORMAT record with index nXclIx and format string rFormatStr. */
void WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXclNumFmt, const String& rFormatStr );
/** Writes the FORMAT record represented by rFormat. */
void WriteFormatRecord( XclExpStream& rStrm, const XclExpNumFmt& rFormat );
String GetFormatCode ( const XclExpNumFmt& rFormat );
private:
typedef ::std::auto_ptr< SvNumberFormatter > SvNumberFormatterPtr;
typedef ::std::vector< XclExpNumFmt > XclExpNumFmtVec;
typedef NfKeywordTable* NfKeywordTablePtr;
SvNumberFormatterPtr mxFormatter; /// Special number formatter for conversion.
XclExpNumFmtVec maFormatMap; /// Maps core formats to Excel indexes.
NfKeywordTablePtr mpKeywordTable; /// Replacement table.
ULONG mnStdFmt; /// Key for standard number format.
sal_uInt16 mnXclOffset; /// Offset to first user defined format.
};
// XF, STYLE record - Cell formatting =========================================
/** Extends the XclCellProt struct for export.
@descr Provides functions to fill from item sets and to fill to Excel record data. */
struct XclExpCellProt : public XclCellProt
{
/** Fills the protection attributes from the passed item set.
@return true = At least one protection item is set. */
bool FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle = false );
#if 0
/** Fills the data to the passed fields of a BIFF2 XF record. */
void FillToXF2( sal_uInt8& rnNumFmt ) const;
#endif
/** Fills the data to the passed fields of a BIFF3-BIFF8 XF record. */
void FillToXF3( sal_uInt16& rnProt ) const;
void SaveXml( XclExpXmlStream& rStrm ) const;
};
// ----------------------------------------------------------------------------
/** Extends the XclCellAlign struct for export.
@descr Provides functions to fill from item sets and to fill to Excel record data. */
struct XclExpCellAlign : public XclCellAlign
{
/** Fills the alignment attributes from the passed item set.
@descr Fills only the attributes exported in the passed BIFF version.
@param bForceLineBreak true = Set line break flag unconditionally.
@return true = At least one alignment item is set. */
bool FillFromItemSet( const SfxItemSet& rItemSet,
bool bForceLineBreak, XclBiff eBiff, bool bStyle = false );
#if 0
/** Fills the data to the passed fields of a BIFF2 XF record. */
void FillToXF2( sal_uInt8& rnFlags ) const;
/** Fills the data to the passed fields of a BIFF3 XF record. */
void FillToXF3( sal_uInt16& rnAlign ) const;
/** Fills the data to the passed fields of a BIFF4 XF record. */
void FillToXF4( sal_uInt16& rnAlign ) const;
#endif
/** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
void FillToXF5( sal_uInt16& rnAlign ) const;
/** Fills the data to the passed fields of a BIFF8 XF record. */
void FillToXF8( sal_uInt16& rnAlign, sal_uInt16& rnMiscAttrib ) const;
void SaveXml( XclExpXmlStream& rStrm ) const;
};
// ----------------------------------------------------------------------------
/** Extends the XclCellBorder struct for export.
@descr Provides functions to fill from item sets and to fill to Excel record data. */
struct XclExpCellBorder : public XclCellBorder
{
sal_uInt32 mnLeftColorId; /// Color ID for left line.
sal_uInt32 mnRightColorId; /// Color ID for right line.
sal_uInt32 mnTopColorId; /// Color ID for top line.
sal_uInt32 mnBottomColorId; /// Color ID for bottom line.
sal_uInt32 mnDiagColorId; /// Color ID for diagonal line(s).
explicit XclExpCellBorder();
/** Fills the border attributes from the passed item set.
@descr Fills only the attributes exported in the passed BIFF version.
@return true = At least one border item is set. */
bool FillFromItemSet( const SfxItemSet& rItemSet,
XclExpPalette& rPalette, XclBiff eBiff, bool bStyle = false );
/** Fills the mn***Color base members from the mn***ColorId members. */
void SetFinalColors( const XclExpPalette& rPalette );
#if 0
/** Fills the data to the passed fields of a BIFF2 XF record. */
void FillToXF2( sal_uInt8& rnFlags ) const;
/** Fills the data to the passed fields of a BIFF3/BIFF4 XF record. */
void FillToXF3( sal_uInt32& rnBorder ) const;
#endif
/** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
void FillToXF5( sal_uInt32& rnBorder, sal_uInt32& rnArea ) const;
/** Fills the data to the passed fields of a BIFF8 XF record. */
void FillToXF8( sal_uInt32& rnBorder1, sal_uInt32& rnBorder2 ) const;
/** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
void FillToCF8( sal_uInt16& rnLine, sal_uInt32& rnColor ) const;
void SaveXml( XclExpXmlStream& rStrm ) const;
};
// ----------------------------------------------------------------------------
/** Extends the XclCellArea struct for export.
@descr Provides functions to fill from item sets and to fill to Excel record data. */
struct XclExpCellArea : public XclCellArea
{
sal_uInt32 mnForeColorId; /// Foreground color ID.
sal_uInt32 mnBackColorId; /// Background color ID.
explicit XclExpCellArea();
/** Fills the area attributes from the passed item set.
@return true = At least one area item is set. */
bool FillFromItemSet(
const SfxItemSet& rItemSet, XclExpPalette& rPalette,
bool bStyle = false );
/** Fills the mn***Color base members from the mn***ColorId members. */
void SetFinalColors( const XclExpPalette& rPalette );
#if 0
/** Fills the data to the passed fields of a BIFF2 XF record. */
void FillToXF2( sal_uInt8& rnFlags ) const;
/** Fills the data to the passed fields of a BIFF3/BIFF4 XF record. */
void FillToXF3( sal_uInt16& rnArea ) const;
#endif
/** Fills the data to the passed fields of a BIFF5/BIFF7 XF record. */
void FillToXF5( sal_uInt32& rnArea ) const;
/** Fills the data to the passed fields of a BIFF8 XF record. */
void FillToXF8( sal_uInt32& rnBorder2, sal_uInt16& rnArea ) const;
/** Fills the data to the passed fields of a BIFF8 CF (conditional format) record. */
void FillToCF8( sal_uInt16& rnPattern, sal_uInt16& rnColor ) const;
void SaveXml( XclExpXmlStream& rStrm ) const;
};
// ----------------------------------------------------------------------------
/** A combination of unique XF identifier with real Excel XF index. */
struct XclExpXFId
{
sal_uInt32 mnXFId; /// Temporary XF identifier.
sal_uInt16 mnXFIndex; /// Real Excel XF index.
explicit XclExpXFId();
explicit XclExpXFId( sal_uInt32 nXFId );
/** Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex. */
void ConvertXFIndex( const XclExpRoot& rRoot );
};
// ----------------------------------------------------------------------------
class SfxStyleSheetBase;
/** Represents an XF record which contains all formatting data of a cell or cell style. */
class XclExpXF : public XclXFBase, public XclExpRecord, protected XclExpRoot
{
public:
/** Constructs a cell XF record from the passed Calc cell formatting. */
explicit XclExpXF(
const XclExpRoot& rRoot,
const ScPatternAttr& rPattern,
sal_Int16 nScript,
ULONG nScForceNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND,
sal_uInt16 nForceXclFont = EXC_FONT_NOTFOUND,
bool bForceLineBreak = false );
/** Constructs a style XF record from the passed cell style sheet. */
explicit XclExpXF(
const XclExpRoot& rRoot,
const SfxStyleSheetBase& rStyleSheet );
/** Returns the cell protection settings of this XF. */
const XclExpCellProt& GetProtectionData() const { return maProtection; }
/** Returns the alignment settings of this XF. */
const XclExpCellAlign& GetAlignmentData() const { return maAlignment; }
/** Returns the cell border settings of this XF. */
const XclExpCellBorder& GetBorderData() const { return maBorder; }
/** Returns the cell fill settings of this XF. */
const XclExpCellArea& GetAreaData() const { return maArea; }
/** Returns true, if this XF record represents the passed cell formatting.
@descr Searches for cell XFs only. */
bool Equals(
const ScPatternAttr& rPattern,
ULONG nScForceNumFmt,
sal_uInt16 nForceXclFont,
bool bForceLineBreak ) const;
/** Returns true, if this XF record represents the passed style.
@descr Searches for style XFs only. */
bool Equals( const SfxStyleSheetBase& rStyleSheet ) const;
/** Sets the resulting Excel palette index from all used color IDs (border and area). */
void SetFinalColors();
/** Returns true, if this XF record is completely equal to the passed. */
bool Equals( const XclExpXF& rCmpXF ) const;
void SetXmlIds( sal_uInt32 nBorderId, sal_uInt32 nFillId );
virtual void SaveXml( XclExpXmlStream& rStrm );
protected:
explicit XclExpXF( const XclExpRoot& rRoot, bool bCellXF );
protected: // access for XclExpDefaultXF
const SfxItemSet* mpItemSet; /// Pointer to the item set (we do not own it).
XclExpCellProt maProtection; /// Cell protection flags.
XclExpCellAlign maAlignment; /// All alignment attributes.
XclExpCellBorder maBorder; /// Border line style.
XclExpCellArea maArea; /// Background area style.
sal_uInt32 mnParentXFId; /// XF ID of parent XF record.
ULONG mnScNumFmt; /// Calc number format index.
sal_uInt16 mnXclFont; /// Excel font index.
sal_uInt16 mnXclNumFmt; /// Excel number format index.
sal_Int32 mnBorderId; /// OOXML Border Index
sal_Int32 mnFillId; /// OOXML Fill Index
private:
using XclXFBase::Equals;
/** Initializes with default values. */
void InitDefault();
/** Fills all members from the passed item set.
@param bDefStyle true = This is the "Default"/"Normal" style - needs special handling. */
void Init(
const SfxItemSet& rItemSet,
sal_Int16 nScript,
ULONG nForceScNumFmt,
sal_uInt16 nForceXclFont,
bool bForceLineBreak,
bool bDefStyle );
/** Returns the bits specifying the used attributes.
@descr In cell XFs a set bit means a used attribute, in style XF a cleared
bit means a used attribute. This method regards the cell/style state.
@return The mask based on bit 0 (not yet bit-shifted as needed for export). */
sal_uInt8 GetUsedFlags() const;
void WriteBody5( XclExpStream& rStrm );
void WriteBody8( XclExpStream& rStrm );
/** Writes the contents of the XF record. */
virtual void WriteBody( XclExpStream& rStrm );
};
// ----------------------------------------------------------------------------
/** Represents a default XF record. Supports methods to set attributes directly. */
class XclExpDefaultXF : public XclExpXF
{
public:
explicit XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF );
//UNUSED2008-05 /** Sets the parent XF ID. Only allowed for cell XFs. */
//UNUSED2008-05 void SetParent( sal_uInt32 nParentXFId );
//UNUSED2008-05
//UNUSED2008-05 /** Sets all "attribute used" flags explicitely.
//UNUSED2008-05 @descr The following Set***() functions set the appropriate flag too. */
//UNUSED2008-05 void SetUsedFlags(
//UNUSED2008-05 bool bProtUsed, bool bFontUsed, bool bFmtUsed,
//UNUSED2008-05 bool bAlignUsed, bool bBorderUsed, bool bAreaUsed );
//UNUSED2008-05 /** Sets the cell protection flags. */
//UNUSED2008-05 void SetProtection( const XclExpCellProt& rProtection );
//UNUSED2008-05 /** Sets cell alignment attributes. */
//UNUSED2008-05 void SetAlignment( const XclExpCellAlign& rAlignment );
//UNUSED2008-05 /** Sets a cell border style. */
//UNUSED2008-05 void SetBorder( const XclExpCellBorder& rBorder );
//UNUSED2008-05 /** Sets a cell area style. */
//UNUSED2008-05 void SetArea( const XclExpCellArea& rArea );
/** Sets the Excel font index. */
void SetFont( sal_uInt16 nXclFont );
/** Sets the Excel number format index. */
void SetNumFmt( sal_uInt16 nXclNumFmt );
};
// ----------------------------------------------------------------------------
/** Represents a STYLE record containing the data of a cell style.
@descr The calss is able to store built-in and user-defined styles. */
class XclExpStyle : public XclExpRecord
{
public:
explicit XclExpStyle( sal_uInt32 nXFId, const String& rStyleName );
explicit XclExpStyle( sal_uInt32 nXFId, sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
/** Returns true, if this record represents an Excel built-in style. */
inline bool IsBuiltIn() const { return mnStyleId != EXC_STYLE_USERDEF; }
inline const String& GetName() const { return maName; }
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
/** Writes the contents of the STYLE record. */
virtual void WriteBody( XclExpStream& rStrm );
private:
String maName; /// Name of the cell style.
XclExpXFId maXFId; /// XF identifier for style formatting.
sal_uInt8 mnStyleId; /// Built-in style identifier.
sal_uInt8 mnLevel; /// Outline level for RowLevel and ColLevel styles.
};
// ----------------------------------------------------------------------------
/** Stores all XF records (cell formats and cell styles) in the document.
Stores also the names of user defined cell styles (STYLE records). Supports
reduction to the maximum count of XF records of the current BIFF version.
An instance of this class collects all XF records in the conversion phase
of the export, using the Insert() and InsertStyle() functions. It returns a
unique identidier for each XF record.
After the entire document is converted, the Finalize() function will reduce
the list to the number of XF records supported by the current BIFF version.
Then, in the streaming phase, the function GetXFIndex() returns the real
Excel XF index for all XF identifiers.
*/
class XclExpXFBuffer : public XclExpRecordBase, protected XclExpRoot
{
public:
explicit XclExpXFBuffer( const XclExpRoot& rRoot );
/** Inserts predefined built-in styles and user-defined styles. */
void Initialize();
/** Finds or creates a cell XF record for the passed item set.
@return A unique XF record ID. */
sal_uInt32 Insert( const ScPatternAttr* pPattern, sal_Int16 nScript );
/** Finds or creates a cell XF record for the passed item set.
@param nForceXclFont The font to be exported. If not equal to EXC_FONT_NOTFOUND,
this font index will be used unconditionally and the cell font will be ignored.
@param bForceLineBreak true = Set line break flag unconditionally.
This is required for cells that contain multi-line text.
@return A unique XF record ID. */
sal_uInt32 InsertWithFont(
const ScPatternAttr* pPattern, sal_Int16 nScript,
sal_uInt16 nForceXclFont,
bool bForceLineBreak );
/** Finds or creates a cell XF record for the passed item set, with custom number format.
@param nXFFlags Additional flags allowing to control the creation of an XF.
@param nForceScNumFmt The number format to be exported, e.g. formula
result type. This format will always overwrite the cell's number format.
@param bForceLineBreak true = Set line break flag unconditionally.
This is required for cells that contain multi-line text.
@return A unique XF record ID. */
sal_uInt32 InsertWithNumFmt(
const ScPatternAttr* pPattern, sal_Int16 nScript,
ULONG nForceScNumFmt,
bool bForceLineBreak );
/** Inserts the passed cell style. Creates a style XF record and a STYLE record.
@return A unique XF record ID. */
sal_uInt32 InsertStyle( const SfxStyleSheetBase* pStyleSheet );
/** Returns the XF identifier representing a fixed Excel XF index (e.g. for built-in XFs). */
static sal_uInt32 GetXFIdFromIndex( sal_uInt16 nXFIndex );
/** Returns the XF identifier representing the default cell XF. */
static sal_uInt32 GetDefCellXFId();
/** Returns an XF record by its unique identifier. */
const XclExpXF* GetXFById( sal_uInt32 nXFId ) const;
/** Reduces the XF record list to the maximum allowed number of records. */
void Finalize();
/** Returns the Excel XF index of the XF record with passed XF ID. */
sal_uInt16 GetXFIndex( sal_uInt32 nXFId ) const;
sal_Int32 GetXmlStyleIndex( sal_uInt32 nXFId ) const;
sal_Int32 GetXmlCellIndex( sal_uInt32 nXFId ) const;
/** Writes all XF records contained in this buffer. */
virtual void Save( XclExpStream& rStrm );
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
typedef XclExpRecordList< XclExpXF > XclExpXFList;
typedef XclExpXFList::RecordRefType XclExpXFRef;
typedef XclExpRecordList< XclExpStyle > XclExpStyleList;
private:
/** Returns the XF ID of the cell XF containing the passed format. */
sal_uInt32 FindXF( const ScPatternAttr& rPattern, ULONG nForceScNumFmt,
sal_uInt16 nForceXclFont, bool bForceLineBreak ) const;
/** Returns the XF ID of the style XF containing the passed style. */
sal_uInt32 FindXF( const SfxStyleSheetBase& rStyleSheet ) const;
/** Returns the XF ID of a built-in style XF, searches by style identifier. */
sal_uInt32 FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL ) const;
/** Tries to find the XF record containing the passed format or inserts a new record.
@return The XF record ID. */
sal_uInt32 InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript,
ULONG nForceScNumFmt,
sal_uInt16 nForceXclFont, bool bForceLineBreak );
/** Inserts the passed cell style. Creates a style XF record and a STYLE record.
@return The XF record ID. */
sal_uInt32 InsertStyleXF( const SfxStyleSheetBase& rStyleSheet );
/** Inserts an XF and a STYLE record for all user defined style sheets. */
void InsertUserStyles();
/** Inserts a built-in XF record without a STYLE record and returns the XF ID.
@param bCreateStyleRec true = Creates the related STYLE record. */
sal_uInt32 AppendBuiltInXF( XclExpXFRef xXF,
sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
/** Inserts a built-in XF and STYLE record and returns the XF ID.
@param bCreateStyleRec true = Creates the related STYLE record. */
sal_uInt32 AppendBuiltInXFWithStyle( XclExpXFRef xXF,
sal_uInt8 nStyleId, sal_uInt8 nLevel = EXC_STYLE_NOLEVEL );
/** Inserts all default XF and STYLE records. */
void InsertDefaultRecords();
/** Appends a XF index to the internal ID<->index maps. */
void AppendXFIndex( sal_uInt32 nXFId );
void AddBorderAndFill( const XclExpXF& rXF );
void SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF );
private:
/** Extended info about a built-in XF. */
struct XclExpBuiltInInfo
{
sal_uInt8 mnStyleId; /// Built-in style identifier.
sal_uInt8 mnLevel; /// Level for RowLevel/ColLevel styles.
bool mbPredefined; /// true = XF still predefined.
bool mbHasStyleRec; /// true = STYLE record created.
explicit XclExpBuiltInInfo();
};
typedef ::std::map< sal_uInt32, XclExpBuiltInInfo > XclExpBuiltInMap;
typedef ::std::vector< XclExpCellBorder > XclExpBorderList;
typedef ::std::vector< XclExpCellArea > XclExpFillList;
XclExpXFList maXFList; /// List of all XF records.
XclExpStyleList maStyleList; /// List of all STYLE records.
XclExpBuiltInMap maBuiltInMap; /// Contained elements describe built-in XFs.
ScfUInt16Vec maXFIndexVec; /// Maps XF IDs to XF indexes.
ScfUInt16Vec maStyleIndexes; /// Maps XF IDs to OOXML Style indexes
ScfUInt16Vec maCellIndexes; /// Maps XF IDs to OOXML Cell indexes
XclExpXFList maSortedXFList; /// List of XF records in XF index order.
XclExpBorderList maBorders; /// List of borders used by XF records
XclExpFillList maFills; /// List of fills used by XF records
};
// ============================================================================
class XclExpXmlStyleSheet : public XclExpRecordBase, protected XclExpRoot
{
public:
explicit XclExpXmlStyleSheet( const XclExpRoot& rRoot );
virtual void SaveXml( XclExpXmlStream& rStrm );
private:
};
// ============================================================================
#endif
|