You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by vh...@apache.org on 2014/04/04 17:52:31 UTC
svn commit: r1584765 - in /xmlgraphics/fop/trunk:
src/java/org/apache/fop/pdf/ src/java/org/apache/fop/render/pdf/
src/java/org/apache/fop/svg/ test/java/org/apache/fop/events/
test/java/org/apache/fop/render/pdf/ test/xml/pdf-a/
Author: vhennebert
Date: Fri Apr 4 15:52:30 2014
New Revision: 1584765
URL: http://svn.apache.org/r1584765
Log:
FOP-2363: Better error message when PDF/A enabled and SVG contains bitmap with transparency
Added:
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java (with props)
xmlgraphics/fop/trunk/test/xml/pdf-a/svg-with-transparent-image.fo (with props)
Modified:
xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFProfile.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.java
xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.xml
xmlgraphics/fop/trunk/test/java/org/apache/fop/events/EventChecker.java
xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFProfile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFProfile.java?rev=1584765&r1=1584764&r2=1584765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFProfile.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFProfile.java Fri Apr 4 15:52:30 2014
@@ -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);
}
}
Added: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java?rev=1584765&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java (added)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java Fri Apr 4 15:52:30 2014
@@ -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;
+ }
+
+}
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/TransparencyDisallowedException.java
------------------------------------------------------------------------------
svn:keywords = Revision Id
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java?rev=1584765&r1=1584764&r2=1584765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java Fri Apr 4 15:52:30 2014
@@ -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 implemen
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());
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.java?rev=1584765&r1=1584764&r2=1584765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.java Fri Apr 4 15:52:30 2014
@@ -98,4 +98,13 @@ public interface SVGEventProducer extend
*/
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);
}
Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.xml?rev=1584765&r1=1584764&r2=1584765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.xml (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/svg/SVGEventProducer.xml Fri Apr 4 15:52:30 2014
@@ -23,4 +23,5 @@
<message key="svgNotBuilt">SVG graphic could not be built. Reason: {e}</message>
<message key="svgRenderingError">SVG graphic could not be rendered. Reason: {e}</message>
<message key="transparencyIgnored">Transparency in an SVG image will be ignored because {pdfProfile} does not allow it[ (see {uri})].</message>
+ <message key="bitmapWithTransparency">An SVG image is referencing a bitmap with transparency while {pdfProfile} does not allow it[ (see {uri})].</message>
</catalogue>
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/events/EventChecker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/events/EventChecker.java?rev=1584765&r1=1584764&r2=1584765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/events/EventChecker.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/events/EventChecker.java Fri Apr 4 15:52:30 2014
@@ -46,7 +46,7 @@ public class EventChecker implements Eve
if (id.equals(expectedEventID)) {
eventReceived = true;
for (Map.Entry<String, Object> param : expectedParams.entrySet()) {
- assertEquals(event.getParam(param.getKey()), param.getValue());
+ assertEquals(param.getValue(), event.getParam(param.getKey()));
}
}
}
Modified: xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java?rev=1584765&r1=1584764&r2=1584765&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java (original)
+++ xmlgraphics/fop/trunk/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java Fri Apr 4 15:52:30 2014
@@ -115,15 +115,29 @@ public class PDFAConformanceTestCase ext
@Test
public void svgTransparency() throws Exception {
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("pdfProfile", PDFAMode.PDFA_1B);
- EventChecker eventChecker = new EventChecker(SVGEventProducer.class.getName()
- + ".transparencyIgnored", params);
FOUserAgent ua = getUserAgent();
- ua.getEventBroadcaster().addEventListener(eventChecker);
+ EventChecker eventChecker = setupEventChecker(ua, "transparencyIgnored");
File foFile = new File(foBaseDir, "svg-transparency.fo");
convertFO(foFile, ua, dumpPDF);
eventChecker.end();
}
+ @Test
+ public void svgContainingBitmapWithTransparency() throws Exception {
+ FOUserAgent ua = getUserAgent();
+ EventChecker eventChecker = setupEventChecker(ua, "bitmapWithTransparency");
+ File foFile = new File(foBaseDir, "svg-with-transparent-image.fo");
+ convertFO(foFile, ua, dumpPDF);
+ eventChecker.end();
+ }
+
+ private EventChecker setupEventChecker(FOUserAgent ua, String expectedEvent) {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("pdfProfile", PDFAMode.PDFA_1B);
+ EventChecker eventChecker = new EventChecker(SVGEventProducer.class.getName()
+ + "." + expectedEvent, params);
+ ua.getEventBroadcaster().addEventListener(eventChecker);
+ return eventChecker;
+ }
+
}
Added: xmlgraphics/fop/trunk/test/xml/pdf-a/svg-with-transparent-image.fo
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/xml/pdf-a/svg-with-transparent-image.fo?rev=1584765&view=auto
==============================================================================
--- xmlgraphics/fop/trunk/test/xml/pdf-a/svg-with-transparent-image.fo (added)
+++ xmlgraphics/fop/trunk/test/xml/pdf-a/svg-with-transparent-image.fo Fri Apr 4 15:52:30 2014
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-family="Gladiator">
+ <fo:layout-master-set>
+ <fo:simple-page-master master-name="page"
+ page-height="320pt" page-width="420pt" margin="10pt">
+ <fo:region-body display-align="center"/>
+ </fo:simple-page-master>
+ </fo:layout-master-set>
+ <fo:page-sequence master-reference="page">
+ <fo:flow flow-name="xsl-region-body" text-align="center">
+ <fo:block start-indent="50pt" end-indent="50pt" font-size="15pt" space-after="10pt">SVG
+ referencing a bitmap image that has transparency</fo:block>
+ <fo:block><fo:instream-foreign-object>
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="100" height="100">
+ <rect x="0" y="0" width="100%" height="100%" fill="none" stroke="black"
+ stroke-width="2"/>
+ <image x="0" y="0" width="100%" height="100%"
+ xlink:href="resources/images/list-item.png"/>
+ </svg>
+ </fo:instream-foreign-object></fo:block>
+ </fo:flow>
+ </fo:page-sequence>
+</fo:root>
Propchange: xmlgraphics/fop/trunk/test/xml/pdf-a/svg-with-transparent-image.fo
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/fop/trunk/test/xml/pdf-a/svg-with-transparent-image.fo
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org