summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasmine Hassan <[email protected]>2012-11-13 15:52:16 +0200
committerJasmine Hassan <[email protected]>2012-11-14 12:28:47 +0200
commit74206714b6a34f49d5fa8f0b7b50f845f3836924 (patch)
tree750d83cda6aa0f5101e034e00ad23f57cadb6368
parent4c9e9bc2b097323bd7b0717f055d5ee034260d22 (diff)
downloadcaja-74206714b6a34f49d5fa8f0b7b50f845f3836924.tar.bz2
caja-74206714b6a34f49d5fa8f0b7b50f845f3836924.tar.xz
[sidebar-title] Use pango directly to set largest-fitting font size
and don't include eel-pango-extensions, which is to be dropped.
-rw-r--r--src/caja-sidebar-title.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/caja-sidebar-title.c b/src/caja-sidebar-title.c
index e02eaa9d..86dd4e41 100644
--- a/src/caja-sidebar-title.c
+++ b/src/caja-sidebar-title.c
@@ -36,9 +36,8 @@
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
-#include <eel/eel-pango-extensions.h>
-#include <eel/eel-string.h>
#include <gtk/gtk.h>
+#include <pango/pango.h>
#include <glib/gi18n.h>
#include <libcaja-private/caja-file-attributes.h>
#include <libcaja-private/caja-global-preferences.h>
@@ -399,15 +398,16 @@ update_icon (CajaSidebarTitle *sidebar_title)
static void
update_title_font (CajaSidebarTitle *sidebar_title)
{
- int available_width;
- PangoFontDescription *title_font;
- int largest_fitting_font_size;
- int max_style_font_size;
+ int available_width, width;
+ int max_fit_font_size, max_style_font_size;
GtkStyle *style;
GtkAllocation allocation;
+ PangoFontDescription *title_font, *tmp_font;
+ PangoLayout *layout;
/* Make sure theres work to do */
- if (eel_strlen (sidebar_title->details->title_text) < 1)
+ if (sidebar_title->details->title_text == NULL
+ || strlen (sidebar_title->details->title_text) < 1)
{
return;
}
@@ -430,19 +430,29 @@ update_title_font (CajaSidebarTitle *sidebar_title)
max_style_font_size = MIN_TITLE_FONT_SIZE + 1;
}
- largest_fitting_font_size = eel_pango_font_description_get_largest_fitting_font_size (
- title_font,
- gtk_widget_get_pango_context (sidebar_title->details->title_label),
- sidebar_title->details->title_text,
- available_width,
- MIN_TITLE_FONT_SIZE,
- max_style_font_size);
- pango_font_description_set_size (title_font, largest_fitting_font_size * PANGO_SCALE);
+ /* Calculate largest-fitting font size */
+ layout = pango_layout_new (gtk_widget_get_pango_context (sidebar_title->details->title_label));
+ pango_layout_set_text (layout, sidebar_title->details->title_text, -1);
+ pango_layout_set_font_description (layout, title_font);
+ tmp_font = pango_font_description_new ();
- pango_font_description_set_weight (title_font, PANGO_WEIGHT_BOLD);
+ max_fit_font_size = max_style_font_size;
+ for (; max_fit_font_size >= MIN_TITLE_FONT_SIZE; max_fit_font_size--)
+ {
+ pango_font_description_set_size (tmp_font, max_fit_font_size * PANGO_SCALE);
+ pango_layout_set_font_description (layout, tmp_font);
+ pango_layout_get_pixel_size (layout, &width, NULL);
- gtk_widget_modify_font (sidebar_title->details->title_label,
- title_font);
+ if (width <= available_width)
+ break;
+ }
+
+ pango_font_description_free (tmp_font);
+ g_object_unref (layout);
+
+ pango_font_description_set_size (title_font, max_fit_font_size * PANGO_SCALE);
+ pango_font_description_set_weight (title_font, PANGO_WEIGHT_BOLD);
+ gtk_widget_modify_font (sidebar_title->details->title_label, title_font);
pango_font_description_free (title_font);
}
@@ -455,7 +465,7 @@ update_title (CajaSidebarTitle *sidebar_title)
label = GTK_LABEL (sidebar_title->details->title_label);
text = sidebar_title->details->title_text;
- if (eel_strcmp (text, gtk_label_get_text (label)) == 0)
+ if (g_strcmp0 (text, gtk_label_get_text (label)) == 0)
{
return;
}