SF.net SVN: geany:[3944] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Thu Jul 9 13:51:37 UTC 2009
Revision: 3944
http://geany.svn.sourceforge.net/geany/?rev=3944&view=rev
Author: ntrel
Date: 2009-07-09 13:51:37 +0000 (Thu, 09 Jul 2009)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/dialogs.c
trunk/src/dialogs.h
trunk/src/plugindata.h
trunk/src/printing.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-07-09 11:54:14 UTC (rev 3943)
+++ trunk/ChangeLog 2009-07-09 13:51:37 UTC (rev 3944)
@@ -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>
Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c 2009-07-09 11:54:14 UTC (rev 3943)
+++ trunk/src/dialogs.c 2009-07-09 13:51:37 UTC (rev 3944)
@@ -557,12 +557,12 @@
* 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_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 */
Modified: trunk/src/dialogs.h
===================================================================
--- trunk/src/dialogs.h 2009-07-09 11:54:14 UTC (rev 3943)
+++ trunk/src/dialogs.h 2009-07-09 13:51:37 UTC (rev 3944)
@@ -58,8 +58,8 @@
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
Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h 2009-07-09 11:54:14 UTC (rev 3943)
+++ trunk/src/plugindata.h 2009-07-09 13:51:37 UTC (rev 3944)
@@ -403,8 +403,8 @@
/* 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);
Modified: trunk/src/printing.c
===================================================================
--- trunk/src/printing.c 2009-07-09 11:54:14 UTC (rev 3943)
+++ trunk/src/printing.c 2009-07-09 13:51:37 UTC (rev 3944)
@@ -150,6 +150,31 @@
}
+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 @@
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 @@
width = pango_font_metrics_get_approximate_digit_width(metrics) / PANGO_SCALE;
pango_font_metrics_unref(metrics);
+ g_object_unref(pc);
+
return width;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list