From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Keith David Bershatsky Newsgroups: gmane.emacs.bugs Subject: bug#30226: Fixing it->pixel_width / it->current_x when tabs and line numbers. Date: Sun, 28 Jan 2018 11:52:48 -0800 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: blaine.gmane.org 1517169087 30864 195.159.176.226 (28 Jan 2018 19:51:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 28 Jan 2018 19:51:27 +0000 (UTC) Cc: 30226@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jan 28 20:51:22 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efsyu-0007CF-Ul for geb-bug-gnu-emacs@m.gmane.org; Sun, 28 Jan 2018 20:51:13 +0100 Original-Received: from localhost ([::1]:58954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eft0u-0004Ic-2o for geb-bug-gnu-emacs@m.gmane.org; Sun, 28 Jan 2018 14:53:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eft0j-0004Hv-PT for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2018 14:53:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eft0g-0001Ku-Lr for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2018 14:53:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38682) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eft0g-0001Kk-HB for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2018 14:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1eft0g-0000Pq-7a for bug-gnu-emacs@gnu.org; Sun, 28 Jan 2018 14:53:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: Resent-From: Keith David Bershatsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 28 Jan 2018 19:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30226 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30226-submit@debbugs.gnu.org id=B30226.15171691741584 (code B ref 30226); Sun, 28 Jan 2018 19:53:02 +0000 Original-Received: (at 30226) by debbugs.gnu.org; 28 Jan 2018 19:52:54 +0000 Original-Received: from localhost ([127.0.0.1]:46579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eft0X-0000PT-M0 for submit@debbugs.gnu.org; Sun, 28 Jan 2018 14:52:54 -0500 Original-Received: from gateway22.websitewelcome.com ([192.185.47.206]:31846) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eft0V-0000PL-4h for 30226@debbugs.gnu.org; Sun, 28 Jan 2018 14:52:51 -0500 Original-Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 8402D29973 for <30226@debbugs.gnu.org>; Sun, 28 Jan 2018 13:52:50 -0600 (CST) Original-Received: from gator3053.hostgator.com ([50.87.144.69]) by cmsmtp with SMTP id ft0UepafgzzFjft0UeUm1f; Sun, 28 Jan 2018 13:52:50 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lawlist.com ; s=default; h=Content-Type:MIME-Version:Subject:Cc:To:From:Message-ID:Date: Sender:Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=bxsDmaozAd2HYNPVQT2mAW99rB20SLM6PmZiUZr92ds=; b=VgbbFdxZotRCaMdPdJIdKJ2Xk9 jxUIHL58tFjgiLncTGZg4W3pTCSvRSVV/N43vVv8ZWzzNtvNo/+7MJit/Grh4Pq+N/ku4eIZhcmBM /YECdTuQVkywOP5jxF3mqz8tPLSBOJ+xGJ6rawvZuRA1J1bmTDj/9t71kbieUjfPzNf/hh9A5c6nJ rYxLqNiBspD/je/1+a4cJjT+Ai6bqUWR/eMcSHaj7J/L0KETPlYaXXJ/LUqhrE0UHDHQvAKVMxYGT hi2BEgunt2kbuG+Ig6OHEtVqpMiHjP1QG6UAvN4xdPY+K2pykx9BjKePxn+nPtT+9Lk8ayDw8SfBd 89MhDR+w==; Original-Received: from cpe-45-48-239-195.socal.res.rr.com ([45.48.239.195]:50905 helo=server.private) by gator3053.hostgator.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.89_1) (envelope-from ) id 1eft0T-0011vu-FD; Sun, 28 Jan 2018 13:52:49 -0600 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3053.hostgator.com X-AntiAbuse: Original Domain - debbugs.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lawlist.com X-BWhitelist: no X-Source-IP: 45.48.239.195 X-Source-L: No X-Exim-ID: 1eft0T-0011vu-FD X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: cpe-45-48-239-195.socal.res.rr.com (server.private) [45.48.239.195]:50905 X-Source-Auth: lawlist X-Email-Count: 1 X-Source-Cap: bGF3bGlzdDtsYXdsaXN0O2dhdG9yMzA1My5ob3N0Z2F0b3IuY29t X-Local-Domain: yes X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:142619 Archived-At: > Bottom line: to get accurate values of pixel width, you need to > subtract it->current_x value at some position from current_x at the > next glyph position. This is the only reliable way to obtain accurate > pixel width values when using the move_it_* functions. Thank you, Eli, for the detailed explanation regarding what is happening underneath the Emacs hood. The "bottom line" method does not seem to be working in this example to calculate the tab STRETCH because it.current_x of the character that _follows_ the tab STRETCH is wrong when w->hscroll >= 2. In the revised bug-30226 function below: When w->hscroll >= 2, we take the it.current_x of the letter "H" in "Hello-world" (which is ostensibly 84); and, we subtract (it.first_visible_x + it.lnum_pixel_width). This gives us a purported tab STRETCH of 42; however, it should really be 35. A. This is the first (1st) time we call the revised bug-30226 [w->hscroll == 1]: 1. NOTHING it.c (0) w->hscroll (1) it.current_x (0) it.pixel_width (0) 2. TAB CHARACTER it.c (187) w->hscroll (1) it.current_x (0) it.pixel_width (7) 3. TAB STRETCH it.c (9) w->hscroll (1) it.current_x (7) it.pixel_width (49) "Bottom Line" method -- pixel-width of tab STRETCH: 0 4. TAB STRETCH it.c (9) w->hscroll (1) it.current_x (35) it.pixel_width (42) "Bottom Line" method -- pixel-width of tab STRETCH: 42 5. TEXT it.c (72) w->hscroll (1) it.current_x (77) it.pixel_width (7) * * * Row Start End Used oE><\CTZFesm X Y W H V A P ============================================================================== 12 455 467 17 111000110000 0 192 154 16 16 12 12 -1 -1 0 -1 -1 -1 -1 Glyph# Type Pos O W Code C Face LR 0 C -1 0 7 0x000020 29 00 1 C -1 0 7 0x000031 1 29 00 2 C -1 0 7 0x000033 3 29 00 3 C -1 0 7 0x000020 29 00 4 S 455 B 42 0x000000 31 00 5 C 456 B 7 0x000048 H 0 00 6 C 457 B 7 0x000065 e 0 00 7 C 458 B 7 0x00006c l 0 00 8 C 459 B 7 0x00006c l 0 00 9 C 460 B 7 0x00006f o 0 00 10 C 461 B 7 0x00002d - 0 00 11 C 462 B 7 0x000077 w 0 00 12 C 463 B 7 0x00006f o 0 00 13 C 464 B 7 0x000072 r 0 00 14 C 465 B 7 0x00006c l 0 00 15 C 466 B 7 0x000064 d 0 00 16 C 0 0 7 0x000020 0 00 B. This is the second (2nd) time we call the revised bug-30226 [w->hscroll == 2]: 1. NOTHING it.c (0) w->hscroll (2) it.current_x (0) it.pixel_width (0) 2. TAB CHARACTER it.c (187) w->hscroll (2) it.current_x (0) it.pixel_width (7) 3. TAB STRETCH it.c (9) w->hscroll (2) it.current_x (7) it.pixel_width (49) "Bottom Line" method -- pixel-width of tab STRETCH: 42 4. TEXT it.c (72) w->hscroll (2) it.current_x (84) it.pixel_width (7) * * * Row Start End Used oE><\CTZFesm X Y W H V A P ============================================================================== 12 455 467 17 111000110000 0 192 147 16 16 12 12 -1 -1 0 -1 -1 -1 -1 Glyph# Type Pos O W Code C Face LR 0 C -1 0 7 0x000020 29 00 1 C -1 0 7 0x000031 1 29 00 2 C -1 0 7 0x000033 3 29 00 3 C -1 0 7 0x000020 29 00 4 S 455 B 35 0x000000 31 00 5 C 456 B 7 0x000048 H 0 00 6 C 457 B 7 0x000065 e 0 00 7 C 458 B 7 0x00006c l 0 00 8 C 459 B 7 0x00006c l 0 00 9 C 460 B 7 0x00006f o 0 00 10 C 461 B 7 0x00002d - 0 00 11 C 462 B 7 0x000077 w 0 00 12 C 463 B 7 0x00006f o 0 00 13 C 464 B 7 0x000072 r 0 00 14 C 465 B 7 0x00006c l 0 00 15 C 466 B 7 0x000064 d 0 00 16 C 0 0 7 0x000020 0 00 DEFUN ("bug-30226", Fbug_30226, Sbug_30226, 0, 0, 0, doc: /* Debug the pixel-width of a stretch tab. */) (void) { Fscroll_left (make_number (1), Qnil); struct window *w = decode_live_window (selected_window); struct frame *f = XFRAME (w->frame); struct it it; void *itdata = bidi_shelve_cache (); enum move_it_result rc = MOVE_X_REACHED; struct text_pos start_text_position; int count = 1; int previous_character = 0; /* ****************************************************************************** START DISPLAY -- w->start ****************************************************************************** */ /* Begin the journey at w->start. */ SET_TEXT_POS_FROM_MARKER (start_text_position, w->start); start_display (&it, w, start_text_position); struct face *face = FACE_FROM_ID (it.f, it.face_id); struct font *font = face->font; /* ****************************************************************************** GO TO THE BEGINNING OF THE CURRENT LINE. ****************************************************************************** */ /* Place the IT on the current line containing PT. */ int voffset = (WINDOW_HEADER_LINE_HEIGHT (w) > 0 && w->output_cursor.vpos > 0) ? w->output_cursor.vpos - 1 : w->output_cursor.vpos; if (voffset > 0) move_it_by_lines (&it, voffset); /* ****************************************************************************** MOVE IT OVER EACH CHARACTER ON THE CURRENT LINE. ****************************************************************************** */ while (true) { if (ITERATOR_AT_END_OF_LINE_P (&it) || FETCH_BYTE (IT_BYTEPOS (it)) == '\n' || rc == MOVE_POS_MATCH_OR_ZV) break; /* ****************************************************************************** HYPOTHETICAL CALCULATION OF PIXEL-WIDTH ****************************************************************************** */ if (w->hscroll > 0 && previous_character == '\t') fprintf (stderr, "\n\"Bottom Line\" method -- pixel-width of tab STRETCH: %d\n", it.current_x - (it.first_visible_x + it.lnum_pixel_width)); /* ****************************************************************************** DUMP RELEVANT GLYPH INFORMATION ****************************************************************************** */ if (w->hscroll > 0) { int w_hscroll = w->hscroll; fprintf (stderr, "\n%d. %s\n\ it.c (%d)\n\ w->hscroll (%d)\n\ it.current_x (%d)\n\ it.pixel_width (%d)\n", count, (it.c == 0 ? "NOTHING" : it.c == 187 ? "TAB CHARACTER" : it.c == '\t' ? "TAB STRETCH" : "TEXT"), it.c, w_hscroll, it.current_x, it.pixel_width); } /* ****************************************************************************** MOVE IT -- INCREMENT == IT.PIXEL_WIDTH ****************************************************************************** */ previous_character = it.c; rc = move_it_in_display_line_to (&it, ZV, it.current_x + it.pixel_width, MOVE_TO_POS | MOVE_TO_X); count = count + 1; if (rc == MOVE_LINE_CONTINUED) break; if (it.current_x - it.first_visible_x + font->space_width >= window_box_width (w, TEXT_AREA)) break; } /* ****************************************************************************** REDISPLAY AND DUMP_GLPYH_ROW ****************************************************************************** */ redisplay_internal (); fprintf (stderr, "\n"); struct glyph_row *glyph_row = MATRIX_ROW (w->current_matrix, it.vpos); dump_glyph_row (glyph_row, it.vpos, 2); bidi_unshelve_cache (itdata, false); return Qnil; }