#950: visibly mark author's annotations,
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 22 Feb 2011 10:43:04 +0000 (11:43 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Tue, 22 Feb 2011 10:43:04 +0000 (11:43 +0100)
add pdf cover option,
add prestigio-pdf packager
epub: minor fix

librarian/epub.py
librarian/epub/xsltAnnotations.xsl
librarian/pdf.py
librarian/pdf/wl.sty
librarian/pdf/wl2tex.xslt
librarian/xslt/book2html.xslt
scripts/book2partner

index a615b7e..0f23923 100644 (file)
@@ -84,6 +84,10 @@ def replace_characters(node):
                    .replace(",,", u"\u201E")\
                    .replace('"', u"\u201D")\
                    .replace("'", u"\u2019")
                    .replace(",,", u"\u201E")\
                    .replace('"', u"\u201D")\
                    .replace("'", u"\u2019")
+    if node.tag in ('uwaga', 'extra'):
+        t = node.tail
+        node.clear()
+        node.tail = t
     node.text = replace_chars(node.text)
     node.tail = replace_chars(node.tail)
     for child in node:
     node.text = replace_chars(node.text)
     node.tail = replace_chars(node.tail)
     for child in node:
index bc5693e..2d05f1c 100644 (file)
@@ -38,6 +38,7 @@
       </a>
       <p xmlns="http://www.w3.org/1999/xhtml">
         <xsl:apply-templates />
       </a>
       <p xmlns="http://www.w3.org/1999/xhtml">
         <xsl:apply-templates />
+        <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
       </p>
     </div>
   </xsl:template>
       </p>
     </div>
   </xsl:template>
index 5f6f0a2..476fbee 100644 (file)
@@ -167,7 +167,8 @@ def package_available(package, args='', verbose=False):
 
 
 def transform(provider, slug=None, file_path=None,
 
 
 def transform(provider, slug=None, file_path=None,
-              output_file=None, output_dir=None, make_dir=False, verbose=False, save_tex=None, morefloats=None):
+              output_file=None, output_dir=None, make_dir=False, verbose=False, save_tex=None, morefloats=None,
+              cover=None, flags=None):
     """ produces a PDF file with XeLaTeX
 
     provider: a DocProvider
     """ produces a PDF file with XeLaTeX
 
     provider: a DocProvider
@@ -179,6 +180,8 @@ def transform(provider, slug=None, file_path=None,
     verbose: prints all output from LaTeX
     save_tex: path to save the intermediary LaTeX file to
     morefloats (old/new/none): force specific morefloats
     verbose: prints all output from LaTeX
     save_tex: path to save the intermediary LaTeX file to
     morefloats (old/new/none): force specific morefloats
+    cover: a cover.Cover object
+    flags: less-advertising,
     """
 
     # Parse XSLT
     """
 
     # Parse XSLT
@@ -192,6 +195,13 @@ def transform(provider, slug=None, file_path=None,
                 raise ValueError('either slug or file_path should be specified')
             document = load_including_children(provider, slug=slug)
 
                 raise ValueError('either slug or file_path should be specified')
             document = load_including_children(provider, slug=slug)
 
+        if cover:
+            document.edoc.getroot().set('data-cover-width', str(cover.width))
+            document.edoc.getroot().set('data-cover-height', str(cover.height))
+        if flags:
+            for flag in flags:
+                document.edoc.getroot().set('flag-' + flag, 'yes')
+
         # check for LaTeX packages
         if morefloats:
             document.edoc.getroot().set('morefloats', morefloats.lower())
         # check for LaTeX packages
         if morefloats:
             document.edoc.getroot().set('morefloats', morefloats.lower())
@@ -214,10 +224,17 @@ def transform(provider, slug=None, file_path=None,
         style_filename = get_stylesheet("wl2tex")
         style = etree.parse(style_filename)
         texml = document.transform(style)
         style_filename = get_stylesheet("wl2tex")
         style = etree.parse(style_filename)
         texml = document.transform(style)
-        del document # no longer needed large object :)
 
         # TeXML -> LaTeX
         temp = mkdtemp('-wl2pdf')
 
         # TeXML -> LaTeX
         temp = mkdtemp('-wl2pdf')
+
+        if cover:
+            c = cover(document.book_info.author.readable(), document.book_info.title)
+            with open(os.path.join(temp, 'cover.png'), 'w') as f:
+                c.save(f)
+
+        del document # no longer needed large object :)
+
         tex_path = os.path.join(temp, 'doc.tex')
         fout = open(tex_path, 'w')
         process(StringIO(texml), fout, 'utf-8')
         tex_path = os.path.join(temp, 'doc.tex')
         fout = open(tex_path, 'w')
         process(StringIO(texml), fout, 'utf-8')
index 897535e..28a23a5 100644 (file)
@@ -9,7 +9,7 @@
 
 \usepackage[overload]{textcase}
 \usepackage{scalefnt}
 
 \usepackage[overload]{textcase}
 \usepackage{scalefnt}
-\usepackage[colorlinks=true,linkcolor=black,urlcolor=black]{hyperref}
+\usepackage[colorlinks=true,linkcolor=black,setpagesize=false,urlcolor=black,xetex]{hyperref}
 
 \setmainfont [
 %ExternalLocation,
 
 \setmainfont [
 %ExternalLocation,
@@ -100,6 +100,34 @@ Letters={SmallCaps,UppercaseSmallCaps}
 \usebox{\ximagebox}%
 \raisebox{0pt}[0pt][0pt]{\makebox[0pt][r]{\usebox{\xglyphbox}}}}
 
 \usebox{\ximagebox}%
 \raisebox{0pt}[0pt][0pt]{\makebox[0pt][r]{\usebox{\xglyphbox}}}}
 
+\newcommand{\makecover}[2]{
+        \pdfpagewidth=#1
+        \pdfpageheight=#2
+
+        \thispagestyle{empty}
+        \newlength{\PictHOffset}
+        \newlength{\PictVOffset}
+        \setlength{\PictHOffset}{1in}
+        \addtolength{\PictHOffset}{\hoffset}
+        \addtolength{\PictHOffset}{\oddsidemargin}
+
+        \setlength{\PictVOffset}{1in}
+        \addtolength{\PictVOffset}{\voffset}
+        \addtolength{\PictVOffset}{\topmargin}
+        \addtolength{\PictVOffset}{\headheight}
+        \addtolength{\PictVOffset}{\headsep}
+        \addtolength{\PictVOffset}{\topskip}
+        \addtolength{\PictVOffset}{-\pdfpageheight}
+
+        \noindent\hspace*{-\PictHOffset}%
+        \raisebox{\PictVOffset}[0pt][0pt]{\makebox[0pt][l]{%
+            \includegraphics[height=\pdfpageheight,width=\pdfpagewidth]{cover.png}}}
+        \clearpage
+
+        \setlength{\pdfpagewidth}{210mm}
+        \setlength{\pdfpageheight}{297mm}
+}
+
 
 \renewcommand{\maketitle}{
     {
 
 \renewcommand{\maketitle}{
     {
@@ -112,12 +140,15 @@ Letters={SmallCaps,UppercaseSmallCaps}
     \end{minipage}
     \begin{minipage}[t]{.65\textwidth}\vspace{0pt}
 
     \end{minipage}
     \begin{minipage}[t]{.65\textwidth}\vspace{0pt}
 
+    \ifflaglessadvertising
+    \else
         \href{\bookurl}{Ta lektura}, podobnie jak tysiące innych, jest dostępna on-line na stronie
         \href{http://www.wolnelektury.pl/}{wolnelektury.pl}.
         \vspace{.5em}
         \href{\bookurl}{Ta lektura}, podobnie jak tysiące innych, jest dostępna on-line na stronie
         \href{http://www.wolnelektury.pl/}{wolnelektury.pl}.
         \vspace{.5em}
+    \fi
 
 
-        Utwór opracowany został w ramach projektu \href{http://www.wolnelektury.pl/}{Wolne Lektury}
-        przez \href{http://nowoczesnapolska.org.pl}{fundację Nowoczesna Polska}.
+    Utwór opracowany został w ramach projektu \href{http://www.wolnelektury.pl/}{Wolne Lektury}
+    przez \href{http://nowoczesnapolska.org.pl}{fundację Nowoczesna Polska}.
 
     \end{minipage}
     \noindent \rule{\linewidth}{0.4pt}
 
     \end{minipage}
     \noindent \rule{\linewidth}{0.4pt}
@@ -137,6 +168,9 @@ Letters={SmallCaps,UppercaseSmallCaps}
     \rightsinfo
     \vspace{.6em}
 
     \rightsinfo
     \vspace{.6em}
 
+    Źródło: \href{\bookurl}{\bookurl}
+
+    \vspace{.6em}
     \sourceinfo
 
     \description
     \sourceinfo
 
     \description
@@ -325,7 +359,7 @@ Letters={Uppercase}
 }
 
 
 }
 
 
-\newcommand{\pa}[1]{\NoCaseChange{\footnote{#1}}}
+\newcommand{\pa}[1]{\NoCaseChange{\footnote{#1 [przypis autorski]}}}
 \newcommand{\pe}[1]{\NoCaseChange{\footnote{#1}}}
 \newcommand{\pr}[1]{\NoCaseChange{\footnote{#1}}}
 \newcommand{\pt}[1]{\NoCaseChange{\footnote{#1}}}
 \newcommand{\pe}[1]{\NoCaseChange{\footnote{#1}}}
 \newcommand{\pr}[1]{\NoCaseChange{\footnote{#1}}}
 \newcommand{\pt}[1]{\NoCaseChange{\footnote{#1}}}
index 5a49a01..58be05f 100644 (file)
     <TeXML xmlns="http://getfo.sourceforge.net/texml/ns1">
         <TeXML escape="0">
         \documentclass[a4paper, oneside, 11pt]{book}
     <TeXML xmlns="http://getfo.sourceforge.net/texml/ns1">
         <TeXML escape="0">
         \documentclass[a4paper, oneside, 11pt]{book}
+
+        <!-- flags and values set on root -->
+
+        \newif\ifflaglessadvertising
+        <xsl:for-each select="@*[starts-with(name(), 'flag-')]">
+            <cmd>
+                <xsl:attribute name="name"><xsl:value-of select="wl:texcommand(name())" />true</xsl:attribute>
+            </cmd>
+        </xsl:for-each>
+
+        <xsl:for-each select="@*[starts-with(name(), 'data-')]">
+            <TeXML escape="0">
+                \def\<xsl:value-of select="wl:texcommand(name())" />{<TeXML escape="1"><xsl:value-of select="."/></TeXML>}
+            </TeXML>
+        </xsl:for-each>
+
         \usepackage{wl}
         </TeXML>
 
         \usepackage{wl}
         </TeXML>
 
         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
 
         <env name="document">
         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
 
         <env name="document">
+            <xsl:if test="@data-cover-width">
+                <cmd name="makecover">
+                    <parm><xsl:value-of select="210 * @data-cover-width div @data-cover-height" />mm</parm>
+                    <parm>210mm</parm>
+                </cmd>
+            </xsl:if>
             <cmd name="maketitle" />
 
             <cmd name="tytul"><parm>
             <cmd name="maketitle" />
 
             <cmd name="tytul"><parm>
index 682ed9b..8e1a574 100755 (executable)
                         <a href="{concat('#anchor-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt]) + 1" />]</a>
                         <xsl:choose>
                             <xsl:when test="count(akap|akap_cd|strofa) = 0">
                         <a href="{concat('#anchor-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt]) + 1" />]</a>
                         <xsl:choose>
                             <xsl:when test="count(akap|akap_cd|strofa) = 0">
-                                <p><xsl:apply-templates select="text()|*" mode="inline" /></p>
+                                <p><xsl:apply-templates select="text()|*" mode="inline" />
+                                <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
+                                </p>
                             </xsl:when>
                             <xsl:otherwise>
                                 <xsl:apply-templates select="text()|*" mode="inline" />
                             </xsl:when>
                             <xsl:otherwise>
                                 <xsl:apply-templates select="text()|*" mode="inline" />
index 6955899..136fffc 100755 (executable)
@@ -9,7 +9,7 @@ import optparse
 from copy import deepcopy
 from lxml import etree
 
 from copy import deepcopy
 from lxml import etree
 
-from librarian import epub, DirDocProvider, ParseError, cover
+from librarian import epub, pdf, DirDocProvider, ParseError, cover
 from librarian.dcparser import BookInfo
 
 
 from librarian.dcparser import BookInfo
 
 
@@ -111,6 +111,31 @@ def prestigio(filenames, output_dir, verbose):
         }
 
 
         }
 
 
+def prestigio_pdf(filenames, output_dir, verbose):
+    try:
+        for main_input in input_filenames:
+            if options.verbose:
+                print main_input
+            path, fname = os.path.realpath(main_input).rsplit('/', 1)
+            provider = DirDocProvider(path)
+            slug, ext = os.path.splitext(fname)
+
+            if output_dir != '':
+                try:
+                    os.makedirs(output_dir)
+                except:
+                    pass
+            outfile = os.path.join(output_dir, slug + '.pdf')
+            pdf.transform(provider, file_path=main_input, output_file=outfile,
+                    cover=cover.PrestigioCover, verbose=options.verbose, flags=('less-advertising',))
+    except ParseError, e:
+        print '%(file)s:%(name)s:%(message)s' % {
+            'file': main_input,
+            'name': e.__class__.__name__,
+            'message': e.message
+        }
+
+
 def bookoteka(filenames, output_dir, verbose):
     try:
         for main_input in input_filenames:
 def bookoteka(filenames, output_dir, verbose):
     try:
         for main_input in input_filenames:
@@ -154,6 +179,8 @@ if __name__ == '__main__':
                       help='prepare files for Virtualo API')
     parser.add_option('--prestigio', action='store_true', dest='prestigio', default=False,
                       help='prepare files for Prestigio')
                       help='prepare files for Virtualo API')
     parser.add_option('--prestigio', action='store_true', dest='prestigio', default=False,
                       help='prepare files for Prestigio')
+    parser.add_option('--prestigio-pdf', action='store_true', dest='prestigio_pdf', default=False,
+                      help='prepare PDF files for Prestigio')
 
     options, input_filenames = parser.parse_args()
 
 
     options, input_filenames = parser.parse_args()
 
@@ -167,3 +194,5 @@ if __name__ == '__main__':
         virtualo(input_filenames, options.output_dir, options.verbose)
     if options.prestigio:
         prestigio(input_filenames, options.output_dir, options.verbose)
         virtualo(input_filenames, options.output_dir, options.verbose)
     if options.prestigio:
         prestigio(input_filenames, options.output_dir, options.verbose)
+    if options.prestigio_pdf:
+        prestigio_pdf(input_filenames, options.output_dir, options.verbose)