]>
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
= FALSE
,
112 const wxString
& face
= wxEmptyString
)
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
)
165 return m_refData
== font
.m_refData
;
168 bool wxFont::operator != ( const wxFont
& font
)
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, "invalid font" );
182 return M_FONTDATA
->m_pointSize
;
185 wxString
wxFont::GetFaceName() const
187 wxCHECK_MSG( Ok(), "", "invalid font" );
189 return M_FONTDATA
->m_faceName
;
192 int wxFont::GetFamily() const
194 wxCHECK_MSG( Ok(), 0, "invalid font" );
196 return M_FONTDATA
->m_family
;
199 wxString
wxFont::GetFamilyString() const
201 wxCHECK_MSG( Ok(), "wxDEFAULT", "invalid font" );
203 switch (M_FONTDATA
->m_family
)
205 case wxDECORATIVE
: return wxString("wxDECORATIVE");
206 case wxROMAN
: return wxString("wxROMAN");
207 case wxSCRIPT
: return wxString("wxSCRIPT");
208 case wxSWISS
: return wxString("wxSWISS");
209 case wxMODERN
: return wxString("wxMODERN");
210 case wxTELETYPE
: return wxString("wxTELETYPE");
211 default: return "wxDEFAULT";
217 int wxFont::GetStyle() const
219 wxCHECK_MSG( Ok(), 0, "invalid font" );
221 return M_FONTDATA
->m_style
;
224 wxString
wxFont::GetStyleString() const
226 wxCHECK_MSG( Ok(), "wxDEFAULT", "invalid font" );
228 switch (M_FONTDATA
->m_style
)
230 case wxNORMAL
: return wxString("wxNORMAL");
231 case wxSLANT
: return wxString("wxSLANT");
232 case wxITALIC
: return wxString("wxITALIC");
233 default: return wxString("wxDEFAULT");
236 return wxString("wxDEFAULT");
239 int wxFont::GetWeight() const
241 wxCHECK_MSG( Ok(), 0, "invalid font" );
243 return M_FONTDATA
->m_weight
;
246 wxString
wxFont::GetWeightString() const
248 wxCHECK_MSG( Ok(), "wxDEFAULT", "invalid font" );
250 switch (M_FONTDATA
->m_weight
)
252 case wxNORMAL
: return wxString("wxNORMAL");
253 case wxBOLD
: return wxString("wxBOLD");
254 case wxLIGHT
: return wxString("wxLIGHT");
255 default: return wxString("wxDEFAULT");
258 return wxString("wxDEFAULT");
261 bool wxFont::GetUnderlined() const
263 wxCHECK_MSG( Ok(), FALSE
, "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( "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("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 char *xfamily
= (char*) NULL
;
388 char *xstyle
= (char*) NULL
;
389 char *xweight
= (char*) NULL
;
393 case wxDECORATIVE
: xfamily
= "lucida"; break;
394 case wxROMAN
: xfamily
= "times"; break;
395 case wxMODERN
: xfamily
= "courier"; break;
396 case wxSWISS
: xfamily
= "helvetica"; break;
397 case wxTELETYPE
: xfamily
= "lucidatypewriter"; break;
398 case wxSCRIPT
: xfamily
= "utopia"; break;
399 default: xfamily
= "*";
402 if (!facename
.IsEmpty())
404 sprintf( wxBuffer
, "-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*", facename
.c_str() );
405 GdkFont
*test
= gdk_font_load( wxBuffer
);
408 gdk_font_unref( test
);
409 xfamily
= WXSTRINGCAST facename
;
415 case wxITALIC
: xstyle
= "i"; break;
416 case wxSLANT
: xstyle
= "o"; break;
417 case wxNORMAL
: xstyle
= "r"; break;
418 default: xstyle
= "*"; break;
422 case wxBOLD
: xweight
= "bold"; break;
424 case wxNORMAL
: xweight
= "medium"; break;
425 default: xweight
= "*"; break;
428 sprintf( wxBuffer
, "-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-*-*",
429 xfamily
, xweight
, xstyle
, pointSize
);
431 return gdk_font_load( 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));
445 /* Search for smaller size (approx.) */
446 for (int i
=point_size
-10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10)
447 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
, facename
);
449 /* Search for larger size (approx.) */
450 for (int i
=point_size
+10; !font
&& i
<= max_size
; i
+= 10)
451 font
= wxLoadQueryFont( i
, family
, style
, weight
, underlined
, facename
);
453 /* Try default family */
454 if (!font
&& family
!= wxDEFAULT
)
455 font
= wxLoadQueryFont( point_size
, wxDEFAULT
, style
, weight
, underlined
, facename
);
459 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
, underlined
, facename
);
467 //-----------------------------------------------------------------------------
468 // face names and index functions
469 //-----------------------------------------------------------------------------
471 static char *font_defaults[] = {
472 "FamilyDefault", "Default",
473 "FamilyRoman", "Roman",
474 "FamilyDecorative", "Decorative",
475 "FamilyModern", "Modern",
476 "FamilyTeletype", "Teletype",
477 "FamilySwiss", "Swiss",
478 "FamilyScript", "Script",
484 "AfmItalic", "${AfmSlant}",
488 "AfmHelvetica", "Helv",
489 "AfmCourier", "Cour",
491 "Afm___", "${AfmTimes,$[weight],$[style]}",
493 "AfmTimes__", "${AfmTimes}${Afm$[weight]}${Afm$[style]}",
494 "AfmTimesMediumStraight", "${AfmTimes}${AfmRoman}",
495 "AfmTimesLightStraight", "${AfmTimes}${AfmRoman}",
496 "AfmTimes_Italic", "${AfmTimes}$[weight]${AfmItalic}",
497 "AfmTimes_Slant", "${AfmTimes}$[weight]${AfmItalic}",
499 "AfmSwiss__", "${AfmHelvetica}${Afm$[weight]}${Afm$[style]}",
500 "AfmModern__", "${AfmCourier}${Afm$[weight]}${Afm$[style]}",
502 "AfmTeletype__", "${AfmModern,$[weight],$[style]}",
504 "PostScriptMediumStraight", "",
505 "PostScriptMediumItalic", "-Oblique",
506 "PostScriptMediumSlant", "-Oblique",
507 "PostScriptLightStraight", "",
508 "PostScriptLightItalic", "-Oblique",
509 "PostScriptLightSlant", "-Oblique",
510 "PostScriptBoldStraight", "-Bold",
511 "PostScriptBoldItalic", "-BoldOblique",
512 "PostScriptBoldSlant", "-BoldOblique",
514 #if WX_NORMALIZED_PS_FONTS
515 "PostScript___", "${PostScriptTimes,$[weight],$[style]}",
517 "PostScriptRoman__", "${PostScriptTimes,$[weight],$[style]}",
518 "PostScript___", "LucidaSans${PostScript$[weight]$[style]}",
521 "PostScriptTimesMedium", "",
522 "PostScriptTimesLight", "",
523 "PostScriptTimesBold", "Bold",
525 "PostScriptTimes__", "Times${PostScript$[weight]$[style]}",
526 "PostScriptTimesMediumStraight", "Times-Roman",
527 "PostScriptTimesLightStraight", "Times-Roman",
528 "PostScriptTimes_Slant", "Times-${PostScriptTimes$[weight]}Italic",
529 "PostScriptTimes_Italic", "Times-${PostScriptTimes$[weight]}Italic",
531 "PostScriptSwiss__", "Helvetica${PostScript$[weight]$[style]}",
532 "PostScriptModern__", "Courier${PostScript$[weight]$[style]}",
534 "PostScriptTeletype__", "${PostScriptModern,$[weight],$[style]}",
536 #if !WX_NORMALIZED_PS_FONTS
537 "PostScriptScript__", "Zapf-Chancery-MediumItalic",
540 "ScreenMedium", "medium",
541 "ScreenBold", "bold",
542 "ScreenLight", "light",
543 "ScreenStraight", "r",
547 "ScreenDefaultBase", "*-times",
549 "ScreenRomanBase", "*-times",
550 "ScreenDecorativeBase", "*-helvetica",
551 "ScreenModernBase", "*-courier",
552 "ScreenTeletypeBase", "*-lucidatypewriter",
553 "ScreenSwissBase", "*-lucida",
554 "ScreenScriptBase", "*-zapfchancery",
556 "ScreenStdSuffix", "-${Screen$[weight]}-${Screen$[style]}"
557 "-normal-*-*-%d-*-*-*-*-*-*",
560 "-${ScreenDefaultBase}${ScreenStdSuffix}",
562 "-${ScreenRomanBase}${ScreenStdSuffix}",
563 "ScreenDecorative__",
564 "-${ScreenDecorativeBase}${ScreenStdSuffix}",
566 "-${ScreenModernBase}${ScreenStdSuffix}",
568 "-${ScreenTeletypeBase}${ScreenStdSuffix}",
570 "-${ScreenSwissBase}${ScreenStdSuffix}",
572 "-${ScreenScriptBase}${ScreenStdSuffix}",
576 enum {wxWEIGHT_NORMAL, wxWEIGHT_BOLD, wxWEIGHT_LIGHT, wxNUM_WEIGHTS};
577 enum {wxSTYLE_NORMAL, wxSTYLE_ITALIC, wxSTYLE_SLANT, wxNUM_STYLES};
579 static int WCoordinate(int w)
583 case wxBOLD: return wxWEIGHT_BOLD;
584 case wxLIGHT: return wxWEIGHT_LIGHT;
586 default: return wxWEIGHT_NORMAL;
590 static int SCoordinate(int s)
594 case wxITALIC: return wxSTYLE_ITALIC;
595 case wxSLANT: return wxSTYLE_SLANT;
597 default: return wxSTYLE_NORMAL;
601 //-----------------------------------------------------------------------------
603 //-----------------------------------------------------------------------------
610 inline char *GetName(int weight, int style)
612 return ( map [WCoordinate(weight)] [SCoordinate(style)] );
615 char *map[wxNUM_WEIGHTS][wxNUM_STYLES];
616 void Initialize(const char *, const char *);
619 static void SearchResource(const char *prefix, const char **names, int count, char **v)
622 char resource[1024], **defaults, *internal;
627 internal = (char *) NULL;
629 for (i = 0; i < k; i++)
631 strcpy(resource, prefix);
632 for (j = 0; j < count; j++)
634 // upon failure to find a matching fontname
635 // in the default fonts above, we substitute more
636 // and more values by _ so that at last ScreenMyFontBoldNormal
637 // would turn into Screen___ and this will then get
638 // converted to -${ScreenDefaultBase}${ScreenStdSuffix}
641 strcat(resource, names[j]);
643 strcat(resource, "_");
646 // we previously search the Xt-resources here
650 defaults = font_defaults;
653 if (!strcmp(*defaults, resource))
655 internal = defaults[1];
665 if ((strcmp(internal,"-${ScreenDefaultBase}${ScreenStdSuffix}") == 0) &&
666 (strcmp(names[0], "Default") != 0))
668 // we did not find any font name in the standard list.
669 // this can (hopefully does) mean that someone supplied
670 // the facename in the wxFont constructor so we insert
673 strcpy( resource,"-*-" ); // any producer
674 strcat( resource, names[0] ); // facename
675 strcat( resource, "${ScreenStdSuffix}" ); // add size params later on
676 *v = copystring(resource);
680 *v = copystring(internal);
685 wxSuffixMap::~wxSuffixMap()
689 for (k = 0; k < wxNUM_WEIGHTS; ++k)
690 for (j = 0; j < wxNUM_STYLES; ++j)
694 map[k][j] = (char *) NULL;
698 void wxSuffixMap::Initialize(const char *resname, const char *devresname)
700 const char *weight, *style;
703 const char *names[3];
705 for (k = 0; k < wxNUM_WEIGHTS; k++)
709 case wxWEIGHT_NORMAL: weight = "Medium"; break;
710 case wxWEIGHT_LIGHT: weight = "Light"; break;
712 default: weight = "Bold";
714 for (j = 0; j < wxNUM_STYLES; j++)
718 case wxSTYLE_NORMAL: style = "Straight"; break;
719 case wxSTYLE_ITALIC: style = "Italic"; break;
721 default: style = "Slant";
727 SearchResource(devresname, names, 3, &v);
729 // Expand macros in the found string:
731 int len, closer = 0, startpos = 0;
733 len = (v ? strlen(v) : 0);
734 for (i = 0; i < len; i++)
736 if (v[i] == '$' && ((v[i+1] == '[') || (v[i+1] == '{')))
739 closer = (v[i+1] == '[') ? ']' : '}';
742 else if (v[i] == closer)
745 const char *r = (char *) NULL; bool delete_r = FALSE;
748 name = v + startpos + 2;
756 for (i = 0, count = 1; name[i]; i++)
762 names = new char*[count];
764 for (i = 0, count = 1; i < len; i++)
767 names[count++] = name + i + 1;
771 SearchResource("", (const char **)names, count, (char **)&r);
777 for (i = 0; i < len; i++)
781 wxLogError( "Bad resource name in font lookup." );
783 } else if (!strcmp(name, "weight")) {
785 } else if (!strcmp(name, "style")) {
787 } else if (!strcmp(name, "family")) {
791 wxLogError( "Bad font macro name." );
795 newstrlen = strlen(r);
796 char *naya = new char[startpos + newstrlen + len - i];
797 memcpy(naya, v, startpos);
798 memcpy(naya + startpos, r, newstrlen);
799 memcpy(naya + startpos + newstrlen, v + i + 1, len - i);
808 // We have a final value:
814 //-----------------------------------------------------------------------------
816 //-----------------------------------------------------------------------------
818 class wxFontNameItem : public wxObject
820 DECLARE_DYNAMIC_CLASS(wxFontNameItem)
822 wxFontNameItem(const char *name, int id, int family);
825 inline char* GetScreenName(int w, int s) {return screen.GetName(w, s);}
826 inline char* GetPostScriptName(int w, int s) {return printing.GetName(w, s);}
827 inline char* GetAFMName(int w, int s) {return afm.GetName(w, s);}
828 inline char* GetName() {return name;}
829 inline int GetFamily() {return family;}
830 inline int GetId() {return id;}
831 inline bool IsRoman() {return isroman;}
832 #if defined(__WXDEBUG__)
833 void Dump(ostream& str);
839 wxSuffixMap screen, printing, afm;
843 IMPLEMENT_ABSTRACT_CLASS(wxFontNameItem, wxObject)
845 wxFontNameItem::wxFontNameItem(const char *Name, int Id, int Family)
847 name = copystring(Name);
851 screen. Initialize(name, "Screen");
852 printing.Initialize(name, "PostScript");
853 afm. Initialize(name, "Afm");
856 wxFontNameItem::~wxFontNameItem()
860 name = (char *) NULL;
863 #if defined(__WXDEBUG__)
864 void wxFontNameItem::Dump(ostream& str)
866 str << "wxFontNameItem(" << name << ")";
870 //-----------------------------------------------------------------------------
872 //-----------------------------------------------------------------------------
874 IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
876 wxFontNameDirectory::wxFontNameDirectory()
878 table = new wxHashTable(wxKEY_INTEGER, 20);
882 wxFontNameDirectory::~wxFontNameDirectory()
884 // Cleanup wxFontNameItems allocated
886 wxNode *node = table->Next();
889 wxFontNameItem *item = (wxFontNameItem*)node->Data();
891 node = table->Next();
896 int wxFontNameDirectory::GetNewFontId()
898 return (nextFontId--);
901 void wxFontNameDirectory::Initialize()
903 Initialize(wxDEFAULT, wxDEFAULT, "Default");
904 Initialize(wxDECORATIVE, wxDECORATIVE, "Decorative");
905 Initialize(wxROMAN, wxROMAN, "Roman");
906 Initialize(wxMODERN, wxMODERN, "Modern");
907 Initialize(wxTELETYPE, wxTELETYPE, "Teletype");
908 Initialize(wxSWISS, wxSWISS, "Swiss");
909 Initialize(wxSCRIPT, wxSCRIPT, "Script");
912 void wxFontNameDirectory::Initialize(int fontid, int family, const char *resname)
914 char *fam, resource[256];
916 sprintf(resource, "Family%s", resname);
917 SearchResource((const char *)resource, (const char **) NULL, 0, (char **)&fam);
921 if (!strcmp(fam, "Default")) family = wxDEFAULT;
922 else if (!strcmp(fam, "Roman")) family = wxROMAN;
923 else if (!strcmp(fam, "Decorative")) family = wxDECORATIVE;
924 else if (!strcmp(fam, "Modern")) family = wxMODERN;
925 else if (!strcmp(fam, "Teletype")) family = wxTELETYPE;
926 else if (!strcmp(fam, "Swiss")) family = wxSWISS;
927 else if (!strcmp(fam, "Script")) family = wxSCRIPT;
928 delete[] fam; // free resource
930 table->Put(fontid, new wxFontNameItem(resname, fontid, family));
933 int wxFontNameDirectory::FindOrCreateFontId(const char *name, int family)
937 // font exists -> return id
938 if ( (id = GetFontId(name)) ) return id;
941 Initialize(id=GetNewFontId(), family, name);
945 char *wxFontNameDirectory::GetScreenName(int fontid, int weight, int style)
947 wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
949 return item->GetScreenName(weight, style);
951 // font does not exist
952 return (char *) NULL;
955 char *wxFontNameDirectory::GetPostScriptName(int fontid, int weight, int style)
957 wxFontNameItem *item = (wxFontNameItem*)table->Get(fontid); // find font
959 return item->GetPostScriptName(weight, style);
961 // font does not exist
962 return (char *) NULL;
965 char *wxFontNameDirectory::GetAFMName(int fontid, int weight, int style)
967 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
969 return item->GetAFMName(weight, style);
970 // font does not exist
971 return (char *) NULL;
974 char *wxFontNameDirectory::GetFontName(int fontid)
976 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid); // find font
978 return item->GetName();
980 // font does not exist
981 return (char *) NULL;
984 int wxFontNameDirectory::GetFontId(const char *name)
990 while ( (node = table->Next()) )
992 wxFontNameItem *item = (wxFontNameItem*)node->Data();
993 if (!strcmp(name, item->name))
997 // font does not exist
1001 int wxFontNameDirectory::GetFamily(int fontid)
1003 wxFontNameItem *item = (wxFontNameItem *)table->Get(fontid);
1006 return item->family;
1008 // font does not exist