aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2010-08-31 14:20:22 +0000
committerVincent Hennebert <vhennebert@apache.org>2010-08-31 14:20:22 +0000
commit1080c61fb2f07d5995bd1671751f2f4bd11b1f3e (patch)
treedc952ac586ac867b37f639a6afe2c17f5a3f6af1 /src
parent519ac01c92c11a0305f13b7124fe2242cfb5b922 (diff)
downloadxmlgraphics-fop-1080c61fb2f07d5995bd1671751f2f4bd11b1f3e.tar.gz
xmlgraphics-fop-1080c61fb2f07d5995bd1671751f2f4bd11b1f3e.zip
Do not issue a warning if renderer configured to output PostScript level 3. Throw an error instead when it is not the case.
Pass the event producer around. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript@991203 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/render/ps/PSDocumentHandler.java16
-rw-r--r--src/java/org/apache/fop/render/ps/PSEventProducer.java8
-rw-r--r--src/java/org/apache/fop/render/ps/PSEventProducer.xml2
-rw-r--r--src/java/org/apache/fop/render/ps/PSFontUtils.java37
-rw-r--r--src/java/org/apache/fop/render/ps/ResourceHandler.java10
5 files changed, 52 insertions, 21 deletions
diff --git a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
index 1e0411aa5..f5f0fbd24 100644
--- a/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
+++ b/src/java/org/apache/fop/render/ps/PSDocumentHandler.java
@@ -49,6 +49,7 @@ import org.apache.xmlgraphics.ps.dsc.ResourceTracker;
import org.apache.xmlgraphics.ps.dsc.events.DSCCommentBoundingBox;
import org.apache.xmlgraphics.ps.dsc.events.DSCCommentHiResBoundingBox;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.intermediate.AbstractBinaryWritingIFDocumentHandler;
import org.apache.fop.render.intermediate.IFContext;
@@ -104,6 +105,8 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
private static final int COMMENT_DOCUMENT_TRAILER = 1;
private static final int COMMENT_PAGE_TRAILER = 2;
+ private PSEventProducer eventProducer;
+
/**
* Default constructor.
*/
@@ -123,7 +126,9 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
/** {@inheritDoc} */
public void setContext(IFContext context) {
super.setContext(context);
- this.psUtil = new PSRenderingUtil(context.getUserAgent());
+ FOUserAgent userAgent = context.getUserAgent();
+ this.psUtil = new PSRenderingUtil(userAgent);
+ eventProducer = PSEventProducer.Provider.get(userAgent.getEventBroadcaster());
}
/** {@inheritDoc} */
@@ -142,7 +147,7 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
try {
OutputStream out;
if (psUtil.isOptimizeResources()) {
- this.tempFile = File.createTempFile("fop", null);
+ this.tempFile = File.createTempFile("fop", ".ps");
out = new java.io.FileOutputStream(this.tempFile);
out = new java.io.BufferedOutputStream(out);
} else {
@@ -200,8 +205,7 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
gen.writeDSCComment(DSCConstants.BEGIN_SETUP);
PSRenderingUtil.writeSetupCodeList(gen, setupCodeList, "SetupCode");
if (!psUtil.isOptimizeResources()) {
- this.fontResources.addAll(PSFontUtils.writeFontDict(gen, fontInfo,
- PSEventProducer.Provider.get(getUserAgent().getEventBroadcaster())));
+ this.fontResources.addAll(PSFontUtils.writeFontDict(gen, fontInfo, eventProducer));
} else {
gen.commentln("%FOPFontSetup"); //Place-holder, will be replaced in the second pass
}
@@ -256,8 +260,8 @@ public class PSDocumentHandler extends AbstractBinaryWritingIFDocumentHandler {
in = new java.io.BufferedInputStream(in);
try {
try {
- ResourceHandler handler = new ResourceHandler(getUserAgent(), this.fontInfo,
- resTracker, this.formResources);
+ ResourceHandler handler = new ResourceHandler(getUserAgent(), eventProducer,
+ this.fontInfo, resTracker, this.formResources);
handler.process(in, this.outputStream,
this.currentPageNumber, this.documentBoundingBox);
this.outputStream.flush();
diff --git a/src/java/org/apache/fop/render/ps/PSEventProducer.java b/src/java/org/apache/fop/render/ps/PSEventProducer.java
index d702a5701..bffdf2236 100644
--- a/src/java/org/apache/fop/render/ps/PSEventProducer.java
+++ b/src/java/org/apache/fop/render/ps/PSEventProducer.java
@@ -29,7 +29,7 @@ public interface PSEventProducer extends EventProducer {
/** Provider class for the event producer. */
final class Provider {
-
+
private Provider() {
}
@@ -54,10 +54,10 @@ public interface PSEventProducer extends EventProducer {
void postscriptDictionaryParseError(Object source, String content, Exception e);
/**
- * PostScript Level 3 features are being used.
+ * PostScript Level 3 features are necessary.
*
* @param source the event source
- * @event.severity WARN
+ * @event.severity FATAL
*/
- void postscriptLevel3Used(Object source);
+ void postscriptLevel3Needed(Object source);
}
diff --git a/src/java/org/apache/fop/render/ps/PSEventProducer.xml b/src/java/org/apache/fop/render/ps/PSEventProducer.xml
index 213e74e27..64b22d1a4 100644
--- a/src/java/org/apache/fop/render/ps/PSEventProducer.xml
+++ b/src/java/org/apache/fop/render/ps/PSEventProducer.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<catalogue xml:lang="en">
<message key="postscriptDictionaryParseError">Failed to parse dictionary string. Reason: {e}, content = "{content}"</message>
- <message key="postscriptLevel3Used">PostScript Level 3 features are needed to handle this document. Please make sure that your printer supports PostScript Level 3.</message>
+ <message key="postscriptLevel3Needed">PostScript Level 3 features are needed to handle this document.</message>
</catalogue>
diff --git a/src/java/org/apache/fop/render/ps/PSFontUtils.java b/src/java/org/apache/fop/render/ps/PSFontUtils.java
index 07ca0e4b5..5272dccac 100644
--- a/src/java/org/apache/fop/render/ps/PSFontUtils.java
+++ b/src/java/org/apache/fop/render/ps/PSFontUtils.java
@@ -77,9 +77,19 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
*/
public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo)
throws IOException {
- return writeFontDict(gen, fontInfo, (PSEventProducer) null);
+ return writeFontDict(gen, fontInfo, null);
}
+ /**
+ * Generates the PostScript code for the font dictionary. This method should only be
+ * used if no "resource optimization" is performed, i.e. when the fonts are not embedded
+ * in a second pass.
+ * @param gen PostScript generator to use for output
+ * @param fontInfo available fonts
+ * @param eventProducer to report events
+ * @return a Map of PSResource instances representing all defined fonts (key: font key)
+ * @throws IOException in case of an I/O problem
+ */
public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo,
PSEventProducer eventProducer) throws IOException {
return writeFontDict(gen, fontInfo, fontInfo.getFonts(), true, eventProducer);
@@ -92,12 +102,13 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
* @param gen PostScript generator to use for output
* @param fontInfo available fonts
* @param fonts the set of fonts to work with
+ * @param eventProducer the event producer
* @return a Map of PSResource instances representing all defined fonts (key: font key)
* @throws IOException in case of an I/O problem
*/
- public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts)
- throws IOException {
- return writeFontDict(gen, fontInfo, fonts, false, null);
+ public static Map writeFontDict(PSGenerator gen, FontInfo fontInfo, Map fonts,
+ PSEventProducer eventProducer) throws IOException {
+ return writeFontDict(gen, fontInfo, fonts, false, eventProducer);
}
/**
@@ -224,14 +235,12 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
if (in != null) {
if (fontType == FontType.TYPE0) {
if (gen.embedIdentityH()) {
+ checkPostScriptVersion(gen, eventProducer);
/*
* First CID-keyed font to be embedded; add
* %%IncludeResource: comment for ProcSet CIDInit.
*/
gen.includeProcsetCIDInitResource();
- if (eventProducer != null) {
- eventProducer.postscriptLevel3Used(gen);
- }
}
PSResource cidFontResource = embedCIDFont(gen, (MultiByteFont) tf, in);
fontResource = PSFontResource.createFontResource(fontRes,
@@ -268,6 +277,19 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
return fontResource;
}
+ private static void checkPostScriptVersion(PSGenerator gen, PSEventProducer eventProducer) {
+ if (gen.getPSLevel() < 3) {
+ if (eventProducer != null) {
+ eventProducer.postscriptLevel3Needed(gen);
+ } else {
+ throw new IllegalStateException("PostScript Level 3 is"
+ + " required to use TrueType fonts,"
+ + " configured level is "
+ + gen.getPSLevel());
+ }
+ }
+ }
+
private static void embedTrueTypeFont(PSGenerator gen,
SingleByteFont font, InputStream fontStream) throws IOException {
/* See Adobe Technical Note #5012, "The Type 42 Font Format Specification" */
@@ -607,6 +629,7 @@ public class PSFontUtils extends org.apache.xmlgraphics.ps.PSFontUtils {
private static PSResource defineDerivedTrueTypeFont(PSGenerator gen,
PSEventProducer eventProducer, String baseFontName, String fontName,
SingleByteEncoding encoding, List cmaps) throws IOException {
+ checkPostScriptVersion(gen, eventProducer);
PSResource res = new PSResource(PSResource.TYPE_FONT, fontName);
gen.writeDSCComment(DSCConstants.BEGIN_RESOURCE, res);
gen.commentln("%XGCDependencies: font " + baseFontName);
diff --git a/src/java/org/apache/fop/render/ps/ResourceHandler.java b/src/java/org/apache/fop/render/ps/ResourceHandler.java
index 502242c17..5594897ba 100644
--- a/src/java/org/apache/fop/render/ps/ResourceHandler.java
+++ b/src/java/org/apache/fop/render/ps/ResourceHandler.java
@@ -83,6 +83,8 @@ public class ResourceHandler implements DSCParserConstants, PSSupportedFlavors {
private FOUserAgent userAgent;
private FontInfo fontInfo;
+ private PSEventProducer eventProducer;
+
private ResourceTracker resTracker;
//key: URI, values PSImageFormResource
@@ -93,13 +95,15 @@ public class ResourceHandler implements DSCParserConstants, PSSupportedFlavors {
/**
* Main constructor.
* @param userAgent the FO user agent
+ * @param eventProducer the event producer
* @param fontInfo the font information
* @param resTracker the resource tracker to use
* @param formResources Contains all forms used by this document (maintained by PSRenderer)
*/
- public ResourceHandler(FOUserAgent userAgent, FontInfo fontInfo,
- ResourceTracker resTracker, Map formResources) {
+ public ResourceHandler(FOUserAgent userAgent, PSEventProducer eventProducer,
+ FontInfo fontInfo, ResourceTracker resTracker, Map formResources) {
this.userAgent = userAgent;
+ this.eventProducer = eventProducer;
this.fontInfo = fontInfo;
this.resTracker = resTracker;
determineInlineForms(formResources);
@@ -222,7 +226,7 @@ public class ResourceHandler implements DSCParserConstants, PSSupportedFlavors {
if (fontSetupPlaceholder == null) {
throw new DSCException("Didn't find %FOPFontSetup comment in stream");
}
- PSFontUtils.writeFontDict(gen, fontInfo, fontInfo.getUsedFonts());
+ PSFontUtils.writeFontDict(gen, fontInfo, fontInfo.getUsedFonts(), eventProducer);
generateForms(globalFormResources, gen);
//Skip the prolog and to the first page