diff options
author | David Schweinsberg <[email protected]> | 2016-03-29 13:05:21 -0700 |
---|---|---|
committer | David Schweinsberg <[email protected]> | 2016-03-29 13:05:21 -0700 |
commit | d3f008a1071af02e26153a367b203b30f2ac35fc (patch) | |
tree | a1dea41d737a411ffb66a9f66c2aeb38ce092279 | |
parent | 27cf086d6d9255374494b3d662df1eed38a38f57 (diff) |
Additional logging around font suitcases
-rw-r--r-- | src/net/java/dev/typecast/ot/OTFont.java | 11 | ||||
-rw-r--r-- | src/net/java/dev/typecast/ot/OTFontCollection.java | 21 | ||||
-rw-r--r-- | src/net/java/dev/typecast/ot/table/LocaTable.java | 20 |
3 files changed, 46 insertions, 6 deletions
diff --git a/src/net/java/dev/typecast/ot/OTFont.java b/src/net/java/dev/typecast/ot/OTFont.java index 95e75a4..7179aba 100644 --- a/src/net/java/dev/typecast/ot/OTFont.java +++ b/src/net/java/dev/typecast/ot/OTFont.java @@ -69,6 +69,8 @@ import net.java.dev.typecast.ot.table.Table; import net.java.dev.typecast.ot.table.TableDirectory; import net.java.dev.typecast.ot.table.TableFactory; import net.java.dev.typecast.ot.table.VheaTable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The TrueType font. @@ -92,6 +94,8 @@ public class OTFont { private PostTable _post; private VheaTable _vhea; + static final Logger logger = LoggerFactory.getLogger(OTFont.class); + /** * Constructor */ @@ -251,7 +255,12 @@ public class OTFont { } dis.reset(); dis.skip(tablesOrigin + entry.getOffset()); - _tables[index] = TableFactory.create(_fc, this, entry, dis); + try { + _tables[index] = TableFactory.create(_fc, this, entry, dis); + } catch (IOException e) { + logger.error("Exception loading Directory Entry {}", entry); + throw e; + } ++index; } diff --git a/src/net/java/dev/typecast/ot/OTFontCollection.java b/src/net/java/dev/typecast/ot/OTFontCollection.java index f0ed2c3..bc13302 100644 --- a/src/net/java/dev/typecast/ot/OTFontCollection.java +++ b/src/net/java/dev/typecast/ot/OTFontCollection.java @@ -18,21 +18,21 @@ package net.java.dev.typecast.ot; -import java.io.File; import java.io.BufferedInputStream; import java.io.DataInputStream; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; - import java.util.ArrayList; - import net.java.dev.typecast.ot.mac.ResourceHeader; import net.java.dev.typecast.ot.mac.ResourceMap; import net.java.dev.typecast.ot.mac.ResourceReference; import net.java.dev.typecast.ot.mac.ResourceType; import net.java.dev.typecast.ot.table.DirectoryEntry; -import net.java.dev.typecast.ot.table.Table; import net.java.dev.typecast.ot.table.TTCHeader; +import net.java.dev.typecast.ot.table.Table; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @@ -47,6 +47,8 @@ public class OTFontCollection { private ArrayList<Table> _tables = new ArrayList<Table>(); private boolean _resourceFork = false; + static final Logger logger = LoggerFactory.getLogger(OTFontCollection.class); + /** Creates new FontCollection */ protected OTFontCollection() { } @@ -131,6 +133,17 @@ public class OTFontCollection { dis.skip(resourceHeader.getMapOffset()); ResourceMap map = new ResourceMap(dis); + // Dump some info about the font suitcase + for (int i = 0; i < map.getResourceTypeCount(); ++i) { + logger.info(map.getResourceType(i).getTypeAsString()); + } + + ResourceType type = map.getResourceType("FOND"); + for (int i = 0; i < type.getCount(); ++i) { + ResourceReference reference = type.getReference(i); + logger.info(reference.getName()); + } + // Get the 'sfnt' resources ResourceType resourceType = map.getResourceType("sfnt"); diff --git a/src/net/java/dev/typecast/ot/table/LocaTable.java b/src/net/java/dev/typecast/ot/table/LocaTable.java index fecf005..34ba93f 100644 --- a/src/net/java/dev/typecast/ot/table/LocaTable.java +++ b/src/net/java/dev/typecast/ot/table/LocaTable.java @@ -10,6 +10,8 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author <a href="mailto:[email protected]">David Schweinsberg</a> @@ -20,6 +22,8 @@ public class LocaTable implements Table { private int[] _offsets = null; private short _factor = 0; + static final Logger logger = LoggerFactory.getLogger(LocaTable.class); + protected LocaTable( DirectoryEntry de, DataInput di, @@ -39,6 +43,17 @@ public class LocaTable implements Table { _offsets[i] = di.readInt(); } } + + // Check the validity of the offsets + int lastOffset = 0; + int index = 0; + for (int offset : _offsets) { + if (offset < lastOffset) { + logger.error("Offset at index {} is bad ({} < {})", index, offset, lastOffset); + } + lastOffset = offset; + ++index; + } } public int getOffset(int i) { @@ -48,12 +63,14 @@ public class LocaTable implements Table { return _offsets[i] * _factor; } + @Override public int getType() { return loca; } + @Override public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("'loca' Table - Index To Location Table\n--------------------------------------\n") .append("Size = ").append(_de.getLength()).append(" bytes, ") .append(_offsets.length).append(" entries\n"); @@ -70,6 +87,7 @@ public class LocaTable implements Table { * particular table. * @return A directory entry */ + @Override public DirectoryEntry getDirectoryEntry() { return _de; } |