aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2005-08-23 15:16:49 +0000
committerJeremias Maerki <jeremias@apache.org>2005-08-23 15:16:49 +0000
commit0c06011d4f128469576cefad5e674d4490400bc8 (patch)
treebb513932fb651c99e7ab4f04e298c8002a37f1b4 /src/java/org/apache/fop
parent9124211fdd13b336c60f606a11983dff70cd8b10 (diff)
downloadxmlgraphics-fop-0c06011d4f128469576cefad5e674d4490400bc8.tar.gz
xmlgraphics-fop-0c06011d4f128469576cefad5e674d4490400bc8.zip
Started to implement a resource tracking facility in the PSGenerator. It tracks resources such as EPS files, procset etc. as PSResource instances.
Resource-DSC comments are now generated. Procsets moved into the Prolog where they belong. Font setup is no longer a resource as it is not interchangeable between rendering runs. It's now just setup code with FOP-specific comments surrounding it. In the future, this may also make it possible to write a size-optimized PS file from which the resources are stripped while writing the file. These resources will then be installed directly on a printer or inserted into the Prolog by a post-processor. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@239419 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/render/ps/DSCConstants.java50
-rw-r--r--src/java/org/apache/fop/render/ps/PSGenerator.java84
-rw-r--r--src/java/org/apache/fop/render/ps/PSImageUtils.java8
-rw-r--r--src/java/org/apache/fop/render/ps/PSProcSets.java301
-rw-r--r--src/java/org/apache/fop/render/ps/PSRenderer.java14
-rw-r--r--src/java/org/apache/fop/render/ps/PSResource.java56
6 files changed, 369 insertions, 144 deletions
diff --git a/src/java/org/apache/fop/render/ps/DSCConstants.java b/src/java/org/apache/fop/render/ps/DSCConstants.java
index 653d9b543..f87b744db 100644
--- a/src/java/org/apache/fop/render/ps/DSCConstants.java
+++ b/src/java/org/apache/fop/render/ps/DSCConstants.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.
@@ -21,8 +21,7 @@ package org.apache.fop.render.ps;
/**
* This class defines constants with Strings for the DSC specification.
*
- * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
- * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
+ * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
* @version $Id: DSCConstants.java,v 1.2 2003/03/07 09:46:30 jeremias Exp $
*/
public class DSCConstants {
@@ -145,6 +144,33 @@ public class DSCConstants {
// ----==== Requirements Conventions ====----
/**@todo Add the missing comments */
+ /**
+ * This comment indicates all types of paper media (paper sizes, weight, color)
+ * this document requires.
+ */
+ public static final String DOCUMENT_MEDIA = "DocumentMedia";
+ /** This comment provides a list of resources the document needs */
+ public static final String DOCUMENT_NEEDED_RESOURCES = "DocumentNeededResources";
+ /** This comment provides a list of resources the document includes */
+ public static final String DOCUMENT_SUPPLIED_RESOURCES = "DocumentSuppliedResources";
+ //Skipping %%DocumentPrinterRequired
+ //Skipping %%DocumentNeededFiles -> deprecated
+ //Skipping %%DocumentSuppliedFiles -> deprecated
+ //Skipping %%DocumentFonts -> deprecated
+ //Skipping %%DocumentNeededFonts -> deprecated
+ //Skipping %%DocumentSuppliedFonts -> deprecated
+ //Skipping %%DocumentNeededProcSets -> deprecated
+ //Skipping %%DocumentSuppliedProcSets -> deprecated
+ //Skipping %%OperatorIntervention
+ //Skipping %%OperatorMessage
+ //Skipping %%ProofMode
+ /**
+ * This comment describes document requirements, such as duplex printing,
+ * hole punching, collating, or other physical document processing needs.
+ */
+ public static final String REQUIREMENTS = "Requirements";
+ //Skipping %%VMlocation
+ //Skipping %%VMusage
// ----==== Requirement Body Comments ====----
@@ -173,5 +199,21 @@ public class DSCConstants {
/** Indicates a referenced a resource (font, file, procset) */
public static final String INCLUDE_RESOURCE = "IncludeResource";
-
+ // ----==== Requirement Page Comments ====----
+
+ //Skipping %%PageFonts -> deprecated
+ //Skipping %%PageFiles -> deprecated
+ /** Indicates that the paper attributes denoted by medianame are invoked on this page. */
+ public static final String PAGE_MEDIA = "PageMedia";
+ /**
+ * This is the page-level invocation of a combination of the options listed in
+ * the %%Requirements: comment.
+ */
+ public static final String PAGE_REQUIREMENTS = "PageRequirements";
+ /**
+ * This comment indicates the names and values of all resources that are needed
+ * or supplied on the present page.
+ */
+ public static final String PAGE_RESOURCES = "PageResources";
+
}
diff --git a/src/java/org/apache/fop/render/ps/PSGenerator.java b/src/java/org/apache/fop/render/ps/PSGenerator.java
index 9a21cb0db..f6835c31c 100644
--- a/src/java/org/apache/fop/render/ps/PSGenerator.java
+++ b/src/java/org/apache/fop/render/ps/PSGenerator.java
@@ -26,13 +26,15 @@ import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Date;
+import java.util.Iterator;
import java.util.Locale;
+import java.util.Set;
import java.util.Stack;
/**
* This class is used to output PostScript code to an OutputStream.
*
- * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
+ * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
* @version $Id$
*/
public class PSGenerator {
@@ -484,7 +486,87 @@ public class PSGenerator {
writeln(name + " " + formatDouble(size) + " F");
}
}
+
+ private Set documentSuppliedResources;
+ private Set documentNeededResources;
+ private Set pageResources;
+
+ /**
+ * Notifies the generator that a new page has been started and that the page resource
+ * set can be cleared.
+ */
+ public void notifyStartNewPage() {
+ if (pageResources != null) {
+ pageResources.clear();
+ }
+ }
+
+ /**
+ * Notifies the generator about the usage of a resource on the current page.
+ * @param res the resource being used
+ * @param needed true if this is a needed resource, false for a supplied resource
+ */
+ public void notifyResourceUsage(PSResource res, boolean needed) {
+ if (pageResources == null) {
+ pageResources = new java.util.HashSet();
+ }
+ pageResources.add(res);
+ if (needed) {
+ if (documentNeededResources == null) {
+ documentNeededResources = new java.util.HashSet();
+ }
+ documentNeededResources.add(res);
+ } else {
+ if (documentSuppliedResources == null) {
+ documentSuppliedResources = new java.util.HashSet();
+ }
+ documentSuppliedResources.add(res);
+ }
+ }
+ /**
+ * Writes a DSC comment for the accumulated used resources, either at page level or
+ * at document level.
+ * @param pageLevel true if the DSC comment for the page level should be generated,
+ * false for the document level (in the trailer)
+ * @exception IOException In case of an I/O problem
+ */
+ public void writeResources(boolean pageLevel) throws IOException {
+ if (pageLevel) {
+ writeResourceComment(DSCConstants.PAGE_RESOURCES, pageResources);
+ } else {
+ writeResourceComment(DSCConstants.DOCUMENT_NEEDED_RESOURCES,
+ documentNeededResources);
+ writeResourceComment(DSCConstants.DOCUMENT_SUPPLIED_RESOURCES,
+ documentSuppliedResources);
+ }
+ }
+
+ private void writeResourceComment(String name, Set resources) throws IOException {
+ if (resources == null || resources.size() == 0) {
+ return;
+ }
+ tempBuffer.setLength(0);
+ tempBuffer.append("%%");
+ tempBuffer.append(name);
+ tempBuffer.append(" ");
+ boolean first = true;
+ Iterator i = resources.iterator();
+ while (i.hasNext()) {
+ if (!first) {
+ writeln(tempBuffer.toString());
+ tempBuffer.setLength(0);
+ tempBuffer.append("%%+ ");
+ }
+ PSResource res = (PSResource)i.next();
+ tempBuffer.append(res.getType());
+ tempBuffer.append(" ");
+ tempBuffer.append(res.getName());
+ first = false;
+ }
+ writeln(tempBuffer.toString());
+ }
+
/** Used for the ATEND constant. See there. */
private static interface AtendIndicator {
}
diff --git a/src/java/org/apache/fop/render/ps/PSImageUtils.java b/src/java/org/apache/fop/render/ps/PSImageUtils.java
index 812ed9ab8..30998d8ca 100644
--- a/src/java/org/apache/fop/render/ps/PSImageUtils.java
+++ b/src/java/org/apache/fop/render/ps/PSImageUtils.java
@@ -195,6 +195,7 @@ public class PSImageUtils {
float x, float y, float w, float h,
int bboxx, int bboxy, int bboxw, int bboxh,
PSGenerator gen) throws IOException {
+ gen.notifyResourceUsage(PSProcSets.EPS_PROCSET, false);
gen.writeln("%FOPBeginEPS: " + name);
gen.writeln("BeginEPSF");
@@ -212,9 +213,12 @@ public class PSImageUtils {
gen.writeln(gen.formatDouble(bboxy) + " " + gen.formatDouble(bboxy)
+ " " + gen.formatDouble(bboxw) + " " + gen.formatDouble(bboxh) + " re clip");
gen.writeln("newpath");
- gen.writeln("%%BeginDocument: " + name);
+
+ PSResource res = new PSResource(PSResource.TYPE_FILE, name);
+ gen.notifyResourceUsage(res, false);
+ gen.writeDSCComment(DSCConstants.BEGIN_DOCUMENT, res.getName());
gen.writeByteArr(rawEPS);
- gen.writeln("%%EndDocument");
+ gen.writeDSCComment(DSCConstants.END_DOCUMENT);
gen.writeln("EndEPSF");
gen.writeln("%FOPEndEPS");
}
diff --git a/src/java/org/apache/fop/render/ps/PSProcSets.java b/src/java/org/apache/fop/render/ps/PSProcSets.java
index abd019252..c56a26a72 100644
--- a/src/java/org/apache/fop/render/ps/PSProcSets.java
+++ b/src/java/org/apache/fop/render/ps/PSProcSets.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.
@@ -30,114 +30,175 @@ import org.apache.fop.fonts.FontInfo;
* This class defines the basic resources (procsets) used by FOP's PostScript
* renderer and SVG transcoder.
*
- * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
- * @author <a href="mailto:jeremias@apache.org">Jeremias Maerki</a>
+ * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
* @version $Id: PSProcSets.java,v 1.3 2003/03/11 08:42:24 jeremias Exp $
*/
public final class PSProcSets {
+ /** the standard FOP procset */
+ public static final PSResource STD_PROCSET = new StdProcSet();
+ /** the EPS FOP procset */
+ public static final PSResource EPS_PROCSET = new EPSProcSet();
+
+ private static class StdProcSet extends PSResource {
+
+ public StdProcSet() {
+ super("procset", "Apache FOP Std ProcSet");
+ }
+
+ public void writeTo(PSGenerator gen) throws IOException {
+ gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
+ new Object[] {"procset", getName(), "1.0", "0"});
+ gen.writeDSCComment(DSCConstants.VERSION,
+ new Object[] {"1.0", "0"});
+ gen.writeDSCComment(DSCConstants.COPYRIGHT, "Copyright 2001-2003 "
+ + "The Apache Software Foundation. All rights reserved.");
+ gen.writeDSCComment(DSCConstants.TITLE, "Basic set of procedures used by FOP");
+
+ gen.writeln("/bd{bind def}bind def");
+ gen.writeln("/ld{load def}bd");
+ gen.writeln("/M/moveto ld");
+ gen.writeln("/RM/rmoveto ld");
+ gen.writeln("/t/show ld");
+ gen.writeln("/A/ashow ld");
+ gen.writeln("/cp/closepath ld");
+
+ gen.writeln("/re {4 2 roll M"); //define rectangle
+ gen.writeln("1 index 0 rlineto");
+ gen.writeln("0 exch rlineto");
+ gen.writeln("neg 0 rlineto");
+ gen.writeln("cp } bd");
+
+ gen.writeln("/_ctm matrix def"); //Holds the current matrix
+ gen.writeln("/_tm matrix def");
+ //BT: save currentmatrix, set _tm to identitymatrix and move to 0/0
+ gen.writeln("/BT { _ctm currentmatrix pop matrix _tm copy pop 0 0 moveto } bd");
+ //ET: restore last currentmatrix
+ gen.writeln("/ET { _ctm setmatrix } bd");
+ gen.writeln("/iTm { _ctm setmatrix _tm concat } bd");
+ gen.writeln("/Tm { _tm astore pop iTm 0 0 moveto } bd");
+
+ gen.writeln("/ux 0.0 def");
+ gen.writeln("/uy 0.0 def");
+
+ // <font> <size> F
+ gen.writeln("/F {");
+ gen.writeln(" /Tp exch def");
+ // gen.writeln(" currentdict exch get");
+ gen.writeln(" /Tf exch def");
+ gen.writeln(" Tf findfont Tp scalefont setfont");
+ gen.writeln(" /cf Tf def /cs Tp def /cw ( ) stringwidth pop def");
+ gen.writeln("} bd");
+
+ gen.writeln("/ULS {currentpoint /uy exch def /ux exch def} bd");
+ gen.writeln("/ULE {");
+ gen.writeln(" /Tcx currentpoint pop def");
+ gen.writeln(" gsave");
+ gen.writeln(" newpath");
+ gen.writeln(" cf findfont cs scalefont dup");
+ gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
+ gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
+ gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
+ gen.writeln(" ux uy To add moveto Tcx uy To add lineto");
+ gen.writeln(" Tt setlinewidth stroke");
+ gen.writeln(" grestore");
+ gen.writeln("} bd");
+
+ gen.writeln("/OLE {");
+ gen.writeln(" /Tcx currentpoint pop def");
+ gen.writeln(" gsave");
+ gen.writeln(" newpath");
+ gen.writeln(" cf findfont cs scalefont dup");
+ gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
+ gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
+ gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
+ gen.writeln(" ux uy To add cs add moveto Tcx uy To add cs add lineto");
+ gen.writeln(" Tt setlinewidth stroke");
+ gen.writeln(" grestore");
+ gen.writeln("} bd");
+
+ gen.writeln("/SOE {");
+ gen.writeln(" /Tcx currentpoint pop def");
+ gen.writeln(" gsave");
+ gen.writeln(" newpath");
+ gen.writeln(" cf findfont cs scalefont dup");
+ gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
+ gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
+ gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
+ gen.writeln(" ux uy To add cs 10 mul 26 idiv add moveto "
+ + "Tcx uy To add cs 10 mul 26 idiv add lineto");
+ gen.writeln(" Tt setlinewidth stroke");
+ gen.writeln(" grestore");
+ gen.writeln("} bd");
+
+ gen.writeln("/QUADTO {");
+ gen.writeln("/Y22 exch store");
+ gen.writeln("/X22 exch store");
+ gen.writeln("/Y21 exch store");
+ gen.writeln("/X21 exch store");
+ gen.writeln("currentpoint");
+ gen.writeln("/Y21 load 2 mul add 3 div exch");
+ gen.writeln("/X21 load 2 mul add 3 div exch");
+ gen.writeln("/X21 load 2 mul /X22 load add 3 div");
+ gen.writeln("/Y21 load 2 mul /Y22 load add 3 div");
+ gen.writeln("/X22 load /Y22 load curveto");
+ gen.writeln("} bd");
+
+ gen.writeDSCComment(DSCConstants.END_RESOURCE);
+ }
+
+ }
+
+ private static class EPSProcSet extends PSResource {
+
+ public EPSProcSet() {
+ super("procset", "Apache FOP EPS ProcSet");
+ }
+
+ public void writeTo(PSGenerator gen) throws IOException {
+ gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE,
+ new Object[] {"procset", getName(), "1.0", "0"});
+ gen.writeDSCComment(DSCConstants.VERSION,
+ new Object[] {"1.0", "0"});
+ gen.writeDSCComment(DSCConstants.COPYRIGHT, "Copyright 2002-2003 "
+ + "The Apache Software Foundation. All rights reserved.");
+ gen.writeDSCComment(DSCConstants.TITLE, "EPS procedures used by FOP");
+
+ gen.writeln("/BeginEPSF { %def");
+ gen.writeln("/b4_Inc_state save def % Save state for cleanup");
+ gen.writeln("/dict_count countdictstack def % Count objects on dict stack");
+ gen.writeln("/op_count count 1 sub def % Count objects on operand stack");
+ gen.writeln("userdict begin % Push userdict on dict stack");
+ gen.writeln("/showpage { } def % Redefine showpage, { } = null proc");
+ gen.writeln("0 setgray 0 setlinecap % Prepare graphics state");
+ gen.writeln("1 setlinewidth 0 setlinejoin");
+ gen.writeln("10 setmiterlimit [ ] 0 setdash newpath");
+ gen.writeln("/languagelevel where % If level not equal to 1 then");
+ gen.writeln("{pop languagelevel % set strokeadjust and");
+ gen.writeln("1 ne % overprint to their defaults.");
+ gen.writeln("{false setstrokeadjust false setoverprint");
+ gen.writeln("} if");
+ gen.writeln("} if");
+ gen.writeln("} bd");
+
+ gen.writeln("/EndEPSF { %def");
+ gen.writeln("count op_count sub {pop} repeat % Clean up stacks");
+ gen.writeln("countdictstack dict_count sub {end} repeat");
+ gen.writeln("b4_Inc_state restore");
+ gen.writeln("} bd");
+
+ gen.writeDSCComment(DSCConstants.END_RESOURCE);
+ }
+
+ }
+
/**
* Generates a resource defining standard procset for FOP.
* @param gen PSGenerator to use for output
* @throws IOException In case of an I/O problem
*/
- public static final void writeFOPStdProcSet(PSGenerator gen) throws IOException {
- gen.writeln("%%BeginResource: procset (Apache FOP Std ProcSet) 1.0 0");
- gen.writeln("%%Version: 1.0 0");
- gen.writeln("%%Copyright: Copyright (C) 2001-2003 "
- + "The Apache Software Foundation. All rights reserved.");
- gen.writeln("%%Title: Basic set of procedures used by FOP");
-
- gen.writeln("/bd{bind def}bind def");
- gen.writeln("/ld{load def}bd");
- gen.writeln("/M/moveto ld");
- gen.writeln("/RM/rmoveto ld");
- gen.writeln("/t/show ld");
- gen.writeln("/A/ashow ld");
- gen.writeln("/cp/closepath ld");
-
- gen.writeln("/re {4 2 roll M"); //define rectangle
- gen.writeln("1 index 0 rlineto");
- gen.writeln("0 exch rlineto");
- gen.writeln("neg 0 rlineto");
- gen.writeln("cp } bd");
-
- gen.writeln("/_ctm matrix def"); //Holds the current matrix
- gen.writeln("/_tm matrix def");
- //BT: save currentmatrix, set _tm to identitymatrix and move to 0/0
- gen.writeln("/BT { _ctm currentmatrix pop matrix _tm copy pop 0 0 moveto } bd");
- //ET: restore last currentmatrix
- gen.writeln("/ET { _ctm setmatrix } bd");
- gen.writeln("/iTm { _ctm setmatrix _tm concat } bd");
- gen.writeln("/Tm { _tm astore pop iTm 0 0 moveto } bd");
-
- gen.writeln("/ux 0.0 def");
- gen.writeln("/uy 0.0 def");
-
- // <font> <size> F
- gen.writeln("/F {");
- gen.writeln(" /Tp exch def");
- // gen.writeln(" currentdict exch get");
- gen.writeln(" /Tf exch def");
- gen.writeln(" Tf findfont Tp scalefont setfont");
- gen.writeln(" /cf Tf def /cs Tp def /cw ( ) stringwidth pop def");
- gen.writeln("} bd");
-
- gen.writeln("/ULS {currentpoint /uy exch def /ux exch def} bd");
- gen.writeln("/ULE {");
- gen.writeln(" /Tcx currentpoint pop def");
- gen.writeln(" gsave");
- gen.writeln(" newpath");
- gen.writeln(" cf findfont cs scalefont dup");
- gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
- gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
- gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
- gen.writeln(" ux uy To add moveto Tcx uy To add lineto");
- gen.writeln(" Tt setlinewidth stroke");
- gen.writeln(" grestore");
- gen.writeln("} bd");
-
- gen.writeln("/OLE {");
- gen.writeln(" /Tcx currentpoint pop def");
- gen.writeln(" gsave");
- gen.writeln(" newpath");
- gen.writeln(" cf findfont cs scalefont dup");
- gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
- gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
- gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
- gen.writeln(" ux uy To add cs add moveto Tcx uy To add cs add lineto");
- gen.writeln(" Tt setlinewidth stroke");
- gen.writeln(" grestore");
- gen.writeln("} bd");
-
- gen.writeln("/SOE {");
- gen.writeln(" /Tcx currentpoint pop def");
- gen.writeln(" gsave");
- gen.writeln(" newpath");
- gen.writeln(" cf findfont cs scalefont dup");
- gen.writeln(" /FontMatrix get 0 get /Ts exch def /FontInfo get dup");
- gen.writeln(" /UnderlinePosition get Ts mul /To exch def");
- gen.writeln(" /UnderlineThickness get Ts mul /Tt exch def");
- gen.writeln(" ux uy To add cs 10 mul 26 idiv add moveto "
- + "Tcx uy To add cs 10 mul 26 idiv add lineto");
- gen.writeln(" Tt setlinewidth stroke");
- gen.writeln(" grestore");
- gen.writeln("} bd");
-
- gen.writeln("/QUADTO {");
- gen.writeln("/Y22 exch store");
- gen.writeln("/X22 exch store");
- gen.writeln("/Y21 exch store");
- gen.writeln("/X21 exch store");
- gen.writeln("currentpoint");
- gen.writeln("/Y21 load 2 mul add 3 div exch");
- gen.writeln("/X21 load 2 mul add 3 div exch");
- gen.writeln("/X21 load 2 mul /X22 load add 3 div");
- gen.writeln("/Y21 load 2 mul /Y22 load add 3 div");
- gen.writeln("/X22 load /Y22 load curveto");
- gen.writeln("} bd");
-
- gen.writeln("%%EndResource");
+ public static void writeFOPStdProcSet(PSGenerator gen) throws IOException {
+ ((StdProcSet)STD_PROCSET).writeTo(gen);
}
@@ -146,37 +207,8 @@ public final class PSProcSets {
* @param gen PSGenerator to use for output
* @throws IOException In case of an I/O problem
*/
- public static final void writeFOPEPSProcSet(PSGenerator gen) throws IOException {
- gen.writeln("%%BeginResource: procset (Apache FOP EPS ProcSet) 1.0 0");
- gen.writeln("%%Version: 1.0 0");
- gen.writeln("%%Copyright: Copyright (C) 2002-2003 "
- + "The Apache Software Foundation. All rights reserved.");
- gen.writeln("%%Title: EPS procedures used by FOP");
-
- gen.writeln("/BeginEPSF { %def");
- gen.writeln("/b4_Inc_state save def % Save state for cleanup");
- gen.writeln("/dict_count countdictstack def % Count objects on dict stack");
- gen.writeln("/op_count count 1 sub def % Count objects on operand stack");
- gen.writeln("userdict begin % Push userdict on dict stack");
- gen.writeln("/showpage { } def % Redefine showpage, { } = null proc");
- gen.writeln("0 setgray 0 setlinecap % Prepare graphics state");
- gen.writeln("1 setlinewidth 0 setlinejoin");
- gen.writeln("10 setmiterlimit [ ] 0 setdash newpath");
- gen.writeln("/languagelevel where % If level not equal to 1 then");
- gen.writeln("{pop languagelevel % set strokeadjust and");
- gen.writeln("1 ne % overprint to their defaults.");
- gen.writeln("{false setstrokeadjust false setoverprint");
- gen.writeln("} if");
- gen.writeln("} if");
- gen.writeln("} bd");
-
- gen.writeln("/EndEPSF { %def");
- gen.writeln("count op_count sub {pop} repeat % Clean up stacks");
- gen.writeln("countdictstack dict_count sub {end} repeat");
- gen.writeln("b4_Inc_state restore");
- gen.writeln("} bd");
-
- gen.writeln("%%EndResource");
+ public static void writeFOPEPSProcSet(PSGenerator gen) throws IOException {
+ ((EPSProcSet)EPS_PROCSET).writeTo(gen);
}
/**
@@ -187,8 +219,7 @@ public final class PSProcSets {
*/
public static void writeFontDict(PSGenerator gen, FontInfo fontInfo)
throws IOException {
- gen.writeln("%%BeginResource: procset FOPFonts");
- gen.writeln("%%Title: Font setup (shortcuts) for this file");
+ gen.commentln("%FOPBeginFontDict");
gen.writeln("/FOPFonts 100 dict dup begin");
// write("/gfF1{/Helvetica findfont} bd");
@@ -201,7 +232,8 @@ public final class PSProcSets {
gen.writeln("/" + key + " /" + fm.getFontName() + " def");
}
gen.writeln("end def");
- gen.writeln("%%EndResource");
+ gen.commentln("%FOPEndFontDict");
+ gen.commentln("%FOPBeginFontReencode");
defineWinAnsiEncoding(gen);
//Rewrite font encodings
@@ -225,6 +257,7 @@ public final class PSProcSets {
+ fm.getFontName() + "' asks for: " + fm.getEncoding());
}
}
+ gen.commentln("%FOPEndFontReencode");
}
private static void defineWinAnsiEncoding(PSGenerator gen) throws IOException {
diff --git a/src/java/org/apache/fop/render/ps/PSRenderer.java b/src/java/org/apache/fop/render/ps/PSRenderer.java
index ef684b582..5b4688d90 100644
--- a/src/java/org/apache/fop/render/ps/PSRenderer.java
+++ b/src/java/org/apache/fop/render/ps/PSRenderer.java
@@ -70,7 +70,7 @@ import org.w3c.dom.Document;
* may help certain users to do certain types of post-processing of the output.
* These comments all start with "%FOP".
*
- * @author <a href="mailto:fop-dev@xml.apache.org">Apache XML FOP Development Team</a>
+ * @author <a href="mailto:fop-dev@xmlgraphics.apache.org">Apache FOP Development Team</a>
* @version $Id$
*/
public class PSRenderer extends AbstractPathOrientedRenderer {
@@ -553,6 +553,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
gen.writeDSCComment(DSCConstants.CREATION_DATE, new Object[] {new java.util.Date()});
gen.writeDSCComment(DSCConstants.LANGUAGE_LEVEL, new Integer(gen.getPSLevel()));
gen.writeDSCComment(DSCConstants.PAGES, new Object[] {PSGenerator.ATEND});
+ gen.writeDSCComment(DSCConstants.DOCUMENT_SUPPLIED_RESOURCES,
+ new Object[] {PSGenerator.ATEND});
gen.writeDSCComment(DSCConstants.END_COMMENTS);
//Defaults
@@ -561,12 +563,12 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
//Prolog
gen.writeDSCComment(DSCConstants.BEGIN_PROLOG);
+ PSProcSets.writeFOPStdProcSet(gen);
+ PSProcSets.writeFOPEPSProcSet(gen);
gen.writeDSCComment(DSCConstants.END_PROLOG);
//Setup
gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
- PSProcSets.writeFOPStdProcSet(gen);
- PSProcSets.writeFOPEPSProcSet(gen);
PSProcSets.writeFontDict(gen, fontInfo);
gen.writeln("FOPFonts begin");
gen.writeDSCComment(DSCConstants.END_SETUP);
@@ -578,6 +580,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
public void stopRenderer() throws IOException {
gen.writeDSCComment(DSCConstants.TRAILER);
gen.writeDSCComment(DSCConstants.PAGES, new Integer(this.currentPageNumber));
+ gen.writeResources(false);
gen.writeDSCComment(DSCConstants.EOF);
gen.flush();
}
@@ -590,6 +593,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
log.debug("renderPage(): " + page);
this.currentPageNumber++;
+ gen.notifyStartNewPage();
+ gen.notifyResourceUsage(PSProcSets.STD_PROCSET, false);
gen.writeDSCComment(DSCConstants.PAGE, new Object[]
{page.getPageNumberString(),
new Integer(this.currentPageNumber)});
@@ -627,6 +632,8 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
gen.writeDSCComment(DSCConstants.PAGE_ORIENTATION, "Portrait");
}
}
+ gen.writeDSCComment(DSCConstants.PAGE_RESOURCES,
+ new Object[] {PSGenerator.ATEND});
gen.writeDSCComment(DSCConstants.BEGIN_PAGE_SETUP);
if (rotate) {
gen.writeln(Math.round(pspageheight) + " 0 translate");
@@ -648,6 +655,7 @@ public class PSRenderer extends AbstractPathOrientedRenderer {
writeln("showpage");
gen.writeDSCComment(DSCConstants.PAGE_TRAILER);
+ gen.writeResources(true);
gen.writeDSCComment(DSCConstants.END_PAGE);
}
diff --git a/src/java/org/apache/fop/render/ps/PSResource.java b/src/java/org/apache/fop/render/ps/PSResource.java
new file mode 100644
index 000000000..d37850a2e
--- /dev/null
+++ b/src/java/org/apache/fop/render/ps/PSResource.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 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.
+ * 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.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.render.ps;
+
+/**
+ * Represents a PostScript resource (file, font, procset etc.).
+ */
+public class PSResource {
+
+ /** a file resource */
+ public static final String TYPE_FILE = "file";
+ /** a font resource */
+ public static final String TYPE_FONT = "font";
+ /** a procset resource */
+ public static final String TYPE_PROCSET = "procset";
+
+ private String type;
+ private String name;
+
+ /**
+ * Main constructor
+ * @param type type of the resource
+ * @param name name of the resource
+ */
+ public PSResource(String type, String name) {
+ this.type = type;
+ this.name = name;
+ }
+
+ /** @return the type of the resource */
+ public String getType() {
+ return this.type;
+ }
+
+ /** @return the name of the resource */
+ public String getName() {
+ return this.name;
+ }
+
+}