foray-commit Mailing List for FOray (Page 83)
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
(4) |
Dec
|
|
From: <vic...@us...> - 2021-01-18 11:10:06
|
Revision: 11819
http://sourceforge.net/p/foray/code/11819
Author: victormote
Date: 2021-01-18 11:09:59 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Add CatalogManager.properties file.
Modified Paths:
--------------
trunk/foray/foray-common/src/test/resources/logback-test.xml
Added Paths:
-----------
trunk/foray/foray-common/src/main/resources/CatalogManager.properties
Added: trunk/foray/foray-common/src/main/resources/CatalogManager.properties
===================================================================
Modified: trunk/foray/foray-common/src/test/resources/logback-test.xml
===================================================================
--- trunk/foray/foray-common/src/test/resources/logback-test.xml 2021-01-18 10:51:38 UTC (rev 11818)
+++ trunk/foray/foray-common/src/test/resources/logback-test.xml 2021-01-18 11:09:59 UTC (rev 11819)
@@ -8,7 +8,7 @@
</encoder>
</appender>
- <root level="debug">
+ <root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 10:51:41
|
Revision: 11818
http://sourceforge.net/p/foray/code/11818
Author: victormote
Date: 2021-01-18 10:51:38 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Adjust logging levels.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-01-18 01:10:29 UTC (rev 11817)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontServer4a.java 2021-01-18 10:51:38 UTC (rev 11818)
@@ -300,7 +300,7 @@
return;
}
/* Otherwise warn the client that the change has been ignored */
- getLogger().info("Tried to reset baseURL. Ignoring.");
+ getLogger().warn("Tried to reset baseURL. Ignoring.");
}
/**
@@ -326,7 +326,7 @@
return;
}
/* Otherwise warn the client that the change has been ignored */
- getLogger().info("Tried to reset baseFontURL. Ignoring.");
+ getLogger().warn("Tried to reset baseFontURL. Ignoring.");
}
/**
@@ -378,12 +378,10 @@
final List<Font> list = this.getSystemFontList();
for (int i = 0; i < list.size(); i++) {
final Font font = list.get(i);
- this.logger.info("System Font: " + font.getName());
- this.logger.info(" Attributes:");
- for (Entry<TextAttribute, ?> entry
- : font.getAttributes().entrySet()) {
- this.logger.info(" Key: " + entry.getKey() + " Value: "
- + entry.getValue());
+ this.logger.debug("System Font: " + font.getName());
+ this.logger.debug(" Attributes:");
+ for (Entry<TextAttribute, ?> entry : font.getAttributes().entrySet()) {
+ this.logger.debug(" Key: " + entry.getKey() + " Value: " + entry.getValue());
}
}
}
@@ -719,8 +717,7 @@
}
this.systemFontFamilyListCreated = true;
if (! Environment.isGraphicalEnvironment()) {
- getLogger().debug("No graphical environment. "
- + "Unable to get System fonts.");
+ getLogger().info("No graphical environment. Unable to get System fonts.");
return;
}
final GraphicsEnvironment ge
@@ -797,8 +794,7 @@
public void setUsingFreeStandingFonts(final boolean using) {
if (this.setupCompleted) {
if (using != this.usingFreeStandingFonts) {
- getLogger().error("Font setup already completed. " +
- "Ignoring setUsingFreeStandingFonts().");
+ getLogger().error("Font setup already completed. Ignoring setUsingFreeStandingFonts().");
}
return;
}
@@ -815,8 +811,7 @@
public void setUsingSystemFonts(final boolean using) {
if (this.setupCompleted) {
if (using != this.usingSystemFonts) {
- getLogger().error("Font setup already completed. " +
- "Ignoring setUsingFreeStandingFonts().");
+ getLogger().error("Font setup already completed. Ignoring setUsingSystemFonts().");
}
return;
}
@@ -846,12 +841,10 @@
@Override
public List<java.awt.Font> getSystemFontList() {
if (! Environment.isGraphicalEnvironment()) {
- getLogger().debug("No graphical environment. "
- + "Unable to get System fonts.");
+ getLogger().info("No graphical environment. Unable to get System fonts.");
return null;
}
- final GraphicsEnvironment ge
- = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
return Arrays.asList(ge.getAllFonts());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-18 01:10:31
|
Revision: 11817
http://sourceforge.net/p/foray/code/11817
Author: victormote
Date: 2021-01-18 01:10:29 +0000 (Mon, 18 Jan 2021)
Log Message:
-----------
Upgrade JEuclid to 3.1.14.
Modified Paths:
--------------
trunk/foray/foray-graphic/build.gradle
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/factory/MathFactory.java
trunk/foray/master/build.gradle
Modified: trunk/foray/foray-graphic/build.gradle
===================================================================
--- trunk/foray/foray-graphic/build.gradle 2021-01-17 23:01:33 UTC (rev 11816)
+++ trunk/foray/foray-graphic/build.gradle 2021-01-18 01:10:29 UTC (rev 11817)
@@ -17,7 +17,8 @@
api group: 'org.apache.xmlgraphics', name: 'batik-awt-util', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-ext', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-svggen', version: batikVersion
- api group: 'net.sourceforge.jeuclid', name: 'jeuclid-core', version: jeuclidVersion
+// api group: 'net.sourceforge.jeuclid', name: 'jeuclid-core', version: jeuclidVersion
+ api group: 'de.rototor.jeuclid', name: 'jeuclid-core', version: jeuclidVersion
api group: 'org.axsl', name: 'axsl-graphic', version: axslVersion
api group: 'org.axsl', name: 'axsl-pdf', version: axslVersion
api project(':foray-common')
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java 2021-01-17 23:01:33 UTC (rev 11816)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java 2021-01-18 01:10:29 UTC (rev 11817)
@@ -54,8 +54,6 @@
import org.axsl.graphic.output.GraphicOutput;
import org.apache.batik.anim.dom.SVGDOMImplementation;
-import org.apache.batik.svggen.SVGGeneratorContext;
-import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
@@ -68,7 +66,6 @@
import org.w3c.dom.mathml.MathMLDocument;
import org.w3c.dom.svg.SVGDocument;
-import java.awt.Dimension;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -83,8 +80,10 @@
import javax.xml.parsers.ParserConfigurationException;
-import net.sourceforge.jeuclid.DOMBuilder;
-import net.sourceforge.jeuclid.MathBase;
+import net.sourceforge.jeuclid.LayoutContext;
+import net.sourceforge.jeuclid.context.LayoutContextImpl;
+import net.sourceforge.jeuclid.converter.Converter;
+import net.sourceforge.jeuclid.converter.ConverterPlugin.DocumentWithDimension;
/**
* create Graphic objects (with a configuration file - not yet implemented).
@@ -432,104 +431,10 @@
+ "MathML document, but was: " + rootElementName);
}
- /*
- * The pro-forma changes for upgrading to JEuclid 3.1.9 are as follows:
- * 1. Change the ext.jeuclidVersion variable in the master build.gradle to '3.1.9'.
- * 2. Uncomment the following section of code.
- * 3. Remove the remainder of the code in this method.
- * 4. Remove the method below this one, having the signature: SVGGraphics2D createSVGGenerator(MathBase).
- *
- * This looks like it /ought/ to work, and in fact compiles cleanly. However, at runtime, when testing MathML
- * documents, it results in the following:
- *
- * Exception in thread "main" java.lang.AbstractMethodError:
- * net.sourceforge.jeuclid.elements.presentation.token.Mo.getTextContent()Ljava/lang/String;
- * at net.sourceforge.jeuclid.elements.support.text.TextContent.getText(TextContent.java:44)
- * at net.sourceforge.jeuclid.elements.AbstractJEuclidElement.getText(AbstractJEuclidElement.java:413)
- * ...
- * at net.sourceforge.jeuclid.converter.BatikConverter.convert(BatikConverter.java:93)
- * at net.sourceforge.jeuclid.converter.Converter.convert(Converter.java:214)
- * at org.foray.graphic.GraphicServer4a.domToSvgDom(GraphicServer4a.java:436)
- * ...
- *
- * This is an unusual exception, basically meaning that something unexpected happened between compile time and
- * runtime. It may also be possible that there is some incompatibility between Java versions of code included
- * in the JEuclid distribution, and/or the FOray dependencies.
- *
- * In any case, this appears to be unsolvable without building JEuclid ourselves, which does not currently
- * (January 13, 2021) appear to be worth the effort.
- */
-
-
- /* Pro-forma JEuclid 3.1.9 code. See above. */
- /*
final Converter converter = Converter.getInstance();
final LayoutContext layoutContext = LayoutContextImpl.getDefaultLayoutContext();
final DocumentWithDimension dwd = converter.convert(dom, Converter.TYPE_SVG, layoutContext);
return (SVGDocument) dwd.getDocument();
- */
-
-
- final MathBase mathBase = new MathBase(MathBase.getDefaultParameters());
- new DOMBuilder(dom, mathBase);
- final SVGGraphics2D svgGenerator = this.createSVGGenerator(mathBase);
- mathBase.paint(svgGenerator);
-
- /* The following line is what /should/ work. However, there appears to
- * be some disconnect in Batik between the Document and the root
- * Element. The root Element recognizes the Document as its Document,
- * but the Document does not see the root Element as its root Element
- * ... */
-// final Document svgDocument = svgGenerator.getDOMFactory();
-
- final Element svgRoot = svgGenerator.getRoot();
-
- /* The variable svgDocument below is the same object as the one
- * commented out above ... */
- final Document svgDocument = svgRoot.getOwnerDocument();
- if (svgDocument == null) {
- throw new GraphicException("Error converting MathML to SVG: "
- + "Document is null.");
- }
-
- /* ... however, the root element below is /NOT/ the same as the svgRoot
- * variable above ... */
- final Element svgRoot2 = svgDocument.getDocumentElement();
-
- /* ... so we need to get the Document and the root element hooked up. */
- svgDocument.removeChild(svgRoot2);
- svgDocument.appendChild(svgRoot);
-
- if (! (svgDocument instanceof SVGDocument)) {
- throw new GraphicException("Error converting MathML to SVG: "
- + "Converted document is not SVG.");
- }
- return (SVGDocument) svgDocument;
}
- /**
- * Create a Batik SVG Generator for a given MathBase instance.
- * NOTE: This method was copied verbatim from
- * net.sourceforge.jeuclid.app.foprep.Processor#createSVGGenerator(MathBase)
- * which is a private method, then modified to start with an SVGDocument
- * instead of generic DOM Document.
- * @param mathBase The JEuclid MathML document to be converted.
- * @return The Batik SVG Generator.
- * @throws GraphicException For error obtaining a new SVGDocument instance.
- */
- private SVGGraphics2D createSVGGenerator(final MathBase mathBase)
- throws GraphicException {
- final SVGDocument svgDocument = this.makeSvgDocument();
- final SVGGeneratorContext svgContext = SVGGeneratorContext
- .createDefault(svgDocument);
- svgContext.setComment("Converted from MathML using JEuclid");
- final SVGGraphics2D svgGenerator = new SVGGraphics2D(svgContext, true);
-
- final Dimension size = new Dimension((int) Math.ceil(mathBase
- .getWidth(svgGenerator)), (int) Math.ceil(mathBase
- .getHeight(svgGenerator)));
- svgGenerator.setSVGCanvasSize(size);
- return svgGenerator;
- }
-
}
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/factory/MathFactory.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/factory/MathFactory.java 2021-01-17 23:01:33 UTC (rev 11816)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/factory/MathFactory.java 2021-01-18 01:10:29 UTC (rev 11817)
@@ -101,7 +101,8 @@
*/
public static InputStream getMathMLDtdAsInputStream(final String fileName) {
/* We expect to find the MathML DTD in the JEuclid jar file at "mathml.2.0/mathml2.dtd". */
- final InputStream theStream = MathMlUtil.class.getResourceAsStream("/mathml.2.0/" + fileName);
+ final InputStream theStream =
+ MathMlUtil.class.getResourceAsStream("/net/sourceforge/jeuclid/mathml.2.0/" + fileName);
return theStream;
}
Modified: trunk/foray/master/build.gradle
===================================================================
--- trunk/foray/master/build.gradle 2021-01-17 23:01:33 UTC (rev 11816)
+++ trunk/foray/master/build.gradle 2021-01-18 01:10:29 UTC (rev 11817)
@@ -43,7 +43,7 @@
ext.servletApiVersion = '3.1.0' // Latest is 4.0.1 as of 2021-01-12. See Note 6.
ext.xmlgraphicsCommonsVersion = '2.4' // Latest is 2.4 as of 2021-01-12.
ext.batikVersion = '1.13' // Latest is 1.13 as of 2021-01-12.
- ext.jeuclidVersion = '3.0.3' // Latest is 3.1.9 as of 2021-01-12. See Note 7.
+ ext.jeuclidVersion = '3.1.14' // Latest is 3.1.14 as of 2021-01-12. See Note 7.
ext.icu4jVersion = '68.2' // Latest is 68.2 as of 2021-01-12.
ext.junitVersion = '4.13.1' // Latest is 5.7.0 as of 2021-01-12. See Note 8.
@@ -76,14 +76,9 @@
* to build with Java 1.7.
* We have therefore stayed with the highest version of 3.x, which is 3.1.0.
*
- * 7. JEuclid 3.1.9 will require handling some API changes.
- * Making those API changes results in runtime problems, which are documented, along with the pro-forma necessary
- * code changes, here:
- * project: foray-graphic
- * class: org.foray.graphic.GraphicServer4a
- * method: org.w3c.dom.svg.SVGDocument domToSvgDom(org.w3c.dom.Document)
- * JEuclid does not appear to be supported any longer, and I don't see any other MathML solutions with the right
- * licensing. Therefore we will leave this dependency at 3.0.3 for now.
+ * 7. JEuclid has moved from group net.sourceforge.jeuclid to de.rototor.jeuclid, but continues to use the name
+ * "jeuclid-core" and the same general release numbering sequence.
+ * The latest version for group net.sourceforge.jeuclid as of 2021-01-12 is 3.1.9 per www.mvnrepository.com.
*
* 8. JUnit is compiled with Java 8 (major version 52) starting with release 5.0.0.
* We have therefore stayed with the highest version supporting Java 7, which is 4.13.1.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 23:01:36
|
Revision: 11816
http://sourceforge.net/p/foray/code/11816
Author: victormote
Date: 2021-01-17 23:01:33 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Remove no-longer needed dependency on Xerces.
Modified Paths:
--------------
trunk/foray/foray-graphic/build.gradle
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/math/MathMlDocument4a.java
trunk/foray/master/build.gradle
Modified: trunk/foray/foray-graphic/build.gradle
===================================================================
--- trunk/foray/foray-graphic/build.gradle 2021-01-17 22:51:43 UTC (rev 11815)
+++ trunk/foray/foray-graphic/build.gradle 2021-01-17 23:01:33 UTC (rev 11816)
@@ -3,7 +3,6 @@
dependencies {
api group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
api group: 'commons-io', name: 'commons-io', version: commonsIoVersion
- api group: 'xerces', name: 'xercesImpl', version: xercesVersion
api group: 'org.apache.xmlgraphics', name: 'xmlgraphics-commons', version: xmlgraphicsCommonsVersion
api group: 'org.apache.xmlgraphics', name: 'batik-bridge', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-gvt', version: batikVersion
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/math/MathMlDocument4a.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/math/MathMlDocument4a.java 2021-01-17 22:51:43 UTC (rev 11815)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/math/MathMlDocument4a.java 2021-01-17 23:01:33 UTC (rev 11816)
@@ -30,7 +30,7 @@
import org.foray.common.MathMlUtil;
-import org.apache.xerces.dom.DocumentImpl;
+import org.apache.batik.dom.GenericDocument;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
@@ -43,7 +43,7 @@
/**
* An implementation of the DOM MathMLDocument interface.
*/
-public final class MathMlDocument4a extends DocumentImpl implements MathMLDocument {
+public final class MathMlDocument4a extends GenericDocument implements MathMLDocument {
/** Constant needed for serialization. */
private static final long serialVersionUID = -2103887514402824538L;
@@ -75,10 +75,8 @@
* See {@link #getReferrer()}.
* See {@link #makeDocumentType()}.
*/
- private MathMlDocument4a(final DocumentType documentType,
- final String referrer, final String domain, final String uri) {
- super(documentType);
-// super(new MathBase(new HashMap<ParameterKey, String>()));
+ private MathMlDocument4a(final DocumentType documentType, final String referrer, final String domain,
+ final String uri) {
this.referrer = referrer;
this.domain = domain;
this.uri = uri;
Modified: trunk/foray/master/build.gradle
===================================================================
--- trunk/foray/master/build.gradle 2021-01-17 22:51:43 UTC (rev 11815)
+++ trunk/foray/master/build.gradle 2021-01-17 23:01:33 UTC (rev 11816)
@@ -41,7 +41,6 @@
ext.xmlResolverVersion = '1.2' // Latest is 1.2 as of 2021-01-12. See Note 4.
ext.antVersion = '1.9.15' // Latest is 1.10.9 as of 2021-01-12. See Note 5.
ext.servletApiVersion = '3.1.0' // Latest is 4.0.1 as of 2021-01-12. See Note 6.
- ext.xercesVersion = '2.12.1' // Latest is 2.12.1 as of 2021-01-12.
ext.xmlgraphicsCommonsVersion = '2.4' // Latest is 2.4 as of 2021-01-12.
ext.batikVersion = '1.13' // Latest is 1.13 as of 2021-01-12.
ext.jeuclidVersion = '3.0.3' // Latest is 3.1.9 as of 2021-01-12. See Note 7.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 22:51:45
|
Revision: 11815
http://sourceforge.net/p/foray/code/11815
Author: victormote
Date: 2021-01-17 22:51:43 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Remove once-again no-longer-needed dependency on Xalan.
Modified Paths:
--------------
trunk/foray/foray-graphic/build.gradle
trunk/foray/master/build.gradle
Modified: trunk/foray/foray-graphic/build.gradle
===================================================================
--- trunk/foray/foray-graphic/build.gradle 2021-01-17 22:45:44 UTC (rev 11814)
+++ trunk/foray/foray-graphic/build.gradle 2021-01-17 22:51:43 UTC (rev 11815)
@@ -4,7 +4,6 @@
api group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
api group: 'commons-io', name: 'commons-io', version: commonsIoVersion
api group: 'xerces', name: 'xercesImpl', version: xercesVersion
- api group: 'xalan', name: 'xalan', version: xalanVersion
api group: 'org.apache.xmlgraphics', name: 'xmlgraphics-commons', version: xmlgraphicsCommonsVersion
api group: 'org.apache.xmlgraphics', name: 'batik-bridge', version: batikVersion
api group: 'org.apache.xmlgraphics', name: 'batik-gvt', version: batikVersion
Modified: trunk/foray/master/build.gradle
===================================================================
--- trunk/foray/master/build.gradle 2021-01-17 22:45:44 UTC (rev 11814)
+++ trunk/foray/master/build.gradle 2021-01-17 22:51:43 UTC (rev 11815)
@@ -44,12 +44,11 @@
ext.xercesVersion = '2.12.1' // Latest is 2.12.1 as of 2021-01-12.
ext.xmlgraphicsCommonsVersion = '2.4' // Latest is 2.4 as of 2021-01-12.
ext.batikVersion = '1.13' // Latest is 1.13 as of 2021-01-12.
- ext.xalanVersion = '2.7.2' // Latest is 2.7.2 as of 2021-01-12. See Note 7.
- ext.jeuclidVersion = '3.0.3' // Latest is 3.1.9 as of 2021-01-12. See Note 8.
+ ext.jeuclidVersion = '3.0.3' // Latest is 3.1.9 as of 2021-01-12. See Note 7.
ext.icu4jVersion = '68.2' // Latest is 68.2 as of 2021-01-12.
- ext.junitVersion = '4.13.1' // Latest is 5.7.0 as of 2021-01-12. See Note 9.
- ext.mockitoVersion = '2.28.2' // Latest is 3.7.0 as of 2021-01-12. See Note 10.
+ ext.junitVersion = '4.13.1' // Latest is 5.7.0 as of 2021-01-12. See Note 8.
+ ext.mockitoVersion = '2.28.2' // Latest is 3.7.0 as of 2021-01-12. See Note 9.
ext.logbackClassicVersion = '1.2.3' // Latest is 1.2.3 as of 2021-01-12.
ext.checkstyleVersion = '8.39' // Latest is 8.39 as of 2021-01-12.
@@ -78,11 +77,7 @@
* to build with Java 1.7.
* We have therefore stayed with the highest version of 3.x, which is 3.1.0.
*
- * 7. Batik 1.8, released May, 2015, appears to have a runtime dependency on the class
- * org.w3c.dom.xpath.XPathEvaluator, which may have been included as part of standard Java by then.
- * Our only dependency on Xalan is to provide that class.
- *
- * 8. JEuclid 3.1.9 will require handling some API changes.
+ * 7. JEuclid 3.1.9 will require handling some API changes.
* Making those API changes results in runtime problems, which are documented, along with the pro-forma necessary
* code changes, here:
* project: foray-graphic
@@ -91,10 +86,10 @@
* JEuclid does not appear to be supported any longer, and I don't see any other MathML solutions with the right
* licensing. Therefore we will leave this dependency at 3.0.3 for now.
*
- * 9. JUnit is compiled with Java 8 (major version 52) starting with release 5.0.0.
+ * 8. JUnit is compiled with Java 8 (major version 52) starting with release 5.0.0.
* We have therefore stayed with the highest version supporting Java 7, which is 4.13.1.
*
- * 10. Mockito is compiled with Java 8 (major version 52) starting with release 3.0.0.
+ * 9. Mockito is compiled with Java 8 (major version 52) starting with release 3.0.0.
* We have therefore stayed with the highest version supporting Java 7, which 2.28.2.
*
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 22:45:48
|
Revision: 11814
http://sourceforge.net/p/foray/code/11814
Author: victormote
Date: 2021-01-17 22:45:44 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Upgrade Batik to 1.13, the latest version.
Modified Paths:
--------------
trunk/foray/master/build.gradle
Modified: trunk/foray/master/build.gradle
===================================================================
--- trunk/foray/master/build.gradle 2021-01-17 22:37:08 UTC (rev 11813)
+++ trunk/foray/master/build.gradle 2021-01-17 22:45:44 UTC (rev 11814)
@@ -38,13 +38,13 @@
ext.commonsIoVersion = '2.6' // Latest is 2.8.0 as of 2021-01-12. See Note 3.
ext.commonsDiscoveryVersion = '0.5' // Latest is 0.5 as of 2021-01-12.
ext.commonsCliVersion = '1.4' // Latest is 1.4 as of 2021-01-12.
- ext.xalanVersion = '2.7.2' // Latest is 2.7.2 as of 2021-01-12. See Note 11.
ext.xmlResolverVersion = '1.2' // Latest is 1.2 as of 2021-01-12. See Note 4.
ext.antVersion = '1.9.15' // Latest is 1.10.9 as of 2021-01-12. See Note 5.
ext.servletApiVersion = '3.1.0' // Latest is 4.0.1 as of 2021-01-12. See Note 6.
ext.xercesVersion = '2.12.1' // Latest is 2.12.1 as of 2021-01-12.
ext.xmlgraphicsCommonsVersion = '2.4' // Latest is 2.4 as of 2021-01-12.
- ext.batikVersion = '1.9.1' // Latest is 1.13 as of 2021-01-12. See Note 7.
+ ext.batikVersion = '1.13' // Latest is 1.13 as of 2021-01-12.
+ ext.xalanVersion = '2.7.2' // Latest is 2.7.2 as of 2021-01-12. See Note 7.
ext.jeuclidVersion = '3.0.3' // Latest is 3.1.9 as of 2021-01-12. See Note 8.
ext.icu4jVersion = '68.2' // Latest is 68.2 as of 2021-01-12.
@@ -78,7 +78,9 @@
* to build with Java 1.7.
* We have therefore stayed with the highest version of 3.x, which is 3.1.0.
*
- * 7. Batik 1.13 will require handling some API changes.
+ * 7. Batik 1.8, released May, 2015, appears to have a runtime dependency on the class
+ * org.w3c.dom.xpath.XPathEvaluator, which may have been included as part of standard Java by then.
+ * Our only dependency on Xalan is to provide that class.
*
* 8. JEuclid 3.1.9 will require handling some API changes.
* Making those API changes results in runtime problems, which are documented, along with the pro-forma necessary
@@ -95,10 +97,6 @@
* 10. Mockito is compiled with Java 8 (major version 52) starting with release 3.0.0.
* We have therefore stayed with the highest version supporting Java 7, which 2.28.2.
*
- * 11. Batik 1.8, released May, 2015, appears to have a runtime dependency on the class
- * org.w3c.dom.xpath.XPathEvaluator, which may have been included as part of standard Java by then.
- * Our only dependency on Xalan is to provide that class.
- *
*/
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 22:37:13
|
Revision: 11813
http://sourceforge.net/p/foray/code/11813
Author: victormote
Date: 2021-01-17 22:37:08 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Upgrade Batik to 1.9.1.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java
trunk/foray/master/build.gradle
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java 2021-01-17 22:06:08 UTC (rev 11812)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java 2021-01-17 22:37:08 UTC (rev 11813)
@@ -193,6 +193,10 @@
*/
public PdfGraphics2D(final PdfGraphics2D g) {
super(g);
+ this.currentStream = g.currentStream;
+ this.fontConsumer = g.fontConsumer;
+ this.pdfContext = g.pdfContext;
+ this.graphicsStateStack = g.graphicsStateStack;
}
/**
Modified: trunk/foray/master/build.gradle
===================================================================
--- trunk/foray/master/build.gradle 2021-01-17 22:06:08 UTC (rev 11812)
+++ trunk/foray/master/build.gradle 2021-01-17 22:37:08 UTC (rev 11813)
@@ -44,7 +44,7 @@
ext.servletApiVersion = '3.1.0' // Latest is 4.0.1 as of 2021-01-12. See Note 6.
ext.xercesVersion = '2.12.1' // Latest is 2.12.1 as of 2021-01-12.
ext.xmlgraphicsCommonsVersion = '2.4' // Latest is 2.4 as of 2021-01-12.
- ext.batikVersion = '1.8' // Latest is 1.13 as of 2021-01-12. See Note 7.
+ ext.batikVersion = '1.9.1' // Latest is 1.13 as of 2021-01-12. See Note 7.
ext.jeuclidVersion = '3.0.3' // Latest is 3.1.9 as of 2021-01-12. See Note 8.
ext.icu4jVersion = '68.2' // Latest is 68.2 as of 2021-01-12.
@@ -76,7 +76,7 @@
*
* 6. Servlet-api 4.0.1 is compiled with Java 1.8 (major version 52), which produces compile-time warnings when we try
* to build with Java 1.7.
- * We have therefore stayed with the hight version of 3.0, which is 3.1.0.
+ * We have therefore stayed with the highest version of 3.x, which is 3.1.0.
*
* 7. Batik 1.13 will require handling some API changes.
*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 22:06:11
|
Revision: 11812
http://sourceforge.net/p/foray/code/11812
Author: victormote
Date: 2021-01-17 22:06:08 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Change logging level for writing of keys from debug to trace.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java 2021-01-17 22:00:31 UTC (rev 11811)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryTree.java 2021-01-17 22:06:08 UTC (rev 11812)
@@ -235,7 +235,7 @@
this.nodes.ensureCapacity(newCapacity);
if (start == 0) {
- this.logger.debug(key.toString());
+ this.logger.trace(key.toString());
}
put(this.nodes.getRootNodeIndex(), key, start, end, value);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 22:00:33
|
Revision: 11811
http://sourceforge.net/p/foray/code/11811
Author: victormote
Date: 2021-01-17 22:00:31 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Fix Batik deprecation complaint.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java 2021-01-17 21:55:42 UTC (rev 11810)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgJava2d.java 2021-01-17 22:00:31 UTC (rev 11811)
@@ -83,8 +83,7 @@
graphics.translate(x, y);
final SVGSVGElement svg = svgDocument.getRootElement();
- final AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg,
- w, h);
+ final AffineTransform at = ViewBox.getPreserveAspectRatioTransform(svg, w, h, null);
AffineTransform inverse = null;
try {
inverse = at.createInverse();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 21:55:45
|
Revision: 11810
http://sourceforge.net/p/foray/code/11810
Author: victormote
Date: 2021-01-17 21:55:42 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Upgrade to Batik 1.8. There are some known problems with this change.
Modified Paths:
--------------
trunk/foray/foray-graphic/build.gradle
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
trunk/foray/foray-graphic/src/test/java/org/foray/graphic/TestSvgGraphic.java
trunk/foray/master/build.gradle
Modified: trunk/foray/foray-graphic/build.gradle
===================================================================
--- trunk/foray/foray-graphic/build.gradle 2021-01-17 19:49:32 UTC (rev 11809)
+++ trunk/foray/foray-graphic/build.gradle 2021-01-17 21:55:42 UTC (rev 11810)
@@ -4,20 +4,21 @@
api group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
api group: 'commons-io', name: 'commons-io', version: commonsIoVersion
api group: 'xerces', name: 'xercesImpl', version: xercesVersion
+ api group: 'xalan', name: 'xalan', version: xalanVersion
api group: 'org.apache.xmlgraphics', name: 'xmlgraphics-commons', version: xmlgraphicsCommonsVersion
- api group: 'batik', name: 'batik-bridge', version: batikVersion
- api group: 'batik', name: 'batik-gvt', version: batikVersion
- api group: 'batik', name: 'batik-parser', version: batikVersion
- api group: 'batik', name: 'batik-script', version: batikVersion
- api group: 'batik', name: 'batik-transcoder', version: batikVersion
- api group: 'batik', name: 'batik-util', version: batikVersion
- api group: 'batik', name: 'batik-svg-dom', version: batikVersion
- api group: 'batik', name: 'batik-dom', version: batikVersion
- api group: 'batik', name: 'batik-xml', version: batikVersion
- api group: 'batik', name: 'batik-css', version: batikVersion
- api group: 'batik', name: 'batik-awt-util', version: batikVersion
- api group: 'batik', name: 'batik-ext', version: batikVersion
- api group: 'batik', name: 'batik-svggen', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-bridge', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-gvt', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-parser', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-script', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-transcoder', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-util', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-svg-dom', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-dom', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-xml', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-css', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-awt-util', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-ext', version: batikVersion
+ api group: 'org.apache.xmlgraphics', name: 'batik-svggen', version: batikVersion
api group: 'net.sourceforge.jeuclid', name: 'jeuclid-core', version: jeuclidVersion
api group: 'org.axsl', name: 'axsl-graphic', version: axslVersion
api group: 'org.axsl', name: 'axsl-pdf', version: axslVersion
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java 2021-01-17 19:49:32 UTC (rev 11809)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GraphicServer4a.java 2021-01-17 21:55:42 UTC (rev 11810)
@@ -53,7 +53,7 @@
import org.axsl.graphic.MathGraphic;
import org.axsl.graphic.output.GraphicOutput;
-import org.apache.batik.dom.svg.SVGDOMImplementation;
+import org.apache.batik.anim.dom.SVGDOMImplementation;
import org.apache.batik.svggen.SVGGeneratorContext;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.transcoder.TranscoderException;
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java 2021-01-17 19:49:32 UTC (rev 11809)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java 2021-01-17 21:55:42 UTC (rev 11810)
@@ -29,6 +29,7 @@
package org.foray.graphic;
import org.foray.common.Mime;
+import org.foray.common.SvgUtil;
import org.foray.graphic.batik.BatikUaAwt;
import org.axsl.common.sequence.ByteSequence;
@@ -35,11 +36,11 @@
import org.axsl.graphic.Graphic;
import org.axsl.graphic.GraphicException;
+import org.apache.batik.anim.dom.SAXSVGDocumentFactory;
+import org.apache.batik.anim.dom.SVGOMDocument;
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.UnitProcessor;
import org.apache.batik.bridge.UserAgent;
-import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
-import org.apache.batik.dom.svg.SVGOMDocument;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;
@@ -160,7 +161,7 @@
String s;
/* Set the width (in pixels). */
- s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
+ s = e.getAttributeNS(SvgUtil.SVG_NAMESPACE_URI, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
if (s.length() == 0) {
/* Default is 100%. */
s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-01-17 19:49:32 UTC (rev 11809)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfTextPainter.java 2021-01-17 21:55:42 UTC (rev 11810)
@@ -42,12 +42,12 @@
import org.axsl.font.FontOptions;
import org.axsl.font.FontUtility;
-import org.apache.batik.gvt.TextNode;
-import org.apache.batik.gvt.TextPainter;
+import org.apache.batik.bridge.Mark;
+import org.apache.batik.bridge.StrokingTextPainter;
+import org.apache.batik.bridge.TextNode;
+import org.apache.batik.bridge.TextPainter;
import org.apache.batik.gvt.font.GVTFontFamily;
-import org.apache.batik.gvt.renderer.StrokingTextPainter;
import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
-import org.apache.batik.gvt.text.Mark;
import org.apache.batik.gvt.text.TextPaintInfo;
import org.slf4j.Logger;
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-17 19:49:32 UTC (rev 11809)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-17 21:55:42 UTC (rev 11810)
@@ -41,9 +41,9 @@
import org.apache.batik.bridge.BridgeContext;
import org.apache.batik.bridge.GVTBuilder;
+import org.apache.batik.bridge.StrokingTextPainter;
+import org.apache.batik.bridge.TextPainter;
import org.apache.batik.gvt.GraphicsNode;
-import org.apache.batik.gvt.TextPainter;
-import org.apache.batik.gvt.renderer.StrokingTextPainter;
import org.w3c.dom.svg.SVGDocument;
import java.awt.geom.AffineTransform;
Modified: trunk/foray/foray-graphic/src/test/java/org/foray/graphic/TestSvgGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/test/java/org/foray/graphic/TestSvgGraphic.java 2021-01-17 19:49:32 UTC (rev 11809)
+++ trunk/foray/foray-graphic/src/test/java/org/foray/graphic/TestSvgGraphic.java 2021-01-17 21:55:42 UTC (rev 11810)
@@ -30,13 +30,14 @@
import org.axsl.graphic.GraphicException;
+import org.apache.batik.anim.dom.SVGOMDocument;
+import org.apache.batik.anim.dom.SVGOMRectElement;
+import org.apache.batik.anim.dom.SVGOMStyleElement;
+import org.apache.batik.anim.dom.SVGOMTextElement;
import org.apache.batik.dom.GenericText;
-import org.apache.batik.dom.svg.SVGOMDocument;
-import org.apache.batik.dom.svg.SVGOMRectElement;
-import org.apache.batik.dom.svg.SVGOMStyleElement;
-import org.apache.batik.dom.svg.SVGOMTextElement;
import org.w3c.dom.Attr;
import org.w3c.dom.Comment;
+import org.w3c.dom.DocumentType;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -69,7 +70,7 @@
Assert.assertNotNull(graphic);
Assert.assertTrue(graphic instanceof SvgGraphic);
final SvgGraphic svg = (SvgGraphic) graphic;
- Assert.assertEquals(200, svg.pixelWidth());
+ Assert.assertEquals(100, svg.pixelWidth());
Assert.assertEquals(50, svg.pixelHeight());
final SVGDocument svgDoc = svg.getSvgDocument();
Assert.assertNotNull(svgDoc);
@@ -81,14 +82,18 @@
/* Test the direct children of the document itself. */
NodeList children = svgDoc.getChildNodes();
int childCount = children.getLength();
- Assert.assertEquals(2, childCount);
+ Assert.assertEquals(3, childCount);
- /* The first child is a comment. */
+ /* The first child is a document type. */
Node child = children.item(0);
+ Assert.assertTrue(child instanceof DocumentType);
+
+ /* The second child is a comment. */
+ child = children.item(1);
Assert.assertTrue(child instanceof Comment);
- /* The second child is the <svg> element itself. */
- child = children.item(1);
+ /* The third child is the <svg> element itself. */
+ child = children.item(2);
Assert.assertTrue(child instanceof SVGSVGElement);
final SVGSVGElement svgElement = (SVGSVGElement) child;
@@ -153,11 +158,11 @@
/* Test the direct children of the document itself. */
NodeList children = batikDoc.getChildNodes();
int childCount = children.getLength();
- Assert.assertEquals(2, childCount);
+ Assert.assertEquals(3, childCount);
- /* The first child is the comment, the second child is the <svg> element
+ /* The first child is the document type, the second is the comment, and the third is the <svg> element
* itself. */
- Node child = children.item(1);
+ Node child = children.item(2);
Assert.assertTrue(child instanceof SVGSVGElement);
final SVGSVGElement svgElement = (SVGSVGElement) child;
Modified: trunk/foray/master/build.gradle
===================================================================
--- trunk/foray/master/build.gradle 2021-01-17 19:49:32 UTC (rev 11809)
+++ trunk/foray/master/build.gradle 2021-01-17 21:55:42 UTC (rev 11810)
@@ -38,12 +38,13 @@
ext.commonsIoVersion = '2.6' // Latest is 2.8.0 as of 2021-01-12. See Note 3.
ext.commonsDiscoveryVersion = '0.5' // Latest is 0.5 as of 2021-01-12.
ext.commonsCliVersion = '1.4' // Latest is 1.4 as of 2021-01-12.
+ ext.xalanVersion = '2.7.2' // Latest is 2.7.2 as of 2021-01-12. See Note 11.
ext.xmlResolverVersion = '1.2' // Latest is 1.2 as of 2021-01-12. See Note 4.
ext.antVersion = '1.9.15' // Latest is 1.10.9 as of 2021-01-12. See Note 5.
ext.servletApiVersion = '3.1.0' // Latest is 4.0.1 as of 2021-01-12. See Note 6.
ext.xercesVersion = '2.12.1' // Latest is 2.12.1 as of 2021-01-12.
ext.xmlgraphicsCommonsVersion = '2.4' // Latest is 2.4 as of 2021-01-12.
- ext.batikVersion = '1.6' // Latest is 1.13 as of 2021-01-12. See Note 7.
+ ext.batikVersion = '1.8' // Latest is 1.13 as of 2021-01-12. See Note 7.
ext.jeuclidVersion = '3.0.3' // Latest is 3.1.9 as of 2021-01-12. See Note 8.
ext.icu4jVersion = '68.2' // Latest is 68.2 as of 2021-01-12.
@@ -77,8 +78,7 @@
* to build with Java 1.7.
* We have therefore stayed with the hight version of 3.0, which is 3.1.0.
*
- * 7. Batik 1.13 will require handling some API changes. Batik 1.7 causes a NullPointerException when running one of
- * our manual tests. Batik 1.6.1 requires a library that does not exist in the Maven repository.
+ * 7. Batik 1.13 will require handling some API changes.
*
* 8. JEuclid 3.1.9 will require handling some API changes.
* Making those API changes results in runtime problems, which are documented, along with the pro-forma necessary
@@ -95,6 +95,10 @@
* 10. Mockito is compiled with Java 8 (major version 52) starting with release 3.0.0.
* We have therefore stayed with the highest version supporting Java 7, which 2.28.2.
*
+ * 11. Batik 1.8, released May, 2015, appears to have a runtime dependency on the class
+ * org.w3c.dom.xpath.XPathEvaluator, which may have been included as part of standard Java by then.
+ * Our only dependency on Xalan is to provide that class.
+ *
*/
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 19:49:40
|
Revision: 11809
http://sourceforge.net/p/foray/code/11809
Author: victormote
Date: 2021-01-17 19:49:32 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Add the SVG namespace to our demo/test SVG files.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg
trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg
trunk/foray/master/dist/resource/fo-examples/svg/multi.svg
trunk/foray/master/dist/resource/fo-examples/svg/ref.svg
trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg
trunk/foray/master/dist/resource/fo-examples/svg/view.svg
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-17 17:40:35 UTC (rev 11808)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-17 19:49:32 UTC (rev 11809)
@@ -57,11 +57,10 @@
* <p>For content that is only to be used one time in a document, there is some overhead associated with creating and
* using the content as an object instead of writing it directly in a content stream.
* In this case, the benefit of reusability does not exist.
- * However, the benefit of independence may well outweigh the small cost of creating the content as a Form XObject.
- * <p>
+ * However, the benefit of independence may well outweigh the small cost of creating the content as a Form XObject.</p>
*
* @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.9, for Form XObjects, including a Note that explains
- * the meaning of the term \"form\" in this context."
+ * the meaning of the term <em>form</em> in this context."
*/
public abstract class PdfXform extends PdfXobject {
Modified: trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg 2021-01-17 17:40:35 UTC (rev 11808)
+++ trunk/foray/master/dist/resource/fo-examples/svg/boxes.svg 2021-01-17 19:49:32 UTC (rev 11809)
@@ -2,7 +2,9 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
-<svg width="20" height="20" xml:space="preserve">
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="20" height="20" xml:space="preserve">
<g style="fill:red; stroke:#000000">
<rect x="0" y="0" width="15" height="15"/>
<rect x="5" y="5" width="15" height="15"/>
Modified: trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg 2021-01-17 17:40:35 UTC (rev 11808)
+++ trunk/foray/master/dist/resource/fo-examples/svg/font-embed.svg 2021-01-17 19:49:32 UTC (rev 11809)
@@ -20,7 +20,9 @@
Only the glyphs needed by this document were included in the embedded font.
-->
-<svg width="150" height="50">
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="150" height="50">
<style type="text/css">
<![CDATA[
Modified: trunk/foray/master/dist/resource/fo-examples/svg/multi.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/multi.svg 2021-01-17 17:40:35 UTC (rev 11808)
+++ trunk/foray/master/dist/resource/fo-examples/svg/multi.svg 2021-01-17 19:49:32 UTC (rev 11809)
@@ -2,7 +2,10 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
-<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="60" height="40" xml:space="preserve">
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="60" height="40" xml:space="preserve">
<g style="fill:none;stroke:yellow">
<rect x="0" y="0" width="25" height="25"/>
<image xlink:href="file:boxes.svg" x="10" y="10" width="20" height="20"/>
Modified: trunk/foray/master/dist/resource/fo-examples/svg/ref.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/ref.svg 2021-01-17 17:40:35 UTC (rev 11808)
+++ trunk/foray/master/dist/resource/fo-examples/svg/ref.svg 2021-01-17 19:49:32 UTC (rev 11809)
@@ -2,7 +2,9 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
-<svg width="20" height="20" xml:space="preserve">
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="20" height="20" xml:space="preserve">
<g id="App">
<text x="0" y="0" style="fill:black;font-weight:bold;font-size:14"><tspan style="fill:red">F</tspan><tspan style="fill:purple">O</tspan><tspan style="fill:blue">P</tspan></text>
</g>
Modified: trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg 2021-01-17 17:40:35 UTC (rev 11808)
+++ trunk/foray/master/dist/resource/fo-examples/svg/text-001.svg 2021-01-17 19:49:32 UTC (rev 11809)
@@ -6,7 +6,9 @@
This document tests the ability of writing some simple text.
-->
-<svg width="200" height="50">
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="200" height="50">
<rect x="0" y="0" width="200" height="50" fill="maroon"/>
<text x="20" y="40" font-family="serif" font-size="36" fill="white">Some Text</text>
Modified: trunk/foray/master/dist/resource/fo-examples/svg/view.svg
===================================================================
--- trunk/foray/master/dist/resource/fo-examples/svg/view.svg 2021-01-17 17:40:35 UTC (rev 11808)
+++ trunk/foray/master/dist/resource/fo-examples/svg/view.svg 2021-01-17 19:49:32 UTC (rev 11809)
@@ -2,7 +2,9 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN"
"http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.dtd">
-<svg viewBox="0 0 10 10" width="20" height="20" xml:space="preserve">
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 10 10" width="20" height="20" xml:space="preserve">
<g style="fill:red; stroke:#000000">
<rect x="0" y="0" width="15" height="15"/>
<rect x="5" y="5" width="15" height="15"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 17:40:38
|
Revision: 11808
http://sourceforge.net/p/foray/code/11808
Author: victormote
Date: 2021-01-17 17:40:35 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Remove some unnecessary logging and logger passing.
Modified Paths:
--------------
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java 2021-01-17 15:25:28 UTC (rev 11807)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/SvgGraphic.java 2021-01-17 17:40:35 UTC (rev 11808)
@@ -53,8 +53,7 @@
/**
* An SVG Graphic.
*/
-public class SvgGraphic extends Graphic4a
- implements org.axsl.graphic.SvgGraphic {
+public class SvgGraphic extends Graphic4a implements org.axsl.graphic.SvgGraphic {
/** The encapsulated SVG document. */
private SVGDocument doc;
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java 2021-01-17 15:25:28 UTC (rev 11807)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/batik/PdfGraphics2D.java 2021-01-17 17:40:35 UTC (rev 11808)
@@ -47,7 +47,7 @@
import org.axsl.graphic.output.GraphicOutputContext;
import org.axsl.pdf.PdfPage;
-import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.awt.AlphaComposite;
import java.awt.BasicStroke;
@@ -156,9 +156,6 @@
/** Used to create proper font metrics. */
private Graphics2D fmg;
- /** The logger. */
- private Logger logger;
-
/** The PDF context. */
private GraphicOutputContext pdfContext;
@@ -175,20 +172,16 @@
* This is used to create a Graphics object for use inside an already existing document.
* @param textAsShapes Set this to true so that text will be rendered using curves and not the font.
* @param fontConsumer The font consumer for this document.
- * @param logger The logger.
* @param pdfContext The PDF context in which this content is being written.
* @param outputStream The output stream to which this processor writes its PDF output.
*/
- public PdfGraphics2D(final boolean textAsShapes,
- final FontConsumer fontConsumer, final Logger logger,
- final GraphicOutputContext pdfContext,
- final OutputStream outputStream) {
+ public PdfGraphics2D(final boolean textAsShapes, final FontConsumer fontConsumer,
+ final GraphicOutputContext pdfContext, final OutputStream outputStream) {
super(textAsShapes);
/* TODO: Only write the comments if running in debug mode?? */
this.currentStream = new CharacterOutputStream(outputStream, true);
this.comment("%%%% Start FOrayGraphic SVG-to-PDF conversion. %%%%");
- this.logger = logger;
this.fontConsumer = fontConsumer;
this.pdfContext = pdfContext;
this.graphicsStateStack.push(new PdfGraphicsState(null));
@@ -200,7 +193,6 @@
*/
public PdfGraphics2D(final PdfGraphics2D g) {
super(g);
- this.logger = g.logger;
}
/**
@@ -639,15 +631,11 @@
}
@Override
- public void drawRenderedImage(final RenderedImage img,
- final AffineTransform xform) {
- this.logger.info("drawRenderedImage");
+ public void drawRenderedImage(final RenderedImage img, final AffineTransform xform) {
}
@Override
- public void drawRenderableImage(final RenderableImage img,
- final AffineTransform xform) {
- this.logger.info("drawRenderableImage");
+ public void drawRenderableImage(final RenderableImage img, final AffineTransform xform) {
}
@Override
@@ -734,10 +722,9 @@
}
@Override
- public void drawString(final AttributedCharacterIterator iterator,
- final float x, final float y) {
- this.logger.error(
- "drawString(AttributedCharacterIterator)");
+ public void drawString(final AttributedCharacterIterator iterator, final float x, final float y) {
+ LoggerFactory.getLogger(this.getClass()).error("drawString(AttributedCharacterIterator)");
+ /* TODO: This method may not ever be called, as we never see the above error logged. Investigate further. */
final Shape imclip = getClip();
writeClip(imclip);
@@ -885,14 +872,11 @@
@Override
public void setXORMode(final Color c1) {
- this.logger.info("setXORMode");
}
@Override
- public void copyArea(final int x, final int y, final int width,
- final int height, final int dx, final int dy) {
- this.logger.info("copyArea");
+ public void copyArea(final int x, final int y, final int width, final int height, final int dx, final int dy) {
}
/**
Modified: trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java
===================================================================
--- trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-17 15:25:28 UTC (rev 11807)
+++ trunk/foray/foray-graphic/src/main/java/org/foray/graphic/output/SvgPdf.java 2021-01-17 17:40:35 UTC (rev 11808)
@@ -133,7 +133,7 @@
builder = null;
final PdfGraphics2D graphics;
- graphics = new PdfGraphics2D(true, fontConsumer, this.svg.getLogger(), pdfContext, outputStream);
+ graphics = new PdfGraphics2D(true, fontConsumer, pdfContext, outputStream);
graphics.setGraphicContext(new org.apache.batik.ext.awt.g2d.GraphicContext());
root.paint(graphics);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 15:25:29
|
Revision: 11807
http://sourceforge.net/p/foray/code/11807
Author: victormote
Date: 2021-01-17 15:25:28 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Doc changes only.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-17 00:33:06 UTC (rev 11806)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXform.java 2021-01-17 15:25:28 UTC (rev 11807)
@@ -36,7 +36,32 @@
import java.awt.geom.AffineTransform;
/**
- * Represents a "Form" XObject.
+ * <p>Represents a Form XObject.
+ * The use of the term "form" here is a bit confusing, and appears to be retained for historical reasons related to
+ * PDF's roots in the PostScript language.
+ * It has nothing to do with interactive forms in general, nor AcroForm in particular.
+ * Instead a Form XObject allows content that could be written into a {@link org.axsl.pdf.PdfContentStream} directly to
+ * be handled as an independent, self-contained object that is simply called as needed when creating the content stream.
+ * Using this approach has several benefits, including:</p>
+ * <ul>
+ * <li>Reusability. The object can be called from multiple pages or all pages.
+ * In a 100 page document that used the content on each page, it is defined only once, but used 100 times, resulting
+ * in a much more compact PDF document.</li>
+ * <li>Independence. The process of writing the content is separate from its placement, scaling, rotation, etc. in the
+ * stream.
+ * This has implicatons for reusability, but also provides a separation of concerns for development, as it allows the
+ * creation of the content to be separated from how it is used in the document.</li>
+ * <li></li>
+ * </ul>
+ *
+ * <p>For content that is only to be used one time in a document, there is some overhead associated with creating and
+ * using the content as an object instead of writing it directly in a content stream.
+ * In this case, the benefit of reusability does not exist.
+ * However, the benefit of independence may well outweigh the small cost of creating the content as a Form XObject.
+ * <p>
+ *
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.9, for Form XObjects, including a Note that explains
+ * the meaning of the term \"form\" in this context."
*/
public abstract class PdfXform extends PdfXobject {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java 2021-01-17 00:33:06 UTC (rev 11806)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXimage.java 2021-01-17 15:25:28 UTC (rev 11807)
@@ -44,10 +44,11 @@
import java.awt.geom.Rectangle2D;
/**
- * A sampled image that is to be embedded in a PDF File. Images in PDF are
- * XObjects (external objects).
+ * A sampled image that is to be embedded in a PDF File.
+ * Images in PDF can either be written directly into the content stream or handled as XObjects (external objects).
*
* @see PdfXobject
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.8.4."
*/
public class PdfXimage extends PdfXobject {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-17 00:33:06 UTC (rev 11806)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-17 15:25:28 UTC (rev 11807)
@@ -49,12 +49,15 @@
import java.io.OutputStream;
/**
- * PDF XObject (external object), aka a "named resource". Used to represent
- * 1) bitmap images, 2) form XObjects (reusable sequences of other graphical
- * objects, not to be confused with an interactive form), and 3) PostScript
- * XObjects (whose use is unnecessary and deprecated).
+ * <p>Abstract superclass for PDF XObject or external object. There are three types:</p>
+ * <ul>
+ * <li>An image XObject. See {@link PdfXimage} for a concrete implementation.</li>
+ * <li>A form XObject. See {@link PdfXform} for a concrete implementation.</li>
+ * <li>A PostScript XObject. The use of these is unnecessary and deprecated, and there is no concrete implementation
+ * for it.</li>
+ * </ul>
*
- * An XObject has not only a dictionary but a stream of image data.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.7, for a general description of External Objects."
*/
public abstract class PdfXobject extends PdfStream {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 00:33:08
|
Revision: 11806
http://sourceforge.net/p/foray/code/11806
Author: victormote
Date: 2021-01-17 00:33:06 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Clean up internal data for CharSet4a.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/resources/resources/org/foray/font/base14/Symbol.jbso
trunk/foray/foray-font/src/main/resources/resources/org/foray/font/base14/ZapfDingbats.jbso
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java
Modified: trunk/foray/foray-font/src/main/resources/resources/org/foray/font/base14/Symbol.jbso
===================================================================
(Binary files differ)
Modified: trunk/foray/foray-font/src/main/resources/resources/org/foray/font/base14/ZapfDingbats.jbso
===================================================================
(Binary files differ)
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java 2021-01-17 00:00:51 UTC (rev 11805)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java 2021-01-17 00:33:06 UTC (rev 11806)
@@ -28,6 +28,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.common.sequence.IntSequenceMutable;
import org.axsl.ps.CharSet;
@@ -35,7 +38,6 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -59,20 +61,18 @@
private transient String name;
/** The 16-bit Unicode codepoints. */
- private transient char[] characterSet16;
+ private transient CharArray characterSet16;
/** The 32-bit Unicode codepoints. These are conceptually appended to the
* end of {@link #characterSet16} as if they were all in one array. */
- private transient int[] characterSet32;
+ private transient IntArray characterSet32;
/**
* Constructor.
* @param name The name of this character set.
- * @param mutable The array containing the code points in this character set.
+ * @param characterSet The array containing the code points in this character set.
*/
- public CharSet4a(final String name, final IntSequenceMutable mutable) {
- final int[] characterSet = mutable.toArray();
-
+ public CharSet4a(final String name, final IntSequenceMutable characterSet) {
this.name = name;
if (characterSet == null) {
return;
@@ -79,41 +79,24 @@
}
/* Make sure the input array is sorted. */
- Arrays.sort(characterSet);
+ characterSet.sort();
- /* Find the index to the first code point > 0xFFFF. */
- int first32bitIndex = Integer.MAX_VALUE;
- for (int i = characterSet.length - 1; i > -1 && first32bitIndex < 0;
- i--) {
- if (characterSet[i] <= Character.MAX_VALUE) {
- /* We are down to the 16-bit items, so we are done. */
+ /* Count the values needing 32 bits. */
+ int count32 = 0;
+ for (int i = characterSet.length() - 1; i > -1; i--) {
+ if (characterSet.intAt(i) > Character.MAX_VALUE) {
+ count32 ++;
+ } else {
break;
}
- /* We are still in the 32-bit items, so this one is now the first
- * known 32-bit item. */
- first32bitIndex = i;
}
- /* Split the input array into 2 arrays, one for 16-bit items, one for
- * 32-bit items. */
- if (first32bitIndex == Integer.MAX_VALUE) {
- /* There are no 32-bit values. */
- this.characterSet32 = null;
- this.characterSet16 = new char[characterSet.length];
- for (int i = 0; i < characterSet.length; i++) {
- this.characterSet16[i] = (char) characterSet[i];
- }
+ if (count32 == 0) {
+ this.characterSet16 = new CharArray(characterSet);
+ this.characterSet32 = IntArray.EMPTY;
} else {
- final int num16bits = first32bitIndex;
- final int num32bits = characterSet.length - num16bits;
- this.characterSet16 = new char[num16bits];
- for (int i = 0; i < first32bitIndex; i++) {
- this.characterSet16[i] = (char) characterSet[i];
- }
- this.characterSet32 = new int[num32bits];
- for (int i = first32bitIndex; i < characterSet.length; i++) {
- this.characterSet32[i - first32bitIndex] = characterSet[i];
- }
+ this.characterSet16 = new CharArray(characterSet.subSequence(0, count32));
+ this.characterSet32 = new IntArray(characterSet.subSequence(count32, characterSet.length()));
}
}
@@ -127,24 +110,13 @@
@Override
public int getIndex(final int codePoint) {
- int index = -1;
- if (this.characterSet16 != null) {
- index = Arrays.binarySearch(this.characterSet16, (char) codePoint);
+ if (codePoint > Character.MAX_VALUE) {
+ final int index = this.characterSet32.binarySearch(codePoint);
+ return index < 0 ? -1 : index + this.characterSet16.length();
+ } else {
+ final int index = this.characterSet16.binarySearch((char) codePoint);
+ return index < 0 ? -1 : index;
}
- if (index > -1) {
- return index;
- }
- if (this.characterSet32 != null) {
- index = Arrays.binarySearch(this.characterSet32, codePoint);
- if (index > -1
- && this.characterSet16 != null) {
- index += this.characterSet16.length;
- }
- }
- if (index < 0) {
- index = -1;
- }
- return index;
}
/**
@@ -197,14 +169,7 @@
* @return The size of this character set.
*/
public int size() {
- int size = 0;
- if (this.characterSet16 != null) {
- size += this.characterSet16.length;
- }
- if (this.characterSet32 != null) {
- size += this.characterSet32.length;
- }
- return size;
+ return this.characterSet16.length() + this.characterSet32.length();
}
/**
@@ -260,8 +225,8 @@
}
stream.defaultReadObject();
this.name = (String) stream.readObject();
- this.characterSet16 = (char[]) stream.readObject();
- this.characterSet32 = (int[]) stream.readObject();
+ this.characterSet16 = (CharArray) stream.readObject();
+ this.characterSet32 = (IntArray) stream.readObject();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-17 00:00:53
|
Revision: 11805
http://sourceforge.net/p/foray/code/11805
Author: victormote
Date: 2021-01-17 00:00:51 +0000 (Sun, 17 Jan 2021)
Log Message:
-----------
Conform to aXSL changes: Leave only the IntSequence method for creating a CharSet.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetExtendedRoman.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetWindowsAnsi.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 23:33:26 UTC (rev 11804)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-17 00:00:51 UTC (rev 11805)
@@ -216,6 +216,20 @@
}
/**
+ * Append a varargs or char[] to this structure.
+ * @param intToAppend The int to append.
+ * @return This object.
+ */
+ public IntArrayBuilder append(final char... intToAppend) {
+ ensureCapacity(this.length + intToAppend.length);
+ for (int index = 0; index < intToAppend.length; index ++) {
+ this.array[this.length] = intToAppend[index];
+ this.length ++;
+ }
+ return this;
+ }
+
+ /**
* Append the content of an existing sequence to this one.
* @param newContent The existing sequence whose content should be appended to this one.
* @return This object.
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 2021-01-16 23:33:26 UTC (rev 11804)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2021-01-17 00:00:51 UTC (rev 11805)
@@ -28,6 +28,7 @@
package org.foray.ps;
+import org.foray.common.sequence.IntArrayBuilder;
import org.foray.ps.encode.CharSet4a;
import org.foray.ps.encode.CharSetParser;
import org.foray.ps.encode.Cmap4a04;
@@ -67,10 +68,8 @@
import org.foray.ps.pdf.PdfSystemDict;
import org.foray.ps.readonly.ReadOnlySystemDict;
-import org.axsl.common.sequence.CharSequencePlus;
-import org.axsl.common.sequence.CharSequenceUtility;
import org.axsl.common.sequence.IntSequence;
-import org.axsl.common.sequence.IntSequencePlus;
+import org.axsl.common.sequence.IntSequenceMutable;
import org.axsl.ps.CharSet;
import org.axsl.ps.Cmap04;
import org.axsl.ps.Cmap12;
@@ -274,21 +273,15 @@
@Override
public CharSet makeCharSet(final String name, final IntSequence characterSet) {
- final IntSequencePlus plus = characterSet.asPlus();
- return new CharSet4a(name, plus.toArray());
+ final IntSequenceMutable mutable = IntArrayBuilder.fromIntSequence(characterSet);
+ return new CharSet4a(name, mutable);
}
@Override
- public CharSet makeCharSet(final String name, final CharSequence characterSet) {
- final CharSequencePlus plus = CharSequenceUtility.asPlus(characterSet);
- return new CharSet4a(name, plus.toArray());
- }
-
- @Override
public CharSet parseCharSet(final String name, final InputStream inputStream) throws IOException, PsException {
final CharSetParser parser = new CharSetParser(inputStream);
parser.parseList();
- final CharSet4a charSet = new CharSet4a(name, parser.getCharacterSet());
+ final CharSet4a charSet = new CharSet4a(name, new IntArrayBuilder().append(parser.getCharacterSet()));
return charSet;
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java 2021-01-16 23:33:26 UTC (rev 11804)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSet4a.java 2021-01-17 00:00:51 UTC (rev 11805)
@@ -28,6 +28,7 @@
package org.foray.ps.encode;
+import org.axsl.common.sequence.IntSequenceMutable;
import org.axsl.ps.CharSet;
import java.io.IOException;
@@ -65,33 +66,13 @@
private transient int[] characterSet32;
/**
- * Constructor suitable for character sets that contain only 16-bit
- * characters. If there are any 32-bit code points in the character set,
- * use {@link #CharSet4a(String, int[])} instead.
+ * Constructor.
* @param name The name of this character set.
- * @param characterSet The array containing the code points in this
- * character set.
+ * @param mutable The array containing the code points in this character set.
*/
- public CharSet4a(final String name, final char[] characterSet) {
- this.name = name;
- if (characterSet == null) {
- return;
- }
- /* Make sure the input array is sorted. */
- Arrays.sort(characterSet);
- this.characterSet16 = characterSet;
- }
+ public CharSet4a(final String name, final IntSequenceMutable mutable) {
+ final int[] characterSet = mutable.toArray();
- /**
- * General constructor suitable for character sets containing 16-bit
- * codePoints, 32-bit code points, or both.
- * If all code points in the character set are 16-bit (less than or equal to
- * 0xFFFF), then {@link #CharSet4a(String, char[])} may also be used.
- * @param name The name of this character set.
- * @param characterSet The array containing the code points in this
- * character set.
- */
- public CharSet4a(final String name, final int[] characterSet) {
this.name = name;
if (characterSet == null) {
return;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetExtendedRoman.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetExtendedRoman.java 2021-01-16 23:33:26 UTC (rev 11804)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetExtendedRoman.java 2021-01-17 00:00:51 UTC (rev 11805)
@@ -28,6 +28,8 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.IntArrayBuilder;
+
/**
* Class containing hard-coded values that represent the ExtendedRoman
* character set.
@@ -372,7 +374,7 @@
* Constructor.
*/
private CharSetExtendedRoman() {
- super("ExtendedRoman", CharSetExtendedRoman.CHARACTER_SET);
+ super("ExtendedRoman", new IntArrayBuilder().append(CharSetExtendedRoman.CHARACTER_SET));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetWindowsAnsi.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetWindowsAnsi.java 2021-01-16 23:33:26 UTC (rev 11804)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetWindowsAnsi.java 2021-01-17 00:00:51 UTC (rev 11805)
@@ -28,6 +28,7 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.IntArrayBuilder;
/**
* Class containing hard-coded values that represent the "Windows ANSI"
@@ -46,7 +47,7 @@
* Constructor.
*/
private CharSetWindowsAnsi() {
- super("WindowsANSI", EncodingWinAnsi.getCodePoints());
+ super("WindowsANSI", new IntArrayBuilder().append(EncodingWinAnsi.getCodePoints()));
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-16 23:33:34
|
Revision: 11804
http://sourceforge.net/p/foray/code/11804
Author: victormote
Date: 2021-01-16 23:33:26 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Conform to aXSL changes: Change char[] and int[] parameters to sequences.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-01-16 22:41:24 UTC (rev 11803)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-01-16 23:33:26 UTC (rev 11804)
@@ -127,7 +127,7 @@
return this;
}
- public ByteArrayBuilder append(final byte[] bytes) {
+ public ByteArrayBuilder append(final byte ... bytes) {
ensureCapacity(length() + bytes.length);
System.arraycopy(bytes, 0, this.backingArray, this.nextIndex, bytes.length);
this.nextIndex += bytes.length;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 22:41:24 UTC (rev 11803)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 23:33:26 UTC (rev 11804)
@@ -296,6 +296,13 @@
return this;
}
+ public CharArrayBuilder append(final char ... chars) {
+ ensureCapacity(length() + chars.length);
+ System.arraycopy(chars, 0, this.backingArray, this.nextIndex, chars.length);
+ this.nextIndex += chars.length;
+ return this;
+ }
+
/**
* Append the content of an existing sequence to this one.
* @param newContent The existing sequence whose content should be appended to this one.
@@ -311,4 +318,12 @@
return this;
}
+ /**
+ * Returns the content of this builder as an instance of {@link CharArray}, which is immutable.
+ * @return A new instance of {@link CharArray} whose contents are identical to this.
+ */
+ public CharArray toCharArray() {
+ return new CharArray(toArray());
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java 2021-01-16 22:41:24 UTC (rev 11803)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java 2021-01-16 23:33:26 UTC (rev 11804)
@@ -1087,7 +1087,8 @@
}
}
}
- this.metrics.setCharSet(psServer.makeCharSet(this.metrics.getPostscriptName(), this.codePoints));
+ this.metrics.setCharSet(psServer.makeCharSet(this.metrics.getPostscriptName(),
+ new IntArrayBuilder().append(this.codePoints)));
}
/**
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 2021-01-16 22:41:24 UTC (rev 11803)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2021-01-16 23:33:26 UTC (rev 11804)
@@ -67,7 +67,10 @@
import org.foray.ps.pdf.PdfSystemDict;
import org.foray.ps.readonly.ReadOnlySystemDict;
+import org.axsl.common.sequence.CharSequencePlus;
+import org.axsl.common.sequence.CharSequenceUtility;
import org.axsl.common.sequence.IntSequence;
+import org.axsl.common.sequence.IntSequencePlus;
import org.axsl.ps.CharSet;
import org.axsl.ps.Cmap04;
import org.axsl.ps.Cmap12;
@@ -270,13 +273,15 @@
}
@Override
- public CharSet makeCharSet(final String name, final int[] characterSet) {
- return new CharSet4a(name, characterSet);
+ public CharSet makeCharSet(final String name, final IntSequence characterSet) {
+ final IntSequencePlus plus = characterSet.asPlus();
+ return new CharSet4a(name, plus.toArray());
}
@Override
- public CharSet makeCharSet(final String name, final char[] characterSet) {
- return new CharSet4a(name, characterSet);
+ public CharSet makeCharSet(final String name, final CharSequence characterSet) {
+ final CharSequencePlus plus = CharSequenceUtility.asPlus(characterSet);
+ return new CharSet4a(name, plus.toArray());
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-16 22:41:28
|
Revision: 11803
http://sourceforge.net/p/foray/code/11803
Author: victormote
Date: 2021-01-16 22:41:24 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Convert char[] to CharArrayBuilder.
Modified Paths:
--------------
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java 2021-01-16 22:34:58 UTC (rev 11802)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/CharSetParser.java 2021-01-16 22:41:24 UTC (rev 11803)
@@ -28,8 +28,8 @@
package org.foray.ps.encode;
-import org.foray.common.primitive.CharacterUtils;
import org.foray.common.primitive.StringUtils;
+import org.foray.common.sequence.CharArrayBuilder;
import org.foray.common.url.UrlFactory;
import org.axsl.ps.GlyphList;
@@ -74,7 +74,7 @@
private transient int currentLineNumber = 0;
/** The array of characters in the character set. */
- private List<Character> characterSet = new ArrayList<Character>();
+ private CharArrayBuilder characterSet = new CharArrayBuilder();
/** The array of glyph names in the character set. */
private List<String> glyphNames = new ArrayList<String>();
@@ -150,7 +150,7 @@
* @throws PsException For errors parsing the line.
*/
private void processCurrentLine(final String line, final int arrayIndex) throws PsException {
- this.characterSet.add(Character.MIN_VALUE);
+ this.characterSet.append(Character.MIN_VALUE);
this.glyphNames.add(StringUtils.EMPTY_STRING);
final GlyphList gl = GlyphListAgl.getInstance();
final char theChar = gl.mapGlyphNameToCodePoint(line);
@@ -159,7 +159,7 @@
+ this.currentLineNumber + ": " + line);
}
- this.characterSet.set(arrayIndex, theChar);
+ this.characterSet.setCharAt(arrayIndex, theChar);
this.glyphNames.set(arrayIndex, line);
}
@@ -171,13 +171,13 @@
boolean anyChanges = true;
while (anyChanges) {
anyChanges = false;
- for (int i = 0; i < this.characterSet.size() - 1; i++) {
- if (this.characterSet.get(i) > this.characterSet.get(i + 1)) {
+ for (int i = 0; i < this.characterSet.length() - 1; i++) {
+ if (this.characterSet.charAt(i) > this.characterSet.charAt(i + 1)) {
/* They are out of order. Switch the corresponding elements
* in both arrays. */
- final char storeChar = this.characterSet.get(i);
- this.characterSet.set(i, this.characterSet.get(i + 1));
- this.characterSet.set(i + 1, storeChar);
+ final char storeChar = this.characterSet.charAt(i);
+ this.characterSet.setCharAt(i, this.characterSet.charAt(i + 1));
+ this.characterSet.setCharAt(i + 1, storeChar);
final String storeString = this.glyphNames.get(i);
this.glyphNames.set(i, this.glyphNames.get(i + 1));
this.glyphNames.set(i + 1, storeString);
@@ -208,11 +208,11 @@
out.write(s.getBytes());
s = " public static final char[] characterSet = {\n";
out.write(s.getBytes());
- for (int i = 0; i < this.characterSet.size(); i++) {
+ for (int i = 0; i < this.characterSet.length(); i++) {
s = " 0x";
- s = s + StringUtils.charToHexString(this.characterSet.get(i), true,
+ s = s + StringUtils.charToHexString(this.characterSet.charAt(i), true,
CharSetParser.MINIMUM_CHAR_SIZE);
- if (i < this.characterSet.size() - 1) {
+ if (i < this.characterSet.length() - 1) {
s = s + ",";
} else {
s = s + " ";
@@ -233,7 +233,7 @@
* @return The Unicode code points in this character set.
*/
public char[] getCharacterSet() {
- return CharacterUtils.toArray(this.characterSet);
+ return this.characterSet.toArray();
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-16 22:35:00
|
Revision: 11802
http://sourceforge.net/p/foray/code/11802
Author: victormote
Date: 2021-01-16 22:34:58 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Conform to aXSL changes serializing all Plus interfaces, and adding some standard methods.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractByteSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractShortSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractByteSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractByteSequence.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractByteSequence.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -47,6 +47,9 @@
*/
public abstract class AbstractByteSequence implements ByteSequencePlus {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -1357351215576051840L;
+
/** Byte array containing all whitespace characters. */
private static final ByteArray WHITESPACE_CHARS = new ByteArray(" \n\r\t");
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -38,6 +38,9 @@
*/
public abstract class AbstractCharSequence implements CharSequencePlus {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -1486986783061908158L;
+
@Override
public int indexOf(final char aChar) {
for (int index = 0; index < length(); index ++) {
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -38,6 +38,9 @@
*/
public abstract class AbstractIntSequence implements IntSequencePlus {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = 6308504447450398044L;
+
@Override
public int indexOf(final int anInt) {
for (int index = 0; index < length(); index ++) {
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -38,6 +38,9 @@
*/
public abstract class AbstractLongSequence implements LongSequencePlus {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -4561491878925977191L;
+
@Override
public int indexOf(final long aLong) {
for (int index = 0; index < length(); index ++) {
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractShortSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractShortSequence.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractShortSequence.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2020 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.ShortPrimitiveIterator;
+import org.axsl.common.sequence.ShortSequence;
+import org.axsl.common.sequence.ShortSequenceMutable;
+import org.axsl.common.sequence.ShortSequencePlus;
+
+/**
+ * Abstract superclass for implementations of {@link ShortSequencePlus}.
+ */
+public abstract class AbstractShortSequence implements ShortSequencePlus {
+
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = 2366533487441850922L;
+
+ @Override
+ public int indexOf(final short aShort) {
+ for (int index = 0; index < length(); index ++) {
+ final short foundShort = shortAt(index);
+ if (foundShort == aShort) {
+ return index;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(final short aShort) {
+ return indexOf(aShort) > -1;
+ }
+
+ @Override
+ public ShortPrimitiveIterator iterator() {
+ return new ShortSequenceIterator(this);
+ }
+
+ @Override
+ public ShortPrimitiveIterator iteratorReverse() {
+ return new ShortSequenceIterator(this, true);
+ }
+
+ @Override
+ public ShortSequencePlus asPlus() {
+ return this;
+ }
+
+ /**
+ * Provides an implementation of {@link ShortSequenceMutable} from a specified {@link ShortSequence}, recasting the
+ * specified sequence if possible, otherwise copying its content into a new mutable instance.
+ * @param shortSequence The sequence for which a mutable instance is needed.
+ * @return A mutable sequence.
+ */
+ public static ShortSequenceMutable fromShortSequence(final ShortSequence shortSequence) {
+ if (shortSequence == null) {
+ return new ShortArrayBuilder();
+ }
+ final ShortSequenceMutable mutable = shortSequence.asMutable();
+ if (mutable != null) {
+ return mutable;
+ }
+ final ShortArrayBuilder builder = new ShortArrayBuilder(shortSequence.length());
+ builder.append(shortSequence);
+ return builder;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (! (other instanceof ShortSequence)) {
+ return false;
+ }
+ final ShortSequence otherShortSequence = (ShortSequence) other;
+ if (length() != otherShortSequence.length()) {
+ return false;
+ }
+ for (int index = 0; index < length(); index ++) {
+ if (shortAt(index) != otherShortSequence.shortAt(index)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -37,6 +37,9 @@
*/
public class ByteSequenceSubset extends AbstractByteSequence {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = 6342437674139035081L;
+
/** The wrapped sequence. */
private ByteSequencePlus wrappedSequence;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -29,6 +29,7 @@
package org.foray.common.sequence;
import org.axsl.common.sequence.CharSequenceMutable;
+import org.axsl.common.sequence.IntSequence;
import java.util.Arrays;
@@ -40,6 +41,9 @@
*/
public class CharArray extends AbstractCharSequence {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -7587343160916738493L;
+
/** The internal array. */
private char[] array;
@@ -66,6 +70,26 @@
}
/**
+ * Constructor for an existing int sequence.
+ * @param sequence The sequence whose content will be the content of this.
+ * Each of the ints will be downcast to a char.
+ * This content is copied into an internal data structure to prevent it from being changed.
+ * @throws IllegalArgumentException If any values in {@code sequence} cannot be cast to a char.
+ */
+ public CharArray(final IntSequence sequence) {
+ this.array = new char[sequence.length()];
+ for (int index = 0; index < sequence.length(); index ++) {
+ final int theInt = sequence.intAt(index);
+ if (theInt < Character.MIN_VALUE
+ || theInt > Character.MAX_VALUE) {
+ throw new IllegalArgumentException(
+ String.format("Unable to cast %d to char at index %d", theInt, index));
+ }
+ this.array[index] = (char) sequence.intAt(index);
+ }
+ }
+
+ /**
* Constructor for an existing sequence.
* @param sequence The sequence whose content will be the content of this.
* This content is copied into an internal data structure to prevent it from being changed.
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -30,7 +30,6 @@
import org.axsl.common.sequence.CharSequenceMutable;
-import java.io.Serializable;
import java.util.Arrays;
/**
@@ -37,7 +36,7 @@
* A mutable array of chars that resizes itself as necessary.
* This is a subsitute for {@link StringBuilder}.
*/
-public class CharArrayBuilder extends AbstractCharSequence implements CharSequenceMutable, Serializable {
+public class CharArrayBuilder extends AbstractCharSequence implements CharSequenceMutable {
/**
* The maximum size of array to allocate (unless necessary).
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -44,6 +44,12 @@
* DEVELOPER NOTE: As methods are added to this class, please make them analogous to those in {@link String}.
**************************************************************************************************************** */
+ /** An empty int array. */
+ public static final IntArray EMPTY = new IntArray();
+
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -4297045025807702664L;
+
/** The internal array. */
private int[] array;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -42,6 +42,9 @@
*/
public class IntArrayBuilder extends AbstractIntSequence implements IntSequenceMutable {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = 8469400214536606921L;
+
/** The initial size of the array of no initial size is specified. */
private static final int DEFAULT_INITIAL_SIZE = 10;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -46,6 +46,9 @@
* DEVELOPER NOTE: As methods are added to this class, please make them analogous to those in {@link String}.
**************************************************************************************************************** */
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = 2373745313861916853L;
+
/** The internal array. */
private long[] array;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-16 18:49:02 UTC (rev 11801)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -44,6 +44,9 @@
*/
public class LongArrayBuilder extends AbstractLongSequence implements LongSequenceMutable {
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -5408291000284628952L;
+
/** The initial size of the array of no initial size is specified. */
private static final int DEFAULT_INITIAL_SIZE = 10;
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArray.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArray.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.ShortPrimitiveIterator;
+import org.axsl.common.sequence.ShortSequence;
+import org.axsl.common.sequence.ShortSequenceMutable;
+import org.axsl.common.sequence.ShortSequencePlus;
+
+import java.util.Arrays;
+
+/**
+ * Wrapper around an array of {@link Short#TYPE}s, intended to be similar in scope and purpose to what {@link String}
+ * does for an array of chars.
+ * Instances of this class are immutable.
+ */
+public class ShortArray extends AbstractShortSequence implements ShortSequencePlus {
+
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -2196475282575408782L;
+
+ /** The internal array. */
+ private short[] array;
+
+ /**
+ * Constructor for an existing array.
+ * @param array The array to be wrapped. This array is copied into an internal data structure to prevent it from
+ * being changed.
+ */
+ public ShortArray(final short... array) {
+ this.array = new short[array.length];
+ System.arraycopy(array, 0, this.array, 0, array.length);
+ }
+
+ /**
+ * Constructor for part of an existing array.
+ * @param array The array to be wrapped. This array is copied into an internal data structure to prevent it from
+ * being changed.
+ * @param start The index of the first element {@code array} to be included in this instance.
+ * @param length The number of elements in {@code array} to be included in this instance.
+ */
+ public ShortArray(final short[] array, final int start, final int length) {
+ this.array = new short[length];
+ System.arraycopy(array, start, this.array, 0, array.length);
+ }
+
+ @Override
+ public int length() {
+ return this.array.length;
+ }
+
+ @Override
+ public short shortAt(final int index) {
+ return this.array[index];
+ }
+
+ @Override
+ public ShortSequence subSequence(final int start, final int end) {
+ return new ShortArray(this.array, start, end - start);
+ }
+
+ @Override
+ public short[] toArray() {
+ /* Return a copy of the array to prevent the internal copy from changing. */
+ final short[] returnValue = new short[this.array.length];
+ System.arraycopy(this.array, 0, returnValue, 0, this.array.length);
+ return returnValue;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (! (other instanceof ShortSequence)) {
+ return false;
+ }
+ final ShortSequence otherShortSequence = (ShortSequence) other;
+ if (this.array.length != otherShortSequence.length()) {
+ return false;
+ }
+ for (int index = 0; index < this.array.length; index ++) {
+ if (shortAt(index) != otherShortSequence.shortAt(index)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(this.array);
+ }
+
+ /**
+ * Convenience method that returns the value of the last element in this array.
+ * @return The last element in this array.
+ */
+ public short lastShort() {
+ final int index = this.length() - 1;
+ return this.shortAt(index);
+ }
+
+ @Override
+ public ShortSequencePlus asPlus() {
+ return this;
+ }
+
+ @Override
+ public ShortSequenceMutable asMutable() {
+ return null;
+ }
+
+ @Override
+ public ShortPrimitiveIterator iterator() {
+ return new ShortSequenceIterator(this);
+ }
+
+ @Override
+ public ShortPrimitiveIterator iteratorReverse() {
+ return new ShortSequenceIterator(this, true);
+ }
+
+ @Override
+ public int binarySearch(final short value) {
+ return Arrays.binarySearch(this.array, value);
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2021-01-16 22:34:58 UTC (rev 11802)
@@ -0,0 +1,325 @@
+/*
+ * Copyright 2019 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.ShortSequence;
+import org.axsl.common.sequence.ShortSequenceMutable;
+
+import java.util.Arrays;
+
+/**
+ * <p>A resizable collection of primitive {@link Short#TYPE}, a subset of what is available in {@link StringBuilder},
+ * but with shorts instead of chars.</p>
+ *
+ * <p>This class can also operate as a stack of primitive shorts.
+ * The {@link #push(short)}, {@link #pop()}, and {@link #peek()} methods exist to support that use case.</p>
+ */
+public class ShortArrayBuilder extends AbstractShortSequence implements ShortSequenceMutable {
+
+ /** Constant needed for serialization. */
+ private static final long serialVersionUID = -1176730727260937528L;
+
+ /** The initial size of the array of no initial size is specified. */
+ private static final int DEFAULT_INITIAL_SIZE = 10;
+
+ /** The internal array. */
+ private short[] array;
+
+ /** The number of shorts actually used in the array. */
+ private int length;
+
+ /**
+ * Constructor.
+ * @param initialCapacity The initial size of the internal array.
+ */
+ public ShortArrayBuilder(final int initialCapacity) {
+ this.array = new short[initialCapacity];
+ }
+
+ /**
+ * No-args constructor.
+ * Creates an instance with an initial size of 10.
+ */
+ public ShortArrayBuilder() {
+ this(DEFAULT_INITIAL_SIZE);
+ }
+
+ @Override
+ public int length() {
+ return this.length;
+ }
+
+ @Override
+ public short shortAt(final int index) {
+ if ((index < 0) || (index >= this.length)) {
+ throw new IndexOutOfBoundsException("Index out of range: " + index);
+ }
+ return this.array[index];
+ }
+
+ @Override
+ public ShortSequence subSequence(final int start, final int end) {
+ if (start < 0) {
+ throw new IndexOutOfBoundsException("Index out of range: " + start);
+ }
+ if (end > this.length) {
+ throw new IndexOutOfBoundsException("Index out of range: " + end);
+ }
+ if (start > end) {
+ throw new StringIndexOutOfBoundsException("Index out of range: " + (end - start));
+ }
+ final ShortArrayBuilder returnBuilder = new ShortArrayBuilder(this.length);
+ for (int index = start; index < end; index ++) {
+ returnBuilder.append(this.array[index]);
+ }
+ return returnBuilder;
+ }
+
+ @Override
+ public short[] toArray() {
+ final short[] returnArray = new short[this.length];
+ System.arraycopy(this.array, 0, returnArray, 0, this.length);
+ return returnArray;
+ }
+
+ /**
+ * Returns the current state of the array as an (immutable) {@link ShortArray}.
+ * @return The current state of the array.
+ */
+ public ShortArray toShortArray() {
+ final short[] theArray = toArray();
+ return new ShortArray(theArray);
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(toArray());
+ }
+
+ /**
+ * Ensures that the capacity is at least equal to the specified minimum.
+ * If the current capacity is less than the argument, then a new internal array is allocated with greater capacity.
+ * The new capacity is the larger of:
+ * <ul>
+ * <li>The {@code minimumCapacity} argument.
+ * <li>Twice the old capacity, plus {@code 2}.
+ * </ul>
+ * If the {@code minimumCapacity} argument is nonpositive, this method takes no action and simply returns.
+ * @param minimumCapacity The minimum desired capacity.
+ * @see java.lang.AbstractStringBuilder#ensureCapacity(int)
+ */
+ public void ensureCapacity(final int minimumCapacity) {
+ if (minimumCapacity > this.array.length) {
+ expandCapacity(minimumCapacity);
+ }
+ }
+
+ /**
+ * Implements the expansion semantics of ensureCapacity with no size check or synchronization.
+ * @param minimumCapacity The minimum desired capacity.
+ * @see This code is based on AbstractStringBuilder.expandCapacity(int).
+ */
+ private void expandCapacity(final int minimumCapacity) {
+ int newCapacity = (this.array.length + 1) * 2;
+ if (newCapacity < 0) {
+ newCapacity = Integer.MAX_VALUE;
+ } else if (minimumCapacity > newCapacity) {
+ newCapacity = minimumCapacity;
+ }
+ this.array = Arrays.copyOf(this.array, newCapacity);
+ }
+
+ /**
+ * Append a {@link Short#TYPE} to this structure.
+ * @param shortToAppend The {@link Short#TYPE} to append.
+ * @return This object.
+ */
+ public ShortArrayBuilder append(final short shortToAppend) {
+ ensureCapacity(this.length + 1);
+ this.array[this.length] = shortToAppend;
+ this.length ++;
+ return this;
+ }
+
+ /**
+ * Append a varargs or short[] to this structure.
+ * @param shortsToAppend The shorts to append.
+ * @return This object.
+ */
+ public ShortArrayBuilder append(final short... shortsToAppend) {
+ ensureCapacity(this.length + shortsToAppend.length);
+ for (int index = 0; index < shortsToAppend.length; index ++) {
+ this.array[this.length] = shortsToAppend[index];
+ this.length ++;
+ }
+ return this;
+ }
+
+ /**
+ * Append the content of an existing sequence to this one.
+ * @param newContent The existing sequence whose content should be appended to this one.
+ * @return This object.
+ */
+ public ShortArrayBuilder append(final ShortSequence newContent) {
+ this.ensureCapacity(length() + newContent.length());
+ for (int index = 0; index < newContent.length(); index ++) {
+ this.array[this.length + index] = newContent.shortAt(index);
+ length ++;
+ }
+ return this;
+ }
+
+ /**
+ * Replaces the value at a given index with a new value.
+ * @param index The index whose value should be replaced.
+ * @param newValue The new value to place at {@code index}.
+ * @return This object.
+ * @throws IndexOutOfBoundsException If the {@code index} is negative or greater than or equal to {@link #length()}.
+ */
+ public ShortArrayBuilder replace(final int index, final short newValue) throws IndexOutOfBoundsException {
+ if ((index < 0) || (index >= this.array.length)) {
+ throw new IndexOutOfBoundsException("Index out of range: " + index);
+ }
+ this.array[index] = newValue;
+ return this;
+ }
+
+ /**
+ * Removes the value at a given index.
+ * @param index The index whose value should be deleted.
+ * @return This object.
+ * @throws IndexOutOfBoundsException If the {@code index} is negative or greater than or equal to {@link #length()}.
+ */
+ public ShortArrayBuilder deleteShortAt(final int index) throws IndexOutOfBoundsException {
+ if ((index < 0) || (index >= this.length)) {
+ throw new IndexOutOfBoundsException("Index out of range: " + index);
+ }
+ System.arraycopy(this.array, index + 1, this.array, index, this.length - index - 1);
+ this.length--;
+ return this;
+ }
+
+ /**
+ * Removes the longs in a range of this sequence.
+ * The range begins at the specified {@code start} and extends to the long at index {@code end - 1} or to the end of
+ * the sequence if no such long exists.
+ * If {@code start} is equal to {@code end}, no changes are made.
+ * @param start The beginning index, inclusive.
+ * @param end The ending index, exclusive.
+ * @return This object.
+ * @throws IndexOutOfBoundsException If {@code start} is negative, greater than {@link #length()}, or greater than
+ * {@code end}.
+ */
+ public ShortArrayBuilder delete(final int start, final int end) throws IndexOutOfBoundsException {
+ if (start < 0) {
+ throw new IndexOutOfBoundsException("Index out of range: " + start);
+ }
+ int adjustedEnd = end;
+ if (end > this.length) {
+ adjustedEnd = this.length;
+ }
+ if (start > adjustedEnd) {
+ throw new IndexOutOfBoundsException("Index out of range: " + start);
+ }
+ final int len = adjustedEnd - start;
+ if (len > 0) {
+ System.arraycopy(this.array, start + len, this.array, start, this.length - adjustedEnd);
+ this.length -= len;
+ }
+ return this;
+ }
+
+ /**
+ * Appends an item to the end of the array (pushes an item onto the stack).
+ * @param shortToPush The long to be added to the end of the array.
+ */
+ public void push(final short shortToPush) {
+ this.append(shortToPush);
+ }
+
+ /**
+ * Removes the last item in the array (the top of the stack) and returns it.
+ * @return The item that was at the top of the stack before the pop.
+ */
+ public short pop() {
+ final int index = this.length - 1;
+ final short returnValue = shortAt(index);
+ deleteShortAt(index);
+ return returnValue;
+ }
+
+ /**
+ * Returns the last item in the array (the top of the stack) without changing the array.
+ * @return The last item in the array.
+ */
+ public long peek() {
+ final int index = this.length - 1;
+ return shortAt(index);
+ }
+
+ @Override
+ public ShortSequenceMutable asMutable() {
+ return this;
+ }
+
+ @Override
+ public void setShortAt(final int index, final short newShort) {
+ this.array[index] = newShort;
+ }
+
+ @Override
+ public void sort() {
+ Arrays.sort(this.array);
+ }
+
+ @Override
+ public void swap(final int index1, final int index2) {
+ final short temp = this.array[index1];
+ this.array[index1] = this.array[index2];
+ this.array[index2] = temp;
+ }
+
+ @Override
+ public int binarySearch(final short value) {
+ return Arrays.binarySearch(this.array, 0, length(), value);
+ }
+
+ @Override
+ public int capacity() {
+ return this.array.length;
+ }
+
+ @Override
+ public void trimToSize() {
+ if (this.length < this.array.length) {
+ this.array = Arrays.copyOf(this.array, this.length);
+ }
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-16 18:49:05
|
Revision: 11801
http://sourceforge.net/p/foray/code/11801
Author: victormote
Date: 2021-01-16 18:49:02 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Conform to aXSL changes: 1. Add more primitive sequence methods. 2. Change the raw material for encoding from char[] to primitive sequences. 3. Use ints for the sequence of code points, to properly handle code points greater than the maximum char.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingParserTests.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,7 +29,9 @@
package org.foray.common.sequence;
import org.axsl.common.sequence.CharPrimitiveIterator;
+import org.axsl.common.sequence.CharSequenceMutable;
import org.axsl.common.sequence.CharSequencePlus;
+import org.axsl.common.sequence.CharSequenceUtility;
/**
* Abstract superclass for implementations of {@link CharSequencePlus}.
@@ -67,4 +69,23 @@
return this;
}
+ /**
+ * Provides an implementation of {@link CharSequenceMutable} from a specified {@link CharSequence}, recasting the
+ * specified sequence if possible, otherwise copying its content into a new mutable instance.
+ * @param charSequence The sequence for which a mutable instance is needed.
+ * @return A mutable sequence.
+ */
+ public static CharSequenceMutable fromCharSequence(final CharSequence charSequence) {
+ if (charSequence == null) {
+ return new CharArrayBuilder();
+ }
+ final CharSequenceMutable mutable = CharSequenceUtility.asMutable(charSequence);
+ if (mutable != null) {
+ return mutable;
+ }
+ final CharArrayBuilder builder = new CharArrayBuilder(charSequence.length());
+ builder.append(charSequence);
+ return builder;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,8 @@
package org.foray.common.sequence;
import org.axsl.common.sequence.IntPrimitiveIterator;
+import org.axsl.common.sequence.IntSequence;
+import org.axsl.common.sequence.IntSequenceMutable;
import org.axsl.common.sequence.IntSequencePlus;
/**
@@ -67,4 +69,23 @@
return this;
}
+ /**
+ * Provides an implementation of {@link IntSequenceMutable} from a specified {@link IntSequence}, recasting the
+ * specified sequence if possible, otherwise copying its content into a new mutable instance.
+ * @param intSequence The sequence for which a mutable instance is needed.
+ * @return A mutable sequence.
+ */
+ public static IntSequenceMutable fromIntSequence(final IntSequence intSequence) {
+ if (intSequence == null) {
+ return new IntArrayBuilder();
+ }
+ final IntSequenceMutable mutable = intSequence.asMutable();
+ if (mutable != null) {
+ return mutable;
+ }
+ final IntArrayBuilder builder = new IntArrayBuilder(intSequence.length());
+ builder.append(intSequence);
+ return builder;
+ }
+
}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractLongSequence.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2020 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.LongPrimitiveIterator;
+import org.axsl.common.sequence.LongSequence;
+import org.axsl.common.sequence.LongSequenceMutable;
+import org.axsl.common.sequence.LongSequencePlus;
+
+/**
+ * Abstract superclass for implementations of {@link LongSequencePlus}.
+ */
+public abstract class AbstractLongSequence implements LongSequencePlus {
+
+ @Override
+ public int indexOf(final long aLong) {
+ for (int index = 0; index < length(); index ++) {
+ final long foundLong = longAt(index);
+ if (foundLong == aLong) {
+ return index;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(final long aLong) {
+ return indexOf(aLong) > -1;
+ }
+
+ @Override
+ public LongPrimitiveIterator iterator() {
+ return new LongSequenceIterator(this);
+ }
+
+ @Override
+ public LongPrimitiveIterator iteratorReverse() {
+ return new LongSequenceIterator(this, true);
+ }
+
+ @Override
+ public LongSequencePlus asPlus() {
+ return this;
+ }
+
+ /**
+ * Provides an implementation of {@link LongSequenceMutable} from a specified {@link LongSequence}, recasting the
+ * specified sequence if possible, otherwise copying its content into a new mutable instance.
+ * @param longSequence The sequence for which a mutable instance is needed.
+ * @return A mutable sequence.
+ */
+ public static LongSequenceMutable fromLongSequence(final LongSequence longSequence) {
+ if (longSequence == null) {
+ return new LongArrayBuilder();
+ }
+ final LongSequenceMutable mutable = longSequence.asMutable();
+ if (mutable != null) {
+ return mutable;
+ }
+ final LongArrayBuilder builder = new LongArrayBuilder(longSequence.length());
+ builder.append(longSequence);
+ return builder;
+ }
+
+}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -65,6 +65,18 @@
System.arraycopy(array, start, this.array, 0, array.length);
}
+ /**
+ * Constructor for an existing sequence.
+ * @param sequence The sequence whose content will be the content of this.
+ * This content is copied into an internal data structure to prevent it from being changed.
+ */
+ public CharArray(final CharSequence sequence) {
+ this.array = new char[sequence.length()];
+ for (int index = 0; index < sequence.length(); index ++) {
+ this.array[index] = sequence.charAt(index);
+ }
+ }
+
@Override
public int length() {
return this.array.length;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -285,4 +285,31 @@
this.backingArray[index2] = temp;
}
+ /**
+ * Append a char to this sequence.
+ * @param charToAppend The char to append.
+ * @return This object.
+ */
+ public CharArrayBuilder append(final char charToAppend) {
+ ensureCapacity(this.nextIndex + 1);
+ this.backingArray[this.nextIndex] = charToAppend;
+ this.nextIndex ++;
+ return this;
+ }
+
+ /**
+ * Append the content of an existing sequence to this one.
+ * @param newContent The existing sequence whose content should be appended to this one.
+ * @return This object.
+ */
+ public CharArrayBuilder append(final CharSequence newContent) {
+ this.ensureCapacity(length() + newContent.length());
+ final int startingLength = this.nextIndex;
+ for (int index = 0; index < newContent.length(); index ++) {
+ this.backingArray[startingLength + index] = newContent.charAt(index);
+ this.nextIndex ++;
+ }
+ return this;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -69,6 +69,31 @@
System.arraycopy(array, start, this.array, 0, array.length);
}
+ /**
+ * Constructor for an existing array of chars.
+ * Each char in the incoming array is upcast to an int.
+ * @param array The array to be wrapped. This array is copied into an internal data structure to prevent it from
+ * being changed.
+ */
+ public IntArray(final char... array) {
+ this.array = new int[array.length];
+ for (int index = 0; index < array.length; index ++) {
+ this.array[index] = array[index];
+ }
+ }
+
+ /**
+ * Constructor for an existing sequence.
+ * @param sequence The sequence whose content will be the content of this.
+ * This content is copied into an internal data structure to prevent it from being changed.
+ */
+ public IntArray(final IntSequence sequence) {
+ this.array = new int[sequence.length()];
+ for (int index = 0; index < sequence.length(); index ++) {
+ this.array[index] = sequence.intAt(index);
+ }
+ }
+
@Override
public int length() {
return this.array.length;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -213,6 +213,21 @@
}
/**
+ * Append the content of an existing sequence to this one.
+ * @param newContent The existing sequence whose content should be appended to this one.
+ * @return This object.
+ */
+ public IntArrayBuilder append(final IntSequence newContent) {
+ this.ensureCapacity(this.length + newContent.length());
+ final int startingLength = this.length;
+ for (int index = 0; index < newContent.length(); index ++) {
+ this.array[startingLength + index] = newContent.intAt(index);
+ this.length ++;
+ }
+ return this;
+ }
+
+ /**
* Replaces the value at a given index with a new value.
* @param index The index whose value should be replaced.
* @param newValue The new value to place at {@code index}.
@@ -311,4 +326,16 @@
return Arrays.binarySearch(this.array, 0, this.length, value);
}
+ @Override
+ public int capacity() {
+ return this.array.length;
+ }
+
+ @Override
+ public void trimToSize() {
+ if (this.length < this.array.length) {
+ this.array = Arrays.copyOf(this.array, this.length);
+ }
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -40,7 +40,7 @@
* an array of chars.
* Instances of this class are immutable.
*/
-public class LongArray implements LongSequencePlus {
+public class LongArray extends AbstractLongSequence implements LongSequencePlus {
/* *****************************************************************************************************************
* DEVELOPER NOTE: As methods are added to this class, please make them analogous to those in {@link String}.
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -42,7 +42,7 @@
* <p>This class can also operate as a stack of primitive longs.
* The {@link #push(long)}, {@link #pop()}, and {@link #peek()} methods exist to support that use case.</p>
*/
-public class LongArrayBuilder implements LongSequenceMutable {
+public class LongArrayBuilder extends AbstractLongSequence implements LongSequenceMutable {
/** The initial size of the array of no initial size is specified. */
private static final int DEFAULT_INITIAL_SIZE = 10;
@@ -198,6 +198,20 @@
}
/**
+ * Append the content of an existing sequence to this one.
+ * @param newContent The existing sequence whose content should be appended to this one.
+ * @return This object.
+ */
+ public LongArrayBuilder append(final LongSequence newContent) {
+ this.ensureCapacity(length() + newContent.length());
+ for (int index = 0; index < newContent.length(); index ++) {
+ this.array[this.length + index] = newContent.longAt(index);
+ length ++;
+ }
+ return this;
+ }
+
+ /**
* Replaces the value at a given index with a new value.
* @param index The index whose value should be replaced.
* @param newValue The new value to place at {@code index}.
@@ -328,4 +342,16 @@
return Arrays.binarySearch(this.array, 0, length(), value);
}
+ @Override
+ public int capacity() {
+ return this.array.length;
+ }
+
+ @Override
+ public void trimToSize() {
+ if (this.length < this.array.length) {
+ this.array = Arrays.copyOf(this.array, this.length);
+ }
+ }
+
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsParserAfm.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,8 @@
package org.foray.font.format.type1;
import org.foray.common.io.RandomAccessInput;
+import org.foray.common.sequence.CharArrayBuilder;
+import org.foray.common.sequence.IntArrayBuilder;
import org.foray.font.FontServer4a;
import org.foray.font.format.Kerning;
@@ -520,13 +522,13 @@
* This array is created as the metrics file is parsed, and is then used
* later to create {@link #internalEncoding}.</p>
*/
- private transient char[] internalCodePoints;
+ private transient IntArrayBuilder internalCodePoints;
/**
* Array parallel to {@link #internalCodePoints} and containing the
* encoded indexes that correspond to the elements therein.
*/
- private transient char[] internalCodePointIndexes;
+ private transient CharArrayBuilder internalCodePointIndexes;
/** The number of internalCodePoint elements parsed so far. */
private transient int internalCodePointCount = 0;
@@ -1039,9 +1041,8 @@
final short[] extentTable = new short[this.qtyCharMetricsExpected];
this.metrics.setExtentTable(extentTable);
// 256 is the maximum size needed. The actual encoding may be less.
- this.internalCodePoints = new char[Type1MetricsParserAfm.MAX_CODE_POINTS];
- this.internalCodePointIndexes =
- new char[Type1MetricsParserAfm.MAX_CODE_POINTS];
+ this.internalCodePoints = new IntArrayBuilder(Type1MetricsParserAfm.MAX_CODE_POINTS);
+ this.internalCodePointIndexes = new CharArrayBuilder(Type1MetricsParserAfm.MAX_CODE_POINTS);
}
/**
@@ -1467,9 +1468,10 @@
if (this.glyphIndex > -1) {
/* Accumulate the information needed to create the internal
* Encoding. */
- this.internalCodePoints[this.internalCodePointCount] = theChar;
- this.internalCodePointIndexes[this.internalCodePointCount]
- = (char) this.glyphIndex;
+// this.internalCodePoints.setIntAt(this.internalCodePointCount, theChar);
+// this.internalCodePointIndexes.setCharAt(this.internalCodePointCount, (char) this.glyphIndex);
+ this.internalCodePoints.append(theChar);
+ this.internalCodePointIndexes.append((char) this.glyphIndex);
this.internalCodePointCount++;
}
}
@@ -1501,8 +1503,8 @@
}
/**
- * Converts the encoding and character set information for this font into an
- * encoding instance, using standard encodings if possible.
+ * Converts the encoding and character set information for this font into an encoding instance, using standard
+ * encodings if possible.
* @param psServer The PostScript server.
* @return The internal encoding for this font.
*/
@@ -1509,14 +1511,8 @@
private PsEncoding findInternalEncoding(final PsServer psServer) {
// Truncate the arrays to the right size.
if (this.internalCodePointCount < Type1MetricsParserAfm.MAX_CODE_POINTS) {
- char[] newArray = new char[this.internalCodePointCount];
- System.arraycopy(this.internalCodePoints, 0, newArray, 0,
- this.internalCodePointCount);
- this.internalCodePoints = newArray;
- newArray = new char[this.internalCodePointCount];
- System.arraycopy(this.internalCodePointIndexes, 0, newArray, 0,
- this.internalCodePointCount);
- this.internalCodePointIndexes = newArray;
+ this.internalCodePoints.trimToSize();
+ this.internalCodePointIndexes.trimToSize();
}
/* Create a tentative EncodingVector instance. */
final PsEncoding newEncoding = psServer.makeEncodingVector("internal-" + this.metrics.getPostscriptName(),
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 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -67,6 +67,7 @@
import org.foray.ps.pdf.PdfSystemDict;
import org.foray.ps.readonly.ReadOnlySystemDict;
+import org.axsl.common.sequence.IntSequence;
import org.axsl.ps.CharSet;
import org.axsl.ps.Cmap04;
import org.axsl.ps.Cmap12;
@@ -243,9 +244,9 @@
}
@Override
- public PsEncoding makeEncodingVector(final String name, final char[] codePoints,
- final char[] codePointIndexes) {
- return new EncodingCustom(name, null, codePoints, codePointIndexes, null, null);
+ public PsEncoding makeEncodingVector(final String name, final IntSequence codePoints,
+ final CharSequence codePointIndexes) {
+ return new EncodingCustom(name, null, codePoints, codePointIndexes);
}
@Override
@@ -254,7 +255,7 @@
final EncodingParser parser = new EncodingParser(inputStream, columnNum, radix, glyphLists);
parser.parseList();
final EncodingVector4a encodingVector = new EncodingCustom(name, parser.getGlyphListsToCheck(),
- parser.getCodePoints(), parser.getCodePointIndexes(), null, null);
+ parser.getCodePoints(), parser.getCodePointIndexes());
return encodingVector;
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -275,10 +278,8 @@
private Encoding4aLatinExtra() {
super(Encoding4aLatinExtra.NAME,
GlyphList4a.standardSourceGlyphLists(),
- Encoding4aLatinExtra.CODE_POINTS,
- Encoding4aLatinExtra.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(Encoding4aLatinExtra.CODE_POINTS),
+ new CharArray(Encoding4aLatinExtra.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -944,10 +947,8 @@
private EncodingCe() {
super(PsEncoding.Predefined.CE.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingCe.CODE_POINTS,
- EncodingCe.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingCe.CODE_POINTS),
+ new CharArray(EncodingCe.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,7 @@
package org.foray.ps.encode;
+import org.axsl.common.sequence.IntSequence;
import org.axsl.ps.GlyphList;
import org.axsl.ps.PsEncoding;
@@ -54,17 +55,10 @@
* This can be null.
* {@code codePointIndexes[n]} should contain the encoded index that corresponds to the Unicode code point at
* {@code codePoints[n]}.
- * @param codePoints2 The array of Unicode code points greater than {@link Character#MAX_VALUE} supported by this
- * encoding.
- * This can be null.
- * @param codePointIndexes2 The array of encoded indexes that is parallel to {@code codePoints2}.
- * This can be null.
- * {@code codePointIndexes2[n]} should contain the encoded index that corresponds to the Unicode code point at
- * {@code codePoints2[n]}.
*/
- public EncodingCustom(final String name, final List<GlyphList> sourceGlyphLists, final char[] codePoints,
- final char[] codePointIndexes, final int[] codePoints2, final char[] codePointIndexes2) {
- super(name, sourceGlyphLists, codePoints, codePointIndexes, codePoints2, codePointIndexes2);
+ public EncodingCustom(final String name, final List<GlyphList> sourceGlyphLists, final IntSequence codePoints,
+ final CharSequence codePointIndexes) {
+ super(name, sourceGlyphLists, codePoints, codePointIndexes);
}
@Override
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -743,10 +746,8 @@
private EncodingExpert() {
super(PsEncoding.Predefined.EXPERT.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingExpert.CODE_POINTS,
- EncodingExpert.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingExpert.CODE_POINTS),
+ new CharArray(EncodingExpert.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -428,10 +431,8 @@
private EncodingExpertSubset() {
super(PsEncoding.Predefined.EXPERT_SUBSET.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingExpertSubset.CODE_POINTS,
- EncodingExpertSubset.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingExpertSubset.CODE_POINTS),
+ new CharArray(EncodingExpertSubset.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -883,10 +886,8 @@
private EncodingIsoLatin1() {
super(PsEncoding.Predefined.ISO_LATIN_1.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingIsoLatin1.CODE_POINTS,
- EncodingIsoLatin1.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingIsoLatin1.CODE_POINTS),
+ new CharArray(EncodingIsoLatin1.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -743,10 +746,8 @@
private EncodingMacExpert() {
super(PsEncoding.Predefined.MAC_EXPERT.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingMacExpert.CODE_POINTS,
- EncodingMacExpert.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingMacExpert.CODE_POINTS),
+ new CharArray(EncodingMacExpert.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -911,10 +914,8 @@
private EncodingMacRoman() {
super(PsEncoding.Predefined.MAC_ROMAN.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingMacRoman.CODE_POINTS,
- EncodingMacRoman.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingMacRoman.CODE_POINTS),
+ new CharArray(EncodingMacRoman.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -1122,10 +1125,8 @@
private EncodingMacStandard() {
super(PsEncoding.Predefined.STANDARD_MACINTOSH_ORDERING.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingMacStandard.CODE_POINTS,
- EncodingMacStandard.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingMacStandard.CODE_POINTS),
+ new CharArray(EncodingMacStandard.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingParser.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -31,8 +31,12 @@
import org.foray.common.WellKnownConstants;
import org.foray.common.primitive.CharacterUtils;
import org.foray.common.primitive.StringUtils;
+import org.foray.common.sequence.CharArrayBuilder;
+import org.foray.common.sequence.IntArrayBuilder;
import org.foray.common.url.UrlFactory;
+import org.axsl.common.sequence.CharSequenceMutable;
+import org.axsl.common.sequence.IntSequenceMutable;
import org.axsl.ps.GlyphList;
import org.axsl.ps.PsException;
@@ -150,10 +154,10 @@
private List<Character> glyphIndexes = new ArrayList<Character>();
/** The parsed Unicode codepoints. */
- private List<Character> codePoints = new ArrayList<Character>();
+ private IntArrayBuilder codePoints = new IntArrayBuilder();
/** The parsed encoded indexes. */
- private List<Character> codePointIndexes = new ArrayList<Character>();
+ private CharArrayBuilder codePointIndexes = new CharArrayBuilder();
/**
* Create a new EncodingParser instance.
@@ -263,8 +267,8 @@
private void processCurrentLine(final String line, final int arrayIndex) throws PsException {
this.glyphNames.add(StringUtils.EMPTY_STRING);
this.glyphIndexes.add(Character.MIN_VALUE);
- this.codePoints.add(Character.MIN_VALUE);
- this.codePointIndexes.add(Character.MIN_VALUE);
+ this.codePoints.append(Integer.MIN_VALUE);
+ this.codePointIndexes.append(Character.MIN_VALUE);
final String[] tokens = tokenizeLine(line);
this.glyphNames.set(arrayIndex, tokens[0]);
@@ -347,13 +351,13 @@
final char codePoint = glyphList.mapGlyphNameToCodePoint(
glyphName);
if (codePoint != Character.MAX_VALUE) {
- this.codePoints.set(i, codePoint);
+ this.codePoints.setIntAt(i, codePoint);
final char glyphIndex = this.glyphIndexes.get(i);
- this.codePointIndexes.set(i, glyphIndex);
+ this.codePointIndexes.setCharAt(i, glyphIndex);
break;
}
}
- if (this.codePointIndexes.get(i) == 0
+ if (this.codePointIndexes.charAt(i) == 0
&& ! glyphName.equals(EncodingVector4a.NOTDEF)) {
throw new PsException("Glyph name not found: " + glyphName);
}
@@ -441,23 +445,21 @@
out.write(s.getBytes());
s = " public static final char[] codePoints = {\n";
out.write(s.getBytes());
- for (int i = 0; i < this.codePoints.size(); i++) {
- final char index = this.codePoints.get(i);
+ for (int i = 0; i < this.codePoints.length(); i++) {
+ final int index = this.codePoints.intAt(i);
s = " ";
s = s + "0x";
- s = s + StringUtils.charToHexString(index, true,
- EncodingParser.HEX_STRING_SIZE);
- if (i < this.codePoints.size() - 1) {
+ s = s + StringUtils.charToHexString((char) index, true, EncodingParser.HEX_STRING_SIZE);
+ if (i < this.codePoints.length() - 1) {
s = s + ",";
}
s = padSpaces(s, EncodingParser.CODE_POINTS_COLUMN_1, 2);
s = s + "// " + formatArrayIndex(i);
s = padSpaces(s, EncodingParser.CODE_POINTS_COLUMN_2, 2);
- s = s + " glyph: 0x" + StringUtils.charToHexString(
- this.codePointIndexes.get(i), true,
+ s = s + " glyph: 0x" + StringUtils.charToHexString(this.codePointIndexes.charAt(i), true,
EncodingParser.HEX_STRING_SIZE);
- s = s + " \\" + StringUtils.charToOctalString(
- this.codePointIndexes.get(i), EncodingParser.HEX_STRING_SIZE);
+ s = s + " \\" + StringUtils.charToOctalString(this.codePointIndexes.charAt(i),
+ EncodingParser.HEX_STRING_SIZE);
s = s + "\n";
out.write(s.getBytes());
}
@@ -469,13 +471,12 @@
out.write(s.getBytes());
s = " public static final char[] codePointIndexes = {\n";
out.write(s.getBytes());
- for (int i = 0; i < this.codePointIndexes.size(); i++) {
- final char index = this.codePointIndexes.get(i);
+ for (int i = 0; i < this.codePointIndexes.length(); i++) {
+ final char index = this.codePointIndexes.charAt(i);
s = " ";
s = s + "0x";
- s = s + StringUtils.charToHexString(index, true,
- EncodingParser.HEX_STRING_SIZE);
- if (i < this.codePointIndexes.size() - 1) {
+ s = s + StringUtils.charToHexString((char) index, true, EncodingParser.HEX_STRING_SIZE);
+ if (i < this.codePointIndexes.length() - 1) {
s = s + ",";
}
s = padSpaces(s, EncodingParser.CODE_POINTS_INDEX_1, 2);
@@ -522,8 +523,8 @@
* Returns the codepoint indexes.
* @return The codepoint indexes.
*/
- public char[] getCodePointIndexes() {
- return CharacterUtils.toArray(this.codePointIndexes);
+ public CharSequenceMutable getCodePointIndexes() {
+ return this.codePointIndexes;
}
/**
@@ -530,8 +531,8 @@
* Returns the codepoints.
* @return The codepoints.
*/
- public char[] getCodePoints() {
- return CharacterUtils.toArray(this.codePoints);
+ public IntSequenceMutable getCodePoints() {
+ return this.codePoints;
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -999,10 +1002,8 @@
private EncodingPdfDoc() {
super(PsEncoding.Predefined.PDF_DOC.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingPdfDoc.CODE_POINTS,
- EncodingPdfDoc.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingPdfDoc.CODE_POINTS),
+ new CharArray(EncodingPdfDoc.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -682,10 +685,8 @@
private EncodingStandard() {
super(PsEncoding.Predefined.STANDARD.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingStandard.CODE_POINTS,
- EncodingStandard.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingStandard.CODE_POINTS),
+ new CharArray(EncodingStandard.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -847,10 +850,8 @@
private EncodingSymbol() {
super(PsEncoding.Predefined.SYMBOL.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingSymbol.CODE_POINTS,
- EncodingSymbol.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingSymbol.CODE_POINTS),
+ new CharArray(EncodingSymbol.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,8 +29,13 @@
package org.foray.ps.encode;
import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.CharArrayBuilder;
import org.foray.common.sequence.IntArray;
+import org.foray.common.sequence.IntArrayBuilder;
+import org.axsl.common.sequence.CharSequenceMutable;
+import org.axsl.common.sequence.IntSequence;
+import org.axsl.common.sequence.IntSequenceMutable;
import org.axsl.ps.Encoding;
import org.axsl.ps.GlyphList;
import org.axsl.ps.PsEncoding;
@@ -79,45 +84,46 @@
* @param sourceGlyphLists The GlyphList instances that were used to create this encoding.
* @param codePoints The array of Unicode code points less than {@link Character#MAX_VALUE} supported by this
* encoding.
- * This can be null.
* @param codePointIndexes The array of encoded indexes that is parallel to {@code codePoints}.
- * This can be null.
* {@code codePointIndexes[n]} should contain the encoded index that corresponds to the Unicode code point at
* {@code codePoints[n]}.
- * @param codePoints2 The array of Unicode code points greaters than {@link Character#MAX_VALUE} supported by this
- * encoding.
- * This can be null.
- * @param codePointIndexes2 The array of encoded indexes that is parallel to {@code codePoints2}.
- * This can be null.
- * {@code codePointIndexes2[n]} should contain the encoded index that corresponds to the Unicode code point at
- * {@code codePoints2[n]}.
*/
- public EncodingVector4a(final String name, final List<GlyphList> sourceGlyphLists,
- final char[] codePoints, final char[] codePointIndexes, final int[] codePoints2,
- final char[] codePointIndexes2) {
+ public EncodingVector4a(final String name, final List<GlyphList> sourceGlyphLists, final IntSequence codePoints,
+ final CharSequence codePointIndexes) {
this.name = name;
this.sourceGlyphLists = sourceGlyphLists;
- /* Normalize the input. */
- final char[] tempCodePoints = codePoints == null ? new char[0] : codePoints;
- final char[] tempCodePointIndexes = codePointIndexes == null ? new char[0] : codePointIndexes;
- final int[] tempCodePoints2 = codePoints2 == null ? new int[0] : codePoints2;
- final char[] tempCodePointIndexes2 = codePointIndexes2 == null ? new char[0] : codePointIndexes2;
+ /* Get mutable instances. */
+ final IntSequenceMutable tempCodePoints = IntArrayBuilder.fromIntSequence(codePoints);
+ final CharSequenceMutable tempCodePointIndexes = CharArrayBuilder.fromCharSequence(codePointIndexes);
- if (tempCodePoints.length != tempCodePointIndexes.length) {
+ if (tempCodePoints.length() != tempCodePointIndexes.length()) {
throw new IllegalArgumentException("codePoints and codePointIndexes must be of the same length.");
}
- if (tempCodePoints2.length != tempCodePointIndexes2.length) {
- throw new IllegalArgumentException("codePoints2 and codePointIndexes2 must be of the same length.");
- }
sortCodePoints(tempCodePoints, tempCodePointIndexes);
- sortCodePoints(tempCodePoints2, tempCodePointIndexes2);
- this.codePoints = new CharArray(tempCodePoints);
- this.codePointIndexes = new CharArray(tempCodePointIndexes);
- this.codePoints2 = new IntArray(tempCodePoints2);
- this.codePointIndexes2 = new CharArray(tempCodePointIndexes2);
+ final CharArrayBuilder codePointsBuilder = new CharArrayBuilder();
+ final CharArrayBuilder codePointIndexesBuilder = new CharArrayBuilder();
+ final IntArrayBuilder codePoints2Builder = new IntArrayBuilder();
+ final CharArrayBuilder codePointIndexes2Builder = new CharArrayBuilder();
+
+ for (int index = 0; index < tempCodePoints.length(); index ++) {
+ final int codePoint = tempCodePoints.intAt(index);
+ final char codePointIndex = tempCodePointIndexes.charAt(index);
+ if (codePoint > Character.MAX_VALUE) {
+ codePoints2Builder.append(codePoint);
+ codePointIndexes2Builder.append(codePointIndex);
+ } else {
+ codePointsBuilder.append((char) codePoint);
+ codePointIndexesBuilder.append(codePointIndex);
+ }
+ }
+
+ this.codePoints = new CharArray(codePointsBuilder);
+ this.codePointIndexes = new CharArray(codePointIndexesBuilder);
+ this.codePoints2 = new IntArray(codePoints2Builder);
+ this.codePointIndexes2 = new CharArray(codePointIndexes2Builder);
}
@Override
@@ -230,19 +236,15 @@
* @param codePoints The array of Unicode code points to be sorted.
* @param codePointIndexes The array of encoding indexes that whose elements correspond to elements in codePoints.
*/
- public void sortCodePoints(final char[] codePoints, final char[] codePointIndexes) {
+ public void sortCodePoints(final IntSequenceMutable codePoints, final CharSequenceMutable codePointIndexes) {
boolean anyChanges = true;
while (anyChanges) {
anyChanges = false;
- for (int i = 0; i < codePoints.length - 1; i++) {
- if (codePoints[i] > codePoints[i + 1]) {
+ for (int i = 0; i < codePoints.length() - 1; i++) {
+ if (codePoints.intAt(i) > codePoints.intAt(i + 1)) {
/* They are out of order. Switch corresponding elements in both arrays.*/
- char saveChar = codePoints[i];
- codePoints[i] = codePoints[i + 1];
- codePoints[i + 1] = saveChar;
- saveChar = codePointIndexes[i];
- codePointIndexes[i] = codePointIndexes[i + 1];
- codePointIndexes[i + 1] = saveChar;
+ codePoints.swap(i, i + 1);
+ codePointIndexes.swap(i, i + 1);
anyChanges = true;
}
}
@@ -249,30 +251,6 @@
}
}
- /**
- * Sorts the codePoints array by its contents, and sorts the parallel codePointIndexes arrays in a parallel manner,
- * keeping its elements synchronized with those in codePoints.
- * @param codePoints The array of Unicode code points to be sorted.
- * @param codePointIndexes The array of encoding indexes that whose elements correspond to elements in codePoints.
- */
- public void sortCodePoints(final int[] codePoints, final char[] codePointIndexes) {
- boolean anyChanges = true;
- while (anyChanges) {
- anyChanges = false;
- for (int i = 0; i < codePoints.length - 1; i++) {
- if (codePoints[i] > codePoints[i + 1]) {
- /* They are out of order. Switch corresponding elements in both arrays.*/
- final int saveInt = codePoints[i];
- codePoints[i] = codePoints[i + 1];
- codePoints[i + 1] = saveInt;
- final char saveChar = codePointIndexes[i];
- codePointIndexes[i] = codePointIndexes[i + 1];
- codePointIndexes[i + 1] = saveChar;
- anyChanges = true;
- }
- }
- }
- }
@Override
public String asPostScript(final org.axsl.ps.Encoding baseEncoding) {
/* TODO: The baseEncoding is ignored for now. We need to consider it. */
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.PsEncoding;
import java.io.Serializable;
@@ -947,10 +950,8 @@
private EncodingWinAnsi() {
super(PsEncoding.Predefined.WIN_ANSI.getName(),
GlyphList4a.standardSourceGlyphLists(),
- EncodingWinAnsi.CODE_POINTS,
- EncodingWinAnsi.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingWinAnsi.CODE_POINTS),
+ new CharArray(EncodingWinAnsi.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -29,6 +29,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.GlyphList;
import org.axsl.ps.PsEncoding;
@@ -910,10 +913,8 @@
private EncodingZapfDingbats() {
super(PsEncoding.Predefined.ZAPF_DINGBATS.getName(),
EncodingZapfDingbats.GLYPH_LISTS_USED,
- EncodingZapfDingbats.CODE_POINTS,
- EncodingZapfDingbats.CODE_POINT_INDEXES,
- null,
- null);
+ new IntArray(EncodingZapfDingbats.CODE_POINTS),
+ new CharArray(EncodingZapfDingbats.CODE_POINT_INDEXES));
}
/**
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingParserTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingParserTests.java 2021-01-16 14:37:36 UTC (rev 11800)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingParserTests.java 2021-01-16 18:49:02 UTC (rev 11801)
@@ -65,8 +65,8 @@
* WinAnsi column, there are 13 unencoded characters. 237 - 8 - 13 = 216. */
Assert.assertEquals(216, parser.getGlyphNames().length);
Assert.assertEquals(216, parser.getGlyphIndexes().length);
- Assert.assertEquals(216, parser.getCodePoints().length);
- Assert.assertEquals(216, parser.getCodePointIndexes().length);
+ Assert.assertEquals(216, parser.getCodePoints().length());
+ Assert.assertEquals(216, parser.getCodePointIndexes().length());
/* Test the first item, as sorted in glyph name order. */
Assert.assertEquals("A", parser.getGlyphNames()[0]);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-16 14:37:38
|
Revision: 11800
http://sourceforge.net/p/foray/code/11800
Author: victormote
Date: 2021-01-16 14:37:36 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
1. Handle encodings with code points > the max char size. 2. Convert encoding internal structure to use sequences instead of raw arrays.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractCharSequence.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2020 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.CharPrimitiveIterator;
+import org.axsl.common.sequence.CharSequencePlus;
+
+/**
+ * Abstract superclass for implementations of {@link CharSequencePlus}.
+ */
+public abstract class AbstractCharSequence implements CharSequencePlus {
+
+ @Override
+ public int indexOf(final char aChar) {
+ for (int index = 0; index < length(); index ++) {
+ final int foundChar = charAt(index);
+ if (foundChar == aChar) {
+ return index;
+ }
+ }
+ return -1;
+ }
+
+ @Override
+ public boolean contains(final char theInt) {
+ return indexOf(theInt) > -1;
+ }
+
+ @Override
+ public CharPrimitiveIterator iterator() {
+ return new CharSequenceIterator(this);
+ }
+
+ @Override
+ public CharPrimitiveIterator iteratorReverse() {
+ return new CharSequenceIterator(this, true);
+ }
+
+ @Override
+ public CharSequencePlus asPlus() {
+ return this;
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArray.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2019 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.CharSequenceMutable;
+
+import java.util.Arrays;
+
+/**
+ * Wrapper around an array of {@link Character#TYPE}s.
+ * Similar to {@link String}, but with the purpose of explicitly storing arrays of {@link Character#TYPE} as numeric
+ * values instead of as characters.
+ * Like {@link String}, instances of this class are immutable.
+ */
+public class CharArray extends AbstractCharSequence {
+
+ /** The internal array. */
+ private char[] array;
+
+ /**
+ * Constructor for an existing array.
+ * @param array The array to be wrapped. This array is copied into an internal data structure to prevent it from
+ * being changed.
+ */
+ public CharArray(final char... array) {
+ this.array = new char[array.length];
+ System.arraycopy(array, 0, this.array, 0, array.length);
+ }
+
+ /**
+ * Constructor for part of an existing array.
+ * @param array The array to be wrapped. This array is copied into an internal data structure to prevent it from
+ * being changed.
+ * @param start The index of the first element {@code array} to be included in this instance.
+ * @param length The number of elements in {@code array} to be included in this instance.
+ */
+ public CharArray(final char[] array, final int start, final int length) {
+ this.array = new char[length];
+ System.arraycopy(array, start, this.array, 0, array.length);
+ }
+
+ @Override
+ public int length() {
+ return this.array.length;
+ }
+
+ @Override
+ public char charAt(final int index) {
+ return this.array[index];
+ }
+
+ @Override
+ public CharSequence subSequence(final int start, final int end) {
+ return new CharArray(this.array, start, end - start);
+ }
+
+ @Override
+ public char[] toArray() {
+ /* Return a copy of the array to prevent the internal copy from changing. */
+ final char[] returnValue = new char[this.array.length];
+ System.arraycopy(this.array, 0, returnValue, 0, this.array.length);
+ return returnValue;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (! (other instanceof CharSequence)) {
+ return false;
+ }
+ final CharSequence otherCharSequence = (CharSequence) other;
+ if (this.array.length != otherCharSequence.length()) {
+ return false;
+ }
+ for (int index = 0; index < this.array.length; index ++) {
+ if (charAt(index) != otherCharSequence.charAt(index)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return Arrays.toString(this.array);
+ }
+
+ @Override
+ public CharSequenceMutable asMutable() {
+ return null;
+ }
+
+ @Override
+ public int binarySearch(final char value) {
+ return Arrays.binarySearch(this.array, value);
+ }
+
+ @Override
+ public char lastChar() {
+ final int index = this.length() - 1;
+ return this.charAt(index);
+ }
+
+}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -28,9 +28,7 @@
package org.foray.common.sequence;
-import org.axsl.common.sequence.CharPrimitiveIterator;
import org.axsl.common.sequence.CharSequenceMutable;
-import org.axsl.common.sequence.CharSequencePlus;
import java.io.Serializable;
import java.util.Arrays;
@@ -39,7 +37,7 @@
* A mutable array of chars that resizes itself as necessary.
* This is a subsitute for {@link StringBuilder}.
*/
-public class CharArrayBuilder implements CharSequenceMutable, Serializable {
+public class CharArrayBuilder extends AbstractCharSequence implements CharSequenceMutable, Serializable {
/**
* The maximum size of array to allocate (unless necessary).
@@ -255,12 +253,6 @@
}
@Override
- public boolean contains(final char testChar) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
public char charAt(final int index) {
if ((index < 0) || (index >= this.nextIndex)) {
throw new IndexOutOfBoundsException("Index out of bounds: " + index);
@@ -282,26 +274,11 @@
}
@Override
- public CharSequencePlus asPlus() {
- return this;
- }
-
- @Override
public CharSequenceMutable asMutable() {
return this;
}
@Override
- public CharPrimitiveIterator iterator() {
- return new CharSequenceIterator(this);
- }
-
- @Override
- public CharPrimitiveIterator iteratorReverse() {
- return new CharSequenceIterator(this, true);
- }
-
- @Override
public void swap(final int index1, final int index2) {
final char temp = this.backingArray[index1];
this.backingArray[index1] = this.backingArray[index2];
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 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/PsServer4a.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -245,7 +245,7 @@
@Override
public PsEncoding makeEncodingVector(final String name, final char[] codePoints,
final char[] codePointIndexes) {
- return new EncodingCustom(name, null, codePoints, codePointIndexes);
+ return new EncodingCustom(name, null, codePoints, codePointIndexes, null, null);
}
@Override
@@ -254,7 +254,7 @@
final EncodingParser parser = new EncodingParser(inputStream, columnNum, radix, glyphLists);
parser.parseList();
final EncodingVector4a encodingVector = new EncodingCustom(name, parser.getGlyphListsToCheck(),
- parser.getCodePoints(), parser.getCodePointIndexes());
+ parser.getCodePoints(), parser.getCodePointIndexes(), null, null);
return encodingVector;
}
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Encoding4aLatinExtra.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -34,18 +34,14 @@
import java.io.Serializable;
/**
- * Class containing hard-coded values that represent the FOrayLatinExtra
- * Encoding Vector.
- * This Encoding is intended to be used in conjuction with the WinAnsiEncoding.
- * It is totally fabricated by FOray and is intended to handle glyphs that
- * commonly appear in Latin fonts, but which are not included in the
- * WinAnsiEncoding.
- * Its main purpose is to prevent the needless proliferation and duplication
- * of custom encodings.
+ * Class containing hard-coded values that represent the FOrayLatinExtra Encoding Vector.
+ * This Encoding is intended to be used in conjuction with the {@link EncodingWinAnsi}.
+ * It is totally fabricated by FOray and is intended to handle glyphs that commonly appear in Latin fonts, but which are
+ * not included in the WinAnsiEncoding.
+ * Its main purpose is to prevent the needless proliferation and duplication of custom encodings.
*
- * <p>The hard-coded values in this class were derived by running
- * {@link EncodingParser#main(String[])} with the following input
- * parameters:</p>
+ * <p>The hard-coded values in this class were derived by running {@link EncodingParser#main(String[])} with the
+ * following input parameters:</p>
* <ol>
* <li>input-file: foray/foray-ps/resource/encoding/foray-latin-extra.txt</li>
* <li>column-number: 1</li>
@@ -273,15 +269,16 @@
private static Encoding4aLatinExtra theInstance;
/**
- * Private Constructor. This class is a singleton and should be instantiated
- * only internally.
- * To obtain the singleton instance of this class, use
- * {@link #getInstance()}.
+ * Private Constructor. This class is a singleton and should be instantiated only internally.
+ * To obtain the singleton instance of this class, use {@link #getInstance()}.
*/
private Encoding4aLatinExtra() {
- super(Encoding4aLatinExtra.NAME, GlyphList4a.standardSourceGlyphLists(),
+ super(Encoding4aLatinExtra.NAME,
+ GlyphList4a.standardSourceGlyphLists(),
Encoding4aLatinExtra.CODE_POINTS,
- Encoding4aLatinExtra.CODE_POINT_INDEXES);
+ Encoding4aLatinExtra.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCe.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -942,9 +942,12 @@
* {@link #getInstance()}.
*/
private EncodingCe() {
- super(PsEncoding.Predefined.CE.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.CE.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingCe.CODE_POINTS,
- EncodingCe.CODE_POINT_INDEXES);
+ EncodingCe.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingCustom.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -45,22 +45,26 @@
/**
* Create a new Encoding instance.
- * @param name The name of this encoding. This name is not used by the
- * system, but may be useful for debugging.
- * @param sourceGlyphLists The GlyphList instances that were used to create
- * this encoding.
- * @param codePoints The array of Unicode code points supported by this
- * encoding. This array <em>must </em> be sorted before this constructor
- * is used.
- * The static method {@link #sortCodePoints(char[], char[])} is provided
- * for this purpose.
- * @param codePointIndexes The array of encoded indexes that is parallel to
- * codePoints. codePointIndexes[n] should contain the encoded index that
- * corresponds to the Unicode code point at codePoints[n].
+ * @param name The name of this encoding. This name is not used by the system, but may be useful for debugging.
+ * @param sourceGlyphLists The GlyphList instances that were used to create this encoding.
+ * @param codePoints The array of Unicode code points less than {@link Character#MAX_VALUE} supported by this
+ * encoding.
+ * This array will be sorted by the superclass constructor.
+ * @param codePointIndexes The array of encoded indexes that is parallel to {@code codePoints}.
+ * This can be null.
+ * {@code codePointIndexes[n]} should contain the encoded index that corresponds to the Unicode code point at
+ * {@code codePoints[n]}.
+ * @param codePoints2 The array of Unicode code points greater than {@link Character#MAX_VALUE} supported by this
+ * encoding.
+ * This can be null.
+ * @param codePointIndexes2 The array of encoded indexes that is parallel to {@code codePoints2}.
+ * This can be null.
+ * {@code codePointIndexes2[n]} should contain the encoded index that corresponds to the Unicode code point at
+ * {@code codePoints2[n]}.
*/
- public EncodingCustom(final String name, final List<GlyphList> sourceGlyphLists,
- final char[] codePoints, final char[] codePointIndexes) {
- super(name, sourceGlyphLists, codePoints, codePointIndexes);
+ public EncodingCustom(final String name, final List<GlyphList> sourceGlyphLists, final char[] codePoints,
+ final char[] codePointIndexes, final int[] codePoints2, final char[] codePointIndexes2) {
+ super(name, sourceGlyphLists, codePoints, codePointIndexes, codePoints2, codePointIndexes2);
}
@Override
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpert.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -741,9 +741,12 @@
* {@link #getInstance()}.
*/
private EncodingExpert() {
- super(PsEncoding.Predefined.EXPERT.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.EXPERT.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingExpert.CODE_POINTS,
- EncodingExpert.CODE_POINT_INDEXES);
+ EncodingExpert.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingExpertSubset.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -426,9 +426,12 @@
* {@link #getInstance()}.
*/
private EncodingExpertSubset() {
- super(PsEncoding.Predefined.EXPERT_SUBSET.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.EXPERT_SUBSET.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingExpertSubset.CODE_POINTS,
- EncodingExpertSubset.CODE_POINT_INDEXES);
+ EncodingExpertSubset.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingIsoLatin1.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -881,9 +881,12 @@
* {@link #getInstance()}.
*/
private EncodingIsoLatin1() {
- super(PsEncoding.Predefined.ISO_LATIN_1.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.ISO_LATIN_1.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingIsoLatin1.CODE_POINTS,
- EncodingIsoLatin1.CODE_POINT_INDEXES);
+ EncodingIsoLatin1.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacExpert.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -741,9 +741,12 @@
* {@link #getInstance()}.
*/
private EncodingMacExpert() {
- super(PsEncoding.Predefined.MAC_EXPERT.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.MAC_EXPERT.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingMacExpert.CODE_POINTS,
- EncodingMacExpert.CODE_POINT_INDEXES);
+ EncodingMacExpert.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacRoman.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -909,9 +909,12 @@
* {@link #getInstance()}.
*/
private EncodingMacRoman() {
- super(PsEncoding.Predefined.MAC_ROMAN.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.MAC_ROMAN.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingMacRoman.CODE_POINTS,
- EncodingMacRoman.CODE_POINT_INDEXES);
+ EncodingMacRoman.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingMacStandard.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -1120,8 +1120,12 @@
* {@link #getInstance()}.
*/
private EncodingMacStandard() {
- super(PsEncoding.Predefined.STANDARD_MACINTOSH_ORDERING.getName(), GlyphList4a.standardSourceGlyphLists(),
- EncodingMacStandard.CODE_POINTS, EncodingMacStandard.CODE_POINT_INDEXES);
+ super(PsEncoding.Predefined.STANDARD_MACINTOSH_ORDERING.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
+ EncodingMacStandard.CODE_POINTS,
+ EncodingMacStandard.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -997,9 +997,12 @@
* {@link #getInstance()}.
*/
private EncodingPdfDoc() {
- super(PsEncoding.Predefined.PDF_DOC.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.PDF_DOC.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingPdfDoc.CODE_POINTS,
- EncodingPdfDoc.CODE_POINT_INDEXES);
+ EncodingPdfDoc.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingStandard.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -680,9 +680,12 @@
* {@link #getInstance()}.
*/
private EncodingStandard() {
- super(PsEncoding.Predefined.STANDARD.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.STANDARD.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingStandard.CODE_POINTS,
- EncodingStandard.CODE_POINT_INDEXES);
+ EncodingStandard.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingSymbol.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -845,9 +845,12 @@
* {@link #getInstance()}.
*/
private EncodingSymbol() {
- super(PsEncoding.Predefined.SYMBOL.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.SYMBOL.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingSymbol.CODE_POINTS,
- EncodingSymbol.CODE_POINT_INDEXES);
+ EncodingSymbol.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingVector4a.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -28,6 +28,9 @@
package org.foray.ps.encode;
+import org.foray.common.sequence.CharArray;
+import org.foray.common.sequence.IntArray;
+
import org.axsl.ps.Encoding;
import org.axsl.ps.GlyphList;
import org.axsl.ps.PsEncoding;
@@ -36,53 +39,10 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.util.Arrays;
import java.util.List;
/**
- * <p>Encoding instances provide some standard encoding resources for
- * PostScript.
- * When a PostScript file is parsed, the characters in a string are really
- * indices into an array of glyph names, which are in turn the keys to entries
- * in a glyph dictionary.
- * Input to a PostScript interpreter is not really characters, but rather
- * character indexes.
- * (The two might be the same, especially for ASCII characters).</p>
- *
- * <p>So the PostScript interpreter uses a two-step process, as follows:
- * 1. It conceptually maps character codes (integer values) to name objects
- * like /A or /Uacute. This map is known as an "encoding".
- * There are several standard encoding schemes defined in the PostScript
- * standard that each interpreter must know how to handle. Those are provided
- * as Encoding subclasses.
- * 2. The name objects created in step 1 are then used as the key into a
- * dictionary (contained in the Font dictionary) whose values contain the
- * PostScript instructions needed to actually paint the glyph.</p>
- *
- * <p>Nowhere in the above scheme is Unicode encoding contemplated or supported.
- * Applications that <em>create </em> PostScript output from Unicode input need
- * a way to convert from that Unicode input to the indexes that are expected
- * for by the selected encoding.
- * The closest resource that we have for this purpose is the standard glyph
- * lists supplied by Adobe.</p>
- *
- * <p>The canonical method for mapping a Unicode code point to a PostScript
- * encoding index would be:</p>
- * <ol>
- * <li>Use the Adobe Glyph List (or another glyph list) to obtain the glyph name for a given Unicode
- * code point.</li>
- * <li>Use an Encoding instance to obtain the index in that Encoding for the
- * glyph name obtained above.</li>
- * </ol>
- *
- * <p>However, for efficiency, an Encoding combines the above two steps and
- * provides a direct mapping from a Unicode code point to the encoded index.
- * Two parallel arrays are used to make this process efficient.
- * The first is a an array of all Unicode code points supported in the Encoding.
- * This array is sorted for fast searching.
- * The second array provides the encoded index for the Unicode code point in
- * the first array.
- * Methods are provided to encode and decode characters.</p>
+ * Abstract superclass for implementations of {@link PsEncoding}.
*/
public abstract class EncodingVector4a implements PsEncoding, Serializable {
@@ -98,30 +58,66 @@
/** The GlyphList instances, in order, which were used to create this encoding. */
private transient List<GlyphList> sourceGlyphLists;
- /** Array of Unicode code points, sorted. Elements in this array are keys
- * to elements in {@link #codePointIndexes}. */
- private transient char[] codePoints;
+ /** Array of Unicode code points that are less than {@link Character#MAX_VALUE}, sorted.
+ * Elements in this array are keys to elements in {@link #codePointIndexes}. */
+ private transient CharArray codePoints;
- /** Array of encoded indexes for the glyphs that correspond to elements
- * in {@link #codePoints}. */
- private transient char[] codePointIndexes;
+ /** Array of encoded indexes for the glyphs that correspond to elements in {@link #codePoints}. */
+ private transient CharArray codePointIndexes;
+ /** Array of Unicode code points that are greater than {@link Character#MAX_VALUE}, sorted.
+ * Elements in this array are keys to elements in {@link #codePointIndexes2}. */
+ private transient IntArray codePoints2;
+
+ /** Array of encoded indexes for the glyphs that correspond to elements in {@link #codePoints2}. */
+ private transient CharArray codePointIndexes2;
+
/**
* Create a new Encoding instance.
* @param name The name of this encoding.
* This name is not used by the system, but may be useful for debugging.
* @param sourceGlyphLists The GlyphList instances that were used to create this encoding.
- * @param codePoints The array of Unicode code points supported by this encoding.
- * @param codePointIndexes The array of encoded indexes that is parallel to codePoints.
- * codePointIndexes[n] should contain the encoded index that corresponds to the Unicode code point at codePoints[n].
+ * @param codePoints The array of Unicode code points less than {@link Character#MAX_VALUE} supported by this
+ * encoding.
+ * This can be null.
+ * @param codePointIndexes The array of encoded indexes that is parallel to {@code codePoints}.
+ * This can be null.
+ * {@code codePointIndexes[n]} should contain the encoded index that corresponds to the Unicode code point at
+ * {@code codePoints[n]}.
+ * @param codePoints2 The array of Unicode code points greaters than {@link Character#MAX_VALUE} supported by this
+ * encoding.
+ * This can be null.
+ * @param codePointIndexes2 The array of encoded indexes that is parallel to {@code codePoints2}.
+ * This can be null.
+ * {@code codePointIndexes2[n]} should contain the encoded index that corresponds to the Unicode code point at
+ * {@code codePoints2[n]}.
*/
public EncodingVector4a(final String name, final List<GlyphList> sourceGlyphLists,
- final char[] codePoints, final char[] codePointIndexes) {
+ final char[] codePoints, final char[] codePointIndexes, final int[] codePoints2,
+ final char[] codePointIndexes2) {
this.name = name;
this.sourceGlyphLists = sourceGlyphLists;
- this.codePoints = codePoints;
- this.codePointIndexes = codePointIndexes;
- sortCodePoints(codePoints, codePointIndexes);
+
+ /* Normalize the input. */
+ final char[] tempCodePoints = codePoints == null ? new char[0] : codePoints;
+ final char[] tempCodePointIndexes = codePointIndexes == null ? new char[0] : codePointIndexes;
+ final int[] tempCodePoints2 = codePoints2 == null ? new int[0] : codePoints2;
+ final char[] tempCodePointIndexes2 = codePointIndexes2 == null ? new char[0] : codePointIndexes2;
+
+ if (tempCodePoints.length != tempCodePointIndexes.length) {
+ throw new IllegalArgumentException("codePoints and codePointIndexes must be of the same length.");
+ }
+ if (tempCodePoints2.length != tempCodePointIndexes2.length) {
+ throw new IllegalArgumentException("codePoints2 and codePointIndexes2 must be of the same length.");
+ }
+
+ sortCodePoints(tempCodePoints, tempCodePointIndexes);
+ sortCodePoints(tempCodePoints2, tempCodePointIndexes2);
+
+ this.codePoints = new CharArray(tempCodePoints);
+ this.codePointIndexes = new CharArray(tempCodePointIndexes);
+ this.codePoints2 = new IntArray(tempCodePoints2);
+ this.codePointIndexes2 = new CharArray(tempCodePointIndexes2);
}
@Override
@@ -131,30 +127,35 @@
@Override
public int encodeCharacter(final int codePoint) {
- if (this.codePoints == null
- || this.codePointIndexes == null) {
- return 0;
+ int index = -1;
+ if (codePoint > Character.MAX_VALUE) {
+ index = this.codePoints2.binarySearch(codePoint);
+ } else {
+ index = this.codePoints.binarySearch((char) codePoint);
}
- final int index = Arrays.binarySearch(this.codePoints,
- (char) codePoint);
+
if (index < 0) {
- return 0;
+ return -1;
}
- return this.codePointIndexes[index];
+
+ if (codePoint > Character.MAX_VALUE) {
+ return this.codePointIndexes2.charAt(index);
+ } else {
+ return this.codePointIndexes.charAt(index);
+ }
}
@Override
public int decodeCharacter(final int encodedIndex) {
- /* This is not expected to be used much or at all, so the
- * codePointIndexes array has not been copied and sorted and
- * referenced.*/
- if (this.codePoints == null
- || this.codePointIndexes == null) {
- return INVALID_UNICODE_CHAR;
+ /* This is not expected to be used much or at all, so no attempt at optimization has been made. */
+ for (int i = 0; i < this.codePointIndexes.length(); i++) {
+ if (this.codePointIndexes.charAt(i) == encodedIndex) {
+ return this.codePoints.charAt(i);
+ }
}
- for (int i = 0; i < this.codePointIndexes.length; i++) {
- if (this.codePointIndexes[i] == encodedIndex) {
- return this.codePoints[i];
+ for (int i = 0; i < this.codePointIndexes2.length(); i++) {
+ if (this.codePointIndexes2.charAt(i) == encodedIndex) {
+ return this.codePoints2.intAt(i);
}
}
return INVALID_UNICODE_CHAR;
@@ -165,7 +166,7 @@
* @return The number of entries in this encoding.
*/
public int size() {
- return this.codePoints.length;
+ return this.codePoints.length() + this.codePoints2.length();
}
@Override
@@ -176,54 +177,66 @@
for (int i = 0; i < glyphList.length; i++) {
glyphList[i] = EncodingVector4a.NOTDEF;
}
- for (int i = 0; i < this.codePoints.length; i++) {
- final char codePoint = this.codePoints[i];
+ for (int i = 0; i < this.codePoints.length(); i++) {
+ final char codePoint = this.codePoints.charAt(i);
final String glyphName = mapCodePointToGlyphName(this.sourceGlyphLists, codePoint);
- final int encodingIndex = this.codePointIndexes[i];
+ final int encodingIndex = this.codePointIndexes.charAt(i);
glyphList[encodingIndex] = glyphName;
}
+ for (int i = 0; i < this.codePoints2.length(); i++) {
+ final int codePoint = this.codePoints2.intAt(i);
+ final String glyphName = mapCodePointToGlyphName(this.sourceGlyphLists, codePoint);
+ final int encodingIndex = this.codePointIndexes2.charAt(i);
+ glyphList[encodingIndex] = glyphName;
+ }
return glyphList;
}
@Override
public int getFirstIndex() {
- char firstIndex = Character.MAX_VALUE;
- for (int i = 0; i < this.codePointIndexes.length; i++) {
- if (this.codePointIndexes[i] < firstIndex) {
- firstIndex = this.codePointIndexes[i];
+ int firstIndex = Integer.MAX_VALUE;
+ for (int i = 0; i < this.codePointIndexes.length(); i++) {
+ if (this.codePointIndexes.charAt(i) < firstIndex) {
+ firstIndex = this.codePointIndexes.charAt(i);
}
}
+ for (int i = 0; i < this.codePointIndexes2.length(); i++) {
+ if (this.codePointIndexes2.charAt(i) < firstIndex) {
+ firstIndex = this.codePointIndexes2.charAt(i);
+ }
+ }
return firstIndex;
}
@Override
public int getLastIndex() {
- char lastIndex = Character.MIN_VALUE;
- for (int i = 0; i < this.codePointIndexes.length; i++) {
- if (this.codePointIndexes[i] > lastIndex) {
- lastIndex = this.codePointIndexes[i];
+ int lastIndex = Integer.MIN_VALUE;
+ for (int i = 0; i < this.codePointIndexes.length(); i++) {
+ if (this.codePointIndexes.charAt(i) > lastIndex) {
+ lastIndex = this.codePointIndexes.charAt(i);
}
}
+ for (int i = 0; i < this.codePointIndexes2.length(); i++) {
+ if (this.codePointIndexes2.charAt(i) > lastIndex) {
+ lastIndex = this.codePointIndexes2.charAt(i);
+ }
+ }
return lastIndex;
}
/**
- * Sorts the codePoints array by its contents, and sorts the parallel
- * codePointIndexes arrays in a parallel manner, keeping its elements
- * synchronized with those in codePoints.
+ * Sorts the codePoints array by its contents, and sorts the parallel codePointIndexes arrays in a parallel manner,
+ * keeping its elements synchronized with those in codePoints.
* @param codePoints The array of Unicode code points to be sorted.
- * @param codePointIndexes The array of encoding indexes that whose elements
- * correspond to elements in codePoints.
+ * @param codePointIndexes The array of encoding indexes that whose elements correspond to elements in codePoints.
*/
- public void sortCodePoints(final char[] codePoints,
- final char[] codePointIndexes) {
+ public void sortCodePoints(final char[] codePoints, final char[] codePointIndexes) {
boolean anyChanges = true;
while (anyChanges) {
anyChanges = false;
for (int i = 0; i < codePoints.length - 1; i++) {
if (codePoints[i] > codePoints[i + 1]) {
- /* They are out of order. Switch corresponding elements
- * in both arrays.*/
+ /* They are out of order. Switch corresponding elements in both arrays.*/
char saveChar = codePoints[i];
codePoints[i] = codePoints[i + 1];
codePoints[i + 1] = saveChar;
@@ -236,6 +249,30 @@
}
}
+ /**
+ * Sorts the codePoints array by its contents, and sorts the parallel codePointIndexes arrays in a parallel manner,
+ * keeping its elements synchronized with those in codePoints.
+ * @param codePoints The array of Unicode code points to be sorted.
+ * @param codePointIndexes The array of encoding indexes that whose elements correspond to elements in codePoints.
+ */
+ public void sortCodePoints(final int[] codePoints, final char[] codePointIndexes) {
+ boolean anyChanges = true;
+ while (anyChanges) {
+ anyChanges = false;
+ for (int i = 0; i < codePoints.length - 1; i++) {
+ if (codePoints[i] > codePoints[i + 1]) {
+ /* They are out of order. Switch corresponding elements in both arrays.*/
+ final int saveInt = codePoints[i];
+ codePoints[i] = codePoints[i + 1];
+ codePoints[i + 1] = saveInt;
+ final char saveChar = codePointIndexes[i];
+ codePointIndexes[i] = codePointIndexes[i + 1];
+ codePointIndexes[i + 1] = saveChar;
+ anyChanges = true;
+ }
+ }
+ }
+ }
@Override
public String asPostScript(final org.axsl.ps.Encoding baseEncoding) {
/* TODO: The baseEncoding is ignored for now. We need to consider it. */
@@ -279,7 +316,7 @@
if (this.sourceGlyphLists == null) {
return null;
}
- if (encodeCharacter(codePoint) == 0) {
+ if (encodeCharacter(codePoint) < 0) {
// codePoint is not in this encoding.
return null;
}
@@ -300,15 +337,20 @@
@Override
public boolean isSubsetOf(final PsEncoding otherVector) {
- for (int i = 0; i < this.codePoints.length; i++) {
- final int thisEncodedValue = this.encodeCharacter(
- this.codePoints[i]);
- final int otherEncodedValue = otherVector.encodeCharacter(
- this.codePoints[i]);
+ for (int i = 0; i < this.codePoints.length(); i++) {
+ final int thisEncodedValue = this.encodeCharacter(this.codePoints.charAt(i));
+ final int otherEncodedValue = otherVector.encodeCharacter(this.codePoints.charAt(i));
if (thisEncodedValue != otherEncodedValue) {
return false;
}
}
+ for (int i = 0; i < this.codePoints2.length(); i++) {
+ final int thisEncodedValue = this.encodeCharacter(this.codePoints2.intAt(i));
+ final int otherEncodedValue = otherVector.encodeCharacter(this.codePoints2.intAt(i));
+ if (thisEncodedValue != otherEncodedValue) {
+ return false;
+ }
+ }
return true;
}
@@ -366,8 +408,10 @@
stream.defaultReadObject();
this.name = (String) stream.readObject();
this.sourceGlyphLists = (List<GlyphList>) stream.readObject();
- this.codePoints = (char[]) stream.readObject();
- this.codePointIndexes = (char[]) stream.readObject();
+ this.codePoints = (CharArray) stream.readObject();
+ this.codePointIndexes = (CharArray) stream.readObject();
+ this.codePoints2 = (IntArray) stream.readObject();
+ this.codePointIndexes2 = (CharArray) stream.readObject();
}
@Override
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingWinAnsi.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -945,9 +945,12 @@
* {@link #getInstance()}.
*/
private EncodingWinAnsi() {
- super(PsEncoding.Predefined.WIN_ANSI.getName(), GlyphList4a.standardSourceGlyphLists(),
+ super(PsEncoding.Predefined.WIN_ANSI.getName(),
+ GlyphList4a.standardSourceGlyphLists(),
EncodingWinAnsi.CODE_POINTS,
- EncodingWinAnsi.CODE_POINT_INDEXES);
+ EncodingWinAnsi.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java 2021-01-16 03:28:31 UTC (rev 11799)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingZapfDingbats.java 2021-01-16 14:37:36 UTC (rev 11800)
@@ -908,9 +908,12 @@
* {@link #getInstance()}.
*/
private EncodingZapfDingbats() {
- super(PsEncoding.Predefined.ZAPF_DINGBATS.getName(), EncodingZapfDingbats.GLYPH_LISTS_USED,
+ super(PsEncoding.Predefined.ZAPF_DINGBATS.getName(),
+ EncodingZapfDingbats.GLYPH_LISTS_USED,
EncodingZapfDingbats.CODE_POINTS,
- EncodingZapfDingbats.CODE_POINT_INDEXES);
+ EncodingZapfDingbats.CODE_POINT_INDEXES,
+ null,
+ null);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-16 03:28:34
|
Revision: 11799
http://sourceforge.net/p/foray/code/11799
Author: victormote
Date: 2021-01-16 03:28:31 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Conform to aXSL changes moving binary search methods from Mutable to Plus interfaces.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java 2021-01-16 00:41:43 UTC (rev 11798)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java 2021-01-16 03:28:31 UTC (rev 11799)
@@ -236,4 +236,9 @@
return null;
}
+ @Override
+ public int binarySearch(final byte value) {
+ return Arrays.binarySearch(this.array, value);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java 2021-01-16 00:41:43 UTC (rev 11798)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java 2021-01-16 03:28:31 UTC (rev 11799)
@@ -125,4 +125,10 @@
return null;
}
+ @Override
+ public int binarySearch(final byte value) {
+ /* TODO: Consider implementing this. May not make sense. */
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java 2021-01-16 00:41:43 UTC (rev 11798)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java 2021-01-16 03:28:31 UTC (rev 11799)
@@ -114,4 +114,10 @@
return null;
}
+ @Override
+ public int binarySearch(final byte value) {
+ /* TODO: Implement this. */
+ throw new UnsupportedOperationException();
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-01-16 00:41:43 UTC (rev 11798)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java 2021-01-16 03:28:31 UTC (rev 11799)
@@ -131,4 +131,9 @@
return null;
}
+ @Override
+ public int binarySearch(final int value) {
+ return Arrays.binarySearch(this.array, value);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 00:41:43 UTC (rev 11798)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 03:28:31 UTC (rev 11799)
@@ -306,4 +306,9 @@
return this;
}
+ @Override
+ public int binarySearch(final int value) {
+ return Arrays.binarySearch(this.array, 0, this.length, value);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java 2021-01-16 00:41:43 UTC (rev 11798)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java 2021-01-16 03:28:31 UTC (rev 11799)
@@ -148,4 +148,9 @@
return new LongSequenceIterator(this, true);
}
+ @Override
+ public int binarySearch(final long value) {
+ return Arrays.binarySearch(this.array, value);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-16 00:41:43 UTC (rev 11798)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-16 03:28:31 UTC (rev 11799)
@@ -323,4 +323,9 @@
this.array[index2] = temp;
}
+ @Override
+ public int binarySearch(final long value) {
+ return Arrays.binarySearch(this.array, 0, length(), value);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-16 00:41:45
|
Revision: 11798
http://sourceforge.net/p/foray/code/11798
Author: victormote
Date: 2021-01-16 00:41:43 +0000 (Sat, 16 Jan 2021)
Log Message:
-----------
Conform to aXSL changes removing isMutable() from Plus sequence interfaces, and adding some basic mutating methods to the Mutable sequence interfaces.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java 2021-01-15 22:42:32 UTC (rev 11797)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java 2021-01-16 00:41:43 UTC (rev 11798)
@@ -232,11 +232,6 @@
}
@Override
- public boolean isMutable() {
- return false;
- }
-
- @Override
public ByteSequenceMutable asMutable() {
return null;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-01-15 22:42:32 UTC (rev 11797)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2021-01-16 00:41:43 UTC (rev 11798)
@@ -361,11 +361,6 @@
return null;
}
- @Override
- public boolean isMutable() {
- return true;
- }
-
/**
* Resets the length of this sequence to a specified length.
* The <em>capacity</em> of the sequence remains unchanged unless it needs to increase to accommodate a bigger size.
@@ -410,4 +405,16 @@
return this;
}
+ @Override
+ public void setByteAt(final int index, final byte newByte) {
+ this.backingArray[index] = newByte;
+ }
+
+ @Override
+ public void swap(final int index1, final int index2) {
+ final byte temp = this.backingArray[index1];
+ this.backingArray[index1] = this.backingArray[index2];
+ this.backingArray[index2] = temp;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java 2021-01-15 22:42:32 UTC (rev 11797)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java 2021-01-16 00:41:43 UTC (rev 11798)
@@ -121,11 +121,6 @@
}
@Override
- public boolean isMutable() {
- return ! (this.sequence instanceof String);
- }
-
- @Override
public ByteSequenceMutable asMutable() {
return null;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java 2021-01-15 22:42:32 UTC (rev 11797)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java 2021-01-16 00:41:43 UTC (rev 11798)
@@ -78,11 +78,6 @@
}
@Override
- public boolean isMutable() {
- return this.wrappedSequence.isMutable();
- }
-
- @Override
public byte[] toArray() {
final byte[] array = new byte[this.length];
for (int index = 0; index < array.length; index ++) {
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-15 22:42:32 UTC (rev 11797)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2021-01-16 00:41:43 UTC (rev 11798)
@@ -205,11 +205,6 @@
}
}
- @Override
- public boolean isMutable() {
- return true;
- }
-
/**
* Resets the length of this sequence to a specified length.
* The <em>capacity</em> of the sequence remains unchanged unless it needs to increase to accommodate a bigger size.
@@ -306,4 +301,11 @@
return new CharSequenceIterator(this, true);
}
+ @Override
+ public void swap(final int index1, final int index2) {
+ final char temp = this.backingArray[index1];
+ this.backingArray[index1] = this.backingArray[index2];
+ this.backingArray[index2] = temp;
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-15 22:42:32 UTC (rev 11797)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2021-01-16 00:41:43 UTC (rev 11798)
@@ -169,6 +169,23 @@
this.array = Arrays.copyOf(this.array, newCapacity);
}
+ @Override
+ public void setIntAt(final int index, final int newInt) {
+ this.array[index] = newInt;
+ }
+
+ @Override
+ public void sort() {
+ Arrays.sort(this.array);
+ }
+
+ @Override
+ public void swap(final int index1, final int index2) {
+ final int temp = this.array[index1];
+ this.array[index1] = this.array[index2];
+ this.array[index2] = temp;
+ }
+
/**
* Append an int to this structure.
* @param intToAppend The int to append.
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-15 22:42:32 UTC (rev 11797)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2021-01-16 00:41:43 UTC (rev 11798)
@@ -306,4 +306,21 @@
return new LongSequenceIterator(this, true);
}
+ @Override
+ public void setLongAt(final int index, final long newLong) {
+ this.array[index] = newLong;
+ }
+
+ @Override
+ public void sort() {
+ Arrays.sort(this.array);
+ }
+
+ @Override
+ public void swap(final int index1, final int index2) {
+ final long temp = this.array[index1];
+ this.array[index1] = this.array[index2];
+ this.array[index2] = temp;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-15 22:42:35
|
Revision: 11797
http://sourceforge.net/p/foray/code/11797
Author: victormote
Date: 2021-01-15 22:42:32 +0000 (Fri, 15 Jan 2021)
Log Message:
-----------
Conform to aXSL changes: 1. Convert a use of char[] to CharSequence. 2. For Cmap04, change unicode values from char to int to capture code points > 16 bits.
Modified Paths:
--------------
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableCmap.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04Entry.java
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableCmap.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableCmap.java 2021-01-15 19:13:51 UTC (rev 11796)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableCmap.java 2021-01-15 22:42:32 UTC (rev 11797)
@@ -195,8 +195,8 @@
/* Skip rangeShift. */
raInput.skipBytes(USHORT_BYTES);
- final char[] endCount = new char[segCountX2 / 2];
- final char[] startCount = new char[segCountX2 / 2];
+ final int[] endCount = new int[segCountX2 / 2];
+ final int[] startCount = new int[segCountX2 / 2];
final int deltas[] = new int[segCountX2 / 2];
final int rangeOffset[] = new int[segCountX2 / 2];
@@ -245,8 +245,7 @@
+ deltas[i]) & Character.MAX_VALUE);
computedIndexes[j - startCount[i]] = glyphIndex;
}
- cmap04.addEntry(startCount[i],
- endCount[i], computedIndexes);
+ cmap04.addEntry(startCount[i], endCount[i], new String(computedIndexes));
}
}
return cmap04;
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04.java 2021-01-15 19:13:51 UTC (rev 11796)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04.java 2021-01-15 22:42:32 UTC (rev 11797)
@@ -28,6 +28,8 @@
package org.foray.ps.encode;
+import org.foray.common.WellKnownConstants;
+
import org.axsl.ps.Cmap04;
/**
@@ -80,24 +82,15 @@
}
@Override
- public void addEntry(final char unicodeStart, final char unicodeEnd,
- final char glyphStartIndex) {
+ public void addEntry(final int unicodeStart, final int unicodeEnd, final char glyphStartIndex) {
final Cmap4a04Entry newEntry = new Cmap4a04Entry(unicodeStart, unicodeEnd,
glyphStartIndex);
addEntry(newEntry);
}
- /**
- * Add a new entry to this map, converting the input values to an entry.
- * @param unicodeStart The starting Unicode code point for this map.
- * @param unicodeEnd The ending Unicode code point for this map.
- * @param glyphIndexes The array of glyph indexes corresponding to the
- * range {@code unicodeStart} through {@code unicodeEnd}.
- */
- public void addEntry(final char unicodeStart, final char unicodeEnd,
- final char[] glyphIndexes) {
- final Cmap4a04Entry newEntry = new Cmap4a04Entry(unicodeStart, unicodeEnd,
- glyphIndexes);
+ @Override
+ public void addEntry(final int unicodeStart, final int unicodeEnd, final CharSequence glyphIndexes) {
+ final Cmap4a04Entry newEntry = new Cmap4a04Entry(unicodeStart, unicodeEnd, glyphIndexes);
addEntry(newEntry);
}
@@ -127,13 +120,12 @@
@Override
public int decodeCharacter(final int glyphIndexInput) {
for (int i = 0; i < this.entries.length; i++) {
- final char codePoint = this.entries[i].decodeCharacter(
- glyphIndexInput);
- if (codePoint != Character.MAX_VALUE) {
+ final int codePoint = this.entries[i].decodeCharacter(glyphIndexInput);
+ if (codePoint != WellKnownConstants.INVALID_UNICODE_CHARACTER) {
return codePoint;
}
}
- return Character.MAX_VALUE;
+ return WellKnownConstants.INVALID_UNICODE_CHARACTER;
}
@Override
Modified: trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04Entry.java
===================================================================
--- trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04Entry.java 2021-01-15 19:13:51 UTC (rev 11796)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/Cmap4a04Entry.java 2021-01-15 22:42:32 UTC (rev 11797)
@@ -28,6 +28,8 @@
package org.foray.ps.encode;
+import org.foray.common.WellKnownConstants;
+
/**
* Contains one entry from a TrueType Cmap4a subtable, format 4, which handles
* 16-bit Unicode codepoint ranges.
@@ -35,10 +37,10 @@
public class Cmap4a04Entry {
/** The first Unicode codepoint in this entry. */
- private char unicodeStart;
+ private int unicodeStart;
/** The last Unicode codepoint in this entry.*/
- private char unicodeEnd;
+ private int unicodeEnd;
/** The starting glyph index for this entry. This index points to the glyph
* representing {@link #unicodeStart}. */
@@ -48,7 +50,7 @@
* For contiguous entries, this will be null.
* For non-contiguous entries, this array contains the glyph Indexes for the
* range of Unicode characters. */
- private char[] glyphIndexes;
+ private CharSequence glyphIndexes;
/**
* Constructor for contiguous entries.
@@ -58,8 +60,7 @@
* @param glyphStartIndex The starting glyph index mapped by this mapping.
* This is the encoded value for {@code unicodeStart}.
*/
- public Cmap4a04Entry(final char unicodeStart, final char unicodeEnd,
- final char glyphStartIndex) {
+ public Cmap4a04Entry(final int unicodeStart, final int unicodeEnd, final char glyphStartIndex) {
this.unicodeStart = unicodeStart;
this.unicodeEnd = unicodeEnd;
this.glyphStartIndex = glyphStartIndex;
@@ -73,8 +74,7 @@
* @param glyphIndexes The array of encoded glyph indexes corresponding to
* the range {@code unicodeStart} through {@code unicodeEnd}.
*/
- public Cmap4a04Entry(final char unicodeStart, final char unicodeEnd,
- final char[] glyphIndexes) {
+ public Cmap4a04Entry(final int unicodeStart, final int unicodeEnd, final CharSequence glyphIndexes) {
this.unicodeStart = unicodeStart;
this.unicodeEnd = unicodeEnd;
this.glyphIndexes = glyphIndexes;
@@ -95,7 +95,7 @@
* @param c The character to be tested.
* @return True iff this entry has encoding information for {@code c}.
*/
- public boolean containsChar(final char c) {
+ public boolean containsChar(final int c) {
return (c >= this.unicodeStart) && (c <= this.unicodeEnd);
}
@@ -105,7 +105,7 @@
* @return The glyph index corresponding to {@code c}, or zero if this
* entry does not know how to encode it.
*/
- public char encodeCharacter(final char c) {
+ public char encodeCharacter(final int c) {
if (! containsChar(c)) {
return 0;
}
@@ -112,7 +112,7 @@
if (this.glyphIndexes == null) {
return (char) (c - this.unicodeStart + this.glyphStartIndex);
}
- return this.glyphIndexes[c - this.unicodeStart];
+ return this.glyphIndexes.charAt(c - this.unicodeStart);
}
/**
@@ -122,7 +122,7 @@
* or {@link Character#MAX_VALUE} if this entry does not know how to decode
* it.
*/
- public char decodeCharacter(final int glyphIndex) {
+ public int decodeCharacter(final int glyphIndex) {
if (this.glyphIndexes == null) {
final char codePoint = (char) (glyphIndex - this.glyphStartIndex
+ this.unicodeStart);
@@ -130,14 +130,14 @@
&& codePoint <= this.unicodeStart) {
return codePoint;
}
- return Character.MAX_VALUE;
+ return WellKnownConstants.INVALID_UNICODE_CHARACTER;
}
- for (int i = 0; i < this.glyphIndexes.length; i++) {
- if (this.glyphIndexes[i] == glyphIndex) {
- return (char) (this.unicodeStart + i);
+ for (int i = 0; i < this.glyphIndexes.length(); i++) {
+ if (this.glyphIndexes.charAt(i) == glyphIndex) {
+ return this.unicodeStart + i;
}
}
- return Character.MAX_VALUE;
+ return WellKnownConstants.INVALID_UNICODE_CHARACTER;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2021-01-15 19:13:57
|
Revision: 11796
http://sourceforge.net/p/foray/code/11796
Author: victormote
Date: 2021-01-15 19:13:51 +0000 (Fri, 15 Jan 2021)
Log Message:
-----------
Move primitive sequence types to their own package.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/WellKnownConstants.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteSequenceTokenizer.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteSequenceTokenizerConfig.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/NibbleArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/OrderedTreePath4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/PackedIntArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/TernaryNodes.java
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ByteUtils.java
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/CharSequenceUtils.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractByteSequenceTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractIntSequenceTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteArrayBuilderTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteArrayTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/IntArrayBuilderTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/IntArrayTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/LongArrayBuilderTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/LongArrayTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/primitive/CharSequenceUtilsTests.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubSubtable.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx01x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx01x02.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx02x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx03x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx04x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx05x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx05x02.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx05x03.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx06x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx06x02.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx06x03.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx07x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/OtfLookupGsubx08x01.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/ttf/TtfTableGsub.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1FontParser.java
trunk/foray/foray-font/src/main/java/org/foray/font/util/MockFont.java
trunk/foray/foray-font/src/test/java/org/foray/font/format/ttf/OtfLookupGsubTests.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/BmpGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/EpsGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/GifGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/Graphic4a.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/JpegGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/PdfGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/PngGraphic.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/TempImage.java
trunk/foray/foray-graphic/src/main/java/org/foray/graphic/TiffGraphic.java
trunk/foray/foray-hyphen/src/main/java/org/foray/hyphen/WordBreaker.java
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/eng.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/fin.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/hun.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/ita.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/mah.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/pol.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/por.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/rus.jbso
trunk/foray/foray-hyphen/src/main/resources/resources/org/foray/hyphen/patterns/spa.jbso
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/ParaContentIterator.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/TotalFitLb.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/LbTestUtilities.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfConstants.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfHeader.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfParser.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfArray.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfBoolean.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfHexString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfTextString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfTrailer.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/PdfParserTests.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfArrayTests.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
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/PsStringInput.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/java2d/Java2dSystemDict.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/pdf/PdfSystemDict.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/readonly/ReadOnlySystemDict.java
trunk/foray/foray-render/src/main/java/org/foray/render/ps/PsRenderer.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractByteSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/AbstractIntSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
Removed Paths:
-------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteSequenceChars.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteSequenceSubset.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/IntArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/WellKnownConstants.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/WellKnownConstants.java 2021-01-15 18:58:47 UTC (rev 11795)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/WellKnownConstants.java 2021-01-15 19:13:51 UTC (rev 11796)
@@ -28,7 +28,7 @@
package org.foray.common;
-import org.foray.common.data.ByteArray;
+import org.foray.common.sequence.ByteArray;
/**
* Class containing well-known or commonly-used constants and conversions.
Deleted: trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java 2021-01-15 18:58:47 UTC (rev 11795)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java 2021-01-15 19:13:51 UTC (rev 11796)
@@ -1,675 +0,0 @@
-/*
- * Copyright 2020 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.common.data;
-
-import org.foray.common.primitive.ByteUtils;
-import org.foray.common.sequence.ByteSequenceIterator;
-
-import org.axsl.common.sequence.BytePrimitiveIterator;
-import org.axsl.common.sequence.ByteSequence;
-import org.axsl.common.sequence.ByteSequencePlus;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
-import java.nio.charset.Charset;
-
-/**
- * Abstract superclass for byte sequence classes.
- *
- * Note that many of the methods in this class were adapted from {@link java.lang.String}.
- */
-public abstract class AbstractByteSequence implements ByteSequencePlus {
-
- /** Byte array containing all whitespace characters. */
- private static final ByteArray WHITESPACE_CHARS = new ByteArray(" \n\r\t");
-
- @Override
- public String toString() {
- return new String(toArray(), java.nio.charset.Charset.forName("US-ASCII"));
- }
-
- @Override
- public String toString(final java.nio.charset.Charset charset) {
- return new String(toArray(), charset);
- }
-
- @Override
- public String toString(final String charsetName) throws UnsupportedEncodingException {
- return new String(toArray(), charsetName);
- }
-
- @Override
- public CharSequence charSubSequence(final int start, final int end) {
- return subSequence(start, end).toString();
- }
-
- @Override
- public CharSequence charSubSequence(final int start, final int end, final Charset charset) {
- return subSequence(start, end).toString(charset);
- }
-
- @Override
- public CharSequence charSubSequence(final int start, final int end, final String charsetName)
- throws UnsupportedEncodingException {
- return subSequence(start, end).toString(charsetName);
- }
-
- @Override
- public boolean equals(final Object other) {
- if (other == null) {
- return false;
- }
- if (! (other instanceof ByteSequence)) {
- return false;
- }
- final ByteSequence otherSequence = (ByteSequence) other;
- if (length() != otherSequence.length()) {
- return false;
- }
- for (int index = 0; index < length(); index ++) {
- if (byteAt(index) != otherSequence.byteAt(index)) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- public String difference(final Object other) {
- if (other == null) {
- return "Comparison object is null.";
- }
- if (! (other instanceof ByteSequence)) {
- return "Comparison object is not a byte sequence.";
- }
- final ByteSequence otherSequence = (ByteSequence) other;
-
- final StringBuilder builder = new StringBuilder();
- if (length() != otherSequence.length()) {
- builder.append(String.format("Lengths are different: this %d, other %d.", this.length(),
- otherSequence.length()));
- }
-
- final int maxIndex = Math.min(this.length(), otherSequence.length());
- int diffIndex = -1;
- for (int index = 0; index < maxIndex; index ++) {
- if (byteAt(index) != otherSequence.byteAt(index)) {
- diffIndex = index;
- break;
- }
- }
- if (diffIndex < 0
- && length() != otherSequence.length()) {
- diffIndex = maxIndex + 1;
- }
-
- if (diffIndex > -1) {
- if (builder.length() > 0) {
- builder.append(" ");
- }
- builder.append(String.format("First difference is at index %d.", diffIndex));
- }
-
- return builder.toString();
- }
-
- @Override
- public int indexOf(final int aByte) {
- return indexOf(aByte, 0);
- }
-
- @Override
- public int indexOf(final int aByte, final int fromIndex) {
- if (aByte < Byte.MIN_VALUE
- || aByte > Byte.MAX_VALUE) {
- return -1;
- }
- final int max = length();
- int startIndex = fromIndex;
- if (fromIndex < 0) {
- startIndex = 0;
- } else if (fromIndex >= max) {
- return -1;
- }
- for (int i = startIndex; i < max; i++) {
- if (byteAt(i) == aByte) {
- return i;
- }
- }
- return -1;
- }
-
- @Override
- public int indexOf(final CharSequence str) {
- return indexOf(str, 0);
- }
-
- @Override
- public int indexOf(final CharSequence str, final int fromIndex) {
- return indexOf(0, length(), str, 0, str.length(), fromIndex);
- }
-
- @Override
- public int indexOf(final int sourceOffset, final int sourceCount, final CharSequence target, final int fromIndex) {
- return indexOf(sourceOffset, sourceCount, target, 0, target.length(), fromIndex);
- }
-
- @Override
- public int indexOf(final int sourceOffset, final int sourceCount, final CharSequence target, final int targetOffset,
- final int targetCount, final int fromIndex) {
- if (fromIndex >= sourceCount) {
- return targetCount == 0 ? sourceCount : -1;
- }
- int startIndex = fromIndex;
- if (fromIndex < 0) {
- startIndex = 0;
- }
- if (targetCount == 0) {
- return startIndex;
- }
-
- final char first = target.charAt(targetOffset);
- final int max = sourceOffset + (sourceCount - targetCount);
-
- for (int i = sourceOffset + startIndex; i <= max; i++) {
- /* Look for first character. */
- if (byteAt(i) != first) {
- while (++i <= max && byteAt(i) != first) { }
- }
-
- /* Found first character, now look at the rest of v2 */
- if (i <= max) {
- int j = i + 1;
- final int end = j + targetCount - 1;
- for (int k = targetOffset + 1; j < end && byteAt(j) == target.charAt(k); j++, k++) { }
-
- if (j == end) {
- /* Found whole string. */
- return i - sourceOffset;
- }
- }
- }
- return -1;
- }
-
- @Override
- public int indexOf(final ByteSequence str) {
- return indexOf(str, 0);
- }
-
- @Override
- public int indexOf(final ByteSequence str, final int fromIndex) {
- return indexOf(0, length(), str, 0, str.length(), fromIndex);
- }
-
- @Override
- public int indexOf(final int sourceOffset, final int sourceCount, final ByteSequence target, final int fromIndex) {
- return indexOf(sourceOffset, sourceCount, target, 0, target.length(), fromIndex);
- }
-
- @Override
- public int indexOf(final int sourceOffset, final int sourceCount, final ByteSequence target,
- final int targetOffset, final int targetCount, final int fromIndex) {
- if (fromIndex >= sourceCount) {
- return targetCount == 0 ? sourceCount : -1;
- }
- int startIndex = fromIndex;
- if (fromIndex < 0) {
- startIndex = 0;
- }
- if (targetCount == 0) {
- return startIndex;
- }
-
- final byte first = target.byteAt(targetOffset);
- final int max = sourceOffset + (sourceCount - targetCount);
-
- for (int i = sourceOffset + startIndex; i <= max; i++) {
- /* Look for first character. */
- if (byteAt(i) != first) {
- while (++i <= max && byteAt(i) != first) { }
- }
-
- /* Found first character, now look at the rest of v2 */
- if (i <= max) {
- int j = i + 1;
- final int end = j + targetCount - 1;
- for (int k = targetOffset + 1; j < end && byteAt(j) == target.byteAt(k); j++, k++) { }
-
- if (j == end) {
- /* Found whole string. */
- return i - sourceOffset;
- }
- }
- }
- return -1;
- }
-
- @Override
- public boolean contains(final byte testByte) {
- return indexOf(testByte) > -1;
- }
-
- @Override
- public int lastIndexOf(final int aByte) {
- return lastIndexOf(aByte, length() - 1);
- }
-
- @Override
- public int lastIndexOf(final int aByte, final int fromIndex) {
- int i = Math.min(fromIndex, length() - 1);
- for (; i >= 0; i--) {
- if (byteAt(i) == aByte) {
- return i;
- }
- }
- return -1;
- }
-
- @Override
- public int lastIndexOf(final CharSequence str) {
- return lastIndexOf(str, length());
- }
-
- @Override
- public int lastIndexOf(final CharSequence str, final int fromIndex) {
- return lastIndexOf(0, length(), str, 0, str.length(), fromIndex);
- }
-
- @Override
- public int lastIndexOf(final int sourceOffset, final int sourceCount, final CharSequence target,
- final int fromIndex) {
- return lastIndexOf(sourceOffset, sourceCount, target, 0, target.length(), fromIndex);
- }
-
- @Override
- public int lastIndexOf(final int sourceOffset, final int sourceCount, final CharSequence target,
- final int targetOffset, final int targetCount, final int fromIndex) {
- /*
- * Check arguments; return immediately where possible. For
- * consistency, don't check for null str.
- */
- final int rightIndex = sourceCount - targetCount;
- if (fromIndex < 0) {
- return -1;
- }
- int fromIndexAdjusted = fromIndex;
- if (fromIndex > rightIndex) {
- fromIndexAdjusted = rightIndex;
- }
- /* Empty string always matches. */
- if (targetCount == 0) {
- return fromIndexAdjusted;
- }
-
- final int strLastIndex = targetOffset + targetCount - 1;
- final char strLastChar = target.charAt(strLastIndex);
- final int min = sourceOffset + targetCount - 1;
- int i = min + fromIndexAdjusted;
-
- startSearchForLastChar:
- while (true) {
- while (i >= min && byteAt(i) != strLastChar) {
- i--;
- }
- if (i < min) {
- return -1;
- }
- int j = i - 1;
- final int start = j - (targetCount - 1);
- int k = strLastIndex - 1;
-
- while (j > start) {
- if (byteAt(j--) != target.charAt(k--)) {
- i--;
- continue startSearchForLastChar;
- }
- }
- return start - sourceOffset + 1;
- }
- }
-
- @Override
- public int lastIndexOf(final ByteSequence str) {
- return lastIndexOf(str, length());
- }
-
- @Override
- public int lastIndexOf(final ByteSequence str, final int fromIndex) {
- return lastIndexOf(0, length(), str, 0, str.length(), fromIndex);
- }
-
- @Override
- public int lastIndexOf(final int sourceOffset, final int sourceCount, final ByteSequence target,
- final int fromIndex) {
- return lastIndexOf(sourceOffset, sourceCount, target, 0, target.length(), fromIndex);
- }
-
- @Override
- public int lastIndexOf(final int sourceOffset, final int sourceCount, final ByteSequence target,
- final int targetOffset, final int targetCount, final int fromIndex) {
- /*
- * Check arguments; return immediately where possible. For
- * consistency, don't check for null str.
- */
- final int rightIndex = sourceCount - targetCount;
- if (fromIndex < 0) {
- return -1;
- }
- int fromIndexAdjusted = fromIndex;
- if (fromIndex > rightIndex) {
- fromIndexAdjusted = rightIndex;
- }
- /* Empty string always matches. */
- if (targetCount == 0) {
- return fromIndexAdjusted;
- }
-
- final int strLastIndex = targetOffset + targetCount - 1;
- final byte strLastChar = target.byteAt(strLastIndex);
- final int min = sourceOffset + targetCount - 1;
- int i = min + fromIndexAdjusted;
-
- startSearchForLastChar:
- while (true) {
- while (i >= min && byteAt(i) != strLastChar) {
- i--;
- }
- if (i < min) {
- return -1;
- }
- int j = i - 1;
- final int start = j - (targetCount - 1);
- int k = strLastIndex - 1;
-
- while (j > start) {
- if (byteAt(j--) != target.byteAt(k--)) {
- i--;
- continue startSearchForLastChar;
- }
- }
- return start - sourceOffset + 1;
- }
- }
-
- @Override
- public int countWhitespace(final int start) {
- int count = 0;
- int index = start;
- while (index < length()
- && WHITESPACE_CHARS.indexOf(byteAt(index)) < 0) {
- count ++;
- index ++;
- }
- return count;
- }
-
- @Override
- public int findStartOfLine(final int start) {
- int currIndex = start;
- while (true) {
- if (currIndex >= length()) {
- return -1;
- }
- if (isStartOfLine(currIndex)) {
- return currIndex;
- }
- currIndex ++;
- }
- }
-
- @Override
- public boolean isStartOfLine(final int start) {
- switch (start) {
- case 0: return true;
- default: {
- if (byteAt(start - 1) == '\r') {
- if (byteAt(start) == '\n') {
- return false;
- } else {
- return true;
- }
- } else if (byteAt(start - 1) == '\n') {
- return true;
- }
- return false;
- }
- }
- }
-
- @Override
- public ByteSequencePlus readCurrentLine(final int start) {
- if (start >= length()) {
- return null;
- }
- int end = start + 1;
- while (end < length()) {
- final byte theByte = byteAt(end);
- if (theByte == '\r'
- || theByte == '\n') {
- break;
- }
- end ++;
- }
- return subSequence(start, end);
- }
-
- @Override
- public ByteSequencePlus readNextLine(final int start) {
- final int startOfNextLine = findStartOfLine(start + 1);
- return readCurrentLine(startOfNextLine);
- }
-
- @Override
- public ByteSequencePlus readWord(final int start) {
- int trueStart = start;
- while (trueStart < length()
- && WHITESPACE_CHARS.indexOf(byteAt(trueStart)) > -1) {
- trueStart ++;
- }
- if (trueStart >= length()) {
- return null;
- }
- int end = trueStart;
- while (end < length()
- && WHITESPACE_CHARS.indexOf(byteAt(end)) < 0) {
- end ++;
- }
- if (end == trueStart) {
- return null;
- }
- return subSequence(trueStart, end);
- }
-
- @Override
- public ByteSequencePlus readWord(final int start, final int sequence) {
- int toSkip = sequence - 1;
- int currentStart = start;
- ByteSequencePlus word = readWord(currentStart);
- if (word == null) {
- return null;
- }
- while (toSkip > 0) {
- currentStart += word.length();
- currentStart += countWhitespace(currentStart);
- word = readWord(currentStart);
- if (word == null) {
- return null;
- }
- toSkip --;
- }
- return word;
- }
-
- @Override
- public abstract ByteSequencePlus subSequence(int start, int end);
-
- @Override
- public boolean canParseByte() {
- try {
- parseByte();
- return true;
- } catch (final NumberFormatException e) {
- return false;
- }
- }
-
- @Override
- public byte parseByte() {
- return Byte.parseByte(this.toString());
- }
-
- @Override
- public byte parseByte(final int radix) {
- return Byte.parseByte(this.toString(), radix);
- }
-
- @Override
- public boolean canParseShort() {
- try {
- parseShort();
- return true;
- } catch (final NumberFormatException e) {
- return false;
- }
- }
-
- @Override
- public short parseShort() {
- return Short.parseShort(this.toString());
- }
-
- @Override
- public short parseShort(final int radix) {
- return Short.parseShort(this.toString());
- }
-
- @Override
- public boolean canParseInt() {
- try {
- parseInt();
- return true;
- } catch (final NumberFormatException e) {
- return false;
- }
- }
-
- @Override
- public int parseInt() {
- return Integer.parseInt(this.toString());
- }
-
- @Override
- public int parseInt(final int radix) {
- return Integer.parseInt(this.toString());
- }
-
- @Override
- public boolean canParseLong() {
- try {
- parseLong();
- return true;
- } catch (final NumberFormatException e) {
- return false;
- }
- }
-
- @Override
- public long parseLong() {
- return Long.parseLong(this.toString());
- }
-
- @Override
- public long parseLong(final int radix) {
- return Long.parseLong(this.toString());
- }
-
- @Override
- public boolean canParseDecimal() {
- try {
- parseDecimal();
- return true;
- } catch (final NumberFormatException e) {
- return false;
- }
- }
-
- @Override
- public BigDecimal parseDecimal() {
- return new BigDecimal(this.toString());
- }
-
- @Override
- public void writeTo(final OutputStream output) throws IOException {
- for (int index = 0; index < length(); index ++) {
- final byte theByte = byteAt(index);
- output.write(theByte);
- }
- }
-
- @Override
- public ByteArray toHexByteSequence() {
- final byte[] outBytes = new byte[length() * 2];
- int outIndex = 0;
- for (int index = 0; index < length(); index ++) {
- final byte theByte = byteAt(index);
- final byte highNibble = ByteUtils.toHexCharHigh(theByte);
- outBytes[outIndex] = highNibble;
- outIndex ++;
- final byte lowNibble = ByteUtils.toHexCharLow(theByte);
- outBytes[outIndex] = lowNibble;
- outIndex ++;
- }
- return new ByteArray(outBytes);
- }
-
- @Override
- public byte lastByte() {
- final int index = length() - 1;
- return byteAt(index);
- }
-
- @Override
- public ByteSequencePlus asPlus() {
- return this;
- }
-
- @Override
- public BytePrimitiveIterator iterator() {
- return new ByteSequenceIterator(this);
- }
-
- @Override
- public BytePrimitiveIterator iteratorReverse() {
- return new ByteSequenceIterator(this, true);
- }
-
-}
Deleted: trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java 2021-01-15 18:58:47 UTC (rev 11795)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java 2021-01-15 19:13:51 UTC (rev 11796)
@@ -1,70 +0,0 @@
-/*
- * Copyright 2020 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.common.data;
-
-import org.axsl.common.sequence.IntPrimitiveIterator;
-import org.axsl.common.sequence.IntSequencePlus;
-
-/**
- * Abstract superclass for implementations of {@link IntSequencePlus}.
- */
-public abstract class AbstractIntSequence implements IntSequencePlus {
-
- @Override
- public int indexOf(final int anInt) {
- for (int index = 0; index < length(); index ++) {
- final int foundInt = intAt(index);
- if (foundInt == anInt) {
- return index;
- }
- }
- return -1;
- }
-
- @Override
- public boolean contains(final int theInt) {
- return indexOf(theInt) > -1;
- }
-
- @Override
- public IntPrimitiveIterator iterator() {
- return new org.foray.common.data.IntSequenceIterator(this);
- }
-
- @Override
- public IntPrimitiveIterator iteratorReverse() {
- return new org.foray.common.data.IntSequenceIterator(this, true);
- }
-
- @Override
- public IntSequencePlus asPlus() {
- return this;
- }
-
-}
Deleted: trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArray.java 2021-01-15 18:58:47 UTC (rev 11795)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArray.java 2021-01-15 19:13:51 UTC (rev 11796)
@@ -1,244 +0,0 @@
-/*
- * Copyright 2019 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.common.data;
-
-import org.foray.common.primitive.ByteUtils;
-import org.foray.common.primitive.NumberUtils;
-
-import org.axsl.common.sequence.ByteSequence;
-import org.axsl.common.sequence.ByteSequenceMutable;
-
-import java.io.Serializable;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Wrapper around an array of bytes, intended to be similar in scope and purpose to what {@link String} does for an
- * array of chars.
- * Instances of this class are immutable.
- */
-public class ByteArray extends AbstractByteSequence implements Serializable {
-
- /* *****************************************************************************************************************
- * DEVELOPER NOTE: As methods are added to this class, please make them analogous to those in {@link String}.
- **************************************************************************************************************** */
-
- /** An empty byte array. */
- public static final ByteArray EMPTY = new ByteArray();
-
- /** An empty, unmodifiable list of ByteArrays suitable for default values in some cases. */
- public static final List<ByteArray> EMPTY_BYTE_ARRAY_LIST =
- Collections.unmodifiableList(new ArrayList<ByteArray>(0));
-
- /** Constant needed for serialization. */
- private static final long serialVersionUID = -8330116207758178277L;
-
- /** The internal array. */
- private byte[] array;
-
- /**
- * Constructor for an existing array.
- * @param array The array to be wrapped. This array is copied into an internal data structure to prevent it from
- * being changed.
- */
- public ByteArray(final byte... array) {
- this.array = Arrays.copyOf(array, array.length);
- }
-
- /**
- * Constructor for part of an existing array.
- * @param array The array to be wrapped. This array is copied into an internal data structure to prevent it from
- * being changed.
- * @param start The index of the first element in {@code array} to be included in this instance.
- * @param length The number of elements in {@code array} to be included in this instance.
- */
- public ByteArray(final byte[] array, final int start, final int length) {
- this.array = Arrays.copyOfRange(array, start, start + length);
- }
-
- /**
- * Constructor for another {@link ByteSequence}.
- * @param sequence The byte sequence whose content is the content of the new array.
- * This sequence is copied into an internal data structure to prevent it from being changed.
- */
- public ByteArray(final ByteSequence sequence) {
- this.array = new byte[sequence.length()];
- for (int index = 0; index < sequence.length(); index ++) {
- this.array[index] = sequence.byteAt(index);
- }
- }
-
- /**
- * Constructor for a String or other CharSequence.
- * The chars in the sequence will be converted to bytes using the "US-ASII" Charset.
- * @param charSequence The String or other CharSequence whose character should be converted to bytes and
- * wrapped.
- */
- public ByteArray(final CharSequence charSequence) {
- this(charSequence.toString().getBytes(Charset.forName("US-ASCII")));
- }
-
- /**
- * Converts an existing byte sequence to a byte array, creating the byte array only if necessary.
- * @param sequence The sequence to be converted.
- * @return If {@code sequence} is null, returns null.
- * If {@code sequence} is already a {@link ByteArray} instance, returns that instance.
- * In all other cases, returns a newly-created {@link ByteArray} instance containing the bytes in {@code sequence}.
- */
- public static ByteArray fromByteSequence(final ByteSequence sequence) {
- if (sequence == null) {
- return null;
- }
- if (sequence instanceof ByteArray) {
- return (ByteArray) sequence;
- }
- return new ByteArray(sequence);
- }
-
- /**
- * Converts a char sequence to a byte array, check first to make sure it is not null.
- * @param sequence The sequence to be converted.
- * @return If {@code sequence} is null, returns null.
- * In all other cases, returns a newly-created {@link ByteArray} instance containing the bytes in {@code sequence}.
- */
- public static ByteArray fromCharSequence(final CharSequence sequence) {
- if (sequence == null) {
- return null;
- }
- return new ByteArray(sequence);
- }
-
- /**
- * Creates a ByteArray instance from a character sequence in which each character is expected to be the ASCII
- * representation of a hexadecimal digit, i.e. in the range 0-9, A-F, or a-f.
- * @param charSequence The char sequence to be converted into a byte array. This must have an even length.
- * @return If {@code charSequence} is null, returns null.
- * In all other cases, returns a new byte array.
- * @throws IllegalArgumentException If {@code charSequence} does not contain an even number of characters.
- */
- public static ByteArray fromHexCharSequence(final CharSequence charSequence) {
- if (charSequence == null) {
- return null;
- }
- if (NumberUtils.isOdd(charSequence.length())) {
- throw new IllegalArgumentException("The CharSequence must be of even length.");
- }
- final int arraySize = charSequence.length() / 2;
- final byte[] bytes = new byte[arraySize];
- int charIndex = 0;
- int arrayIndex = 0;
- while (arrayIndex < arraySize) {
- final byte parsedByte = ByteUtils.fromHexChars(charSequence, charIndex);
- bytes[arrayIndex] = parsedByte;
- charIndex += 2;
- arrayIndex ++;
- }
- return new ByteArray(bytes);
- }
-
- /**
- * Creates a ByteArray instance from a byte sequence in which each byte is expected to be the ASCII
- * representation of a hexadecimal digit, i.e. in the range 0-9, A-F, or a-f.
- * @param byteSequence The byte sequence to be converted into a byte array. This must have an even length.
- * @return If {@code byteSequence} is null, returns null.
- * In all other cases, returns a new byte array.
- * @throws IllegalArgumentException If {@code byteSequence} does not contain an even number of characters.
- */
- public static ByteArray fromHexByteSequence(final ByteSequence byteSequence) {
- if (byteSequence == null) {
- return null;
- }
- if (NumberUtils.isOdd(byteSequence.length())) {
- throw new IllegalArgumentException("The ByteSequence must be of even length.");
- }
- final int arraySize = byteSequence.length() / 2;
- final byte[] bytes = new byte[arraySize];
- int charIndex = 0;
- int arrayIndex = 0;
- while (arrayIndex < arraySize) {
- final byte highOrderByte = byteSequence.byteAt(charIndex);
- final byte lowOrderByte = byteSequence.byteAt(charIndex + 1);
- final byte parsedByte = ByteUtils.fromHexChars(highOrderByte, lowOrderByte);
- bytes[arrayIndex] = parsedByte;
- charIndex += 2;
- arrayIndex ++;
- }
- return new ByteArray(bytes);
- }
-
- @Override
- public int length() {
- return this.array.length;
- }
-
- @Override
- public byte byteAt(final int index) {
- return this.array[index];
- }
-
- @Override
- public ByteArray subSequence(final int start, final int end) {
- return new ByteArray(this.array, start, end - start);
- }
-
- @Override
- public byte[] toArray() {
- /* Return a defensive copy of the array. */
- return Arrays.copyOf(this.array, this.array.length);
- }
-
-// @Override
- public ByteArray toByteArray() {
- return this;
- }
-
- @Override
- public boolean isNativeCharSequence() {
- return false;
- }
-
- @Override
- public CharSequence getNativeCharSequence() {
- return null;
- }
-
- @Override
- public boolean isMutable() {
- return false;
- }
-
- @Override
- public ByteSequenceMutable asMutable() {
- return null;
- }
-
-}
Deleted: trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArrayBuilder.java 2021-01-15 18:58:47 UTC (rev 11795)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteArrayBuilder.java 2021-01-15 19:13:51 UTC (rev 11796)
@@ -1,413 +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:
- * Carlos Villegas <ca...@un...> (Original author)
- */
-
-package org.foray.common.data;
-
-import org.axsl.common.sequence.ByteSequence;
-import org.axsl.common.sequence.ByteSequenceMutable;
-import org.axsl.common.sequence.ByteSequencePlus;
-
-import org.apache.commons.io.IOUtils;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-
-/**
- * A mutable array of bytes.
- * Just as {@link ByteArray} is analogous to {@link java.lang.String}, and {@link ByteSequence} is analogous to
- * {@link CharSequence}, this class is analogous to {@link StringBuilder}.
- * Similar to {@link StringBuilder}, it will resize itself as necessary.
- */
-public class ByteArrayBuilder extends AbstractByteSequence implements ByteSequenceMutable, Serializable {
-
- /**
- * The maximum size of array to allocate (unless necessary).
- * Some VMs reserve some header words in an array.
- * Attempts to allocate larger arrays may result in OutOfMemoryError: Requested array size exceeds VM limit.
- * This value is based on {@link java.lang.AbstractStringBuilder}.MAX_ARRAY_SIZE.
- * @see java.lang.AbstractStringBuilder
- */
- public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
-
- /** Constant needed for serialization. */
- static final long serialVersionUID = 977379027446677063L;
-
- /** Default Capacity increment size. */
- private static final int DEFAULT_BLOCK_SIZE = 2048;
-
- /** Capacity increment size. */
- private int blockSize = ByteArrayBuilder.DEFAULT_BLOCK_SIZE;
-
- /** The encapsulated array. */
- private byte[] backingArray;
-
- /** Index to to the next free item in {@link #backingArray}. */
- private int nextIndex;
-
- /**
- * No-argument constructor.
- */
- public ByteArrayBuilder() {
- this(ByteArrayBuilder.DEFAULT_BLOCK_SIZE);
- }
-
- /**
- * Constructor.
- * @param capacity The initial capacity, in bytes, of the backing array.
- */
- public ByteArrayBuilder(final int capacity) {
- if (capacity > 0) {
- this.blockSize = capacity;
- } else {
- this.blockSize = ByteArrayBuilder.DEFAULT_BLOCK_SIZE;
- }
- this.backingArray = new byte[this.blockSize];
- this.nextIndex = 0;
- }
-
- /**
- * Returns the number of elements used in the backing array.
- * @return The number of elements used in the backing array.
- */
- public int length() {
- return this.nextIndex;
- }
-
- /**
- * Returns the current capacity of the backing array, i.e. the number of items that the array can hold without
- * needing to increase its size.
- * @return The currect capacity of the backing array.
- */
- public int capacity() {
- return this.backingArray.length;
- }
-
- /**
- * Adds one byte.
- * @param value The byte to be added.
- * @return this.
- */
- public ByteArrayBuilder append(final byte value) {
- ensureCapacity(1);
- set(this.nextIndex, value);
- this.nextIndex ++;
- return this;
- }
-
- public ByteArrayBuilder append(final byte[] bytes) {
- ensureCapacity(length() + bytes.length);
- System.arraycopy(bytes, 0, this.backingArray, this.nextIndex, bytes.length);
- this.nextIndex += bytes.length;
- return this;
- }
-
- /**
- * Adds the content of an input stream.
- * @param stream The input stream whose content should be added to this array.
- * @return this.
- * @throws IOException For errors reading from {@code stream}.
- */
- public ByteArrayBuilder append(final InputStream stream) throws IOException {
- final byte[] array = IOUtils.toByteArray(stream);
- if (length() < 1) {
- this.backingArray = array;
- this.nextIndex = array.length;
- } else {
- append(array);
- }
- return this;
- }
-
- public ByteArrayBuilder append(final CharSequence charSequence) {
- final Charset charset = Charset.forName("US-ASCII");
- return append(charSequence, charset);
- }
-
- public ByteArrayBuilder append(final CharSequence charSequence, final Charset charset) {
- if (charSequence == null) {
- return this;
- }
- final byte[] bytes = charSequence.toString().getBytes(charset);
- append(bytes);
- return this;
- }
-
- public ByteArrayBuilder append(final CharSequence charSequence, final String charsetName) {
- final Charset charset = Charset.forName(charsetName);
- final byte[] bytes = charSequence.toString().getBytes(charset);
- append(bytes);
- return this;
- }
-
- public ByteArrayBuilder append(final char theChar) {
- final Charset charset = Charset.forName("US-ASCII");
- return append(theChar, charset);
- }
-
- public ByteArrayBuilder append(final char theChar, final Charset charset) {
- final byte[] bytes = Character.toString(theChar).getBytes(charset);
- append(bytes);
- return this;
- }
-
- public ByteArrayBuilder append(final char theChar, final String charsetName) {
- final Charset charset = Charset.forName(charsetName);
- return append(theChar, charset);
- }
-
- public ByteArrayBuilder append(final ByteSequencePlus byteSequence) {
- final byte[] bytes = byteSequence.toArray();
- append(bytes);
- return this;
- }
-
- public ByteArrayBuilder append(final long theLong) {
- append(Long.toString(theLong));
- return this;
- }
-
- /**
- * Place an item in the vector at a specific index.
- * @param index The 0-based index into the vector.
- * @param val The byte value to be placed in the vector.
- */
- public void set(final int index, final byte val) {
- this.backingArray[index] = val;
- }
-
- /**
- * Retrieve a value from a specific index in the vector.
- * @param index The 0-based index whose value should be returned.
- * @return The value at {@code index}.
- */
- public byte get(final int index) {
- return this.backingArray[index];
- }
-
- /**
- * Allocates or uses a specified number of elements (bytes).
- * If needed, this method automatically increases the vector's capacity.
- * @param size The number of elements (bytes) to be allocated.
- * @return The index to the beginning of the allocated elements (bytes).
- */
- public int alloc(final int size) {
- final int index = this.nextIndex;
- if (this.nextIndex + size >= this.backingArray.length) {
- final byte[] newArray = new byte[this.backingArray.length
- + this.blockSize];
- System.arraycopy(this.backingArray, 0, newArray, 0,
- this.backingArray.length);
- this.backingArray = newArray;
- }
- this.nextIndex += size;
- return index;
- }
-
- /**
- * Ensures that the capacity is at least equal to the specified minimum.
- * If the current capacity is less than the argument, then a new internal
- * array is allocated with greater capacity. The new capacity is the
- * larger of:
- * <ul>
- * <li>The {@code minimumCapacity} argument.
- * <li>Twice the old capacity, plus {@code 2}.
- * </ul>
- * If the {@code minimumCapacity} argument is nonpositive, this
- * method takes no action and simply returns.
- * Note that subsequent operations on this object can reduce the
- * actual capacity below that requested here.
- *
- * @param minimumCapacity the minimum desired capacity.
- * @see StringBuilder#ensureCapacity(int)
- */
- public void ensureCapacity(final int minimumCapacity) {
- if (minimumCapacity > 0) {
- ensureCapacityInternal(minimumCapacity);
- }
- }
-
- /**
- * For positive values of {@code minimumCapacity}, this method
- * behaves like {@code ensureCapacity}, however it is never
- * synchronized.
- * If {@code minimumCapacity} is non positive due to numeric
- * overflow, this method throws {@code OutOfMemoryError}.
- * @param minimumCapacity the minimum desired capacity.
- * @see {@link StringBuilder#ensureCapacity(int)}
- */
- private void ensureCapacityInternal(final int minimumCapacity) {
- // overflow-conscious code
- if (minimumCapacity - this.backingArray.length > 0) {
- backingArray = Arrays.copyOf(backingArray,
- newCapacity(minimumCapacity));
- }
- }
-
- /**
- * Returns a capacity at least as large as the given minimum capacity.
- * Returns the current capacity increased by the same amount + 2 if
- * that suffices.
- * Will not return a capacity greater than {@code MAX_ARRAY_SIZE}
- * unless the given minimum capacity is greater than that.
- *
- * @param minCapacity the desired minimum capacity
- * @return The new capacity.
- * @throws OutOfMemoryError if minCapacity is less than zero or
- * greater than Integer.MAX_VALUE
- */
- private int newCapacity(final int minCapacity) {
- // overflow-conscious code
- int newCapacity = (this.backingArray.length << 1) + 2;
- if (newCapacity - minCapacity < 0) {
- newCapacity = minCapacity;
- }
- return (newCapacity <= 0 || MAX_ARRAY_SIZE - newCapacity < 0)
- ? hugeCapacity(minCapacity)
- : newCapacity;
- }
-
- private int hugeCapacity(final int minCapacity) {
- if (Integer.MAX_VALUE - minCapacity < 0) { // overflow
- throw new OutOfMemoryError();
- }
- return (minCapacity > MAX_ARRAY_SIZE)
- ? minCapacity : MAX_ARRAY_SIZE;
- }
-
- /**
- * Sets the capacity of this vector equal to its size, to that there is no
- * unused capacity.
- */
- public void trimToSize() {
- if (this.nextIndex < this.backingArray.length) {
- final byte[] aux = new byte[this.nextIndex];
- System.arraycopy(this.backingArray, 0, aux, 0, this.nextIndex);
- this.backingArray = aux;
- }
- }
-
- @Override
- public byte byteAt(final int index) {
- if ((index < 0) || (index >= this.nextIndex)) {
- throw new IndexOutOfBoundsException("Index out of bounds: " + index);
- }
- return this.backingArray[index];
- }
-
- /**
- * Convenience method that sets the value of the last byte in the builder.
- * @param newValue The new value for the last byte in the builder.
- */
- public void setLastElement(final byte newValue) {
- final int index = length() - 1;
- set(index, newValue);
- }
-
- @Override
- public ByteArray subSequence(final int start, final int end) {
- return new ByteArray(this.backingArray, start, end - start);
- }
-
- @Override
- public byte[] toArray() {
- return Arrays.copyOf(this.backingArray, this.nextIndex);
- }
-
-// @Override
- public ByteArray toByteArray() {
- return new ByteArray(toArray());
- }
-
- @Override
- public boolean isNativeCharSequence() {
- return false;
- }
-
- @Override
- public CharSequence getNativeCharSequence() {
- return null;
- }
-
- @Override
- public boolean isMutable() {
- return true;
- }
-
- /**
- * Resets the length of this sequence to a specified length.
- * The <em>capacity</em> of the sequence remains unchanged unless it needs to increase to accommodate a bigger size.
- * <p>If {@code newLength} is greater than the current length, the existing bytes in the sequence are unchanged, and
- * the bytes that have effectively been appended to the sequence are filled with zero.</p>
- * @param newLength The new length of this sequence. Must be greater than or equal to {@code 0}.
- * @throws IndexOutOfBoundsException If {@code newLength} is negative.
- */
- public void setLength(final int newLength) {
- if (newLength < 0) {
- throw new StringIndexOutOfBoundsException(newLength);
- }
- ensureCapacityInternal(newLength);
-
- while (this.nextIndex < newLength) {
- this.backingArray[this.nextIndex] = 0;
- this.nextIndex ++;
- }
- this.nextIndex = newLength;
- }
-
- /**
- * Resets the length of this sequence to a 0, allowing it to be reused.
- * The <em>capacity</em> of the sequence remains unchanged.
- */
- public void clear() {
- setLength(0);
- }
-
- @Override
- public void sort() {
- Arrays.sort(this.backingArray);
- }
-
- @Override
- public int binarySearch(final byte value) {
- return Arrays.binarySearch(this.backingArray, 0, length(), value);
- }
-
- @Override
- public ByteSequenceMutable asMutable() {
- return this;
- }
-
-}
Deleted: trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteSequenceChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteSequenceChars.java 2021-01-15 18:58:47 UTC (rev 11795)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/ByteSequenceChars.java 2021-01-15 19:13:51 UTC (rev 11796)
@@ -1,133 +0,0 @@
-/*
- * Copyright 2020 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.common.data;
-
-import org.foray.common.primitive.CharacterUtils;
-import org.foray.common.primitive.NumberUtils;
-
-import org.axsl.common.sequence.ByteSequence;
-import org.axsl.common.sequence.ByteSequenceMutable;
-
-import java.io.Serializable;
-
-/**
- * <p>Wrapper around a {@link CharSequence}, allowing the sequence of chars to be viewed as a sequence of bytes.
- * This is useful for cases where either a sequence of chars or a sequence of bytes is required.
- * The {@link String} or other {@link CharSequence} can be wrapped in an instance of this class, preserving its "char"
- * nature.</p>
- *
- * <p>However, instances of this class are merely a <em>view</em> of the wrapped {@link CharSequence}.
- * There is no copying of data between them at any time.
- * Therefore, even though instances of this class are themselves immutable, the underlying data wrapped in them can be
- * changed.
- * If converting from chars to bytes for an immutable sequence of bytes is desired, use
- * {@link ByteArray#ByteArray(CharSequence)} instead.
- * </p>
- */
-public class ByteSequenceChars extends AbstractByteSequence implements ByteSequence, Serializable {
-
- /** Constant needed for serialization. */
- private static final long serialVersionUID = -8521627567574491374L;
-
- /** The internal sequence. */
- private CharSequence sequence;
-
- /**
- * Constructor.
- * @param sequence The sequence to be wrapped.
- * No copying of this sequence is done.
- * @throws NullPointerException If {@code sequence} is null.
- */
- public ByteSequenceChars(final CharSequence sequence) {
- if (sequence == null) {
- throw new NullPointerException("The CharSequence cannot be null.");
- }
- this.sequence = sequence;
- }
-
- @Override
- public int length() {
- ...
[truncated message content] |
|
From: <vic...@us...> - 2021-01-15 18:58:55
|
Revision: 11795
http://sourceforge.net/p/foray/code/11795
Author: victormote
Date: 2021-01-15 18:58:47 +0000 (Fri, 15 Jan 2021)
Log Message:
-----------
Add primitive iterator implementations for the primitive sequence classes. Conform to related aXSL changes in the primitive sequence interfaces.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
Added Paths:
-----------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractByteSequence.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -29,7 +29,9 @@
package org.foray.common.data;
import org.foray.common.primitive.ByteUtils;
+import org.foray.common.sequence.ByteSequenceIterator;
+import org.axsl.common.sequence.BytePrimitiveIterator;
import org.axsl.common.sequence.ByteSequence;
import org.axsl.common.sequence.ByteSequencePlus;
@@ -660,4 +662,14 @@
return this;
}
+ @Override
+ public BytePrimitiveIterator iterator() {
+ return new ByteSequenceIterator(this);
+ }
+
+ @Override
+ public BytePrimitiveIterator iteratorReverse() {
+ return new ByteSequenceIterator(this, true);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractIntSequence.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,7 @@
package org.foray.common.data;
+import org.axsl.common.sequence.IntPrimitiveIterator;
import org.axsl.common.sequence.IntSequencePlus;
/**
@@ -52,12 +53,12 @@
}
@Override
- public IntSequenceIterator iterator() {
+ public IntPrimitiveIterator iterator() {
return new org.foray.common.data.IntSequenceIterator(this);
}
@Override
- public IntSequenceIterator iteratorReverse() {
+ public IntPrimitiveIterator iteratorReverse() {
return new org.foray.common.data.IntSequenceIterator(this, true);
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/CharArrayBuilder.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,9 @@
package org.foray.common.data;
+import org.foray.common.sequence.CharSequenceIterator;
+
+import org.axsl.common.sequence.CharPrimitiveIterator;
import org.axsl.common.sequence.CharSequenceMutable;
import org.axsl.common.sequence.CharSequencePlus;
@@ -295,4 +298,14 @@
return this;
}
+ @Override
+ public CharPrimitiveIterator iterator() {
+ return new CharSequenceIterator(this);
+ }
+
+ @Override
+ public CharPrimitiveIterator iteratorReverse() {
+ return new CharSequenceIterator(this, true);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/IntSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -35,7 +35,7 @@
/**
* Iterates an instance of {@link IntSequence}.
*/
-public class IntSequenceIterator implements org.axsl.common.sequence.IntSequenceIterator {
+public class IntSequenceIterator implements org.axsl.common.sequence.IntPrimitiveIterator {
/** The sequence being iterated. */
private IntSequence sequence;
@@ -94,7 +94,7 @@
* Check {@link #hasNext()} first to avoid this exception.
* @see java.util.Iterator#next()
*/
- public int next() {
+ public int nextInt() {
if (! hasNext()) {
throw new NoSuchElementException();
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArray.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,9 @@
package org.foray.common.data;
+import org.foray.common.sequence.LongSequenceIterator;
+
+import org.axsl.common.sequence.LongPrimitiveIterator;
import org.axsl.common.sequence.LongSequence;
import org.axsl.common.sequence.LongSequenceMutable;
import org.axsl.common.sequence.LongSequencePlus;
@@ -137,4 +140,14 @@
return null;
}
+ @Override
+ public LongPrimitiveIterator iterator() {
+ return new LongSequenceIterator(this);
+ }
+
+ @Override
+ public LongPrimitiveIterator iteratorReverse() {
+ return new LongSequenceIterator(this, true);
+ }
+
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/LongArrayBuilder.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -28,6 +28,9 @@
package org.foray.common.data;
+import org.foray.common.sequence.LongSequenceIterator;
+
+import org.axsl.common.sequence.LongPrimitiveIterator;
import org.axsl.common.sequence.LongSequence;
import org.axsl.common.sequence.LongSequenceMutable;
import org.axsl.common.sequence.LongSequencePlus;
@@ -295,4 +298,14 @@
return this;
}
+ @Override
+ public LongPrimitiveIterator iterator() {
+ return new LongSequenceIterator(this);
+ }
+
+ @Override
+ public LongPrimitiveIterator iteratorReverse() {
+ return new LongSequenceIterator(this, true);
+ }
+
}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/BooleanSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.BooleanPrimitiveIterator;
+import org.axsl.common.sequence.BooleanSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link BooleanSequence}.
+ */
+public class BooleanSequenceIterator implements BooleanPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private BooleanSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public BooleanSequenceIterator(final BooleanSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public BooleanSequenceIterator(final BooleanSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public boolean nextBoolean() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final boolean returnValue = sequence.booleanAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final boolean returnValue = sequence.booleanAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.BytePrimitiveIterator;
+import org.axsl.common.sequence.ByteSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link ByteSequence}.
+ */
+public class ByteSequenceIterator implements BytePrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private ByteSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public ByteSequenceIterator(final ByteSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public ByteSequenceIterator(final ByteSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public byte nextByte() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final byte returnValue = sequence.byteAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final byte returnValue = sequence.byteAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.CharPrimitiveIterator;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link CharSequence}.
+ */
+public class CharSequenceIterator implements CharPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private CharSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public CharSequenceIterator(final CharSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public CharSequenceIterator(final CharSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public char nextChar() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final char returnValue = sequence.charAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final char returnValue = sequence.charAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.LongPrimitiveIterator;
+import org.axsl.common.sequence.LongSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link LongSequence}.
+ */
+public class LongSequenceIterator implements LongPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private LongSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public LongSequenceIterator(final LongSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public LongSequenceIterator(final LongSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public long nextLong() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final long returnValue = sequence.longAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final long returnValue = sequence.longAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Added: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java (rev 0)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortSequenceIterator.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.sequence;
+
+import org.axsl.common.sequence.ShortPrimitiveIterator;
+import org.axsl.common.sequence.ShortSequence;
+
+import java.util.NoSuchElementException;
+
+/**
+ * Iterates an instance of {@link ShortSequence}.
+ */
+public class ShortSequenceIterator implements ShortPrimitiveIterator {
+
+ /** The sequence being iterated. */
+ private ShortSequence sequence;
+
+ /** The index to the "next" item to return. Conceptually, the iterator pointer sits between {@code index - 1} and
+ * {@code index}. */
+ private int index;
+
+ /** Indicates whether this iterator iterates in reverse order. */
+ private boolean reverseOrder;
+
+ /**
+ * Constructor for the simple case of iterating starting at the first element, and progressing toward the last.
+ * @param sequence The sequence to be iterated.
+ */
+ public ShortSequenceIterator(final ShortSequence sequence) {
+ this(sequence, false);
+ }
+
+ /**
+ * Constructor for the case where we wish to iterate over the content in reverse order.
+ * @param sequence The sequence to be iterated.
+ * @param reverseOrder Indicates whether this iterator should progress forward, from lower index to
+ * higher index (false), or reverse, from higher index to lower (true);
+ */
+ public ShortSequenceIterator(final ShortSequence sequence, final boolean reverseOrder) {
+ this.sequence = sequence;
+ this.reverseOrder = reverseOrder;
+ if (reverseOrder) {
+ this.index = sequence.length();
+ } else {
+ this.index = 0;
+ }
+
+ }
+
+ /**
+ * Indicates whether this iterator has at least one more element.
+ * Follows the semantics of {@link java.util.Iterator#hasNext()}.
+ * @return True if and only if this iterator can return at least one more element.
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (this.reverseOrder) {
+ return this.index > 0;
+ } else {
+ return this.index < this.sequence.length();
+ }
+ }
+
+ /**
+ * Returns the next element in the iteration.
+ * Follows the semantics of {@link java.util.Iterator#next()}.
+ * @return The next element in the iteration.
+ * @throws NoSuchElementException If the iteration has no more elements.
+ * Check {@link #hasNext()} first to avoid this exception.
+ * @see java.util.Iterator#next()
+ */
+ public short nextShort() {
+ if (! hasNext()) {
+ throw new NoSuchElementException();
+ }
+ if (this.reverseOrder) {
+ final short returnValue = sequence.shortAt(this.index - 1);
+ this.index --;
+ return returnValue;
+ } else {
+ final short returnValue = sequence.shortAt(this.index);
+ this.index ++;
+ return returnValue;
+ }
+ }
+
+}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/package-info.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -27,6 +27,7 @@
*/
/**
+ * Implementations of the interfaces in {@link org.axsl.common.sequence}.
* Wrappers of primitive arrays, intended to make array handling more safe and more flexible, and to make code using
* them more fluent.
*/
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -45,21 +45,21 @@
public void testForwardIterator() {
final IntSequenceIterator out = new IntSequenceIterator(array1);
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(5, out.next());
+ Assert.assertEquals(5, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-5, out.next());
+ Assert.assertEquals(-5, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(100, out.next());
+ Assert.assertEquals(100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-100, out.next());
+ Assert.assertEquals(-100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MAX_VALUE, out.next());
+ Assert.assertEquals(Integer.MAX_VALUE, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MIN_VALUE, out.next());
+ Assert.assertEquals(Integer.MIN_VALUE, out.nextInt());
Assert.assertFalse(out.hasNext());
try {
- out.next();
+ out.nextInt();
Assert.fail("NoSuchElementException expected here.");
} catch (final NoSuchElementException e) {
/* This is the expected path. */
@@ -70,21 +70,21 @@
public void testReverseIterator() {
final IntSequenceIterator out = new IntSequenceIterator(array1, true);
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MIN_VALUE, out.next());
+ Assert.assertEquals(Integer.MIN_VALUE, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(Integer.MAX_VALUE, out.next());
+ Assert.assertEquals(Integer.MAX_VALUE, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-100, out.next());
+ Assert.assertEquals(-100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(100, out.next());
+ Assert.assertEquals(100, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(-5, out.next());
+ Assert.assertEquals(-5, out.nextInt());
Assert.assertTrue(out.hasNext());
- Assert.assertEquals(5, out.next());
+ Assert.assertEquals(5, out.nextInt());
Assert.assertFalse(out.hasNext());
try {
- out.next();
+ out.nextInt();
Assert.fail("NoSuchElementException expected here.");
} catch (final NoSuchElementException e) {
/* This is the expected path. */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfCrossRefInfo.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -30,10 +30,11 @@
import org.foray.common.data.ByteArrayBuilder;
import org.foray.common.data.IntArrayBuilder;
-import org.foray.common.data.IntSequenceIterator;
import org.foray.common.primitive.StringUtils;
import org.foray.pdf.object.PdfObject;
+import org.axsl.common.sequence.IntPrimitiveIterator;
+
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@@ -104,7 +105,7 @@
* The deferred list is conceptually stack-like, so the iterator returns the object IDs in reverse order.
* @return A new iterator over the deferred indirect object IDs.
*/
- public IntSequenceIterator iteratorForDeferred() {
+ public IntPrimitiveIterator iteratorForDeferred() {
return this.indirectWriteLast.iteratorReverse();
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-15 17:26:35 UTC (rev 11794)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-15 18:58:47 UTC (rev 11795)
@@ -38,7 +38,6 @@
import org.foray.common.ColorUtil;
import org.foray.common.data.ByteArrayBuilder;
-import org.foray.common.data.IntSequenceIterator;
import org.foray.pdf.PdfConstants;
import org.foray.pdf.PdfCrossRefEntry;
import org.foray.pdf.PdfCrossRefInfo;
@@ -46,6 +45,7 @@
import org.foray.pdf.PdfParser;
import org.axsl.common.Gradient;
+import org.axsl.common.sequence.IntPrimitiveIterator;
import org.axsl.font.Font;
import org.axsl.font.FontUse;
import org.axsl.graphic.Graphic;
@@ -289,9 +289,9 @@
}
private void writeDeferredIndirectObjects(final OutputStream output) throws PdfException {
- final IntSequenceIterator deferredObjectIterator = this.xrefInfo.iteratorForDeferred();
+ final IntPrimitiveIterator deferredObjectIterator = this.xrefInfo.iteratorForDeferred();
while (deferredObjectIterator.hasNext()) {
- final int objectId = deferredObjectIterator.next();
+ final int objectId = deferredObjectIterator.nextInt();
final PdfCrossRefEntry xref = this.xrefInfo.getTableEntry(objectId);
final PdfObject o = xref.getObject();
xref.setOffset(this.position);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|