title: Java: errors in shaping Mongolian glyphs
body: <p>Context: Java 11, JavaFx 11 (where applicable), Linux Mint 19.3, Eclipse 2020.06. Java apps run as desktop applications.</p>
  <p>Background: The Mongolian script is considered &quot;complex&quot; and, to be shaped correctly, requires OpenType tables as <code>isol</code>, <code>init</code>, <code>medi</code>, <code>fina</code>, <code>rlig</code> in the font(s) implementing it.</p>
  <p>I am trying to insert Mongolian strings in Java UI and I am having unexpected results both with Swing and with JavaFX.</p>
  <p>Basically, if a Mongolian string like &quot;ᠪᠠᠢᠨ᠎ᠠ&quot; is inserted in a Swing <code>JLabel</code> or in an Fx <code>Label</code> alone, it is rendered without any shaping (more or less as in &quot;ᠪ ᠠ ᠢ ᠨ ᠠ&quot;), while if a string in another &quot;complex&quot; string is added in the same label, say &quot;अनुच्छेद ᠪᠠᠢᠨ᠎ᠠ&quot; or &quot;ᠪᠠᠢᠨ᠎ᠠ अनुच्छेद&quot;, then it is rendered correctly.</p>
  <p>Furthermore, I noticed that in Swing, either a Devanāgarī or an Arabic string turn on the correct shaping, while in JavaFx a Devanāgarī addition does the job but an Arabic addition does not.</p>
  <p>Of course, I cannot add arbitrary strings just to turn the correct shaping on. Am I forgetting some important initialisation or is the Java shaping tier of the font stack broken? (I suppose it is HarfBuzz, which usually works quite well...).</p>
  <p>Thanks for any suggestion!</p>
  <p>A Swing minimal example, which comments showing which strings are rendered correctly and which are not:</p>
  <pre><code>package com.vistamaresoft.swingtest;
  import javax.swing.BoxLayout;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  public class Main
  {
      private         JFrame      frame;
      private static  Main        window;
  
      public Main()
      {
          frame   = new JFrame();
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.setTitle(&quot;Mongolian Swing Test&quot;);
          frame.setBounds(100, 100, 300, 200);
          //Set up the GUI.
          JPanel      panel       = new JPanel();
          panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
          JLabel      label       = new JLabel(&quot;ᠪᠠᠢᠨ᠎ᠠ&quot;);         // NOT CORRECT
          panel.add(label);
          label                   = new JLabel(&quot;Abc ᠪᠠᠢᠨ᠎ᠠ&quot;);     // NOT CORRECT
          panel.add(label);
          label                   = new JLabel(&quot;ᠪᠠᠢᠨ᠎ᠠ  كتاب &quot;);  // CORRECT
          panel.add(label);
          label                   = new JLabel(&quot;كتاب ᠪᠠᠢᠨ᠎ᠠ&quot;);        // CORRECT
          panel.add(label);
          label                   = new JLabel(&quot;ᠪᠠᠢᠨ᠎ᠠ अनुच्छेद&quot;);        // CORRECT
          panel.add(label);
          label                   = new JLabel(&quot;अनुच्छेद ᠪᠠᠢᠨ᠎ᠠ&quot;);        // CORRECT
          panel.add(label);
          frame.setContentPane(panel);
      }
  
      public static void main(String[] args)
      {
          window = new Main();
          window.frame.setVisible(true);
      }
  }
  </code></pre>
  <p>A JavaFx minimal example. Note that the <code>WebView</code> is not any better than a <code>Label</code> and that copy and pasting a label text into the HTML input field yields the same results:</p>
  <pre><code>package com.vistamaresoft.fxtest;
  
  import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.Label;
  import javafx.scene.layout.VBox;
  import javafx.scene.web.WebView;
  import javafx.stage.Stage;
  
  public class Main
  {
      static final String html    = 
      &quot;&lt;!DOCTYPE HTML PUBLIC \&quot;-//W3C//DTD HTML 4.01//EN\&quot;\n\&quot;http://www.w3.org/TR/html4/strict.dtd\&quot;&gt;\n&quot; + 
      &quot;&lt;html&gt;\n&lt;body&gt;\n&quot; +
      &quot;&lt;p style='font-size: 18pt;'&gt;Sample text: ᠴᠣᠴᠡᠭ᠎ᠠ&lt;/p&gt;&quot; +        // NOT CORRECT!
      &quot;&lt;p style='font-size: 18pt;'&gt;ᠪᠠᠢᠨ᠎ᠠ كتاب &lt;/p&gt;&quot; +                // NOT CORRECT!
      &quot;&lt;p style='font-size: 18pt;'&gt;अनुच्छेद ᠴᠣᠴᠡᠭ᠎ᠠ&lt;/p&gt;&quot; +                // CORRECT!
      &quot;&lt;p&gt;&lt;input type='text' name='title' size='20' maxlength='50' style='font-size: 18pt;' /&gt;&lt;/p&gt;&quot; +
      &quot;&lt;/body&gt;&lt;/html&gt;\n&quot;;
  
      public static void main(String[] args)
      {
          Application.launch(MainApp.class, args);
      }
  
      public static class MainApp extends Application
      {
          @Override public void start(Stage primaryStage) throws Exception
          {
              WebView webView = new WebView();
              webView.getEngine().loadContent(html);
              Label   lab1    = new Label(&quot;ᠪᠠᠢᠨ᠎ᠠ&quot;);      // NOT CORRECT
              lab1.setStyle(&quot;-fx-font-size: 24pt;&quot;);
              Label   lab2    = new Label(&quot;ᠪᠠᠢᠨ᠎ᠠ كتاب&quot;); // NOT CORRECT
              lab2.setStyle(&quot;-fx-font-size: 24pt;&quot;);
              Label   lab3    = new Label(&quot;كتاب ᠪᠠᠢᠨ᠎ᠠ&quot;); // NOT CORRECT
              lab3.setStyle(&quot;-fx-font-size: 24pt;&quot;);
              Label   lab4    = new Label(&quot;ᠪᠠᠢᠨ᠎ᠠ अनुच्छेद&quot;); // CORRECT
              lab4.setStyle(&quot;-fx-font-size: 24pt;&quot;);
              Label   lab5    = new Label(&quot;अनुच्छेद ᠪᠠᠢᠨ᠎ᠠ&quot;); // CORRECT
              lab5.setStyle(&quot;-fx-font-size: 24pt;&quot;);
      
              VBox    vBox    = new VBox(webView, lab1, lab2, lab3, lab4, lab5);
              Scene   scene   = new Scene(vBox, 800, 600);
      
              primaryStage.setTitle(&quot;JavaFX Mongolian Test&quot;);
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }
  
  }
  </code></pre>
  <p>EDIT:</p>
  <p>These issues have been filed as bugs by the Java bug database:</p>
  <ol>
  <li><p>the AWT bug: <a href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8252091" rel="nofollow noreferrer">http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8252091</a></p>
  </li>
  <li><p>the JavaFx bug: <a href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8252220" rel="nofollow noreferrer">http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8252220</a></p>
  </li>
  </ol>