In the FreeTypeGlyphVector we were throwing away control chars. We
shouldn't do that (the RI also keeps them around) but instead replace
them with some invisible char. I chose 'hair space' here because
'zero-width space' didn't work with my font.

2006-12-04  Roman Kennke  <[EMAIL PROTECTED]>

        * gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
        (FreeTypeGlyphVector): Don't filter control chars here.
        (getGlyphs): Filter control chars and replace them by
        hair space char.

/Roman

Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.13
diff -u -1 -5 -r1.13 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	21 Nov 2006 14:14:26 -0000	1.13
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	4 Dec 2006 20:17:30 -0000
@@ -89,37 +89,31 @@
 
   /**
    * Create a glyphvector from a given (Freetype) font and a String.
    */
   public FreetypeGlyphVector(Font f, String s, FontRenderContext frc)
   {
     this(f, s.toCharArray(), 0, s.length(), frc, Font.LAYOUT_LEFT_TO_RIGHT);
   }
 
   /**
    * Create a glyphvector from a given (Freetype) font and a String.
    */
   public FreetypeGlyphVector(Font f, char[] chars, int start, int len,
                              FontRenderContext frc, int flags)
   {
-    // We need to filter out control characters (and possibly other
-    // non-renderable characters here).
-    StringBuilder b = new StringBuilder(chars.length);
-    for (int i = start; i < start + len; i++)
-      if (!Character.isISOControl(chars[i]))
-        b.append(chars[i]);
-    this.s = b.toString();
+    this.s = new String(chars, start, len);
 
     this.font = f;
     this.frc = frc;
     if( !(font.getPeer() instanceof GdkFontPeer ) )
       throw new IllegalArgumentException("Not a valid font.");
     peer = (GdkFontPeer)font.getPeer();
 
     getGlyphs();
     if( flags == Font.LAYOUT_RIGHT_TO_LEFT )
       {
 	// reverse the glyph ordering.
 	int[] temp = new int[ nGlyphs ];
 	for(int i = 0; i < nGlyphs; i++)
 	  temp[ i ] = glyphCodes[ nGlyphs - i - 1];
 	glyphCodes = temp;
@@ -175,34 +169,41 @@
   }
 
   /**
    * Create the array of glyph codes.
    */
   private void getGlyphs()
   {
     nGlyphs = s.codePointCount( 0, s.length() );
     glyphCodes = new int[ nGlyphs ];
     int[] codePoints = new int[ nGlyphs ];
     int stringIndex = 0;
 
     for(int i = 0; i < nGlyphs; i++)
       {
 	codePoints[i] = s.codePointAt( stringIndex );
-	// UTF32 surrogate handling
+        // UTF32 surrogate handling
 	if( codePoints[i] != (int)s.charAt( stringIndex ) )
 	  stringIndex ++;
 	stringIndex ++;
+
+        if (Character.isISOControl(codePoints[i]))
+          {
+            // Replace with 'hair space'. Should better be 'zero-width space'
+            // but that doesn't seem to be supported by default font.
+            codePoints[i] = 8202;
+          }
       }
 
    glyphCodes = getGlyphs( codePoints );
   }
 
   /**
    * Returns the glyph code within the font for a given character
    */
   public native int[] getGlyphs(int[] codepoints);
 
   /**
    * Returns the kerning of a glyph pair
    */
   private native Point2D getKerning(int leftGlyph, int rightGlyph);
 

Reply via email to