From bb737997aea86f08ec16e6444f3666ff6a524be2 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 7 Dec 2011 13:08:00 +0000 Subject: move 2 other non-ardour-specific utility functions into gtkmm2ext git-svn-id: svn://localhost/ardour2/branches/3.0@10932 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/utils.cc | 93 ---------------------------------------------------- 1 file changed, 93 deletions(-) (limited to 'gtk2_ardour/utils.cc') diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index f2e774740d..23cceba72e 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -63,99 +63,6 @@ using Gtkmm2ext::Keyboard; sigc::signal DPIReset; -int -pixel_width (const string& str, Pango::FontDescription& font) -{ - Label foo; - Glib::RefPtr 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; -} - -string -fit_to_pixels (const string& str, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses) -{ - Label foo; - Glib::RefPtr layout = foo.create_pango_layout (""); - string::size_type shorter_by = 0; - string txt; - - layout->set_font_description (font); - - actual_width = 0; - - string ustr = str; - string::iterator last = ustr.end(); - --last; /* now points at final entry */ - - txt = ustr; - - while (!ustr.empty()) { - - layout->set_text (txt); - - int width, height; - Gtkmm2ext::get_ink_pixel_size (layout, width, height); - - if (width < pixel_width) { - actual_width = width; - break; - } - - ustr.erase (last--); - shorter_by++; - - if (with_ellipses && shorter_by > 3) { - txt = ustr; - txt += "..."; - } else { - txt = ustr; - } - } - - return txt; -} - -/** Try to fit a string into a given horizontal space by ellipsizing it. - * @param cr Cairo context in which the text will be plotted. - * @param name Text. - * @param avail Available horizontal space. - * @return (Text, possibly ellipsized) and (horizontal size of text) - */ - -std::pair -fit_to_pixels (cairo_t* cr, std::string name, double avail) -{ - /* XXX hopefully there exists a more efficient way of doing this */ - - bool abbreviated = false; - uint32_t width = 0; - - while (1) { - cairo_text_extents_t ext; - cairo_text_extents (cr, name.c_str(), &ext); - - if (ext.width < avail || name.length() <= 4) { - width = ext.width; - break; - } - - if (abbreviated) { - name = name.substr (0, name.length() - 4) + "..."; - } else { - name = name.substr (0, name.length() - 3) + "..."; - abbreviated = true; - } - } - - return std::make_pair (name, width); -} - /** Add an element to a menu, settings its sensitivity. * @param m Menu to add to. -- cgit v1.2.3