Recalculate font metrics when DPI changes

Fixes: #2296
This commit is contained in:
David Woodhouse 2019-01-21 11:55:18 +00:00
parent 7abeb10cf1
commit e417fbffbb

View File

@ -146,6 +146,7 @@ static void gtk_xtext_search_textentry_fini (gpointer, gpointer);
static void gtk_xtext_search_fini (xtext_buffer *); static void gtk_xtext_search_fini (xtext_buffer *);
static gboolean gtk_xtext_search_init (xtext_buffer *buf, const gchar *text, gtk_xtext_search_flags flags, GError **perr); static gboolean gtk_xtext_search_init (xtext_buffer *buf, const gchar *text, gtk_xtext_search_flags flags, GError **perr);
static char * gtk_xtext_get_word (GtkXText * xtext, int x, int y, textentry ** ret_ent, int *ret_off, int *ret_len, GSList **slp); static char * gtk_xtext_get_word (GtkXText * xtext, int x, int y, textentry ** ret_ent, int *ret_off, int *ret_len, GSList **slp);
static void backend_reload_font(GtkXText *xtext);
#define xtext_draw_bg(xt,x,y,w,h) gdk_draw_rectangle(xt->draw_buf, xt->bgc, 1, x, y, w, h); #define xtext_draw_bg(xt,x,y,w,h) gdk_draw_rectangle(xt->draw_buf, xt->bgc, 1, x, y, w, h);
@ -266,7 +267,8 @@ backend_font_open (GtkXText *xtext, char *name)
PangoFontMetrics *metrics; PangoFontMetrics *metrics;
xtext->font = &xtext->pango_font; xtext->font = &xtext->pango_font;
xtext->font->font = backend_font_open_real (name); if (name)
xtext->font->font = backend_font_open_real (name);
if (!xtext->font->font) if (!xtext->font->font)
{ {
xtext->font = NULL; xtext->font = NULL;
@ -540,6 +542,11 @@ gtk_xtext_new (GdkColor palette[], int separator)
gtk_widget_set_double_buffered (GTK_WIDGET (xtext), FALSE); gtk_widget_set_double_buffered (GTK_WIDGET (xtext), FALSE);
gtk_xtext_set_palette (xtext, palette); gtk_xtext_set_palette (xtext, palette);
g_signal_connect_object(gtk_widget_get_settings(GTK_WIDGET(xtext)),
"notify::gtk-xft-dpi",
G_CALLBACK(backend_reload_font),
xtext, G_CONNECT_SWAPPED|G_CONNECT_AFTER);
return GTK_WIDGET (xtext); return GTK_WIDGET (xtext);
} }
@ -3465,11 +3472,20 @@ gtk_xtext_recalc_widths (xtext_buffer *buf, int do_str_width)
gtk_xtext_calc_lines (buf, FALSE); gtk_xtext_calc_lines (buf, FALSE);
} }
static void
backend_reload_font(GtkXText *xtext)
{
if (gtk_widget_get_realized (GTK_WIDGET(xtext)) && xtext->font)
{
gtk_xtext_set_font(xtext, NULL);
gtk_widget_queue_draw(GTK_WIDGET(xtext));
}
}
int int
gtk_xtext_set_font (GtkXText *xtext, char *name) gtk_xtext_set_font (GtkXText *xtext, char *name)
{ {
if (name && xtext->font)
if (xtext->font)
backend_font_close (xtext); backend_font_close (xtext);
/* realize now, so that font_open has a XDisplay */ /* realize now, so that font_open has a XDisplay */