Re: [cp-patches] FYI: Font substitution

2007-04-03 Thread Francis Kung
I've run through a number of tests and have not noticed any 
regressions in performance or functionality, but please let me know if 
there are any problems.


That didn't take long.  This patch clears up a null pointer exception 
introduced by the last patch.




One last one, a tiny fix for people with --enable-regen-headers

Francis


2007-04-03  Francis Kung  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(getGlyphs(int[], int[], long[])): Return void.

Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.18
diff -u -r1.18 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	2 Apr 2007 21:28:58 -	1.18
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	3 Apr 2007 19:30:10 -
@@ -234,7 +234,7 @@
   /**
* Returns the glyph code within the font for a given character
*/
-  public native int[] getGlyphs(int[] codepoints, int[] glyphs, long[] fonts);
+  public native void getGlyphs(int[] codepoints, int[] glyphs, long[] fonts);
 
   /**
* Returns the kerning of a glyph pair


[cp-patches] FYI: Font substitution

2007-04-02 Thread Francis Kung

Hi,

This patch adds font substitution functionality to our GTK peers.

The Sun JDK seems to ship with a bundled font that covers many 
non-English characters, but since we use Freetype, we need to use 
fontsets and combine different fonts in order to obtain the same 
coverage (but we now support more fonts than the JDK, as long as the 
user has it installed on their system!).


I've run through a number of tests and have not noticed any regressions 
in performance or functionality, but please let me know if there are any 
problems.


Cheers,
Francis


2007-04-02  Francis Kung  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/CairoGraphics2D.java
(cairoDrawGlyphVector): Added parameter.
(drawGlyphVector): Retrieve and pass fontset parameter.
* gnu/java/awt/peer/gtk/ComponentGraphics.java
(cairoDrawGlyphVector): Added parameter.
(lock): Removed unnecessary cast.
(unlock): Removed unnecessary cast and explicitly set to ONE variable.
* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(fontSet): New field.
(dispose): New native method.
(finalize): New method.
(getGlyphFonts): New method.
(getGlyphOutline): Pass fontSet parameter to native method.
(getGlyphOutlineNative): Added parameter.
(getGlyphs): Pass extra parameters to native method.
(getGlyphsNative): Added parameters.
(getKerning): Added fontSet parameter.
(getMetricsNative): Added fontSet parameter.
(performDefaultLayout): Only check kerning if glyphs use the same font.
(setupGlyphMetrics): Pass extra parameters to native methods.
* include/gnu_java_awt_peer_gtk_CairoGraphics2D.h,
* include/gnu_java_awt_peer_gtk_FreetypGlyphVector.h: Regenerated.
* native/jni/gtk-peer/gdkfont.h: Enable pango engine.
(peerfont): Add variable for fontset.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c
(Java_gnu_java_awt_peer_gtk_CairoGraphics2D_cairoDrawGlyphVector): 
Accept
array of font pointers to use when drawing glyphs.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
(getFontSet): New function.
(Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_dispose): New function.
(Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphOutlineNative):
Added and use new fontSet parameter.
(Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphs): Use pango
to retrieve glyphs and estimate font, if the current font does not 
contain
a requested glyph.
(Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getKerning): Added and 
use
new fontSet parameter.
(Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getMetricsNative): Added
and use new fontSet parameter.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
(Java_gnu_java_awt_peer_gtk_GdkFontPeer_dispose): Free fontset.
(Java_gnu_java_awt_peer_gtk_GdkFontPeer_setFont): Load fontset.
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
===
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c,v
retrieving revision 1.4
diff -u -r1.4 gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	11 Jun 2006 11:31:03 -	1.4
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	2 Apr 2007 19:36:03 -
@@ -35,6 +35,7 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+#define PANGO_ENABLE_ENGINE
 #include jni.h
 #include gtk/gtk.h
 #include string.h
@@ -43,6 +44,7 @@
 #include pango/pangofc-font.h
 #include freetype/ftglyph.h
 #include freetype/ftoutln.h
+#include jcl.h
 #include native_state.h
 #include gdkfont.h
 #include gnu_java_awt_peer_gtk_FreetypeGlyphVector.h
@@ -81,42 +83,92 @@
   return (PangoFcFont *)pfont-font;
 }
 
-JNIEXPORT jintArray JNICALL 
+static PangoFontset *
+getFontSet(JNIEnv *env, jobject obj)
+{
+  jfieldID fid;
+  jobject data;
+  jclass cls;
+  struct peerfont *pfont;
+
+  cls = (*env)-GetObjectClass (env, obj);
+  fid = (*env)-GetFieldID (env, cls, peer, 
+ Lgnu/java/awt/peer/gtk/GdkFontPeer;);
+  g_assert (fid != 0);
+
+  data = (*env)-GetObjectField (env, obj, fid);
+  g_assert (data != NULL);
+
+  pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, data);
+  g_assert (pfont != NULL);
+  g_assert (pfont-font != NULL);
+
+  return (PangoFontset *)pfont-set;
+}
+
+JNIEXPORT void JNICALL 
 Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphs
-  (JNIEnv *env, jobject obj, jintArray codepoints)
+  (JNIEnv *env, jobject obj, jintArray codepoints, jintArray glyphs,
+   jlongArray fonts)
 {
-  FT_Face ft_face;
-  jintArray retArray;
-  PangoFcFont *font;
-  jint *values, *cpvals;
+  PangoFcFont 

Re: [cp-patches] FYI: Font substitution

2007-04-02 Thread Francis Kung
I've run through a number of tests and have not noticed any regressions 
in performance or functionality, but please let me know if there are any 
problems.


That didn't take long.  This patch clears up a null pointer exception 
introduced by the last patch.


Francis


2007-04-02  Francis Kung  [EMAIL PROTECTED]

* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
(fontSet): Initialize to null.
(FreetypeGlyphVector(Font, int[], FontRenderContext)): Populate fontSet
array with default font if needed.
(FreetypeGlyphVector(FreetypeGlyphVector)): Clone all fields.
(getNativeFontPointer): New native method.
* include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h: Regenerated.
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
(Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getNativeFontPointer):
New function.

Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
===
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c,v
retrieving revision 1.5
diff -u -r1.5 gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	2 Apr 2007 19:39:26 -	1.5
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	2 Apr 2007 21:26:08 -
@@ -420,3 +420,16 @@
 
   (*env)-ReleaseLongArrayElements (env, fontset, fontArray, 0);
 }
+
+JNIEXPORT jlong JNICALL 
+Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getNativeFontPointer
+ (JNIEnv *env, jobject obj, jint n)
+{
+  int i;
+  PangoFcFont *font = getFont(env, obj);
+  
+  for (i = 0; i  n; i++)
+g_object_ref(font);
+  
+  return PTR_TO_JLONG(font);
+}
Index: include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h
===
RCS file: /cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h,v
retrieving revision 1.3
diff -u -r1.3 gnu_java_awt_peer_gtk_FreetypeGlyphVector.h
--- include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h	2 Apr 2007 19:39:26 -	1.3
+++ include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h	2 Apr 2007 21:26:08 -
@@ -15,6 +15,7 @@
 JNIEXPORT jdoubleArray JNICALL Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getMetricsNative (JNIEnv *env, jobject, jint, jlong);
 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphOutlineNative (JNIEnv *env, jobject, jint, jlong);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_dispose (JNIEnv *env, jobject, jlongArray);
+JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getNativeFontPointer (JNIEnv *env, jobject, jint);
 
 #ifdef __cplusplus
 }
Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.17
diff -u -r1.17 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	2 Apr 2007 19:39:26 -	1.17
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	2 Apr 2007 21:26:08 -
@@ -83,7 +83,7 @@
   /**
* The set of fonts used in this glyph vector.
*/
-  private long[] fontSet;
+  private long[] fontSet = null;
 
   /**
* Glyph transforms. (de facto only the translation is used)
@@ -93,6 +93,17 @@
   private GlyphMetrics[] metricsCache;
   
   private native void dispose(long[] fonts);
+  
+  /**
+   * Returns a pointer to the native PangoFcFont object.
+   * 
+   * The object will be referenced with g_object_ref n times before being
+   * returned, and must be unreferenced a corresponding number of times.
+   * 
+   * @param n Number of times to reference the object.
+   * @return Pointer to the native default font.
+   */
+  private native long getNativeFontPointer(int n);
 
   /**
* Create a glyphvector from a given (Freetype) font and a String.
@@ -142,6 +153,13 @@
 glyphCodes = new int[ codes.length ];
 System.arraycopy(codes, 0, glyphCodes, 0, codes.length);
 nGlyphs = glyphCodes.length;
+
+if (fontSet == null)
+  {
+fontSet = new long[nGlyphs];
+Arrays.fill(fontSet, getNativeFontPointer(nGlyphs));
+  }
+
 performDefaultLayout();
   }
 
@@ -164,6 +182,7 @@
   }
 
 glyphCodes = new int[ nGlyphs ];
+fontSet = new long[nGlyphs];
 glyphPositions = new float[(nGlyphs + 1) * 2];
 glyphTransforms = new AffineTransform[ nGlyphs ];
 for(int i = 0; i  nGlyphs; i++ )
@@ -173,6 +192,8 @@
   }
 System.arraycopy(gv.glyphPositions, 0, glyphPositions, 0,
  glyphPositions.length);
+System.arraycopy(gv.glyphCodes, 0, glyphCodes, 0, nGlyphs);
+System.arraycopy(gv.fontSet, 0, fontSet, 0, nGlyphs);
   }
   
   public void finalize()