Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "stylesbuffer.hxx"
21 :
22 : #include <com/sun/star/awt/FontDescriptor.hpp>
23 : #include <com/sun/star/awt/FontFamily.hpp>
24 : #include <com/sun/star/awt/FontPitch.hpp>
25 : #include <com/sun/star/awt/FontSlant.hpp>
26 : #include <com/sun/star/awt/FontStrikeout.hpp>
27 : #include <com/sun/star/awt/FontType.hpp>
28 : #include <com/sun/star/awt/FontWeight.hpp>
29 : #include <com/sun/star/awt/FontUnderline.hpp>
30 : #include <com/sun/star/awt/XDevice.hpp>
31 : #include <com/sun/star/awt/XFont2.hpp>
32 : #include <com/sun/star/container/XIndexAccess.hpp>
33 : #include <com/sun/star/container/XNameAccess.hpp>
34 : #include <com/sun/star/style/XStyle.hpp>
35 : #include <com/sun/star/text/WritingMode2.hpp>
36 : #include <com/sun/star/text/XText.hpp>
37 : #include <com/sun/star/table/CellVertJustify2.hpp>
38 : #include <com/sun/star/table/CellJustifyMethod.hpp>
39 : #include <com/sun/star/table/TableBorder.hpp>
40 : #include <editeng/justifyitem.hxx>
41 : #include <editeng/frmdiritem.hxx>
42 : #include <editeng/fontitem.hxx>
43 : #include <editeng/postitem.hxx>
44 : #include <editeng/fhgtitem.hxx>
45 : #include <editeng/wghtitem.hxx>
46 : #include <editeng/udlnitem.hxx>
47 : #include <editeng/colritem.hxx>
48 : #include <editeng/crsditem.hxx>
49 : #include <editeng/cntritem.hxx>
50 : #include <editeng/escpitem.hxx>
51 : #include <editeng/shdditem.hxx>
52 : #include <editeng/eeitem.hxx>
53 : #include <editeng/boxitem.hxx>
54 : #include <editeng/bolnitem.hxx>
55 : #include <editeng/brshitem.hxx>
56 : #include <svx/rotmodit.hxx>
57 : #include <tools/fontenum.hxx>
58 : #include <toolkit/helper/vclunohelper.hxx>
59 : #include <rtl/tencinfo.h>
60 : #include <rtl/ustrbuf.hxx>
61 : #include <oox/core/filterbase.hxx>
62 : #include <oox/helper/attributelist.hxx>
63 : #include <oox/helper/containerhelper.hxx>
64 : #include <oox/helper/propertymap.hxx>
65 : #include <oox/helper/propertyset.hxx>
66 : #include "biffinputstream.hxx"
67 : #include "condformatbuffer.hxx"
68 : #include "excelhandlers.hxx"
69 : #include "themebuffer.hxx"
70 : #include "unitconverter.hxx"
71 : #include "document.hxx"
72 : #include "stlpool.hxx"
73 : #include "docpool.hxx"
74 : #include "ftools.hxx"
75 : #include "scitems.hxx"
76 : #include "attrib.hxx"
77 : #include "globstr.hrc"
78 :
79 : using ::com::sun::star::table::BorderLine2;
80 : namespace oox {
81 : namespace xls {
82 :
83 : // ============================================================================
84 :
85 : using namespace ::com::sun::star::awt;
86 : using namespace ::com::sun::star::container;
87 : using namespace ::com::sun::star::style;
88 : using namespace ::com::sun::star::table;
89 : using namespace ::com::sun::star::text;
90 : using namespace ::com::sun::star::uno;
91 :
92 : using ::oox::core::FilterBase;
93 : using ::rtl::OUString;
94 : using ::rtl::OUStringBuffer;
95 :
96 : // ============================================================================
97 :
98 : namespace {
99 :
100 : // OOXML constants ------------------------------------------------------------
101 :
102 : // OOXML predefined color indexes (also used in BIFF3-BIFF8)
103 : const sal_Int32 OOX_COLOR_USEROFFSET = 0; /// First user defined color in palette (OOXML/BIFF12).
104 : const sal_Int32 BIFF_COLOR_USEROFFSET = 8; /// First user defined color in palette (BIFF3-BIFF8).
105 :
106 : // OOXML font family (also used in BIFF)
107 : const sal_Int32 OOX_FONTFAMILY_NONE = 0;
108 : const sal_Int32 OOX_FONTFAMILY_ROMAN = 1;
109 : const sal_Int32 OOX_FONTFAMILY_SWISS = 2;
110 : const sal_Int32 OOX_FONTFAMILY_MODERN = 3;
111 : const sal_Int32 OOX_FONTFAMILY_SCRIPT = 4;
112 : const sal_Int32 OOX_FONTFAMILY_DECORATIVE = 5;
113 :
114 : // OOXML cell text direction (also used in BIFF)
115 : const sal_Int32 OOX_XF_TEXTDIR_CONTEXT = 0;
116 : const sal_Int32 OOX_XF_TEXTDIR_LTR = 1;
117 : const sal_Int32 OOX_XF_TEXTDIR_RTL = 2;
118 :
119 : // OOXML cell rotation (also used in BIFF)
120 : const sal_Int32 OOX_XF_ROTATION_NONE = 0;
121 : const sal_Int32 OOX_XF_ROTATION_90CCW = 90;
122 : const sal_Int32 OOX_XF_ROTATION_90CW = 180;
123 : const sal_Int32 OOX_XF_ROTATION_STACKED = 255;
124 :
125 : // OOXML cell indentation
126 : const sal_Int32 OOX_XF_INDENT_NONE = 0;
127 :
128 : // OOXML built-in cell styles (also used in BIFF)
129 : const sal_Int32 OOX_STYLE_NORMAL = 0; /// Default cell style.
130 : const sal_Int32 OOX_STYLE_ROWLEVEL = 1; /// RowLevel_x cell style.
131 : const sal_Int32 OOX_STYLE_COLLEVEL = 2; /// ColLevel_x cell style.
132 :
133 : const sal_Int32 OOX_STYLE_LEVELCOUNT = 7; /// Number of outline level styles.
134 :
135 : // BIFF12 constants -----------------------------------------------------------
136 :
137 : // BIFF12 color types
138 : const sal_uInt8 BIFF12_COLOR_AUTO = 0;
139 : const sal_uInt8 BIFF12_COLOR_INDEXED = 1;
140 : const sal_uInt8 BIFF12_COLOR_RGB = 2;
141 : const sal_uInt8 BIFF12_COLOR_THEME = 3;
142 :
143 : // BIFF12 diagonal borders
144 : const sal_uInt8 BIFF12_BORDER_DIAG_TLBR = 0x01; /// Top-left to bottom-right.
145 : const sal_uInt8 BIFF12_BORDER_DIAG_BLTR = 0x02; /// Bottom-left to top-right.
146 :
147 : // BIFF12 gradient fill
148 : const sal_Int32 BIFF12_FILL_GRADIENT = 40;
149 :
150 : // BIFF12 XF flags
151 : const sal_uInt32 BIFF12_XF_WRAPTEXT = 0x00400000;
152 : const sal_uInt32 BIFF12_XF_JUSTLASTLINE = 0x00800000;
153 : const sal_uInt32 BIFF12_XF_SHRINK = 0x01000000;
154 : const sal_uInt32 BIFF12_XF_LOCKED = 0x10000000;
155 : const sal_uInt32 BIFF12_XF_HIDDEN = 0x20000000;
156 :
157 : // BIFF12 XF attribute used flags
158 : const sal_uInt16 BIFF12_XF_NUMFMT_USED = 0x0001;
159 : const sal_uInt16 BIFF12_XF_FONT_USED = 0x0002;
160 : const sal_uInt16 BIFF12_XF_ALIGN_USED = 0x0004;
161 : const sal_uInt16 BIFF12_XF_BORDER_USED = 0x0008;
162 : const sal_uInt16 BIFF12_XF_AREA_USED = 0x0010;
163 : const sal_uInt16 BIFF12_XF_PROT_USED = 0x0020;
164 :
165 : // BIFF12 DXF constants
166 : const sal_uInt16 BIFF12_DXF_FILL_PATTERN = 0;
167 : const sal_uInt16 BIFF12_DXF_FILL_FGCOLOR = 1;
168 : const sal_uInt16 BIFF12_DXF_FILL_BGCOLOR = 2;
169 : const sal_uInt16 BIFF12_DXF_FILL_GRADIENT = 3;
170 : const sal_uInt16 BIFF12_DXF_FILL_STOP = 4;
171 : const sal_uInt16 BIFF12_DXF_FONT_COLOR = 5;
172 : const sal_uInt16 BIFF12_DXF_BORDER_TOP = 6;
173 : const sal_uInt16 BIFF12_DXF_BORDER_BOTTOM = 7;
174 : const sal_uInt16 BIFF12_DXF_BORDER_LEFT = 8;
175 : const sal_uInt16 BIFF12_DXF_BORDER_RIGHT = 9;
176 : const sal_uInt16 BIFF12_DXF_BORDER_DIAG = 10;
177 : const sal_uInt16 BIFF12_DXF_BORDER_VERT = 11;
178 : const sal_uInt16 BIFF12_DXF_BORDER_HOR = 12;
179 : const sal_uInt16 BIFF12_DXF_BORDER_DIAGUP = 13;
180 : const sal_uInt16 BIFF12_DXF_BORDER_DIAGDOWN = 14;
181 : const sal_uInt16 BIFF12_DXF_FONT_NAME = 24;
182 : const sal_uInt16 BIFF12_DXF_FONT_WEIGHT = 25;
183 : const sal_uInt16 BIFF12_DXF_FONT_UNDERLINE = 26;
184 : const sal_uInt16 BIFF12_DXF_FONT_ESCAPEMENT = 27;
185 : const sal_uInt16 BIFF12_DXF_FONT_ITALIC = 28;
186 : const sal_uInt16 BIFF12_DXF_FONT_STRIKE = 29;
187 : const sal_uInt16 BIFF12_DXF_FONT_OUTLINE = 30;
188 : const sal_uInt16 BIFF12_DXF_FONT_SHADOW = 31;
189 : const sal_uInt16 BIFF12_DXF_FONT_CONDENSE = 32;
190 : const sal_uInt16 BIFF12_DXF_FONT_EXTEND = 33;
191 : const sal_uInt16 BIFF12_DXF_FONT_CHARSET = 34;
192 : const sal_uInt16 BIFF12_DXF_FONT_FAMILY = 35;
193 : const sal_uInt16 BIFF12_DXF_FONT_HEIGHT = 36;
194 : const sal_uInt16 BIFF12_DXF_FONT_SCHEME = 37;
195 : const sal_uInt16 BIFF12_DXF_NUMFMT_CODE = 38;
196 : const sal_uInt16 BIFF12_DXF_NUMFMT_ID = 41;
197 :
198 : // BIFF12 CELLSTYLE flags
199 : const sal_uInt16 BIFF12_CELLSTYLE_BUILTIN = 0x0001;
200 : const sal_uInt16 BIFF12_CELLSTYLE_HIDDEN = 0x0002;
201 : const sal_uInt16 BIFF12_CELLSTYLE_CUSTOM = 0x0004;
202 :
203 : // BIFF constants -------------------------------------------------------------
204 :
205 : // BIFF predefined color indexes
206 : const sal_uInt16 BIFF2_COLOR_BLACK = 0; /// Black (text) in BIFF2.
207 : const sal_uInt16 BIFF2_COLOR_WHITE = 1; /// White (background) in BIFF2.
208 :
209 : // BIFF font flags, also used in BIFF12
210 : const sal_uInt16 BIFF_FONTFLAG_BOLD = 0x0001;
211 : const sal_uInt16 BIFF_FONTFLAG_ITALIC = 0x0002;
212 : const sal_uInt16 BIFF_FONTFLAG_UNDERLINE = 0x0004;
213 : const sal_uInt16 BIFF_FONTFLAG_STRIKEOUT = 0x0008;
214 : const sal_uInt16 BIFF_FONTFLAG_OUTLINE = 0x0010;
215 : const sal_uInt16 BIFF_FONTFLAG_SHADOW = 0x0020;
216 : const sal_uInt16 BIFF_FONTFLAG_CONDENSE = 0x0040;
217 :
218 : // BIFF font weight
219 : const sal_uInt16 BIFF_FONTWEIGHT_BOLD = 450;
220 :
221 : // BIFF font underline, also used in BIFF12
222 : const sal_uInt8 BIFF_FONTUNDERL_NONE = 0;
223 : const sal_uInt8 BIFF_FONTUNDERL_SINGLE = 1;
224 : const sal_uInt8 BIFF_FONTUNDERL_DOUBLE = 2;
225 : const sal_uInt8 BIFF_FONTUNDERL_SINGLE_ACC = 33;
226 : const sal_uInt8 BIFF_FONTUNDERL_DOUBLE_ACC = 34;
227 :
228 : // BIFF XF flags
229 : const sal_uInt16 BIFF_XF_LOCKED = 0x0001;
230 : const sal_uInt16 BIFF_XF_HIDDEN = 0x0002;
231 : const sal_uInt16 BIFF_XF_STYLE = 0x0004;
232 : const sal_uInt16 BIFF_XF_STYLEPARENT = 0x0FFF; /// Styles don't have a parent.
233 : const sal_uInt16 BIFF_XF_WRAPTEXT = 0x0008; /// Automatic line break.
234 : const sal_uInt16 BIFF_XF_JUSTLASTLINE = 0x0080;
235 : const sal_uInt16 BIFF_XF_SHRINK = 0x0010; /// Shrink to fit into cell.
236 : const sal_uInt16 BIFF_XF_MERGE = 0x0020;
237 :
238 : // BIFF XF attribute used flags
239 : const sal_uInt8 BIFF_XF_NUMFMT_USED = 0x01;
240 : const sal_uInt8 BIFF_XF_FONT_USED = 0x02;
241 : const sal_uInt8 BIFF_XF_ALIGN_USED = 0x04;
242 : const sal_uInt8 BIFF_XF_BORDER_USED = 0x08;
243 : const sal_uInt8 BIFF_XF_AREA_USED = 0x10;
244 : const sal_uInt8 BIFF_XF_PROT_USED = 0x20;
245 :
246 : // BIFF XF text orientation
247 : const sal_uInt8 BIFF_XF_ORIENT_NONE = 0;
248 : const sal_uInt8 BIFF_XF_ORIENT_STACKED = 1; /// Stacked top to bottom.
249 : const sal_uInt8 BIFF_XF_ORIENT_90CCW = 2; /// 90 degr. counterclockwise.
250 : const sal_uInt8 BIFF_XF_ORIENT_90CW = 3; /// 90 degr. clockwise.
251 :
252 : // BIFF XF line styles
253 : const sal_uInt8 BIFF_LINE_NONE = 0;
254 : const sal_uInt8 BIFF_LINE_THIN = 1;
255 :
256 : // BIFF XF patterns
257 : const sal_uInt8 BIFF_PATT_NONE = 0;
258 : const sal_uInt8 BIFF_PATT_125 = 17;
259 :
260 : // BIFF2 XF flags
261 : const sal_uInt8 BIFF2_XF_VALFMT_MASK = 0x3F;
262 : const sal_uInt8 BIFF2_XF_LOCKED = 0x40;
263 : const sal_uInt8 BIFF2_XF_HIDDEN = 0x80;
264 : const sal_uInt8 BIFF2_XF_LEFTLINE = 0x08;
265 : const sal_uInt8 BIFF2_XF_RIGHTLINE = 0x10;
266 : const sal_uInt8 BIFF2_XF_TOPLINE = 0x20;
267 : const sal_uInt8 BIFF2_XF_BOTTOMLINE = 0x40;
268 : const sal_uInt8 BIFF2_XF_BACKGROUND = 0x80;
269 :
270 : // BIFF8 diagonal borders
271 : const sal_uInt32 BIFF_XF_DIAG_TLBR = 0x40000000; /// Top-left to bottom-right.
272 : const sal_uInt32 BIFF_XF_DIAG_BLTR = 0x80000000; /// Bottom-left to top-right.
273 :
274 : // BIFF STYLE flags
275 : const sal_uInt16 BIFF_STYLE_BUILTIN = 0x8000;
276 : const sal_uInt16 BIFF_STYLE_XFMASK = 0x0FFF;
277 :
278 : // BIFF STYLEEXT flags
279 : const sal_uInt8 BIFF_STYLEEXT_BUILTIN = 0x01;
280 : const sal_uInt8 BIFF_STYLEEXT_HIDDEN = 0x02;
281 : const sal_uInt8 BIFF_STYLEEXT_CUSTOM = 0x04;
282 :
283 : // BIFF conditional formatting
284 : const sal_uInt32 BIFF_CFRULE_BORDER_LEFT = 0x00000400;
285 : const sal_uInt32 BIFF_CFRULE_BORDER_RIGHT = 0x00000800;
286 : const sal_uInt32 BIFF_CFRULE_BORDER_TOP = 0x00001000;
287 : const sal_uInt32 BIFF_CFRULE_BORDER_BOTTOM = 0x00002000;
288 : const sal_uInt32 BIFF_CFRULE_FILL_PATTERN = 0x00010000;
289 : const sal_uInt32 BIFF_CFRULE_FILL_PATTCOLOR = 0x00020000;
290 : const sal_uInt32 BIFF_CFRULE_FILL_FILLCOLOR = 0x00040000;
291 : const sal_uInt32 BIFF_CFRULE_FONTBLOCK = 0x04000000;
292 : const sal_uInt32 BIFF_CFRULE_ALIGNBLOCK = 0x08000000;
293 : const sal_uInt32 BIFF_CFRULE_BORDERBLOCK = 0x10000000;
294 : const sal_uInt32 BIFF_CFRULE_FILLBLOCK = 0x20000000;
295 : const sal_uInt32 BIFF_CFRULE_PROTBLOCK = 0x40000000;
296 :
297 : const sal_uInt32 BIFF_CFRULE_FONT_STYLE = 0x00000002; /// Font posture or weight modified?
298 : const sal_uInt32 BIFF_CFRULE_FONT_OUTLINE = 0x00000008; /// Font outline modified?
299 : const sal_uInt32 BIFF_CFRULE_FONT_SHADOW = 0x00000010; /// Font shadow modified?
300 : const sal_uInt32 BIFF_CFRULE_FONT_STRIKEOUT = 0x00000080; /// Font cancellation modified?
301 : const sal_uInt32 BIFF_CFRULE_FONT_UNDERL = 0x00000001; /// Font underline type modified?
302 : const sal_uInt32 BIFF_CFRULE_FONT_ESCAPEM = 0x00000001; /// Font escapement type modified?
303 :
304 : // ----------------------------------------------------------------------------
305 :
306 0 : sal_Int32 lclReadRgbColor( BinaryInputStream& rStrm )
307 : {
308 : sal_uInt8 nR, nG, nB, nA;
309 0 : rStrm >> nR >> nG >> nB >> nA;
310 0 : sal_Int32 nValue = nA;
311 0 : nValue <<= 8;
312 0 : nValue |= nR;
313 0 : nValue <<= 8;
314 0 : nValue |= nG;
315 0 : nValue <<= 8;
316 0 : nValue |= nB;
317 0 : return nValue;
318 : }
319 :
320 : } // namespace
321 :
322 : // ============================================================================
323 :
324 22 : ExcelGraphicHelper::ExcelGraphicHelper( const WorkbookHelper& rHelper ) :
325 44 : GraphicHelper( rHelper.getBaseFilter().getComponentContext(), rHelper.getBaseFilter().getTargetFrame(), rHelper.getBaseFilter().getStorage() ),
326 44 : WorkbookHelper( rHelper )
327 : {
328 22 : }
329 :
330 12 : sal_Int32 ExcelGraphicHelper::getSchemeColor( sal_Int32 nToken ) const
331 : {
332 12 : if( getFilterType() == FILTER_OOXML )
333 12 : return getTheme().getColorByToken( nToken );
334 0 : return GraphicHelper::getSchemeColor( nToken );
335 : }
336 :
337 132 : sal_Int32 ExcelGraphicHelper::getPaletteColor( sal_Int32 nPaletteIdx ) const
338 : {
339 132 : return getStyles().getPaletteColor( nPaletteIdx );
340 : }
341 :
342 : // ============================================================================
343 :
344 0 : void Color::setAuto()
345 : {
346 0 : clearTransformations();
347 0 : setSchemeClr( XML_phClr );
348 0 : }
349 :
350 72 : void Color::setRgb( sal_Int32 nRgbValue, double fTint )
351 : {
352 72 : clearTransformations();
353 72 : setSrgbClr( nRgbValue & 0xFFFFFF );
354 72 : if( fTint != 0.0 ) addExcelTintTransformation( fTint );
355 72 : }
356 :
357 12 : void Color::setTheme( sal_Int32 nThemeIdx, double fTint )
358 : {
359 12 : clearTransformations();
360 : static const sal_Int32 spnColorTokens[] = {
361 : XML_lt1, XML_dk1, XML_lt2, XML_dk2, XML_accent1, XML_accent2,
362 : XML_accent3, XML_accent4, XML_accent5, XML_accent6, XML_hlink, XML_folHlink };
363 12 : setSchemeClr( STATIC_ARRAY_SELECT( spnColorTokens, nThemeIdx, XML_TOKEN_INVALID ) );
364 12 : if( fTint != 0.0 ) addExcelTintTransformation( fTint );
365 12 : }
366 :
367 386 : void Color::setIndexed( sal_Int32 nPaletteIdx, double fTint )
368 : {
369 386 : clearTransformations();
370 386 : setPaletteClr( nPaletteIdx );
371 386 : if( fTint != 0.0 ) addExcelTintTransformation( fTint );
372 386 : }
373 :
374 84 : void Color::importColor( const AttributeList& rAttribs )
375 : {
376 84 : if( rAttribs.getBool( XML_auto, false ) )
377 0 : setAuto();
378 84 : else if( rAttribs.hasAttribute( XML_rgb ) )
379 72 : setRgb( rAttribs.getIntegerHex( XML_rgb, API_RGB_TRANSPARENT ), rAttribs.getDouble( XML_tint, 0.0 ) );
380 12 : else if( rAttribs.hasAttribute( XML_theme ) )
381 12 : setTheme( rAttribs.getInteger( XML_theme, -1 ), rAttribs.getDouble( XML_tint, 0.0 ) );
382 0 : else if( rAttribs.hasAttribute( XML_indexed ) )
383 0 : setIndexed( rAttribs.getInteger( XML_indexed, -1 ), rAttribs.getDouble( XML_tint, 0.0 ) );
384 : else
385 : {
386 : OSL_FAIL( "Color::importColor - unknown color type" );
387 0 : setAuto();
388 : }
389 84 : }
390 :
391 0 : void Color::importColor( SequenceInputStream& rStrm )
392 : {
393 : sal_uInt8 nFlags, nIndex;
394 : sal_Int16 nTint;
395 0 : rStrm >> nFlags >> nIndex >> nTint;
396 :
397 : // scale tint from signed 16-bit to double range -1.0 ... 1.0
398 0 : double fTint = nTint;
399 0 : if( nTint < 0 )
400 0 : fTint /= -SAL_MIN_INT16;
401 0 : else if( nTint > 0 )
402 0 : fTint /= SAL_MAX_INT16;
403 :
404 0 : switch( extractValue< sal_uInt8 >( nFlags, 1, 7 ) )
405 : {
406 : case BIFF12_COLOR_AUTO:
407 0 : setAuto();
408 0 : rStrm.skip( 4 );
409 0 : break;
410 : case BIFF12_COLOR_INDEXED:
411 0 : setIndexed( nIndex, fTint );
412 0 : rStrm.skip( 4 );
413 0 : break;
414 : case BIFF12_COLOR_RGB:
415 0 : setRgb( lclReadRgbColor( rStrm ), fTint );
416 0 : break;
417 : case BIFF12_COLOR_THEME:
418 0 : setTheme( nIndex, fTint );
419 0 : rStrm.skip( 4 );
420 0 : break;
421 : default:
422 : OSL_FAIL( "Color::importColor - unknown color type" );
423 0 : setAuto();
424 0 : rStrm.skip( 4 );
425 : }
426 0 : }
427 :
428 0 : void Color::importColorId( SequenceInputStream& rStrm )
429 : {
430 0 : setIndexed( rStrm.readInt32() );
431 0 : }
432 :
433 0 : SequenceInputStream& operator>>( SequenceInputStream& rStrm, Color& orColor )
434 : {
435 0 : orColor.importColor( rStrm );
436 0 : return rStrm;
437 : }
438 :
439 : // ============================================================================
440 :
441 : namespace {
442 :
443 : /** Standard EGA colors, bright. */
444 : #define PALETTE_EGA_COLORS_LIGHT \
445 : 0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF
446 : /** Standard EGA colors, dark. */
447 : #define PALETTE_EGA_COLORS_DARK \
448 : 0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080
449 :
450 : /** Default color table for BIFF2. */
451 : static const sal_Int32 spnDefColors2[] =
452 : {
453 : /* 0 */ PALETTE_EGA_COLORS_LIGHT
454 : };
455 :
456 : /** Default color table for BIFF3/BIFF4. */
457 : static const sal_Int32 spnDefColors3[] =
458 : {
459 : /* 0 */ PALETTE_EGA_COLORS_LIGHT,
460 : /* 8 */ PALETTE_EGA_COLORS_LIGHT,
461 : /* 16 */ PALETTE_EGA_COLORS_DARK
462 : };
463 :
464 : /** Default color table for BIFF5. */
465 : static const sal_Int32 spnDefColors5[] =
466 : {
467 : /* 0 */ PALETTE_EGA_COLORS_LIGHT,
468 : /* 8 */ PALETTE_EGA_COLORS_LIGHT,
469 : /* 16 */ PALETTE_EGA_COLORS_DARK,
470 : /* 24 */ 0x8080FF, 0x802060, 0xFFFFC0, 0xA0E0E0, 0x600080, 0xFF8080, 0x0080C0, 0xC0C0FF,
471 : /* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
472 : /* 40 */ 0x00CFFF, 0x69FFFF, 0xE0FFE0, 0xFFFF80, 0xA6CAF0, 0xDD9CB3, 0xB38FEE, 0xE3E3E3,
473 : /* 48 */ 0x2A6FF9, 0x3FB8CD, 0x488436, 0x958C41, 0x8E5E42, 0xA0627A, 0x624FAC, 0x969696,
474 : /* 56 */ 0x1D2FBE, 0x286676, 0x004500, 0x453E01, 0x6A2813, 0x85396A, 0x4A3285, 0x424242
475 : };
476 :
477 : /** Default color table for BIFF8/BIFF12/OOXML. */
478 : static const sal_Int32 spnDefColors8[] =
479 : {
480 : /* 0 */ PALETTE_EGA_COLORS_LIGHT,
481 : /* 8 */ PALETTE_EGA_COLORS_LIGHT,
482 : /* 16 */ PALETTE_EGA_COLORS_DARK,
483 : /* 24 */ 0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF,
484 : /* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF,
485 : /* 40 */ 0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99,
486 : /* 48 */ 0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
487 : /* 56 */ 0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333
488 : };
489 :
490 : #undef PALETTE_EGA_COLORS_LIGHT
491 : #undef PALETTE_EGA_COLORS_DARK
492 :
493 : } // namespace
494 :
495 : // ----------------------------------------------------------------------------
496 :
497 22 : ColorPalette::ColorPalette( const WorkbookHelper& rHelper ) :
498 22 : WorkbookHelper( rHelper )
499 : {
500 : // default colors
501 22 : switch( getFilterType() )
502 : {
503 : case FILTER_OOXML:
504 22 : maColors.insert( maColors.begin(), spnDefColors8, STATIC_ARRAY_END( spnDefColors8 ) );
505 22 : mnAppendIndex = OOX_COLOR_USEROFFSET;
506 22 : break;
507 : case FILTER_BIFF:
508 0 : switch( getBiff() )
509 : {
510 0 : case BIFF2: maColors.insert( maColors.begin(), spnDefColors2, STATIC_ARRAY_END( spnDefColors2 ) ); break;
511 : case BIFF3:
512 0 : case BIFF4: maColors.insert( maColors.begin(), spnDefColors3, STATIC_ARRAY_END( spnDefColors3 ) ); break;
513 0 : case BIFF5: maColors.insert( maColors.begin(), spnDefColors5, STATIC_ARRAY_END( spnDefColors5 ) ); break;
514 0 : case BIFF8: maColors.insert( maColors.begin(), spnDefColors8, STATIC_ARRAY_END( spnDefColors8 ) ); break;
515 0 : case BIFF_UNKNOWN: break;
516 : }
517 0 : mnAppendIndex = BIFF_COLOR_USEROFFSET;
518 0 : break;
519 0 : case FILTER_UNKNOWN: break;
520 : }
521 22 : }
522 :
523 112 : void ColorPalette::importPaletteColor( const AttributeList& rAttribs )
524 : {
525 112 : appendColor( rAttribs.getIntegerHex( XML_rgb, API_RGB_WHITE ) );
526 112 : }
527 :
528 0 : void ColorPalette::importPaletteColor( SequenceInputStream& rStrm )
529 : {
530 0 : sal_Int32 nRgb = lclReadRgbColor( rStrm );
531 0 : appendColor( nRgb & 0xFFFFFF );
532 0 : }
533 :
534 132 : sal_Int32 ColorPalette::getColor( sal_Int32 nPaletteIdx ) const
535 : {
536 132 : sal_Int32 nColor = API_RGB_TRANSPARENT;
537 132 : if( const sal_Int32* pnPaletteColor = ContainerHelper::getVectorElement( maColors, nPaletteIdx ) )
538 : {
539 0 : nColor = *pnPaletteColor;
540 : }
541 132 : else switch( nPaletteIdx )
542 : {
543 : case OOX_COLOR_WINDOWTEXT3:
544 : case OOX_COLOR_WINDOWTEXT:
545 110 : case OOX_COLOR_CHWINDOWTEXT: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_windowText ); break;
546 : case OOX_COLOR_WINDOWBACK3:
547 : case OOX_COLOR_WINDOWBACK:
548 22 : case OOX_COLOR_CHWINDOWBACK: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_window ); break;
549 0 : case OOX_COLOR_BUTTONBACK: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_btnFace ); break;
550 0 : case OOX_COLOR_CHBORDERAUTO: nColor = API_RGB_BLACK; /* really always black? */ break;
551 0 : case OOX_COLOR_NOTEBACK: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_infoBk ); break;
552 0 : case OOX_COLOR_NOTETEXT: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_infoText ); break;
553 0 : case OOX_COLOR_FONTAUTO: nColor = API_RGB_TRANSPARENT; break;
554 : default: OSL_FAIL( "ColorPalette::getColor - unknown color index" );
555 : }
556 132 : return nColor;
557 : }
558 :
559 112 : void ColorPalette::appendColor( sal_Int32 nRGBValue )
560 : {
561 112 : if( mnAppendIndex < maColors.size() )
562 112 : maColors[ mnAppendIndex ] = nRGBValue;
563 : else
564 0 : maColors.push_back( nRGBValue );
565 112 : ++mnAppendIndex;
566 112 : }
567 :
568 : // ============================================================================
569 :
570 : namespace {
571 :
572 630 : void lclSetFontName( ApiScriptFontName& rFontName, const FontDescriptor& rFontDesc, bool bHasGlyphs )
573 : {
574 630 : if( bHasGlyphs )
575 : {
576 236 : rFontName.maName = rFontDesc.Name;
577 236 : rFontName.mnFamily = rFontDesc.Family;
578 : // API font descriptor contains rtl_TextEncoding constants
579 236 : rFontName.mnTextEnc = rFontDesc.CharSet;
580 : }
581 : else
582 : {
583 394 : rFontName = ApiScriptFontName();
584 : }
585 630 : }
586 :
587 : } // namespace
588 :
589 : // ----------------------------------------------------------------------------
590 :
591 44 : FontModel::FontModel() :
592 : mnScheme( XML_none ),
593 : mnFamily( OOX_FONTFAMILY_NONE ),
594 : mnCharSet( WINDOWS_CHARSET_DEFAULT ),
595 : mfHeight( 0.0 ),
596 : mnUnderline( XML_none ),
597 : mnEscapement( XML_baseline ),
598 : mbBold( false ),
599 : mbItalic( false ),
600 : mbStrikeout( false ),
601 : mbOutline( false ),
602 44 : mbShadow( false )
603 : {
604 44 : }
605 :
606 0 : void FontModel::setBiff12Scheme( sal_uInt8 nScheme )
607 : {
608 : static const sal_Int32 spnSchemes[] = { XML_none, XML_major, XML_minor };
609 0 : mnScheme = STATIC_ARRAY_SELECT( spnSchemes, nScheme, XML_none );
610 0 : }
611 :
612 0 : void FontModel::setBiffHeight( sal_uInt16 nHeight )
613 : {
614 0 : mfHeight = nHeight / 20.0; // convert twips to points
615 0 : }
616 :
617 0 : void FontModel::setBiffWeight( sal_uInt16 nWeight )
618 : {
619 0 : mbBold = nWeight >= BIFF_FONTWEIGHT_BOLD;
620 0 : }
621 :
622 0 : void FontModel::setBiffUnderline( sal_uInt16 nUnderline )
623 : {
624 0 : switch( nUnderline )
625 : {
626 0 : case BIFF_FONTUNDERL_NONE: mnUnderline = XML_none; break;
627 0 : case BIFF_FONTUNDERL_SINGLE: mnUnderline = XML_single; break;
628 0 : case BIFF_FONTUNDERL_DOUBLE: mnUnderline = XML_double; break;
629 0 : case BIFF_FONTUNDERL_SINGLE_ACC: mnUnderline = XML_singleAccounting; break;
630 0 : case BIFF_FONTUNDERL_DOUBLE_ACC: mnUnderline = XML_doubleAccounting; break;
631 0 : default: mnUnderline = XML_none;
632 : }
633 0 : }
634 :
635 0 : void FontModel::setBiffEscapement( sal_uInt16 nEscapement )
636 : {
637 : static const sal_Int32 spnEscapes[] = { XML_baseline, XML_superscript, XML_subscript };
638 0 : mnEscapement = STATIC_ARRAY_SELECT( spnEscapes, nEscapement, XML_baseline );
639 0 : }
640 :
641 : // ----------------------------------------------------------------------------
642 :
643 210 : 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 210 : mbShadowUsed( bAllUsed )
655 : {
656 210 : }
657 :
658 : // ----------------------------------------------------------------------------
659 :
660 1024 : ApiScriptFontName::ApiScriptFontName() :
661 : mnFamily( ::com::sun::star::awt::FontFamily::DONTKNOW ),
662 1024 : mnTextEnc( RTL_TEXTENCODING_DONTKNOW )
663 : {
664 1024 : }
665 :
666 : // ----------------------------------------------------------------------------
667 :
668 210 : ApiFontData::ApiFontData() :
669 : maDesc(
670 : "Calibri",
671 : 220, // height 11 points
672 : 0,
673 : OUString(),
674 : ::com::sun::star::awt::FontFamily::DONTKNOW,
675 : RTL_TEXTENCODING_DONTKNOW,
676 : ::com::sun::star::awt::FontPitch::DONTKNOW,
677 : 100.0,
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,
682 : 0.0,
683 : sal_False,
684 : sal_False,
685 : ::com::sun::star::awt::FontType::DONTKNOW ),
686 : mnColor( API_RGB_TRANSPARENT ),
687 : mnEscapement( API_ESCAPE_NONE ),
688 : mnEscapeHeight( API_ESCAPEHEIGHT_NONE ),
689 : mbOutline( false ),
690 210 : mbShadow( false )
691 : {
692 210 : maLatinFont.maName = maDesc.Name;
693 210 : }
694 :
695 : // ============================================================================
696 :
697 134 : Font::Font( const WorkbookHelper& rHelper, bool bDxf ) :
698 : WorkbookHelper( rHelper ),
699 134 : maModel( rHelper.getTheme().getDefaultFontModel() ),
700 134 : maUsedFlags( !bDxf ),
701 402 : mbDxf( bDxf )
702 : {
703 134 : }
704 :
705 76 : Font::Font( const WorkbookHelper& rHelper, const FontModel& rModel ) :
706 : WorkbookHelper( rHelper ),
707 : maModel( rModel ),
708 : maUsedFlags( true ),
709 76 : mbDxf( false )
710 : {
711 76 : }
712 :
713 536 : void Font::importAttribs( sal_Int32 nElement, const AttributeList& rAttribs )
714 : {
715 536 : const FontModel& rDefModel = getTheme().getDefaultFontModel();
716 536 : switch( nElement )
717 : {
718 : case XLS_TOKEN( name ): // when in <font> element
719 : case XLS_TOKEN( rFont ): // when in <rPr> element
720 134 : if( rAttribs.hasAttribute( XML_val ) )
721 : {
722 134 : maModel.maName = rAttribs.getXString( XML_val, OUString() );
723 134 : maUsedFlags.mbNameUsed = true;
724 : }
725 134 : break;
726 : case XLS_TOKEN( scheme ):
727 6 : maModel.mnScheme = rAttribs.getToken( XML_val, rDefModel.mnScheme );
728 6 : break;
729 : case XLS_TOKEN( family ):
730 134 : maModel.mnFamily = rAttribs.getInteger( XML_val, rDefModel.mnFamily );
731 134 : break;
732 : case XLS_TOKEN( charset ):
733 68 : maModel.mnCharSet = rAttribs.getInteger( XML_val, rDefModel.mnCharSet );
734 68 : break;
735 : case XLS_TOKEN( sz ):
736 134 : maModel.mfHeight = rAttribs.getDouble( XML_val, rDefModel.mfHeight );
737 134 : maUsedFlags.mbHeightUsed = true;
738 134 : break;
739 : case XLS_TOKEN( color ):
740 36 : maModel.maColor.importColor( rAttribs );
741 36 : maUsedFlags.mbColorUsed = true;
742 36 : break;
743 : case XLS_TOKEN( u ):
744 6 : maModel.mnUnderline = rAttribs.getToken( XML_val, XML_single );
745 6 : maUsedFlags.mbUnderlineUsed = true;
746 6 : break;
747 : case XLS_TOKEN( vertAlign ):
748 0 : maModel.mnEscapement = rAttribs.getToken( XML_val, XML_baseline );
749 0 : maUsedFlags.mbEscapementUsed = true;
750 0 : break;
751 : case XLS_TOKEN( b ):
752 8 : maModel.mbBold = rAttribs.getBool( XML_val, true );
753 8 : maUsedFlags.mbWeightUsed = true;
754 8 : break;
755 : case XLS_TOKEN( i ):
756 8 : maModel.mbItalic = rAttribs.getBool( XML_val, true );
757 8 : maUsedFlags.mbPostureUsed = true;
758 8 : break;
759 : case XLS_TOKEN( strike ):
760 2 : maModel.mbStrikeout = rAttribs.getBool( XML_val, true );
761 2 : maUsedFlags.mbStrikeoutUsed = true;
762 2 : break;
763 : case XLS_TOKEN( outline ):
764 0 : maModel.mbOutline = rAttribs.getBool( XML_val, true );
765 0 : maUsedFlags.mbOutlineUsed = true;
766 0 : break;
767 : case XLS_TOKEN( shadow ):
768 0 : maModel.mbShadow = rAttribs.getBool( XML_val, true );
769 0 : maUsedFlags.mbShadowUsed = true;
770 0 : break;
771 : }
772 536 : }
773 :
774 0 : void Font::importFont( SequenceInputStream& rStrm )
775 : {
776 : OSL_ENSURE( !mbDxf, "Font::importFont - unexpected conditional formatting flag" );
777 :
778 : sal_uInt16 nHeight, nFlags, nWeight, nEscapement;
779 : sal_uInt8 nUnderline, nFamily, nCharSet, nScheme;
780 0 : rStrm >> nHeight >> nFlags >> nWeight >> nEscapement >> nUnderline >> nFamily >> nCharSet;
781 0 : rStrm.skip( 1 );
782 0 : rStrm >> maModel.maColor >> nScheme >> maModel.maName;
783 :
784 : // equal constants in all BIFFs for weight, underline, and escapement
785 0 : maModel.setBiff12Scheme( nScheme );
786 0 : maModel.setBiffHeight( nHeight );
787 0 : maModel.setBiffWeight( nWeight );
788 0 : maModel.setBiffUnderline( nUnderline );
789 0 : maModel.setBiffEscapement( nEscapement );
790 0 : maModel.mnFamily = nFamily;
791 0 : maModel.mnCharSet = nCharSet;
792 : // equal flags in all BIFFs
793 0 : maModel.mbItalic = getFlag( nFlags, BIFF_FONTFLAG_ITALIC );
794 0 : maModel.mbStrikeout = getFlag( nFlags, BIFF_FONTFLAG_STRIKEOUT );
795 0 : maModel.mbOutline = getFlag( nFlags, BIFF_FONTFLAG_OUTLINE );
796 0 : maModel.mbShadow = getFlag( nFlags, BIFF_FONTFLAG_SHADOW );
797 0 : }
798 :
799 0 : void Font::importDxfName( SequenceInputStream& rStrm )
800 : {
801 : OSL_ENSURE( mbDxf, "Font::importDxfName - missing conditional formatting flag" );
802 0 : maModel.maName = BiffHelper::readString( rStrm, false );
803 0 : maUsedFlags.mbColorUsed = true;
804 0 : }
805 :
806 0 : void Font::importDxfColor( SequenceInputStream& rStrm )
807 : {
808 : OSL_ENSURE( mbDxf, "Font::importDxfColor - missing conditional formatting flag" );
809 0 : rStrm >> maModel.maColor;
810 0 : maUsedFlags.mbColorUsed = true;
811 0 : }
812 :
813 0 : void Font::importDxfScheme( SequenceInputStream& rStrm )
814 : {
815 : OSL_ENSURE( mbDxf, "Font::importDxfScheme - missing conditional formatting flag" );
816 0 : maModel.setBiff12Scheme( rStrm.readuInt8() );
817 0 : maUsedFlags.mbSchemeUsed = true;
818 0 : }
819 :
820 0 : void Font::importDxfHeight( SequenceInputStream& rStrm )
821 : {
822 : OSL_ENSURE( mbDxf, "Font::importDxfHeight - missing conditional formatting flag" );
823 0 : maModel.setBiffHeight( rStrm.readuInt16() );
824 0 : maUsedFlags.mbHeightUsed = true;
825 0 : }
826 :
827 0 : void Font::importDxfWeight( SequenceInputStream& rStrm )
828 : {
829 : OSL_ENSURE( mbDxf, "Font::importDxfWeight - missing conditional formatting flag" );
830 0 : maModel.setBiffWeight( rStrm.readuInt16() );
831 0 : maUsedFlags.mbWeightUsed = true;
832 0 : }
833 :
834 0 : void Font::importDxfUnderline( SequenceInputStream& rStrm )
835 : {
836 : OSL_ENSURE( mbDxf, "Font::importDxfUnderline - missing conditional formatting flag" );
837 0 : maModel.setBiffUnderline( rStrm.readuInt16() );
838 0 : maUsedFlags.mbUnderlineUsed = true;
839 0 : }
840 :
841 0 : void Font::importDxfEscapement( SequenceInputStream& rStrm )
842 : {
843 : OSL_ENSURE( mbDxf, "Font::importDxfEscapement - missing conditional formatting flag" );
844 0 : maModel.setBiffEscapement( rStrm.readuInt16() );
845 0 : maUsedFlags.mbEscapementUsed = true;
846 0 : }
847 :
848 0 : void Font::importDxfFlag( sal_Int32 nElement, SequenceInputStream& rStrm )
849 : {
850 : OSL_ENSURE( mbDxf, "Font::importDxfFlag - missing conditional formatting flag" );
851 0 : bool bFlag = rStrm.readuInt8() != 0;
852 0 : switch( nElement )
853 : {
854 : case XML_i:
855 0 : maModel.mbItalic = bFlag;
856 0 : maUsedFlags.mbPostureUsed = true;
857 0 : break;
858 : case XML_strike:
859 0 : maModel.mbStrikeout = bFlag;
860 0 : maUsedFlags.mbStrikeoutUsed = true;
861 0 : break;
862 : case XML_outline:
863 0 : maModel.mbOutline = bFlag;
864 0 : maUsedFlags.mbOutlineUsed = true;
865 0 : break;
866 : case XML_shadow:
867 0 : maModel.mbShadow = bFlag;
868 0 : maUsedFlags.mbShadowUsed = true;
869 0 : break;
870 : default:
871 : OSL_FAIL( "Font::importDxfFlag - unexpected element identifier" );
872 : }
873 0 : }
874 :
875 210 : void Font::finalizeImport()
876 : {
877 : namespace cssawt = ::com::sun::star::awt;
878 :
879 : // font name
880 210 : maApiData.maDesc.Name = maModel.maName;
881 :
882 : // font family
883 210 : switch( maModel.mnFamily )
884 : {
885 42 : case OOX_FONTFAMILY_NONE: maApiData.maDesc.Family = cssawt::FontFamily::DONTKNOW; break;
886 0 : case OOX_FONTFAMILY_ROMAN: maApiData.maDesc.Family = cssawt::FontFamily::ROMAN; break;
887 168 : case OOX_FONTFAMILY_SWISS: maApiData.maDesc.Family = cssawt::FontFamily::SWISS; break;
888 0 : case OOX_FONTFAMILY_MODERN: maApiData.maDesc.Family = cssawt::FontFamily::MODERN; break;
889 0 : case OOX_FONTFAMILY_SCRIPT: maApiData.maDesc.Family = cssawt::FontFamily::SCRIPT; break;
890 0 : case OOX_FONTFAMILY_DECORATIVE: maApiData.maDesc.Family = cssawt::FontFamily::DECORATIVE; break;
891 : }
892 :
893 : // character set (API font descriptor uses rtl_TextEncoding in member CharSet!)
894 210 : if( (0 <= maModel.mnCharSet) && (maModel.mnCharSet <= SAL_MAX_UINT8) )
895 : maApiData.maDesc.CharSet = static_cast< sal_Int16 >(
896 210 : rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( maModel.mnCharSet ) ) );
897 :
898 : // color, height, weight, slant, strikeout, outline, shadow
899 210 : maApiData.mnColor = maModel.maColor.getColor( getBaseFilter().getGraphicHelper() );
900 210 : maApiData.maDesc.Height = static_cast< sal_Int16 >( maModel.mfHeight * 20.0 );
901 210 : maApiData.maDesc.Weight = maModel.mbBold ? cssawt::FontWeight::BOLD : cssawt::FontWeight::NORMAL;
902 210 : maApiData.maDesc.Slant = maModel.mbItalic ? cssawt::FontSlant_ITALIC : cssawt::FontSlant_NONE;
903 210 : maApiData.maDesc.Strikeout = maModel.mbStrikeout ? cssawt::FontStrikeout::SINGLE : cssawt::FontStrikeout::NONE;
904 210 : maApiData.mbOutline = maModel.mbOutline;
905 210 : maApiData.mbShadow = maModel.mbShadow;
906 :
907 : // underline
908 210 : switch( maModel.mnUnderline )
909 : {
910 0 : case XML_double: maApiData.maDesc.Underline = cssawt::FontUnderline::DOUBLE; break;
911 0 : case XML_doubleAccounting: maApiData.maDesc.Underline = cssawt::FontUnderline::DOUBLE; break;
912 204 : case XML_none: maApiData.maDesc.Underline = cssawt::FontUnderline::NONE; break;
913 6 : case XML_single: maApiData.maDesc.Underline = cssawt::FontUnderline::SINGLE; break;
914 0 : case XML_singleAccounting: maApiData.maDesc.Underline = cssawt::FontUnderline::SINGLE; break;
915 : }
916 :
917 : // escapement
918 210 : switch( maModel.mnEscapement )
919 : {
920 : case XML_baseline:
921 210 : maApiData.mnEscapement = API_ESCAPE_NONE;
922 210 : maApiData.mnEscapeHeight = API_ESCAPEHEIGHT_NONE;
923 210 : break;
924 : case XML_superscript:
925 0 : maApiData.mnEscapement = API_ESCAPE_SUPERSCRIPT;
926 0 : maApiData.mnEscapeHeight = API_ESCAPEHEIGHT_DEFAULT;
927 0 : break;
928 : case XML_subscript:
929 0 : maApiData.mnEscapement = API_ESCAPE_SUBSCRIPT;
930 0 : maApiData.mnEscapeHeight = API_ESCAPEHEIGHT_DEFAULT;
931 0 : break;
932 : }
933 :
934 : // supported script types
935 210 : if( maUsedFlags.mbNameUsed )
936 : {
937 210 : PropertySet aDocProps( getDocument() );
938 210 : Reference< XDevice > xDevice( aDocProps.getAnyProperty( PROP_ReferenceDevice ), UNO_QUERY );
939 210 : if( xDevice.is() )
940 : {
941 210 : Reference< XFont2 > xFont( xDevice->getFont( maApiData.maDesc ), UNO_QUERY );
942 210 : if( xFont.is() )
943 : {
944 : // #91658# CJK fonts
945 : bool bHasAsian =
946 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x3041 ) ) ) || // 3040-309F: Hiragana
947 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x30A1 ) ) ) || // 30A0-30FF: Katakana
948 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x3111 ) ) ) || // 3100-312F: Bopomofo
949 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x3131 ) ) ) || // 3130-318F: Hangul Compatibility Jamo
950 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x3301 ) ) ) || // 3300-33FF: CJK Compatibility
951 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x3401 ) ) ) || // 3400-4DBF: CJK Unified Ideographs Extension A
952 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x4E01 ) ) ) || // 4E00-9FAF: CJK Unified Ideographs
953 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x7E01 ) ) ) || // 4E00-9FAF: CJK unified ideographs
954 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0xA001 ) ) ) || // A001-A48F: Yi Syllables
955 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0xAC01 ) ) ) || // AC00-D7AF: Hangul Syllables
956 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0xCC01 ) ) ) || // AC00-D7AF: Hangul Syllables
957 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0xF901 ) ) ) || // F900-FAFF: CJK Compatibility Ideographs
958 5250 : xFont->hasGlyphs( OUString( sal_Unicode( 0xFF71 ) ) ); // FF00-FFEF: Halfwidth/Fullwidth Forms
959 : // #113783# CTL fonts
960 : bool bHasCmplx =
961 630 : xFont->hasGlyphs( OUString( sal_Unicode( 0x05D1 ) ) ) || // 0590-05FF: Hebrew
962 578 : xFont->hasGlyphs( OUString( sal_Unicode( 0x0631 ) ) ) || // 0600-06FF: Arabic
963 578 : xFont->hasGlyphs( OUString( sal_Unicode( 0x0721 ) ) ) || // 0700-074F: Syriac
964 578 : xFont->hasGlyphs( OUString( sal_Unicode( 0x0911 ) ) ) || // 0900-0DFF: Indic scripts
965 578 : xFont->hasGlyphs( OUString( sal_Unicode( 0x0E01 ) ) ) || // 0E00-0E7F: Thai
966 578 : xFont->hasGlyphs( OUString( sal_Unicode( 0xFB21 ) ) ) || // FB1D-FB4F: Hebrew Presentation Forms
967 578 : xFont->hasGlyphs( OUString( sal_Unicode( 0xFB51 ) ) ) || // FB50-FDFF: Arabic Presentation Forms-A
968 2838 : xFont->hasGlyphs( OUString( sal_Unicode( 0xFE71 ) ) ); // FE70-FEFF: Arabic Presentation Forms-B
969 : // Western fonts
970 : bool bHasLatin =
971 420 : (!bHasAsian && !bHasCmplx) ||
972 630 : xFont->hasGlyphs( OUString( sal_Unicode( 'A' ) ) );
973 :
974 210 : lclSetFontName( maApiData.maLatinFont, maApiData.maDesc, bHasLatin );
975 210 : lclSetFontName( maApiData.maAsianFont, maApiData.maDesc, bHasAsian );
976 210 : lclSetFontName( maApiData.maCmplxFont, maApiData.maDesc, bHasCmplx );
977 210 : }
978 210 : }
979 : }
980 210 : }
981 :
982 22 : const FontDescriptor& Font::getFontDescriptor() const
983 : {
984 22 : return maApiData.maDesc;
985 : }
986 :
987 122 : bool Font::needsRichTextFormat() const
988 : {
989 122 : return maApiData.mnEscapement != API_ESCAPE_NONE;
990 : }
991 358 : ::FontFamily lcl_getFontFamily( sal_Int32 nFamily )
992 : {
993 : namespace cssawt = ::com::sun::star::awt;
994 :
995 358 : ::FontFamily eScFamily = FAMILY_DONTKNOW;
996 358 : switch( nFamily )
997 : {
998 : case cssawt::FontFamily::DONTKNOW:
999 126 : eScFamily = FAMILY_DONTKNOW;
1000 126 : break;
1001 : case cssawt::FontFamily::ROMAN:
1002 0 : eScFamily = FAMILY_ROMAN;
1003 0 : break;
1004 : case cssawt::FontFamily::SWISS:
1005 232 : eScFamily = FAMILY_SWISS;
1006 232 : break;
1007 : case cssawt::FontFamily::MODERN:
1008 0 : eScFamily = FAMILY_MODERN;
1009 0 : break;
1010 : case cssawt::FontFamily::SCRIPT:
1011 0 : eScFamily = FAMILY_SCRIPT;
1012 0 : break;
1013 : case cssawt::FontFamily::DECORATIVE:
1014 0 : eScFamily = FAMILY_DECORATIVE;
1015 0 : break;
1016 : }
1017 358 : return eScFamily;
1018 : }
1019 :
1020 330 : void Font::fillToItemSet( SfxItemSet& rItemSet, FontPropertyType ePropType, bool bSkipPoolDefs ) const
1021 : {
1022 : namespace cssawt = ::com::sun::star::awt;
1023 330 : if ( maUsedFlags.mbNameUsed )
1024 : {
1025 330 : if( !maApiData.maLatinFont.maName.isEmpty() )
1026 : {
1027 330 : rtl_TextEncoding eFontEnc = maApiData.maLatinFont.mnTextEnc;
1028 : SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maLatinFont.mnFamily ), maApiData.maLatinFont.maName, rtl::OUString(),
1029 330 : PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
1030 : }
1031 330 : if( !maApiData.maAsianFont.maName.isEmpty() )
1032 : {
1033 0 : rtl_TextEncoding eFontEnc = maApiData.maAsianFont.mnTextEnc;
1034 : SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maAsianFont.mnFamily ), maApiData.maAsianFont.maName, rtl::OUString(),
1035 0 : PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
1036 : }
1037 330 : if( !maApiData.maCmplxFont.maName.isEmpty() )
1038 : {
1039 28 : rtl_TextEncoding eFontEnc = maApiData.maCmplxFont.mnTextEnc;
1040 : SvxFontItem aFontItem( lcl_getFontFamily( maApiData.maCmplxFont.mnFamily ), maApiData.maCmplxFont.maName, rtl::OUString(),
1041 28 : PITCH_DONTKNOW, eFontEnc, ATTR_FONT );
1042 : }
1043 : }
1044 : // font height
1045 330 : if( maUsedFlags.mbHeightUsed )
1046 : {
1047 : // leave in twips ?
1048 330 : SvxFontHeightItem aHeightItem( maApiData.maDesc.Height, 100, ATTR_FONT_HEIGHT );
1049 330 : ScfTools::PutItem( rItemSet, aHeightItem, ATTR_FONT_HEIGHT, bSkipPoolDefs );
1050 330 : ScfTools::PutItem( rItemSet, aHeightItem, ATTR_CJK_FONT_HEIGHT, bSkipPoolDefs );
1051 330 : ScfTools::PutItem( rItemSet, aHeightItem, ATTR_CTL_FONT_HEIGHT, bSkipPoolDefs );
1052 : }
1053 : // font weight
1054 330 : if( maUsedFlags.mbWeightUsed )
1055 : {
1056 330 : ::FontWeight fWeight = VCLUnoHelper::ConvertFontWeight( maApiData.maDesc.Weight );
1057 330 : SvxWeightItem aWeightItem( fWeight, ATTR_FONT_WEIGHT );
1058 330 : ScfTools::PutItem( rItemSet, aWeightItem, ATTR_FONT_WEIGHT, bSkipPoolDefs );
1059 330 : ScfTools::PutItem( rItemSet, aWeightItem, ATTR_CTL_FONT_WEIGHT, bSkipPoolDefs );
1060 330 : ScfTools::PutItem( rItemSet, aWeightItem, ATTR_CJK_FONT_WEIGHT, bSkipPoolDefs );
1061 : }
1062 : // font posture
1063 330 : if( maUsedFlags.mbPostureUsed )
1064 : {
1065 330 : SvxPostureItem aPostItem( ( maApiData.maDesc.Slant == cssawt::FontSlant_ITALIC ) ? ITALIC_NORMAL : ITALIC_NONE, ATTR_FONT_POSTURE);
1066 330 : ScfTools::PutItem( rItemSet, aPostItem, ATTR_FONT_POSTURE, bSkipPoolDefs );
1067 330 : ScfTools::PutItem( rItemSet, aPostItem, ATTR_CJK_FONT_POSTURE, bSkipPoolDefs );
1068 330 : ScfTools::PutItem( rItemSet, aPostItem, ATTR_CTL_FONT_POSTURE, bSkipPoolDefs );
1069 : }
1070 : // character color
1071 330 : if( maUsedFlags.mbColorUsed )
1072 : {
1073 330 : ScfTools::PutItem( rItemSet,SvxColorItem( maApiData.mnColor, ATTR_FONT_COLOR ) , bSkipPoolDefs );
1074 : }
1075 : // underline style
1076 330 : if( maUsedFlags.mbUnderlineUsed )
1077 : {
1078 : ::FontUnderline eScUnderl;
1079 330 : if ( maApiData.maDesc.Underline == cssawt::FontUnderline::DOUBLE )
1080 0 : eScUnderl = UNDERLINE_DOUBLE;
1081 330 : else if ( maApiData.maDesc.Underline == cssawt::FontUnderline::SINGLE )
1082 6 : eScUnderl = UNDERLINE_SINGLE;
1083 : else
1084 324 : eScUnderl = UNDERLINE_NONE;
1085 330 : SvxUnderlineItem aUnderlItem( eScUnderl, ATTR_FONT_UNDERLINE );
1086 330 : ScfTools::PutItem( rItemSet, aUnderlItem, ATTR_FONT_UNDERLINE, bSkipPoolDefs );
1087 : }
1088 : // strike out style
1089 330 : if( maUsedFlags.mbStrikeoutUsed )
1090 : {
1091 330 : ScfTools::PutItem( rItemSet, SvxCrossedOutItem( maModel.mbStrikeout ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT ), ATTR_FONT_CROSSEDOUT, bSkipPoolDefs );
1092 : }
1093 :
1094 : // outline style
1095 330 : if( maUsedFlags.mbOutlineUsed )
1096 : {
1097 330 : ScfTools::PutItem( rItemSet, SvxContourItem( maApiData.mbOutline, ATTR_FONT_CONTOUR ), ATTR_FONT_CONTOUR, bSkipPoolDefs );
1098 : }
1099 :
1100 : // shadow style
1101 330 : if( maUsedFlags.mbShadowUsed )
1102 : {
1103 330 : ScfTools::PutItem( rItemSet, SvxShadowedItem( maApiData.mbShadow, ATTR_FONT_SHADOWED ), ATTR_FONT_SHADOWED, bSkipPoolDefs );
1104 : }
1105 330 : if( maUsedFlags.mbEscapementUsed )
1106 : {
1107 330 : SvxEscapement eScEscapem = SVX_ESCAPEMENT_OFF;
1108 330 : if ( maApiData.mnEscapement == API_ESCAPE_SUPERSCRIPT )
1109 0 : eScEscapem = SVX_ESCAPEMENT_SUPERSCRIPT;
1110 330 : else if ( maApiData.mnEscapement == API_ESCAPE_SUBSCRIPT )
1111 0 : eScEscapem = SVX_ESCAPEMENT_SUBSCRIPT;
1112 330 : rItemSet.Put( SvxEscapementItem( eScEscapem, EE_CHAR_ESCAPEMENT ) );
1113 : if( ePropType == FONT_PROPTYPE_TEXT )
1114 : {
1115 : // #TODO handle EscapementHeight
1116 : }
1117 : }
1118 330 : }
1119 :
1120 142 : void Font::writeToPropertyMap( PropertyMap& rPropMap, FontPropertyType ePropType ) const
1121 : {
1122 : // font name properties
1123 142 : if( maUsedFlags.mbNameUsed )
1124 : {
1125 142 : if( !maApiData.maLatinFont.maName.isEmpty() )
1126 : {
1127 142 : rPropMap[ PROP_CharFontName ] <<= maApiData.maLatinFont.maName;
1128 142 : rPropMap[ PROP_CharFontFamily ] <<= maApiData.maLatinFont.mnFamily;
1129 142 : rPropMap[ PROP_CharFontCharSet ] <<= maApiData.maLatinFont.mnTextEnc;
1130 : }
1131 142 : if( !maApiData.maAsianFont.maName.isEmpty() )
1132 : {
1133 0 : rPropMap[ PROP_CharFontNameAsian ] <<= maApiData.maAsianFont.maName;
1134 0 : rPropMap[ PROP_CharFontFamilyAsian ] <<= maApiData.maAsianFont.mnFamily;
1135 0 : rPropMap[ PROP_CharFontCharSetAsian ] <<= maApiData.maAsianFont.mnTextEnc;
1136 : }
1137 142 : if( !maApiData.maCmplxFont.maName.isEmpty() )
1138 : {
1139 24 : rPropMap[ PROP_CharFontNameComplex ] <<= maApiData.maCmplxFont.maName;
1140 24 : rPropMap[ PROP_CharFontFamilyComplex ] <<= maApiData.maCmplxFont.mnFamily;
1141 24 : rPropMap[ PROP_CharFontCharSetComplex ] <<= maApiData.maCmplxFont.mnTextEnc;
1142 : }
1143 : }
1144 : // font height
1145 142 : if( maUsedFlags.mbHeightUsed )
1146 : {
1147 142 : float fHeight = static_cast< float >( maApiData.maDesc.Height / 20.0 ); // twips to points
1148 142 : rPropMap[ PROP_CharHeight ] <<= fHeight;
1149 142 : rPropMap[ PROP_CharHeightAsian ] <<= fHeight;
1150 142 : rPropMap[ PROP_CharHeightComplex ] <<= fHeight;
1151 : }
1152 : // font weight
1153 142 : if( maUsedFlags.mbWeightUsed )
1154 : {
1155 102 : float fWeight = maApiData.maDesc.Weight;
1156 102 : rPropMap[ PROP_CharWeight ] <<= fWeight;
1157 102 : rPropMap[ PROP_CharWeightAsian ] <<= fWeight;
1158 102 : rPropMap[ PROP_CharWeightComplex ] <<= fWeight;
1159 : }
1160 : // font posture
1161 142 : if( maUsedFlags.mbPostureUsed )
1162 : {
1163 102 : rPropMap[ PROP_CharPosture ] <<= maApiData.maDesc.Slant;
1164 102 : rPropMap[ PROP_CharPostureAsian ] <<= maApiData.maDesc.Slant;
1165 102 : rPropMap[ PROP_CharPostureComplex ] <<= maApiData.maDesc.Slant;
1166 : }
1167 : // character color
1168 142 : if( maUsedFlags.mbColorUsed )
1169 118 : rPropMap[ PROP_CharColor ] <<= maApiData.mnColor;
1170 : // underline style
1171 142 : if( maUsedFlags.mbUnderlineUsed )
1172 102 : rPropMap[ PROP_CharUnderline ] <<= maApiData.maDesc.Underline;
1173 : // strike out style
1174 142 : if( maUsedFlags.mbStrikeoutUsed )
1175 102 : rPropMap[ PROP_CharStrikeout ] <<= maApiData.maDesc.Strikeout;
1176 : // outline style
1177 142 : if( maUsedFlags.mbOutlineUsed )
1178 102 : rPropMap[ PROP_CharContoured ] <<= maApiData.mbOutline;
1179 : // shadow style
1180 142 : if( maUsedFlags.mbShadowUsed )
1181 102 : rPropMap[ PROP_CharShadowed ] <<= maApiData.mbShadow;
1182 : // escapement
1183 142 : if( maUsedFlags.mbEscapementUsed )
1184 : {
1185 102 : rPropMap[ PROP_CharEscapement ] <<= maApiData.mnEscapement;
1186 102 : if( ePropType == FONT_PROPTYPE_TEXT )
1187 80 : rPropMap[ PROP_CharEscapementHeight ] <<= maApiData.mnEscapeHeight;
1188 : }
1189 142 : }
1190 :
1191 80 : void Font::writeToPropertySet( PropertySet& rPropSet, FontPropertyType ePropType ) const
1192 : {
1193 80 : PropertyMap aPropMap;
1194 80 : writeToPropertyMap( aPropMap, ePropType );
1195 80 : rPropSet.setProperties( aPropMap );
1196 80 : }
1197 :
1198 : // ============================================================================
1199 :
1200 374 : AlignmentModel::AlignmentModel() :
1201 : mnHorAlign( XML_general ),
1202 : mnVerAlign( XML_bottom ),
1203 : mnTextDir( OOX_XF_TEXTDIR_CONTEXT ),
1204 : mnRotation( OOX_XF_ROTATION_NONE ),
1205 : mnIndent( OOX_XF_INDENT_NONE ),
1206 : mbWrapText( false ),
1207 : mbShrink( false ),
1208 374 : mbJustLastLine( false )
1209 : {
1210 374 : }
1211 :
1212 0 : void AlignmentModel::setBiffHorAlign( sal_uInt8 nHorAlign )
1213 : {
1214 : static const sal_Int32 spnHorAligns[] = {
1215 : XML_general, XML_left, XML_center, XML_right,
1216 : XML_fill, XML_justify, XML_centerContinuous, XML_distributed };
1217 0 : mnHorAlign = STATIC_ARRAY_SELECT( spnHorAligns, nHorAlign, XML_general );
1218 0 : }
1219 :
1220 0 : void AlignmentModel::setBiffVerAlign( sal_uInt8 nVerAlign )
1221 : {
1222 : static const sal_Int32 spnVerAligns[] = {
1223 : XML_top, XML_center, XML_bottom, XML_justify, XML_distributed };
1224 0 : mnVerAlign = STATIC_ARRAY_SELECT( spnVerAligns, nVerAlign, XML_bottom );
1225 0 : }
1226 :
1227 : // ----------------------------------------------------------------------------
1228 :
1229 374 : ApiAlignmentData::ApiAlignmentData() :
1230 : meHorJustify( ::com::sun::star::table::CellHoriJustify_STANDARD ),
1231 : mnHorJustifyMethod( ::com::sun::star::table::CellJustifyMethod::AUTO ),
1232 : mnVerJustify( ::com::sun::star::table::CellVertJustify2::STANDARD ),
1233 : mnVerJustifyMethod( ::com::sun::star::table::CellJustifyMethod::AUTO ),
1234 : meOrientation( ::com::sun::star::table::CellOrientation_STANDARD ),
1235 : mnRotation( 0 ),
1236 : mnWritingMode( ::com::sun::star::text::WritingMode2::PAGE ),
1237 : mnIndent( 0 ),
1238 : mbWrapText( false ),
1239 374 : mbShrink( false )
1240 : {
1241 374 : }
1242 :
1243 80 : bool operator==( const ApiAlignmentData& rLeft, const ApiAlignmentData& rRight )
1244 : {
1245 : return
1246 : (rLeft.meHorJustify == rRight.meHorJustify) &&
1247 : (rLeft.mnHorJustifyMethod == rRight.mnHorJustifyMethod) &&
1248 : (rLeft.mnVerJustify == rRight.mnVerJustify) &&
1249 : (rLeft.mnVerJustifyMethod == rRight.mnVerJustifyMethod) &&
1250 : (rLeft.meOrientation == rRight.meOrientation) &&
1251 : (rLeft.mnRotation == rRight.mnRotation) &&
1252 : (rLeft.mnWritingMode == rRight.mnWritingMode) &&
1253 : (rLeft.mnIndent == rRight.mnIndent) &&
1254 : (rLeft.mbWrapText == rRight.mbWrapText) &&
1255 80 : (rLeft.mbShrink == rRight.mbShrink);
1256 : }
1257 :
1258 : // ============================================================================
1259 :
1260 374 : Alignment::Alignment( const WorkbookHelper& rHelper ) :
1261 374 : WorkbookHelper( rHelper )
1262 : {
1263 374 : }
1264 :
1265 70 : void Alignment::importAlignment( const AttributeList& rAttribs )
1266 : {
1267 70 : maModel.mnHorAlign = rAttribs.getToken( XML_horizontal, XML_general );
1268 70 : maModel.mnVerAlign = rAttribs.getToken( XML_vertical, XML_bottom );
1269 70 : maModel.mnTextDir = rAttribs.getInteger( XML_readingOrder, OOX_XF_TEXTDIR_CONTEXT );
1270 70 : maModel.mnRotation = rAttribs.getInteger( XML_textRotation, OOX_XF_ROTATION_NONE );
1271 70 : maModel.mnIndent = rAttribs.getInteger( XML_indent, OOX_XF_INDENT_NONE );
1272 70 : maModel.mbWrapText = rAttribs.getBool( XML_wrapText, false );
1273 70 : maModel.mbShrink = rAttribs.getBool( XML_shrinkToFit, false );
1274 70 : maModel.mbJustLastLine = rAttribs.getBool( XML_justifyLastLine, false );
1275 70 : }
1276 :
1277 0 : void Alignment::setBiff12Data( sal_uInt32 nFlags )
1278 : {
1279 0 : maModel.setBiffHorAlign( extractValue< sal_uInt8 >( nFlags, 16, 3 ) );
1280 0 : maModel.setBiffVerAlign( extractValue< sal_uInt8 >( nFlags, 19, 3 ) );
1281 0 : maModel.mnTextDir = extractValue< sal_Int32 >( nFlags, 26, 2 );
1282 0 : maModel.mnRotation = extractValue< sal_Int32 >( nFlags, 0, 8 );
1283 0 : maModel.mnIndent = extractValue< sal_uInt8 >( nFlags, 8, 8 );
1284 0 : maModel.mbWrapText = getFlag( nFlags, BIFF12_XF_WRAPTEXT );
1285 0 : maModel.mbShrink = getFlag( nFlags, BIFF12_XF_SHRINK );
1286 0 : maModel.mbJustLastLine = getFlag( nFlags, BIFF12_XF_JUSTLASTLINE );
1287 0 : }
1288 :
1289 374 : void Alignment::finalizeImport()
1290 : {
1291 : namespace csstab = ::com::sun::star::table;
1292 : namespace csstxt = ::com::sun::star::text;
1293 :
1294 : // horizontal alignment
1295 374 : switch( maModel.mnHorAlign )
1296 : {
1297 10 : case XML_center: maApiData.meHorJustify = csstab::CellHoriJustify_CENTER; break;
1298 0 : case XML_centerContinuous: maApiData.meHorJustify = csstab::CellHoriJustify_CENTER; break;
1299 0 : case XML_distributed: maApiData.meHorJustify = csstab::CellHoriJustify_BLOCK; break;
1300 0 : case XML_fill: maApiData.meHorJustify = csstab::CellHoriJustify_REPEAT; break;
1301 360 : case XML_general: maApiData.meHorJustify = csstab::CellHoriJustify_STANDARD; break;
1302 2 : case XML_justify: maApiData.meHorJustify = csstab::CellHoriJustify_BLOCK; break;
1303 0 : case XML_left: maApiData.meHorJustify = csstab::CellHoriJustify_LEFT; break;
1304 2 : case XML_right: maApiData.meHorJustify = csstab::CellHoriJustify_RIGHT; break;
1305 : }
1306 :
1307 374 : if (maModel.mnHorAlign == XML_distributed)
1308 0 : maApiData.mnHorJustifyMethod = csstab::CellJustifyMethod::DISTRIBUTE;
1309 :
1310 : // vertical alignment
1311 374 : switch( maModel.mnVerAlign )
1312 : {
1313 370 : case XML_bottom: maApiData.mnVerJustify = csstab::CellVertJustify2::BOTTOM; break;
1314 4 : case XML_center: maApiData.mnVerJustify = csstab::CellVertJustify2::CENTER; break;
1315 0 : case XML_distributed: maApiData.mnVerJustify = csstab::CellVertJustify2::BLOCK; break;
1316 0 : case XML_justify: maApiData.mnVerJustify = csstab::CellVertJustify2::BLOCK; break;
1317 0 : case XML_top: maApiData.mnVerJustify = csstab::CellVertJustify2::TOP; break;
1318 : }
1319 :
1320 374 : if (maModel.mnVerAlign == XML_distributed)
1321 0 : maApiData.mnVerJustifyMethod = csstab::CellJustifyMethod::DISTRIBUTE;
1322 :
1323 : /* indentation: expressed as number of blocks of 3 space characters in
1324 : OOXML/BIFF12, and as multiple of 10 points in BIFF8. */
1325 374 : sal_Int32 nIndent = 0;
1326 374 : switch( getFilterType() )
1327 : {
1328 374 : case FILTER_OOXML: nIndent = getUnitConverter().scaleToMm100( 3.0 * maModel.mnIndent, UNIT_SPACE ); break;
1329 0 : case FILTER_BIFF: nIndent = getUnitConverter().scaleToMm100( 10.0 * maModel.mnIndent, UNIT_POINT ); break;
1330 0 : case FILTER_UNKNOWN: break;
1331 : }
1332 374 : if( (0 <= nIndent) && (nIndent <= SAL_MAX_INT16) )
1333 374 : maApiData.mnIndent = static_cast< sal_Int16 >( nIndent );
1334 :
1335 : // complex text direction
1336 374 : switch( maModel.mnTextDir )
1337 : {
1338 374 : case OOX_XF_TEXTDIR_CONTEXT: maApiData.mnWritingMode = csstxt::WritingMode2::PAGE; break;
1339 0 : case OOX_XF_TEXTDIR_LTR: maApiData.mnWritingMode = csstxt::WritingMode2::LR_TB; break;
1340 0 : case OOX_XF_TEXTDIR_RTL: maApiData.mnWritingMode = csstxt::WritingMode2::RL_TB; break;
1341 : }
1342 :
1343 : // rotation: 0-90 means 0 to 90 degrees ccw, 91-180 means 1 to 90 degrees cw, 255 means stacked
1344 374 : sal_Int32 nOoxRot = maModel.mnRotation;
1345 : maApiData.mnRotation = ((0 <= nOoxRot) && (nOoxRot <= 90)) ?
1346 : (100 * nOoxRot) :
1347 374 : (((91 <= nOoxRot) && (nOoxRot <= 180)) ? (100 * (450 - nOoxRot)) : 0);
1348 :
1349 : // "Orientation" property used for character stacking
1350 : maApiData.meOrientation = (nOoxRot == OOX_XF_ROTATION_STACKED) ?
1351 374 : csstab::CellOrientation_STACKED : csstab::CellOrientation_STANDARD;
1352 :
1353 : // alignment flags (#i84960 automatic line break, if vertically justified/distributed)
1354 374 : maApiData.mbWrapText = maModel.mbWrapText || (maModel.mnVerAlign == XML_distributed) || (maModel.mnVerAlign == XML_justify);
1355 374 : maApiData.mbShrink = maModel.mbShrink;
1356 :
1357 374 : }
1358 :
1359 40 : ::SvxCellVerJustify Alignment::GetScVerAlign() const
1360 : {
1361 : namespace csstab = ::com::sun::star::table;
1362 40 : ::SvxCellVerJustify nVert = ::SVX_VER_JUSTIFY_STANDARD;
1363 40 : switch ( maApiData.mnVerJustify )
1364 : {
1365 : case csstab::CellVertJustify2::BOTTOM:
1366 38 : nVert = ::SVX_VER_JUSTIFY_BOTTOM;
1367 38 : break;
1368 : case csstab::CellVertJustify2::CENTER:
1369 2 : nVert = ::SVX_VER_JUSTIFY_CENTER;
1370 2 : break;
1371 : case csstab::CellVertJustify2::TOP:
1372 0 : nVert = ::SVX_VER_JUSTIFY_TOP;
1373 0 : break;
1374 : case csstab::CellVertJustify2::BLOCK:
1375 0 : nVert = ::SVX_VER_JUSTIFY_BLOCK;
1376 0 : break;
1377 : case csstab::CellVertJustify2::STANDARD:
1378 : default:
1379 0 : nVert = ::SVX_VER_JUSTIFY_STANDARD;
1380 0 : break;
1381 : }
1382 40 : return nVert;
1383 : }
1384 :
1385 40 : ::SvxCellHorJustify Alignment::GetScHorAlign() const
1386 : {
1387 : namespace csstab = ::com::sun::star::table;
1388 40 : ::SvxCellHorJustify nHori = ::SVX_HOR_JUSTIFY_STANDARD;
1389 40 : switch( maApiData.meHorJustify )
1390 : {
1391 : case csstab::CellHoriJustify_LEFT:
1392 0 : nHori = ::SVX_HOR_JUSTIFY_LEFT;
1393 0 : break;
1394 : case csstab::CellHoriJustify_CENTER:
1395 8 : nHori = ::SVX_HOR_JUSTIFY_CENTER;
1396 8 : break;
1397 : case csstab::CellHoriJustify_RIGHT:
1398 2 : nHori = ::SVX_HOR_JUSTIFY_RIGHT;
1399 2 : break;
1400 : case csstab::CellHoriJustify_BLOCK:
1401 2 : nHori = ::SVX_HOR_JUSTIFY_BLOCK;
1402 2 : break;
1403 : case csstab::CellHoriJustify_REPEAT:
1404 0 : nHori = ::SVX_HOR_JUSTIFY_REPEAT;
1405 0 : break;
1406 : case csstab::CellHoriJustify_STANDARD:
1407 : default:
1408 28 : nHori = ::SVX_HOR_JUSTIFY_STANDARD;
1409 28 : break;
1410 : }
1411 40 : return nHori;
1412 : }
1413 :
1414 40 : ::SvxFrameDirection Alignment::GetScFrameDir() const
1415 : {
1416 : namespace csstxt = ::com::sun::star::text;
1417 40 : ::SvxFrameDirection eFrameDir = ::FRMDIR_ENVIRONMENT;
1418 40 : switch( maApiData.mnWritingMode )
1419 : {
1420 : case csstxt::WritingMode2::PAGE:
1421 40 : eFrameDir = ::FRMDIR_ENVIRONMENT;
1422 40 : break;
1423 : case csstxt::WritingMode2::LR_TB:
1424 0 : eFrameDir = ::FRMDIR_HORI_LEFT_TOP;
1425 0 : break;
1426 : case csstxt::WritingMode2::RL_TB:
1427 0 : eFrameDir = ::FRMDIR_HORI_RIGHT_TOP;
1428 0 : break;
1429 : default:
1430 : OSL_FAIL( "GetScFrameDir - unknown CTL text direction" );
1431 : }
1432 40 : return eFrameDir;
1433 : }
1434 :
1435 40 : void Alignment::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
1436 : {
1437 : namespace csstab = ::com::sun::star::table;
1438 : // horizontal alignment
1439 40 : ScfTools::PutItem( rItemSet, SvxHorJustifyItem( GetScHorAlign(), ATTR_HOR_JUSTIFY ), bSkipPoolDefs );
1440 40 : ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( ( maApiData.mnHorJustifyMethod == csstab::CellJustifyMethod::DISTRIBUTE ) ? ::SVX_JUSTIFY_METHOD_DISTRIBUTE : ::SVX_JUSTIFY_METHOD_AUTO, ATTR_HOR_JUSTIFY_METHOD ), bSkipPoolDefs );
1441 40 : ScfTools::PutItem( rItemSet, SvxVerJustifyItem( GetScVerAlign(), ATTR_VER_JUSTIFY ), bSkipPoolDefs );
1442 : // vertical alignment
1443 40 : ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( ( maApiData.mnVerJustifyMethod == csstab::CellJustifyMethod::DISTRIBUTE ) ? ::SVX_JUSTIFY_METHOD_DISTRIBUTE : ::SVX_JUSTIFY_METHOD_AUTO, ATTR_VER_JUSTIFY_METHOD ), bSkipPoolDefs );
1444 :
1445 : // CTL text direction
1446 40 : ScfTools::PutItem( rItemSet, SvxFrameDirectionItem( GetScFrameDir(), ATTR_WRITINGDIR ), bSkipPoolDefs );
1447 : // set an angle in the range from -90 to 90 degrees
1448 40 : ScfTools::PutItem( rItemSet, SfxInt32Item( ATTR_ROTATE_VALUE, maApiData.mnRotation ), bSkipPoolDefs );
1449 : // Orientation
1450 40 : ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_STACKED, maApiData.meOrientation == csstab::CellOrientation_STACKED ), bSkipPoolDefs );
1451 : // indent
1452 40 : ScfTools::PutItem( rItemSet, SfxUInt16Item( ATTR_INDENT, maApiData.mnIndent ), bSkipPoolDefs );
1453 : // line wrap
1454 40 : ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_LINEBREAK, maApiData.mbWrapText ), bSkipPoolDefs );
1455 40 : ScfTools::PutItem( rItemSet, SfxBoolItem( ATTR_SHRINKTOFIT, maApiData.mbShrink ), bSkipPoolDefs );
1456 40 : }
1457 :
1458 22 : void Alignment::writeToPropertyMap( PropertyMap& rPropMap ) const
1459 : {
1460 22 : rPropMap[ PROP_HoriJustify ] <<= maApiData.meHorJustify;
1461 22 : rPropMap[ PROP_HoriJustifyMethod ] <<= maApiData.mnHorJustifyMethod;
1462 22 : rPropMap[ PROP_VertJustify ] <<= maApiData.mnVerJustify;
1463 22 : rPropMap[ PROP_VertJustifyMethod ] <<= maApiData.mnVerJustifyMethod;
1464 22 : rPropMap[ PROP_WritingMode ] <<= maApiData.mnWritingMode;
1465 22 : rPropMap[ PROP_RotateAngle ] <<= maApiData.mnRotation;
1466 22 : rPropMap[ PROP_Orientation ] <<= maApiData.meOrientation;
1467 22 : rPropMap[ PROP_ParaIndent ] <<= maApiData.mnIndent;
1468 22 : rPropMap[ PROP_IsTextWrapped ] <<= maApiData.mbWrapText;
1469 22 : rPropMap[ PROP_ShrinkToFit ] <<= maApiData.mbShrink;
1470 22 : }
1471 :
1472 : // ============================================================================
1473 :
1474 374 : ProtectionModel::ProtectionModel() :
1475 : mbLocked( true ), // default in Excel and Calc
1476 374 : mbHidden( false )
1477 : {
1478 374 : }
1479 :
1480 : // ----------------------------------------------------------------------------
1481 :
1482 374 : ApiProtectionData::ApiProtectionData() :
1483 374 : maCellProt( sal_True, sal_False, sal_False, sal_False )
1484 : {
1485 374 : }
1486 :
1487 76 : bool operator==( const ApiProtectionData& rLeft, const ApiProtectionData& rRight )
1488 : {
1489 : return
1490 : (rLeft.maCellProt.IsLocked == rRight.maCellProt.IsLocked) &&
1491 : (rLeft.maCellProt.IsFormulaHidden == rRight.maCellProt.IsFormulaHidden) &&
1492 : (rLeft.maCellProt.IsHidden == rRight.maCellProt.IsHidden) &&
1493 76 : (rLeft.maCellProt.IsPrintHidden == rRight.maCellProt.IsPrintHidden);
1494 : }
1495 :
1496 : // ============================================================================
1497 :
1498 374 : Protection::Protection( const WorkbookHelper& rHelper ) :
1499 374 : WorkbookHelper( rHelper )
1500 : {
1501 374 : }
1502 :
1503 66 : void Protection::importProtection( const AttributeList& rAttribs )
1504 : {
1505 66 : maModel.mbLocked = rAttribs.getBool( XML_locked, true );
1506 66 : maModel.mbHidden = rAttribs.getBool( XML_hidden, false );
1507 66 : }
1508 :
1509 0 : void Protection::setBiff12Data( sal_uInt32 nFlags )
1510 : {
1511 0 : maModel.mbLocked = getFlag( nFlags, BIFF12_XF_LOCKED );
1512 0 : maModel.mbHidden = getFlag( nFlags, BIFF12_XF_HIDDEN );
1513 0 : }
1514 :
1515 374 : void Protection::finalizeImport()
1516 : {
1517 374 : maApiData.maCellProt.IsLocked = maModel.mbLocked;
1518 374 : maApiData.maCellProt.IsFormulaHidden = maModel.mbHidden;
1519 374 : }
1520 :
1521 22 : void Protection::writeToPropertyMap( PropertyMap& rPropMap ) const
1522 : {
1523 22 : rPropMap[ PROP_CellProtection ] <<= maApiData.maCellProt;
1524 22 : }
1525 :
1526 32 : void Protection::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
1527 : {
1528 32 : ScfTools::PutItem( rItemSet, ScProtectionAttr( maApiData.maCellProt.IsLocked, maApiData.maCellProt.IsFormulaHidden ), bSkipPoolDefs );
1529 32 : }
1530 :
1531 : // ============================================================================
1532 :
1533 : namespace {
1534 :
1535 96 : bool lcl_isBorder(const ::com::sun::star::table::BorderLine& rBorder)
1536 : {
1537 96 : return (rBorder.InnerLineWidth > 0) || (rBorder.OuterLineWidth > 0);
1538 : }
1539 :
1540 : }
1541 :
1542 110 : BorderLineModel::BorderLineModel( bool bDxf ) :
1543 : mnStyle( XML_none ),
1544 110 : mbUsed( !bDxf )
1545 : {
1546 110 : maColor.setIndexed( OOX_COLOR_WINDOWTEXT );
1547 110 : }
1548 :
1549 0 : void BorderLineModel::setBiffStyle( sal_Int32 nLineStyle )
1550 : {
1551 : static const sal_Int32 spnStyleIds[] = {
1552 : XML_none, XML_thin, XML_medium, XML_dashed,
1553 : XML_dotted, XML_thick, XML_double, XML_hair,
1554 : XML_mediumDashed, XML_dashDot, XML_mediumDashDot, XML_dashDotDot,
1555 : XML_mediumDashDotDot, XML_slantDashDot };
1556 0 : mnStyle = STATIC_ARRAY_SELECT( spnStyleIds, nLineStyle, XML_none );
1557 0 : }
1558 :
1559 : // ----------------------------------------------------------------------------
1560 :
1561 22 : BorderModel::BorderModel( bool bDxf ) :
1562 : maLeft( bDxf ),
1563 : maRight( bDxf ),
1564 : maTop( bDxf ),
1565 : maBottom( bDxf ),
1566 : maDiagonal( bDxf ),
1567 : mbDiagTLtoBR( false ),
1568 22 : mbDiagBLtoTR( false )
1569 : {
1570 22 : }
1571 :
1572 : // ----------------------------------------------------------------------------
1573 :
1574 22 : ApiBorderData::ApiBorderData() :
1575 : mbBorderUsed( false ),
1576 22 : mbDiagUsed( false )
1577 : {
1578 22 : }
1579 :
1580 2 : bool ApiBorderData::hasAnyOuterBorder() const
1581 : {
1582 : return
1583 2 : ( ( lcl_isBorder( maTop ) && maTop.OuterLineWidth > 0 ) ) ||
1584 2 : ( ( lcl_isBorder( maBottom ) && maBottom.OuterLineWidth > 0 ) ) ||
1585 2 : ( ( lcl_isBorder( maLeft ) && maLeft.OuterLineWidth > 0 ) ) ||
1586 6 : ( ( lcl_isBorder( maRight ) && maRight.OuterLineWidth > 0 ) );
1587 : }
1588 :
1589 : namespace {
1590 :
1591 0 : bool operator==( const BorderLine& rLeft, const BorderLine& rRight )
1592 : {
1593 : return
1594 : (rLeft.Color == rRight.Color) &&
1595 : (rLeft.InnerLineWidth == rRight.InnerLineWidth) &&
1596 : (rLeft.OuterLineWidth == rRight.OuterLineWidth) &&
1597 0 : (rLeft.LineDistance == rRight.LineDistance);
1598 : }
1599 :
1600 : } // namespace
1601 :
1602 0 : bool operator==( const ApiBorderData& rLeft, const ApiBorderData& rRight )
1603 : {
1604 : return
1605 0 : (rLeft.maLeft == rRight.maLeft) &&
1606 0 : (rLeft.maRight == rRight.maRight) &&
1607 0 : (rLeft.maTop == rRight.maTop) &&
1608 0 : (rLeft.maBottom == rRight.maBottom) &&
1609 0 : (rLeft.maTLtoBR == rRight.maTLtoBR) &&
1610 0 : (rLeft.maBLtoTR == rRight.maBLtoTR) &&
1611 : (rLeft.mbBorderUsed == rRight.mbBorderUsed) &&
1612 0 : (rLeft.mbDiagUsed == rRight.mbDiagUsed);
1613 : }
1614 :
1615 : // ============================================================================
1616 :
1617 : namespace {
1618 :
1619 88 : inline void lclSetBorderLineWidth( BorderLine& rBorderLine,
1620 : sal_Int16 nOuter, sal_Int16 nDist = API_LINE_NONE, sal_Int16 nInner = API_LINE_NONE )
1621 : {
1622 88 : rBorderLine.OuterLineWidth = nOuter;
1623 88 : rBorderLine.LineDistance = nDist;
1624 88 : rBorderLine.InnerLineWidth = nInner;
1625 88 : }
1626 :
1627 : } // namespace
1628 :
1629 : // ----------------------------------------------------------------------------
1630 :
1631 22 : Border::Border( const WorkbookHelper& rHelper, bool bDxf ) :
1632 : WorkbookHelper( rHelper ),
1633 : maModel( bDxf ),
1634 22 : mbDxf( bDxf )
1635 : {
1636 22 : }
1637 :
1638 22 : void Border::importBorder( const AttributeList& rAttribs )
1639 : {
1640 22 : maModel.mbDiagTLtoBR = rAttribs.getBool( XML_diagonalDown, false );
1641 22 : maModel.mbDiagBLtoTR = rAttribs.getBool( XML_diagonalUp, false );
1642 22 : }
1643 :
1644 110 : void Border::importStyle( sal_Int32 nElement, const AttributeList& rAttribs )
1645 : {
1646 110 : if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
1647 : {
1648 110 : pBorderLine->mnStyle = rAttribs.getToken( XML_style, XML_none );
1649 110 : pBorderLine->mbUsed = true;
1650 : }
1651 110 : }
1652 :
1653 0 : void Border::importColor( sal_Int32 nElement, const AttributeList& rAttribs )
1654 : {
1655 0 : if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
1656 0 : pBorderLine->maColor.importColor( rAttribs );
1657 0 : }
1658 :
1659 0 : void Border::importBorder( SequenceInputStream& rStrm )
1660 : {
1661 0 : sal_uInt8 nFlags = rStrm.readuInt8();
1662 0 : maModel.mbDiagTLtoBR = getFlag( nFlags, BIFF12_BORDER_DIAG_TLBR );
1663 0 : maModel.mbDiagBLtoTR = getFlag( nFlags, BIFF12_BORDER_DIAG_BLTR );
1664 0 : maModel.maTop.setBiffStyle( rStrm.readuInt16() );
1665 0 : rStrm >> maModel.maTop.maColor;
1666 0 : maModel.maBottom.setBiffStyle( rStrm.readuInt16() );
1667 0 : rStrm >> maModel.maBottom.maColor;
1668 0 : maModel.maLeft.setBiffStyle( rStrm.readuInt16() );
1669 0 : rStrm >> maModel.maLeft.maColor;
1670 0 : maModel.maRight.setBiffStyle( rStrm.readuInt16() );
1671 0 : rStrm >> maModel.maRight.maColor;
1672 0 : maModel.maDiagonal.setBiffStyle( rStrm.readuInt16() );
1673 0 : rStrm >> maModel.maDiagonal.maColor;
1674 0 : }
1675 :
1676 0 : void Border::importDxfBorder( sal_Int32 nElement, SequenceInputStream& rStrm )
1677 : {
1678 : OSL_ENSURE( mbDxf, "Border::importDxfBorder - missing conditional formatting flag" );
1679 0 : if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
1680 : {
1681 : sal_uInt16 nStyle;
1682 0 : rStrm >> pBorderLine->maColor >> nStyle;
1683 0 : pBorderLine->setBiffStyle( nStyle );
1684 0 : pBorderLine->mbUsed = true;
1685 : }
1686 0 : }
1687 :
1688 22 : void Border::finalizeImport()
1689 : {
1690 22 : maApiData.mbBorderUsed = maModel.maLeft.mbUsed || maModel.maRight.mbUsed || maModel.maTop.mbUsed || maModel.maBottom.mbUsed;
1691 22 : maApiData.mbDiagUsed = maModel.maDiagonal.mbUsed;
1692 :
1693 22 : convertBorderLine( maApiData.maLeft, maModel.maLeft );
1694 22 : convertBorderLine( maApiData.maRight, maModel.maRight );
1695 22 : convertBorderLine( maApiData.maTop, maModel.maTop );
1696 22 : convertBorderLine( maApiData.maBottom, maModel.maBottom );
1697 :
1698 22 : if( maModel.mbDiagTLtoBR )
1699 0 : convertBorderLine( maApiData.maTLtoBR, maModel.maDiagonal );
1700 22 : if( maModel.mbDiagBLtoTR )
1701 0 : convertBorderLine( maApiData.maBLtoTR, maModel.maDiagonal );
1702 22 : }
1703 :
1704 32 : void Border::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
1705 : {
1706 32 : if( maApiData.mbBorderUsed )
1707 : {
1708 32 : SvxBoxItem aBoxItem( ATTR_BORDER );
1709 32 : ::editeng::SvxBorderLine aLine;
1710 :
1711 32 : if ( SvxBoxItem::LineToSvxLine(maApiData.maLeft, aLine, true ) )
1712 : {
1713 0 : aBoxItem.SetLine( &aLine, BOX_LINE_LEFT );
1714 : }
1715 32 : if ( SvxBoxItem::LineToSvxLine(maApiData.maRight, aLine, true ) )
1716 : {
1717 0 : aBoxItem.SetLine( &aLine, BOX_LINE_RIGHT );
1718 : }
1719 32 : if ( SvxBoxItem::LineToSvxLine(maApiData.maTop, aLine, true ) )
1720 : {
1721 0 : aBoxItem.SetLine( &aLine, BOX_LINE_TOP );
1722 : }
1723 32 : if ( SvxBoxItem::LineToSvxLine(maApiData.maBottom, aLine, true ) )
1724 : {
1725 0 : aBoxItem.SetLine( &aLine, BOX_LINE_BOTTOM );
1726 : }
1727 32 : ScfTools::PutItem( rItemSet, aBoxItem, bSkipPoolDefs );
1728 : }
1729 32 : if ( maApiData.mbDiagUsed )
1730 : {
1731 32 : SvxLineItem aTLBRItem( ATTR_BORDER_TLBR );
1732 32 : SvxLineItem aBLTRItem( ATTR_BORDER_BLTR );
1733 32 : ::editeng::SvxBorderLine aLine;
1734 32 : if ( SvxBoxItem::LineToSvxLine(maApiData.maTLtoBR, aLine, true ) )
1735 : {
1736 0 : aTLBRItem.SetLine( &aLine );
1737 : }
1738 32 : if ( SvxBoxItem::LineToSvxLine(maApiData.maBLtoTR, aLine, true ) )
1739 : {
1740 0 : aBLTRItem.SetLine( &aLine );
1741 : }
1742 32 : ScfTools::PutItem( rItemSet, aTLBRItem, bSkipPoolDefs );
1743 32 : ScfTools::PutItem( rItemSet, aBLTRItem, bSkipPoolDefs );
1744 : }
1745 32 : }
1746 :
1747 22 : void Border::writeToPropertyMap( PropertyMap& rPropMap ) const
1748 : {
1749 22 : if( maApiData.mbBorderUsed )
1750 : {
1751 22 : rPropMap[ PROP_LeftBorder ] <<= maApiData.maLeft;
1752 22 : rPropMap[ PROP_RightBorder ] <<= maApiData.maRight;
1753 22 : rPropMap[ PROP_TopBorder ] <<= maApiData.maTop;
1754 22 : rPropMap[ PROP_BottomBorder ] <<= maApiData.maBottom;
1755 : }
1756 22 : if( maApiData.mbDiagUsed )
1757 : {
1758 22 : rPropMap[ PROP_DiagonalTLBR ] <<= maApiData.maTLtoBR;
1759 22 : rPropMap[ PROP_DiagonalBLTR ] <<= maApiData.maBLtoTR;
1760 : }
1761 22 : }
1762 :
1763 22 : bool Border::hasBorder() const
1764 : {
1765 22 : if (lcl_isBorder(maApiData.maBottom))
1766 0 : return true;
1767 :
1768 22 : if (lcl_isBorder(maApiData.maTop))
1769 0 : return true;
1770 :
1771 22 : if (lcl_isBorder(maApiData.maLeft))
1772 0 : return true;
1773 :
1774 22 : if (lcl_isBorder(maApiData.maRight))
1775 0 : return true;
1776 :
1777 22 : return false;
1778 : }
1779 :
1780 110 : BorderLineModel* Border::getBorderLine( sal_Int32 nElement )
1781 : {
1782 110 : switch( nElement )
1783 : {
1784 22 : case XLS_TOKEN( left ): return &maModel.maLeft;
1785 22 : case XLS_TOKEN( right ): return &maModel.maRight;
1786 22 : case XLS_TOKEN( top ): return &maModel.maTop;
1787 22 : case XLS_TOKEN( bottom ): return &maModel.maBottom;
1788 22 : case XLS_TOKEN( diagonal ): return &maModel.maDiagonal;
1789 : }
1790 0 : return 0;
1791 : }
1792 :
1793 88 : bool Border::convertBorderLine( BorderLine2& rBorderLine, const BorderLineModel& rModel )
1794 : {
1795 88 : rBorderLine.Color = rModel.maColor.getColor( getBaseFilter().getGraphicHelper(), API_RGB_BLACK );
1796 88 : switch( rModel.mnStyle )
1797 : {
1798 0 : case XML_dashDot: lclSetBorderLineWidth( rBorderLine, API_LINE_THIN ); break;
1799 0 : case XML_dashDotDot: lclSetBorderLineWidth( rBorderLine, API_LINE_THIN ); break;
1800 : case XML_dashed:
1801 : {
1802 0 : lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
1803 0 : rBorderLine.LineStyle = API_LINE_DASHED;
1804 0 : break;
1805 : }
1806 : case XML_dotted:
1807 : {
1808 0 : lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
1809 0 : rBorderLine.LineStyle = API_LINE_DOTTED;
1810 0 : break;
1811 : }
1812 0 : case XML_double: lclSetBorderLineWidth( rBorderLine, API_LINE_THIN, API_LINE_THIN, API_LINE_THIN ); break;
1813 0 : case XML_hair: lclSetBorderLineWidth( rBorderLine, API_LINE_HAIR ); break;
1814 0 : case XML_medium: lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM ); break;
1815 0 : case XML_mediumDashDot: lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM ); break;
1816 0 : case XML_mediumDashDotDot: lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM ); break;
1817 0 : case XML_mediumDashed: lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM ); break;
1818 88 : case XML_none: lclSetBorderLineWidth( rBorderLine, API_LINE_NONE ); break;
1819 0 : case XML_slantDashDot: lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM ); break;
1820 0 : case XML_thick: lclSetBorderLineWidth( rBorderLine, API_LINE_THICK ); break;
1821 0 : case XML_thin: lclSetBorderLineWidth( rBorderLine, API_LINE_THIN ); break;
1822 0 : default: lclSetBorderLineWidth( rBorderLine, API_LINE_NONE ); break;
1823 : }
1824 88 : return rModel.mbUsed;
1825 : }
1826 :
1827 :
1828 : // ============================================================================
1829 :
1830 88 : PatternFillModel::PatternFillModel( bool bDxf ) :
1831 : mnPattern( XML_none ),
1832 88 : mbPattColorUsed( !bDxf ),
1833 88 : mbFillColorUsed( !bDxf ),
1834 264 : mbPatternUsed( !bDxf )
1835 : {
1836 88 : maPatternColor.setIndexed( OOX_COLOR_WINDOWTEXT );
1837 88 : maFillColor.setIndexed( OOX_COLOR_WINDOWBACK );
1838 88 : }
1839 :
1840 0 : void PatternFillModel::setBiffPattern( sal_Int32 nPattern )
1841 : {
1842 : static const sal_Int32 spnPatternIds[] = {
1843 : XML_none, XML_solid, XML_mediumGray, XML_darkGray,
1844 : XML_lightGray, XML_darkHorizontal, XML_darkVertical, XML_darkDown,
1845 : XML_darkUp, XML_darkGrid, XML_darkTrellis, XML_lightHorizontal,
1846 : XML_lightVertical, XML_lightDown, XML_lightUp, XML_lightGrid,
1847 : XML_lightTrellis, XML_gray125, XML_gray0625 };
1848 0 : mnPattern = STATIC_ARRAY_SELECT( spnPatternIds, nPattern, XML_none );
1849 0 : }
1850 :
1851 : // ----------------------------------------------------------------------------
1852 :
1853 0 : GradientFillModel::GradientFillModel() :
1854 : mnType( XML_linear ),
1855 : mfAngle( 0.0 ),
1856 : mfLeft( 0.0 ),
1857 : mfRight( 0.0 ),
1858 : mfTop( 0.0 ),
1859 0 : mfBottom( 0.0 )
1860 : {
1861 0 : }
1862 :
1863 0 : void GradientFillModel::readGradient( SequenceInputStream& rStrm )
1864 : {
1865 : sal_Int32 nType;
1866 0 : rStrm >> nType >> mfAngle >> mfLeft >> mfRight >> mfTop >> mfBottom;
1867 : static const sal_Int32 spnTypes[] = { XML_linear, XML_path };
1868 0 : mnType = STATIC_ARRAY_SELECT( spnTypes, nType, XML_TOKEN_INVALID );
1869 0 : }
1870 :
1871 0 : void GradientFillModel::readGradientStop( SequenceInputStream& rStrm, bool bDxf )
1872 : {
1873 0 : Color aColor;
1874 : double fPosition;
1875 0 : if( bDxf )
1876 : {
1877 0 : rStrm.skip( 2 );
1878 0 : rStrm >> fPosition >> aColor;
1879 : }
1880 : else
1881 : {
1882 0 : rStrm >> aColor >> fPosition;
1883 : }
1884 0 : if( !rStrm.isEof() && (fPosition >= 0.0) )
1885 0 : maColors[ fPosition ] = aColor;
1886 0 : }
1887 :
1888 : // ----------------------------------------------------------------------------
1889 :
1890 88 : ApiSolidFillData::ApiSolidFillData() :
1891 : mnColor( API_RGB_TRANSPARENT ),
1892 : mbTransparent( true ),
1893 88 : mbUsed( false )
1894 : {
1895 88 : }
1896 :
1897 0 : bool operator==( const ApiSolidFillData& rLeft, const ApiSolidFillData& rRight )
1898 : {
1899 : return
1900 : (rLeft.mnColor == rRight.mnColor) &&
1901 : (rLeft.mbTransparent == rRight.mbTransparent) &&
1902 0 : (rLeft.mbUsed == rRight.mbUsed);
1903 : }
1904 :
1905 : // ============================================================================
1906 :
1907 : namespace {
1908 :
1909 198 : inline sal_Int32 lclGetMixedColorComp( sal_Int32 nPatt, sal_Int32 nFill, sal_Int32 nAlpha )
1910 : {
1911 198 : return ((nPatt - nFill) * nAlpha) / 0x80 + nFill;
1912 : }
1913 :
1914 66 : sal_Int32 lclGetMixedColor( sal_Int32 nPattColor, sal_Int32 nFillColor, sal_Int32 nAlpha )
1915 : {
1916 : return
1917 66 : (lclGetMixedColorComp( nPattColor & 0xFF0000, nFillColor & 0xFF0000, nAlpha ) & 0xFF0000) |
1918 66 : (lclGetMixedColorComp( nPattColor & 0x00FF00, nFillColor & 0x00FF00, nAlpha ) & 0x00FF00) |
1919 132 : (lclGetMixedColorComp( nPattColor & 0x0000FF, nFillColor & 0x0000FF, nAlpha ) & 0x0000FF);
1920 : }
1921 :
1922 : } // namespace
1923 :
1924 : // ----------------------------------------------------------------------------
1925 :
1926 88 : Fill::Fill( const WorkbookHelper& rHelper, bool bDxf ) :
1927 : WorkbookHelper( rHelper ),
1928 88 : mbDxf( bDxf )
1929 : {
1930 88 : }
1931 :
1932 88 : void Fill::importPatternFill( const AttributeList& rAttribs )
1933 : {
1934 88 : mxPatternModel.reset( new PatternFillModel( mbDxf ) );
1935 88 : mxPatternModel->mnPattern = rAttribs.getToken( XML_patternType, XML_none );
1936 88 : if( mbDxf )
1937 40 : mxPatternModel->mbPatternUsed = rAttribs.hasAttribute( XML_patternType );
1938 88 : }
1939 :
1940 4 : void Fill::importFgColor( const AttributeList& rAttribs )
1941 : {
1942 : OSL_ENSURE( mxPatternModel.get(), "Fill::importFgColor - missing pattern data" );
1943 4 : if( mxPatternModel.get() )
1944 : {
1945 4 : mxPatternModel->maPatternColor.importColor( rAttribs );
1946 4 : mxPatternModel->mbPattColorUsed = true;
1947 : }
1948 4 : }
1949 :
1950 44 : void Fill::importBgColor( const AttributeList& rAttribs )
1951 : {
1952 : OSL_ENSURE( mxPatternModel.get(), "Fill::importBgColor - missing pattern data" );
1953 44 : if( mxPatternModel.get() )
1954 : {
1955 44 : mxPatternModel->maFillColor.importColor( rAttribs );
1956 44 : mxPatternModel->mbFillColorUsed = true;
1957 : }
1958 44 : }
1959 :
1960 0 : void Fill::importGradientFill( const AttributeList& rAttribs )
1961 : {
1962 0 : mxGradientModel.reset( new GradientFillModel );
1963 0 : mxGradientModel->mnType = rAttribs.getToken( XML_type, XML_linear );
1964 0 : mxGradientModel->mfAngle = rAttribs.getDouble( XML_degree, 0.0 );
1965 0 : mxGradientModel->mfLeft = rAttribs.getDouble( XML_left, 0.0 );
1966 0 : mxGradientModel->mfRight = rAttribs.getDouble( XML_right, 0.0 );
1967 0 : mxGradientModel->mfTop = rAttribs.getDouble( XML_top, 0.0 );
1968 0 : mxGradientModel->mfBottom = rAttribs.getDouble( XML_bottom, 0.0 );
1969 0 : }
1970 :
1971 0 : void Fill::importColor( const AttributeList& rAttribs, double fPosition )
1972 : {
1973 : OSL_ENSURE( mxGradientModel.get(), "Fill::importColor - missing gradient data" );
1974 0 : if( mxGradientModel.get() && (fPosition >= 0.0) )
1975 0 : mxGradientModel->maColors[ fPosition ].importColor( rAttribs );
1976 0 : }
1977 :
1978 0 : void Fill::importFill( SequenceInputStream& rStrm )
1979 : {
1980 : OSL_ENSURE( !mbDxf, "Fill::importFill - unexpected conditional formatting flag" );
1981 0 : sal_Int32 nPattern = rStrm.readInt32();
1982 0 : if( nPattern == BIFF12_FILL_GRADIENT )
1983 : {
1984 0 : mxGradientModel.reset( new GradientFillModel );
1985 : sal_Int32 nStopCount;
1986 0 : rStrm.skip( 16 );
1987 0 : mxGradientModel->readGradient( rStrm );
1988 0 : rStrm >> nStopCount;
1989 0 : for( sal_Int32 nStop = 0; (nStop < nStopCount) && !rStrm.isEof(); ++nStop )
1990 0 : mxGradientModel->readGradientStop( rStrm, false );
1991 : }
1992 : else
1993 : {
1994 0 : mxPatternModel.reset( new PatternFillModel( mbDxf ) );
1995 0 : mxPatternModel->setBiffPattern( nPattern );
1996 0 : rStrm >> mxPatternModel->maPatternColor >> mxPatternModel->maFillColor;
1997 : }
1998 0 : }
1999 :
2000 0 : void Fill::importDxfPattern( SequenceInputStream& rStrm )
2001 : {
2002 : OSL_ENSURE( mbDxf, "Fill::importDxfPattern - missing conditional formatting flag" );
2003 0 : if( !mxPatternModel )
2004 0 : mxPatternModel.reset( new PatternFillModel( mbDxf ) );
2005 0 : mxPatternModel->setBiffPattern( rStrm.readuInt8() );
2006 0 : mxPatternModel->mbPatternUsed = true;
2007 0 : }
2008 :
2009 0 : void Fill::importDxfFgColor( SequenceInputStream& rStrm )
2010 : {
2011 : OSL_ENSURE( mbDxf, "Fill::importDxfFgColor - missing conditional formatting flag" );
2012 0 : if( !mxPatternModel )
2013 0 : mxPatternModel.reset( new PatternFillModel( mbDxf ) );
2014 0 : mxPatternModel->maPatternColor.importColor( rStrm );
2015 0 : mxPatternModel->mbPattColorUsed = true;
2016 0 : }
2017 :
2018 0 : void Fill::importDxfBgColor( SequenceInputStream& rStrm )
2019 : {
2020 : OSL_ENSURE( mbDxf, "Fill::importDxfBgColor - missing conditional formatting flag" );
2021 0 : if( !mxPatternModel )
2022 0 : mxPatternModel.reset( new PatternFillModel( mbDxf ) );
2023 0 : mxPatternModel->maFillColor.importColor( rStrm );
2024 0 : mxPatternModel->mbFillColorUsed = true;
2025 0 : }
2026 :
2027 0 : void Fill::importDxfGradient( SequenceInputStream& rStrm )
2028 : {
2029 : OSL_ENSURE( mbDxf, "Fill::importDxfGradient - missing conditional formatting flag" );
2030 0 : if( !mxGradientModel )
2031 0 : mxGradientModel.reset( new GradientFillModel );
2032 0 : mxGradientModel->readGradient( rStrm );
2033 0 : }
2034 :
2035 0 : void Fill::importDxfStop( SequenceInputStream& rStrm )
2036 : {
2037 : OSL_ENSURE( mbDxf, "Fill::importDxfStop - missing conditional formatting flag" );
2038 0 : if( !mxGradientModel )
2039 0 : mxGradientModel.reset( new GradientFillModel );
2040 0 : mxGradientModel->readGradientStop( rStrm, true );
2041 0 : }
2042 :
2043 88 : void Fill::finalizeImport()
2044 : {
2045 88 : const GraphicHelper& rGraphicHelper = getBaseFilter().getGraphicHelper();
2046 :
2047 88 : if( mxPatternModel.get() )
2048 : {
2049 : // finalize the OOXML data struct
2050 88 : PatternFillModel& rModel = *mxPatternModel;
2051 88 : if( mbDxf )
2052 : {
2053 40 : if( rModel.mbFillColorUsed && (!rModel.mbPatternUsed || (rModel.mnPattern == XML_solid)) )
2054 : {
2055 40 : rModel.maPatternColor = rModel.maFillColor;
2056 40 : rModel.mnPattern = XML_solid;
2057 40 : rModel.mbPattColorUsed = rModel.mbPatternUsed = true;
2058 : }
2059 0 : else if( !rModel.mbFillColorUsed && rModel.mbPatternUsed && (rModel.mnPattern == XML_solid) )
2060 : {
2061 0 : rModel.mbPatternUsed = false;
2062 : }
2063 : }
2064 :
2065 : // convert to API fill settings
2066 88 : maApiData.mbUsed = rModel.mbPatternUsed;
2067 88 : if( rModel.mnPattern == XML_none )
2068 : {
2069 22 : maApiData.mnColor = API_RGB_TRANSPARENT;
2070 22 : maApiData.mbTransparent = true;
2071 : }
2072 : else
2073 : {
2074 66 : sal_Int32 nAlpha = 0x80;
2075 66 : switch( rModel.mnPattern )
2076 : {
2077 0 : case XML_darkDown: nAlpha = 0x40; break;
2078 0 : case XML_darkGray: nAlpha = 0x60; break;
2079 0 : case XML_darkGrid: nAlpha = 0x40; break;
2080 0 : case XML_darkHorizontal: nAlpha = 0x40; break;
2081 0 : case XML_darkTrellis: nAlpha = 0x60; break;
2082 0 : case XML_darkUp: nAlpha = 0x40; break;
2083 0 : case XML_darkVertical: nAlpha = 0x40; break;
2084 0 : case XML_gray0625: nAlpha = 0x08; break;
2085 22 : case XML_gray125: nAlpha = 0x10; break;
2086 0 : case XML_lightDown: nAlpha = 0x20; break;
2087 0 : case XML_lightGray: nAlpha = 0x20; break;
2088 0 : case XML_lightGrid: nAlpha = 0x38; break;
2089 0 : case XML_lightHorizontal: nAlpha = 0x20; break;
2090 0 : case XML_lightTrellis: nAlpha = 0x30; break;
2091 0 : case XML_lightUp: nAlpha = 0x20; break;
2092 0 : case XML_lightVertical: nAlpha = 0x20; break;
2093 0 : case XML_mediumGray: nAlpha = 0x40; break;
2094 44 : case XML_solid: nAlpha = 0x80; break;
2095 : }
2096 :
2097 66 : sal_Int32 nWinTextColor = rGraphicHelper.getSystemColor( XML_windowText );
2098 66 : sal_Int32 nWinColor = rGraphicHelper.getSystemColor( XML_window );
2099 :
2100 66 : if( !rModel.mbPattColorUsed )
2101 0 : rModel.maPatternColor.setAuto();
2102 66 : sal_Int32 nPattColor = rModel.maPatternColor.getColor( rGraphicHelper, nWinTextColor );
2103 :
2104 66 : if( !rModel.mbFillColorUsed )
2105 0 : rModel.maFillColor.setAuto();
2106 66 : sal_Int32 nFillColor = rModel.maFillColor.getColor( rGraphicHelper, nWinColor );
2107 :
2108 66 : maApiData.mnColor = lclGetMixedColor( nPattColor, nFillColor, nAlpha );
2109 66 : maApiData.mbTransparent = false;
2110 : }
2111 : }
2112 0 : else if( mxGradientModel.get() && !mxGradientModel->maColors.empty() )
2113 : {
2114 0 : GradientFillModel& rModel = *mxGradientModel;
2115 0 : maApiData.mbUsed = true; // no support for differential attributes
2116 0 : GradientFillModel::ColorMap::const_iterator aIt = rModel.maColors.begin();
2117 : OSL_ENSURE( !aIt->second.isAuto(), "Fill::finalizeImport - automatic gradient color" );
2118 0 : maApiData.mnColor = aIt->second.getColor( rGraphicHelper, API_RGB_WHITE );
2119 0 : if( ++aIt != rModel.maColors.end() )
2120 : {
2121 : OSL_ENSURE( !aIt->second.isAuto(), "Fill::finalizeImport - automatic gradient color" );
2122 0 : sal_Int32 nEndColor = aIt->second.getColor( rGraphicHelper, API_RGB_WHITE );
2123 0 : maApiData.mnColor = lclGetMixedColor( maApiData.mnColor, nEndColor, 0x40 );
2124 0 : maApiData.mbTransparent = false;
2125 : }
2126 : }
2127 88 : }
2128 :
2129 300 : void Fill::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
2130 : {
2131 300 : if( maApiData.mbUsed )
2132 : {
2133 300 : SvxBrushItem aBrushItem( ATTR_BACKGROUND );
2134 300 : if ( maApiData.mbTransparent )
2135 : {
2136 296 : aBrushItem.SetColor( ::Color( COL_TRANSPARENT ) );
2137 : }
2138 : else
2139 : {
2140 4 : aBrushItem.SetColor( maApiData.mnColor );
2141 : }
2142 300 : ScfTools::PutItem( rItemSet, aBrushItem, bSkipPoolDefs );
2143 : }
2144 300 : }
2145 :
2146 62 : void Fill::writeToPropertyMap( PropertyMap& rPropMap ) const
2147 : {
2148 62 : if( maApiData.mbUsed )
2149 : {
2150 62 : rPropMap[ PROP_CellBackColor ] <<= maApiData.mnColor;
2151 62 : rPropMap[ PROP_IsCellBackgroundTransparent ] <<= maApiData.mbTransparent;
2152 : }
2153 62 : }
2154 :
2155 : // ============================================================================
2156 :
2157 374 : XfModel::XfModel() :
2158 : mnStyleXfId( -1 ),
2159 : mnFontId( -1 ),
2160 : mnNumFmtId( -1 ),
2161 : mnBorderId( -1 ),
2162 : mnFillId( -1 ),
2163 : mbCellXf( true ),
2164 : mbFontUsed( false ),
2165 : mbNumFmtUsed( false ),
2166 : mbAlignUsed( false ),
2167 : mbProtUsed( false ),
2168 : mbBorderUsed( false ),
2169 374 : mbAreaUsed( false )
2170 : {
2171 374 : }
2172 :
2173 : // ============================================================================
2174 :
2175 374 : Xf::Xf( const WorkbookHelper& rHelper ) :
2176 : WorkbookHelper( rHelper ),
2177 : maAlignment( rHelper ),
2178 : maProtection( rHelper ),
2179 : meRotationRef( ::com::sun::star::table::CellVertJustify2::STANDARD ),
2180 374 : mpStyleSheet( NULL )
2181 : {
2182 374 : }
2183 :
2184 374 : void Xf::importXf( const AttributeList& rAttribs, bool bCellXf )
2185 : {
2186 374 : maModel.mbCellXf = bCellXf;
2187 374 : maModel.mnStyleXfId = rAttribs.getInteger( XML_xfId, -1 );
2188 374 : maModel.mnFontId = rAttribs.getInteger( XML_fontId, -1 );
2189 374 : maModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, -1 );
2190 374 : maModel.mnBorderId = rAttribs.getInteger( XML_borderId, -1 );
2191 374 : maModel.mnFillId = rAttribs.getInteger( XML_fillId, -1 );
2192 :
2193 : /* Default value of the apply*** attributes is dependent on context:
2194 : true in cellStyleXfs element, false in cellXfs element... */
2195 374 : maModel.mbAlignUsed = rAttribs.getBool( XML_applyAlignment, !maModel.mbCellXf );
2196 374 : maModel.mbProtUsed = rAttribs.getBool( XML_applyProtection, !maModel.mbCellXf );
2197 374 : maModel.mbFontUsed = rAttribs.getBool( XML_applyFont, !maModel.mbCellXf );
2198 374 : maModel.mbNumFmtUsed = rAttribs.getBool( XML_applyNumberFormat, !maModel.mbCellXf );
2199 374 : maModel.mbBorderUsed = rAttribs.getBool( XML_applyBorder, !maModel.mbCellXf );
2200 374 : maModel.mbAreaUsed = rAttribs.getBool( XML_applyFill, !maModel.mbCellXf );
2201 374 : }
2202 :
2203 70 : void Xf::importAlignment( const AttributeList& rAttribs )
2204 : {
2205 70 : maAlignment.importAlignment( rAttribs );
2206 70 : }
2207 :
2208 66 : void Xf::importProtection( const AttributeList& rAttribs )
2209 : {
2210 66 : maProtection.importProtection( rAttribs );
2211 66 : }
2212 :
2213 0 : void Xf::importXf( SequenceInputStream& rStrm, bool bCellXf )
2214 : {
2215 0 : maModel.mbCellXf = bCellXf;
2216 0 : maModel.mnStyleXfId = rStrm.readuInt16();
2217 0 : maModel.mnNumFmtId = rStrm.readuInt16();
2218 0 : maModel.mnFontId = rStrm.readuInt16();
2219 0 : maModel.mnFillId = rStrm.readuInt16();
2220 0 : maModel.mnBorderId = rStrm.readuInt16();
2221 0 : sal_uInt32 nFlags = rStrm.readuInt32();
2222 0 : maAlignment.setBiff12Data( nFlags );
2223 0 : maProtection.setBiff12Data( nFlags );
2224 : // used flags, see comments in Xf::setBiffUsedFlags()
2225 0 : sal_uInt16 nUsedFlags = rStrm.readuInt16();
2226 0 : maModel.mbFontUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_FONT_USED );
2227 0 : maModel.mbNumFmtUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_NUMFMT_USED );
2228 0 : maModel.mbAlignUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_ALIGN_USED );
2229 0 : maModel.mbProtUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_PROT_USED );
2230 0 : maModel.mbBorderUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_BORDER_USED );
2231 0 : maModel.mbAreaUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_AREA_USED );
2232 0 : }
2233 :
2234 374 : void Xf::finalizeImport()
2235 : {
2236 : // alignment and protection
2237 374 : maAlignment.finalizeImport();
2238 374 : maProtection.finalizeImport();
2239 374 : createPattern();
2240 374 : }
2241 :
2242 218 : FontRef Xf::getFont() const
2243 : {
2244 218 : return getStyles().getFont( maModel.mnFontId );
2245 : }
2246 :
2247 76 : void Xf::writeToMarkData( ::ScMarkData& rMarkData, sal_Int32 nNumFmtId )
2248 : {
2249 76 : createPattern();
2250 76 : ScPatternAttr& rPat = *mpPattern;
2251 76 : ScDocument& rDoc = getScDocument();
2252 76 : if ( isCellXf() )
2253 : {
2254 76 : StylesBuffer& rStyles = getStyles();
2255 76 : rStyles.createCellStyle( maModel.mnStyleXfId );
2256 :
2257 76 : mpStyleSheet = rStyles.getCellStyleSheet( maModel.mnStyleXfId );
2258 76 : if ( mpStyleSheet )
2259 : {
2260 2 : rDoc.ApplySelectionStyle( static_cast<ScStyleSheet&>(*mpStyleSheet), rMarkData );
2261 : }
2262 : else
2263 : {
2264 74 : ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
2265 74 : if (pStylePool)
2266 : {
2267 : ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>(
2268 : pStylePool->Find(
2269 74 : ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA));
2270 :
2271 74 : if (pStyleSheet)
2272 74 : rDoc.ApplySelectionStyle( static_cast<ScStyleSheet&>(*pStyleSheet), rMarkData );
2273 : }
2274 : }
2275 : }
2276 76 : if ( nNumFmtId >= 0 )
2277 : {
2278 0 : ScPatternAttr aNumPat(rDoc.GetPool());
2279 0 : getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId );
2280 0 : rPat.GetItemSet().Put(aNumPat.GetItemSet());
2281 : }
2282 76 : rDoc.ApplySelectionPattern( rPat, rMarkData );
2283 76 : }
2284 :
2285 80 : void Xf::writeToPropertyMap( PropertyMap& rPropMap ) const
2286 : {
2287 80 : StylesBuffer& rStyles = getStyles();
2288 :
2289 : // create and set cell style
2290 80 : if( isCellXf() )
2291 58 : rPropMap[ PROP_CellStyle ] <<= rStyles.createCellStyle( maModel.mnStyleXfId );
2292 :
2293 80 : if( maModel.mbFontUsed )
2294 22 : rStyles.writeFontToPropertyMap( rPropMap, maModel.mnFontId );
2295 80 : if( maModel.mbNumFmtUsed )
2296 22 : rStyles.writeNumFmtToPropertyMap( rPropMap, maModel.mnNumFmtId );
2297 80 : if( maModel.mbAlignUsed )
2298 22 : maAlignment.writeToPropertyMap( rPropMap );
2299 80 : if( maModel.mbProtUsed )
2300 22 : maProtection.writeToPropertyMap( rPropMap );
2301 80 : if( maModel.mbBorderUsed )
2302 22 : rStyles.writeBorderToPropertyMap( rPropMap, maModel.mnBorderId );
2303 80 : if( maModel.mbAreaUsed )
2304 22 : rStyles.writeFillToPropertyMap( rPropMap, maModel.mnFillId );
2305 80 : if( maModel.mbAlignUsed || maModel.mbBorderUsed )
2306 22 : rPropMap[ PROP_RotateReference ] <<= meRotationRef;
2307 :
2308 80 : sal_Int32 eRotRef = ::com::sun::star::table::CellVertJustify2::STANDARD;
2309 80 : if (maModel.mbBorderUsed && rStyles.hasBorder(maModel.mnBorderId) && maAlignment.getApiData().mnRotation)
2310 0 : eRotRef = ::com::sun::star::table::CellVertJustify2::BOTTOM;
2311 80 : rPropMap[ PROP_RotateReference ] <<= eRotRef;
2312 80 : }
2313 :
2314 80 : void Xf::writeToPropertySet( PropertySet& rPropSet ) const
2315 : {
2316 80 : PropertyMap aPropMap;
2317 80 : writeToPropertyMap( aPropMap );
2318 80 : rPropSet.setProperties( aPropMap );
2319 80 : }
2320 :
2321 : const ::ScPatternAttr&
2322 460 : Xf::createPattern( bool bSkipPoolDefs )
2323 : {
2324 460 : if( mpPattern.get() )
2325 86 : return *mpPattern;
2326 374 : mpPattern.reset( new ::ScPatternAttr( getScDocument().GetPool() ) );
2327 374 : SfxItemSet& rItemSet = mpPattern->GetItemSet();
2328 : /* Enables the used flags, if the formatting attributes differ from the
2329 : style XF. In cell XFs Excel uses the cell attributes, if they differ
2330 : from the parent style XF (even if the used flag is switched off).
2331 : #109899# ...or if the respective flag is not set in parent style XF.
2332 : */
2333 374 : StylesBuffer& rStyles = getStyles();
2334 :
2335 374 : const Xf* pStyleXf = isCellXf() ? rStyles.getStyleXf( maModel.mnStyleXfId ).get() : 0;
2336 374 : if( pStyleXf )
2337 : {
2338 76 : const XfModel& rStyleData = pStyleXf->maModel;
2339 76 : if( !maModel.mbFontUsed )
2340 48 : maModel.mbFontUsed = !rStyleData.mbFontUsed || (maModel.mnFontId != rStyleData.mnFontId);
2341 76 : if( !maModel.mbNumFmtUsed )
2342 76 : maModel.mbNumFmtUsed = !rStyleData.mbNumFmtUsed || (maModel.mnNumFmtId != rStyleData.mnNumFmtId);
2343 76 : if( !maModel.mbAlignUsed )
2344 68 : maModel.mbAlignUsed = !rStyleData.mbAlignUsed || !(maAlignment.getApiData() == pStyleXf->maAlignment.getApiData());
2345 76 : if( !maModel.mbProtUsed )
2346 76 : maModel.mbProtUsed = !rStyleData.mbProtUsed || !(maProtection.getApiData() == pStyleXf->maProtection.getApiData());
2347 76 : if( !maModel.mbBorderUsed )
2348 76 : maModel.mbBorderUsed = !rStyleData.mbBorderUsed || !rStyles.equalBorders( maModel.mnBorderId, rStyleData.mnBorderId );
2349 76 : if( !maModel.mbAreaUsed )
2350 76 : maModel.mbAreaUsed = !rStyleData.mbAreaUsed || !rStyles.equalFills( maModel.mnFillId, rStyleData.mnFillId );
2351 : }
2352 : // cell protection
2353 374 : if( maModel.mbProtUsed )
2354 : {
2355 32 : maProtection.fillToItemSet( rItemSet, bSkipPoolDefs );
2356 : }
2357 :
2358 : // font
2359 374 : if( maModel.mbFontUsed )
2360 : {
2361 330 : rStyles.writeFontToItemSet( rItemSet, maModel.mnFontId, bSkipPoolDefs );
2362 : }
2363 :
2364 : // value format
2365 374 : if( maModel.mbNumFmtUsed )
2366 : {
2367 322 : rStyles.writeNumFmtToItemSet( rItemSet, maModel.mnNumFmtId, bSkipPoolDefs );
2368 : }
2369 : // alignment
2370 374 : if( maModel.mbAlignUsed )
2371 : {
2372 40 : maAlignment.fillToItemSet( rItemSet, bSkipPoolDefs );
2373 : }
2374 :
2375 : // border
2376 374 : if( maModel.mbBorderUsed )
2377 : {
2378 32 : rStyles.writeBorderToItemSet( rItemSet, maModel.mnBorderId, bSkipPoolDefs );
2379 : }
2380 :
2381 : // area
2382 374 : if( maModel.mbAreaUsed )
2383 : {
2384 300 : rStyles.writeFillToItemSet( rItemSet, maModel.mnFillId, bSkipPoolDefs );
2385 : }
2386 :
2387 : /* #i38709# Decide which rotation reference mode to use. If any outer
2388 : border line of the cell is set (either explicitly or via cell style),
2389 : and the cell contents are rotated, set rotation reference to bottom of
2390 : cell. This causes the borders to be painted rotated with the text. */
2391 374 : if( const Alignment* pAlignment = maModel.mbAlignUsed ? &maAlignment : (pStyleXf ? &pStyleXf->maAlignment : 0) )
2392 : {
2393 108 : SvxRotateMode eRotateMode = SVX_ROTATE_MODE_STANDARD;
2394 108 : sal_Int32 nBorderId = maModel.mbBorderUsed ? maModel.mnBorderId : (pStyleXf ? pStyleXf->maModel.mnBorderId : -1);
2395 108 : if( const Border* pBorder = rStyles.getBorder( nBorderId ).get() )
2396 : {
2397 108 : if( (pAlignment->getApiData().mnRotation != 0) && pBorder->getApiData().hasAnyOuterBorder() )
2398 : {
2399 0 : meRotationRef = ::com::sun::star::table::CellVertJustify2::BOTTOM;
2400 0 : eRotateMode = SVX_ROTATE_MODE_BOTTOM;
2401 : }
2402 : }
2403 108 : ScfTools::PutItem( rItemSet, SvxRotateModeItem( eRotateMode, ATTR_ROTATE_MODE ), bSkipPoolDefs );
2404 : }
2405 :
2406 374 : return *mpPattern;
2407 : }
2408 :
2409 : // ============================================================================
2410 :
2411 140 : Dxf::Dxf( const WorkbookHelper& rHelper ) :
2412 140 : WorkbookHelper( rHelper )
2413 : {
2414 140 : }
2415 :
2416 40 : FontRef Dxf::createFont( bool bAlwaysNew )
2417 : {
2418 40 : if( bAlwaysNew || !mxFont )
2419 40 : mxFont.reset( new Font( *this, true ) );
2420 40 : return mxFont;
2421 : }
2422 :
2423 0 : BorderRef Dxf::createBorder( bool bAlwaysNew )
2424 : {
2425 0 : if( bAlwaysNew || !mxBorder )
2426 0 : mxBorder.reset( new Border( *this, true ) );
2427 0 : return mxBorder;
2428 : }
2429 :
2430 40 : FillRef Dxf::createFill( bool bAlwaysNew )
2431 : {
2432 40 : if( bAlwaysNew || !mxFill )
2433 40 : mxFill.reset( new Fill( *this, true ) );
2434 40 : return mxFill;
2435 : }
2436 :
2437 140 : void Dxf::importNumFmt( const AttributeList& rAttribs )
2438 : {
2439 : // don't propagate number formats defined in Dxf entries
2440 : // they can have the same id ( but different format codes ) as those
2441 : // defined globally earlier. We discard the id defined in XML_numFmtId
2442 : // and generate one ourselves ( this assumes that the normal numberformat
2443 : // import has already taken place )
2444 140 : sal_Int32 nNumFmtId = getStyles().nextFreeNumFmtId();
2445 140 : OUString aFmtCode = rAttribs.getXString( XML_formatCode, OUString() );
2446 : // we might need to do this generally for format codes,
2447 : // specifically for a fraction code '\ ?/?' is passed to us in xml, the '\' is not
2448 : // an escape character but merely should be telling the formatter to display the next
2449 : // char in the format ( afaics it does that anyhow )
2450 140 : aFmtCode = aFmtCode.replaceAll("\\", "");
2451 140 : mxNumFmt = getStyles().createNumFmt( nNumFmtId, aFmtCode );
2452 140 : }
2453 :
2454 0 : void Dxf::importDxf( SequenceInputStream& rStrm )
2455 : {
2456 0 : sal_Int32 nNumFmtId = -1;
2457 0 : OUString aFmtCode;
2458 : sal_uInt16 nRecCount;
2459 0 : rStrm.skip( 4 ); // flags
2460 0 : rStrm >> nRecCount;
2461 0 : for( sal_uInt16 nRec = 0; !rStrm.isEof() && (nRec < nRecCount); ++nRec )
2462 : {
2463 : sal_uInt16 nSubRecId, nSubRecSize;
2464 0 : sal_Int64 nRecEnd = rStrm.tell();
2465 0 : rStrm >> nSubRecId >> nSubRecSize;
2466 0 : nRecEnd += nSubRecSize;
2467 0 : switch( nSubRecId )
2468 : {
2469 0 : case BIFF12_DXF_FILL_PATTERN: createFill( false )->importDxfPattern( rStrm ); break;
2470 0 : case BIFF12_DXF_FILL_FGCOLOR: createFill( false )->importDxfFgColor( rStrm ); break;
2471 0 : case BIFF12_DXF_FILL_BGCOLOR: createFill( false )->importDxfBgColor( rStrm ); break;
2472 0 : case BIFF12_DXF_FILL_GRADIENT: createFill( false )->importDxfGradient( rStrm ); break;
2473 0 : case BIFF12_DXF_FILL_STOP: createFill( false )->importDxfStop( rStrm ); break;
2474 0 : case BIFF12_DXF_FONT_COLOR: createFont( false )->importDxfColor( rStrm ); break;
2475 0 : case BIFF12_DXF_BORDER_TOP: createBorder( false )->importDxfBorder( XLS_TOKEN( top ), rStrm ); break;
2476 0 : case BIFF12_DXF_BORDER_BOTTOM: createBorder( false )->importDxfBorder( XLS_TOKEN( bottom ), rStrm ); break;
2477 0 : case BIFF12_DXF_BORDER_LEFT: createBorder( false )->importDxfBorder( XLS_TOKEN( left ), rStrm ); break;
2478 0 : case BIFF12_DXF_BORDER_RIGHT: createBorder( false )->importDxfBorder( XLS_TOKEN( right ), rStrm ); break;
2479 0 : case BIFF12_DXF_FONT_NAME: createFont( false )->importDxfName( rStrm ); break;
2480 0 : case BIFF12_DXF_FONT_WEIGHT: createFont( false )->importDxfWeight( rStrm ); break;
2481 0 : case BIFF12_DXF_FONT_UNDERLINE: createFont( false )->importDxfUnderline( rStrm ); break;
2482 0 : case BIFF12_DXF_FONT_ESCAPEMENT: createFont( false )->importDxfEscapement( rStrm ); break;
2483 0 : case BIFF12_DXF_FONT_ITALIC: createFont( false )->importDxfFlag( XML_i, rStrm ); break;
2484 0 : case BIFF12_DXF_FONT_STRIKE: createFont( false )->importDxfFlag( XML_strike, rStrm ); break;
2485 0 : case BIFF12_DXF_FONT_OUTLINE: createFont( false )->importDxfFlag( XML_outline, rStrm ); break;
2486 0 : case BIFF12_DXF_FONT_SHADOW: createFont( false )->importDxfFlag( XML_shadow, rStrm ); break;
2487 0 : case BIFF12_DXF_FONT_HEIGHT: createFont( false )->importDxfHeight( rStrm ); break;
2488 0 : case BIFF12_DXF_FONT_SCHEME: createFont( false )->importDxfScheme( rStrm ); break;
2489 0 : case BIFF12_DXF_NUMFMT_CODE: aFmtCode = BiffHelper::readString( rStrm, false ); break;
2490 0 : case BIFF12_DXF_NUMFMT_ID: nNumFmtId = rStrm.readuInt16(); break;
2491 : }
2492 0 : rStrm.seek( nRecEnd );
2493 : }
2494 : OSL_ENSURE( !rStrm.isEof() && (rStrm.getRemaining() == 0), "Dxf::importDxf - unexpected remaining data" );
2495 0 : mxNumFmt = getStyles().createNumFmt( nNumFmtId, aFmtCode );
2496 0 : }
2497 :
2498 140 : void Dxf::finalizeImport()
2499 : {
2500 140 : if( mxFont.get() )
2501 40 : mxFont->finalizeImport();
2502 : // number format already finalized by the number formats buffer
2503 140 : if( mxAlignment.get() )
2504 0 : mxAlignment->finalizeImport();
2505 140 : if( mxProtection.get() )
2506 0 : mxProtection->finalizeImport();
2507 140 : if( mxBorder.get() )
2508 0 : mxBorder->finalizeImport();
2509 140 : if( mxFill.get() )
2510 40 : mxFill->finalizeImport();
2511 140 : }
2512 :
2513 72 : void Dxf::writeToPropertyMap( PropertyMap& rPropMap ) const
2514 : {
2515 72 : if( mxFont.get() )
2516 40 : mxFont->writeToPropertyMap( rPropMap, FONT_PROPTYPE_CELL );
2517 72 : if( mxNumFmt.get() )
2518 72 : mxNumFmt->writeToPropertyMap( rPropMap );
2519 72 : if( mxAlignment.get() )
2520 0 : mxAlignment->writeToPropertyMap( rPropMap );
2521 72 : if( mxProtection.get() )
2522 0 : mxProtection->writeToPropertyMap( rPropMap );
2523 72 : if( mxBorder.get() )
2524 0 : mxBorder->writeToPropertyMap( rPropMap );
2525 72 : if( mxFill.get() )
2526 40 : mxFill->writeToPropertyMap( rPropMap );
2527 72 : }
2528 :
2529 72 : void Dxf::writeToPropertySet( PropertySet& rPropSet ) const
2530 : {
2531 72 : PropertyMap aPropMap;
2532 72 : writeToPropertyMap( aPropMap );
2533 72 : rPropSet.setProperties( aPropMap );
2534 72 : }
2535 :
2536 : // ============================================================================
2537 :
2538 : namespace {
2539 :
2540 : const sal_Char* const spcLegacyStyleNamePrefix = "Excel_BuiltIn_";
2541 : const sal_Char* const sppcLegacyStyleNames[] =
2542 : {
2543 : "Normal",
2544 : "RowLevel_", // outline level will be appended
2545 : "ColumnLevel_", // outline level will be appended
2546 : "Comma",
2547 : "Currency",
2548 : "Percent",
2549 : "Comma_0", // new in BIFF4
2550 : "Currency_0",
2551 : "Hyperlink", // new in BIFF8
2552 : "Followed_Hyperlink"
2553 : };
2554 : const sal_Int32 snLegacyStyleNamesCount = static_cast< sal_Int32 >( STATIC_ARRAY_SIZE( sppcLegacyStyleNames ) );
2555 :
2556 : const sal_Char* const spcStyleNamePrefix = "Excel Built-in ";
2557 : const sal_Char* const sppcStyleNames[] =
2558 : {
2559 : "Normal",
2560 : "RowLevel_", // outline level will be appended
2561 : "ColLevel_", // outline level will be appended
2562 : "Comma",
2563 : "Currency",
2564 : "Percent",
2565 : "Comma [0]", // new in BIFF4
2566 : "Currency [0]",
2567 : "Hyperlink", // new in BIFF8
2568 : "Followed Hyperlink",
2569 : "Note", // new in OOX
2570 : "Warning Text",
2571 : 0,
2572 : 0,
2573 : 0,
2574 : "Title",
2575 : "Heading 1",
2576 : "Heading 2",
2577 : "Heading 3",
2578 : "Heading 4",
2579 : "Input",
2580 : "Output",
2581 : "Calculation",
2582 : "Check Cell",
2583 : "Linked Cell",
2584 : "Total",
2585 : "Good",
2586 : "Bad",
2587 : "Neutral",
2588 : "Accent1",
2589 : "20% - Accent1",
2590 : "40% - Accent1",
2591 : "60% - Accent1",
2592 : "Accent2",
2593 : "20% - Accent2",
2594 : "40% - Accent2",
2595 : "60% - Accent2",
2596 : "Accent3",
2597 : "20% - Accent3",
2598 : "40% - Accent3",
2599 : "60% - Accent3",
2600 : "Accent4",
2601 : "20% - Accent4",
2602 : "40% - Accent4",
2603 : "60% - Accent4",
2604 : "Accent5",
2605 : "20% - Accent5",
2606 : "40% - Accent5",
2607 : "60% - Accent5",
2608 : "Accent6",
2609 : "20% - Accent6",
2610 : "40% - Accent6",
2611 : "60% - Accent6",
2612 : "Explanatory Text"
2613 : };
2614 : const sal_Int32 snStyleNamesCount = static_cast< sal_Int32 >( STATIC_ARRAY_SIZE( sppcStyleNames ) );
2615 :
2616 254 : OUString lclGetBuiltinStyleName( sal_Int32 nBuiltinId, const OUString& rName, sal_Int32 nLevel = 0 )
2617 : {
2618 : OSL_ENSURE( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount), "lclGetBuiltinStyleName - unknown built-in style" );
2619 254 : OUStringBuffer aStyleName;
2620 254 : aStyleName.appendAscii( spcStyleNamePrefix );
2621 254 : if( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount) && (sppcStyleNames[ nBuiltinId ] != 0) )
2622 252 : aStyleName.appendAscii( sppcStyleNames[ nBuiltinId ] );
2623 2 : else if( !rName.isEmpty() )
2624 2 : aStyleName.append( rName );
2625 : else
2626 0 : aStyleName.append( nBuiltinId );
2627 254 : if( (nBuiltinId == OOX_STYLE_ROWLEVEL) || (nBuiltinId == OOX_STYLE_COLLEVEL) )
2628 0 : aStyleName.append( nLevel );
2629 254 : return aStyleName.makeStringAndClear();
2630 : }
2631 :
2632 88 : OUString lclCreateStyleName( const CellStyleModel& rModel )
2633 : {
2634 88 : return rModel.mbBuiltin ? lclGetBuiltinStyleName( rModel.mnBuiltinId, rModel.maName, rModel.mnLevel ) : rModel.maName;
2635 : }
2636 :
2637 : } // namespace
2638 :
2639 : // ----------------------------------------------------------------------------
2640 :
2641 102 : CellStyleModel::CellStyleModel() :
2642 : mnXfId( -1 ),
2643 : mnBuiltinId( -1 ),
2644 : mnLevel( 0 ),
2645 : mbBuiltin( false ),
2646 : mbCustom( false ),
2647 102 : mbHidden( false )
2648 : {
2649 102 : }
2650 :
2651 182 : bool CellStyleModel::isBuiltin() const
2652 : {
2653 182 : return mbBuiltin && (mnBuiltinId >= 0);
2654 : }
2655 :
2656 206 : bool CellStyleModel::isDefaultStyle() const
2657 : {
2658 206 : return mbBuiltin && (mnBuiltinId == OOX_STYLE_NORMAL);
2659 : }
2660 :
2661 : // ============================================================================
2662 :
2663 102 : CellStyle::CellStyle( const WorkbookHelper& rHelper ) :
2664 : WorkbookHelper( rHelper ),
2665 : mbCreated( false ),
2666 102 : mpStyleSheet( NULL )
2667 : {
2668 102 : }
2669 :
2670 102 : void CellStyle::importCellStyle( const AttributeList& rAttribs )
2671 : {
2672 102 : maModel.maName = rAttribs.getXString( XML_name, OUString() );
2673 102 : maModel.mnXfId = rAttribs.getInteger( XML_xfId, -1 );
2674 102 : maModel.mnBuiltinId = rAttribs.getInteger( XML_builtinId, -1 );
2675 102 : maModel.mnLevel = rAttribs.getInteger( XML_iLevel, 0 );
2676 102 : maModel.mbBuiltin = rAttribs.hasAttribute( XML_builtinId );
2677 102 : maModel.mbCustom = rAttribs.getBool( XML_customBuiltin, false );
2678 102 : maModel.mbHidden = rAttribs.getBool( XML_hidden, false );
2679 102 : }
2680 :
2681 0 : void CellStyle::importCellStyle( SequenceInputStream& rStrm )
2682 : {
2683 : sal_uInt16 nFlags;
2684 0 : rStrm >> maModel.mnXfId >> nFlags;
2685 0 : maModel.mnBuiltinId = rStrm.readInt8();
2686 0 : maModel.mnLevel = rStrm.readInt8();
2687 0 : rStrm >> maModel.maName;
2688 0 : maModel.mbBuiltin = getFlag( nFlags, BIFF12_CELLSTYLE_BUILTIN );
2689 0 : maModel.mbCustom = getFlag( nFlags, BIFF12_CELLSTYLE_CUSTOM );
2690 0 : maModel.mbHidden = getFlag( nFlags, BIFF12_CELLSTYLE_HIDDEN );
2691 0 : }
2692 :
2693 194 : void CellStyle::createCellStyle()
2694 : {
2695 :
2696 : // #i1624# #i1768# ignore unnamed user styles
2697 194 : if( !mbCreated )
2698 34 : mbCreated = maFinalName.isEmpty();
2699 :
2700 194 : ::ScDocument& rDoc = getScDocument();
2701 194 : if( !mbCreated && !mpStyleSheet )
2702 : {
2703 10 : bool bCreatePattern = false;
2704 10 : Xf* pXF = getStyles().getStyleXf( maModel.mnXfId ).get();
2705 :
2706 10 : bool bDefStyle = maModel.isDefaultStyle();
2707 10 : if( bDefStyle )
2708 : {
2709 : // use existing "Default" style sheet
2710 0 : mpStyleSheet = static_cast< ScStyleSheet* >( static_cast< ScStyleSheetPool* >( rDoc.GetStyleSheetPool() )->Find(
2711 0 : getStyles().getDefaultStyleName(), SFX_STYLE_FAMILY_PARA ) );
2712 : OSL_ENSURE( mpStyleSheet, "CellStyle::createStyle - Default style not found" );
2713 0 : bCreatePattern = true;
2714 : }
2715 : else
2716 : {
2717 10 : mpStyleSheet = static_cast< ScStyleSheet* >( static_cast< ScStyleSheetPool* >( rDoc.GetStyleSheetPool() )->Find( maFinalName, SFX_STYLE_FAMILY_PARA ) );
2718 10 : if( !mpStyleSheet )
2719 : {
2720 10 : mpStyleSheet = &static_cast< ScStyleSheet& >( rDoc.GetStyleSheetPool()->Make( maFinalName, SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_USERDEF ) );
2721 10 : bCreatePattern = true;
2722 : }
2723 : }
2724 :
2725 : // bDefStyle==true omits default pool items in CreatePattern()
2726 10 : if( bCreatePattern && mpStyleSheet && pXF )
2727 10 : mpStyleSheet->GetItemSet().Put( pXF->createPattern( bDefStyle ).GetItemSet() );
2728 : }
2729 194 : }
2730 :
2731 80 : void CellStyle::finalizeImport( const OUString& rFinalName )
2732 : {
2733 80 : maFinalName = rFinalName;
2734 80 : if( !maModel.isBuiltin() || maModel.mbCustom )
2735 10 : createCellStyle();
2736 80 : }
2737 :
2738 : // ============================================================================
2739 :
2740 22 : CellStyleBuffer::CellStyleBuffer( const WorkbookHelper& rHelper ) :
2741 22 : WorkbookHelper( rHelper )
2742 : {
2743 22 : }
2744 :
2745 102 : CellStyleRef CellStyleBuffer::importCellStyle( const AttributeList& rAttribs )
2746 : {
2747 102 : CellStyleRef xCellStyle( new CellStyle( *this ) );
2748 102 : xCellStyle->importCellStyle( rAttribs );
2749 102 : insertCellStyle( xCellStyle );
2750 102 : return xCellStyle;
2751 : }
2752 :
2753 0 : CellStyleRef CellStyleBuffer::importCellStyle( SequenceInputStream& rStrm )
2754 : {
2755 0 : CellStyleRef xCellStyle( new CellStyle( *this ) );
2756 0 : xCellStyle->importCellStyle( rStrm );
2757 0 : insertCellStyle( xCellStyle );
2758 0 : return xCellStyle;
2759 : }
2760 :
2761 22 : void CellStyleBuffer::finalizeImport()
2762 : {
2763 : // calculate final names of all styles
2764 : typedef RefMap< OUString, CellStyle, IgnoreCaseCompare > CellStyleNameMap;
2765 22 : CellStyleNameMap aCellStyles;
2766 22 : CellStyleVector aConflictNameStyles;
2767 :
2768 : /* First, reserve style names that are built-in in Calc. This causes that
2769 : imported cell styles get different unused names and thus do not try to
2770 : overwrite these built-in styles. For BIFF4 workbooks (which contain a
2771 : separate list of cell styles per sheet), reserve all existing styles if
2772 : current sheet is not the first sheet (this styles buffer will be
2773 : constructed again for every new sheet). This will create unique names
2774 : for styles in different sheets with the same name. Assuming that the
2775 : BIFF4W import filter is never used to import from clipboard... */
2776 22 : bool bReserveAll = (getFilterType() == FILTER_BIFF) && (getBiff() == BIFF4) && isWorkbookFile() && (getCurrentSheetIndex() > 0);
2777 : try
2778 : {
2779 : // unfortunately, com.sun.star.style.StyleFamily does not implement XEnumerationAccess...
2780 22 : Reference< XIndexAccess > xStyleFamilyIA( getStyleFamily( false ), UNO_QUERY_THROW );
2781 132 : for( sal_Int32 nIndex = 0, nCount = xStyleFamilyIA->getCount(); nIndex < nCount; ++nIndex )
2782 : {
2783 110 : Reference< XStyle > xStyle( xStyleFamilyIA->getByIndex( nIndex ), UNO_QUERY_THROW );
2784 110 : if( bReserveAll || !xStyle->isUserDefined() )
2785 : {
2786 110 : Reference< XNamed > xStyleName( xStyle, UNO_QUERY_THROW );
2787 : // create an empty entry by using ::std::map<>::operator[]
2788 110 : aCellStyles[ xStyleName->getName() ];
2789 : }
2790 132 : }
2791 : }
2792 0 : catch( Exception& )
2793 : {
2794 : }
2795 :
2796 : /* Calculate names of built-in styles. Store styles with reserved names
2797 : in the aConflictNameStyles list. */
2798 116 : for( CellStyleVector::iterator aIt = maBuiltinStyles.begin(), aEnd = maBuiltinStyles.end(); aIt != aEnd; ++aIt )
2799 : {
2800 94 : const CellStyleModel& rModel = (*aIt)->getModel();
2801 94 : if (rModel.isDefaultStyle())
2802 22 : continue;
2803 :
2804 72 : OUString aStyleName = lclCreateStyleName( rModel );
2805 : /* If a builtin style entry already exists, and we do not reserve all
2806 : existing styles, we just stick with the last definition and ignore
2807 : the preceding ones. */
2808 72 : if( bReserveAll && (aCellStyles.count( aStyleName ) > 0) )
2809 0 : aConflictNameStyles.push_back( *aIt );
2810 : else
2811 72 : aCellStyles[ aStyleName ] = *aIt;
2812 72 : }
2813 :
2814 : /* Calculate names of user defined styles. Store styles with reserved
2815 : names in the aConflictNameStyles list. */
2816 30 : for( CellStyleVector::iterator aIt = maUserStyles.begin(), aEnd = maUserStyles.end(); aIt != aEnd; ++aIt )
2817 : {
2818 8 : const CellStyleModel& rModel = (*aIt)->getModel();
2819 8 : OUString aStyleName = lclCreateStyleName( rModel );
2820 : // #i1624# #i1768# ignore unnamed user styles
2821 8 : if( aStyleName.getLength() > 0 )
2822 : {
2823 8 : if( aCellStyles.count( aStyleName ) > 0 )
2824 8 : aConflictNameStyles.push_back( *aIt );
2825 : else
2826 0 : aCellStyles[ aStyleName ] = *aIt;
2827 : }
2828 8 : }
2829 :
2830 : // find unused names for all styles with conflicting names
2831 30 : for( CellStyleVector::iterator aIt = aConflictNameStyles.begin(), aEnd = aConflictNameStyles.end(); aIt != aEnd; ++aIt )
2832 : {
2833 8 : const CellStyleModel& rModel = (*aIt)->getModel();
2834 8 : OUString aStyleName = lclCreateStyleName( rModel );
2835 8 : OUString aUnusedName;
2836 8 : sal_Int32 nIndex = 0;
2837 8 : do
2838 : {
2839 8 : aUnusedName = OUStringBuffer( aStyleName ).append( sal_Unicode( ' ' ) ).append( ++nIndex ).makeStringAndClear();
2840 : }
2841 8 : while( aCellStyles.count( aUnusedName ) > 0 );
2842 8 : aCellStyles[ aUnusedName ] = *aIt;
2843 8 : }
2844 :
2845 : // set final names and create user-defined and modified built-in cell styles
2846 22 : aCellStyles.forEachMemWithKey( &CellStyle::finalizeImport );
2847 :
2848 22 : if (mxDefStyle)
2849 : {
2850 22 : Reference<XNameAccess> xNA(getStyleFamily(false), UNO_QUERY_THROW);
2851 22 : if (xNA->hasByName("Default"))
2852 : {
2853 22 : PropertySet aPropSet(xNA->getByName("Default"));
2854 22 : getStyles().writeStyleXfToPropertySet(aPropSet, mxDefStyle->getModel().mnXfId);
2855 22 : }
2856 22 : }
2857 22 : }
2858 :
2859 98 : sal_Int32 CellStyleBuffer::getDefaultXfId() const
2860 : {
2861 98 : return mxDefStyle.get() ? mxDefStyle->getModel().mnXfId : -1;
2862 : }
2863 :
2864 50 : OUString CellStyleBuffer::getDefaultStyleName() const
2865 : {
2866 50 : return createCellStyle( mxDefStyle );
2867 : }
2868 :
2869 134 : OUString CellStyleBuffer::createCellStyle( sal_Int32 nXfId ) const
2870 : {
2871 134 : return createCellStyle( maStylesByXf.get( nXfId ) );
2872 : }
2873 :
2874 76 : ::ScStyleSheet* CellStyleBuffer::getCellStyleSheet( sal_Int32 nXfId ) const
2875 : {
2876 76 : return getCellStyleSheet( maStylesByXf.get( nXfId ) );
2877 : }
2878 :
2879 : // private --------------------------------------------------------------------
2880 :
2881 102 : void CellStyleBuffer::insertCellStyle( CellStyleRef xCellStyle )
2882 : {
2883 102 : const CellStyleModel& rModel = xCellStyle->getModel();
2884 102 : if( rModel.mnXfId >= 0 )
2885 : {
2886 : // insert into the built-in map or user defined map
2887 102 : (rModel.isBuiltin() ? maBuiltinStyles : maUserStyles).push_back( xCellStyle );
2888 :
2889 : // insert into the XF identifier map
2890 : OSL_ENSURE( maStylesByXf.count( rModel.mnXfId ) == 0, "CellStyleBuffer::insertCellStyle - multiple styles with equal XF identifier" );
2891 102 : maStylesByXf[ rModel.mnXfId ] = xCellStyle;
2892 :
2893 : // remember default cell style
2894 102 : if( rModel.isDefaultStyle() )
2895 22 : mxDefStyle = xCellStyle;
2896 : }
2897 102 : }
2898 :
2899 76 : ::ScStyleSheet* CellStyleBuffer::getCellStyleSheet( const CellStyleRef& rxCellStyle ) const
2900 : {
2901 76 : ::ScStyleSheet* pStyleSheet = NULL;
2902 76 : if ( rxCellStyle.get() )
2903 76 : pStyleSheet = rxCellStyle->getStyleSheet();
2904 76 : return pStyleSheet;
2905 : }
2906 :
2907 184 : OUString CellStyleBuffer::createCellStyle( const CellStyleRef& rxCellStyle ) const
2908 : {
2909 184 : if( rxCellStyle.get() )
2910 : {
2911 184 : rxCellStyle->createCellStyle();
2912 184 : const OUString& rStyleName = rxCellStyle->getFinalStyleName();
2913 184 : if( !rStyleName.isEmpty() )
2914 2 : return rStyleName;
2915 : }
2916 : // on error: fallback to default style
2917 182 : return lclGetBuiltinStyleName( OOX_STYLE_NORMAL, OUString() );
2918 : }
2919 :
2920 : // ============================================================================
2921 :
2922 0 : AutoFormatModel::AutoFormatModel() :
2923 : mnAutoFormatId( 0 ),
2924 : mbApplyNumFmt( false ),
2925 : mbApplyFont( false ),
2926 : mbApplyAlignment( false ),
2927 : mbApplyBorder( false ),
2928 : mbApplyFill( false ),
2929 0 : mbApplyProtection( false )
2930 : {
2931 0 : }
2932 :
2933 : // ============================================================================
2934 :
2935 22 : StylesBuffer::StylesBuffer( const WorkbookHelper& rHelper ) :
2936 : WorkbookHelper( rHelper ),
2937 : maPalette( rHelper ),
2938 : maNumFmts( rHelper ),
2939 22 : maCellStyles( rHelper )
2940 : {
2941 22 : }
2942 :
2943 90 : FontRef StylesBuffer::createFont( sal_Int32* opnFontId )
2944 : {
2945 90 : if( opnFontId ) *opnFontId = static_cast< sal_Int32 >( maFonts.size() );
2946 90 : FontRef xFont( new Font( *this, false ) );
2947 90 : maFonts.push_back( xFont );
2948 90 : return xFont;
2949 : }
2950 :
2951 140 : NumberFormatRef StylesBuffer::createNumFmt( sal_Int32 nNumFmtId, const OUString& rFmtCode )
2952 : {
2953 140 : return maNumFmts.createNumFmt( nNumFmtId, rFmtCode );
2954 : }
2955 :
2956 140 : sal_Int32 StylesBuffer::nextFreeNumFmtId()
2957 : {
2958 140 : return maNumFmts.nextFreeId();
2959 : }
2960 :
2961 22 : BorderRef StylesBuffer::createBorder( sal_Int32* opnBorderId )
2962 : {
2963 22 : if( opnBorderId ) *opnBorderId = static_cast< sal_Int32 >( maBorders.size() );
2964 22 : BorderRef xBorder( new Border( *this, false ) );
2965 22 : maBorders.push_back( xBorder );
2966 22 : return xBorder;
2967 : }
2968 :
2969 48 : FillRef StylesBuffer::createFill( sal_Int32* opnFillId )
2970 : {
2971 48 : if( opnFillId ) *opnFillId = static_cast< sal_Int32 >( maFills.size() );
2972 48 : FillRef xFill( new Fill( *this, false ) );
2973 48 : maFills.push_back( xFill );
2974 48 : return xFill;
2975 : }
2976 :
2977 76 : XfRef StylesBuffer::createCellXf( sal_Int32* opnXfId )
2978 : {
2979 76 : if( opnXfId ) *opnXfId = static_cast< sal_Int32 >( maCellXfs.size() );
2980 76 : XfRef xXf( new Xf( *this ) );
2981 76 : maCellXfs.push_back( xXf );
2982 76 : return xXf;
2983 : }
2984 :
2985 298 : XfRef StylesBuffer::createStyleXf( sal_Int32* opnXfId )
2986 : {
2987 298 : if( opnXfId ) *opnXfId = static_cast< sal_Int32 >( maStyleXfs.size() );
2988 298 : XfRef xXf( new Xf( *this ) );
2989 298 : maStyleXfs.push_back( xXf );
2990 298 : return xXf;
2991 : }
2992 :
2993 140 : DxfRef StylesBuffer::createDxf( sal_Int32* opnDxfId )
2994 : {
2995 140 : if( opnDxfId ) *opnDxfId = static_cast< sal_Int32 >( maDxfs.size() );
2996 140 : DxfRef xDxf( new Dxf( *this ) );
2997 140 : maDxfs.push_back( xDxf );
2998 140 : return xDxf;
2999 : }
3000 :
3001 112 : void StylesBuffer::importPaletteColor( const AttributeList& rAttribs )
3002 : {
3003 112 : maPalette.importPaletteColor( rAttribs );
3004 112 : }
3005 :
3006 58 : NumberFormatRef StylesBuffer::importNumFmt( const AttributeList& rAttribs )
3007 : {
3008 58 : return maNumFmts.importNumFmt( rAttribs );
3009 : }
3010 :
3011 102 : CellStyleRef StylesBuffer::importCellStyle( const AttributeList& rAttribs )
3012 : {
3013 102 : return maCellStyles.importCellStyle( rAttribs );
3014 : }
3015 :
3016 0 : void StylesBuffer::importPaletteColor( SequenceInputStream& rStrm )
3017 : {
3018 0 : maPalette.importPaletteColor( rStrm );
3019 0 : }
3020 :
3021 0 : void StylesBuffer::importNumFmt( SequenceInputStream& rStrm )
3022 : {
3023 0 : maNumFmts.importNumFmt( rStrm );
3024 0 : }
3025 :
3026 0 : void StylesBuffer::importCellStyle( SequenceInputStream& rStrm )
3027 : {
3028 0 : maCellStyles.importCellStyle( rStrm );
3029 0 : }
3030 :
3031 22 : void StylesBuffer::finalizeImport()
3032 : {
3033 : // fonts first, are needed to finalize unit converter and XFs below
3034 22 : maFonts.forEachMem( &Font::finalizeImport );
3035 : // finalize unit coefficients after default font is known
3036 22 : getUnitConverter().finalizeImport();
3037 : // number formats
3038 22 : maNumFmts.finalizeImport();
3039 : // borders and fills
3040 22 : maBorders.forEachMem( &Border::finalizeImport );
3041 22 : maFills.forEachMem( &Fill::finalizeImport );
3042 : // style XFs and cell XFs
3043 22 : maStyleXfs.forEachMem( &Xf::finalizeImport );
3044 22 : maCellXfs.forEachMem( &Xf::finalizeImport );
3045 : // built-in and user defined cell styles
3046 22 : maCellStyles.finalizeImport();
3047 : // differential formatting (for conditional formatting)
3048 22 : maDxfs.forEachMem( &Dxf::finalizeImport );
3049 22 : }
3050 :
3051 132 : sal_Int32 StylesBuffer::getPaletteColor( sal_Int32 nPaletteIdx ) const
3052 : {
3053 132 : return maPalette.getColor( nPaletteIdx );
3054 : }
3055 :
3056 218 : FontRef StylesBuffer::getFont( sal_Int32 nFontId ) const
3057 : {
3058 218 : return maFonts.get( nFontId );
3059 : }
3060 :
3061 108 : BorderRef StylesBuffer::getBorder( sal_Int32 nBorderId ) const
3062 : {
3063 108 : return maBorders.get( nBorderId );
3064 : }
3065 :
3066 1128 : XfRef StylesBuffer::getCellXf( sal_Int32 nXfId ) const
3067 : {
3068 1128 : return maCellXfs.get( nXfId );
3069 : }
3070 :
3071 184 : XfRef StylesBuffer::getStyleXf( sal_Int32 nXfId ) const
3072 : {
3073 184 : return maStyleXfs.get( nXfId );
3074 : }
3075 :
3076 156 : FontRef StylesBuffer::getFontFromCellXf( sal_Int32 nXfId ) const
3077 : {
3078 156 : FontRef xFont;
3079 156 : if( const Xf* pXf = getCellXf( nXfId ).get() )
3080 120 : xFont = pXf->getFont();
3081 156 : return xFont;
3082 : }
3083 :
3084 98 : FontRef StylesBuffer::getDefaultFont() const
3085 : {
3086 98 : FontRef xDefFont;
3087 98 : if( const Xf* pXf = getStyleXf( maCellStyles.getDefaultXfId() ).get() )
3088 98 : xDefFont = pXf->getFont();
3089 : // no font from styles - try first loaded font (e.g. BIFF2)
3090 98 : if( !xDefFont )
3091 0 : xDefFont = maFonts.get( 0 );
3092 : OSL_ENSURE( xDefFont.get(), "StylesBuffer::getDefaultFont - no default font found" );
3093 98 : return xDefFont;
3094 : }
3095 :
3096 76 : const FontModel& StylesBuffer::getDefaultFontModel() const
3097 : {
3098 76 : FontRef xDefFont = getDefaultFont();
3099 76 : return xDefFont.get() ? xDefFont->getModel() : getTheme().getDefaultFontModel();
3100 : }
3101 :
3102 76 : bool StylesBuffer::equalBorders( sal_Int32 nBorderId1, sal_Int32 nBorderId2 ) const
3103 : {
3104 76 : if( nBorderId1 == nBorderId2 )
3105 76 : return true;
3106 :
3107 0 : switch( getFilterType() )
3108 : {
3109 : case FILTER_OOXML:
3110 : // in OOXML, borders are assumed to be unique
3111 0 : return false;
3112 :
3113 : case FILTER_BIFF:
3114 : {
3115 : // in BIFF, a new border entry has been created for every XF
3116 0 : const Border* pBorder1 = maBorders.get( nBorderId1 ).get();
3117 0 : const Border* pBorder2 = maBorders.get( nBorderId2 ).get();
3118 0 : return pBorder1 && pBorder2 && (pBorder1->getApiData() == pBorder2->getApiData());
3119 : }
3120 :
3121 : case FILTER_UNKNOWN:
3122 0 : break;
3123 : }
3124 0 : return false;
3125 : }
3126 :
3127 76 : bool StylesBuffer::equalFills( sal_Int32 nFillId1, sal_Int32 nFillId2 ) const
3128 : {
3129 76 : if( nFillId1 == nFillId2 )
3130 74 : return true;
3131 :
3132 2 : switch( getFilterType() )
3133 : {
3134 : case FILTER_OOXML:
3135 : // in OOXML, fills are assumed to be unique
3136 2 : return false;
3137 :
3138 : case FILTER_BIFF:
3139 : {
3140 : // in BIFF, a new fill entry has been created for every XF
3141 0 : const Fill* pFill1 = maFills.get( nFillId1 ).get();
3142 0 : const Fill* pFill2 = maFills.get( nFillId2 ).get();
3143 0 : return pFill1 && pFill2 && (pFill1->getApiData() == pFill2->getApiData());
3144 : }
3145 :
3146 : case FILTER_UNKNOWN:
3147 0 : break;
3148 : }
3149 0 : return false;
3150 : }
3151 :
3152 50 : OUString StylesBuffer::getDefaultStyleName() const
3153 : {
3154 50 : return maCellStyles.getDefaultStyleName();
3155 : }
3156 :
3157 134 : OUString StylesBuffer::createCellStyle( sal_Int32 nXfId ) const
3158 : {
3159 134 : return maCellStyles.createCellStyle( nXfId );
3160 : }
3161 :
3162 76 : ::ScStyleSheet* StylesBuffer::getCellStyleSheet( sal_Int32 nXfId ) const
3163 : {
3164 76 : return maCellStyles.getCellStyleSheet( nXfId );
3165 : }
3166 :
3167 72 : OUString StylesBuffer::createDxfStyle( sal_Int32 nDxfId ) const
3168 : {
3169 72 : OUString& rStyleName = maDxfStyles[ nDxfId ];
3170 72 : if( rStyleName.isEmpty() )
3171 : {
3172 72 : if( Dxf* pDxf = maDxfs.get( nDxfId ).get() )
3173 : {
3174 72 : rStyleName = OUStringBuffer( "ConditionalStyle_" ).append( nDxfId + 1 ).makeStringAndClear();
3175 : // create the style sheet (this may change rStyleName if such a style already exists)
3176 72 : Reference< XStyle > xStyle = createStyleObject( rStyleName, false );
3177 : // write style formatting properties
3178 72 : PropertySet aPropSet( xStyle );
3179 72 : pDxf->writeToPropertySet( aPropSet );
3180 : }
3181 : // on error: fallback to default style
3182 72 : if( rStyleName.isEmpty() )
3183 0 : rStyleName = maCellStyles.getDefaultStyleName();
3184 : }
3185 72 : return rStyleName;
3186 : }
3187 :
3188 330 : void StylesBuffer::writeFontToItemSet( SfxItemSet& rItemSet, sal_Int32 nFontId, bool bSkipPoolDefs ) const
3189 : {
3190 330 : if( Font* pFont = maFonts.get( nFontId ).get() )
3191 330 : pFont->fillToItemSet( rItemSet, FONT_PROPTYPE_CELL, bSkipPoolDefs );
3192 330 : }
3193 :
3194 22 : void StylesBuffer::writeFontToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFontId ) const
3195 : {
3196 22 : if( Font* pFont = maFonts.get( nFontId ).get() )
3197 22 : pFont->writeToPropertyMap( rPropMap, FONT_PROPTYPE_CELL );
3198 22 : }
3199 :
3200 322 : void StylesBuffer::writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs ) const
3201 : {
3202 322 : maNumFmts.fillToItemSet( rItemSet, nNumFmtId, bSkipPoolDefs );
3203 322 : }
3204 :
3205 22 : void StylesBuffer::writeNumFmtToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const
3206 : {
3207 22 : maNumFmts.writeToPropertyMap( rPropMap, nNumFmtId );
3208 22 : }
3209 :
3210 32 : void StylesBuffer::writeBorderToItemSet( SfxItemSet& rItemSet, sal_Int32 nBorderId, bool bSkipPoolDefs ) const
3211 : {
3212 32 : if( Border* pBorder = maBorders.get( nBorderId ).get() )
3213 32 : pBorder->fillToItemSet( rItemSet, bSkipPoolDefs );
3214 32 : }
3215 :
3216 22 : void StylesBuffer::writeBorderToPropertyMap( PropertyMap& rPropMap, sal_Int32 nBorderId ) const
3217 : {
3218 22 : if( Border* pBorder = maBorders.get( nBorderId ).get() )
3219 22 : pBorder->writeToPropertyMap( rPropMap );
3220 22 : }
3221 :
3222 300 : void StylesBuffer::writeFillToItemSet( SfxItemSet& rItemSet, sal_Int32 nFillId, bool bSkipPoolDefs ) const
3223 : {
3224 300 : if( Fill* pFill = maFills.get( nFillId ).get() )
3225 300 : pFill->fillToItemSet( rItemSet, bSkipPoolDefs );
3226 300 : }
3227 :
3228 22 : void StylesBuffer::writeFillToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFillId ) const
3229 : {
3230 22 : if( Fill* pFill = maFills.get( nFillId ).get() )
3231 22 : pFill->writeToPropertyMap( rPropMap );
3232 22 : }
3233 :
3234 126 : void StylesBuffer::writeCellXfToMarkData( ScMarkData& rMark, sal_Int32 nXfId, sal_Int32 nNumFmtId )
3235 : {
3236 126 : if( Xf* pXf = maCellXfs.get( nXfId ).get() )
3237 76 : pXf->writeToMarkData( rMark, nNumFmtId );
3238 126 : }
3239 :
3240 240 : bool operator==( const XfModel& rXfModel1, const XfModel& rXfModel2 )
3241 : {
3242 : return ( rXfModel1.mbCellXf == rXfModel2.mbCellXf &&
3243 : rXfModel1.mnStyleXfId == rXfModel2.mnStyleXfId &&
3244 : rXfModel1.mbFontUsed == rXfModel2.mbFontUsed &&
3245 : rXfModel1.mnFontId == rXfModel2.mnFontId &&
3246 : rXfModel1.mbNumFmtUsed == rXfModel2.mbNumFmtUsed &&
3247 : rXfModel1.mnNumFmtId == rXfModel2.mnNumFmtId &&
3248 : rXfModel1.mbAlignUsed == rXfModel2.mbAlignUsed &&
3249 : rXfModel1.mbBorderUsed == rXfModel2.mbBorderUsed &&
3250 : rXfModel1.mnBorderId == rXfModel2.mnBorderId &&
3251 : rXfModel1.mbAreaUsed == rXfModel2.mbAreaUsed &&
3252 : rXfModel1.mnFillId == rXfModel2.mnFillId &&
3253 240 : rXfModel1.mbProtUsed == rXfModel2.mbProtUsed );
3254 : }
3255 :
3256 240 : bool operator==( const Xf& rXf1, const Xf& rXf2 )
3257 : {
3258 240 : if ( rXf1.maModel == rXf2.maModel )
3259 : {
3260 12 : if ( rXf1.maModel.mbAlignUsed )
3261 : {
3262 12 : if ( !( rXf1.maAlignment.getApiData() == rXf2.maAlignment.getApiData() ) )
3263 12 : return false;
3264 : }
3265 0 : if ( rXf1.maModel.mbProtUsed )
3266 : {
3267 0 : if ( !( rXf1.maProtection.getApiData() == rXf2.maProtection.getApiData() ) )
3268 0 : return false;
3269 : }
3270 0 : return true;
3271 : }
3272 228 : return false;
3273 : }
3274 :
3275 64 : void StylesBuffer::writeCellXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const
3276 : {
3277 64 : if( Xf* pXf = maCellXfs.get( nXfId ).get() )
3278 58 : pXf->writeToPropertySet( rPropSet );
3279 64 : }
3280 :
3281 22 : bool StylesBuffer::hasBorder( sal_Int32 nBorderId ) const
3282 : {
3283 22 : Border* pBorder = maBorders.get( nBorderId ).get();
3284 22 : return pBorder && pBorder->hasBorder();
3285 : }
3286 :
3287 22 : void StylesBuffer::writeStyleXfToPropertySet( PropertySet& rPropSet, sal_Int32 nXfId ) const
3288 : {
3289 22 : if( Xf* pXf = maStyleXfs.get( nXfId ).get() )
3290 22 : pXf->writeToPropertySet( rPropSet );
3291 22 : }
3292 :
3293 : // ============================================================================
3294 :
3295 : } // namespace xls
3296 24 : } // namespace oox
3297 :
3298 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|