don't crash under GTK1 if we failed to get GdkFont in GetTextExtent()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29217 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1711,10 +1711,17 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
|
|||||||
wxCoord *descent, wxCoord *externalLeading,
|
wxCoord *descent, wxCoord *externalLeading,
|
||||||
wxFont *theFont) const
|
wxFont *theFont) const
|
||||||
{
|
{
|
||||||
|
if ( width )
|
||||||
|
*width = 0;
|
||||||
|
if ( height )
|
||||||
|
*height = 0;
|
||||||
|
if ( descent )
|
||||||
|
*descent = 0;
|
||||||
|
if ( externalLeading )
|
||||||
|
*externalLeading = 0;
|
||||||
|
|
||||||
if (string.IsEmpty())
|
if (string.IsEmpty())
|
||||||
{
|
{
|
||||||
if (width) (*width) = 0;
|
|
||||||
if (height) (*height) = 0;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1761,21 +1768,25 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
|
|||||||
pango_layout_iter_free(iter);
|
pango_layout_iter_free(iter);
|
||||||
*descent = h - PANGO_PIXELS(baseline);
|
*descent = h - PANGO_PIXELS(baseline);
|
||||||
}
|
}
|
||||||
if (externalLeading)
|
|
||||||
*externalLeading = 0; // ??
|
|
||||||
|
|
||||||
// Reset old font description
|
// Reset old font description
|
||||||
if (theFont)
|
if (theFont)
|
||||||
pango_layout_set_font_description( m_layout, m_fontdesc );
|
pango_layout_set_font_description( m_layout, m_fontdesc );
|
||||||
#else // GTK+ 1.x
|
#else // GTK+ 1.x
|
||||||
wxFont fontToUse = m_font;
|
wxFont fontToUse = m_font;
|
||||||
if (theFont) fontToUse = *theFont;
|
if (theFont)
|
||||||
|
fontToUse = *theFont;
|
||||||
|
|
||||||
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
||||||
if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
if ( !font )
|
||||||
if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY);
|
return;
|
||||||
if (descent) (*descent) = wxCoord(font->descent / m_scaleY);
|
|
||||||
if (externalLeading) (*externalLeading) = 0; // ??
|
if (width)
|
||||||
|
*width = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
||||||
|
if (height)
|
||||||
|
*height = wxCoord((font->ascent + font->descent) / m_scaleY);
|
||||||
|
if (descent)
|
||||||
|
*descent = wxCoord(font->descent / m_scaleY);
|
||||||
#endif // GTK+ 2/1
|
#endif // GTK+ 2/1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1711,10 +1711,17 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
|
|||||||
wxCoord *descent, wxCoord *externalLeading,
|
wxCoord *descent, wxCoord *externalLeading,
|
||||||
wxFont *theFont) const
|
wxFont *theFont) const
|
||||||
{
|
{
|
||||||
|
if ( width )
|
||||||
|
*width = 0;
|
||||||
|
if ( height )
|
||||||
|
*height = 0;
|
||||||
|
if ( descent )
|
||||||
|
*descent = 0;
|
||||||
|
if ( externalLeading )
|
||||||
|
*externalLeading = 0;
|
||||||
|
|
||||||
if (string.IsEmpty())
|
if (string.IsEmpty())
|
||||||
{
|
{
|
||||||
if (width) (*width) = 0;
|
|
||||||
if (height) (*height) = 0;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1761,21 +1768,25 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
|
|||||||
pango_layout_iter_free(iter);
|
pango_layout_iter_free(iter);
|
||||||
*descent = h - PANGO_PIXELS(baseline);
|
*descent = h - PANGO_PIXELS(baseline);
|
||||||
}
|
}
|
||||||
if (externalLeading)
|
|
||||||
*externalLeading = 0; // ??
|
|
||||||
|
|
||||||
// Reset old font description
|
// Reset old font description
|
||||||
if (theFont)
|
if (theFont)
|
||||||
pango_layout_set_font_description( m_layout, m_fontdesc );
|
pango_layout_set_font_description( m_layout, m_fontdesc );
|
||||||
#else // GTK+ 1.x
|
#else // GTK+ 1.x
|
||||||
wxFont fontToUse = m_font;
|
wxFont fontToUse = m_font;
|
||||||
if (theFont) fontToUse = *theFont;
|
if (theFont)
|
||||||
|
fontToUse = *theFont;
|
||||||
|
|
||||||
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
GdkFont *font = fontToUse.GetInternalFont( m_scaleY );
|
||||||
if (width) (*width) = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
if ( !font )
|
||||||
if (height) (*height) = wxCoord((font->ascent + font->descent) / m_scaleY);
|
return;
|
||||||
if (descent) (*descent) = wxCoord(font->descent / m_scaleY);
|
|
||||||
if (externalLeading) (*externalLeading) = 0; // ??
|
if (width)
|
||||||
|
*width = wxCoord(gdk_string_width( font, string.mbc_str() ) / m_scaleX);
|
||||||
|
if (height)
|
||||||
|
*height = wxCoord((font->ascent + font->descent) / m_scaleY);
|
||||||
|
if (descent)
|
||||||
|
*descent = wxCoord(font->descent / m_scaleY);
|
||||||
#endif // GTK+ 2/1
|
#endif // GTK+ 2/1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user