Mercurial > audlegacy
changeset 324:fbafca56b6a8 trunk
[svn] playlist window truncation fixes provided by external contributor: Tim Yamin <plasmaroo -at- gentoo.org>.
author | nenolod |
---|---|
date | Mon, 19 Dec 2005 08:45:45 -0800 |
parents | f61c05314118 |
children | ea321d1dae48 |
files | audacious/playlist_list.c |
diffstat | 1 files changed, 41 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/audacious/playlist_list.c Sun Dec 18 14:17:33 2005 -0800 +++ b/audacious/playlist_list.c Mon Dec 19 08:45:45 2005 -0800 @@ -293,29 +293,15 @@ const gchar * text, guint ppos) { + gint len; + guint plist_length_int; - gint len; - gint len_pixmap; - guint plist_length_int; + gchar *text_clipped; PangoLayout *layout; - gchar *text_clipped; + PangoRectangle rect; REQUIRE_STATIC_LOCK(playlist); - len = g_utf8_strlen(text, -1); - len_pixmap = (width_approx_letters * len); - - while (len_pixmap > width && len > 4) { - len--; - len_pixmap -= width_approx_letters; - } - - /* FIXME: Is it possible to overflow text_clipped when text is non - UTF-8? - descender */ - - text_clipped = g_new0(gchar, strlen(text)+1); - g_utf8_strncpy(text_clipped, text, len); - if (cfg.show_numbers_in_pl) { gchar *pos_string = g_strdup_printf("%d", ppos); plist_length_int = @@ -343,6 +329,42 @@ padding = 3; } + /* FIXME: Is it possible to overflow text_clipped when text is non + UTF-8? - descender */ + text_clipped = g_new0(gchar, strlen(text)+1); + len = g_utf8_strlen(text, -1); + g_utf8_strncpy(text_clipped, text, len); + + width -= padding; + layout = gtk_widget_create_pango_layout(playlistwin, text); + pango_layout_set_font_description(layout, playlist_list_font); + pango_layout_get_pixel_extents(layout, &rect, NULL); + if (rect.width > width) + { + while (rect.width > width && len > 4) { + len--; + g_utf8_strncpy(text_clipped, text_clipped, len); + + layout = gtk_widget_create_pango_layout(playlistwin, text_clipped); + pango_layout_set_font_description(layout, playlist_list_font); + pango_layout_get_pixel_extents(layout, &rect, NULL); + } + + /* Add dots */ + layout = gtk_widget_create_pango_layout(playlistwin, " ..."); + pango_layout_set_font_description(layout, playlist_list_font); + pango_layout_get_pixel_extents(layout, &rect, NULL); + + g_utf8_strncpy(text_clipped, text, len - (rect.width / width_approx_letters)); + + /* If we have whitespace on the end strip off some more... */ + while (text_clipped[len] == ' ' && len > 4) { + len--; + g_utf8_strncpy(text_clipped, text_clipped, len); + } + text_clipped = g_strconcat(text_clipped, "...", NULL); + } + layout = gtk_widget_create_pango_layout(playlistwin, text_clipped); pango_layout_set_font_description(layout, playlist_list_font); @@ -486,9 +508,7 @@ /* FIXME: This is just an approximate alignment, maybe something still fast, but exact could be done */ - tail_width = width - (tail_len * width_approx_digits) + - (width_approx_digits_half) - 3; - + tail_width = width - (width_approx_digits * 6) - 5; if (i == playlist_get_position_nolock()) gdk_gc_set_foreground(gc, skin_get_color(bmp_active_skin,