--- loncom/interface/lonprintout.pm 2010/04/01 23:38:26 1.568.2.4
+++ loncom/interface/lonprintout.pm 2010/01/12 11:49:46 1.570
@@ -2,7 +2,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.568.2.4 2010/04/01 23:38:26 raeburn Exp $
+# $Id: lonprintout.pm,v 1.570 2010/01/12 11:49:46 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -494,12 +494,15 @@ sub printf_style_subst {
# %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.
- my $chars_per_line = int($width/2); # Character/textline.
+ my $chars_per_line = int($width/1.6); # Character/textline.
# Default format?
@@ -515,36 +518,58 @@ sub format_page_header {
# - Allow the assignment to be 2 lines (wrapped).
#
- 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);
- }
+
- $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
+ 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 .= '\\\\%c \\\\ %a';
+
- } 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!!!
}
+ # 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!!!
+
+ # If the user has role author, $course and $assignment are empty so
+ # there is '\\ \\ ' in the page header. That's cause a error in LaTeX
+ if($format =~ /\\\\\s\\\\\s/) {
+ #TODO find sensible caption for page header
+ my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout ');
+ $format =~ s/\\\\\s\\\\\s/$testPrintout/;
+ }
+ #
+ # We're going to trust LaTeX to break lines appropriately, but
+ # we'll truncate anything that's more than 3 lines worth of
+ # text. This is also assuming (which will probably end badly)
+ # nobody's going to embed LaTeX control sequences in the title
+ # header or rather that those control sequences won't get broken
+ # by the stuff below.
+ #
+ my $total_length = 3*$chars_per_line;
+ if (length($format) > $total_length) {
+ $format = substr($format, 0, $total_length);
+ }
+
+
return $format;
+
}
#
@@ -1240,6 +1265,8 @@ sub get_course {
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;
}
@@ -1262,7 +1289,6 @@ sub page_format_transformation {
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);
@@ -1283,7 +1309,7 @@ sub page_format_transformation {
$text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /;
}
if ($papersize eq 'a4') {
- $text =~ s/(\\begin{document})/$1\\\\special\{papersize=210mm,297mm\}/;
+ $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/;
}
}
if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
@@ -1555,7 +1581,7 @@ sub print_page_in_course {
$form{'grade_target'} = 'tex';
$form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
- $form{'pdfFormFields'} = 'no';
+ $form{'pdfFormFiels'} = $pdfFormFields; #
$form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
@@ -1731,7 +1757,7 @@ sub recently_generated {
#
#
# use Data::Dumper;
-#sub dump_helper_vars {
+# sub dump_helper_vars {
# my ($helper) = @_;
# my $helpervars = Dumper($helper->{'VARS'});
# &Apache::lonnet::logthis("Dump of helper vars:\n $helpervars");
@@ -1746,6 +1772,122 @@ sub get_page_breaks {
}
return %page_breaks;
}
+#
+# Returns text to insert for any extra vskip prior to the resource.
+# Parameters:
+# helper - Reference to the helper object driving the printout.
+# resource - Identifies the resource about to be printed.
+#
+# This is done as follows:
+# POSSIBLE_RESOURCES has the list of possible resources.
+# EXTRASPACE has the list of extra space values.
+# EXTRASPACE_UNITS is the set of resources for which the units are
+# mm. All others are 'in'.
+#
+# The resource is found in the POSSIBLE_RESOURCES to get the index
+# of the EXTRASPACE value.
+#
+# In order to speed this up for lengthy printouts, the first time,
+# POSSIBLE_RESOURCES is turned into a look up hash and
+# EXTRASPACE is turned into an array.
+#
+
+
+my %possible_resources;
+my %extraspace_mm;
+my @extraspace;
+my $skips_loaded = 0;
+
+# Function to load the skips hash and array
+
+sub load_skips {
+
+ my ($helper) = @_;
+
+ # If this is the first time, unrap the resources and extra spaces:
+
+ if (!$skips_loaded) {
+ @extraspace = (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE'}));
+ my @resource_list = (split(/\|\|\|/, $helper->{'VARS'}->{'POSSIBLE_RESOURCES'}));
+ my $i = 0;
+ foreach my $resource (@resource_list) {
+ $possible_resources{$resource} = $i;
+ $i++;
+ }
+ foreach my $mm_resource (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE_UNITS'})) {
+ $extraspace_mm{$mm_resource} = 1;
+ }
+ $skips_loaded = 1;
+ }
+}
+
+sub get_extra_vspaces {
+ my ($helper, $resource) = @_;
+
+ &load_skips($helper);
+
+ # Lookup the resource in the possible resources hash.. that is the index
+ # into the extraspace array that gives us either an empty string or
+ # the number of mm to skip:
+
+ my $index = $possible_resources{$resource};
+ my $skip = $extraspace[$index];
+
+ my $result = '';
+ if ($skip ne '') {
+ my $units = 'in';
+ if (defined($extraspace_mm{$resource})) {
+ $units = 'mm';
+ }
+ $result = '\vskip '.$skip.' '.$units;
+ }
+
+
+ return $result;
+
+
+}
+
+#
+# The resource chooser part of the helper needs more than just
+# the value of the extraspaces var to recover the value into a text
+# field option. This sub produces the required format for the saved var:
+# specifically
+# ||| separated fields of the form resourcename=value
+#
+# Parameters:
+# $helper - Refers to the helper we are configuring
+# Implicit input:
+# $helper->{'VARS'}->{'EXTRASPACE'} - the spaces helper var has the text field
+# value.
+# $helper->{'VARS'}->{'EXTRASPACE_UNITS'} - units for the skips (checkboxes).
+# $helper->{'VARS'}->{'POSSIBLE_RESOURCES'} - has the list of resources. |||
+# separated of course.
+# Implicit outputs:
+# $env{'form.extraspace'}
+# $env{'form.extraspace_units'}
+#
+sub set_form_extraspace {
+ my ($helper) = @_;
+
+ # the most convenient way to do this is to drive from the skips arrays/hash.
+ # may not be the fastest, but this is once per print request so it's not so
+ # speed critical:
+
+ &load_skips($helper);
+
+ my $result = '';
+
+ foreach my $resource (keys(%possible_resources)) {
+ my $vskip = $extraspace[$possible_resources{$resource}];
+ $result .= $resource .'=' . $vskip . '|||';
+ }
+
+ $env{'form.extraspace'} = $result;
+ $env{'form.extraspace_units'} = $helper->{'VARS'}->{'EXTRASPACE_UNITS'};
+ return $result;
+
+}
# Output a sequence (recursively if neeed)
# from construction space.
@@ -1917,11 +2059,13 @@ ENDPART
# indexed by symb and contains 1's for each break.
$env{'form.pagebreaks'} = $helper->{'VARS'}->{'FINISHPAGE'};
+ &set_form_extraspace($helper);
$env{'form.lastprinttype'} = $helper->{'VARS'}->{'PRINT_TYPE'};
&Apache::loncommon::store_course_settings('print',
{'pagebreaks' => 'scalar',
+ 'extraspace' => 'scalar',
+ 'extraspace_units' => 'scalar',
'lastprinttype' => 'scalar'});
-
my %page_breaks = &get_page_breaks($helper);
my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
@@ -1946,7 +2090,7 @@ ENDPART
my %form;
$form{'grade_target'} = 'tex';
$form{'textwidth'} = &get_textwidth($helper, $LaTeXwidth);
- $form{'pdfFormFields'} = 'no';
+ $form{'pdfFormFields'} = $pdfFormFields;
# If form.showallfoils is set, then request all foils be shown:
# privilege will be enforced both by not allowing the
@@ -2185,6 +2329,7 @@ ENDPART
$result.="\\newpage\n";
}
}
+ $result .= &get_extra_vspaces($helper, $master_seq[$i]);
my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
$urlp=&Apache::lonnet::clutter($urlp);
$form{'symb'}=$master_seq[$i];
@@ -2256,7 +2401,6 @@ ENDPART
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,
@@ -2787,6 +2931,7 @@ sub print_resources {
$current_output.= "\\newpage\n";
}
}
+ $current_output .= &get_extra_vspaces($helper, $curresline);
$i++;
if ( !($type eq 'problems' &&
@@ -2879,12 +3024,10 @@ sub print_resources {
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.'}';
@@ -3036,19 +3179,21 @@ sub printHelper {
$helper->declareVar('PRINT_TYPE');
$helper->declareVar("showallfoils");
$helper->declareVar("STUDENTS");
-
+ $helper->declareVar("EXTRASPACE");
- # The page breaks can get loaded initially from the course environment:
+ # The page breaks and extra spaces
+ # can get loaded initially from the course environment:
# But we only do this in the initial state so that they are allowed to change.
#
- # $helper->{VARS}->{FINISHPAGE} = '';
&Apache::loncommon::restore_course_settings('print',
{'pagebreaks' => 'scalar',
+ 'extraspace' => 'scalar',
+ 'extraspace_units' => 'scalar',
'lastprinttype' => 'scalar'});
# This will persistently load in the data we want from the
@@ -3058,10 +3203,15 @@ sub printHelper {
if (!defined ($env{"form.CURRENT_STATE"})) {
$helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
+ $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
+ $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
} else {
my $state = $env{"form.CURRENT_STATE"};
if ($state eq "START") {
$helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
+ $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
+ $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
+
}
}
@@ -3180,7 +3330,16 @@ sub printHelper {
if ($perm{'pav'}) {
$start_new_option =
"before selected').
- "' variable='FINISHPAGE' />";
+ "' variable='FINISHPAGE' />".
+ "before selected').
+ "' variable='EXTRASPACE' type='text' />" .
+ "".
+ "check for mm').
+ "' variable='EXTRASPACE_UNITS' type='checkbox' />"
+ ;
+
+
}
# If not construction space user can print the components of a page:
@@ -3358,7 +3517,7 @@ ALL_PROBLEMS
'multichoice="1" addstatus="1" closeallpages="1"',
'RESOURCES',
'PRINT_FORMATTING',
- $map,
+ '',
$isProblem, '', $symbFilter,
$start_new_option);
$resource_selector .= <'.&mt('Layout Options').''
@@ -4015,6 +4177,7 @@ sub render {
.'