8222690: Better Glyph Images
authorprr
Wed, 15 May 2019 12:44:31 -0700
changeset 58615 d5ea3bde1ebe
parent 58614 29624901d8bc
child 58616 be9ef671a1b6
8222690: Better Glyph Images Reviewed-by: serb, psadhukhan, mschoene, rhalade
src/java.desktop/share/classes/sun/font/GlyphList.java
src/java.desktop/share/native/libfontmanager/DrawGlyphList.c
src/java.desktop/share/native/libfontmanager/freetypeScaler.c
src/java.desktop/unix/classes/sun/font/XRGlyphCache.java
src/java.desktop/unix/classes/sun/font/XRTextRenderer.java
src/java.desktop/unix/native/common/java2d/x11/X11FontScaler_md.c
--- a/src/java.desktop/share/classes/sun/font/GlyphList.java	Fri May 03 19:42:28 2019 +0100
+++ b/src/java.desktop/share/classes/sun/font/GlyphList.java	Wed May 15 12:44:31 2019 -0700
@@ -303,6 +303,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 =
@@ -341,6 +349,9 @@
                 graybits = new byte[len];
             }
         }
+        if (images[glyphindex] == 0L) {
+            return graybits;
+        }
         long pixelDataAddress =
             StrikeCache.unsafe.getAddress(images[glyphindex] +
                                           StrikeCache.pixelDataOffset);
@@ -448,6 +459,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/java.desktop/share/native/libfontmanager/DrawGlyphList.c	Fri May 03 19:42:28 2019 +0100
+++ b/src/java.desktop/share/native/libfontmanager/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/java.desktop/share/native/libfontmanager/freetypeScaler.c	Fri May 03 19:42:28 2019 +0100
+++ b/src/java.desktop/share/native/libfontmanager/freetypeScaler.c	Wed May 15 12:44:31 2019 -0700
@@ -635,16 +635,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/java.desktop/unix/classes/sun/font/XRGlyphCache.java	Fri May 03 19:42:28 2019 +0100
+++ b/src/java.desktop/unix/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/java.desktop/unix/classes/sun/font/XRTextRenderer.java	Fri May 03 19:42:28 2019 +0100
+++ b/src/java.desktop/unix/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/java.desktop/unix/native/common/java2d/x11/X11FontScaler_md.c	Fri May 03 19:42:28 2019 +0100
+++ b/src/java.desktop/unix/native/common/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;