Bug 39561

Summary: Use svg:title, not svg:desc for XHTML img alt attribute [accessibility]
Product: LibreOffice Reporter: Christophe Strobbe <c_strobbe-fdo>
Component: WriterAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: c_strobbe-fdo, detective.conan.1412, rb.henschel, robinson.libreoffice, v_2e
Priority: medium Keywords: difficultyBeginner, easyHack
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Attachments: ODF test file with three images, one with only title, one with only description, one with both
Export of the test file to XHTML
Patch as unified diff file
Patch generated with git diff.

Description Christophe Strobbe 2011-07-26 09:40:34 UTC
In Writer, images (and other objects) can be given a title <svg:title> and a description <svg:description>. When exporting ODT documents to XHTML, the title should end up in the alt attribute of the image element. (<svg:desc> should be handled differently, but I keep that separate).

Steps to reproduce the issue:
1. Create a document in Writer and insert three images; give the first one only a title, give the second one only a description and give the third one both a title and a description. (Process: right-click on each image and go to Description...)
2. Save the file and export it to XHTML.
3. Open the XHTML file in a source code editor and verify that the Title is not available in the alt attribute of the img elements. 

This is easy to fix:
in the stylesheet body.xsl for XHTML export, replace the lines

<xsl:when test="../svg:desc">
  <xsl:value-of select="../svg:desc"/>
</xsl:when>

 with 

<xsl:when test="../svg:title">
  <xsl:value-of select="../svg:title"/>
</xsl:when>

(I did this in my own installation of LibreOffice and it works.)


Notes: 
* In my tests, the <xsl:otherwise> statement that produces a warning when there is no <svg:title> was never triggered.
* The title attribute on HTML img elements is used for tooltips, not for accessible text alternatives.


Additional information from "Open Document Format for Office Applications
(OpenDocument) v1.1", the OASIS standard.

From section 9.2.20: Title and Description:
"The <svg:title> and <svg:desc> elements specify text-only description strings
for graphical objects as specified in ยง5.4 of [SVG].
The <svg:title> element is used as a short accessible name.
(...)
The <svg:desc> element is used for the long description in support of
accessibility.
(...)
See appendix E for guidelines how to use these elements."


So <svg:title> needs to be exported as text alternative in the img element's alt attribute.
Comment 1 Regina Henschel 2011-07-26 11:20:09 UTC
Please attach the original odt-file. I get nothing, which fit to your description. If I insert an image, I get an img-Element and nothing with svg. If I insert a drawing object, for example a rectangle, in an odt-document, I get no element in xhtml at all.

Are you sure, you are exporting to XHTML? Or do you save as HTML?

In case of an image, the xhtml-text is indeed wrong. The alternative text in LO (given in the picture property dialog in the tab 'Option') should go to the alt-attribute, the title in LO should go to the title-attribute and the description in LO should go to a longdesc-attribute in xhtml.
Comment 2 Christophe Strobbe 2011-07-27 02:00:02 UTC
Created attachment 49607 [details]
ODF test file with three images, one with only title, one with only description, one with both
Comment 3 Christophe Strobbe 2011-07-27 02:14:51 UTC
(In reply to comment #1)
> Please attach the original odt-file. I get nothing, which fit to your
> description. If I insert an image, I get an img-Element and nothing with svg.
> If I insert a drawing object, for example a rectangle, in an odt-document, I
> get no element in xhtml at all.

When you create an ODT file following the procedure I described, the image is wrapped in a <draw:frame> element which contains:
* a <draw:image> element for the image itself,
* a <svg:title> element if the image has been given a title,
* a <svg:desc> element if the image has been given a description.
To verify this, unpack the ODT-file with an unzip utility, and view the file 'content.xml' in a source code editor.


> 
> Are you sure, you are exporting to XHTML? Or do you save as HTML?

In Writer, I went to File > Export...; in the Export dialog I chose the option "XHTML (.html,xhtml)".


(When you choose File > Save as... and select "HTML Document (OpenOffice.org Writer) (.html)" in the Save As dialog, you get a different output, and <svg:title> is converted to the alt attribute of the img element. However, this bug is about the XHTML export.)


> 
> In case of an image, the xhtml-text is indeed wrong. The alternative text
> in LO
> (given in the picture property dialog in the tab 'Option') should go to the
> alt-attribute, the title in LO should go to the title-attribute and the
> description in LO should go to a longdesc-attribute in xhtml.

This is not correct:
* <svg:title> should go to the alt attribute (consult the ODF and HTML specifications);
* <svg:desc> cannot go to the longdesc attribute because the longdesc attribute must contain a URL or a fragment identifier, not plain text (so the content of <svg:desc> should go in a separate file or to a separate section in the same HTML file, the longdesc would then point to it)
* the title attribute in HTML is not read by screen readers; it is not used for accessible text alternatives.

PS: The alternative text in the 'Option' tab for an image is the same text as the Title in the Description dialog.
Comment 4 Regina Henschel 2011-07-27 08:23:00 UTC
Created attachment 49616 [details]
Export of the test file to XHTML

The attached file is the result of my export to XHTML. There is nothing with "svg". I have used LO3.4.2RC1 on WinXP.
Comment 5 Christophe Strobbe 2011-07-27 08:35:00 UTC
(In reply to comment #4)
> Created an attachment (id=49616) [details]
> Export of the test file to XHTML
> 
> The attached file is the result of my export to XHTML. There is nothing with
> "svg". I have used LO3.4.2RC1 on WinXP.

Indeed, there is no <svg:xxx> in the OUTPUT. I never made that claim. 

The issue is that <svg:title> in the INPUT (the content.xml that you can extract from ODF with an unzip tool) is not converted to img/@alt in the output.
In other words: 
* the current XHTML export converts <svg:desc> from the INPUT into img/@alt in the OUTPUT,
* the XHTML export should convert <svg:title> from the INPUT into img/@alt in the OUTPUT.
Comment 6 Christophe Strobbe 2011-08-03 04:04:54 UTC
Created attachment 49870 [details]
Patch as unified diff file

Patch for body.xsl as discussed in the original post. Changes just three lines.
Comment 7 Korrawit Pruegsanusak 2011-08-03 08:11:16 UTC
Christophe, could you please send your patch, generated from git format-patch, to the developer mailing list instead?

For the instruction, see http://wiki.documentfoundation.org/Development#Preparing_patches

Thanks!
Comment 8 Christophe Strobbe 2011-08-04 08:20:22 UTC
Created attachment 49917 [details]
Patch generated with git diff.

Added a patch generated with git diff. This patch has been sent to the developer mailing list.
Comment 9 Gabor Jenei 2011-08-08 07:17:38 UTC
Shouldn't this problem be marked as resolved? As I see there is already a patch for it.
Comment 10 Christophe Strobbe 2011-08-08 07:31:50 UTC
I don't know the exact process. I assume the patch should be accepted before the bug is closed, and I have not received news about acceptance of the patch (although that should be trivial).
Comment 12 Robinson Tryon (qubit) 2015-12-15 12:15:10 UTC
Migrating Whiteboard tags to Keywords: (EasyHack DifficultyBeginner)
[NinjaEdit]