Subject: Re: bug#33944: 27.0.50; harfbuzz: Noto Sans Mandaic not rendered correctly

From: Eli Zaretskii <[email-masked]>
Date: Tue, 01 Jan 2019 17:28:42 +0200

> From: Benjamin Riefenstahl <[email-masked]>
> Date: Tue, 01 Jan 2019 15:36:40 +0100
> 
> This may be a more general problem, but Noto Sans Mandaic reproduces it
> for me:

You mean, with other fonts that support Arabic shaping the problem
doesn't happen?

> I save this code in a file "reproduce.el" and execute it with "emacs -Q
> -l reproduce.el":
> 
>     (set-fontset-font t '(?\u0840 . ?\u085B) "Noto Sans Mandaic 20")
> 
>     (set-char-table-range
>      composition-function-table '(?\u0840 . ?\u085B)
>      (list ["[\u0840-\u085B]+" 0 arabic-shape-gstring]))
> 
>     (setq bidi-paragraph-direction t)

>From the doc string of bidi-paragraph-direction:

  If this is nil (the default), the direction of each paragraph is
  determined by the first strong directional character of its text.
  The values of ‘right-to-left’ and ‘left-to-right’ override that.
  Any other value is treated as nil.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Did you set it to t on purpose?  If so, can you explain why?

>     (insert "\u0856\u0844\u0845")
> 
> The problem is that the second and third character from the right are
> not combined as they should.  This works in hb-view and it also works,
> if I remove the setting of bidi-paragraph-direction.

What happens if bidi-paragraph-direction is set to one of the valid
values?

> The commit that breaks this is the last one, 48776b7011 "Provide text
> directionality and language to HarfBuzz shaper".  Before that commit it
> works for me.

Can you run Emacs under a debugger and see what value of 'dir' do we
come up with in this snippet from ftfont.c:

  hb_direction_t dir = HB_DIRECTION_INVALID;
  if (EQ (direction, QL2R))
    dir = HB_DIRECTION_LTR;
  else if (EQ (direction, QR2L))
    dir = HB_DIRECTION_RTL;
  /* If the caller didn't provide a meaningful DIRECTION, let HarfBuzz
     guess it.  */
  if (dir != HB_DIRECTION_INVALID)
    hb_buffer_set_direction (hb_buffer, dir);

Do we call hb_buffer_set_direction, and if so, with what value?

Thanks.