foray-commit Mailing List for FOray (Page 18)
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-04-20 21:11:06
|
Revision: 13451
http://sourceforge.net/p/foray/code/13451
Author: victormote
Date: 2025-04-20 21:10:48 +0000 (Sun, 20 Apr 2025)
Log Message:
-----------
Hide parse handling logic by pushing it into private inner classes.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableBase.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableBase.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableBase.java 2025-04-20 20:01:46 UTC (rev 13450)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableBase.java 2025-04-20 21:10:48 UTC (rev 13451)
@@ -28,7 +28,9 @@
package org.foray.font.format.ttf;
-import org.foray.common.RandomAccessInput;
+import org.foray.common.primitive.PrimitiveFerry;
+import org.foray.font.FontParserConsumer;
+import org.foray.font.format.ttf.parse.TtfTableBaseParser;
import java.io.IOException;
@@ -39,6 +41,38 @@
public class TtfTableBase extends TtfTable {
/**
+ * The handler of events from the parser.
+ */
+ private final class ParserConsumer implements FontParserConsumer {
+
+ /** The client being built from the parser results. */
+ private TtfTableBase client;
+
+ /**
+ * Constructor.
+ * @param client The client being built from the parser results.
+ */
+ private ParserConsumer(final TtfTableBase client) {
+ this.client = client;
+ }
+
+ @Override
+ public void objectField(final String fieldName, final Object value) {
+ }
+
+ @Override
+ public void primitiveField(final String fieldName, final PrimitiveFerry value) {
+ switch (fieldName) {
+ case "majorVersion": client.majorVersion = (byte) value.getInt(); break;
+ }
+ }
+
+ }
+
+ /** The major verions of this table. */
+ private byte majorVersion;
+
+ /**
* Constructor.
* @param offsetRecord The parent table directory entry.
*/
@@ -48,15 +82,16 @@
/**
* Parse the table from the table content.
- * @param offsetRecord The parent offset table record.
- * @param raInput The input which is being parsed.
+ * @param dirEntry The parent table directory entry.
+ * @param input The input which is being parsed.
* @return The parsed instance.
* @throws IOException For I/O Error.
*/
- public static TtfTableBase parse(final TtfOffsetTableRecord offsetRecord, final RandomAccessInput raInput)
+ public static TtfTableBase parse(final TtfOffsetTableRecord dirEntry, final TtfRandomAccessInput input)
throws IOException {
- raInput.seek(offsetRecord.getOffset());
- final TtfTableBase table = new TtfTableBase(offsetRecord);
+ final TtfTableBase table = new TtfTableBase(dirEntry);
+ final TtfTableBaseParser parser = new TtfTableBaseParser();
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), table.new ParserConsumer(table));
return table;
}
@@ -65,4 +100,12 @@
return "BASE";
}
+ /**
+ * Returns the major version of this table.
+ * @return The major version of this table.
+ */
+ public int getMajorVersion() {
+ return this.majorVersion;
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-20 20:01:46 UTC (rev 13450)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-20 21:10:48 UTC (rev 13451)
@@ -41,8 +41,47 @@
/**
* Class representing a TTF "head" table.
*/
-public class TtfTableHead extends TtfTable implements FontParserConsumer {
+public class TtfTableHead extends TtfTable {
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ParserConsumer implements FontParserConsumer {
+
+ /** The client being built from the parser results. */
+ private TtfTableHead client;
+
+ /**
+ * Constructor.
+ * @param client The client being built from the parser results.
+ */
+ private ParserConsumer(final TtfTableHead client) {
+ this.client = client;
+ }
+
+ @Override
+ public void objectField(final String fieldName, final Object value) {
+ switch (fieldName) {
+ case "boundingBox": {
+ final short[] boundingBoxArray = (short[]) value;
+ client.boundingBox = new BoundingBoxShort(boundingBoxArray);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void primitiveField(final String fieldName, final PrimitiveFerry value) {
+ switch (fieldName) {
+ case "unitsPerEm": client.unitsPerEm = value.getInt(); break;
+ case "indexToLocFormat": client.indexToLocFormat = value.getShort(); break;
+ }
+ }
+
+ }
+
+
+
/** Constant for the offset to the "checkSumAdjustment" in this table. */
public static final byte CHECK_SUM_ADJUSTMENT_OFFSET = 8;
@@ -80,7 +119,7 @@
throws IOException {
final TtfTableHead head = new TtfTableHead(dirEntry);
final TtfTableHeadParser parser = new TtfTableHeadParser();
- parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), head);
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), head.new ParserConsumer(head));
return head;
}
@@ -113,23 +152,4 @@
return this.boundingBox;
}
- @Override
- public void objectField(final String fieldName, final Object value) {
- switch (fieldName) {
- case "boundingBox": {
- final short[] boundingBoxArray = (short[]) value;
- this.boundingBox = new BoundingBoxShort(boundingBoxArray);
- break;
- }
- }
- }
-
- @Override
- public void primitiveField(final String fieldName, final PrimitiveFerry value) {
- switch (fieldName) {
- case "unitsPerEm": this.unitsPerEm = value.getInt(); break;
- case "indexToLocFormat": this.indexToLocFormat = value.getShort(); break;
- }
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-20 20:01:46 UTC (rev 13450)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-20 21:10:48 UTC (rev 13451)
@@ -40,8 +40,47 @@
/**
* Class representing a TTF "OS/2" (OS/2 and Windows metrics) table.
*/
-public class TtfTableOs2 extends TtfTable implements FontParserConsumer {
+public class TtfTableOs2 extends TtfTable {
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ParserConsumer implements FontParserConsumer {
+
+ /** The client being built from the parser results. */
+ private TtfTableOs2 client;
+
+ /**
+ * Constructor.
+ * @param client The client being built from the parser results.
+ */
+ private ParserConsumer(final TtfTableOs2 client) {
+ this.client = client;
+ }
+
+ @Override
+ public void objectField(final String fieldName, final Object value) {
+ switch (fieldName) {
+ case "panose": client.panose = Panose4a.forceInstance((@Unsigned byte[]) value);
+ }
+ }
+
+ @Override
+ public void primitiveField(final String fieldName, final PrimitiveFerry value) {
+ switch (fieldName) {
+ case "version": client.version = (byte) value.getShort(); break;
+ case "fstype": client.fsType = value.getInt(); break;
+ case "yStrikeoutSize": client.yStrikeoutSize = value.getShort(); break;
+ case "yStrikeoutPosition": client.yStrikeoutPosition = value.getShort(); break;
+ case "sTypoAscender": client.sTypoAscender = value.getShort(); break;
+ case "sTypoDescender": client.sTypoDescender = value.getShort(); break;
+ case "sxHeight": client.sxHeight = value.getShort(); break;
+ case "sCapHeight": client.sCapHeight = value.getShort(); break;
+ }
+ }
+
+ }
+
/** The version number of this table. */
private byte version;
@@ -88,7 +127,7 @@
throws IOException {
final TtfTableOs2 os2 = new TtfTableOs2(dirEntry);
final TtfTableOs2Parser parser = new TtfTableOs2Parser();
- parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), os2);
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), os2.new ParserConsumer(os2));
return os2;
}
@@ -175,25 +214,4 @@
return this.sCapHeight;
}
- @Override
- public void objectField(final String fieldName, final Object value) {
- switch (fieldName) {
- case "panose": this.panose = Panose4a.forceInstance((@Unsigned byte[]) value);
- }
- }
-
- @Override
- public void primitiveField(final String fieldName, final PrimitiveFerry value) {
- switch (fieldName) {
- case "version": this.version = (byte) value.getShort(); break;
- case "fstype": this.fsType = value.getInt(); break;
- case "yStrikeoutSize": this.yStrikeoutSize = value.getShort(); break;
- case "yStrikeoutPosition": this.yStrikeoutPosition = value.getShort(); break;
- case "sTypoAscender": this.sTypoAscender = value.getShort(); break;
- case "sTypoDescender": this.sTypoDescender = value.getShort(); break;
- case "sxHeight": this.sxHeight = value.getShort(); break;
- case "sCapHeight": this.sCapHeight = value.getShort(); break;
- }
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-20 20:01:46 UTC (rev 13450)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-20 21:10:48 UTC (rev 13451)
@@ -37,8 +37,39 @@
/**
* Class representing a TTF "PCLT" (PCL 5) table.
*/
-public class TtfTablePclt extends TtfTable implements FontParserConsumer {
+public class TtfTablePclt extends TtfTable {
+ /**
+ * The handler of events from the parser.
+ */
+ private final class ParserConsumer implements FontParserConsumer {
+
+ /** The client being built from the parser results. */
+ private TtfTablePclt client;
+
+ /**
+ * Constructor.
+ * @param client The client being built from the parser results.
+ */
+ private ParserConsumer(final TtfTablePclt client) {
+ this.client = client;
+ }
+
+ @Override
+ public void objectField(final String fieldName, final Object value) {
+ }
+
+ @Override
+ public void primitiveField(final String fieldName, final PrimitiveFerry value) {
+ switch (fieldName) {
+ case "xHeight": client.xHeight = value.getInt(); break;
+ case "capHeight": client.capHeight = value.getInt(); break;
+ case "serifStyle": client.serifStyle = value.getShort(); break;
+ }
+ }
+
+ }
+
/** The size, in bytes, of the "typeface" field. */
public static final byte TYPEFACE_CHARS = 16;
@@ -83,7 +114,7 @@
throws IOException {
final TtfTablePclt pclt = new TtfTablePclt(dirEntry);
final TtfTablePcltParser parser = new TtfTablePcltParser();
- parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), pclt);
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), pclt.new ParserConsumer(pclt));
return pclt;
}
@@ -120,18 +151,4 @@
return this.xHeight;
}
- @Override
- public void objectField(final String fieldName, final Object value) {
- }
-
- @Override
- public void primitiveField(final String fieldName, final PrimitiveFerry value) {
- switch (fieldName) {
- case "xHeight": this.xHeight = value.getInt(); break;
- case "capHeight": this.capHeight = value.getInt(); break;
-
- case "serifStyle": this.serifStyle = value.getShort(); break;
- }
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-20 20:02:03
|
Revision: 13450
http://sourceforge.net/p/foray/code/13450
Author: victormote
Date: 2025-04-20 20:01:46 +0000 (Sun, 20 Apr 2025)
Log Message:
-----------
Add comment about termination of efforts to do compile-time checking of Signedness.
Modified Paths:
--------------
trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
Modified: trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
===================================================================
--- trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-20 18:40:25 UTC (rev 13449)
+++ trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-20 20:01:46 UTC (rev 13450)
@@ -216,6 +216,7 @@
]
/* Uncomment the following line temporarily to disable checker, for testing. */
+ /* We leave this checking turned off for now, pending resolution of build errors that we don't understand. */
skipCheckerFramework = true
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-20 18:40:44
|
Revision: 13449
http://sourceforge.net/p/foray/code/13449
Author: victormote
Date: 2025-04-20 18:40:25 +0000 (Sun, 20 Apr 2025)
Log Message:
-----------
Remove BigInteger conversions, and parse the int and long primitives directly.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-20 16:02:48 UTC (rev 13448)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-20 18:40:25 UTC (rev 13449)
@@ -28,12 +28,9 @@
package org.foray.common;
-import org.checkerframework.checker.signedness.qual.Unsigned;
-
import java.io.DataInput;
import java.io.IOException;
import java.io.RandomAccessFile;
-import java.math.BigInteger;
import java.nio.charset.Charset;
/**
@@ -159,15 +156,19 @@
int readShortLoHi() throws IOException;
/**
- * Reads an integer with an arbitrary input size.
+ * Reads a long with an arbitrary input size.
* @param length The number of bytes to be parsed.
- * @return The integer created from the bytes read.
+ * @return The long created from the bytes read.
* @throws IOException For I/O error.
*/
- default @Unsigned BigInteger readUnsignedInteger(int length) throws IOException {
- final byte[] bytes = new byte[length];
- readFully(bytes);
- return new BigInteger(bytes);
- }
+ long readLong(int length) throws IOException;
+ /**
+ * Reads an int with an arbitrary input size.
+ * @param length The number of bytes to be parsed.
+ * @return The int created from the bytes read.
+ * @throws IOException For I/O error.
+ */
+ int readInt(int length) throws IOException;
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-20 16:02:48 UTC (rev 13448)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-20 18:40:25 UTC (rev 13449)
@@ -310,4 +310,32 @@
return readTerminatedString((byte) 0x00, characterSet);
}
+ @Override
+ public long readLong(final int length) throws IOException {
+ if (length < 1) {
+ return 0;
+ }
+ if (length > Long.BYTES) {
+ throw new IllegalArgumentException("Cannot read more than 8 bytes to create a long");
+ }
+ long ret = readUnsignedByte();
+ for (int counter = 2; counter <= length; counter ++) {
+ ret = (ret <<= PrimitiveConstants.SHIFT_1_BYTE);
+ final int newByte = readUnsignedByte();
+ ret |= newByte;
+ }
+ return ret;
+ }
+
+ @Override
+ public int readInt(final int length) throws IOException {
+ if (length < 1) {
+ return 0;
+ }
+ if (length > Integer.BYTES) {
+ throw new IllegalArgumentException("Cannot read more than 4 bytes to create a long");
+ }
+ return (int) readLong(length);
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java 2025-04-20 16:02:48 UTC (rev 13448)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java 2025-04-20 18:40:25 UTC (rev 13449)
@@ -38,7 +38,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
-import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
/**
@@ -119,8 +118,8 @@
* @throws IOException For I/O Error.
*/
default @Unsigned int read_uint24() throws IOException {
- final BigInteger bi = this.readUnsignedInteger(TtfType.uint24.getQtyBytes());
- return bi.intValue();
+ final long parsed = this.readLong(TtfType.uint24.getQtyBytes());
+ return (int) parsed;
}
/**
@@ -190,8 +189,7 @@
* @throws IOException For I/O Error.
*/
default @Unsigned long read_LONGDATETIME() throws IOException {
- final BigInteger bi = readUnsignedInteger(TtfType.LONGDATETIME.getQtyBytes());
- return bi.longValue();
+ return readLong();
}
/**
@@ -250,6 +248,5 @@
}
-
/* Checkstyle: Restart method name checking. */
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-20 16:03:05
|
Revision: 13448
http://sourceforge.net/p/foray/code/13448
Author: victormote
Date: 2025-04-20 16:02:48 +0000 (Sun, 20 Apr 2025)
Log Message:
-----------
Improvements to "Checker" framework configuration.
Modified Paths:
--------------
trunk/foray/build.gradle
trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
Modified: trunk/foray/build.gradle
===================================================================
--- trunk/foray/build.gradle 2025-04-20 10:52:08 UTC (rev 13447)
+++ trunk/foray/build.gradle 2025-04-20 16:02:48 UTC (rev 13448)
@@ -30,6 +30,12 @@
id "java"
id "com.autonomousapps.dependency-analysis" version "1.0.0-rc02"
id "java-library-distribution"
+ /* The Gradle Checker Framework Plugin (being invoked here) is a wrapper of, but is a separate product from, the
+ Checker Framework, has its own release cycle, and its own release numbering system.
+ https://github.com/kelloggm/checkerframework-gradle-plugin
+ Documentation of the Checker Framework itself can be found at
+ https://checkerframework.org/manual/#gradle
+ */
id "org.checkerframework" version "0.6.53"
}
Modified: trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
===================================================================
--- trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-20 10:52:08 UTC (rev 13447)
+++ trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-20 16:02:48 UTC (rev 13448)
@@ -58,6 +58,7 @@
jeuclid: '3.1.14', // Latest is 3.1.14 as of 2022-11-26. See Note 4.
icu4j: '72.1', // Latest is 72.1 as of 2022-11-26.
+ checkerFramework: '3.49.2', // Latest is 3.49.2 as of 2025-04-20.
junit: '5.10.2', // Latest is 5.10.2 as of 2024-05-08.
mockito: '4.9.0', // Latest is 4.9.0 as of 2022-11-26. See Note 5.
@@ -210,9 +211,18 @@
}
checkerFramework {
- checkers = [
-// "org.checkerframework.checker.signedness.SignednessChecker"
- ]
+ checkers = [
+ "org.checkerframework.checker.signedness.SignednessChecker"
+ ]
+
+ /* Uncomment the following line temporarily to disable checker, for testing. */
+ skipCheckerFramework = true
}
+dependencies {
+ compileOnly (group: 'org.checkerframework', name: 'checker-qual', version: versions.checkerFramework)
+ testCompileOnly (group: 'org.checkerframework', name: 'checker-qual', version: versions.checkerFramework)
+ checkerFramework (group: 'org.checkerframework', name: 'checker', version: versions.checkerFramework)
+}
+
/* Last line of script. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-20 10:52:26
|
Revision: 13447
http://sourceforge.net/p/foray/code/13447
Author: victormote
Date: 2025-04-20 10:52:08 +0000 (Sun, 20 Apr 2025)
Log Message:
-----------
Fix some issues with signedness revealed by the Checker Framework.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java 2025-04-20 10:35:19 UTC (rev 13446)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java 2025-04-20 10:52:08 UTC (rev 13447)
@@ -28,7 +28,10 @@
package org.foray.primitive;
+import org.foray.primitive.sequence.ByteArray;
+
import org.axsl.constants.PrimitiveConstants;
+import org.axsl.primitive.sequence.ByteSequencePlus;
/**
* Utilities for bytes.
@@ -36,7 +39,7 @@
public final class ByteUtils {
/** Array of characters representing the hex values of a nibble. */
- private static final String HEX_CHARS = "0123456789ABCDEF";
+ private static final ByteSequencePlus HEX_CHARS = new ByteArray("0123456789ABCDEF");
/**
* Private constructor. This is a utility class, and should never be instantiated.
@@ -107,7 +110,7 @@
/* Since we mask the high-order bits anyway, we can safely use the signed shift. */
byte index = (byte) (inputByte >> PrimitiveConstants.BITS_PER_NIBBLE);
index &= PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE;
- return (byte) HEX_CHARS.charAt(index);
+ return (byte) HEX_CHARS.byteAt(index);
}
/**
@@ -118,7 +121,7 @@
*/
public static byte toHexCharLow(final byte inputByte) {
final byte index = (byte) (inputByte & PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE);
- return (byte) HEX_CHARS.charAt(index);
+ return (byte) HEX_CHARS.byteAt(index);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-20 10:35:36
|
Revision: 13446
http://sourceforge.net/p/foray/code/13446
Author: victormote
Date: 2025-04-20 10:35:19 +0000 (Sun, 20 Apr 2025)
Log Message:
-----------
Fix some issues with signedness revealed by the Checker Framework.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java 2025-04-19 23:49:48 UTC (rev 13445)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/ByteUtils.java 2025-04-20 10:35:19 UTC (rev 13446)
@@ -104,7 +104,8 @@
* @return The ASCII byte representing the value of the high-order nibble of {@code inputByte}.
*/
public static byte toHexCharHigh(final byte inputByte) {
- byte index = (byte) (inputByte >>> PrimitiveConstants.BITS_PER_NIBBLE);
+ /* Since we mask the high-order bits anyway, we can safely use the signed shift. */
+ byte index = (byte) (inputByte >> PrimitiveConstants.BITS_PER_NIBBLE);
index &= PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE;
return (byte) HEX_CHARS.charAt(index);
}
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java 2025-04-19 23:49:48 UTC (rev 13445)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/StringUtils.java 2025-04-20 10:35:19 UTC (rev 13446)
@@ -435,13 +435,8 @@
final StringBuilder buffer = new StringBuilder();
for (int i = 0; i < value.length; i++) {
- buffer.append(
- HEXADECIMAL_DIGITS[(value[i]
- >>> PrimitiveConstants.BITS_PER_NIBBLE)
- & PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE]);
- buffer.append(
- HEXADECIMAL_DIGITS[value[i]
- & PrimitiveConstants.MAX_4_BIT_UNSIGNED_BYTE]);
+ buffer.append((char) ByteUtils.toHexCharHigh(value[i]));
+ buffer.append((char) ByteUtils.toHexCharLow(value[i]));
}
return buffer.toString();
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java 2025-04-19 23:49:48 UTC (rev 13445)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/NibbleArrayBuilder.java 2025-04-20 10:35:19 UTC (rev 13446)
@@ -190,9 +190,9 @@
nibbleValue = BitUtils.maskHighOrderBits(byteValue);
} else {
/* If the index is even, return just the high-order bits. */
- nibbleValue = (byte) (byteValue >>> PrimitiveConstants.BITS_PER_NIBBLE);
+ nibbleValue = (byte) (byteValue >> PrimitiveConstants.BITS_PER_NIBBLE);
/* Have to mask out the high-order bits after the cast, in case the shifted value has
- * the high-order bit set, and therefore looks negative -- in that case the caset sets
+ * the high-order bit set, and therefore looks negative -- in that case the cast sets
* all of the high-order bits. */
nibbleValue = BitUtils.maskHighOrderBits(nibbleValue);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-19 23:50:05
|
Revision: 13445
http://sourceforge.net/p/foray/code/13445
Author: victormote
Date: 2025-04-19 23:49:48 +0000 (Sat, 19 Apr 2025)
Log Message:
-----------
Move some no-longer-needed bit-twiddling methods to the attic.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/BitUtils.java
trunk/foray/foray-primitive/src/test/java/org/foray/primitive/BitUtilsTests.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java
Added Paths:
-----------
trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/
trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/
trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/BitUtils.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/package-info.java
trunk/foray/foray-zz-attic/src/test/java/org/foray/primitive/
trunk/foray/foray-zz-attic/src/test/java/org/foray/primitive/attic/
trunk/foray/foray-zz-attic/src/test/java/org/foray/primitive/attic/BitUtilsTests.java
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/BitUtils.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/BitUtils.java 2025-04-19 23:11:05 UTC (rev 13444)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/BitUtils.java 2025-04-19 23:49:48 UTC (rev 13445)
@@ -103,48 +103,4 @@
return (byte) (input & BitUtils.BYTE_LOW_ORDER_MASK);
}
- /**
- * Extracts a range of bits from a long and returns the value as a long.
- * @param input The long containing the bits to be extracted.
- * @param position The position in {@code input} at which the bits should be extracted.
- * Position 0 is the low-order bit, position 63 is the high-order bit.
- * Values outside of that range will produce undefined results.
- * @param qtyBits The number of bits that should be extracted.
- * Values outside of 0 inclusive through 64 inclusive will produce undefined results.
- * @return The extracted value.
- */
- public static long extractBits(final long input, final int position, final int qtyBits) {
- final long rightShifted = input >>> position;
- long mask = -1;
- if (qtyBits < Long.SIZE) {
- mask = (1L << qtyBits) - 1L;
- }
- return rightShifted & mask;
- }
-
- /**
- * Replaces a range of bits in a long with a new value.
- * @param input The long containing the bits to be replaced.
- * @param position The position in {@code input} at which the bits should be replaced.
- * Position 0 is the low-order bit, position 63 is the high-order bit.
- * Values outside of that range will produce undefined results.
- * @param qtyBits The number of bits that should be replaced.
- * Values outside of 0 inclusive through 64 inclusive will produce undefined results.
- * @param newValue The value of the bits that will replace the existing bits.
- * @return The new value.
- */
- public static long replaceBits(final long input, final int position, final int qtyBits, final long newValue) {
- if (qtyBits < 1) {
- return input;
- }
- long leftBits = extractBits(input, position + qtyBits, Long.SIZE - qtyBits);
- leftBits = leftBits << (position + qtyBits);
- final long rightBits = extractBits(input, 0, position);
- /* Strip off any high-order bits that exceed the qtyBits. */
- long middleBits = newValue << (Long.SIZE - qtyBits);
- middleBits = middleBits >>> (Long.SIZE - qtyBits);
- middleBits = middleBits << position;
- return leftBits | middleBits | rightBits;
- }
-
}
Modified: trunk/foray/foray-primitive/src/test/java/org/foray/primitive/BitUtilsTests.java
===================================================================
--- trunk/foray/foray-primitive/src/test/java/org/foray/primitive/BitUtilsTests.java 2025-04-19 23:11:05 UTC (rev 13444)
+++ trunk/foray/foray-primitive/src/test/java/org/foray/primitive/BitUtilsTests.java 2025-04-19 23:49:48 UTC (rev 13445)
@@ -68,136 +68,4 @@
assertEquals(expectedOutput, actualOutput);
}
- /**
- * Test of {@link BitUtils#extractBits(long, int, int)}.
- */
- @Test
- public void testExtractBits() {
- /* Decimal 601. */
- long input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0010_0101_1001L;
- assertEquals(1, BitUtils.extractBits(input, 4, 1)); // ...0010010[1]1001
- assertEquals(1, BitUtils.extractBits(input, 4, 2)); // ...001001[01]1001
- assertEquals(5, BitUtils.extractBits(input, 4, 3)); // ...00100[101]1001
- assertEquals(5, BitUtils.extractBits(input, 4, 4)); // ...0010[0101]1001
- assertEquals(5, BitUtils.extractBits(input, 4, 5)); // ...001[00101]1001
- assertEquals(37, BitUtils.extractBits(input, 4, 6)); // ...00[100101]1001
- assertEquals(1, BitUtils.extractBits(input, 0, 1)); // ...00100101100[1]
- assertEquals(1, BitUtils.extractBits(input, 0, 2)); // ...0010010110[01]
- assertEquals(1, BitUtils.extractBits(input, 0, 3)); // ...001001011[001]
- assertEquals(9, BitUtils.extractBits(input, 0, 4)); // ...00100101[1001]
- assertEquals(25, BitUtils.extractBits(input, 0, 5)); // ...0010010[11001]
-
- /* Decimal -601. */
- input = 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1101_1010_0111L;
- assertEquals(0, BitUtils.extractBits(input, 4, 1)); // ...1101101[0]0111
- assertEquals(2, BitUtils.extractBits(input, 4, 2)); // ...110110[10]0111
- assertEquals(2, BitUtils.extractBits(input, 4, 3)); // ...11011[010]0111
- assertEquals(10, BitUtils.extractBits(input, 4, 4)); // ...1101[1010]0111
- assertEquals(26, BitUtils.extractBits(input, 4, 5)); // ...110[11010]0111
- assertEquals(26, BitUtils.extractBits(input, 4, 6)); // ...11[011010]0111
- assertEquals(7, BitUtils.extractBits(input, 31, 3));
- /* The low-order 63 bits, decimal 9,223,372,036,854,775,207. */
- long expected = 0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1101_1010_0111L;
- assertEquals(expected, BitUtils.extractBits(input, 0, 63));
- /* The high-order 63 bits, decimal 9,223,372,036,854,775,507. */
- expected = 0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1110_1101_0011L;
- assertEquals(expected, BitUtils.extractBits(input, 1, 63));
-
- /* Decimal 7,243,477,050,672,021,504. Binary . */
- input = 0b0110_0100_1000_0110_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
- assertEquals(0, BitUtils.extractBits(input, 63, 1)); // [0]110010010000110...
- assertEquals(1, BitUtils.extractBits(input, 62, 2)); // [01]10010010000110...
- assertEquals(3, BitUtils.extractBits(input, 61, 3)); // [011]0010010000110...
- assertEquals(6, BitUtils.extractBits(input, 60, 4)); // [0110]010010000110...
- assertEquals(12, BitUtils.extractBits(input, 59, 5)); // [01100]10010000110...
- assertEquals(25, BitUtils.extractBits(input, 58, 6)); // [011001]0010000110...
-
- /* Test some qtyBits of zero, which should always return 0. */
- assertEquals(0, BitUtils.extractBits(Long.MIN_VALUE, 0, 0));
- assertEquals(0, BitUtils.extractBits(Long.MIN_VALUE, 63, 0));
- assertEquals(0, BitUtils.extractBits(0, 0, 0));
- assertEquals(0, BitUtils.extractBits(0, 63, 0));
- assertEquals(0, BitUtils.extractBits(1, 0, 0));
- assertEquals(0, BitUtils.extractBits(1, 63, 0));
- assertEquals(0, BitUtils.extractBits(601, 8, 0));
- assertEquals(0, BitUtils.extractBits(601, 8, 0));
- assertEquals(0, BitUtils.extractBits(Long.MAX_VALUE, 0, 0));
- assertEquals(0, BitUtils.extractBits(Long.MAX_VALUE, 63, 0));
-
- /* Test some position 0, qtyBits 64, which should always return the input. */
- assertEquals(Long.MIN_VALUE, BitUtils.extractBits(Long.MIN_VALUE, 0, 64));
- assertEquals(-601, BitUtils.extractBits(-601, 0, 64));
- assertEquals(-1, BitUtils.extractBits(-1, 0, 64));
- assertEquals(0, BitUtils.extractBits(0, 0, 64));
- assertEquals(1, BitUtils.extractBits(1, 0, 64));
- assertEquals(601, BitUtils.extractBits(601, 0, 64));
- assertEquals(Long.MAX_VALUE, BitUtils.extractBits(Long.MAX_VALUE, 0, 64));
-
- /* Test some invalid position values. */
- assertEquals(0, BitUtils.extractBits(1, -600, 3));
- assertEquals(0, BitUtils.extractBits(1, -1, 3));
- assertEquals(1, BitUtils.extractBits(1, 64, 3));
- assertEquals(1, BitUtils.extractBits(1, 128, 3));
-
- /* Test some invalid qtyBits values. */
- assertEquals(0, BitUtils.extractBits(1, 1, -600));
- assertEquals(0, BitUtils.extractBits(1, 1, -1));
- assertEquals(0, BitUtils.extractBits(1, 1, 65));
- assertEquals(0, BitUtils.extractBits(1, 1, 128));
- }
-
- /**
- * Test of {@link BitUtils#replaceBits(long, int, int, long)}.
- */
- @Test
- public void testReplaceBits() {
- long input;
- long patch;
- long expected;
-
- /* Decimal 601. */
- input = 0b0010_0101_1001;
- assertEquals(521, BitUtils.replaceBits(input, 4, 5, 0)); // 001<00101>1001 --> 001<00000>1001
- assertEquals(521, BitUtils.replaceBits(input, 4, 5, 0)); // 001<00101>1001 --> 001<00000>1001
- assertEquals(585, BitUtils.replaceBits(input, 4, 5, 4)); // 001<00101>1001 --> 001<00100>1001
- assertEquals(1017, BitUtils.replaceBits(input, 4, 5, 31)); // 001<00101>1001 --> 001<11111>1001
-
- /* Decimal -601. */
- input = 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1101_1010_0111L;
- assertEquals(-1017, BitUtils.replaceBits(input, 4, 5, 0)); // ...1110<11010>0111 --> ...110<00000>0111
-
- input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
- patch = 0b1111_1111L;
- expected = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1111_1111L;
- assertEquals(expected, BitUtils.replaceBits(input, 0, 8, patch));
-
- input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
- patch = 0b1111_1111;
- expected = 0b0000_0000_0000_0000_0000_0000_1111_1111_0000_0000_0000_0000_0000_0000_0000_0000L;
- assertEquals(expected, BitUtils.replaceBits(input, 32, 8, patch));
-
- input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
- patch = 0b1111_1111;
- expected = 0b1111_1111_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
- assertEquals(expected, BitUtils.replaceBits(input, 56, 8, patch));
-
- /* Test some qtyBits of zero, which should always return the input value. */
- assertEquals(Long.MIN_VALUE, BitUtils.replaceBits(Long.MIN_VALUE, 0, 0, 1400));
- assertEquals(Long.MIN_VALUE, BitUtils.replaceBits(Long.MIN_VALUE, 63, 0, 1400));
- assertEquals(0, BitUtils.replaceBits(0, 0, 0, 1400));
- assertEquals(0, BitUtils.replaceBits(0, 63, 0, 1400));
- assertEquals(1, BitUtils.replaceBits(1, 0, 0, 1400));
- assertEquals(1, BitUtils.replaceBits(1, 63, 0, 1400));
- assertEquals(601, BitUtils.replaceBits(601, 8, 0, 1400));
- assertEquals(601, BitUtils.replaceBits(601, 8, 0, 1400));
- assertEquals(Long.MAX_VALUE, BitUtils.replaceBits(Long.MAX_VALUE, 0, 0, 1400));
- assertEquals(Long.MAX_VALUE, BitUtils.replaceBits(Long.MAX_VALUE, 63, 0, 1400));
-
- /* Wipe out all bits. */
- assertEquals(0, BitUtils.replaceBits(Long.MIN_VALUE, 0, 64, 0));
-
- /* Set all bits to true. */
- assertEquals(Long.MIN_VALUE, BitUtils.replaceBits(0, 0, 64, Long.MIN_VALUE));
- }
-
}
Modified: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java 2025-04-19 23:11:05 UTC (rev 13444)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java 2025-04-19 23:49:48 UTC (rev 13445)
@@ -28,7 +28,7 @@
package org.foray.common.data;
-import org.foray.primitive.BitUtils;
+import org.foray.primitive.attic.BitUtils;
import org.foray.primitive.sequence.LongArrayBuilder;
/**
Added: trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/BitUtils.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/BitUtils.java (rev 0)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/BitUtils.java 2025-04-19 23:49:48 UTC (rev 13445)
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2006 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.primitive.attic;
+
+/**
+ * Utility class containing numeric routines, especially bit operators.
+ */
+public final class BitUtils {
+
+ /**
+ * Private constructor. This is a utility class.
+ */
+ private BitUtils() { }
+
+ /**
+ * Extracts a range of bits from a long and returns the value as a long.
+ * @param input The long containing the bits to be extracted.
+ * @param position The position in {@code input} at which the bits should be extracted.
+ * Position 0 is the low-order bit, position 63 is the high-order bit.
+ * Values outside of that range will produce undefined results.
+ * @param qtyBits The number of bits that should be extracted.
+ * Values outside of 0 inclusive through 64 inclusive will produce undefined results.
+ * @return The extracted value.
+ */
+ public static long extractBits(final long input, final int position, final int qtyBits) {
+ final long rightShifted = input >>> position;
+ long mask = -1;
+ if (qtyBits < Long.SIZE) {
+ mask = (1L << qtyBits) - 1L;
+ }
+ return rightShifted & mask;
+ }
+
+ /**
+ * Replaces a range of bits in a long with a new value.
+ * @param input The long containing the bits to be replaced.
+ * @param position The position in {@code input} at which the bits should be replaced.
+ * Position 0 is the low-order bit, position 63 is the high-order bit.
+ * Values outside of that range will produce undefined results.
+ * @param qtyBits The number of bits that should be replaced.
+ * Values outside of 0 inclusive through 64 inclusive will produce undefined results.
+ * @param newValue The value of the bits that will replace the existing bits.
+ * @return The new value.
+ */
+ public static long replaceBits(final long input, final int position, final int qtyBits, final long newValue) {
+ if (qtyBits < 1) {
+ return input;
+ }
+ long leftBits = extractBits(input, position + qtyBits, Long.SIZE - qtyBits);
+ leftBits = leftBits << (position + qtyBits);
+ final long rightBits = extractBits(input, 0, position);
+ /* Strip off any high-order bits that exceed the qtyBits. */
+ long middleBits = newValue << (Long.SIZE - qtyBits);
+ middleBits = middleBits >>> (Long.SIZE - qtyBits);
+ middleBits = middleBits << position;
+ return leftBits | middleBits | rightBits;
+ }
+
+}
Property changes on: trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/BitUtils.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/package-info.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/package-info.java (rev 0)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/package-info.java 2025-04-19 23:49:48 UTC (rev 13445)
@@ -0,0 +1,32 @@
+/*
+ * 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$
+ */
+
+/**
+ * Primitive attic code.
+ */
+package org.foray.primitive.attic;
Property changes on: trunk/foray/foray-zz-attic/src/main/java/org/foray/primitive/attic/package-info.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Added: trunk/foray/foray-zz-attic/src/test/java/org/foray/primitive/attic/BitUtilsTests.java
===================================================================
--- trunk/foray/foray-zz-attic/src/test/java/org/foray/primitive/attic/BitUtilsTests.java (rev 0)
+++ trunk/foray/foray-zz-attic/src/test/java/org/foray/primitive/attic/BitUtilsTests.java 2025-04-19 23:49:48 UTC (rev 13445)
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2008 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.primitive.attic;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
+/**
+ * JUnit test class for the class {@link BitUtils}.
+ */
+public class BitUtilsTests {
+
+ /**
+ * Test of {@link BitUtils#extractBits(long, int, int)}.
+ */
+ @Test
+ public void testExtractBits() {
+ /* Decimal 601. */
+ long input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0010_0101_1001L;
+ assertEquals(1, BitUtils.extractBits(input, 4, 1)); // ...0010010[1]1001
+ assertEquals(1, BitUtils.extractBits(input, 4, 2)); // ...001001[01]1001
+ assertEquals(5, BitUtils.extractBits(input, 4, 3)); // ...00100[101]1001
+ assertEquals(5, BitUtils.extractBits(input, 4, 4)); // ...0010[0101]1001
+ assertEquals(5, BitUtils.extractBits(input, 4, 5)); // ...001[00101]1001
+ assertEquals(37, BitUtils.extractBits(input, 4, 6)); // ...00[100101]1001
+ assertEquals(1, BitUtils.extractBits(input, 0, 1)); // ...00100101100[1]
+ assertEquals(1, BitUtils.extractBits(input, 0, 2)); // ...0010010110[01]
+ assertEquals(1, BitUtils.extractBits(input, 0, 3)); // ...001001011[001]
+ assertEquals(9, BitUtils.extractBits(input, 0, 4)); // ...00100101[1001]
+ assertEquals(25, BitUtils.extractBits(input, 0, 5)); // ...0010010[11001]
+
+ /* Decimal -601. */
+ input = 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1101_1010_0111L;
+ assertEquals(0, BitUtils.extractBits(input, 4, 1)); // ...1101101[0]0111
+ assertEquals(2, BitUtils.extractBits(input, 4, 2)); // ...110110[10]0111
+ assertEquals(2, BitUtils.extractBits(input, 4, 3)); // ...11011[010]0111
+ assertEquals(10, BitUtils.extractBits(input, 4, 4)); // ...1101[1010]0111
+ assertEquals(26, BitUtils.extractBits(input, 4, 5)); // ...110[11010]0111
+ assertEquals(26, BitUtils.extractBits(input, 4, 6)); // ...11[011010]0111
+ assertEquals(7, BitUtils.extractBits(input, 31, 3));
+ /* The low-order 63 bits, decimal 9,223,372,036,854,775,207. */
+ long expected = 0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1101_1010_0111L;
+ assertEquals(expected, BitUtils.extractBits(input, 0, 63));
+ /* The high-order 63 bits, decimal 9,223,372,036,854,775,507. */
+ expected = 0b111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1110_1101_0011L;
+ assertEquals(expected, BitUtils.extractBits(input, 1, 63));
+
+ /* Decimal 7,243,477,050,672,021,504. Binary . */
+ input = 0b0110_0100_1000_0110_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
+ assertEquals(0, BitUtils.extractBits(input, 63, 1)); // [0]110010010000110...
+ assertEquals(1, BitUtils.extractBits(input, 62, 2)); // [01]10010010000110...
+ assertEquals(3, BitUtils.extractBits(input, 61, 3)); // [011]0010010000110...
+ assertEquals(6, BitUtils.extractBits(input, 60, 4)); // [0110]010010000110...
+ assertEquals(12, BitUtils.extractBits(input, 59, 5)); // [01100]10010000110...
+ assertEquals(25, BitUtils.extractBits(input, 58, 6)); // [011001]0010000110...
+
+ /* Test some qtyBits of zero, which should always return 0. */
+ assertEquals(0, BitUtils.extractBits(Long.MIN_VALUE, 0, 0));
+ assertEquals(0, BitUtils.extractBits(Long.MIN_VALUE, 63, 0));
+ assertEquals(0, BitUtils.extractBits(0, 0, 0));
+ assertEquals(0, BitUtils.extractBits(0, 63, 0));
+ assertEquals(0, BitUtils.extractBits(1, 0, 0));
+ assertEquals(0, BitUtils.extractBits(1, 63, 0));
+ assertEquals(0, BitUtils.extractBits(601, 8, 0));
+ assertEquals(0, BitUtils.extractBits(601, 8, 0));
+ assertEquals(0, BitUtils.extractBits(Long.MAX_VALUE, 0, 0));
+ assertEquals(0, BitUtils.extractBits(Long.MAX_VALUE, 63, 0));
+
+ /* Test some position 0, qtyBits 64, which should always return the input. */
+ assertEquals(Long.MIN_VALUE, BitUtils.extractBits(Long.MIN_VALUE, 0, 64));
+ assertEquals(-601, BitUtils.extractBits(-601, 0, 64));
+ assertEquals(-1, BitUtils.extractBits(-1, 0, 64));
+ assertEquals(0, BitUtils.extractBits(0, 0, 64));
+ assertEquals(1, BitUtils.extractBits(1, 0, 64));
+ assertEquals(601, BitUtils.extractBits(601, 0, 64));
+ assertEquals(Long.MAX_VALUE, BitUtils.extractBits(Long.MAX_VALUE, 0, 64));
+
+ /* Test some invalid position values. */
+ assertEquals(0, BitUtils.extractBits(1, -600, 3));
+ assertEquals(0, BitUtils.extractBits(1, -1, 3));
+ assertEquals(1, BitUtils.extractBits(1, 64, 3));
+ assertEquals(1, BitUtils.extractBits(1, 128, 3));
+
+ /* Test some invalid qtyBits values. */
+ assertEquals(0, BitUtils.extractBits(1, 1, -600));
+ assertEquals(0, BitUtils.extractBits(1, 1, -1));
+ assertEquals(0, BitUtils.extractBits(1, 1, 65));
+ assertEquals(0, BitUtils.extractBits(1, 1, 128));
+ }
+
+ /**
+ * Test of {@link BitUtils#replaceBits(long, int, int, long)}.
+ */
+ @Test
+ public void testReplaceBits() {
+ long input;
+ long patch;
+ long expected;
+
+ /* Decimal 601. */
+ input = 0b0010_0101_1001;
+ assertEquals(521, BitUtils.replaceBits(input, 4, 5, 0)); // 001<00101>1001 --> 001<00000>1001
+ assertEquals(521, BitUtils.replaceBits(input, 4, 5, 0)); // 001<00101>1001 --> 001<00000>1001
+ assertEquals(585, BitUtils.replaceBits(input, 4, 5, 4)); // 001<00101>1001 --> 001<00100>1001
+ assertEquals(1017, BitUtils.replaceBits(input, 4, 5, 31)); // 001<00101>1001 --> 001<11111>1001
+
+ /* Decimal -601. */
+ input = 0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1101_1010_0111L;
+ assertEquals(-1017, BitUtils.replaceBits(input, 4, 5, 0)); // ...1110<11010>0111 --> ...110<00000>0111
+
+ input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
+ patch = 0b1111_1111L;
+ expected = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1111_1111L;
+ assertEquals(expected, BitUtils.replaceBits(input, 0, 8, patch));
+
+ input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
+ patch = 0b1111_1111;
+ expected = 0b0000_0000_0000_0000_0000_0000_1111_1111_0000_0000_0000_0000_0000_0000_0000_0000L;
+ assertEquals(expected, BitUtils.replaceBits(input, 32, 8, patch));
+
+ input = 0b0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
+ patch = 0b1111_1111;
+ expected = 0b1111_1111_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000L;
+ assertEquals(expected, BitUtils.replaceBits(input, 56, 8, patch));
+
+ /* Test some qtyBits of zero, which should always return the input value. */
+ assertEquals(Long.MIN_VALUE, BitUtils.replaceBits(Long.MIN_VALUE, 0, 0, 1400));
+ assertEquals(Long.MIN_VALUE, BitUtils.replaceBits(Long.MIN_VALUE, 63, 0, 1400));
+ assertEquals(0, BitUtils.replaceBits(0, 0, 0, 1400));
+ assertEquals(0, BitUtils.replaceBits(0, 63, 0, 1400));
+ assertEquals(1, BitUtils.replaceBits(1, 0, 0, 1400));
+ assertEquals(1, BitUtils.replaceBits(1, 63, 0, 1400));
+ assertEquals(601, BitUtils.replaceBits(601, 8, 0, 1400));
+ assertEquals(601, BitUtils.replaceBits(601, 8, 0, 1400));
+ assertEquals(Long.MAX_VALUE, BitUtils.replaceBits(Long.MAX_VALUE, 0, 0, 1400));
+ assertEquals(Long.MAX_VALUE, BitUtils.replaceBits(Long.MAX_VALUE, 63, 0, 1400));
+
+ /* Wipe out all bits. */
+ assertEquals(0, BitUtils.replaceBits(Long.MIN_VALUE, 0, 64, 0));
+
+ /* Set all bits to true. */
+ assertEquals(Long.MIN_VALUE, BitUtils.replaceBits(0, 0, 64, Long.MIN_VALUE));
+ }
+
+}
Property changes on: trunk/foray/foray-zz-attic/src/test/java/org/foray/primitive/attic/BitUtilsTests.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-04-19 23:11:23
|
Revision: 13444
http://sourceforge.net/p/foray/code/13444
Author: victormote
Date: 2025-04-19 23:11:05 +0000 (Sat, 19 Apr 2025)
Log Message:
-----------
Move unneeded but interesting class to the attic.
Added Paths:
-----------
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/package-info.java
trunk/foray/foray-zz-attic/src/test/java/org/foray/common/
trunk/foray/foray-zz-attic/src/test/java/org/foray/common/data/
trunk/foray/foray-zz-attic/src/test/java/org/foray/common/data/PackedIntArrayTests.java
Removed Paths:
-------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/PackedIntArrayTests.java
Deleted: trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java 2025-04-19 18:48:19 UTC (rev 13443)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java 2025-04-19 23:11:05 UTC (rev 13444)
@@ -1,152 +0,0 @@
-/*
- * Copyright 2019 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.common.data;
-
-import org.foray.primitive.BitUtils;
-import org.foray.primitive.sequence.LongArrayBuilder;
-
-/**
- * Packs an array of integers into less space by knowing the maximum number of bits that are needed to represent them,
- * and using only that number to do so.
- */
-public class PackedIntArray {
-
- /** The internal array. */
- private LongArrayBuilder internalArray = new LongArrayBuilder();
-
- /** The number of bits needed to store one packed item. */
- private int qtyBits;
-
- /**
- * Constructor.
- * @param qtyBits The number of bits assigned to each item in the virtual array.
- */
- public PackedIntArray(final int qtyBits) {
- this.qtyBits = qtyBits;
- }
-
- /**
- * Stores (writes) a value into the virtual array.
- * @param index The index into the virtual array of the item to be stored.
- * @param value The value to be stored at {@code index}.
- */
- public void put(final int index, final int value) {
- final int startingElement = startingElement(index);
- final int startingBit = startingBit(index);
- this.internalArray.ensureCapacity(startingElement + 1);
- while (this.internalArray.length() < startingElement + 2) {
- this.internalArray.append(0);
- }
- final long oldInternal1 = this.internalArray.longAt(startingElement);
- if (startingBit + this.qtyBits < Long.SIZE) {
- /* Everything fits in the starting element. */
- final long newLong = BitUtils.replaceBits(oldInternal1, startingBit, this.qtyBits, value);
- internalArray.setLongAt(startingElement, newLong);
- } else {
- /* The virtual element straddles two physical elements. */
- final long oldInternal2 = this.internalArray.longAt(startingElement + 1);
- final int length1 = Long.SIZE - startingBit;
- final int length2 = this.qtyBits - length1;
-
- /* Extract the low-order bits from value and put them in the high-order bits of
- * the low-order long. */
- final long newValue1 = BitUtils.extractBits(value, 0, length1);
- final long newInternal1 = BitUtils.replaceBits(oldInternal1, Long.SIZE - length1, length1, newValue1);
-
- /* Extract the high-order bits from value and put them in the low-order bits of
- * the high-order long. */
- final long newValue2 = BitUtils.extractBits(value, length1, Long.SIZE - length1);
- final long newInternal2 = BitUtils.replaceBits(oldInternal2, 0, length2, newValue2);
-
- internalArray.setLongAt(startingElement, newInternal1);
- internalArray.setLongAt(startingElement + 1, newInternal2);
- }
- }
-
- /**
- * Returns the value of an item in the virtual array.
- * @param index The index into the virtual array of the item to be retrieved.
- * @return The value stored at {@code index}.
- */
- public int get(final int index) {
- final int startingElement = startingElement(index);
- final int startingBit = startingBit(index);
- final long internal1 = this.internalArray.longAt(startingElement);
- if (startingBit + this.qtyBits < Long.SIZE) {
- /* Everything fits in the starting element. */
- final long extracted = BitUtils.extractBits(internal1, startingBit, this.qtyBits);
- return (int) extracted;
- } else {
- /* The virtual element straddles two physical elements. */
- final long internal2 = this.internalArray.longAt(startingElement + 1);
- final int length1 = Long.SIZE - startingBit;
- final int length2 = this.qtyBits - length1;
- final long part1 = (int) BitUtils.extractBits(internal1, startingBit, length1);
- long part2 = (int) BitUtils.extractBits(internal2, 0, length2);
- part2 = part2 << length1;
-// long returnValue = part1;
-// returnValue = BitUtils.replaceBits(returnValue, length1, length2, part2);
-// return (int) returnValue;
- return (int) (part1 | part2);
- }
- }
-
- /**
- * For a given index into the virtual array, computes the index into the real array at which the value of that
- * element is stored.
- * @param index The index into the virtual array.
- * @return The index into the real array at which the first bit of the value of {@code index} is stored.
- */
- int startingElement(final long index) {
- final long totalBits = index * (long) this.qtyBits;
- return (int) (totalBits / Long.SIZE);
- }
-
- /**
- * For a given index into the virtual array, computes the first bit in the first index into the real array at which
- * the value of that element is stored.
- * @param index The index into the virtual array.
- * @return The first bit of the first index in the real array at which the first bit of the value of {@code index}
- * is stored.
- */
- int startingBit(final long index) {
- final long totalBits = index * (long) this.qtyBits;
- return (int) (totalBits % Long.SIZE);
- }
-
- /**
- * Returns the length of the internal array.
- * This is useful mostly for testing.
- * @return The length of the internal array.
- */
- public int internalLength() {
- return this.internalArray.length();
- }
-
-}
Deleted: trunk/foray/foray-common/src/test/java/org/foray/common/data/PackedIntArrayTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/PackedIntArrayTests.java 2025-04-19 18:48:19 UTC (rev 13443)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/PackedIntArrayTests.java 2025-04-19 23:11:05 UTC (rev 13444)
@@ -1,154 +0,0 @@
-/*
- * Copyright 2019 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.common.data;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.jupiter.api.Test;
-
-import java.math.BigInteger;
-
-/**
- * Tests of {@link PackedIntArray}.
- */
-public class PackedIntArrayTests {
-
- /**
- * Makes assertions about computations in the packed array.
- * @param out The object under test, a {@link PackedIntArray}.
- * @param virtualIndex The virtual index of the item being tested.
- * @param startingIndex The index into the first actual array element containing the value of {@code virtualIndex}.
- * @param startingBit The first bit in {@code startingIndex} for the value of {@code virtualIndex}.
- */
- private void assertLocation(final PackedIntArray out, final int virtualIndex, final int startingIndex,
- final int startingBit) {
- assertEquals(startingIndex, out.startingElement(virtualIndex));
- assertEquals(startingBit, out.startingBit(virtualIndex));
- }
-
- /**
- * Test of {@link PackedIntArray#startingElement(int)}.
- */
- @Test
- public void testOfStartingElement() {
-
- /* Size of 16 bits. Test lower range. */
- PackedIntArray out = new PackedIntArray(16);
- assertLocation(out, 0, 0, 0);
- assertLocation(out, 1, 0, 16);
- assertLocation(out, 2, 0, 32);
- assertLocation(out, 3, 0, 48);
- assertLocation(out, 4, 1, 0);
- assertLocation(out, 5, 1, 16);
- assertLocation(out, 6, 1, 32);
- assertLocation(out, 7, 1, 48);
- assertLocation(out, 8, 2, 0);
- assertLocation(out, 9, 2, 16);
-
- /* Size of 16 bits. Test upper range.
- * We can fit 4 16-bit values into one 64-bit long. Therefore, the number of longs needed to hold the entire
- * range of int values is 1/4 of the maximum value of an integer = 536,870,912. */
- assertLocation(out, Integer.MAX_VALUE - 7, 536870910, 0);
- assertLocation(out, Integer.MAX_VALUE - 6, 536870910, 16);
- assertLocation(out, Integer.MAX_VALUE - 5, 536870910, 32);
- assertLocation(out, Integer.MAX_VALUE - 4, 536870910, 48);
- assertLocation(out, Integer.MAX_VALUE - 3, 536870911, 0);
- assertLocation(out, Integer.MAX_VALUE - 2, 536870911, 16);
- assertLocation(out, Integer.MAX_VALUE - 1, 536870911, 32);
- assertLocation(out, Integer.MAX_VALUE, 536870911, 48);
-
- /* Size of 15 bits. Test lower range. */
- out = new PackedIntArray(15);
- assertLocation(out, 0, 0, 0);
- assertLocation(out, 1, 0, 15);
- assertLocation(out, 2, 0, 30);
- assertLocation(out, 3, 0, 45);
- assertLocation(out, 4, 0, 60);
- assertLocation(out, 5, 1, 11);
- assertLocation(out, 6, 1, 26);
- assertLocation(out, 7, 1, 41);
- assertLocation(out, 8, 1, 56);
- assertLocation(out, 9, 2, 7);
-
- /* Size of 15 bits. Test upper range.
- * We can fit 4 16-bit values into one 64-bit long. Therefore, the number of longs needed to hold the entire
- * range of int values is 1/4 of the maximum value of an integer * 15/16 = 503,316,480. */
- assertLocation(out, Integer.MAX_VALUE - 7, 503316478, 8);
- assertLocation(out, Integer.MAX_VALUE - 6, 503316478, 23);
- assertLocation(out, Integer.MAX_VALUE - 5, 503316478, 38);
- assertLocation(out, Integer.MAX_VALUE - 4, 503316478, 53);
- assertLocation(out, Integer.MAX_VALUE - 3, 503316479, 4);
- assertLocation(out, Integer.MAX_VALUE - 2, 503316479, 19);
- assertLocation(out, Integer.MAX_VALUE - 1, 503316479, 34);
- assertLocation(out, Integer.MAX_VALUE, 503316479, 49);
-
- /* Size of 17 bits. Test lower range. */
- out = new PackedIntArray(17);
- assertLocation(out, 0, 0, 0);
- assertLocation(out, 1, 0, 17);
- assertLocation(out, 2, 0, 34);
- assertLocation(out, 3, 0, 51);
- assertLocation(out, 4, 1, 4);
- assertLocation(out, 5, 1, 21);
- assertLocation(out, 6, 1, 38);
- assertLocation(out, 7, 1, 55);
- assertLocation(out, 8, 2, 8);
- assertLocation(out, 9, 2, 25);
-
- /* Size of 17 bits. Test upper range.
- * We can fit 4 16-bit values into one 64-bit long. Therefore, the number of longs needed to hold the entire
- * range of int values is 1/4 of the maximum value of an integer * 17/16 = 570,425,344. */
- assertLocation(out, Integer.MAX_VALUE - 7, 570425341, 56);
- assertLocation(out, Integer.MAX_VALUE - 6, 570425342, 9);
- assertLocation(out, Integer.MAX_VALUE - 5, 570425342, 26);
- assertLocation(out, Integer.MAX_VALUE - 4, 570425342, 43);
- assertLocation(out, Integer.MAX_VALUE - 3, 570425342, 60);
- assertLocation(out, Integer.MAX_VALUE - 2, 570425343, 13);
- assertLocation(out, Integer.MAX_VALUE - 1, 570425343, 30);
- assertLocation(out, Integer.MAX_VALUE, 570425343, 47);
- }
-
- /**
- * Test using a bit size of 13.
- */
- @Test
- public void testOf13s() {
- final PackedIntArray out = new PackedIntArray(13);
- /* Test putting the maximum number of 13-bit values in the array. */
- final int maxIndex = BigInteger.valueOf(2).pow(13).intValue() - 1;
- assertEquals(8191, maxIndex);
- for (int index = 0; index < maxIndex; index ++) {
- out.put(index, index);
- }
- for (int index = 0; index < maxIndex; index ++) {
- final int value = out.get(index);
- assertEquals(index, value);
- }
- }
-
-}
Copied: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java (from rev 13431, trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java)
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java (rev 0)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/PackedIntArray.java 2025-04-19 23:11:05 UTC (rev 13444)
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2019 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.common.data;
+
+import org.foray.primitive.BitUtils;
+import org.foray.primitive.sequence.LongArrayBuilder;
+
+/**
+ * Packs an array of integers into less space by knowing the maximum number of bits that are needed to represent them,
+ * and using only that number to do so.
+ */
+public class PackedIntArray {
+
+ /** The internal array. */
+ private LongArrayBuilder internalArray = new LongArrayBuilder();
+
+ /** The number of bits needed to store one packed item. */
+ private int qtyBits;
+
+ /**
+ * Constructor.
+ * @param qtyBits The number of bits assigned to each item in the virtual array.
+ */
+ public PackedIntArray(final int qtyBits) {
+ this.qtyBits = qtyBits;
+ }
+
+ /**
+ * Stores (writes) a value into the virtual array.
+ * @param index The index into the virtual array of the item to be stored.
+ * @param value The value to be stored at {@code index}.
+ */
+ public void put(final int index, final int value) {
+ final int startingElement = startingElement(index);
+ final int startingBit = startingBit(index);
+ this.internalArray.ensureCapacity(startingElement + 1);
+ while (this.internalArray.length() < startingElement + 2) {
+ this.internalArray.append(0);
+ }
+ final long oldInternal1 = this.internalArray.longAt(startingElement);
+ if (startingBit + this.qtyBits < Long.SIZE) {
+ /* Everything fits in the starting element. */
+ final long newLong = BitUtils.replaceBits(oldInternal1, startingBit, this.qtyBits, value);
+ internalArray.setLongAt(startingElement, newLong);
+ } else {
+ /* The virtual element straddles two physical elements. */
+ final long oldInternal2 = this.internalArray.longAt(startingElement + 1);
+ final int length1 = Long.SIZE - startingBit;
+ final int length2 = this.qtyBits - length1;
+
+ /* Extract the low-order bits from value and put them in the high-order bits of
+ * the low-order long. */
+ final long newValue1 = BitUtils.extractBits(value, 0, length1);
+ final long newInternal1 = BitUtils.replaceBits(oldInternal1, Long.SIZE - length1, length1, newValue1);
+
+ /* Extract the high-order bits from value and put them in the low-order bits of
+ * the high-order long. */
+ final long newValue2 = BitUtils.extractBits(value, length1, Long.SIZE - length1);
+ final long newInternal2 = BitUtils.replaceBits(oldInternal2, 0, length2, newValue2);
+
+ internalArray.setLongAt(startingElement, newInternal1);
+ internalArray.setLongAt(startingElement + 1, newInternal2);
+ }
+ }
+
+ /**
+ * Returns the value of an item in the virtual array.
+ * @param index The index into the virtual array of the item to be retrieved.
+ * @return The value stored at {@code index}.
+ */
+ public int get(final int index) {
+ final int startingElement = startingElement(index);
+ final int startingBit = startingBit(index);
+ final long internal1 = this.internalArray.longAt(startingElement);
+ if (startingBit + this.qtyBits < Long.SIZE) {
+ /* Everything fits in the starting element. */
+ final long extracted = BitUtils.extractBits(internal1, startingBit, this.qtyBits);
+ return (int) extracted;
+ } else {
+ /* The virtual element straddles two physical elements. */
+ final long internal2 = this.internalArray.longAt(startingElement + 1);
+ final int length1 = Long.SIZE - startingBit;
+ final int length2 = this.qtyBits - length1;
+ final long part1 = (int) BitUtils.extractBits(internal1, startingBit, length1);
+ long part2 = (int) BitUtils.extractBits(internal2, 0, length2);
+ part2 = part2 << length1;
+// long returnValue = part1;
+// returnValue = BitUtils.replaceBits(returnValue, length1, length2, part2);
+// return (int) returnValue;
+ return (int) (part1 | part2);
+ }
+ }
+
+ /**
+ * For a given index into the virtual array, computes the index into the real array at which the value of that
+ * element is stored.
+ * @param index The index into the virtual array.
+ * @return The index into the real array at which the first bit of the value of {@code index} is stored.
+ */
+ int startingElement(final long index) {
+ final long totalBits = index * (long) this.qtyBits;
+ return (int) (totalBits / Long.SIZE);
+ }
+
+ /**
+ * For a given index into the virtual array, computes the first bit in the first index into the real array at which
+ * the value of that element is stored.
+ * @param index The index into the virtual array.
+ * @return The first bit of the first index in the real array at which the first bit of the value of {@code index}
+ * is stored.
+ */
+ int startingBit(final long index) {
+ final long totalBits = index * (long) this.qtyBits;
+ return (int) (totalBits % Long.SIZE);
+ }
+
+ /**
+ * Returns the length of the internal array.
+ * This is useful mostly for testing.
+ * @return The length of the internal array.
+ */
+ public int internalLength() {
+ return this.internalArray.length();
+ }
+
+}
Added: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/package-info.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/package-info.java (rev 0)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/package-info.java 2025-04-19 23:11:05 UTC (rev 13444)
@@ -0,0 +1,32 @@
+/*
+ * 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$
+ */
+
+/**
+ * Common data code for the attic.
+ */
+package org.foray.common.data;
Property changes on: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/data/package-info.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Copied: trunk/foray/foray-zz-attic/src/test/java/org/foray/common/data/PackedIntArrayTests.java (from rev 13431, trunk/foray/foray-common/src/test/java/org/foray/common/data/PackedIntArrayTests.java)
===================================================================
--- trunk/foray/foray-zz-attic/src/test/java/org/foray/common/data/PackedIntArrayTests.java (rev 0)
+++ trunk/foray/foray-zz-attic/src/test/java/org/foray/common/data/PackedIntArrayTests.java 2025-04-19 23:11:05 UTC (rev 13444)
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2019 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.common.data;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
+import java.math.BigInteger;
+
+/**
+ * Tests of {@link PackedIntArray}.
+ */
+public class PackedIntArrayTests {
+
+ /**
+ * Makes assertions about computations in the packed array.
+ * @param out The object under test, a {@link PackedIntArray}.
+ * @param virtualIndex The virtual index of the item being tested.
+ * @param startingIndex The index into the first actual array element containing the value of {@code virtualIndex}.
+ * @param startingBit The first bit in {@code startingIndex} for the value of {@code virtualIndex}.
+ */
+ private void assertLocation(final PackedIntArray out, final int virtualIndex, final int startingIndex,
+ final int startingBit) {
+ assertEquals(startingIndex, out.startingElement(virtualIndex));
+ assertEquals(startingBit, out.startingBit(virtualIndex));
+ }
+
+ /**
+ * Test of {@link PackedIntArray#startingElement(int)}.
+ */
+ @Test
+ public void testOfStartingElement() {
+
+ /* Size of 16 bits. Test lower range. */
+ PackedIntArray out = new PackedIntArray(16);
+ assertLocation(out, 0, 0, 0);
+ assertLocation(out, 1, 0, 16);
+ assertLocation(out, 2, 0, 32);
+ assertLocation(out, 3, 0, 48);
+ assertLocation(out, 4, 1, 0);
+ assertLocation(out, 5, 1, 16);
+ assertLocation(out, 6, 1, 32);
+ assertLocation(out, 7, 1, 48);
+ assertLocation(out, 8, 2, 0);
+ assertLocation(out, 9, 2, 16);
+
+ /* Size of 16 bits. Test upper range.
+ * We can fit 4 16-bit values into one 64-bit long. Therefore, the number of longs needed to hold the entire
+ * range of int values is 1/4 of the maximum value of an integer = 536,870,912. */
+ assertLocation(out, Integer.MAX_VALUE - 7, 536870910, 0);
+ assertLocation(out, Integer.MAX_VALUE - 6, 536870910, 16);
+ assertLocation(out, Integer.MAX_VALUE - 5, 536870910, 32);
+ assertLocation(out, Integer.MAX_VALUE - 4, 536870910, 48);
+ assertLocation(out, Integer.MAX_VALUE - 3, 536870911, 0);
+ assertLocation(out, Integer.MAX_VALUE - 2, 536870911, 16);
+ assertLocation(out, Integer.MAX_VALUE - 1, 536870911, 32);
+ assertLocation(out, Integer.MAX_VALUE, 536870911, 48);
+
+ /* Size of 15 bits. Test lower range. */
+ out = new PackedIntArray(15);
+ assertLocation(out, 0, 0, 0);
+ assertLocation(out, 1, 0, 15);
+ assertLocation(out, 2, 0, 30);
+ assertLocation(out, 3, 0, 45);
+ assertLocation(out, 4, 0, 60);
+ assertLocation(out, 5, 1, 11);
+ assertLocation(out, 6, 1, 26);
+ assertLocation(out, 7, 1, 41);
+ assertLocation(out, 8, 1, 56);
+ assertLocation(out, 9, 2, 7);
+
+ /* Size of 15 bits. Test upper range.
+ * We can fit 4 16-bit values into one 64-bit long. Therefore, the number of longs needed to hold the entire
+ * range of int values is 1/4 of the maximum value of an integer * 15/16 = 503,316,480. */
+ assertLocation(out, Integer.MAX_VALUE - 7, 503316478, 8);
+ assertLocation(out, Integer.MAX_VALUE - 6, 503316478, 23);
+ assertLocation(out, Integer.MAX_VALUE - 5, 503316478, 38);
+ assertLocation(out, Integer.MAX_VALUE - 4, 503316478, 53);
+ assertLocation(out, Integer.MAX_VALUE - 3, 503316479, 4);
+ assertLocation(out, Integer.MAX_VALUE - 2, 503316479, 19);
+ assertLocation(out, Integer.MAX_VALUE - 1, 503316479, 34);
+ assertLocation(out, Integer.MAX_VALUE, 503316479, 49);
+
+ /* Size of 17 bits. Test lower range. */
+ out = new PackedIntArray(17);
+ assertLocation(out, 0, 0, 0);
+ assertLocation(out, 1, 0, 17);
+ assertLocation(out, 2, 0, 34);
+ assertLocation(out, 3, 0, 51);
+ assertLocation(out, 4, 1, 4);
+ assertLocation(out, 5, 1, 21);
+ assertLocation(out, 6, 1, 38);
+ assertLocation(out, 7, 1, 55);
+ assertLocation(out, 8, 2, 8);
+ assertLocation(out, 9, 2, 25);
+
+ /* Size of 17 bits. Test upper range.
+ * We can fit 4 16-bit values into one 64-bit long. Therefore, the number of longs needed to hold the entire
+ * range of int values is 1/4 of the maximum value of an integer * 17/16 = 570,425,344. */
+ assertLocation(out, Integer.MAX_VALUE - 7, 570425341, 56);
+ assertLocation(out, Integer.MAX_VALUE - 6, 570425342, 9);
+ assertLocation(out, Integer.MAX_VALUE - 5, 570425342, 26);
+ assertLocation(out, Integer.MAX_VALUE - 4, 570425342, 43);
+ assertLocation(out, Integer.MAX_VALUE - 3, 570425342, 60);
+ assertLocation(out, Integer.MAX_VALUE - 2, 570425343, 13);
+ assertLocation(out, Integer.MAX_VALUE - 1, 570425343, 30);
+ assertLocation(out, Integer.MAX_VALUE, 570425343, 47);
+ }
+
+ /**
+ * Test using a bit size of 13.
+ */
+ @Test
+ public void testOf13s() {
+ final PackedIntArray out = new PackedIntArray(13);
+ /* Test putting the maximum number of 13-bit values in the array. */
+ final int maxIndex = BigInteger.valueOf(2).pow(13).intValue() - 1;
+ assertEquals(8191, maxIndex);
+ for (int index = 0; index < maxIndex; index ++) {
+ out.put(index, index);
+ }
+ for (int index = 0; index < maxIndex; index ++) {
+ final int value = out.get(index);
+ assertEquals(index, value);
+ }
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-19 18:48:37
|
Revision: 13443
http://sourceforge.net/p/foray/code/13443
Author: victormote
Date: 2025-04-19 18:48:19 +0000 (Sat, 19 Apr 2025)
Log Message:
-----------
Panose improvements.
Modified Paths:
--------------
trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java
Modified: trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
===================================================================
--- trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-19 15:56:16 UTC (rev 13442)
+++ trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-19 18:48:19 UTC (rev 13443)
@@ -5,7 +5,6 @@
id 'checkstyle'
id 'maven-publish'
id "org.checkerframework"
-
}
@@ -210,5 +209,10 @@
options.deprecation = true
}
+checkerFramework {
+ checkers = [
+// "org.checkerframework.checker.signedness.SignednessChecker"
+ ]
+}
/* Last line of script. */
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java 2025-04-19 15:56:16 UTC (rev 13442)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java 2025-04-19 18:48:19 UTC (rev 13443)
@@ -37,24 +37,15 @@
/**
* A PANOSE-1 classification number.
*
- * <p>References:</p>
- * <ul>
- * <li><a href="http://fonts.apple.com/TTRefMan/RM06/Chap6OS2.html">The TTF OS/2 Table
- * doc</a></li>
- * <li><a href="http://www.w3.org/Fonts/Panose/pan2.html#StaticDigits">Panose 2.0 White
- * Paper</a></li>
- * <li><a href="http://www.byte.com/art/9405/sec12/art1.htm">The Panose Typeface-Matching
- * System</a></li>
- * <li>Michael S. De Laurentis, PANOSE 1.0 Core Mapper Services, Hewlett-Packard Document
- * EWC-93-0023b, Hewlett-Packard Corporation, 101 Stewart, Suite 700, Seattle, WA 98101 (1993).</li>
- * <li><a href="www.fonts.com/hp/panose/greybook">The "Grey Book"</a></li>
- * </ul>
+ * @see <a href="http://fonts.apple.com/TTRefMan/RM06/Chap6OS2.html">The TTF OS/2 Table doc</a>
+ * @see <a href="http://www.w3.org/Fonts/Panose/pan2.html#StaticDigits">Panose 2.0 White Paper</a>
+ * @see <a href="http://www.byte.com/art/9405/sec12/art1.htm">The Panose Typeface-Matching System</a>
+ * @see "Michael S. De Laurentis, PANOSE 1.0 Core Mapper Services, Hewlett-Packard Document EWC-93-0023b,
+ * Hewlett-Packard Corporation, 101 Stewart, Suite 700, Seattle, WA 98101 (1993)."
+ * @see <a href="www.fonts.com/hp/panose/greybook">The "Grey Book"</a>
*/
public final class Panose4a implements Panose {
- /** The quantity of element in a Panose 1.0 array. */
- private static final @Unsigned byte QTY_PANOSE_ELEMENTS = 10;
-
/**
* Enumeration of the fields that comprise a PANOSE description.
* @see "http://fonts.apple.com/TTRefMan/RM06/Chap6OS2.html"
@@ -61,34 +52,34 @@
*/
public enum Field {
/** The bFamilyType field. */
- FAMILY_TYPE((byte) 0, (byte) 5),
+ FAMILY_TYPE(0, 5),
/** The bSerifStyle field. */
- SERIF_STYLE((byte) 1, (byte) 15),
+ SERIF_STYLE(1, 15),
/** The bWeight field. */
- WEIGHT((byte) 2, (byte) 11),
+ WEIGHT(2, 11),
/** The bProportion field. */
- PROPORTION((byte) 3, (byte) 9),
+ PROPORTION(3, 9),
/** The bContrast field. */
- CONTRAST((byte) 4, (byte) 9),
+ CONTRAST(4, 9),
/** The bStrokeVariatoon field. */
- STROKE_VARIATION((byte) 5, (byte) 8),
+ STROKE_VARIATION(5, 8),
/** The bArmStyle field. */
- ARM_STYLE((byte) 6, (byte) 11),
+ ARM_STYLE(6, 11),
/** The bLetterform field. */
- LETTERFORM((byte) 7, (byte) 15),
+ LETTERFORM(7, 15),
/** The bMidline field. */
- MIDLINE((byte) 8, (byte) 13),
+ MIDLINE(8, 13),
/** The bXHeight field. */
- X_HEIGHT((byte) 9, (byte) 7);
+ X_HEIGHT(9, 7);
/** The 0-based index of this element in the PANOSE array. */
private @Unsigned byte index;
@@ -101,9 +92,9 @@
* @param index The 0-based index of this element in the PANOSE array.
* @param maxValue The maximum value that is permissible for this element.
*/
- Field(final byte index, final byte maxValue) {
- this.index = index;
- this.maxValue = maxValue;
+ Field(final int index, final int maxValue) {
+ this.index = (byte) index;
+ this.maxValue = (byte) maxValue;
}
/**
@@ -339,6 +330,20 @@
return toString(this.panoseArray);
}
+ @Override
+ public boolean equals(final Object other) {
+ if (! (other instanceof Panose)) {
+ return false;
+ }
+ final Panose otherPanose = (Panose) other;
+ for (int index = 0; index < Panose.QTY_PANOSE_ELEMENTS; index ++) {
+ if (this.getValueAt(index) != otherPanose.getValueAt(index)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
/**
* Returns a String representation of a Panose array.
* @param panoseArray The Panose array to be expressed as a String.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 15:56:16 UTC (rev 13442)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 18:48:19 UTC (rev 13443)
@@ -33,6 +33,8 @@
import org.foray.font.format.Panose4a;
import org.foray.font.format.ttf.parse.TtfTableOs2Parser;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
import java.io.IOException;
/**
@@ -176,7 +178,7 @@
@Override
public void objectField(final String fieldName, final Object value) {
switch (fieldName) {
- case "panose": this.panose = (Panose4a) value;
+ case "panose": this.panose = Panose4a.forceInstance((@Unsigned byte[]) value);
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 15:56:16 UTC (rev 13442)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 18:48:19 UTC (rev 13443)
@@ -76,7 +76,7 @@
for (int i = 0; i < panoseArray.length; i++) {
panoseArray[i] = input.read_uint8();
}
- consumer.objectField("panose", Panose4a.forceInstance(panoseArray));
+ consumer.objectField("panose", panoseArray);
consumer.primitiveField("ulUnicodeRange1", ferry.setLong(input.read_uint32())); // 4 bytes, total 46
consumer.primitiveField("ulUnicodeRange2", ferry.setLong(input.read_uint32())); // 4 bytes, total 50
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java 2025-04-19 15:56:16 UTC (rev 13442)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java 2025-04-19 18:48:19 UTC (rev 13443)
@@ -32,10 +32,14 @@
import org.foray.font.FontServer4a;
import org.foray.font.format.FontContent;
import org.foray.font.format.FontParser;
+import org.foray.font.format.Panose4a;
import org.axsl.font.FontException;
+import org.axsl.font.Panose;
import org.axsl.ps.BoundingBox;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -55,8 +59,9 @@
/**
* Make assertions about the data parsed from the DejaVu Sans Extra Light font.
* @param ttfFont The font instance to be tested.
+ * @throws FontException Not expected here.
*/
- public static void assertionsForDejaVuSansExtraLight(final TrueTypeFont ttfFont) {
+ public static void assertionsForDejaVuSansExtraLight(final TrueTypeFont ttfFont) throws FontException {
/* The following values were obtained by opening the TTF file in FontLab 8.4. */
final String expectedPostScriptName = "DejaVuSans-ExtraLight";
@@ -84,6 +89,9 @@
final BoundingBox expectedBBox = new BoundingBoxShort(-1501, -550, 3398, 2262);
/* Family dimensions / Units Per eM. */
final int expectedUnitsPerEm = 2048;
+ /* Overview / PANOSE */
+ final @Unsigned byte[] expectedPanoseArray = {2, 11, 2, 3, 3, 8, 4, 2, 2, 4};
+ final Panose expectedPanose = Panose4a.makeInstance(expectedPanoseArray);
assertEquals(expectedPostScriptName, ttfFont.getNameTable().getPostscriptName());
assertEquals(expectedFullName, ttfFont.getNameTable().getFullName());
@@ -96,6 +104,7 @@
assertEquals(expectedItalicAngle, ttfFont.getItalicAngle());
assertEquals(expectedBBox, ttfFont.getFontBBox());
assertEquals(expectedUnitsPerEm, ttfFont.getHeadTable().unitsPerEm());
+ assertEquals(expectedPanose, ttfFont.getOs2Table().getPanose());
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-19 15:56:34
|
Revision: 13442
http://sourceforge.net/p/foray/code/13442
Author: victormote
Date: 2025-04-19 15:56:16 +0000 (Sat, 19 Apr 2025)
Log Message:
-----------
Introduce the "Checker" framework, and begin using it to annotate Unsigned primitives.
Modified Paths:
--------------
trunk/foray/build.gradle
trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
Modified: trunk/foray/build.gradle
===================================================================
--- trunk/foray/build.gradle 2025-04-19 13:25:06 UTC (rev 13441)
+++ trunk/foray/build.gradle 2025-04-19 15:56:16 UTC (rev 13442)
@@ -26,10 +26,11 @@
*/
plugins {
- id 'foray.common-conventions'
- id 'java'
+ id "foray.common-conventions"
+ id "java"
id "com.autonomousapps.dependency-analysis" version "1.0.0-rc02"
id "java-library-distribution"
+ id "org.checkerframework" version "0.6.53"
}
Modified: trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle
===================================================================
--- trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-19 13:25:06 UTC (rev 13441)
+++ trunk/foray/buildSrc/src/main/groovy/foray.common-conventions.gradle 2025-04-19 15:56:16 UTC (rev 13442)
@@ -4,6 +4,8 @@
id 'java'
id 'checkstyle'
id 'maven-publish'
+ id "org.checkerframework"
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-19 13:25:06 UTC (rev 13441)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-19 15:56:16 UTC (rev 13442)
@@ -28,6 +28,8 @@
package org.foray.common;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
import java.io.DataInput;
import java.io.IOException;
import java.io.RandomAccessFile;
@@ -162,7 +164,7 @@
* @return The integer created from the bytes read.
* @throws IOException For I/O error.
*/
- default BigInteger readInteger(int length) throws IOException {
+ default @Unsigned BigInteger readUnsignedInteger(int length) throws IOException {
final byte[] bytes = new byte[length];
readFully(bytes);
return new BigInteger(bytes);
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java 2025-04-19 13:25:06 UTC (rev 13441)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/Panose4a.java 2025-04-19 15:56:16 UTC (rev 13442)
@@ -31,7 +31,9 @@
import org.axsl.font.FontException;
import org.axsl.font.Panose;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
/**
* A PANOSE-1 classification number.
*
@@ -51,7 +53,7 @@
public final class Panose4a implements Panose {
/** The quantity of element in a Panose 1.0 array. */
- private static final int QTY_PANOSE_ELEMENTS = 10;
+ private static final @Unsigned byte QTY_PANOSE_ELEMENTS = 10;
/**
* Enumeration of the fields that comprise a PANOSE description.
@@ -89,7 +91,7 @@
X_HEIGHT((byte) 9, (byte) 7);
/** The 0-based index of this element in the PANOSE array. */
- private byte index;
+ private @Unsigned byte index;
/** The maximum value that is permissible for this element. */
private byte maxValue;
@@ -217,7 +219,7 @@
* @return The newly-created instance.
* @see #makeInstance(byte[])
*/
- public static Panose4a forceInstance(final byte[] panoseArray) {
+ public static Panose4a forceInstance(final @Unsigned byte[] panoseArray) {
return new Panose4a(panoseArray);
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java 2025-04-19 13:25:06 UTC (rev 13441)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfRandomAccessInput.java 2025-04-19 15:56:16 UTC (rev 13442)
@@ -33,6 +33,8 @@
import org.axsl.primitive.sequence.ByteSequencePlus;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
@@ -80,8 +82,8 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default short read_uint8() throws IOException {
- return (short) readUnsignedByte();
+ default @Unsigned byte read_uint8() throws IOException {
+ return (byte) readUnsignedByte();
}
/**
@@ -98,8 +100,8 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default int read_uint16() throws IOException {
- return readUnsignedShort();
+ default @Unsigned short read_uint16() throws IOException {
+ return (short) readUnsignedShort();
}
/**
@@ -116,8 +118,8 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default int read_uint24() throws IOException {
- final BigInteger bi = this.readInteger(TtfType.uint24.getQtyBytes());
+ default @Unsigned int read_uint24() throws IOException {
+ final BigInteger bi = this.readUnsignedInteger(TtfType.uint24.getQtyBytes());
return bi.intValue();
}
@@ -126,8 +128,8 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default long read_uint32() throws IOException {
- return readUnsignedInt();
+ default @Unsigned int read_uint32() throws IOException {
+ return (int) readUnsignedInt();
}
/**
@@ -168,7 +170,7 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default int read_UFWORD() throws IOException {
+ default @Unsigned short read_UFWORD() throws IOException {
return read_uint16();
}
@@ -187,8 +189,9 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default BigInteger read_LONGDATETIME() throws IOException {
- return readInteger(TtfType.LONGDATETIME.getQtyBytes());
+ default @Unsigned long read_LONGDATETIME() throws IOException {
+ final BigInteger bi = readUnsignedInteger(TtfType.LONGDATETIME.getQtyBytes());
+ return bi.longValue();
}
/**
@@ -205,7 +208,7 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default short read_Offset8() throws IOException {
+ default @Unsigned byte read_Offset8() throws IOException {
return read_uint8();
}
@@ -214,7 +217,7 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default int read_Offset16() throws IOException {
+ default @Unsigned short read_Offset16() throws IOException {
return read_uint16();
}
@@ -223,7 +226,7 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default int read_Offset24() throws IOException {
+ default @Unsigned int read_Offset24() throws IOException {
return read_uint24();
}
@@ -232,7 +235,7 @@
* @return The parsed value.
* @throws IOException For I/O Error.
*/
- default long read_Offset32() throws IOException {
+ default @Unsigned int read_Offset32() throws IOException {
return read_uint32();
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 13:25:06 UTC (rev 13441)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 15:56:16 UTC (rev 13442)
@@ -183,7 +183,7 @@
@Override
public void primitiveField(final String fieldName, final PrimitiveFerry value) {
switch (fieldName) {
- case "version": this.version = (byte) value.getInt(); break;
+ case "version": this.version = (byte) value.getShort(); break;
case "fstype": this.fsType = value.getInt(); break;
case "yStrikeoutSize": this.yStrikeoutSize = value.getShort(); break;
case "yStrikeoutPosition": this.yStrikeoutPosition = value.getShort(); break;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 13:25:06 UTC (rev 13441)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 15:56:16 UTC (rev 13442)
@@ -35,6 +35,8 @@
import org.foray.font.format.ttf.TtfRandomAccessInput;
import org.foray.font.format.ttf.TtfTable;
+import org.checkerframework.checker.signedness.qual.Unsigned;
+
import java.io.IOException;
/**
@@ -48,8 +50,8 @@
final FontParserConsumer consumer) throws IOException {
final PrimitiveFerry ferry = new PrimitiveFerry();
input.seek(offset);
- final int version = input.read_uint16();
- consumer.primitiveField("version", ferry.setInt(version)); // 2 bytes, total 2
+ final short version = input.read_uint16();
+ consumer.primitiveField("version", ferry.setShort(version)); // 2 bytes, total 2
/* OS/2 Table, Version 0. */
@@ -70,9 +72,9 @@
consumer.primitiveField("sFamilyClass", ferry.setShort(input.read_int16())); // 2 bytes, total 32
/* Read the Panose array. */
- final byte[] panoseArray = new byte[Panose4a.Field.values().length]; // 10 bytes, total 42
+ final @Unsigned byte[] panoseArray = new byte[Panose4a.Field.values().length]; // 10 bytes, total 42
for (int i = 0; i < panoseArray.length; i++) {
- panoseArray[i] = input.readByte();
+ panoseArray[i] = input.read_uint8();
}
consumer.objectField("panose", Panose4a.forceInstance(panoseArray));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-19 13:25:24
|
Revision: 13441
http://sourceforge.net/p/foray/code/13441
Author: victormote
Date: 2025-04-19 13:25:06 +0000 (Sat, 19 Apr 2025)
Log Message:
-----------
Complete conversion of parsers to use of PrimitiveFerry.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-19 12:59:51 UTC (rev 13440)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-19 13:25:06 UTC (rev 13441)
@@ -43,17 +43,10 @@
void objectField(String fieldName, Object value);
/**
- * An Object field has been parsed.
+ * An primitive field has been parsed.
* @param fieldName The name of the field parsed.
* @param value The parsed value.
*/
void primitiveField(String fieldName, PrimitiveFerry value);
- /**
- * An "short" field has been parsed.
- * @param fieldName The name of the field parsed.
- * @param value The parsed value.
- */
- void shortField(String fieldName, short value);
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-19 12:59:51 UTC (rev 13440)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-19 13:25:06 UTC (rev 13441)
@@ -132,8 +132,4 @@
}
}
- @Override
- public void shortField(final String fieldName, final short value) {
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 12:59:51 UTC (rev 13440)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 13:25:06 UTC (rev 13441)
@@ -183,21 +183,15 @@
@Override
public void primitiveField(final String fieldName, final PrimitiveFerry value) {
switch (fieldName) {
- case "version": this.version = (byte) value.getInt(); break;
- case "fstype": this.fsType = value.getInt(); break;
+ case "version": this.version = (byte) value.getInt(); break;
+ case "fstype": this.fsType = value.getInt(); break;
+ case "yStrikeoutSize": this.yStrikeoutSize = value.getShort(); break;
+ case "yStrikeoutPosition": this.yStrikeoutPosition = value.getShort(); break;
+ case "sTypoAscender": this.sTypoAscender = value.getShort(); break;
+ case "sTypoDescender": this.sTypoDescender = value.getShort(); break;
+ case "sxHeight": this.sxHeight = value.getShort(); break;
+ case "sCapHeight": this.sCapHeight = value.getShort(); break;
}
}
- @Override
- public void shortField(final String fieldName, final short value) {
- switch (fieldName) {
- case "yStrikeoutSize": this.yStrikeoutSize = value; break;
- case "yStrikeoutPosition": this.yStrikeoutPosition = value; break;
- case "sTypoAscender": this.sTypoAscender = value; break;
- case "sTypoDescender": this.sTypoDescender = value; break;
- case "sxHeight": this.sxHeight = value; break;
- case "sCapHeight": this.sCapHeight = value; break;
- }
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-19 12:59:51 UTC (rev 13440)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-19 13:25:06 UTC (rev 13441)
@@ -129,13 +129,8 @@
switch (fieldName) {
case "xHeight": this.xHeight = value.getInt(); break;
case "capHeight": this.capHeight = value.getInt(); break;
- }
- }
- @Override
- public void shortField(final String fieldName, final short value) {
- switch (fieldName) {
- case "serifStyle": this.serifStyle = value; break;
+ case "serifStyle": this.serifStyle = value.getShort(); break;
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java 2025-04-19 12:59:51 UTC (rev 13440)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java 2025-04-19 13:25:06 UTC (rev 13441)
@@ -64,10 +64,10 @@
final short yMin = input.read_int16(); // 2 bytes, total 40
final short xMax = input.read_int16(); // 2 bytes, total 42
final short yMax = input.read_int16(); // 2 bytes, total 44
- consumer.shortField("xMin", xMin);
- consumer.shortField("yMin", yMin);
- consumer.shortField("xMax", xMax);
- consumer.shortField("yMax", yMax);
+ consumer.primitiveField("xMin", ferry.setShort(xMin));
+ consumer.primitiveField("yMin", ferry.setShort(yMin));
+ consumer.primitiveField("xMax", ferry.setShort(xMax));
+ consumer.primitiveField("yMax", ferry.setShort(yMax));
/* In case the consumer wants the four bounding box components already assembled. */
final short[] boundingBox = {xMin, yMin, xMax, yMax};
consumer.objectField("boundingBox", boundingBox);
@@ -74,9 +74,9 @@
consumer.primitiveField("macStyle", ferry.setInt(input.read_uint16())); // 2 bytes, total 46
consumer.primitiveField("lowestRecPPEM", ferry.setInt(input.read_uint16())); // 2 bytes, total 48
- consumer.shortField("fontDirectionHint", input.read_int16()); // 2 bytes, total 50
+ consumer.primitiveField("fontDirectionHint", ferry.setShort(input.read_int16())); // 2 bytes, total 50
consumer.primitiveField("indexToLocFormat", ferry.setShort(input.read_int16())); // 2 bytes, total 52
- consumer.shortField("glyphDataFormat", input.read_int16()); // 2 bytes, total 54
+ consumer.primitiveField("glyphDataFormat", ferry.setShort(input.read_int16())); // 2 bytes, total 54
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 12:59:51 UTC (rev 13440)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 13:25:06 UTC (rev 13441)
@@ -53,21 +53,21 @@
/* OS/2 Table, Version 0. */
- consumer.shortField("xAvgCharWidth", input.read_FWORD()); // 2 bytes, total 4
+ consumer.primitiveField("xAvgCharWidth", ferry.setShort(input.read_FWORD())); // 2 bytes, total 4
consumer.primitiveField("usWeightClass", ferry.setInt(input.read_uint16())); // 2 bytes, total 6
consumer.primitiveField("usWidthClass", ferry.setInt(input.read_uint16())); // 2 bytes, total 8
consumer.primitiveField("fsType", ferry.setInt(input.read_uint16())); // 2 bytes, total 10
- consumer.shortField("ySubscriptXSize", input.read_FWORD()); // 2 bytes, total 12
- consumer.shortField("ySubscriptYSize", input.read_FWORD()); // 2 bytes, total 14
- consumer.shortField("ySubscriptXOffset", input.read_FWORD()); // 2 bytes, total 16
- consumer.shortField("ySubscriptYOffset", input.read_FWORD()); // 2 bytes, total 18
- consumer.shortField("ySuperscriptXSize", input.read_FWORD()); // 2 bytes, total 20
- consumer.shortField("ySuperscriptYSize", input.read_FWORD()); // 2 bytes, total 22
- consumer.shortField("ySuperscriptXOffset", input.read_FWORD()); // 2 bytes, total 24
- consumer.shortField("ySuperscriptYOffset", input.read_FWORD()); // 2 bytes, total 26
- consumer.shortField("yStrikeoutSize", input.read_FWORD()); // 2 bytes, total 28
- consumer.shortField("yStrikeoutPosition", input.read_FWORD()); // 2 bytes, total 30
- consumer.shortField("sFamilyClass", input.read_int16()); // 2 bytes, total 32
+ consumer.primitiveField("ySubscriptXSize", ferry.setShort(input.read_FWORD())); // 2 bytes, total 12
+ consumer.primitiveField("ySubscriptYSize", ferry.setShort(input.read_FWORD())); // 2 bytes, total 14
+ consumer.primitiveField("ySubscriptXOffset", ferry.setShort(input.read_FWORD())); // 2 bytes, total 16
+ consumer.primitiveField("ySubscriptYOffset", ferry.setShort(input.read_FWORD())); // 2 bytes, total 18
+ consumer.primitiveField("ySuperscriptXSize", ferry.setShort(input.read_FWORD())); // 2 bytes, total 20
+ consumer.primitiveField("ySuperscriptYSize", ferry.setShort(input.read_FWORD())); // 2 bytes, total 22
+ consumer.primitiveField("ySuperscriptXOffset", ferry.setShort(input.read_FWORD())); // 2 bytes, total 24
+ consumer.primitiveField("ySuperscriptYOffset", ferry.setShort(input.read_FWORD())); // 2 bytes, total 26
+ consumer.primitiveField("yStrikeoutSize", ferry.setShort(input.read_FWORD())); // 2 bytes, total 28
+ consumer.primitiveField("yStrikeoutPosition", ferry.setShort(input.read_FWORD())); // 2 bytes, total 30
+ consumer.primitiveField("sFamilyClass", ferry.setShort(input.read_int16())); // 2 bytes, total 32
/* Read the Panose array. */
final byte[] panoseArray = new byte[Panose4a.Field.values().length]; // 10 bytes, total 42
@@ -84,9 +84,9 @@
consumer.primitiveField("fsSelection", ferry.setInt(input.read_uint16())); // 2 bytes, total 64
consumer.primitiveField("usFirstCharIndex", ferry.setInt(input.read_uint16())); // 2 bytes, total 66
consumer.primitiveField("usLastCharIndex", ferry.setInt(input.read_uint16())); // 2 bytes, total 68
- consumer.shortField("sTypoAscender", input.read_FWORD()); // 2 bytes, total 70
- consumer.shortField("sTypoDescender", input.read_FWORD()); // 2 bytes, total 72
- consumer.shortField("sTypoLineGap", input.read_FWORD()); // 2 bytes, total 74
+ consumer.primitiveField("sTypoAscender", ferry.setShort(input.read_FWORD())); // 2 bytes, total 70
+ consumer.primitiveField("sTypoDescender", ferry.setShort(input.read_FWORD())); // 2 bytes, total 72
+ consumer.primitiveField("sTypoLineGap", ferry.setShort(input.read_FWORD())); // 2 bytes, total 74
consumer.primitiveField("usWinAscent", ferry.setInt(input.read_UFWORD())); // 2 bytes, total 76
consumer.primitiveField("usWinDescent", ferry.setInt(input.read_UFWORD())); // 2 bytes, total 78
@@ -103,8 +103,8 @@
}
/* OS/2 Table, Version 2. Versions 3 & 4 are the same as Version 2. */
- consumer.shortField("sxHeight", input.read_FWORD()); // 2 bytes, total 88
- consumer.shortField("sCapHeight", input.read_FWORD()); // 2 bytes, total 90
+ consumer.primitiveField("sxHeight", ferry.setShort(input.read_FWORD())); // 2 bytes, total 88
+ consumer.primitiveField("sCapHeight", ferry.setShort(input.read_FWORD())); // 2 bytes, total 90
consumer.primitiveField("usDefaultChar", ferry.setInt(input.read_uint16())); // 2 bytes, total 92
consumer.primitiveField("usBreakChar", ferry.setInt(input.read_uint16())); // 2 bytes, total 94
consumer.primitiveField("usMaxContext", ferry.setInt(input.read_uint16())); // 2 bytes, total 96
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-19 12:59:51 UTC (rev 13440)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-19 13:25:06 UTC (rev 13441)
@@ -69,7 +69,7 @@
// 6 bytes, total 50
consumer.primitiveField("strokeWeight", ferry.setByte(input.read_int8())); // 1 bytes, total 51
consumer.primitiveField("widthType", ferry.setByte(input.read_int8())); // 1 bytes, total 52
- consumer.shortField("serifStyle", input.read_uint8()); // 1 bytes, total 53
+ consumer.primitiveField("serifStyle", ferry.setShort(input.read_uint8())); // 1 bytes, total 53
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-19 13:00:08
|
Revision: 13440
http://sourceforge.net/p/foray/code/13440
Author: victormote
Date: 2025-04-19 12:59:51 +0000 (Sat, 19 Apr 2025)
Log Message:
-----------
Remove more FontParserConsumer methods.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java 2025-04-19 12:31:22 UTC (rev 13439)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java 2025-04-19 12:59:51 UTC (rev 13440)
@@ -70,6 +70,15 @@
/** The long currently carried by this ferry. */
private long longValue;
+ /** The char currently carried by this ferry. */
+ private char charValue;
+
+ /** The float currently carried by this ferry. */
+ private float floatValue;
+
+ /** The double currently carried by this ferry. */
+ private double doubleValue;
+
/**
* Compares the requested type to the active type, throwing an exception if they do not match.
* @param requestedType The type requested.
@@ -182,4 +191,64 @@
return this;
}
+ /**
+ * Returns the char value.
+ * @return The char Value.
+ */
+ public char getChar() {
+ checkType(Primitive.Type.CHAR);
+ return this.charValue;
+ }
+
+ /**
+ * Sets the char value.
+ * @param charValue The char value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setChar(final char charValue) {
+ this.activeType = Primitive.Type.CHAR;
+ this.charValue = charValue;
+ return this;
+ }
+
+ /**
+ * Returns the float value.
+ * @return The float Value.
+ */
+ public float getFloat() {
+ checkType(Primitive.Type.FLOAT);
+ return this.floatValue;
+ }
+
+ /**
+ * Sets the float value.
+ * @param floatValue The float value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setFloat(final float floatValue) {
+ this.activeType = Primitive.Type.FLOAT;
+ this.floatValue = floatValue;
+ return this;
+ }
+
+ /**
+ * Returns the double value.
+ * @return The double Value.
+ */
+ public double geDouble() {
+ checkType(Primitive.Type.DOUBLE);
+ return this.doubleValue;
+ }
+
+ /**
+ * Sets the double value.
+ * @param doubleValue The double value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setDouble(final double doubleValue) {
+ this.activeType = Primitive.Type.DOUBLE;
+ this.doubleValue = doubleValue;
+ return this;
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-19 12:31:22 UTC (rev 13439)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-19 12:59:51 UTC (rev 13440)
@@ -50,20 +50,6 @@
void primitiveField(String fieldName, PrimitiveFerry value);
/**
- * A String field has been parsed.
- * @param fieldName The name of the field parsed.
- * @param value The parsed value.
- */
- void stringField(String fieldName, String value);
-
- /**
- * An "byte" field has been parsed.
- * @param fieldName The name of the field parsed.
- * @param value The parsed value.
- */
- void byteField(String fieldName, byte value);
-
- /**
* An "short" field has been parsed.
* @param fieldName The name of the field parsed.
* @param value The parsed value.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-19 12:31:22 UTC (rev 13439)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-19 12:59:51 UTC (rev 13440)
@@ -133,14 +133,6 @@
}
@Override
- public void stringField(final String fieldName, final String value) {
- }
-
- @Override
- public void byteField(final String fieldName, final byte value) {
- }
-
- @Override
public void shortField(final String fieldName, final short value) {
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 12:31:22 UTC (rev 13439)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 12:59:51 UTC (rev 13440)
@@ -181,10 +181,6 @@
}
@Override
- public void stringField(final String fieldName, final String value) {
- }
-
- @Override
public void primitiveField(final String fieldName, final PrimitiveFerry value) {
switch (fieldName) {
case "version": this.version = (byte) value.getInt(); break;
@@ -193,10 +189,6 @@
}
@Override
- public void byteField(final String fieldName, final byte value) {
- }
-
- @Override
public void shortField(final String fieldName, final short value) {
switch (fieldName) {
case "yStrikeoutSize": this.yStrikeoutSize = value; break;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-19 12:31:22 UTC (rev 13439)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-19 12:59:51 UTC (rev 13440)
@@ -125,10 +125,6 @@
}
@Override
- public void stringField(final String fieldName, final String value) {
- }
-
- @Override
public void primitiveField(final String fieldName, final PrimitiveFerry value) {
switch (fieldName) {
case "xHeight": this.xHeight = value.getInt(); break;
@@ -137,10 +133,6 @@
}
@Override
- public void byteField(final String fieldName, final byte value) {
- }
-
- @Override
public void shortField(final String fieldName, final short value) {
switch (fieldName) {
case "serifStyle": this.serifStyle = value; break;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 12:31:22 UTC (rev 13439)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 12:59:51 UTC (rev 13440)
@@ -80,7 +80,7 @@
consumer.primitiveField("ulUnicodeRange2", ferry.setLong(input.read_uint32())); // 4 bytes, total 50
consumer.primitiveField("ulUnicodeRange3", ferry.setLong(input.read_uint32())); // 4 bytes, total 54
consumer.primitiveField("ulUnicodeRange4", ferry.setLong(input.read_uint32())); // 4 bytes, total 58
- consumer.stringField("achVendID", input.read_Tag()); // 4 bytes, total 62
+ consumer.objectField("achVendID", input.read_Tag()); // 4 bytes, total 62
consumer.primitiveField("fsSelection", ferry.setInt(input.read_uint16())); // 2 bytes, total 64
consumer.primitiveField("usFirstCharIndex", ferry.setInt(input.read_uint16())); // 2 bytes, total 66
consumer.primitiveField("usLastCharIndex", ferry.setInt(input.read_uint16())); // 2 bytes, total 68
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-19 12:31:22 UTC (rev 13439)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-19 12:59:51 UTC (rev 13440)
@@ -61,14 +61,14 @@
consumer.primitiveField("typeFamily", ferry.setInt(input.read_uint16())); // 2 bytes, total 16
consumer.primitiveField("capHeight", ferry.setInt(input.read_uint16())); // 2 bytes, total 18
consumer.primitiveField("symbolSet", ferry.setInt(input.read_uint16())); // 2 bytes, total 20
- consumer.stringField("typeface", input.readStringASCII(TtfTablePclt.TYPEFACE_CHARS));
+ consumer.objectField("typeface", input.readStringASCII(TtfTablePclt.TYPEFACE_CHARS));
// 16 bytes, total 36
- consumer.stringField("characterComplement", input.readStringASCII(TtfTablePclt.CHARACTER_COMPLEMENT_CHARS));
+ consumer.objectField("characterComplement", input.readStringASCII(TtfTablePclt.CHARACTER_COMPLEMENT_CHARS));
// 8 bytes, total 44
- consumer.stringField("fileName", input.readStringASCII(TtfTablePclt.FILE_NAME_CHARS));
+ consumer.objectField("fileName", input.readStringASCII(TtfTablePclt.FILE_NAME_CHARS));
// 6 bytes, total 50
- consumer.byteField("strokeWeight", input.read_int8()); // 1 bytes, total 51
- consumer.byteField("widthType", input.read_int8()); // 1 bytes, total 52
+ consumer.primitiveField("strokeWeight", ferry.setByte(input.read_int8())); // 1 bytes, total 51
+ consumer.primitiveField("widthType", ferry.setByte(input.read_int8())); // 1 bytes, total 52
consumer.shortField("serifStyle", input.read_uint8()); // 1 bytes, total 53
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-19 12:31:40
|
Revision: 13439
http://sourceforge.net/p/foray/code/13439
Author: victormote
Date: 2025-04-19 12:31:22 +0000 (Sat, 19 Apr 2025)
Log Message:
-----------
Partial conversion to use of PrimitiveFerry to communicate Font parser results.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java
Added: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -0,0 +1,185 @@
+/*
+ * 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.common.primitive;
+
+import org.axsl.primitive.Primitive;
+
+/**
+ * <p>Class whose instances are used to "ferry" primitive values between applications, hiding their type during
+ * transport.
+ * This is useful mostly in tasks where performance and/or memory consumption need to be optimized.
+ * Instances are reused, preventing unnecessary object creation and garbage collection.
+ * Primitives do not need to be boxed/unboxed in classes such as {@link java.lang.Integer} or {@link java.lang.Float}.
+ * There are getters and setters for each primitive type, and the instance internally tracks which one is currently
+ * active, preventing old or unset values from being accidentally used.</p>
+ *
+ * <p>We don't get something for nothing.
+ * The tradeoff is that the receiver is expected either to know the type, or to inquire about the type before trying
+ * to retrieve the value.
+ * Usually some other clue is given to the receiver about what the type should be.
+ * For example, in a parsing application, a sender (parser) might send field name "color" along with a ferry containing
+ * the short value 0x1234.
+ * The receiver then, must know that field "color" is of primitive type "short" in order to retrieve the value from the
+ * ferry.
+ * Attempting to retrieve the value of a type different than the active type will result in a runtime exception.
+ * For the performance gains mentioned above, we give up some compile-time safety.</p>
+ */
+public class PrimitiveFerry {
+
+ /** The type currently carried by this ferry. */
+ private Primitive.Type activeType;
+
+ /** The boolean currently carried by this ferry. */
+ private boolean booleanValue;
+
+ /** The byte currently carried by this ferry. */
+ private byte byteValue;
+
+ /** The short currently carried by this ferry. */
+ private short shortValue;
+
+ /** The int currently carried by this ferry. */
+ private int intValue;
+
+ /** The long currently carried by this ferry. */
+ private long longValue;
+
+ /**
+ * Compares the requested type to the active type, throwing an exception if they do not match.
+ * @param requestedType The type requested.
+ * @throws RuntimeException When the requested type does not match the actual type.
+ */
+ private void checkType(final Primitive.Type requestedType) {
+ if (requestedType != this.activeType) {
+ final String message = "Primitive ferry active for " + this.activeType + " cannot return " + requestedType;
+ throw new RuntimeException(message);
+ }
+ }
+
+ /**
+ * Returns the boolean value.
+ * @return The boolean Value.
+ */
+ public boolean getBoolean() {
+ checkType(Primitive.Type.BOOLEAN);
+ return this.booleanValue;
+ }
+
+ /**
+ * Sets the boolean value.
+ * @param booleanValue The boolean value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setBoolean(final boolean booleanValue) {
+ this.activeType = Primitive.Type.BOOLEAN;
+ this.booleanValue = booleanValue;
+ return this;
+ }
+
+ /**
+ * Returns the byte value.
+ * @return The byte Value.
+ */
+ public byte getByte() {
+ checkType(Primitive.Type.BYTE);
+ return this.byteValue;
+ }
+
+ /**
+ * Sets the byte value.
+ * @param byteValue The byte value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setByte(final byte byteValue) {
+ this.activeType = Primitive.Type.BYTE;
+ this.byteValue = byteValue;
+ return this;
+ }
+
+ /**
+ * Returns the short value.
+ * @return The short Value.
+ */
+ public short getShort() {
+ checkType(Primitive.Type.SHORT);
+ return this.shortValue;
+ }
+
+ /**
+ * Sets the short value.
+ * @param shortValue The short value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setShort(final short shortValue) {
+ this.activeType = Primitive.Type.SHORT;
+ this.shortValue = shortValue;
+ return this;
+ }
+
+ /**
+ * Returns the int value.
+ * @return The int Value.
+ */
+ public int getInt() {
+ checkType(Primitive.Type.INT);
+ return this.intValue;
+ }
+
+ /**
+ * Sets the int value.
+ * @param intValue The int value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setInt(final int intValue) {
+ this.activeType = Primitive.Type.INT;
+ this.intValue = intValue;
+ return this;
+ }
+
+ /**
+ * Returns the long value.
+ * @return The long Value.
+ */
+ public long getLong() {
+ checkType(Primitive.Type.LONG);
+ return this.longValue;
+ }
+
+ /**
+ * Sets the long value.
+ * @param longValue The long value to set.
+ * @return This instance, to assist with chaining.
+ */
+ public PrimitiveFerry setLong(final long longValue) {
+ this.activeType = Primitive.Type.LONG;
+ this.longValue = longValue;
+ return this;
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/PrimitiveFerry.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/FontParserConsumer.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -28,6 +28,8 @@
package org.foray.font;
+import org.foray.common.primitive.PrimitiveFerry;
+
/**
* Implementations receive events from a {@link FontParser}.
*/
@@ -41,6 +43,13 @@
void objectField(String fieldName, Object value);
/**
+ * An Object field has been parsed.
+ * @param fieldName The name of the field parsed.
+ * @param value The parsed value.
+ */
+ void primitiveField(String fieldName, PrimitiveFerry value);
+
+ /**
* A String field has been parsed.
* @param fieldName The name of the field parsed.
* @param value The parsed value.
@@ -61,18 +70,4 @@
*/
void shortField(String fieldName, short value);
- /**
- * An "int" field has been parsed.
- * @param fieldName The name of the field parsed.
- * @param value The parsed value.
- */
- void intField(String fieldName, int value);
-
- /**
- * An "long" field has been parsed.
- * @param fieldName The name of the field parsed.
- * @param value The parsed value.
- */
- void longField(String fieldName, long value);
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -30,6 +30,7 @@
import org.foray.common.data.BoundingBoxShort;
import org.foray.common.data.BoundingBoxUtils;
+import org.foray.common.primitive.PrimitiveFerry;
import org.foray.font.FontParserConsumer;
import org.foray.font.format.ttf.parse.TtfTableHeadParser;
@@ -58,7 +59,7 @@
private BoundingBox boundingBox = BoundingBoxUtils.ZEROES;
/** The parsed "indexToLocFormat" value from this table. */
- private int indexToLocFormat;
+ private short indexToLocFormat;
/**
* Constructor.
@@ -124,6 +125,14 @@
}
@Override
+ public void primitiveField(final String fieldName, final PrimitiveFerry value) {
+ switch (fieldName) {
+ case "unitsPerEm": this.unitsPerEm = value.getInt(); break;
+ case "indexToLocFormat": this.indexToLocFormat = value.getShort(); break;
+ }
+ }
+
+ @Override
public void stringField(final String fieldName, final String value) {
}
@@ -133,20 +142,6 @@
@Override
public void shortField(final String fieldName, final short value) {
- switch (fieldName) {
- case "indexToLocFormat": this.indexToLocFormat = value; break;
- }
}
- @Override
- public void intField(final String fieldName, final int value) {
- switch (fieldName) {
- case "unitsPerEm": this.unitsPerEm = value; break;
- }
- }
-
- @Override
- public void longField(final String fieldName, final long value) {
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -28,6 +28,7 @@
package org.foray.font.format.ttf;
+import org.foray.common.primitive.PrimitiveFerry;
import org.foray.font.FontParserConsumer;
import org.foray.font.format.Panose4a;
import org.foray.font.format.ttf.parse.TtfTableOs2Parser;
@@ -184,6 +185,14 @@
}
@Override
+ public void primitiveField(final String fieldName, final PrimitiveFerry value) {
+ switch (fieldName) {
+ case "version": this.version = (byte) value.getInt(); break;
+ case "fstype": this.fsType = value.getInt(); break;
+ }
+ }
+
+ @Override
public void byteField(final String fieldName, final byte value) {
}
@@ -199,16 +208,4 @@
}
}
- @Override
- public void intField(final String fieldName, final int value) {
- switch (fieldName) {
- case "version": this.version = (byte) value; break;
- case "fstype": this.fsType = value; break;
- }
- }
-
- @Override
- public void longField(final String fieldName, final long value) {
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -28,6 +28,7 @@
package org.foray.font.format.ttf;
+import org.foray.common.primitive.PrimitiveFerry;
import org.foray.font.FontParserConsumer;
import org.foray.font.format.ttf.parse.TtfTablePcltParser;
@@ -128,6 +129,14 @@
}
@Override
+ public void primitiveField(final String fieldName, final PrimitiveFerry value) {
+ switch (fieldName) {
+ case "xHeight": this.xHeight = value.getInt(); break;
+ case "capHeight": this.capHeight = value.getInt(); break;
+ }
+ }
+
+ @Override
public void byteField(final String fieldName, final byte value) {
}
@@ -138,16 +147,4 @@
}
}
- @Override
- public void intField(final String fieldName, final int value) {
- switch (fieldName) {
- case "xHeight": this.xHeight = value; break;
- case "capHeight": this.capHeight = value; break;
- }
- }
-
- @Override
- public void longField(final String fieldName, final long value) {
- }
-
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -28,6 +28,7 @@
package org.foray.font.format.ttf.parse;
+import org.foray.common.primitive.PrimitiveFerry;
import org.foray.font.FontParser;
import org.foray.font.FontParserConsumer;
import org.foray.font.format.ttf.TtfRandomAccessInput;
@@ -43,24 +44,25 @@
@Override
public void parse(final TtfRandomAccessInput input, final int offset, final int size,
final FontParserConsumer consumer) throws IOException {
+ final PrimitiveFerry ferry = new PrimitiveFerry();
input.seek(offset);
final int majorVersion = input.read_uint16(); // 2 bytes, total 2
- consumer.intField("majorVersion", majorVersion);
+ consumer.primitiveField("majorVersion", ferry.setInt(majorVersion));
final int minorVersion = input.read_uint16(); // 2 bytes, total 4
- consumer.intField("minorVersion", minorVersion);
+ consumer.primitiveField("minorVersion", ferry.setInt(minorVersion));
/* BASE Table Header, Version 1.0. */
final int horizAxisOffset = input.read_Offset16(); // 2 bytes, total 6
- consumer.intField("horizAxisOffset", horizAxisOffset);
+ consumer.primitiveField("horizAxisOffset", ferry.setInt(horizAxisOffset));
final int vertAxisOffset = input.read_Offset16(); // 2 bytes, total 8
- consumer.intField("vertAxisOffset", vertAxisOffset);
+ consumer.primitiveField("vertAxisOffset", ferry.setInt(vertAxisOffset));
/* BASE Table Header, Version 1.1. */
if (minorVersion > 0) {
final long itemVarStoreOffset = input.read_Offset32(); // 4 bytes, total 12
- consumer.longField("itemVarStoreOffset", itemVarStoreOffset);
+ consumer.primitiveField("itemVarStoreOffset", ferry.setLong(itemVarStoreOffset));
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -28,6 +28,7 @@
package org.foray.font.format.ttf.parse;
+import org.foray.common.primitive.PrimitiveFerry;
import org.foray.font.FontParser;
import org.foray.font.FontParserConsumer;
import org.foray.font.format.ttf.TtfRandomAccessInput;
@@ -43,25 +44,26 @@
@Override
public void parse(final TtfRandomAccessInput input, final int offset, final int size,
final FontParserConsumer consumer) throws IOException {
+ final PrimitiveFerry ferry = new PrimitiveFerry();
input.seek(offset);
- final int majorVersion = input.read_uint16(); // 2 bytes, total 2
- consumer.intField("majorVersion", majorVersion);
+ final int majorVersion = input.read_uint16(); // 2 bytes, total 2
+ consumer.primitiveField("majorVersion", ferry.setInt(majorVersion));
/* Head Table, Version 1.0. */
- consumer.intField("minorVersion", input.read_uint16()); // 2 bytes, total 4
- consumer.objectField("fontRevision", input.read_Fixed()); // 4 bytes, total 8
- consumer.longField("checksumAdjustment", input.read_uint32()); // 4 bytes, total 12
- consumer.longField("magicNumber", input.read_uint32()); // 4 bytes, total 16
- consumer.intField("flags", input.read_uint16()); // 2 bytes, total 18
- consumer.intField("unitsPerEm", input.read_uint16()); // 2 bytes, total 20
- consumer.objectField("created", input.read_LONGDATETIME()); // 8 bytes, total 28
- consumer.objectField("modifed", input.read_LONGDATETIME()); // 8 bytes, total 36
+ consumer.primitiveField("minorVersion", ferry.setInt(input.read_uint16())); // 2 bytes, total 4
+ consumer.objectField("fontRevision", input.read_Fixed()); // 4 bytes, total 8
+ consumer.primitiveField("checksumAdjustment", ferry.setLong(input.read_uint32())); // 4 bytes, total 12
+ consumer.primitiveField("magicNumber", ferry.setLong(input.read_uint32())); // 4 bytes, total 16
+ consumer.primitiveField("flags", ferry.setInt(input.read_uint16())); // 2 bytes, total 18
+ consumer.primitiveField("unitsPerEm", ferry.setInt(input.read_uint16())); // 2 bytes, total 20
+ consumer.objectField("created", input.read_LONGDATETIME()); // 8 bytes, total 28
+ consumer.objectField("modifed", input.read_LONGDATETIME()); // 8 bytes, total 36
- final short xMin = input.read_int16(); // 2 bytes, total 38
- final short yMin = input.read_int16(); // 2 bytes, total 40
- final short xMax = input.read_int16(); // 2 bytes, total 42
- final short yMax = input.read_int16(); // 2 bytes, total 44
+ final short xMin = input.read_int16(); // 2 bytes, total 38
+ final short yMin = input.read_int16(); // 2 bytes, total 40
+ final short xMax = input.read_int16(); // 2 bytes, total 42
+ final short yMax = input.read_int16(); // 2 bytes, total 44
consumer.shortField("xMin", xMin);
consumer.shortField("yMin", yMin);
consumer.shortField("xMax", xMax);
@@ -70,11 +72,11 @@
final short[] boundingBox = {xMin, yMin, xMax, yMax};
consumer.objectField("boundingBox", boundingBox);
- consumer.intField("macStyle", input.read_uint16()); // 2 bytes, total 46
- consumer.intField("lowestRecPPEM", input.read_uint16()); // 2 bytes, total 48
- consumer.shortField("fontDirectionHint", input.read_int16()); // 2 bytes, total 50
- consumer.shortField("indexToLocFormat", input.read_int16()); // 2 bytes, total 52
- consumer.shortField("glyphDataFormat", input.read_int16()); // 2 bytes, total 54
+ consumer.primitiveField("macStyle", ferry.setInt(input.read_uint16())); // 2 bytes, total 46
+ consumer.primitiveField("lowestRecPPEM", ferry.setInt(input.read_uint16())); // 2 bytes, total 48
+ consumer.shortField("fontDirectionHint", input.read_int16()); // 2 bytes, total 50
+ consumer.primitiveField("indexToLocFormat", ferry.setShort(input.read_int16())); // 2 bytes, total 52
+ consumer.shortField("glyphDataFormat", input.read_int16()); // 2 bytes, total 54
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -28,6 +28,7 @@
package org.foray.font.format.ttf.parse;
+import org.foray.common.primitive.PrimitiveFerry;
import org.foray.font.FontParser;
import org.foray.font.FontParserConsumer;
import org.foray.font.format.Panose4a;
@@ -45,48 +46,49 @@
@Override
public void parse(final TtfRandomAccessInput input, final int offset, final int size,
final FontParserConsumer consumer) throws IOException {
+ final PrimitiveFerry ferry = new PrimitiveFerry();
input.seek(offset);
final int version = input.read_uint16();
- consumer.intField("version", version); // 2 bytes, total 2
+ consumer.primitiveField("version", ferry.setInt(version)); // 2 bytes, total 2
/* OS/2 Table, Version 0. */
- consumer.shortField("xAvgCharWidth", input.read_FWORD()); // 2 bytes, total 4
- consumer.intField("usWeightClass", input.read_uint16()); // 2 bytes, total 6
- consumer.intField("usWidthClass", input.read_uint16()); // 2 bytes, total 8
- consumer.intField("fsType", input.read_uint16()); // 2 bytes, total 10
- consumer.shortField("ySubscriptXSize", input.read_FWORD()); // 2 bytes, total 12
- consumer.shortField("ySubscriptYSize", input.read_FWORD()); // 2 bytes, total 14
- consumer.shortField("ySubscriptXOffset", input.read_FWORD()); // 2 bytes, total 16
- consumer.shortField("ySubscriptYOffset", input.read_FWORD()); // 2 bytes, total 18
- consumer.shortField("ySuperscriptXSize", input.read_FWORD()); // 2 bytes, total 20
- consumer.shortField("ySuperscriptYSize", input.read_FWORD()); // 2 bytes, total 22
- consumer.shortField("ySuperscriptXOffset", input.read_FWORD()); // 2 bytes, total 24
- consumer.shortField("ySuperscriptYOffset", input.read_FWORD()); // 2 bytes, total 26
- consumer.shortField("yStrikeoutSize", input.read_FWORD()); // 2 bytes, total 28
- consumer.shortField("yStrikeoutPosition", input.read_FWORD()); // 2 bytes, total 30
- consumer.shortField("sFamilyClass", input.read_int16()); // 2 bytes, total 32
+ consumer.shortField("xAvgCharWidth", input.read_FWORD()); // 2 bytes, total 4
+ consumer.primitiveField("usWeightClass", ferry.setInt(input.read_uint16())); // 2 bytes, total 6
+ consumer.primitiveField("usWidthClass", ferry.setInt(input.read_uint16())); // 2 bytes, total 8
+ consumer.primitiveField("fsType", ferry.setInt(input.read_uint16())); // 2 bytes, total 10
+ consumer.shortField("ySubscriptXSize", input.read_FWORD()); // 2 bytes, total 12
+ consumer.shortField("ySubscriptYSize", input.read_FWORD()); // 2 bytes, total 14
+ consumer.shortField("ySubscriptXOffset", input.read_FWORD()); // 2 bytes, total 16
+ consumer.shortField("ySubscriptYOffset", input.read_FWORD()); // 2 bytes, total 18
+ consumer.shortField("ySuperscriptXSize", input.read_FWORD()); // 2 bytes, total 20
+ consumer.shortField("ySuperscriptYSize", input.read_FWORD()); // 2 bytes, total 22
+ consumer.shortField("ySuperscriptXOffset", input.read_FWORD()); // 2 bytes, total 24
+ consumer.shortField("ySuperscriptYOffset", input.read_FWORD()); // 2 bytes, total 26
+ consumer.shortField("yStrikeoutSize", input.read_FWORD()); // 2 bytes, total 28
+ consumer.shortField("yStrikeoutPosition", input.read_FWORD()); // 2 bytes, total 30
+ consumer.shortField("sFamilyClass", input.read_int16()); // 2 bytes, total 32
/* Read the Panose array. */
- final byte[] panoseArray = new byte[Panose4a.Field.values().length]; // 10 bytes, total 42
+ final byte[] panoseArray = new byte[Panose4a.Field.values().length]; // 10 bytes, total 42
for (int i = 0; i < panoseArray.length; i++) {
panoseArray[i] = input.readByte();
}
consumer.objectField("panose", Panose4a.forceInstance(panoseArray));
- consumer.longField("ulUnicodeRange1", input.read_uint32()); // 4 bytes, total 46
- consumer.longField("ulUnicodeRange2", input.read_uint32()); // 4 bytes, total 50
- consumer.longField("ulUnicodeRange3", input.read_uint32()); // 4 bytes, total 54
- consumer.longField("ulUnicodeRange4", input.read_uint32()); // 4 bytes, total 58
- consumer.stringField("achVendID", input.read_Tag()); // 4 bytes, total 62
- consumer.intField("fsSelection", input.read_uint16()); // 2 bytes, total 64
- consumer.intField("usFirstCharIndex", input.read_uint16()); // 2 bytes, total 66
- consumer.intField("usLastCharIndex", input.read_uint16()); // 2 bytes, total 68
- consumer.shortField("sTypoAscender", input.read_FWORD()); // 2 bytes, total 70
- consumer.shortField("sTypoDescender", input.read_FWORD()); // 2 bytes, total 72
- consumer.shortField("sTypoLineGap", input.read_FWORD()); // 2 bytes, total 74
- consumer.intField("usWinAscent", input.read_UFWORD()); // 2 bytes, total 76
- consumer.intField("usWinDescent", input.read_UFWORD()); // 2 bytes, total 78
+ consumer.primitiveField("ulUnicodeRange1", ferry.setLong(input.read_uint32())); // 4 bytes, total 46
+ consumer.primitiveField("ulUnicodeRange2", ferry.setLong(input.read_uint32())); // 4 bytes, total 50
+ consumer.primitiveField("ulUnicodeRange3", ferry.setLong(input.read_uint32())); // 4 bytes, total 54
+ consumer.primitiveField("ulUnicodeRange4", ferry.setLong(input.read_uint32())); // 4 bytes, total 58
+ consumer.stringField("achVendID", input.read_Tag()); // 4 bytes, total 62
+ consumer.primitiveField("fsSelection", ferry.setInt(input.read_uint16())); // 2 bytes, total 64
+ consumer.primitiveField("usFirstCharIndex", ferry.setInt(input.read_uint16())); // 2 bytes, total 66
+ consumer.primitiveField("usLastCharIndex", ferry.setInt(input.read_uint16())); // 2 bytes, total 68
+ consumer.shortField("sTypoAscender", input.read_FWORD()); // 2 bytes, total 70
+ consumer.shortField("sTypoDescender", input.read_FWORD()); // 2 bytes, total 72
+ consumer.shortField("sTypoLineGap", input.read_FWORD()); // 2 bytes, total 74
+ consumer.primitiveField("usWinAscent", ferry.setInt(input.read_UFWORD())); // 2 bytes, total 76
+ consumer.primitiveField("usWinDescent", ferry.setInt(input.read_UFWORD())); // 2 bytes, total 78
if (version < TtfTable.MajorVersion.v1.getValue()) {
return;
@@ -93,8 +95,8 @@
}
/* OS/2 Table, Version 1. */
- consumer.longField("ulCodePageRange1", input.read_uint32()); // 4 bytes, total 82
- consumer.longField("ulCodePageRange2", input.read_uint32()); // 4 bytes, total 86
+ consumer.primitiveField("ulCodePageRange1", ferry.setLong(input.read_uint32())); // 4 bytes, total 82
+ consumer.primitiveField("ulCodePageRange2", ferry.setLong(input.read_uint32())); // 4 bytes, total 86
if (version < TtfTable.MajorVersion.v2.getValue()) {
return;
@@ -101,11 +103,11 @@
}
/* OS/2 Table, Version 2. Versions 3 & 4 are the same as Version 2. */
- consumer.shortField("sxHeight", input.read_FWORD()); // 2 bytes, total 88
- consumer.shortField("sCapHeight", input.read_FWORD()); // 2 bytes, total 90
- consumer.intField("usDefaultChar", input.read_uint16()); // 2 bytes, total 92
- consumer.intField("usBreakChar", input.read_uint16()); // 2 bytes, total 94
- consumer.intField("usMaxContext", input.read_uint16()); // 2 bytes, total 96
+ consumer.shortField("sxHeight", input.read_FWORD()); // 2 bytes, total 88
+ consumer.shortField("sCapHeight", input.read_FWORD()); // 2 bytes, total 90
+ consumer.primitiveField("usDefaultChar", ferry.setInt(input.read_uint16())); // 2 bytes, total 92
+ consumer.primitiveField("usBreakChar", ferry.setInt(input.read_uint16())); // 2 bytes, total 94
+ consumer.primitiveField("usMaxContext", ferry.setInt(input.read_uint16())); // 2 bytes, total 96
if (version < TtfTable.MajorVersion.v5.getValue()) {
return;
@@ -112,8 +114,8 @@
}
/* OS/2 Table, Version 5. */
- consumer.intField("usLowerOpticalPointSize", input.read_uint16()); // 2 bytes, total 98
- consumer.intField("usUpperOpticalPointSize", input.read_uint16()); // 2 bytes, total 100
+ consumer.primitiveField("usLowerOpticalPointSize", ferry.setInt(input.read_uint16())); // 2 bytes, total 98
+ consumer.primitiveField("usUpperOpticalPointSize", ferry.setInt(input.read_uint16())); // 2 bytes, total 100
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -28,6 +28,7 @@
package org.foray.font.format.ttf.parse;
+import org.foray.common.primitive.PrimitiveFerry;
import org.foray.font.FontParser;
import org.foray.font.FontParserConsumer;
import org.foray.font.format.ttf.TtfRandomAccessInput;
@@ -44,30 +45,31 @@
@Override
public void parse(final TtfRandomAccessInput input, final int offset, final int size,
final FontParserConsumer consumer) throws IOException {
+ final PrimitiveFerry ferry = new PrimitiveFerry();
input.seek(offset);
final int majorVersion = input.read_uint16();
- consumer.intField("majorVersion", majorVersion); // 2 bytes, total 2
+ consumer.primitiveField("majorVersion", ferry.setInt(majorVersion)); // 2 bytes, total 2
/* PCLT Table, Version 1.0. */
- consumer.intField("minorVersion", input.read_uint16()); // 2 bytes, total 4
- consumer.longField("fontNumber", input.read_uint32()); // 4 bytes, total 8
+ consumer.primitiveField("minorVersion", ferry.setInt(input.read_uint16())); // 2 bytes, total 4
+ consumer.primitiveField("fontNumber", ferry.setLong(input.read_uint32())); // 4 bytes, total 8
- consumer.intField("pitch", input.read_uint16()); // 2 bytes, total 10
- consumer.intField("xHeight", input.read_uint16()); // 2 bytes, total 12
- consumer.intField("style", input.read_uint16()); // 2 bytes, total 14
- consumer.intField("typeFamily", input.read_uint16()); // 2 bytes, total 16
- consumer.intField("capHeight", input.read_uint16()); // 2 bytes, total 18
- consumer.intField("symbolSet", input.read_uint16()); // 2 bytes, total 20
+ consumer.primitiveField("pitch", ferry.setInt(input.read_uint16())); // 2 bytes, total 10
+ consumer.primitiveField("xHeight", ferry.setInt(input.read_uint16())); // 2 bytes, total 12
+ consumer.primitiveField("style", ferry.setInt(input.read_uint16())); // 2 bytes, total 14
+ consumer.primitiveField("typeFamily", ferry.setInt(input.read_uint16())); // 2 bytes, total 16
+ consumer.primitiveField("capHeight", ferry.setInt(input.read_uint16())); // 2 bytes, total 18
+ consumer.primitiveField("symbolSet", ferry.setInt(input.read_uint16())); // 2 bytes, total 20
consumer.stringField("typeface", input.readStringASCII(TtfTablePclt.TYPEFACE_CHARS));
- // 16 bytes, total 36
+ // 16 bytes, total 36
consumer.stringField("characterComplement", input.readStringASCII(TtfTablePclt.CHARACTER_COMPLEMENT_CHARS));
- // 8 bytes, total 44
+ // 8 bytes, total 44
consumer.stringField("fileName", input.readStringASCII(TtfTablePclt.FILE_NAME_CHARS));
- // 6 bytes, total 50
- consumer.byteField("strokeWeight", input.read_int8()); // 1 bytes, total 51
- consumer.byteField("widthType", input.read_int8()); // 1 bytes, total 52
- consumer.shortField("serifStyle", input.read_uint8()); // 1 bytes, total 53
+ // 6 bytes, total 50
+ consumer.byteField("strokeWeight", input.read_int8()); // 1 bytes, total 51
+ consumer.byteField("widthType", input.read_int8()); // 1 bytes, total 52
+ consumer.shortField("serifStyle", input.read_uint8()); // 1 bytes, total 53
}
}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java 2025-04-18 22:52:56 UTC (rev 13438)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java 2025-04-19 12:31:22 UTC (rev 13439)
@@ -82,6 +82,8 @@
/* The following values were obtained by opening the TTF file in FontLab Studio 5.0.4.
* We are unable to verify these values in FontLab 8.4. */
final BoundingBox expectedBBox = new BoundingBoxShort(-1501, -550, 3398, 2262);
+ /* Family dimensions / Units Per eM. */
+ final int expectedUnitsPerEm = 2048;
assertEquals(expectedPostScriptName, ttfFont.getNameTable().getPostscriptName());
assertEquals(expectedFullName, ttfFont.getNameTable().getFullName());
@@ -93,6 +95,7 @@
assertEquals(expectedCapHeight, ttfFont.getCapHeight());
assertEquals(expectedItalicAngle, ttfFont.getItalicAngle());
assertEquals(expectedBBox, ttfFont.getFontBBox());
+ assertEquals(expectedUnitsPerEm, ttfFont.getHeadTable().unitsPerEm());
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 22:53:14
|
Revision: 13438
http://sourceforge.net/p/foray/code/13438
Author: victormote
Date: 2025-04-18 22:52:56 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Simplify font parsing a bit by passing the consumer at parse time instead of construction time.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FontParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontParser.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontParser.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -35,37 +35,20 @@
/**
* Parses font files and produces events to be consumed by a {@link FontParserConsumer}.
* Making font parsing an event-driven process separates the concerns of parsing and using the font data.
- * The parser parses everything consistently.
+ * The parser parses everything consistently, regardless of the consumer.
* The consumer does what it wishes with the results.
*/
public abstract class FontParser {
- /** The consumer of this parser's events. */
- private FontParserConsumer consumer;
-
/**
- * Constructor.
- * @param consumer The consumer of this parser's events.
- */
- public FontParser(final FontParserConsumer consumer) {
- this.consumer = consumer;
- }
-
- /**
- * Returns the consumer of this parser's events.
- * @return The consumer of this parser's events.
- */
- public FontParserConsumer getConsumer() {
- return this.consumer;
- }
-
- /**
* Parses the input.
* @param input The input to be parsed.
* @param offset The offset, in bytes, into {@code input} at which parsing should begin.
* @param size The size, in bytes, of {@code input} that should be parsed.
+ * @param consumer The consumer of the parsing.
* @throws IOException For errors reading the input.
*/
- public abstract void parse(TtfRandomAccessInput input, int offset, int size) throws IOException;
+ public abstract void parse(TtfRandomAccessInput input, int offset, int size, FontParserConsumer consumer)
+ throws IOException;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -78,8 +78,8 @@
public static TtfTableHead parse(final TtfOffsetTableRecord dirEntry, final TtfRandomAccessInput input)
throws IOException {
final TtfTableHead head = new TtfTableHead(dirEntry);
- final TtfTableHeadParser parser = new TtfTableHeadParser(head);
- parser.parse(input, dirEntry.getOffset(), dirEntry.getLength());
+ final TtfTableHeadParser parser = new TtfTableHeadParser();
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), head);
return head;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -84,8 +84,8 @@
public static TtfTableOs2 parse(final TtfOffsetTableRecord dirEntry, final TtfRandomAccessInput input)
throws IOException {
final TtfTableOs2 os2 = new TtfTableOs2(dirEntry);
- final TtfTableOs2Parser parser = new TtfTableOs2Parser(os2);
- parser.parse(input, dirEntry.getOffset(), dirEntry.getLength());
+ final TtfTableOs2Parser parser = new TtfTableOs2Parser();
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), os2);
return os2;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -81,8 +81,8 @@
public static TtfTablePclt parse(final TtfOffsetTableRecord dirEntry, final TtfRandomAccessInput input)
throws IOException {
final TtfTablePclt pclt = new TtfTablePclt(dirEntry);
- final TtfTablePcltParser parser = new TtfTablePcltParser(pclt);
- parser.parse(input, dirEntry.getOffset(), dirEntry.getLength());
+ final TtfTablePcltParser parser = new TtfTablePcltParser();
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength(), pclt);
return pclt;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -40,17 +40,9 @@
*/
public class TtfTableBaseParser extends FontParser {
- /**
- * Constructor.
- * @param consumer The consumer of this parser's events.
- */
- public TtfTableBaseParser(final FontParserConsumer consumer) {
- super(consumer);
- }
-
@Override
- public void parse(final TtfRandomAccessInput input, final int offset, final int size) throws IOException {
- final FontParserConsumer consumer = getConsumer();
+ public void parse(final TtfRandomAccessInput input, final int offset, final int size,
+ final FontParserConsumer consumer) throws IOException {
input.seek(offset);
final int majorVersion = input.read_uint16(); // 2 bytes, total 2
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -40,17 +40,9 @@
*/
public class TtfTableHeadParser extends FontParser {
- /**
- * Constructor.
- * @param consumer The consumer of this parser's events.
- */
- public TtfTableHeadParser(final FontParserConsumer consumer) {
- super(consumer);
- }
-
@Override
- public void parse(final TtfRandomAccessInput input, final int offset, final int size) throws IOException {
- final FontParserConsumer consumer = getConsumer();
+ public void parse(final TtfRandomAccessInput input, final int offset, final int size,
+ final FontParserConsumer consumer) throws IOException {
input.seek(offset);
final int majorVersion = input.read_uint16(); // 2 bytes, total 2
consumer.intField("majorVersion", majorVersion);
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableOs2Parser.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -42,17 +42,9 @@
*/
public class TtfTableOs2Parser extends FontParser {
- /**
- * Constructor.
- * @param consumer The consumer of this parser's events.
- */
- public TtfTableOs2Parser(final FontParserConsumer consumer) {
- super(consumer);
- }
-
@Override
- public void parse(final TtfRandomAccessInput input, final int offset, final int size) throws IOException {
- final FontParserConsumer consumer = getConsumer();
+ public void parse(final TtfRandomAccessInput input, final int offset, final int size,
+ final FontParserConsumer consumer) throws IOException {
input.seek(offset);
final int version = input.read_uint16();
consumer.intField("version", version); // 2 bytes, total 2
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-18 22:41:10 UTC (rev 13437)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-18 22:52:56 UTC (rev 13438)
@@ -41,17 +41,9 @@
*/
public class TtfTablePcltParser extends FontParser {
- /**
- * Constructor.
- * @param consumer The consumer of this parser's events.
- */
- public TtfTablePcltParser(final FontParserConsumer consumer) {
- super(consumer);
- }
-
@Override
- public void parse(final TtfRandomAccessInput input, final int offset, final int size) throws IOException {
- final FontParserConsumer consumer = getConsumer();
+ public void parse(final TtfRandomAccessInput input, final int offset, final int size,
+ final FontParserConsumer consumer) throws IOException {
input.seek(offset);
final int majorVersion = input.read_uint16();
consumer.intField("majorVersion", majorVersion); // 2 bytes, total 2
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 22:41:27
|
Revision: 13437
http://sourceforge.net/p/foray/code/13437
Author: victormote
Date: 2025-04-18 22:41:10 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Rough-in a parser for TTF Base table.
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java
Added: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.java 2025-04-18 22:41:10 UTC (rev 13437)
@@ -0,0 +1,75 @@
+/*
+ * 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.format.ttf.parse;
+
+import org.foray.font.FontParser;
+import org.foray.font.FontParserConsumer;
+import org.foray.font.format.ttf.TtfRandomAccessInput;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF BASE table.
+ * @see org.foray.font.format.ttf.TtfTableBase
+ */
+public class TtfTableBaseParser extends FontParser {
+
+ /**
+ * Constructor.
+ * @param consumer The consumer of this parser's events.
+ */
+ public TtfTableBaseParser(final FontParserConsumer consumer) {
+ super(consumer);
+ }
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final int size) throws IOException {
+ final FontParserConsumer consumer = getConsumer();
+ input.seek(offset);
+
+ final int majorVersion = input.read_uint16(); // 2 bytes, total 2
+ consumer.intField("majorVersion", majorVersion);
+ final int minorVersion = input.read_uint16(); // 2 bytes, total 4
+ consumer.intField("minorVersion", minorVersion);
+
+
+ /* BASE Table Header, Version 1.0. */
+ final int horizAxisOffset = input.read_Offset16(); // 2 bytes, total 6
+ consumer.intField("horizAxisOffset", horizAxisOffset);
+ final int vertAxisOffset = input.read_Offset16(); // 2 bytes, total 8
+ consumer.intField("vertAxisOffset", vertAxisOffset);
+
+ /* BASE Table Header, Version 1.1. */
+ if (minorVersion > 0) {
+ final long itemVarStoreOffset = input.read_Offset32(); // 4 bytes, total 12
+ consumer.longField("itemVarStoreOffset", itemVarStoreOffset);
+ }
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableBaseParser.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-04-18 20:41:20
|
Revision: 13436
http://sourceforge.net/p/foray/code/13436
Author: victormote
Date: 2025-04-18 20:41:02 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Add parser for HEAD table.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-18 17:02:42 UTC (rev 13435)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-18 20:41:02 UTC (rev 13436)
@@ -157,7 +157,7 @@
int readShortLoHi() throws IOException;
/**
- * Reads an integer of arbitrary length.
+ * Reads an integer with an arbitrary input size.
* @param length The number of bytes to be parsed.
* @return The integer created from the bytes read.
* @throws IOException For I/O error.
@@ -164,7 +164,7 @@
*/
default BigInteger readInteger(int length) throws IOException {
final byte[] bytes = new byte[length];
- readFully(bytes, (int) getOffset(), length);
+ readFully(bytes);
return new BigInteger(bytes);
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-18 17:02:42 UTC (rev 13435)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableHead.java 2025-04-18 20:41:02 UTC (rev 13436)
@@ -28,9 +28,10 @@
package org.foray.font.format.ttf;
-import org.foray.common.RandomAccessInput;
import org.foray.common.data.BoundingBoxShort;
import org.foray.common.data.BoundingBoxUtils;
+import org.foray.font.FontParserConsumer;
+import org.foray.font.format.ttf.parse.TtfTableHeadParser;
import org.axsl.ps.BoundingBox;
@@ -39,7 +40,7 @@
/**
* Class representing a TTF "head" table.
*/
-public class TtfTableHead extends TtfTable {
+public class TtfTableHead extends TtfTable implements FontParserConsumer {
/** Constant for the offset to the "checkSumAdjustment" in this table. */
public static final byte CHECK_SUM_ADJUSTMENT_OFFSET = 8;
@@ -50,11 +51,11 @@
/** A magic number used in the checksum computation. */
public static final int CHECK_SUM_CONSTANT = 0xB1B0AFBA;
- /** The units-per-em for this font. */
+ /** The parsed "unitsPerEm". */
private int unitsPerEm;
- /** The bounding box for this font. */
- private BoundingBox bbox = BoundingBoxUtils.ZEROES;
+ /** The parsed bounding box. */
+ private BoundingBox boundingBox = BoundingBoxUtils.ZEROES;
/** The parsed "indexToLocFormat" value from this table. */
private int indexToLocFormat;
@@ -70,44 +71,15 @@
/**
* Read the "head" table.
* @param dirEntry The parent table directory entry.
- * @param raInput The input which is being parsed.
+ * @param input The input which is being parsed.
* @return The parsed instance.
* @throws IOException For I/O Error.
*/
- public static TtfTableHead parse(final TtfOffsetTableRecord dirEntry, final RandomAccessInput raInput)
+ public static TtfTableHead parse(final TtfOffsetTableRecord dirEntry, final TtfRandomAccessInput input)
throws IOException {
- raInput.seek(dirEntry.getOffset());
final TtfTableHead head = new TtfTableHead(dirEntry);
- /* Skip Table version number. */
- raInput.skipBytes(FIXED_BYTES);
- /* Skip fontRevision. */
- raInput.skipBytes(FIXED_BYTES);
- /* Skip checkSumAdjustment. */
- raInput.skipBytes(ULONG_BYTES);
- /* Skip magicNumber. */
- raInput.skipBytes(ULONG_BYTES);
- /* Skip flags. */
- raInput.skipBytes(USHORT_BYTES);
- head.unitsPerEm = raInput.readUnsignedShort();
- /* Skip created date. */
- raInput.skipBytes(LONG_DATE_TIME_BYTES);
- /* Skip modified date. */
- raInput.skipBytes(LONG_DATE_TIME_BYTES);
- /* Read the bounding box. */
- final short bbllx = raInput.readShort();
- final short bblly = raInput.readShort();
- final short bburx = raInput.readShort();
- final short bbury = raInput.readShort();
- head.bbox = new BoundingBoxShort(bbllx, bblly, bburx, bbury);
- /* Skip macStyle. */
- raInput.skipBytes(USHORT_BYTES);
- /* Skip lowestRecPPEM. */
- raInput.skipBytes(USHORT_BYTES);
- /* Skip fontDirectionHint. */
- raInput.skipBytes(SHORT_BYTES);
- head.indexToLocFormat = raInput.readShort();
- /* Skip glyphDataFormat. */
- raInput.skipBytes(SHORT_BYTES);
+ final TtfTableHeadParser parser = new TtfTableHeadParser(head);
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength());
return head;
}
@@ -117,8 +89,7 @@
}
/**
- * Indicates whether the "long" or "short" version of the "loca" table is
- * used.
+ * Indicates whether the "long" or "short" version of the "loca" table is used.
* @return True if and only if the "long" version of the "loca" table is used.
*/
public boolean longLocaFormat() {
@@ -138,7 +109,44 @@
* @return The bounding box for this font.
*/
public BoundingBox getBbox() {
- return this.bbox;
+ return this.boundingBox;
}
+ @Override
+ public void objectField(final String fieldName, final Object value) {
+ switch (fieldName) {
+ case "boundingBox": {
+ final short[] boundingBoxArray = (short[]) value;
+ this.boundingBox = new BoundingBoxShort(boundingBoxArray);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void stringField(final String fieldName, final String value) {
+ }
+
+ @Override
+ public void byteField(final String fieldName, final byte value) {
+ }
+
+ @Override
+ public void shortField(final String fieldName, final short value) {
+ switch (fieldName) {
+ case "indexToLocFormat": this.indexToLocFormat = value; break;
+ }
+ }
+
+ @Override
+ public void intField(final String fieldName, final int value) {
+ switch (fieldName) {
+ case "unitsPerEm": this.unitsPerEm = value; break;
+ }
+ }
+
+ @Override
+ public void longField(final String fieldName, final long value) {
+ }
+
}
Added: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.java 2025-04-18 20:41:02 UTC (rev 13436)
@@ -0,0 +1,88 @@
+/*
+ * 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.format.ttf.parse;
+
+import org.foray.font.FontParser;
+import org.foray.font.FontParserConsumer;
+import org.foray.font.format.ttf.TtfRandomAccessInput;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF HEAD table.
+ * @see org.foray.font.format.ttf.TtfTableHead
+ */
+public class TtfTableHeadParser extends FontParser {
+
+ /**
+ * Constructor.
+ * @param consumer The consumer of this parser's events.
+ */
+ public TtfTableHeadParser(final FontParserConsumer consumer) {
+ super(consumer);
+ }
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final int size) throws IOException {
+ final FontParserConsumer consumer = getConsumer();
+ input.seek(offset);
+ final int majorVersion = input.read_uint16(); // 2 bytes, total 2
+ consumer.intField("majorVersion", majorVersion);
+
+
+ /* Head Table, Version 1.0. */
+ consumer.intField("minorVersion", input.read_uint16()); // 2 bytes, total 4
+ consumer.objectField("fontRevision", input.read_Fixed()); // 4 bytes, total 8
+ consumer.longField("checksumAdjustment", input.read_uint32()); // 4 bytes, total 12
+ consumer.longField("magicNumber", input.read_uint32()); // 4 bytes, total 16
+ consumer.intField("flags", input.read_uint16()); // 2 bytes, total 18
+ consumer.intField("unitsPerEm", input.read_uint16()); // 2 bytes, total 20
+ consumer.objectField("created", input.read_LONGDATETIME()); // 8 bytes, total 28
+ consumer.objectField("modifed", input.read_LONGDATETIME()); // 8 bytes, total 36
+
+ final short xMin = input.read_int16(); // 2 bytes, total 38
+ final short yMin = input.read_int16(); // 2 bytes, total 40
+ final short xMax = input.read_int16(); // 2 bytes, total 42
+ final short yMax = input.read_int16(); // 2 bytes, total 44
+ consumer.shortField("xMin", xMin);
+ consumer.shortField("yMin", yMin);
+ consumer.shortField("xMax", xMax);
+ consumer.shortField("yMax", yMax);
+ /* In case the consumer wants the four bounding box components already assembled. */
+ final short[] boundingBox = {xMin, yMin, xMax, yMax};
+ consumer.objectField("boundingBox", boundingBox);
+
+ consumer.intField("macStyle", input.read_uint16()); // 2 bytes, total 46
+ consumer.intField("lowestRecPPEM", input.read_uint16()); // 2 bytes, total 48
+ consumer.shortField("fontDirectionHint", input.read_int16()); // 2 bytes, total 50
+ consumer.shortField("indexToLocFormat", input.read_int16()); // 2 bytes, total 52
+ consumer.shortField("glyphDataFormat", input.read_int16()); // 2 bytes, total 54
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTableHeadParser.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-04-18 17:03:00
|
Revision: 13435
http://sourceforge.net/p/foray/code/13435
Author: victormote
Date: 2025-04-18 17:02:42 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Add parser for PCLT table.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
Added Paths:
-----------
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-18 15:07:35 UTC (rev 13434)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontParserConsumer.java 2025-04-18 17:02:42 UTC (rev 13435)
@@ -48,11 +48,11 @@
void stringField(String fieldName, String value);
/**
- * An "int" field has been parsed.
+ * An "byte" field has been parsed.
* @param fieldName The name of the field parsed.
* @param value The parsed value.
*/
- void intField(String fieldName, int value);
+ void byteField(String fieldName, byte value);
/**
* An "short" field has been parsed.
@@ -62,6 +62,13 @@
void shortField(String fieldName, short value);
/**
+ * An "int" field has been parsed.
+ * @param fieldName The name of the field parsed.
+ * @param value The parsed value.
+ */
+ void intField(String fieldName, int value);
+
+ /**
* An "long" field has been parsed.
* @param fieldName The name of the field parsed.
* @param value The parsed value.
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-18 15:07:35 UTC (rev 13434)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableOs2.java 2025-04-18 17:02:42 UTC (rev 13435)
@@ -173,10 +173,6 @@
}
@Override
- public void stringField(final String fieldName, final String value) {
- }
-
- @Override
public void objectField(final String fieldName, final Object value) {
switch (fieldName) {
case "panose": this.panose = (Panose4a) value;
@@ -184,14 +180,14 @@
}
@Override
- public void intField(final String fieldName, final int value) {
- switch (fieldName) {
- case "version": this.version = (byte) value; break;
- case "fstype": this.fsType = value; break;
- }
+ public void stringField(final String fieldName, final String value) {
}
@Override
+ public void byteField(final String fieldName, final byte value) {
+ }
+
+ @Override
public void shortField(final String fieldName, final short value) {
switch (fieldName) {
case "yStrikeoutSize": this.yStrikeoutSize = value; break;
@@ -204,6 +200,14 @@
}
@Override
+ public void intField(final String fieldName, final int value) {
+ switch (fieldName) {
+ case "version": this.version = (byte) value; break;
+ case "fstype": this.fsType = value; break;
+ }
+ }
+
+ @Override
public void longField(final String fieldName, final long value) {
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-18 15:07:35 UTC (rev 13434)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTablePclt.java 2025-04-18 17:02:42 UTC (rev 13435)
@@ -28,7 +28,8 @@
package org.foray.font.format.ttf;
-import org.foray.common.RandomAccessInput;
+import org.foray.font.FontParserConsumer;
+import org.foray.font.format.ttf.parse.TtfTablePcltParser;
import java.io.IOException;
@@ -35,8 +36,17 @@
/**
* Class representing a TTF "PCLT" (PCL 5) table.
*/
-public class TtfTablePclt extends TtfTable {
+public class TtfTablePclt extends TtfTable implements FontParserConsumer {
+ /** The size, in bytes, of the "typeface" field. */
+ public static final byte TYPEFACE_CHARS = 16;
+
+ /** The size, in bytes, of the "characterComplement" field. */
+ public static final byte CHARACTER_COMPLEMENT_CHARS = 8;
+
+ /** The size, in TTF "char"s of the "FileName" field. */
+ public static final byte FILE_NAME_CHARS = 6;
+
/** Mask suitable for determining whether the font has serifs by applying
* it against the "SerifStyle" byte.
* According to the PCLT doc, the font has serifs if the top two bits
@@ -44,23 +54,14 @@
* The mask is therefore 1000,0000. */
private static final byte SERIF_STYLE_MASK = (byte) 0x80;
- /** The size, in TTF "char"s of the "Typeface" field. */
- private static final byte TYPEFACE_CHARS = 16;
-
- /** The size, in TTF "char"s of the "CharacterComplement" field. */
- private static final byte CHARACTER_COMPLEMENT_CHARS = 8;
-
- /** The size, in TTF "char"s of the "FileName" field. */
- private static final byte FILE_NAME_CHARS = 6;
-
/** The cap height as parsed from this table, in text space units. */
- private int capHeight = 0;
+ private int capHeight;
/** The x-height as parsed from this table, in text spaces units. */
- private int xHeight = 0;
+ private int xHeight;
- /** Indicates whether this font has serifs, as parsed from the table. */
- private boolean hasSerifs = true;
+ /** The serif style as parsed from this table. */
+ private short serifStyle;
/**
* Constructor.
@@ -73,49 +74,15 @@
/**
* Reads the "PCLT" table to find xHeight and capHeight.
* @param dirEntry The parent table directory entry.
- * @param raInput The input which is being parsed.
+ * @param input The input which is being parsed.
* @return The parsed instance.
* @throws IOException For I/O Error.
*/
- public static TtfTablePclt parse(final TtfOffsetTableRecord dirEntry, final RandomAccessInput raInput)
+ public static TtfTablePclt parse(final TtfOffsetTableRecord dirEntry, final TtfRandomAccessInput input)
throws IOException {
- raInput.seek(dirEntry.getOffset());
final TtfTablePclt pclt = new TtfTablePclt(dirEntry);
- /* Skip Version. */
- raInput.skipBytes(TtfTable.FIXED_BYTES);
- /* Skip FontNumber. */
- raInput.skipBytes(TtfTable.ULONG_BYTES);
- /* Skip Pitch. */
- raInput.skipBytes(TtfTable.USHORT_BYTES);
- /* Read xHeight. */
- pclt.xHeight = raInput.readUnsignedShort();
- /* Skip Style. */
- raInput.skipBytes(TtfTable.USHORT_BYTES);
- /* Skip TypeFamily. */
- raInput.skipBytes(TtfTable.USHORT_BYTES);
- /* Read CapHeight. */
- pclt.capHeight = raInput.readUnsignedShort();
- /* Skip SymbolSet. */
- raInput.skipBytes(TtfTable.USHORT_BYTES);
- /* Skip Typeface. */
- raInput.skipBytes(TtfTablePclt.TYPEFACE_CHARS * CHAR_BYTES);
- /* Skip CharacterComplement. */
- raInput.skipBytes(TtfTablePclt.CHARACTER_COMPLEMENT_CHARS
- * CHAR_BYTES);
- /* Skip FileName. */
- raInput.skipBytes(TtfTablePclt.FILE_NAME_CHARS
- * CHAR_BYTES);
- /* Skip StrokeWeight. */
- raInput.skipBytes(CHAR_BYTES);
- /* Skip WidthType. */
- raInput.skipBytes(CHAR_BYTES);
- /* Read SerifStyle. */
- final int serifStyle = raInput.readUnsignedByte();
- if ((serifStyle & TtfTablePclt.SERIF_STYLE_MASK) == 0) {
- pclt.hasSerifs = false;
- } else {
- pclt.hasSerifs = true;
- }
+ final TtfTablePcltParser parser = new TtfTablePcltParser(pclt);
+ parser.parse(input, dirEntry.getOffset(), dirEntry.getLength());
return pclt;
}
@@ -137,7 +104,11 @@
* @return True if and only if this font has serifs.
*/
public boolean hasSerifs() {
- return this.hasSerifs;
+ if ((this.serifStyle & TtfTablePclt.SERIF_STYLE_MASK) == 0) {
+ return false;
+ } else {
+ return true;
+ }
}
/**
@@ -148,4 +119,35 @@
return this.xHeight;
}
+ @Override
+ public void objectField(final String fieldName, final Object value) {
+ }
+
+ @Override
+ public void stringField(final String fieldName, final String value) {
+ }
+
+ @Override
+ public void byteField(final String fieldName, final byte value) {
+ }
+
+ @Override
+ public void shortField(final String fieldName, final short value) {
+ switch (fieldName) {
+ case "serifStyle": this.serifStyle = value; break;
+ }
+ }
+
+ @Override
+ public void intField(final String fieldName, final int value) {
+ switch (fieldName) {
+ case "xHeight": this.xHeight = value; break;
+ case "capHeight": this.capHeight = value; break;
+ }
+ }
+
+ @Override
+ public void longField(final String fieldName, final long value) {
+ }
+
}
Added: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java (rev 0)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.java 2025-04-18 17:02:42 UTC (rev 13435)
@@ -0,0 +1,81 @@
+/*
+ * 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.format.ttf.parse;
+
+import org.foray.font.FontParser;
+import org.foray.font.FontParserConsumer;
+import org.foray.font.format.ttf.TtfRandomAccessInput;
+import org.foray.font.format.ttf.TtfTablePclt;
+
+import java.io.IOException;
+
+/**
+ * Parses a TTF PCLT table.
+ * @see org.foray.font.format.ttf.TtfTablePclt
+ */
+public class TtfTablePcltParser extends FontParser {
+
+ /**
+ * Constructor.
+ * @param consumer The consumer of this parser's events.
+ */
+ public TtfTablePcltParser(final FontParserConsumer consumer) {
+ super(consumer);
+ }
+
+ @Override
+ public void parse(final TtfRandomAccessInput input, final int offset, final int size) throws IOException {
+ final FontParserConsumer consumer = getConsumer();
+ input.seek(offset);
+ final int majorVersion = input.read_uint16();
+ consumer.intField("majorVersion", majorVersion); // 2 bytes, total 2
+
+
+ /* PCLT Table, Version 1.0. */
+ consumer.intField("minorVersion", input.read_uint16()); // 2 bytes, total 4
+ consumer.longField("fontNumber", input.read_uint32()); // 4 bytes, total 8
+
+ consumer.intField("pitch", input.read_uint16()); // 2 bytes, total 10
+ consumer.intField("xHeight", input.read_uint16()); // 2 bytes, total 12
+ consumer.intField("style", input.read_uint16()); // 2 bytes, total 14
+ consumer.intField("typeFamily", input.read_uint16()); // 2 bytes, total 16
+ consumer.intField("capHeight", input.read_uint16()); // 2 bytes, total 18
+ consumer.intField("symbolSet", input.read_uint16()); // 2 bytes, total 20
+ consumer.stringField("typeface", input.readStringASCII(TtfTablePclt.TYPEFACE_CHARS));
+ // 16 bytes, total 36
+ consumer.stringField("characterComplement", input.readStringASCII(TtfTablePclt.CHARACTER_COMPLEMENT_CHARS));
+ // 8 bytes, total 44
+ consumer.stringField("fileName", input.readStringASCII(TtfTablePclt.FILE_NAME_CHARS));
+ // 6 bytes, total 50
+ consumer.byteField("strokeWeight", input.read_int8()); // 1 bytes, total 51
+ consumer.byteField("widthType", input.read_int8()); // 1 bytes, total 52
+ consumer.shortField("serifStyle", input.read_uint8()); // 1 bytes, total 53
+ }
+
+}
Property changes on: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/parse/TtfTablePcltParser.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-04-18 15:07:54
|
Revision: 13434
http://sourceforge.net/p/foray/code/13434
Author: victormote
Date: 2025-04-18 15:07:35 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Conform to aXSL change: Remove methods dependent on a Charset name for byte-to-char conversions.
Modified Paths:
--------------
trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfParser.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -111,11 +111,11 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, STD_CONFIG);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(5, actual.size());
- assertEquals("This", actual.get(0).toString());
- assertEquals("is", actual.get(1).toString());
- assertEquals("a", actual.get(2).toString());
- assertEquals("normal", actual.get(3).toString());
- assertEquals("sentence.", actual.get(4).toString());
+ assertEquals("This", actual.get(0).toAscii());
+ assertEquals("is", actual.get(1).toAscii());
+ assertEquals("a", actual.get(2).toAscii());
+ assertEquals("normal", actual.get(3).toAscii());
+ assertEquals("sentence.", actual.get(4).toAscii());
}
/**
@@ -127,11 +127,11 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(5, actual.size());
- assertEquals("This", actual.get(0).toString());
- assertEquals("is", actual.get(1).toString());
- assertEquals("a", actual.get(2).toString());
- assertEquals("normal", actual.get(3).toString());
- assertEquals("sentence.", actual.get(4).toString());
+ assertEquals("This", actual.get(0).toAscii());
+ assertEquals("is", actual.get(1).toAscii());
+ assertEquals("a", actual.get(2).toAscii());
+ assertEquals("normal", actual.get(3).toAscii());
+ assertEquals("sentence.", actual.get(4).toAscii());
}
/**
@@ -145,11 +145,11 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, STD_CONFIG);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(5, actual.size());
- assertEquals("This", actual.get(0).toString());
- assertEquals("is", actual.get(1).toString());
- assertEquals("a", actual.get(2).toString());
- assertEquals("normal", actual.get(3).toString());
- assertEquals("sentence.", actual.get(4).toString());
+ assertEquals("This", actual.get(0).toAscii());
+ assertEquals("is", actual.get(1).toAscii());
+ assertEquals("a", actual.get(2).toAscii());
+ assertEquals("normal", actual.get(3).toAscii());
+ assertEquals("sentence.", actual.get(4).toAscii());
}
/**
@@ -163,11 +163,11 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, STD_CONFIG);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(5, actual.size());
- assertEquals("This", actual.get(0).toString());
- assertEquals("is", actual.get(1).toString());
- assertEquals("a", actual.get(2).toString());
- assertEquals("normal", actual.get(3).toString());
- assertEquals("sentence.", actual.get(4).toString());
+ assertEquals("This", actual.get(0).toAscii());
+ assertEquals("is", actual.get(1).toAscii());
+ assertEquals("a", actual.get(2).toAscii());
+ assertEquals("normal", actual.get(3).toAscii());
+ assertEquals("sentence.", actual.get(4).toAscii());
}
/**
@@ -180,19 +180,19 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, STD_CONFIG);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(13, actual.size());
- assertEquals("Thi", actual.get(0).toString());
- assertEquals("]", actual.get(1).toString());
- assertEquals("s", actual.get(2).toString());
- assertEquals("{", actual.get(3).toString());
- assertEquals("}", actual.get(4).toString());
- assertEquals("is", actual.get(5).toString());
- assertEquals("[", actual.get(6).toString());
- assertEquals("]", actual.get(7).toString());
- assertEquals("a", actual.get(8).toString());
- assertEquals("normal", actual.get(9).toString());
- assertEquals("}", actual.get(10).toString());
- assertEquals("{", actual.get(11).toString());
- assertEquals("sentence.", actual.get(12).toString());
+ assertEquals("Thi", actual.get(0).toAscii());
+ assertEquals("]", actual.get(1).toAscii());
+ assertEquals("s", actual.get(2).toAscii());
+ assertEquals("{", actual.get(3).toAscii());
+ assertEquals("}", actual.get(4).toAscii());
+ assertEquals("is", actual.get(5).toAscii());
+ assertEquals("[", actual.get(6).toAscii());
+ assertEquals("]", actual.get(7).toAscii());
+ assertEquals("a", actual.get(8).toAscii());
+ assertEquals("normal", actual.get(9).toAscii());
+ assertEquals("}", actual.get(10).toAscii());
+ assertEquals("{", actual.get(11).toAscii());
+ assertEquals("sentence.", actual.get(12).toAscii());
}
/**
@@ -205,13 +205,13 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, STD_CONFIG);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(7, actual.size());
- assertEquals("]", actual.get(0).toString());
- assertEquals("[", actual.get(1).toString());
- assertEquals("This", actual.get(2).toString());
- assertEquals("is", actual.get(3).toString());
- assertEquals("a", actual.get(4).toString());
- assertEquals("normal", actual.get(5).toString());
- assertEquals("sentence.", actual.get(6).toString());
+ assertEquals("]", actual.get(0).toAscii());
+ assertEquals("[", actual.get(1).toAscii());
+ assertEquals("This", actual.get(2).toAscii());
+ assertEquals("is", actual.get(3).toAscii());
+ assertEquals("a", actual.get(4).toAscii());
+ assertEquals("normal", actual.get(5).toAscii());
+ assertEquals("sentence.", actual.get(6).toAscii());
}
/**
@@ -224,13 +224,13 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, STD_CONFIG);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(7, actual.size());
- assertEquals("This", actual.get(0).toString());
- assertEquals("is", actual.get(1).toString());
- assertEquals("a", actual.get(2).toString());
- assertEquals("normal", actual.get(3).toString());
- assertEquals("sentence.", actual.get(4).toString());
- assertEquals("]", actual.get(5).toString());
- assertEquals("[", actual.get(6).toString());
+ assertEquals("This", actual.get(0).toAscii());
+ assertEquals("is", actual.get(1).toAscii());
+ assertEquals("a", actual.get(2).toAscii());
+ assertEquals("normal", actual.get(3).toAscii());
+ assertEquals("sentence.", actual.get(4).toAscii());
+ assertEquals("]", actual.get(5).toAscii());
+ assertEquals("[", actual.get(6).toAscii());
}
/**
@@ -243,11 +243,11 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, CONFIG_WITH_ESCAPE);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(5, actual.size());
- assertEquals("\\[This", actual.get(0).toString());
- assertEquals("\\[is\\]", actual.get(1).toString());
- assertEquals("a", actual.get(2).toString());
- assertEquals("no\\]rmal", actual.get(3).toString());
- assertEquals("sentence.\\]", actual.get(4).toString());
+ assertEquals("\\[This", actual.get(0).toAscii());
+ assertEquals("\\[is\\]", actual.get(1).toAscii());
+ assertEquals("a", actual.get(2).toAscii());
+ assertEquals("no\\]rmal", actual.get(3).toAscii());
+ assertEquals("sentence.\\]", actual.get(4).toAscii());
}
/**
@@ -260,14 +260,14 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, CONFIG_WITH_ESCAPE);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(8, actual.size());
- assertEquals("\\\\", actual.get(0).toString());
- assertEquals("[", actual.get(1).toString());
- assertEquals("This", actual.get(2).toString());
- assertEquals("is", actual.get(3).toString());
- assertEquals("a", actual.get(4).toString());
- assertEquals("normal", actual.get(5).toString());
- assertEquals("sentence.\\\\", actual.get(6).toString());
- assertEquals("]", actual.get(7).toString());
+ assertEquals("\\\\", actual.get(0).toAscii());
+ assertEquals("[", actual.get(1).toAscii());
+ assertEquals("This", actual.get(2).toAscii());
+ assertEquals("is", actual.get(3).toAscii());
+ assertEquals("a", actual.get(4).toAscii());
+ assertEquals("normal", actual.get(5).toAscii());
+ assertEquals("sentence.\\\\", actual.get(6).toAscii());
+ assertEquals("]", actual.get(7).toAscii());
}
/**
@@ -280,8 +280,8 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, CONFIG_WITH_BALANCING);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(2, actual.size());
- assertEquals("abc", actual.get(0).toString());
- assertEquals(")", actual.get(1).toString());
+ assertEquals("abc", actual.get(0).toAscii());
+ assertEquals(")", actual.get(1).toAscii());
}
/**
@@ -294,8 +294,8 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, CONFIG_WITH_BALANCING);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(2, actual.size());
- assertEquals("abc (def)", actual.get(0).toString());
- assertEquals(")", actual.get(1).toString());
+ assertEquals("abc (def)", actual.get(0).toAscii());
+ assertEquals(")", actual.get(1).toAscii());
}
/**
@@ -310,16 +310,16 @@
final ByteSequenceTokenizer out = new ByteSequenceTokenizer(ba, STD_CONFIG);
final List<ByteSequence> actual = out.getRemainingTokens();
assertEquals(10, actual.size());
- assertEquals("<<", actual.get(0).toString());
- assertEquals("<", actual.get(1).toString());
- assertEquals("abc", actual.get(2).toString());
- assertEquals("<<", actual.get(3).toString());
- assertEquals("<", actual.get(4).toString());
- assertEquals("<<", actual.get(5).toString());
- assertEquals("<", actual.get(6).toString());
- assertEquals("def", actual.get(7).toString());
- assertEquals("<<", actual.get(8).toString());
- assertEquals("<", actual.get(9).toString());
+ assertEquals("<<", actual.get(0).toAscii());
+ assertEquals("<", actual.get(1).toAscii());
+ assertEquals("abc", actual.get(2).toAscii());
+ assertEquals("<<", actual.get(3).toAscii());
+ assertEquals("<", actual.get(4).toAscii());
+ assertEquals("<<", actual.get(5).toAscii());
+ assertEquals("<", actual.get(6).toAscii());
+ assertEquals("def", actual.get(7).toAscii());
+ assertEquals("<<", actual.get(8).toAscii());
+ assertEquals("<", actual.get(9).toAscii());
}
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -143,7 +143,7 @@
final StringBuilder p = new StringBuilder();
p.append(this.getSerializedId());
p.append(EOL);
- p.append(PdfConstants.OPEN_DICTIONARY);
+ p.append(PdfConstants.OPEN_DICTIONARY.toAscii());
p.append(EOL);
p.append("/Type /Catalog");
p.append(EOL);
@@ -167,9 +167,9 @@
p.append(this.names.pdfReference(doc));
p.append(EOL);
}
- p.append(PdfConstants.CLOSE_DICTIONARY);
+ p.append(PdfConstants.CLOSE_DICTIONARY.toAscii());
p.append(EOL);
- p.append(PdfConstants.KEYWORD_END_OBJECT);
+ p.append(PdfConstants.KEYWORD_END_OBJECT.toAscii());
p.append(EOL);
return new ByteArray(p);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfParser.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfParser.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfParser.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -496,7 +496,7 @@
/* The token is arbitrary text. We need to see what is under it in the stack. */
final ByteSequence subToken = tokenStack.pop();
if (PdfConstants.NAME_PREFIX.equals(subToken)) {
- objectStack.push(new PdfName(token.toString()));
+ objectStack.push(new PdfName(token.toAscii()));
} else if (PdfConstants.OPEN_COMMENT.equals(subToken)) {
/* We don't have any use for the comment right now, but, if we did, it should be captured here. */
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -181,7 +181,7 @@
builder.append(PdfObject.EOL);
builder.append(Long.toString(xrefPosition));
builder.append(PdfObject.EOL);
- builder.append(PdfConstants.DOCUMENT_END_MARKER.toString() + PdfObject.EOL);
+ builder.append(PdfConstants.DOCUMENT_END_MARKER.toAscii() + PdfObject.EOL);
builder.writeTo(output);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -109,7 +109,7 @@
@Override
public String toString() {
- return this.theSequence.toString();
+ return this.theSequence.toAscii();
}
/**
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -127,7 +127,7 @@
}
final StringBuilder builder = new StringBuilder();
- builder.append(PdfConstants.OPEN_DICTIONARY.toString());
+ builder.append(PdfConstants.OPEN_DICTIONARY.toAscii());
if (getDictionaryType() != null
&& getDictionaryType().length() > 0) {
builder.append(" /Type /");
@@ -146,13 +146,13 @@
builder.append("/");
builder.append(key);
builder.append(StringUtils.SINGLE_SPACE);
- builder.append(asPdf);
+ builder.append(asPdf.toAscii());
builder.append(EOL);
}
}
}
- builder.append(PdfConstants.CLOSE_DICTIONARY.toString());
+ builder.append(PdfConstants.CLOSE_DICTIONARY.toAscii());
builder.append(EOL);
return new ByteArray(builder);
}
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -136,7 +136,7 @@
assertTrue(actual instanceof PdfTextString);
final PdfTextString textString = (PdfTextString) actual;
- assertEquals("A simple string.", textString.getValue().toString());
+ assertEquals("A simple string.", textString.getValue().toAscii());
}
/**
@@ -153,7 +153,7 @@
assertTrue(actual instanceof PdfTextString);
final PdfTextString textString = (PdfTextString) actual;
- assertEquals(" A simple string.", textString.getValue().toString());
+ assertEquals(" A simple string.", textString.getValue().toAscii());
}
/**
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java 2025-04-18 12:33:29 UTC (rev 13433)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java 2025-04-18 15:07:35 UTC (rev 13434)
@@ -36,9 +36,9 @@
import java.io.IOException;
import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
/**
* Abstract superclass for byte sequence classes.
@@ -55,7 +55,7 @@
@Override
public String toString() {
- return new String(toArray(), java.nio.charset.Charset.forName("US-ASCII"));
+ return toAscii();
}
@Override
@@ -64,13 +64,13 @@
}
@Override
- public String toString(final String charsetName) throws UnsupportedEncodingException {
- return new String(toArray(), charsetName);
+ public String toAscii() {
+ return toString(StandardCharsets.US_ASCII);
}
@Override
public CharSequence charSubSequence(final int start, final int end) {
- return subSequence(start, end).toString();
+ return subSequence(start, end).toAscii();
}
@Override
@@ -79,12 +79,6 @@
}
@Override
- public CharSequence charSubSequence(final int start, final int end, final String charsetName)
- throws UnsupportedEncodingException {
- return subSequence(start, end).toString(charsetName);
- }
-
- @Override
public boolean equals(final Object other) {
if (other == null) {
return false;
@@ -632,12 +626,12 @@
@Override
public byte parseByte() {
- return Byte.parseByte(this.toString());
+ return Byte.parseByte(toAscii());
}
@Override
public byte parseByte(final int radix) {
- return Byte.parseByte(this.toString(), radix);
+ return Byte.parseByte(toAscii(), radix);
}
@Override
@@ -652,12 +646,12 @@
@Override
public short parseShort() {
- return Short.parseShort(this.toString());
+ return Short.parseShort(toAscii());
}
@Override
public short parseShort(final int radix) {
- return Short.parseShort(this.toString());
+ return Short.parseShort(toAscii());
}
@Override
@@ -672,12 +666,12 @@
@Override
public int parseInt() {
- return Integer.parseInt(this.toString());
+ return Integer.parseInt(toAscii());
}
@Override
public int parseInt(final int radix) {
- return Integer.parseInt(this.toString());
+ return Integer.parseInt(toAscii());
}
@Override
@@ -692,12 +686,12 @@
@Override
public long parseLong() {
- return Long.parseLong(this.toString());
+ return Long.parseLong(toAscii());
}
@Override
public long parseLong(final int radix) {
- return Long.parseLong(this.toString());
+ return Long.parseLong(toAscii());
}
@Override
@@ -712,7 +706,7 @@
@Override
public BigDecimal parseDecimal() {
- return new BigDecimal(this.toString());
+ return new BigDecimal(toAscii());
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 12:33:47
|
Revision: 13433
http://sourceforge.net/p/foray/code/13433
Author: victormote
Date: 2025-04-18 12:33:29 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Remove unneeded method returning the description of a parser.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/FontParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1FontParser.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-18 12:11:23 UTC (rev 13432)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-18 12:33:29 UTC (rev 13433)
@@ -90,12 +90,6 @@
/**
- * Provides some kind of description of this item, useful in user messages.
- * @return A description of the contents of this item.
- */
- String getDescription();
-
- /**
* Reads a String of stringSize bytes at the current location.
* @param stringSize The length, in bytes, of the String to be read.
* @param characterSet The encoding scheme to be used for interpreting the characters in the string.
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-18 12:11:23 UTC (rev 13432)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-18 12:33:29 UTC (rev 13433)
@@ -234,11 +234,6 @@
}
@Override
- public String getDescription() {
- throw new UnsupportedOperationException();
- }
-
- @Override
public final long readUnsignedInt() throws IOException {
long ret = readUnsignedByte();
ret = (ret << PrimitiveConstants.SHIFT_1_BYTE) + readUnsignedByte();
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java 2025-04-18 12:11:23 UTC (rev 13432)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java 2025-04-18 12:33:29 UTC (rev 13433)
@@ -100,9 +100,7 @@
final Type1FontParser parser = new Type1FontParserPfa(getRegisteredFontContent().createFontFileReader());
this.type1File = parser.parse();
} else {
- final String message = "Attempted to parse unknown Type1 font "
- + "type.\n" + reader.getRandomInput().getDescription();
- this.getLogger().error(message);
+ this.getLogger().error("Attempted to parse unknown Type1 font type.");
}
return this.type1File;
}
@@ -175,12 +173,10 @@
.createMetricsFileReader();
metricsFile = reader.parse();
if (metricsFile == null) {
- throw new FontException("Unknown Metric Format: "
- + reader.getRandomInput().getDescription());
+ throw new FontException("Unknown Metric Format");
}
if (metricsFile.getInternalEncoding() == null) {
- throw new FontException("Unusable Internal Encoding: "
- + reader.getRandomInput().getDescription());
+ throw new FontException("Unusable Internal Encoding");
}
return metricsFile;
} else {
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/FontParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/FontParser.java 2025-04-18 12:11:23 UTC (rev 13432)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/FontParser.java 2025-04-18 12:33:29 UTC (rev 13433)
@@ -170,7 +170,7 @@
this.fileFormat = FontFileFormat.OTF_CFF;
return;
}
- throw new FontException("Unsupported Font File Format: " + this.randomInput.getDescription());
+ throw new FontException("Unsupported Font File Format");
}
/**
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1FontParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1FontParser.java 2025-04-18 12:11:23 UTC (rev 13432)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1FontParser.java 2025-04-18 12:33:29 UTC (rev 13433)
@@ -133,14 +133,10 @@
*/
public Type1Font parse() throws FontException {
Type1Font font = null;
- try {
- parseBasics();
- final PsFontDictionary fontDictionary = this.parseFontDictionary();
- font = new Type1Font(isAsciiHex(), this.segments[0].content, this.segments[1].content,
+ parseBasics();
+ final PsFontDictionary fontDictionary = this.parseFontDictionary();
+ font = new Type1Font(isAsciiHex(), this.segments[0].content, this.segments[1].content,
this.segments[2].content, fontDictionary);
- } catch (final IOException e) {
- throw new FontException("Error parsing Type1 font.", e);
- }
return font;
}
@@ -149,18 +145,16 @@
* boundaries.
* @throws IOException For errors reading content.
*/
- private void parseBasics() throws IOException {
+ private void parseBasics() throws FontException {
try {
this.segments = computeSegmentBoundaries();
+ for (int index = 0; index < this.segments.length; index ++) {
+ final Segment segment = this.segments[index];
+ segment.content = getRawSegmentContent(segment);
+ }
} catch (final IOException e) {
- getLogger().error("Unable to parse basics of Type 1 file:\n"
- + " " + getRandomInput().getDescription().toString());
- throw new IllegalStateException(e);
+ throw new FontException(e);
}
- for (int index = 0; index < this.segments.length; index ++) {
- final Segment segment = this.segments[index];
- segment.content = getRawSegmentContent(segment);
- }
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 12:11:40
|
Revision: 13432
http://sourceforge.net/p/foray/code/13432
Author: victormote
Date: 2025-04-18 12:11:23 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Remove some no-longer-needed attic code, reworking and moving the substance of one test class back to active code.
Added Paths:
-----------
trunk/foray/foray-common/src/test/java/org/foray/common/sequence/
trunk/foray/foray-common/src/test/java/org/foray/common/sequence/ByteSequenceParserTests.java
Removed Paths:
-------------
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/
trunk/foray/foray-zz-attic/src/test/java/org/foray/common/
Added: trunk/foray/foray-common/src/test/java/org/foray/common/sequence/ByteSequenceParserTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/sequence/ByteSequenceParserTests.java (rev 0)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/sequence/ByteSequenceParserTests.java 2025-04-18 12:11:23 UTC (rev 13432)
@@ -0,0 +1,78 @@
+/*
+ * 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.common.sequence;
+
+import org.foray.primitive.sequence.ByteArray;
+
+import org.axsl.primitive.sequence.ByteSequence;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+/**
+ * Tests of {@link ByteSequenceParser}.
+ */
+public class ByteSequenceParserTests {
+
+
+ /**
+ * Create the object under test from an array of bytes.
+ * @param byteArray The content to be parsed.
+ * @return A parser ready to be tested.
+ */
+ private ByteSequenceParser createParser(final byte[] byteArray) {
+ final ByteSequence sequence = new ByteArray(byteArray);
+ return new ByteSequenceParser(sequence);
+ }
+
+ /**
+ * Test of {@link ByteSequenceParser#readShort()}.
+ * @throws IOException Not expected here.
+ */
+ @Test
+ public void testReadShort() throws IOException {
+ final byte[] bytes = {(byte) 0xFA, 0x23};
+ final ByteSequenceParser out = createParser(bytes);
+ assertEquals((short) 0xFA23, out.readShort());
+ }
+
+ /**
+ * Test of {@link ByteSequenceParser#readUnsignedShort()}.
+ * @throws IOException Not expected here.
+ */
+ @Test
+ public void testReadUnsignedShort() throws IOException {
+ final byte[] bytes = {(byte) 0xFA, 0x23};
+ final ByteSequenceParser out = createParser(bytes);
+ assertEquals(0xFA23, out.readUnsignedShort());
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/test/java/org/foray/common/sequence/ByteSequenceParserTests.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-04-18 11:52:44
|
Revision: 13431
http://sourceforge.net/p/foray/code/13431
Author: victormote
Date: 2025-04-18 11:52:26 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Allow ByteSequenceParser to parse all ByteSequences, not just ByteSequencePlus.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-18 11:13:49 UTC (rev 13430)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-18 11:52:26 UTC (rev 13431)
@@ -33,7 +33,6 @@
import org.axsl.constants.PrimitiveConstants;
import org.axsl.primitive.sequence.ByteSequence;
-import org.axsl.primitive.sequence.ByteSequencePlus;
import org.apache.commons.io.EndianUtils;
@@ -51,7 +50,7 @@
public class ByteSequenceParser implements RandomAccessInput {
/** The sequence being iterated. */
- private ByteSequencePlus sequence;
+ private ByteSequence sequence;
/** The current location in {@link #sequence}. */
private int index;
@@ -60,7 +59,7 @@
* Constructor.
* @param sequence The sequence being wrapped.
*/
- public ByteSequenceParser(final ByteSequencePlus sequence) {
+ public ByteSequenceParser(final ByteSequence sequence) {
this.sequence = sequence;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 11:14:07
|
Revision: 13430
http://sourceforge.net/p/foray/code/13430
Author: victormote
Date: 2025-04-18 11:13:49 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Remove no-longer-needed method.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputArray.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputFile.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputUrl.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-18 10:45:21 UTC (rev 13429)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/RandomAccessInput.java 2025-04-18 11:13:49 UTC (rev 13430)
@@ -30,7 +30,6 @@
import java.io.DataInput;
import java.io.IOException;
-import java.io.InputStream;
import java.io.RandomAccessFile;
import java.math.BigInteger;
import java.nio.charset.Charset;
@@ -97,13 +96,6 @@
String getDescription();
/**
- * Return the input as an InputStream.
- * @return An InputStream containing the input contents.
- * @exception IOException If an I/O error occurs.
- */
- InputStream getInputStream() throws IOException;
-
- /**
* Reads a String of stringSize bytes at the current location.
* @param stringSize The length, in bytes, of the String to be read.
* @param characterSet The encoding scheme to be used for interpreting the characters in the string.
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-18 10:45:21 UTC (rev 13429)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceParser.java 2025-04-18 11:13:49 UTC (rev 13430)
@@ -37,7 +37,6 @@
import org.apache.commons.io.EndianUtils;
-import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
@@ -241,11 +240,6 @@
}
@Override
- public InputStream getInputStream() {
- return new ByteArrayInputStream(this.sequence.toArray());
- }
-
- @Override
public final long readUnsignedInt() throws IOException {
long ret = readUnsignedByte();
ret = (ret << PrimitiveConstants.SHIFT_1_BYTE) + readUnsignedByte();
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java 2025-04-18 10:45:21 UTC (rev 13429)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java 2025-04-18 11:13:49 UTC (rev 13430)
@@ -31,7 +31,6 @@
import org.foray.common.Environment;
import org.foray.common.data.BoundingBoxUtils;
import org.foray.font.config.RegisteredFontContent;
-import org.foray.font.format.FontParser;
import org.foray.font.format.Kerning;
import org.foray.font.format.Panose4a;
@@ -51,6 +50,7 @@
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
/**
* Handles interface of system (AWT) fonts to the client application.
@@ -377,12 +377,10 @@
SystemFont.INITIAL_FONT_SIZE);
}
Font returnedFont;
- final FontParser fontFileReader = this.getRegisteredFontContent().createFontFileReader();
- if (fontFileReader != null) {
- returnedFont = createFontFromInput(fontFileReader);
- if (returnedFont != null) {
- return returnedFont;
- }
+ final URL fontLocation = getRegisteredFontContent().getFontFileSource();
+ returnedFont = createFontFromInput(fontLocation);
+ if (returnedFont != null) {
+ return returnedFont;
}
/*
* Either no font file is available, or creating an awt font from
@@ -409,13 +407,15 @@
/**
* Creates a java.awt.Font instance from a URL.
- * @param fontFileReader The reader to use to obtain the font content.
+ * @param fontLocation The location of the font file.
* @return The Font created from fontURL.
* @throws FontException If the font cannot be created.
*/
- private Font createFontFromInput(final FontParser fontFileReader) throws FontException {
- final FreeStandingFont fsf =
- this.getRegisteredFontContent().getFreeStandingFont();
+ private Font createFontFromInput(final URL fontLocation) throws FontException {
+ if (fontLocation == null) {
+ return null;
+ }
+ final FreeStandingFont fsf = this.getRegisteredFontContent().getFreeStandingFont();
if (fsf == null) {
return null;
}
@@ -425,14 +425,13 @@
return null;
}
Font newFont = null;
- getLogger().debug("Create AWT font from: \n " + fontFileReader.getRandomInput().getDescription());
+ getLogger().debug("Create AWT font from: " + fontLocation.toString());
InputStream fontStream = null;
try {
- fontStream = fontFileReader.getRandomInput().getInputStream();
+ fontStream = fontLocation.openStream();
newFont = Font.createFont(fontFormat, fontStream);
} catch (final IOException e) {
- throw new FontException("Error reading input stream for: \n "
- + fontFileReader.getRandomInput().getDescription(), e);
+ throw new FontException("Error reading input stream for: " + fontLocation.toString());
} catch (final IllegalArgumentException iae) {
/* Ignore this. This just means that the fontFormat is not one that
* java recognizes, probably because the runtime is lower than
Modified: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputArray.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputArray.java 2025-04-18 10:45:21 UTC (rev 13429)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputArray.java 2025-04-18 11:13:49 UTC (rev 13430)
@@ -32,7 +32,6 @@
import org.apache.commons.io.IOUtils;
-import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
@@ -243,9 +242,4 @@
return this.description;
}
- @Override
- public InputStream getInputStream() {
- return new ByteArrayInputStream(this.byteArray);
- }
-
}
Modified: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputFile.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputFile.java 2025-04-18 10:45:21 UTC (rev 13429)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputFile.java 2025-04-18 11:13:49 UTC (rev 13430)
@@ -29,9 +29,7 @@
package org.foray.common.io;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.RandomAccessFile;
/**
@@ -156,9 +154,4 @@
return this.file.getPath();
}
- @Override
- public InputStream getInputStream() throws IOException {
- return new FileInputStream(this.file);
- }
-
}
Modified: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputUrl.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputUrl.java 2025-04-18 10:45:21 UTC (rev 13429)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/RandomAccessInputUrl.java 2025-04-18 11:13:49 UTC (rev 13430)
@@ -68,7 +68,10 @@
if (this.array != null) {
return;
}
- final InputStream input = this.getInputStream();
+ if (this.url == null) {
+ return;
+ }
+ final InputStream input = this.url.openStream();
final byte[] theBytes = IoUtil.toByteArray(input, 20000);
this.array = new RandomAccessInputArray(this.url.toExternalForm(), theBytes);
}
@@ -192,9 +195,4 @@
return this.array.getDescription();
}
- @Override
- public InputStream getInputStream() throws IOException {
- return this.url.openStream();
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 10:45:38
|
Revision: 13429
http://sourceforge.net/p/foray/code/13429
Author: victormote
Date: 2025-04-18 10:45:21 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Rename method for clarity.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java
trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java 2025-04-18 10:39:03 UTC (rev 13428)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java 2025-04-18 10:45:21 UTC (rev 13429)
@@ -88,9 +88,9 @@
private static final float SUPERSCRIPT_SHIFT_FACTOR = .6666666666666666667f;
/**
- * The RegisteredFont that is attached to this Font instance.
+ * The RegisteredFontContent that is attached to this Font instance.
*/
- private RegisteredFontContent registeredFont = null;
+ private RegisteredFontContent registeredFontContent = null;
/**
* Constructor.
@@ -97,7 +97,7 @@
* @param rf The parent registered font.
*/
protected Font4a(final RegisteredFontContent rf) {
- this.registeredFont = rf;
+ this.registeredFontContent = rf;
}
@Override
@@ -255,8 +255,8 @@
* Return the parent registered font.
* @return The registered font.
*/
- public RegisteredFontContent getRegisteredFont() {
- return this.registeredFont;
+ public RegisteredFontContent getRegisteredFontContent() {
+ return this.registeredFontContent;
}
/**
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java 2025-04-18 10:39:03 UTC (rev 13428)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java 2025-04-18 10:45:21 UTC (rev 13429)
@@ -150,7 +150,7 @@
/* The font and/or metrics may not have been parsed yet. */
return this.fontName;
}
- return this.getRegisteredFont().getConfiguredFontName();
+ return this.getRegisteredFontContent().getConfiguredFontName();
}
@Override
@@ -168,7 +168,7 @@
&& ! this.postscriptName.equals("")) {
return this.postscriptName;
}
- return getRegisteredFont().getConfiguredFontName();
+ return getRegisteredFontContent().getConfiguredFontName();
}
@Override
@@ -250,11 +250,11 @@
return false;
}
/* Don't try to embed unless we have been told to. */
- if (! getRegisteredFont().isEmbedding()) {
+ if (! getRegisteredFontContent().isEmbedding()) {
return false;
}
/* If the fontFile exists, embed it. */
- if (getRegisteredFont().hasFontContent()) {
+ if (getRegisteredFontContent().hasFontContent()) {
return true;
}
return false;
@@ -274,7 +274,7 @@
return false;
}
/* Only subset if we have been told to. */
- return getRegisteredFont().isSubsetting();
+ return getRegisteredFontContent().isSubsetting();
}
/**
@@ -283,7 +283,7 @@
* @throws FontException For errors opening the input stream.
*/
protected InputStream getFontInputStream() throws FontException {
- final URL contentLocation = getRegisteredFont().getFontFileSource();
+ final URL contentLocation = getRegisteredFontContent().getFontFileSource();
if (contentLocation == null) {
return null;
}
@@ -370,7 +370,7 @@
* is none, return null.
*/
public SystemFont systemFontManifestation() {
- return this.getRegisteredFont().getSystemFont();
+ return this.getRegisteredFontContent().getSystemFont();
}
/**
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-04-18 10:39:03 UTC (rev 13428)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsTrueTypeFont.java 2025-04-18 10:45:21 UTC (rev 13429)
@@ -100,8 +100,8 @@
*/
public void parseFont() throws FontException, IOException {
final TrueTypeContainer ttfFile = (TrueTypeContainer)
- getRegisteredFont().createFontFileReader().parseFontFile();
- final String fontName = getRegisteredFont().getTTCName();
+ getRegisteredFontContent().createFontFileReader().parseFontFile();
+ final String fontName = getRegisteredFontContent().getTTCName();
try {
this.ttf = ttfFile.getTTFFont(fontName);
} catch (final IOException e) {
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java 2025-04-18 10:39:03 UTC (rev 13428)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FsType1Font.java 2025-04-18 10:45:21 UTC (rev 13429)
@@ -92,12 +92,12 @@
if (this.type1File != null) {
return this.type1File;
}
- final FontParser reader = getRegisteredFont().createFontFileReader();
+ final FontParser reader = getRegisteredFontContent().createFontFileReader();
if (reader.getFileFormat() == FontFileFormat.TYPE1_PFB) {
- final Type1FontParser parser = new Type1FontParserPfb(getRegisteredFont().createFontFileReader());
+ final Type1FontParser parser = new Type1FontParserPfb(getRegisteredFontContent().createFontFileReader());
this.type1File = parser.parse();
} else if (reader.getFileFormat() == FontFileFormat.TYPE1_PFA) {
- final Type1FontParser parser = new Type1FontParserPfa(getRegisteredFont().createFontFileReader());
+ final Type1FontParser parser = new Type1FontParserPfa(getRegisteredFontContent().createFontFileReader());
this.type1File = parser.parse();
} else {
final String message = "Attempted to parse unknown Type1 font "
@@ -145,7 +145,7 @@
if (this.getInternalEncoding() == null) {
final String encodingName = this.metricsFile.getEncoding();
PsEncoding encoding = null;
- final PsServer psServer = this.getRegisteredFont().getFontServer().getPsServer();
+ final PsServer psServer = this.getRegisteredFontContent().getFontServer().getPsServer();
final PsEncoding.Predefined predefined = PsEncoding.Predefined.findByName(encodingName);
if (encodingName.equals("StandardEncoding")
|| encodingName.equals("AdobeStandardEncoding")) {
@@ -168,10 +168,10 @@
*/
private Type1Metrics getMetricsFile() throws IOException, FontException {
Type1Metrics metricsFile = null;
- final URL serializedMetricsFile = this.getRegisteredFont()
+ final URL serializedMetricsFile = this.getRegisteredFontContent()
.getSerializedMetricsFile();
if (serializedMetricsFile == null) {
- final Type1MetricsParser reader = this.getRegisteredFont()
+ final Type1MetricsParser reader = this.getRegisteredFontContent()
.createMetricsFileReader();
metricsFile = reader.parse();
if (metricsFile == null) {
@@ -203,7 +203,7 @@
*/
private Type1Metrics deserializeMetricsFile() throws IOException,
ClassNotFoundException {
- final URL serializedMetricsFile = this.getRegisteredFont()
+ final URL serializedMetricsFile = this.getRegisteredFontContent()
.getSerializedMetricsFile();
final InputStream is = serializedMetricsFile.openStream();
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java 2025-04-18 10:39:03 UTC (rev 13428)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java 2025-04-18 10:45:21 UTC (rev 13429)
@@ -276,7 +276,7 @@
* @return The font server.
*/
public FontServer4a getFontServer() {
- return this.getRegisteredFont().getFontServer();
+ return this.getRegisteredFontContent().getFontServer();
}
/**
@@ -368,7 +368,7 @@
* font. This usually indicated a font registration error.
*/
public java.awt.Font createFont() throws FontException {
- final String systemName = this.getRegisteredFont().getSystemName();
+ final String systemName = this.getRegisteredFontContent().getSystemName();
/* If present, system-name has the priority */
if (systemName != null && !systemName.equals("")) {
/* Since we are using the font name instead of the font-family
@@ -377,7 +377,7 @@
SystemFont.INITIAL_FONT_SIZE);
}
Font returnedFont;
- final FontParser fontFileReader = this.getRegisteredFont().createFontFileReader();
+ final FontParser fontFileReader = this.getRegisteredFontContent().createFontFileReader();
if (fontFileReader != null) {
returnedFont = createFontFromInput(fontFileReader);
if (returnedFont != null) {
@@ -388,9 +388,11 @@
* Either no font file is available, or creating an awt font from
* the font file has failed
*/
- final org.axsl.font.Font fsf = getRegisteredFont().getFreeStandingFont();
+ final org.axsl.font.Font fsf = getRegisteredFontContent().getFreeStandingFont();
if (fsf == null) {
- throw new FontException("Cannot find a system font for " + getRegisteredFont().getConfiguredFontName());
+ final String message = "Cannot find a system font for " +
+ getRegisteredFontContent().getConfiguredFontName();
+ throw new FontException(message);
}
returnedFont = new Font(fsf.getFontName(), Font.PLAIN,
SystemFont.INITIAL_FONT_SIZE);
@@ -413,7 +415,7 @@
*/
private Font createFontFromInput(final FontParser fontFileReader) throws FontException {
final FreeStandingFont fsf =
- this.getRegisteredFont().getFreeStandingFont();
+ this.getRegisteredFontContent().getFreeStandingFont();
if (fsf == null) {
return null;
}
@@ -478,7 +480,7 @@
* is none, return null.
*/
public FreeStandingFont freeStandingFontManifestation() {
- return this.getRegisteredFont().getFreeStandingFont();
+ return this.getRegisteredFontContent().getFreeStandingFont();
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 10:39:20
|
Revision: 13428
http://sourceforge.net/p/foray/code/13428
Author: victormote
Date: 2025-04-18 10:39:03 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Get font location directly instead of by creating a parser.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/config/RegisteredFontContent.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java 2025-04-18 00:16:24 UTC (rev 13427)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java 2025-04-18 10:39:03 UTC (rev 13428)
@@ -29,7 +29,6 @@
package org.foray.font;
import org.foray.font.config.RegisteredFontContent;
-import org.foray.font.format.FontParser;
import org.foray.font.format.Kerning;
import org.foray.font.format.Panose4a;
@@ -46,6 +45,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
/**
* Base class for all fonts that are registered independently of the operating
@@ -283,15 +283,15 @@
* @throws FontException For errors opening the input stream.
*/
protected InputStream getFontInputStream() throws FontException {
- final FontParser fontFileReader = this.getRegisteredFont().createFontFileReader();
- if (fontFileReader == null) {
+ final URL contentLocation = getRegisteredFont().getFontFileSource();
+ if (contentLocation == null) {
return null;
}
InputStream instream = null;
try {
- instream = fontFileReader.getRandomInput().getInputStream();
+ instream = contentLocation.openStream();
} catch (final IOException e1) {
- getLogger().error("Unable to embed: " + fontFileReader.getRandomInput().getDescription());
+ getLogger().error("Unable to embed: " + contentLocation.toString());
}
return instream;
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/RegisteredFontContent.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/RegisteredFontContent.java 2025-04-18 00:16:24 UTC (rev 13427)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/RegisteredFontContent.java 2025-04-18 10:39:03 UTC (rev 13428)
@@ -542,4 +542,12 @@
return metricsFileDescription;
}
+ /**
+ * Returns the location of the font file content.
+ * @return The location of the font file content.
+ */
+ public URL getFontFileSource() {
+ return fontFileSource;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-04-18 00:16:41
|
Revision: 13427
http://sourceforge.net/p/foray/code/13427
Author: victormote
Date: 2025-04-18 00:16:24 +0000 (Fri, 18 Apr 2025)
Log Message:
-----------
Remove generated TTC file. Reactivate TTC test using a new file.
Modified Paths:
--------------
trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeCollectionParserTests.java
trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java
Removed Paths:
-------------
trunk/foray/foray-font/src/test/resources/source-dejavu/generated/
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeCollectionParserTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeCollectionParserTests.java 2025-04-17 23:25:07 UTC (rev 13426)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeCollectionParserTests.java 2025-04-18 00:16:24 UTC (rev 13427)
@@ -37,11 +37,11 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.InputStream;
+import java.math.BigDecimal;
/**
* Tests of our ability to parse a TrueType Collection file.
@@ -49,16 +49,13 @@
public class TrueTypeCollectionParserTests {
/**
- * Test of ability to parse a TTC file. The font tested here is the same one tested in
- * {@link TrueTypeFontParserTests#testDejaVuSansExtraLight()}, but here we are testing the values parsed out of
- * a TTC file (the other test is for values parsed out of a TTF file).
+ * Test of ability to parse a TTC file.
* @throws IOException Not expected here.
* @throws FontException Not expected here.
*/
@Test
- @Disabled
public void test01() throws IOException, FontException {
- final String path = "/source-dejavu/generated/DejaVuSans.ttc";
+ final String path = "/source-windows-classic-samples/Selwk.ttc";
final InputStream inputStream = getClass().getResourceAsStream(path);
assertNotNull(inputStream);
final FontServer4a fontServer = new FontServer4a();
@@ -70,23 +67,44 @@
final TrueTypeCollection ttc = (TrueTypeCollection) fontContent;
final String[] fontList = ttc.getChildFontNames();
- assertEquals(5, fontList.length);
- assertEquals("DejaVu Sans Bold", fontList[0]);
- assertEquals("DejaVu Sans", fontList[1]);
- assertEquals("DejaVu Sans Oblique", fontList[2]);
- assertEquals("DejaVu Sans ExtraLight", fontList[3]);
- assertEquals("DejaVu Sans Bold Oblique", fontList[4]);
+ /* From observation in Fontlab 8.4. */
+ assertEquals(4, fontList.length);
+ assertEquals("Selwk A", fontList[0]);
+ assertEquals("Selwk B", fontList[1]);
+ assertEquals("Selwk C", fontList[2]);
+ assertEquals("Selwk D", fontList[3]);
- final TrueTypeFont ttfFont = ttc.getTTFFont("DejaVu Sans ExtraLight");
+ /* Pick one file to test the metrics. */
+ final TrueTypeFont ttfFont = ttc.getTTFFont("Selwk C");
assertNotNull(ttfFont);
- /* Delegate assertions to a method that is shared with other classes. */
- TrueTypeFontParserTests.assertionsForDejaVuSansExtraLightSet1(ttfFont);
+ /* The following values were obtained by opening the TTF file (not the TTC) in FontLab Studio 5.0.4. */
+ final String expectedPostScriptName = "SelwkC";
+ final String expectedFullName = "Selwk C";
+ /* Style Group */
+ final String expectedFamilyName = "Selwk C";
+ /* Style Name */
+ final String expectedSubtypeName = "Regular";
+ /* Family Dimensions / Ascender */
+ final int expectedAscender = 1491;
+ /* Family Dimensions / Descender */
+ final int expectedDescender = -431;
+ /* Font Dimensions / x height */
+ final int expectedXHeight = 1024;
+ /* Font Dimensions / Caps height */
+ final int expectedCapHeight = 1434;
+ /* Font Dimensions / Italic angle */
+ final BigDecimal expectedItalicAngle = new BigDecimal("0.0");
- /* The following set of assertions would fail. We examined the TTC file directly, and the values just seem to
- * be wrong. This could be a bug in the FontForge software that was used to create the TTC file, but we are
- * not sure. */
-// TrueTypeFontParserTests.assertionsForDejaVuSansExtraLightSet2(ttfFont);
+ assertEquals(expectedPostScriptName, ttfFont.getNameTable().getPostscriptName());
+ assertEquals(expectedFullName, ttfFont.getNameTable().getFullName());
+ assertEquals(expectedFamilyName, ttfFont.getNameTable().getFamilyName());
+ assertEquals(expectedSubtypeName, ttfFont.getNameTable().getSubFamilyName());
+ assertEquals(expectedAscender, ttfFont.getAscender());
+ assertEquals(expectedDescender, ttfFont.getDescender());
+ assertEquals(expectedXHeight, ttfFont.getXHeight());
+ assertEquals(expectedCapHeight, ttfFont.getCapHeight());
+ assertEquals(expectedItalicAngle, ttfFont.getItalicAngle());
}
}
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java 2025-04-17 23:25:07 UTC (rev 13426)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/TrueTypeFontParserTests.java 2025-04-18 00:16:24 UTC (rev 13427)
@@ -39,7 +39,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.IOException;
@@ -57,7 +56,7 @@
* Make assertions about the data parsed from the DejaVu Sans Extra Light font.
* @param ttfFont The font instance to be tested.
*/
- public static void assertionsForDejaVuSansExtraLightSet1(final TrueTypeFont ttfFont) {
+ public static void assertionsForDejaVuSansExtraLight(final TrueTypeFont ttfFont) {
/* The following values were obtained by opening the TTF file in FontLab 8.4. */
final String expectedPostScriptName = "DejaVuSans-ExtraLight";
@@ -97,14 +96,6 @@
}
/**
- * Make assertions about the data parsed from the DejaVu Sans Extra Light font.
- * @param ttfFont The font instance to be tested.
- */
- public static void assertionsForDejaVuSansExtraLightSet2(final TrueTypeFont ttfFont) {
-
- }
-
- /**
* Test our ability to read a TrueType Font file.
* @throws IOException Not expected here.
* @throws FontException Not expected here.
@@ -125,13 +116,11 @@
assertNotNull(ttfFont);
/* Delegate assertions to a method that can be shared with other classes. */
- assertionsForDejaVuSansExtraLightSet1(ttfFont);
- assertionsForDejaVuSansExtraLightSet2(ttfFont);
+ assertionsForDejaVuSansExtraLight(ttfFont);
}
-
/**
* Make assertions about the data parsed from the Selawik font.
* @param ttfFont The font instance to be tested.
@@ -140,13 +129,20 @@
/* The following values were obtained by opening the TTF file (not the TTC) in FontLab Studio 5.0.4. */
final String expectedPostScriptName = "Selawik-Regular";
final String expectedFullName = "Selawik";
+ /* Style Group */
final String expectedFamilyName = "Selawik";
- final String expectedSubtypeName = "Regular"; //Style Name
- final int expectedAscender = 1491; //Family Dimensions / Ascender
- final int expectedDescender = -431; //Family Dimensions / Descender
- final int expectedXHeight = 1024; //Key dimensions
- final int expectedCapHeight = 1434; //Key dimensions
- final BigDecimal expectedItalicAngle = new BigDecimal("0.0"); //Key dimensions
+ /* Style Name */
+ final String expectedSubtypeName = "Regular";
+ /* Family Dimensions / Ascender */
+ final int expectedAscender = 1491;
+ /* Family Dimensions / Descender */
+ final int expectedDescender = -431;
+ /* Font Dimensions / x height */
+ final int expectedXHeight = 1024;
+ /* Font Dimensions / Caps height */
+ final int expectedCapHeight = 1434;
+ /* Font Dimensions / Italic angle */
+ final BigDecimal expectedItalicAngle = new BigDecimal("0.0");
assertEquals(expectedPostScriptName, ttfFont.getNameTable().getPostscriptName());
assertEquals(expectedFullName, ttfFont.getNameTable().getFullName());
@@ -165,7 +161,6 @@
* @throws FontException Not expected here.
*/
@Test
- @Disabled
public void testWindowsClassic_selawk() throws IOException, FontException {
final String path = "/source-windows-classic-samples/selawk.ttf";
final InputStream inputStream = getClass().getResourceAsStream(path);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|