changeset 6175:f4c5ad39e637

RT-35510: remove PangoGlyphInfo
author Felipe Heidrich <felipe.heidrich@oracle.com>
date Thu, 23 Jan 2014 11:14:34 -0800
parents 766643c4dc7d
children 094806dabd94
files modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphInfo.java modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphLayout.java modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphString.java modules/graphics/src/main/native-font/pango.c
diffstat 4 files changed, 31 insertions(+), 98 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphInfo.java	Thu Jan 23 10:05:20 2014 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.javafx.font.freetype;
-
-class PangoGlyphInfo {
-    int glyph;
-    /* Inline PangoGlyphGeometry */
-    int width;
-    int x_offset;
-    int y_offset;
-}
--- a/modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphLayout.java	Thu Jan 23 10:05:20 2014 -0800
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphLayout.java	Thu Jan 23 11:14:34 2014 -0800
@@ -136,12 +136,11 @@
                 if (g != null) {
                     int slot = composite ? getSlot(font, g) : 0;
                     for (int i = 0; i < g.num_glyphs; i++) {
-                        PangoGlyphInfo info = g.glyphs[i];
                         if (slot != -1) {
-                            glyphs[gi + i] = (slot << 24) | info.glyph;
+                            glyphs[gi + i] = (slot << 24) | g.glyphs[i];
                         }
                         if (size != 0) {
-                            width += info.width;
+                            width += g.widths[i];
                             pos[2 + ((gi + i) << 1)] = ((float)width) / OSPango.PANGO_SCALE;
                         }
                     }
--- a/modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphString.java	Thu Jan 23 10:05:20 2014 -0800
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/freetype/PangoGlyphString.java	Thu Jan 23 11:14:34 2014 -0800
@@ -33,6 +33,9 @@
     /* pangoItem->analysis->font*/
     long font;
     int num_glyphs;
-    PangoGlyphInfo[] glyphs;
+    /* PangoGlyphInfo->glyph */
+    int[] glyphs;
+    /* PangoGlyphInfo->PangoGlyphGeometry->width */
+    int[] widths;
     int[] log_clusters;
 }
--- a/modules/graphics/src/main/native-font/pango.c	Thu Jan 23 10:05:20 2014 -0800
+++ b/modules/graphics/src/main/native-font/pango.c	Thu Jan 23 11:14:34 2014 -0800
@@ -40,50 +40,10 @@
 /*                                                                        */
 /**************************************************************************/
 
