From b92b58ba86f08f04b4f0436479d3d73ce0c03f00 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 22 Feb 2011 11:43:04 +0100 Subject: [PATCH] #950: visibly mark author's annotations, add pdf cover option, add prestigio-pdf packager epub: minor fix --- librarian/epub.py | 4 +++ librarian/epub/xsltAnnotations.xsl | 1 + librarian/pdf.py | 21 +++++++++++++-- librarian/pdf/wl.sty | 42 +++++++++++++++++++++++++++--- librarian/pdf/wl2tex.xslt | 22 ++++++++++++++++ librarian/xslt/book2html.xslt | 4 ++- scripts/book2partner | 31 +++++++++++++++++++++- 7 files changed, 117 insertions(+), 8 deletions(-) diff --git a/librarian/epub.py b/librarian/epub.py index a615b7e..0f23923 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -84,6 +84,10 @@ def replace_characters(node): .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: diff --git a/librarian/epub/xsltAnnotations.xsl b/librarian/epub/xsltAnnotations.xsl index bc5693e..2d05f1c 100644 --- a/librarian/epub/xsltAnnotations.xsl +++ b/librarian/epub/xsltAnnotations.xsl @@ -38,6 +38,7 @@

+ [przypis autorski]

diff --git a/librarian/pdf.py b/librarian/pdf.py index 5f6f0a2..476fbee 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -167,7 +167,8 @@ def package_available(package, args='', verbose=False): 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 @@ -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 + cover: a cover.Cover object + flags: less-advertising, """ # 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) + 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()) @@ -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) - del document # no longer needed large object :) # 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') diff --git a/librarian/pdf/wl.sty b/librarian/pdf/wl.sty index 897535e..28a23a5 100644 --- a/librarian/pdf/wl.sty +++ b/librarian/pdf/wl.sty @@ -9,7 +9,7 @@ \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, @@ -100,6 +100,34 @@ Letters={SmallCaps,UppercaseSmallCaps} \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}{ { @@ -112,12 +140,15 @@ Letters={SmallCaps,UppercaseSmallCaps} \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} + \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} @@ -137,6 +168,9 @@ Letters={SmallCaps,UppercaseSmallCaps} \rightsinfo \vspace{.6em} + Źródło: \href{\bookurl}{\bookurl} + + \vspace{.6em} \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}}} diff --git a/librarian/pdf/wl2tex.xslt b/librarian/pdf/wl2tex.xslt index 5a49a01..58be05f 100644 --- a/librarian/pdf/wl2tex.xslt +++ b/librarian/pdf/wl2tex.xslt @@ -16,6 +16,22 @@ \documentclass[a4paper, oneside, 11pt]{book} + + + + \newif\ifflaglessadvertising + + + true + + + + + + \def\{} + + + \usepackage{wl} @@ -44,6 +60,12 @@ + + + mm + 210mm + + diff --git a/librarian/xslt/book2html.xslt b/librarian/xslt/book2html.xslt index 682ed9b..8e1a574 100755 --- a/librarian/xslt/book2html.xslt +++ b/librarian/xslt/book2html.xslt @@ -416,7 +416,9 @@ [] -

+

+ [przypis autorski] +

diff --git a/scripts/book2partner b/scripts/book2partner index 6955899..136fffc 100755 --- a/scripts/book2partner +++ b/scripts/book2partner @@ -9,7 +9,7 @@ import optparse 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 @@ -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: @@ -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') + 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() @@ -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) + if options.prestigio_pdf: + prestigio_pdf(input_filenames, options.output_dir, options.verbose) -- 2.20.1