From 2cdfc4a83644c13674f393db36719e44ae7d024c Mon Sep 17 00:00:00 2001 From: batzorent Date: Thu, 22 Aug 2019 17:15:40 +0800 Subject: [PATCH] #18 refact: eliminated generic warnings --- .../converter/PsType0ToOpenTypeConverter.java | 5 ++-- .../converter/WoffToOtfConverter.java | 3 +- .../fontverter/opentype/OpenTypeFont.java | 28 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/mabb/fontverter/converter/PsType0ToOpenTypeConverter.java b/src/main/java/org/mabb/fontverter/converter/PsType0ToOpenTypeConverter.java index 905e750..35ef5a2 100644 --- a/src/main/java/org/mabb/fontverter/converter/PsType0ToOpenTypeConverter.java +++ b/src/main/java/org/mabb/fontverter/converter/PsType0ToOpenTypeConverter.java @@ -28,6 +28,7 @@ import org.mabb.fontverter.opentype.OpenTypeFont; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -36,7 +37,7 @@ public class PsType0ToOpenTypeConverter { private OpenTypeFont otfFont; private PDType0Font type0Font; - public FVFont convert(PDType0Font type0Font) throws IOException, IllegalAccessException, InstantiationException { + public FVFont convert(PDType0Font type0Font) throws IOException, IllegalAccessException, InstantiationException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { this.type0Font = type0Font; PDCIDFont descendantFont = type0Font.getDescendantFont(); @@ -56,7 +57,7 @@ public FVFont convert(PDType0Font type0Font) throws IOException, IllegalAccessEx return otfFont; } - private OpenTypeFont getOtfFromDescendantFont(PDCIDFont descendantFont) throws IOException, InstantiationException, IllegalAccessException { + private OpenTypeFont getOtfFromDescendantFont(PDCIDFont descendantFont) throws IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { if (isTtfDescendant()) { byte[] ttfData = type0Font.getFontDescriptor().getFontFile2().toByteArray(); OpenTypeParser otfParser = new OpenTypeParser(); diff --git a/src/main/java/org/mabb/fontverter/converter/WoffToOtfConverter.java b/src/main/java/org/mabb/fontverter/converter/WoffToOtfConverter.java index 6ba7f8c..857f2c1 100644 --- a/src/main/java/org/mabb/fontverter/converter/WoffToOtfConverter.java +++ b/src/main/java/org/mabb/fontverter/converter/WoffToOtfConverter.java @@ -25,6 +25,7 @@ import org.mabb.fontverter.woff.WoffTable; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; public class WoffToOtfConverter implements FontConverter { OpenTypeFont otfFont; @@ -44,7 +45,7 @@ public FVFont convertFont(FVFont font) throws IOException { return otfFont; } - private void readTables() throws IOException, InstantiationException, IllegalAccessException { + private void readTables() throws IOException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { for (WoffTable tableOn : woffFont.getTables()) { OpenTypeTable.OtfTableRecord record = new OpenTypeTable.OtfTableRecord(); diff --git a/src/main/java/org/mabb/fontverter/opentype/OpenTypeFont.java b/src/main/java/org/mabb/fontverter/opentype/OpenTypeFont.java index 8b3e184..79b462e 100644 --- a/src/main/java/org/mabb/fontverter/opentype/OpenTypeFont.java +++ b/src/main/java/org/mabb/fontverter/opentype/OpenTypeFont.java @@ -22,8 +22,6 @@ import org.mabb.fontverter.converter.*; import org.mabb.fontverter.io.FontDataOutputStream; import org.mabb.fontverter.validator.RuleValidator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -41,9 +39,9 @@ * Apple TrueType spec can be found here: https://developer.apple.com/fonts/TrueType-Reference-Manual */ public class OpenTypeFont implements FVFont { + SfntHeader sfntHeader; private List tables; - private static Logger log = LoggerFactory.getLogger(OpenTypeFont.class); private File sourceFile; public static OpenTypeFont createBlankFont() throws IOException { @@ -149,7 +147,6 @@ public void normalize() throws IOException { } private void createNewOS2WinMetricsTable() { - HorizontalHeadTable hhea = getHhea(); OS2WinMetricsTable table = OS2WinMetricsTable.createDefaultTable(); setOs2(table); } @@ -248,18 +245,18 @@ else if (getPost() != null) } private byte[] getRawData() throws IOException { - FontDataOutputStream out = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET); - sfntHeader.setNumTables(tables.size()); + try (FontDataOutputStream out = new FontDataOutputStream(FontDataOutputStream.OPEN_TYPE_CHARSET)) { + sfntHeader.setNumTables(tables.size()); + out.write(sfntHeader.getData()); - out.write(sfntHeader.getData()); + for (OpenTypeTable tableOn : tables) + out.write(tableOn.getRecordData()); - for (OpenTypeTable tableOn : tables) - out.write(tableOn.getRecordData()); - - for (OpenTypeTable tableOn : tables) - out.write(tableOn.getData()); + for (OpenTypeTable tableOn : tables) + out.write(tableOn.getData()); - return out.toByteArray(); + return out.toByteArray(); + } } private void calculateOffsets(List tables) throws IOException { @@ -311,7 +308,7 @@ public void setSourceFile(File sourceFile) { this.sourceFile = sourceFile; } - public void removeTable(Class toRemoveType) { + public void removeTable(Class toRemoveType) { OpenTypeTable toRemoveTable = null; for (OpenTypeTable tableOn : tables) { if (tableOn.getClass() == toRemoveType) @@ -322,7 +319,8 @@ public void removeTable(Class toRemoveType) { tables.remove(toRemoveTable); } - private T findTableType(Class type) { + @SuppressWarnings("unchecked") + private T findTableType(Class type) { for (OpenTypeTable tableOn : tables) { if (tableOn.getClass() == type) return (T) tableOn;