LibreOffice Module svx (master)  1
nbdtmg.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 #include <svx/nbdtmg.hxx>
20 #include <svx/svxids.hrc>
21 #include <vcl/svapp.hxx>
22 #include <svl/itemset.hxx>
23 #include <sfx2/request.hxx>
24 #include <svl/stritem.hxx>
25 #include <svtools/ctrltool.hxx>
26 #include <sfx2/objsh.hxx>
27 #include <editeng/flstitem.hxx>
28 #include <svl/itempool.hxx>
29 #include <vcl/outdev.hxx>
30 #include <editeng/brushitem.hxx>
31 #include <svx/dialmgr.hxx>
32 #include <svx/strings.hrc>
33 #include <vcl/graph.hxx>
34 #include <vcl/settings.hxx>
35 
37 #include <o3tl/temporary.hxx>
38 #include <tools/debug.hxx>
39 #include <tools/urlobj.hxx>
41 #include <unotools/pathoptions.hxx>
42 #include <editeng/eeitem.hxx>
43 
44 #include <com/sun/star/text/VertOrientation.hpp>
45 #include <com/sun/star/style/NumberingType.hpp>
46 #include <com/sun/star/container/XIndexAccess.hpp>
47 #include <com/sun/star/text/DefaultNumberingProvider.hpp>
48 #include <com/sun/star/beans/PropertyValue.hpp>
50 #include <memory>
51 
52 using namespace com::sun::star;
53 using namespace com::sun::star::uno;
54 using namespace com::sun::star::beans;
55 using namespace com::sun::star::lang;
56 using namespace com::sun::star::text;
57 using namespace com::sun::star::container;
58 using namespace com::sun::star::style;
59 
60 namespace svx::sidebar {
61 
62 namespace {
63 
65 {
66  static vcl::Font aDefBulletFont = []()
67  {
68  static vcl::Font tmp("OpenSymbol", "", Size(0, 14));
69  tmp.SetCharSet( RTL_TEXTENCODING_SYMBOL );
70  tmp.SetFamily( FAMILY_DONTKNOW );
71  tmp.SetPitch( PITCH_DONTKNOW );
72  tmp.SetWeight( WEIGHT_DONTKNOW );
73  tmp.SetTransparent( true );
74  return tmp;
75  }();
76  return aDefBulletFont;
77 }
78 
79 const sal_Unicode aDefaultBulletTypes[] =
80 {
81  0x2022,
82  0x25cf,
83  0xe00c,
84  0xe00a,
85  0x2794,
86  0x27a2,
87  0x2717,
88  0x2714
89 };
90 
91 NumSettings_Impl* lcl_CreateNumberingSettingsPtr(const Sequence<PropertyValue>& rLevelProps)
92 {
93  NumSettings_Impl* pNew = new NumSettings_Impl;
94  for(const PropertyValue& rValue : rLevelProps)
95  {
96  if(rValue.Name == "NumberingType")
97  {
98  sal_Int16 nTmp;
99  if (rValue.Value >>= nTmp)
100  pNew->nNumberType = static_cast<SvxNumType>(nTmp);
101  }
102  else if(rValue.Name == "Prefix")
103  rValue.Value >>= pNew->sPrefix;
104  else if(rValue.Name == "Suffix")
105  rValue.Value >>= pNew->sSuffix;
106  else if(rValue.Name == "ParentNumbering")
107  rValue.Value >>= pNew->nParentNumbering;
108  else if(rValue.Name == "BulletChar")
109  rValue.Value >>= pNew->sBulletChar;
110  else if(rValue.Name == "BulletFontName")
111  rValue.Value >>= pNew->sBulletFont;
112  }
113  const sal_Unicode cLocalPrefix = pNew->sPrefix.getLength() ? pNew->sPrefix[0] : 0;
114  const sal_Unicode cLocalSuffix = pNew->sSuffix.getLength() ? pNew->sSuffix[0] : 0;
115  if( cLocalPrefix == ' ') pNew->sPrefix.clear();
116  if( cLocalSuffix == ' ') pNew->sSuffix.clear();
117  return pNew;
118 }
119 
120 }
121 
122 sal_uInt16 NBOTypeMgrBase:: IsSingleLevel(sal_uInt16 nCurLevel)
123 {
124  sal_uInt16 nLv = sal_uInt16(0xFFFF);
125  sal_uInt16 nCount = 0;
126  sal_uInt16 nMask = 1;
127  for( sal_uInt16 i = 0; i < SVX_MAX_NUM; i++ )
128  {
129  if(nCurLevel & nMask)
130  {
131  nCount++;
132  nLv=i;
133  }
134  nMask <<= 1 ;
135  }
136 
137  if ( nCount == 1)
138  return nLv;
139  else
140  return sal_uInt16(0xFFFF);
141 }
142 
143 void NBOTypeMgrBase::SetItems(const SfxItemSet* pArg) {
144  pSet = pArg;
145  if ( !pSet )
146  return;
147 
148  SfxAllItemSet aSet(*pSet);
149 
150  const SfxStringItem* pBulletCharFmt = aSet.GetItem<SfxStringItem>(SID_BULLET_CHAR_FMT, false);
151  if (pBulletCharFmt)
152  aBulletCharFmtName = pBulletCharFmt->GetValue();
153 
154  const SfxStringItem* pNumCharFmt = aSet.GetItem<SfxStringItem>(SID_NUM_CHAR_FMT, false);
155  if (pNumCharFmt)
156  aNumCharFmtName = pNumCharFmt->GetValue();
157 
158  const SfxPoolItem* pItem;
159  SfxItemState eState = pSet->GetItemState(SID_ATTR_NUMBERING_RULE, false, &pItem);
160  if(eState == SfxItemState::SET)
161  {
162  eCoreUnit = pSet->GetPool()->GetMetric(pSet->GetPool()->GetWhich(SID_ATTR_NUMBERING_RULE));
163  } else {
164  //sd use different sid for numbering rule
165  eState = pSet->GetItemState(EE_PARA_NUMBULLET, false, &pItem);
166  if(eState == SfxItemState::SET)
167  {
168  eCoreUnit = pSet->GetPool()->GetMetric(pSet->GetPool()->GetWhich(EE_PARA_NUMBULLET));
169  }
170  }
171 }
172 
173 void NBOTypeMgrBase::ImplLoad(std::u16string_view filename)
174 {
175  bIsLoading = true;
176  MapUnit eOldCoreUnit=eCoreUnit;
177  eCoreUnit = MapUnit::Map100thMM;
178  INetURLObject aFile( SvtPathOptions().GetUserConfigPath() );
179  aFile.Append( filename);
180  std::unique_ptr<SvStream> xIStm(::utl::UcbStreamHelper::CreateStream( aFile.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
181  if( xIStm ) {
182  sal_uInt32 nVersion = 0;
183  sal_Int32 nNumIndex = 0;
184  xIStm->ReadUInt32( nVersion );
185  if (nVersion==DEFAULT_NUMBERING_CACHE_FORMAT_VERSION) //first version
186  {
187  xIStm->ReadInt32( nNumIndex );
188  while (nNumIndex>=0 && nNumIndex<DEFAULT_NUM_VALUSET_COUNT) {
189  SvxNumRule aNum(*xIStm);
190  //bullet color in font properties is not stored correctly. Need set transparency bits manually
191  for(sal_uInt16 i = 0; i < aNum.GetLevelCount(); i++)
192  {
193  SvxNumberFormat aFmt(aNum.GetLevel(i));
194  if (aFmt.GetBulletFont()) {
195  vcl::Font aFont(*aFmt.GetBulletFont());
196  Color c=aFont.GetColor();
197  c.SetAlpha(0);
198  aFont.SetColor(c);
199  aFmt.SetBulletFont(&aFont);
200  aNum.SetLevel(i, aFmt);
201  }
202  }
203  RelplaceNumRule(aNum,nNumIndex,0x1/*nLevel*/);
204  xIStm->ReadInt32( nNumIndex );
205  }
206  }
207  }
208  eCoreUnit = eOldCoreUnit;
209  bIsLoading = false;
210 }
211 void NBOTypeMgrBase::ImplStore(std::u16string_view filename)
212 {
213  if (bIsLoading) return;
214  MapUnit eOldCoreUnit=eCoreUnit;
215  eCoreUnit = MapUnit::Map100thMM;
216  INetURLObject aFile( SvtPathOptions().GetUserConfigPath() );
217  aFile.Append( filename);
218  std::unique_ptr<SvStream> xOStm(::utl::UcbStreamHelper::CreateStream( aFile.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE ));
219  if( xOStm ) {
220  sal_uInt32 nVersion;
221  sal_Int32 nNumIndex;
223  xOStm->WriteUInt32( nVersion );
224  for(sal_Int32 nItem = 0; nItem < DEFAULT_NUM_VALUSET_COUNT; nItem++ ) {
225  if (IsCustomized(nItem)) {
226  SvxNumRule aDefNumRule( SvxNumRuleFlags::BULLET_REL_SIZE | SvxNumRuleFlags::CONTINUOUS | SvxNumRuleFlags::BULLET_COLOR,
227  10, false,
228  SvxNumRuleType::NUMBERING, SvxNumberFormat::LABEL_ALIGNMENT);
229  xOStm->WriteInt32( nItem );
230  ApplyNumRule(aDefNumRule,nItem,0x1/*nLevel*/,false,true);
231  aDefNumRule.Store(*xOStm);
232  }
233  }
234  nNumIndex = -1;
235  xOStm->WriteInt32( nNumIndex ); //write end flag
236  }
237  eCoreUnit = eOldCoreUnit;
238 }
239 
240 // Character Bullet Type lib
241 BulletsSettings* BulletsTypeMgr::pActualBullets[] ={nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr};
242 sal_Unicode BulletsTypeMgr::aDynamicBulletTypes[]={' ',' ',' ',' ',' ',' ',' ',' '};
243 sal_Unicode BulletsTypeMgr::aDynamicRTLBulletTypes[]={' ',' ',' ',' ',' ',' ',' ',' '};
244 
245 BulletsTypeMgr::BulletsTypeMgr()
246 {
247  Init();
248 }
249 
250 BulletsTypeMgr& BulletsTypeMgr::GetInstance()
251 {
252  static BulletsTypeMgr theBulletsTypeMgr;
253  return theBulletsTypeMgr;
254 }
255 
256 void BulletsTypeMgr::Init()
257 {
258  const vcl::Font& rActBulletFont = lcl_GetDefaultBulletFont();
259 
260  for (sal_uInt16 i=0;i<DEFAULT_BULLET_TYPES;i++)
261  {
262  pActualBullets[i] = new BulletsSettings;
263  pActualBullets[i]->cBulletChar = aDefaultBulletTypes[i];
264  pActualBullets[i]->aFont = rActBulletFont;
265  OString id = OString::Concat(RID_SVXSTR_BULLET_DESCRIPTION_0.mpId) + OString::number(i);
266  pActualBullets[i]->sDescription = SvxResId( TranslateId(RID_SVXSTR_BULLET_DESCRIPTION_0.mpContext, id.getStr()) );
267  }
268 }
269 sal_uInt16 BulletsTypeMgr::GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex)
270 {
271  if ( mLevel == sal_uInt16(0xFFFF) || mLevel == 0)
272  return sal_uInt16(0xFFFF);
273  //if ( !lcl_IsNumFmtSet(pNR, mLevel) ) return (sal_uInt16)0xFFFF;
274 
275  sal_uInt16 nActLv = IsSingleLevel(mLevel);
276 
277  if ( nActLv == sal_uInt16(0xFFFF) )
278  return sal_uInt16(0xFFFF);
279 
280  const SvxNumberFormat& aFmt(aNum.GetLevel(nActLv));
281  sal_UCS4 cChar = aFmt.GetBulletChar();
282  for(sal_uInt16 i = nFromIndex; i < DEFAULT_BULLET_TYPES; i++)
283  {
284  if ( (cChar == pActualBullets[i]->cBulletChar) ||
285  (cChar == 9830 && 57356 == pActualBullets[i]->cBulletChar) ||
286  (cChar == 9632 && 57354 == pActualBullets[i]->cBulletChar) )
287  {
288  return i+1;
289  }
290  }
291 
292  return sal_uInt16(0xFFFF);
293 }
294 
295 void BulletsTypeMgr::RelplaceNumRule(SvxNumRule& aNum, sal_uInt16 nIndex, sal_uInt16 mLevel)
296 {
297  if ( mLevel == sal_uInt16(0xFFFF) || mLevel == 0)
298  return;
299 
300  if ( GetNBOIndexForNumRule(aNum,mLevel) != sal_uInt16(0xFFFF) )
301  return;
302 
303  sal_uInt16 nActLv = IsSingleLevel(mLevel);
304 
305  if ( nActLv == sal_uInt16(0xFFFF) )
306  return;
307 
308  SvxNumberFormat aFmt(aNum.GetLevel(nActLv));
309  sal_UCS4 cChar = aFmt.GetBulletChar();
310  std::optional<vcl::Font> pFont = aFmt.GetBulletFont();
311  if ( nIndex >= DEFAULT_BULLET_TYPES )
312  return;
313 
314  pActualBullets[nIndex]->cBulletChar = cChar;
315  if ( pFont )
316  pActualBullets[nIndex]->aFont = *pFont;
317  pActualBullets[nIndex]->bIsCustomized = true;
318 }
319 
320 void BulletsTypeMgr::ApplyNumRule(SvxNumRule& aNum, sal_uInt16 nIndex, sal_uInt16 mLevel, bool /*isDefault*/, bool isResetSize)
321 {
322  if ( nIndex >= DEFAULT_BULLET_TYPES )
323  return;
324  sal_UCS4 cChar = pActualBullets[nIndex]->cBulletChar;
325  const vcl::Font& rActBulletFont = pActualBullets[nIndex]->aFont;
326 
327  sal_uInt16 nMask = 1;
328  OUString sBulletCharFormatName = GetBulletCharFmtName();
329  for(sal_uInt16 i = 0; i < aNum.GetLevelCount(); i++)
330  {
331  if(mLevel & nMask)
332  {
333  SvxNumberFormat aFmt(aNum.GetLevel(i));
335  aFmt.SetBulletFont(&rActBulletFont);
336  aFmt.SetBulletChar(cChar);
337  aFmt.SetCharFormatName(sBulletCharFormatName);
338  aFmt.SetListFormat( "" );
339  if (isResetSize) aFmt.SetBulletRelSize(45);
340  aNum.SetLevel(i, aFmt);
341  }
342  nMask <<= 1;
343  }
344 }
345 
346 OUString BulletsTypeMgr::GetDescription(sal_uInt16 nIndex, bool /*isDefault*/)
347 {
348  OUString sRet;
349 
350  if ( nIndex >= DEFAULT_BULLET_TYPES )
351  return sRet;
352  else
353  sRet = pActualBullets[nIndex]->sDescription;
354 
355  return sRet;
356 }
357 
358 bool BulletsTypeMgr::IsCustomized(sal_uInt16 nIndex)
359 {
360  bool bRet = false;
361 
362  if ( nIndex >= DEFAULT_BULLET_TYPES )
363  bRet = false;
364  else
365  bRet = pActualBullets[nIndex]->bIsCustomized;
366 
367  return bRet;
368 }
369 
370 // Numbering Type lib
371 NumberingTypeMgr::NumberingTypeMgr()
372 {
373  Init();
374  maDefaultNumberSettingsArr = maNumberSettingsArr;
375  ImplLoad(u"standard.syb");
376 }
377 
378 NumberingTypeMgr::~NumberingTypeMgr()
379 {
380 }
381 
383 {
384  RID_SVXSTR_SINGLENUM_DESCRIPTION_0,
385  RID_SVXSTR_SINGLENUM_DESCRIPTION_1,
386  RID_SVXSTR_SINGLENUM_DESCRIPTION_2,
387  RID_SVXSTR_SINGLENUM_DESCRIPTION_3,
388  RID_SVXSTR_SINGLENUM_DESCRIPTION_4,
389  RID_SVXSTR_SINGLENUM_DESCRIPTION_5,
390  RID_SVXSTR_SINGLENUM_DESCRIPTION_6,
391  RID_SVXSTR_SINGLENUM_DESCRIPTION_7
392 };
393 
394 NumberingTypeMgr& NumberingTypeMgr::GetInstance()
395 {
396  static NumberingTypeMgr theNumberingTypeMgr;
397  return theNumberingTypeMgr;
398 }
399 
400 void NumberingTypeMgr::Init()
401 {
402  Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
403  Reference<XDefaultNumberingProvider> xDefNum = DefaultNumberingProvider::create( xContext );
404 
406  Locale aLocale(Application::GetSettings().GetLanguageTag().getLocale());
407  try
408  {
409  aNumberings = xDefNum->getDefaultContinuousNumberingLevels( aLocale );
410 
411  sal_Int32 nLength = aNumberings.getLength();
412 
413  const Sequence<PropertyValue>* pValuesArr = aNumberings.getConstArray();
414  for(sal_Int32 i = 0; i < nLength; i++)
415  {
416  NumSettings_Impl* pNew = lcl_CreateNumberingSettingsPtr(pValuesArr[i]);
417  std::shared_ptr<NumberSettings_Impl> pNumEntry = std::make_shared<NumberSettings_Impl>();
418  pNumEntry->pNumSetting = pNew;
419  if ( i < 8 )
420  pNumEntry->sDescription = SvxResId(RID_SVXSTR_SINGLENUM_DESCRIPTIONS[i]);
421  maNumberSettingsArr.push_back(pNumEntry);
422  }
423  }
424  catch(Exception&)
425  {
426  }
427 }
428 
429 sal_uInt16 NumberingTypeMgr::GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 mLevel,sal_uInt16 nFromIndex)
430 {
431  if ( mLevel == sal_uInt16(0xFFFF) || mLevel > aNum.GetLevelCount() || mLevel == 0)
432  return sal_uInt16(0xFFFF);
433 
434  sal_uInt16 nActLv = IsSingleLevel(mLevel);
435 
436  if ( nActLv == sal_uInt16(0xFFFF) )
437  return sal_uInt16(0xFFFF);
438 
439  const SvxNumberFormat& aFmt(aNum.GetLevel(nActLv));
440  //sal_Unicode cPrefix = OUString(aFmt.GetPrefix())[0];
441  //sal_Unicode cSuffix = :OUString(aFmt.GetSuffix())[0];
442  const OUString& sPrefix = aFmt.GetPrefix();
443  const OUString& sLclSuffix = aFmt.GetSuffix();
444  sal_Int16 eNumType = aFmt.GetNumberingType();
445 
446  sal_uInt16 nCount = maNumberSettingsArr.size();
447  for(sal_uInt16 i = nFromIndex; i < nCount; ++i)
448  {
449  NumberSettings_Impl* _pSet = maNumberSettingsArr[i].get();
450  sal_Int16 eNType = _pSet->pNumSetting->nNumberType;
451  OUString sLocalPrefix = _pSet->pNumSetting->sPrefix;
452  OUString sLocalSuffix = _pSet->pNumSetting->sSuffix;
453  if (sPrefix == sLocalPrefix &&
454  sLclSuffix == sLocalSuffix &&
455  eNumType == eNType )
456  {
457  return i+1;
458  }
459  }
460 
461 
462  return sal_uInt16(0xFFFF);
463 }
464 
465 void NumberingTypeMgr::RelplaceNumRule(SvxNumRule& aNum, sal_uInt16 nIndex, sal_uInt16 mLevel)
466 {
467  sal_uInt16 nActLv = IsSingleLevel(mLevel);
468 
469  if ( nActLv == sal_uInt16(0xFFFF) )
470  return;
471 
472  const SvxNumberFormat& aFmt(aNum.GetLevel(nActLv));
473  SvxNumType eNumType = aFmt.GetNumberingType();
474 
475  sal_uInt16 nCount = maNumberSettingsArr.size();
476  if ( nIndex >= nCount )
477  return;
478 
479  NumberSettings_Impl* _pSet = maNumberSettingsArr[nIndex].get();
480 
481  _pSet->pNumSetting->sPrefix = aFmt.GetPrefix();
482  _pSet->pNumSetting->sSuffix = aFmt.GetSuffix();
483  _pSet->pNumSetting->nNumberType = eNumType;
484  _pSet->bIsCustomized = true;
485 
486  SvxNumRule aTmpRule1(aNum);
487  SvxNumRule aTmpRule2(aNum);
488  ApplyNumRule(aTmpRule1,nIndex,mLevel,true);
489  ApplyNumRule(aTmpRule2,nIndex,mLevel);
490  if (aTmpRule1==aTmpRule2) _pSet->bIsCustomized=false;
491  if (!_pSet->bIsCustomized) {
492  _pSet->sDescription = GetDescription(nIndex,true);
493  }
494  ImplStore(u"standard.syb");
495 }
496 
497 void NumberingTypeMgr::ApplyNumRule(SvxNumRule& aNum, sal_uInt16 nIndex, sal_uInt16 mLevel, bool isDefault, bool isResetSize)
498 {
499  if(maNumberSettingsArr.size() <= nIndex)
500  return;
501  NumberSettingsArr_Impl* pCurrentNumberSettingsArr = &maNumberSettingsArr;
502  if (isDefault) pCurrentNumberSettingsArr = &maDefaultNumberSettingsArr;
503  NumberSettings_Impl* _pSet = (*pCurrentNumberSettingsArr)[nIndex].get();
504  SvxNumType eNewType = _pSet->pNumSetting->nNumberType;
505 
506  sal_uInt16 nMask = 1;
507  OUString sNumCharFmtName = GetNumCharFmtName();
508  for(sal_uInt16 i = 0; i < aNum.GetLevelCount(); i++)
509  {
510  if(mLevel & nMask)
511  {
512  SvxNumberFormat aFmt(aNum.GetLevel(i));
513  if (eNewType!=aFmt.GetNumberingType()) isResetSize=true;
514  aFmt.SetNumberingType(eNewType);
515  aFmt.SetListFormat(_pSet->pNumSetting->sPrefix, _pSet->pNumSetting->sSuffix, i);
516  aFmt.SetCharFormatName(sNumCharFmtName);
517  if (isResetSize) aFmt.SetBulletRelSize(100);
518  aNum.SetLevel(i, aFmt);
519  }
520  nMask <<= 1 ;
521  }
522 }
523 
524 OUString NumberingTypeMgr::GetDescription(sal_uInt16 nIndex, bool isDefault)
525 {
526  OUString sRet;
527  sal_uInt16 nLength = maNumberSettingsArr.size();
528 
529  if ( nIndex >= nLength )
530  return sRet;
531  else
532  sRet = maNumberSettingsArr[nIndex]->sDescription;
533  if (isDefault) sRet = maDefaultNumberSettingsArr[nIndex]->sDescription;
534 
535  return sRet;
536 }
537 
538 bool NumberingTypeMgr::IsCustomized(sal_uInt16 nIndex)
539 {
540  bool bRet = false;
541  sal_uInt16 nLength = maNumberSettingsArr.size();
542 
543  if ( nIndex >= nLength )
544  bRet = false;
545  else
546  bRet = maNumberSettingsArr[nIndex]->bIsCustomized;
547 
548  return bRet;
549 }
550 // Multi-level /Outline Type lib
551 OutlineTypeMgr::OutlineTypeMgr()
552 {
553  Init();
554  for(sal_Int32 nItem = 0; nItem < DEFAULT_NUM_VALUSET_COUNT; nItem++ )
555  {
556  pDefaultOutlineSettingsArrs[nItem] = pOutlineSettingsArrs[nItem];
557  }
558  //Initial the first time to store the default value. Then do it again for customized value
559  Init();
560  ImplLoad(u"standard.syc");
561 }
562 
563 OutlineTypeMgr& OutlineTypeMgr::GetInstance()
564 {
565  static OutlineTypeMgr theOutlineTypeMgr;
566  return theOutlineTypeMgr;
567 }
568 
569 void OutlineTypeMgr::Init()
570 {
571  Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
572  Reference<XDefaultNumberingProvider> xDefNum = DefaultNumberingProvider::create( xContext );
573 
574  Sequence<Reference<XIndexAccess> > aOutlineAccess;
575  Locale aLocale(Application::GetSettings().GetLanguageTag().getLocale());
576  try
577  {
578  aOutlineAccess = xDefNum->getDefaultOutlineNumberings( aLocale );
579 
580  SvxNumRule aDefNumRule( SvxNumRuleFlags::BULLET_REL_SIZE | SvxNumRuleFlags::CONTINUOUS | SvxNumRuleFlags::BULLET_COLOR,
581  10, false,
582  SvxNumRuleType::NUMBERING, SvxNumberFormat::LABEL_ALIGNMENT);
583 
584  auto nSize = std::min<sal_Int32>(aOutlineAccess.getLength(), DEFAULT_NUM_VALUSET_COUNT);
585  for(sal_Int32 nItem = 0; nItem < nSize; nItem++ )
586  {
587  pOutlineSettingsArrs[ nItem ] = new OutlineSettings_Impl;
588  OutlineSettings_Impl* pItemArr = pOutlineSettingsArrs[ nItem ];
589  OString id = OString::Concat(RID_SVXSTR_OUTLINENUM_DESCRIPTION_0.mpId) + OString::number(nItem);
590  pItemArr->sDescription = SvxResId( TranslateId(RID_SVXSTR_OUTLINENUM_DESCRIPTION_0.mpContext, id.getStr()) );
591  pItemArr->pNumSettingsArr = new NumSettingsArr_Impl;
592  Reference<XIndexAccess> xLevel = aOutlineAccess.getConstArray()[nItem];
593  for(sal_Int32 nLevel = 0; nLevel < xLevel->getCount() && nLevel < 5; nLevel++)
594  {
595  Any aValueAny = xLevel->getByIndex(nLevel);
596  Sequence<PropertyValue> aLevelProps;
597  aValueAny >>= aLevelProps;
598  NumSettings_Impl* pNew = lcl_CreateNumberingSettingsPtr(aLevelProps);
599  const SvxNumberFormat& aNumFmt( aDefNumRule.GetLevel( nLevel) );
600  pNew->eLabelFollowedBy = aNumFmt.GetLabelFollowedBy();
601  pNew->nTabValue = aNumFmt.GetListtabPos();
602  pNew->eNumAlign = aNumFmt.GetNumAdjust();
603  pNew->nNumAlignAt = aNumFmt.GetFirstLineIndent();
604  pNew->nNumIndentAt = aNumFmt.GetIndentAt();
605  pItemArr->pNumSettingsArr->push_back(std::shared_ptr<NumSettings_Impl>(pNew));
606  }
607  }
608  }
609  catch(Exception&)
610  {
611  }
612 }
613 
614 sal_uInt16 OutlineTypeMgr::GetNBOIndexForNumRule(SvxNumRule& aNum,sal_uInt16 /*mLevel*/,sal_uInt16 nFromIndex)
615 {
616  sal_uInt16 const nLength = SAL_N_ELEMENTS(pOutlineSettingsArrs);
617  for(sal_uInt16 iDex = nFromIndex; iDex < nLength; iDex++)
618  {
619  bool bNotMatch = false;
620  OutlineSettings_Impl* pItemArr = pOutlineSettingsArrs[iDex];
621  sal_uInt16 nCount = pItemArr->pNumSettingsArr->size();
622  for (sal_uInt16 iLevel=0;iLevel < nCount;iLevel++)
623  {
624  NumSettings_Impl* _pSet = (*pItemArr->pNumSettingsArr)[iLevel].get();
625  sal_Int16 eNType = _pSet->nNumberType;
626 
627  const SvxNumberFormat& aFmt(aNum.GetLevel(iLevel));
628  const OUString& sPrefix = aFmt.GetPrefix();
629  const OUString& sLclSuffix = aFmt.GetSuffix();
630  sal_Int16 eNumType = aFmt.GetNumberingType();
631  if( eNumType == SVX_NUM_CHAR_SPECIAL)
632  {
633  sal_UCS4 cChar = aFmt.GetBulletChar();
634 
635  sal_UCS4 ccChar
636  = _pSet->sBulletChar.iterateCodePoints(&o3tl::temporary(sal_Int32(0)));
637 
638  if ( !((cChar == ccChar) &&
639  _pSet->eLabelFollowedBy == aFmt.GetLabelFollowedBy() &&
640  _pSet->nTabValue == aFmt.GetListtabPos() &&
641  _pSet->eNumAlign == aFmt.GetNumAdjust() &&
642  _pSet->nNumAlignAt == aFmt.GetFirstLineIndent() &&
643  _pSet->nNumIndentAt == aFmt.GetIndentAt()))
644  {
645  bNotMatch = true;
646  break;
647  }
648  }
649  else if ((eNumType&(~LINK_TOKEN)) == SVX_NUM_BITMAP )
650  {
651  const SvxBrushItem* pBrsh1 = aFmt.GetBrush();
652  const SvxBrushItem* pBrsh2 = _pSet->pBrushItem;
653  bool bIsMatch = false;
654  if (pBrsh1==pBrsh2) bIsMatch = true;
655  if (pBrsh1 && pBrsh2) {
656  const Graphic* pGrf1 = pBrsh1->GetGraphic();
657  const Graphic* pGrf2 = pBrsh2->GetGraphic();
658  if (pGrf1==pGrf2) bIsMatch = true;
659  if (pGrf1 && pGrf2) {
660  if ( pGrf1->GetBitmapEx() == pGrf2->GetBitmapEx() &&
661  _pSet->aSize == aFmt.GetGraphicSize())
662  bIsMatch = true;
663  }
664  }
665  if (!bIsMatch) {
666  bNotMatch = true;
667  break;
668  }
669  }
670  else
671  {
672  if (!(sPrefix == _pSet->sPrefix &&
673  sLclSuffix == _pSet->sSuffix &&
674  eNumType == eNType &&
675  _pSet->eLabelFollowedBy == aFmt.GetLabelFollowedBy() &&
676  _pSet->nTabValue == aFmt.GetListtabPos() &&
677  _pSet->eNumAlign == aFmt.GetNumAdjust() &&
678  _pSet->nNumAlignAt == aFmt.GetFirstLineIndent() &&
679  _pSet->nNumIndentAt == aFmt.GetIndentAt()))
680  {
681  bNotMatch = true;
682  break;
683  }
684  }
685  }
686  if ( !bNotMatch )
687  return iDex+1;
688  }
689 
690 
691  return sal_uInt16(0xFFFF);
692 }
693 
694 void OutlineTypeMgr::RelplaceNumRule(SvxNumRule& aNum, sal_uInt16 nIndex, sal_uInt16 mLevel)
695 {
696  sal_uInt16 const nLength = SAL_N_ELEMENTS(pOutlineSettingsArrs);
697  if ( nIndex >= nLength )
698  return;
699 
700  OutlineSettings_Impl* pItemArr = pOutlineSettingsArrs[nIndex];
701  sal_uInt16 nCount = pItemArr->pNumSettingsArr->size();
702  for (sal_uInt16 iLevel=0;iLevel < nCount;iLevel++)
703  {
704  const SvxNumberFormat& aFmt(aNum.GetLevel(iLevel));
705  SvxNumType eNumType = aFmt.GetNumberingType();
706 
707  NumSettings_Impl* _pSet = (*pItemArr->pNumSettingsArr)[iLevel].get();
708 
709  _pSet->eLabelFollowedBy = aFmt.GetLabelFollowedBy();
710  _pSet->nTabValue = aFmt.GetListtabPos();
711  _pSet->eNumAlign = aFmt.GetNumAdjust();
712  _pSet->nNumAlignAt = aFmt.GetFirstLineIndent();
713  _pSet->nNumIndentAt = aFmt.GetIndentAt();
714 
715  if( eNumType == SVX_NUM_CHAR_SPECIAL)
716  {
717  sal_UCS4 cChar = aFmt.GetBulletChar();
718  OUString sChar(&cChar, 1);
719  _pSet->sBulletChar = sChar;
720  if ( aFmt.GetBulletFont() )
721  _pSet->sBulletFont = aFmt.GetBulletFont()->GetFamilyName();
722  _pSet->nNumberType = eNumType;
723  pItemArr->bIsCustomized = true;
724  }else if ((eNumType&(~LINK_TOKEN)) == SVX_NUM_BITMAP ) {
725  if (_pSet->pBrushItem) {
726  delete _pSet->pBrushItem;
727  _pSet->pBrushItem=nullptr;
728  }
729  if (aFmt.GetBrush())
730  _pSet->pBrushItem = new SvxBrushItem(*aFmt.GetBrush());
731  _pSet->aSize = aFmt.GetGraphicSize();
732  _pSet->nNumberType = eNumType;
733  } else
734  {
735  _pSet->sPrefix = aFmt.GetPrefix();
736  _pSet->sSuffix = aFmt.GetSuffix();
737  _pSet->nNumberType = eNumType;
738  if ( aFmt.GetBulletFont() )
739  _pSet->sBulletFont = aFmt.GetBulletFont()->GetFamilyName();
740  pItemArr->bIsCustomized = true;
741  }
742  }
743  SvxNumRule aTmpRule1(aNum);
744  SvxNumRule aTmpRule2(aNum);
745  ApplyNumRule(aTmpRule1,nIndex,mLevel,true);
746  ApplyNumRule(aTmpRule2,nIndex,mLevel);
747  if (aTmpRule1==aTmpRule2) pItemArr->bIsCustomized=false;
748  if (!pItemArr->bIsCustomized) {
749  pItemArr->sDescription = GetDescription(nIndex,true);
750  }
751  ImplStore(u"standard.syc");
752 }
753 
754 void OutlineTypeMgr::ApplyNumRule(SvxNumRule& aNum, sal_uInt16 nIndex, sal_uInt16 /*mLevel*/, bool isDefault, bool isResetSize)
755 {
756  DBG_ASSERT(DEFAULT_NUM_VALUSET_COUNT > nIndex, "wrong index");
757  if(DEFAULT_NUM_VALUSET_COUNT <= nIndex)
758  return;
759 
760  const FontList* pList = nullptr;
761 
762  OutlineSettings_Impl* pItemArr = pOutlineSettingsArrs[nIndex];
763  if (isDefault) pItemArr=pDefaultOutlineSettingsArrs[nIndex];
764 
765  NumSettingsArr_Impl *pNumSettingsArr=pItemArr->pNumSettingsArr;
766 
767  NumSettings_Impl* pLevelSettings = nullptr;
768  for(sal_uInt16 i = 0; i < aNum.GetLevelCount(); i++)
769  {
770  if(pNumSettingsArr->size() > i)
771  pLevelSettings = (*pNumSettingsArr)[i].get();
772 
773  if(!pLevelSettings)
774  break;
775 
776  SvxNumberFormat aFmt(aNum.GetLevel(i));
777  const vcl::Font& rActBulletFont = lcl_GetDefaultBulletFont();
778  if (pLevelSettings->nNumberType !=aFmt.GetNumberingType()) isResetSize=true;
779  aFmt.SetNumberingType( pLevelSettings->nNumberType );
780  sal_uInt16 nUpperLevelOrChar = static_cast<sal_uInt16>(pLevelSettings->nParentNumbering);
781  if(aFmt.GetNumberingType() == SVX_NUM_CHAR_SPECIAL)
782  {
783  if( pLevelSettings->sBulletFont.getLength() &&
784  pLevelSettings->sBulletFont != rActBulletFont.GetFamilyName() )
785  {
786  //search for the font
787  if(!pList)
788  {
789  SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
790  const SvxFontListItem* pFontListItem = static_cast<const SvxFontListItem*>( pCurDocShell->GetItem( SID_ATTR_CHAR_FONTLIST ) );
791  pList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
792  }
793  if(pList && pList->IsAvailable( pLevelSettings->sBulletFont ) )
794  {
795  FontMetric aFontMetric = pList->Get(pLevelSettings->sBulletFont,WEIGHT_NORMAL, ITALIC_NONE);
796  vcl::Font aFont(aFontMetric);
797  aFmt.SetBulletFont(&aFont);
798  }
799  else
800  {
801  //if it cannot be found then create a new one
802  vcl::Font aCreateFont( pLevelSettings->sBulletFont, OUString(), Size( 0, 14 ) );
803  aCreateFont.SetCharSet( RTL_TEXTENCODING_DONTKNOW );
804  aCreateFont.SetFamily( FAMILY_DONTKNOW );
805  aCreateFont.SetPitch( PITCH_DONTKNOW );
806  aCreateFont.SetWeight( WEIGHT_DONTKNOW );
807  aCreateFont.SetTransparent( true );
808  aFmt.SetBulletFont( &aCreateFont );
809  }
810  }else
811  aFmt.SetBulletFont( &rActBulletFont );
812 
813  sal_UCS4 cChar = 0;
814  if( !pLevelSettings->sBulletChar.isEmpty() )
815  {
816  cChar
817  = pLevelSettings->sBulletChar.iterateCodePoints(&o3tl::temporary(sal_Int32(0)));
818  }
820  {
821  if( 0 == i && cChar == BulletsTypeMgr::aDynamicBulletTypes[5] )
822  cChar = BulletsTypeMgr::aDynamicRTLBulletTypes[5];
823  else if( 1 == i )
824  {
825  const SvxNumberFormat& numberFmt = aNum.GetLevel(0);
826  if( numberFmt.GetBulletChar() == BulletsTypeMgr::aDynamicRTLBulletTypes[5] )
827  cChar = BulletsTypeMgr::aDynamicRTLBulletTypes[4];
828  }
829  }
830 
831  aFmt.SetBulletChar(cChar);
832  aFmt.SetCharFormatName( GetBulletCharFmtName() );
833  if (isResetSize) aFmt.SetBulletRelSize(45);
834  }else if ((aFmt.GetNumberingType()&(~LINK_TOKEN)) == SVX_NUM_BITMAP ) {
835  if (pLevelSettings->pBrushItem) {
836  const Graphic* pGrf = pLevelSettings->pBrushItem->GetGraphic();
837  Size aSize = pLevelSettings->aSize;
838  sal_Int16 eOrient = text::VertOrientation::LINE_CENTER;
839  if (!isResetSize && aFmt.GetGraphicSize()!=Size(0,0))
840  aSize = aFmt.GetGraphicSize();
841  else if (aSize.IsEmpty() && pGrf)
842  aSize = SvxNumberFormat::GetGraphicSizeMM100( pGrf );
843  aSize = OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(GetMapUnit()));
844  aFmt.SetGraphicBrush( pLevelSettings->pBrushItem, &aSize, &eOrient );
845  }
846  } else
847  {
848  aFmt.SetIncludeUpperLevels(sal::static_int_cast< sal_uInt8 >(0 != nUpperLevelOrChar ? aNum.GetLevelCount() : 1));
849  aFmt.SetCharFormatName(GetNumCharFmtName());
850  if (isResetSize) aFmt.SetBulletRelSize(100);
851  }
852  if(pNumSettingsArr->size() > i) {
853  aFmt.SetLabelFollowedBy(pLevelSettings->eLabelFollowedBy);
854  aFmt.SetListtabPos(pLevelSettings->nTabValue);
855  aFmt.SetNumAdjust(pLevelSettings->eNumAlign);
856  aFmt.SetFirstLineIndent(pLevelSettings->nNumAlignAt);
857  aFmt.SetIndentAt(pLevelSettings->nNumIndentAt);
858  }
859  aFmt.SetListFormat(pLevelSettings->sPrefix, pLevelSettings->sSuffix, i);
860  aNum.SetLevel(i, aFmt);
861  }
862 }
863 
864 OUString OutlineTypeMgr::GetDescription(sal_uInt16 nIndex, bool isDefault)
865 {
866  OUString sRet;
867 
868  if ( nIndex >= SAL_N_ELEMENTS(pOutlineSettingsArrs) )
869  return sRet;
870  else
871  {
872  OutlineSettings_Impl* pItemArr = pOutlineSettingsArrs[nIndex];
873  if (isDefault) pItemArr = pDefaultOutlineSettingsArrs[nIndex];
874  if ( pItemArr )
875  {
876  sRet = pItemArr->sDescription;
877  }
878  }
879  return sRet;
880 }
881 
882 bool OutlineTypeMgr::IsCustomized(sal_uInt16 nIndex)
883 {
884  bool bRet = false;
885 
886  if ( nIndex >= SAL_N_ELEMENTS(pOutlineSettingsArrs) )
887  return bRet;
888  else
889  {
890  OutlineSettings_Impl* pItemArr = pOutlineSettingsArrs[nIndex];
891  if ( pItemArr )
892  {
893  bRet = pItemArr->bIsCustomized;
894  }
895  }
896 
897  return bRet;
898 }
899 
900 
901 }
902 
903 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetFamily(FontFamily)
SvxNumType GetNumberingType() const
#define DEFAULT_BULLET_TYPES
Definition: nbdtmg.hxx:29
void SetAlpha(sal_uInt8 nAlpha)
sal_UCS4 GetBulletChar() const
void Init()
sal_uInt32 sal_UCS4
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
#define DEFAULT_NUM_VALUSET_COUNT
Definition: nbdtmg.hxx:30
FAMILY_DONTKNOW
static const AllSettings & GetSettings()
const sal_Unicode cBulletChar
std::vector< std::shared_ptr< NumberSettings_Impl > > NumberSettingsArr_Impl
Definition: nbdtmg.hxx:95
void SetWeight(FontWeight)
NumSettings_Impl * pNumSetting
Definition: nbdtmg.hxx:87
void SetCharSet(rtl_TextEncoding)
static SfxObjectShell * Current()
#define DEFAULT_NUMBERING_CACHE_FORMAT_VERSION
Definition: nbdtmg.hxx:31
static Size GetGraphicSizeMM100(const Graphic *pGraphic)
bool IsAvailable(const OUString &rName) const
SvxNumType
void Store(SvStream &rStream)
sal_uInt16 sal_Unicode
std::vector< std::shared_ptr< NumSettings_Impl > > NumSettingsArr_Impl
Definition: nbdtmg.hxx:69
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
static vcl::Font & lcl_GetDefaultBulletFont()
SvxNumberFormat::LabelFollowedBy eLabelFollowedBy
Definition: nbdtmg.hxx:43
int nCount
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
FontMetric Get(const OUString &rName, const OUString &rStyleName) const
NumSettingsArr_Impl * pNumSettingsArr
Definition: nbdtmg.hxx:102
const Graphic * GetGraphic(OUString const &referer=OUString()) const
void SetPitch(FontPitch ePitch)
#define SAL_N_ELEMENTS(arr)
SVX_NUM_BITMAP
SVX_NUM_CHAR_SPECIAL
WEIGHT_DONTKNOW
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
OUString sPrefix
bool IsEmpty() const
#define DBG_ASSERT(sCon, aError)
int i
const OUString & GetValue() const
WEIGHT_NORMAL
const SvxNumberFormat & GetLevel(sal_uInt16 nLevel) const
sal_uInt16 GetLevelCount() const
float u
static bool GetLayoutRTL()
PITCH_DONTKNOW
const TranslateId RID_SVXSTR_SINGLENUM_DESCRIPTIONS[]
SvxBrushItem * pBrushItem
Definition: nbdtmg.hxx:52
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
ITALIC_NONE
sal_Int16 nVersion
constexpr T & temporary(T &&x)
void SetBulletChar(sal_UCS4 cSet)
const LanguageTag & getLocale()
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
SfxItemState
#define LINK_TOKEN
void SetTransparent(bool bTransparent)
#define SVX_MAX_NUM
bool Append(std::u16string_view rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
MapUnit
sal_Int32 nLength
constexpr TypedWhichId< SvxNumBulletItem > EE_PARA_NUMBULLET(EE_PARA_START+5)
const FontList * GetFontList() const
void SetNumberingType(SvxNumType nSet)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
void SetLevel(sal_uInt16 nLevel, const SvxNumberFormat &rFmt, bool bIsValid=true)