-typedef struct PangoGlyphInfo_FID_CACHE {
-    int cached;
-    jclass clazz;
-    jfieldID glyph, width, x_offset, y_offset;
-    jmethodID init;
-} PangoGlyphInfo_FID_CACHE;
-
-PangoGlyphInfo_FID_CACHE PangoGlyphInfoFc;
-
-void cachePangoGlyphInfoFields(JNIEnv *env)
-{
-    if (PangoGlyphInfoFc.cached) return;
-    jclass tmpClass = (*env)->FindClass(env, "com/sun/javafx/font/freetype/PangoGlyphInfo");
-    PangoGlyphInfoFc.clazz =  (jclass)(*env)->NewGlobalRef(env, tmpClass);
-    PangoGlyphInfoFc.glyph = (*env)->GetFieldID(env, PangoGlyphInfoFc.clazz, "glyph", "I");
-    PangoGlyphInfoFc.width = (*env)->GetFieldID(env, PangoGlyphInfoFc.clazz, "width", "I");
-    PangoGlyphInfoFc.x_offset = (*env)->GetFieldID(env, PangoGlyphInfoFc.clazz, "x_offset", "I");
-    PangoGlyphInfoFc.y_offset = (*env)->GetFieldID(env, PangoGlyphInfoFc.clazz, "y_offset", "I");
-    PangoGlyphInfoFc.init = (*env)->GetMethodID(env, PangoGlyphInfoFc.clazz, "<init>", "()V");
-    PangoGlyphInfoFc.cached = 1;
-}
-
-void setPangoGlyphInfoFields(JNIEnv *env, jobject lpObject, PangoGlyphInfo *lpStruct)
-{
-    if (!PangoGlyphInfoFc.cached) cachePangoGlyphInfoFields(env);
-    (*env)->SetIntField(env, lpObject, PangoGlyphInfoFc.glyph, (jint)lpStruct->glyph);
-    (*env)->SetIntField(env, lpObject, PangoGlyphInfoFc.width, (jint)lpStruct->geometry.width);
-    (*env)->SetIntField(env, lpObject, PangoGlyphInfoFc.x_offset, (jint)lpStruct->geometry.x_offset);
-    (*env)->SetIntField(env, lpObject, PangoGlyphInfoFc.y_offset, (jint)lpStruct->geometry.y_offset);
-}
-
-jobject newPangoGlyphInfo(JNIEnv *env, PangoGlyphInfo *lpStruct)
-{
-    jobject lpObject = NULL;
-    if (!PangoGlyphInfoFc.cached) cachePangoGlyphInfoFields(env);
-    lpObject = (*env)->NewObject(env, PangoGlyphInfoFc.clazz, PangoGlyphInfoFc.init);
-    if (lpObject && lpStruct) setPangoGlyphInfoFields(env, lpObject, lpStruct);
-    return lpObject;
-}
-
 typedef struct PangoGlyphString_FID_CACHE {
     int cached;
     jclass clazz;
-    jfieldID num_glyphs, glyphs, log_clusters, offset, length, num_chars, font;
+    jfieldID num_glyphs, glyphs, widths, log_clusters, offset, length, num_chars, font;
     jmethodID init;
 } PangoGlyphString_FID_CACHE;
 
@@ -95,7 +55,8 @@
     jclass tmpClass = (*env)->FindClass(env, "com/sun/javafx/font/freetype/PangoGlyphString");
     PangoGlyphStringFc.clazz =  (jclass)(*env)->NewGlobalRef(env, tmpClass);
     PangoGlyphStringFc.num_glyphs = (*env)->GetFieldID(env, PangoGlyphStringFc.clazz, "num_glyphs", "I");
-    PangoGlyphStringFc.glyphs = (*env)->GetFieldID(env, PangoGlyphStringFc.clazz, "glyphs", "[Lcom/sun/javafx/font/freetype/PangoGlyphInfo;");
+    PangoGlyphStringFc.glyphs = (*env)->GetFieldID(env, PangoGlyphStringFc.clazz, "glyphs", "[I");
+    PangoGlyphStringFc.widths = (*env)->GetFieldID(env, PangoGlyphStringFc.clazz, "widths", "[I");
     PangoGlyphStringFc.log_clusters = (*env)->GetFieldID(env, PangoGlyphStringFc.clazz, "log_clusters", "[I");
     PangoGlyphStringFc.offset = (*env)->GetFieldID(env, PangoGlyphStringFc.clazz, "offset", "I");
     PangoGlyphStringFc.length = (*env)->GetFieldID(env, PangoGlyphStringFc.clazz, "length", "I");
@@ -112,11 +73,6 @@
 /**************************************************************************/
 
 /** Custom **/
-JNIEXPORT jlong JNICALL OS_NATIVE(pango_1itemize)
-    (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2, jint arg3, jlong arg4, jlong arg5)
-{
-    return (jlong)pango_itemize((PangoContext *)arg0, (const char *)arg1, arg2, arg3, (PangoAttrList *)arg4, (PangoAttrIterator *)arg5);
-}
 
 JNIEXPORT jobject JNICALL OS_NATIVE(pango_1shape)
     (JNIEnv *env, jclass that, jlong str, jlong pangoItem)
@@ -125,33 +81,36 @@
     PangoItem *item = (PangoItem *)pangoItem;
     PangoAnalysis analysis = item->analysis;
     const gchar *text= (const gchar *)(str + item->offset);
