X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Futils.cc;h=9378b6727c1cb4dfc9acb2bd4edf408dba1427d1;hb=6001b8d28dd764bada8b9198a5f91e0a2f5251f6;hp=e609d0e33bef8c88bc85ead59948c843dfaade89;hpb=6ef5c8da56800bbce1c23a9ea51c9a1646d5887f;p=ardour.git diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index e609d0e33b..9378b6727c 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Paul Davis - This program is free software; you can redistribute it and/or modify + This program is free software; you an redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -15,19 +15,30 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ +#include // for fontmap resolution control for GnomeCanvas +#include // for fontmap resolution control for GnomeCanvas + #include #include +#include +#include #include +#include #include #include #include #include #include +#include "pbd/file_utils.h" + #include +#include "ardour/configuration.h" +#include "ardour/configuration.h" + +#include "ardour/filesystem_paths.h" #include "ardour_ui.h" #include "keyboard.h" @@ -40,129 +51,72 @@ 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; +sigc::signal DPIReset; - /* 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 */ +int +pixel_width (const ustring& str, Pango::FontDescription& font) +{ + Label foo; + Glib::RefPtr layout = foo.create_pango_layout (""); - while (orig.length() > target_length) { - if ((pos = orig.find_last_of (_("BCDFGHJKLMNPQRTVWXYZ"))) == string::npos) { - break; - } - orig.replace (pos, 1, ""); - } + layout->set_font_description (font); + layout->set_text (str); - /* whatever the length is now, use it */ - - return orig; + int width, height; + Gtkmm2ext::get_ink_pixel_size (layout, width, height); + return width; } -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, bool with_ellipses) { 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) { - Glib::RefPtr layout = foo.create_pango_layout (cstr); + Glib::RefPtr layout = foo.create_pango_layout (""); + ustring::size_type shorter_by = 0; + ustring txt; - 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 */ - } + txt = ustr; - return cstr; -} + while (!ustr.empty()) { -int -atoi (const string& s) -{ - return atoi (s.c_str()); -} + layout->set_text (txt); -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; + if (width < pixel_width) { + actual_width = width; + break; + } + + ustr.erase (last--); + shorter_by++; - for (uint32_t i = 0; array[i]; ++i) { - v.push_back (_(array[i])); + if (with_ellipses && shorter_by > 3) { + txt = ustr; + txt += "..."; + } else { + txt = ustr; + } } - return v; + return txt; } gint just_hide_it (GdkEventAny *ev, Gtk::Window *win) { - win->hide_all (); + win->hide (); return TRUE; } @@ -190,7 +144,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) { @@ -233,7 +187,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 @@ -291,152 +245,35 @@ get_canvas_points (string who, uint32_t npoints) return new ArdourCanvas::Points (npoints); } -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 +Pango::FontDescription* get_font_for_style (string widgetname) { Gtk::Window window (WINDOW_TOPLEVEL); Gtk::Label foobar; - Glib::RefPtr