Fix handling of FROM = t and TO = t by 'window-text-pixel-size'

* src/xdisp.c (Fwindow_text_pixel_size): Use byte position for
accessing buffer text, not character positions.  (Bug#41125)
This commit is contained in:
Eli Zaretskii 2020-05-08 13:35:34 +03:00
parent 76516465bf
commit a76cafea0d

View file

@ -10442,7 +10442,7 @@ include the height of both, if present, in the return value. */)
struct buffer *b; struct buffer *b;
struct it it; struct it it;
struct buffer *old_b = NULL; struct buffer *old_b = NULL;
ptrdiff_t start, end, pos; ptrdiff_t start, end, bpos;
struct text_pos startp; struct text_pos startp;
void *itdata = NULL; void *itdata = NULL;
int c, max_x = 0, max_y = 0, x = 0, y = 0; int c, max_x = 0, max_y = 0, x = 0, y = 0;
@ -10457,32 +10457,56 @@ include the height of both, if present, in the return value. */)
} }
if (NILP (from)) if (NILP (from))
start = BEGV; {
start = BEGV;
bpos = BEGV_BYTE;
}
else if (EQ (from, Qt)) else if (EQ (from, Qt))
{ {
start = pos = BEGV; start = BEGV;
while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) bpos = BEGV_BYTE;
&& (c == ' ' || c == '\t' || c == '\n' || c == '\r')) while (bpos < ZV_BYTE)
start = pos; {
while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t')) FETCH_CHAR_ADVANCE (c, start, bpos);
start = pos; if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r'))
break;
}
while (bpos > BEGV_BYTE)
{
DEC_BOTH (start, bpos);
c = FETCH_CHAR (bpos);
if (!(c == ' ' || c == '\t'))
break;
}
} }
else else
{ {
CHECK_FIXNUM_COERCE_MARKER (from); CHECK_FIXNUM_COERCE_MARKER (from);
start = min (max (XFIXNUM (from), BEGV), ZV); start = min (max (XFIXNUM (from), BEGV), ZV);
bpos = CHAR_TO_BYTE (start);
} }
SET_TEXT_POS (startp, start, bpos);
if (NILP (to)) if (NILP (to))
end = ZV; end = ZV;
else if (EQ (to, Qt)) else if (EQ (to, Qt))
{ {
end = pos = ZV; end = ZV;
while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) bpos = ZV_BYTE;
&& (c == ' ' || c == '\t' || c == '\n' || c == '\r')) while (bpos > BEGV_BYTE)
end = pos; {
while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t')) DEC_BOTH (end, bpos);
end = pos; c = FETCH_CHAR (bpos);
if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r'))
break;
}
while (bpos < ZV_BYTE)
{
FETCH_CHAR_ADVANCE (c, end, bpos);
if (!(c == ' ' || c == '\t'))
break;
}
} }
else else
{ {
@ -10499,7 +10523,6 @@ include the height of both, if present, in the return value. */)
max_y = XFIXNUM (y_limit); max_y = XFIXNUM (y_limit);
itdata = bidi_shelve_cache (); itdata = bidi_shelve_cache ();
SET_TEXT_POS (startp, start, CHAR_TO_BYTE (start));
start_display (&it, w, startp); start_display (&it, w, startp);
/* It makes no sense to measure dimensions of region of text that /* It makes no sense to measure dimensions of region of text that
crosses the point where bidi reordering changes scan direction. crosses the point where bidi reordering changes scan direction.