aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-02-11 20:09:18 +0100
committerSven Gothel <[email protected]>2023-02-12 00:18:47 +0100
commit8ee88b323ce7aec012d584c8620d81c143aca19a (patch)
tree11ca0c43495a179904f558152f9ecb3cdeee0dec
parent626d97d5a9f971c1a3d85440a7182bfc46569b72 (diff)
KernSubtable*: Maintain version, length and coverage. Add boolean accessors to coverage flags. KernSubtableFormat0: Expose binary-search properties.
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/KernSubtable.java65
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat0.java33
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat2.java15
-rw-r--r--src/main/java/net/java/dev/typecast/ot/table/KerningPair.java19
4 files changed, 94 insertions, 38 deletions
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 a14356b..a79e8c8 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
@@ -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;
@@ -16,28 +16,51 @@ import java.io.IOException;
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
*/
public abstract class KernSubtable {
+ private final int version;
+ private final int length;
+ private final int coverage;
/** Creates new KernSubtable */
- KernSubtable() {
+ KernSubtable(final int version, final int length, final int coverage) {
+ this.version = version;
+ this.length = length;
+ this.coverage = coverage;
}
-
+
+ /** Kern subtable version number */
+ public final int getVersion() { return version; }
+ /** Length of the subtable in bytes including the header */
+ public final int getLength() { return length; }
+ /** type of subtable information */
+ public final int getCoverage() { return coverage; }
+ /** Subtable format, i.e. 0 or 2 is supported here */
+ public final int getSubtableFormat() { return coverage >> 8; }
+ /** True if table is horizontal data, otherwise vertical */
+ public final boolean isHorizontal() { return 0 != ( coverage & 0b0001 ); }
+ /** True if table has kerning values, otherwise minimum values */
+ public final boolean areKerningValues() { return 0 == ( coverage & 0b0010 ); }
+ /** True if kerning is perpendicular to text flow, otherwise along with flow */
+ public final boolean isCrossstream() { return 0 != ( coverage & 0b0100 ); }
+ /** True if this table shall replace an accumulated value, otherwise keep */
+ public final boolean isOverride() { return 0 != ( coverage & 0b1000 ); }
+
public abstract int getKerningPairCount();
public abstract KerningPair getKerningPair(int i);
- public static KernSubtable read(DataInput di) throws IOException {
+ public static KernSubtable read(final DataInput di) throws IOException {
KernSubtable table = null;
- int version = di.readUnsignedShort();
- int length = di.readUnsignedShort();
- int coverage = di.readUnsignedShort();
- int format = coverage >> 8;
-
+ final int version = di.readUnsignedShort();
+ final int length = di.readUnsignedShort();
+ final int coverage = di.readUnsignedShort();
+ final int format = coverage >> 8;
+
switch (format) {
case 0:
- table = new KernSubtableFormat0(di);
+ table = new KernSubtableFormat0(version, length, coverage, di);
break;
case 2:
- table = new KernSubtableFormat2(di);
+ table = new KernSubtableFormat2(version, length, coverage, di);
break;
default:
break;
@@ -45,4 +68,18 @@ public abstract class KernSubtable {
return table;
}
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("'kern' Sub-Table\n--------------------------")
+ .append("\n version: ").append(version)
+ .append("\n length: ").append(length)
+ .append("\n coverage: 0x").append(Integer.toHexString(coverage)).append("[")
+ .append("\n format: ").append(getSubtableFormat())
+ .append("\n horizontal: ").append(isHorizontal())
+ .append("\n kerningVal: ").append(areKerningValues())
+ .append("\n crossstream: ").append(isCrossstream())
+ .append("\n override: ").append(isOverride()).append("]");
+ return sb.toString();
+ }
}
diff --git a/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat0.java b/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat0.java
index a60975b..22edb61 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat0.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/KernSubtableFormat0.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;
@@ -16,15 +16,16 @@ import java.io.IOException;
* @author <a href="mailto:[email protected]">David Schweinsberg</a>
*/
public class KernSubtableFormat0 extends KernSubtable {
-
+
private int nPairs;
- private int searchRange;
- private int entrySelector;
- private int rangeShift;
+ private final int searchRange;
+ private final int entrySelector;
+ private final int rangeShift;
private KerningPair[] kerningPairs;
/** Creates new KernSubtableFormat0 */
- KernSubtableFormat0(DataInput di) throws IOException {
+ KernSubtableFormat0(final int version, final int length, final int coverage, final DataInput di) throws IOException {
+ super(version, length, coverage);
nPairs = di.readUnsignedShort();
searchRange = di.readUnsignedShort();
entrySelector = di.readUnsignedShort();
@@ -35,11 +36,23 @@ public class KernSubtableFormat0 extends KernSubtable {
}
}
+ @Override
public int getKerningPairCount() {
return nPairs;
}
- public KerningPair getKerningPair(int i) {
+ public int getSearchRange() {
+ return searchRange;
+ }
+ public int getEntrySelector() {
+ return entrySelector;
+ }
+ public int getRangeShift() {
+ return rangeShift;
+ }
+
+ @Override
+ public KerningPair getKerningPair(final int i) {
return kerningPairs[i];
}
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 bcccf85..f4755eb 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
@@ -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;
@@ -27,18 +27,21 @@ public class KernSubtableFormat2 extends KernSubtable {
private final int array;
/** Creates new KernSubtableFormat2 */
- KernSubtableFormat2(DataInput di) throws IOException {
+ KernSubtableFormat2(final int version, final int length, final int coverage, final DataInput di) throws IOException {
+ super(version, length, coverage);
rowWidth = di.readUnsignedShort();
leftClassTable = di.readUnsignedShort();
rightClassTable = di.readUnsignedShort();
array = di.readUnsignedShort();
}
+ @Override
public int getKerningPairCount() {
return 0;
}
- public KerningPair getKerningPair(int i) {
+ @Override
+ public KerningPair getKerningPair(final int i) {
return null;
}
diff --git a/src/main/java/net/java/dev/typecast/ot/table/KerningPair.java b/src/main/java/net/java/dev/typecast/ot/table/KerningPair.java
index f059df7..bab31c9 100644
--- a/src/main/java/net/java/dev/typecast/ot/table/KerningPair.java
+++ b/src/main/java/net/java/dev/typecast/ot/table/KerningPair.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;
@@ -17,25 +17,28 @@ import java.io.IOException;
*/
public class KerningPair {
- private int left;
- private int right;
- private short value;
+ private final int left; // uint16
+ private final int right; // uint16
+ private final short value; // sint16 in FUnits
/** Creates new KerningPair */
- KerningPair(DataInput di) throws IOException {
+ KerningPair(final DataInput di) throws IOException {
left = di.readUnsignedShort();
right = di.readUnsignedShort();
value = di.readShort();
}
+ /** left glyph index */
public int getLeft() {
return left;
}
+ /** right glyph index */
public int getRight() {
return right;
}
+ /** sint16 in FUnits between left and right glyph within a word */
public short getValue() {
return value;
}