1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <string_view>
26 #include <tools/debug.hxx>
27 #include <i18nlangtag/languagetag.hxx>
28 #include <i18nlangtag/mslangid.hxx>
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
[] =
81 class ImplFontListFontMetric
: public FontMetric
86 ImplFontListFontMetric
* mpNext
;
89 ImplFontListFontMetric( const FontMetric
& rInfo
) :
90 FontMetric( rInfo
), mpNext(nullptr)
96 enum class FontListFontNameType
106 template<> struct typed_flags
<FontListFontNameType
> : is_typed_flags
<FontListFontNameType
, 0x3> {};
109 class ImplFontListNameInfo
111 friend class FontList
;
114 OUString maSearchName
;
115 ImplFontListFontMetric
* mpFirst
;
116 FontListFontNameType mnType
;
118 explicit ImplFontListNameInfo(OUString aSearchName
)
119 : maSearchName(std::move(aSearchName
))
121 , mnType(FontListFontNameType::NONE
)
126 //sort normal to the start
127 static int sortWeightValue(FontWeight eWeight
)
129 if (eWeight
< WEIGHT_NORMAL
)
131 if (eWeight
> WEIGHT_NORMAL
)
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() )
142 else if ( pInfo1
->GetItalic() > pInfo2
->GetItalic() )
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
)
151 else if ( nWeight1
> nWeight2
)
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
177 if (m_Entries
.empty())
180 *pIndex
= SAL_MAX_UINT32
;
185 const ImplFontListNameInfo
* pCmpData
= m_Entries
.back().get();
186 sal_Int32 nComp
= rSearchName
.compare( pCmpData
->maSearchName
);
190 *pIndex
= SAL_MAX_UINT32
;
194 return const_cast<ImplFontListNameInfo
*>(pCmpData
);
197 // search fonts in the list
198 const ImplFontListNameInfo
* pCompareData
;
199 const ImplFontListNameInfo
* pFoundData
= nullptr;
201 size_t nHigh
= m_Entries
.size() - 1;
206 nMid
= (nLow
+ nHigh
) / 2;
207 pCompareData
= m_Entries
[nMid
].get();
208 sal_Int32 nComp
= rSearchName
.compare(pCompareData
->maSearchName
);
221 pFoundData
= pCompareData
;
226 while ( nLow
<= nHigh
);
230 sal_Int32 nComp
= rSearchName
.compare(pCompareData
->maSearchName
);
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
;
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
;
270 aSearchName
= ImplMakeSearchString(aSearchName
);
271 pData
= ImplFind( aSearchName
, &nIndex
);
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
));
286 m_Entries
.push_back(std::unique_ptr
<ImplFontListNameInfo
>(pData
));
294 ImplFontListFontMetric
* pPrev
= nullptr;
295 ImplFontListFontMetric
* pTemp
= pData
->mpFirst
;
296 ImplFontListFontMetric
* pNewInfo
= new ImplFontListFontMetric( aFontMetric
);
299 sal_Int32 eComp
= ImplCompareFontMetric( pNewInfo
, pTemp
);
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
;
321 pTemp
= pTemp
->mpNext
;
326 pNewInfo
->mpNext
= pTemp
;
328 pPrev
->mpNext
= pNewInfo
;
330 pData
->mpFirst
= pNewInfo
;
336 pData
->mnType
|= nType
;
340 FontList::FontList(OutputDevice
* pDevice
, OutputDevice
* pDevice2
)
342 // initialise variables
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();
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
)
381 pTemp
= pInfo
->mpNext
;
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
;
402 else if ( eWeight
> WEIGHT_MEDIUM
)
404 if ( eItalic
> ITALIC_NONE
)
409 else if ( eWeight
> WEIGHT_LIGHT
)
411 if ( eItalic
> ITALIC_NONE
)
412 return maNormalItalic
;
416 else if ( eWeight
!= WEIGHT_DONTKNOW
)
418 if ( eItalic
> ITALIC_NONE
)
419 return maLightItalic
;
425 if ( eItalic
> ITALIC_NONE
)
426 return maNormalItalic
;
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
);
443 // Translate StyleName to localized name
444 OUString aCompareStyleName
= aStyleName
.toAsciiLowerCase().replaceAll(" ", "");
445 if (aCompareStyleName
== "bold")
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
499 if ( eItalic
> ITALIC_NONE
)
501 if ( (aStyleName
== maNormal
) ||
502 (aStyleName
== maBold
) ||
503 (aStyleName
== maLight
) ||
504 (aStyleName
== maBlack
) )
505 aStyleName
= GetStyleName( eWeight
, eItalic
);
512 OUString
FontList::GetFontMapText( const FontMetric
& rInfo
) const
514 if ( rInfo
.GetFamilyName().isEmpty() )
520 ImplFontListNameInfo
* pData
= ImplFindByName( rInfo
.GetFamilyName() );
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;
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
;
566 if (maMapBoth
.isEmpty())
567 const_cast<FontList
*>(this)->maMapBoth
= SvtResId(STR_SVT_FONTMAP_BOTH
);
574 FontMetric
makeMissing(ImplFontListFontMetric
const * pFontNameInfo
, std::u16string_view rName
,
575 FontWeight eWeight
, FontItalic eItalic
)
578 // if the fontname matches, we copy as much as possible
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
);
597 FontMetric
FontList::Get(const OUString
& rName
, const OUString
& rStyleName
) const
599 ImplFontListNameInfo
* pData
= ImplFindByName( rName
);
600 ImplFontListFontMetric
* pFontMetric
= nullptr;
601 ImplFontListFontMetric
* pFontNameInfo
= nullptr;
604 ImplFontListFontMetric
* pSearchInfo
= pData
->mpFirst
;
605 pFontNameInfo
= pSearchInfo
;
606 pSearchInfo
= pData
->mpFirst
;
607 while ( pSearchInfo
)
609 if (rStyleName
.equalsIgnoreAsciiCase(GetStyleName(*pSearchInfo
)))
611 pFontMetric
= pSearchInfo
;
615 pSearchInfo
= pSearchInfo
->mpNext
;
619 // reproduce attributes if data could not be found
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
);
669 aInfo
= *pFontMetric
;
671 // set Fontname to keep FontAlias
672 aInfo
.SetFamilyName( rName
);
673 aInfo
.SetStyleName( rStyleName
);
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;
686 ImplFontListFontMetric
* pSearchInfo
= pData
->mpFirst
;
687 pFontNameInfo
= pSearchInfo
;
688 while ( pSearchInfo
)
690 if ( (eWeight
== pSearchInfo
->GetWeight()) &&
691 (eItalic
== pSearchInfo
->GetItalic()) )
693 pFontMetric
= pSearchInfo
;
697 pSearchInfo
= pSearchInfo
->mpNext
;
701 // reproduce attributes if data could not be found
704 aInfo
= makeMissing(pFontNameInfo
, rName
, eWeight
, eItalic
);
706 aInfo
= *pFontMetric
;
708 // set Fontname to keep FontAlias
709 aInfo
.SetFamilyName( rName
);
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
);
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
);
747 struct ImplFSNameItem
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
);
793 sal_Int32
FontSizeNames::Name2Size( std::u16string_view rName
) const
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
;
809 OUString
FontSizeNames::Size2Name( sal_Int32 nValue
) const
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
);
822 else if ( nValue
< mpArray
[mid
].mnSize
)
824 else /* ( nValue > mpArray[mid].mnSize ) */
831 OUString
FontSizeNames::GetIndexName( sal_Int32 nIndex
) const
835 if ( nIndex
< mnElem
)
836 aStr
= OUString( mpArray
[nIndex
].mszUtf8Name
, strlen(mpArray
[nIndex
].mszUtf8Name
), RTL_TEXTENCODING_UTF8
);
841 sal_Int32
FontSizeNames::GetIndexSize( sal_Int32 nIndex
) const
843 if ( nIndex
>= mnElem
)
845 return mpArray
[nIndex
].mnSize
;
848 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */