#! /usr/bin/perl # # fix-ps-dpi.pl -- pnmtopsが吐いたPSファイルの解像度を修正 # # revision history: # 0.0: by Dai ISHIJIMA # # usage: # perl fix-ps-dpi.pl -dpi # # example: # djpeg -grayscale hogehoge.jpg | pnmtops -dpi 300 -scale 0.25 | # perl fix-ps-dpi.pl -300 | perl fix-ps-bbox.pl | # perl halftome.pl -f 60 > hogehoge.ps # $points = 72; $paperwidth = 210 / 25.4 * $points; $paperheight = 297 / 25.4 * $points; $dpi = 300; if ($ARGV[0] =~ /^-[0-9]+/) { $dpi = -$ARGV[0]; } while () { print; if (/^gsave/) { last; } } print "% % % %\n"; $_ = ; if (!(/([0-9.]+)\s+([0-9.]+)\s+translate/)) { print "% translate mismatch\n"; print; } else { $xoff = $1; $yoff = $2; print "% $xoff, $yoff\n"; } $_ = ; if (!(/([0-9.]+)\s+([0-9.]+)\s+scale/)) { print "% scale mismatch\n"; print; } else { $xscale = $1; $yscale = $2; print "% $xscale, $yscale\n"; } $rotataion = ""; $_ = ; if (!(/.*translate.*rotate.*translate/)) { print "% no rotation\n"; } else { $rotation = $_; } if ($rotation ne "") { $_ = ; } if (!(/([0-9.]+)\s+([0-9.]+)\s+([0-9.]+)/)) { print "% width, height, depth mismatch\n"; print; } else { $width = $1; $height = $2; $depth = $3; print "% $width $height $depth\n"; } if ($rotation eq "") { $picwidth = $width / $dpi * $points; $picheight = $height / $dpi * $points; } else { $picwidth = $height / $dpi * $points; $picheight = $width / $dpi * $points; } $xoffnew = ($paperwidth - $picwidth) / 2; $yoffnew = ($paperheight - $picheight) / 2; printf "%.2f %.2f translate\n", $xoffnew, $yoffnew ; printf "%.2f %.2f scale\n", $picwidth, $picheight ; print "$rotation"; print "$width $height $depth\n"; while () { print; }