emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Shingo Tanaka <shingo.fg8@gmail.com>
Cc: 48148@debbugs.gnu.org
Subject: bug#48148: 27.2; ox-ascii breaks TITLE line wrongly when 2 width char is used
Date: Sun, 02 May 2021 10:03:36 +0300	[thread overview]
Message-ID: <83bl9t8vnb.fsf@gnu.org> (raw)
In-Reply-To: <87h7jm2es2.wl-shingo.fg8@gmail.com> (message from Shingo Tanaka on Sun, 02 May 2021 08:52:13 +0900)

> Date: Sun, 02 May 2021 08:52:13 +0900
> From: Shingo Tanaka <shingo.fg8@gmail.com>
> 
> For example, when the title is "ABCDEF" (each character has width of
> 2), expected title would be like:
> 
>                      ━━━━━━━━━━━━━━━
>                               ABCDEF
>                      ━━━━━━━━━━━━━━━
> 
> However, the reality is:
> 
>                      ━━━━━━━━━━━━━━━
>                                  ABC
>                                  DEF
>                      ━━━━━━━━━━━━━━━
>                      
> This is because it uses `length' to detects the width, which only returns the
> number of characters (6 in this case) but not the actual width displayed (12
> in this case), and it tries to fill the line with that half width.
> `string-width' should be used instead.
> 
> Here is a potential patch.
> 
> --- ox-ascii.el.org	2021-03-26 09:28:44.000000000 +0900
> +++ ox-ascii.el	2021-05-02 08:11:57.657347150 +0900
> @@ -1033,7 +1033,7 @@
>  	     ;; Format TITLE.  It may be filled if it is too wide,
>  	     ;; that is wider than the two thirds of the total width.
>  	     (title-len (min (apply #'max
> -				    (mapcar #'length
> +				    (mapcar #'string-width
>  					    (org-split-string
>  					     (concat title "\n" subtitle) "\n")))
>  			     (/ (* 2 text-width) 3)))

Thanks, but the change you propose will not work reliably on GUI
frames, because the actual width of double-width characters on display
is not necessarily twice the width of a "normal" character.
Especially if this is done in a non-CJK locale, where the default font
is likely to be different from the font used for double-width
characters.

The accurate method of lining up in these cases is to use
window-text-pixel-size instead.  That function will return the exact
width of a string as it will displayed, in pixels, because it uses the
same code as the display engine.





       reply	other threads:[~2021-05-02  7:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87h7jm2es2.wl-shingo.fg8@gmail.com>
2021-05-02  7:03 ` Eli Zaretskii [this message]
2021-05-02  8:23   ` bug#48148: 27.2; ox-ascii breaks TITLE line wrongly when 2 width char is used Nicolas Goaziou
2021-05-02  9:11     ` Eli Zaretskii
2021-05-02 11:33       ` Shingo Tanaka
2021-05-02 12:43         ` Eli Zaretskii
2021-05-02 12:18       ` Nicolas Goaziou
2021-05-02 12:48         ` Eli Zaretskii
2021-05-02 15:56           ` Nicolas Goaziou
2021-05-02 16:11             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83bl9t8vnb.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=48148@debbugs.gnu.org \
    --cc=shingo.fg8@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).