Fonts slightly wider in OpenJDK vs OracleJDK

前端 未结 1 975
粉色の甜心
粉色の甜心 2021-02-13 05:32

I\'m noticing differences in font spacing using OpenJDK compared to OracleJDK. I\'ve narrowed this down to the fonts. They are rendered by OpenJDK ever so slightly wider... Care

相关标签:
1条回答
  • 2021-02-13 05:37

    Further investigation has found sun.font.FontScaler, this uses different underlying fontscaler. This appears partially configurable in sun.font.FontUtilities which checks the system property for -Dsun.java2d.font.scaler=t2k, however setting this makes no difference.

    You're correct in that the underlying font scaler is different between Oracle and OpenJDK - unfortunately however, this is hard coded and not configurable.

    The relevant code is in FontScaler:97:

    if (FontUtilities.isOpenJDK) {
        scalerClass = Class.forName("sun.font.FreetypeFontScaler");
    } else {
        scalerClass = Class.forName("sun.font.T2KFontScaler");
    }
    

    And the isOpenJDK flag? It's set by FontUtilities:125:

    File lucidaFile = new File(jreFontDirName + File.separator + LUCIDA_FILE_NAME);
    isOpenJDK = !lucidaFile.exists();
    

    And that constant:

    static final String LUCIDA_FILE_NAME = "LucidaSansRegular.ttf";
    

    Unless I've missed something in those source files, there's no other configuration flag or any other condition that will change that scaler class being used.

    So the only vaguely sensible way of doing this (I'm excluding horrible classloader / reflection hacks here) is to add that Lucida file in place. Unfortunately though in most scenarios I can think of (assuming you're not distributing the JRE along with the package) this isn't really going to be a viable solution either.

    0 讨论(0)
提交回复
热议问题