LibreOffice Module sc (master) 1
stylesbuffer.cxx
Go to the documentation of this file.
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/sheet/XSpreadsheetDocument.hpp>
34#include <com/sun/star/style/XStyle.hpp>
35#include <com/sun/star/text/WritingMode2.hpp>
36#include <com/sun/star/table/BorderLineStyle.hpp>
37#include <com/sun/star/table/CellVertJustify2.hpp>
38#include <com/sun/star/table/CellJustifyMethod.hpp>
41#include <editeng/fontitem.hxx>
42#include <editeng/postitem.hxx>
43#include <editeng/fhgtitem.hxx>
44#include <editeng/wghtitem.hxx>
45#include <editeng/udlnitem.hxx>
46#include <editeng/colritem.hxx>
50#include <editeng/shdditem.hxx>
51#include <editeng/eeitem.hxx>
53#include <editeng/boxitem.hxx>
54#include <editeng/lineitem.hxx>
55#include <editeng/brushitem.hxx>
56#include <svx/rotmodit.hxx>
57#include <tools/fontenum.hxx>
59#include <utility>
60#include <vcl/unohelp.hxx>
61#include <rtl/tencinfo.h>
62#include <rtl/ustrbuf.hxx>
63#include <sal/log.hxx>
64#include <osl/diagnose.h>
71#include <oox/token/namespaces.hxx>
72#include <oox/token/properties.hxx>
73#include <oox/token/tokens.hxx>
74#include <themebuffer.hxx>
75#include <unitconverter.hxx>
76#include <document.hxx>
77#include <stlpool.hxx>
78#include <docpool.hxx>
79#include <ftools.hxx>
80#include <scitems.hxx>
81#include <attrib.hxx>
82#include <globstr.hrc>
83#include <scresid.hxx>
84#include <documentimport.hxx>
85#include <patattr.hxx>
86#include <stlsheet.hxx>
87#include <biffhelper.hxx>
88
89namespace oox::xls {
90
91using namespace ::com::sun::star::awt;
92using namespace ::com::sun::star::container;
93using namespace ::com::sun::star::style;
94using namespace ::com::sun::star::table;
95using namespace ::com::sun::star::text;
96using namespace ::com::sun::star::uno;
97
98
99namespace {
100
101// OOXML constants ------------------------------------------------------------
102
103// OOXML predefined color indexes (also used in BIFF3-BIFF8)
104const sal_Int32 OOX_COLOR_USEROFFSET = 0;
105
106// OOXML font family (also used in BIFF)
107const sal_Int32 OOX_FONTFAMILY_NONE = 0;
108const sal_Int32 OOX_FONTFAMILY_ROMAN = 1;
109const sal_Int32 OOX_FONTFAMILY_SWISS = 2;
110const sal_Int32 OOX_FONTFAMILY_MODERN = 3;
111const sal_Int32 OOX_FONTFAMILY_SCRIPT = 4;
112const sal_Int32 OOX_FONTFAMILY_DECORATIVE = 5;
113
114// OOXML cell text direction (also used in BIFF)
115const sal_Int32 OOX_XF_TEXTDIR_CONTEXT = 0;
116const sal_Int32 OOX_XF_TEXTDIR_LTR = 1;
117const sal_Int32 OOX_XF_TEXTDIR_RTL = 2;
118
119// OOXML cell rotation (also used in BIFF)
120const sal_Int32 OOX_XF_ROTATION_NONE = 0;
121const sal_Int32 OOX_XF_ROTATION_STACKED = 255;
122
123// OOXML cell indentation
124const sal_Int32 OOX_XF_INDENT_NONE = 0;
125
126// OOXML built-in cell styles (also used in BIFF)
127const sal_Int32 OOX_STYLE_NORMAL = 0;
128const sal_Int32 OOX_STYLE_ROWLEVEL = 1;
129const sal_Int32 OOX_STYLE_COLLEVEL = 2;
130
131// BIFF12 constants -----------------------------------------------------------
132
133// BIFF12 color types
134const sal_uInt8 BIFF12_COLOR_AUTO = 0;
135const sal_uInt8 BIFF12_COLOR_INDEXED = 1;
136const sal_uInt8 BIFF12_COLOR_RGB = 2;
137const sal_uInt8 BIFF12_COLOR_THEME = 3;
138
139// BIFF12 diagonal borders
140const sal_uInt8 BIFF12_BORDER_DIAG_TLBR = 0x01;
141const sal_uInt8 BIFF12_BORDER_DIAG_BLTR = 0x02;
142
143// BIFF12 gradient fill
144const sal_Int32 BIFF12_FILL_GRADIENT = 40;
145
146// BIFF12 XF flags
147const sal_uInt32 BIFF12_XF_WRAPTEXT = 0x00400000;
148const sal_uInt32 BIFF12_XF_JUSTLASTLINE = 0x00800000;
149const sal_uInt32 BIFF12_XF_SHRINK = 0x01000000;
150const sal_uInt32 BIFF12_XF_LOCKED = 0x10000000;
151const sal_uInt32 BIFF12_XF_HIDDEN = 0x20000000;
152
153// BIFF12 XF attribute used flags
154const sal_uInt16 BIFF12_XF_NUMFMT_USED = 0x0001;
155const sal_uInt16 BIFF12_XF_FONT_USED = 0x0002;
156const sal_uInt16 BIFF12_XF_ALIGN_USED = 0x0004;
157const sal_uInt16 BIFF12_XF_BORDER_USED = 0x0008;
158const sal_uInt16 BIFF12_XF_AREA_USED = 0x0010;
159const sal_uInt16 BIFF12_XF_PROT_USED = 0x0020;
160
161// BIFF12 DXF constants
162const sal_uInt16 BIFF12_DXF_FILL_PATTERN = 0;
163const sal_uInt16 BIFF12_DXF_FILL_FGCOLOR = 1;
164const sal_uInt16 BIFF12_DXF_FILL_BGCOLOR = 2;
165const sal_uInt16 BIFF12_DXF_FILL_GRADIENT = 3;
166const sal_uInt16 BIFF12_DXF_FILL_STOP = 4;
167const sal_uInt16 BIFF12_DXF_FONT_COLOR = 5;
168const sal_uInt16 BIFF12_DXF_BORDER_TOP = 6;
169const sal_uInt16 BIFF12_DXF_BORDER_BOTTOM = 7;
170const sal_uInt16 BIFF12_DXF_BORDER_LEFT = 8;
171const sal_uInt16 BIFF12_DXF_BORDER_RIGHT = 9;
172const sal_uInt16 BIFF12_DXF_FONT_NAME = 24;
173const sal_uInt16 BIFF12_DXF_FONT_WEIGHT = 25;
174const sal_uInt16 BIFF12_DXF_FONT_UNDERLINE = 26;
175const sal_uInt16 BIFF12_DXF_FONT_ESCAPEMENT = 27;
176const sal_uInt16 BIFF12_DXF_FONT_ITALIC = 28;
177const sal_uInt16 BIFF12_DXF_FONT_STRIKE = 29;
178const sal_uInt16 BIFF12_DXF_FONT_OUTLINE = 30;
179const sal_uInt16 BIFF12_DXF_FONT_SHADOW = 31;
180const sal_uInt16 BIFF12_DXF_FONT_HEIGHT = 36;
181const sal_uInt16 BIFF12_DXF_FONT_SCHEME = 37;
182const sal_uInt16 BIFF12_DXF_NUMFMT_CODE = 38;
183const sal_uInt16 BIFF12_DXF_NUMFMT_ID = 41;
184
185// BIFF12 CELLSTYLE flags
186const sal_uInt16 BIFF12_CELLSTYLE_BUILTIN = 0x0001;
187const sal_uInt16 BIFF12_CELLSTYLE_HIDDEN = 0x0002;
188const sal_uInt16 BIFF12_CELLSTYLE_CUSTOM = 0x0004;
189
190// BIFF constants -------------------------------------------------------------
191
192// BIFF font flags, also used in BIFF12
193const sal_uInt16 BIFF_FONTFLAG_ITALIC = 0x0002;
194const sal_uInt16 BIFF_FONTFLAG_STRIKEOUT = 0x0008;
195const sal_uInt16 BIFF_FONTFLAG_OUTLINE = 0x0010;
196const sal_uInt16 BIFF_FONTFLAG_SHADOW = 0x0020;
197
198// BIFF font weight
199const sal_uInt16 BIFF_FONTWEIGHT_BOLD = 450;
200
201// BIFF font underline, also used in BIFF12
202const sal_uInt8 BIFF_FONTUNDERL_NONE = 0;
203const sal_uInt8 BIFF_FONTUNDERL_SINGLE = 1;
204const sal_uInt8 BIFF_FONTUNDERL_DOUBLE = 2;
205const sal_uInt8 BIFF_FONTUNDERL_SINGLE_ACC = 33;
206const sal_uInt8 BIFF_FONTUNDERL_DOUBLE_ACC = 34;
207
208::Color lclReadRgbColor( BinaryInputStream& rStrm )
209{
210 sal_uInt8 nR, nG, nB, nA;
211 nR = rStrm.readuChar();
212 nG = rStrm.readuChar();
213 nB = rStrm.readuChar();
214 nA = rStrm.readuChar();
215 sal_Int32 nValue = nA;
216 nValue <<= 8;
217 nValue |= nR;
218 nValue <<= 8;
219 nValue |= nG;
220 nValue <<= 8;
221 nValue |= nB;
222 return ::Color(ColorTransparency, nValue);
223}
224
225} // namespace
226
228 GraphicHelper( rHelper.getBaseFilter().getComponentContext(), rHelper.getBaseFilter().getTargetFrame(), rHelper.getBaseFilter().getStorage() ),
229 WorkbookHelper( rHelper )
230{
231}
232
234{
235 return getTheme().getColorByToken( nToken );
236}
237
238::Color ExcelGraphicHelper::getPaletteColor( sal_Int32 nPaletteIdx ) const
239{
240 return getStyles().getPaletteColor( nPaletteIdx );
241}
242
244{
246 setSchemeClr( XML_phClr );
247}
248
249void Color::setRgb( ::Color nRgbValue, double fTint )
250{
252 setSrgbClr( sal_uInt32(nRgbValue) & 0xFFFFFF );
253 if( fTint != 0.0 ) addExcelTintTransformation( fTint );
254}
255
256void Color::setTheme( sal_Int32 nThemeIdx, double fTint )
257{
259 static const sal_Int32 spnColorTokens[] = {
260 XML_lt1, XML_dk1, XML_lt2, XML_dk2, XML_accent1, XML_accent2,
261 XML_accent3, XML_accent4, XML_accent5, XML_accent6, XML_hlink, XML_folHlink };
262 setSchemeClr( STATIC_ARRAY_SELECT( spnColorTokens, nThemeIdx, XML_TOKEN_INVALID ) );
263 if( fTint != 0.0 ) addExcelTintTransformation( fTint );
264}
265
266void Color::setIndexed( sal_Int32 nPaletteIdx, double fTint )
267{
269 setPaletteClr( nPaletteIdx );
270 if( fTint != 0.0 ) addExcelTintTransformation( fTint );
271}
272
273void Color::importColor( const AttributeList& rAttribs )
274{
275 // tdf#113271 The order of import color is very important in case of more than one color attributes was provided.
276 // This order (theme -> rgb -> indexed -> auto) is not documented and was gathered experimentally based on MS Excel 2013.
277 if( rAttribs.hasAttribute( XML_theme ) )
278 setTheme( rAttribs.getInteger( XML_theme, -1 ), rAttribs.getDouble( XML_tint, 0.0 ) );
279 else if( rAttribs.hasAttribute( XML_rgb ) )
280 setRgb( ::Color(ColorTransparency, rAttribs.getIntegerHex( XML_rgb, sal_Int32(API_RGB_TRANSPARENT) ) ), rAttribs.getDouble( XML_tint, 0.0 ) );
281 else if( rAttribs.hasAttribute( XML_indexed ) )
282 setIndexed( rAttribs.getInteger( XML_indexed, -1 ), rAttribs.getDouble( XML_tint, 0.0 ) );
283 else if( rAttribs.getBool( XML_auto, false ) )
284 setAuto();
285 else
286 {
287 OSL_FAIL( "Color::importColor - unknown color type" );
288 setAuto();
289 }
290}
291
293{
294 sal_uInt8 nFlags, nIndex;
295 sal_Int16 nTint;
296 nFlags = rStrm.readuChar();
297 nIndex = rStrm.readuChar();
298 nTint = rStrm.readInt16();
299
300 // scale tint from signed 16-bit to double range -1.0 ... 1.0
301 double fTint = nTint;
302 if( nTint < 0 )
303 fTint /= -SAL_MIN_INT16;
304 else if( nTint > 0 )
305 fTint /= SAL_MAX_INT16;
306
307 switch( extractValue< sal_uInt8 >( nFlags, 1, 7 ) )
308 {
309 case BIFF12_COLOR_AUTO:
310 setAuto();
311 rStrm.skip( 4 );
312 break;
313 case BIFF12_COLOR_INDEXED:
314 setIndexed( nIndex, fTint );
315 rStrm.skip( 4 );
316 break;
317 case BIFF12_COLOR_RGB:
318 setRgb( lclReadRgbColor( rStrm ), fTint );
319 break;
320 case BIFF12_COLOR_THEME:
321 setTheme( nIndex, fTint );
322 rStrm.skip( 4 );
323 break;
324 default:
325 OSL_FAIL( "Color::importColor - unknown color type" );
326 setAuto();
327 rStrm.skip( 4 );
328 }
329}
330
332{
333 setIndexed( rStrm.readInt32() );
334}
335
337{
338 orColor.importColor( rStrm );
339 return rStrm;
340}
341
342namespace {
343
345#define PALETTE_EGA_COLORS_LIGHT \
346 ::Color(0x000000), ::Color(0xFFFFFF), ::Color(0xFF0000), ::Color(0x00FF00), ::Color(0x0000FF), ::Color(0xFFFF00), ::Color(0xFF00FF), ::Color(0x00FFFF)
348#define PALETTE_EGA_COLORS_DARK \
349 ::Color(0x800000), ::Color(0x008000), ::Color(0x000080), ::Color(0x808000), ::Color(0x800080), ::Color(0x008080), ::Color(0xC0C0C0), ::Color(0x808080)
350
352const ::Color spnDefColors8[] =
353{
357/* 24 */ ::Color(0x9999FF), ::Color(0x993366), ::Color(0xFFFFCC), ::Color(0xCCFFFF), ::Color(0x660066), ::Color(0xFF8080), ::Color(0x0066CC), ::Color(0xCCCCFF),
358/* 32 */ ::Color(0x000080), ::Color(0xFF00FF), ::Color(0xFFFF00), ::Color(0x00FFFF), ::Color(0x800080), ::Color(0x800000), ::Color(0x008080), ::Color(0x0000FF),
359/* 40 */ ::Color(0x00CCFF), ::Color(0xCCFFFF), ::Color(0xCCFFCC), ::Color(0xFFFF99), ::Color(0x99CCFF), ::Color(0xFF99CC), ::Color(0xCC99FF), ::Color(0xFFCC99),
360/* 48 */ ::Color(0x3366FF), ::Color(0x33CCCC), ::Color(0x99CC00), ::Color(0xFFCC00), ::Color(0xFF9900), ::Color(0xFF6600), ::Color(0x666699), ::Color(0x969696),
361/* 56 */ ::Color(0x003366), ::Color(0x339966), ::Color(0x003300), ::Color(0x333300), ::Color(0x993300), ::Color(0x993366), ::Color(0x333399), ::Color(0x333333)
362};
363
364#undef PALETTE_EGA_COLORS_LIGHT
365#undef PALETTE_EGA_COLORS_DARK
366
367} // namespace
368
370 : WorkbookHelper(rHelper)
371 , mnAppendIndex(0)
372{
373 // default colors
374 maColors.insert( maColors.begin(), spnDefColors8, spnDefColors8 + SAL_N_ELEMENTS(spnDefColors8) );
375 mnAppendIndex = OOX_COLOR_USEROFFSET;
376}
377
379{
380 appendColor( ::Color(ColorTransparency, rAttribs.getIntegerHex( XML_rgb, sal_Int32(API_RGB_WHITE) ) ) );
381}
382
384{
385 ::Color nRgb = lclReadRgbColor( rStrm );
386 appendColor( nRgb );
387}
388
389::Color ColorPalette::getColor( sal_Int32 nPaletteIdx ) const
390{
392 if( const ::Color* pnPaletteColor = ContainerHelper::getVectorElement( maColors, nPaletteIdx ) )
393 {
394 nColor = *pnPaletteColor;
395 }
396 else switch( nPaletteIdx )
397 {
400 case OOX_COLOR_CHWINDOWTEXT: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_windowText ); break;
403 case OOX_COLOR_CHWINDOWBACK: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_window ); break;
404 case OOX_COLOR_BUTTONBACK: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_btnFace ); break;
405 case OOX_COLOR_CHBORDERAUTO: nColor = API_RGB_BLACK; /* really always black? */ break;
406 case OOX_COLOR_NOTEBACK: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_infoBk ); break;
407 case OOX_COLOR_NOTETEXT: nColor = getBaseFilter().getGraphicHelper().getSystemColor( XML_infoText ); break;
408 case OOX_COLOR_FONTAUTO: nColor = API_RGB_TRANSPARENT; break;
409 default: OSL_FAIL( "ColorPalette::getColor - unknown color index" );
410 }
411 return nColor;
412}
413
415{
416 if( mnAppendIndex < maColors.size() )
417 maColors[ mnAppendIndex ] = nRGBValue;
418 else
419 maColors.push_back( nRGBValue );
421}
422
423namespace {
424
425void lclSetFontName( ApiScriptFontName& rFontName, const FontDescriptor& rFontDesc, bool bHasGlyphs )
426{
427 if( bHasGlyphs )
428 {
429 rFontName.maName = rFontDesc.Name;
430 rFontName.mnFamily = rFontDesc.Family;
431 // API font descriptor contains rtl_TextEncoding constants
432 rFontName.mnTextEnc = rFontDesc.CharSet;
433 }
434 else
435 {
436 rFontName = ApiScriptFontName();
437 }
438}
439
440} // namespace
441
443 mnScheme( XML_none ),
444 mnFamily( OOX_FONTFAMILY_NONE ),
445 mnCharSet( WINDOWS_CHARSET_DEFAULT ),
446 mfHeight( 0.0 ),
447 mnUnderline( XML_none ),
448 mnEscapement( XML_baseline ),
449 mbBold( false ),
450 mbItalic( false ),
451 mbStrikeout( false ),
452 mbOutline( false ),
453 mbShadow( false )
454{
455}
456
458{
459 static const sal_Int32 spnSchemes[] = { XML_none, XML_major, XML_minor };
460 mnScheme = STATIC_ARRAY_SELECT( spnSchemes, nScheme, XML_none );
461}
462
463void FontModel::setBiffHeight( sal_uInt16 nHeight )
464{
465 mfHeight = nHeight / 20.0; // convert twips to points
466}
467
468void FontModel::setBiffWeight( sal_uInt16 nWeight )
469{
470 mbBold = nWeight >= BIFF_FONTWEIGHT_BOLD;
471}
472
473void FontModel::setBiffUnderline( sal_uInt16 nUnderline )
474{
475 switch( nUnderline )
476 {
477 case BIFF_FONTUNDERL_NONE: mnUnderline = XML_none; break;
478 case BIFF_FONTUNDERL_SINGLE: mnUnderline = XML_single; break;
479 case BIFF_FONTUNDERL_DOUBLE: mnUnderline = XML_double; break;
480 case BIFF_FONTUNDERL_SINGLE_ACC: mnUnderline = XML_singleAccounting; break;
481 case BIFF_FONTUNDERL_DOUBLE_ACC: mnUnderline = XML_doubleAccounting; break;
482 default: mnUnderline = XML_none;
483 }
484}
485
486void FontModel::setBiffEscapement( sal_uInt16 nEscapement )
487{
488 static const sal_Int32 spnEscapes[] = { XML_baseline, XML_superscript, XML_subscript };
489 mnEscapement = STATIC_ARRAY_SELECT( spnEscapes, nEscapement, XML_baseline );
490}
491
493 mbNameUsed( bAllUsed ),
494 mbColorUsed( bAllUsed ),
495 mbSchemeUsed( bAllUsed ),
496 mbHeightUsed( bAllUsed ),
497 mbUnderlineUsed( bAllUsed ),
498 mbEscapementUsed( bAllUsed ),
499 mbWeightUsed( bAllUsed ),
500 mbPostureUsed( bAllUsed ),
501 mbStrikeoutUsed( bAllUsed ),
502 mbOutlineUsed( bAllUsed ),
503 mbShadowUsed( bAllUsed )
504{
505}
506
508 mnFamily( css::awt::FontFamily::DONTKNOW ),
509 mnTextEnc( RTL_TEXTENCODING_DONTKNOW )
510{
511}
512
514 maDesc(
515 "Calibri",
516 220, // height 11 points
517 0,
518 OUString(),
519 css::awt::FontFamily::DONTKNOW,
520 RTL_TEXTENCODING_DONTKNOW,
521 css::awt::FontPitch::DONTKNOW,
522 100.0,
523 css::awt::FontWeight::NORMAL,
524 css::awt::FontSlant_NONE,
525 css::awt::FontUnderline::NONE,
526 css::awt::FontStrikeout::NONE,
527 0.0,
528 false,
529 false,
530 css::awt::FontType::DONTKNOW ),
532 mnEscapement( API_ESCAPE_NONE ),
533 mnEscapeHeight( API_ESCAPEHEIGHT_NONE ),
534 mbOutline( false ),
535 mbShadow( false )
536{
538}
539
540Font::Font( const WorkbookHelper& rHelper, bool bDxf ) :
541 WorkbookHelper( rHelper ),
542 maModel( rHelper.getTheme().getDefaultFontModel() ),
543 maUsedFlags( !bDxf ),
544 mbDxf( bDxf )
545{
546}
547
548Font::Font( const WorkbookHelper& rHelper, FontModel aModel ) :
549 WorkbookHelper( rHelper ),
550 maModel(std::move( aModel )),
551 maUsedFlags( true ),
552 mbDxf( false )
553{
554}
555
556void Font::importAttribs( sal_Int32 nElement, const AttributeList& rAttribs )
557{
558 const FontModel& rDefModel = getTheme().getDefaultFontModel();
559 switch( nElement )
560 {
561 case XLS_TOKEN( name ): // when in <font> element
562 case XLS_TOKEN( rFont ): // when in <rPr> element
563 if( rAttribs.hasAttribute( XML_val ) )
564 {
565 maModel.maName = rAttribs.getXString( XML_val, OUString() );
566 maUsedFlags.mbNameUsed = true;
567 }
568 break;
569 case XLS_TOKEN( scheme ):
570 maModel.mnScheme = rAttribs.getToken( XML_val, rDefModel.mnScheme );
571 break;
572 case XLS_TOKEN( family ):
573 maModel.mnFamily = rAttribs.getInteger( XML_val, rDefModel.mnFamily );
574 break;
575 case XLS_TOKEN( charset ):
576 maModel.mnCharSet = rAttribs.getInteger( XML_val, rDefModel.mnCharSet );
577 break;
578 case XLS_TOKEN( sz ):
579 maModel.mfHeight = rAttribs.getDouble( XML_val, rDefModel.mfHeight );
581 break;
582 case XLS_TOKEN( color ):
583 maModel.maColor.importColor( rAttribs );
585 break;
586 case XLS_TOKEN( u ):
587 maModel.mnUnderline = rAttribs.getToken( XML_val, XML_single );
589 break;
590 case XLS_TOKEN( vertAlign ):
591 maModel.mnEscapement = rAttribs.getToken( XML_val, XML_baseline );
593 break;
594 case XLS_TOKEN( b ):
595 maModel.mbBold = rAttribs.getBool( XML_val, true );
597 break;
598 case XLS_TOKEN( i ):
599 maModel.mbItalic = rAttribs.getBool( XML_val, true );
601 break;
602 case XLS_TOKEN( strike ):
603 maModel.mbStrikeout = rAttribs.getBool( XML_val, true );
605 break;
606 case XLS_TOKEN( outline ):
607 maModel.mbOutline = rAttribs.getBool( XML_val, true );
609 break;
610 case XLS_TOKEN( shadow ):
611 maModel.mbShadow = rAttribs.getBool( XML_val, true );
613 break;
614 }
615}
616
618{
619 SAL_WARN_IF( mbDxf, "sc", "Font::importFont - unexpected conditional formatting flag" );
620
621 sal_uInt16 nHeight, nFlags, nWeight, nEscapement;
622 sal_uInt8 nUnderline, nFamily, nCharSet, nScheme;
623 nHeight = rStrm.readuInt16();
624 nFlags = rStrm.readuInt16();
625 nWeight = rStrm.readuInt16();
626 nEscapement = rStrm.readuInt16();
627 nUnderline = rStrm.readuChar();
628 nFamily = rStrm.readuChar();
629 nCharSet = rStrm.readuChar();
630 rStrm.skip( 1 );
632 nScheme = rStrm.readuChar();
634
635 // equal constants in all BIFFs for weight, underline, and escapement
636 maModel.setBiff12Scheme( nScheme );
637 maModel.setBiffHeight( nHeight );
638 maModel.setBiffWeight( nWeight );
639 maModel.setBiffUnderline( nUnderline );
640 maModel.setBiffEscapement( nEscapement );
641 maModel.mnFamily = nFamily;
642 maModel.mnCharSet = nCharSet;
643 // equal flags in all BIFFs
644 maModel.mbItalic = getFlag( nFlags, BIFF_FONTFLAG_ITALIC );
645 maModel.mbStrikeout = getFlag( nFlags, BIFF_FONTFLAG_STRIKEOUT );
646 maModel.mbOutline = getFlag( nFlags, BIFF_FONTFLAG_OUTLINE );
647 maModel.mbShadow = getFlag( nFlags, BIFF_FONTFLAG_SHADOW );
648}
649
651{
652 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfName - missing conditional formatting flag" );
655}
656
658{
659 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfColor - missing conditional formatting flag" );
662}
663
665{
666 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfScheme - missing conditional formatting flag" );
667 maModel.setBiff12Scheme( rStrm.readuInt8() );
669}
670
672{
673 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfHeight - missing conditional formatting flag" );
674 maModel.setBiffHeight( rStrm.readuInt16() );
676}
677
679{
680 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfWeight - missing conditional formatting flag" );
681 maModel.setBiffWeight( rStrm.readuInt16() );
683}
684
686{
687 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfUnderline - missing conditional formatting flag" );
688 maModel.setBiffUnderline( rStrm.readuInt16() );
690}
691
693{
694 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfEscapement - missing conditional formatting flag" );
695 maModel.setBiffEscapement( rStrm.readuInt16() );
697}
698
699void Font::importDxfFlag( sal_Int32 nElement, SequenceInputStream& rStrm )
700{
701 SAL_WARN_IF( !mbDxf, "sc", "Font::importDxfFlag - missing conditional formatting flag" );
702 bool bFlag = rStrm.readuInt8() != 0;
703 switch( nElement )
704 {
705 case XML_i:
706 maModel.mbItalic = bFlag;
708 break;
709 case XML_strike:
710 maModel.mbStrikeout = bFlag;
712 break;
713 case XML_outline:
714 maModel.mbOutline = bFlag;
716 break;
717 case XML_shadow:
718 maModel.mbShadow = bFlag;
720 break;
721 default:
722 OSL_FAIL( "Font::importDxfFlag - unexpected element identifier" );
723 }
724}
725
727{
728 // font name
730
731 // font family
732 switch( maModel.mnFamily )
733 {
734 case OOX_FONTFAMILY_NONE: maApiData.maDesc.Family = css::awt::FontFamily::DONTKNOW; break;
735 case OOX_FONTFAMILY_ROMAN: maApiData.maDesc.Family = css::awt::FontFamily::ROMAN; break;
736 case OOX_FONTFAMILY_SWISS: maApiData.maDesc.Family = css::awt::FontFamily::SWISS; break;
737 case OOX_FONTFAMILY_MODERN: maApiData.maDesc.Family = css::awt::FontFamily::MODERN; break;
738 case OOX_FONTFAMILY_SCRIPT: maApiData.maDesc.Family = css::awt::FontFamily::SCRIPT; break;
739 case OOX_FONTFAMILY_DECORATIVE: maApiData.maDesc.Family = css::awt::FontFamily::DECORATIVE; break;
740 }
741
742 // character set (API font descriptor uses rtl_TextEncoding in member CharSet!)
743 if( (0 <= maModel.mnCharSet) && (maModel.mnCharSet <= SAL_MAX_UINT8) )
744 maApiData.maDesc.CharSet = static_cast< sal_Int16 >(
745 rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( maModel.mnCharSet ) ) );
746
747 // color, height, weight, slant, strikeout, outline, shadow
749 maApiData.maDesc.Height = static_cast< sal_Int16 >( maModel.mfHeight * 20.0 );
750 maApiData.maDesc.Weight = maModel.mbBold ? css::awt::FontWeight::BOLD : css::awt::FontWeight::NORMAL;
751 maApiData.maDesc.Slant = maModel.mbItalic ? css::awt::FontSlant_ITALIC : css::awt::FontSlant_NONE;
752 maApiData.maDesc.Strikeout = maModel.mbStrikeout ? css::awt::FontStrikeout::SINGLE : css::awt::FontStrikeout::NONE;
755
756 // underline
757 switch( maModel.mnUnderline )
758 {
759 case XML_double: maApiData.maDesc.Underline = css::awt::FontUnderline::DOUBLE; break;
760 case XML_doubleAccounting: maApiData.maDesc.Underline = css::awt::FontUnderline::DOUBLE; break;
762 case XML_single: maApiData.maDesc.Underline = css::awt::FontUnderline::SINGLE; break;
763 case XML_singleAccounting: maApiData.maDesc.Underline = css::awt::FontUnderline::SINGLE; break;
764 }
765
766 // escapement
767 switch( maModel.mnEscapement )
768 {
769 case XML_baseline:
772 break;
773 case XML_superscript:
776 break;
777 case XML_subscript:
780 break;
781 }
782
783 // supported script types
785 return;
786
787 PropertySet aDocProps( getDocument() );
788 Reference< XDevice > xDevice( aDocProps.getAnyProperty( PROP_ReferenceDevice ), UNO_QUERY );
789 if( !xDevice.is() )
790 return;
791
792 Reference< XFont2 > xFont( xDevice->getFont( maApiData.maDesc ), UNO_QUERY );
793 if( !xFont.is() )
794 return;
795
796 // #91658# CJK fonts
797 bool bHasAsian =
798 xFont->hasGlyphs( OUString( u'\x3041' ) ) || // 3040-309F: Hiragana
799 xFont->hasGlyphs( OUString( u'\x30A1' ) ) || // 30A0-30FF: Katakana
800 xFont->hasGlyphs( OUString( u'\x3111' ) ) || // 3100-312F: Bopomofo
801 xFont->hasGlyphs( OUString( u'\x3131' ) ) || // 3130-318F: Hangul Compatibility Jamo
802 xFont->hasGlyphs( OUString( u'\x3301' ) ) || // 3300-33FF: CJK Compatibility
803 xFont->hasGlyphs( OUString( u'\x3401' ) ) || // 3400-4DBF: CJK Unified Ideographs Extension A
804 xFont->hasGlyphs( OUString( u'\x4E01' ) ) || // 4E00-9FFF: CJK Unified Ideographs
805 xFont->hasGlyphs( OUString( u'\x7E01' ) ) || // 4E00-9FFF: CJK Unified Ideographs
806 xFont->hasGlyphs( OUString( u'\xA001' ) ) || // A001-A48F: Yi Syllables
807 xFont->hasGlyphs( OUString( u'\xAC01' ) ) || // AC00-D7AF: Hangul Syllables
808 xFont->hasGlyphs( OUString( u'\xCC01' ) ) || // AC00-D7AF: Hangul Syllables
809 xFont->hasGlyphs( OUString( u'\xF901' ) ) || // F900-FAFF: CJK Compatibility Ideographs
810 xFont->hasGlyphs( OUString( u'\xFF71' ) ); // FF00-FFEF: Halfwidth/Fullwidth Forms
811 // #113783# CTL fonts
812 bool bHasCmplx =
813 xFont->hasGlyphs( OUString( u'\x05D1' ) ) || // 0590-05FF: Hebrew
814 xFont->hasGlyphs( OUString( u'\x0631' ) ) || // 0600-06FF: Arabic
815 xFont->hasGlyphs( OUString( u'\x0721' ) ) || // 0700-074F: Syriac
816 xFont->hasGlyphs( OUString( u'\x0911' ) ) || // 0900-0DFF: Indic scripts
817 xFont->hasGlyphs( OUString( u'\x0E01' ) ) || // 0E00-0E7F: Thai
818 xFont->hasGlyphs( OUString( u'\xFB21' ) ) || // FB1D-FB4F: Hebrew Presentation Forms
819 xFont->hasGlyphs( OUString( u'\xFB51' ) ) || // FB50-FDFF: Arabic Presentation Forms-A
820 xFont->hasGlyphs( OUString( u'\xFE71' ) ); // FE70-FEFF: Arabic Presentation Forms-B
821 // Western fonts
822 bool bHasLatin =
823 (!bHasAsian && !bHasCmplx) ||
824 xFont->hasGlyphs( OUString( 'A' ) );
825
826 lclSetFontName( maApiData.maLatinFont, maApiData.maDesc, bHasLatin );
827 lclSetFontName( maApiData.maAsianFont, maApiData.maDesc, bHasAsian );
828 lclSetFontName( maApiData.maCmplxFont, maApiData.maDesc, bHasCmplx );
829}
830
832{
834}
835
836static ::FontFamily lcl_getFontFamily( sal_Int32 nFamily )
837{
838 ::FontFamily eScFamily = FAMILY_DONTKNOW;
839 switch( nFamily )
840 {
841 case css::awt::FontFamily::DONTKNOW:
842 eScFamily = FAMILY_DONTKNOW;
843 break;
844 case css::awt::FontFamily::ROMAN:
845 eScFamily = FAMILY_ROMAN;
846 break;
847 case css::awt::FontFamily::SWISS:
848 eScFamily = FAMILY_SWISS;
849 break;
850 case css::awt::FontFamily::MODERN:
851 eScFamily = FAMILY_MODERN;
852 break;
853 case css::awt::FontFamily::SCRIPT:
854 eScFamily = FAMILY_SCRIPT;
855 break;
856 case css::awt::FontFamily::DECORATIVE:
857 eScFamily = FAMILY_DECORATIVE;
858 break;
859 }
860 return eScFamily;
861}
862
863void Font::fillToItemSet( SfxItemSet& rItemSet, bool bEditEngineText, bool bSkipPoolDefs ) const
864{
866 {
867 if( !maApiData.maLatinFont.maName.isEmpty() )
868 {
869 rtl_TextEncoding eFontEnc = maApiData.maLatinFont.mnTextEnc;
870 // taken from binary importer
871 rtl_TextEncoding eTempTextEnc = (bEditEngineText && (eFontEnc == getTextEncoding())) ?
873
875 PITCH_DONTKNOW, eTempTextEnc, ATTR_FONT );
876 ScfTools::PutItem( rItemSet, aFontItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTINFO) : ATTR_FONT, bSkipPoolDefs );
877 }
878 if( !maApiData.maAsianFont.maName.isEmpty() )
879 {
880 rtl_TextEncoding eFontEnc = maApiData.maAsianFont.mnTextEnc;
881 // taken from binary importer
882 rtl_TextEncoding eTempTextEnc = (bEditEngineText && (eFontEnc == getTextEncoding())) ?
885 PITCH_DONTKNOW, eTempTextEnc, ATTR_FONT );
886 ScfTools::PutItem( rItemSet, aFontItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTINFO_CJK) : ATTR_CJK_FONT, bSkipPoolDefs );
887 }
888 if( !maApiData.maCmplxFont.maName.isEmpty() )
889 {
890 rtl_TextEncoding eFontEnc = maApiData.maCmplxFont.mnTextEnc;
891 // taken from binary importer
892 rtl_TextEncoding eTempTextEnc = (bEditEngineText && (eFontEnc == getTextEncoding())) ?
895 PITCH_DONTKNOW, eTempTextEnc, ATTR_FONT );
896 ScfTools::PutItem( rItemSet, aFontItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTINFO_CTL) : ATTR_CTL_FONT, bSkipPoolDefs );
897 }
898 }
899 // font height
901 {
902 sal_Int32 nHeight = maApiData.maDesc.Height;
903 // do we use XclFontItemType::HeaderFooter ( or is it just relevant for the binary filter )
904 if( bEditEngineText/* && (eType != XclFontItemType::HeaderFooter) */) // do not convert header/footer height
905 nHeight = convertTwipToMm100(nHeight);
906 SvxFontHeightItem aHeightItem( nHeight, 100, ATTR_FONT_HEIGHT );
907 ScfTools::PutItem( rItemSet, aHeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTHEIGHT) : ATTR_FONT_HEIGHT, bSkipPoolDefs );
908 ScfTools::PutItem( rItemSet, aHeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTHEIGHT_CJK) : ATTR_CJK_FONT_HEIGHT, bSkipPoolDefs );
909 ScfTools::PutItem( rItemSet, aHeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_FONTHEIGHT_CTL) : ATTR_CTL_FONT_HEIGHT, bSkipPoolDefs );
910 }
911 // font weight
913 {
915 SvxWeightItem aWeightItem( fWeight, ATTR_FONT_WEIGHT );
916 ScfTools::PutItem( rItemSet, aWeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_WEIGHT) : ATTR_FONT_WEIGHT, bSkipPoolDefs );
917 ScfTools::PutItem( rItemSet, aWeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_WEIGHT_CTL) : ATTR_CTL_FONT_WEIGHT, bSkipPoolDefs );
918 ScfTools::PutItem( rItemSet, aWeightItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_WEIGHT_CJK) : ATTR_CJK_FONT_WEIGHT, bSkipPoolDefs );
919 }
920 // font posture
922 {
923 SvxPostureItem aPostItem( ( maApiData.maDesc.Slant == css::awt::FontSlant_ITALIC ) ? ITALIC_NORMAL : ITALIC_NONE, ATTR_FONT_POSTURE);
924 ScfTools::PutItem( rItemSet, aPostItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_ITALIC) : ATTR_FONT_POSTURE, bSkipPoolDefs );
925 ScfTools::PutItem( rItemSet, aPostItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_ITALIC_CJK) : ATTR_CJK_FONT_POSTURE, bSkipPoolDefs );
926 ScfTools::PutItem( rItemSet, aPostItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_ITALIC_CTL) : ATTR_CTL_FONT_POSTURE, bSkipPoolDefs );
927 }
928 // character color
930 {
931 ScfTools::PutItem( rItemSet,SvxColorItem( maApiData.mnColor, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_COLOR) : ATTR_FONT_COLOR), bSkipPoolDefs );
932 }
933 // underline style
935 {
936 FontLineStyle eScUnderl;
937 if ( maApiData.maDesc.Underline == css::awt::FontUnderline::DOUBLE )
938 eScUnderl = LINESTYLE_DOUBLE;
939 else if ( maApiData.maDesc.Underline == css::awt::FontUnderline::SINGLE )
940 eScUnderl = LINESTYLE_SINGLE;
941 else
942 eScUnderl = LINESTYLE_NONE;
943 SvxUnderlineItem aUnderlItem( eScUnderl, ATTR_FONT_UNDERLINE );
944 ScfTools::PutItem( rItemSet, aUnderlItem, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_UNDERLINE) : ATTR_FONT_UNDERLINE, bSkipPoolDefs );
945 }
946 // strike out style
948 {
949 ScfTools::PutItem( rItemSet, SvxCrossedOutItem( maModel.mbStrikeout ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_STRIKEOUT) : ATTR_FONT_CROSSEDOUT ), bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_STRIKEOUT) : ATTR_FONT_CROSSEDOUT, bSkipPoolDefs );
950 }
951
952 // outline style
954 {
955 ScfTools::PutItem( rItemSet, SvxContourItem( maApiData.mbOutline, ATTR_FONT_CONTOUR ), bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_OUTLINE) : ATTR_FONT_CONTOUR, bSkipPoolDefs );
956 }
957
958 // shadow style
960 {
961 ScfTools::PutItem( rItemSet, SvxShadowedItem( maApiData.mbShadow, ATTR_FONT_SHADOWED ), bEditEngineText ? static_cast<sal_uInt16>(EE_CHAR_SHADOW) : ATTR_FONT_SHADOWED, bSkipPoolDefs );
962 }
964 return;
965
966 SvxEscapement eScEscapem = SvxEscapement::Off;
968 eScEscapem = SvxEscapement::Superscript;
970 eScEscapem = SvxEscapement::Subscript;
971 if( bEditEngineText )
972 {
973 // #TODO handle EscapementHeight
974 rItemSet.Put( SvxEscapementItem( eScEscapem, EE_CHAR_ESCAPEMENT ) );
975 }
976}
977
979{
980 // font name properties
982 {
983 if( !maApiData.maLatinFont.maName.isEmpty() )
984 {
988 }
989 if( !maApiData.maAsianFont.maName.isEmpty() )
990 {
994 }
995 if( !maApiData.maCmplxFont.maName.isEmpty() )
996 {
1000 }
1001 }
1002 // font height
1004 {
1005 float fHeight = static_cast< float >( maApiData.maDesc.Height / 20.0 ); // twips to points
1006 rPropMap.setProperty( PROP_CharHeight, fHeight);
1007 rPropMap.setProperty( PROP_CharHeightAsian, fHeight);
1008 rPropMap.setProperty( PROP_CharHeightComplex, fHeight);
1009 }
1010 // font weight
1012 {
1013 float fWeight = maApiData.maDesc.Weight;
1014 rPropMap.setProperty( PROP_CharWeight, fWeight);
1015 rPropMap.setProperty( PROP_CharWeightAsian, fWeight);
1016 rPropMap.setProperty( PROP_CharWeightComplex, fWeight);
1017 }
1018 // font posture
1020 {
1021 rPropMap.setProperty( PROP_CharPosture, maApiData.maDesc.Slant);
1024 }
1025 // character color
1028 // underline style
1030 rPropMap.setProperty( PROP_CharUnderline, maApiData.maDesc.Underline);
1031 // strike out style
1033 rPropMap.setProperty( PROP_CharStrikeout, maApiData.maDesc.Strikeout);
1034 // outline style
1037 // shadow style
1040 // escapement
1042 {
1045 }
1046}
1047
1049{
1050 PropertyMap aPropMap;
1051 writeToPropertyMap( aPropMap );
1052 rPropSet.setProperties( aPropMap );
1053}
1054
1056 mnHorAlign( XML_general ),
1057 mnVerAlign( XML_bottom ),
1058 mnTextDir( OOX_XF_TEXTDIR_CONTEXT ),
1059 mnRotation( OOX_XF_ROTATION_NONE ),
1060 mnIndent( OOX_XF_INDENT_NONE ),
1061 mbWrapText( false ),
1062 mbShrink( false ),
1063 mbJustLastLine( false )
1064{
1065}
1066
1068{
1069 static const sal_Int32 spnHorAligns[] = {
1070 XML_general, XML_left, XML_center, XML_right,
1071 XML_fill, XML_justify, XML_centerContinuous, XML_distributed };
1072 mnHorAlign = STATIC_ARRAY_SELECT( spnHorAligns, nHorAlign, XML_general );
1073}
1074
1076{
1077 static const sal_Int32 spnVerAligns[] = {
1078 XML_top, XML_center, XML_bottom, XML_justify, XML_distributed };
1079 mnVerAlign = STATIC_ARRAY_SELECT( spnVerAligns, nVerAlign, XML_bottom );
1080}
1081
1083 meHorJustify( css::table::CellHoriJustify_STANDARD ),
1084 mnHorJustifyMethod( css::table::CellJustifyMethod::AUTO ),
1085 mnVerJustify( css::table::CellVertJustify2::STANDARD ),
1086 mnVerJustifyMethod( css::table::CellJustifyMethod::AUTO ),
1087 meOrientation( css::table::CellOrientation_STANDARD ),
1088 mnRotation( 0 ),
1089 mnWritingMode( css::text::WritingMode2::PAGE ),
1090 mnIndent( 0 ),
1091 mbWrapText( false ),
1092 mbShrink( false )
1093{
1094}
1095
1096bool operator==( const ApiAlignmentData& rLeft, const ApiAlignmentData& rRight )
1097{
1098 return
1099 (rLeft.meHorJustify == rRight.meHorJustify) &&
1100 (rLeft.mnHorJustifyMethod == rRight.mnHorJustifyMethod) &&
1101 (rLeft.mnVerJustify == rRight.mnVerJustify) &&
1102 (rLeft.mnVerJustifyMethod == rRight.mnVerJustifyMethod) &&
1103 (rLeft.meOrientation == rRight.meOrientation) &&
1104 (rLeft.mnRotation == rRight.mnRotation) &&
1105 (rLeft.mnWritingMode == rRight.mnWritingMode) &&
1106 (rLeft.mnIndent == rRight.mnIndent) &&
1107 (rLeft.mbWrapText == rRight.mbWrapText) &&
1108 (rLeft.mbShrink == rRight.mbShrink);
1109}
1110
1112 WorkbookHelper( rHelper )
1113{
1114}
1115
1117{
1118 maModel.mnVerAlign = rAttribs.getToken( XML_vertical, XML_bottom );
1119 maModel.mnTextDir = rAttribs.getInteger( XML_readingOrder, OOX_XF_TEXTDIR_CONTEXT );
1120 maModel.mnRotation = rAttribs.getInteger( XML_textRotation, OOX_XF_ROTATION_NONE );
1121 sal_Int32 nDefaultHorAlign = XML_general;
1122 if (maModel.mnRotation != OOX_XF_ROTATION_NONE)
1123 {
1124 if (maModel.mnRotation < 90 || maModel.mnRotation == 180)
1125 {
1126 nDefaultHorAlign = XML_left;
1127 }
1128 else
1129 {
1130 nDefaultHorAlign = XML_right;
1131 }
1132 }
1133 maModel.mnHorAlign = rAttribs.getToken( XML_horizontal, nDefaultHorAlign );
1134 maModel.mnIndent = rAttribs.getInteger( XML_indent, OOX_XF_INDENT_NONE );
1135 maModel.mbWrapText = rAttribs.getBool( XML_wrapText, false );
1136 maModel.mbShrink = rAttribs.getBool( XML_shrinkToFit, false );
1137 maModel.mbJustLastLine = rAttribs.getBool( XML_justifyLastLine, false );
1138}
1139
1140void Alignment::setBiff12Data( sal_uInt32 nFlags )
1141{
1142 maModel.setBiffHorAlign( extractValue< sal_uInt8 >( nFlags, 16, 3 ) );
1143 maModel.setBiffVerAlign( extractValue< sal_uInt8 >( nFlags, 19, 3 ) );
1144 maModel.mnTextDir = extractValue< sal_Int32 >( nFlags, 26, 2 );
1145 maModel.mnRotation = extractValue< sal_Int32 >( nFlags, 0, 8 );
1146 maModel.mnIndent = extractValue< sal_uInt8 >( nFlags, 8, 8 );
1147 maModel.mbWrapText = getFlag( nFlags, BIFF12_XF_WRAPTEXT );
1148 maModel.mbShrink = getFlag( nFlags, BIFF12_XF_SHRINK );
1149 maModel.mbJustLastLine = getFlag( nFlags, BIFF12_XF_JUSTLASTLINE );
1150}
1151
1153{
1154 // horizontal alignment
1155 switch( maModel.mnHorAlign )
1156 {
1157 case XML_center: maApiData.meHorJustify = css::table::CellHoriJustify_CENTER; break;
1158 case XML_centerContinuous: maApiData.meHorJustify = css::table::CellHoriJustify_CENTER; break;
1159 case XML_distributed: maApiData.meHorJustify = css::table::CellHoriJustify_BLOCK; break;
1160 case XML_fill: maApiData.meHorJustify = css::table::CellHoriJustify_REPEAT; break;
1161 case XML_general: maApiData.meHorJustify = css::table::CellHoriJustify_STANDARD; break;
1162 case XML_justify: maApiData.meHorJustify = css::table::CellHoriJustify_BLOCK; break;
1163 case XML_left: maApiData.meHorJustify = css::table::CellHoriJustify_LEFT; break;
1164 case XML_right: maApiData.meHorJustify = css::table::CellHoriJustify_RIGHT; break;
1165 }
1166
1167 if (maModel.mnHorAlign == XML_distributed)
1168 maApiData.mnHorJustifyMethod = css::table::CellJustifyMethod::DISTRIBUTE;
1169
1170 // vertical alignment
1171 switch( maModel.mnVerAlign )
1172 {
1173 case XML_bottom: maApiData.mnVerJustify = css::table::CellVertJustify2::BOTTOM; break;
1174 case XML_center: maApiData.mnVerJustify = css::table::CellVertJustify2::CENTER; break;
1175 case XML_distributed: maApiData.mnVerJustify = css::table::CellVertJustify2::BLOCK; break;
1176 case XML_justify: maApiData.mnVerJustify = css::table::CellVertJustify2::BLOCK; break;
1177 case XML_top: maApiData.mnVerJustify = css::table::CellVertJustify2::TOP; break;
1178 }
1179
1180 if (maModel.mnVerAlign == XML_distributed)
1181 maApiData.mnVerJustifyMethod = css::table::CellJustifyMethod::DISTRIBUTE;
1182
1183 /* indentation: expressed as number of blocks of 3 space characters in
1184 OOXML. */
1185 UnitConverter& rUnitConverter = getUnitConverter();
1186 // Note: indents are stored in twips
1187 sal_Int32 nIndent = rUnitConverter.scaleValue( 3.0 * maModel.mnIndent, Unit::Space, Unit::Twip);
1188 if( (0 <= nIndent) && (nIndent <= SAL_MAX_INT16) )
1189 maApiData.mnIndent = static_cast< sal_Int16 >( nIndent );
1190
1191 // complex text direction
1192 switch( maModel.mnTextDir )
1193 {
1194 case OOX_XF_TEXTDIR_CONTEXT: maApiData.mnWritingMode = css::text::WritingMode2::PAGE; break;
1195 case OOX_XF_TEXTDIR_LTR: maApiData.mnWritingMode = css::text::WritingMode2::LR_TB; break;
1196 case OOX_XF_TEXTDIR_RTL: maApiData.mnWritingMode = css::text::WritingMode2::RL_TB; break;
1197 }
1198
1199 // rotation: 0-90 means 0 to 90 degrees ccw, 91-180 means 1 to 90 degrees cw, 255 means stacked
1200 sal_Int32 nOoxRot = maModel.mnRotation;
1201 maApiData.mnRotation = Degree100(((0 <= nOoxRot) && (nOoxRot <= 90)) ?
1202 (100 * nOoxRot) :
1203 (((91 <= nOoxRot) && (nOoxRot <= 180)) ? (100 * (450 - nOoxRot)) : 0));
1204
1205 // "Orientation" property used for character stacking
1206 maApiData.meOrientation = (nOoxRot == OOX_XF_ROTATION_STACKED) ?
1207 css::table::CellOrientation_STACKED : css::table::CellOrientation_STANDARD;
1208
1209 // alignment flags (#i84960 automatic line break, if vertically justified/distributed)
1210 maApiData.mbWrapText = maModel.mbWrapText || (maModel.mnVerAlign == XML_distributed) || (maModel.mnVerAlign == XML_justify);
1212
1213}
1214
1216{
1217 ::SvxCellVerJustify nVert = ::SvxCellVerJustify::Standard;
1218 switch ( maApiData.mnVerJustify )
1219 {
1220 case css::table::CellVertJustify2::BOTTOM:
1221 nVert = ::SvxCellVerJustify::Bottom;
1222 break;
1223 case css::table::CellVertJustify2::CENTER:
1224 nVert = ::SvxCellVerJustify::Center;
1225 break;
1226 case css::table::CellVertJustify2::TOP:
1227 nVert = ::SvxCellVerJustify::Top;
1228 break;
1229 case css::table::CellVertJustify2::BLOCK:
1230 nVert = ::SvxCellVerJustify::Block;
1231 break;
1232 case css::table::CellVertJustify2::STANDARD:
1233 default:
1234 nVert = ::SvxCellVerJustify::Standard;
1235 break;
1236 }
1237 return nVert;
1238}
1239
1241{
1242 ::SvxCellHorJustify nHori = ::SvxCellHorJustify::Standard;
1243 switch( maApiData.meHorJustify )
1244 {
1245 case css::table::CellHoriJustify_LEFT:
1246 nHori = ::SvxCellHorJustify::Left;
1247 break;
1248 case css::table::CellHoriJustify_CENTER:
1249 nHori = ::SvxCellHorJustify::Center;
1250 break;
1251 case css::table::CellHoriJustify_RIGHT:
1252 nHori = ::SvxCellHorJustify::Right;
1253 break;
1254 case css::table::CellHoriJustify_BLOCK:
1255 nHori = ::SvxCellHorJustify::Block;
1256 break;
1257 case css::table::CellHoriJustify_REPEAT:
1258 nHori = ::SvxCellHorJustify::Repeat;
1259 break;
1260 case css::table::CellHoriJustify_STANDARD:
1261 default:
1262 nHori = ::SvxCellHorJustify::Standard;
1263 break;
1264 }
1265 return nHori;
1266}
1267
1269{
1270 SvxFrameDirection eFrameDir = SvxFrameDirection::Environment;
1271 switch( maApiData.mnWritingMode )
1272 {
1273 case css::text::WritingMode2::PAGE:
1274 eFrameDir = SvxFrameDirection::Environment;
1275 break;
1276 case css::text::WritingMode2::LR_TB:
1277 eFrameDir = SvxFrameDirection::Horizontal_LR_TB;
1278 break;
1279 case css::text::WritingMode2::RL_TB:
1280 eFrameDir = SvxFrameDirection::Horizontal_RL_TB;
1281 break;
1282 default:
1283 OSL_FAIL( "GetScFrameDir - unknown CTL text direction" );
1284 }
1285 return eFrameDir;
1286}
1287
1288void Alignment::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
1289{
1290 // horizontal alignment
1291 ScfTools::PutItem( rItemSet, SvxHorJustifyItem( GetScHorAlign(), ATTR_HOR_JUSTIFY ), bSkipPoolDefs );
1292 ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( ( maApiData.mnHorJustifyMethod == css::table::CellJustifyMethod::DISTRIBUTE ) ? ::SvxCellJustifyMethod::Distribute : ::SvxCellJustifyMethod::Auto, ATTR_HOR_JUSTIFY_METHOD ), bSkipPoolDefs );
1293 ScfTools::PutItem( rItemSet, SvxVerJustifyItem( GetScVerAlign(), ATTR_VER_JUSTIFY ), bSkipPoolDefs );
1294 // vertical alignment
1295 ScfTools::PutItem( rItemSet, SvxJustifyMethodItem( ( maApiData.mnVerJustifyMethod == css::table::CellJustifyMethod::DISTRIBUTE ) ? ::SvxCellJustifyMethod::Distribute : ::SvxCellJustifyMethod::Auto, ATTR_VER_JUSTIFY_METHOD ), bSkipPoolDefs );
1296
1297 // CTL text direction
1298 ScfTools::PutItem( rItemSet, SvxFrameDirectionItem( GetScFrameDir(), ATTR_WRITINGDIR ), bSkipPoolDefs );
1299 // set an angle in the range from -90 to 90 degrees
1300 ScfTools::PutItem( rItemSet, ScRotateValueItem( maApiData.mnRotation ), bSkipPoolDefs );
1301 // Orientation
1302 ScfTools::PutItem( rItemSet, ScVerticalStackCell( maApiData.meOrientation == css::table::CellOrientation_STACKED ), bSkipPoolDefs );
1303 // indent
1304 ScfTools::PutItem( rItemSet, ScIndentItem( maApiData.mnIndent ), bSkipPoolDefs );
1305 // line wrap
1306 ScfTools::PutItem( rItemSet, ScLineBreakCell( maApiData.mbWrapText ), bSkipPoolDefs );
1307 ScfTools::PutItem( rItemSet, ScShrinkToFitCell( maApiData.mbShrink ), bSkipPoolDefs );
1308}
1309
1311 mbLocked( true ), // default in Excel and Calc
1312 mbHidden( false )
1313{
1314}
1315
1317 maCellProt( true, false, false, false )
1318{
1319}
1320
1321bool operator==( const ApiProtectionData& rLeft, const ApiProtectionData& rRight )
1322{
1323 return
1324 (rLeft.maCellProt.IsLocked == rRight.maCellProt.IsLocked) &&
1325 (rLeft.maCellProt.IsFormulaHidden == rRight.maCellProt.IsFormulaHidden) &&
1326 (rLeft.maCellProt.IsHidden == rRight.maCellProt.IsHidden) &&
1327 (rLeft.maCellProt.IsPrintHidden == rRight.maCellProt.IsPrintHidden);
1328}
1329
1331 WorkbookHelper( rHelper )
1332{
1333}
1334
1336{
1337 maModel.mbLocked = rAttribs.getBool( XML_locked, true );
1338 maModel.mbHidden = rAttribs.getBool( XML_hidden, false );
1339}
1340
1341void Protection::setBiff12Data( sal_uInt32 nFlags )
1342{
1343 maModel.mbLocked = getFlag( nFlags, BIFF12_XF_LOCKED );
1344 maModel.mbHidden = getFlag( nFlags, BIFF12_XF_HIDDEN );
1345}
1346
1348{
1350 maApiData.maCellProt.IsFormulaHidden = maModel.mbHidden;
1351}
1352
1353void Protection::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
1354{
1355 ScfTools::PutItem( rItemSet, ScProtectionAttr( maApiData.maCellProt.IsLocked, maApiData.maCellProt.IsFormulaHidden ), bSkipPoolDefs );
1356}
1357
1358namespace {
1359
1360bool lcl_isBorder(const css::table::BorderLine& rBorder)
1361{
1362 return (rBorder.InnerLineWidth > 0) || (rBorder.OuterLineWidth > 0);
1363}
1364
1365}
1366
1368 mnStyle( XML_none ),
1369 mbUsed( !bDxf )
1370{
1372}
1373
1374void BorderLineModel::setBiffStyle( sal_Int32 nLineStyle )
1375{
1376 static const sal_Int32 spnStyleIds[] = {
1377 XML_none, XML_thin, XML_medium, XML_dashed,
1378 XML_dotted, XML_thick, XML_double, XML_hair,
1379 XML_mediumDashed, XML_dashDot, XML_mediumDashDot, XML_dashDotDot,
1380 XML_mediumDashDotDot, XML_slantDashDot };
1381 mnStyle = STATIC_ARRAY_SELECT( spnStyleIds, nLineStyle, XML_none );
1382}
1383
1385 maLeft( bDxf ),
1386 maRight( bDxf ),
1387 maTop( bDxf ),
1388 maBottom( bDxf ),
1389 maDiagonal( bDxf ),
1390 mbDiagTLtoBR( false ),
1391 mbDiagBLtoTR( false )
1392{
1393}
1394
1396 mbBorderUsed( false ),
1397 mbDiagUsed( false )
1398{
1399}
1400
1402{
1403 return
1404 ( lcl_isBorder( maTop ) && maTop.OuterLineWidth > 0 ) ||
1405 ( lcl_isBorder( maBottom ) && maBottom.OuterLineWidth > 0 ) ||
1406 ( lcl_isBorder( maLeft ) && maLeft.OuterLineWidth > 0 ) ||
1407 ( lcl_isBorder( maRight ) && maRight.OuterLineWidth > 0 );
1408}
1409
1410namespace {
1411
1412void lclSetBorderLineWidth( BorderLine& rBorderLine,
1413 sal_Int16 nOuter, sal_Int16 nDist = API_LINE_NONE, sal_Int16 nInner = API_LINE_NONE )
1414{
1415 rBorderLine.OuterLineWidth = nOuter;
1416 rBorderLine.LineDistance = nDist;
1417 rBorderLine.InnerLineWidth = nInner;
1418}
1419
1420} // namespace
1421
1422Border::Border( const WorkbookHelper& rHelper, bool bDxf ) :
1423 WorkbookHelper( rHelper ),
1424 maModel( bDxf ),
1425 mbDxf( bDxf )
1426{
1427}
1428
1430{
1431 maModel.mbDiagTLtoBR = rAttribs.getBool( XML_diagonalDown, false );
1432 maModel.mbDiagBLtoTR = rAttribs.getBool( XML_diagonalUp, false );
1433}
1434
1435void Border::importStyle( sal_Int32 nElement, const AttributeList& rAttribs )
1436{
1437 if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
1438 {
1439 pBorderLine->mnStyle = rAttribs.getToken( XML_style, XML_none );
1440 pBorderLine->mbUsed = true;
1441 }
1442}
1443
1444void Border::importColor( sal_Int32 nElement, const AttributeList& rAttribs )
1445{
1446 if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
1447 pBorderLine->maColor.importColor( rAttribs );
1448}
1449
1451{
1452 sal_uInt8 nFlags = rStrm.readuInt8();
1453 maModel.mbDiagTLtoBR = getFlag( nFlags, BIFF12_BORDER_DIAG_TLBR );
1454 maModel.mbDiagBLtoTR = getFlag( nFlags, BIFF12_BORDER_DIAG_BLTR );
1455 maModel.maTop.setBiffStyle( rStrm.readuInt16() );
1457 maModel.maBottom.setBiffStyle( rStrm.readuInt16() );
1459 maModel.maLeft.setBiffStyle( rStrm.readuInt16() );
1461 maModel.maRight.setBiffStyle( rStrm.readuInt16() );
1463 maModel.maDiagonal.setBiffStyle( rStrm.readuInt16() );
1465}
1466
1467void Border::importDxfBorder( sal_Int32 nElement, SequenceInputStream& rStrm )
1468{
1469 SAL_WARN_IF( !mbDxf, "sc", "Border::importDxfBorder - missing conditional formatting flag" );
1470 if( BorderLineModel* pBorderLine = getBorderLine( nElement ) )
1471 {
1472 sal_uInt16 nStyle;
1473 rStrm >> pBorderLine->maColor;
1474 nStyle = rStrm.readuInt16();
1475 pBorderLine->setBiffStyle( nStyle );
1476 pBorderLine->mbUsed = true;
1477 }
1478}
1479
1480void Border::finalizeImport( bool bRTL )
1481{
1482 if ( bRTL )
1483 {
1486 maModel.maRight = aTmp;
1487 }
1490
1495
1496 if( maModel.mbDiagTLtoBR )
1498 if( maModel.mbDiagBLtoTR )
1500}
1501
1502void Border::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
1503{
1505 {
1506 SvxBoxItem aBoxItem( ATTR_BORDER );
1508
1509 if (SvxBoxItem::LineToSvxLine(maApiData.maLeft, aLine, false))
1510 {
1511 aBoxItem.SetLine( &aLine, SvxBoxItemLine::LEFT );
1512 }
1513 if (SvxBoxItem::LineToSvxLine(maApiData.maRight, aLine, false))
1514 {
1515 aBoxItem.SetLine( &aLine, SvxBoxItemLine::RIGHT );
1516 }
1517 if (SvxBoxItem::LineToSvxLine(maApiData.maTop, aLine, false))
1518 {
1519 aBoxItem.SetLine( &aLine, SvxBoxItemLine::TOP );
1520 }
1521 if (SvxBoxItem::LineToSvxLine(maApiData.maBottom, aLine, false))
1522 {
1523 aBoxItem.SetLine( &aLine, SvxBoxItemLine::BOTTOM );
1524 }
1525 ScfTools::PutItem( rItemSet, aBoxItem, bSkipPoolDefs );
1526 }
1527 if ( !maApiData.mbDiagUsed )
1528 return;
1529
1530 SvxLineItem aTLBRItem( ATTR_BORDER_TLBR );
1531 SvxLineItem aBLTRItem( ATTR_BORDER_BLTR );
1533 if (SvxBoxItem::LineToSvxLine(maApiData.maTLtoBR, aLine, false))
1534 {
1535 aTLBRItem.SetLine( &aLine );
1536 }
1537 if (SvxBoxItem::LineToSvxLine(maApiData.maBLtoTR, aLine, false))
1538 {
1539 aBLTRItem.SetLine( &aLine );
1540 }
1541 ScfTools::PutItem( rItemSet, aTLBRItem, bSkipPoolDefs );
1542 ScfTools::PutItem( rItemSet, aBLTRItem, bSkipPoolDefs );
1543}
1544
1546{
1547 switch( nElement )
1548 {
1549 case XLS_TOKEN( left ): return &maModel.maLeft;
1550 case XLS_TOKEN( start ): return &maModel.maLeft;
1551 case XLS_TOKEN( right ): return &maModel.maRight;
1552 case XLS_TOKEN( end ): return &maModel.maRight;
1553 case XLS_TOKEN( top ): return &maModel.maTop;
1554 case XLS_TOKEN( bottom ): return &maModel.maBottom;
1555 case XLS_TOKEN( diagonal ): return &maModel.maDiagonal;
1556 }
1557 return nullptr;
1558}
1559
1560bool Border::convertBorderLine( BorderLine2& rBorderLine, const BorderLineModel& rModel )
1561{
1562 // Document: sc/qa/unit/data/README.cellborders
1563
1564 rBorderLine.Color = sal_Int32(rModel.maColor.getColor( getBaseFilter().getGraphicHelper(), API_RGB_BLACK ));
1565 switch( rModel.mnStyle )
1566 {
1567 case XML_dashDot:
1568 lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
1569 rBorderLine.LineStyle = BorderLineStyle::DASH_DOT;
1570 break;
1571 case XML_dashDotDot:
1572 lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
1573 rBorderLine.LineStyle = BorderLineStyle::DASH_DOT_DOT;
1574 break;
1575 case XML_dashed:
1576 lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
1577 rBorderLine.LineStyle = BorderLineStyle::FINE_DASHED;
1578 break;
1579 case XML_dotted:
1580 lclSetBorderLineWidth( rBorderLine, API_LINE_THIN );
1581 rBorderLine.LineStyle = BorderLineStyle::DOTTED;
1582 break;
1583 case XML_double:
1584 lclSetBorderLineWidth( rBorderLine, 10, 15, 10 );
1585 rBorderLine.LineStyle = BorderLineStyle::DOUBLE_THIN;
1586 break;
1587 case XML_hair: lclSetBorderLineWidth( rBorderLine, API_LINE_HAIR ); break;
1588 case XML_medium: lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM ); break;
1589 case XML_mediumDashDot:
1590 lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );
1591 rBorderLine.LineStyle = BorderLineStyle::DASH_DOT;
1592 break;
1593 case XML_mediumDashDotDot:
1594 lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );
1595 rBorderLine.LineStyle = BorderLineStyle::DASH_DOT_DOT;
1596 break;
1597 case XML_mediumDashed:
1598 lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );
1599 rBorderLine.LineStyle = BorderLineStyle::DASHED;
1600 break;
1601 case XML_none: lclSetBorderLineWidth( rBorderLine, API_LINE_NONE ); break;
1602 case XML_slantDashDot:
1603 lclSetBorderLineWidth( rBorderLine, API_LINE_MEDIUM );
1604 rBorderLine.LineStyle = BorderLineStyle::FINE_DASHED;
1605 break;
1606 case XML_thick: lclSetBorderLineWidth( rBorderLine, API_LINE_THICK ); break;
1607 case XML_thin: lclSetBorderLineWidth( rBorderLine, API_LINE_THIN ); break;
1608 default: lclSetBorderLineWidth( rBorderLine, API_LINE_NONE ); break;
1609 }
1610 return rModel.mbUsed;
1611}
1612
1614 mnPattern( XML_none ),
1615 mbPattColorUsed( !bDxf ),
1616 mbFillColorUsed( !bDxf ),
1617 mbPatternUsed( !bDxf )
1618{
1622}
1623
1624void PatternFillModel::setBiffPattern( sal_Int32 nPattern )
1625{
1626 static const sal_Int32 spnPatternIds[] = {
1627 XML_none, XML_solid, XML_mediumGray, XML_darkGray,
1628 XML_lightGray, XML_darkHorizontal, XML_darkVertical, XML_darkDown,
1629 XML_darkUp, XML_darkGrid, XML_darkTrellis, XML_lightHorizontal,
1630 XML_lightVertical, XML_lightDown, XML_lightUp, XML_lightGrid,
1631 XML_lightTrellis, XML_gray125, XML_gray0625 };
1632 mnPattern = STATIC_ARRAY_SELECT( spnPatternIds, nPattern, XML_none );
1633}
1634
1636 mnType( XML_linear ),
1637 mfAngle( 0.0 ),
1638 mfLeft( 0.0 ),
1639 mfRight( 0.0 ),
1640 mfTop( 0.0 ),
1641 mfBottom( 0.0 )
1642{
1643}
1644
1646{
1647 sal_Int32 nType;
1648 nType = rStrm.readInt32();
1649 mfAngle = rStrm.readDouble();
1650 mfLeft = rStrm.readDouble();
1651 mfRight = rStrm.readDouble();
1652 mfTop = rStrm.readDouble();
1653 mfBottom = rStrm.readDouble();
1654 static const sal_Int32 spnTypes[] = { XML_linear, XML_path };
1656}
1657
1659{
1660 Color aColor;
1661 double fPosition;
1662 if( bDxf )
1663 {
1664 rStrm.skip( 2 );
1665 fPosition = rStrm.readDouble();
1666 rStrm >> aColor;
1667 }
1668 else
1669 {
1670 rStrm >> aColor;
1671 fPosition = rStrm.readDouble();
1672 }
1673 if( !rStrm.isEof() && (fPosition >= 0.0) )
1674 maColors[ fPosition ] = aColor;
1675}
1676
1679 mnFilterColor( API_RGB_TRANSPARENT ),
1680 mbTransparent( true ),
1681 mbUsed( false )
1682{
1683}
1684
1685namespace {
1686
1687sal_Int32 lclGetMixedColorComp( sal_Int32 nPatt, sal_Int32 nFill, sal_Int32 nAlpha )
1688{
1689 return ((nPatt - nFill) * nAlpha) / 0x80 + nFill;
1690}
1691
1692::Color lclGetMixedColor( ::Color nPattColor, ::Color nFillColor, sal_Int32 nAlpha )
1693{
1694 return ::Color(
1695 lclGetMixedColorComp( nPattColor.GetRed(), nFillColor.GetRed(), nAlpha ),
1696 lclGetMixedColorComp( nPattColor.GetGreen(), nFillColor.GetGreen(), nAlpha ),
1697 lclGetMixedColorComp( nPattColor.GetBlue(), nFillColor.GetBlue(), nAlpha ) );
1698}
1699
1700} // namespace
1701
1702Fill::Fill( const WorkbookHelper& rHelper, bool bDxf ) :
1703 WorkbookHelper( rHelper ),
1704 mbDxf( bDxf )
1705{
1706}
1707
1709{
1710 mxPatternModel = std::make_shared<PatternFillModel>( mbDxf );
1711 mxPatternModel->mnPattern = rAttribs.getToken( XML_patternType, XML_none );
1712 if( mbDxf )
1713 mxPatternModel->mbPatternUsed = rAttribs.hasAttribute( XML_patternType );
1714}
1715
1716void Fill::importFgColor( const AttributeList& rAttribs )
1717{
1718 OSL_ENSURE( mxPatternModel, "Fill::importFgColor - missing pattern data" );
1719 if( mxPatternModel )
1720 {
1721 mxPatternModel->maPatternColor.importColor( rAttribs );
1722 mxPatternModel->mbPattColorUsed = true;
1723 }
1724}
1725
1726void Fill::importBgColor( const AttributeList& rAttribs )
1727{
1728 OSL_ENSURE( mxPatternModel, "Fill::importBgColor - missing pattern data" );
1729 if( mxPatternModel )
1730 {
1731 mxPatternModel->maFillColor.importColor( rAttribs );
1732 mxPatternModel->mbFillColorUsed = true;
1733 }
1734}
1735
1737{
1738 mxGradientModel = std::make_shared<GradientFillModel>();
1739 mxGradientModel->mnType = rAttribs.getToken( XML_type, XML_linear );
1740 mxGradientModel->mfAngle = rAttribs.getDouble( XML_degree, 0.0 );
1741 mxGradientModel->mfLeft = rAttribs.getDouble( XML_left, 0.0 );
1742 mxGradientModel->mfRight = rAttribs.getDouble( XML_right, 0.0 );
1743 mxGradientModel->mfTop = rAttribs.getDouble( XML_top, 0.0 );
1744 mxGradientModel->mfBottom = rAttribs.getDouble( XML_bottom, 0.0 );
1745}
1746
1747void Fill::importColor( const AttributeList& rAttribs, double fPosition )
1748{
1749 OSL_ENSURE( mxGradientModel, "Fill::importColor - missing gradient data" );
1750 if( mxGradientModel && (fPosition >= 0.0) )
1751 mxGradientModel->maColors[ fPosition ].importColor( rAttribs );
1752}
1753
1755{
1756 SAL_WARN_IF( mbDxf, "sc", "Fill::importFill - unexpected conditional formatting flag" );
1757 sal_Int32 nPattern = rStrm.readInt32();
1758 if( nPattern == BIFF12_FILL_GRADIENT )
1759 {
1760 mxGradientModel = std::make_shared<GradientFillModel>();
1761 sal_Int32 nStopCount;
1762 rStrm.skip( 16 );
1763 mxGradientModel->readGradient( rStrm );
1764 nStopCount = rStrm.readInt32();
1765 for( sal_Int32 nStop = 0; (nStop < nStopCount) && !rStrm.isEof(); ++nStop )
1766 mxGradientModel->readGradientStop( rStrm, false );
1767 }
1768 else
1769 {
1770 mxPatternModel = std::make_shared<PatternFillModel>( mbDxf );
1771 mxPatternModel->setBiffPattern( nPattern );
1772 rStrm >> mxPatternModel->maPatternColor >> mxPatternModel->maFillColor;
1773 }
1774}
1775
1777{
1778 SAL_WARN_IF( !mbDxf, "sc", "Fill::importDxfPattern - missing conditional formatting flag" );
1779 if( !mxPatternModel )
1780 mxPatternModel = std::make_shared<PatternFillModel>( mbDxf );
1781 mxPatternModel->setBiffPattern( rStrm.readuInt8() );
1782 mxPatternModel->mbPatternUsed = true;
1783}
1784
1786{
1787 SAL_WARN_IF( !mbDxf, "sc", "Fill::importDxfFgColor - missing conditional formatting flag" );
1788 if( !mxPatternModel )
1789 mxPatternModel = std::make_shared<PatternFillModel>( mbDxf );
1790 mxPatternModel->maPatternColor.importColor( rStrm );
1791 mxPatternModel->mbPattColorUsed = true;
1792}
1793
1795{
1796 SAL_WARN_IF( !mbDxf, "sc", "Fill::importDxfBgColor - missing conditional formatting flag" );
1797 if( !mxPatternModel )
1798 mxPatternModel = std::make_shared<PatternFillModel>( mbDxf );
1799 mxPatternModel->maFillColor.importColor( rStrm );
1800 mxPatternModel->mbFillColorUsed = true;
1801}
1802
1804{
1805 SAL_WARN_IF( !mbDxf, "sc", "Fill::importDxfGradient - missing conditional formatting flag" );
1806 if( !mxGradientModel )
1807 mxGradientModel = std::make_shared<GradientFillModel>();
1808 mxGradientModel->readGradient( rStrm );
1809}
1810
1812{
1813 SAL_WARN_IF( !mbDxf, "sc", "Fill::importDxfStop - missing conditional formatting flag" );
1814 if( !mxGradientModel )
1815 mxGradientModel = std::make_shared<GradientFillModel>();
1816 mxGradientModel->readGradientStop( rStrm, true );
1817}
1818
1820{
1821 const GraphicHelper& rGraphicHelper = getBaseFilter().getGraphicHelper();
1822
1823 if( mxPatternModel )
1824 {
1825 // finalize the OOXML data struct
1827 if( mbDxf )
1828 {
1829 if( rModel.mbFillColorUsed && (!rModel.mbPatternUsed || (rModel.mnPattern == XML_solid)) )
1830 {
1831 rModel.maFilterPatternColor = rModel.maPatternColor;
1832 rModel.maPatternColor = rModel.maFillColor;
1833 rModel.mnPattern = XML_solid;
1834 rModel.mbPattColorUsed = rModel.mbPatternUsed = true;
1835 }
1836 else if(
1837 !rModel.mbFillColorUsed && !rModel.mbPattColorUsed &&
1838 rModel.mbPatternUsed && rModel.mnPattern == XML_solid )
1839 {
1840 rModel.mbPatternUsed = false;
1841 }
1842 else
1843 rModel.maFilterPatternColor = rModel.maPatternColor;
1844 }
1845
1846 // convert to API fill settings
1848 if( rModel.mnPattern == XML_none )
1849 {
1851 maApiData.mbTransparent = true;
1852 }
1853 else
1854 {
1855 sal_Int32 nAlpha = 0x80;
1856 switch( rModel.mnPattern )
1857 {
1858 case XML_darkDown: nAlpha = 0x40; break;
1859 case XML_darkGray: nAlpha = 0x60; break;
1860 case XML_darkGrid: nAlpha = 0x40; break;
1861 case XML_darkHorizontal: nAlpha = 0x40; break;
1862 case XML_darkTrellis: nAlpha = 0x60; break;
1863 case XML_darkUp: nAlpha = 0x40; break;
1864 case XML_darkVertical: nAlpha = 0x40; break;
1865 case XML_gray0625: nAlpha = 0x08; break;
1866 case XML_gray125: nAlpha = 0x10; break;
1867 case XML_lightDown: nAlpha = 0x20; break;
1868 case XML_lightGray: nAlpha = 0x20; break;
1869 case XML_lightGrid: nAlpha = 0x38; break;
1870 case XML_lightHorizontal: nAlpha = 0x20; break;
1871 case XML_lightTrellis: nAlpha = 0x30; break;
1872 case XML_lightUp: nAlpha = 0x20; break;
1873 case XML_lightVertical: nAlpha = 0x20; break;
1874 case XML_mediumGray: nAlpha = 0x40; break;
1875 case XML_solid: nAlpha = 0x80; break;
1876 }
1877
1878 ::Color nWinTextColor = rGraphicHelper.getSystemColor( XML_windowText );
1879 ::Color nWinColor = rGraphicHelper.getSystemColor( XML_window );
1880
1881 if (!rModel.mbPattColorUsed)
1882 {
1883 rModel.maPatternColor.setAuto();
1885 }
1886 ::Color nPattColor = rModel.maPatternColor.getColor( rGraphicHelper, nWinTextColor );
1887 ::Color nFiltPattColor = rModel.maFilterPatternColor.getColor( rGraphicHelper, nWinTextColor );
1888
1889 if( !rModel.mbFillColorUsed )
1890 rModel.maFillColor.setAuto();
1891 ::Color nFillColor = rModel.maFillColor.getColor( rGraphicHelper, nWinColor );
1892
1893 maApiData.mnColor = lclGetMixedColor( nPattColor, nFillColor, nAlpha );
1894 maApiData.mnFilterColor = lclGetMixedColor( nFiltPattColor, nFillColor, nAlpha );
1895 maApiData.mbTransparent = false;
1896 }
1897 }
1898 else if( mxGradientModel && !mxGradientModel->maColors.empty() )
1899 {
1901 maApiData.mbUsed = true; // no support for differential attributes
1902 GradientFillModel::ColorMap::const_iterator aIt = rModel.maColors.begin();
1903 OSL_ENSURE( !aIt->second.isAuto(), "Fill::finalizeImport - automatic gradient color" );
1904 maApiData.mnColor = aIt->second.getColor( rGraphicHelper, API_RGB_WHITE );
1905 if( ++aIt != rModel.maColors.end() )
1906 {
1907 OSL_ENSURE( !aIt->second.isAuto(), "Fill::finalizeImport - automatic gradient color" );
1908 ::Color nEndColor = aIt->second.getColor( rGraphicHelper, API_RGB_WHITE );
1909 maApiData.mnColor = lclGetMixedColor( maApiData.mnColor, nEndColor, 0x40 );
1910 maApiData.mbTransparent = false;
1911 }
1912 }
1913}
1914
1915void Fill::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const
1916{
1917 if( !maApiData.mbUsed )
1918 return;
1919
1920 SvxBrushItem aBrushItem( ATTR_BACKGROUND );
1922 {
1923 aBrushItem.SetColor( COL_TRANSPARENT );
1924 aBrushItem.SetFiltColor( COL_TRANSPARENT );
1925 }
1926 else
1927 {
1928 aBrushItem.SetColor( maApiData.mnColor );
1929 aBrushItem.SetFiltColor( maApiData.mnFilterColor );
1930 }
1931 ScfTools::PutItem( rItemSet, aBrushItem, bSkipPoolDefs );
1932}
1933
1935 mnStyleXfId( -1 ),
1936 mnFontId( -1 ),
1937 mnNumFmtId( -1 ),
1938 mnBorderId( -1 ),
1939 mnFillId( -1 ),
1940 mbCellXf( true ),
1941 mbFontUsed( false ),
1942 mbNumFmtUsed( false ),
1943 mbAlignUsed( false ),
1944 mbProtUsed( false ),
1945 mbBorderUsed( false ),
1946 mbAreaUsed( false )
1947{
1948}
1949
1951 mbLatinNumFmtOnly(true),
1952 mpDefPattern(pDefPattern)
1953{}
1954
1955Xf::Xf( const WorkbookHelper& rHelper ) :
1956 WorkbookHelper( rHelper ),
1957 mnScNumFmt(0),
1958 maAlignment( rHelper ),
1959 maProtection( rHelper ),
1960 meRotationRef( css::table::CellVertJustify2::STANDARD ),
1961 mpStyleSheet( nullptr )
1962{
1963}
1964
1965void Xf::importXf( const AttributeList& rAttribs, bool bCellXf )
1966{
1967 maModel.mbCellXf = bCellXf;
1968 // tdf#70565 Set proper default value to "0" of xfId attribute
1969 // When xfId is not exist during .xlsx import
1970 // it must have values set to "0".
1971 // This doesn't impact spreadsheets created with MS Excel,
1972 // as xfId attribute is always created during export to .xlsx
1973 // Not setting "0" value is causing wrong .xlsx import by LibreOffice,
1974 // for spreadsheets created by external applications (ex. SAP BI).
1975 bool bApplyDefault;
1976 if ( maModel.mbCellXf )
1977 {
1978 const sal_Int32 xfId = rAttribs.getInteger( XML_xfId, -1 );
1979 // No xfId => no cellStyleXfs that could overwrite this on change, thus
1980 // has to be applied.
1981 bApplyDefault = (xfId < 0);
1982 maModel.mnStyleXfId = std::max<sal_Int32>(0, xfId);
1983 }
1984 else
1985 {
1986 maModel.mnStyleXfId = rAttribs.getInteger( XML_xfId, -1 );
1987 bApplyDefault = true;
1988 }
1989 maModel.mnFontId = rAttribs.getInteger( XML_fontId, -1 );
1990 maModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, -1 );
1991 maModel.mnBorderId = rAttribs.getInteger( XML_borderId, -1 );
1992 maModel.mnFillId = rAttribs.getInteger( XML_fillId, -1 );
1993
1994 // Default value of the apply*** attributes is dependent on context:
1995 // true in cellStyleXfs element, false in cellXfs element...
1996 // But it's not as easy as it sounds, for docs see
1997 // https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/59922f8b-0edc-4e93-a822-9f22254aec46
1998 // and apparently in reality cellStyleXfs xf and cellXfs xf are not merged
1999 // at all, see
2000 // https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/bcf98682-e8d3-44b8-b8f8-0bf696878ba1
2001 // "b. The standard states that both the cell style xf records and cell xf
2002 // records must be read to understand the full set of formatting applied to
2003 // a cell."
2004 // "In Office, only the cell xf record defines the formatting applied to a cell."
2005
2006 // So for reading documents this is all crap and effectively xf records
2007 // apply their explicit properties by default unless denied.
2008 // bApplyDefault==false only for cellXf xf with xfId.
2009
2010 // For cellXf xf, mbAlignUsed and mbProtUsed will be set when actually
2011 // importing the element.
2012 maModel.mbAlignUsed = rAttribs.getBool( XML_applyAlignment, bApplyDefault);
2013 maModel.mbProtUsed = rAttribs.getBool( XML_applyProtection, bApplyDefault);
2014
2015 maModel.mbFontUsed = rAttribs.getBool( XML_applyFont, bApplyDefault || maModel.mnFontId > 0);
2016 maModel.mbNumFmtUsed = rAttribs.getBool( XML_applyNumberFormat, bApplyDefault || maModel.mnNumFmtId > 0);
2017 maModel.mbBorderUsed = rAttribs.getBool( XML_applyBorder, bApplyDefault || maModel.mnBorderId > 0);
2018 maModel.mbAreaUsed = rAttribs.getBool( XML_applyFill, bApplyDefault || maModel.mnFillId > 0);
2019}
2020
2021void Xf::importAlignment( const AttributeList& rAttribs )
2022{
2023 maAlignment.importAlignment( rAttribs );
2024 if (maModel.mbCellXf)
2025 maModel.mbAlignUsed = true;
2026}
2027
2029{
2030 maProtection.importProtection( rAttribs );
2031 if (maModel.mbCellXf)
2032 maModel.mbProtUsed = true;
2033}
2034
2035void Xf::importXf( SequenceInputStream& rStrm, bool bCellXf )
2036{
2037 maModel.mbCellXf = bCellXf;
2038 maModel.mnStyleXfId = rStrm.readuInt16();
2039 maModel.mnNumFmtId = rStrm.readuInt16();
2040 maModel.mnFontId = rStrm.readuInt16();
2041 maModel.mnFillId = rStrm.readuInt16();
2042 maModel.mnBorderId = rStrm.readuInt16();
2043 sal_uInt32 nFlags = rStrm.readuInt32();
2044 maAlignment.setBiff12Data( nFlags );
2045 maProtection.setBiff12Data( nFlags );
2046 // used flags, see comments in Xf::setBiffUsedFlags()
2047 sal_uInt16 nUsedFlags = rStrm.readuInt16();
2048 maModel.mbFontUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_FONT_USED );
2049 maModel.mbNumFmtUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_NUMFMT_USED );
2050 maModel.mbAlignUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_ALIGN_USED );
2051 maModel.mbProtUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_PROT_USED );
2052 maModel.mbBorderUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_BORDER_USED );
2053 maModel.mbAreaUsed = maModel.mbCellXf == getFlag( nUsedFlags, BIFF12_XF_AREA_USED );
2054}
2055
2057{
2058 // alignment and protection
2061}
2062
2064{
2065 return getStyles().getFont( maModel.mnFontId );
2066}
2067
2068void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nNumFmtId )
2069{
2070 createPattern();
2071 ScPatternAttr& rPat = *mpPattern;
2072 ScDocumentImport& rDocImport = getDocImport();
2073 ScDocument& rDoc = getScDocument();
2074 if ( isCellXf() )
2075 {
2076 StylesBuffer& rStyles = getStyles();
2078
2080 if ( mpStyleSheet )
2081 {
2082 //rDoc.ApplySelectionStyle( static_cast<ScStyleSheet&>(*mpStyleSheet), rMarkData );
2083 rPat.SetStyleSheet(mpStyleSheet, false);
2084 }
2085 else
2086 {
2087 ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
2088 if (pStylePool)
2089 {
2090 ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>(
2091 pStylePool->Find(
2092 ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Para));
2093
2094 if (pStyleSheet)
2095 rPat.SetStyleSheet( pStyleSheet, false );
2096 }
2097 }
2098 }
2099 if ( nNumFmtId >= 0 )
2100 {
2101 ScPatternAttr aNumPat(rDoc.GetPool());
2102 mnScNumFmt = getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId, false );
2103 rPat.GetItemSet().Put(aNumPat.GetItemSet());
2104 }
2105
2106 if (!rDocImport.isLatinScript(mnScNumFmt))
2107 rAttrs.mbLatinNumFmtOnly = false;
2108
2109 if (!rPat.GetStyleName())
2110 return;
2111
2112 // Check for a gap between the last entry and this one.
2113 bool bHasGap = false;
2114 if (rAttrs.maAttrs.empty() && nRow1 > 0)
2115 // First attribute range doesn't start at row 0.
2116 bHasGap = true;
2117
2118 if (!rAttrs.maAttrs.empty() && rAttrs.maAttrs.back().nEndRow + 1 < nRow1)
2119 bHasGap = true;
2120
2121 if (bHasGap)
2122 {
2123 // Fill this gap with the default pattern.
2124 ScAttrEntry aEntry;
2125 aEntry.nEndRow = nRow1 - 1;
2126 aEntry.pPattern = &rDoc.GetPool()->Put(*rAttrs.mpDefPattern);
2127 rAttrs.maAttrs.push_back(aEntry);
2128
2129 // Check if the default pattern is 'General'.
2130 if (!rDocImport.isLatinScript(*aEntry.pPattern))
2131 rAttrs.mbLatinNumFmtOnly = false;
2132 }
2133
2134 ScAttrEntry aEntry;
2135 aEntry.nEndRow = nRow2;
2136 aEntry.pPattern = &rDoc.GetPool()->Put(rPat);
2137 rAttrs.maAttrs.push_back(aEntry);
2138
2139 if (!rDocImport.isLatinScript(*aEntry.pPattern))
2140 rAttrs.mbLatinNumFmtOnly = false;
2141}
2142
2143void Xf::writeToDoc( ScDocumentImport& rDoc, const ScRange& rRange )
2144{
2145 const StylesBuffer& rStyles = getStyles();
2146
2147 if (isCellXf())
2148 {
2149 // Cell style name.
2150 OUString aStyleName = rStyles.createCellStyle(maModel.mnStyleXfId);
2151
2152 ScStyleSheet* pStyleSheet =
2153 static_cast<ScStyleSheet*>(
2154 rDoc.getDoc().GetStyleSheetPool()->Find(aStyleName, SfxStyleFamily::Para));
2155
2156 if (pStyleSheet)
2157 {
2159 rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab(),
2160 *pStyleSheet);
2161 }
2162 }
2163
2164 const ScPatternAttr& rAttr = createPattern();
2166 rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab(), rAttr);
2167}
2168
2169const ::ScPatternAttr&
2170Xf::createPattern( bool bSkipPoolDefs )
2171{
2172 if( mpPattern )
2173 return *mpPattern;
2174 mpPattern.reset( new ::ScPatternAttr( getScDocument().GetPool() ) );
2175 SfxItemSet& rItemSet = mpPattern->GetItemSet();
2176 /* Enables the used flags, if the formatting attributes differ from the
2177 style XF. In cell XFs Excel uses the cell attributes, if they differ
2178 from the parent style XF (even if the used flag is switched off).
2179 #109899# ...or if the respective flag is not set in parent style XF.
2180 */
2181 StylesBuffer& rStyles = getStyles();
2182
2183 const Xf* pStyleXf = isCellXf() ? rStyles.getStyleXf( maModel.mnStyleXfId ).get() : nullptr;
2184 if( pStyleXf && !mpStyleSheet )
2185 {
2188 OSL_ENSURE( mpStyleSheet, "Xf::createPattern - no parentStyle created" );
2189
2190 const XfModel& rStyleData = pStyleXf->maModel;
2191 if( !maModel.mbFontUsed )
2192 maModel.mbFontUsed = !rStyleData.mbFontUsed || (maModel.mnFontId != rStyleData.mnFontId);
2193 if( !maModel.mbNumFmtUsed )
2194 maModel.mbNumFmtUsed = !rStyleData.mbNumFmtUsed || (maModel.mnNumFmtId != rStyleData.mnNumFmtId);
2195 if( !maModel.mbAlignUsed )
2196 maModel.mbAlignUsed = !rStyleData.mbAlignUsed || !(maAlignment.getApiData() == pStyleXf->maAlignment.getApiData());
2197 if( !maModel.mbProtUsed )
2198 maModel.mbProtUsed = !rStyleData.mbProtUsed || !(maProtection.getApiData() == pStyleXf->maProtection.getApiData());
2199 if( !maModel.mbBorderUsed )
2201 if( !maModel.mbAreaUsed )
2203 }
2204 // cell protection
2205 if( maModel.mbProtUsed )
2206 {
2207 maProtection.fillToItemSet( rItemSet, bSkipPoolDefs );
2208 }
2209
2210 // font
2211 if( maModel.mbFontUsed )
2212 {
2213 rStyles.writeFontToItemSet( rItemSet, maModel.mnFontId, bSkipPoolDefs );
2214 }
2215
2216 // value format
2217 if( maModel.mbNumFmtUsed )
2218 {
2219 mnScNumFmt = rStyles.writeNumFmtToItemSet( rItemSet, maModel.mnNumFmtId, bSkipPoolDefs );
2220 }
2221 // alignment
2222 if( maModel.mbAlignUsed )
2223 {
2224 maAlignment.fillToItemSet( rItemSet, bSkipPoolDefs );
2225 }
2226
2227 // border
2228 if( maModel.mbBorderUsed )
2229 {
2230 rStyles.writeBorderToItemSet( rItemSet, maModel.mnBorderId, bSkipPoolDefs );
2231 }
2232
2233 // area
2234 if( maModel.mbAreaUsed )
2235 {
2236 rStyles.writeFillToItemSet( rItemSet, maModel.mnFillId, bSkipPoolDefs );
2237 }
2238
2239 /* #i38709# Decide which rotation reference mode to use. If any outer
2240 border line of the cell is set (either explicitly or via cell style),
2241 and the cell contents are rotated, set rotation reference to bottom of
2242 cell. This causes the borders to be painted rotated with the text. */
2243 if( const Alignment* pAlignment = maModel.mbAlignUsed ? &maAlignment : (pStyleXf ? &pStyleXf->maAlignment : nullptr) )
2244 {
2246 sal_Int32 nBorderId = maModel.mbBorderUsed ? maModel.mnBorderId : (pStyleXf ? pStyleXf->maModel.mnBorderId : -1);
2247 if( const Border* pBorder = rStyles.getBorder( nBorderId ).get() )
2248 {
2249 if( (pAlignment->getApiData().mnRotation) && pBorder->getApiData().hasAnyOuterBorder() )
2250 {
2251 meRotationRef = css::table::CellVertJustify2::BOTTOM;
2252 eRotateMode = SVX_ROTATE_MODE_BOTTOM;
2253 }
2254 }
2255 ScfTools::PutItem( rItemSet, SvxRotateModeItem( eRotateMode, ATTR_ROTATE_MODE ), bSkipPoolDefs );
2256 }
2257
2258 return *mpPattern;
2259}
2260
2261Dxf::Dxf( const WorkbookHelper& rHelper ) :
2262 WorkbookHelper( rHelper )
2263{
2264}
2265
2266FontRef const & Dxf::createFont( bool bAlwaysNew )
2267{
2268 if( bAlwaysNew || !mxFont )
2269 mxFont = std::make_shared<Font>( *this, true );
2270 return mxFont;
2271}
2272
2273BorderRef const & Dxf::createBorder( bool bAlwaysNew )
2274{
2275 if( bAlwaysNew || !mxBorder )
2276 mxBorder = std::make_shared<Border>( *this, true );
2277 return mxBorder;
2278}
2279
2280FillRef const & Dxf::createFill( bool bAlwaysNew )
2281{
2282 if( bAlwaysNew || !mxFill )
2283 mxFill = std::make_shared<Fill>( *this, true );
2284 return mxFill;
2285}
2286
2287void Dxf::importNumFmt( const AttributeList& rAttribs )
2288{
2289 // don't propagate number formats defined in Dxf entries
2290 // they can have the same id ( but different format codes ) as those
2291 // defined globally earlier. We discard the id defined in XML_numFmtId
2292 // and generate one ourselves ( this assumes that the normal numberformat
2293 // import has already taken place )
2294 sal_Int32 nNumFmtId = getStyles().nextFreeNumFmtId();
2295 OUString aFmtCode = rAttribs.getXString( XML_formatCode, OUString() );
2296 mxNumFmt = getStyles().createNumFmt( nNumFmtId, aFmtCode );
2297}
2298
2300{
2301 sal_Int32 nNumFmtId = -1;
2302 OUString aFmtCode;
2303 sal_uInt16 nRecCount;
2304 rStrm.skip( 4 ); // flags
2305 nRecCount = rStrm.readuInt16();
2306 for( sal_uInt16 nRec = 0; !rStrm.isEof() && (nRec < nRecCount); ++nRec )
2307 {
2308 sal_uInt16 nSubRecId, nSubRecSize;
2309 sal_Int64 nRecEnd = rStrm.tell();
2310 nSubRecId = rStrm.readuInt16();
2311 nSubRecSize = rStrm.readuInt16();
2312 nRecEnd += nSubRecSize;
2313 switch( nSubRecId )
2314 {
2315 case BIFF12_DXF_FILL_PATTERN: createFill( false )->importDxfPattern( rStrm ); break;
2316 case BIFF12_DXF_FILL_FGCOLOR: createFill( false )->importDxfFgColor( rStrm ); break;
2317 case BIFF12_DXF_FILL_BGCOLOR: createFill( false )->importDxfBgColor( rStrm ); break;
2318 case BIFF12_DXF_FILL_GRADIENT: createFill( false )->importDxfGradient( rStrm ); break;
2319 case BIFF12_DXF_FILL_STOP: createFill( false )->importDxfStop( rStrm ); break;
2320 case BIFF12_DXF_FONT_COLOR: createFont( false )->importDxfColor( rStrm ); break;
2321 case BIFF12_DXF_BORDER_TOP: createBorder( false )->importDxfBorder( XLS_TOKEN( top ), rStrm ); break;
2322 case BIFF12_DXF_BORDER_BOTTOM: createBorder( false )->importDxfBorder( XLS_TOKEN( bottom ), rStrm ); break;
2323 case BIFF12_DXF_BORDER_LEFT: createBorder( false )->importDxfBorder( XLS_TOKEN( left ), rStrm ); break;
2324 case BIFF12_DXF_BORDER_RIGHT: createBorder( false )->importDxfBorder( XLS_TOKEN( right ), rStrm ); break;
2325 case BIFF12_DXF_FONT_NAME: createFont( false )->importDxfName( rStrm ); break;
2326 case BIFF12_DXF_FONT_WEIGHT: createFont( false )->importDxfWeight( rStrm ); break;
2327 case BIFF12_DXF_FONT_UNDERLINE: createFont( false )->importDxfUnderline( rStrm ); break;
2328 case BIFF12_DXF_FONT_ESCAPEMENT: createFont( false )->importDxfEscapement( rStrm ); break;
2329 case BIFF12_DXF_FONT_ITALIC: createFont( false )->importDxfFlag( XML_i, rStrm ); break;
2330 case BIFF12_DXF_FONT_STRIKE: createFont( false )->importDxfFlag( XML_strike, rStrm ); break;
2331 case BIFF12_DXF_FONT_OUTLINE: createFont( false )->importDxfFlag( XML_outline, rStrm ); break;
2332 case BIFF12_DXF_FONT_SHADOW: createFont( false )->importDxfFlag( XML_shadow, rStrm ); break;
2333 case BIFF12_DXF_FONT_HEIGHT: createFont( false )->importDxfHeight( rStrm ); break;
2334 case BIFF12_DXF_FONT_SCHEME: createFont( false )->importDxfScheme( rStrm ); break;
2335 case BIFF12_DXF_NUMFMT_CODE: aFmtCode = BiffHelper::readString( rStrm, false ); break;
2336 case BIFF12_DXF_NUMFMT_ID: nNumFmtId = rStrm.readuInt16(); break;
2337 }
2338 rStrm.seek( nRecEnd );
2339 }
2340 OSL_ENSURE( !rStrm.isEof() && (rStrm.getRemaining() == 0), "Dxf::importDxf - unexpected remaining data" );
2341 mxNumFmt = getStyles().createNumFmt( nNumFmtId, aFmtCode );
2342}
2343
2345{
2346 if( mxFont )
2347 mxFont->finalizeImport();
2348 bool bRTL = false;
2349 // number format already finalized by the number formats buffer
2350 if( mxAlignment )
2351 {
2352 mxAlignment->finalizeImport();
2353 // how do we detect RTL when text dir is OOX_XF_CONTEXT? ( seems you
2354 // would need access to the cell content, which we don't here )
2355 if ( mxAlignment->getModel().mnTextDir == OOX_XF_TEXTDIR_RTL )
2356 bRTL = true;
2357 }
2358 if( mxProtection )
2359 mxProtection->finalizeImport();
2360 if( mxBorder )
2361 {
2362 mxBorder->finalizeImport( bRTL );
2363 }
2364 if( mxFill )
2365 mxFill->finalizeImport();
2366}
2367
2369{
2370 if (mxFont)
2371 mxFont->fillToItemSet(rSet, false);
2372 if (mxNumFmt)
2373 mxNumFmt->fillToItemSet(rSet);
2374 if (mxAlignment)
2375 mxAlignment->fillToItemSet(rSet);
2376 if (mxProtection)
2377 mxProtection->fillToItemSet(rSet);
2378 if (mxBorder)
2379 mxBorder->fillToItemSet(rSet);
2380 if (mxFill)
2381 mxFill->fillToItemSet(rSet);
2382}
2383
2384namespace {
2385
2386const char* const sppcStyleNames[] =
2387{
2388 "Normal",
2389 "RowLevel_", // outline level will be appended
2390 "ColLevel_", // outline level will be appended
2391 "Comma",
2392 "Currency",
2393 "Percent",
2394 "Comma [0]", // new in BIFF4
2395 "Currency [0]",
2396 "Hyperlink", // new in BIFF8
2397 "Followed Hyperlink",
2398 "Note", // new in OOX
2399 "Warning Text",
2400 nullptr,
2401 nullptr,
2402 nullptr,
2403 "Title",
2404 "Heading 1",
2405 "Heading 2",
2406 "Heading 3",
2407 "Heading 4",
2408 "Input",
2409 "Output",
2410 "Calculation",
2411 "Check Cell",
2412 "Linked Cell",
2413 "Total",
2414 "Good",
2415 "Bad",
2416 "Neutral",
2417 "Accent1",
2418 "20% - Accent1",
2419 "40% - Accent1",
2420 "60% - Accent1",
2421 "Accent2",
2422 "20% - Accent2",
2423 "40% - Accent2",
2424 "60% - Accent2",
2425 "Accent3",
2426 "20% - Accent3",
2427 "40% - Accent3",
2428 "60% - Accent3",
2429 "Accent4",
2430 "20% - Accent4",
2431 "40% - Accent4",
2432 "60% - Accent4",
2433 "Accent5",
2434 "20% - Accent5",
2435 "40% - Accent5",
2436 "60% - Accent5",
2437 "Accent6",
2438 "20% - Accent6",
2439 "40% - Accent6",
2440 "60% - Accent6",
2441 "Explanatory Text"
2442};
2443const sal_Int32 snStyleNamesCount = static_cast< sal_Int32 >( SAL_N_ELEMENTS( sppcStyleNames ) );
2444
2445OUString lclGetBuiltinStyleName( sal_Int32 nBuiltinId, std::u16string_view rName, sal_Int32 nLevel = 0 )
2446{
2447 OSL_ENSURE( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount), "lclGetBuiltinStyleName - unknown built-in style" );
2448 OUStringBuffer aStyleName("Excel Built-in ");
2449 if( (0 <= nBuiltinId) && (nBuiltinId < snStyleNamesCount) && (sppcStyleNames[ nBuiltinId ] != nullptr) )
2450 aStyleName.appendAscii( sppcStyleNames[ nBuiltinId ] );
2451 else if( !rName.empty() )
2452 aStyleName.append( rName );
2453 else
2454 aStyleName.append( nBuiltinId );
2455 if( (nBuiltinId == OOX_STYLE_ROWLEVEL) || (nBuiltinId == OOX_STYLE_COLLEVEL) )
2456 aStyleName.append( nLevel );
2457 return aStyleName.makeStringAndClear();
2458}
2459
2460OUString lclCreateStyleName( const CellStyleModel& rModel )
2461{
2462 return rModel.mbBuiltin ? lclGetBuiltinStyleName( rModel.mnBuiltinId, rModel.maName, rModel.mnLevel ) : rModel.maName;
2463}
2464
2465} // namespace
2466
2468 mnXfId( -1 ),
2469 mnBuiltinId( -1 ),
2470 mnLevel( 0 ),
2471 mbBuiltin( false ),
2472 mbCustom( false ),
2473 mbHidden( false )
2474{
2475}
2476
2478{
2479 return mbBuiltin && (mnBuiltinId >= 0);
2480}
2481
2483{
2484 return mbBuiltin && (mnBuiltinId == OOX_STYLE_NORMAL);
2485}
2486
2488 WorkbookHelper( rHelper ),
2489 mbCreated( false ),
2490 mpStyleSheet( nullptr )
2491{
2492}
2493
2495{
2496 maModel.maName = rAttribs.getXString( XML_name, OUString() );
2497 maModel.mnXfId = rAttribs.getInteger( XML_xfId, -1 );
2498 maModel.mnBuiltinId = rAttribs.getInteger( XML_builtinId, -1 );
2499 maModel.mnLevel = rAttribs.getInteger( XML_iLevel, 0 );
2500 maModel.mbBuiltin = rAttribs.hasAttribute( XML_builtinId );
2501 maModel.mbCustom = rAttribs.getBool( XML_customBuiltin, false );
2502 maModel.mbHidden = rAttribs.getBool( XML_hidden, false );
2503}
2504
2506{
2507 sal_uInt16 nFlags;
2508 maModel.mnXfId = rStrm.readInt32();
2509 nFlags = rStrm.readuInt16();
2510 maModel.mnBuiltinId = rStrm.readInt8();
2511 maModel.mnLevel = rStrm.readInt8();
2512 rStrm >> maModel.maName;
2513 maModel.mbBuiltin = getFlag( nFlags, BIFF12_CELLSTYLE_BUILTIN );
2514 maModel.mbCustom = getFlag( nFlags, BIFF12_CELLSTYLE_CUSTOM );
2515 maModel.mbHidden = getFlag( nFlags, BIFF12_CELLSTYLE_HIDDEN );
2516}
2517
2519{
2520
2521 // #i1624# #i1768# ignore unnamed user styles
2522 bool bDefStyle = maModel.isDefaultStyle();
2523 if( !mbCreated )
2524 {
2525 if ( bDefStyle && maFinalName.isEmpty() )
2526 maFinalName = ScResId( STR_STYLENAME_STANDARD );
2527 mbCreated = maFinalName.isEmpty();
2528 }
2529
2530 if( mbCreated || mpStyleSheet )
2531 return;
2532
2533 bool bCreatePattern = false;
2534 Xf* pXF = getStyles().getStyleXf( maModel.mnXfId ).get();
2535 ::ScDocument& rDoc = getScDocument();
2536
2537 if( bDefStyle )
2538 {
2539 // use existing "Default" style sheet
2540 mpStyleSheet = static_cast< ScStyleSheet* >( rDoc.GetStyleSheetPool()->Find(
2541 ScResId( STR_STYLENAME_STANDARD ), SfxStyleFamily::Para ) );
2542 OSL_ENSURE( mpStyleSheet, "CellStyle::createStyle - Default style not found" );
2543 bCreatePattern = true;
2544 }
2545 else
2546 {
2547 mpStyleSheet = static_cast< ScStyleSheet* >( rDoc.GetStyleSheetPool()->Find( maFinalName, SfxStyleFamily::Para ) );
2548 if( !mpStyleSheet )
2549 {
2550 mpStyleSheet = &static_cast< ScStyleSheet& >( rDoc.GetStyleSheetPool()->Make( maFinalName, SfxStyleFamily::Para, SfxStyleSearchBits::UserDefined ) );
2551 bCreatePattern = true;
2552 }
2553 }
2554
2555 // bDefStyle==true omits default pool items in CreatePattern()
2556 if( bCreatePattern && mpStyleSheet && pXF )
2557 mpStyleSheet->GetItemSet().Put( pXF->createPattern( bDefStyle ).GetItemSet() );
2558}
2559
2560void CellStyle::finalizeImport( const OUString& rFinalName )
2561{
2562 maFinalName = rFinalName;
2563 if( !maModel.isBuiltin() || maModel.mbCustom )
2565}
2566
2568 WorkbookHelper( rHelper )
2569{
2570}
2571
2573{
2574 CellStyleRef xCellStyle = std::make_shared<CellStyle>( *this );
2575 xCellStyle->importCellStyle( rAttribs );
2576 insertCellStyle( xCellStyle );
2577 return xCellStyle;
2578}
2579
2581{
2582 CellStyleRef xCellStyle = std::make_shared<CellStyle>( *this );
2583 xCellStyle->importCellStyle( rStrm );
2584 insertCellStyle( xCellStyle );
2585 return xCellStyle;
2586}
2587
2589{
2590 // calculate final names of all styles
2592 CellStyleNameMap aCellStyles;
2593 CellStyleVector aConflictNameStyles;
2594
2595 /* First, reserve style names that are built-in in Calc. This causes that
2596 imported cell styles get different unused names and thus do not try to
2597 overwrite these built-in styles. */
2598 try
2599 {
2600 // unfortunately, com.sun.star.style.StyleFamily does not implement XEnumerationAccess...
2601 Reference< XIndexAccess > xStyleFamilyIA( getCellStyleFamily(), UNO_QUERY_THROW );
2602 for( sal_Int32 nIndex = 0, nCount = xStyleFamilyIA->getCount(); nIndex < nCount; ++nIndex )
2603 {
2604 Reference< XStyle > xStyle( xStyleFamilyIA->getByIndex( nIndex ), UNO_QUERY_THROW );
2605 if( !xStyle->isUserDefined() )
2606 {
2607 // create an empty entry by using ::std::map<>::operator[]
2608 aCellStyles[ xStyle->getName() ];
2609 }
2610 }
2611 }
2612 catch( Exception& )
2613 {
2614 }
2615
2616 /* Calculate names of built-in styles. Store styles with reserved names
2617 in the aConflictNameStyles list. */
2618 for( const auto& rxStyle : maBuiltinStyles )
2619 {
2620 const CellStyleModel& rModel = rxStyle->getModel();
2621 if (rModel.isDefaultStyle())
2622 continue;
2623
2624 OUString aStyleName = lclCreateStyleName( rModel );
2625 /* If a builtin style entry already exists,
2626 we just stick with the last definition and ignore
2627 the preceding ones. */
2628 aCellStyles[ aStyleName ] = rxStyle;
2629 }
2630
2631 /* Calculate names of user defined styles. Store styles with reserved
2632 names in the aConflictNameStyles list. */
2633 for( const auto& rxStyle : maUserStyles )
2634 {
2635 const CellStyleModel& rModel = rxStyle->getModel();
2636 OUString aStyleName = lclCreateStyleName( rModel );
2637 // #i1624# #i1768# ignore unnamed user styles
2638 if( aStyleName.getLength() > 0 )
2639 {
2640 if( aCellStyles.find( aStyleName ) != aCellStyles.end() )
2641 aConflictNameStyles.push_back( rxStyle );
2642 else
2643 aCellStyles[ aStyleName ] = rxStyle;
2644 }
2645 }
2646
2647 // find unused names for all styles with conflicting names
2648 // having the index counter outside the loop prevents performance problems with opening some pathological documents (tdf#62095)
2649 sal_Int32 nIndex = 0;
2650 for( const auto& rxStyle : aConflictNameStyles )
2651 {
2652 const CellStyleModel& rModel = rxStyle->getModel();
2653 OUString aStyleName = lclCreateStyleName( rModel );
2654 OUString aUnusedName;
2655 do
2656 {
2657 aUnusedName = aStyleName + OUStringChar(' ') + OUString::number( ++nIndex );
2658 }
2659 while( !aCellStyles.try_emplace( aUnusedName, rxStyle ).second );
2660 }
2661
2662 // set final names and create user-defined and modified built-in cell styles
2663 aCellStyles.forEachMemWithKey( &CellStyle::finalizeImport );
2664}
2665
2667{
2668 return mxDefStyle ? mxDefStyle->getModel().mnXfId : -1;
2669}
2670
2672{
2673 return createCellStyle( mxDefStyle );
2674}
2675
2676OUString CellStyleBuffer::createCellStyle( sal_Int32 nXfId ) const
2677{
2678 return createCellStyle( maStylesByXf.get( nXfId ) );
2679}
2680
2682{
2683 return getCellStyleSheet( maStylesByXf.get( nXfId ) );
2684}
2685
2686// private --------------------------------------------------------------------
2687
2689{
2690 const CellStyleModel& rModel = xCellStyle->getModel();
2691 if( rModel.mnXfId < 0 )
2692 return;
2693
2694 // insert into the built-in map or user defined map
2695 (rModel.isBuiltin() ? maBuiltinStyles : maUserStyles).push_back( xCellStyle );
2696
2697 // insert into the XF identifier map
2698 OSL_ENSURE( maStylesByXf.count( rModel.mnXfId ) == 0, "CellStyleBuffer::insertCellStyle - multiple styles with equal XF identifier" );
2699 maStylesByXf[ rModel.mnXfId ] = xCellStyle;
2700
2701 // remember default cell style
2702 if( rModel.isDefaultStyle() )
2703 mxDefStyle = xCellStyle;
2704}
2705
2707{
2708 ::ScStyleSheet* pStyleSheet = nullptr;
2709 if ( rxCellStyle )
2710 pStyleSheet = rxCellStyle->getStyleSheet();
2711 return pStyleSheet;
2712}
2713
2715{
2716 if( rxCellStyle )
2717 {
2718 rxCellStyle->createCellStyle();
2719 const OUString& rStyleName = rxCellStyle->getFinalStyleName();
2720 if( !rStyleName.isEmpty() )
2721 return rStyleName;
2722 }
2723 // on error: fallback to default style
2724 return lclGetBuiltinStyleName( OOX_STYLE_NORMAL, u"" );
2725}
2726
2728 mnAutoFormatId( 0 ),
2729 mbApplyNumFmt( false ),
2730 mbApplyFont( false ),
2731 mbApplyAlignment( false ),
2732 mbApplyBorder( false ),
2733 mbApplyFill( false ),
2734 mbApplyProtection( false )
2735{
2736}
2737
2739 WorkbookHelper( rHelper ),
2740 maPalette( rHelper ),
2741 maNumFmts( rHelper ),
2742 maCellStyles( rHelper )
2743{
2744}
2745
2747{
2748 FontRef xFont = std::make_shared<Font>( *this, false );
2749 maFonts.push_back( xFont );
2750 return xFont;
2751}
2752
2753NumberFormatRef StylesBuffer::createNumFmt( sal_Int32 nNumFmtId, std::u16string_view aFmtCode )
2754{
2755 return maNumFmts.createNumFmt( nNumFmtId, aFmtCode );
2756}
2757
2759{
2760 return maNumFmts.nextFreeId();
2761}
2762
2764{
2765 BorderRef xBorder = std::make_shared<Border>( *this, false );
2766 maBorders.push_back( xBorder );
2767 return xBorder;
2768}
2769
2771{
2772 FillRef xFill = std::make_shared<Fill>( *this, false );
2773 maFills.push_back( xFill );
2774 return xFill;
2775}
2776
2778{
2779 XfRef xXf = std::make_shared<Xf>( *this );
2780 maCellXfs.push_back( xXf );
2781 return xXf;
2782}
2783
2785{
2786 XfRef xXf = std::make_shared<Xf>( *this );
2787 maStyleXfs.push_back( xXf );
2788 return xXf;
2789}
2790
2792{
2793 DxfRef xDxf = std::make_shared<Dxf>( *this );
2794 maDxfs.push_back( xDxf );
2795 return xDxf;
2796}
2797
2799{
2800 DxfRef xDxf = std::make_shared<Dxf>( *this );
2801 maExtDxfs.push_back( xDxf );
2802 return xDxf;
2803}
2804
2806{
2807 maPalette.importPaletteColor( rAttribs );
2808}
2809
2811{
2812 return maNumFmts.importNumFmt( rAttribs );
2813}
2814
2816{
2817 return maCellStyles.importCellStyle( rAttribs );
2818}
2819
2821{
2823}
2824
2826{
2828}
2829
2831{
2833}
2834
2836{
2837 // fonts first, are needed to finalize unit converter and XFs below
2839 // finalize unit coefficients after default font is known
2841 // number formats
2843 // borders and fills
2844 // is there a document wide RTL setting that we
2845 // would/could need to pass to finalizeImport here ?
2848 // style XFs and cell XFs
2851 // built-in and user defined cell styles
2853 // differential formatting (for conditional formatting)
2855}
2856
2857::Color StylesBuffer::getPaletteColor( sal_Int32 nPaletteIdx ) const
2858{
2859 return maPalette.getColor( nPaletteIdx );
2860}
2861
2862FontRef StylesBuffer::getFont( sal_Int32 nFontId ) const
2863{
2864 return maFonts.get( nFontId );
2865}
2866
2867BorderRef StylesBuffer::getBorder( sal_Int32 nBorderId ) const
2868{
2869 return maBorders.get( nBorderId );
2870}
2871
2872XfRef StylesBuffer::getCellXf( sal_Int32 nXfId ) const
2873{
2874 return maCellXfs.get( nXfId );
2875}
2876
2877XfRef StylesBuffer::getStyleXf( sal_Int32 nXfId ) const
2878{
2879 return maStyleXfs.get( nXfId );
2880}
2881
2883{
2884 FontRef xFont;
2885 if( const Xf* pXf = getCellXf( nXfId ).get() )
2886 xFont = pXf->getFont();
2887 return xFont;
2888}
2889
2891{
2892 FontRef xDefFont;
2893 if( const Xf* pXf = getStyleXf( maCellStyles.getDefaultXfId() ).get() )
2894 xDefFont = pXf->getFont();
2895 // no font from styles - try first loaded font (e.g. BIFF2)
2896 if( !xDefFont )
2897 xDefFont = maFonts.get( 0 );
2898 OSL_ENSURE( xDefFont, "StylesBuffer::getDefaultFont - no default font found" );
2899 return xDefFont;
2900}
2901
2903{
2904 FontRef xDefFont = getDefaultFont();
2905 return xDefFont ? xDefFont->getModel() : getTheme().getDefaultFontModel();
2906}
2907
2908bool StylesBuffer::equalBorders( sal_Int32 nBorderId1, sal_Int32 nBorderId2 )
2909{
2910 // in OOXML, borders are assumed to be unique
2911 return nBorderId1 == nBorderId2;
2912}
2913
2914bool StylesBuffer::equalFills( sal_Int32 nFillId1, sal_Int32 nFillId2 )
2915{
2916 // in OOXML, fills are assumed to be unique
2917 return nFillId1 == nFillId2;
2918}
2919
2921{
2923}
2924
2925OUString StylesBuffer::createCellStyle( sal_Int32 nXfId ) const
2926{
2927 return maCellStyles.createCellStyle( nXfId );
2928}
2929
2931{
2932 return maCellStyles.getCellStyleSheet( nXfId );
2933}
2934
2935OUString StylesBuffer::createDxfStyle( sal_Int32 nDxfId ) const
2936{
2937 OUString& rStyleName = maDxfStyles[ nDxfId ];
2938 if (!rStyleName.isEmpty())
2939 return rStyleName;
2940
2941 if (Dxf* pDxf = maDxfs.get(nDxfId).get())
2942 {
2943 // FIXME: How can we know whether this dxf is for conditional formatting,
2944 // not for color filter? Currently this style is created for each dxf
2945 // (which might only be used by color filter)
2946 rStyleName = "ConditionalStyle_" + OUString::number(nDxfId + 1);
2947
2948 // Create a cell style. This may overwrite an existing style if
2949 // one with the same name exists.
2951 *getScDocument().GetStyleSheetPool(), rStyleName, true);
2952
2953 rStyleSheet.ResetParent();
2954 SfxItemSet& rStyleItemSet =
2955 rStyleSheet.GetItemSet();
2956
2957 pDxf->fillToItemSet(rStyleItemSet);
2958
2959 }
2960
2961 // on error: fallback to default style
2962 if (rStyleName.isEmpty())
2963 rStyleName = maCellStyles.getDefaultStyleName();
2964
2965 return rStyleName;
2966}
2967
2968OUString StylesBuffer::createExtDxfStyle( sal_Int32 nDxfId ) const
2969{
2970 OUString rStyleName;
2971
2972 if (Dxf* pDxf = maExtDxfs.get(nDxfId).get())
2973 {
2974 rStyleName = "ExtConditionalStyle_" + OUString::number(nDxfId + 1);
2975
2976 // Create a cell style. This may overwrite an existing style if
2977 // one with the same name exists.
2979 *getScDocument().GetStyleSheetPool(), rStyleName, true);
2980
2981 rStyleSheet.ResetParent();
2982 SfxItemSet& rStyleItemSet =
2983 rStyleSheet.GetItemSet();
2984
2985 pDxf->fillToItemSet(rStyleItemSet);
2986 }
2987
2988 // on error: fallback to default style
2989 if (rStyleName.isEmpty())
2990 rStyleName = maCellStyles.getDefaultStyleName();
2991
2992 return rStyleName;
2993}
2994
2995void StylesBuffer::writeFontToItemSet( SfxItemSet& rItemSet, sal_Int32 nFontId, bool bSkipPoolDefs ) const
2996{
2997 if( Font* pFont = maFonts.get( nFontId ).get() )
2998 pFont->fillToItemSet( rItemSet, false, bSkipPoolDefs );
2999}
3000
3001sal_uInt32 StylesBuffer::writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_uInt32 nNumFmtId, bool bSkipPoolDefs ) const
3002{
3003 return maNumFmts.fillToItemSet( rItemSet, nNumFmtId, bSkipPoolDefs );
3004}
3005
3006void StylesBuffer::writeBorderToItemSet( SfxItemSet& rItemSet, sal_Int32 nBorderId, bool bSkipPoolDefs ) const
3007{
3008 if( Border* pBorder = maBorders.get( nBorderId ).get() )
3009 pBorder->fillToItemSet( rItemSet, bSkipPoolDefs );
3010}
3011
3012void StylesBuffer::writeFillToItemSet( SfxItemSet& rItemSet, sal_Int32 nFillId, bool bSkipPoolDefs ) const
3013{
3014 if( Fill* pFill = maFills.get( nFillId ).get() )
3015 pFill->fillToItemSet( rItemSet, bSkipPoolDefs );
3016}
3017
3018bool operator==( const XfModel& rXfModel1, const XfModel& rXfModel2 )
3019{
3020 return ( rXfModel1.mbCellXf == rXfModel2.mbCellXf &&
3021 rXfModel1.mnStyleXfId == rXfModel2.mnStyleXfId &&
3022 rXfModel1.mbFontUsed == rXfModel2.mbFontUsed &&
3023 rXfModel1.mnFontId == rXfModel2.mnFontId &&
3024 rXfModel1.mbNumFmtUsed == rXfModel2.mbNumFmtUsed &&
3025 rXfModel1.mnNumFmtId == rXfModel2.mnNumFmtId &&
3026 rXfModel1.mbAlignUsed == rXfModel2.mbAlignUsed &&
3027 rXfModel1.mbBorderUsed == rXfModel2.mbBorderUsed &&
3028 rXfModel1.mnBorderId == rXfModel2.mnBorderId &&
3029 rXfModel1.mbAreaUsed == rXfModel2.mbAreaUsed &&
3030 rXfModel1.mnFillId == rXfModel2.mnFillId &&
3031 rXfModel1.mbProtUsed == rXfModel2.mbProtUsed );
3032}
3033
3034bool operator==( const Xf& rXf1, const Xf& rXf2 )
3035{
3036 if ( rXf1.maModel == rXf2.maModel )
3037 {
3038 if ( rXf1.maModel.mbAlignUsed )
3039 {
3040 if ( !( rXf1.maAlignment.getApiData() == rXf2.maAlignment.getApiData() ) )
3041 return false;
3042 }
3043 if ( rXf1.maModel.mbProtUsed )
3044 {
3045 if ( !( rXf1.maProtection.getApiData() == rXf2.maProtection.getApiData() ) )
3046 return false;
3047 }
3048 return true;
3049 }
3050 return false;
3051}
3052
3054 ScDocumentImport& rDoc, const ScRange& rRange, sal_Int32 nXfId ) const
3055{
3056 Xf* pXf = maCellXfs.get(nXfId).get();
3057 if (!pXf)
3058 return;
3059
3060 pXf->writeToDoc(rDoc, rRange);
3061}
3062
3063} // namespace oox
3064
3065/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
LineDescriptorList maRight
LineDescriptorList maLeft
constexpr auto convertTwipToMm100(N n)
OUString maName
sal_uInt8 GetBlue() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
Accessor class to ScDocument.
ScDocument & getDoc()
bool isLatinScript(sal_uInt32 nFormat)
small cache for hot call during import
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6181
SC_DLLPUBLIC void ApplyPatternAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScPatternAttr &rAttr)
Definition: document.cxx:4875
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6186
SC_DLLPUBLIC void ApplyStyleAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScStyleSheet &rStyle)
Definition: document.cxx:4940
const OUString * GetStyleName() const
Definition: patattr.cxx:1207
void SetStyleSheet(ScStyleSheet *pNewStyle, bool bClearDirectFormat=true)
Definition: patattr.cxx:1212
SfxItemSet & GetItemSet()
Definition: patattr.hxx:155
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
virtual SfxStyleSheetBase & Make(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits nMask=SfxStyleSearchBits::All) override
Definition: stlpool.cxx:72
virtual SC_DLLPUBLIC SfxItemSet & GetItemSet() override
Definition: stlsheet.cxx:128
SC_DLLPUBLIC void ResetParent()
Definition: stlsheet.cxx:123
static rtl_TextEncoding GetSystemTextEncoding()
Returns system text encoding for byte string conversion.
Definition: ftools.cxx:116
static void PutItem(SfxItemSet &rItemSet, const SfxPoolItem &rItem, sal_uInt16 nWhichId, bool bSkipPoolDef)
Puts the item into the passed item set.
Definition: ftools.cxx:214
static ScStyleSheet & MakeCellStyleSheet(ScStyleSheetPool &rPool, const OUString &rStyleName, bool bForceName)
Creates and returns a cell style sheet and inserts it into the pool.
Definition: ftools.cxx:257
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All) const
static bool LineToSvxLine(const css::table::BorderLine &rLine, editeng::SvxBorderLine &rSvxLine, bool bConvert)
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
void SetColor(const Color &rCol)
void SetFiltColor(const Color &rCol)
void SetLine(const editeng::SvxBorderLine *pNew)
bool hasAttribute(sal_Int32 nAttrToken) const
std::optional< OUString > getXString(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getIntegerHex(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< bool > getBool(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
std::optional< double > getDouble(sal_Int32 nAttrToken) const
static const VectorType::value_type * getVectorElement(const VectorType &rVector, sal_Int32 nIndex)
::Color getSystemColor(sal_Int32 nToken, ::Color nDefaultRgb=API_RGB_TRANSPARENT) const
bool setProperty(sal_Int32 nPropId, Type &&rValue)
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
mapped_type get(key_type nKey) const
value_type get(sal_Int32 nIndex) const
void forEachMem(FuncType pFunc) const
GraphicHelper & getGraphicHelper() const
void addExcelTintTransformation(double fTint)
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
void setSchemeClr(sal_Int32 nToken)
void setSrgbClr(sal_Int32 nRgb)
void setPaletteClr(sal_Int32 nPaletteIdx)
ApiAlignmentData maApiData
Alignment model data.
::SvxCellVerJustify GetScVerAlign() const
::SvxFrameDirection GetScFrameDir() const
::SvxCellHorJustify GetScHorAlign() const
void finalizeImport()
Final processing after import of all style settings.
void setBiff12Data(sal_uInt32 nFlags)
Sets the alignment attributes from the passed BIFF12 XF record data.
Alignment(const WorkbookHelper &rHelper)
const ApiAlignmentData & getApiData() const
Returns the converted API alignment data struct.
void fillToItemSet(SfxItemSet &rItemSet, bool bSkipPoolDefs=false) const
AlignmentModel maModel
void importAlignment(const AttributeList &rAttribs)
Sets all attributes from the alignment element.
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
Definition: biffhelper.cxx:79
void finalizeImport(bool bRTL)
Final processing after import of all style settings.
void importDxfBorder(sal_Int32 nElement, SequenceInputStream &rStrm)
Imports a border from a DXF record from the passed stream.
BorderModel maModel
BorderLineModel * getBorderLine(sal_Int32 nElement)
Returns the border line struct specified by the passed XML token identifier.
Border(const WorkbookHelper &rHelper, bool bDxf)
void importStyle(sal_Int32 nElement, const AttributeList &rAttribs)
Sets border attributes for the border line with the passed element identifier.
void importBorder(const AttributeList &rAttribs)
Sets global border attributes from the border element.
ApiBorderData maApiData
bool convertBorderLine(css::table::BorderLine2 &rBorderLine, const BorderLineModel &rModel)
Converts border line data to an API struct, returns true, if the line is marked as used.
void importColor(sal_Int32 nElement, const AttributeList &rAttribs)
Sets color attributes for the border line with the passed element identifier.
void fillToItemSet(SfxItemSet &rItemSet, bool bSkipPoolDefs=false) const
void finalizeImport()
Final processing after import of all style settings.
CellStyleRef importCellStyle(const AttributeList &rAttribs)
Appends and returns a new named cell style object.
OUString getDefaultStyleName() const
Returns the default style sheet for unused cells.
void insertCellStyle(CellStyleRef const &xCellStyle)
Inserts the passed cell style object into the internal maps.
CellStyleBuffer(const WorkbookHelper &rHelper)
CellStyleVector maUserStyles
All built-in cell styles.
CellStyleRef mxDefStyle
All cell styles, mapped by XF identifier.
sal_Int32 getDefaultXfId() const
Returns the XF identifier associated to the default cell style.
OUString createCellStyle(sal_Int32 nXfId) const
Creates the style sheet described by the style XF with the passed identifier.
CellStyleXfIdMap maStylesByXf
All user defined cell styles.
::ScStyleSheet * getCellStyleSheet(sal_Int32 nXfId) const
CellStyleVector maBuiltinStyles
bool mbCreated
Final style name used in API.
CellStyle(const WorkbookHelper &rHelper)
CellStyleModel maModel
void createCellStyle()
Creates the style sheet in the document described by this cell style object.
void finalizeImport(const OUString &rFinalName)
Stores the passed final style name and creates the cell style, if it is user-defined or modified buil...
void importCellStyle(const AttributeList &rAttribs)
Imports passed attributes from the cellStyle element.
::ScStyleSheet * mpStyleSheet
True = style sheet created.
::Color getColor(sal_Int32 nPaletteIdx) const
Returns the RGB value of the color with the passed index.
::std::vector< ::Color > maColors
size_t mnAppendIndex
List of RGB values.
ColorPalette(const WorkbookHelper &rHelper)
Constructs the color palette with predefined color values.
void importPaletteColor(const AttributeList &rAttribs)
Appends a new color from the passed attributes.
void appendColor(::Color nRGBValue)
Appends the passed color.
void setRgb(::Color nRgbValue, double fTint=0.0)
Sets the color to the passed RGB value.
void setTheme(sal_Int32 nThemeIdx, double fTint=0.0)
Sets the color to the passed theme index.
void importColorId(SequenceInputStream &rStrm)
Imports a 32-bit palette color identifier from the passed BIFF12 stream.
void setIndexed(sal_Int32 nPaletteIdx, double fTint=0.0)
Sets the color to the passed palette index.
void setAuto()
Sets the color to automatic.
void importColor(const AttributeList &rAttribs)
Imports the color from the passed attribute list.
BorderRef mxBorder
Protection data.
Dxf(const WorkbookHelper &rHelper)
FillRef mxFill
Border data.
FontRef const & createFont(bool bAlwaysNew=true)
Creates a new empty font object.
std::shared_ptr< Protection > mxProtection
Alignment data.
BorderRef const & createBorder(bool bAlwaysNew=true)
Creates a new empty border object.
std::shared_ptr< Alignment > mxAlignment
Number format data.
void fillToItemSet(SfxItemSet &rSet) const
void finalizeImport()
Final processing after import of all style settings.
NumberFormatRef mxNumFmt
Font data.
void importNumFmt(const AttributeList &rAttribs)
Inserts a new number format code.
FillRef const & createFill(bool bAlwaysNew=true)
Creates a new empty fill object.
void importDxf(SequenceInputStream &rStrm)
Imports the DXF record from the passed stream.
ExcelGraphicHelper(const WorkbookHelper &rHelper)
virtual ::Color getPaletteColor(sal_Int32 nPaletteIdx) const override
Derived classes may implement to resolve a palette index to an RGB color.
virtual ::Color getSchemeColor(sal_Int32 nToken) const override
Derived classes may implement to resolve a scheme color from the passed XML token identifier.
Contains cell fill attributes, either a pattern fill or a gradient fill.
void importFgColor(const AttributeList &rAttribs)
Sets the pattern color from the fgColor element.
void finalizeImport()
Final processing after import of all style settings.
void fillToItemSet(SfxItemSet &rItemSet, bool bSkipPoolDefs=false) const
ApiSolidFillData maApiData
void importDxfGradient(SequenceInputStream &rStrm)
Imports gradient settings from a DXF record.
GradientModelRef mxGradientModel
void importColor(const AttributeList &rAttribs, double fPosition)
Sets a color from the color element in a gradient fill.
PatternModelRef mxPatternModel
void importDxfFgColor(SequenceInputStream &rStrm)
Imports the pattern color from a DXF record.
Fill(const WorkbookHelper &rHelper, bool bDxf)
void importPatternFill(const AttributeList &rAttribs)
Sets attributes of a patternFill element.
void importBgColor(const AttributeList &rAttribs)
Sets the background color from the bgColor element.
void importFill(SequenceInputStream &rStrm)
Imports the FILL record from the passed stream.
void importDxfStop(SequenceInputStream &rStrm)
Imports gradient stop settings from a DXF record.
void importDxfPattern(SequenceInputStream &rStrm)
Imports the fill pattern from a DXF record.
void importDxfBgColor(SequenceInputStream &rStrm)
Imports the background color from a DXF record.
void importGradientFill(const AttributeList &rAttribs)
Sets attributes of a gradientFill element.
ApiFontUsedFlags maUsedFlags
void importDxfHeight(SequenceInputStream &rStrm)
Imports the font height from a DXF record.
void importDxfColor(SequenceInputStream &rStrm)
Imports the font color from a DXF record.
void importAttribs(sal_Int32 nElement, const AttributeList &rAttribs)
Sets font formatting attributes for the passed element.
void importDxfName(SequenceInputStream &rStrm)
Imports the font name from a DXF record.
void fillToItemSet(SfxItemSet &rItemSet, bool bEditEngineText, bool bSkipPoolDefs=false) const
void importDxfWeight(SequenceInputStream &rStrm)
Imports the font weight from a DXF record.
void writeToPropertySet(PropertySet &rPropSet) const
Writes all font attributes to the passed property set.
bool needsRichTextFormat() const
Returns true, if the font requires rich text formatting in Calc.
void importDxfFlag(sal_Int32 nElement, SequenceInputStream &rStrm)
Imports a font style flag from a DXF record.
void importDxfScheme(SequenceInputStream &rStrm)
Imports the font scheme from a DXF record.
Font(const WorkbookHelper &rHelper, bool bDxf)
void writeToPropertyMap(PropertyMap &rPropMap) const
Writes all font attributes to the passed property map.
void finalizeImport()
Final processing after import of all style settings.
void importDxfEscapement(SequenceInputStream &rStrm)
Imports the font escapement style from a DXF record.
ApiFontData maApiData
FontModel maModel
void importFont(SequenceInputStream &rStrm)
Imports the FONT record from the passed stream.
void importDxfUnderline(SequenceInputStream &rStrm)
Imports the font underline style from a DXF record.
NumberFormatRef createNumFmt(sal_uInt32 nNumFmtId, std::u16string_view aFmtCode)
Inserts a new number format.
NumberFormatRef importNumFmt(const AttributeList &rAttribs)
Inserts a new number format code.
sal_uInt32 fillToItemSet(SfxItemSet &rItemSet, sal_uInt32 nNumFmtId, bool bSkipPoolDefs) const
void finalizeImport()
Final processing after import of all style settings.
void setBiff12Data(sal_uInt32 nFlags)
Sets the protection attributes from the passed BIFF12 XF record data.
void importProtection(const AttributeList &rAttribs)
Sets all attributes from the protection element.
Protection(const WorkbookHelper &rHelper)
void finalizeImport()
Final processing after import of all style settings.
const ApiProtectionData & getApiData() const
Returns the converted API protection data struct.
ApiProtectionData maApiData
Protection model data.
void fillToItemSet(SfxItemSet &rItemSet, bool bSkipPoolDefs=false) const
ProtectionModel maModel
NumberFormatsBuffer maNumFmts
List of font objects.
CellStyleRef importCellStyle(const AttributeList &rAttribs)
Appends and returns a new named cell style object.
XfRef getStyleXf(sal_Int32 nXfId) const
Returns the specified style format object.
const FontModel & getDefaultFontModel() const
Returns the model of the default application font (used in the "Normal" cell style).
FontRef createFont()
Creates a new empty font object.
::ScStyleSheet * getCellStyleSheet(sal_Int32 nXfId) const
static bool equalFills(sal_Int32 nFillId1, sal_Int32 nFillId2)
Returns true, if the specified fills are equal.
XfVector maCellXfs
List of cell area fill objects.
void writeFillToItemSet(SfxItemSet &rItemSet, sal_Int32 nFillId, bool bSkipPoolDefs) const
Writes the fill attributes of the specified fill data to the passed property map.
void writeCellXfToDoc(ScDocumentImport &rDoc, const ScRange &rRange, sal_Int32 nXfId) const
Writes the cell formatting attributes of the specified XF to the passed property set.
FontRef getFontFromCellXf(sal_Int32 nXfId) const
Returns the font object of the specified cell XF.
FontRef getFont(sal_Int32 nFontId) const
Returns the specified font object.
BorderRef createBorder()
Creates a new empty border object.
static bool equalBorders(sal_Int32 nBorderId1, sal_Int32 nBorderId2)
Returns true, if the specified borders are equal.
OUString createDxfStyle(sal_Int32 nDxfId) const
Creates the style sheet described by the DXF with the passed identifier.
BorderRef getBorder(sal_Int32 nBorderId) const
Returns the specified border object.
XfRef createCellXf()
Creates a new empty cell formatting object.
StylesBuffer(const WorkbookHelper &rHelper)
void writeFontToItemSet(SfxItemSet &rItemSet, sal_Int32 nFontId, bool bSkipPoolDefs) const
DxfStyleMap maDxfStyles
List of differential extlst cell styles.
NumberFormatRef importNumFmt(const AttributeList &rAttribs)
Inserts a new number format code.
BorderVector maBorders
List of all number format codes.
FontVector maFonts
Color palette.
::Color getPaletteColor(sal_Int32 nIndex) const
Returns the palette color with the specified index.
DxfVector maExtDxfs
List of differential cell styles.
FillRef createFill()
Creates a new empty fill object.
sal_uInt32 writeNumFmtToItemSet(SfxItemSet &rItemSet, sal_uInt32 nNumFmtId, bool bSkipPoolDefs) const
XfVector maStyleXfs
List of cell formats.
XfRef createStyleXf()
Creates a new empty style formatting object.
FontRef getDefaultFont() const
Returns the default application font (used in the "Normal" cell style).
DxfVector maDxfs
All built-in and user defined cell styles.
FillVector maFills
List of cell border objects.
OUString getDefaultStyleName() const
Returns the default style sheet for unused cells.
DxfRef createDxf()
Creates a new empty differential formatting object.
void finalizeImport()
Final processing after import of all style settings.
void importPaletteColor(const AttributeList &rAttribs)
Appends a new color to the color palette.
OUString createExtDxfStyle(sal_Int32 nDxfId) const
NumberFormatRef createNumFmt(sal_Int32 nNumFmtId, std::u16string_view aFmtCode)
Creates a number format.
OUString createCellStyle(sal_Int32 nXfId) const
Creates the style sheet described by the style XF with the passed identifier.
CellStyleBuffer maCellStyles
List of cell styles.
XfRef getCellXf(sal_Int32 nXfId) const
Returns the specified cell format object.
void writeBorderToItemSet(SfxItemSet &rItemSet, sal_Int32 nBorderId, bool bSkipPoolDefs) const
Writes the specified number format to the passed property map.
::Color getColorByToken(sal_Int32 nToken) const
Returns the theme color with the specified token identifier.
Definition: themebuffer.cxx:40
const FontModel & getDefaultFontModel() const
Returns the default font data for the current file type.
Definition: themebuffer.hxx:41
Helper class that provides functions to convert values from and to different units.
void finalizeImport()
Final processing after import of all style settings.
double scaleValue(double fValue, Unit eFromUnit, Unit eToUnit) const
Converts the passed value between the passed units.
Helper class to provide access to global workbook data.
rtl_TextEncoding getTextEncoding() const
Returns the text encoding used to import/export byte strings.
css::uno::Reference< css::container::XNameContainer > getCellStyleFamily() const
Returns the cell styles container from the Calc document.
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
ScDocumentImport & getDocImport()
ThemeBuffer & getTheme() const
Returns the office theme object read from the theme substorage.
UnitConverter & getUnitConverter() const
Returns the measurement unit converter.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
Represents a cell format or a cell style (called XF, extended format).
FontRef getFont() const
Returns the referred font object.
XfModel maModel
Calc number format.
const ::ScPatternAttr & createPattern(bool bSkipPoolDefs=false)
void importXf(const AttributeList &rAttribs, bool bCellXf)
Sets all attributes from the xf element.
void importAlignment(const AttributeList &rAttribs)
Sets all attributes from the alignment element.
void importProtection(const AttributeList &rAttribs)
Sets all attributes from the protection element.
sal_uInt32 mnScNumFmt
Calc item set.
::ScStyleSheet * mpStyleSheet
Rotation reference dependent on border.
void finalizeImport()
Final processing after import of all style settings.
Xf(const WorkbookHelper &rHelper)
void writeToDoc(ScDocumentImport &rDoc, const ScRange &rRange)
sal_Int32 meRotationRef
Cell protection data.
Alignment maAlignment
Cell XF or style XF model data.
Protection maProtection
Cell alignment data.
bool isCellXf() const
Returns true, if the XF is a cell XF, and false, if it is a style XF.
ScPatternAttrPtr mpPattern
void applyPatternToAttrList(AttrList &rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nForceScNumFmt)
ColorTransparency
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
Color mnColor
sal_Int16 mnLevel
int nCount
OString right
OString top
OString bottom
float u
constexpr TypedWhichId< SvxContourItem > EE_CHAR_OUTLINE(EE_CHAR_START+8)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CJK(EE_CHAR_START+17)
constexpr TypedWhichId< SvxUnderlineItem > EE_CHAR_UNDERLINE(EE_CHAR_START+5)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT(EE_CHAR_START+2)
constexpr TypedWhichId< SvxShadowedItem > EE_CHAR_SHADOW(EE_CHAR_START+9)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
constexpr TypedWhichId< SvxColorItem > EE_CHAR_COLOR(EE_CHAR_START+0)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CTL(EE_CHAR_START+22)
constexpr TypedWhichId< SvxCrossedOutItem > EE_CHAR_STRIKEOUT(EE_CHAR_START+6)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC(EE_CHAR_START+7)
constexpr TypedWhichId< SvxEscapementItem > EE_CHAR_ESCAPEMENT(EE_CHAR_START+10)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CTL(EE_CHAR_START+20)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT_CJK(EE_CHAR_START+21)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CJK(EE_CHAR_START+23)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO_CTL(EE_CHAR_START+18)
constexpr TypedWhichId< SvxPostureItem > EE_CHAR_ITALIC_CTL(EE_CHAR_START+24)
constexpr TypedWhichId< SvxFontHeightItem > EE_CHAR_FONTHEIGHT_CJK(EE_CHAR_START+19)
constexpr TypedWhichId< SvxFontItem > EE_CHAR_FONTINFO(EE_CHAR_START+1)
NORMAL
sal_Int16 nValue
FontLineStyle
LINESTYLE_SINGLE
LINESTYLE_DOUBLE
LINESTYLE_NONE
FontStrikeout
STRIKEOUT_SINGLE
STRIKEOUT_NONE
FontPitch
PITCH_DONTKNOW
ITALIC_NORMAL
ITALIC_NONE
FontFamily
FAMILY_DECORATIVE
FAMILY_DONTKNOW
FAMILY_SCRIPT
FAMILY_SWISS
FAMILY_MODERN
FAMILY_ROMAN
FontType
Style maTop
Style maBottom
SvxFrameDirection
#define STATIC_ARRAY_SELECT(array, index, def)
const char * name
sal_Int32 nIndex
#define SAL_WARN_IF(condition, area, stream)
#define SAL_N_ELEMENTS(arr)
def text(shape, orig_st)
@ table
NONE
@ Exception
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
AUTO
int i
void SvStream & rStrm
const sal_Int8 API_ESCAPEHEIGHT_NONE
Subscript: lower characters automatically (magic value -101).
::FontFamily lcl_getFontFamily(sal_Int32 nFamily)
const sal_Int16 API_ESCAPE_SUPERSCRIPT
No escapement.
const sal_Int32 OOX_COLOR_NOTETEXT
Note background color.
const sal_Int16 API_LINE_THICK
const sal_Int32 OOX_COLOR_WINDOWTEXT
System window background color (BIFF3-BIFF4).
std::shared_ptr< NumberFormat > NumberFormatRef
bool operator==(const ApiAlignmentData &rLeft, const ApiAlignmentData &rRight)
std::shared_ptr< Font > FontRef
const sal_Int32 OOX_COLOR_WINDOWBACK3
System window text color (BIFF3-BIFF4).
SequenceInputStream & operator>>(SequenceInputStream &rStrm, BinAddress &orPos)
const sal_Int16 API_LINE_MEDIUM
const sal_Int16 API_LINE_THIN
const sal_Int16 API_ESCAPE_SUBSCRIPT
Superscript: raise characters automatically (magic value 101).
const sal_Int32 OOX_COLOR_WINDOWTEXT3
std::shared_ptr< Border > BorderRef
std::shared_ptr< Dxf > DxfRef
const sal_Int16 API_LINE_NONE
Font auto color (system window text color).
std::shared_ptr< Fill > FillRef
const sal_Int32 OOX_COLOR_BUTTONBACK
System window background color (BIFF5+).
const sal_Int32 OOX_COLOR_FONTAUTO
Note text color.
const sal_Int32 OOX_COLOR_WINDOWBACK
System window text color (BIFF5+).
const sal_Int32 OOX_COLOR_NOTEBACK
Automatic frame border (BIFF8 charts).
const sal_Int8 API_ESCAPEHEIGHT_DEFAULT
Relative character height if not escaped.
std::shared_ptr< CellStyle > CellStyleRef
const sal_Int16 API_ESCAPE_NONE
const sal_Int32 OOX_COLOR_CHBORDERAUTO
System window background color (BIFF8 charts).
@ Space
Digit width of document default font.
const sal_Int32 OOX_COLOR_CHWINDOWBACK
System window text color (BIFF8 charts).
const sal_Int16 API_LINE_HAIR
std::shared_ptr< Xf > XfRef
const sal_Int32 OOX_COLOR_CHWINDOWTEXT
System button background color (face color).
const ::Color API_RGB_BLACK(0x000000)
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
const sal_uInt8 WINDOWS_CHARSET_DEFAULT
bool getFlag(Type nBitField, Type nMask)
const ::Color API_RGB_WHITE(0xFFFFFF)
end
FontWeight
XML_none
XML_type
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
VCL_DLLPUBLIC float ConvertFontWeight(FontWeight eWeight)
XML_TOKEN_INVALID
sal_Int32 mnNumFmtId
bool mbBold
DefTokenId nToken
Definition: qproform.cxx:397
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
sal_Int32 mnType
SvxRotateMode
SVX_ROTATE_MODE_BOTTOM
SVX_ROTATE_MODE_STANDARD
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
constexpr TypedWhichId< SvxFontItem > ATTR_CJK_FONT(111)
constexpr TypedWhichId< SvxPostureItem > ATTR_CTL_FONT_POSTURE(119)
constexpr TypedWhichId< SvxFontItem > ATTR_CTL_FONT(116)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CJK_FONT_HEIGHT(112)
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
constexpr TypedWhichId< SvxWeightItem > ATTR_CJK_FONT_WEIGHT(113)
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_TLBR(141)
constexpr TypedWhichId< SvxShadowedItem > ATTR_FONT_SHADOWED(108)
constexpr TypedWhichId< SvxContourItem > ATTR_FONT_CONTOUR(107)
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
constexpr TypedWhichId< SvxJustifyMethodItem > ATTR_VER_JUSTIFY_METHOD(133)
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
constexpr TypedWhichId< SvxRotateModeItem > ATTR_ROTATE_MODE(136)
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
constexpr TypedWhichId< SvxJustifyMethodItem > ATTR_HOR_JUSTIFY_METHOD(130)
constexpr TypedWhichId< SvxFrameDirectionItem > ATTR_WRITINGDIR(138)
constexpr TypedWhichId< SvxCrossedOutItem > ATTR_FONT_CROSSEDOUT(106)
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_BLTR(142)
constexpr TypedWhichId< SvxVerJustifyItem > ATTR_VER_JUSTIFY(132)
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
constexpr TypedWhichId< SvxWeightItem > ATTR_CTL_FONT_WEIGHT(118)
constexpr TypedWhichId< SvxPostureItem > ATTR_CJK_FONT_POSTURE(114)
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CTL_FONT_HEIGHT(117)
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
static SfxItemSet & rSet
SCROW nEndRow
Definition: attarray.hxx:83
const ScPatternAttr * pPattern
Definition: attarray.hxx:84
sal_Int32 mnIndent
Text rotation angle.
void setBiffVerAlign(sal_uInt8 nVerAlign)
Sets vertical alignment from the passed BIFF data.
bool mbWrapText
Indentation.
AlignmentModel()
True = justify last line in block text.
sal_Int32 mnTextDir
Vertical alignment.
bool mbShrink
True = multi-line text.
bool mbJustLastLine
True = shrink to fit cell size.
sal_Int32 mnVerAlign
Horizontal alignment.
sal_Int32 mnRotation
CTL text direction.
void setBiffHorAlign(sal_uInt8 nHorAlign)
Sets horizontal alignment from the passed BIFF data.
Contains all API cell alignment attributes.
sal_Int32 mnHorJustifyMethod
Horizontal alignment.
Degree100 mnRotation
Normal or stacked text.
css::table::CellOrientation meOrientation
sal_Int16 mnIndent
CTL text direction.
bool mbShrink
True = multi-line text.
css::table::CellHoriJustify meHorJustify
bool mbWrapText
Indentation.
ApiAlignmentData()
True = shrink to fit cell size.
sal_Int32 mnVerJustifyMethod
Vertical alignment.
sal_Int16 mnWritingMode
Text rotation angle.
ApiBorderLine maRight
Left line format.
bool mbBorderUsed
Diagonal bottom-left to top-right line format.
ApiBorderLine maBLtoTR
Diagonal top-left to bottom-right line format.
ApiBorderData()
True = diagonal line format used.
ApiBorderLine maTLtoBR
Bottom line format.
ApiBorderLine maTop
Right line format.
bool hasAnyOuterBorder() const
Returns true, if any of the outer border lines is visible.
bool mbDiagUsed
True = left/right/top/bottom line format used.
ApiBorderLine maBottom
Top line format.
::Color mnColor
Font descriptor (height in twips, weight in %).
ApiScriptFontName maLatinFont
sal_Int16 mnEscapement
Font color.
ApiFontData()
True = shadowed chgaracters.
css::awt::FontDescriptor maDesc
Font name for complex scripts.
sal_Int8 mnEscapeHeight
Escapement style.
ApiScriptFontName maAsianFont
Font name for latin scripts.
bool mbShadow
True = outlined characters.
bool mbOutline
Escapement font height.
ApiScriptFontName maCmplxFont
Font name for east-asian scripts.
bool mbShadowUsed
True = outline style is used.
bool mbSchemeUsed
True = font color is used.
bool mbOutlineUsed
True = strike out style is used.
ApiFontUsedFlags(bool bAllUsed)
True = shadow style is used.
bool mbColorUsed
True = font name/family/char set are used.
bool mbStrikeoutUsed
True = font posture (italic) is used.
bool mbEscapementUsed
True = underline style is used.
bool mbHeightUsed
True = font scheme is used.
bool mbPostureUsed
True = font weight (boldness) is used.
bool mbWeightUsed
True = escapement style is used.
bool mbUnderlineUsed
True = font height is used.
Contains all API cell protection attributes.
ApiCellProtection maCellProt
Contains API font name, family, and charset for a script type.
sal_Int16 mnFamily
Font name.
sal_Int16 mnTextEnc
Font family.
ApiScriptFontName()
Font text encoding.
bool mbTransparent
Fill color filtering.
ApiSolidFillData()
True = fill data is valid.
bool mbUsed
True = transparent area.
::Color mnFilterColor
Fill color.
AutoFormatModel()
True = apply protection from autoformatting.
Contains XML attributes of a single border line.
bool mbUsed
Border line style.
sal_Int32 mnStyle
Borderline color.
void setBiffStyle(sal_Int32 nLineStyle)
Sets the passed BIFF line style.
BorderLineModel(bool bDxf)
True = line format used.
bool mbDiagBLtoTR
True = top-left to bottom-right on.
BorderLineModel maBottom
Top line format.
bool mbDiagTLtoBR
Diagonal line format.
BorderLineModel maLeft
BorderModel(bool bDxf)
True = bottom-left to top-right on.
BorderLineModel maDiagonal
Bottom line format.
BorderLineModel maRight
Left line format.
BorderLineModel maTop
Right line format.
Contains attributes of a cell style, e.g.
bool mbHidden
True = customized builtin style.
bool isDefaultStyle() const
Returns true, if this style represents the default document cell style.
sal_Int32 mnXfId
Cell style name.
sal_Int32 mnLevel
Identifier for builtin styles.
CellStyleModel()
True = style not visible in GUI.
bool isBuiltin() const
Returns true, if this style is a builtin style.
bool mbCustom
True = builtin style.
sal_Int32 mnBuiltinId
Formatting for this cell style.
bool mbBuiltin
Level for builtin column/row styles.
Contains all XML font attributes, e.g.
bool mbShadow
True = outlined characters.
FontModel()
True = shadowed chgaracters.
bool mbItalic
True = bold characters.
sal_Int32 mnFamily
Major/minor scheme font.
void setBiff12Scheme(sal_uInt8 nScheme)
bool mbOutline
True = Strike out characters.
void setBiffEscapement(sal_uInt16 nEscapement)
sal_Int32 mnEscapement
Underline style.
sal_Int32 mnCharSet
Font family.
sal_Int32 mnScheme
Font color.
void setBiffUnderline(sal_uInt16 nUnderline)
sal_Int32 mnUnderline
Font height in points.
void setBiffHeight(sal_uInt16 nHeight)
bool mbBold
Escapement style.
double mfHeight
Windows font character set.
Color maColor
Font name.
void setBiffWeight(sal_uInt16 nWeight)
bool mbStrikeout
True = italic characters.
Contains XML gradient fill attributes from the gradientFill element.
double mfRight
Left convergence for type path.
double mfBottom
Top convergence for type path.
double mfLeft
Rotation angle for type linear.
double mfTop
Right convergence for type path.
void readGradient(SequenceInputStream &rStrm)
Reads BIFF12 gradient settings from a FILL or DXF record.
GradientFillModel()
Gradient colors.
ColorMap maColors
Bottom convergence for type path.
double mfAngle
Gradient type, linear or path.
void readGradientStop(SequenceInputStream &rStrm, bool bDxf)
Reads BIFF12 gradient stop settings from a FILL or DXF record.
Contains XML pattern fill attributes from the patternFill element.
PatternFillModel(bool bDxf)
True = pattern used.
void setBiffPattern(sal_Int32 nPattern)
Sets the passed BIFF pattern identifier.
Color maFilterPatternColor
Pattern foreground color.
Color maFillColor
Pattern foreground for color filter.
bool mbFillColorUsed
True = pattern foreground color used.
sal_Int32 mnPattern
Background fill color.
bool mbPattColorUsed
Pattern identifier (e.g. solid).
bool mbPatternUsed
True = background fill color used.
ProtectionModel()
True = formula is hidden.
bool mbHidden
True = locked against editing.
Contains all data for a cell format or cell style.
bool mbFontUsed
True = cell XF, false = style XF.
sal_Int32 mnBorderId
Index to number format list.
XfModel()
True = area data used.
bool mbAreaUsed
True = border data used.
sal_Int32 mnNumFmtId
Index to font data list.
bool mbNumFmtUsed
True = font index used.
sal_Int32 mnFillId
Index to list of cell borders.
bool mbAlignUsed
True = number format used.
bool mbCellXf
Index to list of cell areas.
bool mbProtUsed
True = alignment used.
sal_Int32 mnFontId
Index to parent style XF.
bool mbBorderUsed
True = cell protection used.
AttrList(const ScPatternAttr *pDefPatternAttr)
std::vector< ScAttrEntry > maAttrs
const ScPatternAttr * mpDefPattern
#define PALETTE_EGA_COLORS_DARK
Standard EGA colors), dark.
#define PALETTE_EGA_COLORS_LIGHT
Standard EGA colors, bright.
SvxEscapement
SvxCellHorJustify
SvxCellVerJustify
Reference< XStyle > maCellStyles[style_count]
#define SAL_MAX_UINT8
unsigned char sal_uInt8
#define SAL_MIN_INT16
#define SAL_MAX_INT16
sal_Int32 SCROW
Definition: types.hxx:17
std::map< OUString, sal_Int32 > CellStyleNameMap
sal_uInt64 left
constexpr OUStringLiteral PROP_CharFontCharSetComplex
constexpr OUStringLiteral PROP_CharShadowed
constexpr OUStringLiteral PROP_CharHeightComplex
constexpr OUStringLiteral PROP_CharHeight
constexpr OUStringLiteral PROP_CharPostureComplex
constexpr OUStringLiteral PROP_CharContoured
constexpr OUStringLiteral PROP_CharPosture
constexpr OUStringLiteral PROP_CharWeight
constexpr OUStringLiteral PROP_CharFontNameComplex
constexpr OUStringLiteral PROP_CharUnderline
constexpr OUStringLiteral PROP_CharColor
constexpr OUStringLiteral PROP_CharWeightComplex
constexpr OUStringLiteral PROP_CharEscapement
constexpr OUStringLiteral PROP_CharStrikeout
constexpr OUStringLiteral PROP_CharHeightAsian
constexpr OUStringLiteral PROP_CharFontFamilyAsian
constexpr OUStringLiteral PROP_CharWeightAsian
constexpr OUStringLiteral PROP_CharFontCharSet
constexpr OUStringLiteral PROP_CharFontNameAsian
constexpr OUStringLiteral PROP_CharFontFamilyComplex
constexpr OUStringLiteral PROP_CharEscapementHeight
constexpr OUStringLiteral PROP_CharFontName
constexpr OUStringLiteral PROP_CharFontCharSetAsian
constexpr OUStringLiteral PROP_CharPostureAsian
constexpr OUStringLiteral PROP_CharFontFamily