diff options
author | John Sullivan <sullivan@src.gnome.org> | 2000-04-26 22:07:02 +0000 |
---|---|---|
committer | John Sullivan <sullivan@src.gnome.org> | 2000-04-26 22:07:02 +0000 |
commit | 0b4acd0e69510fd12585f223b89b25ea5ed49d70 (patch) | |
tree | f15bca2ad4d0f029a39e45699807b0fef1761fc5 /libnautilus-private/nautilus-gdk-extensions.c | |
parent | 5f90e5043e8d6f8abc16bfc8fbc09511e7b6cfa7 (diff) | |
download | nautilus-0b4acd0e69510fd12585f223b89b25ea5ed49d70.tar.gz |
More FIXME-to-bug work.
* src/nautilus-index-title.c,
* libnautilus-extensions/nautilus-gdk-extensions.h,
* libnautilus-extensions/nautilus-gdk-extensions.c:
(select_font): Moved this function to gdk_extensions
and renamed it nautilus_get_largest_fitting_font.
* src/nautilus-index-tabs.c,
* src/nautilus-index-title.c,
* src/file-manager/fm-list-view.c,
* src/file-manager/fm-properties-window.c:
Wrote bug reports for all (other) FIXMEs in these files. Down to
81 in Nautilus with no bug report.
Diffstat (limited to 'libnautilus-private/nautilus-gdk-extensions.c')
-rw-r--r-- | libnautilus-private/nautilus-gdk-extensions.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libnautilus-private/nautilus-gdk-extensions.c b/libnautilus-private/nautilus-gdk-extensions.c index 527ed7411..525dcb554 100644 --- a/libnautilus-private/nautilus-gdk-extensions.c +++ b/libnautilus-private/nautilus-gdk-extensions.c @@ -473,6 +473,48 @@ nautilus_gdk_font_equal (GdkFont *font_a_null_allowed, return gdk_font_equal (font_a_null_allowed, font_b_null_allowed); } +GdkFont * +nautilus_get_largest_fitting_font (const char *text_to_format, int width, const char* font_template) +{ + int font_index, this_width; + char *font_name; + const int font_sizes[5] = { 28, 24, 18, 14, 12 }; + GdkFont *candidate_font = NULL; + char *alt_text_to_format = NULL; + char *temp_str = strdup(text_to_format); + char *cr_pos = strchr(temp_str, '\n'); + + if (cr_pos) { + *cr_pos = '\0'; + alt_text_to_format = cr_pos + 1; + } + + for (font_index = 0; font_index < NAUTILUS_N_ELEMENTS (font_sizes); font_index++) { + if (candidate_font != NULL) { + gdk_font_unref (candidate_font); + } + + font_name = g_strdup_printf (font_template, font_sizes[font_index]); + candidate_font = gdk_font_load (font_name); + g_free (font_name); + + this_width = gdk_string_width (candidate_font, temp_str); + if (alt_text_to_format != NULL) { + int alt_width = gdk_string_width (candidate_font, alt_text_to_format); + if (this_width <= width && alt_width <= width) { + break; + } + } else { + if (this_width <= width) { + break; + } + } + } + + g_free (temp_str); + return candidate_font; +} + /** * nautilus_stipple_bitmap: * |