emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#48148: 27.2; ox-ascii breaks TITLE line wrongly when 2 width char is


From: Nicolas Goaziou
Subject: bug#48148: 27.2; ox-ascii breaks TITLE line wrongly when 2 width char is used
Date: Sun, 02 May 2021 10:23:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Hello,

Eli Zaretskii <eliz@gnu.org> writes:

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

Would you mind giving an example about `window-text-pixel-size' usage in
this situation?

AFAIU, `window-text-pixel-size' returns the size of the window, but
I fail to see how it is relevant here. Note that `text-width' in the
code above is not related to the width of the window, but is a maximum
number of allowed characters on a line.

Thank you!

Regards,
-- 
Nicolas Goaziou





reply via email to

[Prev in Thread] Current Thread [Next in Thread]