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