LibreOffice Module sc (master)  1
xestyle.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 <memory>
21 #include <xestyle.hxx>
22 
23 #include <algorithm>
24 #include <iterator>
25 #include <com/sun/star/i18n/ScriptType.hpp>
27 #include <rtl/tencinfo.h>
28 #include <vcl/font.hxx>
29 #include <svl/languageoptions.hxx>
30 #include <scitems.hxx>
31 #include <editeng/borderline.hxx>
32 #include <editeng/boxitem.hxx>
33 #include <editeng/lineitem.hxx>
34 #include <editeng/brushitem.hxx>
35 #include <editeng/frmdiritem.hxx>
36 #include <editeng/fontitem.hxx>
37 #include <editeng/justifyitem.hxx>
38 #include <editeng/langitem.hxx>
39 #include <document.hxx>
40 #include <stlpool.hxx>
41 #include <stlsheet.hxx>
42 #include <patattr.hxx>
43 #include <attrib.hxx>
44 #include <globstr.hrc>
45 #include <scresid.hxx>
46 #include <xestring.hxx>
47 #include <xltools.hxx>
48 #include <conditio.hxx>
49 #include <dbdata.hxx>
50 #include <filterentries.hxx>
51 
52 #include <o3tl/safeint.hxx>
53 #include <oox/export/utils.hxx>
54 #include <oox/token/tokens.hxx>
55 #include <oox/token/namespaces.hxx>
57 #include <svl/numformat.hxx>
58 
59 using namespace ::com::sun::star;
60 using namespace oox;
61 
62 // PALETTE record - color information =========================================
63 
64 namespace {
65 
66 sal_uInt32 lclGetWeighting( XclExpColorType eType )
67 {
68  switch( eType )
69  {
70  case EXC_COLOR_CHARTLINE: return 1;
72  case EXC_COLOR_CHARTAREA: return 2;
73  case EXC_COLOR_CELLTEXT:
75  case EXC_COLOR_CTRLTEXT: return 10;
76  case EXC_COLOR_TABBG:
77  case EXC_COLOR_CELLAREA: return 20;
78  case EXC_COLOR_GRID: return 50;
79  default: OSL_FAIL( "lclGetWeighting - unknown color type" );
80  }
81  return 1;
82 }
83 
84 sal_Int32 lclGetColorDistance( const Color& rColor1, const Color& rColor2 )
85 {
86  sal_Int32 nDist = rColor1.GetRed() - rColor2.GetRed();
87  nDist *= nDist * 77;
88  sal_Int32 nDummy = rColor1.GetGreen() - rColor2.GetGreen();
89  nDist += nDummy * nDummy * 151;
90  nDummy = rColor1.GetBlue() - rColor2.GetBlue();
91  nDist += nDummy * nDummy * 28;
92  return nDist;
93 }
94 
95 sal_uInt8 lclGetMergedColorComp( sal_uInt8 nComp1, sal_uInt32 nWeight1, sal_uInt8 nComp2, sal_uInt32 nWeight2 )
96 {
97  sal_uInt8 nComp1Dist = ::std::min< sal_uInt8 >( nComp1, 0xFF - nComp1 );
98  sal_uInt8 nComp2Dist = ::std::min< sal_uInt8 >( nComp2, 0xFF - nComp2 );
99  if( nComp1Dist != nComp2Dist )
100  {
101  /* #i36945# One of the passed RGB components is nearer at the limits (0x00 or 0xFF).
102  Increase its weighting to prevent fading of the colors during reduction. */
103  const sal_uInt8& rnCompNearer = (nComp1Dist < nComp2Dist) ? nComp1 : nComp2;
104  sal_uInt32& rnWeight = (nComp1Dist < nComp2Dist) ? nWeight1 : nWeight2;
105  rnWeight *= ((rnCompNearer - 0x80L) * (rnCompNearer - 0x7FL) / 0x1000L + 1);
106  }
107  sal_uInt32 nWSum = nWeight1 + nWeight2;
108  return static_cast< sal_uInt8 >( (nComp1 * nWeight1 + nComp2 * nWeight2 + nWSum / 2) / nWSum );
109 }
110 
111 void lclSetMixedColor( Color& rDest, const Color& rSrc1, const Color& rSrc2 )
112 {
113  rDest.SetRed( static_cast< sal_uInt8 >( (static_cast< sal_uInt16 >( rSrc1.GetRed() ) + rSrc2.GetRed()) / 2 ) );
114  rDest.SetGreen( static_cast< sal_uInt8 >( (static_cast< sal_uInt16 >( rSrc1.GetGreen() ) + rSrc2.GetGreen()) / 2 ) );
115  rDest.SetBlue( static_cast< sal_uInt8 >( (static_cast< sal_uInt16 >( rSrc1.GetBlue() ) + rSrc2.GetBlue()) / 2 ) );
116 }
117 
118 } // namespace
119 
120 // additional classes for color reduction -------------------------------------
121 
122 namespace {
123 
130 class XclListColor
131 {
132 private:
133  Color maColor;
134  sal_uInt32 mnColorId;
135  sal_uInt32 mnWeight;
136  bool mbBaseColor;
137 
138 public:
139  explicit XclListColor( const Color& rColor, sal_uInt32 nColorId );
140 
142  const Color& GetColor() const { return maColor; }
144  sal_uInt32 GetColorId() const { return mnColorId; }
146  sal_uInt32 GetWeighting() const { return mnWeight; }
148  bool IsBaseColor() const { return mbBaseColor; }
149 
151  void AddWeighting( sal_uInt32 nWeight ) { mnWeight += nWeight; }
153  void Merge( const XclListColor& rColor );
154 };
155 
156 XclListColor::XclListColor( const Color& rColor, sal_uInt32 nColorId ) :
157  maColor( rColor ),
158  mnColorId( nColorId ),
159  mnWeight( 0 )
160 {
161  mbBaseColor =
162  ((rColor.GetRed() == 0x00) || (rColor.GetRed() == 0xFF)) &&
163  ((rColor.GetGreen() == 0x00) || (rColor.GetGreen() == 0xFF)) &&
164  ((rColor.GetBlue() == 0x00) || (rColor.GetBlue() == 0xFF));
165 }
166 
167 void XclListColor::Merge( const XclListColor& rColor )
168 {
169  sal_uInt32 nWeight2 = rColor.GetWeighting();
170  // do not change RGB value of base colors
171  if( !mbBaseColor )
172  {
173  maColor.SetRed( lclGetMergedColorComp( maColor.GetRed(), mnWeight, rColor.maColor.GetRed(), nWeight2 ) );
174  maColor.SetGreen( lclGetMergedColorComp( maColor.GetGreen(), mnWeight, rColor.maColor.GetGreen(), nWeight2 ) );
175  maColor.SetBlue( lclGetMergedColorComp( maColor.GetBlue(), mnWeight, rColor.maColor.GetBlue(), nWeight2 ) );
176  }
177  AddWeighting( nWeight2 );
178 }
179 
181 struct XclColorIdData
182 {
183  Color maColor;
184  sal_uInt32 mnIndex;
185 
186  void Set( const Color& rColor, sal_uInt32 nIndex ) { maColor = rColor; mnIndex = nIndex; }
187 };
188 
190 struct XclPaletteColor
191 {
192  Color maColor;
193  bool mbUsed;
194 
195  explicit XclPaletteColor( const Color& rColor ) : maColor( rColor ), mbUsed( false ) {}
196  void SetColor( const Color& rColor ) { maColor = rColor; mbUsed = true; }
197 };
198 
201 struct XclRemap
202 {
203  sal_uInt32 mnPalIndex;
204  bool mbProcessed;
205 
206  explicit XclRemap() : mnPalIndex( 0 ), mbProcessed( false ) {}
207  void SetIndex( sal_uInt32 nPalIndex )
208  { mnPalIndex = nPalIndex; mbProcessed = true; }
209 };
210 
212 struct XclNearest
213 {
214  sal_uInt32 mnPalIndex;
215  sal_Int32 mnDist;
216 
217  explicit XclNearest() : mnPalIndex( 0 ), mnDist( 0 ) {}
218 };
219 
220 } // namespace
221 
223 {
224 public:
225  explicit XclExpPaletteImpl( const XclDefaultPalette& rDefPal );
226 
230  sal_uInt32 InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault = 0 );
232  static sal_uInt32 GetColorIdFromIndex( sal_uInt16 nIndex );
233 
235  void Finalize();
236 
238  sal_uInt16 GetColorIndex( sal_uInt32 nColorId ) const;
239 
244  void GetMixedColors(
245  sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
246  sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const;
247 
250  Color GetColor( sal_uInt16 nXclIndex ) const;
251 
253  bool IsDefaultPalette() const;
255  void WriteBody( XclExpStream& rStrm );
256  void SaveXml( XclExpXmlStream& rStrm );
257 
258 private:
260  static sal_uInt16 GetXclIndex( sal_uInt32 nIndex )
261  { return static_cast< sal_uInt16 >( nIndex + EXC_COLOR_USEROFFSET ); }
262 
264  const Color& GetOriginalColor( sal_uInt32 nColorId ) const;
265 
267  XclListColor* SearchListEntry( const Color& rColor, sal_uInt32& rnIndex );
269  XclListColor* CreateListEntry( const Color& rColor, sal_uInt32 nIndex );
270 
272  void RawReducePalette( sal_uInt32 nPass );
274  void ReduceLeastUsedColor();
275 
277  sal_uInt32 GetLeastUsedListColor() const;
281  sal_uInt32 GetNearestListColor( const Color& rColor, sal_uInt32 nIgnore ) const;
283  sal_uInt32 GetNearestListColor( sal_uInt32 nIndex ) const;
284 
288  sal_Int32 GetNearestPaletteColor(
289  sal_uInt32& rnIndex,
290  const Color& rColor ) const;
293  sal_Int32 GetNearPaletteColors(
294  sal_uInt32& rnFirst, sal_uInt32& rnSecond,
295  const Color& rColor ) const;
296 
297 private:
298  typedef std::vector< std::unique_ptr<XclListColor> > XclListColorList;
299  typedef std::shared_ptr< XclListColorList > XclListColorListRef;
300 
302  XclListColorListRef mxColorList;
303  std::vector< XclColorIdData >
305  std::vector< XclPaletteColor >
307  sal_uInt32 mnLastIdx;
308 };
309 
310 const sal_uInt32 EXC_PAL_INDEXBASE = 0xFFFF0000;
311 const sal_uInt32 EXC_PAL_MAXRAWSIZE = 1024;
312 
314  mrDefPal( rDefPal ),
315  mxColorList( std::make_shared<XclListColorList>() ),
316  mnLastIdx( 0 )
317 {
318  // initialize maPalette with default colors
319  sal_uInt16 nCount = static_cast< sal_uInt16 >( mrDefPal.GetColorCount() );
320  maPalette.reserve( nCount );
321  for( sal_uInt16 nIdx = 0; nIdx < nCount; ++nIdx )
322  maPalette.emplace_back( mrDefPal.GetDefColor( GetXclIndex( nIdx ) ) );
323 
325 }
326 
327 sal_uInt32 XclExpPaletteImpl::InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault )
328 {
329  if( rColor == COL_AUTO )
330  return GetColorIdFromIndex( nAutoDefault );
331 
332  sal_uInt32 nFoundIdx = 0;
333  XclListColor* pEntry = SearchListEntry( rColor, nFoundIdx );
334  if( !pEntry || (pEntry->GetColor() != rColor) )
335  pEntry = CreateListEntry( rColor, nFoundIdx );
336  pEntry->AddWeighting( lclGetWeighting( eType ) );
337 
338  return pEntry->GetColorId();
339 }
340 
341 sal_uInt32 XclExpPaletteImpl::GetColorIdFromIndex( sal_uInt16 nIndex )
342 {
343  return EXC_PAL_INDEXBASE | nIndex;
344 }
345 
347 {
348 // --- build initial color ID data vector (maColorIdDataVec) ---
349 
350  sal_uInt32 nCount = mxColorList->size();
351  maColorIdDataVec.resize( nCount );
352  for( sal_uInt32 nIdx = 0; nIdx < nCount; ++nIdx )
353  {
354  const XclListColor& listColor = *mxColorList->at( nIdx );
355  maColorIdDataVec[ listColor.GetColorId() ].Set( listColor.GetColor(), nIdx );
356  }
357 
358 // --- loop as long as current color count does not fit into palette of current BIFF ---
359 
360  // phase 1: raw reduction (performance reasons, #i36945#)
361  sal_uInt32 nPass = 0;
362  while( mxColorList->size() > EXC_PAL_MAXRAWSIZE )
363  RawReducePalette( nPass++ );
364 
365  // phase 2: precise reduction using advanced color merging based on color weighting
366  while( mxColorList->size() > mrDefPal.GetColorCount() )
368 
369 // --- use default palette and replace colors with nearest used colors ---
370 
371  nCount = mxColorList->size();
372  std::vector< XclRemap > aRemapVec( nCount );
373  std::vector< XclNearest > aNearestVec( nCount );
374 
375  // in each run: search the best fitting color and replace a default color with it
376  for( sal_uInt32 nRun = 0; nRun < nCount; ++nRun )
377  {
378  sal_uInt32 nIndex;
379  // find nearest unused default color for each unprocessed list color
380  for( nIndex = 0; nIndex < nCount; ++nIndex )
381  aNearestVec[ nIndex ].mnDist = aRemapVec[ nIndex ].mbProcessed ? SAL_MAX_INT32 :
382  GetNearestPaletteColor( aNearestVec[ nIndex ].mnPalIndex, mxColorList->at( nIndex )->GetColor() );
383  // find the list color which is nearest to a default color
384  sal_uInt32 nFound = 0;
385  for( nIndex = 1; nIndex < nCount; ++nIndex )
386  if( aNearestVec[ nIndex ].mnDist < aNearestVec[ nFound ].mnDist )
387  nFound = nIndex;
388  // replace default color with list color
389  sal_uInt32 nNearest = aNearestVec[ nFound ].mnPalIndex;
390  OSL_ENSURE( nNearest < maPalette.size(), "XclExpPaletteImpl::Finalize - algorithm error" );
391  maPalette[ nNearest ].SetColor( mxColorList->at( nFound )->GetColor() );
392  aRemapVec[ nFound ].SetIndex( nNearest );
393  }
394 
395  // remap color ID data map (maColorIdDataVec) from list indexes to palette indexes
396  for( auto& rColorIdData : maColorIdDataVec )
397  rColorIdData.mnIndex = aRemapVec[ rColorIdData.mnIndex ].mnPalIndex;
398 }
399 
400 sal_uInt16 XclExpPaletteImpl::GetColorIndex( sal_uInt32 nColorId ) const
401 {
402  sal_uInt16 nRet = 0;
403  if( nColorId >= EXC_PAL_INDEXBASE )
404  nRet = static_cast< sal_uInt16 >( nColorId & ~EXC_PAL_INDEXBASE );
405  else if( nColorId < maColorIdDataVec.size() )
406  nRet = GetXclIndex( maColorIdDataVec[ nColorId ].mnIndex );
407  return nRet;
408 }
409 
411  sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
412  sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const
413 {
414  rnXclForeIx = GetColorIndex( nForeColorId );
415  rnXclBackIx = GetColorIndex( nBackColorId );
416  if( (rnXclPattern != EXC_PATT_SOLID) || (nForeColorId >= maColorIdDataVec.size()) )
417  return;
418 
419  // now we have solid pattern, and a defined foreground (background doesn't care for solid pattern)
420 
421  sal_uInt32 nIndex1, nIndex2;
422  Color aForeColor( GetOriginalColor( nForeColorId ) );
423  sal_Int32 nFirstDist = GetNearPaletteColors( nIndex1, nIndex2, aForeColor );
424  if( (nIndex1 >= maPalette.size()) || (nIndex2 >= maPalette.size()) )
425  return;
426 
427  Color aColorArr[ 5 ];
428  aColorArr[ 0 ] = maPalette[ nIndex1 ].maColor;
429  aColorArr[ 4 ] = maPalette[ nIndex2 ].maColor;
430  lclSetMixedColor( aColorArr[ 2 ], aColorArr[ 0 ], aColorArr[ 4 ] );
431  lclSetMixedColor( aColorArr[ 1 ], aColorArr[ 0 ], aColorArr[ 2 ] );
432  lclSetMixedColor( aColorArr[ 3 ], aColorArr[ 2 ], aColorArr[ 4 ] );
433 
434  sal_Int32 nMinDist = nFirstDist;
435  sal_uInt32 nMinIndex = 0;
436  for( sal_uInt32 nCnt = 1; nCnt < 4; ++nCnt )
437  {
438  sal_Int32 nDist = lclGetColorDistance( aForeColor, aColorArr[ nCnt ] );
439  if( nDist < nMinDist )
440  {
441  nMinDist = nDist;
442  nMinIndex = nCnt;
443  }
444  }
445  rnXclForeIx = GetXclIndex( nIndex1 );
446  rnXclBackIx = GetXclIndex( nIndex2 );
447  if( nMinDist < nFirstDist )
448  {
449  switch( nMinIndex )
450  {
451  case 1: rnXclPattern = EXC_PATT_75_PERC; break;
452  case 2: rnXclPattern = EXC_PATT_50_PERC; break;
453  case 3: rnXclPattern = EXC_PATT_25_PERC; break;
454  }
455  }
456 }
457 
458 Color XclExpPaletteImpl::GetColor( sal_uInt16 nXclIndex ) const
459 {
460  if( nXclIndex >= EXC_COLOR_USEROFFSET )
461  {
462  sal_uInt32 nIdx = nXclIndex - EXC_COLOR_USEROFFSET;
463  if( nIdx < maPalette.size() )
464  return maPalette[ nIdx ].maColor;
465  }
466  return mrDefPal.GetDefColor( nXclIndex );
467 }
468 
470 {
471  bool bDefault = true;
472  for( sal_uInt32 nIdx = 0, nSize = static_cast< sal_uInt32 >( maPalette.size() ); bDefault && (nIdx < nSize); ++nIdx )
473  bDefault = maPalette[ nIdx ].maColor == mrDefPal.GetDefColor( GetXclIndex( nIdx ) );
474  return bDefault;
475 }
476 
478 {
479  rStrm << static_cast< sal_uInt16 >( maPalette.size() );
480  for( const auto& rColor : maPalette )
481  rStrm << rColor.maColor;
482 }
483 
485 {
486  if( maPalette.empty() )
487  return;
488 
489  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
490  rStyleSheet->startElement(XML_colors);
491  rStyleSheet->startElement(XML_indexedColors);
492  for( const auto& rColor : maPalette )
493  rStyleSheet->singleElement(XML_rgbColor, XML_rgb, XclXmlUtils::ToOString(rColor.maColor));
494  rStyleSheet->endElement( XML_indexedColors );
495  rStyleSheet->endElement( XML_colors );
496 }
497 
498 const Color& XclExpPaletteImpl::GetOriginalColor( sal_uInt32 nColorId ) const
499 {
500  if( nColorId < maColorIdDataVec.size() )
501  return maColorIdDataVec[ nColorId ].maColor;
502  return maPalette[ 0 ].maColor;
503 }
504 
505 XclListColor* XclExpPaletteImpl::SearchListEntry( const Color& rColor, sal_uInt32& rnIndex )
506 {
507  rnIndex = 0;
508 
509  if (mxColorList->empty())
510  return nullptr;
511 
512  XclListColor* pEntry = nullptr;
513 
514  // search optimization for equal-colored objects occurring repeatedly
515  if (mnLastIdx < mxColorList->size())
516  {
517  pEntry = (*mxColorList)[mnLastIdx].get();
518  if( pEntry->GetColor() == rColor )
519  {
520  rnIndex = mnLastIdx;
521  return pEntry;
522  }
523  }
524 
525  // binary search for color
526  sal_uInt32 nBegIdx = 0;
527  sal_uInt32 nEndIdx = mxColorList->size();
528  bool bFound = false;
529  while( !bFound && (nBegIdx < nEndIdx) )
530  {
531  rnIndex = (nBegIdx + nEndIdx) / 2;
532  pEntry = (*mxColorList)[rnIndex].get();
533  bFound = pEntry->GetColor() == rColor;
534  if( !bFound )
535  {
536  if( pEntry->GetColor() < rColor )
537  nBegIdx = rnIndex + 1;
538  else
539  nEndIdx = rnIndex;
540  }
541  }
542 
543  // not found - use end of range as new insertion position
544  if( !bFound )
545  rnIndex = nEndIdx;
546 
547  mnLastIdx = rnIndex;
548  return pEntry;
549 }
550 
551 XclListColor* XclExpPaletteImpl::CreateListEntry( const Color& rColor, sal_uInt32 nIndex )
552 {
553  XclListColor* pEntry = new XclListColor( rColor, mxColorList->size() );
554  mxColorList->insert(mxColorList->begin() + nIndex, std::unique_ptr<XclListColor>(pEntry));
555  return pEntry;
556 }
557 
558 void XclExpPaletteImpl::RawReducePalette( sal_uInt32 nPass )
559 {
560  /* Fast palette reduction - in each call of this function one RGB component
561  of each color is reduced to a lower number of distinct values.
562  Pass 0: Blue is reduced to 128 distinct values.
563  Pass 1: Red is reduced to 128 distinct values.
564  Pass 2: Green is reduced to 128 distinct values.
565  Pass 3: Blue is reduced to 64 distinct values.
566  Pass 4: Red is reduced to 64 distinct values.
567  Pass 5: Green is reduced to 64 distinct values.
568  And so on...
569  */
570 
571  XclListColorListRef xOldList = mxColorList;
572  mxColorList = std::make_shared<XclListColorList>();
573 
574  // maps old list indexes to new list indexes, used to update maColorIdDataVec
575  ScfUInt32Vec aListIndexMap;
576  aListIndexMap.reserve( xOldList->size() );
577 
578  // preparations
579  sal_uInt8 nR, nG, nB;
580  sal_uInt8& rnComp = ((nPass % 3 == 0) ? nB : ((nPass % 3 == 1) ? nR : nG));
581  nPass /= 3;
582  OSL_ENSURE( nPass < 7, "XclExpPaletteImpl::RawReducePalette - reduction not terminated" );
583 
584  static const sal_uInt8 spnFactor2[] = { 0x81, 0x82, 0x84, 0x88, 0x92, 0xAA, 0xFF };
585  sal_uInt8 nFactor1 = static_cast< sal_uInt8 >( 0x02 << nPass );
586  sal_uInt8 nFactor2 = spnFactor2[ nPass ];
587  sal_uInt8 nFactor3 = static_cast< sal_uInt8 >( 0x40 >> nPass );
588 
589  // process each color in the old color list
590  for(const std::unique_ptr<XclListColor> & pOldColor : *xOldList)
591  {
592  // get the old list entry
593  const XclListColor* pOldEntry = pOldColor.get();
594  nR = pOldEntry->GetColor().GetRed();
595  nG = pOldEntry->GetColor().GetGreen();
596  nB = pOldEntry->GetColor().GetBlue();
597 
598  /* Calculate the new RGB component (rnComp points to one of nR, nG, nB).
599  Using integer arithmetic with its rounding errors, the results of
600  this calculation are always exactly in the range 0x00 to 0xFF
601  (simply cutting the lower bits would darken the colors slightly). */
602  sal_uInt32 nNewComp = rnComp;
603  nNewComp /= nFactor1;
604  nNewComp *= nFactor2;
605  nNewComp /= nFactor3;
606  rnComp = static_cast< sal_uInt8 >( nNewComp );
607  Color aNewColor( nR, nG, nB );
608 
609  // find or insert the new color
610  sal_uInt32 nFoundIdx = 0;
611  XclListColor* pNewEntry = SearchListEntry( aNewColor, nFoundIdx );
612  if( !pNewEntry || (pNewEntry->GetColor() != aNewColor) )
613  pNewEntry = CreateListEntry( aNewColor, nFoundIdx );
614  pNewEntry->AddWeighting( pOldEntry->GetWeighting() );
615  aListIndexMap.push_back( nFoundIdx );
616  }
617 
618  // update color ID data map (maps color IDs to color list indexes), replace old by new list indexes
619  for( auto& rColorIdData : maColorIdDataVec )
620  rColorIdData.mnIndex = aListIndexMap[ rColorIdData.mnIndex ];
621 }
622 
624 {
625  // find a list color to remove
626  sal_uInt32 nRemove = GetLeastUsedListColor();
627  // find its nearest neighbor
628  sal_uInt32 nKeep = GetNearestListColor( nRemove );
629 
630  // merge both colors to one color, remove one color from list
631  XclListColor* pKeepEntry = mxColorList->at(nKeep).get();
632  XclListColor* pRemoveEntry = mxColorList->at(nRemove).get();
633  if( !(pKeepEntry && pRemoveEntry) )
634  return;
635 
636  // merge both colors (if pKeepEntry is a base color, it will not change)
637  pKeepEntry->Merge( *pRemoveEntry );
638  // remove the less used color, adjust nKeep index if kept color follows removed color
639  XclListColorList::iterator itr = mxColorList->begin();
640  ::std::advance(itr, nRemove);
641  mxColorList->erase(itr);
642  if( nKeep > nRemove ) --nKeep;
643 
644  // recalculate color ID data map (maps color IDs to color list indexes)
645  for( auto& rColorIdData : maColorIdDataVec )
646  {
647  if( rColorIdData.mnIndex > nRemove )
648  --rColorIdData.mnIndex;
649  else if( rColorIdData.mnIndex == nRemove )
650  rColorIdData.mnIndex = nKeep;
651  }
652 }
653 
655 {
656  sal_uInt32 nFound = 0;
657  sal_uInt32 nMinW = SAL_MAX_UINT32;
658 
659  for( sal_uInt32 nIdx = 0, nCount = mxColorList->size(); nIdx < nCount; ++nIdx )
660  {
661  XclListColor& rEntry = *mxColorList->at( nIdx );
662  // ignore the base colors
663  if( !rEntry.IsBaseColor() && (rEntry.GetWeighting() < nMinW) )
664  {
665  nFound = nIdx;
666  nMinW = rEntry.GetWeighting();
667  }
668  }
669  return nFound;
670 }
671 
672 sal_uInt32 XclExpPaletteImpl::GetNearestListColor( const Color& rColor, sal_uInt32 nIgnore ) const
673 {
674  sal_uInt32 nFound = 0;
675  sal_Int32 nMinD = SAL_MAX_INT32;
676 
677  for( sal_uInt32 nIdx = 0, nCount = mxColorList->size(); nIdx < nCount; ++nIdx )
678  {
679  if( nIdx != nIgnore )
680  {
681  if( XclListColor* pEntry = mxColorList->at(nIdx).get() )
682  {
683  sal_Int32 nDist = lclGetColorDistance( rColor, pEntry->GetColor() );
684  if( nDist < nMinD )
685  {
686  nFound = nIdx;
687  nMinD = nDist;
688  }
689  }
690  }
691  }
692  return nFound;
693 }
694 
695 sal_uInt32 XclExpPaletteImpl::GetNearestListColor( sal_uInt32 nIndex ) const
696 {
697  if (nIndex >= mxColorList->size())
698  return 0;
699  XclListColor* pEntry = mxColorList->at(nIndex).get();
700  return GetNearestListColor( pEntry->GetColor(), nIndex );
701 }
702 
704  sal_uInt32& rnIndex, const Color& rColor ) const
705 {
706  rnIndex = 0;
707  sal_Int32 nDist = SAL_MAX_INT32;
708 
709  sal_uInt32 nPaletteIndex = 0;
710  for( const auto& rPaletteColor : maPalette )
711  {
712  if( !rPaletteColor.mbUsed )
713  {
714  sal_Int32 nCurrDist = lclGetColorDistance( rColor, rPaletteColor.maColor );
715  if( nCurrDist < nDist )
716  {
717  rnIndex = nPaletteIndex;
718  nDist = nCurrDist;
719  }
720  }
721  ++nPaletteIndex;
722  }
723  return nDist;
724 }
725 
727  sal_uInt32& rnFirst, sal_uInt32& rnSecond, const Color& rColor ) const
728 {
729  rnFirst = rnSecond = 0;
730  sal_Int32 nDist1 = SAL_MAX_INT32;
731  sal_Int32 nDist2 = SAL_MAX_INT32;
732 
733  sal_uInt32 nPaletteIndex = 0;
734  for( const auto& rPaletteColor : maPalette )
735  {
736  sal_Int32 nCurrDist = lclGetColorDistance( rColor, rPaletteColor.maColor );
737  if( nCurrDist < nDist1 )
738  {
739  rnSecond = rnFirst;
740  nDist2 = nDist1;
741  rnFirst = nPaletteIndex;
742  nDist1 = nCurrDist;
743  }
744  else if( nCurrDist < nDist2 )
745  {
746  rnSecond = nPaletteIndex;
747  nDist2 = nCurrDist;
748  }
749  ++nPaletteIndex;
750  }
751  return nDist1;
752 }
753 
755  XclDefaultPalette( rRoot ),
757 {
758  mxImpl = std::make_shared<XclExpPaletteImpl>( *this );
759  SetRecSize( GetColorCount() * 4 + 2 );
760 }
761 
763 {
764 }
765 
766 sal_uInt32 XclExpPalette::InsertColor( const Color& rColor, XclExpColorType eType, sal_uInt16 nAutoDefault )
767 {
768  return mxImpl->InsertColor( rColor, eType, nAutoDefault );
769 }
770 
771 sal_uInt32 XclExpPalette::GetColorIdFromIndex( sal_uInt16 nIndex )
772 {
774 }
775 
777 {
778  mxImpl->Finalize();
779 }
780 
781 sal_uInt16 XclExpPalette::GetColorIndex( sal_uInt32 nColorId ) const
782 {
783  return mxImpl->GetColorIndex( nColorId );
784 }
785 
787  sal_uInt16& rnXclForeIx, sal_uInt16& rnXclBackIx, sal_uInt8& rnXclPattern,
788  sal_uInt32 nForeColorId, sal_uInt32 nBackColorId ) const
789 {
790  return mxImpl->GetMixedColors( rnXclForeIx, rnXclBackIx, rnXclPattern, nForeColorId, nBackColorId );
791 }
792 
793 Color XclExpPalette::GetColor( sal_uInt16 nXclIndex ) const
794 {
795  return mxImpl->GetColor( nXclIndex );
796 }
797 
799 {
800  if( !mxImpl->IsDefaultPalette() )
801  XclExpRecord::Save( rStrm );
802 }
803 
805 {
806  if( !mxImpl->IsDefaultPalette() )
807  mxImpl->SaveXml( rStrm );
808 }
809 
811 {
812  mxImpl->WriteBody( rStrm );
813 }
814 
815 // FONT record - font information =============================================
816 
817 namespace {
818 
819 typedef ::std::pair< sal_uInt16, sal_Int16 > WhichAndScript;
820 
821 sal_Int16 lclCheckFontItems( const SfxItemSet& rItemSet,
822  const WhichAndScript& rWAS1, const WhichAndScript& rWAS2, const WhichAndScript& rWAS3 )
823 {
824  if( ScfTools::CheckItem( rItemSet, rWAS1.first, false ) ) return rWAS1.second;
825  if( ScfTools::CheckItem( rItemSet, rWAS2.first, false ) ) return rWAS2.second;
826  if( ScfTools::CheckItem( rItemSet, rWAS3.first, false ) ) return rWAS3.second;
827  return 0;
828 };
829 
830 } // namespace
831 
832 sal_Int16 XclExpFontHelper::GetFirstUsedScript( const XclExpRoot& rRoot, const SfxItemSet& rItemSet )
833 {
834  namespace ApiScriptType = ::com::sun::star::i18n::ScriptType;
835 
836  /* #i17050# #i107170# We need to determine which font items are set in the
837  item set, and which script type we should prefer according to the
838  current language settings. */
839 
840  static const WhichAndScript WAS_LATIN( ATTR_FONT, css::i18n::ScriptType::LATIN );
841  static const WhichAndScript WAS_ASIAN( ATTR_CJK_FONT, css::i18n::ScriptType::ASIAN );
842  static const WhichAndScript WAS_CMPLX( ATTR_CTL_FONT, css::i18n::ScriptType::COMPLEX );
843 
844  /* do not let a font from a parent style override an explicit
845  cell font. */
846 
847  sal_Int16 nDefScript = rRoot.GetDefApiScript();
848  sal_Int16 nScript = 0;
849  const SfxItemSet* pCurrSet = &rItemSet;
850 
851  while( (nScript == 0) && pCurrSet )
852  {
853  switch( nDefScript )
854  {
855  case ApiScriptType::LATIN:
856  nScript = lclCheckFontItems( *pCurrSet, WAS_LATIN, WAS_CMPLX, WAS_ASIAN );
857  break;
858  case ApiScriptType::ASIAN:
859  nScript = lclCheckFontItems( *pCurrSet, WAS_ASIAN, WAS_CMPLX, WAS_LATIN );
860  break;
861  case ApiScriptType::COMPLEX:
862  nScript = lclCheckFontItems( *pCurrSet, WAS_CMPLX, WAS_ASIAN, WAS_LATIN );
863  break;
864  default:
865  OSL_FAIL( "XclExpFontHelper::GetFirstUsedScript - unknown script type" );
866  nScript = ApiScriptType::LATIN;
867  };
868  pCurrSet = pCurrSet->GetParent();
869  }
870 
871  if (nScript == 0)
872  nScript = nDefScript;
873 
874  if (nScript == 0)
875  {
876  OSL_FAIL( "XclExpFontHelper::GetFirstUsedScript - unknown script type" );
877  nScript = ApiScriptType::LATIN;
878  }
879 
880  return nScript;
881 }
882 
883 vcl::Font XclExpFontHelper::GetFontFromItemSet( const XclExpRoot& rRoot, const SfxItemSet& rItemSet, sal_Int16 nScript )
884 {
885  // if WEAK is passed, guess script type from existing items in the item set
886  if( nScript == css::i18n::ScriptType::WEAK )
887  nScript = GetFirstUsedScript( rRoot, rItemSet );
888 
889  // convert to core script type constants
891 
892  // fill the font object
893  vcl::Font aFont;
894  ScPatternAttr::GetFont( aFont, rItemSet, SC_AUTOCOL_RAW, nullptr, nullptr, nullptr, nScScript );
895  return aFont;
896 }
897 
899 {
900  sal_Int16 nScript = GetFirstUsedScript(rRoot, rItemSet);
901 
902  // convert to core script type constants
904  return ScPatternAttr::GetDxfFont(rItemSet, nScScript);
905 }
906 
907 bool XclExpFontHelper::CheckItems( const XclExpRoot& rRoot, const SfxItemSet& rItemSet, sal_Int16 nScript, bool bDeep )
908 {
909  static const sal_uInt16 pnCommonIds[] = {
912  static const sal_uInt16 pnLatinIds[] = {
914  static const sal_uInt16 pnAsianIds[] = {
916  static const sal_uInt16 pnComplexIds[] = {
918 
919  bool bUsed = ScfTools::CheckItems( rItemSet, pnCommonIds, bDeep );
920  if( !bUsed )
921  {
922  namespace ApiScriptType = css::i18n::ScriptType;
923  // if WEAK is passed, guess script type from existing items in the item set
924  if( nScript == ApiScriptType::WEAK )
925  nScript = GetFirstUsedScript( rRoot, rItemSet );
926  // check the correct items
927  switch( nScript )
928  {
929  case ApiScriptType::LATIN: bUsed = ScfTools::CheckItems( rItemSet, pnLatinIds, bDeep ); break;
930  case ApiScriptType::ASIAN: bUsed = ScfTools::CheckItems( rItemSet, pnAsianIds, bDeep ); break;
931  case ApiScriptType::COMPLEX: bUsed = ScfTools::CheckItems( rItemSet, pnComplexIds, bDeep ); break;
932  default: OSL_FAIL( "XclExpFontHelper::CheckItems - unknown script type" );
933  }
934  }
935  return bUsed;
936 }
937 
938 namespace {
939 
940 sal_uInt32 lclCalcHash( const XclFontData& rFontData )
941 {
942  sal_uInt32 nHash = rFontData.maName.getLength();
943  nHash += sal_uInt32(rFontData.maColor) * 2;
944  nHash += rFontData.mnWeight * 3;
945  nHash += rFontData.mnCharSet * 5;
946  nHash += rFontData.mnFamily * 7;
947  nHash += rFontData.mnHeight * 11;
948  nHash += rFontData.mnUnderline * 13;
949  nHash += rFontData.mnEscapem * 17;
950  if( rFontData.mbItalic ) nHash += 19;
951  if( rFontData.mbStrikeout ) nHash += 23;
952  if( rFontData.mbOutline ) nHash += 29;
953  if( rFontData.mbShadow ) nHash += 31;
954  return nHash;
955 }
956 
957 } // namespace
958 
960  const XclFontData& rFontData, XclExpColorType eColorType ) :
961  XclExpRecord( EXC_ID2_FONT, 14 ),
962  XclExpRoot( rRoot ),
963  maData( rFontData )
964 {
965  // insert font color into palette
966  mnColorId = rRoot.GetPalette().InsertColor( rFontData.maColor, eColorType, EXC_COLOR_FONTAUTO );
967  // hash value for faster comparison
968  mnHash = lclCalcHash( maData );
969  // record size
970  sal_Int32 nStrLen = maData.maName.getLength();
971  SetRecSize( ((GetBiff() == EXC_BIFF8) ? (nStrLen * 2 + 1) : nStrLen) + 15 );
972 }
973 
974 bool XclExpFont::Equals( const XclFontData& rFontData, sal_uInt32 nHash ) const
975 {
976  return (mnHash == nHash) && (maData == rFontData);
977 }
978 
980 {
981  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
982  rStyleSheet->startElement(XML_font);
983  XclXmlUtils::WriteFontData( rStyleSheet, maData, XML_name );
984  // OOXTODO: XML_scheme; //scheme/@val values: "major", "minor", "none"
985  rStyleSheet->endElement( XML_font );
986 }
987 
988 // private --------------------------------------------------------------------
989 
991 {
992  sal_uInt16 nAttr = EXC_FONTATTR_NONE;
994  if( maData.mnUnderline > 0 )
995  ::set_flag( nAttr, EXC_FONTATTR_UNDERLINE, true );
999 
1000  OSL_ENSURE( maData.maName.getLength() < 256, "XclExpFont::WriteBody - font name too long" );
1001  XclExpString aFontName;
1002  if( GetBiff() <= EXC_BIFF5 )
1004  else
1006 
1007  rStrm << maData.mnHeight
1008  << nAttr
1010  << maData.mnWeight
1011  << maData.mnEscapem
1012  << maData.mnUnderline
1013  << maData.mnFamily
1014  << maData.mnCharSet
1015  << sal_uInt8( 0 )
1016  << aFontName;
1017 }
1018 
1020  const SfxItemSet& rItemSet):
1021  XclExpRoot(rRoot)
1022 {
1024 }
1025 
1026 namespace {
1027 
1028 const char* getUnderlineOOXValue(FontLineStyle eUnderline)
1029 {
1030  switch (eUnderline)
1031  {
1032  case LINESTYLE_NONE:
1033  case LINESTYLE_DONTKNOW:
1034  return "none";
1035  case LINESTYLE_DOUBLE:
1036  case LINESTYLE_DOUBLEWAVE:
1037  return "double";
1038  default:
1039  return "single";
1040  }
1041 }
1042 
1043 const char* getFontFamilyOOXValue(FontFamily eValue)
1044 {
1045  switch (eValue)
1046  {
1047  case FAMILY_DONTKNOW:
1048  return "0";
1049  case FAMILY_SWISS:
1050  case FAMILY_SYSTEM:
1051  return "2";
1052  case FAMILY_ROMAN:
1053  return "1";
1054  case FAMILY_SCRIPT:
1055  return "4";
1056  case FAMILY_MODERN:
1057  return "3";
1058  case FAMILY_DECORATIVE:
1059  return "5";
1060  default:
1061  return "0";
1062  }
1063 }
1064 
1065 }
1066 
1068 {
1069  if (maDxfData.isEmpty())
1070  return;
1071 
1072  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
1073  rStyleSheet->startElement(XML_font);
1074 
1075  if (maDxfData.pFontAttr)
1076  {
1077  OUString aFontName = (*maDxfData.pFontAttr)->GetFamilyName();
1078 
1079  aFontName = XclTools::GetXclFontName(aFontName);
1080  if (!aFontName.isEmpty())
1081  {
1082  rStyleSheet->singleElement(XML_name, XML_val, aFontName);
1083  }
1084 
1085  rtl_TextEncoding eTextEnc = (*maDxfData.pFontAttr)->GetCharSet();
1086  sal_uInt8 nExcelCharSet = rtl_getBestWindowsCharsetFromTextEncoding(eTextEnc);
1087  if (nExcelCharSet)
1088  {
1089  rStyleSheet->singleElement(XML_charset, XML_val, OString::number(nExcelCharSet));
1090  }
1091 
1092  FontFamily eFamily = (*maDxfData.pFontAttr)->GetFamily();
1093  const char* pVal = getFontFamilyOOXValue(eFamily);
1094  if (pVal)
1095  {
1096  rStyleSheet->singleElement(XML_family, XML_val, pVal);
1097  }
1098  }
1099 
1100  if (maDxfData.eWeight)
1101  {
1102  rStyleSheet->singleElement(XML_b,
1103  XML_val, ToPsz10(*maDxfData.eWeight != WEIGHT_NORMAL));
1104  }
1105 
1106  if (maDxfData.eItalic)
1107  {
1108  bool bItalic = (*maDxfData.eItalic == ITALIC_OBLIQUE) || (*maDxfData.eItalic == ITALIC_NORMAL);
1109  rStyleSheet->singleElement(XML_i, XML_val, ToPsz10(bItalic));
1110  }
1111 
1112  if (maDxfData.eStrike)
1113  {
1114  bool bStrikeout =
1118 
1119  rStyleSheet->singleElement(XML_strike, XML_val, ToPsz10(bStrikeout));
1120  }
1121 
1122  if (maDxfData.bOutline)
1123  {
1124  rStyleSheet->singleElement(XML_outline, XML_val, ToPsz10(*maDxfData.bOutline));
1125  }
1126 
1127  if (maDxfData.bShadow)
1128  {
1129  rStyleSheet->singleElement(XML_shadow, XML_val, ToPsz10(*maDxfData.bShadow));
1130  }
1131 
1132  if (maDxfData.aColor)
1133  {
1134  rStyleSheet->singleElement(XML_color,
1136  }
1137 
1138  if (maDxfData.nFontHeight)
1139  {
1140  rStyleSheet->singleElement(XML_sz,
1141  XML_val, OString::number(*maDxfData.nFontHeight/20));
1142  }
1143 
1144  if (maDxfData.eUnder)
1145  {
1146  const char* pVal = getUnderlineOOXValue(*maDxfData.eUnder);
1147  rStyleSheet->singleElement(XML_u, XML_val, pVal);
1148  }
1149 
1150  rStyleSheet->endElement(XML_font);
1151 }
1152 
1155 {
1156 }
1157 
1158 bool XclExpBlindFont::Equals( const XclFontData& /*rFontData*/, sal_uInt32 /*nHash*/ ) const
1159 {
1160  return false;
1161 }
1162 
1164 {
1165  // do nothing
1166 }
1167 
1169  XclExpRoot( rRoot ),
1170  mnXclMaxSize( 0 )
1171 {
1172  switch( GetBiff() )
1173  {
1174  case EXC_BIFF4: mnXclMaxSize = EXC_FONT_MAXCOUNT4; break;
1175  case EXC_BIFF5: mnXclMaxSize = EXC_FONT_MAXCOUNT5; break;
1176  case EXC_BIFF8: mnXclMaxSize = EXC_FONT_MAXCOUNT8; break;
1177  default: DBG_ERROR_BIFF();
1178  }
1179  InitDefaultFonts();
1180 }
1181 
1182 const XclExpFont* XclExpFontBuffer::GetFont( sal_uInt16 nXclFont ) const
1183 {
1184  return maFontList.GetRecord( nXclFont );
1185 }
1186 
1188 {
1189  return maFontList.GetRecord( EXC_FONT_APP )->GetFontData(); // exists always
1190 }
1191 
1193  const XclFontData& rFontData, XclExpColorType eColorType, bool bAppFont )
1194 {
1195  if( bAppFont )
1196  {
1197  XclExpFontRef xFont = new XclExpFont( GetRoot(), rFontData, eColorType );
1199  // set width of '0' character for column width export
1200  SetCharWidth( xFont->GetFontData() );
1201  return EXC_FONT_APP;
1202  }
1203 
1204  size_t nPos = Find( rFontData );
1205  if( nPos == EXC_FONTLIST_NOTFOUND )
1206  {
1207  // not found in buffer - create new font
1208  size_t nSize = maFontList.GetSize();
1209  if( nSize < mnXclMaxSize )
1210  {
1211  // possible to insert
1212  maFontList.AppendNewRecord( new XclExpFont( GetRoot(), rFontData, eColorType ) );
1213  nPos = nSize; // old size is last position now
1214  }
1215  else
1216  {
1217  // buffer is full - ignore new font, use default font
1218  nPos = EXC_FONT_APP;
1219  }
1220  }
1221  return static_cast< sal_uInt16 >( nPos );
1222 }
1223 
1225  const SvxFont& rFont, XclExpColorType eColorType )
1226 {
1227  return Insert( XclFontData( rFont ), eColorType );
1228 }
1229 
1230 sal_uInt16 XclExpFontBuffer::Insert( const SfxItemSet& rItemSet,
1231  sal_Int16 nScript, XclExpColorType eColorType, bool bAppFont )
1232 {
1233  // #i17050# script type now provided by caller
1234  vcl::Font aFont = XclExpFontHelper::GetFontFromItemSet( GetRoot(), rItemSet, nScript );
1235  return Insert( XclFontData( aFont ), eColorType, bAppFont );
1236 }
1237 
1239 {
1240  maFontList.Save( rStrm );
1241 }
1242 
1244 {
1245  if( maFontList.IsEmpty() )
1246  return;
1247 
1248  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
1249  rStyleSheet->startElement(XML_fonts, XML_count, OString::number(maFontList.GetSize()));
1250 
1251  maFontList.SaveXml( rStrm );
1252 
1253  rStyleSheet->endElement( XML_fonts );
1254 }
1255 
1256 // private --------------------------------------------------------------------
1257 
1259 {
1260  XclFontData aFontData;
1261  aFontData.maName = "Arial";
1262  aFontData.SetScFamily( FAMILY_DONTKNOW );
1264  aFontData.SetScHeight( 200 ); // 200 twips = 10 pt
1265  aFontData.SetScWeight( WEIGHT_NORMAL );
1266 
1267  switch( GetBiff() )
1268  {
1269  case EXC_BIFF5:
1270  {
1272  aFontData.SetScWeight( WEIGHT_BOLD );
1274  aFontData.SetScWeight( WEIGHT_NORMAL );
1275  aFontData.SetScPosture( ITALIC_NORMAL );
1277  aFontData.SetScWeight( WEIGHT_BOLD );
1279  // the blind font with index 4
1281  // already add the first user defined font (Excel does it too)
1282  aFontData.SetScWeight( WEIGHT_NORMAL );
1283  aFontData.SetScPosture( ITALIC_NONE );
1285  }
1286  break;
1287  case EXC_BIFF8:
1288  {
1289  XclExpFontRef xFont = new XclExpFont( GetRoot(), aFontData, EXC_COLOR_CELLTEXT );
1290  maFontList.AppendRecord( xFont );
1291  maFontList.AppendRecord( xFont );
1292  maFontList.AppendRecord( xFont );
1293  maFontList.AppendRecord( xFont );
1294  if( GetOutput() == EXC_OUTPUT_BINARY )
1295  // the blind font with index 4
1297  }
1298  break;
1299  default:
1300  DBG_ERROR_BIFF();
1301  }
1302 }
1303 
1304 size_t XclExpFontBuffer::Find( const XclFontData& rFontData )
1305 {
1306  sal_uInt32 nHash = lclCalcHash( rFontData );
1307  for( size_t nPos = 0, nSize = maFontList.GetSize(); nPos < nSize; ++nPos )
1308  if( maFontList.GetRecord( nPos )->Equals( rFontData, nHash ) )
1309  return nPos;
1310  return EXC_FONTLIST_NOTFOUND;
1311 }
1312 
1313 // FORMAT record - number formats =============================================
1314 
1315 namespace {
1316 
1318 struct XclExpNumFmtPred
1319 {
1320  sal_uInt32 mnScNumFmt;
1321  explicit XclExpNumFmtPred( sal_uInt32 nScNumFmt ) : mnScNumFmt( nScNumFmt ) {}
1322  bool operator()( const XclExpNumFmt& rFormat ) const
1323  { return rFormat.mnScNumFmt == mnScNumFmt; }
1324 };
1325 
1326 }
1327 
1329 {
1330  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
1331  rStyleSheet->singleElement( XML_numFmt,
1332  XML_numFmtId, OString::number(mnXclNumFmt),
1333  XML_formatCode, maNumFmtString );
1334 }
1335 
1337  XclExpRoot( rRoot ),
1339  mpKeywordTable( new NfKeywordTable ),
1340  mnStdFmt( GetFormatter().GetStandardIndex( ScGlobal::eLnge ) )
1341 {
1342  switch( GetBiff() )
1343  {
1344  case EXC_BIFF5: mnXclOffset = EXC_FORMAT_OFFSET5; break;
1345  case EXC_BIFF8: mnXclOffset = EXC_FORMAT_OFFSET8; break;
1346  default: mnXclOffset = 0; DBG_ERROR_BIFF();
1347  }
1348 
1349  mxFormatter->FillKeywordTableForExcel( *mpKeywordTable );
1350 }
1351 
1353 {
1354 }
1355 
1356 sal_uInt16 XclExpNumFmtBuffer::Insert( sal_uInt32 nScNumFmt )
1357 {
1358  XclExpNumFmtVec::const_iterator aIt =
1359  ::std::find_if( maFormatMap.begin(), maFormatMap.end(), XclExpNumFmtPred( nScNumFmt ) );
1360  if( aIt != maFormatMap.end() )
1361  return aIt->mnXclNumFmt;
1362 
1363  size_t nSize = maFormatMap.size();
1364  if( nSize < o3tl::make_unsigned( 0xFFFF - mnXclOffset ) )
1365  {
1366  sal_uInt16 nXclNumFmt = static_cast< sal_uInt16 >( nSize + mnXclOffset );
1367  maFormatMap.emplace_back( nScNumFmt, nXclNumFmt, GetFormatCode( nScNumFmt ) );
1368  return nXclNumFmt;
1369  }
1370 
1371  return 0;
1372 }
1373 
1375 {
1376  for( const auto& rEntry : maFormatMap )
1377  WriteFormatRecord( rStrm, rEntry );
1378 }
1379 
1381 {
1382  if( maFormatMap.empty() )
1383  return;
1384 
1385  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
1386  rStyleSheet->startElement(XML_numFmts, XML_count, OString::number(maFormatMap.size()));
1387  for( auto& rEntry : maFormatMap )
1388  {
1389  rEntry.SaveXml( rStrm );
1390  }
1391  rStyleSheet->endElement( XML_numFmts );
1392 }
1393 
1394 void XclExpNumFmtBuffer::WriteFormatRecord( XclExpStream& rStrm, sal_uInt16 nXclNumFmt, const OUString& rFormatStr )
1395 {
1396  XclExpString aExpStr;
1397  if( GetBiff() <= EXC_BIFF5 )
1398  aExpStr.AssignByte( rFormatStr, GetTextEncoding(), XclStrFlags::EightBitLength );
1399  else
1400  aExpStr.Assign( rFormatStr );
1401 
1402  rStrm.StartRecord( EXC_ID4_FORMAT, 2 + aExpStr.GetSize() );
1403  rStrm << nXclNumFmt << aExpStr;
1404  rStrm.EndRecord();
1405 }
1406 
1408 {
1409  WriteFormatRecord( rStrm, rFormat.mnXclNumFmt, GetFormatCode( rFormat.mnScNumFmt ) );
1410 }
1411 
1412 namespace {
1413 
1414 OUString GetNumberFormatCode(const XclRoot& rRoot, const sal_uInt32 nScNumFmt, SvNumberFormatter* pFormatter, const NfKeywordTable* pKeywordTable)
1415 {
1416  return rRoot.GetFormatter().GetFormatStringForExcel( nScNumFmt, *pKeywordTable, *pFormatter);
1417 }
1418 
1419 }
1420 
1421 OUString XclExpNumFmtBuffer::GetFormatCode( sal_uInt32 nScNumFmt )
1422 {
1423  return GetNumberFormatCode( *this, nScNumFmt, mxFormatter.get(), mpKeywordTable.get() );
1424 }
1425 
1426 // XF, STYLE record - Cell formatting =========================================
1427 
1428 bool XclExpCellProt::FillFromItemSet( const SfxItemSet& rItemSet, bool bStyle )
1429 {
1430  const ScProtectionAttr& rProtItem = rItemSet.Get( ATTR_PROTECTION );
1431  mbLocked = rProtItem.GetProtection();
1432  mbHidden = rProtItem.GetHideFormula() || rProtItem.GetHideCell();
1433  return ScfTools::CheckItem( rItemSet, ATTR_PROTECTION, bStyle );
1434 }
1435 
1436 void XclExpCellProt::FillToXF3( sal_uInt16& rnProt ) const
1437 {
1438  ::set_flag( rnProt, EXC_XF_LOCKED, mbLocked );
1439  ::set_flag( rnProt, EXC_XF_HIDDEN, mbHidden );
1440 }
1441 
1443 {
1444  rStrm.GetCurrentStream()->singleElement( XML_protection,
1445  XML_locked, ToPsz( mbLocked ),
1446  XML_hidden, ToPsz( mbHidden ) );
1447 }
1448 
1449 bool XclExpCellAlign::FillFromItemSet(const XclRoot& rRoot, const SfxItemSet& rItemSet,
1450  bool bForceLineBreak, XclBiff eBiff, bool bStyle)
1451 {
1452  bool bUsed = false;
1453  SvxCellHorJustify eHorAlign = rItemSet.Get( ATTR_HOR_JUSTIFY ).GetValue();
1454  SvxCellVerJustify eVerAlign = rItemSet.Get( ATTR_VER_JUSTIFY ).GetValue();
1455 
1456  switch( eBiff )
1457  {
1458  case EXC_BIFF8: // attributes new in BIFF8
1459  {
1460  // text indent
1461  tools::Long nTmpIndent = rItemSet.Get( ATTR_INDENT ).GetValue(); // already in twips
1462  tools::Long nSpaceWidth = rRoot.GetSpaceWidth();
1463  sal_Int32 nIndent = static_cast<double>(nTmpIndent) / (3.0 * nSpaceWidth) + 0.5;
1464  mnIndent = limit_cast< sal_uInt8 >( nIndent, 0, 15 );
1465  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_INDENT, bStyle );
1466 
1467  // shrink to fit
1468  mbShrink = rItemSet.Get( ATTR_SHRINKTOFIT ).GetValue();
1469  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_SHRINKTOFIT, bStyle );
1470 
1471  // CTL text direction
1472  SetScFrameDir( rItemSet.Get( ATTR_WRITINGDIR ).GetValue() );
1473  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_WRITINGDIR, bStyle );
1474 
1475  [[fallthrough]];
1476  }
1477 
1478  case EXC_BIFF5: // attributes new in BIFF5
1479  case EXC_BIFF4: // attributes new in BIFF4
1480  {
1481  // vertical alignment
1482  SetScVerAlign( eVerAlign );
1483  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_VER_JUSTIFY, bStyle );
1484 
1485  // stacked/rotation
1486  bool bStacked = rItemSet.Get( ATTR_STACKED ).GetValue();
1487  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_STACKED, bStyle );
1488  if( bStacked )
1489  {
1491  }
1492  else
1493  {
1494  // rotation
1495  Degree100 nScRot = rItemSet.Get( ATTR_ROTATE_VALUE ).GetValue();
1497  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_ROTATE_VALUE, bStyle );
1498  }
1500 
1501  [[fallthrough]];
1502  }
1503 
1504  case EXC_BIFF3: // attributes new in BIFF3
1505  {
1506  // text wrap
1507  mbLineBreak = bForceLineBreak || rItemSet.Get( ATTR_LINEBREAK ).GetValue();
1508  bUsed |= bForceLineBreak || ScfTools::CheckItem( rItemSet, ATTR_LINEBREAK, bStyle );
1509 
1510  [[fallthrough]];
1511  }
1512 
1513  case EXC_BIFF2: // attributes new in BIFF2
1514  {
1515  // horizontal alignment
1516  SetScHorAlign( eHorAlign );
1517  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_HOR_JUSTIFY, bStyle );
1518  }
1519 
1520  break;
1521  default: DBG_ERROR_BIFF();
1522  }
1523 
1524  if (eBiff == EXC_BIFF8)
1525  {
1526  // Adjust for distributed alignments.
1527  if (eHorAlign == SvxCellHorJustify::Block)
1528  {
1529  SvxCellJustifyMethod eHorJustMethod =
1531  if (eHorJustMethod == SvxCellJustifyMethod::Distribute)
1533  }
1534 
1535  if (eVerAlign == SvxCellVerJustify::Block)
1536  {
1537  SvxCellJustifyMethod eVerJustMethod =
1539  if (eVerJustMethod == SvxCellJustifyMethod::Distribute)
1541  }
1542  }
1543 
1544  return bUsed;
1545 }
1546 
1547 void XclExpCellAlign::FillToXF5( sal_uInt16& rnAlign ) const
1548 {
1549  ::insert_value( rnAlign, mnHorAlign, 0, 3 );
1551  ::insert_value( rnAlign, mnVerAlign, 4, 3 );
1552  ::insert_value( rnAlign, mnOrient, 8, 2 );
1553 }
1554 
1555 void XclExpCellAlign::FillToXF8( sal_uInt16& rnAlign, sal_uInt16& rnMiscAttrib ) const
1556 {
1557  ::insert_value( rnAlign, mnHorAlign, 0, 3 );
1559  ::insert_value( rnAlign, mnVerAlign, 4, 3 );
1560  ::insert_value( rnAlign, mnRotation, 8, 8 );
1561  ::insert_value( rnMiscAttrib, mnIndent, 0, 4 );
1562  ::set_flag( rnMiscAttrib, EXC_XF8_SHRINK, mbShrink );
1563  ::insert_value( rnMiscAttrib, mnTextDir, 6, 2 );
1564 }
1565 
1566 static const char* ToHorizontalAlignment( sal_uInt8 nHorAlign )
1567 {
1568  switch( nHorAlign )
1569  {
1570  case EXC_XF_HOR_GENERAL: return "general";
1571  case EXC_XF_HOR_LEFT: return "left";
1572  case EXC_XF_HOR_CENTER: return "center";
1573  case EXC_XF_HOR_RIGHT: return "right";
1574  case EXC_XF_HOR_FILL: return "fill";
1575  case EXC_XF_HOR_JUSTIFY: return "justify";
1576  case EXC_XF_HOR_CENTER_AS: return "centerContinuous";
1577  case EXC_XF_HOR_DISTRIB: return "distributed";
1578  }
1579  return "*unknown*";
1580 }
1581 
1582 static const char* ToVerticalAlignment( sal_uInt8 nVerAlign )
1583 {
1584  switch( nVerAlign )
1585  {
1586  case EXC_XF_VER_TOP: return "top";
1587  case EXC_XF_VER_CENTER: return "center";
1588  case EXC_XF_VER_BOTTOM: return "bottom";
1589  case EXC_XF_VER_JUSTIFY: return "justify";
1590  case EXC_XF_VER_DISTRIB: return "distributed";
1591  }
1592  return "*unknown*";
1593 }
1594 
1596 {
1597  rStrm.GetCurrentStream()->singleElement( XML_alignment,
1598  XML_horizontal, ToHorizontalAlignment( mnHorAlign ),
1599  XML_vertical, ToVerticalAlignment( mnVerAlign ),
1600  XML_textRotation, OString::number(mnRotation),
1601  XML_wrapText, ToPsz( mbLineBreak ),
1602  XML_indent, OString::number(mnIndent),
1603  // OOXTODO: XML_relativeIndent, mnIndent?
1604  // OOXTODO: XML_justifyLastLine,
1605  XML_shrinkToFit, ToPsz( mbShrink ),
1606  XML_readingOrder, sax_fastparser::UseIf(OString::number(mnTextDir), mnTextDir != EXC_XF_TEXTDIR_CONTEXT) );
1607 }
1608 
1609 namespace {
1610 
1611 void lclGetBorderLine(
1612  sal_uInt8& rnXclLine, sal_uInt32& rnColorId,
1613  const ::editeng::SvxBorderLine* pLine, XclExpPalette& rPalette, XclBiff eBiff )
1614 {
1615  // Document: sc/qa/unit/data/README.cellborders
1616 
1617  enum CalcLineIndex{Idx_None, Idx_Solid, Idx_Dotted, Idx_Dashed, Idx_FineDashed, Idx_DashDot, Idx_DashDotDot, Idx_DoubleThin, Idx_Last};
1618  enum ExcelWidthIndex{Width_Hair, Width_Thin, Width_Medium, Width_Thick, Width_Last};
1619  static sal_uInt8 Map_LineLO_toMS[Idx_Last][Width_Last] =
1620  {
1621  // 0,05 - 0,74 0,75 - 1,49 1,50 - 2,49 2,50 - 9,00 Width Range [pt]
1622  // EXC_BORDER_HAIR EXC_BORDER_THIN EXC_BORDER_MEDIUM EXC_BORDER_THICK MS Width
1623  {EXC_LINE_NONE , EXC_LINE_NONE , EXC_LINE_NONE , EXC_LINE_NONE }, // 0 BorderLineStyle::NONE
1624  {EXC_LINE_HAIR , EXC_LINE_THIN , EXC_LINE_MEDIUM , EXC_LINE_THICK }, // 1 BorderLineStyle::SOLID
1625  {EXC_LINE_DOTTED , EXC_LINE_DOTTED , EXC_LINE_MEDIUM_SLANT_DASHDOT, EXC_LINE_MEDIUM_SLANT_DASHDOT}, // 2 BorderLineStyle::DOTTED
1626  {EXC_LINE_DOTTED , EXC_LINE_DASHED , EXC_LINE_MEDIUM_DASHED , EXC_LINE_MEDIUM_DASHED }, // 3 BorderLineStyle::DASHED
1627  {EXC_LINE_DASHED , EXC_LINE_DASHED , EXC_LINE_MEDIUM_SLANT_DASHDOT, EXC_LINE_MEDIUM_SLANT_DASHDOT}, // 4 BorderLineStyle::FINE_DASHED
1628  {EXC_LINE_DASHED , EXC_LINE_THIN_DASHDOT , EXC_LINE_MEDIUM_DASHDOT , EXC_LINE_MEDIUM_DASHDOT }, // 5 BorderLineStyle::DASH_DOT
1629  {EXC_LINE_DASHED , EXC_LINE_THIN_DASHDOTDOT , EXC_LINE_MEDIUM_DASHDOTDOT , EXC_LINE_MEDIUM_DASHDOTDOT }, // 6 BorderLineStyle::DASH_DOT_DOT
1630  {EXC_LINE_DOUBLE , EXC_LINE_DOUBLE , EXC_LINE_DOUBLE , EXC_LINE_DOUBLE } // 7 BorderLineStyle::DOUBLE_THIN
1631  }; // Line Name
1632 
1633  rnXclLine = EXC_LINE_NONE;
1634  if( pLine )
1635  {
1636  sal_uInt16 nOuterWidth = pLine->GetOutWidth();
1637  ExcelWidthIndex nOuterWidthIndx;
1638  CalcLineIndex nStyleIndex;
1639 
1640  switch (pLine->GetBorderLineStyle())
1641  {
1642  case SvxBorderLineStyle::NONE:
1643  nStyleIndex = Idx_None;
1644  break;
1645  case SvxBorderLineStyle::SOLID:
1646  nStyleIndex = Idx_Solid;
1647  break;
1648  case SvxBorderLineStyle::DOTTED:
1649  nStyleIndex = Idx_Dotted;
1650  break;
1651  case SvxBorderLineStyle::DASHED:
1652  nStyleIndex = Idx_Dashed;
1653  break;
1654  case SvxBorderLineStyle::FINE_DASHED:
1655  nStyleIndex = Idx_FineDashed;
1656  break;
1657  case SvxBorderLineStyle::DASH_DOT:
1658  nStyleIndex = Idx_DashDot;
1659  break;
1660  case SvxBorderLineStyle::DASH_DOT_DOT:
1661  nStyleIndex = Idx_DashDotDot;
1662  break;
1663  case SvxBorderLineStyle::DOUBLE_THIN:
1664  // the "nOuterWidth" is not right for this line type
1665  // but at the moment width it not important for that
1666  // the right function is nOuterWidth = (sal_uInt16) pLine->GetWidth();
1667  nStyleIndex = Idx_DoubleThin;
1668  break;
1669  default:
1670  nStyleIndex = Idx_Solid;
1671  }
1672 
1673  if( nOuterWidth >= EXC_BORDER_THICK )
1674  nOuterWidthIndx = Width_Thick;
1675  else if( nOuterWidth >= EXC_BORDER_MEDIUM )
1676  nOuterWidthIndx = Width_Medium;
1677  else if( nOuterWidth >= EXC_BORDER_THIN )
1678  nOuterWidthIndx = Width_Thin;
1679  else if ( nOuterWidth >= EXC_BORDER_HAIR )
1680  nOuterWidthIndx = Width_Hair;
1681  else
1682  nOuterWidthIndx = Width_Thin;
1683 
1684  rnXclLine = Map_LineLO_toMS[nStyleIndex][nOuterWidthIndx];
1685  }
1686 
1687  if( (eBiff == EXC_BIFF2) && (rnXclLine != EXC_LINE_NONE) )
1688  rnXclLine = EXC_LINE_THIN;
1689 
1690  rnColorId = (pLine && (rnXclLine != EXC_LINE_NONE)) ?
1691  rPalette.InsertColor( pLine->GetColor(), EXC_COLOR_CELLBORDER ) :
1693 }
1694 
1695 } // namespace
1696 
1698  mnLeftColorId( XclExpPalette::GetColorIdFromIndex( mnLeftColor ) ),
1699  mnRightColorId( XclExpPalette::GetColorIdFromIndex( mnRightColor ) ),
1700  mnTopColorId( XclExpPalette::GetColorIdFromIndex( mnTopColor ) ),
1701  mnBottomColorId( XclExpPalette::GetColorIdFromIndex( mnBottomColor ) ),
1702  mnDiagColorId( XclExpPalette::GetColorIdFromIndex( mnDiagColor ) )
1703 {
1704 }
1705 
1707  const SfxItemSet& rItemSet, XclExpPalette& rPalette, XclBiff eBiff, bool bStyle )
1708 {
1709  bool bUsed = false;
1710 
1711  switch( eBiff )
1712  {
1713  case EXC_BIFF8: // attributes new in BIFF8
1714  {
1715  const SvxLineItem& rTLBRItem = rItemSet.Get( ATTR_BORDER_TLBR );
1716  sal_uInt8 nTLBRLine;
1717  sal_uInt32 nTLBRColorId;
1718  lclGetBorderLine( nTLBRLine, nTLBRColorId, rTLBRItem.GetLine(), rPalette, eBiff );
1719  mbDiagTLtoBR = (nTLBRLine != EXC_LINE_NONE);
1720 
1721  const SvxLineItem& rBLTRItem = rItemSet.Get( ATTR_BORDER_BLTR );
1722  sal_uInt8 nBLTRLine;
1723  sal_uInt32 nBLTRColorId;
1724  lclGetBorderLine( nBLTRLine, nBLTRColorId, rBLTRItem.GetLine(), rPalette, eBiff );
1725  mbDiagBLtoTR = (nBLTRLine != EXC_LINE_NONE);
1726 
1727  if( ::ScHasPriority( rTLBRItem.GetLine(), rBLTRItem.GetLine() ) )
1728  {
1729  mnDiagLine = nTLBRLine;
1730  mnDiagColorId = nTLBRColorId;
1731  }
1732  else
1733  {
1734  mnDiagLine = nBLTRLine;
1735  mnDiagColorId = nBLTRColorId;
1736  }
1737 
1738  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_BORDER_TLBR, bStyle ) ||
1739  ScfTools::CheckItem( rItemSet, ATTR_BORDER_BLTR, bStyle );
1740 
1741  [[fallthrough]];
1742  }
1743 
1744  case EXC_BIFF5:
1745  case EXC_BIFF4:
1746  case EXC_BIFF3:
1747  case EXC_BIFF2:
1748  {
1749  const SvxBoxItem& rBoxItem = rItemSet.Get( ATTR_BORDER );
1750  lclGetBorderLine( mnLeftLine, mnLeftColorId, rBoxItem.GetLeft(), rPalette, eBiff );
1751  lclGetBorderLine( mnRightLine, mnRightColorId, rBoxItem.GetRight(), rPalette, eBiff );
1752  lclGetBorderLine( mnTopLine, mnTopColorId, rBoxItem.GetTop(), rPalette, eBiff );
1753  lclGetBorderLine( mnBottomLine, mnBottomColorId, rBoxItem.GetBottom(), rPalette, eBiff );
1754  bUsed |= ScfTools::CheckItem( rItemSet, ATTR_BORDER, bStyle );
1755  }
1756 
1757  break;
1758  default: DBG_ERROR_BIFF();
1759  }
1760 
1761  return bUsed;
1762 }
1763 
1765 {
1766  mnLeftColor = rPalette.GetColorIndex( mnLeftColorId );
1768  mnTopColor = rPalette.GetColorIndex( mnTopColorId );
1770  mnDiagColor = rPalette.GetColorIndex( mnDiagColorId );
1771 }
1772 
1773 void XclExpCellBorder::FillToXF5( sal_uInt32& rnBorder, sal_uInt32& rnArea ) const
1774 {
1775  ::insert_value( rnBorder, mnTopLine, 0, 3 );
1776  ::insert_value( rnBorder, mnLeftLine, 3, 3 );
1777  ::insert_value( rnArea, mnBottomLine, 22, 3 );
1778  ::insert_value( rnBorder, mnRightLine, 6, 3 );
1779  ::insert_value( rnBorder, mnTopColor, 9, 7 );
1780  ::insert_value( rnBorder, mnLeftColor, 16, 7 );
1781  ::insert_value( rnArea, mnBottomColor, 25, 7 );
1782  ::insert_value( rnBorder, mnRightColor, 23, 7 );
1783 }
1784 
1785 void XclExpCellBorder::FillToXF8( sal_uInt32& rnBorder1, sal_uInt32& rnBorder2 ) const
1786 {
1787  ::insert_value( rnBorder1, mnLeftLine, 0, 4 );
1788  ::insert_value( rnBorder1, mnRightLine, 4, 4 );
1789  ::insert_value( rnBorder1, mnTopLine, 8, 4 );
1790  ::insert_value( rnBorder1, mnBottomLine, 12, 4 );
1791  ::insert_value( rnBorder1, mnLeftColor, 16, 7 );
1792  ::insert_value( rnBorder1, mnRightColor, 23, 7 );
1793  ::insert_value( rnBorder2, mnTopColor, 0, 7 );
1794  ::insert_value( rnBorder2, mnBottomColor, 7, 7 );
1795  ::insert_value( rnBorder2, mnDiagColor, 14, 7 );
1796  ::insert_value( rnBorder2, mnDiagLine, 21, 4 );
1799 }
1800 
1801 void XclExpCellBorder::FillToCF8( sal_uInt16& rnLine, sal_uInt32& rnColor ) const
1802 {
1803  ::insert_value( rnLine, mnLeftLine, 0, 4 );
1804  ::insert_value( rnLine, mnRightLine, 4, 4 );
1805  ::insert_value( rnLine, mnTopLine, 8, 4 );
1806  ::insert_value( rnLine, mnBottomLine, 12, 4 );
1807  ::insert_value( rnColor, mnLeftColor, 0, 7 );
1808  ::insert_value( rnColor, mnRightColor, 7, 7 );
1809  ::insert_value( rnColor, mnTopColor, 16, 7 );
1810  ::insert_value( rnColor, mnBottomColor, 23, 7 );
1811 }
1812 
1813 static const char* ToLineStyle( sal_uInt8 nLineStyle )
1814 {
1815  switch( nLineStyle )
1816  {
1817  case EXC_LINE_NONE: return "none";
1818  case EXC_LINE_THIN: return "thin";
1819  case EXC_LINE_MEDIUM: return "medium";
1820  case EXC_LINE_THICK: return "thick";
1821  case EXC_LINE_DOUBLE: return "double";
1822  case EXC_LINE_HAIR: return "hair";
1823  case EXC_LINE_DOTTED: return "dotted";
1824  case EXC_LINE_DASHED: return "dashed";
1825  case EXC_LINE_MEDIUM_DASHED: return "mediumDashed";
1826  case EXC_LINE_THIN_DASHDOT: return "dashDot";
1827  case EXC_LINE_THIN_DASHDOTDOT: return "dashDotDot";
1828  case EXC_LINE_MEDIUM_DASHDOT: return "mediumDashDot";
1829  case EXC_LINE_MEDIUM_DASHDOTDOT: return "mediumDashDotDot";
1830  case EXC_LINE_MEDIUM_SLANT_DASHDOT: return "slantDashDot";
1831  }
1832  return "*unknown*";
1833 }
1834 
1835 static void lcl_WriteBorder( XclExpXmlStream& rStrm, sal_Int32 nElement, sal_uInt8 nLineStyle, const Color& rColor )
1836 {
1837  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
1838  if( nLineStyle == EXC_LINE_NONE )
1839  rStyleSheet->singleElement(nElement);
1840  else if( rColor == Color( 0, 0, 0 ) )
1841  rStyleSheet->singleElement(nElement, XML_style, ToLineStyle(nLineStyle));
1842  else
1843  {
1844  rStyleSheet->startElement(nElement, XML_style, ToLineStyle(nLineStyle));
1845  rStyleSheet->singleElement(XML_color, XML_rgb, XclXmlUtils::ToOString(rColor));
1846  rStyleSheet->endElement( nElement );
1847  }
1848 }
1849 
1851 {
1852  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
1853 
1854  XclExpPalette& rPalette = rStrm.GetRoot().GetPalette();
1855 
1856  rStyleSheet->startElement( XML_border,
1857  XML_diagonalUp, ToPsz( mbDiagBLtoTR ),
1858  XML_diagonalDown, ToPsz( mbDiagTLtoBR )
1859  // OOXTODO: XML_outline
1860  );
1861  lcl_WriteBorder( rStrm, XML_left, mnLeftLine, rPalette.GetColor( mnLeftColor ) );
1862  lcl_WriteBorder( rStrm, XML_right, mnRightLine, rPalette.GetColor( mnRightColor ) );
1863  lcl_WriteBorder( rStrm, XML_top, mnTopLine, rPalette.GetColor( mnTopColor ) );
1864  lcl_WriteBorder( rStrm, XML_bottom, mnBottomLine, rPalette.GetColor( mnBottomColor ) );
1865  lcl_WriteBorder( rStrm, XML_diagonal, mnDiagLine, rPalette.GetColor( mnDiagColor ) );
1866  // OOXTODO: XML_vertical, XML_horizontal
1867  rStyleSheet->endElement( XML_border );
1868 }
1869 
1871  mnForeColorId( XclExpPalette::GetColorIdFromIndex( mnForeColor ) ),
1872  mnBackColorId( XclExpPalette::GetColorIdFromIndex( mnBackColor ) ),
1873  maForeColor(0),
1874  maBackColor(0)
1875 {
1876 }
1877 
1880  , mnForeColorId(0)
1881  , mnBackColorId(0)
1882  , maForeColor(aForeColor)
1883  , maBackColor(aBackColor)
1884 {
1885 }
1886 
1887 bool XclExpCellArea::FillFromItemSet( const SfxItemSet& rItemSet, XclExpPalette& rPalette, bool bStyle )
1888 {
1889  const SvxBrushItem& rBrushItem = rItemSet.Get( ATTR_BACKGROUND );
1890  if( rBrushItem.GetColor().IsTransparent() )
1891  {
1895  }
1896  else
1897  {
1899  mnForeColorId = rPalette.InsertColor( rBrushItem.GetColor(), EXC_COLOR_CELLAREA );
1901  }
1902  return ScfTools::CheckItem( rItemSet, ATTR_BACKGROUND, bStyle );
1903 }
1904 
1906 {
1908 }
1909 
1910 void XclExpCellArea::FillToXF5( sal_uInt32& rnArea ) const
1911 {
1912  ::insert_value( rnArea, mnPattern, 16, 6 );
1913  ::insert_value( rnArea, mnForeColor, 0, 7 );
1914  ::insert_value( rnArea, mnBackColor, 7, 7 );
1915 }
1916 
1917 void XclExpCellArea::FillToXF8( sal_uInt32& rnBorder2, sal_uInt16& rnArea ) const
1918 {
1919  ::insert_value( rnBorder2, mnPattern, 26, 6 );
1920  ::insert_value( rnArea, mnForeColor, 0, 7 );
1921  ::insert_value( rnArea, mnBackColor, 7, 7 );
1922 }
1923 
1924 void XclExpCellArea::FillToCF8( sal_uInt16& rnPattern, sal_uInt16& rnColor ) const
1925 {
1926  XclCellArea aTmp( *this );
1927  if( !aTmp.IsTransparent() && (aTmp.mnBackColor == EXC_COLOR_WINDOWTEXT) )
1928  aTmp.mnBackColor = 0;
1929  if( aTmp.mnPattern == EXC_PATT_SOLID )
1930  ::std::swap( aTmp.mnForeColor, aTmp.mnBackColor );
1931  ::insert_value( rnColor, aTmp.mnForeColor, 0, 7 );
1932  ::insert_value( rnColor, aTmp.mnBackColor, 7, 7 );
1933  ::insert_value( rnPattern, aTmp.mnPattern, 10, 6 );
1934 }
1935 
1936 static const char* ToPatternType( sal_uInt8 nPattern )
1937 {
1938  switch( nPattern )
1939  {
1940  case EXC_PATT_NONE: return "none";
1941  case EXC_PATT_SOLID: return "solid";
1942  case EXC_PATT_50_PERC: return "mediumGray";
1943  case EXC_PATT_75_PERC: return "darkGray";
1944  case EXC_PATT_25_PERC: return "lightGray";
1945  case EXC_PATT_12_5_PERC: return "gray125";
1946  case EXC_PATT_6_25_PERC: return "gray0625";
1947  }
1948  return "*unknown*";
1949 }
1950 
1952 {
1953  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
1954  rStyleSheet->startElement(XML_fill);
1955 
1956  // OOXTODO: XML_gradientFill
1957 
1958  XclExpPalette& rPalette = rStrm.GetRoot().GetPalette();
1959 
1960  if (mnPattern == EXC_PATT_NONE
1961  || (mnForeColor == 0 && mnBackColor == 0 && maForeColor == 0 && maBackColor == 0))
1962  {
1963  rStyleSheet->singleElement(XML_patternFill, XML_patternType, ToPatternType(mnPattern));
1964  }
1965  else
1966  {
1967  rStyleSheet->startElement(XML_patternFill, XML_patternType, ToPatternType(mnPattern));
1968  if (maForeColor != 0 || maBackColor != 0)
1969  {
1970  if (maForeColor != 0)
1971  {
1972  rStyleSheet->singleElement(XML_fgColor, XML_rgb,
1974  }
1975 
1976  if (maBackColor != 0)
1977  {
1978  rStyleSheet->singleElement(XML_bgColor, XML_rgb,
1980  }
1981  }
1982  else
1983  {
1984  if (mnForeColor != 0)
1985  {
1986  rStyleSheet->singleElement(XML_fgColor, XML_rgb,
1988  }
1989  if (mnBackColor != 0)
1990  {
1991  rStyleSheet->singleElement(XML_bgColor, XML_rgb,
1993  }
1994  }
1995 
1996  rStyleSheet->endElement( XML_patternFill );
1997  }
1998 
1999  rStyleSheet->endElement( XML_fill );
2000 }
2001 
2003 {
2004  if( !ScfTools::CheckItem( rItemSet, ATTR_BACKGROUND, true ) )
2005  return false;
2006 
2007  const SvxBrushItem& rBrushItem = rItemSet.Get( ATTR_BACKGROUND );
2008  maColor = rBrushItem.GetColor();
2009 
2010  return true;
2011 }
2012 
2014 {
2015  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
2016  rStyleSheet->startElement(XML_fill);
2017  rStyleSheet->startElement(XML_patternFill);
2018  rStyleSheet->singleElement(XML_bgColor, XML_rgb, XclXmlUtils::ToOString(maColor));
2019 
2020  rStyleSheet->endElement( XML_patternFill );
2021  rStyleSheet->endElement( XML_fill );
2022 }
2023 
2025  mnXFId( XclExpXFBuffer::GetDefCellXFId() ),
2026  mnXFIndex( EXC_XF_DEFAULTCELL )
2027 {
2028 }
2029 
2030 XclExpXFId::XclExpXFId( sal_uInt32 nXFId ) :
2031  mnXFId( nXFId ),
2032  mnXFIndex( EXC_XF_DEFAULTCELL )
2033 {
2034 }
2035 
2037 {
2038  mnXFIndex = rRoot.GetXFBuffer().GetXFIndex( mnXFId );
2039 }
2040 
2042  const XclExpRoot& rRoot, const ScPatternAttr& rPattern, sal_Int16 nScript,
2043  sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak ) :
2044  XclXFBase( true ),
2045  XclExpRoot( rRoot )
2046 {
2048  Init( rPattern.GetItemSet(), nScript, nForceScNumFmt, nForceXclFont, bForceLineBreak, false );
2049 }
2050 
2051 XclExpXF::XclExpXF( const XclExpRoot& rRoot, const SfxStyleSheetBase& rStyleSheet ) :
2052  XclXFBase( false ),
2053  XclExpRoot( rRoot ),
2054  mnParentXFId( XclExpXFBuffer::GetXFIdFromIndex( EXC_XF_STYLEPARENT ) )
2055 {
2056  bool bDefStyle = (rStyleSheet.GetName() == ScResId( STR_STYLENAME_STANDARD ));
2057  sal_Int16 nScript = bDefStyle ? GetDefApiScript() : css::i18n::ScriptType::WEAK;
2058  Init( const_cast< SfxStyleSheetBase& >( rStyleSheet ).GetItemSet(), nScript,
2059  NUMBERFORMAT_ENTRY_NOT_FOUND, EXC_FONT_NOTFOUND, false, bDefStyle );
2060 }
2061 
2062 XclExpXF::XclExpXF( const XclExpRoot& rRoot, bool bCellXF ) :
2063  XclXFBase( bCellXF ),
2064  XclExpRoot( rRoot ),
2065  mnParentXFId( XclExpXFBuffer::GetXFIdFromIndex( EXC_XF_STYLEPARENT ) )
2066 {
2067  InitDefault();
2068 }
2069 
2070 bool XclExpXF::Equals( const ScPatternAttr& rPattern,
2071  sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak ) const
2072 {
2073  return IsCellXF() && (mpItemSet == &rPattern.GetItemSet()) &&
2074  (!bForceLineBreak || maAlignment.mbLineBreak) &&
2075  ((nForceScNumFmt == NUMBERFORMAT_ENTRY_NOT_FOUND) || (mnScNumFmt == nForceScNumFmt)) &&
2076  ((nForceXclFont == EXC_FONT_NOTFOUND) || (mnXclFont == nForceXclFont));
2077 }
2078 
2079 bool XclExpXF::Equals( const SfxStyleSheetBase& rStyleSheet ) const
2080 {
2081  return IsStyleXF() && (mpItemSet == &const_cast< SfxStyleSheetBase& >( rStyleSheet ).GetItemSet());
2082 }
2083 
2085 {
2088 }
2089 
2090 bool XclExpXF::Equals( const XclExpXF& rCmpXF ) const
2091 {
2092  return XclXFBase::Equals( rCmpXF ) &&
2093  (maProtection == rCmpXF.maProtection) && (maAlignment == rCmpXF.maAlignment) &&
2094  (maBorder == rCmpXF.maBorder) && (maArea == rCmpXF.maArea) &&
2095  (mnXclFont == rCmpXF.mnXclFont) && (mnXclNumFmt == rCmpXF.mnXclNumFmt) &&
2096  (mnParentXFId == rCmpXF.mnParentXFId);
2097 }
2098 
2100 {
2101  SetRecHeader( EXC_ID5_XF, (GetBiff() == EXC_BIFF8) ? 20 : 16 );
2102  mpItemSet = nullptr;
2104  mnXclFont = mnXclNumFmt = 0;
2105  SetXmlIds(0, 0);
2106 }
2107 
2108 void XclExpXF::Init( const SfxItemSet& rItemSet, sal_Int16 nScript,
2109  sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak, bool bDefStyle )
2110 {
2111  InitDefault();
2112  mpItemSet = &rItemSet;
2113 
2114  // cell protection
2116 
2117  // font
2118  if( nForceXclFont == EXC_FONT_NOTFOUND )
2119  {
2120  mnXclFont = GetFontBuffer().Insert( rItemSet, nScript, EXC_COLOR_CELLTEXT, bDefStyle );
2121  mbFontUsed = XclExpFontHelper::CheckItems( GetRoot(), rItemSet, nScript, IsStyleXF() );
2122  }
2123  else
2124  {
2125  mnXclFont = nForceXclFont;
2126  mbFontUsed = true;
2127  }
2128 
2129  // number format
2130  if (nForceScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND)
2131  mnXclNumFmt = nForceScNumFmt;
2132  else
2133  {
2134  // Built-in formats of dedicated languages may be attributed using the
2135  // system language (or even other?) format with a language attribute,
2136  // obtain the "real" format key.
2137  mnScNumFmt = rItemSet.Get( ATTR_VALUE_FORMAT ).GetValue();
2138  LanguageType nLang = rItemSet.Get( ATTR_LANGUAGE_FORMAT).GetLanguage();
2141  }
2144 
2145  // alignment
2146  mbAlignUsed = maAlignment.FillFromItemSet(*this, rItemSet, bForceLineBreak, GetBiff(), IsStyleXF());
2147 
2148  // cell border
2150 
2151  // background area
2153 
2154  // set all b***Used flags to true in "Default"/"Normal" style
2155  if( bDefStyle )
2156  SetAllUsedFlags( true );
2157 }
2158 
2160 {
2161  sal_uInt8 nUsedFlags = 0;
2162  /* In cell XFs a set bit means a used attribute, in style XFs a cleared bit.
2163  "mbCellXF == mb***Used" evaluates to correct value in cell and style XFs. */
2164  ::set_flag( nUsedFlags, EXC_XF_DIFF_PROT, mbCellXF == mbProtUsed );
2165  ::set_flag( nUsedFlags, EXC_XF_DIFF_FONT, mbCellXF == mbFontUsed );
2166  ::set_flag( nUsedFlags, EXC_XF_DIFF_VALFMT, mbCellXF == mbFmtUsed );
2167  ::set_flag( nUsedFlags, EXC_XF_DIFF_ALIGN, mbCellXF == mbAlignUsed );
2169  ::set_flag( nUsedFlags, EXC_XF_DIFF_AREA, mbCellXF == mbAreaUsed );
2170  return nUsedFlags;
2171 }
2172 
2174 {
2175  sal_uInt16 nTypeProt = 0, nAlign = 0;
2176  sal_uInt32 nArea = 0, nBorder = 0;
2177 
2178  ::set_flag( nTypeProt, EXC_XF_STYLE, IsStyleXF() );
2179  ::insert_value( nTypeProt, mnParent, 4, 12 );
2180  ::insert_value( nAlign, GetUsedFlags(), 10, 6 );
2181 
2182  maProtection.FillToXF3( nTypeProt );
2183  maAlignment.FillToXF5( nAlign );
2184  maBorder.FillToXF5( nBorder, nArea );
2185  maArea.FillToXF5( nArea );
2186 
2187  rStrm << mnXclFont << mnXclNumFmt << nTypeProt << nAlign << nArea << nBorder;
2188 }
2189 
2191 {
2192  sal_uInt16 nTypeProt = 0, nAlign = 0, nMiscAttrib = 0, nArea = 0;
2193  sal_uInt32 nBorder1 = 0, nBorder2 = 0;
2194 
2195  ::set_flag( nTypeProt, EXC_XF_STYLE, IsStyleXF() );
2196  ::insert_value( nTypeProt, mnParent, 4, 12 );
2197  ::insert_value( nMiscAttrib, GetUsedFlags(), 10, 6 );
2198 
2199  maProtection.FillToXF3( nTypeProt );
2200  maAlignment.FillToXF8( nAlign, nMiscAttrib );
2201  maBorder.FillToXF8( nBorder1, nBorder2 );
2202  maArea.FillToXF8( nBorder2, nArea );
2203 
2204  rStrm << mnXclFont << mnXclNumFmt << nTypeProt << nAlign << nMiscAttrib << nBorder1 << nBorder2 << nArea;
2205 }
2206 
2208 {
2209  XclExpXFId aParentId( mnParentXFId );
2210  aParentId.ConvertXFIndex( GetRoot() );
2211  mnParent = aParentId.mnXFIndex;
2212  switch( GetBiff() )
2213  {
2214  case EXC_BIFF5: WriteBody5( rStrm ); break;
2215  case EXC_BIFF8: WriteBody8( rStrm ); break;
2216  default: DBG_ERROR_BIFF();
2217  }
2218 }
2219 
2220 void XclExpXF::SetXmlIds( sal_uInt32 nBorderId, sal_uInt32 nFillId )
2221 {
2222  mnBorderId = nBorderId;
2223  mnFillId = nFillId;
2224 }
2225 
2227 {
2228  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
2229 
2230  sal_Int32 nXfId = 0;
2231  const XclExpXF* pStyleXF = nullptr;
2232  if( IsCellXF() )
2233  {
2234  sal_uInt16 nXFIndex = rStrm.GetRoot().GetXFBuffer().GetXFIndex( mnParentXFId );
2235  nXfId = rStrm.GetRoot().GetXFBuffer().GetXmlStyleIndex( nXFIndex );
2236  pStyleXF = rStrm.GetRoot().GetXFBuffer().GetXFById( mnParentXFId );
2237  }
2238 
2239  rStyleSheet->startElement( XML_xf,
2240  XML_numFmtId, OString::number(mnXclNumFmt),
2241  XML_fontId, OString::number(mnXclFont),
2242  XML_fillId, OString::number(mnFillId),
2243  XML_borderId, OString::number(mnBorderId),
2244  XML_xfId, sax_fastparser::UseIf(OString::number(nXfId), !IsStyleXF()),
2245  // OOXTODO: XML_quotePrefix,
2246  // OOXTODO: XML_pivotButton,
2247  // OOXTODO: XML_applyNumberFormat, ;
2248  XML_applyFont, ToPsz( mbFontUsed ),
2249  // OOXTODO: XML_applyFill,
2250  XML_applyBorder, ToPsz( mbBorderUsed ),
2251  XML_applyAlignment, ToPsz( mbAlignUsed ),
2252  XML_applyProtection, ToPsz( mbProtUsed ) );
2253  if( mbAlignUsed )
2254  maAlignment.SaveXml( rStrm );
2255  else if ( pStyleXF )
2256  pStyleXF->GetAlignmentData().SaveXml( rStrm );
2257  if( mbProtUsed )
2258  maProtection.SaveXml( rStrm );
2259  else if ( pStyleXF )
2260  pStyleXF->GetProtectionData().SaveXml( rStrm );
2261 
2262  // OOXTODO: XML_extLst
2263  rStyleSheet->endElement( XML_xf );
2264 }
2265 
2266 XclExpDefaultXF::XclExpDefaultXF( const XclExpRoot& rRoot, bool bCellXF ) :
2267  XclExpXF( rRoot, bCellXF )
2268 {
2269 }
2270 
2271 void XclExpDefaultXF::SetFont( sal_uInt16 nXclFont )
2272 {
2273  mnXclFont = nXclFont;
2274  mbFontUsed = true;
2275 }
2276 
2277 void XclExpDefaultXF::SetNumFmt( sal_uInt16 nXclNumFmt )
2278 {
2279  mnXclNumFmt = nXclNumFmt;
2280  mbFmtUsed = true;
2281 }
2282 
2283 XclExpStyle::XclExpStyle( sal_uInt32 nXFId, const OUString& rStyleName ) :
2284  XclExpRecord( EXC_ID_STYLE, 4 ),
2285  maName( rStyleName ),
2286  maXFId( nXFId ),
2287  mnStyleId( EXC_STYLE_USERDEF ),
2289 {
2290  OSL_ENSURE( !maName.isEmpty(), "XclExpStyle::XclExpStyle - empty style name" );
2291 #if OSL_DEBUG_LEVEL > 0
2292  sal_uInt8 nStyleId, nLevel; // do not use members for debug tests
2293  OSL_ENSURE( !XclTools::GetBuiltInStyleId( nStyleId, nLevel, maName ),
2294  "XclExpStyle::XclExpStyle - this is a built-in style" );
2295 #endif
2296 }
2297 
2298 XclExpStyle::XclExpStyle( sal_uInt32 nXFId, sal_uInt8 nStyleId, sal_uInt8 nLevel ) :
2299  XclExpRecord( EXC_ID_STYLE, 4 ),
2300  maXFId( nXFId ),
2301  mnStyleId( nStyleId ),
2302  mnLevel( nLevel )
2303 {
2304 }
2305 
2307 {
2308  maXFId.ConvertXFIndex( rStrm.GetRoot() );
2310  rStrm << maXFId.mnXFIndex;
2311 
2312  if( IsBuiltIn() )
2313  {
2314  rStrm << mnStyleId << mnLevel;
2315  }
2316  else
2317  {
2318  XclExpString aNameEx;
2319  if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
2320  aNameEx.Assign( maName );
2321  else
2323  rStrm << aNameEx;
2324  }
2325 }
2326 
2327 static const char* lcl_StyleNameFromId( sal_Int32 nStyleId )
2328 {
2329  switch( nStyleId )
2330  {
2331  case 0: return "Normal";
2332  case 3: return "Comma";
2333  case 4: return "Currency";
2334  case 5: return "Percent";
2335  case 6: return "Comma [0]";
2336  case 7: return "Currency [0]";
2337  }
2338  return "*unknown*";
2339 }
2340 
2342 {
2343  constexpr sal_Int32 CELL_STYLE_MAX_BUILTIN_ID = 54;
2344  OString sName;
2345  OString sBuiltinId;
2346  const char* pBuiltinId = nullptr;
2347  if( IsBuiltIn() )
2348  {
2349  sName = OString( lcl_StyleNameFromId( mnStyleId ) );
2350  sBuiltinId = OString::number( std::min( static_cast<sal_Int32>( CELL_STYLE_MAX_BUILTIN_ID - 1 ), static_cast <sal_Int32>( mnStyleId ) ) );
2351  pBuiltinId = sBuiltinId.getStr();
2352  }
2353  else
2354  sName = maName.toUtf8();
2355 
2356  // get the index in sortedlist associated with the mnXId
2357  sal_Int32 nXFId = rStrm.GetRoot().GetXFBuffer().GetXFIndex( maXFId.mnXFId );
2358  // get the style index associated with index into sortedlist
2359  nXFId = rStrm.GetRoot().GetXFBuffer().GetXmlStyleIndex( nXFId );
2360  rStrm.GetCurrentStream()->singleElement( XML_cellStyle,
2361  XML_name, sName,
2362  XML_xfId, OString::number(nXFId),
2363 // builtinId of 54 or above is invalid according to OpenXML SDK validator.
2364  XML_builtinId, pBuiltinId
2365  // OOXTODO: XML_iLevel,
2366  // OOXTODO: XML_hidden,
2367  // XML_customBuiltin, ToPsz( ! IsBuiltIn() )
2368  );
2369  // OOXTODO: XML_extLst
2370 }
2371 
2372 namespace {
2373 
2374 const sal_uInt32 EXC_XFLIST_INDEXBASE = 0xFFFE0000;
2376 const sal_uInt32 EXC_XFLIST_HARDLIMIT = 256 * 1024;
2377 
2378 bool lclIsBuiltInStyle( const OUString& rStyleName )
2379 {
2380  return
2381  XclTools::IsBuiltInStyleName( rStyleName ) ||
2382  XclTools::IsCondFormatStyleName( rStyleName );
2383 }
2384 
2385 } // namespace
2386 
2388  mnStyleId( EXC_STYLE_USERDEF ),
2390  mbPredefined( true ),
2391  mbHasStyleRec( false )
2392 {
2393 }
2394 
2395 namespace {
2396 
2398 struct XclExpBorderPred
2399 {
2400  const XclExpCellBorder&
2401  mrBorder;
2402  explicit XclExpBorderPred( const XclExpCellBorder& rBorder ) : mrBorder( rBorder ) {}
2403  bool operator()( const XclExpCellBorder& rBorder ) const;
2404 };
2405 
2406 }
2407 
2408 bool XclExpBorderPred::operator()( const XclExpCellBorder& rBorder ) const
2409 {
2410  return
2411  mrBorder.mnLeftColor == rBorder.mnLeftColor &&
2412  mrBorder.mnRightColor == rBorder.mnRightColor &&
2413  mrBorder.mnTopColor == rBorder.mnTopColor &&
2414  mrBorder.mnBottomColor == rBorder.mnBottomColor &&
2415  mrBorder.mnDiagColor == rBorder.mnDiagColor &&
2416  mrBorder.mnLeftLine == rBorder.mnLeftLine &&
2417  mrBorder.mnRightLine == rBorder.mnRightLine &&
2418  mrBorder.mnTopLine == rBorder.mnTopLine &&
2419  mrBorder.mnBottomLine == rBorder.mnBottomLine &&
2420  mrBorder.mnDiagLine == rBorder.mnDiagLine &&
2421  mrBorder.mbDiagTLtoBR == rBorder.mbDiagTLtoBR &&
2422  mrBorder.mbDiagBLtoTR == rBorder.mbDiagBLtoTR &&
2423  mrBorder.mnLeftColorId == rBorder.mnLeftColorId &&
2424  mrBorder.mnRightColorId == rBorder.mnRightColorId &&
2425  mrBorder.mnTopColorId == rBorder.mnTopColorId &&
2426  mrBorder.mnBottomColorId == rBorder.mnBottomColorId &&
2427  mrBorder.mnDiagColorId == rBorder.mnDiagColorId;
2428 }
2429 
2430 namespace {
2431 
2432 struct XclExpFillPred
2433 {
2434  const XclExpCellArea&
2435  mrFill;
2436  explicit XclExpFillPred( const XclExpCellArea& rFill ) : mrFill( rFill ) {}
2437  bool operator()( const XclExpCellArea& rFill ) const;
2438 };
2439 
2440 }
2441 
2442 bool XclExpFillPred::operator()( const XclExpCellArea& rFill ) const
2443 {
2444  return
2445  mrFill.mnForeColor == rFill.mnForeColor &&
2446  mrFill.mnBackColor == rFill.mnBackColor &&
2447  mrFill.mnPattern == rFill.mnPattern &&
2448  mrFill.mnForeColorId == rFill.mnForeColorId &&
2449  mrFill.mnBackColorId == rFill.mnBackColorId;
2450 }
2451 
2453  XclExpRoot( rRoot )
2454 {
2455 }
2456 
2458 {
2460  InsertUserStyles();
2461 }
2462 
2463 sal_uInt32 XclExpXFBuffer::Insert( const ScPatternAttr* pPattern, sal_Int16 nScript )
2464 {
2465  return InsertCellXF( pPattern, nScript, NUMBERFORMAT_ENTRY_NOT_FOUND, EXC_FONT_NOTFOUND, false );
2466 }
2467 
2468 sal_uInt32 XclExpXFBuffer::InsertWithFont( const ScPatternAttr* pPattern, sal_Int16 nScript,
2469  sal_uInt16 nForceXclFont, bool bForceLineBreak )
2470 {
2471  return InsertCellXF( pPattern, nScript, NUMBERFORMAT_ENTRY_NOT_FOUND, nForceXclFont, bForceLineBreak );
2472 }
2473 
2474 sal_uInt32 XclExpXFBuffer::InsertWithNumFmt( const ScPatternAttr* pPattern, sal_Int16 nScript, sal_uInt32 nForceScNumFmt, bool bForceLineBreak )
2475 {
2476  return InsertCellXF( pPattern, nScript, nForceScNumFmt, EXC_FONT_NOTFOUND, bForceLineBreak );
2477 }
2478 
2479 sal_uInt32 XclExpXFBuffer::InsertStyle( const SfxStyleSheetBase* pStyleSheet )
2480 {
2481  return pStyleSheet ? InsertStyleXF( *pStyleSheet ) : GetXFIdFromIndex( EXC_XF_DEFAULTSTYLE );
2482 }
2483 
2484 sal_uInt32 XclExpXFBuffer::GetXFIdFromIndex( sal_uInt16 nXFIndex )
2485 {
2486  return EXC_XFLIST_INDEXBASE | nXFIndex;
2487 }
2488 
2490 {
2492 }
2493 
2494 const XclExpXF* XclExpXFBuffer::GetXFById( sal_uInt32 nXFId ) const
2495 {
2496  return maXFList.GetRecord( nXFId );
2497 }
2498 
2500 {
2501  for( size_t nPos = 0, nSize = maXFList.GetSize(); nPos < nSize; ++nPos )
2503 
2504  sal_uInt32 nTotalCount = static_cast< sal_uInt32 >( maXFList.GetSize() );
2505  sal_uInt32 nId;
2506  maXFIndexVec.resize( nTotalCount, EXC_XF_DEFAULTCELL );
2507  maStyleIndexes.resize( nTotalCount, EXC_XF_DEFAULTCELL );
2508  maCellIndexes.resize( nTotalCount, EXC_XF_DEFAULTCELL );
2509 
2510  XclExpBuiltInMap::const_iterator aBuiltInEnd = maBuiltInMap.end();
2511  /* nMaxBuiltInXFId used to decide faster whether an XF record is
2512  user-defined. If the current XF ID is greater than this value,
2513  maBuiltInMap doesn't need to be searched. */
2514  sal_uInt32 nMaxBuiltInXFId = maBuiltInMap.empty() ? 0 : maBuiltInMap.rbegin()->first;
2515 
2516  // *** map all built-in XF records (cell and style) *** -------------------
2517 
2518  // do not change XF order -> std::map<> iterates elements in ascending order
2519  for( const auto& rEntry : maBuiltInMap )
2520  AppendXFIndex( rEntry.first );
2521 
2522  // *** insert all user-defined style XF records, without reduce *** -------
2523 
2524  sal_uInt32 nStyleXFCount = 0; // counts up to EXC_XF_MAXSTYLECOUNT limit
2525 
2526  for( nId = 0; nId < nTotalCount; ++nId )
2527  {
2528  XclExpXFRef xXF = maXFList.GetRecord( nId );
2529  if( xXF->IsStyleXF() && ((nId > nMaxBuiltInXFId) || (maBuiltInMap.find( nId ) == aBuiltInEnd)) )
2530  {
2531  if( nStyleXFCount < EXC_XF_MAXSTYLECOUNT )
2532  {
2533  // maximum count of styles not reached
2534  AppendXFIndex( nId );
2535  ++nStyleXFCount;
2536  }
2537  else
2538  {
2539  /* Maximum count of styles reached - do not append more
2540  pointers to XFs; use default style XF instead; do not break
2541  the loop to initialize all maXFIndexVec elements. */
2543  }
2544  }
2545  }
2546 
2547  // *** insert all cell XF records *** -------------------------------------
2548 
2549  // start position to search for equal inserted XF records
2550  size_t nSearchStart = maSortedXFList.GetSize();
2551 
2552  // break the loop if XF limit reached - maXFIndexVec is already initialized with default index
2554  for( nId = 0; (nId < nTotalCount) && (maSortedXFList.GetSize() < EXC_XF_MAXCOUNT); ++nId )
2555  {
2556  XclExpXFRef xXF = maXFList.GetRecord( nId );
2557  if( xXF->IsCellXF() && ((nId > nMaxBuiltInXFId) || (maBuiltInMap.find( nId ) == aBuiltInEnd)) )
2558  {
2559  // try to find an XF record equal to *xXF, which is already inserted
2560  sal_uInt16 nFoundIndex = EXC_XF_NOTFOUND;
2561 
2562  // first try if it is equal to the default cell XF
2563  if( xDefCellXF->Equals( *xXF ) )
2564  {
2565  nFoundIndex = EXC_XF_DEFAULTCELL;
2566  }
2567  else for( size_t nSearchPos = nSearchStart, nSearchEnd = maSortedXFList.GetSize();
2568  (nSearchPos < nSearchEnd) && (nFoundIndex == EXC_XF_NOTFOUND); ++nSearchPos )
2569  {
2570  if( maSortedXFList.GetRecord( nSearchPos )->Equals( *xXF ) )
2571  nFoundIndex = static_cast< sal_uInt16 >( nSearchPos );
2572  }
2573 
2574  if( nFoundIndex != EXC_XF_NOTFOUND )
2575  // equal XF already in the list, use its resulting XF index
2576  maXFIndexVec[ nId ] = nFoundIndex;
2577  else
2578  AppendXFIndex( nId );
2579  }
2580  }
2581 
2582  sal_uInt16 nXmlStyleIndex = 0;
2583  sal_uInt16 nXmlCellIndex = 0;
2584 
2585  size_t nXFCount = maSortedXFList.GetSize();
2586  for( size_t i = 0; i < nXFCount; ++i )
2587  {
2589  if( xXF->IsStyleXF() )
2590  maStyleIndexes[ i ] = nXmlStyleIndex++;
2591  else
2592  maCellIndexes[ i ] = nXmlCellIndex++;
2593  }
2594 }
2595 
2596 sal_uInt16 XclExpXFBuffer::GetXFIndex( sal_uInt32 nXFId ) const
2597 {
2598  sal_uInt16 nXFIndex = EXC_XF_DEFAULTSTYLE;
2599  if( nXFId >= EXC_XFLIST_INDEXBASE )
2600  nXFIndex = static_cast< sal_uInt16 >( nXFId & ~EXC_XFLIST_INDEXBASE );
2601  else if( nXFId < maXFIndexVec.size() )
2602  nXFIndex = maXFIndexVec[ nXFId ];
2603  return nXFIndex;
2604 }
2605 
2606 sal_Int32 XclExpXFBuffer::GetXmlStyleIndex( sal_uInt32 nXFIndex ) const
2607 {
2608  OSL_ENSURE( nXFIndex < maStyleIndexes.size(), "XclExpXFBuffer::GetXmlStyleIndex - invalid index!" );
2609  if( nXFIndex >= maStyleIndexes.size() )
2610  return 0; // should be caught/debugged via above assert; return "valid" index.
2611  return maStyleIndexes[ nXFIndex ];
2612 }
2613 
2614 sal_Int32 XclExpXFBuffer::GetXmlCellIndex( sal_uInt32 nXFIndex ) const
2615 {
2616  OSL_ENSURE( nXFIndex < maCellIndexes.size(), "XclExpXFBuffer::GetXmlStyleIndex - invalid index!" );
2617  if( nXFIndex >= maCellIndexes.size() )
2618  return 0; // should be caught/debugged via above assert; return "valid" index.
2619  return maCellIndexes[ nXFIndex ];
2620 }
2621 
2623 {
2624  // save all XF records contained in the maSortedXFList vector (sorted by XF index)
2625  maSortedXFList.Save( rStrm );
2626  // save all STYLE records
2627  maStyleList.Save( rStrm );
2628 }
2629 
2630 static void lcl_GetCellCounts( const XclExpRecordList< XclExpXF >& rXFList, sal_Int32& rCells, sal_Int32& rStyles )
2631 {
2632  rCells = 0;
2633  rStyles = 0;
2634  size_t nXFCount = rXFList.GetSize();
2635  for( size_t i = 0; i < nXFCount; ++i )
2636  {
2638  if( xXF->IsCellXF() )
2639  ++rCells;
2640  else if( xXF->IsStyleXF() )
2641  ++rStyles;
2642  }
2643 }
2644 
2646 {
2647  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
2648 
2649  rStyleSheet->startElement(XML_fills, XML_count, OString::number(maFills.size()));
2650  for( const auto& rFill : maFills )
2651  {
2652  rFill.SaveXml( rStrm );
2653  }
2654  rStyleSheet->endElement( XML_fills );
2655 
2656  rStyleSheet->startElement(XML_borders, XML_count, OString::number(maBorders.size()));
2657  for( const auto& rBorder : maBorders )
2658  {
2659  rBorder.SaveXml( rStrm );
2660  }
2661  rStyleSheet->endElement( XML_borders );
2662 
2663  // save all XF records contained in the maSortedXFList vector (sorted by XF index)
2664  sal_Int32 nCells, nStyles;
2665  lcl_GetCellCounts( maSortedXFList, nCells, nStyles );
2666 
2667  if( nStyles > 0 )
2668  {
2669  rStyleSheet->startElement(XML_cellStyleXfs, XML_count, OString::number(nStyles));
2670  size_t nXFCount = maSortedXFList.GetSize();
2671  for( size_t i = 0; i < nXFCount; ++i )
2672  {
2674  if( ! xXF->IsStyleXF() )
2675  continue;
2676  SaveXFXml( rStrm, *xXF );
2677  }
2678  rStyleSheet->endElement( XML_cellStyleXfs );
2679  }
2680 
2681  if( nCells > 0 )
2682  {
2683  rStyleSheet->startElement(XML_cellXfs, XML_count, OString::number(nCells));
2684  size_t nXFCount = maSortedXFList.GetSize();
2685  for( size_t i = 0; i < nXFCount; ++i )
2686  {
2688  if( ! xXF->IsCellXF() )
2689  continue;
2690  SaveXFXml( rStrm, *xXF );
2691  }
2692  rStyleSheet->endElement( XML_cellXfs );
2693  }
2694 
2695  // save all STYLE records
2696  rStyleSheet->startElement(XML_cellStyles, XML_count, OString::number(maStyleList.GetSize()));
2697  maStyleList.SaveXml( rStrm );
2698  rStyleSheet->endElement( XML_cellStyles );
2699 }
2700 
2702 {
2703  XclExpBorderList::iterator aBorderPos =
2704  std::find_if( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) );
2705  OSL_ENSURE( aBorderPos != maBorders.end(), "XclExpXFBuffer::SaveXml - Invalid @borderId!" );
2706  XclExpFillList::iterator aFillPos =
2707  std::find_if( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) );
2708  OSL_ENSURE( aFillPos != maFills.end(), "XclExpXFBuffer::SaveXml - Invalid @fillId!" );
2709 
2710  sal_Int32 nBorderId = 0, nFillId = 0;
2711  if( aBorderPos != maBorders.end() )
2712  nBorderId = std::distance( maBorders.begin(), aBorderPos );
2713  if( aFillPos != maFills.end() )
2714  nFillId = std::distance( maFills.begin(), aFillPos );
2715 
2716  rXF.SetXmlIds( nBorderId, nFillId );
2717  rXF.SaveXml( rStrm );
2718 }
2719 
2720 sal_uInt32 XclExpXFBuffer::FindXF( const ScPatternAttr& rPattern,
2721  sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak ) const
2722 {
2723  if (nForceScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND && nForceXclFont == EXC_FONT_NOTFOUND)
2724  {
2725  FindKey key1 { /*mbCellXF*/true, &rPattern.GetItemSet(), nForceScNumFmt, 0 };
2726  FindKey key2 { /*mbCellXF*/true, &rPattern.GetItemSet(), nForceScNumFmt, EXC_FONT_NOTFOUND };
2727  auto it1 = maXFFindMap.lower_bound(key1);
2728  if (it1 != maXFFindMap.end())
2729  {
2730  auto it2 = maXFFindMap.upper_bound(key2);
2731  for (auto it = it1; it != it2; ++it)
2732  for (auto const & nPos : it->second)
2733  if( maXFList.GetRecord( nPos )->Equals( rPattern, nForceScNumFmt, nForceXclFont, bForceLineBreak ) )
2734  return nPos;
2735  }
2736  }
2737  else if (nForceScNumFmt == NUMBERFORMAT_ENTRY_NOT_FOUND || nForceXclFont == EXC_FONT_NOTFOUND)
2738  {
2739  FindKey key1 { /*mbCellXF*/true, &rPattern.GetItemSet(), 0, 0 };
2740  FindKey key2 { /*mbCellXF*/true, &rPattern.GetItemSet(), NUMBERFORMAT_ENTRY_NOT_FOUND, EXC_FONT_NOTFOUND };
2741  auto it1 = maXFFindMap.lower_bound(key1);
2742  if (it1 != maXFFindMap.end())
2743  {
2744  auto it2 = maXFFindMap.upper_bound(key2);
2745  for (auto it = it1; it != it2; ++it)
2746  for (auto const & nPos : it->second)
2747  if( maXFList.GetRecord( nPos )->Equals( rPattern, nForceScNumFmt, nForceXclFont, bForceLineBreak ) )
2748  return nPos;
2749  }
2750  }
2751  else
2752  {
2753  FindKey key { /*mbCellXF*/true, &rPattern.GetItemSet(), nForceScNumFmt, nForceXclFont };
2754  auto it = maXFFindMap.find(key);
2755  if (it == maXFFindMap.end())
2756  return EXC_XFID_NOTFOUND;
2757  for (auto const & nPos : it->second)
2758  if( maXFList.GetRecord( nPos )->Equals( rPattern, nForceScNumFmt, nForceXclFont, bForceLineBreak ) )
2759  return nPos;
2760  }
2761  return EXC_XFID_NOTFOUND;
2762 }
2763 
2764 sal_uInt32 XclExpXFBuffer::FindXF( const SfxStyleSheetBase& rStyleSheet ) const
2765 {
2766  const SfxItemSet* pItemSet = &const_cast< SfxStyleSheetBase& >( rStyleSheet ).GetItemSet();
2767  FindKey key1 { /*mbCellXF*/false, pItemSet, 0, 0 };
2768  FindKey key2 { /*mbCellXF*/false, pItemSet, NUMBERFORMAT_ENTRY_NOT_FOUND, EXC_FONT_NOTFOUND };
2769  auto it1 = maXFFindMap.lower_bound(key1);
2770  auto it2 = maXFFindMap.upper_bound(key2);
2771  for (auto it = it1; it != it2; ++it)
2772  for (auto const & nPos : it->second)
2773  if( maXFList.GetRecord( nPos )->Equals( rStyleSheet ) )
2774  return nPos;
2775  return EXC_XFID_NOTFOUND;
2776 }
2777 
2778 sal_uInt32 XclExpXFBuffer::FindBuiltInXF( sal_uInt8 nStyleId, sal_uInt8 nLevel ) const
2779 {
2780  auto aIt = std::find_if(maBuiltInMap.begin(), maBuiltInMap.end(),
2781  [&nStyleId, nLevel](const XclExpBuiltInMap::value_type& rEntry) {
2782  return (rEntry.second.mnStyleId == nStyleId) && (rEntry.second.mnLevel == nLevel);
2783  });
2784  if (aIt != maBuiltInMap.end())
2785  return aIt->first;
2786  return EXC_XFID_NOTFOUND;
2787 }
2788 
2790 {
2791  return { rRec.IsCellXF(), rRec.GetItemSet(), rRec.GetScNumFmt(), rRec.GetXclFont() };
2792 }
2793 
2794 sal_uInt32 XclExpXFBuffer::InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript,
2795  sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak )
2796 {
2797  const ScPatternAttr* pDefPattern = GetDoc().GetDefPattern();
2798  if( !pPattern )
2799  pPattern = pDefPattern;
2800 
2801  // special handling for default cell formatting
2802  if( (pPattern == pDefPattern) && !bForceLineBreak &&
2803  (nForceScNumFmt == NUMBERFORMAT_ENTRY_NOT_FOUND) &&
2804  (nForceXclFont == EXC_FONT_NOTFOUND) )
2805  {
2806  // Is it the first try to insert the default cell format?
2807  bool& rbPredefined = maBuiltInMap[ EXC_XF_DEFAULTCELL ].mbPredefined;
2808  if( rbPredefined )
2809  {
2810  // remove old entry in find-map
2811  auto & rPositions = maXFFindMap[ToFindKey(*maXFList.GetRecord(EXC_XF_DEFAULTCELL))];
2812  auto it = std::find(rPositions.begin(), rPositions.end(), EXC_XF_DEFAULTCELL);
2813  rPositions.erase(it);
2814  // replace default cell pattern
2815  XclExpXFRef xNewXF = new XclExpXF( GetRoot(), *pPattern, nScript );
2817  // and add new entry in find-map
2818  maXFFindMap[ToFindKey(*xNewXF)].push_back(EXC_XF_DEFAULTCELL);
2819  rbPredefined = false;
2820  }
2821  return GetDefCellXFId();
2822  }
2823 
2824  sal_uInt32 nXFId = FindXF( *pPattern, nForceScNumFmt, nForceXclFont, bForceLineBreak );
2825  if( nXFId == EXC_XFID_NOTFOUND )
2826  {
2827  // not found - insert new cell XF
2828  if( maXFList.GetSize() < EXC_XFLIST_HARDLIMIT )
2829  {
2830  auto pNewExp = new XclExpXF(
2831  GetRoot(), *pPattern, nScript, nForceScNumFmt, nForceXclFont, bForceLineBreak );
2832  maXFList.AppendNewRecord( pNewExp );
2833  // do not set nXFId before the AppendNewRecord() call - it may insert 2 XFs (style+cell)
2834  nXFId = static_cast< sal_uInt32 >( maXFList.GetSize() - 1 );
2835  maXFFindMap[ToFindKey(*pNewExp)].push_back(nXFId);
2836  }
2837  else
2838  {
2839  // list full - fall back to default cell XF
2840  nXFId = GetDefCellXFId();
2841  }
2842  }
2843  return nXFId;
2844 }
2845 
2846 sal_uInt32 XclExpXFBuffer::InsertStyleXF( const SfxStyleSheetBase& rStyleSheet )
2847 {
2848  // *** try, if it is a built-in style - create new XF or replace existing predefined XF ***
2849 
2850  sal_uInt8 nStyleId, nLevel;
2851  if( XclTools::GetBuiltInStyleId( nStyleId, nLevel, rStyleSheet.GetName() ) )
2852  {
2853  // try to find the built-in XF record (if already created in InsertDefaultRecords())
2854  sal_uInt32 nXFId = FindBuiltInXF( nStyleId, nLevel );
2855  if( nXFId == EXC_XFID_NOTFOUND )
2856  {
2857  // built-in style XF not yet created - do it now
2858  XclExpXFRef xXF = new XclExpXF( GetRoot(), rStyleSheet );
2859  nXFId = AppendBuiltInXFWithStyle( xXF, nStyleId, nLevel );
2860  // this new XF record is not predefined
2861  maBuiltInMap[ nXFId ].mbPredefined = false;
2862  }
2863  else
2864  {
2865  OSL_ENSURE( maXFList.HasRecord( nXFId ), "XclExpXFBuffer::InsertStyleXF - built-in XF not found" );
2866  // XF record still predefined? -> Replace with real XF
2867  bool& rbPredefined = maBuiltInMap[ nXFId ].mbPredefined;
2868  if( rbPredefined )
2869  {
2870  // remove old entry in find-map
2871  auto & rPositions = maXFFindMap[ToFindKey(*maXFList.GetRecord(nXFId))];
2872  auto it = std::find(rPositions.begin(), rPositions.end(), nXFId);
2873  rPositions.erase(it);
2874  // replace predefined built-in style (ReplaceRecord() deletes old record)
2875  XclExpXFRef pNewExp = new XclExpXF( GetRoot(), rStyleSheet );
2876  maXFList.ReplaceRecord( pNewExp, nXFId );
2877  // and add new entry in find-map
2878  maXFFindMap[ToFindKey(*pNewExp)].push_back(nXFId);
2879  rbPredefined = false;
2880  }
2881  }
2882 
2883  // STYLE already inserted? (may be not, i.e. for RowLevel/ColLevel or Hyperlink styles)
2884  bool& rbHasStyleRec = maBuiltInMap[ nXFId ].mbHasStyleRec;
2885  if( !rbHasStyleRec )
2886  {
2887  maStyleList.AppendNewRecord( new XclExpStyle( nXFId, nStyleId, nLevel ) );
2888  rbHasStyleRec = true;
2889  }
2890 
2891  return nXFId;
2892  }
2893 
2894  // *** try to find the XF record of a user-defined style ***
2895 
2896  sal_uInt32 nXFId = FindXF( rStyleSheet );
2897  if( nXFId == EXC_XFID_NOTFOUND )
2898  {
2899  // not found - insert new style XF and STYLE
2900  nXFId = static_cast< sal_uInt32 >( maXFList.GetSize() );
2901  if( nXFId < EXC_XFLIST_HARDLIMIT )
2902  {
2903  auto pNewExp = new XclExpXF( GetRoot(), rStyleSheet );
2904  maXFList.AppendNewRecord( pNewExp );
2905  // create the STYLE record
2906  if( !rStyleSheet.GetName().isEmpty() )
2907  maStyleList.AppendNewRecord( new XclExpStyle( nXFId, rStyleSheet.GetName() ) );
2908  maXFFindMap[ToFindKey(*pNewExp)].push_back(nXFId);
2909  }
2910  else
2911  // list full - fall back to default style XF
2913  }
2914  return nXFId;
2915 }
2916 
2918 {
2919  SfxStyleSheetIterator aStyleIter( GetDoc().GetStyleSheetPool(), SfxStyleFamily::Para );
2920  for( SfxStyleSheetBase* pStyleSheet = aStyleIter.First(); pStyleSheet; pStyleSheet = aStyleIter.Next() )
2921  if( pStyleSheet->IsUserDefined() && !lclIsBuiltInStyle( pStyleSheet->GetName() ) )
2922  InsertStyleXF( *pStyleSheet );
2923 }
2924 
2925 sal_uInt32 XclExpXFBuffer::AppendBuiltInXF( XclExpXFRef const & xXF, sal_uInt8 nStyleId, sal_uInt8 nLevel )
2926 {
2927  sal_uInt32 nXFId = static_cast< sal_uInt32 >( maXFList.GetSize() );
2928  maXFList.AppendRecord( xXF );
2929  maXFFindMap[ToFindKey(*xXF)].push_back(nXFId);
2930  XclExpBuiltInInfo& rInfo = maBuiltInMap[ nXFId ];
2931  rInfo.mnStyleId = nStyleId;
2932  rInfo.mnLevel = nLevel;
2933  rInfo.mbPredefined = true;
2934  return nXFId;
2935 }
2936 
2938 {
2939  sal_uInt32 nXFId = AppendBuiltInXF( xXF, nStyleId, nLevel );
2940  maStyleList.AppendNewRecord( new XclExpStyle( nXFId, nStyleId, nLevel ) );
2941  maBuiltInMap[ nXFId ].mbHasStyleRec = true; // mark existing STYLE record
2942  return nXFId;
2943 }
2944 
2946 {
2947  XclExpCellArea aFill;
2948  aFill.mnPattern = EXC_PATT_NONE;
2949  return aFill;
2950 }
2951 
2953 {
2954  XclExpCellArea aFill;
2955  aFill.mnPattern = EXC_PATT_12_5_PERC;
2956  aFill.mnForeColor = 0;
2957  aFill.mnBackColor = 0;
2958  return aFill;
2959 }
2960 
2962 {
2963  maFills.push_back( lcl_GetPatternFill_None() );
2964  maFills.push_back( lcl_GetPatternFill_Gray125() );
2965 
2966  // index 0: default style
2967  if( SfxStyleSheetBase* pDefStyleSheet = GetStyleSheetPool().Find( ScResId( STR_STYLENAME_STANDARD ), SfxStyleFamily::Para ) )
2968  {
2969  XclExpXFRef xDefStyle = new XclExpXF( GetRoot(), *pDefStyleSheet );
2970  sal_uInt32 nXFId = AppendBuiltInXFWithStyle( xDefStyle, EXC_STYLE_NORMAL );
2971  // mark this XF as not predefined, prevents overwriting
2972  maBuiltInMap[ nXFId ].mbPredefined = false;
2973  }
2974  else
2975  {
2976  OSL_FAIL( "XclExpXFBuffer::InsertDefaultRecords - default style not found" );
2977  XclExpXFRef xDefStyle = new XclExpDefaultXF( GetRoot(), false );
2978  xDefStyle->SetAllUsedFlags( true );
2980  }
2981 
2982  // index 1-14: RowLevel and ColLevel styles (without STYLE records)
2983  XclExpDefaultXF aLevelStyle( GetRoot(), false );
2984  // RowLevel_1, ColLevel_1
2985  aLevelStyle.SetFont( 1 );
2986  AppendBuiltInXF( new XclExpDefaultXF( aLevelStyle ), EXC_STYLE_ROWLEVEL, 0 );
2987  AppendBuiltInXF( new XclExpDefaultXF( aLevelStyle ), EXC_STYLE_COLLEVEL, 0 );
2988  // RowLevel_2, ColLevel_2
2989  aLevelStyle.SetFont( 2 );
2990  AppendBuiltInXF( new XclExpDefaultXF( aLevelStyle ), EXC_STYLE_ROWLEVEL, 1 );
2991  AppendBuiltInXF( new XclExpDefaultXF( aLevelStyle ), EXC_STYLE_COLLEVEL, 1 );
2992  // RowLevel_3, ColLevel_3 ... RowLevel_7, ColLevel_7
2993  aLevelStyle.SetFont( 0 );
2994  for( sal_uInt8 nLevel = 2; nLevel < EXC_STYLE_LEVELCOUNT; ++nLevel )
2995  {
2996  AppendBuiltInXF( new XclExpDefaultXF( aLevelStyle ), EXC_STYLE_ROWLEVEL, nLevel );
2997  AppendBuiltInXF( new XclExpDefaultXF( aLevelStyle ), EXC_STYLE_COLLEVEL, nLevel );
2998  }
2999 
3000  // index 15: default hard cell format, placeholder to be able to add more built-in styles
3001  maXFList.AppendNewRecord( new XclExpDefaultXF( GetRoot(), true ) );
3003  maBuiltInMap[ EXC_XF_DEFAULTCELL ].mbPredefined = true;
3004 
3005  // index 16-20: other built-in styles
3006  XclExpDefaultXF aFormatStyle( GetRoot(), false );
3007  aFormatStyle.SetFont( 1 );
3008  aFormatStyle.SetNumFmt( 43 );
3010  aFormatStyle.SetNumFmt( 41 );
3012  aFormatStyle.SetNumFmt( 44 );
3014  aFormatStyle.SetNumFmt( 42 );
3016  aFormatStyle.SetNumFmt( 9 );
3018 
3019  // other built-in style XF records (i.e. Hyperlink styles) are created on demand
3020 
3021  /* Insert the real default hard cell format -> 0 is document default pattern.
3022  Do it here (and not already above) to really have all built-in styles. */
3023  Insert( nullptr, GetDefApiScript() );
3024 }
3025 
3026 void XclExpXFBuffer::AppendXFIndex( sal_uInt32 nXFId )
3027 {
3028  OSL_ENSURE( nXFId < maXFIndexVec.size(), "XclExpXFBuffer::AppendXFIndex - XF ID out of range" );
3029  maXFIndexVec[ nXFId ] = static_cast< sal_uInt16 >( maSortedXFList.GetSize() );
3030  XclExpXFRef xXF = maXFList.GetRecord( nXFId );
3031  AddBorderAndFill( *xXF );
3033  OSL_ENSURE( maXFList.HasRecord( nXFId ), "XclExpXFBuffer::AppendXFIndex - XF not found" );
3034 }
3035 
3037 {
3038  if( std::none_of( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ) )
3039  {
3040  maBorders.push_back( rXF.GetBorderData() );
3041  }
3042 
3043  if( std::none_of( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ) )
3044  {
3045  maFills.push_back( rXF.GetAreaData() );
3046  }
3047 }
3048 
3050  : XclExpRoot( rRoot ),
3051  mpKeywordTable( new NfKeywordTable )
3052 {
3053  // Special number formatter for conversion.
3055  xFormatter->FillKeywordTableForExcel( *mpKeywordTable );
3056 
3057  SCTAB nTables = rRoot.GetDoc().GetTableCount();
3058  sal_Int32 nDxfId = 0;
3059  for(SCTAB nTab = 0; nTab < nTables; ++nTab)
3060  {
3061  // Color filters
3062  const ScDBData* pData = rRoot.GetDoc().GetDBCollection()->GetDBNearCursor(0, 0, 0);
3063  if (pData)
3064  {
3065  ScRange aRange;
3066  pData->GetArea(aRange);
3067  for (auto nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); nCol++)
3068  {
3069  ScFilterEntries aFilterEntries;
3070  rRoot.GetDoc().GetFilterEntriesArea(nCol, aRange.aStart.Row(),
3071  aRange.aEnd.Row(), nTab, true, aFilterEntries);
3072 
3073  // Excel has all filter values stored as foreground colors
3074  // Does not matter it is text color or cell background color
3075  for (auto& rColor : aFilterEntries.getBackgroundColors())
3076  {
3077  if (!maColorToDxfId.emplace(rColor, nDxfId).second)
3078  continue;
3079 
3080  std::unique_ptr<XclExpCellArea> pExpCellArea(new XclExpCellArea(rColor, 0));
3081  maDxf.push_back(std::make_unique<XclExpDxf>(rRoot, std::move(pExpCellArea)));
3082  nDxfId++;
3083  }
3084  for (auto& rColor : aFilterEntries.getTextColors())
3085  {
3086  if (!maColorToDxfId.emplace(rColor, nDxfId).second)
3087  continue;
3088 
3089  std::unique_ptr<XclExpCellArea> pExpCellArea(new XclExpCellArea(rColor, 0));
3090  maDxf.push_back(std::make_unique<XclExpDxf>(rRoot, std::move(pExpCellArea)));
3091  nDxfId++;
3092  }
3093  }
3094  }
3095 
3096  // Conditional formatting
3097  ScConditionalFormatList* pList = rRoot.GetDoc().GetCondFormList(nTab);
3098  if (pList)
3099  {
3100  for (const auto& rxItem : *pList)
3101  {
3102  size_t nEntryCount = rxItem->size();
3103  for (size_t nFormatEntry = 0; nFormatEntry < nEntryCount; ++nFormatEntry)
3104  {
3105  const ScFormatEntry* pFormatEntry = rxItem->GetEntry(nFormatEntry);
3106  if (!pFormatEntry
3107  || (pFormatEntry->GetType() != ScFormatEntry::Type::Condition
3108  && pFormatEntry->GetType() != ScFormatEntry::Type::Date
3109  && pFormatEntry->GetType() != ScFormatEntry::Type::ExtCondition))
3110  continue;
3111 
3112  OUString aStyleName;
3113  if (pFormatEntry->GetType() == ScFormatEntry::Type::Condition
3114  || pFormatEntry->GetType() == ScFormatEntry::Type::ExtCondition)
3115  {
3116  const ScCondFormatEntry* pEntry = static_cast<const ScCondFormatEntry*>(pFormatEntry);
3117  aStyleName= pEntry->GetStyle();
3118  }
3119  else
3120  {
3121  const ScCondDateFormatEntry* pEntry = static_cast<const ScCondDateFormatEntry*>(pFormatEntry);
3122  aStyleName = pEntry->GetStyleName();
3123  }
3124 
3125  if (maStyleNameToDxfId.emplace(aStyleName, nDxfId).second)
3126  {
3127  SfxStyleSheetBase* pStyle = rRoot.GetDoc().GetStyleSheetPool()->Find(aStyleName, SfxStyleFamily::Para);
3128  if(!pStyle)
3129  continue;
3130 
3131  SfxItemSet& rSet = pStyle->GetItemSet();
3132 
3133  std::unique_ptr<XclExpCellBorder> pBorder(new XclExpCellBorder);
3134  if (!pBorder->FillFromItemSet( rSet, GetPalette(), GetBiff()) )
3135  {
3136  pBorder.reset();
3137  }
3138 
3139  std::unique_ptr<XclExpCellAlign> pAlign(new XclExpCellAlign);
3140  if (!pAlign->FillFromItemSet(rRoot, rSet, false, GetBiff()))
3141  {
3142  pAlign.reset();
3143  }
3144 
3145  std::unique_ptr<XclExpCellProt> pCellProt(new XclExpCellProt);
3146  if (!pCellProt->FillFromItemSet( rSet ))
3147  {
3148  pCellProt.reset();
3149  }
3150 
3151  std::unique_ptr<XclExpColor> pColor(new XclExpColor);
3152  if(!pColor->FillFromItemSet( rSet ))
3153  {
3154  pColor.reset();
3155  }
3156 
3157  std::unique_ptr<XclExpDxfFont> pFont(new XclExpDxfFont(rRoot, rSet));
3158 
3159  std::unique_ptr<XclExpNumFmt> pNumFormat;
3160  const SfxPoolItem *pPoolItem = nullptr;
3161  if( rSet.GetItemState( ATTR_VALUE_FORMAT, true, &pPoolItem ) == SfxItemState::SET )
3162  {
3163  sal_uInt32 nScNumFmt = static_cast< const SfxUInt32Item* >(pPoolItem)->GetValue();
3164  sal_Int32 nXclNumFmt = GetRoot().GetNumFmtBuffer().Insert(nScNumFmt);
3165  pNumFormat.reset(new XclExpNumFmt( nScNumFmt, nXclNumFmt, GetNumberFormatCode( *this, nScNumFmt, xFormatter.get(), mpKeywordTable.get() )));
3166  }
3167 
3168  maDxf.push_back(std::make_unique<XclExpDxf>( rRoot, std::move(pAlign), std::move(pBorder),
3169  std::move(pFont), std::move(pNumFormat), std::move(pCellProt), std::move(pColor) ));
3170  ++nDxfId;
3171  }
3172 
3173  }
3174  }
3175  }
3176  }
3177 }
3178 
3179 sal_Int32 XclExpDxfs::GetDxfId( const OUString& rStyleName )
3180 {
3181  std::map<OUString, sal_Int32>::iterator itr = maStyleNameToDxfId.find(rStyleName);
3182  if(itr!= maStyleNameToDxfId.end())
3183  return itr->second;
3184  return -1;
3185 }
3186 
3188 {
3189  std::map<Color, sal_Int32>::iterator itr = maColorToDxfId.find(aColor);
3190  if (itr != maColorToDxfId.end())
3191  return itr->second;
3192  return -1;
3193 }
3194 
3196 {
3197  if(maDxf.empty())
3198  return;
3199 
3200  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
3201  rStyleSheet->startElement(XML_dxfs, XML_count, OString::number(maDxf.size()));
3202 
3203  for ( auto& rxDxf : maDxf )
3204  {
3205  rxDxf->SaveXml( rStrm );
3206  }
3207 
3208  rStyleSheet->endElement( XML_dxfs );
3209 }
3210 
3211 XclExpDxf::XclExpDxf( const XclExpRoot& rRoot, std::unique_ptr<XclExpCellAlign> pAlign, std::unique_ptr<XclExpCellBorder> pBorder,
3212  std::unique_ptr<XclExpDxfFont> pFont, std::unique_ptr<XclExpNumFmt> pNumberFmt, std::unique_ptr<XclExpCellProt> pProt,
3213  std::unique_ptr<XclExpColor> pColor)
3214  : XclExpRoot( rRoot ),
3215  mpAlign(std::move(pAlign)),
3216  mpBorder(std::move(pBorder)),
3217  mpFont(std::move(pFont)),
3218  mpNumberFmt(std::move(pNumberFmt)),
3219  mpProt(std::move(pProt)),
3220  mpColor(std::move(pColor))
3221 {
3222 }
3223 
3224 XclExpDxf::XclExpDxf(const XclExpRoot& rRoot, std::unique_ptr<XclExpCellArea> pCellArea)
3225  : XclExpRoot(rRoot)
3226  , mpCellArea(std::move(pCellArea))
3227 {
3228 }
3229 
3231 {
3232 }
3233 
3235 {
3236  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
3237  rStyleSheet->startElement(XML_dxf);
3238 
3239  if (mpFont)
3240  mpFont->SaveXml(rStrm);
3241  if (mpNumberFmt)
3242  mpNumberFmt->SaveXml(rStrm);
3243  if (mpColor)
3244  mpColor->SaveXml(rStrm);
3245  if (mpAlign)
3246  mpAlign->SaveXml(rStrm);
3247  if (mpBorder)
3248  mpBorder->SaveXml(rStrm);
3249  if (mpProt)
3250  mpProt->SaveXml(rStrm);
3251  if (mpCellArea)
3252  mpCellArea->SaveXml(rStrm);
3253  rStyleSheet->endElement( XML_dxf );
3254 }
3255 
3257 {
3258  sax_fastparser::FSHelperPtr& rStyleSheet = rStrm.GetCurrentStream();
3259  rStyleSheet->startElementNS( XML_x14, XML_dxf );
3260 
3261  if (mpFont)
3262  mpFont->SaveXml(rStrm);
3263  if (mpNumberFmt)
3264  mpNumberFmt->SaveXml(rStrm);
3265  if (mpColor)
3266  mpColor->SaveXml(rStrm);
3267  if (mpAlign)
3268  mpAlign->SaveXml(rStrm);
3269  if (mpBorder)
3270  mpBorder->SaveXml(rStrm);
3271  if (mpProt)
3272  mpProt->SaveXml(rStrm);
3273  rStyleSheet->endElementNS( XML_x14, XML_dxf );
3274 }
3275 
3276 
3278  : XclExpRoot( rRoot )
3279 {
3280 }
3281 
3283 {
3284  sax_fastparser::FSHelperPtr aStyleSheet = rStrm.CreateOutputStream(
3285  "xl/styles.xml",
3286  u"styles.xml",
3287  rStrm.GetCurrentStream()->getOutputStream(),
3288  "application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml",
3289  oox::getRelationship(Relationship::STYLES));
3290  rStrm.PushStream( aStyleSheet );
3291 
3292  aStyleSheet->startElement(XML_styleSheet, XML_xmlns, rStrm.getNamespaceURL(OOX_NS(xls)));
3293 
3294  CreateRecord( EXC_ID_FORMATLIST )->SaveXml( rStrm );
3295  CreateRecord( EXC_ID_FONTLIST )->SaveXml( rStrm );
3296  CreateRecord( EXC_ID_XFLIST )->SaveXml( rStrm );
3297  CreateRecord( EXC_ID_DXFS )->SaveXml( rStrm );
3298  CreateRecord( EXC_ID_PALETTE )->SaveXml( rStrm );
3299 
3300  aStyleSheet->endElement( XML_styleSheet );
3301 
3302  rStrm.PopStream();
3303 }
3304 
3305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 mnBottomColor
Palette index for top line.
Definition: xlstyle.hxx:527
sal_uInt16 GetXclFont() const
Definition: xestyle.hxx:476
sal_uInt8 mnTopLine
Style of right line.
Definition: xlstyle.hxx:531
std::unique_ptr< XclExpNumFmt > mpNumberFmt
Definition: xestyle.hxx:740
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:1243
This class stores an unformatted or formatted string for Excel export.
Definition: xestring.hxx:47
bool mbShrink
true = Multi-line text.
Definition: xlstyle.hxx:496
void FillToXF8(sal_uInt16 &rnAlign, sal_uInt16 &rnMiscAttrib) const
Fills the data to the passed fields of a BIFF8 XF record.
Definition: xestyle.cxx:1555
constexpr TypedWhichId< SvxWeightItem > ATTR_CTL_FONT_WEIGHT(118)
void SaveXml(XclExpXmlStream &rStrm) const
Definition: xestyle.cxx:1951
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
XclExpBuiltInMap maBuiltInMap
List of all STYLE records.
Definition: xestyle.hxx:714
virtual void Save(XclExpStream &rStrm) override
Writes the complete record list.
Definition: xerecord.hxx:374
Stores all XF records (cell formats and cell styles) in the document.
Definition: xestyle.hxx:574
bool mbAreaUsed
true = border data used.
Definition: xlstyle.hxx:595
SvxCellHorJustify
#define DBG_ERROR_BIFF()
Definition: xltools.hxx:33
virtual void Save(XclExpStream &rStrm) override
Writes all FORMAT records contained in this buffer.
Definition: xestyle.cxx:1374
std::optional< FontItalic > eItalic
Definition: fonthelper.hxx:26
static OString ToOString(const Color &rColor)
Definition: xestream.cxx:703
const sal_uInt8 EXC_XF_VER_CENTER
Definition: xlstyle.hxx:168
const sal_uInt8 EXC_XF_HOR_JUSTIFY
Definition: xlstyle.hxx:163
vcl::Font GetFontFromItemSet(const XclExpRoot &rRoot, const SfxItemSet &rItemSet, sal_Int16 nScript)
Returns a VCL font object filled from the passed item set.
Definition: xestyle.cxx:883
const sal_uInt8 EXC_XF_HOR_CENTER
Definition: xlstyle.hxx:160
bool mbDiagBLtoTR
true = Top-left to bottom-right on.
Definition: xlstyle.hxx:535
XclExpColorType
For internal use only. TODO:moggi: find a better/correct value.
Definition: xestyle.hxx:45
rtl_TextEncoding GetTextEncoding() const
Returns the text encoding to import/export byte strings.
Definition: xlroot.hxx:147
sal_Int32 nIndex
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:814
XclBiff
An enumeration for all Excel file format types (BIFF types).
Definition: xlconst.hxx:29
sal_uInt8 mnCharSet
Windows font family.
Definition: xlstyle.hxx:294
std::set< Color > & getTextColors()
ScAddress aStart
Definition: address.hxx:499
const sal_uInt8 EXC_XF_TEXTDIR_CONTEXT
Definition: xlstyle.hxx:173
XclExpDxf(const XclExpRoot &rRoot, std::unique_ptr< XclExpCellAlign > pAlign, std::unique_ptr< XclExpCellBorder > pBorder, std::unique_ptr< XclExpDxfFont > pFont, std::unique_ptr< XclExpNumFmt > pNumberFmt, std::unique_ptr< XclExpCellProt > pProt, std::unique_ptr< XclExpColor > pColor)
Definition: xestyle.cxx:3211
sal_uInt16 mnDiagColor
Palette index for bottom line.
Definition: xlstyle.hxx:528
const sal_uInt16 EXC_BORDER_HAIR
Definition: xlconst.hxx:251
sal_uInt32 mnScNumFmt
Definition: xestyle.hxx:255
sal_uInt8 mnOrient
Vertical alignment.
Definition: xlstyle.hxx:491
sal_uInt16 mnXclFont
Calc number format index.
Definition: xestyle.hxx:490
bool mbShadow
true = Outlined.
Definition: xlstyle.hxx:299
constexpr TypedWhichId< SvxLanguageItem > ATTR_LANGUAGE_FORMAT(147)
sal_uInt8 GetRed() const
const sal_uInt16 EXC_XF_LINEBREAK
Styles don't have a parent.
Definition: xlstyle.hxx:148
std::optional< Color > aColor
Definition: fonthelper.hxx:35
static bool CheckItem(const SfxItemSet &rItemSet, sal_uInt16 nWhichId, bool bDeep)
Returns true, if the passed item set contains the item.
Definition: ftools.cxx:199
void SetAllUsedFlags(bool bUsed)
Sets all "attribute used" flags to the passed state.
Definition: xlstyle.cxx:1727
const sal_uInt16 EXC_XF_DEFAULTCELL
Excel index to default style XF.
Definition: xlstyle.hxx:139
void WriteBody(XclExpStream &rStrm)
Writes the color list (contents of the palette record) to the passed stream.
Definition: xestyle.cxx:477
void SetBlue(sal_uInt8 nBlue)
FAMILY_SCRIPT
const sal_uInt8 EXC_XF_DIFF_VALFMT
Shrink to fit into cell.
Definition: xlstyle.hxx:151
const sal_uInt8 EXC_XF_HOR_DISTRIB
Definition: xlstyle.hxx:165
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
const sal_uInt8 EXC_PATT_6_25_PERC
Definition: xlstyle.hxx:60
const XclExpRoot & GetRoot() const
Returns the filter root data.
Definition: xestream.hxx:291
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
static FindKey ToFindKey(XclExpXF const &)
Definition: xestyle.cxx:2789
virtual ~XclExpNumFmtBuffer() override
Definition: xestyle.cxx:1352
This class is used to export Excel record streams.
Definition: xestream.hxx:72
SCROW Row() const
Definition: address.hxx:261
XclExpXFId maXFId
Name of the cell style.
Definition: xestyle.hxx:554
#define LANGUAGE_ENGLISH_US
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xerecord.hxx:381
Background area of a cell.
Definition: xestyle.hxx:50
const sal_uInt16 EXC_XF_LOCKED
Definition: xlstyle.hxx:144
FAMILY_MODERN
bool mbDiagTLtoBR
Style of diagonal line(s).
Definition: xlstyle.hxx:534
static sal_uInt8 GetXclRotation(Degree100 nScRot)
Calculates the Excel angle value from an angle in 1/100 of degrees.
Definition: xltools.cxx:162
std::unique_ptr< ContentProperties > pData
std::string GetValue
const size_t EXC_FONTLIST_NOTFOUND
Definition: xestyle.hxx:120
bool IsTransparent() const
XclExpNumFmtVec maFormatMap
Special number formatter for conversion.
Definition: xestyle.hxx:298
sal_Int16 mnLevel
static sal_uInt8 GetXclOrientFromRot(sal_uInt16 nXclRot)
Calculates BIFF2-BIFF5 text orientation from BIFF8 rotation angle.
Definition: xltools.cxx:189
std::map< OUString, sal_Int32 > maStyleNameToDxfId
Definition: xestyle.hxx:757
void SaveXml(XclExpXmlStream &rStrm) const
Definition: xestyle.cxx:1850
virtual void Save(XclExpStream &rStrm) override
Writes all FONT records contained in this buffer.
Definition: xestyle.cxx:1238
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:1067
void AppendRecord(RecType *pRec)
Appends a record to the list.
Definition: xerecord.hxx:347
const sal_uInt8 EXC_LINE_MEDIUM_DASHDOTDOT
Definition: xlstyle.hxx:49
XclExpPaletteImplRef mxImpl
Definition: xestyle.hxx:115
const sal_uInt8 EXC_ROT_STACKED
Text rotation: 90 deg clockwise.
Definition: xlconst.hxx:141
const sal_uInt8 EXC_LINE_DOTTED
Definition: xlstyle.hxx:41
Border of a cell.
Definition: xestyle.hxx:49
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:3282
sal_uInt32 FindXF(const ScPatternAttr &rPattern, sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak) const
Returns the XF ID of the cell XF containing the passed format.
Definition: xestyle.cxx:2720
void SetCharWidth(const XclFontData &rFontData)
Sets the width of the '0' - '9' digit character as well as the ' ' space char (using the default font...
Definition: xlroot.cxx:207
void SaveXml(XclExpXmlStream &rStrm) const
Definition: xestyle.cxx:1595
const sal_uInt32 EXC_PAL_MAXRAWSIZE
Definition: xestyle.cxx:311
constexpr TypedWhichId< SvxCrossedOutItem > ATTR_FONT_CROSSEDOUT(106)
long Long
const XclExpCellBorder & GetBorderData() const
Returns the cell border settings of this XF.
Definition: xestyle.hxx:447
OUString maNumFmtString
Resulting Excel format index.
Definition: xestyle.hxx:257
FAMILY_DONTKNOW
const XclExpCellArea & GetAreaData() const
Returns the cell fill settings of this XF.
Definition: xestyle.hxx:449
XclExpPalette(const XclExpRoot &rRoot)
Definition: xestyle.cxx:754
const sal_uInt8 EXC_XF_HOR_RIGHT
Definition: xlstyle.hxx:161
sal_uInt16 Insert(const XclFontData &rFontData, XclExpColorType eColorType, bool bAppFont=false)
Inserts a new font with the passed font data into the buffer if not present.
Definition: xestyle.cxx:1192
constexpr TypedWhichId< SvxLanguageItem > ATTR_FONT_LANGUAGE(110)
bool mbCellXF
Index to parent style XF.
Definition: xlstyle.hxx:589
const SfxItemSet * GetItemSet() const
Definition: xestyle.hxx:473
constexpr::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
void FillToXF3(sal_uInt16 &rnProt) const
Fills the data to the passed fields of a BIFF3-BIFF8 XF record.
Definition: xestyle.cxx:1436
This struct helps reading and writing Excel fonts.
Definition: xlstyle.hxx:285
bool FillFromItemSet(const SfxItemSet &rItemSet, XclExpPalette &rPalette, bool bStyle)
Fills the area attributes from the passed item set.
Definition: xestyle.cxx:1887
const size_t EXC_FONT_MAXCOUNT4
Definition: xlstyle.hxx:79
void GetMixedColors(sal_uInt16 &rnXclForeIx, sal_uInt16 &rnXclBackIx, sal_uInt8 &rnXclPattern, sal_uInt32 nForeColorId, sal_uInt32 nBackColorId) const
Returns a foreground and background color for the two passed color IDs.
Definition: xestyle.cxx:786
sal_uInt8 mnRightLine
Style of left line.
Definition: xlstyle.hxx:530
const sal_uInt16 EXC_BORDER_THICK
Definition: xlconst.hxx:248
static bool GetBuiltInStyleId(sal_uInt8 &rnStyleId, sal_uInt8 &rnLevel, const OUString &rStyleName)
Returns the Excel built-in style identifier of a passed style name.
Definition: xltools.cxx:625
const OUString & GetStyle() const
Definition: conditio.hxx:473
const sal_uInt8 EXC_LINE_THIN_DASHDOTDOT
Definition: xlstyle.hxx:48
void SetRecSize(std::size_t nRecSize)
Sets a new record size prediction.
Definition: xerecord.hxx:162
Spreadsheet grid color.
Definition: xestyle.hxx:55
sal_uInt32 mnForeColorId
Definition: xestyle.hxx:374
XclExpCellAlign maAlignment
Cell protection flags.
Definition: xestyle.hxx:485
void SetXmlIds(sal_uInt32 nBorderId, sal_uInt32 nFillId)
Definition: xestyle.cxx:2220
bool mbFmtUsed
true = font index used.
Definition: xlstyle.hxx:592
OUString GetFormatCode(sal_uInt32 nScNumFmt)
Definition: xestyle.cxx:1421
sal_Int16 nId
const SfxItemSet & GetItemSet() const
void InsertUserStyles()
Inserts an XF and a STYLE record for all user defined style sheets.
Definition: xestyle.cxx:2917
Stores all default colors for a specific BIFF version.
Definition: xlstyle.hxx:250
sal_uInt32 GetNearestListColor(const Color &rColor, sal_uInt32 nIgnore) const
Returns the list index of the color nearest to rColor.
Definition: xestyle.cxx:672
sal_uInt16 mnHeight
Font color.
Definition: xlstyle.hxx:290
void SaveXml(XclExpXmlStream &rStrm) const
Definition: xestyle.cxx:1442
const sal_uInt16 EXC_XF_NOTFOUND
Excel index to default cell XF.
Definition: xlstyle.hxx:140
const sal_uInt16 EXC_FONTATTR_UNDERLINE
Definition: xlstyle.hxx:99
XclExpXFBuffer(const XclExpRoot &rRoot)
Definition: xestyle.cxx:2452
const sal_uInt16 EXC_ID_DXFS
For internal use only.
Definition: xestyle.hxx:40
sal_uInt32 mnTopColorId
Color ID for right line.
Definition: xestyle.hxx:345
sal_uInt32 mnBottomColorId
Color ID for top line.
Definition: xestyle.hxx:346
ScAddress aEnd
Definition: address.hxx:500
void set_flag(Type &rnBitField, Type nMask, bool bSet=true)
Sets or clears (according to bSet) all set bits of nMask in rnBitField.
Definition: ftools.hxx:95
basegfx::BColor maColor
STRIKEOUT_SLASH
constexpr TypedWhichId< SvxFontItem > ATTR_FONT(100)
ReturnType limit_cast(Type nValue, ReturnType nMin, ReturnType nMax)
Returns the value, if it is not less than nMin and not greater than nMax, otherwise one of the limits...
Definition: ftools.hxx:63
const sal_uInt8 EXC_XF_VER_JUSTIFY
Definition: xlstyle.hxx:170
virtual SfxItemSet & GetItemSet()
ScfUInt16Vec maXFIndexVec
Contained elements describe built-in XFs.
Definition: xestyle.hxx:715
FAMILY_ROMAN
constexpr TypedWhichId< ScLineBreakCell > ATTR_LINEBREAK(139)
std::unique_ptr< NfKeywordTable > mpKeywordTable
Definition: xestyle.hxx:760
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
XclExpFontBuffer(const XclExpRoot &rRoot)
Definition: xestyle.cxx:1168
XclExpXFId()
Real Excel XF index.
Definition: xestyle.cxx:2024
std::shared_ptr< T > make_shared(Args &&...args)
void FillToXF5(sal_uInt16 &rnAlign) const
Fills the data to the passed fields of a BIFF5/BIFF7 XF record.
Definition: xestyle.cxx:1547
sal_uInt32 mnParentXFId
Background area style.
Definition: xestyle.hxx:488
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:286
XclExpCellArea maArea
Border line style.
Definition: xestyle.hxx:487
const sal_uInt16 EXC_COLOR_USEROFFSET
Definition: xlstyle.hxx:204
SvNumberFormatter & GetFormatter() const
Returns the number formatter of the Calc document.
Definition: xlroot.cxx:323
virtual void WriteBody(XclExpStream &rStrm) override
Writes the contents of the STYLE record.
Definition: xestyle.cxx:2306
const XclExpXF * GetXFById(sal_uInt32 nXFId) const
Returns an XF record by its unique identifier.
Definition: xestyle.cxx:2494
sal_uInt32 GetColorCount() const
Returns the color count in the current palette.
Definition: xlstyle.hxx:256
const editeng::SvxBorderLine * GetRight() const
const sal_uInt16 EXC_FONTATTR_ITALIC
Definition: xlstyle.hxx:98
const sal_uInt8 EXC_STYLE_USERDEF
"Followed_Hyperlink" style.
Definition: xlstyle.hxx:234
void SetScFrameDir(SvxFrameDirection eFrameDir)
Sets the Calc frame direction.
Definition: xlstyle.cxx:1642
const sal_uInt8 EXC_STYLE_COMMA_0
"Percent" style.
Definition: xlstyle.hxx:230
static sal_uInt32 GetXFIdFromIndex(sal_uInt16 nXFIndex)
Returns the XF identifier representing a fixed Excel XF index (e.g.
Definition: xestyle.cxx:2484
sal_uInt32 mnLastIdx
Contains resulting colors to export.
Definition: xestyle.cxx:307
virtual void Save(XclExpStream &rStrm) override
Saves the PALETTE record, if it differs from the default palette.
Definition: xestyle.cxx:798
XclExpFontList maFontList
Definition: xestyle.hxx:246
void SetFinalColors()
Sets the resulting Excel palette index from all used color IDs (border and area). ...
Definition: xestyle.cxx:2084
std::vector< sal_Int8 > maData
const XclExpCellProt & GetProtectionData() const
Returns the cell protection settings of this XF.
Definition: xestyle.hxx:443
const sal_uInt8 EXC_XF_HOR_GENERAL
Definition: xlstyle.hxx:158
const sal_uInt8 EXC_PATT_25_PERC
Definition: xlstyle.hxx:58
Extends the XclCellArea struct for export.
Definition: xestyle.hxx:372
void ReplaceRecord(RecType *pRec, size_t nPos)
Replaces the record at the specified position from the list with the passed record.
Definition: xerecord.hxx:354
ScDBData * GetDBNearCursor(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: dbdata.cxx:1487
const XclExpFont * GetFont(sal_uInt16 nXclFont) const
Returns the specified font from font list.
Definition: xestyle.cxx:1182
void RawReducePalette(sal_uInt32 nPass)
Raw and fast reduction of the palette.
Definition: xestyle.cxx:558
static const char * ToVerticalAlignment(sal_uInt8 nVerAlign)
Definition: xestyle.cxx:1582
sal_Int32 GetDxfByColor(Color aColor)
Definition: xestyle.cxx:3187
const sal_uInt8 EXC_LINE_THIN
Definition: xlstyle.hxx:38
constexpr TypedWhichId< ScIndentItem > ATTR_INDENT(131)
const sal_uInt8 EXC_LINE_HAIR
Definition: xlstyle.hxx:44
WEIGHT_BOLD
ScfUInt16Vec maStyleIndexes
Maps XF IDs to XF indexes.
Definition: xestyle.hxx:716
#define SAL_MAX_UINT32
const sal_uInt8 EXC_STYLE_CURRENCY
"Comma" style.
Definition: xlstyle.hxx:228
Text in a cell.
Definition: xestyle.hxx:48
sal_uInt32 InsertCellXF(const ScPatternAttr *pPattern, sal_Int16 nScript, sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak)
Tries to find the XF record containing the passed format or inserts a new record. ...
Definition: xestyle.cxx:2794
sal_uInt16 mnXclNumFmt
Excel font index.
Definition: xestyle.hxx:491
std::set< Color > & getBackgroundColors()
constexpr TypedWhichId< ScRotateValueItem > ATTR_ROTATE_VALUE(135)
sal_uInt32 AppendBuiltInXF(XclExpXFRef const &xXF, sal_uInt8 nStyleId, sal_uInt8 nLevel=EXC_STYLE_NOLEVEL)
Inserts a built-in XF record without a STYLE record and returns the XF ID.
Definition: xestyle.cxx:2925
void FillToXF5(sal_uInt32 &rnArea) const
Fills the data to the passed fields of a BIFF5/BIFF7 XF record.
Definition: xestyle.cxx:1910
SC_DLLPUBLIC ScConditionalFormatList * GetCondFormList(SCTAB nTab) const
Definition: documen4.cxx:868
Access to global data from other classes.
Definition: xeroot.hxx:112
const sal_uInt16 EXC_FONT_APP
Definition: xlstyle.hxx:76
sal_uInt32 InsertStyle(const SfxStyleSheetBase *pStyleSheet)
Inserts the passed cell style.
Definition: xestyle.cxx:2479
SvxCellVerJustify
static OUString GetXclFontName(const OUString &rFontName)
Returns the matching Excel font name for a passed Calc font name.
Definition: xltools.cxx:455
const OUString & GetName() const
bool Equals(const ScPatternAttr &rPattern, sal_uInt32 nScForceNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak) const
Returns true, if this XF record represents the passed cell formatting.
Definition: xestyle.cxx:2070
OUString getNamespaceURL(sal_Int32 nNSID) const
const sal_uInt16 EXC_FONT_NOTFOUND
Application font index.
Definition: xlstyle.hxx:77
LINESTYLE_NONE
MS Excel 4.0.
Definition: xlconst.hxx:34
virtual bool Equals(const XclFontData &rFontData, sal_uInt32 nHash) const
Compares this font with the passed font data.
Definition: xestyle.cxx:974
const sal_uInt8 EXC_PATT_75_PERC
Definition: xlstyle.hxx:57
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
SvtScriptType FromI18NToSvtScriptType(sal_Int16 nI18NType)
sal_Int32 GetXmlCellIndex(sal_uInt32 nXFId) const
Definition: xestyle.cxx:2614
size_t mnXclMaxSize
List of all FONT records.
Definition: xestyle.hxx:247
ScStyleSheetPool & GetStyleSheetPool() const
Returns the style sheet pool of the Calc document.
Definition: xlroot.cxx:307
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND
void Init(const SfxItemSet &rItemSet, sal_Int16 nScript, sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak, bool bDefStyle)
Fills all members from the passed item set.
Definition: xestyle.cxx:2108
const sal_uInt8 EXC_LINE_MEDIUM_SLANT_DASHDOT
Definition: xlstyle.hxx:50
int nCount
void FillToXF5(sal_uInt32 &rnBorder, sal_uInt32 &rnArea) const
Fills the data to the passed fields of a BIFF5/BIFF7 XF record.
Definition: xestyle.cxx:1773
bool mbOutline
true = Struck out.
Definition: xlstyle.hxx:298
sal_uInt32 mnScNumFmt
XF ID of parent XF record.
Definition: xestyle.hxx:489
const size_t EXC_FONT_MAXCOUNT8
Definition: xlstyle.hxx:81
sal_uInt16 mnBackColor
Palette index to foreground color.
Definition: xlstyle.hxx:546
constexpr TypedWhichId< SvxJustifyMethodItem > ATTR_HOR_JUSTIFY_METHOD(130)
bool IsStyleXF() const
Returns true, if this is a cell style.
Definition: xlstyle.hxx:581
sal_Int32 GetNearestPaletteColor(sal_uInt32 &rnIndex, const Color &rColor) const
Returns in rnIndex the palette index of the color nearest to rColor.
Definition: xestyle.cxx:703
void PushStream(sax_fastparser::FSHelperPtr const &aStream)
Definition: xestream.cxx:921
static sax_fastparser::FSHelperPtr WriteFontData(sax_fastparser::FSHelperPtr pStream, const XclFontData &rFontData, sal_Int32 nNameId)
Definition: xestream.cxx:871
std::map< Color, sal_Int32 > maColorToDxfId
Definition: xestyle.hxx:758
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:2645
XclExpXFList maXFList
Definition: xestyle.hxx:709
sal_uInt32 mnLeftColorId
Definition: xestyle.hxx:343
virtual SfxStyleSheetBase * First()
constexpr TypedWhichId< ScShrinkToFitCell > ATTR_SHRINKTOFIT(140)
const sal_uInt8 EXC_XF_DIFF_ALIGN
Definition: xlstyle.hxx:153
void SetScWeight(FontWeight eScWeight)
Sets the Calc font weight.
Definition: xlstyle.cxx:341
void ConvertXFIndex(const XclExpRoot &rRoot)
Converts the XF identifier in mnXFId to an Excel XF index and stores it in mnXFIndex.
Definition: xestyle.cxx:2036
sal_uInt8 mnDiagLine
Style of bottom line.
Definition: xlstyle.hxx:533
virtual void WriteBody(XclExpStream &rStrm) override
Writes the contents of the FONT record.
Definition: xestyle.cxx:990
sal_uInt16 mnRightColor
Palette index for left line.
Definition: xlstyle.hxx:525
sal_uInt16 mnForeColor
Definition: xlstyle.hxx:545
Extends the XclCellAlign struct for export.
Definition: xestyle.hxx:322
sal_uInt32 InsertColor(const Color &rColor, XclExpColorType eType, sal_uInt16 nAutoDefault=0)
Inserts the color into the list and updates weighting.
Definition: xestyle.cxx:766
sal_uInt16 GetColorIndex(sal_uInt32 nColorId) const
Returns the Excel palette index of the color with passed color ID.
Definition: xestyle.cxx:400
sal_uInt16 mnTopColor
Palette index for right line.
Definition: xlstyle.hxx:526
Color maForeColor
Background color ID.
Definition: xestyle.hxx:376
bool mbItalic
Underline style.
Definition: xlstyle.hxx:296
sax_fastparser::FSHelperPtr & GetCurrentStream()
Definition: xestream.cxx:915
XclExpFont(const XclExpRoot &rRoot, const XclFontData &rFontData, XclExpColorType eColorType)
Definition: xestyle.cxx:959
bool FillFromItemSet(const SfxItemSet &rItemSet, bool bStyle=false)
Fills the protection attributes from the passed item set.
Definition: xestyle.cxx:1428
bool IsCellXF() const
Returns true, if this is a hard cell format.
Definition: xlstyle.hxx:579
const sal_uInt32 EXC_XF_MAXCOUNT
Definition: xlstyle.hxx:136
STRIKEOUT_SINGLE
OUString getRelationship(Relationship eRelationship)
FAMILY_DECORATIVE
std::optional< bool > bOutline
Definition: fonthelper.hxx:31
sal_uInt8 GetBlue() const
bool HasRecord(size_t nPos) const
Returns true, if the passed index points to an exiting record.
Definition: xerecord.hxx:329
const sal_uInt8 EXC_PATT_12_5_PERC
Definition: xlstyle.hxx:59
const sal_uInt8 EXC_STYLE_ROWLEVEL
"Normal" style.
Definition: xlstyle.hxx:225
void InitDefaultFonts()
Initializes the default fonts for the current BIFF version.
Definition: xestyle.cxx:1258
const char * sName
void PopStream()
Definition: xestream.cxx:926
XclExpCellBorder()
Color ID for diagonal line(s).
Definition: xestyle.cxx:1697
static const char * lcl_StyleNameFromId(sal_Int32 nStyleId)
Definition: xestyle.cxx:2327
sal_uInt32 AppendBuiltInXFWithStyle(XclExpXFRef const &xXF, sal_uInt8 nStyleId, sal_uInt8 nLevel=EXC_STYLE_NOLEVEL)
Inserts a built-in XF and STYLE record and returns the XF ID.
Definition: xestyle.cxx:2937
bool mbFontUsed
true = cell protection used.
Definition: xlstyle.hxx:591
constexpr TypedWhichId< SvxUnderlineItem > ATTR_FONT_UNDERLINE(104)
bool mbAlignUsed
true = number format used.
Definition: xlstyle.hxx:593
sal_uInt8 mnVerAlign
Horizontal alignment.
Definition: xlstyle.hxx:490
std::vector< XclPaletteColor > maPalette
Data of all CIDs.
Definition: xestyle.cxx:306
sal_uInt32 mnColorId
All font attributes.
Definition: xestyle.hxx:175
void SetFinalColors(const XclExpPalette &rPalette)
Fills the mn***Color base members from the mn***ColorId members.
Definition: xestyle.cxx:1905
sal_uInt16 mnLeftColor
Definition: xlstyle.hxx:524
virtual void Save(XclExpStream &rStrm) override
Writes all XF records contained in this buffer.
Definition: xestyle.cxx:2622
const XclFontData & GetFontData() const
Returns read-only access to font data.
Definition: xestyle.hxx:160
const Color & GetOriginalColor(sal_uInt32 nColorId) const
Returns the original inserted color represented by the color ID nColorId.
Definition: xestyle.cxx:498
const sal_uInt16 EXC_XF_STYLEPARENT
Definition: xlstyle.hxx:147
const sal_uInt8 EXC_LINE_DASHED
Definition: xlstyle.hxx:40
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_TLBR(141)
bool GetHideCell() const
Definition: attrib.hxx:147
const Color & GetColor() const
::std::unique_ptr< SvNumberFormatter > SvNumberFormatterPtr
Definition: xestyle.hxx:265
XclExpXmlStyleSheet(const XclExpRoot &rRoot)
Definition: xestyle.cxx:3277
composite key for the find-map, so we can do partial key searching
Definition: xestyle.hxx:689
const sal_uInt8 EXC_STYLE_PERCENT
"Currency" style.
Definition: xlstyle.hxx:229
const editeng::SvxBorderLine * GetTop() const
sal_uInt16 mnEscapem
Boldness: 400=normal, 700=bold.
Definition: xlstyle.hxx:292
constexpr TypedWhichId< SvxPostureItem > ATTR_FONT_POSTURE(103)
XclFontData maData
Definition: xestyle.hxx:174
Stores all data of an Excel font and provides export of FONT records.
Definition: xestyle.hxx:153
bool IsTransparent() const
Returns true, if the area represents transparent state.
Definition: xlstyle.cxx:1704
const sal_uInt8 EXC_XF_HOR_FILL
Definition: xlstyle.hxx:162
Represents a default XF record.
Definition: xestyle.hxx:524
constexpr TypedWhichId< SvxShadowedItem > ATTR_FONT_SHADOWED(108)
SvtScriptType
MS Excel 5.0, MS Excel 7.0 (95)
Definition: xlconst.hxx:35
sal_uInt32 GetScNumFmt() const
Definition: xestyle.hxx:475
Extends the XclCellBorder struct for export.
Definition: xestyle.hxx:341
static void GetFont(vcl::Font &rFont, const SfxItemSet &rItemSet, ScAutoFontColorMode eAutoMode, const OutputDevice *pOutDev=nullptr, const Fraction *pScale=nullptr, const SfxItemSet *pCondSet=nullptr, SvtScriptType nScript=SvtScriptType::NONE, const Color *pBackConfigColor=nullptr, const Color *pTextConfigColor=nullptr)
Static helper function to fill a font object from the passed item set.
Definition: patattr.cxx:215
void Assign(const OUString &rString, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Assigns an unformatted string, converts this object to a BIFF8 Unicode string.
Definition: xestring.cxx:111
XclOutput GetOutput() const
Returns the current output format of the importer/exporter.
Definition: xlroot.hxx:143
void SetScVerAlign(SvxCellVerJustify eVerJust)
Sets the Calc vertical alignment.
Definition: xlstyle.cxx:1629
#define SAL_MAX_INT32
const SfxItemSet * GetParent() const
sal_uInt8 mnUnderline
Windows character set.
Definition: xlstyle.hxx:295
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:1380
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CJK_FONT_HEIGHT(112)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const editeng::SvxBorderLine * GetLeft() const
sal_uInt16 GetColorIndex(sal_uInt32 nColorId) const
Returns the Excel palette index of the color with passed color ID.
Definition: xestyle.cxx:781
std::unique_ptr< XclExpCellProt > mpProt
Definition: xestyle.hxx:741
sal_uInt32 mnDiagColorId
Color ID for bottom line.
Definition: xestyle.hxx:347
void GetMixedColors(sal_uInt16 &rnXclForeIx, sal_uInt16 &rnXclBackIx, sal_uInt8 &rnXclPattern, sal_uInt32 nForeColorId, sal_uInt32 nBackColorId) const
Returns a foreground and background color for the two passed color IDs.
Definition: xestyle.cxx:410
const sal_uInt8 EXC_XF_DIFF_PROT
Definition: xlstyle.hxx:156
int i
XclExpNumFmtBuffer(const XclExpRoot &rRoot)
Definition: xestyle.cxx:1336
std::unique_ptr< XclExpDxfFont > mpFont
Definition: xestyle.hxx:739
std::optional< bool > bShadow
Definition: fonthelper.hxx:32
const sal_uInt32 EXC_PAL_INDEXBASE
Definition: xestyle.cxx:310
const sal_uInt16 EXC_ID_FONTLIST
Definition: xestyle.hxx:37
sal_uInt32 InsertStyleXF(const SfxStyleSheetBase &rStyleSheet)
Inserts the passed cell style.
Definition: xestyle.cxx:2846
const sal_uInt16 EXC_COLOR_WINDOWTEXT
System window background color (BIFF3-BIFF4).
Definition: xlstyle.hxx:207
sal_uInt16 Insert(sal_uInt32 nScNumFmt)
Inserts a number format into the format buffer.
Definition: xestyle.cxx:1356
ScDxfFont maDxfData
Definition: xestyle.hxx:187
ITALIC_OBLIQUE
#define LANGUAGE_SYSTEM
LINESTYLE_DOUBLEWAVE
const sal_uInt8 EXC_LINE_MEDIUM_DASHED
Definition: xlstyle.hxx:45
OUString GetFormatStringForExcel(sal_uInt32 nKey, const NfKeywordTable &rKeywords, SvNumberFormatter &rTempFormatter) const
bool mbPredefined
Level for RowLevel/ColLevel styles.
Definition: xestyle.hxx:680
bool isEmpty() const
Definition: fonthelper.hxx:38
XclExpFillList maFills
List of borders used by XF records.
Definition: xestyle.hxx:720
XclExpPalette & GetPalette() const
Returns the color buffer.
Definition: xeroot.cxx:107
constexpr TypedWhichId< SvxVerJustifyItem > ATTR_VER_JUSTIFY(132)
const sal_uInt32 EXC_XF_DIAGONAL_TL_TO_BR
Definition: xlstyle.hxx:189
void Finalize()
Reduces the XF record list to the maximum allowed number of records.
Definition: xestyle.cxx:2499
Color GetDefColor(sal_uInt16 nXclIndex) const
Returns the default color for a (non-zero-based) Excel color or COL_AUTO on error.
Definition: xlstyle.cxx:142
sax_fastparser::FSHelperPtr CreateOutputStream(const OUString &sFullStream, std::u16string_view sRelativeStream, const css::uno::Reference< css::io::XOutputStream > &xParentRelation, const char *sContentType, std::u16string_view sRelationshipType, OUString *pRelationshipId=nullptr)
Definition: xestream.cxx:944
void SetNumFmt(sal_uInt16 nXclNumFmt)
Sets the Excel number format index.
Definition: xestyle.cxx:2277
const sal_uInt8 EXC_STYLE_LEVELCOUNT
No built-in style.
Definition: xlstyle.hxx:236
bool ScHasPriority(const ::editeng::SvxBorderLine *pThis, const ::editeng::SvxBorderLine *pOther)
General Help Function.
Definition: attrib.cxx:49
const XclFontData & GetAppFontData() const
Returns the application font data of this file, needed e.g.
Definition: xestyle.cxx:1187
Represents an XF record which contains all formatting data of a cell or cell style.
Definition: xestyle.hxx:426
const sal_uInt8 EXC_LINE_DOUBLE
Definition: xlstyle.hxx:43
size_t size() const
Definition: conditio.cxx:2258
bool GetHideFormula() const
Definition: attrib.hxx:145
bool mbLocked
Definition: xlstyle.hxx:478
XclExpNumFmtBuffer & GetNumFmtBuffer() const
Returns the number format buffer.
Definition: xeroot.cxx:119
sal_uInt32 mnHash
Unique color ID for text color.
Definition: xestyle.hxx:176
sal_uInt8 mnHorAlign
Definition: xlstyle.hxx:489
static bool IsCondFormatStyleName(const OUString &rStyleName)
Returns true, if the passed string is a name of a conditional format style created by Excel import...
Definition: xltools.cxx:672
tools::Long GetSpaceWidth() const
Definition: xlroot.hxx:158
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:126
static bool CheckItems(const SfxItemSet &rItemSet, const sal_uInt16 *pnWhichIds, bool bDeep)
Returns true, if the passed item set contains at least one of the items.
Definition: ftools.cxx:204
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
Stores all used colors in the document.
Definition: xestyle.hxx:74
WEIGHT_NORMAL
const sal_uInt8 EXC_XF_DIFF_FONT
Definition: xlstyle.hxx:152
static XclExpCellArea lcl_GetPatternFill_Gray125()
Definition: xestyle.cxx:2952
sal_Int32 mnWeight
void SetRed(sal_uInt8 nRed)
void WriteFormatRecord(XclExpStream &rStrm, sal_uInt16 nXclNumFmt, const OUString &rFormatStr)
Writes the FORMAT record with index nXclIx and format string rFormatStr.
Definition: xestyle.cxx:1394
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
float u
static bool IsBuiltInStyleName(const OUString &rStyleName, sal_uInt8 *pnStyleId=nullptr, sal_Int32 *pnNextChar=nullptr)
Returns true, if the passed string is a name of an Excel built-in style.
Definition: xltools.cxx:577
const sal_uInt8 EXC_XF_DIFF_AREA
Definition: xlstyle.hxx:155
std::unique_ptr< NfKeywordTable > mpKeywordTable
Maps core formats to Excel indexes.
Definition: xestyle.hxx:299
void EndRecord()
Checks and corrects real record length.
Definition: xestream.cxx:122
const sal_uInt16 EXC_STYLE_BUILTIN
Definition: xlstyle.hxx:221
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
const sal_uInt8 EXC_XF_VER_TOP
Definition: xlstyle.hxx:167
MS Excel 3.0.
Definition: xlconst.hxx:33
const sal_uInt16 EXC_ID_STYLE
Font auto color (system window text color).
Definition: xlstyle.hxx:219
size
bool mbLineBreak
Indentation.
Definition: xlstyle.hxx:495
XclListColorListRef mxColorList
The default palette for the current BIFF version.
Definition: xestyle.cxx:302
void SaveXFXml(XclExpXmlStream &rStrm, XclExpXF &rXF)
Definition: xestyle.cxx:2701
XclListColor * CreateListEntry(const Color &rColor, sal_uInt32 nIndex)
Creates and inserts a new color list entry at the specified list position.
Definition: xestyle.cxx:551
sal_uInt32 FindBuiltInXF(sal_uInt8 nStyleId, sal_uInt8 nLevel) const
Returns the XF ID of a built-in style XF, searches by style identifier.
Definition: xestyle.cxx:2778
sal_uInt8 mnLevel
Built-in style identifier.
Definition: xestyle.hxx:679
const sal_uInt8 EXC_XF_HOR_CENTER_AS
Definition: xlstyle.hxx:164
const sal_uInt16 EXC_FORMAT_OFFSET8
Definition: xlstyle.hxx:68
const sal_uInt32 EXC_XF_MAXSTYLECOUNT
Maximum number of all XF records.
Definition: xlstyle.hxx:137
sal_uInt32 InsertColor(const Color &rColor, XclExpColorType eType, sal_uInt16 nAutoDefault=0)
Inserts the color into the list and updates weighting.
Definition: xestyle.cxx:327
std::unique_ptr< XclExpCellAlign > mpAlign
Definition: xestyle.hxx:737
const sal_uInt8 EXC_STYLE_NOLEVEL
Number of outline level styles.
Definition: xlstyle.hxx:237
const sal_uInt8 EXC_XF_HOR_LEFT
Definition: xlstyle.hxx:159
virtual ~XclExpDxf() override
Definition: xestyle.cxx:3230
static const char * ToLineStyle(sal_uInt8 nLineStyle)
Definition: xestyle.cxx:1813
std::optional< const SvxFontItem * > pFontAttr
Definition: fonthelper.hxx:23
constexpr TypedWhichId< ScVerticalStackCell > ATTR_STACKED(134)
void InsertDefaultRecords()
Inserts all default XF and STYLE records.
Definition: xestyle.cxx:2961
#define SV_COUNTRY_LANGUAGE_OFFSET
Line in a chart.
Definition: xestyle.hxx:52
ITALIC_NONE
void FillToCF8(sal_uInt16 &rnPattern, sal_uInt16 &rnColor) const
Fills the data to the passed fields of a BIFF8 CF (conditional format) record.
Definition: xestyle.cxx:1924
const SfxItemSet * mpItemSet
Definition: xestyle.hxx:482
XclExpBorderList maBorders
List of XF records in XF index order.
Definition: xestyle.hxx:719
sal_uInt8 mnPattern
Palette index to background color.
Definition: xlstyle.hxx:547
constexpr TypedWhichId< SvxFontHeightItem > ATTR_CTL_FONT_HEIGHT(117)
virtual bool Equals(const XclFontData &rFontData, sal_uInt32 nHash) const override
Returns always false to never find this font while searching the font list.
Definition: xestyle.cxx:1158
constexpr TypedWhichId< SvxFontItem > ATTR_CTL_FONT(116)
const size_t EXC_FONT_MAXCOUNT5
Definition: xlstyle.hxx:80
sal_uInt32 GetLeastUsedListColor() const
Finds the least used color and returns its current list index.
Definition: xestyle.cxx:654
const sal_uInt16 EXC_BORDER_THIN
Definition: xlconst.hxx:250
virtual ~XclExpPalette() override
Definition: xestyle.cxx:762
std::shared_ptr< FastSerializerHelper > FSHelperPtr
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:300
void AppendNewRecord(RecType *pRec)
Appends a newly created record to the list.
Definition: xerecord.hxx:360
XclExpRecordRef CreateRecord(sal_uInt16 nRecId) const
Returns the reference to a record (or record list) representing a root object.
Definition: xeroot.cxx:282
virtual void Save(XclExpStream &rStrm) override
Skips writing this record.
Definition: xestyle.cxx:1163
LINESTYLE_DONTKNOW
ScfUInt16Vec maCellIndexes
Maps XF IDs to OOXML Style indexes.
Definition: xestyle.hxx:717
sal_uInt8 mnLeftLine
Palette index for diagonal line(s).
Definition: xlstyle.hxx:529
STRIKEOUT_X
void SetScFamily(FontFamily eScFamily)
Sets the Calc font family.
Definition: xlstyle.cxx:313
sal_uInt8 GetUsedFlags() const
Returns the bits specifying the used attributes.
Definition: xestyle.cxx:2159
void Finalize()
Reduces the color list to the maximum count of the current BIFF version.
Definition: xestyle.cxx:776
const sal_uInt16 EXC_ID4_FORMAT
Definition: xlstyle.hxx:65
const sal_uInt8 EXC_XF_DIFF_BORDER
Definition: xlstyle.hxx:154
sal_Int16 GetDefApiScript() const
Returns the default script type, e.g.
Definition: xlroot.hxx:155
SCCOL Col() const
Definition: address.hxx:266
void FillToCF8(sal_uInt16 &rnLine, sal_uInt32 &rnColor) const
Fills the data to the passed fields of a BIFF8 CF (conditional format) record.
Definition: xestyle.cxx:1801
sal_uInt8 mnLevel
Built-in style identifier.
Definition: xestyle.hxx:556
const sal_uInt8 EXC_STYLE_COLLEVEL
"RowLevel_*" styles.
Definition: xlstyle.hxx:226
const XclExpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xeroot.hxx:118
void SaveXml(XclExpXmlStream &rStrm)
Definition: xestyle.cxx:1328
sal_uInt8 mnTextDir
Text orientation.
Definition: xlstyle.hxx:492
const sal_uInt16 EXC_ID_XFLIST
For internal use only.
Definition: xestyle.hxx:39
const sal_uInt8 EXC_STYLE_NORMAL
Definition: xlstyle.hxx:224
SC_DLLPUBLIC void GetFilterEntriesArea(SCCOL nCol, SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bCaseSens, ScFilterEntries &rFilterEntries)
Entries for Filter dialog.
Definition: documen3.cxx:1611
bool FillFromItemSet(const SfxItemSet &rItemSet, XclExpPalette &rPalette, XclBiff eBiff, bool bStyle=false)
Fills the border attributes from the passed item set.
Definition: xestyle.cxx:1706
Stores a core number format index with corresponding Excel format index.
Definition: xestyle.hxx:253
void WriteBody8(XclExpStream &rStrm)
Definition: xestyle.cxx:2190
bool IsBuiltIn() const
Returns true, if this record represents an Excel built-in style.
Definition: xestyle.hxx:544
sal_uInt32 InsertWithNumFmt(const ScPatternAttr *pPattern, sal_Int16 nScript, sal_uInt32 nForceScNumFmt, bool bForceLineBreak)
Finds or creates a cell XF record for the passed item set, with custom number format.
Definition: xestyle.cxx:2474
sal_uInt16 mnXclNumFmt
Core index of the number format.
Definition: xestyle.hxx:256
const sal_uInt32 EXC_XFID_NOTFOUND
Special index for "not found" state.
Definition: xlstyle.hxx:142
sal_uInt16 mnParent
Definition: xlstyle.hxx:588
constexpr TypedWhichId< SvxFontItem > ATTR_CJK_FONT(111)
static void lcl_WriteBorder(XclExpXmlStream &rStrm, sal_Int32 nElement, sal_uInt8 nLineStyle, const Color &rColor)
Definition: xestyle.cxx:1835
virtual void WriteBody(XclExpStream &rStrm) override
Writes the contents of the XF record.
Definition: xestyle.cxx:2207
tools::Long const nBorder
Default string settings.
FAMILY_SYSTEM
Extends the XclCellProt struct for export.
Definition: xestyle.hxx:308
constexpr TypedWhichId< SvxBrushItem > ATTR_BACKGROUND(148)
bool FillFromItemSet(const SfxItemSet &rItemSet)
Definition: xestyle.cxx:2002
bool CheckItems(const XclExpRoot &rRoot, const SfxItemSet &rItemSet, sal_Int16 nScript, bool bDeep)
Returns true, if at least one font related item is set in the passed item set.
Definition: xestyle.cxx:907
XclExpXFList maSortedXFList
Maps XF IDs to OOXML Cell indexes.
Definition: xestyle.hxx:718
bool FillFromItemSet(const XclRoot &rRoot, const SfxItemSet &rItemSet, bool bForceLineBreak, XclBiff eBiff, bool bStyle=false)
Fills the alignment attributes from the passed item set.
Definition: xestyle.cxx:1449
sal_uInt8 GetGreen() const
bool IsDefaultPalette() const
Returns true, if all colors of the palette are equal to default palette colors.
Definition: xestyle.cxx:469
const sal_uInt16 EXC_COLOR_FONTAUTO
Note text color.
Definition: xlstyle.hxx:215
const sal_uInt8 EXC_STYLE_CURRENCY_0
"Comma [0]" style.
Definition: xlstyle.hxx:231
FontFamily
sal_uInt32 mnRightColorId
Color ID for left line.
Definition: xestyle.hxx:344
const sal_uInt16 EXC_FONTATTR_STRIKEOUT
Definition: xlstyle.hxx:100
RecType * GetRecord(size_t nPos) const
Returns reference to an existing record or empty reference on error.
Definition: xerecord.hxx:332
static sal_uInt32 GetDefCellXFId()
Returns the XF identifier representing the default cell XF.
Definition: xestyle.cxx:2489
void Initialize()
Inserts predefined built-in styles and user-defined styles.
Definition: xestyle.cxx:2457
constexpr TypedWhichId< SvxFrameDirectionItem > ATTR_WRITINGDIR(138)
virtual SfxStyleSheetBase * Next()
sal_Int32 mnFillId
OOXML Border Index.
Definition: xestyle.hxx:493
std::optional< FontStrikeout > eStrike
Definition: fonthelper.hxx:30
std::unique_ptr< XclExpColor > mpColor
Definition: xestyle.hxx:742
XclExpBuiltInInfo()
true = STYLE record created.
Definition: xestyle.cxx:2387
::std::vector< sal_uInt32 > ScfUInt32Vec
Definition: ftools.hxx:257
const XclExpCellAlign & GetAlignmentData() const
Returns the alignment settings of this XF.
Definition: xestyle.hxx:445
void SetRecHeader(sal_uInt16 nRecId, std::size_t nRecSize)
Sets record ID and size with one call.
Definition: xerecord.cxx:140
sal_uInt8 mnBottomLine
Style of top line.
Definition: xlstyle.hxx:532
const sal_uInt16 EXC_XF_STYLE
Definition: xlstyle.hxx:146
std::map< FindKey, std::vector< sal_uInt32 > > maXFFindMap
List of all XF records.
Definition: xestyle.hxx:711
void SetScHeight(sal_Int32 nTwips)
Sets the Calc font height (in twips).
Definition: xlstyle.cxx:308
const sal_uInt16 EXC_ID_PALETTE
Definition: xlstyle.hxx:199
const editeng::SvxBorderLine * GetLine() const
constexpr TypedWhichId< SvxJustifyMethodItem > ATTR_VER_JUSTIFY_METHOD(133)
constexpr TypedWhichId< SvxPostureItem > ATTR_CTL_FONT_POSTURE(119)
XclListColor * SearchListEntry(const Color &rColor, sal_uInt32 &rnIndex)
Searches for rColor, returns the ordered insertion index for rColor in rnIndex.
Definition: xestyle.cxx:505
static const char * ToHorizontalAlignment(sal_uInt8 nHorAlign)
Definition: xestyle.cxx:1566
const sal_uInt8 EXC_XF_VER_BOTTOM
Definition: xlstyle.hxx:169
const sal_uInt16 EXC_FONTATTR_OUTLINE
Definition: xlstyle.hxx:101
const sal_uInt16 EXC_FONTATTR_SHADOW
Definition: xlstyle.hxx:102
Represents a STYLE record containing the data of a cell style.
Definition: xestyle.hxx:537
void SetScPosture(FontItalic eScPosture)
Sets the Calc font posture.
Definition: xlstyle.cxx:336
const sal_uInt8 EXC_PATT_SOLID
Definition: xlstyle.hxx:55
void SetFinalColors(const XclExpPalette &rPalette)
Fills the mn***Color base members from the mn***ColorId members.
Definition: xestyle.cxx:1764
STRIKEOUT_DOUBLE
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
Color maColor
Definition: xestyle.hxx:403
const sal_uInt8 EXC_LINE_MEDIUM_DASHDOT
Definition: xlstyle.hxx:47
const sal_uInt8 EXC_LINE_NONE
Definition: xlstyle.hxx:37
ITALIC_NORMAL
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:3195
size_t Find(const XclFontData &rFontData)
Tries to find the passed font and returns the current list index.
Definition: xestyle.cxx:1304
unsigned char sal_uInt8
void SaveXml(XclExpXmlStream &rStrm)
Definition: xestyle.cxx:484
void FillToXF8(sal_uInt32 &rnBorder2, sal_uInt16 &rnArea) const
Fills the data to the passed fields of a BIFF8 XF record.
Definition: xestyle.cxx:1917
void AssignByte(std::u16string_view rString, rtl_TextEncoding eTextEnc, XclStrFlags nFlags=XclStrFlags::NONE, sal_uInt16 nMaxLen=EXC_STR_MAXLEN)
Assigns an unformatted string, converts this object to a BIFF2-BIFF7 byte string. ...
Definition: xestring.cxx:121
const OUString & GetStyleName() const
Definition: conditio.hxx:514
std::size_t GetSize() const
Returns the byte count the whole string will take on export.
Definition: xestring.cxx:249
void FillToXF8(sal_uInt32 &rnBorder1, sal_uInt32 &rnBorder2) const
Fills the data to the passed fields of a BIFF8 XF record.
Definition: xestyle.cxx:1785
sal_uInt32 mnXFId
Definition: xestyle.hxx:413
static sal_uInt16 GetXclIndex(sal_uInt32 nIndex)
Returns the Excel index of a 0-based color index.
Definition: xestyle.cxx:260
sal_uInt8 mnFamily
Escapement type.
Definition: xlstyle.hxx:293
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:804
XclExpStyle(sal_uInt32 nXFId, const OUString &rStyleName)
Definition: xestyle.cxx:2283
bool GetProtection() const
Definition: attrib.hxx:143
const sal_uInt8 EXC_PATT_50_PERC
Definition: xlstyle.hxx:56
void SetGreen(sal_uInt8 nGreen)
sal_uInt16 mnXclOffset
Key for standard number format.
Definition: xestyle.hxx:301
XclExpDefaultXF(const XclExpRoot &rRoot, bool bCellXF)
Definition: xestyle.cxx:2266
OUString maName
std::optional< sal_uInt32 > nFontHeight
Definition: fonthelper.hxx:24
FAMILY_SWISS
constexpr TypedWhichId< SvxPostureItem > ATTR_CJK_FONT_POSTURE(114)
Always use UCS-2 characters (default: try to compress). BIFF8 only.
const sal_uInt16 EXC_FORMAT_OFFSET5
Definition: xlstyle.hxx:67
DxfContainer maDxf
Definition: xestyle.hxx:759
sal_uInt16 mnWeight
Font height in twips (1/20 of a point).
Definition: xlstyle.hxx:291
Color GetColor(sal_uInt16 nXclIndex) const
Returns the RGB color for a (non-zero-based) Excel palette entry.
Definition: xestyle.cxx:458
const sal_uInt8 EXC_LINE_MEDIUM
Definition: xlstyle.hxx:39
void SaveXml(XclExpXmlStream &rStrm) const
Definition: xestyle.cxx:2013
std::vector< std::unique_ptr< XclListColor > > XclListColorList
Definition: xestyle.cxx:298
A combination of unique XF identifier with real Excel XF index.
Definition: xestyle.hxx:411
XclExpCellProt maProtection
Pointer to the item set (we do not own it).
Definition: xestyle.hxx:484
static sal_uInt32 GetColorIdFromIndex(sal_uInt16 nIndex)
Returns the color ID representing a fixed Excel palette index (i.e.
Definition: xestyle.cxx:341
constexpr TypedWhichId< SvxWeightItem > ATTR_FONT_WEIGHT(102)
sal_Int32 mnBorderId
Excel number format index.
Definition: xestyle.hxx:492
constexpr TypedWhichId< SvxHorJustifyItem > ATTR_HOR_JUSTIFY(129)
XclExpPaletteImpl(const XclDefaultPalette &rDefPal)
Definition: xestyle.cxx:313
sal_uInt32 mnBackColorId
Foreground color ID.
Definition: xestyle.hxx:375
sal_uInt32 Insert(const ScPatternAttr *pPattern, sal_Int16 nScript)
Finds or creates a cell XF record for the passed item set.
Definition: xestyle.cxx:2463
Used as placeholder for font index 4, which is not used in Excel.
Definition: xestyle.hxx:191
void insert_value(Type &rnBitField, InsertType nValue, sal_uInt8 nStartBit, sal_uInt8 nBitCount)
Inserts a value into a bitfield.
Definition: ftools.hxx:102
void SetFontEncoding(rtl_TextEncoding eFontEnc)
Sets the font text encoding.
Definition: xlstyle.cxx:330
Reference< XComponentContext > getProcessComponentContext()
Contains background colors and pattern for a cell.
Definition: xlstyle.hxx:543
Extended info about a built-in XF.
Definition: xestyle.hxx:676
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
sal_uInt8 mnIndent
Text rotation angle.
Definition: xlstyle.hxx:494
SvNumberFormatterPtr mxFormatter
Definition: xestyle.hxx:297
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
Definition: document.cxx:6082
sal_uInt16 mnXFIndex
Temporary XF identifier.
Definition: xestyle.hxx:414
virtual void WriteBody(XclExpStream &rStrm) override
Writes the contents of the PALETTE record.
Definition: xestyle.cxx:810
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Definition: xlroot.hxx:141
bool mbHidden
true = Locked against editing.
Definition: xlstyle.hxx:479
XclExpRecordList< XclExpStyle > maStyleList
map of itemset to vector of positions, to speed up find
Definition: xestyle.hxx:713
const sal_uInt32 EXC_XF_DIAGONAL_BL_TO_TR
Top-left to bottom-right.
Definition: xlstyle.hxx:190
const sal_uInt16 EXC_COLOR_WINDOWBACK
System window text color (>=BIFF5).
Definition: xlstyle.hxx:208
std::shared_ptr< XclListColorList > XclListColorListRef
Definition: xestyle.cxx:299
bool Equals(const XclXFBase &rCmp) const
Returns true, if this object is equal to the passed.
Definition: xlstyle.cxx:1737
bool mbProtUsed
true = cell XF, false = style XF.
Definition: xlstyle.hxx:590
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6092
SvxBoxItem & rBoxItem
const sal_uInt16 EXC_ID2_FONT
Definition: xlstyle.hxx:73
void WriteBody5(XclExpStream &rStrm)
Definition: xestyle.cxx:2173
const XclDefaultPalette & mrDefPal
Definition: xestyle.cxx:301
sal_Int32 GetNearPaletteColors(sal_uInt32 &rnFirst, sal_uInt32 &rnSecond, const Color &rColor) const
Returns in rnFirst and rnSecond the palette indexes of the two colors nearest to rColor.
Definition: xestyle.cxx:726
size_t GetSize() const
Definition: xerecord.hxx:326
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:2226
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:979
sal_Int32 GetXmlStyleIndex(sal_uInt32 nXFId) const
Definition: xestyle.cxx:2606
Text color in a chart.
Definition: xestyle.hxx:51
void StartRecord(sal_uInt16 nRecId, std::size_t nRecSize)
Starts a new record: writes header data, stores calculated record size.
Definition: xestream.cxx:110
const sal_uInt16 EXC_ID_FORMATLIST
For internal use only.
Definition: xestyle.hxx:38
std::vector< XclColorIdData > maColorIdDataVec
Working color list.
Definition: xestyle.cxx:304
virtual Type GetType() const =0
const sal_uInt16 EXC_FONTATTR_NONE
Definition: xlstyle.hxx:96
const sal_uInt8 EXC_PATT_NONE
Definition: xlstyle.hxx:54
const sal_uInt8 EXC_XF_VER_DISTRIB
Definition: xlstyle.hxx:171
void SetScHorAlign(SvxCellHorJustify eHorJust)
Sets the Calc horizontal alignment.
Definition: xlstyle.cxx:1614
void SaveXmlExt(XclExpXmlStream &rStrm)
Definition: xestyle.cxx:3256
const sal_uInt8 EXC_LINE_THIN_DASHDOT
Definition: xlstyle.hxx:46
sal_uInt8 mnStyleId
XF identifier for style formatting.
Definition: xestyle.hxx:555
void Finalize()
Reduces the color list to the maximum count of the current BIFF version.
Definition: xestyle.cxx:346
const sal_uInt16 EXC_ID5_XF
Definition: xlstyle.hxx:134
Color maColor
String with styles (bold, italic).
Definition: xlstyle.hxx:289
sal_uInt8 mnRotation
CTL text direction.
Definition: xlstyle.hxx:493
std::unique_ptr< XclExpCellArea > mpCellArea
Definition: xestyle.hxx:743
SvxCellJustifyMethod
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:3234
const sal_uInt16 EXC_XF8_SHRINK
Definition: xlstyle.hxx:186
LINESTYLE_DOUBLE
MS Excel 2.1.
Definition: xlconst.hxx:32
XclExpBlindFont(const XclExpRoot &rRoot)
Definition: xestyle.cxx:1153
const sal_uInt16 EXC_XF_HIDDEN
Definition: xlstyle.hxx:145
const XclExpRoot & GetRoot() const
Returns the filter root data.
Definition: xestream.hxx:87
static const char * ToPatternType(sal_uInt8 nPattern)
Definition: xestyle.cxx:1936
int mnIndex
const sal_uInt8 EXC_LINE_THICK
Definition: xlstyle.hxx:42
bool mbBorderUsed
true = alignment used.
Definition: xlstyle.hxx:594
void ReduceLeastUsedColor()
Reduction of one color using advanced color merging based on color weighting.
Definition: xestyle.cxx:623
static void lcl_GetCellCounts(const XclExpRecordList< XclExpXF > &rXFList, sal_Int32 &rCells, sal_Int32 &rStyles)
Definition: xestyle.cxx:2630
FontLineStyle
Area in a chart.
Definition: xestyle.hxx:53
OUString maName
Definition: xestyle.hxx:553
bool IsEmpty() const
Definition: xerecord.hxx:325
virtual void Save(XclExpStream &rStrm) override
Writes the record header and calls WriteBody().
Definition: xerecord.cxx:150
static sal_uInt32 GetColorIdFromIndex(sal_uInt16 nIndex)
Returns the color ID representing a fixed Excel palette index (i.e.
Definition: xestyle.cxx:771
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
void SvStream & rStrm
XclExpXFBuffer & GetXFBuffer() const
Returns the cell formatting attributes buffer.
Definition: xeroot.cxx:125
sal_Int32 GetDxfId(const OUString &rName)
Definition: xestyle.cxx:3179
bool mbStrikeout
true = Italic.
Definition: xlstyle.hxx:297
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
const char * UseIf(const char *s, bool bUse)
constexpr TypedWhichId< SvxColorItem > ATTR_FONT_COLOR(109)
XclExpFontBuffer & GetFontBuffer() const
Returns the font buffer.
Definition: xeroot.cxx:113
ScDxfFont GetDxfFontFromItemSet(const XclExpRoot &rRoot, const SfxItemSet &rSet)
Get a dxf related font object from the item set.
Definition: xestyle.cxx:898
static rtl_TextEncoding GetSystemTextEncoding()
Returns system text encoding for byte string conversion.
Definition: ftools.cxx:115
Access to global data for a filter object (imported or exported document) from other classes...
Definition: xlroot.hxx:127
constexpr TypedWhichId< SvxWeightItem > ATTR_CJK_FONT_WEIGHT(113)
std::optional< FontWeight > eWeight
Definition: fonthelper.hxx:25
void InitDefault()
Initializes with default values.
Definition: xestyle.cxx:2099
constexpr TypedWhichId< SvxFontHeightItem > ATTR_FONT_HEIGHT(101)
Color GetColor(sal_uInt16 nXclIndex) const
Returns the color for a (non-zero-based) Excel palette entry.
Definition: xestyle.cxx:793
Contains base members for XF record import/export.
Definition: xlstyle.hxx:562
virtual void SaveXml(XclExpXmlStream &rStrm) override
Definition: xestyle.cxx:2341
const sal_uInt16 EXC_XF_DEFAULTSTYLE
Arbitrary maximum number of style XFs.
Definition: xlstyle.hxx:138
void SetFont(sal_uInt16 nXclFont)
Sets the Excel font index.
Definition: xestyle.cxx:2271
const sal_uInt8 EXC_STYLE_COMMA
"ColLevel_*" styles.
Definition: xlstyle.hxx:227
const editeng::SvxBorderLine * GetBottom() const
constexpr TypedWhichId< SvxLineItem > ATTR_BORDER_BLTR(142)
constexpr TypedWhichId< SvxContourItem > ATTR_FONT_CONTOUR(107)
void AddBorderAndFill(const XclExpXF &rXF)
Definition: xestyle.cxx:3036
std::optional< vcl::Font > mpFont
std::optional< FontLineStyle > eUnder
Definition: fonthelper.hxx:27
Color maBackColor
Definition: xestyle.hxx:377
static XclExpCellArea lcl_GetPatternFill_None()
Definition: xestyle.cxx:2945
STRIKEOUT_BOLD
sal_uInt32 InsertWithFont(const ScPatternAttr *pPattern, sal_Int16 nScript, sal_uInt16 nForceXclFont, bool bForceLineBreak)
Finds or creates a cell XF record for the passed item set.
Definition: xestyle.cxx:2468
XclExpDxfs(const XclExpRoot &rRoot)
Definition: xestyle.cxx:3049
Base class for single records with any content.
Definition: xerecord.hxx:141
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:22
Text color in a form control.
Definition: xestyle.hxx:54
XclExpCellBorder maBorder
All alignment attributes.
Definition: xestyle.hxx:486
void AppendXFIndex(sal_uInt32 nXFId)
Appends a XF index to the internal ID<->index maps.
Definition: xestyle.cxx:3026
OUString maName
Definition: xlstyle.hxx:287
sal_Int16 GetFirstUsedScript(const XclExpRoot &rRoot, const SfxItemSet &rItemSet)
Returns the script type of the first font item found in the item set and its parents.
Definition: xestyle.cxx:832
sal_uInt16 GetXFIndex(sal_uInt32 nXFId) const
Returns the Excel XF index of the XF record with passed XF ID.
Definition: xestyle.cxx:2596
static ScDxfFont GetDxfFont(const SfxItemSet &rSet, SvtScriptType nScript)
Definition: patattr.cxx:457
XclExpDxfFont(const XclExpRoot &rRoot, const SfxItemSet &rItemSet)
Definition: xestyle.cxx:1019
XclExpXF(const XclExpRoot &rRoot, const ScPatternAttr &rPattern, sal_Int16 nScript, sal_uInt32 nScForceNumFmt=NUMBERFORMAT_ENTRY_NOT_FOUND, sal_uInt16 nForceXclFont=EXC_FONT_NOTFOUND, bool bForceLineBreak=false)
Constructs a cell XF record from the passed Calc cell formatting.
Definition: xestyle.cxx:2041
const sal_uInt16 EXC_BORDER_MEDIUM
Definition: xlconst.hxx:249
std::unique_ptr< XclExpCellBorder > mpBorder
Definition: xestyle.hxx:738