Commit 6701eb6d4f45af5643756da9160a115a916f4845
1 parent
d7adc4c5
Exists in
master
and in
1 other branch
Emiting warning on invalid font-family.
Showing
1 changed file
with
44 additions
and
0 deletions
Show diff stats
src/terminal/font/properties.c
| ... | ... | @@ -29,6 +29,7 @@ |
| 29 | 29 | |
| 30 | 30 | #include <config.h> |
| 31 | 31 | #include "private.h" |
| 32 | + #include <gdk/gdk.h> | |
| 32 | 33 | |
| 33 | 34 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
| 34 | 35 | |
| ... | ... | @@ -44,6 +45,33 @@ const gchar * v3270_get_default_font_name() |
| 44 | 45 | #endif // _WIN32 |
| 45 | 46 | } |
| 46 | 47 | |
| 48 | +static guint validate_font_family(const gchar *family_name) | |
| 49 | +{ | |
| 50 | + int rc = 2; | |
| 51 | + | |
| 52 | + gint n_families, i; | |
| 53 | + PangoFontFamily **families; | |
| 54 | + | |
| 55 | + PangoContext * context = gdk_pango_context_get_for_screen(gdk_screen_get_default()); | |
| 56 | + | |
| 57 | + pango_context_list_families(context,&families, &n_families); | |
| 58 | + | |
| 59 | + for(i=0; i < n_families; i++) | |
| 60 | + { | |
| 61 | + if(!g_ascii_strcasecmp(pango_font_family_get_name(families[i]),family_name)) | |
| 62 | + { | |
| 63 | + rc = pango_font_family_is_monospace(families[i]) ? 0 : 1; | |
| 64 | + break; | |
| 65 | + } | |
| 66 | + | |
| 67 | + | |
| 68 | + } | |
| 69 | + g_object_unref(G_OBJECT(context)); | |
| 70 | + g_free(families); | |
| 71 | + | |
| 72 | + return rc; | |
| 73 | +} | |
| 74 | + | |
| 47 | 75 | LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name) |
| 48 | 76 | { |
| 49 | 77 | v3270 * terminal; |
| ... | ... | @@ -57,6 +85,22 @@ LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name) |
| 57 | 85 | |
| 58 | 86 | if(g_ascii_strcasecmp(terminal->font.family,name)) |
| 59 | 87 | { |
| 88 | + | |
| 89 | + switch(validate_font_family(name)) | |
| 90 | + { | |
| 91 | + case 0: | |
| 92 | + g_message("Change font to \"%s\"", name); | |
| 93 | + break; | |
| 94 | + | |
| 95 | + case 1: | |
| 96 | + g_warning("Font \"%s\" is not monospace", name); | |
| 97 | + break; | |
| 98 | + | |
| 99 | + default: | |
| 100 | + g_warning("Invalid or unexpected font family name: \"%s\"", name); | |
| 101 | + | |
| 102 | + } | |
| 103 | + | |
| 60 | 104 | // Font has changed, update it |
| 61 | 105 | g_free(terminal->font.family); |
| 62 | 106 | ... | ... |