Emit a warning message for .otf files, which are not supported yet

This commit is contained in:
David Kuettel
2013-04-19 16:24:19 -07:00
parent 0cffdd1e74
commit ade3f14974
@@ -3,6 +3,9 @@ package com.google.typography.font.compression;
import com.google.common.io.Files; import com.google.common.io.Files;
import com.google.typography.font.sfntly.Font; import com.google.typography.font.sfntly.Font;
import com.google.typography.font.sfntly.FontFactory; import com.google.typography.font.sfntly.FontFactory;
import com.google.typography.font.sfntly.Tag;
import com.google.typography.font.sfntly.table.truetype.GlyphTable;
import com.google.typography.font.sfntly.table.truetype.LocaTable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -41,6 +44,11 @@ public class SimpleRunner {
byte[] bytes = Files.toByteArray(file); byte[] bytes = Files.toByteArray(file);
Font font = FONT_FACTORY.loadFonts(bytes)[0]; Font font = FONT_FACTORY.loadFonts(bytes)[0];
if (!isTrueType(font)) {
System.err.printf("WARNING: unable to compress: %s (not a TrueType font)\n", filename);
continue;
}
byte[] gzip = Experiment.run(font, GZIP); byte[] gzip = Experiment.run(font, GZIP);
byte[] woff2 = Experiment.run(font, WOFF2); byte[] woff2 = Experiment.run(font, WOFF2);
@@ -58,6 +66,12 @@ public class SimpleRunner {
} }
} }
private static boolean isTrueType(Font font) {
LocaTable loca = font.getTable(Tag.loca);
GlyphTable glyf = font.getTable(Tag.glyf);
return (loca != null && glyf != null);
}
private static void usage() { private static void usage() {
System.err.println("Usage: SimpleRunner font..."); System.err.println("Usage: SimpleRunner font...");
System.exit(-1); System.exit(-1);