diff options
author | David Schweinsberg <[email protected]> | 2017-05-12 10:09:56 -0700 |
---|---|---|
committer | David Schweinsberg <[email protected]> | 2017-05-12 10:09:56 -0700 |
commit | e1968e0e18935de275dce8325dab418011427117 (patch) | |
tree | 97927c111dadbbe1bac89ff2d66ee8d787da6e07 /src | |
parent | 3a61bed3a754fbfcfa98e0a130f3ed330c34996b (diff) |
Dump of GSUB coverage
Diffstat (limited to 'src')
5 files changed, 61 insertions, 13 deletions
diff --git a/src/net/java/dev/typecast/ot/table/Coverage.java b/src/net/java/dev/typecast/ot/table/Coverage.java index 1711db1..684139f 100644 --- a/src/net/java/dev/typecast/ot/table/Coverage.java +++ b/src/net/java/dev/typecast/ot/table/Coverage.java @@ -68,6 +68,8 @@ public abstract class Coverage { */ public abstract int findGlyph(int glyphId); + public abstract int[] getGlyphIds(); + protected static Coverage read(DataInput di) throws IOException { Coverage c = null; int format = di.readUnsignedShort(); diff --git a/src/net/java/dev/typecast/ot/table/CoverageFormat1.java b/src/net/java/dev/typecast/ot/table/CoverageFormat1.java index 9075580..238ce9e 100644 --- a/src/net/java/dev/typecast/ot/table/CoverageFormat1.java +++ b/src/net/java/dev/typecast/ot/table/CoverageFormat1.java @@ -59,8 +59,8 @@ import java.io.IOException; */ public class CoverageFormat1 extends Coverage { - private int _glyphCount; - private int[] _glyphIds; + private final int _glyphCount; + private final int[] _glyphIds; /** Creates new CoverageFormat1 */ protected CoverageFormat1(DataInput di) throws IOException { @@ -71,10 +71,12 @@ public class CoverageFormat1 extends Coverage { } } + @Override public int getFormat() { return 1; } + @Override public int findGlyph(int glyphId) { for (int i = 0; i < _glyphCount; i++) { if (_glyphIds[i] == glyphId) { @@ -84,4 +86,8 @@ public class CoverageFormat1 extends Coverage { return -1; } + @Override + public int[] getGlyphIds() { + return _glyphIds; + } } diff --git a/src/net/java/dev/typecast/ot/table/CoverageFormat2.java b/src/net/java/dev/typecast/ot/table/CoverageFormat2.java index 5670bb9..234ec74 100644 --- a/src/net/java/dev/typecast/ot/table/CoverageFormat2.java +++ b/src/net/java/dev/typecast/ot/table/CoverageFormat2.java @@ -52,6 +52,8 @@ package net.java.dev.typecast.ot.table; import java.io.DataInput; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** * @@ -59,8 +61,8 @@ import java.io.IOException; */ public class CoverageFormat2 extends Coverage { - private int _rangeCount; - private RangeRecord[] _rangeRecords; + private final int _rangeCount; + private final RangeRecord[] _rangeRecords; /** Creates new CoverageFormat2 */ protected CoverageFormat2(DataInput di) throws IOException { @@ -71,10 +73,12 @@ public class CoverageFormat2 extends Coverage { } } + @Override public int getFormat() { return 2; } + @Override public int findGlyph(int glyphId) { for (int i = 0; i < _rangeCount; i++) { int n = _rangeRecords[i].getCoverageIndex(glyphId); @@ -85,4 +89,14 @@ public class CoverageFormat2 extends Coverage { return -1; } + @Override + public int[] getGlyphIds() { + List<Integer> ids = new ArrayList<>(); + for (RangeRecord record : _rangeRecords) { + for (int i = record.getStart(); i < record.getEnd(); ++i) { + ids.add(i); + } + } + return ids.stream().mapToInt(i->i).toArray(); + } } diff --git a/src/net/java/dev/typecast/ot/table/RangeRecord.java b/src/net/java/dev/typecast/ot/table/RangeRecord.java index 2b19732..5073b9c 100644 --- a/src/net/java/dev/typecast/ot/table/RangeRecord.java +++ b/src/net/java/dev/typecast/ot/table/RangeRecord.java @@ -60,9 +60,9 @@ import java.io.IOException; */ public class RangeRecord { - private int _start; - private int _end; - private int _startCoverageIndex; + private final int _start; + private final int _end; + private final int _startCoverageIndex; /** Creates new RangeRecord */ public RangeRecord(DataInput di) throws IOException { @@ -71,6 +71,18 @@ public class RangeRecord { _startCoverageIndex = di.readUnsignedShort(); } + public int getStart() { + return _start; + } + + public int getEnd() { + return _end; + } + + public int getStartCoverageIndex() { + return _startCoverageIndex; + } + public boolean isInRange(int glyphId) { return (_start <= glyphId && glyphId <= _end); } @@ -81,6 +93,5 @@ public class RangeRecord { } return -1; } - } diff --git a/src/net/java/dev/typecast/ot/table/SingleSubstFormat2.java b/src/net/java/dev/typecast/ot/table/SingleSubstFormat2.java index f95e5ac..6608589 100644 --- a/src/net/java/dev/typecast/ot/table/SingleSubstFormat2.java +++ b/src/net/java/dev/typecast/ot/table/SingleSubstFormat2.java @@ -59,10 +59,10 @@ import java.io.IOException; */ public class SingleSubstFormat2 extends SingleSubst { - private int _coverageOffset; - private int _glyphCount; - private int[] _substitutes; - private Coverage _coverage; + private final int _coverageOffset; + private final int _glyphCount; + private final int[] _substitutes; + private final Coverage _coverage; /** Creates new SingleSubstFormat2 */ protected SingleSubstFormat2(DataInputStream dis, int offset) throws IOException { @@ -77,10 +77,12 @@ public class SingleSubstFormat2 extends SingleSubst { _coverage = Coverage.read(dis); } + @Override public int getFormat() { return 2; } + @Override public int substitute(int glyphId) { int i = _coverage.findGlyph(glyphId); if (i > -1) { @@ -89,8 +91,21 @@ public class SingleSubstFormat2 extends SingleSubst { return glyphId; } + @Override public String getTypeAsString() { return "SingleSubstFormat2"; } -} + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + int[] glyphIds = _coverage.getGlyphIds(); + for (int glyphId : glyphIds) { + int i = _coverage.findGlyph(glyphId); + if (i > -1) { + sb.append(String.format("%d = %d\n", glyphId, _substitutes[i])); + } + } + return sb.toString(); + } +} |