diff options
author | Bernhard Haumacher <[email protected]> | 2020-05-09 12:49:39 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-02 19:21:49 +0100 |
commit | 43c20bb2e7644aef7002caeb93e1770be5cacaab (patch) | |
tree | 805bd400835dd7b58baa2c78b316a97916d0bc89 | |
parent | 8543225f7ce9a5ff16cd1f4aea74fe9ec24c2354 (diff) |
Documentation for `HeadTable`
* Added documentation to fields in `HeadTable` taken from
https://docs.microsoft.com/en-us/typography/opentype/spec/head.
* Added `LongDateTime` conversion of date values encoded as "seconds
since 1904".
* Added `getType()` API to `Table` interface.
# Conflicts:
# src/main/java/net/java/dev/typecast/ot/table/HdmxTable.java
# src/main/java/net/java/dev/typecast/ot/table/HeadTable.java
# src/main/java/net/java/dev/typecast/ot/table/LocaTable.java
# src/main/java/net/java/dev/typecast/ot/table/SbixTable.java
33 files changed, 511 insertions, 55 deletions
diff --git a/src/main/java/net/java/dev/typecast/ot/Fixed.java b/src/main/java/net/java/dev/typecast/ot/Fixed.java index 043df24..8d4803d 100644 --- a/src/main/java/net/java/dev/typecast/ot/Fixed.java +++ b/src/main/java/net/java/dev/typecast/ot/Fixed.java @@ -838,6 +838,9 @@ public class Fixed { return n; } + /** + * Converts a 32-bit signed fixed-point number (16.16) to <code>float</code>. + */ public static float floatValue(long fixed) { return (fixed >> 16) + (float)(fixed & 0xffff) / 0x10000; } diff --git a/src/main/java/net/java/dev/typecast/ot/LongDateTime.java b/src/main/java/net/java/dev/typecast/ot/LongDateTime.java new file mode 100644 index 0000000..4529394 --- /dev/null +++ b/src/main/java/net/java/dev/typecast/ot/LongDateTime.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020 Business Operation Systems GmbH. All Rights Reserved. + */ +package net.java.dev.typecast.ot; + +import java.time.ZoneId; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; + +/** + * Utility to convert number of seconds since 12:00 midnight that started + * January 1st 1904 in GMT/UTC time zone to a {@link Date} value. + * + * @author <a href="mailto:[email protected]">Bernhard Haumacher</a> + */ +public class LongDateTime { + + private static final long BASE; + + static { + GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone(ZoneId.of("UTC"))); + calendar.set(Calendar.YEAR, 1904); + calendar.set(Calendar.MONTH, Calendar.JANUARY); + calendar.set(Calendar.DAY_OF_MONTH, 1); + calendar.set(Calendar.HOUR, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + + BASE = calendar.getTimeInMillis(); + } + + /** + * Converts a {@link LongDateTime} value to a {@link Date}. + */ + public static Date toDate(long longDateTime) { + return new Date(toSystemMillis(longDateTime)); + } + + /** + * Converts a {@link LongDateTime} value to a Java system millis value compatible + * with {@link System#currentTimeMillis()}. + */ + public static long toSystemMillis(long longDateTime) { + return BASE + 1000L * longDateTime; + } + + /** + * Converts a {@link Date} to a {@link LongDateTime} value. + */ + public static long fromDate(Date date) { + return fromSystemMillis(date.getTime()); + } + + /** + * Converts a Java system millis value compatible + * with {@link System#currentTimeMillis()} to a {@link LongDateTime} value. + */ + public static long fromSystemMillis(long systemMillis) { + return (systemMillis - BASE) / 1000L; + } + +} diff --git a/src/main/java/net/java/dev/typecast/ot/table/BaseTable.java b/src/main/java/net/java/dev/typecast/ot/table/BaseTable.java index f092698..506a34f 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/BaseTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/BaseTable.java @@ -27,7 +27,7 @@ import java.io.IOException; * Baseline Table * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ -public class BaseTable implements Table { +public abstract class BaseTable implements Table { private abstract static class BaseCoord { diff --git a/src/main/java/net/java/dev/typecast/ot/table/CffTable.java b/src/main/java/net/java/dev/typecast/ot/table/CffTable.java index 86162cc..0037e5a 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/CffTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/CffTable.java @@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream; import java.io.DataInput; import java.io.DataInputStream; import java.io.IOException; + import net.java.dev.typecast.cff.CffFont; import net.java.dev.typecast.cff.Index; import net.java.dev.typecast.cff.NameIndex; @@ -102,6 +103,11 @@ public class CffTable implements Table { _buf, offset, _buf.length - offset)); } + + @Override + public int getType() { + return CFF; + } public NameIndex getNameIndex() { return _nameIndex; diff --git a/src/main/java/net/java/dev/typecast/ot/table/CmapTable.java b/src/main/java/net/java/dev/typecast/ot/table/CmapTable.java index fe0597f..e5bd3c1 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/CmapTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/CmapTable.java @@ -52,7 +52,6 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; - import java.util.Arrays; /** @@ -103,6 +102,11 @@ public class CmapTable implements Table { } } + @Override + public int getType() { + return cmap; + } + public int getVersion() { return _version; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/ColrTable.java b/src/main/java/net/java/dev/typecast/ot/table/ColrTable.java index 54ef89a..6c193af 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/ColrTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/ColrTable.java @@ -104,6 +104,11 @@ class ColrTable implements Table { } @Override + public int getType() { + return COLR; + } + + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("'COLR' Table\n------------\nBase Glyph Records\n"); diff --git a/src/main/java/net/java/dev/typecast/ot/table/CpalTable.java b/src/main/java/net/java/dev/typecast/ot/table/CpalTable.java index e71e5fa..4362420 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/CpalTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/CpalTable.java @@ -103,6 +103,11 @@ class CpalTable implements Table { } } + @Override + public int getType() { + return CPAL; + } + public int getNumPalettesEntries() { return _numPalettesEntries; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/CvtTable.java b/src/main/java/net/java/dev/typecast/ot/table/CvtTable.java index a205617..03b2519 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/CvtTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/CvtTable.java @@ -26,6 +26,11 @@ class CvtTable implements Table { } } + @Override + public int getType() { + return cvt; + } + public short[] getValues() { return values; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/DsigTable.java b/src/main/java/net/java/dev/typecast/ot/table/DsigTable.java index 853332b..f9ec449 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/DsigTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/DsigTable.java @@ -8,8 +8,8 @@ package net.java.dev.typecast.ot.table; -import java.io.IOException; import java.io.DataInput; +import java.io.IOException; /** * @@ -38,6 +38,11 @@ class DsigTable implements Table { } } + @Override + public int getType() { + return DSIG; + } + public String toString() { StringBuilder sb = new StringBuilder().append("DSIG\n"); for (int i = 0; i < numSigs; i++) { diff --git a/src/main/java/net/java/dev/typecast/ot/table/FpgmTable.java b/src/main/java/net/java/dev/typecast/ot/table/FpgmTable.java index e5bf788..95a1abb 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/FpgmTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/FpgmTable.java @@ -10,6 +10,7 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; + import net.java.dev.typecast.ot.Disassembler; /** @@ -21,6 +22,11 @@ class FpgmTable extends Program implements Table { readInstructions(di, length); } + @Override + public int getType() { + return fpgm; + } + public String toString() { return Disassembler.disassemble(getInstructions(), 0); } diff --git a/src/main/java/net/java/dev/typecast/ot/table/GaspTable.java b/src/main/java/net/java/dev/typecast/ot/table/GaspTable.java index 9dbf642..cf5e008 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/GaspTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/GaspTable.java @@ -31,6 +31,11 @@ public class GaspTable implements Table { } } + @Override + public int getType() { + return gasp; + } + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("'gasp' Table - Grid-fitting And Scan-conversion Procedure\n---------------------------------------------------------"); diff --git a/src/main/java/net/java/dev/typecast/ot/table/GdefTable.java b/src/main/java/net/java/dev/typecast/ot/table/GdefTable.java index 9e243f6..34353c0 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/GdefTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/GdefTable.java @@ -12,4 +12,9 @@ class GdefTable implements Table { protected GdefTable(DataInput di) throws IOException { } + @Override + public int getType() { + return GDEF; + } + } diff --git a/src/main/java/net/java/dev/typecast/ot/table/GlyfTable.java b/src/main/java/net/java/dev/typecast/ot/table/GlyfTable.java index 791dfa0..884b30d 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/GlyfTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/GlyfTable.java @@ -105,6 +105,11 @@ public class GlyfTable implements Table { } } + @Override + public int getType() { + return glyf; + } + public GlyfDescript getDescription(int i) { if (i < _descript.length) { return _descript[i]; diff --git a/src/main/java/net/java/dev/typecast/ot/table/GposTable.java b/src/main/java/net/java/dev/typecast/ot/table/GposTable.java index b49b0a0..e8e5cf5 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/GposTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/GposTable.java @@ -36,6 +36,11 @@ class GposTable implements Table { int lookupList = di.readInt(); } + @Override + public int getType() { + return GPOS; + } + public String toString() { return "GPOS"; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/GsubTable.java b/src/main/java/net/java/dev/typecast/ot/table/GsubTable.java index 50e6b20..ca2b2b6 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/GsubTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/GsubTable.java @@ -124,6 +124,11 @@ public class GsubTable implements Table, LookupSubtableFactory { return s; } + @Override + public int getType() { + return GSUB; + } + public ScriptList getScriptList() { return _scriptList; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/HdmxTable.java b/src/main/java/net/java/dev/typecast/ot/table/HdmxTable.java index dd3bd4f..1e7fcc1 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/HdmxTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/HdmxTable.java @@ -88,6 +88,10 @@ public class HdmxTable implements Table { } @Override + public int getType() { + return hdmx; + } + public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("'hdmx' Table - Horizontal Device Metrics\n----------------------------------------\n"); diff --git a/src/main/java/net/java/dev/typecast/ot/table/HeadTable.java b/src/main/java/net/java/dev/typecast/ot/table/HeadTable.java index d0e1760..b088c33 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/HeadTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/HeadTable.java @@ -54,31 +54,69 @@ import java.io.DataInput; import java.io.IOException; import net.java.dev.typecast.ot.Fixed; +import net.java.dev.typecast.ot.LongDateTime; /** + * Font Header Table + * + * This table gives global information about the font. The bounding box values + * ({@link #getXMin()}, {@link #getXMax()}, {@link #getYMin()}, + * {@link #getYMax()}) should be computed using only glyphs that have contours. + * Glyphs with no contours should be ignored for the purposes of these + * calculations. + * * @author <a href="mailto:[email protected]">David Schweinsberg</a> */ public class HeadTable implements Table { - - private final int _versionNumber; - private final int _fontRevision; - private final int _checkSumAdjustment; - private final int _magicNumber; - private final short _flags; - private final int _unitsPerEm; - private final long _created; - private final long _modified; - private final short _xMin; - private final short _yMin; - private final short _xMax; - private final short _yMax; - private final short _macStyle; - private final short _lowestRecPPEM; - private final short _fontDirectionHint; - private final short _indexToLocFormat; - private final short _glyphDataFormat; - - public HeadTable(final DataInput di) throws IOException { + + /** + * @see #getMagicNumber() + */ + public static final int MAGIC = 0x5F0F3CF5; + + /** + * @see #getGlyphDataFormat() + */ + public static final short GLYPH_DATA_FORMAT = 0; + + private int _versionNumber; + + private int _fontRevision; + + private int _checkSumAdjustment; + + private int _magicNumber = MAGIC; + + private short _flags; + + private short _unitsPerEm; + + private long _created; + + private long _modified; + + private short _xMin; + + private short _yMin; + + private short _xMax; + + private short _yMax; + + private short _macStyle; + + private short _lowestRecPPEM; + + private short _fontDirectionHint; + + private short _indexToLocFormat; + + private short _glyphDataFormat = GLYPH_DATA_FORMAT; + + /** + * Creates a {@link HeadTable} from binary encoding. + */ + public HeadTable(DataInput di) throws IOException { _versionNumber = di.readInt(); _fontRevision = di.readInt(); _checkSumAdjustment = di.readInt(); @@ -98,8 +136,17 @@ public class HeadTable implements Table { _glyphDataFormat = di.readShort(); } - public int getCheckSumAdjustment() { - return _checkSumAdjustment; + @Override + public int getType() { + return head; + } + + /** + * uint16 majorVersion Major version number of the font header table — set to 1. + * uint16 minorVersion Minor version number of the font header table — set to 0. + */ + public int getVersionNumber() { + return _versionNumber; } public long getCreated() { @@ -110,60 +157,251 @@ public class HeadTable implements Table { return _flags; } - public short getFontDirectionHint() { - return _fontDirectionHint; - } - + /** + * Fixed Set by font manufacturer. + * + * For historical reasons, the fontRevision value contained in this table is + * not used by Windows to determine the version of a font. Instead, Windows + * evaluates the version string (ID 5) in the 'name' table. + */ public int getFontRevision(){ return _fontRevision; } - public short getGlyphDataFormat() { - return _glyphDataFormat; + /** + * uint32 + * + * To compute: set it to 0, sum the entire font as uint32, then store + * 0xB1B0AFBA - sum. + * + * If the font is used as a component in a font collection file, the value + * of this field will be invalidated by changes to the file structure and + * font table directory, and must be ignored. + */ + public int getCheckSumAdjustment() { + return _checkSumAdjustment; + } + + /** + * uint32 Set to {@link #MAGIC}. + */ + public int getMagicNumber() { + return _magicNumber; } - public short getIndexToLocFormat() { - return _indexToLocFormat; + /** + * uint16 + * + * Bit 0: Baseline for font at y=0; + * + * Bit 1: Left sidebearing point at x=0 (relevant only for TrueType + * rasterizers) — see the note below regarding variable fonts; + * + * Bit 2: Instructions may depend on point size; + * + * Bit 3: Force ppem to integer values for all internal scaler math; may use + * fractional ppem sizes if this bit is clear; + * + * Bit 4: Instructions may alter advance width (the advance widths might not + * scale linearly); + * + * Bit 5: This bit is not used in OpenType, and should not be set in order + * to ensure compatible behavior on all platforms. If set, it may result in + * different behavior for vertical layout in some platforms. (See Apple’s + * specification for details regarding behavior in Apple platforms.) + * + * Bits 6–10: These bits are not used in Opentype and should always be + * cleared. (See Apple’s specification for details regarding legacy used in + * Apple platforms.) + * + * Bit 11: Font data is “lossless” as a result of having been subjected to + * optimizing transformation and/or compression (such as e.g. compression + * mechanisms defined by ISO/IEC 14496-18, MicroType Express, WOFF 2.0 or + * similar) where the original font functionality and features are retained + * but the binary compatibility between input and output font files is not + * guaranteed. As a result of the applied transform, the DSIG table may also + * be invalidated. + * + * Bit 12: Font converted (produce compatible metrics) + * + * Bit 13: Font optimized for ClearType™. Note, fonts that rely on embedded + * bitmaps (EBDT) for rendering should not be considered optimized for + * ClearType, and therefore should keep this bit cleared. + * + * Bit 14: Last Resort font. If set, indicates that the glyphs encoded in + * the 'cmap' subtables are simply generic symbolic representations of code + * point ranges and don’t truly represent support for those code points. If + * unset, indicates that the glyphs encoded in the 'cmap' subtables + * represent proper support for those code points. + * + * Bit 15: Reserved, set to 0 + * + * Note that, in a variable font with TrueType outlines, the left side + * bearing for each glyph must equal {@link #_xMin}, and bit 1 in the flags + * field must be set. + * + * Also, bit 5 must be cleared in all variable fonts. For + * general information on OpenType Font Variations, see the chapter, + * OpenType Font Variations Overview. + */ + public short getFlags() { + return _flags; } - public short getLowestRecPPEM() { - return _lowestRecPPEM; + /** + * uint16 + * + * Set to a value from 16 to 16384. Any value in this range is valid. In + * fonts that have TrueType outlines, a power of 2 is recommended as this + * allows performance optimizations in some rasterizers. + */ + public short getUnitsPerEm() { + return _unitsPerEm; } - public short getMacStyle() { - return _macStyle; + /** + * LONGDATETIME + * + * Number of seconds since 12:00 midnight that started January 1st 1904 in + * GMT/UTC time zone. 64-bit integer + */ + public long getCreated() { + return _created; } + /** + * LONGDATETIME + * + * Number of seconds since 12:00 midnight that started January 1st 1904 in + * GMT/UTC time zone. 64-bit integer + */ public long getModified() { return _modified; } - public int getType() { - return head; - } - - public int getUnitsPerEm() { - return _unitsPerEm; + /** + * int16 + * + * For all glyph bounding boxes. + */ + public short getXMin() { + return _xMin; } - public int getVersionNumber() { - return _versionNumber; + /** + * int16 + * + * For all glyph bounding boxes. + */ + public short getYMin() { + return _yMin; } + /** + * int16 + * + * For all glyph bounding boxes. + */ public short getXMax() { return _xMax; } - public short getXMin() { - return _xMin; - } - + /** + * int16 + * + * For all glyph bounding boxes. + */ public short getYMax() { return _yMax; } - public short getYMin() { - return _yMin; + /** + * uint16 + * + * Bit 0: Bold (if set to 1); + * + * Bit 1: Italic (if set to 1) + * + * Bit 2: Underline (if set to 1) + * + * Bit 3: Outline (if set to 1) + * + * Bit 4: Shadow (if set to 1) + * + * Bit 5: Condensed (if set to 1) + * + * Bit 6: Extended (if set to 1) + * + * Bits 7–15: Reserved (set to 0). + * + * Note that the macStyle bits must agree with the OS/2 table fsSelection + * bits. The fsSelection bits are used over the macStyle bits in Microsoft + * Windows. The PANOSE values and 'post' table values are ignored for + * determining bold or italic fonts. + */ + public short getMacStyle() { + return _macStyle; + } + + /** + * uint16 + * + * Smallest readable size in pixels. + */ + public short getLowestRecPPEM() { + return _lowestRecPPEM; + } + + /** + * int16 + * + * Deprecated (Set to 2). + * + * 0: Fully mixed directional glyphs; + * + * 1: Only strongly left to right; + * + * 2: Like 1 but also contains neutrals; + * + * -1: Only strongly right to left; + * + * -2: Like -1 but also contains neutrals. + * + * (A neutral character has no inherent directionality; it is not a + * character with zero (0) width. Spaces and punctuation are examples of + * neutral characters. Non-neutral characters are those with inherent + * directionality. For example, Roman letters (left-to-right) and Arabic + * letters (right-to-left) have directionality. In a “normal” Roman font + * where spaces and punctuation are present, the font direction hints should + * be set to two (2).) + */ + public short getFontDirectionHint() { + return _fontDirectionHint; + } + + /** + * int16 + * + * 0 for short offsets (Offset16), 1 for long (Offset32). + */ + public short getIndexToLocFormat() { + return _indexToLocFormat; + } + + /** + * Whether short offsets (Offset16) are used. + */ + public boolean useShortEntries() { + return getIndexToLocFormat() == 0; + } + + /** + * int16 + * + * {@link #GLYPH_DATA_FORMAT} for current format. + */ + public short getGlyphDataFormat() { + return _glyphDataFormat; } @Override @@ -175,8 +413,8 @@ public class HeadTable implements Table { "\n magicNumber: 0x" + Integer.toHexString(_magicNumber).toUpperCase() + "\n flags: 0x" + Integer.toHexString(_flags).toUpperCase() + "\n unitsPerEm: " + _unitsPerEm + - "\n created: " + _created + - "\n modified: " + _modified + + "\n created: " + LongDateTime.toDate(_created) + + "\n modified: " + LongDateTime.toDate(_modified) + "\n xMin: " + _xMin + "\n yMin: " + _yMin + "\n xMax: " + _xMax + diff --git a/src/main/java/net/java/dev/typecast/ot/table/HheaTable.java b/src/main/java/net/java/dev/typecast/ot/table/HheaTable.java index 946353e..1df8adc 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/HheaTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/HheaTable.java @@ -10,6 +10,7 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; + import net.java.dev.typecast.ot.Fixed; /** @@ -48,6 +49,11 @@ public class HheaTable implements Table { numberOfHMetrics = di.readUnsignedShort(); } + @Override + public int getType() { + return hhea; + } + public short getAdvanceWidthMax() { return advanceWidthMax; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/HmtxTable.java b/src/main/java/net/java/dev/typecast/ot/table/HmtxTable.java index bb50656..00dd214 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/HmtxTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/HmtxTable.java @@ -83,6 +83,11 @@ public class HmtxTable implements Table { _length = length; } + @Override + public int getType() { + return hmtx; + } + public int getAdvanceWidth(int i) { if (_hMetrics == null) { return 0; diff --git a/src/main/java/net/java/dev/typecast/ot/table/KernTable.java b/src/main/java/net/java/dev/typecast/ot/table/KernTable.java index 99709e4..8caccc8 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/KernTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/KernTable.java @@ -37,6 +37,11 @@ public class KernTable implements Table { table0 = _table0; } + @Override + public int getType() { + return kern; + } + public int getSubtableCount() { return nTables; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/LocaTable.java b/src/main/java/net/java/dev/typecast/ot/table/LocaTable.java index 2041ac7..0ae1fae 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/LocaTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/LocaTable.java @@ -26,7 +26,8 @@ public class LocaTable implements Table { HeadTable head, MaxpTable maxp) throws IOException { _offsets = new int[maxp.getNumGlyphs() + 1]; - boolean shortEntries = head.getIndexToLocFormat() == 0; + boolean shortEntries = head.useShortEntries(); + // FIXME boolean shortEntries = head.getIndexToLocFormat() == 0; if (shortEntries) { _factor = 2; for (int i = 0; i <= maxp.getNumGlyphs(); i++) { @@ -51,6 +52,11 @@ public class LocaTable implements Table { } _length = length; } + + @Override + public int getType() { + return loca; + } public int getOffset(int i) { if (_offsets == null) { diff --git a/src/main/java/net/java/dev/typecast/ot/table/LtshTable.java b/src/main/java/net/java/dev/typecast/ot/table/LtshTable.java index c09a10d..d2340f6 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/LtshTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/LtshTable.java @@ -31,6 +31,11 @@ class LtshTable implements Table { } } + @Override + public int getType() { + return LTSH; + } + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("'LTSH' Table - Linear Threshold Table\n-------------------------------------") diff --git a/src/main/java/net/java/dev/typecast/ot/table/MaxpTable.java b/src/main/java/net/java/dev/typecast/ot/table/MaxpTable.java index f23cf4d..96ac560 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/MaxpTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/MaxpTable.java @@ -10,6 +10,7 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; + import net.java.dev.typecast.ot.Fixed; /** @@ -57,6 +58,11 @@ public class MaxpTable implements Table { } } + @Override + public int getType() { + return maxp; + } + public int getVersionNumber() { return versionNumber; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/NameTable.java b/src/main/java/net/java/dev/typecast/ot/table/NameTable.java index 6630493..2d239b7 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/NameTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/NameTable.java @@ -50,9 +50,9 @@ package net.java.dev.typecast.ot.table; +import java.io.ByteArrayInputStream; import java.io.DataInput; import java.io.DataInputStream; -import java.io.ByteArrayInputStream; import java.io.IOException; /** @@ -93,6 +93,11 @@ public class NameTable implements Table { } } + @Override + public int getType() { + return name; + } + public short getNumberOfNameRecords() { return _numberOfNameRecords; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/Os2Table.java b/src/main/java/net/java/dev/typecast/ot/table/Os2Table.java index 8d3a8a1..408c7e1 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/Os2Table.java +++ b/src/main/java/net/java/dev/typecast/ot/table/Os2Table.java @@ -142,6 +142,11 @@ public class Os2Table implements Table { } } + @Override + public int getType() { + return OS_2; + } + public int getVersion() { return _version; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/PcltTable.java b/src/main/java/net/java/dev/typecast/ot/table/PcltTable.java index 04e76c9..69c6733 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/PcltTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/PcltTable.java @@ -58,6 +58,11 @@ class PcltTable implements Table { reserved = di.readByte(); } + @Override + public int getType() { + return PCLT; + } + public String toString() { return "'PCLT' Table - Printer Command Language Table\n---------------------------------------------" + "\n version: 0x" + Integer.toHexString(version).toUpperCase() + diff --git a/src/main/java/net/java/dev/typecast/ot/table/PostTable.java b/src/main/java/net/java/dev/typecast/ot/table/PostTable.java index 2b013ee..33bc6dd 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/PostTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/PostTable.java @@ -10,6 +10,7 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; + import net.java.dev.typecast.ot.Fixed; /** @@ -328,6 +329,11 @@ public class PostTable implements Table { } } + @Override + public int getType() { + return post; + } + public int getVersion() { return version; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/PrepTable.java b/src/main/java/net/java/dev/typecast/ot/table/PrepTable.java index 1792c34..0027a8b 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/PrepTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/PrepTable.java @@ -10,6 +10,7 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; + import net.java.dev.typecast.ot.Disassembler; /** @@ -21,6 +22,11 @@ class PrepTable extends Program implements Table { readInstructions(di, length); } + @Override + public int getType() { + return prep; + } + public String toString() { return Disassembler.disassemble(getInstructions(), 0); } diff --git a/src/main/java/net/java/dev/typecast/ot/table/SbixTable.java b/src/main/java/net/java/dev/typecast/ot/table/SbixTable.java index 68d9cb5..8168d53 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/SbixTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/SbixTable.java @@ -144,6 +144,11 @@ public class SbixTable implements Table { buf.length - offset); } + @Override + public int getType() { + return sbix; + } + public Strike[] getStrikes() { return _strikes; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/Table.java b/src/main/java/net/java/dev/typecast/ot/table/Table.java index 6afae80..cfa2a46 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/Table.java +++ b/src/main/java/net/java/dev/typecast/ot/table/Table.java @@ -61,4 +61,8 @@ public interface Table { static final int vhea = 0x76686561; // Vertical Metrics header static final int vmtx = 0x766d7478; // Vertical Metrics + /** + * The type code of this {@link Table}. + */ + int getType(); } diff --git a/src/main/java/net/java/dev/typecast/ot/table/VdmxTable.java b/src/main/java/net/java/dev/typecast/ot/table/VdmxTable.java index 2336645..1961b78 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/VdmxTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/VdmxTable.java @@ -143,6 +143,11 @@ public class VdmxTable implements Table { } } + @Override + public int getType() { + return VDMX; + } + public String toString() { StringBuilder sb = new StringBuilder(); sb.append("'VDMX' Table - Precomputed Vertical Device Metrics\n") diff --git a/src/main/java/net/java/dev/typecast/ot/table/VheaTable.java b/src/main/java/net/java/dev/typecast/ot/table/VheaTable.java index 57a0169..7f772f0 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/VheaTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/VheaTable.java @@ -20,6 +20,7 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; + import net.java.dev.typecast.ot.Fixed; /** @@ -59,6 +60,11 @@ public class VheaTable implements Table { _numberOfLongVerMetrics = di.readUnsignedShort(); } + @Override + public int getType() { + return vhea; + } + public short getAdvanceHeightMax() { return _advanceHeightMax; } diff --git a/src/main/java/net/java/dev/typecast/ot/table/VmtxTable.java b/src/main/java/net/java/dev/typecast/ot/table/VmtxTable.java index f7d4fc9..e3f8922 100644 --- a/src/main/java/net/java/dev/typecast/ot/table/VmtxTable.java +++ b/src/main/java/net/java/dev/typecast/ot/table/VmtxTable.java @@ -49,6 +49,11 @@ class VmtxTable implements Table { } } + @Override + public int getType() { + return vmtx; + } + private int getAdvanceHeight(int i) { if (_vMetrics == null) { return 0; |