diff options
author | David Schweinsberg <[email protected]> | 2019-09-13 14:41:19 -0700 |
---|---|---|
committer | David Schweinsberg <[email protected]> | 2019-09-13 14:41:19 -0700 |
commit | 974c0c58947ef06873fe30bb9e6a58ebe08b9dc5 (patch) | |
tree | 313e3c6625c7cee812ce588c1f6c87279daf7e7c | |
parent | 193329eafc1a14214e15297b4b1b56d9bbb9ecbb (diff) |
Start decoupling tables, fonts, and font collections
35 files changed, 493 insertions, 935 deletions
diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..b26911b --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Encoding"> + <file url="file://$PROJECT_DIR$" charset="UTF-8" /> + </component> +</project>
\ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="Palette2"> + <group name="Swing"> + <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> + </item> + <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> + <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> + <initial-values> + <property name="text" value="Button" /> + </initial-values> + </item> + <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="RadioButton" /> + </initial-values> + </item> + <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="CheckBox" /> + </initial-values> + </item> + <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> + <initial-values> + <property name="text" value="Label" /> + </initial-values> + </item> + <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> + <preferred-size width="150" height="-1" /> + </default-constraints> + </item> + <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> + <preferred-size width="150" height="50" /> + </default-constraints> + </item> + <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> + <preferred-size width="200" height="200" /> + </default-constraints> + </item> + <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> + </item> + <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> + </item> + <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> + <preferred-size width="-1" height="20" /> + </default-constraints> + </item> + <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> + <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> + </item> + <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> + <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> + </item> + </group> + </component> +</project>
\ No newline at end of file diff --git a/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java b/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java index 9dcda51..c5c276b 100644 --- a/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java +++ b/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java @@ -348,66 +348,66 @@ public class SVGExporter throw new TableException("Cannot find a suitable cmap table"); } - // If this font includes arabic script, we want to specify substitutions - // for initial, medial, terminal & isolated cases. - GsubTable gsub = (GsubTable) font.getTable(Table.GSUB); - SingleSubst initialSubst = null; - SingleSubst medialSubst = null; - SingleSubst terminalSubst = null; - if (gsub != null && gsub.getScriptList() != null) { - Script s = gsub.getScriptList().findScript(SCRIPT_TAG_ARAB); - if (s != null) { - LangSys ls = s.getDefaultLangSys(); - if (ls != null) { - Feature init = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_INIT); - Feature medi = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_MEDI); - Feature fina = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_FINA); - - initialSubst = (SingleSubst) - gsub.getLookupList().getLookup(init, 0).getSubtable(0); - medialSubst = (SingleSubst) - gsub.getLookupList().getLookup(medi, 0).getSubtable(0); - terminalSubst = (SingleSubst) - gsub.getLookupList().getLookup(fina, 0).getSubtable(0); - } - } - } - - // Include the missing glyph - ps.println(getGlyphAsSVG(font, font.getGlyph(0), 0, horiz_advance_x, - initialSubst, medialSubst, terminalSubst, "")); - - try { - // Include our requested range - for (int i = first; i <= last; i++) { - int glyphIndex = cmapFmt.mapCharCode(i); - - if (glyphIndex > 0) { - ps.println(getGlyphAsSVG( - font, - font.getGlyph(glyphIndex), - glyphIndex, - horiz_advance_x, - initialSubst, medialSubst, terminalSubst, - (32 <= i && i <= 127) ? - encodeEntities("" + (char) i) : - XML_CHAR_REF_PREFIX + Integer.toHexString(i) + XML_CHAR_REF_SUFFIX)); - } - - } - - // Output kerning pairs from the requested range - KernTable kern = (KernTable) font.getTable(Table.kern); - if (kern != null) { - KernSubtable kst = kern.getSubtable(0); - PostTable post = (PostTable) font.getTable(Table.post); - for (int i = 0; i < kst.getKerningPairCount(); i++) { - ps.println(getKerningPairAsSVG(kst.getKerningPair(i), post)); - } - } - } catch (Exception e) { - System.err.println(e.getMessage()); - } +// // If this font includes arabic script, we want to specify substitutions +// // for initial, medial, terminal & isolated cases. +// GsubTable gsub = (GsubTable) font.getTable(Table.GSUB); +// SingleSubst initialSubst = null; +// SingleSubst medialSubst = null; +// SingleSubst terminalSubst = null; +// if (gsub != null && gsub.getScriptList() != null) { +// Script s = gsub.getScriptList().findScript(SCRIPT_TAG_ARAB); +// if (s != null) { +// LangSys ls = s.getDefaultLangSys(); +// if (ls != null) { +// Feature init = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_INIT); +// Feature medi = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_MEDI); +// Feature fina = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_FINA); +// +// initialSubst = (SingleSubst) +// gsub.getLookupList().getLookup(init, 0).getSubtable(0); +// medialSubst = (SingleSubst) +// gsub.getLookupList().getLookup(medi, 0).getSubtable(0); +// terminalSubst = (SingleSubst) +// gsub.getLookupList().getLookup(fina, 0).getSubtable(0); +// } +// } +// } +// +// // Include the missing glyph +// ps.println(getGlyphAsSVG(font, font.getGlyph(0), 0, horiz_advance_x, +// initialSubst, medialSubst, terminalSubst, "")); +// +// try { +// // Include our requested range +// for (int i = first; i <= last; i++) { +// int glyphIndex = cmapFmt.mapCharCode(i); +// +// if (glyphIndex > 0) { +// ps.println(getGlyphAsSVG( +// font, +// font.getGlyph(glyphIndex), +// glyphIndex, +// horiz_advance_x, +// initialSubst, medialSubst, terminalSubst, +// (32 <= i && i <= 127) ? +// encodeEntities("" + (char) i) : +// XML_CHAR_REF_PREFIX + Integer.toHexString(i) + XML_CHAR_REF_SUFFIX)); +// } +// +// } +// +// // Output kerning pairs from the requested range +// KernTable kern = (KernTable) font.getTable(Table.kern); +// if (kern != null) { +// KernSubtable kst = kern.getSubtable(0); +// PostTable post = (PostTable) font.getTable(Table.post); +// for (int i = 0; i < kst.getKerningPairCount(); i++) { +// ps.println(getKerningPairAsSVG(kst.getKerningPair(i), post)); +// } +// } +// } catch (Exception e) { +// System.err.println(e.getMessage()); +// } ps.print(XML_CLOSE_TAG_START); ps.print(SVG_FONT_TAG); @@ -486,75 +486,75 @@ public class SVGExporter String code) { StringBuilder sb = new StringBuilder(); - boolean substituted = false; - - // arabic = "initial | medial | terminal | isolated" - int arabInitGlyphIndex = glyphIndex; - int arabMediGlyphIndex = glyphIndex; - int arabTermGlyphIndex = glyphIndex; - if (arabInitSubst != null) { - arabInitGlyphIndex = arabInitSubst.substitute(glyphIndex); - } - if (arabMediSubst != null) { - arabMediGlyphIndex = arabMediSubst.substitute(glyphIndex); - } - if (arabTermSubst != null) { - arabTermGlyphIndex = arabTermSubst.substitute(glyphIndex); - } - - if (arabInitGlyphIndex != glyphIndex) { - sb.append(getGlyphAsSVG( - font, - font.getGlyph(arabInitGlyphIndex), - arabInitGlyphIndex, - defaultHorizAdvanceX, - SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_INITIAL_VALUE + XML_CHAR_QUOT, - code)); - sb.append(EOL); - substituted = true; - } - - if (arabMediGlyphIndex != glyphIndex) { - sb.append(getGlyphAsSVG( - font, - font.getGlyph(arabMediGlyphIndex), - arabMediGlyphIndex, - defaultHorizAdvanceX, - SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_MEDIAL_VALUE + XML_CHAR_QUOT, - code)); - sb.append(EOL); - substituted = true; - } - - if (arabTermGlyphIndex != glyphIndex) { - sb.append(getGlyphAsSVG( - font, - font.getGlyph(arabTermGlyphIndex), - arabTermGlyphIndex, - defaultHorizAdvanceX, - SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_TERMINAL_VALUE + XML_CHAR_QUOT, - code)); - sb.append(EOL); - substituted = true; - } - - if (substituted) { - sb.append(getGlyphAsSVG( - font, - glyph, - glyphIndex, - defaultHorizAdvanceX, - SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_ISOLATED_VALUE + XML_CHAR_QUOT, - code)); - } else { - sb.append(getGlyphAsSVG( - font, - glyph, - glyphIndex, - defaultHorizAdvanceX, - null, - code)); - } +// boolean substituted = false; +// +// // arabic = "initial | medial | terminal | isolated" +// int arabInitGlyphIndex = glyphIndex; +// int arabMediGlyphIndex = glyphIndex; +// int arabTermGlyphIndex = glyphIndex; +// if (arabInitSubst != null) { +// arabInitGlyphIndex = arabInitSubst.substitute(glyphIndex); +// } +// if (arabMediSubst != null) { +// arabMediGlyphIndex = arabMediSubst.substitute(glyphIndex); +// } +// if (arabTermSubst != null) { +// arabTermGlyphIndex = arabTermSubst.substitute(glyphIndex); +// } +// +// if (arabInitGlyphIndex != glyphIndex) { +// sb.append(getGlyphAsSVG( +// font, +// font.getGlyph(arabInitGlyphIndex), +// arabInitGlyphIndex, +// defaultHorizAdvanceX, +// SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_INITIAL_VALUE + XML_CHAR_QUOT, +// code)); +// sb.append(EOL); +// substituted = true; +// } +// +// if (arabMediGlyphIndex != glyphIndex) { +// sb.append(getGlyphAsSVG( +// font, +// font.getGlyph(arabMediGlyphIndex), +// arabMediGlyphIndex, +// defaultHorizAdvanceX, +// SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_MEDIAL_VALUE + XML_CHAR_QUOT, +// code)); +// sb.append(EOL); +// substituted = true; +// } +// +// if (arabTermGlyphIndex != glyphIndex) { +// sb.append(getGlyphAsSVG( +// font, +// font.getGlyph(arabTermGlyphIndex), +// arabTermGlyphIndex, +// defaultHorizAdvanceX, +// SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_TERMINAL_VALUE + XML_CHAR_QUOT, +// code)); +// sb.append(EOL); +// substituted = true; +// } +// +// if (substituted) { +// sb.append(getGlyphAsSVG( +// font, +// glyph, +// glyphIndex, +// defaultHorizAdvanceX, +// SVG_ARABIC_FORM_ATTRIBUTE + XML_EQUAL_QUOT + SVG_ISOLATED_VALUE + XML_CHAR_QUOT, +// code)); +// } else { +// sb.append(getGlyphAsSVG( +// font, +// glyph, +// glyphIndex, +// defaultHorizAdvanceX, +// null, +// code)); +// } return sb.toString(); } 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 7179aba..c23aa8f 100644 --- a/src/main/java/net/java/dev/typecast/ot/OTFont.java +++ b/src/main/java/net/java/dev/typecast/ot/OTFont.java @@ -52,22 +52,18 @@ package net.java.dev.typecast.ot; import java.io.DataInputStream; import java.io.IOException; -import net.java.dev.typecast.cff.CharstringType2; -import net.java.dev.typecast.ot.table.CffTable; + import net.java.dev.typecast.ot.table.CmapTable; import net.java.dev.typecast.ot.table.DirectoryEntry; -import net.java.dev.typecast.ot.table.GlyfTable; import net.java.dev.typecast.ot.table.HeadTable; import net.java.dev.typecast.ot.table.HheaTable; import net.java.dev.typecast.ot.table.HmtxTable; -import net.java.dev.typecast.ot.table.LocaTable; import net.java.dev.typecast.ot.table.MaxpTable; import net.java.dev.typecast.ot.table.NameTable; import net.java.dev.typecast.ot.table.Os2Table; import net.java.dev.typecast.ot.table.PostTable; 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; @@ -78,17 +74,12 @@ import org.slf4j.LoggerFactory; */ public class OTFont { - private final OTFontCollection _fc; - private TableDirectory _tableDirectory = null; - private Table[] _tables; private Os2Table _os2; - private CffTable _cff; +// private CffTable _cff; private CmapTable _cmap; - private GlyfTable _glyf; private HeadTable _head; private HheaTable _hhea; private HmtxTable _hmtx; - private LocaTable _loca; private MaxpTable _maxp; private NameTable _name; private PostTable _post; @@ -97,28 +88,79 @@ public class OTFont { static final Logger logger = LoggerFactory.getLogger(OTFont.class); /** - * Constructor + * @param dis OpenType/TrueType font file data. + * @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 */ - public OTFont(OTFontCollection fc) { - _fc = fc; - } + public OTFont(DataInputStream dis, int tablesOrigin) throws IOException { - public Table getTable(int tableType) { - for (Table _table : _tables) { - if ((_table != null) && (_table.getType() == tableType)) { - return _table; - } + // Load the table directory + dis.reset(); +// dis.skip(directoryOffset); + TableDirectory tableDirectory = new TableDirectory(dis); + + // Load some prerequisite tables + // (These are tables that are referenced by other tables, so we need to load + // them first) + seekTable(tableDirectory, dis, tablesOrigin, Table.head); + _head = new HeadTable(dis); + + // 'hhea' is required by 'hmtx' + seekTable(tableDirectory, dis, tablesOrigin, Table.hhea); + _hhea = new HheaTable(dis); + + // 'maxp' is required by 'glyf', 'hmtx', 'loca', and 'vmtx' + seekTable(tableDirectory, dis, tablesOrigin, Table.maxp); + _maxp = new MaxpTable(dis); + + // 'vhea' is required by 'vmtx' + int length = seekTable(tableDirectory, dis, tablesOrigin, Table.vhea); + if (length > 0) { + _vhea = new VheaTable(dis); } - return null; + + // 'post' is required by 'glyf' + seekTable(tableDirectory, dis, tablesOrigin, Table.post); + _post = new PostTable(dis); + + // Load all the other required tables + seekTable(tableDirectory, dis, tablesOrigin, Table.cmap); + _cmap = new CmapTable(dis); + length = seekTable(tableDirectory, dis, tablesOrigin, Table.hmtx); + _hmtx = new HmtxTable(dis, length, _hhea, _maxp); + length = seekTable(tableDirectory, dis, tablesOrigin, Table.name); + _name = new NameTable(dis, length); + seekTable(tableDirectory, dis, tablesOrigin, Table.OS_2); + _os2 = new Os2Table(dis); + + // If this is a TrueType outline, then we'll have at least the + // 'glyf' table (along with the 'loca' table) +// _glyf = (GlyfTable) getTable(Table.glyf); } +// public Table getTable(int tableType) { +// for (Table _table : _tables) { +// if ((_table != null) && (_table.getType() == tableType)) { +// return _table; +// } +// } +// return null; +// } + public Os2Table getOS2Table() { return _os2; } - public CffTable getCffTable() { - return _cff; - } +// public CffTable getCffTable() { +// return _cff; +// } public CmapTable getCmapTable() { return _cmap; @@ -136,9 +178,9 @@ public class OTFont { return _hmtx; } - public LocaTable getLocaTable() { - return _loca; - } +// public LocaTable getLocaTable() { +// return _loca; +// } public MaxpTable getMaxpTable() { return _maxp; @@ -168,121 +210,44 @@ public class OTFont { return _maxp.getNumGlyphs(); } - // TODO What happens with the following when dealing with PostScript? - public Glyph getGlyph(int i) { - if (_glyf != null && _glyf.getDescription(i) != null) { - return new TTGlyph( - _glyf.getDescription(i), - _hmtx.getLeftSideBearing(i), - _hmtx.getAdvanceWidth(i)); - } else if (_cff != null && _cff.getFont(0).getCharstring(i) != null) { - return new T2Glyph( - (CharstringType2) _cff.getFont(0).getCharstring(i), - _hmtx.getLeftSideBearing(i), - _hmtx.getAdvanceWidth(i)); - } else { - return null; - } - } - - public TableDirectory getTableDirectory() { - return _tableDirectory; - } - - private Table readTable( +// // TODO What happens with the following when dealing with PostScript? +// public Glyph getGlyph(int i) { +// if (_glyf != null && _glyf.getDescription(i) != null) { +// return new TTGlyph( +// _glyf.getDescription(i), +// _hmtx.getLeftSideBearing(i), +// _hmtx.getAdvanceWidth(i)); +// } else if (_cff != null && _cff.getFont(0).getCharstring(i) != null) { +// return new T2Glyph( +// (CharstringType2) _cff.getFont(0).getCharstring(i), +// _hmtx.getLeftSideBearing(i), +// _hmtx.getAdvanceWidth(i)); +// } else { +// return null; +// } +// } + + protected int seekTable( + TableDirectory tableDirectory, DataInputStream dis, int tablesOrigin, int tag) throws IOException { dis.reset(); - DirectoryEntry entry = _tableDirectory.getEntryByTag(tag); + DirectoryEntry entry = tableDirectory.getEntryByTag(tag); if (entry == null) { - return null; + return 0; } dis.skip(tablesOrigin + entry.getOffset()); - return TableFactory.create(_fc, this, entry, dis); + return entry.getLength(); } - /** - * @param dis OpenType/TrueType font file data. - * @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 - */ - protected void read( - DataInputStream dis, - int directoryOffset, - int tablesOrigin) throws IOException { - - // Load the table directory - dis.reset(); - dis.skip(directoryOffset); - _tableDirectory = new TableDirectory(dis); - _tables = new Table[_tableDirectory.getNumTables()]; - - // Load some prerequisite tables - _head = (HeadTable) readTable(dis, tablesOrigin, Table.head); - _hhea = (HheaTable) readTable(dis, tablesOrigin, Table.hhea); - _maxp = (MaxpTable) readTable(dis, tablesOrigin, Table.maxp); - _loca = (LocaTable) readTable(dis, tablesOrigin, Table.loca); - _vhea = (VheaTable) readTable(dis, tablesOrigin, Table.vhea); - - int index = 0; - _tables[index++] = _head; - _tables[index++] = _hhea; - _tables[index++] = _maxp; - if (_loca != null) { - _tables[index++] = _loca; - } - if (_vhea != null) { - _tables[index++] = _vhea; - } - - // Load all other tables - for (int i = 0; i < _tableDirectory.getNumTables(); i++) { - DirectoryEntry entry = _tableDirectory.getEntry(i); - if (entry.getTag() == Table.head - || entry.getTag() == Table.hhea - || entry.getTag() == Table.maxp - || entry.getTag() == Table.loca - || entry.getTag() == Table.vhea) { - continue; - } - dis.reset(); - dis.skip(tablesOrigin + entry.getOffset()); - try { - _tables[index] = TableFactory.create(_fc, this, entry, dis); - } catch (IOException e) { - logger.error("Exception loading Directory Entry {}", entry); - throw e; - } - ++index; - } - - // Get references to commonly used tables (these happen to be all the - // required tables) - _cff = (CffTable) getTable(Table.CFF); - _cmap = (CmapTable) getTable(Table.cmap); - _hmtx = (HmtxTable) getTable(Table.hmtx); - _name = (NameTable) getTable(Table.name); - _os2 = (Os2Table) getTable(Table.OS_2); - _post = (PostTable) getTable(Table.post); - - // If this is a TrueType outline, then we'll have at least the - // 'glyf' table (along with the 'loca' table) - _glyf = (GlyfTable) getTable(Table.glyf); - } +// protected void read( +// DataInputStream dis, +// int directoryOffset, +// int tablesOrigin) throws IOException { +// } public String toString() { - if (_tableDirectory != null) { - return _tableDirectory.toString(); - } else { - return "Empty font"; - } + return _head.toString(); } } diff --git a/src/main/java/net/java/dev/typecast/ot/OTFontCollection.java b/src/main/java/net/java/dev/typecast/ot/OTFontCollection.java index bc13302..e18daac 100644 --- a/src/main/java/net/java/dev/typecast/ot/OTFontCollection.java +++ b/src/main/java/net/java/dev/typecast/ot/OTFontCollection.java @@ -44,7 +44,6 @@ public class OTFontCollection { private String _fileName; private TTCHeader _ttcHeader; private OTFont[] _fonts; - private ArrayList<Table> _tables = new ArrayList<Table>(); private boolean _resourceFork = false; static final Logger logger = LoggerFactory.getLogger(OTFontCollection.class); @@ -82,21 +81,6 @@ public class OTFontCollection { return _ttcHeader; } - public Table getTable(DirectoryEntry de) { - for (int i = 0; i < _tables.size(); i++) { - Table table = _tables.get(i); - if ((table.getDirectoryEntry().getTag() == de.getTag()) && - (table.getDirectoryEntry().getOffset() == de.getOffset())) { - return table; - } - } - return null; - } - - public void addTable(Table table) { - _tables.add(table); - } - /** * @param file The OpenType font file */ @@ -151,10 +135,9 @@ public class OTFontCollection { _fonts = new OTFont[resourceType.getCount()]; for (int i = 0; i < resourceType.getCount(); i++) { ResourceReference resourceReference = resourceType.getReference(i); - _fonts[i] = new OTFont(this); int offset = resourceHeader.getDataOffset() + resourceReference.getDataOffset() + 4; - _fonts[i].read(dis, offset, offset); + _fonts[i] = new TTFont(dis, offset /*, offset*/); } } else if (TTCHeader.isTTC(dis)) { @@ -164,15 +147,15 @@ public class OTFontCollection { _ttcHeader = new TTCHeader(dis); _fonts = new OTFont[_ttcHeader.getDirectoryCount()]; for (int i = 0; i < _ttcHeader.getDirectoryCount(); i++) { - _fonts[i] = new OTFont(this); - _fonts[i].read(dis, _ttcHeader.getTableDirectory(i), 0); + _fonts[i] = new TTFont(dis, _ttcHeader.getTableDirectory(i)); } } else { // This is a standalone font file _fonts = new OTFont[1]; - _fonts[0] = new OTFont(this); - _fonts[0].read(dis, 0, 0); + _fonts[0] = new TTFont(dis, 0); + + // TODO T2Fonts } dis.close(); } diff --git a/src/main/java/net/java/dev/typecast/ot/TTFont.java b/src/main/java/net/java/dev/typecast/ot/TTFont.java new file mode 100644 index 0000000..072994f --- /dev/null +++ b/src/main/java/net/java/dev/typecast/ot/TTFont.java @@ -0,0 +1,60 @@ +package net.java.dev.typecast.ot; + +import net.java.dev.typecast.ot.table.*; + +import java.io.DataInputStream; +import java.io.IOException; + +public class TTFont extends OTFont { + + private GlyfTable _glyf; + private GaspTable _gasp; + private KernTable _kern; + private HdmxTable _hdmx; + private VdmxTable _vdmx; + + /** + * Constructor + * + * @param dis + * @param tablesOrigin + */ + public TTFont(DataInputStream dis, int tablesOrigin) throws IOException { + super(dis, tablesOrigin); + + // Load the table directory + dis.reset(); +// dis.skip(directoryOffset); + TableDirectory tableDirectory = new TableDirectory(dis); + + // 'loca' is required by 'glyf' + int length = seekTable(tableDirectory, 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); + _glyf = new GlyfTable(dis, length, this.getMaxpTable(), loca); + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.gasp); + if (length > 0) { + _gasp = new GaspTable(dis); + } + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.kern); + if (length > 0) { + _kern = new KernTable(dis); + } + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.hdmx); + if (length > 0) { + _hdmx = new HdmxTable(dis, length, this.getMaxpTable()); + } + + length = seekTable(tableDirectory, dis, tablesOrigin, Table.VDMX); + if (length > 0) { + _vdmx = new VdmxTable(dis); + } + } + +} 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 3531322..a4f3e89 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 @@ -347,7 +347,6 @@ public class BaseTable implements Table { } } - private DirectoryEntry _de; private int _version; private int _horizAxisOffset; private int _vertAxisOffset; @@ -356,11 +355,10 @@ public class BaseTable implements Table { private byte[] _buf; /** Creates a new instance of BaseTable */ - protected BaseTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + protected BaseTable(DataInput di, int length) throws IOException { // Load entire table into a buffer, and create another input stream - _buf = new byte[de.getLength()]; + _buf = new byte[length]; di.readFully(_buf); DataInput di2 = getDataInputForOffset(0); @@ -381,7 +379,7 @@ public class BaseTable implements Table { private DataInput getDataInputForOffset(int offset) { return new DataInputStream(new ByteArrayInputStream( _buf, offset, - _de.getLength() - offset)); + _buf.length - offset)); } // private String valueAsShortHex(int value) { @@ -401,10 +399,6 @@ public class BaseTable implements Table { return String.valueOf(c); } - public int getType() { - return BASE; - } - public String toString() { StringBuffer sb = new StringBuffer() .append("; 'BASE' Table - Baseline\n;-------------------------------------\n\n") @@ -420,14 +414,5 @@ public class BaseTable implements Table { } return sb.toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } + } 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 a0d8436..86162cc 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 @@ -34,7 +34,6 @@ import net.java.dev.typecast.cff.TopDictIndex; */ public class CffTable implements Table { - private final DirectoryEntry _de; private final int _major; private final int _minor; private final int _hdrSize; @@ -48,14 +47,13 @@ public class CffTable implements Table { private final byte[] _buf; /** Creates a new instance of CffTable - * @param de * @param di + * @param length * @throws java.io.IOException */ - protected CffTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + protected CffTable(DataInput di, int length) throws IOException { // Load entire table into a buffer, and create another input stream - _buf = new byte[de.getLength()]; + _buf = new byte[length]; di.readFully(_buf); DataInput di2 = getDataInputForOffset(0); @@ -102,7 +100,7 @@ public class CffTable implements Table { public final DataInput getDataInputForOffset(int offset) { return new DataInputStream(new ByteArrayInputStream( _buf, offset, - _de.getLength() - offset)); + _buf.length - offset)); } public NameIndex getNameIndex() { @@ -122,11 +120,6 @@ public class CffTable implements Table { } @Override - public int getType() { - return CFF; - } - - @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("'CFF' Table - Compact Font Format\n---------------------------------\n"); @@ -144,15 +137,5 @@ public class CffTable implements Table { } return sb.toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - @Override - public DirectoryEntry getDirectoryEntry() { - return _de; - } + } 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 868222e..4d4faeb 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 @@ -60,13 +60,11 @@ import java.util.Arrays; */ public class CmapTable implements Table { - private DirectoryEntry _de; private int _version; private int _numTables; private CmapIndexEntry[] _entries; - protected CmapTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + public CmapTable(DataInput di) throws IOException { _version = di.readUnsignedShort(); _numTables = di.readUnsignedShort(); long bytesRead = 4; @@ -130,11 +128,6 @@ public class CmapTable implements Table { } @Override - public int getType() { - return cmap; - } - - @Override public String toString() { StringBuffer sb = new StringBuffer().append("cmap\n"); @@ -149,15 +142,5 @@ public class CmapTable implements Table { // } return sb.toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - @Override - public DirectoryEntry getDirectoryEntry() { - return _de; - } + } 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 45051d3..ef26e43 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 @@ -67,7 +67,6 @@ public class ColrTable implements Table { } } - private final DirectoryEntry _de; private final int _version; private final int _numBaseGlyphRecords; private final int _offsetBaseGlyphRecord; @@ -76,8 +75,7 @@ public class ColrTable implements Table { private final BaseGlyphRecord[] _baseGlyphRecords; private final LayerRecord[] _layerRecords; - protected ColrTable(DirectoryEntry de, DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); + protected ColrTable(DataInput di) throws IOException { _version = di.readUnsignedShort(); _numBaseGlyphRecords = di.readUnsignedShort(); _offsetBaseGlyphRecord = di.readInt(); @@ -121,13 +119,4 @@ public class ColrTable implements Table { return sb.toString(); } - @Override - public int getType() { - return COLR; - } - - @Override - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 9a3d384..9153274 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 @@ -54,7 +54,6 @@ public class CpalTable implements Table { } } - private final DirectoryEntry _de; private final int _version; private final int _numPalettesEntries; private final int _numPalette; @@ -66,8 +65,7 @@ public class CpalTable implements Table { private final int _offsetPaletteEntryLabelArray; private final ColorRecord[] _colorRecords; - protected CpalTable(DirectoryEntry de, DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); + protected CpalTable(DataInput di) throws IOException { _version = di.readUnsignedShort(); _numPalettesEntries = di.readUnsignedShort(); _numPalette = di.readUnsignedShort(); @@ -127,13 +125,4 @@ public class CpalTable implements Table { return sb.toString(); } - @Override - public int getType() { - return CPAL; - } - - @Override - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 b912704..32f4c47 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 @@ -17,22 +17,16 @@ import java.io.IOException; */ public class CvtTable implements Table { - private DirectoryEntry de; private short[] values; - protected CvtTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - int len = de.getLength() / 2; + protected CvtTable(DataInput di, int length) throws IOException { + int len = length / 2; values = new short[len]; for (int i = 0; i < len; i++) { values[i] = di.readShort(); } } - public int getType() { - return cvt; - } - public short[] getValues() { return values; } @@ -47,15 +41,5 @@ public class CvtTable implements Table { } return sb.toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - + } 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 56a8609..9175d7a 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 @@ -17,7 +17,6 @@ import java.io.DataInput; */ public class DsigTable implements Table { - private DirectoryEntry de; private int version; private int numSigs; private int flag; @@ -25,8 +24,7 @@ public class DsigTable implements Table { private SignatureBlock[] sigBlocks; /** Creates new DsigTable */ - protected DsigTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + protected DsigTable(DataInput di) throws IOException { version = di.readInt(); numSigs = di.readUnsignedShort(); flag = di.readUnsignedShort(); @@ -40,24 +38,6 @@ public class DsigTable implements Table { } } - /** - * Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return DSIG; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - public String toString() { StringBuffer sb = new StringBuffer().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 4c3ca59..9542668 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 @@ -17,29 +17,12 @@ import net.java.dev.typecast.ot.Disassembler; */ public class FpgmTable extends Program implements Table { - private DirectoryEntry de; - - protected FpgmTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); - readInstructions(di, de.getLength()); - } - - public int getType() { - return fpgm; + protected FpgmTable(DataInput di, int length) throws IOException { + readInstructions(di, length); } public String toString() { return Disassembler.disassemble(getInstructions(), 0); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - } 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 6c68263..d34367d 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 @@ -17,14 +17,12 @@ import java.io.IOException; */ public class GaspTable implements Table { - private DirectoryEntry de; private int version; private int numRanges; private GaspRange[] gaspRange; /** Creates new GaspTable */ - protected GaspTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public GaspTable(DataInput di) throws IOException { version = di.readUnsignedShort(); numRanges = di.readUnsignedShort(); gaspRange = new GaspRange[numRanges]; @@ -33,10 +31,6 @@ public class GaspTable implements Table { } } - public int getType() { - return gasp; - } - public String toString() { StringBuffer sb = new StringBuffer(); sb.append("'gasp' Table - Grid-fitting And Scan-conversion Procedure\n---------------------------------------------------------"); @@ -48,15 +42,5 @@ public class GaspTable implements Table { } return sb.toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - + } 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 2358aa9..0b3a65b 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 @@ -9,19 +9,7 @@ import java.io.IOException; */ public class GdefTable implements Table { - private DirectoryEntry _de; - - protected GdefTable(DirectoryEntry de, DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); - } - - @Override - public int getType() { - return GDEF; + protected GdefTable(DataInput di) throws IOException { } - @Override - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 f046c17..266bd47 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 @@ -60,19 +60,17 @@ import java.io.IOException; */ public class GlyfTable implements Table { - private DirectoryEntry _de; private GlyfDescript[] _descript; - protected GlyfTable( - DirectoryEntry de, + public GlyfTable( DataInput di, + int length, MaxpTable maxp, LocaTable loca) throws IOException { - _de = (DirectoryEntry) de.clone(); _descript = new GlyfDescript[maxp.getNumGlyphs()]; // Buffer the whole table so we can randomly access it - byte[] buf = new byte[de.getLength()]; + byte[] buf = new byte[length]; di.readFully(buf); ByteArrayInputStream bais = new ByteArrayInputStream(buf); @@ -115,17 +113,4 @@ public class GlyfTable implements Table { } } - public int getType() { - return glyf; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 7bec107..1399480 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 @@ -27,10 +27,7 @@ import java.io.IOException; */ public class GposTable implements Table { - private DirectoryEntry _de; - - protected GposTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + protected GposTable(DataInput di) throws IOException { // GPOS Header int version = di.readInt(); @@ -39,25 +36,8 @@ public class GposTable implements Table { int lookupList = di.readInt(); } - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return GPOS; - } - public String toString() { return "GPOS"; } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - } 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 81b4bbc..50e6b20 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 @@ -61,16 +61,14 @@ import java.io.IOException; */ public class GsubTable implements Table, LookupSubtableFactory { - private DirectoryEntry _de; private ScriptList _scriptList; private FeatureList _featureList; private LookupList _lookupList; - protected GsubTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); - + protected GsubTable(DataInput di, int length) throws IOException { + // Load into a temporary buffer, and create another input stream - byte[] buf = new byte[de.getLength()]; + byte[] buf = new byte[length]; di.readFully(buf); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(buf)); @@ -126,13 +124,6 @@ public class GsubTable implements Table, LookupSubtableFactory { return s; } - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return GSUB; - } - public ScriptList getScriptList() { return _scriptList; } @@ -166,15 +157,5 @@ public class GsubTable implements Table, LookupSubtableFactory { } return "Unknown"; } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - + } 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 1df5255..25e11a8 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 @@ -56,16 +56,15 @@ public class HdmxTable implements Table { } } - private DirectoryEntry _de; private int _version; private short _numRecords; private int _sizeDeviceRecords; private DeviceRecord[] _records; + private int _length; /** Creates a new instance of HdmxTable */ - protected HdmxTable(DirectoryEntry de, DataInput di, MaxpTable maxp) + public HdmxTable(DataInput di, int length, MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); _version = di.readUnsignedShort(); _numRecords = di.readShort(); _sizeDeviceRecords = di.readInt(); @@ -75,16 +74,13 @@ public class HdmxTable implements Table { for (int i = 0; i < _numRecords; ++i) { _records[i] = new DeviceRecord(maxp.getNumGlyphs(), di); } + _length = length; } - public int getType() { - return hdmx; - } - public String toString() { StringBuffer sb = new StringBuffer(); sb.append("'hdmx' Table - Horizontal Device Metrics\n----------------------------------------\n"); - sb.append("Size = ").append(_de.getLength()).append(" bytes\n") + sb.append("Size = ").append(_length).append(" bytes\n") .append("\t'hdmx' version: ").append(_version).append("\n") .append("\t# device records: ").append(_numRecords).append("\n") .append("\tRecord length: ").append(_sizeDeviceRecords).append("\n"); @@ -102,13 +98,4 @@ public class HdmxTable implements Table { return sb.toString(); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 2db1c4a..f2eddf1 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 @@ -60,7 +60,6 @@ import net.java.dev.typecast.ot.Fixed; */ public class HeadTable implements Table { - private DirectoryEntry _de; private int _versionNumber; private int _fontRevision; private int _checkSumAdjustment; @@ -79,8 +78,7 @@ public class HeadTable implements Table { private short _indexToLocFormat; private short _glyphDataFormat; - protected HeadTable(DirectoryEntry de, DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); + public HeadTable(DataInput di) throws IOException { _versionNumber = di.readInt(); _fontRevision = di.readInt(); _checkSumAdjustment = di.readInt(); @@ -190,15 +188,5 @@ public class HeadTable implements Table { .append("\n glyphDataFormat: ").append(_glyphDataFormat) .toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - + } 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 7641cc1..25f50ec 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 @@ -17,7 +17,6 @@ import net.java.dev.typecast.ot.Fixed; */ public class HheaTable implements Table { - private DirectoryEntry de; private int version; private short ascender; private short descender; @@ -31,8 +30,7 @@ public class HheaTable implements Table { private short metricDataFormat; private int numberOfHMetrics; - protected HheaTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public HheaTable(DataInput di) throws IOException { version = di.readInt(); ascender = di.readShort(); descender = di.readShort(); @@ -90,10 +88,6 @@ public class HheaTable implements Table { return numberOfHMetrics; } - public int getType() { - return hhea; - } - public short getXMaxExtent() { return xMaxExtent; } @@ -120,15 +114,5 @@ public class HheaTable implements Table { .append("\n numOf_LongHorMetrics: ").append(numberOfHMetrics) .toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - + } 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 42fdd09..8e2bdd4 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 @@ -58,16 +58,15 @@ import java.io.IOException; */ public class HmtxTable implements Table { - private DirectoryEntry _de; private int[] _hMetrics = null; private short[] _leftSideBearing = null; + private int _length; - protected HmtxTable( - DirectoryEntry de, + public HmtxTable( DataInput di, + int length, HheaTable hhea, MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); _hMetrics = new int[hhea.getNumberOfHMetrics()]; for (int i = 0; i < hhea.getNumberOfHMetrics(); ++i) { _hMetrics[i] = @@ -81,6 +80,7 @@ public class HmtxTable implements Table { for (int i = 0; i < lsbCount; ++i) { _leftSideBearing[i] = di.readShort(); } + _length = length; } public int getAdvanceWidth(int i) { @@ -105,14 +105,10 @@ public class HmtxTable implements Table { } } - public int getType() { - return hmtx; - } - public String toString() { StringBuffer sb = new StringBuffer(); sb.append("'hmtx' Table - Horizontal Metrics\n---------------------------------\n"); - sb.append("Size = ").append(_de.getLength()).append(" bytes, ") + sb.append("Size = ").append(_length).append(" bytes, ") .append(_hMetrics.length).append(" entries\n"); for (int i = 0; i < _hMetrics.length; i++) { sb.append(" ").append(i) @@ -128,13 +124,4 @@ public class HmtxTable implements Table { return sb.toString(); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 a5210ee..66d7142 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 @@ -17,14 +17,12 @@ import java.io.IOException; */ public class KernTable implements Table { - private DirectoryEntry de; private int version; private int nTables; private KernSubtable[] tables; /** Creates new KernTable */ - protected KernTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public KernTable(DataInput di) throws IOException { version = di.readUnsignedShort(); nTables = di.readUnsignedShort(); tables = new KernSubtable[nTables]; @@ -41,21 +39,4 @@ public class KernTable implements Table { return tables[i]; } - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return kern; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - } 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 34ba93f..158afff 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 @@ -18,18 +18,17 @@ import org.slf4j.LoggerFactory; */ public class LocaTable implements Table { - private DirectoryEntry _de; private int[] _offsets = null; private short _factor = 0; + private int _length; static final Logger logger = LoggerFactory.getLogger(LocaTable.class); - protected LocaTable( - DirectoryEntry de, + public LocaTable( DataInput di, + int length, HeadTable head, MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); _offsets = new int[maxp.getNumGlyphs() + 1]; boolean shortEntries = head.getIndexToLocFormat() == 0; if (shortEntries) { @@ -54,6 +53,7 @@ public class LocaTable implements Table { lastOffset = offset; ++index; } + _length = length; } public int getOffset(int i) { @@ -64,15 +64,10 @@ public class LocaTable implements Table { } @Override - public int getType() { - return loca; - } - - @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("'loca' Table - Index To Location Table\n--------------------------------------\n") - .append("Size = ").append(_de.getLength()).append(" bytes, ") + .append("Size = ").append(_length).append(" bytes, ") .append(_offsets.length).append(" entries\n"); for (int i = 0; i < _offsets.length; i++) { sb.append(" Idx ").append(i) @@ -81,14 +76,4 @@ public class LocaTable implements Table { return sb.toString(); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - @Override - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 c01a7f8..2a71a54 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 @@ -17,7 +17,6 @@ import net.java.dev.typecast.ot.Fixed; */ public class MaxpTable implements Table { - private DirectoryEntry de; private int versionNumber; private int numGlyphs; private int maxPoints; @@ -34,8 +33,7 @@ public class MaxpTable implements Table { private int maxComponentElements; private int maxComponentDepth; - protected MaxpTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public MaxpTable(DataInput di) throws IOException { versionNumber = di.readInt(); // CFF fonts use version 0.5, TrueType fonts use version 1.0 @@ -119,10 +117,6 @@ public class MaxpTable implements Table { return numGlyphs; } - public int getType() { - return maxp; - } - public String toString() { StringBuffer sb = new StringBuffer(); sb.append("'maxp' Table - Maximum Profile\n------------------------------") @@ -147,15 +141,5 @@ public class MaxpTable implements Table { } return sb.toString(); } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - + } 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 5e80e5e..6037e29 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 @@ -63,14 +63,12 @@ import java.io.IOException; */ public class NameTable implements Table { - private DirectoryEntry _de; private short _formatSelector; private short _numberOfNameRecords; private short _stringStorageOffset; private NameRecord[] _records; - protected NameTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + public NameTable(DataInput di, int length) throws IOException { _formatSelector = di.readShort(); _numberOfNameRecords = di.readShort(); _stringStorageOffset = di.readShort(); @@ -84,7 +82,7 @@ public class NameTable implements Table { // Load the string data into a buffer so the records can copy out the // bits they are interested in - byte[] buffer = new byte[_de.getLength() - _stringStorageOffset]; + byte[] buffer = new byte[length - _stringStorageOffset]; di.readFully(buffer); // Now let the records get their hands on them @@ -113,18 +111,4 @@ public class NameTable implements Table { return ""; } - public int getType() { - return name; - } - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } - } 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 09c9adf..6882994 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 @@ -59,7 +59,6 @@ import net.java.dev.typecast.ot.Fixed; */ public class Os2Table implements Table { - private DirectoryEntry _de; private int _version; private short _xAvgCharWidth; private int _usWeightClass; @@ -98,8 +97,7 @@ public class Os2Table implements Table { private int _usBreakChar; private int _usMaxContext; - protected Os2Table(DirectoryEntry de, DataInput di) throws IOException { - this._de = (DirectoryEntry) de.clone(); + public Os2Table(DataInput di) throws IOException { _version = di.readUnsignedShort(); _xAvgCharWidth = di.readShort(); _usWeightClass = di.readUnsignedShort(); @@ -293,10 +291,6 @@ public class Os2Table implements Table { return _usMaxContext; } - public int getType() { - return OS_2; - } - public String toString() { return new StringBuffer() .append("'OS/2' Table - OS/2 and Windows Metrics\n---------------------------------------") @@ -345,13 +339,4 @@ public class Os2Table implements Table { .toString(); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 c1d1fbe..7ef3e8f 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 @@ -18,9 +18,6 @@ import net.java.dev.typecast.ot.Fixed; */ public class PostTable implements Table { - /** - * TODO: Mac Glyph names for 210 & 257 - */ private static final String[] macGlyphName = { ".notdef", // 0 "null", // 1 @@ -173,15 +170,15 @@ public class PostTable implements Table { "lessequal", // 148 "greaterequal", // 149 "yen", // 150 - "mu", // 151 + "mu", // 151 "partialdiff", // 152 "summation", // 153 "product", // 154 - "pi", // 155 + "pi", // 155 "integral'", // 156 "ordfeminine", // 157 "ordmasculine", // 158 - "Omega", // 159 + "Omega", // 159 "ae", // 160 "oslash", // 161 "questiondown", // 162 @@ -232,7 +229,7 @@ public class PostTable implements Table { "Igrave", // 207 "Oacute", // 208 "Ocircumflex", // 209 - "", // 210 + "apple", // 210 "Ograve", // 211 "Uacute", // 212 "Ucircumflex", // 213 @@ -279,10 +276,9 @@ public class PostTable implements Table { "cacute", // 254 "Ccaron", // 255 "ccaron", // 256 - "" // 257 + "dcroat" // 257 }; - private DirectoryEntry de; private int version; private int italicAngle; private short underlinePosition; @@ -299,8 +295,7 @@ public class PostTable implements Table { private String[] psGlyphName; /** Creates new PostTable */ - protected PostTable(DirectoryEntry de, DataInput di) throws IOException { - this.de = (DirectoryEntry) de.clone(); + public PostTable(DataInput di) throws IOException { version = di.readInt(); italicAngle = di.readInt(); underlinePosition = di.readShort(); @@ -365,13 +360,6 @@ public class PostTable implements Table { } } - /** Get the table type, as a table directory value. - * @return The table type - */ - public int getType() { - return post; - } - public String toString() { StringBuffer sb = new StringBuffer(); sb.append("'post' Table - PostScript Metrics\n---------------------------------\n") @@ -408,14 +396,4 @@ public class PostTable implements Table { return sb.toString(); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return de; - } - } 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 3d9f5f8..988ca22 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 @@ -106,7 +106,6 @@ public class SbixTable implements Table { } } - private final DirectoryEntry _de; private final int _version; private final int _flags; private final int _numStrikes; @@ -115,11 +114,10 @@ public class SbixTable implements Table { static final Logger logger = LoggerFactory.getLogger(SbixTable.class); - protected SbixTable(DirectoryEntry de, DataInput di, MaxpTable maxp) throws IOException { - _de = (DirectoryEntry) de.clone(); + public SbixTable(DataInput di, int length, MaxpTable maxp) throws IOException { // Load entire table into a buffer, and create another input stream - byte[] buf = new byte[de.getLength()]; + byte[] buf = new byte[length]; di.readFully(buf); DataInput di2 = new DataInputStream(getByteArrayInputStreamForOffset(buf, 0)); @@ -141,20 +139,11 @@ public class SbixTable implements Table { private ByteArrayInputStream getByteArrayInputStreamForOffset(byte[] buf, int offset) { return new ByteArrayInputStream( buf, offset, - _de.getLength() - offset); + buf.length - offset); } public Strike[] getStrikes() { return _strikes; } - @Override - public int getType() { - return sbix; - } - - @Override - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 7d6319d..6972795 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,18 +61,4 @@ public interface Table { public static final int vhea = 0x76686561; // Vertical Metrics header public static final int vmtx = 0x766d7478; // Vertical Metrics - /** - * Get the table type, as a table directory value. - * @return The table type - */ - public int getType(); - - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry(); - } diff --git a/src/main/java/net/java/dev/typecast/ot/table/TableFactory.java b/src/main/java/net/java/dev/typecast/ot/table/TableFactory.java deleted file mode 100644 index 2034ce7..0000000 --- a/src/main/java/net/java/dev/typecast/ot/table/TableFactory.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Typecast - The Font Development Environment - * - * Copyright (c) 2004-2016 David Schweinsberg - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.java.dev.typecast.ot.table; - -import java.io.DataInputStream; -import java.io.IOException; -import net.java.dev.typecast.ot.OTFont; -import net.java.dev.typecast.ot.OTFontCollection; - -/** - * - * @author <a href="mailto:[email protected]">David Schweinsberg</a> - */ -public class TableFactory { - - public static Table create( - OTFontCollection fc, - OTFont font, - DirectoryEntry de, - DataInputStream dis) throws IOException { - Table t = null; - - // First, if we have a font collection, look for the table there - if (fc != null) { - t = fc.getTable(de); - if (t != null) { - return t; - } - } - - // Create the table - switch (de.getTag()) { - case Table.BASE: - t = new BaseTable(de, dis); - break; - case Table.CFF: - t = new CffTable(de, dis); - break; - case Table.COLR: - t = new ColrTable(de, dis); - break; - case Table.CPAL: - t = new CpalTable(de, dis); - break; - case Table.DSIG: - t = new DsigTable(de, dis); - break; - case Table.EBDT: - break; - case Table.EBLC: - break; - case Table.EBSC: - break; - case Table.GDEF: - t = new GdefTable(de, dis); - break; - case Table.GPOS: - t = new GposTable(de, dis); - break; - case Table.GSUB: - t = new GsubTable(de, dis); - break; - case Table.JSTF: - break; - case Table.LTSH: - t = new LtshTable(de, dis); - break; - case Table.MMFX: - break; - case Table.MMSD: - break; - case Table.OS_2: - t = new Os2Table(de, dis); - break; - case Table.PCLT: - t = new PcltTable(de, dis); - break; - case Table.VDMX: - t = new VdmxTable(de, dis); - break; - case Table.cmap: - t = new CmapTable(de, dis); - break; - case Table.cvt: - t = new CvtTable(de, dis); - break; - case Table.fpgm: - t = new FpgmTable(de, dis); - break; - case Table.fvar: - break; - case Table.gasp: - t = new GaspTable(de, dis); - break; - case Table.glyf: - t = new GlyfTable(de, dis, font.getMaxpTable(), font.getLocaTable()); - break; - case Table.hdmx: - t = new HdmxTable(de, dis, font.getMaxpTable()); - break; - case Table.head: - t = new HeadTable(de, dis); - break; - case Table.hhea: - t = new HheaTable(de, dis); - break; - case Table.hmtx: - t = new HmtxTable(de, dis, font.getHheaTable(), font.getMaxpTable()); - break; - case Table.kern: - t = new KernTable(de, dis); - break; - case Table.loca: - t = new LocaTable(de, dis, font.getHeadTable(), font.getMaxpTable()); - break; - case Table.maxp: - t = new MaxpTable(de, dis); - break; - case Table.name: - t = new NameTable(de, dis); - break; - case Table.prep: - t = new PrepTable(de, dis); - break; - case Table.post: - t = new PostTable(de, dis); - break; - case Table.sbix: - t = new SbixTable(de, dis, font.getMaxpTable()); - break; - case Table.vhea: - t = new VheaTable(de, dis); - break; - case Table.vmtx: - t = new VmtxTable(de, dis, font.getVheaTable(), font.getMaxpTable()); - break; - } - - // If we have a font collection, add this table to it - if ((fc != null) && (t != null)) { - fc.addTable(t); - } - return t; - } -} 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 fbf721c..c282423 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 @@ -117,7 +117,6 @@ public class VdmxTable implements Table { } } - private DirectoryEntry _de; private int _version; private int _numRecs; private int _numRatios; @@ -126,8 +125,7 @@ public class VdmxTable implements Table { private Group[] _groups; /** Creates a new instance of VdmxTable */ - protected VdmxTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + public VdmxTable(DataInput di) throws IOException { _version = di.readUnsignedShort(); _numRecs = di.readUnsignedShort(); _numRatios = di.readUnsignedShort(); @@ -145,10 +143,6 @@ public class VdmxTable implements Table { } } - public int getType() { - return VDMX; - } - public String toString() { StringBuffer sb = new StringBuffer(); sb.append("'VDMX' Table - Precomputed Vertical Device Metrics\n") @@ -182,13 +176,4 @@ public class VdmxTable implements Table { return sb.toString(); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } } 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 d761075..dd69a3d 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 @@ -28,7 +28,6 @@ import net.java.dev.typecast.ot.Fixed; */ public class VheaTable implements Table { - private DirectoryEntry _de; private int _version; private short _ascent; private short _descent; @@ -42,8 +41,7 @@ public class VheaTable implements Table { private short _metricDataFormat; private int _numberOfLongVerMetrics; - protected VheaTable(DirectoryEntry de, DataInput di) throws IOException { - _de = (DirectoryEntry) de.clone(); + public VheaTable(DataInput di) throws IOException { _version = di.readInt(); _ascent = di.readShort(); _descent = di.readShort(); @@ -101,10 +99,6 @@ public class VheaTable implements Table { return _numberOfLongVerMetrics; } - public int getType() { - return vhea; - } - public short getYMaxExtent() { return _yMaxExtent; } @@ -132,13 +126,4 @@ public class VheaTable implements Table { .toString(); } - /** - * Get a directory entry for this table. This uniquely identifies the - * table in collections where there may be more than one instance of a - * particular table. - * @return A directory entry - */ - public DirectoryEntry getDirectoryEntry() { - return _de; - } } diff --git a/src/test/java/net/java/dev/typecast/ot/OTFontTest.java b/src/test/java/net/java/dev/typecast/ot/TTFontTest.java index 028bf8a..1621f3e 100644 --- a/src/test/java/net/java/dev/typecast/ot/OTFontTest.java +++ b/src/test/java/net/java/dev/typecast/ot/TTFontTest.java @@ -1,23 +1,20 @@ package net.java.dev.typecast.ot; -import java.io.File; -import java.io.IOException; -import java.net.URI; +import java.io.*; import java.net.URISyntaxException; import java.net.URL; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; - import net.java.dev.typecast.ot.table.HeadTable; -public class OTFontTest extends TestCase { +public class TTFontTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ - public OTFontTest(String testName) { + public TTFontTest(String testName) { super(testName); } @@ -25,14 +22,15 @@ public class OTFontTest extends TestCase { * @return the suite of tests being tested */ public static Test suite() { - return new TestSuite(OTFontTest.class); + return new TestSuite(TTFontTest.class); } public void testLoadSingleFont() throws URISyntaxException, IOException { URL url = ClassLoader.getSystemResource("Lato-Regular.ttf"); File file = new File(url.toURI()); - OTFontCollection fontCollection = OTFontCollection.create(file); - OTFont font = fontCollection.getFont(0); + DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(file), (int)file.length())); + dis.mark((int)file.length()); + TTFont font = new TTFont(dis, 0); assertEquals(HeadTable.class, font.getHeadTable().getClass()); } } |