aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-02-03 00:31:42 +0100
committerSven Göthel <[email protected]>2024-02-03 00:31:42 +0100
commit601ca0e703138852c816d06fbaa151fa028ca9d3 (patch)
treef6133b9380ffce734a79db42260c07da0618b3d4
parentfd088fbb47f1d08b5cb4c2cec4d66d87c52b6b9c (diff)
Cleanup (static, final, whitespace, ..) post Hausmacher Merge
-rw-r--r--src/main/java/net/java/dev/typecast/exchange/SVGExporter.java156
-rw-r--r--src/main/java/net/java/dev/typecast/ot/Disassembler.java32
-rw-r--r--src/main/java/net/java/dev/typecast/ot/OTFont.java24
-rw-r--r--src/main/java/net/java/dev/typecast/ot/TTFont.java26
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/CmapFormat2.java78
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java60
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/GlyfDescript.java34
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/HdmxTable.java1
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/HeadTable.java212
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/HheaTable.java37
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/HmtxTable.java58
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/ID.java12
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/KernSubtable.java2
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat2.java2
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/LocaTable.java44
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/MaxpTable.java17
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/NameRecord.java35
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/NameTable.java33
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/Table.java82
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/VdmxTable.java85
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/VheaTable.java31
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/VmtxTable.java19
-rw-r--r--src/test/java/net/java/dev/typecast/ot/TTFontTest.java18
23 files changed, 552 insertions, 546 deletions
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 fcaca25..f378224 100644
--- a/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java
+++ b/src/main/java/net/java/dev/typecast/exchange/SVGExporter.java
@@ -55,15 +55,15 @@ public class SVGExporter
static {
String temp;
- try {
- temp = System.getProperty (PROPERTY_LINE_SEPARATOR,
- PROPERTY_LINE_SEPARATOR_DEFAULT);
- } catch (SecurityException e) {
+ try {
+ temp = System.getProperty (PROPERTY_LINE_SEPARATOR,
+ PROPERTY_LINE_SEPARATOR_DEFAULT);
+ } catch (final SecurityException e) {
temp = PROPERTY_LINE_SEPARATOR_DEFAULT;
}
EOL = temp;
}
-
+
private static final String QUOT_EOL = XML_CHAR_QUOT + EOL;
/**
@@ -71,25 +71,25 @@ public class SVGExporter
* {0} SVG public ID
* {1} SVG system ID
*/
- private static final String CONFIG_SVG_BEGIN =
+ private static final String CONFIG_SVG_BEGIN =
"SVGFont.config.svg.begin";
/**
* Defines the SVG start fragment that exercise the generated
* Font.
*/
- private static final String CONFIG_SVG_TEST_CARD_START =
+ private static final String CONFIG_SVG_TEST_CARD_START =
"SVGFont.config.svg.test.card.start";
/**
* Defines the end of the SVG fragment that exercise the generated
* Font.
*/
- private static final String CONFIG_SVG_TEST_CARD_END =
+ private static final String CONFIG_SVG_TEST_CARD_END =
"SVGFont.config.svg.test.card.end";
- private static String encodeEntities(String s) {
- StringBuilder sb = new StringBuilder();
+ private static String encodeEntities(final String s) {
+ final StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
switch (s.charAt(i)) {
case XML_CHAR_LT:
@@ -115,20 +115,20 @@ public class SVGExporter
return sb.toString();
}
- private static String getContourAsSVGPathData(Glyph glyph, int startIndex, int count) {
+ private static String getContourAsSVGPathData(final Glyph glyph, final int startIndex, final int count) {
// If this is a single point on it's own, we can't do anything with it
if (glyph.getPoint(startIndex).endOfContour) {
return "";
}
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
int offset = 0;
while (offset < count) {
- Point point = glyph.getPoint(startIndex + offset%count);
- Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count);
- Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count);
+ final Point point = glyph.getPoint(startIndex + offset%count);
+ final Point point_plus1 = glyph.getPoint(startIndex + (offset+1)%count);
+ final Point point_plus2 = glyph.getPoint(startIndex + (offset+2)%count);
if (offset == 0) {
sb.append(PATH_MOVE)
@@ -196,17 +196,17 @@ public class SVGExporter
return sb.toString();
}
- private static String getSVGFontFaceElement(OTFont font) {
- StringBuilder sb = new StringBuilder();
- String fontFamily = font.getNameTable().getRecordString(ID.nameFontFamilyName);
- int unitsPerEm = font.getHeadTable().getUnitsPerEm();
- String panose = font.getOS2Table().getPanose().toString();
- short ascent = font.getHheaTable().getAscender();
- short descent = font.getHheaTable().getDescender();
- int baseline = 0; // bit 0 of head.flags will indicate if this is true
+ private static String getSVGFontFaceElement(final OTFont font) {
+ final StringBuilder sb = new StringBuilder();
+ final String fontFamily = font.getNameTable().getRecordString(ID.nameFontFamilyName);
+ final int unitsPerEm = font.getHeadTable().getUnitsPerEm();
+ final String panose = font.getOS2Table().getPanose().toString();
+ final short ascent = font.getHheaTable().getAscender();
+ final short descent = font.getHheaTable().getDescender();
+ final int baseline = 0; // bit 0 of head.flags will indicate if this is true
// <!ELEMENT font-face (%descTitleMetadata;,font-face-src?,definition-src?) >
- // <!ATTLIST font-face
+ // <!ATTLIST font-face
// %stdAttrs;
// font-family CDATA #IMPLIED
// font-style CDATA #IMPLIED
@@ -241,7 +241,7 @@ public class SVGExporter
// strikethrough-thickness %Number; #IMPLIED
// overline-position %Number; #IMPLIED
// overline-thickness %Number; #IMPLIED >
-
+
sb.append(XML_OPEN_TAG_START).append(SVG_FONT_FACE_TAG).append(EOL)
.append(XML_TAB).append(SVG_FONT_FAMILY_ATTRIBUTE).append(XML_EQUAL_QUOT).append(fontFamily).append(QUOT_EOL)
.append(XML_TAB).append(SVG_UNITS_PER_EM_ATTRIBUTE).append(XML_EQUAL_QUOT).append(unitsPerEm).append(QUOT_EOL)
@@ -250,7 +250,7 @@ public class SVGExporter
.append(XML_TAB).append(SVG_DESCENT_ATTRIBUTE).append(XML_EQUAL_QUOT).append(descent).append(QUOT_EOL)
.append(XML_TAB).append(SVG_ALPHABETIC_ATTRIBUTE).append(XML_EQUAL_QUOT).append(baseline).append(XML_CHAR_QUOT)
.append(XML_OPEN_TAG_END_NO_CHILDREN).append(EOL);
-
+
return sb.toString();
}
@@ -265,9 +265,9 @@ public class SVGExporter
* @param forceAscii Force the use of the ASCII character map
* @throws net.java.dev.typecast.ot.table.TableException
*/
- private static void writeFontAsSVGFragment(PrintStream ps, TTFont font, String id, int first, int last, boolean forceAscii)
+ private static void writeFontAsSVGFragment(final PrintStream ps, final TTFont font, final String id, final int first, final int last, final boolean forceAscii)
throws TableException {
- int horiz_advance_x = font.getOS2Table().getAvgCharWidth();
+ final int horiz_advance_x = font.getOS2Table().getAvgCharWidth();
ps.print(XML_OPEN_TAG_START);
ps.print(SVG_FONT_TAG);
@@ -291,13 +291,13 @@ public class SVGExporter
// Decide upon a cmap table to use for our character to glyph look-up
CmapFormat cmapFmt;
if (forceAscii) {
-
+
// We've been asked to use the ASCII/Macintosh cmap format
cmapFmt = font.getCmapTable().getCmapFormat(
ID.platformMacintosh,
ID.encodingRoman);
} else {
-
+
// The default behaviour is to use the Unicode cmap encoding
cmapFmt = font.getCmapTable().getCmapFormat(
ID.platformMicrosoft,
@@ -316,18 +316,18 @@ public class SVGExporter
// If this font includes arabic script, we want to specify substitutions
// for initial, medial, terminal & isolated cases.
- GsubTable gsub = font.getGsubTable();
+ final GsubTable gsub = font.getGsubTable();
SingleSubst initialSubst = null;
SingleSubst medialSubst = null;
SingleSubst terminalSubst = null;
if (gsub != null && gsub.getScriptList() != null) {
- Script s = gsub.getScriptList().findScript(SCRIPT_TAG_ARAB);
+ final Script s = gsub.getScriptList().findScript(SCRIPT_TAG_ARAB);
if (s != null) {
- LangSys ls = s.getDefaultLangSys();
+ final 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);
+ final Feature init = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_INIT);
+ final Feature medi = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_MEDI);
+ final Feature fina = gsub.getFeatureList().findFeature(ls, FEATURE_TAG_FINA);
initialSubst = (SingleSubst)
gsub.getLookupList().getLookup(init, 0).getSubtable(0);
@@ -346,7 +346,7 @@ public class SVGExporter
try {
// Include our requested range
for (int i = first; i <= last; i++) {
- int glyphIndex = cmapFmt.mapCharCode(i);
+ final int glyphIndex = cmapFmt.mapCharCode(i);
if (glyphIndex > 0) {
ps.println(getGlyphAsSVG(
@@ -363,15 +363,15 @@ public class SVGExporter
}
// Output kerning pairs from the requested range
- KernTable kern = font.getKernTable();
+ final KernTable kern = font.getKernTable();
if (kern != null) {
- KernSubtable kst = kern.getSubtable(0);
- PostTable post = font.getPostTable();
+ final KernSubtable kst = kern.getSubtable(0);
+ final PostTable post = font.getPostTable();
for (int i = 0; i < kst.getKerningPairCount(); i++) {
ps.println(getKerningPairAsSVG(kst.getKerningPair(i), post));
}
}
- } catch (Exception e) {
+ } catch (final Exception e) {
System.err.println(e.getMessage());
}
@@ -381,14 +381,14 @@ public class SVGExporter
}
private static String getGlyphAsSVG(
- OTFont font,
- Glyph glyph,
- int glyphIndex,
- int defaultHorizAdvanceX,
- String attrib,
- String code) {
-
- StringBuilder sb = new StringBuilder();
+ final OTFont font,
+ final Glyph glyph,
+ final int glyphIndex,
+ final int defaultHorizAdvanceX,
+ final String attrib,
+ final String code) {
+
+ final StringBuilder sb = new StringBuilder();
int firstIndex = 0;
int count = 0;
int i;
@@ -434,7 +434,7 @@ public class SVGExporter
}
sb.append(XML_OPEN_TAG_END_NO_CHILDREN);
-
+
// Chop-up the string into 255 character lines
chopUpStringBuffer(sb);
@@ -442,16 +442,16 @@ public class SVGExporter
}
private static String getGlyphAsSVG(
- TTFont font,
- Glyph glyph,
- int glyphIndex,
- int defaultHorizAdvanceX,
- SingleSubst arabInitSubst,
- SingleSubst arabMediSubst,
- SingleSubst arabTermSubst,
- String code) {
-
- StringBuilder sb = new StringBuilder();
+ final TTFont font,
+ final Glyph glyph,
+ final int glyphIndex,
+ final int defaultHorizAdvanceX,
+ final SingleSubst arabInitSubst,
+ final SingleSubst arabMediSubst,
+ final SingleSubst arabTermSubst,
+ final String code) {
+
+ final StringBuilder sb = new StringBuilder();
boolean substituted = false;
// arabic = "initial | medial | terminal | isolated"
@@ -525,8 +525,8 @@ public class SVGExporter
return sb.toString();
}
- private static String getKerningPairAsSVG(KerningPair kp, PostTable post) {
- StringBuilder sb = new StringBuilder();
+ private static String getKerningPairAsSVG(final KerningPair kp, final PostTable post) {
+ final StringBuilder sb = new StringBuilder();
sb.append(XML_OPEN_TAG_START).append(SVG_HKERN_TAG).append(XML_SPACE);
sb.append(SVG_G1_ATTRIBUTE).append(XML_EQUAL_QUOT);
@@ -543,25 +543,25 @@ public class SVGExporter
return sb.toString();
}
- private static void writeSvgBegin(PrintStream ps) {
+ private static void writeSvgBegin(final PrintStream ps) {
ps.println(Messages.formatMessage(CONFIG_SVG_BEGIN,
new Object[]{SVG_PUBLIC_ID, SVG_SYSTEM_ID}));
-
+
}
-
- private static void writeSvgDefsBegin(PrintStream ps) {
+
+ private static void writeSvgDefsBegin(final PrintStream ps) {
ps.println(XML_OPEN_TAG_START + SVG_DEFS_TAG + XML_OPEN_TAG_END_CHILDREN);
}
- private static void writeSvgDefsEnd(PrintStream ps) {
+ private static void writeSvgDefsEnd(final PrintStream ps) {
ps.println(XML_CLOSE_TAG_START + SVG_DEFS_TAG + XML_CLOSE_TAG_END);
}
- private static void writeSvgEnd(PrintStream ps) {
+ private static void writeSvgEnd(final PrintStream ps) {
ps.println(XML_CLOSE_TAG_START + SVG_SVG_TAG + XML_CLOSE_TAG_END);
}
- private static void writeSvgTestCard(PrintStream ps, String fontFamily) {
+ private static void writeSvgTestCard(final PrintStream ps, final String fontFamily) {
ps.println(Messages.formatMessage(CONFIG_SVG_TEST_CARD_START, null));
ps.println(fontFamily);
ps.println(Messages.formatMessage(CONFIG_SVG_TEST_CARD_END, null));
@@ -570,11 +570,11 @@ public class SVGExporter
private final TTFont _font;
private final int _low;
private final int _high;
- private String _id;
+ private final String _id;
private final boolean _ascii;
private final boolean _testCard;
-
- public SVGExporter(TTFont font, int low, int high, String id, boolean ascii, boolean testCard) {
+
+ public SVGExporter(final TTFont font, final int low, final int high, final String id, final boolean ascii, final boolean testCard) {
_font = font;
_low = low;
_high = high;
@@ -589,9 +589,9 @@ public class SVGExporter
* @throws net.java.dev.typecast.ot.table.TableException
*/
@Override
- public void export(OutputStream os) throws TableException {
- PrintStream ps = new PrintStream(os);
-
+ public void export(final OutputStream os) throws TableException {
+ final PrintStream ps = new PrintStream(os);
+
// Write the various parts of the SVG file
writeSvgBegin(ps);
writeSvgDefsBegin(ps);
@@ -604,13 +604,13 @@ public class SVGExporter
_ascii);
writeSvgDefsEnd(ps);
if (_testCard) {
- String fontFamily = _font.getNameTable().getRecordString(ID.nameFontFamilyName);
+ final String fontFamily = _font.getNameTable().getRecordString(ID.nameFontFamilyName);
writeSvgTestCard(ps, fontFamily);
}
writeSvgEnd(ps);
}
- private static void chopUpStringBuffer(StringBuilder sb) {
+ private static void chopUpStringBuffer(final StringBuilder sb) {
if (sb.length() < 256) {
} else {
// Being rather simplistic about it, for now we'll insert a newline after
@@ -624,7 +624,7 @@ public class SVGExporter
}
}
- private static int midValue(int a, int b) {
+ private static int midValue(final int a, final int b) {
return a + (b - a)/2;
}
}
diff --git a/src/main/java/net/java/dev/typecast/ot/Disassembler.java b/src/main/java/net/java/dev/typecast/ot/Disassembler.java
index 23f1558..be8d246 100644
--- a/src/main/java/net/java/dev/typecast/ot/Disassembler.java
+++ b/src/main/java/net/java/dev/typecast/ot/Disassembler.java
@@ -1,9 +1,9 @@
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
+ * ------------------------------------------------------------------------- *
+ * This software is published under the terms of the Apache Software License *
+ * version 1.1, a copy of which has been included with this distribution in *
+ * the LICENSE file. *
*****************************************************************************/
package net.java.dev.typecast.ot;
@@ -21,7 +21,7 @@ public class Disassembler {
* @param ip The current instruction pointer
* @return The new instruction pointer
*/
- private static int advanceIP(short[] instructions, int ip) {
+ private static int advanceIP(final short[] instructions, int ip) {
// The high word specifies font, cvt, or glyph program
int i = ip & 0xffff;
@@ -45,8 +45,8 @@ public class Disassembler {
return ip;
}
- private static short getPushCount(short[] instructions, int ip) {
- short instr = instructions[ip & 0xffff];
+ private static short getPushCount(final short[] instructions, final int ip) {
+ final short instr = instructions[ip & 0xffff];
if ((Mnemonic.NPUSHB == instr) || (Mnemonic.NPUSHW == instr)) {
return instructions[(ip & 0xffff) + 1];
} else if ((Mnemonic.PUSHB == (instr & 0xf8)) || (Mnemonic.PUSHW == (instr & 0xf8))) {
@@ -55,11 +55,11 @@ public class Disassembler {
return 0;
}
- private static int[] getPushData(short[] instructions, int ip) {
- int count = getPushCount(instructions, ip);
- int[] data = new int[count];
- int i = ip & 0xffff;
- short instr = instructions[i];
+ private static int[] getPushData(final short[] instructions, final int ip) {
+ final int count = getPushCount(instructions, ip);
+ final int[] data = new int[count];
+ final int i = ip & 0xffff;
+ final short instr = instructions[i];
if (Mnemonic.NPUSHB == instr) {
for (int j = 0; j < count; j++) {
data[j] = instructions[i + j + 2];
@@ -80,8 +80,8 @@ public class Disassembler {
return data;
}
- public static String disassemble(short[] instructions, int leadingSpaces) {
- StringBuilder sb = new StringBuilder();
+ public static String disassemble(final short[] instructions, final int leadingSpaces) {
+ final StringBuilder sb = new StringBuilder();
int ip = 0;
while (ip < instructions.length) {
for (int i = 0; i < leadingSpaces; i++) {
@@ -90,8 +90,8 @@ public class Disassembler {
sb.append(Fmt.pad(3, ip)).append(": ");
sb.append(Mnemonic.getMnemonic(instructions[ip]));
if (getPushCount(instructions, ip) > 0) {
- int[] data = getPushData(instructions, ip);
- for (int datum : data) {
+ final int[] data = getPushData(instructions, ip);
+ for (final int datum : data) {
if ((instructions[ip] == Mnemonic.PUSHW) ||
(instructions[ip] == Mnemonic.NPUSHW)) {
sb.append(" ").append((short) datum);
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 241bf55..9cfc0ec 100644
--- a/src/main/java/net/java/dev/typecast/ot/OTFont.java
+++ b/src/main/java/net/java/dev/typecast/ot/OTFont.java
@@ -70,9 +70,9 @@ public abstract class OTFont {
* individual font resource data.
* @throws java.io.IOException
*/
- OTFont(final DataInputStream dis, TableDirectory tableDirectory, final int tablesOrigin) throws IOException {
+ OTFont(final DataInputStream dis, final TableDirectory tableDirectory, final int tablesOrigin) throws IOException {
_tableDirectory = tableDirectory;
-
+
// Load some prerequisite tables
// (These are tables that are referenced by other tables, so we need to load
// them first)
@@ -108,10 +108,10 @@ public abstract class OTFont {
_name = new NameTable(dis, length);
seekTable(tableDirectory, dis, tablesOrigin, Table.OS_2);
_os2 = new Os2Table(dis);
-
+
_gsub = null; // FIXME: delete?
}
-
+
/**
* {@link TableDirectory} with all font tables.
*/
@@ -205,19 +205,19 @@ public abstract class OTFont {
}
return sb;
}
-
+
@Override
public String toString() {
return _head.toString();
}
-
+
/**
* Dumps information of all tables to the given {@link Writer}.
*/
- public void dumpTo(Writer out) throws IOException {
+ public void dumpTo(final Writer out) throws IOException {
out.write(getTableDirectory().toString());
out.write("\n");
-
+
dump(out, getHeadTable());
dump(out, getOS2Table());
dump(out, getCmapTable());
@@ -230,16 +230,16 @@ public abstract class OTFont {
dump(out, getGsubTable());
}
- /**
+ /**
* Writes the toString() representation of the given table to the given {@link Writer}.
*/
- protected static void dump(Writer out, Table table) throws IOException {
+ protected static void dump(final Writer out, final Table table) throws IOException {
if (table != null) {
table.dump(out);
out.write("\n");
out.write("\n");
}
}
-
-
+
+
}
diff --git a/src/main/java/net/java/dev/typecast/ot/TTFont.java b/src/main/java/net/java/dev/typecast/ot/TTFont.java
index a0793e1..c8f3712 100644
--- a/src/main/java/net/java/dev/typecast/ot/TTFont.java
+++ b/src/main/java/net/java/dev/typecast/ot/TTFont.java
@@ -50,9 +50,9 @@ public class TTFont extends OTFont {
// Load the table directory
dis.reset(); // throws if not marked or mark not supported
dis.skip(directoryOffset);
- return new TableDirectory(dis);
+ return new TableDirectory(dis);
}
-
+
private static DataInputStream openStream(final File file) throws IOException {
if (!file.exists()) {
throw new IOException("File <"+file.getName()+"> doesn't exist.");
@@ -63,18 +63,18 @@ public class TTFont extends OTFont {
throw new IllegalArgumentException("stream of type "+bis.getClass().getName()+" doesn't support mark");
}
bis.mark(streamLen);
- return new DataInputStream(bis);
+ return new DataInputStream(bis);
}
-
+
private static DataInputStream openStream(final InputStream is, final int streamLen) throws IOException {
final BufferedInputStream bis = new BufferedInputStream(is, streamLen);
if( !bis.markSupported() ) {
throw new IllegalArgumentException("stream of type "+is.getClass().getName()+" doesn't support mark");
}
bis.mark(streamLen);
- return new DataInputStream(bis);
+ return new DataInputStream(bis);
}
-
+
/**
* Constructor
* @param file standalone font file
@@ -94,7 +94,7 @@ public class TTFont extends OTFont {
public TTFont(final InputStream is, final int streamLen) throws IOException {
this(openStream(is, streamLen), 0, 0);
}
-
+
/**
* Constructor
* @param dis input stream marked at start with read-ahead set to known stream length
@@ -108,7 +108,7 @@ public class TTFont extends OTFont {
}
/**
- *
+ *
* @param dis input stream marked at start with read-ahead set to known stream length
* @param tableDirectory
* @param tablesOrigin
@@ -120,8 +120,8 @@ public class TTFont extends OTFont {
// 'loca' is required by 'glyf'
int length = seekTable(tableDirectory, dis, tablesOrigin, Table.loca);
if (length > 0) {
- LocaTable loca = new LocaTable(dis, length, this.getHeadTable(), this.getMaxpTable());
-
+ final 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);
@@ -129,7 +129,7 @@ public class TTFont extends OTFont {
} else {
_glyf = null;
}
-
+
length = seekTable(tableDirectory, dis, tablesOrigin, Table.svg);
if (length > 0) {
_svg = new SVGTable(dis);
@@ -169,7 +169,7 @@ public class TTFont extends OTFont {
public GlyfTable getGlyfTable() {
return _glyf;
}
-
+
/**
* Optional {@link SVGTable}.
*/
@@ -207,7 +207,7 @@ public class TTFont extends OTFont {
}
@Override
- public void dumpTo(Writer out) throws IOException {
+ public void dumpTo(final Writer out) throws IOException {
super.dumpTo(out);
dump(out, getGlyfTable());
dump(out, getSvgTable());
diff --git a/src/main/java/net/java/dev/typecast/ot/table/CmapFormat2.java b/src/main/java/net/java/dev/typecast/ot/table/CmapFormat2.java
index 09fb4a4..31ec19d 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/CmapFormat2.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/CmapFormat2.java
@@ -25,28 +25,28 @@ import java.util.Arrays;
/**
* Format 2: High-byte mapping through table.
- *
+ *
* @see "https://docs.microsoft.com/en-us/typography/opentype/spec/cmap#format-2-high-byte-mapping-through-table"
- *
+ *
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
*/
public class CmapFormat2 extends CmapFormat {
- static class SubHeader {
+ private static class SubHeader {
/**
* uint16
- *
+ *
* First valid low byte for this SubHeader.
- *
+ *
* @see #_entryCount
*/
int _firstCode;
-
+
/**
* uint16
- *
+ *
* Number of valid low bytes for this SubHeader.
- *
+ *
* <p>
* The {@link #_firstCode} and {@link #_entryCount} values specify a
* subrange that begins at {@link #_firstCode} and has a length equal to
@@ -69,7 +69,7 @@ public class CmapFormat2 extends CmapFormat {
* </p>
*/
int _entryCount;
-
+
/**
* @see #_entryCount
*/
@@ -82,47 +82,47 @@ public class CmapFormat2 extends CmapFormat {
int _arrayIndex;
}
-
+
/**
* uint16
- *
+ *
* @see #getLength()
*/
private final int _length;
/**
* uint16
- *
+ *
* @see #getLanguage()
*/
private final int _language;
-
+
/**
* uint16[256]
- *
+ *
* Array that maps high bytes to subHeaders: value is subHeader index × 8.
*/
private final int[] _subHeaderKeys = new int[256];
-
+
/**
* Variable-length array of SubHeader records.
*/
private final SubHeader[] _subHeaders;
-
+
/**
* uint16
- *
+ *
* Variable-length array containing subarrays used for mapping the low byte
* of 2-byte characters.
*/
private final int[] _glyphIndexArray;
- CmapFormat2(DataInput di) throws IOException {
+ CmapFormat2(final DataInput di) throws IOException {
_length = di.readUnsignedShort();
_language = di.readUnsignedShort();
-
+
int pos = 6;
-
+
// Read the subheader keys, noting the highest value, as this will
// determine the number of subheaders to read.
int highest = 0;
@@ -131,31 +131,31 @@ public class CmapFormat2 extends CmapFormat {
highest = Math.max(highest, _subHeaderKeys[i]);
pos += 2;
}
- int subHeaderCount = highest / 8 + 1;
+ final int subHeaderCount = highest / 8 + 1;
_subHeaders = new SubHeader[subHeaderCount];
-
+
// Read the subheaders, once again noting the highest glyphIndexArray
// index range.
- int indexArrayOffset = 8 * subHeaderCount + 518;
+ final int indexArrayOffset = 8 * subHeaderCount + 518;
highest = 0;
for (int i = 0; i < _subHeaders.length; ++i) {
- SubHeader sh = new SubHeader();
+ final SubHeader sh = new SubHeader();
sh._firstCode = di.readUnsignedShort();
sh._entryCount = di.readUnsignedShort();
sh._idDelta = di.readShort();
sh._idRangeOffset = di.readUnsignedShort();
-
+
// Calculate the offset into the _glyphIndexArray
pos += 8;
sh._arrayIndex =
(pos - 2 + sh._idRangeOffset - indexArrayOffset) / 2;
-
+
// What is the highest range within the glyphIndexArray?
highest = Math.max(highest, sh._arrayIndex + sh._entryCount);
-
+
_subHeaders[i] = sh;
}
-
+
// Read the glyphIndexArray
_glyphIndexArray = new int[highest];
for (int i = 0; i < _glyphIndexArray.length; ++i) {
@@ -182,13 +182,13 @@ public class CmapFormat2 extends CmapFormat {
public int getRangeCount() {
return _subHeaders.length;
}
-
+
@Override
- public Range getRange(int index) throws ArrayIndexOutOfBoundsException {
+ public Range getRange(final int index) throws ArrayIndexOutOfBoundsException {
if (index < 0 || index >= _subHeaders.length) {
throw new ArrayIndexOutOfBoundsException();
}
-
+
// Find the high-byte (if any)
int highByte = 0;
if (index != 0) {
@@ -199,7 +199,7 @@ public class CmapFormat2 extends CmapFormat {
}
}
}
-
+
return new Range(
highByte | _subHeaders[index]._firstCode,
highByte | (_subHeaders[index]._firstCode +
@@ -207,23 +207,23 @@ public class CmapFormat2 extends CmapFormat {
}
@Override
- public int mapCharCode(int charCode) {
-
+ public int mapCharCode(final int charCode) {
+
// Get the appropriate subheader
int index = 0;
- int highByte = charCode >> 8;
+ final int highByte = charCode >> 8;
if (highByte != 0) {
index = _subHeaderKeys[highByte] / 8;
}
- SubHeader sh = _subHeaders[index];
-
+ final SubHeader sh = _subHeaders[index];
+
// Is the charCode out-of-range?
- int lowByte = charCode & 0xff;
+ final int lowByte = charCode & 0xff;
if (lowByte < sh._firstCode ||
lowByte >= (sh._firstCode + sh._entryCount)) {
return 0;
}
-
+
// Now calculate the glyph index
int glyphIndex =
_glyphIndexArray[sh._arrayIndex + (lowByte - sh._firstCode)];
diff --git a/src/main/java/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java b/src/main/java/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java
index 64bb24b..4adcca5 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/GlyfCompositeDescript.java
@@ -52,7 +52,6 @@ package net.java.dev.typecast.ot.table;
import java.io.DataInput;
import java.io.IOException;
-
import java.util.ArrayList;
import java.util.List;
@@ -72,7 +71,7 @@ public class GlyfCompositeDescript extends GlyfDescript {
/**
* Creates a {@link GlyfCompositeDescript} from the given reader.
- *
+ *
* <p>
* A composite glyph starts with two uint16 values (“flags” and
* “glyphIndex,” i.e. the index of the first contour in this composite
@@ -91,13 +90,13 @@ public class GlyfCompositeDescript extends GlyfDescript {
// Get all of the composite components
GlyfCompositeComp comp;
- int index = 0;
+ int firstIndex = 0;
int firstContour = 0;
do {
- _components.add(comp = new GlyfCompositeComp(index, firstContour, di));
- GlyfDescript desc = parentTable.getDescription(comp.getGlyphIndex());
+ _components.add(comp = new GlyfCompositeComp(firstIndex, firstContour, di));
+ final GlyfDescript desc = parentTable.getDescription(comp.getGlyphIndex());
if (desc != null) {
- index += desc.getPointCount();
+ firstIndex += desc.getPointCount();
firstContour += desc.getContourCount();
}
} while ((comp.getFlags() & GlyfCompositeComp.MORE_COMPONENTS) != 0);
@@ -109,8 +108,8 @@ public class GlyfCompositeDescript extends GlyfDescript {
}
@Override
- public int getEndPtOfContours(int contour) {
- GlyfCompositeComp c = getCompositeCompEndPt(contour);
+ public int getEndPtOfContours(final int contour) {
+ final GlyfCompositeComp c = getCompositeCompEndPt(contour);
if (c != null) {
final GlyphDescription gd = getReferencedGlyph(c);
return gd.getEndPtOfContours(contour - c.getFirstContour()) + c.getFirstIndex();
@@ -141,17 +140,18 @@ public class GlyfCompositeDescript extends GlyfDescript {
return 0;
}
- private GlyfDescript getReferencedGlyph(GlyfCompositeComp c) {
+ private GlyfDescript getReferencedGlyph(final GlyfCompositeComp c) {
return c.getReferencedGlyph(_parentTable);
}
- public short getYCoordinate(int i) {
- GlyfCompositeComp c = getCompositeComp(i);
+ @Override
+ public short getYCoordinate(final int i) {
+ final GlyfCompositeComp c = getCompositeComp(i);
if (c != null) {
- GlyphDescription gd = getReferencedGlyph(c);
- int n = i - c.getFirstIndex();
- int x = gd.getXCoordinate(n);
- int y = gd.getYCoordinate(n);
+ final GlyphDescription gd = getReferencedGlyph(c);
+ final int n = i - c.getFirstIndex();
+ final int x = gd.getXCoordinate(n);
+ final int y = gd.getYCoordinate(n);
return c.transformY(x, y);
}
return 0;
@@ -164,8 +164,8 @@ public class GlyfCompositeDescript extends GlyfDescript {
@Override
public int getPointCount() {
- GlyfCompositeComp last = lastComponent();
- GlyphDescription gd = getReferencedGlyph(last);
+ final GlyfCompositeComp last = lastComponent();
+ final GlyphDescription gd = getReferencedGlyph(last);
if (gd != null) {
return last.getFirstIndex() + gd.getPointCount();
} else {
@@ -175,7 +175,7 @@ public class GlyfCompositeDescript extends GlyfDescript {
@Override
public int getContourCount() {
- GlyfCompositeComp last = lastComponent();
+ final GlyfCompositeComp last = lastComponent();
return last.getFirstContour() + getReferencedGlyph(last).getContourCount();
}
@@ -189,7 +189,7 @@ public class GlyfCompositeDescript extends GlyfDescript {
/**
* The number of {@link GlyfCompositeComp} in this {@link GlyfCompositeDescript}.
- *
+ *
* @see #getComponent(int)
*/
public int getComponentCount() {
@@ -198,18 +198,18 @@ public class GlyfCompositeDescript extends GlyfDescript {
/**
* The {@link GlyfCompositeComp} with the given index.
- *
+ *
* @see #getComponentCount()
*/
- public GlyfCompositeComp getComponent(int i) {
+ public GlyfCompositeComp getComponent(final int i) {
return _components.get(i);
}
- private GlyfCompositeComp getCompositeComp(int i) {
+ private GlyfCompositeComp getCompositeComp(final int i) {
GlyfCompositeComp c;
- for (GlyfCompositeComp component : _components) {
+ for (final GlyfCompositeComp component : _components) {
c = component;
- GlyphDescription gd = getReferencedGlyph(c);
+ final GlyphDescription gd = getReferencedGlyph(c);
if (c.getFirstIndex() <= i && i < (c.getFirstIndex() + gd.getPointCount())) {
return c;
}
@@ -217,26 +217,26 @@ public class GlyfCompositeDescript extends GlyfDescript {
return null;
}
- private GlyfCompositeComp getCompositeCompEndPt(int i) {
+ private GlyfCompositeComp getCompositeCompEndPt(final int i) {
GlyfCompositeComp c;
- for (GlyfCompositeComp component : _components) {
+ for (final GlyfCompositeComp component : _components) {
c = component;
- GlyphDescription gd = getReferencedGlyph(c);
+ final GlyphDescription gd = getReferencedGlyph(c);
if (c.getFirstContour() <= i && i < (c.getFirstContour() + gd.getContourCount())) {
return c;
}
}
return null;
}
-
+
@Override
public String toString() {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append(" Composite Glyph\n");
sb.append(" ---------------\n");
sb.append(super.toString());
sb.append("\n\n");
- for (GlyfCompositeComp component : _components) {
+ for (final GlyfCompositeComp component : _components) {
sb.append(" Component\n");
sb.append(" ---------\n");
sb.append(component.toString());
diff --git a/src/main/java/net/java/dev/typecast/ot/table/GlyfDescript.java b/src/main/java/net/java/dev/typecast/ot/table/GlyfDescript.java
index 8658334..e08b0b8 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/GlyfDescript.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/GlyfDescript.java
@@ -55,7 +55,7 @@ import java.io.IOException;
/**
* Glyph description.
- *
+ *
* <p>
* Note: The glyph descriptions do not include side bearing information.
* {@link HmtxTable#getLeftSideBearing(int) Left side bearings} are provided in
@@ -72,9 +72,9 @@ import java.io.IOException;
* by glyph instructions. See the chapter Instructing TrueType Glyphs for more
* background on phantom points.
* </p>
- *
+ *
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
- *
+ *
* @see "https://docs.microsoft.com/en-us/typography/opentype/spec/glyf"
*/
public abstract class GlyfDescript extends Program implements GlyphDescription {
@@ -83,21 +83,21 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
* Bit 0: If set, the point is on the curve; otherwise, it is off the curve.
*/
public static final byte ON_CURVE_POINT = 0x01;
-
+
/**
* Bit 1: If set, the corresponding x-coordinate is 1 byte long. If not set,
* it is two bytes long. For the sign of this value, see the description of
* the {@link #X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR} flag.
*/
public static final byte X_SHORT_VECTOR = 0x02;
-
+
/**
* Bit 2: If set, the corresponding y-coordinate is 1 byte long. If not set,
* it is two bytes long. For the sign of this value, see the description of
* the {@link #Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR} flag.
*/
public static final byte Y_SHORT_VECTOR = 0x04;
-
+
/**
* Bit 3: If set, the next byte (read as unsigned) specifies the number of
* additional times this flag byte is to be repeated in the logical flags
@@ -107,7 +107,7 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
* points in the glyph description.
*/
public static final byte REPEAT_FLAG = 0x08;
-
+
/**
* Bit 4: This flag has two meanings, depending on how the
* {@link #X_SHORT_VECTOR} flag is set. If {@link #X_SHORT_VECTOR} is set,
@@ -118,7 +118,7 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
* current x-coordinate is a signed 16-bit delta vector.
*/
public static final byte X_IS_SAME_OR_POSITIVE_X_SHORT_VECTOR = 0x10;
-
+
/**
* Bit 5: This flag has two meanings, depending on how the
* {@link #Y_SHORT_VECTOR} flag is set. If {@link #Y_SHORT_VECTOR} is set,
@@ -129,7 +129,7 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
* current y-coordinate is a signed 16-bit delta vector.
*/
public static final byte Y_IS_SAME_OR_POSITIVE_Y_SHORT_VECTOR = 0x20;
-
+
/**
* Bit 6: If set, contours in the glyph description may overlap. Use of this
* flag is not required in OpenType — that is, it is valid to have contours
@@ -138,7 +138,7 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
* Apple’s specification for details regarding behavior in Apple platforms.)
* When used, it must be set on the first flag byte for the glyph. See
* additional details below.
- *
+ *
* <p>
* A non-zero-fill algorithm is needed to avoid dropouts when contours
* overlap. The {@link #OVERLAP_SIMPLE} flag is used by some rasterizer
@@ -150,7 +150,7 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
* can be used in order to provide broad interoperability of fonts —
* particularly non-variable fonts — when glyphs have overlapping contours.
* </p>
- *
+ *
* <p>
* Note that variable fonts often make use of overlapping contours. This has
* implications for tools that generate static-font data for a specific
@@ -160,7 +160,7 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
* data, or else should merge contours to remove overlap of separate
* contours.
* </p>
- *
+ *
* <p>
* Note: The OVERLAP_COMPOUND flag, described below, has a similar purpose
* in relation to composite glyphs. The same considerations described for
@@ -178,10 +178,10 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
private final short _yMax;
GlyfDescript(
- GlyfTable parentTable,
- int glyphIndex,
- short numberOfContours,
- DataInput di) throws IOException {
+ final GlyfTable parentTable,
+ final int glyphIndex,
+ final short numberOfContours,
+ final DataInput di) throws IOException {
_parentTable = parentTable;
_glyphIndex = glyphIndex;
_numberOfContours = numberOfContours;
@@ -190,7 +190,7 @@ public abstract class GlyfDescript extends Program implements GlyphDescription {
_xMax = di.readShort();
_yMax = di.readShort();
}
-
+
/**
* The {@link GlyfTable} this {@link GlyfDescript} belongs to.
*/
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 1e7fcc1..f35ec41 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
@@ -92,6 +92,7 @@ public class HdmxTable implements Table {
return hdmx;
}
+ @Override
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 e0a1a12..9818657 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
@@ -59,24 +59,24 @@ 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.
- *
+ *
* @see "https://docs.microsoft.com/en-us/typography/opentype/spec/head"
- *
+ *
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
*/
public class HeadTable implements Table {
-
+
/**
* @see #getMagicNumber()
*/
public static final int MAGIC = 0x5F0F3CF5;
-
+
/**
* @see #getMajorVersion()
*/
@@ -86,7 +86,7 @@ public class HeadTable implements Table {
* @see #getMinorVersion()
*/
public static final int MINOR_VERSION = 0;
-
+
/**
* @see #getGlyphDataFormat()
*/
@@ -97,7 +97,7 @@ public class HeadTable implements Table {
* @see #getFontDirectionHint()
*/
public static final short FONT_DIRECTION_MIXED = 0;
-
+
/**
* 1: Only strongly left to right;
* @see #getFontDirectionHint()
@@ -115,98 +115,98 @@ public class HeadTable implements Table {
* @see #getFontDirectionHint()
*/
public static final short FONT_DIRECTION_RIGHT_TO_LEFT = -1;
-
+
/**
* -2: Like -1 but also contains neutrals.
* @see #getFontDirectionHint()
*/
public static final short FONT_DIRECTION_RIGHT_TO_LEFT_AND_NEUTRAL = -2;
-
+
/**
* @see #getMajorVersion()
*/
private int _majorVersion = MAJOR_VERSION;
-
+
/**
* @see #getMinorVersion()
*/
private int _minorVersion = MINOR_VERSION;
-
+
/**
* @see #getFontRevision()
*/
- private int _fontRevision;
-
+ private final int _fontRevision;
+
/**
* @see #getCheckSumAdjustment()
*/
- private int _checkSumAdjustment;
-
+ private final int _checkSumAdjustment;
+
/**
* @see #getMagicNumber()
*/
private int _magicNumber = MAGIC;
-
+
/**
* @see #getFlags()
*/
- private int _flags;
-
+ private final int _flags;
+
/**
* @see #getUnitsPerEm()
*/
- private int _unitsPerEm;
-
+ private final int _unitsPerEm;
+
/**
* @see #getCreated()
*/
- private long _created;
-
+ private final long _created;
+
/**
* @see #getModified()
*/
- private long _modified;
-
+ private final long _modified;
+
/**
* @see #getXMin()
*/
- private short _xMin;
-
+ private final short _xMin;
+
/**
* @see #getYMin()
*/
- private short _yMin;
-
+ private final short _yMin;
+
/**
* @see #getXMax()
*/
- private short _xMax;
-
+ private final short _xMax;
+
/**
* @see #getYMax()
*/
- private short _yMax;
-
+ private final short _yMax;
+
/**
* @see #getMacStyle()
*/
- private short _macStyle;
-
+ private final short _macStyle;
+
/**
* @see #getLowestRecPPEM()
*/
- private short _lowestRecPPEM;
-
+ private final short _lowestRecPPEM;
+
/**
* @see #getFontDirectionHint()
*/
private short _fontDirectionHint = FONT_DIRECTION_LEFT_TO_RIGHT_AND_NEUTRAL;
-
+
/**
* @see #getIndexToLocFormat()
*/
- private short _indexToLocFormat;
-
+ private final short _indexToLocFormat;
+
/**
* @see #getGlyphDataFormat()
*/
@@ -215,7 +215,7 @@ public class HeadTable implements Table {
/**
* Creates a {@link HeadTable} from binary encoding.
*/
- public HeadTable(DataInput di) throws IOException {
+ public HeadTable(final DataInput di) throws IOException {
_majorVersion = di.readUnsignedShort();
_minorVersion = di.readUnsignedShort();
_fontRevision = di.readInt();
@@ -240,14 +240,14 @@ public class HeadTable implements Table {
public int getType() {
return head;
}
-
+
/**
* uint16 majorVersion Major version number of the font header table — set to {@link #MAJOR_VERSION}.
*/
public int getMajorVersion() {
return _majorVersion;
}
-
+
/**
* uint16 minorVersion Minor version number of the font header table — set to {@link #MINOR_VERSION}.
*/
@@ -261,10 +261,10 @@ public class HeadTable implements Table {
public int getVersionNumber() {
return _majorVersion << 16 | _minorVersion;
}
-
+
/**
* Printable version number.
- *
+ *
* @see #getMajorVersion()
* @see #getMinorVersion()
*/
@@ -274,7 +274,7 @@ public class HeadTable implements Table {
/**
* Fixed Set by font manufacturer.
- *
+ *
* <p>
* For historical reasons, the fontRevision value contained in this table is
* not used by Windows to determine the version of a font. Instead, Windows
@@ -287,10 +287,10 @@ public class HeadTable implements Table {
/**
* 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.
@@ -298,7 +298,7 @@ public class HeadTable implements Table {
public int getCheckSumAdjustment() {
return _checkSumAdjustment;
}
-
+
/**
* uint32 Set to {@link #MAGIC}.
*/
@@ -308,29 +308,29 @@ public class HeadTable implements Table {
/**
* uint16
- *
+ *
* Bit 0: Baseline for font at y=0;
- *
+ *
* Bit 1: Left sidebearing point at x=0 (relevant only for TrueType
* rasterizers) — see {@link #isLeftSidebearingNormalized()};
- *
+ *
* 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
@@ -338,25 +338,25 @@ public class HeadTable implements Table {
* 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.
- *
+ * 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.
@@ -364,11 +364,11 @@ public class HeadTable implements Table {
public int getFlags() {
return _flags;
}
-
+
/**
* The Left sidebearing point is at x=0 for all glyphs (relevant only for
* TrueType rasterizers)
- *
+ *
* <p>
* Note: The scaler will perform better if the glyph coordinates have been
* created such that the xMin is equal to the lsb. For example, if the lsb
@@ -383,7 +383,7 @@ public class HeadTable implements Table {
/**
* 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.
@@ -394,7 +394,7 @@ public class HeadTable implements Table {
/**
* LONGDATETIME
- *
+ *
* Number of seconds since 12:00 midnight that started January 1st 1904 in
* GMT/UTC time zone. 64-bit integer
*/
@@ -404,7 +404,7 @@ public class HeadTable implements Table {
/**
* LONGDATETIME
- *
+ *
* Number of seconds since 12:00 midnight that started January 1st 1904 in
* GMT/UTC time zone. 64-bit integer
*/
@@ -413,8 +413,8 @@ public class HeadTable implements Table {
}
/**
- * int16
- *
+ * int16
+ *
* For all glyph bounding boxes.
*/
public short getXMin() {
@@ -422,8 +422,8 @@ public class HeadTable implements Table {
}
/**
- * int16
- *
+ * int16
+ *
* For all glyph bounding boxes.
*/
public short getYMin() {
@@ -431,8 +431,8 @@ public class HeadTable implements Table {
}
/**
- * int16
- *
+ * int16
+ *
* For all glyph bounding boxes.
*/
public short getXMax() {
@@ -440,8 +440,8 @@ public class HeadTable implements Table {
}
/**
- * int16
- *
+ * int16
+ *
* For all glyph bounding boxes.
*/
public short getYMax() {
@@ -450,25 +450,25 @@ public class HeadTable implements Table {
/**
* uint16
- *
+ *
* Contains information concerning the nature of the font patterns.
- *
+ *
* 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
* {@link Os2Table#getSelection() fsSelection} bits. The fsSelection bits
* are used over the macStyle bits in Microsoft Windows. The PANOSE values
@@ -477,10 +477,10 @@ public class HeadTable implements Table {
public short getMacStyle() {
return _macStyle;
}
-
+
/**
* Whether the glyphs are emboldened.
- *
+ *
* @see #getMacStyle()
*/
public boolean isMacBold() {
@@ -489,59 +489,59 @@ public class HeadTable implements Table {
/**
* Font contains italic or oblique glyphs, otherwise they are upright.
- *
+ *
* @see #getMacStyle()
*/
public boolean isMacItalic() {
return Bits.bit(_macStyle, 1);
}
-
+
/**
* Glyphs are underscored.
- *
+ *
* @see #getMacStyle()
*/
public boolean isMacUnderline() {
return Bits.bit(_macStyle, 2);
}
-
+
/**
* Outline (hollow) glyphs, otherwise they are solid.
- *
+ *
* @see #getMacStyle()
*/
public boolean isMacOutline() {
return Bits.bit(_macStyle, 3);
}
-
+
/**
* Whether the font has shadow.
- *
+ *
* @see #getMacStyle()
*/
public boolean isMacShadow() {
return Bits.bit(_macStyle, 4);
}
-
+
/**
* Whether the font is condensed.
- *
+ *
* @see #getMacStyle()
*/
public boolean isMacCondensed() {
return Bits.bit(_macStyle, 5);
}
-
+
/**
* @see #getMacStyle()
*/
public boolean isMacExtended() {
return Bits.bit(_macStyle, 6);
}
-
+
/**
- * uint16
- *
+ * uint16
+ *
* Smallest readable size in pixels.
*/
public short getLowestRecPPEM() {
@@ -550,9 +550,9 @@ public class HeadTable implements Table {
/**
* int16
- *
+ *
* Deprecated (Set to {@link #FONT_DIRECTION_LEFT_TO_RIGHT_AND_NEUTRAL}).
- *
+ *
* (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
@@ -560,7 +560,7 @@ public class HeadTable implements Table {
* 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).)
- *
+ *
* @see #FONT_DIRECTION_MIXED
* @see #FONT_DIRECTION_LEFT_TO_RIGHT
* @see #FONT_DIRECTION_LEFT_TO_RIGHT_AND_NEUTRAL
@@ -573,7 +573,7 @@ public class HeadTable implements Table {
/**
* int16
- *
+ *
* 0 for short offsets (Offset16), 1 for long (Offset32).
*/
public short getIndexToLocFormat() {
@@ -589,7 +589,7 @@ public class HeadTable implements Table {
/**
* int16
- *
+ *
* {@link #GLYPH_DATA_FORMAT} for current format.
*/
public short getGlyphDataFormat() {
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 1df8adc..0c12343 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
@@ -1,9 +1,9 @@
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
+ * ------------------------------------------------------------------------- *
+ * This software is published under the terms of the Apache Software License *
+ * version 1.1, a copy of which has been included with this distribution in *
+ * the LICENSE file. *
*****************************************************************************/
package net.java.dev.typecast.ot.table;
@@ -18,20 +18,20 @@ import net.java.dev.typecast.ot.Fixed;
*/
public class HheaTable implements Table {
- private int version;
- private short ascender;
- private short descender;
- private short lineGap;
- private short advanceWidthMax;
- private short minLeftSideBearing;
- private short minRightSideBearing;
- private short xMaxExtent;
- private short caretSlopeRise;
- private short caretSlopeRun;
- private short metricDataFormat;
- private int numberOfHMetrics;
-
- public HheaTable(DataInput di) throws IOException {
+ private final int version;
+ private final short ascender;
+ private final short descender;
+ private final short lineGap;
+ private final short advanceWidthMax;
+ private final short minLeftSideBearing;
+ private final short minRightSideBearing;
+ private final short xMaxExtent;
+ private final short caretSlopeRise;
+ private final short caretSlopeRun;
+ private final short metricDataFormat;
+ private final int numberOfHMetrics;
+
+ public HheaTable(final DataInput di) throws IOException {
version = di.readInt();
ascender = di.readShort();
descender = di.readShort();
@@ -98,6 +98,7 @@ public class HheaTable implements Table {
return xMaxExtent;
}
+ @Override
public String toString() {
return "'hhea' Table - Horizontal Header\n--------------------------------" +
"\n 'hhea' version: " + Fixed.floatValue(version) +
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 c3e9157..825fad6 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
@@ -57,7 +57,7 @@ import net.java.dev.typecast.ot.Fmt;
/**
* Horizontal Metrics Table
- *
+ *
* <p>
* Glyph metrics used for horizontal text layout include glyph advance widths,
* side bearings and X-direction min and max values (xMin, xMax). These are
@@ -65,7 +65,7 @@ import net.java.dev.typecast.ot.Fmt;
* CFF2) and the horizontal metrics table. The horizontal metrics ('hmtx') table
* provides glyph advance widths and left side bearings.
* </p>
- *
+ *
* <p>
* In a font with TrueType outline data, the 'glyf' table provides xMin and xMax
* values, but not advance widths or side bearings. The advance width is always
@@ -78,7 +78,7 @@ import net.java.dev.typecast.ot.Fmt;
* side bearing values from the 'hmtx' table, plus bounding-box information in
* the glyph description — see below for more details.
* </p>
- *
+ *
* <p>
* In a variable font with TrueType outline data, the left side bearing value in
* the 'hmtx' table must always be equal to xMin (bit 1 of the 'head'
@@ -90,7 +90,7 @@ import net.java.dev.typecast.ot.Fmt;
* for additional details), or by applying variation data in the HVAR table to
* default-instance values from the 'glyf' or 'hmtx' table.
* </p>
- *
+ *
* <p>
* In a font with CFF version 1 outline data, the 'CFF ' table does include
* advance widths. These values are used by PostScript processors, but are not
@@ -108,7 +108,7 @@ import net.java.dev.typecast.ot.Fmt;
* left side bearing and advance width values for non-default instances should
* be obtained by combining information from the 'hmtx' and HVAR tables.
* </p>
- *
+ *
* <p>
* The table uses a longHorMetric record to give the advance width and left side
* bearing of a glyph. Records are indexed by glyph ID. As an optimization, the
@@ -119,23 +119,23 @@ import net.java.dev.typecast.ot.Fmt;
* appropriately). The number of longHorMetric records is determined by the
* numberOfHMetrics field in the 'hhea' table.
* </p>
- *
+ *
* <p>
* If the longHorMetric array is less than the total number of glyphs, then that
* array is followed by an array for the left side bearing values of the
* remaining glyphs. The number of elements in the left side bearing will be
* derived from numberOfHMetrics plus the numGlyphs field in the 'maxp' table.
* </p>
- *
+ *
* @see "https://docs.microsoft.com/en-us/typography/opentype/spec/hmtx"
- *
+ *
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
*/
public class HmtxTable implements Table {
- private int[] _hMetrics;
- private short[] _leftSideBearing;
- private int _length;
+ private final int[] _hMetrics;
+ private final short[] _leftSideBearing;
+ private final int _length;
/**
* Creates a {@link HmtxTable}.
@@ -150,11 +150,11 @@ public class HmtxTable implements Table {
* The corresponding {@link MaxpTable}.
*/
public HmtxTable(
- DataInput di,
- int length,
- HheaTable hhea,
- MaxpTable maxp) throws IOException {
-
+ final DataInput di,
+ final int length,
+ final HheaTable hhea,
+ final MaxpTable maxp) throws IOException {
+
// Paired advance width and left side bearing values for each glyph.
// Records are indexed by glyph ID.
_hMetrics = new int[hhea.getNumberOfHMetrics()];
@@ -165,10 +165,10 @@ public class HmtxTable implements Table {
| di.readUnsignedByte()<<8
| di.readUnsignedByte();
}
-
+
// Left side bearings for glyph IDs greater than or equal to
// numberOfHMetrics.
- int lsbCount = maxp.getNumGlyphs() - hhea.getNumberOfHMetrics();
+ final int lsbCount = maxp.getNumGlyphs() - hhea.getNumberOfHMetrics();
_leftSideBearing = new short[lsbCount];
for (int i = 0; i < lsbCount; ++i) {
_leftSideBearing[i] = di.readShort();
@@ -183,9 +183,9 @@ public class HmtxTable implements Table {
/**
* uint16
- *
+ *
* Advance width, in font design units.
- *
+ *
* <p>
* The baseline is an imaginary line that is used to ‘guide’ glyphs when
* rendering text. It can be horizontal (e.g., Latin, Cyrillic, Arabic) or
@@ -193,20 +193,20 @@ public class HmtxTable implements Table {
* a virtual point, located on the baseline, called the pen position or
* origin, is used to locate glyphs.
* </p>
- *
+ *
* <p>
* The distance between two successive pen positions is glyph-specific and
* is called the advance width. Note that its value is always positive, even
* for right-to-left oriented scripts like Arabic. This introduces some
* differences in the way text is rendered.
* </p>
- *
+ *
* @param i
* The glyph index, see {@link GlyfTable#getNumGlyphs()}.
- *
+ *
* @see "https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html"
*/
- public int getAdvanceWidth(int i) {
+ public int getAdvanceWidth(final int i) {
if (_hMetrics == null) {
return 0;
}
@@ -219,9 +219,9 @@ public class HmtxTable implements Table {
/**
* int16
- *
+ *
* Glyph left side bearing, in font design units.
- *
+ *
* <p>
* The horizontal distance from the current pen position to the glyph's left
* bbox edge. It is positive for horizontal layouts, and in most cases
@@ -230,10 +230,10 @@ public class HmtxTable implements Table {
*
* @param i
* The glyph index, see {@link GlyfTable#getNumGlyphs()}.
- *
+ *
* @see "https://www.freetype.org/freetype2/docs/glyphs/glyphs-3.html"
*/
- public short getLeftSideBearing(int i) {
+ public short getLeftSideBearing(final int i) {
if (_hMetrics == null) {
return 0;
}
@@ -246,7 +246,7 @@ public class HmtxTable implements Table {
@Override
public String toString() {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append("'hmtx' Table - Horizontal Metrics\n");
sb.append("---------------------------------\n");
sb.append(" Size: ").append(_length).append(" bytes\n");
diff --git a/src/main/java/net/java/dev/typecast/ot/table/ID.java b/src/main/java/net/java/dev/typecast/ot/table/ID.java
index e51f2fb..01d9cc6 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/ID.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/ID.java
@@ -38,7 +38,7 @@ public abstract class ID {
private static final short encodingUnicode20Semantics = 4;
private static final short encodingUnicodeVariationSequences = 5;
private static final short encodingFullUnicodeCoverage = 6;
-
+
// Microsoft Encoding IDs
// public static final short encodingUndefined = 0;
// public static final short encodingUGL = 1;
@@ -190,7 +190,7 @@ public abstract class ID {
private static final short nameSampleText = 19;
private static final short namePostScriptCIDFindfontName = 20;
- public static String getPlatformName(short platformId) {
+ public static String getPlatformName(final short platformId) {
switch (platformId) {
case platformUnicode: return "Unicode";
case platformMacintosh: return "Macintosh";
@@ -200,10 +200,10 @@ public abstract class ID {
}
}
- public static String getEncodingName(short platformId, short encodingId) {
+ public static String getEncodingName(final short platformId, final short encodingId) {
if (platformId == platformUnicode) {
-
+
// Unicode specific encodings
switch (encodingId) {
case encodingUnicode10Semantics: return "Unicode 1.0 semantics";
@@ -287,7 +287,7 @@ public abstract class ID {
return "";
}
- public static String getLanguageName(short platformId, short languageId) {
+ public static String getLanguageName(final short platformId, final short languageId) {
if (platformId == platformMacintosh) {
switch (languageId) {
@@ -374,7 +374,7 @@ public abstract class ID {
return "";
}
- public static String getNameName(short nameId) {
+ public static String getNameName(final short nameId) {
switch (nameId) {
case nameCopyrightNotice: return "Copyright notice";
case nameFontFamilyName: return "Font Family name";
diff --git a/src/main/java/net/java/dev/typecast/ot/table/KernSubtable.java b/src/main/java/net/java/dev/typecast/ot/table/KernSubtable.java
index e57ff0d..844c5d2 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/KernSubtable.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/KernSubtable.java
@@ -47,7 +47,7 @@ public abstract class KernSubtable {
public abstract int getKerningPairCount();
public abstract KerningPair getKerningPair(int i);
-
+
public abstract void clearKerningPairs();
public static KernSubtable read(final DataInput di) throws IOException {
diff --git a/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat2.java b/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat2.java
index d099ecc..f6fffcd 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat2.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat2.java
@@ -38,7 +38,7 @@ public class KernSubtableFormat2 extends KernSubtable {
@Override
public void clearKerningPairs() {
}
-
+
@Override
public int getKerningPairCount() {
return 0;
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 49bf4eb..ae16552 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
@@ -1,9 +1,9 @@
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
+ * ------------------------------------------------------------------------- *
+ * This software is published under the terms of the Apache Software License *
+ * version 1.1, a copy of which has been included with this distribution in *
+ * the LICENSE file. *
*****************************************************************************/
package net.java.dev.typecast.ot.table;
@@ -13,14 +13,14 @@ import java.io.IOException;
/**
* Index to Location table
- *
+ *
* <p>
* The indexToLoc table stores the offsets to the locations of the glyphs in the
* font, relative to the beginning of the glyphData table. In order to compute
* the length of the last glyph element, there is an extra entry after the last
* valid index.
* </p>
- *
+ *
* <p>
* By definition, index zero points to the “missing character”, which is the
* character that appears if a character is not found in the font. The missing
@@ -32,31 +32,31 @@ import java.io.IOException;
* loca[n] will be equal the length of the glyph data ('glyf') table. The
* offsets must be in ascending order with loca[n] <= loca[n+1].
* </p>
- *
+ *
* <p>
* Most routines will look at the 'maxp' table to determine the number of glyphs
* in the font, but the value in the 'loca' table must agree.
* </p>
- *
+ *
* <p>
* There are two versions of this table: a short version, and a long version.
* The version is specified in the indexToLocFormat entry in the 'head' table.
* </p>
- *
+ *
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
*/
public class LocaTable implements Table {
- private int[] _offsets;
- private int _length;
+ private final int[] _offsets;
+ private final int _length;
public LocaTable(
- DataInput di,
- int length,
- HeadTable head,
- MaxpTable maxp) throws IOException {
+ final DataInput di,
+ final int length,
+ final HeadTable head,
+ final MaxpTable maxp) throws IOException {
_offsets = new int[maxp.getNumGlyphs() + 1];
- boolean shortEntries = head.useShortEntries();
+ final boolean shortEntries = head.useShortEntries();
// FIXME boolean shortEntries = head.getIndexToLocFormat() == 0;
if (shortEntries) {
for (int i = 0; i <= maxp.getNumGlyphs(); i++) {
@@ -67,11 +67,11 @@ public class LocaTable implements Table {
_offsets[i] = di.readInt();
}
}
-
+
// Check the validity of the offsets
int lastOffset = 0;
int index = 0;
- for (int offset : _offsets) {
+ for (final int offset : _offsets) {
if (offset < lastOffset) {
System.err.printf("LocaTable: Offset at index %d is bad (%d < %d)%n", index, offset, lastOffset);
}
@@ -80,13 +80,13 @@ public class LocaTable implements Table {
}
_length = length;
}
-
+
@Override
public int getType() {
return loca;
}
- public int getOffset(int i) {
+ public int getOffset(final int i) {
if (_offsets == null) {
return 0;
}
@@ -95,7 +95,7 @@ public class LocaTable implements Table {
@Override
public String toString() {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append("'loca' Table - Index To Location Table\n--------------------------------------\n")
.append("Size = ").append(_length).append(" bytes, ")
.append(_offsets.length).append(" entries\n");
@@ -105,5 +105,5 @@ public class LocaTable implements Table {
}
return sb.toString();
}
-
+
}
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 96ac560..c096fb9 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
@@ -1,9 +1,9 @@
/*****************************************************************************
* Copyright (C) The Apache Software Foundation. All rights reserved. *
- * ------------------------------------------------------------------------- *
- * This software is published under the terms of the Apache Software License *
- * version 1.1, a copy of which has been included with this distribution in *
- * the LICENSE file. *
+ * ------------------------------------------------------------------------- *
+ * This software is published under the terms of the Apache Software License *
+ * version 1.1, a copy of which has been included with this distribution in *
+ * the LICENSE file. *
*****************************************************************************/
package net.java.dev.typecast.ot.table;
@@ -18,7 +18,7 @@ import net.java.dev.typecast.ot.Fixed;
*/
public class MaxpTable implements Table {
- private int versionNumber;
+ private final int versionNumber;
private int numGlyphs;
private int maxPoints;
private int maxContours;
@@ -34,9 +34,9 @@ public class MaxpTable implements Table {
private int maxComponentElements;
private int maxComponentDepth;
- public MaxpTable(DataInput di) throws IOException {
+ public MaxpTable(final DataInput di) throws IOException {
versionNumber = di.readInt();
-
+
// CFF fonts use version 0.5, TrueType fonts use version 1.0
if (versionNumber == 0x00005000) {
numGlyphs = di.readUnsignedShort();
@@ -123,8 +123,9 @@ public class MaxpTable implements Table {
return numGlyphs;
}
+ @Override
public String toString() {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append("'maxp' Table - Maximum Profile\n------------------------------")
.append("\n 'maxp' version: ").append(Fixed.floatValue(versionNumber))
.append("\n numGlyphs: ").append(numGlyphs);
diff --git a/src/main/java/net/java/dev/typecast/ot/table/NameRecord.java b/src/main/java/net/java/dev/typecast/ot/table/NameRecord.java
index fc404e3..fb02387 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/NameRecord.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/NameRecord.java
@@ -58,15 +58,15 @@ import java.io.IOException;
*/
public class NameRecord {
- private short _platformId;
- private short _encodingId;
- private short _languageId;
- private short _nameId;
- private short _stringLength;
- private short _stringOffset;
+ private final short _platformId;
+ private final short _encodingId;
+ private final short _languageId;
+ private final short _nameId;
+ private final short _stringLength;
+ private final short _stringOffset;
private String _record;
- NameRecord(DataInput di) throws IOException {
+ NameRecord(final DataInput di) throws IOException {
_platformId = di.readShort();
_encodingId = di.readShort();
_languageId = di.readShort();
@@ -74,19 +74,19 @@ public class NameRecord {
_stringLength = di.readShort();
_stringOffset = di.readShort();
}
-
+
public short getEncodingId() {
return _encodingId;
}
-
+
public short getLanguageId() {
return _languageId;
}
-
+
public short getNameId() {
return _nameId;
}
-
+
public short getPlatformId() {
return _platformId;
}
@@ -95,11 +95,11 @@ public class NameRecord {
return _record;
}
- void loadString(DataInput di) throws IOException {
- StringBuilder sb = new StringBuilder();
+ void loadString(final DataInput di) throws IOException {
+ final StringBuilder sb = new StringBuilder();
di.skipBytes(_stringOffset);
if (_platformId == ID.platformUnicode) {
-
+
// Unicode (big-endian)
for (int i = 0; i < _stringLength/2; i++) {
sb.append(di.readChar());
@@ -111,13 +111,13 @@ public class NameRecord {
sb.append((char) di.readByte());
}
} else if (_platformId == ID.platformISO) {
-
+
// ISO encoding, ASCII
for (int i = 0; i < _stringLength; i++) {
sb.append((char) di.readByte());
}
} else if (_platformId == ID.platformMicrosoft) {
-
+
// Microsoft encoding, Unicode
char c;
for (int i = 0; i < _stringLength/2; i++) {
@@ -128,9 +128,10 @@ public class NameRecord {
_record = sb.toString();
}
+ @Override
public String toString() {
- String sb = " Platform ID: " + _platformId +
+ final String sb = " Platform ID: " + _platformId +
"\n Specific ID: " + _encodingId +
"\n Language ID: " + _languageId +
"\n Name ID: " + _nameId +
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 af9e7b1..892d4f1 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
@@ -61,50 +61,49 @@ import java.util.stream.Collectors;
* The naming table allows multilingual strings to be associated with the
* OpenType font file. These strings can represent copyright notices, font
* names, family names, style names, and so on.
- *
+ *
* Other parts of the OpenType font that require these strings can refer to them
* using a language-independent name ID. In addition to language variants, the
* table also allows for platform-specific character-encoding variants. Clients
* that need a particular string can look it up by its platform ID, encoding ID,
* language ID and name ID. Note that different platforms may have different
* requirements for the encoding of strings.
- *
+ *
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
- *
+ *
* @see "https://docs.microsoft.com/en-us/typography/opentype/spec/name"
*/
public class NameTable implements Table {
- @SuppressWarnings("unused")
- private short _formatSelector;
- private short _numberOfNameRecords;
- private short _stringStorageOffset;
- private NameRecord[] _records;
+ private final short _formatSelector;
+ private final short _numberOfNameRecords;
+ private final short _stringStorageOffset;
+ private final NameRecord[] _records;
- public NameTable(DataInput di, int length) throws IOException {
+ public NameTable(final DataInput di, final int length) throws IOException {
_formatSelector = di.readShort();
_numberOfNameRecords = di.readShort();
_stringStorageOffset = di.readShort();
_records = new NameRecord[_numberOfNameRecords];
-
+
// Load the records, which contain the encoding information and string
// offsets
for (int i = 0; i < _numberOfNameRecords; i++) {
_records[i] = new NameRecord(di);
}
-
+
// Load the string data into a buffer so the records can copy out the
// bits they are interested in
- byte[] buffer = new byte[length - _stringStorageOffset];
+ final byte[] buffer = new byte[length - _stringStorageOffset];
di.readFully(buffer);
-
+
// Now let the records get their hands on them
for (int i = 0; i < _numberOfNameRecords; i++) {
_records[i].loadString(
new DataInputStream(new ByteArrayInputStream(buffer)));
}
}
-
+
@Override
public int getType() {
return name;
@@ -123,7 +122,7 @@ public class NameTable implements Table {
public short getNumberOfNameRecords() {
return _numberOfNameRecords;
}
-
+
/**
* Offset16 stringOffset Offset to start of string storage (from start of table).
*/
@@ -146,9 +145,9 @@ public class NameTable implements Table {
return "";
}
}
-
+
/** Return a named record string */
- public String getRecordString(short nameId) {
+ public String getRecordString(final short nameId) {
// Search for the first instance of this name ID
for (int i = 0; i < _numberOfNameRecords; i++) {
if (_records[i].getNameId() == nameId) {
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 4eff4db..66dc4f9 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
@@ -26,54 +26,54 @@ import java.io.Writer;
public interface Table {
// Table constants
- int BASE = 0x42415345; // Baseline data [OpenType]
- int CFF = 0x43464620; // PostScript font program (compact font format) [PostScript]
- int COLR = 0x434f4c52; // Color Table
- int CPAL = 0x4350414c; // Color Palette Table
- int DSIG = 0x44534947; // Digital signature
- int EBDT = 0x45424454; // Embedded bitmap data
- int EBLC = 0x45424c43; // Embedded bitmap location data
- int EBSC = 0x45425343; // Embedded bitmap scaling data
- int GDEF = 0x47444546; // Glyph definition data [OpenType]
- int GPOS = 0x47504f53; // Glyph positioning data [OpenType]
- int GSUB = 0x47535542; // Glyph substitution data [OpenType]
- int JSTF = 0x4a535446; // Justification data [OpenType]
- int LTSH = 0x4c545348; // Linear threshold table
- int MMFX = 0x4d4d4658; // Multiple master font metrics [PostScript]
- int MMSD = 0x4d4d5344; // Multiple master supplementary data [PostScript]
- int OS_2 = 0x4f532f32; // OS/2 and Windows specific metrics [r]
- int PCLT = 0x50434c54; // PCL5
- int VDMX = 0x56444d58; // Vertical Device Metrics table
- int cmap = 0x636d6170; // character to glyph mapping [r]
- int cvt = 0x63767420; // Control Value Table
- int fpgm = 0x6670676d; // font program
- int fvar = 0x66766172; // Apple's font variations table [PostScript]
- int gasp = 0x67617370; // grid-fitting and scan conversion procedure (grayscale)
- int glyf = 0x676c7966; // glyph data [r]
- int hdmx = 0x68646d78; // horizontal device metrics
- int head = 0x68656164; // font header [r]
- int hhea = 0x68686561; // horizontal header [r]
- int hmtx = 0x686d7478; // horizontal metrics [r]
- int kern = 0x6b65726e; // kerning
- int loca = 0x6c6f6361; // index to location [r]
- int maxp = 0x6d617870; // maximum profile [r]
- int name = 0x6e616d65; // naming table [r]
- int prep = 0x70726570; // CVT Program
- int post = 0x706f7374; // PostScript information [r]
- int sbix = 0x73626978; // Extended Bitmaps
- int vhea = 0x76686561; // Vertical Metrics header
- int vmtx = 0x766d7478; // Vertical Metrics
- int svg = TableDirectory.fromStringTag("SVG "); // SVG outlines
-
+ static final int BASE = 0x42415345; // Baseline data [OpenType]
+ static final int CFF = 0x43464620; // PostScript font program (compact font format) [PostScript]
+ static final int COLR = 0x434f4c52; // Color Table
+ static final int CPAL = 0x4350414c; // Color Palette Table
+ static final int DSIG = 0x44534947; // Digital signature
+ static final int EBDT = 0x45424454; // Embedded bitmap data
+ static final int EBLC = 0x45424c43; // Embedded bitmap location data
+ static final int EBSC = 0x45425343; // Embedded bitmap scaling data
+ static final int GDEF = 0x47444546; // Glyph definition data [OpenType]
+ static final int GPOS = 0x47504f53; // Glyph positioning data [OpenType]
+ static final int GSUB = 0x47535542; // Glyph substitution data [OpenType]
+ static final int JSTF = 0x4a535446; // Justification data [OpenType]
+ static final int LTSH = 0x4c545348; // Linear threshold table
+ static final int MMFX = 0x4d4d4658; // Multiple master font metrics [PostScript]
+ static final int MMSD = 0x4d4d5344; // Multiple master supplementary data [PostScript]
+ static final int OS_2 = 0x4f532f32; // OS/2 and Windows specific metrics [r]
+ static final int PCLT = 0x50434c54; // PCL5
+ static final int VDMX = 0x56444d58; // Vertical Device Metrics table
+ static final int cmap = 0x636d6170; // character to glyph mapping [r]
+ static final int cvt = 0x63767420; // Control Value Table
+ static final int fpgm = 0x6670676d; // font program
+ static final int fvar = 0x66766172; // Apple's font variations table [PostScript]
+ static final int gasp = 0x67617370; // grid-fitting and scan conversion procedure (grayscale)
+ static final int glyf = 0x676c7966; // glyph data [r]
+ static final int hdmx = 0x68646d78; // horizontal device metrics
+ static final int head = 0x68656164; // font header [r]
+ static final int hhea = 0x68686561; // horizontal header [r]
+ static final int hmtx = 0x686d7478; // horizontal metrics [r]
+ static final int kern = 0x6b65726e; // kerning
+ static final int loca = 0x6c6f6361; // index to location [r]
+ static final int maxp = 0x6d617870; // maximum profile [r]
+ static final int name = 0x6e616d65; // naming table [r]
+ static final int prep = 0x70726570; // CVT Program
+ static final int post = 0x706f7374; // PostScript information [r]
+ static final int sbix = 0x73626978; // Extended Bitmaps
+ static final int vhea = 0x76686561; // Vertical Metrics header
+ static final int vmtx = 0x766d7478; // Vertical Metrics
+ static final int svg = TableDirectory.fromStringTag("SVG "); // SVG outlines
+
/**
* The type code of this {@link Table}.
*/
int getType();
- /**
+ /**
* Writes full debug information to the given writer.
*/
- default void dump(Writer out) throws IOException {
+ default void dump(final Writer out) throws IOException {
out.write(toString());
}
}
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 1961b78..fec5ce5 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
@@ -28,13 +28,13 @@ import java.io.IOException;
public class VdmxTable implements Table {
private static class Ratio {
-
- private byte _bCharSet;
- private byte _xRatio;
- private byte _yStartRatio;
- private byte _yEndRatio;
-
- Ratio(DataInput di) throws IOException {
+
+ private final byte _bCharSet;
+ private final byte _xRatio;
+ private final byte _yStartRatio;
+ private final byte _yEndRatio;
+
+ Ratio(final DataInput di) throws IOException {
_bCharSet = di.readByte();
_xRatio = di.readByte();
_yStartRatio = di.readByte();
@@ -44,27 +44,27 @@ public class VdmxTable implements Table {
byte getBCharSet() {
return _bCharSet;
}
-
+
byte getXRatio() {
return _xRatio;
}
-
+
byte getYStartRatio() {
return _yStartRatio;
}
-
+
byte getYEndRatio() {
return _yEndRatio;
}
}
-
+
private static class VTableRecord {
-
- private int _yPelHeight;
- private short _yMax;
- private short _yMin;
-
- VTableRecord(DataInput di) throws IOException {
+
+ private final int _yPelHeight;
+ private final short _yMax;
+ private final short _yMin;
+
+ VTableRecord(final DataInput di) throws IOException {
_yPelHeight = di.readUnsignedShort();
_yMax = di.readShort();
_yMin = di.readShort();
@@ -73,24 +73,24 @@ public class VdmxTable implements Table {
int getYPelHeight() {
return _yPelHeight;
}
-
+
short getYMax() {
return _yMax;
}
-
+
short getYMin() {
return _yMin;
}
}
-
+
private static class Group {
-
- private int _recs;
- private int _startsz;
- private int _endsz;
- private VTableRecord[] _entry;
-
- Group(DataInput di) throws IOException {
+
+ private final int _recs;
+ private final int _startsz;
+ private final int _endsz;
+ private final VTableRecord[] _entry;
+
+ Group(final DataInput di) throws IOException {
_recs = di.readUnsignedShort();
_startsz = di.readUnsignedByte();
_endsz = di.readUnsignedByte();
@@ -103,29 +103,29 @@ public class VdmxTable implements Table {
int getRecs() {
return _recs;
}
-
+
int getStartSZ() {
return _startsz;
}
-
+
int getEndSZ() {
return _endsz;
}
-
+
VTableRecord[] getEntry() {
return _entry;
}
}
-
- private int _version;
- private int _numRecs;
- private int _numRatios;
- private Ratio[] _ratRange;
- private int[] _offset;
- private Group[] _groups;
-
+
+ private final int _version;
+ private final int _numRecs;
+ private final int _numRatios;
+ private final Ratio[] _ratRange;
+ private final int[] _offset;
+ private final Group[] _groups;
+
/** Creates a new instance of VdmxTable */
- public VdmxTable(DataInput di) throws IOException {
+ public VdmxTable(final DataInput di) throws IOException {
_version = di.readUnsignedShort();
_numRecs = di.readUnsignedShort();
_numRatios = di.readUnsignedShort();
@@ -142,14 +142,15 @@ public class VdmxTable implements Table {
_groups[i] = new Group(di);
}
}
-
+
@Override
public int getType() {
return VDMX;
}
+ @Override
public String toString() {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append("'VDMX' Table - Precomputed Vertical Device Metrics\n")
.append("--------------------------------------------------\n")
.append(" Version: ").append(_version).append("\n")
@@ -166,7 +167,7 @@ public class VdmxTable implements Table {
sb.append("\n VDMX Height Record Groups\n")
.append(" -------------------------\n");
for (int i = 0; i < _numRecs; ++i) {
- Group group = _groups[i];
+ final Group group = _groups[i];
sb.append(" ").append(i + 1)
.append(". Number of Hgt Records ").append(group.getRecs()).append("\n")
.append(" Starting Y Pel Height ").append(group.getStartSZ()).append("\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 7f772f0..4cc1f20 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
@@ -29,20 +29,20 @@ import net.java.dev.typecast.ot.Fixed;
*/
public class VheaTable implements Table {
- private int _version;
- private short _ascent;
- private short _descent;
- private short _lineGap;
- private short _advanceHeightMax;
- private short _minTopSideBearing;
- private short _minBottomSideBearing;
- private short _yMaxExtent;
- private short _caretSlopeRise;
- private short _caretSlopeRun;
- private short _metricDataFormat;
- private int _numberOfLongVerMetrics;
-
- public VheaTable(DataInput di) throws IOException {
+ private final int _version;
+ private final short _ascent;
+ private final short _descent;
+ private final short _lineGap;
+ private final short _advanceHeightMax;
+ private final short _minTopSideBearing;
+ private final short _minBottomSideBearing;
+ private final short _yMaxExtent;
+ private final short _caretSlopeRise;
+ private final short _caretSlopeRun;
+ private final short _metricDataFormat;
+ private final int _numberOfLongVerMetrics;
+
+ public VheaTable(final DataInput di) throws IOException {
_version = di.readInt();
_ascent = di.readShort();
_descent = di.readShort();
@@ -109,6 +109,7 @@ public class VheaTable implements Table {
return _yMaxExtent;
}
+ @Override
public String toString() {
return "'vhea' Table - Vertical Header\n------------------------------" +
"\n 'vhea' version: " + Fixed.floatValue(_version) +
@@ -129,5 +130,5 @@ public class VheaTable implements Table {
"\n metricDataFormat: " + _metricDataFormat +
"\n numOf_LongVerMetrics: " + _numberOfLongVerMetrics;
}
-
+
}
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 f6d8dc9..35bbcbb 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
@@ -27,13 +27,13 @@ import java.io.IOException;
*/
class VmtxTable implements Table {
- private int[] _vMetrics;
- private short[] _topSideBearing;
+ private final int[] _vMetrics;
+ private final short[] _topSideBearing;
protected VmtxTable(
- DataInput di,
- VheaTable vhea,
- MaxpTable maxp) throws IOException {
+ final DataInput di,
+ final VheaTable vhea,
+ final MaxpTable maxp) throws IOException {
_vMetrics = new int[vhea.getNumberOfLongVerMetrics()];
for (int i = 0; i < vhea.getNumberOfLongVerMetrics(); ++i) {
_vMetrics[i] =
@@ -42,7 +42,7 @@ class VmtxTable implements Table {
| di.readUnsignedByte()<<8
| di.readUnsignedByte();
}
- int tsbCount = maxp.getNumGlyphs() - vhea.getNumberOfLongVerMetrics();
+ final int tsbCount = maxp.getNumGlyphs() - vhea.getNumberOfLongVerMetrics();
_topSideBearing = new short[tsbCount];
for (int i = 0; i < tsbCount; ++i) {
_topSideBearing[i] = di.readShort();
@@ -54,7 +54,7 @@ class VmtxTable implements Table {
return vmtx;
}
- private int getAdvanceHeight(int i) {
+ public int getAdvanceHeight(final int i) {
if (_vMetrics == null) {
return 0;
}
@@ -65,7 +65,7 @@ class VmtxTable implements Table {
}
}
- public short getTopSideBearing(int i) {
+ public short getTopSideBearing(final int i) {
if (_vMetrics == null) {
return 0;
}
@@ -76,8 +76,9 @@ class VmtxTable implements Table {
}
}
+ @Override
public String toString() {
- StringBuilder sb = new StringBuilder();
+ final StringBuilder sb = new StringBuilder();
sb.append("'vmtx' Table - Vertical Metrics\n-------------------------------\n");
// sb.append("Size = ").append(_de.getLength()).append(" bytes, ")
sb.append(_vMetrics.length).append(" entries\n");
diff --git a/src/test/java/net/java/dev/typecast/ot/TTFontTest.java b/src/test/java/net/java/dev/typecast/ot/TTFontTest.java
index c703b3f..b424159 100644
--- a/src/test/java/net/java/dev/typecast/ot/TTFontTest.java
+++ b/src/test/java/net/java/dev/typecast/ot/TTFontTest.java
@@ -41,7 +41,7 @@ public class TTFontTest extends TestCase {
*
* @param testName name of the test case
*/
- public TTFontTest(String testName) {
+ public TTFontTest(final String testName) {
super(testName);
}
@@ -53,23 +53,23 @@ public class TTFontTest extends TestCase {
}
public void testLoadFont() throws URISyntaxException, IOException {
- TTFont font = loadFontResource("Lato-Regular.ttf");
+ final TTFont font = loadFontResource("Lato-Regular.ttf");
assertEquals(HeadTable.class, font.getHeadTable().getClass());
dumpFont("Lato-Regular.txt", font);
}
public void testLoadColorFont() throws URISyntaxException, IOException {
- TTFont font = loadFontResource("NotoColorEmoji.ttf");
+ final TTFont font = loadFontResource("NotoColorEmoji.ttf");
dumpFont("NotoColorEmoji.txt", font);
}
-
+
public void testLoadColorFont2() throws URISyntaxException, IOException {
- TTFont font = loadFontResource("Gilbert-Color Bold Preview5.otf");
+ final TTFont font = loadFontResource("Gilbert-Color Bold Preview5.otf");
dumpFont("Gilbert-Color Bold Preview5.txt", font);
}
-
- private void dumpFont(String name, TTFont font)
+
+ private void dumpFont(final String name, final TTFont font)
throws IOException, FileNotFoundException {
new File("target/tmp").mkdirs();
try (Writer out = new OutputStreamWriter(new FileOutputStream(new File("target/tmp/" + name)))) {
@@ -77,12 +77,12 @@ public class TTFontTest extends TestCase {
}
}
- private TTFont loadFontResource(String name)
+ private TTFont loadFontResource(final String name)
throws URISyntaxException, IOException {
return loadFont( ClassLoader.getSystemResource(name) );
}
- private TTFont loadFont(URL url) throws URISyntaxException, IOException {
+ private TTFont loadFont(final URL url) throws URISyntaxException, IOException {
final URLConnection con = url.openConnection();
final int len = con.getContentLength();
try(InputStream is = con.getInputStream()) {