From 1e9e66541553b2a439f8748b1ae12f398040d7e5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 5 Jan 2022 17:11:23 +0100 Subject: [PATCH] Do not override the requested spec in font_open_by_spec * src/font.c (font_open_by_spec): Do not override the requested spec when opening a font. Only provide default values if the spec is underspecified. This ensures that, when loading fonts with multiple matching alternatives, font_load_for_lface will pick the requested variant. --- src/font.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/font.c b/src/font.c index 58ff1a7981..1cb20f5796 100644 --- a/src/font.c +++ b/src/font.c @@ -3544,11 +3544,22 @@ font_open_by_spec (struct frame *f, Lisp_Object spec) { Lisp_Object attrs[LFACE_VECTOR_SIZE]; - /* We set up the default font-related attributes of a face to prefer - a moderate font. */ - attrs[LFACE_FAMILY_INDEX] = attrs[LFACE_FOUNDRY_INDEX] = Qnil; - attrs[LFACE_SWIDTH_INDEX] = attrs[LFACE_WEIGHT_INDEX] - = attrs[LFACE_SLANT_INDEX] = Qnormal; + /* Filter according to spec. */ + attrs[LFACE_FAMILY_INDEX] = Ffont_get (spec, QCfamily); + attrs[LFACE_FOUNDRY_INDEX] = Ffont_get (spec, QCfoundry); + attrs[LFACE_SWIDTH_INDEX] = Ffont_get (spec, QCwidth); + attrs[LFACE_WEIGHT_INDEX] = Ffont_get (spec, QCweight); + attrs[LFACE_SLANT_INDEX] = Ffont_get (spec, QCslant); + + /* We set up the fallback font-related attributes of a face to + prefer a moderate font. */ + if (NILP (attrs[LFACE_SWIDTH_INDEX])) + attrs[LFACE_SWIDTH_INDEX] = Qnormal; + if (NILP (attrs[LFACE_WEIGHT_INDEX])) + attrs[LFACE_WEIGHT_INDEX] = Qnormal; + if (NILP (attrs[LFACE_WEIGHT_INDEX])) + attrs[LFACE_WEIGHT_INDEX] = Qnormal; + #ifndef HAVE_NS attrs[LFACE_HEIGHT_INDEX] = make_fixnum (120); #else -- 2.34.1