This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: Implement native drawString using Pango


Hello,

This patch changes the native implementation of GdkGraphics.drawString
to use Pango text-handling functions.  The existing XLFD implementation
was producing completely incorrect output.

Please review and comment.

Thanks,
Tom

2003-08-22  Thomas Fitzsimmons  <fitzsim@redhat.com>

	* gnu/java/awt/peer/gtk/GdkGraphics.java (drawString): Pass font
	name, not XLFD, to native drawString.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (drawString):
	Replace XLFD-based implementation with Pango-based
	implementation.

Index: gnu/java/awt/peer/gtk/GdkGraphics.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 GdkGraphics.java
--- gnu/java/awt/peer/gtk/GdkGraphics.java	13 Jul 2003 15:09:20 -0000	1.3
+++ gnu/java/awt/peer/gtk/GdkGraphics.java	22 Aug 2003 15:44:12 -0000
@@ -215,8 +215,7 @@
   native void drawString (String str, int x, int y, String fname, int size);
   public void drawString (String str, int x, int y)
   {
-    drawString (str, x, y,
-		((GtkFontPeer)font.getPeer ()).getXLFD (), font.getSize ());
+    drawString (str, x, y, font.getName(), font.getSize());
   }
 
   public void drawString (AttributedCharacterIterator ci, int x, int y)
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c,v
retrieving revision 1.2
diff -u -b -B -r1.2 gnu_java_awt_peer_gtk_GdkGraphics.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c	30 Jun 2003 23:53:29 -0000	1.2
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c	22 Aug 2003 15:44:13 -0000
@@ -191,26 +191,39 @@
    jstring fname, jint size)
 {
   struct graphics *g;
-  const char *cfname, *cstr;
-  gchar *xlfd;
+  const char *cstr;
+  const char *font_name;
+  PangoFontDescription *font_desc;
+  PangoContext *context;
+  PangoLayout *layout;
 
   g = (struct graphics *) NSA_GET_PTR (env, obj);
   
-  cfname = (*env)->GetStringUTFChars (env, fname, NULL);
-  xlfd = g_strdup_printf (cfname, (size * 10));
-  (*env)->ReleaseStringUTFChars (env, fname, cfname);
-
   cstr = (*env)->GetStringUTFChars (env, str, NULL);
+  font_name = (*env)->GetStringUTFChars (env, fname, NULL);
 
   gdk_threads_enter ();
-  gdk_draw_string (g->drawable, gdk_font_load (xlfd), g->gc, 
-		   x + g->x_offset, y + g->y_offset, cstr);
+
+  font_desc = pango_font_description_from_string (font_name);
+  pango_font_description_set_size (font_desc, size * PANGO_SCALE);
+
+  context = gdk_pango_context_get();
+  pango_context_set_font_description (context, font_desc);
+
+  layout = pango_layout_new (context);
+
+  pango_layout_set_text (layout, cstr, -1);
+
+  gdk_draw_layout (g->drawable, g->gc, 
+  		   x + g->x_offset, y + g->y_offset, layout);
+
+  pango_font_description_free (font_desc);
+
   gdk_threads_leave ();
 
+  (*env)->ReleaseStringUTFChars (env, fname, font_name);
   (*env)->ReleaseStringUTFChars (env, str, cstr);
-  g_free (xlfd);
 }
-
 
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkGraphics_drawLine
   (JNIEnv *env, jobject obj, jint x, jint y, jint x2, jint y2)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]