Revision: 11835
http://sourceforge.net/p/foray/code/11835
Author: victormote
Date: 2021-01-19 23:29:24 +0000 (Tue, 19 Jan 2021)
Log Message:
-----------
Rename class in anticipation of same-named interface to be created in aXSL.
Modified Paths:
--------------
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/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/PdfResources.java
Added Paths:
-----------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
Removed Paths:
-------------
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -280,12 +280,12 @@
final Rectangle2D.Float contentRectangle,
final Rectangle2D.Float clipRectangle,
final FontConsumer fontConsumer, final boolean strokeText) throws PdfException {
- final PdfXobject xObject;
+ final PdfXobject4a xObject;
try {
if (strokeText) {
- xObject = PdfXobject.makeXObject(doc, image, null);
+ xObject = PdfXobject4a.makeXObject(doc, image, null);
} else {
- xObject = PdfXobject.makeXObject(doc, image, fontConsumer);
+ xObject = PdfXobject4a.makeXObject(doc, image, fontConsumer);
}
} catch (final GraphicException e) {
throw new PdfException(e);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -131,8 +131,8 @@
* create the possibility of reusing XObjects.
* The key is the Graphic instance and the value is a PdfXobject instance.
*/
- private Map<Graphic, PdfXobject> xObjectsMap =
- new HashMap<Graphic, PdfXobject>();
+ private Map<Graphic, PdfXobject4a> xObjectsMap =
+ new HashMap<Graphic, PdfXobject4a>();
/**
* Default list of filters that should be applied to each stream in this
@@ -410,7 +410,7 @@
* @return The incremented X object count.
*/
public int registerXObjectResource(final Graphic graphic,
- final PdfXobject theXObject) {
+ final PdfXobject4a theXObject) {
// Add it to the global map so that it can be reused.
this.xObjectsMap.put(graphic, theXObject);
registerIndirectObject(theXObject);
@@ -492,7 +492,7 @@
* @param graphic The Graphic instance for which a PdfXobject is sought.
* @return The corresponding PdfXobject, or null if there is none.
*/
- public PdfXobject findXObject(final Graphic graphic) {
+ public PdfXobject4a findXObject(final Graphic graphic) {
return this.xObjectsMap.get(graphic);
}
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfFormXobject.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -62,7 +62,7 @@
* @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 PdfXobject {
+public abstract class PdfFormXobject extends PdfXobject4a {
/**
* Constructor.
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfImageXobject.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -47,10 +47,10 @@
* A sampled image that is to be embedded in a PDF File.
* Images in PDF can either be written directly into the content stream or handled as XObjects (external objects).
*
- * @see PdfXobject
+ * @see PdfXobject4a
* @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.8.4."
*/
-public class PdfImageXobject extends PdfXobject {
+public class PdfImageXobject extends PdfXobject4a {
/** The Graphic instance associated with this XObject. */
private Graphic graphic;
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -43,7 +43,7 @@
private List<PdfFont4a> fonts = new ArrayList<PdfFont4a>();
/** The list of X Objects used in this document. */
- private List<PdfXobject> xObjects = new ArrayList<PdfXobject>();
+ private List<PdfXobject4a> xObjects = new ArrayList<PdfXobject4a>();
/** The list of patterns used in this document. */
private List<PdfPattern> patterns = new ArrayList<PdfPattern>();
@@ -63,7 +63,7 @@
* Add an x object to the resources list.
* @param xObject The x object to add.
*/
- public void addXObject(final PdfXobject xObject) {
+ public void addXObject(final PdfXobject4a xObject) {
this.xObjects.add(xObject);
}
@@ -136,7 +136,7 @@
p.append("/XObject" + EOL);
p.append("<<" + EOL);
for (int i = 0; i < this.xObjects.size(); i++) {
- final PdfXobject xObject = this.xObjects.get(i);
+ final PdfXobject4a xObject = this.xObjects.get(i);
p.append("/" + xObject.getXObjectName() + " "
+ xObject.pdfReference(doc) + EOL);
}
Deleted: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-19 22:36:27 UTC (rev 11834)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -1,283 +0,0 @@
-/*
- * Copyright 2004 The FOray Project.
- * http://www.foray.org
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * This work is in part derived from the following work(s), used with the
- * permission of the licensor:
- * Apache FOP, licensed by the Apache Software Foundation
- *
- */
-
-/*
- * $LastChangedRevision$
- * $LastChangedDate$
- * $LastChangedBy$
- */
-
-/*
- * Known contributors:
- * JKT
- * Eric SCHAEFFER
- */
-
-package org.foray.pdf.object;
-
-import org.axsl.font.FontConsumer;
-import org.axsl.graphic.EpsGraphic;
-import org.axsl.graphic.Graphic;
-import org.axsl.graphic.GraphicException;
-import org.axsl.graphic.MathGraphic;
-import org.axsl.graphic.SvgGraphic;
-import org.axsl.pdf.PdfException;
-import org.axsl.ps.PsEncodeFilter;
-import org.axsl.ps.PsFilterType;
-import org.axsl.ps.PsServer;
-
-import java.awt.geom.Rectangle2D;
-import java.io.OutputStream;
-
-/**
- * <p>Abstract superclass for PDF XObject or external object. There are three types:</p>
- * <ul>
- * <li>An image XObject. See {@link PdfImageXobject} for a concrete implementation.</li>
- * <li>A form XObject. See {@link PdfFormXobject} for a concrete implementation.</li>
- * <li>A PostScript XObject. The use of these is unnecessary and deprecated, and there is no concrete implementation
- * for it.</li>
- * </ul>
- *
- * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.7, for a general description of External Objects."
- */
-public abstract class PdfXobject extends PdfStream {
-
- /** The sequentially-assigned XObject number for this XObject. This is used
- * to build the "name" entry in the XObject subdictionary. */
- private int xNumber;
-
- /** The PSFilter, if any, that should be applied to this XObject. */
- private PsEncodeFilter filter;
-
- /**
- * Create an Xobject instance.
- * @param doc The parent PDF document.
- * @param graphic The graphic to be encapsulated.
- */
- protected PdfXobject(final PdfDocument4a doc, final Graphic graphic) {
- if (graphic == null) {
- throw new NullPointerException("Graphic must not be null.");
- }
- this.xNumber = doc.registerXObjectResource(graphic, this);
- }
-
- /**
- * Factory method that encapsulates a Graphic instance into an appropriate
- * PdfXobject instance.
- * @param pdfDoc The parent PDF document.
- * @param img The graphic to be encapsulated.
- * @param fontConsumer The font consumer to use for resolving fonts in the SVG.
- * @return An appropriate PdfXobject instance that encapsulates the input.
- * @throws GraphicException For errors getting the appropriate filter.
- */
- public static PdfXobject makeXObject(final PdfDocument4a pdfDoc, final Graphic img, final FontConsumer fontConsumer)
- throws GraphicException {
- /* If it has already been created, reuse it ... */
- PdfXobject xObject = pdfDoc.findXObject(img);
- if (xObject != null) {
- return xObject;
- }
-
- /* ... otherwise, create a new one. */
- if (img instanceof EpsGraphic) {
- final EpsGraphic epsGraphic = (EpsGraphic) img;
- xObject = new PdfXformEps(pdfDoc, epsGraphic);
- } else if (img instanceof SvgGraphic) {
- final SvgGraphic svgGraphic = (SvgGraphic) img;
- xObject = new PdfXformSvg(pdfDoc, svgGraphic, fontConsumer);
- } else if (img instanceof MathGraphic) {
- final MathGraphic mathGraphic = (MathGraphic) img;
- xObject = new PdfXformMath(pdfDoc, mathGraphic, fontConsumer);
- } else if (img.getGraphicType() == Graphic.Type.PDF) {
- xObject = new PdfXreference(pdfDoc, img);
- } else {
- /* The following line is bogus, and is intended only to make sure
- * that no exceptions are thrown. If there are any exceptions
- * thrown, we don't want to create the xObject. */
- img.getColorSpace();
- xObject = new PdfImageXobject(pdfDoc, img);
- }
- xObject.filter = xObject.getFilter(xObject.getOutputStream(), pdfDoc);
- return xObject;
- }
-
- /**
- * Returns the XObject name for this object.
- * @return The name by which this XObject is recorded in the XObject
- * subdictionary.
- */
- public String getXObjectName() {
- return "X" + this.xNumber;
- }
-
- /**
- * Returns the subtype for this XObject.
- * @return The subtype for this XObject.
- */
- protected abstract String xObjectSubtype();
-
- /**
- * Add the content specific to this type of XObject to the content stream.
- * @param doc The PDF document.
- * @throws PdfException For errors in the graphic or when writing to the
- * stream.
- */
- protected abstract void xObjectContent(PdfDocument4a doc) throws PdfException;
-
- /**
- * Subclasses return any specialized dictionary entries here, so that they
- * are included when writing the stream dictionary.
- * @param doc The PDF document.
- * @return The dictonary entries specific to this type of XObject.
- * @exception GraphicException For errors during parsing of the graphic content.
- */
- protected abstract String specialXObjectDictEntries(PdfDocument4a doc) throws GraphicException;
-
- /**
- * Return an appropriate compression filter for the Graphic.
- * @param outputStream The output stream into which the compressed data should be written.
- * @param doc The PDF document.
- * @return An appropriate compression filter, or null if no compression should be used.
- * @exception GraphicException For error reading Graphic file.
- */
- private PsEncodeFilter getFilter(final OutputStream outputStream, final PdfDocument4a doc)
- throws GraphicException {
- final PsServer psServer = doc.getPsServer();
- PsEncodeFilter filter = null;
- final Graphic graphic = this.getGraphic();
- if (graphic.getGraphicType() == Graphic.Type.JPEG) {
- filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
- filter.setInactive();
- return filter;
- }
- if (graphic.getGraphicType() == Graphic.Type.TIFF) {
- final Graphic.Compression imageCompression
- = graphic.getCompressionType();
- switch (imageCompression) {
- case UNCOMPRESSED:
- return null;
- case CCITT_GROUP_3:
- filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
- filter.setInactive();
- return filter;
- case CCITT_GROUP_4:
- filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
- filter.setInactive();
- filter.setDecodeParms("<< /K -1 /Columns " + graphic.pixelWidth() + " >>");
- return filter;
- case JPEG:
- filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
- filter.setInactive();
- return filter;
- default:
- throw new GraphicException("Error while loading image "
- + graphic.getUrl() + " : "
- + this.getClass() + " - "
- + "unsupported compression value "
- + imageCompression);
- }
- }
- return null;
- }
-
- /**
- * Adds the normal stream filters used for graphics.
- * @param doc The PDF document.
- */
- protected void addStreamFilters(final PdfDocument4a doc) {
- try {
- if (this.filter == null) {
- this.addDefaultFilters(doc);
- } else {
- this.addFilter(this.filter);
- }
- } catch (final PdfException e) {
- /* Ignore, should not happen. */
- }
- if (doc.getEncryption() != null) {
- this.addEncryption(doc.getEncryption());
- }
- }
-
- /**
- * Return the encapsulated graphic.
- * @return The graphic.
- */
- public abstract Graphic getGraphic();
-
- /**
- * Returns the horizontal scaling factor that should be used for a specific
- * "Do" for a specific content rectangle.
- * This is used in transformations that are outside the actual XObject
- * definition, so that the XObject can be reused in other places, using
- * different content rectangles.
- * This abstraction is needed because bitmapped graphics are specified in
- * image space, and XForm graphics (SVG and EPS) are specified in form
- * space, which require radically different scaling mechanisms.
- * @param contentRectangle The content rectangle into which the graphic
- * will be scaled.
- * @return The horizontal scaling factor that should be applied to this
- * graphic when converting from its native space to user space.
- * @throws GraphicException For errors parsing the graphic.
- */
- public abstract float getHorizontalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
-
- /**
- * Returns the vertical scaling factor that should be used for a specific
- * "Do" for a specific content rectangle.
- * See {@link #getHorizontalScaling(java.awt.geom.Rectangle2D.Float)} for an
- * explanation of the need for this computation.
- * @param contentRectangle The content rectangle into which the graphic
- * will be scaled.
- * @return The vertical scaling factor that should be applied to this
- * graphic when converting from its native space to user space.
- * @throws GraphicException For errors parsing the graphic.
- */
- public abstract float getVerticalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
-
- @Override
- protected String specialStreamDictEntries(final PdfDocument4a doc) throws PdfException {
- addStreamFilters(doc);
- this.xObjectContent(doc);
- final String dictEntries = this.applyFilters();
-
- final StringBuilder builder = new StringBuilder();
- builder.append("/Type /XObject" + EOL
- + "/Subtype /" + xObjectSubtype() + EOL);
-
- /* Let the subclasses add entries if they need to (Image, PS, Form). */
- try {
- builder.append(this.specialXObjectDictEntries(doc));
- } catch (final GraphicException e) {
- throw new PdfException(e);
- }
-
- builder.append(dictEntries);
- return builder.toString();
- }
-
- @Override
- protected void finalizeStreamContent(final PdfDocument4a doc) {
- /* Nothing needs to be done here. */
- }
-
-}
Copied: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java (from rev 11831, trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject.java)
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java (rev 0)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-01-19 23:29:24 UTC (rev 11835)
@@ -0,0 +1,283 @@
+/*
+ * 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:
+ * JKT
+ * Eric SCHAEFFER
+ */
+
+package org.foray.pdf.object;
+
+import org.axsl.font.FontConsumer;
+import org.axsl.graphic.EpsGraphic;
+import org.axsl.graphic.Graphic;
+import org.axsl.graphic.GraphicException;
+import org.axsl.graphic.MathGraphic;
+import org.axsl.graphic.SvgGraphic;
+import org.axsl.pdf.PdfException;
+import org.axsl.ps.PsEncodeFilter;
+import org.axsl.ps.PsFilterType;
+import org.axsl.ps.PsServer;
+
+import java.awt.geom.Rectangle2D;
+import java.io.OutputStream;
+
+/**
+ * <p>Abstract superclass for PDF XObject or external object. There are three types:</p>
+ * <ul>
+ * <li>An image XObject. See {@link PdfImageXobject} for a concrete implementation.</li>
+ * <li>A form XObject. See {@link PdfFormXobject} for a concrete implementation.</li>
+ * <li>A PostScript XObject. The use of these is unnecessary and deprecated, and there is no concrete implementation
+ * for it.</li>
+ * </ul>
+ *
+ * @see "PDF Reference, Sixth Edition (PDF Version 1.7), Section 4.7, for a general description of External Objects."
+ */
+public abstract class PdfXobject4a extends PdfStream {
+
+ /** The sequentially-assigned XObject number for this XObject. This is used
+ * to build the "name" entry in the XObject subdictionary. */
+ private int xNumber;
+
+ /** The PSFilter, if any, that should be applied to this XObject. */
+ private PsEncodeFilter filter;
+
+ /**
+ * Create an Xobject instance.
+ * @param doc The parent PDF document.
+ * @param graphic The graphic to be encapsulated.
+ */
+ protected PdfXobject4a(final PdfDocument4a doc, final Graphic graphic) {
+ if (graphic == null) {
+ throw new NullPointerException("Graphic must not be null.");
+ }
+ this.xNumber = doc.registerXObjectResource(graphic, this);
+ }
+
+ /**
+ * Factory method that encapsulates a Graphic instance into an appropriate
+ * PdfXobject instance.
+ * @param pdfDoc The parent PDF document.
+ * @param img The graphic to be encapsulated.
+ * @param fontConsumer The font consumer to use for resolving fonts in the SVG.
+ * @return An appropriate PdfXobject instance that encapsulates the input.
+ * @throws GraphicException For errors getting the appropriate filter.
+ */
+ public static PdfXobject4a makeXObject(final PdfDocument4a pdfDoc, final Graphic img,
+ final FontConsumer fontConsumer) throws GraphicException {
+ /* If it has already been created, reuse it ... */
+ PdfXobject4a xObject = pdfDoc.findXObject(img);
+ if (xObject != null) {
+ return xObject;
+ }
+
+ /* ... otherwise, create a new one. */
+ if (img instanceof EpsGraphic) {
+ final EpsGraphic epsGraphic = (EpsGraphic) img;
+ xObject = new PdfXformEps(pdfDoc, epsGraphic);
+ } else if (img instanceof SvgGraphic) {
+ final SvgGraphic svgGraphic = (SvgGraphic) img;
+ xObject = new PdfXformSvg(pdfDoc, svgGraphic, fontConsumer);
+ } else if (img instanceof MathGraphic) {
+ final MathGraphic mathGraphic = (MathGraphic) img;
+ xObject = new PdfXformMath(pdfDoc, mathGraphic, fontConsumer);
+ } else if (img.getGraphicType() == Graphic.Type.PDF) {
+ xObject = new PdfXreference(pdfDoc, img);
+ } else {
+ /* The following line is bogus, and is intended only to make sure
+ * that no exceptions are thrown. If there are any exceptions
+ * thrown, we don't want to create the xObject. */
+ img.getColorSpace();
+ xObject = new PdfImageXobject(pdfDoc, img);
+ }
+ xObject.filter = xObject.getFilter(xObject.getOutputStream(), pdfDoc);
+ return xObject;
+ }
+
+ /**
+ * Returns the XObject name for this object.
+ * @return The name by which this XObject is recorded in the XObject
+ * subdictionary.
+ */
+ public String getXObjectName() {
+ return "X" + this.xNumber;
+ }
+
+ /**
+ * Returns the subtype for this XObject.
+ * @return The subtype for this XObject.
+ */
+ protected abstract String xObjectSubtype();
+
+ /**
+ * Add the content specific to this type of XObject to the content stream.
+ * @param doc The PDF document.
+ * @throws PdfException For errors in the graphic or when writing to the
+ * stream.
+ */
+ protected abstract void xObjectContent(PdfDocument4a doc) throws PdfException;
+
+ /**
+ * Subclasses return any specialized dictionary entries here, so that they
+ * are included when writing the stream dictionary.
+ * @param doc The PDF document.
+ * @return The dictonary entries specific to this type of XObject.
+ * @exception GraphicException For errors during parsing of the graphic content.
+ */
+ protected abstract String specialXObjectDictEntries(PdfDocument4a doc) throws GraphicException;
+
+ /**
+ * Return an appropriate compression filter for the Graphic.
+ * @param outputStream The output stream into which the compressed data should be written.
+ * @param doc The PDF document.
+ * @return An appropriate compression filter, or null if no compression should be used.
+ * @exception GraphicException For error reading Graphic file.
+ */
+ private PsEncodeFilter getFilter(final OutputStream outputStream, final PdfDocument4a doc)
+ throws GraphicException {
+ final PsServer psServer = doc.getPsServer();
+ PsEncodeFilter filter = null;
+ final Graphic graphic = this.getGraphic();
+ if (graphic.getGraphicType() == Graphic.Type.JPEG) {
+ filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
+ filter.setInactive();
+ return filter;
+ }
+ if (graphic.getGraphicType() == Graphic.Type.TIFF) {
+ final Graphic.Compression imageCompression
+ = graphic.getCompressionType();
+ switch (imageCompression) {
+ case UNCOMPRESSED:
+ return null;
+ case CCITT_GROUP_3:
+ filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
+ filter.setInactive();
+ return filter;
+ case CCITT_GROUP_4:
+ filter = psServer.makeEncodeFilter(PsFilterType.CCITT_FAX, outputStream);
+ filter.setInactive();
+ filter.setDecodeParms("<< /K -1 /Columns " + graphic.pixelWidth() + " >>");
+ return filter;
+ case JPEG:
+ filter = psServer.makeEncodeFilter(PsFilterType.DCT, outputStream);
+ filter.setInactive();
+ return filter;
+ default:
+ throw new GraphicException("Error while loading image "
+ + graphic.getUrl() + " : "
+ + this.getClass() + " - "
+ + "unsupported compression value "
+ + imageCompression);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Adds the normal stream filters used for graphics.
+ * @param doc The PDF document.
+ */
+ protected void addStreamFilters(final PdfDocument4a doc) {
+ try {
+ if (this.filter == null) {
+ this.addDefaultFilters(doc);
+ } else {
+ this.addFilter(this.filter);
+ }
+ } catch (final PdfException e) {
+ /* Ignore, should not happen. */
+ }
+ if (doc.getEncryption() != null) {
+ this.addEncryption(doc.getEncryption());
+ }
+ }
+
+ /**
+ * Return the encapsulated graphic.
+ * @return The graphic.
+ */
+ public abstract Graphic getGraphic();
+
+ /**
+ * Returns the horizontal scaling factor that should be used for a specific
+ * "Do" for a specific content rectangle.
+ * This is used in transformations that are outside the actual XObject
+ * definition, so that the XObject can be reused in other places, using
+ * different content rectangles.
+ * This abstraction is needed because bitmapped graphics are specified in
+ * image space, and XForm graphics (SVG and EPS) are specified in form
+ * space, which require radically different scaling mechanisms.
+ * @param contentRectangle The content rectangle into which the graphic
+ * will be scaled.
+ * @return The horizontal scaling factor that should be applied to this
+ * graphic when converting from its native space to user space.
+ * @throws GraphicException For errors parsing the graphic.
+ */
+ public abstract float getHorizontalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
+
+ /**
+ * Returns the vertical scaling factor that should be used for a specific
+ * "Do" for a specific content rectangle.
+ * See {@link #getHorizontalScaling(java.awt.geom.Rectangle2D.Float)} for an
+ * explanation of the need for this computation.
+ * @param contentRectangle The content rectangle into which the graphic
+ * will be scaled.
+ * @return The vertical scaling factor that should be applied to this
+ * graphic when converting from its native space to user space.
+ * @throws GraphicException For errors parsing the graphic.
+ */
+ public abstract float getVerticalScaling(Rectangle2D.Float contentRectangle) throws GraphicException;
+
+ @Override
+ protected String specialStreamDictEntries(final PdfDocument4a doc) throws PdfException {
+ addStreamFilters(doc);
+ this.xObjectContent(doc);
+ final String dictEntries = this.applyFilters();
+
+ final StringBuilder builder = new StringBuilder();
+ builder.append("/Type /XObject" + EOL
+ + "/Subtype /" + xObjectSubtype() + EOL);
+
+ /* Let the subclasses add entries if they need to (Image, PS, Form). */
+ try {
+ builder.append(this.specialXObjectDictEntries(doc));
+ } catch (final GraphicException e) {
+ throw new PdfException(e);
+ }
+
+ builder.append(dictEntries);
+ return builder.toString();
+ }
+
+ @Override
+ protected void finalizeStreamContent(final PdfDocument4a doc) {
+ /* Nothing needs to be done here. */
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|