]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow constructing wxGTK wxTextMeasure with NULL font.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 1 Nov 2012 17:15:15 +0000 (17:15 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 1 Nov 2012 17:15:15 +0000 (17:15 +0000)
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

include/wx/gtk/private/textmeasure.h
include/wx/private/textmeasure.h
src/common/textmeasurecmn.cpp
src/gtk/textmeasure.cpp

index c7fc712ea7303ee65fa102eee6cba372ffec44ce..5027be7b3539ef29aaee92a5d75a18f275d58379 100644 (file)
@@ -49,7 +49,6 @@ protected:
                                          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
index ebd6a612141a1d2496c7263e9212ec6a7558dbcc..4788c992eda29c2ca3a55bb7356065538519396e 100644 (file)
@@ -23,7 +23,8 @@ class wxTextMeasureBase
 {
 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);
 
@@ -123,6 +124,10 @@ protected:
                            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.
index f45de698c12d6aa43596f0d5f39b3a115aa66d5f..4db3b892fba74583cbe06b494414eb638972a237 100644 (file)
@@ -53,6 +53,13 @@ wxTextMeasureBase::wxTextMeasureBase(const wxWindow *win, const wxFont *theFont)
     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,
index 2032a45df0d771696f3db6aae72d5a1f9f1df652..7320111f0e51a33644d8dee6a829a469a107e0c4 100644 (file)
@@ -40,8 +40,6 @@
 
 void wxTextMeasure::Init()
 {
-    wxASSERT_MSG( m_font, wxT("wxTextMeasure needs a valid wxFont") );
-
     m_context = NULL;
     m_layout = NULL;
 
@@ -87,7 +85,7 @@ void wxTextMeasure::BeginMeasuring()
     if ( m_layout )
     {
         pango_layout_set_font_description(m_layout,
-                                          m_font->GetNativeFontInfo()->description);
+                                          GetFont().GetNativeFontInfo()->description);
     }
 }
 
@@ -124,7 +122,7 @@ void wxTextMeasure::DoGetTextExtent(const wxString& string,
     }
 
     // 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?
@@ -167,7 +165,7 @@ bool wxTextMeasure::DoGetPartialTextExtents(const wxString& text,
                                             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?