Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef OOX_XLS_STYLESBUFFER_HXX
21 : #define OOX_XLS_STYLESBUFFER_HXX
22 :
23 : #include <com/sun/star/awt/FontDescriptor.hpp>
24 : #include <com/sun/star/table/CellHoriJustify.hpp>
25 : #include <com/sun/star/table/CellOrientation.hpp>
26 : #include <com/sun/star/table/CellVertJustify2.hpp>
27 : #include <com/sun/star/table/BorderLine2.hpp>
28 : #include <com/sun/star/util/CellProtection.hpp>
29 : #include "oox/drawingml/color.hxx"
30 : #include "oox/helper/graphichelper.hxx"
31 : #include "oox/helper/refmap.hxx"
32 : #include "oox/helper/refvector.hxx"
33 : #include "numberformatsbuffer.hxx"
34 : #include "patattr.hxx"
35 : #include "stlsheet.hxx"
36 : #include <editeng/svxenum.hxx>
37 : #include <editeng/frmdir.hxx>
38 :
39 : class ScMarkData;
40 : namespace com { namespace sun { namespace star {
41 : namespace awt { struct FontDescrtiptor; }
42 : } } }
43 :
44 : namespace oox { class PropertySet; }
45 :
46 : namespace oox {
47 : namespace xls {
48 :
49 : // ============================================================================
50 :
51 : const sal_Int32 OOX_COLOR_WINDOWTEXT3 = 24; /// System window text color (BIFF3-BIFF4).
52 : const sal_Int32 OOX_COLOR_WINDOWBACK3 = 25; /// System window background color (BIFF3-BIFF4).
53 : const sal_Int32 OOX_COLOR_WINDOWTEXT = 64; /// System window text color (BIFF5+).
54 : const sal_Int32 OOX_COLOR_WINDOWBACK = 65; /// System window background color (BIFF5+).
55 : const sal_Int32 OOX_COLOR_BUTTONBACK = 67; /// System button background color (face color).
56 : const sal_Int32 OOX_COLOR_CHWINDOWTEXT = 77; /// System window text color (BIFF8 charts).
57 : const sal_Int32 OOX_COLOR_CHWINDOWBACK = 78; /// System window background color (BIFF8 charts).
58 : const sal_Int32 OOX_COLOR_CHBORDERAUTO = 79; /// Automatic frame border (BIFF8 charts).
59 : const sal_Int32 OOX_COLOR_NOTEBACK = 80; /// Note background color.
60 : const sal_Int32 OOX_COLOR_NOTETEXT = 81; /// Note text color.
61 : const sal_Int32 OOX_COLOR_FONTAUTO = 0x7FFF; /// Font auto color (system window text color).
62 :
63 : // ----------------------------------------------------------------------------
64 :
65 : const sal_Int16 API_LINE_NONE = 0;
66 : const sal_Int16 API_LINE_HAIR = 2;
67 : const sal_Int16 API_LINE_THIN = 35;
68 : const sal_Int16 API_LINE_MEDIUM = 88;
69 : const sal_Int16 API_LINE_THICK = 141;
70 :
71 : const sal_Int16 API_ESCAPE_NONE = 0; /// No escapement.
72 : const sal_Int16 API_ESCAPE_SUPERSCRIPT = 101; /// Superscript: raise characters automatically (magic value 101).
73 : const sal_Int16 API_ESCAPE_SUBSCRIPT = -101; /// Subscript: lower characters automatically (magic value -101).
74 :
75 : const sal_Int8 API_ESCAPEHEIGHT_NONE = 100; /// Relative character height if not escaped.
76 : const sal_Int8 API_ESCAPEHEIGHT_DEFAULT = 58; /// Relative character height if escaped.
77 :
78 : // ============================================================================
79 :
80 : /** Special implementation of the GraphicHelper for Excel palette and scheme
81 : colors.
82 : */
83 22 : class ExcelGraphicHelper : public GraphicHelper, public WorkbookHelper
84 : {
85 : public:
86 : explicit ExcelGraphicHelper( const WorkbookHelper& rHelper );
87 :
88 : /** Derived classes may implement to resolve a scheme color from the passed XML token identifier. */
89 : virtual sal_Int32 getSchemeColor( sal_Int32 nToken ) const;
90 : /** Derived classes may implement to resolve a palette index to an RGB color. */
91 : virtual sal_Int32 getPaletteColor( sal_Int32 nPaletteIdx ) const;
92 : };
93 :
94 : // ============================================================================
95 :
96 696 : class Color : public ::oox::drawingml::Color
97 : {
98 : public:
99 : /** Sets the color to automatic. */
100 : void setAuto();
101 : /** Sets the color to the passed RGB value. */
102 : void setRgb( sal_Int32 nRgbValue, double fTint = 0.0 );
103 : /** Sets the color to the passed theme index. */
104 : void setTheme( sal_Int32 nThemeIdx, double fTint = 0.0 );
105 : /** Sets the color to the passed palette index. */
106 : void setIndexed( sal_Int32 nPaletteIdx, double fTint = 0.0 );
107 :
108 : /** Imports the color from the passed attribute list. */
109 : void importColor( const AttributeList& rAttribs );
110 :
111 : /** Imports a 64-bit color from the passed binary stream. */
112 : void importColor( SequenceInputStream& rStrm );
113 : /** Imports a 32-bit palette color identifier from the passed BIFF12 stream. */
114 : void importColorId( SequenceInputStream& rStrm );
115 :
116 : /** Returns true, if the color is set to automatic. */
117 25 : inline bool isAuto() const { return isPlaceHolder(); }
118 : };
119 :
120 : // ----------------------------------------------------------------------------
121 :
122 : SequenceInputStream& operator>>( SequenceInputStream& rStrm, Color& orColor );
123 :
124 : // ============================================================================
125 :
126 : /** Stores all colors of the color palette. */
127 11 : class ColorPalette : public WorkbookHelper
128 : {
129 : public:
130 : /** Constructs the color palette with predefined color values. */
131 : explicit ColorPalette( const WorkbookHelper& rHelper );
132 :
133 : /** Appends a new color from the passed attributes. */
134 : void importPaletteColor( const AttributeList& rAttribs );
135 : /** Appends a new color from the passed RGBCOLOR record. */
136 : void importPaletteColor( SequenceInputStream& rStrm );
137 :
138 : /** Rturns the RGB value of the color with the passed index. */
139 : sal_Int32 getColor( sal_Int32 nPaletteIdx ) const;
140 :
141 : private:
142 : /** Appends the passed color. */
143 : void appendColor( sal_Int32 nRGBValue );
144 :
145 : private:
146 : ::std::vector< sal_Int32 > maColors; /// List of RGB values.
147 : size_t mnAppendIndex; /// Index to append a new color.
148 : };
149 :
150 : // ============================================================================
151 :
152 : /** Contains all XML font attributes, e.g. from a font or rPr element. */
153 268 : struct FontModel
154 : {
155 : ::rtl::OUString maName; /// Font name.
156 : Color maColor; /// Font color.
157 : sal_Int32 mnScheme; /// Major/minor scheme font.
158 : sal_Int32 mnFamily; /// Font family.
159 : sal_Int32 mnCharSet; /// Windows font character set.
160 : double mfHeight; /// Font height in points.
161 : sal_Int32 mnUnderline; /// Underline style.
162 : sal_Int32 mnEscapement; /// Escapement style.
163 : bool mbBold; /// True = bold characters.
164 : bool mbItalic; /// True = italic characters.
165 : bool mbStrikeout; /// True = Strike out characters.
166 : bool mbOutline; /// True = outlined characters.
167 : bool mbShadow; /// True = shadowed chgaracters.
168 :
169 : explicit FontModel();
170 :
171 : void setBiff12Scheme( sal_uInt8 nScheme );
172 : void setBiffHeight( sal_uInt16 nHeight );
173 : void setBiffWeight( sal_uInt16 nWeight );
174 : void setBiffUnderline( sal_uInt16 nUnderline );
175 : void setBiffEscapement( sal_uInt16 nEscapement );
176 : };
177 :
178 : // ----------------------------------------------------------------------------
179 :
180 : /** Enumerates different types of API font property sets. */
181 : enum FontPropertyType
182 : {
183 : FONT_PROPTYPE_CELL, /// Font properties in a spreadsheet cell (table::Cell service).
184 : FONT_PROPTYPE_TEXT /// Font properties in a text object (text::Text service).
185 : };
186 :
187 : // ----------------------------------------------------------------------------
188 :
189 : /** Contains used flags for all API font attributes. */
190 : struct ApiFontUsedFlags
191 : {
192 : bool mbNameUsed; /// True = font name/family/char set are used.
193 : bool mbColorUsed; /// True = font color is used.
194 : bool mbSchemeUsed; /// True = font scheme is used.
195 : bool mbHeightUsed; /// True = font height is used.
196 : bool mbUnderlineUsed; /// True = underline style is used.
197 : bool mbEscapementUsed; /// True = escapement style is used.
198 : bool mbWeightUsed; /// True = font weight (boldness) is used.
199 : bool mbPostureUsed; /// True = font posture (italic) is used.
200 : bool mbStrikeoutUsed; /// True = strike out style is used.
201 : bool mbOutlineUsed; /// True = outline style is used.
202 : bool mbShadowUsed; /// True = shadow style is used.
203 :
204 : explicit ApiFontUsedFlags( bool bAllUsed );
205 : };
206 :
207 : // ----------------------------------------------------------------------------
208 :
209 : /** Contains API font name, family, and charset for a script type. */
210 702 : struct ApiScriptFontName
211 : {
212 : ::rtl::OUString maName; /// Font name.
213 : sal_Int16 mnFamily; /// Font family.
214 : sal_Int16 mnTextEnc; /// Font text encoding.
215 :
216 : explicit ApiScriptFontName();
217 : };
218 :
219 : // ----------------------------------------------------------------------------
220 :
221 : /** Contains all API font attributes. */
222 104 : struct ApiFontData
223 : {
224 : typedef ::com::sun::star::awt::FontDescriptor ApiFontDescriptor;
225 :
226 : ApiScriptFontName maLatinFont; /// Font name for latin scripts.
227 : ApiScriptFontName maAsianFont; /// Font name for east-asian scripts.
228 : ApiScriptFontName maCmplxFont; /// Font name for complex scripts.
229 : ApiFontDescriptor maDesc; /// Font descriptor (height in twips, weight in %).
230 : sal_Int32 mnColor; /// Font color.
231 : sal_Int16 mnEscapement; /// Escapement style.
232 : sal_Int8 mnEscapeHeight; /// Escapement font height.
233 : bool mbOutline; /// True = outlined characters.
234 : bool mbShadow; /// True = shadowed chgaracters.
235 :
236 : explicit ApiFontData();
237 : };
238 :
239 : // ============================================================================
240 :
241 170 : class Font : public WorkbookHelper
242 : {
243 : public:
244 : explicit Font( const WorkbookHelper& rHelper, bool bDxf );
245 : explicit Font( const WorkbookHelper& rHelper, const FontModel& rModel );
246 :
247 : /** Sets font formatting attributes for the passed element. */
248 : void importAttribs( sal_Int32 nElement, const AttributeList& rAttribs );
249 :
250 : /** Imports the FONT record from the passed stream. */
251 : void importFont( SequenceInputStream& rStrm );
252 : /** Imports the font name from a DXF record. */
253 : void importDxfName( SequenceInputStream& rStrm );
254 : /** Imports the font color from a DXF record. */
255 : void importDxfColor( SequenceInputStream& rStrm );
256 : /** Imports the font scheme from a DXF record. */
257 : void importDxfScheme( SequenceInputStream& rStrm );
258 : /** Imports the font height from a DXF record. */
259 : void importDxfHeight( SequenceInputStream& rStrm );
260 : /** Imports the font weight from a DXF record. */
261 : void importDxfWeight( SequenceInputStream& rStrm );
262 : /** Imports the font underline style from a DXF record. */
263 : void importDxfUnderline( SequenceInputStream& rStrm );
264 : /** Imports the font escapement style from a DXF record. */
265 : void importDxfEscapement( SequenceInputStream& rStrm );
266 : /** Imports a font style flag from a DXF record. */
267 : void importDxfFlag( sal_Int32 nElement, SequenceInputStream& rStrm );
268 :
269 : /** Returns the font model structure. This function can be called before
270 : finalizeImport() has been called. */
271 38 : inline const FontModel& getModel() const { return maModel; }
272 :
273 : /** Final processing after import of all style settings. */
274 : void finalizeImport();
275 :
276 : /** Returns an API font descriptor with own font information. */
277 : const ::com::sun::star::awt::FontDescriptor& getFontDescriptor() const;
278 : /** Returns true, if the font requires rich text formatting in Calc.
279 : @descr Example: Font escapement is a cell attribute in Excel, but Calc
280 : needs an rich text cell for this attribute. */
281 : bool needsRichTextFormat() const;
282 :
283 : void fillToItemSet( SfxItemSet& rItemSet, FontPropertyType ePropType, bool bSkipPoolDefs = false ) const;
284 : /** Writes all font attributes to the passed property map. */
285 : void writeToPropertyMap(
286 : PropertyMap& rPropMap,
287 : FontPropertyType ePropType ) const;
288 : /** Writes all font attributes to the passed property set. */
289 : void writeToPropertySet(
290 : PropertySet& rPropSet,
291 : FontPropertyType ePropType ) const;
292 :
293 : private:
294 : FontModel maModel;
295 : ApiFontData maApiData;
296 : ApiFontUsedFlags maUsedFlags;
297 : bool mbDxf;
298 : };
299 :
300 : typedef ::boost::shared_ptr< Font > FontRef;
301 :
302 : // ============================================================================
303 :
304 : /** Contains all XML cell alignment attributes, e.g. from an alignment element. */
305 : struct AlignmentModel
306 : {
307 : sal_Int32 mnHorAlign; /// Horizontal alignment.
308 : sal_Int32 mnVerAlign; /// Vertical alignment.
309 : sal_Int32 mnTextDir; /// CTL text direction.
310 : sal_Int32 mnRotation; /// Text rotation angle.
311 : sal_Int32 mnIndent; /// Indentation.
312 : bool mbWrapText; /// True = multi-line text.
313 : bool mbShrink; /// True = shrink to fit cell size.
314 : bool mbJustLastLine; /// True = justify last line in block text.
315 :
316 : explicit AlignmentModel();
317 :
318 : /** Sets horizontal alignment from the passed BIFF data. */
319 : void setBiffHorAlign( sal_uInt8 nHorAlign );
320 : /** Sets vertical alignment from the passed BIFF data. */
321 : void setBiffVerAlign( sal_uInt8 nVerAlign );
322 : };
323 :
324 : // ----------------------------------------------------------------------------
325 :
326 : /** Contains all API cell alignment attributes. */
327 : struct ApiAlignmentData
328 : {
329 : typedef ::com::sun::star::table::CellHoriJustify ApiCellHoriJustify;
330 : typedef ::com::sun::star::table::CellOrientation ApiCellOrientation;
331 :
332 : ApiCellHoriJustify meHorJustify; /// Horizontal alignment.
333 : sal_Int32 mnHorJustifyMethod;
334 : sal_Int32 mnVerJustify; /// Vertical alignment.
335 : sal_Int32 mnVerJustifyMethod;
336 : ApiCellOrientation meOrientation; /// Normal or stacked text.
337 : sal_Int32 mnRotation; /// Text rotation angle.
338 : sal_Int16 mnWritingMode; /// CTL text direction.
339 : sal_Int16 mnIndent; /// Indentation.
340 : bool mbWrapText; /// True = multi-line text.
341 : bool mbShrink; /// True = shrink to fit cell size.
342 :
343 : explicit ApiAlignmentData();
344 : };
345 :
346 : bool operator==( const ApiAlignmentData& rLeft, const ApiAlignmentData& rRight );
347 :
348 : // ============================================================================
349 :
350 186 : class Alignment : public WorkbookHelper
351 : {
352 : public:
353 : explicit Alignment( const WorkbookHelper& rHelper );
354 :
355 : /** Sets all attributes from the alignment element. */
356 : void importAlignment( const AttributeList& rAttribs );
357 :
358 : /** Sets the alignment attributes from the passed BIFF12 XF record data. */
359 : void setBiff12Data( sal_uInt32 nFlags );
360 :
361 : /** Final processing after import of all style settings. */
362 : void finalizeImport();
363 :
364 : /** Returns the alignment model structure. */
365 328 : inline const AlignmentModel& getModel() const { return maModel; }
366 : /** Returns the converted API alignment data struct. */
367 131 : inline const ApiAlignmentData& getApiData() const { return maApiData; }
368 :
369 : void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
370 : /** Writes all alignment attributes to the passed property map. */
371 : void writeToPropertyMap( PropertyMap& rPropMap ) const;
372 :
373 : private:
374 : ::SvxCellHorJustify GetScHorAlign() const;
375 : ::SvxCellVerJustify GetScVerAlign() const;
376 : ::SvxFrameDirection GetScFrameDir() const;
377 : AlignmentModel maModel; /// Alignment model data.
378 : ApiAlignmentData maApiData; /// Alignment data converted to API constants.
379 : };
380 :
381 : typedef ::boost::shared_ptr< Alignment > AlignmentRef;
382 :
383 : // ============================================================================
384 :
385 : /** Contains all XML cell protection attributes, e.g. from a protection element. */
386 : struct ProtectionModel
387 : {
388 : bool mbLocked; /// True = locked against editing.
389 : bool mbHidden; /// True = formula is hidden.
390 :
391 : explicit ProtectionModel();
392 : };
393 :
394 : // ----------------------------------------------------------------------------
395 :
396 : /** Contains all API cell protection attributes. */
397 : struct ApiProtectionData
398 : {
399 : typedef ::com::sun::star::util::CellProtection ApiCellProtection;
400 :
401 : ApiCellProtection maCellProt;
402 :
403 : explicit ApiProtectionData();
404 : };
405 :
406 : bool operator==( const ApiProtectionData& rLeft, const ApiProtectionData& rRight );
407 :
408 : // ============================================================================
409 :
410 186 : class Protection : public WorkbookHelper
411 : {
412 : public:
413 : explicit Protection( const WorkbookHelper& rHelper );
414 :
415 : /** Sets all attributes from the protection element. */
416 : void importProtection( const AttributeList& rAttribs );
417 :
418 : /** Sets the protection attributes from the passed BIFF12 XF record data. */
419 : void setBiff12Data( sal_uInt32 nFlags );
420 :
421 : /** Final processing after import of all style settings. */
422 : void finalizeImport();
423 :
424 : /** Returns the protection model structure. */
425 : inline const ProtectionModel& getModel() const { return maModel; }
426 : /** Returns the converted API protection data struct. */
427 74 : inline const ApiProtectionData& getApiData() const { return maApiData; }
428 :
429 : /** Writes all protection attributes to the passed property map. */
430 : void writeToPropertyMap( PropertyMap& rPropMap ) const;
431 : void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
432 : private:
433 : ProtectionModel maModel; /// Protection model data.
434 : ApiProtectionData maApiData; /// Protection data converted to API constants.
435 : };
436 :
437 : typedef ::boost::shared_ptr< Protection > ProtectionRef;
438 :
439 : // ============================================================================
440 :
441 : /** Contains XML attributes of a single border line. */
442 55 : struct BorderLineModel
443 : {
444 : Color maColor; /// Borderline color.
445 : sal_Int32 mnStyle; /// Border line style.
446 : bool mbUsed; /// True = line format used.
447 :
448 : explicit BorderLineModel( bool bDxf );
449 :
450 : /** Sets the passed BIFF line style. */
451 : void setBiffStyle( sal_Int32 nLineStyle );
452 : };
453 :
454 : // ----------------------------------------------------------------------------
455 :
456 : /** Contains XML attributes of a complete cell border. */
457 11 : struct BorderModel
458 : {
459 : BorderLineModel maLeft; /// Left line format.
460 : BorderLineModel maRight; /// Right line format.
461 : BorderLineModel maTop; /// Top line format.
462 : BorderLineModel maBottom; /// Bottom line format.
463 : BorderLineModel maDiagonal; /// Diagonal line format.
464 : bool mbDiagTLtoBR; /// True = top-left to bottom-right on.
465 : bool mbDiagBLtoTR; /// True = bottom-left to top-right on.
466 :
467 : explicit BorderModel( bool bDxf );
468 : };
469 :
470 : // ----------------------------------------------------------------------------
471 :
472 : /** Contains API attributes of a complete cell border. */
473 : struct ApiBorderData
474 : {
475 : typedef ::com::sun::star::table::BorderLine2 ApiBorderLine;
476 :
477 : ApiBorderLine maLeft; /// Left line format
478 : ApiBorderLine maRight; /// Right line format
479 : ApiBorderLine maTop; /// Top line format
480 : ApiBorderLine maBottom; /// Bottom line format
481 : ApiBorderLine maTLtoBR; /// Diagonal top-left to bottom-right line format.
482 : ApiBorderLine maBLtoTR; /// Diagonal bottom-left to top-right line format.
483 : bool mbBorderUsed; /// True = left/right/top/bottom line format used.
484 : bool mbDiagUsed; /// True = diagonal line format used.
485 :
486 : explicit ApiBorderData();
487 :
488 : /** Returns true, if any of the outer border lines is visible. */
489 : bool hasAnyOuterBorder() const;
490 : };
491 :
492 : bool operator==( const ApiBorderData& rLeft, const ApiBorderData& rRight );
493 :
494 : // ============================================================================
495 :
496 22 : class Border : public WorkbookHelper
497 : {
498 : public:
499 : explicit Border( const WorkbookHelper& rHelper, bool bDxf );
500 :
501 : /** Sets global border attributes from the border element. */
502 : void importBorder( const AttributeList& rAttribs );
503 : /** Sets border attributes for the border line with the passed element identifier. */
504 : void importStyle( sal_Int32 nElement, const AttributeList& rAttribs );
505 : /** Sets color attributes for the border line with the passed element identifier. */
506 : void importColor( sal_Int32 nElement, const AttributeList& rAttribs );
507 :
508 : /** Imports the BORDER record from the passed stream. */
509 : void importBorder( SequenceInputStream& rStrm );
510 : /** Imports a border from a DXF record from the passed stream. */
511 : void importDxfBorder( sal_Int32 nElement, SequenceInputStream& rStrm );
512 :
513 : /** Final processing after import of all style settings. */
514 : void finalizeImport();
515 :
516 : /** Returns the border model structure. */
517 : inline const BorderModel& getModel() const { return maModel; }
518 : /** Returns the converted API border data struct. */
519 1 : inline const ApiBorderData& getApiData() const { return maApiData; }
520 :
521 : void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const;
522 :
523 : /** Writes all border attributes to the passed property map. */
524 : void writeToPropertyMap( PropertyMap& rPropMap ) const;
525 :
526 : bool hasBorder() const;
527 :
528 : private:
529 : /** Returns the border line struct specified by the passed XML token identifier. */
530 : BorderLineModel* getBorderLine( sal_Int32 nElement );
531 :
532 : /** Converts border line data to an API struct, returns true, if the line is marked as used. */
533 : bool convertBorderLine(
534 : ::com::sun::star::table::BorderLine2& rBorderLine,
535 : const BorderLineModel& rModel );
536 :
537 : private:
538 : BorderModel maModel;
539 : ApiBorderData maApiData;
540 : bool mbDxf;
541 : };
542 :
543 : typedef ::boost::shared_ptr< Border > BorderRef;
544 :
545 : // ============================================================================
546 :
547 : /** Contains XML pattern fill attributes from the patternFill element. */
548 44 : struct PatternFillModel
549 : {
550 : Color maPatternColor; /// Pattern foreground color.
551 : Color maFillColor; /// Background fill color.
552 : sal_Int32 mnPattern; /// Pattern identifier (e.g. solid).
553 : bool mbPattColorUsed; /// True = pattern foreground color used.
554 : bool mbFillColorUsed; /// True = background fill color used.
555 : bool mbPatternUsed; /// True = pattern used.
556 :
557 : explicit PatternFillModel( bool bDxf );
558 :
559 : /** Sets the passed BIFF pattern identifier. */
560 : void setBiffPattern( sal_Int32 nPattern );
561 : };
562 :
563 : // ----------------------------------------------------------------------------
564 :
565 : /** Contains XML gradient fill attributes from the gradientFill element. */
566 0 : struct GradientFillModel
567 : {
568 : typedef ::std::map< double, Color > ColorMap;
569 :
570 : sal_Int32 mnType; /// Gradient type, linear or path.
571 : double mfAngle; /// Rotation angle for type linear.
572 : double mfLeft; /// Left convergence for type path.
573 : double mfRight; /// Right convergence for type path.
574 : double mfTop; /// Top convergence for type path.
575 : double mfBottom; /// Bottom convergence for type path.
576 : ColorMap maColors; /// Gradient colors.
577 :
578 : explicit GradientFillModel();
579 :
580 : /** Reads BIFF12 gradient settings from a FILL or DXF record. */
581 : void readGradient( SequenceInputStream& rStrm );
582 : /** Reads BIFF12 gradient stop settings from a FILL or DXF record. */
583 : void readGradientStop( SequenceInputStream& rStrm, bool bDxf );
584 : };
585 :
586 : // ----------------------------------------------------------------------------
587 :
588 : /** Contains API fill attributes. */
589 : struct ApiSolidFillData
590 : {
591 : sal_Int32 mnColor; /// Fill color.
592 : bool mbTransparent; /// True = transparent area.
593 : bool mbUsed; /// True = fill data is valid.
594 :
595 : explicit ApiSolidFillData();
596 : };
597 :
598 : bool operator==( const ApiSolidFillData& rLeft, const ApiSolidFillData& rRight );
599 :
600 : // ============================================================================
601 :
602 : /** Contains cell fill attributes, either a pattern fill or a gradient fill. */
603 88 : class Fill : public WorkbookHelper
604 : {
605 : public:
606 : explicit Fill( const WorkbookHelper& rHelper, bool bDxf );
607 :
608 : /** Sets attributes of a patternFill element. */
609 : void importPatternFill( const AttributeList& rAttribs );
610 : /** Sets the pattern color from the fgColor element. */
611 : void importFgColor( const AttributeList& rAttribs );
612 : /** Sets the background color from the bgColor element. */
613 : void importBgColor( const AttributeList& rAttribs );
614 : /** Sets attributes of a gradientFill element. */
615 : void importGradientFill( const AttributeList& rAttribs );
616 : /** Sets a color from the color element in a gradient fill. */
617 : void importColor( const AttributeList& rAttribs, double fPosition );
618 :
619 : /** Imports the FILL record from the passed stream. */
620 : void importFill( SequenceInputStream& rStrm );
621 : /** Imports the fill pattern from a DXF record. */
622 : void importDxfPattern( SequenceInputStream& rStrm );
623 : /** Imports the pattern color from a DXF record. */
624 : void importDxfFgColor( SequenceInputStream& rStrm );
625 : /** Imports the background color from a DXF record. */
626 : void importDxfBgColor( SequenceInputStream& rStrm );
627 : /** Imports gradient settings from a DXF record. */
628 : void importDxfGradient( SequenceInputStream& rStrm );
629 : /** Imports gradient stop settings from a DXF record. */
630 : void importDxfStop( SequenceInputStream& rStrm );
631 :
632 : /** Final processing after import of all style settings. */
633 : void finalizeImport();
634 :
635 : /** Returns the fill pattern model structure, if extant. */
636 : inline const PatternFillModel* getPatternModel() const { return mxPatternModel.get(); }
637 : /** Returns the fill gradient model structure, if extant. */
638 : inline const GradientFillModel* getGradientModel() const { return mxGradientModel.get(); }
639 : /** Returns the converted API fill data struct. */
640 0 : inline const ApiSolidFillData& getApiData() const { return maApiData; }
641 :
642 : void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const;
643 : /** Writes all fill attributes to the passed property map. */
644 : void writeToPropertyMap( PropertyMap& rPropMap ) const;
645 :
646 : private:
647 : typedef ::boost::shared_ptr< PatternFillModel > PatternModelRef;
648 : typedef ::boost::shared_ptr< GradientFillModel > GradientModelRef;
649 :
650 : PatternModelRef mxPatternModel;
651 : GradientModelRef mxGradientModel;
652 : ApiSolidFillData maApiData;
653 : bool mbDxf;
654 : };
655 :
656 : typedef ::boost::shared_ptr< Fill > FillRef;
657 :
658 : // ============================================================================
659 :
660 : /** Contains all data for a cell format or cell style. */
661 : struct XfModel
662 : {
663 : sal_Int32 mnStyleXfId; /// Index to parent style XF.
664 : sal_Int32 mnFontId; /// Index to font data list.
665 : sal_Int32 mnNumFmtId; /// Index to number format list.
666 : sal_Int32 mnBorderId; /// Index to list of cell borders.
667 : sal_Int32 mnFillId; /// Index to list of cell areas.
668 : bool mbCellXf; /// True = cell XF, false = style XF.
669 : bool mbFontUsed; /// True = font index used.
670 : bool mbNumFmtUsed; /// True = number format used.
671 : bool mbAlignUsed; /// True = alignment used.
672 : bool mbProtUsed; /// True = cell protection used.
673 : bool mbBorderUsed; /// True = border data used.
674 : bool mbAreaUsed; /// True = area data used.
675 :
676 : explicit XfModel();
677 : };
678 :
679 : bool operator==( const XfModel& rXfModel1, const XfModel& rXfModel2 );
680 :
681 : // ============================================================================
682 :
683 : /** Represents a cell format or a cell style (called XF, extended format).
684 :
685 : This class stores the type (cell/style), the index to the parent style (if
686 : it is a cell format) and all "attribute used" flags, which reflect the
687 : state of specific attribute groups (true = user has changed the attributes)
688 : and all formatting data.
689 : */
690 372 : class Xf : public WorkbookHelper
691 : {
692 : friend bool operator==( const Xf& rXf1, const Xf& rXf2 );
693 : public:
694 : explicit Xf( const WorkbookHelper& rHelper );
695 :
696 : /** Sets all attributes from the xf element. */
697 : void importXf( const AttributeList& rAttribs, bool bCellXf );
698 : /** Sets all attributes from the alignment element. */
699 : void importAlignment( const AttributeList& rAttribs );
700 : /** Sets all attributes from the protection element. */
701 : void importProtection( const AttributeList& rAttribs );
702 :
703 : /** Imports the XF record from the passed stream. */
704 : void importXf( SequenceInputStream& rStrm, bool bCellXf );
705 :
706 : /** Final processing after import of all style settings. */
707 : void finalizeImport();
708 :
709 : /** Returns true, if the XF is a cell XF, and false, if it is a style XF. */
710 263 : inline bool isCellXf() const { return maModel.mbCellXf; }
711 :
712 : /** Returns the referred font object. */
713 : FontRef getFont() const;
714 : /** Returns the alignment data of this style. */
715 328 : inline const Alignment& getAlignment() const { return maAlignment; }
716 : /** Returns the cell protection data of this style. */
717 : inline const Protection& getProtection() const { return maProtection; }
718 :
719 : void writeToMarkData( ::ScMarkData& rMarkData, sal_Int32 nNumFmtId );
720 : /** Writes all formatting attributes to the passed property map. */
721 : void writeToPropertyMap( PropertyMap& rPropMap ) const;
722 : /** Writes all formatting attributes to the passed property set. */
723 : void writeToPropertySet( PropertySet& rPropSet ) const;
724 :
725 : const ::ScPatternAttr& createPattern( bool bSkipPoolDefs = false );
726 :
727 : private:
728 : typedef ::std::auto_ptr< ::ScPatternAttr > ScPatternAttrPtr;
729 :
730 : ScPatternAttrPtr mpPattern; /// Calc item set.
731 :
732 : XfModel maModel; /// Cell XF or style XF model data.
733 : Alignment maAlignment; /// Cell alignment data.
734 : Protection maProtection; /// Cell protection data.
735 : sal_Int32 meRotationRef; /// Rotation reference dependent on border.
736 : ::ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
737 : };
738 :
739 : bool operator==( const Xf& rXf1, const Xf& rXf2 );
740 :
741 : typedef ::boost::shared_ptr< Xf > XfRef;
742 :
743 : // ============================================================================
744 :
745 140 : class Dxf : public WorkbookHelper
746 : {
747 : public:
748 : explicit Dxf( const WorkbookHelper& rHelper );
749 :
750 : /** Creates a new empty font object. */
751 : FontRef createFont( bool bAlwaysNew = true );
752 : /** Creates a new empty border object. */
753 : BorderRef createBorder( bool bAlwaysNew = true );
754 : /** Creates a new empty fill object. */
755 : FillRef createFill( bool bAlwaysNew = true );
756 :
757 : /** Inserts a new number format code. */
758 : void importNumFmt( const AttributeList& rAttribs );
759 :
760 : /** Imports the DXF record from the passed stream. */
761 : void importDxf( SequenceInputStream& rStrm );
762 :
763 : /** Final processing after import of all style settings. */
764 : void finalizeImport();
765 :
766 : /** Writes all formatting attributes to the passed property map. */
767 : void writeToPropertyMap( PropertyMap& rPropMap ) const;
768 : /** Writes all formatting attributes to the passed property set. */
769 : void writeToPropertySet( PropertySet& rPropSet ) const;
770 :
771 : private:
772 : FontRef mxFont; /// Font data.
773 : NumberFormatRef mxNumFmt; /// Number format data.
774 : AlignmentRef mxAlignment; /// Alignment data.
775 : ProtectionRef mxProtection; /// Protection data.
776 : BorderRef mxBorder; /// Border data.
777 : FillRef mxFill; /// Fill data.
778 : };
779 :
780 : typedef ::boost::shared_ptr< Dxf > DxfRef;
781 :
782 : // ============================================================================
783 :
784 : /** Contains attributes of a cell style, e.g. from the cellStyle element. */
785 51 : struct CellStyleModel
786 : {
787 : ::rtl::OUString maName; /// Cell style name.
788 : sal_Int32 mnXfId; /// Formatting for this cell style.
789 : sal_Int32 mnBuiltinId; /// Identifier for builtin styles.
790 : sal_Int32 mnLevel; /// Level for builtin column/row styles.
791 : bool mbBuiltin; /// True = builtin style.
792 : bool mbCustom; /// True = customized builtin style.
793 : bool mbHidden; /// True = style not visible in GUI.
794 :
795 : explicit CellStyleModel();
796 :
797 : /** Returns true, if this style is a builtin style. */
798 : bool isBuiltin() const;
799 : /** Returns true, if this style represents the default document cell style. */
800 : bool isDefaultStyle() const;
801 : };
802 :
803 : // ============================================================================
804 :
805 102 : class CellStyle : public WorkbookHelper
806 : {
807 : public:
808 : explicit CellStyle( const WorkbookHelper& rHelper );
809 :
810 : /** Imports passed attributes from the cellStyle element. */
811 : void importCellStyle( const AttributeList& rAttribs );
812 : /** Imports style settings from a CELLSTYLE record. */
813 : void importCellStyle( SequenceInputStream& rStrm );
814 :
815 : /** Creates the style sheet in the document described by this cell style object. */
816 : void createCellStyle();
817 : /** Stores tha passed final style name and creates the cell style, if it is
818 : user-defined or modified built-in. */
819 : void finalizeImport( const ::rtl::OUString& rFinalName );
820 :
821 : /** Returns the cell style model structure. */
822 166 : inline const CellStyleModel& getModel() const { return maModel; }
823 : /** Returns the final style name used in the document. */
824 91 : inline const ::rtl::OUString& getFinalStyleName() const { return maFinalName; }
825 37 : inline ::ScStyleSheet* getStyleSheet() { return mpStyleSheet; }
826 : private:
827 : CellStyleModel maModel;
828 : ::rtl::OUString maFinalName; /// Final style name used in API.
829 : bool mbCreated; /// True = style sheet created.
830 : ::ScStyleSheet* mpStyleSheet; /// Calc cell style sheet.
831 :
832 : };
833 :
834 : typedef ::boost::shared_ptr< CellStyle > CellStyleRef;
835 :
836 : // ============================================================================
837 :
838 11 : class CellStyleBuffer : public WorkbookHelper
839 : {
840 : public:
841 : explicit CellStyleBuffer( const WorkbookHelper& rHelper );
842 :
843 : /** Appends and returns a new named cell style object. */
844 : CellStyleRef importCellStyle( const AttributeList& rAttribs );
845 : /** Imports the CELLSTYLE record from the passed stream. */
846 : CellStyleRef importCellStyle( SequenceInputStream& rStrm );
847 :
848 : /** Final processing after import of all style settings. */
849 : void finalizeImport();
850 :
851 : /** Returns the XF identifier associated to the default cell style. */
852 : sal_Int32 getDefaultXfId() const;
853 : /** Returns the default style sheet for unused cells. */
854 : ::rtl::OUString getDefaultStyleName() const;
855 : /** Creates the style sheet described by the style XF with the passed identifier. */
856 : ::rtl::OUString createCellStyle( sal_Int32 nXfId ) const;
857 : ::ScStyleSheet* getCellStyleSheet( sal_Int32 nXfId ) const;
858 :
859 : private:
860 : /** Inserts the passed cell style object into the internal maps. */
861 : void insertCellStyle( CellStyleRef xCellStyle );
862 : /** Creates the style sheet described by the passed cell style object. */
863 : ::rtl::OUString createCellStyle( const CellStyleRef& rxCellStyle ) const;
864 : ::ScStyleSheet* getCellStyleSheet( const CellStyleRef& rxCellStyle ) const;
865 :
866 : private:
867 : typedef RefVector< CellStyle > CellStyleVector;
868 : typedef RefMap< sal_Int32, CellStyle > CellStyleXfIdMap;
869 :
870 : CellStyleVector maBuiltinStyles; /// All built-in cell styles.
871 : CellStyleVector maUserStyles; /// All user defined cell styles.
872 : CellStyleXfIdMap maStylesByXf; /// All cell styles, mapped by XF identifier.
873 : CellStyleRef mxDefStyle; /// Default cell style.
874 : };
875 :
876 : // ============================================================================
877 :
878 : struct AutoFormatModel
879 : {
880 : sal_Int32 mnAutoFormatId; /// Index of predefined autoformatting.
881 : bool mbApplyNumFmt; /// True = apply number format from autoformatting.
882 : bool mbApplyFont; /// True = apply font from autoformatting.
883 : bool mbApplyAlignment; /// True = apply alignment from autoformatting.
884 : bool mbApplyBorder; /// True = apply border from autoformatting.
885 : bool mbApplyFill; /// True = apply fill from autoformatting.
886 : bool mbApplyProtection; /// True = apply protection from autoformatting.
887 :
888 : explicit AutoFormatModel();
889 : };
890 :
891 : // ============================================================================
892 :
893 22 : class StylesBuffer : public WorkbookHelper
894 : {
895 : public:
896 : explicit StylesBuffer( const WorkbookHelper& rHelper );
897 :
898 : /** Creates a new empty font object.
899 : @param opnFontId (out-param) The identifier of the new font object. */
900 : FontRef createFont( sal_Int32* opnFontId = 0 );
901 : /** Creates a number format. */
902 : NumberFormatRef createNumFmt( sal_Int32 nNumFmtId, const ::rtl::OUString& rFmtCode );
903 : sal_Int32 nextFreeNumFmtId();
904 : /** Creates a new empty border object.
905 : @param opnBorderId (out-param) The identifier of the new border object. */
906 : BorderRef createBorder( sal_Int32* opnBorderId = 0 );
907 : /** Creates a new empty fill object.
908 : @param opnFillId (out-param) The identifier of the new fill object. */
909 : FillRef createFill( sal_Int32* opnFillId = 0 );
910 : /** Creates a new empty cell formatting object.
911 : @param opnXfId (out-param) The identifier of the new XF object. */
912 : XfRef createCellXf( sal_Int32* opnXfId = 0 );
913 : /** Creates a new empty style formatting object.
914 : @param opnXfId (out-param) The identifier of the new XF object. */
915 : XfRef createStyleXf( sal_Int32* opnXfId = 0 );
916 : /** Creates a new empty differential formatting object.
917 : @param opnDxfId (out-param) The identifier of the new DXF object. */
918 : DxfRef createDxf( sal_Int32* opnDxfId = 0 );
919 :
920 : /** Appends a new color to the color palette. */
921 : void importPaletteColor( const AttributeList& rAttribs );
922 : /** Inserts a new number format code. */
923 : NumberFormatRef importNumFmt( const AttributeList& rAttribs );
924 : /** Appends and returns a new named cell style object. */
925 : CellStyleRef importCellStyle( const AttributeList& rAttribs );
926 :
927 : /** Appends a new color to the color palette. */
928 : void importPaletteColor( SequenceInputStream& rStrm );
929 : /** Imports the NUMFMT record from the passed stream. */
930 : void importNumFmt( SequenceInputStream& rStrm );
931 : /** Imports the CELLSTYLE record from the passed stream. */
932 : void importCellStyle( SequenceInputStream& rStrm );
933 :
934 : /** Final processing after import of all style settings. */
935 : void finalizeImport();
936 :
937 : /** Returns the palette color with the specified index. */
938 : sal_Int32 getPaletteColor( sal_Int32 nIndex ) const;
939 : /** Returns the specified font object. */
940 : FontRef getFont( sal_Int32 nFontId ) const;
941 : /** Returns the specified border object. */
942 : BorderRef getBorder( sal_Int32 nBorderId ) const;
943 : /** Returns the specified cell format object. */
944 : XfRef getCellXf( sal_Int32 nXfId ) const;
945 : /** Returns the specified style format object. */
946 : XfRef getStyleXf( sal_Int32 nXfId ) const;
947 :
948 : /** Returns the font object of the specified cell XF. */
949 : FontRef getFontFromCellXf( sal_Int32 nXfId ) const;
950 : /** Returns the default application font (used in the "Normal" cell style). */
951 : FontRef getDefaultFont() const;
952 : /** Returns the model of the default application font (used in the "Normal" cell style). */
953 : const FontModel& getDefaultFontModel() const;
954 :
955 : /** Returns true, if the specified borders are equal. */
956 : bool equalBorders( sal_Int32 nBorderId1, sal_Int32 nBorderId2 ) const;
957 : /** Returns true, if the specified fills are equal. */
958 : bool equalFills( sal_Int32 nFillId1, sal_Int32 nFillId2 ) const;
959 :
960 : /** Returns the default style sheet for unused cells. */
961 : ::rtl::OUString getDefaultStyleName() const;
962 : /** Creates the style sheet described by the style XF with the passed identifier. */
963 : ::rtl::OUString createCellStyle( sal_Int32 nXfId ) const;
964 : ::ScStyleSheet* getCellStyleSheet( sal_Int32 nXfId ) const;
965 : /** Creates the style sheet described by the DXF with the passed identifier. */
966 : ::rtl::OUString createDxfStyle( sal_Int32 nDxfId ) const;
967 :
968 : void writeFontToItemSet( SfxItemSet& rItemSet, sal_Int32 nFontId, bool bSkipPoolDefs = false ) const;
969 : /** Writes the font attributes of the specified font data to the passed property map. */
970 : void writeFontToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFontId ) const;
971 : void writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs = false ) const;
972 : /** Writes the specified number format to the passed property map. */
973 : void writeNumFmtToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const;
974 : void writeBorderToItemSet( SfxItemSet& rItemSet, sal_Int32 nBorderId, bool bSkipPoolDefs = false ) const;
975 : /** Writes the border attributes of the specified border data to the passed property map. */
976 : void writeBorderToPropertyMap( PropertyMap& rPropMap, sal_Int32 nBorderId ) const;
977 : /** Writes the fill attributes of the specified fill data to the passed property map. */
978 : void writeFillToItemSet( SfxItemSet& rItemSet, sal_Int32 nFillId, bool bSkipPoolDefs = false ) const;
979 : void writeFillToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFillId ) const;
980 : void writeCellXfToMarkData( ::ScMarkData& rMark, sal_Int32 nXfId, sal_Int32 nNumFmtId );
981 :
982 : /** Writes the cell formatting attributes of the specified XF to the passed property set. */
983 : void writeCellXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const;
984 : /** Writes the cell formatting attributes of the specified style XF to the passed property set. */
985 : void writeStyleXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const;
986 :
987 : bool hasBorder( sal_Int32 nBorderId ) const;
988 : private:
989 : typedef RefVector< Font > FontVector;
990 : typedef RefVector< Border > BorderVector;
991 : typedef RefVector< Fill > FillVector;
992 : typedef RefVector< Xf > XfVector;
993 : typedef RefVector< Dxf > DxfVector;
994 : typedef ::std::map< sal_Int32, ::rtl::OUString > DxfStyleMap;
995 :
996 : ColorPalette maPalette; /// Color palette.
997 : FontVector maFonts; /// List of font objects.
998 : NumberFormatsBuffer maNumFmts; /// List of all number format codes.
999 : BorderVector maBorders; /// List of cell border objects.
1000 : FillVector maFills; /// List of cell area fill objects.
1001 : XfVector maCellXfs; /// List of cell formats.
1002 : XfVector maStyleXfs; /// List of cell styles.
1003 : CellStyleBuffer maCellStyles; /// All built-in and user defined cell styles.
1004 : DxfVector maDxfs; /// List of differential cell styles.
1005 : mutable DxfStyleMap maDxfStyles; /// Maps DXF identifiers to Calc style sheet names.
1006 : };
1007 :
1008 : // ============================================================================
1009 :
1010 : } // namespace xls
1011 : } // namespace oox
1012 :
1013 : #endif
1014 :
1015 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|