changeset 5257:4f55a53bfabd

RT-32255 [linux only]
author Felipe Heidrich <felipe.heidrich@oracle.com>
date Thu, 03 Oct 2013 09:30:59 -0700
parents 8b1a40fed5c8
children 50b282551554
files modules/graphics/src/main/java/com/sun/javafx/font/pango/FTFontFile.java modules/graphics/src/main/java/com/sun/javafx/font/pango/FTGlyph.java modules/graphics/src/main/java/com/sun/javafx/font/pango/PangoFactory.java modules/graphics/src/main/java/com/sun/javafx/font/pango/PangoGlyphLayout.java modules/graphics/src/main/native-font/freetype.c
diffstat 5 files changed, 47 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/font/pango/FTFontFile.java	Thu Oct 03 10:52:57 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/pango/FTFontFile.java	Thu Oct 03 09:30:59 2013 -0700
@@ -97,13 +97,15 @@
     protected synchronized int[] createGlyphBoundingBox(int gc) {
         int flags = OS.FT_LOAD_NO_SCALE;
         OS.FT_Load_Glyph(face, gc, flags);
+        int[] bbox = new int[4];
         FT_GlyphSlotRec glyphRec = OS.getGlyphSlot(face);
-        FT_Glyph_Metrics gm = glyphRec.metrics;
-        int[] bbox = new int[4];
-        bbox[0] = (int)gm.horiBearingX;
-        bbox[1] = (int)(gm.horiBearingY - gm.height);
-        bbox[2] = (int)(gm.horiBearingX + gm.width);
-        bbox[3] = (int)gm.horiBearingY;
+        if (glyphRec != null && glyphRec.metrics != null) {
+            FT_Glyph_Metrics gm = glyphRec.metrics;
+            bbox[0] = (int)gm.horiBearingX;
+            bbox[1] = (int)(gm.horiBearingY - gm.height);
+            bbox[2] = (int)(gm.horiBearingX + gm.width);
+            bbox[3] = (int)gm.horiBearingY;
+        }
         return bbox;
     }
 
@@ -153,14 +155,16 @@
         }
 
         FT_GlyphSlotRec glyphRec = OS.getGlyphSlot(face);
+        if (glyphRec == null) return;
         FT_Bitmap bitmap = glyphRec.bitmap;
