]> www.wagner.pp.ru Git - fiction/Kate-the-Empress.git/commitdiff
Tex2fb2 with cover page support
authorVictor Wagner <vitus@wagner.pp.ru>
Sat, 21 Dec 2013 11:33:42 +0000 (15:33 +0400)
committerVictor Wagner <vitus@wagner.pp.ru>
Sat, 21 Dec 2013 11:33:42 +0000 (15:33 +0400)
Tex2fb2
fb2meta.xml

diff --git a/Tex2fb2 b/Tex2fb2
index 30988082287d8c4345292a34f511a10b60ca4e66..96279b391b0062e4b4afdb8b8e21ceddb3366ecd 100755 (executable)
--- a/Tex2fb2
+++ b/Tex2fb2
@@ -1,6 +1,7 @@
 #!/usr/bin/perl -CDS
 use utf8;
 use POSIX qw(strftime);
+use MIME::Base64;
 # char-level modes
 my $poetry = 0;
 my $verbatim = 0;
@@ -19,6 +20,7 @@ print "<FictionBook xmlns=\"http://www.gribuser.ru/xml/fictionbook/2.0\"
 xmlns:l=\"http://www.w3.org/1999/xlink\">\n";
 my $metadata = shift @ARGV;
 open F,"<",$metadata;
+my $pics = "";
 while (<F>) {
        # Replace empty date with current date
        if (/<date\s+\/>/ || /<date>\s*<\/date>/) {
@@ -30,6 +32,15 @@ while (<F>) {
                my $ver = $1+time()/1E10;
                $_=tag(sprintf("%g",$ver),"version")."\n";
        }
+       # Если  существует cover.png, добавляем coverpage
+       if (/<coverpage \/>/) {
+               $_="";
+               if (-f "cover.png") { 
+                       my $id = "cover_png";
+                       $_ = "<coverpage>\n<image l:href=\"#$id\" />\n</coverpage>\n";
+                       $pics .= mkbinary("cover.png",$id);
+               }
+       }
        print $_;
 }
 close F;
@@ -137,6 +148,7 @@ while (@sections) {
 print "</body>\n";
 ## print footnotes
 print "<body>\n$footnotes\n</body>" if $footnotes;
+print $pics;
 print "</FictionBook>";
 
 sub add_to_section {
@@ -207,3 +219,14 @@ sub push_footnote {
        $footnotes.="<section id=\"$id\">".tag(shift,'p')."</section>\n";
        return "<a l:href=\"#$id\" type=\"note\">$idseq</a>";
 }
+
+sub mkbinary {
+       my ($filename,$id) = @_;
+       my $f;
+       open $f,"<",$filename;
+       binmode $f;
+       local $/;
+       my $data = encode_base64(<$f>);
+       return "<binary id=\"$id\" content-type=\"image/png\">$data</binary>\n";
+       close $f;
+}
index f1d2f9d744227b96f23524fd4f426818cc5ee78a..058f11409c95492b4dbaee557afddaf2bd170763 100644 (file)
@@ -21,6 +21,7 @@
 него одного.</p>
 </annotation>
 <date value="2014-01-01">1994-2014</date>
+<coverpage />
 <lang>ru</lang>
 </title-info>
 <document-info>