Diff for /gobook-pdf-strips.perl between versions 3.1 and 3.2

version 3.1, 2017/08/30 22:29:14 version 3.2, 2019/03/02 09:00:46
Line 7  use GD; Line 7  use GD;
   
 $Text::Wrap::columns = 30;  $Text::Wrap::columns = 30;
   
   # The landout database ...
 my $strips = XMLin('OmLand.gpx');  my $strips = XMLin('OmLand.gpx');
   
   # The photos of the landouts ...
   my $pics = "/export/extra/map/landoutbook/";
   
   # The map fragments ...
   my $maps = "/var/www/htdocs/landout/";
   
 my $t1 = 10;  my $t1 = 10;
 my $t2 = $t1 + 20;  my $t2 = $t1 + 20;
 my $t3 = $t1 + 50;  my $t3 = $t1 + 50;
Line 26  use constant pt => 1; Line 33  use constant pt => 1;
   
   
   
 # Start the strip pages with pictures:  # Make all the gobook pages.
   
 foreach my $stripnum ( sort keys %{$strips->{'wpt'}} ){  foreach my $stripnum ( sort keys %{$strips->{'wpt'}} ){
  if ( $strips->{'wpt'}->{$stripnum}->{'extensions'}->{gobook} eq "yes" ){   #if ( $strips->{'wpt'}->{$stripnum}->{'extensions'}->{gobook} eq "yes" ){
   $strips{$strips->{'wpt'}->{$stripnum}->{'desc'}} = $stripnum;  
   my $pagename = "/map/landout" . $stripnum . ".pdf";  
   my $pdf = PDF::API2->new( -file => $pagename );  
   
   my %font = (  
    Helvetica => {  
     Bold   => $pdf->corefont( 'Helvetica-Bold',    -encoding => 'latin1' ),  
     Roman  => $pdf->corefont( 'Helvetica',         -encoding => 'latin1' ),  
     Italic => $pdf->corefont( 'Helvetica-Oblique', -encoding => 'latin1' ),  
    },  
    Times => {  
     Bold   => $pdf->corefont( 'Times-Bold',   -encoding => 'latin1' ),  
     Roman  => $pdf->corefont( 'Times',        -encoding => 'latin1' ),  
     Italic => $pdf->corefont( 'Times-Italic', -encoding => 'latin1' ),  
    },  
   );  
   
   print "Working on $stripnum\n";    print "Working on $stripnum\n";
     # %strips is used for the index. Add the current strip.
   # create a new page for the pic and data    $strips{$strips->{'wpt'}->{$stripnum}->{'desc'}} = $stripnum;
   my $page = $pdf->page;    process_strip($stripnum);
   # A5 148 x 210  
   $page->mediabox('A5');  
   my $text = $page->text;  
   $text->font( $font{'Helvetica'}{'Roman'}, 20 );  
   $text->fillcolor('blue');  
   $text->translate( 10/mm, 195/mm );  
   $text->text($strips->{'wpt'}->{$stripnum}->{'desc'});  
   $text->translate(125/mm,195/mm);  
   $text->text($stripnum);  
   $text->fillcolor('black');  
   $text->font( $font{'Helvetica'}{'Roman'}, 14 );  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'ele'} ){  
    $text->translate($t5/mm,195/mm);  
    $text->text(printfeet($strips->{'wpt'}->{$stripnum}->{'ele'}));  
   }  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'length'} ){  
    $text->translate($t6/mm,195/mm);  
    $text->text($strips->{'wpt'}->{$stripnum}->{'extensions'}->{'length'} . 'm');  
   }  
   $text->font( $font{'Helvetica'}{'Roman'}, 10 );  
   my $latlng = printlat($strips->{'wpt'}->{$stripnum}->{'lat'}) . " " .   
                printlon($strips->{'wpt'}->{$stripnum}->{'lon'});  
   $text->translate($t1/mm,190/mm);  
   $text->text($latlng);  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'slope'} ){  
    $text->translate(($t1 + 45)/mm,190/mm);  
   $text->text('Slope: ' . $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'slope'});  
   }  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{surface} ){  
   $text->translate($t5/mm,190/mm);  
   $text->text('Sfc: ' . $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'surface'});  
   }  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'width'} ){  
    $text->translate($t6/mm,190/mm);  
    $text->text('Width: ' . $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'width'});  
   }  
   
   my $stripimage=$page->gfx;  
   my $pic = "/map/landoutbook/250k/". $stripnum . ".jpg";  
   if ( -f $pic ){  
    my $image = GD::Image->new($pic);  
    my ($width,$height) = $image->getBounds();  
    print "\t$pic - $width $height\n";  
    my $strip_pic = $pdf->image_gd($image);  
    # width available is 65mm  
    my $scale = 65 / $width;  
    print "\tDisplay Width 65mm Height ", $height * $scale, "\n";  
    my $vertical = $height * $scale;  
    $stripimage->image( $strip_pic, $t1/mm, 105/mm, 65/mm, $vertical/mm );  
   }  
   
   my $strippic = "/map/landoutbook/". $stripnum . ".jpg";  
   if ( -f $strippic ){  
    my $image = GD::Image->new($strippic);  
    my ($width,$height) = $image->getBounds();  
    print "\t$strippic - $width $height\n";  
    # width available is 120mm  
    my $scale = 120 / $width;  
    print "\tDisplay Width 120mm Height ", $height * $scale, "\n";  
    my $vertical = $height * $scale;  
    my $strip_pic = $pdf->image_gd($image);  
    $stripimage->image( $strip_pic, $t1/mm, 10/mm, 120/mm, $vertical/mm );  
   }  
   
    
  #$eps = "L" . $stripnum . ".ps";  
  #if ( -f $eps ){  
  # $p->importepsfile($eps,$t1,10, 140,100);  
  #}  
  #else {  
  # $p->setcolour(255,54,0); # Glide Omarama Orange  
  # $p->setfont("Helvetica", 32);  
  # $p->text({rotate => 45}, $t2 ,20, 'No picture yet' );  
  # $p->setcolour("black");  
  #}   #}
   my $v = 185;  
   $text->font( $font{'Helvetica'}{'Roman'}, 12 );  
   
   $text->translate($t5/mm,$v/mm);  
   $text->text("Location:");  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'} ){  
    $v -= 5;  
    $Text::Wrap::columns = 30;  
    my @para = split (/\n/,wrap('', '', $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'}));  
    while (my $ln = shift @para){  
     $text->translate($t5/mm,$v/mm);  
     $text->text($ln);  
     $v -= 5;  
    }  
    $v += 5;  
   }  
   $v -= 10;  
   
   $text->translate($t5/mm,$v/mm);  
   $text->text("Comment:");  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'comment'} ){  
    $v -= 5;  
    $Text::Wrap::columns = 30;  
    if ( $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'comment'} =~ /Danger/ ){  
     #$p->setcolour("red");  
     # Draw over image ...  
     #$p->setlinewidth(4);  
     #$p->arc( 70, 60, 20, 0, 360);  
     #$p->line(50,40, 90,80);  
    }  
    my @para = split (/\n/,wrap('', '', $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'comment'}));  
    while (my $ln = shift @para){  
     $text->translate($t5/mm,$v/mm);  
     $text->text($ln);  
     $v -= 5;  
    }  
    $v += 5;  
    $text->fillcolor('black');  
   }  
   $v -= 10;  
   
   $text->translate($t5/mm,$v/mm);  
   $text->text("Alternate:");  
   if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'alternate'} ){  
    $v -= 5;  
    $Text::Wrap::columns = 30;  
    my @para = split (/\n/,wrap('', '', $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'alternate'}));  
    while (my $ln = shift @para){  
     $text->translate($t5/mm,$v/mm);  
     $text->text($ln);  
     $v -= 5;  
    }  
    $v += 5;  
   }  
   $pdf->save;  
   $pdf->end();  
  }  
 }  }
   
 # Create the index pages  # Create the index pages
 my $pagename = "/map/landoutIndex.pdf";  my $pagename = "/export/extra/map/landoutIndex.pdf";
 my $pdf = PDF::API2->new( -file => $pagename );  my $pdf = PDF::API2->new( -file => $pagename );
   
 my %font = (  my %font = (
Line 280  sub printfeet { Line 139  sub printfeet {
  return sprintf("%d ft", int($meters * 3.2808399));   return sprintf("%d ft", int($meters * 3.2808399));
 }  }
   
   sub process_strip {
    my $stripnum = shift(@_);
   
    my $pagename = "/var/www/htdocs/landout/" . $stripnum . ".pdf";
    my $pdf = PDF::API2->new( -file => $pagename );
   
    my %font = (
     Helvetica => {
      Bold   => $pdf->corefont( 'Helvetica-Bold',    -encoding => 'latin1' ),
      Roman  => $pdf->corefont( 'Helvetica',         -encoding => 'latin1' ),
      Italic => $pdf->corefont( 'Helvetica-Oblique', -encoding => 'latin1' ),
     },
     Times => {
      Bold   => $pdf->corefont( 'Times-Bold',   -encoding => 'latin1' ),
      Roman  => $pdf->corefont( 'Times',        -encoding => 'latin1' ),
      Italic => $pdf->corefont( 'Times-Italic', -encoding => 'latin1' ),
     },
    );
   
   
    # create a new page for the pic and data
    my $page = $pdf->page;
    # A5 148 x 210
    $page->mediabox('A5');
    my $text = $page->text;
    $text->font( $font{'Helvetica'}{'Roman'}, 20 );
    $text->fillcolor('blue');
    $text->translate( 10/mm, 195/mm );
    $text->text($strips->{'wpt'}->{$stripnum}->{'desc'});
    $text->translate(125/mm,195/mm);
    $text->text($stripnum);
    $text->fillcolor('black');
    $text->font( $font{'Helvetica'}{'Roman'}, 14 );
    if ( defined $strips->{'wpt'}->{$stripnum}->{'ele'} ){
     $text->translate($t5/mm,195/mm);
     $text->text(printfeet($strips->{'wpt'}->{$stripnum}->{'ele'}));
    }
    if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'length'} ){
     $text->translate($t6/mm,195/mm);
     $text->text($strips->{'wpt'}->{$stripnum}->{'extensions'}->{'length'} . 'm');
    }
    $text->font( $font{'Helvetica'}{'Roman'}, 10 );
    my $latlng = printlat($strips->{'wpt'}->{$stripnum}->{'lat'}) . " " . 
                 printlon($strips->{'wpt'}->{$stripnum}->{'lon'});
    $text->translate($t1/mm,190/mm);
    $text->text($latlng);
    if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'slope'} ){
     $text->translate(($t1 + 45)/mm,190/mm);
     $text->text('Slope: ' . $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'slope'});
    }
    if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{surface} ){
     $text->translate($t5/mm,190/mm);
     $text->text('Sfc: ' . $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'surface'});
    }
    if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'width'} ){
     $text->translate($t6/mm,190/mm);
     $text->text('Width: ' . $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'width'});
    }
   
    my $stripimage=$page->gfx;
    my $pic = $maps . $stripnum . "-250k.jpg";
    if ( -f $pic ){
     my $image = GD::Image->new($pic);
     my ($width,$height) = $image->getBounds();
     print "\t$pic - $width $height\n";
     my $strip_pic = $pdf->image_gd($image);
     # width available is 65mm
     my $scale = 65 / $width;
     print "\tDisplay Width 65mm Height ", $height * $scale, "\n";
     my $vertical = $height * $scale;
     $stripimage->image( $strip_pic, $t1/mm, 115/mm, 65/mm, $vertical/mm );
    }
   
    my $strippic = $pics . $stripnum . ".jpg";
    if ( -f $strippic ){
     my $image = GD::Image->new($strippic);
     my ($width,$height) = $image->getBounds();
     print "\t$strippic - $width $height\n";
     # width available is 120mm
     my $scale = 120 / $width;
     print "\tDisplay Width 120mm Height ", $height * $scale, "\n";
     my $vertical = $height * $scale;
     my $strip_pic = $pdf->image_gd($image);
     $stripimage->image( $strip_pic, $t1/mm, 10/mm, 120/mm, $vertical/mm );
    }
    else {
     $strippic = $maps . $stripnum . "-50k.jpg";
     if ( -f $strippic ){
      my $image = GD::Image->new($strippic);
      my ($width,$height) = $image->getBounds();
      print "\t$strippic - $width $height\n";
      # width available is 120mm
      my $scale = 100 / $width;
      print "\tDisplay Width 100mm Height ", $height * $scale, "\n";
      my $vertical = $height * $scale;
      my $strip_pic = $pdf->image_gd($image);
      $stripimage->image( $strip_pic, $t1/mm, 10/mm, 100/mm, $vertical/mm );
     }
    }
   
    
    #$eps = "L" . $stripnum . ".ps";
    #if ( -f $eps ){
    # $p->importepsfile($eps,$t1,10, 140,100);
    #}
    #else {
    # $p->setcolour(255,54,0); # Glide Omarama Orange
    # $p->setfont("Helvetica", 32);
    # $p->text({rotate => 45}, $t2 ,20, 'No picture yet' );
    # $p->setcolour("black");
    #}
    my $v = 185;
    $text->font( $font{'Helvetica'}{'Roman'}, 12 );
   
    $text->translate($t5/mm,$v/mm);
    $text->text("Location:");
    if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'} ){
     $v -= 5;
     $Text::Wrap::columns = 30;
     my @para = split (/\n/,wrap('', '', $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'location'}));
     while (my $ln = shift @para){
      $text->translate($t5/mm,$v/mm);
      $text->text($ln);
      $v -= 5;
     }
     $v += 5;
    }
    $v -= 10;
   
    $text->translate($t5/mm,$v/mm);
    $text->text("Comment:");
    if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'comment'} ){
     $v -= 5;
     $Text::Wrap::columns = 30;
     if ( $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'comment'} =~ /Danger/ ){
      #$p->setcolour("red");
      # Draw over image ...
      #$p->setlinewidth(4);
      #$p->arc( 70, 60, 20, 0, 360);
      #$p->line(50,40, 90,80);
     }
     my @para = split (/\n/,wrap('', '', $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'comment'}));
     while (my $ln = shift @para){
      $text->translate($t5/mm,$v/mm);
      $text->text($ln);
      $v -= 5;
     }
     $v += 5;
     $text->fillcolor('black');
    }
    $v -= 10;
   
    $text->translate($t5/mm,$v/mm);
    $text->text("Alternate:");
    if ( defined $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'alternate'} ){
     $v -= 5;
     $Text::Wrap::columns = 30;
     my @para = split (/\n/,wrap('', '', $strips->{'wpt'}->{$stripnum}->{'extensions'}->{'alternate'}));
     while (my $ln = shift @para){
      $text->translate($t5/mm,$v/mm);
      $text->text($ln);
      $v -= 5;
     }
     $v += 5;
    }
    $pdf->save;
    $pdf->end();
   }

Removed from v.3.1  
changed lines
  Added in v.3.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>