]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/textmeasure.cpp
Disable wxUSE_ENH_METAFILE for wxGTK builds.
[wxWidgets.git] / src / gtk / textmeasure.cpp
index f32df4af087c39cb190362df67a161d58ecd6023..87bc7c90d5b0e6310d85c927fb22d5c4c82126d5 100644 (file)
@@ -3,6 +3,7 @@
 // Purpose:     wxTextMeasure implementation for wxGTK
 // Author:      Manuel Martin
 // Created:     2012-10-05
 // Purpose:     wxTextMeasure implementation for wxGTK
 // Author:      Manuel Martin
 // Created:     2012-10-05
+// RCS-ID:      $Id:
 // Copyright:   (c) 1997-2012 wxWidgets team
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) 1997-2012 wxWidgets team
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
 #ifndef WX_PRECOMP
     #include "wx/window.h"
 
 #ifndef WX_PRECOMP
     #include "wx/window.h"
+    #include "wx/log.h"
 #endif //WX_PRECOMP
 
 #include "wx/private/textmeasure.h"
 
 #include "wx/fontutil.h"
 #include "wx/gtk/private.h"
 #endif //WX_PRECOMP
 
 #include "wx/private/textmeasure.h"
 
 #include "wx/fontutil.h"
 #include "wx/gtk/private.h"
+#include "wx/gtk/dc.h"
 
 #ifndef __WXGTK3__
     #include "wx/gtk/dcclient.h"
 
 #ifndef __WXGTK3__
     #include "wx/gtk/dcclient.h"
 
 void wxTextMeasure::Init()
 {
 
 void wxTextMeasure::Init()
 {
-    wxASSERT_MSG( m_font, wxT("wxTextMeasure needs a valid wxFont") );
+    m_context = NULL;
+    m_layout = NULL;
 
 #ifndef __WXGTK3__
     m_wdc = NULL;
 
 #ifndef __WXGTK3__
     m_wdc = NULL;
+
+    if ( m_dc )
+    {
+        wxClassInfo* const ci = m_dc->GetImpl()->GetClassInfo();
+
+        // Currently the code here only works with wxWindowDCImpl and only in
+        // wxGTK2 as wxGTK3 uses Cairo and not Pango for all its DCs.
+        if ( ci->IsKindOf(wxCLASSINFO(wxWindowDCImpl)))
+        {
+            m_useDCImpl = false;
+        }
+    }
 #endif // GTK+ < 3
 #endif // GTK+ < 3
-    m_context = NULL;
-    m_layout = NULL;
 }
 
 // Get Gtk needed elements, if we have not them yet.
 }
 
 // Get Gtk needed elements, if we have not them yet.
@@ -71,7 +85,7 @@ void wxTextMeasure::BeginMeasuring()
     if ( m_layout )
     {
         pango_layout_set_font_description(m_layout,
     if ( m_layout )
     {
         pango_layout_set_font_description(m_layout,
-                                          m_font->GetNativeFontInfo()->description);
+                                          GetFont().GetNativeFontInfo()->description);
     }
 }
 
     }
 }
 
@@ -102,14 +116,17 @@ void wxTextMeasure::DoGetTextExtent(const wxString& string,
 {
     if ( !m_context )
     {
 {
     if ( !m_context )
     {
-        *width =
-        *height = 0;
+        if ( width )
+            *width = 0;
+
+        if ( height )
+            *height = 0;
         return;
     }
 
     // Set layout's text
         return;
     }
 
     // Set layout's text
-    const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, *m_font);
-    if ( !dataUTF8 )
+    const wxCharBuffer dataUTF8 = wxGTK_CONV_FONT(string, GetFont());
+    if ( !dataUTF8 && !string.empty() )
     {
         // hardly ideal, but what else can we do if conversion failed?
         wxLogLastError(wxT("GetTextExtent"));
     {
         // hardly ideal, but what else can we do if conversion failed?
         wxLogLastError(wxT("GetTextExtent"));
@@ -148,10 +165,13 @@ void wxTextMeasure::DoGetTextExtent(const wxString& string,
 
 bool wxTextMeasure::DoGetPartialTextExtents(const wxString& text,
                                             wxArrayInt& widths,
 
 bool wxTextMeasure::DoGetPartialTextExtents(const wxString& text,
                                             wxArrayInt& widths,
-                                            double WXUNUSED(scaleX))
+                                            double scaleX)
 {
 {
+    if ( !m_layout )
+        return wxTextMeasureBase::DoGetPartialTextExtents(text, widths, scaleX);
+
     // Set layout's text
     // 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?
     if ( !dataUTF8 )
     {
         // hardly ideal, but what else can we do if conversion failed?