public
Last active — forked from trustin/fontfix.patch

OpenJDK 7 font rendering patch for Linux (cd openjdk/jdk; patch -p1 < fontfix.patch)

  • Download Gist
fontfix.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
diff -r 96a023de3ddf make/sun/font/Makefile
--- a/make/sun/font/Makefile Wed Jun 06 18:39:46 2012 -0700
+++ b/make/sun/font/Makefile Fri Jun 08 12:52:01 2012 +0900
@@ -128,7 +128,7 @@
ifeq ($(USING_SYSTEM_FT_LIB), false)
FREETYPE_LIB = $(LIB_LOCATION)/$(LIB_PREFIX)freetype.$(LIBRARY_SUFFIX).6
endif
- OTHER_LDLIBS += -L$(FREETYPE_LIB_PATH) -lfreetype
+ OTHER_LDLIBS += -L$(FREETYPE_LIB_PATH) -lfreetype -lfontconfig
endif
library:: $(FREETYPE_LIB)
diff -r 96a023de3ddf src/share/native/sun/font/freetypeScaler.c
--- a/src/share/native/sun/font/freetypeScaler.c Wed Jun 06 18:39:46 2012 -0700
+++ b/src/share/native/sun/font/freetypeScaler.c Fri Jun 08 12:52:01 2012 +0900
@@ -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"
@@ -692,6 +694,145 @@
}
}
+typedef struct {
+ FT_Render_Mode ftRenderMode;
+ int ftLoadFlags;
+ FT_LcdFilter ftLcdFilter;
+} RenderingProperties;
+
+static FcPattern* matchedPattern(const FcChar8* family, double ptSize) {
+ /*
+ we will create pattern to find our family and size in
+ fontconfig configuration, and then will return it's
+ properties:
+ */
+ FcPattern* fcPattern = 0;
+ fcPattern = FcPatternCreate();
+ FcValue fcValue;
+ fcValue.type = FcTypeString;
+ fcValue.u.s = family;
+ FcPatternAdd(fcPattern, FC_FAMILY, fcValue, FcTrue);
+ FcPatternAddBool(fcPattern, FC_SCALABLE, FcTrue);
+ FcPatternAddDouble(fcPattern, FC_SIZE, ptSize);
+ // TODO FcPatternAddInteger(pattern, FC_WEIGHT, weight_value);
+ // TODO FcPatternAddInteger(pattern, FC_SLANT, slant_value);
+ // TODO FcPatternAddDouble(pattern, FC_PIXEL_SIZE, size_value);
+ // TODO FcPatternAddInteger(pattern, FC_WIDTH, stretch); 100 in most cases
+ FcConfigSubstitute(0, fcPattern, FcMatchPattern);
+ FcConfigSubstitute(0, fcPattern, FcMatchFont);
+ FcDefaultSubstitute(fcPattern);
+ FcResult res;
+
+ FcPattern *pattern = 0;
+ pattern = FcFontMatch(0, fcPattern, &res);
+ FcPatternDestroy(fcPattern);
+ return pattern;
+}
+
+static void readFontconfig(const FcChar8* family, double ptSize, jint aaType, RenderingProperties* rp) {
+
+ FcPattern *pattern = matchedPattern(family, ptSize);
+
+ int ftLoadFalgs = FT_LOAD_DEFAULT;
+ FT_Render_Mode ftRenderMode;
+ FT_LcdFilter ftLcdFilter;
+ char horizontal = 1;
+ FcBool b;
+
+ // subpixel order:
+ if (aaType == TEXT_AA_ON)
+ ftRenderMode = FT_RENDER_MODE_NORMAL;
+ else if (aaType == TEXT_AA_OFF)
+ ftRenderMode = FT_RENDER_MODE_MONO;
+ else if (FcPatternGetBool(pattern, FC_ANTIALIAS, 0, &b) == FcResultMatch)
+ if (b) {
+ int subpixel = FC_RGBA_UNKNOWN;
+ FcPatternGetInteger(pattern, FC_RGBA, 0, &subpixel);
+ if (subpixel == FC_RGBA_UNKNOWN)
+ subpixel = FC_RGBA_NONE;
+ switch (subpixel) {
+ 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:
+ break;
+ }
+ } else {
+ ftRenderMode = FT_RENDER_MODE_NORMAL;
+ }
+
+ // loading mode:
+ if (aaType == TEXT_AA_OFF)
+ ftLoadFalgs |= FT_LOAD_TARGET_MONO;
+ else {
+ int hint_style = FC_HINT_NONE;
+ FcPatternGetInteger(pattern, FC_HINT_STYLE, 0, &hint_style);
+ switch (hint_style) {
+ case FC_HINT_NONE:
+ ftLoadFalgs |= FT_LOAD_NO_HINTING;
+ break;
+ case FC_HINT_SLIGHT:
+ ftLoadFalgs |= FT_LOAD_TARGET_LIGHT;
+ break;
+ case FC_HINT_MEDIUM:
+ ftLoadFalgs |= FT_LOAD_TARGET_NORMAL;
+ break;
+ case FC_HINT_FULL:
+ if (aaType == TEXT_AA_ON)
+ ftLoadFalgs |= FT_LOAD_TARGET_NORMAL;
+ else
+ ftLoadFalgs |= horizontal ? FT_LOAD_TARGET_LCD : FT_LOAD_TARGET_LCD_V;
+ break;
+ default:
+ // what else to use as default?
+ ftLoadFalgs |= FT_LOAD_TARGET_NORMAL;
+ break;
+ }
+ }
+
+ // autohinting:
+ if (FcPatternGetBool(pattern, FC_AUTOHINT, 0, &b) == FcResultMatch)
+ if (b)
+ ftLoadFalgs |= FT_LOAD_FORCE_AUTOHINT;
+
+ // LCD filter:
+ int filter = FC_LCD_DEFAULT;
+ FcPatternGetInteger(pattern, FC_LCD_FILTER, 0, &filter);
+ switch (filter) {
+ 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:
+ // new unknown lcd filter type?! will use default one:
+ ftLcdFilter = FT_LCD_FILTER_DEFAULT;
+ break;
+ }
+
+ FcPatternDestroy(pattern);
+
+ rp->ftRenderMode = ftRenderMode;
+ rp->ftLoadFlags = ftLoadFalgs;
+ rp->ftLcdFilter = ftLcdFilter;
+}
/*
* Class: sun_font_FreetypeFontScaler
@@ -707,7 +848,6 @@
UInt16 width, height;
GlyphInfo *glyphInfo;
int glyph_index;
- int renderFlags = FT_LOAD_RENDER, target;
FT_GlyphSlot ftglyph;
FTScalerContext* context =
@@ -725,32 +865,15 @@
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)
@@ -767,11 +890,7 @@
FT_GlyphSlot_Oblique(ftglyph);
}
- /* 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;
@@ -984,7 +1103,6 @@
static FT_Outline* getFTOutline(JNIEnv* env, jobject font2D,
FTScalerContext *context, FTScalerInfo* scalerInfo,
jint glyphCode, jfloat xpos, jfloat ypos) {
- int renderFlags;
int glyph_index;
FT_Error error;
FT_GlyphSlot ftglyph;
@@ -999,11 +1117,13 @@
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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.