audun's tempo redraw fix; sort-of cache time axis view item name widths and avoid...
[ardour.git] / gtk2_ardour / utils.cc
index 1057773ae704195be8006686a13462f4ea885ca7..9c1ef22a88c579ebcd38e08a3f24d270eeb0d538 100644 (file)
@@ -44,6 +44,20 @@ using namespace sigc;
 using namespace Glib;
 using namespace PBD;
 
+int
+pixel_width (const ustring& str, Pango::FontDescription& font)
+{
+       Label foo;
+       Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout ("");
+
+       layout->set_font_description (font);
+       layout->set_text (str);
+
+       int width, height;
+       Gtkmm2ext::get_ink_pixel_size (layout, width, height);
+       return width;
+}
+
 ustring
 fit_to_pixels (const ustring& str, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses)
 {
@@ -119,7 +133,7 @@ xpm2rgb (const char** xpm, uint32_t& w, uint32_t& h)
                return 0;
        }
 
-       savergb = rgb = (unsigned char*)art_alloc (h * w * 3);
+       savergb = rgb = (unsigned char*) malloc (h * w * 3);
        
        // LOAD XPM COLORMAP LONG ENOUGH TO DO CONVERSION
        for (t = 0; t < colors; ++t) {
@@ -162,7 +176,7 @@ xpm2rgba (const char** xpm, uint32_t& w, uint32_t& h)
                return 0;
        }
 
-       savergb = rgb = (unsigned char*)art_alloc (h * w * 4);
+       savergb = rgb = (unsigned char*) malloc (h * w * 4);
        
        // LOAD XPM COLORMAP LONG ENOUGH TO DO CONVERSION
 
@@ -232,7 +246,21 @@ get_font_for_style (string widgetname)
        foobar.ensure_style();
 
        style = foobar.get_style ();
-       return style->get_font();
+
+       Glib::RefPtr<const Pango::Layout> layout = foobar.get_layout();
+       
+       PangoFontDescription *pfd = (PangoFontDescription *)pango_layout_get_font_description((PangoLayout *)layout->gobj());
+       
+       if (!pfd) {
+               
+               /* layout inherited its font description from a PangoContext */
+
+               PangoContext* ctxt = (PangoContext*) pango_layout_get_context ((PangoLayout*) layout->gobj());
+               pfd =  pango_context_get_font_description (ctxt);
+               return Pango::FontDescription (pfd, true); /* make a copy */
+       } 
+
+       return Pango::FontDescription (pfd, true); /* make a copy */
 }
 
 uint32_t