aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-12-11 17:00:05 -0800
committerGuy Harris <guy@alum.mit.edu>2015-12-12 01:01:46 +0000
commitb8b77aecc38f8ada88de78939e4d35d0fa535bd4 (patch)
tree8e4920303bff3e98213c8c527d9485ba85a0c59b
parent2ebfa30ffd8c5ef76d06f1705cb7e7797bda954a (diff)
Clamp zooming so that we don't get zero or negative font sizes.
Those are obviously wrong. Also, clean up some stuff left over from the GTK+ 1.x days; GTK+ 2.x doesn't expose raw XLFD font names, it lets you specify a font by name and size, and font_zoom() doesn't determine whether the font is resizeable - it just constructs a new font name/size pair and leaves it up to its callers to try to load the font, so "there's no such font as Wingdings Gothic" and "you can't blow up Fraktur to 10 million points" both show up as errors loading the font by name. Bug: 8854 Change-Id: I6af142c75c9ebabd1a95308c203f8cb1f36dd82f Reviewed-on: https://code.wireshark.org/review/12549 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--ui/gtk/font_utils.c28
-rw-r--r--ui/gtk/font_utils.h2
-rw-r--r--ui/gtk/main.c8
-rw-r--r--ui/gtk/prefs_font_color.c5
4 files changed, 17 insertions, 26 deletions
diff --git a/ui/gtk/font_utils.c b/ui/gtk/font_utils.c
index 825d13f552..4fb41dacf1 100644
--- a/ui/gtk/font_utils.c
+++ b/ui/gtk/font_utils.c
@@ -79,8 +79,7 @@ view_zoom_in_cb(GtkWidget *w _U_, gpointer d _U_)
case FA_SUCCESS:
break;
- case FA_FONT_NOT_RESIZEABLE:
- /* "font_apply()" popped up an alert box. */
+ case FA_ZOOMED_TOO_FAR:
recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */
break;
@@ -105,8 +104,7 @@ view_zoom_out_cb(GtkWidget *w _U_, gpointer d _U_)
case FA_SUCCESS:
break;
- case FA_FONT_NOT_RESIZEABLE:
- /* "font_apply()" popped up an alert box. */
+ case FA_ZOOMED_TOO_FAR:
recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */
break;
@@ -131,8 +129,7 @@ view_zoom_100_cb(GtkWidget *w _U_, gpointer d _U_)
case FA_SUCCESS:
break;
- case FA_FONT_NOT_RESIZEABLE:
- /* "font_apply()" popped up an alert box. */
+ case FA_ZOOMED_TOO_FAR:
recent.gui_zoom_level = save_gui_zoom_level; /* undo zoom */
break;
@@ -180,9 +177,7 @@ font_zoom(char *gui_font_name)
long font_point_size_l;
if (recent.gui_zoom_level == 0) {
- /* There is no zoom factor - just return the name, so that if
- this is GTK+ 1.2[.x] and the font name isn't an XLFD font
- name, we don't fail. */
+ /* There is no zoom factor - just return the name */
return g_strdup(gui_font_name);
}
@@ -196,6 +191,9 @@ font_zoom(char *gui_font_name)
/* calculate the new font size */
font_point_size_l = strtol(font_name_p, NULL, 10);
font_point_size_l += recent.gui_zoom_level;
+ /* make sure the size didn't become zero or negative */
+ if (font_point_size_l <= 0)
+ return NULL;
/* build a new font name */
new_font_name = g_strdup_printf("%s %ld", font_name_dup, font_point_size_l);
@@ -213,16 +211,8 @@ user_font_apply(void) {
/* convert font name to reflect the zoom level */
gui_font_name = font_zoom(prefs.gui_gtk2_font_name);
- if (gui_font_name == NULL) {
- /*
- * This means the font name isn't an XLFD font name.
- * We just report that for now as a font not available in
- * multiple sizes.
- */
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "Your current font isn't available in any other sizes.\n");
- return FA_FONT_NOT_RESIZEABLE;
- }
+ if (gui_font_name == NULL)
+ return FA_ZOOMED_TOO_FAR;
/* load normal font */
new_r_font = pango_font_description_from_string(gui_font_name);
diff --git a/ui/gtk/font_utils.h b/ui/gtk/font_utils.h
index 5ff485eb7f..d9678e1121 100644
--- a/ui/gtk/font_utils.h
+++ b/ui/gtk/font_utils.h
@@ -40,7 +40,7 @@ extern void font_init(void);
/** Return value from font_apply() */
typedef enum {
FA_SUCCESS, /**< function succeeded */
- FA_FONT_NOT_RESIZEABLE, /**< the chosen font isn't resizable */
+ FA_ZOOMED_TOO_FAR, /**< we've zoomed too far */
FA_FONT_NOT_AVAILABLE /**< the chosen font isn't available */
} fa_ret_t;
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 9e92ac27f6..c3fe025305 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -3154,9 +3154,10 @@ DIAG_ON(cast-qual)
switch (user_font_apply()) {
case FA_SUCCESS:
break;
- case FA_FONT_NOT_RESIZEABLE:
- /* "user_font_apply()" popped up an alert box. */
- /* turn off zooming - font can't be resized */
+ case FA_ZOOMED_TOO_FAR:
+ /* The zoom level is too big for this font; turn off zooming. */
+ recent.gui_zoom_level = 0;
+ break;
case FA_FONT_NOT_AVAILABLE:
/* XXX - did we successfully load the un-zoomed version earlier?
If so, this *probably* means the font is available, but not at
@@ -3168,6 +3169,7 @@ DIAG_ON(cast-qual)
/* in any other case than FA_SUCCESS, turn off zooming */
recent.gui_zoom_level = 0;
/* XXX: would it be a good idea to disable zooming (insensitive GUI)? */
+ break;
}
dnd_init(top_level);
diff --git a/ui/gtk/prefs_font_color.c b/ui/gtk/prefs_font_color.c
index f6325b7c0f..fafe0f07b9 100644
--- a/ui/gtk/prefs_font_color.c
+++ b/ui/gtk/prefs_font_color.c
@@ -507,9 +507,8 @@ font_color_prefs_apply(GtkWidget *w _U_, gboolean redissect)
case FA_SUCCESS:
break;
- case FA_FONT_NOT_RESIZEABLE:
- /* "user_font_apply()" popped up an alert box. */
- /* turn off zooming - font can't be resized */
+ case FA_ZOOMED_TOO_FAR:
+ /* zoomed too far - turn off zooming */
recent.gui_zoom_level = 0;
break;