[FOray-commit] SF.net SVN: foray:[12494] trunk/foray/foray-pdf/src
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-01-29 14:29:38
|
Revision: 12494
http://sourceforge.net/p/foray/code/12494
Author: victormote
Date: 2022-01-29 14:29:35 +0000 (Sat, 29 Jan 2022)
Log Message:
-----------
Move PDF common structures to new package.
Modified Paths:
--------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfParser.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDestinationNamed4a.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/PdfFontDescriptor.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfLink.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfOutlineItem4a.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/PdfPageLabel.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.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/PdfLiteralString.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/PdfParserTests.java
trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfArrayTests.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/
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/structure/package-info.java
Removed Paths:
-------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDate.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNameTree.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNumberTree.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRectangle.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfTextString.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfParser.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfParser.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/PdfParser.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -37,8 +37,8 @@
import org.foray.pdf.object.PdfGenericDictionary;
import org.foray.pdf.object.PdfGenericStream;
import org.foray.pdf.object.PdfObjectReference;
-import org.foray.pdf.object.PdfTextString;
import org.foray.pdf.object.PdfTrailer;
+import org.foray.pdf.structure.PdfTextString;
import org.foray.pdf.type.PdfArray;
import org.foray.pdf.type.PdfBoolean;
import org.foray.pdf.type.PdfDictionary;
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDate.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDate.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDate.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -1,96 +0,0 @@
-/*
- * Copyright 2005 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.object;
-
-import org.foray.pdf.type.PdfObject;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * Represents a Date object in PDF. Date is listed as a PDF Data Type in PDF
- * Reference, 3rd Edition, Table 3.22. The Date data type is discussed at
- * Section 3.8.2.
- *
- * <p>Dates are technically PDF strings, probably actually PDF text strings,
- * so it is tempting to make this class a subclass of PdfTextString. However,
- * since the output will always be ASCII characters (as far as we know), there
- * is currently no benefit to doing so.</p>
- */
-public class PdfDate extends PdfObject {
-
- /** The number of chars used to represent the time zone hours in a Java
- * Date. */
- private static final int TIMEZONE_HOURS_SIZE = 3;
-
- /** The number of chars used to represent the time zone minutes in a Java
- * Date. */
- private static final int TIMEZONE_MINUTES_SIZE = 2;
-
- /** The encapsulated Date instance. */
- private Date date;
-
- /**
- * Create a PdfDate instance.
- * @param date The Date to be encapsulated.
- */
- public PdfDate(final Date date) {
- this.date = date;
- }
-
- @Override
- public String toPDF(final PdfDocument4a doc) {
- if (this.date == null) {
- return new String();
- }
- final StringBuilder buffer = new StringBuilder();
- buffer.append("(D:");
- final SimpleDateFormat formatter = new SimpleDateFormat(
- "yyyyMMddHHmmss");
- buffer.append(formatter.format(this.date));
- formatter.applyPattern("Z");
- final String tzOffset = formatter.format(this.date);
- buffer.append(tzOffset.substring(0, PdfDate.TIMEZONE_HOURS_SIZE));
- buffer.append("'");
- buffer.append(tzOffset.substring(PdfDate.TIMEZONE_HOURS_SIZE,
- PdfDate.TIMEZONE_HOURS_SIZE + PdfDate.TIMEZONE_MINUTES_SIZE));
- buffer.append("'");
- buffer.append(")");
- return buffer.toString();
- }
-
- /**
- * Returns the wrapped Date instance.
- * @return The wrapped Date instance.
- */
- public Date getValue() {
- return this.date;
- }
-
-}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDestinationNamed4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDestinationNamed4a.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDestinationNamed4a.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -28,6 +28,7 @@
package org.foray.pdf.object;
+import org.foray.pdf.structure.PdfTextString;
import org.foray.pdf.type.PdfObject;
import org.axsl.pdf.PdfDestinationNamed;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFont4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFont4a.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFont4a.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -29,6 +29,7 @@
package org.foray.pdf.object;
import org.foray.common.WellKnownConstants;
+import org.foray.pdf.structure.PdfRectangle;
import org.foray.pdf.type.PdfArray;
import org.foray.pdf.type.PdfObject;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFontDescriptor.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFontDescriptor.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFontDescriptor.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -29,6 +29,7 @@
package org.foray.pdf.object;
import org.foray.common.WellKnownConstants;
+import org.foray.pdf.structure.PdfRectangle;
import org.foray.pdf.type.PdfObject;
import org.axsl.font.Font;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfLink.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfLink.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfLink.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -29,6 +29,7 @@
package org.foray.pdf.object;
import org.foray.common.WellKnownConstants;
+import org.foray.pdf.structure.PdfTextString;
import java.awt.geom.Rectangle2D;
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNameTree.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNameTree.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNameTree.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -1,82 +0,0 @@
-/*
- * Copyright 2006 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.pdf.object;
-
-import org.foray.pdf.type.PdfObject;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A PDF Name Tree.
- * @param <T> The type of value mapped in this name tree.
- * @see "PDF Reference, Sixth Edition, (PDF version 1.7) Section 3.8.5."
- */
-public class PdfNameTree<T extends PdfObject> extends PdfObject {
- /* TODO: This currently handles a tree with only one level. */
-
- /** This name tree's map. */
- private Map<String, T> names = new HashMap<String, T>();
-
- @Override
- public String toPDF(final PdfDocument4a doc) {
- final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
- p.append("<<" + EOL);
- p.append("/Names [" + EOL);
- for (Map.Entry<String, T> entry : this.names.entrySet()) {
- final PdfObject pdfObject = entry.getValue();
- p.append("(" + entry.getKey() + ") " + pdfObject.pdfReference(doc)
- + EOL);
- }
- p.append("]" + EOL);
- p.append(">>" + EOL);
- p.append("endobj" + EOL);
- return p.toString();
- }
-
- /**
- * Add a mapping to this name tree.
- * @param key The key to be added.
- * @param value The value to be added.
- */
- public void add(final String key, final T value) {
- this.names.put(key, value);
- }
-
- /**
- * Returns a mapped item from its key.
- * @param key The key.
- * @return The mapped item, or null if the key does not exist in this tree.
- */
- public T get(final String key) {
- return this.names.get(key);
- }
-
-}
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNumberTree.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNumberTree.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNumberTree.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -1,81 +0,0 @@
-/*
- * Copyright 2006 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-package org.foray.pdf.object;
-
-import org.foray.pdf.type.PdfObject;
-
-import java.util.Map;
-import java.util.TreeMap;
-
-/**
- * A PDF Number Tree.
- * @param <T> The type of value mapped in this number tree.
- * @see "PDF Reference, Sixth Edition (PDF version 1.7), Section 3.8.6."
- */
-public class PdfNumberTree<T extends PdfObject> extends PdfObject {
- /* TODO: This currently handles a tree with only one level. */
-
- /** This number tree's map. */
- private Map<Integer, T> nums = new TreeMap<Integer, T>();
-
- @Override
- public String toPDF(final PdfDocument4a doc) {
- final StringBuilder p = new StringBuilder();
- p.append(this.pdfID() + EOL);
- p.append("<<" + EOL);
- p.append("/Nums [" + EOL);
- for (Map.Entry<Integer, T> entry : this.nums.entrySet()) {
- final PdfObject pdfObject = entry.getValue();
- p.append(entry.getKey() + " " + pdfObject.pdfReference(doc) + EOL);
- }
- p.append("]" + EOL);
- p.append(">>" + EOL);
- p.append("endobj" + EOL);
- return p.toString();
- }
-
- /**
- * Add a mapping to this number tree.
- * @param key The key to be added.
- * @param value The value to be added.
- */
- public void add(final Integer key, final T value) {
- this.nums.put(key, value);
- }
-
- /**
- * Returns a mapped item from its key.
- * @param key The key.
- * @return The mapped item, or null if the key does not exist in this tree.
- */
- public T get(final Integer key) {
- return this.nums.get(key);
- }
-
-}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfOutlineItem4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfOutlineItem4a.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfOutlineItem4a.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -32,6 +32,8 @@
*/
package org.foray.pdf.object;
+import org.foray.pdf.structure.PdfTextString;
+
import org.axsl.pdf.PdfDestination;
import org.axsl.pdf.PdfOutlineItem;
import org.axsl.pdf.PdfOutlineTarget;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -28,6 +28,7 @@
package org.foray.pdf.object;
+import org.foray.pdf.structure.PdfNameTree;
import org.foray.pdf.type.PdfObject;
import org.axsl.pdf.PdfDestination;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPageLabel.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPageLabel.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPageLabel.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -28,6 +28,7 @@
package org.foray.pdf.object;
+import org.foray.pdf.structure.PdfTextString;
import org.foray.pdf.type.PdfObject;
import org.axsl.pdf.PdfPageLabelStyle;
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRectangle.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRectangle.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRectangle.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -1,116 +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.object;
-
-import org.axsl.ps.BoundingBox;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * A PDF rectangle.
- * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.8.4."
- */
-public class PdfRectangle {
-
- /** Lower left x coordinate. */
- private int llx;
-
- /** Lower left y coordinate. */
- private int lly;
-
- /** Upper right x coordinate. */
- private int urx;
-
- /** Upper right y coordinate. */
- private int ury;
-
- /**
- * Create a rectangle from its coordinates.
- * @param llx Lower left x coordinate.
- * @param lly Lower left y coordinate.
- * @param urx Upper right x coordinate.
- * @param ury Upper right y coordinate.
- */
- public PdfRectangle(final int llx, final int lly, final int urx,
- final int ury) {
- this.llx = llx;
- this.lly = lly;
- this.urx = urx;
- this.ury = ury;
- }
-
- /**
- * Create a rectangle from an array of four values.
- * @param array values in the order llx, lly, urx, ury
- */
- public PdfRectangle(final int[] array) {
- int index = 0;
- this.llx = array[index];
- index ++;
- this.lly = array[index];
- index ++;
- this.urx = array[index];
- index ++;
- this.ury = array[index];
- }
-
- /**
- * Create a rectangle from a bounding box.
- * @param bBox A bounding box.
- */
- public PdfRectangle(final BoundingBox bBox) {
- this.llx = bBox.getCoordinateAsInt(BoundingBox.LOWER_LEFT_X_INDEX);
- this.lly = bBox.getCoordinateAsInt(BoundingBox.LOWER_LEFT_Y_INDEX);
- this.urx = bBox.getCoordinateAsInt(BoundingBox.UPPER_RIGHT_X_INDEX);
- this.ury = bBox.getCoordinateAsInt(BoundingBox.UPPER_RIGHT_Y_INDEX);
- }
-
- /**
- * Produce the PDF representation for the object.
- * @return the PDF
- */
- public byte[] toPDF() {
- try {
- return toPDFString().getBytes(PdfDocument4a.ENCODING);
- } catch (final UnsupportedEncodingException ue) {
- return toPDFString().getBytes();
- }
- }
-
- /**
- * Returns the description of the rectangle suitable for embedding in the
- * PDF document.
- * @return The rectangle description, for PDF.
- */
- public String toPDFString() {
- return new String(" [" + this.llx + " " + this.lly + " "
- + this.urx + " " + this.ury + "] ");
- }
-
-}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRoot.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -30,6 +30,8 @@
import org.foray.common.primitive.StringUtils;
import org.foray.pdf.PdfConstants;
+import org.foray.pdf.structure.PdfNameTree;
+import org.foray.pdf.structure.PdfNumberTree;
import org.foray.pdf.type.PdfDictionary;
import java.util.List;
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfTextString.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfTextString.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfTextString.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -1,208 +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.object;
-
-import org.foray.common.WellKnownConstants;
-import org.foray.common.sequence.ByteSequenceChars;
-import org.foray.pdf.type.PdfLiteralString;
-import org.foray.pdf.type.PdfObject;
-
-import org.axsl.utility.sequence.ByteSequence;
-
-/**
- * A PDF Text String.
- * Text-strings are used in such PDF concepts as bookmarks, text annotations, etc., which do not have (or need) control
- * over fonts, layout, etc.
- * For string objects used in PDF content streams, see {@link PdfLiteralString}.
- * @see PdfLiteralString
- * @see "PDF Reference, 2nd Edition (PDF Version 1.3), Section 3.8.1."
- * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.8.1."
- */
-public class PdfTextString extends PdfObject {
-
- /** This char is returned when a Unicode character cannot be encoded using
- * the PDFDocEncoding. */
- public static final char INVALID_PDF_DOC_ENCODING = 0xffff;
-
- /** Constant used to mask the hi-order bits in a multibyte character. */
- private static final int HI_MASK = WellKnownConstants.MAX_8_BIT_UNSIGNED_INT
- << WellKnownConstants.SHIFT_1_BYTE;
-
- /** The encapsulated String. */
- private ByteSequence theSequence;
-
- /**
- * Constructor.
- * @param string The encapsulated String.
- */
- public PdfTextString(final ByteSequence string) {
- this.theSequence = string;
- }
-
- /**
- * Constructor.
- * @param sequence The encapsulated character sequence.
- * @throws NullPointerException If {@code sequence} is null.
- */
- public PdfTextString(final CharSequence sequence) {
- if (sequence == null) {
- throw new NullPointerException("The CharSequence cannot be null.");
- }
- this.theSequence = new ByteSequenceChars(sequence);
- }
-
- /**
- * {@inheritDoc}
- * Convert this.theString to valid content for a PDF String Object.
- * See PDF Reference, 2nd edition, Section 3.2.3 for general information
- * on String objects, including how to add non-ASCII characters.
- * See Section 3.8.1 for information on the Unicode byte markers that must
- * be present for Text Strings that are encoded in Unicode (as opposed to
- * PDFDocEncoding).
- */
- @Override
- public String toPDF(final PdfDocument4a doc) {
- if (this.theSequence == null) {
- return new String();
- }
- final StringBuilder buffer = new StringBuilder();
- buffer.append("(");
- // Since it is more readable, try to use the PDFDocEncoding.
- final String pdfDoc = unicodeToPDFDocEncoding(this.theSequence);
- if (pdfDoc != null) {
- buffer.append(pdfDoc);
- } else {
- buffer.append(toPDFUnicode());
- }
- buffer.append(")");
- return buffer.toString();
- }
-
- @Override
- public String toString() {
- return this.theSequence.toString();
- }
-
- /**
- * Converts the encapsulated String to its PDF Unicode equivalent.
- * @return The PDF Unicode representation of the encapsulated String.
- */
- private String toPDFUnicode() {
- final StringBuilder result = new StringBuilder();
- // byte order marker (0xfeff)
- result.append("\\376\\377");
-
- /* @TODO: Handle different ByteSequence types better. */
- final String theString = this.theSequence.toString();
- for (int i = 0; i < theString.length(); i++) {
- final char ch = theString.charAt(i);
- final int high = (ch & PdfTextString.HI_MASK)
- >>> WellKnownConstants.SHIFT_1_BYTE;
- final int low = ch & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT;
- result.append("\\");
- result.append(Integer.toOctalString(high));
- result.append("\\");
- result.append(Integer.toOctalString(low));
- }
- return result.toString();
- }
-
- /**
- * Converts a String from Unicode to PDFDocEncoding, if possible.
- * @param unicodeSequence The {@link String} to be converted.
- * @return The converted String, or null if unicodeString contains one or
- * more chars that cannot be converted to PDFDocEncoding.
- */
- public static String unicodeToPDFDocEncoding(final ByteSequence unicodeSequence) {
- /* @TODO: Handle different types of ByteSequences better. */
- final String unicodeString = unicodeSequence.toString();
- final StringBuilder pdfDocString = new StringBuilder(unicodeString);
- for (int i = 0; i < unicodeString.length(); i++) {
- final char unicodeChar = unicodeString.charAt(i);
- final char pdfDocChar = unicodeToPDFDocEncoding(unicodeChar);
- if (pdfDocChar == PdfTextString.INVALID_PDF_DOC_ENCODING) {
- return null;
- }
- if (unicodeChar != pdfDocChar) {
- pdfDocString.setCharAt(i, pdfDocChar);
- }
- }
- return pdfDocString.toString();
- }
-
- /**
- * Converts a Unicode character to its PDFDocEncoding equivalent, if
- * possible.
- * @param unicodeChar The Unicode character to be converted.
- * @return The PDFDocEncoding equivalent of #unicodeChar if possible,
- * or #INVALID_PDF_DOC_ENCODING if it cannot be converted.
- */
- public static char unicodeToPDFDocEncoding(final char unicodeChar) {
- /*
- * This may not be right, but I am pretty sure that the ASCII chars
- * are the same.
- */
- if (unicodeChar >= ' '
- && unicodeChar <= WellKnownConstants.MAX_8_BIT_UNSIGNED_INT) {
- return unicodeChar;
- }
- /*
- * TODO: The remaining items are not complete.
- */
- switch (unicodeChar) {
- case '\u00C1': return '\u00C1'; //Aacute
- case '\u00C6': return '\u00C6'; //AE
- }
- return PdfTextString.INVALID_PDF_DOC_ENCODING;
- }
-
- /**
- * Indicates whether this String has any content.
- * @return True if and only if this String has no content.
- */
- public boolean isEmpty() {
- if (this.theSequence == null) {
- return true;
- }
- return this.theSequence.length() < 1;
- }
-
- /**
- * Returns the length of this string.
- * @return The number of bytes in this sequence.
- */
- public int length() {
- return this.theSequence.length();
- }
-
- public ByteSequence getValue() {
- return this.theSequence;
- }
-
-}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java (from rev 12492, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDate.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfDate.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2005 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.structure;
+
+import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.type.PdfObject;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Represents a Date object in PDF. Date is listed as a PDF Data Type in PDF
+ * Reference, 3rd Edition, Table 3.22. The Date data type is discussed at
+ * Section 3.8.2.
+ *
+ * <p>Dates are technically PDF strings, probably actually PDF text strings,
+ * so it is tempting to make this class a subclass of PdfTextString. However,
+ * since the output will always be ASCII characters (as far as we know), there
+ * is currently no benefit to doing so.</p>
+ */
+public class PdfDate extends PdfObject {
+
+ /** The number of chars used to represent the time zone hours in a Java
+ * Date. */
+ private static final int TIMEZONE_HOURS_SIZE = 3;
+
+ /** The number of chars used to represent the time zone minutes in a Java
+ * Date. */
+ private static final int TIMEZONE_MINUTES_SIZE = 2;
+
+ /** The encapsulated Date instance. */
+ private Date date;
+
+ /**
+ * Create a PdfDate instance.
+ * @param date The Date to be encapsulated.
+ */
+ public PdfDate(final Date date) {
+ this.date = date;
+ }
+
+ @Override
+ public String toPDF(final PdfDocument4a doc) {
+ if (this.date == null) {
+ return new String();
+ }
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append("(D:");
+ final SimpleDateFormat formatter = new SimpleDateFormat(
+ "yyyyMMddHHmmss");
+ buffer.append(formatter.format(this.date));
+ formatter.applyPattern("Z");
+ final String tzOffset = formatter.format(this.date);
+ buffer.append(tzOffset.substring(0, PdfDate.TIMEZONE_HOURS_SIZE));
+ buffer.append("'");
+ buffer.append(tzOffset.substring(PdfDate.TIMEZONE_HOURS_SIZE,
+ PdfDate.TIMEZONE_HOURS_SIZE + PdfDate.TIMEZONE_MINUTES_SIZE));
+ buffer.append("'");
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+ /**
+ * Returns the wrapped Date instance.
+ * @return The wrapped Date instance.
+ */
+ public Date getValue() {
+ return this.date;
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java (from rev 12492, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNameTree.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNameTree.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2006 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.structure;
+
+import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.type.PdfObject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A PDF Name Tree.
+ * @param <T> The type of value mapped in this name tree.
+ * @see "PDF Reference, Sixth Edition, (PDF version 1.7) Section 3.8.5."
+ */
+public class PdfNameTree<T extends PdfObject> extends PdfObject {
+ /* TODO: This currently handles a tree with only one level. */
+
+ /** This name tree's map. */
+ private Map<String, T> names = new HashMap<String, T>();
+
+ @Override
+ public String toPDF(final PdfDocument4a doc) {
+ final StringBuilder p = new StringBuilder();
+ p.append(this.pdfID() + EOL);
+ p.append("<<" + EOL);
+ p.append("/Names [" + EOL);
+ for (Map.Entry<String, T> entry : this.names.entrySet()) {
+ final PdfObject pdfObject = entry.getValue();
+ p.append("(" + entry.getKey() + ") " + pdfObject.pdfReference(doc)
+ + EOL);
+ }
+ p.append("]" + EOL);
+ p.append(">>" + EOL);
+ p.append("endobj" + EOL);
+ return p.toString();
+ }
+
+ /**
+ * Add a mapping to this name tree.
+ * @param key The key to be added.
+ * @param value The value to be added.
+ */
+ public void add(final String key, final T value) {
+ this.names.put(key, value);
+ }
+
+ /**
+ * Returns a mapped item from its key.
+ * @param key The key.
+ * @return The mapped item, or null if the key does not exist in this tree.
+ */
+ public T get(final String key) {
+ return this.names.get(key);
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java (from rev 12492, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfNumberTree.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfNumberTree.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2006 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.pdf.structure;
+
+import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.type.PdfObject;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * A PDF Number Tree.
+ * @param <T> The type of value mapped in this number tree.
+ * @see "PDF Reference, Sixth Edition (PDF version 1.7), Section 3.8.6."
+ */
+public class PdfNumberTree<T extends PdfObject> extends PdfObject {
+ /* TODO: This currently handles a tree with only one level. */
+
+ /** This number tree's map. */
+ private Map<Integer, T> nums = new TreeMap<Integer, T>();
+
+ @Override
+ public String toPDF(final PdfDocument4a doc) {
+ final StringBuilder p = new StringBuilder();
+ p.append(this.pdfID() + EOL);
+ p.append("<<" + EOL);
+ p.append("/Nums [" + EOL);
+ for (Map.Entry<Integer, T> entry : this.nums.entrySet()) {
+ final PdfObject pdfObject = entry.getValue();
+ p.append(entry.getKey() + " " + pdfObject.pdfReference(doc) + EOL);
+ }
+ p.append("]" + EOL);
+ p.append(">>" + EOL);
+ p.append("endobj" + EOL);
+ return p.toString();
+ }
+
+ /**
+ * Add a mapping to this number tree.
+ * @param key The key to be added.
+ * @param value The value to be added.
+ */
+ public void add(final Integer key, final T value) {
+ this.nums.put(key, value);
+ }
+
+ /**
+ * Returns a mapped item from its key.
+ * @param key The key.
+ * @return The mapped item, or null if the key does not exist in this tree.
+ */
+ public T get(final Integer key) {
+ return this.nums.get(key);
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfRectangle.java (from rev 12487, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfRectangle.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfRectangle.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfRectangle.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -0,0 +1,118 @@
+/*
+ * 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.structure;
+
+import org.foray.pdf.object.PdfDocument4a;
+
+import org.axsl.ps.BoundingBox;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * A PDF rectangle.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.8.4."
+ */
+public class PdfRectangle {
+
+ /** Lower left x coordinate. */
+ private int llx;
+
+ /** Lower left y coordinate. */
+ private int lly;
+
+ /** Upper right x coordinate. */
+ private int urx;
+
+ /** Upper right y coordinate. */
+ private int ury;
+
+ /**
+ * Create a rectangle from its coordinates.
+ * @param llx Lower left x coordinate.
+ * @param lly Lower left y coordinate.
+ * @param urx Upper right x coordinate.
+ * @param ury Upper right y coordinate.
+ */
+ public PdfRectangle(final int llx, final int lly, final int urx,
+ final int ury) {
+ this.llx = llx;
+ this.lly = lly;
+ this.urx = urx;
+ this.ury = ury;
+ }
+
+ /**
+ * Create a rectangle from an array of four values.
+ * @param array values in the order llx, lly, urx, ury
+ */
+ public PdfRectangle(final int[] array) {
+ int index = 0;
+ this.llx = array[index];
+ index ++;
+ this.lly = array[index];
+ index ++;
+ this.urx = array[index];
+ index ++;
+ this.ury = array[index];
+ }
+
+ /**
+ * Create a rectangle from a bounding box.
+ * @param bBox A bounding box.
+ */
+ public PdfRectangle(final BoundingBox bBox) {
+ this.llx = bBox.getCoordinateAsInt(BoundingBox.LOWER_LEFT_X_INDEX);
+ this.lly = bBox.getCoordinateAsInt(BoundingBox.LOWER_LEFT_Y_INDEX);
+ this.urx = bBox.getCoordinateAsInt(BoundingBox.UPPER_RIGHT_X_INDEX);
+ this.ury = bBox.getCoordinateAsInt(BoundingBox.UPPER_RIGHT_Y_INDEX);
+ }
+
+ /**
+ * Produce the PDF representation for the object.
+ * @return the PDF
+ */
+ public byte[] toPDF() {
+ try {
+ return toPDFString().getBytes(PdfDocument4a.ENCODING);
+ } catch (final UnsupportedEncodingException ue) {
+ return toPDFString().getBytes();
+ }
+ }
+
+ /**
+ * Returns the description of the rectangle suitable for embedding in the
+ * PDF document.
+ * @return The rectangle description, for PDF.
+ */
+ public String toPDFString() {
+ return new String(" [" + this.llx + " " + this.lly + " "
+ + this.urx + " " + this.ury + "] ");
+ }
+
+}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java (from rev 12493, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfTextString.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/PdfTextString.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -0,0 +1,209 @@
+/*
+ * 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.structure;
+
+import org.foray.common.WellKnownConstants;
+import org.foray.common.sequence.ByteSequenceChars;
+import org.foray.pdf.object.PdfDocument4a;
+import org.foray.pdf.type.PdfLiteralString;
+import org.foray.pdf.type.PdfObject;
+
+import org.axsl.utility.sequence.ByteSequence;
+
+/**
+ * A PDF Text String.
+ * Text-strings are used in such PDF concepts as bookmarks, text annotations, etc., which do not have (or need) control
+ * over fonts, layout, etc.
+ * For string objects used in PDF content streams, see {@link PdfLiteralString}.
+ * @see PdfLiteralString
+ * @see "PDF Reference, 2nd Edition (PDF Version 1.3), Section 3.8.1."
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.8.1."
+ */
+public class PdfTextString extends PdfObject {
+
+ /** This char is returned when a Unicode character cannot be encoded using
+ * the PDFDocEncoding. */
+ public static final char INVALID_PDF_DOC_ENCODING = 0xffff;
+
+ /** Constant used to mask the hi-order bits in a multibyte character. */
+ private static final int HI_MASK = WellKnownConstants.MAX_8_BIT_UNSIGNED_INT
+ << WellKnownConstants.SHIFT_1_BYTE;
+
+ /** The encapsulated String. */
+ private ByteSequence theSequence;
+
+ /**
+ * Constructor.
+ * @param string The encapsulated String.
+ */
+ public PdfTextString(final ByteSequence string) {
+ this.theSequence = string;
+ }
+
+ /**
+ * Constructor.
+ * @param sequence The encapsulated character sequence.
+ * @throws NullPointerException If {@code sequence} is null.
+ */
+ public PdfTextString(final CharSequence sequence) {
+ if (sequence == null) {
+ throw new NullPointerException("The CharSequence cannot be null.");
+ }
+ this.theSequence = new ByteSequenceChars(sequence);
+ }
+
+ /**
+ * {@inheritDoc}
+ * Convert this.theString to valid content for a PDF String Object.
+ * See PDF Reference, 2nd edition, Section 3.2.3 for general information
+ * on String objects, including how to add non-ASCII characters.
+ * See Section 3.8.1 for information on the Unicode byte markers that must
+ * be present for Text Strings that are encoded in Unicode (as opposed to
+ * PDFDocEncoding).
+ */
+ @Override
+ public String toPDF(final PdfDocument4a doc) {
+ if (this.theSequence == null) {
+ return new String();
+ }
+ final StringBuilder buffer = new StringBuilder();
+ buffer.append("(");
+ // Since it is more readable, try to use the PDFDocEncoding.
+ final String pdfDoc = unicodeToPDFDocEncoding(this.theSequence);
+ if (pdfDoc != null) {
+ buffer.append(pdfDoc);
+ } else {
+ buffer.append(toPDFUnicode());
+ }
+ buffer.append(")");
+ return buffer.toString();
+ }
+
+ @Override
+ public String toString() {
+ return this.theSequence.toString();
+ }
+
+ /**
+ * Converts the encapsulated String to its PDF Unicode equivalent.
+ * @return The PDF Unicode representation of the encapsulated String.
+ */
+ private String toPDFUnicode() {
+ final StringBuilder result = new StringBuilder();
+ // byte order marker (0xfeff)
+ result.append("\\376\\377");
+
+ /* @TODO: Handle different ByteSequence types better. */
+ final String theString = this.theSequence.toString();
+ for (int i = 0; i < theString.length(); i++) {
+ final char ch = theString.charAt(i);
+ final int high = (ch & PdfTextString.HI_MASK)
+ >>> WellKnownConstants.SHIFT_1_BYTE;
+ final int low = ch & WellKnownConstants.MAX_8_BIT_UNSIGNED_INT;
+ result.append("\\");
+ result.append(Integer.toOctalString(high));
+ result.append("\\");
+ result.append(Integer.toOctalString(low));
+ }
+ return result.toString();
+ }
+
+ /**
+ * Converts a String from Unicode to PDFDocEncoding, if possible.
+ * @param unicodeSequence The {@link String} to be converted.
+ * @return The converted String, or null if unicodeString contains one or
+ * more chars that cannot be converted to PDFDocEncoding.
+ */
+ public static String unicodeToPDFDocEncoding(final ByteSequence unicodeSequence) {
+ /* @TODO: Handle different types of ByteSequences better. */
+ final String unicodeString = unicodeSequence.toString();
+ final StringBuilder pdfDocString = new StringBuilder(unicodeString);
+ for (int i = 0; i < unicodeString.length(); i++) {
+ final char unicodeChar = unicodeString.charAt(i);
+ final char pdfDocChar = unicodeToPDFDocEncoding(unicodeChar);
+ if (pdfDocChar == PdfTextString.INVALID_PDF_DOC_ENCODING) {
+ return null;
+ }
+ if (unicodeChar != pdfDocChar) {
+ pdfDocString.setCharAt(i, pdfDocChar);
+ }
+ }
+ return pdfDocString.toString();
+ }
+
+ /**
+ * Converts a Unicode character to its PDFDocEncoding equivalent, if
+ * possible.
+ * @param unicodeChar The Unicode character to be converted.
+ * @return The PDFDocEncoding equivalent of #unicodeChar if possible,
+ * or #INVALID_PDF_DOC_ENCODING if it cannot be converted.
+ */
+ public static char unicodeToPDFDocEncoding(final char unicodeChar) {
+ /*
+ * This may not be right, but I am pretty sure that the ASCII chars
+ * are the same.
+ */
+ if (unicodeChar >= ' '
+ && unicodeChar <= WellKnownConstants.MAX_8_BIT_UNSIGNED_INT) {
+ return unicodeChar;
+ }
+ /*
+ * TODO: The remaining items are not complete.
+ */
+ switch (unicodeChar) {
+ case '\u00C1': return '\u00C1'; //Aacute
+ case '\u00C6': return '\u00C6'; //AE
+ }
+ return PdfTextString.INVALID_PDF_DOC_ENCODING;
+ }
+
+ /**
+ * Indicates whether this String has any content.
+ * @return True if and only if this String has no content.
+ */
+ public boolean isEmpty() {
+ if (this.theSequence == null) {
+ return true;
+ }
+ return this.theSequence.length() < 1;
+ }
+
+ /**
+ * Returns the length of this string.
+ * @return The number of bytes in this sequence.
+ */
+ public int length() {
+ return this.theSequence.length();
+ }
+
+ public ByteSequence getValue() {
+ return this.theSequence;
+ }
+
+}
Added: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/package-info.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/package-info.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/package-info.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -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 representing the PDF common data structures.
+ * @see "PDF Reference, 6th Edition (PDF Version 1.7), Section 3.8."
+ */
+package org.foray.pdf.structure;
Property changes on: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/structure/package-info.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/type/PdfArray.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfArray.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -30,10 +30,10 @@
import org.foray.common.sequence.ByteArrayBuilder;
import org.foray.pdf.PdfConstants;
-import org.foray.pdf.object.PdfDate;
import org.foray.pdf.object.PdfDocument4a;
import org.foray.pdf.object.PdfObjectReference;
-import org.foray.pdf.object.PdfTextString;
+import org.foray.pdf.structure.PdfDate;
+import org.foray.pdf.structure.PdfTextString;
import java.math.BigDecimal;
import java.util.ArrayList;
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 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfDictionary.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -30,11 +30,11 @@
import org.foray.common.primitive.StringUtils;
import org.foray.pdf.PdfConstants;
-import org.foray.pdf.object.PdfDate;
import org.foray.pdf.object.PdfDocument4a;
import org.foray.pdf.object.PdfObjectReference;
-import org.foray.pdf.object.PdfTextString;
import org.foray.pdf.object.PdfTrailer;
+import org.foray.pdf.structure.PdfDate;
+import org.foray.pdf.structure.PdfTextString;
import java.math.BigDecimal;
import java.util.ArrayList;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfLiteralString.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfLiteralString.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/type/PdfLiteralString.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -29,7 +29,7 @@
package org.foray.pdf.type;
import org.foray.pdf.object.PdfDocument4a;
-import org.foray.pdf.object.PdfTextString;
+import org.foray.pdf.structure.PdfTextString;
import org.axsl.font.FontContext;
import org.axsl.orthography.Orthography;
Modified: trunk/foray/foray-pdf/src/test/java/org/foray/pdf/PdfParserTests.java
===================================================================
--- trunk/foray/foray-pdf/src/test/java/org/foray/pdf/PdfParserTests.java 2022-01-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/PdfParserTests.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -31,7 +31,7 @@
import org.foray.common.data.ByteSequenceTokenizer;
import org.foray.common.sequence.ByteArray;
import org.foray.pdf.object.PdfObjectReference;
-import org.foray.pdf.object.PdfTextString;
+import org.foray.pdf.structure.PdfTextString;
import org.foray.pdf.type.PdfArray;
import org.foray.pdf.type.PdfDictionary;
import org.foray.pdf.type.PdfHexString;
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-29 13:13:23 UTC (rev 12493)
+++ trunk/foray/foray-pdf/src/test/java/org/foray/pdf/object/PdfArrayTests.java 2022-01-29 14:29:35 UTC (rev 12494)
@@ -29,6 +29,7 @@
package org.foray.pdf.object;
import org.foray.common.sequence.ByteArray;
+import org.foray.pdf.structure.PdfTextString;
import org.foray.pdf.type.PdfArray;
import org.foray.pdf.type.PdfBoolean;
import org.foray.pdf.type.PdfName;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|