unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Add a function that returns pixel distance between points?
@ 2021-01-30 20:47 Yuan Fu
  2021-01-31  3:31 ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Yuan Fu @ 2021-01-30 20:47 UTC (permalink / raw)
  To: emacs-devel\@gnu.org

For aligning text according to their display size, I need to calculate the width of some text. Currently I’m using window-text-pixel-size, but it has some problem: if the text I’m measuring has line-prefix or wrap-prefix, the size returned will include the width of the prefix. So if the prefix is 14 pixels wide and the text is 7 pixels wide, the returned value is 21 instead of 7. Line number width is sometimes included in the result and sometimes not.

There is also posn-at-point but that requires the point to be visible in the window. My alignment function wants to run in jit-lock so point is not always visible, so I can’t use posn-at-point.


Yuan


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-30 20:47 Add a function that returns pixel distance between points? Yuan Fu
@ 2021-01-31  3:31 ` Eli Zaretskii
  2021-01-31  5:17   ` Yuan Fu
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-01-31  3:31 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 30 Jan 2021 15:47:38 -0500
> 
> For aligning text according to their display size, I need to calculate the width of some text. Currently I’m using window-text-pixel-size, but it has some problem: if the text I’m measuring has line-prefix or wrap-prefix, the size returned will include the width of the prefix. So if the prefix is 14 pixels wide and the text is 7 pixels wide, the returned value is 21 instead of 7. Line number width is sometimes included in the result and sometimes not.
> 
> There is also posn-at-point but that requires the point to be visible in the window. My alignment function wants to run in jit-lock so point is not always visible, so I can’t use posn-at-point.

Please explain what you mean by "align text according to display
size".  It isn't clear what you want to accomplish, and therefore the
full set of requirements and restrictions is not evident, which makes
it hard to provide useful advice.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-31  3:31 ` Eli Zaretskii
@ 2021-01-31  5:17   ` Yuan Fu
  2021-01-31  5:52     ` Ihor Radchenko
  2021-01-31 15:24     ` Eli Zaretskii
  0 siblings, 2 replies; 18+ messages in thread
From: Yuan Fu @ 2021-01-31  5:17 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

>> For aligning text according to their display size, I need to calculate the width of some text. Currently I’m using window-text-pixel-size, but it has some problem: if the text I’m measuring has line-prefix or wrap-prefix, the size returned will include the width of the prefix. So if the prefix is 14 pixels wide and the text is 7 pixels wide, the returned value is 21 instead of 7. Line number width is sometimes included in the result and sometimes not.
>> 
>> There is also posn-at-point but that requires the point to be visible in the window. My alignment function wants to run in jit-lock so point is not always visible, so I can’t use posn-at-point.
> 
> Please explain what you mean by "align text according to display
> size".  It isn't clear what you want to accomplish, and therefore the
> full set of requirements and restrictions is not evident, which makes
> it hard to provide useful advice.

Sorry for that. I want to align text-based tables by pixel size, as in:

| header | header | header |
| 1      | 1      | 8      |
| 2      | 6      | 3      |

When the text is displayed in variable-pitch font, the bars aren’t aligned. I’m using display property (space :align-to) to align those bars. To know with pixel position to align to, I need to calculate each column’s pixel width, and met the difficulties mentioned earlier.

Yuan


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-31  5:17   ` Yuan Fu
@ 2021-01-31  5:52     ` Ihor Radchenko
  2021-01-31 19:42       ` Yuan Fu
  2021-01-31 15:24     ` Eli Zaretskii
  1 sibling, 1 reply; 18+ messages in thread
From: Ihor Radchenko @ 2021-01-31  5:52 UTC (permalink / raw)
  To: Yuan Fu, Eli Zaretskii; +Cc: emacs-devel

Yuan Fu <casouri@gmail.com> writes:

> When the text is displayed in variable-pitch font, the bars aren’t aligned. I’m using display property (space :align-to) to align those bars. To know with pixel position to align to, I need to calculate each column’s pixel width, and met the difficulties mentioned earlier.

You can do it in temp buffer with line numbers and wrap prefix disabled.
Something like

