tdf#132274 follow-up fix to Writer zoom options
[LibreOffice.git] / svtools / source / control / ctrltool.cxx
blob438b229c73a76146707837074ced62fd9039c046
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <memory>
23 #include <string.h>
24 #include <string_view>
26 #include <tools/debug.hxx>
27 #include <i18nlangtag/languagetag.hxx>
28 #include <i18nlangtag/mslangid.hxx>
29 #include <utility>
30 #include <vcl/outdev.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/settings.hxx>
33 #include <sal/macros.h>
34 #include <svtools/strings.hrc>
35 #include <svtools/svtresid.hxx>
36 #include <svtools/ctrltool.hxx>
37 #include <o3tl/typed_flags_set.hxx>
38 #include <o3tl/string_view.hxx>
39 #include <comphelper/lok.hxx>
41 // Standard fontsizes for scalable Fonts
42 const int FontList::aStdSizeAry[] =
44 60,
45 70,
46 80,
47 90,
48 100,
49 105,
50 110,
51 120,
52 130,
53 140,
54 150,
55 160,
56 180,
57 200,
58 210,
59 220,
60 240,
61 260,
62 280,
63 320,
64 360,
65 400,
66 420,
67 440,
68 480,
69 540,
70 600,
71 660,
72 720,
73 800,
74 880,
75 960,
79 namespace {
81 class ImplFontListFontMetric : public FontMetric
83 friend FontList;
85 private:
86 ImplFontListFontMetric* mpNext;
88 public:
89 ImplFontListFontMetric( const FontMetric& rInfo ) :
90 FontMetric( rInfo ), mpNext(nullptr)
96 enum class FontListFontNameType
98 NONE = 0x00,
99 PRINTER = 0x01,
100 SCREEN = 0x02,
104 namespace o3tl
106 template<> struct typed_flags<FontListFontNameType> : is_typed_flags<FontListFontNameType, 0x3> {};
109 class ImplFontListNameInfo
111 friend class FontList;
113 private:
114 OUString maSearchName;
115 ImplFontListFontMetric* mpFirst;
116 FontListFontNameType mnType;
118 explicit ImplFontListNameInfo(OUString aSearchName)
119 : maSearchName(std::move(aSearchName))
120 , mpFirst(nullptr)
121 , mnType(FontListFontNameType::NONE)
126 //sort normal to the start
127 static int sortWeightValue(FontWeight eWeight)
129 if (eWeight < WEIGHT_NORMAL)
130 return eWeight + 1;
131 if (eWeight > WEIGHT_NORMAL)
132 return eWeight - 1;
133 return 0; // eWeight == WEIGHT_NORMAL
136 static sal_Int32 ImplCompareFontMetric( ImplFontListFontMetric* pInfo1,
137 ImplFontListFontMetric* pInfo2 )
139 //Sort non italic before italics
140 if ( pInfo1->GetItalic() < pInfo2->GetItalic() )
141 return -1;
142 else if ( pInfo1->GetItalic() > pInfo2->GetItalic() )
143 return 1;
145 //Sort normal weight to the start, followed by lightest to heaviest weights
146 int nWeight1 = sortWeightValue(pInfo1->GetWeight());
147 int nWeight2 = sortWeightValue(pInfo2->GetWeight());
149 if ( nWeight1 < nWeight2 )
150 return -1;
151 else if ( nWeight1 > nWeight2 )
152 return 1;
154 return pInfo1->GetStyleName().compareTo( pInfo2->GetStyleName() );
157 static OUString ImplMakeSearchString(const OUString& rStr)
159 return rStr.toAsciiLowerCase();
162 static OUString ImplMakeSearchStringFromName(std::u16string_view rStr)
164 // check for features before alternate font separator
165 if (size_t nColon = rStr.find(':'); nColon != std::u16string_view::npos)
166 if (size_t nSemiColon = rStr.find(';'); nSemiColon == std::u16string_view::npos || nColon < nSemiColon)
167 return ImplMakeSearchString(OUString(o3tl::getToken(rStr, 0, ':' )));
168 return ImplMakeSearchString(OUString(o3tl::getToken(rStr, 0, ';' )));
171 ImplFontListNameInfo* FontList::ImplFind(std::u16string_view rSearchName, sal_uInt32* pIndex) const
173 // Append if there is no entry in the list or if the entry is larger
174 // then the last one. We only compare to the last entry as the list of VCL
175 // is returned sorted, which increases the probability that appending
176 // is more likely
177 if (m_Entries.empty())
179 if ( pIndex )
180 *pIndex = SAL_MAX_UINT32;
181 return nullptr;
183 else
185 const ImplFontListNameInfo* pCmpData = m_Entries.back().get();
186 sal_Int32 nComp = rSearchName.compare( pCmpData->maSearchName );
187 if (nComp > 0)
189 if ( pIndex )
190 *pIndex = SAL_MAX_UINT32;
191 return nullptr;
193 else if (nComp == 0)
194 return const_cast<ImplFontListNameInfo*>(pCmpData);
197 // search fonts in the list
198 const ImplFontListNameInfo* pCompareData;
199 const ImplFontListNameInfo* pFoundData = nullptr;
200 size_t nLow = 0;
201 size_t nHigh = m_Entries.size() - 1;
202 size_t nMid;
206 nMid = (nLow + nHigh) / 2;
207 pCompareData = m_Entries[nMid].get();
208 sal_Int32 nComp = rSearchName.compare(pCompareData->maSearchName);
209 if (nComp < 0)
211 if ( !nMid )
212 break;
213 nHigh = nMid-1;
215 else
217 if (nComp > 0)
218 nLow = nMid + 1;
219 else
221 pFoundData = pCompareData;
222 break;
226 while ( nLow <= nHigh );
228 if ( pIndex )
230 sal_Int32 nComp = rSearchName.compare(pCompareData->maSearchName);
231 if (nComp > 0)
232 *pIndex = (nMid+1);
233 else
234 *pIndex = nMid;
237 return const_cast<ImplFontListNameInfo*>(pFoundData);
240 ImplFontListNameInfo* FontList::ImplFindByName(std::u16string_view rStr) const
242 OUString aSearchName = ImplMakeSearchStringFromName(rStr);
243 return ImplFind( aSearchName, nullptr );
246 void FontList::ImplInsertFonts(OutputDevice* pDevice, bool bInsertData)
248 rtl_TextEncoding eSystemEncoding = osl_getThreadTextEncoding();
250 FontListFontNameType nType;
251 if ( pDevice->GetOutDevType() != OUTDEV_PRINTER )
252 nType = FontListFontNameType::SCREEN;
253 else
254 nType = FontListFontNameType::PRINTER;
256 // inquire all fonts from the device
257 int n = pDevice->GetFontFaceCollectionCount();
258 if (n == 0 && comphelper::LibreOfficeKit::isActive())
260 pDevice->RefreshFontData(true);
261 n = pDevice->GetFontFaceCollectionCount();
264 for (int i = 0; i < n; ++i)
266 FontMetric aFontMetric = pDevice->GetFontMetricFromCollection( i );
267 OUString aSearchName(aFontMetric.GetFamilyName());
268 ImplFontListNameInfo* pData;
269 sal_uInt32 nIndex;
270 aSearchName = ImplMakeSearchString(aSearchName);
271 pData = ImplFind( aSearchName, &nIndex );
273 if ( !pData )
275 if ( bInsertData )
277 ImplFontListFontMetric* pNewInfo = new ImplFontListFontMetric( aFontMetric );
278 pData = new ImplFontListNameInfo( aSearchName );
279 pData->mpFirst = pNewInfo;
280 pNewInfo->mpNext = nullptr;
282 if (nIndex < static_cast<sal_uInt32>(m_Entries.size()))
283 m_Entries.insert(m_Entries.begin()+nIndex,
284 std::unique_ptr<ImplFontListNameInfo>(pData));
285 else
286 m_Entries.push_back(std::unique_ptr<ImplFontListNameInfo>(pData));
289 else
291 if ( bInsertData )
293 bool bInsert = true;
294 ImplFontListFontMetric* pPrev = nullptr;
295 ImplFontListFontMetric* pTemp = pData->mpFirst;
296 ImplFontListFontMetric* pNewInfo = new ImplFontListFontMetric( aFontMetric );
297 while ( pTemp )
299 sal_Int32 eComp = ImplCompareFontMetric( pNewInfo, pTemp );
300 if ( eComp <= 0 )
302 if ( eComp == 0 )
304 // Overwrite charset, because charset should match
305 // with the system charset
306 if ( (pTemp->GetCharSet() != eSystemEncoding) &&
307 (pNewInfo->GetCharSet() == eSystemEncoding) )
309 ImplFontListFontMetric* pTemp2 = pTemp->mpNext;
310 *static_cast<FontMetric*>(pTemp) = *static_cast<FontMetric*>(pNewInfo);
311 pTemp->mpNext = pTemp2;
313 delete pNewInfo;
314 bInsert = false;
317 break;
320 pPrev = pTemp;
321 pTemp = pTemp->mpNext;
324 if ( bInsert )
326 pNewInfo->mpNext = pTemp;
327 if ( pPrev )
328 pPrev->mpNext = pNewInfo;
329 else
330 pData->mpFirst = pNewInfo;
335 if ( pData )
336 pData->mnType |= nType;
340 FontList::FontList(OutputDevice* pDevice, OutputDevice* pDevice2)
342 // initialise variables
343 mpDev = pDevice;
344 mpDev2 = pDevice2;
346 // store style names
347 maLight = SvtResId(STR_SVT_STYLE_LIGHT);
348 maLightItalic = SvtResId(STR_SVT_STYLE_LIGHT_ITALIC);
349 maNormal = SvtResId(STR_SVT_STYLE_NORMAL);
350 maNormalItalic = SvtResId(STR_SVT_STYLE_NORMAL_ITALIC);
351 maBold = SvtResId(STR_SVT_STYLE_BOLD);
352 maBoldItalic = SvtResId(STR_SVT_STYLE_BOLD_ITALIC);
353 maBlack = SvtResId(STR_SVT_STYLE_BLACK);
354 maBlackItalic = SvtResId(STR_SVT_STYLE_BLACK_ITALIC);
356 ImplInsertFonts(pDevice, true);
358 // if required compare to the screen fonts
359 // in order to map the duplicates to Equal
360 bool bCompareWindow = false;
361 if ( !pDevice2 && (pDevice->GetOutDevType() == OUTDEV_PRINTER) )
363 bCompareWindow = true;
364 pDevice2 = Application::GetDefaultDevice();
367 if ( pDevice2 &&
368 (pDevice2->GetOutDevType() != pDevice->GetOutDevType()) )
369 ImplInsertFonts(pDevice2, !bCompareWindow);
372 FontList::~FontList()
374 // delete FontMetrics
375 ImplFontListFontMetric *pTemp, *pInfo;
376 for (auto const& it : m_Entries)
378 pInfo = it->mpFirst;
379 while ( pInfo )
381 pTemp = pInfo->mpNext;
382 delete pInfo;
383 pInfo = pTemp;
388 std::unique_ptr<FontList> FontList::Clone() const
390 return std::unique_ptr<FontList>(new FontList(mpDev, mpDev2));
393 const OUString& FontList::GetStyleName(FontWeight eWeight, FontItalic eItalic) const
395 if ( eWeight > WEIGHT_BOLD )
397 if ( eItalic > ITALIC_NONE )
398 return maBlackItalic;
399 else
400 return maBlack;
402 else if ( eWeight > WEIGHT_MEDIUM )
404 if ( eItalic > ITALIC_NONE )
405 return maBoldItalic;
406 else
407 return maBold;
409 else if ( eWeight > WEIGHT_LIGHT )
411 if ( eItalic > ITALIC_NONE )
412 return maNormalItalic;
413 else
414 return maNormal;
416 else if ( eWeight != WEIGHT_DONTKNOW )
418 if ( eItalic > ITALIC_NONE )
419 return maLightItalic;
420 else
421 return maLight;
423 else
425 if ( eItalic > ITALIC_NONE )
426 return maNormalItalic;
427 else
428 return maNormal;
432 OUString FontList::GetStyleName(const FontMetric& rInfo) const
434 OUString aStyleName = rInfo.GetStyleName();
435 FontWeight eWeight = rInfo.GetWeight();
436 FontItalic eItalic = rInfo.GetItalic();
438 // return synthetic Name if no StyleName was set
439 if (aStyleName.isEmpty())
440 aStyleName = GetStyleName(eWeight, eItalic);
441 else
443 // Translate StyleName to localized name
444 OUString aCompareStyleName = aStyleName.toAsciiLowerCase().replaceAll(" ", "");
445 if (aCompareStyleName == "bold")
446 aStyleName = maBold;
447 else if (aCompareStyleName == "bolditalic")
448 aStyleName = maBoldItalic;
449 else if (aCompareStyleName == "italic")
450 aStyleName = maNormalItalic;
451 else if (aCompareStyleName == "standard")
452 aStyleName = maNormal;
453 else if (aCompareStyleName == "regular")
454 aStyleName = maNormal;
455 else if (aCompareStyleName == "light")
456 aStyleName = maLight;
457 else if (aCompareStyleName == "lightitalic")
458 aStyleName = maLightItalic;
459 else if (aCompareStyleName == "black")
460 aStyleName = maBlack;
461 else if (aCompareStyleName == "blackitalic")
462 aStyleName = maBlackItalic;
463 /* tdf#107700 support some less common style names with localization */
464 else if (aCompareStyleName == "book")
465 aStyleName = SvtResId(STR_SVT_STYLE_BOOK);
466 else if (aCompareStyleName == "boldoblique")
467 aStyleName = SvtResId(STR_SVT_STYLE_BOLD_OBLIQUE);
468 else if (aCompareStyleName == "condensed")
469 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED);
470 else if (aCompareStyleName == "condensedbold")
471 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_BOLD);
472 else if (aCompareStyleName == "condensedbolditalic")
473 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_BOLD_ITALIC);
474 else if (aCompareStyleName == "condensedboldoblique")
475 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_BOLD_OBLIQUE);
476 else if (aCompareStyleName == "condenseditalic")
477 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_ITALIC);
478 else if (aCompareStyleName == "condensedoblique")
479 aStyleName = SvtResId(STR_SVT_STYLE_CONDENSED_OBLIQUE);
480 else if (aCompareStyleName == "extralight")
481 aStyleName = SvtResId(STR_SVT_STYLE_EXTRALIGHT);
482 else if (aCompareStyleName == "extralightitalic")
483 aStyleName = SvtResId(STR_SVT_STYLE_EXTRALIGHT_ITALIC);
484 else if (aCompareStyleName == "oblique")
485 aStyleName = SvtResId(STR_SVT_STYLE_OBLIQUE);
486 else if (aCompareStyleName == "semibold")
487 aStyleName = SvtResId(STR_SVT_STYLE_SEMIBOLD);
488 else if (aCompareStyleName == "semibolditalic")
489 aStyleName = SvtResId(STR_SVT_STYLE_SEMIBOLD_ITALIC);
490 // tdf#147739 medium is not a synonym of normal
491 else if (aCompareStyleName == "medium")
492 aStyleName = SvtResId(STR_SVT_STYLE_MEDIUM);
493 else if (aCompareStyleName == "mediumitalic")
494 aStyleName = SvtResId(STR_SVT_STYLE_MEDIUM_ITALIC);
496 // fix up StyleName, because the PS Printer driver from
497 // W2000 returns wrong StyleNames (e.g. Bold instead of Bold Italic
498 // for Helvetica)
499 if ( eItalic > ITALIC_NONE )
501 if ( (aStyleName == maNormal) ||
502 (aStyleName == maBold) ||
503 (aStyleName == maLight) ||
504 (aStyleName == maBlack) )
505 aStyleName = GetStyleName( eWeight, eItalic );
509 return aStyleName;
512 OUString FontList::GetFontMapText( const FontMetric& rInfo ) const
514 if ( rInfo.GetFamilyName().isEmpty() )
516 return OUString();
519 // Search Fontname
520 ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetFamilyName() );
521 if ( !pData )
523 if (maMapNotAvailable.isEmpty())
524 maMapNotAvailable = SvtResId(STR_SVT_FONTMAP_NOTAVAILABLE);
525 return maMapNotAvailable;
528 // search for synthetic style
529 FontListFontNameType nType = pData->mnType;
530 const OUString& rStyleName = rInfo.GetStyleName();
531 if (!rStyleName.isEmpty())
533 bool bNotSynthetic = false;
534 FontWeight eWeight = rInfo.GetWeight();
535 FontItalic eItalic = rInfo.GetItalic();
536 ImplFontListFontMetric* pFontMetric = pData->mpFirst;
537 while ( pFontMetric )
539 if ( (eWeight == pFontMetric->GetWeight()) &&
540 (eItalic == pFontMetric->GetItalic()) )
542 bNotSynthetic = true;
543 break;
546 pFontMetric = pFontMetric->mpNext;
549 if ( !bNotSynthetic )
551 if (maMapStyleNotAvailable.isEmpty())
552 const_cast<FontList*>(this)->maMapStyleNotAvailable = SvtResId(STR_SVT_FONTMAP_STYLENOTAVAILABLE);
553 return maMapStyleNotAvailable;
557 // Only Printer-Font?
558 if ( nType == FontListFontNameType::PRINTER )
560 if (maMapPrinterOnly.isEmpty())
561 const_cast<FontList*>(this)->maMapPrinterOnly = SvtResId(STR_SVT_FONTMAP_PRINTERONLY);
562 return maMapPrinterOnly;
564 else
566 if (maMapBoth.isEmpty())
567 const_cast<FontList*>(this)->maMapBoth = SvtResId(STR_SVT_FONTMAP_BOTH);
568 return maMapBoth;
572 namespace
574 FontMetric makeMissing(ImplFontListFontMetric const * pFontNameInfo, std::u16string_view rName,
575 FontWeight eWeight, FontItalic eItalic)
577 FontMetric aInfo;
578 // if the fontname matches, we copy as much as possible
579 if (pFontNameInfo)
581 aInfo = *pFontNameInfo;
582 aInfo.SetStyleName(OUString());
585 aInfo.SetWeight(eWeight);
586 aInfo.SetItalic(eItalic);
588 //If this is a known but uninstalled symbol font which we can remap to
589 //OpenSymbol then toggle its charset to be a symbol font
590 if (ConvertChar::GetRecodeData(rName, u"OpenSymbol"))
591 aInfo.SetCharSet(RTL_TEXTENCODING_SYMBOL);
593 return aInfo;
597 FontMetric FontList::Get(const OUString& rName, const OUString& rStyleName) const
599 ImplFontListNameInfo* pData = ImplFindByName( rName );
600 ImplFontListFontMetric* pFontMetric = nullptr;
601 ImplFontListFontMetric* pFontNameInfo = nullptr;
602 if ( pData )
604 ImplFontListFontMetric* pSearchInfo = pData->mpFirst;
605 pFontNameInfo = pSearchInfo;
606 pSearchInfo = pData->mpFirst;
607 while ( pSearchInfo )
609 if (rStyleName.equalsIgnoreAsciiCase(GetStyleName(*pSearchInfo)))
611 pFontMetric = pSearchInfo;
612 break;
615 pSearchInfo = pSearchInfo->mpNext;
619 // reproduce attributes if data could not be found
620 FontMetric aInfo;
621 if ( !pFontMetric )
623 FontWeight eWeight = WEIGHT_DONTKNOW;
624 FontItalic eItalic = ITALIC_NONE;
626 if ( rStyleName == maNormal )
628 eItalic = ITALIC_NONE;
629 eWeight = WEIGHT_NORMAL;
631 else if ( rStyleName == maNormalItalic )
633 eItalic = ITALIC_NORMAL;
634 eWeight = WEIGHT_NORMAL;
636 else if ( rStyleName == maBold )
638 eItalic = ITALIC_NONE;
639 eWeight = WEIGHT_BOLD;
641 else if ( rStyleName == maBoldItalic )
643 eItalic = ITALIC_NORMAL;
644 eWeight = WEIGHT_BOLD;
646 else if ( rStyleName == maLight )
648 eItalic = ITALIC_NONE;
649 eWeight = WEIGHT_LIGHT;
651 else if ( rStyleName == maLightItalic )
653 eItalic = ITALIC_NORMAL;
654 eWeight = WEIGHT_LIGHT;
656 else if ( rStyleName == maBlack )
658 eItalic = ITALIC_NONE;
659 eWeight = WEIGHT_BLACK;
661 else if ( rStyleName == maBlackItalic )
663 eItalic = ITALIC_NORMAL;
664 eWeight = WEIGHT_BLACK;
666 aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
668 else
669 aInfo = *pFontMetric;
671 // set Fontname to keep FontAlias
672 aInfo.SetFamilyName( rName );
673 aInfo.SetStyleName( rStyleName );
675 return aInfo;
678 FontMetric FontList::Get(const OUString& rName,
679 FontWeight eWeight, FontItalic eItalic) const
681 ImplFontListNameInfo* pData = ImplFindByName( rName );
682 ImplFontListFontMetric* pFontMetric = nullptr;
683 ImplFontListFontMetric* pFontNameInfo = nullptr;
684 if ( pData )
686 ImplFontListFontMetric* pSearchInfo = pData->mpFirst;
687 pFontNameInfo = pSearchInfo;
688 while ( pSearchInfo )
690 if ( (eWeight == pSearchInfo->GetWeight()) &&
691 (eItalic == pSearchInfo->GetItalic()) )
693 pFontMetric = pSearchInfo;
694 break;
697 pSearchInfo = pSearchInfo->mpNext;
701 // reproduce attributes if data could not be found
702 FontMetric aInfo;
703 if ( !pFontMetric )
704 aInfo = makeMissing(pFontNameInfo, rName, eWeight, eItalic);
705 else
706 aInfo = *pFontMetric;
708 // set Fontname to keep FontAlias
709 aInfo.SetFamilyName( rName );
711 return aInfo;
714 bool FontList::IsAvailable(std::u16string_view rName) const
716 return (ImplFindByName( rName ) != nullptr);
719 const FontMetric& FontList::GetFontName(size_t const nFont) const
721 DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontName(): nFont >= Count" );
723 return *(m_Entries[nFont]->mpFirst);
726 sal_Handle FontList::GetFirstFontMetric(std::u16string_view rName) const
728 ImplFontListNameInfo* pData = ImplFindByName( rName );
729 if ( !pData )
730 return nullptr;
731 else
732 return static_cast<sal_Handle>(pData->mpFirst);
735 sal_Handle FontList::GetNextFontMetric( sal_Handle hFontMetric )
737 ImplFontListFontMetric* pInfo = static_cast<ImplFontListFontMetric*>(hFontMetric);
738 return static_cast<sal_Handle>(pInfo->mpNext);
741 const FontMetric& FontList::GetFontMetric( sal_Handle hFontMetric )
743 ImplFontListFontMetric* pInfo = static_cast<ImplFontListFontMetric*>(hFontMetric);
744 return *pInfo;
747 struct ImplFSNameItem
749 sal_Int32 mnSize;
750 const char* mszUtf8Name;
753 const ImplFSNameItem aImplSimplifiedChinese[] =
755 { 50, "\xe5\x85\xab\xe5\x8f\xb7" },
756 { 55, "\xe4\xb8\x83\xe5\x8f\xb7" },
757 { 65, "\xe5\xb0\x8f\xe5\x85\xad" },
758 { 75, "\xe5\x85\xad\xe5\x8f\xb7" },
759 { 90, "\xe5\xb0\x8f\xe4\xba\x94" },
760 { 105, "\xe4\xba\x94\xe5\x8f\xb7" },
761 { 120, "\xe5\xb0\x8f\xe5\x9b\x9b" },
762 { 140, "\xe5\x9b\x9b\xe5\x8f\xb7" },
763 { 150, "\xe5\xb0\x8f\xe4\xb8\x89" },
764 { 160, "\xe4\xb8\x89\xe5\x8f\xb7" },
765 { 180, "\xe5\xb0\x8f\xe4\xba\x8c" },
766 { 220, "\xe4\xba\x8c\xe5\x8f\xb7" },
767 { 240, "\xe5\xb0\x8f\xe4\xb8\x80" },
768 { 260, "\xe4\xb8\x80\xe5\x8f\xb7" },
769 { 360, "\xe5\xb0\x8f\xe5\x88\x9d" },
770 { 420, "\xe5\x88\x9d\xe5\x8f\xb7" }
773 FontSizeNames::FontSizeNames( LanguageType eLanguage )
775 if ( eLanguage == LANGUAGE_DONTKNOW )
776 eLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
777 if ( eLanguage == LANGUAGE_SYSTEM )
778 eLanguage = MsLangId::getConfiguredSystemUILanguage();
780 if (MsLangId::isSimplifiedChinese(eLanguage))
782 // equivalent for traditional chinese disabled by popular request, #i89077#
783 mpArray = aImplSimplifiedChinese;
784 mnElem = SAL_N_ELEMENTS(aImplSimplifiedChinese);
786 else
788 mpArray = nullptr;
789 mnElem = 0;
793 sal_Int32 FontSizeNames::Name2Size( std::u16string_view rName ) const
795 if ( mnElem )
797 OString aName(OUStringToOString(rName,
798 RTL_TEXTENCODING_UTF8));
800 // linear search is sufficient for this rare case
801 for( tools::Long i = mnElem; --i >= 0; )
802 if ( aName == mpArray[i].mszUtf8Name )
803 return mpArray[i].mnSize;
806 return 0;
809 OUString FontSizeNames::Size2Name( sal_Int32 nValue ) const
811 OUString aStr;
813 // binary search
814 for( tools::Long lower = 0, upper = mnElem - 1; lower <= upper; )
816 tools::Long mid = (upper + lower) >> 1;
817 if ( nValue == mpArray[mid].mnSize )
819 aStr = OUString( mpArray[mid].mszUtf8Name, strlen(mpArray[mid].mszUtf8Name), RTL_TEXTENCODING_UTF8 );
820 break;
822 else if ( nValue < mpArray[mid].mnSize )
823 upper = mid - 1;
824 else /* ( nValue > mpArray[mid].mnSize ) */
825 lower = mid + 1;
828 return aStr;
831 OUString FontSizeNames::GetIndexName( sal_Int32 nIndex ) const
833 OUString aStr;
835 if ( nIndex < mnElem )
836 aStr = OUString( mpArray[nIndex].mszUtf8Name, strlen(mpArray[nIndex].mszUtf8Name), RTL_TEXTENCODING_UTF8 );
838 return aStr;
841 sal_Int32 FontSizeNames::GetIndexSize( sal_Int32 nIndex ) const
843 if ( nIndex >= mnElem )
844 return 0;
845 return mpArray[nIndex].mnSize;
848 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */