From 0a05a9f1295e06d158bba4bb7e86f96d4bd845a7 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 16 Oct 2009 15:53:13 +0000 Subject: [PATCH] Route message for missing alt-text property through event notification system git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_Accessibility@825964 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/events/EventFormatter.xml | 1 + .../apache/fop/fo/FOValidationEventProducer.java | 13 ++++++++++++- .../fop/fo/extensions/ExtensionElementMapping.java | 2 +- .../org/apache/fop/fo/flow/AbstractGraphics.java | 6 ++++++ .../fop/render/pdf/PDFLogicalStructureHandler.java | 3 --- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/fop/events/EventFormatter.xml b/src/java/org/apache/fop/events/EventFormatter.xml index 147744a0d..7561f1548 100644 --- a/src/java/org/apache/fop/events/EventFormatter.xml +++ b/src/java/org/apache/fop/events/EventFormatter.xml @@ -105,4 +105,5 @@ Any reference to it will be considered a reference to the first occurrence in th Font "{requested}" not found. Substituting with "{effective}". Unable to load font file: {fontURL}.[ Reason: {e}] Glyph "{ch}" (0x{ch,hex}[, {ch,glyph-name}]) not available in font "{fontName}". + Alternate text is missing on {foElement}.{{locator}} diff --git a/src/java/org/apache/fop/fo/FOValidationEventProducer.java b/src/java/org/apache/fop/fo/FOValidationEventProducer.java index 889bf706a..ff005b1b4 100644 --- a/src/java/org/apache/fop/fo/FOValidationEventProducer.java +++ b/src/java/org/apache/fop/fo/FOValidationEventProducer.java @@ -36,7 +36,9 @@ public interface FOValidationEventProducer extends EventProducer { /** * Provider class for the event producer. */ - class Provider { + final class Provider { + + private Provider() { } /** * Returns an event producer. @@ -354,4 +356,13 @@ public interface FOValidationEventProducer extends EventProducer { void unknownFormattingObject(Object source, String elementName, QName offendingNode, Locator loc); + /** + * Alternate text is missing for a graphic element. + * + * @param source the event source + * @param foElement name of the element (external-graphic or instream-foreign-object) + * @param loc the location of the error or null + * @event.severity WARN + */ + void altTextMissing(Object source, String foElement, Locator loc); } diff --git a/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java b/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java index ee2b3886e..f9a556167 100644 --- a/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java +++ b/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java @@ -47,7 +47,7 @@ public class ExtensionElementMapping extends ElementMapping { propertyAttributes.add("internal-destination"); propertyAttributes.add("disable-column-balancing"); //These are FOP's extension properties for accessibility - propertyAttributes.add("alt"); + propertyAttributes.add("alt-text"); } /** diff --git a/src/java/org/apache/fop/fo/flow/AbstractGraphics.java b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java index bd4152295..eeb06c1df 100644 --- a/src/java/org/apache/fop/fo/flow/AbstractGraphics.java +++ b/src/java/org/apache/fop/fo/flow/AbstractGraphics.java @@ -106,6 +106,12 @@ public abstract class AbstractGraphics extends FObj scaling = pList.get(PR_SCALING).getEnum(); textAlign = pList.get(PR_TEXT_ALIGN).getEnum(); width = pList.get(PR_WIDTH).getLength(); + if (getUserAgent().isAccessibilityEnabled()) { + String altText = pList.get(PR_X_ALT_TEXT).getString(); + if (altText.equals("")) { + getFOValidationEventProducer().altTextMissing(this, getLocalName(), getLocator()); + } + } } /** diff --git a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java index 2313431f0..cfa0719ea 100644 --- a/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java +++ b/src/java/org/apache/fop/render/pdf/PDFLogicalStructureHandler.java @@ -163,9 +163,6 @@ class PDFLogicalStructureHandler { if (altTextNode != null) { structElem.put("Alt", altTextNode.getNodeValue()); } else { - // TODO route that to event notification system -// log.warn("fo:" + s -// + " requires an alternative text attribute fox:alt-text for accessibility"); structElem.put("Alt", "No alternate text specified"); } } -- 2.39.5