diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-04-17 12:10:07 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-04-17 12:10:07 +0000 |
commit | 8eefdf7d68cc640ca4c3d4ac331e5af1a9049ee0 (patch) | |
tree | d7ff2463e2e2ce6a322e9df1796a8b205f2c5440 /src/java/org/apache/fop/render/pdf | |
parent | eeb0cc4fb8f3816e7507ce22de0fb4b9dd433f1c (diff) | |
download | xmlgraphics-fop-8eefdf7d68cc640ca4c3d4ac331e5af1a9049ee0.tar.gz xmlgraphics-fop-8eefdf7d68cc640ca4c3d4ac331e5af1a9049ee0.zip |
Added support for adding natural language information on page-sequence and document level to a tagged PDF.
The document-level language is assumed to be the language of the first page-sequence.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@765965 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/PDFDocumentHandler.java | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java index 7f5a9be5f..aba4cceb3 100644 --- a/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFDocumentHandler.java @@ -70,6 +70,7 @@ import org.apache.fop.render.intermediate.IFDocumentHandlerConfigurator; import org.apache.fop.render.intermediate.IFDocumentNavigationHandler; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.IFPainter; +import org.apache.fop.util.XMLUtil; /** * {@code IFDocumentHandler} implementation that produces PDF. @@ -82,7 +83,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { /** the following variables are used for accessibility */ private int pageSequenceCounter; private DocumentBuilder parser = null; - private Document doc = null; + private Document reducedFOTree = null; private Map structElemType = new HashMap(); private boolean accessEnabled = false; private int parentTreeKey = -1; @@ -226,10 +227,6 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { this.pdfDoc.addTrailerObject(structElemDocument); structTreeRoot.addKid(structElemDocument); - //TODO: make document language variable, see note on wiki page PDF Accessibility - //TODO: and follow-up emails on fop-dev - this.pdfDoc.getRoot().setLanguage("en"); - parentTree = new PDFParentTree(); pageSequenceCounter = 0; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -271,7 +268,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { getStructTreeRoot().addParentTree(parentTree); pdfDoc.outputTrailer(this.outputStream); parser = null; - doc = null; + reducedFOTree = null; structElemType = null; parentTree = null; structTreeMap = null; @@ -298,17 +295,31 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { /** {@inheritDoc} */ public void startPageSequence(String id) throws IFException { - //TODO page sequence title, country and language + //TODO page sequence title + + if (this.pdfDoc.getRoot().getLanguage() == null + && getContext().getLanguage() != null) { + //No document-level language set, so we use the first page-sequence's language + this.pdfDoc.getRoot().setLanguage(XMLUtil.toRFC3066(getContext().getLanguage())); + } if (getUserAgent().isAccessibilityEnabled()) { try { - if (doc == null) { - doc = parser.parse( + if (this.pdfDoc.getRoot().getLanguage() == null) { + //No language has been set on the first page-sequence, so fall back to "en". + this.pdfDoc.getRoot().setLanguage("en"); + } + + if (reducedFOTree == null) { + reducedFOTree = parser.parse( new ByteArrayInputStream(this.getUserAgent().getReducedFOTree())); } PDFStructElem parent = (PDFStructElem)getStructTreeRoot().getFirstChild(); PDFStructElem structElemPart = new PDFStructElem(parent, FOToPDFRoleMap.mapFormattingObject("page-sequence", parent)); + if (getContext().getLanguage() != null) { + structElemPart.setLanguage(getContext().getLanguage()); + } this.pdfDoc.assignObjectNumber(structElemPart); this.pdfDoc.addTrailerObject(structElemPart); parent.addKid(structElemPart); @@ -320,7 +331,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { "http://www.w3.org/1999/XSL/Format"); xpath.setNamespaceContext(namespaceContext); - NodeList nodes = (NodeList) xpath.evaluate(xpathExpr, doc, + NodeList nodes = (NodeList) xpath.evaluate(xpathExpr, reducedFOTree, XPathConstants.NODESET); for (int i = 0, n = nodes.getLength(); i < n; i++) { |