.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:
</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>
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
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
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())
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')
\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,
\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}{
{
\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}
\rightsinfo
\vspace{.6em}
+ Źródło: \href{\bookurl}{\bookurl}
+
+ \vspace{.6em}
\sourceinfo
\description
}
-\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}}}
<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>
<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>
<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" />
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
}
+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:
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()
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)