You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by de...@apache.org on 2001/12/10 19:30:34 UTC
cvs commit: xml-batik/sources/org/apache/batik/gvt/text GlyphLayout.java
deweese 01/12/10 10:30:34
Modified: sources/org/apache/batik/ext/awt/image/renderable
AbstractRable.java
sources/org/apache/batik/gvt/font AWTGVTFont.java
AWTGVTGlyphVector.java
sources/org/apache/batik/gvt/text GlyphLayout.java
Log:
1) Fixed a bug in one of the AbstractRable constructors.
2) Put in workaround for worst of Mac OS X text problems (layout
still isn't 100% correct in most cases).
3) Removed code that is no longer needed in GlyphLayout
Note this will cause regressions in some of the text-selection
tests but these should be ignored (I get cyrillic, hebrew, arabic,
start35,beforeafter).
Revision Changes Path
1.4 +2 -1 xml-batik/sources/org/apache/batik/ext/awt/image/renderable/AbstractRable.java
Index: AbstractRable.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/ext/awt/image/renderable/AbstractRable.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractRable.java 2001/09/19 12:11:50 1.3
+++ AbstractRable.java 2001/12/10 18:30:33 1.4
@@ -39,7 +39,7 @@
* implementation.
*
* @author <a href="mailto:Thomas.DeWeeese@Kodak.com">Thomas DeWeese</a>
- * @version $Id: AbstractRable.java,v 1.3 2001/09/19 12:11:50 deweese Exp $
+ * @version $Id: AbstractRable.java,v 1.4 2001/12/10 18:30:33 deweese Exp $
*/
public abstract class AbstractRable implements Filter {
@@ -54,6 +54,7 @@
* method need to be computed in the subclasses constructor.
*/
protected AbstractRable() {
+ srcs = new Vector();
}
/**
1.10 +5 -6 xml-batik/sources/org/apache/batik/gvt/font/AWTGVTFont.java
Index: AWTGVTFont.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/font/AWTGVTFont.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- AWTGVTFont.java 2001/11/05 20:04:11 1.9
+++ AWTGVTFont.java 2001/12/10 18:30:33 1.10
@@ -34,7 +34,7 @@
* This is a wrapper class for a java.awt.Font instance.
*
* @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
- * @version $Id: AWTGVTFont.java,v 1.9 2001/11/05 20:04:11 deweese Exp $
+ * @version $Id: AWTGVTFont.java,v 1.10 2001/12/10 18:30:33 deweese Exp $
*/
public class AWTGVTFont implements GVTFont {
private Font awtFont;
@@ -149,8 +149,8 @@
StringCharacterIterator sci =
new StringCharacterIterator(new String(chars));
- return new AWTGVTGlyphVector(awtFont.createGlyphVector(frc, chars),
- this, scale, sci);
+ GlyphVector gv = awtFont.createGlyphVector(frc, chars);
+ return new AWTGVTGlyphVector(gv, this, scale, sci);
}
/**
@@ -168,9 +168,8 @@
return createGlyphVector(frc, str);
}
}
-
- return new AWTGVTGlyphVector(awtFont.createGlyphVector(frc, ci),
- this, scale, ci);
+ GlyphVector gv = awtFont.createGlyphVector(frc, ci);
+ return new AWTGVTGlyphVector(gv, this, scale, ci);
}
/**
1.14 +65 -54 xml-batik/sources/org/apache/batik/gvt/font/AWTGVTGlyphVector.java
Index: AWTGVTGlyphVector.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/font/AWTGVTGlyphVector.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AWTGVTGlyphVector.java 2001/11/09 15:33:27 1.13
+++ AWTGVTGlyphVector.java 2001/12/10 18:30:34 1.14
@@ -34,13 +34,15 @@
* This is a wrapper class for a java.awt.font.GlyphVector instance.
*
* @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
- * @version $Id: AWTGVTGlyphVector.java,v 1.13 2001/11/09 15:33:27 tkormann Exp $
+ * @version $Id: AWTGVTGlyphVector.java,v 1.14 2001/12/10 18:30:34 deweese Exp $
*/
public class AWTGVTGlyphVector implements GVTGlyphVector {
private GlyphVector awtGlyphVector;
private AWTGVTFont gvtFont;
private CharacterIterator ci;
+ /** This contains the glyphPostions after doing a performDefaultLayout */
+ private Point2D[] defaultGlyphPositions;
private Point2D[] glyphPositions;
// need to keep track of the glyphTransforms since GlyphVector doesn't seem
@@ -88,12 +90,11 @@
ascent = lineMetrics.getAscent();
descent = lineMetrics.getDescent();
-
- int numGlyphs = glyphVector.getNumGlyphs();
- outline = null;
+ outline = null;
logicalBounds = null;
- glyphTransforms = new AffineTransform[numGlyphs];
+ int numGlyphs = glyphVector.getNumGlyphs();
glyphPositions = new Point2D.Float[numGlyphs];
+ glyphTransforms = new AffineTransform[numGlyphs];
glyphOutlines = new Shape[numGlyphs];
glyphVisualBounds = new Shape[numGlyphs];
glyphLogicalBounds = new Shape[numGlyphs];
@@ -144,6 +145,17 @@
}
/**
+ * Returns the logical bounds of this GlyphVector.
+ */
+ public Rectangle2D getLogicalBounds() {
+ if (logicalBounds == null) {
+ // This fills in logicalBounds...
+ computeGlyphLogicalBounds();
+ }
+ return logicalBounds;
+ }
+
+ /**
* Returns the logical bounds of the specified glyph within this
* GlyphVector.
*/
@@ -368,44 +380,50 @@
if (glyphTransform != null) {
tr.concatenate(glyphTransform);
+ }
+ //
+ // <!> HACK
+ //
+ // GlyphVector.getGlyphOutline behavior changes between 1.3 and 1.4
+ //
+ // I've looked at this problem a bit more and the incorrect glyph
+ // positioning in Batik is definitely due to the change in
+ // behavior of GlyphVector.getGlyphOutline(glyphIndex). It used to
+ // return the outline of the glyph at position 0,0 which meant
+ // that we had to translate it to the actual glyph position before
+ // drawing it. Now, it returns the outline which has already been
+ // positioned.
+ //
+ // -- Bella
+ //
+
+ if (outlinesPositioned()) {
+ Point2D glyphPos = defaultGlyphPositions[glyphIndex];
+ tr.translate(-glyphPos.getX(), -glyphPos.getY());
}
- //
- // <!> HACK
- //
- // GlyphVector.getGlyphOutline behavior changes between 1.3 and 1.4
- //
- // I've looked at this problem a bit more and the incorrect glyph
- // positioning in Batik is definitely due to the change in
- // behavior of GlyphVector.getGlyphOutline(glyphIndex). It used to
- // return the outline of the glyph at position 0,0 which meant
- // that we had to translate it to the actual glyph position before
- // drawing it. Now, it returns the outline which has already been
- // positioned.
- //
- // -- Bella
- //
-
- if (isJDK1_4OrGreater()) {
- Point2D glyphPos = awtGlyphVector.getGlyphPosition(glyphIndex);
- tr.translate(-glyphPos.getX(), -glyphPos.getY());
- }
tr.scale(scaleFactor, scaleFactor);
- glyphOutlines[glyphIndex] = tr.createTransformedShape(glyphOutline);
+ glyphOutlines[glyphIndex]=tr.createTransformedShape(glyphOutline);
}
return glyphOutlines[glyphIndex];
}
- private static final boolean is1_4OrGreater;
+ private static final boolean outlinesPositioned;
static {
- String s = System.getProperty("java.version");
- is1_4OrGreater = ("1.4".compareTo(s) < 0);
+ String s = System.getProperty("java.version");
+ if ("1.4".compareTo(s) <= 0) {
+ outlinesPositioned = true;
+ } else if ("Mac OS X".equals(System.getProperty("os.name"))) {
+ outlinesPositioned = true;
+ } else {
+ outlinesPositioned = false;
+ }
}
- private static boolean isJDK1_4OrGreater() {
- return is1_4OrGreater;
+ private static boolean outlinesPositioned() {
+ return outlinesPositioned;
}
/**
@@ -467,17 +485,6 @@
}
/**
- * Returns the logical bounds of this GlyphVector.
- */
- public Rectangle2D getLogicalBounds() {
- if (logicalBounds == null) {
- // This fills in logicalBounds...
- computeGlyphLogicalBounds();
- }
- return logicalBounds;
- }
-
- /**
* Returns the number of glyphs in this GlyphVector.
*/
public int getNumGlyphs() {
@@ -527,28 +534,32 @@
* Assigns default positions to each glyph in this GlyphVector.
*/
public void performDefaultLayout() {
- awtGlyphVector.performDefaultLayout();
- outline = null;
+ if (defaultGlyphPositions == null) {
+ awtGlyphVector.performDefaultLayout();
+ defaultGlyphPositions = new Point2D.Float[getNumGlyphs()];
+ for (int i = 0; i < getNumGlyphs(); i++)
+ defaultGlyphPositions[i] = awtGlyphVector.getGlyphPosition(i);
+ }
+
+ outline = null;
logicalBounds = null;
float shiftLeft = 0;
for (int i = 0; i < getNumGlyphs(); i++) {
- Point2D glyphPos = awtGlyphVector.getGlyphPosition(i);
+ glyphTransforms [i] = null;
+ glyphVisualBounds [i] = null;
+ glyphLogicalBounds[i] = null;
+ glyphOutlines [i] = null;
+ Point2D glyphPos = defaultGlyphPositions[i];
glyphPositions[i] = new Point2D.Float
- ((float)((glyphPos.getX()-shiftLeft) * scaleFactor),
- (float)(glyphPos.getY() * scaleFactor));
-
- glyphTransforms[i] = null;
- glyphVisualBounds[i] = null;
- glyphLogicalBounds[i] = null;
- glyphOutlines[i] = null;
+ ((float)((glyphPos.getX() * scaleFactor)-shiftLeft),
+ (float) (glyphPos.getY() * scaleFactor));
// if c is a transparent arabic char then need to shift the
// following glyphs left so that the current glyph is overwritten
char c = ci.setIndex(i + ci.getBeginIndex());
if (ArabicTextHandler.arabicCharTransparent(c)) {
- GlyphMetrics gm = awtGlyphVector.getGlyphMetrics(i);
- shiftLeft = gm.getAdvance();
+ shiftLeft += getGlyphMetrics(i).getHorizontalAdvance();
}
}
}
1.31 +7 -38 xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java
Index: GlyphLayout.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- GlyphLayout.java 2001/12/10 14:20:12 1.30
+++ GlyphLayout.java 2001/12/10 18:30:34 1.31
@@ -42,7 +42,7 @@
* @see org.apache.batik.gvt.text.TextSpanLayout
*
* @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
- * @version $Id: GlyphLayout.java,v 1.30 2001/12/10 14:20:12 tkormann Exp $
+ * @version $Id: GlyphLayout.java,v 1.31 2001/12/10 18:30:34 deweese Exp $
*/
public class GlyphLayout implements TextSpanLayout {
@@ -364,43 +364,12 @@
Point2D.Float pt;
pt = new Point2D.Float(pts[0], pts[1]);
if (count == 0) firstPt = pt;
- switch(glyphOrientationAngle) {
- case 0:
- // Use sides of rectangle...
- switch (count) {
- case 0: botPts[ptIdx] = pt; break;
- case 1: topPts[ptIdx] = pt; break;
- case 2: topPts[ptIdx+1] = pt; break;
- case 3: botPts[ptIdx+1] = pt; break;
- }
- break;
- case 90:
- // Use "top" and "bottom"
- switch (count) {
- case 0: topPts[ptIdx] = pt; break;
- case 1: topPts[ptIdx+1] = pt; break;
- case 2: botPts[ptIdx+1] = pt; break;
- case 3: botPts[ptIdx] = pt; break;
- }
- break;
- case 180:
- // Use reverse sides of rectangle...
- switch (count) {
- case 0: botPts[ptIdx+1] = pt; break;
- case 1: topPts[ptIdx+1] = pt; break;
- case 2: topPts[ptIdx] = pt; break;
- case 3: botPts[ptIdx] = pt; break;
- }
- break;
- case 270:
- // Use "bottom" and "top"
- switch (count) {
- case 0: topPts[ptIdx+1] = pt; break;
- case 1: topPts[ptIdx] = pt; break;
- case 2: botPts[ptIdx] = pt; break;
- case 3: botPts[ptIdx+1] = pt; break;
- }
- break;
+ // Use sides of rectangle...
+ switch (count) {
+ case 0: botPts[ptIdx] = pt; break;
+ case 1: topPts[ptIdx] = pt; break;
+ case 2: topPts[ptIdx+1] = pt; break;
+ case 3: botPts[ptIdx+1] = pt; break;
}
}
} else if (type == PathIterator.SEG_CLOSE) {
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org