From ae2f49e8dc610c78e4058e7f2f9d130e52d35336 Mon Sep 17 00:00:00 2001 From: prr Date: Wed, 19 Jun 2019 15:24:42 -0700 Subject: [PATCH] 8225286: Better rendering of native glyphs Reviewed-by: serb, psadhukhan, mschoene, rhalade --- src/share/native/sun/font/freetypeScaler.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/share/native/sun/font/freetypeScaler.c b/src/share/native/sun/font/freetypeScaler.c index 8a7024ceb..eadca4026 100644 --- a/src/share/native/sun/font/freetypeScaler.c +++ b/src/share/native/sun/font/freetypeScaler.c @@ -770,6 +770,13 @@ static void CopyFTSubpixelVToSubpixel(const void* srcImage, int srcRowBytes, } +/* JDK does not use glyph images for fonts with a + * pixel size > 100 (see THRESHOLD in OutlineTextRenderer.java) + * so if the glyph bitmap image dimension is > 1024 pixels, + * something is up. + */ +#define MAX_GLYPH_DIM 1024 + /* * Class: sun_font_FreetypeFontScaler * Method: getGlyphImageNative @@ -846,6 +853,15 @@ Java_sun_font_FreetypeFontScaler_getGlyphImageNative( /* 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_BBox bbox; + int w, h; + FT_Outline_Get_CBox(&(ftglyph->outline), &bbox); + w = (int)((bbox.xMax>>6)-(bbox.xMin>>6)); + h = (int)((bbox.yMax>>6)-(bbox.yMin>>6)); + if (w > MAX_GLYPH_DIM || h > MAX_GLYPH_DIM) { + glyphInfo = getNullGlyphImage(); + return ptr_to_jlong(glyphInfo); + } error = FT_Render_Glyph(ftglyph, FT_LOAD_TARGET_MODE(target)); if (error != 0) { return ptr_to_jlong(getNullGlyphImage()); @@ -854,6 +870,11 @@ Java_sun_font_FreetypeFontScaler_getGlyphImageNative( width = (UInt16) ftglyph->bitmap.width; height = (UInt16) ftglyph->bitmap.rows; + if (width > MAX_GLYPH_DIM || height > MAX_GLYPH_DIM) { + glyphInfo = getNullGlyphImage(); + return ptr_to_jlong(glyphInfo); + } + imageSize = width*height; glyphInfo = (GlyphInfo*) malloc(sizeof(GlyphInfo) + imageSize); -- GitLab