Skip to content

Commit abbc6ab

Browse files
committed
Merge implement actualtext, artifact from recent graphicx (PR brucemiller#2684)
2 parents 796a365 + 32635a0 commit abbc6ab

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

MANIFEST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ t/complex/figure_dual_caption.xml
999999
t/complex/figure_mixed_content.pdf
10001000
t/complex/figure_mixed_content.tex
10011001
t/complex/figure_mixed_content.xml
1002+
t/complex/graphicxalt.pdf
1003+
t/complex/graphicxalt.tex
1004+
t/complex/graphicxalt.xml
10021005
t/complex/hyperchars.pdf
10031006
t/complex/hyperchars.tex
10041007
t/complex/hyperchars.xml

lib/LaTeXML/Package/graphicx.sty.ltxml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ DefKeyVal('Gin', 'keepaspectratio', '', 'true');
3333
DefKeyVal('Gin', 'clip', '', 'true');
3434
DefKeyVal('Gin', 'scale', '');
3535
DefKeyVal('Gin', 'angle', '');
36+
DefKeyVal('Gin', 'actualtext', '');
3637
DefKeyVal('Gin', 'alt', '');
38+
DefKeyVal('Gin', 'artifact', '', 'true');
3739
DefKeyVal('Gin', 'trim', 'GraphixDimensions');
3840
DefKeyVal('Gin', 'viewport', 'GraphixDimensions');
3941
# NOTE: graphicx defines @angle to actually carry out the rotation (on \box\z@) w/\Gin@erotate
@@ -56,19 +58,30 @@ DefConstructor('\@includegraphicx OptionalMatch:* OptionalKeyVals:Gin Semiverbat
5658
scope => 'global',
5759
afterConstruct => sub {
5860
my ($document, $whatsit) = @_;
59-
my $alt = $whatsit->getProperty('alt');
60-
# Trickery to set @description EVEN IF empty string (constructor shorthand omits it)
61-
if (defined $alt) {
62-
$document->getNode->lastChild->setAttribute(description => ToString($alt)); } },
61+
my $actualtext = $whatsit->getProperty('actualtext');
62+
my $alt = $whatsit->getProperty('alt');
63+
my $artifact = $whatsit->getProperty('artifact');
64+
$artifact = 1 if defined $artifact && ToString($artifact) ne 'false';
65+
if ($artifact || defined $actualtext || defined $alt) {
66+
my $node = $document->getNode->lastChild;
67+
# Trickery to set @description EVEN IF empty string (constructor shorthand omits it)
68+
$node->setAttribute(description => ToString($actualtext // $alt // ''));
69+
# when both actualtext and alt are specified, use aria-description for alt
70+
$document->setAttribute($node, 'aria:description', ToString($alt)) if defined $alt && defined $actualtext;
71+
$document->setAttribute($node, 'aria:hidden', 'true') if $artifact; } },
6372
properties => sub {
6473
my ($stomach, $starred, $kv, $graphic) = @_;
6574
my $options = graphicX_options($starred, $kv);
6675
my ($path, @candidates) = image_candidates(ToString($graphic));
67-
my $alt = $kv && $kv->getValue('alt');
76+
my $alt = $kv && $kv->getValue('alt');
77+
my $actualtext = $kv && $kv->getValue('actualtext');
78+
my $artifact = $kv && $kv->getValue('artifact');
6879
(path => $path,
6980
candidates => join(',', @candidates),
70-
(defined $alt ? (alt => $alt) : ()),
71-
options => $options); },
81+
actualtext => $actualtext,
82+
alt => $alt,
83+
artifact => $artifact,
84+
options => $options); },
7285
mode => 'restricted_horizontal', enterHorizontal => 1);
7386

7487
#**********************************************************************

t/complex/graphicxalt.pdf

19.8 KB
Binary file not shown.

t/complex/graphicxalt.tex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
\documentclass{article}
2+
\usepackage{graphicx}
3+
\begin{document}
4+
\includegraphics{sunset}
5+
\includegraphics[alt={alt text}]{sunset}
6+
\includegraphics[actualtext={actual text}]{sunset}
7+
\includegraphics[actualtext={actual text},alt={alt text}]{sunset}
8+
\includegraphics[artifact]{sunset}
9+
\includegraphics[artifact,alt={alt text}]{sunset}
10+
\includegraphics[artifact,actualtext={actual text}]{sunset}
11+
\includegraphics[artifact,actualtext={actual text},alt={alt text}]{sunset}
12+
\end{document}

t/complex/graphicxalt.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?latexml class="article"?>
3+
<?latexml package="graphicx"?>
4+
<?latexml RelaxNGSchema="LaTeXML"?>
5+
<document xmlns="http://dlmf.nist.gov/LaTeXML" xmlns:aria="http://www.w3.org/ns/wai-aria">
6+
<resource src="LaTeXML.css" type="text/css"/>
7+
<resource src="ltx-article.css" type="text/css"/>
8+
<para xml:id="p1">
9+
<graphics candidates="sunset.jpg" graphic="sunset" xml:id="p1.g1"/>
10+
<graphics candidates="sunset.jpg" description="alt text" graphic="sunset" options="alt=alt text" xml:id="p1.g2"/>
11+
<graphics candidates="sunset.jpg" description="actual text" graphic="sunset" options="actualtext=actual text" xml:id="p1.g3"/>
12+
<graphics aria:description="alt text" candidates="sunset.jpg" description="actual text" graphic="sunset" options="actualtext=actual text,alt=alt text" xml:id="p1.g4"/>
13+
<graphics aria:hidden="true" candidates="sunset.jpg" description="" graphic="sunset" options="artifact=true" xml:id="p1.g5"/>
14+
<graphics aria:hidden="true" candidates="sunset.jpg" description="alt text" graphic="sunset" options="artifact=true,alt=alt text" xml:id="p1.g6"/>
15+
<graphics aria:hidden="true" candidates="sunset.jpg" description="actual text" graphic="sunset" options="artifact=true,actualtext=actual text" xml:id="p1.g7"/>
16+
<graphics aria:description="alt text" aria:hidden="true" candidates="sunset.jpg" description="actual text" graphic="sunset" options="artifact=true,actualtext=actual text,alt=alt text" xml:id="p1.g8"/>
17+
</para>
18+
</document>

0 commit comments

Comments
 (0)