Corrected GetCharWidth() and GetCharHeight()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17580 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2002-10-20 11:20:32 +00:00
parent cd12eca16a
commit 09cb4267da
2 changed files with 44 additions and 0 deletions

View File

@@ -1651,18 +1651,40 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
wxCoord wxWindowDC::GetCharWidth() const wxCoord wxWindowDC::GetCharWidth() const
{ {
#ifdef __WXGTK20__
// There should be an easier way.
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_text(layout, "H", 1 );
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
g_object_unref( G_OBJECT( layout ) );
return w;
#else
GdkFont *font = m_font.GetInternalFont( m_scaleY ); GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, wxT("invalid font") ); wxCHECK_MSG( font, -1, wxT("invalid font") );
return wxCoord(gdk_string_width( font, "H" ) / m_scaleX); return wxCoord(gdk_string_width( font, "H" ) / m_scaleX);
#endif
} }
wxCoord wxWindowDC::GetCharHeight() const wxCoord wxWindowDC::GetCharHeight() const
{ {
#ifdef __WXGTK20__
// There should be an easier way.
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_text(layout, "H", 1 );
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
g_object_unref( G_OBJECT( layout ) );
return h;
#else
GdkFont *font = m_font.GetInternalFont( m_scaleY ); GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, wxT("invalid font") ); wxCHECK_MSG( font, -1, wxT("invalid font") );
return wxCoord((font->ascent + font->descent) / m_scaleY); return wxCoord((font->ascent + font->descent) / m_scaleY);
#endif
} }
void wxWindowDC::Clear() void wxWindowDC::Clear()

View File

@@ -1651,18 +1651,40 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
wxCoord wxWindowDC::GetCharWidth() const wxCoord wxWindowDC::GetCharWidth() const
{ {
#ifdef __WXGTK20__
// There should be an easier way.
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_text(layout, "H", 1 );
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
g_object_unref( G_OBJECT( layout ) );
return w;
#else
GdkFont *font = m_font.GetInternalFont( m_scaleY ); GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, wxT("invalid font") ); wxCHECK_MSG( font, -1, wxT("invalid font") );
return wxCoord(gdk_string_width( font, "H" ) / m_scaleX); return wxCoord(gdk_string_width( font, "H" ) / m_scaleX);
#endif
} }
wxCoord wxWindowDC::GetCharHeight() const wxCoord wxWindowDC::GetCharHeight() const
{ {
#ifdef __WXGTK20__
// There should be an easier way.
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_text(layout, "H", 1 );
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
g_object_unref( G_OBJECT( layout ) );
return h;
#else
GdkFont *font = m_font.GetInternalFont( m_scaleY ); GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, wxT("invalid font") ); wxCHECK_MSG( font, -1, wxT("invalid font") );
return wxCoord((font->ascent + font->descent) / m_scaleY); return wxCoord((font->ascent + font->descent) / m_scaleY);
#endif
} }
void wxWindowDC::Clear() void wxWindowDC::Clear()