]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/font.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "font.h"
17 #include "wx/gdicmn.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
27 extern wxFontNameDirectory *wxTheFontNameDirectory;
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 class wxFontRefData
: public wxObjectRefData
39 wxFontRefData( const wxFontRefData
& data
);
42 wxList m_scaled_xfonts
;
44 int m_family
, m_style
, m_weight
;
54 wxFontRefData::wxFontRefData() : m_scaled_xfonts(wxKEY_INTEGER
)
56 m_byXFontName
= FALSE
;
62 m_font
= (GdkFont
*) NULL
;
65 wxFontRefData::wxFontRefData( const wxFontRefData
& data
) : m_scaled_xfonts(wxKEY_INTEGER
)
67 m_byXFontName
= FALSE
;
68 m_pointSize
= data
.m_pointSize
;
69 m_family
= data
.m_family
;
70 m_style
= data
.m_style
;
71 m_weight
= data
.m_weight
;
72 m_underlined
= data
.m_underlined
;
73 m_faceName
= data
.m_faceName
;
74 m_font
= (GdkFont
*) NULL
;
75 if (data
.m_font
) m_font
= gdk_font_ref( data
.m_font
);
78 wxFontRefData::~wxFontRefData()
80 wxNode
*node
= m_scaled_xfonts
.First();
83 GdkFont
*font
= (GdkFont
*)node
->Data();
84 wxNode
*next
= node
->Next();
85 gdk_font_unref( font
);
88 if (m_font
) gdk_font_unref( m_font
);
91 //-----------------------------------------------------------------------------
93 #define M_FONTDATA ((wxFontRefData *)m_refData)
95 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
99 if (wxTheFontList
) wxTheFontList
->Append( this );
102 wxFont::wxFont( char *xFontName
)
104 if (!xFontName
) return;
106 m_refData
= new wxFontRefData();
108 M_FONTDATA
->m_byXFontName
= TRUE
;
109 M_FONTDATA
->m_font
= gdk_font_load( xFontName
);
112 wxFont::wxFont( int pointSize
, int family
, int style
, int weight
, bool underlined
, const wxString
& face
)
114 m_refData
= new wxFontRefData();
116 if (family
== wxDEFAULT
)
117 M_FONTDATA
->m_family
= wxSWISS
;
119 M_FONTDATA
->m_family
= family
;
121 if (!face
.IsEmpty()) M_FONTDATA
->m_faceName
= face
;
123 if (style
== wxDEFAULT
)
124 M_FONTDATA
->m_style
= wxNORMAL
;
126 M_FONTDATA
->m_style
= style
;
128 if (weight
== wxDEFAULT
)
129 M_FONTDATA
->m_weight
= wxNORMAL
;
131 M_FONTDATA
->m_weight
= weight
;
133 if (pointSize
== wxDEFAULT
)
134 M_FONTDATA
->m_pointSize
= 12;
136 M_FONTDATA
->m_pointSize
= pointSize
;
138 M_FONTDATA
->m_underlined
= underlined
;
140 if (wxTheFontList
) wxTheFontList
->Append( this );
144 wxFont::wxFont( const wxFont
& font
)
148 if (wxTheFontList
) wxTheFontList
->Append( this );
153 if (wxTheFontList
) wxTheFontList
->DeleteObject( this );
156 wxFont
& wxFont::operator = ( const wxFont
& font
)
158 if (*this == font
) return (*this);
163 bool wxFont::operator == ( const wxFont
& font
) const
165 return m_refData
== font
.m_refData
;
168 bool wxFont::operator != ( const wxFont
& font
) const
170 return m_refData
!= font
.m_refData
;
173 bool wxFont::Ok() const
175 return (m_refData
!= NULL
);
178 int wxFont::GetPointSize() const
180 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
182 return M_FONTDATA
->m_pointSize
;
185 wxString
wxFont::GetFaceName() const
187 wxCHECK_MSG( Ok(), _T(""), _T("invalid font") );
189 return M_FONTDATA
->m_faceName
;
192 int wxFont::GetFamily() const
194 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
196 return M_FONTDATA
->m_family
;
199 wxString
wxFont::GetFamilyString() const
201 wxCHECK_MSG( Ok(), _T("wxDEFAULT"), _T("invalid font") );
203 switch (M_FONTDATA
->m_family
)
205 case wxDECORATIVE
: return wxString(_T("wxDECORATIVE"));
206 case wxROMAN
: return wxString(_T("wxROMAN"));
207 case wxSCRIPT
: return wxString(_T("wxSCRIPT"));
208 case wxSWISS
: return wxString(_T("wxSWISS"));
209 case wxMODERN
: return wxString(_T("wxMODERN"));
210 case wxTELETYPE
: return wxString(_T("wxTELETYPE"));
211 default: return _T("wxDEFAULT");
217 int wxFont::GetStyle() const
219 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
221 return M_FONTDATA
->m_style
;
224 wxString
wxFont::GetStyleString() const
226 wxCHECK_MSG( Ok(), _T("wxDEFAULT"), _T("invalid font") );
228 switch (M_FONTDATA
->m_style
)
230 case wxNORMAL
: return wxString(_T("wxNORMAL"));
231 case wxSLANT
: return wxString(_T("wxSLANT"));
232 case wxITALIC
: return wxString(_T("wxITALIC"));
233 default: return wxString(_T("wxDEFAULT"));
236 return wxString(_T("wxDEFAULT"));
239 int wxFont::GetWeight() const
241 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
243 return M_FONTDATA
->m_weight
;
246 wxString
wxFont::GetWeightString() const
248 wxCHECK_MSG( Ok(), _T("wxDEFAULT"), _T("invalid font") );
250 switch (M_FONTDATA
->m_weight
)
252 case wxNORMAL
: return wxString(_T("wxNORMAL"));
253 case wxBOLD
: return wxString(_T("wxBOLD"));
254 case wxLIGHT
: return wxString(_T("wxLIGHT"));
255 default: return wxString(_T("wxDEFAULT"));
258 return wxString(_T("wxDEFAULT"));
261 bool wxFont::GetUnderlined() const
263 wxCHECK_MSG( Ok(), FALSE
, _T("invalid font") );
265 return M_FONTDATA
->m_underlined
;
268 void wxFont::Unshare()
272 m_refData
= new wxFontRefData();
276 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
282 void wxFont::SetPointSize(int pointSize
)
286 M_FONTDATA
->m_pointSize
= pointSize
;
289 void wxFont::SetFamily(int family
)
293 M_FONTDATA
->m_family
= family
;
296 void wxFont::SetStyle(int style
)
300 M_FONTDATA
->m_style
= style
;
303 void wxFont::SetWeight(int weight
)
307 M_FONTDATA
->m_weight
= weight
;
310 void wxFont::SetFaceName(const wxString
& faceName
)
314 M_FONTDATA
->m_faceName
= faceName
;
317 void wxFont::SetUnderlined(bool underlined
)
321 M_FONTDATA
->m_underlined
= underlined
;
324 //-----------------------------------------------------------------------------
325 // get internal representation of font
326 //-----------------------------------------------------------------------------
328 static GdkFont
*wxLoadQueryNearestFont( int point_size
, int family
, int style
, int weight
,
329 bool underlined
, const wxString
&facename
);
331 GdkFont
*wxFont::GetInternalFont( float scale
) const
335 wxFAIL_MSG( _T("invalid font") );
336 return (GdkFont
*) NULL
;
339 /* short cut if the special X font constructor has been used */
340 if (M_FONTDATA
->m_byXFontName
) return M_FONTDATA
->m_font
;
342 long int_scale
= long(scale
* 100.0 + 0.5); /* key for fontlist */
343 int point_scale
= (M_FONTDATA
->m_pointSize
* 10 * int_scale
) / 100;
344 GdkFont
*font
= (GdkFont
*) NULL
;
346 wxNode
*node
= M_FONTDATA
->m_scaled_xfonts
.Find(int_scale
);
349 font
= (GdkFont
*)node
->Data();
354 if ((int_scale == 100) &&
355 (M_FONTDATA->m_family == wxSWISS) &&
356 (M_FONTDATA->m_style == wxNORMAL) &&
357 (M_FONTDATA->m_pointSize == 12) &&
358 (M_FONTDATA->m_weight == wxNORMAL) &&
359 (M_FONTDATA->m_underlined == FALSE))
361 font = gdk_font_load( "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*" );
366 font
= wxLoadQueryNearestFont( point_scale
, M_FONTDATA
->m_family
, M_FONTDATA
->m_style
,
367 M_FONTDATA
->m_weight
, M_FONTDATA
->m_underlined
, M_FONTDATA
->m_faceName
);
369 M_FONTDATA
->m_scaled_xfonts
.Append( int_scale
, (wxObject
*)font
);
374 wxLogError(_T("could not load any font"));
380 //-----------------------------------------------------------------------------
381 // local utilities to find a X font
382 //-----------------------------------------------------------------------------
384 static GdkFont
*wxLoadQueryFont( int pointSize
, int family
, int style
, int weight
,
385 bool underlined
, const wxString
&facename
)
387 wxChar
*xfamily
= (wxChar
*) NULL
;
388 wxChar
*xstyle
= (wxChar
*) NULL
;
389 wxChar
*xweight
= (wxChar
*) NULL
;
393 case wxDECORATIVE
: xfamily
= _T("lucida"); break;
394 case wxROMAN
: xfamily
= _T("times"); break;
395 case wxMODERN
: xfamily
= _T("courier"); break;
396 case wxSWISS
: xfamily
= _T("helvetica"); break;
397 case wxTELETYPE
: xfamily
= _T("lucidatypewriter"); break;
398 case wxSCRIPT
: xfamily
= _T("utopia"); break;
399 default: xfamily
= _T("*");
402 if (!facename
.IsEmpty())
404 wxSprintf( wxBuffer
, _T("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"), facename
.c_str() );
405 GdkFont
*test
= gdk_font_load( wxConvCurrent
->cWX2MB(wxBuffer
) );
408 gdk_font_unref( test
);
409 xfamily
= WXSTRINGCAST facename
;
415 case wxITALIC
: xstyle
= _T("i"); break;
416 case wxSLANT
: xstyle
= _T("o"); break;
417 case wxNORMAL
: xstyle
= _T("r"); break;
418 default: xstyle
= _T("*"); break;
422 case wxBOLD
: xweight
= _T("bold"); break;
424 case wxNORMAL
: xweight
= _T("medium"); break;
425 default: xweight
= _T("*"); break;
428 wxSprintf( wxBuffer
, _T("-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-*-*"),
429 xfamily
, xweight
, xstyle
, pointSize
);
431 return gdk_font_load( wxConvCurrent
->cWX2MB(wxBuffer
) );
434 static GdkFont
*wxLoadQueryNearestFont( int point_size
, int family
, int style
, int weight
,
435 bool underlined
, const wxString
&facename
)
437 GdkFont
*font
= wxLoadQueryFont( point_size
, family
, style
, weight
, underlined
, facename
);
441 /* search up and down by stepsize 10 */
442 int max_size
= point_size
+ 20 * (1 + (point_size
/180));
443 int min_size
= point_size
- 20 * (1 + (point_size
/180));
447 /* Search for smaller size (approx.) */
448 for (i
=point_size
-10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10)
449 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
, facename
);
451 /* Search for larger size (approx.) */
452 for (i
=point_size
+10; !font
&& i
<= max_size
; i
+= 10)
453 font
= wxLoadQueryFont( i
, family
, style
, weight
, underlined
, facename
);
455 /* Try default family */
456 if (!font
&& family
!= wxDEFAULT
)
457 font
= wxLoadQueryFont( point_size
, wxDEFAULT
, style
, weight
, underlined
, facename
);
461 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
, underlined
, facename
);
469 //-----------------------------------------------------------------------------
470 // face names and index functions
471 //-----------------------------------------------------------------------------
473 static char *font_defaults[] = {
474 "FamilyDefault", "Default",
475 "FamilyRoman", "Roman",
476 "FamilyDecorative", "Decorative",
477 "FamilyModern", "Modern",
478 "FamilyTeletype", "Teletype",
479 "FamilySwiss", "Swiss",
480 "FamilyScript", "Script",
486 "AfmItalic", "${AfmSlant}",
490 "AfmHelvetica", "Helv",
491 "AfmCourier", "Cour",
493 "Afm___", "${AfmTimes,$[weight],$[style]}",
495 "AfmTimes__", "${AfmTimes}${Afm$[weight]}${Afm$[style]}",
496 "AfmTimesMediumStraight", "${AfmTimes}${AfmRoman}",
497 "AfmTimesLightStraight", "${AfmTimes}${AfmRoman}",
498 "AfmTimes_Italic", "${AfmTimes}$[weight]${AfmItalic}",
499 "AfmTimes_Slant", "${AfmTimes}$[weight]${AfmItalic}",
501 "AfmSwiss__", "${AfmHelvetica}${Afm$[weight]}${Afm$[style]}",
502 "AfmModern__", "${AfmCourier}${Afm$[weight]}${Afm$[style]}",
504 "AfmTeletype__", "${AfmModern,$[weight],$[style]}",
506 "PostScriptMediumStraight", "",
507 "PostScriptMediumItalic", "-Oblique",
508 "PostScriptMediumSlant", "-Oblique",
509 "PostScriptLightStraight", "",
510 "PostScriptLightItalic", "-Oblique",
511 "PostScriptLightSlant", "-Oblique",
512 "PostScriptBoldStraight", "-Bold",
513 "PostScriptBoldItalic", "-BoldOblique",
514 "PostScriptBoldSlant", "-BoldOblique",
516 #if WX_NORMALIZED_PS_FONTS
517 "PostScript___", "${PostScriptTimes,$[weight],$[style]}",
519 "PostScriptRoman__", "${PostScriptTimes,$[weight],$[style]}",
520 "PostScript___", "LucidaSans${PostScript$[weight]$[style]}",
523 "PostScriptTimesMedium", "",
524 "PostScriptTimesLight", "",
525 "PostScriptTimesBold", "Bold",
527 "PostScriptTimes__", "Times${PostScript$[weight]$[style]}",
528 "PostScriptTimesMediumStraight", "Times-Roman",
529 "PostScriptTimesLightStraight", "Times-Roman",
530 "PostScriptTimes_Slant", "Times-${PostScriptTimes$[weight]}Italic",
531 "PostScriptTimes_Italic", "Times-${PostScriptTimes$[weight]}Italic",
533 "PostScriptSwiss__", "Helvetica${PostScript$[weight]$[style]}",
534 "PostScriptModern__", "Courier${PostScript$[weight]$[style]}",
536 "PostScriptTeletype__", "${PostScriptModern,$[weight],$[style]}",
538 #if !WX_NORMALIZED_PS_FONTS
539 "PostScriptScript__", "Zapf-Chancery-MediumItalic",
542 "ScreenMedium", "medium",
543 "ScreenBold", "bold",
544 "ScreenLight", "light",
545 "ScreenStraight", "r",
549 "ScreenDefaultBase", "*-times",
551 "ScreenRomanBase", "*-times",
552 "ScreenDecorativeBase", "*-helvetica",
553 "ScreenModernBase", "*-courier",
554 "ScreenTeletypeBase", "*-lucidatypewriter",
555 "ScreenSwissBase", "*-lucida",
556 "ScreenScriptBase", "*-zapfchancery",
558 "ScreenStdSuffix", "-${Screen$[weight]}-${Screen$[style]}"
559 "-normal-*-*-%d-*-*-*-*-*-*",
562 "-${ScreenDefaultBase}${ScreenStdSuffix}",
564 "-${ScreenRomanBase}${ScreenStdSuffix}",
565 "ScreenDecorative__",
566 "-${ScreenDecorativeBase}${ScreenStdSuffix}",
568 "-${ScreenModernBase}${ScreenStdSuffix}",
570 "-${ScreenTeletypeBase}${ScreenStdSuffix}",
572 "-${ScreenSwissBase}${ScreenStdSuffix}",
574 "-${ScreenScriptBase}${ScreenStdSuffix}",
578 enum {wxWEIGHT_NORMAL, wxWEIGHT_BOLD, wxWEIGHT_LIGHT, wxNUM_WEIGHTS};
579 enum {wxSTYLE_NORMAL, wxSTYLE_ITALIC, wxSTYLE_SLANT, wxNUM_STYLES};
581 static int WCoordinate(int w)
585 case wxBOLD: return wxWEIGHT_BOLD;
586 case wxLIGHT: return wxWEIGHT_LIGHT;
588 default: return wxWEIGHT_NORMAL;
592 static int SCoordinate(int s)
596 case wxITALIC: return wxSTYLE_ITALIC;
597 case wxSLANT: return wxSTYLE_SLANT;
599 default: return wxSTYLE_NORMAL;
603 //-----------------------------------------------------------------------------
605 //-----------------------------------------------------------------------------
612 inline char *GetName(int weight, int style)
614 return ( map [WCoordinate(weight)] [SCoordinate(style)] );
617 char *map[wxNUM_WEIGHTS][wxNUM_STYLES];
618 void Initialize(const char *, const char *);
621 static void SearchResource(const char *prefix, const char **names, int count, char **v)
624 char resource[1024], **defaults, *internal;
629 internal = (char *) NULL;
631 for (i = 0; i < k; i++)
633 strcpy(resource, prefix);
634 for (j = 0; j < count; j++)
636 // upon failure to find a matching fontname
637 // in the default fonts above, we substitute more
638 // and more values by _ so that at last ScreenMyFontBoldNormal
639 // would turn into Screen___ and this will then get
640 // converted to -${ScreenDefaultBase}${ScreenStdSuffix}
643 strcat(resource, names[j]);
645 strcat(resource, "_");
648 // we previously search the Xt-resources here
652 defaults = font_defaults;
655 if (!strcmp(*defaults, resource))
657 internal = defaults[1];
667 if ((strcmp(internal,"-${ScreenDefaultBase}${ScreenStdSuffix}") == 0) &&
668 (strcmp(names[0], "Default") != 0))
670 // we did not find any font name in the standard list.
671 // this can (hopefully does) mean that someone supplied
672 // the facename in the wxFont constructor so we insert
675 strcpy( resource,"-*-" ); // any producer
676 strcat( resource, names[0] ); // facename
677 strcat( resource, "${ScreenStdSuffix}" ); // add size params later on
678 *v = copystring(resource);
682 *v = copystring(internal);
687 wxSuffixMap::~wxSuffixMap()
691 for (k = 0; k < wxNUM_WEIGHTS; ++k)
692 for (j = 0; j < wxNUM_STYLES; ++j)
696 map[k][j] = (char *) NULL;
700 void wxSuffixMap::Initialize(const char *resname, const char *devresname)
702 const char *weight, *style;
705 const char *names[3];
707 for (k = 0; k < wxNUM_WEIGHTS; k++)
711 case wxWEIGHT_NORMAL: weight = "Medium"; break;
712 case wxWEIGHT_LIGHT: weight = "Light"; break;
714 default: weight = "Bold";
716 for (j = 0; j < wxNUM_STYLES; j++)
720 case wxSTYLE_NORMAL: style = "Straight"; break;
721 case wxSTYLE_ITALIC: style = "Italic"; break;
723 default: style = "Slant";
729 SearchResource(devresname, names, 3, &v);
731 // Expand macros in the found string:
733 int len, closer = 0, startpos = 0;
735 len = (v ? strlen(v) : 0);
736 for (i = 0; i < len; i++)
738 if (v[i] == '$' && ((v[i+1] == '[') || (v[i+1] == '{')))
741 closer = (v[i+1] == '[') ? ']' : '}';
744 else if (v[i] == closer)
747 const char *r = (char *) NULL; bool delete_r = FALSE;
750 name = v + startpos + 2;
758 for (i = 0, count = 1; name[i]; i++)
764 names = new char*[count];
766 for (i = 0, count = 1; i < len; i++)
769 names[count++] = name + i + 1;
773 SearchResource("", (const char **)names, count, (char **)&r);
779 for (i = 0; i < len; i++)
783 wxLogError( "Bad resource name in font lookup." );
785 } else if (!strcmp(name, "weight")) {
787 } else if (!strcmp(name, "style")) {
789 } else if (!strcmp(name, "family")) {
793 wxLogError( "Bad font macro name." );
797 newstrlen = strlen(r);
798 char *naya = new char[startpos + newstrlen + len - i];
799 memcpy(naya, v, startpos);
800 memcpy(naya + startpos, r, newstrlen);
801 memcpy(naya + startpos + newstrlen, v + i + 1, len - i);
810 // We have a final value:
816 //-----------------------------------------------------------------------------
818 //-----------------------------------------------------------------------------
820 class wxFontNameItem : public wxObject
822 DECLARE_DYNAMIC_CLASS(wxFontNameItem)
824 wxFontNameItem(const char *name, int id, int family);
827 inline char* GetScreenName(int w, int s) {return screen.GetName(w, s);}
828 inline char* GetPostScriptName(int w, int s) {return printing.GetName(w, s);}
829 inline char* GetAFMName(int w, int s) {return afm.GetName(w, s);}
830 inline char* GetName() {return name;}
831 inline int GetFamily() {return family;}
832 inline int GetId() {return id;}
833 inline bool IsRoman() {return isroman;}
834 #if defined(__WXDEBUG__)
835 void Dump(ostream& str);
841 wxSuffixMap screen, printing, afm;
845 IMPLEMENT_ABSTRACT_CLASS(wxFontNameItem, wxObject)
847 wxFontNameItem::wxFontNameItem(const char *Name, int Id, int Family)
849 name = copystring(Name);
853 screen. Initialize(name, "Screen");
854 printing.Initialize(name, "PostScript");
855 afm. Initialize(name, "Afm");
858 wxFontNameItem::~wxFontNameItem()
862 name = (char *) NULL;
865 #if defined(__WXDEBUG__)
866 void wxFontNameItem::Dump(ostream& str)
868 str << "wxFontNameItem(" << name << ")";
872 //-----------------------------------------------------------------------------
874 //-----------------------------------------------------------------------------
876 IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
878 wxFontNameDirectory::wxFontNameDirectory()
880 table = new wxHashTable(wxKEY_INTEGER, 20);
884 wxFontNameDirectory::~wxFontNameDirectory()
886 // Cleanup wxFontNameItems allocated
888 wxNode *node = table->Next();
891 wxFontNameItem *item = (wxFontNameItem*)node->Data();
893 node = table->Next();
898 int wxFontNameDirectory::GetNewFontId()
900 return (nextFontId--);
903 void wxFontNameDirectory::Initialize()
905 Initialize(wxDEFAULT, wxDEFAULT, "Default");
906 Initialize(wxDECORATIVE, wxDECORATIVE, "Decorative");
907 Initialize(wxROMAN, wxROMAN, "Roman");
908 Initialize(wxMODERN, wxMODERN, "Modern");
909 Initialize(wxTELETYPE, wxTELETYPE, "Teletype");
910 Initialize(wxSWISS, wxSWISS, "Swiss");
911 Initialize(wxSCRIPT, wxSCRIPT, "Script");
914 void wxFontNameDirectory::Initialize(int fontid, int family, const char *resname)
916 char *fam, resource[256];
918 sprintf(resource, "Family%s", resname);
919 SearchResource((const char *)resource, (const char **) NULL, 0, (char **)&fam);
923 if (!strcmp(fam, "Default")) family = wxDEFAULT;
924 else if (!strcmp(fam, "Roman")) family = wxROMAN;
925 else if (!strcmp(fam, "Decorative")) family = wxDECORATIVE;
926 else if (!strcmp(fam, "Modern")) family = wxMODERN;
927 else if (!strcmp(fam, "Teletype")) family = wxTELETYPE;
928 else if (!strcmp(fam, "Swiss")) family = wxSWISS;
929 else if (!strcmp(fam, "Script")) family = wxSCRIPT;
930 delete[] fam; // free resource
932 table->Put(fontid, new wxFontNameItem(resname, fontid, family));
935 int wxFontNameDirectory::FindOrCreateFontId(const char *name, int family)
939 // font exists -> return id
940 if ( (id = GetFontId(name)) ) return id;
943 Initialize(id=GetNewFontId(), family, name);
947 char *wxFontNameDirectory::GetScreenName(int fontid, int weight, int style)
949 wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
951 return item->GetScreenName(weight, style);
953 // font does not exist
954 return (char *) NULL;
957 char *wxFontNameDirectory::GetPostScriptName(int fontid, int weight, int style)
959 wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
961 return item->GetPostScriptName(weight, style);
963 // font does not exist
964 return (char *) NULL;
967 char *wxFontNameDirectory::GetAFMName(int fontid, int weight, int style)
969 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
971 return item->GetAFMName(weight, style);
972 // font does not exist
973 return (char *) NULL;
976 char *wxFontNameDirectory::GetFontName(int fontid)
978 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
980 return item->GetName();
982 // font does not exist
983 return (char *) NULL;
986 int wxFontNameDirectory::GetFontId(const char *name)
992 while ( (node = table->Next()) )
994 wxFontNameItem *item = (wxFontNameItem*)node->Data();
995 if (!strcmp(name, item->name))
999 // font does not exist
1003 int wxFontNameDirectory::GetFamily(int fontid)
1005 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid);
1008 return item->family;
1010 // font does not exist