(defun string-display-pixel-width (string &optional mode)
  "Calculate pixel width of STRING.
Optional MODE specifies major mode used for display."
  (with-temp-buffer
    (with-silent-modifications
      (setf (buffer-string) string))
    (when (fboundp mode)
      (funcall mode)
      (font-lock-fontify-buffer))
    (let (wrap-prefix display-line-numbers)
      (if (get-buffer-window (current-buffer))
	  (car (window-text-pixel-size nil (line-beginning-position) (point)))
        (set-window-buffer nil (current-buffer))
        (car (window-text-pixel-size nil (line-beginning-position) (point)))))))

Best,
Ihor



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-31  5:17   ` Yuan Fu
  2021-01-31  5:52     ` Ihor Radchenko
@ 2021-01-31 15:24     ` Eli Zaretskii
  2021-01-31 19:41       ` Yuan Fu
  1 sibling, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-01-31 15:24 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 31 Jan 2021 00:17:58 -0500
> Cc: emacs-devel@gnu.org
> 
> I want to align text-based tables by pixel size, as in:
> 
> | header | header | header |
> | 1      | 1      | 8      |
> | 2      | 6      | 3      |
> 
> When the text is displayed in variable-pitch font, the bars aren’t aligned. I’m using display property (space :align-to) to align those bars. To know with pixel position to align to, I need to calculate each column’s pixel width, and met the difficulties mentioned earlier.

So the columns in your case have width that changes dynamically?  That
is, if I type enough characters into a cell that the current width is
no longer sufficient, the width of the cell's column will be
increased?

Also, I don't think I understand why it is a problem for you that
posn-at-point requires point to be visible -- are you generating the
table in a buffer that is not displayed, or in a portion of a buffer
that is not visible?  Or is there some other reason why you have
problems with this requirement of posn-at-point?

Finally, I'm not sure why the behavior of window-text-pixel-size is a
problem: if you use :align-to with pixel units (as opposed to column
units), then you should _want_ it to account for stuff like
line-prefix, no?



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-31 15:24     ` Eli Zaretskii
@ 2021-01-31 19:41       ` Yuan Fu
  2021-01-31 20:13         ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Yuan Fu @ 2021-01-31 19:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel



> On Jan 31, 2021, at 10:24 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sun, 31 Jan 2021 00:17:58 -0500
>> Cc: emacs-devel@gnu.org
>> 
>> I want to align text-based tables by pixel size, as in:
>> 
>> | header | header | header |
>> | 1      | 1      | 8      |
>> | 2      | 6      | 3      |
>> 
>> When the text is displayed in variable-pitch font, the bars aren’t aligned. I’m using display property (space :align-to) to align those bars. To know with pixel position to align to, I need to calculate each column’s pixel width, and met the difficulties mentioned earlier.
> 
> So the columns in your case have width that changes dynamically?  That
> is, if I type enough characters into a cell that the current width is
> no longer sufficient, the width of the cell's column will be
> increased?
> 

Yes, naturally you want to adapt the alignment while the user is editing.

> Also, I don't think I understand why it is a problem for you that
> posn-at-point requires point to be visible -- are you generating the
> table in a buffer that is not displayed, or in a portion of a buffer
> that is not visible?  Or is there some other reason why you have
> problems with this requirement of posn-at-point?

Using posn-at-point would be too complicated: Table might by partially visible, I need to make sure the alignment function is immediately called when an unaligned table is displayed in the window, etc. Comparing to that, adding my alignment function into jit-lock hooks is much simpler and cleaner.

> 
> Finally, I'm not sure why the behavior of window-text-pixel-size is a
> problem: if you use :align-to with pixel units (as opposed to column
> units), then you should _want_ it to account for stuff like
> line-prefix, no?

Yes, value given to :align-to needs to account for line-prefix. But when I want to calculate the pixel width of a column, I don’t want to include the prefix: that makes the returned value larger than the actually width of the column (because the line-prefix width is added to it).

Yuan




^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-31  5:52     ` Ihor Radchenko
@ 2021-01-31 19:42       ` Yuan Fu
  0 siblings, 0 replies; 18+ messages in thread
From: Yuan Fu @ 2021-01-31 19:42 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Eli Zaretskii, emacs-devel



