Revert "Improve last change to xfaces.c" (05ece1eb8b)

* src/xfaces.c: Revert 05ece1eb8b.

See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59347#331.
This commit is contained in:
Gregory Heytings 2022-12-12 02:12:09 +01:00
parent 24c8c28ae6
commit b8d2ec920f

View file

@ -6014,21 +6014,6 @@ realize_non_ascii_face (struct frame *f, Lisp_Object font_object,
} }
#endif /* HAVE_WINDOW_SYSTEM */ #endif /* HAVE_WINDOW_SYSTEM */
/* Remove the attribute at INDEX from the font object if SYMBOL
appears in `font-fallback-ignored-attributes'. */
static void
font_maybe_unset_attribute (Lisp_Object font_object,
enum font_property_index index, Lisp_Object symbol)
{
Lisp_Object tail = Vface_font_lax_matched_attributes;
FOR_EACH_TAIL_SAFE (tail)
{
if (EQ (XCAR (tail), symbol))
ASET (font_object, index, Qnil);
}
}
/* Realize the fully-specified face with attributes ATTRS in face /* Realize the fully-specified face with attributes ATTRS in face
cache CACHE for ASCII characters. Do it for GUI frame CACHE->f. cache CACHE for ASCII characters. Do it for GUI frame CACHE->f.
@ -6088,33 +6073,38 @@ realize_gui_face (struct face_cache *cache, Lisp_Object attrs[LFACE_VECTOR_SIZE]
if (! FONT_OBJECT_P (attrs[LFACE_FONT_INDEX])) if (! FONT_OBJECT_P (attrs[LFACE_FONT_INDEX]))
{ {
Lisp_Object spec = copy_font_spec (attrs[LFACE_FONT_INDEX]); Lisp_Object spec = copy_font_spec (attrs[LFACE_FONT_INDEX]);
#define MAYBE_UNSET_ATTRIBUTE(ATTR) \
/* Maybe unset several values in SPEC, usually the width, if (realize_gui_face_ignored_spec_attributes \
slant, and weight. The best possible values for these & (1 << FONT_##ATTR##_INDEX)) \
attributes are determined in font_find_for_lface, called ASET (spec, FONT_##ATTR##_INDEX, Qnil);
by font_load_for_lface, when the list of candidate fonts /* The default value of
returned by font_list_entities is sorted by font_select_entity realize_gui_face_ignored_spec_attributes unsets the
(which calls font_sort_entities, which calls font_score). weight, slant and width in spec. The best possible
If these attributes are not unset here, the candidate values for these attributes is determined in
font list returned by font_list_entities only contains font_find_for_lface, called by font_load_for_lface, when
fonts that are exact matches for these weight, slant, and the candidate list returned by font_list_entities is
width attributes, which could lead to suboptimal or wrong sorted by font_select_entity (which calls
font selection. (bug#5934) */ font_sort_entities, which calls font_score). If these
font_maybe_unset_attribute (spec, FONT_WEIGHT_INDEX, QCweight); attributes are not unset here, the candidate font list
font_maybe_unset_attribute (spec, FONT_SLANT_INDEX, QCslant); returned by font_list_entities only contains fonts that
font_maybe_unset_attribute (spec, FONT_WIDTH_INDEX, QCwidth); are exact matches for these weight, slant and width
attributes, which leads to suboptimal or wrong font
choices. See bug#59347. */
MAYBE_UNSET_ATTRIBUTE (WEIGHT);
MAYBE_UNSET_ATTRIBUTE (SLANT);
MAYBE_UNSET_ATTRIBUTE (WIDTH);
/* Also allow unsetting other attributes for debugging /* Also allow unsetting other attributes for debugging
purposes. But not FONT_EXTRA_INDEX; that is not safe to purposes. */
touch, at least in the Haiku font backend. */ MAYBE_UNSET_ATTRIBUTE (FAMILY);
font_maybe_unset_attribute (spec, FONT_FAMILY_INDEX, QCfamily); MAYBE_UNSET_ATTRIBUTE (FOUNDRY);
font_maybe_unset_attribute (spec, FONT_FOUNDRY_INDEX, QCfoundry); MAYBE_UNSET_ATTRIBUTE (REGISTRY);
font_maybe_unset_attribute (spec, FONT_REGISTRY_INDEX, QCregistry); MAYBE_UNSET_ATTRIBUTE (ADSTYLE);
font_maybe_unset_attribute (spec, FONT_ADSTYLE_INDEX, QCadstyle); MAYBE_UNSET_ATTRIBUTE (SIZE);
font_maybe_unset_attribute (spec, FONT_SIZE_INDEX, QCsize); MAYBE_UNSET_ATTRIBUTE (DPI);
font_maybe_unset_attribute (spec, FONT_DPI_INDEX, QCdpi); MAYBE_UNSET_ATTRIBUTE (SPACING);
font_maybe_unset_attribute (spec, FONT_SPACING_INDEX, QCspacing); MAYBE_UNSET_ATTRIBUTE (AVGWIDTH);
font_maybe_unset_attribute (spec, FONT_AVGWIDTH_INDEX, QCavgwidth); MAYBE_UNSET_ATTRIBUTE (EXTRA);
#undef MAYBE_UNSET_ATTRIBUTE
attrs[LFACE_FONT_INDEX] = font_load_for_lface (f, attrs, spec); attrs[LFACE_FONT_INDEX] = font_load_for_lface (f, attrs, spec);
} }
if (FONT_OBJECT_P (attrs[LFACE_FONT_INDEX])) if (FONT_OBJECT_P (attrs[LFACE_FONT_INDEX]))
@ -7404,24 +7394,27 @@ Lisp programs that change the value of this variable should also
clear the face cache, see `clear-face-cache'. */); clear the face cache, see `clear-face-cache'. */);
face_near_same_color_threshold = 30000; face_near_same_color_threshold = 30000;
DEFVAR_LISP ("face-font-lax-matched-attributes", DEFVAR_INT ("realize-gui-face-ignored-spec-attributes",
Vface_font_lax_matched_attributes, realize_gui_face_ignored_spec_attributes,
doc: /* Font-related face attributes to match in lax manner when realizing faces. doc: /* Ignored font-spec attributes in realize_gui_face.
The value should be a list of font-related face attribute symbols; The value is an integer number and represents a bit mask.
see `set-face-attribute' for the full list of attributes. The The attribute corresponding to each bit that is set is cleared in
corresponding face attributes will be treated as "soft" constraints realize_gui_face. The bits are: 1 = :foundry, 2 = :family,
when looking for suitable fonts: if an exact match is not possible, 3 = :adstyle, 4 = :registry, 5 = :weight, 6 = :slant, 7 = :width,
a font can be selected that is a close, but not an exact, match. For 8 = :size, 9 = :dpi, 10 = :spacing, 11 = :avgwidth, 12 = extra
example, looking for a semi-bold font might select a bold or a medium attributes (:name, :script, :lang and :otf).
font if no semi-bold font matching other attributes is found. Emacs
still tries to find a font that is the closest possible match; in
particular, if a font is available that matches the face attributes
exactly, it will be selected.
Note that if the `:extra' attribute is present in the value, it Bits 5 to 7 are set in the default value. When these bits are not
will be ignored. */); set, and when the font chosen for the default face has a weight, slant
Vface_font_lax_matched_attributes = list3 (QCweight, QCslant, QCwidth); or width that is not supported by other available fonts on the system,
such as 'medium', Emacs may select suboptimal fonts for other faces.
There is no reason to change that value except for debugging purposes. */);
realize_gui_face_ignored_spec_attributes =
(1 << FONT_WEIGHT_INDEX) |
(1 << FONT_SLANT_INDEX) |
(1 << FONT_WIDTH_INDEX);
#ifdef HAVE_WINDOW_SYSTEM #ifdef HAVE_WINDOW_SYSTEM
defsubr (&Sbitmap_spec_p); defsubr (&Sbitmap_spec_p);