2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * $RCSfile: stylesbuffer.cxx,v $
11 * $Revision: 1.5.20.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "oox/xls/stylesbuffer.hxx"
33 #include <com/sun/star/container/XIndexAccess.hpp>
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/awt/FontDescriptor.hpp>
36 #include <com/sun/star/awt/FontFamily.hpp>
37 #include <com/sun/star/awt/FontPitch.hpp>
38 #include <com/sun/star/awt/FontSlant.hpp>
39 #include <com/sun/star/awt/FontStrikeout.hpp>
40 #include <com/sun/star/awt/FontType.hpp>
41 #include <com/sun/star/awt/FontWeight.hpp>
42 #include <com/sun/star/awt/FontUnderline.hpp>
43 #include <com/sun/star/awt/XDevice.hpp>
44 #include <com/sun/star/awt/XFont2.hpp>
45 #include <com/sun/star/style/XStyle.hpp>
46 #include <com/sun/star/text/WritingMode2.hpp>
47 #include <com/sun/star/text/XText.hpp>
48 #include <rtl/tencinfo.h>
49 #include <rtl/ustrbuf.hxx>
50 #include "properties.hxx"
51 #include "oox/helper/attributelist.hxx"
52 #include "oox/helper/propertymap.hxx"
53 #include "oox/helper/propertyset.hxx"
54 #include "oox/helper/recordinputstream.hxx"
55 #include "oox/core/filterbase.hxx"
56 #include "oox/xls/biffinputstream.hxx"
57 #include "oox/xls/condformatbuffer.hxx"
58 #include "oox/xls/excelhandlers.hxx"
59 #include "oox/xls/themebuffer.hxx"
60 #include "oox/xls/unitconverter.hxx"
62 using ::rtl::OUString
;
63 using ::rtl::OUStringBuffer
;
64 using ::com::sun::star::uno::Exception
;
65 using ::com::sun::star::uno::Reference
;
66 using ::com::sun::star::uno::UNO_QUERY
;
67 using ::com::sun::star::uno::UNO_QUERY_THROW
;
68 using ::com::sun::star::uno::UNO_SET_THROW
;
69 using ::com::sun::star::container::XIndexAccess
;
70 using ::com::sun::star::container::XNameAccess
;
71 using ::com::sun::star::container::XNamed
;
72 using ::com::sun::star::awt::FontDescriptor
;
73 using ::com::sun::star::awt::XDevice
;
74 using ::com::sun::star::awt::XFont2
;
75 using ::com::sun::star::table::BorderLine
;
76 using ::com::sun::star::text::XText
;
77 using ::com::sun::star::style::XStyle
;
78 using ::oox::core::FilterBase
;
83 // ============================================================================
87 // OOXML constants ------------------------------------------------------------
89 // OOX predefined color indexes (also used in BIFF3-BIFF8)
90 const sal_Int32 OOX_COLOR_USEROFFSET
= 0; /// First user defined color in palette (OOX).
91 const sal_Int32 BIFF_COLOR_USEROFFSET
= 8; /// First user defined color in palette (BIFF).
93 // OOX font family (also used in BIFF)
94 const sal_Int32 OOX_FONTFAMILY_NONE
= 0;
95 const sal_Int32 OOX_FONTFAMILY_ROMAN
= 1;
96 const sal_Int32 OOX_FONTFAMILY_SWISS
= 2;
97 const sal_Int32 OOX_FONTFAMILY_MODERN
= 3;
98 const sal_Int32 OOX_FONTFAMILY_SCRIPT
= 4;
99 const sal_Int32 OOX_FONTFAMILY_DECORATIVE
= 5;
101 // OOX font charset (also used in BIFF)
102 const sal_Int32 OOX_FONTCHARSET_UNUSED
= -1;
103 const sal_Int32 OOX_FONTCHARSET_ANSI
= 0;
105 // OOX cell text direction (also used in BIFF)
106 const sal_Int32 OOX_XF_TEXTDIR_CONTEXT
= 0;
107 const sal_Int32 OOX_XF_TEXTDIR_LTR
= 1;
108 const sal_Int32 OOX_XF_TEXTDIR_RTL
= 2;
110 // OOX cell rotation (also used in BIFF)
111 const sal_Int32 OOX_XF_ROTATION_NONE
= 0;
112 const sal_Int32 OOX_XF_ROTATION_90CCW
= 90;
113 const sal_Int32 OOX_XF_ROTATION_90CW
= 180;
114 const sal_Int32 OOX_XF_ROTATION_STACKED
= 255;
116 // OOX cell indentation
117 const sal_Int32 OOX_XF_INDENT_NONE
= 0;
119 // OOX built-in cell styles (also used in BIFF)
120 const sal_Int32 OOX_STYLE_NORMAL
= 0; /// Default cell style.
121 const sal_Int32 OOX_STYLE_ROWLEVEL
= 1; /// RowLevel_x cell style.
122 const sal_Int32 OOX_STYLE_COLLEVEL
= 2; /// ColLevel_x cell style.
124 const sal_Int32 OOX_STYLE_LEVELCOUNT
= 7; /// Number of outline level styles.
126 // OOBIN constants ------------------------------------------------------------
129 const sal_uInt8 OOBIN_COLOR_AUTO
= 0;
130 const sal_uInt8 OOBIN_COLOR_INDEXED
= 1;
131 const sal_uInt8 OOBIN_COLOR_RGB
= 2;
132 const sal_uInt8 OOBIN_COLOR_THEME
= 3;
134 // OOBIN diagonal borders
135 const sal_uInt8 OOBIN_BORDER_DIAG_TLBR
= 0x01; /// Top-left to bottom-right.
136 const sal_uInt8 OOBIN_BORDER_DIAG_BLTR
= 0x02; /// Bottom-left to top-right.
138 // OOBIN gradient fill
139 const sal_Int32 OOBIN_FILL_GRADIENT
= 40;
142 const sal_uInt32 OOBIN_XF_WRAPTEXT
= 0x00400000;
143 const sal_uInt32 OOBIN_XF_JUSTLASTLINE
= 0x00800000;
144 const sal_uInt32 OOBIN_XF_SHRINK
= 0x01000000;
145 const sal_uInt32 OOBIN_XF_LOCKED
= 0x10000000;
146 const sal_uInt32 OOBIN_XF_HIDDEN
= 0x20000000;
148 // OOBIN XF attribute used flags
149 const sal_uInt16 OOBIN_XF_NUMFMT_USED
= 0x0001;
150 const sal_uInt16 OOBIN_XF_FONT_USED
= 0x0002;
151 const sal_uInt16 OOBIN_XF_ALIGN_USED
= 0x0004;
152 const sal_uInt16 OOBIN_XF_BORDER_USED
= 0x0008;
153 const sal_uInt16 OOBIN_XF_AREA_USED
= 0x0010;
154 const sal_uInt16 OOBIN_XF_PROT_USED
= 0x0020;
156 // OOBIN DXF constants
157 const sal_uInt16 OOBIN_DXF_FILL_PATTERN
= 0;
158 const sal_uInt16 OOBIN_DXF_FILL_FGCOLOR
= 1;
159 const sal_uInt16 OOBIN_DXF_FILL_BGCOLOR
= 2;
160 const sal_uInt16 OOBIN_DXF_FILL_GRADIENT
= 3;
161 const sal_uInt16 OOBIN_DXF_FILL_STOP
= 4;
162 const sal_uInt16 OOBIN_DXF_FONT_COLOR
= 5;
163 const sal_uInt16 OOBIN_DXF_BORDER_TOP
= 6;
164 const sal_uInt16 OOBIN_DXF_BORDER_BOTTOM
= 7;
165 const sal_uInt16 OOBIN_DXF_BORDER_LEFT
= 8;
166 const sal_uInt16 OOBIN_DXF_BORDER_RIGHT
= 9;
167 const sal_uInt16 OOBIN_DXF_BORDER_DIAG
= 10;
168 const sal_uInt16 OOBIN_DXF_BORDER_VERT
= 11;
169 const sal_uInt16 OOBIN_DXF_BORDER_HOR
= 12;
170 const sal_uInt16 OOBIN_DXF_BORDER_DIAGUP
= 13;
171 const sal_uInt16 OOBIN_DXF_BORDER_DIAGDOWN
= 14;
172 const sal_uInt16 OOBIN_DXF_FONT_NAME
= 24;
173 const sal_uInt16 OOBIN_DXF_FONT_WEIGHT
= 25;
174 const sal_uInt16 OOBIN_DXF_FONT_UNDERLINE
= 26;
175 const sal_uInt16 OOBIN_DXF_FONT_ESCAPEMENT
= 27;
176 const sal_uInt16 OOBIN_DXF_FONT_ITALIC
= 28;
177 const sal_uInt16 OOBIN_DXF_FONT_STRIKE
= 29;
178 const sal_uInt16 OOBIN_DXF_FONT_OUTLINE
= 30;
179 const sal_uInt16 OOBIN_DXF_FONT_SHADOW
= 31;
180 const sal_uInt16 OOBIN_DXF_FONT_CONDENSE
= 32;
181 const sal_uInt16 OOBIN_DXF_FONT_EXTEND
= 33;
182 const sal_uInt16 OOBIN_DXF_FONT_CHARSET
= 34;
183 const sal_uInt16 OOBIN_DXF_FONT_FAMILY
= 35;
184 const sal_uInt16 OOBIN_DXF_FONT_HEIGHT
= 36;
185 const sal_uInt16 OOBIN_DXF_FONT_SCHEME
= 37;
186 const sal_uInt16 OOBIN_DXF_NUMFMT_CODE
= 38;
187 const sal_uInt16 OOBIN_DXF_NUMFMT_ID
= 41;
189 // OOBIN CELLSTYLE flags
190 const sal_uInt16 OOBIN_CELLSTYLE_BUILTIN
= 0x0001;
191 const sal_uInt16 OOBIN_CELLSTYLE_HIDDEN
= 0x0002;
192 const sal_uInt16 OOBIN_CELLSTYLE_CUSTOM
= 0x0004;
194 // OOBIN and BIFF constants ---------------------------------------------------
196 // BIFF predefined color indexes
197 const sal_uInt16 BIFF2_COLOR_BLACK
= 0; /// Black (text) in BIFF2.
198 const sal_uInt16 BIFF2_COLOR_WHITE
= 1; /// White (background) in BIFF2.
200 // BIFF font flags, also used in OOBIN
201 const sal_uInt16 BIFF_FONTFLAG_BOLD
= 0x0001;
202 const sal_uInt16 BIFF_FONTFLAG_ITALIC
= 0x0002;
203 const sal_uInt16 BIFF_FONTFLAG_UNDERLINE
= 0x0004;
204 const sal_uInt16 BIFF_FONTFLAG_STRIKEOUT
= 0x0008;
205 const sal_uInt16 BIFF_FONTFLAG_OUTLINE
= 0x0010;
206 const sal_uInt16 BIFF_FONTFLAG_SHADOW
= 0x0020;
207 const sal_uInt16 BIFF_FONTFLAG_CONDENSE
= 0x0040;
210 const sal_uInt16 BIFF_FONTWEIGHT_BOLD
= 450;
212 // BIFF font underline, also used in OOBIN
213 const sal_uInt8 BIFF_FONTUNDERL_NONE
= 0;
214 const sal_uInt8 BIFF_FONTUNDERL_SINGLE
= 1;
215 const sal_uInt8 BIFF_FONTUNDERL_DOUBLE
= 2;
216 const sal_uInt8 BIFF_FONTUNDERL_SINGLE_ACC
= 33;
217 const sal_uInt8 BIFF_FONTUNDERL_DOUBLE_ACC
= 34;
220 const sal_uInt16 BIFF_XF_LOCKED
= 0x0001;
221 const sal_uInt16 BIFF_XF_HIDDEN
= 0x0002;
222 const sal_uInt16 BIFF_XF_STYLE
= 0x0004;
223 const sal_uInt16 BIFF_XF_STYLEPARENT
= 0x0FFF; /// Syles don't have a parent.
224 const sal_uInt16 BIFF_XF_WRAPTEXT
= 0x0008; /// Automatic line break.
225 const sal_uInt16 BIFF_XF_JUSTLASTLINE
= 0x0080;
226 const sal_uInt16 BIFF_XF_SHRINK
= 0x0010; /// Shrink to fit into cell.
227 const sal_uInt16 BIFF_XF_MERGE
= 0x0020;
229 // BIFF XF attribute used flags
230 const sal_uInt8 BIFF_XF_NUMFMT_USED
= 0x01;
231 const sal_uInt8 BIFF_XF_FONT_USED
= 0x02;
232 const sal_uInt8 BIFF_XF_ALIGN_USED
= 0x04;
233 const sal_uInt8 BIFF_XF_BORDER_USED
= 0x08;
234 const sal_uInt8 BIFF_XF_AREA_USED
= 0x10;
235 const sal_uInt8 BIFF_XF_PROT_USED
= 0x20;
237 // BIFF XF text orientation
238 const sal_uInt8 BIFF_XF_ORIENT_NONE
= 0;
239 const sal_uInt8 BIFF_XF_ORIENT_STACKED
= 1; /// Stacked top to bottom.
240 const sal_uInt8 BIFF_XF_ORIENT_90CCW
= 2; /// 90 degr. counterclockwise.
241 const sal_uInt8 BIFF_XF_ORIENT_90CW
= 3; /// 90 degr. clockwise.
243 // BIFF XF line styles
244 const sal_uInt8 BIFF_LINE_NONE
= 0;
245 const sal_uInt8 BIFF_LINE_THIN
= 1;
248 const sal_uInt8 BIFF_PATT_NONE
= 0;
249 const sal_uInt8 BIFF_PATT_125
= 17;
252 const sal_uInt8 BIFF2_XF_VALFMT_MASK
= 0x3F;
253 const sal_uInt8 BIFF2_XF_LOCKED
= 0x40;
254 const sal_uInt8 BIFF2_XF_HIDDEN
= 0x80;
255 const sal_uInt8 BIFF2_XF_LEFTLINE
= 0x08;
256 const sal_uInt8 BIFF2_XF_RIGHTLINE
= 0x10;
257 const sal_uInt8 BIFF2_XF_TOPLINE
= 0x20;
258 const sal_uInt8 BIFF2_XF_BOTTOMLINE
= 0x40;
259 const sal_uInt8 BIFF2_XF_BACKGROUND
= 0x80;
261 // BIFF8 diagonal borders
262 const sal_uInt32 BIFF_XF_DIAG_TLBR
= 0x40000000; /// Top-left to bottom-right.
263 const sal_uInt32 BIFF_XF_DIAG_BLTR
= 0x80000000; /// Bottom-left to top-right.
266 const sal_uInt16 BIFF_STYLE_BUILTIN
= 0x8000;
267 const sal_uInt16 BIFF_STYLE_XFMASK
= 0x0FFF;
269 // BIFF STYLEEXT flags
270 const sal_uInt8 BIFF_STYLEEXT_BUILTIN
= 0x01;
271 const sal_uInt8 BIFF_STYLEEXT_HIDDEN
= 0x02;
272 const sal_uInt8 BIFF_STYLEEXT_CUSTOM
= 0x04;
274 // BIFF conditional formatting
275 const sal_uInt32 BIFF_CFRULE_BORDER_LEFT
= 0x00000400;
276 const sal_uInt32 BIFF_CFRULE_BORDER_RIGHT
= 0x00000800;
277 const sal_uInt32 BIFF_CFRULE_BORDER_TOP
= 0x00001000;
278 const sal_uInt32 BIFF_CFRULE_BORDER_BOTTOM
= 0x00002000;
279 const sal_uInt32 BIFF_CFRULE_FILL_PATTERN
= 0x00010000;
280 const sal_uInt32 BIFF_CFRULE_FILL_PATTCOLOR
= 0x00020000;
281 const sal_uInt32 BIFF_CFRULE_FILL_FILLCOLOR
= 0x00040000;
282 const sal_uInt32 BIFF_CFRULE_FONTBLOCK
= 0x04000000;
283 const sal_uInt32 BIFF_CFRULE_ALIGNBLOCK
= 0x08000000;
284 const sal_uInt32 BIFF_CFRULE_BORDERBLOCK
= 0x10000000;
285 const sal_uInt32 BIFF_CFRULE_FILLBLOCK
= 0x20000000;
286 const sal_uInt32 BIFF_CFRULE_PROTBLOCK
= 0x40000000;
288 const sal_uInt32 BIFF_CFRULE_FONT_STYLE
= 0x00000002; /// Font posture or weight modified?
289 const sal_uInt32 BIFF_CFRULE_FONT_OUTLINE
= 0x00000008; /// Font outline modified?
290 const sal_uInt32 BIFF_CFRULE_FONT_SHADOW
= 0x00000010; /// Font shadow modified?
291 const sal_uInt32 BIFF_CFRULE_FONT_STRIKEOUT
= 0x00000080; /// Font cancellation modified?
292 const sal_uInt32 BIFF_CFRULE_FONT_UNDERL
= 0x00000001; /// Font underline type modified?
293 const sal_uInt32 BIFF_CFRULE_FONT_ESCAPEM
= 0x00000001; /// Font escapement type modified?
295 // ----------------------------------------------------------------------------
297 sal_Int32
lclReadRgbColor( BinaryInputStream
& rStrm
)
299 sal_uInt8 nR
, nG
, nB
, nA
;
300 rStrm
>> nR
>> nG
>> nB
>> nA
;
301 sal_Int32 nValue
= nA
;
313 // ----------------------------------------------------------------------------
315 void Color::setAuto()
317 clearTransformations();
318 setSchemeClr( XML_phClr
);
321 void Color::setRgb( sal_Int32 nRgbValue
, double fTint
)
323 clearTransformations();
324 setSrgbClr( nRgbValue
& 0xFFFFFF );
325 if( fTint
!= 0.0 ) addExcelTintTransformation( fTint
);
328 void Color::setTheme( sal_Int32 nThemeIdx
, double fTint
)
330 clearTransformations();
331 static const sal_Int32 spnColorTokens
[] = {
332 XML_lt1
, XML_dk1
, XML_lt2
, XML_dk2
, XML_accent1
, XML_accent2
,
333 XML_accent3
, XML_accent4
, XML_accent5
, XML_accent6
, XML_hlink
, XML_folHlink
};
334 setSchemeClr( STATIC_ARRAY_SELECT( spnColorTokens
, nThemeIdx
, XML_TOKEN_INVALID
) );
335 if( fTint
!= 0.0 ) addExcelTintTransformation( fTint
);
338 void Color::setIndexed( sal_Int32 nPaletteIdx
, double fTint
)
340 clearTransformations();
341 setPaletteClr( nPaletteIdx
);
342 if( fTint
!= 0.0 ) addExcelTintTransformation( fTint
);
345 void Color::importColor( const AttributeList
& rAttribs
)
347 if( rAttribs
.getBool( XML_auto
, false ) )
349 else if( rAttribs
.hasAttribute( XML_rgb
) )
350 setRgb( rAttribs
.getIntegerHex( XML_rgb
, API_RGB_TRANSPARENT
), rAttribs
.getDouble( XML_tint
, 0.0 ) );
351 else if( rAttribs
.hasAttribute( XML_theme
) )
352 setTheme( rAttribs
.getInteger( XML_theme
, -1 ), rAttribs
.getDouble( XML_tint
, 0.0 ) );
353 else if( rAttribs
.hasAttribute( XML_indexed
) )
354 setIndexed( rAttribs
.getInteger( XML_indexed
, -1 ), rAttribs
.getDouble( XML_tint
, 0.0 ) );
357 OSL_ENSURE( false, "Color::importColor - unknown color type" );
362 void Color::importColor( RecordInputStream
& rStrm
)
364 sal_uInt8 nFlags
, nIndex
;
366 rStrm
>> nFlags
>> nIndex
>> nTint
;
368 // scale tint from signed 16-bit to double range -1.0 ... 1.0
369 double fTint
= nTint
;
371 fTint
/= -SAL_MIN_INT16
;
373 fTint
/= SAL_MAX_INT16
;
375 switch( extractValue
< sal_uInt8
>( nFlags
, 1, 7 ) )
377 case OOBIN_COLOR_AUTO
:
381 case OOBIN_COLOR_INDEXED
:
382 setIndexed( nIndex
, fTint
);
385 case OOBIN_COLOR_RGB
:
386 setRgb( lclReadRgbColor( rStrm
), fTint
);
388 case OOBIN_COLOR_THEME
:
389 setTheme( nIndex
, fTint
);
393 OSL_ENSURE( false, "Color::importColor - unknown color type" );
399 void Color::importColorId( RecordInputStream
& rStrm
)
401 setIndexed( rStrm
.readInt32() );
404 void Color::importColorRgb( RecordInputStream
& rStrm
)
406 setRgb( lclReadRgbColor( rStrm
) );
409 void Color::importColorId( BiffInputStream
& rStrm
, bool b16Bit
)
411 setIndexed( b16Bit
? rStrm
.readuInt16() : rStrm
.readuInt8() );
414 void Color::importColorRgb( BiffInputStream
& rStrm
)
416 setRgb( lclReadRgbColor( rStrm
) );
419 RecordInputStream
& operator>>( RecordInputStream
& rStrm
, Color
& orColor
)
421 orColor
.importColor( rStrm
);
425 // ============================================================================
429 /** Standard EGA colors, bright. */
430 #define PALETTE_EGA_COLORS_LIGHT \
431 0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF
432 /** Standard EGA colors, dark. */
433 #define PALETTE_EGA_COLORS_DARK \
434 0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080
436 /** Default color table for BIFF2. */
437 static const sal_Int32 spnDefColors2
[] =
439 /* 0 */ PALETTE_EGA_COLORS_LIGHT
442 /** Default color table for BIFF3/BIFF4. */
443 static const sal_Int32 spnDefColors3
[] =
445 /* 0 */ PALETTE_EGA_COLORS_LIGHT
,
446 /* 8 */ PALETTE_EGA_COLORS_LIGHT
,
447 /* 16 */ PALETTE_EGA_COLORS_DARK
450 /** Default color table for BIFF5. */
451 static const sal_Int32 spnDefColors5
[] =
453 /* 0 */ PALETTE_EGA_COLORS_LIGHT
,
454 /* 8 */ PALETTE_EGA_COLORS_LIGHT
,
455 /* 16 */ PALETTE_EGA_COLORS_DARK
,
456 /* 24 */ 0x8080FF, 0x802060, 0xFFFFC0, 0xA0E0E0, 0x600080, 0xFF8080, 0x0080C0, 0xC0C0FF,
457 /* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
458 /* 40 */ 0x00CFFF, 0x69FFFF, 0xE0FFE0, 0xFFFF80, 0xA6CAF0, 0xDD9CB3, 0xB38FEE, 0xE3E3E3,
459 /* 48 */ 0x2A6FF9, 0x3FB8CD, 0x488436, 0x958C41, 0x8E5E42, 0xA0627A, 0x624FAC, 0x969696,
460 /* 56 */ 0x1D2FBE, 0x286676, 0x004500, 0x453E01, 0x6A2813, 0x85396A, 0x4A3285, 0x424242
463 /** Default color table for BIFF8/OOX. */
464 static const sal_Int32 spnDefColors8
[] =
466 /* 0 */ PALETTE_EGA_COLORS_LIGHT
,
467 /* 8 */ PALETTE_EGA_COLORS_LIGHT
,
468 /* 16 */ PALETTE_EGA_COLORS_DARK
,
469 /* 24 */ 0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF,
470 /* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
471 /* 40 */ 0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99,
472 /* 48 */ 0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
473 /* 56 */ 0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333
476 #undef PALETTE_EGA_COLORS_LIGHT
477 #undef PALETTE_EGA_COLORS_DARK
481 // ----------------------------------------------------------------------------
483 ColorPalette::ColorPalette( const WorkbookHelper
& rHelper
) :
484 WorkbookHelper( rHelper
)
487 switch( getFilterType() )
490 maColors
.insert( maColors
.begin(), spnDefColors8
, STATIC_ARRAY_END( spnDefColors8
) );
491 mnAppendIndex
= OOX_COLOR_USEROFFSET
;
496 case BIFF2
: maColors
.insert( maColors
.begin(), spnDefColors2
, STATIC_ARRAY_END( spnDefColors2
) ); break;
498 case BIFF4
: maColors
.insert( maColors
.begin(), spnDefColors3
, STATIC_ARRAY_END( spnDefColors3
) ); break;
499 case BIFF5
: maColors
.insert( maColors
.begin(), spnDefColors5
, STATIC_ARRAY_END( spnDefColors5
) ); break;
500 case BIFF8
: maColors
.insert( maColors
.begin(), spnDefColors8
, STATIC_ARRAY_END( spnDefColors8
) ); break;
501 case BIFF_UNKNOWN
: break;
503 mnAppendIndex
= BIFF_COLOR_USEROFFSET
;
505 case FILTER_UNKNOWN
: break;
509 void ColorPalette::importPaletteColor( const AttributeList
& rAttribs
)
511 appendColor( rAttribs
.getIntegerHex( XML_rgb
, API_RGB_WHITE
) );
514 void ColorPalette::importPaletteColor( RecordInputStream
& rStrm
)
516 sal_Int32 nRgb
= lclReadRgbColor( rStrm
);
517 appendColor( nRgb
& 0xFFFFFF );
520 void ColorPalette::importPalette( BiffInputStream
& rStrm
)
524 OSL_ENSURE( rStrm
.getRemaining() == 4 * nCount
, "ColorPalette::importPalette - wrong palette size" );
526 // fill palette from BIFF_COLOR_USEROFFSET
527 mnAppendIndex
= BIFF_COLOR_USEROFFSET
;
528 for( sal_uInt16 nIndex
= 0; !rStrm
.isEof() && (nIndex
< nCount
); ++nIndex
)
530 sal_Int32 nRgb
= lclReadRgbColor( rStrm
);
531 appendColor( nRgb
& 0xFFFFFF );
535 sal_Int32
ColorPalette::getColor( sal_Int32 nPaletteIdx
) const
537 sal_Int32 nColor
= API_RGB_TRANSPARENT
;
538 if( const sal_Int32
* pnPaletteColor
= ContainerHelper::getVectorElement( maColors
, nPaletteIdx
) )
540 nColor
= *pnPaletteColor
;
542 else switch( nPaletteIdx
)
544 case OOX_COLOR_WINDOWTEXT3
:
545 case OOX_COLOR_WINDOWTEXT
:
546 case OOX_COLOR_CHWINDOWTEXT
: nColor
= getBaseFilter().getSystemColor( XML_windowText
); break;
547 case OOX_COLOR_WINDOWBACK3
:
548 case OOX_COLOR_WINDOWBACK
:
549 case OOX_COLOR_CHWINDOWBACK
: nColor
= getBaseFilter().getSystemColor( XML_window
); break;
550 case OOX_COLOR_BUTTONBACK
: nColor
= getBaseFilter().getSystemColor( XML_btnFace
); break;
551 case OOX_COLOR_CHBORDERAUTO
: nColor
= API_RGB_BLACK
; /* really always black? */ break;
552 case OOX_COLOR_NOTEBACK
: nColor
= getBaseFilter().getSystemColor( XML_infoBk
); break;
553 case OOX_COLOR_NOTETEXT
: nColor
= getBaseFilter().getSystemColor( XML_infoText
); break;
554 case OOX_COLOR_FONTAUTO
: nColor
= API_RGB_TRANSPARENT
; break;
555 default: OSL_ENSURE( false, "ColorPalette::getColor - unknown color index" );
560 void ColorPalette::appendColor( sal_Int32 nRGBValue
)
562 if( mnAppendIndex
< maColors
.size() )
563 maColors
[ mnAppendIndex
] = nRGBValue
;
565 maColors
.push_back( nRGBValue
);
569 // ============================================================================
573 void lclSetFontName( ApiScriptFontName
& rFontName
, const FontDescriptor
& rFontDesc
, bool bHasGlyphs
)
577 rFontName
.maName
= rFontDesc
.Name
;
578 rFontName
.mnFamily
= rFontDesc
.Family
;
579 rFontName
.mnCharSet
= rFontDesc
.CharSet
;
583 rFontName
= ApiScriptFontName();
589 // ----------------------------------------------------------------------------
591 FontModel::FontModel() :
592 mnScheme( XML_none
),
593 mnFamily( OOX_FONTFAMILY_NONE
),
594 mnCharSet( OOX_FONTCHARSET_ANSI
),
596 mnUnderline( XML_none
),
597 mnEscapement( XML_baseline
),
600 mbStrikeout( false ),
606 void FontModel::setBinScheme( sal_uInt8 nScheme
)
608 static const sal_Int32 spnSchemes
[] = { XML_none
, XML_major
, XML_minor
};
609 mnScheme
= STATIC_ARRAY_SELECT( spnSchemes
, nScheme
, XML_none
);
612 void FontModel::setBiffHeight( sal_uInt16 nHeight
)
614 mfHeight
= nHeight
/ 20.0; // convert twips to points
617 void FontModel::setBiffWeight( sal_uInt16 nWeight
)
619 mbBold
= nWeight
>= BIFF_FONTWEIGHT_BOLD
;
622 void FontModel::setBiffUnderline( sal_uInt16 nUnderline
)
626 case BIFF_FONTUNDERL_NONE
: mnUnderline
= XML_none
; break;
627 case BIFF_FONTUNDERL_SINGLE
: mnUnderline
= XML_single
; break;
628 case BIFF_FONTUNDERL_DOUBLE
: mnUnderline
= XML_double
; break;
629 case BIFF_FONTUNDERL_SINGLE_ACC
: mnUnderline
= XML_singleAccounting
; break;
630 case BIFF_FONTUNDERL_DOUBLE_ACC
: mnUnderline
= XML_doubleAccounting
; break;
631 default: mnUnderline
= XML_none
;
635 void FontModel::setBiffEscapement( sal_uInt16 nEscapement
)
637 static const sal_Int32 spnEscapes
[] = { XML_baseline
, XML_superscript
, XML_subscript
};
638 mnEscapement
= STATIC_ARRAY_SELECT( spnEscapes
, nEscapement
, XML_baseline
);
641 // ----------------------------------------------------------------------------
643 ApiFontUsedFlags::ApiFontUsedFlags( bool bAllUsed
) :
644 mbNameUsed( bAllUsed
),
645 mbColorUsed( bAllUsed
),
646 mbSchemeUsed( bAllUsed
),
647 mbHeightUsed( bAllUsed
),
648 mbUnderlineUsed( bAllUsed
),
649 mbEscapementUsed( bAllUsed
),
650 mbWeightUsed( bAllUsed
),
651 mbPostureUsed( bAllUsed
),
652 mbStrikeoutUsed( bAllUsed
),
653 mbOutlineUsed( bAllUsed
),
654 mbShadowUsed( bAllUsed
)
658 // ----------------------------------------------------------------------------
660 ApiScriptFontName::ApiScriptFontName() :
661 mnFamily( ::com::sun::star::awt::FontFamily::DONTKNOW
),
662 mnCharSet( RTL_TEXTENCODING_DONTKNOW
)
666 // ----------------------------------------------------------------------------
668 ApiFontData::ApiFontData() :
670 CREATE_OUSTRING( "Calibri" ),
671 220, // height 11 points
674 ::com::sun::star::awt::FontFamily::DONTKNOW
,
675 RTL_TEXTENCODING_DONTKNOW
,
676 ::com::sun::star::awt::FontPitch::DONTKNOW
,
678 ::com::sun::star::awt::FontWeight::NORMAL
,
679 ::com::sun::star::awt::FontSlant_NONE
,
680 ::com::sun::star::awt::FontUnderline::NONE
,
681 ::com::sun::star::awt::FontStrikeout::NONE
,
685 ::com::sun::star::awt::FontType::DONTKNOW
),
686 mnColor( API_RGB_TRANSPARENT
),
687 mnEscapement( API_ESCAPE_NONE
),
688 mnEscapeHeight( API_ESCAPEHEIGHT_NONE
),
692 maLatinFont
.maName
= maDesc
.Name
;
695 // ============================================================================
697 Font::Font( const WorkbookHelper
& rHelper
, bool bDxf
) :
698 WorkbookHelper( rHelper
),
699 maModel( rHelper
.getTheme().getDefaultFontModel() ),
700 maUsedFlags( !bDxf
),
705 Font::Font( const WorkbookHelper
& rHelper
, const FontModel
& rModel
) :
706 WorkbookHelper( rHelper
),
713 void Font::importAttribs( sal_Int32 nElement
, const AttributeList
& rAttribs
)
715 const FontModel
& rDefModel
= getTheme().getDefaultFontModel();
718 case XLS_TOKEN( name
): // when in <font> element
719 case XLS_TOKEN( rFont
): // when in <rPr> element
720 if( rAttribs
.hasAttribute( XML_val
) )
722 maModel
.maName
= rAttribs
.getXString( XML_val
, OUString() );
723 maUsedFlags
.mbNameUsed
= true;
726 case XLS_TOKEN( scheme
):
727 maModel
.mnScheme
= rAttribs
.getToken( XML_val
, rDefModel
.mnScheme
);
729 case XLS_TOKEN( family
):
730 maModel
.mnFamily
= rAttribs
.getInteger( XML_val
, rDefModel
.mnFamily
);
732 case XLS_TOKEN( charset
):
733 maModel
.mnCharSet
= rAttribs
.getInteger( XML_val
, rDefModel
.mnCharSet
);
735 case XLS_TOKEN( sz
):
736 maModel
.mfHeight
= rAttribs
.getDouble( XML_val
, rDefModel
.mfHeight
);
737 maUsedFlags
.mbHeightUsed
= true;
739 case XLS_TOKEN( color
):
740 maModel
.maColor
.importColor( rAttribs
);
741 maUsedFlags
.mbColorUsed
= true;
744 maModel
.mnUnderline
= rAttribs
.getToken( XML_val
, XML_single
);
745 maUsedFlags
.mbUnderlineUsed
= true;
747 case XLS_TOKEN( vertAlign
):
748 maModel
.mnEscapement
= rAttribs
.getToken( XML_val
, XML_baseline
);
749 maUsedFlags
.mbEscapementUsed
= true;
752 maModel
.mbBold
= rAttribs
.getBool( XML_val
, true );
753 maUsedFlags
.mbWeightUsed
= true;
756 maModel
.mbItalic
= rAttribs
.getBool( XML_val
, true );
757 maUsedFlags
.mbPostureUsed
= true;
759 case XLS_TOKEN( strike
):
760 maModel
.mbStrikeout
= rAttribs
.getBool( XML_val
, true );
761 maUsedFlags
.mbStrikeoutUsed
= true;
763 case XLS_TOKEN( outline
):
764 maModel
.mbOutline
= rAttribs
.getBool( XML_val
, true );
765 maUsedFlags
.mbOutlineUsed
= true;
767 case XLS_TOKEN( shadow
):
768 maModel
.mbShadow
= rAttribs
.getBool( XML_val
, true );
769 maUsedFlags
.mbShadowUsed
= true;
774 void Font::importFont( RecordInputStream
& rStrm
)
776 OSL_ENSURE( !mbDxf
, "Font::importFont - unexpected conditional formatting flag" );
778 sal_uInt16 nHeight
, nFlags
, nWeight
, nEscapement
;
779 sal_uInt8 nUnderline
, nFamily
, nCharSet
, nScheme
;
780 rStrm
>> nHeight
>> nFlags
>> nWeight
>> nEscapement
>> nUnderline
>> nFamily
>> nCharSet
;
782 rStrm
>> maModel
.maColor
>> nScheme
>> maModel
.maName
;
784 // equal constants in BIFF and OOBIN for weight, underline, and escapement
785 maModel
.setBinScheme( nScheme
);
786 maModel
.setBiffHeight( nHeight
);
787 maModel
.setBiffWeight( nWeight
);
788 maModel
.setBiffUnderline( nUnderline
);
789 maModel
.setBiffEscapement( nEscapement
);
790 maModel
.mnFamily
= nFamily
;
791 maModel
.mnCharSet
= nCharSet
;
792 // equal flags in BIFF and OOBIN
793 maModel
.mbItalic
= getFlag( nFlags
, BIFF_FONTFLAG_ITALIC
);
794 maModel
.mbStrikeout
= getFlag( nFlags
, BIFF_FONTFLAG_STRIKEOUT
);
795 maModel
.mbOutline
= getFlag( nFlags
, BIFF_FONTFLAG_OUTLINE
);
796 maModel
.mbShadow
= getFlag( nFlags
, BIFF_FONTFLAG_SHADOW
);
799 void Font::importDxfName( RecordInputStream
& rStrm
)
801 OSL_ENSURE( mbDxf
, "Font::importDxfName - missing conditional formatting flag" );
802 maModel
.maName
= rStrm
.readString( false );
803 maUsedFlags
.mbColorUsed
= true;
806 void Font::importDxfColor( RecordInputStream
& rStrm
)
808 OSL_ENSURE( mbDxf
, "Font::importDxfColor - missing conditional formatting flag" );
809 rStrm
>> maModel
.maColor
;
810 maUsedFlags
.mbColorUsed
= true;
813 void Font::importDxfScheme( RecordInputStream
& rStrm
)
815 OSL_ENSURE( mbDxf
, "Font::importDxfScheme - missing conditional formatting flag" );
816 maModel
.setBinScheme( rStrm
.readuInt8() );
817 maUsedFlags
.mbSchemeUsed
= true;
820 void Font::importDxfHeight( RecordInputStream
& rStrm
)
822 OSL_ENSURE( mbDxf
, "Font::importDxfHeight - missing conditional formatting flag" );
823 maModel
.setBiffHeight( rStrm
.readuInt16() );
824 maUsedFlags
.mbHeightUsed
= true;
827 void Font::importDxfWeight( RecordInputStream
& rStrm
)
829 OSL_ENSURE( mbDxf
, "Font::importDxfWeight - missing conditional formatting flag" );
830 maModel
.setBiffWeight( rStrm
.readuInt16() );
831 maUsedFlags
.mbWeightUsed
= true;
834 void Font::importDxfUnderline( RecordInputStream
& rStrm
)
836 OSL_ENSURE( mbDxf
, "Font::importDxfUnderline - missing conditional formatting flag" );
837 maModel
.setBiffUnderline( rStrm
.readuInt16() );
838 maUsedFlags
.mbUnderlineUsed
= true;
841 void Font::importDxfEscapement( RecordInputStream
& rStrm
)
843 OSL_ENSURE( mbDxf
, "Font::importDxfEscapement - missing conditional formatting flag" );
844 maModel
.setBiffEscapement( rStrm
.readuInt16() );
845 maUsedFlags
.mbEscapementUsed
= true;
848 void Font::importDxfFlag( sal_Int32 nElement
, RecordInputStream
& rStrm
)
850 OSL_ENSURE( mbDxf
, "Font::importDxfFlag - missing conditional formatting flag" );
851 bool bFlag
= rStrm
.readuInt8() != 0;
855 maModel
.mbItalic
= bFlag
;
856 maUsedFlags
.mbPostureUsed
= true;
859 maModel
.mbStrikeout
= bFlag
;
860 maUsedFlags
.mbStrikeoutUsed
= true;
863 maModel
.mbOutline
= bFlag
;
864 maUsedFlags
.mbOutlineUsed
= true;
867 maModel
.mbShadow
= bFlag
;
868 maUsedFlags
.mbShadowUsed
= true;
871 OSL_ENSURE( false, "Font::importDxfFlag - unexpected element identifier" );
875 void Font::importFont( BiffInputStream
& rStrm
)
877 OSL_ENSURE( !mbDxf
, "Font::importFont - unexpected conditional formatting flag" );
881 importFontData2( rStrm
);
882 importFontName2( rStrm
);
886 importFontData2( rStrm
);
887 importFontColor( rStrm
);
888 importFontName2( rStrm
);
891 importFontData2( rStrm
);
892 importFontColor( rStrm
);
893 importFontData5( rStrm
);
894 importFontName2( rStrm
);
897 importFontData2( rStrm
);
898 importFontColor( rStrm
);
899 importFontData5( rStrm
);
900 importFontName8( rStrm
);
902 case BIFF_UNKNOWN
: break;
906 void Font::importFontColor( BiffInputStream
& rStrm
)
908 OSL_ENSURE( !mbDxf
, "Font::importFontColor - unexpected conditional formatting flag" );
909 maModel
.maColor
.importColorId( rStrm
);
912 void Font::importCfRule( BiffInputStream
& rStrm
)
914 OSL_ENSURE( mbDxf
, "Font::importCfRule - missing conditional formatting flag" );
916 sal_Int32 nHeight
, nColor
;
917 sal_uInt32 nStyle
, nFontFlags1
, nFontFlags2
, nFontFlags3
;
918 sal_uInt16 nWeight
, nEscapement
;
919 sal_uInt8 nUnderline
;
921 OSL_ENSURE( rStrm
.getRemaining() >= 118, "Font::importCfRule - missing record data" );
922 sal_Int64 nRecPos
= rStrm
.tell();
923 maModel
.maName
= rStrm
.readUniStringBody( rStrm
.readuInt8() );
924 maUsedFlags
.mbNameUsed
= maModel
.maName
.getLength() > 0;
925 OSL_ENSURE( !rStrm
.isEof() && (rStrm
.tell() <= nRecPos
+ 64), "Font::importCfRule - font name too long" );
926 rStrm
.seek( nRecPos
+ 64 );
927 rStrm
>> nHeight
>> nStyle
>> nWeight
>> nEscapement
>> nUnderline
;
931 rStrm
>> nFontFlags1
>> nFontFlags2
>> nFontFlags3
;
934 if( (maUsedFlags
.mbColorUsed
= (0 <= nColor
) && (nColor
<= 0x7FFF)) == true )
935 maModel
.maColor
.setIndexed( nColor
);
936 if( (maUsedFlags
.mbHeightUsed
= (0 < nHeight
) && (nHeight
<= 0x7FFF)) == true )
937 maModel
.setBiffHeight( static_cast< sal_uInt16
>( nHeight
) );
938 if( (maUsedFlags
.mbUnderlineUsed
= !getFlag( nFontFlags3
, BIFF_CFRULE_FONT_UNDERL
)) == true )
939 maModel
.setBiffUnderline( nUnderline
);
940 if( (maUsedFlags
.mbEscapementUsed
= !getFlag( nFontFlags2
, BIFF_CFRULE_FONT_ESCAPEM
)) == true )
941 maModel
.setBiffEscapement( nEscapement
);
942 if( (maUsedFlags
.mbWeightUsed
= maUsedFlags
.mbPostureUsed
= !getFlag( nFontFlags1
, BIFF_CFRULE_FONT_STYLE
)) == true )
944 maModel
.setBiffWeight( nWeight
);
945 maModel
.mbItalic
= getFlag( nStyle
, BIFF_CFRULE_FONT_STYLE
);
947 if( (maUsedFlags
.mbStrikeoutUsed
= !getFlag( nFontFlags1
, BIFF_CFRULE_FONT_STRIKEOUT
)) == true )
948 maModel
.mbStrikeout
= getFlag( nStyle
, BIFF_CFRULE_FONT_STRIKEOUT
);
949 if( (maUsedFlags
.mbOutlineUsed
= !getFlag( nFontFlags1
, BIFF_CFRULE_FONT_OUTLINE
)) == true )
950 maModel
.mbOutline
= getFlag( nStyle
, BIFF_CFRULE_FONT_OUTLINE
);
951 if( (maUsedFlags
.mbShadowUsed
= !getFlag( nFontFlags1
, BIFF_CFRULE_FONT_SHADOW
)) == true )
952 maModel
.mbShadow
= getFlag( nStyle
, BIFF_CFRULE_FONT_SHADOW
);
955 rtl_TextEncoding
Font::getFontEncoding() const
957 // #i63105# cells use text encoding from FONT record character set
958 // #i67768# BIFF2-BIFF4 FONT records do not contain character set
959 // #i71033# do not use maApiData, this function is used before finalizeImport()
960 rtl_TextEncoding eFontEnc
= RTL_TEXTENCODING_DONTKNOW
;
961 if( (0 <= maModel
.mnCharSet
) && (maModel
.mnCharSet
<= SAL_MAX_UINT8
) )
962 eFontEnc
= rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8
>( maModel
.mnCharSet
) );
963 return (eFontEnc
== RTL_TEXTENCODING_DONTKNOW
) ? getTextEncoding() : eFontEnc
;
966 void Font::finalizeImport()
968 namespace cssawt
= ::com::sun::star::awt
;
971 maApiData
.maDesc
.Name
= maModel
.maName
;
974 switch( maModel
.mnFamily
)
976 case OOX_FONTFAMILY_NONE
: maApiData
.maDesc
.Family
= cssawt::FontFamily::DONTKNOW
; break;
977 case OOX_FONTFAMILY_ROMAN
: maApiData
.maDesc
.Family
= cssawt::FontFamily::ROMAN
; break;
978 case OOX_FONTFAMILY_SWISS
: maApiData
.maDesc
.Family
= cssawt::FontFamily::SWISS
; break;
979 case OOX_FONTFAMILY_MODERN
: maApiData
.maDesc
.Family
= cssawt::FontFamily::MODERN
; break;
980 case OOX_FONTFAMILY_SCRIPT
: maApiData
.maDesc
.Family
= cssawt::FontFamily::SCRIPT
; break;
981 case OOX_FONTFAMILY_DECORATIVE
: maApiData
.maDesc
.Family
= cssawt::FontFamily::DECORATIVE
; break;
985 if( (0 <= maModel
.mnCharSet
) && (maModel
.mnCharSet
<= 255) )
986 maApiData
.maDesc
.CharSet
= static_cast< sal_Int16
>(
987 rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8
>( maModel
.mnCharSet
) ) );
989 // color, height, weight, slant, strikeout, outline, shadow
990 maApiData
.mnColor
= maModel
.maColor
.getColor( getBaseFilter() );
991 maApiData
.maDesc
.Height
= static_cast< sal_Int16
>( maModel
.mfHeight
* 20.0 );
992 maApiData
.maDesc
.Weight
= maModel
.mbBold
? cssawt::FontWeight::BOLD
: cssawt::FontWeight::NORMAL
;
993 maApiData
.maDesc
.Slant
= maModel
.mbItalic
? cssawt::FontSlant_ITALIC
: cssawt::FontSlant_NONE
;
994 maApiData
.maDesc
.Strikeout
= maModel
.mbStrikeout
? cssawt::FontStrikeout::SINGLE
: cssawt::FontStrikeout::NONE
;
995 maApiData
.mbOutline
= maModel
.mbOutline
;
996 maApiData
.mbShadow
= maModel
.mbShadow
;
999 switch( maModel
.mnUnderline
)
1001 case XML_double
: maApiData
.maDesc
.Underline
= cssawt::FontUnderline::DOUBLE
; break;
1002 case XML_doubleAccounting
: maApiData
.maDesc
.Underline
= cssawt::FontUnderline::DOUBLE
; break;
1003 case XML_none
: maApiData
.maDesc
.Underline
= cssawt::FontUnderline::NONE
; break;
1004 case XML_single
: maApiData
.maDesc
.Underline
= cssawt::FontUnderline::SINGLE
; break;
1005 case XML_singleAccounting
: maApiData
.maDesc
.Underline
= cssawt::FontUnderline::SINGLE
; break;
1009 switch( maModel
.mnEscapement
)
1012 maApiData
.mnEscapement
= API_ESCAPE_NONE
;
1013 maApiData
.mnEscapeHeight
= API_ESCAPEHEIGHT_NONE
;
1015 case XML_superscript
:
1016 maApiData
.mnEscapement
= API_ESCAPE_SUPERSCRIPT
;
1017 maApiData
.mnEscapeHeight
= API_ESCAPEHEIGHT_DEFAULT
;
1020 maApiData
.mnEscapement
= API_ESCAPE_SUBSCRIPT
;
1021 maApiData
.mnEscapeHeight
= API_ESCAPEHEIGHT_DEFAULT
;
1025 // supported script types
1026 if( maUsedFlags
.mbNameUsed
)
1028 Reference
< XDevice
> xDevice
= getReferenceDevice();
1031 Reference
< XFont2
> xFont( xDevice
->getFont( maApiData
.maDesc
), UNO_QUERY
);
1034 // #91658# CJK fonts
1036 xFont
->hasGlyphs( OUString( sal_Unicode( 0x3041 ) ) ) || // 3040-309F: Hiragana
1037 xFont
->hasGlyphs( OUString( sal_Unicode( 0x30A1 ) ) ) || // 30A0-30FF: Katakana
1038 xFont
->hasGlyphs( OUString( sal_Unicode( 0x3111 ) ) ) || // 3100-312F: Bopomofo
1039 xFont
->hasGlyphs( OUString( sal_Unicode( 0x3131 ) ) ) || // 3130-318F: Hangul Compatibility Jamo
1040 xFont
->hasGlyphs( OUString( sal_Unicode( 0x3301 ) ) ) || // 3300-33FF: CJK Compatibility
1041 xFont
->hasGlyphs( OUString( sal_Unicode( 0x3401 ) ) ) || // 3400-4DBF: CJK Unified Ideographs Extension A
1042 xFont
->hasGlyphs( OUString( sal_Unicode( 0x4E01 ) ) ) || // 4E00-9FAF: CJK Unified Ideographs
1043 xFont
->hasGlyphs( OUString( sal_Unicode( 0x7E01 ) ) ) || // 4E00-9FAF: CJK unified ideographs
1044 xFont
->hasGlyphs( OUString( sal_Unicode( 0xA001 ) ) ) || // A001-A48F: Yi Syllables
1045 xFont
->hasGlyphs( OUString( sal_Unicode( 0xAC01 ) ) ) || // AC00-D7AF: Hangul Syllables
1046 xFont
->hasGlyphs( OUString( sal_Unicode( 0xCC01 ) ) ) || // AC00-D7AF: Hangul Syllables
1047 xFont
->hasGlyphs( OUString( sal_Unicode( 0xF901 ) ) ) || // F900-FAFF: CJK Compatibility Ideographs
1048 xFont
->hasGlyphs( OUString( sal_Unicode( 0xFF71 ) ) ); // FF00-FFEF: Halfwidth/Fullwidth Forms
1049 // #113783# CTL fonts
1051 xFont
->hasGlyphs( OUString( sal_Unicode( 0x05D1 ) ) ) || // 0590-05FF: Hebrew
1052 xFont
->hasGlyphs( OUString( sal_Unicode( 0x0631 ) ) ) || // 0600-06FF: Arabic
1053 xFont
->hasGlyphs( OUString( sal_Unicode( 0x0721 ) ) ) || // 0700-074F: Syriac
1054 xFont
->hasGlyphs( OUString( sal_Unicode( 0x0911 ) ) ) || // 0900-0DFF: Indic scripts
1055 xFont
->hasGlyphs( OUString( sal_Unicode( 0x0E01 ) ) ) || // 0E00-0E7F: Thai
1056 xFont
->hasGlyphs( OUString( sal_Unicode( 0xFB21 ) ) ) || // FB1D-FB4F: Hebrew Presentation Forms
1057 xFont
->hasGlyphs( OUString( sal_Unicode( 0xFB51 ) ) ) || // FB50-FDFF: Arabic Presentation Forms-A
1058 xFont
->hasGlyphs( OUString( sal_Unicode( 0xFE71 ) ) ); // FE70-FEFF: Arabic Presentation Forms-B
1061 (!bHasAsian
&& !bHasCmplx
) ||
1062 xFont
->hasGlyphs( OUString( sal_Unicode( 'A' ) ) );
1064 lclSetFontName( maApiData
.maLatinFont
, maApiData
.maDesc
, bHasLatin
);
1065 lclSetFontName( maApiData
.maAsianFont
, maApiData
.maDesc
, bHasAsian
);
1066 lclSetFontName( maApiData
.maCmplxFont
, maApiData
.maDesc
, bHasCmplx
);
1072 const FontDescriptor
& Font::getFontDescriptor() const
1074 return maApiData
.maDesc
;
1077 bool Font::needsRichTextFormat() const
1079 return maApiData
.mnEscapement
!= API_ESCAPE_NONE
;
1082 void Font::writeToPropertyMap( PropertyMap
& rPropMap
, FontPropertyType ePropType
) const
1084 // font name properties
1085 if( maUsedFlags
.mbNameUsed
)
1087 if( maApiData
.maLatinFont
.maName
.getLength() > 0 )
1089 rPropMap
[ PROP_CharFontName
] <<= maApiData
.maLatinFont
.maName
;
1090 rPropMap
[ PROP_CharFontFamily
] <<= maApiData
.maLatinFont
.mnFamily
;
1091 rPropMap
[ PROP_CharFontCharSet
] <<= maApiData
.maLatinFont
.mnCharSet
;
1093 if( maApiData
.maAsianFont
.maName
.getLength() > 0 )
1095 rPropMap
[ PROP_CharFontNameAsian
] <<= maApiData
.maAsianFont
.maName
;
1096 rPropMap
[ PROP_CharFontFamilyAsian
] <<= maApiData
.maAsianFont
.mnFamily
;
1097 rPropMap
[ PROP_CharFontCharSetAsian
] <<= maApiData
.maAsianFont
.mnCharSet
;
1099 if( maApiData
.maCmplxFont
.maName
.getLength() > 0 )
1101 rPropMap
[ PROP_CharFontNameComplex
] <<= maApiData
.maCmplxFont
.maName
;
1102 rPropMap
[ PROP_CharFontFamilyComplex
] <<= maApiData
.maCmplxFont
.mnFamily
;
1103 rPropMap
[ PROP_CharFontCharSetComplex
] <<= maApiData
.maCmplxFont
.mnCharSet
;
1107 if( maUsedFlags
.mbHeightUsed
)
1109 float fHeight
= static_cast< float >( maApiData
.maDesc
.Height
/ 20.0 ); // twips to points
1110 rPropMap
[ PROP_CharHeight
] <<= fHeight
;
1111 rPropMap
[ PROP_CharHeightAsian
] <<= fHeight
;
1112 rPropMap
[ PROP_CharHeightComplex
] <<= fHeight
;
1115 if( maUsedFlags
.mbWeightUsed
)
1117 float fWeight
= maApiData
.maDesc
.Weight
;
1118 rPropMap
[ PROP_CharWeight
] <<= fWeight
;
1119 rPropMap
[ PROP_CharWeightAsian
] <<= fWeight
;
1120 rPropMap
[ PROP_CharWeightComplex
] <<= fWeight
;
1123 if( maUsedFlags
.mbPostureUsed
)
1125 rPropMap
[ PROP_CharPosture
] <<= maApiData
.maDesc
.Slant
;
1126 rPropMap
[ PROP_CharPostureAsian
] <<= maApiData
.maDesc
.Slant
;
1127 rPropMap
[ PROP_CharPostureComplex
] <<= maApiData
.maDesc
.Slant
;
1130 if( maUsedFlags
.mbColorUsed
)
1131 rPropMap
[ PROP_CharColor
] <<= maApiData
.mnColor
;
1133 if( maUsedFlags
.mbUnderlineUsed
)
1134 rPropMap
[ PROP_CharUnderline
] <<= maApiData
.maDesc
.Underline
;
1136 if( maUsedFlags
.mbStrikeoutUsed
)
1137 rPropMap
[ PROP_CharStrikeout
] <<= maApiData
.maDesc
.Strikeout
;
1139 if( maUsedFlags
.mbOutlineUsed
)
1140 rPropMap
[ PROP_CharContoured
] <<= maApiData
.mbOutline
;
1142 if( maUsedFlags
.mbShadowUsed
)
1143 rPropMap
[ PROP_CharShadowed
] <<= maApiData
.mbShadow
;
1145 if( maUsedFlags
.mbEscapementUsed
&& (ePropType
== FONT_PROPTYPE_TEXT
) )
1147 rPropMap
[ PROP_CharEscapement
] <<= maApiData
.mnEscapement
;
1148 rPropMap
[ PROP_CharEscapementHeight
] <<= maApiData
.mnEscapeHeight
;
1152 void Font::writeToPropertySet( PropertySet
& rPropSet
, FontPropertyType ePropType
) const
1154 PropertyMap aPropMap
;
1155 writeToPropertyMap( aPropMap
, ePropType
);
1156 rPropSet
.setProperties( aPropMap
);
1159 void Font::importFontData2( BiffInputStream
& rStrm
)
1161 sal_uInt16 nHeight
, nFlags
;
1162 rStrm
>> nHeight
>> nFlags
;
1164 maModel
.setBiffHeight( nHeight
);
1165 maModel
.mnFamily
= OOX_FONTFAMILY_NONE
;
1166 maModel
.mnCharSet
= OOX_FONTCHARSET_UNUSED
; // ensure to not use font charset in byte string import
1167 maModel
.mnUnderline
= getFlagValue( nFlags
, BIFF_FONTFLAG_UNDERLINE
, XML_single
, XML_none
);
1168 maModel
.mnEscapement
= XML_none
;
1169 maModel
.mbBold
= getFlag( nFlags
, BIFF_FONTFLAG_BOLD
);
1170 maModel
.mbItalic
= getFlag( nFlags
, BIFF_FONTFLAG_ITALIC
);
1171 maModel
.mbStrikeout
= getFlag( nFlags
, BIFF_FONTFLAG_STRIKEOUT
);
1172 maModel
.mbOutline
= getFlag( nFlags
, BIFF_FONTFLAG_OUTLINE
);
1173 maModel
.mbShadow
= getFlag( nFlags
, BIFF_FONTFLAG_SHADOW
);
1176 void Font::importFontData5( BiffInputStream
& rStrm
)
1178 sal_uInt16 nWeight
, nEscapement
;
1179 sal_uInt8 nUnderline
, nFamily
, nCharSet
;
1180 rStrm
>> nWeight
>> nEscapement
>> nUnderline
>> nFamily
>> nCharSet
;
1183 maModel
.setBiffWeight( nWeight
);
1184 maModel
.setBiffUnderline( nUnderline
);
1185 maModel
.setBiffEscapement( nEscapement
);
1186 // equal constants in XML and BIFF for family and charset
1187 maModel
.mnFamily
= nFamily
;
1188 maModel
.mnCharSet
= nCharSet
;
1191 void Font::importFontName2( BiffInputStream
& rStrm
)
1193 maModel
.maName
= rStrm
.readByteStringUC( false, getTextEncoding() );
1196 void Font::importFontName8( BiffInputStream
& rStrm
)
1198 maModel
.maName
= rStrm
.readUniStringBody( rStrm
.readuInt8() );
1201 // ============================================================================
1203 AlignmentModel::AlignmentModel() :
1204 mnHorAlign( XML_general
),
1205 mnVerAlign( XML_bottom
),
1206 mnTextDir( OOX_XF_TEXTDIR_CONTEXT
),
1207 mnRotation( OOX_XF_ROTATION_NONE
),
1208 mnIndent( OOX_XF_INDENT_NONE
),
1209 mbWrapText( false ),
1211 mbJustLastLine( false )
1215 void AlignmentModel::setBinHorAlign( sal_uInt8 nHorAlign
)
1217 static const sal_Int32 spnHorAligns
[] = {
1218 XML_general
, XML_left
, XML_center
, XML_right
,
1219 XML_fill
, XML_justify
, XML_centerContinuous
, XML_distributed
};
1220 mnHorAlign
= STATIC_ARRAY_SELECT( spnHorAligns
, nHorAlign
, XML_general
);
1223 void AlignmentModel::setBinVerAlign( sal_uInt8 nVerAlign
)
1225 static const sal_Int32 spnVerAligns
[] = {
1226 XML_top
, XML_center
, XML_bottom
, XML_justify
, XML_distributed
};
1227 mnVerAlign
= STATIC_ARRAY_SELECT( spnVerAligns
, nVerAlign
, XML_bottom
);
1230 void AlignmentModel::setBinTextOrient( sal_uInt8 nTextOrient
)
1232 static const sal_Int32 spnRotations
[] = {
1233 OOX_XF_ROTATION_NONE
, OOX_XF_ROTATION_STACKED
,
1234 OOX_XF_ROTATION_90CCW
, OOX_XF_ROTATION_90CW
};
1235 mnRotation
= STATIC_ARRAY_SELECT( spnRotations
, nTextOrient
, OOX_XF_ROTATION_NONE
);
1238 // ----------------------------------------------------------------------------
1240 ApiAlignmentData::ApiAlignmentData() :
1241 meHorJustify( ::com::sun::star::table::CellHoriJustify_STANDARD
),
1242 meVerJustify( ::com::sun::star::table::CellVertJustify_STANDARD
),
1243 meOrientation( ::com::sun::star::table::CellOrientation_STANDARD
),
1245 mnWritingMode( ::com::sun::star::text::WritingMode2::PAGE
),
1247 mbWrapText( false ),
1252 bool operator==( const ApiAlignmentData
& rLeft
, const ApiAlignmentData
& rRight
)
1255 (rLeft
.meHorJustify
== rRight
.meHorJustify
) &&
1256 (rLeft
.meVerJustify
== rRight
.meVerJustify
) &&
1257 (rLeft
.meOrientation
== rRight
.meOrientation
) &&
1258 (rLeft
.mnRotation
== rRight
.mnRotation
) &&
1259 (rLeft
.mnWritingMode
== rRight
.mnWritingMode
) &&
1260 (rLeft
.mnIndent
== rRight
.mnIndent
) &&
1261 (rLeft
.mbWrapText
== rRight
.mbWrapText
) &&
1262 (rLeft
.mbShrink
== rRight
.mbShrink
);
1265 // ============================================================================
1267 Alignment::Alignment( const WorkbookHelper
& rHelper
) :
1268 WorkbookHelper( rHelper
)
1272 void Alignment::importAlignment( const AttributeList
& rAttribs
)
1274 maModel
.mnHorAlign
= rAttribs
.getToken( XML_horizontal
, XML_general
);
1275 maModel
.mnVerAlign
= rAttribs
.getToken( XML_vertical
, XML_bottom
);
1276 maModel
.mnTextDir
= rAttribs
.getInteger( XML_readingOrder
, OOX_XF_TEXTDIR_CONTEXT
);
1277 maModel
.mnRotation
= rAttribs
.getInteger( XML_textRotation
, OOX_XF_ROTATION_NONE
);
1278 maModel
.mnIndent
= rAttribs
.getInteger( XML_indent
, OOX_XF_INDENT_NONE
);
1279 maModel
.mbWrapText
= rAttribs
.getBool( XML_wrapText
, false );
1280 maModel
.mbShrink
= rAttribs
.getBool( XML_shrinkToFit
, false );
1281 maModel
.mbJustLastLine
= rAttribs
.getBool( XML_justifyLastLine
, false );
1284 void Alignment::setBinData( sal_uInt32 nFlags
)
1286 maModel
.setBinHorAlign( extractValue
< sal_uInt8
>( nFlags
, 16, 3 ) );
1287 maModel
.setBinVerAlign( extractValue
< sal_uInt8
>( nFlags
, 19, 3 ) );
1288 maModel
.mnTextDir
= extractValue
< sal_Int32
>( nFlags
, 26, 2 );
1289 maModel
.mnRotation
= extractValue
< sal_Int32
>( nFlags
, 0, 8 );
1290 maModel
.mnIndent
= extractValue
< sal_uInt8
>( nFlags
, 8, 8 );
1291 maModel
.mbWrapText
= getFlag( nFlags
, OOBIN_XF_WRAPTEXT
);
1292 maModel
.mbShrink
= getFlag( nFlags
, OOBIN_XF_SHRINK
);
1293 maModel
.mbJustLastLine
= getFlag( nFlags
, OOBIN_XF_JUSTLASTLINE
);
1296 void Alignment::setBiff2Data( sal_uInt8 nFlags
)
1298 maModel
.setBinHorAlign( extractValue
< sal_uInt8
>( nFlags
, 0, 3 ) );
1301 void Alignment::setBiff3Data( sal_uInt16 nAlign
)
1303 maModel
.setBinHorAlign( extractValue
< sal_uInt8
>( nAlign
, 0, 3 ) );
1304 maModel
.mbWrapText
= getFlag( nAlign
, BIFF_XF_WRAPTEXT
); // new in BIFF3
1307 void Alignment::setBiff4Data( sal_uInt16 nAlign
)
1309 maModel
.setBinHorAlign( extractValue
< sal_uInt8
>( nAlign
, 0, 3 ) );
1310 maModel
.setBinVerAlign( extractValue
< sal_uInt8
>( nAlign
, 4, 2 ) ); // new in BIFF4
1311 maModel
.setBinTextOrient( extractValue
< sal_uInt8
>( nAlign
, 6, 2 ) ); // new in BIFF4
1312 maModel
.mbWrapText
= getFlag( nAlign
, BIFF_XF_WRAPTEXT
);
1315 void Alignment::setBiff5Data( sal_uInt16 nAlign
)
1317 maModel
.setBinHorAlign( extractValue
< sal_uInt8
>( nAlign
, 0, 3 ) );
1318 maModel
.setBinVerAlign( extractValue
< sal_uInt8
>( nAlign
, 4, 3 ) );
1319 maModel
.setBinTextOrient( extractValue
< sal_uInt8
>( nAlign
, 8, 2 ) );
1320 maModel
.mbWrapText
= getFlag( nAlign
, BIFF_XF_WRAPTEXT
);
1323 void Alignment::setBiff8Data( sal_uInt16 nAlign
, sal_uInt16 nMiscAttrib
)
1325 maModel
.setBinHorAlign( extractValue
< sal_uInt8
>( nAlign
, 0, 3 ) );
1326 maModel
.setBinVerAlign( extractValue
< sal_uInt8
>( nAlign
, 4, 3 ) );
1327 maModel
.mnTextDir
= extractValue
< sal_Int32
>( nMiscAttrib
, 6, 2 ); // new in BIFF8
1328 maModel
.mnRotation
= extractValue
< sal_Int32
>( nAlign
, 8, 8 ); // new in BIFF8
1329 maModel
.mnIndent
= extractValue
< sal_uInt8
>( nMiscAttrib
, 0, 4 ); // new in BIFF8
1330 maModel
.mbWrapText
= getFlag( nAlign
, BIFF_XF_WRAPTEXT
);
1331 maModel
.mbShrink
= getFlag( nMiscAttrib
, BIFF_XF_SHRINK
); // new in BIFF8
1332 maModel
.mbJustLastLine
= getFlag( nAlign
, BIFF_XF_JUSTLASTLINE
); // new in BIFF8(?)
1335 void Alignment::finalizeImport()
1337 namespace csstab
= ::com::sun::star::table
;
1338 namespace csstxt
= ::com::sun::star::text
;
1340 // horizontal alignment
1341 switch( maModel
.mnHorAlign
)
1343 case XML_center
: maApiData
.meHorJustify
= csstab::CellHoriJustify_CENTER
; break;
1344 case XML_centerContinuous
: maApiData
.meHorJustify
= csstab::CellHoriJustify_CENTER
; break;
1345 case XML_distributed
: maApiData
.meHorJustify
= csstab::CellHoriJustify_BLOCK
; break;
1346 case XML_fill
: maApiData
.meHorJustify
= csstab::CellHoriJustify_REPEAT
; break;
1347 case XML_general
: maApiData
.meHorJustify
= csstab::CellHoriJustify_STANDARD
; break;
1348 case XML_justify
: maApiData
.meHorJustify
= csstab::CellHoriJustify_BLOCK
; break;
1349 case XML_left
: maApiData
.meHorJustify
= csstab::CellHoriJustify_LEFT
; break;
1350 case XML_right
: maApiData
.meHorJustify
= csstab::CellHoriJustify_RIGHT
; break;
1353 // vertical alignment
1354 switch( maModel
.mnVerAlign
)
1356 case XML_bottom
: maApiData
.meVerJustify
= csstab::CellVertJustify_BOTTOM
; break;
1357 case XML_center
: maApiData
.meVerJustify
= csstab::CellVertJustify_CENTER
; break;
1358 case XML_distributed
: maApiData
.meVerJustify
= csstab::CellVertJustify_TOP
; break;
1359 case XML_justify
: maApiData
.meVerJustify
= csstab::CellVertJustify_TOP
; break;
1360 case XML_top
: maApiData
.meVerJustify
= csstab::CellVertJustify_TOP
; break;
1363 /* indentation: expressed as number of blocks of 3 space characters in
1364 OOX, and as multiple of 10 points in BIFF. */
1365 sal_Int32 nIndent
= 0;
1366 switch( getFilterType() )
1368 case FILTER_OOX
: nIndent
= getUnitConverter().scaleToMm100( 3.0 * maModel
.mnIndent
, UNIT_SPACE
); break;
1369 case FILTER_BIFF
: nIndent
= getUnitConverter().scaleToMm100( 10.0 * maModel
.mnIndent
, UNIT_POINT
); break;
1370 case FILTER_UNKNOWN
: break;
1372 if( (0 <= nIndent
) && (nIndent
<= SAL_MAX_INT16
) )
1373 maApiData
.mnIndent
= static_cast< sal_Int16
>( nIndent
);
1375 // complex text direction
1376 switch( maModel
.mnTextDir
)
1378 case OOX_XF_TEXTDIR_CONTEXT
: maApiData
.mnWritingMode
= csstxt::WritingMode2::PAGE
; break;
1379 case OOX_XF_TEXTDIR_LTR
: maApiData
.mnWritingMode
= csstxt::WritingMode2::LR_TB
; break;
1380 case OOX_XF_TEXTDIR_RTL
: maApiData
.mnWritingMode
= csstxt::WritingMode2::RL_TB
; break;
1383 // rotation: 0-90 means 0 to 90 degrees ccw, 91-180 means 1 to 90 degrees cw, 255 means stacked
1384 sal_Int32 nOoxRot
= maModel
.mnRotation
;
1385 maApiData
.mnRotation
= ((0 <= nOoxRot
) && (nOoxRot
<= 90)) ?
1387 (((91 <= nOoxRot
) && (nOoxRot
<= 180)) ? (100 * (450 - nOoxRot
)) : 0);
1389 // "Orientation" property used for character stacking
1390 maApiData
.meOrientation
= (nOoxRot
== OOX_XF_ROTATION_STACKED
) ?
1391 csstab::CellOrientation_STACKED
: csstab::CellOrientation_STANDARD
;
1393 // alignment flags (#i84960 automatic line break, if vertically justified/distributed)
1394 maApiData
.mbWrapText
= maModel
.mbWrapText
|| (maModel
.mnVerAlign
== XML_distributed
) || (maModel
.mnVerAlign
== XML_justify
);
1395 maApiData
.mbShrink
= maModel
.mbShrink
;
1399 void Alignment::writeToPropertyMap( PropertyMap
& rPropMap
) const
1401 rPropMap
[ PROP_HoriJustify
] <<= maApiData
.meHorJustify
;
1402 rPropMap
[ PROP_VertJustify
] <<= maApiData
.meVerJustify
;
1403 rPropMap
[ PROP_WritingMode
] <<= maApiData
.mnWritingMode
;
1404 rPropMap
[ PROP_RotateAngle
] <<= maApiData
.mnRotation
;
1405 rPropMap
[ PROP_RotateReference
] <<= ::com::sun::star::table::CellVertJustify_STANDARD
; // rotation reference
1406 rPropMap
[ PROP_Orientation
] <<= maApiData
.meOrientation
;
1407 rPropMap
[ PROP_ParaIndent
] <<= maApiData
.mnIndent
;
1408 rPropMap
[ PROP_IsTextWrapped
] <<= maApiData
.mbWrapText
;
1409 rPropMap
[ PROP_ShrinkToFit
] <<= maApiData
.mbShrink
;
1412 // ============================================================================
1414 ProtectionModel::ProtectionModel() :
1415 mbLocked( true ), // default in Excel and Calc
1420 // ----------------------------------------------------------------------------
1422 ApiProtectionData::ApiProtectionData() :
1423 maCellProt( sal_True
, sal_False
, sal_False
, sal_False
)
1427 bool operator==( const ApiProtectionData
& rLeft
, const ApiProtectionData
& rRight
)
1430 (rLeft
.maCellProt
.IsLocked
== rRight
.maCellProt
.IsLocked
) &&
1431 (rLeft
.maCellProt
.IsFormulaHidden
== rRight
.maCellProt
.IsFormulaHidden
) &&
1432 (rLeft
.maCellProt
.IsHidden
== rRight
.maCellProt
.IsHidden
) &&
1433 (rLeft
.maCellProt
.IsPrintHidden
== rRight
.maCellProt
.IsPrintHidden
);
1436 // ============================================================================
1438 Protection::Protection( const WorkbookHelper
& rHelper
) :
1439 WorkbookHelper( rHelper
)
1443 void Protection::importProtection( const AttributeList
& rAttribs
)
1445 maModel
.mbLocked
= rAttribs
.getBool( XML_locked
, true );
1446 maModel
.mbHidden
= rAttribs
.getBool( XML_hidden
, false );
1449 void Protection::setBinData( sal_uInt32 nFlags
)
1451 maModel
.mbLocked
= getFlag( nFlags
, OOBIN_XF_LOCKED
);
1452 maModel
.mbHidden
= getFlag( nFlags
, OOBIN_XF_HIDDEN
);
1455 void Protection::setBiff2Data( sal_uInt8 nNumFmt
)
1457 maModel
.mbLocked
= getFlag( nNumFmt
, BIFF2_XF_LOCKED
);
1458 maModel
.mbHidden
= getFlag( nNumFmt
, BIFF2_XF_HIDDEN
);
1461 void Protection::setBiff3Data( sal_uInt16 nProt
)
1463 maModel
.mbLocked
= getFlag( nProt
, BIFF_XF_LOCKED
);
1464 maModel
.mbHidden
= getFlag( nProt
, BIFF_XF_HIDDEN
);
1467 void Protection::finalizeImport()
1469 maApiData
.maCellProt
.IsLocked
= maModel
.mbLocked
;
1470 maApiData
.maCellProt
.IsFormulaHidden
= maModel
.mbHidden
;
1473 void Protection::writeToPropertyMap( PropertyMap
& rPropMap
) const
1475 rPropMap
[ PROP_CellProtection
] <<= maApiData
.maCellProt
;
1478 // ============================================================================
1480 BorderLineModel::BorderLineModel( bool bDxf
) :
1481 mnStyle( XML_none
),
1484 maColor
.setIndexed( OOX_COLOR_WINDOWTEXT
);
1487 void BorderLineModel::setBiffStyle( sal_Int32 nLineStyle
)
1489 static const sal_Int32 spnStyleIds
[] = {
1490 XML_none
, XML_thin
, XML_medium
, XML_dashed
,
1491 XML_dotted
, XML_thick
, XML_double
, XML_hair
,
1492 XML_mediumDashed
, XML_dashDot
, XML_mediumDashDot
, XML_dashDotDot
,
1493 XML_mediumDashDotDot
, XML_slantDashDot
};
1494 mnStyle
= STATIC_ARRAY_SELECT( spnStyleIds
, nLineStyle
, XML_none
);
1497 void BorderLineModel::setBiffData( sal_uInt8 nLineStyle
, sal_uInt16 nLineColor
)
1499 maColor
.setIndexed( nLineColor
);
1500 setBiffStyle( nLineStyle
);
1503 // ----------------------------------------------------------------------------
1505 BorderModel::BorderModel( bool bDxf
) :
1511 mbDiagTLtoBR( false ),
1512 mbDiagBLtoTR( false )
1516 // ----------------------------------------------------------------------------
1518 ApiBorderData::ApiBorderData() :
1519 mbBorderUsed( false ),
1524 // ============================================================================
1528 inline void lclSetBorderLineWidth( BorderLine
& rBorderLine
,
1529 sal_Int16 nOuter
, sal_Int16 nDist
= API_LINE_NONE
, sal_Int16 nInner
= API_LINE_NONE
)
1531 rBorderLine
.OuterLineWidth
= nOuter
;
1532 rBorderLine
.LineDistance
= nDist
;
1533 rBorderLine
.InnerLineWidth
= nInner
;
1536 inline sal_Int32
lclGetBorderLineWidth( const BorderLine
& rBorderLine
)
1538 return rBorderLine
.OuterLineWidth
+ rBorderLine
.LineDistance
+ rBorderLine
.InnerLineWidth
;
1541 const BorderLine
* lclGetThickerLine( const BorderLine
& rBorderLine1
, sal_Bool bValid1
, const BorderLine
& rBorderLine2
, sal_Bool bValid2
)
1543 if( bValid1
&& bValid2
)
1544 return (lclGetBorderLineWidth( rBorderLine1
) < lclGetBorderLineWidth( rBorderLine2
)) ? &rBorderLine2
: &rBorderLine1
;
1546 return &rBorderLine1
;
1548 return &rBorderLine2
;
1554 // ----------------------------------------------------------------------------
1556 Border::Border( const WorkbookHelper
& rHelper
, bool bDxf
) :
1557 WorkbookHelper( rHelper
),
1563 void Border::importBorder( const AttributeList
& rAttribs
)
1565 maModel
.mbDiagTLtoBR
= rAttribs
.getBool( XML_diagonalDown
, false );
1566 maModel
.mbDiagBLtoTR
= rAttribs
.getBool( XML_diagonalUp
, false );
1569 void Border::importStyle( sal_Int32 nElement
, const AttributeList
& rAttribs
)
1571 if( BorderLineModel
* pBorderLine
= getBorderLine( nElement
) )
1573 pBorderLine
->mnStyle
= rAttribs
.getToken( XML_style
, XML_none
);
1574 pBorderLine
->mbUsed
= true;
1578 void Border::importColor( sal_Int32 nElement
, const AttributeList
& rAttribs
)
1580 if( BorderLineModel
* pBorderLine
= getBorderLine( nElement
) )
1581 pBorderLine
->maColor
.importColor( rAttribs
);
1584 void Border::importBorder( RecordInputStream
& rStrm
)
1586 sal_uInt8 nFlags
= rStrm
.readuInt8();
1587 maModel
.mbDiagTLtoBR
= getFlag( nFlags
, OOBIN_BORDER_DIAG_TLBR
);
1588 maModel
.mbDiagBLtoTR
= getFlag( nFlags
, OOBIN_BORDER_DIAG_BLTR
);
1589 maModel
.maTop
.setBiffStyle( rStrm
.readuInt16() );
1590 rStrm
>> maModel
.maTop
.maColor
;
1591 maModel
.maBottom
.setBiffStyle( rStrm
.readuInt16() );
1592 rStrm
>> maModel
.maBottom
.maColor
;
1593 maModel
.maLeft
.setBiffStyle( rStrm
.readuInt16() );
1594 rStrm
>> maModel
.maLeft
.maColor
;
1595 maModel
.maRight
.setBiffStyle( rStrm
.readuInt16() );
1596 rStrm
>> maModel
.maRight
.maColor
;
1597 maModel
.maDiagonal
.setBiffStyle( rStrm
.readuInt16() );
1598 rStrm
>> maModel
.maDiagonal
.maColor
;
1601 void Border::importDxfBorder( sal_Int32 nElement
, RecordInputStream
& rStrm
)
1603 OSL_ENSURE( mbDxf
, "Border::importDxfBorder - missing conditional formatting flag" );
1604 if( BorderLineModel
* pBorderLine
= getBorderLine( nElement
) )
1607 rStrm
>> pBorderLine
->maColor
>> nStyle
;
1608 pBorderLine
->setBiffStyle( nStyle
);
1609 pBorderLine
->mbUsed
= true;
1613 void Border::setBiff2Data( sal_uInt8 nFlags
)
1615 OSL_ENSURE( !mbDxf
, "Border::setBiff2Data - unexpected conditional formatting flag" );
1616 maModel
.maLeft
.setBiffData( getFlagValue( nFlags
, BIFF2_XF_LEFTLINE
, BIFF_LINE_THIN
, BIFF_LINE_NONE
), BIFF2_COLOR_BLACK
);
1617 maModel
.maRight
.setBiffData( getFlagValue( nFlags
, BIFF2_XF_RIGHTLINE
, BIFF_LINE_THIN
, BIFF_LINE_NONE
), BIFF2_COLOR_BLACK
);
1618 maModel
.maTop
.setBiffData( getFlagValue( nFlags
, BIFF2_XF_TOPLINE
, BIFF_LINE_THIN
, BIFF_LINE_NONE
), BIFF2_COLOR_BLACK
);
1619 maModel
.maBottom
.setBiffData( getFlagValue( nFlags
, BIFF2_XF_BOTTOMLINE
, BIFF_LINE_THIN
, BIFF_LINE_NONE
), BIFF2_COLOR_BLACK
);
1620 maModel
.maDiagonal
.mbUsed
= false;
1623 void Border::setBiff3Data( sal_uInt32 nBorder
)
1625 OSL_ENSURE( !mbDxf
, "Border::setBiff3Data - unexpected conditional formatting flag" );
1626 maModel
.maLeft
.setBiffData( extractValue
< sal_uInt8
>( nBorder
, 8, 3 ), extractValue
< sal_uInt16
>( nBorder
, 11, 5 ) );
1627 maModel
.maRight
.setBiffData( extractValue
< sal_uInt8
>( nBorder
, 24, 3 ), extractValue
< sal_uInt16
>( nBorder
, 27, 5 ) );
1628 maModel
.maTop
.setBiffData( extractValue
< sal_uInt8
>( nBorder
, 0, 3 ), extractValue
< sal_uInt16
>( nBorder
, 3, 5 ) );
1629 maModel
.maBottom
.setBiffData( extractValue
< sal_uInt8
>( nBorder
, 16, 3 ), extractValue
< sal_uInt16
>( nBorder
, 19, 5 ) );
1630 maModel
.maDiagonal
.mbUsed
= false;
1633 void Border::setBiff5Data( sal_uInt32 nBorder
, sal_uInt32 nArea
)
1635 OSL_ENSURE( !mbDxf
, "Border::setBiff5Data - unexpected conditional formatting flag" );
1636 maModel
.maLeft
.setBiffData( extractValue
< sal_uInt8
>( nBorder
, 3, 3 ), extractValue
< sal_uInt16
>( nBorder
, 16, 7 ) );
1637 maModel
.maRight
.setBiffData( extractValue
< sal_uInt8
>( nBorder
, 6, 3 ), extractValue
< sal_uInt16
>( nBorder
, 23, 7 ) );
1638 maModel
.maTop
.setBiffData( extractValue
< sal_uInt8
>( nBorder
, 0, 3 ), extractValue
< sal_uInt16
>( nBorder
, 9, 7 ) );
1639 maModel
.maBottom
.setBiffData( extractValue
< sal_uInt8
>( nArea
, 22, 3 ), extractValue
< sal_uInt16
>( nArea
, 25, 7 ) );
1640 maModel
.maDiagonal
.mbUsed
= false;
1643 void Border::setBiff8Data( sal_uInt32 nBorder1
, sal_uInt32 nBorder2
)
1645 OSL_ENSURE( !mbDxf
, "Border::setBiff8Data - unexpected conditional formatting flag" );
1646 maModel
.maLeft
.setBiffData( extractValue
< sal_uInt8
>( nBorder1
, 0, 4 ), extractValue
< sal_uInt16
>( nBorder1
, 16, 7 ) );
1647 maModel
.maRight
.setBiffData( extractValue
< sal_uInt8
>( nBorder1
, 4, 4 ), extractValue
< sal_uInt16
>( nBorder1
, 23, 7 ) );
1648 maModel
.maTop
.setBiffData( extractValue
< sal_uInt8
>( nBorder1
, 8, 4 ), extractValue
< sal_uInt16
>( nBorder2
, 0, 7 ) );
1649 maModel
.maBottom
.setBiffData( extractValue
< sal_uInt8
>( nBorder1
, 12, 4 ), extractValue
< sal_uInt16
>( nBorder2
, 7, 7 ) );
1650 maModel
.mbDiagTLtoBR
= getFlag( nBorder1
, BIFF_XF_DIAG_TLBR
);
1651 maModel
.mbDiagBLtoTR
= getFlag( nBorder1
, BIFF_XF_DIAG_BLTR
);
1652 if( maModel
.mbDiagTLtoBR
|| maModel
.mbDiagBLtoTR
)
1653 maModel
.maDiagonal
.setBiffData( extractValue
< sal_uInt8
>( nBorder2
, 21, 4 ), extractValue
< sal_uInt16
>( nBorder2
, 14, 7 ) );
1656 void Border::importCfRule( BiffInputStream
& rStrm
, sal_uInt32 nFlags
)
1658 OSL_ENSURE( mbDxf
, "Border::importCfRule - missing conditional formatting flag" );
1659 OSL_ENSURE( getFlag( nFlags
, BIFF_CFRULE_BORDERBLOCK
), "Border::importCfRule - missing border block flag" );
1662 rStrm
>> nStyle
>> nColor
;
1664 maModel
.maLeft
.setBiffData( extractValue
< sal_uInt8
>( nStyle
, 0, 4 ), extractValue
< sal_uInt16
>( nColor
, 0, 7 ) );
1665 maModel
.maRight
.setBiffData( extractValue
< sal_uInt8
>( nStyle
, 4, 4 ), extractValue
< sal_uInt16
>( nColor
, 7, 7 ) );
1666 maModel
.maTop
.setBiffData( extractValue
< sal_uInt8
>( nStyle
, 8, 4 ), extractValue
< sal_uInt16
>( nColor
, 16, 7 ) );
1667 maModel
.maBottom
.setBiffData( extractValue
< sal_uInt8
>( nStyle
, 12, 4 ), extractValue
< sal_uInt16
>( nColor
, 23, 7 ) );
1668 maModel
.maLeft
.mbUsed
= !getFlag( nFlags
, BIFF_CFRULE_BORDER_LEFT
);
1669 maModel
.maRight
.mbUsed
= !getFlag( nFlags
, BIFF_CFRULE_BORDER_RIGHT
);
1670 maModel
.maTop
.mbUsed
= !getFlag( nFlags
, BIFF_CFRULE_BORDER_TOP
);
1671 maModel
.maBottom
.mbUsed
= !getFlag( nFlags
, BIFF_CFRULE_BORDER_BOTTOM
);
1674 void Border::finalizeImport()
1676 maApiData
.mbBorderUsed
= maModel
.maLeft
.mbUsed
|| maModel
.maRight
.mbUsed
|| maModel
.maTop
.mbUsed
|| maModel
.maBottom
.mbUsed
;
1677 maApiData
.mbDiagUsed
= maModel
.maDiagonal
.mbUsed
;
1679 maApiData
.maBorder
.IsLeftLineValid
= convertBorderLine( maApiData
.maBorder
.LeftLine
, maModel
.maLeft
);
1680 maApiData
.maBorder
.IsRightLineValid
= convertBorderLine( maApiData
.maBorder
.RightLine
, maModel
.maRight
);
1681 maApiData
.maBorder
.IsTopLineValid
= convertBorderLine( maApiData
.maBorder
.TopLine
, maModel
.maTop
);
1682 maApiData
.maBorder
.IsBottomLineValid
= convertBorderLine( maApiData
.maBorder
.BottomLine
, maModel
.maBottom
);
1686 maApiData
.maBorder
.IsVerticalLineValid
= maApiData
.maBorder
.IsLeftLineValid
|| maApiData
.maBorder
.IsRightLineValid
;
1687 if( const BorderLine
* pVertLine
= lclGetThickerLine( maApiData
.maBorder
.LeftLine
, maApiData
.maBorder
.IsLeftLineValid
, maApiData
.maBorder
.RightLine
, maApiData
.maBorder
.IsRightLineValid
) )
1688 maApiData
.maBorder
.VerticalLine
= *pVertLine
;
1690 maApiData
.maBorder
.IsHorizontalLineValid
= maApiData
.maBorder
.IsTopLineValid
|| maApiData
.maBorder
.IsBottomLineValid
;
1691 if( const BorderLine
* pHorLine
= lclGetThickerLine( maApiData
.maBorder
.TopLine
, maApiData
.maBorder
.IsTopLineValid
, maApiData
.maBorder
.BottomLine
, maApiData
.maBorder
.IsBottomLineValid
) )
1692 maApiData
.maBorder
.HorizontalLine
= *pHorLine
;
1695 if( maModel
.mbDiagTLtoBR
)
1696 convertBorderLine( maApiData
.maTLtoBR
, maModel
.maDiagonal
);
1697 if( maModel
.mbDiagBLtoTR
)
1698 convertBorderLine( maApiData
.maBLtoTR
, maModel
.maDiagonal
);
1701 void Border::writeToPropertyMap( PropertyMap
& rPropMap
) const
1703 if( maApiData
.mbBorderUsed
)
1704 rPropMap
[ PROP_TableBorder
] <<= maApiData
.maBorder
;
1705 if( maApiData
.mbDiagUsed
)
1707 rPropMap
[ PROP_DiagonalTLBR
] <<= maApiData
.maTLtoBR
;
1708 rPropMap
[ PROP_DiagonalBLTR
] <<= maApiData
.maBLtoTR
;
1712 BorderLineModel
* Border::getBorderLine( sal_Int32 nElement
)
1716 case XLS_TOKEN( left
): return &maModel
.maLeft
;
1717 case XLS_TOKEN( right
): return &maModel
.maRight
;
1718 case XLS_TOKEN( top
): return &maModel
.maTop
;
1719 case XLS_TOKEN( bottom
): return &maModel
.maBottom
;
1720 case XLS_TOKEN( diagonal
): return &maModel
.maDiagonal
;
1725 bool Border::convertBorderLine( BorderLine
& rBorderLine
, const BorderLineModel
& rModel
)
1727 rBorderLine
.Color
= rModel
.maColor
.getColor( getBaseFilter(), API_RGB_BLACK
);
1728 switch( rModel
.mnStyle
)
1730 case XML_dashDot
: lclSetBorderLineWidth( rBorderLine
, API_LINE_THIN
); break;
1731 case XML_dashDotDot
: lclSetBorderLineWidth( rBorderLine
, API_LINE_THIN
); break;
1732 case XML_dashed
: lclSetBorderLineWidth( rBorderLine
, API_LINE_THIN
); break;
1733 case XML_dotted
: lclSetBorderLineWidth( rBorderLine
, API_LINE_THIN
); break;
1734 case XML_double
: lclSetBorderLineWidth( rBorderLine
, API_LINE_THIN
, API_LINE_THIN
, API_LINE_THIN
); break;
1735 case XML_hair
: lclSetBorderLineWidth( rBorderLine
, API_LINE_HAIR
); break;
1736 case XML_medium
: lclSetBorderLineWidth( rBorderLine
, API_LINE_MEDIUM
); break;
1737 case XML_mediumDashDot
: lclSetBorderLineWidth( rBorderLine
, API_LINE_MEDIUM
); break;
1738 case XML_mediumDashDotDot
: lclSetBorderLineWidth( rBorderLine
, API_LINE_MEDIUM
); break;
1739 case XML_mediumDashed
: lclSetBorderLineWidth( rBorderLine
, API_LINE_MEDIUM
); break;
1740 case XML_none
: lclSetBorderLineWidth( rBorderLine
, API_LINE_NONE
); break;
1741 case XML_slantDashDot
: lclSetBorderLineWidth( rBorderLine
, API_LINE_MEDIUM
); break;
1742 case XML_thick
: lclSetBorderLineWidth( rBorderLine
, API_LINE_THICK
); break;
1743 case XML_thin
: lclSetBorderLineWidth( rBorderLine
, API_LINE_THIN
); break;
1744 default: lclSetBorderLineWidth( rBorderLine
, API_LINE_NONE
); break;
1746 return rModel
.mbUsed
;
1750 // ============================================================================
1752 PatternFillModel::PatternFillModel( bool bDxf
) :
1753 mnPattern( XML_none
),
1754 mbPattColorUsed( !bDxf
),
1755 mbFillColorUsed( !bDxf
),
1756 mbPatternUsed( !bDxf
)
1758 maPatternColor
.setIndexed( OOX_COLOR_WINDOWTEXT
);
1759 maFillColor
.setIndexed( OOX_COLOR_WINDOWBACK
);
1762 void PatternFillModel::setBinPattern( sal_Int32 nPattern
)
1764 static const sal_Int32 spnPatternIds
[] = {
1765 XML_none
, XML_solid
, XML_mediumGray
, XML_darkGray
,
1766 XML_lightGray
, XML_darkHorizontal
, XML_darkVertical
, XML_darkDown
,
1767 XML_darkUp
, XML_darkGrid
, XML_darkTrellis
, XML_lightHorizontal
,
1768 XML_lightVertical
, XML_lightDown
, XML_lightUp
, XML_lightGrid
,
1769 XML_lightTrellis
, XML_gray125
, XML_gray0625
};
1770 mnPattern
= STATIC_ARRAY_SELECT( spnPatternIds
, nPattern
, XML_none
);
1773 void PatternFillModel::setBiffData( sal_uInt16 nPatternColor
, sal_uInt16 nFillColor
, sal_uInt8 nPattern
)
1775 maPatternColor
.setIndexed( nPatternColor
);
1776 maFillColor
.setIndexed( nFillColor
);
1777 // patterns equal in BIFF and OOBIN
1778 setBinPattern( nPattern
);
1781 // ----------------------------------------------------------------------------
1783 GradientFillModel::GradientFillModel() :
1784 mnType( XML_linear
),
1793 void GradientFillModel::readGradient( RecordInputStream
& rStrm
)
1796 rStrm
>> nType
>> mfAngle
>> mfLeft
>> mfRight
>> mfTop
>> mfBottom
;
1797 static const sal_Int32 spnTypes
[] = { XML_linear
, XML_path
};
1798 mnType
= STATIC_ARRAY_SELECT( spnTypes
, nType
, XML_TOKEN_INVALID
);
1801 void GradientFillModel::readGradientStop( RecordInputStream
& rStrm
, bool bDxf
)
1808 rStrm
>> fPosition
>> aColor
;
1812 rStrm
>> aColor
>> fPosition
;
1814 if( !rStrm
.isEof() && (fPosition
>= 0.0) )
1815 maColors
[ fPosition
] = aColor
;
1818 // ----------------------------------------------------------------------------
1820 ApiSolidFillData::ApiSolidFillData() :
1821 mnColor( API_RGB_TRANSPARENT
),
1822 mbTransparent( true ),
1827 // ============================================================================
1831 inline sal_Int32
lclGetMixedColorComp( sal_Int32 nPatt
, sal_Int32 nFill
, sal_Int32 nAlpha
)
1833 return ((nPatt
- nFill
) * nAlpha
) / 0x80 + nFill
;
1836 sal_Int32
lclGetMixedColor( sal_Int32 nPattColor
, sal_Int32 nFillColor
, sal_Int32 nAlpha
)
1839 (lclGetMixedColorComp( nPattColor
& 0xFF0000, nFillColor
& 0xFF0000, nAlpha
) & 0xFF0000) |
1840 (lclGetMixedColorComp( nPattColor
& 0x00FF00, nFillColor
& 0x00FF00, nAlpha
) & 0x00FF00) |
1841 (lclGetMixedColorComp( nPattColor
& 0x0000FF, nFillColor
& 0x0000FF, nAlpha
) & 0x0000FF);
1846 // ----------------------------------------------------------------------------
1848 Fill::Fill( const WorkbookHelper
& rHelper
, bool bDxf
) :
1849 WorkbookHelper( rHelper
),
1854 void Fill::importPatternFill( const AttributeList
& rAttribs
)
1856 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1857 mxPatternModel
->mnPattern
= rAttribs
.getToken( XML_patternType
, XML_none
);
1859 mxPatternModel
->mbPatternUsed
= rAttribs
.hasAttribute( XML_patternType
);
1862 void Fill::importFgColor( const AttributeList
& rAttribs
)
1864 OSL_ENSURE( mxPatternModel
.get(), "Fill::importFgColor - missing pattern data" );
1865 if( mxPatternModel
.get() )
1867 mxPatternModel
->maPatternColor
.importColor( rAttribs
);
1868 mxPatternModel
->mbPattColorUsed
= true;
1872 void Fill::importBgColor( const AttributeList
& rAttribs
)
1874 OSL_ENSURE( mxPatternModel
.get(), "Fill::importBgColor - missing pattern data" );
1875 if( mxPatternModel
.get() )
1877 mxPatternModel
->maFillColor
.importColor( rAttribs
);
1878 mxPatternModel
->mbFillColorUsed
= true;
1882 void Fill::importGradientFill( const AttributeList
& rAttribs
)
1884 mxGradientModel
.reset( new GradientFillModel
);
1885 mxGradientModel
->mnType
= rAttribs
.getToken( XML_type
, XML_linear
);
1886 mxGradientModel
->mfAngle
= rAttribs
.getDouble( XML_degree
, 0.0 );
1887 mxGradientModel
->mfLeft
= rAttribs
.getDouble( XML_left
, 0.0 );
1888 mxGradientModel
->mfRight
= rAttribs
.getDouble( XML_right
, 0.0 );
1889 mxGradientModel
->mfTop
= rAttribs
.getDouble( XML_top
, 0.0 );
1890 mxGradientModel
->mfBottom
= rAttribs
.getDouble( XML_bottom
, 0.0 );
1893 void Fill::importColor( const AttributeList
& rAttribs
, double fPosition
)
1895 OSL_ENSURE( mxGradientModel
.get(), "Fill::importColor - missing gradient data" );
1896 if( mxGradientModel
.get() && (fPosition
>= 0.0) )
1897 mxGradientModel
->maColors
[ fPosition
].importColor( rAttribs
);
1900 void Fill::importFill( RecordInputStream
& rStrm
)
1902 OSL_ENSURE( !mbDxf
, "Fill::importFill - unexpected conditional formatting flag" );
1903 sal_Int32 nPattern
= rStrm
.readInt32();
1904 if( nPattern
== OOBIN_FILL_GRADIENT
)
1906 mxGradientModel
.reset( new GradientFillModel
);
1907 sal_Int32 nStopCount
;
1909 mxGradientModel
->readGradient( rStrm
);
1910 rStrm
>> nStopCount
;
1911 for( sal_Int32 nStop
= 0; (nStop
< nStopCount
) && !rStrm
.isEof(); ++nStop
)
1912 mxGradientModel
->readGradientStop( rStrm
, false );
1916 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1917 mxPatternModel
->setBinPattern( nPattern
);
1918 rStrm
>> mxPatternModel
->maPatternColor
>> mxPatternModel
->maFillColor
;
1922 void Fill::importDxfPattern( RecordInputStream
& rStrm
)
1924 OSL_ENSURE( mbDxf
, "Fill::importDxfPattern - missing conditional formatting flag" );
1925 if( !mxPatternModel
)
1926 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1927 mxPatternModel
->setBinPattern( rStrm
.readuInt8() );
1928 mxPatternModel
->mbPatternUsed
= true;
1931 void Fill::importDxfFgColor( RecordInputStream
& rStrm
)
1933 OSL_ENSURE( mbDxf
, "Fill::importDxfFgColor - missing conditional formatting flag" );
1934 if( !mxPatternModel
)
1935 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1936 mxPatternModel
->maPatternColor
.importColor( rStrm
);
1937 mxPatternModel
->mbPattColorUsed
= true;
1940 void Fill::importDxfBgColor( RecordInputStream
& rStrm
)
1942 OSL_ENSURE( mbDxf
, "Fill::importDxfBgColor - missing conditional formatting flag" );
1943 if( !mxPatternModel
)
1944 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1945 mxPatternModel
->maFillColor
.importColor( rStrm
);
1946 mxPatternModel
->mbFillColorUsed
= true;
1949 void Fill::importDxfGradient( RecordInputStream
& rStrm
)
1951 OSL_ENSURE( mbDxf
, "Fill::importDxfGradient - missing conditional formatting flag" );
1952 if( !mxGradientModel
)
1953 mxGradientModel
.reset( new GradientFillModel
);
1954 mxGradientModel
->readGradient( rStrm
);
1957 void Fill::importDxfStop( RecordInputStream
& rStrm
)
1959 OSL_ENSURE( mbDxf
, "Fill::importDxfStop - missing conditional formatting flag" );
1960 if( !mxGradientModel
)
1961 mxGradientModel
.reset( new GradientFillModel
);
1962 mxGradientModel
->readGradientStop( rStrm
, true );
1965 void Fill::setBiff2Data( sal_uInt8 nFlags
)
1967 OSL_ENSURE( !mbDxf
, "Fill::setBiff2Data - unexpected conditional formatting flag" );
1968 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1969 mxPatternModel
->setBiffData(
1972 getFlagValue( nFlags
, BIFF2_XF_BACKGROUND
, BIFF_PATT_125
, BIFF_PATT_NONE
) );
1975 void Fill::setBiff3Data( sal_uInt16 nArea
)
1977 OSL_ENSURE( !mbDxf
, "Fill::setBiff3Data - unexpected conditional formatting flag" );
1978 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1979 mxPatternModel
->setBiffData(
1980 extractValue
< sal_uInt16
>( nArea
, 6, 5 ),
1981 extractValue
< sal_uInt16
>( nArea
, 11, 5 ),
1982 extractValue
< sal_uInt8
>( nArea
, 0, 6 ) );
1985 void Fill::setBiff5Data( sal_uInt32 nArea
)
1987 OSL_ENSURE( !mbDxf
, "Fill::setBiff5Data - unexpected conditional formatting flag" );
1988 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1989 mxPatternModel
->setBiffData(
1990 extractValue
< sal_uInt16
>( nArea
, 0, 7 ),
1991 extractValue
< sal_uInt16
>( nArea
, 7, 7 ),
1992 extractValue
< sal_uInt8
>( nArea
, 16, 6 ) );
1995 void Fill::setBiff8Data( sal_uInt32 nBorder2
, sal_uInt16 nArea
)
1997 OSL_ENSURE( !mbDxf
, "Fill::setBiff8Data - unexpected conditional formatting flag" );
1998 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
1999 mxPatternModel
->setBiffData(
2000 extractValue
< sal_uInt16
>( nArea
, 0, 7 ),
2001 extractValue
< sal_uInt16
>( nArea
, 7, 7 ),
2002 extractValue
< sal_uInt8
>( nBorder2
, 26, 6 ) );
2005 void Fill::importCfRule( BiffInputStream
& rStrm
, sal_uInt32 nFlags
)
2007 OSL_ENSURE( mbDxf
, "Fill::importCfRule - missing conditional formatting flag" );
2008 OSL_ENSURE( getFlag( nFlags
, BIFF_CFRULE_FILLBLOCK
), "Fill::importCfRule - missing fill block flag" );
2009 mxPatternModel
.reset( new PatternFillModel( mbDxf
) );
2010 sal_uInt32 nFillData
;
2012 mxPatternModel
->setBiffData(
2013 extractValue
< sal_uInt16
>( nFillData
, 16, 7 ),
2014 extractValue
< sal_uInt16
>( nFillData
, 23, 7 ),
2015 extractValue
< sal_uInt8
>( nFillData
, 10, 6 ) );
2016 mxPatternModel
->mbPattColorUsed
= !getFlag( nFlags
, BIFF_CFRULE_FILL_PATTCOLOR
);
2017 mxPatternModel
->mbFillColorUsed
= !getFlag( nFlags
, BIFF_CFRULE_FILL_FILLCOLOR
);
2018 mxPatternModel
->mbPatternUsed
= !getFlag( nFlags
, BIFF_CFRULE_FILL_PATTERN
);
2021 void Fill::finalizeImport()
2023 const FilterBase
& rFilter
= getBaseFilter();
2025 if( mxPatternModel
.get() )
2027 // finalize the OOX data struct
2028 PatternFillModel
& rModel
= *mxPatternModel
;
2031 if( rModel
.mbFillColorUsed
&& (!rModel
.mbPatternUsed
|| (rModel
.mnPattern
== XML_solid
)) )
2033 rModel
.maPatternColor
= rModel
.maFillColor
;
2034 rModel
.mnPattern
= XML_solid
;
2035 rModel
.mbPattColorUsed
= rModel
.mbPatternUsed
= true;
2037 else if( !rModel
.mbFillColorUsed
&& rModel
.mbPatternUsed
&& (rModel
.mnPattern
== XML_solid
) )
2039 rModel
.mbPatternUsed
= false;
2043 // convert to API fill settings
2044 maApiData
.mbUsed
= rModel
.mbPatternUsed
;
2045 if( rModel
.mnPattern
== XML_none
)
2047 maApiData
.mnColor
= API_RGB_TRANSPARENT
;
2048 maApiData
.mbTransparent
= true;
2052 sal_Int32 nAlpha
= 0x80;
2053 switch( rModel
.mnPattern
)
2055 case XML_darkDown
: nAlpha
= 0x40; break;
2056 case XML_darkGray
: nAlpha
= 0x60; break;
2057 case XML_darkGrid
: nAlpha
= 0x40; break;
2058 case XML_darkHorizontal
: nAlpha
= 0x40; break;
2059 case XML_darkTrellis
: nAlpha
= 0x60; break;
2060 case XML_darkUp
: nAlpha
= 0x40; break;
2061 case XML_darkVertical
: nAlpha
= 0x40; break;
2062 case XML_gray0625
: nAlpha
= 0x08; break;
2063 case XML_gray125
: nAlpha
= 0x10; break;
2064 case XML_lightDown
: nAlpha
= 0x20; break;
2065 case XML_lightGray
: nAlpha
= 0x20; break;
2066 case XML_lightGrid
: nAlpha
= 0x38; break;
2067 case XML_lightHorizontal
: nAlpha
= 0x20; break;
2068 case XML_lightTrellis
: nAlpha
= 0x30; break;
2069 case XML_lightUp
: nAlpha
= 0x20; break;
2070 case XML_lightVertical
: nAlpha
= 0x20; break;
2071 case XML_mediumGray
: nAlpha
= 0x40; break;
2072 case XML_solid
: nAlpha
= 0x80; break;
2075 sal_Int32 nWinTextColor
= rFilter
.getSystemColor( XML_windowText
);
2076 sal_Int32 nWinColor
= rFilter
.getSystemColor( XML_window
);
2078 if( !rModel
.mbPattColorUsed
)
2079 rModel
.maPatternColor
.setAuto();
2080 sal_Int32 nPattColor
= rModel
.maPatternColor
.getColor( rFilter
, nWinTextColor
);
2082 if( !rModel
.mbFillColorUsed
)
2083 rModel
.maFillColor
.setAuto();
2084 sal_Int32 nFillColor
= rModel
.maFillColor
.getColor( rFilter
, nWinColor
);
2086 maApiData
.mnColor
= lclGetMixedColor( nPattColor
, nFillColor
, nAlpha
);
2087 maApiData
.mbTransparent
= false;
2090 else if( mxGradientModel
.get() && !mxGradientModel
->maColors
.empty() )
2092 GradientFillModel
& rModel
= *mxGradientModel
;
2093 maApiData
.mbUsed
= true; // no support for differential attributes
2094 GradientFillModel::ColorMap::const_iterator aIt
= rModel
.maColors
.begin();
2095 OSL_ENSURE( !aIt
->second
.isAuto(), "Fill::finalizeImport - automatic gradient color" );
2096 maApiData
.mnColor
= aIt
->second
.getColor( rFilter
, API_RGB_WHITE
);
2097 if( ++aIt
!= rModel
.maColors
.end() )
2099 OSL_ENSURE( !aIt
->second
.isAuto(), "Fill::finalizeImport - automatic gradient color" );
2100 sal_Int32 nEndColor
= aIt
->second
.getColor( rFilter
, API_RGB_WHITE
);
2101 maApiData
.mnColor
= lclGetMixedColor( maApiData
.mnColor
, nEndColor
, 0x40 );
2102 maApiData
.mbTransparent
= false;
2107 void Fill::writeToPropertyMap( PropertyMap
& rPropMap
) const
2109 if( maApiData
.mbUsed
)
2111 rPropMap
[ PROP_CellBackColor
] <<= maApiData
.mnColor
;
2112 rPropMap
[ PROP_IsCellBackgroundTransparent
] <<= maApiData
.mbTransparent
;
2116 // ============================================================================
2118 XfModel::XfModel() :
2125 mbFontUsed( false ),
2126 mbNumFmtUsed( false ),
2127 mbAlignUsed( false ),
2128 mbProtUsed( false ),
2129 mbBorderUsed( false ),
2134 // ============================================================================
2136 Xf::Xf( const WorkbookHelper
& rHelper
) :
2137 WorkbookHelper( rHelper
),
2138 maAlignment( rHelper
),
2139 maProtection( rHelper
)
2143 void Xf::setAllUsedFlags( bool bUsed
)
2145 maModel
.mbAlignUsed
= maModel
.mbProtUsed
= maModel
.mbFontUsed
=
2146 maModel
.mbNumFmtUsed
= maModel
.mbBorderUsed
= maModel
.mbAreaUsed
= bUsed
;
2149 void Xf::importXf( const AttributeList
& rAttribs
, bool bCellXf
)
2151 maModel
.mbCellXf
= bCellXf
;
2152 maModel
.mnStyleXfId
= rAttribs
.getInteger( XML_xfId
, -1 );
2153 maModel
.mnFontId
= rAttribs
.getInteger( XML_fontId
, -1 );
2154 maModel
.mnNumFmtId
= rAttribs
.getInteger( XML_numFmtId
, -1 );
2155 maModel
.mnBorderId
= rAttribs
.getInteger( XML_borderId
, -1 );
2156 maModel
.mnFillId
= rAttribs
.getInteger( XML_fillId
, -1 );
2158 /* Default value of the apply*** attributes is dependent on context:
2159 true in cellStyleXfs element, false in cellXfs element... */
2160 maModel
.mbAlignUsed
= rAttribs
.getBool( XML_applyAlignment
, !maModel
.mbCellXf
);
2161 maModel
.mbProtUsed
= rAttribs
.getBool( XML_applyProtection
, !maModel
.mbCellXf
);
2162 maModel
.mbFontUsed
= rAttribs
.getBool( XML_applyFont
, !maModel
.mbCellXf
);
2163 maModel
.mbNumFmtUsed
= rAttribs
.getBool( XML_applyNumberFormat
, !maModel
.mbCellXf
);
2164 maModel
.mbBorderUsed
= rAttribs
.getBool( XML_applyBorder
, !maModel
.mbCellXf
);
2165 maModel
.mbAreaUsed
= rAttribs
.getBool( XML_applyFill
, !maModel
.mbCellXf
);
2168 void Xf::importAlignment( const AttributeList
& rAttribs
)
2170 maAlignment
.importAlignment( rAttribs
);
2173 void Xf::importProtection( const AttributeList
& rAttribs
)
2175 maProtection
.importProtection( rAttribs
);
2178 void Xf::importXf( RecordInputStream
& rStrm
, bool bCellXf
)
2180 maModel
.mbCellXf
= bCellXf
;
2181 maModel
.mnStyleXfId
= rStrm
.readuInt16();
2182 maModel
.mnNumFmtId
= rStrm
.readuInt16();
2183 maModel
.mnFontId
= rStrm
.readuInt16();
2184 maModel
.mnFillId
= rStrm
.readuInt16();
2185 maModel
.mnBorderId
= rStrm
.readuInt16();
2186 sal_uInt32 nFlags
= rStrm
.readuInt32();
2187 maAlignment
.setBinData( nFlags
);
2188 maProtection
.setBinData( nFlags
);
2189 // used flags, see comments in Xf::setBiffUsedFlags()
2190 sal_uInt16 nUsedFlags
= rStrm
.readuInt16();
2191 maModel
.mbFontUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, OOBIN_XF_FONT_USED
);
2192 maModel
.mbNumFmtUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, OOBIN_XF_NUMFMT_USED
);
2193 maModel
.mbAlignUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, OOBIN_XF_ALIGN_USED
);
2194 maModel
.mbProtUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, OOBIN_XF_PROT_USED
);
2195 maModel
.mbBorderUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, OOBIN_XF_BORDER_USED
);
2196 maModel
.mbAreaUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, OOBIN_XF_AREA_USED
);
2199 void Xf::importXf( BiffInputStream
& rStrm
)
2201 BorderRef xBorder
= getStyles().createBorder( &maModel
.mnBorderId
);
2202 FillRef xFill
= getStyles().createFill( &maModel
.mnFillId
);
2208 sal_uInt8 nFontId
, nNumFmtId
, nFlags
;
2211 rStrm
>> nNumFmtId
>> nFlags
;
2213 // only cell XFs in BIFF2, no parent style, used flags always true
2214 setAllUsedFlags( true );
2217 maAlignment
.setBiff2Data( nFlags
);
2218 maProtection
.setBiff2Data( nNumFmtId
);
2219 xBorder
->setBiff2Data( nFlags
);
2220 xFill
->setBiff2Data( nFlags
);
2221 maModel
.mnFontId
= static_cast< sal_Int32
>( nFontId
);
2222 maModel
.mnNumFmtId
= static_cast< sal_Int32
>( nNumFmtId
& BIFF2_XF_VALFMT_MASK
);
2229 sal_uInt16 nTypeProt
, nAlign
, nArea
;
2230 sal_uInt8 nFontId
, nNumFmtId
;
2231 rStrm
>> nFontId
>> nNumFmtId
>> nTypeProt
>> nAlign
>> nArea
>> nBorder
;
2234 maModel
.mbCellXf
= !getFlag( nTypeProt
, BIFF_XF_STYLE
); // new in BIFF3
2235 maModel
.mnStyleXfId
= extractValue
< sal_Int32
>( nAlign
, 4, 12 ); // new in BIFF3
2236 // attribute used flags
2237 setBiffUsedFlags( extractValue
< sal_uInt8
>( nTypeProt
, 10, 6 ) ); // new in BIFF3
2240 maAlignment
.setBiff3Data( nAlign
);
2241 maProtection
.setBiff3Data( nTypeProt
);
2242 xBorder
->setBiff3Data( nBorder
);
2243 xFill
->setBiff3Data( nArea
);
2244 maModel
.mnFontId
= static_cast< sal_Int32
>( nFontId
);
2245 maModel
.mnNumFmtId
= static_cast< sal_Int32
>( nNumFmtId
);
2252 sal_uInt16 nTypeProt
, nAlign
, nArea
;
2253 sal_uInt8 nFontId
, nNumFmtId
;
2254 rStrm
>> nFontId
>> nNumFmtId
>> nTypeProt
>> nAlign
>> nArea
>> nBorder
;
2257 maModel
.mbCellXf
= !getFlag( nTypeProt
, BIFF_XF_STYLE
);
2258 maModel
.mnStyleXfId
= extractValue
< sal_Int32
>( nTypeProt
, 4, 12 );
2259 // attribute used flags
2260 setBiffUsedFlags( extractValue
< sal_uInt8
>( nAlign
, 10, 6 ) );
2263 maAlignment
.setBiff4Data( nAlign
);
2264 maProtection
.setBiff3Data( nTypeProt
);
2265 xBorder
->setBiff3Data( nBorder
);
2266 xFill
->setBiff3Data( nArea
);
2267 maModel
.mnFontId
= static_cast< sal_Int32
>( nFontId
);
2268 maModel
.mnNumFmtId
= static_cast< sal_Int32
>( nNumFmtId
);
2274 sal_uInt32 nArea
, nBorder
;
2275 sal_uInt16 nFontId
, nNumFmtId
, nTypeProt
, nAlign
;
2276 rStrm
>> nFontId
>> nNumFmtId
>> nTypeProt
>> nAlign
>> nArea
>> nBorder
;
2279 maModel
.mbCellXf
= !getFlag( nTypeProt
, BIFF_XF_STYLE
);
2280 maModel
.mnStyleXfId
= extractValue
< sal_Int32
>( nTypeProt
, 4, 12 );
2281 // attribute used flags
2282 setBiffUsedFlags( extractValue
< sal_uInt8
>( nAlign
, 10, 6 ) );
2285 maAlignment
.setBiff5Data( nAlign
);
2286 maProtection
.setBiff3Data( nTypeProt
);
2287 xBorder
->setBiff5Data( nBorder
, nArea
);
2288 xFill
->setBiff5Data( nArea
);
2289 maModel
.mnFontId
= static_cast< sal_Int32
>( nFontId
);
2290 maModel
.mnNumFmtId
= static_cast< sal_Int32
>( nNumFmtId
);
2296 sal_uInt32 nBorder1
, nBorder2
;
2297 sal_uInt16 nFontId
, nNumFmtId
, nTypeProt
, nAlign
, nMiscAttrib
, nArea
;
2298 rStrm
>> nFontId
>> nNumFmtId
>> nTypeProt
>> nAlign
>> nMiscAttrib
>> nBorder1
>> nBorder2
>> nArea
;
2301 maModel
.mbCellXf
= !getFlag( nTypeProt
, BIFF_XF_STYLE
);
2302 maModel
.mnStyleXfId
= extractValue
< sal_Int32
>( nTypeProt
, 4, 12 );
2303 // attribute used flags
2304 setBiffUsedFlags( extractValue
< sal_uInt8
>( nMiscAttrib
, 10, 6 ) );
2307 maAlignment
.setBiff8Data( nAlign
, nMiscAttrib
);
2308 maProtection
.setBiff3Data( nTypeProt
);
2309 xBorder
->setBiff8Data( nBorder1
, nBorder2
);
2310 xFill
->setBiff8Data( nBorder2
, nArea
);
2311 maModel
.mnFontId
= static_cast< sal_Int32
>( nFontId
);
2312 maModel
.mnNumFmtId
= static_cast< sal_Int32
>( nNumFmtId
);
2316 case BIFF_UNKNOWN
: break;
2320 void Xf::finalizeImport()
2322 // alignment and protection
2323 maAlignment
.finalizeImport();
2324 maProtection
.finalizeImport();
2325 // update used flags from cell style
2326 if( maModel
.mbCellXf
)
2327 if( const Xf
* pStyleXf
= getStyles().getStyleXf( maModel
.mnStyleXfId
).get() )
2328 updateUsedFlags( *pStyleXf
);
2331 FontRef
Xf::getFont() const
2333 return getStyles().getFont( maModel
.mnFontId
);
2336 bool Xf::hasAnyUsedFlags() const
2339 maModel
.mbAlignUsed
|| maModel
.mbProtUsed
|| maModel
.mbFontUsed
||
2340 maModel
.mbNumFmtUsed
|| maModel
.mbBorderUsed
|| maModel
.mbAreaUsed
;
2343 void Xf::writeToPropertyMap( PropertyMap
& rPropMap
) const
2345 StylesBuffer
& rStyles
= getStyles();
2347 // create and set cell style
2348 if( maModel
.mbCellXf
)
2349 rPropMap
[ PROP_CellStyle
] <<= rStyles
.createCellStyle( maModel
.mnStyleXfId
);
2351 if( maModel
.mbFontUsed
)
2352 rStyles
.writeFontToPropertyMap( rPropMap
, maModel
.mnFontId
);
2353 if( maModel
.mbNumFmtUsed
)
2354 rStyles
.writeNumFmtToPropertyMap( rPropMap
, maModel
.mnNumFmtId
);
2355 if( maModel
.mbAlignUsed
)
2356 maAlignment
.writeToPropertyMap( rPropMap
);
2357 if( maModel
.mbProtUsed
)
2358 maProtection
.writeToPropertyMap( rPropMap
);
2359 if( maModel
.mbBorderUsed
)
2360 rStyles
.writeBorderToPropertyMap( rPropMap
, maModel
.mnBorderId
);
2361 if( maModel
.mbAreaUsed
)
2362 rStyles
.writeFillToPropertyMap( rPropMap
, maModel
.mnFillId
);
2365 void Xf::writeToPropertySet( PropertySet
& rPropSet
) const
2367 PropertyMap aPropMap
;
2368 writeToPropertyMap( aPropMap
);
2369 rPropSet
.setProperties( aPropMap
);
2372 void Xf::setBiffUsedFlags( sal_uInt8 nUsedFlags
)
2374 /* Notes about finding the used flags:
2375 - In cell XFs a *set* bit means a used attribute.
2376 - In style XFs a *cleared* bit means a used attribute.
2377 The boolean flags always store true, if the attribute is used.
2378 The "maModel.mbCellXf == getFlag(...)" construct evaluates to true in
2379 both mentioned cases: cell XF and set bit; or style XF and cleared bit.
2381 maModel
.mbFontUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, BIFF_XF_FONT_USED
);
2382 maModel
.mbNumFmtUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, BIFF_XF_NUMFMT_USED
);
2383 maModel
.mbAlignUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, BIFF_XF_ALIGN_USED
);
2384 maModel
.mbProtUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, BIFF_XF_PROT_USED
);
2385 maModel
.mbBorderUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, BIFF_XF_BORDER_USED
);
2386 maModel
.mbAreaUsed
= maModel
.mbCellXf
== getFlag( nUsedFlags
, BIFF_XF_AREA_USED
);
2389 void Xf::updateUsedFlags( const Xf
& rStyleXf
)
2391 /* Enables the used flags, if the formatting attributes differ from the
2392 passed style XF. In cell XFs Excel uses the cell attributes, if they
2393 differ from the parent style XF.
2394 #109899# ...or if the respective flag is not set in parent style XF.
2396 const XfModel
& rStyleData
= rStyleXf
.maModel
;
2397 if( !maModel
.mbFontUsed
)
2398 maModel
.mbFontUsed
= !rStyleData
.mbFontUsed
|| (maModel
.mnFontId
!= rStyleData
.mnFontId
);
2399 if( !maModel
.mbNumFmtUsed
)
2400 maModel
.mbNumFmtUsed
= !rStyleData
.mbNumFmtUsed
|| (maModel
.mnNumFmtId
!= rStyleData
.mnNumFmtId
);
2401 if( !maModel
.mbAlignUsed
)
2402 maModel
.mbAlignUsed
= !rStyleData
.mbAlignUsed
|| !(maAlignment
.getApiData() == rStyleXf
.maAlignment
.getApiData());
2403 if( !maModel
.mbProtUsed
)
2404 maModel
.mbProtUsed
= !rStyleData
.mbProtUsed
|| !(maProtection
.getApiData() == rStyleXf
.maProtection
.getApiData());
2405 if( !maModel
.mbBorderUsed
)
2406 maModel
.mbBorderUsed
= !rStyleData
.mbBorderUsed
|| (maModel
.mnBorderId
!= rStyleData
.mnBorderId
);
2407 if( !maModel
.mbAreaUsed
)
2408 maModel
.mbAreaUsed
= !rStyleData
.mbAreaUsed
|| (maModel
.mnFillId
!= rStyleData
.mnFillId
);
2411 // ============================================================================
2413 Dxf::Dxf( const WorkbookHelper
& rHelper
) :
2414 WorkbookHelper( rHelper
)
2418 FontRef
Dxf::createFont( bool bAlwaysNew
)
2420 if( bAlwaysNew
|| !mxFont
)
2421 mxFont
.reset( new Font( *this, true ) );
2425 BorderRef
Dxf::createBorder( bool bAlwaysNew
)
2427 if( bAlwaysNew
|| !mxBorder
)
2428 mxBorder
.reset( new Border( *this, true ) );
2432 FillRef
Dxf::createFill( bool bAlwaysNew
)
2434 if( bAlwaysNew
|| !mxFill
)
2435 mxFill
.reset( new Fill( *this, true ) );
2439 void Dxf::importNumFmt( const AttributeList
& rAttribs
)
2441 mxNumFmt
= getStyles().importNumFmt( rAttribs
);
2444 void Dxf::importAlignment( const AttributeList
& rAttribs
)
2446 mxAlignment
.reset( new Alignment( *this ) );
2447 mxAlignment
->importAlignment( rAttribs
);
2450 void Dxf::importProtection( const AttributeList
& rAttribs
)
2452 mxProtection
.reset( new Protection( *this ) );
2453 mxProtection
->importProtection( rAttribs
);
2456 void Dxf::importDxf( RecordInputStream
& rStrm
)
2458 sal_Int32 nNumFmtId
= -1;
2460 sal_uInt16 nRecCount
;
2461 rStrm
.skip( 4 ); // flags
2463 for( sal_uInt16 nRec
= 0; !rStrm
.isEof() && (nRec
< nRecCount
); ++nRec
)
2465 sal_uInt16 nSubRecId
, nSubRecSize
;
2466 sal_Int64 nRecEnd
= rStrm
.tell();
2467 rStrm
>> nSubRecId
>> nSubRecSize
;
2468 nRecEnd
+= nSubRecSize
;
2471 case OOBIN_DXF_FILL_PATTERN
: createFill( false )->importDxfPattern( rStrm
); break;
2472 case OOBIN_DXF_FILL_FGCOLOR
: createFill( false )->importDxfFgColor( rStrm
); break;
2473 case OOBIN_DXF_FILL_BGCOLOR
: createFill( false )->importDxfBgColor( rStrm
); break;
2474 case OOBIN_DXF_FILL_GRADIENT
: createFill( false )->importDxfGradient( rStrm
); break;
2475 case OOBIN_DXF_FILL_STOP
: createFill( false )->importDxfStop( rStrm
); break;
2476 case OOBIN_DXF_FONT_COLOR
: createFont( false )->importDxfColor( rStrm
); break;
2477 case OOBIN_DXF_BORDER_TOP
: createBorder( false )->importDxfBorder( XLS_TOKEN( top
), rStrm
); break;
2478 case OOBIN_DXF_BORDER_BOTTOM
: createBorder( false )->importDxfBorder( XLS_TOKEN( bottom
), rStrm
); break;
2479 case OOBIN_DXF_BORDER_LEFT
: createBorder( false )->importDxfBorder( XLS_TOKEN( left
), rStrm
); break;
2480 case OOBIN_DXF_BORDER_RIGHT
: createBorder( false )->importDxfBorder( XLS_TOKEN( right
), rStrm
); break;
2481 case OOBIN_DXF_FONT_NAME
: createFont( false )->importDxfName( rStrm
); break;
2482 case OOBIN_DXF_FONT_WEIGHT
: createFont( false )->importDxfWeight( rStrm
); break;
2483 case OOBIN_DXF_FONT_UNDERLINE
: createFont( false )->importDxfUnderline( rStrm
); break;
2484 case OOBIN_DXF_FONT_ESCAPEMENT
: createFont( false )->importDxfEscapement( rStrm
); break;
2485 case OOBIN_DXF_FONT_ITALIC
: createFont( false )->importDxfFlag( XML_i
, rStrm
); break;
2486 case OOBIN_DXF_FONT_STRIKE
: createFont( false )->importDxfFlag( XML_strike
, rStrm
); break;
2487 case OOBIN_DXF_FONT_OUTLINE
: createFont( false )->importDxfFlag( XML_outline
, rStrm
); break;
2488 case OOBIN_DXF_FONT_SHADOW
: createFont( false )->importDxfFlag( XML_shadow
, rStrm
); break;
2489 case OOBIN_DXF_FONT_HEIGHT
: createFont( false )->importDxfHeight( rStrm
); break;
2490 case OOBIN_DXF_FONT_SCHEME
: createFont( false )->importDxfScheme( rStrm
); break;
2491 case OOBIN_DXF_NUMFMT_CODE
: aFmtCode
= rStrm
.readString( false ); break;
2492 case OOBIN_DXF_NUMFMT_ID
: nNumFmtId
= rStrm
.readuInt16(); break;
2494 rStrm
.seek( nRecEnd
);
2496 OSL_ENSURE( !rStrm
.isEof() && (rStrm
.getRemaining() == 0), "Dxf::importDxf - unexpected remaining data" );
2497 mxNumFmt
= getStyles().createNumFmt( nNumFmtId
, aFmtCode
);
2500 void Dxf::importCfRule( BiffInputStream
& rStrm
, sal_uInt32 nFlags
)
2502 if( getFlag( nFlags
, BIFF_CFRULE_FONTBLOCK
) )
2503 createFont()->importCfRule( rStrm
);
2504 if( getFlag( nFlags
, BIFF_CFRULE_ALIGNBLOCK
) )
2506 if( getFlag( nFlags
, BIFF_CFRULE_BORDERBLOCK
) )
2507 createBorder()->importCfRule( rStrm
, nFlags
);
2508 if( getFlag( nFlags
, BIFF_CFRULE_FILLBLOCK
) )
2509 createFill()->importCfRule( rStrm
, nFlags
);
2510 if( getFlag( nFlags
, BIFF_CFRULE_PROTBLOCK
) )
2514 void Dxf::finalizeImport()
2517 mxFont
->finalizeImport();
2518 // number format already finalized by the number formats buffer
2519 if( mxAlignment
.get() )
2520 mxAlignment
->finalizeImport();
2521 if( mxProtection
.get() )
2522 mxProtection
->finalizeImport();
2523 if( mxBorder
.get() )
2524 mxBorder
->finalizeImport();
2526 mxFill
->finalizeImport();
2529 void Dxf::writeToPropertyMap( PropertyMap
& rPropMap
) const
2532 mxFont
->writeToPropertyMap( rPropMap
, FONT_PROPTYPE_CELL
);
2533 if( mxNumFmt
.get() )
2534 mxNumFmt
->writeToPropertyMap( rPropMap
);
2535 if( mxAlignment
.get() )
2536 mxAlignment
->writeToPropertyMap( rPropMap
);
2537 if( mxProtection
.get() )
2538 mxProtection
->writeToPropertyMap( rPropMap
);
2539 if( mxBorder
.get() )
2540 mxBorder
->writeToPropertyMap( rPropMap
);
2542 mxFill
->writeToPropertyMap( rPropMap
);
2545 void Dxf::writeToPropertySet( PropertySet
& rPropSet
) const
2547 PropertyMap aPropMap
;
2548 writeToPropertyMap( aPropMap
);
2549 rPropSet
.setProperties( aPropMap
);
2552 // ============================================================================
2556 const sal_Char
* const spcLegacyStyleNamePrefix
= "Excel_BuiltIn_";
2557 const sal_Char
* const sppcLegacyStyleNames
[] =
2560 "RowLevel_", // outline level will be appended
2561 "ColumnLevel_", // outline level will be appended
2565 "Comma_0", // new in BIFF4
2567 "Hyperlink", // new in BIFF8
2568 "Followed_Hyperlink"
2570 const sal_Int32 snLegacyStyleNamesCount
= static_cast< sal_Int32
>( STATIC_ARRAY_SIZE( sppcLegacyStyleNames
) );
2572 const sal_Char
* const spcStyleNamePrefix
= "Excel Built-in ";
2573 const sal_Char
* const sppcStyleNames
[] =
2576 "RowLevel_", // outline level will be appended
2577 "ColLevel_", // outline level will be appended
2581 "Comma [0]", // new in BIFF4
2583 "Hyperlink", // new in BIFF8
2584 "Followed Hyperlink",
2585 "Note", // new in OOX
2630 const sal_Int32 snStyleNamesCount
= static_cast< sal_Int32
>( STATIC_ARRAY_SIZE( sppcStyleNames
) );
2632 OUString
lclGetBuiltinStyleName( sal_Int32 nBuiltinId
, const OUString
& rName
, sal_Int32 nLevel
= 0 )
2634 OSL_ENSURE( (0 <= nBuiltinId
) && (nBuiltinId
< snStyleNamesCount
), "lclGetBuiltinStyleName - unknown built-in style" );
2635 OUStringBuffer aStyleName
;
2636 aStyleName
.appendAscii( spcStyleNamePrefix
);
2637 if( (0 <= nBuiltinId
) && (nBuiltinId
< snStyleNamesCount
) && (sppcStyleNames
[ nBuiltinId
][ 0 ] != 0) )
2638 aStyleName
.appendAscii( sppcStyleNames
[ nBuiltinId
] );
2639 else if( rName
.getLength() > 0 )
2640 aStyleName
.append( rName
);
2642 aStyleName
.append( nBuiltinId
);
2643 if( (nBuiltinId
== OOX_STYLE_ROWLEVEL
) || (nBuiltinId
== OOX_STYLE_COLLEVEL
) )
2644 aStyleName
.append( nLevel
);
2645 return aStyleName
.makeStringAndClear();
2648 OUString
lclGetBuiltInStyleName( const OUString
& rName
)
2650 OUStringBuffer aStyleName
;
2651 aStyleName
.appendAscii( spcStyleNamePrefix
).append( rName
);
2652 return aStyleName
.makeStringAndClear();
2655 bool lclIsBuiltinStyleName( const OUString
& rStyleName
, sal_Int32
* pnBuiltinId
, sal_Int32
* pnNextChar
)
2657 // try the other built-in styles
2658 OUString aPrefix
= OUString::createFromAscii( spcStyleNamePrefix
);
2659 sal_Int32 nPrefixLen
= aPrefix
.getLength();
2660 sal_Int32 nFoundId
= 0;
2661 sal_Int32 nNextChar
= 0;
2662 if( rStyleName
.matchIgnoreAsciiCase( aPrefix
) )
2664 OUString aShortName
;
2665 for( sal_Int32 nId
= 0; nId
< snStyleNamesCount
; ++nId
)
2667 aShortName
= OUString::createFromAscii( sppcStyleNames
[ nId
] );
2668 if( rStyleName
.matchIgnoreAsciiCase( aShortName
, nPrefixLen
) &&
2669 (nNextChar
< nPrefixLen
+ aShortName
.getLength()) )
2672 nNextChar
= nPrefixLen
+ aShortName
.getLength();
2679 if( pnBuiltinId
) *pnBuiltinId
= nFoundId
;
2680 if( pnNextChar
) *pnNextChar
= nNextChar
;
2684 if( pnBuiltinId
) *pnBuiltinId
= -1;
2685 if( pnNextChar
) *pnNextChar
= 0;
2689 bool lclGetBuiltinStyleId( sal_Int32
& rnBuiltinId
, sal_Int32
& rnLevel
, const OUString
& rStyleName
)
2691 sal_Int32 nBuiltinId
;
2692 sal_Int32 nNextChar
;
2693 if( lclIsBuiltinStyleName( rStyleName
, &nBuiltinId
, &nNextChar
) )
2695 if( (nBuiltinId
== OOX_STYLE_ROWLEVEL
) || (nBuiltinId
== OOX_STYLE_COLLEVEL
) )
2697 OUString aLevel
= rStyleName
.copy( nNextChar
);
2698 sal_Int32 nLevel
= aLevel
.toInt32();
2699 if( (0 < nLevel
) && (nLevel
<= OOX_STYLE_LEVELCOUNT
) )
2701 rnBuiltinId
= nBuiltinId
;
2706 else if( rStyleName
.getLength() == nNextChar
)
2708 rnBuiltinId
= nBuiltinId
;
2720 // ----------------------------------------------------------------------------
2722 CellStyleModel::CellStyleModel() :
2732 bool CellStyleModel::isBuiltin() const
2734 return mbBuiltin
&& (mnBuiltinId
>= 0);
2737 bool CellStyleModel::isDefaultStyle() const
2739 return mbBuiltin
&& (mnBuiltinId
== OOX_STYLE_NORMAL
);
2742 // ============================================================================
2744 CellStyle::CellStyle( const WorkbookHelper
& rHelper
) :
2745 WorkbookHelper( rHelper
),
2750 void CellStyle::importCellStyle( const AttributeList
& rAttribs
)
2752 maModel
.maName
= rAttribs
.getXString( XML_name
, OUString() );
2753 maModel
.mnXfId
= rAttribs
.getInteger( XML_xfId
, -1 );
2754 maModel
.mnBuiltinId
= rAttribs
.getInteger( XML_builtinId
, -1 );
2755 maModel
.mnLevel
= rAttribs
.getInteger( XML_iLevel
, 0 );
2756 maModel
.mbBuiltin
= rAttribs
.hasAttribute( XML_builtinId
);
2757 maModel
.mbCustom
= rAttribs
.getBool( XML_customBuiltin
, false );
2758 maModel
.mbHidden
= rAttribs
.getBool( XML_hidden
, false );
2761 void CellStyle::importCellStyle( RecordInputStream
& rStrm
)
2764 rStrm
>> maModel
.mnXfId
>> nFlags
;
2765 maModel
.mnBuiltinId
= rStrm
.readInt8();
2766 maModel
.mnLevel
= rStrm
.readInt8();
2767 rStrm
>> maModel
.maName
;
2768 maModel
.mbBuiltin
= getFlag( nFlags
, OOBIN_CELLSTYLE_BUILTIN
);
2769 maModel
.mbCustom
= getFlag( nFlags
, OOBIN_CELLSTYLE_CUSTOM
);
2770 maModel
.mbHidden
= getFlag( nFlags
, OOBIN_CELLSTYLE_HIDDEN
);
2773 void CellStyle::importStyle( BiffInputStream
& rStrm
)
2775 sal_uInt16 nStyleXf
;
2777 maModel
.mnXfId
= static_cast< sal_Int32
>( nStyleXf
& BIFF_STYLE_XFMASK
);
2778 maModel
.mbBuiltin
= getFlag( nStyleXf
, BIFF_STYLE_BUILTIN
);
2779 if( maModel
.mbBuiltin
)
2781 maModel
.mnBuiltinId
= rStrm
.readInt8();
2782 maModel
.mnLevel
= rStrm
.readInt8();
2786 maModel
.maName
= (getBiff() == BIFF8
) ?
2787 rStrm
.readUniString() : rStrm
.readByteStringUC( false, getTextEncoding() );
2788 // #i103281# check if this is a new built-in style introduced in XL2007
2789 if( (getBiff() == BIFF8
) && (rStrm
.getNextRecId() == BIFF_ID_STYLEEXT
) && rStrm
.startNextRecord() )
2791 sal_uInt8 nExtFlags
;
2794 maModel
.mbBuiltin
= getFlag( nExtFlags
, BIFF_STYLEEXT_BUILTIN
);
2795 maModel
.mbCustom
= getFlag( nExtFlags
, BIFF_STYLEEXT_CUSTOM
);
2796 maModel
.mbHidden
= getFlag( nExtFlags
, BIFF_STYLEEXT_HIDDEN
);
2797 if( maModel
.mbBuiltin
)
2799 maModel
.mnBuiltinId
= rStrm
.readInt8();
2800 maModel
.mnLevel
= rStrm
.readInt8();
2806 void CellStyle::createCellStyle()
2808 // #i1624# #i1768# ignore unnamed user styles
2810 mbCreated
= maFinalName
.getLength() == 0;
2812 /* #i103281# do not create another style of the same name, if it exists
2813 already. This is needed to prevent that styles pasted from clipboard
2814 get duplicated over and over. */
2815 if( !mbCreated
) try
2817 Reference
< XNameAccess
> xCellStylesNA( getStyleFamily( false ), UNO_QUERY_THROW
);
2818 mbCreated
= xCellStylesNA
->hasByName( maFinalName
);
2824 // create the style object in the document
2825 if( !mbCreated
) try
2828 Reference
< XStyle
> xStyle( createStyleObject( maFinalName
, false ), UNO_SET_THROW
);
2829 // write style formatting properties
2830 PropertySet
aPropSet( xStyle
);
2831 getStyles().writeStyleXfToPropertySet( aPropSet
, maModel
.mnXfId
);
2832 if( !maModel
.isDefaultStyle() )
2833 xStyle
->setParentStyle( getStyles().getDefaultStyleName() );
2840 void CellStyle::finalizeImport( const OUString
& rFinalName
)
2842 maFinalName
= rFinalName
;
2843 if( !maModel
.isBuiltin() || maModel
.mbCustom
)
2847 // ============================================================================
2849 CellStyleBuffer::CellStyleBuffer( const WorkbookHelper
& rHelper
) :
2850 WorkbookHelper( rHelper
)
2854 CellStyleRef
CellStyleBuffer::importCellStyle( const AttributeList
& rAttribs
)
2856 CellStyleRef
xCellStyle( new CellStyle( *this ) );
2857 xCellStyle
->importCellStyle( rAttribs
);
2858 insertCellStyle( xCellStyle
);
2862 CellStyleRef
CellStyleBuffer::importCellStyle( RecordInputStream
& rStrm
)
2864 CellStyleRef
xCellStyle( new CellStyle( *this ) );
2865 xCellStyle
->importCellStyle( rStrm
);
2866 insertCellStyle( xCellStyle
);
2870 CellStyleRef
CellStyleBuffer::importStyle( BiffInputStream
& rStrm
)
2872 CellStyleRef
xCellStyle( new CellStyle( *this ) );
2873 xCellStyle
->importStyle( rStrm
);
2874 insertCellStyle( xCellStyle
);
2878 void CellStyleBuffer::finalizeImport()
2880 // calculate final names of all styles
2881 typedef RefMap
< OUString
, CellStyle
, IgnoreCaseCompare
> CellStyleNameMap
;
2882 CellStyleNameMap aCellStyles
;
2883 CellStyleVector aConflictNameStyles
;
2885 /* First, reserve style names that are built-in in Calc. This causes that
2886 imported cell styles get different unused names and thus do not try to
2887 overwrite these built-in styles. For BIFF4 workbooks (which contain a
2888 separate list of cell styles per sheet), reserve all existing styles if
2889 current sheet is not the first sheet (this styles buffer will be
2890 constructed again for every new sheet). This will create unique names
2891 for styles in different sheets with the same name. Assuming that the
2892 BIFF4W import filter is never used to import from clipboard... */
2893 bool bReserveAll
= (getFilterType() == FILTER_BIFF
) && (getBiff() == BIFF4
) && isWorkbookFile() && (getCurrentSheetIndex() > 0);
2896 // unfortunately, com.sun.star.style.StyleFamily does not implement XEnumerationAccess...
2897 Reference
< XIndexAccess
> xStyleFamilyIA( getStyleFamily( false ), UNO_QUERY_THROW
);
2898 for( sal_Int32 nIndex
= 0, nCount
= xStyleFamilyIA
->getCount(); nIndex
< nCount
; ++nIndex
)
2900 Reference
< XStyle
> xStyle( xStyleFamilyIA
->getByIndex( nIndex
), UNO_QUERY_THROW
);
2901 if( bReserveAll
|| !xStyle
->isUserDefined() )
2903 Reference
< XNamed
> xStyleName( xStyle
, UNO_QUERY_THROW
);
2904 // create an empty entry by using ::std::map<>::operator[]
2905 aCellStyles
[ xStyleName
->getName() ];
2913 /* Calculate names of built-in styles. Store styles with reserved names
2914 in the aConflictNameStyles list. */
2915 for( CellStyleVector::iterator aIt
= maBuiltinStyles
.begin(), aEnd
= maBuiltinStyles
.end(); aIt
!= aEnd
; ++aIt
)
2917 const CellStyleModel
& rModel
= (*aIt
)->getModel();
2918 OUString aStyleName
= lclGetBuiltinStyleName( rModel
.mnBuiltinId
, rModel
.maName
, rModel
.mnLevel
);
2919 OSL_ENSURE( bReserveAll
|| (aCellStyles
.count( aStyleName
) == 0),
2920 "CellStyleBuffer::finalizeImport - multiple styles with equal built-in identifier" );
2921 if( aCellStyles
.count( aStyleName
) > 0 )
2922 aConflictNameStyles
.push_back( *aIt
);
2924 aCellStyles
[ aStyleName
] = *aIt
;
2927 /* Calculate names of user defined styles. Store styles with reserved
2928 names in the aConflictNameStyles list. */
2929 for( CellStyleVector::iterator aIt
= maUserStyles
.begin(), aEnd
= maUserStyles
.end(); aIt
!= aEnd
; ++aIt
)
2931 const CellStyleModel
& rModel
= (*aIt
)->getModel();
2932 // #i1624# #i1768# ignore unnamed user styles
2933 if( rModel
.maName
.getLength() > 0 )
2935 if( aCellStyles
.count( rModel
.maName
) > 0 )
2936 aConflictNameStyles
.push_back( *aIt
);
2938 aCellStyles
[ rModel
.maName
] = *aIt
;
2942 // find unused names for all styles with conflicting names
2943 for( CellStyleVector::iterator aIt
= aConflictNameStyles
.begin(), aEnd
= aConflictNameStyles
.end(); aIt
!= aEnd
; ++aIt
)
2945 const CellStyleModel
& rModel
= (*aIt
)->getModel();
2946 OUString aUnusedName
;
2947 sal_Int32 nIndex
= 0;
2950 aUnusedName
= OUStringBuffer( rModel
.maName
).append( sal_Unicode( ' ' ) ).append( ++nIndex
).makeStringAndClear();
2952 while( aCellStyles
.count( aUnusedName
) > 0 );
2953 aCellStyles
[ aUnusedName
] = *aIt
;
2956 // set final names and create user-defined and modified built-in cell styles
2957 aCellStyles
.forEachMemWithKey( &CellStyle::finalizeImport
);
2960 sal_Int32
CellStyleBuffer::getDefaultXfId() const
2962 return mxDefStyle
.get() ? mxDefStyle
->getModel().mnXfId
: -1;
2965 OUString
CellStyleBuffer::getDefaultStyleName() const
2967 return createCellStyle( mxDefStyle
);
2970 OUString
CellStyleBuffer::createCellStyle( sal_Int32 nXfId
) const
2972 return createCellStyle( maStylesByXf
.get( nXfId
) );
2975 // private --------------------------------------------------------------------
2977 void CellStyleBuffer::insertCellStyle( CellStyleRef xCellStyle
)
2979 const CellStyleModel
& rModel
= xCellStyle
->getModel();
2980 if( rModel
.mnXfId
>= 0 )
2982 // insert into the built-in map or user defined map
2983 (rModel
.isBuiltin() ? maBuiltinStyles
: maUserStyles
).push_back( xCellStyle
);
2985 // insert into the XF identifier map
2986 OSL_ENSURE( maStylesByXf
.count( rModel
.mnXfId
) == 0, "CellStyleBuffer::insertCellStyle - multiple styles with equal XF identifier" );
2987 maStylesByXf
[ rModel
.mnXfId
] = xCellStyle
;
2989 // remember default cell style
2990 if( rModel
.isDefaultStyle() )
2991 mxDefStyle
= xCellStyle
;
2995 OUString
CellStyleBuffer::createCellStyle( const CellStyleRef
& rxCellStyle
) const
2997 if( rxCellStyle
.get() )
2999 rxCellStyle
->createCellStyle();
3000 const OUString
& rStyleName
= rxCellStyle
->getFinalStyleName();
3001 if( rStyleName
.getLength() > 0 )
3004 // on error: fallback to default style
3005 return lclGetBuiltinStyleName( OOX_STYLE_NORMAL
, OUString() );
3008 // ============================================================================
3010 StylesBuffer::StylesBuffer( const WorkbookHelper
& rHelper
) :
3011 WorkbookHelper( rHelper
),
3012 maPalette( rHelper
),
3013 maNumFmts( rHelper
),
3014 maCellStyles( rHelper
)
3018 FontRef
StylesBuffer::createFont( sal_Int32
* opnFontId
)
3020 if( opnFontId
) *opnFontId
= static_cast< sal_Int32
>( maFonts
.size() );
3021 FontRef
xFont( new Font( *this, false ) );
3022 maFonts
.push_back( xFont
);
3026 NumberFormatRef
StylesBuffer::createNumFmt( sal_Int32 nNumFmtId
, const OUString
& rFmtCode
)
3028 return maNumFmts
.createNumFmt( nNumFmtId
, rFmtCode
);
3031 BorderRef
StylesBuffer::createBorder( sal_Int32
* opnBorderId
)
3033 if( opnBorderId
) *opnBorderId
= static_cast< sal_Int32
>( maBorders
.size() );
3034 BorderRef
xBorder( new Border( *this, false ) );
3035 maBorders
.push_back( xBorder
);
3039 FillRef
StylesBuffer::createFill( sal_Int32
* opnFillId
)
3041 if( opnFillId
) *opnFillId
= static_cast< sal_Int32
>( maFills
.size() );
3042 FillRef
xFill( new Fill( *this, false ) );
3043 maFills
.push_back( xFill
);
3047 XfRef
StylesBuffer::createCellXf( sal_Int32
* opnXfId
)
3049 if( opnXfId
) *opnXfId
= static_cast< sal_Int32
>( maCellXfs
.size() );
3050 XfRef
xXf( new Xf( *this ) );
3051 maCellXfs
.push_back( xXf
);
3055 XfRef
StylesBuffer::createStyleXf( sal_Int32
* opnXfId
)
3057 if( opnXfId
) *opnXfId
= static_cast< sal_Int32
>( maStyleXfs
.size() );
3058 XfRef
xXf( new Xf( *this ) );
3059 maStyleXfs
.push_back( xXf
);
3063 DxfRef
StylesBuffer::createDxf( sal_Int32
* opnDxfId
)
3065 if( opnDxfId
) *opnDxfId
= static_cast< sal_Int32
>( maDxfs
.size() );
3066 DxfRef
xDxf( new Dxf( *this ) );
3067 maDxfs
.push_back( xDxf
);
3071 void StylesBuffer::importPaletteColor( const AttributeList
& rAttribs
)
3073 maPalette
.importPaletteColor( rAttribs
);
3076 NumberFormatRef
StylesBuffer::importNumFmt( const AttributeList
& rAttribs
)
3078 return maNumFmts
.importNumFmt( rAttribs
);
3081 CellStyleRef
StylesBuffer::importCellStyle( const AttributeList
& rAttribs
)
3083 return maCellStyles
.importCellStyle( rAttribs
);
3086 void StylesBuffer::importPaletteColor( RecordInputStream
& rStrm
)
3088 maPalette
.importPaletteColor( rStrm
);
3091 void StylesBuffer::importNumFmt( RecordInputStream
& rStrm
)
3093 maNumFmts
.importNumFmt( rStrm
);
3096 void StylesBuffer::importCellStyle( RecordInputStream
& rStrm
)
3098 maCellStyles
.importCellStyle( rStrm
);
3101 void StylesBuffer::importPalette( BiffInputStream
& rStrm
)
3103 maPalette
.importPalette( rStrm
);
3106 void StylesBuffer::importFont( BiffInputStream
& rStrm
)
3108 /* Font with index 4 is not stored in BIFF. This means effectively, first
3109 font in the BIFF file has index 0, fourth font has index 3, and fifth
3110 font has index 5. Insert a dummy font to correctly map passed font
3112 if( maFonts
.size() == 4 )
3113 maFonts
.push_back( maFonts
.front() );
3115 FontRef xFont
= createFont();
3116 xFont
->importFont( rStrm
);
3118 /* #i71033# Set stream text encoding from application font, if CODEPAGE
3119 record is missing. Must be done now (not while finalizeImport() runs),
3120 to be able to read all following byte strings correctly (e.g. cell
3122 if( maFonts
.size() == 1 )
3123 setAppFontEncoding( xFont
->getFontEncoding() );
3126 void StylesBuffer::importFontColor( BiffInputStream
& rStrm
)
3128 if( !maFonts
.empty() )
3129 maFonts
.back()->importFontColor( rStrm
);
3132 void StylesBuffer::importFormat( BiffInputStream
& rStrm
)
3134 maNumFmts
.importFormat( rStrm
);
3137 void StylesBuffer::importXf( BiffInputStream
& rStrm
)
3139 XfRef
xXf( new Xf( *this ) );
3140 // store XF in both lists (except BIFF2 which does not support cell styles)
3141 maCellXfs
.push_back( xXf
);
3142 if( getBiff() != BIFF2
)
3143 maStyleXfs
.push_back( xXf
);
3144 xXf
->importXf( rStrm
);
3147 void StylesBuffer::importStyle( BiffInputStream
& rStrm
)
3149 maCellStyles
.importStyle( rStrm
);
3152 void StylesBuffer::finalizeImport()
3154 // fonts first, are needed to finalize unit converter and XFs below
3155 maFonts
.forEachMem( &Font::finalizeImport
);
3156 // finalize unit coefficients after default font is known
3157 getUnitConverter().finalizeImport();
3159 maNumFmts
.finalizeImport();
3160 // borders and fills
3161 maBorders
.forEachMem( &Border::finalizeImport
);
3162 maFills
.forEachMem( &Fill::finalizeImport
);
3164 /* Style XFs and cell XFs. The BIFF format stores cell XFs and style XFs
3165 mixed in a single list. The import filter has stored the XFs in both
3166 lists to make the getStyleXf() function working correctly (e.g. for
3167 retrieving the default font, see getDefaultFont() function), except for
3168 BIFF2 which does not support cell styles at all. Therefore, if in BIFF
3169 filter mode, we do not need to finalize the cell styles list. */
3170 if( getFilterType() == FILTER_OOX
)
3171 maStyleXfs
.forEachMem( &Xf::finalizeImport
);
3172 maCellXfs
.forEachMem( &Xf::finalizeImport
);
3174 // built-in and user defined cell styles
3175 maCellStyles
.finalizeImport();
3177 // differential formatting (for conditional formatting)
3178 maDxfs
.forEachMem( &Dxf::finalizeImport
);
3181 sal_Int32
StylesBuffer::getPaletteColor( sal_Int32 nPaletteIdx
) const
3183 return maPalette
.getColor( nPaletteIdx
);
3186 FontRef
StylesBuffer::getFont( sal_Int32 nFontId
) const
3188 return maFonts
.get( nFontId
);
3191 XfRef
StylesBuffer::getCellXf( sal_Int32 nXfId
) const
3193 return maCellXfs
.get( nXfId
);
3196 XfRef
StylesBuffer::getStyleXf( sal_Int32 nXfId
) const
3198 return maStyleXfs
.get( nXfId
);
3201 DxfRef
StylesBuffer::getDxf( sal_Int32 nDxfId
) const
3203 return maDxfs
.get( nDxfId
);
3206 FontRef
StylesBuffer::getFontFromCellXf( sal_Int32 nXfId
) const
3209 if( const Xf
* pXf
= getCellXf( nXfId
).get() )
3210 xFont
= pXf
->getFont();
3214 FontRef
StylesBuffer::getDefaultFont() const
3217 if( const Xf
* pXf
= getStyleXf( maCellStyles
.getDefaultXfId() ).get() )
3218 xDefFont
= pXf
->getFont();
3219 // no font from styles - try first loaded font (e.g. BIFF2)
3221 xDefFont
= maFonts
.get( 0 );
3222 OSL_ENSURE( xDefFont
.get(), "StylesBuffer::getDefaultFont - no default font found" );
3226 const FontModel
& StylesBuffer::getDefaultFontModel() const
3228 FontRef xDefFont
= getDefaultFont();
3229 return xDefFont
.get() ? xDefFont
->getModel() : getTheme().getDefaultFontModel();
3232 OUString
StylesBuffer::getDefaultStyleName() const
3234 return maCellStyles
.getDefaultStyleName();
3237 OUString
StylesBuffer::createCellStyle( sal_Int32 nXfId
) const
3239 return maCellStyles
.createCellStyle( nXfId
);
3242 OUString
StylesBuffer::createDxfStyle( sal_Int32 nDxfId
) const
3244 OUString
& rStyleName
= maDxfStyles
[ nDxfId
];
3245 if( rStyleName
.getLength() == 0 )
3247 if( Dxf
* pDxf
= maDxfs
.get( nDxfId
).get() )
3249 rStyleName
= OUStringBuffer( CREATE_OUSTRING( "ConditionalStyle_" ) ).append( nDxfId
+ 1 ).makeStringAndClear();
3250 // create the style sheet (this may change rStyleName if such a style already exists)
3251 Reference
< XStyle
> xStyle
= createStyleObject( rStyleName
, false );
3252 // write style formatting properties
3253 PropertySet
aPropSet( xStyle
);
3254 pDxf
->writeToPropertySet( aPropSet
);
3256 // on error: fallback to default style
3257 if( rStyleName
.getLength() == 0 )
3258 rStyleName
= maCellStyles
.getDefaultStyleName();
3263 void StylesBuffer::writeFontToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nFontId
) const
3265 if( Font
* pFont
= maFonts
.get( nFontId
).get() )
3266 pFont
->writeToPropertyMap( rPropMap
, FONT_PROPTYPE_CELL
);
3269 void StylesBuffer::writeNumFmtToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nNumFmtId
) const
3271 maNumFmts
.writeToPropertyMap( rPropMap
, nNumFmtId
);
3274 void StylesBuffer::writeBorderToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nBorderId
) const
3276 if( Border
* pBorder
= maBorders
.get( nBorderId
).get() )
3277 pBorder
->writeToPropertyMap( rPropMap
);
3280 void StylesBuffer::writeFillToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nFillId
) const
3282 if( Fill
* pFill
= maFills
.get( nFillId
).get() )
3283 pFill
->writeToPropertyMap( rPropMap
);
3286 void StylesBuffer::writeCellXfToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nXfId
) const
3288 if( Xf
* pXf
= maCellXfs
.get( nXfId
).get() )
3289 pXf
->writeToPropertyMap( rPropMap
);
3292 void StylesBuffer::writeStyleXfToPropertyMap( PropertyMap
& rPropMap
, sal_Int32 nXfId
) const
3294 if( Xf
* pXf
= maStyleXfs
.get( nXfId
).get() )
3295 pXf
->writeToPropertyMap( rPropMap
);
3298 void StylesBuffer::writeCellXfToPropertySet( PropertySet
& rPropSet
, sal_Int32 nXfId
) const
3300 if( Xf
* pXf
= maCellXfs
.get( nXfId
).get() )
3301 pXf
->writeToPropertySet( rPropSet
);
3304 void StylesBuffer::writeStyleXfToPropertySet( PropertySet
& rPropSet
, sal_Int32 nXfId
) const
3306 if( Xf
* pXf
= maStyleXfs
.get( nXfId
).get() )
3307 pXf
->writeToPropertySet( rPropSet
);
3310 // ============================================================================