diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 928b3bd137..601eda7733 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -830,14 +830,14 @@ Editor::initialize_canvas () /* stuff for the verbose canvas cursor */ - string fontname = get_font_for_style (N_("VerboseCanvasCursor")); + Pango::FontDescription font = get_font_for_style (N_("VerboseCanvasCursor")); verbose_canvas_cursor = gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(track_gnome_canvas)), - gnome_canvas_text_get_type(), - "font", fontname.c_str(), - "anchor", GTK_ANCHOR_NW, - "fill_color_rgba", color_map[cVerboseCanvasCursor], - NULL); + gnome_canvas_text_get_type(), + "font-desc", fontname, + "anchor", GTK_ANCHOR_NW, + "fill_color_rgba", color_map[cVerboseCanvasCursor], + NULL); verbose_cursor_visible = false; /* a group to hold time (measure) lines */ @@ -1389,7 +1389,7 @@ Editor::track_canvas_allocate (GtkAllocation *alloc) if (session == 0 && !ARDOUR_UI::instance()->will_create_new_session_automatically()) { - string fontname = get_font_for_style (N_("FirstActionMessage")); + Pango::FontDescription font = get_font_for_style (N_("FirstActionMessage")); const char *txt1 = _("Start a new session\n"); const char *txt2 = _("via Session menu"); @@ -1400,27 +1400,21 @@ Editor::track_canvas_allocate (GtkAllocation *alloc) compute width, and multiply the height by 2. */ - gint width; - gint lbearing; - gint rbearing; - gint ascent; - gint descent; + int pixel_height; + int pixel_width; /* this is a dummy widget that exists so that we can get the style from the RC file. */ Label foo (_(txt2)); + Glib::RefPtr layout; foo.set_name ("NoSessionMessage"); foo.ensure_style (); - gdk_string_extents (foo.get_style()->get_font(), - _(txt2), - &lbearing, - &rbearing, - &width, - &ascent, - &descent); + layout = foo.create_pango_layout (_(txt2)); + layout->set_font_description (font); + layout->get_pixel_size (pixel_width, pixel_height); if (first_action_message == 0) { @@ -1432,22 +1426,22 @@ Editor::track_canvas_allocate (GtkAllocation *alloc) strcat (txt, _(txt2)); first_action_message = gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(track_gnome_canvas)), - gnome_canvas_text_get_type(), - "font", fontname.c_str(), - "fill_color_rgba", color_map[cFirstActionMessage], - "x", (gdouble) (canvas_width - width) / 2.0, - "y", (gdouble) (canvas_height/2.0) - (2.0 * (ascent+descent)), - "anchor", GTK_ANCHOR_NORTH_WEST, - "text", txt, - NULL); + gnome_canvas_text_get_type(), + "fontdesc", font, + "fill_color_rgba", color_map[cFirstActionMessage], + "x", (gdouble) (canvas_width - pixel_width) / 2.0, + "y", (gdouble) (canvas_height/2.0) - (2.0 * (pixel_height)), + "anchor", GTK_ANCHOR_NORTH_WEST, + "text", txt, + NULL); } else { /* center it */ gnome_canvas_item_set (first_action_message, - "x", (gdouble) (canvas_width - width) / 2.0, - "y", (gdouble) (canvas_height/2.0) - (2.0 * (ascent+descent)), + "x", (gdouble) (canvas_width - pixel_width) / 2.0, + "y", (gdouble) (canvas_height/2.0) - (2.0 * (pixel_height)), NULL); } } diff --git a/gtk2_ardour/marker.cc b/gtk2_ardour/marker.cc index 2621102865..0d124f556c 100644 --- a/gtk2_ardour/marker.cc +++ b/gtk2_ardour/marker.cc @@ -351,17 +351,17 @@ Marker::Marker (PublicEditor& ed, GnomeCanvasGroup *parent, guint32 rgba, const "outline_color", "black", NULL); - string fontname = get_font_for_style (N_("MarkerText")); + Pango::FontDescription font = get_font_for_style (N_("MarkerText")); text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group), - gnome_canvas_text_get_type (), - "text", annotation.c_str(), - "x", label_offset, - "y", 0.0, - "font", fontname.c_str(), - "anchor", GTK_ANCHOR_NW, - "fill_color", "black", - NULL); + gnome_canvas_text_get_type (), + "text", annotation.c_str(), + "x", label_offset, + "y", 0.0, + "fontdesc", font, + "anchor", GTK_ANCHOR_NW, + "fill_color", "black", + NULL); gtk_object_set_data (GTK_OBJECT(group), "marker", this); gtk_signal_connect (GTK_OBJECT(group), "event", (GtkSignalFunc) callback, &editor); diff --git a/gtk2_ardour/time_axis_view_item.cc b/gtk2_ardour/time_axis_view_item.cc index 7f1bfc53e5..62a1e7d9e6 100644 --- a/gtk2_ardour/time_axis_view_item.cc +++ b/gtk2_ardour/time_axis_view_item.cc @@ -38,7 +38,8 @@ using namespace Editing; //------------------------------------------------------------------------------ /** Initialize static memeber data */ -std::string TimeAxisViewItem::NAME_FONT; +Pango::FontDescription TimeAxisViewItem::NAME_FONT; +bool TimeAxisViewItem::have_name_font = false; const double TimeAxisViewItem::NAME_X_OFFSET = 15.0; const double TimeAxisViewItem::NAME_Y_OFFSET = 15.0 ; /* XXX depends a lot on the font size, sigh. */ const double TimeAxisViewItem::NAME_HIGHLIGHT_SIZE = 15.0 ; /* ditto */ @@ -65,8 +66,9 @@ TimeAxisViewItem::TimeAxisViewItem(std::string it_name, GnomeCanvasGroup* parent Visibility visibility) : trackview (tv) { - if (NAME_FONT.empty()) { + if (!have_name_font) { NAME_FONT = get_font_for_style (N_("TimeAxisViewItemName")); + have_name_font = true; } item_name = it_name ; diff --git a/gtk2_ardour/time_axis_view_item.h b/gtk2_ardour/time_axis_view_item.h index d4e852461a..ff651b9649 100644 --- a/gtk2_ardour/time_axis_view_item.h +++ b/gtk2_ardour/time_axis_view_item.h @@ -264,7 +264,8 @@ class TimeAxisViewItem : public sigc::trackable, public Selectable bool name_active() const { return name_connected; } // Default sizes, font and spacing - static std::string NAME_FONT ; + static Pango::FontDescription NAME_FONT ; + static bool have_name_font; static const double NAME_X_OFFSET ; static const double NAME_Y_OFFSET ; static const double NAME_HIGHLIGHT_SIZE ; diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index 21a8233d44..e0a31e5844 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -25,6 +25,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -36,6 +40,7 @@ using namespace std; using namespace Gtk; +using namespace sigc; string short_version (string orig, string::size_type target_length) @@ -102,27 +107,22 @@ short_version (string orig, string::size_type target_length) } string -fit_to_pixels (string str, int32_t pixel_width, Gdk_Font& font) +fit_to_pixels (string str, int pixel_width, string font) { - gint width; - gint lbearing; - gint rbearing; - gint ascent; - gint descent; - + Label foo; + int width; + int height; + Pango::FontDescription fontdesc (font); + int namelen = str.length(); char cstr[namelen+1]; strcpy (cstr, str.c_str()); while (namelen) { - - gdk_string_extents (font, - cstr, - &lbearing, - &rbearing, - &width, - &ascent, - &descent); + Glib::RefPtr layout = foo.create_pango_layout (cstr); + + layout->set_font_description (fontdesc); + layout->get_pixel_size (width, height); if (width < (pixel_width)) { break; @@ -415,26 +415,19 @@ url_decode (string& url) } } -string +Pango::FontDescription get_font_for_style (string widgetname) { Gtk::Label foobar; + Glib::RefPtr