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