From 87e8f51e368e85a7ff76b5dee5e9ec8661126134 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 9 Jul 2009 13:51:37 +0000 Subject: [PATCH] Add warning when printing and editor font is not monospaced. Fix using GtkMessageType instead of gint param for dialogs_show_msgbox*(). Add missing G_GNUC_PRINTF macro check to API dialog funcs. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3944 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 5 +++++ src/dialogs.c | 8 ++++---- src/dialogs.h | 4 ++-- src/plugindata.h | 4 ++-- src/printing.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64db3491..4b4b4977 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,11 @@ If autocompletion is already visible when forcing completion, show document word completion instead of tag completion. Docs: Minor edits of related prefs items. + * src/printing.c, src/dialogs.c, src/dialogs.h, src/plugindata.h: + Add warning when printing and editor font is not monospaced. + Fix using GtkMessageType instead of gint param for + dialogs_show_msgbox*(). + Add missing G_GNUC_PRINTF macro check to API dialog funcs. 2009-07-08 Enrico Tröger diff --git a/src/dialogs.c b/src/dialogs.c index dcf3d2d9..2dc13b30 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -557,12 +557,12 @@ gboolean dialogs_show_save_as() * On Unix-like systems a GTK message dialog box is shown, on Win32 systems a native Windows * message dialog box is shown. * - * @param type A GtkMessageType, can be one of: GTK_MESSAGE_INFO, GTK_MESSAGE_WARNING, - * GTK_MESSAGE_QUESTION, GTK_MESSAGE_ERROR + * @param type A GtkMessageType, e.g. GTK_MESSAGE_INFO, GTK_MESSAGE_WARNING, + * GTK_MESSAGE_QUESTION, GTK_MESSAGE_ERROR. * @param text Printf()-style format string. * @param ... Arguments for the @c text format string. **/ -void dialogs_show_msgbox(gint type, const gchar *text, ...) +void dialogs_show_msgbox(GtkMessageType type, const gchar *text, ...) { #ifndef G_OS_WIN32 GtkWidget *dialog; @@ -586,7 +586,7 @@ void dialogs_show_msgbox(gint type, const gchar *text, ...) } -void dialogs_show_msgbox_with_secondary(gint type, const gchar *text, const gchar *secondary) +void dialogs_show_msgbox_with_secondary(GtkMessageType type, const gchar *text, const gchar *secondary) { #ifdef G_OS_WIN32 /* put the two strings together because Windows message boxes don't support secondary texts */ diff --git a/src/dialogs.h b/src/dialogs.h index eca64a77..1a1282f1 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -58,8 +58,8 @@ gboolean dialogs_show_question(const gchar *text, ...) G_GNUC_PRINTF (1, 2); gboolean dialogs_show_question_full(GtkWidget *parent, const gchar *yes_btn, const gchar *no_btn, const gchar *extra_text, const gchar *main_text, ...) G_GNUC_PRINTF (5, 6); -void dialogs_show_msgbox(gint type, const gchar *text, ...) G_GNUC_PRINTF (2, 3); +void dialogs_show_msgbox(GtkMessageType type, const gchar *text, ...) G_GNUC_PRINTF (2, 3); -void dialogs_show_msgbox_with_secondary(gint type, const gchar *text, const gchar *secondary); +void dialogs_show_msgbox_with_secondary(GtkMessageType type, const gchar *text, const gchar *secondary); #endif diff --git a/src/plugindata.h b/src/plugindata.h index d1185df5..cdc1512f 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -403,8 +403,8 @@ UIUtilsFuncs; /* See dialogs.h */ typedef struct DialogFuncs { - gboolean (*show_question) (const gchar *text, ...); - void (*show_msgbox) (gint type, const gchar *text, ...); + gboolean (*show_question) (const gchar *text, ...) G_GNUC_PRINTF (1, 2); + void (*show_msgbox) (GtkMessageType type, const gchar *text, ...) G_GNUC_PRINTF (2, 3); gboolean (*show_save_as) (void); gboolean (*show_input_numeric) (const gchar *title, const gchar *label_text, gdouble *value, gdouble min, gdouble max, gdouble step); diff --git a/src/printing.c b/src/printing.c index 04230a8c..5dc0b18e 100644 --- a/src/printing.c +++ b/src/printing.c @@ -150,6 +150,31 @@ static PangoLayout *setup_pango_layout(GtkPrintContext *context, PangoFontDescri } +static gboolean utils_font_desc_check_monospace(PangoContext *pc, PangoFontDescription *desc) +{ + PangoFontFamily **families; + gint n_families, i; + const gchar *font; + gboolean ret = TRUE; + + font = pango_font_description_get_family(desc); + pango_context_list_families(pc, &families, &n_families); + for (i = 0; i < n_families; i++) + { + if (utils_str_equal(font, pango_font_family_get_name(families[i]))) + { + if (!pango_font_family_is_monospace(families[i])) + { + ret = FALSE; + } + } + } + g_free(families); + return ret; +} + + +/* We don't support variable width fonts (yet) */ static gint get_font_width(GtkPrintContext *context, PangoFontDescription *desc) { PangoContext *pc; @@ -158,6 +183,11 @@ static gint get_font_width(GtkPrintContext *context, PangoFontDescription *desc) pc = gtk_print_context_create_pango_context(context); + if (!utils_font_desc_check_monospace(pc, desc)) + dialogs_show_msgbox_with_secondary(GTK_MESSAGE_WARNING, + _("The editor font is not a monospaced font!"), + _("Text will be wrongly spaced.")); + metrics = pango_context_get_metrics(pc, desc, pango_context_get_language(pc)); /** TODO is this the best result we can get? */ /* digit and char width are mostly equal for monospace fonts, char width might be @@ -166,6 +196,8 @@ static gint get_font_width(GtkPrintContext *context, PangoFontDescription *desc) width = pango_font_metrics_get_approximate_digit_width(metrics) / PANGO_SCALE; pango_font_metrics_unref(metrics); + g_object_unref(pc); + return width; }