Hey,
This patch (committed) continues fixing FreetypeGlyphVector.
The previous implementation treated glyph transformations as relative to
the origin, when instead they should be relative to the glyph's
individual position (and thus independent of the position).
This also makes it much easier to implement the getLogicalBounds method
properly. The barChart SVG test in Batik now works.
Cheers,
Francis
2006-09-21 Francis Kung <[EMAIL PROTECTED]>
* gnu/java/awt/peer/gtk/FreetypeGlyphVector.java:
(getLogicalBounds): Respect glyph transformations.
(getGlyphOutline): Added null pointer check.
(getGlyphTransform): Do not generate identity transform (API permits
null).
(setGlyphPosition): Do not invalidate transform.
(setGlyphTransform): Do not modify glyph position.
Index: gnu/java/awt/peer/gtk/FreetypeGlyphVector.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java,v
retrieving revision 1.9
diff -u -r1.9 FreetypeGlyphVector.java
--- gnu/java/awt/peer/gtk/FreetypeGlyphVector.java 20 Sep 2006 21:50:01 -0000 1.9
+++ gnu/java/awt/peer/gtk/FreetypeGlyphVector.java 21 Sep 2006 23:01:37 -0000
@@ -297,9 +297,6 @@
return rval;
}
- /**
- * FIXME: Implement me.
- */
public Shape getGlyphLogicalBounds(int glyphIndex)
{
GlyphMetrics gm = getGlyphMetrics( glyphIndex );
@@ -307,10 +304,17 @@
return null;
Rectangle2D r = gm.getBounds2D();
Point2D p = getGlyphPosition( glyphIndex );
- return new Rectangle2D.Double( p.getX() + r.getX() - gm.getLSB(),
- p.getY() + r.getY(),
- gm.getAdvanceX(),
- r.getHeight() );
+
+ double[] bounds = new double[] {p.getX() + r.getX() - gm.getLSB(),
+ p.getY() + r.getY(),
+ p.getX() + r.getX() - gm.getLSB() + gm.getAdvanceX(),
+ p.getY() + r.getY() + r.getHeight()};
+
+ if (glyphTransforms[glyphIndex] != null)
+ glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 4);
+
+ return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
+ bounds[3] - bounds[1]);
}
/*
@@ -363,7 +367,9 @@
public Shape getGlyphOutline(int glyphIndex)
{
GeneralPath gp = getGlyphOutlineNative( glyphCodes[ glyphIndex ] );
- gp.transform( getGlyphTransform(glyphIndex));
+ if (glyphTransforms[glyphIndex] != null)
+ gp.transform( glyphTransforms[glyphIndex]);
+
return gp;
}
@@ -395,10 +401,6 @@
*/
public AffineTransform getGlyphTransform(int glyphIndex)
{
- if (glyphTransforms[glyphIndex] == null)
- glyphTransforms[glyphIndex] = AffineTransform.getTranslateInstance(glyphPositions[glyphIndex*2],
- glyphPositions[glyphIndex*2 + 1]);
-
return glyphTransforms[glyphIndex];
}
@@ -487,13 +489,9 @@
*/
public void setGlyphPosition(int glyphIndex, Point2D newPos)
{
- // FIXME: Scaling, etc.?
glyphPositions[glyphIndex*2] = (float)(newPos.getX());
glyphPositions[glyphIndex*2 + 1] = (float)(newPos.getY());
logicalBounds = null;
-
- if (glyphIndex != nGlyphs)
- glyphTransforms[glyphIndex] = null;
}
/**
@@ -501,15 +499,7 @@
*/
public void setGlyphTransform(int glyphIndex, AffineTransform newTX)
{
- // 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());
glyphTransforms[glyphIndex] = newTX;
}
}