foray-commit Mailing List for FOray (Page 13)
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
(139) |
Apr
(98) |
May
(250) |
Jun
(394) |
Jul
(84) |
Aug
(13) |
Sep
(420) |
Oct
(186) |
Nov
(1) |
Dec
(3) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(108) |
Feb
(202) |
Mar
(291) |
Apr
(247) |
May
(374) |
Jun
(227) |
Jul
(231) |
Aug
(60) |
Sep
(31) |
Oct
(45) |
Nov
(18) |
Dec
|
| 2008 |
Jan
(38) |
Feb
(71) |
Mar
(142) |
Apr
|
May
(59) |
Jun
(6) |
Jul
(10) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2009 |
Jan
(12) |
Feb
(4) |
Mar
(88) |
Apr
(121) |
May
(17) |
Jun
(30) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2010 |
Jan
(11) |
Feb
(76) |
Mar
(11) |
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
(44) |
Sep
(14) |
Oct
(7) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(10) |
Nov
|
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
(4) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(168) |
| 2017 |
Jan
(77) |
Feb
(11) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
|
Feb
(88) |
Mar
(118) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(141) |
| 2021 |
Jan
(170) |
Feb
(20) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(62) |
Nov
(189) |
Dec
(162) |
| 2022 |
Jan
(201) |
Feb
(118) |
Mar
(8) |
Apr
|
May
(2) |
Jun
(47) |
Jul
(19) |
Aug
(14) |
Sep
(3) |
Oct
|
Nov
(28) |
Dec
(235) |
| 2023 |
Jan
(112) |
Feb
(23) |
Mar
(2) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(70) |
Sep
(92) |
Oct
(20) |
Nov
(1) |
Dec
(1) |
| 2024 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
(14) |
Jun
(11) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2025 |
Jan
(10) |
Feb
(29) |
Mar
|
Apr
(162) |
May
(245) |
Jun
(83) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <vic...@us...> - 2025-05-02 22:47:56
|
Revision: 13578
http://sourceforge.net/p/foray/code/13578
Author: victormote
Date: 2025-05-02 22:47:29 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Convert loca table to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 22:32:05 UTC (rev 13577)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 22:47:29 UTC (rev 13578)
@@ -74,6 +74,7 @@
import org.foray.fontParse.ttf.HmtxTableParser;
import org.foray.fontParse.ttf.JstfTableParser;
import org.foray.fontParse.ttf.KernTableParser;
+import org.foray.fontParse.ttf.LocaTableParser;
import org.foray.fontParse.ttf.MathTableParser;
import org.foray.fontParse.ttf.MaxpTableParser;
import org.foray.fontParse.ttf.NameTableParser;
@@ -98,6 +99,7 @@
import org.foray.fontParse.ttfHandler.HmtxTableHandler;
import org.foray.fontParse.ttfHandler.JstfTableHandler;
import org.foray.fontParse.ttfHandler.KernTableHandler;
+import org.foray.fontParse.ttfHandler.LocaTableHandler;
import org.foray.fontParse.ttfHandler.MathTableHandler;
import org.foray.fontParse.ttfHandler.MaxpTableHandler;
import org.foray.fontParse.ttfHandler.NameTableHandler;
@@ -334,8 +336,11 @@
dirEntry = ttfTableDir.getTableDirectoryEntry("loca");
if (dirEntry != null) {
final boolean isLongFormat = font.headTable.longLocaFormat();
- font.locaTable = LocaTable.parse(raInput, dirEntry.getOffset(), dirEntry.getLength(), isLongFormat,
+ final ParserKit<LocaTable, LocaTableHandler> contentHandler = LocaTable.createContentHandler(isLongFormat,
numberOfGlyphs);
+ final LocaTableParser parser = new LocaTableParser();
+ parser.parse(raInput, dirEntry.getOffset(), contentHandler.getHandler());
+ font.locaTable = contentHandler.getTable();
}
/* glyf must be parsed after hmtx and loca. */
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 22:32:05 UTC (rev 13577)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 22:47:29 UTC (rev 13578)
@@ -30,13 +30,10 @@
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
-import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.fontParse.ttfHandler.LocaTableHandler;
import org.checkerframework.checker.signedness.qual.Unsigned;
-import java.io.IOException;
-
/**
* A TrueType/OpenType "loca" (Index to location) table.
* This table is used only in fonts that contain TrueType outlines.
@@ -49,7 +46,6 @@
private final class ContentHandler implements LocaTableHandler {
/** The table instance being created. */
- @SuppressWarnings("unused")
private LocaTable table;
/** Indicates whether the long format (true) or the short format (false) should be used. This information is
@@ -71,11 +67,6 @@
this.table = table;
this.isLongFormat = isLongFormat;
this.numberOfGlyphs = numberOfGlyphs;
- if (isLongFormat) {
- table.longOffsets = new @Unsigned int[numberOfGlyphs + 1];
- } else {
- table.shortOffsets = new @Unsigned short[numberOfGlyphs + 1];
- }
}
@Override
@@ -87,6 +78,16 @@
public int getNumberOfGlyphs() {
return this.numberOfGlyphs;
}
+
+ @Override
+ public void longOffsets(@Unsigned final int[] value) {
+ this.table.longOffsets = value;
+ }
+
+ @Override
+ public void shortOffsets(@Unsigned final short[] value) {
+ this.table.shortOffsets = value;
+ }
}
@@ -98,6 +99,8 @@
+
+
/** The array of offsets, if using the short format. If not, must be null. */
private @Unsigned short[] shortOffsets;
@@ -120,39 +123,6 @@
}
/**
- * Reads the "loca" table.
- * @param input The input which is being parsed.
- * @param offset The offset into {@code input} at which to start parsing.
- * @param length The number of bytes to parse from {@code input}.
- * @param isLongFormat Indicates whether the long format (true) or the short format (false) should be used.
- * This information is derived from the "head" table.
- * @param numberOfGlyphs The number of glyph entries to be parsed.
- * This information is derived from the "maxp" table.
- * @return The parsed instance.
- * @throws IOException For I/O Error.
- */
- public static LocaTable parse(final TtfRandomAccessInput input, final int offset, final int length,
- final boolean isLongFormat, final int numberOfGlyphs) throws IOException {
- input.seek(offset);
- final LocaTable loca = new LocaTable();
- if (isLongFormat) {
- loca.longOffsets = new @Unsigned int[numberOfGlyphs + 1];
- } else {
- loca.shortOffsets = new @Unsigned short[numberOfGlyphs + 1];
- }
-
- /* Reads n + 1 values, where n = numberOfGlyphs. */
- for (int i = 0; i <= numberOfGlyphs; i++) {
- if (isLongFormat) {
- loca.longOffsets[i] = input.read_Offset32();
- } else {
- loca.shortOffsets[i] = input.read_Offset16();
- }
- }
- return loca;
- }
-
- /**
* Returns the offset for a given glyph index.
* @param glyphIndex The glyph index for which the offset should be returned.
* @return The offset at {@code glyphIndex}.
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java 2025-05-02 22:32:05 UTC (rev 13577)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java 2025-05-02 22:47:29 UTC (rev 13578)
@@ -61,11 +61,17 @@
} else {
final @Unsigned short shortOffset = input.read_Offset16();
handler.shortOffset(shortOffset);
- longOffsets[index] = shortOffset;
+ shortOffsets[index] = shortOffset;
}
}
- handler.longOffsets(longOffsets);
- handler.shortOffsets(shortOffsets);
+
+ if (isLongFormat) {
+ handler.longOffsets(longOffsets);
+ handler.shortOffsets(null);
+ } else {
+ handler.shortOffsets(shortOffsets);
+ handler.longOffsets(null);
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 22:32:24
|
Revision: 13577
http://sourceforge.net/p/foray/code/13577
Author: victormote
Date: 2025-05-02 22:32:05 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Progress toward converting loca table to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2025-05-02 21:27:18 UTC (rev 13576)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2025-05-02 22:32:05 UTC (rev 13577)
@@ -41,7 +41,6 @@
import org.axsl.primitive.sequence.ShortSequence;
import org.axsl.ps.BoundingBox;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@@ -105,7 +104,7 @@
try {
this.ttf = ttfFile.getTTFFont(fontName);
} catch (final IOException e) {
- getLogger().error(e.getMessage());
+ LoggerFactory.getLogger(getClass()).error(e.getMessage());
}
/*
@@ -264,13 +263,4 @@
return new BoundingBoxShort(scaled);
}
- /**
- * Returns the logger.
- * @return The logger.
- */
- private Logger getLogger() {
- /* Not cached because not expected to get used much. */
- return LoggerFactory.getLogger(getClass());
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 21:27:18 UTC (rev 13576)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 22:32:05 UTC (rev 13577)
@@ -115,7 +115,6 @@
import org.axsl.ps.BoundingBox;
import org.axsl.ps.Encoding;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@@ -710,7 +709,8 @@
* the range +/- 1500. Log an error if there is any truncation. */
if (roundedResult < Short.MIN_VALUE
|| roundedResult > Short.MAX_VALUE) {
- getLogger().error("Glyph space metric outside range of a \"short\", actual: " + roundedResult);
+ LoggerFactory.getLogger(getClass()).error(
+ "Glyph space metric outside range of a \"short\", actual: " + roundedResult);
}
return (short) roundedResult;
}
@@ -945,15 +945,6 @@
}
/**
- * Returns the logger.
- * @return The logger.
- */
- private Logger getLogger() {
- /* Not cached because not expected to get used much. */
- return LoggerFactory.getLogger(getClass());
- }
-
- /**
* Returns the format of this font.
* @return The format of this font.
*/
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 21:27:18 UTC (rev 13576)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 22:32:05 UTC (rev 13577)
@@ -52,13 +52,41 @@
@SuppressWarnings("unused")
private LocaTable table;
+ /** Indicates whether the long format (true) or the short format (false) should be used. This information is
+ * derived from the "head" table. */
+ private boolean isLongFormat;
+
+ /** The number of glyph entries to be parsed. This information is derived from the "maxp" table. */
+ private int numberOfGlyphs;
+
/**
* Constructor.
* @param table The table instance being created.
+ * @param isLongFormat Indicates whether the long format (true) or the short format (false) should be used.
+ * This information is derived from the "head" table.
+ * @param numberOfGlyphs The number of glyph entries to be parsed.
+ * This information is derived from the "maxp" table.
*/
- private ContentHandler(final LocaTable table) {
+ private ContentHandler(final LocaTable table, final boolean isLongFormat, final int numberOfGlyphs) {
this.table = table;
+ this.isLongFormat = isLongFormat;
+ this.numberOfGlyphs = numberOfGlyphs;
+ if (isLongFormat) {
+ table.longOffsets = new @Unsigned int[numberOfGlyphs + 1];
+ } else {
+ table.shortOffsets = new @Unsigned short[numberOfGlyphs + 1];
+ }
}
+
+ @Override
+ public boolean isLongFormat() {
+ return this.isLongFormat;
+ }
+
+ @Override
+ public int getNumberOfGlyphs() {
+ return this.numberOfGlyphs;
+ }
}
@@ -67,6 +95,9 @@
+
+
+
/** The array of offsets, if using the short format. If not, must be null. */
private @Unsigned short[] shortOffsets;
@@ -75,11 +106,16 @@
/**
* Creates a table instance and a content handler for that instance.
+ * @param isLongFormat Indicates whether the long format (true) or the short format (false) should be used.
+ * This information is derived from the "head" table.
+ * @param numberOfGlyphs The number of glyph entries to be parsed.
+ * This information is derived from the "maxp" table.
* @return A new content handler.
*/
- public static ParserKit<LocaTable, LocaTableHandler> createContentHandler() {
+ public static ParserKit<LocaTable, LocaTableHandler> createContentHandler(final boolean isLongFormat,
+ final int numberOfGlyphs) {
final LocaTable table = new LocaTable();
- final LocaTableHandler handler = table.new ContentHandler(table);
+ final LocaTableHandler handler = table.new ContentHandler(table, isLongFormat, numberOfGlyphs);
return new ParserKit<LocaTable, LocaTableHandler>(table, handler);
}
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java 2025-05-02 21:27:18 UTC (rev 13576)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java 2025-05-02 22:32:05 UTC (rev 13577)
@@ -31,6 +31,8 @@
import org.foray.fontParse.TableParser;
import org.foray.fontParse.ttfHandler.LocaTableHandler;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
import java.io.IOException;
/**
@@ -44,7 +46,26 @@
throws IOException {
input.seek(offset);
- /* TODO: Complete this. */
+ final boolean isLongFormat = handler.isLongFormat();
+ final int numGlyphs = handler.getNumberOfGlyphs();
+
+
+ /* Reads n + 1 values, where n = numberOfGlyphs. */
+ final @Unsigned int[] longOffsets = new @Unsigned int[numGlyphs + 1];
+ final @Unsigned short[] shortOffsets = new @Unsigned short[numGlyphs + 1];
+ for (int index = 0; index <= numGlyphs; index ++) {
+ if (isLongFormat) {
+ final @Unsigned int longOffset = input.read_Offset32();
+ handler.longOffset(longOffset);
+ longOffsets[index] = longOffset;
+ } else {
+ final @Unsigned short shortOffset = input.read_Offset16();
+ handler.shortOffset(shortOffset);
+ longOffsets[index] = shortOffset;
+ }
+ }
+ handler.longOffsets(longOffsets);
+ handler.shortOffsets(shortOffsets);
}
}
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java 2025-05-02 21:27:18 UTC (rev 13576)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java 2025-05-02 22:32:05 UTC (rev 13577)
@@ -31,11 +31,34 @@
import org.foray.fontParse.FontContentHandler;
import org.foray.fontParse.ttf.LocaTableParser;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
/**
* Implementations catch and handle the output from {@link LocaTableParser}.
*/
public interface LocaTableHandler extends FontContentHandler {
- /* TODO: Complete this. */
+ /**
+ * Unlike most handler methods which are essentially "setters", this method is a getter.
+ * The value is obtained from the "head" table, "indexToLocFormat" field.
+ * Also unlike most handler methods, implementation of this method is required.
+ * @return True if the long format of offsets is used, false if the short format is used.
+ */
+ boolean isLongFormat();
+ /**
+ * Unlike most handler methods which are essentially "setters", this method is a getter.
+ * Although not documented as such, this value is obtained the same way that it is for
+ * {@link HmtxTableHandler#getNumberOfGlyphs()}, this is, from the "maxp" table, "numGlyphs" field.
+ * Also unlike most handler methods, implementation of this method is required.
+ * @return The total number of glyphs in this font.
+ */
+ int getNumberOfGlyphs();
+
+ default void longOffset(@Unsigned final int value) { return; }
+ default void shortOffset(@Unsigned final short value) { return; }
+
+ default void longOffsets(@Unsigned final int[] value) { return; }
+ default void shortOffsets(@Unsigned final short[] value) { return; }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 21:27:35
|
Revision: 13576
http://sourceforge.net/p/foray/code/13576
Author: victormote
Date: 2025-05-02 21:27:18 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Remove class MtxEntry and move remaining contents to HmtxTable.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java
Removed Paths:
-------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 19:30:32 UTC (rev 13575)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 21:27:18 UTC (rev 13576)
@@ -864,10 +864,10 @@
* @return The widths of the glyphs in this font.
*/
public ShortSequence getWidths() {
- final ShortArrayBuilder wx = new ShortArrayBuilder(this.hmtxTable.numMtxEntries());
- wx.setLength(this.hmtxTable.numMtxEntries());
+ final ShortArrayBuilder wx = new ShortArrayBuilder(this.hmtxTable.size());
+ wx.setLength(this.hmtxTable.size());
for (int i = 0; i < wx.length(); i++) {
- wx.setShortAt(i, convertFunitsToMillipoints(this.hmtxTable.getMtxEntry(i).getWidth()));
+ wx.setShortAt(i, convertFunitsToMillipoints(this.hmtxTable.getWidth(i)));
}
return wx.toImmutable();
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 19:30:32 UTC (rev 13575)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 21:27:18 UTC (rev 13576)
@@ -34,7 +34,6 @@
import org.foray.font.ttf.table.HeadTable;
import org.foray.font.ttf.table.HmtxTable;
import org.foray.font.ttf.table.LocaTable;
-import org.foray.font.ttf.table.MtxEntry;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.axsl.constants.PrimitiveConstants;
@@ -532,10 +531,8 @@
final HmtxTable hmtx = this.ttfFont.getHmtxTable();
for (int i = 0; i < this.subset.numGlyphsUsed(); i ++) {
final int originalIndex = this.subset.decodeSubsetIndex(i);
- final MtxEntry metricEntry = hmtx.getMtxEntry(originalIndex);
- writeUShort(byteArray, i * entrySize, metricEntry.getWidth());
- writeUShort(byteArray, (i * entrySize) + widthSize,
- metricEntry.getLeftSideBearing());
+ writeUShort(byteArray, i * entrySize, hmtx.getWidth(originalIndex));
+ writeUShort(byteArray, (i * entrySize) + widthSize, hmtx.getLeftSideBearing(originalIndex));
}
return byteArray;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java 2025-05-02 19:30:32 UTC (rev 13575)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java 2025-05-02 21:27:18 UTC (rev 13576)
@@ -68,11 +68,8 @@
this.table = table;
this.numGlyphs = numGlyphs;
this.numOfHMetrics = numOfHMetrics;
- final int metricsSize = Math.max(numGlyphs, numOfHMetrics);
- table.metrics = new MtxEntry[metricsSize];
- for (int i = 0; i < metricsSize; i++) {
- table.metrics[i] = new MtxEntry();
- }
+ table.advanceWidth = new @Unsigned short[numOfHMetrics];
+ table.lsb = new short[numOfHMetrics];
}
@Override
@@ -88,22 +85,17 @@
@Override
public void advanceWidth(final @Unsigned short value) {
this.currentIndex ++;
- this.table.metrics[this.currentIndex].setWidth(value);
+ this.table.advanceWidth[this.currentIndex] = value;
}
@Override
public void lsb(final short value) {
- this.table.metrics[this.currentIndex].setLeftSideBearing(value);
+ this.table.lsb[this.currentIndex] = value;
}
@Override
public void leftSideBearings(final short[] value) {
- final int lastWidth = table.metrics[numOfHMetrics - 1].getWidth();
- for (int index = 0; index < value.length; index ++) {
- final int metricIndex = this.numOfHMetrics + index;
- table.metrics[metricIndex].setWidth(lastWidth);
- table.metrics[metricIndex].setLeftSideBearing(value[index]);
- }
+ this.table.leftSideBearings = value;
}
}
@@ -116,9 +108,15 @@
- /** The metrics entries for this table. */
- private MtxEntry[] metrics;
+ /** The glyph width. */
+ private @Unsigned short[] advanceWidth;
+ /** The glyph left side bearing. */
+ private short[] lsb;
+
+ /** Left side bearings for glyphIDs greater than or equal to numberOfHMetrics. */
+ private short[] leftSideBearings;
+
/**
* Creates a table instance and a content handler for that instance.
* @param numGlyphs The total number of glyphs in this font, obtained from the "maxp" table, "numGlyphs" field.
@@ -134,28 +132,37 @@
}
/**
- * Return a specific metric record.
- * @param index The index to the desired metric record.
- * @return The metric record corresponding to {@code index}.
+ * Returns the width of a given glyph, in text space units.
+ * @param glyphIndex The index to the desired glyph.
+ * @return The width of the glyph at {@code glyphIndex}.
*/
- public MtxEntry getMtxEntry(final int index) {
- if (this.metrics == null
- || index < 0
- || index > this.metrics.length - 1) {
- return null;
+ public int getWidth(final int glyphIndex) {
+ if (glyphIndex >= this.advanceWidth.length) {
+ return this.advanceWidth[this.advanceWidth.length - 1];
+ } else {
+ return this.advanceWidth[glyphIndex];
}
- return this.metrics[index];
}
/**
- * Returns the number of metric records in this table.
- * @return The number of metric records in this table.
+ * Returns the left side bearing for this entry.
+ * @param glyphIndex The index to the desired glyph.
+ * @return The left side bearing for this entry.
*/
- public int numMtxEntries() {
- if (this.metrics == null) {
- return 0;
+ public int getLeftSideBearing(final int glyphIndex) {
+ if (glyphIndex >= this.lsb.length) {
+ return this.leftSideBearings[glyphIndex - this.lsb.length];
+ } else {
+ return this.lsb[glyphIndex];
}
- return this.metrics.length;
}
+ /**
+ * Returns the number of entries in this table.
+ * @return The number of entries in this table.
+ */
+ public int size() {
+ return this.lsb.length + this.leftSideBearings.length;
+ }
+
}
Deleted: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java 2025-05-02 19:30:32 UTC (rev 13575)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java 2025-05-02 21:27:18 UTC (rev 13576)
@@ -1,75 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font.ttf.table;
-
-/**
- * A TTF Font Mtx entry.
- */
-public class MtxEntry {
-
- /** The glyph width. */
- private int wx;
-
- /** The glyph left side bearing. */
- private int lsb;
-
-
- /**
- * Set the width of this entry, in text space units.
- * @param width The new width for this entry.
- */
- public void setWidth(final int width) {
- this.wx = width;
- }
-
- /**
- * Returns the width of this entry, in text space units.
- * @return The width of this entry.
- */
- public int getWidth() {
- return this.wx;
- }
-
- /**
- * Returns the left side bearing for this entry.
- * @return The left side bearing for this entry.
- */
- public int getLeftSideBearing() {
- return this.lsb;
- }
-
- /**
- * Sets the left side bearing for this entry.
- * @param leftSideBearing The new left side bearing value.
- */
- public void setLeftSideBearing(final int leftSideBearing) {
- this.lsb = leftSideBearing;
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 19:30:53
|
Revision: 13575
http://sourceforge.net/p/foray/code/13575
Author: victormote
Date: 2025-05-02 19:30:32 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Unbind glyf values from htmx values, now storing glyf values in the GlyfTable class.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2025-05-02 18:58:44 UTC (rev 13574)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2025-05-02 19:30:32 UTC (rev 13575)
@@ -256,7 +256,7 @@
@Override
public BoundingBox getGlyphBoundingBox(final int glyphIndex, final int fontSize) {
- final BoundingBox raw = this.ttf.getHmtxTable().getMtxEntry(glyphIndex).getBoundingBox();
+ final BoundingBox raw = this.ttf.getGlyfTable().getBoundingBox(glyphIndex);
final short[] scaled = new short[BoundingBox.QTY_ENTRIES];
for (int index = 0; index < BoundingBox.QTY_ENTRIES; index ++) {
scaled[index] = this.ttf.convertFunitsToMillipoints(raw.getCoordinateAsInt(index));
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 18:58:44 UTC (rev 13574)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 19:30:32 UTC (rev 13575)
@@ -51,7 +51,6 @@
import org.foray.font.ttf.table.LocaTable;
import org.foray.font.ttf.table.MathTable;
import org.foray.font.ttf.table.MaxpTable;
-import org.foray.font.ttf.table.MtxEntry;
import org.foray.font.ttf.table.NameTable;
import org.foray.font.ttf.table.Os2Table;
import org.foray.font.ttf.table.PcltTable;
@@ -337,7 +336,7 @@
if (dirEntry != null) {
final boolean isLongFormat = font.headTable.longLocaFormat();
font.locaTable = LocaTable.parse(raInput, dirEntry.getOffset(), dirEntry.getLength(), isLongFormat,
- numberOfGlyphs, font.hmtxTable);
+ numberOfGlyphs);
}
/* glyf must be parsed after hmtx and loca. */
@@ -344,7 +343,7 @@
dirEntry = ttfTableDir.getTableDirectoryEntry("glyf");
if (dirEntry != null) {
font.glyfTable = GlyfTable.parse(raInput, dirEntry.getOffset(), dirEntry.getLength(), numberOfGlyphs,
- font.hmtxTable, font.locaTable);
+ font.locaTable);
}
dirEntry = ttfTableDir.getTableDirectoryEntry("prep");
@@ -769,8 +768,7 @@
/* No metrics for "H". */
return -1;
} else {
- final MtxEntry mtx = this.hmtxTable.getMtxEntry(metricIndex);
- return mtx.getBoundingBox().computeHeightAsInt();
+ return this.glyfTable.getBoundingBox(metricIndex).computeHeightAsInt();
}
}
@@ -792,8 +790,7 @@
/* No metrics for "x". */
return -1;
} else {
- final MtxEntry mtx = this.hmtxTable.getMtxEntry(metricIndex);
- return mtx.getBoundingBox().computeHeightAsInt();
+ return this.glyfTable.getBoundingBox(metricIndex).computeHeightAsInt();
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java 2025-05-02 18:58:44 UTC (rev 13574)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java 2025-05-02 19:30:32 UTC (rev 13575)
@@ -103,6 +103,12 @@
/** The bit in the composite flag indicating USE_MY_METRICS. */
public static final byte CF_BIT_USE_MY_METRICS = 9;
+
+ /** The glyph bounding boxes. */
+ private BoundingBox[] bbox;
+
+
+
/**
* Creates a table instance and a content handler for that instance.
* @return A new content handler.
@@ -120,18 +126,16 @@
* @param length The number of bytes to parse from {@code input}.
* @param numberOfGlyphs The number of glyphs to be parsed.
* This data is derived from the "maxp" table.
- * @param hmtx The related horizontal metrics (hmtx) table.
* @param loca The loca table.
* @return The parsed instance.
* @throws IOException For I/O Error.
*/
public static GlyfTable parse(final RandomAccessInput input, final int offset, final int length,
- final int numberOfGlyphs, final HmtxTable hmtx, final LocaTable loca) throws IOException {
+ final int numberOfGlyphs, final LocaTable loca) throws IOException {
input.seek(offset);
final GlyfTable glyf = new GlyfTable();
- final MtxEntry firstMetric = hmtx.getMtxEntry(0);
+ glyf.bbox = new BoundingBoxShort[numberOfGlyphs];
for (int i = 0; i < (numberOfGlyphs - 1); i++) {
- final MtxEntry thisMetric = hmtx.getMtxEntry(i);
final int thisOffset = loca.getOffset(i);
final int nextOffset = loca.getOffset(i + 1);
if (thisOffset != nextOffset) {
@@ -141,18 +145,17 @@
for (int j = 0; j < BoundingBox.QTY_ENTRIES; j++) {
bboxEntries[j] = input.readShort();
}
- thisMetric.setBoundingBox(new BoundingBoxShort(bboxEntries));
+ glyf.bbox[i] = new BoundingBoxShort(bboxEntries);
} else {
- thisMetric.setBoundingBox(firstMetric.getBoundingBox());
+ glyf.bbox[i] = glyf.bbox[0];
}
}
final int n = offset;
for (int i = 0; i < numberOfGlyphs; i++) {
- final MtxEntry thisMetric = hmtx.getMtxEntry(i);
final int thisOffset = loca.getOffset(i);
final int nextOffset = loca.getOffset(i + 1);
- if ((i + 1) >= hmtx.numMtxEntries()
+ if ((i + 1) >= numberOfGlyphs
|| thisOffset != nextOffset) {
input.seek(n + thisOffset);
input.skipBytes(2);
@@ -160,9 +163,9 @@
for (int j = 0; j < BoundingBox.QTY_ENTRIES; j++) {
bboxEntries[j] = input.readShort();
}
- thisMetric.setBoundingBox(new BoundingBoxShort(bboxEntries));
+ glyf.bbox[i] = new BoundingBoxShort(bboxEntries);
} else {
- thisMetric.setBoundingBox(firstMetric.getBoundingBox());
+ glyf.bbox[i] = glyf.bbox[0];
}
}
return glyf;
@@ -211,4 +214,25 @@
return BitUtils.getBit(compositeFlags, GlyfTable.CF_BIT_MORE_COMPONENTS);
}
+ /**
+ * Returns the total vertical size of the glyph at a given index.
+ * @param glyphIndex The glyphIndex for which the height should be returned.
+ * @return The total vertical size, in millipoints, of the glyph at {@code glyphIndex}.
+ */
+ public int getHeight(final int glyphIndex) {
+ if (this.bbox == null) {
+ return 0;
+ }
+ return this.bbox[glyphIndex].computeHeightAsInt();
+ }
+
+ /**
+ * Returns the bounding box for this entry.
+ * @param glyphIndex The glyphIndex for which the height should be returned.
+ * @return The bounding box.
+ */
+ public BoundingBox getBoundingBox(final int glyphIndex) {
+ return this.bbox[glyphIndex];
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 18:58:44 UTC (rev 13574)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 19:30:32 UTC (rev 13575)
@@ -92,12 +92,11 @@
* This information is derived from the "head" table.
* @param numberOfGlyphs The number of glyph entries to be parsed.
* This information is derived from the "maxp" table.
- * @param hmtx The horizontal metrics ("hmtx") table.
* @return The parsed instance.
* @throws IOException For I/O Error.
*/
public static LocaTable parse(final TtfRandomAccessInput input, final int offset, final int length,
- final boolean isLongFormat, final int numberOfGlyphs, final HmtxTable hmtx) throws IOException {
+ final boolean isLongFormat, final int numberOfGlyphs) throws IOException {
input.seek(offset);
final LocaTable loca = new LocaTable();
if (isLongFormat) {
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java 2025-05-02 18:58:44 UTC (rev 13574)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java 2025-05-02 19:30:32 UTC (rev 13575)
@@ -28,8 +28,6 @@
package org.foray.font.ttf.table;
-import org.axsl.ps.BoundingBox;
-
/**
* A TTF Font Mtx entry.
*/
@@ -41,21 +39,8 @@
/** The glyph left side bearing. */
private int lsb;
- /** The glyph bounding box. */
- private BoundingBox bbox;
/**
- * Returns the total vertical size of this character.
- * @return The total vertical size, in millipoints, of this character.
- */
- public int getHeight() {
- if (this.bbox == null) {
- return 0;
- }
- return this.bbox.computeHeightAsInt();
- }
-
- /**
* Set the width of this entry, in text space units.
* @param width The new width for this entry.
*/
@@ -87,20 +72,4 @@
this.lsb = leftSideBearing;
}
- /**
- * Returns the bounding box for this entry.
- * @return The bounding box.
- */
- public BoundingBox getBoundingBox() {
- return this.bbox;
- }
-
- /**
- * Sets the bounding box for this entry.
- * @param boundingBox The new bounding box.
- */
- public void setBoundingBox(final BoundingBox boundingBox) {
- this.bbox = boundingBox;
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 18:59:01
|
Revision: 13574
http://sourceforge.net/p/foray/code/13574
Author: victormote
Date: 2025-05-02 18:58:44 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Unbind loca values from htmx values, now storing loca values in the LocaTable class.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 17:50:14 UTC (rev 13573)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 18:58:44 UTC (rev 13574)
@@ -340,10 +340,11 @@
numberOfGlyphs, font.hmtxTable);
}
+ /* glyf must be parsed after hmtx and loca. */
dirEntry = ttfTableDir.getTableDirectoryEntry("glyf");
if (dirEntry != null) {
font.glyfTable = GlyfTable.parse(raInput, dirEntry.getOffset(), dirEntry.getLength(), numberOfGlyphs,
- font.hmtxTable);
+ font.hmtxTable, font.locaTable);
}
dirEntry = ttfTableDir.getTableDirectoryEntry("prep");
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 17:50:14 UTC (rev 13573)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 18:58:44 UTC (rev 13574)
@@ -33,6 +33,7 @@
import org.foray.font.ttf.table.GlyfTable;
import org.foray.font.ttf.table.HeadTable;
import org.foray.font.ttf.table.HmtxTable;
+import org.foray.font.ttf.table.LocaTable;
import org.foray.font.ttf.table.MtxEntry;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
@@ -462,12 +463,11 @@
final byte[] byteArray = createTableByteArray(arraySize);
int cumulativeSize = 0;
- final HmtxTable hmtx = this.ttfFont.getHmtxTable();
+ final LocaTable loca = this.ttfFont.getLocaTable();
for (int i = 0; i < this.subset.numGlyphsUsed(); i++) {
final int origGlyphIndex = this.subset.decodeSubsetIndex(i);
final int glyphLength = computeGlyphLength(origGlyphIndex);
- final MtxEntry mtx = hmtx.getMtxEntry(origGlyphIndex);
- final int glyphOffset = (int) mtx.getOffset();
+ final int glyphOffset = loca.getOffset(origGlyphIndex);
final int fileOffset = entry.getOffset() + glyphOffset;
// Copy glyph
System.arraycopy(
@@ -498,25 +498,16 @@
}
/**
- * Returns the number of bytes that should be read for the glyph drawing
- * instructions of a specific glyph.
+ * Returns the number of bytes that should be read for the glyph drawing instructions of a specific glyph.
* @param origGlyphIndex The glyph index whose size is needed.
- * @return The number of bytes that should be read for the glyph drawing for
- * this glyph.
+ * @return The number of bytes that should be read for the glyph drawing for this glyph.
* @throws IOException For I/O Error.
*/
- private int computeGlyphLength(final int origGlyphIndex)
- throws IOException {
- int nextOffset = 0;
- final HmtxTable hmtx = this.ttfFont.getHmtxTable();
- if (origGlyphIndex >= (hmtx.numMtxEntries() - 1)) {
- nextOffset = (int) this.ttfFont.getLocaTable().lastOffset();
- } else {
- nextOffset = (int) hmtx.getMtxEntry(origGlyphIndex + 1).getOffset();
- }
+ private int computeGlyphLength(final int origGlyphIndex) throws IOException {
+ final LocaTable loca = this.ttfFont.getLocaTable();
+ final int nextOffset = loca.getOffset(origGlyphIndex + 1);
int glyphLength = 0;
- glyphLength = nextOffset - (int) hmtx.getMtxEntry(origGlyphIndex)
- .getOffset();
+ glyphLength = nextOffset - loca.getOffset(origGlyphIndex);
return glyphLength;
}
@@ -562,9 +553,9 @@
final List<Integer> ret = new ArrayList<Integer>();
ret.add(glyphIdx);
int offset = glyphOffset;
- final HmtxTable hmtxTable = this.ttfFont.getHmtxTable();
- final MtxEntry mtxEntry = hmtxTable.getMtxEntry(glyphIdx.intValue());
- offset += (int) mtxEntry.getOffset();
+ final LocaTable locaTable = this.ttfFont.getLocaTable();
+ final int glyphIndex = glyphIdx.intValue();
+ offset += locaTable.getOffset(glyphIndex);
offset += GlyfTable.HEADER_SIZE;
Integer compositeIdx = null;
int flags = 0;
@@ -654,13 +645,12 @@
final Map<Integer, Integer> usedCompositeGlyphs
= new HashMap<Integer, Integer>();
boolean stillCheckingForCompositeGlyphs = true;
- final HmtxTable hmtx = this.ttfFont.getHmtxTable();
+ final LocaTable loca = this.ttfFont.getLocaTable();
while (stillCheckingForCompositeGlyphs) {
boolean anyGlyphsAdded = false;
for (int i = 0; i < this.subset.numGlyphsUsed(); i++) {
final int originalIndex = this.subset.decodeSubsetIndex(i);
- final long glyphOffset = hmtx.getMtxEntry(originalIndex)
- .getOffset();
+ final int glyphOffset = loca.getOffset(originalIndex);
/*
* Save the current position so that we can go back to it after
* this test.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java 2025-05-02 17:50:14 UTC (rev 13573)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java 2025-05-02 18:58:44 UTC (rev 13574)
@@ -121,19 +121,21 @@
* @param numberOfGlyphs The number of glyphs to be parsed.
* This data is derived from the "maxp" table.
* @param hmtx The related horizontal metrics (hmtx) table.
+ * @param loca The loca table.
* @return The parsed instance.
* @throws IOException For I/O Error.
*/
public static GlyfTable parse(final RandomAccessInput input, final int offset, final int length,
- final int numberOfGlyphs, final HmtxTable hmtx) throws IOException {
+ final int numberOfGlyphs, final HmtxTable hmtx, final LocaTable loca) throws IOException {
input.seek(offset);
final GlyfTable glyf = new GlyfTable();
final MtxEntry firstMetric = hmtx.getMtxEntry(0);
for (int i = 0; i < (numberOfGlyphs - 1); i++) {
final MtxEntry thisMetric = hmtx.getMtxEntry(i);
- final MtxEntry nextMetric = hmtx.getMtxEntry(i + 1);
- if (thisMetric.getOffset() != nextMetric.getOffset()) {
- input.seek(offset + thisMetric.getOffset());
+ final int thisOffset = loca.getOffset(i);
+ final int nextOffset = loca.getOffset(i + 1);
+ if (thisOffset != nextOffset) {
+ input.seek(offset + thisOffset);
input.skipBytes(2);
final short[] bboxEntries = new short[BoundingBox.QTY_ENTRIES];
for (int j = 0; j < BoundingBox.QTY_ENTRIES; j++) {
@@ -148,10 +150,11 @@
final int n = offset;
for (int i = 0; i < numberOfGlyphs; i++) {
final MtxEntry thisMetric = hmtx.getMtxEntry(i);
- final MtxEntry nextMetric = hmtx.getMtxEntry(i + 1);
+ final int thisOffset = loca.getOffset(i);
+ final int nextOffset = loca.getOffset(i + 1);
if ((i + 1) >= hmtx.numMtxEntries()
- || thisMetric.getOffset() != nextMetric.getOffset()) {
- input.seek(n + thisMetric.getOffset());
+ || thisOffset != nextOffset) {
+ input.seek(n + thisOffset);
input.skipBytes(2);
final short[] bboxEntries = new short[BoundingBox.QTY_ENTRIES];
for (int j = 0; j < BoundingBox.QTY_ENTRIES; j++) {
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 17:50:14 UTC (rev 13573)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 18:58:44 UTC (rev 13574)
@@ -28,11 +28,13 @@
package org.foray.font.ttf.table;
-import org.foray.common.RandomAccessInput;
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.fontParse.ttfHandler.LocaTableHandler;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
import java.io.IOException;
/**
@@ -65,13 +67,12 @@
+ /** The array of offsets, if using the short format. If not, must be null. */
+ private @Unsigned short[] shortOffsets;
+ /** The array of offsets, if using the long format. If not, must be null. */
+ private @Unsigned int[] longOffsets;
-
- /** The last offset value in the table, which points to no glyph, but
- * exists to be able to compute the size of the previous entry. */
- private long lastOffset = 0;
-
/**
* Creates a table instance and a content handler for that instance.
* @return A new content handler.
@@ -95,31 +96,35 @@
* @return The parsed instance.
* @throws IOException For I/O Error.
*/
- public static LocaTable parse(final RandomAccessInput input, final int offset, final int length,
+ public static LocaTable parse(final TtfRandomAccessInput input, final int offset, final int length,
final boolean isLongFormat, final int numberOfGlyphs, final HmtxTable hmtx) throws IOException {
input.seek(offset);
final LocaTable loca = new LocaTable();
- for (int i = 0; i < numberOfGlyphs; i++) {
- final long entry;
+ if (isLongFormat) {
+ loca.longOffsets = new @Unsigned int[numberOfGlyphs + 1];
+ } else {
+ loca.shortOffsets = new @Unsigned short[numberOfGlyphs + 1];
+ }
+
+ /* Reads n + 1 values, where n = numberOfGlyphs. */
+ for (int i = 0; i <= numberOfGlyphs; i++) {
if (isLongFormat) {
- entry = input.readUnsignedInt();
+ loca.longOffsets[i] = input.read_Offset32();
} else {
- entry = input.readUnsignedShort() << 1;
+ loca.shortOffsets[i] = input.read_Offset16();
}
- hmtx.getMtxEntry(i).setOffset(entry);
}
- loca.lastOffset = input.readUnsignedInt();
return loca;
}
/**
- * Returns the last offset value in the table.
- * Note that this offset points to no glyph, but exists only for purposes
- * of computing the size of the last valid item.
- * @return The last offset value in the table.
+ * Returns the offset for a given glyph index.
+ * @param glyphIndex The glyph index for which the offset should be returned.
+ * @return The offset at {@code glyphIndex}.
*/
- public long lastOffset() {
- return this.lastOffset;
+ public @Unsigned int getOffset(final @Unsigned int glyphIndex) {
+ return this.shortOffsets == null ? this.longOffsets[glyphIndex] :
+ Short.toUnsignedInt(this.shortOffsets[glyphIndex]) * 2;
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java 2025-05-02 17:50:14 UTC (rev 13573)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/MtxEntry.java 2025-05-02 18:58:44 UTC (rev 13574)
@@ -44,16 +44,7 @@
/** The glyph bounding box. */
private BoundingBox bbox;
- /** Obtained from the "loca" table. */
- private long offset;
-
/**
- * Constructor.
- */
- MtxEntry() {
- }
-
- /**
* Returns the total vertical size of this character.
* @return The total vertical size, in millipoints, of this character.
*/
@@ -81,22 +72,6 @@
}
/**
- * Returns the offset of the glyf information for this entry.
- * @return The offset of the glyf information for this entry.
- */
- public long getOffset() {
- return this.offset;
- }
-
- /**
- * Sets the offset of the glyf information for this entry.
- * @param offset The new offset to the glyf information for this entry.
- */
- public void setOffset(final long offset) {
- this.offset = offset;
- }
-
- /**
* Returns the left side bearing for this entry.
* @return The left side bearing for this entry.
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 17:50:43
|
Revision: 13573
http://sourceforge.net/p/foray/code/13573
Author: victormote
Date: 2025-05-02 17:50:14 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Convert htmx table to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 16:12:13 UTC (rev 13572)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 17:50:14 UTC (rev 13573)
@@ -72,6 +72,7 @@
import org.foray.fontParse.ttf.GsubTableParser;
import org.foray.fontParse.ttf.HeadTableParser;
import org.foray.fontParse.ttf.HheaTableParser;
+import org.foray.fontParse.ttf.HmtxTableParser;
import org.foray.fontParse.ttf.JstfTableParser;
import org.foray.fontParse.ttf.KernTableParser;
import org.foray.fontParse.ttf.MathTableParser;
@@ -95,6 +96,7 @@
import org.foray.fontParse.ttfHandler.GsubTableHandler;
import org.foray.fontParse.ttfHandler.HeadTableHandler;
import org.foray.fontParse.ttfHandler.HheaTableHandler;
+import org.foray.fontParse.ttfHandler.HmtxTableHandler;
import org.foray.fontParse.ttfHandler.JstfTableHandler;
import org.foray.fontParse.ttfHandler.KernTableHandler;
import org.foray.fontParse.ttfHandler.MathTableHandler;
@@ -279,13 +281,21 @@
font.hheaTable = parseKit.getTable();
}
+
+
+
/* After this point, the order may not matter. */
dirEntry = ttfTableDir.getTableDirectoryEntry("hmtx");
final int numberOfGlyphs = font.maxpTable.getNumberOfGlyphs();
final int numberOfHMetrics = font.hheaTable.getNumberOfHMetrics();
- font.hmtxTable = HmtxTable.parse(raInput, dirEntry.getOffset(), dirEntry.getLength(), numberOfGlyphs,
- numberOfHMetrics);
+ {
+ final ParserKit<HmtxTable, HmtxTableHandler> parseKit =
+ HmtxTable.createContentHandler(numberOfGlyphs, numberOfHMetrics);
+ final HmtxTableParser parser = new HmtxTableParser();
+ parser.parse(raInput, dirEntry.getOffset(), parseKit.getHandler());
+ font.hmtxTable = parseKit.getTable();
+ }
dirEntry = ttfTableDir.getTableDirectoryEntry("post");
{
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java 2025-05-02 16:12:13 UTC (rev 13572)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java 2025-05-02 17:50:14 UTC (rev 13573)
@@ -28,12 +28,11 @@
package org.foray.font.ttf.table;
-import org.foray.common.RandomAccessInput;
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
import org.foray.fontParse.ttfHandler.HmtxTableHandler;
-import java.io.IOException;
+import org.checkerframework.checker.signedness.qual.Unsigned;
/**
* Class representing a TTF "hmtx" (horizontal metrics) table.
@@ -46,16 +45,66 @@
private final class ContentHandler implements HmtxTableHandler {
/** The table instance being created. */
- @SuppressWarnings("unused")
private HmtxTable table;
+ /** The total number of glyphs in this font, obtained from the "maxp" table, "numGlyphs" field. */
+ private int numGlyphs;
+
+ /** The total number of horizontal metrics in this font, obtained from the "hhea" table, "numberOfHMetrics"
+ * field. */
+ private int numOfHMetrics;
+
+ /** Index of the metrics record currently being parsed. */
+ private int currentIndex = -1;
+
/**
* Constructor.
* @param table The table instance being created.
+ * @param numGlyphs The total number of glyphs in this font, obtained from the "maxp" table, "numGlyphs" field.
+ * @param numOfHMetrics The total number of horizontal metrics in this font, obtained from the "hhea" table,
+ * "numberOfHMetrics" field.
*/
- private ContentHandler(final HmtxTable table) {
+ private ContentHandler(final HmtxTable table, final int numGlyphs, final int numOfHMetrics) {
this.table = table;
+ this.numGlyphs = numGlyphs;
+ this.numOfHMetrics = numOfHMetrics;
+ final int metricsSize = Math.max(numGlyphs, numOfHMetrics);
+ table.metrics = new MtxEntry[metricsSize];
+ for (int i = 0; i < metricsSize; i++) {
+ table.metrics[i] = new MtxEntry();
+ }
}
+
+ @Override
+ public int getNumberOfGlyphs() {
+ return this.numGlyphs;
+ }
+
+ @Override
+ public int getNumberOfHMetrics() {
+ return this.numOfHMetrics;
+ }
+
+ @Override
+ public void advanceWidth(final @Unsigned short value) {
+ this.currentIndex ++;
+ this.table.metrics[this.currentIndex].setWidth(value);
+ }
+
+ @Override
+ public void lsb(final short value) {
+ this.table.metrics[this.currentIndex].setLeftSideBearing(value);
+ }
+
+ @Override
+ public void leftSideBearings(final short[] value) {
+ final int lastWidth = table.metrics[numOfHMetrics - 1].getWidth();
+ for (int index = 0; index < value.length; index ++) {
+ final int metricIndex = this.numOfHMetrics + index;
+ table.metrics[metricIndex].setWidth(lastWidth);
+ table.metrics[metricIndex].setLeftSideBearing(value[index]);
+ }
+ }
}
@@ -72,55 +121,19 @@
/**
* Creates a table instance and a content handler for that instance.
+ * @param numGlyphs The total number of glyphs in this font, obtained from the "maxp" table, "numGlyphs" field.
+ * @param numOfHMetrics The total number of horizontal metrics in this font, obtained from the "hhea" table,
+ * "numberOfHMetrics" field.
* @return A new content handler.
*/
- public static ParserKit<HmtxTable, HmtxTableHandler> createContentHandler() {
+ public static ParserKit<HmtxTable, HmtxTableHandler> createContentHandler(final int numGlyphs,
+ final int numOfHMetrics) {
final HmtxTable table = new HmtxTable();
- final HmtxTableHandler handler = table.new ContentHandler(table);
+ final HmtxTableHandler handler = table.new ContentHandler(table, numGlyphs, numOfHMetrics);
return new ParserKit<HmtxTable, HmtxTableHandler>(table, handler);
}
/**
- * Read "hmtx" table and put the horizontal metrics in the metrics array.
- * If the number of metrics is less than the number of glyphs (eg fixed size fonts), extend the metrics array and
- * fill in the missing widths.
- * @param input The input which is being parsed.
- * @param offset The offset into {@code input} at which to start parsing.
- * @param length The number of bytes to parse from {@code input}.
- * @param numberOfGlyphs The number of glyphs in the font.
- * This information is derived from the "maxp" table.
- * @param numberOfHMetrics The number of horizontal metrics in the font.
- * This information is derived from the "hhea" table.
- * @return The parsed instance.
- * @throws IOException For I/O Error.
- */
- public static HmtxTable parse(final RandomAccessInput input, final int offset, final int length,
- final int numberOfGlyphs, final int numberOfHMetrics) throws IOException {
- input.seek(offset);
- final HmtxTable hmtx = new HmtxTable();
- final int metricsSize = Math.max(numberOfGlyphs, numberOfHMetrics);
- hmtx.metrics = new MtxEntry[metricsSize];
-
- for (int i = 0; i < metricsSize; i++) {
- hmtx.metrics[i] = new MtxEntry();
- }
- for (int i = 0; i < numberOfHMetrics; i++) {
- hmtx.metrics[i].setWidth(input.readUnsignedShort());
- hmtx.metrics[i].setLeftSideBearing(input.readShort());
- }
-
- if (numberOfHMetrics < metricsSize) {
- // Fill in the missing widths
- final int lastWidth = hmtx.metrics[numberOfHMetrics - 1].getWidth();
- for (int i = numberOfHMetrics; i < metricsSize; i++) {
- hmtx.metrics[i].setWidth(lastWidth);
- hmtx.metrics[i].setLeftSideBearing(input.readShort());
- }
- }
- return hmtx;
- }
-
- /**
* Return a specific metric record.
* @param index The index to the desired metric record.
* @return The metric record corresponding to {@code index}.
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java 2025-05-02 16:12:13 UTC (rev 13572)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java 2025-05-02 17:50:14 UTC (rev 13573)
@@ -44,7 +44,25 @@
throws IOException {
input.seek(offset);
- /* TODO: Complete this. */
+ final int numGlyphs = handler.getNumberOfGlyphs();
+ final int numberOfHMetrics = handler.getNumberOfHMetrics();
+
+
+ for (int i = 0; i < numberOfHMetrics; i++) {
+ handler.advanceWidth(input.read_UFWORD());
+ handler.lsb(input.read_FWORD());
+ }
+
+ if (numberOfHMetrics < numGlyphs) {
+ final int lsbOnlyCount = numGlyphs - numberOfHMetrics;
+ final short[] leftSideBearings = new short[lsbOnlyCount];
+ for (int index = 0; index < lsbOnlyCount; index ++) {
+ final short lsbOnly = input.read_FWORD();
+ handler.leftSideBearing(lsbOnly);
+ leftSideBearings[index] = lsbOnly;
+ }
+ handler.leftSideBearings(leftSideBearings);
+ }
}
}
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java 2025-05-02 16:12:13 UTC (rev 13572)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java 2025-05-02 17:50:14 UTC (rev 13573)
@@ -31,11 +31,32 @@
import org.foray.fontParse.FontContentHandler;
import org.foray.fontParse.ttf.HmtxTableParser;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
/**
* Implementations catch and handle the output from {@link HmtxTableParser}.
*/
public interface HmtxTableHandler extends FontContentHandler {
- /* TODO: Complete this. */
+ /**
+ * Unlike most handler methods which are essentially "setters", this method is a getter.
+ * The value is obtained from the "maxp" table, "numGlyphs" field.
+ * Also unlike most handler methods, implementation of this method is required.
+ * @return The total number of glyph records in this font.
+ */
+ int getNumberOfGlyphs();
+ /**
+ * Unlike most handler methods which are essentially "setters", this method is a getter.
+ * The value is obtained from the "hhea" table, "numberOfHMetrics" field.
+ * Also unlike most handler methods, implementation of this method is required.
+ * @return The total number of horizontal metrics records in this font.
+ */
+ int getNumberOfHMetrics();
+
+ default void advanceWidth(@Unsigned short value) { return; }
+ default void lsb(short value) { return; }
+
+ default void leftSideBearing(short value) { return; }
+ default void leftSideBearings(short[] value) { return; }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 16:12:32
|
Revision: 13572
http://sourceforge.net/p/foray/code/13572
Author: victormote
Date: 2025-05-02 16:12:13 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Rough-in support for new parsing schem in hmtx, loca, and glyf tables.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
Added Paths:
-----------
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GlyfTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GlyfTableHandler.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java 2025-05-02 15:49:01 UTC (rev 13571)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GlyfTable.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -30,7 +30,9 @@
import org.foray.common.RandomAccessInput;
import org.foray.common.data.BoundingBoxShort;
+import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.GlyfTableHandler;
import org.foray.primitive.BitUtils;
import org.axsl.ps.BoundingBox;
@@ -43,6 +45,33 @@
*/
public class GlyfTable extends RoTable {
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements GlyfTableHandler {
+
+ /** The table instance being created. */
+ @SuppressWarnings("unused")
+ private GlyfTable table;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final GlyfTable table) {
+ this.table = table;
+ }
+ }
+
+
+
+
+
+
+
+
+
+
/** The size, in bytes, of the header portion of this table. */
public static final byte HEADER_SIZE = RoTable.SHORT_BYTES + RoTable.FWORD_BYTES
+ RoTable.FWORD_BYTES + RoTable.FWORD_BYTES + RoTable.FWORD_BYTES;
@@ -75,6 +104,16 @@
public static final byte CF_BIT_USE_MY_METRICS = 9;
/**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<GlyfTable, GlyfTableHandler> createContentHandler() {
+ final GlyfTable table = new GlyfTable();
+ final GlyfTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<GlyfTable, GlyfTableHandler>(table, handler);
+ }
+
+ /**
* Reads the "glyf" table to find the bounding boxes.
* @param input The input which is being parsed.
* @param offset The offset into {@code input} at which to start parsing.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java 2025-05-02 15:49:01 UTC (rev 13571)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/HmtxTable.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -29,7 +29,9 @@
package org.foray.font.ttf.table;
import org.foray.common.RandomAccessInput;
+import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.HmtxTableHandler;
import java.io.IOException;
@@ -38,10 +40,47 @@
*/
public class HmtxTable extends RoTable {
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements HmtxTableHandler {
+
+ /** The table instance being created. */
+ @SuppressWarnings("unused")
+ private HmtxTable table;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final HmtxTable table) {
+ this.table = table;
+ }
+ }
+
+
+
+
+
+
+
+
+
+
/** The metrics entries for this table. */
private MtxEntry[] metrics;
/**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<HmtxTable, HmtxTableHandler> createContentHandler() {
+ final HmtxTable table = new HmtxTable();
+ final HmtxTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<HmtxTable, HmtxTableHandler>(table, handler);
+ }
+
+ /**
* Read "hmtx" table and put the horizontal metrics in the metrics array.
* If the number of metrics is less than the number of glyphs (eg fixed size fonts), extend the metrics array and
* fill in the missing widths.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 15:49:01 UTC (rev 13571)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LocaTable.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -29,7 +29,9 @@
package org.foray.font.ttf.table;
import org.foray.common.RandomAccessInput;
+import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.LocaTableHandler;
import java.io.IOException;
@@ -39,11 +41,48 @@
*/
public class LocaTable extends RoTable {
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements LocaTableHandler {
+
+ /** The table instance being created. */
+ @SuppressWarnings("unused")
+ private LocaTable table;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final LocaTable table) {
+ this.table = table;
+ }
+ }
+
+
+
+
+
+
+
+
+
+
/** The last offset value in the table, which points to no glyph, but
* exists to be able to compute the size of the previous entry. */
private long lastOffset = 0;
/**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<LocaTable, LocaTableHandler> createContentHandler() {
+ final LocaTable table = new LocaTable();
+ final LocaTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<LocaTable, LocaTableHandler>(table, handler);
+ }
+
+ /**
* Reads the "loca" table.
* @param input The input which is being parsed.
* @param offset The offset into {@code input} at which to start parsing.
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GlyfTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GlyfTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GlyfTableParser.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.GlyfTableHandler;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "glyf" table.
+ */
+public class GlyfTableParser extends TableParser<GlyfTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final GlyfTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ /* TODO: Complete this. */
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GlyfTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.HmtxTableHandler;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "hmtx" table.
+ */
+public class HmtxTableParser extends TableParser<HmtxTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final HmtxTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ /* TODO: Complete this. */
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/HmtxTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.LocaTableHandler;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "loca" table.
+ */
+public class LocaTableParser extends TableParser<LocaTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final LocaTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ /* TODO: Complete this. */
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LocaTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GlyfTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GlyfTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GlyfTableHandler.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.GlyfTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link GlyfTableParser}.
+ */
+public interface GlyfTableHandler extends FontContentHandler {
+
+ /* TODO: Complete this. */
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GlyfTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.HmtxTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link HmtxTableParser}.
+ */
+public interface HmtxTableHandler extends FontContentHandler {
+
+ /* TODO: Complete this. */
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/HmtxTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java 2025-05-02 16:12:13 UTC (rev 13572)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.LocaTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link LocaTableParser}.
+ */
+public interface LocaTableHandler extends FontContentHandler {
+
+ /* TODO: Complete this. */
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LocaTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 15:49:19
|
Revision: 13571
http://sourceforge.net/p/foray/code/13571
Author: victormote
Date: 2025-05-02 15:49:01 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Remove unneeded method.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 15:45:40 UTC (rev 13570)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 15:49:01 UTC (rev 13571)
@@ -38,7 +38,6 @@
import org.axsl.constants.PrimitiveConstants;
-import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@@ -918,10 +917,8 @@
/**
* Returns the table directory entry for a given named table.
- * @param tableName The name of the table whose table directory entry is
- * sought.
- * @param requiredTable Set to true if the table is a table that is required
- * in all TTF fonts.
+ * @param tableName The name of the table whose table directory entry is sought.
+ * @param requiredTable Set to true if the table is a table that is required in all TTF fonts.
* @return The appropriate table directory entry.
*/
private TtfOffsetTableRecord getEntry(final String tableName,
@@ -929,15 +926,13 @@
final TtfOffsetTableRecord entry = this.ttfFont.getTTFDirTabEntry(
tableName);
if (entry == null && requiredTable) {
- getLogger().error(TtfSubSetFile.TTF_MESSAGE
- + "Can't find " + tableName + " table");
+ LoggerFactory.getLogger(getClass()).error(TtfSubSetFile.TTF_MESSAGE + "Can't find " + tableName + " table");
}
return entry;
}
/**
- * For a given array size, return an empty byte array for the content,
- * adding any needed padding.
+ * For a given array size, return an empty byte array for the content, adding any needed padding.
* @param inputArraySize The size of the original table to be copied.
* @return The empty but properly-sized byte array.
*/
@@ -945,8 +940,8 @@
/* Align on 4-byte boundary */
final int arraySize = inputArraySize + getPadSize(inputArraySize);
/*
- * Byte arrays initialize at 0x00, which is what we want, as extra bytes
- * in the 4-byte padding scheme should be zero.
+ * Byte arrays initialize at 0x00, which is what we want, as extra bytes in the 4-byte padding scheme should be
+ * zero.
*/
return new byte[arraySize];
}
@@ -980,13 +975,4 @@
return padSize;
}
- /**
- * Return the logger.
- * @return The logger.
- */
- private Logger getLogger() {
- /* Not cached because not expected to get used much. */
- return LoggerFactory.getLogger(getClass());
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 15:46:05
|
Revision: 13570
http://sourceforge.net/p/foray/code/13570
Author: victormote
Date: 2025-05-02 15:45:40 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Remove construction-time need for the byte-level parser.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2025-05-02 14:56:25 UTC (rev 13569)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2025-05-02 15:45:40 UTC (rev 13570)
@@ -87,7 +87,7 @@
final Subset subset = fontUse.getSubset();
if (subset != null) {
final TtfSubSetFile ttfSubset = new TtfSubSetFile(this.ttf, subset);
- return ttfSubset.buildEmbeddableSubset();
+ return ttfSubset.buildEmbeddableSubset(this.ttf.getTTFFile().getReader().getRandomInput());
}
final InputStream instream = getFontInputStream();
return IoUtil.toByteArray(instream, FsTrueTypeFont.EXPECTED_FILE_SIZE);
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 14:56:25 UTC (rev 13569)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TtfSubSetFile.java 2025-05-02 15:45:40 UTC (rev 13570)
@@ -29,12 +29,12 @@
package org.foray.font.ttf;
import org.foray.font.Subset;
-import org.foray.font.format.FontParser;
import org.foray.font.ttf.table.CffTable;
import org.foray.font.ttf.table.GlyfTable;
import org.foray.font.ttf.table.HeadTable;
import org.foray.font.ttf.table.HmtxTable;
import org.foray.font.ttf.table.MtxEntry;
+import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.axsl.constants.PrimitiveConstants;
@@ -74,9 +74,6 @@
*/
private Subset subset;
- /** For convenience only. */
- private FontParser in = null;
-
/**
* List of the String names of each table in the font subset ("head",
* "hhea", etc.), stored in the order in which it should appear in the
@@ -109,19 +106,19 @@
*/
public TtfSubSetFile(final TrueTypeFont ttfFont, final Subset subset) {
this.ttfFont = ttfFont;
- this.in = ttfFont.getTTFFile().getReader();
this.subset = subset;
}
/**
* Builds and returns the embeddable subset.
+ * @param input The raw font content.
* @return The embeddable subset as a byte array.
* @throws IOException For I/O Error.
*/
- public byte[] buildEmbeddableSubset() throws IOException {
+ public byte[] buildEmbeddableSubset(final TtfRandomAccessInput input) throws IOException {
final GlyfTable glyfTable = this.ttfFont.getGlyfTable();
if (glyfTable != null) {
- return embeddableSubsetTTF();
+ return embeddableSubsetTTF(input);
}
final CffTable cffTable = this.ttfFont.getCffTable();
if (cffTable != null) {
@@ -132,25 +129,26 @@
/**
* Builds and returns the embeddable subset for a TTF font.
+ * @param input The raw font content.
* @return The embeddable subset as a byte array.
* @throws IOException For I/O Error.
*/
- private byte[] embeddableSubsetTTF() throws IOException {
- scanGlyphs();
+ private byte[] embeddableSubsetTTF(final TtfRandomAccessInput input) throws IOException {
+ scanGlyphs(input);
- addTable("head", createHead());
- addTable("hhea", createHhea());
+ addTable("head", createHead(input));
+ addTable("hhea", createHhea(input));
addTable("hmtx", createHmtx());
- addTable("maxp", createMaxp());
- final byte[] cvtTable = createCvt();
+ addTable("maxp", createMaxp(input));
+ final byte[] cvtTable = createCvt(input);
if (cvtTable != null
&& cvtTable.length != 0) {
addTable("cvt ", cvtTable);
}
- addTable("fpgm", createFpgm());
- addTable("prep", createPrep());
+ addTable("fpgm", createFpgm(input));
+ addTable("prep", createPrep(input));
addTable("loca", createLoca());
- addTable("glyf", createGlyf());
+ addTable("glyf", createGlyf(input));
this.directoryTableArray = createDirectory();
this.offsetTableArray = createOffsetTable();
@@ -309,30 +307,32 @@
/**
* Copy the (optional) cvt table as-is from original font to subset font.
+ * @param input The raw font content.
* @return The cvt table.
* @throws IOException For I/O Error.
*/
- private byte[] createCvt() throws IOException {
+ private byte[] createCvt(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("cvt ", false);
if (entry == null) {
return null;
}
this.ttfFont.seekTab("cvt ");
- return copyTableToByteArray(entry.getLength());
+ return copyTableToByteArray(input, entry.getLength());
}
/**
* Copy the (optional) fpgm table as is from original font to subset font.
+ * @param input The raw font content.
* @return The fpgm table.
* @throws IOException For I/O Error.
*/
- private byte[] createFpgm() throws IOException {
+ private byte[] createFpgm(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("fpgm", false);
if (entry == null) {
return null;
}
this.ttfFont.seekTab("fpgm");
- return copyTableToByteArray(entry.getLength());
+ return copyTableToByteArray(input, entry.getLength());
}
/**
@@ -362,18 +362,18 @@
/**
- * Copy the maxp table as is from original font to subset font
- * and set numGlyphs to its proper value.
+ * Copy the maxp table as is from original font to subset font and set numGlyphs to its proper value.
+ * @param input The raw font content.
* @return The maxp table.
* @throws IOException For I/O Error.
*/
- private byte[] createMaxp() throws IOException {
+ private byte[] createMaxp(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("maxp", true);
if (entry == null) {
return null;
}
this.ttfFont.seekTab("maxp");
- final byte[] byteArray = copyTableToByteArray(entry.getLength());
+ final byte[] byteArray = copyTableToByteArray(input, entry.getLength());
int arrayIndex = 0;
/* Skip the table name (already written). */
arrayIndex += RoTable.ULONG_BYTES;
@@ -384,32 +384,33 @@
/**
* Copy the (optional) prep table as is from original font to subset font.
+ * @param input The raw font content.
* @return The prep table.
* @throws IOException For I/O Error.
*/
- private byte[] createPrep() throws IOException {
+ private byte[] createPrep(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("prep", false);
if (entry == null) {
return null;
}
this.ttfFont.seekTab("prep");
- return copyTableToByteArray(entry.getLength());
+ return copyTableToByteArray(input, entry.getLength());
}
/**
- * Copies the "hhea" table from original font to the subset font, and fills
- * in the size of the "hmtx" table.
+ * Copies the "hhea" table from original font to the subset font, and fills in the size of the "hmtx" table.
+ * @param input The raw font content.
* @return The hhea table contents.
* @throws IOException For I/O Error.
*/
- private byte[] createHhea() throws IOException {
+ private byte[] createHhea(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("hhea", true);
if (entry == null) {
return null;
}
this.ttfFont.seekTab("hhea");
- final byte[] byteArray = copyTableToByteArray(entry.getLength());
+ final byte[] byteArray = copyTableToByteArray(input, entry.getLength());
writeUShort(byteArray, entry.getLength() - 2,
this.subset.numGlyphsUsed());
return byteArray;
@@ -417,19 +418,19 @@
/**
- * Copies the "head" table from the original font to the subset font, sets
- * "indexToLocaFormat" to "long", sets "checkSumAdjustment" to 0, and stores
- * offset to checkSumAdjustment in checkSumAdjustmentOffset.
+ * Copies the "head" table from the original font to the subset font, sets "indexToLocaFormat" to "long", sets
+ * "checkSumAdjustment" to 0, and stores offset to checkSumAdjustment in checkSumAdjustmentOffset.
+ * @param input The raw font content.
* @return The hhea table contents.
* @throws IOException For I/O Error.
*/
- private byte[] createHead() throws IOException {
+ private byte[] createHead(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("head", true);
if (entry == null) {
return null;
}
this.ttfFont.seekTab("head");
- final byte[] byteArray = copyTableToByteArray(entry.getLength());
+ final byte[] byteArray = copyTableToByteArray(input, entry.getLength());
/* Set checkSumAdjustment to 0. */
writeULong(byteArray, HeadTable.CHECK_SUM_ADJUSTMENT_OFFSET, 0);
/* Write the index to loc format, setting it to "1". */
@@ -443,10 +444,11 @@
/**
* Creates the "glyf" table and fills in "loca" table.
+ * @param input The raw font content.
* @return The glyf table contents.
* @throws IOException For I/O Error.
*/
- private byte[] createGlyf() throws IOException {
+ private byte[] createGlyf(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("glyf", true);
if (entry == null) {
return null;
@@ -470,7 +472,7 @@
final int fileOffset = entry.getOffset() + glyphOffset;
// Copy glyph
System.arraycopy(
- getGlyphBytes(fileOffset, glyphLength),
+ getGlyphBytes(input, fileOffset, glyphLength),
0,
byteArray,
cumulativeSize,
@@ -481,18 +483,18 @@
}
/**
- * Returns the bytes from the glyph drawing portion of the font file for a
- * specific glyph.
+ * Returns the bytes from the glyph drawing portion of the font file for a specific glyph.
+ * @param input The raw font content.
* @param fileOffset Offset to the first byte of the glyph drawing.
* @param glyphLength The number of bytes in the glyph drawing.
* @return The byte array containing the glyph drawing instructions.
* @throws IOException For I/O Error.
*/
- private byte[] getGlyphBytes(final int fileOffset, final int glyphLength)
+ private byte[] getGlyphBytes(final TtfRandomAccessInput input, final int fileOffset, final int glyphLength)
throws IOException {
- this.in.getRandomInput().seek(fileOffset);
+ input.seek(fileOffset);
final byte[] byteArray = new byte[glyphLength];
- this.in.getRandomInput().readFully(byteArray, 0, glyphLength);
+ input.readFully(byteArray, 0, glyphLength);
return remapComposite(byteArray);
}
@@ -549,14 +551,14 @@
}
/**
- * Returns a List containing the glyph itself plus all glyphs
- * that this composite glyph uses.
+ * Returns a List containing the glyph itself plus all glyphs that this composite glyph uses.
+ * @param input The raw font content.
* @param glyphOffset The offset to the start of the glyph table.
* @param glyphIdx The index to the glyph whose included glyphs are sought.
* @return A list of the glyf entries used.
* @throws IOException For I/O Error.
*/
- private List<Integer> getIncludedGlyphs(final int glyphOffset,
+ private List<Integer> getIncludedGlyphs(final TtfRandomAccessInput input, final int glyphOffset,
final Integer glyphIdx) throws IOException {
final List<Integer> ret = new ArrayList<Integer>();
ret.add(glyphIdx);
@@ -569,9 +571,9 @@
int flags = 0;
boolean moreComposites = true;
while (moreComposites) {
- this.in.getRandomInput().seek(offset);
- flags = this.in.getRandomInput().readUnsignedShort();
- compositeIdx = this.in.getRandomInput().readUnsignedShort();
+ input.seek(offset);
+ flags = input.readUnsignedShort();
+ compositeIdx = input.readUnsignedShort();
ret.add(compositeIdx);
offset += GlyfTable.computeCompositeEntrySize(flags);
moreComposites = GlyfTable.hasMoreComponents(flags);
@@ -618,20 +620,19 @@
}
/**
- * Scans all the original glyphs for composite glyphs and adds those glyphs
- * to the glyphmapping.
+ * Scans all the original glyphs for composite glyphs and adds those glyphs to the glyphmapping.
* Also rewrites the composite glyph pointers to the new mapping.
+ * @param input The raw font content.
* @throws IOException For I/O Error.
*/
- private void scanGlyphs() throws IOException {
+ private void scanGlyphs(final TtfRandomAccessInput input) throws IOException {
final TtfOffsetTableRecord entry = getEntry("glyf", true);
if (entry == null) {
return;
}
- final Map<Integer, Integer> usedCompositeGlyphs
- = getUsedCompositeGlyphs(entry);
+ final Map<Integer, Integer> usedCompositeGlyphs = getUsedCompositeGlyphs(input, entry);
final Map<Integer, Integer> componentGlyphsToAdd
- = getComponentGlyphsToAdd(entry, usedCompositeGlyphs);
+ = getComponentGlyphsToAdd(input, entry, usedCompositeGlyphs);
// Add component glyphs to the Map of used glyphs.
for (Integer key : componentGlyphsToAdd.keySet()) {
@@ -641,14 +642,15 @@
}
/**
- * Iterates through used glyphs, creating a Map of glyphs that are composite
- * glyphs. In case some glyphs might be both a component of a composite and
- * a composite, it repeats this process until no more composites are found.
+ * Iterates through used glyphs, creating a Map of glyphs that are composite glyphs.
+ * In case some glyphs might be both a component of a composite and a composite, it repeats this process until no
+ * more composites are found.
+ * @param input The raw font content.
* @param glyfTableDirEntry The TTFTableDirEntry for the "glyf" table.
* @return The Map of composite glyphs that have been used.
* @throws IOException for errors when reading the font file.
*/
- private Map<Integer, Integer> getUsedCompositeGlyphs(
+ private Map<Integer, Integer> getUsedCompositeGlyphs(final TtfRandomAccessInput input,
final TtfOffsetTableRecord glyfTableDirEntry) throws IOException {
final Map<Integer, Integer> usedCompositeGlyphs
= new HashMap<Integer, Integer>();
@@ -664,13 +666,12 @@
* Save the current position so that we can go back to it after
* this test.
*/
- final long cp = this.in.getRandomInput().getOffset();
- final long position = glyfTableDirEntry.getOffset()
- + glyphOffset;
- this.in.getRandomInput().seek(position);
- final boolean glyphIsComposite = this.in.getRandomInput().readShort() < 0;
+ final long cp = input.getOffset();
+ final long position = glyfTableDirEntry.getOffset() + glyphOffset;
+ input.seek(position);
+ final boolean glyphIsComposite = input.readShort() < 0;
/* Return to the original location. */
- this.in.getRandomInput().seek(cp);
+ input.seek(cp);
if (glyphIsComposite
&& usedCompositeGlyphs.get(originalIndex) == null) {
final int subsetIndex = this.subset.encodeSubsetIndex(
@@ -687,15 +688,14 @@
}
/**
- * Iterates through the used composite glyphs, adding component glyphs to
- * the used glyphs where needed.
+ * Iterates through the used composite glyphs, adding component glyphs to the used glyphs where needed.
+ * @param input The raw font content.
* @param glyfTableDirEntry The TTFTableDirEntry for the "glyf" table.
* @param usedCompositeGlyphs The Map of used composite glyphs to check.
- * @return The Map of component glyphs that need to be included in the
- * subset font.
+ * @return The Map of component glyphs that need to be included in the subset font.
* @throws IOException for errors reading the font file.
*/
- private Map<Integer, Integer> getComponentGlyphsToAdd(
+ private Map<Integer, Integer> getComponentGlyphsToAdd(final TtfRandomAccessInput input,
final TtfOffsetTableRecord glyfTableDirEntry,
final Map<Integer, Integer> usedCompositeGlyphs)
throws IOException {
@@ -703,7 +703,7 @@
= new HashMap<Integer, Integer>();
int newIndex = this.subset.numGlyphsUsed();
for (Integer origIndex : usedCompositeGlyphs.keySet()) {
- final List<Integer> composites = getIncludedGlyphs(
+ final List<Integer> composites = getIncludedGlyphs(input,
glyfTableDirEntry.getOffset(), origIndex);
// Iterate through all composites pointed to
@@ -953,14 +953,15 @@
/**
* Copies the content of a table into a byte array.
+ * @param input The raw font content.
* @param originalTableSize The number of bytes to be copied.
* @return The byte array containing the designated content.
* @throws IOException For I/O Error.
*/
- private byte[] copyTableToByteArray(final int originalTableSize)
+ private byte[] copyTableToByteArray(final TtfRandomAccessInput input, final int originalTableSize)
throws IOException {
final byte[] byteArray = createTableByteArray(originalTableSize);
- this.in.getRandomInput().readFully(byteArray, 0, originalTableSize);
+ input.readFully(byteArray, 0, originalTableSize);
return byteArray;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 14:56:47
|
Revision: 13569
http://sourceforge.net/p/foray/code/13569
Author: victormote
Date: 2025-05-02 14:56:25 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Add parser and handler for TableDirectory.
Added Paths:
-----------
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/TableDirectoryParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/TableDirectoryHandler.java
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/TableDirectoryParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/TableDirectoryParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/TableDirectoryParser.java 2025-05-02 14:56:25 UTC (rev 13569)
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.TableDirectoryHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "TableDirectory".
+ */
+public class TableDirectoryParser extends TableParser<TableDirectoryHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final TableDirectoryHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ handler.sfntVersion(input.read_uint32()); // 4 bytes, total 4
+ final @Unsigned short numTables = input.read_uint16(); // 2 bytes, total 6
+ handler.numTables(numTables);
+ handler.searchRange(input.read_uint16()); // 2 bytes, total 8
+ handler.entrySelector(input.read_uint16()); // 2 bytes, total 10
+ handler.rangeShift(input.read_uint16()); // 2 bytes, total 12
+
+ for (int index = 0; index < numTables; index ++) { // *** Restart Count ***
+ handler.tableTag(input.read_Tag()); // 4 bytes, total 4
+ handler.checksum(input.read_uint32()); // 4 bytes, total 8
+ handler.offset(input.read_Offset32()); // 4 bytes, total 12
+ handler.length(input.read_uint32()); // 4 bytes, total 16
+ }
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/TableDirectoryParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/TableDirectoryHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/TableDirectoryHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/TableDirectoryHandler.java 2025-05-02 14:56:25 UTC (rev 13569)
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.TableDirectoryParser;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+/**
+ * Implementations catch and handle the output from {@link TableDirectoryParser}.
+ */
+public interface TableDirectoryHandler extends FontContentHandler {
+
+ default void sfntVersion(@Unsigned int value) { return; }
+ default void numTables(@Unsigned short value) { return; }
+ default void searchRange(@Unsigned short value) { return; }
+ default void entrySelector(@Unsigned short value) { return; }
+ default void rangeShift(@Unsigned short value) { return; }
+
+ default void tableTag(String value) { return; }
+ default void checksum(@Unsigned int value) { return; }
+ default void offset(@Unsigned int value) { return; }
+ default void length(@Unsigned int value) { return; }
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/TableDirectoryHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 13:33:16
|
Revision: 13568
http://sourceforge.net/p/foray/code/13568
Author: victormote
Date: 2025-05-02 13:32:57 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Remove AbstractOtfLayoutTable class. GPOS and GSUB share 4 tables, but some of them may end up being different subtypes. There is no great benefit in having the superclass.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
Removed Paths:
-------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
Deleted: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 13:29:48 UTC (rev 13567)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 13:32:57 UTC (rev 13568)
@@ -1,39 +0,0 @@
-/*
- * Copyright 2016 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font.ttf.table;
-
-import org.foray.font.ttf.RoTable;
-
-/**
- * Abstract superclass for the OpenType layout tables.
- */
-public abstract class AbstractOtfLayoutTable extends RoTable {
-
-
-}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 13:29:48 UTC (rev 13567)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 13:32:57 UTC (rev 13568)
@@ -29,6 +29,7 @@
package org.foray.font.ttf.table;
import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
import org.foray.fontParse.ttfHandler.FeatureVariationsTableHandler;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
@@ -45,7 +46,7 @@
* An OpenType "GSUB" (Glyphs Substitution Data) table.
* This table is an Advanced Typographic Table.
*/
-public class GsubTable extends AbstractOtfLayoutTable {
+public class GsubTable extends RoTable {
/**
* The handler of events from the parser.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 13:30:07
|
Revision: 13567
http://sourceforge.net/p/foray/code/13567
Author: victormote
Date: 2025-05-02 13:29:48 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Convert GSUB table to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GsubTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GsubTableHandler.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 12:06:40 UTC (rev 13566)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/TrueTypeFont.java 2025-05-02 13:29:48 UTC (rev 13567)
@@ -69,6 +69,7 @@
import org.foray.fontParse.ttf.GaspTableParser;
import org.foray.fontParse.ttf.GdefTableParser;
import org.foray.fontParse.ttf.GposTableParser;
+import org.foray.fontParse.ttf.GsubTableParser;
import org.foray.fontParse.ttf.HeadTableParser;
import org.foray.fontParse.ttf.HheaTableParser;
import org.foray.fontParse.ttf.JstfTableParser;
@@ -91,6 +92,7 @@
import org.foray.fontParse.ttfHandler.GaspTableHandler;
import org.foray.fontParse.ttfHandler.GdefTableHandler;
import org.foray.fontParse.ttfHandler.GposTableHandler;
+import org.foray.fontParse.ttfHandler.GsubTableHandler;
import org.foray.fontParse.ttfHandler.HeadTableHandler;
import org.foray.fontParse.ttfHandler.HheaTableHandler;
import org.foray.fontParse.ttfHandler.JstfTableHandler;
@@ -404,11 +406,10 @@
dirEntry = ttfTableDir.getTableDirectoryEntry("GSUB");
if (dirEntry != null) {
- font.gsubTable = GsubTable.parse(dirEntry, raInput);
-// final ParserKit<GsubTable, GsubTableHandler> contentHandler = GsubTable.createContentHandler();
-// final GsubTableParser parser = new GsubTableParser();
-// parser.parse(raInput, dirEntry.getOffset(), contentHandler.getHandler());
-// font.gsubTable = contentHandler.getTable();
+ final ParserKit<GsubTable, GsubTableHandler> contentHandler = GsubTable.createContentHandler();
+ final GsubTableParser parser = new GsubTableParser();
+ parser.parse(raInput, dirEntry.getOffset(), contentHandler.getHandler());
+ font.gsubTable = contentHandler.getTable();
}
dirEntry = ttfTableDir.getTableDirectoryEntry("JSTF");
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 12:06:40 UTC (rev 13566)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 13:29:48 UTC (rev 13567)
@@ -35,75 +35,5 @@
*/
public abstract class AbstractOtfLayoutTable extends RoTable {
- /** List of OpenType scripts for this table. */
- private ScriptListTable scriptList;
- /** List of OpenType features for this table. */
- private FeatureListTable featureList;
-
- /** The lookup list. */
- private LookupListTable lookupList;
-
- /** The feature variations. */
- private FeatureVariationsTable featureVariations;
-
- /**
- * Constructor.
- * @param scriptList The script list for this table.
- * @param featureList The feature list for this table.
- * @param lookupList The lookup list for this table.
- * @param featureVariations The feature variations for this table.
- */
- AbstractOtfLayoutTable(final ScriptListTable scriptList, final FeatureListTable featureList,
- final LookupListTable lookupList, final FeatureVariationsTable featureVariations) {
- this.scriptList = scriptList;
- this.featureList = featureList;
- this.lookupList = lookupList;
- this.featureVariations = featureVariations;
- }
-
- /**
- * Returns the script instance for a given tag.
- * @param scriptTag The script tag to be retrieved.
- * @return The script instance referenced by {@code scriptTag}, or null if that reference does not exist.
- */
- public ScriptTable getScript(final String scriptTag) {
- if (this.scriptList == null) {
- return null;
- }
- return this.scriptList.get(scriptTag);
- }
-
- /**
- * Package-visible method for testing.
- * @return The script list.
- */
- ScriptListTable getScriptList() {
- return this.scriptList;
- }
-
- /**
- * Package-visible method for testing.
- * @return The feature list.
- */
- FeatureListTable getFeatureList() {
- return this.featureList;
- }
-
- /**
- * Returns the lookup list.
- * @return The lookup list.
- */
- public LookupListTable getLookupList() {
- return this.lookupList;
- }
-
- /**
- * Returns the feature variations.
- * @return The feature variations.
- */
- public FeatureVariationsTable getFeatureVariations() {
- return this.featureVariations;
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 12:06:40 UTC (rev 13566)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 13:29:48 UTC (rev 13567)
@@ -29,12 +29,6 @@
package org.foray.font.ttf.table;
import org.foray.font.ttf.ParserKit;
-import org.foray.font.ttf.TtfOffsetTableRecord;
-import org.foray.fontParse.ttf.FeatureListTableParser;
-import org.foray.fontParse.ttf.FeatureVariationsTableParser;
-import org.foray.fontParse.ttf.LookupListTableParser;
-import org.foray.fontParse.ttf.ScriptListTableParser;
-import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
import org.foray.fontParse.ttfHandler.FeatureVariationsTableHandler;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
@@ -45,7 +39,6 @@
import org.axsl.font.FontContext;
import org.axsl.orthography.Orthography;
-import java.io.IOException;
import java.util.List;
/**
@@ -70,6 +63,35 @@
private ContentHandler(final GsubTable table) {
this.table = table;
}
+
+ @Override
+ public ScriptListTableHandler startScriptList() {
+ final ParserKit<ScriptListTable, ScriptListTableHandler> kit = ScriptListTable.createContentHandler();
+ this.table.scriptList = kit.getTable();
+ return kit.getHandler();
+ }
+
+ @Override
+ public FeatureListTableHandler startFeatureList() {
+ final ParserKit<FeatureListTable, FeatureListTableHandler> kit = FeatureListTable.createContentHandler();
+ this.table.featureList = kit.getTable();
+ return kit.getHandler();
+ }
+
+ @Override
+ public LookupListTableHandler startLookupList() {
+ final ParserKit<LookupListTable, LookupListTableHandler> kit = LookupListTable.createContentHandler();
+ this.table.lookupList = kit.getTable();
+ return kit.getHandler();
+ }
+
+ @Override
+ public FeatureVariationsTableHandler startFeatureVariations() {
+ final ParserKit<FeatureVariationsTable, FeatureVariationsTableHandler> kit =
+ FeatureVariationsTable.createContentHandler();
+ this.table.featureVariations = kit.getTable();
+ return kit.getHandler();
+ }
}
@@ -80,84 +102,29 @@
- /**
- * Constructor.
- * @param scriptList The script list for this table.
- * @param featureList The feature list for this table.
- * @param lookupList The lookup list for this table.
- * @param featureVariations The feature variations for this table.
- */
- public GsubTable(final ScriptListTable scriptList, final FeatureListTable featureList,
- final LookupListTable lookupList, final FeatureVariationsTable featureVariations) {
- super(scriptList, featureList, lookupList, featureVariations);
- }
+ /** List of OpenType scripts for this table. */
+ private ScriptListTable scriptList;
+ /** List of OpenType features for this table. */
+ private FeatureListTable featureList;
+
+ /** The lookup list. */
+ private LookupListTable lookupList;
+
+ /** The feature variations. */
+ private FeatureVariationsTable featureVariations;
+
/**
* Creates a table instance and a content handler for that instance.
* @return A new content handler.
*/
public static ParserKit<GsubTable, GsubTableHandler> createContentHandler() {
- final GsubTable table = new GsubTable(null, null, null, null);
+ final GsubTable table = new GsubTable();
final GsubTableHandler handler = table.new ContentHandler(table);
return new ParserKit<GsubTable, GsubTableHandler>(table, handler);
}
/**
- * Parse the table from the table content.
- * @param offsetRecord The parent offset table record.
- * @param raInput The input which is being parsed.
- * @return The parsed instance.
- * @throws IOException For I/O Error.
- */
- public static GsubTable parse(final TtfOffsetTableRecord offsetRecord, final TtfRandomAccessInput raInput)
- throws IOException {
- raInput.seek(offsetRecord.getOffset());
- final int majorVersion = raInput.readUnsignedShort();
- final int minorVersion = raInput.readUnsignedShort();
- final int scriptListOffset = raInput.readUnsignedShort();
- final int featureListOffset = raInput.readUnsignedShort();
- final int lookupListOffset = raInput.readUnsignedShort();
- final int featureVariationsOffset;
- if (majorVersion > 1
- || minorVersion > 0) {
- featureVariationsOffset = raInput.readUnsignedShort();
- } else {
- featureVariationsOffset = -1;
- }
-
- final ParserKit<ScriptListTable, ScriptListTableHandler> scriptKit = ScriptListTable.createContentHandler();
- final ScriptListTableParser scriptParser = new ScriptListTableParser();
- scriptParser.parse(raInput, offsetRecord.getOffset() + scriptListOffset, scriptKit.getHandler());
- final ScriptListTable scriptListTable = scriptKit.getTable();
-
- final ParserKit<FeatureListTable, FeatureListTableHandler> featureKit = FeatureListTable.createContentHandler();
- final FeatureListTableParser featureParser = new FeatureListTableParser();
- featureParser.parse(raInput, offsetRecord.getOffset() + featureListOffset, featureKit.getHandler());
- final FeatureListTable featureListTable = featureKit.getTable();
-
- final ParserKit<LookupListTable, LookupListTableHandler> lookupKit = LookupListTable.createContentHandler();
- final LookupListTableParser lookupParser = new LookupListTableParser();
- lookupParser.parse(raInput, offsetRecord.getOffset() + lookupListOffset, lookupKit.getHandler());
- final LookupListTable lookupListTable = lookupKit.getTable();
-
- FeatureVariationsTable featureVariationsTable = null;
- if (featureVariationsOffset > -1) {
- final ParserKit<FeatureVariationsTable, FeatureVariationsTableHandler> variationsKit =
- FeatureVariationsTable.createContentHandler();
- final FeatureVariationsTableParser variationsParser = new FeatureVariationsTableParser();
- variationsParser.parse(raInput, offsetRecord.getOffset() + featureVariationsOffset,
- variationsKit.getHandler());
- featureVariationsTable = variationsKit.getTable();
- }
-
- final GsubTable table = new GsubTable(scriptListTable, featureListTable, lookupListTable,
- featureVariationsTable);
-
-
- return table;
- }
-
- /**
* Looks through the possible substitution in this font, and for those that the client wants, converts the glyph
* indexes for those substitutions.
* @param glyphIndexes The glyph indexes for which substitutions are being considered.
@@ -188,4 +155,48 @@
}
}
+ /**
+ * Returns the script instance for a given tag.
+ * @param scriptTag The script tag to be retrieved.
+ * @return The script instance referenced by {@code scriptTag}, or null if that reference does not exist.
+ */
+ public ScriptTable getScript(final String scriptTag) {
+ if (this.scriptList == null) {
+ return null;
+ }
+ return this.scriptList.get(scriptTag);
+ }
+
+ /**
+ * Package-visible method for testing.
+ * @return The script list.
+ */
+ ScriptListTable getScriptList() {
+ return this.scriptList;
+ }
+
+ /**
+ * Package-visible method for testing.
+ * @return The feature list.
+ */
+ FeatureListTable getFeatureList() {
+ return this.featureList;
+ }
+
+ /**
+ * Returns the lookup list.
+ * @return The lookup list.
+ */
+ public LookupListTable getLookupList() {
+ return this.lookupList;
+ }
+
+ /**
+ * Returns the feature variations.
+ * @return The feature variations.
+ */
+ public FeatureVariationsTable getFeatureVariations() {
+ return this.featureVariations;
+ }
+
}
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GsubTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GsubTableParser.java 2025-05-02 12:06:40 UTC (rev 13566)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/GsubTableParser.java 2025-05-02 13:29:48 UTC (rev 13567)
@@ -29,7 +29,11 @@
package org.foray.fontParse.ttf;
import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
+import org.foray.fontParse.ttfHandler.FeatureVariationsTableHandler;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
+import org.foray.fontParse.ttfHandler.LookupListTableHandler;
+import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
import java.io.IOException;
import java.math.BigDecimal;
@@ -63,15 +67,41 @@
/* GSUB Header, Version 1.1. */
- @SuppressWarnings("unused")
final int featureVariationsOffset;
if (version.compareTo(VERSION_1_1) >= 0) {
- featureVariationsOffset = input.readUnsignedShort();
+ featureVariationsOffset = input.read_Offset32();
} else {
featureVariationsOffset = -1;
}
+ handler.featureVariationsOffset(featureVariationsOffset);
- /* TODO: Complete this. */
+
+ /* Parse the child tables. */
+ final ScriptListTableHandler scriptListTableHandler = handler.startScriptList();
+ if (scriptListTableHandler != null) {
+ final ScriptListTableParser parser = new ScriptListTableParser();
+ parser.parse(input, offset + Short.toUnsignedInt(scriptListOffset), scriptListTableHandler);
+ }
+
+ final FeatureListTableHandler featureListTableHandler = handler.startFeatureList();
+ if (featureListTableHandler != null) {
+ final FeatureListTableParser parser = new FeatureListTableParser();
+ parser.parse(input, offset + Short.toUnsignedInt(featureListOffset), featureListTableHandler);
+ }
+
+ final LookupListTableHandler lookupListTableHandler = handler.startLookupList();
+ if (lookupListTableHandler != null) {
+ final LookupListTableParser parser = new LookupListTableParser();
+ parser.parse(input, offset + Short.toUnsignedInt(lookupListOffset), lookupListTableHandler);
+ }
+
+ if (featureVariationsOffset > -1) {
+ final FeatureVariationsTableHandler featureVariationsTableHandler = handler.startFeatureVariations();
+ if (featureVariationsTableHandler != null) {
+ final FeatureVariationsTableParser parser = new FeatureVariationsTableParser();
+ parser.parse(input, offset + featureVariationsOffset, featureVariationsTableHandler);
+ }
+ }
}
}
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GsubTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GsubTableHandler.java 2025-05-02 12:06:40 UTC (rev 13566)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/GsubTableHandler.java 2025-05-02 13:29:48 UTC (rev 13567)
@@ -40,9 +40,16 @@
default void majorVersion(@Unsigned short value) { return; }
default void minorVersion(@Unsigned short value) { return; }
+
default void scriptListOffset(@Unsigned short value) { return; }
default void featureListOffset(@Unsigned short value) { return; }
default void lookupListOffset(@Unsigned short value) { return; }
default void featureVariationsOffset(@Unsigned int value) { return; }
+
+ default ScriptListTableHandler startScriptList() { return null; }
+ default FeatureListTableHandler startFeatureList() { return null; }
+ default LookupListTableHandler startLookupList() { return null; }
+ default FeatureVariationsTableHandler startFeatureVariations() { return null; }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 12:07:01
|
Revision: 13566
http://sourceforge.net/p/foray/code/13566
Author: victormote
Date: 2025-05-02 12:06:40 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Move lookupList and featureVariations to the supertype, as they are shared with GPOS.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 11:52:19 UTC (rev 13565)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 12:06:40 UTC (rev 13566)
@@ -41,14 +41,25 @@
/** List of OpenType features for this table. */
private FeatureListTable featureList;
+ /** The lookup list. */
+ private LookupListTable lookupList;
+
+ /** The feature variations. */
+ private FeatureVariationsTable featureVariations;
+
/**
* Constructor.
* @param scriptList The script list for this table.
* @param featureList The feature list for this table.
+ * @param lookupList The lookup list for this table.
+ * @param featureVariations The feature variations for this table.
*/
- AbstractOtfLayoutTable(final ScriptListTable scriptList, final FeatureListTable featureList) {
+ AbstractOtfLayoutTable(final ScriptListTable scriptList, final FeatureListTable featureList,
+ final LookupListTable lookupList, final FeatureVariationsTable featureVariations) {
this.scriptList = scriptList;
this.featureList = featureList;
+ this.lookupList = lookupList;
+ this.featureVariations = featureVariations;
}
/**
@@ -79,4 +90,20 @@
return this.featureList;
}
+ /**
+ * Returns the lookup list.
+ * @return The lookup list.
+ */
+ public LookupListTable getLookupList() {
+ return this.lookupList;
+ }
+
+ /**
+ * Returns the feature variations.
+ * @return The feature variations.
+ */
+ public FeatureVariationsTable getFeatureVariations() {
+ return this.featureVariations;
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 11:52:19 UTC (rev 13565)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 12:06:40 UTC (rev 13566)
@@ -80,19 +80,16 @@
- /** The lookup list. */
- private LookupListTable lookupList;
-
- /** The feature variations. */
- private FeatureVariationsTable featureVariations;
-
/**
* Constructor.
- * @param scriptMap The scripts for this table.
- * @param featureListTable The features for this table.
+ * @param scriptList The script list for this table.
+ * @param featureList The feature list for this table.
+ * @param lookupList The lookup list for this table.
+ * @param featureVariations The feature variations for this table.
*/
- public GsubTable(final ScriptListTable scriptMap, final FeatureListTable featureListTable) {
- super(scriptMap, featureListTable);
+ public GsubTable(final ScriptListTable scriptList, final FeatureListTable featureList,
+ final LookupListTable lookupList, final FeatureVariationsTable featureVariations) {
+ super(scriptList, featureList, lookupList, featureVariations);
}
/**
@@ -100,7 +97,7 @@
* @return A new content handler.
*/
public static ParserKit<GsubTable, GsubTableHandler> createContentHandler() {
- final GsubTable table = new GsubTable(null, null);
+ final GsubTable table = new GsubTable(null, null, null, null);
final GsubTableHandler handler = table.new ContentHandler(table);
return new ParserKit<GsubTable, GsubTableHandler>(table, handler);
}
@@ -138,13 +135,12 @@
featureParser.parse(raInput, offsetRecord.getOffset() + featureListOffset, featureKit.getHandler());
final FeatureListTable featureListTable = featureKit.getTable();
- final GsubTable table = new GsubTable(scriptListTable, featureListTable);
-
final ParserKit<LookupListTable, LookupListTableHandler> lookupKit = LookupListTable.createContentHandler();
final LookupListTableParser lookupParser = new LookupListTableParser();
lookupParser.parse(raInput, offsetRecord.getOffset() + lookupListOffset, lookupKit.getHandler());
- table.lookupList = lookupKit.getTable();
+ final LookupListTable lookupListTable = lookupKit.getTable();
+ FeatureVariationsTable featureVariationsTable = null;
if (featureVariationsOffset > -1) {
final ParserKit<FeatureVariationsTable, FeatureVariationsTableHandler> variationsKit =
FeatureVariationsTable.createContentHandler();
@@ -151,26 +147,14 @@
final FeatureVariationsTableParser variationsParser = new FeatureVariationsTableParser();
variationsParser.parse(raInput, offsetRecord.getOffset() + featureVariationsOffset,
variationsKit.getHandler());
- table.featureVariations = variationsKit.getTable();
+ featureVariationsTable = variationsKit.getTable();
}
- return table;
- }
+ final GsubTable table = new GsubTable(scriptListTable, featureListTable, lookupListTable,
+ featureVariationsTable);
- /**
- * Returns the lookup list.
- * @return The lookup list.
- */
- public LookupListTable getLookupList() {
- return this.lookupList;
- }
- /**
- * Returns the feature variations.
- * @return The feature variations.
- */
- public FeatureVariationsTable getFeatureVariations() {
- return this.featureVariations;
+ return table;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 11:52:37
|
Revision: 13565
http://sourceforge.net/p/foray/code/13565
Author: victormote
Date: 2025-05-02 11:52:19 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Rough-in classes for parsing of FeatureVariations table.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureVariationsTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureVariationsTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureVariationsTableHandler.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 11:05:41 UTC (rev 13564)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-02 11:52:19 UTC (rev 13565)
@@ -28,11 +28,8 @@
package org.foray.font.ttf.table;
-import org.foray.common.RandomAccessInput;
import org.foray.font.ttf.RoTable;
-import java.io.IOException;
-
/**
* Abstract superclass for the OpenType layout tables.
*/
@@ -55,18 +52,6 @@
}
/**
- * Parses the feature variations.
- * @param raInput The input from which the feature variations is being parsed.
- * @param offset The offset in {@code raInput} for the start of the feature variations.
- * @throws IOException For I/O errors during parsing.
- */
- protected static void parseFeatureVariations(final RandomAccessInput raInput, final int offset) throws IOException {
- if (offset < 0) {
- return;
- }
- }
-
- /**
* Returns the script instance for a given tag.
* @param scriptTag The script tag to be retrieved.
* @return The script instance referenced by {@code scriptTag}, or null if that reference does not exist.
Added: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureVariationsTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureVariationsTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureVariationsTable.java 2025-05-02 11:52:19 UTC (rev 13565)
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.FeatureVariationsTableHandler;
+
+/**
+ * An OpenType "FeatureVariations".
+ */
+public class FeatureVariationsTable extends RoTable {
+
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements FeatureVariationsTableHandler {
+
+ /** The table instance being created. */
+ @SuppressWarnings("unused")
+ private FeatureVariationsTable table;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final FeatureVariationsTable table) {
+ this.table = table;
+ }
+ }
+
+
+
+
+
+ /**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<FeatureVariationsTable, FeatureVariationsTableHandler> createContentHandler() {
+ final FeatureVariationsTable table = new FeatureVariationsTable();
+ final FeatureVariationsTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<FeatureVariationsTable, FeatureVariationsTableHandler>(table, handler);
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureVariationsTable.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 11:05:41 UTC (rev 13564)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 11:52:19 UTC (rev 13565)
@@ -31,10 +31,12 @@
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.TtfOffsetTableRecord;
import org.foray.fontParse.ttf.FeatureListTableParser;
+import org.foray.fontParse.ttf.FeatureVariationsTableParser;
import org.foray.fontParse.ttf.LookupListTableParser;
import org.foray.fontParse.ttf.ScriptListTableParser;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
+import org.foray.fontParse.ttfHandler.FeatureVariationsTableHandler;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
import org.foray.fontParse.ttfHandler.LookupListTableHandler;
import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
@@ -81,6 +83,9 @@
/** The lookup list. */
private LookupListTable lookupList;
+ /** The feature variations. */
+ private FeatureVariationsTable featureVariations;
+
/**
* Constructor.
* @param scriptMap The scripts for this table.
@@ -140,7 +145,14 @@
lookupParser.parse(raInput, offsetRecord.getOffset() + lookupListOffset, lookupKit.getHandler());
table.lookupList = lookupKit.getTable();
- parseFeatureVariations(raInput, offsetRecord.getOffset() + featureVariationsOffset);
+ if (featureVariationsOffset > -1) {
+ final ParserKit<FeatureVariationsTable, FeatureVariationsTableHandler> variationsKit =
+ FeatureVariationsTable.createContentHandler();
+ final FeatureVariationsTableParser variationsParser = new FeatureVariationsTableParser();
+ variationsParser.parse(raInput, offsetRecord.getOffset() + featureVariationsOffset,
+ variationsKit.getHandler());
+ table.featureVariations = variationsKit.getTable();
+ }
return table;
}
@@ -154,6 +166,14 @@
}
/**
+ * Returns the feature variations.
+ * @return The feature variations.
+ */
+ public FeatureVariationsTable getFeatureVariations() {
+ return this.featureVariations;
+ }
+
+ /**
* Looks through the possible substitution in this font, and for those that the client wants, converts the glyph
* indexes for those substitutions.
* @param glyphIndexes The glyph indexes for which substitutions are being considered.
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureVariationsTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureVariationsTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureVariationsTableParser.java 2025-05-02 11:52:19 UTC (rev 13565)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.FeatureVariationsTableHandler;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "FeatureVariations" table.
+ */
+public class FeatureVariationsTableParser extends TableParser<FeatureVariationsTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final FeatureVariationsTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ /* TODO: Complete this. */
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureVariationsTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureVariationsTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureVariationsTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureVariationsTableHandler.java 2025-05-02 11:52:19 UTC (rev 13565)
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.FeatureVariationsTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link FeatureVariationsTableParser}.
+ */
+public interface FeatureVariationsTableHandler extends FontContentHandler {
+
+ /* TODO: Complete this. */
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureVariationsTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 11:05:59
|
Revision: 13564
http://sourceforge.net/p/foray/code/13564
Author: victormote
Date: 2025-05-02 11:05:41 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Convert LookupList tables to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupListTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupListTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupListTableHandler.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 01:08:11 UTC (rev 13563)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 11:05:41 UTC (rev 13564)
@@ -31,12 +31,12 @@
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.TtfOffsetTableRecord;
import org.foray.fontParse.ttf.FeatureListTableParser;
-import org.foray.fontParse.ttf.LookupTableParser;
+import org.foray.fontParse.ttf.LookupListTableParser;
import org.foray.fontParse.ttf.ScriptListTableParser;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
-import org.foray.fontParse.ttfHandler.LookupTableHandler;
+import org.foray.fontParse.ttfHandler.LookupListTableHandler;
import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
import org.foray.primitive.sequence.IntArrayBuilder;
@@ -44,7 +44,6 @@
import org.axsl.orthography.Orthography;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
/**
@@ -80,7 +79,7 @@
/** The lookup list. */
- private List<LookupTable> lookupList;
+ private LookupListTable lookupList;
/**
* Constructor.
@@ -136,7 +135,11 @@
final GsubTable table = new GsubTable(scriptListTable, featureListTable);
- table.lookupList = parseLookupList(raInput, offsetRecord.getOffset() + lookupListOffset);
+ final ParserKit<LookupListTable, LookupListTableHandler> lookupKit = LookupListTable.createContentHandler();
+ final LookupListTableParser lookupParser = new LookupListTableParser();
+ lookupParser.parse(raInput, offsetRecord.getOffset() + lookupListOffset, lookupKit.getHandler());
+ table.lookupList = lookupKit.getTable();
+
parseFeatureVariations(raInput, offsetRecord.getOffset() + featureVariationsOffset);
return table;
@@ -143,36 +146,10 @@
}
/**
- * Parses the lookup list.
- * @param raInput The input from which the lookup list is being parsed.
- * @param offset The offset in {@code raInput} for the start of the lookup list.
- * @return The parsed lookup list.
- * @throws IOException For I/O errors during parsing.
- */
- protected static List<LookupTable> parseLookupList(final TtfRandomAccessInput raInput, final int offset)
- throws IOException {
- raInput.seek(offset);
- final int lookupCount = raInput.readUnsignedShort();
- final int[] lookupTableOffsets = new int[lookupCount];
- for (int index = 0; index < lookupCount; index ++) {
- lookupTableOffsets[index] = raInput.readUnsignedShort();
- }
- final List<LookupTable> lookupList = new ArrayList<LookupTable>();
-
- for (int index = 0; index < lookupCount; index ++) {
- final ParserKit<LookupTable, LookupTableHandler> kit = LookupTable.createContentHandler();
- final LookupTableParser parser = new LookupTableParser();
- parser.parse(raInput, offset + lookupTableOffsets[index], kit.getHandler());
- lookupList.add(kit.getTable());
- }
- return lookupList;
- }
-
- /**
* Returns the lookup list.
* @return The lookup list.
*/
- public List<LookupTable> getLookupList() {
+ public LookupListTable getLookupList() {
return this.lookupList;
}
@@ -196,7 +173,7 @@
* See http://www.microsoft.com/typography/otspec/chapter2.htm, "Features & Lookups", paragraph 3. */
/* Iterate the lookups in the order that they are listed in the GSUB table. */
- final List<LookupTable> lookupList = getLookupList();
+ final List<LookupTable> lookupList = getLookupList().getLookupList();
for (int lookupIndex = 0; lookupIndex < lookupList.size(); lookupIndex ++) {
final LookupTable lookup = lookupList.get(lookupIndex);
final List<GsubLookupSubtable> lookupSubtables = lookup.getSubtables();
Added: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupListTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupListTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupListTable.java 2025-05-02 11:05:41 UTC (rev 13564)
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2016 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.LookupListTableHandler;
+import org.foray.fontParse.ttfHandler.LookupTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An OpenType "LookupList" table.
+ */
+public class LookupListTable extends RoTable {
+
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements LookupListTableHandler {
+
+ /** The table instance being created. */
+ private LookupListTable table;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final LookupListTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public void lookupCount(final @Unsigned short value) {
+ this.table.lookupList = new ArrayList<LookupTable>(value);
+ }
+
+ @Override
+ public LookupTableHandler startLookupTable() {
+ final ParserKit<LookupTable, LookupTableHandler> kit = LookupTable.createContentHandler();
+ this.table.lookupList.add(kit.getTable());
+ return kit.getHandler();
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+ /** The lookup list. */
+ private List<LookupTable> lookupList;
+
+ /**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<LookupListTable, LookupListTableHandler> createContentHandler() {
+ final LookupListTable table = new LookupListTable();
+ final LookupListTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<LookupListTable, LookupListTableHandler>(table, handler);
+ }
+
+ /**
+ * Returns the list of lookups in this lookup list.
+ * @return The list of lookups in this lookup list.
+ */
+ public List<LookupTable> getLookupList() {
+ return this.lookupList;
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupListTable.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-02 01:08:11 UTC (rev 13563)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-02 11:05:41 UTC (rev 13564)
@@ -137,7 +137,7 @@
assertEquals(2, ligaFeature.lookupListIndexAt(0));
/* Tests of the lookup list. */
- final List<LookupTable> lookupList = gsub.getLookupList();
+ final List<LookupTable> lookupList = gsub.getLookupList().getLookupList();
assertNotNull(lookupList);
assertEquals(40, lookupList.size());
final LookupTableParser.LookupType[] expectedLookupTypes = {
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupListTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupListTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupListTableParser.java 2025-05-02 11:05:41 UTC (rev 13564)
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.LookupListTableHandler;
+import org.foray.fontParse.ttfHandler.LookupTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "LookupList" table.
+ */
+public class LookupListTableParser extends TableParser<LookupListTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final LookupListTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ final @Unsigned short lookupCount = input.read_uint16(); // 2 bytes, 2 total
+ handler.lookupCount(lookupCount);
+
+ final @Unsigned short[] lookupOffsets = new @Unsigned short[lookupCount];
+ for (int index = 0; index < lookupCount; index ++) {
+ final @Unsigned short lookupOffset = input.read_Offset16(); // 2 bytes @
+ handler.lookupOffset(lookupCount);
+ lookupOffsets[index] = lookupOffset;
+ }
+
+ for (int index = 0; index < lookupCount; index ++) {
+ final LookupTableHandler lookupHandler = handler.startLookupTable();
+ final LookupTableParser parser = new LookupTableParser();
+ parser.parse(input, offset + Short.toUnsignedInt(lookupOffsets[index]), lookupHandler);
+ }
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupListTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupListTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupListTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupListTableHandler.java 2025-05-02 11:05:41 UTC (rev 13564)
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.LookupListTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link LookupListTableParser}.
+ */
+public interface LookupListTableHandler extends FontContentHandler {
+
+ default void lookupCount(short value) { return; }
+ default void lookupOffset(short value) { return; }
+ default LookupTableHandler startLookupTable() { return null; }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupListTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-02 01:08:33
|
Revision: 13563
http://sourceforge.net/p/foray/code/13563
Author: victormote
Date: 2025-05-02 01:08:11 +0000 (Fri, 02 May 2025)
Log Message:
-----------
Convert Lookup tables to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookupSubtable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/KernTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupSubtable.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookupSubtable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookupSubtable.java 2025-05-01 21:53:03 UTC (rev 13562)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookupSubtable.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -28,7 +28,6 @@
package org.foray.font.ttf.table;
-import org.foray.font.ttf.RoTable;
import org.foray.primitive.sequence.IntArrayBuilder;
import org.axsl.font.FontContext;
@@ -36,7 +35,7 @@
/**
* Abstract superclass for all GSUB subtables.
*/
-public abstract class GsubLookupSubtable extends RoTable {
+public abstract class GsubLookupSubtable extends LookupSubtable {
/**
* Process the substitution for this subtable.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 21:53:03 UTC (rev 13562)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -31,10 +31,12 @@
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.TtfOffsetTableRecord;
import org.foray.fontParse.ttf.FeatureListTableParser;
+import org.foray.fontParse.ttf.LookupTableParser;
import org.foray.fontParse.ttf.ScriptListTableParser;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
+import org.foray.fontParse.ttfHandler.LookupTableHandler;
import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
import org.foray.primitive.sequence.IntArrayBuilder;
@@ -158,8 +160,10 @@
final List<LookupTable> lookupList = new ArrayList<LookupTable>();
for (int index = 0; index < lookupCount; index ++) {
- final LookupTable lookup = LookupTable.parse(raInput, offset + lookupTableOffsets[index]);
- lookupList.add(lookup);
+ final ParserKit<LookupTable, LookupTableHandler> kit = LookupTable.createContentHandler();
+ final LookupTableParser parser = new LookupTableParser();
+ parser.parse(raInput, offset + lookupTableOffsets[index], kit.getHandler());
+ lookupList.add(kit.getTable());
}
return lookupList;
}
@@ -195,9 +199,9 @@
final List<LookupTable> lookupList = getLookupList();
for (int lookupIndex = 0; lookupIndex < lookupList.size(); lookupIndex ++) {
final LookupTable lookup = lookupList.get(lookupIndex);
- final GsubLookupSubtable[] lookupSubtables = lookup.getSubtables();
- for (int subtableIndex = 0; subtableIndex < lookupSubtables.length; subtableIndex ++) {
- final GsubLookupSubtable lookupSubtable = lookupSubtables[subtableIndex];
+ final List<GsubLookupSubtable> lookupSubtables = lookup.getSubtables();
+ for (int subtableIndex = 0; subtableIndex < lookupSubtables.size(); subtableIndex ++) {
+ final GsubLookupSubtable lookupSubtable = lookupSubtables.get(subtableIndex);
lookupSubtable.makeSubstitutions(glyphIndexes, context);
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/KernTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/KernTable.java 2025-05-01 21:53:03 UTC (rev 13562)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/KernTable.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -87,6 +87,10 @@
+
+
+
+
/** The parsed kerning data from this table. */
private List<KernSubtable> subtables;
Added: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupSubtable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupSubtable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupSubtable.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.RoTable;
+
+/**
+ * Abstract superclass for all Lookup subtables.
+ */
+public abstract class LookupSubtable extends RoTable {
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupSubtable.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java 2025-05-01 21:53:03 UTC (rev 13562)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -29,20 +29,9 @@
package org.foray.font.ttf.table;
import org.foray.font.ttf.ParserKit;
-import org.foray.fontParse.ttf.GsubLookup01x01Parser;
-import org.foray.fontParse.ttf.GsubLookup01x02Parser;
-import org.foray.fontParse.ttf.GsubLookup02x01Parser;
-import org.foray.fontParse.ttf.GsubLookup03x01Parser;
-import org.foray.fontParse.ttf.GsubLookup04x01Parser;
-import org.foray.fontParse.ttf.GsubLookup05x01Parser;
-import org.foray.fontParse.ttf.GsubLookup05x02Parser;
-import org.foray.fontParse.ttf.GsubLookup05x03Parser;
-import org.foray.fontParse.ttf.GsubLookup06x01Parser;
-import org.foray.fontParse.ttf.GsubLookup06x02Parser;
-import org.foray.fontParse.ttf.GsubLookup06x03Parser;
-import org.foray.fontParse.ttf.GsubLookup07x01Parser;
-import org.foray.fontParse.ttf.GsubLookup08x01Parser;
-import org.foray.fontParse.ttf.TtfRandomAccessInput;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttf.LookupTableParser;
+import org.foray.fontParse.ttf.LookupTableParser.LookupType;
import org.foray.fontParse.ttfHandler.GsubLookup01x01Handler;
import org.foray.fontParse.ttfHandler.GsubLookup01x02Handler;
import org.foray.fontParse.ttfHandler.GsubLookup02x01Handler;
@@ -56,254 +45,170 @@
import org.foray.fontParse.ttfHandler.GsubLookup06x03Handler;
import org.foray.fontParse.ttfHandler.GsubLookup07x01Handler;
import org.foray.fontParse.ttfHandler.GsubLookup08x01Handler;
+import org.foray.fontParse.ttfHandler.LookupTableHandler;
-import java.io.IOException;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* An OpenType lookup for the GSUB table.
*/
-public class LookupTable {
+public class LookupTable extends RoTable {
/**
- * Enumeration of possible LookupType values in a GSUB table.
+ * The handler of events from the parser.
*/
- public enum LookupType {
+ private final class ContentHandler implements LookupTableHandler {
- /** Replace one glyph with one glyph. */
- SINGLE(1),
+ /** The table instance being created. */
+ @SuppressWarnings("unused")
+ private LookupTable table;
- /** Replace one glyph with more than one glyph. */
- MULTIPLE(2),
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final LookupTable table) {
+ this.table = table;
+ }
- /** Replace one glyph with one of many glyphs. */
- ALTERNATE(3),
+ @Override
+ public void lookupType(final LookupTableParser.LookupType value) {
+ this.table.lookupType = value;
+ }
- /** Replace multiple glyphs with one glyph. */
- LIGATURE(4),
+ @Override
+ public void lookupFlag(final short value) {
+ this.table.lookupFlag = value;
+ }
- /** Replace one or more glyphs in context. */
- CONTEXT(5),
+ @Override
+ public void subTableCount(final short value) {
+ this.table.subtables = new ArrayList<GsubLookupSubtable>(value);
+ }
- /** Replace one or more glyphs in chained context. */
- CHAINING_CONTEXT(6),
+ @Override
+ public GsubLookup01x01Handler startGsubLookup01x01() {
+ final ParserKit<GsubLookup01x01, GsubLookup01x01Handler> kit = GsubLookup01x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** Extension mechanism for other substitutions (i.e. this excludes the Extension type substitution itself). */
- EXTENSION_SUBSTITUTION(7),
+ @Override
+ public GsubLookup01x02Handler startGsubLookup01x02() {
+ final ParserKit<GsubLookup01x02, GsubLookup01x02Handler> kit = GsubLookup01x02.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** Applied in reverse order, replace single glyph in chaining context. */
- REVERSE_CHAINING_CONTEXT_SINGLE(8);
+ @Override
+ public GsubLookup02x01Handler startGsubLookup02x01() {
+ final ParserKit<GsubLookup02x01, GsubLookup02x01Handler> kit = GsubLookup02x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** The number this enumerated item is stored as in a font file. */
- private byte value;
+ @Override
+ public GsubLookup03x01Handler startGsubLookup03x01() {
+ final ParserKit<GsubLookup03x01, GsubLookup03x01Handler> kit = GsubLookup03x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /**
- * Constructor.
- * @param value The number this enumerated item is stored as in a font file.
- */
- LookupType(final int value) {
- this.value = (byte) value;
+ @Override
+ public GsubLookup04x01Handler startGsubLookup04x01() {
+ final ParserKit<GsubLookup04x01, GsubLookup04x01Handler> kit = GsubLookup04x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
}
- /**
- * Finds the enumerated item from its value.
- * @param value The value for which the enumerated item is needed.
- * @return The enumerated item matching {@code value}, or null if it is not found.
- */
- public static LookupType fromValue(final int value) {
- for (LookupType lookupType : values()) {
- if (lookupType.value == value) {
- return lookupType;
- }
- }
- return null;
+ @Override
+ public GsubLookup05x01Handler startGsubLookup05x01() {
+ final ParserKit<GsubLookup05x01, GsubLookup05x01Handler> kit = GsubLookup05x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
}
- }
- /** Constant identifying a format number. */
- private static final byte FORMAT_1 = 1;
+ @Override
+ public GsubLookup05x02Handler startGsubLookup05x02() {
+ final ParserKit<GsubLookup05x02, GsubLookup05x02Handler> kit = GsubLookup05x02.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** Constant identifying a format number. */
- private static final byte FORMAT_2 = 2;
+ @Override
+ public GsubLookup05x03Handler startGsubLookup05x03() {
+ final ParserKit<GsubLookup05x03, GsubLookup05x03Handler> kit = GsubLookup05x03.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** Constant identifying a format number. */
- private static final byte FORMAT_3 = 3;
+ @Override
+ public GsubLookup06x01Handler startGsubLookup06x01() {
+ final ParserKit<GsubLookup06x01, GsubLookup06x01Handler> kit = GsubLookup06x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** The lookup type for this lookup. */
- private LookupType lookupType;
+ @Override
+ public GsubLookup06x02Handler startGsubLookup06x02() {
+ final ParserKit<GsubLookup06x02, GsubLookup06x02Handler> kit = GsubLookup06x02.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** The lookup flag. */
- private int lookupFlag;
+ @Override
+ public GsubLookup06x03Handler startGsubLookup06x03() {
+ final ParserKit<GsubLookup06x03, GsubLookup06x03Handler> kit = GsubLookup06x03.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
+ }
- /** The subtables. */
- private GsubLookupSubtable[] subtables;
-
- /**
- * Constructor.
- */
- public LookupTable() {
- }
-
- /**
- * Parses a lookup.
- * @param raInput The input from which the lookup is being parsed.
- * @param offset The offset in {@code raInput} for the start of the lookup table.
- * @return The parsed lookup table instance.
- * @throws IOException For I/O errors during parsing.
- */
- public static LookupTable parse(final TtfRandomAccessInput raInput, final int offset) throws IOException {
- raInput.seek(offset);
- final LookupTable lookup = new LookupTable();
- final int lookupTypeInteger = raInput.readUnsignedShort();
- lookup.lookupType = LookupType.fromValue(lookupTypeInteger);
- lookup.lookupFlag = raInput.readUnsignedShort();
- final int subTableCount = raInput.readUnsignedShort();
- final int[] subTableOffsets = new int[subTableCount];
- for (int index = 0; index < subTableCount; index ++) {
- subTableOffsets[index] = raInput.readUnsignedShort();
+ @Override
+ public GsubLookup07x01Handler startGsubLookup07x01() {
+ final ParserKit<GsubLookup07x01, GsubLookup07x01Handler> kit = GsubLookup07x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
}
- /* TODO: The last item in the table is named "MarkFilteringSet" with a type of "unit16". Although this is
- * probably a 16-bit type of some sort, we don't recognize it, and, for now, therefore skip parsing it. */
- lookup.subtables = new GsubLookupSubtable[subTableCount];
- for (int index = 0; index < subTableCount; index ++) {
- final GsubLookupSubtable subtable =
- parseSubtable(raInput, offset + subTableOffsets[index], lookup.lookupType);
- lookup.subtables[index] = subtable;
+ @Override
+ public GsubLookup08x01Handler startGsubLookup08x01() {
+ final ParserKit<GsubLookup08x01, GsubLookup08x01Handler> kit = GsubLookup08x01.createContentHandler();
+ this.table.subtables.add(kit.getTable());
+ return kit.getHandler();
}
- return lookup;
}
+
+
+
+
+
+
+
+
+
+
+ /** The lookup type for this lookup. */
+ private LookupTableParser.LookupType lookupType;
+
+ /** The lookup flag. */
+ private @Unsigned short lookupFlag;
+
+ /** The subtables. */
+ private List<GsubLookupSubtable> subtables;
+
/**
- * Parses a subtable.
- * @param raInput The input from which the subtable is being parsed.
- * @param offset The offset in {@code raInput} for the start of the subtable.
- * @param lookupType The lookup type being parsed.
- * @return The parsed subtable instance.
- * @throws IOException For I/O errors during parsing.
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
*/
- private static GsubLookupSubtable parseSubtable(final TtfRandomAccessInput raInput, final int offset,
- final LookupTable.LookupType lookupType) throws IOException {
- raInput.seek(offset);
-
- final int formatId = raInput.readUnsignedShort();
-
- switch (lookupType) {
- case SINGLE: {
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup01x01, GsubLookup01x01Handler> kit = GsubLookup01x01.createContentHandler();
- final GsubLookup01x01Parser parser = new GsubLookup01x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_2: {
- final ParserKit<GsubLookup01x02, GsubLookup01x02Handler> kit = GsubLookup01x02.createContentHandler();
- final GsubLookup01x02Parser parser = new GsubLookup01x02Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 1: " + formatId);
- }
- }
- case MULTIPLE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup02x01, GsubLookup02x01Handler> kit = GsubLookup02x01.createContentHandler();
- final GsubLookup02x01Parser parser = new GsubLookup02x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 2: " + formatId);
- }
- case ALTERNATE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup03x01, GsubLookup03x01Handler> kit = GsubLookup03x01.createContentHandler();
- final GsubLookup03x01Parser parser = new GsubLookup03x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 3: " + formatId);
- }
- case LIGATURE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup04x01, GsubLookup04x01Handler> kit = GsubLookup04x01.createContentHandler();
- final GsubLookup04x01Parser parser = new GsubLookup04x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 4: " + formatId);
- }
- case CONTEXT:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup05x01, GsubLookup05x01Handler> kit = GsubLookup05x01.createContentHandler();
- final GsubLookup05x01Parser parser = new GsubLookup05x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_2: {
- final ParserKit<GsubLookup05x02, GsubLookup05x02Handler> kit = GsubLookup05x02.createContentHandler();
- final GsubLookup05x02Parser parser = new GsubLookup05x02Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_3: {
- final ParserKit<GsubLookup05x03, GsubLookup05x03Handler> kit = GsubLookup05x03.createContentHandler();
- final GsubLookup05x03Parser parser = new GsubLookup05x03Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 5: " + formatId);
- }
- case CHAINING_CONTEXT:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup06x01, GsubLookup06x01Handler> kit = GsubLookup06x01.createContentHandler();
- final GsubLookup06x01Parser parser = new GsubLookup06x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_2: {
- final ParserKit<GsubLookup06x02, GsubLookup06x02Handler> kit = GsubLookup06x02.createContentHandler();
- final GsubLookup06x02Parser parser = new GsubLookup06x02Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_3: {
- final ParserKit<GsubLookup06x03, GsubLookup06x03Handler> kit = GsubLookup06x03.createContentHandler();
- final GsubLookup06x03Parser parser = new GsubLookup06x03Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 6: " + formatId);
- }
- case EXTENSION_SUBSTITUTION:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup07x01, GsubLookup07x01Handler> kit = GsubLookup07x01.createContentHandler();
- final GsubLookup07x01Parser parser = new GsubLookup07x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 7: " + formatId);
- }
- case REVERSE_CHAINING_CONTEXT_SINGLE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup08x01, GsubLookup08x01Handler> kit = GsubLookup08x01.createContentHandler();
- final GsubLookup08x01Parser parser = new GsubLookup08x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 8: " + formatId);
- }
- default: {
- throw new UnsupportedOperationException("Unrecognized GSUB lookup type: " + lookupType);
- }
- }
+ public static ParserKit<LookupTable, LookupTableHandler> createContentHandler() {
+ final LookupTable table = new LookupTable();
+ final LookupTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<LookupTable, LookupTableHandler>(table, handler);
}
/**
@@ -326,7 +231,7 @@
* Returns the subtables.
* @return The subtables.
*/
- protected GsubLookupSubtable[] getSubtables() {
+ protected List<GsubLookupSubtable> getSubtables() {
return this.subtables;
}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 21:53:03 UTC (rev 13562)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -36,6 +36,7 @@
import org.foray.font.ttf.TrueTypeSingle;
import org.foray.font.ttf.table.GsubLookup04x01.Ligature;
import org.foray.font.ttf.table.GsubLookup04x01.LigatureSet;
+import org.foray.fontParse.ttf.LookupTableParser;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.primitive.sequence.IntArrayBuilder;
@@ -139,50 +140,50 @@
final List<LookupTable> lookupList = gsub.getLookupList();
assertNotNull(lookupList);
assertEquals(40, lookupList.size());
- final LookupTable.LookupType[] expectedLookupTypes = {
- LookupTable.LookupType.LIGATURE, // 0
- LookupTable.LookupType.CHAINING_CONTEXT, // 1
- LookupTable.LookupType.LIGATURE, // 2
- LookupTable.LookupType.SINGLE, // 3
- LookupTable.LookupType.SINGLE, // 4
- LookupTable.LookupType.LIGATURE, // 5
- LookupTable.LookupType.LIGATURE, // 6
- LookupTable.LookupType.SINGLE, // 7
- LookupTable.LookupType.SINGLE, // 8
- LookupTable.LookupType.SINGLE, // 9
- LookupTable.LookupType.SINGLE, // 10
- LookupTable.LookupType.SINGLE, // 11
- LookupTable.LookupType.SINGLE, // 12
- LookupTable.LookupType.SINGLE, // 13
- LookupTable.LookupType.SINGLE, // 14
- LookupTable.LookupType.SINGLE, // 15
- LookupTable.LookupType.SINGLE, // 16
- LookupTable.LookupType.SINGLE, // 17
- LookupTable.LookupType.SINGLE, // 18
- LookupTable.LookupType.SINGLE, // 19
- LookupTable.LookupType.SINGLE, // 20
- LookupTable.LookupType.SINGLE, // 21
- LookupTable.LookupType.LIGATURE, // 22
- LookupTable.LookupType.SINGLE, // 23
- LookupTable.LookupType.ALTERNATE, // 24
- LookupTable.LookupType.SINGLE, // 25
- LookupTable.LookupType.SINGLE, // 26
- LookupTable.LookupType.SINGLE, // 27
- LookupTable.LookupType.SINGLE, // 28
- LookupTable.LookupType.ALTERNATE, // 29
- LookupTable.LookupType.SINGLE, // 30
- LookupTable.LookupType.ALTERNATE, // 31
- LookupTable.LookupType.ALTERNATE, // 32
- LookupTable.LookupType.ALTERNATE, // 33
- LookupTable.LookupType.SINGLE, // 34
- LookupTable.LookupType.SINGLE, // 35
- LookupTable.LookupType.LIGATURE, // 36
- LookupTable.LookupType.LIGATURE, // 37
- LookupTable.LookupType.SINGLE, // 38
- LookupTable.LookupType.SINGLE // 39
+ final LookupTableParser.LookupType[] expectedLookupTypes = {
+ LookupTableParser.LookupType.LIGATURE, // 0
+ LookupTableParser.LookupType.CHAINING_CONTEXT, // 1
+ LookupTableParser.LookupType.LIGATURE, // 2
+ LookupTableParser.LookupType.SINGLE, // 3
+ LookupTableParser.LookupType.SINGLE, // 4
+ LookupTableParser.LookupType.LIGATURE, // 5
+ LookupTableParser.LookupType.LIGATURE, // 6
+ LookupTableParser.LookupType.SINGLE, // 7
+ LookupTableParser.LookupType.SINGLE, // 8
+ LookupTableParser.LookupType.SINGLE, // 9
+ LookupTableParser.LookupType.SINGLE, // 10
+ LookupTableParser.LookupType.SINGLE, // 11
+ LookupTableParser.LookupType.SINGLE, // 12
+ LookupTableParser.LookupType.SINGLE, // 13
+ LookupTableParser.LookupType.SINGLE, // 14
+ LookupTableParser.LookupType.SINGLE, // 15
+ LookupTableParser.LookupType.SINGLE, // 16
+ LookupTableParser.LookupType.SINGLE, // 17
+ LookupTableParser.LookupType.SINGLE, // 18
+ LookupTableParser.LookupType.SINGLE, // 19
+ LookupTableParser.LookupType.SINGLE, // 20
+ LookupTableParser.LookupType.SINGLE, // 21
+ LookupTableParser.LookupType.LIGATURE, // 22
+ LookupTableParser.LookupType.SINGLE, // 23
+ LookupTableParser.LookupType.ALTERNATE, // 24
+ LookupTableParser.LookupType.SINGLE, // 25
+ LookupTableParser.LookupType.SINGLE, // 26
+ LookupTableParser.LookupType.SINGLE, // 27
+ LookupTableParser.LookupType.SINGLE, // 28
+ LookupTableParser.LookupType.ALTERNATE, // 29
+ LookupTableParser.LookupType.SINGLE, // 30
+ LookupTableParser.LookupType.ALTERNATE, // 31
+ LookupTableParser.LookupType.ALTERNATE, // 32
+ LookupTableParser.LookupType.ALTERNATE, // 33
+ LookupTableParser.LookupType.SINGLE, // 34
+ LookupTableParser.LookupType.SINGLE, // 35
+ LookupTableParser.LookupType.LIGATURE, // 36
+ LookupTableParser.LookupType.LIGATURE, // 37
+ LookupTableParser.LookupType.SINGLE, // 38
+ LookupTableParser.LookupType.SINGLE // 39
};
for (int index = 0; index < expectedLookupTypes.length; index ++) {
- final LookupTable.LookupType expectedLookupType = expectedLookupTypes[index];
+ final LookupTableParser.LookupType expectedLookupType = expectedLookupTypes[index];
final LookupTable actual = lookupList.get(index);
assertEquals(expectedLookupType, actual.getLookupType(), "Failure at index: " + index);
}
@@ -190,9 +191,9 @@
/* Tests of the LIGATURE lookup table pointed to by the latin features. The "liga" feature contains only one
* index = 2. */
final LookupTable ligatureLookup = lookupList.get(2);
- final GsubLookupSubtable[] ligatureLookupSubtables = ligatureLookup.getSubtables();
- assertEquals(1, ligatureLookupSubtables.length);
- final GsubLookupSubtable ligatureLookupSubtable = ligatureLookupSubtables[0];
+ final List<GsubLookupSubtable> ligatureLookupSubtables = ligatureLookup.getSubtables();
+ assertEquals(1, ligatureLookupSubtables.size());
+ final GsubLookupSubtable ligatureLookupSubtable = ligatureLookupSubtables.get(0);
assertTrue(ligatureLookupSubtable instanceof GsubLookup04x01);
final GsubLookup04x01 ligatureSubtable = (GsubLookup04x01) ligatureLookupSubtable;
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java 2025-05-01 21:53:03 UTC (rev 13562)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -29,6 +29,19 @@
package org.foray.fontParse.ttf;
import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.GsubLookup01x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup01x02Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup02x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup03x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup04x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup05x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup05x02Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup05x03Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup06x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup06x02Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup06x03Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup07x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup08x01Handler;
import org.foray.fontParse.ttfHandler.LookupTableHandler;
import org.checkerframework.checker.signedness.qual.Unsigned;
@@ -40,21 +53,239 @@
*/
public class LookupTableParser extends TableParser<LookupTableHandler> {
+ /**
+ * Enumeration of possible LookupType values in a GSUB table.
+ */
+ public enum LookupType {
+ /** Replace one glyph with one glyph. */
+ SINGLE(1),
+
+ /** Replace one glyph with more than one glyph. */
+ MULTIPLE(2),
+
+ /** Replace one glyph with one of many glyphs. */
+ ALTERNATE(3),
+
+ /** Replace multiple glyphs with one glyph. */
+ LIGATURE(4),
+
+ /** Replace one or more glyphs in context. */
+ CONTEXT(5),
+
+ /** Replace one or more glyphs in chained context. */
+ CHAINING_CONTEXT(6),
+
+ /** Extension mechanism for other substitutions (i.e. this excludes the Extension type substitution itself). */
+ EXTENSION_SUBSTITUTION(7),
+
+ /** Applied in reverse order, replace single glyph in chaining context. */
+ REVERSE_CHAINING_CONTEXT_SINGLE(8);
+
+ /** The number this enumerated item is stored as in a font file. */
+ private byte value;
+
+ /**
+ * Constructor.
+ * @param value The number this enumerated item is stored as in a font file.
+ */
+ LookupType(final int value) {
+ this.value = (byte) value;
+ }
+
+ /**
+ * Finds the enumerated item from its value.
+ * @param value The value for which the enumerated item is needed.
+ * @return The enumerated item matching {@code value}, or null if it is not found.
+ */
+ public static LookupType fromValue(final int value) {
+ for (LookupType lookupType : values()) {
+ if (lookupType.value == value) {
+ return lookupType;
+ }
+ }
+ return null;
+ }
+ }
+
+ /** Constant identifying a format number. */
+ private static final byte FORMAT_1 = 1;
+
+ /** Constant identifying a format number. */
+ private static final byte FORMAT_2 = 2;
+
+ /** Constant identifying a format number. */
+ private static final byte FORMAT_3 = 3;
+
+
+
+
+
@Override
public void parse(final TtfRandomAccessInput input, final int offset, final LookupTableHandler handler)
throws IOException {
input.seek(offset);
- final @Unsigned short lookupType = input.read_uint16(); // 2 bytes, total 2
+ final LookupType lookupType = LookupType.fromValue(input.read_uint16()); // 2 bytes, total 2
handler.lookupType(lookupType);
- handler.lookupFlag(input.read_uint16()); // 2 bytes, total 4
+ final short lookupFlag = input.read_uint16(); // 2 bytes, total 4
+ handler.lookupFlag(lookupFlag);
final @Unsigned short subTableCount = input.read_uint16(); // 2 bytes, total 6
handler.subTableCount(subTableCount);
- /* TODO: Complete this. */
+ final @Unsigned short[] subTableOffsets = new @Unsigned short[subTableCount];
+ for (@Unsigned short index = 0; index < subTableCount; index ++) {
+ final @Unsigned short subtableOffset = input.read_Offset16(); // 2 bytes @
+ subTableOffsets[index] = subtableOffset;
+ handler.subtableOffset(subtableOffset);
+ }
+
+ final short mask = 0x0010; // Only bit 5 is on.
+ final boolean useMarkFilteringSet = (lookupFlag & mask) != 0;
+ if (useMarkFilteringSet) {
+ /* TODO: Just returning this value is probably not the right thing to do. Find out how to tie it in with the
+ * GDEF code. */
+ final @Unsigned short markFilteringSet = input.read_uint16();
+ handler.markFilteringSet(markFilteringSet);
+ }
+
+ for (int index = 0; index < subTableCount; index ++) {
+ parseSubtable(input, offset + subTableOffsets[index], lookupType, handler);
+ }
}
+ /**
+ * Parses a subtable.
+ * @param input The input from which the subtable is being parsed.
+ * @param offset The offset in {@code raInput} for the start of the subtable.
+ * @param lookupType The lookup type being parsed.
+ * @param handler The handler for the lookup table.
+ * @throws IOException For I/O errors during parsing.
+ */
+ private void parseSubtable(final TtfRandomAccessInput input, final int offset,
+ final LookupType lookupType, final LookupTableHandler handler) throws IOException {
+ input.seek(offset);
+
+ final int formatId = input.readUnsignedShort();
+
+ switch (lookupType) {
+ case SINGLE: {
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup01x01Handler subTableHandler = handler.startGsubLookup01x01();
+ final GsubLookup01x01Parser parser = new GsubLookup01x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ case FORMAT_2: {
+ final GsubLookup01x02Handler subTableHandler = handler.startGsubLookup01x02();
+ final GsubLookup01x02Parser parser = new GsubLookup01x02Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 1: " + formatId);
+ }
+ }
+ case MULTIPLE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup02x01Handler subTableHandler = handler.startGsubLookup02x01();
+ final GsubLookup02x01Parser parser = new GsubLookup02x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 2: " + formatId);
+ }
+ case ALTERNATE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup03x01Handler subTableHandler = handler.startGsubLookup03x01();
+ final GsubLookup03x01Parser parser = new GsubLookup03x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 3: " + formatId);
+ }
+ case LIGATURE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup04x01Handler subTableHandler = handler.startGsubLookup04x01();
+ final GsubLookup04x01Parser parser = new GsubLookup04x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 4: " + formatId);
+ }
+ case CONTEXT:
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup05x01Handler subTableHandler = handler.startGsubLookup05x01();
+ final GsubLookup05x01Parser parser = new GsubLookup05x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ case FORMAT_2: {
+ final GsubLookup05x02Handler subTableHandler = handler.startGsubLookup05x02();
+ final GsubLookup05x02Parser parser = new GsubLookup05x02Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ case FORMAT_3: {
+ final GsubLookup05x03Handler subTableHandler = handler.startGsubLookup05x03();
+ final GsubLookup05x03Parser parser = new GsubLookup05x03Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 5: " + formatId);
+ }
+ case CHAINING_CONTEXT:
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup06x01Handler subTableHandler = handler.startGsubLookup06x01();
+ final GsubLookup06x01Parser parser = new GsubLookup06x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ case FORMAT_2: {
+ final GsubLookup06x02Handler subTableHandler = handler.startGsubLookup06x02();
+ final GsubLookup06x02Parser parser = new GsubLookup06x02Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ case FORMAT_3: {
+ final GsubLookup06x03Handler subTableHandler = handler.startGsubLookup06x03();
+ final GsubLookup06x03Parser parser = new GsubLookup06x03Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 6: " + formatId);
+ }
+ case EXTENSION_SUBSTITUTION:
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup07x01Handler subTableHandler = handler.startGsubLookup07x01();
+ final GsubLookup07x01Parser parser = new GsubLookup07x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 7: " + formatId);
+ }
+ case REVERSE_CHAINING_CONTEXT_SINGLE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final GsubLookup08x01Handler subTableHandler = handler.startGsubLookup08x01();
+ final GsubLookup08x01Parser parser = new GsubLookup08x01Parser();
+ parser.parse(input, offset, subTableHandler);
+ return;
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 8: " + formatId);
+ }
+ default: {
+ throw new UnsupportedOperationException("Unrecognized GSUB lookup type: " + lookupType);
+ }
+ }
+ }
+
}
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java 2025-05-01 21:53:03 UTC (rev 13562)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java 2025-05-02 01:08:11 UTC (rev 13563)
@@ -36,10 +36,24 @@
*/
public interface LookupTableHandler extends FontContentHandler {
- default void lookupType(short value) { return; }
+ default void lookupType(LookupTableParser.LookupType value) { return; }
default void lookupFlag(short value) { return; }
default void subTableCount(short value) { return; }
default void subtableOffset(short value) { return; }
default void markFilteringSet(short value) { return; }
+ default GsubLookup01x01Handler startGsubLookup01x01() { return null; }
+ default GsubLookup01x02Handler startGsubLookup01x02() { return null; }
+ default GsubLookup02x01Handler startGsubLookup02x01() { return null; }
+ default GsubLookup03x01Handler startGsubLookup03x01() { return null; }
+ default GsubLookup04x01Handler startGsubLookup04x01() { return null; }
+ default GsubLookup05x01Handler startGsubLookup05x01() { return null; }
+ default GsubLookup05x02Handler startGsubLookup05x02() { return null; }
+ default GsubLookup05x03Handler startGsubLookup05x03() { return null; }
+ default GsubLookup06x01Handler startGsubLookup06x01() { return null; }
+ default GsubLookup06x02Handler startGsubLookup06x02() { return null; }
+ default GsubLookup06x03Handler startGsubLookup06x03() { return null; }
+ default GsubLookup07x01Handler startGsubLookup07x01() { return null; }
+ default GsubLookup08x01Handler startGsubLookup08x01() { return null; }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 21:53:25
|
Revision: 13562
http://sourceforge.net/p/foray/code/13562
Author: victormote
Date: 2025-05-01 21:53:03 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Rename GsubLookup to LookupTable. Rough-in parser and handler classes.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java
Removed Paths:
-------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookup.java
Deleted: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookup.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookup.java 2025-05-01 21:20:57 UTC (rev 13561)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookup.java 2025-05-01 21:53:03 UTC (rev 13562)
@@ -1,333 +0,0 @@
-/*
- * Copyright 2016 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font.ttf.table;
-
-import org.foray.font.ttf.ParserKit;
-import org.foray.fontParse.ttf.GsubLookup01x01Parser;
-import org.foray.fontParse.ttf.GsubLookup01x02Parser;
-import org.foray.fontParse.ttf.GsubLookup02x01Parser;
-import org.foray.fontParse.ttf.GsubLookup03x01Parser;
-import org.foray.fontParse.ttf.GsubLookup04x01Parser;
-import org.foray.fontParse.ttf.GsubLookup05x01Parser;
-import org.foray.fontParse.ttf.GsubLookup05x02Parser;
-import org.foray.fontParse.ttf.GsubLookup05x03Parser;
-import org.foray.fontParse.ttf.GsubLookup06x01Parser;
-import org.foray.fontParse.ttf.GsubLookup06x02Parser;
-import org.foray.fontParse.ttf.GsubLookup06x03Parser;
-import org.foray.fontParse.ttf.GsubLookup07x01Parser;
-import org.foray.fontParse.ttf.GsubLookup08x01Parser;
-import org.foray.fontParse.ttf.TtfRandomAccessInput;
-import org.foray.fontParse.ttfHandler.GsubLookup01x01Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup01x02Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup02x01Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup03x01Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup04x01Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup05x01Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup05x02Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup05x03Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup06x01Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup06x02Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup06x03Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup07x01Handler;
-import org.foray.fontParse.ttfHandler.GsubLookup08x01Handler;
-
-import java.io.IOException;
-
-/**
- * An OpenType lookup for the GSUB table.
- */
-public class GsubLookup {
-
- /**
- * Enumeration of possible LookupType values in a GSUB table.
- */
- public enum LookupType {
-
- /** Replace one glyph with one glyph. */
- SINGLE(1),
-
- /** Replace one glyph with more than one glyph. */
- MULTIPLE(2),
-
- /** Replace one glyph with one of many glyphs. */
- ALTERNATE(3),
-
- /** Replace multiple glyphs with one glyph. */
- LIGATURE(4),
-
- /** Replace one or more glyphs in context. */
- CONTEXT(5),
-
- /** Replace one or more glyphs in chained context. */
- CHAINING_CONTEXT(6),
-
- /** Extension mechanism for other substitutions (i.e. this excludes the Extension type substitution itself). */
- EXTENSION_SUBSTITUTION(7),
-
- /** Applied in reverse order, replace single glyph in chaining context. */
- REVERSE_CHAINING_CONTEXT_SINGLE(8);
-
- /** The number this enumerated item is stored as in a font file. */
- private byte value;
-
- /**
- * Constructor.
- * @param value The number this enumerated item is stored as in a font file.
- */
- LookupType(final int value) {
- this.value = (byte) value;
- }
-
- /**
- * Finds the enumerated item from its value.
- * @param value The value for which the enumerated item is needed.
- * @return The enumerated item matching {@code value}, or null if it is not found.
- */
- public static LookupType fromValue(final int value) {
- for (LookupType lookupType : values()) {
- if (lookupType.value == value) {
- return lookupType;
- }
- }
- return null;
- }
- }
-
- /** Constant identifying a format number. */
- private static final byte FORMAT_1 = 1;
-
- /** Constant identifying a format number. */
- private static final byte FORMAT_2 = 2;
-
- /** Constant identifying a format number. */
- private static final byte FORMAT_3 = 3;
-
- /** The lookup type for this lookup. */
- private LookupType lookupType;
-
- /** The lookup flag. */
- private int lookupFlag;
-
- /** The subtables. */
- private GsubLookupSubtable[] subtables;
-
- /**
- * Constructor.
- */
- public GsubLookup() {
- }
-
- /**
- * Parses a lookup.
- * @param raInput The input from which the lookup is being parsed.
- * @param offset The offset in {@code raInput} for the start of the lookup table.
- * @return The parsed lookup table instance.
- * @throws IOException For I/O errors during parsing.
- */
- public static GsubLookup parse(final TtfRandomAccessInput raInput, final int offset) throws IOException {
- raInput.seek(offset);
- final GsubLookup lookup = new GsubLookup();
- final int lookupTypeInteger = raInput.readUnsignedShort();
- lookup.lookupType = LookupType.fromValue(lookupTypeInteger);
- lookup.lookupFlag = raInput.readUnsignedShort();
- final int subTableCount = raInput.readUnsignedShort();
- final int[] subTableOffsets = new int[subTableCount];
- for (int index = 0; index < subTableCount; index ++) {
- subTableOffsets[index] = raInput.readUnsignedShort();
- }
- /* TODO: The last item in the table is named "MarkFilteringSet" with a type of "unit16". Although this is
- * probably a 16-bit type of some sort, we don't recognize it, and, for now, therefore skip parsing it. */
-
- lookup.subtables = new GsubLookupSubtable[subTableCount];
- for (int index = 0; index < subTableCount; index ++) {
- final GsubLookupSubtable subtable =
- parseSubtable(raInput, offset + subTableOffsets[index], lookup.lookupType);
- lookup.subtables[index] = subtable;
- }
-
- return lookup;
- }
-
- /**
- * Parses a subtable.
- * @param raInput The input from which the subtable is being parsed.
- * @param offset The offset in {@code raInput} for the start of the subtable.
- * @param lookupType The lookup type being parsed.
- * @return The parsed subtable instance.
- * @throws IOException For I/O errors during parsing.
- */
- private static GsubLookupSubtable parseSubtable(final TtfRandomAccessInput raInput, final int offset,
- final GsubLookup.LookupType lookupType) throws IOException {
- raInput.seek(offset);
-
- final int formatId = raInput.readUnsignedShort();
-
- switch (lookupType) {
- case SINGLE: {
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup01x01, GsubLookup01x01Handler> kit = GsubLookup01x01.createContentHandler();
- final GsubLookup01x01Parser parser = new GsubLookup01x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_2: {
- final ParserKit<GsubLookup01x02, GsubLookup01x02Handler> kit = GsubLookup01x02.createContentHandler();
- final GsubLookup01x02Parser parser = new GsubLookup01x02Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 1: " + formatId);
- }
- }
- case MULTIPLE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup02x01, GsubLookup02x01Handler> kit = GsubLookup02x01.createContentHandler();
- final GsubLookup02x01Parser parser = new GsubLookup02x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 2: " + formatId);
- }
- case ALTERNATE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup03x01, GsubLookup03x01Handler> kit = GsubLookup03x01.createContentHandler();
- final GsubLookup03x01Parser parser = new GsubLookup03x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 3: " + formatId);
- }
- case LIGATURE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup04x01, GsubLookup04x01Handler> kit = GsubLookup04x01.createContentHandler();
- final GsubLookup04x01Parser parser = new GsubLookup04x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 4: " + formatId);
- }
- case CONTEXT:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup05x01, GsubLookup05x01Handler> kit = GsubLookup05x01.createContentHandler();
- final GsubLookup05x01Parser parser = new GsubLookup05x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_2: {
- final ParserKit<GsubLookup05x02, GsubLookup05x02Handler> kit = GsubLookup05x02.createContentHandler();
- final GsubLookup05x02Parser parser = new GsubLookup05x02Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_3: {
- final ParserKit<GsubLookup05x03, GsubLookup05x03Handler> kit = GsubLookup05x03.createContentHandler();
- final GsubLookup05x03Parser parser = new GsubLookup05x03Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 5: " + formatId);
- }
- case CHAINING_CONTEXT:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup06x01, GsubLookup06x01Handler> kit = GsubLookup06x01.createContentHandler();
- final GsubLookup06x01Parser parser = new GsubLookup06x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_2: {
- final ParserKit<GsubLookup06x02, GsubLookup06x02Handler> kit = GsubLookup06x02.createContentHandler();
- final GsubLookup06x02Parser parser = new GsubLookup06x02Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- case FORMAT_3: {
- final ParserKit<GsubLookup06x03, GsubLookup06x03Handler> kit = GsubLookup06x03.createContentHandler();
- final GsubLookup06x03Parser parser = new GsubLookup06x03Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 6: " + formatId);
- }
- case EXTENSION_SUBSTITUTION:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup07x01, GsubLookup07x01Handler> kit = GsubLookup07x01.createContentHandler();
- final GsubLookup07x01Parser parser = new GsubLookup07x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 7: " + formatId);
- }
- case REVERSE_CHAINING_CONTEXT_SINGLE:
- switch (formatId) {
- case FORMAT_1: {
- final ParserKit<GsubLookup08x01, GsubLookup08x01Handler> kit = GsubLookup08x01.createContentHandler();
- final GsubLookup08x01Parser parser = new GsubLookup08x01Parser();
- parser.parse(raInput, offset, kit.getHandler());
- return kit.getTable();
- }
- default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 8: " + formatId);
- }
- default: {
- throw new UnsupportedOperationException("Unrecognized GSUB lookup type: " + lookupType);
- }
- }
- }
-
- /**
- * Returns the lookup type.
- * @return The lookupType.
- */
- protected LookupType getLookupType() {
- return this.lookupType;
- }
-
- /**
- * Returns the lookup flag.
- * @return The lookupFlag.
- */
- protected int getLookupFlag() {
- return this.lookupFlag;
- }
-
- /**
- * Returns the subtables.
- * @return The subtables.
- */
- protected GsubLookupSubtable[] getSubtables() {
- return this.subtables;
- }
-
-}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 21:20:57 UTC (rev 13561)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 21:53:03 UTC (rev 13562)
@@ -78,7 +78,7 @@
/** The lookup list. */
- private List<GsubLookup> lookupList;
+ private List<LookupTable> lookupList;
/**
* Constructor.
@@ -147,7 +147,7 @@
* @return The parsed lookup list.
* @throws IOException For I/O errors during parsing.
*/
- protected static List<GsubLookup> parseLookupList(final TtfRandomAccessInput raInput, final int offset)
+ protected static List<LookupTable> parseLookupList(final TtfRandomAccessInput raInput, final int offset)
throws IOException {
raInput.seek(offset);
final int lookupCount = raInput.readUnsignedShort();
@@ -155,10 +155,10 @@
for (int index = 0; index < lookupCount; index ++) {
lookupTableOffsets[index] = raInput.readUnsignedShort();
}
- final List<GsubLookup> lookupList = new ArrayList<GsubLookup>();
+ final List<LookupTable> lookupList = new ArrayList<LookupTable>();
for (int index = 0; index < lookupCount; index ++) {
- final GsubLookup lookup = GsubLookup.parse(raInput, offset + lookupTableOffsets[index]);
+ final LookupTable lookup = LookupTable.parse(raInput, offset + lookupTableOffsets[index]);
lookupList.add(lookup);
}
return lookupList;
@@ -168,7 +168,7 @@
* Returns the lookup list.
* @return The lookup list.
*/
- public List<GsubLookup> getLookupList() {
+ public List<LookupTable> getLookupList() {
return this.lookupList;
}
@@ -192,9 +192,9 @@
* See http://www.microsoft.com/typography/otspec/chapter2.htm, "Features & Lookups", paragraph 3. */
/* Iterate the lookups in the order that they are listed in the GSUB table. */
- final List<GsubLookup> lookupList = getLookupList();
+ final List<LookupTable> lookupList = getLookupList();
for (int lookupIndex = 0; lookupIndex < lookupList.size(); lookupIndex ++) {
- final GsubLookup lookup = lookupList.get(lookupIndex);
+ final LookupTable lookup = lookupList.get(lookupIndex);
final GsubLookupSubtable[] lookupSubtables = lookup.getSubtables();
for (int subtableIndex = 0; subtableIndex < lookupSubtables.length; subtableIndex ++) {
final GsubLookupSubtable lookupSubtable = lookupSubtables[subtableIndex];
Copied: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java (from rev 13552, trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubLookup.java)
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LookupTable.java 2025-05-01 21:53:03 UTC (rev 13562)
@@ -0,0 +1,333 @@
+/*
+ * Copyright 2016 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.fontParse.ttf.GsubLookup01x01Parser;
+import org.foray.fontParse.ttf.GsubLookup01x02Parser;
+import org.foray.fontParse.ttf.GsubLookup02x01Parser;
+import org.foray.fontParse.ttf.GsubLookup03x01Parser;
+import org.foray.fontParse.ttf.GsubLookup04x01Parser;
+import org.foray.fontParse.ttf.GsubLookup05x01Parser;
+import org.foray.fontParse.ttf.GsubLookup05x02Parser;
+import org.foray.fontParse.ttf.GsubLookup05x03Parser;
+import org.foray.fontParse.ttf.GsubLookup06x01Parser;
+import org.foray.fontParse.ttf.GsubLookup06x02Parser;
+import org.foray.fontParse.ttf.GsubLookup06x03Parser;
+import org.foray.fontParse.ttf.GsubLookup07x01Parser;
+import org.foray.fontParse.ttf.GsubLookup08x01Parser;
+import org.foray.fontParse.ttf.TtfRandomAccessInput;
+import org.foray.fontParse.ttfHandler.GsubLookup01x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup01x02Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup02x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup03x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup04x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup05x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup05x02Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup05x03Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup06x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup06x02Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup06x03Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup07x01Handler;
+import org.foray.fontParse.ttfHandler.GsubLookup08x01Handler;
+
+import java.io.IOException;
+
+/**
+ * An OpenType lookup for the GSUB table.
+ */
+public class LookupTable {
+
+ /**
+ * Enumeration of possible LookupType values in a GSUB table.
+ */
+ public enum LookupType {
+
+ /** Replace one glyph with one glyph. */
+ SINGLE(1),
+
+ /** Replace one glyph with more than one glyph. */
+ MULTIPLE(2),
+
+ /** Replace one glyph with one of many glyphs. */
+ ALTERNATE(3),
+
+ /** Replace multiple glyphs with one glyph. */
+ LIGATURE(4),
+
+ /** Replace one or more glyphs in context. */
+ CONTEXT(5),
+
+ /** Replace one or more glyphs in chained context. */
+ CHAINING_CONTEXT(6),
+
+ /** Extension mechanism for other substitutions (i.e. this excludes the Extension type substitution itself). */
+ EXTENSION_SUBSTITUTION(7),
+
+ /** Applied in reverse order, replace single glyph in chaining context. */
+ REVERSE_CHAINING_CONTEXT_SINGLE(8);
+
+ /** The number this enumerated item is stored as in a font file. */
+ private byte value;
+
+ /**
+ * Constructor.
+ * @param value The number this enumerated item is stored as in a font file.
+ */
+ LookupType(final int value) {
+ this.value = (byte) value;
+ }
+
+ /**
+ * Finds the enumerated item from its value.
+ * @param value The value for which the enumerated item is needed.
+ * @return The enumerated item matching {@code value}, or null if it is not found.
+ */
+ public static LookupType fromValue(final int value) {
+ for (LookupType lookupType : values()) {
+ if (lookupType.value == value) {
+ return lookupType;
+ }
+ }
+ return null;
+ }
+ }
+
+ /** Constant identifying a format number. */
+ private static final byte FORMAT_1 = 1;
+
+ /** Constant identifying a format number. */
+ private static final byte FORMAT_2 = 2;
+
+ /** Constant identifying a format number. */
+ private static final byte FORMAT_3 = 3;
+
+ /** The lookup type for this lookup. */
+ private LookupType lookupType;
+
+ /** The lookup flag. */
+ private int lookupFlag;
+
+ /** The subtables. */
+ private GsubLookupSubtable[] subtables;
+
+ /**
+ * Constructor.
+ */
+ public LookupTable() {
+ }
+
+ /**
+ * Parses a lookup.
+ * @param raInput The input from which the lookup is being parsed.
+ * @param offset The offset in {@code raInput} for the start of the lookup table.
+ * @return The parsed lookup table instance.
+ * @throws IOException For I/O errors during parsing.
+ */
+ public static LookupTable parse(final TtfRandomAccessInput raInput, final int offset) throws IOException {
+ raInput.seek(offset);
+ final LookupTable lookup = new LookupTable();
+ final int lookupTypeInteger = raInput.readUnsignedShort();
+ lookup.lookupType = LookupType.fromValue(lookupTypeInteger);
+ lookup.lookupFlag = raInput.readUnsignedShort();
+ final int subTableCount = raInput.readUnsignedShort();
+ final int[] subTableOffsets = new int[subTableCount];
+ for (int index = 0; index < subTableCount; index ++) {
+ subTableOffsets[index] = raInput.readUnsignedShort();
+ }
+ /* TODO: The last item in the table is named "MarkFilteringSet" with a type of "unit16". Although this is
+ * probably a 16-bit type of some sort, we don't recognize it, and, for now, therefore skip parsing it. */
+
+ lookup.subtables = new GsubLookupSubtable[subTableCount];
+ for (int index = 0; index < subTableCount; index ++) {
+ final GsubLookupSubtable subtable =
+ parseSubtable(raInput, offset + subTableOffsets[index], lookup.lookupType);
+ lookup.subtables[index] = subtable;
+ }
+
+ return lookup;
+ }
+
+ /**
+ * Parses a subtable.
+ * @param raInput The input from which the subtable is being parsed.
+ * @param offset The offset in {@code raInput} for the start of the subtable.
+ * @param lookupType The lookup type being parsed.
+ * @return The parsed subtable instance.
+ * @throws IOException For I/O errors during parsing.
+ */
+ private static GsubLookupSubtable parseSubtable(final TtfRandomAccessInput raInput, final int offset,
+ final LookupTable.LookupType lookupType) throws IOException {
+ raInput.seek(offset);
+
+ final int formatId = raInput.readUnsignedShort();
+
+ switch (lookupType) {
+ case SINGLE: {
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup01x01, GsubLookup01x01Handler> kit = GsubLookup01x01.createContentHandler();
+ final GsubLookup01x01Parser parser = new GsubLookup01x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ case FORMAT_2: {
+ final ParserKit<GsubLookup01x02, GsubLookup01x02Handler> kit = GsubLookup01x02.createContentHandler();
+ final GsubLookup01x02Parser parser = new GsubLookup01x02Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 1: " + formatId);
+ }
+ }
+ case MULTIPLE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup02x01, GsubLookup02x01Handler> kit = GsubLookup02x01.createContentHandler();
+ final GsubLookup02x01Parser parser = new GsubLookup02x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 2: " + formatId);
+ }
+ case ALTERNATE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup03x01, GsubLookup03x01Handler> kit = GsubLookup03x01.createContentHandler();
+ final GsubLookup03x01Parser parser = new GsubLookup03x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 3: " + formatId);
+ }
+ case LIGATURE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup04x01, GsubLookup04x01Handler> kit = GsubLookup04x01.createContentHandler();
+ final GsubLookup04x01Parser parser = new GsubLookup04x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 4: " + formatId);
+ }
+ case CONTEXT:
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup05x01, GsubLookup05x01Handler> kit = GsubLookup05x01.createContentHandler();
+ final GsubLookup05x01Parser parser = new GsubLookup05x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ case FORMAT_2: {
+ final ParserKit<GsubLookup05x02, GsubLookup05x02Handler> kit = GsubLookup05x02.createContentHandler();
+ final GsubLookup05x02Parser parser = new GsubLookup05x02Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ case FORMAT_3: {
+ final ParserKit<GsubLookup05x03, GsubLookup05x03Handler> kit = GsubLookup05x03.createContentHandler();
+ final GsubLookup05x03Parser parser = new GsubLookup05x03Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 5: " + formatId);
+ }
+ case CHAINING_CONTEXT:
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup06x01, GsubLookup06x01Handler> kit = GsubLookup06x01.createContentHandler();
+ final GsubLookup06x01Parser parser = new GsubLookup06x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ case FORMAT_2: {
+ final ParserKit<GsubLookup06x02, GsubLookup06x02Handler> kit = GsubLookup06x02.createContentHandler();
+ final GsubLookup06x02Parser parser = new GsubLookup06x02Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ case FORMAT_3: {
+ final ParserKit<GsubLookup06x03, GsubLookup06x03Handler> kit = GsubLookup06x03.createContentHandler();
+ final GsubLookup06x03Parser parser = new GsubLookup06x03Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 6: " + formatId);
+ }
+ case EXTENSION_SUBSTITUTION:
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup07x01, GsubLookup07x01Handler> kit = GsubLookup07x01.createContentHandler();
+ final GsubLookup07x01Parser parser = new GsubLookup07x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 7: " + formatId);
+ }
+ case REVERSE_CHAINING_CONTEXT_SINGLE:
+ switch (formatId) {
+ case FORMAT_1: {
+ final ParserKit<GsubLookup08x01, GsubLookup08x01Handler> kit = GsubLookup08x01.createContentHandler();
+ final GsubLookup08x01Parser parser = new GsubLookup08x01Parser();
+ parser.parse(raInput, offset, kit.getHandler());
+ return kit.getTable();
+ }
+ default: throw new UnsupportedOperationException("Unrecognized GSUB lookup type 8: " + formatId);
+ }
+ default: {
+ throw new UnsupportedOperationException("Unrecognized GSUB lookup type: " + lookupType);
+ }
+ }
+ }
+
+ /**
+ * Returns the lookup type.
+ * @return The lookupType.
+ */
+ protected LookupType getLookupType() {
+ return this.lookupType;
+ }
+
+ /**
+ * Returns the lookup flag.
+ * @return The lookupFlag.
+ */
+ protected int getLookupFlag() {
+ return this.lookupFlag;
+ }
+
+ /**
+ * Returns the subtables.
+ * @return The subtables.
+ */
+ protected GsubLookupSubtable[] getSubtables() {
+ return this.subtables;
+ }
+
+}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java 2025-05-01 21:20:57 UTC (rev 13561)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java 2025-05-01 21:53:03 UTC (rev 13562)
@@ -119,7 +119,7 @@
* Returns the number of scripts in this script list.
* @return The number of scripts in this script list.
*/
- public int getQtyScripts() {
+ public int size() {
return this.scriptTags.length;
}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 21:20:57 UTC (rev 13561)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 21:53:03 UTC (rev 13562)
@@ -56,7 +56,7 @@
import java.util.List;
/**
- * Tests of {@link GsubLookup}.
+ * Tests of {@link LookupTable}.
*/
public class OtfLookupGsubTests {
@@ -100,7 +100,7 @@
/* Tests of the scripts. */
final ScriptListTable scriptList = gsub.getScriptList();
assertNotNull(scriptList);
- assertEquals(4, scriptList.getQtyScripts());
+ assertEquals(4, scriptList.size());
assertNotNull(gsub.getScript("grek"));
assertNotNull(gsub.getScript("hebr"));
assertNotNull(gsub.getScript("ital"));
@@ -136,60 +136,60 @@
assertEquals(2, ligaFeature.lookupListIndexAt(0));
/* Tests of the lookup list. */
- final List<GsubLookup> lookupList = gsub.getLookupList();
+ final List<LookupTable> lookupList = gsub.getLookupList();
assertNotNull(lookupList);
assertEquals(40, lookupList.size());
- final GsubLookup.LookupType[] expectedLookupTypes = {
- GsubLookup.LookupType.LIGATURE, // 0
- GsubLookup.LookupType.CHAINING_CONTEXT, // 1
- GsubLookup.LookupType.LIGATURE, // 2
- GsubLookup.LookupType.SINGLE, // 3
- GsubLookup.LookupType.SINGLE, // 4
- GsubLookup.LookupType.LIGATURE, // 5
- GsubLookup.LookupType.LIGATURE, // 6
- GsubLookup.LookupType.SINGLE, // 7
- GsubLookup.LookupType.SINGLE, // 8
- GsubLookup.LookupType.SINGLE, // 9
- GsubLookup.LookupType.SINGLE, // 10
- GsubLookup.LookupType.SINGLE, // 11
- GsubLookup.LookupType.SINGLE, // 12
- GsubLookup.LookupType.SINGLE, // 13
- GsubLookup.LookupType.SINGLE, // 14
- GsubLookup.LookupType.SINGLE, // 15
- GsubLookup.LookupType.SINGLE, // 16
- GsubLookup.LookupType.SINGLE, // 17
- GsubLookup.LookupType.SINGLE, // 18
- GsubLookup.LookupType.SINGLE, // 19
- GsubLookup.LookupType.SINGLE, // 20
- GsubLookup.LookupType.SINGLE, // 21
- GsubLookup.LookupType.LIGATURE, // 22
- GsubLookup.LookupType.SINGLE, // 23
- GsubLookup.LookupType.ALTERNATE, // 24
- GsubLookup.LookupType.SINGLE, // 25
- GsubLookup.LookupType.SINGLE, // 26
- GsubLookup.LookupType.SINGLE, // 27
- GsubLookup.LookupType.SINGLE, // 28
- GsubLookup.LookupType.ALTERNATE, // 29
- GsubLookup.LookupType.SINGLE, // 30
- GsubLookup.LookupType.ALTERNATE, // 31
- GsubLookup.LookupType.ALTERNATE, // 32
- GsubLookup.LookupType.ALTERNATE, // 33
- GsubLookup.LookupType.SINGLE, // 34
- GsubLookup.LookupType.SINGLE, // 35
- GsubLookup.LookupType.LIGATURE, // 36
- GsubLookup.LookupType.LIGATURE, // 37
- GsubLookup.LookupType.SINGLE, // 38
- GsubLookup.LookupType.SINGLE // 39
+ final LookupTable.LookupType[] expectedLookupTypes = {
+ LookupTable.LookupType.LIGATURE, // 0
+ LookupTable.LookupType.CHAINING_CONTEXT, // 1
+ LookupTable.LookupType.LIGATURE, // 2
+ LookupTable.LookupType.SINGLE, // 3
+ LookupTable.LookupType.SINGLE, // 4
+ LookupTable.LookupType.LIGATURE, // 5
+ LookupTable.LookupType.LIGATURE, // 6
+ LookupTable.LookupType.SINGLE, // 7
+ LookupTable.LookupType.SINGLE, // 8
+ LookupTable.LookupType.SINGLE, // 9
+ LookupTable.LookupType.SINGLE, // 10
+ LookupTable.LookupType.SINGLE, // 11
+ LookupTable.LookupType.SINGLE, // 12
+ LookupTable.LookupType.SINGLE, // 13
+ LookupTable.LookupType.SINGLE, // 14
+ LookupTable.LookupType.SINGLE, // 15
+ LookupTable.LookupType.SINGLE, // 16
+ LookupTable.LookupType.SINGLE, // 17
+ LookupTable.LookupType.SINGLE, // 18
+ LookupTable.LookupType.SINGLE, // 19
+ LookupTable.LookupType.SINGLE, // 20
+ LookupTable.LookupType.SINGLE, // 21
+ LookupTable.LookupType.LIGATURE, // 22
+ LookupTable.LookupType.SINGLE, // 23
+ LookupTable.LookupType.ALTERNATE, // 24
+ LookupTable.LookupType.SINGLE, // 25
+ LookupTable.LookupType.SINGLE, // 26
+ LookupTable.LookupType.SINGLE, // 27
+ LookupTable.LookupType.SINGLE, // 28
+ LookupTable.LookupType.ALTERNATE, // 29
+ LookupTable.LookupType.SINGLE, // 30
+ LookupTable.LookupType.ALTERNATE, // 31
+ LookupTable.LookupType.ALTERNATE, // 32
+ LookupTable.LookupType.ALTERNATE, // 33
+ LookupTable.LookupType.SINGLE, // 34
+ LookupTable.LookupType.SINGLE, // 35
+ LookupTable.LookupType.LIGATURE, // 36
+ LookupTable.LookupType.LIGATURE, // 37
+ LookupTable.LookupType.SINGLE, // 38
+ LookupTable.LookupType.SINGLE // 39
};
for (int index = 0; index < expectedLookupTypes.length; index ++) {
- final GsubLookup.LookupType expectedLookupType = expectedLookupTypes[index];
- final GsubLookup actual = lookupList.get(index);
+ final LookupTable.LookupType expectedLookupType = expectedLookupTypes[index];
+ final LookupTable actual = lookupList.get(index);
assertEquals(expectedLookupType, actual.getLookupType(), "Failure at index: " + index);
}
/* Tests of the LIGATURE lookup table pointed to by the latin features. The "liga" feature contains only one
* index = 2. */
- final GsubLookup ligatureLookup = lookupList.get(2);
+ final LookupTable ligatureLookup = lookupList.get(2);
final GsubLookupSubtable[] ligatureLookupSubtables = ligatureLookup.getSubtables();
assertEquals(1, ligatureLookupSubtables.length);
final GsubLookupSubtable ligatureLookupSubtable = ligatureLookupSubtables[0];
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java 2025-05-01 21:53:03 UTC (rev 13562)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.LookupTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "Lookup" table.
+ */
+public class LookupTableParser extends TableParser<LookupTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final LookupTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ final @Unsigned short lookupType = input.read_uint16(); // 2 bytes, total 2
+ handler.lookupType(lookupType);
+ handler.lookupFlag(input.read_uint16()); // 2 bytes, total 4
+ final @Unsigned short subTableCount = input.read_uint16(); // 2 bytes, total 6
+ handler.subTableCount(subTableCount);
+
+
+
+ /* TODO: Complete this. */
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LookupTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java 2025-05-01 21:53:03 UTC (rev 13562)
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.LookupTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link LookupTableParser}.
+ */
+public interface LookupTableHandler extends FontContentHandler {
+
+ default void lookupType(short value) { return; }
+ default void lookupFlag(short value) { return; }
+ default void subTableCount(short value) { return; }
+ default void subtableOffset(short value) { return; }
+ default void markFilteringSet(short value) { return; }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LookupTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 21:21:21
|
Revision: 13561
http://sourceforge.net/p/foray/code/13561
Author: victormote
Date: 2025-05-01 21:20:57 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Complete conversion of FeatureList table parsing to new scheme, including fixing a test that essentially exposed a bug in the previous logic.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 18:15:54 UTC (rev 13560)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 21:20:57 UTC (rev 13561)
@@ -29,15 +29,9 @@
package org.foray.font.ttf.table;
import org.foray.common.RandomAccessInput;
-import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
-import org.foray.fontParse.ttf.FeatureTableParser;
-import org.foray.fontParse.ttf.TtfRandomAccessInput;
-import org.foray.fontParse.ttfHandler.FeatureTableHandler;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
/**
* Abstract superclass for the OpenType layout tables.
@@ -47,49 +41,20 @@
/** List of OpenType scripts for this table. */
private ScriptListTable scriptList;
- /** Map of OpenType features for this table. The key is the feature tag, and the value is the OtfFeature instance
- * for that tag. */
- private Map<String, FeatureTable> featureMap;
+ /** List of OpenType features for this table. */
+ private FeatureListTable featureList;
/**
* Constructor.
* @param scriptList The script list for this table.
- * @param featureMap The feature map for this table.
+ * @param featureList The feature list for this table.
*/
- AbstractOtfLayoutTable(final ScriptListTable scriptList, final Map<String, FeatureTable> featureMap) {
+ AbstractOtfLayoutTable(final ScriptListTable scriptList, final FeatureListTable featureList) {
this.scriptList = scriptList;
- this.featureMap = featureMap;
+ this.featureList = featureList;
}
/**
- * Parses the feature list.
- * @param raInput The input from which the feature list is being parsed.
- * @param offset The offset in {@code raInput} for the start of the feature list.
- * @return The parsed map of features.
- * @throws IOException For I/O errors during parsing.
- */
- protected static Map<String, FeatureTable> parseFeatureList(final TtfRandomAccessInput raInput, final int offset)
- throws IOException {
- raInput.seek(offset);
- final int featureCount = raInput.readUnsignedShort();
- final String[] featureTags = new String[featureCount];
- final int[] featureOffsets = new int[featureCount];
- for (int index = 0; index < featureCount; index ++) {
- featureTags[index] = raInput.readStringASCII(FeatureTable.TAG_SIZE);
- featureOffsets[index] = raInput.readUnsignedShort();
- }
- final Map<String, FeatureTable> featureMap = new HashMap<String, FeatureTable>();
- for (int index = 0; index < featureCount; index ++) {
- final ParserKit<FeatureTable, FeatureTableHandler> kit = FeatureTable.createContentHandler();
- final FeatureTableParser parser = new FeatureTableParser();
- parser.parse(raInput, offset + featureOffsets[index], kit.getHandler());
- final FeatureTable feature = kit.getTable();
- featureMap.put(featureTags[index], feature);
- }
- return featureMap;
- }
-
- /**
* Parses the feature variations.
* @param raInput The input from which the feature variations is being parsed.
* @param offset The offset in {@code raInput} for the start of the feature variations.
@@ -114,18 +79,6 @@
}
/**
- * Returns the feature instance for a given tag.
- * @param featureTag The feature tag to be retrieved.
- * @return The feature instance referenced by {@code featureTag}, or null if that reference does not exist.
- */
- public FeatureTable getFeature(final String featureTag) {
- if (this.featureMap == null) {
- return null;
- }
- return this.featureMap.get(featureTag);
- }
-
- /**
* Package-visible method for testing.
* @return The script list.
*/
@@ -135,10 +88,10 @@
/**
* Package-visible method for testing.
- * @return The feature map.
+ * @return The feature list.
*/
- Map<String, FeatureTable> getFeatureMap() {
- return this.featureMap;
+ FeatureListTable getFeatureList() {
+ return this.featureList;
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java 2025-05-01 18:15:54 UTC (rev 13560)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java 2025-05-01 21:20:57 UTC (rev 13561)
@@ -35,8 +35,6 @@
import org.checkerframework.checker.signedness.qual.Unsigned;
-import java.util.Arrays;
-
/**
* An OpenType "FeatureList"table.
*/
@@ -105,16 +103,6 @@
}
/**
- * Returns the feature for a given feature tag.
- * @param featureTag The The tag for which a feature should be returned.
- * @return The script for {@code featureTag}, or null if not found.
- */
- public FeatureTable get(final String featureTag) {
- final int index = Arrays.binarySearch(this.featureTags, featureTag);
- return index >= 0 ? this.features[index] : null;
- }
-
- /**
* Returns the number of scripts in this script list.
* @return The number of scripts in this script list.
*/
@@ -122,4 +110,22 @@
return this.featureTags.length;
}
+ /**
+ * Return the feature tag at a given index.
+ * @param index The index for which the feature tag should be returned.
+ * @return The feature tag at {@code index}.
+ */
+ public String getFeatureTag(final int index) {
+ return this.featureTags[index];
+ }
+
+ /**
+ * Return the feature at a given index.
+ * @param index The index for which the feature should be returned.
+ * @return The feature at {@code index}.
+ */
+ public FeatureTable getFeature(final int index) {
+ return this.features[index];
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 18:15:54 UTC (rev 13560)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 21:20:57 UTC (rev 13561)
@@ -30,8 +30,10 @@
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.TtfOffsetTableRecord;
+import org.foray.fontParse.ttf.FeatureListTableParser;
import org.foray.fontParse.ttf.ScriptListTableParser;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
+import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
import org.foray.primitive.sequence.IntArrayBuilder;
@@ -42,7 +44,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
/**
* An OpenType "GSUB" (Glyphs Substitution Data) table.
@@ -82,10 +83,10 @@
/**
* Constructor.
* @param scriptMap The scripts for this table.
- * @param featureMap The features for this table.
+ * @param featureListTable The features for this table.
*/
- public GsubTable(final ScriptListTable scriptMap, final Map<String, FeatureTable> featureMap) {
- super(scriptMap, featureMap);
+ public GsubTable(final ScriptListTable scriptMap, final FeatureListTable featureListTable) {
+ super(scriptMap, featureListTable);
}
/**
@@ -121,15 +122,17 @@
featureVariationsOffset = -1;
}
- final ParserKit<ScriptListTable, ScriptListTableHandler> kit = ScriptListTable.createContentHandler();
- final ScriptListTableParser parser = new ScriptListTableParser();
- parser.parse(raInput, offsetRecord.getOffset() + scriptListOffset, kit.getHandler());
- final ScriptListTable scriptListTable = kit.getTable();
+ final ParserKit<ScriptListTable, ScriptListTableHandler> scriptKit = ScriptListTable.createContentHandler();
+ final ScriptListTableParser scriptParser = new ScriptListTableParser();
+ scriptParser.parse(raInput, offsetRecord.getOffset() + scriptListOffset, scriptKit.getHandler());
+ final ScriptListTable scriptListTable = scriptKit.getTable();
- final Map<String, FeatureTable> featureMap =
- parseFeatureList(raInput, offsetRecord.getOffset() + featureListOffset);
+ final ParserKit<FeatureListTable, FeatureListTableHandler> featureKit = FeatureListTable.createContentHandler();
+ final FeatureListTableParser featureParser = new FeatureListTableParser();
+ featureParser.parse(raInput, offsetRecord.getOffset() + featureListOffset, featureKit.getHandler());
+ final FeatureListTable featureListTable = featureKit.getTable();
- final GsubTable table = new GsubTable(scriptListTable, featureMap);
+ final GsubTable table = new GsubTable(scriptListTable, featureListTable);
table.lookupList = parseLookupList(raInput, offsetRecord.getOffset() + lookupListOffset);
parseFeatureVariations(raInput, offsetRecord.getOffset() + featureVariationsOffset);
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 18:15:54 UTC (rev 13560)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 21:20:57 UTC (rev 13561)
@@ -54,7 +54,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import java.util.Map;
/**
* Tests of {@link GsubLookup}.
@@ -118,18 +117,21 @@
assertArrayEquals(expectedFeatures, defaultLatinLanguageSystem.getFeatureIndexes());
/* Tests of the features. */
- final Map<String, FeatureTable> featureMap = gsub.getFeatureMap();
- assertNotNull(featureMap);
- assertEquals(25, featureMap.size());
- final String[] expectedFeatureTags =
- {"onum", "pnum", "hist", "subs", "hlig", "ss15", "ss13", "ss11", "ss12", "sups", "liga", "ccmp", "dlig",
- "ss10", "ss01", "ss03", "ss02", "ss05", "ss04", "smcp", "ss07", "ss06", "ss09", "ss08", "salt"};
- for (String expectedFeatureTag : expectedFeatureTags) {
- assertNotNull(gsub.getFeature(expectedFeatureTag));
+ final FeatureListTable featureList = gsub.getFeatureList();
+ assertNotNull(featureList);
+ assertEquals(31, featureList.size());
+ final String[] expectedFeatureTags = {
+ "ccmp", "ccmp", "dlig", "dlig", "hist", "hlig", "liga", "onum", "onum", "pnum",
+ "pnum", "salt", "salt", "smcp", "ss01", "ss01", "ss02", "ss03", "ss04", "ss05",
+ "ss06", "ss07", "ss08", "ss09", "ss10", "ss11", "ss12", "ss13", "ss15", "subs",
+ "sups" };
+ for (int index = 0; index < expectedFeatureTags.length; index ++) {
+ assertEquals(expectedFeatureTags[index], featureList.getFeatureTag(index));
+ assertNotNull(featureList.getFeature(index));
}
- /* Test of the "liga" feature. */
- final FeatureTable ligaFeature = gsub.getFeature("liga");
+ /* Test of the "liga" feature, which, as seen above, is at index 6. */
+ final FeatureTable ligaFeature = featureList.getFeature(6);
assertEquals(1, ligaFeature.lookupListIndexLength());
assertEquals(2, ligaFeature.lookupListIndexAt(0));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 18:16:16
|
Revision: 13560
http://sourceforge.net/p/foray/code/13560
Author: victormote
Date: 2025-05-01 18:15:54 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Add supporting classes for FeatureList table parsing under new scheme.
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureListTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureListTableHandler.java
Added: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java 2025-05-01 18:15:54 UTC (rev 13560)
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
+import org.foray.fontParse.ttfHandler.FeatureTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.util.Arrays;
+
+/**
+ * An OpenType "FeatureList"table.
+ */
+public class FeatureListTable extends RoTable {
+
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements FeatureListTableHandler {
+
+ /** The table instance being created. */
+ private FeatureListTable table;
+
+ /** Index to the current feature being parsed. */
+ private int currentFeatureIndex = -1;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final FeatureListTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public void featureCount(final @Unsigned short value) {
+ this.table.featureTags = new String[value];
+ this.table.features = new FeatureTable[value];
+ }
+
+ @Override
+ public void featureTag(final String value) {
+ this.currentFeatureIndex ++;
+ this.table.featureTags[this.currentFeatureIndex] = value;
+ }
+
+ @Override
+ public FeatureTableHandler startFeatureTable() {
+ final ParserKit<FeatureTable, FeatureTableHandler> kit = FeatureTable.createContentHandler();
+ this.table.features[this.currentFeatureIndex] = kit.getTable();
+ return kit.getHandler();
+ }
+ }
+
+
+
+
+
+
+
+
+ /** The feature tags in this feature list. Parallel to {@link #features}. */
+ private String[] featureTags;
+
+ /** The scripts in this script list. Parallel to {@link #featureTags}. */
+ private FeatureTable[] features;
+
+ /**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<FeatureListTable, FeatureListTableHandler> createContentHandler() {
+ final FeatureListTable table = new FeatureListTable();
+ final FeatureListTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<FeatureListTable, FeatureListTableHandler>(table, handler);
+ }
+
+ /**
+ * Returns the feature for a given feature tag.
+ * @param featureTag The The tag for which a feature should be returned.
+ * @return The script for {@code featureTag}, or null if not found.
+ */
+ public FeatureTable get(final String featureTag) {
+ final int index = Arrays.binarySearch(this.featureTags, featureTag);
+ return index >= 0 ? this.features[index] : null;
+ }
+
+ /**
+ * Returns the number of scripts in this script list.
+ * @return The number of scripts in this script list.
+ */
+ public int size() {
+ return this.featureTags.length;
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureListTable.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureListTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureListTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureListTableParser.java 2025-05-01 18:15:54 UTC (rev 13560)
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.FeatureListTableHandler;
+import org.foray.fontParse.ttfHandler.FeatureTableHandler;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "FeatureList" table.
+ */
+public class FeatureListTableParser extends TableParser<FeatureListTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final FeatureListTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ final short featureCount = input.read_uint16(); // 2 bytes, total 2
+ handler.featureCount(featureCount);
+
+ for (int index = 0; index < featureCount; index ++) {
+ final String featureTag = input.read_Tag(); // 4 bytes @
+ handler.featureTag(featureTag);
+ final short featureOffset = input.read_Offset16(); // 2 bytes @
+ handler.featureOffset(featureOffset);
+
+ final long bookmark = input.getOffset();
+
+ final FeatureTableHandler featureHandler = handler.startFeatureTable();
+ final FeatureTableParser parser = new FeatureTableParser();
+ parser.parse(input, offset + featureOffset, featureHandler);
+
+ input.seek(bookmark);
+ }
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureListTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureListTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureListTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureListTableHandler.java 2025-05-01 18:15:54 UTC (rev 13560)
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.MathTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link MathTableParser}.
+ */
+public interface FeatureListTableHandler extends FontContentHandler {
+
+ default void featureCount(short value) { return; }
+
+ default void featureTag(String value) { return; }
+ default void featureOffset(short value) { return; }
+ default FeatureTableHandler startFeatureTable() { return null; }
+
+
+ /* TODO: Complete this. */
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureListTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 17:29:58
|
Revision: 13559
http://sourceforge.net/p/foray/code/13559
Author: victormote
Date: 2025-05-01 17:29:39 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Move OtfFeature to table package and rename it FeatureTable, to match OTF doc. Convert it to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureTableHandler.java
Removed Paths:
-------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java
Deleted: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java 2025-05-01 16:51:20 UTC (rev 13558)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java 2025-05-01 17:29:39 UTC (rev 13559)
@@ -1,88 +0,0 @@
-/*
- * Copyright 2016 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font.ttf;
-
-import org.foray.common.RandomAccessInput;
-
-import java.io.IOException;
-
-/**
- * An OpenType layout table feature.
- */
-public class OtfFeature {
-
- /** The size, in bytes, of an OpenType Feature tag. */
- public static final int TAG_SIZE = 4;
-
- /** Array of lookup list indexes for this feature. */
- private char[] lookupListIndexes;
-
- /**
- * Constructor.
- */
- public OtfFeature() {
- }
-
- /**
- * Parses a feature.
- * @param raInput The input from which the feature is being parsed.
- * @param offset The offset in {@code raInput} for the start of the feature table.
- * @return The parsed feature table instance.
- * @throws IOException For I/O errors during parsing.
- */
- public static OtfFeature parse(final RandomAccessInput raInput, final int offset) throws IOException {
- raInput.seek(offset);
- final OtfFeature feature = new OtfFeature();
- /*final int featureParamsOffset = */raInput.readUnsignedShort();
- final int lookupCount = raInput.readUnsignedShort();
- feature.lookupListIndexes = new char[lookupCount];
- for (int index = 0; index < lookupCount; index ++) {
- feature.lookupListIndexes[index] = raInput.readChar();
- }
- return feature;
- }
-
- /**
- * Returns the number of lookup list indexes in this feature.
- * @return The number of lookup list indexes in this feature.
- */
- public int lookupListIndexLength() {
- return this.lookupListIndexes.length;
- }
-
- /**
- * Returns a specified lookup list index.
- * @param index The index into the lookup list indexes.
- * @return The lookup list index at {@code index}.
- */
- public char lookupListIndexAt(final int index) {
- return this.lookupListIndexes[index];
- }
-
-}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 16:51:20 UTC (rev 13558)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 17:29:39 UTC (rev 13559)
@@ -29,8 +29,11 @@
package org.foray.font.ttf.table;
import org.foray.common.RandomAccessInput;
-import org.foray.font.ttf.OtfFeature;
+import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttf.FeatureTableParser;
+import org.foray.fontParse.ttf.TtfRandomAccessInput;
+import org.foray.fontParse.ttfHandler.FeatureTableHandler;
import java.io.IOException;
import java.util.HashMap;
@@ -46,7 +49,7 @@
/** Map of OpenType features for this table. The key is the feature tag, and the value is the OtfFeature instance
* for that tag. */
- private Map<String, OtfFeature> featureMap;
+ private Map<String, FeatureTable> featureMap;
/**
* Constructor.
@@ -53,7 +56,7 @@
* @param scriptList The script list for this table.
* @param featureMap The feature map for this table.
*/
- AbstractOtfLayoutTable(final ScriptListTable scriptList, final Map<String, OtfFeature> featureMap) {
+ AbstractOtfLayoutTable(final ScriptListTable scriptList, final Map<String, FeatureTable> featureMap) {
this.scriptList = scriptList;
this.featureMap = featureMap;
}
@@ -65,7 +68,7 @@
* @return The parsed map of features.
* @throws IOException For I/O errors during parsing.
*/
- protected static Map<String, OtfFeature> parseFeatureList(final RandomAccessInput raInput, final int offset)
+ protected static Map<String, FeatureTable> parseFeatureList(final TtfRandomAccessInput raInput, final int offset)
throws IOException {
raInput.seek(offset);
final int featureCount = raInput.readUnsignedShort();
@@ -72,12 +75,15 @@
final String[] featureTags = new String[featureCount];
final int[] featureOffsets = new int[featureCount];
for (int index = 0; index < featureCount; index ++) {
- featureTags[index] = raInput.readStringASCII(OtfFeature.TAG_SIZE);
+ featureTags[index] = raInput.readStringASCII(FeatureTable.TAG_SIZE);
featureOffsets[index] = raInput.readUnsignedShort();
}
- final Map<String, OtfFeature> featureMap = new HashMap<String, OtfFeature>();
+ final Map<String, FeatureTable> featureMap = new HashMap<String, FeatureTable>();
for (int index = 0; index < featureCount; index ++) {
- final OtfFeature feature = OtfFeature.parse(raInput, offset + featureOffsets[index]);
+ final ParserKit<FeatureTable, FeatureTableHandler> kit = FeatureTable.createContentHandler();
+ final FeatureTableParser parser = new FeatureTableParser();
+ parser.parse(raInput, offset + featureOffsets[index], kit.getHandler());
+ final FeatureTable feature = kit.getTable();
featureMap.put(featureTags[index], feature);
}
return featureMap;
@@ -112,7 +118,7 @@
* @param featureTag The feature tag to be retrieved.
* @return The feature instance referenced by {@code featureTag}, or null if that reference does not exist.
*/
- public OtfFeature getFeature(final String featureTag) {
+ public FeatureTable getFeature(final String featureTag) {
if (this.featureMap == null) {
return null;
}
@@ -131,7 +137,7 @@
* Package-visible method for testing.
* @return The feature map.
*/
- Map<String, OtfFeature> getFeatureMap() {
+ Map<String, FeatureTable> getFeatureMap() {
return this.featureMap;
}
Copied: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureTable.java (from rev 13558, trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java)
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/FeatureTable.java 2025-05-01 17:29:39 UTC (rev 13559)
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2016 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.FeatureTableHandler;
+
+/**
+ * An OpenType layout table feature.
+ */
+public class FeatureTable extends RoTable {
+
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements FeatureTableHandler {
+
+ /** The table instance being created. */
+ private FeatureTable table;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final FeatureTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public void lookupIndexCount(final short value) {
+ this.table.lookupListIndexes = new char[value];
+ }
+
+ @Override
+ public void lookupListIndexes(final short[] value) {
+ for (int index = 0; index < value.length; index ++) {
+ this.table.lookupListIndexes[index] = (char) value[index];
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+ /** The size, in bytes, of an OpenType Feature tag. */
+ public static final int TAG_SIZE = 4;
+
+ /** Array of lookup list indexes for this feature. */
+ private char[] lookupListIndexes;
+
+ /**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<FeatureTable, FeatureTableHandler> createContentHandler() {
+ final FeatureTable table = new FeatureTable();
+ final FeatureTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<FeatureTable, FeatureTableHandler>(table, handler);
+ }
+
+ /**
+ * Returns the number of lookup list indexes in this feature.
+ * @return The number of lookup list indexes in this feature.
+ */
+ public int lookupListIndexLength() {
+ return this.lookupListIndexes.length;
+ }
+
+ /**
+ * Returns a specified lookup list index.
+ * @param index The index into the lookup list indexes.
+ * @return The lookup list index at {@code index}.
+ */
+ public char lookupListIndexAt(final int index) {
+ return this.lookupListIndexes[index];
+ }
+
+}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 16:51:20 UTC (rev 13558)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 17:29:39 UTC (rev 13559)
@@ -28,7 +28,6 @@
package org.foray.font.ttf.table;
-import org.foray.font.ttf.OtfFeature;
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.TtfOffsetTableRecord;
import org.foray.fontParse.ttf.ScriptListTableParser;
@@ -85,7 +84,7 @@
* @param scriptMap The scripts for this table.
* @param featureMap The features for this table.
*/
- public GsubTable(final ScriptListTable scriptMap, final Map<String, OtfFeature> featureMap) {
+ public GsubTable(final ScriptListTable scriptMap, final Map<String, FeatureTable> featureMap) {
super(scriptMap, featureMap);
}
@@ -127,7 +126,7 @@
parser.parse(raInput, offsetRecord.getOffset() + scriptListOffset, kit.getHandler());
final ScriptListTable scriptListTable = kit.getTable();
- final Map<String, OtfFeature> featureMap =
+ final Map<String, FeatureTable> featureMap =
parseFeatureList(raInput, offsetRecord.getOffset() + featureListOffset);
final GsubTable table = new GsubTable(scriptListTable, featureMap);
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 16:51:20 UTC (rev 13558)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 17:29:39 UTC (rev 13559)
@@ -32,7 +32,6 @@
import org.foray.font.FontServer4a;
import org.foray.font.format.FontContent;
import org.foray.font.format.FontParser;
-import org.foray.font.ttf.OtfFeature;
import org.foray.font.ttf.TrueTypeFont;
import org.foray.font.ttf.TrueTypeSingle;
import org.foray.font.ttf.table.GsubLookup04x01.Ligature;
@@ -119,7 +118,7 @@
assertArrayEquals(expectedFeatures, defaultLatinLanguageSystem.getFeatureIndexes());
/* Tests of the features. */
- final Map<String, OtfFeature> featureMap = gsub.getFeatureMap();
+ final Map<String, FeatureTable> featureMap = gsub.getFeatureMap();
assertNotNull(featureMap);
assertEquals(25, featureMap.size());
final String[] expectedFeatureTags =
@@ -130,7 +129,7 @@
}
/* Test of the "liga" feature. */
- final OtfFeature ligaFeature = gsub.getFeature("liga");
+ final FeatureTable ligaFeature = gsub.getFeature("liga");
assertEquals(1, ligaFeature.lookupListIndexLength());
assertEquals(2, ligaFeature.lookupListIndexAt(0));
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureTableParser.java 2025-05-01 17:29:39 UTC (rev 13559)
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.FeatureTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "Feature" table.
+ */
+public class FeatureTableParser extends TableParser<FeatureTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final FeatureTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ handler.featureParamsOffset(input.read_Offset16());
+ final @Unsigned short lookupIndexCount = input.read_uint16();
+ handler.lookupIndexCount(lookupIndexCount);
+
+ final @Unsigned short[] lookupListIndexes = new @Unsigned short[lookupIndexCount];
+ for (int index = 0; index < lookupIndexCount; index ++) {
+ final @Unsigned short lookupListIndex = input.read_uint16();
+ handler.lookupListIndex(lookupListIndex);
+ lookupListIndexes[index] = lookupListIndex;
+ }
+ handler.lookupListIndexes(lookupListIndexes);
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/FeatureTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureTableHandler.java 2025-05-01 17:29:39 UTC (rev 13559)
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.FeatureTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link FeatureTableParser}.
+ */
+public interface FeatureTableHandler extends FontContentHandler {
+
+ default void featureParamsOffset(short value) { return; }
+ default void lookupIndexCount(short value) { return; }
+
+ /* The data being the same, most applications will want to use only one of either lookupListIndex or
+ * lookupListIndexes. */
+ default void lookupListIndex(short value) { return; }
+ default void lookupListIndexes(short[] value) { return; }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/FeatureTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 16:51:39
|
Revision: 13558
http://sourceforge.net/p/foray/code/13558
Author: victormote
Date: 2025-05-01 16:51:20 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Extract OtfFeatureTag enumeration into its own file.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeatureTag.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java 2025-05-01 16:23:16 UTC (rev 13557)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeature.java 2025-05-01 16:51:20 UTC (rev 13558)
@@ -37,400 +37,6 @@
*/
public class OtfFeature {
- /**
- * Enumeration of the various OTF feature tags.
- */
- public enum OtfFeatureTag {
- /** The "aalt" tag. */
- ACCESS_ALL_ALTERNATES("aalt"),
-
- /** The "abvf" tag. */
- ABOVE_BASE_FORMS("abvf"),
-
- /** The "abvm" tag. */
- ABOVE_BASE_MARK_POSITIONING("abvm"),
-
- /** The "abvs" tag. */
- ABOVE_BASE_SUBSTITUTIONS("abvs"),
-
- /** The "afrc" tag. */
- ALTERNATIVE_FRACTIONS("afrc"),
-
- /** The "akhn" tag. */
- AKHANDS("akhn"),
-
- /** The "blwf" tag. */
- BELOW_BASE_FORMS("blwf"),
-
- /** The "blwm" tag. */
- BELOW_BASE_MARK_POSITIONING("blwm"),
-
- /** The "blws" tag. */
- BELOW_BASE_SUBSTITUTIONS("blws"),
-
- /** The "calt" tag. */
- CONTEXTUAL_ALTERNATES("calt"),
-
- /** The "case" tag. */
- CASE_SENSITIVE_FORMS("case"),
-
- /** The "ccmp" tag. */
- GLYPH_COMPOSITION_DECOMPOSITION("ccmp"),
-
- /** The "clig" tag. */
- CONTEXTUAL_LIGATURES("clig"),
-
- /** The "cpsp" tag. */
- CAPITAL_SPACING("cpsp"),
-
- /** The "cswh" tag. */
- CONTEXTUAL_SWASH("cswh"),
-
- /** The "curs" tag. */
- CURSIVE_POSITIONING("curs"),
-
- /** The "c2sc" tag. */
- SMALL_CAPITALS_FROM_CAPITALS("c2sc"),
-
- /** The "c2pc" tag. */
- PETITE_CAPITALS_FROM_CAPITALS("c2pc"),
-
- /** The "dist" tag. */
- DISTANCES("dist"),
-
- /** The "dlig" tag. */
- DISCRETIONARY_LIGATURES("dlig"),
-
- /** The "dnom" tag. */
- DENOMINATORS("dnom"),
-
- /** The "expt" tag. */
- EXPERT_FORMS("expt"),
-
- /** The "falt" tag. */
- FINAL_GLYPH_ON_LINE_ALTERNATES("falt"),
-
- /** The "fin2" tag. */
- TERMINAL_FORMS_NO_2("fin2"),
-
- /** The "fin3" tag. */
- TERMINAL_FORMS_NO_3("fin3"),
-
- /** The "fina" tag. */
- TERMINAL_FORMS("fina"),
-
- /** The "frac" tag. */
- FRACTIONS("frac"),
-
- /** The "fwid" tag. */
- FULL_WIDTHS("fwid"),
-
- /** The "half" tag. */
- HALF_FORMS("half"),
-
- /** The "haln" tag. */
- HALANT_FORMS("haln"),
-
- /** The "halt" tag. */
- ALTERNATE_HALF_WIDTHS("halt"),
-
- /** The "hist" tag. */
- HISTORICAL_FORMS("hist"),
-
- /** The "hkna" tag. */
- HORIZONTAL_KANA_ALTERNATES("hkna"),
-
- /** The "hlig" tag. */
- HISTORICAL_LIGATURES("hlig"),
-
- /** The "hngl" tag. */
- HANGUL("hngl"),
-
- /** The "hwid" tag. */
- HALF_WIDTHS("hwid"),
-
- /** The "init" tag. */
- INITIAL_FORMS("init"),
-
- /** The "isol" tag. */
- ISOLATED_FORMS("isol"),
-
- /** The "ital" tag. */
- ITALICS("ital"),
-
- /** The "jalt" tag. */
- JUSTIFICATION_ALTERNATES("jalt"),
-
- /** The "jp78" tag. */
- JIS78_FORMS("jp78"),
-
- /** The "jp83" tag. */
- JIS83_FORMS("jp83"),
-
- /** The "jp90" tag. */
- JIS90_FORMS("jp90"),
-
- /** The "kern" tag. */
- KERNING("kern"),
-
- /** The "lfbd" tag. */
- LEFT_BOUNDS("lfbd"),
-
- /** The "liga" tag. */
- STANDARD_LIGATURES("liga"),
-
- /** The "ljmo" tag. */
- LEADING_JAMO_FORMS("ljmo"),
-
- /** The "lnum" tag. */
- LINING_FIGURES("lnum"),
-
- /** The "locl" tag. */
- LOCALIZED_FORMS("locl"),
-
- /** The "mark" tag. */
- MARK_POSITIONING("mark"),
-
- /** The "med2" tag. */
- MEDIAL_FORMS_NO_2("med2"),
-
- /** The "medi" tag. */
- MEDIAL_FORMS("medi"),
-
- /** The "mgrk" tag. */
- MATHEMATICAL_GREEK("mgrk"),
-
- /** The "mkmk" tag. */
- MARK_TO_MARK_POSITIONING("mkmk"),
-
- /** The "mset" tag. */
- MARK_POSITIONING_VIA_SUBSTITUTION("mset"),
-
- /** The "nalt" tag. */
- ALTERNATE_ANNOTATION_FORMS("nalt"),
-
- /** The "nlck" tag. */
- NLC_KANJI_FORMS("nlck"),
-
- /** The "nukt" tag. */
- NUKTA_FORMS("nukt"),
-
- /** The "numr" tag. */
- NUMERATORS("numr"),
-
- /** The "onum" tag. */
- OLDSTYLE_FIGURES("onum"),
-
- /** The "opbd" tag. */
- OPTICAL_BOUNDS("opbd"),
-
- /** The "ordn" tag. */
- ORDINALS("ordn"),
-
- /** The "ornm" tag. */
- ORNAMENTS("ornm"),
-
- /** The "palt" tag. */
- PROPORTIONAL_ALTERNATE_WIDTHS("palt"),
-
- /** The "pcap" tag. */
- PETITE_CAPITALS("pcap"),
-
- /** The "pnum" tag. */
- PROPORTIONAL_FIGURES("pnum"),
-
- /** The "pref" tag. */
- PRE_BASE_FORMS("pref"),
-
- /** The "pres" tag. */
- PRE_BASE_SUBSTITUTIONS("pres"),
-
- /** The "pstf" tag. */
- POST_BASE_FORMS("pstf"),
-
- /** The "psts" tag. */
- POST_BASE_SUBSTITUTIONS("psts"),
-
- /** The "pwid" tag. */
- PROPORTIONAL_WIDTHS("pwid"),
-
- /** The "qwid" tag. */
- QUARTER_WIDTHS("qwid"),
-
- /** The "rand" tag. */
- RANDOMIZE("rand"),
-
- /** The "rlig" tag. */
- REQUIRED_LIGATURES("rlig"),
-
- /** The "rphf" tag. */
- REPH_FORMS("rphf"),
-
- /** The "rtbd" tag. */
- RIGHT_BOUNDS("rtbd"),
-
- /** The "rtla" tag. */
- RIGHT_TO_LEFT_ALTERNATES("rtla"),
-
- /** The "ruby" tag. */
- RUBY_NOTATION_FORMS("ruby"),
-
- /** The "salt" tag. */
- STYLISTIC_ALTERNATES("salt"),
-
- /** The "sinf" tag. */
- SCIENTIFIC_INFERIORS("sinf"),
-
- /** The "size" tag. */
- OPTICAL_SIZE("size"),
-
- /** The "smcp" tag. */
- SMALL_CAPITALS("smcp"),
-
- /** The "smpl" tag. */
- SIMPLIFIED_FORMS("smpl"),
-
- /** The "ss01" tag. */
- STYLISTIC_SET_1("ss01"),
-
- /** The "ss02" tag. */
- STYLISTIC_SET_2("ss02"),
-
- /** The "ss03" tag. */
- STYLISTIC_SET_3("ss03"),
-
- /** The "ss04" tag. */
- STYLISTIC_SET_4("ss04"),
-
- /** The "ss05" tag. */
- STYLISTIC_SET_5("ss05"),
-
- /** The "ss06" tag. */
- STYLISTIC_SET_6("ss06"),
-
- /** The "ss07" tag. */
- STYLISTIC_SET_7("ss07"),
-
- /** The "ss08" tag. */
- STYLISTIC_SET_8("ss08"),
-
- /** The "ss09" tag. */
- STYLISTIC_SET_9("ss09"),
-
- /** The "ss10" tag. */
- STYLISTIC_SET_10("ss10"),
-
- /** The "ss11" tag. */
- STYLISTIC_SET_11("ss11"),
-
- /** The "ss12" tag. */
- STYLISTIC_SET_12("ss12"),
-
- /** The "ss13" tag. */
- STYLISTIC_SET_13("ss13"),
-
- /** The "ss14" tag. */
- STYLISTIC_SET_14("ss14"),
-
- /** The "ss15" tag. */
- STYLISTIC_SET_15("ss15"),
-
- /** The "ss16" tag. */
- STYLISTIC_SET_16("ss16"),
-
- /** The "ss17" tag. */
- STYLISTIC_SET_17("ss17"),
-
- /** The "ss18" tag. */
- STYLISTIC_SET_18("ss18"),
-
- /** The "ss19" tag. */
- STYLISTIC_SET_19("ss19"),
-
- /** The "ss20" tag. */
- STYLISTIC_SET_20("ss20"),
-
- /** The "subs" tag. */
- SUBSCRIPT("subs"),
-
- /** The "sups" tag. */
- SUPERSCRIPT("sups"),
-
- /** The "swsh" tag. */
- SWASH("swsh"),
-
- /** The "titl" tag. */
- TITLING("titl"),
-
- /** The "tjmo" tag. */
- TRAILING_JAMO_FORMS("tjmo"),
-
- /** The "tnam" tag. */
- TRADITIONAL_NAME_FORMS("tnam"),
-
- /** The "tnum" tag. */
- TABULAR_FIGURES("tnum"),
-
- /** The "trad" tag. */
- TRADITIONAL_FORMS("trad"),
-
- /** The "twid" tag. */
- THIRD_WIDTHS("twid"),
-
- /** The "unic" tag. */
- UNICASE("unic"),
-
- /** The "valt" tag. */
- ALTERNATE_VERTICAL_METRICS("valt"),
-
- /** The "vatu" tag. */
- VATTU_VARIANTS("vatu"),
-
- /** The "vert" tag. */
- VERTICAL_WRITING("vert"),
-
- /** The "vhal" tag. */
- ALTERNATE_VERTICAL_HALF_METRICS("vhal"),
-
- /** The "vjmo" tag. */
- VOWEL_JAMO_FORMS("vjmo"),
-
- /** The "vkna" tag. */
- VERTICAL_KANA_ALTERNATES("vkna"),
-
- /** The "vkrn" tag. */
- VERTICAL_KERNING("vkrn"),
-
- /** The "vpal" tag. */
- PROPORTIONAL_ALTERNATE_VERTICAL_METRICS("vpal"),
-
- /** The "vrt2" tag. */
- VERTICAL_ALTERNATES_AND_ROTATION("vrt2"),
-
- /** The "zero" tag. */
- SLASHED_ZERO("zero");
-
- /** The text for this tag that is stored in the table. */
- private String tagText;
-
- /**
- * Constructor.
- * @param tagText The text for this tag.
- */
- OtfFeatureTag(final String tagText) {
- this.tagText = tagText;
- }
-
- /**
- * Returns the text for this tag.
- * @return The text for this tag.
- */
- public String getTagText() {
- return this.tagText;
- }
-
- }
-
/** The size, in bytes, of an OpenType Feature tag. */
public static final int TAG_SIZE = 4;
Added: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeatureTag.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeatureTag.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeatureTag.java 2025-05-01 16:51:20 UTC (rev 13558)
@@ -0,0 +1,424 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf;
+
+/**
+ * Enumeration of the various OpenType feature tags.
+ */
+public enum OtfFeatureTag {
+
+ /** The "aalt" tag. */
+ ACCESS_ALL_ALTERNATES("aalt"),
+
+ /** The "abvf" tag. */
+ ABOVE_BASE_FORMS("abvf"),
+
+ /** The "abvm" tag. */
+ ABOVE_BASE_MARK_POSITIONING("abvm"),
+
+ /** The "abvs" tag. */
+ ABOVE_BASE_SUBSTITUTIONS("abvs"),
+
+ /** The "afrc" tag. */
+ ALTERNATIVE_FRACTIONS("afrc"),
+
+ /** The "akhn" tag. */
+ AKHANDS("akhn"),
+
+ /** The "blwf" tag. */
+ BELOW_BASE_FORMS("blwf"),
+
+ /** The "blwm" tag. */
+ BELOW_BASE_MARK_POSITIONING("blwm"),
+
+ /** The "blws" tag. */
+ BELOW_BASE_SUBSTITUTIONS("blws"),
+
+ /** The "calt" tag. */
+ CONTEXTUAL_ALTERNATES("calt"),
+
+ /** The "case" tag. */
+ CASE_SENSITIVE_FORMS("case"),
+
+ /** The "ccmp" tag. */
+ GLYPH_COMPOSITION_DECOMPOSITION("ccmp"),
+
+ /** The "clig" tag. */
+ CONTEXTUAL_LIGATURES("clig"),
+
+ /** The "cpsp" tag. */
+ CAPITAL_SPACING("cpsp"),
+
+ /** The "cswh" tag. */
+ CONTEXTUAL_SWASH("cswh"),
+
+ /** The "curs" tag. */
+ CURSIVE_POSITIONING("curs"),
+
+ /** The "c2sc" tag. */
+ SMALL_CAPITALS_FROM_CAPITALS("c2sc"),
+
+ /** The "c2pc" tag. */
+ PETITE_CAPITALS_FROM_CAPITALS("c2pc"),
+
+ /** The "dist" tag. */
+ DISTANCES("dist"),
+
+ /** The "dlig" tag. */
+ DISCRETIONARY_LIGATURES("dlig"),
+
+ /** The "dnom" tag. */
+ DENOMINATORS("dnom"),
+
+ /** The "expt" tag. */
+ EXPERT_FORMS("expt"),
+
+ /** The "falt" tag. */
+ FINAL_GLYPH_ON_LINE_ALTERNATES("falt"),
+
+ /** The "fin2" tag. */
+ TERMINAL_FORMS_NO_2("fin2"),
+
+ /** The "fin3" tag. */
+ TERMINAL_FORMS_NO_3("fin3"),
+
+ /** The "fina" tag. */
+ TERMINAL_FORMS("fina"),
+
+ /** The "frac" tag. */
+ FRACTIONS("frac"),
+
+ /** The "fwid" tag. */
+ FULL_WIDTHS("fwid"),
+
+ /** The "half" tag. */
+ HALF_FORMS("half"),
+
+ /** The "haln" tag. */
+ HALANT_FORMS("haln"),
+
+ /** The "halt" tag. */
+ ALTERNATE_HALF_WIDTHS("halt"),
+
+ /** The "hist" tag. */
+ HISTORICAL_FORMS("hist"),
+
+ /** The "hkna" tag. */
+ HORIZONTAL_KANA_ALTERNATES("hkna"),
+
+ /** The "hlig" tag. */
+ HISTORICAL_LIGATURES("hlig"),
+
+ /** The "hngl" tag. */
+ HANGUL("hngl"),
+
+ /** The "hwid" tag. */
+ HALF_WIDTHS("hwid"),
+
+ /** The "init" tag. */
+ INITIAL_FORMS("init"),
+
+ /** The "isol" tag. */
+ ISOLATED_FORMS("isol"),
+
+ /** The "ital" tag. */
+ ITALICS("ital"),
+
+ /** The "jalt" tag. */
+ JUSTIFICATION_ALTERNATES("jalt"),
+
+ /** The "jp78" tag. */
+ JIS78_FORMS("jp78"),
+
+ /** The "jp83" tag. */
+ JIS83_FORMS("jp83"),
+
+ /** The "jp90" tag. */
+ JIS90_FORMS("jp90"),
+
+ /** The "kern" tag. */
+ KERNING("kern"),
+
+ /** The "lfbd" tag. */
+ LEFT_BOUNDS("lfbd"),
+
+ /** The "liga" tag. */
+ STANDARD_LIGATURES("liga"),
+
+ /** The "ljmo" tag. */
+ LEADING_JAMO_FORMS("ljmo"),
+
+ /** The "lnum" tag. */
+ LINING_FIGURES("lnum"),
+
+ /** The "locl" tag. */
+ LOCALIZED_FORMS("locl"),
+
+ /** The "mark" tag. */
+ MARK_POSITIONING("mark"),
+
+ /** The "med2" tag. */
+ MEDIAL_FORMS_NO_2("med2"),
+
+ /** The "medi" tag. */
+ MEDIAL_FORMS("medi"),
+
+ /** The "mgrk" tag. */
+ MATHEMATICAL_GREEK("mgrk"),
+
+ /** The "mkmk" tag. */
+ MARK_TO_MARK_POSITIONING("mkmk"),
+
+ /** The "mset" tag. */
+ MARK_POSITIONING_VIA_SUBSTITUTION("mset"),
+
+ /** The "nalt" tag. */
+ ALTERNATE_ANNOTATION_FORMS("nalt"),
+
+ /** The "nlck" tag. */
+ NLC_KANJI_FORMS("nlck"),
+
+ /** The "nukt" tag. */
+ NUKTA_FORMS("nukt"),
+
+ /** The "numr" tag. */
+ NUMERATORS("numr"),
+
+ /** The "onum" tag. */
+ OLDSTYLE_FIGURES("onum"),
+
+ /** The "opbd" tag. */
+ OPTICAL_BOUNDS("opbd"),
+
+ /** The "ordn" tag. */
+ ORDINALS("ordn"),
+
+ /** The "ornm" tag. */
+ ORNAMENTS("ornm"),
+
+ /** The "palt" tag. */
+ PROPORTIONAL_ALTERNATE_WIDTHS("palt"),
+
+ /** The "pcap" tag. */
+ PETITE_CAPITALS("pcap"),
+
+ /** The "pnum" tag. */
+ PROPORTIONAL_FIGURES("pnum"),
+
+ /** The "pref" tag. */
+ PRE_BASE_FORMS("pref"),
+
+ /** The "pres" tag. */
+ PRE_BASE_SUBSTITUTIONS("pres"),
+
+ /** The "pstf" tag. */
+ POST_BASE_FORMS("pstf"),
+
+ /** The "psts" tag. */
+ POST_BASE_SUBSTITUTIONS("psts"),
+
+ /** The "pwid" tag. */
+ PROPORTIONAL_WIDTHS("pwid"),
+
+ /** The "qwid" tag. */
+ QUARTER_WIDTHS("qwid"),
+
+ /** The "rand" tag. */
+ RANDOMIZE("rand"),
+
+ /** The "rlig" tag. */
+ REQUIRED_LIGATURES("rlig"),
+
+ /** The "rphf" tag. */
+ REPH_FORMS("rphf"),
+
+ /** The "rtbd" tag. */
+ RIGHT_BOUNDS("rtbd"),
+
+ /** The "rtla" tag. */
+ RIGHT_TO_LEFT_ALTERNATES("rtla"),
+
+ /** The "ruby" tag. */
+ RUBY_NOTATION_FORMS("ruby"),
+
+ /** The "salt" tag. */
+ STYLISTIC_ALTERNATES("salt"),
+
+ /** The "sinf" tag. */
+ SCIENTIFIC_INFERIORS("sinf"),
+
+ /** The "size" tag. */
+ OPTICAL_SIZE("size"),
+
+ /** The "smcp" tag. */
+ SMALL_CAPITALS("smcp"),
+
+ /** The "smpl" tag. */
+ SIMPLIFIED_FORMS("smpl"),
+
+ /** The "ss01" tag. */
+ STYLISTIC_SET_1("ss01"),
+
+ /** The "ss02" tag. */
+ STYLISTIC_SET_2("ss02"),
+
+ /** The "ss03" tag. */
+ STYLISTIC_SET_3("ss03"),
+
+ /** The "ss04" tag. */
+ STYLISTIC_SET_4("ss04"),
+
+ /** The "ss05" tag. */
+ STYLISTIC_SET_5("ss05"),
+
+ /** The "ss06" tag. */
+ STYLISTIC_SET_6("ss06"),
+
+ /** The "ss07" tag. */
+ STYLISTIC_SET_7("ss07"),
+
+ /** The "ss08" tag. */
+ STYLISTIC_SET_8("ss08"),
+
+ /** The "ss09" tag. */
+ STYLISTIC_SET_9("ss09"),
+
+ /** The "ss10" tag. */
+ STYLISTIC_SET_10("ss10"),
+
+ /** The "ss11" tag. */
+ STYLISTIC_SET_11("ss11"),
+
+ /** The "ss12" tag. */
+ STYLISTIC_SET_12("ss12"),
+
+ /** The "ss13" tag. */
+ STYLISTIC_SET_13("ss13"),
+
+ /** The "ss14" tag. */
+ STYLISTIC_SET_14("ss14"),
+
+ /** The "ss15" tag. */
+ STYLISTIC_SET_15("ss15"),
+
+ /** The "ss16" tag. */
+ STYLISTIC_SET_16("ss16"),
+
+ /** The "ss17" tag. */
+ STYLISTIC_SET_17("ss17"),
+
+ /** The "ss18" tag. */
+ STYLISTIC_SET_18("ss18"),
+
+ /** The "ss19" tag. */
+ STYLISTIC_SET_19("ss19"),
+
+ /** The "ss20" tag. */
+ STYLISTIC_SET_20("ss20"),
+
+ /** The "subs" tag. */
+ SUBSCRIPT("subs"),
+
+ /** The "sups" tag. */
+ SUPERSCRIPT("sups"),
+
+ /** The "swsh" tag. */
+ SWASH("swsh"),
+
+ /** The "titl" tag. */
+ TITLING("titl"),
+
+ /** The "tjmo" tag. */
+ TRAILING_JAMO_FORMS("tjmo"),
+
+ /** The "tnam" tag. */
+ TRADITIONAL_NAME_FORMS("tnam"),
+
+ /** The "tnum" tag. */
+ TABULAR_FIGURES("tnum"),
+
+ /** The "trad" tag. */
+ TRADITIONAL_FORMS("trad"),
+
+ /** The "twid" tag. */
+ THIRD_WIDTHS("twid"),
+
+ /** The "unic" tag. */
+ UNICASE("unic"),
+
+ /** The "valt" tag. */
+ ALTERNATE_VERTICAL_METRICS("valt"),
+
+ /** The "vatu" tag. */
+ VATTU_VARIANTS("vatu"),
+
+ /** The "vert" tag. */
+ VERTICAL_WRITING("vert"),
+
+ /** The "vhal" tag. */
+ ALTERNATE_VERTICAL_HALF_METRICS("vhal"),
+
+ /** The "vjmo" tag. */
+ VOWEL_JAMO_FORMS("vjmo"),
+
+ /** The "vkna" tag. */
+ VERTICAL_KANA_ALTERNATES("vkna"),
+
+ /** The "vkrn" tag. */
+ VERTICAL_KERNING("vkrn"),
+
+ /** The "vpal" tag. */
+ PROPORTIONAL_ALTERNATE_VERTICAL_METRICS("vpal"),
+
+ /** The "vrt2" tag. */
+ VERTICAL_ALTERNATES_AND_ROTATION("vrt2"),
+
+ /** The "zero" tag. */
+ SLASHED_ZERO("zero");
+
+ /** The text for this tag that is stored in the table. */
+ private String tagText;
+
+ /**
+ * Constructor.
+ * @param tagText The text for this tag.
+ */
+ OtfFeatureTag(final String tagText) {
+ this.tagText = tagText;
+ }
+
+ /**
+ * Returns the text for this tag.
+ * @return The text for this tag.
+ */
+ public String getTagText() {
+ return this.tagText;
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfFeatureTag.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 16:23:33
|
Revision: 13557
http://sourceforge.net/p/foray/code/13557
Author: victormote
Date: 2025-05-01 16:23:16 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Convert ScriptList tables to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 16:00:08 UTC (rev 13556)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 16:23:16 UTC (rev 13557)
@@ -30,11 +30,7 @@
import org.foray.common.RandomAccessInput;
import org.foray.font.ttf.OtfFeature;
-import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
-import org.foray.fontParse.ttf.ScriptTableParser;
-import org.foray.fontParse.ttf.TtfRandomAccessInput;
-import org.foray.fontParse.ttfHandler.ScriptTableHandler;
import java.io.IOException;
import java.util.HashMap;
@@ -45,9 +41,8 @@
*/
public abstract class AbstractOtfLayoutTable extends RoTable {
- /** Map of OpenType scripts for this table. The key is the script tag, and the value is the OtfScript instance for
- * that tag. */
- private Map<String, ScriptTable> scriptMap;
+ /** List of OpenType scripts for this table. */
+ private ScriptListTable scriptList;
/** Map of OpenType features for this table. The key is the feature tag, and the value is the OtfFeature instance
* for that tag. */
@@ -55,44 +50,15 @@
/**
* Constructor.
- * @param scriptMap The script map for this table.
+ * @param scriptList The script list for this table.
* @param featureMap The feature map for this table.
*/
- AbstractOtfLayoutTable(final Map<String, ScriptTable> scriptMap, final Map<String, OtfFeature> featureMap) {
- this.scriptMap = scriptMap;
+ AbstractOtfLayoutTable(final ScriptListTable scriptList, final Map<String, OtfFeature> featureMap) {
+ this.scriptList = scriptList;
this.featureMap = featureMap;
}
/**
- * Parses the script list.
- * @param raInput The input from which the script list is being parsed.
- * @param offset The offset in {@code raInput} for the start of the script list.
- * @return The parsed map of scripts.
- * @throws IOException For I/O errors during parsing.
- */
- protected static Map<String, ScriptTable> parseScriptList(final TtfRandomAccessInput raInput, final int offset)
- throws IOException {
- raInput.seek(offset);
- final int scriptCount = raInput.readUnsignedShort();
- final String[] scriptTableTags = new String[scriptCount];
- final int[] scriptTableOffsets = new int[scriptCount];
- for (int index = 0; index < scriptCount; index ++) {
- scriptTableTags[index] = raInput.readStringASCII(ScriptTable.TAG_SIZE);
- scriptTableOffsets[index] = raInput.readUnsignedShort();
- }
-
- final Map<String, ScriptTable> scriptMap = new HashMap<String, ScriptTable>();
- for (int index = 0; index < scriptCount; index ++) {
- final ParserKit<ScriptTable, ScriptTableHandler> kit = ScriptTable.createContentHandler();
- final ScriptTableParser parser = new ScriptTableParser();
- parser.parse(raInput, offset + scriptTableOffsets[index], kit.getHandler());
- final ScriptTable script = kit.getTable();
- scriptMap.put(scriptTableTags[index], script);
- }
- return scriptMap;
- }
-
- /**
* Parses the feature list.
* @param raInput The input from which the feature list is being parsed.
* @param offset The offset in {@code raInput} for the start of the feature list.
@@ -135,10 +101,10 @@
* @return The script instance referenced by {@code scriptTag}, or null if that reference does not exist.
*/
public ScriptTable getScript(final String scriptTag) {
- if (this.scriptMap == null) {
+ if (this.scriptList == null) {
return null;
}
- return this.scriptMap.get(scriptTag);
+ return this.scriptList.get(scriptTag);
}
/**
@@ -155,10 +121,10 @@
/**
* Package-visible method for testing.
- * @return The script map.
+ * @return The script list.
*/
- Map<String, ScriptTable> getScriptMap() {
- return this.scriptMap;
+ ScriptListTable getScriptList() {
+ return this.scriptList;
}
/**
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 16:00:08 UTC (rev 13556)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 16:23:16 UTC (rev 13557)
@@ -31,8 +31,10 @@
import org.foray.font.ttf.OtfFeature;
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.TtfOffsetTableRecord;
+import org.foray.fontParse.ttf.ScriptListTableParser;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
import org.foray.fontParse.ttfHandler.GsubTableHandler;
+import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
import org.foray.primitive.sequence.IntArrayBuilder;
import org.axsl.font.FontContext;
@@ -83,7 +85,7 @@
* @param scriptMap The scripts for this table.
* @param featureMap The features for this table.
*/
- public GsubTable(final Map<String, ScriptTable> scriptMap, final Map<String, OtfFeature> featureMap) {
+ public GsubTable(final ScriptListTable scriptMap, final Map<String, OtfFeature> featureMap) {
super(scriptMap, featureMap);
}
@@ -120,12 +122,15 @@
featureVariationsOffset = -1;
}
- final Map<String, ScriptTable> scriptMap =
- parseScriptList(raInput, offsetRecord.getOffset() + scriptListOffset);
+ final ParserKit<ScriptListTable, ScriptListTableHandler> kit = ScriptListTable.createContentHandler();
+ final ScriptListTableParser parser = new ScriptListTableParser();
+ parser.parse(raInput, offsetRecord.getOffset() + scriptListOffset, kit.getHandler());
+ final ScriptListTable scriptListTable = kit.getTable();
+
final Map<String, OtfFeature> featureMap =
parseFeatureList(raInput, offsetRecord.getOffset() + featureListOffset);
- final GsubTable table = new GsubTable(scriptMap, featureMap);
+ final GsubTable table = new GsubTable(scriptListTable, featureMap);
table.lookupList = parseLookupList(raInput, offsetRecord.getOffset() + lookupListOffset);
parseFeatureVariations(raInput, offsetRecord.getOffset() + featureVariationsOffset);
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java 2025-05-01 16:00:08 UTC (rev 13556)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java 2025-05-01 16:23:16 UTC (rev 13557)
@@ -35,6 +35,8 @@
import org.checkerframework.checker.signedness.qual.Unsigned;
+import java.util.Arrays;
+
/**
* Class representing a TTF "ScriptList" table.
*/
@@ -73,7 +75,6 @@
@Override
public ScriptTableHandler startScriptTable() {
- this.currentScriptIndex ++;
final ParserKit<ScriptTable, ScriptTableHandler> kit = ScriptTable.createContentHandler();
this.table.scripts[this.currentScriptIndex] = kit.getTable();
return kit.getHandler();
@@ -104,4 +105,22 @@
return new ParserKit<ScriptListTable, ScriptListTableHandler>(table, handler);
}
+ /**
+ * Returns the script for a given script tag.
+ * @param scriptTag The The tag for which a script should be returned.
+ * @return The script for {@code scriptTag}, or null if not found.
+ */
+ public ScriptTable get(final String scriptTag) {
+ final int index = Arrays.binarySearch(this.scriptTags, scriptTag);
+ return index >= 0 ? this.scripts[index] : null;
+ }
+
+ /**
+ * Returns the number of scripts in this script list.
+ * @return The number of scripts in this script list.
+ */
+ public int getQtyScripts() {
+ return this.scriptTags.length;
+ }
+
}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 16:00:08 UTC (rev 13556)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 16:23:16 UTC (rev 13557)
@@ -100,9 +100,9 @@
assertNotNull(gsub);
/* Tests of the scripts. */
- final Map<String, ScriptTable> scriptMap = gsub.getScriptMap();
- assertNotNull(scriptMap);
- assertEquals(4, scriptMap.size());
+ final ScriptListTable scriptList = gsub.getScriptList();
+ assertNotNull(scriptList);
+ assertEquals(4, scriptList.getQtyScripts());
assertNotNull(gsub.getScript("grek"));
assertNotNull(gsub.getScript("hebr"));
assertNotNull(gsub.getScript("ital"));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 16:00:42
|
Revision: 13556
http://sourceforge.net/p/foray/code/13556
Author: victormote
Date: 2025-05-01 16:00:08 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Add infrastructure for ScriptList to be parsed in new scheme.
Modified Paths:
--------------
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/MaxpTableParser.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptListTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptListTableHandler.java
Added: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java 2025-05-01 16:00:08 UTC (rev 13556)
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
+import org.foray.fontParse.ttfHandler.ScriptTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+/**
+ * Class representing a TTF "ScriptList" table.
+ */
+public class ScriptListTable extends RoTable {
+
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements ScriptListTableHandler {
+
+ /** The table instance being created. */
+ private ScriptListTable table;
+
+ /** Index to the current script being parsed. */
+ private int currentScriptIndex = -1;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final ScriptListTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public void scriptCount(final @Unsigned short value) {
+ this.table.scriptTags = new String[value];
+ this.table.scripts = new ScriptTable[value];
+ }
+
+ @Override
+ public void scriptTag(final String value) {
+ this.currentScriptIndex ++;
+ this.table.scriptTags[this.currentScriptIndex] = value;
+ }
+
+ @Override
+ public ScriptTableHandler startScriptTable() {
+ this.currentScriptIndex ++;
+ final ParserKit<ScriptTable, ScriptTableHandler> kit = ScriptTable.createContentHandler();
+ this.table.scripts[this.currentScriptIndex] = kit.getTable();
+ return kit.getHandler();
+ }
+ }
+
+
+
+
+
+
+
+
+ /** The script tags in this script list. Parallel to {@link #scripts}. */
+ private String[] scriptTags;
+
+ /** The scripts in this script list. Parallel to {@link #scriptTags}. */
+ private ScriptTable[] scripts;
+
+
+ /**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<ScriptListTable, ScriptListTableHandler> createContentHandler() {
+ final ScriptListTable table = new ScriptListTable();
+ final ScriptListTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<ScriptListTable, ScriptListTableHandler>(table, handler);
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptListTable.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/MaxpTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/MaxpTableParser.java 2025-05-01 14:40:29 UTC (rev 13555)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/MaxpTableParser.java 2025-05-01 16:00:08 UTC (rev 13556)
@@ -36,7 +36,7 @@
import java.io.IOException;
/**
- * Parses a TTF OS/2 table.
+ * Parses a TTF "maxp" table.
*/
public class MaxpTableParser extends TableParser<MaxpTableHandler> {
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptListTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptListTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptListTableParser.java 2025-05-01 16:00:08 UTC (rev 13556)
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.ScriptListTableHandler;
+import org.foray.fontParse.ttfHandler.ScriptTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "ScriptList" table.
+ */
+public class ScriptListTableParser extends TableParser<ScriptListTableHandler> {
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final ScriptListTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ final @Unsigned short scriptCount = input.read_uint16(); // 2 bytes, total 2
+ handler.scriptCount(scriptCount);
+
+ for (int index = 0; index < Short.toUnsignedInt(scriptCount); index ++) {
+ handler.scriptTag(input.read_Tag()); // 4 bytes @
+ final short scriptOffset = input.read_Offset16(); // 2 bytes @
+
+ final long bookmark = input.getOffset();
+
+ final ScriptTableHandler scriptHandler = handler.startScriptTable();
+ final ScriptTableParser parser = new ScriptTableParser();
+ parser.parse(input, offset + scriptOffset, scriptHandler);
+
+ input.seek(bookmark);
+ }
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptListTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptListTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptListTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptListTableHandler.java 2025-05-01 16:00:08 UTC (rev 13556)
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.ScriptListTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link ScriptListTableParser}.
+ */
+public interface ScriptListTableHandler extends FontContentHandler {
+
+ default void scriptCount(short value) { return; }
+
+ default void scriptTag(String value) { return; }
+ default void scriptOffset(short value) { return; }
+ default ScriptTableHandler startScriptTable() { return null; }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptListTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 14:40:50
|
Revision: 13555
http://sourceforge.net/p/foray/code/13555
Author: victormote
Date: 2025-05-01 14:40:29 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Move OtfScript to table package and rename it ScriptTable, to match OTF doc. Convert it to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptTableHandler.java
Removed Paths:
-------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java
Deleted: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java 2025-05-01 13:03:45 UTC (rev 13554)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -1,120 +0,0 @@
-/*
- * Copyright 2016 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font.ttf;
-
-import org.foray.font.ttf.table.LangSysTable;
-import org.foray.fontParse.ttf.LangSysTableParser;
-import org.foray.fontParse.ttf.TtfRandomAccessInput;
-import org.foray.fontParse.ttfHandler.LangSysTableHandler;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * An OpenType Script.
- */
-public class OtfScript {
-
- /** The size, in bytes, of an OpenType Script tag. */
- public static final byte TAG_SIZE = 4;
-
- /** The (optional) default language system. */
- private LangSysTable defaultLanguageSystem;
-
- /** Map of the other (non-default) language systems. */
- private Map<String, LangSysTable> languageSystems = new HashMap<String, LangSysTable>();
-
- /**
- * Constructor.
- */
- public OtfScript() {
- }
-
- /**
- * Parses a script.
- * @param raInput The input from which the script is being parsed.
- * @param offset The offset in {@code raInput} for the start of the script.
- * @return The parsed script instance.
- * @throws IOException For I/O errors during parsing.
- */
- public static OtfScript parse(final TtfRandomAccessInput raInput, final int offset) throws IOException {
- raInput.seek(offset);
- final OtfScript script = new OtfScript();
- final int offsetToDefaultLangSys = raInput.readUnsignedShort();
- final int langSysCount = raInput.readUnsignedShort();
- final String[] langSysTags = new String[langSysCount];
- final int[] langSysOffsets = new int[langSysCount];
- for (int index = 0; index < langSysCount; index ++) {
- langSysTags[index] = raInput.readStringASCII(TAG_SIZE);
- langSysOffsets[index] = raInput.readUnsignedShort();
- }
-
- if (offsetToDefaultLangSys > 0) {
- final ParserKit<LangSysTable, LangSysTableHandler> kit = LangSysTable.createContentHandler();
- final LangSysTableParser parser = new LangSysTableParser();
- parser.parse(raInput, offset + offsetToDefaultLangSys, kit.getHandler());
- script.defaultLanguageSystem = kit.getTable();
- }
- for (int index = 0; index < langSysCount; index ++) {
- final ParserKit<LangSysTable, LangSysTableHandler> kit = LangSysTable.createContentHandler();
- final LangSysTableParser parser = new LangSysTableParser();
- parser.parse(raInput, offset + langSysOffsets[index], kit.getHandler());
- script.languageSystems.put(langSysTags[index], kit.getTable());
- }
-
- return script;
- }
-
- /**
- * Returns the default language system for this script.
- * @return The default language system.
- */
- public LangSysTable getDefaultLanguageSystem() {
- return this.defaultLanguageSystem;
- }
-
- /**
- * Returns the language system for a given tag.
- * @param languageSystemTag The language system tag to be retrieved.
- * @return The language system for {@code languageSystemTag}, or null if that tag is not in this script.
- */
- public LangSysTable getNamedLanguageSystem(final String languageSystemTag) {
- return this.languageSystems.get(languageSystemTag);
- }
-
- /**
- * Returns the number of language systems in this script.
- * @return The number of language systems in this script.
- */
- public int getQtyLanguageSystems() {
- return this.languageSystems.size();
- }
-
-}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 13:03:45 UTC (rev 13554)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -30,9 +30,11 @@
import org.foray.common.RandomAccessInput;
import org.foray.font.ttf.OtfFeature;
-import org.foray.font.ttf.OtfScript;
+import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttf.ScriptTableParser;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
+import org.foray.fontParse.ttfHandler.ScriptTableHandler;
import java.io.IOException;
import java.util.HashMap;
@@ -45,7 +47,7 @@
/** Map of OpenType scripts for this table. The key is the script tag, and the value is the OtfScript instance for
* that tag. */
- private Map<String, OtfScript> scriptMap;
+ private Map<String, ScriptTable> scriptMap;
/** Map of OpenType features for this table. The key is the feature tag, and the value is the OtfFeature instance
* for that tag. */
@@ -56,7 +58,7 @@
* @param scriptMap The script map for this table.
* @param featureMap The feature map for this table.
*/
- AbstractOtfLayoutTable(final Map<String, OtfScript> scriptMap, final Map<String, OtfFeature> featureMap) {
+ AbstractOtfLayoutTable(final Map<String, ScriptTable> scriptMap, final Map<String, OtfFeature> featureMap) {
this.scriptMap = scriptMap;
this.featureMap = featureMap;
}
@@ -68,7 +70,7 @@
* @return The parsed map of scripts.
* @throws IOException For I/O errors during parsing.
*/
- protected static Map<String, OtfScript> parseScriptList(final TtfRandomAccessInput raInput, final int offset)
+ protected static Map<String, ScriptTable> parseScriptList(final TtfRandomAccessInput raInput, final int offset)
throws IOException {
raInput.seek(offset);
final int scriptCount = raInput.readUnsignedShort();
@@ -75,13 +77,16 @@
final String[] scriptTableTags = new String[scriptCount];
final int[] scriptTableOffsets = new int[scriptCount];
for (int index = 0; index < scriptCount; index ++) {
- scriptTableTags[index] = raInput.readStringASCII(OtfScript.TAG_SIZE);
+ scriptTableTags[index] = raInput.readStringASCII(ScriptTable.TAG_SIZE);
scriptTableOffsets[index] = raInput.readUnsignedShort();
}
- final Map<String, OtfScript> scriptMap = new HashMap<String, OtfScript>();
+ final Map<String, ScriptTable> scriptMap = new HashMap<String, ScriptTable>();
for (int index = 0; index < scriptCount; index ++) {
- final OtfScript script = OtfScript.parse(raInput, offset + scriptTableOffsets[index]);
+ final ParserKit<ScriptTable, ScriptTableHandler> kit = ScriptTable.createContentHandler();
+ final ScriptTableParser parser = new ScriptTableParser();
+ parser.parse(raInput, offset + scriptTableOffsets[index], kit.getHandler());
+ final ScriptTable script = kit.getTable();
scriptMap.put(scriptTableTags[index], script);
}
return scriptMap;
@@ -129,7 +134,7 @@
* @param scriptTag The script tag to be retrieved.
* @return The script instance referenced by {@code scriptTag}, or null if that reference does not exist.
*/
- public OtfScript getScript(final String scriptTag) {
+ public ScriptTable getScript(final String scriptTag) {
if (this.scriptMap == null) {
return null;
}
@@ -152,7 +157,7 @@
* Package-visible method for testing.
* @return The script map.
*/
- Map<String, OtfScript> getScriptMap() {
+ Map<String, ScriptTable> getScriptMap() {
return this.scriptMap;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 13:03:45 UTC (rev 13554)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/GsubTable.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -29,7 +29,6 @@
package org.foray.font.ttf.table;
import org.foray.font.ttf.OtfFeature;
-import org.foray.font.ttf.OtfScript;
import org.foray.font.ttf.ParserKit;
import org.foray.font.ttf.TtfOffsetTableRecord;
import org.foray.fontParse.ttf.TtfRandomAccessInput;
@@ -84,7 +83,7 @@
* @param scriptMap The scripts for this table.
* @param featureMap The features for this table.
*/
- public GsubTable(final Map<String, OtfScript> scriptMap, final Map<String, OtfFeature> featureMap) {
+ public GsubTable(final Map<String, ScriptTable> scriptMap, final Map<String, OtfFeature> featureMap) {
super(scriptMap, featureMap);
}
@@ -121,7 +120,8 @@
featureVariationsOffset = -1;
}
- final Map<String, OtfScript> scriptMap = parseScriptList(raInput, offsetRecord.getOffset() + scriptListOffset);
+ final Map<String, ScriptTable> scriptMap =
+ parseScriptList(raInput, offsetRecord.getOffset() + scriptListOffset);
final Map<String, OtfFeature> featureMap =
parseFeatureList(raInput, offsetRecord.getOffset() + featureListOffset);
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java 2025-05-01 13:03:45 UTC (rev 13554)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -43,7 +43,6 @@
private final class ContentHandler implements LangSysTableHandler {
/** The table instance being created. */
- @SuppressWarnings("unused")
private LangSysTable table;
/**
Copied: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptTable.java (from rev 13554, trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java)
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/ScriptTable.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2016 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.LangSysTableHandler;
+import org.foray.fontParse.ttfHandler.ScriptTableHandler;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * An OpenType Script.
+ */
+public class ScriptTable extends RoTable {
+
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements ScriptTableHandler {
+
+ /** The table instance being created. */
+ private ScriptTable table;
+
+ /** The LangSys tag that is currently being parsed. */
+ private String currentLangSysTag;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final ScriptTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public LangSysTableHandler startDefaultLangSysTable() {
+ final ParserKit<LangSysTable, LangSysTableHandler> kit = LangSysTable.createContentHandler();
+ this.table.defaultLanguageSystem = kit.getTable();
+ return kit.getHandler();
+ }
+
+ @Override
+ public void langSysTag(final String value) {
+ this.currentLangSysTag = value;
+ }
+
+ @Override
+ public LangSysTableHandler startLangSysTable() {
+ final ParserKit<LangSysTable, LangSysTableHandler> kit = LangSysTable.createContentHandler();
+ this.table.languageSystems.put(this.currentLangSysTag, kit.getTable());
+ return kit.getHandler();
+ }
+
+ }
+
+
+
+
+
+
+
+
+
+
+ /** The size, in bytes, of an OpenType Script tag. */
+ public static final byte TAG_SIZE = 4;
+
+ /** The (optional) default language system. */
+ private LangSysTable defaultLanguageSystem;
+
+ /** Map of the other (non-default) language systems. */
+ private Map<String, LangSysTable> languageSystems = new HashMap<String, LangSysTable>();
+
+ /**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<ScriptTable, ScriptTableHandler> createContentHandler() {
+ final ScriptTable table = new ScriptTable();
+ final ScriptTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<ScriptTable, ScriptTableHandler>(table, handler);
+ }
+
+ /**
+ * Returns the default language system for this script.
+ * @return The default language system.
+ */
+ public LangSysTable getDefaultLanguageSystem() {
+ return this.defaultLanguageSystem;
+ }
+
+ /**
+ * Returns the language system for a given tag.
+ * @param languageSystemTag The language system tag to be retrieved.
+ * @return The language system for {@code languageSystemTag}, or null if that tag is not in this script.
+ */
+ public LangSysTable getNamedLanguageSystem(final String languageSystemTag) {
+ return this.languageSystems.get(languageSystemTag);
+ }
+
+ /**
+ * Returns the number of language systems in this script.
+ * @return The number of language systems in this script.
+ */
+ public int getQtyLanguageSystems() {
+ return this.languageSystems.size();
+ }
+
+}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 13:03:45 UTC (rev 13554)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -33,7 +33,6 @@
import org.foray.font.format.FontContent;
import org.foray.font.format.FontParser;
import org.foray.font.ttf.OtfFeature;
-import org.foray.font.ttf.OtfScript;
import org.foray.font.ttf.TrueTypeFont;
import org.foray.font.ttf.TrueTypeSingle;
import org.foray.font.ttf.table.GsubLookup04x01.Ligature;
@@ -101,13 +100,13 @@
assertNotNull(gsub);
/* Tests of the scripts. */
- final Map<String, OtfScript> scriptMap = gsub.getScriptMap();
+ final Map<String, ScriptTable> scriptMap = gsub.getScriptMap();
assertNotNull(scriptMap);
assertEquals(4, scriptMap.size());
assertNotNull(gsub.getScript("grek"));
assertNotNull(gsub.getScript("hebr"));
assertNotNull(gsub.getScript("ital"));
- final OtfScript latinScript = gsub.getScript("latn");
+ final ScriptTable latinScript = gsub.getScript("latn");
assertNotNull(latinScript);
final LangSysTable defaultLatinLanguageSystem = latinScript.getDefaultLanguageSystem();
assertNotNull(defaultLatinLanguageSystem);
Modified: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java 2025-05-01 13:03:45 UTC (rev 13554)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -49,7 +49,7 @@
handler.requiredFeatureIndex(input.read_uint16());
final @Unsigned short featureIndexCount = input.read_uint16();
- final @Unsigned short[] featureIndexes = new @Unsigned short[featureIndexCount];
+ final @Unsigned short[] featureIndexes = new @Unsigned short[Short.toUnsignedInt(featureIndexCount)];
for (int index = 0; index < featureIndexCount; index ++) {
final @Unsigned short featureIndex = input.read_uint16();
handler.featureIndex(featureIndex);
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptTableParser.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.LangSysTableHandler;
+import org.foray.fontParse.ttfHandler.ScriptTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "Script" table.
+ */
+public class ScriptTableParser extends TableParser<ScriptTableHandler> {
+
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final ScriptTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ /* Read the whole table first. */
+ final @Unsigned short defaultLangSysOffset = input.read_Offset16(); // 2 bytes, total 2
+ handler.defaultLangSysOffset(defaultLangSysOffset);
+ final @Unsigned short langSysCount = input.read_uint16(); // 2 bytes, total 4
+ handler.langSysCount(langSysCount);
+
+ final String[] langSysTagArray = new String[langSysCount];
+ final @Unsigned short[] langSysOffsetArray = new @Unsigned short[langSysCount];
+ for (int index = 0; index < langSysCount; index ++) {
+ langSysTagArray[index] = input.read_Tag(); // 4 bytes @
+ langSysOffsetArray[index] = input.read_Offset16(); // 2 bytes @
+ }
+
+ /* Read the default LangSys table. */
+ if (defaultLangSysOffset != 0) {
+ final LangSysTableHandler langSysHandler = handler.startDefaultLangSysTable();
+ final LangSysTableParser langSysParser = new LangSysTableParser();
+ final int absoluteDefaultLangSysOffset = offset + Short.toUnsignedInt(defaultLangSysOffset);
+ langSysParser.parse(input, absoluteDefaultLangSysOffset, langSysHandler);
+ }
+
+ /* Read the other LangSys tables. */
+ for (int index = 0; index < langSysCount; index ++) {
+ handler.langSysTag(langSysTagArray[index]);
+ final LangSysTableHandler langSysHandler = handler.startLangSysTable();
+ final LangSysTableParser langSysParser = new LangSysTableParser();
+ final int absoluteLangSysOffset = offset + Short.toUnsignedInt(langSysOffsetArray[index]);
+ langSysParser.parse(input, absoluteLangSysOffset, langSysHandler);
+ }
+
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/ScriptTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptTableHandler.java 2025-05-01 14:40:29 UTC (rev 13555)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.ScriptTableParser;
+
+/**
+ * Implementations catch and handle the output from {@link ScriptTableParser}.
+ */
+public interface ScriptTableHandler extends FontContentHandler {
+
+ default void defaultLangSysOffset(short value) { return; }
+ default void langSysCount(short value) { return; }
+
+ default void langSysTag(String value) { return; }
+ default void langSysOffset(short value) { return; }
+
+ default LangSysTableHandler startDefaultLangSysTable() { return null; }
+ default LangSysTableHandler startLangSysTable() { return null; }
+
+ /* TODO: Complete this. */
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/ScriptTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-01 13:04:03
|
Revision: 13554
http://sourceforge.net/p/foray/code/13554
Author: victormote
Date: 2025-05-01 13:03:45 +0000 (Thu, 01 May 2025)
Log Message:
-----------
Move OtfLanguageSystem to table package and rename it LangSysTable, to match OTF doc. Convert it to new parsing scheme.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java
trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LangSysTableHandler.java
Removed Paths:
-------------
trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfLanguageSystem.java
Deleted: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfLanguageSystem.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfLanguageSystem.java 2025-05-01 12:24:24 UTC (rev 13553)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfLanguageSystem.java 2025-05-01 13:03:45 UTC (rev 13554)
@@ -1,93 +0,0 @@
-/*
- * Copyright 2016 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.font.ttf;
-
-import org.foray.common.RandomAccessInput;
-
-import java.io.IOException;
-
-/**
- * An OpenType Language System.
- */
-public class OtfLanguageSystem {
-
- /** The size, in bytes, of an OpenType Language System tag. */
- public static final byte TAG_SIZE = 4;
-
- /** Index of a required feature in this language system. If null, the value is 0xFFFF. */
- private char reqFeatureIndex;
-
- /** The (arbitarily ordered) array of indexes into the features list. */
- private char[] featureIndexes;
-
- /**
- * Constructor.
- */
- public OtfLanguageSystem() {
- }
-
- /**
- * Parses a language system.
- * @param raInput The input from which the language system is being parsed.
- * @param offset The offset in {@code raInput} for the start of the language system.
- * @return The parsed language system instance.
- * @throws IOException For I/O errors during parsing.
- */
- public static OtfLanguageSystem parse(final RandomAccessInput raInput, final int offset)
- throws IOException {
- raInput.seek(offset);
- final OtfLanguageSystem langSys = new OtfLanguageSystem();
- /* Skip the LookupOrder. */
- raInput.skipBytes(RoTable.OFFSET_BYTES);
- langSys.reqFeatureIndex = raInput.readChar();
- final int featureCount = raInput.readUnsignedShort();
- langSys.featureIndexes = new char[featureCount];
- for (int index = 0; index < featureCount; index ++) {
- langSys.featureIndexes[index] = raInput.readChar();
- }
- return langSys;
- }
-
- /**
- * Returns the index of a required feature in this language system. If null, the value is 0xFFFF.
- * @return The index of a required feature, or 0xFFFF if null.
- */
- public char getRequiredFeatureIndex() {
- return this.reqFeatureIndex;
- }
-
- /**
- * Returns the (arbitarily ordered) array of indexes into the features list.
- * @return The array of feature indexes for this language system.
- */
- public char[] getFeatureIndexes() {
- return this.featureIndexes;
- }
-
-}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java 2025-05-01 12:24:24 UTC (rev 13553)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfScript.java 2025-05-01 13:03:45 UTC (rev 13554)
@@ -28,7 +28,10 @@
package org.foray.font.ttf;
-import org.foray.common.RandomAccessInput;
+import org.foray.font.ttf.table.LangSysTable;
+import org.foray.fontParse.ttf.LangSysTableParser;
+import org.foray.fontParse.ttf.TtfRandomAccessInput;
+import org.foray.fontParse.ttfHandler.LangSysTableHandler;
import java.io.IOException;
import java.util.HashMap;
@@ -43,10 +46,10 @@
public static final byte TAG_SIZE = 4;
/** The (optional) default language system. */
- private OtfLanguageSystem defaultLanguageSystem;
+ private LangSysTable defaultLanguageSystem;
/** Map of the other (non-default) language systems. */
- private Map<String, OtfLanguageSystem> languageSystems = new HashMap<String, OtfLanguageSystem>();
+ private Map<String, LangSysTable> languageSystems = new HashMap<String, LangSysTable>();
/**
* Constructor.
@@ -61,7 +64,7 @@
* @return The parsed script instance.
* @throws IOException For I/O errors during parsing.
*/
- public static OtfScript parse(final RandomAccessInput raInput, final int offset) throws IOException {
+ public static OtfScript parse(final TtfRandomAccessInput raInput, final int offset) throws IOException {
raInput.seek(offset);
final OtfScript script = new OtfScript();
final int offsetToDefaultLangSys = raInput.readUnsignedShort();
@@ -69,16 +72,21 @@
final String[] langSysTags = new String[langSysCount];
final int[] langSysOffsets = new int[langSysCount];
for (int index = 0; index < langSysCount; index ++) {
- langSysTags[index] = raInput.readStringASCII(OtfLanguageSystem.TAG_SIZE);
+ langSysTags[index] = raInput.readStringASCII(TAG_SIZE);
langSysOffsets[index] = raInput.readUnsignedShort();
}
if (offsetToDefaultLangSys > 0) {
- script.defaultLanguageSystem = OtfLanguageSystem.parse(raInput, offset + offsetToDefaultLangSys);
+ final ParserKit<LangSysTable, LangSysTableHandler> kit = LangSysTable.createContentHandler();
+ final LangSysTableParser parser = new LangSysTableParser();
+ parser.parse(raInput, offset + offsetToDefaultLangSys, kit.getHandler());
+ script.defaultLanguageSystem = kit.getTable();
}
for (int index = 0; index < langSysCount; index ++) {
- final OtfLanguageSystem langSys = OtfLanguageSystem.parse(raInput, offset + langSysOffsets[index]);
- script.languageSystems.put(langSysTags[index], langSys);
+ final ParserKit<LangSysTable, LangSysTableHandler> kit = LangSysTable.createContentHandler();
+ final LangSysTableParser parser = new LangSysTableParser();
+ parser.parse(raInput, offset + langSysOffsets[index], kit.getHandler());
+ script.languageSystems.put(langSysTags[index], kit.getTable());
}
return script;
@@ -88,7 +96,7 @@
* Returns the default language system for this script.
* @return The default language system.
*/
- public OtfLanguageSystem getDefaultLanguageSystem() {
+ public LangSysTable getDefaultLanguageSystem() {
return this.defaultLanguageSystem;
}
@@ -97,7 +105,7 @@
* @param languageSystemTag The language system tag to be retrieved.
* @return The language system for {@code languageSystemTag}, or null if that tag is not in this script.
*/
- public OtfLanguageSystem getNamedLanguageSystem(final String languageSystemTag) {
+ public LangSysTable getNamedLanguageSystem(final String languageSystemTag) {
return this.languageSystems.get(languageSystemTag);
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 12:24:24 UTC (rev 13553)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/AbstractOtfLayoutTable.java 2025-05-01 13:03:45 UTC (rev 13554)
@@ -32,6 +32,7 @@
import org.foray.font.ttf.OtfFeature;
import org.foray.font.ttf.OtfScript;
import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttf.TtfRandomAccessInput;
import java.io.IOException;
import java.util.HashMap;
@@ -67,7 +68,7 @@
* @return The parsed map of scripts.
* @throws IOException For I/O errors during parsing.
*/
- protected static Map<String, OtfScript> parseScriptList(final RandomAccessInput raInput, final int offset)
+ protected static Map<String, OtfScript> parseScriptList(final TtfRandomAccessInput raInput, final int offset)
throws IOException {
raInput.seek(offset);
final int scriptCount = raInput.readUnsignedShort();
Copied: trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java (from rev 13486, trunk/foray/foray-font/src/main/java/org/foray/font/ttf/OtfLanguageSystem.java)
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/ttf/table/LangSysTable.java 2025-05-01 13:03:45 UTC (rev 13554)
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2016 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.font.ttf.table;
+
+import org.foray.font.ttf.ParserKit;
+import org.foray.font.ttf.RoTable;
+import org.foray.fontParse.ttfHandler.LangSysTableHandler;
+
+/**
+ * An OpenType Language System.
+ */
+public class LangSysTable extends RoTable {
+
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ContentHandler implements LangSysTableHandler {
+
+ /** The table instance being created. */
+ @SuppressWarnings("unused")
+ private LangSysTable table;
+
+ /**
+ * Constructor.
+ * @param table The table instance being created.
+ */
+ private ContentHandler(final LangSysTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public void requiredFeatureIndex(final short value) {
+ this.table.reqFeatureIndex = (char) value;
+ }
+
+ @Override
+ public void featureIndexes(final short[] value) {
+ this.table.featureIndexes = new char[value.length];
+ for (int index = 0; index < value.length; index ++) {
+ this.table.featureIndexes[index] = (char) value[index];
+ }
+ }
+ }
+
+
+
+
+
+
+
+
+ /** Index of a required feature in this language system. If null, the value is 0xFFFF. */
+ private char reqFeatureIndex;
+
+ /** The (arbitarily ordered) array of indexes into the features list. */
+ private char[] featureIndexes;
+
+ /**
+ * Creates a table instance and a content handler for that instance.
+ * @return A new content handler.
+ */
+ public static ParserKit<LangSysTable, LangSysTableHandler> createContentHandler() {
+ final LangSysTable table = new LangSysTable();
+ final LangSysTableHandler handler = table.new ContentHandler(table);
+ return new ParserKit<LangSysTable, LangSysTableHandler>(table, handler);
+ }
+
+ /**
+ * Returns the index of a required feature in this language system. If null, the value is 0xFFFF.
+ * @return The index of a required feature, or 0xFFFF if null.
+ */
+ public char getRequiredFeatureIndex() {
+ return this.reqFeatureIndex;
+ }
+
+ /**
+ * Returns the (arbitarily ordered) array of indexes into the features list.
+ * @return The array of feature indexes for this language system.
+ */
+ public char[] getFeatureIndexes() {
+ return this.featureIndexes;
+ }
+
+}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 12:24:24 UTC (rev 13553)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/ttf/table/OtfLookupGsubTests.java 2025-05-01 13:03:45 UTC (rev 13554)
@@ -33,7 +33,6 @@
import org.foray.font.format.FontContent;
import org.foray.font.format.FontParser;
import org.foray.font.ttf.OtfFeature;
-import org.foray.font.ttf.OtfLanguageSystem;
import org.foray.font.ttf.OtfScript;
import org.foray.font.ttf.TrueTypeFont;
import org.foray.font.ttf.TrueTypeSingle;
@@ -110,7 +109,7 @@
assertNotNull(gsub.getScript("ital"));
final OtfScript latinScript = gsub.getScript("latn");
assertNotNull(latinScript);
- final OtfLanguageSystem defaultLatinLanguageSystem = latinScript.getDefaultLanguageSystem();
+ final LangSysTable defaultLatinLanguageSystem = latinScript.getDefaultLanguageSystem();
assertNotNull(defaultLatinLanguageSystem);
assertEquals(0, latinScript.getQtyLanguageSystems());
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java 2025-05-01 13:03:45 UTC (rev 13554)
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttf;
+
+import org.foray.fontParse.TableParser;
+import org.foray.fontParse.ttfHandler.LangSysTableHandler;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF "LangSys" table.
+ */
+public class LangSysTableParser extends TableParser<LangSysTableHandler> {
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final LangSysTableHandler handler)
+ throws IOException {
+ input.seek(offset);
+
+ handler.lookupOrderOffset(input.read_Offset16());
+ handler.requiredFeatureIndex(input.read_uint16());
+ final @Unsigned short featureIndexCount = input.read_uint16();
+
+ final @Unsigned short[] featureIndexes = new @Unsigned short[featureIndexCount];
+ for (int index = 0; index < featureIndexCount; index ++) {
+ final @Unsigned short featureIndex = input.read_uint16();
+ handler.featureIndex(featureIndex);
+ featureIndexes[index] = featureIndex;
+ }
+ handler.featureIndexes(featureIndexes);
+
+ }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttf/LangSysTableParser.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LangSysTableHandler.java
===================================================================
--- trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LangSysTableHandler.java (rev 0)
+++ trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LangSysTableHandler.java 2025-05-01 13:03:45 UTC (rev 13554)
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2025 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.fontParse.ttfHandler;
+
+import org.foray.fontParse.FontContentHandler;
+import org.foray.fontParse.ttf.LangSysTableParser;
+
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
+/**
+ * Implementations catch and handle the output from {@link LangSysTableParser}.
+ */
+public interface LangSysTableHandler extends FontContentHandler {
+
+ default void lookupOrderOffset(@Unsigned short value) { return; }
+ default void requiredFeatureIndex(@Unsigned short value) { return; }
+ default void featureIndexCount(@Unsigned short value) { return; }
+
+ default void featureIndex(@Unsigned short value) { return; }
+ default void featureIndexes(@Unsigned short[] value) { return; }
+
+}
Property changes on: trunk/foray/foray-font-parse/src/main/java/org/foray/fontParse/ttfHandler/LangSysTableHandler.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|