> On Jan 31, 2021, at 12:52 AM, Ihor Radchenko <yantar92@gmail.com> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> When the text is displayed in variable-pitch font, the bars aren’t aligned. I’m using display property (space :align-to) to align those bars. To know with pixel position to align to, I need to calculate each column’s pixel width, and met the difficulties mentioned earlier.
> 
> You can do it in temp buffer with line numbers and wrap prefix disabled.
> Something like
> 
> (defun string-display-pixel-width (string &optional mode)
>  "Calculate pixel width of STRING.
> Optional MODE specifies major mode used for display."
>  (with-temp-buffer
>    (with-silent-modifications
>      (setf (buffer-string) string))
>    (when (fboundp mode)
>      (funcall mode)
>      (font-lock-fontify-buffer))
>    (let (wrap-prefix display-line-numbers)
>      (if (get-buffer-window (current-buffer))
> 	  (car (window-text-pixel-size nil (line-beginning-position) (point)))
>        (set-window-buffer nil (current-buffer))
>        (car (window-text-pixel-size nil (line-beginning-position) (point)))))))
> 
> Best,
> Ihor

Thanks, I’ll try that and see if it is fast enough for my use :-)

Yuan


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-31 19:41       ` Yuan Fu
@ 2021-01-31 20:13         ` Eli Zaretskii
  2021-02-01 14:16           ` Yuan Fu
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-01-31 20:13 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 31 Jan 2021 14:41:52 -0500
> Cc: emacs-devel@gnu.org
> 
> > Finally, I'm not sure why the behavior of window-text-pixel-size is a
> > problem: if you use :align-to with pixel units (as opposed to column
> > units), then you should _want_ it to account for stuff like
> > line-prefix, no?
> 
> Yes, value given to :align-to needs to account for line-prefix. But when I want to calculate the pixel width of a column, I don’t want to include the prefix: that makes the returned value larger than the actually width of the column (because the line-prefix width is added to it).

But the pixel coordinate to which you need to align also needs to be
increased due to line-prefix, doesn't it?

IOW, can you show a test case where using window-text-pixel-size
returns incorrect results for :align-to due to line-prefix?



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-01-31 20:13         ` Eli Zaretskii
@ 2021-02-01 14:16           ` Yuan Fu
  2021-02-01 18:22             ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Yuan Fu @ 2021-02-01 14:16 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel\@gnu.org



> On Jan 31, 2021, at 3:13 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sun, 31 Jan 2021 14:41:52 -0500
>> Cc: emacs-devel@gnu.org
>> 
>>> Finally, I'm not sure why the behavior of window-text-pixel-size is a
>>> problem: if you use :align-to with pixel units (as opposed to column
>>> units), then you should _want_ it to account for stuff like
>>> line-prefix, no?
>> 
>> Yes, value given to :align-to needs to account for line-prefix. But when I want to calculate the pixel width of a column, I don’t want to include the prefix: that makes the returned value larger than the actually width of the column (because the line-prefix width is added to it).
> 
> But the pixel coordinate to which you need to align also needs to be
> increased due to line-prefix, doesn't it?
> 
> IOW, can you show a test case where using window-text-pixel-size
> returns incorrect results for :align-to due to line-prefix?

Here is an example:

(let ((width))
  (insert "woome")
  (setq width (car (window-text-pixel-size
                    nil (line-beginning-position) (point))))
  (put-text-property (line-beginning-position) (point)
                     'line-prefix "   ")
  (message "true width: %d returned width: %d"
           width (car (window-text-pixel-size
                       nil (line-beginning-position) (point)))))

Run it in an empty buffer and it will print the expected width and returned width. In the snippet I’m trying to measure the width of the text.

Yuan


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-01 14:16           ` Yuan Fu
@ 2021-02-01 18:22             ` Eli Zaretskii
  2021-02-01 23:00               ` Yuan Fu
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-02-01 18:22 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Mon, 1 Feb 2021 09:16:52 -0500
> Cc: "emacs-devel\\@gnu.org" <emacs-devel@gnu.org>
> 
> > IOW, can you show a test case where using window-text-pixel-size
> > returns incorrect results for :align-to due to line-prefix?
> 
> Here is an example:
> 
> (let ((width))
>   (insert "woome")
>   (setq width (car (window-text-pixel-size
>                     nil (line-beginning-position) (point))))
>   (put-text-property (line-beginning-position) (point)
>                      'line-prefix "   ")
>   (message "true width: %d returned width: %d"
>            width (car (window-text-pixel-size
>                        nil (line-beginning-position) (point)))))
> 
> Run it in an empty buffer and it will print the expected width and returned width. In the snippet I’m trying to measure the width of the text.

This says:

  true width: 40 returned width: 64

However, if I use :align-to with the value of 64 pixels, the stretch
of whitespace ends where I'd expect it to end: aligned to right after
"woome".

So I still don't understand the problem you are facing.  Which is why
I asked for an example code which uses :align-to in a way similar to
what you intend to do in your table rendering code, because I wanted
to see a situation where :align-to produces incorrect results when
using the return value of window-text-pixel-size in the presence of
line-prefix.  But the example you show doesn't use :align-to.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-01 18:22             ` Eli Zaretskii
@ 2021-02-01 23:00               ` Yuan Fu
  2021-02-02 16:29                 ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Yuan Fu @ 2021-02-01 23:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel



> On Feb 1, 2021, at 1:22 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Mon, 1 Feb 2021 09:16:52 -0500
>> Cc: "emacs-devel\\@gnu.org" <emacs-devel@gnu.org>
>> 
>>> IOW, can you show a test case where using window-text-pixel-size
>>> returns incorrect results for :align-to due to line-prefix?
>> 
>> Here is an example:
>> 
>> (let ((width))
>>  (insert "woome")
>>  (setq width (car (window-text-pixel-size
>>                    nil (line-beginning-position) (point))))
>>  (put-text-property (line-beginning-position) (point)
>>                     'line-prefix "   ")
>>  (message "true width: %d returned width: %d"
>>           width (car (window-text-pixel-size
>>                       nil (line-beginning-position) (point)))))
>> 
>> Run it in an empty buffer and it will print the expected width and returned width. In the snippet I’m trying to measure the width of the text.
> 
> This says:
> 
>  true width: 40 returned width: 64
> 
> However, if I use :align-to with the value of 64 pixels, the stretch
> of whitespace ends where I'd expect it to end: aligned to right after
> "woome".
> 
> So I still don't understand the problem you are facing.  Which is why
> I asked for an example code which uses :align-to in a way similar to
> what you intend to do in your table rendering code, because I wanted
> to see a situation where :align-to produces incorrect results when
> using the return value of window-text-pixel-size in the presence of
> line-prefix.  But the example you show doesn't use :align-to.

Ah, I see. Here is a demo that should show that.

(let (width-1 width-2 (start (point)))
  (insert (propertize "| loooooong |\n| world |"
                      'line-prefix "     "))
  (goto-char start)
  (search-forward "|")
  (let ((start (point)))
    (search-forward "|")
    (setq width-1 (car (window-text-pixel-size
                        nil (1+ start) (- (point) 2)))))
  (search-forward "|")
  (let ((start (point)))
    (search-forward "|")
    (setq width-2 (car (window-text-pixel-size
                        nil (1+ start) (- (point) 2)))))
  (let ((col-width (+ 2 (max width-1 width-2)))
        cell-start)
    (goto-char start)
    (search-forward "|")
    (setq cell-start (car (window-text-pixel-size
                           nil (line-beginning-position) (point))))
    (search-forward "|")
    (put-text-property (- (point) 2) (1- (point))
                       'display
                       `(space :align-to (,(+ cell-start col-width))))
    (search-forward "|")
    (setq cell-start (car (window-text-pixel-size
                           nil (line-beginning-position) (point))))
    (search-forward "|")
    (put-text-property (- (point) 2) (1- (point))
                       'display
                       `(space :align-to (,(+ cell-start col-width))))))

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.

Yuan


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-01 23:00               ` Yuan Fu
@ 2021-02-02 16:29                 ` Eli Zaretskii
  2021-02-03 15:04                   ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-02-02 16:29 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> 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.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-02 16:29                 ` Eli Zaretskii
@ 2021-02-03 15:04                   ` Eli Zaretskii
  2021-02-03 16:48                     ` Yuan Fu
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-02-03 15:04 UTC (permalink / raw)
  To: casouri; +Cc: emacs-devel

> 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));
 }
 \f
 /***********************************************************************



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-03 15:04                   ` Eli Zaretskii
@ 2021-02-03 16:48                     ` Yuan Fu
  2021-02-04 16:02                       ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Yuan Fu @ 2021-02-03 16:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel



> On Feb 3, 2021, at 10:04 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> 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?

Yes, it worked well. Thanks!

Yuan


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-03 16:48                     ` Yuan Fu
@ 2021-02-04 16:02                       ` Eli Zaretskii
  2021-02-05 10:15                         ` martin rudalics
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-02-04 16:02 UTC (permalink / raw)
  To: Yuan Fu; +Cc: emacs-devel

> From: Yuan Fu <casouri@gmail.com>
> Date: Wed, 3 Feb 2021 11:48:27 -0500
> Cc: emacs-devel@gnu.org
> 
> > 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?
> 
> Yes, it worked well. Thanks!

Thanks, I installed that on the master branch.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-04 16:02                       ` Eli Zaretskii
@ 2021-02-05 10:15                         ` martin rudalics
  2021-02-05 12:25                           ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: martin rudalics @ 2021-02-05 10:15 UTC (permalink / raw)
  To: Eli Zaretskii, Yuan Fu; +Cc: emacs-devel

 > Thanks, I installed that on the master branch.

I haven't been able to investigate this any further but AFAICT it breaks
'window-text-pixel-size' when a header line is present.  To check for an
arbitrary buffer with some text in it do:

(window-text-pixel-size)

(ruler-mode)

(window-text-pixel-size)

Here the values returned by the invocations of 'window-text-pixel-size'
differ although they shouldn't.

martin



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-05 10:15                         ` martin rudalics
@ 2021-02-05 12:25                           ` Eli Zaretskii
  2021-02-05 15:48                             ` martin rudalics
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2021-02-05 12:25 UTC (permalink / raw)
  To: martin rudalics; +Cc: casouri, emacs-devel

> Cc: emacs-devel@gnu.org
> From: martin rudalics <rudalics@gmx.at>
> Date: Fri, 5 Feb 2021 11:15:29 +0100
> 
>  > Thanks, I installed that on the master branch.
> 
> I haven't been able to investigate this any further but AFAICT it breaks
> 'window-text-pixel-size' when a header line is present.  To check for an
> arbitrary buffer with some text in it do:
> 
> (window-text-pixel-size)
> 
> (ruler-mode)
> 
> (window-text-pixel-size)
> 
> Here the values returned by the invocations of 'window-text-pixel-size'
> differ although they shouldn't.

Thanks, should be fixed now.



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Add a function that returns pixel distance between points?
  2021-02-05 12:25                           ` Eli Zaretskii
@ 2021-02-05 15:48                             ` martin rudalics
  0 siblings, 0 replies; 18+ messages in thread
From: martin rudalics @ 2021-02-05 15:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: casouri, emacs-devel

> Thanks, should be fixed now.

Confirmed.

Thanks for the fix, martin




^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-02-05 15:48 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-30 20:47 Add a function that returns pixel distance between points? Yuan Fu
2021-01-31  3:31 ` Eli Zaretskii
2021-01-31  5:17   ` Yuan Fu
2021-01-31  5:52     ` Ihor Radchenko
2021-01-31 19:42       ` Yuan Fu
2021-01-31 15:24     ` Eli Zaretskii
2021-01-31 19:41       ` Yuan Fu
2021-01-31 20:13         ` Eli Zaretskii
2021-02-01 14:16           ` Yuan Fu
2021-02-01 18:22             ` Eli Zaretskii
2021-02-01 23:00               ` Yuan Fu
2021-02-02 16:29                 ` Eli Zaretskii
2021-02-03 15:04                   ` Eli Zaretskii
2021-02-03 16:48                     ` Yuan Fu
2021-02-04 16:02                       ` Eli Zaretskii
2021-02-05 10:15                         ` martin rudalics
2021-02-05 12:25                           ` Eli Zaretskii
2021-02-05 15:48                             ` martin rudalics

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).