Skip to content

Commit

Permalink
Add new tool FontViewer for examining existing fonts.
Browse files Browse the repository at this point in the history
The goal of the FontViewer is to allow inspection of a font file, being
close to the actual representation in the file.

Only a few tables are implemented yet.
  • Loading branch information
rillig committed Oct 11, 2017
1 parent d14e6ce commit 7f0f597
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
22 changes: 15 additions & 7 deletions java/src/com/google/typography/font/tools/fontviewer/FontNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.typography.font.sfntly.Tag;
import com.google.typography.font.sfntly.table.Table;
import com.google.typography.font.sfntly.table.core.NameTable;
import com.google.typography.font.sfntly.table.opentype.GSubTable;
import com.google.typography.font.sfntly.table.truetype.GlyphTable;
import com.google.typography.font.sfntly.table.truetype.LocaTable;

Expand All @@ -30,13 +31,7 @@ private static List<AbstractNode> createTableNodes(Font font) {
List<AbstractNode> tableNodes = new ArrayList<AbstractNode>();
for (Iterator<? extends Table> it = font.iterator(); it.hasNext(); ) {
Table table = it.next();
if (table instanceof LocaTable) {
tableNodes.add(new LocaTableNode((LocaTable) table, Tag.stringValue(table.headerTag())));
} else if (table instanceof GlyphTable) {
tableNodes.add(new GlyfTableNode((GlyphTable) table, (LocaTable) font.getTable(Tag.loca)));
} else {
tableNodes.add(new SubTableNode(table, Tag.stringValue(table.headerTag())));
}
tableNodes.add(nodeFor(font, table));
}
Collections.sort(tableNodes, new Comparator<AbstractNode>() {
@Override
Expand All @@ -47,6 +42,19 @@ public int compare(AbstractNode o1, AbstractNode o2) {
return tableNodes;
}

private static AbstractNode nodeFor(Font font, Table table) {
int tag = table.headerTag();
if (tag == Tag.loca) {
return new LocaTableNode((LocaTable) table, Tag.stringValue(table.headerTag()));
} else if (tag == Tag.glyf) {
return new GlyfTableNode((GlyphTable) table, (LocaTable) font.getTable(Tag.loca));
} else if (tag == Tag.GSUB) {
return new GsubTableNode((GSubTable) table);
} else {
return new SubTableNode(table, Tag.stringValue(table.headerTag()));
}
}

@Override
public int getChildCount() {
return this.tables.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.google.typography.font.tools.fontviewer;

import com.google.typography.font.sfntly.table.opentype.GSubTable;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JTextArea;

public class GsubTableNode extends AbstractNode {

private final GSubTable gsub;
private final List<AbstractNode> children = new ArrayList<AbstractNode>();

public GsubTableNode(GSubTable gsub) {
this.gsub = gsub;
this.children.add(new SubTableNode(gsub.scriptList(), "script"));
this.children.add(new SubTableNode(gsub.featureList(), "feature"));
this.children.add(new SubTableNode(gsub.lookupList(), "lookup"));
}

@Override
protected String getNodeName() {
return "GSUB";
}

@Override
public int getChildCount() {
return children.size();
}

@Override
public AbstractNode getChildAt(int index) {
return children.get(index);
}

@Override
JComponent render() {
return new JTextArea(this.gsub.toString());
}
}

0 comments on commit 7f0f597

Please sign in to comment.