From bdb96507bd59daf9f4002ea170dc4c05ed368a3c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 24 Sep 2019 22:37:48 +0200 Subject: [PATCH] CSS: Handle unknown resolution gdk_screen_get_resolution() can return -1 when the resolution is unknown. Catch that case and use the default resolution of 96, like in every other case. Fixes #2119 --- gtk/gtkcssshorthandpropertyimpl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c index d46be8bd0d..53465a988c 100644 --- a/gtk/gtkcssshorthandpropertyimpl.c +++ b/gtk/gtkcssshorthandpropertyimpl.c @@ -1118,7 +1118,12 @@ unpack_font_description (GtkCssShorthandProperty *shorthand, g_value_init (&v, G_TYPE_DOUBLE); size = pango_font_description_get_size (description) / PANGO_SCALE; if (!pango_font_description_get_size_is_absolute (description)) - size = size * gdk_screen_get_resolution (gdk_screen_get_default ()) / 72.0; + { + double dpi = gdk_screen_get_resolution (gdk_screen_get_default ()); + if (dpi <= 0.0) + dpi = 96.0; + size = size * dpi / 72.0; + } g_value_set_double (&v, size); prop = _gtk_style_property_lookup ("font-size"); _gtk_style_property_assign (prop, props, state, &v);