aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2003-03-27 11:28:51 +0000
committerJeremias Maerki <jeremias@apache.org>2003-03-27 11:28:51 +0000
commit90c4d070333cedff83b42cabfaeb5e0d42691ac8 (patch)
tree8d69dc8a3a5e6ca16b173aa367d358c602329b28 /src
parent0451135a08b684078c32646ff8b2e9197a3bd624 (diff)
downloadxmlgraphics-fop-90c4d070333cedff83b42cabfaeb5e0d42691ac8.tar.gz
xmlgraphics-fop-90c4d070333cedff83b42cabfaeb5e0d42691ac8.zip
Adjust to changes in PDF library.
Avalonize in a backwards-compatible way (optional logging and configuration). git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196182 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java136
1 files changed, 107 insertions, 29 deletions
diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
index 73aa04572..58d33264d 100644
--- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
+++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
@@ -51,6 +51,7 @@
package org.apache.fop.svg;
import org.apache.fop.pdf.PDFDocument;
+import org.apache.fop.pdf.PDFFilterList;
import org.apache.fop.pdf.PDFPage;
import org.apache.fop.pdf.PDFStream;
import org.apache.fop.pdf.PDFState;
@@ -59,6 +60,15 @@ import org.apache.fop.pdf.PDFResources;
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.pdf.PDFAnnotList;
import org.apache.fop.render.pdf.FontSetup;
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.LogEnabled;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.fop.layout.FontInfo;
import java.awt.Graphics;
@@ -70,6 +80,7 @@ import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.io.OutputStream;
import java.io.IOException;
+import java.util.List;
/**
* This class is a wrapper for the <tt>PDFGraphics2D</tt> that
@@ -80,11 +91,18 @@ import java.io.IOException;
* @version $Id: PDFDocumentGraphics2D.java,v 1.27 2003/03/07 09:51:26 jeremias Exp $
* @see org.apache.fop.svg.PDFGraphics2D
*/
-public class PDFDocumentGraphics2D extends PDFGraphics2D {
+public class PDFDocumentGraphics2D extends PDFGraphics2D
+ implements LogEnabled, Configurable, Initializable {
+
private PDFPage currentPage;
private PDFStream pdfStream;
private int width;
private int height;
+ private List fontList;
+
+ //Avalon-dependent stuff
+ private Logger logger;
+ private Configuration cfg;
/**
* Create a new PDFDocumentGraphics2D.
@@ -97,7 +115,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
* @param textAsShapes set this to true so that text will be rendered
* using curves and not the font.
*/
- PDFDocumentGraphics2D(boolean textAsShapes) {
+ public PDFDocumentGraphics2D(boolean textAsShapes) {
super(textAsShapes);
if (!textAsShapes) {
@@ -106,16 +124,96 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
//FontState fontState = new FontState("Helvetica", "normal",
// FontInfo.NORMAL, 12, 0);
}
+ try {
+ initialize();
+ } catch (Exception e) {
+ //Should never happen
+ throw new CascadingRuntimeException("Internal error", e);
+ }
+ }
+
+ /**
+ * Create a new PDFDocumentGraphics2D.
+ * This is used to create a new pdf document of the given height
+ * and width.
+ * The resulting document is written to the stream after rendering.
+ *
+ * @param textAsShapes set this to true so that text will be rendered
+ * using curves and not the font.
+ * @param stream the stream that the final document should be written to.
+ * @param width the width of the document
+ * @param height the height of the document
+ * @throws IOException an io exception if there is a problem
+ * writing to the output stream
+ */
+ public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
+ int width, int height) throws IOException {
+ this(textAsShapes);
+ setupDocument(stream, width, height);
+ }
+
+ /**
+ * Create a new PDFDocumentGraphics2D.
+ * This is used to create a new pdf document.
+ * For use by the transcoder which needs font information
+ * for the bridge before the document size is known.
+ * The resulting document is written to the stream after rendering.
+ * This constructor is Avalon-style.
+ */
+ public PDFDocumentGraphics2D() {
+ super(false);
+ }
+
+ /**
+ * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger)
+ */
+ public void enableLogging(Logger logger) {
+ this.logger = logger;
+ }
+
+ /**
+ * Returns the logger.
+ * @return Logger the logger
+ */
+ protected final Logger getLogger() {
+ if (this.logger == null) {
+ this.logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
+ }
+ return this.logger;
+ }
- this.pdfDoc = new PDFDocument("FOP SVG Renderer");
- this.pdfDoc.enableLogging(new org.apache.avalon.framework.logger.NullLogger());
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
+ */
+ public void configure(Configuration cfg) throws ConfigurationException {
+ this.cfg = cfg;
+ this.fontList = FontSetup.buildFontListFromConfiguration(cfg);
+ }
+
+ /**
+ * @see org.apache.avalon.framework.activity.Initializable#initialize()
+ */
+ public void initialize() throws Exception {
+ if (this.fontInfo == null) {
+ fontInfo = new FontInfo();
+ FontSetup.setup(fontInfo, this.fontList);
+ //FontState fontState = new FontState("Helvetica", "normal",
+ // FontInfo.NORMAL, 12, 0);
+ }
+ this.pdfDoc = new PDFDocument("Apache FOP: SVG to PDF Transcoder");
+ ContainerUtil.enableLogging(this.pdfDoc, getLogger().getChildLogger("pdf"));
+ if (this.cfg != null) {
+ this.pdfDoc.setFilterMap(
+ PDFFilterList.buildFilterMapFromConfiguration(cfg));
+ }
+
graphicsState = new PDFState();
currentFontName = "";
currentFontSize = 0;
- pdfStream = this.pdfDoc.makeStream(PDFStream.CONTENT_FILTER, false);
+ pdfStream = this.pdfDoc.getFactory().makeStream(PDFFilterList.CONTENT_FILTER, false);
}
/**
@@ -131,7 +229,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
this.height = height;
PDFResources pdfResources = this.pdfDoc.getResources();
- currentPage = this.pdfDoc.makePage(pdfResources,
+ currentPage = this.pdfDoc.getFactory().makePage(pdfResources,
width, height);
resourceContext = currentPage;
pageRef = currentPage.referencePDF();
@@ -143,26 +241,6 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
}
/**
- * Create a new PDFDocumentGraphics2D.
- * This is used to create a new pdf document of the given height
- * and width.
- * The resulting document is written to the stream after rendering.
- *
- * @param textAsShapes set this to true so that text will be rendered
- * using curves and not the font.
- * @param stream the stream that the final document should be written to.
- * @param width the width of the document
- * @param height the height of the document
- * @throws IOException an io exception if there is a problem
- * writing to the output stream
- */
- public PDFDocumentGraphics2D(boolean textAsShapes, OutputStream stream,
- int width, int height) throws IOException {
- this(textAsShapes);
- setupDocument(stream, width, height);
- }
-
- /**
* Get the font info for this pdf document.
* @return the font information
*/
@@ -222,13 +300,13 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D {
// restorePDFState();
pdfStream.add(getString());
- this.pdfDoc.addStream(pdfStream);
+ this.pdfDoc.registerObject(pdfStream);
currentPage.setContents(pdfStream);
PDFAnnotList annots = currentPage.getAnnotations();
if (annots != null) {
- this.pdfDoc.addAnnotList(annots);
+ this.pdfDoc.addObject(annots);
}
- this.pdfDoc.addPage(currentPage);
+ this.pdfDoc.addObject(currentPage);
if (fontInfo != null) {
FontSetup.addToResources(pdfDoc, pdfDoc.getResources(), fontInfo);
}