From: Vincent Hennebert Date: Tue, 29 May 2012 09:48:03 +0000 (+0000) Subject: Added possibility to treat some content as artifact. X-Git-Tag: fop-1_1rc1^2~1^2~19 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9e1c3f381c661eff5ebb45f3d442b0dc871dd865;p=xmlgraphics-fop.git Added possibility to treat some content as artifact. If any fo:static-content or fo:wrapper element has their 'role' property set to 'artifact', then they and their descendants will be treated as artifacts. Suggested by Martin Koegler as part of Bugzilla #50852 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1343632 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/accessibility/Accessibility.java b/src/java/org/apache/fop/accessibility/Accessibility.java index c842cf43f..88ec6dbdd 100644 --- a/src/java/org/apache/fop/accessibility/Accessibility.java +++ b/src/java/org/apache/fop/accessibility/Accessibility.java @@ -28,6 +28,12 @@ public final class Accessibility { /** Constant string for the rendering options key to enable accessibility features. */ public static final String ACCESSIBILITY = "accessibility"; + /** + * The value to be set on the 'role' property for the element and its descendants to + * be considered as artifacts. + */ + public static final String ROLE_ARTIFACT = "artifact"; + private Accessibility() { } } diff --git a/src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java b/src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java index 47c227e9a..27469d6e0 100644 --- a/src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java +++ b/src/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverter.java @@ -23,6 +23,7 @@ import java.util.Stack; import org.xml.sax.SAXException; +import org.apache.fop.accessibility.Accessibility; import org.apache.fop.accessibility.StructureTreeEventHandler; import org.apache.fop.fo.DelegatingFOEventHandler; import org.apache.fop.fo.FOEventHandler; @@ -57,6 +58,8 @@ 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.CommonAccessibility; +import org.apache.fop.fo.properties.CommonAccessibilityHolder; /** * Allows to create the structure tree of an FO document, by converting FO @@ -355,6 +358,7 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { @Override public void startStatic(StaticContent staticContent) { + handleStartArtifact(staticContent); converter.startStatic(staticContent); super.startStatic(staticContent); } @@ -362,6 +366,7 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { @Override public void endStatic(StaticContent statisContent) { converter.endStatic(statisContent); + handleEndArtifact(statisContent); super.endStatic(statisContent); } @@ -454,6 +459,7 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { @Override public void startWrapper(Wrapper wrapper) { + handleStartArtifact(wrapper); converter.startWrapper(wrapper); super.startWrapper(wrapper); } @@ -461,6 +467,7 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { @Override public void endWrapper(Wrapper wrapper) { converter.endWrapper(wrapper); + handleEndArtifact(wrapper); super.endWrapper(wrapper); } @@ -488,4 +495,22 @@ public class FO2StructureTreeConverter extends DelegatingFOEventHandler { super.endExternalDocument(document); } + private void handleStartArtifact(CommonAccessibilityHolder fobj) { + if (isArtifact(fobj)) { + converters.push(converter); + converter = eventSwallower; + } + } + + private void handleEndArtifact(CommonAccessibilityHolder fobj) { + if (isArtifact(fobj)) { + converter = converters.pop(); + } + } + + private boolean isArtifact(CommonAccessibilityHolder fobj) { + CommonAccessibility accessibility = fobj.getCommonAccessibility(); + return Accessibility.ROLE_ARTIFACT.equalsIgnoreCase(accessibility.getRole()); + } + } diff --git a/src/java/org/apache/fop/fo/flow/Wrapper.java b/src/java/org/apache/fop/fo/flow/Wrapper.java index 1302e3134..0aec7ce16 100644 --- a/src/java/org/apache/fop/fo/flow/Wrapper.java +++ b/src/java/org/apache/fop/fo/flow/Wrapper.java @@ -26,7 +26,10 @@ import org.apache.fop.fo.Constants; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FOText; import org.apache.fop.fo.FObjMixed; +import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.properties.CommonAccessibility; +import org.apache.fop.fo.properties.CommonAccessibilityHolder; /** * Class modelling the @@ -34,13 +37,13 @@ import org.apache.fop.fo.ValidationException; * The fo:wrapper object serves as a property holder for * its child node objects. */ -public class Wrapper extends FObjMixed { - // The value of properties relevant for fo:wrapper. - // End of property values +public class Wrapper extends FObjMixed implements CommonAccessibilityHolder { // used for FO validation private boolean blockOrInlineItemFound = false; + private CommonAccessibility commonAccessibility; + /** * Create a Wrapper instance that is a child of the * given {@link FONode} @@ -51,6 +54,12 @@ public class Wrapper extends FObjMixed { super(parent); } + @Override + public void bind(PropertyList pList) throws FOPException { + super.bind(pList); + commonAccessibility = CommonAccessibility.getInstance(pList); + } + @Override protected void startOfNode() throws FOPException { super.startOfNode(); @@ -136,6 +145,10 @@ public class Wrapper extends FObjMixed { return FO_WRAPPER; } + public CommonAccessibility getCommonAccessibility() { + return commonAccessibility; + } + @Override public boolean isDelimitedTextRangeBoundary ( int boundary ) { return false; diff --git a/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java index 9c53bdde3..863bfe797 100644 --- a/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java +++ b/test/java/org/apache/fop/accessibility/fo/FO2StructureTreeConverterTestCase.java @@ -19,8 +19,6 @@ package org.apache.fop.accessibility.fo; -import static org.junit.Assert.assertTrue; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -45,6 +43,8 @@ import org.w3c.dom.Document; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; +import static org.junit.Assert.assertTrue; + import org.apache.fop.accessibility.StructureTree2SAXEventAdapter; import org.apache.fop.accessibility.StructureTreeEventHandler; import org.apache.fop.apps.FOPException; @@ -102,6 +102,17 @@ public class FO2StructureTreeConverterTestCase { testConverter(); } + @Test + public void testArtifact() throws Exception { + foLoader = new FOLoader() { + + public InputStream getFoInputStream() { + return getResource("artifact.fo"); + } + }; + testConverter(); + } + private Transformer createTransformer(Source xslt) throws TransformerFactoryConfigurationError, TransformerConfigurationException { TransformerFactory transformerFactory = TransformerFactory.newInstance(); diff --git a/test/java/org/apache/fop/accessibility/fo/artifact.fo b/test/java/org/apache/fop/accessibility/fo/artifact.fo new file mode 100644 index 000000000..c3d5fadf3 --- /dev/null +++ b/test/java/org/apache/fop/accessibility/fo/artifact.fo @@ -0,0 +1,97 @@ + + + + + + + + + + + + This piece of text is normal content that should be read out loud by a screen + reader. + + The following content will be treated as artifact: + + + + + A block as artifact. + + + + + Header 1.1 + Header 1.2 + + + Footer 1.1 + Footer 1.2 + + + + Cell 1.1 + Cell 1.2 + + + Cell 2.1 + Cell 2.2 + + + + + + + • + + + Item 1. + + + + + • + + + Item 2. + + + + + • + + + Item 3. + + + + + A block in a nested wrapper. + + + A block in a nested artifact wrapper. + + + Inside a nested wrapper. + An artifact wrapper inside the nested wrapper. + Inside a wrapper inside the artifact wrapper that is inside + the nested wrapper. Outside the wrapper inside the artifact + wrapper that is inside the nested wrapper. + Outside the artifact wrapper. + + + + + + Now we are back to normal content that is part of the logical + structure, should appear in the structure tree and should be read out loud by the screen + reader. + + + + + diff --git a/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl index ce326f3b1..db0dffb14 100644 --- a/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl +++ b/test/java/org/apache/fop/accessibility/fo/fo2StructureTree.xsl @@ -105,6 +105,8 @@ + + diff --git a/test/pdf/accessibility/pdf/role.pdf b/test/pdf/accessibility/pdf/role.pdf index 38fcf1bde..4dfb686c9 100644 Binary files a/test/pdf/accessibility/pdf/role.pdf and b/test/pdf/accessibility/pdf/role.pdf differ diff --git a/test/pdf/accessibility/role.fo b/test/pdf/accessibility/role.fo index 885638592..b94c6ab67 100644 --- a/test/pdf/accessibility/role.fo +++ b/test/pdf/accessibility/role.fo @@ -24,8 +24,8 @@ - - + +