foray-commit Mailing List for FOray (Page 55)
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
(3) |
Dec
|
|
From: <vic...@us...> - 2022-02-01 16:37:24
|
Revision: 12526
http://sourceforge.net/p/foray/code/12526
Author: victormote
Date: 2022-02-01 16:37:22 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Doc changes only.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-02-01 16:34:44 UTC (rev 12525)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-02-01 16:37:22 UTC (rev 12526)
@@ -65,6 +65,8 @@
* The specified output order for entries in this dictionary.
* If not null, this list will be used.
* Otherwise, the list in {@link #getOutputOrder()} will be used.
+ * This is probably not useful for generated documents, but may be useful for documents that are parsed from a
+ * serialized form that wish to re-serialize the entries in the original order.
*/
private List<String> outputOrder;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 16:34:47
|
Revision: 12525
http://sourceforge.net/p/foray/code/12525
Author: victormote
Date: 2022-02-01 16:34:44 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Doc changes only.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-02-01 15:43:04 UTC (rev 12524)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-02-01 16:34:44 UTC (rev 12525)
@@ -44,9 +44,19 @@
import java.util.List;
/**
- * A PDF array object.
+ * <p>A PDF array object.
+ * A PDF array is not much like an array, but more like a dictionary that is accessed by a positional index.
+ * Per the PDF Reference, 6th Edition:</p>
+ *
+ * <blockquote>Unlike arrays in many other computer languages, PDF arrays may be heterogeneous; that is, an array’s
+ * elements may be any combination of numbers, strings, dictionaries, or any other objects, including other
+ * arrays.</blockquote>
+ *
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.2.5"
*/
public class PdfArray extends PdfObject {
+ /* CAVEAT: It is tempting to think that an "array" class should have a generic qualifier. See the class javadocs
+ * for explanation of why that is not appropriate. */
/** Format for type mismatch error messages. */
private static final String TYPE_EXCEPTION_FORMAT = "Type mismatch at index {0}. Expected: {1}, Actual: {2}.";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 15:43:07
|
Revision: 12524
http://sourceforge.net/p/foray/code/12524
Author: victormote
Date: 2022-02-01 15:43:04 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Use standard method to retrieve and cast for type-specific getters.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-02-01 14:11:17 UTC (rev 12523)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-02-01 15:43:04 UTC (rev 12524)
@@ -48,6 +48,9 @@
*/
public class PdfArray extends PdfObject {
+ /** Format for type mismatch error messages. */
+ private static final String TYPE_EXCEPTION_FORMAT = "Type mismatch at index {0}. Expected: {1}, Actual: {2}.";
+
/** The contents of the array. */
private List<PdfObject> arrayContents = new ArrayList<PdfObject>();
@@ -137,15 +140,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfTextString}.
*/
public PdfTextString getPdfTextString(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfTextString) {
- return (PdfTextString) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfTextString.class);
}
public String getString(final int index) {
@@ -160,15 +155,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfHexString}.
*/
public PdfHexString getPdfHexString(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfHexString) {
- return (PdfHexString) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfHexString.class);
}
/**
@@ -178,15 +165,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfInteger}.
*/
public PdfInteger getPdfInteger(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfInteger) {
- return (PdfInteger) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfInteger.class);
}
public int getInteger(final int index) {
@@ -201,15 +180,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfReal}.
*/
public PdfReal getPdfReal(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfReal) {
- return (PdfReal) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfReal.class);
}
public BigDecimal getBigDecimal(final int index) {
@@ -224,15 +195,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfDate}.
*/
public PdfDate getPdfDate(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfDate) {
- return (PdfDate) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfDate.class);
}
public Date getDate(final int index) {
@@ -247,15 +210,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfDictionary}.
*/
public PdfDictionary getPdfDictionary(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfDictionary) {
- return (PdfDictionary) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfDictionary.class);
}
/**
@@ -265,15 +220,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfName}.
*/
public PdfName getPdfName(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfName) {
- return (PdfName) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfName.class);
}
/**
@@ -283,15 +230,7 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfObjectReference}.
*/
public PdfObjectReference getPdfObjectReference(final int index) {
- final PdfObject value = get(index);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfObjectReference) {
- return (PdfObjectReference) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+ return retrieve(index, PdfObjectReference.class);
}
/**
@@ -301,15 +240,30 @@
* @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfArray}.
*/
public PdfArray getPdfArray(final int index) {
+ return retrieve(index, PdfArray.class);
+ }
+
+ /**
+ * Retrieves an object from the internal array and casts it to its expected type.
+ * @param index The index at which the value should be found.
+ * @param expectedType The type expected for {@code value}.
+ * @param <T> The subclass of {@link PdfObject} which should be returned by this method.
+ * @return The array element cast to its expected type, or null if the array returned null.
+ * @throws IllegalArgumentException If the expected type does not match the actual type.
+ */
+ private <T extends PdfObject> T retrieve(final int index, final Class<T> expectedType) {
final PdfObject value = get(index);
if (value == null) {
return null;
}
- if (value instanceof PdfArray) {
- return (PdfArray) value;
+ if (expectedType.isInstance(value)) {
+ return expectedType.cast(value);
}
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
+
+ /* The retrieved value is of the wrong type. Throw an exception. */
+ final String message = String.format(
+ TYPE_EXCEPTION_FORMAT, index, expectedType.getName(), value.getClass().getName());
+ throw new IllegalArgumentException(message);
}
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-02-01 14:11:17 UTC (rev 12523)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-02-01 15:43:04 UTC (rev 12524)
@@ -53,6 +53,9 @@
*/
public abstract class PdfDictionary extends PdfObject {
+ /** Format for type mismatch error messages. */
+ private static final String TYPE_EXCEPTION_FORMAT = "Type mismatch for key [{0}]. Expected: {1}, Actual: {2}.";
+
/** Internal map of the dictionary. */
private Map<String, PdfObject> entries = new HashMap<String, PdfObject>();
/* TODO: The key to this map should technically be a PdfName. However, this seems unimportant at the
@@ -213,15 +216,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfTextString}.
*/
public PdfTextString getPdfTextString(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfTextString) {
- return (PdfTextString) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfTextString.class);
}
public String getString(final String key) {
@@ -236,15 +231,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfHexString}.
*/
public PdfHexString getPdfHexString(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfHexString) {
- return (PdfHexString) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfHexString.class);
}
/**
@@ -254,15 +241,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfInteger}.
*/
public PdfInteger getPdfInteger(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfInteger) {
- return (PdfInteger) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfInteger.class);
}
public int getInteger(final String key) {
@@ -277,15 +256,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfReal}.
*/
public PdfReal getPdfReal(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfReal) {
- return (PdfReal) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfReal.class);
}
public BigDecimal getBigDecimal(final String key) {
@@ -300,15 +271,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfDate}.
*/
public PdfDate getPdfDate(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfDate) {
- return (PdfDate) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfDate.class);
}
public Date getDate(final String key) {
@@ -323,15 +286,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfDictionary}.
*/
public PdfDictionary getPdfDictionary(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfDictionary) {
- return (PdfDictionary) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfDictionary.class);
}
/**
@@ -341,15 +296,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfName}.
*/
public PdfName getPdfName(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfName) {
- return (PdfName) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfName.class);
}
/**
@@ -359,15 +306,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfObjectReference}.
*/
public PdfObjectReference getPdfObjectReference(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfObjectReference) {
- return (PdfObjectReference) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfObjectReference.class);
}
/**
@@ -377,15 +316,7 @@
* @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfArray}.
*/
public PdfArray getPdfArray(final String key) {
- final PdfObject value = get(key);
- if (value == null) {
- return null;
- }
- if (value instanceof PdfArray) {
- return (PdfArray) value;
- }
- throw new IllegalArgumentException(String.format(
- "Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
+ return retrieve(key, PdfArray.class);
}
/**
@@ -414,4 +345,27 @@
return new PdfTrailer(this);
}
+ /**
+ * Retrieves an object from the internal array and casts it to its expected type.
+ * @param key The key at which the value should be found.
+ * @param expectedType The type expected for {@code value}.
+ * @param <T> The subclass of {@link PdfObject} which should be returned by this method.
+ * @return The array element cast to its expected type, or null if the array returned null.
+ * @throws IllegalArgumentException If the expected type does not match the actual type.
+ */
+ private <T extends PdfObject> T retrieve(final String key, final Class<T> expectedType) {
+ final PdfObject value = get(key);
+ if (value == null) {
+ return null;
+ }
+ if (expectedType.isInstance(value)) {
+ return expectedType.cast(value);
+ }
+
+ /* The retrieved value is of the wrong type. Throw an exception. */
+ final String message = String.format(
+ TYPE_EXCEPTION_FORMAT, key, expectedType.getName(), value.getClass().getName());
+ throw new IllegalArgumentException(message);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 14:11:20
|
Revision: 12523
http://sourceforge.net/p/foray/code/12523
Author: victormote
Date: 2022-02-01 14:11:17 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Remove unneeded convenience method.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java
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 2022-02-01 13:56:47 UTC (rev 12522)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceSubset.java 2022-02-01 14:11:17 UTC (rev 12523)
@@ -102,16 +102,10 @@
@Override
public ByteArray subSequence(final int start, final int end) {
- final ByteArray array = toByteArray();
+ final ByteArray array = new ByteArray(this);
return array.subSequence(start, end);
}
-// @Override
- public ByteArray toByteArray() {
- final byte[] bytes = toArray();
- return new ByteArray(bytes);
- }
-
@Override
public ByteSequenceMutable asMutable() {
return null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 13:56:50
|
Revision: 12522
http://sourceforge.net/p/foray/code/12522
Author: victormote
Date: 2022-02-01 13:56:47 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Add missing javadoc, convert throw of IOException to returning a null InputStream.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/ForayEntityResolver.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/ForayEntityResolver.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/ForayEntityResolver.java 2022-02-01 13:42:25 UTC (rev 12521)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/ForayEntityResolver.java 2022-02-01 13:56:47 UTC (rev 12522)
@@ -35,6 +35,7 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -99,8 +100,8 @@
* @param dtdName The name of the DTD to be retrieved.
* @return The appropriate FOray DTD, or null if not found.
*/
- private InputStream getForayDtdAsInputStream(final String dtdName) throws IOException {
- InputStream inputStream = this.getClass().getResourceAsStream("/resources/org/foray/dtds/" + dtdName);
+ private InputStream getForayDtdAsInputStream(final String dtdName) {
+ final InputStream inputStream = this.getClass().getResourceAsStream("/resources/org/foray/dtds/" + dtdName);
if (inputStream == null) {
/* The aXSL DTDs should all be found in jar files resolved by the build system.
@@ -109,15 +110,26 @@
* See build.gradle where the file is copied into the jar file.
* Therefore, we look for the file on the local file system. */
final File file = new File("../foray-00-master/doc/web/dtds/0.1/en/" + dtdName);
- if (file.exists()) {
- inputStream = new FileInputStream(file);
+ if (! file.exists()) {
+ return null;
}
+ try {
+ return new FileInputStream(file);
+ } catch (final FileNotFoundException e) {
+ return null;
+ }
}
return inputStream;
}
- public InputStream getInputStream(final String publicId) throws IOException {
+ /**
+ * Returns an {@link InputStream} for a given public ID.
+ * @param publicId The public ID for which an {@link InputStream} is needed.
+ * @return A newly-created {@link InputStream}, or null if the publicId is not a standard aXSL-FOray resource,
+ * or if the resource cannot be found.
+ */
+ public InputStream getInputStream(final String publicId) {
switch(publicId) {
/* aXSL DTDs. */
case NATURAL_LANGUAGE_PUBLIC_ID: return getAxslDtdAsInputStream("axsl-natural-language.dtd");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 13:42:28
|
Revision: 12521
http://sourceforge.net/p/foray/code/12521
Author: victormote
Date: 2022-02-01 13:42:25 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Conform to aXSL changes: Add standard methods for converting mutable sequences to immutable ones.
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-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-common/src/main/java/org/foray/common/sequence/ShortArray.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/LongArrayBuilderTests.java
trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/AbstractRandomAccessInput.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 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -352,9 +352,9 @@
return Arrays.copyOf(this.backingArray, this.length);
}
-// @Override
- public ByteArray toByteArray() {
- return new ByteArray(toArray());
+ @Override
+ public ByteArray toImmutable() {
+ return new ByteArray(this);
}
@Override
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 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -253,6 +253,11 @@
}
@Override
+ public CharArray toImmutable() {
+ return new CharArray(this);
+ }
+
+ @Override
public char charAt(final int index) {
if ((index < 0) || (index >= this.length)) {
throw new MarkedIndexOutOfBoundsException(index, this.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 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -121,6 +121,11 @@
}
@Override
+ public IntArray toImmutable() {
+ return new IntArray(this);
+ }
+
+ @Override
public String toString() {
return Arrays.toString(toArray());
}
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 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArray.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -74,6 +74,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 LongArray(final LongSequence sequence) {
+ this.array = new long[sequence.length()];
+ for (int index = 0; index < sequence.length(); index ++) {
+ this.array[index] = sequence.longAt(index);
+ }
+ }
+
@Override
public int length() {
return this.array.length;
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 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -113,13 +113,9 @@
return returnArray;
}
- /**
- * Returns the current state of the array as an (immutable) {@link LongArray}.
- * @return The current state of the array.
- */
- public LongArray toLongArray() {
- final long[] theArray = toArray();
- return new LongArray(theArray);
+ @Override
+ public LongArray toImmutable() {
+ return new LongArray(this);
}
@Override
Modified: 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 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArray.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -70,6 +70,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 ShortArray(final ShortSequence sequence) {
+ this.array = new short[sequence.length()];
+ for (int index = 0; index < sequence.length(); index ++) {
+ this.array[index] = sequence.shortAt(index);
+ }
+ }
+
@Override
public int length() {
return this.array.length;
Modified: 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 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -111,13 +111,9 @@
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 ShortArray toImmutable() {
+ return new ShortArray(this);
}
@Override
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/LongArrayBuilderTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/LongArrayBuilderTests.java 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/LongArrayBuilderTests.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -100,7 +100,7 @@
out.append(1);
out.append(2, 3, 4, 5);
final LongArray expected = new LongArray(new long[] {0, 1, 2, 3, 4, 5});
- Assert.assertEquals(expected, out.toLongArray());
+ Assert.assertEquals(expected, out.toImmutable());
}
}
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/format/type1/Type1MetricsSerializer.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -144,7 +144,7 @@
final ByteArrayBuilder builder = new ByteArrayBuilder();
builder.append(is);
is.close();
- final RandomAccessInput input = new ByteSequenceParser(builder.toByteArray());
+ final RandomAccessInput input = new ByteSequenceParser(builder.toImmutable());
final Type1MetricsParser reader = new Type1MetricsParser(getFontServer(), input);
metricsFile = reader.parse();
} catch (final IOException e) {
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -115,7 +115,7 @@
output.close();
final ByteArray actual = new ByteArray(output.toByteArray());
- final ByteArray expected = new ByteArrayBuilder().append(new FileInputStream(baselineFile)).toByteArray();
+ final ByteArray expected = new ByteArrayBuilder().append(new FileInputStream(baselineFile)).toImmutable();
Assert.assertEquals(expected.difference(actual), expected, actual);
}
Modified: trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/AbstractRandomAccessInput.java
===================================================================
--- trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/AbstractRandomAccessInput.java 2022-02-01 13:03:39 UTC (rev 12520)
+++ trunk/foray/foray-zz-attic/src/main/java/org/foray/common/io/AbstractRandomAccessInput.java 2022-02-01 13:42:25 UTC (rev 12521)
@@ -98,7 +98,7 @@
final ByteArrayBuilder builder = new ByteArrayBuilder();
builder.append(dataSource.getInputStream());
dataSource.getInputStream().close();
- return new ByteSequenceParser(builder.toByteArray());
+ return new ByteSequenceParser(builder.toImmutable());
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 13:03:42
|
Revision: 12520
http://sourceforge.net/p/foray/code/12520
Author: victormote
Date: 2022-02-01 13:03:39 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Conform to aXSL changes: Add methods to ByteSequenceMutable for appending chars and CharSequences.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.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 2022-02-01 01:04:57 UTC (rev 12519)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2022-02-01 13:03:39 UTC (rev 12520)
@@ -150,12 +150,7 @@
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}.
- */
+ @Override
public ByteArrayBuilder append(final InputStream stream) throws IOException {
final byte[] array = IOUtils.toByteArray(stream);
if (length() < 1) {
@@ -167,11 +162,13 @@
return this;
}
+ @Override
public ByteArrayBuilder append(final CharSequence charSequence) {
final Charset charset = Charset.forName("US-ASCII");
return append(charSequence, charset);
}
+ @Override
public ByteArrayBuilder append(final CharSequence charSequence, final Charset charset) {
if (charSequence == null) {
return this;
@@ -181,6 +178,7 @@
return this;
}
+ @Override
public ByteArrayBuilder append(final CharSequence charSequence, final String charsetName) {
final Charset charset = Charset.forName(charsetName);
final byte[] bytes = charSequence.toString().getBytes(charset);
@@ -188,11 +186,13 @@
return this;
}
+ @Override
public ByteArrayBuilder append(final char theChar) {
final Charset charset = Charset.forName("US-ASCII");
return append(theChar, charset);
}
+ @Override
public ByteArrayBuilder append(final char theChar, final Charset charset) {
final byte[] bytes = Character.toString(theChar).getBytes(charset);
append(bytes);
@@ -199,16 +199,12 @@
return this;
}
+ @Override
public ByteArrayBuilder append(final char theChar, final String charsetName) {
final Charset charset = Charset.forName(charsetName);
return append(theChar, charset);
}
- 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.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.java 2022-02-01 01:04:57 UTC (rev 12519)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.java 2022-02-01 13:03:39 UTC (rev 12520)
@@ -132,7 +132,7 @@
builder.append("xref");
builder.append(PdfObject.EOL);
builder.append("0 ");
- builder.append(this.xrefTable.size());
+ builder.append(Long.toString(this.xrefTable.size()));
builder.append(PdfObject.EOL);
builder.writeTo(stream);
builder.clear();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 01:05:00
|
Revision: 12519
http://sourceforge.net/p/foray/code/12519
Author: victormote
Date: 2022-02-01 01:04:57 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Conform to aXSL changes: Add methods to append other sequences and subsets of sequences 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-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.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/ByteArrayBuilder.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2022-02-01 00:20:44 UTC (rev 12518)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2022-02-01 01:04:57 UTC (rev 12519)
@@ -35,8 +35,8 @@
import org.foray.common.MarkedIndexOutOfBoundsException;
+import org.axsl.utility.sequence.ByteSequence;
import org.axsl.utility.sequence.ByteSequenceMutable;
-import org.axsl.utility.sequence.ByteSequencePlus;
import org.apache.commons.io.IOUtils;
@@ -134,6 +134,22 @@
return this;
}
+ @Override
+ public ByteArrayBuilder append(final ByteSequence sequence) {
+ ensureCapacity(length() + sequence.length());
+ return append(sequence, 0, sequence.length());
+ }
+
+ @Override
+ public ByteArrayBuilder append(final ByteSequence sequence, final int start, final int end) {
+ ensureCapacity(length() + end - start);
+ for (int index = start; index < end; index ++) {
+ this.backingArray[this.length] = sequence.byteAt(index);
+ this.length ++;
+ }
+ return this;
+ }
+
/**
* Adds the content of an input stream.
* @param stream The input stream whose content should be added to this array.
@@ -188,12 +204,6 @@
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;
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 2022-02-01 00:20:44 UTC (rev 12518)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2022-02-01 01:04:57 UTC (rev 12519)
@@ -302,16 +302,17 @@
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) {
- ensureCapacity(length() + newContent.length());
- final int startingLength = this.length;
- for (int index = 0; index < newContent.length(); index ++) {
- this.backingArray[startingLength + index] = newContent.charAt(index);
+ @Override
+ public CharArrayBuilder append(final CharSequence sequence) {
+ ensureCapacity(length() + sequence.length());
+ return append(sequence, 0, sequence.length());
+ }
+
+ @Override
+ public CharArrayBuilder append(final CharSequence sequence, final int start, final int end) {
+ ensureCapacity(length() + end - start);
+ for (int index = start; index < end; index ++) {
+ this.backingArray[this.length] = sequence.charAt(index);
this.length ++;
}
return this;
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 2022-02-01 00:20:44 UTC (rev 12518)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2022-02-01 01:04:57 UTC (rev 12519)
@@ -232,6 +232,22 @@
return this;
}
+ @Override
+ public IntArrayBuilder append(final IntSequence sequence) {
+ ensureCapacity(length() + sequence.length());
+ return append(sequence, 0, sequence.length());
+ }
+
+ @Override
+ public IntArrayBuilder append(final IntSequence sequence, final int start, final int end) {
+ ensureCapacity(length() + end - start);
+ for (int index = start; index < end; index ++) {
+ this.backingArray[this.length] = sequence.intAt(index);
+ this.length ++;
+ }
+ return this;
+ }
+
/**
* Append a varargs or char[] to this structure.
* @param intToAppend The int to append.
@@ -247,21 +263,6 @@
}
/**
- * 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.backingArray[startingLength + index] = newContent.intAt(index);
- this.length ++;
- }
- return this;
- }
-
- /**
* Removes the value at a given index.
* @param index The index whose value should be deleted.
* @return This object.
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 2022-02-01 00:20:44 UTC (rev 12518)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2022-02-01 01:04:57 UTC (rev 12519)
@@ -199,16 +199,18 @@
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 LongArrayBuilder append(final LongSequence newContent) {
- this.ensureCapacity(length() + newContent.length());
- for (int index = 0; index < newContent.length(); index ++) {
- this.backingArray[this.length + index] = newContent.longAt(index);
- length ++;
+ @Override
+ public LongArrayBuilder append(final LongSequence sequence) {
+ ensureCapacity(length() + sequence.length());
+ return append(sequence, 0, sequence.length());
+ }
+
+ @Override
+ public LongArrayBuilder append(final LongSequence sequence, final int start, final int end) {
+ ensureCapacity(length() + end - start);
+ for (int index = start; index < end; index ++) {
+ this.backingArray[this.length] = sequence.longAt(index);
+ this.length ++;
}
return this;
}
Modified: 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 2022-02-01 00:20:44 UTC (rev 12518)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2022-02-01 01:04:57 UTC (rev 12519)
@@ -180,16 +180,18 @@
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.backingArray[this.length + index] = newContent.shortAt(index);
- length ++;
+ @Override
+ public ShortArrayBuilder append(final ShortSequence sequence) {
+ ensureCapacity(length() + sequence.length());
+ return append(sequence, 0, sequence.length());
+ }
+
+ @Override
+ public ShortArrayBuilder append(final ShortSequence sequence, final int start, final int end) {
+ ensureCapacity(length() + end - start);
+ for (int index = start; index < end; index ++) {
+ this.backingArray[this.length] = sequence.shortAt(index);
+ this.length ++;
}
return this;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-02-01 00:20:47
|
Revision: 12518
http://sourceforge.net/p/foray/code/12518
Author: victormote
Date: 2022-02-01 00:20:44 +0000 (Tue, 01 Feb 2022)
Log Message:
-----------
Conform to aXSL changes: Add methods to append varargs/arrays to sequences.
Modified Paths:
--------------
trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
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-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java
trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java
Modified: trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-01-31 21:13:57 UTC (rev 12517)
+++ trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-02-01 00:20:44 UTC (rev 12518)
@@ -126,8 +126,7 @@
<property name="scope" value="private"/>
</module>
- <!-- Check the javadoc style. If there is a javadoc comment, it must be
- well-formed, even if it is private. -->
+ <!-- Check the javadoc style. If there is a javadoc comment, it must be well-formed, even if it is private. -->
<module name="JavadocStyle">
<property name="scope" value="private"/>
<property name="checkEmptyJavadoc" value="true"/>
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 2022-01-31 21:13:57 UTC (rev 12517)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArrayBuilder.java 2022-02-01 00:20:44 UTC (rev 12518)
@@ -126,6 +126,7 @@
return this;
}
+ @Override
public ByteArrayBuilder append(final byte ... bytes) {
ensureCapacity(length() + bytes.length);
System.arraycopy(bytes, 0, this.backingArray, this.length, 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 2022-01-31 21:13:57 UTC (rev 12517)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/CharArrayBuilder.java 2022-02-01 00:20:44 UTC (rev 12518)
@@ -294,6 +294,7 @@
return this;
}
+ @Override
public CharArrayBuilder append(final char ... chars) {
ensureCapacity(length() + chars.length);
System.arraycopy(chars, 0, this.backingArray, this.length, chars.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 2022-01-31 21:13:57 UTC (rev 12517)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/IntArrayBuilder.java 2022-02-01 00:20:44 UTC (rev 12518)
@@ -222,11 +222,7 @@
return this;
}
- /**
- * Append a varargs or int[] to this structure.
- * @param intToAppend The int to append.
- * @return This object.
- */
+ @Override
public IntArrayBuilder append(final int... intToAppend) {
ensureCapacity(this.length + intToAppend.length);
for (int index = 0; index < intToAppend.length; index ++) {
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 2022-01-31 21:13:57 UTC (rev 12517)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/LongArrayBuilder.java 2022-02-01 00:20:44 UTC (rev 12518)
@@ -189,11 +189,7 @@
return this;
}
- /**
- * Append a varargs or long[] to this structure.
- * @param longsToAppend The longs to append.
- * @return This object.
- */
+ @Override
public LongArrayBuilder append(final long... longsToAppend) {
ensureCapacity(this.length + longsToAppend.length);
for (int index = 0; index < longsToAppend.length; index ++) {
Modified: 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 2022-01-31 21:13:57 UTC (rev 12517)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ShortArrayBuilder.java 2022-02-01 00:20:44 UTC (rev 12518)
@@ -170,11 +170,7 @@
return this;
}
- /**
- * Append a varargs or short[] to this structure.
- * @param shortsToAppend The shorts to append.
- * @return This object.
- */
+ @Override
public ShortArrayBuilder append(final short... shortsToAppend) {
ensureCapacity(this.length + shortsToAppend.length);
for (int index = 0; index < shortsToAppend.length; index ++) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-31 21:14:00
|
Revision: 12517
http://sourceforge.net/p/foray/code/12517
Author: victormote
Date: 2022-01-31 21:13:57 +0000 (Mon, 31 Jan 2022)
Log Message:
-----------
Move embedded files to their correct location in the tree.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java 2022-01-31 20:39:25 UTC (rev 12516)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java 2022-01-31 21:13:57 UTC (rev 12517)
@@ -28,11 +28,16 @@
package org.foray.pdf.document;
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.PdfConstants;
+import org.foray.pdf.filespec.PdfEmbeddedFileStream;
import org.foray.pdf.interact.PdfDestinationNamed4a;
import org.foray.pdf.interact.PdfNamedDestinationsTree4a;
import org.foray.pdf.structure.PdfNameTree;
import org.foray.pdf.type.PdfDictionary;
+import org.axsl.utility.sequence.ByteSequencePlus;
+
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -53,9 +58,12 @@
/** The parent root object. */
private PdfRoot root;
- /** Map of name strings to destinations. */
+ /** Name tree mapping name strings to destinations. */
private PdfNamedDestinationsTree4a dests = new PdfNamedDestinationsTree4a();
+ /** Name tree mapping name strings to file specifications for embedded file streams. */
+ private PdfNameTree<PdfEmbeddedFileStream> embeddedFiles = new PdfNameTree<PdfEmbeddedFileStream>();
+
/**
* Constructor.
* @param root The parent root object.
@@ -84,6 +92,36 @@
}
/**
+ * Represent the object as PDF.
+ * @param doc The PDF Document.
+ * @return The PDF string
+ */
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ final StringBuilder p = new StringBuilder();
+ p.append(this.getSerializedId());
+ p.append(EOL);
+ p.append(PdfConstants.OPEN_DICTIONARY);
+ p.append(EOL);
+
+ if (! this.dests.isEmpty()) {
+ p.append(" /Dests ");
+ p.append(this.dests.pdfReference(doc));
+ p.append(EOL);
+ }
+ if (! this.embeddedFiles.isEmpty()) {
+ p.append(" /EmbeddedFiles ");
+ p.append(this.embeddedFiles.pdfReference(doc));
+ p.append(EOL);
+ }
+
+ p.append(PdfConstants.CLOSE_DICTIONARY);
+ p.append(EOL);
+ p.append(PdfConstants.KEYWORD_END_OBJECT);
+ p.append(EOL);
+ return new ByteArray(p);
+ }
+
+ /**
* Returns the named destinations in this document.
* @return The named destinations in this document, or null if there are none.
*/
@@ -91,8 +129,17 @@
return this.dests;
}
+ /**
+ * Returns the embedded files in this document.
+ * @return The embedded files in this document.
+ */
+ public PdfNameTree<PdfEmbeddedFileStream> getEmbeddedFiles() {
+ return this.embeddedFiles;
+ }
+
public boolean isEmpty() {
- return this.dests.isEmpty();
+ return this.dests.isEmpty()
+ && this.embeddedFiles.isEmpty();
}
/**
@@ -103,6 +150,9 @@
if (! this.dests.isEmpty()) {
this.root.getDocument().registerIndirectObjectLast(this.dests);
}
+ if (! this.embeddedFiles.isEmpty()) {
+ this.root.getDocument().registerIndirectObjectLast(this.embeddedFiles);
+ }
}
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-31 20:39:25 UTC (rev 12516)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-31 21:13:57 UTC (rev 12517)
@@ -28,13 +28,10 @@
package org.foray.pdf.document;
-import org.foray.common.primitive.StringUtils;
import org.foray.common.sequence.ByteArray;
import org.foray.pdf.PdfConstants;
-import org.foray.pdf.filespec.PdfEmbeddedFileStream;
import org.foray.pdf.interact.PdfOutline4a;
import org.foray.pdf.interact.PdfPageLabel;
-import org.foray.pdf.structure.PdfNameTree;
import org.foray.pdf.structure.PdfNumberTree;
import org.foray.pdf.type.PdfDictionary;
@@ -78,9 +75,6 @@
/** The root outline object. Lazily created, to avoid unnecessary objects. */
private PdfOutline4a outline;
- /** The embedded files. */
- private PdfNameTree<PdfEmbeddedFileStream> embeddedFiles;
-
/**
* Create a Root (/Catalog) object.
* @param document The parent PDF document.
@@ -129,17 +123,6 @@
}
/**
- * Returns the embedded files in this document.
- * @return The embedded files in this document.
- */
- public PdfNameTree<PdfEmbeddedFileStream> getEmbeddedFiles() {
- if (this.embeddedFiles == null) {
- this.embeddedFiles = new PdfNameTree<PdfEmbeddedFileStream>();
- }
- return this.embeddedFiles;
- }
-
- /**
* Returns the root Outlines object, creating it if necessary.
* @return The root Outlines object.
*/
@@ -176,31 +159,18 @@
p.append("/Outlines ");
p.append(this.outline.pdfReference(doc));
p.append(EOL);
- p.append("/PageMode /UseOutlines");
+ p.append(" /PageMode /UseOutlines");
p.append(EOL);
}
if (! this.names.isEmpty()) {
- p.append("/Names");
+ p.append("/Names ");
+ p.append(this.names.pdfReference(doc));
p.append(EOL);
- p.append(StringUtils.SINGLE_SPACE);
- p.append(PdfConstants.OPEN_DICTIONARY + EOL);
- if (this.names.getNamedDestinations() != null) {
- p.append(" /Dests ");
- p.append(this.names.getNamedDestinations().pdfReference(doc));
- p.append(EOL);
- }
- if (this.embeddedFiles != null) {
- p.append(" /EmbeddedFiles ");
- p.append(this.embeddedFiles.pdfReference(doc));
- p.append(EOL);
- }
- p.append(StringUtils.SINGLE_SPACE);
- p.append(PdfConstants.CLOSE_DICTIONARY);
- p.append(EOL);
}
p.append(PdfConstants.CLOSE_DICTIONARY);
p.append(EOL);
- p.append("endobj" + EOL);
+ p.append(PdfConstants.KEYWORD_END_OBJECT);
+ p.append(EOL);
return new ByteArray(p);
}
@@ -259,7 +229,10 @@
* unless they have content.
*/
public void registerOptionalIndirectObjects() {
- this.names.registerOptionalIndirectObjects();
+ if (! this.names.isEmpty()) {
+ this.document.registerIndirectObjectLast(this.names);
+ this.names.registerOptionalIndirectObjects();
+ }
}
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java 2022-01-31 20:39:25 UTC (rev 12516)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java 2022-01-31 21:13:57 UTC (rev 12517)
@@ -49,7 +49,7 @@
*/
public PdfEmbeddedFileStream(final PdfDocument4a doc, final String name) {
this.name = name;
- doc.getRoot().getEmbeddedFiles().put(name, this);
+ doc.getRoot().getNameDictionary().getEmbeddedFiles().put(name, this);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-31 20:39:28
|
Revision: 12516
http://sourceforge.net/p/foray/code/12516
Author: victormote
Date: 2022-01-31 20:39:25 +0000 (Mon, 31 Jan 2022)
Log Message:
-----------
1. Add class for the names dictionary, and move the named destinations to it. 2. Add mechanism for optional objects to get registered as indirect objects after the document is built and before it gets going on serialization.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -49,6 +49,7 @@
import org.foray.pdf.graphics.PdfPattern4a;
import org.foray.pdf.graphics.PdfShading;
import org.foray.pdf.graphics.PdfXobject4a;
+import org.foray.pdf.interact.PdfDestinationNamed4a;
import org.foray.pdf.interact.PdfOutlineParent4a;
import org.foray.pdf.interact.PdfPageLabel;
import org.foray.pdf.interact.annotation.PdfBorderStyle;
@@ -69,7 +70,6 @@
import org.axsl.graphic.GraphicException;
import org.axsl.graphic.output.GraphicOutputContext;
import org.axsl.orthography.Orthography;
-import org.axsl.pdf.PdfDestinationNamed;
import org.axsl.pdf.PdfDocument;
import org.axsl.pdf.PdfException;
import org.axsl.pdf.PdfPage;
@@ -758,8 +758,8 @@
}
@Override
- public PdfDestinationNamed getNamedDestination(final String name) {
- return this.root.getNamedDestinations().get(name);
+ public PdfDestinationNamed4a getNamedDestination(final String name) {
+ return this.root.getNameDictionary().getNamedDestinations().get(name);
}
/**
@@ -853,4 +853,12 @@
this.incrementalFileId = fileId;
}
+ /**
+ * Registers any indirect objects that have not yet been registered, usually because we don't want to serialize them
+ * unless they have content.
+ */
+ public void registerOptionalIndirectObjects() {
+ this.root.registerOptionalIndirectObjects();
+ }
+
}
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2022 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.pdf.document;
+
+import org.foray.pdf.interact.PdfDestinationNamed4a;
+import org.foray.pdf.interact.PdfNamedDestinationsTree4a;
+import org.foray.pdf.structure.PdfNameTree;
+import org.foray.pdf.type.PdfDictionary;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * The PDF Name dictionary.
+ * The reference to this dictionary is stored as the "Names" entry in the {@link PdfRoot} (/Catalog) dictionary.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.6.3 for the description of the Name Dictionary."
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.6, Table 3.25, for the structure of the /Catalog."
+ */
+public class PdfNameDictionary extends PdfDictionary {
+
+ /** The default entry order when serializing dictionaries of this class. */
+ private static final List<String> DEFAULT_ORDER = Collections.unmodifiableList(
+ Arrays.asList("Dests", "AP", "JavaScript", "Pages", "Templates", "IDS", "URLS", "EmbeddedFiles",
+ "AlternatePresentations", "Renditions"));
+
+ /** The parent root object. */
+ private PdfRoot root;
+
+ /** Map of name strings to destinations. */
+ private PdfNamedDestinationsTree4a dests = new PdfNamedDestinationsTree4a();
+
+ /**
+ * Constructor.
+ * @param root The parent root object.
+ */
+ public PdfNameDictionary(final PdfRoot root) {
+ this.root = root;
+ }
+
+ @Override
+ public List<String> getOutputOrder() {
+ return PdfNameDictionary.DEFAULT_ORDER;
+ }
+
+ @Override
+ public String getDictionaryType() {
+ /* This dictionary does not have or need a /Type entry. */
+ return null;
+ }
+
+ /**
+ * Returns the parent root object.
+ * @return The parent.
+ */
+ public PdfRoot getParent() {
+ return this.root;
+ }
+
+ /**
+ * Returns the named destinations in this document.
+ * @return The named destinations in this document, or null if there are none.
+ */
+ public PdfNameTree<PdfDestinationNamed4a> getNamedDestinations() {
+ return this.dests;
+ }
+
+ public boolean isEmpty() {
+ return this.dests.isEmpty();
+ }
+
+ /**
+ * Registers any indirect objects that have not yet been registered, usually because we don't want to serialize them
+ * unless they have content.
+ */
+ public void registerOptionalIndirectObjects() {
+ if (! this.dests.isEmpty()) {
+ this.root.getDocument().registerIndirectObjectLast(this.dests);
+ }
+ }
+
+}
Property changes on: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfNameDictionary.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -212,7 +212,8 @@
final Coordinates coordinates, final Float explicitZoom, final String name) throws PdfException {
/* Has the name already been registered as a named destination? */
final PdfDocument4a document = this.parent.getRoot().getDocument();
- final PdfNameTree<PdfDestinationNamed4a> namedDestinations = document.getRoot().getNamedDestinations();
+ final PdfNameTree<PdfDestinationNamed4a> namedDestinations =
+ document.getRoot().getNameDictionary().getNamedDestinations();
if (name != null) {
final PdfDestinationNamed4a existingDestination = namedDestinations.get(name);
if (existingDestination != null) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -32,8 +32,6 @@
import org.foray.common.sequence.ByteArray;
import org.foray.pdf.PdfConstants;
import org.foray.pdf.filespec.PdfEmbeddedFileStream;
-import org.foray.pdf.interact.PdfDestinationNamed4a;
-import org.foray.pdf.interact.PdfNamedDestinationsTree4a;
import org.foray.pdf.interact.PdfOutline4a;
import org.foray.pdf.interact.PdfPageLabel;
import org.foray.pdf.structure.PdfNameTree;
@@ -66,12 +64,20 @@
* document. */
private PdfNumberTree<PdfPageLabel> pageLabels;
+ /** The document's name dictionary. */
+ private PdfNameDictionary names;
+
+ /* TODO: We do not currently support the compatibility option for PDF 1.1 of storing named destinations directly
+ * in the catalog as a dictionary. Instead, they are stored in the name dictionary above. For 1.1 compatibility,
+ * consider adding this capability.
+ * See "PDF Reference, 6th Edition (PDF Version 1.7), Section 8.2.1, last paragraph," where storage in the document
+ * catalog is deprecated unless PDF 1.1 compatibility is required. */
+// /** The named destinations. */
+// private PdfDictionary namedDestinations;
+
/** The root outline object. Lazily created, to avoid unnecessary objects. */
private PdfOutline4a outline;
- /** Collection of named destinations. */
- private PdfNamedDestinationsTree4a namedDestinations;
-
/** The embedded files. */
private PdfNameTree<PdfEmbeddedFileStream> embeddedFiles;
@@ -83,6 +89,7 @@
this.document = document;
this.pdfVersion = DEFAULT_PDF_VERSION;
this.pages = new PdfPages(this);
+ this.names = new PdfNameDictionary(this);
}
/**
@@ -122,18 +129,6 @@
}
/**
- * Returns the destinations in this document.
- * @return The destinations in this document.
- */
- public PdfNameTree<PdfDestinationNamed4a> getNamedDestinations() {
- if (this.namedDestinations == null) {
- this.namedDestinations = new PdfNamedDestinationsTree4a();
- this.document.registerIndirectObjectLast(this.namedDestinations);
- }
- return this.namedDestinations;
- }
-
- /**
* Returns the embedded files in this document.
* @return The embedded files in this document.
*/
@@ -163,47 +158,52 @@
*/
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder p = new StringBuilder();
- p.append(this.getSerializedId() + EOL);
- p.append(PdfConstants.OPEN_DICTIONARY + EOL);
- p.append("/Type /Catalog" + EOL);
- p.append("/Pages " + this.pages.pdfReference(doc) + EOL);
+ p.append(this.getSerializedId());
+ p.append(EOL);
+ p.append(PdfConstants.OPEN_DICTIONARY);
+ p.append(EOL);
+ p.append("/Type /Catalog");
+ p.append(EOL);
+ p.append("/Pages ");
+ p.append(this.pages.pdfReference(doc));
+ p.append(EOL);
if (this.pageLabels != null) {
- p.append("/PageLabels " + this.pageLabels.pdfReference(doc) + EOL);
+ p.append("/PageLabels ");
+ p.append(this.pageLabels.pdfReference(doc));
+ p.append(EOL);
}
if (this.outline != null) {
- p.append(" /Outlines " + this.outline.pdfReference(doc) + EOL);
- p.append(" /PageMode /UseOutlines" + EOL);
+ p.append("/Outlines ");
+ p.append(this.outline.pdfReference(doc));
+ p.append(EOL);
+ p.append("/PageMode /UseOutlines");
+ p.append(EOL);
}
- if (this.hasNameDictionary()) {
- p.append(" /Names" + EOL);
- p.append(StringUtils.SINGLE_SPACE + PdfConstants.OPEN_DICTIONARY + EOL);
- if (this.namedDestinations != null) {
- p.append(" /Dests " + this.namedDestinations.pdfReference(doc) + EOL);
+ if (! this.names.isEmpty()) {
+ p.append("/Names");
+ p.append(EOL);
+ p.append(StringUtils.SINGLE_SPACE);
+ p.append(PdfConstants.OPEN_DICTIONARY + EOL);
+ if (this.names.getNamedDestinations() != null) {
+ p.append(" /Dests ");
+ p.append(this.names.getNamedDestinations().pdfReference(doc));
+ p.append(EOL);
}
if (this.embeddedFiles != null) {
- p.append(" /EmbeddedFiles " + this.embeddedFiles.pdfReference(doc) + EOL);
+ p.append(" /EmbeddedFiles ");
+ p.append(this.embeddedFiles.pdfReference(doc));
+ p.append(EOL);
}
- p.append(StringUtils.SINGLE_SPACE + PdfConstants.CLOSE_DICTIONARY + EOL);
+ p.append(StringUtils.SINGLE_SPACE);
+ p.append(PdfConstants.CLOSE_DICTIONARY);
+ p.append(EOL);
}
- p.append(PdfConstants.CLOSE_DICTIONARY + EOL);
+ p.append(PdfConstants.CLOSE_DICTIONARY);
+ p.append(EOL);
p.append("endobj" + EOL);
return new ByteArray(p);
}
- /**
- * Indicates whether a name dictionary should be written for this catalog.
- * @return True if there is any data requiring a name dictionary.
- */
- private boolean hasNameDictionary() {
- if (this.namedDestinations != null) {
- return true;
- }
- if (this.embeddedFiles != null) {
- return true;
- }
- return false;
- }
-
@Override
public List<String> getOutputOrder() {
return null;
@@ -246,4 +246,20 @@
return pdfVersion;
}
+ /**
+ * Returns the /Names entry.
+ * @return The name dictionary in this catalog.
+ */
+ public PdfNameDictionary getNameDictionary() {
+ return this.names;
+ }
+
+ /**
+ * Registers any indirect objects that have not yet been registered, usually because we don't want to serialize them
+ * unless they have content.
+ */
+ public void registerOptionalIndirectObjects() {
+ this.names.registerOptionalIndirectObjects();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -33,7 +33,7 @@
/**
* PDF Name tree containing named destinations.
- * The reference to this tree is stored in the Name Dictionary.
+ * The reference to this tree is stored in the {@link org.foray.pdf.document.PdfNameDictionary}.
*/
public class PdfNamedDestinationsTree4a extends PdfNameTree<PdfDestinationNamed4a> {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -39,8 +39,12 @@
import java.util.List;
/**
- * Represents a PDF document information dictionary /Info object. See PDF
- * Reference, 3rd Edition, Section 9.2.1.
+ * Represents a PDF document information dictionary /Info object.
+ * An instance of this class can optionally be included as part of the {@link org.foray.pdf.serial.PdfTrailer} during
+ * serialization.
+ * Apart from serialization, it is stored at {@link org.foray.pdf.document.PdfDocument4a#getDocumentInfo(boolean)}.
+ * @see "PDF Reference, 3rd Edition, Section 9.2.1."
+ * @see "PDF Reference, 6th Edition, Section 10.2.1"
*/
public class PdfDocumentInfo4a extends PdfDictionary implements PdfDocumentInfo {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -103,6 +103,7 @@
processBytes(header.serialize());
/* Write the pages and other indirect objects. */
+ this.document.registerOptionalIndirectObjects();
final List<PdfObject> indirectObjects = this.document.getIndirectObjects();
final PdfCrossRefInfo xrefInfo = new PdfCrossRefInfo();
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -31,6 +31,7 @@
import org.foray.pdf.type.PdfDictionary;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
/**
@@ -39,7 +40,8 @@
public class PdfTrailer extends PdfDictionary {
/** The default order when writing dictionaries of this class. */
- private static final List<String> DEFAULT_ORDER = Arrays.asList("Size", "Prev", "Root", "Encrypt", "Info", "ID");
+ private static final List<String> DEFAULT_ORDER = Collections.unmodifiableList(
+ Arrays.asList("Size", "Prev", "Root", "Encrypt", "Info", "ID"));
/**
* No-args constructor.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -110,4 +110,12 @@
return value.pdfReference(doc);
}
+ /**
+ * Indicates whether this name tree is empty.
+ * @return True if and only if this name tree has no elements.
+ */
+ public boolean isEmpty() {
+ return this.names.isEmpty();
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-31 17:33:15 UTC (rev 12515)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-31 20:39:25 UTC (rev 12516)
@@ -90,8 +90,14 @@
public abstract List<String> getOutputOrder();
/**
- * Returns the /Type of this dictionary.
+ * <p>Returns the /Type of this dictionary.
+ * Per the PDF Reference,</p>
+ * <blockquote>The Type entry is not required unless so stated in its description; however, if the entry is present,
+ * it must have the correct value.
+ * In addition, the value of the Type entry in any dictionary, even in private data, must be either a name defined
+ * in this book or a registered name; see Appendix E for details.</blockquote>
* @return The type of this dictionary.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.2.6, last paragraph."
*/
public abstract String getDictionaryType();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-31 17:33:18
|
Revision: 12515
http://sourceforge.net/p/foray/code/12515
Author: victormote
Date: 2022-01-31 17:33:15 +0000 (Mon, 31 Jan 2022)
Log Message:
-----------
Add some missing javadoc.
Modified Paths:
--------------
trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
trunk/foray/foray-areatree/src/main/java/org/foray/area/BlockArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.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/ByteSequenceChars.java
trunk/foray/foray-common/src/test/java/org/foray/common/ConfigurationTests.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/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/IntSequenceIteratorTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ByteUtilsTests.java
trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoRefinedText4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfBoolean.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfHexString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java
Modified: trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-01-31 17:33:15 UTC (rev 12515)
@@ -115,7 +115,9 @@
<module name="JavadocType"/>
<!-- Make sure each Method has javadoc -->
- <!-- <module name="MissingJavadocMethod"/> -->
+ <module name="MissingJavadocMethod">
+ <property name="severity" value="ignore"/>
+ </module>
<!-- Make sure Method javadoc is well-formed. -->
<module name="JavadocMethod"/>
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/BlockArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/BlockArea.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/BlockArea.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -69,6 +69,7 @@
return false;
}
+ @Override
public abstract Link<Block> getFoLink();
@Override
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -50,6 +50,10 @@
/** The parent area tree. */
private AreaTree4a parent;
+ /**
+ * Constructor.
+ * @param parent The parent node.
+ */
public DocumentMetadata4a(final AreaTree4a parent) {
this.parent = parent;
}
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 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteArray.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -217,9 +217,9 @@
}
// @Override
- public ByteArray toByteArray() {
- return this;
- }
+// public ByteArray toByteArray() {
+// return this;
+// }
@Override
public boolean isNativeCharSequence() {
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 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/sequence/ByteSequenceChars.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -99,12 +99,6 @@
throw new UnsupportedOperationException();
}
-// @Override
- public ByteArray toByteArray() {
- /* TODO: Implement this. */
- throw new UnsupportedOperationException();
- }
-
@Override
public String toString() {
return this.sequence.toString();
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/ConfigurationTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/ConfigurationTests.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/ConfigurationTests.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -41,6 +41,11 @@
*/
public class ConfigurationTests {
+ /**
+ * Test of {@link Configuration#parseURLDirectory(URL, String, String)}.
+ * @throws ConfigurationException Not expected here.
+ * @throws MalformedURLException Not expected here.
+ */
@Test
public void parseUrlDirectoryTest001() throws ConfigurationException, MalformedURLException {
final URL baseUrl = new File("c:/bogus/bogus2/bogus3.txt").toURI().toURL();
@@ -49,6 +54,11 @@
Assert.assertEquals("file:/c:/bogus/fonts/", resolvedUrl.toExternalForm());
}
+ /**
+ * Test of {@link Configuration#parseURLDirectory(URL, String, String)}.
+ * @throws ConfigurationException Not expected here.
+ * @throws MalformedURLException Not expected here.
+ */
@Test
public void parseUrlDirectoryTest002() throws ConfigurationException, MalformedURLException {
final URL baseUrl = new File("c:/bogus/bogus2/bogus3.txt").toURI().toURL();
@@ -57,6 +67,11 @@
Assert.assertEquals("file:/c:/bogus/bogus2/", resolvedUrl.toExternalForm());
}
+ /**
+ * Test of {@link Configuration#parseURLDirectory(URL, String, String)}.
+ * @throws ConfigurationException Not expected here.
+ * @throws MalformedURLException Not expected here.
+ */
@Test
public void parseUrlDirectoryTest003() throws ConfigurationException, MalformedURLException {
final URL baseUrl = new File("c:/bogus/bogus2/bogus3.txt").toURI().toURL();
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractIntSequenceTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractIntSequenceTests.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractIntSequenceTests.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -44,6 +44,9 @@
/** Array builder available to all tests. */
private IntArrayBuilder builder;
+ /**
+ * Test setup.
+ */
@Before
public void before() {
final IntArrayBuilder builder = new IntArrayBuilder();
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteArrayTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteArrayTests.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteArrayTests.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -38,6 +38,9 @@
*/
public class ByteArrayTests {
+ /**
+ * Test of {@link ByteArray#fromHexCharSequence(CharSequence)}.
+ */
@Test
public void fromHexCharSequenceTests() {
final String input = "4397CDCC3F8F94FD6C77A64F83E95278";
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/ByteSequenceTokenizerTests.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -89,6 +89,10 @@
private static final ByteSequenceTokenizerConfig CONFIG_WITH_BALANCING =
new ByteSequenceTokenizerConfig(CLOSING_BALANCED_DELIMITERS, null, null, OPENING_BALANCED_DELIMITERS);
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array has no content.
+ */
@Test
public void testEmptyInput() {
final ByteArray ba = new ByteArray();
@@ -96,6 +100,10 @@
Assert.assertFalse(out.hasMoreTokens());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array has normal content.
+ */
@Test
public void testNormalSentence() {
final ByteArray ba = new ByteArray("This is a normal sentence.");
@@ -125,6 +133,10 @@
Assert.assertEquals("sentence.", actual.get(4).toString());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array is a normal sentence with leading whitespace.
+ */
@Test
public void testNormalSentenceLeadingWhitespace() {
/* Note the space at the beginning of the test array. */
@@ -139,6 +151,10 @@
Assert.assertEquals("sentence.", actual.get(4).toString());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array is a normal sentence with trailing whitespace.
+ */
@Test
public void testNormalSentenceTrailingWhitespace() {
/* Note the space at the end of the test array. */
@@ -153,6 +169,10 @@
Assert.assertEquals("sentence.", actual.get(4).toString());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array is a normal sentence with embedded tokens.
+ */
@Test
public void testNormalSentenceEmbeddedTokens() {
final ByteArray ba = new ByteArray("Thi]s{ }is []a normal}{ sentence.");
@@ -174,6 +194,10 @@
Assert.assertEquals("sentence.", actual.get(12).toString());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array is a normal sentence with leading tokens.
+ */
@Test
public void testNormalSentenceLeadingTokens() {
final ByteArray ba = new ByteArray("][This is a normal sentence.");
@@ -189,6 +213,10 @@
Assert.assertEquals("sentence.", actual.get(6).toString());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array is a normal sentence with trailing tokens.
+ */
@Test
public void testNormalSentenceTrailingTokens() {
final ByteArray ba = new ByteArray("This is a normal sentence.][");
@@ -204,6 +232,10 @@
Assert.assertEquals("[", actual.get(6).toString());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array is a normal sentence with escape characters.
+ */
@Test
public void testEscape() {
final ByteArray ba = new ByteArray("\\[This \\[is\\] a no\\]rmal sentence.\\]");
@@ -217,6 +249,10 @@
Assert.assertEquals("sentence.\\]", actual.get(4).toString());
}
+ /**
+ * Test of {@link ByteSequenceTokenizer#ByteSequenceTokenizer(org.axsl.utility.sequence.ByteSequencePlus,
+ * ByteSequenceTokenizerConfig)}, where the byte array is a normal sentence with escaped escape characters.
+ */
@Test
public void testEscapeOfEscape() {
final ByteArray ba = new ByteArray("\\\\[This is a normal sentence.\\\\]");
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 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/IntSequenceIteratorTests.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -44,6 +44,9 @@
/** An array useful for testing the iterator. */
private IntArray array1 = new IntArray(5, -5, 100, -100, Integer.MAX_VALUE, Integer.MIN_VALUE);
+ /**
+ * Test of {@link IntSequenceIterator#IntSequenceIterator(org.axsl.utility.sequence.IntSequence, false)}.
+ */
@Test
public void testForwardIterator() {
final IntSequenceIterator out = new IntSequenceIterator(array1);
@@ -69,6 +72,9 @@
}
}
+ /**
+ * Test of {@link IntSequenceIterator#IntSequenceIterator(org.axsl.utility.sequence.IntSequence, false)}.
+ */
@Test
public void testReverseIterator() {
final IntSequenceIterator out = new IntSequenceIterator(array1, true);
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ByteUtilsTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ByteUtilsTests.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/primitive/ByteUtilsTests.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -55,6 +55,9 @@
}
}
+ /**
+ * Test of {@link ByteUtils#fromHexChars(CharSequence, int)}.
+ */
@Test
public void fromHexCharsTests() {
final String testString = "23FA7E";
@@ -100,6 +103,9 @@
Assert.assertEquals('0', ByteUtils.toHexCharHigh((byte) 0x03));
}
+ /**
+ * Tests of {@link ByteUtils#toHexCharLow(byte)}.
+ */
@Test
public void toHexCharLowTests() {
Assert.assertEquals('9', ByteUtils.toHexCharLow((byte) 0xF9));
Modified: trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java
===================================================================
--- trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-font/src/main/java/org/foray/font/FontUse4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -821,6 +821,7 @@
}
}
+ @Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append("[");
Modified: trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java
===================================================================
--- trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-font/src/test/java/org/foray/font/SubsetTests.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -41,6 +41,9 @@
*/
public class SubsetTests {
+ /**
+ * Test of {@link Subset#encodeSubsetIndex(int)}.
+ */
@Test
public void test01() {
/* The mock encoding just returns the code point to be encoded, i.e. the glyph index is the same as the code
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -2801,6 +2801,11 @@
return getPropertyList().traitStress(this, context);
}
+ /**
+ * Returns the raw, unresolved "script" property.
+ * @param context An object that knows how to resolve FO context issues.
+ * @return The raw, unresolved "script" property.
+ */
public String traitScriptRaw(final FoContext context) {
return getPropertyList().traitScript(this, context);
}
@@ -3690,6 +3695,7 @@
return WritingSystem4a.find(language, script, country);
}
+ @Override
public Orthography getOrthography() {
final OrthographyServer server = getOrthographyServer();
final WritingSystem writingSystem = getWritingSystem();
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoRefinedText4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoRefinedText4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoRefinedText4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -48,7 +48,7 @@
/** The text-transform. */
private TextTransform textTransform;
- /** The codepoint immediate before {@link #wrapped}. */
+ /** The codepoint immediately before {@link #wrapped}. */
private int codepointBefore;
/** The sorted list of indexes that are deleted. */
@@ -60,6 +60,15 @@
/** The new values for indexes that are changed. This is parallel with {@link #changed}. */
private CharSequence deltas;
+ /**
+ * Constructor.
+ * @param wrapped The wrapped raw text.
+ * @param linefeedTreatment The linefeed-treatment.
+ * @param textTransform The text-transform.
+ * @param whiteSpaceCollapse The white-space-collapse.
+ * @param codepointBefore The codepoint immediately before {@link #wrapped}.
+ * @param codepointAfter The codepoint immediately after {@link #wrapped}.
+ */
public FoRefinedText4a(final CharSequence wrapped, final LinefeedTreatment linefeedTreatment,
final TextTransform textTransform, final boolean whiteSpaceCollapse, final int codepointBefore,
final int codepointAfter) {
@@ -156,6 +165,7 @@
return builder;
}
+ @Override
public String toString() {
final StringBuilder builder = new StringBuilder();
for (int index = 0; index < length(); index ++) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -51,11 +51,22 @@
/** The object's generation (0 in new documents). */
private int generation = 0;
+ /**
+ * Constructor.
+ * @param objectNumber The object number for this reference.
+ * @param generation The generation number for this reference.
+ */
public PdfObjectReference(final int objectNumber, final int generation) {
this.number = objectNumber;
this.generation = generation;
}
+ /**
+ * Constructor.
+ * @param objectNumber The object number for this reference.
+ * @param generation The generation number for this reference.
+ * @throws PdfException If either {@code objectNumber} or {@code generation} cannot be cast to {@link PdfInteger}.
+ */
public PdfObjectReference(final PdfObject objectNumber, final PdfObject generation) throws PdfException {
if (! (objectNumber instanceof PdfInteger)) {
throw new PdfException("Object Id value must be an integer, actual = " + objectNumber.toString());
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -729,6 +729,10 @@
throw new UnsupportedOperationException();
}
+ /**
+ * Returns the list of registered indirect objects.
+ * @return The list of registered indirect objects.
+ */
public List<PdfObject> getIndirectObjects() {
return this.indirectObjects;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -214,6 +214,10 @@
return "Catalog";
}
+ /**
+ * Returns the pages.
+ * @return The pages.
+ */
public PdfPages getPages() {
return this.pages;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -292,6 +292,9 @@
return encryptWithKey(data, key);
}
+ /**
+ * Initializes this encryption.
+ */
public void init() throws PdfException {
// Generate the owner value
final byte[] oValue;
@@ -368,8 +371,7 @@
public byte[] encryptData(final byte [] data, final int number,
final int generation) {
if (this.encryptionKey == null) {
- throw new IllegalStateException("PDF Encryption has not been "
- + "initialized");
+ throw new IllegalStateException("PDF Encryption has not been initialized");
}
final byte[] hash = new byte[this.encryptionKey.length
@@ -403,8 +405,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
if (this.dictionary == null) {
- throw new IllegalStateException("PDF Encryption has not been "
- + "initialized");
+ throw new IllegalStateException("PDF Encryption has not been initialized");
}
return new ByteArray(this.dictionary);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -50,6 +50,11 @@
/** The dash phase. */
private float dashPhase;
+ /**
+ * Constructor.
+ * @param dashArray The dash array for this pattern.
+ * @param dashPhase The dash phase for this pattern.
+ */
public PdfDashPattern4a(final float[] dashArray, final float dashPhase) {
this.dashArray = new float[dashArray.length];
System.arraycopy(dashArray, 0, this.dashArray, 0, dashArray.length);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -47,6 +47,11 @@
/** The explicit destination to which this named destination is attached. */
private PdfDestinationExplicit4a explicitDestination;
+ /**
+ * Constructor.
+ * @param name The name of this destination.
+ * @param explicitDestination The explicit destination to which this named destination points.
+ */
public PdfDestinationNamed4a(final String name, final PdfDestinationExplicit4a explicitDestination) {
this.name = new PdfTextString(name);
this.explicitDestination = explicitDestination;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -197,6 +197,7 @@
return PdfDocumentTrapped.fromName(getString(PRODUCER_KEY));
}
+ @Override
public List<String> getOutputOrder() {
return OUTPUT_ORDER;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -56,11 +56,20 @@
* document may contain binary data. */
private ByteArray binaryComment;
+ /**
+ * Constructor.
+ * @param pdfVersion The PDF version for this header.
+ */
public PdfHeader(final PdfVersion pdfVersion) {
this.pdfVersion = pdfVersion;
this.binaryComment = DEFAULT_BINARY_COMMENT;
}
+
+ /**
+ * Returns the serialized value of this header.
+ * @return The serialized value.
+ */
public ByteArrayBuilder serialize() {
final ByteArrayBuilder builder = new ByteArrayBuilder();
// The PDF identifier comment.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -204,6 +204,10 @@
return this.theSequence.length();
}
+ /**
+ * Returns the wrapped bytes.
+ * @return The wrapped bytes.
+ */
public ByteSequence getValue() {
return this.theSequence;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -51,20 +51,36 @@
/** The contents of the array. */
private List<PdfObject> arrayContents = new ArrayList<PdfObject>();
+ /**
+ * Adds a {@link PdfObject} to this array.
+ * @param newElement The element to be added to this array.
+ */
public void addElement(final PdfObject newElement) {
this.arrayContents.add(newElement);
}
+ /**
+ * Converts a {@link Integer#TYPE} to a {@link PdfInteger}, and adds it to this array.
+ * @param anInteger The element to be added to this array.
+ */
public void addElement(final int anInteger) {
final PdfInteger newElement = new PdfInteger(anInteger);
addElement(newElement);
}
+ /**
+ * Converts a {@link BigDecimal} to a {@link PdfReal}, and adds it to this array.
+ * @param aReal The element to be added to this array.
+ */
public void addElement(final BigDecimal aReal) {
final PdfReal newElement = new PdfReal(aReal);
addElement(newElement);
}
+ /**
+ * Ensures that this array has a specified minimum size, adding null elements as needed.
+ * @param minimumSize The minimum size for this array.
+ */
public void ensureMinimumSize(final int minimumSize) {
while (this.arrayContents.size() < minimumSize) {
addElement((PdfObject) null);
@@ -105,10 +121,21 @@
this.arrayContents.set(index, object);
}
+ /**
+ * Returns the object at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ */
public PdfObject get(final int index) {
return this.arrayContents.get(index);
}
+ /**
+ * Returns the {@link PdfTextString} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfTextString}.
+ */
public PdfTextString getPdfTextString(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -126,6 +153,12 @@
return value == null ? null : value.toString();
}
+ /**
+ * Returns the {@link PdfHexString} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfHexString}.
+ */
public PdfHexString getPdfHexString(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -138,6 +171,12 @@
"Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfInteger} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfInteger}.
+ */
public PdfInteger getPdfInteger(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -155,6 +194,12 @@
return value == null ? null : value.getValue();
}
+ /**
+ * Returns the {@link PdfReal} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfReal}.
+ */
public PdfReal getPdfReal(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -172,6 +217,12 @@
return value == null ? null : value.getValue();
}
+ /**
+ * Returns the {@link PdfDate} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfDate}.
+ */
public PdfDate getPdfDate(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -189,6 +240,12 @@
return value == null ? null : value.getValue();
}
+ /**
+ * Returns the {@link PdfDictionary} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfDictionary}.
+ */
public PdfDictionary getPdfDictionary(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -201,6 +258,12 @@
"Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfName} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfName}.
+ */
public PdfName getPdfName(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -213,6 +276,12 @@
"Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfObjectReference} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfObjectReference}.
+ */
public PdfObjectReference getPdfObjectReference(final int index) {
final PdfObject value = get(index);
if (value == null) {
@@ -225,6 +294,12 @@
"Element for key \"{0}\" is of type {1}", index, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfArray} at a given index.
+ * @param index The index for which the element should be returned.
+ * @return The object at index {@code index}.
+ * @throws IllegalArgumentException If the object at {@code index} is not an instance of {@link PdfArray}.
+ */
public PdfArray getPdfArray(final int index) {
final PdfObject value = get(index);
if (value == null) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfBoolean.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfBoolean.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfBoolean.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -82,10 +82,18 @@
return null;
}
+ /**
+ * Returns the wrapped value.
+ * @return The wrapped value.
+ */
public boolean getValue() {
return this.value;
}
+ /**
+ * Returns the string representation of this.
+ * @return The string representation of this, either "true" or "false".
+ */
public ByteArray getTextValue() {
return this.textValue;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -200,6 +200,12 @@
return this.entries.get(key);
}
+ /**
+ * Returns the {@link PdfTextString} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfTextString}.
+ */
public PdfTextString getPdfTextString(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -217,6 +223,12 @@
return value == null ? null : value.toString();
}
+ /**
+ * Returns the {@link PdfHexString} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfHexString}.
+ */
public PdfHexString getPdfHexString(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -229,6 +241,12 @@
"Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfInteger} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfInteger}.
+ */
public PdfInteger getPdfInteger(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -246,6 +264,12 @@
return value == null ? null : value.getValue();
}
+ /**
+ * Returns the {@link PdfReal} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfReal}.
+ */
public PdfReal getPdfReal(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -263,6 +287,12 @@
return value == null ? null : value.getValue();
}
+ /**
+ * Returns the {@link PdfDate} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfDate}.
+ */
public PdfDate getPdfDate(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -280,6 +310,12 @@
return value == null ? null : value.getValue();
}
+ /**
+ * Returns the {@link PdfDictionary} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfDictionary}.
+ */
public PdfDictionary getPdfDictionary(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -292,6 +328,12 @@
"Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfName} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfName}.
+ */
public PdfName getPdfName(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -304,6 +346,12 @@
"Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfObjectReference} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfObjectReference}.
+ */
public PdfObjectReference getPdfObjectReference(final String key) {
final PdfObject value = get(key);
if (value == null) {
@@ -316,6 +364,12 @@
"Element for key \"{0}\" is of type {1}", key, value.getClass().getName()));
}
+ /**
+ * Returns the {@link PdfArray} for a given key.
+ * @param key The key for which the element should be returned.
+ * @return The value for key {@code key}, or null if {@code key} is not found in this dictionary.
+ * @throws IllegalArgumentException If the object at {@code key} is not an instance of {@link PdfArray}.
+ */
public PdfArray getPdfArray(final String key) {
final PdfObject value = get(key);
if (value == null) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfHexString.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfHexString.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfHexString.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -44,6 +44,10 @@
/** The parsed hex string bytes. */
private ByteArray value;
+ /**
+ * Constructor.
+ * @param value The bytes to be encapsulated.
+ */
public PdfHexString(final ByteArray value) {
this.value = value;
}
@@ -57,6 +61,10 @@
return new ByteArray(builder);
}
+ /**
+ * Returns the encapsulated bytes.
+ * @return The encapsulated bytes.
+ */
public ByteArray getValue() {
return this.value;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -42,10 +42,18 @@
/** The integer value. */
private int value;
+ /**
+ * Constructor.
+ * @param value The integer to be encapsulated.
+ */
public PdfInteger(final int value) {
this.value = value;
}
+ /**
+ * Returns the encapsulated integer.
+ * @return The encapsulated integer.
+ */
public int getValue() {
return this.value;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -84,7 +84,13 @@
return pdf.length();
}
+ /**
+ * Sets the indirect object reference for this object, marking it as an indirect object.
+ * @param reference The indirect object reference for this object.
+ * @throws IllegalStateException If this object already has an indirect object reference.
+ */
public void registerIndirectReference(final PdfObjectReference reference) {
+ /* TODO: Try to restrict the use of this method to only {@link PdfDocument4a}. */
if (this.reference != null) {
throw new IllegalStateException("Indirect reference already set.");
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java 2022-01-31 15:43:41 UTC (rev 12514)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java 2022-01-31 17:33:15 UTC (rev 12515)
@@ -46,6 +46,10 @@
/** The numeric value. */
private BigDecimal value;
+ /**
+ * Constructor.
+ * @param value The real number to be encapsulated.
+ */
public PdfReal(final BigDecimal value) {
this.value = value;
}
@@ -55,6 +59,10 @@
return new ByteArray(this.value.toPlainString());
}
+ /**
+ * Returns the encapsulated real number.
+ * @return The encapsulated real number.
+ */
public BigDecimal getValue() {
return this.value;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-31 15:43:44
|
Revision: 12514
http://sourceforge.net/p/foray/code/12514
Author: victormote
Date: 2022-01-31 15:43:41 +0000 (Mon, 31 Jan 2022)
Log Message:
-----------
Add some missing javadoc.
Modified Paths:
--------------
trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreakResult4a.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java
trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/AmbiguousWord.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DerivativeRule.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/MutableTokenFlowLocation.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.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/PdfDocumentInfo4aTests.java
trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java
trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingVector4aTests.java
trunk/foray/foray-render/src/main/java/org/foray/render/awt/AwtRenderer.java
trunk/foray/foray-unicode/src/main/java/org/foray/unicode/Block.java
Modified: trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-01-31 15:43:41 UTC (rev 12514)
@@ -114,10 +114,10 @@
<!-- Make sure Type javadoc is well-formed. -->
<module name="JavadocType"/>
- <!-- Make sure each method has javadoc -->
- <module name="JavadocMethod">
- <property name="scope" value="private"/>
- </module>
+ <!-- Make sure each Method has javadoc -->
+ <!-- <module name="MissingJavadocMethod"/> -->
+ <!-- Make sure Method javadoc is well-formed. -->
+ <module name="JavadocMethod"/>
<!-- Make sure each variable has javadoc -->
<module name="JavadocVariable">
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreakResult4a.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreakResult4a.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreakResult4a.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -48,6 +48,11 @@
/** The array of breakpoints for the paragraph. */
private int[] breakPositions;
+ /**
+ * Constructor.
+ * @param lineLengths The array of line lengths, in millipoints, for this result.
+ * @param breakPositions The array of break positions for this result.
+ */
public LineBreakResult4a(final int[] lineLengths, final int[] breakPositions) {
if (lineLengths.length != breakPositions.length) {
throw new IllegalArgumentException("Line length and breakpoint arrays must be of equal length.");
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/ParaBranch4aTestFixture.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -61,6 +61,9 @@
this.addNode(word);
}
+ /**
+ * Adds a normal space character.
+ */
public void addSpace() {
this.addNode(Whitespace4a.SPACE);
}
Modified: trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java
===================================================================
--- trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-linebreak/src/test/java/org/foray/linebreak/util/DumpParaBranch.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -47,6 +47,10 @@
/** The output stream to which the output should be sent. */
private PrintStream output;
+ /**
+ * Creates an instance and dumps a branch.
+ * @param branch The branch to be dumped.
+ */
public DumpParaBranch(final ParaBranch branch) {
this.output = System.out;
this.output.println(" Start");
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/AmbiguousWord.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/AmbiguousWord.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/AmbiguousWord.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -64,10 +64,19 @@
this.alternatives = alternatives;
}
+ /**
+ * Returns the number of alternatives for this ambiguous word.
+ * @return Tthe number of alternatives for this ambiguous word.
+ */
public int length() {
return this.alternatives.length;
}
+ /**
+ * Returns the alternative at a given index.
+ * @param index The index whose alternative should be returned.
+ * @return The alternative at {@code index}.
+ */
public T getAlternative(final int index) {
return this.alternatives[index];
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DerivativeRule.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DerivativeRule.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/DerivativeRule.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -50,6 +50,12 @@
* In other words, if this rule applies, identifies the types of derivative that the derivative could be. */
private List<Word.DerivativeType> types;
+ /**
+ * Constructor.
+ * @param rootPos The part-of-speech for which this derivative applies.
+ * @param qualifier The part-of-speech qualifier for which this derivative applies.
+ * @param types The types of derivatives for which this derivative rule applies.
+ */
public DerivativeRule(final Word.PartOfSpeech rootPos, final Word.PosQualifier qualifier,
final List<Word.DerivativeType> types) {
this.rootPos = rootPos;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/MutableTokenFlowLocation.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/MutableTokenFlowLocation.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/MutableTokenFlowLocation.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -47,6 +47,10 @@
/** The char index. See {@link TokenFlow.Location#getCharIndex()}. */
private byte charIndex;
+ /**
+ * Creates a mutable token flow location, using another location for its starting indexes.
+ * @param location The location whose indexes should be used as starting indexes for this new location.
+ */
public MutableTokenFlowLocation(final TokenFlow.Location location) {
this.tokenIndex = location.getTokenIndex();
this.segmentIndex = location.getSegmentIndex();
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PatternTree.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -176,6 +176,9 @@
return start;
}
+ /**
+ * Optimizes this tree.
+ */
public void optimize() {
this.patternKeys.optimize();
this.patternValues.trimToSize();
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/PosUtils.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -244,6 +244,12 @@
return (flags & mask) != 0;
}
+ /**
+ * Parses a single {@link PosQualifier} from a SAX {@link Attributes} instance.
+ * @param attributes The attributes whose names and values are being parsed.
+ * @return The parsed single {@link PosQualifier}, or null if none is found.
+ * @throws IllegalArgumentException If more than qualifier can be parsed from {@code attributes}.
+ */
public static PosQualifier parseSingleQualifier(final Attributes attributes) {
PosQualifier qualifier = null;
for (int index = 0; index < attributes.getLength(); index ++) {
@@ -263,6 +269,14 @@
return qualifier;
}
+ /**
+ * Parses the {@link PosQualifier}s from a SAX {@link Attributes} instance and adds their encodings to an existing
+ * encoding.
+ * @param existing The existing encoding.
+ * @param pos The part-of-speech for which the qualifiers apply.
+ * @param attributes The SAX attributes to be parsed and encoded.
+ * @return The new encoding, essentially the previous encoding plus any new qualifiers.
+ */
public static int parseAndEncodeQualifier(final int existing, final PartOfSpeech pos,
final Attributes attributes) {
int encoded = existing;
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SegmentDictionary.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -113,6 +113,11 @@
this.wordMap.put(rawWord, dictWord);
}
+ /**
+ * Adds an ambiguous word to this dictionary.
+ * @param rawWord The raw word to be disambiguated.
+ * @param word The list of possible disambiguated values for {@code rawWord}.
+ */
public void addAmbiguousWord(final String rawWord, final AmbiguousWord<SegmentDictionaryWord> word) {
this.ambiguousWordMap.put(rawWord, word);
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/SimpleDictionary.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -45,12 +45,16 @@
/** Constant needed for serialization. */
private static final long serialVersionUID = 1797657088308334420L;
- /** Regex pattern used to break compound words into their components. */
+ /** Regex pattern used to break words containing discretionary hyphens into their components. */
private Pattern wordBreaker;
/** The map of words. */
private Map<String, Word> words = new HashMap<String, Word>();
+ /**
+ * Constructor.
+ * @param softHyphenChar The used by this dictionary to mark discretionary hyphenation points in a word.
+ */
public SimpleDictionary(final char softHyphenChar) {
this.wordBreaker = Pattern.compile(Character.toString(softHyphenChar));
}
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/util/WordChecker.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -80,9 +80,6 @@
/** The output stream to which the output should be sent. */
private PrintStream output;
- /** The logger. */
-// private Logger logger = LoggerFactory.getLogger(WordChecker.class);
-
/** The current orthography configuration. */
private Orthography4a currentOrthographyConfig;
@@ -129,7 +126,11 @@
}
}
- public void start() throws SAXException, ParserConfigurationException, IOException {
+ /**
+ * Starts the process.
+ * @throws IOException For errors reading the input.
+ */
+ public void start() throws IOException {
String line = this.input.readLine();
while (line != null) {
processWord(line);
@@ -137,6 +138,10 @@
}
}
+ /**
+ * Processed a single word.
+ * @param word The word to be processed.
+ */
public void processWord(final String word) {
if (word.length() < 1) {
return;
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfArrayTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfArrayTests.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfArrayTests.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -34,8 +34,6 @@
import org.foray.pdf.type.PdfBoolean;
import org.foray.pdf.type.PdfName;
-import org.axsl.pdf.PdfException;
-
import org.junit.Assert;
import org.junit.Test;
@@ -46,9 +44,12 @@
*/
public class PdfArrayTests {
+ /**
+ * Test creation and serialization of a {@link PdfArray}.
+ /* Test is from example in PDF Reference, Sixth Edition (PDF version 1.7), Section 3.2.5.
+ */
@Test
- public void basicTest() throws PdfException {
- /* Test is from example in PDF Reference, Sixth Edition (PDF version 1.7), Section 3.2.5. */
+ public void basicTest() {
final PdfArray out = new PdfArray();
out.addElement(549);
out.addElement(new BigDecimal("3.14"));
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentInfo4aTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentInfo4aTests.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentInfo4aTests.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -53,6 +53,9 @@
/** A meaningless date, for test purposes. */
private Date bogusModDate;
+ /**
+ * General test setup.
+ */
@Before
public void setup() {
Calendar calendar = Calendar.getInstance();
@@ -62,7 +65,6 @@
calendar = Calendar.getInstance();
calendar.set(2020, Calendar.DECEMBER, 18, 9, 53, 28);
this.bogusModDate = calendar.getTime();
-
}
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 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-ps/src/main/java/org/foray/ps/encode/EncodingPdfDoc.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -1019,6 +1019,7 @@
return EncodingWinAnsi.getInstance();
}
+ @Override
public boolean isStatic() {
return true;
}
Modified: trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingVector4aTests.java
===================================================================
--- trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingVector4aTests.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-ps/src/test/java/org/foray/ps/encode/EncodingVector4aTests.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -44,6 +44,9 @@
/** A sequence of indexes for testing. */
private static final IntArray INDEXES_1 = new IntArray(0, 1, 2, 3, 4, 5);
+ /**
+ * Test with negative code points.
+ */
@Test
public void negativeCodePointTest() {
final IntArray codePoints = new IntArray(14, 18, -1, 24, 15);
@@ -56,6 +59,9 @@
}
}
+ /**
+ * Test with code point that is too high.
+ */
@Test
public void codePointTooHighTest() {
final IntArray codePoints = new IntArray(14, 18, Character.MAX_CODE_POINT + 1, 24, 15);
@@ -68,6 +74,9 @@
}
}
+ /**
+ * Test with negative index points.
+ */
@Test
public void negativeIndexTest() {
final IntArray codePoints = new IntArray(14, 18, 1, 24, 15);
@@ -80,6 +89,9 @@
}
}
+ /**
+ * Test with mismatched array sizes.
+ */
@Test
public void quantityMismatchTest() {
final IntArray codePoints = new IntArray(14, 18, 1, 24, 15); // 5 elements.
@@ -92,6 +104,9 @@
}
}
+ /**
+ * Tests of encoding.
+ */
@Test
public void encodingTest01() {
final EncodingVector4a out = new EncodingCustom("Test Encoding", null, CODE_POINTS_1, INDEXES_1);
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/awt/AwtRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/awt/AwtRenderer.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/awt/AwtRenderer.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -828,6 +828,7 @@
}
}
+ @Override
public FontSelectionConstraints getFontSelectionConstraints() {
return FontSelectionConstraints4a.NO_CONSTRAINTS;
}
Modified: trunk/foray/foray-unicode/src/main/java/org/foray/unicode/Block.java
===================================================================
--- trunk/foray/foray-unicode/src/main/java/org/foray/unicode/Block.java 2022-01-31 14:13:27 UTC (rev 12513)
+++ trunk/foray/foray-unicode/src/main/java/org/foray/unicode/Block.java 2022-01-31 15:43:41 UTC (rev 12514)
@@ -126,6 +126,11 @@
return this.name.replace(" ", "_").replace("-", "_");
}
+ /**
+ * Adds a code point to this block.
+ * @param codePoint The code point to be added.
+ * @throws IllegalArgumentException if {@code codePoint} is outside the range of valid code points for this block.
+ */
public void addCodePoint(final CodePoint codePoint) {
if (codePoint.getValue() < this.start) {
throw new IllegalArgumentException(
@@ -135,6 +140,11 @@
Collections.sort(this.codePoints);
}
+ /**
+ * Returns the length of the longest Java name in this code block.
+ * This is used when formatting generated classes.
+ * @return The length of the longest Java name in this code block.
+ */
public int getLengthLongestJavaName() {
int longest = 0;
for (CodePoint cp : this.codePoints) {
@@ -143,6 +153,11 @@
return longest;
}
+ /**
+ * Returns the Java type which should be used to store members of this block.
+ * This is used when generating Java classes.
+ * @return The Java type which should be used to store members of this block.
+ */
public String getSmallestIndexType() {
if (this.end > Character.MAX_VALUE) {
return "int";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-31 14:13:31
|
Revision: 12513
http://sourceforge.net/p/foray/code/12513
Author: victormote
Date: 2022-01-31 14:13:27 +0000 (Mon, 31 Jan 2022)
Log Message:
-----------
Add checkstyle checks previously covered by other checks.
Modified Paths:
--------------
trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/link/LinkFactory.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.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/TernaryNodesTests.java
trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeIteratorTests.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfName.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfNumeric.java
Modified: trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml
===================================================================
--- trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-00-master/config/checkstyle/checkstyle-config.xml 2022-01-31 14:13:27 UTC (rev 12513)
@@ -24,7 +24,7 @@
<property name="headerFile" value="${foray.root}/foray-00-master/config/checkstyle/checkstyle-header-java.txt"/>
</module>
- <!-- Make sure each package has javadoc package.html -->
+ <!-- Make sure each package has javadoc package-info.java. -->
<module name="JavadocPackage"/>
<module name="LineLength">
@@ -106,7 +106,12 @@
</module>
<module name="StringLiteralEquality"/>
- <!-- Make sure each Type has javadoc, regardless of visibility -->
+ <!-- Make sure each package-info.java has javadoc comment. -->
+ <module name="MissingJavadocPackage"/>
+
+ <!-- Make sure each Type has javadoc, regardless of visibility. -->
+ <module name="MissingJavadocType"/>
+ <!-- Make sure Type javadoc is well-formed. -->
<module name="JavadocType"/>
<!-- Make sure each method has javadoc -->
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -36,6 +36,10 @@
import java.io.Serializable;
+/**
+ * A {@link TextArea} that wraps a sequence of characters.
+ * @see TextAreaWords which instead wraps a sequence of words and interword content.
+ */
public final class TextAreaCharacters extends TextArea {
/** The link to the FO tree. */
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -33,6 +33,10 @@
import org.axsl.fotree.fo.FoTextWords;
import org.axsl.fotree.text.FoTokenFlow;
+/**
+ * A {@link TextArea} that wraps a sequence of words and interword content.
+ * @see TextAreaCharacters which instead wraps a sequence of characters.
+ */
public class TextAreaWords extends TextArea {
/** The link to the FO tree. */
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/link/LinkFactory.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/link/LinkFactory.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/link/LinkFactory.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -87,6 +87,9 @@
import org.axsl.fotree.fo.Wrapper;
import org.axsl.fotree.foreign.SvgElement;
+/**
+ * Implementation of {@link FoVisitor} that knows how to create the link objects to the FO tree.
+ */
public class LinkFactory implements FoVisitor<Link<? extends Fo>> {
@Override
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/metadata/DocumentMetadata4a.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -42,6 +42,9 @@
import java.util.Collections;
import java.util.List;
+/**
+ * The document-level metadata.
+ */
public class DocumentMetadata4a extends AreaNode4a implements DocumentMetadataG5 {
/** The parent area tree. */
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/primitive/ArrayUtils.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -28,6 +28,9 @@
package org.foray.common.primitive;
+/**
+ * Array-related utilities.
+ */
public final class ArrayUtils {
private ArrayUtils() { }
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractByteSequenceTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractByteSequenceTests.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/AbstractByteSequenceTests.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -34,6 +34,9 @@
import org.junit.Assert;
import org.junit.Test;
+/**
+ * JUnit tests of {@link AbstractByteSequence}.
+ */
public class AbstractByteSequenceTests {
/** A test sequence. */
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryNodesTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryNodesTests.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryNodesTests.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -31,6 +31,9 @@
import org.junit.Assert;
import org.junit.Test;
+/**
+ * JUnit tests of {@link TernaryNodes}.
+ */
public class TernaryNodesTests extends TernaryTreeTestsHelper {
/**
Modified: trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeIteratorTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeIteratorTests.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/data/TernaryTreeIteratorTests.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -35,6 +35,9 @@
import java.util.Iterator;
import java.util.List;
+/**
+ * JUnit tests of the return value of {@link TernaryTree#getIterator()}.
+ */
public class TernaryTreeIteratorTests {
/**
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoTree4a.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -46,6 +46,9 @@
import java.net.URL;
+/**
+ * An XSL-FO document tree.
+ */
public class FoTree4a implements FoTree {
/** The parent server. */
Modified: trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java
===================================================================
--- trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-linebreak/src/main/java/org/foray/linebreak/LineBreaker4a.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -30,6 +30,9 @@
import org.axsl.linebreak.LineBreaker;
+/**
+ * Abstract superclass for line-breakers.
+ */
public abstract class LineBreaker4a implements LineBreaker {
/** Magic number used in demerit computation to help normalize adjustment ratios and penalties. */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -35,6 +35,10 @@
import org.axsl.pdf.PdfDestinationNamed;
import org.axsl.utility.sequence.ByteSequencePlus;
+/**
+ * A PDF named destination.
+ * @see "PDF Reference 6th Edition (PDF Version 1.7), Section 8.2.1."
+ */
public class PdfDestinationNamed4a extends PdfObject implements PdfDestinationNamed {
/** The registered name of this destination. */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -31,6 +31,10 @@
import org.foray.pdf.document.PdfDocument4a;
import org.foray.pdf.structure.PdfNameTree;
+/**
+ * PDF Name tree containing named destinations.
+ * The reference to this tree is stored in the Name Dictionary.
+ */
public class PdfNamedDestinationsTree4a extends PdfNameTree<PdfDestinationNamed4a> {
protected String valueToPDF(final PdfDestinationNamed4a value, final PdfDocument4a doc) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -33,6 +33,9 @@
import java.util.Arrays;
import java.util.List;
+/**
+ * The trailer dictionary, used for serialization only.
+ */
public class PdfTrailer extends PdfDictionary {
/** The default order when writing dictionaries of this class. */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -47,6 +47,10 @@
import java.util.Map;
import java.util.Set;
+/**
+ * A PDF Dictionary object.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.2.6."
+ */
public abstract class PdfDictionary extends PdfObject {
/** Internal map of the dictionary. */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfName.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfName.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfName.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -37,6 +37,10 @@
import org.axsl.utility.sequence.ByteSequencePlus;
+/**
+ * A PDF Name object.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.2.4."
+ */
public class PdfName extends PdfObject {
/** The value of this name. */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfNumeric.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfNumeric.java 2022-01-30 19:23:05 UTC (rev 12512)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfNumeric.java 2022-01-31 14:13:27 UTC (rev 12513)
@@ -28,6 +28,10 @@
package org.foray.pdf.type;
+/**
+ * A PDF Numeric object.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.2.2."
+ */
public abstract class PdfNumeric extends PdfObject {
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-30 19:23:08
|
Revision: 12512
http://sourceforge.net/p/foray/code/12512
Author: victormote
Date: 2022-01-30 19:23:05 +0000 (Sun, 30 Jan 2022)
Log Message:
-----------
Improvement to indirect object registration.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 17:02:34 UTC (rev 12511)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 19:23:05 UTC (rev 12512)
@@ -316,39 +316,35 @@
}
/**
- * Marks a given object with its reference information.
- * @param object The object to be registered.
- * @return True if and only if the object has not already been registered.
+ * Returns an indirect object reference, creating and registering it if it does not already exist.
+ * @param object The object to be registered as an indirect object.
+ * @return The indirect object reference for {@code object}.
*/
- private boolean registerIndirectObjectShared(final PdfObject object) {
- if (object.getIndirectReference() != null) {
- return false;
+ public PdfObjectReference registerIndirectObject(final PdfObject object) {
+ PdfObjectReference reference = object.getIndirectReference();
+ if (reference != null) {
+ return reference;
}
-
- final PdfObjectReference reference = new PdfObjectReference(this.indirectObjects.size(), 0);
- object.registerIndirectReference(reference);
- return true;
- }
-
- /**
- * Register an object as an indirect object.
- * @param object The object to be registered as an indirect object.
- */
- public void registerIndirectObject(final PdfObject object) {
- if (registerIndirectObjectShared(object)) {
+ synchronized (this.indirectObjects) {
+ reference = new PdfObjectReference(this.indirectObjects.size(), 0);
this.indirectObjects.add(object);
+ object.registerIndirectReference(reference);
}
+ return reference;
}
/**
* Register an object as an indirect object that should be written at the end of the PDF output.
* @param object The object to be registered.
+ * @return The indirect object reference for {@code object}.
*/
- public void registerIndirectObjectLast(final PdfObject object) {
- if (registerIndirectObjectShared(object)) {
- this.indirectObjects.add(object);
+ public PdfObjectReference registerIndirectObjectLast(final PdfObject object) {
+ final PdfObjectReference reference = registerIndirectObject(object);
+ if (reference == null) {
+ return null;
}
this.indirectWriteLast.append(object.getIndirectReference().getNumber());
+ return reference;
}
/**
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-30 17:02:34 UTC (rev 12511)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-30 19:23:05 UTC (rev 12512)
@@ -127,6 +127,9 @@
final PdfObject object = indirectObjects.get(objectId);
if (object != null) {
final PdfObjectReference reference = object.getIndirectReference();
+ if (reference == null) {
+ ObjectUtils.noOperation(object);
+ }
if (this.document.isWriteLastIndirectObject(reference.getNumber())) {
/* We are not serializing this object yet. */
} else {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-30 17:02:34 UTC (rev 12511)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-30 19:23:05 UTC (rev 12512)
@@ -110,6 +110,10 @@
return this.reference.getSerializedId();
}
+ /**
+ * Returns the indirect reference for this object.
+ * @return The indirect reference for this object, or null if it is not an indirect object.
+ */
public PdfObjectReference getIndirectReference() {
return this.reference;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-30 17:02:38
|
Revision: 12511
http://sourceforge.net/p/foray/code/12511
Author: victormote
Date: 2022-01-30 17:02:34 +0000 (Sun, 30 Jan 2022)
Log Message:
-----------
Move remaining serialization code from PdfDocument4a to PdfSerializer.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 15:28:52 UTC (rev 12510)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 17:02:34 UTC (rev 12511)
@@ -37,7 +37,8 @@
package org.foray.pdf.document;
import org.foray.common.ColorUtil;
-import org.foray.common.sequence.ByteArrayBuilder;
+import org.foray.common.primitive.ObjectUtils;
+import org.foray.common.sequence.ByteArray;
import org.foray.common.sequence.IntArrayBuilder;
import org.foray.pdf.PdfConstants;
import org.foray.pdf.PdfObjectReference;
@@ -52,13 +53,13 @@
import org.foray.pdf.interact.PdfPageLabel;
import org.foray.pdf.interact.annotation.PdfBorderStyle;
import org.foray.pdf.interchange.PdfDocumentInfo4a;
-import org.foray.pdf.serial.PdfCrossRefEntry;
-import org.foray.pdf.serial.PdfCrossRefInfo;
import org.foray.pdf.serial.PdfParser;
import org.foray.pdf.serial.PdfSerializer;
import org.foray.pdf.serial.PdfTrailer;
import org.foray.pdf.text.PdfEncoding4a;
import org.foray.pdf.text.PdfFont4a;
+import org.foray.pdf.type.PdfArray;
+import org.foray.pdf.type.PdfHexString;
import org.foray.pdf.type.PdfObject;
import org.axsl.font.Font;
@@ -97,6 +98,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Random;
/**
* Represents a PDF document.
@@ -117,9 +119,12 @@
* bytes. */
public static final String ENCODING = "ISO-8859-1";
- /** The current character position. */
- private long position = 0;
+ /** This document's permanent file ID, if any. */
+ private ByteArray permanentFileId;
+ /** This document's incremental file ID, if any. */
+ private ByteArray incrementalFileId;
+
/** The list of indirectly-referenced objects in this document. The index into the list is the object's object
* number, and should match the object number in {@link PdfObject#getIndirectReference()}. */
private List<PdfObject> indirectObjects = new ArrayList<PdfObject>();
@@ -204,10 +209,6 @@
/** The PostScript server. */
private PsServer psServer;
- /** The trailer dictionary. Always use {@link #getTrailer()} to obtain the instance, because it is lazily
- * created. */
- private PdfTrailer lazyTrailer;
-
/**
* Constructor which creates an empty PDF document.
* The constructor creates a /Root and /Pages object to track the document
@@ -237,7 +238,9 @@
*/
public PdfDocument4a(final PdfParser parser) throws PdfException {
final PdfVersion pdfVersion = parser.parseHeader();
- this.lazyTrailer = parser.parseTrailer();
+ final PdfTrailer trailer = parser.parseTrailer();
+ /* TODO: Figure out what we need from the trailer during parsing. */
+ ObjectUtils.noOperation(trailer);
parser.parseIndirectObjects();
setVersion(pdfVersion);
}
@@ -291,60 +294,8 @@
return this.resources;
}
- private PdfCrossRefInfo writeIndirectObjects(final OutputStream output) throws PdfException {
- final PdfCrossRefInfo xrefInfo = new PdfCrossRefInfo();
-
- /*
- * Use a "while" loop here, because as each object is written, it has
- * potential to reference another object indirectly, which will add an
- * item to indirectObjects.
- */
- int objectId = 1;
- while (objectId < this.indirectObjects.size()) {
- final PdfObject object = this.indirectObjects.get(objectId);
- if (object != null) {
- final PdfObjectReference reference = object.getIndirectReference();
- if (this.indirectWriteLast.contains(reference.getNumber())) {
- /* We are not serializing this object yet. */
- } else {
- /* Output the object and increment the character position by the object's length. */
- final PdfCrossRefEntry xref = new PdfCrossRefEntry(object);
- xref.setOffset(this.position);
- xrefInfo.setTableEntry(reference.getNumber(), xref);
- this.position += object.serialize(output, this);
- }
- }
- objectId ++;
- }
- return xrefInfo;
- }
-
- private void writeDeferredIndirectObjects(final OutputStream output, final PdfCrossRefInfo xrefInfo)
- throws PdfException {
- /* Treat the deferred items like a stack, and iterate in reverse order. */
- final IntPrimitiveIterator deferredObjectIterator = this.indirectWriteLast.iteratorReverse();
- while (deferredObjectIterator.hasNext()) {
- final int objectId = deferredObjectIterator.nextInt();
- final PdfObject object = this.indirectObjects.get(objectId);
- if (object != null) {
- final PdfObjectReference reference = object.getIndirectReference();
- final PdfCrossRefEntry xref = new PdfCrossRefEntry(object);
- xref.setOffset(this.position);
- xrefInfo.setTableEntry(reference.getNumber(), xref);
- this.position += object.serialize(output, this);
- }
- }
- }
-
- /**
- * Write the document trailer.
- * @param output The output stream.
- * @param xrefPosition The offset to the cross-reference table.
- * @throws PdfException For errors while writing to the output stream.
- */
- private void writeTrailer(final OutputStream output, final long xrefPosition) throws PdfException, IOException {
- /* Construct the trailer. */
- final PdfTrailer trailer = getTrailer();
+ public PdfTrailer getTrailer() {
+ final PdfTrailer trailer = new PdfTrailer();
trailer.put("Size", this.indirectObjects.size());
trailer.put("Root", this.root);
final PdfDocumentInfo4a documentInfo = getDocumentInfo(false);
@@ -355,18 +306,13 @@
if (this.encryption != null) {
trailer.put("Encrypt", this.encryption);
}
-
- /* Write the trailer. */
- final ByteArrayBuilder builder = new ByteArrayBuilder();
- builder.append("trailer" + PdfObject.EOL);
- builder.append(getTrailer().serialize(this));
- builder.append("startxref");
- builder.append(PdfObject.EOL);
- builder.append(Long.toString(xrefPosition));
- builder.append(PdfObject.EOL);
- builder.append(PdfConstants.DOCUMENT_END_MARKER.toString() + PdfObject.EOL);
-
- builder.writeTo(output);
+ if (this.permanentFileId != null) {
+ final PdfArray array = trailer.ensureArray("ID");
+ array.ensureMinimumSize(2);
+ array.set(0, new PdfHexString(getPermanentFileId()));
+ array.set(1, new PdfHexString(getIncrementalFileId()));
+ }
+ return trailer;
}
/**
@@ -778,18 +724,6 @@
throws PdfException, IOException {
final PdfSerializer serializer = new PdfSerializer(this, output, config);
serializer.process();
-
- this.position = serializer.getPosition();
-
- /* Write the pages and other accumulated objects. */
- final PdfCrossRefInfo xrefInfo = writeIndirectObjects(output);
- writeDeferredIndirectObjects(output, xrefInfo);
-
- /* Remember position of xref table. */
- final long xrefPosition = this.position;
- xrefInfo.writeTable(output);
-
- writeTrailer(output, xrefPosition);
}
@Override
@@ -799,17 +733,6 @@
throw new UnsupportedOperationException();
}
- /**
- * Returns the file trailer, creating it if necessary.
- * @return the file trailer object.
- */
- public PdfTrailer getTrailer() {
- if (this.lazyTrailer == null) {
- this.lazyTrailer = new PdfTrailer();
- }
- return this.lazyTrailer;
- }
-
public List<PdfObject> getIndirectObjects() {
return this.indirectObjects;
}
@@ -839,4 +762,95 @@
return this.root.getNamedDestinations().get(name);
}
+ /**
+ * Indicates whether a given object ID is included in the "write last" list of indirect objects.
+ * @param objectId The object ID to be tested.
+ * @return True if and only if {@code objectId} is on the "write last" list of indirect objects.
+ */
+ public boolean isWriteLastIndirectObject(final int objectId) {
+ return this.indirectWriteLast.contains(objectId);
+ }
+
+ /**
+ * Returns an iterator over the "write last" indirect objects, which, because they are conceptually a stack, will
+ * iterate over them in reverse order.
+ * @return An iterator over the "write last" indirect objects.
+ */
+ public IntPrimitiveIterator getWriteLastIterator() {
+ return this.indirectWriteLast.iteratorReverse();
+ }
+
+ /**
+ * Returns the permanent document file ID.
+ * @return The permanent file ID.
+ * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
+ */
+ public ByteArray getPermanentFileId() {
+ return this.permanentFileId;
+ }
+
+ /**
+ * Creates a random permanent file ID for this document.
+ * @return The newly-created file ID.
+ * @throws IllegalStateException If this document already has a permanent file ID.
+ */
+ public ByteArray createPermanentFileId() {
+ if (this.permanentFileId != null) {
+ throw new IllegalStateException("Permanent file ID already exists.");
+ }
+ final byte[] fileIdBytes = new byte[PdfConstants.FILE_ID_SIZE];
+ final Random random = new Random();
+ random.nextBytes(fileIdBytes);
+ this.permanentFileId = new ByteArray(fileIdBytes);
+ return this.permanentFileId;
+ }
+
+ /**
+ * Sets the permanent document file ID.
+ * @param fileId The new value for the permanent document file ID.
+ * The size of the array must be exactly 16.
+ * @throws IllegalStateException If this document already has a permanent file ID.
+ * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
+ */
+ public void setPermanentFileId(final ByteArray fileId) {
+ if (this.permanentFileId != null) {
+ throw new IllegalStateException("Permanent file ID already exists.");
+ }
+ if (fileId.length() != PdfConstants.FILE_ID_SIZE) {
+ throw new IllegalArgumentException(
+ String.format("Size of array must be exactly {0}, actual: {1}",
+ PdfConstants.FILE_ID_SIZE, fileId.length()));
+ }
+ this.permanentFileId = fileId;
+ }
+
+ /**
+ * Returns the incremental document file ID.
+ * @return The incremental file ID.
+ * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
+ */
+ public ByteArray getIncrementalFileId() {
+ if (this.incrementalFileId == null) {
+ /* If not explicitly set, we assume that this is a new file, and the incremental file ID should be the same
+ * as the permanent one. */
+ this.incrementalFileId = this.permanentFileId;
+ }
+ return this.incrementalFileId;
+ }
+
+ /**
+ * Sets the incremental document file ID.
+ * @param fileId The new value for the incremental document file ID.
+ * The size of the array must be exactly 16.
+ * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
+ */
+ public void setIncrementalFileId(final ByteArray fileId) {
+ if (fileId.length() != PdfConstants.FILE_ID_SIZE) {
+ throw new IllegalArgumentException(
+ String.format("Size of array must be exactly {0}, actual: {1}",
+ PdfConstants.FILE_ID_SIZE, fileId.length()));
+ }
+ this.incrementalFileId = fileId;
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java 2022-01-30 15:28:52 UTC (rev 12510)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java 2022-01-30 17:02:34 UTC (rev 12511)
@@ -331,7 +331,7 @@
this.digest.update((byte) (permissions >>> WellKnownConstants.SHIFT_1_BYTE));
this.digest.update((byte) (permissions >>> WellKnownConstants.SHIFT_2_BYTES));
this.digest.update((byte) (permissions >>> WellKnownConstants.SHIFT_3_BYTES));
- this.digest.update(this.doc.getTrailer().getPermanentFileID().toArray());
+ this.digest.update(this.doc.getPermanentFileId().toArray());
final byte[] hash = this.digest.digest();
this.encryptionKey = new byte[PdfEncryption4a.DEFAULT_KEY_SIZE];
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-30 15:28:52 UTC (rev 12510)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-30 17:02:34 UTC (rev 12511)
@@ -29,13 +29,20 @@
package org.foray.pdf.serial;
import org.foray.common.primitive.ObjectUtils;
+import org.foray.common.sequence.ByteArrayBuilder;
+import org.foray.pdf.PdfConstants;
+import org.foray.pdf.PdfObjectReference;
import org.foray.pdf.document.PdfDocument4a;
+import org.foray.pdf.type.PdfObject;
+import org.axsl.pdf.PdfException;
import org.axsl.pdf.PdfSerializationConfig;
import org.axsl.utility.sequence.ByteSequencePlus;
+import org.axsl.utility.sequence.IntPrimitiveIterator;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.List;
/**
* Serializes a {@link PdfDocument4a}.
@@ -86,16 +93,92 @@
* For the objects provided at construction, writes the serialized content of the document to the output stream
* using the configuration.
* @throws IOException For errors writing to the output stream.
+ * @throws PdfException For errors serializing the PDF content.
*/
- public void process() throws IOException {
+ public void process() throws IOException, PdfException {
/* TODO: Remove following line after config is used. */
ObjectUtils.noOperation(this.config);
final PdfHeader header = new PdfHeader(this.document.getVersion());
processBytes(header.serialize());
+
+ /* Write the pages and other indirect objects. */
+ final List<PdfObject> indirectObjects = this.document.getIndirectObjects();
+
+ final PdfCrossRefInfo xrefInfo = new PdfCrossRefInfo();
+ writeIndirectObjects(indirectObjects, xrefInfo);
+ writeDeferredIndirectObjects(indirectObjects, xrefInfo);
+
+ /* Remember position of xref table. */
+ final long xrefPosition = this.position;
+ xrefInfo.writeTable(output);
+
+ writeTrailer(output, xrefPosition);
}
+ private void writeIndirectObjects(final List<PdfObject> indirectObjects, final PdfCrossRefInfo xrefInfo)
+ throws PdfException {
+
+ /* Use a "while" loop here, because as each object is written, it has potential to reference another object
+ * indirectly, which will add an item to indirectObjects.
+ */
+ int objectId = 1;
+ while (objectId < indirectObjects.size()) {
+ final PdfObject object = indirectObjects.get(objectId);
+ if (object != null) {
+ final PdfObjectReference reference = object.getIndirectReference();
+ if (this.document.isWriteLastIndirectObject(reference.getNumber())) {
+ /* We are not serializing this object yet. */
+ } else {
+ /* Output the object and increment the character position by the object's length. */
+ final PdfCrossRefEntry xref = new PdfCrossRefEntry(object);
+ xref.setOffset(this.position);
+ xrefInfo.setTableEntry(reference.getNumber(), xref);
+ this.position += object.serialize(output, this.document);
+ }
+ }
+ objectId ++;
+ }
+ }
+
+ private void writeDeferredIndirectObjects(final List<PdfObject> indirectObjects, final PdfCrossRefInfo xrefInfo)
+ throws PdfException {
+ /* Treat the deferred items like a stack, and iterate in reverse order. */
+ final IntPrimitiveIterator deferredObjectIterator = this.document.getWriteLastIterator();
+ while (deferredObjectIterator.hasNext()) {
+ final int objectId = deferredObjectIterator.nextInt();
+ final PdfObject object = indirectObjects.get(objectId);
+ if (object != null) {
+ final PdfObjectReference reference = object.getIndirectReference();
+ final PdfCrossRefEntry xref = new PdfCrossRefEntry(object);
+ xref.setOffset(this.position);
+ xrefInfo.setTableEntry(reference.getNumber(), xref);
+ this.position += object.serialize(output, this.document);
+ }
+ }
+ }
+
/**
+ * Write the document trailer.
+ * @param output The output stream.
+ * @param xrefPosition The offset to the cross-reference table.
+ * @throws PdfException For errors while writing to the output stream.
+ */
+ private void writeTrailer(final OutputStream output, final long xrefPosition) throws PdfException, IOException {
+ /* Write the trailer. */
+ final ByteArrayBuilder builder = new ByteArrayBuilder();
+ builder.append("trailer" + PdfObject.EOL);
+ builder.append(this.document.getTrailer().serialize(this.document));
+ builder.append("startxref");
+ builder.append(PdfObject.EOL);
+ builder.append(Long.toString(xrefPosition));
+ builder.append(PdfObject.EOL);
+ builder.append(PdfConstants.DOCUMENT_END_MARKER.toString() + PdfObject.EOL);
+
+ builder.writeTo(output);
+ }
+
+ /**
* Writes a sequence of bytes to the output and adds the size to the position.
* @param bytes The bytes to be written.
* @throws IOException For errors writing to the output stream.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java 2022-01-30 15:28:52 UTC (rev 12510)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfTrailer.java 2022-01-30 17:02:34 UTC (rev 12511)
@@ -28,15 +28,10 @@
package org.foray.pdf.serial;
-import org.foray.common.sequence.ByteArray;
-import org.foray.pdf.PdfConstants;
-import org.foray.pdf.type.PdfArray;
import org.foray.pdf.type.PdfDictionary;
-import org.foray.pdf.type.PdfHexString;
import java.util.Arrays;
import java.util.List;
-import java.util.Random;
public class PdfTrailer extends PdfDictionary {
@@ -68,85 +63,4 @@
return null;
}
- private ByteArray getStoredPermanentFileId() {
- final PdfArray idArray = this.getPdfArray("ID");
- if (idArray == null) {
- return null;
- }
- final PdfHexString hexString = idArray.getPdfHexString(0);
- return hexString == null ? null : hexString.getValue();
- }
-
- private ByteArray getStoredIncrementalFileId() {
- final PdfArray idArray = this.getPdfArray("ID");
- if (idArray == null) {
- return null;
- }
- final PdfHexString hexString = idArray.getPdfHexString(1);
- return hexString == null ? null : hexString.getValue();
- }
-
- /**
- * Returns the permanent document file ID.
- * @return The permanent file ID.
- * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
- */
- public ByteArray getPermanentFileID() {
- if (getStoredPermanentFileId() == null) {
- final byte[] fileIdBytes = new byte[PdfConstants.FILE_ID_SIZE];
- final Random random = new Random();
- random.nextBytes(fileIdBytes);
- setPermanentFileId(new ByteArray(fileIdBytes));
- }
- return getStoredPermanentFileId();
- }
-
- /**
- * Sets the permanent document file ID.
- * @param fileId The new value for the permanent document file ID.
- * The size of the array must be exactly 16.
- * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
- */
- public void setPermanentFileId(final ByteArray fileId) {
- if (fileId.length() != PdfConstants.FILE_ID_SIZE) {
- throw new IllegalArgumentException(
- String.format("Size of array must be exactly {0}, actual: {1}",
- PdfConstants.FILE_ID_SIZE, fileId.length()));
- }
- final PdfArray array = this.ensureArray("ID");
- array.ensureMinimumSize(2);
- array.set(0, new PdfHexString(fileId));
- }
-
- /**
- * Returns the incremental document file ID.
- * @return The incremental file ID.
- * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
- */
- public ByteArray getIncrementalFileID() {
- if (getStoredIncrementalFileId() == null) {
- /* If not explicitly set, we assume that this is a new file, and the incremental file ID should be the same
- * as the permanent one. */
- this.setIncrementalFileId(getPermanentFileID());
- }
- return getStoredIncrementalFileId();
- }
-
- /**
- * Sets the incremental document file ID.
- * @param fileId The new value for the incremental document file ID.
- * The size of the array must be exactly 16.
- * @see "PDFReference, Sixth Edition (PDF version 1.7), Section 10.3."
- */
- public void setIncrementalFileId(final ByteArray fileId) {
- if (fileId.length() != PdfConstants.FILE_ID_SIZE) {
- throw new IllegalArgumentException(
- String.format("Size of array must be exactly {0}, actual: {1}",
- PdfConstants.FILE_ID_SIZE, fileId.length()));
- }
- final PdfArray array = this.ensureArray("ID");
- array.ensureMinimumSize(2);
- array.set(1, new PdfHexString(fileId));
- }
-
}
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java 2022-01-30 15:28:52 UTC (rev 12510)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java 2022-01-30 17:02:34 UTC (rev 12511)
@@ -80,8 +80,8 @@
final PsServer ps = null;
final PdfDocument4a doc = new PdfDocument4a(ps);
doc.setVersion(PdfVersion.VERSION_1_4);
- doc.getTrailer().setPermanentFileId(ByteArray.fromHexCharSequence("4397CDCC3F8F94FD6C77A64F83E95278"));
- doc.getTrailer().setIncrementalFileId(ByteArray.fromHexCharSequence("7CA33F3FFDF62A30122D7AAD3DA09789"));
+ doc.setPermanentFileId(ByteArray.fromHexCharSequence("4397CDCC3F8F94FD6C77A64F83E95278"));
+ doc.setIncrementalFileId(ByteArray.fromHexCharSequence("7CA33F3FFDF62A30122D7AAD3DA09789"));
final int widthPoints = 396; // 5.5in
final int heightPoints = 612; // 8.5in
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-30 15:28:55
|
Revision: 12510
http://sourceforge.net/p/foray/code/12510
Author: victormote
Date: 2022-01-30 15:28:52 +0000 (Sun, 30 Jan 2022)
Log Message:
-----------
Partially detach the serialization of the cross-reference table from the document.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefEntry.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 13:02:06 UTC (rev 12509)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 15:28:52 UTC (rev 12510)
@@ -38,6 +38,7 @@
import org.foray.common.ColorUtil;
import org.foray.common.sequence.ByteArrayBuilder;
+import org.foray.common.sequence.IntArrayBuilder;
import org.foray.pdf.PdfConstants;
import org.foray.pdf.PdfObjectReference;
import org.foray.pdf.content.PdfResources;
@@ -119,9 +120,18 @@
/** The current character position. */
private long position = 0;
- /** The cross-reference information (tables and/or streams) for this document. */
- private PdfCrossRefInfo xrefInfo = new PdfCrossRefInfo();
+ /** The list of indirectly-referenced objects in this document. The index into the list is the object's object
+ * number, and should match the object number in {@link PdfObject#getIndirectReference()}. */
+ private List<PdfObject> indirectObjects = new ArrayList<PdfObject>();
+ {
+ /* Add a placeholder for object 0. */
+ this.indirectObjects.add(null);
+ }
+ /** Stack of indirect object IDs (indexes into {@link #indirectObjects} that, because their content my change
+ * during the serialization of other objects, should be serialized after all other objects have been serialized. */
+ private IntArrayBuilder indirectWriteLast = new IntArrayBuilder();
+
/** The /Root object. */
private PdfRoot root;
@@ -281,7 +291,9 @@
return this.resources;
}
- private void writeIndirectObjects(final OutputStream output) throws PdfException {
+ private PdfCrossRefInfo writeIndirectObjects(final OutputStream output) throws PdfException {
+ final PdfCrossRefInfo xrefInfo = new PdfCrossRefInfo();
+
/*
* Use a "while" loop here, because as each object is written, it has
* potential to reference another object indirectly, which will add an
@@ -288,33 +300,39 @@
* item to indirectObjects.
*/
int objectId = 1;
- while (objectId < this.xrefInfo.getTableSize()) {
- final PdfCrossRefEntry xref = this.xrefInfo.getTableEntry(objectId);
- if (xref.getOffset() > -1) {
- /* This object has already been written. */
- } else {
- final PdfObject object = xref.getObject();
- if (this.xrefInfo.isDeferred(objectId)) {
- /* We are not serializing this object yet. Set the offset accordingly. */
- xref.setOffset(-1);
- } else {
- /* Output the object and increment the character position by the object's length. */
- xref.setOffset(this.position);
- this.position += object.serialize(output, this);
- }
+ while (objectId < this.indirectObjects.size()) {
+ final PdfObject object = this.indirectObjects.get(objectId);
+ if (object != null) {
+ final PdfObjectReference reference = object.getIndirectReference();
+ if (this.indirectWriteLast.contains(reference.getNumber())) {
+ /* We are not serializing this object yet. */
+ } else {
+ /* Output the object and increment the character position by the object's length. */
+ final PdfCrossRefEntry xref = new PdfCrossRefEntry(object);
+ xref.setOffset(this.position);
+ xrefInfo.setTableEntry(reference.getNumber(), xref);
+ this.position += object.serialize(output, this);
+ }
}
objectId ++;
}
+ return xrefInfo;
}
- private void writeDeferredIndirectObjects(final OutputStream output) throws PdfException {
- final IntPrimitiveIterator deferredObjectIterator = this.xrefInfo.iteratorForDeferred();
+ private void writeDeferredIndirectObjects(final OutputStream output, final PdfCrossRefInfo xrefInfo)
+ throws PdfException {
+ /* Treat the deferred items like a stack, and iterate in reverse order. */
+ final IntPrimitiveIterator deferredObjectIterator = this.indirectWriteLast.iteratorReverse();
while (deferredObjectIterator.hasNext()) {
final int objectId = deferredObjectIterator.nextInt();
- final PdfCrossRefEntry xref = this.xrefInfo.getTableEntry(objectId);
- final PdfObject o = xref.getObject();
- xref.setOffset(this.position);
- this.position += o.serialize(output, this);
+ final PdfObject object = this.indirectObjects.get(objectId);
+ if (object != null) {
+ final PdfObjectReference reference = object.getIndirectReference();
+ final PdfCrossRefEntry xref = new PdfCrossRefEntry(object);
+ xref.setOffset(this.position);
+ xrefInfo.setTableEntry(reference.getNumber(), xref);
+ this.position += object.serialize(output, this);
+ }
}
}
@@ -327,7 +345,7 @@
private void writeTrailer(final OutputStream output, final long xrefPosition) throws PdfException, IOException {
/* Construct the trailer. */
final PdfTrailer trailer = getTrailer();
- trailer.put("Size", this.xrefInfo.getTableSize());
+ trailer.put("Size", this.indirectObjects.size());
trailer.put("Root", this.root);
final PdfDocumentInfo4a documentInfo = getDocumentInfo(false);
if (documentInfo != null
@@ -360,11 +378,8 @@
if (object.getIndirectReference() != null) {
return false;
}
- if (this.xrefInfo.getTableSize() < 1) {
- this.xrefInfo.addTableEntry(PdfCrossRefEntry.createInitialEntry());
- }
- final PdfObjectReference reference = new PdfObjectReference(this.xrefInfo.getTableSize(), 0);
+ final PdfObjectReference reference = new PdfObjectReference(this.indirectObjects.size(), 0);
object.registerIndirectReference(reference);
return true;
}
@@ -375,7 +390,7 @@
*/
public void registerIndirectObject(final PdfObject object) {
if (registerIndirectObjectShared(object)) {
- this.xrefInfo.addTableEntry(new PdfCrossRefEntry(object));
+ this.indirectObjects.add(object);
}
}
@@ -385,8 +400,9 @@
*/
public void registerIndirectObjectLast(final PdfObject object) {
if (registerIndirectObjectShared(object)) {
- this.xrefInfo.addDeferredTableEntry(new PdfCrossRefEntry(object));
+ this.indirectObjects.add(object);
}
+ this.indirectWriteLast.append(object.getIndirectReference().getNumber());
}
/**
@@ -766,12 +782,12 @@
this.position = serializer.getPosition();
/* Write the pages and other accumulated objects. */
- writeIndirectObjects(output);
- writeDeferredIndirectObjects(output);
+ final PdfCrossRefInfo xrefInfo = writeIndirectObjects(output);
+ writeDeferredIndirectObjects(output, xrefInfo);
/* Remember position of xref table. */
final long xrefPosition = this.position;
- this.xrefInfo.writeTable(output);
+ xrefInfo.writeTable(output);
writeTrailer(output, xrefPosition);
}
@@ -794,8 +810,8 @@
return this.lazyTrailer;
}
- public PdfCrossRefInfo getCrossRefInfo() {
- return this.xrefInfo;
+ public List<PdfObject> getIndirectObjects() {
+ return this.indirectObjects;
}
@Override
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefEntry.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefEntry.java 2022-01-30 13:02:06 UTC (rev 12509)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefEntry.java 2022-01-30 15:28:52 UTC (rev 12510)
@@ -29,6 +29,7 @@
package org.foray.pdf.serial;
import org.foray.pdf.PdfConstants;
+import org.foray.pdf.PdfObjectReference;
import org.foray.pdf.type.PdfObject;
import org.axsl.utility.sequence.ByteSequencePlus;
@@ -87,8 +88,14 @@
public PdfCrossRefEntry(final PdfObject object) {
this.offset = -1;
this.generation = 0;
- this.inUse = true;
+ this.inUse = object != null;
this.object = object;
+ if (object != null) {
+ final PdfObjectReference reference = object.getIndirectReference();
+ if (reference != null) {
+ this.generation = reference.getGeneration();
+ }
+ }
}
/**
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.java 2022-01-30 13:02:06 UTC (rev 12509)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfCrossRefInfo.java 2022-01-30 15:28:52 UTC (rev 12510)
@@ -83,6 +83,18 @@
}
/**
+ * Pushes an entry into a specific location in the table.
+ * @param index The index at which {@code xref} should be placed.
+ * @param xref The entry to be added.
+ */
+ public void setTableEntry(final int index, final PdfCrossRefEntry xref) {
+ while (this.xrefTable.size() <= index) {
+ this.xrefTable.add(null);
+ }
+ this.xrefTable.set(index, xref);
+ }
+
+ /**
* Adds a deferred entry (an entry that should be written toward the end of serialization) to the table.
* @param xref The entry to be added.
*/
@@ -115,8 +127,7 @@
* @throws IOException For errors while writing to the output stream.
*/
public void writeTable(final OutputStream stream) throws IOException {
-// int bytesWritten = 0;
-
+ /* Write header lines. */
final ByteArrayBuilder builder = new ByteArrayBuilder();
builder.append("xref");
builder.append(PdfObject.EOL);
@@ -123,12 +134,21 @@
builder.append("0 ");
builder.append(this.xrefTable.size());
builder.append(PdfObject.EOL);
-// bytesWritten += builder.length();
builder.writeTo(stream);
+ builder.clear();
+ /* Write entry 0. */
+ builder.append("0000000000 65535 f ");
+ builder.append(PdfObject.EOL);
+ builder.writeTo(stream);
builder.clear();
- for (int i = 0; i < this.xrefTable.size(); i++) {
+
+ /* Start the iteration of the remaining items at index 1. */
+ for (int i = 1; i < this.xrefTable.size(); i++) {
final PdfCrossRefEntry xref = this.xrefTable.get(i);
+ if (xref == null) {
+ builder.append("");
+ }
builder.append(xref.getOffsetFormatted());
builder.append(StringUtils.SINGLE_SPACE);
builder.append(xref.getGenerationFormatted());
@@ -136,7 +156,6 @@
builder.append(xref.getInUseFormatted());
builder.append(PdfObject.XREF_EOL);
-// bytesWritten += builder.length();
builder.writeTo(stream);
builder.clear();
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java 2022-01-30 13:02:06 UTC (rev 12509)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java 2022-01-30 15:28:52 UTC (rev 12510)
@@ -72,7 +72,7 @@
private void process4a(final PdfDocument4a pdf, final PrintStream output) {
output.println("PDF Version: " + pdf.getVersion().getVersionString());
- output.println("Qty Indirect Objects: " + pdf.getCrossRefInfo().getTableSize());
+ output.println("Qty Indirect Objects: " + pdf.getIndirectObjects().size());
// output.println("Is Encrypted? " + pdf.isEncrypted());
// final PdfDocumentInfo4a docInfo = pdf.getDocumentInfo(false);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-30 13:02:09
|
Revision: 12509
http://sourceforge.net/p/foray/code/12509
Author: victormote
Date: 2022-01-30 13:02:06 +0000 (Sun, 30 Jan 2022)
Log Message:
-----------
Remove PdfHeader from PdfDocument4a.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 12:45:35 UTC (rev 12508)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 13:02:06 UTC (rev 12509)
@@ -53,7 +53,6 @@
import org.foray.pdf.interchange.PdfDocumentInfo4a;
import org.foray.pdf.serial.PdfCrossRefEntry;
import org.foray.pdf.serial.PdfCrossRefInfo;
-import org.foray.pdf.serial.PdfHeader;
import org.foray.pdf.serial.PdfParser;
import org.foray.pdf.serial.PdfSerializer;
import org.foray.pdf.serial.PdfTrailer;
@@ -120,9 +119,6 @@
/** The current character position. */
private long position = 0;
- /** The header portion of this document. */
- private PdfHeader header = new PdfHeader();
-
/** The cross-reference information (tables and/or streams) for this document. */
private PdfCrossRefInfo xrefInfo = new PdfCrossRefInfo();
@@ -238,7 +234,7 @@
@Override
public PdfVersion getVersion() {
- return this.header.getPdfVersion();
+ return this.root.getPdfVersion();
}
@Override
@@ -246,7 +242,7 @@
if (newVersion == null) {
throw new IllegalArgumentException("Cannot set a null PDF Version");
}
- this.header.setPdfVersion(newVersion);
+ this.root.setPdfVersion(newVersion);
}
/**
@@ -798,10 +794,6 @@
return this.lazyTrailer;
}
- public PdfHeader getHeader() {
- return this.header;
- }
-
public PdfCrossRefInfo getCrossRefInfo() {
return this.xrefInfo;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-30 12:45:35 UTC (rev 12508)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-30 13:02:06 UTC (rev 12509)
@@ -40,6 +40,7 @@
import org.foray.pdf.structure.PdfNumberTree;
import org.foray.pdf.type.PdfDictionary;
+import org.axsl.pdf.PdfVersion;
import org.axsl.utility.sequence.ByteSequencePlus;
import java.util.List;
@@ -49,9 +50,15 @@
*/
public class PdfRoot extends PdfDictionary {
+ /** The default value for the PDF version. */
+ private static final PdfVersion DEFAULT_PDF_VERSION = PdfVersion.VERSION_1_6;
+
/** The parent PDF document. */
private PdfDocument4a document;
+ /** The version of PDF for this document. */
+ private PdfVersion pdfVersion;
+
/** The /Pages object that is root of the Pages hierarchy. */
private PdfPages pages;
@@ -74,6 +81,7 @@
*/
public PdfRoot(final PdfDocument4a document) {
this.document = document;
+ this.pdfVersion = DEFAULT_PDF_VERSION;
this.pages = new PdfPages(this);
}
@@ -218,4 +226,20 @@
return this.document;
}
+ /**
+ * Sets the PDF version for this document.
+ * @param pdfVersion The new value for the PDF version.
+ */
+ public void setPdfVersion(final PdfVersion pdfVersion) {
+ this.pdfVersion = pdfVersion;
+ }
+
+ /**
+ * Returns the version of PDF for this document.
+ * @return The PDF version.
+ */
+ public PdfVersion getPdfVersion() {
+ return pdfVersion;
+ }
+
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java 2022-01-30 12:45:35 UTC (rev 12508)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java 2022-01-30 13:02:06 UTC (rev 12509)
@@ -36,14 +36,11 @@
import org.axsl.pdf.PdfVersion;
/**
- * The header portion of a PDF document.
+ * The header portion of a serialized PDF document.
* @see "PDF Reference, Sixth Edition (PDF version 1.7), Section 3.4.1"
*/
public class PdfHeader {
- /** The default value for the PDF version. */
- private static final PdfVersion DEFAULT_PDF_VERSION = PdfVersion.VERSION_1_6;
-
/** A default value for the binary comment as recommended by the PDF spec (3.4.1). */
private static final ByteArray DEFAULT_BINARY_COMMENT = new ByteArray(
(byte) 0xAA,
@@ -59,8 +56,8 @@
* document may contain binary data. */
private ByteArray binaryComment;
- public PdfHeader() {
- this.pdfVersion = DEFAULT_PDF_VERSION;
+ public PdfHeader(final PdfVersion pdfVersion) {
+ this.pdfVersion = pdfVersion;
this.binaryComment = DEFAULT_BINARY_COMMENT;
}
@@ -77,22 +74,6 @@
}
/**
- * Returns the version of PDF for this document.
- * @return The PDF version.
- */
- public PdfVersion getPdfVersion() {
- return pdfVersion;
- }
-
- /**
- * Sets the PDF version for this document.
- * @param pdfVersion The new value for the PDF version.
- */
- public void setPdfVersion(final PdfVersion pdfVersion) {
- this.pdfVersion = pdfVersion;
- }
-
- /**
* Returns the binary comment, written immediately after the header line, indicating to parsing applications that
* this document may contain binary data.
* @see "PDF Reference, Sixth Edition (PDF version 1.7), Section 3.4.1."
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-30 12:45:35 UTC (rev 12508)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-30 13:02:06 UTC (rev 12509)
@@ -91,11 +91,15 @@
/* TODO: Remove following line after config is used. */
ObjectUtils.noOperation(this.config);
- final PdfHeader header = new PdfHeader();
- header.setPdfVersion(this.document.getVersion());
+ final PdfHeader header = new PdfHeader(this.document.getVersion());
processBytes(header.serialize());
}
+ /**
+ * Writes a sequence of bytes to the output and adds the size to the position.
+ * @param bytes The bytes to be written.
+ * @throws IOException For errors writing to the output stream.
+ */
private void processBytes(final ByteSequencePlus bytes) throws IOException {
bytes.writeTo(this.output);
this.position += bytes.length();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-30 12:45:38
|
Revision: 12508
http://sourceforge.net/p/foray/code/12508
Author: victormote
Date: 2022-01-30 12:45:35 +0000 (Sun, 30 Jan 2022)
Log Message:
-----------
Begin process of moving serialization code from PdfDocument4a to new class PdfSerializer.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 11:19:19 UTC (rev 12507)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-30 12:45:35 UTC (rev 12508)
@@ -55,6 +55,7 @@
import org.foray.pdf.serial.PdfCrossRefInfo;
import org.foray.pdf.serial.PdfHeader;
import org.foray.pdf.serial.PdfParser;
+import org.foray.pdf.serial.PdfSerializer;
import org.foray.pdf.serial.PdfTrailer;
import org.foray.pdf.text.PdfEncoding4a;
import org.foray.pdf.text.PdfFont4a;
@@ -197,10 +198,6 @@
/** The PostScript server. */
private PsServer psServer;
- /** Indicates whether this document has already been serialized. After serialization, an exception is thrown if
- * serialization is attempted again. */
- private boolean serialized = false;
-
/** The trailer dictionary. Always use {@link #getTrailer()} to obtain the instance, because it is lazily
* created. */
private PdfTrailer lazyTrailer;
@@ -764,22 +761,13 @@
return this.info;
}
- private void checkAlreadySerialized() {
- if (this.serialized) {
- throw new IllegalStateException("Document has already been serialized. Cannot serialize again.");
- }
- this.serialized = true;
- }
-
@Override
public void serialize(final OutputStream output, final PdfSerializationConfig config)
throws PdfException, IOException {
- checkAlreadySerialized();
- this.position = 0;
+ final PdfSerializer serializer = new PdfSerializer(this, output, config);
+ serializer.process();
- final ByteArrayBuilder headerBytes = this.header.toPDF();
- headerBytes.writeTo(output);
- this.position += headerBytes.length();
+ this.position = serializer.getPosition();
/* Write the pages and other accumulated objects. */
writeIndirectObjects(output);
@@ -795,7 +783,6 @@
@Override
public void serialize(final OutputStream output, final PdfPageProvider<PdfPage4a> provider,
final PdfSerializationConfig config) {
- checkAlreadySerialized();
/* @TODO: Implement this. */
throw new UnsupportedOperationException();
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java 2022-01-30 11:19:19 UTC (rev 12507)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfHeader.java 2022-01-30 12:45:35 UTC (rev 12508)
@@ -64,7 +64,7 @@
this.binaryComment = DEFAULT_BINARY_COMMENT;
}
- public ByteArrayBuilder toPDF() {
+ public ByteArrayBuilder serialize() {
final ByteArrayBuilder builder = new ByteArrayBuilder();
// The PDF identifier comment.
builder.append(PdfConstants.DOCUMENT_BEGIN_MARKER);
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java 2022-01-30 12:45:35 UTC (rev 12508)
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2022 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.pdf.serial;
+
+import org.foray.common.primitive.ObjectUtils;
+import org.foray.pdf.document.PdfDocument4a;
+
+import org.axsl.pdf.PdfSerializationConfig;
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * Serializes a {@link PdfDocument4a}.
+ */
+public class PdfSerializer {
+
+ /**
+ * The default serialization configuration.
+ */
+ private static final PdfSerializationConfig DEFAULT_CONFIG = new PdfSerializationConfig() {
+
+ /* Checkstyle: Allow Magic Numbers that are hard-coded data. */
+
+ @Override
+ public int getMaxLineLength() {
+ return 120;
+ }
+
+ /* Checkstyle: Restart Magic Number checking. */
+ };
+
+ /** The document to be serialized. */
+ private PdfDocument4a document;
+
+ /** The configuration for the serialization process. */
+ private PdfSerializationConfig config;
+
+ /** The output stream to which the serialized document should be written. */
+ private OutputStream output;
+
+ /** The index to the next byte to be written, which is the same as the number of bytes written so far. */
+ private int position;
+
+ /**
+ * Constructor.
+ * @param document The document to be serialized.
+ * @param output The output stream to which the serialized document should be written.
+ * @param config The configuration for the serialization process.
+ * If null, a default configuration will be used.
+ */
+ public PdfSerializer(final PdfDocument4a document, final OutputStream output, final PdfSerializationConfig config) {
+ this.document = document;
+ this.config = config == null ? DEFAULT_CONFIG : config;
+ this.output = output;
+ }
+
+ /**
+ * For the objects provided at construction, writes the serialized content of the document to the output stream
+ * using the configuration.
+ * @throws IOException For errors writing to the output stream.
+ */
+ public void process() throws IOException {
+ /* TODO: Remove following line after config is used. */
+ ObjectUtils.noOperation(this.config);
+
+ final PdfHeader header = new PdfHeader();
+ header.setPdfVersion(this.document.getVersion());
+ processBytes(header.serialize());
+ }
+
+ private void processBytes(final ByteSequencePlus bytes) throws IOException {
+ bytes.writeTo(this.output);
+ this.position += bytes.length();
+ }
+
+ /**
+ * Returns the number of bytes written so far.
+ * @return The number of bytes written so far.
+ */
+ public int getPosition() {
+ return this.position;
+ }
+
+}
Property changes on: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfSerializer.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-30 11:19:22
|
Revision: 12507
http://sourceforge.net/p/foray/code/12507
Author: victormote
Date: 2022-01-30 11:19:19 +0000 (Sun, 30 Jan 2022)
Log Message:
-----------
Rename PdfObjectReference methods for clarity.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/function/PdfFunction.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfShading.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationExplicit4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutline4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutlineItem4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfPageLabel.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoTo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoToRemote.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfBorderStyle.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfLink.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCidFont.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfEncoding4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFont4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -100,21 +100,20 @@
}
/**
- * The String used to reference this object within the PDF.
- * @return The String used to reference this object within the PDF, in the form of "196 0 R", where 196 is the
- * object ID, 0 is the object generation, and "R" is a keyword indicating a reference to an object.
+ * The String used to <em>reference</em> this object within a serialized PDF.
+ * @return The String used to reference this object within a serialized PDF, in the form of "196 0 R", where 196 is
+ * the object ID, 0 is the object generation, and "R" is a keyword indicating a reference to an object.
*/
- public String pdfReference() {
+ public String getSerializedReference() {
return this.number + " " + this.generation + " R";
}
/**
- * The String used to identify this object as it is written in the PDF.
- * @return The String used to identify this object as it is written in the PDF, in the form of "196 0 obj",
- * where 196 is the object ID, 0 is the object generation, and "obj" is a keyword indicating the beginning of the
- * object.
+ * The String used to <em>identify</em> this object within a serialized PDF.
+ * @return The String used to identify this object within a serialized PDF, in the form of "196 0 obj", where 196 is
+ * the object ID, 0 is the object generation, and "obj" is a keyword indicating the beginning of the object.
*/
- public String pdfID() {
+ public String getSerializedId() {
return this.number + " " + this.generation + " obj";
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -96,7 +96,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append("<<" + EOL);
if (! this.fonts.isEmpty()) {
/* construct PDF dictionary of font object references */
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -75,7 +75,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append("[" + EOL);
for (int i = 0; i < this.annotations.size(); i++) {
final PdfAnnotation child = this.annotations.get(i);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -137,7 +137,7 @@
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder sb = new StringBuilder();
- sb.append(this.pdfID() + EOL
+ sb.append(this.getSerializedId() + EOL
+ "<<" + EOL
+ "/Type /Page" + EOL
+ "/Parent " + this.parent.pdfReference(doc) + EOL
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -78,7 +78,7 @@
public ByteSequencePlus serialize(final PdfDocument4a doc) {
/* TODO: Create a balanced tree here. See the PDF Reference. */
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append("<< /Type /Pages" + EOL);
p.append("/Count " + this.kids.size() + EOL);
p.append("/Kids [" + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -155,7 +155,7 @@
*/
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append(PdfConstants.OPEN_DICTIONARY + EOL);
p.append("/Type /Catalog" + EOL);
p.append("/Pages " + this.pages.pdfReference(doc) + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -345,7 +345,7 @@
prepPassword(""), this.encryptionKey);
// Create the dictionary
- this.dictionary = this.pdfID() + EOL
+ this.dictionary = this.getSerializedId() + EOL
+ "<<" + EOL
+ "/Filter" + EOL
+ "/Standard" + EOL
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -67,7 +67,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder builder = new StringBuilder();
- builder.append(pdfID() + EOL
+ builder.append(getSerializedId() + EOL
+ "<<" + EOL
+ "/Type /FileSpec" + EOL);
if (this.filename != null) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/function/PdfFunction.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/function/PdfFunction.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/function/PdfFunction.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -419,7 +419,7 @@
int numberOfFunctions = 0;
int tempInt = 0;
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL + "<<" + EOL + "/FunctionType "
+ p.append(this.getSerializedId() + EOL + "<<" + EOL + "/FunctionType "
+ this.functionType + EOL);
// FunctionType 0
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -186,7 +186,7 @@
int vectorSize = 0;
int tempInt = 0;
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL + "<<" + EOL + "/Type /Pattern" + EOL);
+ p.append(this.getSerializedId() + EOL + "<<" + EOL + "/Type /Pattern" + EOL);
if (this.resources != null) {
p.append("/Resources " + this.resources.pdfReference(doc) + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfShading.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfShading.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfShading.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -375,7 +375,7 @@
int vectorSize;
int tempInt;
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append("<<" + EOL);
p.append("/ShadingType " + this.shadingType + EOL);
if (this.colorSpace != null) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationExplicit4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationExplicit4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationExplicit4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -80,7 +80,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder buffer = new StringBuilder();
- buffer.append(this.pdfID());
+ buffer.append(this.getSerializedId());
buffer.append(EOL);
buffer.append("[");
buffer.append(this.page.pdfReference(doc));
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutline4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutline4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutline4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -55,7 +55,7 @@
return ByteArray.EMPTY;
}
final StringBuilder result = new StringBuilder();
- result.append(this.pdfID() + EOL);
+ result.append(this.getSerializedId() + EOL);
result.append("<<" + EOL);
result.append(" /Type /Outlines" + EOL);
if (getFirst() != null && getLast() != null) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutlineItem4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutlineItem4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutlineItem4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -171,7 +171,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder result = new StringBuilder();
- result.append(this.pdfID() + EOL + "<<" + EOL);
+ result.append(this.getSerializedId() + EOL + "<<" + EOL);
final int countDescendants = this.count();
// subentry Outline object
result.append(" /Title " + this.title.serialize(doc) + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfPageLabel.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfPageLabel.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfPageLabel.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -81,7 +81,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder buffer = new StringBuilder();
- buffer.append(this.pdfID() + EOL);
+ buffer.append(this.getSerializedId() + EOL);
buffer.append("<< /Type /PageLabel" + EOL);
if (this.style != null) {
buffer.append("/S /" + this.style.getPdfName() + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoTo.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoTo.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoTo.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -60,7 +60,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder buffer = new StringBuilder();
- buffer.append(this.pdfID() + EOL);
+ buffer.append(this.getSerializedId() + EOL);
buffer.append("<<" + EOL);
buffer.append("/S /GoTo" + EOL);
buffer.append("/D " + this.destination.serialize(doc) + ">>" + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoToRemote.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoToRemote.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoToRemote.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -86,7 +86,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
- String p = new String(this.pdfID() + EOL
+ String p = new String(this.getSerializedId() + EOL
+ "<<" + EOL + "/S /GoToR" + EOL + "/F "
+ this.pdfFileSpec.pdfReference(doc) + "" + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfBorderStyle.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfBorderStyle.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfBorderStyle.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -108,7 +108,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder buffer = new StringBuilder();
- buffer.append(this.pdfID() + EOL);
+ buffer.append(this.getSerializedId() + EOL);
buffer.append("<< /Type /Border" + EOL);
if (this.width >= 0) {
buffer.append("/W " + this.width + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfLink.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfLink.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfLink.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -119,7 +119,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder buffer = new StringBuilder();
- buffer.append(this.pdfID() + EOL);
+ buffer.append(this.getSerializedId() + EOL);
buffer.append("<<" + EOL
+ "/Type /Annot" + EOL
+ "/Subtype /Link" + EOL
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -54,7 +54,7 @@
/* TODO: This currently handles a tree with only one level. Add the capability here of writing a root node,
* intermediate nodes, and leaf nodes to properly balance the serialized version of the tree for performance. */
final ByteArrayBuilder p = new ByteArrayBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append("<<");
p.append(EOL);
p.append("/Limits [(");
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -51,7 +51,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append("<<" + EOL);
p.append("/Nums [" + EOL);
for (Map.Entry<Integer, T> entry : this.nums.entrySet()) {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCidFont.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCidFont.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCidFont.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -127,7 +127,7 @@
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final Font font = this.fsFont.getFont();
final StringBuilder p = new StringBuilder();
- p.append(pdfID() + EOL);
+ p.append(getSerializedId() + EOL);
p.append("<< /Type /Font");
p.append(EOL + "/BaseFont /");
p.append(font.getPostscriptName());
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfEncoding4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfEncoding4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfEncoding4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -92,7 +92,7 @@
return ByteArray.EMPTY;
}
final StringBuilder p = new StringBuilder();
- p.append(pdfID() + EOL);
+ p.append(getSerializedId() + EOL);
p.append("% " + this.encoding.getName() + EOL);
p.append("<< /Type /Encoding" + EOL);
p.append(this.encoding.asPostScript(null));
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFont4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFont4a.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFont4a.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -173,7 +173,7 @@
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final StringBuilder buffer = new StringBuilder();
- buffer.append(this.pdfID() + EOL);
+ buffer.append(this.getSerializedId() + EOL);
buffer.append("<<" + EOL);
buffer.append("/Type /Font" + EOL);
buffer.append("/Subtype /" + this.getFontSubtype().getPdfName() + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontDescriptor.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontDescriptor.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontDescriptor.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -140,7 +140,7 @@
public ByteSequencePlus serialize(final PdfDocument4a doc) {
final Font font = this.pdfFont.getFont();
final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
+ p.append(this.getSerializedId() + EOL);
p.append("<< /Type /FontDescriptor" + EOL);
p.append("/FontName /" + this.pdfFont.getBaseFont(doc));
p.append(EOL + "/FontBBox ");
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -126,7 +126,7 @@
if (object != null) {
final PdfObjectReference indirectReference = object.getIndirectReference();
final ByteSequencePlus asPdf = indirectReference == null ? object.serialize(doc) :
- new ByteArray(indirectReference.pdfReference());
+ new ByteArray(indirectReference.getSerializedReference());
if (asPdf != null
&& ! asPdf.isEmpty()) {
builder.append("/");
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -64,8 +64,8 @@
/**
* Writes the serialized content of this object directly to an output stream.
- * The default case first runs {@link #serialize(PdfDocument4a)} first, then writes the result of that to the
- * output stream.
+ * The default case runs {@link #serialize(PdfDocument4a)} first, then writes the result of that to the output
+ * stream.
* Subclasses like streams that do not wish to spend the memory to hold the entire serialized content in memory
* should override this method to write directly to the stream.
* @param stream The stream to which the PDF content is being written.
@@ -98,7 +98,7 @@
*/
public String pdfReference(final PdfDocument4a doc) {
doc.registerIndirectObject(this);
- return this.reference.pdfReference();
+ return this.reference.getSerializedReference();
}
/**
@@ -106,8 +106,8 @@
* @return The String used to identify this object as it is written in the
* PDF.
*/
- protected String pdfID() {
- return this.reference.pdfID();
+ protected String getSerializedId() {
+ return this.reference.getSerializedId();
}
public PdfObjectReference getIndirectReference() {
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java 2022-01-29 23:18:11 UTC (rev 12506)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java 2022-01-30 11:19:19 UTC (rev 12507)
@@ -251,7 +251,7 @@
/* Write the dictionary. */
final StringBuilder builder = new StringBuilder();
- builder.append(this.pdfID() + EOL
+ builder.append(this.getSerializedId() + EOL
+ "<<" + EOL);
final String special = specialStreamDictEntries(doc);
builder.append(special);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-29 23:18:14
|
Revision: 12506
http://sourceforge.net/p/foray/code/12506
Author: victormote
Date: 2022-01-29 23:18:11 +0000 (Sat, 29 Jan 2022)
Log Message:
-----------
Rename method for clarity. Upgrade its doc to explain why two similar methods are needed.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-29 22:26:06 UTC (rev 12505)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-29 23:18:11 UTC (rev 12506)
@@ -307,7 +307,7 @@
} else {
/* Output the object and increment the character position by the object's length. */
xref.setOffset(this.position);
- this.position += object.output(output, this);
+ this.position += object.serialize(output, this);
}
}
objectId ++;
@@ -321,7 +321,7 @@
final PdfCrossRefEntry xref = this.xrefInfo.getTableEntry(objectId);
final PdfObject o = xref.getObject();
xref.setOffset(this.position);
- this.position += o.output(output, this);
+ this.position += o.serialize(output, this);
}
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-29 22:26:06 UTC (rev 12505)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-29 23:18:11 UTC (rev 12506)
@@ -55,13 +55,26 @@
private PdfObjectReference reference;
/**
- * Write the PDF represention of this object to a given output stream.
+ * Returns this object in its serialized form, i.e. the content that should be written to a PDF file.
+ * @param doc The PDF document, which contains data needed by some objects in it.
+ * @return The PDF text necessary to represent the object. This should never be null, but can be empty.
+ * @see #serialize(OutputStream, PdfDocument4a)
+ */
+ public abstract ByteSequencePlus serialize(PdfDocument4a doc);
+
+ /**
+ * Writes the serialized content of this object directly to an output stream.
+ * The default case first runs {@link #serialize(PdfDocument4a)} first, then writes the result of that to the
+ * output stream.
+ * Subclasses like streams that do not wish to spend the memory to hold the entire serialized content in memory
+ * should override this method to write directly to the stream.
* @param stream The stream to which the PDF content is being written.
* @param doc The PDF document being written.
* @return The number of bytes written.
* @throws PdfException For I/O errors during output.
+ * @see #serialize(PdfDocument4a)
*/
- public int output(final OutputStream stream, final PdfDocument4a doc) throws PdfException {
+ public int serialize(final OutputStream stream, final PdfDocument4a doc) throws PdfException {
final ByteSequencePlus pdf = this.serialize(doc);
try {
pdf.writeTo(stream);
@@ -97,13 +110,6 @@
return this.reference.pdfID();
}
- /**
- * Returns this object in its serialized form, i.e. the content that should be written to a PDF file.
- * @param doc The PDF document, which contains data needed by some objects in it.
- * @return The PDF text necessary to represent the object. This should never be null, but can be empty.
- */
- public abstract ByteSequencePlus serialize(PdfDocument4a doc);
-
public PdfObjectReference getIndirectReference() {
return this.reference;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java 2022-01-29 22:26:06 UTC (rev 12505)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java 2022-01-29 23:18:11 UTC (rev 12506)
@@ -232,15 +232,18 @@
return this.bytesWritten;
}
+ /**
+ * Since the content of the stream could be huge, this method will always throw a {@link RuntimeException}.
+ * Use {@link #serialize(OutputStream, PdfDocument4a)} instead.
+ */
@Override
public ByteSequencePlus serialize(final PdfDocument4a doc) {
- throw new RuntimeException();
+ throw new RuntimeException("This content could be huge. Use serialize(OutputStream, PdfDocument4a) instead.");
}
@Override
- public int output(final OutputStream stream, final PdfDocument4a doc) throws PdfException {
- /* Give subclasses an opportunity to finish writing to the stream
- * content. */
+ public int serialize(final OutputStream stream, final PdfDocument4a doc) throws PdfException {
+ /* Give subclasses an opportunity to finish writing to the stream content. */
finalizeStreamContent(doc);
int length = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-29 22:26:08
|
Revision: 12505
http://sourceforge.net/p/foray/code/12505
Author: victormote
Date: 2022-01-29 22:26:06 +0000 (Sat, 29 Jan 2022)
Log Message:
-----------
Disallow a null result from serialization.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-29 22:16:36 UTC (rev 12504)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java 2022-01-29 22:26:06 UTC (rev 12505)
@@ -63,9 +63,6 @@
*/
public int output(final OutputStream stream, final PdfDocument4a doc) throws PdfException {
final ByteSequencePlus pdf = this.serialize(doc);
- if (pdf == null) {
- return 0;
- }
try {
pdf.writeTo(stream);
} catch (final IOException e) {
@@ -103,7 +100,7 @@
/**
* Returns this object in its serialized form, i.e. the content that should be written to a PDF file.
* @param doc The PDF document, which contains data needed by some objects in it.
- * @return The PDF text necessary to represent the object.
+ * @return The PDF text necessary to represent the object. This should never be null, but can be empty.
*/
public abstract ByteSequencePlus serialize(PdfDocument4a doc);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <vic...@us...> - 2022-01-29 22:16:41
|
Revision: 12504
http://sourceforge.net/p/foray/code/12504
Author: victormote
Date: 2022-01-29 22:16:36 +0000 (Sat, 29 Jan 2022)
Log Message:
-----------
Complete movement of types in the "object" package to more specific packages.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfGraphicsState4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfImageXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfShading.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXreference.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutlineItem4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoToRemote.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfLink.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfParser.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFont4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfGraphics2D.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentInfo4aTests.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/serial/PdfParserTests.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfContentStream4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/function/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/function/PdfFunction.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/function/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfColor4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfIccProfileStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfBorderStyle.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/PdfDocumentInfo4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interchange/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfGenericDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfGenericStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCharProcs.java
Removed Paths:
-------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java (from rev 12503, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfObjectReference.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfObjectReference.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,121 @@
+/*
+ * 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.pdf;
+
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.document.PdfDocument4a;
+import org.foray.pdf.type.PdfInteger;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.pdf.PdfException;
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+/**
+ * <p>A reference to an indirect object, also known as a labeled object.
+ * These references are used throughout a PDF to either 1) define an object as being an indirect object, or 2) to refer
+ * to the indirect object.
+ * The physical offset of each indirect object is also stored in the cross-reference table near the end of a PDF, with
+ * the object number being the index into that table, and the generation being written into the table content.</p>
+ */
+public class PdfObjectReference extends PdfObject {
+
+ /** The object's number. */
+ private int number = -1;
+
+ /** The object's generation (0 in new documents). */
+ private int generation = 0;
+
+ public PdfObjectReference(final int objectNumber, final int generation) {
+ this.number = objectNumber;
+ this.generation = generation;
+ }
+
+ public PdfObjectReference(final PdfObject objectNumber, final PdfObject generation) throws PdfException {
+ if (! (objectNumber instanceof PdfInteger)) {
+ throw new PdfException("Object Id value must be an integer, actual = " + objectNumber.toString());
+ }
+ if (! (generation instanceof PdfInteger)) {
+ throw new PdfException("Generation must be an integer, actual = " + generation.toString());
+ }
+ this.number = ((PdfInteger) objectNumber).getValue();
+ this.generation = ((PdfInteger) generation).getValue();
+ }
+
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ return ByteArray.EMPTY;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("[");
+ builder.append(this.number);
+ builder.append(", ");
+ builder.append(this.generation);
+ builder.append("]");
+ return builder.toString();
+ }
+
+ /**
+ * Returns this object's number.
+ * @return The PDF Object number.
+ */
+ public int getNumber() {
+ return this.number;
+ }
+
+ /**
+ * Returns this object's generation number.
+ * @return The PDF generation number.
+ */
+ public int getGeneration() {
+ return this.generation;
+ }
+
+ /**
+ * The String used to reference this object within the PDF.
+ * @return The String used to reference this object within the PDF, in the form of "196 0 R", where 196 is the
+ * object ID, 0 is the object generation, and "R" is a keyword indicating a reference to an object.
+ */
+ public String pdfReference() {
+ return this.number + " " + this.generation + " R";
+ }
+
+ /**
+ * The String used to identify this object as it is written in the PDF.
+ * @return The String used to identify this object as it is written in the PDF, in the form of "196 0 obj",
+ * where 196 is the object ID, 0 is the object generation, and "obj" is a keyword indicating the beginning of the
+ * object.
+ */
+ public String pdfID() {
+ return this.number + " " + this.generation + " obj";
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfContentStream4a.java (from rev 12503, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfContentStream4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfContentStream4a.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,371 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.content;
+
+import org.foray.common.WellKnownConstants;
+import org.foray.pdf.document.PdfDocument4a;
+import org.foray.pdf.graphics.PdfDashPattern4a;
+import org.foray.pdf.graphics.PdfGraphicsState4a;
+import org.foray.pdf.type.PdfStream;
+
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontContext;
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.orthography.Orthography;
+import org.axsl.pdf.PdfColor;
+import org.axsl.pdf.PdfContentStream;
+import org.axsl.pdf.PdfException;
+import org.axsl.pdf.PdfFont;
+import org.axsl.pdf.PdfLineCapStyle;
+import org.axsl.pdf.PdfTextRenderingMode;
+import org.axsl.pdf.PdfXobject;
+
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
+import java.util.Stack;
+
+/**
+ * Specialized version of PdfStream with methods useful in creating PDF content
+ * streams.
+ */
+public class PdfContentStream4a extends PdfStream implements PdfContentStream {
+
+ /** The stack of PDF Graphics States for this content stream. */
+ private Stack<PdfGraphicsState4a> graphicsStateStack = new Stack<PdfGraphicsState4a>();
+
+ /** State variable indicating whether a text object is currently open. */
+ private boolean textObjectOpen = false;
+
+ /**
+ * Constructor.
+ */
+ public PdfContentStream4a() {
+ this.graphicsStateStack.push(new PdfGraphicsState4a());
+ }
+
+ /**
+ * Returns the current graphics state.
+ * @return The current graphics state.
+ */
+ public PdfGraphicsState4a getCurrentGraphicsState() {
+ return this.graphicsStateStack.peek();
+ }
+
+ @Override
+ public void close() throws PdfException {
+ closeTextObject();
+ }
+
+ /**
+ * Makes the stream ready to accept text manipulation operators.
+ * @throws PdfException For errors writing the content.
+ */
+ public void openTextObject() throws PdfException {
+ if (! this.textObjectOpen) {
+ write("BT" + EOL);
+ this.textObjectOpen = true;
+ }
+ }
+
+ /**
+ * Closes any open text object.
+ * @throws PdfException For errors writing the content.
+ */
+ public void closeTextObject() throws PdfException {
+ if (this.textObjectOpen) {
+ write("ET" + EOL);
+ this.textObjectOpen = false;
+ }
+ }
+
+ @Override
+ public synchronized void setCursor(final float originX, final float originY)
+ throws PdfException {
+ openTextObject();
+ write("1 0 0 1 " + originX + " " + originY + " Tm" + EOL);
+ }
+
+ @Override
+ public synchronized void drawText(final CharSequence text, final FontContext fontContext,
+ final Orthography orthography) throws PdfException {
+ if (text.length() < 1) {
+ return;
+ }
+ openTextObject();
+ final CharSequence stringOut =
+ this.getCurrentGraphicsState().getTextState().getFont().textToPdf(text, fontContext, orthography);
+ write(stringOut);
+ }
+
+ @Override
+ public void setFont(final PdfFont newFont, final float newFontSize) throws PdfException {
+ openTextObject();
+ boolean anyChange = false;
+ anyChange |= this.getCurrentGraphicsState().getTextState().setFont(newFont);
+ anyChange |= this.getCurrentGraphicsState().getTextState().setFontSize(newFontSize);
+ if (! anyChange) {
+ // Nothing needs to change.
+ return;
+ }
+ final String psStyleName = newFont.getName();
+ write("/" + psStyleName + " " + newFontSize + " Tf" + EOL);
+ }
+
+ @Override
+ public void setStrokeColor(final PdfColor newColor) throws PdfException {
+ if (! this.getCurrentGraphicsState().setStrokeColor(newColor)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newColor.getSetterString(false));
+ }
+
+ @Override
+ public void setFillColor(final PdfColor newColor) throws PdfException {
+ if (! this.getCurrentGraphicsState().setFillColor(newColor)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newColor.getSetterString(true));
+ }
+
+ @Override
+ public void setWordSpacing(final float newWordSpacing) throws PdfException {
+ /* TODO: Remove following line. We do not need to be in a text object
+ * to set this parameter. */
+ openTextObject();
+ if (! this.getCurrentGraphicsState().getTextState().setWordSpacing(newWordSpacing)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newWordSpacing + " Tw" + EOL);
+ }
+
+ @Override
+ public void setCharacterSpacing(final float newCharacterSpacing) throws PdfException {
+ /* TODO: Remove following line. We do not need to be in a text object
+ * to set this parameter. */
+ openTextObject();
+ if (! this.getCurrentGraphicsState().getTextState().setCharacterSpacing(newCharacterSpacing)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newCharacterSpacing + " Tc" + EOL);
+ }
+
+ @Override
+ public void setHorizontalScaling(final float newHorizontalScaling) throws PdfException {
+ if (! this.getCurrentGraphicsState().getTextState().setHorizontalScaling(newHorizontalScaling)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newHorizontalScaling + " Tz" + EOL);
+ }
+
+ @Override
+ public void setLeading(final float newLeading) throws PdfException {
+ if (! this.getCurrentGraphicsState().getTextState().setLeading(newLeading)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newLeading + " TL" + EOL);
+ }
+
+ @Override
+ public void setTextRenderingMode(final PdfTextRenderingMode newTextRenderingMode)
+ throws PdfException {
+ PdfTextRenderingMode mode = newTextRenderingMode;
+ if (mode == null) {
+ mode = PdfTextRenderingMode.FILL;
+ }
+ if (! this.getCurrentGraphicsState().getTextState().setTextRenderingMode(mode)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(mode.getModeValue() + " Tr" + EOL);
+ }
+
+ @Override
+ public void setTextRise(final float newTextRise) throws PdfException {
+ if (! this.getCurrentGraphicsState().getTextState().setTextRise(newTextRise)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newTextRise + " Ts" + EOL);
+ }
+
+ @Override
+ public void setTextKnockout(final boolean newTextKnockout) {
+ if (this.textObjectOpen) {
+ throw new IllegalStateException("Text Knockout may not be set when "
+ + "a text object is open.");
+ }
+ throw new UnsupportedOperationException(
+ "Unsupported: set text knockout");
+ }
+
+ @Override
+ public void setLineCapStyle(final PdfLineCapStyle newLineCapStyle) throws PdfException {
+ if (! this.getCurrentGraphicsState().setLineCapStyle(newLineCapStyle)) {
+ // Nothing needs to change.
+ return;
+ }
+ write(newLineCapStyle.getPdfValue() + " J" + EOL);
+ }
+
+ @Override
+ public void drawLine(final Line2D.Float line) throws PdfException {
+ closeTextObject();
+ write("q" + EOL);
+ write(line.x1 + " " + line.y1 + " m" + EOL);
+ write(line.x2 + " " + line.y2 + " l" + EOL);
+ write("S" + EOL);
+ write("Q" + EOL);
+ }
+
+ @Override
+ public void drawRectangle(final Rectangle2D.Float rectangle,
+ final boolean stroke, final boolean fill) throws PdfException {
+ /* Bail out if neither stroking nor filling. */
+ if (! stroke && ! fill) {
+ return;
+ }
+ closeTextObject();
+ write("q" + EOL);
+ /* Draw the rectangle. */
+ write(rectangle.x + " " + rectangle.y + " " + rectangle.width + " "
+ + rectangle.height + " re ");
+ if (stroke && fill) {
+ /* Close, fill, and stroke the rectangle. */
+ write("b");
+ } else if (stroke) {
+ /* Close and stroke the rectangle. */
+ write("s");
+ } else {
+ /* Fill the rectangle. */
+ write("f");
+ }
+ write(EOL);
+ write("Q" + EOL);
+ }
+
+ @Override
+ public void drawGraphic(final Graphic image, final Rectangle2D.Float contentRectangle,
+ final Rectangle2D.Float clipRectangle, final FontConsumer fontConsumer) throws PdfException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Clips a specified content rectangle to a specified clip rectangle.
+ * @param clipRectangle The clip rectangle.
+ * @param contentRectangle The content rectangle.
+ * @throws PdfException For errors while writing the clip.
+ */
+ private void clip(final Rectangle2D.Float clipRectangle,
+ final Rectangle2D.Float contentRectangle) throws PdfException {
+ if (clipRectangle == null || contentRectangle == null) {
+ return;
+ }
+ /* If the clip rectangle contains all of the content rectangle,
+ * clipping will make the output larger for no benefit. */
+ if (clipRectangle.contains(contentRectangle)) {
+ return;
+ }
+ // Start a new path at the lower left corner.
+ write(clipRectangle.getMinX() + " " + clipRectangle.getMinY() + " m"
+ + EOL);
+ // Append a line across the bottom of the rectangle (left-to-right).
+ write(clipRectangle.getMaxX() + " " + clipRectangle.getMinY() + " l"
+ + EOL);
+ // Append a line up the right side of the rectangle.
+ write(clipRectangle.getMaxX() + " " + clipRectangle.getMaxY() + " l"
+ + EOL);
+ // Append a line across the top of the rectangle (right-to-left).
+ write(clipRectangle.getMinX() + " " + clipRectangle.getMaxY() + " l"
+ + EOL);
+ // Close the path and merge it with the clipping path
+ write("h W n" + EOL);
+ }
+
+ @Override
+ public void setLineWidth(final float width) throws PdfException {
+ write(width + " w" + EOL);
+ }
+
+ @Override
+ public void setDashPattern(final float[] dashArray, final float dashPhase) throws PdfException {
+ final PdfDashPattern4a newDashPattern = new PdfDashPattern4a(dashArray, dashPhase);
+ if (! this.getCurrentGraphicsState().setLineDashPattern(newDashPattern)) {
+ // Nothing needs to change.
+ return;
+ }
+ write("[");
+ if (dashArray != null) {
+ for (int i = 0; i < dashArray.length; i++) {
+ if (i != 0) {
+ write(" ");
+ }
+ write(Float.toString(dashArray[i]));
+ }
+ }
+ write("] " + dashPhase + " d" + EOL);
+ }
+
+ @Override
+ protected void finalizeStreamContent(final PdfDocument4a doc) {
+ /* Nothing needs to be done here. */
+ }
+
+ @Override
+ protected String specialStreamDictEntries(final PdfDocument4a doc) {
+ return WellKnownConstants.EMPTY_STRING;
+ }
+
+ @Override
+ public void drawXobject(final PdfXobject xObject, final Rectangle2D.Float contentRectangle,
+ final Rectangle2D.Float clipRectangle) throws PdfException {
+ closeTextObject();
+ write("q" + EOL);
+ clip(clipRectangle, contentRectangle);
+ try {
+ write(xObject.getHorizontalScaling(contentRectangle)
+ + " 0 0 "
+ + xObject.getVerticalScaling(contentRectangle) + " "
+ + contentRectangle.x + " "
+ + (contentRectangle.y - contentRectangle.height) + " cm"
+ + EOL);
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+ write("/" + xObject.getXobjectName() + " Do" + EOL);
+ write("Q" + EOL);
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java (from rev 12503, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/PdfResources.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.content;
+
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.document.PdfDocument4a;
+import org.foray.pdf.graphics.PdfPattern4a;
+import org.foray.pdf.graphics.PdfShading;
+import org.foray.pdf.graphics.PdfXobject4a;
+import org.foray.pdf.text.PdfFont4a;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * class representing a /Resources object.
+ *
+ * /Resources object contain a list of references to the fonts for the
+ * document
+ */
+public class PdfResources extends PdfObject {
+
+ /** The list of fonts used in this document. */
+ private List<PdfFont4a> fonts = new ArrayList<PdfFont4a>();
+
+ /** The list of X Objects used in this document. */
+ private List<PdfXobject4a> xObjects = new ArrayList<PdfXobject4a>();
+
+ /** The list of patterns used in this document. */
+ private List<PdfPattern4a> patterns = new ArrayList<PdfPattern4a>();
+
+ /** The list of shadings used in this document. */
+ private List<PdfShading> shadings = new ArrayList<PdfShading>();
+
+ /**
+ * Add a font object to resources list.
+ * @param font The PdfFont4a to add.
+ */
+ public void addFont(final PdfFont4a font) {
+ this.fonts.add(font);
+ }
+
+ /**
+ * Add an x object to the resources list.
+ * @param xObject The x object to add.
+ */
+ public void addXObject(final PdfXobject4a xObject) {
+ this.xObjects.add(xObject);
+ }
+
+ /**
+ * Add a shading to the resources list.
+ * @param shading The shading to add.
+ */
+ public void addShading(final PdfShading shading) {
+ this.shadings.add(shading);
+ }
+
+ /**
+ * Add a pattern to the resources list.
+ * @param pattern The pattern to add.
+ */
+ public void addPattern(final PdfPattern4a pattern) {
+ this.patterns.add(pattern);
+ }
+
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ final StringBuilder p = new StringBuilder();
+ p.append(this.pdfID() + EOL);
+ p.append("<<" + EOL);
+ if (! this.fonts.isEmpty()) {
+ /* construct PDF dictionary of font object references */
+ p.append("/Font" + EOL);
+ p.append("<<" + EOL);
+ for (int i = 0; i < this.fonts.size(); i++) {
+ final PdfFont4a pdfFont = this.fonts.get(i);
+ p.append("/" + pdfFont.getName() + " " + pdfFont.pdfReference(doc)
+ + EOL);
+ }
+ p.append(">>" + EOL);
+ }
+
+ PdfShading currentShading = null;
+ if (!this.shadings.isEmpty()) {
+ p.append("/Shading <<" + EOL);
+ for (int currentShadingNumber = 0;
+ currentShadingNumber < this.shadings.size();
+ currentShadingNumber++) {
+ currentShading = this.shadings.get(currentShadingNumber);
+ p.append("/" + currentShading.getName() + " "
+ + currentShading.pdfReference(doc) + EOL);
+ }
+ p.append(">>" + EOL);
+ }
+ // "free" the memory. Sorta.
+ currentShading = null;
+
+ PdfPattern4a currentPattern = null;
+ if (!this.patterns.isEmpty()) {
+ p.append("/Pattern <<" + EOL);
+ for (int currentPatternNumber = 0;
+ currentPatternNumber < this.patterns.size();
+ currentPatternNumber++) {
+ currentPattern = this.patterns.get(currentPatternNumber);
+ p.append("/" + currentPattern.getName() + " "
+ + currentPattern.pdfReference(doc) + EOL);
+ }
+ p.append(">>" + EOL);
+ }
+ // "free" the memory. Sorta.
+ currentPattern = null;
+
+ p.append("/ProcSet [ /PDF /ImageC /Text ]" + EOL);
+
+ if (! this.xObjects.isEmpty()) {
+ p.append("/XObject" + EOL);
+ p.append("<<" + EOL);
+ for (int i = 0; i < this.xObjects.size(); i++) {
+ final PdfXobject4a xObject = this.xObjects.get(i);
+ p.append("/" + xObject.getXobjectName() + " "
+ + xObject.pdfReference(doc) + EOL);
+ }
+ p.append(">>" + EOL);
+ }
+ p.append(">>" + EOL);
+ p.append("endobj" + EOL);
+
+ return new ByteArray(p);
+ }
+
+}
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/package-info.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/package-info.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/package-info.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2022 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$
+ */
+
+/**
+ * The content streams and resources of a PDF document.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.7."
+ */
+package org.foray.pdf.content;
Property changes on: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/content/package-info.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java (from rev 12503, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfAnnotList.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfAnnotList.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.document;
+
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.interact.annotation.PdfAnnotation;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A collection of {@link PdfAnnotation} objects that are associated with a {@link PdfPage4a}.
+ */
+public class PdfAnnotList extends PdfObject {
+
+ /** Collection of PdfAnnotation objects. */
+ private List<PdfAnnotation> annotations
+ = new ArrayList<PdfAnnotation>();
+
+ /**
+ * Add a PdfAnnotation to the collection.
+ * @param annotation The {@link PdfAnnotation} to add.
+ */
+ public void addAnnotation(final PdfAnnotation annotation) {
+ if (annotation == null) {
+ return;
+ }
+ this.annotations.add(annotation);
+ }
+
+ /**
+ * For each item in annotationList, add the item to this.
+ * @param listToAdd The PdfAnnotList whose contents are to be added
+ * to this.
+ */
+ public void addAnnotationList(final PdfAnnotList listToAdd) {
+ if (listToAdd == null) {
+ return;
+ }
+ for (int i = 0; i < listToAdd.annotations.size(); i++) {
+ final PdfAnnotation annotationToAdd = listToAdd.annotations.get(i);
+ this.addAnnotation(annotationToAdd);
+ }
+ }
+
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ final StringBuilder p = new StringBuilder();
+ p.append(this.pdfID() + EOL);
+ p.append("[" + EOL);
+ for (int i = 0; i < this.annotations.size(); i++) {
+ final PdfAnnotation child = this.annotations.get(i);
+ p.append(child.pdfReference(doc) + EOL);
+ }
+ p.append("] endobj" + EOL);
+ return new ByteArray(p);
+ }
+
+ /*
+ * example
+ * 20 0 obj
+ * [
+ * 19 0 R
+ * ]
+ * endobj
+ */
+}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-29 21:21:04 UTC (rev 12503)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -39,18 +39,18 @@
import org.foray.common.ColorUtil;
import org.foray.common.sequence.ByteArrayBuilder;
import org.foray.pdf.PdfConstants;
+import org.foray.pdf.PdfObjectReference;
+import org.foray.pdf.content.PdfResources;
+import org.foray.pdf.encrypt.PdfEncryption4a;
+import org.foray.pdf.function.PdfFunction;
+import org.foray.pdf.graphics.PdfColor4a;
import org.foray.pdf.graphics.PdfPattern4a;
import org.foray.pdf.graphics.PdfShading;
import org.foray.pdf.graphics.PdfXobject4a;
import org.foray.pdf.interact.PdfOutlineParent4a;
import org.foray.pdf.interact.PdfPageLabel;
-import org.foray.pdf.object.PdfBorderStyle;
-import org.foray.pdf.object.PdfColor4a;
-import org.foray.pdf.object.PdfDocumentInfo4a;
-import org.foray.pdf.object.PdfEncryption4a;
-import org.foray.pdf.object.PdfFunction;
-import org.foray.pdf.object.PdfObjectReference;
-import org.foray.pdf.object.PdfResources;
+import org.foray.pdf.interact.annotation.PdfBorderStyle;
+import org.foray.pdf.interchange.PdfDocumentInfo4a;
import org.foray.pdf.serial.PdfCrossRefEntry;
import org.foray.pdf.serial.PdfCrossRefInfo;
import org.foray.pdf.serial.PdfHeader;
@@ -569,7 +569,7 @@
@Override
public PdfEncryption4a createPdfEncryption() {
if (this.encryption == null) {
- this.encryption = new org.foray.pdf.object.PdfEncryption4a(this);
+ this.encryption = new org.foray.pdf.encrypt.PdfEncryption4a(this);
}
return this.encryption;
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java 2022-01-29 21:21:04 UTC (rev 12503)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -29,6 +29,10 @@
package org.foray.pdf.document;
import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.content.PdfContentStream4a;
+import org.foray.pdf.content.PdfResources;
+import org.foray.pdf.encrypt.PdfEncryption4a;
+import org.foray.pdf.filespec.PdfFileSpec;
import org.foray.pdf.graphics.PdfShading;
import org.foray.pdf.interact.PdfDestinationExplicit4a;
import org.foray.pdf.interact.PdfDestinationNamed4a;
@@ -36,11 +40,6 @@
import org.foray.pdf.interact.action.PdfGoToRemote;
import org.foray.pdf.interact.action.PdfUri;
import org.foray.pdf.interact.annotation.PdfLink;
-import org.foray.pdf.object.PdfAnnotList;
-import org.foray.pdf.object.PdfContentStream4a;
-import org.foray.pdf.object.PdfEncryption4a;
-import org.foray.pdf.object.PdfFileSpec;
-import org.foray.pdf.object.PdfResources;
import org.foray.pdf.structure.PdfNameTree;
import org.foray.pdf.type.PdfObject;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-29 21:21:04 UTC (rev 12503)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -31,11 +31,11 @@
import org.foray.common.primitive.StringUtils;
import org.foray.common.sequence.ByteArray;
import org.foray.pdf.PdfConstants;
+import org.foray.pdf.filespec.PdfEmbeddedFileStream;
import org.foray.pdf.interact.PdfDestinationNamed4a;
import org.foray.pdf.interact.PdfNamedDestinationsTree4a;
import org.foray.pdf.interact.PdfOutline4a;
import org.foray.pdf.interact.PdfPageLabel;
-import org.foray.pdf.object.PdfEmbeddedFileStream;
import org.foray.pdf.structure.PdfNameTree;
import org.foray.pdf.structure.PdfNumberTree;
import org.foray.pdf.type.PdfDictionary;
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java (from rev 12503, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfEncryption4a.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/PdfEncryption4a.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,430 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.encrypt;
+
+import org.foray.common.WellKnownConstants;
+import org.foray.common.primitive.StringUtils;
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.PdfObjectReference;
+import org.foray.pdf.document.PdfDocument4a;
+import org.foray.pdf.type.PdfDictionary;
+
+import org.axsl.pdf.PdfException;
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.security.InvalidKeyException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.List;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * class representing a /Filter /Standard object.
+ *
+ */
+public class PdfEncryption4a extends PdfDictionary implements org.axsl.pdf.PdfEncryption {
+
+ /**
+ * Private inner class for the encryption filter.
+ */
+ public class EncryptionFilter extends FilterOutputStream {
+ /* TODO: We almost certainly need to override some more methods in FilterOutputStream to get this to work. */
+
+ /** The encryption object computing the filtering. */
+ private PdfEncryption4a encryption;
+
+ /**
+ * The constructor for the internal PdfEncryption4a filter.
+ * @param outputStream The stream to which the encrypted data should be
+ * written.
+ * @param encryption The encryption object to use.
+ */
+ public EncryptionFilter(final OutputStream outputStream, final PdfEncryption4a encryption) {
+ super(outputStream);
+ this.encryption = encryption;
+ }
+
+ /**
+ * Encode the given data with the filter.
+ * @param data The data to be encrypted.
+ * @throws IOException For errors writing to the stream.
+ */
+ @Override
+ public void write(final byte[] data) throws IOException {
+ final PdfObjectReference reference = this.encryption.getIndirectReference();
+ this.out.write(this.encryption.encryptData(data, reference.getNumber(), reference.getGeneration()));
+ }
+
+ }
+
+ /** Constant for printing permission. */
+ public static final int PERMISSION_PRINT = 4;
+
+ /** Constant for content editing permission. */
+ public static final int PERMISSION_EDIT_CONTENT = 8;
+
+ /** Constant for content extraction permission. */
+ public static final int PERMISSION_COPY_CONTENT = 16;
+
+ /** Constant for annotation editing permission. */
+ public static final int PERMISSION_EDIT_ANNOTATIONS = 32;
+
+ /** The padding that is added to the password if it is less than 32 bytes
+ * long. These values are specified in PDF Reference, 3rd Edition,
+ * Section 3.5.2. */
+ static final char[] PAD = {
+ 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
+ 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
+ 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
+ 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A };
+
+ /** The maximum size, in bytes, of the password field. */
+ private static final int PASSWORD_SIZE = 32;
+
+ /** The default size, in bytes, of the encryption key. */
+ private static final int DEFAULT_KEY_SIZE = 5;
+
+ /** The default permissions. */
+ private static final int DEFAULT_PERMISSIONS = -4;
+
+ // Encryption tools
+
+ /** The message digest. */
+ private MessageDigest digest = null;
+
+ /** The cipher. */
+ private Cipher cipher = null;
+
+ // Control attributes
+
+ /** The user password. */
+ private String userPassword = "";
+
+ /** The owner password. */
+ private String ownerPassword = "";
+
+ /** Indicates whether printing is allowed. */
+ private boolean allowPrint = true;
+
+ /** Indicates whether content can be copied. */
+ private boolean allowCopyContent = true;
+
+ /** Indicates whether content can be edited. */
+ private boolean allowEditContent = true;
+
+ /** Indicates whether annotations can be edited. */
+ private boolean allowEditAnnotations = true;
+
+ // Output attributes
+
+ /** The encryption key. */
+ private byte[] encryptionKey = null;
+
+ /** The dictionary entry to be written into the PDF file describing the
+ * encryption. */
+ private String dictionary = null;
+
+ /** The PDF document. */
+ private PdfDocument4a doc;
+
+ /**
+ * Create a /Filter /Standard object.
+ * @param doc The parent PDF document.
+ */
+ public PdfEncryption4a(final PdfDocument4a doc) {
+ this.doc = doc;
+ try {
+ this.digest = MessageDigest.getInstance("MD5");
+ this.cipher = Cipher.getInstance("RC4");
+ } catch (final NoSuchAlgorithmException e) {
+ throw new IllegalStateException(e.getMessage());
+ } catch (final NoSuchPaddingException e) {
+ throw new IllegalStateException(e.getMessage());
+ }
+ doc.registerIndirectObjectLast(this);
+ }
+
+ @Override
+ public void setUserPassword(final String value) {
+ this.userPassword = value;
+ }
+
+ /**
+ * Returns the current user password.
+ * @return The user password.
+ */
+ public String getUserPassword() {
+ return this.userPassword;
+ }
+
+ @Override
+ public void setOwnerPassword(final String value) {
+ this.ownerPassword = value;
+ }
+
+ /**
+ * Returns the owner password for the PDF.
+ * @return The owner password.
+ */
+ public String getOwnerPassword() {
+ return this.ownerPassword;
+ }
+
+ @Override
+ public void setAllowPrint(final boolean value) {
+ this.allowPrint = value;
+ }
+
+ @Override
+ public void setAllowCopyContent(final boolean value) {
+ this.allowCopyContent = value;
+ }
+
+ @Override
+ public void setAllowEditContent(final boolean value) {
+ this.allowEditContent = value;
+ }
+
+ /**
+ * Set whether the document will allow annotation modifications.
+ * @param value The new permission value.
+ */
+ public void setAllowEditAnnotation(final boolean value) {
+ this.allowEditAnnotations = value;
+ }
+
+ /**
+ * Convert the String password to an array of bytes, truncating or padding
+ * as needed.
+ * @param password The String password.
+ * @return The padded or truncated password.
+ */
+ private byte[] prepPassword(final String password) {
+ final byte[] obuffer = new byte[PdfEncryption4a.PASSWORD_SIZE];
+ final byte[] pbuffer = password.getBytes();
+
+ int i = 0;
+ int j = 0;
+
+ while (i < obuffer.length && i < pbuffer.length) {
+ obuffer[i] = pbuffer[i];
+ i++;
+ }
+
+ /* Add padding if necessary. */
+ while (i < obuffer.length) {
+ obuffer[i++] = (byte) PdfEncryption4a.PAD[j++];
+ }
+ return obuffer;
+ }
+
+ /**
+ * Encrypts a chunk of data with a key.
+ * @param data The data to be encrypted.
+ * @param key The key to use during encryption.
+ * @return The encrypted data.
+ */
+ private byte[] encryptWithKey(final byte[] data, final byte[] key) {
+ try {
+ final SecretKeySpec keyspec = new SecretKeySpec(key, "RC4");
+ this.cipher.init(Cipher.ENCRYPT_MODE, keyspec);
+ return this.cipher.doFinal(data);
+ } catch (final IllegalBlockSizeException e) {
+ throw new IllegalStateException(e.getMessage());
+ } catch (final BadPaddingException e) {
+ throw new IllegalStateException(e.getMessage());
+ } catch (final InvalidKeyException e) {
+ throw new IllegalStateException(e.getMessage());
+ }
+ }
+
+ /**
+ * Encrypts a chunk of data with a hash.
+ * @param data The data to be encrypted.
+ * @param hash The hash to use during encryption.
+ * @param keySize The size of the key.
+ * @return The encrypted data.
+ */
+ private byte[] encryptWithHash(final byte[] data, final byte[] hash,
+ final int keySize) {
+ final byte[] hashToUse = this.digest.digest(hash);
+
+ final byte[] key = new byte[keySize];
+
+ for (int i = 0; i < keySize; i++) {
+ key[i] = hashToUse[i];
+ }
+
+ return encryptWithKey(data, key);
+ }
+
+ public void init() throws PdfException {
+ // Generate the owner value
+ final byte[] oValue;
+ final String encryptionPassword;
+ if (this.ownerPassword.length() > 0) {
+ oValue = encryptWithHash(prepPassword(this.ownerPassword),
+ prepPassword(this.ownerPassword),
+ PdfEncryption4a.DEFAULT_KEY_SIZE);
+ encryptionPassword = this.ownerPassword;
+ } else {
+ oValue = encryptWithHash(prepPassword(this.userPassword),
+ prepPassword(this.userPassword),
+ PdfEncryption4a.DEFAULT_KEY_SIZE);
+ encryptionPassword = this.userPassword;
+ }
+
+ // Generate permissions value
+ int permissions = PdfEncryption4a.DEFAULT_PERMISSIONS;
+
+ if (! this.allowPrint) {
+ permissions -= PdfEncryption4a.PERMISSION_PRINT;
+ }
+ if (! this.allowCopyContent) {
+ permissions -= PdfEncryption4a.PERMISSION_COPY_CONTENT;
+ }
+ if (! this.allowEditContent) {
+ permissions -= PdfEncryption4a.PERMISSION_EDIT_CONTENT;
+ }
+ if (! this.allowEditAnnotations) {
+ permissions -= PdfEncryption4a.PERMISSION_EDIT_ANNOTATIONS;
+ }
+
+ /* Create the encryption key */
+ this.digest.update(prepPassword(encryptionPassword));
+ this.digest.update(oValue);
+ this.digest.update((byte) (permissions >>> 0));
+ this.digest.update((byte) (permissions >>> WellKnownConstants.SHIFT_1_BYTE));
+ this.digest.update((byte) (permissions >>> WellKnownConstants.SHIFT_2_BYTES));
+ this.digest.update((byte) (permissions >>> WellKnownConstants.SHIFT_3_BYTES));
+ this.digest.update(this.doc.getTrailer().getPermanentFileID().toArray());
+
+ final byte[] hash = this.digest.digest();
+ this.encryptionKey = new byte[PdfEncryption4a.DEFAULT_KEY_SIZE];
+
+ for (int i = 0; i < this.encryptionKey.length; i++) {
+ this.encryptionKey[i] = hash[i];
+ }
+
+ // Create the user value
+ final byte[] uValue = encryptWithKey(
+ prepPassword(""), this.encryptionKey);
+
+ // Create the dictionary
+ this.dictionary = this.pdfID() + EOL
+ + "<<" + EOL
+ + "/Filter" + EOL
+ + "/Standard" + EOL
+ + "/V 1" + EOL
+ + "/R 2" + EOL
+ + "/Length 40" + EOL
+ + "/P " + permissions + EOL
+ + "/O <" + StringUtils.toHex(oValue) + ">" + EOL
+ + "/U <" + StringUtils.toHex(uValue) + ">" + EOL
+ + ">>" + EOL
+ + "endobj" + EOL;
+ }
+
+ /** This method encrypts the passed data using the generated keys.
+ * @param data The data to be encrypted
+ * @param number The block number
+ * @param generation The block generation
+ * @return The encrypted data
+ */
+ public byte[] encryptData(final byte [] data, final int number,
+ final int generation) {
+ if (this.encryptionKey == null) {
+ throw new IllegalStateException("PDF Encryption has not been "
+ + "initialized");
+ }
+
+ final byte[] hash = new byte[this.encryptionKey.length
+ + PdfEncryption4a.DEFAULT_KEY_SIZE];
+
+ int i = 0;
+
+ while (i < this.encryptionKey.length) {
+ hash[i] = this.encryptionKey[i]; i++;
+ }
+
+ hash[i++] = (byte) (number >>> 0);
+ hash[i++] = (byte) (number >>> WellKnownConstants.SHIFT_1_BYTE);
+ hash[i++] = (byte) (number >>> WellKnownConstants.SHIFT_2_BYTES);
+ hash[i++] = (byte) (generation >>> 0);
+ hash[i++] = (byte) (generation >>> WellKnownConstants.SHIFT_1_BYTE);
+
+ return encryptWithHash(data, hash, hash.length);
+ }
+
+ /**
+ * Creates PSEncodeFilter for the encryption object.
+ * @param outputStream The output stream to which the encrypted data should
+ * be written.
+ * @return The resulting filter.
+ */
+ public OutputStream makeFilter(final OutputStream outputStream) {
+ return new EncryptionFilter(outputStream, this);
+ }
+
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ if (this.dictionary == null) {
+ throw new IllegalStateException("PDF Encryption has not been "
+ + "initialized");
+ }
+ return new ByteArray(this.dictionary);
+ }
+
+ /**
+ * Indicates whether encryption is available in the current environment.
+ * @return True if and only if encryption is available in the current environment.
+ */
+ public static boolean encryptionAvailable() {
+ return true;
+ }
+
+ @Override
+ public List<String> getOutputOrder() {
+ return null;
+ }
+
+ @Override
+ public String getDictionaryType() {
+ return null;
+ }
+
+}
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/package-info.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/package-info.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/package-info.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2022 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$
+ */
+
+/**
+ * Classes for PDF encryption.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.5."
+ */
+package org.foray.pdf.encrypt;
Property changes on: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/encrypt/package-info.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java (from rev 12503, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfEmbeddedFileStream.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfEmbeddedFileStream.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.filespec;
+
+import org.foray.pdf.document.PdfDocument4a;
+import org.foray.pdf.type.PdfStream;
+
+/**
+ * Container for a PDF Embedded File Stream. See PDF Reference, 3rd Edition,
+ * Section 3.10.3.
+ */
+public class PdfEmbeddedFileStream extends PdfStream {
+
+ /** The name by which this embedded file stream is accessed from the map
+ * of embedded files. */
+ private String name;
+
+ /**
+ * Create a PdfEmbeddedFileStream instance.
+ * @param doc The parent PDF document.
+ * @param name The name by which this embedded file stream is accessed from
+ * the map of embedded files.
+ */
+ public PdfEmbeddedFileStream(final PdfDocument4a doc, final String name) {
+ this.name = name;
+ doc.getRoot().getEmbeddedFiles().put(name, this);
+ }
+
+ /**
+ * Return the name by which this embedded file stream is accessed from the
+ * map of embedded files.
+ * @return The name of this embedded file stream.
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ protected void finalizeStreamContent(final PdfDocument4a doc) {
+ /* Nothing needs to be done here. */
+ }
+
+ @Override
+ protected String specialStreamDictEntries(final PdfDocument4a doc) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("/Type /EmbeddedFile" + EOL);
+ return builder.toString();
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java (from rev 12503, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFileSpec.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/filespec/PdfFileSpec.java 2022-01-29 22:16:36 UTC (rev 12504)
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.filespec;
+
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.document.PdfDocument4a;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+/**
+ * A File Specification Dictionary.
+ * @see "PDF Reference, 3rd Edition, Section 3.10.2"
+ */
+public class PdfFileSpec extends PdfObject {
+
+ /** The filename being referenced by the file specification.
+ * This will be null unless this instance references an external file. */
+ private String filename;
+
+ /** The embedded file stream being referenced by the file specification.
+ * This will be null unless this instance references an embedded file. */
+ private PdfEmbeddedFileStream efs;
+
+ /**
+ * Constructor for the case of specifying an external file.
+ * @param filename the filename represented by this object
+ */
+ public PdfFileSpec(final String filename) {
+ this.filename = filename;
+ }
+
+ /**
+ * Constructor for the case of specifying an embedded file.
+ * @param efs The embedded file stream that is being referenced.
+ */
+ public PdfFileSpec(final PdfEmbeddedFileStream efs) {
+ this.efs = efs;
+ }
+
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(pdfID() + EOL
+ + "<<" + EOL
+ + "/Type /FileSpec" + EOL);
+ if (this.filename != null) {
+ builder.append("/F (" + this.filename + ")" + EOL);
+ }
+ if (this.efs != null) {
+ builder.append("/F (" + this.efs.getName() + ")" + EOL);
+ builder.append("/EF" + EOL);
+ builder.append("<<" + EOL);
+ builder.append(" /F /" + this.efs.getName() + EOL);
+ buil...
[truncated message content] |
|
From: <vic...@us...> - 2022-01-29 21:21:09
|
Revision: 12503
http://sourceforge.net/p/foray/code/12503
Author: victormote
Date: 2022-01-29 21:21:04 +0000 (Sat, 29 Jan 2022)
Log Message:
-----------
Move more PDF classes to specific packages.
Modified Paths:
--------------
trunk/foray/foray-app/src/main/java/org/foray/app/OutputTargetFactory.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfItem.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfFormXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfImageXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformEps.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformSvg.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXobject4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXreference.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationExplicit4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfDestinationNamed4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfNamedDestinationsTree4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutline4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfOutlineItem4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/PdfPageLabel.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfAction.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoTo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfGoToRemote.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/action/PdfUri.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/interact/annotation/PdfLink.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfAnnotList.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfBorderStyle.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfCharProcs.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfColor4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfEmbeddedFileStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfEncryption4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFileSpec.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFunction.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfGenericStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfIccStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfObjectReference.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/serial/PdfParser.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfRectangle.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfEncoding4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFont4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontType0.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfToUnicodeCmap.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfBoolean.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfHexString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfInteger.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfLiteralString.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfName.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfObject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfReal.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/util/PdfReport.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfDocumentTests.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfShading.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCidFont.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCidFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCidSystemInfo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfCmap.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontFileStream.java
Removed Paths:
-------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfCidFont.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfCidFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfCidSystemInfo.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfCmap.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/PdfFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFontFileStream.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPages.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfShading.java
Modified: trunk/foray/foray-app/src/main/java/org/foray/app/OutputTargetFactory.java
===================================================================
--- trunk/foray/foray-app/src/main/java/org/foray/app/OutputTargetFactory.java 2022-01-29 21:03:44 UTC (rev 12502)
+++ trunk/foray/foray-app/src/main/java/org/foray/app/OutputTargetFactory.java 2022-01-29 21:21:04 UTC (rev 12503)
@@ -31,7 +31,7 @@
import org.foray.core.ForayException;
import org.foray.core.OutputConfig;
import org.foray.output.MifConverter;
-import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.document.PdfDocument4a;
import org.foray.ps.PsServer4a;
import org.foray.render.awt.AwtRenderer;
import org.foray.render.pcl.PclRenderer;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfItem.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfItem.java 2022-01-29 21:03:44 UTC (rev 12502)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfItem.java 2022-01-29 21:21:04 UTC (rev 12503)
@@ -29,7 +29,7 @@
package org.foray.pdf;
import org.foray.common.primitive.StringUtils;
-import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.document.PdfDocument4a;
import org.axsl.pdf.PdfException;
import org.axsl.unicode.block.Basic_Latin_Block;
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java (from rev 12502, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfDocument4a.java 2022-01-29 21:21:04 UTC (rev 12503)
@@ -0,0 +1,847 @@
+/*
+ * 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:
+ * Mark Lillywhite, mar...@in...
+ * lmc...@ca...
+ * Image support modified from work of BoBoGi
+ * Font support based on work by Takayuki Takeuchi
+ */
+
+package org.foray.pdf.document;
+
+import org.foray.common.ColorUtil;
+import org.foray.common.sequence.ByteArrayBuilder;
+import org.foray.pdf.PdfConstants;
+import org.foray.pdf.graphics.PdfPattern4a;
+import org.foray.pdf.graphics.PdfShading;
+import org.foray.pdf.graphics.PdfXobject4a;
+import org.foray.pdf.interact.PdfOutlineParent4a;
+import org.foray.pdf.interact.PdfPageLabel;
+import org.foray.pdf.object.PdfBorderStyle;
+import org.foray.pdf.object.PdfColor4a;
+import org.foray.pdf.object.PdfDocumentInfo4a;
+import org.foray.pdf.object.PdfEncryption4a;
+import org.foray.pdf.object.PdfFunction;
+import org.foray.pdf.object.PdfObjectReference;
+import org.foray.pdf.object.PdfResources;
+import org.foray.pdf.serial.PdfCrossRefEntry;
+import org.foray.pdf.serial.PdfCrossRefInfo;
+import org.foray.pdf.serial.PdfHeader;
+import org.foray.pdf.serial.PdfParser;
+import org.foray.pdf.serial.PdfTrailer;
+import org.foray.pdf.text.PdfEncoding4a;
+import org.foray.pdf.text.PdfFont4a;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.font.Font;
+import org.axsl.font.FontConsumer;
+import org.axsl.font.FontUse;
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.graphic.output.GraphicOutputContext;
+import org.axsl.orthography.Orthography;
+import org.axsl.pdf.PdfDestinationNamed;
+import org.axsl.pdf.PdfDocument;
+import org.axsl.pdf.PdfException;
+import org.axsl.pdf.PdfPage;
+import org.axsl.pdf.PdfPageLabelStyle;
+import org.axsl.pdf.PdfPageProvider;
+import org.axsl.pdf.PdfSerializationConfig;
+import org.axsl.pdf.PdfVersion;
+import org.axsl.pdf.PdfXobject;
+import org.axsl.ps.Encoding;
+import org.axsl.ps.PsServer;
+import org.axsl.utility.sequence.IntPrimitiveIterator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.awt.Color;
+import java.awt.LinearGradientPaint;
+import java.awt.MultipleGradientPaint;
+import java.awt.RadialGradientPaint;
+import java.awt.color.ColorSpace;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents a PDF document.
+ *
+ * The document is built up by calling various methods and then finally
+ * output to given filehandle using output method.
+ *
+ * A PDF document consists of a series of numbered objects preceded by a
+ * header and followed by an xref table and trailer. The xref table
+ * allows for quick access to objects by listing their character
+ * positions within the document. For this reason the PDF document must
+ * keep track of the character position of each object. The document
+ * also keeps direct track of the /Root, /Info and /Resources objects.
+ */
+public class PdfDocument4a implements PdfDocument<PdfPage4a>, GraphicOutputContext {
+
+ /** Name of the CharSet that should be used when converting Strings to
+ * bytes. */
+ public static final String ENCODING = "ISO-8859-1";
+
+ /** The current character position. */
+ private long position = 0;
+
+ /** The header portion of this document. */
+ private PdfHeader header = new PdfHeader();
+
+ /** The cross-reference information (tables and/or streams) for this document. */
+ private PdfCrossRefInfo xrefInfo = new PdfCrossRefInfo();
+
+ /** The /Root object. */
+ private PdfRoot root;
+
+ /** The /Info object. */
+ private PdfDocumentInfo4a info;
+
+ /** The /Resources object. */
+ private PdfResources resources;
+
+ /** The documents encryption, if any. */
+ private PdfEncryption4a encryption;
+
+ /** The colorspace for this document. */
+ private ColorSpace colorspace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+
+ /** The counter for Pattern name numbering. */
+ private int lastPatternAssigned = 0;
+
+ /** The counter for Shading name numbering. */
+ private int lastShadingAssigned = 0;
+
+ /** The counter for XObject numbering. */
+ private int lastXObjectAssigned = 0;
+
+ /** The counter for Font numbering. */
+ private int lastFontAssigned = 0;
+
+ /**
+ * A global map of all XObjects used in the document, whose purpose is to
+ * create the possibility of reusing XObjects.
+ * The key is the Graphic instance and the value is a PdfXobject instance.
+ */
+ private Map<Graphic, PdfXobject4a> xObjectsMap =
+ new HashMap<Graphic, PdfXobject4a>();
+
+ /**
+ * Default list of filters that should be applied to each stream in this
+ * document, listed in encoding order.
+ */
+ private List<String> filters = new ArrayList<String>();
+
+ /**
+ * Stores the next available tag to be used in a subset font's BaseFont or
+ * FontName entry.
+ * @see #getNextFontSubsetTag
+ */
+ private char[] nextFontSubsetTag = new char[]
+ {'A', 'A', 'A', 'A', 'A', 'A'};
+
+ /** The logger. */
+ private Logger logger = LoggerFactory.getLogger(PdfDocument4a.class);
+
+ /** The default border style. */
+ private PdfBorderStyle defaultBorderStyle;
+
+ /**
+ * Map whose key is an Encoding and whose value is the PdfEncoding
+ * that wraps it.
+ * This is used to ensure that only one PdfEncoding is created per Encoding
+ * that is actually used.*/
+ private Map<Encoding, PdfEncoding4a> encodingsUsed
+ = new HashMap<Encoding, PdfEncoding4a>();
+
+ /** List of PdfFont4a instances that have been used by this document. */
+ private List<PdfFont4a> usedFonts = new ArrayList<PdfFont4a>();
+
+ /** List of PdfColor4a instances that have been used by this document. */
+ private List<PdfColor4a> usedColors = new ArrayList<PdfColor4a>();
+
+ /** The PostScript server. */
+ private PsServer psServer;
+
+ /** Indicates whether this document has already been serialized. After serialization, an exception is thrown if
+ * serialization is attempted again. */
+ private boolean serialized = false;
+
+ /** The trailer dictionary. Always use {@link #getTrailer()} to obtain the instance, because it is lazily
+ * created. */
+ private PdfTrailer lazyTrailer;
+
+ /**
+ * Constructor which creates an empty PDF document.
+ * The constructor creates a /Root and /Pages object to track the document
+ * but does not write these objects until the trailer is written.
+ * Note that the object ID of the pages object is determined now, and the
+ * xref table is updated later.
+ * This allows Pages to refer to their Parent before we write it out.
+ * @param psServer The PostScript server.
+ */
+ public PdfDocument4a(final PsServer psServer) {
+ this.psServer = psServer;
+
+ // Create the Root object
+ this.root = new PdfRoot(this);
+ registerIndirectObjectLast(this.root);
+ registerIndirectObjectLast(this.root.getPages());
+
+ // Create the Resources object
+ this.resources = new PdfResources();
+ registerIndirectObjectLast(this.resources);
+ }
+
+ /**
+ * Creates a PDF document from a parser.
+ * @param parser The parser to be used to create this document.
+ * @throws PdfException For errors parsing the document.
+ */
+ public PdfDocument4a(final PdfParser parser) throws PdfException {
+ final PdfVersion pdfVersion = parser.parseHeader();
+ this.lazyTrailer = parser.parseTrailer();
+ parser.parseIndirectObjects();
+ setVersion(pdfVersion);
+ }
+
+ @Override
+ public PdfVersion getVersion() {
+ return this.header.getPdfVersion();
+ }
+
+ @Override
+ public void setVersion(final PdfVersion newVersion) {
+ if (newVersion == null) {
+ throw new IllegalArgumentException("Cannot set a null PDF Version");
+ }
+ this.header.setPdfVersion(newVersion);
+ }
+
+ /**
+ * Returns the encryption for this document, if any.
+ * @return The encryption for this document, or null if there is none.
+ */
+ public PdfEncryption4a getEncryption() {
+ return this.encryption;
+ }
+
+ /**
+ * Returns the color space for this document.
+ * @return The color space for this document.
+ */
+ public ColorSpace getColorSpace() {
+ return this.colorspace;
+ }
+
+ /**
+ * Sets the color space for this document.
+ * @param theColorspace The new color space.
+ */
+ public void setColorSpace(final ColorSpace theColorspace) {
+ this.colorspace = theColorspace;
+ }
+
+ @Override
+ public PdfOutlineParent4a getOutlineRoot() {
+ return this.root.getOutlineRoot();
+ }
+
+ /** Returns the /Resources object for the document.
+ * @return The /Resources object.
+ */
+ public PdfResources getResources() {
+ return this.resources;
+ }
+
+ private void writeIndirectObjects(final OutputStream output) throws PdfException {
+ /*
+ * Use a "while" loop here, because as each object is written, it has
+ * potential to reference another object indirectly, which will add an
+ * item to indirectObjects.
+ */
+ int objectId = 1;
+ while (objectId < this.xrefInfo.getTableSize()) {
+ final PdfCrossRefEntry xref = this.xrefInfo.getTableEntry(objectId);
+ if (xref.getOffset() > -1) {
+ /* This object has already been written. */
+ } else {
+ final PdfObject object = xref.getObject();
+ if (this.xrefInfo.isDeferred(objectId)) {
+ /* We are not serializing this object yet. Set the offset accordingly. */
+ xref.setOffset(-1);
+ } else {
+ /* Output the object and increment the character position by the object's length. */
+ xref.setOffset(this.position);
+ this.position += object.output(output, this);
+ }
+ }
+ objectId ++;
+ }
+ }
+
+ private void writeDeferredIndirectObjects(final OutputStream output) throws PdfException {
+ final IntPrimitiveIterator deferredObjectIterator = this.xrefInfo.iteratorForDeferred();
+ while (deferredObjectIterator.hasNext()) {
+ final int objectId = deferredObjectIterator.nextInt();
+ final PdfCrossRefEntry xref = this.xrefInfo.getTableEntry(objectId);
+ final PdfObject o = xref.getObject();
+ xref.setOffset(this.position);
+ this.position += o.output(output, this);
+ }
+ }
+
+ /**
+ * Write the document trailer.
+ * @param output The output stream.
+ * @param xrefPosition The offset to the cross-reference table.
+ * @throws PdfException For errors while writing to the output stream.
+ */
+ private void writeTrailer(final OutputStream output, final long xrefPosition) throws PdfException, IOException {
+ /* Construct the trailer. */
+ final PdfTrailer trailer = getTrailer();
+ trailer.put("Size", this.xrefInfo.getTableSize());
+ trailer.put("Root", this.root);
+ final PdfDocumentInfo4a documentInfo = getDocumentInfo(false);
+ if (documentInfo != null
+ && ! documentInfo.isEmpty()) {
+ trailer.put("Info", this.info);
+ }
+ if (this.encryption != null) {
+ trailer.put("Encrypt", this.encryption);
+ }
+
+ /* Write the trailer. */
+ final ByteArrayBuilder builder = new ByteArrayBuilder();
+ builder.append("trailer" + PdfObject.EOL);
+ builder.append(getTrailer().serialize(this));
+ builder.append("startxref");
+ builder.append(PdfObject.EOL);
+ builder.append(Long.toString(xrefPosition));
+ builder.append(PdfObject.EOL);
+ builder.append(PdfConstants.DOCUMENT_END_MARKER.toString() + PdfObject.EOL);
+
+ builder.writeTo(output);
+ }
+
+ /**
+ * Marks a given object with its reference information.
+ * @param object The object to be registered.
+ * @return True if and only if the object has not already been registered.
+ */
+ private boolean registerIndirectObjectShared(final PdfObject object) {
+ if (object.getIndirectReference() != null) {
+ return false;
+ }
+ if (this.xrefInfo.getTableSize() < 1) {
+ this.xrefInfo.addTableEntry(PdfCrossRefEntry.createInitialEntry());
+ }
+
+ final PdfObjectReference reference = new PdfObjectReference(this.xrefInfo.getTableSize(), 0);
+ object.registerIndirectReference(reference);
+ return true;
+ }
+
+ /**
+ * Register an object as an indirect object.
+ * @param object The object to be registered as an indirect object.
+ */
+ public void registerIndirectObject(final PdfObject object) {
+ if (registerIndirectObjectShared(object)) {
+ this.xrefInfo.addTableEntry(new PdfCrossRefEntry(object));
+ }
+ }
+
+ /**
+ * Register an object as an indirect object that should be written at the end of the PDF output.
+ * @param object The object to be registered.
+ */
+ public void registerIndirectObjectLast(final PdfObject object) {
+ if (registerIndirectObjectShared(object)) {
+ this.xrefInfo.addDeferredTableEntry(new PdfCrossRefEntry(object));
+ }
+ }
+
+ /**
+ * Register a shading resource for use in this document.
+ * @param shading The shading resource to register.
+ * @return The incremented shading count.
+ */
+ public int registerShadingResource(final PdfShading shading) {
+ registerIndirectObject(shading);
+ getResources().addShading(shading);
+ return ++this.lastShadingAssigned;
+ }
+
+ /**
+ * Register a pattern resource for use in this document.
+ * @param pattern The pattern resource to register.
+ * @return The incremented pattern count.
+ */
+ public int registerPatternResource(final PdfPattern4a pattern) {
+ registerIndirectObject(pattern);
+ getResources().addPattern(pattern);
+ return ++this.lastPatternAssigned;
+ }
+
+ /**
+ * Register a font resource for use in this document.
+ * @param font The font resource to register.
+ * @return The incremented font count.
+ */
+ public int registerFontResource(final PdfFont4a font) {
+ registerIndirectObject(font);
+ getResources().addFont(font);
+ return ++this.lastFontAssigned;
+ }
+
+ /**
+ * Register an X object for use in this document.
+ * @param graphic The Graphic instance backing the X object resource.
+ * @param theXObject The X object to register.
+ * @return The incremented X object count.
+ */
+ public int registerXObjectResource(final Graphic graphic,
+ final PdfXobject4a theXObject) {
+ // Add it to the global map so that it can be reused.
+ this.xObjectsMap.put(graphic, theXObject);
+ registerIndirectObject(theXObject);
+ getResources().addXObject(theXObject);
+ return ++this.lastXObjectAssigned;
+ }
+
+ /**
+ * Return the root object.
+ * @return The root object.
+ */
+ public PdfRoot getRoot() {
+ return this.root;
+ }
+
+ /**
+ * Return the default list of filters to be applied to streams in this
+ * document.
+ * @return The default filters.
+ */
+ public List<String> getDefaultFilters() {
+ return this.filters;
+ }
+
+ @Override
+ public void addDefaultFilter(final String filterToAdd) {
+ if (filterToAdd == null) {
+ return;
+ }
+ this.filters.add(filterToAdd);
+ }
+
+ /**
+ * Computes the next available tag to be used as a prefix for a BaseFont or
+ * FontName entry, when the font is subsetted. The specification for the
+ * tag is described in PDF Reference, Second Edition, Section 5.5.3.
+ * @return The tag to be prefixed to the subset font's name.
+ */
+ public String getNextFontSubsetTag() {
+ final StringBuilder tag = new StringBuilder();
+ for (int i = 0; i < this.nextFontSubsetTag.length; i ++) {
+ tag.append(this.nextFontSubsetTag[i]);
+ }
+ this.nextFontSubsetTag.toString();
+ this.nextFontSubsetTag[this.nextFontSubsetTag.length - 1] += 1;
+ for (int i = this.nextFontSubsetTag.length - 1; i >= 0; i--) {
+ if (this.nextFontSubsetTag[i] > 'Z') {
+ this.nextFontSubsetTag[i] = 'A';
+ if (i > 0) {
+ this.nextFontSubsetTag[i - 1] += 1;
+ }
+ }
+ }
+ return tag.toString();
+ }
+
+ /**
+ * Return the logger.
+ * @return The logger.
+ */
+ public Logger getLogger() {
+ return this.logger;
+ }
+
+ /**
+ * Returns the default border style for this document.
+ * @return Returns the default border style.
+ */
+ public PdfBorderStyle getDefaultBorderStyle() {
+ if (this.defaultBorderStyle == null) {
+ this.defaultBorderStyle = new PdfBorderStyle(this, 0, PdfBorderStyle.Style.SOLID);
+ }
+ return this.defaultBorderStyle;
+ }
+
+ /**
+ * If a PdfXobject has already been created for a given URL, return that
+ * PdfXobject so that it can be reused.
+ * @param graphic The Graphic instance for which a PdfXobject is sought.
+ * @return The corresponding PdfXobject, or null if there is none.
+ */
+ public PdfXobject4a findXObject(final Graphic graphic) {
+ return this.xObjectsMap.get(graphic);
+ }
+
+ /**
+ * Obtain a PdfEncoding for a given Encoding instance.
+ * This method ensures that unnecessary duplicate PdfEncoding instances are
+ * not created.
+ * @param encoding The encoding for which a PdfEncoding is needed.
+ * @return The appropriate PdfEncoding instance.
+ */
+ public PdfEncoding4a obtainPDFEncoding(final Encoding encoding) {
+ if (encoding == null) {
+ return null;
+ }
+ PdfEncoding4a pdfEncoding = this.encodingsUsed.get(encoding);
+ if (pdfEncoding == null) {
+ pdfEncoding = new PdfEncoding4a(encoding);
+ this.encodingsUsed.put(encoding, pdfEncoding);
+ }
+ return pdfEncoding;
+ }
+
+ /**
+ * Obtain a PdfFont4a for a given FontUse instance.
+ * This method ensures that unnecessary duplicate PdfFont4a instances are
+ * not created.
+ * @param fontUse The font for which a PdfFont4a is needed.
+ * @return The appropriate PdfFont4a instance.
+ */
+ public PdfFont4a getPdfFont(final FontUse fontUse) {
+ final Font font = fontUse.getFont();
+ /* Look for a match in the existing fonts. */
+ for (int i = 0; i < this.usedFonts.size(); i++) {
+ final PdfFont4a pdfFont = this.usedFonts.get(i);
+ final Font testFont = pdfFont.getFont();
+ /* For there to be a match, the underlying fonts must be the same
+ * and the encoding must be the same. */
+ if (testFont == font
+ && fontUse.getEncoding() == pdfFont.getEncoding()) {
+ return pdfFont;
+ }
+ }
+ final PdfFont4a pdfFont = PdfFont4a.makeFont(this, fontUse);
+ this.usedFonts.add(pdfFont);
+ return pdfFont;
+ }
+
+ @Override
+ public PdfEncryption4a createPdfEncryption() {
+ if (this.encryption == null) {
+ this.encryption = new org.foray.pdf.object.PdfEncryption4a(this);
+ }
+ return this.encryption;
+ }
+
+ @Override
+ public PdfColor4a createPdfColor(final Color color) {
+ PdfColor4a pdfColor = null;
+ for (int i = 0; i < this.usedColors.size(); i++) {
+ pdfColor = this.usedColors.get(i);
+ if (pdfColor.getAwtColor().equals(color)) {
+ return pdfColor;
+ }
+ }
+ pdfColor = new PdfColor4a(color);
+ this.usedColors.add(pdfColor);
+ return pdfColor;
+ }
+
+ @Override
+ public PdfPage4a createPdfPage(final int pagewidth, final int pageheight) {
+ /* Delegate this entirely to the root. */
+ return this.root.createPage(pagewidth, pageheight);
+ }
+
+ @Override
+ public String getFontName(final FontUse fontUse) {
+ final PdfFont4a pdfFont = this.getPdfFont(fontUse);
+ return pdfFont.getName();
+ }
+
+ @Override
+ public String getGradientName(final MultipleGradientPaint gradient) {
+ /* TODO: See if this gradient already exists before creating it again. */
+ final PdfPattern4a pattern = this.createGradient(gradient);
+ return pattern.getName();
+ }
+
+ @Override
+ public void addPageLabelRange(final int startingPageIndex,
+ final PdfPageLabelStyle labelStyle, final CharSequence labelPrefix,
+ final int startingPageNumber) {
+ final PdfPageLabel newPageLabel = new PdfPageLabel(this, labelStyle,
+ labelPrefix, startingPageNumber);
+ this.getRoot().addPageLabel(startingPageIndex, newPageLabel);
+ }
+
+ @Override
+ public PdfPattern4a createGradient(final MultipleGradientPaint gradient) {
+ final boolean radial = gradient instanceof RadialGradientPaint;
+ ColorSpace theColorSpace = null;
+ if (gradient.getColorSpace() != null) {
+ switch (gradient.getColorSpace()) {
+ case SRGB: {
+ theColorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+ break;
+ }
+ case LINEAR_RGB: {
+ theColorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
+ break;
+ }
+ default: {
+ throw new IllegalStateException("Unexpected Gradient color space type: " + gradient.getColorSpace());
+ }
+ }
+ }
+ final List<Color> theColors = Arrays.asList(gradient.getColors());
+ final List<Double> theBounds = new ArrayList<Double>();
+ theBounds.add(0D);
+ theBounds.add(1D);
+ final List<Double> theCoords = new ArrayList<Double>();
+ if (gradient instanceof LinearGradientPaint) {
+ final LinearGradientPaint linearGradient = (LinearGradientPaint) gradient;
+ theCoords.add(linearGradient.getStartPoint().getX());
+ theCoords.add(linearGradient.getStartPoint().getY());
+ theCoords.add(linearGradient.getEndPoint().getX());
+ theCoords.add(linearGradient.getEndPoint().getY());
+ } else if (gradient instanceof RadialGradientPaint) {
+ final RadialGradientPaint radialGradient = (RadialGradientPaint) gradient;
+ radialGradient.getCenterPoint().getX();
+ radialGradient.getCenterPoint().getY();
+ radialGradient.getFocusPoint().getX();
+ radialGradient.getFocusPoint().getY();
+ }
+
+ final PdfShading myShad;
+ final PdfFunction myfunky;
+ PdfFunction myfunc;
+ List<Double> theCzero;
+ List<Double> theCone;
+ final PdfPattern4a myPattern;
+ final double interpolation = 1.000;
+ final List<PdfFunction> theFunctions = new ArrayList<PdfFunction>();
+
+ int currentPosition;
+ final int lastPosition = theColors.size() - 1;
+
+
+ // if 5 elements, the penultimate element is 3.
+ // do not go beyond that, because you always need
+ // to have a next color when creating the function.
+
+ for (currentPosition = 0; currentPosition < lastPosition;
+ currentPosition++) { // for every consecutive color pair
+ Color currentColor = theColors.get(currentPosition);
+ Color nextColor = theColors.get(currentPosition + 1);
+ /* The colorspace must be consistent. */
+ if (theColorSpace.getType()
+ != currentColor.getColorSpace().getType()) {
+ currentColor = ColorUtil.convertColorSpace(currentColor,
+ theColorSpace);
+ }
+
+ if (theColorSpace.getType()
+ != nextColor.getColorSpace().getType()) {
+ nextColor = ColorUtil.convertColorSpace(nextColor,
+ theColorSpace);
+ }
+
+ theCzero = colorToDoubleList(currentColor);
+ theCone = colorToDoubleList(nextColor);
+
+ myfunc = new PdfFunction(2, null, null, theCzero, theCone, interpolation);
+
+ theFunctions.add(myfunc);
+
+ } // end of for every consecutive color pair
+
+ myfunky = new PdfFunction(PdfFunction.TYPE_STITCHING, null, null, theFunctions, theBounds, null);
+ if (radial) {
+ if (theCoords.size() == PdfConstants.QTY_RADIAL_SHADING_COMPONENTS) {
+ myShad = new PdfShading(this, PdfShading.TYPE_RADIAL,
+ theColorSpace, null, null,
+ false, theCoords, null, myfunky,
+ null);
+ } else { // if the center x, center y, and radius specifiy
+ // the gradient, then assume the same center x, center y,
+ // and radius of zero for the other necessary component
+ final List<Double> newCoords = new ArrayList<Double>();
+ newCoords.add(theCoords.get(0));
+ newCoords.add(theCoords.get(1));
+ newCoords.add(theCoords.get(2));
+ newCoords.add(theCoords.get(0));
+ newCoords.add(theCoords.get(1));
+ newCoords.add(0.0);
+ myShad = new PdfShading(this, PdfShading.TYPE_RADIAL,
+ theColorSpace,
+ null, null, false, newCoords, null, myfunky,
+ null);
+ }
+ } else {
+ myShad = new PdfShading(this, 2, theColorSpace,
+ null, null, false, theCoords, null, myfunky, null);
+ }
+ myPattern = new PdfPattern4a(this, 2, myShad, null,
+ null, null);
+ return myPattern;
+ }
+
+ /**
+ * Convert a color to a list of its components.
+ * @param theColor The color to be converted.
+ * @return The list of the color components.
+ */
+ static List<Double> colorToDoubleList(final Color theColor) {
+ final List<Double> theColorVector = new ArrayList<Double>();
+ if (theColor == null) {
+ return theColorVector;
+ }
+ final float[] colorComponents = theColor.getColorComponents(null);
+ for (int i = 0; i < colorComponents.length; i++) {
+ theColorVector.add((double) colorComponents[i]);
+ }
+ return theColorVector;
+ }
+
+ /**
+ * Returns the PostScript server.
+ * @return The PostScript server.
+ */
+ public PsServer getPsServer() {
+ return this.psServer;
+ }
+
+ @Override
+ public PdfDocumentInfo4a getDocumentInfo(final boolean forceCreate) {
+ if (this.info != null) {
+ return this.info;
+ }
+ if (forceCreate) {
+ this.info = new PdfDocumentInfo4a();
+ }
+ return this.info;
+ }
+
+ private void checkAlreadySerialized() {
+ if (this.serialized) {
+ throw new IllegalStateException("Document has already been serialized. Cannot serialize again.");
+ }
+ this.serialized = true;
+ }
+
+ @Override
+ public void serialize(final OutputStream output, final PdfSerializationConfig config)
+ throws PdfException, IOException {
+ checkAlreadySerialized();
+ this.position = 0;
+
+ final ByteArrayBuilder headerBytes = this.header.toPDF();
+ headerBytes.writeTo(output);
+ this.position += headerBytes.length();
+
+ /* Write the pages and other accumulated objects. */
+ writeIndirectObjects(output);
+ writeDeferredIndirectObjects(output);
+
+ /* Remember position of xref table. */
+ final long xrefPosition = this.position;
+ this.xrefInfo.writeTable(output);
+
+ writeTrailer(output, xrefPosition);
+ }
+
+ @Override
+ public void serialize(final OutputStream output, final PdfPageProvider<PdfPage4a> provider,
+ final PdfSerializationConfig config) {
+ checkAlreadySerialized();
+ /* @TODO: Implement this. */
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Returns the file trailer, creating it if necessary.
+ * @return the file trailer object.
+ */
+ public PdfTrailer getTrailer() {
+ if (this.lazyTrailer == null) {
+ this.lazyTrailer = new PdfTrailer();
+ }
+ return this.lazyTrailer;
+ }
+
+ public PdfHeader getHeader() {
+ return this.header;
+ }
+
+ public PdfCrossRefInfo getCrossRefInfo() {
+ return this.xrefInfo;
+ }
+
+ @Override
+ public PdfXobject createXobject(final Graphic graphic, final Orthography orthography,
+ final FontConsumer fontConsumer) throws PdfException {
+ final PdfXobject4a xObject;
+ try {
+ xObject = PdfXobject4a.makeXObject(this, graphic, orthography, fontConsumer);
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+ if (xObject == null) {
+ throw new PdfException("Don't know how to process graphic: " + graphic.getUrl());
+ }
+ return xObject;
+ }
+
+ @Override
+ public void reorderPages(final Comparator<PdfPage> comparator) {
+ this.root.getPages().reorderPages(comparator);
+ }
+
+ @Override
+ public PdfDestinationNamed getNamedDestination(final String name) {
+ return this.root.getNamedDestinations().get(name);
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java (from rev 12500, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPage4a.java 2022-01-29 21:21:04 UTC (rev 12503)
@@ -0,0 +1,236 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.document;
+
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.graphics.PdfShading;
+import org.foray.pdf.interact.PdfDestinationExplicit4a;
+import org.foray.pdf.interact.PdfDestinationNamed4a;
+import org.foray.pdf.interact.action.PdfAction;
+import org.foray.pdf.interact.action.PdfGoToRemote;
+import org.foray.pdf.interact.action.PdfUri;
+import org.foray.pdf.interact.annotation.PdfLink;
+import org.foray.pdf.object.PdfAnnotList;
+import org.foray.pdf.object.PdfContentStream4a;
+import org.foray.pdf.object.PdfEncryption4a;
+import org.foray.pdf.object.PdfFileSpec;
+import org.foray.pdf.object.PdfResources;
+import org.foray.pdf.structure.PdfNameTree;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.pdf.PdfDestination;
+import org.axsl.pdf.PdfDestinationExplicit.Coordinates;
+import org.axsl.pdf.PdfDestinationExplicit.PositionAndZoom;
+import org.axsl.pdf.PdfException;
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.awt.geom.Rectangle2D;
+
+/**
+ * A PDF Page.
+ * There is one of these for every page in a PDF document. The object
+ * specifies the dimensions of the page and references a /Resources
+ * object, a contents stream and the page's parent in the page
+ * hierarchy.
+ */
+public class PdfPage4a extends PdfObject implements org.axsl.pdf.PdfPage {
+
+ /** Constant used to specify a destination fragment. */
+ private static final String PDF_DESTINATION_FRAGMENT_SPECIFIER = "#dest=";
+
+ /** Constant used to designate a page destination. */
+ private static final String PDF_PAGE_FRAGMENT_SPECIFIER = "#page=";
+
+ /** The standard file extension for a PDF document. */
+ private static final String PDF_FILE_EXTENSION = ".pdf";
+
+ /** The page's parent, a PDF reference object. */
+ private PdfPages parent;
+
+ /** The page's /Resource object. */
+ private PdfResources resources;
+
+ /** The page's content stream. */
+ private PdfContentStream4a contents;
+
+ /** The width of the page in points. */
+ private int pagewidth;
+
+ /** The height of the page in points. */
+ private int pageheight;
+
+ /** The list of annotation objects for this page.
+ * Since the /Annots entry in the Page dictionary is optional, this should
+ * remain null until the first time an annotation needs to be entered. */
+ private PdfAnnotList annotList = null;
+
+ /**
+ * Create a /Page object.
+ * @param parent The parent /Pages object.
+ * @param resources The /Resources object.
+ * @param pagewidth The page's width in points.
+ * @param pageheight The page's height in points.
+ */
+ public PdfPage4a(final PdfPages parent, final PdfResources resources, final int pagewidth, final int pageheight) {
+ this.parent = parent;
+ final PdfDocument4a document = parent.getRoot().getDocument();
+ this.resources = resources;
+ this.pagewidth = pagewidth;
+ this.pageheight = pageheight;
+ this.contents = new PdfContentStream4a();
+ try {
+ this.contents.addDefaultFilters(document);
+ } catch (final PdfException e) {
+ /* Ignore, should not happen. */
+ }
+ final PdfEncryption4a encryption = document.getEncryption();
+ if (encryption != null) {
+ this.contents.addEncryption(encryption);
+ }
+ }
+
+ /**
+ * Get this page's annotation list.
+ * @return annotList a PdfAnnotList list of annotations
+ */
+ private PdfAnnotList getAnnotList() {
+ if (this.annotList == null) {
+ this.annotList = new PdfAnnotList();
+ }
+ return this.annotList;
+ }
+
+ /**
+ * Add a shading to this page.
+ * @param shading The shading to be added.
+ */
+ public void addShading(final PdfShading shading) {
+ this.resources.addShading(shading);
+ }
+
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append(this.pdfID() + EOL
+ + "<<" + EOL
+ + "/Type /Page" + EOL
+ + "/Parent " + this.parent.pdfReference(doc) + EOL
+ + "/MediaBox [ 0 0 " + this.pagewidth + " "
+ + this.pageheight + " ]" + EOL
+ + "/Resources " + this.resources.pdfReference(doc) + EOL
+ + "/Contents " + this.contents.pdfReference(doc) + EOL);
+ if (this.annotList != null) {
+ sb.append("/Annots " + this.annotList.pdfReference(doc) + EOL);
+ }
+
+ sb.append(">>" + EOL + "endobj" + EOL);
+
+ return new ByteArray(sb);
+ }
+
+ /**
+ * Add an annotation list to the annotations on this page.
+ * @param listToAdd The annotation list to add.
+ */
+ public void addAnnotationList(final PdfAnnotList listToAdd) {
+ this.getAnnotList().addAnnotationList(listToAdd);
+ }
+
+ @Override
+ public PdfLink createLink(final Rectangle2D rect, final String destination, final boolean externalLink) {
+ final PdfAction action;
+ PdfLink link = null;
+ int index = 0;
+
+ if (externalLink) {
+ // check destination
+ // FileSpec
+ if (destination.endsWith(PdfPage4a.PDF_FILE_EXTENSION)) {
+ final PdfFileSpec fileSpec = new PdfFileSpec(destination);
+ action = new PdfGoToRemote(fileSpec);
+ } else if ((index = destination.indexOf(PdfPage4a.PDF_FILE_EXTENSION
+ + PdfPage4a.PDF_PAGE_FRAGMENT_SPECIFIER)) > 0) {
+ final String file = destination.substring(0, index + PdfPage4a.PDF_FILE_EXTENSION.length());
+ final int pageNum = Integer.parseInt(destination.substring(
+ index + PdfPage4a.PDF_FILE_EXTENSION.length()
+ + PdfPage4a.PDF_PAGE_FRAGMENT_SPECIFIER.length()));
+ final PdfFileSpec fileSpec = new PdfFileSpec(file);
+ action = new PdfGoToRemote(fileSpec, pageNum);
+ } else if ((index = destination.indexOf(PdfPage4a.PDF_FILE_EXTENSION
+ + PdfPage4a.PDF_DESTINATION_FRAGMENT_SPECIFIER)) > 0) {
+ final String file = destination.substring(0,
+ index + PdfPage4a.PDF_FILE_EXTENSION.length());
+ final String dest = destination.substring(
+ index + PdfPage4a.PDF_FILE_EXTENSION.length()
+ + PdfPage4a.PDF_DESTINATION_FRAGMENT_SPECIFIER.length());
+ final PdfFileSpec fileSpec = new PdfFileSpec(file);
+ action = new PdfGoToRemote(fileSpec, dest);
+ } else { // URI
+ action = new PdfUri(destination);
+ }
+ link = new PdfLink(rect, action);
+ } else { // linkType is internal
+ link = new PdfLink(rect, destination);
+ }
+ getAnnotList().addAnnotation(link);
+ return link;
+ }
+
+ @Override
+ public PdfContentStream4a getContentStream() {
+ return this.contents;
+ }
+
+ @Override
+ public PdfDestination createDestination(final PositionAndZoom positionAndZoom,
+ final Coordinates coordinates, final Float explicitZoom, final String name) throws PdfException {
+ /* Has the name already been registered as a named destination? */
+ final PdfDocument4a document = this.parent.getRoot().getDocument();
+ final PdfNameTree<PdfDestinationNamed4a> namedDestinations = document.getRoot().getNamedDestinations();
+ if (name != null) {
+ final PdfDestinationNamed4a existingDestination = namedDestinations.get(name);
+ if (existingDestination != null) {
+ throw new PdfException("Named destination already exists: " + name);
+ }
+ }
+ final PdfDestinationExplicit4a explicitDestination =
+ new PdfDestinationExplicit4a(this, positionAndZoom, coordinates, explicitZoom);
+ document.registerIndirectObjectLast(explicitDestination);
+
+ if (name != null) {
+ final PdfDestinationNamed4a namedDestination = new PdfDestinationNamed4a(name, explicitDestination);
+ namedDestinations.put(name, namedDestination);
+ return namedDestination;
+ } else {
+ return explicitDestination;
+ }
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java (from rev 12498, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPages.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfPages.java 2022-01-29 21:21:04 UTC (rev 12503)
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.document;
+
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.pdf.PdfPage;
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * A /Pages object.
+ * A /Pages object is an ordered collection of pages (/Page objects).
+ * (Actually, /Pages can contain further /Pages as well but this implementation doesn't currently support this).
+ */
+public class PdfPages extends PdfObject {
+
+ /** The parent root (/Catalog) object. */
+ private PdfRoot pdfRoot;
+
+ /** The /Page objects. This list must be modifiable so that it can be sorted by
+ * {@link #reorderPages(Comparator)}. */
+ private List<PdfPage4a> kids = new ArrayList<PdfPage4a>();
+
+ /**
+ * <p>Constructor for a /Pages object.</p>
+ * <p>NOTE: The {@link PdfPages} object must be created before the PDF document is generated, but it is not written
+ * to the stream immediately.
+ * It must also be allocated an object ID (so that the kids can refer to the parent), and the XRef table needs to be
+ * updated before this object is written.
+ * @param pdfRoot The parent root (/Catalog) object.
+ */
+ public PdfPages(final PdfRoot pdfRoot) {
+ this.pdfRoot = pdfRoot;
+ }
+
+ /**
+ * Adds a /Page object.
+ * @param page The PdfPage4a to add.
+ */
+ public void addPage(final PdfPage4a page) {
+ this.pdfRoot.getDocument().registerIndirectObject(page);
+ this.kids.add(page);
+ }
+
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ /* TODO: Create a balanced tree here. See the PDF Reference. */
+ final StringBuilder p = new StringBuilder();
+ p.append(this.pdfID() + EOL);
+ p.append("<< /Type /Pages" + EOL);
+ p.append("/Count " + this.kids.size() + EOL);
+ p.append("/Kids [" + EOL);
+ for (int i = 0; i < this.kids.size(); i++) {
+ final PdfPage4a page = this.kids.get(i);
+ final String pageRef = page.pdfReference(doc);
+ p.append(pageRef + EOL);
+ }
+ p.append("] >>" + EOL + "endobj" + EOL);
+
+ return new ByteArray(p);
+ }
+
+ /**
+ * Returns the parent root (/Catalog) object.
+ * @return The parent root object.
+ */
+ public PdfRoot getRoot() {
+ return this.pdfRoot;
+ }
+
+ /**
+ * Sorts the child pages of the object using a comparator.
+ * @param comparator The comparator to be used to sort the child pages.
+ */
+ public void reorderPages(final Comparator<PdfPage> comparator) {
+ Collections.sort(this.kids, comparator);
+ }
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java (from rev 12499, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/document/PdfRoot.java 2022-01-29 21:21:04 UTC (rev 12503)
@@ -0,0 +1,221 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.document;
+
+import org.foray.common.primitive.StringUtils;
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.PdfConstants;
+import org.foray.pdf.interact.PdfDestinationNamed4a;
+import org.foray.pdf.interact.PdfNamedDestinationsTree4a;
+import org.foray.pdf.interact.PdfOutline4a;
+import org.foray.pdf.interact.PdfPageLabel;
+import org.foray.pdf.object.PdfEmbeddedFileStream;
+import org.foray.pdf.structure.PdfNameTree;
+import org.foray.pdf.structure.PdfNumberTree;
+import org.foray.pdf.type.PdfDictionary;
+
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.util.List;
+
+/**
+ * The Root (/Catalog) object.
+ */
+public class PdfRoot extends PdfDictionary {
+
+ /** The parent PDF document. */
+ private PdfDocument4a document;
+
+ /** The /Pages object that is root of the Pages hierarchy. */
+ private PdfPages pages;
+
+ /** The number tree containing the range values for the page labels in this
+ * document. */
+ private PdfNumberTree<PdfPageLabel> pageLabels;
+
+ /** The root outline object. Lazily created, to avoid unnecessary objects. */
+ private PdfOutline4a outline;
+
+ /** Collection of named destinations. */
+ private PdfNamedDestinationsTree4a namedDestinations;
+
+ /** The embedded files. */
+ private PdfNameTree<PdfEmbeddedFileStream> embeddedFiles;
+
+ /**
+ * Create a Root (/Catalog) object.
+ * @param document The parent PDF document.
+ */
+ public PdfRoot(final PdfDocument4a document) {
+ this.document = document;
+ this.pages = new PdfPages(this);
+ }
+
+ /**
+ * Create a /Page object and add it to /Pages.
+ * @param width The width of the new page, in points.
+ * @param height The height of the new page, in points.
+ * @return The new page.
+ */
+ public PdfPage4a createPage(final int width, final int height) {
+ final PdfPage4a page = new PdfPage4a(this.pages, this.document.getResources(), width, height);
+ this.pages.addPage(page);
+ return page;
+ }
+
+ /**
+ * Returns the page labels in this document.
+ * @return The page labels in this document.
+ */
+ private PdfNumberTree<PdfPageLabel> getPageLabels() {
+ if (this.pageLabels == null) {
+ this.pageLabels = new PdfNumberTree<PdfPageLabel>();
+ }
+ return this.pageLabels;
+ }
+
+ /**
+ * Adds a range of pages to the page labels for this document.
+ * @param pageIndex The 0-based page index of the first page in this range
+ * label.
+ * @param pageLabel The page label instance that handles formatting for page
+ * {@code pageIndex} until the next range label.
+ */
+ public void addPageLabel(final int pageIndex,
+ final PdfPageLabel pageLabel) {
+ final PdfNumberTree<PdfPageLabel> pageLabels = this.getPageLabels();
+ pageLabels.add(pageIndex, pageLabel);
+ }
+
+ /**
+ * Returns the destinations in this document.
+ * @return The destinations in this document.
+ */
+ public PdfNameTree<PdfDestinationNamed4a> getNamedDestinations() {
+ if (this.namedDestinations == null) {
+ this.namedDestinations = new PdfNamedDestinationsTree4a();
+ this.document.registerIndirectObjectLast(this.namedDestinations);
+ }
+ return this.namedDestinations;
+ }
+
+ /**
+ * Returns the embedded files in this document.
+ * @return The embedded files in this document.
+ */
+ public PdfNameTree<PdfEmbeddedFileStream> getEmbeddedFiles() {
+ if (this.embeddedFiles == null) {
+ this.embeddedFiles = new PdfNameTree<PdfEmbeddedFileStream>();
+ }
+ return this.embeddedFiles;
+ }
+
+ /**
+ * Returns the root Outlines object, creating it if necessary.
+ * @return The root Outlines object.
+ */
+ public PdfOutline4a getOutlineRoot() {
+ if (this.outline == null) {
+ this.outline = new PdfOutline4a();
+ this.document.registerIndirectObject(this.outline);
+ }
+ return this.outline;
+ }
+
+ /**
+ * Represent the object as PDF.
+ * @param doc The PDF Document.
+ * @return The PDF string
+ */
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ final StringBuilder p = new StringBuilder();
+ p.append(this.pdfID() + EOL);
+ p.append(PdfConstants.OPEN_DICTIONARY + EOL);
+ p.append("/Type /Catalog" + EOL);
+ p.append("/Pages " + this.pages.pdfReference(doc) + EOL);
+ if (this.pageLabels != null) {
+ p.append("/PageLabels " + this.pageLabels.pdfReference(doc) + EOL);
+ }
+ if (this.outline != null) {
+ p.append(" /Outlines " + this.outline.pdfReference(doc) + EOL);
+ p.append(" /PageMode /UseOutlines" + EOL);
+ }
+ if (this.hasNameDictionary()) {
+ p.append(" /Names" + EOL);
+ p.append(StringUtils.SINGLE_SPACE + PdfConstants.OPEN_DICTIONARY + EOL);
+ if (this.namedDestinations != null) {
+ p.append(" /Dests " + this.namedDestinations.pdfReference(doc) + EOL);
+ }
+ if (this.embeddedFiles != null) {
+ p.append(" /EmbeddedFiles " + this.embeddedFiles.pdfReference(doc) + EOL);
+ }
+ p.append(StringUtils.S...
[truncated message content] |
|
From: <vic...@us...> - 2022-01-29 21:03:50
|
Revision: 12502
http://sourceforge.net/p/foray/code/12502
Author: victormote
Date: 2022-01-29 21:03:44 +0000 (Sat, 29 Jan 2022)
Log Message:
-----------
Move some graphics- and text-related classes to new packages.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfCidFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfColor4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.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/PdfFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFunction.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/package-info.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfFormXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfGraphicsState4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfImageXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPathPaint4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformEps.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformSvg.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXobject4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXreference.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/package-info.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfEncoding4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFont4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfFontType0.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfTextState4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/PdfToUnicodeCmap.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/text/package-info.java
Removed Paths:
-------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDashPattern.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfEncoding.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFont4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFontType0.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPathPaint.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPattern.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfToUnicodeCmap.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformMath.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformSvg.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState4a.java 2022-01-29 20:19:15 UTC (rev 12501)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState4a.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -1,204 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.pdf;
-
-import org.foray.pdf.object.PdfColor4a;
-import org.foray.pdf.object.PdfDashPattern;
-
-import org.axsl.pdf.PdfColor;
-import org.axsl.pdf.PdfLineCapStyle;
-
-/**
- * The PDF graphics state.
- * Tracks the current state of various properties used to render content, such as colors and fonts.
- * The PDF Reference distinguishes between graphics state parameters that are device-independent and those that are
- * device-dependent.
- * While rendering the PDF document, we care only about those that are device-independent, and therefore track only
- * those in this class.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3."
- */
-public class PdfGraphicsState4a {
-
- /** The stroke color. */
- private PdfColor strokeColor;
-
- /** The "non-stroke" or "other" color. */
- private PdfColor fillColor;
-
- /** The text state. */
- private PdfTextState textState = new PdfTextState();
-
- /** The line cap style. */
- private PdfLineCapStyle lineCapStyle;
-
- /** The dash pattern. */
- private PdfDashPattern dashPattern;
-
- /**
- * Create a PdfGraphicsState instance.
- */
- public PdfGraphicsState4a() {
- reset();
- }
-
- /**
- * Creates a new PdfGraphicsState instance, initilializing its values to those of an existing instance.
- * @param existingState The instance whose values should be copied into the new instance.
- */
- public PdfGraphicsState4a(final PdfGraphicsState4a existingState) {
- this.strokeColor = existingState.strokeColor;
- this.fillColor = existingState.fillColor;
- this.textState = new PdfTextState(this.textState);
- this.lineCapStyle = existingState.lineCapStyle;
- this.dashPattern = existingState.dashPattern;
- }
-
- /**
- * Resets each property in the Graphics State to its initial state.
- * The initial state values are documented in Table 4.2 in "PDF Reference, Sixth Edition (PDF Version 1.7), Section
- * 4.3."
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3."
- */
- public void reset() {
- this.strokeColor = PdfColor4a.BLACK;
- this.fillColor = PdfColor4a.BLACK;
- this.textState.reset();
- this.lineCapStyle = PdfLineCapStyle.BUTT_CAP;
- this.dashPattern = PdfDashPattern.SOLID_LINE;
- }
-
- /**
- * Returns the stroke color.
- * @return The stroke color.
- */
- public PdfColor getStrokeColor() {
- return strokeColor;
- }
-
- /**
- * Sets the stroke color.
- * @param newStrokeColor The new stroke color.
- * @return True if and only if the Graphics State was changed by this operation.
- * @see #getStrokeColor()
- */
- public boolean setStrokeColor(final PdfColor newStrokeColor) {
- if (newStrokeColor == null) {
- return false;
- }
- boolean anyChange = false;
- if (! newStrokeColor.equals(this.strokeColor)) {
- this.strokeColor = newStrokeColor;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Returns the non-stroke or "other" color.
- * @return The non-stroke or other color.
- */
- public PdfColor getFillColor() {
- return fillColor;
- }
-
- /**
- * Sets the "non-stroke" or "other" or "fill" color.
- * @param newFillColor The new non-stroke color.
- * @return True if and only if the Graphics State was changed by this operation.
- * @see #getFillColor()
- */
- public boolean setFillColor(final PdfColor newFillColor) {
- if (newFillColor == null) {
- return false;
- }
- boolean anyChange = false;
- if (! newFillColor.equals(this.fillColor)) {
- this.fillColor = newFillColor;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Returns the text state.
- * @return The text state.
- */
- public PdfTextState getTextState() {
- return textState;
- }
-
- /**
- * Returns the line cap style.
- * @return The line cap style.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
- */
- public PdfLineCapStyle getLineCapStyle() {
- return lineCapStyle;
- }
-
- /**
- * Sets the line cap style.
- * @param newLineCapStyle The new line cap style.
- * @return True if and only if the Graphics State was changed by this operation.
- * @see #getLineCapStyle()
- */
- public boolean setLineCapStyle(final PdfLineCapStyle newLineCapStyle) {
- boolean anyChange = false;
- if (newLineCapStyle != this.lineCapStyle) {
- this.lineCapStyle = newLineCapStyle;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Returns the dash pattern.
- * @return The dash pattern.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
- */
- public PdfDashPattern getDashPattern() {
- return dashPattern;
- }
-
- /**
- * Sets the line dash pattern.
- * @param newDashPattern The new dash pattern.
- * @return True if and only if the Graphics State was changed by this operation.
- * @see #getDashPattern()
- */
- public boolean setLineDashPattern(final PdfDashPattern newDashPattern) {
- boolean anyChange = false;
- if (! this.dashPattern.equals(newDashPattern)) {
- this.dashPattern = newDashPattern;
- anyChange = true;
- }
- return anyChange;
- }
-
-}
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java 2022-01-29 20:19:15 UTC (rev 12501)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfTextState.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -1,327 +0,0 @@
-/*
- * 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.pdf;
-
-import org.axsl.pdf.PdfFont;
-import org.axsl.pdf.PdfTextRenderingMode;
-
-/**
- * The text state for the PDF graphics state.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2."
- */
-public class PdfTextState {
-
- /** Constant for the initial horizontal scaling percentage, that is 100%. */
- public static final float INITIAL_HORIZONTAL_SCALING = 100;
-
- /** The character spacing, expressed in unscaled text space units. */
- private float characterSpacing;
-
- /** The word spacing, expressed in unscaled text space units. */
- private float wordSpacing;
-
- /** The horizontal scaling, a percentage. */
- private float horizontalScaling;
-
- /** The text leading, expressed in unscaled text units. */
- private float leading;
-
- /** The font. */
- private PdfFont font;
-
- /** The font size. */
- private float fontSize;
-
- /** The text rendering mode. */
- private PdfTextRenderingMode textRenderingMode;
-
- /** The text rise, expressed in unscaled text space units. */
- private float textRise;
-
- /** The text knockout flag. */
- private boolean textKnockout;
-
- /**
- * Create a new instance.
- */
- public PdfTextState() {
- reset();
- }
-
- /**
- * Creates a new instance, initilializing its values to those of an existing instance.
- * @param existingState The instance whose values should be copied into the new instance.
- */
- public PdfTextState(final PdfTextState existingState) {
- this.characterSpacing = existingState.characterSpacing;
- this.wordSpacing = existingState.wordSpacing;
- this.horizontalScaling = existingState.horizontalScaling;
- this.leading = existingState.leading;
- this.font = existingState.font;
- this.fontSize = existingState.fontSize;
- this.textRenderingMode = existingState.textRenderingMode;
- this.textRise = existingState.textRise;
- this.textKnockout = existingState.textKnockout;
- }
-
- /**
- * Resets the text state parameters to their initial values.
- * The initial values, except for font and fontSize are documented at Table 5.2 in "PDF Reference, Sixth Edition
- * (PDV Version 1.7), Section 5.2".
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2."
- */
- public void reset() {
- this.characterSpacing = 0;
- this.wordSpacing = 0;
- this.horizontalScaling = PdfTextState.INITIAL_HORIZONTAL_SCALING;
- this.leading = 0;
- this.font = null;
- this.fontSize = -1;
- this.textRenderingMode = PdfTextRenderingMode.FILL;
- this.textRise = 0;
- this.textKnockout = true;
- }
-
- /**
- * Sets the character spacing.
- * @param newCharacterSpacing The new character spacing, expressed in unscaled text space units.
- * @return True if and only if the character spacing was changed.
- * @see #getCharacterSpacing()
- */
- public boolean setCharacterSpacing(final float newCharacterSpacing) {
- boolean anyChange = false;
- if (newCharacterSpacing != this.characterSpacing) {
- this.characterSpacing = newCharacterSpacing;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the word spacing.
- * @param newWordSpacing The new word spacing, expressed unscaled text space units.
- * @return True if and only if the word spacing was changed.
- * @see #getWordSpacing()
- */
- public boolean setWordSpacing(final float newWordSpacing) {
- boolean anyChange = false;
- if (newWordSpacing != this.wordSpacing) {
- this.wordSpacing = newWordSpacing;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the horizontal scaling.
- * @param newHorizontalScaling The new horizontal scaling, expressed as a percentage.
- * @return True if and only if the horizontal scaling was changed.
- * @see #getHorizontalScaling()
- */
- public boolean setHorizontalScaling(final float newHorizontalScaling) {
- boolean anyChange = false;
- if (newHorizontalScaling != this.horizontalScaling) {
- this.horizontalScaling = newHorizontalScaling;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the font.
- * @param newFont The new font.
- * @return True if and only if the font was changed.
- * @see #getFont()
- */
- public boolean setFont(final PdfFont newFont) {
- boolean anyChange = false;
- if (! newFont.equals(this.font)) {
- this.font = newFont;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the font size.
- * @param newFontSize The new font size, in points.
- * @return True if and only if the font size was changed.
- * @see #getFontSize()
- */
- public boolean setFontSize(final float newFontSize) {
- boolean anyChange = false;
- if (newFontSize != this.fontSize) {
- this.fontSize = newFontSize;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text leading. See PDF Reference, 3rd Edition, Section 5.2.4.
- * @param newLeading The new leading value.
- * @return True if and only if the text leading was changed by this operation.
- * @see #getLeading()
- */
- public boolean setLeading(final float newLeading) {
- boolean anyChange = false;
- if (newLeading != this.leading) {
- this.leading = newLeading;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text rendering mode. See PDF Reference, 3rd Edition, Section
- * 5.2.5.
- * @param newTextRenderingMode The new text rendering mode.
- * @return True if and only if the text rendering mode was changed by this operation.
- * @see #getTextRenderingMode()
- */
- public boolean setTextRenderingMode(
- final PdfTextRenderingMode newTextRenderingMode) {
- boolean anyChange = false;
- if (newTextRenderingMode != this.textRenderingMode) {
- this.textRenderingMode = newTextRenderingMode;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text rise. See PDF Reference, 3rd Edition, Section 5.2.6.
- * @param newTextRise The new text rise value.
- * @return True if and only if the text rise was changed by this operation.
- * @see #getTextRise()
- */
- public boolean setTextRise(final float newTextRise) {
- boolean anyChange = false;
- if (newTextRise != this.textRise) {
- this.textRise = newTextRise;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Sets the text knockout flag.
- * @param newTextKnockout The new text rise value.
- * @return True if and only if the text knockout was changed by this operation.
- * @see #isTextKnockout()
- */
- public boolean setTextKnockout(final boolean newTextKnockout) {
- boolean anyChange = false;
- if (newTextKnockout != this.textKnockout) {
- this.textKnockout = newTextKnockout;
- anyChange = true;
- }
- return anyChange;
- }
-
- /**
- * Returns the character spacing.
- * @return The character spacing, expressed in unscaled text space units.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.1."
- */
- public float getCharacterSpacing() {
- return characterSpacing;
- }
-
- /**
- * Returns the word spacing.
- * @return The word spacing, expressed in unscaled text space units.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.2."
- */
- public float getWordSpacing() {
- return wordSpacing;
- }
-
- /**
- * Returns the horizontal scaling.
- * @return The horizontal scaling, a percentage.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.3."
- */
- public float getHorizontalScaling() {
- return horizontalScaling;
- }
-
- /**
- * Returns the text leading.
- * @return The text leading, expressed in unscaled text units.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.4."
- */
- public float getLeading() {
- return leading;
- }
-
- /**
- * Returns the font.
- * @return The font.
- */
- public PdfFont getFont() {
- return font;
- }
-
- /**
- * Returns the font size.
- * @return The font size.
- */
- public float getFontSize() {
- return fontSize;
- }
-
- /**
- * Returns the text rendering mode.
- * @return The text rendering mode.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.5."
- */
- public PdfTextRenderingMode getTextRenderingMode() {
- return textRenderingMode;
- }
-
- /**
- * Returns the text rise.
- * @return The text rise, expressed in unscaled text space units.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.6."
- */
- public float getTextRise() {
- return textRise;
- }
-
- /**
- * Returns the text knockout flag.
- * @return The text knockout flag.
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 5.2.7."
- */
- public boolean isTextKnockout() {
- return textKnockout;
- }
-
-}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java (from rev 12484, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDashPattern.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfDashPattern4a.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -0,0 +1,93 @@
+/*
+ * 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.pdf.graphics;
+
+/**
+ * A PDF Line Dash Pattern.
+ * Instances of this class are immutable.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
+ */
+public class PdfDashPattern4a {
+
+ /** Dash pattern that will draw a solid, unbroken line. */
+ public static final PdfDashPattern4a SOLID_LINE = new PdfDashPattern4a(new float[0], 0);
+
+ /** Constant used to designate a "dotted" dash pattern. */
+ public static final PdfDashPattern4a DOTTED = new PdfDashPattern4a(new float[] {1, 3}, 0);
+
+ /** Constant used to designate a "dashed" dash pattern. */
+ public static final PdfDashPattern4a DASHED = new PdfDashPattern4a(new float[] {3, 3}, 0);
+
+ /** The dash array. */
+ private float[] dashArray;
+
+ /** The dash phase. */
+ private float dashPhase;
+
+ public PdfDashPattern4a(final float[] dashArray, final float dashPhase) {
+ this.dashArray = new float[dashArray.length];
+ System.arraycopy(dashArray, 0, this.dashArray, 0, dashArray.length);
+ this.dashPhase = dashPhase;
+ }
+
+ /**
+ * Returns the dash array.
+ * @return The dash array.
+ */
+ public float[] getDashArray() {
+ return this.dashArray;
+ }
+
+ /**
+ * Returns the dash phase.
+ * @return The dash phase.
+ */
+ public float getDashPhase() {
+ return this.dashPhase;
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (! (other instanceof PdfDashPattern4a)) {
+ return false;
+ }
+ final PdfDashPattern4a otherDashPattern = (PdfDashPattern4a) other;
+ if (! this.dashArray.equals(otherDashPattern.dashArray)) {
+ return false;
+ }
+ if (this.dashPhase != otherDashPattern.dashPhase) {
+ return false;
+ }
+ return true;
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfFormXobject.java (from rev 12482, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfFormXobject.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfFormXobject.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.graphics;
+
+import org.foray.pdf.object.PdfDocument4a;
+
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.pdf.PdfException;
+import org.axsl.ps.BoundingBox;
+
+import java.awt.geom.AffineTransform;
+
+/**
+ * <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 <em>form</em> in this context."
+ */
+public abstract class PdfFormXobject extends PdfXobject4a {
+
+ /**
+ * Constructor.
+ * @param doc The parent PDF document.
+ * @param graphic The form to be encapsulated.
+ */
+ public PdfFormXobject(final PdfDocument4a doc, final Graphic graphic) {
+ super(doc, graphic);
+ }
+
+ @Override
+ protected String xObjectSubtype() {
+ return "Form";
+ }
+
+ @Override
+ protected void xObjectContent(final PdfDocument4a doc) throws PdfException {
+ byte[] bytes = null;
+ try {
+ bytes = getPdfContent(doc);
+ } catch (final GraphicException e) {
+ // Ignore this. An error was already logged & fallback is below.
+ }
+ if (bytes == null) {
+ return;
+ }
+ this.write(bytes);
+ }
+
+ /**
+ * Converts the graphic content to PDF content.
+ * @param doc The PDF document.
+ * @return The PDF content.
+ * @throws GraphicException For errors during conversion.
+ */
+ protected abstract byte[] getPdfContent(PdfDocument4a doc) throws GraphicException;
+
+ @Override
+ protected String specialXObjectDictEntries(final PdfDocument4a doc) throws GraphicException {
+ final BoundingBox boundingBox = this.getBoundingBox();
+ final float llx = boundingBox.getCoordinateAsFloat(BoundingBox.LOWER_LEFT_X_INDEX);
+ final float lly = boundingBox.getCoordinateAsFloat(BoundingBox.LOWER_LEFT_Y_INDEX);
+ final float urx = boundingBox.getCoordinateAsFloat(BoundingBox.UPPER_RIGHT_X_INDEX);
+ final float ury = boundingBox.getCoordinateAsFloat(BoundingBox.UPPER_RIGHT_Y_INDEX);
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append("/FormType 1" + EOL);
+ buffer.append("/BBox [");
+ buffer.append(llx + " ");
+ buffer.append(lly + " ");
+ buffer.append(urx + " ");
+ buffer.append(ury + "]" + EOL);
+ final AffineTransform transform = this.getUserSpaceTransform();
+ buffer.append("/Matrix ["
+ + transform.getScaleX()
+ + " 0 0 "
+ + transform.getScaleY() + " "
+ + transform.getTranslateX() + " "
+ + transform.getTranslateY() + "]"
+ + EOL);
+ buffer.append("/Resources " + doc.getResources().pdfReference(doc) + EOL);
+
+ /* Add any special entries that the subclasses might have. */
+ buffer.append(this.specialXFormDict(doc));
+ return buffer.toString();
+ }
+
+ /**
+ * Returns the bounding box dimensions, in form space, for this graphic.
+ * @return The bounding box for this graphic.
+ * @exception GraphicException For errors during parsing of the graphic content.
+ */
+ protected abstract BoundingBox getBoundingBox() throws GraphicException;
+
+ /**
+ * Returns any special entries that should be added to the XForm dictionary.
+ * @param doc The PDF Document.
+ * @return Special XForm dictionary entries.
+ */
+ protected abstract String specialXFormDict(PdfDocument4a doc);
+
+ /**
+ * Return the transformation that should be used to convert this form from
+ * form space to user space.
+ * @return The transformation to be used to convert this form to user space.
+ * @throws GraphicException For errors parsing the graphic.
+ */
+ protected abstract AffineTransform getUserSpaceTransform() throws GraphicException;
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfGraphicsState4a.java (from rev 12484, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfGraphicsState4a.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfGraphicsState4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfGraphicsState4a.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -0,0 +1,204 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.graphics;
+
+import org.foray.pdf.object.PdfColor4a;
+import org.foray.pdf.text.PdfTextState4a;
+
+import org.axsl.pdf.PdfColor;
+import org.axsl.pdf.PdfLineCapStyle;
+
+/**
+ * The PDF graphics state.
+ * Tracks the current state of various properties used to render content, such as colors and fonts.
+ * The PDF Reference distinguishes between graphics state parameters that are device-independent and those that are
+ * device-dependent.
+ * While rendering the PDF document, we care only about those that are device-independent, and therefore track only
+ * those in this class.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3."
+ */
+public class PdfGraphicsState4a {
+
+ /** The stroke color. */
+ private PdfColor strokeColor;
+
+ /** The "non-stroke" or "other" color. */
+ private PdfColor fillColor;
+
+ /** The text state. */
+ private PdfTextState4a textState = new PdfTextState4a();
+
+ /** The line cap style. */
+ private PdfLineCapStyle lineCapStyle;
+
+ /** The dash pattern. */
+ private PdfDashPattern4a dashPattern;
+
+ /**
+ * Create a PdfGraphicsState instance.
+ */
+ public PdfGraphicsState4a() {
+ reset();
+ }
+
+ /**
+ * Creates a new PdfGraphicsState instance, initilializing its values to those of an existing instance.
+ * @param existingState The instance whose values should be copied into the new instance.
+ */
+ public PdfGraphicsState4a(final PdfGraphicsState4a existingState) {
+ this.strokeColor = existingState.strokeColor;
+ this.fillColor = existingState.fillColor;
+ this.textState = new PdfTextState4a(this.textState);
+ this.lineCapStyle = existingState.lineCapStyle;
+ this.dashPattern = existingState.dashPattern;
+ }
+
+ /**
+ * Resets each property in the Graphics State to its initial state.
+ * The initial state values are documented in Table 4.2 in "PDF Reference, Sixth Edition (PDF Version 1.7), Section
+ * 4.3."
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3."
+ */
+ public void reset() {
+ this.strokeColor = PdfColor4a.BLACK;
+ this.fillColor = PdfColor4a.BLACK;
+ this.textState.reset();
+ this.lineCapStyle = PdfLineCapStyle.BUTT_CAP;
+ this.dashPattern = PdfDashPattern4a.SOLID_LINE;
+ }
+
+ /**
+ * Returns the stroke color.
+ * @return The stroke color.
+ */
+ public PdfColor getStrokeColor() {
+ return strokeColor;
+ }
+
+ /**
+ * Sets the stroke color.
+ * @param newStrokeColor The new stroke color.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getStrokeColor()
+ */
+ public boolean setStrokeColor(final PdfColor newStrokeColor) {
+ if (newStrokeColor == null) {
+ return false;
+ }
+ boolean anyChange = false;
+ if (! newStrokeColor.equals(this.strokeColor)) {
+ this.strokeColor = newStrokeColor;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Returns the non-stroke or "other" color.
+ * @return The non-stroke or other color.
+ */
+ public PdfColor getFillColor() {
+ return fillColor;
+ }
+
+ /**
+ * Sets the "non-stroke" or "other" or "fill" color.
+ * @param newFillColor The new non-stroke color.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getFillColor()
+ */
+ public boolean setFillColor(final PdfColor newFillColor) {
+ if (newFillColor == null) {
+ return false;
+ }
+ boolean anyChange = false;
+ if (! newFillColor.equals(this.fillColor)) {
+ this.fillColor = newFillColor;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Returns the text state.
+ * @return The text state.
+ */
+ public PdfTextState4a getTextState() {
+ return textState;
+ }
+
+ /**
+ * Returns the line cap style.
+ * @return The line cap style.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
+ */
+ public PdfLineCapStyle getLineCapStyle() {
+ return lineCapStyle;
+ }
+
+ /**
+ * Sets the line cap style.
+ * @param newLineCapStyle The new line cap style.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getLineCapStyle()
+ */
+ public boolean setLineCapStyle(final PdfLineCapStyle newLineCapStyle) {
+ boolean anyChange = false;
+ if (newLineCapStyle != this.lineCapStyle) {
+ this.lineCapStyle = newLineCapStyle;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+ /**
+ * Returns the dash pattern.
+ * @return The dash pattern.
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.3.2."
+ */
+ public PdfDashPattern4a getDashPattern() {
+ return dashPattern;
+ }
+
+ /**
+ * Sets the line dash pattern.
+ * @param newDashPattern The new dash pattern.
+ * @return True if and only if the Graphics State was changed by this operation.
+ * @see #getDashPattern()
+ */
+ public boolean setLineDashPattern(final PdfDashPattern4a newDashPattern) {
+ boolean anyChange = false;
+ if (! this.dashPattern.equals(newDashPattern)) {
+ this.dashPattern = newDashPattern;
+ anyChange = true;
+ }
+ return anyChange;
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfImageXobject.java (from rev 12482, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfImageXobject.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfImageXobject.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -0,0 +1,172 @@
+/*
+ * 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:
+ * Eric Dalquist
+ * Manuel Mall
+ */
+
+package org.foray.pdf.graphics;
+
+import org.foray.pdf.object.PdfColor4a;
+import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.object.PdfIccStream;
+
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.pdf.PdfException;
+
+import java.awt.Color;
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * 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 PdfXobject4a
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.8.4."
+ */
+public class PdfImageXobject extends PdfXobject4a {
+
+ /** The Graphic instance associated with this XObject. */
+ private Graphic graphic;
+
+ /** The ICC stream. */
+ private PdfIccStream pdfICCStream;
+
+ /**
+ * Create a sampled-image Xobject.
+ * @param doc The parent PDF document.
+ * @param graphic The graphic to be encapsulated.
+ * @throws GraphicException For errors getting the appropriate filter.
+ */
+ public PdfImageXobject(final PdfDocument4a doc, final Graphic graphic) throws GraphicException {
+ super(doc, graphic);
+ this.graphic = graphic;
+ final ColorSpace cs = getGraphic().getColorSpace();
+ if (getGraphic().getGraphicType() == Graphic.Type.JPEG
+ && cs instanceof ICC_ColorSpace) {
+ final ICC_ColorSpace iccCS = (ICC_ColorSpace) cs;
+ this.pdfICCStream = new PdfIccStream(iccCS);
+ try {
+ this.pdfICCStream.addDefaultFilters(doc);
+ } catch (final PdfException e) {
+ /* Ignore. Shouldn't happen. */
+ }
+ if (doc.getEncryption() != null) {
+ this.pdfICCStream.addEncryption(doc.getEncryption());
+ }
+ }
+ }
+
+ @Override
+ protected String xObjectSubtype() {
+ return "Image";
+ }
+
+ @Override
+ protected void xObjectContent(final PdfDocument4a doc) throws PdfException {
+ try {
+ if (getGraphic().getGraphicType() == Graphic.Type.JPEG
+ || getGraphic().getGraphicType() == Graphic.Type.TIFF) {
+ /* JPEG is natively compressed using DTD, so use its raw
+ * content.
+ * TIFF is currently presumed to be compressed natively also,
+ * and an appropriate filter has been added for that
+ * compression. */
+ this.write(getGraphic().getRawSamples());
+ } else {
+ this.write(getGraphic().getContent());
+ }
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+ }
+
+ @Override
+ protected String specialXObjectDictEntries(final PdfDocument4a doc) throws GraphicException {
+ int pixelWidth = 0;
+ int pixelHeight = 0;
+ int bitsPerPixel = 0;
+ ColorSpace cs = null;
+ boolean isTransparent = false;
+ Color transp = null;
+ pixelWidth = getGraphic().pixelWidth();
+ pixelHeight = getGraphic().pixelHeight();
+ bitsPerPixel = getGraphic().getBitsPerComponent();
+ cs = getGraphic().getColorSpace();
+ isTransparent = getGraphic().isTransparent();
+ transp = getGraphic().getTransparentColor();
+ final StringBuilder buffer = new StringBuilder();
+ // The width, in pixels (aka samples), *not* points.
+ buffer.append("/Width " + pixelWidth + EOL);
+ // The width, in pixels (aka samples), *not* points.
+ buffer.append("/Height " + pixelHeight + EOL);
+ buffer.append("/BitsPerComponent " + bitsPerPixel + EOL);
+ if (this.pdfICCStream != null) {
+ buffer.append("/ColorSpace [/ICCBased "
+ + this.pdfICCStream.pdfReference(doc) + "]" + EOL);
+ } else {
+ buffer.append("/ColorSpace /"
+ + PdfColor4a.getColorSpacePDFString(cs)
+ + EOL);
+ }
+ /* PhotoShop generates CMYK values that's inverse. */
+ if (cs.getType() == ColorSpace.TYPE_CMYK
+ && getGraphic().isInverted()) {
+ buffer.append("/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]" + EOL);
+ }
+ if (isTransparent) {
+ buffer.append("/Mask [" + transp.getRed() + " " + transp.getRed()
+ + " " + transp.getGreen() + " " + transp.getGreen()
+ + " " + transp.getBlue() + " " + transp.getBlue()
+ + "]" + EOL);
+ }
+ return buffer.toString();
+ }
+
+ @Override
+ public float getHorizontalScaling(
+ final Rectangle2D.Float contentRectangle) {
+ return contentRectangle.width;
+ }
+
+ @Override
+ public float getVerticalScaling(final Rectangle2D.Float contentRectangle) {
+ return contentRectangle.height;
+ }
+
+ @Override
+ public Graphic getGraphic() {
+ return this.graphic;
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPathPaint4a.java (from rev 12492, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPathPaint.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPathPaint4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPathPaint4a.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.graphics;
+
+import org.foray.pdf.type.PdfObject;
+
+import java.awt.color.ColorSpace;
+
+/**
+ * Abstract superclass for classes painting paths.
+ */
+public abstract class PdfPathPaint4a extends PdfObject
+ implements org.axsl.pdf.PdfPathPaint {
+
+ /** The color space for this paint. */
+ private ColorSpace colorSpace;
+
+ /**
+ * Sets the color space for this paint.
+ * @param theColorSpace The new color space.
+ */
+ public void setColorSpace(final ColorSpace theColorSpace) {
+ this.colorSpace = theColorSpace;
+ }
+
+ /**
+ * Return the color space for this paint.
+ * @return The color space.
+ */
+ public ColorSpace getColorSpace() {
+ return this.colorSpace;
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java (from rev 12498, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPattern.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfPattern4a.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -0,0 +1,287 @@
+/*
+ * Copyright 2004 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.graphics;
+
+import org.foray.common.ps.PsUtil;
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.object.PdfResources;
+import org.foray.pdf.object.PdfShading;
+
+import org.axsl.utility.sequence.ByteSequencePlus;
+
+import java.util.List;
+
+/**
+ * A PDF pattern.
+ */
+public class PdfPattern4a extends PdfPathPaint4a implements org.axsl.pdf.PdfPattern {
+
+ /** The resources associated with this pattern. */
+ private PdfResources resources = null;
+
+ /** Either one (1) for tiling, or two (2) for shading. (2) is the
+ * default. */
+ private int patternType = 2;
+
+ /** The number of the pattern. */
+ private int patternCount;
+
+ /** 1 for colored pattern, 2 for uncolored. */
+ private int paintType = 2;
+
+ /** 1 for constant spacing, 2 for no distortion, and 3 for fast
+ * rendering. */
+ private int tilingType = 1;
+
+ /** List of Doubles representing the Bounding box rectangle. */
+ private List<Double> bBox = null;
+
+ /** Horizontal spacing. */
+ private double xStep = -1;
+
+ /** Vertical spacing. */
+ private double yStep = -1;
+
+ /** The Shading object comprising the Type 2 pattern. */
+ private PdfShading shading = null;
+
+ /** List of Integers represetning the Extended unique Identifier. */
+ private List<Integer> xUID = null;
+
+ /**
+ * String representing the extended Graphics state.
+ * Probably will never be used like this.
+ */
+ private StringBuilder extGState = null;
+ /* TODO: Add a PDFExtGSState. */
+
+ /** List of Doubles representing the Transformation matrix. */
+ private List<Double> matrix = null;
+
+ /** The stream of a pattern. */
+ private StringBuilder patternDataStream = null;
+
+ /**
+ * Create a tiling pattern (type 1).
+ *
+ * @param doc The PDF document being built.
+ * @param theResources the resources associated with this pattern
+ * @param thePatternType the type of pattern, which is 1 for tiling.
+ * @param thePaintType 1 or 2, colored or uncolored.
+ * @param theTilingType 1, 2, or 3, constant spacing, no distortion, or
+ * faster tiling.
+ * @param theBBox List of Doubles: The pattern cell bounding box
+ * @param theXStep horizontal spacing
+ * @param theYStep vertical spacing
+ * @param theMatrix Optional List of Doubles transformation matrix
+ * @param theXUID Optional List of Integers that uniquely identify the
+ * pattern.
+ * @param thePatternDataStream The stream of pattern data to be tiled.
+ */
+ public PdfPattern4a(final PdfDocument4a doc, final PdfResources theResources,
+ final int thePatternType, final int thePaintType,
+ final int theTilingType, final List<Double> theBBox,
+ final double theXStep,
+ final double theYStep, final List<Double> theMatrix,
+ final List<Integer> theXUID,
+ final StringBuilder thePatternDataStream) {
+ this.patternCount = doc.registerPatternResource(this);
+ this.resources = theResources;
+ // This next parameter is implicit to all constructors, and is
+ // not directly passed.
+
+ this.patternType = 1; // thePatternType;
+ this.paintType = thePaintType;
+ this.tilingType = theTilingType;
+ this.bBox = theBBox;
+ this.xStep = theXStep;
+ this.yStep = theYStep;
+ this.matrix = theMatrix;
+ this.xUID = theXUID;
+ this.patternDataStream = thePatternDataStream;
+ }
+
+ /**
+ * Create a type 2 pattern (smooth shading).
+ * @param doc The PDF document being built.
+ * @param thePatternType the type of the pattern, which is 2, smooth shading
+ * @param theShading the PDF Shading object that comprises this pattern
+ * @param theXUID optional:the extended unique Identifier if used.
+ * @param theExtGState optional: the extended graphics state, if used.
+ * @param theMatrix Optional:List of Doubles that specify the matrix.
+ */
+ public PdfPattern4a(final PdfDocument4a doc, final int thePatternType,
+ final PdfShading theShading, final List<Integer> theXUID,
+ final StringBuilder theExtGState, final List<Double> theMatrix) {
+ this.patternCount = doc.registerPatternResource(this);
+ this.patternType = 2; // thePatternType;
+ this.shading = theShading;
+ this.xUID = theXUID;
+ /*
+ * This isn't really implemented, so it should always be null.
+ * I just don't want to have to add a new parameter once it is
+ * implemented.
+ */
+ this.extGState = theExtGState; // always null
+ this.matrix = theMatrix;
+ }
+
+ /**
+ * Get the name of the pattern.
+ * @return String representing the name of the pattern.
+ */
+ public String getName() {
+ return "Pa" + this.patternCount;
+ }
+
+ @Override
+ public String getSetterString(final boolean fillNotStroke) {
+ if (fillNotStroke) {
+ // fill but no stroke
+ return "/Pattern cs /" + this.getName() + " scn" + EOL;
+ }
+ // stroke (or border)
+ return "/Pattern CS /" + this.getName() + " SCN" + EOL;
+ }
+
+ /**
+ * represent as PDF. Whatever the FunctionType is, the correct
+ * representation spits out. The sets of required and optional
+ * attributes are different for each type, but if a required
+ * attribute's object was constructed as null, then no error
+ * is raised. Instead, the malformed PDF that was requested
+ * by the construction is dutifully output.
+ * This policy should be reviewed.
+ *
+ * @return the PDF string.
+ */
+ @Override
+ public ByteSequencePlus serialize(final PdfDocument4a doc) {
+ int vectorSize = 0;
+ int tempInt = 0;
+ final StringBuilder p = new StringBuilder();
+ p.append(this.pdfID() + EOL + "<<" + EOL + "/Type /Pattern" + EOL);
+
+ if (this.resources != null) {
+ p.append("/Resources " + this.resources.pdfReference(doc) + EOL);
+ }
+
+ p.append("/PatternType " + this.patternType + EOL);
+
+ if (this.patternType == 1) {
+ p.append("/PaintType " + this.paintType + EOL);
+ p.append("/TilingType " + this.tilingType + EOL);
+
+ if (this.bBox != null) {
+ vectorSize = this.bBox.size();
+ p.append("/BBox [ ");
+ for (tempInt = 0; tempInt < vectorSize; tempInt++) {
+ p.append(PsUtil.doubleOut(
+ this.bBox.get(tempInt)));
+ p.append(" ");
+ }
+ p.append("]" + EOL);
+ }
+ p.append("/XStep " + PsUtil.doubleOut(this.xStep) + EOL);
+ p.append("/YStep " + PsUtil.doubleOut(this.yStep) + EOL);
+
+ if (this.matrix != null) {
+ vectorSize = this.matrix.size();
+ p.append("/Matrix [ ");
+ for (tempInt = 0; tempInt < vectorSize; tempInt++) {
+ p.append(PsUtil.doubleOut(
+ this.matrix.get(tempInt)));
+ p.append(" ");
+ }
+ p.append("]" + EOL);
+ }
+
+ if (this.xUID != null) {
+ vectorSize = this.xUID.size();
+ p.append("/XUID [ ");
+ for (tempInt = 0; tempInt < vectorSize; tempInt++) {
+ p.append(this.xUID.get(tempInt) + " ");
+ }
+ p.append("]" + EOL);
+ }
+ // don't forget the length of the stream.
+ if (this.patternDataStream != null) {
+ p.append("/Length " + (this.patternDataStream.length() + 1)
+ + EOL);
+ }
+
+ } else {
+ // if (this.patternType ==2)
+ // Smooth Shading...
+ if (this.shading != null) {
+ p.append("/Shading " + this.shading.pdfReference(doc) + EOL);
+ }
+
+ if (this.xUID != null) {
+ vectorSize = this.xUID.size();
+ p.append("/XUID [ ");
+ for (tempInt = 0; tempInt < vectorSize; tempInt++) {
+ p.append(this.xUID.get(tempInt) + " ");
+ }
+ p.append("]" + EOL);
+ }
+
+ // will probably have to change this if it's used.
+ if (this.extGState
+ != null) {
+ p.append("/ExtGState " + this.extGState + EOL);
+ }
+
+ if (this.matrix != null) {
+ vectorSize = this.matrix.size();
+ p.append("/Matrix [ ");
+ for (tempInt = 0; tempInt < vectorSize; tempInt++) {
+ p.append(PsUtil.doubleOut(
+ this.matrix.get(tempInt)));
+ p.append(" ");
+ }
+ p.append("]" + EOL);
+ }
+ } // end of if patterntype =1...else 2.
+
+ p.append(">>" + EOL);
+
+ // stream representing the function
+ if (this.patternDataStream != null) {
+ p.append("stream" + EOL + this.patternDataStream + "" + EOL
+ + "endstream" + EOL);
+ }
+
+ p.append("endobj" + EOL);
+
+ return new ByteArray(p);
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformEps.java (from rev 12482, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXformEps.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformEps.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/graphics/PdfXformEps.java 2022-01-29 21:03:44 UTC (rev 12502)
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2007 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.pdf.graphics;
+
+import org.foray.common.data.BoundingBoxUtils;
+import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.object.PdfDocument4a;
+
+import org.axsl.graphic.EpsGraphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.ps.BoundingBox;
+import org.axsl.ps.PsException;
+import org.axsl.ps.PsInput;
+import org....
[truncated message content] |