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>
This commit is contained in:
Guy Harris 2015-12-11 17:00:05 -08:00
parent 2ebfa30ffd
commit b8b77aecc3
4 changed files with 17 additions and 26 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;