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

sakharuk lon-capa-cvs@mail.lon-capa.org
Wed, 18 Aug 2004 18:56:46 -0000


This is a MIME encoded message

--sakharuk1092855406
Content-Type: text/plain

sakharuk		Wed Aug 18 14:56:46 2004 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm printout.pl 
  Log:
  Started to do some cleanup according to your (Guy) remarks. Any critical notes would be welcomed.
  
  
--sakharuk1092855406
Content-Type: text/plain
Content-Disposition: attachment; filename="sakharuk-20040818145646.txt"

Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.325 loncom/interface/lonprintout.pm:1.326
--- loncom/interface/lonprintout.pm:1.325	Mon Aug 16 13:11:10 2004
+++ loncom/interface/lonprintout.pm	Wed Aug 18 14:56:46 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.325 2004/08/16 17:11:10 sakharuk Exp $
+# $Id: lonprintout.pm,v 1.326 2004/08/18 18:56:46 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -375,167 +375,142 @@
 
 sub page_format {
 #
-#Correspondence between $papersize variable and real paper format:
-# 0 - "Letter [8 1/2x11 in]"
-# 1 - "Legal [8 1/2x14 in]"
-# 2 - "Ledger/Tabloid [11x17 in]"
-# 3 - "Executive [7 1/2x10 in]"
-# 4 - "A2 [420x594 mm]"
-# 5 - "A3 [297x420 mm]"
-# 6 - "A4 [210x297 mm]"
-# 7 - "A5 [148x210 mm]"
-# 8 - "A6 [105x148 mm]"
+#Supported paper format: "Letter [8 1/2x11 in]",      "Legal [8 1/2x14 in]",
+#                        "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
+#                        "A2 [420x594 mm]",           "A3 [297x420 mm]",
+#                        "A4 [210x297 mm]",           "A5 [148x210 mm]",
+#                        "A6 [105x148 mm]"
 # 
     my ($papersize,$layout,$numberofcolumns) = @_; 
     my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = (0,0,0,0,0);
-    if ($papersize eq '0') {
-	if ($layout eq 'book') {
-	    if ($numberofcolumns == 1) {
-		$textwidth = '7.1 in';      #'18 cm';
-		$textheight = '10.2 in';    #'25.9 cm';
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-	    } elsif ($numberofcolumns == 2) {
-		$textwidth = '3.66 in';     #'93 mm';
-		$textheight = '10.2 in';    #'25.9 cm';
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-	    }
-	} elsif ($layout eq 'album') {
-	    if ($numberofcolumns eq '1') {
-		$textwidth = '8.8 in';
-		$textheight = '6.8 in';
-		$oddoffset = '-40 pt';
-		$evenoffset = '-60 pt';
-	    } elsif ($numberofcolumns == 2) {
-		$textwidth = '4.4 in';
-		$textheight = '6.8 in';
-		$oddoffset = '-0.5 in';
-		$evenoffset = '-1.5 in';
-		$topmargin = '3.5 in';
-	    }
-	}
-    } elsif($papersize eq '1') {
-	if ($layout eq 'book') {
-	    if ($numberofcolumns == 1) {
-		$textwidth = '7.1 in';      
-		$textheight = '13 in';    
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '-0.5 in';
-	    } elsif ($numberofcolumns == 2) {
-		$textwidth = '3.66 in';     
-		$textheight = '13 in';    
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '-0.5 in';
-	    }
-	} elsif ($layout eq 'album') {
-	    if ($numberofcolumns eq '1') {
-#		$textwidth = '8.8 in';
-#		$textheight = '6.8 in';
-#		$oddoffset = '-40 pt';
-#		$evenoffset = '-60 pt';
-	    } elsif ($numberofcolumns == 2) {
-#		$textwidth = '4.4 in';
-#		$textheight = '6.8 in';
-#		$oddoffset = '-0.5 in';
-#		$evenoffset = '-1.5 in';
-#		$topmargin = '3.5 in';
-	    }
-	}
-    } elsif($papersize eq '2') {
-	if ($layout eq 'book') {
-	    if ($numberofcolumns == 1) {
-		$textwidth = '9.8 in';      
-		$textheight = '16 in';    
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '-0.5 in';
-	    } elsif ($numberofcolumns == 2) {
-		$textwidth = '4.9 in';     
-		$textheight = '16 in';    
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '-0.5 in';
-	    }
-	} elsif ($layout eq 'album') {
-	    if ($numberofcolumns eq '1') {
-#		$textwidth = '8.8 in';
-#		$textheight = '6.8 in';
-#		$oddoffset = '-40 pt';
-#		$evenoffset = '-60 pt';
-	    } elsif ($numberofcolumns == 2) {
-#		$textwidth = '4.4 in';
-#		$textheight = '6.8 in';
-#		$oddoffset = '-0.5 in';
-#		$evenoffset = '-1.5 in';
-#		$topmargin = '3.5 in';
-	    }
-	}
-    } elsif($papersize eq '3') {
-	if ($layout eq 'book') {
-	    if ($numberofcolumns == 1) {
-		$textwidth = '6.8 in';      
-		$textheight = '9 in';    
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '1.2 in';
-	    } elsif ($numberofcolumns == 2) {
-		$textwidth = '3.1 in';     
-		$textheight = '9 in';    
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '1.2 in';
-	    }
-	} elsif ($layout eq 'album') {
-	    if ($numberofcolumns eq '1') {
-#		$textwidth = '8.8 in';
-#		$textheight = '6.8 in';
-#		$oddoffset = '-40 pt';
-#		$evenoffset = '-60 pt';
-	    } elsif ($numberofcolumns == 2) {
-#		$textwidth = '4.4 in';
-#		$textheight = '6.8 in';
-#		$oddoffset = '-0.5 in';
-#		$evenoffset = '-1.5 in';
-#		$topmargin = '3.5 in';
-	    }
-	}
-    } elsif($papersize eq '6') {
-	if ($layout eq 'book') {
-	    if ($numberofcolumns == 1) {
-		$textwidth = '176 mm';
-		$textheight = '272 mm';
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '-0.5 in';
-	    } elsif ($numberofcolumns == 2) {
-		$textwidth = '91 mm';
-		$textheight = '272 mm';
-		$oddoffset = '-0.57 in';
-		$evenoffset = '-0.57 in';
-		$topmargin = '-0.5 in';
-	    }
-	} elsif ($layout eq 'album') {
-	    if ($numberofcolumns eq '1') {
-		$textwidth = '8.5 in';
-		$textheight = '7.7 in';
-		$oddoffset = '-40 pt';
-		$evenoffset = '-60 pt';
-	    } elsif ($numberofcolumns == 2) {
-		$textwidth = '3.9 in';
-		$textheight = '7.7 in';
-		$oddoffset = '-40 pt';
-		$evenoffset = '-60 pt';
-	    }
-	}
-#    } elsif($papersize eq '4') {
-#    } elsif($papersize eq '5') {
-#    } elsif($papersize eq '7') {
-#    } elsif($papersize eq '8') {
-    }
-    return $textwidth,$textheight,$oddoffset,$evenoffset,$topmargin;
+    my $page_formats={'book'=>{
+	'1'=>{'letter'=>{'width'=>'7.1 in','height'=>'10.2 in','topmargin'=>'0 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',
+	      },
+	      'legal'=>{'width'=>'7.1 in','height'=>'13 in','topmargin'=>'-0.5 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',
+	      },
+	      'tabloid'=>{'width'=>'9.8 in','height'=>'16 in','topmargin'=>'-0.5 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',
+	      },
+	      'exacutive'=>{'width'=>'6.8 in','height'=>'9 in','topmargin'=>'1.2 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',		  
+	      },
+	      'a2'=>{
+		  
+	      },
+	      'a3'=>{
+		  
+	      },
+	      'a4'=>{'width'=>'176 mm','height'=>'272 mm','topmargin'=>'-0.5 in',
+              'oddsidemargin'=>'-40 pt in','evensidemargin'=>'-60 pt',
+		  
+	      },
+	      'a5'=>{
+		  
+	      },
+	      'a6'=>{
+		  
+	      },
+	  },
+        '2'=>{'letter'=>{'width'=>'3.66 in','height'=>'10.2 in','topmargin'=>'0 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',
+	      },
+	      'legal'=>{'width'=>'3.16 in','height'=>'13 in','topmargin'=>'-0.5 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',		  
+	      },
+	      'tabloid'=>{'width'=>'4.9 in','height'=>'16 in','topmargin'=>'-0.5 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',
+
+	      },
+	      'exacutive'=>{'width'=>'3.1 in','height'=>'9 in','topmargin'=>'1.2 in',
+              'oddsidemargin'=>'-0.57 in','evensidemargin'=>'-0.57 in',	  
+	      },
+	      'a2'=>{
+		  
+	      },
+	      'a3'=>{
+		  
+	      },
+	      'a4'=>{'width'=>'91 mm','height'=>'272 mm','topmargin'=>'-0.5 in',
+              'oddsidemargin'=>'-40 pt in','evensidemargin'=>'-60 pt',
+		  
+	      },
+	      'a5'=>{
+		  
+	      },
+	      'a6'=>{
+		  
+	      },
+
+	},
+    },'album'=>{
+	'1'=>{'letter'=>{'width'=>'8.8 in','height'=>'6.8 in','topmargin'=>'0 in',
+              'oddsidemargin'=>'-40 pt in','evensidemargin'=>'-60 pt',
+	      },
+	      'legal'=>{
+		  
+	      },
+	      'tabloid'=>{
+
+	      },
+	      'exacutive'=>{
+		  
+	      },
+	      'a2'=>{
+		  
+	      },
+	      'a3'=>{
+		  
+	      },
+	      'a4'=>{'width'=>'8.5 in','height'=>'7.7 in','topmargin'=>'0 in',
+              'oddsidemargin'=>'-40 pt in','evensidemargin'=>'-60 pt',
+		  
+	      },
+	      'a5'=>{
+		  
+	      },
+	      'a6'=>{
+		  
+	      },
+	  },
+        '2'=>{'letter'=>{'width'=>'4.4 in','height'=>'6.8 in','topmargin'=>'3.5 in',
+              'oddsidemargin'=>'-0.5 in','evensidemargin'=>'-1.5 in',
+	      },
+	      'legal'=>{
+		  
+	      },
+	      'tabloid'=>{
+
+	      },
+	      'exacutive'=>{
+		  
+	      },
+	      'a2'=>{
+		  
+	      },
+	      'a3'=>{
+		  
+	      },
+	      'a4'=>{'width'=>'3.9 in','height'=>'7.7 in','topmargin'=>'0 in',
+              'oddsidemargin'=>'-40 pt in','evensidemargin'=>'-60 pt',
+		  
+	      },
+	      'a5'=>{
+		  
+	      },
+	      'a6'=>{
+		  
+	      },
+
+	     },
+ 	  },
+    };	    
+    return $page_formats->{$layout}->{$numberofcolumns}->{$papersize}->{'width'},
+           $page_formats->{$layout}->{$numberofcolumns}->{$papersize}->{'height'},
+           $page_formats->{$layout}->{$numberofcolumns}->{$papersize}->{'oddmargin'},
+           $page_formats->{$layout}->{$numberofcolumns}->{$papersize}->{'evensidemargin'},
+           $page_formats->{$layout}->{$numberofcolumns}->{$papersize}->{'topmargin'};
 }
 
 
