my $FILENAME_SEPARATOR = '/';
-my $RXP = '/usr/bin/rxp';
-my $CP = '/bin/cp';
-my $MV = '/bin/mv';
-my $TAR = '/bin/tar';
-my $ZIP = '/usr/bin/zip';
-my $BZIP2 = '/bin/bzip2';
-my $JAVA = '/usr/bin/java';
+my $RXP = qx{which rxp};
+my $CP = qx{which cp};
+my $MV = qx{which mv};
+my $TAR = qx{which tar};
+my $ZIP = qx{which zip};
+my $BZIP2 = qx{which bzip2};
+my $JAVA = qx{which java};
+# Note: In Debian/Ubuntu the Xalan processor is provided in the package libxalan2-java
my $XALAN_JAR = '/usr/share/java/xalan2.jar';
-my $RM = '/bin/rm';
-my $CHMOD = '/bin/chmod';
+# Old version of Xalan processor (Xalan 1)
+#my $XALAN_JAR = '/usr/share/ant/lib/xalan.jar';
+my $RM = qx{which rm};
+my $CHMOD = qx{which chmod};
+
+chomp $RXP;
+chomp $CP;
+chomp $MV;
+chomp $TAR;
+chomp $ZIP;
+chomp $BZIP2;
+chomp $JAVA;
+chomp $RM;
+chomp $CHMOD;
# Check that all the binaries are were want them
my $epubXSL = 'common/xsl/epub-xhtml.xsl';
my $metadataXSL = 'common/xsl/epub-opf-metadata.xsl';
my $spineXSL = 'common/xsl/epub-opf-spine.xsl';
-my $coverXSL = 'common/xsl/epub-coverpage.xsl';
-my $fontFiles = "$ENV{'HOME'}${FILENAME_SEPARATOR}souvenir";
+my $fontFiles = "common/fonts";
my $language = 'en';
my $verbose = 0;
unless( -e $fontFiles && -d $fontFiles ) {
die "$PROGRAM_NAME: font files directory does not exist or is not a directory \"$fontFiles\": $!\n";
}
-print qx{$CP $fontFiles${FILENAME_SEPARATOR}*.otf $outPath{'oebps'}};
+print qx{$CP $fontFiles${FILENAME_SEPARATOR}*tf $outPath{'oebps'}};
### write NCX file
close MIMETYPE;
-## write coverpage
-
-# Generate the cover image. This can be done in two ways:
-# 1.- A file is available under the directory of JPEG files for the book
-# 2.- A file is generated using imagemagick
-
-# Cover filename
-my $coverImage = $outPath{'oebps'} . $FILENAME_SEPARATOR . "cover.jpg";
-# Cover filename generated by Project Aon
-my $pa_coverImage = $rulesHash{'language'} . $FILENAME_SEPARATOR . "jpeg" . $FILENAME_SEPARATOR .$rulesHash{'book-series'}. $FILENAME_SEPARATOR .$bookCode . $FILENAME_SEPARATOR . "cover.jpg";
-
-if ( -e "$pa_coverImage") {
- # Copy the file here
- print STDERR "DEBUG: Using cover from $pa_coverImage\n" if $verbose;
- system "cp $pa_coverImage $coverImage";
-} else {
-
-# Use Imagemagick if available
- if ( -x "/usr/bin/convert" ) {
-
- print STDERR "DEBUG: Will generate cover with ImageMagick\n" if $verbose;
- my $TITLE = quote_shell(find_title($bookXML));
- my $AUTHOR = quote_shell(find_author($bookXML));
- my $ILLUSTRATOR = quote_shell(find_illustrator($bookXML));
- my $convert_cmd = "";
-
- if ( -e "$fontFiles/SouvenirStd-Demi.otf" && -e "$fontFiles/SouvenirStd-Light.otf" ) {
- $convert_cmd="convert -size 600x800 -background white -font $fontFiles/SouvenirStd-Demi.otf -pointsize 32 -fill '#006633' -gravity north caption:\"\" -annotate +0+218 \"$TITLE\" -font $fontFiles/SouvenirStd-Light.otf -pointsize 22 -fill black -annotate +0+304 '$AUTHOR' -annotate +0+333 '$ILLUSTRATOR' $coverImage"
- } else {
- print STDERR "WARN: Fontfiles not found, using standard font\n";
- $convert_cmd="convert -size 600x800 -background white -pointsize 32 -fill '#006633' -gravity north caption:\"\" -annotate +0+218 \"$TITLE\" -pointsize 22 -fill black -annotate +0+304 '$AUTHOR' -annotate +0+333 '$ILLUSTRATOR' $coverImage";
- }
-
- print STDERR "DEBUG: Will run '$convert_cmd'\n" if $verbose;
- system $convert_cmd;
- }
-}
-
-# If there is no coverImage then we will change the XSL output
-my $addCover = "yes";
-$addCover = "no" if ! -e $coverImage;
-
-
-#
-# TODO: The coverpage seems to be stripped by Calibre since it
-# expects an image file for the coverpage. Alternatively, create
-# a jpeg file based on the HTML (using html2ps for example)
-# and use that for the OPF description of the book
-
-my $coverFileName = "coverpage.html";
-my $coverFile = "$outPath{'oebps'}$FILENAME_SEPARATOR$coverFileName";
-open( COVER, '>', $coverFile ) or
- die "$PROGRAM_NAME: unable to open OPF file for writing " .
- "\"$coverFile\"\n";
-
-my $cover = qx{$JAVA -classpath "$XALAN_JAR" org.apache.xalan.xslt.Process -IN "$bookXML" -XSL "$coverXSL" -PARAM opf-id "$uniqueID" -PARAM unique-identifier "$bookUniqueURI" -PARAM language "$rulesHash{'language'}" -PARAM book_series "$SERIES" -PARAM book_series_index "$SERIES_NUMBER" -PARAM addcover "$addCover"}; #" comment to unconfuse VIM syntax hilighting
-
-
-print COVER "$cover";
-
-close COVER;
-
-check_file($coverFileName);
-
### write OPF Root file
# All content files must be created prior to creating the OPF root file
# with its manifest of content files.
## write metadata
-my $metadata = qx{$JAVA -classpath "$XALAN_JAR" org.apache.xalan.xslt.Process -IN "$bookXML" -XSL "$metadataXSL" -PARAM opf-id "$uniqueID" -PARAM unique-identifier "$bookUniqueURI" -PARAM language "$rulesHash{'language'}" -PARAM book_series "$SERIES" -PARAM book_series_index "$SERIES_NUMBER" -PARAM addcover "$addCover"}; #" comment to unconfuse VIM syntax hilighting
+my $metadata = qx{$JAVA -classpath "$XALAN_JAR" org.apache.xalan.xslt.Process -IN "$bookXML" -XSL "$metadataXSL" -PARAM opf-id "$uniqueID" -PARAM unique-identifier "$bookUniqueURI" -PARAM language "$rulesHash{'language'}" -PARAM book_series "$SERIES" -PARAM book_series_index "$SERIES_NUMBER"}; #" comment to unconfuse VIM syntax hilighting
$metadata = " $metadata";
$metadata =~ s|(<dc:)|\n $1|g;
$metadata =~ s|(</metadata>)|\n $1|g;
## write spine data
my $ncxID = make_id( $NCX_FILE );
-#print OPF qx{$JAVA -classpath "$XALAN_JAR" org.apache.xalan.xslt.Process -IN "$bookXML" -XSL "$spineXSL" -PARAM toc-id "$ncxID"};
-my $spine = qx{$JAVA -classpath "$XALAN_JAR" org.apache.xalan.xslt.Process -IN "$bookXML" -XSL "$spineXSL" -PARAM toc-id "$ncxID" -PARAM addcover "$addCover"};
+my $spine = qx{$JAVA -classpath "$XALAN_JAR" org.apache.xalan.xslt.Process -IN "$bookXML" -XSL "$spineXSL" -PARAM toc-id "$ncxID"};
$spine =~ s/idref="([^"]*)"/idref="$1.$XHTML_EXT"/g;
$spine = " $spine";
return $series_number;
}
-# Determine the book title by reading the book meta information
-sub find_title {
- my ($book) = @_;
- my $title = ""; my $line = "";
- open (BOOK, "head -100 $book | ") || die ("Could not read $book: $!");
- while ($title eq "" && ( $line = <BOOK> ) ) {
- chomp $line;
- if ( $line =~ /<title>(.*?)<\/title>/ ) {
- $title = $1;
- }
- }
- close BOOK;
-
- if ( $title eq "" ) {
- print STDERR "WARN: Cannot find title for book '$book'\n";
- $title = "[Undefined]";
- }
-
- return convert_entities($title);
-}
-
-# Determine the book author by reading the book meta information
-sub find_author {
- my ($book) = @_;
- my $author = "";
- my $line = "";
- open (BOOK, "head -100 $book |") || die ("Could not read $book: $!");
-
- my $find_line = 0;
- while ($author eq "" && ( $line = <BOOK> ) ) {
- chomp $line;
- if ( $find_line == 1 && $line =~ /<line>(.*?)<\/line>/ ) {
- $author = $1;
- }
- $find_line = 1 if ( $line =~ /<creator class="medium">/ );
- $find_line = 0 if ( $line =~ /<\/creator>/ );
- if ( $line =~ /<creator class="author">(.*?)<\/title>/ ) {
- $author = $1;
- }
- }
- close BOOK;
-
- if ( $author eq "" ) {
- print STDERR "WARN: Cannot find author for book '$book'\n";
- $author = "[Undefined]";
- }
-
-
- return $author;
-}
-
-# Determine the book illustrator by reading the book meta information
-sub find_illustrator {
- my ($book) = @_;
- my $illustrator = "";
- my $line = "";
- open (BOOK, "head -100 $book | ") || die ("Could not read $book: $!");
-
- my $find_line = 0;
- while ($illustrator eq "" && ( $line = <BOOK> ) ) {
- chomp $line;
- if ( $find_line == 1 && $line =~ /<line>Illustrated by (.*?)<\/line>/ ) {
- $illustrator = $1;
- }
- $find_line = 1 if ( $line =~ /<creator class="medium">/ );
- $find_line = 0 if ( $line =~ /<\/creator>/ );
- if ( $line =~ /<creator class="illustrator">(.*?)<\/title>/ ) {
- $illustrator = $1;
- }
- }
- close BOOK;
-
- if ( $illustrator eq "" ) {
- print STDERR "WARN: Cannot find illustrator for book '$book'\n";
- $illustrator = "[Undefined]";
- }
- if ( $language eq "en" ) {
- $illustrator = "Illustrated by ".$illustrator;
- } elsif ( $language eq "es" ) {
- $illustrator = "Illustrado por ".$illustrator;
- }
-
- return $illustrator;
-}
-
-sub convert_entities {
-# Convert character entities to their correspondent values
- my ($text) = @_;
-
- $text =~ s/\<ch.apos\/\>/'/g;
- $text =~ s/\<ch.nbsp\/\>/ /g;
- $text =~ s/\<ch.plusmn\/\>/+-/g;
- $text =~ s/\<ch.aacute\/\>/á/g;
- $text =~ s/\<ch.eacute\/\>/é/g;
- $text =~ s/\<ch.iacute\/\>/í/g;
- $text =~ s/\<ch.oacute\/\>/ó/g;
- $text =~ s/\<ch.uacute\/\>/ú/g;
- $text =~ s/\<ch.ntilde\/\>/ñ/g;
- $text =~ s/\<ch.Aacute\/\>/Á/g;
- $text =~ s/\<ch.Eacute\/\>/É/g;
- $text =~ s/\<ch.Iacute\/\>/Í/g;
- $text =~ s/\<ch.Oacute\/\>/Ó/g;
- $text =~ s/\<ch.Uacute\/\>/Ú/g;
- $text =~ s/\<ch.auml\/\>/ä/g;
- $text =~ s/\<ch.euml\/\>/ë/g;
- $text =~ s/\<ch.iuml\/\>/ï/g;
- $text =~ s/\<ch.ouml\/\>/ö/g;
- $text =~ s/\<ch.uuml\/\>/ü/g;
- $text =~ s/\<ch.Ntilde\/\>/Ñ/g;
- $text =~ s/\<ch.acute\/\>/´/g;
- $text =~ s/\<ch.iexcl\/\>/¡/g;
- $text =~ s/\<ch.iquest\/\>/¿/g;
- $text =~ s/\<ch.laquo\/\>/«/g;
- $text =~ s/\<ch.raquo\/\>/»/g;
- $text =~ s/\<ch.ampersand\/\>/&/g;
-
- return $text;
-}
-
# Quote metacaracters for shell use
sub quote_shell {
my ($text) = @_;