merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / control / ctrltool.cxx
blob9675268688233e5f23e7e6f7d12d68bcc227478c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ctrltool.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define CTRLTOOL_CXX
36 #include <string.h>
38 #ifndef TOOLS_DEBUG_HXX
39 #include <tools/debug.hxx>
40 #endif
41 #include <i18npool/mslangid.hxx>
42 #ifndef _VCL_WINDOW_HXX
43 #include <vcl/window.hxx>
44 #endif
45 #include <vcl/svapp.hxx>
46 #include <vcl/wrkwin.hxx>
48 #include <svtools/svtools.hrc>
49 #include <svtools/svtdata.hxx>
50 #include <ctrltool.hxx>
52 // =======================================================================
54 // Standard Fontgroessen fuer scalierbare Fonts
55 static long aStdSizeAry[] =
57 60,
58 70,
59 80,
60 90,
61 100,
62 105,
63 110,
64 120,
65 130,
66 140,
67 150,
68 160,
69 180,
70 200,
71 220,
72 240,
73 260,
74 280,
75 320,
76 360,
77 400,
78 440,
79 480,
80 540,
81 600,
82 660,
83 720,
84 800,
85 880,
86 960,
90 // =======================================================================
92 // -----------------------------
93 // - class ImplFontListFonInfo -
94 // -----------------------------
96 class ImplFontListFontInfo : public FontInfo
98 friend class FontList;
100 private:
101 OutputDevice* mpDevice;
102 ImplFontListFontInfo* mpNext;
104 public:
105 ImplFontListFontInfo( const FontInfo& rInfo,
106 OutputDevice* pDev ) :
107 FontInfo( rInfo )
109 mpDevice = pDev;
112 OutputDevice* GetDevice() const { return mpDevice; }
115 // ------------------------------
116 // - class ImplFontListNameInfo -
117 // ------------------------------
119 class ImplFontListNameInfo
121 friend class FontList;
123 private:
124 XubString maSearchName;
125 ImplFontListFontInfo* mpFirst;
126 USHORT mnType;
128 ImplFontListNameInfo( const XubString& rSearchName ) :
129 maSearchName( rSearchName )
132 const XubString& GetSearchName() const { return maSearchName; }
135 // =======================================================================
137 static StringCompare ImplCompareFontInfo( ImplFontListFontInfo* pInfo1,
138 ImplFontListFontInfo* pInfo2 )
140 if ( pInfo1->GetWeight() < pInfo2->GetWeight() )
141 return COMPARE_LESS;
142 else if ( pInfo1->GetWeight() > pInfo2->GetWeight() )
143 return COMPARE_GREATER;
145 if ( pInfo1->GetItalic() < pInfo2->GetItalic() )
146 return COMPARE_LESS;
147 else if ( pInfo1->GetItalic() > pInfo2->GetItalic() )
148 return COMPARE_GREATER;
150 return pInfo1->GetStyleName().CompareTo( pInfo2->GetStyleName() );
153 // =======================================================================
155 static void ImplMakeSearchString( XubString& rStr )
157 rStr.ToLowerAscii();
160 // -----------------------------------------------------------------------
162 static void ImplMakeSearchStringFromName( XubString& rStr )
164 // check for features before alternate font separator
165 if (rStr.Search(':') < rStr.Search(';'))
166 rStr = rStr.GetToken( 0, ':' );
167 else
168 rStr = rStr.GetToken( 0, ';' );
169 ImplMakeSearchString( rStr );
172 // -----------------------------------------------------------------------
174 ImplFontListNameInfo* FontList::ImplFind( const XubString& rSearchName, ULONG* pIndex ) const
176 // Wenn kein Eintrag in der Liste oder der Eintrag groesser ist als
177 // der Letzte, dann hinten dranhaengen. Wir vergleichen erst mit dem
178 // letzten Eintrag, da die Liste von VCL auch sortiert zurueckkommt
179 // und somit die Wahrscheinlichkeit das hinten angehaengt werden muss
180 // sehr gross ist.
181 StringCompare eComp;
182 ULONG nCnt = Count();
183 if ( !nCnt )
185 if ( pIndex )
186 *pIndex = LIST_APPEND;
187 return NULL;
189 else
191 ImplFontListNameInfo* pCmpData = (ImplFontListNameInfo*)List::GetObject( nCnt-1 );
192 eComp = rSearchName.CompareTo( pCmpData->maSearchName );
193 if ( eComp == COMPARE_GREATER )
195 if ( pIndex )
196 *pIndex = LIST_APPEND;
197 return NULL;
199 else if ( eComp == COMPARE_EQUAL )
200 return pCmpData;
203 // Fonts in der Liste suchen
204 ImplFontListNameInfo* pCompareData;
205 ImplFontListNameInfo* pFoundData = NULL;
206 ULONG nLow = 0;
207 ULONG nHigh = nCnt-1;
208 ULONG nMid;
212 nMid = (nLow + nHigh) / 2;
213 pCompareData = (ImplFontListNameInfo*)List::GetObject( nMid );
214 eComp = rSearchName.CompareTo( pCompareData->maSearchName );
215 if ( eComp == COMPARE_LESS )
217 if ( !nMid )
218 break;
219 nHigh = nMid-1;
221 else
223 if ( eComp == COMPARE_GREATER )
224 nLow = nMid + 1;
225 else
227 pFoundData = pCompareData;
228 break;
232 while ( nLow <= nHigh );
234 if ( pIndex )
236 eComp = rSearchName.CompareTo( pCompareData->maSearchName );
237 if ( eComp == COMPARE_GREATER )
238 *pIndex = (nMid+1);
239 else
240 *pIndex = nMid;
243 return pFoundData;
246 // -----------------------------------------------------------------------
248 ImplFontListNameInfo* FontList::ImplFindByName( const XubString& rStr ) const
250 XubString aSearchName = rStr;
251 ImplMakeSearchStringFromName( aSearchName );
252 return ImplFind( aSearchName, NULL );
255 // -----------------------------------------------------------------------
257 void FontList::ImplInsertFonts( OutputDevice* pDevice, BOOL bAll,
258 BOOL bInsertData )
260 rtl_TextEncoding eSystemEncoding = gsl_getSystemTextEncoding();
262 USHORT nType;
263 if ( pDevice->GetOutDevType() != OUTDEV_PRINTER )
264 nType = FONTLIST_FONTNAMETYPE_SCREEN;
265 else
266 nType = FONTLIST_FONTNAMETYPE_PRINTER;
268 // Alle Fonts vom Device abfragen
269 int n = pDevice->GetDevFontCount();
270 USHORT i;
271 for( i = 0; i < n; i++ )
273 FontInfo aFontInfo = pDevice->GetDevFont( i );
275 // Wenn keine Raster-Schriften angezeigt werden sollen,
276 // dann diese ignorieren
277 if ( !bAll && (aFontInfo.GetType() == TYPE_RASTER) )
278 continue;
280 XubString aSearchName = aFontInfo.GetName();
281 ImplFontListNameInfo* pData;
282 ULONG nIndex;
283 ImplMakeSearchString( aSearchName );
284 pData = ImplFind( aSearchName, &nIndex );
286 if ( !pData )
288 if ( bInsertData )
290 ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
291 pData = new ImplFontListNameInfo( aSearchName );
292 pData->mpFirst = pNewInfo;
293 pNewInfo->mpNext = NULL;
294 pData->mnType = 0;
295 Insert( (void*)pData, nIndex );
298 else
300 if ( bInsertData )
302 BOOL bInsert = TRUE;
303 ImplFontListFontInfo* pPrev = NULL;
304 ImplFontListFontInfo* pTemp = pData->mpFirst;
305 ImplFontListFontInfo* pNewInfo = new ImplFontListFontInfo( aFontInfo, pDevice );
306 while ( pTemp )
308 StringCompare eComp = ImplCompareFontInfo( pNewInfo, pTemp );
309 if ( (eComp == COMPARE_LESS) || (eComp == COMPARE_EQUAL) )
311 if ( eComp == COMPARE_EQUAL )
313 // Overwrite charset, because charset should match
314 // with the system charset
315 if ( (pTemp->GetCharSet() != eSystemEncoding) &&
316 (pNewInfo->GetCharSet() == eSystemEncoding) )
318 ImplFontListFontInfo* pTemp2 = pTemp->mpNext;
319 *((FontInfo*)pTemp) = *((FontInfo*)pNewInfo);
320 pTemp->mpNext = pTemp2;
322 delete pNewInfo;
323 bInsert = FALSE;
326 break;
329 pPrev = pTemp;
330 pTemp = pTemp->mpNext;
333 if ( bInsert )
335 pNewInfo->mpNext = pTemp;
336 if ( pPrev )
337 pPrev->mpNext = pNewInfo;
338 else
339 pData->mpFirst = pNewInfo;
344 if ( pData )
346 pData->mnType |= nType;
347 if ( aFontInfo.GetType() != TYPE_RASTER )
348 pData->mnType |= FONTLIST_FONTNAMETYPE_SCALABLE;
353 // =======================================================================
355 FontList::FontList( OutputDevice* pDevice, OutputDevice* pDevice2, BOOL bAll ) :
356 List( 4096, sal::static_int_cast< USHORT >(pDevice->GetDevFontCount()), 32 )
358 // Variablen initialisieren
359 mpDev = pDevice;
360 mpDev2 = pDevice2;
361 mpSizeAry = NULL;
363 // Stylenamen festlegen
364 maLight = XubString( SvtResId( STR_SVT_STYLE_LIGHT ) );
365 maLightItalic = XubString( SvtResId( STR_SVT_STYLE_LIGHT_ITALIC ) );
366 maNormal = XubString( SvtResId( STR_SVT_STYLE_NORMAL ) );
367 maNormalItalic = XubString( SvtResId( STR_SVT_STYLE_NORMAL_ITALIC ) );
368 maBold = XubString( SvtResId( STR_SVT_STYLE_BOLD ) );
369 maBoldItalic = XubString( SvtResId( STR_SVT_STYLE_BOLD_ITALIC ) );
370 maBlack = XubString( SvtResId( STR_SVT_STYLE_BLACK ) );
371 maBlackItalic = XubString( SvtResId( STR_SVT_STYLE_BLACK_ITALIC ) );
373 ImplInsertFonts( pDevice, bAll, TRUE );
375 // Gegebenenfalls muessen wir mit den Bildschirmfonts vergleichen,
376 // damit dort die eigentlich doppelten auf Equal mappen koennen
377 BOOL bCompareWindow = FALSE;
378 if ( !pDevice2 && (pDevice->GetOutDevType() == OUTDEV_PRINTER) )
380 bCompareWindow = TRUE;
381 pDevice2 = Application::GetDefaultDevice();
384 if ( pDevice2 &&
385 (pDevice2->GetOutDevType() != pDevice->GetOutDevType()) )
386 ImplInsertFonts( pDevice2, bAll, !bCompareWindow );
389 // -----------------------------------------------------------------------
391 FontList::~FontList()
393 // Gegebenenfalls SizeArray loeschen
394 if ( mpSizeAry )
395 delete[] mpSizeAry;
397 // FontInfos loeschen
398 ImplFontListNameInfo* pData = (ImplFontListNameInfo*)First();
399 while ( pData )
401 ImplFontListFontInfo* pTemp;
402 ImplFontListFontInfo* pInfo = pData->mpFirst;
403 while ( pInfo )
405 pTemp = pInfo->mpNext;
406 delete pInfo;
407 pInfo = pTemp;
409 ImplFontListNameInfo* pNext = (ImplFontListNameInfo*)Next();
410 delete pData;
411 pData = pNext;
414 // -----------------------------------------------------------------------
415 FontList* FontList::Clone() const
417 FontList* pReturn = new FontList(
418 mpDev, mpDev2, GetFontNameCount() == mpDev->GetDevFontCount());
419 return pReturn;
422 // -----------------------------------------------------------------------
424 const XubString& FontList::GetStyleName( FontWeight eWeight, FontItalic eItalic ) const
426 if ( eWeight > WEIGHT_BOLD )
428 if ( eItalic > ITALIC_NONE )
429 return maBlackItalic;
430 else
431 return maBlack;
433 else if ( eWeight > WEIGHT_MEDIUM )
435 if ( eItalic > ITALIC_NONE )
436 return maBoldItalic;
437 else
438 return maBold;
440 else if ( eWeight > WEIGHT_LIGHT )
442 if ( eItalic > ITALIC_NONE )
443 return maNormalItalic;
444 else
445 return maNormal;
447 else if ( eWeight != WEIGHT_DONTKNOW )
449 if ( eItalic > ITALIC_NONE )
450 return maLightItalic;
451 else
452 return maLight;
454 else
456 if ( eItalic > ITALIC_NONE )
457 return maNormalItalic;
458 else
459 return maNormal;
463 // -----------------------------------------------------------------------
465 XubString FontList::GetStyleName( const FontInfo& rInfo ) const
467 XubString aStyleName = rInfo.GetStyleName();
468 FontWeight eWeight = rInfo.GetWeight();
469 FontItalic eItalic = rInfo.GetItalic();
471 // Nur wenn kein StyleName gesetzt ist, geben wir einen syntetischen
472 // Namen zurueck
473 if ( !aStyleName.Len() )
474 aStyleName = GetStyleName( eWeight, eItalic );
475 else
477 // Translate StyleName to localized name
478 XubString aCompareStyleName = aStyleName;
479 aCompareStyleName.ToLowerAscii();
480 aCompareStyleName.EraseAllChars( ' ' );
481 if ( aCompareStyleName.EqualsAscii( "bold" ) )
482 aStyleName = maBold;
483 else if ( aCompareStyleName.EqualsAscii( "bolditalic" ) )
484 aStyleName = maBoldItalic;
485 else if ( aCompareStyleName.EqualsAscii( "italic" ) )
486 aStyleName = maNormalItalic;
487 else if ( aCompareStyleName.EqualsAscii( "standard" ) )
488 aStyleName = maNormal;
489 else if ( aCompareStyleName.EqualsAscii( "regular" ) )
490 aStyleName = maNormal;
491 else if ( aCompareStyleName.EqualsAscii( "medium" ) )
492 aStyleName = maNormal;
493 else if ( aCompareStyleName.EqualsAscii( "light" ) )
494 aStyleName = maLight;
495 else if ( aCompareStyleName.EqualsAscii( "lightitalic" ) )
496 aStyleName = maLightItalic;
497 else if ( aCompareStyleName.EqualsAscii( "black" ) )
498 aStyleName = maBlack;
499 else if ( aCompareStyleName.EqualsAscii( "blackitalic" ) )
500 aStyleName = maBlackItalic;
502 // fix up StyleName, because the PS Printer driver from
503 // W2000 returns wrong StyleNames (e.g. Bold instead of Bold Italic
504 // for Helvetica)
505 if ( eItalic > ITALIC_NONE )
507 if ( (aStyleName == maNormal) ||
508 (aStyleName == maBold) ||
509 (aStyleName == maLight) ||
510 (aStyleName == maBlack) )
511 aStyleName = GetStyleName( eWeight, eItalic );
515 return aStyleName;
518 // -----------------------------------------------------------------------
520 XubString FontList::GetFontMapText( const FontInfo& rInfo ) const
522 if ( !rInfo.GetName().Len() )
524 XubString aEmptryStr;
525 return aEmptryStr;
528 // Search Fontname
529 ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetName() );
530 if ( !pData )
532 if ( !maMapNotAvailable.Len() )
533 ((FontList*)this)->maMapNotAvailable = XubString( SvtResId( STR_SVT_FONTMAP_NOTAVAILABLE ) );
534 return maMapNotAvailable;
537 // search for synthetic style
538 USHORT nType = pData->mnType;
539 const XubString& rStyleName = rInfo.GetStyleName();
540 if ( rStyleName.Len() )
542 BOOL bNotSynthetic = FALSE;
543 BOOL bNoneAvailable = FALSE;
544 FontWeight eWeight = rInfo.GetWeight();
545 FontItalic eItalic = rInfo.GetItalic();
546 ImplFontListFontInfo* pFontInfo = pData->mpFirst;
547 while ( pFontInfo )
549 if ( (eWeight == pFontInfo->GetWeight()) &&
550 (eItalic == pFontInfo->GetItalic()) )
552 bNotSynthetic = TRUE;
553 break;
556 pFontInfo = pFontInfo->mpNext;
559 if ( bNoneAvailable )
561 XubString aEmptryStr;
562 return aEmptryStr;
564 else if ( !bNotSynthetic )
566 if ( !maMapStyleNotAvailable.Len() )
567 ((FontList*)this)->maMapStyleNotAvailable = XubString( SvtResId( STR_SVT_FONTMAP_STYLENOTAVAILABLE ) );
568 return maMapStyleNotAvailable;
572 /* Size not available not implemented yet
573 if ( !(nType & FONTLIST_FONTNAMETYPE_SCALABLE) )
577 if ( !maMapSizeNotAvailable.Len() )
578 ((FontList*)this)->maMapSizeNotAvailable = XubString( SvtResId( STR_SVT_FONTMAP_SIZENOTAVAILABLE ) );
579 return maMapSizeNotAvailable;
584 // Only Printer-Font?
585 if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_PRINTER )
587 if ( !maMapPrinterOnly.Len() )
588 ((FontList*)this)->maMapPrinterOnly = XubString( SvtResId( STR_SVT_FONTMAP_PRINTERONLY ) );
589 return maMapPrinterOnly;
591 // Only Screen-Font?
592 else if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_SCREEN
593 && rInfo.GetType() == TYPE_RASTER )
595 if ( !maMapScreenOnly.Len() )
596 ((FontList*)this)->maMapScreenOnly = XubString( SvtResId( STR_SVT_FONTMAP_SCREENONLY ) );
597 return maMapScreenOnly;
599 else
601 if ( !maMapBoth.Len() )
602 ((FontList*)this)->maMapBoth = XubString( SvtResId( STR_SVT_FONTMAP_BOTH ) );
603 return maMapBoth;
607 // -----------------------------------------------------------------------
609 USHORT FontList::GetFontNameType( const XubString& rFontName ) const
611 ImplFontListNameInfo* pData = ImplFindByName( rFontName );
612 if ( pData )
613 return pData->mnType;
614 else
615 return 0;
618 // -----------------------------------------------------------------------
620 FontInfo FontList::Get( const XubString& rName, const XubString& rStyleName ) const
622 ImplFontListNameInfo* pData = ImplFindByName( rName );
623 ImplFontListFontInfo* pFontInfo = NULL;
624 ImplFontListFontInfo* pFontNameInfo = NULL;
625 if ( pData )
627 ImplFontListFontInfo* pSearchInfo = pData->mpFirst;
628 pFontNameInfo = pSearchInfo;
629 pSearchInfo = pData->mpFirst;
630 while ( pSearchInfo )
632 if ( rStyleName.EqualsIgnoreCaseAscii( GetStyleName( *pSearchInfo ) ) )
634 pFontInfo = pSearchInfo;
635 break;
638 pSearchInfo = pSearchInfo->mpNext;
642 // Konnten die Daten nicht gefunden werden, dann muessen bestimmte
643 // Attribute nachgebildet werden
644 FontInfo aInfo;
645 if ( !pFontInfo )
647 if ( pFontNameInfo )
648 aInfo = *pFontNameInfo;
650 if ( rStyleName == maNormal )
652 aInfo.SetItalic( ITALIC_NONE );
653 aInfo.SetWeight( WEIGHT_NORMAL );
655 else if ( rStyleName == maNormalItalic )
657 aInfo.SetItalic( ITALIC_NORMAL );
658 aInfo.SetWeight( WEIGHT_NORMAL );
660 else if ( rStyleName == maBold )
662 aInfo.SetItalic( ITALIC_NONE );
663 aInfo.SetWeight( WEIGHT_BOLD );
665 else if ( rStyleName == maBoldItalic )
667 aInfo.SetItalic( ITALIC_NORMAL );
668 aInfo.SetWeight( WEIGHT_BOLD );
670 else if ( rStyleName == maLight )
672 aInfo.SetItalic( ITALIC_NONE );
673 aInfo.SetWeight( WEIGHT_LIGHT );
675 else if ( rStyleName == maLightItalic )
677 aInfo.SetItalic( ITALIC_NORMAL );
678 aInfo.SetWeight( WEIGHT_LIGHT );
680 else if ( rStyleName == maBlack )
682 aInfo.SetItalic( ITALIC_NONE );
683 aInfo.SetWeight( WEIGHT_BLACK );
685 else if ( rStyleName == maBlackItalic )
687 aInfo.SetItalic( ITALIC_NORMAL );
688 aInfo.SetWeight( WEIGHT_BLACK );
690 else
692 aInfo.SetItalic( ITALIC_NONE );
693 aInfo.SetWeight( WEIGHT_DONTKNOW );
696 else
697 aInfo = *pFontInfo;
699 // set Fontname to keep FontAlias
700 aInfo.SetName( rName );
701 aInfo.SetStyleName( rStyleName );
703 return aInfo;
706 // -----------------------------------------------------------------------
708 FontInfo FontList::Get( const XubString& rName,
709 FontWeight eWeight, FontItalic eItalic ) const
711 ImplFontListNameInfo* pData = ImplFindByName( rName );
712 ImplFontListFontInfo* pFontInfo = NULL;
713 ImplFontListFontInfo* pFontNameInfo = NULL;
714 if ( pData )
716 ImplFontListFontInfo* pSearchInfo = pData->mpFirst;
717 pFontNameInfo = pSearchInfo;
718 while ( pSearchInfo )
720 if ( (eWeight == pSearchInfo->GetWeight()) &&
721 (eItalic == pSearchInfo->GetItalic()) )
723 pFontInfo = pSearchInfo;
724 break;
727 pSearchInfo = pSearchInfo->mpNext;
731 // Konnten die Daten nicht gefunden werden, dann muessen bestimmte
732 // Attribute nachgebildet werden
733 FontInfo aInfo;
734 if ( !pFontInfo )
736 // Falls der Fontname stimmt, uebernehmen wir soviel wie moeglich
737 if ( pFontNameInfo )
739 aInfo = *pFontNameInfo;
740 aInfo.SetStyleName( XubString() );
743 aInfo.SetWeight( eWeight );
744 aInfo.SetItalic( eItalic );
746 else
747 aInfo = *pFontInfo;
749 // set Fontname to keep FontAlias
750 aInfo.SetName( rName );
752 return aInfo;
755 // -----------------------------------------------------------------------
757 BOOL FontList::IsAvailable( const XubString& rName ) const
759 return (ImplFindByName( rName ) != 0);
762 // -----------------------------------------------------------------------
764 const FontInfo& FontList::GetFontName( USHORT nFont ) const
766 DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontName(): nFont >= Count" );
768 ImplFontListNameInfo* pData = (ImplFontListNameInfo*)List::GetObject( nFont );
769 return *(pData->mpFirst);
772 // -----------------------------------------------------------------------
774 USHORT FontList::GetFontNameType( USHORT nFont ) const
776 DBG_ASSERT( nFont < GetFontNameCount(), "FontList::GetFontNameType(): nFont >= Count" );
778 ImplFontListNameInfo* pData = (ImplFontListNameInfo*)List::GetObject( nFont );
779 return pData->mnType;
782 // -----------------------------------------------------------------------
784 sal_Handle FontList::GetFirstFontInfo( const XubString& rName ) const
786 ImplFontListNameInfo* pData = ImplFindByName( rName );
787 if ( !pData )
788 return (sal_Handle)NULL;
789 else
790 return (sal_Handle)pData->mpFirst;
793 // -----------------------------------------------------------------------
795 sal_Handle FontList::GetNextFontInfo( sal_Handle hFontInfo ) const
797 ImplFontListFontInfo* pInfo = (ImplFontListFontInfo*)(void*)hFontInfo;
798 return (sal_Handle)(pInfo->mpNext);
801 // -----------------------------------------------------------------------
803 const FontInfo& FontList::GetFontInfo( sal_Handle hFontInfo ) const
805 ImplFontListFontInfo* pInfo = (ImplFontListFontInfo*)(void*)hFontInfo;
806 return *pInfo;
809 // -----------------------------------------------------------------------
811 const long* FontList::GetSizeAry( const FontInfo& rInfo ) const
813 // Size-Array vorher loeschen
814 if ( mpSizeAry )
816 delete[] ((FontList*)this)->mpSizeAry;
817 ((FontList*)this)->mpSizeAry = NULL;
820 // Falls kein Name, dann Standardgroessen
821 if ( !rInfo.GetName().Len() )
822 return aStdSizeAry;
824 // Zuerst nach dem Fontnamen suchen um das Device dann von dem
825 // entsprechenden Font zu nehmen
826 OutputDevice* pDevice = mpDev;
827 ImplFontListNameInfo* pData = ImplFindByName( rInfo.GetName() );
828 if ( pData )
829 pDevice = pData->mpFirst->GetDevice();
831 int nDevSizeCount = pDevice->GetDevFontSizeCount( rInfo );
832 if ( !nDevSizeCount ||
833 (pDevice->GetDevFontSize( rInfo, 0 ).Height() == 0) )
834 return aStdSizeAry;
836 MapMode aOldMapMode = pDevice->GetMapMode();
837 MapMode aMap( MAP_10TH_INCH, Point(), Fraction( 1, 72 ), Fraction( 1, 72 ) );
838 pDevice->SetMapMode( aMap );
840 USHORT i;
841 USHORT nRealCount = 0;
842 long nOldHeight = 0;
843 ((FontList*)this)->mpSizeAry = new long[nDevSizeCount+1];
844 for ( i = 0; i < nDevSizeCount; i++ )
846 Size aSize = pDevice->GetDevFontSize( rInfo, i );
847 if ( aSize.Height() != nOldHeight )
849 nOldHeight = aSize.Height();
850 ((FontList*)this)->mpSizeAry[nRealCount] = nOldHeight;
851 nRealCount++;
854 ((FontList*)this)->mpSizeAry[nRealCount] = 0;
856 pDevice->SetMapMode( aOldMapMode );
857 return mpSizeAry;
860 // -----------------------------------------------------------------------
862 const long* FontList::GetStdSizeAry()
864 return aStdSizeAry;
867 // =======================================================================
869 // ---------------------------------
870 // - FontSizeNames & FsizeNameItem -
871 // ---------------------------------
873 struct ImplFSNameItem
875 long mnSize;
876 const char* mszUtf8Name;
879 //------------------------------------------------------------------------
881 static ImplFSNameItem aImplSimplifiedChinese[] =
883 { 50, "\xe5\x85\xab\xe5\x8f\xb7" },
884 { 55, "\xe4\xb8\x83\xe5\x8f\xb7" },
885 { 65, "\xe5\xb0\x8f\xe5\x85\xad" },
886 { 75, "\xe5\x85\xad\xe5\x8f\xb7" },
887 { 90, "\xe5\xb0\x8f\xe4\xba\x94" },
888 { 105, "\xe4\xba\x94\xe5\x8f\xb7" },
889 { 120, "\xe5\xb0\x8f\xe5\x9b\x9b" },
890 { 140, "\xe5\x9b\x9b\xe5\x8f\xb7" },
891 { 150, "\xe5\xb0\x8f\xe4\xb8\x89" },
892 { 160, "\xe4\xb8\x89\xe5\x8f\xb7" },
893 { 180, "\xe5\xb0\x8f\xe4\xba\x8c" },
894 { 220, "\xe4\xba\x8c\xe5\x8f\xb7" },
895 { 240, "\xe5\xb0\x8f\xe4\xb8\x80" },
896 { 260, "\xe4\xb8\x80\xe5\x8f\xb7" },
897 { 360, "\xe5\xb0\x8f\xe5\x88\x9d" },
898 { 420, "\xe5\x88\x9d\xe5\x8f\xb7" }
901 // -----------------------------------------------------------------------
903 #if 0 // #i89077# disabled by popular request
904 static ImplFSNameItem aImplTraditionalChinese[] =
906 { 50, "\xe5\x85\xab\xe8\x99\x9f" },
907 { 55, "\xe4\xb8\x83\xe8\x99\x9f" },
908 { 65, "\xe5\xb0\x8f\xe5\x85\xad" },
909 { 75, "\xe5\x85\xad\xe8\x99\x9f" },
910 { 90, "\xe5\xb0\x8f\xe4\xba\x94" },
911 { 105, "\xe4\xba\x94\xe8\x99\x9f" },
912 { 120, "\xe5\xb0\x8f\xe5\x9b\x9b" },
913 { 140, "\xe5\x9b\x9b\xe8\x99\x9f" },
914 { 150, "\xe5\xb0\x8f\xe4\xb8\x89" },
915 { 160, "\xe4\xb8\x89\xe8\x99\x9f" },
916 { 180, "\xe5\xb0\x8f\xe4\xba\x8c" },
917 { 220, "\xe4\xba\x8c\xe8\x99\x9f" },
918 { 240, "\xe5\xb0\x8f\xe4\xb8\x80" },
919 { 260, "\xe4\xb8\x80\xe8\x99\x9f" },
920 { 360, "\xe5\xb0\x8f\xe5\x88\x9d" },
921 { 420, "\xe5\x88\x9d\xe8\x99\x9f" }
923 #endif
925 //------------------------------------------------------------------------
927 FontSizeNames::FontSizeNames( LanguageType eLanguage )
929 if ( eLanguage == LANGUAGE_DONTKNOW )
930 eLanguage = Application::GetSettings().GetUILanguage();
931 if ( eLanguage == LANGUAGE_SYSTEM )
932 eLanguage = MsLangId::getSystemUILanguage();
934 switch( eLanguage )
936 case LANGUAGE_CHINESE:
937 case LANGUAGE_CHINESE_SIMPLIFIED:
938 mpArray = aImplSimplifiedChinese;
939 mnElem = sizeof(aImplSimplifiedChinese) / sizeof(aImplSimplifiedChinese[0]);
940 break;
942 #if 0 // #i89077# disabled by popular request
943 case LANGUAGE_CHINESE_HONGKONG:
944 case LANGUAGE_CHINESE_SINGAPORE:
945 case LANGUAGE_CHINESE_MACAU:
946 case LANGUAGE_CHINESE_TRADITIONAL:
947 mpArray = aImplTraditionalChinese;
948 mnElem = sizeof(aImplTraditionalChinese) / sizeof(aImplTraditionalChinese[0]);
949 break;
950 #endif
952 default:
953 mpArray = NULL;
954 mnElem = 0;
955 break;
959 //------------------------------------------------------------------------
961 long FontSizeNames::Name2Size( const String& rName ) const
963 if ( mnElem )
965 ByteString aName( rName, RTL_TEXTENCODING_UTF8 );
967 // linear search is sufficient for this rare case
968 for( long i = mnElem; --i >= 0; )
969 if ( aName == mpArray[i].mszUtf8Name )
970 return mpArray[i].mnSize;
973 return 0;
976 //------------------------------------------------------------------------
978 String FontSizeNames::Size2Name( long nValue ) const
980 String aStr;
982 // binary search
983 for( long lower = 0, upper = mnElem - 1; lower <= upper; )
985 long mid = (upper + lower) >> 1;
986 if ( nValue == mpArray[mid].mnSize )
988 aStr = String( mpArray[mid].mszUtf8Name, RTL_TEXTENCODING_UTF8 );
989 break;
991 else if ( nValue < mpArray[mid].mnSize )
992 upper = mid - 1;
993 else /* ( nValue > mpArray[mid].mnSize ) */
994 lower = mid + 1;
997 return aStr;
1000 //------------------------------------------------------------------------
1002 String FontSizeNames::GetIndexName( ULONG nIndex ) const
1004 String aStr;
1006 if ( nIndex < mnElem )
1007 aStr = String( mpArray[nIndex].mszUtf8Name, RTL_TEXTENCODING_UTF8 );
1009 return aStr;
1012 //------------------------------------------------------------------------
1014 long FontSizeNames::GetIndexSize( ULONG nIndex ) const
1016 if ( nIndex >= mnElem )
1017 return 0;
1018 return mpArray[nIndex].mnSize;