diff --git a/include/helper.h b/include/helper.h index a74a162e..85ff158a 100644 --- a/include/helper.h +++ b/include/helper.h @@ -234,4 +234,12 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st * characters (not bytes) of `b`. */ int utf8_strncmp ( const char *a, const char* b, size_t n ); + +/** + * @param pfd Pango font description to validate. + * @param font The name of the font to check. + * + * @returns true if font is valid. + */ +gboolean helper_validate_font ( PangoFontDescription *pfd, const char *font ); #endif // ROFI_HELPER_H diff --git a/source/helper.c b/source/helper.c index 9f136dbf..159a05bb 100644 --- a/source/helper.c +++ b/source/helper.c @@ -50,6 +50,8 @@ #include "rofi.h" #include "view.h" +#define LOG_DOMAIN "Helper" + const char *const monitor_position_entries[] = { "on focused monitor", "on focused window", @@ -524,6 +526,18 @@ void remove_pid_file ( int fd ) } } +gboolean helper_validate_font ( PangoFontDescription *pfd, const char *font ) +{ + const char *fam = pango_font_description_get_family ( pfd ); + int size = pango_font_description_get_size ( pfd ); + if ( fam == NULL || size == 0 ){ + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Pango failed to parse font: '%s'", font); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got family: %s at size: %d", fam?fam:"{unknown}", size); + return FALSE; + } + return TRUE; +} + /** * Do some input validation, especially the first few could break things. * It is good to catch them beforehand. diff --git a/source/view.c b/source/view.c index 967178f8..ed494853 100644 --- a/source/view.c +++ b/source/view.c @@ -694,7 +694,9 @@ void __create_window ( MenuFlags menu_flags ) char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font ); if ( font ) { PangoFontDescription *pfd = pango_font_description_from_string ( font ); - pango_context_set_font_description ( p, pfd ); + if ( helper_validate_font(pfd, font)) { + pango_context_set_font_description ( p, pfd ); + } pango_font_description_free ( pfd ); } PangoLanguage *l = pango_language_get_default(); diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 06cf5d0d..76ef94af 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -31,6 +31,7 @@ #include #include "widgets/textbox.h" #include "keyb.h" +#include "helper.h" #include "x11-helper.h" #include "mode.h" #include "view.h" @@ -125,12 +126,20 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType if ( tbfc == NULL ){ tbfc = g_malloc0 ( sizeof (TBFontConfig) ); tbfc->pfd = pango_font_description_from_string ( font ); - tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL ); - g_hash_table_insert ( tbfc_cache, font, tbfc); + if ( helper_validate_font ( tbfc->pfd, font)) { + tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL ); + g_hash_table_insert ( tbfc_cache, font, tbfc); + } else { + pango_font_description_free ( tbfc->pfd ); + g_free( tbfc); + tbfc = NULL; + } + } + if ( tbfc ) { + // Update for used font. + pango_layout_set_font_description ( tb->layout, tbfc->pfd ); + tb->metrics = tbfc->metrics; } - // Update for used font. - pango_layout_set_font_description ( tb->layout, tbfc->pfd ); - tb->metrics = tbfc->metrics; }