+        if (bitmap == null) return;
         int width = bitmap.width;
         int height = bitmap.rows;
         int pitch = bitmap.pitch;
         byte[] buffer;
         if (width != 0 && height != 0) {
             buffer = OS.getBitmapData(face);
-            if (pitch != width) {
+            if (buffer != null && pitch != width) {
                 /* Common for LCD glyphs */
                 byte[] newBuffer = new byte[width * height];
                 int src = 0, dst = 0;
--- a/modules/graphics/src/main/java/com/sun/javafx/font/pango/FTGlyph.java	Thu Oct 03 10:52:57 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/pango/FTGlyph.java	Thu Oct 03 09:30:59 2013 -0700
@@ -103,13 +103,13 @@
     public int getWidth() {
         init();
         /* Note: In Freetype the width is byte based */
-        return bitmap.width;
+        return bitmap != null ? bitmap.width : 0;
     }
 
     @Override
     public int getHeight() {
         init();
-        return bitmap.rows;
+        return bitmap != null ? bitmap.rows : 0;
     }
 
     @Override
@@ -121,7 +121,7 @@
     @Override
     public int getOriginY() {
         init();
-        return -bitmap_top; /*Inverted coordinates system */
+        return -bitmap_top; /* Inverted coordinates system */
     }
 
     @Override
--- a/modules/graphics/src/main/java/com/sun/javafx/font/pango/PangoFactory.java	Thu Oct 03 10:52:57 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/pango/PangoFactory.java	Thu Oct 03 09:30:59 2013 -0700
@@ -74,7 +74,7 @@
 
     @Override
     public GlyphLayout createGlyphLayout() {
-        /* Implementing a HarfbuzzGlyphLayout would needed in order to support
+        /* Implementing a HarfbuzzGlyphLayout is needed to support
          * font features and non-hinted glyph advances.  */
         return new PangoGlyphLayout();
     }
--- a/modules/graphics/src/main/java/com/sun/javafx/font/pango/PangoGlyphLayout.java	Thu Oct 03 10:52:57 2013 -0700
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/pango/PangoGlyphLayout.java	Thu Oct 03 09:30:59 2013 -0700
@@ -115,36 +115,40 @@
             OS.pango_attr_list_insert(attrList, attr);
         }
         long runs = OS.pango_itemize(context, out, 0, out.position(), attrList, 0);
-        int runsCount = OS.g_list_length(runs);
-        int runStart = start;
-        for (int i = 0; i < runsCount; i++) {
-            long pangoItem = OS.g_list_nth_data(runs, i);
-            PangoGlyphString glyphString = OS.pango_shape(out, pangoItem);
-            OS.pango_item_free(pangoItem);
-            int slot = composite ? getSlot(font, glyphString) : 0;
-            int glyphCount = glyphString.num_glyphs;
-            int[] glyphs = new int[glyphCount];
-            float[] pos = new float[glyphCount*2+2];
-            PangoGlyphInfo info = null;
-            int k = 2;
-            int width = 0;
-            for (int j = 0; j < glyphCount; j++) {
-                info = glyphString.glyphs[j];
-                if (slot != -1) {
-                    glyphs[j] = (slot << 24) | info.glyph;
+        if (runs != 0) {
+            int runsCount = OS.g_list_length(runs);
+            int runStart = start;
+            for (int i = 0; i < runsCount; i++) {
+                long pangoItem = OS.g_list_nth_data(runs, i);
+                PangoGlyphString glyphString = OS.pango_shape(out, pangoItem);
+                OS.pango_item_free(pangoItem);
+                if (glyphString != null) {
+                    int slot = composite ? getSlot(font, glyphString) : 0;
+                    int glyphCount = glyphString.num_glyphs;
+                    int[] glyphs = new int[glyphCount];
+                    float[] pos = new float[glyphCount*2+2];
+                    PangoGlyphInfo info = null;
+                    int k = 2;
+                    int width = 0;
+                    for (int j = 0; j < glyphCount; j++) {
+                        info = glyphString.glyphs[j];
+                        if (slot != -1) {
+                            glyphs[j] = (slot << 24) | info.glyph;
+                        }
+                        if (size != 0) width += info.width;
+                        pos[k] = ((float)width) / OS.PANGO_SCALE;
+                        k += 2;
+                    }
+
+                    int runLength = glyphString.num_chars;
+                    textRun = new TextRun(runStart, runLength, level, true, 0, span, 0, false);
+                    textRun.shape(glyphCount, glyphs, pos, glyphString.log_clusters);
+                    layout.addTextRun(textRun);
+                    runStart += runLength;
                 }
-                if (size != 0) width += info.width;
-                pos[k] = ((float)width) / OS.PANGO_SCALE;
-                k += 2;
             }
-
-            int runLength = glyphString.num_chars;
-            textRun = new TextRun(runStart, runLength, level, true, 0, span, 0, false);
-            textRun.shape(glyphCount, glyphs, pos, glyphString.log_clusters);
-            layout.addTextRun(textRun);
-            runStart += runLength;
+            OS.g_list_free(runs);
         }
-        OS.g_list_free(runs);
         /* pango_attr_list_unref() also frees the attributes it contains */
         OS.pango_attr_list_unref(attrList);
         OS.pango_font_description_free(desc);
--- a/modules/graphics/src/main/native-font/freetype.c	Thu Oct 03 10:52:57 2013 -0700
+++ b/modules/graphics/src/main/native-font/freetype.c	Thu Oct 03 09:30:59 2013 -0700
@@ -378,7 +378,7 @@
 }
 
 static int JFX_Outline_LineToFunc(const FT_Vector*   to,
-                                  void* user)
+                                  void*              user)
 {
     PathData *info =  checkSize(user, 1);
     info->pointTypes[info->numTypes++] = 1;