I have a problem on Roboto font where the Arabic language is not displayed correctly, on the fonts I'm not very prepared but I think it does not support Arabic unicode.
My project deals with a material theme for swing and therefore I would not change fonts for the Arabic language support so I thought that when the theme is loaded I check for a keyboard layaut and if that language is not supported by a robot then change font to loading, this is the only solution I could find but the solution does not work for devices without a keyboard.
Now I would like to ask you two questions:
---------- Problem Load Font to GraphicsEnvironment ------- I have rewritten fonts of different types and now through a method written by me I go to set the font according to the style and the support of the String but I get this problem when I go to render the look and feel
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
}
setting font on the button
Font font = MaterialFonts.getFont(button.getText(), "Black");
button.setFont (font);
problem rendering is enter image description here
'Roboto' is owned by Google... It doesn't support Arabic ... Google uses a fallback font named 'noto font' where 'roboto' isn't supported...