[LON-CAPA-cvs] cvs: loncom /interface entities.pm lonprintout.pm

foxr foxr@source.lon-capa.org
Thu, 23 Jul 2009 10:53:03 -0000


This is a MIME encoded message

--foxr1248346383
Content-Type: text/plain

foxr		Thu Jul 23 10:53:03 2009 EDT

  Modified files:              
    /loncom/interface	entities.pm lonprintout.pm 
  Log:
  This merger with head should resolve BZ 5969, 5970, 5732 5927 .. various 
  problems with printing pages, as well as some missing/not quite right entity
  handling in the arrows.
  
  
  
--foxr1248346383
Content-Type: text/plain
Content-Disposition: attachment; filename="foxr-20090723105303.txt"

Index: loncom/interface/entities.pm
diff -u loncom/interface/entities.pm:1.18 loncom/interface/entities.pm:1.19
--- loncom/interface/entities.pm:1.18	Fri Nov 21 20:17:11 2008
+++ loncom/interface/entities.pm	Thu Jul 23 10:53:03 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # entity -> tex.
 #
-# $Id: entities.pm,v 1.18 2008/11/21 20:17:11 jms Exp $
+# $Id: entities.pm,v 1.19 2009/07/23 10:53:03 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -651,14 +651,14 @@
 
     # Arrows and then some (harpoons from Hon Kie).
 
