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

foxr lon-capa-cvs-allow@mail.lon-capa.org
Mon, 25 Aug 2008 10:16:30 -0000


foxr		Mon Aug 25 06:16:30 2008 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  BZ5446:
  1. Added support for %s title formatting code.  This will encode
     the section number if it is available for a print job.
  2. Set a default title format so that the section can never 
    (well hardly ever) get cut out of a print job's title by setting
    a default format string that ensures space for both the student name
    and the section in the first line, bumping the course to the second line
    and reserving a new third line for the assignment name.
  
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.536 loncom/interface/lonprintout.pm:1.537
--- loncom/interface/lonprintout.pm:1.536	Mon Jul 14 06:40:57 2008
+++ loncom/interface/lonprintout.pm	Mon Aug 25 06:16:27 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.536 2008/07/14 10:40:57 foxr Exp $
+# $Id: lonprintout.pm,v 1.537 2008/08/25 10:16:27 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -229,9 +229,11 @@
 #     %a    - Assignment name.
 #     %c    - Course name.
 #     %n    - Student name.
+#     %s    - The section if it is supplied.
 #
 sub format_page_header {
-    my ($width, $format, $assignment, $course, $student) = @_;
+    my ($width, $format, $assignment, $course, $student, $section) = @_;
+
     
     $width = &recalcto_mm($width); # Get width in mm.
     #  Default format?
@@ -248,38 +250,36 @@
 	# - Allow the assignment to be 2 lines (wrapped).
 	#
 	my $chars_per_line = $width/2; # Character/textline.
+	
 
 
-	my $firstline = "$student $course";
-	if (length($firstline) > $chars_per_line) {
-	    my $lastchar = $chars_per_line - length($student) - 1;
-	    if ($lastchar > 0) {
-		$course = substr($course, 0, $lastchar);
-	    } else {		# Nothing left of course:
-		$course = '';
-	    }
-	}
-	if (length($assignment) > $chars_per_line) {
-	    $assignment = substr($assignment, 0, $chars_per_line);
+	my $name_length    = int($chars_per_line *3 /4);
+	my $sec_length     = int($chars_per_line / 5);
+
+	$format  = "%$name_length".'n';
+
+	if ($section) {
+	    $format .=  ' - Sec: '."%$sec_length".'s';
 	}
-	
-	$format =  "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
-	
-    } else {
-	# An open question is how to handle long user formatted page headers...
-	# A possible future is to support e.g. %na so that the user can control
-	# the truncation of the elements that can appear in the header.
-	#
-	$format =  &printf_style_subst("a", $format, $assignment);
-	$format =  &printf_style_subst("c", $format, $course);
-	$format =  &printf_style_subst("n", $format, $student);
-
-	# If the user put %'s in the format string, they  must be escaped
-	# to \% else LaTeX will think they are comments and terminate
-	# the line.. which is bad!!!
 
+	$format .= '\\\\%c \\\\ %a';
+        
 
     }
+    # An open question is how to handle long user formatted page headers...
+    # A possible future is to support e.g. %na so that the user can control
+    # the truncation of the elements that can appear in the header.
+    #
+    $format =  &printf_style_subst("a", $format, $assignment);
+    $format =  &printf_style_subst("c", $format, $course);
+    $format =  &printf_style_subst("n", $format, $student);
+    $format =  &printf_style_subst("s", $format, $section);
+    
+    
+    # If the user put %'s in the format string, they  must be escaped
+    # to \% else LaTeX will think they are comments and terminate
+    # the line.. which is bad!!!
+    
     
 
     return $format;
@@ -978,6 +978,8 @@
     my $courseidinfo;
     if (defined($env{'request.course.id'})) {
 	$courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');
+	my $sec = $env{'request.course.sec'};
+	    
     }
     return $courseidinfo;
 }
@@ -1000,7 +1002,6 @@
 
     my $name = &get_name();
     my $courseidinfo = &get_course();
-    if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
     my $header_text  = $parmhash{'print_header_format'};
     $header_text     = &format_page_header($textwidth, $header_text, $assignment,
 					   $courseidinfo, $name);
@@ -1779,7 +1780,6 @@
 		if (($selectionmade == 4) and ($assignment ne $prevassignment)) {
 		    my $name = &get_name();
 		    my $courseidinfo = &get_course();
-		    if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
 		    $prevassignment=$assignment;
 		    my $header_text = $parmhash{'print_header_format'};
 		    $header_text    = &format_page_header($textwidth, $header_text,
@@ -2364,12 +2364,10 @@
 	if (&Apache::loncommon::connection_aborted($r)) { last; }
     }
     my $courseidinfo = &get_course();
-    if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
-    if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}
     my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
     my $header_line =
 	&format_page_header($LaTeXwidth, $parmhash{'print_header_format'},
-			    $currentassignment, $courseidinfo, $fullname);
+			    $currentassignment, $courseidinfo, $fullname, $usersection);
     my $header_start = ($columns_in_format == 1) ? '\lhead'
 	                                         : '\fancyhead[LO]';
     $header_line = $header_start.'{'.$header_line.'}';