You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2023/05/25 14:34:58 UTC
[xmlgraphics-fop-pdf-images] branch main updated: FOP-3108: Gradient component not displayed correctly after scaling by Dave Roxburgh
This is an automated email from the ASF dual-hosted git repository.
ssteiner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-fop-pdf-images.git
The following commit(s) were added to refs/heads/main by this push:
new 53e5469 FOP-3108: Gradient component not displayed correctly after scaling by Dave Roxburgh
53e5469 is described below
commit 53e5469d1c1c6590f4ac22267686738d8710296a
Author: Simon Steiner <ss...@apache.org>
AuthorDate: Thu May 25 15:34:46 2023 +0100
FOP-3108: Gradient component not displayed correctly after scaling by Dave Roxburgh
---
.../render/pdf/pdfbox/AbstractPDFBoxHandler.java | 19 +--
.../fop/render/pdf/pdfbox/PDFBoxAdapter.java | 146 ++++++++++++++-------
.../fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java | 79 +++++++++++
.../fop/render/pdf/pdfbox/PDFBoxImageHandler.java | 18 ++-
.../apache/fop/render/pdf/pdfbox/UniqueName.java | 56 +++++++-
.../fop/render/pdf/PDFBoxAdapterTestCase.java | 115 ++++++++++++----
.../apache/fop/render/pdf/PDFRotateTestCase.java | 9 +-
.../apache/fop/render/pdf/PDFWriterTestCase.java | 12 +-
.../fop/render/pdf/pdfbox/PDFClonerTestCase.java | 6 +-
9 files changed, 361 insertions(+), 99 deletions(-)
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java b/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
index 758f1b6..3bd5d14 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/AbstractPDFBoxHandler.java
@@ -50,7 +50,7 @@ import org.apache.fop.render.pdf.PDFLogicalStructureHandler;
public abstract class AbstractPDFBoxHandler {
protected Object createStreamForPDF(ImagePDF image, PDFPage targetPage, FOUserAgent userAgent,
- AffineTransform at, FontInfo fontinfo, Rectangle pos,
+ AffineTransform pageAdjust, FontInfo fontinfo, Rectangle destRect,
Map<Integer, PDFArray> pageNumbers,
PDFLogicalStructureHandler handler,
PDFStructElem curentSessionElem) throws IOException {
@@ -62,8 +62,8 @@ public abstract class AbstractPDFBoxHandler {
String originalImageUri = image.getInfo().getOriginalURI();
final int selectedPage = ImageUtil.needPageIndexFromURI(originalImageUri);
- PDDocument pddoc = image.getPDDocument();
- float pdfVersion = pddoc.getDocument().getVersion();
+ PDDocument srcDoc = image.getPDDocument();
+ float pdfVersion = srcDoc.getDocument().getVersion();
Version inputDocVersion = Version.getValueOf(String.valueOf(pdfVersion));
PDFDocument pdfDoc = targetPage.getDocument();
@@ -77,12 +77,11 @@ public abstract class AbstractPDFBoxHandler {
}
//Encryption test
- if (pddoc.isEncrypted()) {
+ if (srcDoc.isEncrypted()) {
getEventProducer(eventBroadcaster).encryptedPdf(this);
return null;
}
-
//Warn about potential problems with PDF/A and PDF/X
if (pdfDoc.getProfile().isPDFAActive()) {
getEventProducer(eventBroadcaster).pdfAActive(this);
@@ -93,7 +92,7 @@ public abstract class AbstractPDFBoxHandler {
Map<Object, Object> objectCachePerFile = getObjectCache(getImagePath(originalImageUri), userAgent);
- PDPage page = pddoc.getPage(selectedPage);
+ PDPage srcPage = srcDoc.getPage(selectedPage);
if (targetPage.getPDFResources().getParentResources() == null) {
PDFResources res = pdfDoc.getFactory().makeResources();
@@ -108,10 +107,12 @@ public abstract class AbstractPDFBoxHandler {
if (handler != null) {
adapter.setCurrentMCID(handler.getPageParentTree().length());
}
- Object stream = adapter.createStreamFromPDFBoxPage(pddoc, page, originalImageUri, at, fontinfo, pos);
+ Object stream = adapter.createStreamFromPDFBoxPage(srcDoc, srcPage, originalImageUri, pageAdjust,
+ (PDFArray)targetPage.get("MediaBox"),
+ fontinfo, destRect);
if (userAgent.isAccessibilityEnabled() && curentSessionElem != null) {
- TaggedPDFConductor conductor = new TaggedPDFConductor(curentSessionElem, handler, page, adapter);
- conductor.handleLogicalStructure(pddoc);
+ TaggedPDFConductor conductor = new TaggedPDFConductor(curentSessionElem, handler, srcPage, adapter);
+ conductor.handleLogicalStructure(srcDoc);
}
return stream;
}
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
index 6cc06d2..0f07eb5 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
@@ -39,8 +39,6 @@ import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
@@ -55,7 +53,6 @@ import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.common.PDStream;
-
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.fop.fonts.FontInfo;
@@ -77,9 +74,6 @@ import org.apache.fop.pdf.PDFStream;
*/
public class PDFBoxAdapter {
- /** logging instance */
- protected static final Log log = LogFactory.getLog(PDFBoxAdapter.class);
-
protected static final Set<String> FILTER_FILTER = Collections.unmodifiableSet(
new HashSet<String>(Arrays.asList("Filter", "DecodeParms")));
@@ -92,6 +86,7 @@ public class PDFBoxAdapter {
private Map<Integer, PDFArray> pageNumbers;
private Collection<String> parentFonts = new ArrayList<String>();
+ // Current Marked Content ID
protected int currentMCID;
protected UniqueName uniqueName;
@@ -168,32 +163,48 @@ public class PDFBoxAdapter {
/**
* Creates a stream (from FOP's PDF library) from a PDF page parsed with PDFBox.
- * @param sourceDoc the source PDF the given page to be copied belongs to
- * @param page the page to transform into a stream
+ * @param sourceDoc the source PDF the given sourcePage to be copied belongs to
+ * @param sourcePage the page to transform into a stream
* @param key value to use as key for the stream
- * @param atdoc adjustment for stream
+ * @param pageAdjust adjustment for annotations
+ * @param targetPageMediaBox The Media Box of the target page.
* @param fontinfo fonts
- * @param pos rectangle
+ * @param destRect rectangle
* @return the stream
* @throws IOException if an I/O error occurs
*/
- public Object createStreamFromPDFBoxPage(PDDocument sourceDoc, PDPage page, String key,
- AffineTransform atdoc, FontInfo fontinfo, Rectangle pos)
- throws IOException {
- COSDictionary sourcePageResources = getResources(page);
- uniqueName = new UniqueName(key, sourcePageResources, pdfDoc.isFormXObjectEnabled());
- handleAnnotations(sourceDoc, page, atdoc, pos);
+ public Object createStreamFromPDFBoxPage(PDDocument sourceDoc, PDPage sourcePage, String key,
+ AffineTransform pageAdjust, PDFArray targetPageMediaBox,
+ FontInfo fontinfo, Rectangle destRect)
+ throws IOException {
+ COSDictionary srcPgResCosDict = getResources(sourcePage);
+ PDResources srcPgResources = sourcePage.getResources();
+ Iterable<COSName> patternNamesIt = null;
+ if (srcPgResources != null) {
+ patternNamesIt = srcPgResources.getPatternNames();
+ }
+ uniqueName = new UniqueName(key, srcPgResCosDict, patternNamesIt, pdfDoc.isFormXObjectEnabled(), destRect);
+ if (uniqueName.hasPatterns()) {
+ key += destRect.getX() + destRect.getY() + destRect.getWidth() + destRect.getHeight();
+ }
+ handleAnnotations(sourceDoc, sourcePage, pageAdjust, destRect);
+
+ PDFBoxAdapterUtil.transformPatterns(targetPageMediaBox,
+ destRect,
+ sourcePage,
+ patternNamesIt);
+
if (pageNumbers.containsKey(targetPage.getPageIndex())) {
pageNumbers.get(targetPage.getPageIndex()).set(0, targetPage.makeReference());
}
- PDStream pdStream = getContents(page);
+ PDStream pdStream = getContents(sourcePage);
- COSDictionary fonts = (COSDictionary)sourcePageResources.getDictionaryObject(COSName.FONT);
+ COSDictionary srcPgFonts = (COSDictionary)srcPgResCosDict.getDictionaryObject(COSName.FONT);
COSDictionary fontsBackup = null;
String newStream = null;
- if (fonts != null && pdfDoc.isMergeFontsEnabled()) {
- fontsBackup = new COSDictionary(fonts);
- MergeFontsPDFWriter m = new MergeFontsPDFWriter(fonts, fontinfo, uniqueName, parentFonts, currentMCID);
+ if (srcPgFonts != null && pdfDoc.isMergeFontsEnabled()) {
+ fontsBackup = new COSDictionary(srcPgFonts);
+ MergeFontsPDFWriter m = new MergeFontsPDFWriter(srcPgFonts, fontinfo, uniqueName, parentFonts, currentMCID);
newStream = m.writeText(pdStream);
}
if (!pdfDoc.isFormXObjectEnabled()) {
@@ -207,13 +218,16 @@ public class PDFBoxAdapter {
}
pdStream = new PDStream(sourceDoc, new ByteArrayInputStream(newStream.getBytes("ISO-8859-1")));
}
- mergeXObj(sourcePageResources, fontinfo, uniqueName);
- PDFDictionary pageResources = (PDFDictionary)cloneForNewDocument(sourcePageResources);
+ mergeXObj(srcPgResCosDict, fontinfo, uniqueName);
+
+ List<COSName> exclude = Arrays.asList(COSName.PATTERN);
+ PDFDictionary pageResources =
+ (PDFDictionary)cloneForNewDocument(srcPgResCosDict, srcPgResCosDict, exclude);
updateMergeFontInfo(pageResources, fontinfo);
- updateXObj(sourcePageResources, pageResources);
+ updateXObj(srcPgResCosDict, pageResources);
if (fontsBackup != null) {
- sourcePageResources.setItem(COSName.FONT, fontsBackup);
+ srcPgResCosDict.setItem(COSName.FONT, fontsBackup);
}
COSStream originalPageContents = pdStream.getCOSObject();
@@ -230,7 +244,7 @@ public class PDFBoxAdapter {
// IOUtils.copyLarge(in, out);
// filter = FILTER_FILTER;
// } else {
- pageStream = (PDFStream)cloneForNewDocument(originalPageContents);
+ pageStream = (PDFStream)cloneForNewDocument(originalPageContents, originalPageContents, exclude);
filter = Collections.EMPTY_SET;
// }
if (pageStream == null) {
@@ -238,37 +252,39 @@ public class PDFBoxAdapter {
}
if (pdfDoc.isFormXObjectEnabled()) {
- return getFormXObject(pageResources, pageStream, key, page);
+ return getFormXObject(pageResources, pageStream, key, sourcePage);
}
if (originalPageContents != null) {
transferDict(originalPageContents, pageStream, filter);
}
- transferPageDict(fonts, uniqueName, sourcePageResources);
+ transferPageDict(srcPgFonts, uniqueName, srcPgResCosDict);
- PDRectangle mediaBox = page.getMediaBox();
- PDRectangle cropBox = page.getCropBox();
+ promotePatterns(targetPage.getPDFResources());
+
+ PDRectangle mediaBox = sourcePage.getMediaBox();
+ PDRectangle cropBox = sourcePage.getCropBox();
PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;
- //Handle the /Rotation entry on the page dict
- int rotation = PDFUtil.getNormalizedRotation(page);
+ //Handle the /Rotation entry on the sourcePage dict
+ int rotation = PDFUtil.getNormalizedRotation(sourcePage);
//Transform to FOP's user space
- float w = (float)pos.getWidth() / 1000f;
- float h = (float)pos.getHeight() / 1000f;
+ float w = (float)destRect.getWidth() / 1000f;
+ float h = (float)destRect.getHeight() / 1000f;
if (rotation == 90 || rotation == 270) {
float tmp = w;
w = h;
h = tmp;
}
- atdoc.setTransform(AffineTransform.getScaleInstance(w / viewBox.getWidth(), h / viewBox.getHeight()));
- atdoc.translate(0, viewBox.getHeight());
- atdoc.rotate(-Math.PI);
- atdoc.scale(-1, 1);
- atdoc.translate(-viewBox.getLowerLeftX(), -viewBox.getLowerLeftY());
+ pageAdjust.setTransform(AffineTransform.getScaleInstance(w / viewBox.getWidth(), h / viewBox.getHeight()));
+ pageAdjust.translate(0, viewBox.getHeight());
+ pageAdjust.rotate(-Math.PI);
+ pageAdjust.scale(-1, 1);
+ pageAdjust.translate(-viewBox.getLowerLeftX(), -viewBox.getLowerLeftY());
- PDFBoxAdapterUtil.rotate(rotation, viewBox, atdoc);
+ PDFBoxAdapterUtil.rotate(rotation, viewBox, pageAdjust);
StringBuilder boxStr = new StringBuilder();
boxStr.append(PDFNumber.doubleOut(mediaBox.getLowerLeftX())).append(' ')
@@ -278,6 +294,35 @@ public class PDFBoxAdapter {
return boxStr.toString() + IOUtils.toString(pdStream.createInputStream(), "ISO-8859-1");
}
+ /**
+ * Move pattern definitions from being embedded in the page resources to being top-level indirect objects.
+ * @param pageResources The target page resources.
+ */
+ private void promotePatterns(PDFDictionary pageResources) {
+ if (pageResources != null) {
+ Object patterns = pageResources.get(COSName.PATTERN.getName());
+ if (patterns != null && patterns instanceof PDFDictionary) {
+ PDFDictionary patternsDict = (PDFDictionary) patterns;
+ Set<String> keys = patternsDict.keySet();
+ for (String key : keys) {
+ PDFObject patternObj = null;
+ Object pattern = patternsDict.get(key);
+ if (pattern instanceof PDFStream) {
+ // Tiling pattern
+ patternObj = (PDFStream)pattern;
+ } else if (pattern instanceof PDFDictionary) {
+ // Shading pattern
+ patternObj = (PDFDictionary)pattern;
+ }
+ if (patternObj != null) {
+ patternObj.setObjectNumber(targetPage.getDocument());
+ targetPage.getDocument().addObject(patternObj);
+ }
+ }
+ }
+ }
+ }
+
private PDStream getContents(PDPage page) throws IOException {
PDStream pdStream = new PDStream(new COSStream());
OutputStream os = pdStream.createOutputStream();
@@ -415,10 +460,17 @@ public class PDFBoxAdapter {
}
}
- private void transferPageDict(COSDictionary fonts, UniqueName uniqueName, COSDictionary sourcePageResources)
- throws IOException {
- if (fonts != null) {
- for (Map.Entry<COSName, COSBase> f : fonts.entrySet()) {
+ /**
+ * Transfer source page resources to target page.
+ * @param srcPgFonts The source page's fonts.
+ * @param uniqueName Name de-collisioner.
+ * @param sourcePageResources The source page's resources.
+ * @throws IOException On IO exception.
+ */
+ private void transferPageDict(COSDictionary srcPgFonts, UniqueName uniqueName, COSDictionary sourcePageResources)
+ throws IOException {
+ if (srcPgFonts != null) {
+ for (Map.Entry<COSName, COSBase> f : srcPgFonts.entrySet()) {
String name = uniqueName.getName(f.getKey());
targetPage.getPDFResources().addFont(name, (PDFDictionary)cloneForNewDocument(f.getValue()));
}
@@ -428,6 +480,12 @@ public class PDFBoxAdapter {
}
}
+ /**
+ * Transfer source page resource to target page.
+ * @param dict A source page resource.
+ * @param uniqueName Name de-collisioner.
+ * @throws IOException On IO exception.
+ */
private void transferDict(Map.Entry<COSName, COSBase> dict, UniqueName uniqueName) throws IOException {
COSBase src;
if (dict.getValue() instanceof COSObject) {
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java
index b397a7c..5139a68 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterUtil.java
@@ -36,10 +36,13 @@ import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
+import org.apache.pdfbox.util.Matrix;
import org.apache.fop.pdf.PDFArray;
import org.apache.fop.pdf.PDFDictionary;
@@ -195,6 +198,42 @@ public final class PDFBoxAdapterUtil {
}
}
+ /**
+ * Modify pattern matrix of source patterns according to the calculated adjustment.
+ * @param targetPageMediaBox The Media Box of the target page.
+ * @param destRect The rectangle the embedded page will be placed in.
+ * @param sourcePage The page to be embedded as an image.
+ * @param srcPgPatternNamesIt Names of patterns in the source page.
+ * @throws IOException On IO exception.
+ */
+ protected static void transformPatterns(PDFArray targetPageMediaBox,
+ Rectangle destRect,
+ PDPage sourcePage,
+ Iterable<COSName> srcPgPatternNamesIt) throws IOException {
+ // The pattern found in the source document.
+ PDAbstractPattern srcPattern;
+
+ if (srcPgPatternNamesIt != null) {
+ AffineTransform shadingAdjust = getShadingAffineTransform(targetPageMediaBox, destRect, sourcePage);
+ // No null checks - throw NPE if anything is null.
+ PDResources srcPgResources = sourcePage.getResources();
+
+ for (COSName srcPgPatternName : srcPgPatternNamesIt) {
+ // Get the original pattern.
+ srcPattern = srcPgResources.getPattern(srcPgPatternName);
+ // No null checks - throw NPE if srcPattern is null.
+ Matrix originalMatrix = srcPattern.getMatrix();
+ Matrix shadingMatrix = new Matrix(shadingAdjust);
+ // Create the required new matrix and apply it to the pattern.
+ Matrix newMatrix = originalMatrix.multiply(shadingMatrix);
+ srcPattern.setMatrix(newMatrix.createAffineTransform());
+
+ // Add the pattern to the page resources for now.
+ srcPgResources.put(srcPgPatternName, srcPattern);
+ }
+ }
+ }
+
private static void rotateStream(AffineTransform transform, int rotation, float height, PDAnnotation annot) {
transform.rotate(Math.toRadians(-rotation));
transform.translate(-height, 0);
@@ -221,4 +260,44 @@ public final class PDFBoxAdapterUtil {
(float)rectangleT.getWidth(), (float)rectangleT.getHeight());
return rect;
}
+
+ /**
+ * Get an affine transform that will translate and scale a source page to a rectangle on a target page.
+ * @param targetMediaBox The Media Box of the target page.
+ * @param destRect The rectangle the embedded page will be placed in.
+ * @param srcPage The page to be embedded as an image.
+ * @return The affine transform.
+ */
+ private static AffineTransform getShadingAffineTransform(PDFArray targetMediaBox,
+ Rectangle destRect,
+ PDPage srcPage) {
+
+ AffineTransform shadingAdjust;
+ // No null checks - throw NPE if anything is null.
+ PDRectangle srcMediaBox = srcPage.getMediaBox();
+
+ double targetMediaBoxHeight = (double) targetMediaBox.get(3);
+
+ // Convert destRect to use bottom/left frame as origin.
+ Rectangle cDestRect = new Rectangle(destRect);
+ cDestRect.y = (int) ((targetMediaBoxHeight * 1000 - (destRect.getY() + destRect.getHeight())));
+
+ // No divide-by-zero protection. Result will be Infinity.
+ double xScaleFactor = cDestRect.getWidth() / 1000f / srcMediaBox.getWidth();
+ double yScaleFactor = cDestRect.getHeight() / 1000f / srcMediaBox.getHeight();
+
+ // x translation: media box offset + scaled cDestRect x-offset
+ double xTranslation = cDestRect.getX() / 1000f - srcMediaBox.getLowerLeftX() * xScaleFactor;
+
+ // y translation: media box offset + scaled cDestRect
+ double yTranslation = cDestRect.getY() / 1000f - srcMediaBox.getLowerLeftY() * yScaleFactor;
+
+ shadingAdjust = new AffineTransform(xScaleFactor,
+ 0,
+ 0,
+ yScaleFactor,
+ xTranslation,
+ yTranslation);
+ return shadingAdjust;
+ }
}
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java
index 88631f7..99a784e 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java
@@ -30,6 +30,7 @@ import org.apache.xmlgraphics.image.loader.Image;
import org.apache.xmlgraphics.image.loader.ImageFlavor;
import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.pdf.PDFPage;
import org.apache.fop.pdf.PDFXObject;
import org.apache.fop.render.ImageHandler;
import org.apache.fop.render.RenderingContext;
@@ -50,17 +51,20 @@ public class PDFBoxImageHandler extends AbstractPDFBoxHandler implements ImageHa
ImagePDF.PDFBOX_IMAGE
};
- public void handleImage(RenderingContext context, Image image, Rectangle pos) throws IOException {
+ public void handleImage(RenderingContext context, Image image, Rectangle destRect) throws IOException {
assert context instanceof PDFRenderingContext;
PDFRenderingContext pdfContext = (PDFRenderingContext)context;
PDFContentGenerator generator = pdfContext.getGenerator();
+ PDFPage targetPage = pdfContext.getPage();
+
assert image instanceof ImagePDF;
ImagePDF pdfImage = (ImagePDF)image;
try {
- float x = (float)pos.getX() / 1000f;
- float y = (float)pos.getY() / 1000f;
- float w = (float)pos.getWidth() / 1000f;
- float h = (float)pos.getHeight() / 1000f;
+ // destRect in points. Because destRect size is in millipoints.
+ float x = (float)destRect.getX() / 1000f; // Offset from left of page (IPD origin).
+ float y = (float)destRect.getY() / 1000f; // Offset from top of page (BPD origin).
+ float w = (float)destRect.getWidth() / 1000f; // Width of image.
+ float h = (float)destRect.getHeight() / 1000f; // Height of image.
AffineTransform pageAdjust = new AffineTransform();
AffineTransform at = generator.getAffineTransform();
@@ -70,8 +74,8 @@ public class PDFBoxImageHandler extends AbstractPDFBoxHandler implements ImageHa
(float)(generator.getState().getTransform().getTranslateY() - h - y));
}
FontInfo fontinfo = (FontInfo)context.getHint("fontinfo");
- Object stream = createStreamForPDF(pdfImage, pdfContext.getPage(), pdfContext.getUserAgent(),
- pageAdjust, fontinfo, pos, pdfContext.getPageNumbers(),
+ Object stream = createStreamForPDF(pdfImage, targetPage, pdfContext.getUserAgent(),
+ pageAdjust, fontinfo, destRect, pdfContext.getPageNumbers(),
pdfContext.getPdfLogicalStructureHandler(), pdfContext.getCurrentSessionStructElem());
if (stream == null) {
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/UniqueName.java b/src/java/org/apache/fop/render/pdf/pdfbox/UniqueName.java
index f5a8369..dc1ca18 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/UniqueName.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/UniqueName.java
@@ -18,6 +18,7 @@
/* $Id$ */
package org.apache.fop.render.pdf.pdfbox;
+import java.awt.Rectangle;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -31,38 +32,77 @@ import org.apache.pdfbox.cos.COSObject;
import org.apache.fop.pdf.PDFDocument;
+/**
+ * This class provides collision-avoidance for names within a collection.
+ * That is, if a submitted name collides with a name in the collection, an alternative is provided.
+ * The alternative may or may not be in the collection.
+ */
public class UniqueName {
+ // General key.
private String key;
+ // A key to be used only for pattern names.
+ private String patternKey = "";
+ // General resource names.
private List<COSName> resourceNames;
+ // Pattern resource names.
+ private List<COSName> patternResourceNames = new ArrayList<>();
- public UniqueName(String key, COSDictionary sourcePageResources, boolean disable) {
+ public UniqueName(String key, COSDictionary sourcePageResources, Iterable<COSName> patternNames, boolean disable,
+ Rectangle destRect) {
if (disable) {
resourceNames = Collections.emptyList();
} else {
key = key.split("#")[0];
this.key = Integer.toString(key.hashCode());
- resourceNames = getResourceNames(sourcePageResources);
+ if (patternNames != null) {
+ // Make pattern key unique to the destination rectangle.
+ this.patternKey = Integer.toString(
+ (key + destRect.getX() + destRect.getY() + destRect.getWidth() + destRect.getHeight()
+ ).hashCode());
+ for (COSName cosName : patternNames) {
+ patternResourceNames.add(cosName);
+ }
+ }
+ resourceNames = getResourceNames(sourcePageResources, patternResourceNames);
}
}
+ /**
+ * Provides a de-collisioned name.
+ * @param cn Submitted name.
+ * @return The submitted name if it is not already in this object's collection or an alternative it is.
+ * It is possible that the alternative is also in the collection.
+ */
protected String getName(COSName cn) {
+ if (patternResourceNames.contains(cn)) {
+ return cn.getName() + patternKey;
+ }
if (resourceNames.contains(cn)) {
return cn.getName() + key;
}
return cn.getName();
}
+ /**
+ * Writes a name into a StringBuilder, appending a suffix if the name exists in this object's collection.
+ * @param sb The StringBuilder.
+ * @param cn The COSName.
+ * @throws IOException On IO exception.
+ */
protected void writeName(StringBuilder sb, COSName cn) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
cn.writePDF(bos);
String name = bos.toString(PDFDocument.ENCODING);
sb.append(name);
+ if (patternResourceNames.contains(cn)) {
+ sb.append(patternKey);
+ }
if (resourceNames.contains(cn)) {
sb.append(key);
}
}
- private List<COSName> getResourceNames(COSDictionary sourcePageResources) {
+ private List<COSName> getResourceNames(COSDictionary sourcePageResources, List<COSName> patternResourceNames) {
List<COSName> resourceNames = new ArrayList<COSName>();
for (COSBase e : sourcePageResources.getValues()) {
if (e instanceof COSObject) {
@@ -70,9 +110,17 @@ public class UniqueName {
}
if (e instanceof COSDictionary) {
COSDictionary d = (COSDictionary) e;
- resourceNames.addAll(d.keySet());
+ for (COSName cosName : d.keySet()) {
+ if (!patternResourceNames.contains(cosName)) {
+ resourceNames.add(cosName);
+ }
+ }
}
}
return resourceNames;
}
+
+ public boolean hasPatterns() {
+ return !patternResourceNames.isEmpty();
+ }
}
diff --git a/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java b/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
index 3e87026..5e6d9a5 100644
--- a/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
@@ -53,6 +53,7 @@ import org.apache.fontbox.ttf.TrueTypeFont;
import org.apache.fontbox.type1.Type1Font;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.cos.COSInteger;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSObject;
@@ -137,6 +138,7 @@ public class PDFBoxAdapterTestCase {
protected static final String TYPE0CFF = "type0cff.pdf";
protected static final String ACCESSIBLERADIOBUTTONS = "accessibleradiobuttons.pdf";
protected static final String PATTERN = "pattern.pdf";
+ protected static final String PATTERN2 = "pattern2.pdf";
protected static final String FORMROTATED = "formrotated.pdf";
private static PDFPage getPDFPage(PDFDocument doc) {
@@ -244,9 +246,10 @@ public class PDFBoxAdapterTestCase {
private String writeText(FontInfo fi, String pdf) throws IOException {
PDDocument doc = load(pdf);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
String c = (String) getPDFBoxAdapter(true, false)
- .createStreamFromPDFBoxPage(doc, page, pdf, at, fi, new Rectangle());
+ .createStreamFromPDFBoxPage(doc, page, pdf, pageAdjust, targetPageMediaBox, fi, new Rectangle());
doc.close();
return c;
}
@@ -257,9 +260,11 @@ public class PDFBoxAdapterTestCase {
adapter.setCurrentMCID(5);
PDDocument doc = load(HELLOTagged);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- String stream = (String) adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ String stream = (String) adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust,
+ targetPageMediaBox, null, r);
Assert.assertTrue(stream, stream.contains("/P <</MCID 5 >>BDC"));
doc.close();
}
@@ -273,12 +278,13 @@ public class PDFBoxAdapterTestCase {
PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap<>(), new HashMap<Integer, PDFArray>());
PDDocument doc = load(ANNOT);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
ByteArrayOutputStream os = new ByteArrayOutputStream();
pdfdoc.output(os);
os.reset();
- adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust, targetPageMediaBox, null, r);
pdfdoc.outputTrailer(os);
Assert.assertTrue(os.toString("UTF-8").contains("/Fields ["));
doc.close();
@@ -293,9 +299,10 @@ public class PDFBoxAdapterTestCase {
COSDictionary dict = (COSDictionary) ((COSObject)annots.get(0)).getObject();
dict.setItem(COSName.PARENT, COSInteger.ONE);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust, targetPageMediaBox, null, r);
doc.close();
}
@@ -309,9 +316,10 @@ public class PDFBoxAdapterTestCase {
PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap<>(), new HashMap<Integer, PDFArray>());
PDDocument doc = load(ACCESSIBLERADIOBUTTONS);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust, targetPageMediaBox, null, r);
ByteArrayOutputStream os = new ByteArrayOutputStream();
pdfdoc.output(os);
String out = os.toString("UTF-8");
@@ -332,9 +340,10 @@ public class PDFBoxAdapterTestCase {
doc.getDocumentCatalog().getAcroForm().getCOSObject().getDictionaryObject(COSName.FIELDS);
fields.remove(0);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust, targetPageMediaBox, null, r);
ByteArrayOutputStream os = new ByteArrayOutputStream();
pdfdoc.outputTrailer(os);
Assert.assertTrue(os.toString("UTF-8").contains("/Fields []"));
@@ -351,9 +360,11 @@ public class PDFBoxAdapterTestCase {
PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap<>(), pageNumbers);
PDDocument doc = load(LINK);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- String stream = (String) adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ String stream = (String) adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust,
+ targetPageMediaBox, null, r);
Assert.assertTrue(stream.contains("/Link <</MCID 5 >>BDC"));
Assert.assertEquals(pageNumbers.size(), 4);
PDFAnnotList annots = (PDFAnnotList) pdfpage.get("Annots");
@@ -373,9 +384,10 @@ public class PDFBoxAdapterTestCase {
PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap<>(), pageNumbers);
PDDocument doc = load(XFORM);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- adapter.createStreamFromPDFBoxPage(doc, page, "key", at, new FontInfo(), r);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust, targetPageMediaBox, new FontInfo(), r);
doc.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
pdfdoc.output(bos);
@@ -523,7 +535,9 @@ public class PDFBoxAdapterTestCase {
PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap<>(), new HashMap<Integer, PDFArray>());
PDDocument doc = load(src);
PDPage page = doc.getPage(0);
- adapter.createStreamFromPDFBoxPage(doc, page, "key", new AffineTransform(), null, new Rectangle());
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", new AffineTransform(), targetPageMediaBox, null,
+ new Rectangle());
doc.close();
}
@@ -551,6 +565,46 @@ public class PDFBoxAdapterTestCase {
Assert.assertTrue(bos.toString("UTF-8").contains("/ExtGState << /GS1"));
}
+ /**
+ * Tests that pattern matrices in source PDFs are modified according to their transposition.
+ * @throws Exception On exception.
+ */
+ @Test
+ public void testPDFBoxImageHandlerTransformPatternMatrix() throws Exception {
+ ImageInfo imgi = new ImageInfo("a", "b");
+ PDDocument srcPDFDoc = load(SHADING);
+ ImagePDF srcImagePDF = new ImagePDF(imgi, srcPDFDoc);
+ PDFDocument targetPDFDoc = new PDFDocument("");
+ PDFPage targetPDFPage = getPDFPage(targetPDFDoc);
+ targetPDFPage.setDocument(targetPDFDoc);
+ PDFGState g = new PDFGState();
+ targetPDFDoc.assignObjectNumber(g);
+ targetPDFPage.addGState(g);
+
+ PDFContentGenerator con = new PDFContentGenerator(targetPDFDoc, null, null);
+ FOUserAgent mockedAgent = mock(FOUserAgent.class);
+ when(mockedAgent.isAccessibilityEnabled()).thenReturn(false);
+ when(mockedAgent.getPDFObjectCache()).thenReturn(new SoftMapCache(true));
+ PDFRenderingContext c = new PDFRenderingContext(mockedAgent, con, targetPDFPage, null);
+ c.setPageNumbers(new HashMap<Integer, PDFArray>());
+ Rectangle destRect = new Rectangle(0, 1650, 274818, 174879);
+ PDFBoxImageHandler pdfBoxImageHandler = new PDFBoxImageHandler();
+ pdfBoxImageHandler.handleImage(c, srcImagePDF, destRect);
+
+ // Drill down into image and check that the pattern matrix has been transformed correctly.
+ PDDocument pdDocument = srcImagePDF.getPDDocument();
+ COSDocument cosDocument = pdDocument.getDocument();
+ List<COSObject> cosObjects = cosDocument.getObjectsByType(COSName.PATTERN);
+ String baseObjectStringDef = cosObjects.get(0).getObject().toString();
+
+ Assert.assertTrue(baseObjectStringDef.contains(
+ "COSName{Matrix}:"
+ + "COSArray{"
+ + "COSFloat{53.885883};COSFloat{0.0};1;"
+ + "COSFloat{-26.496819};COSFloat{72.74594};COSFloat{-20.860199};"
+ + "};"));
+ }
+
@Test
public void testPDFCache() throws IOException {
LoadPDFWithCache loadPDFWithCache = new LoadPDFWithCache();
@@ -592,8 +646,9 @@ public class PDFBoxAdapterTestCase {
pdfpage, objectCachePerFile, new HashMap<Integer, PDFArray>(), pdfCache);
PDDocument doc = load(pdf);
PDPage page = doc.getPage(0);
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
String stream = (String) adapter.createStreamFromPDFBoxPage(
- doc, page, pdf, new AffineTransform(), null, new Rectangle());
+ doc, page, pdf, new AffineTransform(), targetPageMediaBox, null, new Rectangle());
doc.close();
return stream;
}
@@ -641,8 +696,11 @@ public class PDFBoxAdapterTestCase {
PDDocument doc = load(CFF1);
PDPage page = doc.getPage(0);
page.setResources(null);
- AffineTransform at = new AffineTransform();
- getPDFBoxAdapter(false, false).createStreamFromPDFBoxPage(doc, page, CFF1, at, new FontInfo(), new Rectangle());
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
+ getPDFBoxAdapter(false, false)
+ .createStreamFromPDFBoxPage(doc, page, CFF1, pageAdjust, targetPageMediaBox, new FontInfo(),
+ new Rectangle());
doc.close();
}
@@ -668,10 +726,12 @@ public class PDFBoxAdapterTestCase {
String msg = "";
PDDocument doc = load(IMAGE);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
try {
getPDFBoxAdapter(true, true)
- .createStreamFromPDFBoxPage(doc, page, IMAGE, at, new FontInfo(), new Rectangle());
+ .createStreamFromPDFBoxPage(doc, page, IMAGE, pageAdjust, targetPageMediaBox, new FontInfo(),
+ new Rectangle());
} catch (RuntimeException e) {
msg = e.getMessage();
}
@@ -683,9 +743,11 @@ public class PDFBoxAdapterTestCase {
public void testFormXObject() throws IOException {
PDDocument doc = load(IMAGE);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
PDFFormXObject formXObject = (PDFFormXObject) getPDFBoxAdapter(false, true)
- .createStreamFromPDFBoxPage(doc, page, IMAGE, at, new FontInfo(), new Rectangle());
+ .createStreamFromPDFBoxPage(doc, page, IMAGE, pageAdjust, targetPageMediaBox, new FontInfo(),
+ new Rectangle());
doc.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
formXObject.output(bos);
@@ -705,9 +767,10 @@ public class PDFBoxAdapterTestCase {
PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap<>(), new HashMap<Integer, PDFArray>());
PDDocument doc = load(pdf);
PDPage page = doc.getPage(0);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust, targetPageMediaBox, null, r);
ByteArrayOutputStream os = new ByteArrayOutputStream();
Map<String, List<String>> filterMap = new HashMap<String, List<String>>();
List<String> filterList = new ArrayList<String>();
diff --git a/test/java/org/apache/fop/render/pdf/PDFRotateTestCase.java b/test/java/org/apache/fop/render/pdf/PDFRotateTestCase.java
index 3c960a8..fc243c1 100644
--- a/test/java/org/apache/fop/render/pdf/PDFRotateTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/PDFRotateTestCase.java
@@ -36,6 +36,7 @@ import org.apache.xmlgraphics.image.loader.impl.ImageGraphics2D;
import org.apache.xmlgraphics.java2d.GraphicContext;
import org.apache.xmlgraphics.java2d.ps.PSGraphics2D;
+import org.apache.fop.pdf.PDFArray;
import org.apache.fop.render.pdf.pdfbox.ImageConverterPDF2G2D;
import org.apache.fop.render.pdf.pdfbox.ImagePDF;
import org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter;
@@ -78,12 +79,14 @@ public class PDFRotateTestCase {
PDDocument doc = PDFBoxAdapterTestCase.load(PDFBoxAdapterTestCase.ROTATE);
PDPage page = doc.getPage(0);
page.setRotation(angle);
- AffineTransform at = new AffineTransform();
+ AffineTransform pageAdjust = new AffineTransform();
+ PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
Rectangle r = new Rectangle(0, 1650, 842000, 595000);
- String stream = (String) adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ String stream = (String) adapter.createStreamFromPDFBoxPage(doc, page, "key", pageAdjust, targetPageMediaBox,
+ null, r);
Assert.assertTrue(stream.contains("/GS0106079 gs"));
Assert.assertTrue(stream.contains("/TT0106079 1 Tf"));
doc.close();
- return at;
+ return pageAdjust;
}
}
diff --git a/test/java/org/apache/fop/render/pdf/PDFWriterTestCase.java b/test/java/org/apache/fop/render/pdf/PDFWriterTestCase.java
index dba67bc..bf0f08b 100644
--- a/test/java/org/apache/fop/render/pdf/PDFWriterTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/PDFWriterTestCase.java
@@ -16,6 +16,7 @@
*/
package org.apache.fop.render.pdf;
+import java.awt.Rectangle;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Locale;
@@ -56,7 +57,7 @@ public class PDFWriterTestCase {
int i;
public MyPDFWriter() {
- super(new UniqueName("", null, true), 0);
+ super(new UniqueName("", null, null, true, new Rectangle(0, 0, 100, 100)), 0);
}
protected void addCache(float f) {
@@ -69,7 +70,8 @@ public class PDFWriterTestCase {
public void testBoolean() throws IOException {
String text = "[true true ] a\n";
PDStream pdStream = new PDStream(new PDDocument(), new ByteArrayInputStream(text.getBytes("UTF-8")));
- PDFWriter pdfWriter = new PDFWriter(new UniqueName("", null, true), 0);
+ Rectangle rect = new Rectangle(0, 0, 100, 100);
+ PDFWriter pdfWriter = new PDFWriter(new UniqueName("", null, null, true, rect), 0);
String out = pdfWriter.writeText(pdStream);
Assert.assertEquals(out, text);
}
@@ -78,7 +80,8 @@ public class PDFWriterTestCase {
public void testNull() throws IOException {
String text = "[null ] a\n";
PDStream pdStream = new PDStream(new PDDocument(), new ByteArrayInputStream(text.getBytes("UTF-8")));
- PDFWriter pdfWriter = new PDFWriter(new UniqueName("", null, true), 0);
+ Rectangle rect = new Rectangle(0, 0, 100, 100);
+ PDFWriter pdfWriter = new PDFWriter(new UniqueName("", null, null, true, rect), 0);
String out = pdfWriter.writeText(pdStream);
Assert.assertEquals(out, text);
}
@@ -87,7 +90,8 @@ public class PDFWriterTestCase {
public void testSpaceInName() throws IOException {
String text = "/a#20a a\n";
PDStream pdStream = new PDStream(new PDDocument(), new ByteArrayInputStream(text.getBytes("UTF-8")));
- PDFWriter pdfWriter = new PDFWriter(new UniqueName("", null, true), 0);
+ Rectangle rect = new Rectangle(0, 0, 100, 100);
+ PDFWriter pdfWriter = new PDFWriter(new UniqueName("", null, null, true, rect), 0);
String out = pdfWriter.writeText(pdStream);
Assert.assertEquals(out, text);
}
diff --git a/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java b/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java
index eb3ed40..cd2317e 100644
--- a/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/pdfbox/PDFClonerTestCase.java
@@ -18,6 +18,7 @@
/* $Id$ */
package org.apache.fop.render.pdf.pdfbox;
+import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -82,9 +83,10 @@ public class PDFClonerTestCase {
COSDictionary child = new COSDictionary();
child.setBoolean("a", true);
res.setItem("a", child);
- adapter.uniqueName = new UniqueName("a", res, false);
+ Rectangle rect = new Rectangle(0, 0, 100, 100);
+ adapter.uniqueName = new UniqueName("a", res, null, false, rect);
PDFStream cloneda = (PDFStream) new PDFCloner(adapter).cloneForNewDocument(getStream());
- adapter.uniqueName = new UniqueName("b", res, false);
+ adapter.uniqueName = new UniqueName("b", res, null, false, rect);
PDFStream clonedb = (PDFStream) new PDFCloner(adapter).cloneForNewDocument(getStream());
Assert.assertNotSame(cloneda, clonedb);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org