Subject: bug#41005: problem with rendering Persian text in Emacs 27

From: hossein valizadeh <[email-masked]>
Date: Fri, 5 Jun 2020 17:02:55 +0430

> Please tell which patch was that, and in what Emacs version you tried
> it.  (Please understand that you are generally talking to people some
> of whom don't read Arabic or Persian, so the more details you supply
> the less misunderstanding and confusion will follow, and the faster
> this problem will be solved.)

I'm sorry, my English is so bad, at least in writing. That's why it's
hard for me to give a full explanation.
My Emacs version:  27.0.91
I applied this patch:

diff --git a/src/hbfont.c b/src/hbfont.c
index 576c5fe..4b3f64e 100644
--- a/src/hbfont.c
+++ b/src/hbfont.c
@@ -26,6 +26,7 @@
 #include "composite.h"
 #include "font.h"
 #include "dispextern.h"
+#include "buffer.h"

 #ifdef HAVE_NTGUI

@@ -438,7 +439,11 @@ hbfont_shape (Lisp_Object lgstring, Lisp_Object
direction)

   /* If the caller didn't provide a meaningful DIRECTION, let HarfBuzz
      guess it. */
-  if (!NILP (direction))
+  if (!NILP (direction)
+      /* If they bind bidi-display-reordering to nil, the DIRECTION
+        they provide is meaningless, and we should let HarfBuzz guess
+        the real direction.  */
+      && !NILP (BVAR (current_buffer, bidi_display_reordering)))
     {
       hb_direction_t dir = HB_DIRECTION_LTR;
       if (EQ (direction, QL2R))

--------------------------------------------------------------------------------
> I cannot play this on my system, I see a bunch of ads (or what looks
> like ads), and the name of a .mkv file.

video file reuploaded (.mp4 and .ogg):
https://srv-file9.gofile.io/download/cz7P41/out.mp4
https://srv-file4.gofile.io/download/Mwv8k4/out.ogg
--------------------------------------------------------------------------------

This patch solved the problems of eww, newsticker, (and possibly some
other major modes) in displaying Persian/Arabic words. However, if one
of the auto-fill-mode or column-number-mode is enabled, there is still
the same problem in files that use Persian or Arabic characters.
Especially when you want to go back a few characters in a line and add
something to that line.

--------------------------------------------------------------------------------
> Please tell the codepoint of each character you type to reproduce
> the problem and each Emacs command.

For example, if you type in the following sentence:
این نام است که می‌ماند

codepoint:
\u0627\u06cc\u0646 \u0646\u0627\u0645 \u0627\u0633\u062a \u06a9\u0647
\u0645\u06cc\u200c\u0645\u0627\u0646\u062f

Then go back a few characters in the same line and type words randomly. You
will see that the letters in some words are displayed separately. I type a
few words at random, after the word این and before the word نام :‌

این فراموشی را به همه اینکه فرمت مراتب افتتاح گرامی گرایش سراسیمه نام است
که می‌ماند

codepoint:
\u0627\u06cc\u0646 \u0641\u0631\u0627\u0645\u0648\u0634\u06cc \u0631\u0627
\u0628\u0647 \u0647\u0645\u0647 \u0627\u06cc\u0646\u06a9\u0647
\u0641\u0631\u0645\u062a \u0645\u0631\u0627\u062a\u0628
\u0627\u0641\u062a\u062a\u0627\u062d \u06af\u0631\u0627\u0645\u06cc
\u06af\u0631\u0627\u06cc\u0634 \u0633\u0631\u0627\u0633\u06cc\u0645\u0647
\u0646\u0627\u0645 \u0627\u0633\u062a \u06a9\u0647
\u0645\u06cc\u200c\u0645\u0627\u0646\u062f

This line should look like this:
http://s12.picofile.com/file/8399190550/correct.png

But if one of the auto-fill-mode or column-number-mode is enabled. it will
be displayed this way:
http://s13.picofile.com/file/8399190584/malformed.png

--------------------------------------------------------------------------------
> Please show a full recipe for reproducing this, starting from
> "emacs -Q", and describing every step to reproduce the result.

All steps are displayed in the video file.

> I'd also greatly appreciate if you specifically point out at which
> parts of the display to look at what differences to pay attention
> to. This is needed to fully understand the problem and analyze its
> root cause(s), given that not all of us can read the Arabic script.

The letters that should normally be connected will be displayed separately:
http://s12.picofile.com/file/8399222618/latest_screenshot.png
--------------------------------------------------------------------------------