summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2015-06-11 15:46:20 +0000
committerSimon Steiner <ssteiner@apache.org>2015-06-11 15:46:20 +0000
commitf238bd0aa5085b8fbd10a73a156893fd7e13ce55 (patch)
treee3710065f72be1a287004a01a484a6eb4143c7c3
parent533698665f8540fd3d5abdd83e665ea518a02dcd (diff)
downloadxmlgraphics-fop-f238bd0aa5085b8fbd10a73a156893fd7e13ce55.tar.gz
xmlgraphics-fop-f238bd0aa5085b8fbd10a73a156893fd7e13ce55.zip
FOP-2436: Merging of Tagged (Accessible) PDF
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1684928 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/java/org/apache/fop/pdf/PDFDictionary.java22
-rw-r--r--src/java/org/apache/fop/pdf/PDFStructElem.java26
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java10
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFPainter.java43
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFRenderingContext.java19
5 files changed, 113 insertions, 7 deletions
diff --git a/src/java/org/apache/fop/pdf/PDFDictionary.java b/src/java/org/apache/fop/pdf/PDFDictionary.java
index d91e87d92..4ad1c2ce5 100644
--- a/src/java/org/apache/fop/pdf/PDFDictionary.java
+++ b/src/java/org/apache/fop/pdf/PDFDictionary.java
@@ -161,4 +161,26 @@ public class PDFDictionary extends PDFObject {
}
}
}
+
+ public Set<String> keySet() {
+ return entries.keySet();
+ }
+
+ /**
+ * @see java.util.Map#containsKey(Object)
+ *
+ * @param name The key to find in the map.
+ * @return true if the map contains this key.
+ */
+ public boolean containsKey(String name) {
+ return this.entries.containsKey(name);
+ }
+
+ /**
+ * Removes the mapping for the specified key
+ * @param name key whose mapping is to be removed
+ */
+ public void remove(String name) {
+ entries.remove(name);
+ }
}
diff --git a/src/java/org/apache/fop/pdf/PDFStructElem.java b/src/java/org/apache/fop/pdf/PDFStructElem.java
index badf53060..f9a182ceb 100644
--- a/src/java/org/apache/fop/pdf/PDFStructElem.java
+++ b/src/java/org/apache/fop/pdf/PDFStructElem.java
@@ -47,6 +47,12 @@ public class PDFStructElem extends StructureHierarchyMember
private List<PDFDictionary> attributes;
/**
+ * Creates PDFStructElem with no entries.
+ */
+ public PDFStructElem() {
+ }
+
+ /**
* Creates a new structure element.
*
* @param parent parent of this element
@@ -170,6 +176,22 @@ public class PDFStructElem extends StructureHierarchyMember
}
}
+ public void addKidInSpecificOrder(int position, PDFStructElem kid) {
+ if (kids == null) {
+ addKid(kid);
+ } else {
+ if ((kids.size() - 1) < position) {
+ kids.add(kid);
+ } else if (kids.get(position) == null) {
+ kids.set(position, kid);
+ } else {
+ if (!kids.contains(kid)) {
+ kids.add(position, kid);
+ }
+ }
+ }
+ }
+
/**
* Attaches all valid kids to the kids array.
*
@@ -217,6 +239,10 @@ public class PDFStructElem extends StructureHierarchyMember
attributes.add(attribute);
}
+ public List<PDFObject> getKids() {
+ return this.kids;
+ }
+
/**
* Class representing a placeholder for a PDF Structure Element.
*/
diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
index e82a63d0d..abaffad60 100644
--- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
@@ -32,7 +32,7 @@ import org.apache.fop.pdf.PDFStructElem;
/**
* Handles the creation of the logical structure in the PDF document.
*/
-class PDFLogicalStructureHandler {
+public class PDFLogicalStructureHandler {
private static final PDFName MCR = new PDFName("MCR");
@@ -92,11 +92,15 @@ class PDFLogicalStructureHandler {
this.pdfDoc = pdfDoc;
}
- PDFParentTree getParentTree() {
+ public PDFArray getPageParentTree() {
+ return this.pageParentTreeArray;
+ }
+
+ public PDFParentTree getParentTree() {
return parentTree;
}
- private int getNextParentTreeKey() {
+ public int getNextParentTreeKey() {
return parentTreeKey++;
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java
index c43e6347a..998dc3ade 100644
--- a/src/java/org/apache/fop/render/pdf/PDFPainter.java
+++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java
@@ -25,6 +25,7 @@ import java.awt.Paint;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Locale;
@@ -32,6 +33,12 @@ import java.util.Set;
import org.w3c.dom.Document;
+import org.apache.xmlgraphics.image.loader.ImageException;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageManager;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+
+import org.apache.fop.ResourceEventProducer;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.LazyFont;
@@ -166,10 +173,6 @@ public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> {
placeImage(rect, xobject);
}
} else {
- if (accessEnabled) {
- PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement();
- prepareImageMCID(structElem);
- }
drawImageUsingURI(uri, rect);
if (!getDocumentHandler().getPDFDocument().isLinearizationEnabled()) {
flushPDFDoc();
@@ -177,6 +180,36 @@ public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> {
}
}
+ @Override
+ protected void drawImageUsingURI(String uri, Rectangle rect) {
+ ImageManager manager = getUserAgent().getImageManager();
+ ImageInfo info = null;
+ try {
+ ImageSessionContext sessionContext = getUserAgent().getImageSessionContext();
+ info = manager.getImageInfo(uri, sessionContext);
+ if (accessEnabled) {
+ PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement();
+ String mimeType = info.getMimeType();
+ if (!mimeType.equalsIgnoreCase("application/pdf")) {
+ prepareImageMCID(structElem);
+ }
+ }
+ drawImageUsingImageHandler(info, rect);
+ } catch (ImageException ie) {
+ ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
+ getUserAgent().getEventBroadcaster());
+ eventProducer.imageError(this, (info != null ? info.toString() : uri), ie, null);
+ } catch (FileNotFoundException fe) {
+ ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
+ getUserAgent().getEventBroadcaster());
+ eventProducer.imageNotFound(this, (info != null ? info.toString() : uri), fe, null);
+ } catch (IOException ioe) {
+ ResourceEventProducer eventProducer = ResourceEventProducer.Provider.get(
+ getUserAgent().getEventBroadcaster());
+ eventProducer.imageIOError(this, (info != null ? info.toString() : uri), ioe, null);
+ }
+ }
+
private void prepareImageMCID(PDFStructElem structElem) {
imageMCI = logicalStructureHandler.addImageContentItem(structElem);
if (structElem != null) {
@@ -191,6 +224,8 @@ public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> {
getUserAgent(), generator, getDocumentHandler().getCurrentPage(), getFontInfo());
pdfContext.setMarkedContentInfo(imageMCI);
pdfContext.setPageNumbers(getDocumentHandler().getPageNumbers());
+ pdfContext.setPdfLogicalStructureHandler(logicalStructureHandler);
+ pdfContext.setCurrentSessionStructElem((PDFStructElem) getContext().getStructureTreeElement());
return pdfContext;
}
diff --git a/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java b/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java
index 429d9b936..b99bcdbfe 100644
--- a/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java
+++ b/src/java/org/apache/fop/render/pdf/PDFRenderingContext.java
@@ -27,6 +27,7 @@ import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.pdf.PDFArray;
import org.apache.fop.pdf.PDFPage;
+import org.apache.fop.pdf.PDFStructElem;
import org.apache.fop.render.AbstractRenderingContext;
import org.apache.fop.render.pdf.PDFLogicalStructureHandler.MarkedContentInfo;
@@ -40,6 +41,8 @@ public class PDFRenderingContext extends AbstractRenderingContext {
private PDFPage page;
private MarkedContentInfo mci;
private Map<Integer, PDFArray> pageNumbers;
+ private PDFLogicalStructureHandler pdfLogicalStructureHandler;
+ private PDFStructElem currentSessionStructElem;
/**
* Main constructor.
@@ -100,4 +103,20 @@ public class PDFRenderingContext extends AbstractRenderingContext {
public void setPageNumbers(Map<Integer, PDFArray> pageNumbers) {
this.pageNumbers = pageNumbers;
}
+
+ public PDFLogicalStructureHandler getPdfLogicalStructureHandler() {
+ return pdfLogicalStructureHandler;
+ }
+
+ public void setPdfLogicalStructureHandler(PDFLogicalStructureHandler pdfLogicalStructureHandler) {
+ this.pdfLogicalStructureHandler = pdfLogicalStructureHandler;
+ }
+
+ public PDFStructElem getCurrentSessionStructElem() {
+ return currentSessionStructElem;
+ }
+
+ public void setCurrentSessionStructElem(PDFStructElem currentSessionStructElem) {
+ this.currentSessionStructElem = currentSessionStructElem;
+ }
}