#!/usr/bin/perl #Copyright (c) 2002, 2012 KAMICHI, Koichi(kamichi@fonts.jp) #Last updated: 27 February, 2012. use utf8; binmode STDOUT, ":utf8"; use CGI; $fullsp = " "; $page = "頁"; $top = "初"; $prev = "前"; $next = "次"; $end = "終"; @number = ("〇", "一", "二", "三", "四", "五", "六", "七", "八", "九"); #ファイルからデータを読み込む sub getdata{ while(1){ #データが終わりであれば空白文字を返す if(eof FH || $eod eq "yes"){ $res = $fullsp; #EOFのときもeodを立てる $eod = "yes"; return; } else{ #本文が来るまで読む if($isstart eq "no"){ while($isstart eq "no"){ $res = ; if(not $res =~ m//i){ $beforebody = $beforebody.$res; next; } $res = $'; $beforebody = $beforebody.$`; $isstart = "yes"; #タイトルを探す $beforebody =~ m/(.+)<\/title>/i; $title = $1; } } #データを読み込む else{ $res = <FH>; #改行コードカット chomp($res); #</body>が来たら終わり if($res =~ m/<\/body>/i){ $res = $`; $eod = "yes"; } if(length($res) != 0){ return; } } } } } #小字データが何文字かをカウント sub countsmall{ $count = length($ressmall); } #小字データを1文字読み込む sub getdatasmall{ $ressmallchar = substr($ressmall, 0, 1); $ressmall = substr($ressmall, 1); } $cgi = new CGI; $filename = $cgi->param('filename'); if($filename eq ""){ $filename = "default.html"; } open FH,"<:utf8", "$filename" or die "cannot open $dbf : $!"; $pages = $cgi->param('pages'); if($pages eq ""){ $pages = 1; } $lastpage = $pages; $isstart = "no"; $beforebody = ""; $title = ""; $eod = "no"; print <<'EOF'; Content-type: text/html <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style> * { margin: 0px; padding: 0px; line-height: 0px; } body { margin: 24px 0 0 0; } td { vertical-align: top; text-align: center; font-family: HanaMinA,HanaMinB,花園明朝A,花園明朝B; } span.c1 { font-size: 32px; line-height: 30px; } span.c2 { font-size: 15px; line-height: 15px; } span.c1t { font-size: 0px; line-height: 0px; } span.c2t { font-size: 0px; line-height: 0px; } span.c3 { font-size: 15px; line-height: 20px; } </style> </head> <body background="back.gif" style="background-repeat: no-repeat;"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td width="6"></td> EOF while($lastpage > 0){ $mode = "big"; $lastline = 20; $res = ""; $ressmall = ""; while($lastline >= 0){ $linebuf = "<td width='43'>"; $lastchar = 17; while($lastchar > 0){ #大字 if($mode eq "big"){ if(length($res) == 0){ &getdata; } if(substr($res,0,1) eq "<"){ #改行タグ if(substr($res,0,4) =~ m/<br>/i){ #残りを空白文字で埋める while($lastchar > 0){ $linebuf = $linebuf."<span class='c1'>$fullsp</span><br>"; $lastchar--; } $res = substr($res,4); next; } #小字タグ elsif(substr($res,0,7) =~ m/<small>/i){ $mode = "small"; $res = substr($res,7); #小字データの準備 $ressmall = $res; while(not $ressmall =~ m/<\/small>/i){ &getdata; $ressmall = $ressmall.$res; } #小字タグの整形 $ressmall =~ s/<\/small>/<\/small>/i; #小字データと残りデータの分割 $res = substr($ressmall, index($ressmall, "</small>") + 8); $ressmall = substr($ressmall, 0, index($ressmall, "</small>")); #タグは無視する $ressmall =~ s/<.+>//; next; } #その他のタグは無視する else{ $res =~ s/<.+>//; } } #行の始まり(大字) if($lastchar == 17){ $linebuf = $linebuf."<span class='c1t'>$fullsp</span><br>"; } #文字の代入 $linebuf = $linebuf."<span class='c1'>".substr($res,0,1)."</span><br>"; $res = substr($res,1); $lastchar--; } #小字 else{ if(length($ressmall) == 0){ $mode = "big"; next; } #何文字入るか計算 &countsmall; $range = $count; if(int(($range + 3) / 4) > $lastchar){ $range = $lastchar * 4; } #左と右の文字数計算 $rangeleft = int($range / 2); $rangeright = int(($range + 1) / 2); #小字の始まり #$bufright = "<td width='18'><span class='c2t'>$fullsp</span><br>"; #$bufleft = "<td width='18'><span class='c2t'>$fullsp</span><br>"; #$bufright = "<td width='18'><span class='c2t'></span><br>"; #$bufleft = "<td width='18'><span class='c2t'></span><br>"; $bufright = "<td width='18' style='padding: 2px 0 0 0;'>"; $bufleft = "<td width='18' style='padding: 2px 0 0 0;'>"; #代入(右側) while($rangeright > 0){ &getdatasmall; $bufright = $bufright."<span class='c2'>$ressmallchar</span><br>"; $rangeright--; } #あまり部分に空白文字代入(右側) if($range % 4 == 1 || $range % 4 == 2){ $bufright = $bufright."<span class='c2'>$fullsp</span><br>"; } #代入(左側) while($rangeleft > 0){ &getdatasmall; $bufleft = $bufleft."<span class='c2'>$ressmallchar</span><br>"; $rangeleft--; } #あまり部分に空白文字代入(左側) if($range % 4 == 1){ $bufleft = $bufleft."<span class='c2'>$fullsp</span><br>"; } if($range % 4 != 0){ $bufleft = $bufleft."<span class='c2'>$fullsp</span><br>"; } #htmlに出力 $smallbuf = "<table cellpadding='0' cellspacing='0'><tr><td width='2'></td>".$bufleft."</td><td width='1'></td>".$bufright."</td></tr></table>"; $linebuf = $linebuf.$smallbuf; $lastchar = $lastchar - int(($range + 3) / 4); } } $linebuf = $linebuf."</td>"; $buf[$lastline] = $linebuf; $lastline--; #版心 if($lastline == 10){ if($pages >= 20 && $pages % 10 != 0){ $numpages = $number[int($pages / 10)].$number[0].$number[$pages % 10]; } elsif($pages >= 20){ $numpages = $number[int($pages / 10)].$number[0]; } elsif($pages > 10){ $numpages = $number[0].$number[$pages % 10]; } elsif($pages == 10){ $numpages = $number[0]; } else{ $numpages = $number[$pages % 10]; } $buf[$lastline] = "<td width='10'></td><td width='33'><table cellpadding='0' cellspacing='0' height='100%'><tr><td width='20' height='170' valign='top'><span class='c2t'> </span></td></tr><tr><td width='20' height='140' valign='top'><span class='c2'>$title</span></td></tr><tr><td width='20' height='50' valign='top'><span class='c2'>$numpages</span></td></tr></table></td>"; $lastline--; } } $lastpage--; } #html書き込み if($pages == 1){ $prevpages = 1; } else{ $prevpages = $pages - 1; } $nextpages = $pages + 1; print "<td width='43' valign='top'><span class='c3'>"; if($pages != 1){ print "<a href='view.cgi?filename=$filename'>$top$page</a><br><a href='view.cgi?filename=$filename&pages=$prevpages'>$prev$page</a><br>"; } else{ print "$top$page<br>$prev$page<br>"; } if($eod eq "yes"){ print "$next$page<br>"; } else{ print "<a href='view.cgi?filename=$filename&pages=$nextpages'>$next$page</a><br>"; } print "$end$page<br></span></td><td width='13'></td>"; foreach(@buf){ print $_; } close FH; print <<'EOF'; </tr> </table> </div> </body> </html> EOF