changeset 13696:eeac0c758228

8222690: Better Glyph Images Reviewed-by: serb, psadhukhan, mschoene, rhalade
author prr
date Wed, 15 May 2019 12:44:31 -0700
parents 643871d087e0
children 1f801b99581a
files src/share/classes/sun/font/GlyphList.java src/share/native/sun/font/DrawGlyphList.c src/share/native/sun/font/freetypeScaler.c src/solaris/classes/sun/font/XRGlyphCache.java src/solaris/classes/sun/font/XRTextRenderer.java src/solaris/native/sun/java2d/x11/X11FontScaler_md.c
diffstat 6 files changed, 48 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/font/GlyphList.java	Wed May 22 19:41:59 2019 -0700
+++ b/src/share/classes/sun/font/GlyphList.java	Wed May 15 12:44:31 2019 -0700
@@ -323,6 +323,14 @@
      */
     public void setGlyphIndex(int i) {
         glyphindex = i;
+        if (images[i] == 0L) {
+           metrics[0] = (int)gposx;
+           metrics[1] = (int)gposy;
+           metrics[2] = 0;
+           metrics[3] = 0;
+           metrics[4] = 0;
+           return;
+        }
         float gx =
             StrikeCache.unsafe.getFloat(images[i]+StrikeCache.topLeftXOffset);
         float gy =
@@ -361,6 +369,9 @@
                 graybits = new byte[len];
             }
         }
+        if (images[glyphindex] == 0L) {
+            return graybits;
+        }
         long pixelDataAddress =
             StrikeCache.unsafe.getAddress(images[glyphindex] +
                                           StrikeCache.pixelDataOffset);
@@ -468,6 +479,9 @@
         char gw, gh;
         float gx, gy, gx0, gy0, gx1, gy1;
         for (int i=0; i<len; i++) {
+            if (images[i] == 0L) {
+                continue;
+            }
             gx = StrikeCache.unsafe.getFloat(images[i]+xOffset);
             gy = StrikeCache.unsafe.getFloat(images[i]+yOffset);
             gw = StrikeCache.unsafe.getChar(images[i]+wOffset);
--- a/src/share/native/sun/font/DrawGlyphList.c	Wed May 22 19:41:59 2019 -0700
+++ b/src/share/native/sun/font/DrawGlyphList.c	Wed May 15 12:44:31 2019 -0700
@@ -532,6 +532,12 @@
      */
     if (subPixPos && len > 0) {
         ginfo = (GlyphInfo*)imagePtrs[0];
+        if (ginfo == NULL) {
+            (*env)->ReleasePrimitiveArrayCritical(env, glyphImages,
+                                                  imagePtrs, JNI_ABORT);
+            free(gbv);
+            return (GlyphBlitVector*)NULL;
+        }
         /* rowBytes==width tests if its a B&W or LCD glyph */
         if (ginfo->width == ginfo->rowBytes) {
             subPixPos = JNI_FALSE;
@@ -561,6 +567,12 @@
             jfloat px, py;
 
             ginfo = (GlyphInfo*)imagePtrs[g];
+            if (ginfo == NULL) {
+                (*env)->ReleasePrimitiveArrayCritical(env, glyphImages,
+                                                  imagePtrs, JNI_ABORT);
+                free(gbv);
+                return (GlyphBlitVector*)NULL;
+            }
             gbv->glyphs[g].glyphInfo = ginfo;
             gbv->glyphs[g].pixels = ginfo->image;
             gbv->glyphs[g].width = ginfo->width;
@@ -636,6 +648,12 @@
     } else {
         for (g=0; g<len; g++) {
             ginfo = (GlyphInfo*)imagePtrs[g];
+            if (ginfo == NULL) {
+                (*env)->ReleasePrimitiveArrayCritical(env, glyphImages,
+                                                  imagePtrs, JNI_ABORT);
+                free(gbv);
+                return (GlyphBlitVector*)NULL;
+            }
             gbv->glyphs[g].glyphInfo = ginfo;
             gbv->glyphs[g].pixels = ginfo->image;
             gbv->glyphs[g].width = ginfo->width;
--- a/src/share/native/sun/font/freetypeScaler.c	Wed May 22 19:41:59 2019 -0700
+++ b/src/share/native/sun/font/freetypeScaler.c	Wed May 15 12:44:31 2019 -0700
@@ -622,16 +622,17 @@
       to avoid unnecesary work with bitmaps. */
 
     GlyphInfo *info;
-    jfloat advance;
+    jfloat advance = 0.0f;
     jlong image;
 
     image = Java_sun_font_FreetypeFontScaler_getGlyphImageNative(
                  env, scaler, font2D, pScalerContext, pScaler, glyphCode);
     info = (GlyphInfo*) jlong_to_ptr(image);
 
-    advance = info->advanceX;
-
-    free(info);
+    if (info != NULL) {
+        advance = info->advanceX;
+        free(info);
+    }
 
     return advance;
 }
--- a/src/solaris/classes/sun/font/XRGlyphCache.java	Wed May 22 19:41:59 2019 -0700
+++ b/src/solaris/classes/sun/font/XRGlyphCache.java	Wed May 15 12:44:31 2019 -0700
@@ -114,6 +114,9 @@
         for (int i = 0; i < glyphList.getNumGlyphs(); i++) {
             XRGlyphCacheEntry glyph;
 
+            if (imgPtrs[i] == 0L) {
+                continue;
+            }
             // Find uncached glyphs and queue them for upload
             if ((glyph = getEntryForPointer(imgPtrs[i])) == null) {
                 glyph = new XRGlyphCacheEntry(imgPtrs[i], glyphList);
--- a/src/solaris/classes/sun/font/XRTextRenderer.java	Wed May 22 19:41:59 2019 -0700
+++ b/src/solaris/classes/sun/font/XRTextRenderer.java	Wed May 15 12:44:31 2019 -0700
@@ -88,6 +88,9 @@
             for (int i = 0; i < gl.getNumGlyphs(); i++) {
                 gl.setGlyphIndex(i);
                 XRGlyphCacheEntry cacheEntry = cachedGlyphs[i];
+                if (cacheEntry == null) {
+                    continue;
+                }
 
                 eltList.getGlyphs().addInt(cacheEntry.getGlyphID());
                 int glyphSet = cacheEntry.getGlyphSet();
--- a/src/solaris/native/sun/java2d/x11/X11FontScaler_md.c	Wed May 22 19:41:59 2019 -0700
+++ b/src/solaris/native/sun/java2d/x11/X11FontScaler_md.c	Wed May 15 12:44:31 2019 -0700
@@ -273,6 +273,7 @@
     unsigned int imageSize;
     JNIEnv *env;
 
+
     FONT_AWT_LOCK();
 /*     XTextExtents16(xFont, xChar, 1, &direction, &ascent, &descent, &xcs); */
     XQueryTextExtents16(awt_display,xFont->fid, xChar, 1,
@@ -280,8 +281,11 @@
     width = xcs.rbearing - xcs.lbearing;
     height = xcs.ascent+xcs.descent;
     imageSize = width*height;
-
     glyphInfo = (GlyphInfo*)malloc(sizeof(GlyphInfo)+imageSize);
+    if (glyphInfo == NULL) {
+        AWT_UNLOCK();
+        return (jlong)(uintptr_t)NULL;
+    }
     glyphInfo->cellInfo = NULL;
     glyphInfo->width = width;
     glyphInfo->height = height;