aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2018-03-05 09:39:38 +0000
committerSimon Steiner <ssteiner@apache.org>2018-03-05 09:39:38 +0000
commit37bfd1135cf869ce3a56e8f49e90b7acb5af7996 (patch)
tree64077ac13cd1a9fc69ba0013309fab59ae286af9
parent1942336d7e574eaf285b36ab88f746d6a8d1b25c (diff)
downloadxmlgraphics-fop-37bfd1135cf869ce3a56e8f49e90b7acb5af7996.tar.gz
xmlgraphics-fop-37bfd1135cf869ce3a56e8f49e90b7acb5af7996.zip
FOP-2773: Images inside a PDF not shown when goca=print-file
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1825861 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java10
-rw-r--r--fop-core/src/main/java/org/apache/fop/afp/AFPResourceManager.java52
-rw-r--r--fop-core/src/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java52
3 files changed, 93 insertions, 21 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java b/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
index e42b07fc5..ac15fa1b6 100644
--- a/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
+++ b/fop-core/src/main/java/org/apache/fop/afp/AFPGraphics2D.java
@@ -58,6 +58,7 @@ import org.apache.xmlgraphics.util.UnitConv;
import org.apache.fop.afp.goca.GraphicsSetLineType;
import org.apache.fop.afp.modca.GraphicsObject;
+import org.apache.fop.afp.modca.ResourceObject;
import org.apache.fop.afp.util.CubicBezierApproximator;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.render.afp.AFPImageHandlerRenderedImage;
@@ -626,7 +627,12 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
double h = toMillipointFactor * imgHeight * -gat.getScaleY();
AFPImageHandlerRenderedImage handler = new AFPImageHandlerRenderedImage();
- ImageInfo imageInfo = new ImageInfo(null, null);
+ String uri = null;
+ if (resourceManager.getResourceLevelDefaults()
+ .getDefaultResourceLevel(ResourceObject.TYPE_GRAPHIC).isPrintFile()) {
+ uri = resourceInfo.getUri();
+ }
+ ImageInfo imageInfo = new ImageInfo(uri, null);
imageInfo.setSize(new ImageSize(
img.getWidth(), img.getHeight(), paintingState.getResolution()));
imageInfo.getSize().calcSizeFromPixels();
@@ -638,11 +644,13 @@ public class AFPGraphics2D extends AbstractGraphics2D implements NativeImageHand
(int)Math.round(h));
AFPRenderingContext context = new AFPRenderingContext(null,
resourceManager, paintingState, fontInfo, null);
+ resourceManager.includeCached = false;
try {
handler.handleImage(context, red, targetPos);
} catch (IOException ioe) {
handleIOException(ioe);
}
+ resourceManager.includeCached = true;
}
/**
diff --git a/fop-core/src/main/java/org/apache/fop/afp/AFPResourceManager.java b/fop-core/src/main/java/org/apache/fop/afp/AFPResourceManager.java
index 255abd938..459f0e9a6 100644
--- a/fop-core/src/main/java/org/apache/fop/afp/AFPResourceManager.java
+++ b/fop-core/src/main/java/org/apache/fop/afp/AFPResourceManager.java
@@ -25,6 +25,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
@@ -74,10 +77,13 @@ public class AFPResourceManager {
private int instreamObjectCount;
/** Mapping of resourceInfo to AbstractCachedObject */
- private final Map<AFPResourceInfo, AbstractCachedObject> includeObjectCache
- = new java.util.HashMap<AFPResourceInfo, AbstractCachedObject>();
+ private final Map<AFPResourceInfo, List<AbstractCachedObject>> includeObjectCache =
+ new HashMap<AFPResourceInfo, List<AbstractCachedObject>>();
+
private AFPResourceLevelDefaults resourceLevelDefaults = new AFPResourceLevelDefaults();
+ protected boolean includeCached = true;
+
/**
* Main constructor
*
@@ -262,7 +268,7 @@ public class AFPResourceManager {
cachedObject.includeObject();
- includeObjectCache.put(dataObjectInfo.getResourceInfo(), cachedObject);
+ addToCache(dataObjectInfo.getResourceInfo(), cachedObject);
//The data field of dataObjectInfo is not further required
// therefore we are safe to null the reference, saving memory
@@ -270,6 +276,15 @@ public class AFPResourceManager {
}
+ private void addToCache(AFPResourceInfo resourceInfo, AbstractCachedObject cachedObject) {
+ List<AbstractCachedObject> objs = includeObjectCache.get(resourceInfo);
+ if (objs == null) {
+ objs = new ArrayList<AbstractCachedObject>();
+ includeObjectCache.put(resourceInfo, objs);
+ }
+ objs.add(cachedObject);
+ }
+
/**
* Returns {@code true} if the passed {@link AFPResourceInfo} instance is already cached.
*
@@ -287,17 +302,14 @@ public class AFPResourceManager {
* @return {@code true} if ...
*/
public boolean includeCachedObject(AFPResourceInfo resourceInfo, AFPObjectAreaInfo areaInfo) {
-
- String objectName;
-
- AbstractCachedObject cachedObject = includeObjectCache.get(resourceInfo);
-
- if (cachedObject != null) {
- if (areaInfo != null) {
- cachedObject.dataObjectInfo.setObjectAreaInfo(areaInfo);
+ List<AbstractCachedObject> cachedObjectList = includeObjectCache.get(resourceInfo);
+ if (cachedObjectList != null && includeCached) {
+ for (AbstractCachedObject cachedObject : cachedObjectList) {
+ if (areaInfo != null && cachedObjectList.size() == 1) {
+ cachedObject.dataObjectInfo.setObjectAreaInfo(areaInfo);
+ }
+ cachedObject.includeObject();
}
- cachedObject.includeObject();
-
return true;
} else {
return false;
@@ -399,7 +411,7 @@ public class AFPResourceManager {
resourceInfo.setName(resourceName);
resourceInfo.setUri(uri.toASCIIString());
- AbstractCachedObject cachedObject = includeObjectCache.get(resourceInfo);
+ List<AbstractCachedObject> cachedObject = includeObjectCache.get(resourceInfo);
if (cachedObject == null) {
if (log.isDebugEnabled()) {
log.debug("Adding included resource: " + resourceName);
@@ -441,10 +453,10 @@ public class AFPResourceManager {
}
//TODO what is the data object?
- cachedObject = new CachedObject(resourceName, null);
+ CachedObject newcachedObject = new CachedObject(resourceName, null);
// record mapping of resource info to data object resource name
- includeObjectCache.put(resourceInfo, cachedObject);
+ addToCache(resourceInfo, newcachedObject);
} else {
//skip, already created
}
@@ -484,8 +496,8 @@ public class AFPResourceManager {
resourceInfo.setName(resourceName);
resourceInfo.setUri(uri.toASCIIString());
- AbstractCachedObject cachedObject = includeObjectCache.get(resourceInfo);
- if (cachedObject == null) {
+ List<AbstractCachedObject> resource = includeObjectCache.get(resourceInfo);
+ if (resource == null) {
ResourceGroup resourceGroup = streamer.getResourceGroup(resourceLevel);
//resourceObject delegates write commands to copyNamedResource()
@@ -512,8 +524,8 @@ public class AFPResourceManager {
protected void writeEnd(OutputStream os) throws IOException { }
};
resourceGroup.addObject(resourceObject);
- cachedObject = new CachedObject(resourceName, null);
- includeObjectCache.put(resourceInfo, cachedObject);
+ CachedObject newresource = new CachedObject(resourceName, null);
+ addToCache(resourceInfo, newresource);
}
}
diff --git a/fop-core/src/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java b/fop-core/src/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java
index 9d805a7da..2387692c9 100644
--- a/fop-core/src/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java
@@ -19,6 +19,10 @@
package org.apache.fop.afp;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@@ -26,12 +30,16 @@ import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
import org.apache.xmlgraphics.util.MimeConstants;
import org.apache.fop.apps.io.ResourceResolverFactory;
+import org.apache.fop.render.afp.AFPParser;
/**
* Test case for {@link AFPResourceManager}.
@@ -90,4 +98,48 @@ public class AFPResourceManagerTestCase {
dataInfo.setObjectAreaInfo(objectAreaInfo);
return dataInfo;
}
+
+ @Test
+ public void testIncludeObject() throws IOException {
+ sut.createObject(createAFPGraphicsObjectInfo());
+ sut.createObject(createAFPGraphicsObjectInfo());
+ StringBuilder sb = new StringBuilder();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ sut.getDataStream().getCurrentPage().writeToStream(bos);
+ new AFPParser(true).read(new ByteArrayInputStream(bos.toByteArray()), sb);
+ assertEquals(sb.toString(), "BEGIN PAGE PGN00001\n"
+ + "BEGIN ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ + "DESCRIPTOR PAGE\n"
+ + "MIGRATION PRESENTATION_TEXT\n"
+ + "END ACTIVE_ENVIRONMENT_GROUP AEG00001\n"
+ + "INCLUDE DATA_RESOURCE\n"
+ + "INCLUDE DATA_RESOURCE\n"
+ + "INCLUDE DATA_RESOURCE\n"
+ + "INCLUDE DATA_RESOURCE\n");
+ }
+
+ private AFPGraphicsObjectInfo createAFPGraphicsObjectInfo() {
+ final AFPGraphicsObjectInfo dataInfo = new AFPGraphicsObjectInfo();
+ final String uri = "test";
+ dataInfo.setUri(uri);
+ AFPGraphics2D graphics2D = new AFPGraphics2D(false, new AFPPaintingState(), null, null, null);
+ graphics2D.setGraphicContext(new GraphicContext());
+ dataInfo.setGraphics2D(graphics2D);
+ dataInfo.setPainter(new Graphics2DImagePainter() {
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ try {
+ AFPDataObjectInfo dataObjectInfo = createAFPDataObjectInfo();
+ dataObjectInfo.setUri(uri);
+ sut.createObject(dataObjectInfo);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ public Dimension getImageSize() {
+ return null;
+ }
+ });
+ dataInfo.setObjectAreaInfo(new AFPObjectAreaInfo(0, 0, 0, 0, 0, 0));
+ return dataInfo;
+ }
}