Re: [isabelle] Isabelle2019-RC0: Fonts look blurry



Peter Lammich wrote:
> Hi List,
> 
> the font rendering problem on non-highres screens has still not been
> fixed.

As Makarius wrote, this is a consequence of switching to OpenJDK.
Oracle's JDK uses Bitstream's proprietary T2K font engine, whereas
OpenJDK uses FreeType [1], which as far as I can discern simply does
not support the super-agressive kind of hinting that T2K does on
medium DPI displays.

One can coerce Freetype into doing a bit more. I'm attaching a dirty
LD_PRELOAD hack (sorry, Linux only) that can be used to play with some
options. The most promising one is the 'warping' feature [2], which
attempts to align stems such that one of the sides is pixel aligned.
This avoids the particularly bad case of having two gray pixel columns
next to each other for a vertical stem.

Doing this kind of tweaking properly would require patching the JDK,
unfortunately. See the OpenJDK repo [3] respectively the AdoptOpenJDK
mirror [4].

Cheers,

Bertram

P.S. Speaking for myself I expect I will get used to the new, somewhat
blurrier, look of Isabelle/jEdit on my HD display. The projector
scenario (for teaching) seems to be a more serious concern though.

[1] http://mail.openjdk.java.net/pipermail/discuss/2017-November/004621.html
[2] https://www.freetype.org/freetype2/docs/reference/ft2-properties.html#warping
[3] https://hg.openjdk.java.net/jdk/jdk11/file/tip/src/java.desktop/share/native/libfontmanager/freetypeScaler.c
[4] https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.desktop/share/native/libfontmanager/freetypeScaler.c
//
// A nasty hack for tweaking various Freetype settings in Isabelle/jEdit.
//
// Usage:
//   gcc -O -Wall -fPIC -shared -ldl $(pkg-config --cflags --libs freetype2) grr.c -o grr.so
//   LD_PRELOAD=$(pwd)/grr.so isabelle jedit
//
// Doing this properly would require patching the JDK, see
//   https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.desktop/share/native/libfontmanager/freetypeScaler.c
// respectively
//   https://hg.openjdk.java.net/jdk/jdk11/file/tip/src/java.desktop/share/native/libfontmanager/freetypeScaler.c
//

#define _GNU_SOURCE

#include <ft2build.h>
#include <freetype/freetype.h>
#include <freetype/ftmodapi.h>
#include <freetype/ftdriver.h>
#include <dlfcn.h>

static FT_Error (*FT_Load_Glyph_orig)(FT_Face, FT_UInt, FT_Int32);
static FT_Error (*FT_Init_FreeType_orig)(FT_Library *);

static void init() __attribute__((constructor));

static void init()
{
    FT_Load_Glyph_orig = dlsym(RTLD_NEXT, "FT_Load_Glyph");
    FT_Init_FreeType_orig = dlsym(RTLD_NEXT, "FT_Init_FreeType");
}

FT_Error FT_Load_Glyph(
    FT_Face   face,
    FT_UInt   glyph_index,
    FT_Int32  load_flags
)
{
    // https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_load_force_autohint
    load_flags |= FT_LOAD_FORCE_AUTOHINT;

    // https://freetype-py.readthedocs.io/en/latest/ft_load_targets.html
    // load_flags &= ~ FT_LOAD_TARGET_(15);
    // load_flags |= FT_LOAD_TARGET_NORMAL;
    // load_flags |= FT_LOAD_TARGET_LIGHT;

    return FT_Load_Glyph_orig(face, glyph_index, load_flags);
}

FT_Error FT_Init_FreeType(FT_Library *alibrary)
{
    FT_Error result;

    result = FT_Init_FreeType_orig(alibrary);

    if (result == 0) {
        // https://www.freetype.org/freetype2/docs/reference/ft2-properties.html#no-stem-darkening
        // FT_Bool no_stem_darkening = 1;
        // FT_Property_Set(*alibrary, "autofitter", "no-stem-darkening", &no_stem_darkening);

        // https://www.freetype.org/freetype2/docs/reference/ft2-properties.html#hinting-engine
        // FT_UInt hinting_engine = FT_HINTING_ADOBE;
        // FT_Property_Set(*alibrary, "autofitter", "hinting-engine", &hinting_engine);

        // https://www.freetype.org/freetype2/docs/reference/ft2-properties.html#warping
        FT_Bool warping = 1;
        FT_Property_Set(*alibrary, "autofitter", "warping", &warping);
    }

    return result;
}


This archive was generated by a fusion of Pipermail (Mailman edition) and MHonArc.