Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 4 Mar 2018 00:56:32 +0000 (UTC)
From:      Greg Lewis <glewis@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r463545 - in head/java/openjdk8: . files
Message-ID:  <201803040056.w240uW6D067920@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glewis
Date: Sun Mar  4 00:56:31 2018
New Revision: 463545
URL: https://svnweb.freebsd.org/changeset/ports/463545

Log:
  . Add a FONTCONFIG option which allows scaler to obtain per-family FreeType
    rendering and loading and may noticeably improves font rendering in Java
    appications
  
  PR:		215636
  Submitted by:	Dmitri Goutnik <dg@syrec.org>

Added:
  head/java/openjdk8/files/fontconfig.patch   (contents, props changed)
Modified:
  head/java/openjdk8/Makefile

Modified: head/java/openjdk8/Makefile
==============================================================================
--- head/java/openjdk8/Makefile	Sat Mar  3 23:57:50 2018	(r463544)
+++ head/java/openjdk8/Makefile	Sun Mar  4 00:56:31 2018	(r463545)
@@ -234,7 +234,7 @@ CONFIGURE_ARGS+=	--disable-ccache \
 CONFIGURE_SCRIPT=	../../configure
 CONFIGURE_WRKSRC=	${WRKSRC}/common/autoconf
 
-OPTIONS_DEFINE=		ALSA POLICY TZUPDATE X11
+OPTIONS_DEFINE=		ALSA POLICY TZUPDATE X11 FONTCONFIG
 OPTIONS_DEFINE_armv6=	FPUHACK
 OPTIONS_DEFINE_armv7=	FPUHACK
 OPTIONS_DEFAULT=	ALSA POLICY TZUPDATE X11
@@ -264,6 +264,7 @@ X11_MAKE_ENV_OFF=	BUILD_HEADLESS_ONLY=1 \
 			MAKEFLAGS=X_CFLAGS="-I${LOCALBASE}/include"
 X11_MAKE_ENV_ON=	MAKEFLAGS=""
 X11_USE=		XORG=x11,xext,xi,xrender,xt,xtst
+FONTCONFIG_IMPLIES=	X11
 
 JAVAVMS_COMMENT=	OpenJDK${JDK_MAJOR_VERSION}
 
@@ -384,6 +385,9 @@ post-extract:
 post-extract-TEST-on:
 	@${LN} -sf ${WRKDIR}/jtreg/linux/bin ${WRKDIR}/jtreg/
 
+do-patch-FONTCONFIG-on:
+	@${PATCH} -d ${PATCH_WRKSRC} < ${PATCHDIR}/fontconfig.patch
+
 post-patch:
 	@${FIND} ${WRKSRC} -name '*.orig' -delete
 	@${RMDIR} ${WRKSRC}/jdk/src/macosx/classes/java/net \
@@ -396,6 +400,7 @@ post-patch:
 	    -e 's|%%OBJCOPY%%|${OBJCOPY}|' \
 	    ${WRKSRC}/configure \
 	    ${WRKSRC}/common/autoconf/toolchain.m4 \
+	    ${WRKSRC}/jdk/make/lib/Awt2dLibraries.gmk \
 	    ${WRKSRC}/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java \
 	    ${WRKSRC}/jdk/src/share/classes/sun/print/PSPrinterJob.java \
 	    ${WRKSRC}/jdk/src/solaris/classes/sun/nio/fs/BsdFileSystemProvider.java

