foray-commit Mailing List for FOray (Page 4)
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-06-02 16:23:01
|
Revision: 13803
http://sourceforge.net/p/foray/code/13803
Author: victormote
Date: 2025-06-02 16:22:57 +0000 (Mon, 02 Jun 2025)
Log Message:
-----------
Roll up PsInputFile into PsFile. Some temporary broken tests.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoPanel.java
Removed Paths:
-------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java 2025-06-02 16:12:46 UTC (rev 13802)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java 2025-06-02 16:22:57 UTC (rev 13803)
@@ -33,6 +33,7 @@
import org.axsl.primitive.sequence.ByteSequence;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
/**
@@ -41,11 +42,14 @@
* source, like standard input, or 3) a filter that sits on top of another
* PsFile instance.
*/
-public class PsFile implements PsObjectComposite {
+public class PsFile extends PsInputStream implements PsObjectComposite {
/** The encapsulated file for this object, if any. */
private File value;
+ /** The encapsulated input stream. */
+ private FileInputStream fis;
+
/** The encapsulated input source for this object, if any. */
private PsInputStream input;
@@ -216,4 +220,18 @@
return this.value;
}
+ @Override
+ public int read() throws IOException {
+ if (this.fis == null) {
+ this.fis = new FileInputStream(this.value);
+ }
+ return this.fis.read();
+ }
+
+ @Override
+ ByteSequence providePostScriptInput() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
Deleted: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-06-02 16:12:46 UTC (rev 13802)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-06-02 16:22:57 UTC (rev 13803)
@@ -1,77 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-/* Known contributors:
- * Jeremias Maerki
- */
-
-package org.foray.ps;
-
-import org.foray.primitive.sequence.ByteArray;
-
-import org.axsl.constants.MeasurementConstants;
-import org.axsl.primitive.sequence.ByteSequence;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * An implementation of PsInput that wraps a java.io.File instance.
- * @see PsInputStream
- */
-public class PsInputFile extends PsInputStream {
-
- /** The encapsulated input stream. */
- private InputStream in;
-
- /**
- * Basic constructor.
- * @param input The File instance that should be used as standard input to the PsInterpreter.
- */
- public PsInputFile(final InputStream input) {
- this.in = new java.io.BufferedInputStream(input);
- }
-
- @Override
- public ByteSequence providePostScriptInput() throws IOException {
- final byte[] buf = new byte[MeasurementConstants.BYTES_PER_KILOBYTE * 2];
- final int bytesRead = this.in.read(buf);
- if (bytesRead <= 0) {
- return null;
- }
- final byte[] trimmed = new byte[bytesRead];
- System.arraycopy(buf, 0, trimmed, 0, bytesRead);
- return new ByteArray(trimmed);
- }
-
- @Override
- public int read() throws IOException {
- return this.in.read();
- }
-
-}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2025-06-02 16:12:46 UTC (rev 13802)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2025-06-02 16:22:57 UTC (rev 13803)
@@ -55,7 +55,7 @@
* @throws IOException For errors opening the file.
*/
public PsInputStream createPsInput(final InputStream input) throws IOException {
- return new PsInputFile(input);
+ return new PsGenericInputStream(input);
}
@Override
@@ -80,7 +80,7 @@
}
final org.foray.ps.PsSystemDict4a foraySystemDict = (org.foray.ps.PsSystemDict4a) systemDict;
try {
- final PsInputStream psInput = new PsInputFile(input);
+ final PsInputStream psInput = new PsGenericInputStream(input);
return new PsInterpreter4a(psInput, foraySystemDict);
} catch (final PsInterpreterException4a e) {
/* The reason for this exception is the possibility of a null key being added to the various dictionaries
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-02 16:12:46 UTC (rev 13802)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-02 16:22:57 UTC (rev 13803)
@@ -1887,6 +1887,7 @@
if (! (object instanceof PsFile)) {
throw new PsOperatorException(PsError.TYPECHECK, PsOperator.READSTRING);
}
+ @SuppressWarnings("resource")
final PsFile file = (PsFile) object;
final ByteArrayBuilder builder = new ByteArrayBuilder(string.getValue().length());
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoPanel.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoPanel.java 2025-06-02 16:12:46 UTC (rev 13802)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/demo/DemoPanel.java 2025-06-02 16:22:57 UTC (rev 13803)
@@ -29,7 +29,8 @@
package org.foray.ps.java2d.demo;
-import org.foray.ps.PsInputFile;
+import org.foray.ps.PsFile;
+import org.foray.ps.PsInputStream;
import org.foray.ps.PsInterpreter4a;
import org.foray.ps.PsInterpreterException4a;
import org.foray.ps.java2d.Java2dSystemDict;
@@ -42,7 +43,6 @@
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
@@ -115,10 +115,8 @@
throws PsInterpreterException4a, IOException {
final Dimension dim = rect.getSize();
final Graphics2D g2d = (Graphics2D) graphics;
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
- RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
final AffineTransform baktrans = g2d.getTransform();
g2d.translate(rect.getX(), rect.getY());
@@ -127,9 +125,7 @@
g2d.scale(2, 2);
final File file = new File(this.fileName);
- final FileInputStream fis = new FileInputStream(file);
- PsInputFile eps = null;
- eps = new PsInputFile(fis);
+ final PsInputStream eps = new PsFile(file);
final Java2dSystemDict j2dSystemDict = new Java2dSystemDict(g2d);
final PsInterpreter4a interpreter = new PsInterpreter4a(eps, j2dSystemDict);
interpreter.process();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-02 16:12:53
|
Revision: 13802
http://sourceforge.net/p/foray/code/13802
Author: victormote
Date: 2025-06-02 16:12:46 +0000 (Mon, 02 Jun 2025)
Log Message:
-----------
Roll up PsInputString into PsString. Some temporary broken tests.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
Removed Paths:
-------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
Deleted: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-06-02 13:19:04 UTC (rev 13801)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-06-02 16:12:46 UTC (rev 13802)
@@ -1,77 +0,0 @@
-/*
- * 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.ps;
-
-import org.foray.primitive.sequence.ByteArray;
-
-import org.axsl.primitive.sequence.ByteSequence;
-
-import java.io.IOException;
-
-/**
- * A {@link PsInputStream} implementation that simply wraps a String.
- */
-public class PsInputString extends PsInputStream {
-
- /** The String whose content is the PostScript input. */
- private PsString wrappedString;
-
- /** Flag indicating whether this content has already been consumed or not. */
- private boolean hasBeenConsumed = false;
-
- /** Index to the next char in the stream. */
- private int nextIndex = 0;
-
- /**
- * Constructor.
- * @param theString The String whose content is the PostScript input.
- */
- public PsInputString(final PsString theString) {
- this.wrappedString = theString;
- }
-
- @Override
- public ByteSequence providePostScriptInput() {
- if (this.hasBeenConsumed) {
- return null;
- }
- this.hasBeenConsumed = true;
- return new ByteArray(this.wrappedString.getValue());
- }
-
- @Override
- public int read() throws IOException {
- if (this.nextIndex >= this.wrappedString.size()) {
- return -1;
- }
- nextIndex ++;
- return this.wrappedString.getValue().byteAt(nextIndex - 1);
- }
-
-}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-06-02 13:19:04 UTC (rev 13801)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-06-02 16:12:46 UTC (rev 13802)
@@ -358,9 +358,7 @@
return;
}
/* Otherwise, execute it. */
- final PsInputString stringInput = new PsInputString(psString);
- final PsFile inputFile = new PsFile(stringInput);
- this.executionStack.push(inputFile);
+ this.executionStack.push(psString);
return;
}
if (currentExecution instanceof PsOperator) {
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java 2025-06-02 13:19:04 UTC (rev 13801)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java 2025-06-02 16:12:46 UTC (rev 13802)
@@ -30,6 +30,10 @@
import org.foray.primitive.sequence.ByteArray;
+import org.axsl.primitive.sequence.ByteSequence;
+
+import java.io.IOException;
+
/**
* Class representing a "string" PostScript object.
* A PostScript string is really an array of unsigned bytes that are not required to adhere to any character set or even
@@ -36,7 +40,7 @@
* be used as string characters.
* @see "PostScript Language Reference, Third Editions, Section 3.3.7."
*/
-public class PsString implements PsObjectComposite {
+public class PsString extends PsInputStream implements PsObjectComposite {
/** The encapsulated value for this object. */
private ByteArray value;
@@ -48,6 +52,9 @@
/** The access permission for this object. */
private PsAccess access = PsAccess.UNLIMITED;
+ /** Index to the next char in the stream. */
+ private int nextIndex = 0;
+
/**
* Constructor.
* @param value The value to encapsulate.
@@ -168,4 +175,18 @@
return this.access;
}
+ @Override
+ public int read() throws IOException {
+ if (this.nextIndex >= size()) {
+ return -1;
+ }
+ nextIndex ++;
+ return this.value.byteAt(nextIndex - 1);
+ }
+
+ @Override
+ ByteSequence providePostScriptInput() throws IOException {
+ return null;
+ }
+
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-02 13:19:04 UTC (rev 13801)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-02 16:12:46 UTC (rev 13802)
@@ -1881,6 +1881,7 @@
if (! (object instanceof PsString)) {
throw new PsOperatorException(PsError.TYPECHECK, PsOperator.READSTRING);
}
+ @SuppressWarnings("resource")
final PsString string = (PsString) object;
object = popOperand(PsOperator.READSTRING);
if (! (object instanceof PsFile)) {
@@ -2373,6 +2374,7 @@
/* See PsLRM, 2nd Ed., documentation of the "exec" operator for an example of a string
* being made executable, and for a discussion of how an executable string is
* processed. */
+ @SuppressWarnings("resource")
final PsString psString = (PsString) object;
psString.setExecutable(true);
return;
@@ -3185,6 +3187,7 @@
this.getInterpreter().process();
}
} else if (stackObject instanceof PsString) {
+ @SuppressWarnings("resource")
final PsString string = (PsString) stackObject;
final byte[] chars = string.getValue().toArray();
for (int i = 0; i < chars.length; i++) {
@@ -3538,7 +3541,9 @@
}
} else if (object1 instanceof PsString) {
if (object2 instanceof PsString) {
+ @SuppressWarnings("resource")
final PsString string1 = (PsString) object1;
+ @SuppressWarnings("resource")
final PsString string2 = (PsString) object2;
final int compare = string1.getValue().compareToLtR(string2.getValue());
return compare;
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-06-02 13:19:04 UTC (rev 13801)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-06-02 16:12:46 UTC (rev 13802)
@@ -49,8 +49,7 @@
*/
private PsInputStream createPsInputFromString(final String inputString) {
final PsString psString = new PsString(new ByteArray(inputString));
- final PsInputString psInputString = new PsInputString(psString);
- return psInputString;
+ return psString;
}
/**
@@ -704,6 +703,7 @@
interpreter.process();
object = interpreter.getOperandStack().pop();
assertTrue(object instanceof PsString);
+ @SuppressWarnings("resource")
PsString psString = (PsString) object;
assertFalse(psString.isExecutable());
assertEquals(0, interpreter.getOperandStack().size());
@@ -1681,6 +1681,7 @@
assertEquals(1, interpreter.getOperandStack().size());
final PsObject object = interpreter.getOperandStack().pop();
assertTrue(object instanceof PsString);
+ @SuppressWarnings("resource")
final PsString theString = (PsString) object;
assertEquals("2", theString.getValue().toString());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-02 13:19:09
|
Revision: 13801
http://sourceforge.net/p/foray/code/13801
Author: victormote
Date: 2025-06-02 13:19:04 +0000 (Mon, 02 Jun 2025)
Log Message:
-----------
Add class for generic input streams.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsObject.java
Added Paths:
-----------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsGenericInputStream.java
Added: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsGenericInputStream.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsGenericInputStream.java (rev 0)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsGenericInputStream.java 2025-06-02 13:19:04 UTC (rev 13801)
@@ -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.ps;
+
+import org.axsl.primitive.sequence.ByteSequence;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Wraps an input stream that is neither a {@link PsFile} nor a {@link PsString}, suitable for handling generic
+ * {@link InputStream} instances and filters.
+ */
+public class PsGenericInputStream extends PsInputStream implements PsObject {
+
+ /** The wrapped input stream. */
+ private InputStream inputStream;
+
+ /**
+ * Constructor.
+ * @param inputStream The input stream to be wrapped.
+ */
+ public PsGenericInputStream(final InputStream inputStream) {
+ this.inputStream = inputStream;
+ }
+
+ @Override
+ public PsObject duplicate() {
+ return this;
+ }
+
+ @Override
+ public boolean isComposite() {
+ return true;
+ }
+
+ @Override
+ public boolean isExecutable() {
+ return true;
+ }
+
+ @Override
+ public boolean isComparable(final PsObject object) {
+ return false;
+ }
+
+ @Override
+ public PsName getTypeName() {
+ return new PsName("filetype", true, false);
+ }
+
+ @Override
+ ByteSequence providePostScriptInput() throws IOException {
+ return null;
+ }
+
+ @Override
+ public int read() throws IOException {
+ return this.inputStream.read();
+ }
+
+}
Property changes on: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsGenericInputStream.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsObject.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsObject.java 2025-06-02 12:30:22 UTC (rev 13800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsObject.java 2025-06-02 13:19:04 UTC (rev 13801)
@@ -65,7 +65,7 @@
/**
* Needed for the "type" operator.
- * @return The type name as defined in PSRM2, Chapter 8, "type" operator.
+ * @return The type name as defined in PostScript Language Reference, Third Editiion, Section 8.2, "type" operator.
*/
PsName getTypeName();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-02 12:30:33
|
Revision: 13800
http://sourceforge.net/p/foray/code/13800
Author: victormote
Date: 2025-06-02 12:30:22 +0000 (Mon, 02 Jun 2025)
Log Message:
-----------
Roll up PsFileReal into PsFile.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
Removed Paths:
-------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java 2025-06-02 12:07:41 UTC (rev 13799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFile.java 2025-06-02 12:30:22 UTC (rev 13800)
@@ -28,6 +28,11 @@
package org.foray.ps;
+import org.foray.primitive.sequence.ByteArray;
+
+import org.axsl.primitive.sequence.ByteSequence;
+
+import java.io.File;
import java.io.IOException;
/**
@@ -36,8 +41,14 @@
* source, like standard input, or 3) a filter that sits on top of another
* PsFile instance.
*/
-public abstract class PsFile implements PsObjectComposite {
+public class PsFile implements PsObjectComposite {
+ /** The encapsulated file for this object, if any. */
+ private File value;
+
+ /** The encapsulated input source for this object, if any. */
+ private PsInputStream input;
+
/** Indicates whether the file is open. */
private boolean fileIsOpen = true;
@@ -53,12 +64,24 @@
private PsAccess access = PsAccess.UNLIMITED;
/**
- * Constructor.
+ * Constructor for an instance that wraps a real file.
+ * @param file The File to be encapsulated.
*/
- public PsFile() {
+ public PsFile(final File file) {
super();
+ this.value = file;
}
+ /**
+ * Constructor for an instance that wraps an input source (like standard
+ * input).
+ * @param input The input to be encapsulated.
+ */
+ public PsFile(final PsInputStream input) {
+ super();
+ this.input = input;
+ }
+
@Override
public PsObject duplicate() {
return this;
@@ -102,7 +125,20 @@
* @return The next byte array for this file.
* @throws IOException For I/O Errors.
*/
- protected abstract byte[] getNextChunk() throws IOException;
+ protected byte[] getNextChunk() throws IOException {
+ byte[] tempChunk = getRemainingChunk();
+ if (tempChunk != null) {
+ return tempChunk;
+ }
+ if (this.input != null) {
+ final ByteSequence psInput = this.input.providePostScriptInput();
+ tempChunk = psInput == null ? null : new ByteArray(psInput).toArray();
+ } else if (this.value != null) {
+ // TODO: Handle i/o from real files
+ tempChunk = null;
+ }
+ return tempChunk;
+ }
/**
* Close the input file.
@@ -172,4 +208,12 @@
return this.access;
}
+ /**
+ * Returns the file.
+ * @return The file.
+ */
+ public File getFile() {
+ return this.value;
+ }
+
}
Deleted: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java 2025-06-02 12:07:41 UTC (rev 13799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java 2025-06-02 12:30:22 UTC (rev 13800)
@@ -1,93 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.ps;
-
-import org.foray.primitive.sequence.ByteArray;
-
-import org.axsl.primitive.sequence.ByteSequence;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * An instance of this class is really a wrapper around either a real file
- * or an input source, like standard input.
- */
-public class PsFileReal extends PsFile {
-
- /** The encapsulated file for this object, if any. */
- private File value;
-
- /** The encapsulated input source for this object, if any. */
- private PsInputStream input;
-
- /**
- * Constructor for an instance that wraps a real file.
- * @param file The File to be encapsulated.
- */
- public PsFileReal(final File file) {
- super();
- this.value = file;
- }
-
- /**
- * Constructor for an instance that wraps an input source (like standard
- * input).
- * @param input The input to be encapsulated.
- */
- public PsFileReal(final PsInputStream input) {
- super();
- this.input = input;
- }
-
- @Override
- protected byte[] getNextChunk() throws IOException {
- byte[] tempChunk = getRemainingChunk();
- if (tempChunk != null) {
- return tempChunk;
- }
- if (this.input != null) {
- final ByteSequence psInput = this.input.providePostScriptInput();
- tempChunk = psInput == null ? null : new ByteArray(psInput).toArray();
- } else if (this.value != null) {
- // TODO: Handle i/o from real files
- tempChunk = null;
- }
- return tempChunk;
- }
-
- /**
- * Returns the file.
- * @return The file.
- */
- public File getFile() {
- return this.value;
- }
-
-}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-06-02 12:07:41 UTC (rev 13799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-06-02 12:30:22 UTC (rev 13800)
@@ -237,7 +237,7 @@
throw new NullPointerException("PostScript Error: No standard input.");
}
// Create the standard input file.
- this.standardInput = new PsFileReal(input);
+ this.standardInput = new PsFile(input);
// Place it on the execution stack.
this.executionStack.push(this.standardInput);
// Get the System Dictionary.
@@ -359,7 +359,7 @@
}
/* Otherwise, execute it. */
final PsInputString stringInput = new PsInputString(psString);
- final PsFileReal inputFile = new PsFileReal(stringInput);
+ final PsFile inputFile = new PsFile(stringInput);
this.executionStack.push(inputFile);
return;
}
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-06-02 12:07:41 UTC (rev 13799)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-06-02 12:30:22 UTC (rev 13800)
@@ -1699,7 +1699,7 @@
PsObject object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsReal);
input = createPsInputFromString("cvr");
- interpreter.getExecutionStack().push(new PsFileReal(input));
+ interpreter.getExecutionStack().push(new PsFile(input));
interpreter.process();
PsObject object2 = interpreter.getOperandStack().pop();
assertTrue(object2 instanceof PsReal);
@@ -1713,7 +1713,7 @@
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsInteger);
input = createPsInputFromString("cvr");
- interpreter.getExecutionStack().push(new PsFileReal(input));
+ interpreter.getExecutionStack().push(new PsFile(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
assertTrue(object2 instanceof PsReal);
@@ -1729,7 +1729,7 @@
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsString);
input = createPsInputFromString("cvr");
- interpreter.getExecutionStack().push(new PsFileReal(input));
+ interpreter.getExecutionStack().push(new PsFile(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
assertTrue(object2 instanceof PsReal);
@@ -1743,7 +1743,7 @@
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsString);
input = createPsInputFromString("cvr");
- interpreter.getExecutionStack().push(new PsFileReal(input));
+ interpreter.getExecutionStack().push(new PsFile(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
assertTrue(object2 instanceof PsReal);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-02 12:07:47
|
Revision: 13799
http://sourceforge.net/p/foray/code/13799
Author: victormote
Date: 2025-06-02 12:07:41 +0000 (Mon, 02 Jun 2025)
Log Message:
-----------
Remove class PsFileFilter.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
Removed Paths:
-------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
Deleted: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-06-02 11:37:12 UTC (rev 13798)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-06-02 12:07:41 UTC (rev 13799)
@@ -1,79 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.ps;
-
-import org.foray.primitive.sequence.ByteArrayBuilder;
-import org.foray.ps.filter.EexecDecodeFilter;
-
-import java.io.IOException;
-
-/**
- * Class representing a PostScript "file" object. An instance of this class is
- * really a wrapper around one of several things: 1) a real file, 2) an input
- * source, like standard input, or 3) a filter that sits on top of another
- * PsFile instance.
- */
-public class PsFileFilter extends PsFile {
-
- /** The encapsulated filter. */
- private EexecDecodeFilter filter;
-
- /** The encapsulated file, if any. */
- private PsFile underlyingFile;
-
- /**
- * Constructor for an instance that is a filter for a PsFile instance.
- * @param filter The filter instance.
- * @param underlyingFile The PsFile which backs this filter.
- */
- public PsFileFilter(final EexecDecodeFilter filter, final PsFile underlyingFile) {
- super();
- this.filter = filter;
- this.underlyingFile = underlyingFile;
- }
-
- @Override
- protected byte[] getNextChunk() throws IOException {
- byte[] tempChunk = getRemainingChunk();
- if (tempChunk != null) {
- return tempChunk;
- }
- // Get the chunk from the underlying file
- if (this.underlyingFile != null) {
- tempChunk = this.underlyingFile.getNextChunk();
- }
- if (tempChunk == null) {
- return null;
- }
- final ByteArrayBuilder builder = new ByteArrayBuilder(tempChunk.length);
- builder.append(this.filter);
- return builder.toArray();
- }
-
-}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java 2025-06-02 11:37:12 UTC (rev 13798)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java 2025-06-02 12:07:41 UTC (rev 13799)
@@ -82,4 +82,12 @@
return tempChunk;
}
+ /**
+ * Returns the file.
+ * @return The file.
+ */
+ public File getFile() {
+ return this.value;
+ }
+
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-02 11:37:12 UTC (rev 13798)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-02 12:07:41 UTC (rev 13799)
@@ -30,7 +30,6 @@
import org.foray.primitive.sequence.ByteArray;
import org.foray.primitive.sequence.ByteArrayBuilder;
-import org.foray.ps.filter.EexecDecodeFilter;
import org.axsl.constants.PrimitiveConstants;
@@ -1821,15 +1820,17 @@
operandStack.push(getInterpreter().getSystemDict());
begin();
+ /* TODO: Badly broken at the moment during refactoring. */
+
/* Create the operand for eexec. */
- final PsObject toExec = popOperand(PsOperator.EEXEC);
- final EexecDecodeFilter filter = new EexecDecodeFilter(null);
- PsFile file = null;
- if (toExec instanceof PsFile) {
- file = new PsFileFilter(filter, (PsFile) toExec);
- } else {
- throw new PsOperatorException(PsError.TYPECHECK, PsOperator.EEXEC);
- }
+// final PsObject toExec = popOperand(PsOperator.EEXEC);
+// final EexecDecodeFilter filter = new EexecDecodeFilter(null);
+ final PsFile file = null;
+// if (toExec instanceof PsFile) {
+// file = new PsFileFilter(filter, (PsFile) toExec);
+// } else {
+// throw new PsOperatorException(PsError.TYPECHECK, PsOperator.EEXEC);
+// }
operandStack.push(file);
exec();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-02 11:37:16
|
Revision: 13798
http://sourceforge.net/p/foray/code/13798
Author: victormote
Date: 2025-06-02 11:37:12 +0000 (Mon, 02 Jun 2025)
Log Message:
-----------
Rename class, for clarity.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
Added Paths:
-----------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputStream.java
Removed Paths:
-------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java 2025-06-02 10:34:55 UTC (rev 13797)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileReal.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -45,7 +45,7 @@
private File value;
/** The encapsulated input source for this object, if any. */
- private PsInput input;
+ private PsInputStream input;
/**
* Constructor for an instance that wraps a real file.
@@ -61,7 +61,7 @@
* input).
* @param input The input to be encapsulated.
*/
- public PsFileReal(final PsInput input) {
+ public PsFileReal(final PsInputStream input) {
super();
this.input = input;
}
Deleted: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java 2025-06-02 10:34:55 UTC (rev 13797)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -1,55 +0,0 @@
-/*
- * Copyright 2009 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.ps;
-
-import org.axsl.primitive.sequence.ByteSequence;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Interface for objects that wish to be used as input to the PostScript interpreter.
- * This interface is needed because a variety of file types may be used as input to a PostScript interpreter.
- * For example, Type 1 font files are frequently packaged in operating-system-specific wrapper files that must be
- * unwrapped (and sometimes decoded) before they can be consumed by the PostScript interpreter.
- * This interface allows other classes to do that work and pass the results through to the interpreter.
- *
- * Please note that the implementing class is responsible for any buffering of
- * the data for i/o efficiency purposes.
- */
-public abstract class PsInput extends InputStream {
-
- /**
- * Returns the next byte array chunk in the input so that it can be consumed by the PostScript interpreter.
- * @return The next byte array that should be consumed by the interpreter, or null if there is no more input.
- * @throws IOException For I/O Errors.
- */
- abstract ByteSequence providePostScriptInput() throws IOException;
-
-}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-06-02 10:34:55 UTC (rev 13797)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -42,9 +42,9 @@
/**
* An implementation of PsInput that wraps a java.io.File instance.
- * @see PsInput
+ * @see PsInputStream
*/
-public class PsInputFile extends PsInput {
+public class PsInputFile extends PsInputStream {
/** The encapsulated input stream. */
private InputStream in;
Copied: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputStream.java (from rev 13796, trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java)
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputStream.java (rev 0)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputStream.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2009 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.ps;
+
+import org.axsl.primitive.sequence.ByteSequence;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Interface for objects that wish to be used as input to the PostScript interpreter.
+ * This interface is needed because a variety of file types may be used as input to a PostScript interpreter.
+ * For example, Type 1 font files are frequently packaged in operating-system-specific wrapper files that must be
+ * unwrapped (and sometimes decoded) before they can be consumed by the PostScript interpreter.
+ * This interface allows other classes to do that work and pass the results through to the interpreter.
+ *
+ * Please note that the implementing class is responsible for any buffering of
+ * the data for i/o efficiency purposes.
+ */
+public abstract class PsInputStream extends InputStream {
+
+ /**
+ * Returns the next byte array chunk in the input so that it can be consumed by the PostScript interpreter.
+ * @return The next byte array that should be consumed by the interpreter, or null if there is no more input.
+ * @throws IOException For I/O Errors.
+ */
+ abstract ByteSequence providePostScriptInput() throws IOException;
+
+}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-06-02 10:34:55 UTC (rev 13797)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -35,9 +35,9 @@
import java.io.IOException;
/**
- * A {@link PsInput} implementation that simply wraps a String.
+ * A {@link PsInputStream} implementation that simply wraps a String.
*/
-public class PsInputString extends PsInput {
+public class PsInputString extends PsInputStream {
/** The String whose content is the PostScript input. */
private PsString wrappedString;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-06-02 10:34:55 UTC (rev 13797)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -232,7 +232,7 @@
* @param systemDict The dictionary that should be used.
* @throws PsInterpreterException4a For invalid parameters.
*/
- public PsInterpreter4a(final PsInput input, final PsSystemDict4a systemDict) throws PsInterpreterException4a {
+ public PsInterpreter4a(final PsInputStream input, final PsSystemDict4a systemDict) throws PsInterpreterException4a {
if (input == null) {
throw new NullPointerException("PostScript Error: No standard input.");
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2025-06-02 10:34:55 UTC (rev 13797)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -49,12 +49,12 @@
public class PsServer4a implements PsServer {
/**
- * Creates a {@link PsInput} instance from a File.
+ * Creates a {@link PsInputStream} instance from a File.
* @param input The input to be processed as PostScript input.
* @return The newly-created PsInput.
* @throws IOException For errors opening the file.
*/
- public PsInput createPsInput(final InputStream input) throws IOException {
+ public PsInputStream createPsInput(final InputStream input) throws IOException {
return new PsInputFile(input);
}
@@ -80,7 +80,7 @@
}
final org.foray.ps.PsSystemDict4a foraySystemDict = (org.foray.ps.PsSystemDict4a) systemDict;
try {
- final PsInput psInput = new PsInputFile(input);
+ final PsInputStream psInput = new PsInputFile(input);
return new PsInterpreter4a(psInput, foraySystemDict);
} catch (final PsInterpreterException4a e) {
/* The reason for this exception is the possibility of a null key being added to the various dictionaries
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-06-02 10:34:55 UTC (rev 13797)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-06-02 11:37:12 UTC (rev 13798)
@@ -47,7 +47,7 @@
* @param inputString The string to be converted.
* @return The executable wrapped string.
*/
- private PsInput createPsInputFromString(final String inputString) {
+ private PsInputStream createPsInputFromString(final String inputString) {
final PsString psString = new PsString(new ByteArray(inputString));
final PsInputString psInputString = new PsInputString(psString);
return psInputString;
@@ -60,7 +60,7 @@
*/
@Test
public void testDict01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("3 dict");
+ final PsInputStream input = createPsInputFromString("3 dict");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -77,7 +77,7 @@
@Test
public void testPop01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("1 2 3 pop");
+ PsInputStream input = createPsInputFromString("1 2 3 pop");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
/* There should be two items remaining on the stack. */
@@ -113,7 +113,7 @@
*/
@Test
public void testBegin01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("17 dict begin");
+ final PsInputStream input = createPsInputFromString("17 dict begin");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(0, interpreter.getOperandStack().size());
@@ -129,7 +129,7 @@
@Test
public void testDiv01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("3 2 div");
+ PsInputStream input = createPsInputFromString("3 2 div");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -157,7 +157,7 @@
@Test
public void testIdiv01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("3 2 idiv");
+ PsInputStream input = createPsInputFromString("3 2 idiv");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -195,7 +195,7 @@
@Test
public void testAdd01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("3 4 add");
+ PsInputStream input = createPsInputFromString("3 4 add");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -221,7 +221,7 @@
@Test
public void testSub01() throws PsInterpreterException4a, PsOperatorException {
/* Inverse of the first example for "add" from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("7 3 sub");
+ PsInputStream input = createPsInputFromString("7 3 sub");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -247,7 +247,7 @@
@Test
public void testMul01() throws PsInterpreterException4a, PsOperatorException {
/* Use the same operands as for the "add" operator tests. */
- PsInput input = createPsInputFromString("3 4 mul");
+ PsInputStream input = createPsInputFromString("3 4 mul");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -281,7 +281,7 @@
*/
@Test
public void testTrueOperator01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("true");
+ final PsInputStream input = createPsInputFromString("true");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -298,7 +298,7 @@
*/
@Test
public void testFalseOperator01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("false");
+ final PsInputStream input = createPsInputFromString("false");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -532,7 +532,7 @@
@Test
public void testNeg01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd Ed. */
- PsInput input = createPsInputFromString("4.5 neg");
+ PsInputStream input = createPsInputFromString("4.5 neg");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -562,7 +562,7 @@
generalBooleanTest("false not", true);
/* Third example from the PSLRM, 2nd Ed. */
- final PsInput input = createPsInputFromString("52 not");
+ final PsInputStream input = createPsInputFromString("52 not");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -590,7 +590,7 @@
generalBooleanTest("false false or", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- final PsInput input = createPsInputFromString("17 5 or");
+ final PsInputStream input = createPsInputFromString("17 5 or");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -618,7 +618,7 @@
generalBooleanTest("false false xor", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- PsInput input = createPsInputFromString("7 3 xor");
+ PsInputStream input = createPsInputFromString("7 3 xor");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -654,7 +654,7 @@
generalBooleanTest("false false and", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- PsInput input = createPsInputFromString("99 1 and");
+ PsInputStream input = createPsInputFromString("99 1 and");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -678,7 +678,7 @@
@Test
public void testCvx01() throws PsInterpreterException4a, PsOperatorException {
/* First create a name and make sure it is not executable. */
- PsInput input = createPsInputFromString("/literal");
+ PsInputStream input = createPsInputFromString("/literal");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -726,7 +726,7 @@
*/
@Test
public void testExec01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("(3 2 add) cvx exec");
+ final PsInputStream input = createPsInputFromString("(3 2 add) cvx exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -744,7 +744,7 @@
*/
@Test
public void testExec02() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("3 2 /add exec");
+ final PsInputStream input = createPsInputFromString("3 2 /add exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(3, interpreter.getOperandStack().size());
@@ -774,7 +774,7 @@
*/
@Test
public void testExec03() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("3 2 /add cvx exec");
+ final PsInputStream input = createPsInputFromString("3 2 /add cvx exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -811,7 +811,7 @@
@Test
public void testCount01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("clear count");
+ PsInputStream input = createPsInputFromString("clear count");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -837,7 +837,7 @@
@Test
public void testEq01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("4.0 4 eq");
+ PsInputStream input = createPsInputFromString("4.0 4 eq");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -905,7 +905,7 @@
@Test
public void testNe01() throws PsInterpreterException4a, PsOperatorException {
/* First example (for "eq") from the PSLRM, 2nd ed. */
- PsInput input = createPsInputFromString("4.0 4 ne");
+ PsInputStream input = createPsInputFromString("4.0 4 ne");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -972,7 +972,7 @@
@Test
public void testMatrix01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- final PsInput input = createPsInputFromString("matrix");
+ final PsInputStream input = createPsInputFromString("matrix");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -1590,7 +1590,7 @@
final boolean isEqualTo, final boolean isGreaterThan) throws PsInterpreterException4a,
PsOperatorException {
/* Test number that is less. */
- PsInput input = createPsInputFromString("2 3 " + comparisonOperation);
+ PsInputStream input = createPsInputFromString("2 3 " + comparisonOperation);
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1660,7 +1660,7 @@
*/
private void generalBooleanTest(final String testString, final boolean expectedResult)
throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString(testString);
+ final PsInputStream input = createPsInputFromString(testString);
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -1675,7 +1675,7 @@
*/
@Test
public void testVersion01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("version");
+ final PsInputStream input = createPsInputFromString("version");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1693,7 +1693,7 @@
@Test
public void testCvr01() throws PsInterpreterException4a, PsOperatorException {
/* Test a real. */
- PsInput input = createPsInputFromString("9.2");
+ PsInputStream input = createPsInputFromString("9.2");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object1 = interpreter.getOperandStack().peek();
@@ -1759,7 +1759,7 @@
*/
@Test
public void testClear01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = createPsInputFromString("1 2 3 clear");
+ final PsInputStream input = createPsInputFromString("1 2 3 clear");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(0, interpreter.getOperandStack().size());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-02 10:34:57
|
Revision: 13797
http://sourceforge.net/p/foray/code/13797
Author: victormote
Date: 2025-06-02 10:34:55 +0000 (Mon, 02 Jun 2025)
Log Message:
-----------
Remove string from PsFileFilter content.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-06-01 14:31:50 UTC (rev 13796)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-06-02 10:34:55 UTC (rev 13797)
@@ -47,9 +47,6 @@
/** The encapsulated file, if any. */
private PsFile underlyingFile;
- /** The encapsulated string, if any. */
- private PsString underlyingString;
-
/**
* Constructor for an instance that is a filter for a PsFile instance.
* @param filter The filter instance.
@@ -61,17 +58,6 @@
this.underlyingFile = underlyingFile;
}
- /**
- * Constructor for an instance that is a filter for a PsString instance.
- * @param filter The filter instance.
- * @param underlyingString The String which backs this filter.
- */
- public PsFileFilter(final EexecDecodeFilter filter, final PsString underlyingString) {
- super();
- this.filter = filter;
- this.underlyingString = underlyingString;
- }
-
@Override
protected byte[] getNextChunk() throws IOException {
byte[] tempChunk = getRemainingChunk();
@@ -81,8 +67,6 @@
// Get the chunk from the underlying file
if (this.underlyingFile != null) {
tempChunk = this.underlyingFile.getNextChunk();
- } else if (this.underlyingString != null) {
- tempChunk = this.underlyingString.getValue().toArray();
}
if (tempChunk == null) {
return null;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-01 14:31:50 UTC (rev 13796)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-06-02 10:34:55 UTC (rev 13797)
@@ -1827,8 +1827,6 @@
PsFile file = null;
if (toExec instanceof PsFile) {
file = new PsFileFilter(filter, (PsFile) toExec);
- } else if (toExec instanceof PsString) {
- file = new PsFileFilter(filter, (PsString) toExec);
} else {
throw new PsOperatorException(PsError.TYPECHECK, PsOperator.EEXEC);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-01 14:31:54
|
Revision: 13796
http://sourceforge.net/p/foray/code/13796
Author: victormote
Date: 2025-06-01 14:31:50 +0000 (Sun, 01 Jun 2025)
Log Message:
-----------
Make PsInput a subclass of InputStream.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java 2025-06-01 13:31:32 UTC (rev 13795)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java 2025-06-01 14:31:50 UTC (rev 13796)
@@ -31,6 +31,7 @@
import org.axsl.primitive.sequence.ByteSequence;
import java.io.IOException;
+import java.io.InputStream;
/**
* Interface for objects that wish to be used as input to the PostScript interpreter.
@@ -42,7 +43,7 @@
* Please note that the implementing class is responsible for any buffering of
* the data for i/o efficiency purposes.
*/
-public abstract class PsInput {
+public abstract class PsInput extends InputStream {
/**
* Returns the next byte array chunk in the input so that it can be consumed by the PostScript interpreter.
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-06-01 13:31:32 UTC (rev 13795)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-06-01 14:31:50 UTC (rev 13796)
@@ -69,4 +69,9 @@
return new ByteArray(trimmed);
}
+ @Override
+ public int read() throws IOException {
+ return this.in.read();
+ }
+
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-06-01 13:31:32 UTC (rev 13795)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-06-01 14:31:50 UTC (rev 13796)
@@ -32,6 +32,8 @@
import org.axsl.primitive.sequence.ByteSequence;
+import java.io.IOException;
+
/**
* A {@link PsInput} implementation that simply wraps a String.
*/
@@ -43,6 +45,9 @@
/** Flag indicating whether this content has already been consumed or not. */
private boolean hasBeenConsumed = false;
+ /** Index to the next char in the stream. */
+ private int nextIndex = 0;
+
/**
* Constructor.
* @param theString The String whose content is the PostScript input.
@@ -60,4 +65,13 @@
return new ByteArray(this.wrappedString.getValue());
}
+ @Override
+ public int read() throws IOException {
+ if (this.nextIndex >= this.wrappedString.size()) {
+ return -1;
+ }
+ nextIndex ++;
+ return this.wrappedString.getValue().byteAt(nextIndex - 1);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-06-01 13:31:35
|
Revision: 13795
http://sourceforge.net/p/foray/code/13795
Author: victormote
Date: 2025-06-01 13:31:32 +0000 (Sun, 01 Jun 2025)
Log Message:
-----------
Convert interface PsInput to an abstract class.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java 2025-05-31 21:55:10 UTC (rev 13794)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInput.java 2025-06-01 13:31:32 UTC (rev 13795)
@@ -42,7 +42,7 @@
* Please note that the implementing class is responsible for any buffering of
* the data for i/o efficiency purposes.
*/
-public interface PsInput {
+public abstract class PsInput {
/**
* Returns the next byte array chunk in the input so that it can be consumed by the PostScript interpreter.
@@ -49,6 +49,6 @@
* @return The next byte array that should be consumed by the interpreter, or null if there is no more input.
* @throws IOException For I/O Errors.
*/
- ByteSequence providePostScriptInput() throws IOException;
+ abstract ByteSequence providePostScriptInput() throws IOException;
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-05-31 21:55:10 UTC (rev 13794)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputFile.java 2025-06-01 13:31:32 UTC (rev 13795)
@@ -44,7 +44,7 @@
* An implementation of PsInput that wraps a java.io.File instance.
* @see PsInput
*/
-public class PsInputFile implements PsInput {
+public class PsInputFile extends PsInput {
/** The encapsulated input stream. */
private InputStream in;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-05-31 21:55:10 UTC (rev 13794)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-06-01 13:31:32 UTC (rev 13795)
@@ -35,7 +35,7 @@
/**
* A {@link PsInput} implementation that simply wraps a String.
*/
-public class PsInputString implements PsInput {
+public class PsInputString extends PsInput {
/** The String whose content is the PostScript input. */
private PsString wrappedString;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 21:55:15
|
Revision: 13794
http://sourceforge.net/p/foray/code/13794
Author: victormote
Date: 2025-05-31 21:55:10 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Fix comparisons between PsName and PsString.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsName.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsName.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsName.java 2025-05-31 20:51:14 UTC (rev 13793)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsName.java 2025-05-31 21:55:10 UTC (rev 13794)
@@ -108,10 +108,17 @@
}
if (anObject instanceof PsString) {
final PsString psStringObject = (PsString) anObject;
- if (psStringObject.getValue().equals(this.value)) {
- return true;
+ if (this.value.length() != psStringObject.getValue().length()) {
+ return false;
}
- return false;
+ for (int index = 0; index < this.value.length(); index ++) {
+ final char myChar = this.value.charAt(index);
+ final int otherChar = Byte.toUnsignedInt(psStringObject.getValue().byteAt(index));
+ if (myChar != otherChar) {
+ return false;
+ }
+ }
+ return true;
}
if (anObject instanceof String) {
final String string = (String) anObject;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java 2025-05-31 20:51:14 UTC (rev 13793)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java 2025-05-31 21:55:10 UTC (rev 13794)
@@ -77,10 +77,18 @@
}
if (anObject instanceof PsName) {
final PsName psNameObject = (PsName) anObject;
- if (psNameObject.getValue().equals(this.value)) {
- return true;
+
+ if (this.value.length() != psNameObject.getValue().length()) {
+ return false;
}
- return false;
+ for (int index = 0; index < this.value.length(); index ++) {
+ final int myChar = Byte.toUnsignedInt(getValue().byteAt(index));
+ final char otherChar = psNameObject.getValue().charAt(index);
+ if (myChar != otherChar) {
+ return false;
+ }
+ }
+ return true;
}
if (anObject instanceof PsString) {
final PsString psStringObject = (PsString) anObject;
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 20:51:14 UTC (rev 13793)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 21:55:10 UTC (rev 13794)
@@ -33,7 +33,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
@@ -836,7 +835,6 @@
* @throws PsOperatorException For PostScript operator errors.
*/
@Test
- @Disabled
public void testEq01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
PsInput input = createPsInputFromString("4.0 4 eq");
@@ -868,6 +866,16 @@
assertTrue(psBoolean.getValue());
assertEquals(0, interpreter.getOperandStack().size());
+ /* Third example from the PSLRM, 2nd ed, but reversed. */
+ input = createPsInputFromString("/abc (abc) eq");
+ interpreter = new PsInterpreter4a(input, null);
+ interpreter.process();
+ object = interpreter.getOperandStack().pop();
+ assertTrue(object instanceof PsBoolean);
+ psBoolean = (PsBoolean) object;
+ assertTrue(psBoolean.getValue());
+ assertEquals(0, interpreter.getOperandStack().size());
+
/* Fourth example from the PSLRM, 2nd ed. */
input = createPsInputFromString("[1 2 3] dup eq");
interpreter = new PsInterpreter4a(input, null);
@@ -895,7 +903,6 @@
* @throws PsOperatorException For PostScript operator errors.
*/
@Test
- @Disabled
public void testNe01() throws PsInterpreterException4a, PsOperatorException {
/* First example (for "eq") from the PSLRM, 2nd ed. */
PsInput input = createPsInputFromString("4.0 4 ne");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 20:51:17
|
Revision: 13793
http://sourceforge.net/p/foray/code/13793
Author: victormote
Date: 2025-05-31 20:51:14 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Conform to aXSL change: Add compare method to ByteSequencePlus.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java
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-05-31 17:53:55 UTC (rev 13792)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java 2025-05-31 20:51:14 UTC (rev 13793)
@@ -137,41 +137,7 @@
return builder.toString();
}
- /**
- * <p>Compares two byte arrays lexicographically, as if they were strings.
- * If the array is considered as a sequence where index 0 is at the left, and index (length - 1) is at the right,
- * the comparison runs from left to right.
- * The result is a negative integer if this {@code ByteSequencePlus} object lexicographically precedes the argument
- * object.
- * The result is a positive integer if this {@code ByteSequencePlus} object lexicographically follows the argument
- * object.
- * The result is zero if the sequences are equal; {@code compareTo} returns {@code 0} exactly when the
- * {@link #equals(Object)} method would return {@code true}.</p>
- *
- * <p>If the two sequences are different, then either they have different characters at some index that is a valid
- * index for both sequences, or their lengths are different, or both.
- * If they have different characters at one or more index positions, let <i>k</i> be the smallest such index; then
- * the sequence whose byte at position <i>k</i> has the smaller value, as determined by using the < operator,
- * lexicographically precedes the other sequence.
- * In this case, {@code compareTo} returns the difference of the two character values at position {@code k} in
- * the two sequences:
- * <blockquote><pre>
- * this.byteAt(k) - other.byteAt(k)
- * </pre></blockquote>
- *
- * <p>If there is no index position at which they differ, then the shorter sequence lexicographically precedes the
- * longer sequence.
- * In this case, {@code compareTo} returns the difference of the lengths of the sequences:
- * <blockquote><pre>
- * this.length() - other.length()
- * </pre></blockquote>
- *
- * @param other The {@code ByteSequence} to be compared.
- * @return Tthe value {@code 0} if the argument sequence is equal to this sequence; a value less than {@code 0} if
- * this sequence is lexicographically less than the argument sequence; and a value greater than {@code 0} if this
- * sequence is lexicographically greater than the argument sequence.
- * @see String#compareTo(String)
- */
+ @Override
public int compareToLtR(final ByteSequence other) {
final int len1 = length();
final int len2 = other.length();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 17:53:58
|
Revision: 13792
http://sourceforge.net/p/foray/code/13792
Author: victormote
Date: 2025-05-31 17:53:55 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Convert PsString to wrap a byte array instead of a String.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsDictionary.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsOperatorException.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsReal.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/type1/PsFontInfoDictionary4a.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
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-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/AbstractByteSequence.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -137,6 +137,58 @@
return builder.toString();
}
+ /**
+ * <p>Compares two byte arrays lexicographically, as if they were strings.
+ * If the array is considered as a sequence where index 0 is at the left, and index (length - 1) is at the right,
+ * the comparison runs from left to right.
+ * The result is a negative integer if this {@code ByteSequencePlus} object lexicographically precedes the argument
+ * object.
+ * The result is a positive integer if this {@code ByteSequencePlus} object lexicographically follows the argument
+ * object.
+ * The result is zero if the sequences are equal; {@code compareTo} returns {@code 0} exactly when the
+ * {@link #equals(Object)} method would return {@code true}.</p>
+ *
+ * <p>If the two sequences are different, then either they have different characters at some index that is a valid
+ * index for both sequences, or their lengths are different, or both.
+ * If they have different characters at one or more index positions, let <i>k</i> be the smallest such index; then
+ * the sequence whose byte at position <i>k</i> has the smaller value, as determined by using the < operator,
+ * lexicographically precedes the other sequence.
+ * In this case, {@code compareTo} returns the difference of the two character values at position {@code k} in
+ * the two sequences:
+ * <blockquote><pre>
+ * this.byteAt(k) - other.byteAt(k)
+ * </pre></blockquote>
+ *
+ * <p>If there is no index position at which they differ, then the shorter sequence lexicographically precedes the
+ * longer sequence.
+ * In this case, {@code compareTo} returns the difference of the lengths of the sequences:
+ * <blockquote><pre>
+ * this.length() - other.length()
+ * </pre></blockquote>
+ *
+ * @param other The {@code ByteSequence} to be compared.
+ * @return Tthe value {@code 0} if the argument sequence is equal to this sequence; a value less than {@code 0} if
+ * this sequence is lexicographically less than the argument sequence; and a value greater than {@code 0} if this
+ * sequence is lexicographically greater than the argument sequence.
+ * @see String#compareTo(String)
+ */
+ public int compareToLtR(final ByteSequence other) {
+ final int len1 = length();
+ final int len2 = other.length();
+ final int lim = Math.min(len1, len2);
+
+ int k = 0;
+ while (k < lim) {
+ final byte byte1 = byteAt(k);
+ final byte byte2 = other.byteAt(k);
+ if (byte1 != byte2) {
+ return byte1 - byte2;
+ }
+ k++;
+ }
+ return len1 - len2;
+ }
+
@Override
public int indexOf(final int aByte) {
return indexOf(aByte, 0);
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsDictionary.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsDictionary.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsDictionary.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -250,14 +250,14 @@
* @return The value for {@code key}, if it is found and is a {@link PsString}, or null
* otherwise.
*/
- public String getString(final String key) {
+ public PsString getString(final String key) {
final PsObject object = this.getItem(key);
if (object == null
|| ! (object instanceof PsString)) {
return null;
}
- final PsString string = (PsString) object;
- return string.getValue();
+ final PsString psString = (PsString) object;
+ return psString;
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -82,7 +82,7 @@
if (this.underlyingFile != null) {
tempChunk = this.underlyingFile.getNextChunk();
} else if (this.underlyingString != null) {
- tempChunk = this.underlyingString.getValue().getBytes();
+ tempChunk = this.underlyingString.getValue().toArray();
}
if (tempChunk == null) {
return null;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -28,6 +28,7 @@
package org.foray.ps;
+import org.foray.primitive.sequence.ByteArrayBuilder;
import org.foray.ps.encode.EncodingVector4a;
import org.foray.ps.readonly.ReadOnlySystemDict;
@@ -173,7 +174,7 @@
// private long tokenCount = 0;
/** Reusable buffer for building Strings. */
- private StringBuilder stringBeingBuilt = new StringBuilder();
+ private ByteArrayBuilder stringBeingBuilt = new ByteArrayBuilder();
/** The current nesting level for parentheses.
* Zero indicates we are not inside parentheses.*/
@@ -648,9 +649,9 @@
break;
}
this.inString = false;
- final PsString stringObject = new PsString(this.stringBeingBuilt.toString());
+ final PsString stringObject = new PsString(this.stringBeingBuilt.toImmutable());
processToken(stringObject);
- this.stringBeingBuilt = new StringBuilder();
+ this.stringBeingBuilt.setLength(0);
break;
default:
addToString(inputByte);
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsOperatorException.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsOperatorException.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsOperatorException.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -48,12 +48,11 @@
* Constructor.
* @param throwable The exception to be wrapped in this exception.
* @param errorCode The PS error code for this exception.
- * @param offendingOperator The PS operator that triggered the request
- * that threw the exception.
+ * @param offendingOperator The PS operator that triggered the request that threw the exception.
* @param message The user message.
*/
- public PsOperatorException(final Throwable throwable, final PsError errorCode,
- final PsOperator offendingOperator, final String message) {
+ public PsOperatorException(final Throwable throwable, final PsError errorCode, final PsOperator offendingOperator,
+ final String message) {
super(message, throwable);
if (errorCode == null) {
throw new NullPointerException("PostScript error code is required.");
@@ -65,12 +64,10 @@
/**
* Constructor.
* @param errorCode The PS error code for this exception.
- * @param offendingOperator The PS operator that triggered the request
- * that threw the exception.
+ * @param offendingOperator The PS operator that triggered the request that threw the exception.
* @param message The user message.
*/
- public PsOperatorException(final PsError errorCode,
- final PsOperator offendingOperator, final String message) {
+ public PsOperatorException(final PsError errorCode, final PsOperator offendingOperator, final String message) {
this(null, errorCode, offendingOperator, message);
}
@@ -85,8 +82,7 @@
/**
* Constructor.
* @param errorCode The PS error code for this exception.
- * @param offendingOperator The PS operator that triggered the request
- * that threw the exception.
+ * @param offendingOperator The PS operator that triggered the request that threw the exception.
*/
public PsOperatorException(final PsError errorCode, final PsOperator offendingOperator) {
this(errorCode, offendingOperator, null);
@@ -108,9 +104,6 @@
return this.offendingOperator;
}
- /**
- * {@inheritDoc}
- */
@Override
public String getMessage() {
String superMessage = super.getMessage();
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsReal.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsReal.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsReal.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -50,15 +50,12 @@
}
/**
- * Static method to attempt to create a PSReal instance, if the input
- * qualifies.
+ * Static method to attempt to create a PSReal instance, if the input qualifies.
* @param interpreter The parent interpreter.
- * @param input The byte array containing the content to be converted to
- * a PSReal instance.
+ * @param input The byte array containing the content to be converted to a PSReal instance.
* @return A PsReal instance, if the input qualifies, otherwise, null.
*/
- public static PsReal create(final PsInterpreter4a interpreter,
- final byte[] input) {
+ public static PsReal create(final PsInterpreter4a interpreter, final byte[] input) {
// Every char must be a digit, sign, decimal point, E, or e
for (int i = 0; i < input.length; i++) {
if (!isNumeral(input[i])
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsString.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -28,13 +28,18 @@
package org.foray.ps;
+import org.foray.primitive.sequence.ByteArray;
+
/**
- * Class representing a string PostScript object.
+ * Class representing a "string" PostScript object.
+ * A PostScript string is really an array of unsigned bytes that are not required to adhere to any character set or even
+ * be used as string characters.
+ * @see "PostScript Language Reference, Third Editions, Section 3.3.7."
*/
public class PsString implements PsObjectComposite {
/** The encapsulated value for this object. */
- private String value;
+ private ByteArray value;
/** Indicates whether this name is executable. See PSLRM, 2nd Ed, documentation of the "exec"
* operator for example and discussion of executable strings. */
@@ -47,7 +52,7 @@
* Constructor.
* @param value The value to encapsulate.
*/
- public PsString(final String value) {
+ public PsString(final ByteArray value) {
super();
this.value = value;
}
@@ -122,7 +127,7 @@
* Returns this string's value.
* @return The value.
*/
- public String getValue() {
+ public ByteArray getValue() {
return this.value;
}
@@ -130,7 +135,7 @@
* Sets this string's value.
* @param newValue The new value for this string.
*/
- public void setValue(final String newValue) {
+ public void setValue(final ByteArray newValue) {
this.value = newValue;
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -28,6 +28,8 @@
package org.foray.ps;
+import org.foray.primitive.sequence.ByteArray;
+import org.foray.primitive.sequence.ByteArrayBuilder;
import org.foray.ps.filter.EexecDecodeFilter;
import org.axsl.constants.PrimitiveConstants;
@@ -55,7 +57,7 @@
private PsInteger languageLevel;
/** A reusable value for the version. */
- private PsString version = new PsString("2");
+ private PsString version = new PsString(new ByteArray("2"));
/** The parent interpreter. */
private PsInterpreter4a interpreter;
@@ -1851,11 +1853,11 @@
}
final PsInteger psinteger = (PsInteger) object;
final int size = psinteger.intValue();
- final StringBuilder sb = new StringBuilder(size);
+ final ByteArrayBuilder builder = new ByteArrayBuilder(size);
for (int i = 1; i <= size; i++) {
- sb.append('0');
+ builder.append('0');
}
- final PsString string = new PsString(sb.toString());
+ final PsString string = new PsString(builder.toImmutable());
pushOperand(string);
}
@@ -1886,17 +1888,20 @@
throw new PsOperatorException(PsError.TYPECHECK, PsOperator.READSTRING);
}
final PsFile file = (PsFile) object;
- final char[] charArray = string.getValue().toCharArray();
+
+ final ByteArrayBuilder builder = new ByteArrayBuilder(string.getValue().length());
+ builder.append(string.getValue());
+
int charsRead = 0;
- for (int i = 0; i < charArray.length && file.isOpen(); i++) {
+ for (int i = 0; i < string.getValue().length() && file.isOpen(); i++) {
try {
- charArray[i] = (char) file.provideInput();
- charsRead ++;
+ builder.setByteAt(i, (byte) file.provideInput());
} catch (final IOException e) {
- file.closeFile();
+ throw new PsOperatorException(e, PsError.IOERROR, PsOperator.READSTRING, null);
}
+ charsRead ++;
}
- final String substring = new String(charArray, 0, charsRead);
+ final ByteArray substring = builder.subSequence(0, charsRead);
final PsString newString = new PsString(substring);
pushOperand(newString);
final PsBoolean newBoolean = PsBoolean.getBoolean(charsRead == string.getValue().length());
@@ -2035,13 +2040,12 @@
/**
* Executes the "put" operator on a string operand.
* @param string The string operated upon.
- * @param where The index into the string where {@code what} should
- * be placed.
+ * @param where The index into the string where {@code what} should be placed.
* @param what A PsInteger whose value should be "put" into the string.
* @throws PsOperatorException For any PostScript error.
*/
- private void putString(final PsString string, final PsObject where,
- final PsObject what) throws PsOperatorException {
+ private void putString(final PsString string, final PsObject where, final PsObject what)
+ throws PsOperatorException {
if (! (where instanceof PsInteger)) {
throw new PsOperatorException(PsError.TYPECHECK, PsOperator.PUT);
}
@@ -2054,11 +2058,16 @@
throw new PsOperatorException(PsError.TYPECHECK, PsOperator.PUT);
}
psinteger = (PsInteger) what;
- final char replacementChar = (char) psinteger.intValue();
- final char[] charArray = new char[string.getValue().length()];
- string.getValue().getChars(0, string.getValue().length(), charArray, 0);
- charArray[index] = replacementChar;
- string.setValue(new String(charArray));
+ final int replacementChar = psinteger.intValue();
+ if (replacementChar < 0
+ || replacementChar > PrimitiveConstants.MAX_8_BIT_UNSIGNED_INT) {
+ throw new PsOperatorException(PsError.RANGECHECK, PsOperator.PUT, "New string content must be in range"
+ + " of 0 to 255.");
+ }
+
+ final ByteArrayBuilder builder = new ByteArrayBuilder();
+ builder.append(string.getValue());
+ builder.setByteAt(index, (byte) replacementChar);
}
/**
@@ -2168,12 +2177,10 @@
/**
* Executes the "get" operator on a string operand.
* @param string The string operated upon.
- * @param where The index into {@code string} that should be pushed
- * onto the stack.
+ * @param where The index into {@code string} that should be pushed onto the stack.
* @throws PsOperatorException For any PostScript error.
*/
- private void getString(final PsString string, final PsObject where)
- throws PsOperatorException {
+ private void getString(final PsString string, final PsObject where) throws PsOperatorException {
if (! (where instanceof PsInteger)) {
throw new PsOperatorException(PsError.TYPECHECK, PsOperator.GET);
}
@@ -2181,7 +2188,7 @@
if (index < 0 || index > string.getValue().length() - 1) {
throw new PsOperatorException(PsError.RANGECHECK, PsOperator.GET);
}
- final PsInteger psinteger = new PsInteger(string.getValue().charAt(index));
+ final PsInteger psinteger = new PsInteger(string.getValue().byteAt(index));
pushOperand(psinteger);
}
@@ -3075,7 +3082,7 @@
if (string2.size() < string1.size()) {
throw new PsOperatorException(PsError.RANGECHECK, PsOperator.COPY);
}
- final String string2Contents = new String(string1.getValue());
+ final ByteArray string2Contents = string1.getValue();
string2.setValue(string2Contents);
pushOperand(string2);
}
@@ -3180,9 +3187,9 @@
}
} else if (stackObject instanceof PsString) {
final PsString string = (PsString) stackObject;
- final char[] chars = string.getValue().toCharArray();
+ final byte[] chars = string.getValue().toArray();
for (int i = 0; i < chars.length; i++) {
- char charItem = chars[i];
+ byte charItem = chars[i];
if (charItem > PrimitiveConstants.MAX_8_BIT_UNSIGNED_VALUES - 1) {
charItem = 0;
}
@@ -3192,8 +3199,7 @@
this.getInterpreter().process();
}
} else {
- throw new PsOperatorException(PsError.TYPECHECK,
- PsOperator.FORALL, "Expected: array, packedarray, "
+ throw new PsOperatorException(PsError.TYPECHECK, PsOperator.FORALL, "Expected: array, packedarray, "
+ "dict, or string.");
}
}
@@ -3533,12 +3539,9 @@
}
} else if (object1 instanceof PsString) {
if (object2 instanceof PsString) {
- /* TODO: This comparison may not be right. The PostScript
- * standard calls for a byte-by-byte comparison, not a
- * char-by-char comparison. */
- final String string1 = ((PsString) object1).getValue();
- final String string2 = ((PsString) object2).getValue();
- final int compare = string1.compareTo(string2);
+ final PsString string1 = (PsString) object1;
+ final PsString string2 = (PsString) object2;
+ final int compare = string1.getValue().compareToLtR(string2.getValue());
return compare;
}
}
@@ -3623,9 +3626,8 @@
return;
}
if (object instanceof PsString) {
- final String value = ((PsString) object).getValue();
- final PsReal real = PsReal.create(this.getInterpreter(),
- value.getBytes());
+ final ByteArray value = ((PsString) object).getValue();
+ final PsReal real = PsReal.create(this.getInterpreter(), value.toArray());
this.pushOperand(real);
return;
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/type1/PsFontInfoDictionary4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/type1/PsFontInfoDictionary4a.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/type1/PsFontInfoDictionary4a.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -78,27 +78,27 @@
@Override
public String getVersion() {
- return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.VERSION_KEY);
+ return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.VERSION_KEY).getValue().toString();
}
@Override
public String getNotice() {
- return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.NOTICE_KEY);
+ return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.NOTICE_KEY).getValue().toString();
}
@Override
public String getFullName() {
- return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.FULL_NAME_KEY);
+ return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.FULL_NAME_KEY).getValue().toString();
}
@Override
public String getFamilyName() {
- return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.FAMILY_NAME_KEY);
+ return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.FAMILY_NAME_KEY).getValue().toString();
}
@Override
public String getWeight() {
- return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.WEIGHT_KEY);
+ return this.getWrappedDictionary().getString(PsFontInfoDictionary4a.WEIGHT_KEY).getValue().toString();
}
@Override
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 14:25:11 UTC (rev 13791)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 17:53:55 UTC (rev 13792)
@@ -28,9 +28,12 @@
package org.foray.ps;
+import org.foray.primitive.sequence.ByteArray;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
@@ -46,7 +49,7 @@
* @return The executable wrapped string.
*/
private PsInput createPsInputFromString(final String inputString) {
- final PsString psString = new PsString(inputString);
+ final PsString psString = new PsString(new ByteArray(inputString));
final PsInputString psInputString = new PsInputString(psString);
return psInputString;
}
@@ -833,6 +836,7 @@
* @throws PsOperatorException For PostScript operator errors.
*/
@Test
+ @Disabled
public void testEq01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
PsInput input = createPsInputFromString("4.0 4 eq");
@@ -891,6 +895,7 @@
* @throws PsOperatorException For PostScript operator errors.
*/
@Test
+ @Disabled
public void testNe01() throws PsInterpreterException4a, PsOperatorException {
/* First example (for "eq") from the PSLRM, 2nd ed. */
PsInput input = createPsInputFromString("4.0 4 ne");
@@ -1670,7 +1675,7 @@
final PsObject object = interpreter.getOperandStack().pop();
assertTrue(object instanceof PsString);
final PsString theString = (PsString) object;
- assertEquals("2", theString.getValue());
+ assertEquals("2", theString.getValue().toString());
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 14:25:18
|
Revision: 13791
http://sourceforge.net/p/foray/code/13791
Author: victormote
Date: 2025-05-31 14:25:11 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Have PsInputString wrap a PsString instead of String.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-05-31 14:08:58 UTC (rev 13790)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-05-31 14:25:11 UTC (rev 13791)
@@ -38,7 +38,7 @@
public class PsInputString implements PsInput {
/** The String whose content is the PostScript input. */
- private String wrappedString;
+ private PsString wrappedString;
/** Flag indicating whether this content has already been consumed or not. */
private boolean hasBeenConsumed = false;
@@ -47,7 +47,7 @@
* Constructor.
* @param theString The String whose content is the PostScript input.
*/
- public PsInputString(final String theString) {
+ public PsInputString(final PsString theString) {
this.wrappedString = theString;
}
@@ -57,7 +57,7 @@
return null;
}
this.hasBeenConsumed = true;
- return new ByteArray(this.wrappedString);
+ return new ByteArray(this.wrappedString.getValue());
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-05-31 14:08:58 UTC (rev 13790)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-05-31 14:25:11 UTC (rev 13791)
@@ -357,7 +357,7 @@
return;
}
/* Otherwise, execute it. */
- final PsInputString stringInput = new PsInputString(psString.getValue());
+ final PsInputString stringInput = new PsInputString(psString);
final PsFileReal inputFile = new PsFileReal(stringInput);
this.executionStack.push(inputFile);
return;
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 14:08:58 UTC (rev 13790)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 14:25:11 UTC (rev 13791)
@@ -41,6 +41,17 @@
public class PsSystemDict4aTests {
/**
+ * Converts a String into an object executable by the PostScript interpreter.
+ * @param inputString The string to be converted.
+ * @return The executable wrapped string.
+ */
+ private PsInput createPsInputFromString(final String inputString) {
+ final PsString psString = new PsString(inputString);
+ final PsInputString psInputString = new PsInputString(psString);
+ return psInputString;
+ }
+
+ /**
* Test of the "dict" operator.
* @throws PsInterpreterException4a For PostScript errors.
* @throws PsOperatorException For PostScript operator errors.
@@ -47,7 +58,7 @@
*/
@Test
public void testDict01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("3 dict");
+ final PsInput input = createPsInputFromString("3 dict");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -64,7 +75,7 @@
@Test
public void testPop01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("1 2 3 pop");
+ PsInput input = createPsInputFromString("1 2 3 pop");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
/* There should be two items remaining on the stack. */
@@ -81,7 +92,7 @@
assertEquals(1, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsInputString("1 2 3 pop pop");
+ input = createPsInputFromString("1 2 3 pop pop");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
/* There should be one item remaining on the stack. */
@@ -100,7 +111,7 @@
*/
@Test
public void testBegin01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("17 dict begin");
+ final PsInput input = createPsInputFromString("17 dict begin");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(0, interpreter.getOperandStack().size());
@@ -116,7 +127,7 @@
@Test
public void testDiv01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("3 2 div");
+ PsInput input = createPsInputFromString("3 2 div");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -126,7 +137,7 @@
assertEquals(1.5, real.getDoubleValue(), .0000001);
/* Second example from the PSLRM, 2nd ed. */
- input = new PsInputString("4 2 div");
+ input = createPsInputFromString("4 2 div");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -144,7 +155,7 @@
@Test
public void testIdiv01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("3 2 idiv");
+ PsInput input = createPsInputFromString("3 2 idiv");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -154,7 +165,7 @@
assertEquals(1, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsInputString("4 2 idiv");
+ input = createPsInputFromString("4 2 idiv");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -164,7 +175,7 @@
assertEquals(2, integer.intValue());
/* Third example from the PSLRM, 2nd ed. */
- input = new PsInputString("-5 2 idiv");
+ input = createPsInputFromString("-5 2 idiv");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -182,7 +193,7 @@
@Test
public void testAdd01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("3 4 add");
+ PsInput input = createPsInputFromString("3 4 add");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -191,7 +202,7 @@
assertEquals(7, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsInputString("9.9 1.1 add");
+ input = createPsInputFromString("9.9 1.1 add");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -208,7 +219,7 @@
@Test
public void testSub01() throws PsInterpreterException4a, PsOperatorException {
/* Inverse of the first example for "add" from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("7 3 sub");
+ PsInput input = createPsInputFromString("7 3 sub");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -217,7 +228,7 @@
assertEquals(4, integer.intValue());
/* Inverse of the second example for "add" from the PSLRM, 2nd ed. */
- input = new PsInputString("11.0 9.9 sub");
+ input = createPsInputFromString("11.0 9.9 sub");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -234,7 +245,7 @@
@Test
public void testMul01() throws PsInterpreterException4a, PsOperatorException {
/* Use the same operands as for the "add" operator tests. */
- PsInput input = new PsInputString("3 4 mul");
+ PsInput input = createPsInputFromString("3 4 mul");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -243,7 +254,7 @@
assertEquals(12, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsInputString("9.9 1.1 mul");
+ input = createPsInputFromString("9.9 1.1 mul");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -268,7 +279,7 @@
*/
@Test
public void testTrueOperator01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("true");
+ final PsInput input = createPsInputFromString("true");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -285,7 +296,7 @@
*/
@Test
public void testFalseOperator01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("false");
+ final PsInput input = createPsInputFromString("false");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -519,7 +530,7 @@
@Test
public void testNeg01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd Ed. */
- PsInput input = new PsInputString("4.5 neg");
+ PsInput input = createPsInputFromString("4.5 neg");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -527,7 +538,7 @@
assertEquals(new BigDecimal("-4.5"), ((PsReal) object).getValue());
/* Second example from the PSLRM, 2nd Ed. */
- input = new PsInputString("-3 neg");
+ input = createPsInputFromString("-3 neg");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -549,7 +560,7 @@
generalBooleanTest("false not", true);
/* Third example from the PSLRM, 2nd Ed. */
- final PsInput input = new PsInputString("52 not");
+ final PsInput input = createPsInputFromString("52 not");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -577,7 +588,7 @@
generalBooleanTest("false false or", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- final PsInput input = new PsInputString("17 5 or");
+ final PsInput input = createPsInputFromString("17 5 or");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -605,7 +616,7 @@
generalBooleanTest("false false xor", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- PsInput input = new PsInputString("7 3 xor");
+ PsInput input = createPsInputFromString("7 3 xor");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -613,7 +624,7 @@
assertEquals(new BigDecimal(4), ((PsInteger) object).getValue());
/* Sixth example from the PSLRM, 2nd Ed. */
- input = new PsInputString("12 3 xor");
+ input = createPsInputFromString("12 3 xor");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -641,7 +652,7 @@
generalBooleanTest("false false and", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- PsInput input = new PsInputString("99 1 and");
+ PsInput input = createPsInputFromString("99 1 and");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -649,7 +660,7 @@
assertEquals(new BigDecimal(1), ((PsInteger) object).getValue());
/* Sixth example from the PSLRM, 2nd Ed. */
- input = new PsInputString("52 7 and");
+ input = createPsInputFromString("52 7 and");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -665,7 +676,7 @@
@Test
public void testCvx01() throws PsInterpreterException4a, PsOperatorException {
/* First create a name and make sure it is not executable. */
- PsInput input = new PsInputString("/literal");
+ PsInput input = createPsInputFromString("/literal");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -675,7 +686,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Now make the same name executable. */
- input = new PsInputString("/literal cvx");
+ input = createPsInputFromString("/literal cvx");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -686,7 +697,7 @@
/* Now test a string that is not executable. This example is from the PSLRM, 2nd Ed., in the
* "exec" doc. */
- input = new PsInputString("(3 2 add)");
+ input = createPsInputFromString("(3 2 add)");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -696,7 +707,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Now make the same string executable. */
- input = new PsInputString("(3 2 add) cvx");
+ input = createPsInputFromString("(3 2 add) cvx");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -713,7 +724,7 @@
*/
@Test
public void testExec01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("(3 2 add) cvx exec");
+ final PsInput input = createPsInputFromString("(3 2 add) cvx exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -731,7 +742,7 @@
*/
@Test
public void testExec02() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("3 2 /add exec");
+ final PsInput input = createPsInputFromString("3 2 /add exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(3, interpreter.getOperandStack().size());
@@ -761,7 +772,7 @@
*/
@Test
public void testExec03() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("3 2 /add cvx exec");
+ final PsInput input = createPsInputFromString("3 2 /add cvx exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -798,7 +809,7 @@
@Test
public void testCount01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("clear count");
+ PsInput input = createPsInputFromString("clear count");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -807,7 +818,7 @@
assertEquals(0, psInteger.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsInputString("clear 1 2 3 count");
+ input = createPsInputFromString("clear 1 2 3 count");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -824,7 +835,7 @@
@Test
public void testEq01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("4.0 4 eq");
+ PsInput input = createPsInputFromString("4.0 4 eq");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -834,7 +845,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsInputString("(abc)(abc) eq");
+ input = createPsInputFromString("(abc)(abc) eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -844,7 +855,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Third example from the PSLRM, 2nd ed. */
- input = new PsInputString("(abc) /abc eq");
+ input = createPsInputFromString("(abc) /abc eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -854,7 +865,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fourth example from the PSLRM, 2nd ed. */
- input = new PsInputString("[1 2 3] dup eq");
+ input = createPsInputFromString("[1 2 3] dup eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -864,7 +875,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fifth example from the PSLRM, 2nd ed. */
- input = new PsInputString("[1 2 3] [1 2 3] eq");
+ input = createPsInputFromString("[1 2 3] [1 2 3] eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -882,7 +893,7 @@
@Test
public void testNe01() throws PsInterpreterException4a, PsOperatorException {
/* First example (for "eq") from the PSLRM, 2nd ed. */
- PsInput input = new PsInputString("4.0 4 ne");
+ PsInput input = createPsInputFromString("4.0 4 ne");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -892,7 +903,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Second example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsInputString("(abc)(abc) ne");
+ input = createPsInputFromString("(abc)(abc) ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -902,7 +913,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Third example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsInputString("(abc) /abc ne");
+ input = createPsInputFromString("(abc) /abc ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -912,7 +923,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fourth example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsInputString("[1 2 3] dup ne");
+ input = createPsInputFromString("[1 2 3] dup ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -922,7 +933,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fifth example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsInputString("[1 2 3] [1 2 3] ne");
+ input = createPsInputFromString("[1 2 3] [1 2 3] ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -949,7 +960,7 @@
@Test
public void testMatrix01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- final PsInput input = new PsInputString("matrix");
+ final PsInput input = createPsInputFromString("matrix");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -1567,7 +1578,7 @@
final boolean isEqualTo, final boolean isGreaterThan) throws PsInterpreterException4a,
PsOperatorException {
/* Test number that is less. */
- PsInput input = new PsInputString("2 3 " + comparisonOperation);
+ PsInput input = createPsInputFromString("2 3 " + comparisonOperation);
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1577,7 +1588,7 @@
assertTrue(theBoolean.getValue() == isLessThan);
/* Test number that is equal. */
- input = new PsInputString("4 4 " + comparisonOperation);
+ input = createPsInputFromString("4 4 " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1587,7 +1598,7 @@
assertTrue(theBoolean.getValue() == isEqualTo);
/* Test number that is greater. */
- input = new PsInputString("7 6.9 " + comparisonOperation);
+ input = createPsInputFromString("7 6.9 " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1597,7 +1608,7 @@
assertTrue(theBoolean.getValue() == isGreaterThan);
/* Test String that is less. */
- input = new PsInputString("(abc) (xyz) " + comparisonOperation);
+ input = createPsInputFromString("(abc) (xyz) " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1607,7 +1618,7 @@
assertTrue(theBoolean.getValue() == isLessThan);
/* Test String that is equal. */
- input = new PsInputString("(pdq) (pdq) " + comparisonOperation);
+ input = createPsInputFromString("(pdq) (pdq) " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1617,7 +1628,7 @@
assertTrue(theBoolean.getValue() == isEqualTo);
/* Test String that is greater. */
- input = new PsInputString("(xyz) (abc) " + comparisonOperation);
+ input = createPsInputFromString("(xyz) (abc) " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1637,7 +1648,7 @@
*/
private void generalBooleanTest(final String testString, final boolean expectedResult)
throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString(testString);
+ final PsInput input = createPsInputFromString(testString);
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -1652,7 +1663,7 @@
*/
@Test
public void testVersion01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("version");
+ final PsInput input = createPsInputFromString("version");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1670,12 +1681,12 @@
@Test
public void testCvr01() throws PsInterpreterException4a, PsOperatorException {
/* Test a real. */
- PsInput input = new PsInputString("9.2");
+ PsInput input = createPsInputFromString("9.2");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsReal);
- input = new PsInputString("cvr");
+ input = createPsInputFromString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
PsObject object2 = interpreter.getOperandStack().pop();
@@ -1684,12 +1695,12 @@
assertTrue(object1 == object2);
/* Test an integer. */
- input = new PsInputString("3");
+ input = createPsInputFromString("3");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsInteger);
- input = new PsInputString("cvr");
+ input = createPsInputFromString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
@@ -1700,12 +1711,12 @@
assertTrue(number1.getValue().compareTo(number2.getValue()) == 0);
/* Test a String containing a real. */
- input = new PsInputString("(12.98)");
+ input = createPsInputFromString("(12.98)");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsString);
- input = new PsInputString("cvr");
+ input = createPsInputFromString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
@@ -1714,12 +1725,12 @@
assertTrue(new BigDecimal("12.98").compareTo(number2.getValue()) == 0);
/* Test a String containing integer. */
- input = new PsInputString("(15)");
+ input = createPsInputFromString("(15)");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsString);
- input = new PsInputString("cvr");
+ input = createPsInputFromString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
@@ -1736,7 +1747,7 @@
*/
@Test
public void testClear01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsInputString("1 2 3 clear");
+ final PsInput input = createPsInputFromString("1 2 3 clear");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(0, interpreter.getOperandStack().size());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 14:09:03
|
Revision: 13790
http://sourceforge.net/p/foray/code/13790
Author: victormote
Date: 2025-05-31 14:08:58 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Fix bug in capacity logic.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java 2025-05-31 13:40:27 UTC (rev 13789)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java 2025-05-31 14:08:58 UTC (rev 13790)
@@ -98,7 +98,7 @@
@Override
public ByteArrayBuilder append(final byte value) {
- ensureCapacity(1);
+ ensureCapacity(this.length + 1);
this.length ++;
setByteAt(this.length - 1, value);
return this;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 13:40:31
|
Revision: 13789
http://sourceforge.net/p/foray/code/13789
Author: victormote
Date: 2025-05-31 13:40:27 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Rename class, for consistency.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
Added Paths:
-----------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java
Removed Paths:
-------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsStringInput.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java 2025-05-31 13:04:55 UTC (rev 13788)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java 2025-05-31 13:40:27 UTC (rev 13789)
@@ -30,7 +30,7 @@
/**
* Enumeration of PostScript error types.
- * @see "PostScript Language Reference, Third Edition, Section 8.2, Heading "Errors"."
+ * @see "PostScript Language Reference, Third Edition, Section 8.1, Heading "Errors"."
*/
public enum PsError {
Copied: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java (from rev 13776, trunk/foray/foray-ps/src/main/java/org/foray/ps/PsStringInput.java)
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java (rev 0)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInputString.java 2025-05-31 13:40:27 UTC (rev 13789)
@@ -0,0 +1,63 @@
+/*
+ * 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.ps;
+
+import org.foray.primitive.sequence.ByteArray;
+
+import org.axsl.primitive.sequence.ByteSequence;
+
+/**
+ * A {@link PsInput} implementation that simply wraps a String.
+ */
+public class PsInputString implements PsInput {
+
+ /** The String whose content is the PostScript input. */
+ private String wrappedString;
+
+ /** Flag indicating whether this content has already been consumed or not. */
+ private boolean hasBeenConsumed = false;
+
+ /**
+ * Constructor.
+ * @param theString The String whose content is the PostScript input.
+ */
+ public PsInputString(final String theString) {
+ this.wrappedString = theString;
+ }
+
+ @Override
+ public ByteSequence providePostScriptInput() {
+ if (this.hasBeenConsumed) {
+ return null;
+ }
+ this.hasBeenConsumed = true;
+ return new ByteArray(this.wrappedString);
+ }
+
+}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-05-31 13:04:55 UTC (rev 13788)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsInterpreter4a.java 2025-05-31 13:40:27 UTC (rev 13789)
@@ -357,7 +357,7 @@
return;
}
/* Otherwise, execute it. */
- final PsStringInput stringInput = new PsStringInput(psString.getValue());
+ final PsInputString stringInput = new PsInputString(psString.getValue());
final PsFileReal inputFile = new PsFileReal(stringInput);
this.executionStack.push(inputFile);
return;
Deleted: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsStringInput.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsStringInput.java 2025-05-31 13:04:55 UTC (rev 13788)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsStringInput.java 2025-05-31 13:40:27 UTC (rev 13789)
@@ -1,63 +0,0 @@
-/*
- * 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.ps;
-
-import org.foray.primitive.sequence.ByteArray;
-
-import org.axsl.primitive.sequence.ByteSequence;
-
-/**
- * A {@link PsInput} implementation that simply wraps a String.
- */
-public class PsStringInput implements PsInput {
-
- /** The String whose content is the PostScript input. */
- private String wrappedString;
-
- /** Flag indicating whether this content has already been consumed or not. */
- private boolean hasBeenConsumed = false;
-
- /**
- * Constructor.
- * @param theString The String whose content is the PostScript input.
- */
- public PsStringInput(final String theString) {
- this.wrappedString = theString;
- }
-
- @Override
- public ByteSequence providePostScriptInput() {
- if (this.hasBeenConsumed) {
- return null;
- }
- this.hasBeenConsumed = true;
- return new ByteArray(this.wrappedString);
- }
-
-}
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 13:04:55 UTC (rev 13788)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/PsSystemDict4aTests.java 2025-05-31 13:40:27 UTC (rev 13789)
@@ -47,7 +47,7 @@
*/
@Test
public void testDict01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("3 dict");
+ final PsInput input = new PsInputString("3 dict");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -64,7 +64,7 @@
@Test
public void testPop01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("1 2 3 pop");
+ PsInput input = new PsInputString("1 2 3 pop");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
/* There should be two items remaining on the stack. */
@@ -81,7 +81,7 @@
assertEquals(1, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsStringInput("1 2 3 pop pop");
+ input = new PsInputString("1 2 3 pop pop");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
/* There should be one item remaining on the stack. */
@@ -100,7 +100,7 @@
*/
@Test
public void testBegin01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("17 dict begin");
+ final PsInput input = new PsInputString("17 dict begin");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(0, interpreter.getOperandStack().size());
@@ -116,7 +116,7 @@
@Test
public void testDiv01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("3 2 div");
+ PsInput input = new PsInputString("3 2 div");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -126,7 +126,7 @@
assertEquals(1.5, real.getDoubleValue(), .0000001);
/* Second example from the PSLRM, 2nd ed. */
- input = new PsStringInput("4 2 div");
+ input = new PsInputString("4 2 div");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -144,7 +144,7 @@
@Test
public void testIdiv01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("3 2 idiv");
+ PsInput input = new PsInputString("3 2 idiv");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -154,7 +154,7 @@
assertEquals(1, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsStringInput("4 2 idiv");
+ input = new PsInputString("4 2 idiv");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -164,7 +164,7 @@
assertEquals(2, integer.intValue());
/* Third example from the PSLRM, 2nd ed. */
- input = new PsStringInput("-5 2 idiv");
+ input = new PsInputString("-5 2 idiv");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -182,7 +182,7 @@
@Test
public void testAdd01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("3 4 add");
+ PsInput input = new PsInputString("3 4 add");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -191,7 +191,7 @@
assertEquals(7, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsStringInput("9.9 1.1 add");
+ input = new PsInputString("9.9 1.1 add");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -208,7 +208,7 @@
@Test
public void testSub01() throws PsInterpreterException4a, PsOperatorException {
/* Inverse of the first example for "add" from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("7 3 sub");
+ PsInput input = new PsInputString("7 3 sub");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -217,7 +217,7 @@
assertEquals(4, integer.intValue());
/* Inverse of the second example for "add" from the PSLRM, 2nd ed. */
- input = new PsStringInput("11.0 9.9 sub");
+ input = new PsInputString("11.0 9.9 sub");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -234,7 +234,7 @@
@Test
public void testMul01() throws PsInterpreterException4a, PsOperatorException {
/* Use the same operands as for the "add" operator tests. */
- PsInput input = new PsStringInput("3 4 mul");
+ PsInput input = new PsInputString("3 4 mul");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -243,7 +243,7 @@
assertEquals(12, integer.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsStringInput("9.9 1.1 mul");
+ input = new PsInputString("9.9 1.1 mul");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -268,7 +268,7 @@
*/
@Test
public void testTrueOperator01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("true");
+ final PsInput input = new PsInputString("true");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -285,7 +285,7 @@
*/
@Test
public void testFalseOperator01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("false");
+ final PsInput input = new PsInputString("false");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -519,7 +519,7 @@
@Test
public void testNeg01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd Ed. */
- PsInput input = new PsStringInput("4.5 neg");
+ PsInput input = new PsInputString("4.5 neg");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -527,7 +527,7 @@
assertEquals(new BigDecimal("-4.5"), ((PsReal) object).getValue());
/* Second example from the PSLRM, 2nd Ed. */
- input = new PsStringInput("-3 neg");
+ input = new PsInputString("-3 neg");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -549,7 +549,7 @@
generalBooleanTest("false not", true);
/* Third example from the PSLRM, 2nd Ed. */
- final PsInput input = new PsStringInput("52 not");
+ final PsInput input = new PsInputString("52 not");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -577,7 +577,7 @@
generalBooleanTest("false false or", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- final PsInput input = new PsStringInput("17 5 or");
+ final PsInput input = new PsInputString("17 5 or");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -605,7 +605,7 @@
generalBooleanTest("false false xor", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- PsInput input = new PsStringInput("7 3 xor");
+ PsInput input = new PsInputString("7 3 xor");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -613,7 +613,7 @@
assertEquals(new BigDecimal(4), ((PsInteger) object).getValue());
/* Sixth example from the PSLRM, 2nd Ed. */
- input = new PsStringInput("12 3 xor");
+ input = new PsInputString("12 3 xor");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -641,7 +641,7 @@
generalBooleanTest("false false and", false);
/* Fifth example from the PSLRM, 2nd Ed. */
- PsInput input = new PsStringInput("99 1 and");
+ PsInput input = new PsInputString("99 1 and");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -649,7 +649,7 @@
assertEquals(new BigDecimal(1), ((PsInteger) object).getValue());
/* Sixth example from the PSLRM, 2nd Ed. */
- input = new PsStringInput("52 7 and");
+ input = new PsInputString("52 7 and");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -665,7 +665,7 @@
@Test
public void testCvx01() throws PsInterpreterException4a, PsOperatorException {
/* First create a name and make sure it is not executable. */
- PsInput input = new PsStringInput("/literal");
+ PsInput input = new PsInputString("/literal");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -675,7 +675,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Now make the same name executable. */
- input = new PsStringInput("/literal cvx");
+ input = new PsInputString("/literal cvx");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -686,7 +686,7 @@
/* Now test a string that is not executable. This example is from the PSLRM, 2nd Ed., in the
* "exec" doc. */
- input = new PsStringInput("(3 2 add)");
+ input = new PsInputString("(3 2 add)");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -696,7 +696,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Now make the same string executable. */
- input = new PsStringInput("(3 2 add) cvx");
+ input = new PsInputString("(3 2 add) cvx");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -713,7 +713,7 @@
*/
@Test
public void testExec01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("(3 2 add) cvx exec");
+ final PsInput input = new PsInputString("(3 2 add) cvx exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -731,7 +731,7 @@
*/
@Test
public void testExec02() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("3 2 /add exec");
+ final PsInput input = new PsInputString("3 2 /add exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(3, interpreter.getOperandStack().size());
@@ -761,7 +761,7 @@
*/
@Test
public void testExec03() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("3 2 /add cvx exec");
+ final PsInput input = new PsInputString("3 2 /add cvx exec");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -798,7 +798,7 @@
@Test
public void testCount01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("clear count");
+ PsInput input = new PsInputString("clear count");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -807,7 +807,7 @@
assertEquals(0, psInteger.intValue());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsStringInput("clear 1 2 3 count");
+ input = new PsInputString("clear 1 2 3 count");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -824,7 +824,7 @@
@Test
public void testEq01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("4.0 4 eq");
+ PsInput input = new PsInputString("4.0 4 eq");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -834,7 +834,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Second example from the PSLRM, 2nd ed. */
- input = new PsStringInput("(abc)(abc) eq");
+ input = new PsInputString("(abc)(abc) eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -844,7 +844,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Third example from the PSLRM, 2nd ed. */
- input = new PsStringInput("(abc) /abc eq");
+ input = new PsInputString("(abc) /abc eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -854,7 +854,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fourth example from the PSLRM, 2nd ed. */
- input = new PsStringInput("[1 2 3] dup eq");
+ input = new PsInputString("[1 2 3] dup eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -864,7 +864,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fifth example from the PSLRM, 2nd ed. */
- input = new PsStringInput("[1 2 3] [1 2 3] eq");
+ input = new PsInputString("[1 2 3] [1 2 3] eq");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -882,7 +882,7 @@
@Test
public void testNe01() throws PsInterpreterException4a, PsOperatorException {
/* First example (for "eq") from the PSLRM, 2nd ed. */
- PsInput input = new PsStringInput("4.0 4 ne");
+ PsInput input = new PsInputString("4.0 4 ne");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object = interpreter.getOperandStack().pop();
@@ -892,7 +892,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Second example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsStringInput("(abc)(abc) ne");
+ input = new PsInputString("(abc)(abc) ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -902,7 +902,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Third example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsStringInput("(abc) /abc ne");
+ input = new PsInputString("(abc) /abc ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -912,7 +912,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fourth example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsStringInput("[1 2 3] dup ne");
+ input = new PsInputString("[1 2 3] dup ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -922,7 +922,7 @@
assertEquals(0, interpreter.getOperandStack().size());
/* Fifth example (for "eq") from the PSLRM, 2nd ed. */
- input = new PsStringInput("[1 2 3] [1 2 3] ne");
+ input = new PsInputString("[1 2 3] [1 2 3] ne");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object = interpreter.getOperandStack().pop();
@@ -949,7 +949,7 @@
@Test
public void testMatrix01() throws PsInterpreterException4a, PsOperatorException {
/* First example from the PSLRM, 2nd ed. */
- final PsInput input = new PsStringInput("matrix");
+ final PsInput input = new PsInputString("matrix");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -1567,7 +1567,7 @@
final boolean isEqualTo, final boolean isGreaterThan) throws PsInterpreterException4a,
PsOperatorException {
/* Test number that is less. */
- PsInput input = new PsStringInput("2 3 " + comparisonOperation);
+ PsInput input = new PsInputString("2 3 " + comparisonOperation);
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1577,7 +1577,7 @@
assertTrue(theBoolean.getValue() == isLessThan);
/* Test number that is equal. */
- input = new PsStringInput("4 4 " + comparisonOperation);
+ input = new PsInputString("4 4 " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1587,7 +1587,7 @@
assertTrue(theBoolean.getValue() == isEqualTo);
/* Test number that is greater. */
- input = new PsStringInput("7 6.9 " + comparisonOperation);
+ input = new PsInputString("7 6.9 " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1597,7 +1597,7 @@
assertTrue(theBoolean.getValue() == isGreaterThan);
/* Test String that is less. */
- input = new PsStringInput("(abc) (xyz) " + comparisonOperation);
+ input = new PsInputString("(abc) (xyz) " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1607,7 +1607,7 @@
assertTrue(theBoolean.getValue() == isLessThan);
/* Test String that is equal. */
- input = new PsStringInput("(pdq) (pdq) " + comparisonOperation);
+ input = new PsInputString("(pdq) (pdq) " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1617,7 +1617,7 @@
assertTrue(theBoolean.getValue() == isEqualTo);
/* Test String that is greater. */
- input = new PsStringInput("(xyz) (abc) " + comparisonOperation);
+ input = new PsInputString("(xyz) (abc) " + comparisonOperation);
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1637,7 +1637,7 @@
*/
private void generalBooleanTest(final String testString, final boolean expectedResult)
throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput(testString);
+ final PsInput input = new PsInputString(testString);
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
final PsObject object = interpreter.getOperandStack().pop();
@@ -1652,7 +1652,7 @@
*/
@Test
public void testVersion01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("version");
+ final PsInput input = new PsInputString("version");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(1, interpreter.getOperandStack().size());
@@ -1670,12 +1670,12 @@
@Test
public void testCvr01() throws PsInterpreterException4a, PsOperatorException {
/* Test a real. */
- PsInput input = new PsStringInput("9.2");
+ PsInput input = new PsInputString("9.2");
PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
PsObject object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsReal);
- input = new PsStringInput("cvr");
+ input = new PsInputString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
PsObject object2 = interpreter.getOperandStack().pop();
@@ -1684,12 +1684,12 @@
assertTrue(object1 == object2);
/* Test an integer. */
- input = new PsStringInput("3");
+ input = new PsInputString("3");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsInteger);
- input = new PsStringInput("cvr");
+ input = new PsInputString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
@@ -1700,12 +1700,12 @@
assertTrue(number1.getValue().compareTo(number2.getValue()) == 0);
/* Test a String containing a real. */
- input = new PsStringInput("(12.98)");
+ input = new PsInputString("(12.98)");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsString);
- input = new PsStringInput("cvr");
+ input = new PsInputString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
@@ -1714,12 +1714,12 @@
assertTrue(new BigDecimal("12.98").compareTo(number2.getValue()) == 0);
/* Test a String containing integer. */
- input = new PsStringInput("(15)");
+ input = new PsInputString("(15)");
interpreter = new PsInterpreter4a(input, null);
interpreter.process();
object1 = interpreter.getOperandStack().peek();
assertTrue(object1 instanceof PsString);
- input = new PsStringInput("cvr");
+ input = new PsInputString("cvr");
interpreter.getExecutionStack().push(new PsFileReal(input));
interpreter.process();
object2 = interpreter.getOperandStack().pop();
@@ -1736,7 +1736,7 @@
*/
@Test
public void testClear01() throws PsInterpreterException4a, PsOperatorException {
- final PsInput input = new PsStringInput("1 2 3 clear");
+ final PsInput input = new PsInputString("1 2 3 clear");
final PsInterpreter4a interpreter = new PsInterpreter4a(input, null);
interpreter.process();
assertEquals(0, interpreter.getOperandStack().size());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 13:04:58
|
Revision: 13788
http://sourceforge.net/p/foray/code/13788
Author: victormote
Date: 2025-05-31 13:04:55 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Fix compile errors preventing further refactoring.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-05-31 12:56:50 UTC (rev 13787)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsFileFilter.java 2025-05-31 13:04:55 UTC (rev 13788)
@@ -28,6 +28,7 @@
package org.foray.ps;
+import org.foray.primitive.sequence.ByteArrayBuilder;
import org.foray.ps.filter.EexecDecodeFilter;
import java.io.IOException;
@@ -83,7 +84,12 @@
} else if (this.underlyingString != null) {
tempChunk = this.underlyingString.getValue().getBytes();
}
- return tempChunk == null ? null : this.filter.decode(tempChunk);
+ if (tempChunk == null) {
+ return null;
+ }
+ final ByteArrayBuilder builder = new ByteArrayBuilder(tempChunk.length);
+ builder.append(this.filter);
+ return builder.toArray();
}
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-05-31 12:56:50 UTC (rev 13787)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsSystemDict4a.java 2025-05-31 13:04:55 UTC (rev 13788)
@@ -1821,8 +1821,7 @@
/* Create the operand for eexec. */
final PsObject toExec = popOperand(PsOperator.EEXEC);
- final EexecDecodeFilter filter = new EexecDecodeFilter(EexecDecodeFilter.EEXEC_INITIAL_KEY,
- EexecDecodeFilter.EEXEC_RANDOM_BYTES);
+ final EexecDecodeFilter filter = new EexecDecodeFilter(null);
PsFile file = null;
if (toExec instanceof PsFile) {
file = new PsFileFilter(filter, (PsFile) toExec);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 12:56:55
|
Revision: 13787
http://sourceforge.net/p/foray/code/13787
Author: victormote
Date: 2025-05-31 12:56:50 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Minor doc enhancement.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java 2025-05-31 10:38:20 UTC (rev 13786)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsError.java 2025-05-31 12:56:50 UTC (rev 13787)
@@ -30,6 +30,7 @@
/**
* Enumeration of PostScript error types.
+ * @see "PostScript Language Reference, Third Edition, Section 8.2, Heading "Errors"."
*/
public enum PsError {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 10:38:25
|
Revision: 13786
http://sourceforge.net/p/foray/code/13786
Author: victormote
Date: 2025-05-31 10:38:20 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Fix and reenable test.
Modified Paths:
--------------
trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/AsciiHexDecodeFilterTests.java
Modified: trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/AsciiHexDecodeFilterTests.java
===================================================================
--- trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/AsciiHexDecodeFilterTests.java 2025-05-31 10:34:50 UTC (rev 13785)
+++ trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/AsciiHexDecodeFilterTests.java 2025-05-31 10:38:20 UTC (rev 13786)
@@ -35,7 +35,6 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
@@ -70,13 +69,13 @@
* @throws IOException Not expected here.
*/
@Test
- @Disabled
public void testReadInput() throws IOException {
final byte[] inputBytes = INPUT.getBytes("US-ASCII");
final InputStream is = new ByteArrayInputStream(inputBytes);
final AsciiHexDecodeFilter filter = new AsciiHexDecodeFilter(is);
-// filter.readInput();
- final byte[] actual = filter.getDecodedBuffer();
+ final ByteArrayBuilder builder = new ByteArrayBuilder();
+ builder.append(filter);
+ final byte[] actual = builder.toArray();
filter.close();
assertArrayEquals(EXPECTED, actual);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 10:34:53
|
Revision: 13785
http://sourceforge.net/p/foray/code/13785
Author: victormote
Date: 2025-05-31 10:34:50 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Convert EexecDecodeFilter to a true filter. This temporarily breaks the build.
Modified Paths:
--------------
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java
trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/EexecDecodeFilterTests.java
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java 2025-05-31 10:17:40 UTC (rev 13784)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java 2025-05-31 10:34:50 UTC (rev 13785)
@@ -30,10 +30,11 @@
import org.foray.primitive.StringUtils;
+import org.axsl.constants.MeasurementConstants;
import org.axsl.constants.PrimitiveConstants;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
/**
* <p>Handles the PostScript encryption used in the "eexec" operator, usually used in Type1 fonts to encrypt the actual
@@ -44,16 +45,6 @@
* writing or embedding programs that need to encrypt code to be used by that operator.
* It is not (to our knowledge) available as a standard filter.</p>
*
- * <p>This filter is designed to allow chunks of data to be encoded or decoded at a time.
- * In other words, the entire set of data does not have to be encoded or decoded as the same time, but can be done in
- * pieces.
- * (This was done to save memory).
- * However, the encoding and decoding used by this filter are dependent on data previously processed.
- * Therefore, you must process the data starting at its beginning to be able to encode or decode subsequent data.
- * Both the encode and decode methods are stateful, i.e. they are highly dependent on keeping track of their state from
- * one chunk to the next.
- * Of course, there is nothing wrong with encoding or decoding your entire input in one chunk, if you wish to do so.</p>
- *
* <p>Type1 fonts actually use a double layer of encryption, whereby the glyph definitions are encrypted using this
* algorithm, then a large chunk of the font file, which includes the glyph definitions, is encrypted again, also using
* this algorithm (although with different seeding and constants).
@@ -64,8 +55,7 @@
* @see "PostScript Language Reference, Third Edition, which cites the above Type 1 documentation as the authoritative
* reference on the eexec operator. See the eexec operator in Section 8.2."
*/
-public class EexecDecodeFilter {
- /* TODO: This class should eventually extend PSDecodeFilter. */
+public class EexecDecodeFilter extends PsDecodeFilter4a {
/** A magic number specified in "Adobe Type Type 1 Font Format", section 7.2. */
public static final int EEXEC_INITIAL_KEY = 55665;
@@ -86,147 +76,82 @@
* This is an unsigned 16-bit integer. */
private int encryptionKey;
- /** The quantity of random bytes at the beginning of the sequence to be processed, the variable "n" in "Adobe Type
- * Type 1 Font Format", section 7.1. */
- private byte randomBytes;
+ /** The count of bytes read, mostly to discard the random bytes added during encryption. */
+ private int bytesRead = 0;
- /** Tracks the number of random bytes that still need to be discarded. The variable is needed in case not enough
- * bytes are in the first byte array that is decrypted to use them all. */
- private byte randomBytesToDiscard;
-
- /** The first four bytes must be analyzed in order to figure out whether the input is in ASCII hexadecimal format or
- * binary format. */
- private byte[] first4Bytes = new byte[EexecDecodeFilter.EEXEC_RANDOM_BYTES];
-
- /** This tracks how much of the first four bytes has actually been accumulated. This is needed because we might not
- * get all four bytes in the first chunk. */
- private byte first4BytesIndex = 0;
-
- /** Tracks whether the input file is in ASCII hexadecimal format. If it is false, then the input is in binary
- * format. */
- private boolean hexFormat = false;
-
- /** Tracks whether we yet know what format the input file is in. It should be set to false until we have analyzed
- * the first four bytes. */
- private boolean formatResolved = false;
-
- /** Helper filter used to normalize input in ASCII hex format. */
- private AsciiHexDecodeFilter hexFilter = null;
-
/**
- * Default constructor.
- * @param encryptionKey The starting encryption key to use.
- * @param randomBytes The quantity of random bytes that should occur at the beginning of the sequence to be
- * processed.
+ * Constructor.
+ * @param inputStream The inputStream to be decoded.
*/
- public EexecDecodeFilter(final int encryptionKey, final byte randomBytes) {
- this.encryptionKey = encryptionKey;
- this.randomBytes = randomBytes;
- this.randomBytesToDiscard = this.randomBytes;
+ public EexecDecodeFilter(final InputStream inputStream) {
+ super(inputStream);
+ this.encryptionKey = EEXEC_INITIAL_KEY;
}
- /**
- * Decodes the encoded bytes.
- * @param input The encoded bytes.
- * @return The decoded bytes.
- * @throws IOException For I/O errors during processing.
- */
- public byte[] decode(final byte[] input) throws IOException {
- if (input.length < 1) {
- return new byte[0];
+ @Override
+ public int read() throws IOException {
+ final int cipherText = in.read();
+ if (cipherText < 0) {
+ return -1;
}
- if (! this.formatResolved) {
- resolveFormat(input);
- /* If the format is not yet resolved, it is because we don't have all of the first 4 bytes yet.
- * Fill the input array with spaces and return it. */
- if (! this.formatResolved) {
- for (int i = 0; i < input.length; i++) {
- input[i] = ' ';
- }
- return input;
- }
- }
- byte[] normalizedInput = input;
- if (this.hexFormat) {
- if (this.hexFilter == null) {
- final ByteArrayInputStream bais = new ByteArrayInputStream(input);
- this.hexFilter = new AsciiHexDecodeFilter(bais);
- }
- this.hexFilter.read();
- normalizedInput = this.hexFilter.getDecodedBuffer();
- }
+ this.bytesRead ++;
+ final int temp = this.encryptionKey >> PrimitiveConstants.SHIFT_1_BYTE;
+ int plainText = cipherText ^ temp;
+ plainText = plainText & PrimitiveConstants.MAX_8_BIT_UNSIGNED_INT;
- final byte[] output = new byte[normalizedInput.length];
- for (int i = 0; i < normalizedInput.length; i++) {
- output[i] = decrypt(normalizedInput[i]);
- }
- /* Uncomment the next two lines to spit out the output to system out. */
-// final String outputString = new String(output, "US-ASCII");
-// System.out.print(outputString);
- return output;
- }
-
- /**
- * Decrypts a byte of encoded (encrypted) text.
- * @param cipherText The byte of encoded (encrypted) text to be decrypted.
- * @return The decrypted value.
- */
- private byte decrypt(final byte cipherText) {
- final byte temp = (byte) (this.encryptionKey >> PrimitiveConstants.SHIFT_1_BYTE);
- byte plainText = (byte) (cipherText ^ temp);
- // The trick here is to get cipherText treated as unsigned
- int unsignedCipherText = cipherText;
- if (cipherText < 0) {
- unsignedCipherText += PrimitiveConstants.MAX_8_BIT_UNSIGNED_VALUES;
- }
- long temp2 = unsignedCipherText + this.encryptionKey;
+ long temp2 = cipherText + this.encryptionKey;
temp2 *= EexecDecodeFilter.ENCRYPTION_CONSTANT_1;
temp2 += EexecDecodeFilter.ENCRYPTION_CONSTANT_2;
temp2 %= PrimitiveConstants.MAX_16_BIT_UNSIGNED_VALUES;
this.encryptionKey = (int) temp2;
- /*
- * The first few bytes of the decrypted text need to be discarded.
- * To avoid copying arrays around, we'll try to just replace them with spaces.
- */
- if (this.randomBytesToDiscard > 0) {
- plainText = ' ';
- this.randomBytesToDiscard --;
+
+ /* The initial random bytes are meaningless and should be discarded by the downstream user.
+ * We convert them to ASCII spaces for readability. */
+ if (this.bytesRead <= EEXEC_RANDOM_BYTES) {
+ return ' ';
}
return plainText;
}
/**
- * If possible, determines whether the input is ASCII hex or binary.
- * @param input The array whose content should be tested.
+ * Examines the first four bytes of an input stream to determine whether the content is ASCII hex or binary.
+ * It marks and resets the stream to its original position.
+ * @param input The input stream to be tested.
+ * @return true if the input stream is ASCII hex, or false if it is binary.
*/
- private void resolveFormat(final byte[] input) {
- byte inputIndex = 0;
- while (this.first4BytesIndex < EexecDecodeFilter.EEXEC_RANDOM_BYTES
- && inputIndex < input.length) {
- this.first4Bytes[this.first4BytesIndex] = input[inputIndex];
- inputIndex ++;
- this.first4BytesIndex ++;
+ public static boolean isAsciiHex(final InputStream input) throws IOException {
+ final byte[] first4Bytes = new byte[EexecDecodeFilter.EEXEC_RANDOM_BYTES];
+ input.mark(MeasurementConstants.BYTES_PER_KILOBYTE);
+ final int bytesRead = input.read(first4Bytes);
+ input.reset();
+ if (bytesRead != EexecDecodeFilter.EEXEC_RANDOM_BYTES) {
+ /* Restriction described at "Adobe Type Type 1 Font Format", section 7.2. */
+ throw new IllegalArgumentException("The InputStream must contain at least 4 bytes.");
}
- if (this.first4BytesIndex < EexecDecodeFilter.EEXEC_RANDOM_BYTES - 1) {
- return;
+ if (AsciiHexEncodeFilter.isAsciiHexWhitespace(first4Bytes[0])) {
+ /* Restriction described at "Adobe Type Type 1 Font Format", section 7.2. */
+ throw new IllegalArgumentException("The InputStream must not start with ASCII whitespace.");
}
- /*
- * Otherwise, we have the first four bytes. Section 7.2 of the Adobe Type 1 Font Format spec says that at least
- * one of the first 4 ciphertext bytes must not be one of the ASCII hexadecimal character codes (0-9, A-F, a-f).
+
+ /* Section 7.2 of the Adobe Type 1 Font Format spec says that at least one of the first 4 ciphertext bytes must
+ * not be one of the ASCII hexadecimal character codes (0-9, A-F, a-f).
* Since the binary format is one byte per ciphertext byte, all we need to do is find one byte in the first four
* that is outside the range for ASCII hexadecimal codes.
* If we find that, then the file is binary.
- * Otherwise it is ASCII hexadecimal.
- */
- for (int i = 0; i < EexecDecodeFilter.EEXEC_RANDOM_BYTES; i++) {
- if (! StringUtils.isASCIIHex(this.first4Bytes[i])) {
- this.hexFormat = false;
- this.formatResolved = true;
- return;
+ * Otherwise it is ASCII hexadecimal. */
+ for (int index = 0; index < first4Bytes.length; index ++) {
+ final byte testByte = first4Bytes[index];
+ if (! StringUtils.isASCIIHex(testByte)) {
+ return false;
}
}
- this.hexFormat = true;
- this.formatResolved = true;
+ return true;
}
+ @Override
+ public String getName() {
+ /* The eexec filter is not a named, accessible filter. */
+ return "N/A";
+ }
+
}
Modified: trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/EexecDecodeFilterTests.java
===================================================================
--- trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/EexecDecodeFilterTests.java 2025-05-31 10:17:40 UTC (rev 13784)
+++ trunk/foray/foray-ps-data/src/test/java/org/foray/ps/filter/EexecDecodeFilterTests.java 2025-05-31 10:34:50 UTC (rev 13785)
@@ -28,11 +28,13 @@
package org.foray.ps.filter;
+import org.foray.primitive.sequence.ByteArrayBuilder;
+
import org.apache.commons.io.IOUtils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.junit.jupiter.api.Disabled;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
@@ -51,7 +53,6 @@
* @throws IOException Not expected here.
*/
@Test
- @Disabled
public void test01() throws IOException {
final InputStream fis =
new FileInputStream("../foray-font/src/test/resources/source-utah.edu/utopia-1.0/putr.pfa");
@@ -59,22 +60,28 @@
fis.close();
/* Take only the portion of the file that is encrypted. These values were obtained by looking at the file. */
- final byte[] encodedBytes = new byte[70956];
+ final int qtyBytes = 70956;
+ final byte[] encodedBytes = new byte[qtyBytes];
System.arraycopy(bytes, 866, encodedBytes, 0, encodedBytes.length);
+ assertEquals(qtyBytes, encodedBytes.length);
- /* Convert the ASCII Hex input to binary data. */
- final InputStream encodedBytesInputStream = new ByteArrayInputStream(encodedBytes);
- final AsciiHexDecodeFilter asciiDecoder = new AsciiHexDecodeFilter(encodedBytesInputStream);
-// asciiDecoder.readInput();
- final byte[] decodedBinaryBytes = asciiDecoder.getDecodedBuffer();
- asciiDecoder.close();
+ /* Create input stream containing the raw input bytes. */
+ final InputStream rawBytes = new ByteArrayInputStream(encodedBytes);
+ assertTrue(EexecDecodeFilter.isAsciiHex(rawBytes));
- /* Now eexec decode the result. */
- final EexecDecodeFilter filter =
- new EexecDecodeFilter(EexecDecodeFilter.EEXEC_INITIAL_KEY,
- EexecDecodeFilter.EEXEC_RANDOM_BYTES);
- final byte[] plaintextBytes = filter.decode(decodedBinaryBytes);
+ /* Wrap the raw bytes in an ASCII Hex decoder filter. */
+ final AsciiHexDecodeFilter hexFilter = new AsciiHexDecodeFilter(rawBytes);
+ /* Wrap the hex decoder in an eexec filter. */
+ final EexecDecodeFilter filter = new EexecDecodeFilter(hexFilter);
+
+ /* Store the decoded bytes for testing. */
+ /* See {@link AsciiHexDecodeFilter#testWithFontInput()} for size computation. */
+ final ByteArrayBuilder builder = new ByteArrayBuilder(34932);
+ builder.append(filter);
+ assertEquals(34932, builder.length());
+ final byte[] plaintextBytes = builder.toArray();
+
/* Convert the byte array to list of String, one per line. */
final InputStream plaintextInputStream = new ByteArrayInputStream(plaintextBytes);
final List<String> lines = (List<String>) IOUtils.readLines(plaintextInputStream, "US-ASCII");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 10:17:44
|
Revision: 13784
http://sourceforge.net/p/foray/code/13784
Author: victormote
Date: 2025-05-31 10:17:40 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Skip creation of intermediate byte array. Just read the input stream directly.
Modified Paths:
--------------
trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java
Modified: trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java 2025-05-31 01:47:55 UTC (rev 13783)
+++ trunk/foray/foray-primitive/src/main/java/org/foray/primitive/sequence/ByteArrayBuilder.java 2025-05-31 10:17:40 UTC (rev 13784)
@@ -37,8 +37,6 @@
import org.axsl.primitive.sequence.ByteSequenceMutable;
import org.axsl.primitive.sequence.MutableSequence;
-import org.apache.commons.io.IOUtils;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
@@ -132,12 +130,12 @@
@Override
public ByteArrayBuilder append(final InputStream stream) throws IOException {
- final byte[] array = IOUtils.toByteArray(stream);
- if (length() < 1) {
- this.backingArray = array;
- this.length = array.length;
- } else {
- append(array);
+ int lastByte = 0;
+ while (lastByte != -1) {
+ lastByte = stream.read();
+ if (lastByte > -1) {
+ append((byte) lastByte);
+ }
}
return this;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-31 01:47:59
|
Revision: 13783
http://sourceforge.net/p/foray/code/13783
Author: victormote
Date: 2025-05-31 01:47:55 +0000 (Sat, 31 May 2025)
Log Message:
-----------
Minor improvements to doc and constants.
Modified Paths:
--------------
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java 2025-05-30 23:56:33 UTC (rev 13782)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/EexecDecodeFilter.java 2025-05-31 01:47:55 UTC (rev 13783)
@@ -67,28 +67,27 @@
public class EexecDecodeFilter {
/* TODO: This class should eventually extend PSDecodeFilter. */
- /** A magic number specified in the PostScript standard. */
+ /** A magic number specified in "Adobe Type Type 1 Font Format", section 7.2. */
public static final int EEXEC_INITIAL_KEY = 55665;
- /** The number of random bytes specified in the PostScript standard. */
+ /** The number of random bytes at the beginning of the stream processed by eexec, as specified in "Adobe Type Type 1
+ * Font Format", section 7.2.
+ * These bytes are ignored by eexec, except to determine whether the remaining bytes in the eexec stream are binary
+ * or ASCII hexadecimal characters. */
public static final byte EEXEC_RANDOM_BYTES = 4;
- /** The number of initial bytes specified in the PostScript standard. */
- public static final byte EEXEC_INITIAL_BYTES = 4;
- /* TODO: Is the initial bytes the same as the random bytes? */
-
- /** A magic number specified in the PostScript standard. */
+ /** A magic number specified in "Adobe Type Type 1 Font Format", section 7.1. */
private static final int ENCRYPTION_CONSTANT_1 = 52845;
- /** A magic number specified in the PostScript standard. */
+ /** A magic number specified in "Adobe Type Type 1 Font Format", section 7.1. */
private static final int ENCRYPTION_CONSTANT_2 = 22719;
- /** This is the variable "R" described in the spec. The spec calls for an unsigned 16-bit integer, but we have no
- * such thing in java, so we use an int instead to handle the extra bit. */
+ /** The encryption key, the variable "R" described in "Adobe Type Type 1 Font Format", section 7.1.
+ * This is an unsigned 16-bit integer. */
private int encryptionKey;
- /** The quantity of randomBytes that should occur at the beginning of the sequence to be processed. This is the
- * variable "n" in the spec. */
+ /** The quantity of random bytes at the beginning of the sequence to be processed, the variable "n" in "Adobe Type
+ * Type 1 Font Format", section 7.1. */
private byte randomBytes;
/** Tracks the number of random bytes that still need to be discarded. The variable is needed in case not enough
@@ -97,7 +96,7 @@
/** The first four bytes must be analyzed in order to figure out whether the input is in ASCII hexadecimal format or
* binary format. */
- private byte[] first4Bytes = new byte[EexecDecodeFilter.EEXEC_INITIAL_BYTES];
+ private byte[] first4Bytes = new byte[EexecDecodeFilter.EEXEC_RANDOM_BYTES];
/** This tracks how much of the first four bytes has actually been accumulated. This is needed because we might not
* get all four bytes in the first chunk. */
@@ -202,13 +201,13 @@
*/
private void resolveFormat(final byte[] input) {
byte inputIndex = 0;
- while (this.first4BytesIndex < EexecDecodeFilter.EEXEC_INITIAL_BYTES
+ while (this.first4BytesIndex < EexecDecodeFilter.EEXEC_RANDOM_BYTES
&& inputIndex < input.length) {
this.first4Bytes[this.first4BytesIndex] = input[inputIndex];
inputIndex ++;
this.first4BytesIndex ++;
}
- if (this.first4BytesIndex < EexecDecodeFilter.EEXEC_INITIAL_BYTES - 1) {
+ if (this.first4BytesIndex < EexecDecodeFilter.EEXEC_RANDOM_BYTES - 1) {
return;
}
/*
@@ -219,7 +218,7 @@
* If we find that, then the file is binary.
* Otherwise it is ASCII hexadecimal.
*/
- for (int i = 0; i < EexecDecodeFilter.EEXEC_INITIAL_BYTES; i++) {
+ for (int i = 0; i < EexecDecodeFilter.EEXEC_RANDOM_BYTES; i++) {
if (! StringUtils.isASCIIHex(this.first4Bytes[i])) {
this.hexFormat = false;
this.formatResolved = true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-30 23:56:37
|
Revision: 13782
http://sourceforge.net/p/foray/code/13782
Author: victormote
Date: 2025-05-30 23:56:33 +0000 (Fri, 30 May 2025)
Log Message:
-----------
Conform to aXSL change: Move CharSet to foray-ps-data.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java
trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1Metrics.java
trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java
trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserPfm.java
trunk/foray/foray-font/src/test/java/org/foray/font/type1/Type1MetricsParserAfmTests.java
trunk/foray/foray-font-tf/src/main/java/org/foray/font/fixture/MockFont.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet4a.java
Added Paths:
-----------
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet.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-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/Font4a.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -31,11 +31,11 @@
import org.foray.font.config.RegisteredFontContent;
import org.foray.font.format.Kerning;
import org.foray.font.format.Panose4a;
+import org.foray.ps.encode.CharSet;
import org.axsl.font.Font;
import org.axsl.font.FontFormat;
import org.axsl.i18n.Script;
-import org.axsl.ps.CharSet;
import org.axsl.unicode.block.U0000_Basic_Latin;
import org.axsl.unicode.block.U0080_Latin_1_Supplement;
import org.axsl.unicode.block.U2000_General_Punctuation;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -37,6 +37,7 @@
import org.foray.primitive.sequence.ByteArray;
import org.foray.primitive.sequence.IntArrayBuilder;
import org.foray.primitive.sequence.ShortArrayBuilder;
+import org.foray.ps.encode.CharSet;
import org.axsl.constants.NumericConstants;
import org.axsl.constants.PrimitiveConstants;
@@ -51,7 +52,6 @@
import org.axsl.primitive.sequence.ByteSequence;
import org.axsl.primitive.sequence.IntSequence;
import org.axsl.primitive.sequence.ShortSequence;
-import org.axsl.ps.CharSet;
import org.axsl.ps.Encoding;
import org.axsl.unicode.block.U0000_Basic_Latin;
import org.axsl.value.FontStretch;
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-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FreeStandingFont.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -31,6 +31,7 @@
import org.foray.font.config.RegisteredFontContent;
import org.foray.font.format.Kerning;
import org.foray.font.format.Panose4a;
+import org.foray.ps.encode.CharSet;
import org.axsl.constants.TypographicConstants;
import org.axsl.font.Font;
@@ -38,7 +39,6 @@
import org.axsl.font.FontFormat;
import org.axsl.primitive.sequence.ShortSequence;
import org.axsl.ps.BoundingBox;
-import org.axsl.ps.CharSet;
import org.axsl.ps.Encoding;
import org.slf4j.Logger;
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-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/SystemFont.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -33,12 +33,12 @@
import org.foray.font.config.RegisteredFontContent;
import org.foray.font.format.Kerning;
import org.foray.font.format.Panose4a;
+import org.foray.ps.encode.CharSet;
import org.axsl.constants.TypographicConstants;
import org.axsl.font.FontException;
import org.axsl.font.FontFormat;
import org.axsl.ps.BoundingBox;
-import org.axsl.ps.CharSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1Metrics.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1Metrics.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1Metrics.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -32,11 +32,11 @@
import org.foray.font.format.Kerning;
import org.foray.font.output.FontPdfUtilities;
import org.foray.primitive.BitUtils;
+import org.foray.ps.encode.CharSet;
import org.axsl.constants.TypographicConstants;
import org.axsl.primitive.sequence.ShortSequence;
import org.axsl.ps.BoundingBox;
-import org.axsl.ps.CharSet;
import org.axsl.ps.EncodingVector;
import java.io.Serializable;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -34,6 +34,7 @@
import org.foray.font.format.Kerning;
import org.foray.primitive.sequence.IntArrayBuilder;
import org.foray.primitive.sequence.ShortArrayBuilder;
+import org.foray.ps.encode.CharSet;
import org.foray.ps.encode.CharSet4a;
import org.foray.ps.encode.EncodingVector4a;
import org.foray.ps.encode.GlyphList;
@@ -41,7 +42,6 @@
import org.axsl.font.FontException;
import org.axsl.ps.BoundingBox;
-import org.axsl.ps.CharSet;
import org.axsl.ps.EncodingVector;
import org.axsl.ps.PsServer;
import org.axsl.value.FontWeight;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserPfm.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserPfm.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserPfm.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -31,11 +31,11 @@
import org.foray.common.RandomAccessInput;
import org.foray.font.format.Kerning;
import org.foray.primitive.sequence.ShortArrayBuilder;
+import org.foray.ps.encode.CharSet;
import org.foray.ps.encode.CharSet4a;
import org.foray.ps.encode.EncodingVector4a;
import org.axsl.constants.PrimitiveConstants;
-import org.axsl.ps.CharSet;
import org.axsl.ps.EncodingVector;
import java.io.IOException;
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/type1/Type1MetricsParserAfmTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/type1/Type1MetricsParserAfmTests.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/type1/Type1MetricsParserAfmTests.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -31,9 +31,9 @@
import org.foray.common.sequence.ByteSequenceParser;
import org.foray.font.FontServer4a;
import org.foray.font.FontServer4aTests;
+import org.foray.ps.encode.CharSet;
import org.axsl.font.FontException;
-import org.axsl.ps.CharSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Modified: trunk/foray/foray-font-tf/src/main/java/org/foray/font/fixture/MockFont.java
===================================================================
--- trunk/foray/foray-font-tf/src/main/java/org/foray/font/fixture/MockFont.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-font-tf/src/main/java/org/foray/font/fixture/MockFont.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -28,11 +28,12 @@
package org.foray.font.fixture;
+import org.foray.ps.encode.CharSet;
+
import org.axsl.font.Font;
import org.axsl.font.FontFormat;
import org.axsl.i18n.Script;
import org.axsl.ps.BoundingBox;
-import org.axsl.ps.CharSet;
import org.axsl.ps.Encoding;
import org.axsl.value.BaselineIdentifier;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -29,6 +29,7 @@
package org.foray.ps;
import org.foray.primitive.sequence.IntArrayBuilder;
+import org.foray.ps.encode.CharSet;
import org.foray.ps.encode.CharSet4a;
import org.foray.ps.encode.CharSetParser;
import org.foray.ps.java2d.Java2dSystemDict;
@@ -35,7 +36,6 @@
import org.foray.ps.pdf.PdfSystemDict;
import org.foray.ps.readonly.ReadOnlySystemDict;
-import org.axsl.ps.CharSet;
import org.axsl.ps.PsException;
import org.axsl.ps.PsServer;
Added: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet.java (rev 0)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2009 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.ps.encode;
+
+/**
+ * <p>A CharSet is a collection of related characters.
+ * Fonts are frequently designed to cover a specific collection of characters.
+ * For example, 12 of the Base-14 fonts cover the ExtendedRoman collection.</p>
+ *
+ * <p>The main purpose of the CharSet interface is to efficiently map a Unicode code point to an array index that can be
+ * used in some other place to store information about that code point.
+ * For example, as an Adobe Font Metrics (AFM) file is parsed, width metric information is accumulated about each glyph
+ * in the font.
+ * Those widths are most efficiently stored in an array, but some means for getting the index to that array is needed.
+ * The font Encoding is not a suitable concept to use as an index for such information, because it is limited to 256
+ * characters and, as a matter of practice, most Encodings use less than that.
+ * A font may contain more than 256 glyphs.
+ * For example, the ExtendedRoman character set contains 315 glyphs.
+ * By separating CharSet from Encoding, we can record all of the information about a font without caring how it will be
+ * encoded as it is used.</p>
+ */
+public interface CharSet {
+
+ /**
+ * Enumeration of predefined character sets.
+ */
+ enum Predefined {
+
+ /** The "Windows ANSI" character set, also known as Windows Code Page 1252. Its members are the same as those
+ * encoded in {@link PsEncoding.Predefined#WIN_ANSI}. */
+ WINDOWS_ANSI("WindowsANSI"),
+
+ /** The "Extended Roman" character set. There does not seem to be an official list for this character set, but
+ * it can be inferred from the AFM files for the PDF Base-14 Roman fonts. */
+ EXTENDED_ROMAN("ExtendedRoman");
+
+ /** The name of the character set. */
+ private String name;
+
+ /**
+ * Private Constructor.
+ * @param name The name of the character set.
+ */
+ Predefined(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the name of the character set.
+ * @return The name of the character set.
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * Finds the instance that matches a given name.
+ * @param name The name of the predefined character set to find.
+ * @return The predefined character set matching {@code name}, or null if no such character set exists.
+ */
+ public static Predefined findByName(final String name) {
+ for (int i = 0; i < CharSet.Predefined.values().length; i++) {
+ final Predefined charSet = CharSet.Predefined.values()[i];
+ if (charSet.getName().equals(name)) {
+ return charSet;
+ }
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Returns the array index for a Unicode code point in this character set.
+ * @param codePoint The Unicode code point whose index should be found.
+ * @return The index for {@code codePoint}, or -1 if it is not in the character set.
+ */
+ int getIndex(int codePoint);
+
+ /**
+ * Returns the number of elements (Unicode code points) in this character set.
+ * @return The number of elements in this character set.
+ */
+ int size();
+
+}
Property changes on: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet4a.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet4a.java 2025-05-30 22:36:09 UTC (rev 13781)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSet4a.java 2025-05-30 23:56:33 UTC (rev 13782)
@@ -34,7 +34,6 @@
import org.axsl.primitive.sequence.IntSequence;
import org.axsl.primitive.sequence.IntSequenceMutable;
-import org.axsl.ps.CharSet;
import java.io.IOException;
import java.io.ObjectInputStream;
@@ -46,7 +45,7 @@
/**
* The FOray implementation of {@link org.axsl.ps.CharSet}.
*/
-public class CharSet4a implements org.axsl.ps.CharSet, Serializable {
+public class CharSet4a implements CharSet, Serializable {
/** Constant needed for serialization. */
public static final long serialVersionUID = -194139196582956914L;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-30 22:36:17
|
Revision: 13781
http://sourceforge.net/p/foray/code/13781
Author: victormote
Date: 2025-05-30 22:36:09 +0000 (Fri, 30 May 2025)
Log Message:
-----------
Conform to aXSL change: Move GlyphList interface to foray-ps-data.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSetParser.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingCustom.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingParser.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingVector4a.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList4a.java
Added Paths:
-----------
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/config/FontConfigParser.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -33,6 +33,7 @@
import org.foray.font.FontServer4a;
import org.foray.primitive.StringUtils;
import org.foray.ps.encode.EncodingVector4a;
+import org.foray.ps.encode.GlyphList;
import org.foray.ps.encode.GlyphList4a;
import org.foray.ps.encode.GlyphListParser;
import org.foray.xml.SaxLocation;
@@ -41,7 +42,6 @@
import org.axsl.font.Font;
import org.axsl.font.FontException;
import org.axsl.ps.EncodingVector;
-import org.axsl.ps.GlyphList;
import org.axsl.ps.PsException;
import org.axsl.value.FontStretch;
import org.axsl.value.FontStyle;
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/type1/Type1MetricsParserAfm.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -36,6 +36,7 @@
import org.foray.primitive.sequence.ShortArrayBuilder;
import org.foray.ps.encode.CharSet4a;
import org.foray.ps.encode.EncodingVector4a;
+import org.foray.ps.encode.GlyphList;
import org.foray.ps.encode.GlyphList4a;
import org.axsl.font.FontException;
@@ -42,7 +43,6 @@
import org.axsl.ps.BoundingBox;
import org.axsl.ps.CharSet;
import org.axsl.ps.EncodingVector;
-import org.axsl.ps.GlyphList;
import org.axsl.ps.PsServer;
import org.axsl.value.FontWeight;
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSetParser.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSetParser.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/CharSetParser.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -32,7 +32,6 @@
import org.foray.primitive.StringUtils;
import org.foray.primitive.sequence.CharArrayBuilder;
-import org.axsl.ps.GlyphList;
import org.axsl.ps.PsException;
import org.slf4j.Logger;
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingCustom.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingCustom.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingCustom.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -31,7 +31,6 @@
import org.axsl.primitive.sequence.IntSequence;
import org.axsl.ps.EncodingVector;
-import org.axsl.ps.GlyphList;
import java.util.List;
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingParser.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingParser.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingParser.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -36,7 +36,6 @@
import org.axsl.constants.PrimitiveConstants;
import org.axsl.primitive.sequence.CharSequenceMutable;
import org.axsl.primitive.sequence.IntSequenceMutable;
-import org.axsl.ps.GlyphList;
import org.axsl.ps.PsException;
import org.slf4j.Logger;
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingVector4a.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingVector4a.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingVector4a.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -36,7 +36,6 @@
import org.axsl.primitive.sequence.IntSequence;
import org.axsl.primitive.sequence.IntSequenceMutable;
import org.axsl.ps.EncodingVector;
-import org.axsl.ps.GlyphList;
import org.axsl.ps.PsException;
import java.io.IOException;
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -32,7 +32,6 @@
import org.foray.primitive.sequence.IntArray;
import org.axsl.ps.EncodingVector;
-import org.axsl.ps.GlyphList;
import java.io.Serializable;
import java.util.ArrayList;
Added: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList.java (rev 0)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.ps.encode;
+
+/**
+ * Maps glyph names to Unicode code points.
+ * Such a mapping is needed because Type 1 fonts are keyed by names, and these names must be mapped to their
+ * corresponding code points before an {@link EncodingVector} can be built.
+ */
+public interface GlyphList {
+
+ /**
+ * Enumeration of the predefined glphy lists.
+ */
+ enum Predefined {
+ /**
+ * The Adobe Glyph List, the standard glyph list used in most Type 1 fonts.
+ * See http://partners.adobe.com/asn/tech/type/glyphlist.txt for the list, and see
+ * http://partners.adobe.com/asn/tech/type/unicodegn.jsp for the background.
+ */
+ AGL,
+
+ /** The special glyph list used for dingbat fonts. */
+ ZAPF_DINGBATS;
+ }
+
+ /**
+ * Finds the Unicode code point which corresponds to a given glyph name.
+ * @param glyphName The glyph name for which a code point is sought.
+ * @return The Unicode code point which corresponds to {@code glyphName}, or -1 if there is none.
+ */
+ int mapGlyphNameToCodePoint(String glyphName);
+
+ /**
+ * Finds the glyph name for a given Unicode code point.
+ * @param codePoint The Unicode code point for which a glyph name is sought.
+ * @return The glyph name which corresponds to {@code codePoint}, or null if there is none.
+ */
+ String mapCodePointToGlyphName(int codePoint);
+
+}
Property changes on: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList4a.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList4a.java 2025-05-30 16:44:41 UTC (rev 13780)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/encode/GlyphList4a.java 2025-05-30 22:36:09 UTC (rev 13781)
@@ -28,8 +28,6 @@
package org.foray.ps.encode;
-import org.axsl.ps.GlyphList;
-
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-30 16:44:44
|
Revision: 13780
http://sourceforge.net/p/foray/code/13780
Author: victormote
Date: 2025-05-30 16:44:41 +0000 (Fri, 30 May 2025)
Log Message:
-----------
Conform to aXSL change: Remove PsEncodeFilter. If filters are needed, they can be obtained directly from foray-ps-data.
Modified Paths:
--------------
trunk/foray/foray-pdf/build.gradle
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXobject4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/PsEncodeFilter4a.java
Modified: trunk/foray/foray-pdf/build.gradle
===================================================================
--- trunk/foray/foray-pdf/build.gradle 2025-05-30 14:52:16 UTC (rev 13779)
+++ trunk/foray/foray-pdf/build.gradle 2025-05-30 16:44:41 UTC (rev 13780)
@@ -25,6 +25,7 @@
implementation (project(":foray-ps-data"))
testImplementation (project(':foray-font'))
+ testImplementation (project(':foray-ps'))
}
javadoc {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXobject4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXobject4a.java 2025-05-30 14:52:16 UTC (rev 13779)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXobject4a.java 2025-05-30 16:44:41 UTC (rev 13780)
@@ -36,6 +36,7 @@
import org.foray.pdf.document.PdfDocument4a;
import org.foray.pdf.type.PdfStream;
+import org.foray.ps.filter.PsEncodeFilter4a;
import org.foray.ps.filter.PsFilter;
import org.axsl.font.FontConsumer;
@@ -49,7 +50,6 @@
import org.axsl.orthography.Orthography;
import org.axsl.pdf.PdfException;
import org.axsl.pdf.PdfXobject;
-import org.axsl.ps.PsEncodeFilter;
import java.io.OutputStream;
@@ -71,7 +71,7 @@
private int xNumber;
/** The PSFilter, if any, that should be applied to this XObject. */
- private PsEncodeFilter filter;
+ private PsEncodeFilter4a filter;
/**
* Create an Xobject instance.
@@ -163,8 +163,8 @@
* @return An appropriate compression filter, or null if no compression should be used.
* @throws GraphicException For error reading Graphic file.
*/
- private PsEncodeFilter getFilter(final OutputStream outputStream) throws GraphicException {
- PsEncodeFilter filter = null;
+ private PsEncodeFilter4a getFilter(final OutputStream outputStream) throws GraphicException {
+ PsEncodeFilter4a filter = null;
final Graphic graphic = this.getGraphic();
if (graphic.getFormat() == GraphicFormat.JPEG) {
filter = PsFilter.DCT.makeEncodeFilter(outputStream, false);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java 2025-05-30 14:52:16 UTC (rev 13779)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java 2025-05-30 16:44:41 UTC (rev 13780)
@@ -30,12 +30,12 @@
import org.foray.pdf.document.PdfDocument4a;
import org.foray.pdf.encrypt.PdfEncryption4a;
+import org.foray.ps.filter.PsEncodeFilter4a;
import org.foray.ps.filter.PsFilter;
import org.axsl.pdf.PdfException;
import org.axsl.primitive.sequence.ByteSequence;
import org.axsl.primitive.sequence.ByteSequencePlus;
-import org.axsl.ps.PsEncodeFilter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -60,7 +60,7 @@
/** The LIFO (last-in, first-out) list of filters that should be applied to
* this stream. */
- private List<PsEncodeFilter> filters = new ArrayList<PsEncodeFilter>();
+ private List<PsEncodeFilter4a> filters = new ArrayList<PsEncodeFilter4a>();
/** The furthest upstream output stream, that is, the stream to which this
* should write when it has content to be written. */
@@ -146,7 +146,7 @@
* @param filter The filter to be added.
* @throws PdfException For errors adding the filter.
*/
- public void addFilter(final PsEncodeFilter filter) throws PdfException {
+ public void addFilter(final PsEncodeFilter4a filter) throws PdfException {
/* TODO: This method is similar to addFilter(String, PdfDocument4a). We need to either clean that up or
* document why both are needed. */
if (filter == null) {
@@ -179,7 +179,7 @@
* @return The newly-created filter.
* @throws PdfException For errors while adding the filter.
*/
- public PsEncodeFilter addFilter(final String filterType) throws PdfException {
+ public PsEncodeFilter4a addFilter(final String filterType) throws PdfException {
if (filterType == null
|| "".equals(filterType)) {
return null;
@@ -189,7 +189,7 @@
+ "content has been written to the stream.");
}
final PsFilter filter = PsFilter.findFilter(filterType);
- final PsEncodeFilter encodeFilter = filter.makeEncodeFilter(this.out, false);
+ final PsEncodeFilter4a encodeFilter = filter.makeEncodeFilter(this.out, false);
if (encodeFilter != null) {
this.out = encodeFilter;
this.filters.add(encodeFilter);
@@ -327,7 +327,7 @@
/* Mark the filters as applied. */
for (int i = 0; i < this.filters.size(); i++) {
- final PsEncodeFilter filter = this.filters.get(i);
+ final PsEncodeFilter4a filter = this.filters.get(i);
// place the names in our local List in reverse order
names.add(0, filter.getDecodeName());
parms.add(0, filter.getDecodeParms());
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java 2025-05-30 14:52:16 UTC (rev 13779)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java 2025-05-30 16:44:41 UTC (rev 13780)
@@ -42,6 +42,7 @@
import org.foray.pdf.serial.PdfSerializationConfig4a;
import org.foray.primitive.sequence.ByteArray;
import org.foray.primitive.sequence.ByteArrayBuilder;
+import org.foray.ps.PsServer4a;
import org.foray.ps.encode.EncodingStandard;
import org.axsl.font.FontContext;
@@ -94,7 +95,8 @@
final PdfContentStream4a contentStream = page.getContentStream();
/* TODO: This is too painful for just wanting to use a Base-14 font. */
- final FontServer4a fontServer = new FontServer4a();
+ final PsServer4a psServer = new PsServer4a();
+ final FontServer4a fontServer = new FontServer4a(psServer);
final FontConsumer4a fontConsumer = fontServer.createFontConsumer(null);
final RegisteredFontContent rf = fontServer.getRegisteredFont("Base14-Helvetica");
final RegisteredFontFamily rff = fontServer.getRegisteredFontFamily("Base14-Helvetica");
Modified: trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/PsEncodeFilter4a.java
===================================================================
--- trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/PsEncodeFilter4a.java 2025-05-30 14:52:16 UTC (rev 13779)
+++ trunk/foray/foray-ps-data/src/main/java/org/foray/ps/filter/PsEncodeFilter4a.java 2025-05-30 16:44:41 UTC (rev 13780)
@@ -28,9 +28,10 @@
package org.foray.ps.filter;
-import org.axsl.ps.PsEncodeFilter;
+import org.axsl.ps.PsFilterType;
import java.io.ByteArrayOutputStream;
+import java.io.FilterOutputStream;
import java.io.OutputStream;
/**
@@ -37,7 +38,7 @@
* Superclass for PostScript encode filters.
* @see "PostScript Language Reference, Third Edition, Section 3.8.4."
*/
-public abstract class PsEncodeFilter4a extends PsEncodeFilter {
+public abstract class PsEncodeFilter4a extends FilterOutputStream {
/** Tracks whether this filter has already been applied to the data. */
private boolean applied = false;
@@ -67,13 +68,29 @@
return this.applied;
}
- @Override
+ /**
+ * Return a PostScript name representation of the filter, e.g. /FlateEncode.
+ * @return A PostScript name representation of the filter.
+ */
public abstract String getName();
- @Override
+ /**
+ * Return the PostScript name of the filter that should be used to decode content encoded by this filter.
+ * For example, if this filter is "/FlateEncode", this method should return "/FlateDecode".
+ * @return The name of the decode filter.
+ */
public abstract String getDecodeName();
- @Override
+ /**
+ * Sets the decode parameters for this filter.
+ * @param decodeParms The new decode parameters.
+ */
+ public abstract void setDecodeParms(String decodeParms);
+
+ /**
+ * Return a parameter dictionary for this filter, or null if there is none.
+ * @return The parameter dictionary for this filter.
+ */
public abstract String getDecodeParms();
/**
@@ -86,9 +103,22 @@
}
}
- @Override
+ /**
+ * Sets this filter to a state where it acts as a null filter, simply passing the data through as received.
+ * This is useful in cases where the filter needs to exist as a marker, but should not be applied.
+ * One example is the case where the raw data has already been filtered, but the filter needs to be created anyway
+ * to signal to something downstream that it needs to be unfiltered.
+ */
public void setInactive() {
this.applied = true;
}
+ /**
+ * Sets the length of the output line that should be written during encoding.
+ * This only applies to some filter types, such as that for {@link PsFilterType#ASCII_HEX}, and will be ignored by
+ * other filter types.
+ * @param lineLength The length, in ASCII characters, of the filter output lines.
+ */
+ public abstract void setLineLength(int lineLength);
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2025-05-30 14:52:20
|
Revision: 13779
http://sourceforge.net/p/foray/code/13779
Author: victormote
Date: 2025-05-30 14:52:16 +0000 (Fri, 30 May 2025)
Log Message:
-----------
Remove normal access to foray-ps in foray-font, allowing access only in test classes.
Modified Paths:
--------------
trunk/foray/foray-font/build.gradle
Modified: trunk/foray/foray-font/build.gradle
===================================================================
--- trunk/foray/foray-font/build.gradle 2025-05-30 14:29:23 UTC (rev 13778)
+++ trunk/foray/foray-font/build.gradle 2025-05-30 14:52:16 UTC (rev 13779)
@@ -25,9 +25,7 @@
api (project(':foray-ps-data'))
api (project(':foray-font-parse'))
-// TODO: FIX THIS!
-// testRuntimeOnly (project(':foray-ps'))
- api (project(':foray-ps'))
+ testRuntimeOnly (project(':foray-ps'))
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|