-    PangoGlyphString *glyphs = pango_glyph_string_new();
+    PangoGlyphString *glyphString = pango_glyph_string_new();
 
-    pango_shape(text, item->length, &analysis, glyphs);
-    int count = glyphs->num_glyphs;
+    pango_shape(text, item->length, &analysis, glyphString);
+    int count = glyphString->num_glyphs;
     if(count == 0) return NULL;
 
-    if (!PangoGlyphInfoFc.cached) cachePangoGlyphInfoFields(env);
-    jobjectArray infoArray = (*env)->NewObjectArray(env, count, PangoGlyphInfoFc.clazz, NULL);
+    jintArray glyphsArray = (*env)->NewIntArray(env, count);
+    jintArray widthsArray = (*env)->NewIntArray(env, count);
     jintArray clusterArray = (*env)->NewIntArray(env, count);
     jobject result = NULL;
-    if (infoArray && clusterArray) {
+    if (glyphsArray && widthsArray && clusterArray) {
+    	jint glyphs[count];
+    	jint widths[count];
         jint cluster[count];
         int i;
         for (i = 0; i < count; i++) {
-            jobject info = newPangoGlyphInfo(env, &glyphs->glyphs[i]);
-            (*env)->SetObjectArrayElement(env, infoArray, i, info);
+        	glyphs[i] = glyphString->glyphs[i].glyph;
+        	widths[i] = glyphString->glyphs[i].geometry.width;
             /* translate byte index to char index */
-            cluster[i] = (jint)g_utf8_pointer_to_offset(text, text + glyphs->log_clusters[i]);
+            cluster[i] = (jint)g_utf8_pointer_to_offset(text, text + glyphString->log_clusters[i]);
         }
+        (*env)->SetIntArrayRegion(env, glyphsArray, 0, count, glyphs);
+        (*env)->SetIntArrayRegion(env, widthsArray, 0, count, widths);
         (*env)->SetIntArrayRegion(env, clusterArray, 0, count, cluster);
         if (!PangoGlyphStringFc.cached) cachePangoGlyphStringFields(env);
         result = (*env)->NewObject(env, PangoGlyphStringFc.clazz, PangoGlyphStringFc.init);
         if (result) {
             (*env)->SetIntField(env, result, PangoGlyphStringFc.num_glyphs, count);
-
-            /* Set custom fields */
-            (*env)->SetObjectField(env, result, PangoGlyphStringFc.glyphs, infoArray);
+            (*env)->SetObjectField(env, result, PangoGlyphStringFc.glyphs, glyphsArray);
+            (*env)->SetObjectField(env, result, PangoGlyphStringFc.widths, widthsArray);
             (*env)->SetObjectField(env, result, PangoGlyphStringFc.log_clusters, clusterArray);
             (*env)->SetIntField(env, result, PangoGlyphStringFc.offset, item->offset);
             (*env)->SetIntField(env, result, PangoGlyphStringFc.length, item->length);
@@ -159,7 +118,7 @@
             (*env)->SetLongField(env, result, PangoGlyphStringFc.font, (jlong)analysis.font);
         }
     }
-    pango_glyph_string_free(glyphs);
+    pango_glyph_string_free(glyphString);
     return result;
 }
 
@@ -206,6 +165,12 @@
 }
 
 /** one to one **/
+JNIEXPORT jlong JNICALL OS_NATIVE(pango_1itemize)
+    (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2, jint arg3, jlong arg4, jlong arg5)
+{
+    return (jlong)pango_itemize((PangoContext *)arg0, (const char *)arg1, arg2, arg3, (PangoAttrList *)arg4, (PangoAttrIterator *)arg5);
+}
+
 JNIEXPORT jlong JNICALL OS_NATIVE(pango_1font_1describe)
     (JNIEnv *env, jclass that, jlong arg0)
 {