Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The image alternative text is not used when generating PDF with Apache FOP formatter #2850

Closed
radu-pisoi opened this issue Nov 24, 2017 · 6 comments
Labels
accessibility bug priority/high High severity or high priority issue
Milestone

Comments

@radu-pisoi
Copy link

Actual Behavior

The image alternate text is not processed by the PDF transformation when generate the XSL-FO file. I've used the Apache FOP processor.

Conforming with Apache FOP documentation, images must have an alternate text fox:alt-text
extension attribute (in the fox namespace) on fo:external-graphic and fo:instream-foreign-object to
specify a short text describing the image.

See: https://xmlgraphics.apache.org/fop/2.2/accessibility.html

Possible Solution

Override the next template:
<xsl:template match="*" mode="placeImage">
Location: org.dita.pdf2/xsl/fo/topic.xsl

from org.dita.pdf2.fop plugin:

<!--
	Override the original XSLT template to make images accessible.
	
	Conforming with Apache FOP documentation, images must have an alternate text fox:alt-text 
	extension attribute (in the fox namespace) on fo:external-graphic and fo:instream-foreign-object to 
	specify a short text describing the image.
	
	See: https://xmlgraphics.apache.org/fop/2.2/accessibility.html
-->
<xsl:template match="*" mode="placeImage">
	<xsl:param name="imageAlign"/>
	<xsl:param name="href"/>
	<xsl:param name="height" as="xs:string?"/>
	<xsl:param name="width" as="xs:string?"/>
	
	<!--
		Call the default processing to get an fo:external-graphic. 
	-->
	<xsl:variable name="external-graphic">
		<xsl:next-match>
			<xsl:with-param name="imageAlign" select="$imageAlign"/>
			<xsl:with-param name="href" select="$href"/>
			<xsl:with-param name="height" select="$height"/>
			<xsl:with-param name="width" select="$width"/>
		</xsl:next-match>    
	</xsl:variable>
	
	<!--
		Add fox:alt-text attribute if alt attribute or element is present.  
	-->
	<xsl:apply-templates select="$external-graphic" mode="fix-image-alt">
		<xsl:with-param name="ctx" select="." tunnel="yes"/>
	</xsl:apply-templates>
</xsl:template>

<!--
	Add 'fox:alt-text' attribute if image has an alternative text.
-->
<xsl:template match="fo:external-graphic" mode="fix-image-alt">
	<xsl:param name="ctx" tunnel="yes"/>        
	<xsl:copy>
		<xsl:choose>
			<xsl:when test="$ctx/@alt">
				<xsl:attribute name="fox:alt-text" 
					select="$ctx/@alt"/>                    
			</xsl:when>
			
			<xsl:when test="$ctx/alt">
				<xsl:attribute name="fox:alt-text" 
					select="$ctx/alt"/>                    
			</xsl:when>
		</xsl:choose>          
		
		<xsl:apply-templates select="node() | @*" mode="fix-image-alt"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="node() | @*" mode="fix-image-alt">
	<xsl:copy>
		<xsl:apply-templates select="node() | @*" mode="fix-image-alt"/>                            
	</xsl:copy>
</xsl:template>

Steps to Reproduce

Add an image in a topic:
<image href="../../images/Iris_sanguinea.jpg" scale="50" alt="Alternate text"/>

  • DITA-OT version: 2.5.2
  • How did you run DITA-OT?
    oXygen
  • Transformation type:
    PDF
@raducoravu
Copy link
Member

@radu-pisoi tested the changes on Windows, using the narrator embedded in Acrobat Reader (main menu "View->Read out loud" after enabling accessibility in the "fop.xconf".

@robander robander added accessibility bug priority/high High severity or high priority issue labels Nov 27, 2017
@Thiroshini
Copy link

Thiroshini commented Jun 4, 2018

Hi Radu,
Any idea when this bug be fixed ?

Thanks.

Regards,
Thiro

@raducoravu
Copy link
Member

Looks like @robander committed a fix for this in: #2964 so probably this issue could be closed.
That particular pull request is marked for DITA OT 3.1. @robander do you have a timeline for the release of DITA OT 3.1?
I tried to look in the wiki for meeting minutes from 2018 but they are not present there:
https://github.com/dita-ot/docs/wiki

@jelovirt
Copy link
Member

jelovirt commented Jun 4, 2018

@raducoravu 3.1 will be out in beginning of June.

@jelovirt jelovirt added this to the 3.1 milestone Jun 4, 2018
@jelovirt jelovirt closed this as completed Jun 4, 2018
@raducoravu
Copy link
Member

👍

@catrachos
Copy link

catrachos commented Jul 23, 2019

Hey, does this work now in DITA-OT 3.x? I tried today with <image><alt>String</alt></image> using DITA-OT 3.3,3 and it doesn't translate into alt text in the PDF output. I examined topic_fop.xsl and the following does show:

   <xsl:template match="*|@alt" mode="graphicAlternateText">
        <xsl:attribute name="fox:alt-text">
           <xsl:apply-templates select="." mode="text-only"/>
         </xsl:attribute>
     </xsl:template>

I checked and the processor is running through it and the select statement is resolving correctly. But the output doesn't have the alt text. I'd expect alt text to be visible as popup text when I hover the mouse pointer or at least when the Acrobat screen reader reads the content, just as if I had entered the alt text manually in a PDF editor (e.g. MS Word). Neither. Nothing added to the PDF.

To answer my own question, the <accessibility> setting has to be added or configured as true in the fop.xconf file:

<fop version="1.0">
  <accessibility>true</accessibility>
  ...****

See following link: Apache™ FOP: Accessibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility bug priority/high High severity or high priority issue
Projects
None yet
Development

No branches or pull requests

6 participants