stop using gkd_pango_context_get() in ArdourCanvas::Canvas and require concrete insta...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 13 Oct 2016 21:11:38 +0000 (17:11 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 13 Oct 2016 21:18:54 +0000 (17:18 -0400)
libs/canvas/canvas.cc
libs/canvas/canvas/canvas.h
libs/canvas/text.cc
libs/surfaces/push2/canvas.cc
libs/surfaces/push2/canvas.h

index 22c586090ed123d6a907af4a78b361c23c828821..92100c9ce1dbe09ae950a8c2957b23dd5ef2a5af 100644 (file)
@@ -1259,6 +1259,12 @@ GtkCanvas::hide_tooltip ()
        }
 }
 
+Glib::RefPtr<Pango::Context>
+GtkCanvas::get_pango_context ()
+{
+       return Glib::wrap (gdk_pango_context_get());
+}
+
 /** Create a GtkCanvaSViewport.
  *  @param hadj Adjustment to use for horizontal scrolling.
  *  @param vadj Adjustment to use for vertica scrolling.
index b818c7eb4170ae38dee28d2fd13eba8a73d958fd..7731b8533b536ec6d8f95c58e2f53cb72f0c460e 100644 (file)
@@ -43,6 +43,10 @@ namespace Gtk {
        class Label;
 }
 
+namespace Pango {
+       class Context;
+}
+
 namespace ArdourCanvas
 {
 struct Rect;
@@ -154,7 +158,9 @@ public:
         */
        static void set_tooltip_timeout (uint32_t msecs);
 
-protected:
+       virtual Glib::RefPtr<Pango::Context> get_pango_context() = 0;
+
+  protected:
        Root  _root;
         Color _bg_color;
 
@@ -195,7 +201,9 @@ public:
        void start_tooltip_timeout (Item*);
        void stop_tooltip_timeout ();
 
-protected:
+       Glib::RefPtr<Pango::Context> get_pango_context();
+
+  protected:
        void on_size_allocate (Gtk::Allocation&);
        bool on_scroll_event (GdkEventScroll *);
        bool on_expose_event (GdkEventExpose *);
index fb38423dec22887ac82fa8a70111c08e58272aba..735b9b87f82e6edf7489b70edbe46d931dbcc051 100644 (file)
@@ -106,7 +106,8 @@ void
 Text::_redraw () const
 {
        assert (!_text.empty());
-       Glib::RefPtr<Pango::Context> context = Glib::wrap (gdk_pango_context_get());
+       assert (_canvas);
+       Glib::RefPtr<Pango::Context> context = _canvas->get_pango_context();
        Glib::RefPtr<Pango::Layout> layout = Pango::Layout::create (context);
 
 #ifdef __APPLE__
index 52a8534f5e90793e80d7f28d4395df8959efb7da..6a8d046aa9f3b41b5ef5b2e73679195d32287ab4 100644 (file)
 
 */
 
+#include <vector>
+
 #include <cairomm/region.h>
 #include <cairomm/surface.h>
 #include <cairomm/context.h>
 
 #include "pbd/compose.h"
+#include "pbd/error.h"
+#include "pbd/i18n.h"
 
 #include "ardour/debug.h"
 
@@ -233,3 +237,26 @@ Push2Canvas::visible_area () const
        /* may need to get more sophisticated once we do scrolling */
        return Rect (0, 0, 960, 160);
 }
+
+Glib::RefPtr<Pango::Context>
+Push2Canvas::get_pango_context ()
+{
+       if (!pango_context) {
+               PangoFontMap* map = pango_cairo_font_map_get_default ();
+               if (!map) {
+                       error << _("Default Cairo font map is null!") << endmsg;
+                       return Glib::RefPtr<Pango::Context> ();
+               }
+
+               PangoContext* context = pango_font_map_create_context (map);
+
+               if (!context) {
+                       error << _("cannot create new PangoContext from cairo font map") << endmsg;
+                       return Glib::RefPtr<Pango::Context> ();
+               }
+
+               pango_context = Glib::wrap (context);
+       }
+
+       return pango_context;
+}
index e3343e3296beadeb05c41f4fcc6099c5137ceb0d..fe419f44ba6723107146d1cfdca873eddb2b1aea 100644 (file)
@@ -69,6 +69,8 @@ class Push2Canvas : public ArdourCanvas::Canvas
        void pick_current_item (ArdourCanvas::Duple const &, int) {}
        bool get_mouse_position (ArdourCanvas::Duple&) const { return false; }
 
+       Glib::RefPtr<Pango::Context> get_pango_context ();
+
   private:
        Push2& p2;
        int _cols;
@@ -83,6 +85,7 @@ class Push2Canvas : public ArdourCanvas::Canvas
        Cairo::RefPtr<Cairo::ImageSurface> frame_buffer;
        Cairo::RefPtr<Cairo::Context> context;
        Cairo::RefPtr<Cairo::Region> expose_region;
+       Glib::RefPtr<Pango::Context> pango_context;
 
        bool expose ();
        int blit_to_device_frame_buffer ();