Moved accessibility initialization out of PDFRenderingUtil because PDFRenderer doesn't support accessibility and both the new and old implementation use this class. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@746248 13f79535-47bb-0310-9956-ffa450edef68tags/fop-1_0
@@ -623,10 +623,10 @@ public class FOUserAgent { | |||
} | |||
/** | |||
* check if accessibility is enabled | |||
* @return boolean | |||
* Check if accessibility is enabled. | |||
* @return true if accessibility is enabled | |||
*/ | |||
public boolean accessibilityEnabled() { | |||
public boolean isAccessibilityEnabled() { | |||
Boolean enabled = (Boolean)this.getRendererOptions().get("accessibility"); | |||
if (enabled != null) { | |||
return enabled.booleanValue(); |
@@ -111,7 +111,7 @@ public class Fop { | |||
if (foTreeBuilder == null) { | |||
createDefaultHandler(); | |||
} | |||
if (this.foUserAgent.accessibilityEnabled()) { | |||
if (this.foUserAgent.isAccessibilityEnabled()) { | |||
return AccessibilityUtil.decorateDefaultHandler(this.foTreeBuilder, foUserAgent); | |||
} else { | |||
return this.foTreeBuilder; |
@@ -200,7 +200,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler | |||
handler.startPrefixMapping(DocumentNavigationExtensionConstants.PREFIX, | |||
DocumentNavigationExtensionConstants.NAMESPACE); | |||
handler.startElement(EL_DOCUMENT); | |||
if (this.getUserAgent().accessibilityEnabled()) { | |||
if (this.getUserAgent().isAccessibilityEnabled()) { | |||
pageSequenceCounter = 0; | |||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |||
factory.setNamespaceAware(true); | |||
@@ -269,7 +269,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler | |||
} | |||
handler.startElement(EL_PAGE_SEQUENCE, atts); | |||
if (this.getUserAgent().accessibilityEnabled()) { | |||
if (this.getUserAgent().isAccessibilityEnabled()) { | |||
if (doc == null) { | |||
doc = parser.parse( | |||
new ByteArrayInputStream(this.getUserAgent().getReducedFOTree())); |
@@ -214,11 +214,21 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { | |||
super.startDocument(); | |||
try { | |||
this.pdfDoc = pdfUtil.setupPDFDocument(this.outputStream); | |||
this.accessEnabled = getUserAgent().accessibilityEnabled(); | |||
this.accessEnabled = getUserAgent().isAccessibilityEnabled(); | |||
if (accessEnabled) { | |||
this.pdfDoc.getRoot().makeTagged(); | |||
log.info("Accessibility is enabled"); | |||
PDFStructTreeRoot structTreeRoot = this.pdfDoc.getFactory().makeStructTreeRoot(); | |||
this.pdfDoc.getRoot().setStructTreeRoot(structTreeRoot); | |||
PDFStructElem structElemDocument = new PDFStructElem("root", structTreeRoot); | |||
this.pdfDoc.assignObjectNumber(structElemDocument); | |||
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(); | |||
@@ -241,7 +251,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { | |||
public void endDocument() throws IFException { | |||
try { | |||
pdfDoc.getResources().addFonts(pdfDoc, fontInfo); | |||
if (getUserAgent().accessibilityEnabled()) { | |||
if (getUserAgent().isAccessibilityEnabled()) { | |||
PDFNumsArray nums = parentTree.getNums(); | |||
for (int i = 0; i <= this.parentTreeKey; i++) { | |||
PDFArray tArray = new PDFArray(); | |||
@@ -288,7 +298,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { | |||
public void startPageSequence(String id) throws IFException { | |||
//TODO page sequence title, country and language | |||
if (getUserAgent().accessibilityEnabled()) { | |||
if (getUserAgent().isAccessibilityEnabled()) { | |||
try { | |||
if (doc == null) { | |||
doc = parser.parse( |
@@ -82,7 +82,7 @@ public class PDFImageHandlerRawJPEG implements PDFImageHandler, ImageHandler { | |||
float y = (float)pos.getY() / 1000f; | |||
float w = (float)pos.getWidth() / 1000f; | |||
float h = (float)pos.getHeight() / 1000f; | |||
if (context.getUserAgent().accessibilityEnabled()) { | |||
if (context.getUserAgent().isAccessibilityEnabled()) { | |||
String structElemType = pdfContext.getStructElemType(); | |||
if (structElemType.length() > 0) { | |||
int sequenceNum = pdfContext.getSequenceNum(); |
@@ -83,7 +83,7 @@ public class PDFImageHandlerRenderedImage implements PDFImageHandler, ImageHandl | |||
float y = (float)pos.getY() / 1000f; | |||
float w = (float)pos.getWidth() / 1000f; | |||
float h = (float)pos.getHeight() / 1000f; | |||
if (context.getUserAgent().accessibilityEnabled()) { | |||
if (context.getUserAgent().isAccessibilityEnabled()) { | |||
String structElemType = pdfContext.getStructElemType(); | |||
int sequenceNum = pdfContext.getSequenceNum(); | |||
generator.placeImage(x, y, w, h, xobj, structElemType, sequenceNum); |
@@ -121,7 +121,7 @@ public class PDFImageHandlerSVG implements ImageHandler { | |||
*/ | |||
generator.comment("SVG setup"); | |||
generator.saveGraphicsState(); | |||
if (context.getUserAgent().accessibilityEnabled()) { | |||
if (context.getUserAgent().isAccessibilityEnabled()) { | |||
String structElemType = pdfContext.getStructElemType(); | |||
int sequenceNum = pdfContext.getSequenceNum(); | |||
generator.startAccessSequence(structElemType, sequenceNum); | |||
@@ -173,7 +173,7 @@ public class PDFImageHandlerSVG implements ImageHandler { | |||
eventProducer.svgRenderingError(this, e, image.getInfo().getOriginalURI()); | |||
} | |||
generator.getState().restore(); | |||
if (context.getUserAgent().accessibilityEnabled()) { | |||
if (context.getUserAgent().isAccessibilityEnabled()) { | |||
generator.restoreGraphicsStateAccess(); | |||
} else { | |||
generator.restoreGraphicsState(); |
@@ -82,7 +82,7 @@ public class PDFPainter extends AbstractIFPainter { | |||
this.generator = documentHandler.generator; | |||
this.borderPainter = new PDFBorderPainter(this.generator); | |||
this.state = IFState.create(); | |||
accessEnabled = this.getUserAgent().accessibilityEnabled(); | |||
accessEnabled = this.getUserAgent().isAccessibilityEnabled(); | |||
} | |||
/** {@inheritDoc} */ |
@@ -52,8 +52,6 @@ import org.apache.fop.pdf.PDFMetadata; | |||
import org.apache.fop.pdf.PDFNumsArray; | |||
import org.apache.fop.pdf.PDFOutputIntent; | |||
import org.apache.fop.pdf.PDFPageLabels; | |||
import org.apache.fop.pdf.PDFStructElem; | |||
import org.apache.fop.pdf.PDFStructTreeRoot; | |||
import org.apache.fop.pdf.PDFXMode; | |||
import org.apache.fop.util.ColorProfileUtil; | |||
@@ -77,9 +75,6 @@ class PDFRenderingUtil implements PDFConfigurationConstants { | |||
/** the PDF/X mode (Default: disabled) */ | |||
protected PDFXMode pdfXMode = PDFXMode.DISABLED; | |||
/** the accessibility mode (Default: false=disabled) */ | |||
protected boolean accessibility = false; | |||
/** the (optional) encryption parameters */ | |||
protected PDFEncryptionParams encryptionParams; | |||
@@ -174,12 +169,6 @@ class PDFRenderingUtil implements PDFConfigurationConstants { | |||
if (s != null) { | |||
this.outputProfileURI = s; | |||
} | |||
// used for accessibility | |||
setting = userAgent.getRendererOptions().get(ACCESSIBLITY); | |||
if (setting != null) { | |||
this.accessibility = booleanValueOf(setting); | |||
} | |||
setting = userAgent.getRendererOptions().get(KEY_DISABLE_SRGB_COLORSPACE); | |||
if (setting != null) { | |||
this.disableSRGBColorSpace = booleanValueOf(setting); | |||
@@ -395,16 +384,6 @@ class PDFRenderingUtil implements PDFConfigurationConstants { | |||
log.debug("PDF/A is active. Conformance Level: " + pdfAMode); | |||
addPDFA1OutputIntent(); | |||
} | |||
if (this.accessibility) { | |||
this.pdfDoc.getRoot().makeTagged(); | |||
log.info("Accessibility is enabled"); | |||
PDFStructTreeRoot structTreeRoot = this.pdfDoc.getFactory().makeStructTreeRoot(); | |||
this.pdfDoc.getRoot().setStructTreeRoot(structTreeRoot); | |||
PDFStructElem structElemDocument = new PDFStructElem("root", structTreeRoot); | |||
this.pdfDoc.assignObjectNumber(structElemDocument); | |||
this.pdfDoc.addTrailerObject(structElemDocument); | |||
structTreeRoot.addKid(structElemDocument); | |||
} | |||
return this.pdfDoc; | |||
} | |||