在我的程序中,我正在从 UTF-8 文件中读取 Bangla(印度语)文本并显示在 JavaFx 的文本组件中。虽然显示了字符,但它们的位置不正确。
在这种复杂的脚本语言中,一些元音应该在字母的左右两边环绕,但在某些计算机中,它以错误的方式显示,即首先是元音,然后是字母。
例如包含“拆分元音”ো 的单词显示不正确。 https://bug686225.bugzilla.mozilla.org/attachment.cgi?id=559780
在系统中使用 http://www.tariquemahmud.net/?p=35 修复了它但在 JavaFx 程序中,问题仍然存在。
显示错误
正确的显示
您可以根据上面的屏幕截图在您的计算机上检查以下可执行文件是否正确
http://dl.dropbox.com/u/655237/share/BanglaTest.zip
我正在使用下面的代码
package banglatest;
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.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class BanglaTest extends Application {
@Override
public void start(Stage primaryStage) throws MalformedURLException {
Text text = new Text();
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(), 20);
text.setFont(font);
StackPane root = new StackPane();
root.getChildren().add(text);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
最佳答案
JDK 8 (FX 8) 终于提供了这种支持。 使用相同的 Developer 预览版重新编译并且有效。
关于java - 在 JavaFX 中显示复杂的印度孟加拉语字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13195563/