--- loncom/homework/randomlabel.pm 2016/07/01 19:59:15 1.97 +++ loncom/homework/randomlabel.pm 2025/01/26 16:29:03 1.98 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # random labelling tool # -# $Id: randomlabel.pm,v 1.97 2016/07/01 19:59:15 raeburn Exp $ +# $Id: randomlabel.pm,v 1.98 2025/01/26 16:29:03 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -110,6 +110,8 @@ use Apache::File(); use Apache::Constants qw(:common :http); use Image::Magick; use Apache::lonplot; +use Apache::lonlocal; +use Apache::lonmeta; use LONCAPA; @@ -162,13 +164,14 @@ sub extract_tag_sizes { } -my ($height_param,$width_param); +my ($height_param,$width_param,$alt_param); sub start_randomlabel { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; push (@Apache::lonxml::namespace,'randomlabel'); ($height_param,$width_param)=(0,0); + $alt_param = ''; $label_xscale = 1.0; # Assume image size not overridden. $label_yscale = 1.0; my $bgimg= &Apache::lonxml::get_param('bgimg',$parstack,$safeeval); @@ -185,6 +188,13 @@ sub start_randomlabel { $args{"cgi.$cgi_id.BGIMG"}=&escape($bgimg); $height_param = &Apache::lonxml::get_param('height',$parstack, $safeeval); $width_param = &Apache::lonxml::get_param('width', $parstack, $safeeval); + $alt_param = &Apache::lonxml::get_param('alt', $parstack, $safeeval); + if ($alt_param eq '') { + unless (($bgimg =~ m{^data\:image/gif;base64,}) || ($bgimg =~ /^https?\:/) || + ($bgimg eq $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonKaputt/lonlogo_broken.gif')) { + $alt_param = &Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$bgimg); + } + } } elsif ($target eq 'tex' && defined($bgimg)) { $result.=&make_eps_image($bgimg,$parstack,$safeeval); } elsif ($target eq 'edit') { @@ -196,6 +206,7 @@ sub start_randomlabel { $result.=&Apache::edit::text_arg('Image:','bgimg',$token,75).' '. &Apache::edit::browse_or_search('bgimg',undef,undef,$only,undef,1). '
'. + &Apache::edit::text_arg('Description:' ,'alt' ,$token,40).'
'. &Apache::edit::text_arg('Width(pixel):' ,'width' ,$token,6). &Apache::edit::text_arg('Height(pixel):','height' ,$token,6). &Apache::edit::text_arg('TeXWidth(mm):' ,'texwidth',$token,6). @@ -203,7 +214,7 @@ sub start_randomlabel { } elsif ($target eq 'modified') { my $constructtag=&Apache::edit::get_new_args($token,$parstack, $safeeval,'bgimg','width', - 'height','texwidth'); + 'height','texwidth','alt'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } @@ -217,9 +228,16 @@ sub end_randomlabel { my $count; pop @Apache::lonxml::namespace; if ($target eq 'web') { + my $alttext; + if ($alt_param eq '') { + $alttext = &mt('labeled image'); + } else { + $alttext = $alt_param; + } + $alttext = &HTML::Entities::encode($alttext,'<>&"'); $count = $Apache::randomlabel::obj_cnt; if( $count != 0) { $args{"cgi.$cgi_id.OBJCOUNT"}=$count; } - $result.='
'."\n"; + $result.=''.$alttext.'
'."\n"; &Apache::lonnet::appenv(\%args); } elsif ($target eq 'tex') { $result='\end{picture}\\\\';