-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) printf( "int_scale.\n" );
- if (M_FONTDATA->m_style == wxSWISS) printf( "swiss.\n" );
- if (M_FONTDATA->m_pointSize == 12) printf( "12.\n" );
- if (M_FONTDATA->m_weight == wxNORMAL) printf( "normal.\n" );
- if (M_FONTDATA->m_underlined == FALSE) printf( "false.\n" );
-*/
- if ((int_scale == 100) &&
- (M_FONTDATA->m_family == wxSWISS) &&
- (M_FONTDATA->m_style == wxNORMAL) &&
- (M_FONTDATA->m_pointSize == 12) &&
- (M_FONTDATA->m_weight == wxNORMAL) &&
- (M_FONTDATA->m_underlined == FALSE))
- {
- 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);