Apologies for not testing properly last time; this patch (also
committed) fixes the earlier FreeGlyphVector patch.

Cheers,
Francis


2006-09-20  Francis Kung  <[EMAIL PROTECTED]>

        PR 29011
        * gnu/java/awt/peer/gtk/FreetypeGlyphVector.java:
        (getGlyphTransform): Use translation instead of scale.
        (performDefaultLayout): Increment position values instead of resetting,
and
        pre-increment instead of post-increment.
        (setGlyphTransform): Handle null case with identity transform.


On Wed, 2006-09-20 at 14:23 -0400, Francis Kung wrote:
> Hi,
> 
> The following patch (committed) fixes the getGlyphPosition and
> getGlyphPositions methods in the gtk peers for
> java.awt.font.GlyphVector, as well as adding support for vertical fonts
> and cleaning up the implementation a bit.
> 
> Regards,
> Francis
> 
> 
> 2006-09-20  Francis Kung  <[EMAIL PROTECTED]>
> 
>       * gnu/java/awt/peer/gtk/FreetypeGlyphVector.java:
>       (constructor): Expanded glyphPositions array to accomodate
> Y-coordinates.
>       (getGlyphOutline): Call getGylphTransform to generate transform.
>       (getGylphPosition): Read position directly out of array.
>       (getGlyphPositions): Read positions directly out of array.
>       (getGlyphTransform): Generate transform based on gylphPositions array.
>       (performDefaultLayout): Populate glyphPositions array instead of
> transforms.
>       (setGlyphPosition): Set position directly into array.
>       (setGlyphTransform): Update positions array as well.
> 
Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.8
diff -u -r1.8 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	20 Sep 2006 18:26:24 -0000	1.8
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java	20 Sep 2006 21:45:39 -0000
@@ -47,6 +47,7 @@
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
 
 public class FreetypeGlyphVector extends GlyphVector
 {
@@ -243,26 +244,31 @@
   public void performDefaultLayout()
   {
     logicalBounds = null; // invalidate caches.
-    glyphPositions = new float[(nGlyphs + 1) * 2];
     glyphTransforms = new AffineTransform[nGlyphs];
+    Arrays.fill(glyphTransforms, null);
+    glyphPositions = new float[(nGlyphs + 1) * 2];
 
     GlyphMetrics gm = null;
+    float x = 0;
+    float y = 0;
     for(int i = 0; i < nGlyphs; i++)
       {
         gm = getGlyphMetrics( i );
-        glyphPositions[i*2] += gm.getAdvanceX();
-        glyphPositions[i*2 + 1] += gm.getAdvanceY();
-        glyphTransforms[i] = null;
+        glyphPositions[i*2] = x;
+        glyphPositions[i*2 + 1] = y;
+
+        x += gm.getAdvanceX();
+        y += gm.getAdvanceY();
         
-        if (i != 0 && i != (nGlyphs + 1))
+        if (i != nGlyphs-1)
           {
-            Point2D p = getKerning(glyphCodes[i - 1], glyphCodes[i]);
-            glyphPositions[i * 2] += p.getX();
-            glyphPositions[i * 2 + 1] += p.getY();
+            Point2D p = getKerning(glyphCodes[i], glyphCodes[i + 1]);
+            x += p.getX();
+            y += p.getY();
           }
       }
-    glyphPositions[nGlyphs * 2] = gm.getAdvanceX();
-    glyphPositions[nGlyphs * 2 + 1] = gm.getAdvanceY();
+    glyphPositions[nGlyphs * 2] = x;
+    glyphPositions[nGlyphs * 2 + 1] = y;
   }
 
   /**
@@ -390,8 +396,8 @@
   public AffineTransform getGlyphTransform(int glyphIndex)
   {
     if (glyphTransforms[glyphIndex] == null)
-      glyphTransforms[glyphIndex] = AffineTransform.getScaleInstance(glyphPositions[glyphIndex*2],
-                                                                     glyphPositions[glyphIndex*2 + 1]);
+      glyphTransforms[glyphIndex] = AffineTransform.getTranslateInstance(glyphPositions[glyphIndex*2],
+                                                                         glyphPositions[glyphIndex*2 + 1]);
     
     return glyphTransforms[glyphIndex];
   }
@@ -497,6 +503,10 @@
   {
     // FIXME: Scaling, etc.?
     logicalBounds = null;
+    
+    if (newTX == null)
+      newTX = new AffineTransform();
+    
     Point2D pt = newTX.transform(new Point2D.Double(0, 0), null);
     glyphPositions[glyphIndex*2] = (float)(pt.getX());
     glyphPositions[glyphIndex*2 + 1] = (float)(pt.getY());

Reply via email to