aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/ps/PSRenderer.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-11-19 20:13:48 +0000
committerJeremias Maerki <jeremias@apache.org>2008-11-19 20:13:48 +0000
commitbe4dc692db093ec6b8039d7e61804e28f1709db4 (patch)
treeaa484221fc31f715fcc9e386afb978e31de8b3a0 /src/java/org/apache/fop/render/ps/PSRenderer.java
parentdfeb96c655c3e361b5fdf6f0cecbf46adab01a72 (diff)
downloadxmlgraphics-fop-be4dc692db093ec6b8039d7e61804e28f1709db4.tar.gz
xmlgraphics-fop-be4dc692db093ec6b8039d7e61804e28f1709db4.zip
Added page master name to IFDocumentHandler.startPage() method.
Wired together the support for out-of-order rendering (only applicable to PDF) when the intermediate format is not used (in-memory rendering). Fixed a logical bug in IFRenderer that caused some unneeded code. Glyph adjustments (kerning, letter/word space...) were not done right. All painters fixed/adjusted accordingly. Started implementation of the PostScript painter: Supports only text and filled rectangles so far. Work in progress... git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@719051 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/ps/PSRenderer.java')
-rw-r--r--src/java/org/apache/fop/render/ps/PSRenderer.java184
1 files changed, 27 insertions, 157 deletions
diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java
index 4ccb0bd52..83dbd4b62 100644
--- a/src/java/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/java/org/apache/fop/render/ps/PSRenderer.java
@@ -28,7 +28,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.io.LineNumberReader;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Iterator;
@@ -128,7 +127,7 @@ import org.apache.fop.util.ColorUtil;
* @version $Id$
*/
public class PSRenderer extends AbstractPathOrientedRenderer
- implements ImageAdapter, PSSupportedFlavors {
+ implements ImageAdapter, PSSupportedFlavors, PSConfigurationConstants {
/** logging instance */
private static Log log = LogFactory.getLog(PSRenderer.class);
@@ -136,17 +135,9 @@ public class PSRenderer extends AbstractPathOrientedRenderer
/** The MIME type for PostScript */
public static final String MIME_TYPE = "application/postscript";
- private static final String AUTO_ROTATE_LANDSCAPE = "auto-rotate-landscape";
- private static final String OPTIMIZE_RESOURCES = "optimize-resources";
- private static final String LANGUAGE_LEVEL = "language-level";
-
/** The application producing the PostScript */
private int currentPageNumber = 0;
- private final boolean enableComments = true;
- private boolean autoRotateLandscape = false;
- private int languageLevel = PSGenerator.DEFAULT_LANGUAGE_LEVEL;
-
/** the OutputStream the PS file is written to */
private OutputStream outputStream;
/** the temporary file in case of two-pass processing */
@@ -154,8 +145,6 @@ public class PSRenderer extends AbstractPathOrientedRenderer
/** The PostScript generator used to output the PostScript */
protected PSGenerator gen;
- /** Determines whether the PS file is generated in two passes to minimize file size */
- private boolean twoPassGeneration = false;
private boolean ioTrouble = false;
private boolean inTextMode = false;
@@ -171,14 +160,11 @@ public class PSRenderer extends AbstractPathOrientedRenderer
/** encapsulation of dictionary used in setpagedevice instruction **/
private PSPageDeviceDictionary pageDeviceDictionary;
- /** Whether or not the safe set page device macro will be used or not */
- private boolean safeSetPageDevice = false;
-
/**
- * Whether or not PostScript Document Structuring Conventions (DSC) compliant output are
- * enforced.
+ * Utility class which enables all sorts of features that are not directly connected to the
+ * normal rendering process.
*/
- private boolean dscCompliant = true;
+ protected PSRenderingUtil psUtil;
/** Is used to determine the document's bounding box */
private Rectangle2D documentBoundingBox;
@@ -192,39 +178,11 @@ public class PSRenderer extends AbstractPathOrientedRenderer
/** {@inheritDoc} */
public void setUserAgent(FOUserAgent agent) {
super.setUserAgent(agent);
- Object obj;
- obj = agent.getRendererOptions().get(AUTO_ROTATE_LANDSCAPE);
- if (obj != null) {
- setAutoRotateLandscape(booleanValueOf(obj));
- }
- obj = agent.getRendererOptions().get(LANGUAGE_LEVEL);
- if (obj != null) {
- setLanguageLevel(intValueOf(obj));
- }
- obj = agent.getRendererOptions().get(OPTIMIZE_RESOURCES);
- if (obj != null) {
- setOptimizeResources(booleanValueOf(obj));
- }
+ this.psUtil = new PSRenderingUtil(getUserAgent());
}
- private boolean booleanValueOf(Object obj) {
- if (obj instanceof Boolean) {
- return ((Boolean)obj).booleanValue();
- } else if (obj instanceof String) {
- return Boolean.valueOf((String)obj).booleanValue();
- } else {
- throw new IllegalArgumentException("Boolean or \"true\" or \"false\" expected.");
- }
- }
-
- private int intValueOf(Object obj) {
- if (obj instanceof Integer) {
- return ((Integer)obj).intValue();
- } else if (obj instanceof String) {
- return Integer.parseInt((String)obj);
- } else {
- throw new IllegalArgumentException("Integer or String with a number expected.");
- }
+ PSRenderingUtil getPSUtil() {
+ return this.psUtil;
}
/**
@@ -233,12 +191,12 @@ public class PSRenderer extends AbstractPathOrientedRenderer
* a "wider-than-long" page by 90 degrees.
*/
public void setAutoRotateLandscape(boolean value) {
- this.autoRotateLandscape = value;
+ getPSUtil().setAutoRotateLandscape(value);
}
/** @return true if the renderer is configured to rotate landscape pages */
public boolean isAutoRotateLandscape() {
- return this.autoRotateLandscape;
+ return getPSUtil().isAutoRotateLandscape();
}
/**
@@ -246,11 +204,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
* @param level the language level (currently allowed: 2 or 3)
*/
public void setLanguageLevel(int level) {
- if (level == 2 || level == 3) {
- this.languageLevel = level;
- } else {
- throw new IllegalArgumentException("Only language levels 2 or 3 are allowed/supported");
- }
+ getPSUtil().setLanguageLevel(level);
}
/**
@@ -258,7 +212,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
* @return the language level
*/
public int getLanguageLevel() {
- return this.languageLevel;
+ return getPSUtil().getLanguageLevel();
}
/**
@@ -268,12 +222,12 @@ public class PSRenderer extends AbstractPathOrientedRenderer
* @param value true to enable the resource optimization
*/
public void setOptimizeResources(boolean value) {
- this.twoPassGeneration = value;
+ getPSUtil().setOptimizeResources(value);
}
/** @return true if the renderer does two passes to optimize PostScript resources */
public boolean isOptimizeResources() {
- return this.twoPassGeneration;
+ return getPSUtil().isOptimizeResources();
}
/** {@inheritDoc} */
@@ -316,12 +270,15 @@ public class PSRenderer extends AbstractPathOrientedRenderer
* @param comment Comment to write
*/
protected void comment(String comment) {
- if (this.enableComments) {
+ try {
if (comment.startsWith("%")) {
+ gen.commentln(comment);
writeln(comment);
} else {
- writeln("%" + comment);
+ gen.commentln("%" + comment);
}
+ } catch (IOException ioe) {
+ handleIOTrouble(ioe);
}
}
@@ -931,7 +888,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
//Initial default page device dictionary settings
this.pageDeviceDictionary = new PSPageDeviceDictionary();
- pageDeviceDictionary.setFlushOnRetrieval(!this.dscCompliant);
+ pageDeviceDictionary.setFlushOnRetrieval(!getPSUtil().isDSCComplianceEnabled());
pageDeviceDictionary.put("/ImagingBBox", "null");
}
@@ -969,7 +926,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
//Setup
gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
- writeSetupCodeList(setupCodeList, "SetupCode");
+ PSRenderingUtil.writeSetupCodeList(gen, setupCodeList, "SetupCode");
if (!isOptimizeResources()) {
this.fontResources = PSFontUtils.writeFontDict(gen, fontInfo);
} else {
@@ -980,16 +937,6 @@ public class PSRenderer extends AbstractPathOrientedRenderer
/** {@inheritDoc} */
public void stopRenderer() throws IOException {
- //Notify resource usage for font which are not supplied
- /* done in useFont now
- Map fonts = fontInfo.getUsedFonts();
- Iterator e = fonts.keySet().iterator();
- while (e.hasNext()) {
- String key = (String)e.next();
- PSResource res = (PSResource)this.fontResources.get(key);
- gen.notifyResourceUsage(res);
- }*/
-
//Write trailer
gen.writeDSCComment(DSCConstants.TRAILER);
if (footerComments != null) {
@@ -1102,34 +1049,6 @@ public class PSRenderer extends AbstractPathOrientedRenderer
super.processOffDocumentItem(oDI);
}
- /**
- * Formats and writes a List of PSSetupCode instances to the output stream.
- * @param setupCodeList a List of PSSetupCode instances
- * @param type the type of code section
- */
- private void writeSetupCodeList(List setupCodeList, String type) throws IOException {
- if (setupCodeList != null) {
- Iterator i = setupCodeList.iterator();
- while (i.hasNext()) {
- PSSetupCode setupCode = (PSSetupCode)i.next();
- gen.commentln("%FOPBegin" + type + ": ("
- + (setupCode.getName() != null ? setupCode.getName() : "")
- + ")");
- LineNumberReader reader = new LineNumberReader(
- new java.io.StringReader(setupCode.getContent()));
- String line;
- while ((line = reader.readLine()) != null) {
- line = line.trim();
- if (line.length() > 0) {
- gen.writeln(line.trim());
- }
- }
- gen.commentln("%FOPEnd" + type);
- i.remove();
- }
- }
- }
-
/** {@inheritDoc} */
public void renderPage(PageViewport page)
throws IOException, FOPException {
@@ -1151,7 +1070,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
double pageHeight = Math.round(page.getViewArea().getHeight()) / 1000f;
boolean rotate = false;
List pageSizes = new java.util.ArrayList();
- if (this.autoRotateLandscape && (pageHeight < pageWidth)) {
+ if (getPSUtil().isAutoRotateLandscape() && (pageHeight < pageWidth)) {
rotate = true;
pageSizes.add(new Long(Math.round(pageHeight)));
pageSizes.add(new Long(Math.round(pageWidth)));
@@ -1189,7 +1108,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
try {
if (setupCodeList != null) {
- writeEnclosedExtensionAttachments(setupCodeList);
+ PSRenderingUtil.writeEnclosedExtensionAttachments(gen, setupCodeList);
setupCodeList.clear();
}
} catch (IOException e) {
@@ -1214,7 +1133,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
gen.writeDSCComment(DSCConstants.PAGE_HIRES_BBOX, new Object[] {
zero, zero, new Double(pageWidth),
new Double(pageHeight) });
- if (autoRotateLandscape) {
+ if (getPSUtil().isAutoRotateLandscape()) {
gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION,
"Portrait");
}
@@ -1245,12 +1164,12 @@ public class PSRenderer extends AbstractPathOrientedRenderer
// Write any unwritten changes to page device dictionary
if (!pageDeviceDictionary.isEmpty()) {
String content = pageDeviceDictionary.getContent();
- if (safeSetPageDevice) {
+ if (getPSUtil().isSafeSetPageDevice()) {
content += " SSPD";
} else {
content += " setpagedevice";
}
- writeEnclosedExtensionAttachment(new PSSetPageDevice(content));
+ PSRenderingUtil.writeEnclosedExtensionAttachment(gen, new PSSetPageDevice(content));
}
if (rotate) {
@@ -1633,55 +1552,6 @@ public class PSRenderer extends AbstractPathOrientedRenderer
}
/**
- * Formats and writes a PSExtensionAttachment to the output stream.
- *
- * @param attachment an PSExtensionAttachment instance
- */
- private void writeEnclosedExtensionAttachment(PSExtensionAttachment attachment)
- throws IOException {
- String info = "";
- if (attachment instanceof PSSetupCode) {
- PSSetupCode setupCodeAttach = (PSSetupCode)attachment;
- String name = setupCodeAttach.getName();
- if (name != null) {
- info += ": (" + name + ")";
- }
- }
- String type = attachment.getType();
- gen.commentln("%FOPBegin" + type + info);
- LineNumberReader reader = new LineNumberReader(
- new java.io.StringReader(attachment.getContent()));
- String line;
- while ((line = reader.readLine()) != null) {
- line = line.trim();
- if (line.length() > 0) {
- gen.writeln(line);
- }
- }
- gen.commentln("%FOPEnd" + type);
- }
-
- /**
- * Formats and writes a Collection of PSExtensionAttachment instances to
- * the output stream.
- *
- * @param attachmentCollection
- * a Collection of PSExtensionAttachment instances
- */
- private void writeEnclosedExtensionAttachments(Collection attachmentCollection)
- throws IOException {
- Iterator iter = attachmentCollection.iterator();
- while (iter.hasNext()) {
- PSExtensionAttachment attachment = (PSExtensionAttachment)iter
- .next();
- if (attachment != null) {
- writeEnclosedExtensionAttachment(attachment);
- }
- iter.remove();
- }
- }
-
- /**
* Sets whether or not the safe set page device macro should be used
* (as opposed to directly invoking setpagedevice) when setting the
* postscript page device.
@@ -1694,7 +1564,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
* device macro call (default is false).
*/
public void setSafeSetPageDevice(boolean safeSetPageDevice) {
- this.safeSetPageDevice = safeSetPageDevice;
+ getPSUtil().setSafeSetPageDevice(safeSetPageDevice);
}
/**
@@ -1711,7 +1581,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer
* @param dscCompliant boolean value (default is true)
*/
public void setDSCCompliant(boolean dscCompliant) {
- this.dscCompliant = dscCompliant;
+ getPSUtil().setDSCComplianceEnabled(dscCompliant);
}
}