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
This commit is contained in:
Nick Treleaven 2009-07-09 13:51:37 +00:00
parent 979585dbb6
commit 87e8f51e36
5 changed files with 45 additions and 8 deletions

View File

@ -7,6 +7,11 @@
If autocompletion is already visible when forcing completion, show If autocompletion is already visible when forcing completion, show
document word completion instead of tag completion. document word completion instead of tag completion.
Docs: Minor edits of related prefs items. 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 <enrico(dot)troeger(at)uvena(dot)de> 2009-07-08 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

View File

@ -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 * On Unix-like systems a GTK message dialog box is shown, on Win32 systems a native Windows
* message dialog box is shown. * message dialog box is shown.
* *
* @param type A GtkMessageType, can be one of: GTK_MESSAGE_INFO, GTK_MESSAGE_WARNING, * @param type A GtkMessageType, e.g. GTK_MESSAGE_INFO, GTK_MESSAGE_WARNING,
* GTK_MESSAGE_QUESTION, GTK_MESSAGE_ERROR * GTK_MESSAGE_QUESTION, GTK_MESSAGE_ERROR.
* @param text Printf()-style format string. * @param text Printf()-style format string.
* @param ... Arguments for the @c text 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 #ifndef G_OS_WIN32
GtkWidget *dialog; 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 #ifdef G_OS_WIN32
/* put the two strings together because Windows message boxes don't support secondary texts */ /* put the two strings together because Windows message boxes don't support secondary texts */

View File

@ -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, 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); 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 #endif

View File

@ -403,8 +403,8 @@ UIUtilsFuncs;
/* See dialogs.h */ /* See dialogs.h */
typedef struct DialogFuncs typedef struct DialogFuncs
{ {
gboolean (*show_question) (const gchar *text, ...); gboolean (*show_question) (const gchar *text, ...) G_GNUC_PRINTF (1, 2);
void (*show_msgbox) (gint type, const gchar *text, ...); void (*show_msgbox) (GtkMessageType type, const gchar *text, ...) G_GNUC_PRINTF (2, 3);
gboolean (*show_save_as) (void); gboolean (*show_save_as) (void);
gboolean (*show_input_numeric) (const gchar *title, const gchar *label_text, gboolean (*show_input_numeric) (const gchar *title, const gchar *label_text,
gdouble *value, gdouble min, gdouble max, gdouble step); gdouble *value, gdouble min, gdouble max, gdouble step);

View File

@ -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) static gint get_font_width(GtkPrintContext *context, PangoFontDescription *desc)
{ {
PangoContext *pc; PangoContext *pc;
@ -158,6 +183,11 @@ static gint get_font_width(GtkPrintContext *context, PangoFontDescription *desc)
pc = gtk_print_context_create_pango_context(context); 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)); metrics = pango_context_get_metrics(pc, desc, pango_context_get_language(pc));
/** TODO is this the best result we can get? */ /** TODO is this the best result we can get? */
/* digit and char width are mostly equal for monospace fonts, char width might be /* 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; width = pango_font_metrics_get_approximate_digit_width(metrics) / PANGO_SCALE;
pango_font_metrics_unref(metrics); pango_font_metrics_unref(metrics);
g_object_unref(pc);
return width; return width;
} }