From 8b7898a557a8100abf84923f9d10a5285d67368f Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Wed, 18 May 2016 12:13:12 +0100 Subject: [PATCH] Image overlay configurable font User configurable option to set the font of the Image Overlay text --- src/image-overlay.c | 12 ++++++++++++ src/options.c | 1 + src/options.h | 1 + src/preferences.c | 30 +++++++++++++++++++++++++++++- src/rcfile.c | 2 ++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/image-overlay.c b/src/image-overlay.c index dcba8ed1..88ccb9c1 100644 --- a/src/image-overlay.c +++ b/src/image-overlay.c @@ -100,6 +100,14 @@ void set_default_image_overlay_template_string(gchar **template_string) set_image_overlay_template_string(template_string, DEFAULT_OVERLAY_INFO); } +void set_image_overlay_font_string(gchar **font_string, const gchar *value) +{ + g_assert(font_string); + + g_free(*font_string); + *font_string = g_strdup(value); +} + static OverlayStateData *image_get_osd_data(ImageWindow *imd) { OverlayStateData *osd; @@ -493,6 +501,7 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd) const HistMap *histmap = NULL; ImageWindow *imd = osd->imd; FileData *fd = image_get_fd(imd); + PangoFontDescription *font_desc; if (!fd) return NULL; @@ -653,7 +662,10 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd) } } + font_desc = pango_font_description_from_string(options->image_overlay.font); layout = gtk_widget_create_pango_layout(imd->pr, NULL); + pango_layout_set_font_description(layout, font_desc); + pango_layout_set_markup(layout, text, -1); g_free(text); diff --git a/src/options.c b/src/options.c index f8d0a80e..99e4de78 100644 --- a/src/options.c +++ b/src/options.c @@ -88,6 +88,7 @@ ConfOptions *init_options(ConfOptions *options) options->image_overlay.template_string = NULL; options->image_overlay.x = 10; options->image_overlay.y = -10; + options->image_overlay.font = NULL; options->lazy_image_sync = FALSE; options->mousewheel_scrolls = FALSE; diff --git a/src/options.h b/src/options.h index b44db26d..fbbd8f9c 100644 --- a/src/options.h +++ b/src/options.h @@ -138,6 +138,7 @@ struct _ConfOptions gchar *template_string; gint x; gint y; + gchar *font; } image_overlay; /* properties dialog */ diff --git a/src/preferences.c b/src/preferences.c index 1f0e136f..0f2426c0 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -284,7 +284,9 @@ static void config_window_apply(void) if (c_options->image_overlay.template_string) set_image_overlay_template_string(&options->image_overlay.template_string, c_options->image_overlay.template_string); - + if (c_options->image_overlay.font) + set_image_overlay_font_string(&options->image_overlay.font, + c_options->image_overlay.font); options->update_on_time_change = c_options->update_on_time_change; options->image.exif_rotate_enable = c_options->image.exif_rotate_enable; options->image.exif_proof_rotate_enable = c_options->image.exif_proof_rotate_enable; @@ -1015,6 +1017,27 @@ static void image_overlay_help_cb(GtkWidget *widget, gpointer data) help_window_show("overlay"); } +static void image_overlay_set_font_cb(GtkWidget *widget, gpointer data) +{ + GenericDialog *dialog; + char *font; + PangoFontDescription *font_desc; + + dialog = gtk_font_chooser_dialog_new("Image Overlay Font", gtk_widget_get_toplevel(widget)); + gtk_font_chooser_set_font(dialog, options->image_overlay.font); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL) + { + font_desc = gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(dialog)); + font = pango_font_description_to_string(font_desc); + g_free(c_options->image_overlay.font); + c_options->image_overlay.font = g_strdup(font); + g_free(font); + } + + gtk_widget_destroy(dialog); +} + static void accel_store_populate(void) { LayoutWindow *lw; @@ -1451,6 +1474,11 @@ static void config_tab_windows(GtkWidget *notebook) hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_BUTTON_GAP); + button = pref_button_new(NULL, GTK_STOCK_SELECT_FONT, _("Font"), FALSE, + G_CALLBACK(image_overlay_set_font_cb), notebook); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, NULL, 0); + gtk_widget_show(button); + button = pref_button_new(NULL, NULL, _("Defaults"), FALSE, G_CALLBACK(image_overlay_default_template_cb), image_overlay_template_view); gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); diff --git a/src/rcfile.c b/src/rcfile.c index 1e8c569b..0aae6acf 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -354,6 +354,7 @@ static void write_global_attributes(GString *outstr, gint indent) WRITE_NL(); WRITE_INT(*options, image_overlay.x); WRITE_NL(); WRITE_INT(*options, image_overlay.y); + WRITE_NL(); WRITE_CHAR(*options, image_overlay.font); /* Slideshow Options */ WRITE_NL(); WRITE_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION); @@ -615,6 +616,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar ** if (READ_CHAR(*options, image_overlay.template_string)) continue; if (READ_INT(*options, image_overlay.x)) continue; if (READ_INT(*options, image_overlay.y)) continue; + if (READ_CHAR(*options, image_overlay.font)) continue; /* Slideshow options */ if (READ_INT_UNIT(*options, slideshow.delay, SLIDESHOW_SUBSECOND_PRECISION)) continue; -- 2.20.1