@@ -585,7 +560,7 @@
 	} else {
 	    $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\\setcounter{page}{1}  \\vskip 5 mm /;
 	}
-	if ($papersize eq '6') {
+	if ($papersize eq 'a4') {
 	    $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/;
 	}
     }
@@ -1345,6 +1320,9 @@
 	}
     }
 
+    &Apache::lonnet::logthis("SSSSSSS: $filename,$laystyle,$papersize,$numberofcolumns,$selectionmade,$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$ENV{'request.role.adv'},$#print_array,$student_names,$URLback");
+
+
     &Apache::lonnet::appenv('cgi.'.$identifier.'.file'   => $filename,
                             'cgi.'.$identifier.'.layout'  => $laystyle,
                             'cgi.'.$identifier.'.numcol'  => $numberofcolumns,
@@ -1712,7 +1690,7 @@
     </state>
 HELPERFRAGMENT
 
-        &Apache::lonxml::xmlparse($r, 'helper', $helperFragment); 
+	&Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
     }
 
     # If the user is priviledged, allow them to print all 
@@ -2064,10 +2042,10 @@
 use Apache::lonlocal;
 
 my $maxColumns = 2;
-my @paperSize = ("Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]", 
-                 "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
-                 "A2 [420x594 mm]", "A3 [297x420 mm]", "A4 [210x297 mm]", 
-                 "A5 [148x210 mm]", "A6 [105x148 mm]" );
+my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", 
+                 "tabloid (ladger) [11x17 in]", "executive [7 1/2x10 in]",
+                 "a2 [420x594 mm]", "a3 [297x420 mm]", "a4 [210x297 mm]", 
+                 "a5 [148x210 mm]", "a6 [105x148 mm]" );
 
 # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
 #                   Paper type
