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].



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.

// 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
//   LD_PRELOAD=$(pwd)/ isabelle jedit
// Doing this properly would require patching the JDK, see
// respectively

#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
    load_flags |= FT_LOAD_FORCE_AUTOHINT;

    // 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) {
        // FT_Bool no_stem_darkening = 1;
        // FT_Property_Set(*alibrary, "autofitter", "no-stem-darkening", &no_stem_darkening);

        // FT_UInt hinting_engine = FT_HINTING_ADOBE;
        // FT_Property_Set(*alibrary, "autofitter", "hinting-engine", &hinting_engine);

        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.