From cfa853d5b2a728fa90c12cd1a44ca1a3eec1a12e Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Wed, 17 Nov 2010 19:45:27 +0000 Subject: findbugs-reported bug squashing; 959 bugs left (findbugs 1.3.9) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1036179 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/render/intermediate/extensions/AbstractAction.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java') diff --git a/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java b/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java index 340b2e068..8d8a30cf6 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java @@ -33,7 +33,7 @@ public abstract class AbstractAction implements XMLizable { * Sets an ID to make the action referencable. * @param id the ID */ - public void setID(String id) { + public void setId(String id) { this.id = id; } @@ -41,7 +41,7 @@ public abstract class AbstractAction implements XMLizable { * Returns an optional ID for this action. * @return the ID or null */ - public String getID() { + public String getId() { return this.id; } @@ -65,7 +65,7 @@ public abstract class AbstractAction implements XMLizable { * Indicates whether the action has an ID and is therefore referencable. * @return true if the action has an ID */ - public boolean hasID() { + public boolean hasId() { return this.id != null; } @@ -90,7 +90,7 @@ public abstract class AbstractAction implements XMLizable { * Returns a string that is used to prefix a generated ID to make it unique. * @return the prefix string */ - public String getIDPrefix() { + public String getIdPrefix() { return null; } -- cgit v1.2.3 From bf82c8fb0162ff0c8f31092b73756746b424c3a4 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Fri, 19 Nov 2010 11:25:15 +0000 Subject: Reverting renaming of public methods of rev. 1036179 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1036809 13f79535-47bb-0310-9956-ffa450edef68 --- .../embedding/java/embedding/ExampleFO2PDF.java | 4 +- .../embedding/java/embedding/MultipleFO2PDF.java | 4 +- .../org/apache/fop/apps/PageSequenceResults.java | 2 +- src/java/org/apache/fop/area/BlockParent.java | 3 - .../org/apache/fop/cli/CommandLineOptions.java | 206 ++++++++++----------- src/java/org/apache/fop/fo/FOText.java | 2 +- src/java/org/apache/fop/fonts/apps/PFMReader.java | 4 +- src/java/org/apache/fop/fonts/type1/PFMFile.java | 10 +- .../apache/fop/fonts/type1/Type1FontLoader.java | 4 +- .../fop/render/AbstractGenericSVGHandler.java | 2 +- src/java/org/apache/fop/render/XMLHandler.java | 2 +- .../org/apache/fop/render/XMLHandlerRegistry.java | 2 +- .../fop/render/afp/AFPRendererImageInfo.java | 2 +- .../fop/render/intermediate/IFSerializer.java | 8 +- .../intermediate/extensions/AbstractAction.java | 8 +- .../render/intermediate/extensions/ActionSet.java | 8 +- .../extensions/DocumentNavigationHandler.java | 2 +- .../intermediate/extensions/GoToXYAction.java | 8 +- .../render/intermediate/extensions/URIAction.java | 6 +- .../render/pdf/PDFDocumentNavigationHandler.java | 12 +- .../apache/fop/render/ps/PSImageFormResource.java | 2 +- .../org/apache/fop/render/ps/ResourceHandler.java | 2 +- .../fop/render/rtf/TextAttributesConverter.java | 2 +- .../org/apache/fop/render/xml/XMLXMLHandler.java | 2 +- src/java/org/apache/fop/tools/TestConverter.java | 18 +- src/java/org/apache/fop/tools/anttasks/Fop.java | 32 ++-- .../org/apache/fop/render/svg/SVGSVGHandler.java | 8 +- 27 files changed, 181 insertions(+), 184 deletions(-) (limited to 'src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java') diff --git a/examples/embedding/java/embedding/ExampleFO2PDF.java b/examples/embedding/java/embedding/ExampleFO2PDF.java index 20d27c128..6ae674908 100644 --- a/examples/embedding/java/embedding/ExampleFO2PDF.java +++ b/examples/embedding/java/embedding/ExampleFO2PDF.java @@ -94,8 +94,8 @@ public class ExampleFO2PDF { for (java.util.Iterator it = pageSequences.iterator(); it.hasNext();) { PageSequenceResults pageSequenceResults = (PageSequenceResults)it.next(); System.out.println("PageSequence " - + (String.valueOf(pageSequenceResults.getId()).length() > 0 - ? pageSequenceResults.getId() : "") + + (String.valueOf(pageSequenceResults.getID()).length() > 0 + ? pageSequenceResults.getID() : "") + " generated " + pageSequenceResults.getPageCount() + " pages."); } System.out.println("Generated " + foResults.getPageCount() + " pages in total."); diff --git a/examples/embedding/java/embedding/MultipleFO2PDF.java b/examples/embedding/java/embedding/MultipleFO2PDF.java index 0da9ae14c..a9ace7cf0 100644 --- a/examples/embedding/java/embedding/MultipleFO2PDF.java +++ b/examples/embedding/java/embedding/MultipleFO2PDF.java @@ -147,8 +147,8 @@ public class MultipleFO2PDF { for (java.util.Iterator it = pageSequences.iterator(); it.hasNext();) { PageSequenceResults pageSequenceResults = (PageSequenceResults)it.next(); System.out.println("PageSequence " - + (String.valueOf(pageSequenceResults.getId()).length() > 0 - ? pageSequenceResults.getId() : "") + + (String.valueOf(pageSequenceResults.getID()).length() > 0 + ? pageSequenceResults.getID() : "") + " generated " + pageSequenceResults.getPageCount() + " pages."); } System.out.println("Generated " + foResults.getPageCount() + " pages in total."); diff --git a/src/java/org/apache/fop/apps/PageSequenceResults.java b/src/java/org/apache/fop/apps/PageSequenceResults.java index f94fe8fdb..241f4a5f9 100644 --- a/src/java/org/apache/fop/apps/PageSequenceResults.java +++ b/src/java/org/apache/fop/apps/PageSequenceResults.java @@ -44,7 +44,7 @@ public class PageSequenceResults { * * @return The ID */ - public String getId() { + public String getID() { return this.id; } diff --git a/src/java/org/apache/fop/area/BlockParent.java b/src/java/org/apache/fop/area/BlockParent.java index f2cf01cf2..18f9056da 100644 --- a/src/java/org/apache/fop/area/BlockParent.java +++ b/src/java/org/apache/fop/area/BlockParent.java @@ -27,9 +27,6 @@ import java.util.List; */ public class BlockParent extends Area { - /** - * - */ private static final long serialVersionUID = 7076916890348533805L; // this position is used for absolute position diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index eff7b76f0..2a5c0d272 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -89,23 +89,23 @@ public class CommandLineOptions { /* user configuration file */ private File userConfigFile = null; /* input fo file */ - private File foFile = null; + private File fofile = null; /* xsltfile (xslt transformation as input) */ - private File xsltFile = null; + private File xsltfile = null; /* xml file (xslt transformation as input) */ - private File xmlFile = null; + private File xmlfile = null; /* area tree input file */ - private File areatreeFile = null; + private File areatreefile = null; /* intermediate format input file */ - private File ifFile = null; + private File iffile = null; /* area tree input file */ - private File imageFile = null; + private File imagefile = null; /* output file */ - private File outFile = null; + private File outfile = null; /* input mode */ - private int inputMode = NOT_SET; + private int inputmode = NOT_SET; /* output mode */ - private String outputMode = null; + private String outputmode = null; /* true if System.in (stdin) should be used for the input file */ private boolean useStdIn = false; /* true if System.out (stdout) should be used for the output file */ @@ -194,7 +194,7 @@ public class CommandLineOptions { inputHandler = createInputHandler(); - if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputMode)) { + if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputmode)) { //set the system look&feel for the preview dialog try { UIManager.setLookAndFeel( @@ -207,7 +207,7 @@ public class CommandLineOptions { renderer.setRenderable(inputHandler); //set before user agent! renderer.setUserAgent(foUserAgent); foUserAgent.setRendererOverride(renderer); - } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputMode) + } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode) && mimicRenderer != null) { // render from FO to Intermediate Format Renderer targetRenderer = foUserAgent.getRendererFactory().createRenderer( @@ -220,7 +220,7 @@ public class CommandLineOptions { //Make sure the prepared XMLRenderer is used foUserAgent.setRendererOverride(xmlRenderer); - } else if (MimeConstants.MIME_FOP_IF.equals(outputMode) + } else if (MimeConstants.MIME_FOP_IF.equals(outputmode) && mimicRenderer != null) { // render from FO to Intermediate Format IFSerializer serializer = new IFSerializer(); @@ -447,7 +447,7 @@ public class CommandLineOptions { if (isSystemInOutFile(filename)) { this.useStdIn = true; } else { - foFile = new File(filename); + fofile = new File(filename); } return 1; } @@ -460,7 +460,7 @@ public class CommandLineOptions { throw new FOPException("you must specify the stylesheet " + "file for the '-xsl' option"); } else { - xsltFile = new File(args[i + 1]); + xsltfile = new File(args[i + 1]); return 1; } } @@ -476,7 +476,7 @@ public class CommandLineOptions { if (isSystemInOutFile(filename)) { this.useStdIn = true; } else { - xmlFile = new File(filename); + xmlfile = new File(filename); } return 1; } @@ -508,7 +508,7 @@ public class CommandLineOptions { if (isSystemInOutFile(filename)) { this.useStdOut = true; } else { - outFile = new File(filename); + outfile = new File(filename); } } @@ -701,16 +701,16 @@ public class CommandLineOptions { } private int parseUnknownOption(String[] args, int i) throws FOPException { - if (inputMode == NOT_SET) { - inputMode = FO_INPUT; + if (inputmode == NOT_SET) { + inputmode = FO_INPUT; String filename = args[i]; if (isSystemInOutFile(filename)) { this.useStdIn = true; } else { - foFile = new File(filename); + fofile = new File(filename); } - } else if (outputMode == null) { - outputMode = MimeConstants.MIME_PDF; + } else if (outputmode == null) { + outputmode = MimeConstants.MIME_PDF; setOutputFile(args[i]); } else { throw new FOPException("Don't know what to do with " @@ -765,7 +765,7 @@ public class CommandLineOptions { if (isSystemInOutFile(filename)) { this.useStdIn = true; } else { - areatreeFile = new File(filename); + areatreefile = new File(filename); } return 1; } @@ -781,7 +781,7 @@ public class CommandLineOptions { if (isSystemInOutFile(filename)) { this.useStdIn = true; } else { - ifFile = new File(filename); + iffile = new File(filename); } return 1; } @@ -797,7 +797,7 @@ public class CommandLineOptions { if (isSystemInOutFile(filename)) { this.useStdIn = true; } else { - imageFile = new File(filename); + imagefile = new File(filename); } return 1; } @@ -867,8 +867,8 @@ public class CommandLineOptions { } private void setOutputMode(String mime) throws FOPException { - if (outputMode == null) { - outputMode = mime; + if (outputmode == null) { + outputmode = mime; } else { throw new FOPException("you can only set one output method"); } @@ -896,8 +896,8 @@ public class CommandLineOptions { } private void setInputFormat(int format) throws FOPException { - if (inputMode == NOT_SET || inputMode == format) { - inputMode = format; + if (inputmode == NOT_SET || inputmode == format) { + inputmode = format; } else { throw new FOPException("Only one input mode can be specified!"); } @@ -907,100 +907,100 @@ public class CommandLineOptions { * checks whether all necessary information has been given in a consistent way */ private void checkSettings() throws FOPException, FileNotFoundException { - if (inputMode == NOT_SET) { + if (inputmode == NOT_SET) { throw new FOPException("No input file specified"); } - if (outputMode == null) { + if (outputmode == null) { throw new FOPException("No output file specified"); } - if ((outputMode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW) - || outputMode.equals(MimeConstants.MIME_FOP_PRINT)) - && outFile != null) { + if ((outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW) + || outputmode.equals(MimeConstants.MIME_FOP_PRINT)) + && outfile != null) { throw new FOPException("Output file may not be specified " + "for AWT or PRINT output"); } - if (inputMode == XSLT_INPUT) { + if (inputmode == XSLT_INPUT) { // check whether xml *and* xslt file have been set - if (xmlFile == null && !this.useStdIn) { + if (xmlfile == null && !this.useStdIn) { throw new FOPException("XML file must be specified for the transform mode"); } - if (xsltFile == null) { + if (xsltfile == null) { throw new FOPException("XSLT file must be specified for the transform mode"); } // warning if fofile has been set in xslt mode - if (foFile != null) { + if (fofile != null) { log.warn("Can't use fo file with transform mode! Ignoring.\n" + "Your input is " + "\n xmlfile: " - + xmlFile.getAbsolutePath() + + xmlfile.getAbsolutePath() + "\nxsltfile: " - + xsltFile.getAbsolutePath() + + xsltfile.getAbsolutePath() + "\n fofile: " - + foFile.getAbsolutePath()); + + fofile.getAbsolutePath()); } - if (xmlFile != null && !xmlFile.exists()) { + if (xmlfile != null && !xmlfile.exists()) { throw new FileNotFoundException("Error: xml file " - + xmlFile.getAbsolutePath() + + xmlfile.getAbsolutePath() + " not found "); } - if (!xsltFile.exists()) { + if (!xsltfile.exists()) { throw new FileNotFoundException("Error: xsl file " - + xsltFile.getAbsolutePath() + + xsltfile.getAbsolutePath() + " not found "); } - } else if (inputMode == FO_INPUT) { - if (outputMode.equals(MimeConstants.MIME_XSL_FO)) { + } else if (inputmode == FO_INPUT) { + if (outputmode.equals(MimeConstants.MIME_XSL_FO)) { throw new FOPException( "FO output mode is only available if you use -xml and -xsl"); } - if (foFile != null && !foFile.exists()) { + if (fofile != null && !fofile.exists()) { throw new FileNotFoundException("Error: fo file " - + foFile.getAbsolutePath() + + fofile.getAbsolutePath() + " not found "); } - } else if (inputMode == AREATREE_INPUT) { - if (outputMode.equals(MimeConstants.MIME_XSL_FO)) { + } else if (inputmode == AREATREE_INPUT) { + if (outputmode.equals(MimeConstants.MIME_XSL_FO)) { throw new FOPException( "FO output mode is only available if you use -xml and -xsl"); - } else if (outputMode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { + } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { throw new FOPException( "Area Tree Output is not available if Area Tree is used as input!"); } - if (areatreeFile != null && !areatreeFile.exists()) { + if (areatreefile != null && !areatreefile.exists()) { throw new FileNotFoundException("Error: area tree file " - + areatreeFile.getAbsolutePath() + + areatreefile.getAbsolutePath() + " not found "); } - } else if (inputMode == IF_INPUT) { - if (outputMode.equals(MimeConstants.MIME_XSL_FO)) { + } else if (inputmode == IF_INPUT) { + if (outputmode.equals(MimeConstants.MIME_XSL_FO)) { throw new FOPException( "FO output mode is only available if you use -xml and -xsl"); - } else if (outputMode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { + } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { throw new FOPException( "Area Tree Output is not available if Intermediate Format" + " is used as input!"); - } else if (outputMode.equals(MimeConstants.MIME_FOP_IF)) { + } else if (outputmode.equals(MimeConstants.MIME_FOP_IF)) { throw new FOPException( "Intermediate Output is not available if Intermediate Format" + " is used as input!"); } - if (ifFile != null && !ifFile.exists()) { + if (iffile != null && !iffile.exists()) { throw new FileNotFoundException("Error: intermediate format file " - + ifFile.getAbsolutePath() + + iffile.getAbsolutePath() + " not found "); } - } else if (inputMode == IMAGE_INPUT) { - if (outputMode.equals(MimeConstants.MIME_XSL_FO)) { + } else if (inputmode == IMAGE_INPUT) { + if (outputmode.equals(MimeConstants.MIME_XSL_FO)) { throw new FOPException( "FO output mode is only available if you use -xml and -xsl"); } - if (imageFile != null && !imageFile.exists()) { + if (imagefile != null && !imagefile.exists()) { throw new FileNotFoundException("Error: image file " - + imageFile.getAbsolutePath() + + imagefile.getAbsolutePath() + " not found "); } } @@ -1027,13 +1027,13 @@ public class CommandLineOptions { * @throws FOPException for invalid output formats */ protected String getOutputFormat() throws FOPException { - if (outputMode == null) { + if (outputmode == null) { throw new FOPException("Renderer has not been set!"); } - if (outputMode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { + if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) { renderingOptions.put("fineDetail", isCoarseAreaXml()); } - return outputMode; + return outputmode; } /** @@ -1042,21 +1042,21 @@ public class CommandLineOptions { * @throws IllegalArgumentException if invalid/missing parameters */ private InputHandler createInputHandler() { - switch (inputMode) { + switch (inputmode) { case FO_INPUT: - return new InputHandler(foFile); + return new InputHandler(fofile); case AREATREE_INPUT: - return new AreaTreeInputHandler(areatreeFile); + return new AreaTreeInputHandler(areatreefile); case IF_INPUT: - return new IFInputHandler(ifFile); + return new IFInputHandler(iffile); case XSLT_INPUT: - InputHandler handler = new InputHandler(xmlFile, xsltFile, xsltParams); + InputHandler handler = new InputHandler(xmlfile, xsltfile, xsltParams); if (useCatalogResolver) { handler.createCatalogResolver(foUserAgent); } return handler; case IMAGE_INPUT: - return new ImageInputHandler(imageFile, xsltFile, xsltParams); + return new ImageInputHandler(imagefile, xsltfile, xsltParams); default: throw new IllegalArgumentException("Error creating InputHandler object."); } @@ -1074,24 +1074,24 @@ public class CommandLineOptions { * Returns the XSL-FO file if set. * @return the XSL-FO file, null if not set */ - public File getFoFile() { - return foFile; + public File getFOFile() { + return fofile; } /** * Returns the input XML file if set. * @return the input XML file, null if not set */ - public File getXmlFile() { - return xmlFile; + public File getXMLFile() { + return xmlfile; } /** * Returns the stylesheet to be used for transformation to XSL-FO. * @return stylesheet */ - public File getXslFile() { - return xsltFile; + public File getXSLFile() { + return xsltfile; } /** @@ -1099,7 +1099,7 @@ public class CommandLineOptions { * @return the output file */ public File getOutputFile() { - return outFile; + return outfile; } /** @@ -1139,13 +1139,13 @@ public class CommandLineOptions { * @return either the fofile or the xmlfile */ public File getInputFile() { - switch (inputMode) { + switch (inputmode) { case FO_INPUT: - return foFile; + return fofile; case XSLT_INPUT: - return xmlFile; + return xmlfile; default: - return foFile; + return fofile; } } @@ -1270,7 +1270,7 @@ public class CommandLineOptions { */ private void dumpConfiguration() { log.info("Input mode: "); - switch (inputMode) { + switch (inputmode) { case NOT_SET: log.info("not set"); break; @@ -1279,7 +1279,7 @@ public class CommandLineOptions { if (isInputFromStdIn()) { log.info("fo input file: from stdin"); } else { - log.info("fo input file: " + foFile.toString()); + log.info("fo input file: " + fofile.toString()); } break; case XSLT_INPUT: @@ -1287,16 +1287,16 @@ public class CommandLineOptions { if (isInputFromStdIn()) { log.info("xml input file: from stdin"); } else { - log.info("xml input file: " + xmlFile.toString()); + log.info("xml input file: " + xmlfile.toString()); } - log.info("xslt stylesheet: " + xsltFile.toString()); + log.info("xslt stylesheet: " + xsltfile.toString()); break; case AREATREE_INPUT: log.info("AT "); if (isInputFromStdIn()) { log.info("area tree input file: from stdin"); } else { - log.info("area tree input file: " + areatreeFile.toString()); + log.info("area tree input file: " + areatreefile.toString()); } break; case IF_INPUT: @@ -1304,7 +1304,7 @@ public class CommandLineOptions { if (isInputFromStdIn()) { log.info("intermediate input file: from stdin"); } else { - log.info("intermediate input file: " + ifFile.toString()); + log.info("intermediate input file: " + iffile.toString()); } break; case IMAGE_INPUT: @@ -1312,28 +1312,28 @@ public class CommandLineOptions { if (isInputFromStdIn()) { log.info("image input file: from stdin"); } else { - log.info("image input file: " + imageFile.toString()); + log.info("image input file: " + imagefile.toString()); } break; default: log.info("unknown input type"); } log.info("Output mode: "); - if (outputMode == null) { + if (outputmode == null) { log.info("not set"); - } else if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputMode)) { + } else if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputmode)) { log.info("awt on screen"); - if (outFile != null) { + if (outfile != null) { log.error("awt mode, but outfile is set:"); - log.error("out file: " + outFile.toString()); + log.error("out file: " + outfile.toString()); } - } else if (MimeConstants.MIME_FOP_PRINT.equals(outputMode)) { + } else if (MimeConstants.MIME_FOP_PRINT.equals(outputmode)) { log.info("print directly"); - if (outFile != null) { + if (outfile != null) { log.error("print mode, but outfile is set:"); - log.error("out file: " + outFile.toString()); + log.error("out file: " + outfile.toString()); } - } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputMode)) { + } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)) { log.info("area tree"); if (mimicRenderer != null) { log.info("mimic renderer: " + mimicRenderer); @@ -1341,17 +1341,17 @@ public class CommandLineOptions { if (isOutputToStdOut()) { log.info("output file: to stdout"); } else { - log.info("output file: " + outFile.toString()); + log.info("output file: " + outfile.toString()); } - } else if (MimeConstants.MIME_FOP_IF.equals(outputMode)) { + } else if (MimeConstants.MIME_FOP_IF.equals(outputmode)) { log.info("intermediate format"); - log.info("output file: " + outFile.toString()); + log.info("output file: " + outfile.toString()); } else { - log.info(outputMode); + log.info(outputmode); if (isOutputToStdOut()) { log.info("output file: to stdout"); } else { - log.info("output file: " + outFile.toString()); + log.info("output file: " + outfile.toString()); } } diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index c78421cbe..5db11f731 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -619,7 +619,7 @@ public class FOText extends FONode implements CharSequence { } /** @return the baseline-shift property */ - public Length getBaselineShift() { + public Length getBaseLineShift() { return baselineShift; } diff --git a/src/java/org/apache/fop/fonts/apps/PFMReader.java b/src/java/org/apache/fop/fonts/apps/PFMReader.java index bc294057b..e5e8ca524 100644 --- a/src/java/org/apache/fop/fonts/apps/PFMReader.java +++ b/src/java/org/apache/fop/fonts/apps/PFMReader.java @@ -173,7 +173,7 @@ public class PFMReader extends AbstractFontReader { public void preview(PFMFile pfm) { if (log != null && log.isInfoEnabled()) { log.info("Font: " + pfm.getWindowsName()); - log.info("Name: " + pfm.getPostScriptName()); + log.info("Name: " + pfm.getPostscriptName()); log.info("CharSet: " + pfm.getCharSetName()); log.info("CapHeight: " + pfm.getCapHeight()); log.info("XHeight: " + pfm.getXHeight()); @@ -217,7 +217,7 @@ public class PFMReader extends AbstractFontReader { Element el = doc.createElement("font-name"); root.appendChild(el); - el.appendChild(doc.createTextNode(pfm.getPostScriptName())); + el.appendChild(doc.createTextNode(pfm.getPostscriptName())); // Currently unused. // String s = pfm.getPostscriptName(); diff --git a/src/java/org/apache/fop/fonts/type1/PFMFile.java b/src/java/org/apache/fop/fonts/type1/PFMFile.java index b5faddac1..d1a3d79ff 100644 --- a/src/java/org/apache/fop/fonts/type1/PFMFile.java +++ b/src/java/org/apache/fop/fonts/type1/PFMFile.java @@ -38,7 +38,7 @@ public class PFMFile { // Header stuff private String windowsName; - private String postScriptName; + private String postscriptName; private short dfItalic; private int dfWeight; private short dfCharSet; @@ -164,7 +164,7 @@ public class PFMFile { inStream.reset(); inStream.skip(driverInfoOffset); - postScriptName = inStream.readString(); + postscriptName = inStream.readString(); if (extMetricsOffset != 0) { inStream.reset(); @@ -279,8 +279,8 @@ public class PFMFile { * * @return The Postscript name. */ - public String getPostScriptName() { - return postScriptName; + public String getPostscriptName() { + return postscriptName; } /** @@ -304,7 +304,7 @@ public class PFMFile { case 0: return "WinAnsi"; // AKA ISOAdobe case 2: - if ("Symbol".equals(getPostScriptName())) { + if ("Symbol".equals(getPostscriptName())) { return "Symbol"; } break; diff --git a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java index 0c0c6187c..d5036de7b 100644 --- a/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java +++ b/src/java/org/apache/fop/fonts/type1/Type1FontLoader.java @@ -226,8 +226,8 @@ public class Type1FontLoader extends FontLoader { names.add(afm.getFamilyName()); returnFont.setFamilyNames(names); } else { - returnFont.setFontName(pfm.getPostScriptName()); - String fullName = pfm.getPostScriptName(); + returnFont.setFontName(pfm.getPostscriptName()); + String fullName = pfm.getPostscriptName(); fullName = fullName.replace('-', ' '); //Hack! Try to emulate full name returnFont.setFullName(fullName); //emulate afm.getFullName() Set names = new java.util.HashSet(); diff --git a/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java b/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java index f2c86b35f..392eb875e 100644 --- a/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java +++ b/src/java/org/apache/fop/render/AbstractGenericSVGHandler.java @@ -178,7 +178,7 @@ public abstract class AbstractGenericSVGHandler implements XMLHandler, RendererC } /** {@inheritDoc} */ - public String getNameSpace() { + public String getNamespace() { return SVGDOMImplementation.SVG_NAMESPACE_URI; } diff --git a/src/java/org/apache/fop/render/XMLHandler.java b/src/java/org/apache/fop/render/XMLHandler.java index 1060bec51..f8152fcbf 100644 --- a/src/java/org/apache/fop/render/XMLHandler.java +++ b/src/java/org/apache/fop/render/XMLHandler.java @@ -60,6 +60,6 @@ public interface XMLHandler { * @return the XML namespace for the XML dialect this XMLHandler supports, * null if all XML content is handled by this instance. */ - String getNameSpace(); + String getNamespace(); } diff --git a/src/java/org/apache/fop/render/XMLHandlerRegistry.java b/src/java/org/apache/fop/render/XMLHandlerRegistry.java index 84177df45..81d9fcc93 100644 --- a/src/java/org/apache/fop/render/XMLHandlerRegistry.java +++ b/src/java/org/apache/fop/render/XMLHandlerRegistry.java @@ -85,7 +85,7 @@ public class XMLHandlerRegistry { * @param handler the XMLHandler instance */ public void addXMLHandler(XMLHandler handler) { - String ns = handler.getNameSpace(); + String ns = handler.getNamespace(); if (ns == null) { setDefaultXMLHandler(handler); } else { diff --git a/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java b/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java index cffcf8a25..2687d9071 100644 --- a/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java +++ b/src/java/org/apache/fop/render/afp/AFPRendererImageInfo.java @@ -124,7 +124,7 @@ public class AFPRendererImageInfo { * * @return the uri */ - public String getUri() { + public String getURI() { return this.uri; } diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java index dcc0d3523..edeef9766 100644 --- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java +++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java @@ -668,8 +668,8 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler throw new NullPointerException("action must not be null"); } if (!action.isComplete()) { - assert action.hasId(); - incompleteActions.put(action.getId(), action); + assert action.hasID(); + incompleteActions.put(action.getID(), action); } } @@ -744,8 +744,8 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler /** {@inheritDoc} */ public void addResolvedAction(AbstractAction action) throws IFException { assert action.isComplete(); - assert action.hasId(); - AbstractAction noted = (AbstractAction)incompleteActions.remove(action.getId()); + assert action.hasID(); + AbstractAction noted = (AbstractAction)incompleteActions.remove(action.getID()); if (noted != null) { completeActions.add(action); } else { diff --git a/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java b/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java index 8d8a30cf6..340b2e068 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java @@ -33,7 +33,7 @@ public abstract class AbstractAction implements XMLizable { * Sets an ID to make the action referencable. * @param id the ID */ - public void setId(String id) { + public void setID(String id) { this.id = id; } @@ -41,7 +41,7 @@ public abstract class AbstractAction implements XMLizable { * Returns an optional ID for this action. * @return the ID or null */ - public String getId() { + public String getID() { return this.id; } @@ -65,7 +65,7 @@ public abstract class AbstractAction implements XMLizable { * Indicates whether the action has an ID and is therefore referencable. * @return true if the action has an ID */ - public boolean hasId() { + public boolean hasID() { return this.id != null; } @@ -90,7 +90,7 @@ public abstract class AbstractAction implements XMLizable { * Returns a string that is used to prefix a generated ID to make it unique. * @return the prefix string */ - public String getIdPrefix() { + public String getIDPrefix() { return null; } diff --git a/src/java/org/apache/fop/render/intermediate/extensions/ActionSet.java b/src/java/org/apache/fop/render/intermediate/extensions/ActionSet.java index 719d2225b..b980f1051 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/ActionSet.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/ActionSet.java @@ -39,7 +39,7 @@ public class ActionSet { */ public synchronized String generateNewID(AbstractAction action) { this.lastGeneratedID++; - String prefix = action.getIdPrefix(); + String prefix = action.getIDPrefix(); if (prefix == null) { throw new IllegalArgumentException("Action class is not compatible"); } @@ -62,12 +62,12 @@ public class ActionSet { * @return the action instance that should be used in place of the given one */ public AbstractAction put(AbstractAction action) { - if (!action.hasId()) { - action.setId(generateNewID(action)); + if (!action.hasID()) { + action.setID(generateNewID(action)); } AbstractAction effAction = normalize(action); if (effAction == action) { - this.actionRegistry.put(action.getId(), action); + this.actionRegistry.put(action.getID(), action); } return effAction; } diff --git a/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java b/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java index 1d5bc23fe..1e613d7eb 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java @@ -132,7 +132,7 @@ public class DocumentNavigationHandler extends DefaultHandler boolean newWindow = "new".equals(showDestination); URIAction action = new URIAction(gotoURI, newWindow); if (id != null) { - action.setId(id); + action.setID(id); } if (structurePointer != null) { action.setStructurePointer(structurePointer); diff --git a/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java b/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java index d905c7800..a2b4f31b6 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/GoToXYAction.java @@ -52,7 +52,7 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx * or null, if the position isn't known, yet */ public GoToXYAction(String id, int pageIndex, Point targetLocation) { - setId(id); + setID(id); if (pageIndex < 0 && targetLocation != null) { throw new IllegalArgumentException( "Page index may not be null if target location is known!"); @@ -144,7 +144,7 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx AttributesImpl atts = new AttributesImpl(); if (this.isCompleteExceptTargetLocation()) { final Point reportedTargetLocation = this.getTargetLocation(); - atts.addAttribute(null, "id", "id", XMLUtil.CDATA, getId()); + atts.addAttribute(null, "id", "id", XMLUtil.CDATA, getID()); atts.addAttribute(null, "page-index", "page-index", XMLUtil.CDATA, Integer.toString(pageIndex)); atts.addAttribute(null, "x", "x", XMLUtil.CDATA, @@ -152,7 +152,7 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx atts.addAttribute(null, "y", "y", XMLUtil.CDATA, Integer.toString(reportedTargetLocation.y)); } else { - atts.addAttribute(null, "idref", "idref", XMLUtil.CDATA, getId()); + atts.addAttribute(null, "idref", "idref", XMLUtil.CDATA, getID()); } handler.startElement(GOTO_XY.getNamespaceURI(), GOTO_XY.getLocalName(), GOTO_XY.getQName(), atts); @@ -162,7 +162,7 @@ public class GoToXYAction extends AbstractAction implements DocumentNavigationEx /** {@inheritDoc} */ public String toString() { - return "GoToXY: ID=" + getId() + return "GoToXY: ID=" + getID() + ", page=" + getPageIndex() + ", loc=" + getTargetLocation() + ", " + (isComplete() ? "complete" : "INCOMPLETE"); diff --git a/src/java/org/apache/fop/render/intermediate/extensions/URIAction.java b/src/java/org/apache/fop/render/intermediate/extensions/URIAction.java index 4251619ff..22e7a270c 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/URIAction.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/URIAction.java @@ -82,15 +82,15 @@ public class URIAction extends AbstractAction implements DocumentNavigationExten } /** {@inheritDoc} */ - public String getIdPrefix() { + public String getIDPrefix() { return "fop-" + GOTO_URI.getLocalName(); } /** {@inheritDoc} */ public void toSAX(ContentHandler handler) throws SAXException { AttributesImpl atts = new AttributesImpl(); - if (hasId()) { - atts.addAttribute(null, "id", "id", XMLUtil.CDATA, getId()); + if (hasID()) { + atts.addAttribute(null, "id", "id", XMLUtil.CDATA, getID()); } atts.addAttribute(null, "uri", "uri", XMLUtil.CDATA, getURI()); if (isNewWindow()) { diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java index 4a51cb176..c215243a7 100644 --- a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java @@ -129,7 +129,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler /** {@inheritDoc} */ public void addResolvedAction(AbstractAction action) throws IFException { assert action.isComplete(); - PDFAction pdfAction = (PDFAction)this.incompleteActions.remove(action.getId()); + PDFAction pdfAction = (PDFAction)this.incompleteActions.remove(action.getID()); if (pdfAction == null) { getAction(action); } else if (pdfAction instanceof PDFGoTo) { @@ -145,11 +145,11 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler if (action == null) { return null; } - PDFAction pdfAction = (PDFAction)this.completeActions.get(action.getId()); + PDFAction pdfAction = (PDFAction)this.completeActions.get(action.getID()); if (pdfAction != null) { return pdfAction; } else if (action instanceof GoToXYAction) { - pdfAction = (PDFAction) incompleteActions.get(action.getId()); + pdfAction = (PDFAction) incompleteActions.get(action.getID()); if (pdfAction != null) { return pdfAction; } else { @@ -159,7 +159,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler if (action.isComplete()) { updateTargetLocation(pdfGoTo, a); } else { - this.incompleteActions.put(action.getId(), pdfGoTo); + this.incompleteActions.put(action.getID(), pdfGoTo); } return pdfGoTo; } @@ -173,7 +173,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler //Some PDF actions are pooled getPDFDoc().registerObject(pdfAction); } - this.completeActions.put(action.getId(), pdfAction); + this.completeActions.put(action.getID(), pdfAction); return pdfAction; } else { throw new UnsupportedOperationException("Unsupported action type: " @@ -195,7 +195,7 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler //Queue this object now that it's complete getPDFDoc().addObject(pdfGoTo); - this.completeActions.put(action.getId(), pdfGoTo); + this.completeActions.put(action.getID(), pdfGoTo); } } diff --git a/src/java/org/apache/fop/render/ps/PSImageFormResource.java b/src/java/org/apache/fop/render/ps/PSImageFormResource.java index 4c40c6f92..11c3205e6 100644 --- a/src/java/org/apache/fop/render/ps/PSImageFormResource.java +++ b/src/java/org/apache/fop/render/ps/PSImageFormResource.java @@ -53,7 +53,7 @@ public class PSImageFormResource extends PSResource { * Returns the image URI. * @return the image URI */ - public String getImageUri() { + public String getImageURI() { return this.uri; } diff --git a/src/java/org/apache/fop/render/ps/ResourceHandler.java b/src/java/org/apache/fop/render/ps/ResourceHandler.java index 06d6b9034..502242c17 100644 --- a/src/java/org/apache/fop/render/ps/ResourceHandler.java +++ b/src/java/org/apache/fop/render/ps/ResourceHandler.java @@ -281,7 +281,7 @@ public class ResourceHandler implements DSCParserConstants, PSSupportedFlavors { private void generateFormForImage(PSGenerator gen, PSImageFormResource form) throws IOException { - final String uri = form.getImageUri(); + final String uri = form.getImageURI(); ImageManager manager = userAgent.getFactory().getImageManager(); ImageInfo info = null; diff --git a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java index 29bbecded..d377f740d 100644 --- a/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TextAttributesConverter.java @@ -149,7 +149,7 @@ final class TextAttributesConverter { attrFont(fobj.getCommonFont(), attrib); attrFontColor(fobj.getColor(), attrib); attrTextDecoration(fobj.getTextDecoration(), attrib); - attrBaseLineShift(fobj.getBaselineShift(), attrib); + attrBaseLineShift(fobj.getBaseLineShift(), attrib); return attrib; } diff --git a/src/java/org/apache/fop/render/xml/XMLXMLHandler.java b/src/java/org/apache/fop/render/xml/XMLXMLHandler.java index f181e1911..d1cf1cf9a 100644 --- a/src/java/org/apache/fop/render/xml/XMLXMLHandler.java +++ b/src/java/org/apache/fop/render/xml/XMLXMLHandler.java @@ -48,7 +48,7 @@ public class XMLXMLHandler implements XMLHandler { } /** {@inheritDoc} */ - public String getNameSpace() { + public String getNamespace() { return null; //Handle all XML content } diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java index ba03ee567..0c6e09bd0 100644 --- a/src/java/org/apache/fop/tools/TestConverter.java +++ b/src/java/org/apache/fop/tools/TestConverter.java @@ -56,7 +56,7 @@ public class TestConverter { private String outputFormat = MimeConstants.MIME_FOP_AREA_TREE; private File destdir; private File compare = null; - private String basedir = "./"; + private String baseDir = "./"; private Map differ = new java.util.HashMap(); /** @@ -95,7 +95,7 @@ public class TestConverter { } else if (args[count].equals("-d")) { tc.setDebug(true); } else if (args[count].equals("-b")) { - tc.setBasedir(args[++count]); + tc.setBaseDir(args[++count]); } else if (args[count].equals("-results")) { results = args[++count]; } else { @@ -138,8 +138,8 @@ public class TestConverter { * Sets the base directory. * @param str base directory */ - public void setBasedir(String str) { - basedir = str; + public void setBaseDir(String str) { + baseDir = str; } /** @@ -167,11 +167,11 @@ public class TestConverter { logger.debug("running tests in file:" + fname); try { if (compDir != null) { - compare = new File(basedir + "/" + compDir); + compare = new File(baseDir + "/" + compDir); } - destdir = new File(basedir + "/" + dest); + destdir = new File(baseDir + "/" + dest); destdir.mkdirs(); - File f = new File(basedir + "/" + fname); + File f = new File(baseDir + "/" + fname); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder db = factory.newDocumentBuilder(); Document doc = db.parse(f); @@ -271,7 +271,7 @@ public class TestConverter { res = resNode.getNodeValue(); } try { - File xmlFile = new File(basedir + "/" + xml); + File xmlFile = new File(baseDir + "/" + xml); String baseURL = null; try { baseURL = xmlFile.getParentFile().toURI().toURL().toExternalForm(); @@ -284,7 +284,7 @@ public class TestConverter { inputHandler = new InputHandler(xmlFile); } else { inputHandler = new InputHandler(xmlFile, - new File(basedir + "/" + new File(baseDir + "/" + xsl), null); } diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java index 3aeac1215..58dd1fb5b 100644 --- a/src/java/org/apache/fop/tools/anttasks/Fop.java +++ b/src/java/org/apache/fop/tools/anttasks/Fop.java @@ -85,7 +85,7 @@ public class Fop extends Task { * Sets the filename for the userconfig.xml. * @param userConfig Configuration to use */ - public void setUserConfig(File userConfig) { + public void setUserconfig(File userConfig) { this.userConfig = userConfig; } @@ -93,7 +93,7 @@ public class Fop extends Task { * Returns the file for the userconfig.xml. * @return the userconfig.xml file */ - public File getUserConfig() { + public File getUserconfig() { return this.userConfig; } @@ -101,7 +101,7 @@ public class Fop extends Task { * Sets the input XSL-FO file. * @param foFile input XSL-FO file */ - public void setFoFile(File foFile) { + public void setFofile(File foFile) { this.foFile = foFile; } @@ -109,7 +109,7 @@ public class Fop extends Task { * Gets the input XSL-FO file. * @return input XSL-FO file */ - public File getFoFile() { + public File getFofile() { return foFile; } @@ -267,7 +267,7 @@ public class Fop extends Task { * default is false. * @param throwExceptions true if exceptions should be thrown */ - public void setThrowExceptions(boolean throwExceptions) { + public void setThrowexceptions(boolean throwExceptions) { this.throwExceptions = throwExceptions; } @@ -275,7 +275,7 @@ public class Fop extends Task { * Gets the throw exceptions attribute * @return the throw exceptions attribute */ - public boolean getThrowExceptions() { + public boolean getThrowexceptions() { return this.throwExceptions; } @@ -408,8 +408,8 @@ class FOPTaskStarter { FOPTaskStarter(Fop task) throws SAXException, IOException { this.task = task; - if (task.getUserConfig() != null) { - fopFactory.setUserConfig(task.getUserConfig()); + if (task.getUserconfig() != null) { + fopFactory.setUserConfig(task.getUserconfig()); } } @@ -497,8 +497,8 @@ class FOPTaskStarter { } } else { try { - if (task.getFoFile() != null) { - this.baseURL = task.getFoFile().getParentFile().toURI().toURL(). + if (task.getFofile() != null) { + this.baseURL = task.getFofile().getParentFile().toURI().toURL(). toExternalForm(); } } catch (MalformedURLException mfue) { @@ -517,8 +517,8 @@ class FOPTaskStarter { int skippedcount = 0; // deal with single source file - if (task.getFoFile() != null) { - if (task.getFoFile().exists()) { + if (task.getFofile() != null) { + if (task.getFofile().exists()) { File outf = task.getOutfile(); if (outf == null) { throw new BuildException("outfile is required when fofile is used"); @@ -530,11 +530,11 @@ class FOPTaskStarter { // OR output file doesn't exist OR // output file is older than input file if (task.getForce() || !outf.exists() - || (task.getFoFile().lastModified() > outf.lastModified() )) { - render(task.getFoFile(), outf, outputFormat); + || (task.getFofile().lastModified() > outf.lastModified() )) { + render(task.getFofile(), outf, outputFormat); actioncount++; } else if (outf.exists() - && (task.getFoFile().lastModified() <= outf.lastModified() )) { + && (task.getFofile().lastModified() <= outf.lastModified() )) { skippedcount++; } } @@ -653,7 +653,7 @@ class FOPTaskStarter { inputHandler.renderTo(userAgent, outputFormat, out); success = true; } catch (Exception ex) { - if (task.getThrowExceptions()) { + if (task.getThrowexceptions()) { throw new BuildException(ex); } throw ex; diff --git a/src/sandbox/org/apache/fop/render/svg/SVGSVGHandler.java b/src/sandbox/org/apache/fop/render/svg/SVGSVGHandler.java index ea73da0a1..c46c35b99 100644 --- a/src/sandbox/org/apache/fop/render/svg/SVGSVGHandler.java +++ b/src/sandbox/org/apache/fop/render/svg/SVGSVGHandler.java @@ -38,7 +38,7 @@ public class SVGSVGHandler implements XMLHandler, SVGRendererContextConstants { /** {@inheritDoc} */ public void handleXML(RendererContext context, org.w3c.dom.Document doc, String ns) throws Exception { - if (getNameSpace().equals(ns)) { + if (getNamespace().equals(ns)) { if (!(doc instanceof SVGDocument)) { DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); doc = DOMUtilities.deepCloneDocument(doc, impl); @@ -46,7 +46,7 @@ public class SVGSVGHandler implements XMLHandler, SVGRendererContextConstants { SVGSVGElement svg = ((SVGDocument) doc).getRootElement(); SVGDocument targetDoc = (SVGDocument)context.getProperty(SVG_DOCUMENT); SVGElement currentPageG = (SVGElement)context.getProperty(SVG_PAGE_G); - Element view = targetDoc.createElementNS(getNameSpace(), "svg"); + Element view = targetDoc.createElementNS(getNamespace(), "svg"); Node newsvg = targetDoc.importNode(svg, true); //view.setAttributeNS(null, "viewBox", "0 0 "); int xpos = ((Integer)context.getProperty(XPOS)).intValue(); @@ -57,7 +57,7 @@ public class SVGSVGHandler implements XMLHandler, SVGRendererContextConstants { // this fixes a problem where the xmlns is repeated sometimes Element ele = (Element) newsvg; ele.setAttributeNS(XMLSupport.XMLNS_NAMESPACE_URI, "xmlns", - getNameSpace()); + getNamespace()); if (ele.hasAttributeNS(null, "xmlns")) { ele.removeAttributeNS(null, "xmlns"); } @@ -74,7 +74,7 @@ public class SVGSVGHandler implements XMLHandler, SVGRendererContextConstants { } /** {@inheritDoc} */ - public String getNameSpace() { + public String getNamespace() { return SVGRenderer.MIME_TYPE; } -- cgit v1.2.3 From 160d78ce1c348b96e9807f59f3d20bb2226e75c0 Mon Sep 17 00:00:00 2001 From: Peter Hancock Date: Fri, 27 Jan 2012 15:36:05 +0000 Subject: Associate structure tree elements directly to render content * Defer the binding of PCData to struct elems using a placeholder mechanism. * Translate text nodes to marked-content sequences in IF structure tree. * Replace ptr with structure tree element. * Re-order table footers so they appear at the end of the structure tree. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_ImproveAccessibility@1236718 13f79535-47bb-0310-9956-ffa450edef68 --- build.xml | 1 + .../DummyStructureTreeEventHandler.java | 23 +- .../accessibility/FO2StructureTreeConverter.java | 823 --------------------- .../StructureTree2SAXEventAdapter.java | 35 +- .../fop/accessibility/StructureTreeElement.java | 31 + .../accessibility/StructureTreeEventHandler.java | 31 +- .../fo/FO2StructureTreeConverter.java | 491 ++++++++++++ .../fop/accessibility/fo/FOEventRecorder.java | 508 +++++++++++++ .../fo/StructureTreeEventTrigger.java | 408 ++++++++++ src/java/org/apache/fop/area/AreaTreeParser.java | 11 - src/java/org/apache/fop/area/Trait.java | 6 +- .../apache/fop/fo/DelegatingFOEventHandler.java | 4 +- src/java/org/apache/fop/fo/FOEventHandler.java | 10 +- src/java/org/apache/fop/fo/FONode.java | 3 +- src/java/org/apache/fop/fo/FOText.java | 33 +- src/java/org/apache/fop/fo/FOTreeBuilder.java | 2 +- .../fop/fo/extensions/InternalElementMapping.java | 9 +- .../org/apache/fop/fo/flow/AbstractGraphics.java | 15 +- .../fop/fo/flow/AbstractPageNumberCitation.java | 15 +- src/java/org/apache/fop/fo/flow/BasicLink.java | 15 +- src/java/org/apache/fop/fo/flow/Block.java | 14 +- src/java/org/apache/fop/fo/flow/Character.java | 15 +- src/java/org/apache/fop/fo/flow/Inline.java | 14 +- src/java/org/apache/fop/fo/flow/PageNumber.java | 15 +- .../org/apache/fop/fo/flow/table/TableFObj.java | 14 +- .../fo/properties/StructurePointerPropertySet.java | 34 - .../fo/properties/StructureTreeElementHolder.java | 38 + .../apache/fop/layoutmgr/BlockLayoutManager.java | 1 - src/java/org/apache/fop/layoutmgr/TraitSetter.java | 14 +- .../inline/AbstractGraphicsLayoutManager.java | 2 +- .../AbstractPageNumberCitationLayoutManager.java | 2 +- .../layoutmgr/inline/BasicLinkLayoutManager.java | 2 +- .../layoutmgr/inline/CharacterLayoutManager.java | 2 +- .../layoutmgr/inline/PageNumberLayoutManager.java | 8 +- .../fop/layoutmgr/inline/TextLayoutManager.java | 18 +- src/java/org/apache/fop/pdf/PDFStructElem.java | 102 ++- .../apache/fop/render/intermediate/IFContext.java | 33 +- .../apache/fop/render/intermediate/IFParser.java | 56 +- .../apache/fop/render/intermediate/IFRenderer.java | 21 +- .../fop/render/intermediate/IFSerializer.java | 29 +- .../intermediate/IFStructureTreeBuilder.java | 118 ++- .../intermediate/extensions/AbstractAction.java | 14 +- .../extensions/DocumentNavigationHandler.java | 24 +- .../render/pdf/PDFDocumentNavigationHandler.java | 8 +- .../fop/render/pdf/PDFLogicalStructureHandler.java | 84 +-- src/java/org/apache/fop/render/pdf/PDFPainter.java | 21 +- .../fop/render/pdf/PDFStructureTreeBuilder.java | 71 +- src/java/org/apache/fop/render/rtf/RTFHandler.java | 12 +- test/accessibility/background-image_jpg_repeat.fo | 4 +- test/accessibility/background-image_jpg_single.fo | 4 +- test/accessibility/background-image_png_repeat.fo | 4 +- test/accessibility/background-image_png_single.fo | 4 +- test/accessibility/background-image_svg_repeat.fo | 4 +- test/accessibility/background-image_svg_single.fo | 4 +- test/accessibility/complete.fo | 6 +- test/accessibility/image_jpg.fo | 4 +- test/accessibility/image_png.fo | 4 +- test/accessibility/image_svg.fo | 4 +- test/accessibility/image_wmf.fo | 4 +- test/accessibility/leader.fo | 4 +- test/accessibility/links.fo | 4 +- .../pdf/background-image_jpg_repeat.pdf | Bin 12814 -> 12806 bytes .../pdf/background-image_jpg_single.pdf | Bin 12653 -> 12645 bytes .../pdf/background-image_png_repeat.pdf | Bin 35437 -> 35429 bytes .../pdf/background-image_png_single.pdf | Bin 58317 -> 58309 bytes .../pdf/background-image_svg_repeat.pdf | Bin 17104 -> 17096 bytes .../pdf/background-image_svg_single.pdf | Bin 9943 -> 9935 bytes test/accessibility/pdf/complete.pdf | Bin 96730 -> 96722 bytes test/accessibility/pdf/image_jpg.pdf | Bin 9078 -> 9070 bytes test/accessibility/pdf/image_png.pdf | Bin 57788 -> 57780 bytes test/accessibility/pdf/image_svg.pdf | Bin 14292 -> 14284 bytes test/accessibility/pdf/image_wmf.pdf | Bin 208454 -> 304960 bytes test/accessibility/pdf/leader.pdf | Bin 9379 -> 9371 bytes test/accessibility/pdf/links.pdf | Bin 9712 -> 9704 bytes test/accessibility/pdf/role.pdf | Bin 18976 -> 18968 bytes test/accessibility/pdf/role_non-standard.pdf | Bin 18990 -> 18982 bytes test/accessibility/pdf/text_1.pdf | Bin 7504 -> 7496 bytes test/accessibility/pdf/text_2.pdf | Bin 10346 -> 10338 bytes test/accessibility/pdf/text_font-embedding.pdf | Bin 19785 -> 19777 bytes test/accessibility/role.fo | 4 +- test/accessibility/role_non-standard.fo | 4 +- test/accessibility/text_1.fo | 4 +- test/accessibility/text_2.fo | 4 +- test/accessibility/text_font-embedding.fo | 4 +- .../FO2StructureTreeConverterTestCase.java | 202 ----- .../apache/fop/accessibility/fo/DOMResultUtil.java | 54 ++ .../fo/FO2StructureTreeConverterTestCase.java | 223 ++++++ .../fop/accessibility/fo/fo2StructureTree.xsl | 135 ++++ .../apache/fop/accessibility/fo/table-footers.fo | 195 +++++ .../fo/wrapCompleteDocumentInTableFooter.xsl | 66 ++ .../apache/fop/accessibility/fo2StructureTree.xsl | 116 --- .../IFStructureTreeBuilderTestCase.java | 2 +- 92 files changed, 2725 insertions(+), 1602 deletions(-) delete mode 100644 src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java create mode 100644 src/java/org/apache/fop/accessibility/StructureTreeElement.java create mode 100644 src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java create mode 100644 src/java/org/apache/fop/accessibility/fo/FOEventRecorder.java create mode 100644 src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java delete mode 100644 src/java/org/apache/fop/fo/properties/StructurePointerPropertySet.java create mode 100644 src/java/org/apache/fop/fo/properties/StructureTreeElementHolder.java delete mode 100644 test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java create mode 100644 test/java/org/apache/fop/accessibility/fo/DOMResultUtil.java create mode 100644 test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java create mode 100644 test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl create mode 100644 test/java/org/apache/fop/accessibility/fo/table-footers.fo create mode 100644 test/java/org/apache/fop/accessibility/fo/wrapCompleteDocumentInTableFooter.xsl delete mode 100644 test/java/org/apache/fop/accessibility/fo2StructureTree.xsl (limited to 'src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java') diff --git a/build.xml b/build.xml index dda6493ae..8bc66cd95 100644 --- a/build.xml +++ b/build.xml @@ -581,6 +581,7 @@ list of possible build targets. + diff --git a/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java b/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java index 80a011bab..07daf2f73 100644 --- a/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java +++ b/src/java/org/apache/fop/accessibility/DummyStructureTreeEventHandler.java @@ -33,20 +33,31 @@ public final class DummyStructureTreeEventHandler implements StructureTreeEventH private DummyStructureTreeEventHandler() { } - /** {@inheritDoc} */ public void startPageSequence(Locale locale) { } - /** {@inheritDoc} */ - public void startNode(String name, Attributes attributes) { + public void endPageSequence() { + } + + public StructureTreeElement startNode(String name, Attributes attributes) { + return null; } - /** {@inheritDoc} */ public void endNode(String name) { } - /** {@inheritDoc} */ - public void endPageSequence() { + public StructureTreeElement startImageNode(String name, Attributes attributes) { + return null; + } + + public void endImageNode(String name) { + } + + public StructureTreeElement startReferencedNode(String name, Attributes attributes) { + return null; + } + + public void endReferencedNode(String name) { } } diff --git a/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java b/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java deleted file mode 100644 index e6d0193b9..000000000 --- a/src/java/org/apache/fop/accessibility/FO2StructureTreeConverter.java +++ /dev/null @@ -1,823 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.accessibility; - -import java.util.Locale; - -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; - -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.fo.DelegatingFOEventHandler; -import org.apache.fop.fo.FOEventHandler; -import org.apache.fop.fo.FONode; -import org.apache.fop.fo.extensions.ExtensionElementMapping; -import org.apache.fop.fo.extensions.ExternalDocument; -import org.apache.fop.fo.extensions.InternalElementMapping; -import org.apache.fop.fo.flow.AbstractGraphics; -import org.apache.fop.fo.flow.BasicLink; -import org.apache.fop.fo.flow.Block; -import org.apache.fop.fo.flow.BlockContainer; -import org.apache.fop.fo.flow.Character; -import org.apache.fop.fo.flow.ExternalGraphic; -import org.apache.fop.fo.flow.Footnote; -import org.apache.fop.fo.flow.FootnoteBody; -import org.apache.fop.fo.flow.Inline; -import org.apache.fop.fo.flow.InstreamForeignObject; -import org.apache.fop.fo.flow.Leader; -import org.apache.fop.fo.flow.ListBlock; -import org.apache.fop.fo.flow.ListItem; -import org.apache.fop.fo.flow.ListItemBody; -import org.apache.fop.fo.flow.ListItemLabel; -import org.apache.fop.fo.flow.PageNumber; -import org.apache.fop.fo.flow.PageNumberCitation; -import org.apache.fop.fo.flow.PageNumberCitationLast; -import org.apache.fop.fo.flow.Wrapper; -import org.apache.fop.fo.flow.table.Table; -import org.apache.fop.fo.flow.table.TableBody; -import org.apache.fop.fo.flow.table.TableCell; -import org.apache.fop.fo.flow.table.TableColumn; -import org.apache.fop.fo.flow.table.TableFooter; -import org.apache.fop.fo.flow.table.TableHeader; -import org.apache.fop.fo.flow.table.TableRow; -import org.apache.fop.fo.pagination.Flow; -import org.apache.fop.fo.pagination.PageSequence; -import org.apache.fop.fo.pagination.Root; -import org.apache.fop.fo.pagination.StaticContent; -import org.apache.fop.fo.properties.CommonAccessibilityHolder; -import org.apache.fop.util.XMLUtil; - -/** - * Allows to create the structure tree of an FO document, by converting FO - * events into appropriate structure tree events. - */ -public class FO2StructureTreeConverter extends DelegatingFOEventHandler { - - private int idCounter; - - /** Delegates to either {@link #foToStructureTreeEventAdapter} or {@link #eventSwallower}. */ - private FOEventHandler converter; - - private final FOEventHandler foToStructureTreeEventAdapter; - - /** The descendants of some elements like fo:leader must be ignored. */ - private final FOEventHandler eventSwallower; - - private final StructureTreeEventHandler structureTreeEventHandler; - - private final class FOToStructureTreeEventAdapter extends FOEventHandler { - - public FOToStructureTreeEventAdapter(FOUserAgent foUserAgent) { - super(foUserAgent); - } - - @Override - public void startDocument() throws SAXException { - } - - @Override - public void endDocument() throws SAXException { - } - - @Override - public void startPageSequence(PageSequence pageSeq) { - Locale locale = null; - if (pageSeq.getLanguage() != null) { - if (pageSeq.getCountry() != null) { - locale = new Locale(pageSeq.getLanguage(), pageSeq.getCountry()); - } else { - locale = new Locale(pageSeq.getLanguage()); - } - } - structureTreeEventHandler.startPageSequence(locale); - } - - @Override - public void endPageSequence(PageSequence pageSeq) { - structureTreeEventHandler.endPageSequence(); - } - - @Override - public void startPageNumber(PageNumber pagenum) { - startElementWithID(pagenum); - } - - @Override - public void endPageNumber(PageNumber pagenum) { - endElement(pagenum); - } - - @Override - public void startPageNumberCitation(PageNumberCitation pageCite) { - startElementWithID(pageCite); - } - - @Override - public void endPageNumberCitation(PageNumberCitation pageCite) { - endElement(pageCite); - } - - @Override - public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { - startElementWithID(pageLast); - } - - @Override - public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { - endElement(pageLast); - } - - @Override - public void startFlow(Flow fl) { - startElement(fl); - } - - @Override - public void endFlow(Flow fl) { - endElement(fl); - } - - @Override - public void startBlock(Block bl) { - startElementWithID(bl); - } - - @Override - public void endBlock(Block bl) { - endElement(bl); - } - - @Override - public void startBlockContainer(BlockContainer blc) { - startElement(blc); - } - - @Override - public void endBlockContainer(BlockContainer blc) { - endElement(blc); - } - - @Override - public void startInline(Inline inl) { - startElementWithID(inl); - } - - @Override - public void endInline(Inline inl) { - endElement(inl); - } - - @Override - public void startTable(Table tbl) { - startElementWithID(tbl); - } - - @Override - public void endTable(Table tbl) { - endElement(tbl); - } - - @Override - public void startHeader(TableHeader header) { - startElementWithID(header); - } - - @Override - public void endHeader(TableHeader header) { - endElement(header); - } - - @Override - public void startFooter(TableFooter footer) { - startElementWithID(footer); - } - - @Override - public void endFooter(TableFooter footer) { - endElement(footer); - } - - @Override - public void startBody(TableBody body) { - startElementWithID(body); - } - - @Override - public void endBody(TableBody body) { - endElement(body); - } - - @Override - public void startRow(TableRow tr) { - startElementWithID(tr); - } - - @Override - public void endRow(TableRow tr) { - endElement(tr); - } - - @Override - public void startCell(TableCell tc) { - AttributesImpl attributes = new AttributesImpl(); - int colSpan = tc.getNumberColumnsSpanned(); - if (colSpan > 1) { - addNoNamespaceAttribute(attributes, "number-columns-spanned", - Integer.toString(colSpan)); - } - startElementWithID(tc, attributes); - } - - @Override - public void endCell(TableCell tc) { - endElement(tc); - } - - @Override - public void startList(ListBlock lb) { - startElement(lb); - } - - @Override - public void endList(ListBlock lb) { - endElement(lb); - } - - @Override - public void startListItem(ListItem li) { - startElement(li); - } - - @Override - public void endListItem(ListItem li) { - endElement(li); - } - - @Override - public void startListLabel(ListItemLabel listItemLabel) { - startElement(listItemLabel); - } - - @Override - public void endListLabel(ListItemLabel listItemLabel) { - endElement(listItemLabel); - } - - @Override - public void startListBody(ListItemBody listItemBody) { - startElement(listItemBody); - } - - @Override - public void endListBody(ListItemBody listItemBody) { - endElement(listItemBody); - } - - @Override - public void startStatic(StaticContent staticContent) { - startElement(staticContent); - } - - @Override - public void endStatic(StaticContent statisContent) { - endElement(statisContent); - } - - @Override - public void startLink(BasicLink basicLink) { - startElementWithID(basicLink); - } - - @Override - public void endLink(BasicLink basicLink) { - endElement(basicLink); - } - - @Override - public void image(ExternalGraphic eg) { - startElementWithIDAndAltText(eg); - endElement(eg); - } - - @Override - public void startInstreamForeignObject(InstreamForeignObject ifo) { - startElementWithIDAndAltText(ifo); - } - - @Override - public void endInstreamForeignObject(InstreamForeignObject ifo) { - endElement(ifo); - } - - @Override - public void startFootnote(Footnote footnote) { - startElement(footnote); - } - - @Override - public void endFootnote(Footnote footnote) { - endElement(footnote); - } - - @Override - public void startFootnoteBody(FootnoteBody body) { - startElement(body); - } - - @Override - public void endFootnoteBody(FootnoteBody body) { - endElement(body); - } - - @Override - public void startWrapper(Wrapper wrapper) { - startElement(wrapper); - } - - @Override - public void endWrapper(Wrapper wrapper) { - endElement(wrapper); - } - - @Override - public void character(Character c) { - startElementWithID(c); - endElement(c); - } - - - private void startElement(FONode node) { - startElement(node, new AttributesImpl()); - } - - private void startElementWithID(FONode node) { - startElementWithID(node, new AttributesImpl()); - } - - private void startElementWithIDAndAltText(AbstractGraphics node) { - AttributesImpl attributes = new AttributesImpl(); - addAttribute(attributes, ExtensionElementMapping.URI, "alt-text", - ExtensionElementMapping.STANDARD_PREFIX, node.getAltText()); - startElementWithID(node, attributes); - } - - private void startElementWithID(FONode node, AttributesImpl attributes) { - String id = Integer.toHexString(idCounter++); - node.setPtr(id); - addAttribute(attributes, - InternalElementMapping.URI, "ptr", InternalElementMapping.STANDARD_PREFIX, id); - startElement(node, attributes); - } - - private void startElement(FONode node, AttributesImpl attributes) { - String localName = node.getLocalName(); - if (node instanceof CommonAccessibilityHolder) { - addRole((CommonAccessibilityHolder) node, attributes); - } - structureTreeEventHandler.startNode(localName, attributes); - } - - private void addNoNamespaceAttribute(AttributesImpl attributes, String name, String value) { - attributes.addAttribute("", name, name, XMLUtil.CDATA, value); - } - - private void addAttribute(AttributesImpl attributes, - String namespace, String localName, String prefix, String value) { - assert namespace.length() > 0 && prefix.length() > 0; - String qualifiedName = prefix + ":" + localName; - attributes.addAttribute(namespace, localName, qualifiedName, XMLUtil.CDATA, value); - } - - private void addRole(CommonAccessibilityHolder node, AttributesImpl attributes) { - String role = node.getCommonAccessibility().getRole(); - if (role != null) { - addNoNamespaceAttribute(attributes, "role", role); - } - } - - private void endElement(FONode node) { - String localName = node.getLocalName(); - structureTreeEventHandler.endNode(localName); - } - - } - - /** - * Creates a new instance. - * - * @param structureTreeEventHandler the object that will hold the structure tree - * @param delegate the FO event handler that must be wrapped by this instance - */ - public FO2StructureTreeConverter(StructureTreeEventHandler structureTreeEventHandler, - FOEventHandler delegate) { - super(delegate); - this.structureTreeEventHandler = structureTreeEventHandler; - this.foToStructureTreeEventAdapter = new FOToStructureTreeEventAdapter(foUserAgent); - this.converter = foToStructureTreeEventAdapter; - this.eventSwallower = new FOEventHandler(foUserAgent) { }; - } - - @Override - public void startDocument() throws SAXException { - converter.startDocument(); - super.startDocument(); - } - - @Override - public void endDocument() throws SAXException { - converter.endDocument(); - super.endDocument(); - } - - @Override - public void startRoot(Root root) { - converter.startRoot(root); - super.startRoot(root); - } - - @Override - public void endRoot(Root root) { - converter.endRoot(root); - super.endRoot(root); - } - - @Override - public void startPageSequence(PageSequence pageSeq) { - converter.startPageSequence(pageSeq); - super.startPageSequence(pageSeq); - } - - @Override - public void endPageSequence(PageSequence pageSeq) { - converter.endPageSequence(pageSeq); - super.endPageSequence(pageSeq); - } - - @Override - public void startPageNumber(PageNumber pagenum) { - converter.startPageNumber(pagenum); - super.startPageNumber(pagenum); - } - - @Override - public void endPageNumber(PageNumber pagenum) { - converter.endPageNumber(pagenum); - super.endPageNumber(pagenum); - } - - @Override - public void startPageNumberCitation(PageNumberCitation pageCite) { - converter.startPageNumberCitation(pageCite); - super.startPageNumberCitation(pageCite); - } - - @Override - public void endPageNumberCitation(PageNumberCitation pageCite) { - converter.endPageNumberCitation(pageCite); - super.endPageNumberCitation(pageCite); - } - - @Override - public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { - converter.startPageNumberCitationLast(pageLast); - super.startPageNumberCitationLast(pageLast); - } - - @Override - public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { - converter.endPageNumberCitationLast(pageLast); - super.endPageNumberCitationLast(pageLast); - } - - @Override - public void startFlow(Flow fl) { - converter.startFlow(fl); - super.startFlow(fl); - } - - @Override - public void endFlow(Flow fl) { - converter.endFlow(fl); - super.endFlow(fl); - } - - @Override - public void startBlock(Block bl) { - converter.startBlock(bl); - super.startBlock(bl); - } - - @Override - public void endBlock(Block bl) { - converter.endBlock(bl); - super.endBlock(bl); - } - - @Override - public void startBlockContainer(BlockContainer blc) { - converter.startBlockContainer(blc); - super.startBlockContainer(blc); - } - - @Override - public void endBlockContainer(BlockContainer blc) { - converter.endBlockContainer(blc); - super.endBlockContainer(blc); - } - - @Override - public void startInline(Inline inl) { - converter.startInline(inl); - super.startInline(inl); - } - - @Override - public void endInline(Inline inl) { - converter.endInline(inl); - super.endInline(inl); - } - - @Override - public void startTable(Table tbl) { - converter.startTable(tbl); - super.startTable(tbl); - } - - @Override - public void endTable(Table tbl) { - converter.endTable(tbl); - super.endTable(tbl); - } - - @Override - public void startColumn(TableColumn tc) { - converter.startColumn(tc); - super.startColumn(tc); - } - - @Override - public void endColumn(TableColumn tc) { - converter.endColumn(tc); - super.endColumn(tc); - } - - @Override - public void startHeader(TableHeader header) { - converter.startHeader(header); - super.startHeader(header); - } - - @Override - public void endHeader(TableHeader header) { - converter.endHeader(header); - super.endHeader(header); - } - - @Override - public void startFooter(TableFooter footer) { - converter.startFooter(footer); - super.startFooter(footer); - } - - @Override - public void endFooter(TableFooter footer) { - converter.endFooter(footer); - super.endFooter(footer); - } - - @Override - public void startBody(TableBody body) { - converter.startBody(body); - super.startBody(body); - } - - @Override - public void endBody(TableBody body) { - converter.endBody(body); - super.endBody(body); - } - - @Override - public void startRow(TableRow tr) { - converter.startRow(tr); - super.startRow(tr); - } - - @Override - public void endRow(TableRow tr) { - converter.endRow(tr); - super.endRow(tr); - } - - @Override - public void startCell(TableCell tc) { - converter.startCell(tc); - super.startCell(tc); - } - - @Override - public void endCell(TableCell tc) { - converter.endCell(tc); - super.endCell(tc); - } - - @Override - public void startList(ListBlock lb) { - converter.startList(lb); - super.startList(lb); - } - - @Override - public void endList(ListBlock lb) { - converter.endList(lb); - super.endList(lb); - } - - @Override - public void startListItem(ListItem li) { - converter.startListItem(li); - super.startListItem(li); - } - - @Override - public void endListItem(ListItem li) { - converter.endListItem(li); - super.endListItem(li); - } - - @Override - public void startListLabel(ListItemLabel listItemLabel) { - converter.startListLabel(listItemLabel); - super.startListLabel(listItemLabel); - } - - @Override - public void endListLabel(ListItemLabel listItemLabel) { - converter.endListLabel(listItemLabel); - super.endListLabel(listItemLabel); - } - - @Override - public void startListBody(ListItemBody listItemBody) { - converter.startListBody(listItemBody); - super.startListBody(listItemBody); - } - - @Override - public void endListBody(ListItemBody listItemBody) { - converter.endListBody(listItemBody); - super.endListBody(listItemBody); - } - - @Override - public void startStatic(StaticContent staticContent) { - converter.startStatic(staticContent); - super.startStatic(staticContent); - } - - @Override - public void endStatic(StaticContent statisContent) { - converter.endStatic(statisContent); - super.endStatic(statisContent); - } - - @Override - public void startMarkup() { - converter.startMarkup(); - super.startMarkup(); - } - - @Override - public void endMarkup() { - converter.endMarkup(); - super.endMarkup(); - } - - @Override - public void startLink(BasicLink basicLink) { - converter.startLink(basicLink); - super.startLink(basicLink); - } - - @Override - public void endLink(BasicLink basicLink) { - converter.endLink(basicLink); - super.endLink(basicLink); - } - - @Override - public void image(ExternalGraphic eg) { - converter.image(eg); - super.image(eg); - } - - @Override - public void pageRef() { - converter.pageRef(); - super.pageRef(); - } - - @Override - public void startInstreamForeignObject(InstreamForeignObject ifo) { - converter.startInstreamForeignObject(ifo); - super.startInstreamForeignObject(ifo); - } - - @Override - public void endInstreamForeignObject(InstreamForeignObject ifo) { - converter.endInstreamForeignObject(ifo); - super.endInstreamForeignObject(ifo); - } - - @Override - public void startFootnote(Footnote footnote) { - converter.startFootnote(footnote); - super.startFootnote(footnote); - } - - @Override - public void endFootnote(Footnote footnote) { - converter.endFootnote(footnote); - super.endFootnote(footnote); - } - - @Override - public void startFootnoteBody(FootnoteBody body) { - converter.startFootnoteBody(body); - super.startFootnoteBody(body); - } - - @Override - public void endFootnoteBody(FootnoteBody body) { - converter.endFootnoteBody(body); - super.endFootnoteBody(body); - } - - @Override - public void startLeader(Leader l) { - converter = eventSwallower; - converter.startLeader(l); - super.startLeader(l); - } - - @Override - public void endLeader(Leader l) { - converter.endLeader(l); - converter = foToStructureTreeEventAdapter; - super.endLeader(l); - } - - @Override - public void startWrapper(Wrapper wrapper) { - converter.startWrapper(wrapper); - super.startWrapper(wrapper); - } - - @Override - public void endWrapper(Wrapper wrapper) { - converter.endWrapper(wrapper); - super.endWrapper(wrapper); - } - - @Override - public void character(Character c) { - converter.character(c); - super.character(c); - } - - @Override - public void characters(char[] data, int start, int length) { - converter.characters(data, start, length); - super.characters(data, start, length); - } - - @Override - public void startExternalDocument(ExternalDocument document) { - converter.startExternalDocument(document); - super.startExternalDocument(document); - } - - @Override - public void endExternalDocument(ExternalDocument document) { - converter.endExternalDocument(document); - super.endExternalDocument(document); - } - -} diff --git a/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java b/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java index 240c384d6..2cd92a5ce 100644 --- a/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java +++ b/src/java/org/apache/fop/accessibility/StructureTree2SAXEventAdapter.java @@ -50,7 +50,6 @@ public final class StructureTree2SAXEventAdapter implements StructureTreeEventHa return new StructureTree2SAXEventAdapter(contentHandler); } - /** {@inheritDoc} */ public void startPageSequence(Locale locale) { try { @@ -66,7 +65,6 @@ public final class StructureTree2SAXEventAdapter implements StructureTreeEventHa } } - /** {@inheritDoc} */ public void endPageSequence() { try { contentHandler.endElement(IFConstants.NAMESPACE, IFConstants.EL_STRUCTURE_TREE, @@ -81,18 +79,23 @@ public final class StructureTree2SAXEventAdapter implements StructureTreeEventHa } } - /** {@inheritDoc} */ - public void startNode(String name, Attributes attributes) { + public StructureTreeElement startNode(String name, Attributes attributes) { try { - contentHandler.startElement(FOElementMapping.URI, name, - FOElementMapping.STANDARD_PREFIX + ":" + name, - attributes); + if (name.equals("#PCDATA")) { + name = "marked-content"; + contentHandler.startElement(IFConstants.NAMESPACE, name, + name, attributes); + } else { + contentHandler.startElement(FOElementMapping.URI, name, + FOElementMapping.STANDARD_PREFIX + ":" + name, + attributes); + } + return null; } catch (SAXException e) { throw new RuntimeException(e); } } - /** {@inheritDoc} */ public void endNode(String name) { try { contentHandler.endElement(FOElementMapping.URI, name, @@ -101,4 +104,20 @@ public final class StructureTree2SAXEventAdapter implements StructureTreeEventHa throw new RuntimeException(e); } } + + public StructureTreeElement startImageNode(String name, Attributes attributes) { + return startNode(name, attributes); + } + + public void endImageNode(String name) { + endNode(name); + } + + public StructureTreeElement startReferencedNode(String name, Attributes attributes) { + return startNode(name, attributes); + } + + public void endReferencedNode(String name) { + endNode(name); + } } diff --git a/src/java/org/apache/fop/accessibility/StructureTreeElement.java b/src/java/org/apache/fop/accessibility/StructureTreeElement.java new file mode 100644 index 000000000..3a691c42c --- /dev/null +++ b/src/java/org/apache/fop/accessibility/StructureTreeElement.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +/** + * + */ +package org.apache.fop.accessibility; + +/** + * An object that represents the structure of the document in the output format. + * In PDF, an implementation of this interface will typically result into the + * creation of a structure element dictionary (a dictionary of type StructElem). + */ +public interface StructureTreeElement { +} diff --git a/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java b/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java index d84d07870..4b94d61f1 100644 --- a/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java +++ b/src/java/org/apache/fop/accessibility/StructureTreeEventHandler.java @@ -32,23 +32,46 @@ public interface StructureTreeEventHandler { /** * Starts a page sequence structure tree node. + * * @param locale The locale of the page sequence */ void startPageSequence(Locale locale); /** * Starts a structure tree node. - * @param name The name of the structure tree node - * @param attributes Map of node properties + * + * @param name the name of the structure tree node + * @param attributes the node properties + * @return the corresponding structure tree element */ - void startNode(String name, Attributes attributes); + StructureTreeElement startNode(String name, Attributes attributes); /** * Ends a structure tree node. - * @param name The name of the structure tree node + * + * @param name the name of the structure tree node */ void endNode(String name); + /** + * Starts an image node. + * + * @param name the name of the structure tree node + * @param attributes the node properties + * @return the corresponding structure tree element + */ + StructureTreeElement startImageNode(String name, Attributes attributes); + + /** + * Starts a node that can be referenced by other nodes. This is usually a + * node that can have Marked Content References as children. + * + * @param name the name of the structure tree node + * @param attributes the node properties + * @return the corresponding structure tree element + */ + StructureTreeElement startReferencedNode(String name, Attributes attributes); + /** * Ends a page sequence structure tree node. */ diff --git a/src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java b/src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java new file mode 100644 index 000000000..47c227e9a --- /dev/null +++ b/src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java @@ -0,0 +1,491 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.accessibility.fo; + +import java.util.Stack; + +import org.xml.sax.SAXException; + +import org.apache.fop.accessibility.StructureTreeEventHandler; +import org.apache.fop.fo.DelegatingFOEventHandler; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.FOText; +import org.apache.fop.fo.extensions.ExternalDocument; +import org.apache.fop.fo.flow.BasicLink; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.BlockContainer; +import org.apache.fop.fo.flow.Character; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.ListItemBody; +import org.apache.fop.fo.flow.ListItemLabel; +import org.apache.fop.fo.flow.PageNumber; +import org.apache.fop.fo.flow.PageNumberCitation; +import org.apache.fop.fo.flow.PageNumberCitationLast; +import org.apache.fop.fo.flow.Wrapper; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TableCell; +import org.apache.fop.fo.flow.table.TableColumn; +import org.apache.fop.fo.flow.table.TableFooter; +import org.apache.fop.fo.flow.table.TableHeader; +import org.apache.fop.fo.flow.table.TableRow; +import org.apache.fop.fo.pagination.Flow; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.Root; +import org.apache.fop.fo.pagination.StaticContent; + +/** + * Allows to create the structure tree of an FO document, by converting FO + * events into appropriate structure tree events. + */ +public class FO2StructureTreeConverter extends DelegatingFOEventHandler { + + /** The top of the {@link converters} stack. */ + private FOEventHandler converter; + + private final Stack converters = new Stack(); + + private final Stack tableFooterRecorders = new Stack(); + + private final FOEventHandler structureTreeEventTrigger; + + /** The descendants of some elements like fo:leader must be ignored. */ + private final FOEventHandler eventSwallower = new FOEventHandler() { + }; + + /** + * Creates a new instance. + * + * @param structureTreeEventHandler the object that will hold the structure tree + * @param delegate the FO event handler that must be wrapped by this instance + */ + public FO2StructureTreeConverter(StructureTreeEventHandler structureTreeEventHandler, + FOEventHandler delegate) { + super(delegate); + this.structureTreeEventTrigger = new StructureTreeEventTrigger(structureTreeEventHandler); + this.converter = structureTreeEventTrigger; + } + + @Override + public void startDocument() throws SAXException { + converter.startDocument(); + super.startDocument(); + } + + @Override + public void endDocument() throws SAXException { + converter.endDocument(); + super.endDocument(); + } + + @Override + public void startRoot(Root root) { + converter.startRoot(root); + super.startRoot(root); + } + + @Override + public void endRoot(Root root) { + converter.endRoot(root); + super.endRoot(root); + } + + @Override + public void startPageSequence(PageSequence pageSeq) { + converter.startPageSequence(pageSeq); + super.startPageSequence(pageSeq); + } + + @Override + public void endPageSequence(PageSequence pageSeq) { + converter.endPageSequence(pageSeq); + super.endPageSequence(pageSeq); + } + + @Override + public void startPageNumber(PageNumber pagenum) { + converter.startPageNumber(pagenum); + super.startPageNumber(pagenum); + } + + @Override + public void endPageNumber(PageNumber pagenum) { + converter.endPageNumber(pagenum); + super.endPageNumber(pagenum); + } + + @Override + public void startPageNumberCitation(PageNumberCitation pageCite) { + converter.startPageNumberCitation(pageCite); + super.startPageNumberCitation(pageCite); + } + + @Override + public void endPageNumberCitation(PageNumberCitation pageCite) { + converter.endPageNumberCitation(pageCite); + super.endPageNumberCitation(pageCite); + } + + @Override + public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { + converter.startPageNumberCitationLast(pageLast); + super.startPageNumberCitationLast(pageLast); + } + + @Override + public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { + converter.endPageNumberCitationLast(pageLast); + super.endPageNumberCitationLast(pageLast); + } + + @Override + public void startFlow(Flow fl) { + converter.startFlow(fl); + super.startFlow(fl); + } + + @Override + public void endFlow(Flow fl) { + converter.endFlow(fl); + super.endFlow(fl); + } + + @Override + public void startBlock(Block bl) { + converter.startBlock(bl); + super.startBlock(bl); + } + + @Override + public void endBlock(Block bl) { + converter.endBlock(bl); + super.endBlock(bl); + } + + @Override + public void startBlockContainer(BlockContainer blc) { + converter.startBlockContainer(blc); + super.startBlockContainer(blc); + } + + @Override + public void endBlockContainer(BlockContainer blc) { + converter.endBlockContainer(blc); + super.endBlockContainer(blc); + } + + @Override + public void startInline(Inline inl) { + converter.startInline(inl); + super.startInline(inl); + } + + @Override + public void endInline(Inline inl) { + converter.endInline(inl); + super.endInline(inl); + } + + @Override + public void startTable(Table tbl) { + converter.startTable(tbl); + tableFooterRecorders.push(null); + super.startTable(tbl); + } + + @Override + public void endTable(Table tbl) { + FOEventRecorder tableFooterRecorder = tableFooterRecorders.pop(); + if (tableFooterRecorder != null) { + tableFooterRecorder.replay(converter); + } + converter.endTable(tbl); + super.endTable(tbl); + } + + @Override + public void startColumn(TableColumn tc) { + converter.startColumn(tc); + super.startColumn(tc); + } + + @Override + public void endColumn(TableColumn tc) { + converter.endColumn(tc); + super.endColumn(tc); + } + + @Override + public void startHeader(TableHeader header) { + converter.startHeader(header); + super.startHeader(header); + } + + @Override + public void endHeader(TableHeader header) { + converter.endHeader(header); + super.endHeader(header); + } + + @Override + public void startFooter(TableFooter footer) { + converters.push(converter); + converter = new FOEventRecorder(); + converter.startFooter(footer); + super.startFooter(footer); + } + + @Override + public void endFooter(TableFooter footer) { + converter.endFooter(footer); + /* Replace the dummy table footer with the real one. */ + tableFooterRecorders.pop(); + tableFooterRecorders.push((FOEventRecorder) converter); + converter = converters.pop(); + super.endFooter(footer); + } + + @Override + public void startBody(TableBody body) { + converter.startBody(body); + super.startBody(body); + } + + @Override + public void endBody(TableBody body) { + converter.endBody(body); + super.endBody(body); + } + + @Override + public void startRow(TableRow tr) { + converter.startRow(tr); + super.startRow(tr); + } + + @Override + public void endRow(TableRow tr) { + converter.endRow(tr); + super.endRow(tr); + } + + @Override + public void startCell(TableCell tc) { + converter.startCell(tc); + super.startCell(tc); + } + + @Override + public void endCell(TableCell tc) { + converter.endCell(tc); + super.endCell(tc); + } + + @Override + public void startList(ListBlock lb) { + converter.startList(lb); + super.startList(lb); + } + + @Override + public void endList(ListBlock lb) { + converter.endList(lb); + super.endList(lb); + } + + @Override + public void startListItem(ListItem li) { + converter.startListItem(li); + super.startListItem(li); + } + + @Override + public void endListItem(ListItem li) { + converter.endListItem(li); + super.endListItem(li); + } + + @Override + public void startListLabel(ListItemLabel listItemLabel) { + converter.startListLabel(listItemLabel); + super.startListLabel(listItemLabel); + } + + @Override + public void endListLabel(ListItemLabel listItemLabel) { + converter.endListLabel(listItemLabel); + super.endListLabel(listItemLabel); + } + + @Override + public void startListBody(ListItemBody listItemBody) { + converter.startListBody(listItemBody); + super.startListBody(listItemBody); + } + + @Override + public void endListBody(ListItemBody listItemBody) { + converter.endListBody(listItemBody); + super.endListBody(listItemBody); + } + + @Override + public void startStatic(StaticContent staticContent) { + converter.startStatic(staticContent); + super.startStatic(staticContent); + } + + @Override + public void endStatic(StaticContent statisContent) { + converter.endStatic(statisContent); + super.endStatic(statisContent); + } + + @Override + public void startMarkup() { + converter.startMarkup(); + super.startMarkup(); + } + + @Override + public void endMarkup() { + converter.endMarkup(); + super.endMarkup(); + } + + @Override + public void startLink(BasicLink basicLink) { + converter.startLink(basicLink); + super.startLink(basicLink); + } + + @Override + public void endLink(BasicLink basicLink) { + converter.endLink(basicLink); + super.endLink(basicLink); + } + + @Override + public void image(ExternalGraphic eg) { + converter.image(eg); + super.image(eg); + } + + @Override + public void pageRef() { + converter.pageRef(); + super.pageRef(); + } + + @Override + public void startInstreamForeignObject(InstreamForeignObject ifo) { + converter.startInstreamForeignObject(ifo); + super.startInstreamForeignObject(ifo); + } + + @Override + public void endInstreamForeignObject(InstreamForeignObject ifo) { + converter.endInstreamForeignObject(ifo); + super.endInstreamForeignObject(ifo); + } + + @Override + public void startFootnote(Footnote footnote) { + converter.startFootnote(footnote); + super.startFootnote(footnote); + } + + @Override + public void endFootnote(Footnote footnote) { + converter.endFootnote(footnote); + super.endFootnote(footnote); + } + + @Override + public void startFootnoteBody(FootnoteBody body) { + converter.startFootnoteBody(body); + super.startFootnoteBody(body); + } + + @Override + public void endFootnoteBody(FootnoteBody body) { + converter.endFootnoteBody(body); + super.endFootnoteBody(body); + } + + @Override + public void startLeader(Leader l) { + converters.push(converter); + converter = eventSwallower; + converter.startLeader(l); + super.startLeader(l); + } + + @Override + public void endLeader(Leader l) { + converter.endLeader(l); + converter = converters.pop(); + super.endLeader(l); + } + + @Override + public void startWrapper(Wrapper wrapper) { + converter.startWrapper(wrapper); + super.startWrapper(wrapper); + } + + @Override + public void endWrapper(Wrapper wrapper) { + converter.endWrapper(wrapper); + super.endWrapper(wrapper); + } + + @Override + public void character(Character c) { + converter.character(c); + super.character(c); + } + + @Override + public void characters(FOText foText) { + converter.characters(foText); + super.characters(foText); + } + + @Override + public void startExternalDocument(ExternalDocument document) { + converter.startExternalDocument(document); + super.startExternalDocument(document); + } + + @Override + public void endExternalDocument(ExternalDocument document) { + converter.endExternalDocument(document); + super.endExternalDocument(document); + } + +} diff --git a/src/java/org/apache/fop/accessibility/fo/FOEventRecorder.java b/src/java/org/apache/fop/accessibility/fo/FOEventRecorder.java new file mode 100644 index 000000000..b2b18046d --- /dev/null +++ b/src/java/org/apache/fop/accessibility/fo/FOEventRecorder.java @@ -0,0 +1,508 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.accessibility.fo; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.FOText; +import org.apache.fop.fo.flow.BasicLink; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.BlockContainer; +import org.apache.fop.fo.flow.Character; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.Leader; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.ListItemBody; +import org.apache.fop.fo.flow.ListItemLabel; +import org.apache.fop.fo.flow.PageNumber; +import org.apache.fop.fo.flow.PageNumberCitation; +import org.apache.fop.fo.flow.PageNumberCitationLast; +import org.apache.fop.fo.flow.Wrapper; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TableCell; +import org.apache.fop.fo.flow.table.TableColumn; +import org.apache.fop.fo.flow.table.TableFooter; +import org.apache.fop.fo.flow.table.TableHeader; +import org.apache.fop.fo.flow.table.TableRow; + +final class FOEventRecorder extends FOEventHandler { + + private interface Event { + void replay(FOEventHandler target); + } + + private final List events = new ArrayList(); + + public void replay(FOEventHandler target) { + for (Event event : events) { + event.replay(target); + } + } + + @Override + public void startPageNumber(final PageNumber pagenum) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startPageNumber(pagenum); + } + }); + } + + @Override + public void endPageNumber(final PageNumber pagenum) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endPageNumber(pagenum); + } + }); + } + + @Override + public void startPageNumberCitation(final PageNumberCitation pageCite) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startPageNumberCitation(pageCite); + } + }); + } + + @Override + public void endPageNumberCitation(final PageNumberCitation pageCite) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endPageNumberCitation(pageCite); + } + }); + } + + @Override + public void startPageNumberCitationLast(final PageNumberCitationLast pageLast) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startPageNumberCitationLast(pageLast); + } + }); + } + + @Override + public void endPageNumberCitationLast(final PageNumberCitationLast pageLast) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endPageNumberCitationLast(pageLast); + } + }); + } + + @Override + public void startBlock(final Block bl) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startBlock(bl); + } + }); + } + + @Override + public void endBlock(final Block bl) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endBlock(bl); + } + }); + } + + @Override + public void startBlockContainer(final BlockContainer blc) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startBlockContainer(blc); + } + }); + } + + @Override + public void endBlockContainer(final BlockContainer blc) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endBlockContainer(blc); + } + }); + } + + @Override + public void startInline(final Inline inl) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startInline(inl); + } + }); + } + + @Override + public void endInline(final Inline inl) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endInline(inl); + } + }); + } + + @Override + public void startTable(final Table tbl) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startTable(tbl); + } + }); + } + + @Override + public void endTable(final Table tbl) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endTable(tbl); + } + }); + } + + @Override + public void startColumn(final TableColumn tc) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startColumn(tc); + } + }); + } + + @Override + public void endColumn(final TableColumn tc) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endColumn(tc); + } + }); + } + + @Override + public void startHeader(final TableHeader header) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startHeader(header); + } + }); + } + + @Override + public void endHeader(final TableHeader header) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endHeader(header); + } + }); + } + + @Override + public void startFooter(final TableFooter footer) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startFooter(footer); + } + }); + } + + @Override + public void endFooter(final TableFooter footer) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endFooter(footer); + } + }); + } + + @Override + public void startBody(final TableBody body) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startBody(body); + } + }); + } + + @Override + public void endBody(final TableBody body) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endBody(body); + } + }); + } + + @Override + public void startRow(final TableRow tr) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startRow(tr); + } + }); + } + + @Override + public void endRow(final TableRow tr) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endRow(tr); + } + }); + } + + @Override + public void startCell(final TableCell tc) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startCell(tc); + } + }); + } + + @Override + public void endCell(final TableCell tc) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endCell(tc); + } + }); + } + + @Override + public void startList(final ListBlock lb) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startList(lb); + } + }); + } + + @Override + public void endList(final ListBlock lb) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endList(lb); + } + }); + } + + @Override + public void startListItem(final ListItem li) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startListItem(li); + } + }); + } + + @Override + public void endListItem(final ListItem li) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endListItem(li); + } + }); + } + + @Override + public void startListLabel(final ListItemLabel listItemLabel) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startListLabel(listItemLabel); + } + }); + } + + @Override + public void endListLabel(final ListItemLabel listItemLabel) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endListLabel(listItemLabel); + } + }); + } + + @Override + public void startListBody(final ListItemBody listItemBody) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startListBody(listItemBody); + } + }); + } + + @Override + public void endListBody(final ListItemBody listItemBody) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endListBody(listItemBody); + } + }); + } + + @Override + public void startLink(final BasicLink basicLink) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startLink(basicLink); + } + }); + } + + @Override + public void endLink(final BasicLink basicLink) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endLink(basicLink); + } + }); + } + + @Override + public void image(final ExternalGraphic eg) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.image(eg); + } + }); + } + + @Override + public void startInstreamForeignObject(final InstreamForeignObject ifo) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startInstreamForeignObject(ifo); + } + }); + } + + @Override + public void endInstreamForeignObject(final InstreamForeignObject ifo) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endInstreamForeignObject(ifo); + } + }); + } + + @Override + public void startFootnote(final Footnote footnote) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startFootnote(footnote); + } + }); + } + + @Override + public void endFootnote(final Footnote footnote) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endFootnote(footnote); + } + }); + } + + @Override + public void startFootnoteBody(final FootnoteBody body) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startFootnoteBody(body); + } + }); + } + + @Override + public void endFootnoteBody(final FootnoteBody body) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endFootnoteBody(body); + } + }); + } + + @Override + public void startLeader(final Leader l) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startLeader(l); + } + }); + } + + @Override + public void endLeader(final Leader l) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endLeader(l); + } + }); + } + + @Override + public void startWrapper(final Wrapper wrapper) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.startWrapper(wrapper); + } + }); + } + + @Override + public void endWrapper(final Wrapper wrapper) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.endWrapper(wrapper); + } + }); + } + + @Override + public void character(final Character c) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.character(c); + } + }); + } + + @Override + public void characters(final FOText foText) { + events.add(new Event() { + public void replay(FOEventHandler target) { + target.characters(foText); + } + }); + } + +} diff --git a/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java b/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java new file mode 100644 index 000000000..b5cd0a5a4 --- /dev/null +++ b/src/java/org/apache/fop/accessibility/fo/StructureTreeEventTrigger.java @@ -0,0 +1,408 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.accessibility.fo; + +import java.util.Locale; + +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import org.apache.fop.accessibility.StructureTreeElement; +import org.apache.fop.accessibility.StructureTreeEventHandler; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.FOText; +import org.apache.fop.fo.extensions.ExtensionElementMapping; +import org.apache.fop.fo.flow.AbstractGraphics; +import org.apache.fop.fo.flow.BasicLink; +import org.apache.fop.fo.flow.Block; +import org.apache.fop.fo.flow.BlockContainer; +import org.apache.fop.fo.flow.Character; +import org.apache.fop.fo.flow.ExternalGraphic; +import org.apache.fop.fo.flow.Footnote; +import org.apache.fop.fo.flow.FootnoteBody; +import org.apache.fop.fo.flow.Inline; +import org.apache.fop.fo.flow.InstreamForeignObject; +import org.apache.fop.fo.flow.ListBlock; +import org.apache.fop.fo.flow.ListItem; +import org.apache.fop.fo.flow.ListItemBody; +import org.apache.fop.fo.flow.ListItemLabel; +import org.apache.fop.fo.flow.PageNumber; +import org.apache.fop.fo.flow.PageNumberCitation; +import org.apache.fop.fo.flow.PageNumberCitationLast; +import org.apache.fop.fo.flow.Wrapper; +import org.apache.fop.fo.flow.table.Table; +import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TableCell; +import org.apache.fop.fo.flow.table.TableFooter; +import org.apache.fop.fo.flow.table.TableHeader; +import org.apache.fop.fo.flow.table.TableRow; +import org.apache.fop.fo.pagination.Flow; +import org.apache.fop.fo.pagination.PageSequence; +import org.apache.fop.fo.pagination.StaticContent; +import org.apache.fop.fo.properties.CommonAccessibilityHolder; +import org.apache.fop.util.XMLUtil; + +/** + * A bridge between {@link FOEventHandler} and {@link StructureTreeEventHandler}. + */ +class StructureTreeEventTrigger extends FOEventHandler { + + private StructureTreeEventHandler structureTreeEventHandler; + + public StructureTreeEventTrigger(StructureTreeEventHandler structureTreeEventHandler) { + this.structureTreeEventHandler = structureTreeEventHandler; + } + + @Override + public void startDocument() throws SAXException { + } + + @Override + public void endDocument() throws SAXException { + } + + @Override + public void startPageSequence(PageSequence pageSeq) { + Locale locale = null; + if (pageSeq.getLanguage() != null) { + if (pageSeq.getCountry() != null) { + locale = new Locale(pageSeq.getLanguage(), pageSeq.getCountry()); + } else { + locale = new Locale(pageSeq.getLanguage()); + } + } + structureTreeEventHandler.startPageSequence(locale); + } + + @Override + public void endPageSequence(PageSequence pageSeq) { + structureTreeEventHandler.endPageSequence(); + } + + @Override + public void startPageNumber(PageNumber pagenum) { + startElementWithID(pagenum); + } + + @Override + public void endPageNumber(PageNumber pagenum) { + endElement(pagenum); + } + + @Override + public void startPageNumberCitation(PageNumberCitation pageCite) { + startElementWithID(pageCite); + } + + @Override + public void endPageNumberCitation(PageNumberCitation pageCite) { + endElement(pageCite); + } + + @Override + public void startPageNumberCitationLast(PageNumberCitationLast pageLast) { + startElementWithID(pageLast); + } + + @Override + public void endPageNumberCitationLast(PageNumberCitationLast pageLast) { + endElement(pageLast); + } + + @Override + public void startFlow(Flow fl) { + startElement(fl); + } + + @Override + public void endFlow(Flow fl) { + endElement(fl); + } + + @Override + public void startBlock(Block bl) { + startElement(bl); + } + + @Override + public void endBlock(Block bl) { + endElement(bl); + } + + @Override + public void startBlockContainer(BlockContainer blc) { + startElement(blc); + } + + @Override + public void endBlockContainer(BlockContainer blc) { + endElement(blc); + } + + @Override + public void startInline(Inline inl) { + startElement(inl); + } + + @Override + public void endInline(Inline inl) { + endElement(inl); + } + + @Override + public void startTable(Table tbl) { + startElement(tbl); + } + + @Override + public void endTable(Table tbl) { + endElement(tbl); + } + + @Override + public void startHeader(TableHeader header) { + startElement(header); + } + + @Override + public void endHeader(TableHeader header) { + endElement(header); + } + + @Override + public void startFooter(TableFooter footer) { + startElement(footer); + } + + @Override + public void endFooter(TableFooter footer) { + endElement(footer); + } + + @Override + public void startBody(TableBody body) { + startElement(body); + } + + @Override + public void endBody(TableBody body) { + endElement(body); + } + + @Override + public void startRow(TableRow tr) { + startElement(tr); + } + + @Override + public void endRow(TableRow tr) { + endElement(tr); + } + + @Override + public void startCell(TableCell tc) { + AttributesImpl attributes = new AttributesImpl(); + int colSpan = tc.getNumberColumnsSpanned(); + if (colSpan > 1) { + addNoNamespaceAttribute(attributes, "number-columns-spanned", + Integer.toString(colSpan)); + } + startElement(tc, attributes); + } + + @Override + public void endCell(TableCell tc) { + endElement(tc); + } + + @Override + public void startList(ListBlock lb) { + startElement(lb); + } + + @Override + public void endList(ListBlock lb) { + endElement(lb); + } + + @Override + public void startListItem(ListItem li) { + startElement(li); + } + + @Override + public void endListItem(ListItem li) { + endElement(li); + } + + @Override + public void startListLabel(ListItemLabel listItemLabel) { + startElement(listItemLabel); + } + + @Override + public void endListLabel(ListItemLabel listItemLabel) { + endElement(listItemLabel); + } + + @Override + public void startListBody(ListItemBody listItemBody) { + startElement(listItemBody); + } + + @Override + public void endListBody(ListItemBody listItemBody) { + endElement(listItemBody); + } + + @Override + public void startStatic(StaticContent staticContent) { + startElement(staticContent); + } + + @Override + public void endStatic(StaticContent statisContent) { + endElement(statisContent); + } + + @Override + public void startLink(BasicLink basicLink) { + startElementWithID(basicLink); + } + + @Override + public void endLink(BasicLink basicLink) { + endElement(basicLink); + } + + @Override + public void image(ExternalGraphic eg) { + startElementWithIDAndAltText(eg); + endElement(eg); + } + + @Override + public void startInstreamForeignObject(InstreamForeignObject ifo) { + startElementWithIDAndAltText(ifo); + } + + @Override + public void endInstreamForeignObject(InstreamForeignObject ifo) { + endElement(ifo); + } + + @Override + public void startFootnote(Footnote footnote) { + startElement(footnote); + } + + @Override + public void endFootnote(Footnote footnote) { + endElement(footnote); + } + + @Override + public void startFootnoteBody(FootnoteBody body) { + startElement(body); + } + + @Override + public void endFootnoteBody(FootnoteBody body) { + endElement(body); + } + + @Override + public void startWrapper(Wrapper wrapper) { + startElement(wrapper); + } + + @Override + public void endWrapper(Wrapper wrapper) { + endElement(wrapper); + } + + @Override + public void character(Character c) { + startElementWithID(c); + endElement(c); + } + + @Override + public void characters(FOText foText) { + startElementWithID(foText); + endElement(foText); + } + + + private void startElement(FONode node) { + startElement(node, new AttributesImpl()); + } + + private void startElementWithID(FONode node) { + AttributesImpl attributes = new AttributesImpl(); + String localName = node.getLocalName(); + if (node instanceof CommonAccessibilityHolder) { + addRole((CommonAccessibilityHolder) node, attributes); + } + node.setStructureTreeElement(structureTreeEventHandler.startReferencedNode(localName, attributes)); + } + + private void startElementWithIDAndAltText(AbstractGraphics node) { + AttributesImpl attributes = new AttributesImpl(); + String localName = node.getLocalName(); + addRole(node, attributes); + addAttribute(attributes, ExtensionElementMapping.URI, "alt-text", + ExtensionElementMapping.STANDARD_PREFIX, node.getAltText()); + node.setStructureTreeElement(structureTreeEventHandler.startImageNode(localName, attributes)); + } + + private StructureTreeElement startElement(FONode node, AttributesImpl attributes) { + String localName = node.getLocalName(); + if (node instanceof CommonAccessibilityHolder) { + addRole((CommonAccessibilityHolder) node, attributes); + } + return structureTreeEventHandler.startNode(localName, attributes); + } + + private void addNoNamespaceAttribute(AttributesImpl attributes, String name, String value) { + attributes.addAttribute("", name, name, XMLUtil.CDATA, value); + } + + private void addAttribute(AttributesImpl attributes, + String namespace, String localName, String prefix, String value) { + assert namespace.length() > 0 && prefix.length() > 0; + String qualifiedName = prefix + ":" + localName; + attributes.addAttribute(namespace, localName, qualifiedName, XMLUtil.CDATA, value); + } + + private void addRole(CommonAccessibilityHolder node, AttributesImpl attributes) { + String role = node.getCommonAccessibility().getRole(); + if (role != null) { + addNoNamespaceAttribute(attributes, "role", role); + } + } + + private void endElement(FONode node) { + String localName = node.getLocalName(); + structureTreeEventHandler.endNode(localName); + } + +} diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java index 545c9015d..29a363495 100644 --- a/src/java/org/apache/fop/area/AreaTreeParser.java +++ b/src/java/org/apache/fop/area/AreaTreeParser.java @@ -728,7 +728,6 @@ public class AreaTreeParser { setTraits(attributes, ip, SUBSET_BOX); setTraits(attributes, ip, SUBSET_COLOR); setTraits(attributes, ip, SUBSET_LINK); - setPtr(ip, attributes); Area parent = (Area)areaStack.peek(); parent.addChildArea(ip); areaStack.push(ip); @@ -777,7 +776,6 @@ public class AreaTreeParser { "tlsadjust", 0)); text.setTextWordSpaceAdjust(XMLUtil.getAttributeAsInt(attributes, "twsadjust", 0)); - setPtr(text, attributes); Area parent = (Area)areaStack.peek(); parent.addChildArea(text); areaStack.push(text); @@ -870,7 +868,6 @@ public class AreaTreeParser { viewport.setContentPosition(XMLUtil.getAttributeAsRectangle2D(attributes, "pos")); viewport.setClip(XMLUtil.getAttributeAsBoolean(attributes, "clip", false)); viewport.setOffset(XMLUtil.getAttributeAsInt(attributes, "offset", 0)); - setPtr(viewport, attributes); Area parent = (Area)areaStack.peek(); parent.addChildArea(viewport); areaStack.push(viewport); @@ -889,7 +886,6 @@ public class AreaTreeParser { transferForeignObjects(attributes, image); setAreaAttributes(attributes, image); setTraits(attributes, image, SUBSET_COMMON); - setPtr(image, attributes); getCurrentViewport().setContent(image); } } @@ -1174,13 +1170,6 @@ public class AreaTreeParser { } } - private void setPtr(Area area, Attributes attributes) { - String ptr = attributes.getValue("ptr"); - if (ptr != null) { - area.addTrait(Trait.PTR, ptr); - } - } - /** {@inheritDoc} */ public void characters(char[] ch, int start, int length) throws SAXException { if (delegate != null) { diff --git a/src/java/org/apache/fop/area/Trait.java b/src/java/org/apache/fop/area/Trait.java index 042b65337..d9194559d 100644 --- a/src/java/org/apache/fop/area/Trait.java +++ b/src/java/org/apache/fop/area/Trait.java @@ -153,8 +153,8 @@ public final class Trait implements Serializable { /** Trait for color of linethrough decorations when rendering inline parent. */ public static final Integer LINETHROUGH_COLOR = 36; - /** The ptr trait. Used for accessibility */ - public static final Integer PTR = 37; + /** For navigation in the document structure. */ + public static final Integer STRUCTURE_TREE_ELEMENT = 37; /** Maximum value used by trait keys */ public static final int MAX_TRAIT_KEY = 37; @@ -186,7 +186,7 @@ public final class Trait implements Serializable { static { // Create a hashmap mapping trait code to name for external representation //put(ID_LINK, new TraitInfo("id-link", String.class)); - put(PTR, new TraitInfo("ptr", String.class)); + put(STRUCTURE_TREE_ELEMENT, new TraitInfo("structure-tree-element", String.class)); put(INTERNAL_LINK, new TraitInfo("internal-link", InternalLink.class)); put(EXTERNAL_LINK, new TraitInfo("external-link", ExternalLink.class)); put(FONT, new TraitInfo("font", FontTriplet.class)); diff --git a/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java b/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java index ed85bd1c9..e64106a80 100644 --- a/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java +++ b/src/java/org/apache/fop/fo/DelegatingFOEventHandler.java @@ -387,8 +387,8 @@ public abstract class DelegatingFOEventHandler extends FOEventHandler { } @Override - public void characters(char[] data, int start, int length) { - delegate.characters(data, start, length); + public void characters(FOText foText) { + delegate.characters(foText); } @Override diff --git a/src/java/org/apache/fop/fo/FOEventHandler.java b/src/java/org/apache/fop/fo/FOEventHandler.java index 1f3514dea..bed1f3677 100644 --- a/src/java/org/apache/fop/fo/FOEventHandler.java +++ b/src/java/org/apache/fop/fo/FOEventHandler.java @@ -88,6 +88,10 @@ public abstract class FOEventHandler { this.fontInfo.setEventListener(new FontEventAdapter(foUserAgent.getEventBroadcaster())); } + /** Constructor for sub-classes that do not need an {@link FOUserAgent} instance. */ + protected FOEventHandler() { + } + /** * Returns the User Agent object associated with this FOEventHandler. * @return the User Agent object @@ -532,11 +536,9 @@ public abstract class FOEventHandler { /** * Process character data. - * @param data Array of characters to process. - * @param start Offset for characters to process. - * @param length Portion of array to process. + * @param foText text to process */ - public void characters(char[] data, int start, int length) { + public void characters(FOText foText) { } /** diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 4946f6d5c..622ff86d4 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.util.QName; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.extensions.ExtensionAttachment; @@ -912,7 +913,7 @@ public abstract class FONode implements Cloneable { } - public void setPtr(String ptr) { + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { throw new UnsupportedOperationException(); } diff --git a/src/java/org/apache/fop/fo/FOText.java b/src/java/org/apache/fop/fo/FOText.java index 5db11f731..3858cdea9 100644 --- a/src/java/org/apache/fop/fo/FOText.java +++ b/src/java/org/apache/fop/fo/FOText.java @@ -25,6 +25,7 @@ import java.util.NoSuchElementException; import org.xml.sax.Locator; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.flow.Block; @@ -79,6 +80,8 @@ public class FOText extends FONode implements CharSequence { /** Holds the text decoration values. May be null */ private CommonTextDecoration textDecoration; + private StructureTreeElement structureTreeElement; + private static final int IS_WORD_CHAR_FALSE = 0; private static final int IS_WORD_CHAR_TRUE = 1; private static final int IS_WORD_CHAR_MAYBE = 2; @@ -115,25 +118,14 @@ public class FOText extends FONode implements CharSequence { /** * Return the array of characters for this instance. * - * @return a char array containing the text + * @return a char sequence containing the text */ - public char[] getCharArray() { - + public CharSequence getCharSequence() { if (this.charBuffer == null) { return null; } - - if (this.charBuffer.hasArray()) { - return this.charBuffer.array(); - } - - // only if the buffer implementation has - // no accessible backing array, return a new one - char[] ca = new char[this.charBuffer.limit()]; this.charBuffer.rewind(); - this.charBuffer.get(ca); - return ca; - + return this.charBuffer.asReadOnlyBuffer().subSequence(0, this.charBuffer.limit()); } /** {@inheritDoc} */ @@ -176,8 +168,7 @@ public class FOText extends FONode implements CharSequence { /** {@inheritDoc} */ protected void endOfNode() throws FOPException { super.endOfNode(); - getFOEventHandler().characters( - this.getCharArray(), 0, this.charBuffer.limit()); + getFOEventHandler().characters(this); } /** {@inheritDoc} */ @@ -670,4 +661,14 @@ public class FOText extends FONode implements CharSequence { this.charBuffer.rewind(); } } + + @Override + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; + } + + public StructureTreeElement getStructureTreeElement() { + return structureTreeElement; + } + } diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index b053692d6..ece4e5448 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -33,7 +33,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.util.QName; -import org.apache.fop.accessibility.FO2StructureTreeConverter; +import org.apache.fop.accessibility.fo.FO2StructureTreeConverter; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.FormattingResults; diff --git a/src/java/org/apache/fop/fo/extensions/InternalElementMapping.java b/src/java/org/apache/fop/fo/extensions/InternalElementMapping.java index e939841e1..687952d25 100644 --- a/src/java/org/apache/fop/fo/extensions/InternalElementMapping.java +++ b/src/java/org/apache/fop/fo/extensions/InternalElementMapping.java @@ -37,11 +37,18 @@ public class InternalElementMapping extends ElementMapping { /** The standard XML prefix for elements and attributes in this namespace. */ public static final String STANDARD_PREFIX = "foi"; + /** The "struct-id" attribute, to identify a structure tree element. */ + public static final String STRUCT_ID = "struct-id"; + + /** The "struct-ref" attribute, to refer to a structure tree element. */ + public static final String STRUCT_REF = "struct-ref"; + private static final Set PROPERTY_ATTRIBUTES = new java.util.HashSet(); static { //These are FOP's extension properties for accessibility - PROPERTY_ATTRIBUTES.add("ptr"); + PROPERTY_ATTRIBUTES.add(STRUCT_ID); + PROPERTY_ATTRIBUTES.add(STRUCT_REF); } /** diff --git a/src/java/org/apache/fop/fo/flow/AbstractGraphics.java b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java index 67a33d088..2b8fa8a0b 100644 --- a/src/java/org/apache/fop/fo/flow/AbstractGraphics.java +++ b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java @@ -19,6 +19,7 @@ package org.apache.fop.fo.flow; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; @@ -31,7 +32,7 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.LengthRangeProperty; import org.apache.fop.fo.properties.SpaceProperty; -import org.apache.fop.fo.properties.StructurePointerPropertySet; +import org.apache.fop.fo.properties.StructureTreeElementHolder; /** * Common base class for the @@ -40,7 +41,7 @@ import org.apache.fop.fo.properties.StructurePointerPropertySet; * fo:external-graphic flow formatting objects. */ public abstract class AbstractGraphics extends FObj - implements GraphicsProperties, StructurePointerPropertySet, CommonAccessibilityHolder { + implements GraphicsProperties, StructureTreeElementHolder, CommonAccessibilityHolder { // The value of properties relevant for fo:instream-foreign-object // and external-graphics. @@ -66,7 +67,7 @@ public abstract class AbstractGraphics extends FObj private int textAlign; private Length width; private String altText; - private String ptr; // used for accessibility + private StructureTreeElement structureTreeElement; // Unused but valid items, commented out for performance: // private CommonAccessibility commonAccessibility; // private CommonAural commonAural; @@ -226,13 +227,13 @@ public abstract class AbstractGraphics extends FObj } @Override - public void setPtr(String ptr) { - this.ptr = ptr; + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; } /** {@inheritDoc} */ - public String getPtr() { - return ptr; + public StructureTreeElement getStructureTreeElement() { + return structureTreeElement; } public String getAltText() { diff --git a/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java b/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java index bbb632b29..108896d91 100644 --- a/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java +++ b/src/java/org/apache/fop/fo/flow/AbstractPageNumberCitation.java @@ -24,6 +24,7 @@ import java.awt.Color; import org.xml.sax.Attributes; import org.xml.sax.Locator; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.Constants; @@ -37,7 +38,7 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fo.properties.CommonFont; import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.SpaceProperty; -import org.apache.fop.fo.properties.StructurePointerPropertySet; +import org.apache.fop.fo.properties.StructureTreeElementHolder; /** * Common base class for the @@ -46,7 +47,7 @@ import org.apache.fop.fo.properties.StructurePointerPropertySet; * fo:page-number-citation-last objects. */ public abstract class AbstractPageNumberCitation extends FObj - implements StructurePointerPropertySet, CommonAccessibilityHolder { + implements StructureTreeElementHolder, CommonAccessibilityHolder { // The value of properties relevant for fo:page-number-citation(-last). private CommonAccessibility commonAccessibility; @@ -56,7 +57,7 @@ public abstract class AbstractPageNumberCitation extends FObj private int alignmentBaseline; private Length baselineShift; private int dominantBaseline; - private String ptr; // used for accessibility + private StructureTreeElement structureTreeElement; // private ToBeImplementedProperty letterSpacing; private SpaceProperty lineHeight; private String refId; @@ -151,13 +152,13 @@ public abstract class AbstractPageNumberCitation extends FObj } @Override - public void setPtr(String ptr) { - this.ptr = ptr; + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; } /** {@inheritDoc} */ - public String getPtr() { - return ptr; + public StructureTreeElement getStructureTreeElement() { + return structureTreeElement; } /** @return the "alignment-adjust" property */ diff --git a/src/java/org/apache/fop/fo/flow/BasicLink.java b/src/java/org/apache/fop/fo/flow/BasicLink.java index 7bff2d521..0d6d5d9b4 100644 --- a/src/java/org/apache/fop/fo/flow/BasicLink.java +++ b/src/java/org/apache/fop/fo/flow/BasicLink.java @@ -21,12 +21,13 @@ package org.apache.fop.fo.flow; import org.xml.sax.Locator; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; -import org.apache.fop.fo.properties.StructurePointerPropertySet; +import org.apache.fop.fo.properties.StructureTreeElementHolder; /** * Class modelling the @@ -36,14 +37,14 @@ import org.apache.fop.fo.properties.StructurePointerPropertySet; * and whether that link is external (uses a URI) or internal (an id * reference). */ -public class BasicLink extends InlineLevel implements StructurePointerPropertySet { +public class BasicLink extends InlineLevel implements StructureTreeElementHolder { // The value of properties relevant for fo:basic-link. private Length alignmentAdjust; private int alignmentBaseline; private Length baselineShift; private int dominantBaseline; - private String ptr; + private StructureTreeElement structureTreeElement; // private ToBeImplementedProperty destinationPlacementOffset; private String externalDestination; // private ToBeImplementedProperty indicateDestination; @@ -143,13 +144,13 @@ public class BasicLink extends InlineLevel implements StructurePointerPropertySe } @Override - public void setPtr(String ptr) { - this.ptr = ptr; + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; } /** {@inheritDoc} */ - public String getPtr() { - return ptr; + public StructureTreeElement getStructureTreeElement() { + return structureTreeElement; } /** diff --git a/src/java/org/apache/fop/fo/flow/Block.java b/src/java/org/apache/fop/fo/flow/Block.java index b1705288a..4e5b6f15f 100644 --- a/src/java/org/apache/fop/fo/flow/Block.java +++ b/src/java/org/apache/fop/fo/flow/Block.java @@ -42,13 +42,12 @@ import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.fo.properties.CommonRelativePosition; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.SpaceProperty; -import org.apache.fop.fo.properties.StructurePointerPropertySet; /** * Class modelling the * fo:block object. */ -public class Block extends FObjMixed implements BreakPropertySet, StructurePointerPropertySet, +public class Block extends FObjMixed implements BreakPropertySet, CommonAccessibilityHolder { // used for FO validation @@ -77,7 +76,6 @@ public class Block extends FObjMixed implements BreakPropertySet, StructurePoint private int lineHeightShiftAdjustment; private int lineStackingStrategy; private Numeric orphans; - private String ptr; //used for accessibility private int whiteSpaceTreatment; private int span; private int textAlign; @@ -183,16 +181,6 @@ public class Block extends FObjMixed implements BreakPropertySet, StructurePoint return breakAfter; } - @Override - public void setPtr(String ptr) { - this.ptr = ptr; - } - - /** {@inheritDoc} */ - public String getPtr() { - return ptr; - } - /** @return the "break-before" property. */ public int getBreakBefore() { return breakBefore; diff --git a/src/java/org/apache/fop/fo/flow/Character.java b/src/java/org/apache/fop/fo/flow/Character.java index a33bea53d..c4de9fb72 100644 --- a/src/java/org/apache/fop/fo/flow/Character.java +++ b/src/java/org/apache/fop/fo/flow/Character.java @@ -24,6 +24,7 @@ import java.util.NoSuchElementException; import org.xml.sax.Locator; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.CharIterator; @@ -38,13 +39,13 @@ import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.KeepProperty; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.SpaceProperty; -import org.apache.fop.fo.properties.StructurePointerPropertySet; +import org.apache.fop.fo.properties.StructureTreeElementHolder; /** * Class modelling the * fo:character object. */ -public class Character extends FObj implements StructurePointerPropertySet { +public class Character extends FObj implements StructureTreeElementHolder { // The value of properties relevant for fo:character. private CommonBorderPaddingBackground commonBorderPaddingBackground; private CommonFont commonFont; @@ -63,7 +64,7 @@ public class Character extends FObj implements StructurePointerPropertySet { private CommonTextDecoration textDecoration; // private ToBeImplementedProperty textShadow; private Property wordSpacing; - private String ptr; // used for accessibility + private StructureTreeElement structureTreeElement; // Unused but valid items, commented out for performance: // private CommonAural commonAural; // private CommonMarginInline commonMarginInline; @@ -210,13 +211,13 @@ public class Character extends FObj implements StructurePointerPropertySet { } @Override - public void setPtr(String ptr) { - this.ptr = ptr; + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; } /** {@inheritDoc} */ - public String getPtr() { - return ptr; + public StructureTreeElement getStructureTreeElement() { + return structureTreeElement; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/fo/flow/Inline.java b/src/java/org/apache/fop/fo/flow/Inline.java index e458184f4..debf6bbf6 100644 --- a/src/java/org/apache/fop/fo/flow/Inline.java +++ b/src/java/org/apache/fop/fo/flow/Inline.java @@ -26,19 +26,17 @@ import org.apache.fop.datatypes.Length; import org.apache.fop.fo.FONode; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; -import org.apache.fop.fo.properties.StructurePointerPropertySet; /** * Class modelling the * fo:inline formatting object. */ -public class Inline extends InlineLevel implements StructurePointerPropertySet { +public class Inline extends InlineLevel { // The value of properties relevant for fo:inline. // See also superclass InlineLevel private Length alignmentAdjust; private int alignmentBaseline; private Length baselineShift; - private String ptr; // used for accessibility private int dominantBaseline; // Unused but valid items, commented out for performance: // private CommonRelativePosition commonRelativePosition; @@ -147,16 +145,6 @@ public class Inline extends InlineLevel implements StructurePointerPropertySet { return dominantBaseline; } - @Override - public void setPtr(String ptr) { - this.ptr = ptr; - } - - /** {@inheritDoc} */ - public String getPtr() { - return ptr; - } - /** {@inheritDoc} */ public String getLocalName() { return "inline"; diff --git a/src/java/org/apache/fop/fo/flow/PageNumber.java b/src/java/org/apache/fop/fo/flow/PageNumber.java index c0373aa7f..0e5ce5071 100644 --- a/src/java/org/apache/fop/fo/flow/PageNumber.java +++ b/src/java/org/apache/fop/fo/flow/PageNumber.java @@ -23,6 +23,7 @@ import java.awt.Color; import org.xml.sax.Locator; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.Length; import org.apache.fop.fo.Constants; @@ -36,14 +37,14 @@ import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fo.properties.CommonFont; import org.apache.fop.fo.properties.CommonTextDecoration; import org.apache.fop.fo.properties.SpaceProperty; -import org.apache.fop.fo.properties.StructurePointerPropertySet; +import org.apache.fop.fo.properties.StructureTreeElementHolder; /** * Class modelling the * fo:page-number object. */ public class PageNumber extends FObj - implements StructurePointerPropertySet, CommonAccessibilityHolder { + implements StructureTreeElementHolder, CommonAccessibilityHolder { // The value of properties relevant for fo:page-number. private CommonAccessibility commonAccessibility; private CommonBorderPaddingBackground commonBorderPaddingBackground; @@ -52,7 +53,7 @@ public class PageNumber extends FObj private int alignmentBaseline; private Length baselineShift; private int dominantBaseline; - private String ptr; // used for accessibility + private StructureTreeElement structureTreeElement; // private ToBeImplementedProperty letterSpacing; private SpaceProperty lineHeight; /** Holds the text decoration values. May be null */ @@ -176,13 +177,13 @@ public class PageNumber extends FObj } @Override - public void setPtr(String ptr) { - this.ptr = ptr; + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; } /** {@inheritDoc} */ - public String getPtr() { - return ptr; + public StructureTreeElement getStructureTreeElement() { + return structureTreeElement; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/fo/flow/table/TableFObj.java b/src/java/org/apache/fop/fo/flow/table/TableFObj.java index 0da7b9458..2506c26b4 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableFObj.java +++ b/src/java/org/apache/fop/fo/flow/table/TableFObj.java @@ -36,19 +36,17 @@ import org.apache.fop.fo.properties.EnumProperty; import org.apache.fop.fo.properties.NumberProperty; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.PropertyMaker; -import org.apache.fop.fo.properties.StructurePointerPropertySet; import org.apache.fop.layoutmgr.table.CollapsingBorderModel; /** * Common base class for table-related FOs */ -public abstract class TableFObj extends FObj implements StructurePointerPropertySet { +public abstract class TableFObj extends FObj { private Numeric borderAfterPrecedence; private Numeric borderBeforePrecedence; private Numeric borderEndPrecedence; private Numeric borderStartPrecedence; - private String ptr; ConditionalBorder borderBefore; // CSOK: VisibilityModifier ConditionalBorder borderAfter; // CSOK: VisibilityModifier @@ -240,16 +238,6 @@ public abstract class TableFObj extends FObj implements StructurePointerProperty } } - @Override - public void setPtr(String ptr) { - this.ptr = ptr; - } - - /** {@inheritDoc} */ - public String getPtr() { - return ptr; - } - /** * Prepares the borders of this element if the collapsing-border model is in use. * Conflict resolution with parent elements is done where applicable. diff --git a/src/java/org/apache/fop/fo/properties/StructurePointerPropertySet.java b/src/java/org/apache/fop/fo/properties/StructurePointerPropertySet.java deleted file mode 100644 index 5cce2822e..000000000 --- a/src/java/org/apache/fop/fo/properties/StructurePointerPropertySet.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.fo.properties; - -/** - * Defines property access methods for internal structure pointer extension properties. - */ -public interface StructurePointerPropertySet { - - /** - * Returns the value of the "foi:ptr" property, the internal structure pointer used - * for tagged PDF and other formats that support a structure tree in addition to paged content. - * @return the "foi:ptr" property - */ - String getPtr(); - -} diff --git a/src/java/org/apache/fop/fo/properties/StructureTreeElementHolder.java b/src/java/org/apache/fop/fo/properties/StructureTreeElementHolder.java new file mode 100644 index 000000000..6fbb608de --- /dev/null +++ b/src/java/org/apache/fop/fo/properties/StructureTreeElementHolder.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.fo.properties; + +import org.apache.fop.accessibility.StructureTreeElement; + +/** + * Implementations of this interface can return the element in the document's + * structure tree that they resulted into. Used for tagged PDF and other formats + * that support a structure tree in addition to paged content. + */ +public interface StructureTreeElementHolder { + + /** + * Returns the element in the document's structure tree that corresponds to this instance. + * + * @return a structure tree element + */ + StructureTreeElement getStructureTreeElement(); + +} diff --git a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java index b748c2152..ed2ea4ee9 100644 --- a/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -329,7 +329,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager addMarkersToPage(false, isFirst(firstPos), isLast(lastPos)); - TraitSetter.addPtr(curBlockArea, getBlockFO().getPtr()); // used for accessibility TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(), effSpaceBefore, effSpaceAfter); flush(); diff --git a/src/java/org/apache/fop/layoutmgr/TraitSetter.java b/src/java/org/apache/fop/layoutmgr/TraitSetter.java index c0e451577..da548c23c 100644 --- a/src/java/org/apache/fop/layoutmgr/TraitSetter.java +++ b/src/java/org/apache/fop/layoutmgr/TraitSetter.java @@ -22,6 +22,7 @@ package org.apache.fop.layoutmgr; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.area.Area; import org.apache.fop.area.Trait; import org.apache.fop.datatypes.LengthBase; @@ -29,9 +30,9 @@ import org.apache.fop.datatypes.PercentBaseContext; import org.apache.fop.datatypes.SimplePercentBaseContext; import org.apache.fop.fo.Constants; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo; import org.apache.fop.fo.properties.CommonMarginBlock; import org.apache.fop.fo.properties.CommonTextDecoration; -import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo; import org.apache.fop.fonts.Font; import org.apache.fop.traits.BorderProps; import org.apache.fop.traits.MinOptMax; @@ -591,13 +592,14 @@ public final class TraitSetter { } /** - * Adds the ptr trait to the area. + * Sets the structure tree element associated to the given area. + * * @param area the area to set the traits on - * @param ptr string + * @param structureTreeElement the element the area is associated to in the document structure */ - public static void addPtr(Area area, String ptr) { - if (ptr != null && ptr.length() > 0) { - area.addTrait(Trait.PTR, ptr); + public static void addStructureTreeElement(Area area, StructureTreeElement structureTreeElement) { + if (structureTreeElement != null) { + area.addTrait(Trait.STRUCTURE_TREE_ELEMENT, structureTreeElement); } } diff --git a/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java index 218497a53..8c797a48c 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/AbstractGraphicsLayoutManager.java @@ -85,7 +85,7 @@ public abstract class AbstractGraphicsLayoutManager extends LeafNodeLayoutManage transferForeignAttributes(viewportArea); InlineViewport vp = new InlineViewport(viewportArea); - TraitSetter.addPtr(vp, fobj.getPtr()); // used for accessibility + TraitSetter.addStructureTreeElement(vp, fobj.getStructureTreeElement()); TraitSetter.setProducerID(vp, fobj.getId()); vp.setIPD(imageLayout.getViewportSize().width); vp.setBPD(imageLayout.getViewportSize().height); diff --git a/src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java index e090fbae6..8c769924a 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/AbstractPageNumberCitationLayoutManager.java @@ -136,7 +136,7 @@ public abstract class AbstractPageNumberCitationLayoutManager extends LeafNodeLa text.setBaselineOffset(font.getAscender()); TraitSetter.addFontTraits(text, font); text.addTrait(Trait.COLOR, fobj.getColor()); - TraitSetter.addPtr(text, fobj.getPtr()); // used for accessibility + TraitSetter.addStructureTreeElement(text, fobj.getStructureTreeElement()); TraitSetter.addTextDecoration(text, fobj.getTextDecoration()); } diff --git a/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java index 40c9a324e..1390c04d8 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/BasicLinkLayoutManager.java @@ -59,7 +59,7 @@ public class BasicLinkLayoutManager extends InlineLayoutManager { private void setupBasicLinkArea(InlineArea area) { BasicLink fobj = (BasicLink) this.fobj; // internal destinations take precedence: - TraitSetter.addPtr(area, fobj.getPtr()); // used for accessibility + TraitSetter.addStructureTreeElement(area, fobj.getStructureTreeElement()); if (fobj.hasInternalDestination()) { String idref = fobj.getInternalDestination(); PageSequenceLayoutManager pslm = getPSLM(); diff --git a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java index 2178b2e77..4877ff9bd 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java @@ -87,7 +87,7 @@ public class CharacterLayoutManager extends LeafNodeLayoutManager { } TraitSetter.setProducerID(text, node.getId()); TraitSetter.addTextDecoration(text, node.getTextDecoration()); - TraitSetter.addPtr(text, node.getPtr()); // used for accessibility + TraitSetter.addStructureTreeElement(text, node.getStructureTreeElement()); return text; } diff --git a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java index d8cfe6cda..4b7289b37 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/PageNumberLayoutManager.java @@ -19,13 +19,13 @@ package org.apache.fop.layoutmgr.inline; +import org.apache.fop.area.Trait; +import org.apache.fop.area.inline.InlineArea; +import org.apache.fop.area.inline.TextArea; import org.apache.fop.fo.flow.PageNumber; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; -import org.apache.fop.area.inline.InlineArea; -import org.apache.fop.area.inline.TextArea; -import org.apache.fop.area.Trait; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.TraitSetter; import org.apache.fop.traits.MinOptMax; @@ -85,7 +85,7 @@ public class PageNumberLayoutManager extends LeafNodeLayoutManager { text.setBaselineOffset(font.getAscender()); TraitSetter.addFontTraits(text, font); text.addTrait(Trait.COLOR, fobj.getColor()); - TraitSetter.addPtr(text, fobj.getPtr()); // used for accessibility + TraitSetter.addStructureTreeElement(text, fobj.getStructureTreeElement()); TraitSetter.addTextDecoration(text, fobj.getTextDecoration()); return text; diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java index 81240dec0..8767fe296 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java @@ -31,8 +31,6 @@ import org.apache.fop.area.Trait; import org.apache.fop.area.inline.TextArea; import org.apache.fop.fo.Constants; import org.apache.fop.fo.FOText; -import org.apache.fop.fo.FObj; -import org.apache.fop.fo.properties.StructurePointerPropertySet; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontSelector; import org.apache.fop.layoutmgr.InlineKnuthSequence; @@ -438,7 +436,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager { setText(); TraitSetter.addFontTraits(textArea, font); textArea.addTrait(Trait.COLOR, foText.getColor()); - TraitSetter.addPtr(textArea, getPtr()); // used for accessibility + TraitSetter.addStructureTreeElement(textArea, foText.getStructureTreeElement()); TraitSetter.addTextDecoration(textArea, foText.getTextDecoration()); TraitSetter.addFontTraits(textArea, font); return textArea; @@ -577,20 +575,6 @@ public class TextLayoutManager extends LeafNodeLayoutManager { } } - /** - * used for accessibility - * @return ptr of fobj - */ - private String getPtr() { - FObj fobj = parentLayoutManager.getFObj(); - if (fobj instanceof StructurePointerPropertySet) { - return (((StructurePointerPropertySet) fobj).getPtr()); - } else { - //No structure pointer applicable - return null; - } - } - private AreaInfo getAreaInfo(int index) { return (AreaInfo) areaInfos.get(index); } diff --git a/src/java/org/apache/fop/pdf/PDFStructElem.java b/src/java/org/apache/fop/pdf/PDFStructElem.java index 6dfb0dc95..44622638d 100644 --- a/src/java/org/apache/fop/pdf/PDFStructElem.java +++ b/src/java/org/apache/fop/pdf/PDFStructElem.java @@ -19,17 +19,28 @@ package org.apache.fop.pdf; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; import java.util.Locale; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.util.LanguageTags; /** * Class representing a PDF Structure Element. */ -public class PDFStructElem extends PDFDictionary { +public class PDFStructElem extends PDFDictionary implements StructureTreeElement { private PDFStructElem parentElement; + /** + * Elements to be added to the kids array. + */ + protected List kids; + /** * Creates a new structure element. * @@ -57,20 +68,11 @@ public class PDFStructElem extends PDFDictionary { /** {@inheritDoc} */ public void setParent(PDFObject parent) { - if (parent != null) { + if (parent != null && parent.hasObjectNumber()) { put("P", new PDFReference(parent)); } } - /** - * Returns the kids of this structure element. - * - * @return the value of the K entry - */ - private PDFArray getKids() { - return (PDFArray) get("K"); - } - /** * Add a kid to this structure element. This element will then add itself to * its parent structure element if it has not already, and so will the @@ -79,24 +81,10 @@ public class PDFStructElem extends PDFDictionary { * @param kid element to be added */ public void addKid(PDFObject kid) { - PDFArray kids = getKids(); if (kids == null) { - kids = new PDFArray(); - put("K", kids); + kids = new ArrayList(); } kids.add(kid); - joinHierarchy(); - } - - private boolean containsKid(PDFObject kid) { - PDFArray kids = getKids(); - return kids != null && kids.contains(kid); - } - - private void joinHierarchy() { - if (parentElement != null && !parentElement.containsKid(this)) { - parentElement.addKid(this); - } } /** @@ -109,7 +97,6 @@ public class PDFStructElem extends PDFDictionary { */ public void setMCIDKid(int mcid) { put("K", mcid); - joinHierarchy(); } /** @@ -127,7 +114,7 @@ public class PDFStructElem extends PDFDictionary { * @return the value of the S entry */ public PDFName getStructureType() { - return (PDFName)get("S"); + return (PDFName) get("S"); } /** @@ -154,6 +141,63 @@ public class PDFStructElem extends PDFDictionary { * @return the value of the Lang entry (null if no language was specified) */ public String getLanguage() { - return (String)get("Lang"); + return (String) get("Lang"); + } + + @Override + protected void writeDictionary(OutputStream out, Writer writer) throws IOException { + attachKids(); + super.writeDictionary(out, writer); + } + + /** + * Attaches all valid kids to the kids array. + * + * @return true iff 1+ kids were added to the kids array + */ + protected boolean attachKids() { + List validKids = new ArrayList(); + if (kids != null) { + for (PDFObject kid : kids) { + if (kid instanceof Placeholder) { + if (((Placeholder) kid).attachKids()) { + validKids.add(kid); + } + } else { + validKids.add(kid); + } + } + } + boolean kidsAttached = !validKids.isEmpty(); + if (kidsAttached) { + PDFArray array = new PDFArray(); + for (PDFObject ob : validKids) { + array.add(ob); + } + put("K", array); + } + return kidsAttached; } + + public static class Placeholder extends PDFStructElem { + + @Override + public void outputInline(OutputStream out, Writer writer) throws IOException { + if (kids != null) { + assert kids.size() > 0; + for (int i = 0; i < kids.size(); i++) { + if (i > 0) { + writer.write(' '); + } + Object obj = kids.get(i); + formatObject(obj, out, writer); + } + } + } + + public Placeholder(PDFObject parent, String name) { + super(parent, new PDFName(name)); + } + } + } diff --git a/src/java/org/apache/fop/render/intermediate/IFContext.java b/src/java/org/apache/fop/render/intermediate/IFContext.java index b8be97253..c59a02ba8 100644 --- a/src/java/org/apache/fop/render/intermediate/IFContext.java +++ b/src/java/org/apache/fop/render/intermediate/IFContext.java @@ -25,6 +25,7 @@ import java.util.Map; import org.apache.xmlgraphics.util.QName; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOUserAgent; /** @@ -46,7 +47,7 @@ public class IFContext { private Locale language; - private String structurePointer; + private StructureTreeElement structureTreeElement; private String id = ""; @@ -132,29 +133,31 @@ public class IFContext { } /** - * Sets the structure pointer for the following painted marks. This method is used when - * accessibility features are enabled. - * @param ptr the structure pointer + * Sets the structure tree element to which the subsequently painted marks + * will correspond. This method is used when accessibility features are + * enabled. + * + * @param structureTreeElement the structure tree element */ - public void setStructurePointer(String ptr) { - this.structurePointer = ptr; + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; } /** - * Resets the current structure pointer. - * @see #setStructurePointer(String) + * Resets the current structure tree element. + * @see #setStructureTreeElement(String) */ - public void resetStructurePointer() { - setStructurePointer(null); + public void resetStructureTreeElement() { + setStructureTreeElement(null); } /** - * Returns the current structure pointer. - * @return the structure pointer (or null if no pointer is active) - * @see #setStructurePointer(String) + * Returns the current structure tree element. + * @return the structure tree element (or null if no element is active) + * @see #setStructureTreeElement(String) */ - public String getStructurePointer() { - return this.structurePointer; + public StructureTreeElement getStructureTreeElement() { + return this.structureTreeElement; } /** diff --git a/src/java/org/apache/fop/render/intermediate/IFParser.java b/src/java/org/apache/fop/render/intermediate/IFParser.java index 8f0bb88ec..1a384c6e9 100644 --- a/src/java/org/apache/fop/render/intermediate/IFParser.java +++ b/src/java/org/apache/fop/render/intermediate/IFParser.java @@ -49,11 +49,13 @@ import org.apache.commons.logging.LogFactory; import org.apache.xmlgraphics.util.QName; import org.apache.fop.accessibility.AccessibilityEventProducer; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.accessibility.StructureTreeEventHandler; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.fo.ElementMapping; import org.apache.fop.fo.ElementMappingRegistry; import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.extensions.InternalElementMapping; import org.apache.fop.render.intermediate.extensions.DocumentNavigationExtensionConstants; import org.apache.fop.render.intermediate.extensions.DocumentNavigationHandler; import org.apache.fop.traits.BorderProps; @@ -158,6 +160,9 @@ public class IFParser implements IFConstants { private Attributes pageSequenceAttributes; + private Map structureTreeElements = + new HashMap(); + private final class StructureTreeHandler extends DefaultHandler { private final StructureTreeEventHandler structureTreeEventHandler; @@ -177,7 +182,23 @@ public class IFParser implements IFConstants { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (!"structure-tree".equals(localName)) { - structureTreeEventHandler.startNode(localName, attributes); + if (localName.equals("marked-content")) { + localName = "#PCDATA"; + } + String structID = attributes.getValue(InternalElementMapping.URI, + InternalElementMapping.STRUCT_ID); + if (structID == null) { + structureTreeEventHandler.startNode(localName, attributes); + } else if (localName.equals("external-graphic") + || localName.equals("instream-foreign-object")) { + StructureTreeElement structureTreeElement = + structureTreeEventHandler.startImageNode(localName, attributes); + structureTreeElements.put(structID, structureTreeElement); + } else { + StructureTreeElement structureTreeElement = + structureTreeEventHandler.startReferencedNode(localName, attributes); + structureTreeElements.put(structID, structureTreeElement); + } } } @@ -225,14 +246,6 @@ public class IFParser implements IFConstants { documentHandler.getContext().resetForeignAttributes(); } - private void establishStructurePointer(String ptr) { - documentHandler.getContext().setStructurePointer(ptr); - } - - private void resetStructurePointer() { - documentHandler.getContext().resetStructurePointer(); - } - /** {@inheritDoc} */ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { @@ -276,7 +289,7 @@ public class IFParser implements IFConstants { } else if (DocumentNavigationExtensionConstants.NAMESPACE.equals(uri)) { if (this.navParser == null) { this.navParser = new DocumentNavigationHandler( - this.documentHandler.getDocumentNavigationHandler()); + this.documentHandler.getDocumentNavigationHandler(), structureTreeElements); } delegate = this.navParser; delegateDepth++; @@ -604,9 +617,9 @@ public class IFParser implements IFConstants { s = lastAttributes.getValue("word-spacing"); int wordSpacing = (s != null ? Integer.parseInt(s) : 0); int[] dx = XMLUtil.getAttributeAsIntArray(lastAttributes, "dx"); - setStructurePointer(lastAttributes); + establishStructureTreeElement(lastAttributes); painter.drawText(x, y, letterSpacing, wordSpacing, dx, content.toString()); - resetStructurePointer(); + resetStructureTreeElement(); } public boolean ignoreCharacters() { @@ -701,7 +714,7 @@ public class IFParser implements IFConstants { int height = Integer.parseInt(lastAttributes.getValue("height")); Map foreignAttributes = getForeignAttributes(lastAttributes); establishForeignAttributes(foreignAttributes); - setStructurePointer(lastAttributes); + establishStructureTreeElement(lastAttributes); if (foreignObject != null) { painter.drawImage(foreignObject, new Rectangle(x, y, width, height)); @@ -715,7 +728,7 @@ public class IFParser implements IFConstants { painter.drawImage(uri, new Rectangle(x, y, width, height)); } resetForeignAttributes(); - resetStructurePointer(); + resetStructureTreeElement(); inForeignObject = false; } @@ -769,13 +782,20 @@ public class IFParser implements IFConstants { return foreignAttributes; } - private void setStructurePointer(Attributes attributes) { - String ptr = attributes.getValue("ptr"); - if (ptr != null && ptr.length() > 0) { - establishStructurePointer(ptr); + private void establishStructureTreeElement(Attributes attributes) { + String structRef = attributes.getValue(InternalElementMapping.URI, + InternalElementMapping.STRUCT_REF); + if (structRef != null && structRef.length() > 0) { + assert structureTreeElements.containsKey(structRef); + StructureTreeElement structureTreeElement = structureTreeElements.get(structRef); + documentHandler.getContext().setStructureTreeElement(structureTreeElement); } } + private void resetStructureTreeElement() { + documentHandler.getContext().resetStructureTreeElement(); + } + /** {@inheritDoc} */ public void characters(char[] ch, int start, int length) throws SAXException { if (delegate != null) { diff --git a/src/java/org/apache/fop/render/intermediate/IFRenderer.java b/src/java/org/apache/fop/render/intermediate/IFRenderer.java index d217646f6..a2d8a0bea 100644 --- a/src/java/org/apache/fop/render/intermediate/IFRenderer.java +++ b/src/java/org/apache/fop/render/intermediate/IFRenderer.java @@ -50,6 +50,7 @@ import org.apache.xmlgraphics.xmp.schemas.XMPBasicAdapter; import org.apache.xmlgraphics.xmp.schemas.XMPBasicSchema; import org.apache.fop.Version; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; @@ -629,12 +630,12 @@ public class IFRenderer extends AbstractPathOrientedRenderer { documentHandler.getContext().resetForeignAttributes(); } - private void establishStructurePointer(String ptr) { - documentHandler.getContext().setStructurePointer(ptr); + private void establishStructureTreeElement(StructureTreeElement structureTreeElement) { + documentHandler.getContext().setStructureTreeElement(structureTreeElement); } private void resetStructurePointer() { - documentHandler.getContext().resetStructurePointer(); + documentHandler.getContext().resetStructureTreeElement(); } /** {@inheritDoc} */ @@ -851,8 +852,9 @@ public class IFRenderer extends AbstractPathOrientedRenderer { /** {@inheritDoc} */ public void renderInlineViewport(InlineViewport viewport) { - String ptr = (String) viewport.getTrait(Trait.PTR); - establishStructurePointer(ptr); + StructureTreeElement structElem = + (StructureTreeElement) viewport.getTrait(Trait.STRUCTURE_TREE_ELEMENT); + establishStructureTreeElement(structElem); pushdID(viewport); Dimension dim = new Dimension(viewport.getIPD(), viewport.getBPD()); viewportDimensionStack.push(dim); @@ -912,7 +914,6 @@ public class IFRenderer extends AbstractPathOrientedRenderer { // stuff we only need if a link must be created: Rectangle ipRect = null; AbstractAction action = null; - String ptr = (String) ip.getTrait(Trait.PTR); // used for accessibility // make sure the rect is determined *before* calling super! int ipp = currentIPPosition; int bpp = currentBPPosition + ip.getOffset(); @@ -956,7 +957,9 @@ public class IFRenderer extends AbstractPathOrientedRenderer { // warn if link trait found but not allowed, else create link if (linkTraitFound) { - action.setStructurePointer(ptr); // used for accessibility + StructureTreeElement structElem = + (StructureTreeElement) ip.getTrait(Trait.STRUCTURE_TREE_ELEMENT); + action.setStructureTreeElement(structElem); Link link = new Link(action, ipRect); this.deferredLinks.add(link); } @@ -1009,8 +1012,8 @@ public class IFRenderer extends AbstractPathOrientedRenderer { String fontName = getInternalFontNameForArea(text); int size = ((Integer) text.getTrait(Trait.FONT_SIZE)).intValue(); - String ptr = (String)text.getTrait(Trait.PTR); // used for accessibility - establishStructurePointer(ptr); + StructureTreeElement structElem = (StructureTreeElement) text.getTrait(Trait.STRUCTURE_TREE_ELEMENT); + establishStructureTreeElement(structElem); // This assumes that *all* CIDFonts use a /ToUnicode mapping Typeface tf = getTypeface(fontName); diff --git a/src/java/org/apache/fop/render/intermediate/IFSerializer.java b/src/java/org/apache/fop/render/intermediate/IFSerializer.java index a4431b972..c6bf9af9e 100644 --- a/src/java/org/apache/fop/render/intermediate/IFSerializer.java +++ b/src/java/org/apache/fop/render/intermediate/IFSerializer.java @@ -38,9 +38,11 @@ import org.apache.xmlgraphics.util.QName; import org.apache.xmlgraphics.util.XMLizable; import org.apache.fop.accessibility.StructureTreeEventHandler; +import org.apache.fop.fo.extensions.InternalElementMapping; import org.apache.fop.fonts.FontInfo; import org.apache.fop.render.PrintRendererConfigurator; import org.apache.fop.render.RenderingContext; +import org.apache.fop.render.intermediate.IFStructureTreeBuilder.IFStructureTreeElement; import org.apache.fop.render.intermediate.extensions.AbstractAction; import org.apache.fop.render.intermediate.extensions.Bookmark; import org.apache.fop.render.intermediate.extensions.BookmarkTree; @@ -163,6 +165,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler handler.startPrefixMapping(XLINK_PREFIX, XLINK_NAMESPACE); handler.startPrefixMapping(DocumentNavigationExtensionConstants.PREFIX, DocumentNavigationExtensionConstants.NAMESPACE); + handler.startPrefixMapping(InternalElementMapping.STANDARD_PREFIX, InternalElementMapping.URI); handler.startElement(EL_DOCUMENT); } catch (SAXException e) { throw new IFException("SAX error in startDocument()", e); @@ -439,7 +442,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler addAttribute(atts, "width", Integer.toString(rect.width)); addAttribute(atts, "height", Integer.toString(rect.height)); addForeignAttributes(atts); - addStructurePointerAttribute(atts); + addStructureReference(atts); handler.element(EL_IMAGE, atts); } catch (SAXException e) { throw new IFException("SAX error in startGroup()", e); @@ -467,7 +470,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler addAttribute(atts, "width", Integer.toString(rect.width)); addAttribute(atts, "height", Integer.toString(rect.height)); addForeignAttributes(atts); - addStructurePointerAttribute(atts); + addStructureReference(atts); handler.startElement(EL_IMAGE, atts); new DOM2SAX(handler).writeDocument(doc, true); handler.endElement(EL_IMAGE); @@ -582,7 +585,7 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler if (dx != null) { addAttribute(atts, "dx", IFUtil.toString(dx)); } - addStructurePointerAttribute(atts); + addStructureReference(atts); handler.startElement(EL_TEXT, atts); char[] chars = text.toCharArray(); handler.characters(chars, 0, chars.length); @@ -682,13 +685,22 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler XMLUtil.addAttribute(atts, localName, value); } - private void addStructurePointerAttribute(AttributesImpl atts) { - String ptr = getContext().getStructurePointer(); - if (ptr != null) { - addAttribute(atts, "ptr", ptr); + private void addStructureReference(AttributesImpl atts) { + IFStructureTreeElement structureTreeElement = + (IFStructureTreeElement) getContext().getStructureTreeElement(); + if (structureTreeElement != null) { + addStructRefAttribute(atts, structureTreeElement.id); } } + private void addStructRefAttribute(AttributesImpl atts, String id) { + atts.addAttribute(InternalElementMapping.URI, + InternalElementMapping.STRUCT_REF, + InternalElementMapping.STANDARD_PREFIX + ":" + InternalElementMapping.STRUCT_REF, + XMLConstants.CDATA, + id); + } + private void addID() throws SAXException { String id = getContext().getID(); if (!currentID.equals(id)) { @@ -773,7 +785,8 @@ public class IFSerializer extends AbstractXMLWritingIFDocumentHandler atts.addAttribute(null, "rect", "rect", XMLConstants.CDATA, IFUtil.toString(link.getTargetRect())); if (getUserAgent().isAccessibilityEnabled()) { - addAttribute(atts, "ptr", link.getAction().getStructurePointer()); + addStructRefAttribute(atts, + ((IFStructureTreeElement) link.getAction().getStructureTreeElement()).id); } try { handler.startElement(DocumentNavigationExtensionConstants.LINK, atts); diff --git a/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java b/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java index 66457681f..b78ae35bc 100644 --- a/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java +++ b/src/java/org/apache/fop/render/intermediate/IFStructureTreeBuilder.java @@ -26,10 +26,14 @@ import java.util.Locale; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.DefaultHandler; import org.apache.fop.accessibility.StructureTree2SAXEventAdapter; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.accessibility.StructureTreeEventHandler; +import org.apache.fop.fo.extensions.InternalElementMapping; +import org.apache.fop.util.XMLUtil; /** * Saves structure tree events as SAX events in order to replay them when it's @@ -37,42 +41,17 @@ import org.apache.fop.accessibility.StructureTreeEventHandler; */ final class IFStructureTreeBuilder implements StructureTreeEventHandler { - private StructureTreeEventHandler delegate; - - private final List pageSequenceEventRecorders = new ArrayList(); - - /** - * Replay SAX events for a page sequence. - * @param handler The handler that receives SAX events - * @param pageSequenceIndex The index of the page sequence - * @throws SAXException - */ - public void replayEventsForPageSequence(ContentHandler handler, - int pageSequenceIndex) throws SAXException { - pageSequenceEventRecorders.get(pageSequenceIndex).replay(handler); - } - - /** {@inheritDoc} */ - public void startPageSequence(Locale locale) { - SAXEventRecorder eventRecorder = new SAXEventRecorder(); - pageSequenceEventRecorders.add(eventRecorder); - delegate = StructureTree2SAXEventAdapter.newInstance(eventRecorder); - delegate.startPageSequence(locale); - } + static final class IFStructureTreeElement implements StructureTreeElement { - /** {@inheritDoc} */ - public void endPageSequence() { - delegate.endPageSequence(); - } + final String id; - /** {@inheritDoc} */ - public void startNode(String name, Attributes attributes) { - delegate.startNode(name, attributes); - } + IFStructureTreeElement() { + this.id = null; + } - /** {@inheritDoc} */ - public void endNode(String name) { - delegate.endNode(name); + IFStructureTreeElement(String id) { + this.id = id; + } } /** A SAX handler that records events to replay them later. */ @@ -159,22 +138,22 @@ final class IFStructureTreeBuilder implements StructureTreeEventHandler { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { events.add(new StartElement(uri, localName, qName, attributes)); - }; + } @Override public void endElement(String uri, String localName, String qName) throws SAXException { events.add(new EndElement(uri, localName, qName)); - }; + } @Override public void startPrefixMapping(String prefix, String uri) throws SAXException { events.add(new StartPrefixMapping(prefix, uri)); - }; + } @Override public void endPrefixMapping(String prefix) throws SAXException { events.add(new EndPrefixMapping(prefix)); - }; + } /** * Replays the recorded events. @@ -187,4 +166,69 @@ final class IFStructureTreeBuilder implements StructureTreeEventHandler { } } } + + private StructureTreeEventHandler delegate; + + private final List pageSequenceEventRecorders = new ArrayList(); + + private int idCounter; + + /** + * Replay SAX events for a page sequence. + * @param handler The handler that receives SAX events + * @param pageSequenceIndex The index of the page sequence + * @throws SAXException + */ + public void replayEventsForPageSequence(ContentHandler handler, + int pageSequenceIndex) throws SAXException { + pageSequenceEventRecorders.get(pageSequenceIndex).replay(handler); + } + + public void startPageSequence(Locale locale) { + SAXEventRecorder eventRecorder = new SAXEventRecorder(); + pageSequenceEventRecorders.add(eventRecorder); + delegate = StructureTree2SAXEventAdapter.newInstance(eventRecorder); + delegate.startPageSequence(locale); + } + + public void endPageSequence() { + delegate.endPageSequence(); + } + + public StructureTreeElement startNode(String name, Attributes attributes) { + delegate.startNode(name, attributes); + return new IFStructureTreeElement(); + } + + public void endNode(String name) { + delegate.endNode(name); + } + + public StructureTreeElement startImageNode(String name, Attributes attributes) { + String id = getNextID(); + AttributesImpl atts = addIDAttribute(attributes, id); + delegate.startImageNode(name, atts); + return new IFStructureTreeElement(id); + } + + public StructureTreeElement startReferencedNode(String name, Attributes attributes) { + String id = getNextID(); + AttributesImpl atts = addIDAttribute(attributes, id); + delegate.startReferencedNode(name, atts); + return new IFStructureTreeElement(id); + } + + private String getNextID() { + return Integer.toHexString(idCounter++); + } + + private AttributesImpl addIDAttribute(Attributes attributes, String id) { + AttributesImpl atts = new AttributesImpl(attributes); + atts.addAttribute(InternalElementMapping.URI, + InternalElementMapping.STRUCT_ID, + InternalElementMapping.STANDARD_PREFIX + ":" + InternalElementMapping.STRUCT_ID, + XMLUtil.CDATA, + id); + return atts; + } } diff --git a/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java b/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java index 340b2e068..a2595d320 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/AbstractAction.java @@ -21,13 +21,15 @@ package org.apache.fop.render.intermediate.extensions; import org.apache.xmlgraphics.util.XMLizable; +import org.apache.fop.accessibility.StructureTreeElement; + /** * Abstract base class for document actions, like "go-to" actions with absolute page coordinates. */ public abstract class AbstractAction implements XMLizable { private String id; - private String structurePointer; + private StructureTreeElement structureTreeElement; /** * Sets an ID to make the action referencable. @@ -47,18 +49,18 @@ public abstract class AbstractAction implements XMLizable { /** * Sets the structure element corresponding to this action. - * @param structurePointer a reference to the structure element + * @param structureTreeElement a reference to the structure element */ - public void setStructurePointer(String structurePointer) { - this.structurePointer = structurePointer; + public void setStructureTreeElement(StructureTreeElement structureTreeElement) { + this.structureTreeElement = structureTreeElement; } /** * Returns the structure element corresponding to this action. * @return the reference to the structure element */ - public String getStructurePointer() { - return structurePointer; + public StructureTreeElement getStructureTreeElement() { + return structureTreeElement; } /** diff --git a/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java b/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java index 1e613d7eb..693497b73 100644 --- a/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java +++ b/src/java/org/apache/fop/render/intermediate/extensions/DocumentNavigationHandler.java @@ -21,6 +21,7 @@ package org.apache.fop.render.intermediate.extensions; import java.awt.Point; import java.awt.Rectangle; +import java.util.Map; import java.util.Stack; import org.xml.sax.Attributes; @@ -30,6 +31,8 @@ import org.xml.sax.helpers.DefaultHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.fop.accessibility.StructureTreeElement; +import org.apache.fop.fo.extensions.InternalElementMapping; import org.apache.fop.render.intermediate.IFDocumentNavigationHandler; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.util.XMLUtil; @@ -48,14 +51,20 @@ public class DocumentNavigationHandler extends DefaultHandler private IFDocumentNavigationHandler navHandler; - private String structurePointer; + private StructureTreeElement structureTreeElement; + + private Map structureTreeElements; /** * Main constructor. * @param navHandler the navigation handler that will receive the events + * @param structureTreeElements the elements representing the structure of the document */ - public DocumentNavigationHandler(IFDocumentNavigationHandler navHandler) { + public DocumentNavigationHandler(IFDocumentNavigationHandler navHandler, + Map structureTreeElements) { this.navHandler = navHandler; + assert structureTreeElements != null; + this.structureTreeElements = structureTreeElements; } /** {@inheritDoc} */ @@ -98,7 +107,8 @@ public class DocumentNavigationHandler extends DefaultHandler throw new SAXException(localName + " must be the root element!"); } Rectangle targetRect = XMLUtil.getAttributeAsRectangle(attributes, "rect"); - structurePointer = attributes.getValue("ptr"); + structureTreeElement = structureTreeElements.get( + attributes.getValue(InternalElementMapping.URI, InternalElementMapping.STRUCT_REF)); Link link = new Link(null, targetRect); objectStack.push(link); } else if (GOTO_XY.getLocalName().equals(localName)) { @@ -121,8 +131,8 @@ public class DocumentNavigationHandler extends DefaultHandler } action = new GoToXYAction(id, pageIndex, location); } - if (structurePointer != null) { - action.setStructurePointer(structurePointer); + if (structureTreeElement != null) { + action.setStructureTreeElement(structureTreeElement); } objectStack.push(action); } else if (GOTO_URI.getLocalName().equals(localName)) { @@ -134,8 +144,8 @@ public class DocumentNavigationHandler extends DefaultHandler if (id != null) { action.setID(id); } - if (structurePointer != null) { - action.setStructurePointer(structurePointer); + if (structureTreeElement != null) { + action.setStructureTreeElement(structureTreeElement); } objectStack.push(action); } else { diff --git a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java index c8fa481d4..2236778b5 100644 --- a/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFDocumentNavigationHandler.java @@ -31,6 +31,7 @@ import org.apache.fop.pdf.PDFFactory; import org.apache.fop.pdf.PDFGoTo; import org.apache.fop.pdf.PDFLink; import org.apache.fop.pdf.PDFOutline; +import org.apache.fop.pdf.PDFStructElem; import org.apache.fop.render.intermediate.IFDocumentNavigationHandler; import org.apache.fop.render.intermediate.IFException; import org.apache.fop.render.intermediate.extensions.AbstractAction; @@ -111,10 +112,9 @@ public class PDFDocumentNavigationHandler implements IFDocumentNavigationHandler PDFLink pdfLink = getPDFDoc().getFactory().makeLink( targetRect2D, pdfAction); if (pdfLink != null) { - String ptr = link.getAction().getStructurePointer(); - if (documentHandler.getUserAgent().isAccessibilityEnabled() - && ptr != null && ptr.length() > 0) { - documentHandler.getLogicalStructureHandler().addLinkContentItem(pdfLink, ptr); + PDFStructElem structure = (PDFStructElem) link.getAction().getStructureTreeElement(); + if (documentHandler.getUserAgent().isAccessibilityEnabled() && structure != null) { + documentHandler.getLogicalStructureHandler().addLinkContentItem(pdfLink, structure); } documentHandler.currentPage.addAnnotation(pdfLink); } diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java index d49ef4a3e..88a6e9c22 100644 --- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java @@ -19,9 +19,7 @@ package org.apache.fop.render.pdf; -import java.util.HashMap; import java.util.Locale; -import java.util.Map; import org.apache.fop.pdf.PDFArray; import org.apache.fop.pdf.PDFDictionary; @@ -47,11 +45,6 @@ class PDFLogicalStructureHandler { private final PDFDocument pdfDoc; - /** - * Map of references to the corresponding structure elements. - */ - private final Map structTreeMap = new HashMap(); - private final PDFParentTree parentTree = new PDFParentTree(); private int parentTreeKey; @@ -151,100 +144,79 @@ class PDFLogicalStructureHandler { parentTree.getNums().put(currentPage.getStructParents(), pageParentTreeArray); } - private MarkedContentInfo addToParentTree(String structurePointer) { - PDFStructElem parent = (PDFStructElem) structTreeMap.get(structurePointer); - if (parent == null) { - return ARTIFACT; - } else { - pageParentTreeArray.add(parent); - String type = parent.getStructureType().toString(); - int mcid = pageParentTreeArray.length() - 1; - return new MarkedContentInfo(type, mcid, parent); - } + private MarkedContentInfo addToParentTree(PDFStructElem structureTreeElement) { + PDFStructElem parent = (structureTreeElement instanceof PDFStructElem.Placeholder) + ? structureTreeElement.getParentStructElem() + : structureTreeElement; + pageParentTreeArray.add(parent); + String type = parent.getStructureType().toString(); + int mcid = pageParentTreeArray.length() - 1; + return new MarkedContentInfo(type, mcid, structureTreeElement); } /** * Adds a content item corresponding to text into the structure tree, if * there is a structure element associated to it. * - * @param structurePointer reference to the parent structure element of the - * piece of text + * @param structElem the parent structure element of the piece of text * @return the necessary information for bracketing the content as a * marked-content sequence. If there is no element in the structure tree * associated to that content, returns an instance whose * {@link MarkedContentInfo#tag} value is null. The content * must then be treated as an artifact. */ - MarkedContentInfo addTextContentItem(String structurePointer) { - MarkedContentInfo mci = addToParentTree(structurePointer); - if (mci != ARTIFACT) { + MarkedContentInfo addTextContentItem(PDFStructElem structElem) { + if (structElem == null) { + return ARTIFACT; + } else { + MarkedContentInfo mci = addToParentTree(structElem); PDFDictionary contentItem = new PDFDictionary(); contentItem.put("Type", MCR); contentItem.put("Pg", this.currentPage); contentItem.put("MCID", mci.mcid); mci.parent.addKid(contentItem); + return mci; } - return mci; } /** * Adds a content item corresponding to an image into the structure tree, if * there is a structure element associated to it. * - * @param structurePointer reference to the parent structure element of the - * image + * @param structElem the parent structure element of the image * @return the necessary information for bracketing the content as a * marked-content sequence. If there is no element in the structure tree * associated to that image, returns an instance whose - * {@link MarkedContentInfo#tag} value is null. The image - * must then be treated as an artifact. + * {@link MarkedContentInfo#tag} value is null. The image must + * then be treated as an artifact. */ - MarkedContentInfo addImageContentItem(String structurePointer) { - MarkedContentInfo mci = addToParentTree(structurePointer); - if (mci != ARTIFACT) { + MarkedContentInfo addImageContentItem(PDFStructElem structElem) { + if (structElem == null) { + return ARTIFACT; + } else { + MarkedContentInfo mci = addToParentTree(structElem); mci.parent.setMCIDKid(mci.mcid); mci.parent.setPage(this.currentPage); + return mci; } - return mci; } - // While the PDF spec allows images to be referred as PDF objects, this - // makes the Acrobat Pro checker complain that the image is not accessible. - // Its alt-text is still read aloud though. Using marked-content sequences - // like for text works. -// MarkedContentInfo addImageObject(String parentReference) { -// MarkedContentInfo mci = addToParentTree(parentReference); -// if (mci != ARTIFACT) { -// PDFDictionary contentItem = new PDFDictionary(); -// contentItem.put("Type", OBJR); -// contentItem.put("Pg", this.currentPage); -// contentItem.put("Obj", null); -// mci.parent.addKid(contentItem); -// } -// return mci; -// } - /** * Adds a content item corresponding to the given link into the structure * tree. * * @param link a link - * @param structurePointer reference to the corresponding parent structure element + * @param structureTreeElement its parent structure element */ - void addLinkContentItem(PDFLink link, String structurePointer) { + void addLinkContentItem(PDFLink link, PDFStructElem structureTreeElement) { int structParent = getNextParentTreeKey(); link.setStructParent(structParent); PDFDictionary contentItem = new PDFDictionary(); contentItem.put("Type", OBJR); contentItem.put("Pg", this.currentPage); contentItem.put("Obj", link); - PDFStructElem parent = (PDFStructElem) structTreeMap.get(structurePointer); - parentTree.getNums().put(structParent, parent); - parent.addKid(contentItem); - } - - void addStructurePointer(String ptr, PDFStructElem structElem) { - structTreeMap.put(ptr, structElem); + parentTree.getNums().put(structParent, structureTreeElement); + structureTreeElement.addKid(contentItem); } } diff --git a/src/java/org/apache/fop/render/pdf/PDFPainter.java b/src/java/org/apache/fop/render/pdf/PDFPainter.java index 11af216a2..f2fbfd014 100644 --- a/src/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/src/java/org/apache/fop/render/pdf/PDFPainter.java @@ -37,6 +37,7 @@ import org.apache.fop.fonts.SingleByteFont; import org.apache.fop.fonts.Typeface; import org.apache.fop.pdf.PDFDocument; import org.apache.fop.pdf.PDFNumber; +import org.apache.fop.pdf.PDFStructElem; import org.apache.fop.pdf.PDFTextUtil; import org.apache.fop.pdf.PDFXObject; import org.apache.fop.render.RenderingContext; @@ -133,24 +134,24 @@ public class PDFPainter extends AbstractIFPainter { PDFXObject xobject = getPDFDoc().getXObject(uri); if (xobject != null) { if (accessEnabled) { - String ptr = getContext().getStructurePointer(); - prepareImageMCID(ptr); + PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement(); + prepareImageMCID(structElem); placeImageAccess(rect, xobject); } else { placeImage(rect, xobject); } } else { if (accessEnabled) { - String ptr = getContext().getStructurePointer(); - prepareImageMCID(ptr); + PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement(); + prepareImageMCID(structElem); } drawImageUsingURI(uri, rect); flushPDFDoc(); } } - private void prepareImageMCID(String ptr) { - imageMCI = logicalStructureHandler.addImageContentItem(ptr); + private void prepareImageMCID(PDFStructElem structElem) { + imageMCI = logicalStructureHandler.addImageContentItem(structElem); } /** {@inheritDoc} */ @@ -194,8 +195,8 @@ public class PDFPainter extends AbstractIFPainter { /** {@inheritDoc} */ public void drawImage(Document doc, Rectangle rect) throws IFException { if (accessEnabled) { - String ptr = getContext().getStructurePointer(); - prepareImageMCID(ptr); + PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement(); + prepareImageMCID(structElem); } drawImageUsingDocument(doc, rect); flushPDFDoc(); @@ -294,8 +295,8 @@ public class PDFPainter extends AbstractIFPainter { String text) throws IFException { if (accessEnabled) { - String ptr = getContext().getStructurePointer(); - MarkedContentInfo mci = logicalStructureHandler.addTextContentItem(ptr); + PDFStructElem structElem = (PDFStructElem) getContext().getStructureTreeElement(); + MarkedContentInfo mci = logicalStructureHandler.addTextContentItem(structElem); if (generator.getTextUtil().isInTextObject()) { generator.separateTextElements(mci.tag, mci.mcid); } diff --git a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java index 8ec10b209..3b5b00c33 100644 --- a/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java +++ b/src/java/org/apache/fop/render/pdf/PDFStructureTreeBuilder.java @@ -24,10 +24,10 @@ import java.util.Locale; import org.xml.sax.Attributes; +import org.apache.fop.accessibility.StructureTreeElement; import org.apache.fop.accessibility.StructureTreeEventHandler; import org.apache.fop.events.EventBroadcaster; import org.apache.fop.fo.extensions.ExtensionElementMapping; -import org.apache.fop.fo.extensions.InternalElementMapping; import org.apache.fop.pdf.PDFFactory; import org.apache.fop.pdf.PDFStructElem; @@ -61,33 +61,64 @@ class PDFStructureTreeBuilder implements StructureTreeEventHandler { public void endPageSequence() { } - public void startNode(String name, Attributes attributes) { + public StructureTreeElement startNode(String name, Attributes attributes) { PDFStructElem parent = ancestors.getFirst(); String role = attributes.getValue("role"); - PDFStructElem created = pdfFactory.makeStructureElement( - FOToPDFRoleMap.mapFormattingObject(name, role, parent, - eventBroadcaster), parent); - if (ancestors.size() <= 2) { // TODO remove - parent.addKid(created); - } - String ptr = attributes.getValue(InternalElementMapping.URI, "ptr"); - if (ptr != null) { - logicalStructureHandler.addStructurePointer(ptr, created); + PDFStructElem created; + created = pdfFactory.makeStructureElement( + FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster), parent); + parent.addKid(created); + ancestors.addFirst(created); + return created; + } + + public void endNode(String name) { + removeFirstAncestor(); + } + + private void removeFirstAncestor() { + ancestors.removeFirst(); + } + + public StructureTreeElement startImageNode(String name, Attributes attributes) { + PDFStructElem parent = ancestors.getFirst(); + String role = attributes.getValue("role"); + PDFStructElem created; + created = pdfFactory.makeStructureElement( + FOToPDFRoleMap.mapFormattingObject(name, role, parent, eventBroadcaster), parent); + parent.addKid(created); + String altTextNode = attributes.getValue(ExtensionElementMapping.URI, "alt-text"); + if (altTextNode != null) { + created.put("Alt", altTextNode); + } else { + created.put("Alt", "No alternate text specified"); } + ancestors.addFirst(created); + return created; + } + + public void endImageNode(String name) { + removeFirstAncestor(); + } - if (name.equals("external-graphic") || name.equals("instream-foreign-object")) { - String altTextNode = attributes.getValue(ExtensionElementMapping.URI, "alt-text"); - if (altTextNode != null) { - created.put("Alt", altTextNode); - } else { - created.put("Alt", "No alternate text specified"); - } + public StructureTreeElement startReferencedNode(String name, Attributes attributes) { + PDFStructElem parent = ancestors.getFirst(); + String role = attributes.getValue("role"); + PDFStructElem created; + if ("#PCDATA".equals(name)) { + created = new PDFStructElem.Placeholder(parent, name); + } else { + created = pdfFactory.makeStructureElement( + FOToPDFRoleMap.mapFormattingObject(name, role, parent, + eventBroadcaster), parent); } + parent.addKid(created); ancestors.addFirst(created); + return created; } - public void endNode(String name) { - ancestors.removeFirst(); + public void endReferencedNode(String name) { + removeFirstAncestor(); } } diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 8878b5d24..a3e3db461 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -117,13 +117,13 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFootnote; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfHyperLink; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfList; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem; +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem.RtfListItemLabel; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfPage; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun; -import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem.RtfListItemLabel; import org.apache.fop.render.rtf.rtflib.tools.BuilderContext; import org.apache.fop.render.rtf.rtflib.tools.PercentContext; import org.apache.fop.render.rtf.rtflib.tools.TableContext; @@ -1362,11 +1362,9 @@ public class RTFHandler extends FOEventHandler { /** * @param text FOText object - * @param data Array of characters to process. - * @param start Offset for characters to process. - * @param length Portion of array to process. + * @param characters CharSequence of the characters to process. */ - public void text(FOText text, char[] data, int start, int length) { + public void text(FOText text, CharSequence characters) { if (bDefer) { return; } @@ -1381,7 +1379,7 @@ public class RTFHandler extends FOEventHandler { = TextAttributesConverter.convertCharacterAttributes(text); textrun.pushInlineAttributes(rtfAttr); - textrun.addString(new String(data, start, length - start)); + textrun.addString(characters.toString()); textrun.popInlineAttributes(); } catch (IOException ioe) { handleIOTrouble(ioe); @@ -1558,7 +1556,7 @@ public class RTFHandler extends FOEventHandler { } else if (foNode instanceof FOText) { if (bStart) { FOText text = (FOText) foNode; - text(text, text.getCharArray(), 0, text.length()); + text(text, text.getCharSequence()); } } else if (foNode instanceof Character) { if (bStart) { diff --git a/test/accessibility/background-image_jpg_repeat.fo b/test/accessibility/background-image_jpg_repeat.fo index 2c8f7f66d..727162e49 100644 --- a/test/accessibility/background-image_jpg_repeat.fo +++ b/test/accessibility/background-image_jpg_repeat.fo @@ -16,14 +16,14 @@ limitations under the License. --> - + - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/background-image_jpg_single.fo b/test/accessibility/background-image_jpg_single.fo index 2250c24e2..335353e03 100644 --- a/test/accessibility/background-image_jpg_single.fo +++ b/test/accessibility/background-image_jpg_single.fo @@ -16,7 +16,7 @@ limitations under the License. --> - + @@ -25,7 +25,7 @@ background-position-vertical="50%"/> - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/background-image_png_repeat.fo b/test/accessibility/background-image_png_repeat.fo index 7506c0f2b..5e4a8ba0d 100644 --- a/test/accessibility/background-image_png_repeat.fo +++ b/test/accessibility/background-image_png_repeat.fo @@ -16,14 +16,14 @@ limitations under the License. --> - + - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/background-image_png_single.fo b/test/accessibility/background-image_png_single.fo index 1f60e9411..90067ec53 100644 --- a/test/accessibility/background-image_png_single.fo +++ b/test/accessibility/background-image_png_single.fo @@ -16,7 +16,7 @@ limitations under the License. --> - + @@ -25,7 +25,7 @@ background-position-vertical="50%"/> - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/background-image_svg_repeat.fo b/test/accessibility/background-image_svg_repeat.fo index 6e71409d0..02520b6cf 100644 --- a/test/accessibility/background-image_svg_repeat.fo +++ b/test/accessibility/background-image_svg_repeat.fo @@ -16,14 +16,14 @@ limitations under the License. --> - + - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/background-image_svg_single.fo b/test/accessibility/background-image_svg_single.fo index 9dc67c86c..3029f32ec 100644 --- a/test/accessibility/background-image_svg_single.fo +++ b/test/accessibility/background-image_svg_single.fo @@ -16,7 +16,7 @@ limitations under the License. --> - + @@ -25,7 +25,7 @@ background-position-vertical="50%"/> - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/complete.fo b/test/accessibility/complete.fo index 81df372b5..75684750c 100644 --- a/test/accessibility/complete.fo +++ b/test/accessibility/complete.fo @@ -17,7 +17,7 @@ --> + xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" language="en" country="GB"> @@ -25,7 +25,7 @@ - + This is the page headerPage @@ -117,7 +117,7 @@ And now we are going to see how a second page sequence is handled. - + This is the page headerPage diff --git a/test/accessibility/image_jpg.fo b/test/accessibility/image_jpg.fo index be0e24bee..5fe36f61a 100644 --- a/test/accessibility/image_jpg.fo +++ b/test/accessibility/image_jpg.fo @@ -17,14 +17,14 @@ --> + xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" language="en" country="GB"> - + This document contains an image in the JPEG format: + xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" language="en" country="GB"> - + This document contains an image in the PNG format: + xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" language="en" country="GB"> - + This document contains an image in the SVG format: + xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" language="en" country="GB"> - + This document contains an image in the WMF format: - + - + This is a text followed by a leader with leader-pattern=​"use-content", the diff --git a/test/accessibility/links.fo b/test/accessibility/links.fo index 66f0f66f4..36250e332 100644 --- a/test/accessibility/links.fo +++ b/test/accessibility/links.fo @@ -17,14 +17,14 @@ --> + xmlns:fox="http://xmlgraphics.apache.org/fop/extensions" language="en" country="GB"> - + This is a link to the next diff --git a/test/accessibility/pdf/background-image_jpg_repeat.pdf b/test/accessibility/pdf/background-image_jpg_repeat.pdf index 97b304c53..221761757 100644 Binary files a/test/accessibility/pdf/background-image_jpg_repeat.pdf and b/test/accessibility/pdf/background-image_jpg_repeat.pdf differ diff --git a/test/accessibility/pdf/background-image_jpg_single.pdf b/test/accessibility/pdf/background-image_jpg_single.pdf index e1d7f9340..232afdd05 100644 Binary files a/test/accessibility/pdf/background-image_jpg_single.pdf and b/test/accessibility/pdf/background-image_jpg_single.pdf differ diff --git a/test/accessibility/pdf/background-image_png_repeat.pdf b/test/accessibility/pdf/background-image_png_repeat.pdf index 9f5e7ff12..52da4020a 100644 Binary files a/test/accessibility/pdf/background-image_png_repeat.pdf and b/test/accessibility/pdf/background-image_png_repeat.pdf differ diff --git a/test/accessibility/pdf/background-image_png_single.pdf b/test/accessibility/pdf/background-image_png_single.pdf index 81156e18d..356e4885c 100644 Binary files a/test/accessibility/pdf/background-image_png_single.pdf and b/test/accessibility/pdf/background-image_png_single.pdf differ diff --git a/test/accessibility/pdf/background-image_svg_repeat.pdf b/test/accessibility/pdf/background-image_svg_repeat.pdf index 0e438958d..0bce2404d 100644 Binary files a/test/accessibility/pdf/background-image_svg_repeat.pdf and b/test/accessibility/pdf/background-image_svg_repeat.pdf differ diff --git a/test/accessibility/pdf/background-image_svg_single.pdf b/test/accessibility/pdf/background-image_svg_single.pdf index a46b6df38..3e4afcdcf 100644 Binary files a/test/accessibility/pdf/background-image_svg_single.pdf and b/test/accessibility/pdf/background-image_svg_single.pdf differ diff --git a/test/accessibility/pdf/complete.pdf b/test/accessibility/pdf/complete.pdf index a42bb2a97..cffb9e2cb 100644 Binary files a/test/accessibility/pdf/complete.pdf and b/test/accessibility/pdf/complete.pdf differ diff --git a/test/accessibility/pdf/image_jpg.pdf b/test/accessibility/pdf/image_jpg.pdf index 6b70c268d..cb004bbd2 100644 Binary files a/test/accessibility/pdf/image_jpg.pdf and b/test/accessibility/pdf/image_jpg.pdf differ diff --git a/test/accessibility/pdf/image_png.pdf b/test/accessibility/pdf/image_png.pdf index d63db6708..c3289374f 100644 Binary files a/test/accessibility/pdf/image_png.pdf and b/test/accessibility/pdf/image_png.pdf differ diff --git a/test/accessibility/pdf/image_svg.pdf b/test/accessibility/pdf/image_svg.pdf index 94720f564..c3fce5b0e 100644 Binary files a/test/accessibility/pdf/image_svg.pdf and b/test/accessibility/pdf/image_svg.pdf differ diff --git a/test/accessibility/pdf/image_wmf.pdf b/test/accessibility/pdf/image_wmf.pdf index 4b6eb0827..b9ec8c55a 100644 Binary files a/test/accessibility/pdf/image_wmf.pdf and b/test/accessibility/pdf/image_wmf.pdf differ diff --git a/test/accessibility/pdf/leader.pdf b/test/accessibility/pdf/leader.pdf index 4a6c25253..c7432e751 100644 Binary files a/test/accessibility/pdf/leader.pdf and b/test/accessibility/pdf/leader.pdf differ diff --git a/test/accessibility/pdf/links.pdf b/test/accessibility/pdf/links.pdf index b8d4e3be3..91d7c2592 100644 Binary files a/test/accessibility/pdf/links.pdf and b/test/accessibility/pdf/links.pdf differ diff --git a/test/accessibility/pdf/role.pdf b/test/accessibility/pdf/role.pdf index ec5d5f536..acb435027 100644 Binary files a/test/accessibility/pdf/role.pdf and b/test/accessibility/pdf/role.pdf differ diff --git a/test/accessibility/pdf/role_non-standard.pdf b/test/accessibility/pdf/role_non-standard.pdf index d90693066..fcf614ed1 100644 Binary files a/test/accessibility/pdf/role_non-standard.pdf and b/test/accessibility/pdf/role_non-standard.pdf differ diff --git a/test/accessibility/pdf/text_1.pdf b/test/accessibility/pdf/text_1.pdf index 0b1e1ee9f..596419c9d 100644 Binary files a/test/accessibility/pdf/text_1.pdf and b/test/accessibility/pdf/text_1.pdf differ diff --git a/test/accessibility/pdf/text_2.pdf b/test/accessibility/pdf/text_2.pdf index 3330cc902..19fff21a4 100644 Binary files a/test/accessibility/pdf/text_2.pdf and b/test/accessibility/pdf/text_2.pdf differ diff --git a/test/accessibility/pdf/text_font-embedding.pdf b/test/accessibility/pdf/text_font-embedding.pdf index a268dbb63..0288449d5 100644 Binary files a/test/accessibility/pdf/text_font-embedding.pdf and b/test/accessibility/pdf/text_font-embedding.pdf differ diff --git a/test/accessibility/role.fo b/test/accessibility/role.fo index e284cde9c..ced8a4d44 100644 --- a/test/accessibility/role.fo +++ b/test/accessibility/role.fo @@ -16,14 +16,14 @@ limitations under the License. --> - + - + - + - + - + - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/text_2.fo b/test/accessibility/text_2.fo index 5eff059b6..f5693110e 100644 --- a/test/accessibility/text_2.fo +++ b/test/accessibility/text_2.fo @@ -16,14 +16,14 @@ limitations under the License. --> - + - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/accessibility/text_font-embedding.fo b/test/accessibility/text_font-embedding.fo index 1d3abe027..10c1c99d9 100644 --- a/test/accessibility/text_font-embedding.fo +++ b/test/accessibility/text_font-embedding.fo @@ -16,14 +16,14 @@ limitations under the License. --> - + - + Apache FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application diff --git a/test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java b/test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java deleted file mode 100644 index f8719edd6..000000000 --- a/test/java/org/apache/fop/accessibility/FO2StructureTreeConverterTestCase.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* $Id$ */ - -package org.apache.fop.accessibility; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.io.InputStream; - -import javax.xml.transform.Result; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.sax.SAXTransformerFactory; -import javax.xml.transform.sax.TransformerHandler; -import javax.xml.transform.stream.StreamSource; - -import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.Difference; -import org.custommonkey.xmlunit.DifferenceConstants; -import org.custommonkey.xmlunit.DifferenceListener; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; - -import org.apache.fop.apps.FOPException; -import org.apache.fop.apps.FOUserAgent; -import org.apache.fop.fo.FODocumentParser; -import org.apache.fop.fo.FODocumentParser.FOEventHandlerFactory; -import org.apache.fop.fo.FOEventHandler; -import org.apache.fop.fo.LoadingException; -import org.apache.fop.fotreetest.DummyFOEventHandler; - -public class FO2StructureTreeConverterTestCase { - - private static class IgnoringPtrDifferenceListener implements DifferenceListener { - - public int differenceFound(Difference difference) { - switch (difference.getId()) { - case DifferenceConstants.ELEMENT_NUM_ATTRIBUTES_ID: - return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR; - case DifferenceConstants.ATTR_NAME_NOT_FOUND_ID: - String additionalAttribute = difference.getTestNodeDetail().getValue(); - if (additionalAttribute.equals("ptr")) { - return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR; - } else { - return RETURN_ACCEPT_DIFFERENCE; - } - default: - return RETURN_ACCEPT_DIFFERENCE; - } - } - - public void skippedComparison(Node control, Node test) { - throw new UnsupportedOperationException("Not implemented"); - } - } - - private static final String STRUCTURE_TREE_SEQUENCE_NAME = "structure-tree-sequence"; - - @Test - public void testConverter() throws Exception { - DOMResult expectedStructureTree = loadExpectedStructureTree(); - DOMResult actualStructureTree = buildActualStructureTree(); - final Diff diff = createDiff(expectedStructureTree, actualStructureTree); - assertTrue(diff.toString(), diff.similar()); - } - - private static DOMResult loadExpectedStructureTree() { - DOMResult expectedStructureTree = new DOMResult(); - runXSLT(getXsltInputStream(), getFoInputStream(), expectedStructureTree); - return expectedStructureTree; - } - - private static InputStream getXsltInputStream() { - return FO2StructureTreeConverterTestCase.class.getResourceAsStream("foToIfStructureTree.xsl"); - } - - private static InputStream getFoInputStream() { - return FO2StructureTreeConverterTestCase.class.getResourceAsStream( - "/org/apache/fop/fo/complete_document.fo"); - } - - private static void runXSLT(InputStream xslt, InputStream doc, Result result) { - Source fo = new StreamSource(doc); - try { - Transformer transformer = TransformerFactory.newInstance() - .newTransformer(new StreamSource(xslt)); - transformer.transform(fo, result); - } catch (TransformerConfigurationException e) { - throw new RuntimeException(e); - } catch (TransformerException e) { - throw new RuntimeException(e); - } finally { - closeStream(xslt); - closeStream(doc); - } - } - - private static void closeStream(InputStream stream) { - try { - stream.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private static DOMResult buildActualStructureTree() throws Exception { - DOMResult actualStructureTree = new DOMResult(); - createStructureTreeFromDocument(getFoInputStream(), actualStructureTree); - return actualStructureTree; - } - - private static void createStructureTreeFromDocument(InputStream foInputStream, - DOMResult domResult) throws Exception { - TransformerHandler tHandler = createTransformerHandler(domResult); - startStructureTreeSequence(tHandler); - StructureTreeEventHandler structureTreeEventHandler - = StructureTree2SAXEventAdapter.newInstance(tHandler); - FODocumentParser documentParser = createDocumentParser(structureTreeEventHandler); - FOUserAgent userAgent = createFOUserAgent(documentParser); - parseDocument(foInputStream, documentParser, userAgent); - endStructureTreeSequence(tHandler); - } - - private static TransformerHandler createTransformerHandler(DOMResult domResult) - throws TransformerConfigurationException, TransformerFactoryConfigurationError { - SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); - TransformerHandler transformerHandler = factory.newTransformerHandler(); - transformerHandler.setResult(domResult); - return transformerHandler; - } - - private static void startStructureTreeSequence(TransformerHandler tHandler) throws SAXException { - tHandler.startDocument(); - tHandler.startElement("", STRUCTURE_TREE_SEQUENCE_NAME, STRUCTURE_TREE_SEQUENCE_NAME, - new AttributesImpl()); - } - - private static FODocumentParser createDocumentParser( - final StructureTreeEventHandler structureTreeEventHandler) { - return FODocumentParser.newInstance(new FOEventHandlerFactory() { - public FOEventHandler newFOEventHandler(FOUserAgent foUserAgent) { - return new FO2StructureTreeConverter(structureTreeEventHandler, - new DummyFOEventHandler(foUserAgent)); - } - }); - } - - private static FOUserAgent createFOUserAgent(FODocumentParser documentParser) { - FOUserAgent userAgent = documentParser.createFOUserAgent(); - userAgent.setAccessibility(true); - return userAgent; - } - - private static void parseDocument(InputStream foInputStream, FODocumentParser documentParser, - FOUserAgent userAgent) throws FOPException, LoadingException { - try { - documentParser.parse(foInputStream, userAgent); - } finally { - closeStream(foInputStream); - } - } - - private static void endStructureTreeSequence(TransformerHandler tHandler) throws SAXException { - tHandler.endElement("", STRUCTURE_TREE_SEQUENCE_NAME, STRUCTURE_TREE_SEQUENCE_NAME); - tHandler.endDocument(); - } - - private static Diff createDiff(DOMResult expected, DOMResult actual) { - Diff diff = new Diff(getDocument(expected), getDocument(actual)); - diff.overrideDifferenceListener(new IgnoringPtrDifferenceListener()); - return diff; - } - - private static Document getDocument(DOMResult result) { - return (Document) result.getNode(); - } -} diff --git a/test/java/org/apache/fop/accessibility/fo/DOMResultUtil.java b/test/java/org/apache/fop/accessibility/fo/DOMResultUtil.java new file mode 100644 index 000000000..5b4e264f2 --- /dev/null +++ b/test/java/org/apache/fop/accessibility/fo/DOMResultUtil.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.accessibility.fo; + +import java.io.File; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +/** + * Utility class to stream an instance of {@link DOMResult} into a file. May be + * useful for debugging. + */ +final class DOMResultUtil { + + private DOMResultUtil() { + } + + /** + * Streams the given result into a file of the given name. + * + * @param result the result of a transformation + * @param filename name of the file into which to stream the result + * @throws TransformerException if a problem occurs when streaming + */ + public static void streamToFile(DOMResult result, String filename) throws TransformerException { + DOMSource source = new DOMSource(result.getNode()); + TransformerFactory tFactory = TransformerFactory.newInstance(); + Transformer transformer = tFactory.newTransformer(); + transformer.transform(source, new StreamResult(new File(filename))); + } + +} diff --git a/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java new file mode 100644 index 000000000..9c53bdde3 --- /dev/null +++ b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id$ */ + +package org.apache.fop.accessibility.fo; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.custommonkey.xmlunit.Diff; +import org.junit.Test; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + +import org.apache.fop.accessibility.StructureTree2SAXEventAdapter; +import org.apache.fop.accessibility.StructureTreeEventHandler; +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.fo.FODocumentParser; +import org.apache.fop.fo.FODocumentParser.FOEventHandlerFactory; +import org.apache.fop.fo.FOEventHandler; +import org.apache.fop.fo.LoadingException; +import org.apache.fop.fotreetest.DummyFOEventHandler; + +public class FO2StructureTreeConverterTestCase { + + private interface FOLoader { + + InputStream getFoInputStream(); + } + + private static final String STRUCTURE_TREE_SEQUENCE_NAME = "structure-tree-sequence"; + + private FOLoader foLoader; + + @Test + public void testCompleteDocument() throws Exception { + foLoader = new FOLoader() { + public InputStream getFoInputStream() { + return getResource("/org/apache/fop/fo/complete_document.fo"); + } + }; + testConverter(); + } + + @Test + public void testTableFooters() throws Exception { + foLoader = new FOLoader() { + public InputStream getFoInputStream() { + return getResource("table-footers.fo"); + } + }; + testConverter(); + } + + @Test + public void testCompleteContentWrappedInTableFooter() throws Exception { + Source xslt = new StreamSource(getResource("wrapCompleteDocumentInTableFooter.xsl")); + Transformer transformer = createTransformer(xslt); + InputStream originalFO = getResource("/org/apache/fop/fo/complete_document.fo"); + ByteArrayOutputStream transformedFoOutput = new ByteArrayOutputStream(); + transformer.transform(new StreamSource(originalFO), new StreamResult(transformedFoOutput)); + final byte[] transformedFoOutputBytes = transformedFoOutput.toByteArray(); + foLoader = new FOLoader() { + public InputStream getFoInputStream() { + return new ByteArrayInputStream(transformedFoOutputBytes); + } + }; + testConverter(); + } + + private Transformer createTransformer(Source xslt) throws TransformerFactoryConfigurationError, + TransformerConfigurationException { + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + return transformerFactory.newTransformer(xslt); + } + + private static InputStream getResource(String name) { + return FO2StructureTreeConverterTestCase.class.getResourceAsStream(name); + } + + private void testConverter() throws Exception { + DOMResult expectedStructureTree = loadExpectedStructureTree(); + DOMResult actualStructureTree = buildActualStructureTree(); + final Diff diff = createDiff(expectedStructureTree, actualStructureTree); + assertTrue(diff.toString(), diff.identical()); + } + + private DOMResult loadExpectedStructureTree() { + DOMResult expectedStructureTree = new DOMResult(); + InputStream xslt = getResource("fo2StructureTree.xsl"); + runXSLT(xslt, foLoader.getFoInputStream(), expectedStructureTree); + return expectedStructureTree; + } + + private static void runXSLT(InputStream xslt, InputStream doc, Result result) { + Source fo = new StreamSource(doc); + try { + Transformer transformer = TransformerFactory.newInstance() + .newTransformer(new StreamSource(xslt)); + transformer.transform(fo, result); + } catch (TransformerConfigurationException e) { + throw new RuntimeException(e); + } catch (TransformerException e) { + throw new RuntimeException(e); + } finally { + closeStream(xslt); + closeStream(doc); + } + } + + private static void closeStream(InputStream stream) { + try { + stream.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private DOMResult buildActualStructureTree() throws Exception { + DOMResult actualStructureTree = new DOMResult(); + createStructureTreeFromDocument(foLoader.getFoInputStream(), actualStructureTree); + return actualStructureTree; + } + + private static void createStructureTreeFromDocument(InputStream foInputStream, + Result result) throws Exception { + TransformerHandler tHandler = createTransformerHandler(result); + startStructureTreeSequence(tHandler); + StructureTreeEventHandler structureTreeEventHandler + = StructureTree2SAXEventAdapter.newInstance(tHandler); + FODocumentParser documentParser = createDocumentParser(structureTreeEventHandler); + FOUserAgent userAgent = createFOUserAgent(documentParser); + parseDocument(foInputStream, documentParser, userAgent); + endStructureTreeSequence(tHandler); + } + + private static TransformerHandler createTransformerHandler(Result domResult) + throws TransformerConfigurationException, TransformerFactoryConfigurationError { + SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); + TransformerHandler transformerHandler = factory.newTransformerHandler(); + transformerHandler.setResult(domResult); + return transformerHandler; + } + + private static void startStructureTreeSequence(TransformerHandler tHandler) throws SAXException { + tHandler.startDocument(); + tHandler.startElement("", STRUCTURE_TREE_SEQUENCE_NAME, STRUCTURE_TREE_SEQUENCE_NAME, + new AttributesImpl()); + } + + private static FODocumentParser createDocumentParser( + final StructureTreeEventHandler structureTreeEventHandler) { + return FODocumentParser.newInstance(new FOEventHandlerFactory() { + public FOEventHandler newFOEventHandler(FOUserAgent foUserAgent) { + return new FO2StructureTreeConverter(structureTreeEventHandler, + new DummyFOEventHandler(foUserAgent)); + } + }); + } + + private static FOUserAgent createFOUserAgent(FODocumentParser documentParser) { + FOUserAgent userAgent = documentParser.createFOUserAgent(); + userAgent.setAccessibility(true); + return userAgent; + } + + private static void parseDocument(InputStream foInputStream, FODocumentParser documentParser, + FOUserAgent userAgent) throws FOPException, LoadingException { + try { + documentParser.parse(foInputStream, userAgent); + } finally { + closeStream(foInputStream); + } + } + + private static void endStructureTreeSequence(TransformerHandler tHandler) throws SAXException { + tHandler.endElement("", STRUCTURE_TREE_SEQUENCE_NAME, STRUCTURE_TREE_SEQUENCE_NAME); + tHandler.endDocument(); + } + + private static Diff createDiff(DOMResult expected, DOMResult actual) { + Diff diff = new Diff(getDocument(expected), getDocument(actual)); + return diff; + } + + private static Document getDocument(DOMResult result) { + return (Document) result.getNode(); + } +} diff --git a/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl new file mode 100644 index 000000000..ce326f3b1 --- /dev/null +++ b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/java/org/apache/fop/accessibility/fo/table-footers.fo b/test/java/org/apache/fop/accessibility/fo/table-footers.fo new file mode 100644 index 000000000..6dcb9b68d --- /dev/null +++ b/test/java/org/apache/fop/accessibility/fo/table-footers.fo @@ -0,0 +1,195 @@ + + + + + + + + + + + + + Start Outer Header + + + + Inner Header 1.1 + + + Inner Header 1.2 + + + + + Inner Footer 1.1 + + + Inner Footer 1.2 + + + + + + Inner Body 1.1 + + + Inner Body 1.2 + + + + + Inner Body 2.1 + + + Inner Body 2.2 + + + + + End Outer Header + + + + + Start Outer Footer + + + + Inner Header 1.1 + + + Inner Header 1.2 + + + + + Start Inner Footer 1.1 + + + + Inner Inner Header 1.1 + + + Inner Inner Header 1.2 + + + + + Inner Inner Footer 1.1 + + + Inner Inner Footer 1.2 + + + + + + Inner Inner Body 1.1 + + + Inner Inner Body 1.2 + + + + + Inner Inner Body 2.1 + + + Inner Inner Body 2.2 + + + + + End Inner Footer 1.1 + + + Inner Footer 1.2 + + + + + + Inner Body 1.1 + + + Inner Body 1.2 + + + + + Inner Body 2.1 + + + Inner Body 2.2 + + + + + End Outer Footer + + + + + + Outer Body Cell 1 + + + + + Start Outer Body Cell 2 + + + + Inner Footer 1.1 + + + Inner Footer 1.2 + + + + + Inner Header 1.1 + + + Inner Header 1.2 + + + + + + Inner Body 1.1 + + + Inner Body 1.2 + + + + + Inner Body 2.1 + + + Inner Body 2.2 + + + + + End Outer Body Cell 2 + + + + + + + diff --git a/test/java/org/apache/fop/accessibility/fo/wrapCompleteDocumentInTableFooter.xsl b/test/java/org/apache/fop/accessibility/fo/wrapCompleteDocumentInTableFooter.xsl new file mode 100644 index 000000000..9608b2fb9 --- /dev/null +++ b/test/java/org/apache/fop/accessibility/fo/wrapCompleteDocumentInTableFooter.xsl @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The content below is in the table footer. + + + + + + + diff --git a/test/java/org/apache/fop/accessibility/fo2StructureTree.xsl b/test/java/org/apache/fop/accessibility/fo2StructureTree.xsl deleted file mode 100644 index 5c9c5615c..000000000 --- a/test/java/org/apache/fop/accessibility/fo2StructureTree.xsl +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java b/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java index d7db7db7f..65c6b25a6 100644 --- a/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java +++ b/test/java/org/apache/fop/render/intermediate/IFStructureTreeBuilderTestCase.java @@ -85,7 +85,7 @@ public class IFStructureTreeBuilderTestCase { @Test public void startNode() throws Exception { - final String[] attributes = {"ptr", "1"}; + final String[] attributes = {"struct-id", "1"}; final String nodeName = "block"; final ContentHandler handler = mock(ContentHandler.class); -- cgit v1.2.3