aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-10-19 16:30:58 +0000
committerJeremias Maerki <jeremias@apache.org>2005-10-19 16:30:58 +0000
commit4d2cb06d14f480d24bd2a10198940811748d730e (patch)
tree009dff0745da03e711863065d6336b4716ace2f0 /src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
parent20be3fe07bda82ab51d180744cba05ed707d8276 (diff)
downloadxmlgraphics-fop-4d2cb06d14f480d24bd2a10198940811748d730e.tar.gz
xmlgraphics-fop-4d2cb06d14f480d24bd2a10198940811748d730e.zip
Fix to make the Graphics.create() method (calls a copy constructor) work.
Extracted stuff into a PDFContext class which gets passed to each copy of PDFDocumentGraphics2D, so the state is uniform over all copies. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@326600 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java')
-rw-r--r--src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java90
1 files changed, 39 insertions, 51 deletions
diff --git a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
index 00d1ec5d7..d90857743 100644
--- a/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
+++ b/src/java/org/apache/fop/svg/PDFDocumentGraphics2D.java
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,8 +34,6 @@ 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.commons.logging.impl.SimpleLog;
-import org.apache.commons.logging.Log;
import java.awt.Graphics;
import java.awt.Font;
@@ -47,7 +45,6 @@ import java.awt.geom.AffineTransform;
import java.io.OutputStream;
import java.io.IOException;
import java.io.StringWriter;
-import java.util.List;
/**
* This class is a wrapper for the <tt>PDFGraphics2D</tt> that
@@ -55,13 +52,13 @@ import java.util.List;
* <tt>PDFGraphics2D</tt>.
*
* @author <a href="mailto:keiron@aftexsw.com">Keiron Liddle</a>
- * @version $Id: PDFDocumentGraphics2D.java,v 1.27 2003/03/07 09:51:26 jeremias Exp $
+ * @version $Id$
* @see org.apache.fop.svg.PDFGraphics2D
*/
public class PDFDocumentGraphics2D extends PDFGraphics2D
implements Configurable, Initializable {
- private PDFPage currentPage;
+ private PDFContext pdfContext;
private int width;
private int height;
@@ -70,13 +67,6 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
private float svgWidth;
private float svgHeight;
- private List fontList;
-
- /** number of pages generated */
- protected int pagecount;
- /** indicates whether a page is currently being generated */
- protected boolean pagePending;
-
/** Initial clipping area, used to restore to original setting when a new page is started. */
protected Shape initialClip;
/**
@@ -85,8 +75,6 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
*/
protected AffineTransform initialTransform;
- private Log logger;
-
//Avalon component
private Configuration cfg;
@@ -104,6 +92,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
public PDFDocumentGraphics2D(boolean textAsShapes) {
super(textAsShapes);
+ this.pdfContext = new PDFContext();
if (!textAsShapes) {
fontInfo = new FontInfo();
FontSetup.setup(fontInfo, null);
@@ -147,23 +136,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
* This constructor is Avalon-style.
*/
public PDFDocumentGraphics2D() {
- super(false);
- }
-
- public void setLogger(Log logger) {
- this.logger = logger;
- }
-
- /**
- * Returns the logger.
- * @return Logger the logger
- */
- protected final Log getLogger() {
- if (this.logger == null) {
- this.logger = new SimpleLog("FOP/PDF");
- ((SimpleLog) logger).setLevel(SimpleLog.LOG_LEVEL_INFO);
- }
- return this.logger;
+ this(false);
}
/**
@@ -171,7 +144,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
*/
public void configure(Configuration cfg) throws ConfigurationException {
this.cfg = cfg;
- this.fontList = FontSetup.buildFontListFromConfiguration(cfg);
+ this.pdfContext.setFontList(FontSetup.buildFontListFromConfiguration(cfg));
}
/**
@@ -180,7 +153,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
public void initialize() throws Exception {
if (this.fontInfo == null) {
fontInfo = new FontInfo();
- FontSetup.setup(fontInfo, this.fontList);
+ FontSetup.setup(fontInfo, this.pdfContext.getFontList());
//FontState fontState = new FontState("Helvetica", "normal",
// FontInfo.NORMAL, 12, 0);
}
@@ -257,34 +230,39 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
currentStream.write("Q\n");
}
+ /**
+ * Is called to prepare the PDFDocumentGraphics2D for the next page to be painted. Basically,
+ * this closes the current page. A new page is prepared as soon as painting starts.
+ */
public void nextPage() {
closePage();
}
-
+ /**
+ * Closes the current page and adds it to the PDF file.
+ */
protected void closePage() {
- if (!this.pagePending) {
+ if (!pdfContext.isPagePending()) {
return; //ignore
}
//Finish page
- PDFStream pdfStream = this.pdfDoc.getFactory().makeStream(PDFFilterList.CONTENT_FILTER, false);
+ PDFStream pdfStream = this.pdfDoc.getFactory().makeStream(
+ PDFFilterList.CONTENT_FILTER, false);
pdfStream.add(getString());
currentStream = null;
this.pdfDoc.registerObject(pdfStream);
- currentPage.setContents(pdfStream);
- PDFAnnotList annots = currentPage.getAnnotations();
+ pdfContext.getCurrentPage().setContents(pdfStream);
+ PDFAnnotList annots = pdfContext.getCurrentPage().getAnnotations();
if (annots != null) {
this.pdfDoc.addObject(annots);
}
- this.pdfDoc.addObject(currentPage);
- this.currentPage = null;
-
- this.pagePending = false;
+ this.pdfDoc.addObject(pdfContext.getCurrentPage());
+ pdfContext.clearCurrentPage();
}
/** {@inheritDoc} */
protected void preparePainting() {
- if (this.pagePending) {
+ if (pdfContext.isPagePending()) {
return;
}
try {
@@ -294,8 +272,12 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
}
}
+ /**
+ * Called to prepare a new page
+ * @throws IOException if starting the new page fails due to I/O errors.
+ */
protected void startPage() throws IOException {
- if (this.pagePending) {
+ if (pdfContext.isPagePending()) {
throw new IllegalStateException("Close page first before starting another");
}
//Start page
@@ -318,10 +300,11 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
}
PDFResources pdfResources = this.pdfDoc.getResources();
- currentPage = this.pdfDoc.getFactory().makePage(pdfResources,
- width, height);
- resourceContext = currentPage;
- pageRef = currentPage.referencePDF();
+ PDFPage page = this.pdfDoc.getFactory().makePage(pdfResources,
+ width, height);
+ resourceContext = page;
+ pdfContext.setCurrentPage(page);
+ pageRef = page.referencePDF();
graphicsState.setTransform(new AffineTransform(1.0, 0.0, 0.0, -1.0, 0.0, (double)height));
currentStream.write("1 0 0 -1 0 " + height + " cm\n");
if (svgWidth != 0) {
@@ -329,8 +312,7 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
+ PDFNumber.doubleOut(height / svgHeight) + " 0 0 cm\n");
}
- this.pagecount++;
- this.pagePending = true;
+ pdfContext.increasePageCount();
}
@@ -361,6 +343,12 @@ public class PDFDocumentGraphics2D extends PDFGraphics2D
*/
public PDFDocumentGraphics2D(PDFDocumentGraphics2D g) {
super(g);
+ this.pdfContext = g.pdfContext;
+ this.cfg = g.cfg;
+ this.width = g.width;
+ this.height = g.height;
+ this.svgWidth = g.svgWidth;
+ this.svgHeight = g.svgHeight;
}
/**