From 5cae15e0accf7bb753111394ba9870f5b815ab29 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 4 Apr 2014 15:52:30 +0000 Subject: FOP-2363: Better error message when PDF/A enabled and SVG contains bitmap with transparency git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1584765 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFProfile.java | 3 +- .../fop/pdf/TransparencyDisallowedException.java | 57 ++++++++++++++++++++++ .../apache/fop/render/pdf/PDFImageHandlerSVG.java | 5 ++ src/java/org/apache/fop/svg/SVGEventProducer.java | 9 ++++ src/java/org/apache/fop/svg/SVGEventProducer.xml | 1 + 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 src/java/org/apache/fop/pdf/TransparencyDisallowedException.java (limited to 'src') diff --git a/src/java/org/apache/fop/pdf/PDFProfile.java b/src/java/org/apache/fop/pdf/PDFProfile.java index 4ae5ba8df..4289d0ee8 100644 --- a/src/java/org/apache/fop/pdf/PDFProfile.java +++ b/src/java/org/apache/fop/pdf/PDFProfile.java @@ -171,8 +171,7 @@ public class PDFProfile { public void verifyTransparencyAllowed(String context) { Object profile = isTransparencyAllowed(); if (profile != null) { - throw new PDFConformanceException(profile + " does not allow the use of transparency. (" - + profile + ")"); + throw new TransparencyDisallowedException(profile, context); } } diff --git a/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java b/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java new file mode 100644 index 000000000..11d8baf54 --- /dev/null +++ b/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.pdf; + +/** + * The PDF profile being used does not allow transparency. + */ +public class TransparencyDisallowedException extends PDFConformanceException { + + private static final long serialVersionUID = -1653621832449817596L; + + private final Object profile; + + private final String context; + + public TransparencyDisallowedException(Object profile, String context) { + super(profile + " does not allow the use of transparency." + + (context == null ? "" : " (" + context + ")")); + this.profile = profile; + this.context = context; + } + + /** + * Returns the profile that is being used and disallows transparency. + * + * @see PDFAMode + * @see PDFXMode + */ + public Object getProfile() { + return profile; + } + + /** + * Returns context information to help spotting the problem. + */ + public String getContext() { + return context; + } + +} diff --git a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java index ae282f149..a71fe9417 100644 --- a/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java +++ b/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java @@ -44,6 +44,7 @@ import org.apache.fop.apps.FOUserAgent; import org.apache.fop.events.EventBroadcaster; import org.apache.fop.image.loader.batik.BatikImageFlavors; import org.apache.fop.image.loader.batik.BatikUtil; +import org.apache.fop.pdf.TransparencyDisallowedException; import org.apache.fop.render.ImageHandler; import org.apache.fop.render.ImageHandlerUtil; import org.apache.fop.render.RenderingContext; @@ -207,6 +208,10 @@ public class PDFImageHandlerSVG implements ImageHandler { root.paint(graphics); ctx.dispose(); generator.add(graphics.getString()); + } catch (TransparencyDisallowedException e) { + SVGEventProducer eventProducer = SVGEventProducer.Provider.get( + context.getUserAgent().getEventBroadcaster()); + eventProducer.bitmapWithTransparency(this, e.getProfile(), image.getInfo().getOriginalURI()); } catch (Exception e) { SVGEventProducer eventProducer = SVGEventProducer.Provider.get( context.getUserAgent().getEventBroadcaster()); diff --git a/src/java/org/apache/fop/svg/SVGEventProducer.java b/src/java/org/apache/fop/svg/SVGEventProducer.java index 6bf7ed100..fd529ef04 100644 --- a/src/java/org/apache/fop/svg/SVGEventProducer.java +++ b/src/java/org/apache/fop/svg/SVGEventProducer.java @@ -98,4 +98,13 @@ public interface SVGEventProducer extends EventProducer { */ void transparencyIgnored(Object source, Object pdfProfile, String uri); + + /** + * SVG references a bitmap image that contains transparency while it is not allowed. + * @param source the event source + * @param pdfProfile the PDF profile that disallows transparency + * @param uri the image URI, if available + * @event.severity ERROR + */ + void bitmapWithTransparency(Object source, Object pdfProfile, String uri); } diff --git a/src/java/org/apache/fop/svg/SVGEventProducer.xml b/src/java/org/apache/fop/svg/SVGEventProducer.xml index f5e1d300a..e7d9b555d 100644 --- a/src/java/org/apache/fop/svg/SVGEventProducer.xml +++ b/src/java/org/apache/fop/svg/SVGEventProducer.xml @@ -23,4 +23,5 @@ SVG graphic could not be built. Reason: {e} SVG graphic could not be rendered. Reason: {e} Transparency in an SVG image will be ignored because {pdfProfile} does not allow it[ (see {uri})]. + An SVG image is referencing a bitmap with transparency while {pdfProfile} does not allow it[ (see {uri})]. -- cgit v1.2.3