From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Add a function that returns pixel distance between points? Date: Wed, 03 Feb 2021 17:04:54 +0200 Message-ID: <83r1lx42g9.fsf@gnu.org> References: <960DAE7C-A1AF-416A-ACA5-F6674C87A2C9@gmail.com> <837dnt9400.fsf@gnu.org> <1EDD0FA5-025C-4A87-BBA1-7B8944E91A12@gmail.com> <83tuqx6sdz.fsf@gnu.org> <83ft2g7tlr.fsf@gnu.org> <51016978-4D2F-45A8-8589-F4562B6DC4A8@gmail.com> <83v9bb6429.fsf@gnu.org> <83bld25t7o.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39096"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: casouri@gmail.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Feb 03 16:07:30 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7Jkf-000A29-Vj for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Feb 2021 16:07:29 +0100 Original-Received: from localhost ([::1]:35708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7Jkf-0007YK-1k for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Feb 2021 10:07:29 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7JiC-00051L-Di for emacs-devel@gnu.org; Wed, 03 Feb 2021 10:04:56 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:44454) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7JiB-0002Q5-57; Wed, 03 Feb 2021 10:04:56 -0500 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1594 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l7Ji9-00043s-JU; Wed, 03 Feb 2021 10:04:54 -0500 In-Reply-To: <83bld25t7o.fsf@gnu.org> (message from Eli Zaretskii on Tue, 02 Feb 2021 18:29:15 +0200) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:263797 Archived-At: > Date: Tue, 02 Feb 2021 18:29:15 +0200 > From: Eli Zaretskii > Cc: emacs-devel@gnu.org > > > From: Yuan Fu > > Date: Mon, 1 Feb 2021 18:00:18 -0500 > > Cc: emacs-devel > > > > 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)); } /***********************************************************************