]>
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"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
26 extern wxFontNameDirectory *wxTheFontNameDirectory;
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
33 class wxFontRefData
: public wxObjectRefData
38 wxFontRefData( const wxFontRefData
& data
);
41 wxList m_scaled_xfonts
;
43 int m_family
, m_style
, m_weight
;
53 wxFontRefData::wxFontRefData() : m_scaled_xfonts(wxKEY_INTEGER
)
55 m_byXFontName
= FALSE
;
61 m_font
= (GdkFont
*) NULL
;
64 wxFontRefData::wxFontRefData( const wxFontRefData
& data
) : m_scaled_xfonts(wxKEY_INTEGER
)
66 m_byXFontName
= FALSE
;
67 m_pointSize
= data
.m_pointSize
;
68 m_family
= data
.m_family
;
69 m_style
= data
.m_style
;
70 m_weight
= data
.m_weight
;
71 m_underlined
= data
.m_underlined
;
72 m_faceName
= data
.m_faceName
;
73 m_font
= (GdkFont
*) NULL
;
74 if (data
.m_font
) m_font
= gdk_font_ref( data
.m_font
);
77 wxFontRefData::~wxFontRefData()
79 wxNode
*node
= m_scaled_xfonts
.First();
82 GdkFont
*font
= (GdkFont
*)node
->Data();
83 wxNode
*next
= node
->Next();
84 gdk_font_unref( font
);
87 if (m_font
) gdk_font_unref( m_font
);
90 //-----------------------------------------------------------------------------
92 #define M_FONTDATA ((wxFontRefData *)m_refData)
94 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
98 if (wxTheFontList
) wxTheFontList
->Append( this );
101 wxFont::wxFont( char *xFontName
)
103 if (!xFontName
) return;
105 m_refData
= new wxFontRefData();
107 M_FONTDATA
->m_byXFontName
= TRUE
;
108 M_FONTDATA
->m_font
= gdk_font_load( xFontName
);
111 wxFont::wxFont( int pointSize
, int family
, int style
, int weight
, bool underlined
, const wxString
& face
)
113 m_refData
= new wxFontRefData();
115 if (family
== wxDEFAULT
)
116 M_FONTDATA
->m_family
= wxSWISS
;
118 M_FONTDATA
->m_family
= family
;
120 if (!face
.IsEmpty()) M_FONTDATA
->m_faceName
= face
;
122 if (style
== wxDEFAULT
)
123 M_FONTDATA
->m_style
= wxNORMAL
;
125 M_FONTDATA
->m_style
= style
;
127 if (weight
== wxDEFAULT
)
128 M_FONTDATA
->m_weight
= wxNORMAL
;
130 M_FONTDATA
->m_weight
= weight
;
132 if (pointSize
== wxDEFAULT
)
133 M_FONTDATA
->m_pointSize
= 12;
135 M_FONTDATA
->m_pointSize
= pointSize
;
137 M_FONTDATA
->m_underlined
= underlined
;
139 if (wxTheFontList
) wxTheFontList
->Append( this );
143 wxFont::wxFont( const wxFont
& font
)
147 if (wxTheFontList
) wxTheFontList
->Append( this );
152 if (wxTheFontList
) wxTheFontList
->DeleteObject( this );
155 wxFont
& wxFont::operator = ( const wxFont
& font
)
157 if (*this == font
) return (*this);
162 bool wxFont::operator == ( const wxFont
& font
) const
164 return m_refData
== font
.m_refData
;
167 bool wxFont::operator != ( const wxFont
& font
) const
169 return m_refData
!= font
.m_refData
;
172 bool wxFont::Ok() const
174 return (m_refData
!= NULL
);
177 int wxFont::GetPointSize() const
179 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
181 return M_FONTDATA
->m_pointSize
;
184 wxString
wxFont::GetFaceName() const
186 wxCHECK_MSG( Ok(), _T(""), _T("invalid font") );
188 return M_FONTDATA
->m_faceName
;
191 int wxFont::GetFamily() const
193 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
195 return M_FONTDATA
->m_family
;
198 wxString
wxFont::GetFamilyString() const
200 wxCHECK_MSG( Ok(), _T("wxDEFAULT"), _T("invalid font") );
202 switch (M_FONTDATA
->m_family
)
204 case wxDECORATIVE
: return wxString(_T("wxDECORATIVE"));
205 case wxROMAN
: return wxString(_T("wxROMAN"));
206 case wxSCRIPT
: return wxString(_T("wxSCRIPT"));
207 case wxSWISS
: return wxString(_T("wxSWISS"));
208 case wxMODERN
: return wxString(_T("wxMODERN"));
209 case wxTELETYPE
: return wxString(_T("wxTELETYPE"));
210 default: return _T("wxDEFAULT");
216 int wxFont::GetStyle() const
218 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
220 return M_FONTDATA
->m_style
;
223 wxString
wxFont::GetStyleString() const
225 wxCHECK_MSG( Ok(), _T("wxDEFAULT"), _T("invalid font") );
227 switch (M_FONTDATA
->m_style
)
229 case wxNORMAL
: return wxString(_T("wxNORMAL"));
230 case wxSLANT
: return wxString(_T("wxSLANT"));
231 case wxITALIC
: return wxString(_T("wxITALIC"));
232 default: return wxString(_T("wxDEFAULT"));
235 return wxString(_T("wxDEFAULT"));
238 int wxFont::GetWeight() const
240 wxCHECK_MSG( Ok(), 0, _T("invalid font") );
242 return M_FONTDATA
->m_weight
;
245 wxString
wxFont::GetWeightString() const
247 wxCHECK_MSG( Ok(), _T("wxDEFAULT"), _T("invalid font") );
249 switch (M_FONTDATA
->m_weight
)
251 case wxNORMAL
: return wxString(_T("wxNORMAL"));
252 case wxBOLD
: return wxString(_T("wxBOLD"));
253 case wxLIGHT
: return wxString(_T("wxLIGHT"));
254 default: return wxString(_T("wxDEFAULT"));
257 return wxString(_T("wxDEFAULT"));
260 bool wxFont::GetUnderlined() const
262 wxCHECK_MSG( Ok(), FALSE
, _T("invalid font") );
264 return M_FONTDATA
->m_underlined
;
267 void wxFont::Unshare()
271 m_refData
= new wxFontRefData();
275 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
281 void wxFont::SetPointSize(int pointSize
)
285 M_FONTDATA
->m_pointSize
= pointSize
;
288 void wxFont::SetFamily(int family
)
292 M_FONTDATA
->m_family
= family
;
295 void wxFont::SetStyle(int style
)
299 M_FONTDATA
->m_style
= style
;
302 void wxFont::SetWeight(int weight
)
306 M_FONTDATA
->m_weight
= weight
;
309 void wxFont::SetFaceName(const wxString
& faceName
)
313 M_FONTDATA
->m_faceName
= faceName
;
316 void wxFont::SetUnderlined(bool underlined
)
320 M_FONTDATA
->m_underlined
= underlined
;
323 //-----------------------------------------------------------------------------
324 // get internal representation of font
325 //-----------------------------------------------------------------------------
327 static GdkFont
*wxLoadQueryNearestFont( int point_size
, int family
, int style
, int weight
,
328 bool underlined
, const wxString
&facename
);
330 GdkFont
*wxFont::GetInternalFont( float scale
) const
334 wxFAIL_MSG( _T("invalid font") );
335 return (GdkFont
*) NULL
;
338 /* short cut if the special X font constructor has been used */
339 if (M_FONTDATA
->m_byXFontName
) return M_FONTDATA
->m_font
;
341 long int_scale
= long(scale
* 100.0 + 0.5); /* key for fontlist */
342 int point_scale
= (M_FONTDATA
->m_pointSize
* 10 * int_scale
) / 100;
343 GdkFont
*font
= (GdkFont
*) NULL
;
345 wxNode
*node
= M_FONTDATA
->m_scaled_xfonts
.Find(int_scale
);
348 font
= (GdkFont
*)node
->Data();
353 if ((int_scale == 100) &&
354 (M_FONTDATA->m_family == wxSWISS) &&
355 (M_FONTDATA->m_style == wxNORMAL) &&
356 (M_FONTDATA->m_pointSize == 12) &&
357 (M_FONTDATA->m_weight == wxNORMAL) &&
358 (M_FONTDATA->m_underlined == FALSE))
360 font = gdk_font_load( "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*" );
365 font
= wxLoadQueryNearestFont( point_scale
, M_FONTDATA
->m_family
, M_FONTDATA
->m_style
,
366 M_FONTDATA
->m_weight
, M_FONTDATA
->m_underlined
, M_FONTDATA
->m_faceName
);
368 M_FONTDATA
->m_scaled_xfonts
.Append( int_scale
, (wxObject
*)font
);
373 wxLogError(_T("could not load any font"));
379 //-----------------------------------------------------------------------------
380 // local utilities to find a X font
381 //-----------------------------------------------------------------------------
383 static GdkFont
*wxLoadQueryFont( int pointSize
, int family
, int style
, int weight
,
384 bool underlined
, const wxString
&facename
)
386 wxChar
*xfamily
= (wxChar
*) NULL
;
387 wxChar
*xstyle
= (wxChar
*) NULL
;
388 wxChar
*xweight
= (wxChar
*) NULL
;
392 case wxDECORATIVE
: xfamily
= _T("lucida"); break;
393 case wxROMAN
: xfamily
= _T("times"); break;
394 case wxMODERN
: xfamily
= _T("courier"); break;
395 case wxSWISS
: xfamily
= _T("helvetica"); break;
396 case wxTELETYPE
: xfamily
= _T("lucidatypewriter"); break;
397 case wxSCRIPT
: xfamily
= _T("utopia"); break;
398 default: xfamily
= _T("*");
401 if (!facename
.IsEmpty())
403 wxSprintf( wxBuffer
, _T("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"), facename
.c_str() );
404 GdkFont
*test
= gdk_font_load( wxConv_libc
.cWX2MB(wxBuffer
) );
407 gdk_font_unref( test
);
408 xfamily
= WXSTRINGCAST facename
;
414 case wxITALIC
: xstyle
= _T("i"); break;
415 case wxSLANT
: xstyle
= _T("o"); break;
416 case wxNORMAL
: xstyle
= _T("r"); break;
417 default: xstyle
= _T("*"); break;
421 case wxBOLD
: xweight
= _T("bold"); break;
423 case wxNORMAL
: xweight
= _T("medium"); break;
424 default: xweight
= _T("*"); break;
427 wxSprintf( wxBuffer
, _T("-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-*-*"),
428 xfamily
, xweight
, xstyle
, pointSize
);
430 return gdk_font_load( wxConv_libc
.cWX2MB(wxBuffer
) );
433 static GdkFont
*wxLoadQueryNearestFont( int point_size
, int family
, int style
, int weight
,
434 bool underlined
, const wxString
&facename
)
436 GdkFont
*font
= wxLoadQueryFont( point_size
, family
, style
, weight
, underlined
, facename
);
440 /* search up and down by stepsize 10 */
441 int max_size
= point_size
+ 20 * (1 + (point_size
/180));
442 int min_size
= point_size
- 20 * (1 + (point_size
/180));
446 /* Search for smaller size (approx.) */
447 for (i
=point_size
-10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10)
448 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
, facename
);
450 /* Search for larger size (approx.) */
451 for (i
=point_size
+10; !font
&& i
<= max_size
; i
+= 10)
452 font
= wxLoadQueryFont( i
, family
, style
, weight
, underlined
, facename
);
454 /* Try default family */
455 if (!font
&& family
!= wxDEFAULT
)
456 font
= wxLoadQueryFont( point_size
, wxDEFAULT
, style
, weight
, underlined
, facename
);
460 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
, underlined
, facename
);
468 //-----------------------------------------------------------------------------
469 // face names and index functions
470 //-----------------------------------------------------------------------------
472 static char *font_defaults[] = {
473 "FamilyDefault", "Default",
474 "FamilyRoman", "Roman",
475 "FamilyDecorative", "Decorative",
476 "FamilyModern", "Modern",
477 "FamilyTeletype", "Teletype",
478 "FamilySwiss", "Swiss",
479 "FamilyScript", "Script",
485 "AfmItalic", "${AfmSlant}",
489 "AfmHelvetica", "Helv",
490 "AfmCourier", "Cour",
492 "Afm___", "${AfmTimes,$[weight],$[style]}",
494 "AfmTimes__", "${AfmTimes}${Afm$[weight]}${Afm$[style]}",
495 "AfmTimesMediumStraight", "${AfmTimes}${AfmRoman}",
496 "AfmTimesLightStraight", "${AfmTimes}${AfmRoman}",
497 "AfmTimes_Italic", "${AfmTimes}$[weight]${AfmItalic}",
498 "AfmTimes_Slant", "${AfmTimes}$[weight]${AfmItalic}",
500 "AfmSwiss__", "${AfmHelvetica}${Afm$[weight]}${Afm$[style]}",
501 "AfmModern__", "${AfmCourier}${Afm$[weight]}${Afm$[style]}",
503 "AfmTeletype__", "${AfmModern,$[weight],$[style]}",
505 "PostScriptMediumStraight", "",
506 "PostScriptMediumItalic", "-Oblique",
507 "PostScriptMediumSlant", "-Oblique",
508 "PostScriptLightStraight", "",
509 "PostScriptLightItalic", "-Oblique",
510 "PostScriptLightSlant", "-Oblique",
511 "PostScriptBoldStraight", "-Bold",
512 "PostScriptBoldItalic", "-BoldOblique",
513 "PostScriptBoldSlant", "-BoldOblique",
515 #if WX_NORMALIZED_PS_FONTS
516 "PostScript___", "${PostScriptTimes,$[weight],$[style]}",
518 "PostScriptRoman__", "${PostScriptTimes,$[weight],$[style]}",
519 "PostScript___", "LucidaSans${PostScript$[weight]$[style]}",
522 "PostScriptTimesMedium", "",
523 "PostScriptTimesLight", "",
524 "PostScriptTimesBold", "Bold",
526 "PostScriptTimes__", "Times${PostScript$[weight]$[style]}",
527 "PostScriptTimesMediumStraight", "Times-Roman",
528 "PostScriptTimesLightStraight", "Times-Roman",
529 "PostScriptTimes_Slant", "Times-${PostScriptTimes$[weight]}Italic",
530 "PostScriptTimes_Italic", "Times-${PostScriptTimes$[weight]}Italic",
532 "PostScriptSwiss__", "Helvetica${PostScript$[weight]$[style]}",
533 "PostScriptModern__", "Courier${PostScript$[weight]$[style]}",
535 "PostScriptTeletype__", "${PostScriptModern,$[weight],$[style]}",
537 #if !WX_NORMALIZED_PS_FONTS
538 "PostScriptScript__", "Zapf-Chancery-MediumItalic",
541 "ScreenMedium", "medium",
542 "ScreenBold", "bold",
543 "ScreenLight", "light",
544 "ScreenStraight", "r",
548 "ScreenDefaultBase", "*-times",
550 "ScreenRomanBase", "*-times",
551 "ScreenDecorativeBase", "*-helvetica",
552 "ScreenModernBase", "*-courier",
553 "ScreenTeletypeBase", "*-lucidatypewriter",
554 "ScreenSwissBase", "*-lucida",
555 "ScreenScriptBase", "*-zapfchancery",
557 "ScreenStdSuffix", "-${Screen$[weight]}-${Screen$[style]}"
558 "-normal-*-*-%d-*-*-*-*-*-*",
561 "-${ScreenDefaultBase}${ScreenStdSuffix}",
563 "-${ScreenRomanBase}${ScreenStdSuffix}",
564 "ScreenDecorative__",
565 "-${ScreenDecorativeBase}${ScreenStdSuffix}",
567 "-${ScreenModernBase}${ScreenStdSuffix}",
569 "-${ScreenTeletypeBase}${ScreenStdSuffix}",
571 "-${ScreenSwissBase}${ScreenStdSuffix}",
573 "-${ScreenScriptBase}${ScreenStdSuffix}",
577 enum {wxWEIGHT_NORMAL, wxWEIGHT_BOLD, wxWEIGHT_LIGHT, wxNUM_WEIGHTS};
578 enum {wxSTYLE_NORMAL, wxSTYLE_ITALIC, wxSTYLE_SLANT, wxNUM_STYLES};
580 static int WCoordinate(int w)
584 case wxBOLD: return wxWEIGHT_BOLD;
585 case wxLIGHT: return wxWEIGHT_LIGHT;
587 default: return wxWEIGHT_NORMAL;
591 static int SCoordinate(int s)
595 case wxITALIC: return wxSTYLE_ITALIC;
596 case wxSLANT: return wxSTYLE_SLANT;
598 default: return wxSTYLE_NORMAL;
602 //-----------------------------------------------------------------------------
604 //-----------------------------------------------------------------------------
611 inline char *GetName(int weight, int style)
613 return ( map [WCoordinate(weight)] [SCoordinate(style)] );
616 char *map[wxNUM_WEIGHTS][wxNUM_STYLES];
617 void Initialize(const char *, const char *);
620 static void SearchResource(const char *prefix, const char **names, int count, char **v)
623 char resource[1024], **defaults, *internal;
628 internal = (char *) NULL;
630 for (i = 0; i < k; i++)
632 strcpy(resource, prefix);
633 for (j = 0; j < count; j++)
635 // upon failure to find a matching fontname
636 // in the default fonts above, we substitute more
637 // and more values by _ so that at last ScreenMyFontBoldNormal
638 // would turn into Screen___ and this will then get
639 // converted to -${ScreenDefaultBase}${ScreenStdSuffix}
642 strcat(resource, names[j]);
644 strcat(resource, "_");
647 // we previously search the Xt-resources here
651 defaults = font_defaults;
654 if (!strcmp(*defaults, resource))
656 internal = defaults[1];
666 if ((strcmp(internal,"-${ScreenDefaultBase}${ScreenStdSuffix}") == 0) &&
667 (strcmp(names[0], "Default") != 0))
669 // we did not find any font name in the standard list.
670 // this can (hopefully does) mean that someone supplied
671 // the facename in the wxFont constructor so we insert
674 strcpy( resource,"-*-" ); // any producer
675 strcat( resource, names[0] ); // facename
676 strcat( resource, "${ScreenStdSuffix}" ); // add size params later on
677 *v = copystring(resource);
681 *v = copystring(internal);
686 wxSuffixMap::~wxSuffixMap()
690 for (k = 0; k < wxNUM_WEIGHTS; ++k)
691 for (j = 0; j < wxNUM_STYLES; ++j)
695 map[k][j] = (char *) NULL;
699 void wxSuffixMap::Initialize(const char *resname, const char *devresname)
701 const char *weight, *style;
704 const char *names[3];
706 for (k = 0; k < wxNUM_WEIGHTS; k++)
710 case wxWEIGHT_NORMAL: weight = "Medium"; break;
711 case wxWEIGHT_LIGHT: weight = "Light"; break;
713 default: weight = "Bold";
715 for (j = 0; j < wxNUM_STYLES; j++)
719 case wxSTYLE_NORMAL: style = "Straight"; break;
720 case wxSTYLE_ITALIC: style = "Italic"; break;
722 default: style = "Slant";
728 SearchResource(devresname, names, 3, &v);
730 // Expand macros in the found string:
732 int len, closer = 0, startpos = 0;
734 len = (v ? strlen(v) : 0);
735 for (i = 0; i < len; i++)
737 if (v[i] == '$' && ((v[i+1] == '[') || (v[i+1] == '{')))
740 closer = (v[i+1] == '[') ? ']' : '}';
743 else if (v[i] == closer)
746 const char *r = (char *) NULL; bool delete_r = FALSE;
749 name = v + startpos + 2;
757 for (i = 0, count = 1; name[i]; i++)
763 names = new char*[count];
765 for (i = 0, count = 1; i < len; i++)
768 names[count++] = name + i + 1;
772 SearchResource("", (const char **)names, count, (char **)&r);
778 for (i = 0; i < len; i++)
782 wxLogError( "Bad resource name in font lookup." );
784 } else if (!strcmp(name, "weight")) {
786 } else if (!strcmp(name, "style")) {
788 } else if (!strcmp(name, "family")) {
792 wxLogError( "Bad font macro name." );
796 newstrlen = strlen(r);
797 char *naya = new char[startpos + newstrlen + len - i];
798 memcpy(naya, v, startpos);
799 memcpy(naya + startpos, r, newstrlen);
800 memcpy(naya + startpos + newstrlen, v + i + 1, len - i);
809 // We have a final value:
815 //-----------------------------------------------------------------------------
817 //-----------------------------------------------------------------------------
819 class wxFontNameItem : public wxObject
821 DECLARE_DYNAMIC_CLASS(wxFontNameItem)
823 wxFontNameItem(const char *name, int id, int family);
826 inline char* GetScreenName(int w, int s) {return screen.GetName(w, s);}
827 inline char* GetPostScriptName(int w, int s) {return printing.GetName(w, s);}
828 inline char* GetAFMName(int w, int s) {return afm.GetName(w, s);}
829 inline char* GetName() {return name;}
830 inline int GetFamily() {return family;}
831 inline int GetId() {return id;}
832 inline bool IsRoman() {return isroman;}
833 #if defined(__WXDEBUG__)
834 void Dump(ostream& str);
840 wxSuffixMap screen, printing, afm;
844 IMPLEMENT_ABSTRACT_CLASS(wxFontNameItem, wxObject)
846 wxFontNameItem::wxFontNameItem(const char *Name, int Id, int Family)
848 name = copystring(Name);
852 screen. Initialize(name, "Screen");
853 printing.Initialize(name, "PostScript");
854 afm. Initialize(name, "Afm");
857 wxFontNameItem::~wxFontNameItem()
861 name = (char *) NULL;
864 #if defined(__WXDEBUG__)
865 void wxFontNameItem::Dump(ostream& str)
867 str << "wxFontNameItem(" << name << ")";
871 //-----------------------------------------------------------------------------
873 //-----------------------------------------------------------------------------
875 IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
877 wxFontNameDirectory::wxFontNameDirectory()
879 table = new wxHashTable(wxKEY_INTEGER, 20);
883 wxFontNameDirectory::~wxFontNameDirectory()
885 // Cleanup wxFontNameItems allocated
887 wxNode *node = table->Next();
890 wxFontNameItem *item = (wxFontNameItem*)node->Data();
892 node = table->Next();
897 int wxFontNameDirectory::GetNewFontId()
899 return (nextFontId--);
902 void wxFontNameDirectory::Initialize()
904 Initialize(wxDEFAULT, wxDEFAULT, "Default");
905 Initialize(wxDECORATIVE, wxDECORATIVE, "Decorative");
906 Initialize(wxROMAN, wxROMAN, "Roman");
907 Initialize(wxMODERN, wxMODERN, "Modern");
908 Initialize(wxTELETYPE, wxTELETYPE, "Teletype");
909 Initialize(wxSWISS, wxSWISS, "Swiss");
910 Initialize(wxSCRIPT, wxSCRIPT, "Script");
913 void wxFontNameDirectory::Initialize(int fontid, int family, const char *resname)
915 char *fam, resource[256];
917 sprintf(resource, "Family%s", resname);
918 SearchResource((const char *)resource, (const char **) NULL, 0, (char **)&fam);
922 if (!strcmp(fam, "Default")) family = wxDEFAULT;
923 else if (!strcmp(fam, "Roman")) family = wxROMAN;
924 else if (!strcmp(fam, "Decorative")) family = wxDECORATIVE;
925 else if (!strcmp(fam, "Modern")) family = wxMODERN;
926 else if (!strcmp(fam, "Teletype")) family = wxTELETYPE;
927 else if (!strcmp(fam, "Swiss")) family = wxSWISS;
928 else if (!strcmp(fam, "Script")) family = wxSCRIPT;
929 delete[] fam; // free resource
931 table->Put(fontid, new wxFontNameItem(resname, fontid, family));
934 int wxFontNameDirectory::FindOrCreateFontId(const char *name, int family)
938 // font exists -> return id
939 if ( (id = GetFontId(name)) ) return id;
942 Initialize(id=GetNewFontId(), family, name);
946 char *wxFontNameDirectory::GetScreenName(int fontid, int weight, int style)
948 wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
950 return item->GetScreenName(weight, style);
952 // font does not exist
953 return (char *) NULL;
956 char *wxFontNameDirectory::GetPostScriptName(int fontid, int weight, int style)
958 wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
960 return item->GetPostScriptName(weight, style);
962 // font does not exist
963 return (char *) NULL;
966 char *wxFontNameDirectory::GetAFMName(int fontid, int weight, int style)
968 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
970 return item->GetAFMName(weight, style);
971 // font does not exist
972 return (char *) NULL;
975 char *wxFontNameDirectory::GetFontName(int fontid)
977 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
979 return item->GetName();
981 // font does not exist
982 return (char *) NULL;
985 int wxFontNameDirectory::GetFontId(const char *name)
991 while ( (node = table->Next()) )
993 wxFontNameItem *item = (wxFontNameItem*)node->Data();
994 if (!strcmp(name, item->name))
998 // font does not exist
1002 int wxFontNameDirectory::GetFamily(int fontid)
1004 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid);
1007 return item->family;
1009 // font does not exist