Browse Source

Brought the branch in sync with rev. 1590916 of trunk


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_WhitespaceManagement@1591437 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-2_0
Vincent Hennebert 10 years ago
parent
commit
ac6fc935d8

+ 15
- 0
findbugs-exclude.xml View File

@@ -444,6 +444,21 @@
<Method name="renderSVGDocument"/>
</Or>
</And>
<And>
<Class name="org.apache.fop.render.ps.PSTextPainter"/>
<Or>
<Field name="gen"/>
<Field name="ps"/>
<Field name="psRun"/>
<Field name="textUtil"/>
</Or>
</And>
<And>
<Class name="org.apache.fop.svg.PDFTextPainter"/>
<Or>
<Field name="pdf"/>
</Or>
</And>
</Or>
</Match>
<Match>

+ 1
- 2
src/java/org/apache/fop/pdf/PDFProfile.java View File

@@ -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);
}
}


+ 27
- 4
src/java/org/apache/fop/pdf/PDFResources.java View File

@@ -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);
}


+ 57
- 0
src/java/org/apache/fop/pdf/TransparencyDisallowedException.java View File

@@ -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;
}

}

+ 4
- 2
src/java/org/apache/fop/render/bitmap/AbstractBitmapDocumentHandler.java View File

@@ -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);
}

+ 7
- 0
src/java/org/apache/fop/render/pdf/PDFContentGenerator.java View File

@@ -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.

+ 5
- 0
src/java/org/apache/fop/render/pdf/PDFImageHandlerSVG.java View File

@@ -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());

+ 14
- 0
src/java/org/apache/fop/render/ps/PSImageHandlerRenderedImage.java View File

@@ -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();

+ 14
- 1
src/java/org/apache/fop/svg/AbstractFOPTextPainter.java View File

@@ -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) {

+ 9
- 0
src/java/org/apache/fop/svg/SVGEventProducer.java View File

@@ -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);
}

+ 1
- 0
src/java/org/apache/fop/svg/SVGEventProducer.xml View File

@@ -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>

+ 1
- 1
test/java/org/apache/fop/events/EventChecker.java View File

@@ -46,7 +46,7 @@ public class EventChecker implements EventListener {
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()));
}
}
}

+ 19
- 5
test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java View File

@@ -115,15 +115,29 @@ public class PDFAConformanceTestCase extends BasePDFTest {

@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;
}

}

+ 24
- 0
test/xml/pdf-a/svg-with-transparent-image.fo View File

@@ -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>

Loading…
Cancel
Save