Roboto 无法正确显示阿拉伯语
Roboto does not display correctly with the Arabic language
我在使用 Roboto 字体时遇到问题,其中阿拉伯语显示不正确,我还没有准备好这些字体,但我认为它不支持阿拉伯语 unicode。
我的项目处理 material swing 主题,因此我不会更改字体以支持阿拉伯语,所以我认为加载主题时我会检查键盘布局以及该语言是否可用机器人不支持然后将字体更改为加载,这是我能找到的唯一解决方案,但该解决方案不适用于没有键盘的设备。
现在我想问你两个问题:
- 是否可以在那里找到支持阿拉伯语和该沿袭语言的 roboto 字体?
- 如果我需要更改字体以获得支持,有没有比我更好的解决方案?
--------- 将字体加载到 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);
问题渲染是
enter image description here
'Roboto' 归 Google 所有...它不支持阿拉伯语...Google 使用名为 'noto font' 的备用字体,其中 'roboto' 不受支持...
我在使用 Roboto 字体时遇到问题,其中阿拉伯语显示不正确,我还没有准备好这些字体,但我认为它不支持阿拉伯语 unicode。
我的项目处理 material swing 主题,因此我不会更改字体以支持阿拉伯语,所以我认为加载主题时我会检查键盘布局以及该语言是否可用机器人不支持然后将字体更改为加载,这是我能找到的唯一解决方案,但该解决方案不适用于没有键盘的设备。
现在我想问你两个问题:
- 是否可以在那里找到支持阿拉伯语和该沿袭语言的 roboto 字体?
- 如果我需要更改字体以获得支持,有没有比我更好的解决方案?
--------- 将字体加载到 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);
问题渲染是 enter image description here
'Roboto' 归 Google 所有...它不支持阿拉伯语...Google 使用名为 'noto font' 的备用字体,其中 'roboto' 不受支持...