Fix '(space :relative-width N)' display spec w/non-ASCII chars

* src/xdisp.c (produce_stretch_glyph): Use the correct face for
non-ASCII characters.  Support :relative-width display spec on
Lisp strings, not just on buffer text.
This commit is contained in:
Eli Zaretskii 2021-11-22 20:00:48 +02:00
parent 712898210f
commit d791cd556d

View file

@ -29810,7 +29810,7 @@ append_stretch_glyph (struct it *it, Lisp_Object object,
#endif /* HAVE_WINDOW_SYSTEM */ #endif /* HAVE_WINDOW_SYSTEM */
/* Produce a stretch glyph for iterator IT. IT->object is the value /* Produce a stretch glyph for iterator IT. IT->object is the value
of the glyph property displayed. The value must be a list of the display property. The value must be a list of the form
`(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
being recognized: being recognized:
@ -29820,7 +29820,7 @@ append_stretch_glyph (struct it *it, Lisp_Object object,
2. `:relative-width FACTOR' specifies that the width of the stretch 2. `:relative-width FACTOR' specifies that the width of the stretch
should be computed from the width of the first character having the should be computed from the width of the first character having the
`glyph' property, and should be FACTOR times that width. `display' property, and should be FACTOR times that width.
3. `:align-to HPOS' specifies that the space should be wide enough 3. `:align-to HPOS' specifies that the space should be wide enough
to reach HPOS, a value in canonical character units. to reach HPOS, a value in canonical character units.
@ -29832,7 +29832,7 @@ append_stretch_glyph (struct it *it, Lisp_Object object,
5. `:relative-height FACTOR' specifies that the height of the 5. `:relative-height FACTOR' specifies that the height of the
stretch should be FACTOR times the height of the characters having stretch should be FACTOR times the height of the characters having
the glyph property. the display property.
Either none or exactly one of 4 or 5 must be present. Either none or exactly one of 4 or 5 must be present.
@ -29853,10 +29853,11 @@ produce_stretch_glyph (struct it *it)
#ifdef HAVE_WINDOW_SYSTEM #ifdef HAVE_WINDOW_SYSTEM
int ascent = 0; int ascent = 0;
bool zero_height_ok_p = false; bool zero_height_ok_p = false;
struct face *face;
if (FRAME_WINDOW_P (it->f)) if (FRAME_WINDOW_P (it->f))
{ {
struct face *face = FACE_FROM_ID (it->f, it->face_id); face = FACE_FROM_ID (it->f, it->face_id);
font = face->font ? face->font : FRAME_FONT (it->f); font = face->font ? face->font : FRAME_FONT (it->f);
prepare_face_for_display (it->f, face); prepare_face_for_display (it->f, face);
} }
@ -29877,14 +29878,27 @@ produce_stretch_glyph (struct it *it)
else if (prop = Fplist_get (plist, QCrelative_width), NUMVAL (prop) > 0) else if (prop = Fplist_get (plist, QCrelative_width), NUMVAL (prop) > 0)
{ {
/* Relative width `:relative-width FACTOR' specified and valid. /* Relative width `:relative-width FACTOR' specified and valid.
Compute the width of the characters having the `glyph' Compute the width of the characters having this `display'
property. */ property. */
struct it it2; struct it it2;
unsigned char *p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); Lisp_Object object = it->stack[it->sp - 1].string;
unsigned char *p = (STRINGP (object)
? SDATA (object) + IT_STRING_BYTEPOS (*it)
: BYTE_POS_ADDR (IT_BYTEPOS (*it)));
bool multibyte_p =
STRINGP (object) ? STRING_MULTIBYTE (object) : it->multibyte_p;
it2 = *it; it2 = *it;
if (it->multibyte_p) if (multibyte_p)
it2.c = it2.char_to_display = string_char_and_length (p, &it2.len); {
it2.c = it2.char_to_display = string_char_and_length (p, &it2.len);
#ifdef HAVE_WINDOW_SYSTEM
if (FRAME_WINDOW_P (it->f) && ! ASCII_CHAR_P (it2.c))
it2.face_id = FACE_FOR_CHAR (it->f, face, it2.c,
IT_CHARPOS (*it),
STRINGP (object)? object : Qnil);
#endif
}
else else
{ {
it2.c = it2.char_to_display = *p, it2.len = 1; it2.c = it2.char_to_display = *p, it2.len = 1;