You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by de...@apache.org on 2005/09/17 21:23:39 UTC
svn commit: r289842 - in
/xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table:
GlyfCompositeComp.java GlyfCompositeDescript.java GlyfDescript.java
GlyfTable.java HheaTable.java
Author: deweese
Date: Sat Sep 17 12:23:19 2005
New Revision: 289842
URL: http://svn.apache.org/viewcvs?rev=289842&view=rev
Log:
Fixed problems TTF2SVG tool encountered with code2000.ttf font.
Modified:
xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeComp.java
xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java
xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfDescript.java
xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfTable.java
xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/HheaTable.java
Modified: xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeComp.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeComp.java?rev=289842&r1=289841&r2=289842&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeComp.java (original)
+++ xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeComp.java Sat Sep 17 12:23:19 2005
@@ -40,7 +40,7 @@
private short argument1;
private short argument2;
private short flags;
- private short glyphIndex;
+ private int glyphIndex;
private double xscale = 1.0;
private double yscale = 1.0;
private double scale01 = 0.0;
@@ -50,11 +50,9 @@
private int point1 = 0;
private int point2 = 0;
- protected GlyfCompositeComp(int firstIndex, int firstContour, ByteArrayInputStream bais) {
- this.firstIndex = firstIndex;
- this.firstContour = firstContour;
- flags = (short)(bais.read()<<8 | bais.read());
- glyphIndex = (short)(bais.read()<<8 | bais.read());
+ protected GlyfCompositeComp(ByteArrayInputStream bais) {
+ flags = (short)((bais.read()<<8) | bais.read());
+ glyphIndex = ((bais.read()<<8) | bais.read());
// Get the arguments as just their raw values
if ((flags & ARG_1_AND_2_ARE_WORDS) != 0) {
@@ -95,10 +93,17 @@
}
}
+ public void setFirstIndex(int idx) {
+ firstIndex = idx;
+ }
+
public int getFirstIndex() {
return firstIndex;
}
+ public void setFirstContour(int idx) {
+ firstContour = idx;
+ }
public int getFirstContour() {
return firstContour;
}
@@ -115,7 +120,7 @@
return flags;
}
- public short getGlyphIndex() {
+ public int getGlyphIndex() {
return glyphIndex;
}
Modified: xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java?rev=289842&r1=289841&r2=289842&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java (original)
+++ xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfCompositeDescript.java Sat Sep 17 12:23:19 2005
@@ -18,7 +18,9 @@
package org.apache.batik.svggen.font.table;
import java.io.ByteArrayInputStream;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
/**
* Glyph description for composite glyphs. Composite glyphs are made up of one
@@ -30,7 +32,10 @@
*/
public class GlyfCompositeDescript extends GlyfDescript {
- private Vector components = new Vector();
+ private List components = new ArrayList();
+
+ protected boolean beingResolved = false;
+ protected boolean resolved = false;
public GlyfCompositeDescript(GlyfTable parentTable,
ByteArrayInputStream bais) {
@@ -38,24 +43,44 @@
// Get all of the composite components
GlyfCompositeComp comp;
+ do {
+ comp = new GlyfCompositeComp(bais);
+ components.add(comp);
+ } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
+
+ // Are there hinting intructions to read?
+ if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) {
+ readInstructions(bais, (bais.read()<<8 | bais.read()));
+ }
+ }
+
+ public void resolve() {
+ if (resolved) return;
+ if (beingResolved) {
+ System.err.println("Circular reference in GlyfCompositeDesc");
+ return;
+ }
+ beingResolved = true;
+
int firstIndex = 0;
int firstContour = 0;
- do {
- comp = new GlyfCompositeComp(firstIndex, firstContour, bais);
- components.addElement(comp);
- GlyphDescription desc;
+ Iterator i = components.iterator();
+ while (i.hasNext()) {
+ GlyfCompositeComp comp = (GlyfCompositeComp)i.next();
+ comp.setFirstIndex(firstIndex);
+ comp.setFirstContour(firstContour);
+
+ GlyfDescript desc;
desc = parentTable.getDescription(comp.getGlyphIndex());
if (desc != null) {
+ desc.resolve();
firstIndex += desc.getPointCount();
firstContour += desc.getContourCount();
}
- } while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
-
- // Are there hinting intructions to read?
- if ((comp.getFlags() & GlyfCompositeComp.WE_HAVE_INSTRUCTIONS) != 0) {
- readInstructions(bais, (bais.read()<<8 | bais.read()));
}
+ resolved = true;
+ beingResolved = false;
}
public int getEndPtOfContours(int i) {
@@ -109,17 +134,25 @@
}
public int getPointCount() {
- GlyfCompositeComp c = (GlyfCompositeComp) components.elementAt(components.size()-1);
+ if (!resolved)
+ System.err.println("getPointCount called on unresolved GlyfCompositeDescript");
+
+ GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size()-1);
+ // System.err.println("C: " + c + " Idx: " + c.getGlyphIndex());
+ // System.err.println("Ptbl: " + parentTable);
return c.getFirstIndex() + parentTable.getDescription(c.getGlyphIndex()).getPointCount();
}
public int getContourCount() {
- GlyfCompositeComp c = (GlyfCompositeComp) components.elementAt(components.size()-1);
+ if (!resolved)
+ System.err.println("getContourCount called on unresolved GlyfCompositeDescript");
+
+ GlyfCompositeComp c = (GlyfCompositeComp) components.get(components.size()-1);
return c.getFirstContour() + parentTable.getDescription(c.getGlyphIndex()).getContourCount();
}
public int getComponentIndex(int i) {
- return ((GlyfCompositeComp)components.elementAt(i)).getFirstIndex();
+ return ((GlyfCompositeComp)components.get(i)).getFirstIndex();
}
public int getComponentCount() {
@@ -129,7 +162,7 @@
protected GlyfCompositeComp getCompositeComp(int i) {
GlyfCompositeComp c;
for (int n = 0; n < components.size(); n++) {
- c = (GlyfCompositeComp) components.elementAt(n);
+ c = (GlyfCompositeComp) components.get(n);
GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) {
return c;
@@ -141,7 +174,7 @@
protected GlyfCompositeComp getCompositeCompEndPt(int i) {
GlyfCompositeComp c;
for (int j = 0; j < components.size(); j++) {
- c = (GlyfCompositeComp) components.elementAt(j);
+ c = (GlyfCompositeComp) components.get(j);
GlyphDescription gd = parentTable.getDescription(c.getGlyphIndex());
if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) {
return c;
Modified: xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfDescript.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfDescript.java?rev=289842&r1=289841&r2=289842&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfDescript.java (original)
+++ xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfDescript.java Sat Sep 17 12:23:19 2005
@@ -49,6 +49,9 @@
yMax = (short)(bais.read()<<8 | bais.read());
}
+ public void resolve() {
+ }
+
public int getNumberOfContours() {
return numberOfContours;
}
Modified: xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfTable.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfTable.java?rev=289842&r1=289841&r2=289842&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfTable.java (original)
+++ xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/GlyfTable.java Sat Sep 17 12:23:19 2005
@@ -73,31 +73,26 @@
descript = new GlyfDescript[numGlyphs];
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
for (int i = 0; i < numGlyphs; i++) {
- int len = loca.getOffset((short)(i + 1)) - loca.getOffset(i);
+ int len = loca.getOffset((i + 1)) - loca.getOffset(i);
if (len > 0) {
bais.reset();
bais.skip(loca.getOffset(i));
short numberOfContours = (short)(bais.read()<<8 | bais.read());
if (numberOfContours >= 0) {
descript[i] = new GlyfSimpleDescript(this, numberOfContours, bais);
+ } else {
+ descript[i] = new GlyfCompositeDescript(this, bais);
}
- } else {
- descript[i] = null;
}
}
+ buf = null;
+
for (int i = 0; i < numGlyphs; i++) {
- int len = loca.getOffset((short)(i + 1)) - loca.getOffset(i);
- if (len > 0) {
- bais.reset();
- bais.skip(loca.getOffset(i));
- short numberOfContours = (short)(bais.read()<<8 | bais.read());
- if (numberOfContours < 0) {
- descript[i] = new GlyfCompositeDescript(this, bais);
- }
- }
+ if (descript[i] == null) continue;
+
+ descript[i].resolve();
}
- buf = null;
}
public GlyfDescript getDescription(int i) {
Modified: xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/HheaTable.java
URL: http://svn.apache.org/viewcvs/xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/HheaTable.java?rev=289842&r1=289841&r2=289842&view=diff
==============================================================================
--- xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/HheaTable.java (original)
+++ xmlgraphics/batik/branches/svg11/sources/org/apache/batik/svggen/font/table/HheaTable.java Sat Sep 17 12:23:19 2005
@@ -37,7 +37,7 @@
private short caretSlopeRise;
private short caretSlopeRun;
private short metricDataFormat;
- private short numberOfHMetrics;
+ private int numberOfHMetrics;
protected HheaTable(DirectoryEntry de,RandomAccessFile raf) throws IOException {
raf.seek(de.getOffset());
@@ -55,7 +55,7 @@
raf.readShort();
}
metricDataFormat = raf.readShort();
- numberOfHMetrics = raf.readShort();
+ numberOfHMetrics = raf.readUnsignedShort();
}
public short getAdvanceWidthMax() {
@@ -94,7 +94,7 @@
return minRightSideBearing;
}
- public short getNumberOfHMetrics() {
+ public int getNumberOfHMetrics() {
return numberOfHMetrics;
}