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/08/07 14:49:43 UTC
[xmlgraphics-fop-pdf-images] branch main updated: FOP-3136: Softmask dictionary preserved
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 b001a30 FOP-3136: Softmask dictionary preserved
b001a30 is described below
commit b001a302b957ca0ba7ab953e65438e79453d14f6
Author: Simon Steiner <ss...@apache.org>
AuthorDate: Mon Aug 7 15:23:23 2023 +0100
FOP-3136: Softmask dictionary preserved
---
.../fop/render/pdf/pdfbox/PDFBoxAdapter.java | 6 +-
.../apache/fop/render/pdf/pdfbox/PDFCloner.java | 18 ++----
.../apache/fop/render/pdf/pdfbox/UniqueName.java | 1 +
.../render/pdf/pdfbox/PDFBoxAdapterTestCase.java | 67 +++++++--------------
.../apache/fop/render/pdf/pdfbox/softmask-min.pdf | Bin 5588 -> 0 bytes
5 files changed, 27 insertions(+), 65 deletions(-)
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 ac40acd..d3fd52d 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
@@ -137,10 +137,6 @@ public class PDFBoxAdapter {
return new PDFCloner(this, false).cloneForNewDocument(base);
}
- protected Object cloneResourcesForNewDocument(Object base, Object keyBase, Collection exclude) throws IOException {
- return new PDFCloner(this, false).cloneResourcesForNewDocument(base, keyBase, exclude);
- }
-
protected Object cloneForNewDocument(Object base, Object keyBase, Collection exclude) throws IOException {
return new PDFCloner(this, false).cloneForNewDocument(base, keyBase, exclude);
}
@@ -228,7 +224,7 @@ public class PDFBoxAdapter {
List<COSName> exclude = Arrays.asList(COSName.PATTERN);
PDFDictionary pageResources =
- (PDFDictionary)cloneResourcesForNewDocument(srcPgResCosDict, srcPgResCosDict, exclude);
+ (PDFDictionary)cloneForNewDocument(srcPgResCosDict, srcPgResCosDict, exclude);
updateMergeFontInfo(pageResources, fontinfo);
updateXObj(srcPgResCosDict, pageResources);
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java b/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java
index b013238..6a08e62 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/PDFCloner.java
@@ -68,16 +68,7 @@ public class PDFCloner {
return cloneForNewDocument(base, keyBase, Collections.EMPTY_LIST);
}
- protected Object cloneResourcesForNewDocument(Object base, Object keyBase, Collection exclude) throws IOException {
- return cloneForNewDocument(base, keyBase, exclude, true);
- }
-
protected Object cloneForNewDocument(Object base, Object keyBase, Collection exclude) throws IOException {
- return cloneForNewDocument(base, keyBase, exclude, false);
- }
-
- private Object cloneForNewDocument(Object base, Object keyBase, Collection exclude, boolean rename)
- throws IOException {
if (base == null) {
return null;
}
@@ -110,7 +101,7 @@ public class PDFCloner {
} else if (base instanceof COSStream) {
return readCOSStream((COSStream) base, keyBase);
} else if (base instanceof COSDictionary) {
- return readCOSDictionary((COSDictionary) base, keyBase, exclude, rename);
+ return readCOSDictionary((COSDictionary) base, keyBase, exclude);
} else if (base instanceof COSName) {
PDFName newName = new PDFName(((COSName)base).getName());
return cacheClonedObject(keyBase, newName);
@@ -151,17 +142,16 @@ public class PDFCloner {
return obj;
}
- private PDFDictionary readCOSDictionary(COSDictionary dic, Object keyBase, Collection exclude, boolean rename)
- throws IOException {
+ private PDFDictionary readCOSDictionary(COSDictionary dic, Object keyBase, Collection exclude) throws IOException {
PDFDictionary newDict = new PDFDictionary();
cacheClonedObject(keyBase, newDict);
for (Map.Entry<COSName, COSBase> e : dic.entrySet()) {
if (!exclude.contains(e.getKey())) {
String name = e.getKey().getName();
- if (rename && adapter.uniqueName != null) {
+ if (adapter.uniqueName != null) {
name = adapter.uniqueName.getName(e.getKey());
}
- newDict.put(name, cloneForNewDocument(e.getValue(), e.getValue(), exclude, true));
+ newDict.put(name, cloneForNewDocument(e.getValue(), e.getValue(), exclude));
}
}
return newDict;
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 dc1ca18..006c1f8 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/UniqueName.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/UniqueName.java
@@ -117,6 +117,7 @@ public class UniqueName {
}
}
}
+ resourceNames.remove(COSName.S);
return resourceNames;
}
diff --git a/test/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterTestCase.java b/test/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterTestCase.java
index 5feed17..d75062a 100644
--- a/test/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapterTestCase.java
@@ -138,7 +138,6 @@ public class PDFBoxAdapterTestCase {
protected static final String PATTERN = "pattern.pdf";
protected static final String PATTERN2 = "pattern2.pdf";
protected static final String FORMROTATED = "formrotated.pdf";
- protected static final String SOFTMASK = "softmask-min.pdf";
private static PDFPage getPDFPage(PDFDocument doc) {
final Rectangle2D r = new Rectangle2D.Double();
@@ -554,16 +553,21 @@ public class PDFBoxAdapterTestCase {
}
private void loadPage(PDFDocument pdfdoc, String src) throws IOException {
+ PDDocument doc = load(src);
+ loadPage(pdfdoc, doc);
+ }
+
+ private PDFPage loadPage(PDFDocument pdfdoc, PDDocument doc) throws IOException {
PDFPage pdfpage = getPDFPage(pdfdoc);
pdfdoc.assignObjectNumber(pdfpage);
pdfpage.setDocument(pdfdoc);
PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap<>(), new HashMap<Integer, PDFArray>());
- PDDocument doc = load(src);
PDPage page = doc.getPage(0);
PDFArray targetPageMediaBox = new PDFArray(0d, 0d, 100d, 100d);
adapter.createStreamFromPDFBoxPage(doc, page, "key", new AffineTransform(), targetPageMediaBox, null,
new Rectangle());
doc.close();
+ return pdfpage;
}
@Test
@@ -625,53 +629,11 @@ public class PDFBoxAdapterTestCase {
Assert.assertTrue(baseObjectStringDef.contains(
"COSName{Matrix}:"
+ "COSArray{"
- + "COSFloat{53.885883};COSFloat{0.0};1;"
- + "COSFloat{-26.496819};COSFloat{72.74594};COSFloat{-20.860199};"
+ + "COSFloat{53.885883};COSFloat{0.0};1;"
+ + "COSFloat{-26.496819};COSFloat{72.74594};COSFloat{-20.860199};"
+ "};"));
}
- /**
- * Only page resources names should be de-collisioned - this tests that deeper COSNames are preserved.
- * @throws Exception On exception.
- */
- @Test
- public void testPDFBoxImageHandlerPreserveNames() throws Exception {
- ImageInfo imgi = new ImageInfo("a", "b");
- PDDocument srcPDFDoc = load(SOFTMASK);
- 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, 0, 637920, 850320);
- PDFBoxImageHandler pdfBoxImageHandler = new PDFBoxImageHandler();
- pdfBoxImageHandler.handleImage(c, srcImagePDF, destRect);
-
- // Drill down into doc and check that the soft mask dictionary has been preserved.
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- c.getGenerator().getDocument().output(bos);
- String docString = bos.toString("UTF-8");
-
- Assert.assertTrue(docString.contains("2 0 obj\n"
- + "<<\n"
- + " /S /Transparency\n"
- + " /CS /DeviceCMYK\n"
- + " /Type /Group\n"
- + " /I false\n"
- + " /K false\n"
- + ">>\n"
- + "endobj"));
- }
-
@Test
public void testPDFCache() throws IOException {
LoadPDFWithCache loadPDFWithCache = new LoadPDFWithCache();
@@ -984,4 +946,17 @@ public class PDFBoxAdapterTestCase {
+ "/T (Fullname1)\n"
+ ">>"));
}
+
+ @Test
+ public void testPreservePropertyNames() throws Exception {
+ PDDocument doc = load(CFF1);
+ COSDictionary properties = new COSDictionary();
+ properties.setItem(COSName.S, COSName.S);
+ doc.getPage(0).getResources().getCOSObject().setItem(COSName.PROPERTIES, properties);
+ PDFDocument pdfdoc = new PDFDocument("");
+ PDFPage page = loadPage(pdfdoc, doc);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ page.getPDFResources().output(bos);
+ Assert.assertTrue(bos.toString("UTF-8").contains("/Properties << /S /S >>"));
+ }
}
diff --git a/test/resources/org/apache/fop/render/pdf/pdfbox/softmask-min.pdf b/test/resources/org/apache/fop/render/pdf/pdfbox/softmask-min.pdf
deleted file mode 100644
index 6107d98..0000000
Binary files a/test/resources/org/apache/fop/render/pdf/pdfbox/softmask-min.pdf and /dev/null differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org