Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8123396

Exception while rendering certain bengali characters/words in label

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 8
    • 8
    • javafx

      The following word in Bengali font is throwing exception while rendering in Text Field

      যান, গাড়ি, ট্যাক্সি, বাস, লরি, ভেন, এমম্বুলেন্স, রেলগাড়ি, সাইকেল, মোটর সাইকেল, অটো রিকশ, বোট, জাহাজ, বিমান চলো গাড়ি ( ট্যাক্সি ) নিয়ে স্টেশনে যাই । এখানে গাড়ি রাখবেন না, এটি ব্যক্তিগত জমী ।

      Code

      package banglatestfont;

      import java.io.File;
      import java.io.FileNotFoundException;
      import java.net.MalformedURLException;
      import java.util.Scanner;
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.StackPane;
      import javafx.scene.text.Font;
      import javafx.scene.text.Text;
      import javafx.stage.Stage;

      public class BanglaTestFont extends Application {

          @Override
          public void start(Stage primaryStage) throws MalformedURLException {
              //Text text = new Text();
              Label label = new Label();
              File file = new File("data.txt");
              StringBuffer sb = new StringBuffer();
              try {
                  Scanner scanner = new Scanner(file,"UTF-8");
                  while (scanner.hasNextLine()) {
                      String line = scanner.nextLine();
                      sb = sb.append(line);
                  }
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              }
              //text.setText(sb.toString());
              
              Font font = Font.loadFont(new File("bangla.ttf").toURL().toExternalForm(), 18);
              //text.setFont(font);
              //label.setWrapText(true);
              label.setStyle("-fx-wrap-text: true;-fx-font-size:18;");
              /*
               * Comment the following stylesheet assignement for
               * displaying the characters properly
               * JavaFx JIRA Issue - RT-31074
               *
               */
              //label.setStyle("-fx-font-size:18;");
              label.setFont(font);
              
              label.setText(sb.toString());
              StackPane root = new StackPane();
              //root.getChildren().add(text);
              root.getChildren().add(label);
              Scene scene = new Scene(root, 300, 250);
              primaryStage.setTitle("Hello World!");
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

      Exception

      Executing com.javafx.main.Main from D:\projects\BanglaFontTest\dist\run1552035427\BanglaFontTest.jar using platform C:\Program Files\Java\jdk1.8.0/bin/java
      Exception in Application start method
      java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:491)
      at com.javafx.main.Main.launchApp(Main.java:642)
      at com.javafx.main.Main.main(Main.java:805)
      Caused by: java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:867)
      at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
      at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
      at java.lang.Thread.run(Thread.java:724)
      Caused by: java.lang.ArrayIndexOutOfBoundsException: 8
      at com.sun.javafx.text.TextRun.getCharOffset(TextRun.java:538)
      at com.sun.javafx.text.TextRun.getWrapIndex(TextRun.java:274)
      at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:997)
      at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:199)
      at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:222)
      at javafx.scene.text.Text.getLogicalBounds(Text.java:388)
      at javafx.scene.text.Text.impl_computeLayoutBounds(Text.java:1159)
      at javafx.scene.Node$15.computeBounds(Node.java:3114)
      at javafx.scene.Node$LazyBoundsProperty.get(Node.java:8749)
      at javafx.scene.Node$LazyBoundsProperty.get(Node.java:8719)
      at javafx.scene.Node.getLayoutBounds(Node.java:3129)
      at com.sun.javafx.scene.control.skin.Utils.computeTextHeight(Utils.java:118)
      at com.sun.javafx.scene.control.skin.LabeledSkinBase.computePrefHeight(LabeledSkinBase.java:776)
      at javafx.scene.control.Control.computePrefHeight(Control.java:534)
      at javafx.scene.Parent.prefHeight(Parent.java:896)
      at javafx.scene.layout.Region.prefHeight(Region.java:1240)
      at com.sun.javafx.scene.control.skin.LabeledSkinBase.computeMaxHeight(LabeledSkinBase.java:799)
      at javafx.scene.control.Control.computeMaxHeight(Control.java:514)
      at javafx.scene.layout.Region.maxHeight(Region.java:1274)
      at javafx.scene.layout.Region.boundedNodeSizeWithBias(Region.java:1663)
      at javafx.scene.layout.Region.layoutInArea(Region.java:2035)
      at javafx.scene.layout.Region.layoutInArea(Region.java:1964)
      at javafx.scene.layout.Region.layoutInArea(Region.java:1905)
      at javafx.scene.layout.StackPane.layoutChildren(StackPane.java:366)
      at javafx.scene.Parent.layout(Parent.java:1032)
      at javafx.scene.Scene.layoutDirtyRoots(Scene.java:615)
      at javafx.scene.Scene.doLayoutPass(Scene.java:586)
      at javafx.scene.Scene.preferredSize(Scene.java:1623)
      at javafx.scene.Scene.impl_preferredSize(Scene.java:1650)
      at javafx.stage.Window$9.invalidated(Window.java:730)
      at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
      at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143)
      at javafx.stage.Window.setShowing(Window.java:796)
      at javafx.stage.Window.show(Window.java:811)
      at javafx.stage.Stage.show(Stage.java:243)
      at banglatestfont.BanglaTestFont.start(BanglaTestFont.java:54)
      at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:810)
      at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:273)
      at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:239)
      at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:236)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:236)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:101)
      ... 1 more
      Java Result: 1

            fheidric Felipe Heidrich (Inactive)
            nghoshjfx Neil Ghosh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: