mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-11 13:50:48 -05:00
Don't apply fonts that don't result in family name or have size 0.
Issue: 554
This commit is contained in:
parent
42a1eba275
commit
8f4a4d51c6
4 changed files with 39 additions and 6 deletions
|
@ -234,4 +234,12 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st
|
||||||
* characters (not bytes) of `b`.
|
* characters (not bytes) of `b`.
|
||||||
*/
|
*/
|
||||||
int utf8_strncmp ( const char *a, const char* b, size_t n );
|
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
|
#endif // ROFI_HELPER_H
|
||||||
|
|
|
@ -50,6 +50,8 @@
|
||||||
#include "rofi.h"
|
#include "rofi.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
|
||||||
|
#define LOG_DOMAIN "Helper"
|
||||||
|
|
||||||
const char *const monitor_position_entries[] = {
|
const char *const monitor_position_entries[] = {
|
||||||
"on focused monitor",
|
"on focused monitor",
|
||||||
"on focused window",
|
"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: <b>%s</b> at size: <b>%d</b>", fam?fam:"{unknown}", size);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do some input validation, especially the first few could break things.
|
* Do some input validation, especially the first few could break things.
|
||||||
* It is good to catch them beforehand.
|
* It is good to catch them beforehand.
|
||||||
|
|
|
@ -694,7 +694,9 @@ void __create_window ( MenuFlags menu_flags )
|
||||||
char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
|
char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font );
|
||||||
if ( font ) {
|
if ( font ) {
|
||||||
PangoFontDescription *pfd = pango_font_description_from_string ( font );
|
PangoFontDescription *pfd = pango_font_description_from_string ( font );
|
||||||
|
if ( helper_validate_font(pfd, font)) {
|
||||||
pango_context_set_font_description ( p, pfd );
|
pango_context_set_font_description ( p, pfd );
|
||||||
|
}
|
||||||
pango_font_description_free ( pfd );
|
pango_font_description_free ( pfd );
|
||||||
}
|
}
|
||||||
PangoLanguage *l = pango_language_get_default();
|
PangoLanguage *l = pango_language_get_default();
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "widgets/textbox.h"
|
#include "widgets/textbox.h"
|
||||||
#include "keyb.h"
|
#include "keyb.h"
|
||||||
|
#include "helper.h"
|
||||||
#include "x11-helper.h"
|
#include "x11-helper.h"
|
||||||
#include "mode.h"
|
#include "mode.h"
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
|
@ -125,13 +126,21 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
|
||||||
if ( tbfc == NULL ){
|
if ( tbfc == NULL ){
|
||||||
tbfc = g_malloc0 ( sizeof (TBFontConfig) );
|
tbfc = g_malloc0 ( sizeof (TBFontConfig) );
|
||||||
tbfc->pfd = pango_font_description_from_string ( font );
|
tbfc->pfd = pango_font_description_from_string ( font );
|
||||||
|
if ( helper_validate_font ( tbfc->pfd, font)) {
|
||||||
tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL );
|
tbfc->metrics = pango_context_get_metrics ( p_context, tbfc->pfd, NULL );
|
||||||
g_hash_table_insert ( tbfc_cache, font, tbfc);
|
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.
|
// Update for used font.
|
||||||
pango_layout_set_font_description ( tb->layout, tbfc->pfd );
|
pango_layout_set_font_description ( tb->layout, tbfc->pfd );
|
||||||
tb->metrics = tbfc->metrics;
|
tb->metrics = tbfc->metrics;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( ( flags & TB_WRAP ) == TB_WRAP ) {
|
if ( ( flags & TB_WRAP ) == TB_WRAP ) {
|
||||||
|
|
Loading…
Reference in a new issue