Added: head/java/openjdk8/files/fontconfig.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/java/openjdk8/files/fontconfig.patch	Sun Mar  4 00:56:31 2018	(r463545)
@@ -0,0 +1,222 @@
+--- jdk/src/share/native/sun/font/freetypeScaler.c.orig	2017-01-20 17:04:07 UTC
++++ jdk/src/share/native/sun/font/freetypeScaler.c
+@@ -38,6 +38,8 @@
+ #include FT_SIZES_H
+ #include FT_OUTLINE_H
+ #include FT_SYNTHESIS_H
++#include FT_LCD_FILTER_H
++#include <fontconfig/fontconfig.h>
+ 
+ #include "fontscaler.h"
+ 
+@@ -693,6 +695,132 @@ static void CopyFTSubpixelVToSubpixel(co
+     }
+ }
+ 
++typedef struct {
++    FT_Render_Mode ftRenderMode;
++    int ftLoadFlags;
++    FT_LcdFilter ftLcdFilter;
++} RenderingProperties;
++
++static FcPattern* matchedPattern(const FcChar8* family, double ptSize) {
++    FcPattern* pattern = FcPatternCreate();
++    if (!pattern)
++        return 0;
++
++    FcPatternAddString(pattern, FC_FAMILY, family);
++    FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
++    FcPatternAddDouble(pattern, FC_SIZE, ptSize);
++
++    FcConfigSubstitute(0, pattern, FcMatchPattern);
++    FcDefaultSubstitute(pattern);
++
++    FcResult res;
++    FcPattern *match = FcFontMatch(0, pattern, &res);
++    FcPatternDestroy(pattern);
++    return (res == FcResultMatch) ? match : NULL;
++}
++
++static void readFontconfig(const FcChar8* family, double ptSize, jint aaType, RenderingProperties* rp) {
++    FcPattern *pattern = matchedPattern(family, ptSize);
++
++    FT_Render_Mode ftRenderMode = FT_RENDER_MODE_NORMAL;
++    int ftLoadFlags = FT_LOAD_DEFAULT;
++    FT_LcdFilter ftLcdFilter = FT_LCD_FILTER_DEFAULT;
++    FcBool fcAntialias = 0;
++    char horizontal = 1;
++
++    // subpixel order
++    if (aaType == TEXT_AA_ON)
++        ftRenderMode = FT_RENDER_MODE_NORMAL;
++    else if (aaType == TEXT_AA_OFF)
++        ftRenderMode = FT_RENDER_MODE_MONO;
++    else {
++        int fcRGBA = FC_RGBA_UNKNOWN;
++        if (pattern)
++            FcPatternGetInteger(pattern, FC_RGBA, 0, &fcRGBA);
++        switch (fcRGBA) {
++        case FC_RGBA_NONE:
++            ftRenderMode = FT_RENDER_MODE_NORMAL;
++            break;
++        case FC_RGBA_RGB:
++        case FC_RGBA_BGR:
++            ftRenderMode = FT_RENDER_MODE_LCD;
++            horizontal = 1;
++            break;
++        case FC_RGBA_VRGB:
++        case FC_RGBA_VBGR:
++            ftRenderMode = FT_RENDER_MODE_LCD_V;
++            horizontal = 0;
++            break;
++        default:
++            ftRenderMode = FT_RENDER_MODE_NORMAL;
++            break;
++        }
++    }
++
++    // loading mode
++    if (aaType == TEXT_AA_OFF)
++        ftLoadFlags |= FT_LOAD_TARGET_MONO;
++    else {
++        int fcHintStyle = FC_HINT_NONE;
++        if (pattern)
++            FcPatternGetInteger(pattern, FC_HINT_STYLE, 0, &fcHintStyle);
++        switch (fcHintStyle) {
++        case FC_HINT_NONE:
++            ftLoadFlags |= FT_LOAD_NO_HINTING;
++            break;
++        case FC_HINT_SLIGHT:
++            ftLoadFlags |= FT_LOAD_TARGET_LIGHT;
++            break;
++        case FC_HINT_MEDIUM:
++            ftLoadFlags |= FT_LOAD_TARGET_NORMAL;
++            break;
++        case FC_HINT_FULL:
++            if (aaType == TEXT_AA_ON)
++                ftLoadFlags |= FT_LOAD_TARGET_NORMAL;
++            else
++                ftLoadFlags |= horizontal ? FT_LOAD_TARGET_LCD : FT_LOAD_TARGET_LCD_V;
++            break;
++        default:
++            ftLoadFlags |= FT_LOAD_TARGET_NORMAL;
++            break;
++        }
++    }
++
++    // autohinting
++    FcBool fcAutohint = 0;
++    if (pattern && FcPatternGetBool(pattern, FC_AUTOHINT, 0, &fcAutohint) == FcResultMatch)
++        if (fcAutohint)
++            ftLoadFlags |= FT_LOAD_FORCE_AUTOHINT;
++
++    // LCD filter
++    int fcLCDFilter = FC_LCD_DEFAULT;
++    if (pattern)
++        FcPatternGetInteger(pattern, FC_LCD_FILTER, 0, &fcLCDFilter);
++    switch (fcLCDFilter) {
++    case FC_LCD_NONE:
++        ftLcdFilter = FT_LCD_FILTER_NONE;
++        break;
++    case FC_LCD_DEFAULT:
++        ftLcdFilter = FT_LCD_FILTER_DEFAULT;
++        break;
++    case FC_LCD_LIGHT:
++        ftLcdFilter = FT_LCD_FILTER_LIGHT;
++        break;
++    case FC_LCD_LEGACY:
++        ftLcdFilter = FT_LCD_FILTER_LEGACY;
++        break;
++    default:
++        ftLcdFilter = FT_LCD_FILTER_DEFAULT;
++        break;
++    }
++
++    if (pattern)
++        FcPatternDestroy(pattern);
++
++    rp->ftRenderMode = ftRenderMode;
++    rp->ftLoadFlags = ftLoadFlags;
++    rp->ftLcdFilter = ftLcdFilter;
++}
+ 
+ /*
+  * Class:     sun_font_FreetypeFontScaler
+@@ -726,32 +850,15 @@ Java_sun_font_FreetypeFontScaler_getGlyp
+         return ptr_to_jlong(getNullGlyphImage());
+     }
+ 
+-    /* if algorithmic styling is required then we do not request bitmap */
+-    if (context->doBold || context->doItalize) {
+-        renderFlags =  FT_LOAD_DEFAULT;
+-    }
+-
+-    /* NB: in case of non identity transform
+-     we might also prefer to disable transform before hinting,
+-     and apply it explicitly after hinting is performed.
+-     Or we can disable hinting. */
+-
+-    /* select appropriate hinting mode */
+-    if (context->aaType == TEXT_AA_OFF) {
+-        target = FT_LOAD_TARGET_MONO;
+-    } else if (context->aaType == TEXT_AA_ON) {
+-        target = FT_LOAD_TARGET_NORMAL;
+-    } else if (context->aaType == TEXT_AA_LCD_HRGB ||
+-               context->aaType == TEXT_AA_LCD_HBGR) {
+-        target = FT_LOAD_TARGET_LCD;
+-    } else {
+-        target = FT_LOAD_TARGET_LCD_V;
+-    }
+-    renderFlags |= target;
++    RenderingProperties renderingProperties;
++    readFontconfig((const FcChar8 *) scalerInfo->face->family_name,
++                   context->ptsz, context->aaType, &renderingProperties);
+ 
+     glyph_index = FT_Get_Char_Index(scalerInfo->face, glyphCode);
+ 
+-    error = FT_Load_Glyph(scalerInfo->face, glyphCode, renderFlags);
++    FT_Library_SetLcdFilter(scalerInfo->library, renderingProperties.ftLcdFilter);
++    error = FT_Load_Glyph(scalerInfo->face, glyphCode, renderingProperties.ftLoadFlags);
++
+     if (error) {
+         //do not destroy scaler yet.
+         //this can be problem of particular context (e.g. with bad transform)
+@@ -770,9 +877,7 @@ Java_sun_font_FreetypeFontScaler_getGlyp
+ 
+     /* generate bitmap if it is not done yet
+      e.g. if algorithmic styling is performed and style was added to outline */
+-    if (ftglyph->format == FT_GLYPH_FORMAT_OUTLINE) {
+-        FT_Render_Glyph(ftglyph, FT_LOAD_TARGET_MODE(target));
+-    }
++    FT_Render_Glyph(ftglyph, renderingProperties.ftRenderMode);
+ 
+     width  = (UInt16) ftglyph->bitmap.width;
+     height = (UInt16) ftglyph->bitmap.rows;
+@@ -1001,11 +1106,14 @@ static FT_Outline* getFTOutline(JNIEnv* 
+         return NULL;
+     }
+ 
+-    renderFlags = FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP;
++    RenderingProperties renderingProperties;
++    readFontconfig((const FcChar8 *) scalerInfo->face->family_name,
++                   context->ptsz, context->aaType, &renderingProperties);
+ 
+     glyph_index = FT_Get_Char_Index(scalerInfo->face, glyphCode);
+ 
+-    error = FT_Load_Glyph(scalerInfo->face, glyphCode, renderFlags);
++    error = FT_Load_Glyph(scalerInfo->face, glyphCode, renderingProperties.ftLoadFlags);
++
+     if (error) {
+         return NULL;
+     }
+--- jdk/make/lib/Awt2dLibraries.gmk.orig	2015-07-18 14:30:01.000000000 -0700
++++ jdk/make/lib/Awt2dLibraries.gmk	2015-07-18 14:30:08.000000000 -0700
+@@ -943,7 +943,7 @@
+     LDFLAGS_SUFFIX_linux := -lawt $(LIBM) $(LIBCXX) -ljava -ljvm -lc, \
+     LDFLAGS_SUFFIX_solaris := -lawt -lawt_headless -lc $(LIBM) $(LIBCXX) -ljava -ljvm, \
+     LDFLAGS_SUFFIX_aix := -lawt -lawt_headless $(LIBM) $(LIBCXX) -ljava -ljvm,\
+-    LDFLAGS_SUFFIX_bsd := -lawt $(LIBM) $(LIBCXX) -ljava -ljvm -lc, \
++    LDFLAGS_SUFFIX_bsd := -L%%LOCALBASE%%/lib -lfontconfig -lawt $(LIBM) $(LIBCXX) -ljava -ljvm -lc, \
+     LDFLAGS_SUFFIX_macosx := -lawt $(LIBM) $(LIBCXX) -undefined dynamic_lookup \
+         -ljava -ljvm, \
+     LDFLAGS_SUFFIX_windows := $(WIN_JAVA_LIB) advapi32.lib user32.lib gdi32.lib \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803040056.w240uW6D067920>