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