Qt: try harder to find a working monospace font

QFont::toString returned the default font (which might be unavailable),
leading to use of non-monospace fonts in the bytes view. Detect the
effective font instead and apply it to avoid this issue.

Add additional logic to invoke font detection when the configured font
is bad (for example, because of the bug or because a font has been
removed in meantime).

Bug: 13638
Change-Id: I8a625cf365c90119caebe8c4deada0df7426e53a
Reviewed-on: https://code.wireshark.org/review/21551
Reviewed-by: Jörg Mayer <jmayer@loplof.de>
Petri-Dish: Jörg Mayer <jmayer@loplof.de>
Tested-by: Jörg Mayer <jmayer@loplof.de>
Reviewed-by: Ahmad Fatoum <ahmad@a3f.at>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Peter Wu 2017-05-07 21:50:00 +02:00 committed by Michael Mann
parent ee37135c67
commit ab504191fc
1 changed files with 9 additions and 1 deletions

View File

@ -86,6 +86,7 @@
#include <QEvent>
#include <QFileOpenEvent>
#include <QFontMetrics>
#include <QFontInfo>
#include <QLibraryInfo>
#include <QLocale>
#include <QMutableListIterator>
@ -274,7 +275,11 @@ void WiresharkApplication::setMonospaceFont(const char *font_string) {
if (font_string && strlen(font_string) > 0) {
mono_font_.fromString(font_string);
return;
// Only accept the font name if it actually exists.
if (mono_font_.family() == QFontInfo(mono_font_).family()) {
return;
}
}
// http://en.wikipedia.org/wiki/Category:Monospaced_typefaces
@ -313,6 +318,9 @@ void WiresharkApplication::setMonospaceFont(const char *font_string) {
mono_font_.setPointSize(wsApp->font().pointSize() + font_size_adjust);
mono_font_.setBold(false);
// Retrieve the effective font and apply it.
mono_font_.setFamily(QFontInfo(mono_font_).family());
g_free(prefs.gui_qt_font_name);
prefs.gui_qt_font_name = qstring_strdup(mono_font_.toString());
}