aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/pdf
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2012-05-25 15:15:28 +0000
committerVincent Hennebert <vhennebert@apache.org>2012-05-25 15:15:28 +0000
commit89b98e43e014d7045a548b7f88be265c2621a328 (patch)
tree2fd521a451fb8be4e28a2c54706f62740028e16e /src/java/org/apache/fop/render/pdf
parentf227dce56c9bed87a8cd0daec86267e43d2b2ae1 (diff)
downloadxmlgraphics-fop-89b98e43e014d7045a548b7f88be265c2621a328.tar.gz
xmlgraphics-fop-89b98e43e014d7045a548b7f88be265c2621a328.zip
Added support for the role property on fo:page-sequence, fo:flow and fo:static-content.
This allows to change the mapping of those FOs to PDF structure types when enabling accessibility. Suggested by Martin Koegler as part of Bugzilla #50852 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1342680 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/pdf')
-rw-r--r--src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java49
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java21
-rw-r--r--src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java67
3 files changed, 69 insertions, 68 deletions
diff --git a/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java b/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
index 9b76d0620..0f752e886 100644
--- a/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
+++ b/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
@@ -103,9 +103,9 @@ final class FOToPDFRoleMap {
addStructureType("Formula");
addStructureType("Form");
- NON_STRUCT = (PDFName) STANDARD_STRUCTURE_TYPES.get("NonStruct");
+ NON_STRUCT = STANDARD_STRUCTURE_TYPES.get("NonStruct");
assert NON_STRUCT != null;
- THEAD = (PDFName) STANDARD_STRUCTURE_TYPES.get("THead");
+ THEAD = STANDARD_STRUCTURE_TYPES.get("THead");
assert THEAD != null;
// Create the standard mappings
@@ -155,7 +155,7 @@ final class FOToPDFRoleMap {
}
private static void addMapping(String fo, String structureType) {
- PDFName type = (PDFName) STANDARD_STRUCTURE_TYPES.get(structureType);
+ PDFName type = STANDARD_STRUCTURE_TYPES.get(structureType);
assert type != null;
addMapping(fo, new SimpleMapper(type));
}
@@ -168,21 +168,6 @@ final class FOToPDFRoleMap {
/**
* Maps a Formatting Object to a PDFName representing the associated structure type.
* @param fo the formatting object's local name
- * @param parent the parent of the structure element to be mapped
- * @return the structure type or null if no match could be found
- */
- public static PDFName mapFormattingObject(String fo, PDFObject parent) {
- Mapper mapper = (Mapper) DEFAULT_MAPPINGS.get(fo);
- if (mapper != null) {
- return mapper.getStructureType(parent);
- } else {
- return NON_STRUCT;
- }
- }
-
- /**
- * Maps a Formatting Object to a PDFName representing the associated structure type.
- * @param fo the formatting object's local name
* @param role the value of the formatting object's role property
* @param parent the parent of the structure element to be mapped
* @param eventBroadcaster the event broadcaster
@@ -192,11 +177,11 @@ final class FOToPDFRoleMap {
PDFObject parent, EventBroadcaster eventBroadcaster) {
PDFName type = null;
if (role == null) {
- type = mapFormattingObject(fo, parent);
+ type = getDefaultMappingFor(fo, parent);
} else {
- type = (PDFName) STANDARD_STRUCTURE_TYPES.get(role);
+ type = STANDARD_STRUCTURE_TYPES.get(role);
if (type == null) {
- type = mapFormattingObject(fo, parent);
+ type = getDefaultMappingFor(fo, parent);
PDFEventProducer.Provider.get(eventBroadcaster).nonStandardStructureType(fo,
fo, role, type.toString().substring(1));
}
@@ -205,6 +190,21 @@ final class FOToPDFRoleMap {
return type;
}
+ /**
+ * Maps a Formatting Object to a PDFName representing the associated structure type.
+ * @param fo the formatting object's local name
+ * @param parent the parent of the structure element to be mapped
+ * @return the structure type or NonStruct if no match could be found
+ */
+ private static PDFName getDefaultMappingFor(String fo, PDFObject parent) {
+ Mapper mapper = DEFAULT_MAPPINGS.get(fo);
+ if (mapper != null) {
+ return mapper.getStructureType(parent);
+ } else {
+ return NON_STRUCT;
+ }
+ }
+
private interface Mapper {
PDFName getStructureType(PDFObject parent);
}
@@ -226,14 +226,13 @@ final class FOToPDFRoleMap {
private static class TableCellMapper implements Mapper {
public PDFName getStructureType(PDFObject parent) {
- PDFStructElem grandParent = (PDFStructElem)
- ((PDFStructElem) parent).getParentStructElem();
+ PDFStructElem grandParent = ((PDFStructElem) parent).getParentStructElem();
//TODO What to do with cells from table-footer? Currently they are mapped on TD.
PDFName type;
if (THEAD.equals(grandParent.getStructureType())) {
- type = (PDFName) STANDARD_STRUCTURE_TYPES.get("TH");
+ type = STANDARD_STRUCTURE_TYPES.get("TH");
} else {
- type = (PDFName) STANDARD_STRUCTURE_TYPES.get("TD");
+ type = STANDARD_STRUCTURE_TYPES.get("TD");
}
assert type != null;
return type;
diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
index 1c9f9b49d..6559e8d56 100644
--- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
+++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java
@@ -19,8 +19,6 @@
package org.apache.fop.render.pdf;
-import java.util.Locale;
-
import org.apache.fop.pdf.PDFArray;
import org.apache.fop.pdf.PDFDictionary;
import org.apache.fop.pdf.PDFDocument;
@@ -29,7 +27,6 @@ import org.apache.fop.pdf.PDFName;
import org.apache.fop.pdf.PDFPage;
import org.apache.fop.pdf.PDFParentTree;
import org.apache.fop.pdf.PDFStructElem;
-import org.apache.fop.pdf.PDFStructTreeRoot;
/**
@@ -59,8 +56,6 @@ class PDFLogicalStructureHandler {
*/
private PDFArray pageParentTreeArray;
- private PDFStructElem rootStructureElement;
-
/**
* Class providing the necessary information for bracketing content
* associated to a structure element as a marked-content sequence.
@@ -95,22 +90,10 @@ class PDFLogicalStructureHandler {
*/
PDFLogicalStructureHandler(PDFDocument pdfDoc) {
this.pdfDoc = pdfDoc;
- PDFStructTreeRoot structTreeRoot = pdfDoc.makeStructTreeRoot(parentTree);
- rootStructureElement = pdfDoc.makeStructureElement(
- FOToPDFRoleMap.mapFormattingObject("root", structTreeRoot), structTreeRoot);
- structTreeRoot.addKid(rootStructureElement);
}
-
- PDFStructElem createPageSequence(Locale language) {
- PDFStructElem structElemPart = pdfDoc.makeStructureElement(
- FOToPDFRoleMap.mapFormattingObject("page-sequence", rootStructureElement),
- rootStructureElement);
- rootStructureElement.addKid(structElemPart);
- if (language != null) {
- structElemPart.setLanguage(language);
- }
- return structElemPart;
+ PDFParentTree getParentTree() {
+ return parentTree;
}
private int getNextParentTreeKey() {
diff --git a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java
index 2a2a4a392..3839d47bc 100644
--- a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java
+++ b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java
@@ -29,7 +29,11 @@ import org.apache.fop.accessibility.StructureTreeEventHandler;
import org.apache.fop.events.EventBroadcaster;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.pdf.PDFFactory;
+import org.apache.fop.pdf.PDFName;
+import org.apache.fop.pdf.PDFObject;
+import org.apache.fop.pdf.PDFParentTree;
import org.apache.fop.pdf.PDFStructElem;
+import org.apache.fop.pdf.PDFStructTreeRoot;
class PDFStructureTreeBuilder implements StructureTreeEventHandler {
@@ -41,21 +45,42 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler {
private LinkedList<PDFStructElem> ancestors = new LinkedList<PDFStructElem>();
+ private PDFStructElem rootStructureElement;
+
void setPdfFactory(PDFFactory pdfFactory) {
this.pdfFactory = pdfFactory;
}
void setLogicalStructureHandler(PDFLogicalStructureHandler logicalStructureHandler) {
this.logicalStructureHandler = logicalStructureHandler;
+ createRootStructureElement();
+ }
+
+ private void createRootStructureElement() {
+ assert rootStructureElement == null;
+ PDFParentTree parentTree = logicalStructureHandler.getParentTree();
+ PDFStructTreeRoot structTreeRoot = pdfFactory.getDocument().makeStructTreeRoot(parentTree);
+ rootStructureElement = createStructureElement("root", structTreeRoot, null);
+ structTreeRoot.addKid(rootStructureElement);
}
void setEventBroadcaster(EventBroadcaster eventBroadcaster) {
this.eventBroadcaster = eventBroadcaster;
}
- public void startPageSequence(Locale locale) {
+ public void startPageSequence(Locale language, String role) {
ancestors = new LinkedList<PDFStructElem>();
- ancestors.add(logicalStructureHandler.createPageSequence(locale));
+ PDFStructElem structElem = createStructureElement("page-sequence", rootStructureElement, role);
+ if (language != null) {
+ structElem.setLanguage(language);
+ }
+ rootStructureElement.addKid(structElem);
+ ancestors.add(structElem);
+ }
+
+ private PDFStructElem createStructureElement(String name, PDFObject parent, String role) {
+ PDFName structureType = FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster);
+ return pdfFactory.getDocument().makeStructureElement(structureType, parent);
}
public void endPageSequence() {
@@ -64,12 +89,10 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler {
public StructureTreeElement startNode(String name, Attributes attributes) {
PDFStructElem parent = ancestors.getFirst();
String role = attributes.getValue("role");
- PDFStructElem created;
- created = pdfFactory.getDocument().makeStructureElement(
- FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster), parent);
- parent.addKid(created);
- ancestors.addFirst(created);
- return created;
+ PDFStructElem structElem = createStructureElement(name, parent, role);
+ parent.addKid(structElem);
+ ancestors.addFirst(structElem);
+ return structElem;
}
public void endNode(String name) {
@@ -83,34 +106,30 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler {
public StructureTreeElement startImageNode(String name, Attributes attributes) {
PDFStructElem parent = ancestors.getFirst();
String role = attributes.getValue("role");
- PDFStructElem created;
- created = pdfFactory.getDocument().makeStructureElement(
- FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster), parent);
- parent.addKid(created);
+ PDFStructElem structElem = createStructureElement(name, parent, role);
+ parent.addKid(structElem);
String altTextNode = attributes.getValue(ExtensionElementMapping.URI, "alt-text");
if (altTextNode != null) {
- created.put("Alt", altTextNode);
+ structElem.put("Alt", altTextNode);
} else {
- created.put("Alt", "No alternate text specified");
+ structElem.put("Alt", "No alternate text specified");
}
- ancestors.addFirst(created);
- return created;
+ ancestors.addFirst(structElem);
+ return structElem;
}
public StructureTreeElement startReferencedNode(String name, Attributes attributes) {
PDFStructElem parent = ancestors.getFirst();
String role = attributes.getValue("role");
- PDFStructElem created;
+ PDFStructElem structElem;
if ("#PCDATA".equals(name)) {
- created = new PDFStructElem.Placeholder(parent, name);
+ structElem = new PDFStructElem.Placeholder(parent, name);
} else {
- created = pdfFactory.getDocument().makeStructureElement(
- FOToPDFRoleMap.mapFormattingObject(name, role, parent,
- eventBroadcaster), parent);
+ structElem = createStructureElement(name, parent, role);
}
- parent.addKid(created);
- ancestors.addFirst(created);
- return created;
+ parent.addKid(structElem);
+ ancestors.addFirst(structElem);
+ return structElem;
}
}