X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Futils.cc;h=0f53b0912f27f05232eef85a7d603c119a1617f4;hb=ccf58b8de23619db9983a45f696fd97e13a15cce;hp=4c4bcf69ec5efef711b4714827568d469ae94436;hpb=c83e48e07a0b4790512c6251d8ad8f941c881021;p=ardour.git diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index 4c4bcf69ec..0f53b0912f 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -936,3 +936,40 @@ resize_window_to_proportion_of_monitor (Gtk::Window* window, int max_width, int window->resize (w, h); } + +Glib::RefPtr +pixbuf_from_ustring(const ustring& name, Pango::FontDescription* font, int clip_width, int clip_height) +{ + static Glib::RefPtr* empty_pixbuf = 0; + + if (name.empty()) { + if (empty_pixbuf == 0) { + empty_pixbuf = new Glib::RefPtr; + *empty_pixbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, clip_width, clip_height); + } + cerr << "\n\nUSE EMPTY PIXBUF\n"; + return *empty_pixbuf; + } + + Glib::RefPtr buf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, clip_width, clip_height); + + cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, clip_width, clip_height); + cairo_t* cr = cairo_create (surface); + cairo_text_extents_t te; + + cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0); + cairo_select_font_face (cr, font->get_family().c_str(), + CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (cr, font->get_size() / Pango::SCALE); + cairo_text_extents (cr, name.c_str(), &te); + + cairo_move_to (cr, 0.5, 0.5 - te.height / 2 - te.y_bearing + clip_height / 2); + cairo_show_text (cr, name.c_str()); + + convert_bgra_to_rgba(cairo_image_surface_get_data (surface), buf->get_pixels(), clip_width, clip_height); + + cairo_destroy(cr); + cairo_surface_destroy(surface); + + return buf; +}