@@ -2127,14 +2105,15 @@
     if ($DefaultPaperSize eq '') {$DefaultPaperSize='letter';}
     $i = 0;
     foreach (@paperSize) {
+	$_=~/(\w+)/;
+	my $papersize=$1;
         if ($paperSize[$i]=~/$DefaultPaperSize/) {
-            $result .= "<option selected value='$i'>" . $paperSize[$i] . "</option>\n";
+            $result .= "<option selected value='$papersize'>" . $paperSize[$i] . "</option>\n";
         } else {
-            $result .= "<option value='$i'>" . $paperSize[$i] . "</option>\n";
+            $result .= "<option value='$papersize'>" . $paperSize[$i] . "</option>\n";
         }
         $i++;
     }
-
     $result .= "</select></td></tr></table>";
     return $result;
 }
Index: loncom/interface/printout.pl
diff -u loncom/interface/printout.pl:1.66 loncom/interface/printout.pl:1.67
--- loncom/interface/printout.pl:1.66	Fri Aug 13 13:14:48 2004
+++ loncom/interface/printout.pl	Wed Aug 18 14:56:46 2004
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
 #
-# $Id: printout.pl,v 1.66 2004/08/13 17:14:48 sakharuk Exp $
+# $Id: printout.pl,v 1.67 2004/08/18 18:56:46 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -209,8 +209,7 @@
 			     \%prog_state,$dvi_file);
       } #to create index
       #Do we have a latex error in the log file?
