I added the code to filter out non-printing characters in native, like Mark suggested. It is a lot more efficient.
2005-11-22 Lillian Angel <[EMAIL PROTECTED]> PR 24937 * gnu/java/awt/peer/gtk/GdkGraphics.java (drawString): Removed pattern matching code. This is now done in native. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (Java_gnu_java_awt_peer_gtk_GdkGraphics_drawString): Added a loop to filter out all non-printing characters. On Tue, 2005-11-22 at 09:37 -0500, Lillian Angel wrote: > Robert was right about the regex. I have fixed it for now. I will work > on putting the filtering of characters in the native code instead. > > 2005-11-22 Lillian Angel <[EMAIL PROTECTED]> > > * gnu/java/awt/peer/gtk/GdkGraphics.java > (drawString): Fixed regex. > > > > On Tue, 2005-11-22 at 12:35 +0100, Robert Schuster wrote: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > Hi Lillian, > > this broke text drawing considerably. All the spaces in labels, textfields > > etc > > are missing now. > > > > Lillian Angel wrote: > > >> public class GdkGraphics extends Graphics > > >> { > > >>@@ -247,10 +247,13 @@ > > >> native void drawString (GdkFontPeer f, String str, int x, int y); > > >> public void drawString (String str, int x, int y) > > >> { > > >>+ // FIXME: Possibly more characters we need to ignore/ > > >>+ // Also, implementation may be inefficent because allocating > > >>+ // new Strings. > > > > The reason for this is here: > > > > >>+ str = Pattern.compile("[\b | \t | \n | \f | \r | \" | > > >>\']").matcher(str).replaceAll(""); > > > > I guess you added the spaces to let the regexp look a bit nicer but this > > actually means that the expression will match space characters. The correct > > expression would be: "[\b|\t|\n|\f|\r|\"|\']" > > > > Apart from that I think Mark is right here. Doing the filtering in C would > > result in better performance. You could implement a special variant of the > > JNI > > function that makes Java Strings available as C strings and filter unwanted > > characters in it. > > > > cya > > Robert > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.4.1 (GNU/Linux) > > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org > > > > iD8DBQFDgwKMG9cfwmwwEtoRAuc4AJ9vJz9to+lDFTchIs1qtPTOnwyoggCeJp5d > > dFgnMuaS2/DCWKmYZMCP/Sk= > > =z6rn > > -----END PGP SIGNATURE----- > _______________________________________________ > Classpath-patches mailing list > Classpath-patches@gnu.org > http://lists.gnu.org/mailman/listinfo/classpath-patches
Index: gnu/java/awt/peer/gtk/GdkGraphics.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkGraphics.java,v retrieving revision 1.51 diff -u -r1.51 GdkGraphics.java --- gnu/java/awt/peer/gtk/GdkGraphics.java 22 Nov 2005 14:37:43 -0000 1.51 +++ gnu/java/awt/peer/gtk/GdkGraphics.java 22 Nov 2005 19:06:03 -0000 @@ -247,10 +247,6 @@ native void drawString (GdkFontPeer f, String str, int x, int y); public void drawString (String str, int x, int y) { - // FIXME: Possibly more characters we need to ignore/ - // Also, implementation may be inefficent because allocating - // new Strings. - str = Pattern.compile("[\b|\t|\n|\f|\r|\"|\']").matcher(str).replaceAll(""); drawString(getFontPeer(), str, x, y); } Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c =================================================================== RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c,v retrieving revision 1.29 diff -u -r1.29 gnu_java_awt_peer_gtk_GdkGraphics.c --- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c 22 Sep 2005 20:25:39 -0000 1.29 +++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c 22 Nov 2005 19:06:04 -0000 @@ -291,6 +291,11 @@ struct peerfont *pfont = NULL; struct graphics *g = NULL; const char *cstr = NULL; + char *p = NULL; + char *tmp = NULL; + char *sTmp = NULL; + int count = 0; + int charSize = 0; int baseline_y = 0; PangoLayoutIter *iter = NULL; @@ -303,9 +308,29 @@ g_assert (pfont != NULL); cstr = (*env)->GetStringUTFChars (env, str, NULL); + g_assert (cstr != NULL); + + charSize = sizeof(char); + p = malloc((strlen(cstr) + 1) * charSize); + g_assert (p != NULL); + + tmp = p; + sTmp = cstr; + for (; *sTmp != '\0'; sTmp++) + if (isprint(*sTmp)) + { + *p = *sTmp; + count++; + p++; + } + *p = '\0'; + + p = realloc(tmp, (count + 1) * charSize); + g_assert (p != NULL); + pango_layout_set_text (pfont->layout, p, -1); + free(p); pango_layout_set_font_description (pfont->layout, pfont->desc); - pango_layout_set_text (pfont->layout, cstr, -1); iter = pango_layout_get_iter (pfont->layout); baseline_y = pango_layout_iter_get_baseline (iter); @@ -317,7 +342,7 @@ pango_layout_iter_free (iter); pango_layout_set_text (pfont->layout, "", -1); - + gdk_flush (); (*env)->ReleaseStringUTFChars (env, str, cstr);
_______________________________________________ Classpath-patches mailing list Classpath-patches@gnu.org http://lists.gnu.org/mailman/listinfo/classpath-patches