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:
parent
979585dbb6
commit
87e8f51e36
@ -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 <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
@ -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 */
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user