This has been approved by Tom and Roman.
I re-implemented this to just use replaceAll. I know it is sometimes
inefficent, so I added a FIXME.
2005-11-21 Lillian Angel <[EMAIL PROTECTED]>
PR classpath/PR24937
* gnu/java/awt/peer/gtk/GdkGraphics.java
(drawString): Removed most non-printable characters
from the string that will be drawn. Added a FIXME comment
because may not have filtered out all characters and
replace all is inefficent.
On Mon, 2005-11-21 at 15:54 -0500, Lillian Angel wrote:
> On Mon, 2005-11-21 at 15:46 -0500, Thomas Fitzsimmons wrote:
> > On Mon, 2005-11-21 at 14:33 -0500, Lillian Angel wrote:
> > > This fixes bug # 24937
> > > I spoke in detail to Roman about this.
> > > drawString(String...) was changed to call
> > > drawString(AttributedCharacterIterator...) because they both need to
> > > ignore the newline characters.
> > >
> > > drawString(AttributedCharacterIterator...) iterates through the
> > > characters and stores the non-newline chars in an array. Here Roman
> > > suggested that I make some changes and pass the char[] to the native
> > > drawString function because allocating a new String is not ideal.
> > >
> > > I tried doing this, but that native function calls getStringUTFChars
> > > (which requires a jstring). Removing the call to getStringUTFChars
> > > obviously does not work...
> > >
> > > The best way to do this right now (since
> > > drawString(AttributedCharacterIterator...) is not fully implemented), is
> > > creating a new String, like I have done in this patch, or call
> > > replaceAll("\n", "") on the String. replaceAll does a lot of unnecessary
> > > things, so I avoided using it.
> >
> > Why bring the AttributedCharacterIterator drawString into this?
>
> In this function, we need to filter out those characters as well. Roman
> thought it was best I do it like this. If its not good, I can always
> change it around.
>
>
> > Why not
> > just create a new string in "drawString (String str, int x, int y)"
> > using something like String.replaceAll?
>
> replaceAll does alot of stuff, it would be more inefficent to use it.
>
> >
> > Also, is it enough to check for '\n'? Are there other Unicode
> > formatting characters we should filter out?
>
> Good point. I will look into this.
>
> Lillian
>
>
>
> _______________________________________________
> Classpath-patches mailing list
> [email protected]
> 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.49
diff -u -r1.49 GdkGraphics.java
--- gnu/java/awt/peer/gtk/GdkGraphics.java 3 Nov 2005 00:21:21 -0000 1.49
+++ gnu/java/awt/peer/gtk/GdkGraphics.java 21 Nov 2005 22:07:53 -0000
@@ -48,9 +48,9 @@
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Shape;
-import java.awt.SystemColor;
import java.awt.image.ImageObserver;
import java.text.AttributedCharacterIterator;
+import java.util.regex.*;
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.
+ str = Pattern.compile("[\b | \t | \n | \f | \r | \" | \']").matcher(str).replaceAll("");
drawString(getFontPeer(), str, x, y);
- }
+ }
-
public void drawString (AttributedCharacterIterator ci, int x, int y)
{
throw new Error ("not implemented");
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches