diff options
author | Bernhard Haumacher <[email protected]> | 2020-05-10 12:41:31 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-02 20:53:58 +0100 |
commit | effede5f4299823cbc47e5cd92e571e0d2f92587 (patch) | |
tree | 21fc842c0861f3a1e5c595df9038c764c51ee2f5 | |
parent | ff0b0fb0ea7f6360a468e2db702022d5e0f19b55 (diff) |
Added offset table as member to the font.
* Include the offset table in the font's dump.
* Simplified reading since the offset table now does not be read twice.
# Conflicts:
# src/main/java/net/java/dev/typecast/ot/OTFont.java
# src/main/java/net/java/dev/typecast/ot/TTFont.java
3 files changed, 36 insertions, 16 deletions
diff --git a/src/main/java/net/java/dev/typecast/ot/OTFont.java b/src/main/java/net/java/dev/typecast/ot/OTFont.java index d9b45b6..970a336 100644 --- a/src/main/java/net/java/dev/typecast/ot/OTFont.java +++ b/src/main/java/net/java/dev/typecast/ot/OTFont.java @@ -58,11 +58,16 @@ public abstract class OTFont { private final GsubTable _gsub; /** - * * @param dis input stream marked at start with read-ahead set to known stream length - * @param tableDirectory - * @param tablesOrigin - * @throws IOException + * @param directoryOffset The Table Directory offset within the file. For a + * regular TTF/OTF file this will be zero, but for a TTC (Font Collection) + * the offset is retrieved from the TTC header. For a Mac font resource, + * offset is retrieved from the resource headers. + * @param tablesOrigin The point the table offsets are calculated from. + * Once again, in a regular TTF file, this will be zero. In a TTC is is + * also zero, but within a Mac resource, it is the beginning of the + * individual font resource data. + * @throws java.io.IOException */ OTFont(final DataInputStream dis, TableDirectory tableDirectory, final int tablesOrigin) throws IOException { // Load some prerequisite tables @@ -103,6 +108,13 @@ public abstract class OTFont { _gsub = null; // FIXME: delete? } + + /** + * {@link TableDirectory} with all font tables. + */ + public TableDirectory getTableDirectory() { + return _tableDirectory; + } public Os2Table getOS2Table() { return _os2; @@ -200,6 +212,9 @@ public abstract class OTFont { * Dumps information of all tables to the given {@link Writer}. */ public void dumpTo(Writer out) throws IOException { + out.write(getTableDirectory().toString()); + out.write("\n"); + dump(out, getHeadTable()); dump(out, getOS2Table()); dump(out, getCmapTable()); diff --git a/src/main/java/net/java/dev/typecast/ot/TTFont.java b/src/main/java/net/java/dev/typecast/ot/TTFont.java index 18e14fd..9f2224e 100644 --- a/src/main/java/net/java/dev/typecast/ot/TTFont.java +++ b/src/main/java/net/java/dev/typecast/ot/TTFont.java @@ -33,7 +33,6 @@ import net.java.dev.typecast.ot.table.HdmxTable; import net.java.dev.typecast.ot.table.KernTable; import net.java.dev.typecast.ot.table.LocaTable; import net.java.dev.typecast.ot.table.Table; -import net.java.dev.typecast.ot.table.TableDirectory; import net.java.dev.typecast.ot.table.VdmxTable; public class TTFont extends OTFont { @@ -119,27 +118,31 @@ public class TTFont extends OTFont { int length = seekTable(tableDirectory, dis, tablesOrigin, Table.loca); final LocaTable loca = new LocaTable(dis, length, this.getHeadTable(), this.getMaxpTable()); + // 'loca' is required by 'glyf' + int length = seekTable(dis, tablesOrigin, Table.loca); + LocaTable loca = new LocaTable(dis, length, this.getHeadTable(), this.getMaxpTable()); + // If this is a TrueType outline, then we'll have at least the // 'glyf' table (along with the 'loca' table) - length = seekTable(tableDirectory, dis, tablesOrigin, Table.glyf); + length = seekTable(dis, tablesOrigin, Table.glyf); _glyf = new GlyfTable(dis, length, this.getMaxpTable(), loca); - length = seekTable(tableDirectory, dis, tablesOrigin, Table.gasp); + length = seekTable(dis, tablesOrigin, Table.gasp); if (length > 0) { _gasp = new GaspTable(dis); } - length = seekTable(tableDirectory, dis, tablesOrigin, Table.kern); + length = seekTable(dis, tablesOrigin, Table.kern); if (length > 0) { _kern = new KernTable(dis); } - length = seekTable(tableDirectory, dis, tablesOrigin, Table.hdmx); + length = seekTable(dis, tablesOrigin, Table.hdmx); if (length > 0) { _hdmx = new HdmxTable(dis, length, this.getMaxpTable()); } - length = seekTable(tableDirectory, dis, tablesOrigin, Table.VDMX); + length = seekTable(dis, tablesOrigin, Table.VDMX); if (length > 0) { _vdmx = new VdmxTable(dis); } diff --git a/src/main/java/net/java/dev/typecast/ot/table/TableDirectory.java b/src/main/java/net/java/dev/typecast/ot/table/TableDirectory.java index dbdf8fb..3bdba9a 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/TableDirectory.java +++ b/src/main/java/net/java/dev/typecast/ot/table/TableDirectory.java @@ -52,7 +52,9 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; + import net.java.dev.typecast.ot.Fixed; +import net.java.dev.typecast.ot.Fmt; /** * @author <a href="mailto:[email protected]">David Schweinsberg</a> @@ -161,14 +163,14 @@ public class TableDirectory { public String toString() { final StringBuilder sb = new StringBuilder() .append("Offset Table\n------ -----") - .append("\n sfnt version: ").append(Fixed.floatValue(_version)) - .append("\n numTables = ").append(_numTables) - .append("\n searchRange = ").append(_searchRange) - .append("\n entrySelector = ").append(_entrySelector) - .append("\n rangeShift = ").append(_rangeShift) + .append("\n sfnt version: ").append(Fixed.floatValue(_version)) + .append("\n numTables: ").append(_numTables) + .append("\n searchRange: ").append(_searchRange) + .append("\n entrySelector: ").append(_entrySelector) + .append("\n rangeShift: ").append(_rangeShift) .append("\n\n"); for (int i = 0; i < _numTables; i++) { - sb.append(i).append(". ").append(_entries[i].toString()).append("\n"); + sb.append(" ").append(Fmt.pad(2, i)).append(": ").append(_entries[i].toString()).append("\n"); } return sb.toString(); } |