我在使用无法正确显示阿拉伯语的 Roboto 字体上遇到问题,在我没有准备好但我认为它不支持阿拉伯语 unicode 的字体上。
我的项目处理swing的材料主题,因此我不会更改阿拉伯语支持的字体,所以我认为加载主题时我会检查键盘布局,如果机器人不支持该语言,则将字体更改为加载,这是我能找到的唯一解决方案,但该解决方案不适用于没有键盘的设备。
现在我想问你两个问题:
- 是否可以在那里找到支持阿拉伯语和该血统语言的机器人字体?
- 如果我需要更改字体以获得支持,有没有比我更好的解决方案?
---------- Problem Load Font to GraphicsEnvironment -------- 我已经重写了不同类型的字体,现在通过我写的方法我去根据样式和支持设置字体的字符串,但是当我去渲染外观时遇到了这个问题
static {
try {
//Noto sans
Font black = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-Black.ttf"));
Font blackItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-BlackItalic.ttf"));
Font bold = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-Bold.ttf"));
Font boldItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-BoldItalic.ttf"));
Font italic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-Italic.ttf"));
Font light = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-Light.ttf"));
Font lightItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-LightItalic.ttf"));
Font medium = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-Medium.ttf"));
Font mediumItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-MediumItalic.ttf"));
Font regular = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-Regular.ttf"));
Font thin = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-Thin.ttf"));
Font thinItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/NotoSans/NotoSans-ThinItalic.ttf"));
//Register font
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
graphicsEnvironment.registerFont(black);
graphicsEnvironment.registerFont(blackItalic);
graphicsEnvironment.registerFont(bold);
graphicsEnvironment.registerFont(boldItalic);
graphicsEnvironment.registerFont(italic);
graphicsEnvironment.registerFont(light);
graphicsEnvironment.registerFont(lightItalic);
graphicsEnvironment.registerFont(medium);
graphicsEnvironment.registerFont(mediumItalic);
graphicsEnvironment.registerFont(regular);
graphicsEnvironment.registerFont(thin);
graphicsEnvironment.registerFont(thinItalic);
black = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-Black.ttf"));
//blackItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/Roboto/Roboto-BlackItalic.ttf"));
bold = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-Bold.ttf"));
boldItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-BoldItalic.ttf"));
italic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-Italic.ttf"));
light = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-Light.ttf"));
lightItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-LightItalic.ttf"));
medium = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-Medium.ttf"));
mediumItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-MediumItalic.ttf"));
regular = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-Regular.ttf"));
thin = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-Thin.ttf"));
thinItalic = Font.createFont(Font.TRUETYPE_FONT, new File("src/main/resources/fonts/Roboto/Roboto-ThinItalic.ttf"));
//register font
graphicsEnvironment.registerFont(black);
//graphicsEnvironment.registerFont(blackItalic);
graphicsEnvironment.registerFont(bold);
graphicsEnvironment.registerFont(boldItalic);
graphicsEnvironment.registerFont(italic);
graphicsEnvironment.registerFont(light);
graphicsEnvironment.registerFont(lightItalic);
graphicsEnvironment.registerFont(medium);
graphicsEnvironment.registerFont(mediumItalic);
graphicsEnvironment.registerFont(regular);
graphicsEnvironment.registerFont(thin);
graphicsEnvironment.registerFont(thinItalic);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (FontFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static Font getFont(String textCompatibily, String tipeFont){
String familyFontRoboto = "Roboto";
String familyFontNotoSans = "Noto Sans";
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
//System.out.println(familyFontRoboto + " " + tipeFont);
for(Font font : graphicsEnvironment.getAllFonts()){
if(font.canDisplayUpTo(textCompatibily) < 0){
if(font.getName().equals(familyFontRoboto + " " + tipeFont)){
System.out.println("Roboto ok");
System.out.println(font.toString());
return font;
}
}
}
for(Font font : graphicsEnvironment.getAllFonts()){
if(font.canDisplayUpTo(textCompatibily) < 0){
if(font.getName().equals(familyFontNotoSans + " " + tipeFont)){
System.out.println("noto sans ok");
return font;
}
}
}
System.out.print("ops");
return graphicsEnvironment.getAllFonts()[0]; // Noto sans dovrebbe coprire tutto, altrimenti questa cosa si allunga
}
在按钮上设置字体
Font font = MaterialFonts.getFont(button.getText(), "Black");
button.setFont (font);
问题渲染是 在此处输入图像描述