- if (!Ok())
- {
- wxFAIL_MSG( "invalid font" );
- return 0;
- }
-
- return M_FONTDATA->m_fontId; // stub
-}
-
-int wxFont::GetStyle(void) const
-{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid font" );
- return 0;
- }
-
- return M_FONTDATA->m_style;
-}
-
-wxString wxFont::GetStyleString(void) const
-{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid font" );
- return "wxDEFAULT";
- }
-
- switch (M_FONTDATA->m_style)
- {
- case wxNORMAL: return wxString("wxNORMAL");
- case wxSLANT: return wxString("wxSLANT");
- case wxITALIC: return wxString("wxITALIC");
- default: return wxString("wxDEFAULT");
- }
-
- return wxString("wxDEFAULT");
-}
-
-int wxFont::GetWeight(void) const
-{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid font" );
- return 0;
- }
-
- return M_FONTDATA->m_weight;
-}
-
-wxString wxFont::GetWeightString(void) const
-{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid font" );
- return "wxDEFAULT";
- }
-
- switch (M_FONTDATA->m_weight)
- {
- case wxNORMAL: return wxString("wxNORMAL");
- case wxBOLD: return wxString("wxBOLD");
- case wxLIGHT: return wxString("wxLIGHT");
- default: return wxString("wxDEFAULT");
- }
-
- return wxString("wxDEFAULT");
-}
-
-bool wxFont::GetUnderlined(void) const
-{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid font" );
- return FALSE;
- }
-
- return M_FONTDATA->m_underlined;
-}
-
-//-----------------------------------------------------------------------------
-// get internal representation of font
-//-----------------------------------------------------------------------------
-
-// local help function
-static GdkFont *wxLoadQueryNearestFont(int point_size, int fontid,
- int style, int weight,
- bool underlined);
-
-GdkFont *wxFont::GetInternalFont(float scale) const
-{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid font" );
- return (GdkFont*) NULL;
- }
-
- if (M_FONTDATA->m_byXFontName) return M_FONTDATA->m_font;
-
- long int_scale = long(scale * 100.0 + 0.5); // key for fontlist
- int point_scale = (M_FONTDATA->m_pointSize * 10 * int_scale) / 100;
- GdkFont *font = (GdkFont *) NULL;
-
- wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale);
- if (node)
- {
- font = (GdkFont*)node->Data();
- }
- else
- {
- if ((int_scale == 100) &&
- (M_FONTDATA->m_style == wxSWISS) &&
- (M_FONTDATA->m_pointSize == 12) &&
- (M_FONTDATA->m_weight == wxNORMAL) &&
- (M_FONTDATA->m_underlined == FALSE) &&
- (M_FONTDATA->m_style == wxNORMAL))
- {
- font = gdk_font_load( "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*" );
- }
- else
- {
- font = wxLoadQueryNearestFont( point_scale, M_FONTDATA->m_fontId, M_FONTDATA->m_style,
- M_FONTDATA->m_weight, M_FONTDATA->m_underlined );
- }
- M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
- }
- if (!font)
- printf("could not load any font");
-// wxError("could not load any font", "wxFont");
- return font;
-}
-
-//-----------------------------------------------------------------------------
-// local utilities to find a X font
-//-----------------------------------------------------------------------------
-
-static GdkFont *wxLoadQueryFont(int point_size, int fontid, int style,
- int weight, bool WXUNUSED(underlined))
-{
- char buffer[512];
- char *name = wxTheFontNameDirectory->GetScreenName( fontid, weight, style );
-
- if (!name)
- name = "-*-*-*-*-*-*-*-%d-*-*-*-*-*-*";
- sprintf(buffer, name, point_size);
-
- return gdk_font_load( buffer );
-}
-
-static GdkFont *wxLoadQueryNearestFont(int point_size, int fontid,
- int style, int weight,
- bool underlined)
-{
- GdkFont *font;
-
- font = wxLoadQueryFont( point_size, fontid, style, weight, underlined );
-
- if (!font) {
- // search up and down by stepsize 10
- int max_size = point_size + 20 * (1 + (point_size/180));
- int min_size = point_size - 20 * (1 + (point_size/180));
- int i;
-
- // Search for smaller size (approx.)
- for (i=point_size-10; !font && i >= 10 && i >= min_size; i -= 10)
- font = wxLoadQueryFont(i, fontid, style, weight, underlined);
- // Search for larger size (approx.)
- for (i=point_size+10; !font && i <= max_size; i += 10)
- font = wxLoadQueryFont(i, fontid, style, weight, underlined);
- // Try default family
- if (!font && fontid != wxDEFAULT)
- font = wxLoadQueryFont(point_size, wxDEFAULT, style,
- weight, underlined);
- // Bogus font
- if (!font)
- font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
- underlined);
- }
- return font;
-}
-
-//-----------------------------------------------------------------------------
-// face names and index functions
-//-----------------------------------------------------------------------------
-
-static char *font_defaults[] = {
- "FamilyDefault", "Default",
- "FamilyRoman", "Roman",
- "FamilyDecorative", "Decorative",
- "FamilyModern", "Modern",
- "FamilyTeletype", "Teletype",
- "FamilySwiss", "Swiss",
- "FamilyScript", "Script",
-
- "AfmMedium", "",
- "AfmBold", "Bo",
- "AfmLight", "",
- "AfmStraight", "",
- "AfmItalic", "${AfmSlant}",
- "AfmSlant", "O",
- "AfmRoman", "Ro",
- "AfmTimes", "Times",
- "AfmHelvetica", "Helv",
- "AfmCourier", "Cour",
-
- "Afm___", "${AfmTimes,$[weight],$[style]}",
-
- "AfmTimes__", "${AfmTimes}${Afm$[weight]}${Afm$[style]}",
- "AfmTimesMediumStraight", "${AfmTimes}${AfmRoman}",
- "AfmTimesLightStraight", "${AfmTimes}${AfmRoman}",
- "AfmTimes_Italic", "${AfmTimes}$[weight]${AfmItalic}",
- "AfmTimes_Slant", "${AfmTimes}$[weight]${AfmItalic}",
-
- "AfmSwiss__", "${AfmHelvetica}${Afm$[weight]}${Afm$[style]}",
- "AfmModern__", "${AfmCourier}${Afm$[weight]}${Afm$[style]}",
-
- "AfmTeletype__", "${AfmModern,$[weight],$[style]}",
-
- "PostScriptMediumStraight", "",
- "PostScriptMediumItalic", "-Oblique",
- "PostScriptMediumSlant", "-Oblique",
- "PostScriptLightStraight", "",
- "PostScriptLightItalic", "-Oblique",
- "PostScriptLightSlant", "-Oblique",
- "PostScriptBoldStraight", "-Bold",
- "PostScriptBoldItalic", "-BoldOblique",
- "PostScriptBoldSlant", "-BoldOblique",
-
-#if WX_NORMALIZED_PS_FONTS
- "PostScript___", "${PostScriptTimes,$[weight],$[style]}",
-#else
- "PostScriptRoman__", "${PostScriptTimes,$[weight],$[style]}",
- "PostScript___", "LucidaSans${PostScript$[weight]$[style]}",
-#endif