[FOray-commit] SF.net SVN: foray:[11836] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-01-20 00:45:22
|
Revision: 11836
http://sourceforge.net/p/foray/code/11836
Author: victormote
Date: 2021-01-20 00:45:14 +0000 (Wed, 20 Jan 2021)
Log Message:
-----------
Conform to aXSL changes: Add method for creating XObjects to PdfDocument. Add method for displaying them to PdfContentStream.
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/PdfPage4a.java
trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.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
trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.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 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfContentStream4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -42,6 +42,7 @@
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;
@@ -55,21 +56,10 @@
/** The current graphics state. */
private PdfGraphicsState currentGraphicsState = new PdfGraphicsState();
- /** The PDF document. */
- private PdfDocument4a doc;
-
/** State variable indicating whether a text object is currently open. */
private boolean textObjectOpen = false;
/**
- * Create a PdfContentStream.
- * @param doc The parent PDF document.
- */
- public PdfContentStream4a(final PdfDocument4a doc) {
- this.doc = doc;
- }
-
- /**
* Return the graphic state.
* @return The graphic state.
*/
@@ -276,39 +266,9 @@
}
@Override
- public void drawGraphic(final Graphic image,
- final Rectangle2D.Float contentRectangle,
- final Rectangle2D.Float clipRectangle,
- final FontConsumer fontConsumer, final boolean strokeText) throws PdfException {
- final PdfXobject4a xObject;
- try {
- if (strokeText) {
- xObject = PdfXobject4a.makeXObject(doc, image, null);
- } else {
- xObject = PdfXobject4a.makeXObject(doc, image, fontConsumer);
- }
- } catch (final GraphicException e) {
- throw new PdfException(e);
- }
- if (xObject == null) {
- throw new PdfException("Don't know how to process graphic:" + MSG_EOL
- + image.getUrl());
- }
- 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);
+ public void drawGraphic(final Graphic image, final Rectangle2D.Float contentRectangle,
+ final Rectangle2D.Float clipRectangle, final FontConsumer fontConsumer) throws PdfException {
+ throw new UnsupportedOperationException();
}
/**
@@ -376,4 +336,24 @@
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);
+ }
+
}
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 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfDocument4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -47,8 +47,10 @@
import org.axsl.common.Gradient;
import org.axsl.common.sequence.IntPrimitiveIterator;
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.pdf.PdfDocument;
import org.axsl.pdf.PdfException;
@@ -56,6 +58,7 @@
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;
@@ -762,4 +765,18 @@
return this.xrefInfo;
}
+ @Override
+ public PdfXobject createXobject(final Graphic graphic, final FontConsumer fontConsumer) throws PdfException {
+ final PdfXobject4a xObject;
+ try {
+ xObject = PdfXobject4a.makeXObject(this, graphic, null);
+ } 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;
+ }
+
}
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 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfPage4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -89,7 +89,7 @@
this.resources = resources;
this.pagewidth = pagewidth;
this.pageheight = pageheight;
- this.contents = new PdfContentStream4a(this.getPDFDocument());
+ this.contents = new PdfContentStream4a();
try {
this.contents.addDefaultFilters(doc);
} catch (final PdfException e) {
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 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfResources.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -137,7 +137,7 @@
p.append("<<" + EOL);
for (int i = 0; i < this.xObjects.size(); i++) {
final PdfXobject4a xObject = this.xObjects.get(i);
- p.append("/" + xObject.getXObjectName() + " "
+ p.append("/" + xObject.getXobjectName() + " "
+ xObject.pdfReference(doc) + EOL);
}
p.append(">>" + EOL);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXobject4a.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -41,11 +41,11 @@
import org.axsl.graphic.MathGraphic;
import org.axsl.graphic.SvgGraphic;
import org.axsl.pdf.PdfException;
+import org.axsl.pdf.PdfXobject;
import org.axsl.ps.PsEncodeFilter;
import org.axsl.ps.PsFilterType;
import org.axsl.ps.PsServer;
-import java.awt.geom.Rectangle2D;
import java.io.OutputStream;
/**
@@ -59,7 +59,7 @@
*
* @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 {
+public abstract class PdfXobject4a extends PdfStream implements PdfXobject {
/** The sequentially-assigned XObject number for this XObject. This is used
* to build the "name" entry in the XObject subdictionary. */
@@ -120,12 +120,8 @@
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() {
+ @Override
+ public String getXobjectName() {
return "X" + this.xNumber;
}
@@ -224,36 +220,6 @@
*/
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);
Modified: trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java
===================================================================
--- trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-pdf/src/main/java/org/foray/pdf/object/PdfXreference.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -63,7 +63,7 @@
this.graphic = graphic;
/* Write the content of the graphic file to an embedded file stream. */
- final String efsName = this.getXObjectName() + "-EF";
+ final String efsName = this.getXobjectName() + "-EF";
final PdfEmbeddedFileStream embeddedFile = new PdfEmbeddedFileStream(doc, efsName);
final ByteSequence efsContent = this.graphic.getContent();
try {
Modified: trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java
===================================================================
--- trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-01-19 23:29:24 UTC (rev 11835)
+++ trunk/foray/foray-render/src/main/java/org/foray/render/pdf/PdfRenderer.java 2021-01-20 00:45:14 UTC (rev 11836)
@@ -78,6 +78,7 @@
import org.axsl.pdf.PdfPageLabelStyle;
import org.axsl.pdf.PdfPathPaint;
import org.axsl.pdf.PdfVersion;
+import org.axsl.pdf.PdfXobject;
import java.awt.Color;
import java.awt.Rectangle;
@@ -301,8 +302,8 @@
final Rectangle2D.Float pdfClipRectangle = convertMillipointRectangle(
clipRectangle);
try {
- getContentStream().drawGraphic(image, pdfContentRectangle,
- pdfClipRectangle, this.getFontConsumer(), getStrokeSVGText());
+ final PdfXobject xObject = this.pdfDoc.createXobject(image, getFontConsumer());
+ getContentStream().drawXobject(xObject, pdfContentRectangle, pdfClipRectangle);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
}
@@ -317,9 +318,8 @@
toPoints(foreign.referenceBpd()));
final SvgGraphic svgGraphic = area.getGraphic();
try {
- getContentStream().drawGraphic(svgGraphic,
- contentRectangle, null, this.getFontConsumer(),
- getStrokeSVGText());
+ final PdfXobject xObject = this.pdfDoc.createXobject(svgGraphic, getFontConsumer());
+ getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
}
@@ -335,9 +335,8 @@
toPoints(foreign.referenceBpd()));
final MathGraphic mathGraphic = area.getGraphic();
try {
- getContentStream().drawGraphic(mathGraphic,
- contentRectangle, null, this.getFontConsumer(),
- getStrokeSVGText());
+ final PdfXobject xObject = this.pdfDoc.createXobject(mathGraphic, getFontConsumer());
+ getContentStream().drawXobject(xObject, contentRectangle, null);
} catch (final PdfException e) {
throw new GalleyVisitorException(e);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|