aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2014-04-30 18:20:40 +0000
committerVincent Hennebert <vhennebert@apache.org>2014-04-30 18:20:40 +0000
commitac6fc935d8a34b9933b80093473344aba22bb488 (patch)
tree6a48bdae910696f7c3233f96bec34f114625f791 /src/java/org/apache
parent57ccdb8751394586dd27a057feba7ff4039aba38 (diff)
parent25460e0663a0c6dd9ecd5d5f9fc219190ad88a5d (diff)
downloadxmlgraphics-fop-ac6fc935d8a34b9933b80093473344aba22bb488.tar.gz
xmlgraphics-fop-ac6fc935d8a34b9933b80093473344aba22bb488.zip
Brought the branch in sync with rev. 1590916 of trunkTemp_WhitespaceManagement
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_WhitespaceManagement@1591437 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/fop/pdf/PDFProfile.java3
-rw-r--r--src/java/org/apache/fop/pdf/PDFResources.java31
-rw-r--r--src/java/org/apache/fop/pdf/TransparencyDisallowedException.java57
-rw-r--r--src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java6
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFContentGenerator.java7
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java5
-rw-r--r--src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java14
-rw-r--r--src/java/org/apache/fop/svg/AbstractFOPTextPainter.java15
-rw-r--r--src/java/org/apache/fop/svg/SVGEventProducer.java9
-rw-r--r--src/java/org/apache/fop/svg/SVGEventProducer.xml1
10 files changed, 139 insertions, 9 deletions
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/PDFResources.java b/src/java/org/apache/fop/pdf/PDFResources.java
index 6d09d5738..dc6319f07 100644
--- a/src/java/org/apache/fop/pdf/PDFResources.java
+++ b/src/java/org/apache/fop/pdf/PDFResources.java
@@ -45,7 +45,7 @@ public class PDFResources extends PDFDictionary {
/**
* /Font objects keyed by their internal name
*/
- protected Map<String, PDFFont> fonts = new LinkedHashMap<String, PDFFont>();
+ protected Map<String, PDFDictionary> fonts = new LinkedHashMap<String, PDFDictionary>();
/**
* Set of XObjects
@@ -76,6 +76,8 @@ public class PDFResources extends PDFDictionary {
/** Named properties */
protected Map<String, PDFReference> properties = new LinkedHashMap<String, PDFReference>();
+ private PDFResources parent;
+
/**
* create a /Resources object.
*
@@ -87,13 +89,29 @@ public class PDFResources extends PDFDictionary {
setObjectNumber(objnum);
}
+ public void setParentResources(PDFResources p) {
+ parent = p;
+ }
+
+ public PDFResources getParentResources() {
+ return parent;
+ }
+
/**
* add font object to resources list.
*
* @param font the PDFFont to add
*/
public void addFont(PDFFont font) {
- this.fonts.put(font.getName(), font);
+ fonts.put(font.getName(), font);
+ }
+
+ public void addFont(String name, PDFDictionary font) {
+ fonts.put(name, font);
+ }
+
+ public Map<String, PDFDictionary> getFonts() {
+ return fonts;
}
/**
@@ -220,12 +238,17 @@ public class PDFResources extends PDFDictionary {
}
private void populateDictionary() {
- if (!this.fonts.isEmpty()) {
+ if (!this.fonts.isEmpty() || (parent != null && !parent.getFonts().isEmpty())) {
PDFDictionary dict = new PDFDictionary(this);
/* construct PDF dictionary of font object references */
- for (Map.Entry<String, PDFFont> entry : fonts.entrySet()) {
+ for (Map.Entry<String, PDFDictionary> entry : fonts.entrySet()) {
dict.put(entry.getKey(), entry.getValue());
}
+ if (parent != null) {
+ for (Map.Entry<String, PDFDictionary> entry : parent.getFonts().entrySet()) {
+ dict.put(entry.getKey(), entry.getValue());
+ }
+ }
put("Font", dict);
}
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/bitmap/AbstractBitmapDocumentHandler.java b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
index 8d0ce14ac..374fa5833 100644
--- a/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
+++ b/src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java
@@ -229,7 +229,10 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin
}
//Set up bitmap to paint on
- this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
+ if (currentImage == null || currentImage.getWidth() != bitmapWidth
+ || currentImage.getHeight() != bitmapHeight) {
+ currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
+ }
Graphics2D graphics2D = this.currentImage.createGraphics();
// draw page background
@@ -316,7 +319,6 @@ public abstract class AbstractBitmapDocumentHandler extends AbstractBinaryWritin
this.multiImageWriter.writeImage(this.currentImage,
getSettings().getWriterParams());
}
- this.currentImage = null;
} catch (IOException ioe) {
throw new IFException("I/O error while encoding BufferedImage", ioe);
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
index ac7b1d905..3f75554fb 100644
--- a/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
+++ b/src/java/org/apache/fop/render/pdf/PDFContentGenerator.java
@@ -486,6 +486,13 @@ public class PDFContentGenerator {
restoreGraphicsState();
}
+ public void placeImage(AffineTransform at, String stream) {
+ saveGraphicsState();
+ concatenate(at);
+ add(stream);
+ restoreGraphicsState();
+ }
+
/**
* Places a previously registered image at a certain place on the page,
* bracketing it as a marked-content sequence.
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/render/ps/PSImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java
index d943f1ce8..6b5745e86 100644
--- a/src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java
+++ b/src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java
@@ -19,9 +19,12 @@
package org.apache.fop.render.ps;
+import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.RenderedImage;
import java.io.IOException;
@@ -63,6 +66,17 @@ public class PSImageHandlerRenderedImage implements PSImageHandler {
Rectangle2D targetRect = new Rectangle2D.Double(x, y, w, h);
RenderedImage ri = imageRend.getRenderedImage();
+
+ if (ri instanceof BufferedImage && ri.getColorModel().hasAlpha()) {
+ BufferedImage convertedImg = new BufferedImage(ri.getWidth(), ri.getHeight(), BufferedImage.TYPE_INT_RGB);
+ Graphics2D g = (Graphics2D) convertedImg.getGraphics();
+ g.setBackground(Color.WHITE);
+ g.clearRect(0, 0, ri.getWidth(), ri.getHeight());
+ g.drawImage((BufferedImage)ri, 0, 0, null);
+ g.dispose();
+ ri = convertedImg;
+ }
+
ImageEncoder encoder = ImageEncodingHelper.createRenderedImageEncoder(ri);
Dimension imgDim = new Dimension(ri.getWidth(), ri.getHeight());
String imgDescription = ri.getClass().getName();
diff --git a/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java b/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java
index 7df127d3a..9cb868448 100644
--- a/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java
+++ b/src/java/org/apache/fop/svg/AbstractFOPTextPainter.java
@@ -152,8 +152,21 @@ public abstract class AbstractFOPTextPainter implements TextPainter {
double y = outputLocation.getY();
try {
try {
+ AFPGraphics2D afpg2d = (AFPGraphics2D)g2d;
+ int fontSize = 0;
+ if (font != null) {
+ fontSize = (int) Math.round(afpg2d.convertToAbsoluteLength(font.getFontSize()));
+ }
+ if (fontSize < 6000) {
+ nativeTextHandler.drawString(g2d, txt, (float) (x + tx), (float) y);
+ } else {
+ double scaleX = g2d.getTransform().getScaleX();
+ for (int i = 0; i < txt.length(); i++) {
+ double ad = run.getLayout().getGlyphAdvances()[i] * scaleX;
+ nativeTextHandler.drawString(g2d, txt.charAt(i) + "", (float) (x + tx + ad), (float) y);
+ }
+ }
//TODO draw underline and overline if set
- nativeTextHandler.drawString(g2d, txt, (float) (x + tx), (float) y);
//TODO draw strikethrough if set
} catch (IOException ioe) {
if (g2d instanceof AFPGraphics2D) {
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 @@
<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>