aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
diff options
context:
space:
mode:
authorPeter Hancock <phancock@apache.org>2012-08-16 13:31:38 +0000
committerPeter Hancock <phancock@apache.org>2012-08-16 13:31:38 +0000
commit80e1071780dacf1235c0f31bf20fe6c6df7ff8e8 (patch)
tree012a241ed426e2d10965ab402f04f84c9827b421 /src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
parent3e96fb119fcbd9e6e0644092b0e2376bdbbe6c10 (diff)
parent726e1ef3093bedfd6671c2e6471e0d62ef605be5 (diff)
downloadxmlgraphics-fop-80e1071780dacf1235c0f31bf20fe6c6df7ff8e8.tar.gz
xmlgraphics-fop-80e1071780dacf1235c0f31bf20fe6c6df7ff8e8.zip
Merged trunk@1373227
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_RoundedCorners@1373825 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java')
-rw-r--r--src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java180
1 files changed, 49 insertions, 131 deletions
diff --git a/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java b/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
index 0f752e886..68bfd8686 100644
--- a/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
+++ b/src/java/org/apache/fop/render/pdf/FOToPDFRoleMap.java
@@ -19,145 +19,66 @@
package org.apache.fop.render.pdf;
-import java.util.HashMap;
import java.util.Map;
import org.apache.fop.events.EventBroadcaster;
-import org.apache.fop.pdf.PDFName;
import org.apache.fop.pdf.PDFObject;
import org.apache.fop.pdf.PDFStructElem;
+import org.apache.fop.pdf.StandardStructureTypes;
+import org.apache.fop.pdf.StructureType;
/**
* This class provides the standard mappings from Formatting Objects to PDF structure types.
*/
final class FOToPDFRoleMap {
- /**
- * Standard structure types defined by the PDF Reference, Fourth Edition (PDF 1.5).
- */
- private static final Map<String, PDFName> STANDARD_STRUCTURE_TYPES
- = new HashMap<String, PDFName>();
-
- private static final Map<String, Mapper> DEFAULT_MAPPINGS
- = new java.util.HashMap<String, Mapper>();
-
- private static final PDFName THEAD;
- private static final PDFName NON_STRUCT;
+ private static final Map<String, Mapper> DEFAULT_MAPPINGS = new java.util.HashMap<String, Mapper>();
static {
- // Create PDFNames for the standard structure types
- // Table 10.18: Grouping elements
- addStructureType("Document");
- addStructureType("Part");
- addStructureType("Art");
- addStructureType("Sect");
- addStructureType("Div");
- addStructureType("BlockQuote");
- addStructureType("Caption");
- addStructureType("TOC");
- addStructureType("TOCI");
- addStructureType("Index");
- addStructureType("NonStruct");
- addStructureType("Private");
- // Table 10.20: Paragraphlike elements
- addStructureType("H");
- addStructureType("H1");
- addStructureType("H2");
- addStructureType("H3");
- addStructureType("H4");
- addStructureType("H5");
- addStructureType("H6");
- addStructureType("P");
- // Table 10.21: List elements
- addStructureType("L");
- addStructureType("LI");
- addStructureType("Lbl");
- addStructureType("LBody");
- // Table 10.22: Table elements
- addStructureType("Table");
- addStructureType("TR");
- addStructureType("TH");
- addStructureType("TD");
- addStructureType("THead");
- addStructureType("TBody");
- addStructureType("TFoot");
- // Table 10.23: Inline-level structure elements
- addStructureType("Span");
- addStructureType("Quote");
- addStructureType("Note");
- addStructureType("Reference");
- addStructureType("BibEntry");
- addStructureType("Code");
- addStructureType("Link");
- addStructureType("Annot");
- // Table 10.24: Ruby and Warichu elements
- addStructureType("Ruby");
- addStructureType("RB");
- addStructureType("RT");
- addStructureType("RP");
- addStructureType("Warichu");
- addStructureType("WT");
- addStructureType("WP");
- // Table 10.25: Illustration elements
- addStructureType("Figure");
- addStructureType("Formula");
- addStructureType("Form");
-
- NON_STRUCT = STANDARD_STRUCTURE_TYPES.get("NonStruct");
- assert NON_STRUCT != null;
- THEAD = STANDARD_STRUCTURE_TYPES.get("THead");
- assert THEAD != null;
-
// Create the standard mappings
// Declarations and Pagination and Layout Formatting Objects
- addMapping("root", "Document");
- addMapping("page-sequence", "Part");
- addMapping("flow", "Sect");
- addMapping("static-content", "Sect");
+ addMapping("root", StandardStructureTypes.Grouping.DOCUMENT);
+ addMapping("page-sequence", StandardStructureTypes.Grouping.PART);
+ addMapping("flow", StandardStructureTypes.Grouping.SECT);
+ addMapping("static-content", StandardStructureTypes.Grouping.SECT);
// Block-level Formatting Objects
- addMapping("block", "P");
- addMapping("block-container", "Div");
+ addMapping("block", StandardStructureTypes.Paragraphlike.P);
+ addMapping("block-container", StandardStructureTypes.Grouping.DIV);
// Inline-level Formatting Objects
- addMapping("character", "Span");
- addMapping("external-graphic", "Figure");
- addMapping("instream-foreign-object", "Figure");
- addMapping("inline", "Span");
- addMapping("inline-container", "Div");
- addMapping("page-number", "Quote");
- addMapping("page-number-citation", "Quote");
- addMapping("page-number-citation-last", "Quote");
+ addMapping("character", StandardStructureTypes.InlineLevelStructure.SPAN);
+ addMapping("external-graphic", StandardStructureTypes.Illustration.FIGURE);
+ addMapping("instream-foreign-object", StandardStructureTypes.Illustration.FIGURE);
+ addMapping("inline", StandardStructureTypes.InlineLevelStructure.SPAN);
+ addMapping("inline-container", StandardStructureTypes.Grouping.DIV);
+ addMapping("page-number", StandardStructureTypes.InlineLevelStructure.QUOTE);
+ addMapping("page-number-citation", StandardStructureTypes.InlineLevelStructure.QUOTE);
+ addMapping("page-number-citation-last", StandardStructureTypes.InlineLevelStructure.QUOTE);
// Formatting Objects for Tables
- addMapping("table-and-caption", "Div");
- addMapping("table", "Table");
- addMapping("table-caption", "Caption");
- addMapping("table-header", "THead");
- addMapping("table-footer", "TFoot");
- addMapping("table-body", "TBody");
- addMapping("table-row", "TR");
+ addMapping("table-and-caption", StandardStructureTypes.Grouping.DIV);
+ addMapping("table", StandardStructureTypes.Table.TABLE);
+ addMapping("table-caption", StandardStructureTypes.Grouping.CAPTION);
+ addMapping("table-header", StandardStructureTypes.Table.THEAD);
+ addMapping("table-footer", StandardStructureTypes.Table.TFOOT);
+ addMapping("table-body", StandardStructureTypes.Table.TBODY);
+ addMapping("table-row", StandardStructureTypes.Table.TR);
addMapping("table-cell", new TableCellMapper());
// Formatting Objects for Lists
- addMapping("list-block", "L");
- addMapping("list-item", "LI");
- addMapping("list-item-body", "LBody");
- addMapping("list-item-label", "Lbl");
+ addMapping("list-block", StandardStructureTypes.List.L);
+ addMapping("list-item", StandardStructureTypes.List.LI);
+ addMapping("list-item-body", StandardStructureTypes.List.LBODY);
+ addMapping("list-item-label", StandardStructureTypes.List.LBL);
// Dynamic Effects: Link and Multi Formatting Objects
- addMapping("basic-link", "Link");
+ addMapping("basic-link", StandardStructureTypes.InlineLevelStructure.LINK);
// Out-of-Line Formatting Objects
- addMapping("float", "Div");
- addMapping("footnote", "Note");
- addMapping("footnote-body", "Sect");
- addMapping("wrapper", "Span");
- addMapping("marker", "Private");
- }
-
- private static void addStructureType(String structureType) {
- STANDARD_STRUCTURE_TYPES.put(structureType, new PDFName(structureType));
+ addMapping("float", StandardStructureTypes.Grouping.DIV);
+ addMapping("footnote", StandardStructureTypes.InlineLevelStructure.NOTE);
+ addMapping("footnote-body", StandardStructureTypes.Grouping.SECT);
+ addMapping("wrapper", StandardStructureTypes.InlineLevelStructure.SPAN);
+ addMapping("marker", StandardStructureTypes.Grouping.PRIVATE);
}
- private static void addMapping(String fo, String structureType) {
- PDFName type = STANDARD_STRUCTURE_TYPES.get(structureType);
- assert type != null;
- addMapping(fo, new SimpleMapper(type));
+ private static void addMapping(String fo, StructureType structureType) {
+ addMapping(fo, new SimpleMapper(structureType));
}
private static void addMapping(String fo, Mapper mapper) {
@@ -173,13 +94,13 @@ final class FOToPDFRoleMap {
* @param eventBroadcaster the event broadcaster
* @return the structure type or null if no match could be found
*/
- public static PDFName mapFormattingObject(String fo, String role,
+ public static StructureType mapFormattingObject(String fo, String role,
PDFObject parent, EventBroadcaster eventBroadcaster) {
- PDFName type = null;
+ StructureType type = null;
if (role == null) {
type = getDefaultMappingFor(fo, parent);
} else {
- type = STANDARD_STRUCTURE_TYPES.get(role);
+ type = StandardStructureTypes.get(role);
if (type == null) {
type = getDefaultMappingFor(fo, parent);
PDFEventProducer.Provider.get(eventBroadcaster).nonStandardStructureType(fo,
@@ -196,28 +117,28 @@ final class FOToPDFRoleMap {
* @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) {
+ private static StructureType getDefaultMappingFor(String fo, PDFObject parent) {
Mapper mapper = DEFAULT_MAPPINGS.get(fo);
if (mapper != null) {
return mapper.getStructureType(parent);
} else {
- return NON_STRUCT;
+ return StandardStructureTypes.Grouping.NON_STRUCT;
}
}
private interface Mapper {
- PDFName getStructureType(PDFObject parent);
+ StructureType getStructureType(PDFObject parent);
}
private static class SimpleMapper implements Mapper {
- private PDFName structureType;
+ private StructureType structureType;
- public SimpleMapper(PDFName structureType) {
+ public SimpleMapper(StructureType structureType) {
this.structureType = structureType;
}
- public PDFName getStructureType(PDFObject parent) {
+ public StructureType getStructureType(PDFObject parent) {
return structureType;
}
@@ -225,17 +146,14 @@ final class FOToPDFRoleMap {
private static class TableCellMapper implements Mapper {
- public PDFName getStructureType(PDFObject parent) {
+ public StructureType getStructureType(PDFObject parent) {
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 = STANDARD_STRUCTURE_TYPES.get("TH");
+ if (grandParent.getStructureType() == StandardStructureTypes.Table.THEAD) {
+ return StandardStructureTypes.Table.TH;
} else {
- type = STANDARD_STRUCTURE_TYPES.get("TD");
+ return StandardStructureTypes.Table.TD;
}
- assert type != null;
- return type;
}
}