Skip to content

Commit 5747a59

Browse files
committed
Recalculate default font when switching font backend
This is an updated version of the patch by Dmitry Antipov <[email protected]> in <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=23386#43>. Fixes Bug#23386 * src/dispextern.h (struct redisplay_interface): New member default_font_parameter. * src/xterm.h: Add prototype for x_default_font_parameter. * src/xterm.c (x_redisplay_interface): Initialize default_font_parameter member. * src/xfns.c (x_default_font_parameter): Make non-static. * src/w32term.h: Add prototype for w32_default_font_parameter * src/w32fns.c (w32_default_font_parameter): Make non-static. * src/w32term.c (w32_redisplay_interface): Initialize default_font_parameter member. * src/nsterm.m (ns_redisplay_interface): Add dummy ns_default_font_parameter (there is currently only one possible font backend on macOS). Initialize default_font_parameter member. * src/frame.c (gui_set_font_backend): Recalculate default font using RIF default_font_parameter to avoid crash when changing font backend.
1 parent a2dd8c4 commit 5747a59

File tree

9 files changed

+30
-10
lines changed

9 files changed

+30
-10
lines changed

src/dispextern.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,9 @@ struct redisplay_interface
30033003
/* Cancel hourglass cursor on frame F. */
30043004
void (*hide_hourglass) (struct frame *f);
30053005

3006+
/* Called to (re)calculate the default face when changing the font
3007+
backend. */
3008+
void (*default_font_parameter) (struct frame *f, Lisp_Object parms);
30063009
#endif /* HAVE_WINDOW_SYSTEM */
30073010
};
30083011

src/frame.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4565,7 +4565,11 @@ gui_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_va
45654565
return;
45664566

45674567
if (FRAME_FONT (f))
4568-
free_all_realized_faces (Qnil);
4568+
{
4569+
Lisp_Object frame;
4570+
XSETFRAME (frame, f);
4571+
free_all_realized_faces (frame);
4572+
}
45694573

45704574
new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
45714575
if (NILP (new_value))
@@ -4579,10 +4583,8 @@ gui_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_va
45794583

45804584
if (FRAME_FONT (f))
45814585
{
4582-
Lisp_Object frame;
4583-
4584-
XSETFRAME (frame, f);
4585-
gui_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
4586+
/* Reconsider default font after backend(s) change (Bug#23386). */
4587+
FRAME_RIF(f)->default_font_parameter (f, Qnil);
45864588
face_change = true;
45874589
windows_or_buffers_changed = 18;
45884590
}

src/nsterm.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5132,6 +5132,13 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
51325132
reset_mouse_highlight (&dpyinfo->mouse_highlight);
51335133
}
51345134

5135+
/* This currently does nothing, since it's only really needed when
5136+
changing the font-backend, but macOS currently only has one
5137+
possible backend. This may change if we add HarfBuzz support. */
5138+
static void
5139+
ns_default_font_parameter (struct frame *f, Lisp_Object parms)
5140+
{
5141+
}
51355142

51365143
/* This and next define (many of the) public functions in this file. */
51375144
/* gui_* are generic versions in xdisp.c that we, and other terms, get away
@@ -5167,7 +5174,8 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
51675174
ns_draw_window_divider,
51685175
ns_shift_glyphs_for_insert,
51695176
ns_show_hourglass,
5170-
ns_hide_hourglass
5177+
ns_hide_hourglass,
5178+
ns_default_font_parameter
51715179
};
51725180

51735181

src/w32fns.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5749,7 +5749,7 @@ do_unwind_create_frame (Lisp_Object frame)
57495749
unwind_create_frame (frame);
57505750
}
57515751

5752-
static void
5752+
void
57535753
w32_default_font_parameter (struct frame *f, Lisp_Object parms)
57545754
{
57555755
struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);

src/w32term.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7249,7 +7249,8 @@ static struct redisplay_interface w32_redisplay_interface =
72497249
w32_draw_window_divider,
72507250
w32_shift_glyphs_for_insert,
72517251
w32_show_hourglass,
7252-
w32_hide_hourglass
7252+
w32_hide_hourglass,
7253+
w32_default_font_parameter
72537254
};
72547255

72557256
static void w32_delete_terminal (struct terminal *term);

src/w32term.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ extern void w32con_show_cursor (void);
267267
extern const char *w32_get_string_resource (void *v_rdb,
268268
const char *name,
269269
const char *class);
270+
271+
/* w32fns.c */
272+
extern void w32_default_font_parameter (struct frame* f, Lisp_Object parms);
273+
270274

271275
#define PIX_TYPE COLORREF
272276

src/xfns.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3555,7 +3555,7 @@ do_unwind_create_frame (Lisp_Object frame)
35553555
unwind_create_frame (frame);
35563556
}
35573557

3558-
static void
3558+
void
35593559
x_default_font_parameter (struct frame *f, Lisp_Object parms)
35603560
{
35613561
struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);

src/xterm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13374,7 +13374,8 @@ static struct redisplay_interface x_redisplay_interface =
1337413374
x_draw_window_divider,
1337513375
x_shift_glyphs_for_insert, /* Never called; see comment in function. */
1337613376
x_show_hourglass,
13377-
x_hide_hourglass
13377+
x_hide_hourglass,
13378+
x_default_font_parameter
1337813379
};
1337913380

1338013381

src/xterm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@ extern void x_real_pos_and_offsets (struct frame *f,
10561056
int *xptr,
10571057
int *yptr,
10581058
int *outer_border);
1059+
extern void x_default_font_parameter (struct frame* f, Lisp_Object parms);
10591060

10601061
/* From xrdb.c. */
10611062

0 commit comments

Comments
 (0)