Lines 23-31
import java.util.HashMap;
Link Here
|
23 |
import java.util.Locale; |
23 |
import java.util.Locale; |
24 |
import java.util.Map; |
24 |
import java.util.Map; |
25 |
|
25 |
|
26 |
import org.w3c.dom.Node; |
26 |
import org.apache.fop.accessibility.StructureElement; |
27 |
import org.w3c.dom.NodeList; |
|
|
28 |
|
29 |
import org.apache.fop.events.EventBroadcaster; |
27 |
import org.apache.fop.events.EventBroadcaster; |
30 |
import org.apache.fop.fo.extensions.ExtensionElementMapping; |
28 |
import org.apache.fop.fo.extensions.ExtensionElementMapping; |
31 |
import org.apache.fop.fo.extensions.InternalElementMapping; |
29 |
import org.apache.fop.fo.extensions.InternalElementMapping; |
Lines 123-129
class PDFLogicalStructureHandler {
Link Here
|
123 |
* @param structureTree the structure tree of the current page sequence |
121 |
* @param structureTree the structure tree of the current page sequence |
124 |
* @param language language set on the page sequence |
122 |
* @param language language set on the page sequence |
125 |
*/ |
123 |
*/ |
126 |
void processStructureTree(NodeList structureTree, Locale language) { |
124 |
void processStructureTree(StructureElement structureTree, Locale language) { |
127 |
pdfDoc.enforceLanguageOnRoot(); |
125 |
pdfDoc.enforceLanguageOnRoot(); |
128 |
PDFStructElem structElemPart = pdfDoc.getFactory().makeStructureElement( |
126 |
PDFStructElem structElemPart = pdfDoc.getFactory().makeStructureElement( |
129 |
FOToPDFRoleMap.mapFormattingObject("page-sequence", rootStructureElement), |
127 |
FOToPDFRoleMap.mapFormattingObject("page-sequence", rootStructureElement), |
Lines 134-157
class PDFLogicalStructureHandler {
Link Here
|
134 |
} |
132 |
} |
135 |
|
133 |
|
136 |
for (int i = 0, n = structureTree.getLength(); i < n; i++) { |
134 |
for (int i = 0, n = structureTree.getLength(); i < n; i++) { |
137 |
Node node = structureTree.item(i); |
135 |
StructureElement node = structureTree.getChild(i); |
138 |
assert node.getLocalName().equals("flow") |
136 |
assert node.getName().equals("flow") |
139 |
|| node.getLocalName().equals("static-content"); |
137 |
|| node.getName().equals("static-content"); |
140 |
PDFStructElem structElemSect = pdfDoc.getFactory().makeStructureElement( |
138 |
PDFStructElem structElemSect = pdfDoc.getFactory().makeStructureElement( |
141 |
FOToPDFRoleMap.mapFormattingObject(node.getLocalName(), structElemPart), |
139 |
FOToPDFRoleMap.mapFormattingObject(node.getName(), structElemPart), |
142 |
structElemPart); |
140 |
structElemPart); |
143 |
structElemPart.addKid(structElemSect); |
141 |
structElemPart.addKid(structElemSect); |
144 |
NodeList childNodes = node.getChildNodes(); |
142 |
for (int j = 0, m = node.getLength(); j < m; j++) { |
145 |
for (int j = 0, m = childNodes.getLength(); j < m; j++) { |
143 |
processNode(node.getChild(j), structElemSect, true); |
146 |
processNode(childNodes.item(j), structElemSect, true); |
|
|
147 |
} |
144 |
} |
148 |
} |
145 |
} |
149 |
} |
146 |
} |
150 |
|
147 |
|
151 |
private void processNode(Node node, PDFStructElem parent, boolean addKid) { |
148 |
private void processNode(StructureElement node, PDFStructElem parent, boolean addKid) { |
152 |
Node attr = node.getAttributes().getNamedItemNS(InternalElementMapping.URI, "ptr"); |
149 |
String ptr = node.getPtr(); |
153 |
assert attr != null; |
150 |
assert ptr != null; |
154 |
String ptr = attr.getNodeValue(); |
|
|
155 |
PDFStructElem structElem = pdfDoc.getFactory().makeStructureElement( |
151 |
PDFStructElem structElem = pdfDoc.getFactory().makeStructureElement( |
156 |
FOToPDFRoleMap.mapFormattingObject(node, parent, eventBroadcaster), parent); |
152 |
FOToPDFRoleMap.mapFormattingObject(node, parent, eventBroadcaster), parent); |
157 |
// TODO necessary? If a page-sequence is empty (e.g., contains a single |
153 |
// TODO necessary? If a page-sequence is empty (e.g., contains a single |
Lines 160-179
class PDFLogicalStructureHandler {
Link Here
|
160 |
if (addKid) { |
156 |
if (addKid) { |
161 |
parent.addKid(structElem); |
157 |
parent.addKid(structElem); |
162 |
} |
158 |
} |
163 |
String nodeName = node.getLocalName(); |
159 |
String nodeName = node.getName(); |
164 |
if (nodeName.equals("external-graphic") || nodeName.equals("instream-foreign-object")) { |
160 |
if (nodeName.equals("external-graphic") || nodeName.equals("instream-foreign-object")) { |
165 |
Node altTextNode = node.getAttributes().getNamedItemNS( |
161 |
String altTextNode = node.getAltText(); |
166 |
ExtensionElementMapping.URI, "alt-text"); |
|
|
167 |
if (altTextNode != null) { |
162 |
if (altTextNode != null) { |
168 |
structElem.put("Alt", altTextNode.getNodeValue()); |
163 |
structElem.put("Alt", altTextNode); |
169 |
} else { |
164 |
} else { |
170 |
structElem.put("Alt", "No alternate text specified"); |
165 |
structElem.put("Alt", "No alternate text specified"); |
171 |
} |
166 |
} |
172 |
} |
167 |
} |
173 |
structTreeMap.put(ptr, structElem); |
168 |
structTreeMap.put(ptr, structElem); |
174 |
NodeList nodes = node.getChildNodes(); |
169 |
for (int i = 0, n = node.getLength(); i < n; i++) { |
175 |
for (int i = 0, n = nodes.getLength(); i < n; i++) { |
170 |
processNode(node.getChild(i), structElem, false); |
176 |
processNode(nodes.item(i), structElem, false); |
|
|
177 |
} |
171 |
} |
178 |
} |
172 |
} |
179 |
|
173 |
|