aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core/src/main
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2022-02-14 14:54:33 +0000
committerSimon Steiner <ssteiner@apache.org>2022-02-14 14:54:33 +0000
commitef84640cc1f7020a4d2090923ea0e35be45a6743 (patch)
treeebbbaaae8c59bae2853929090570cee280693358 /fop-core/src/main
parenta60d463293648f5c8449c464718ef77e0a38306d (diff)
downloadxmlgraphics-fop-ef84640cc1f7020a4d2090923ea0e35be45a6743.tar.gz
xmlgraphics-fop-ef84640cc1f7020a4d2090923ea0e35be45a6743.zip
FOP-3055: Use a event for a draw image error
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1898074 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core/src/main')
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java7
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java36
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java18
-rw-r--r--fop-core/src/main/java/org/apache/fop/render/ps/ResourceHandler.java4
4 files changed, 40 insertions, 25 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java b/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
index e9499f881..fbcd16487 100644
--- a/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/intermediate/AbstractIFPainter.java
@@ -51,6 +51,7 @@ import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.MultiByteFont;
import org.apache.fop.fonts.truetype.SVGGlyphData;
+import org.apache.fop.pdf.PDFConformanceException;
import org.apache.fop.render.ImageHandler;
import org.apache.fop.render.ImageHandlerRegistry;
import org.apache.fop.render.ImageHandlerUtil;
@@ -171,10 +172,12 @@ public abstract class AbstractIFPainter<T extends IFDocumentHandler> implements
try {
drawImage(img, rect, context);
- } catch (IOException ioe) {
+ } catch (PDFConformanceException e) {
+ throw e;
+ } catch (Exception e) {
ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
getUserAgent().getEventBroadcaster());
- eventProducer.imageWritingError(this, ioe);
+ eventProducer.imageWritingError(this, e);
}
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java b/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
index 3988fdf09..56a9eba42 100644
--- a/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/ps/PSGraphics2DAdapter.java
@@ -106,25 +106,27 @@ public class PSGraphics2DAdapter extends AbstractGraphics2DAdapter {
// scale to viewbox
transform.translate(fx, fy);
gen.getCurrentState().concatMatrix(transform);
- if (paintAsBitmap) {
- //Fallback solution: Paint to a BufferedImage
- int resolution = Math.round(context.getUserAgent().getTargetResolution());
- RendererContextWrapper ctx = RendererContext.wrapRendererContext(context);
- BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false);
-
- float scale = PDFFactory.DEFAULT_PDF_RESOLUTION
- / context.getUserAgent().getTargetResolution();
- graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null);
- } else {
- if (painter instanceof GeneralGraphics2DImagePainter) {
- PSFontUtils.addFallbackFonts(fontInfo, (GeneralGraphics2DImagePainter) painter);
+ try {
+ if (paintAsBitmap) {
+ //Fallback solution: Paint to a BufferedImage
+ int resolution = Math.round(context.getUserAgent().getTargetResolution());
+ RendererContextWrapper ctx = RendererContext.wrapRendererContext(context);
+ BufferedImage bi = paintToBufferedImage(painter, ctx, resolution, false, false);
+
+ float scale = PDFFactory.DEFAULT_PDF_RESOLUTION
+ / context.getUserAgent().getTargetResolution();
+ graphics.drawImage(bi, new AffineTransform(scale, 0, 0, scale, 0, 0), null);
+ } else {
+ if (painter instanceof GeneralGraphics2DImagePainter) {
+ PSFontUtils.addFallbackFonts(fontInfo, (GeneralGraphics2DImagePainter) painter);
+ }
+ Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
+ painter.paint(graphics, area);
}
- Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, imw, imh);
- painter.paint(graphics, area);
+ } finally {
+ gen.restoreGraphicsState();
+ gen.commentln("%FOPEndGraphics2D");
}
-
- gen.restoreGraphicsState();
- gen.commentln("%FOPEndGraphics2D");
}
}
diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java b/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
index f128ecc8d..aefbb410b 100644
--- a/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
+++ b/fop-core/src/main/java/org/apache/fop/render/ps/PSImageHandlerGraphics2D.java
@@ -98,9 +98,12 @@ public class PSImageHandlerGraphics2D implements PSImageHandler {
if (painter instanceof GeneralGraphics2DImagePainter) {
PSFontUtils.addFallbackFonts(psContext.getFontInfo(), (GeneralGraphics2DImagePainter) painter);
}
- painter.paint(graphics, area);
- gen.restoreGraphicsState();
- gen.commentln("%FOPEndGraphics2D");
+ try {
+ painter.paint(graphics, area);
+ } finally {
+ gen.restoreGraphicsState();
+ gen.commentln("%FOPEndGraphics2D");
+ }
}
/** {@inheritDoc} */
@@ -161,9 +164,12 @@ public class PSImageHandlerGraphics2D implements PSImageHandler {
gen.writeln(" /Filter /SubFileDecode");
gen.writeln(" /DecodeParms << /EODCount 0 /EODString (%FOPEndOfData) >>");
gen.writeln(">> /ReusableStreamDecode filter");
- paintImageG2D(imageG2D, dimensionsMpt, gen, fontInfo);
- gen.writeln("%FOPEndOfData");
- gen.writeln("def");
+ try {
+ paintImageG2D(imageG2D, dimensionsMpt, gen, fontInfo);
+ } finally {
+ gen.writeln("%FOPEndOfData");
+ gen.writeln("def");
+ }
}
@Override
diff --git a/fop-core/src/main/java/org/apache/fop/render/ps/ResourceHandler.java b/fop-core/src/main/java/org/apache/fop/render/ps/ResourceHandler.java
index ac3ad5b10..7144aafd6 100644
--- a/fop-core/src/main/java/org/apache/fop/render/ps/ResourceHandler.java
+++ b/fop-core/src/main/java/org/apache/fop/render/ps/ResourceHandler.java
@@ -327,6 +327,10 @@ public class ResourceHandler implements DSCParserConstants, PSSupportedFlavors {
userAgent.getEventBroadcaster());
eventProducer.imageError(resTracker, (info != null ? info.toString() : uri),
ie, null);
+ } catch (Exception e) {
+ ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
+ userAgent.getEventBroadcaster());
+ eventProducer.imageWritingError(this, e);
}
}