-      my $logfilename = $texfile;
-      $logfilename =~ s/\.tex$/\.log/;
+      my $logfilename = $texfile; $logfilename =~ s/\.tex$/\.log/;
       my $temporary_file=IO::File->new($logfilename) || die "Couldn't open file for reading: $!\n";
       my @content_of_file = <$temporary_file>;
       close $temporary_file; 
@@ -274,8 +273,7 @@
 	  $name_file =~ s/\.tex/\.dvi/;
 	  my $new_name_file = $name_file;
 	  $new_name_file =~ s/\.dvi/\.ps/;
-	  my @papers=('letter','legal','tabloid','executive','','a3','a4','a5','');
-	  my $papera=$papers[$paper];
+	  my $papera=$paper;
 	  if ($papera eq 'letter') {$papera='';}
 	  if ($papera ne '') {$papera='-t'.$papera;}
 	  my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file";
@@ -293,8 +291,8 @@
 				     "for $status_statement now Modifying PS layout",
 				     \%prog_state,$tempo_file); 
 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
-		  my @papers=('letter','legal','tabloid','executive','','a3','a4','a5','');
-                  my $papera=$papers[$paper];
+		  my $papera=$paper;
+                  if ($papera eq 'letter') {$papera='';}
 		  if ($papera ne '') {$papera='-p'.$papera;}
 		  $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"';
 		  &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null",
