The font is explicitly documented as being possibly NULL in the base class and
wxMSW handles NULL font just fine, so also handle it in the GTK version.
See #14706.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72844
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
wxArrayInt& widths,
double scaleX);
-
// This class is only used for DC text measuring with GTK+ 2 as GTK+ 3 uses
// Cairo and not Pango for this. However it's still used even with GTK+ 3
// for window text measuring, so the context and the layout are still
{
public:
// The first ctor argument must be non-NULL, i.e. each object of this class
- // is associated with either a valid wxDC or a valid wxWindow.
+ // is associated with either a valid wxDC or a valid wxWindow. The font can
+ // be NULL to use the current DC/window font or can be specified explicitly.
wxTextMeasureBase(const wxDC *dc, const wxFont *theFont);
wxTextMeasureBase(const wxWindow *win, const wxFont *theFont);
wxCoord *descent = NULL,
wxCoord *externalLeading = NULL);
+ // Return a valid font: if one was given to us in the ctor, use this one,
+ // otherwise use the current font of the associated wxDC or wxWindow.
+ wxFont GetFont() const;
+
// Exactly one of m_dc and m_win is non-NULL for any given object of this
// class.
m_useDCImpl = false;
}
+wxFont wxTextMeasureBase::GetFont() const
+{
+ return m_font ? *m_font
+ : m_win ? m_win->GetFont()
+ : m_dc->GetFont();
+}
+
void wxTextMeasureBase::CallGetTextExtent(const wxString& string,
wxCoord *width,
wxCoord *height,
void wxTextMeasure::Init()
{
- wxASSERT_MSG( m_font, wxT("wxTextMeasure needs a valid wxFont") );
-
m_context = NULL;
m_layout = NULL;
if ( m_layout )
{
pango_layout_set_font_description(m_layout,
- m_font->GetNativeFontInfo()->description);
+ GetFont().GetNativeFontInfo()->description);
}
}
}
// Set layout's text
- const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, *m_font);
+ const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, GetFont());
if ( !dataUTF8 )
{
// hardly ideal, but what else can we do if conversion failed?
double WXUNUSED(scaleX))
{
// Set layout's text
- const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(text, *m_font);
+ const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(text, GetFont());
if ( !dataUTF8 )
{
// hardly ideal, but what else can we do if conversion failed?