Subject: 27.2; ox-ascii breaks TITLE line wrongly when 2 width char is used
From: Shingo Tanaka <[email-masked]>
To: [email-masked]
Date: Sun, 02 May 2021 08:52:13 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

When exporting org-mode document to plain text (either ascii/unicode/utf-8)
with `org-export-dispatch', Emacs translates the document title with
`org-ascii-template--document-title'.  However, when 2 width character is
used, it detects the title line's width wrongly and breaks it even if the
width is not too long.

For example, when the title is "ＡＢＣＤＥＦ" (each character has width of
2), expected title would be like:

                     ━━━━━━━━━━━━━━━
                              ＡＢＣＤＥＦ
                     ━━━━━━━━━━━━━━━

However, the reality is:

                     ━━━━━━━━━━━━━━━
                                 ＡＢＣ
                                 ＤＥＦ
                     ━━━━━━━━━━━━━━━
                     
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)))

---
Shingo Tanaka