[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Add a function that returns pixel distance between points?
From: |
Eli Zaretskii |
Subject: |
Re: Add a function that returns pixel distance between points? |
Date: |
Wed, 03 Feb 2021 17:04:54 +0200 |
> Date: Tue, 02 Feb 2021 18:29:15 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: emacs-devel@gnu.org
>
> > From: Yuan Fu <casouri@gmail.com>
> > Date: Mon, 1 Feb 2021 18:00:18 -0500
> > Cc: emacs-devel <emacs-devel@gnu.org>
> >
> > This code inserts a mini table
> >
> > | looooong |
> > | world |
> >
> > And tries to aligns it to
> >
> > | looooong |
> > | world |
> >
> > You will notice there are extra white space on the right of the cells, and
> > the table actually looks like this:
> >
> > | loooooong |
> > | world |
> >
> > That’s because window-text-pixel-size returned a width that’s larger than
> > the true with of the cells. If you enlarge the line-prefix, the extra space
> > grows.
>
> Hmm... this sounds like some bug in window-text-pixel-size. Let me
> take a closer look.
It turned out the function wasn't designed to handle text that spans
less than a single screen line.
Does the patch below fix your problems?
--- src/xdisp.c~0 2020-04-15 14:22:25.000000000 +0300
+++ src/xdisp.c 2021-02-03 16:20:03.222230600 +0200
@@ -10428,8 +10428,22 @@ include the height of both, if present,
same directionality. */
it.bidi_p = false;
+ /* Start at the beginning of the line containing FROM. Otherwise
+ IT.current_x will be incorrect. */
+ reseat_at_previous_visible_line_start (&it);
+ it.current_x = it.hpos = 0;
+ if (IT_CHARPOS (it) != start)
+ move_it_to (&it, start, -1, -1, -1, MOVE_TO_POS);
+
+ /* Now move to TO. */
+ int start_x = it.current_x;
int move_op = MOVE_TO_POS | MOVE_TO_Y;
int to_x = -1;
+ it.current_y = 0;
+ /* If FROM is on a newline, pretend that we start at the beginning
+ of the next line. */
+ if (FETCH_BYTE (start) == '\n')
+ it.current_x = 0;
if (!NILP (x_limit))
{
it.last_visible_x = max_x;
@@ -10472,6 +10486,11 @@ include the height of both, if present,
x = max_x;
}
+ /* If text spans more than one screen line, we don't need to adjust
+ the x-span for start_x. */
+ if (it.current_y > 0)
+ start_x = 0;
+
/* Subtract height of header-line which was counted automatically by
start_display. */
y = it.current_y + it.max_ascent + it.max_descent
@@ -10500,7 +10519,7 @@ include the height of both, if present,
if (old_b)
set_buffer_internal (old_b);
- return Fcons (make_fixnum (x), make_fixnum (y));
+ return Fcons (make_fixnum (x - start_x), make_fixnum (y));
}
/***********************************************************************
- Re: Add a function that returns pixel distance between points?, Yuan Fu, 2021/02/01
- Re: Add a function that returns pixel distance between points?, Eli Zaretskii, 2021/02/01
- Re: Add a function that returns pixel distance between points?, Yuan Fu, 2021/02/01
- Re: Add a function that returns pixel distance between points?, Eli Zaretskii, 2021/02/02
- Re: Add a function that returns pixel distance between points?,
Eli Zaretskii <=
- Re: Add a function that returns pixel distance between points?, Yuan Fu, 2021/02/03
- Re: Add a function that returns pixel distance between points?, Eli Zaretskii, 2021/02/04
- Re: Add a function that returns pixel distance between points?, martin rudalics, 2021/02/05
- Re: Add a function that returns pixel distance between points?, Eli Zaretskii, 2021/02/05
- Re: Add a function that returns pixel distance between points?, martin rudalics, 2021/02/05