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