-    8592     => '\textleftarrow',
-    'larr'   => '\textleftarrow',
-    8593     => '\textuparrow',
-    'uarr'   => '\textuparrow',
-    8594     => '\textrightarrow',
-    'rarr'   => '\textrightarrow',
-    8595     => '\textdownarrow',
-    'darr'   => '\textdownarrow',
+    8592     => '\ensuremath{\leftarrow}',
+    'larr'   => '\ensuremath{\leftarrow}',
+    8593     => '\ensuremath{\uparrow}',
+    'uarr'   => '\ensuremath{\uparrow}',
+    8594     => '\ensuremath{\rightarrow}',
+    'rarr'   => '\ensuremath{\rightarrow}',
+    8595     => '\ensuremath{\downarrow}',
+    'darr'   => '\ensuremath{\downarrow}',
     8596     => '\ensuremath{\leftrightarrow}',
     'harr'   => '\ensuremath{\leftrightarrow}',
     8598     => '\ensuremath{\nwarrow}',
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.558 loncom/interface/lonprintout.pm:1.559
--- loncom/interface/lonprintout.pm:1.558	Fri Jul  3 16:13:13 2009
+++ loncom/interface/lonprintout.pm	Thu Jul 23 10:53:03 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.558 2009/07/03 16:13:13 bisitz Exp $
+# $Id: lonprintout.pm,v 1.559 2009/07/23 10:53:03 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -104,7 +104,7 @@
 sub annotate {
     my ($symb) = @_;
 
-    my $annotation_text = &Apache::admannotations::get_annotation($symb, 1);
+    my $annotation_text = &Apache::loncommon::get_annotation($symb, 1);
 
 
     my $result = "";
@@ -197,7 +197,7 @@
 
 
 #
-#   ssi_with_retries - Does the server side include of a resource.
+#   ssi_with_retries- Does the server side include of a resource.
 #                      if the ssi call returns an error we'll retry it up to
 #                      the number of times requested by the caller.
 #                      If we still have a proble, no text is appended to the
@@ -230,6 +230,10 @@
 sub ssi_with_retries {
     my ($resource, $retries, %form) = @_;
 
+    my $target = $form{'grade_target'};
+    my $aom    = $form{'answer_output_mode'};
+
+
 
     my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
     if (!$response->is_success) {
@@ -944,6 +948,7 @@
     $result =~ s/&(rdquo|#8221);/\'\'/g;
 
 
+
     return $result;
 }
 
@@ -1305,6 +1310,180 @@
     return $result;
 }
 
+#
+#  Map from helper layout style to the book/album:
+#
+sub map_laystyle {
+    my ($laystyle) = @_;
+    if ($laystyle eq 'L') {
+	$laystyle='album';
+    } else {
+	$laystyle='book';
+    }
+    return $laystyle;
+}
+
+sub print_page_in_course {
+    my ($helper, $rparmhash, $currentURL, $resources) = @_;
+    my %parmhash       = %$rparmhash;
+    my @page_resources = @$resources;
+    my $mode = $helper->{'VARS'}->{'LATEX_TYPE'};
+    my $symb = $helper->{'VARS'}->{'symb'};
+
+
+    my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
+
+
+    my @temporary_array=split /\|/,$format_from_helper;
+    my ($laystyle,$numberofcolumns,$papersize,$pdfFormFields)=@temporary_array;
+    $laystyle = &map_laystyle($laystyle);
+    my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,
+								      $numberofcolumns);
+    my $LaTeXwidth=&recalcto_mm($textwidth); 
+
+
+    if ($mode ne '') {$mode='\\'.$mode}
+    my $result.= &print_latex_header($mode);
+    if ($currentURL=~m|^(/adm/wrapper/)?ext/|) {
+	$currentURL=~s|^(/adm/wrapper/)?ext/|http://|;
+	my $title=&Apache::lonnet::gettitle($symb);
+	$title = &Apache::lonxml::latex_special_symbols($title);
+    } else {
+	$result.=$currentURL;
+    }
+    $result .= '\\\\';
+
+    if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
+	&Apache::lonnet::appenv({'construct.style' =>
+				$helper->{'VARS'}->{'style_file'}});
+    } elsif ($env{'construct.style'}) {
+	&Apache::lonnet::delenv('construct.style');
+    }
+
+    # First is the overall page description.  This is then followed by the 
+    # components of the page. Each of which must be printed independently.
+
+    my $the_page = shift(@page_resources); 
+
+    foreach my $resource (@page_resources) {
+	my $resource_src   = $resource->src(); # Essentially the URL of the resource.
+	$result           .= $resource->title() . '\\\\';
+
+	# Recurse if a .page:
+
+	if ($resource_src =~ /.page$/i) {
+	    my $navmap         = Apache::lonnavmaps::navmap->new();
+	    my @page_resources = $navmap->retrieveResources($resource_src);
+	    $result           .= &print_page_in_course($helper, $rparmhash, 
+						       $resource_src, \@page_resources);
+	}
+	# these resources go through the XML transformer:
+
+	elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm\xhtml|xhtm)$/)  {		
+	    my $urlp = &Apache::lonnet::clutter($resource_src);
+	    my %form;
+	    my %moreenv;
+
+	    &Apache::lonxml::remember_problem_counter();
+	    $moreenv{'request.filename'}=$urlp;
+	    if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
+
+	    $form{'grade_target'}  = 'tex';
+	    $form{'textwidth'}    = &get_textwidth($helper, $LaTeXwidth);
+	    $form{'pdfFormFiels'} = $pdfFormFields; # 
+	    $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};    
+	    
+	    $form{'problem_split'}=$parmhash{'problem_stream_switch'};
+	    $form{'suppress_tries'}=$parmhash{'suppress_tries'};
+	    $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
+	    $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
+	    $form{'print_annotations'}=$helper->{'VARS'}->{'PRINT_ANNOTATIONS'};
+	    if (($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') ||
+		($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes')) {
+		$form{'problem_split'}='yes';
+	    }
+	    my $rndseed = time;
+	    if ($helper->{'VARS'}->{'curseed'}) {
+		$rndseed=$helper->{'VARS'}->{'curseed'};
+	    }
+	    $form{'rndseed'}=$rndseed;
+	    &Apache::lonnet::appenv(\%moreenv);
+	    
+	    &Apache::lonxml::clear_problem_counter();
+
+	    my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
+
+	    # There seems to be an extraneous \vskip 1mm \\\\ :
+
+	    $texversion =~ s/^\\vskip 1mm \\\\\\\\//;
+
+	    # current document with answers.. no need to encap in minipage
+	    #  since there's only one answer.
+
+	    if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
+	       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
+		my %answerform = %form;
+
+
+		$answerform{'problem_split'}=$parmhash{'problem_stream_switch'};
+		$answerform{'grade_target'}='answer';
+		$answerform{'answer_output_mode'}='tex';
+		$answerform{'rndseed'}=$rndseed;
+                if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {
+		    $answerform{'problemtype'}='exam';
+		}
+		$resources_printed .= $urlp.':';
+		my $answer=&ssi_with_retries($urlp,$ssi_retry_count, %answerform);
+
+		if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
+		    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
+		} else {
+		    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
+		    if ($helper->{'VARS'}->{'construction'} ne '1') {
+			my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
+			$title = &Apache::lonxml::latex_special_symbols($title);
+			$texversion.='\vskip 0 mm \noindent\textbf{'.$title.'}\vskip 0 mm ';
+			$texversion.=&path_to_problem($urlp,$LaTeXwidth);
+		    } else {
+			$texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
+			my $URLpath=$urlp;
+			$URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
+			$texversion.=&path_to_problem($URLpath,$LaTeXwidth);
+		    }
+		    $texversion.='\vskip 1 mm '.$answer.'\end{document}';
+		}
+
+
+		
+
+	    
+	    }
+	    # Print annotations.
+
+
+	    if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
+		my $annotation .= &annotate($currentURL);
+		$texversion =~ s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/;
+	    }
+	    
+	    if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
+		$texversion=&IndexCreation($texversion,$currentURL);
+	    }
+	    if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
+		$texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
+
+	    }
+	    $result .= $texversion;
+	    if ($currentURL=~m/\.page\s*$/) {
+		($result,$numberofcolumns) = &page_cleanup($result);
+	    }
+	}
+    }
+
+    $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
+    return $result;
+}
+
 
 #
 # List of recently generated print files