@@ -346,8 +344,7 @@
 	  $name_file =~ s/\.tex/\.dvi/;
 	  my $new_name_file = $name_file;
 	  $new_name_file =~ s/\.dvi/\.ps/;
-	  my @papers=('letter','legal','tabloid','executive','','a3','a4','a5','');
-	  my $papera=$papers[$paper];
+	  my $papera=$paper;
 	  if ($papera eq 'letter') {$papera='';}
 	  if ($papera ne '') {$papera='-t'.$papera;}
 	  my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file";
@@ -373,24 +370,21 @@
 	      } else {
 		  $ps_file=$new_name_file;
 	      }
-	      if (($paper eq '6') or ($paper eq '1') or ($paper eq '2') or ($paper eq '3') 
-               or ($paper eq '4') or ($paper eq '5') or ($paper eq '7') or ($paper eq '8')) {
+	      my $addtoPSfile={'legal'=>'<< /PageSize [612 1008] >> setpagedevice',
+                               'tabloid'=>'<< /PageSize [792 1224] >> setpagedevice',
+                               'executive'=>,'<< /PageSize [540 720] >> setpagedevice',
+                               'a2'=>'<< /PageSize [1195.02 1690.09] >> setpagedevice',
+                               'a3'=>'<< /PageSize [842 1195.02] >> setpagedevice',
+                               'a4'=>'<< /PageSize [595.2 842] >> setpagedevice',
+                               'a5'=>'<< /PageSize [421.1 595.2] >> setpagedevice',
+                               'a6'=>'<< /PageSize [298.75 421.1] >> setpagedevice',
+			   };
+	      if ($paper ne 'letter') {
 		  open(FFH,'<',$ps_file) || die "Couldn't open file for reading: $!\n";
 		  my $new_ps_file='new'.$ps_file;
 		  open(FFHS,'>',$new_ps_file) || die "Couldn't open file for reading: $!\n";
-		  my $i=-1;
+		  print FFHS $addtoPSfile->{$paper}."\n";
 		  while (<FFH>) {
-		      $i++;
-		      if ($i==0) {
-			  if ($paper eq '6') {print FFHS '<< /PageSize [595.2 842] >> setpagedevice'."\n";}
-			  if ($paper eq '1') {print FFHS '<< /PageSize [612 1008] >> setpagedevice'."\n";}
-			  if ($paper eq '2') {print FFHS '<< /PageSize [792 1224] >> setpagedevice'."\n";}
-			  if ($paper eq '3') {print FFHS '<< /PageSize [542 722.7] >> setpagedevice'."\n";}
-			  if ($paper eq '4') {print FFHS '<< /PageSize [1195.02 1690.09] >> setpagedevice'."\n";}
-			  if ($paper eq '5') {print FFHS '<< /PageSize [842 1195.02] >> setpagedevice'."\n";}
-			  if ($paper eq '7') {print FFHS '<< /PageSize [421.1 595.2] >> setpagedevice'."\n";}
-			  if ($paper eq '8') {print FFHS '<< /PageSize [298.75 421.1] >> setpagedevice'."\n";}
-		      } 
 		      print FFHS $_;
 		  }
 		  close(FFH);

--sakharuk1092855406--