X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Futils.cc;h=76b237713adba8725cd99160f617e6faab8811ea;hb=f95d814143060efc7a69164362a3311b3a3b54a4;hp=acc9574a182a2694483c7420f0088649c460af81;hpb=6817b59169b2c334245f8018d7e3f2235e195aa0;p=ardour.git diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index acc9574a18..76b237713a 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -20,6 +20,8 @@ #include #include +#include +#include #include #include #include @@ -28,6 +30,7 @@ #include #include +#include #include "ardour_ui.h" #include "keyboard.h" @@ -40,123 +43,38 @@ using namespace std; using namespace Gtk; using namespace sigc; using namespace Glib; +using namespace PBD; -string -short_version (string orig, string::size_type target_length) -{ - /* this tries to create a recognizable abbreviation - of "orig" by removing characters until we meet - a certain target length. - - note that we deliberately leave digits in the result - without modification. - */ - - - string::size_type pos; - - /* remove white-space and punctuation, starting at end */ - - while (orig.length() > target_length) { - if ((pos = orig.find_last_of (_("\"\n\t ,<.>/?:;'[{}]~`!@#$%^&*()_-+="))) == string::npos) { - break; - } - orig.replace (pos, 1, ""); - } - - /* remove lower-case vowels, starting at end */ - - while (orig.length() > target_length) { - if ((pos = orig.find_last_of (_("aeiou"))) == string::npos) { - break; - } - orig.replace (pos, 1, ""); - } - - /* remove upper-case vowels, starting at end */ - - while (orig.length() > target_length) { - if ((pos = orig.find_last_of (_("AEIOU"))) == string::npos) { - break; - } - orig.replace (pos, 1, ""); - } - - /* remove lower-case consonants, starting at end */ - - while (orig.length() > target_length) { - if ((pos = orig.find_last_of (_("bcdfghjklmnpqrtvwxyz"))) == string::npos) { - break; - } - orig.replace (pos, 1, ""); - } - - /* remove upper-case consonants, starting at end */ - - while (orig.length() > target_length) { - if ((pos = orig.find_last_of (_("BCDFGHJKLMNPQRTVWXYZ"))) == string::npos) { - break; - } - orig.replace (pos, 1, ""); - } - - /* whatever the length is now, use it */ - - return orig; -} - -string -fit_to_pixels (const string & str, int pixel_width, const string & font) +ustring +fit_to_pixels (const ustring& str, int pixel_width, Pango::FontDescription& font, int& actual_width) { Label foo; - int width; - int height; - Pango::FontDescription fontdesc (font); + Glib::RefPtr layout = foo.create_pango_layout (""); - int namelen = str.length(); - char cstr[namelen+1]; - strcpy (cstr, str.c_str()); - - while (namelen) { - Glib::RefPtr layout = foo.create_pango_layout (cstr); - - layout->set_font_description (fontdesc); - layout->get_pixel_size (width, height); + layout->set_font_description (font); - if (width < (pixel_width)) { - break; - } + actual_width = 0; - --namelen; - cstr[namelen] = '\0'; + ustring ustr = str; + ustring::iterator last = ustr.end(); + --last; /* now points at final entry */ - } - - return cstr; -} + while (!ustr.empty()) { -int -atoi (const string& s) -{ - return atoi (s.c_str()); -} + layout->set_text (ustr); -double -atof (const string& s) -{ - return atof (s.c_str()); -} + int width, height; + Gtkmm2ext::get_ink_pixel_size (layout, width, height); -vector -internationalize (const char **array) -{ - vector v; - - for (uint32_t i = 0; array[i]; ++i) { - v.push_back (_(array[i])); + if (width < pixel_width) { + actual_width = width; + break; + } + + ustr.erase (last--); } - return v; + return ustr; } gint @@ -291,102 +209,12 @@ get_canvas_points (string who, uint32_t npoints) return new ArdourCanvas::Points (npoints); } -int -channel_combo_get_channel_count (Gtk::ComboBoxText& combo) -{ - string str = combo.get_active_text(); - int chns; - - if (str == _("mono")) { - return 1; - } else if (str == _("stereo")) { - return 2; - } else if ((chns = atoi (str)) != 0) { - return chns; - } else { - return 0; - } -} - -static int32_t -int_from_hex (char hic, char loc) -{ - int hi; /* hi byte */ - int lo; /* low byte */ - - hi = (int) hic; - - if( ('0'<=hi) && (hi<='9') ) { - hi -= '0'; - } else if( ('a'<= hi) && (hi<= 'f') ) { - hi -= ('a'-10); - } else if( ('A'<=hi) && (hi<='F') ) { - hi -= ('A'-10); - } - - lo = (int) loc; - - if( ('0'<=lo) && (lo<='9') ) { - lo -= '0'; - } else if( ('a'<=lo) && (lo<='f') ) { - lo -= ('a'-10); - } else if( ('A'<=lo) && (lo<='F') ) { - lo -= ('A'-10); - } - - return lo + (16 * hi); -} - -void -url_decode (string& url) -{ - string::iterator last; - string::iterator next; - - for (string::iterator i = url.begin(); i != url.end(); ++i) { - if ((*i) == '+') { - *i = ' '; - } - } - - if (url.length() <= 3) { - return; - } - - last = url.end(); - - --last; /* points at last char */ - --last; /* points at last char - 1 */ - - for (string::iterator i = url.begin(); i != last; ) { - - if (*i == '%') { - - next = i; - - url.erase (i); - - i = next; - ++next; - - if (isxdigit (*i) && isxdigit (*next)) { - /* replace first digit with char */ - *i = int_from_hex (*i,*next); - ++i; /* points at 2nd of 2 digits */ - url.erase (i); - } - } else { - ++i; - } - } -} - Pango::FontDescription get_font_for_style (string widgetname) { Gtk::Window window (WINDOW_TOPLEVEL); Gtk::Label foobar; - Glib::RefPtr