@@ -1580,11 +1759,8 @@
     my $number_of_columns = 1; #used only for pages to determine the width of the cell
     my @temporary_array=split /\|/,$format_from_helper;
     my ($laystyle,$numberofcolumns,$papersize,$pdfFormFields)=@temporary_array;
-    if ($laystyle eq 'L') {
-	$laystyle='album';
-    } else {
-	$laystyle='book';
-    }
+
+    $laystyle = &map_laystyle($laystyle);
     my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
     my $assignment =  $env{'form.assignment'};
     my $LaTeXwidth=&recalcto_mm($textwidth); 
@@ -1733,6 +1909,8 @@
         } elsif ($cleanURL!~m|^/adm/|
 		 && $currentURL=~/\.(sequence|page)$/ && $helper->{'VARS'}->{'construction'} eq '1') {
             #printing content of sequence from the construction space	
+
+
 	    $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
 #	    $result .= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
 	    $result .= &print_construction_sequence($currentURL, $helper, %form,
@@ -1768,7 +1946,18 @@
 	} elsif ($cleanURL =~ /\.pdf$/i) {
 	    $result .= &include_pdf($cleanURL);
 	    $result .= '\end{document}';
+	} elsif ($cleanURL =~ /\.page$/i) { #  Print page in non construction space contexts.
+
+	    # Determine the set of resources in the map of the page:
+
+	    my $navmap         =  Apache::lonnavmaps::navmap->new();
+	    my @page_resources =  $navmap->retrieveResources($cleanURL);
+	    $result           .=  &print_page_in_course($helper, $rparmhash,
+							$cleanURL, \@page_resources);
+
+       
 	} else {
+	    &Apache::lonnet::logthis("Unsupported type handler");
 	    $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},
 				  $helper->{'VARS'}->{'symb'});
 	}
@@ -1839,6 +2028,7 @@
 		&Apache::lonxml::remember_problem_counter();
 		$texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);
 		if ($urlp=~/\.page$/) {
+
 		    ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
 		    if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} 
 		    $texversion =~ s/\\end{document}\d*/\\end{document}/;
@@ -2427,7 +2617,6 @@
 		if ($res_url!~m|^ext/|
 		    && $res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
 		    $printed .= $curresline.':';
-
 		    &Apache::lonxml::remember_problem_counter();    
 
 		    my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
@@ -3194,7 +3383,6 @@
 	    )) 
 	&& $helper->{VARS}->{'assignment'} eq ""
 	) {
-
 	my $pretty_dir = &Apache::lonnet::hreflocation($subdir);
         push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from current subdirectory [_3]','<b>','</b>','<b><i>'.$pretty_dir.'</i></b>','<b>','</b>'), 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
         my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
@@ -3739,12 +3927,8 @@
     my ($laystyle, $cols, $papersize) = split(/\|/, $format);
     ($papersize)                      = split(/ /, $papersize);
 
+    $laystyle = &Apache::lonprintout::map_laystyle($laystyle);
 
-    if ($laystyle eq 'L') {
-	$laystyle = 'album';
-    } else {
-	$laystyle = 'book';
-    }
 
 
     my %size;
@@ -3825,11 +4009,8 @@
 	($papersize)                      = split(/ /, $papersize);
 	
 	
-	if ($laystyle eq 'L') {
-	    $laystyle = 'album';
-	} else {
-	    $laystyle = 'book';
-	}
+	$laystyle = &map_laystyle($laystyle);
+
 	#  Figure out some good defaults for the print out and set them:
 	
 	my %size;

--foxr1248346383--