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 .
22 #include <comphelper/string.hxx>
23 #include <tools/debug.hxx>
24 #include <i18nlangtag/mslangid.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/wrkwin.hxx>
28 #include <sal/macros.h>
29 #include <svtools/svtools.hrc>
30 #include <svtools/svtresid.hxx>
31 #include <svtools/ctrltool.hxx>
33 // =======================================================================
35 // Standard Fontgroessen fuer scalierbare Fonts
36 static const sal_IntPtr aStdSizeAry
[] =
71 // =======================================================================
73 // -----------------------------
74 // - class ImplFontListFonInfo -
75 // -----------------------------
77 class ImplFontListFontInfo
: public FontInfo
79 friend class FontList
;
82 OutputDevice
* mpDevice
;
83 ImplFontListFontInfo
* mpNext
;
86 ImplFontListFontInfo( const FontInfo
& rInfo
,
87 OutputDevice
* pDev
) :
88 FontInfo( rInfo
), mpNext(NULL
)
93 OutputDevice
* GetDevice() const { return mpDevice
; }
96 // ------------------------------
97 // - class ImplFontListNameInfo -
98 // ------------------------------
100 class ImplFontListNameInfo
102 friend class FontList
;
105 OUString maSearchName
;
106 ImplFontListFontInfo
* mpFirst
;
109 ImplFontListNameInfo(const OUString
& rSearchName
)
110 : maSearchName( rSearchName
)
116 //sort normal to the start
117 static int sortWeightValue(FontWeight eWeight
)
119 if (eWeight
< WEIGHT_NORMAL
)
121 if (eWeight
> WEIGHT_NORMAL
)
123 return 0; // eWeight == WEIGHT_NORMAL
126 static sal_Int32
ImplCompareFontInfo( ImplFontListFontInfo
* pInfo1
,
127 ImplFontListFontInfo
* pInfo2
)
129 //Sort non italic before italics
130 if ( pInfo1
->GetItalic() < pInfo2
->GetItalic() )
132 else if ( pInfo1
->GetItalic() > pInfo2
->GetItalic() )
135 //Sort normal weight to the start, followed by lightest to heaviest weights
136 int nWeight1
= sortWeightValue(pInfo1
->GetWeight());
137 int nWeight2
= sortWeightValue(pInfo2
->GetWeight());
139 if ( nWeight1
< nWeight2
)
141 else if ( nWeight1
> nWeight2
)
144 return pInfo1
->GetStyleName().compareTo( pInfo2
->GetStyleName() );
147 // =======================================================================
149 static OUString
ImplMakeSearchString(const OUString
& rStr
)
151 return rStr
.toAsciiLowerCase();
154 // -----------------------------------------------------------------------
156 static OUString
ImplMakeSearchStringFromName(const OUString
& rStr
)
158 // check for features before alternate font separator
159 sal_Int32 nColon
= rStr
.indexOf(':');
160 sal_Int32 nSemiColon
= rStr
.indexOf(';');
161 if (nColon
!= -1 && (nSemiColon
== -1 || nColon
< nSemiColon
))
162 return ImplMakeSearchString(rStr
.getToken( 0, ':' ));
163 return ImplMakeSearchString(rStr
.getToken( 0, ';' ));
166 // -----------------------------------------------------------------------
168 ImplFontListNameInfo
* FontList::ImplFind(const OUString
& rSearchName
, sal_uLong
* pIndex
) const
170 // Wenn kein Eintrag in der Liste oder der Eintrag groesser ist als
171 // der Letzte, dann hinten dranhaengen. Wir vergleichen erst mit dem
172 // letzten Eintrag, da die Liste von VCL auch sortiert zurueckkommt
173 // und somit die Wahrscheinlichkeit das hinten angehaengt werden muss
175 sal_uLong nCnt
= maEntries
.size();
184 const ImplFontListNameInfo
* pCmpData
= &maEntries
[nCnt
-1];
185 sal_Int32 nComp
= rSearchName
.compareTo( pCmpData
->maSearchName
);
193 return const_cast<ImplFontListNameInfo
*>(pCmpData
);
196 // Fonts in der Liste suchen
197 const ImplFontListNameInfo
* pCompareData
;
198 const ImplFontListNameInfo
* pFoundData
= NULL
;
200 sal_uLong nHigh
= nCnt
-1;
205 nMid
= (nLow
+ nHigh
) / 2;
206 pCompareData
= &maEntries
[nMid
];
207 sal_Int32 nComp
= rSearchName
.compareTo(pCompareData
->maSearchName
);
220 pFoundData
= pCompareData
;
225 while ( nLow
<= nHigh
);
229 sal_Int32 nComp
= rSearchName
.compareTo(pCompareData
->maSearchName
);
236 return const_cast<ImplFontListNameInfo
*>(pFoundData
);
239 ImplFontListNameInfo
* FontList::ImplFindByName(const OUString
& rStr
) const
241 OUString aSearchName
= ImplMakeSearchStringFromName(rStr
);
242 return ImplFind( aSearchName
, NULL
);
245 void FontList::ImplInsertFonts( OutputDevice
* pDevice
, sal_Bool bAll
,
246 sal_Bool bInsertData
)
248 rtl_TextEncoding eSystemEncoding
= osl_getThreadTextEncoding();
251 if ( pDevice
->GetOutDevType() != OUTDEV_PRINTER
)
252 nType
= FONTLIST_FONTNAMETYPE_SCREEN
;
254 nType
= FONTLIST_FONTNAMETYPE_PRINTER
;
256 // Alle Fonts vom Device abfragen
257 int n
= pDevice
->GetDevFontCount();
259 for( i
= 0; i
< n
; i
++ )
261 FontInfo aFontInfo
= pDevice
->GetDevFont( i
);
263 // Wenn keine Raster-Schriften angezeigt werden sollen,
264 // dann diese ignorieren
265 if ( !bAll
&& (aFontInfo
.GetType() == TYPE_RASTER
) )
268 OUString
aSearchName(aFontInfo
.GetName());
269 ImplFontListNameInfo
* pData
;
271 aSearchName
= ImplMakeSearchString(aSearchName
);
272 pData
= ImplFind( aSearchName
, &nIndex
);
278 ImplFontListFontInfo
* pNewInfo
= new ImplFontListFontInfo( aFontInfo
, pDevice
);
279 pData
= new ImplFontListNameInfo( aSearchName
);
280 pData
->mpFirst
= pNewInfo
;
281 pNewInfo
->mpNext
= NULL
;
283 if (nIndex
< maEntries
.size())
284 maEntries
.insert(maEntries
.begin()+nIndex
,pData
);
286 maEntries
.push_back(pData
);
293 sal_Bool bInsert
= sal_True
;
294 ImplFontListFontInfo
* pPrev
= NULL
;
295 ImplFontListFontInfo
* pTemp
= pData
->mpFirst
;
296 ImplFontListFontInfo
* pNewInfo
= new ImplFontListFontInfo( aFontInfo
, pDevice
);
299 sal_Int32 eComp
= ImplCompareFontInfo( pNewInfo
, pTemp
);
304 // Overwrite charset, because charset should match
305 // with the system charset
306 if ( (pTemp
->GetCharSet() != eSystemEncoding
) &&
307 (pNewInfo
->GetCharSet() == eSystemEncoding
) )
309 ImplFontListFontInfo
* pTemp2
= pTemp
->mpNext
;
310 *((FontInfo
*)pTemp
) = *((FontInfo
*)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 // =======================================================================
342 FontList::FontList( OutputDevice
* pDevice
, OutputDevice
* pDevice2
, sal_Bool bAll
)
344 // Variablen initialisieren
349 // Stylenamen festlegen
350 maLight
= SVT_RESSTR(STR_SVT_STYLE_LIGHT
);
351 maLightItalic
= SVT_RESSTR(STR_SVT_STYLE_LIGHT_ITALIC
);
352 maNormal
= SVT_RESSTR(STR_SVT_STYLE_NORMAL
);
353 maNormalItalic
= SVT_RESSTR(STR_SVT_STYLE_NORMAL_ITALIC
);
354 maBold
= SVT_RESSTR(STR_SVT_STYLE_BOLD
);
355 maBoldItalic
= SVT_RESSTR(STR_SVT_STYLE_BOLD_ITALIC
);
356 maBlack
= SVT_RESSTR(STR_SVT_STYLE_BLACK
);
357 maBlackItalic
= SVT_RESSTR(STR_SVT_STYLE_BLACK_ITALIC
);
359 ImplInsertFonts( pDevice
, bAll
, sal_True
);
361 // Gegebenenfalls muessen wir mit den Bildschirmfonts vergleichen,
362 // damit dort die eigentlich doppelten auf Equal mappen koennen
363 sal_Bool bCompareWindow
= sal_False
;
364 if ( !pDevice2
&& (pDevice
->GetOutDevType() == OUTDEV_PRINTER
) )
366 bCompareWindow
= sal_True
;
367 pDevice2
= Application::GetDefaultDevice();
371 (pDevice2
->GetOutDevType() != pDevice
->GetOutDevType()) )
372 ImplInsertFonts( pDevice2
, bAll
, !bCompareWindow
);
375 // -----------------------------------------------------------------------
377 FontList::~FontList()
379 // Gegebenenfalls SizeArray loeschen
382 // FontInfos loeschen
383 ImplFontListFontInfo
*pTemp
, *pInfo
;
384 boost::ptr_vector
<ImplFontListNameInfo
>::iterator it
;
385 for (it
= maEntries
.begin(); it
!= maEntries
.end(); ++it
)
390 pTemp
= pInfo
->mpNext
;
396 // -----------------------------------------------------------------------
397 FontList
* FontList::Clone() const
399 FontList
* pReturn
= new FontList(
400 mpDev
, mpDev2
, GetFontNameCount() == mpDev
->GetDevFontCount());
404 // -----------------------------------------------------------------------
406 const OUString
& FontList::GetStyleName(FontWeight eWeight
, FontItalic eItalic
) const
408 if ( eWeight
> WEIGHT_BOLD
)
410 if ( eItalic
> ITALIC_NONE
)
411 return maBlackItalic
;
415 else if ( eWeight
> WEIGHT_MEDIUM
)
417 if ( eItalic
> ITALIC_NONE
)
422 else if ( eWeight
> WEIGHT_LIGHT
)
424 if ( eItalic
> ITALIC_NONE
)
425 return maNormalItalic
;
429 else if ( eWeight
!= WEIGHT_DONTKNOW
)
431 if ( eItalic
> ITALIC_NONE
)
432 return maLightItalic
;
438 if ( eItalic
> ITALIC_NONE
)
439 return maNormalItalic
;
445 // -----------------------------------------------------------------------
447 OUString
FontList::GetStyleName(const FontInfo
& rInfo
) const
449 OUString aStyleName
= rInfo
.GetStyleName();
450 FontWeight eWeight
= rInfo
.GetWeight();
451 FontItalic eItalic
= rInfo
.GetItalic();
453 // Nur wenn kein StyleName gesetzt ist, geben wir einen syntetischen
455 if (aStyleName
.isEmpty())
456 aStyleName
= GetStyleName(eWeight
, eItalic
);
459 // Translate StyleName to localized name
460 OUString aCompareStyleName
= aStyleName
.toAsciiLowerCase();
461 aCompareStyleName
= comphelper::string::remove(aCompareStyleName
, ' ');
462 if (aCompareStyleName
== "bold")
464 else if (aCompareStyleName
== "bolditalic")
465 aStyleName
= maBoldItalic
;
466 else if (aCompareStyleName
== "italic")
467 aStyleName
= maNormalItalic
;
468 else if (aCompareStyleName
== "standard")
469 aStyleName
= maNormal
;
470 else if (aCompareStyleName
== "regular")
471 aStyleName
= maNormal
;
472 else if (aCompareStyleName
== "medium")
473 aStyleName
= maNormal
;
474 else if (aCompareStyleName
== "light")
475 aStyleName
= maLight
;
476 else if (aCompareStyleName
== "lightitalic")
477 aStyleName
= maLightItalic
;
478 else if (aCompareStyleName
== "black")
479 aStyleName
= maBlack
;
480 else if (aCompareStyleName
== "blackitalic")
481 aStyleName
= maBlackItalic
;
483 // fix up StyleName, because the PS Printer driver from
484 // W2000 returns wrong StyleNames (e.g. Bold instead of Bold Italic
486 if ( eItalic
> ITALIC_NONE
)
488 if ( (aStyleName
== maNormal
) ||
489 (aStyleName
== maBold
) ||
490 (aStyleName
== maLight
) ||
491 (aStyleName
== maBlack
) )
492 aStyleName
= GetStyleName( eWeight
, eItalic
);
499 // -----------------------------------------------------------------------
501 OUString
FontList::GetFontMapText( const FontInfo
& rInfo
) const
503 if ( rInfo
.GetName().isEmpty() )
509 ImplFontListNameInfo
* pData
= ImplFindByName( rInfo
.GetName() );
512 if (maMapNotAvailable
.isEmpty())
513 maMapNotAvailable
= SVT_RESSTR(STR_SVT_FONTMAP_NOTAVAILABLE
);
514 return maMapNotAvailable
;
517 // search for synthetic style
518 sal_uInt16 nType
= pData
->mnType
;
519 const OUString
& rStyleName
= rInfo
.GetStyleName();
520 if (!rStyleName
.isEmpty())
522 sal_Bool bNotSynthetic
= sal_False
;
523 sal_Bool bNoneAvailable
= sal_False
;
524 FontWeight eWeight
= rInfo
.GetWeight();
525 FontItalic eItalic
= rInfo
.GetItalic();
526 ImplFontListFontInfo
* pFontInfo
= pData
->mpFirst
;
529 if ( (eWeight
== pFontInfo
->GetWeight()) &&
530 (eItalic
== pFontInfo
->GetItalic()) )
532 bNotSynthetic
= sal_True
;
536 pFontInfo
= pFontInfo
->mpNext
;
539 if ( bNoneAvailable
)
543 else if ( !bNotSynthetic
)
545 if (maMapStyleNotAvailable
.isEmpty())
546 ((FontList
*)this)->maMapStyleNotAvailable
= SVT_RESSTR(STR_SVT_FONTMAP_STYLENOTAVAILABLE
);
547 return maMapStyleNotAvailable
;
551 // Only Printer-Font?
552 if ( (nType
& (FONTLIST_FONTNAMETYPE_PRINTER
| FONTLIST_FONTNAMETYPE_SCREEN
)) == FONTLIST_FONTNAMETYPE_PRINTER
)
554 if (maMapPrinterOnly
.isEmpty())
555 ((FontList
*)this)->maMapPrinterOnly
= SVT_RESSTR(STR_SVT_FONTMAP_PRINTERONLY
);
556 return maMapPrinterOnly
;
559 else if ( (nType
& (FONTLIST_FONTNAMETYPE_PRINTER
| FONTLIST_FONTNAMETYPE_SCREEN
)) == FONTLIST_FONTNAMETYPE_SCREEN
560 && rInfo
.GetType() == TYPE_RASTER
)
562 if (maMapScreenOnly
.isEmpty())
563 ((FontList
*)this)->maMapScreenOnly
= SVT_RESSTR(STR_SVT_FONTMAP_SCREENONLY
);
564 return maMapScreenOnly
;
568 if (maMapBoth
.isEmpty())
569 ((FontList
*)this)->maMapBoth
= SVT_RESSTR(STR_SVT_FONTMAP_BOTH
);
576 FontInfo
makeMissing(ImplFontListFontInfo
* pFontNameInfo
, const OUString
&rName
,
577 FontWeight eWeight
, FontItalic eItalic
)
580 // Falls der Fontname stimmt, uebernehmen wir soviel wie moeglich
583 aInfo
= *pFontNameInfo
;
584 aInfo
.SetStyleName(OUString());
587 aInfo
.SetWeight(eWeight
);
588 aInfo
.SetItalic(eItalic
);
590 //If this is a known but uninstalled symbol font which we can remap to
591 //OpenSymbol then toggle its charset to be a symbol font
592 if (ConvertChar::GetRecodeData(rName
, OUString("OpenSymbol")))
593 aInfo
.SetCharSet(RTL_TEXTENCODING_SYMBOL
);
599 FontInfo
FontList::Get(const OUString
& rName
, const OUString
& rStyleName
) const
601 ImplFontListNameInfo
* pData
= ImplFindByName( rName
);
602 ImplFontListFontInfo
* pFontInfo
= NULL
;
603 ImplFontListFontInfo
* pFontNameInfo
= NULL
;
606 ImplFontListFontInfo
* pSearchInfo
= pData
->mpFirst
;
607 pFontNameInfo
= pSearchInfo
;
608 pSearchInfo
= pData
->mpFirst
;
609 while ( pSearchInfo
)
611 if (rStyleName
.equalsIgnoreAsciiCase(GetStyleName(*pSearchInfo
)))
613 pFontInfo
= pSearchInfo
;
617 pSearchInfo
= pSearchInfo
->mpNext
;
621 // Konnten die Daten nicht gefunden werden, dann muessen bestimmte
622 // Attribute nachgebildet werden
626 FontWeight eWeight
= WEIGHT_DONTKNOW
;
627 FontItalic eItalic
= ITALIC_NONE
;
629 if ( rStyleName
== maNormal
)
631 eItalic
= ITALIC_NONE
;
632 eWeight
= WEIGHT_NORMAL
;
634 else if ( rStyleName
== maNormalItalic
)
636 eItalic
= ITALIC_NORMAL
;
637 eWeight
= WEIGHT_NORMAL
;
639 else if ( rStyleName
== maBold
)
641 eItalic
= ITALIC_NONE
;
642 eWeight
= WEIGHT_BOLD
;
644 else if ( rStyleName
== maBoldItalic
)
646 eItalic
= ITALIC_NORMAL
;
647 eWeight
= WEIGHT_BOLD
;
649 else if ( rStyleName
== maLight
)
651 eItalic
= ITALIC_NONE
;
652 eWeight
= WEIGHT_LIGHT
;
654 else if ( rStyleName
== maLightItalic
)
656 eItalic
= ITALIC_NORMAL
;
657 eWeight
= WEIGHT_LIGHT
;
659 else if ( rStyleName
== maBlack
)
661 eItalic
= ITALIC_NONE
;
662 eWeight
= WEIGHT_BLACK
;
664 else if ( rStyleName
== maBlackItalic
)
666 eItalic
= ITALIC_NORMAL
;
667 eWeight
= WEIGHT_BLACK
;
669 aInfo
= makeMissing(pFontNameInfo
, rName
, eWeight
, eItalic
);
674 // set Fontname to keep FontAlias
675 aInfo
.SetName( rName
);
676 aInfo
.SetStyleName( rStyleName
);
681 // -----------------------------------------------------------------------
683 FontInfo
FontList::Get(const OUString
& rName
,
684 FontWeight eWeight
, FontItalic eItalic
) const
686 ImplFontListNameInfo
* pData
= ImplFindByName( rName
);
687 ImplFontListFontInfo
* pFontInfo
= NULL
;
688 ImplFontListFontInfo
* pFontNameInfo
= NULL
;
691 ImplFontListFontInfo
* pSearchInfo
= pData
->mpFirst
;
692 pFontNameInfo
= pSearchInfo
;
693 while ( pSearchInfo
)
695 if ( (eWeight
== pSearchInfo
->GetWeight()) &&
696 (eItalic
== pSearchInfo
->GetItalic()) )
698 pFontInfo
= pSearchInfo
;
702 pSearchInfo
= pSearchInfo
->mpNext
;
706 // Konnten die Daten nicht gefunden werden, dann muessen bestimmte
707 // Attribute nachgebildet werden
710 aInfo
= makeMissing(pFontNameInfo
, rName
, eWeight
, eItalic
);
714 // set Fontname to keep FontAlias
715 aInfo
.SetName( rName
);
720 // -----------------------------------------------------------------------
722 sal_Bool
FontList::IsAvailable(const OUString
& rName
) const
724 return (ImplFindByName( rName
) != 0);
727 // -----------------------------------------------------------------------
729 const FontInfo
& FontList::GetFontName( sal_uInt16 nFont
) const
731 DBG_ASSERT( nFont
< GetFontNameCount(), "FontList::GetFontName(): nFont >= Count" );
733 return *(maEntries
[nFont
].mpFirst
);
736 // -----------------------------------------------------------------------
738 sal_Handle
FontList::GetFirstFontInfo(const OUString
& rName
) const
740 ImplFontListNameInfo
* pData
= ImplFindByName( rName
);
742 return (sal_Handle
)NULL
;
744 return (sal_Handle
)pData
->mpFirst
;
747 // -----------------------------------------------------------------------
749 sal_Handle
FontList::GetNextFontInfo( sal_Handle hFontInfo
) const
751 ImplFontListFontInfo
* pInfo
= (ImplFontListFontInfo
*)(void*)hFontInfo
;
752 return (sal_Handle
)(pInfo
->mpNext
);
755 // -----------------------------------------------------------------------
757 const FontInfo
& FontList::GetFontInfo( sal_Handle hFontInfo
) const
759 ImplFontListFontInfo
* pInfo
= (ImplFontListFontInfo
*)(void*)hFontInfo
;
763 // -----------------------------------------------------------------------
765 const sal_IntPtr
* FontList::GetSizeAry( const FontInfo
& rInfo
) const
767 // Size-Array vorher loeschen
770 delete[] ((FontList
*)this)->mpSizeAry
;
771 ((FontList
*)this)->mpSizeAry
= NULL
;
774 // Falls kein Name, dann Standardgroessen
775 if ( rInfo
.GetName().isEmpty() )
778 // Zuerst nach dem Fontnamen suchen um das Device dann von dem
779 // entsprechenden Font zu nehmen
780 OutputDevice
* pDevice
= mpDev
;
781 ImplFontListNameInfo
* pData
= ImplFindByName( rInfo
.GetName() );
783 pDevice
= pData
->mpFirst
->GetDevice();
785 int nDevSizeCount
= pDevice
->GetDevFontSizeCount( rInfo
);
786 if ( !nDevSizeCount
||
787 (pDevice
->GetDevFontSize( rInfo
, 0 ).Height() == 0) )
790 MapMode aOldMapMode
= pDevice
->GetMapMode();
791 MapMode
aMap( MAP_10TH_INCH
, Point(), Fraction( 1, 72 ), Fraction( 1, 72 ) );
792 pDevice
->SetMapMode( aMap
);
795 sal_uInt16 nRealCount
= 0;
797 ((FontList
*)this)->mpSizeAry
= new sal_IntPtr
[nDevSizeCount
+1];
798 for ( i
= 0; i
< nDevSizeCount
; i
++ )
800 Size aSize
= pDevice
->GetDevFontSize( rInfo
, i
);
801 if ( aSize
.Height() != nOldHeight
)
803 nOldHeight
= aSize
.Height();
804 ((FontList
*)this)->mpSizeAry
[nRealCount
] = nOldHeight
;
808 ((FontList
*)this)->mpSizeAry
[nRealCount
] = 0;
810 pDevice
->SetMapMode( aOldMapMode
);
814 // -----------------------------------------------------------------------
816 const sal_IntPtr
* FontList::GetStdSizeAry()
821 // =======================================================================
823 // ---------------------------------
824 // - FontSizeNames & FsizeNameItem -
825 // ---------------------------------
827 struct ImplFSNameItem
830 const char* mszUtf8Name
;
833 //------------------------------------------------------------------------
835 static const ImplFSNameItem aImplSimplifiedChinese
[] =
837 { 50, "\xe5\x85\xab\xe5\x8f\xb7" },
838 { 55, "\xe4\xb8\x83\xe5\x8f\xb7" },
839 { 65, "\xe5\xb0\x8f\xe5\x85\xad" },
840 { 75, "\xe5\x85\xad\xe5\x8f\xb7" },
841 { 90, "\xe5\xb0\x8f\xe4\xba\x94" },
842 { 105, "\xe4\xba\x94\xe5\x8f\xb7" },
843 { 120, "\xe5\xb0\x8f\xe5\x9b\x9b" },
844 { 140, "\xe5\x9b\x9b\xe5\x8f\xb7" },
845 { 150, "\xe5\xb0\x8f\xe4\xb8\x89" },
846 { 160, "\xe4\xb8\x89\xe5\x8f\xb7" },
847 { 180, "\xe5\xb0\x8f\xe4\xba\x8c" },
848 { 220, "\xe4\xba\x8c\xe5\x8f\xb7" },
849 { 240, "\xe5\xb0\x8f\xe4\xb8\x80" },
850 { 260, "\xe4\xb8\x80\xe5\x8f\xb7" },
851 { 360, "\xe5\xb0\x8f\xe5\x88\x9d" },
852 { 420, "\xe5\x88\x9d\xe5\x8f\xb7" }
855 //------------------------------------------------------------------------
857 FontSizeNames::FontSizeNames( LanguageType eLanguage
)
859 if ( eLanguage
== LANGUAGE_DONTKNOW
)
860 eLanguage
= Application::GetSettings().GetUILanguageTag().getLanguageType();
861 if ( eLanguage
== LANGUAGE_SYSTEM
)
862 eLanguage
= MsLangId::getSystemUILanguage();
864 if (MsLangId::isSimplifiedChinese(eLanguage
))
866 // equivalent for traditional chinese disabled by popular request, #i89077#
867 mpArray
= aImplSimplifiedChinese
;
868 mnElem
= SAL_N_ELEMENTS(aImplSimplifiedChinese
);
877 //------------------------------------------------------------------------
879 long FontSizeNames::Name2Size( const OUString
& rName
) const
883 OString
aName(OUStringToOString(rName
,
884 RTL_TEXTENCODING_UTF8
));
886 // linear search is sufficient for this rare case
887 for( long i
= mnElem
; --i
>= 0; )
888 if ( aName
.equals(mpArray
[i
].mszUtf8Name
) )
889 return mpArray
[i
].mnSize
;
895 //------------------------------------------------------------------------
897 OUString
FontSizeNames::Size2Name( long nValue
) const
902 for( long lower
= 0, upper
= mnElem
- 1; lower
<= upper
; )
904 long mid
= (upper
+ lower
) >> 1;
905 if ( nValue
== mpArray
[mid
].mnSize
)
907 aStr
= OUString( mpArray
[mid
].mszUtf8Name
, strlen(mpArray
[mid
].mszUtf8Name
), RTL_TEXTENCODING_UTF8
);
910 else if ( nValue
< mpArray
[mid
].mnSize
)
912 else /* ( nValue > mpArray[mid].mnSize ) */
919 //------------------------------------------------------------------------
921 OUString
FontSizeNames::GetIndexName( sal_uLong nIndex
) const
925 if ( nIndex
< mnElem
)
926 aStr
= OUString( mpArray
[nIndex
].mszUtf8Name
, strlen(mpArray
[nIndex
].mszUtf8Name
), RTL_TEXTENCODING_UTF8
);
931 //------------------------------------------------------------------------
933 long FontSizeNames::GetIndexSize( sal_uLong nIndex
) const
935 if ( nIndex
>= mnElem
)
937 return mpArray
[nIndex
].mnSize
;
940 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */