Beautiful (anti alias) Chinese character

alt text
(source: google.com )

I recently realized that the displayed Chinese characters in my application look pretty ugly.

I thought I should do them with "smoothing." But how can I do this in Java?

For your information, I obviously did not select the font that I want to use in my GUI application. I solely allow the system to decide on its own during startup. I do, however, explicitly configure the locale before showing the GUI.

Locale.setDefault(locale);

The system will always choose

javax.swing.plaf.FontUIResource [family = Tahoma, name = Tahoma, style = plain, size = 11]

regardless of whether I am in English or Chinese.

+3
2

truetype :

private static Font readFont(String name) {
    InputStream in = Fonts.class.getResourceAsStream(name + ".ttf");
    if (in == null) {
        throw new IllegalArgumentException(name);
    }
    try {
        Font retval = Font.createFont(Font.TRUETYPE_FONT, in);
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(retval);
        return retval;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

, Swing CSS. , "font-family", , Font.getName().

:

static {

    Font font = readFont("VeraMono");
    if (font != null) {
        font = font.deriveFont(14f);
    } else {
        throw new IllegalStateException();
    }

    MONOSPACED_TEXT_FONT = font;
    MONOSPACED_TEXT_FONT_STYLE = "font-family: " + font.getName() + "; font-size: 14pt; font-weight: normal;";

}
+1

Source: https://habr.com/ru/post/1750791/


All Articles