some cleaning
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 13 Jan 2011 09:42:58 +0000 (10:42 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 13 Jan 2011 09:42:58 +0000 (10:42 +0100)
some more cover generation

15 files changed:
librarian/cover.py
librarian/epub.py
librarian/epub/logo_wolnelektury.png [deleted file]
librarian/fonts/JunicodeWL-Italic.ttf [new file with mode: 0644]
librarian/fonts/JunicodeWL-Regular.ttf [new file with mode: 0644]
librarian/pdf.py
librarian/pdf/JunicodeWL-Italic.ttf [deleted file]
librarian/pdf/JunicodeWL-Regular.ttf [deleted file]
librarian/pdf/wl-logo.png [deleted file]
librarian/pdf/wl2tex.xslt [new file with mode: 0644]
librarian/res/wl-logo-small.png [new file with mode: 0644]
librarian/res/wl-logo.png [new file with mode: 0644]
librarian/xslt/wl2tex.xslt [deleted file]
scripts/book2partner
setup.py

index a7fc674..c946d43 100644 (file)
@@ -3,37 +3,78 @@
 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
-import Image, ImageFont, ImageDraw
+import Image, ImageFont, ImageDraw, ImageFilter
 from librarian import get_resource
 
 
-def cover(width, height, author, title):
-    def draw_centered_text(text, draw, font, width, pos_y, lineskip):
+def cover(author, title,
+          width, height, background_color, background_img,
+          author_top, author_margin_left, author_margin_right, author_lineskip, author_color, author_font, author_shadow,
+          title_top, title_margin_left, title_margin_right, title_lineskip, title_color, title_font, title_shadow,
+          logo_width, logo_bottom
+          ):
+    def draw_centered_text(text, img, font, margin_left, width, pos_y, lineskip, color, shadow_color):
+        if shadow_color:
+            shadow_img = Image.new('RGBA', img.size)
+            shadow_draw = ImageDraw.Draw(shadow_img)
+        text_img = Image.new('RGBA', img.size)
+        text_draw = ImageDraw.Draw(text_img)
         while text:
             line = text
-            while draw.textsize(line, font=font)[0] > width:
+            while text_draw.textsize(line, font=font)[0] > width:
                 try:
                     line, ext = line.rsplit(' ', 1)
                 except:
                     break
-            draw.text(((img.size[0] - draw.textsize(line, font=font)[0]) / 2, pos_y), line, font=font, fill='#000')
+            pos_x = margin_left + (width - text_draw.textsize(line, font=font)[0]) / 2
+            if shadow_color:
+                shadow_draw.text((pos_x + 3, pos_y + 3), line, font=font, fill=shadow_color)
+            text_draw.text((pos_x, pos_y), line, font=font, fill=color)
             pos_y += lineskip
             text = text[len(line)+1:]
+        if shadow_color:
+            shadow_img = shadow_img.filter(ImageFilter.BLUR)
+            img.paste(shadow_img, None, shadow_img)
+        img.paste(text_img, None, text_img)
         return pos_y
 
 
-    img = Image.new('RGB', (width, height), (255, 255, 255))
+    img = Image.new('RGB', (width, height), background_color)
 
-    # WL logo
-    logo = Image.open(get_resource('pdf/wl-logo.png'))
-    logo = logo.resize((img.size[0] / 2, logo.size[1] * img.size[0] / 2 / logo.size[0]))
-    img.paste(logo, (width / 4, img.size[1] - logo.size[1]))
+    if background_img:
+        background = Image.open(background_img)
+        img.paste(background)
+        del background
 
-    draw = ImageDraw.Draw(img)
-    author_font = ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), width/20)
-    title_y = draw_centered_text(author, draw, author_font, width*9/10, height/10, width/15) + height/10
+    # WL logo
+    if logo_width:
+        logo = Image.open(get_resource('res/wl-logo.png'))
+        logo = logo.resize((logo_width, logo.size[1] * logo_width / logo.size[0]))
+        img.paste(logo, ((width - logo_width) / 2, img.size[1] - logo.size[1] - logo_bottom))
 
-    title_font = ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), width/15)
-    draw_centered_text(title, draw, title_font, width*9/10, title_y, width/11)
+    title_y = draw_centered_text(author, img, author_font,
+                    author_margin_left, width - author_margin_left - author_margin_right, author_top,
+                    author_lineskip, author_color, author_shadow) + title_top
+    draw_centered_text(title, img, title_font,
+                    title_margin_left, width - title_margin_left - title_margin_right, title_y,
+                    title_lineskip, title_color, title_shadow)
 
     return img
+
+
+def virtualo_cover(author, title):
+    return cover(author, title,
+          600, 730, '#fff', None,
+          73, 20, 20, 40, '#000', ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), 30), None,
+          73, 20, 20, 54, '#000', ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), 40), None,
+          300, 0
+          )
+
+def asbis_cover(author, title):
+    return cover(author, u"„%s”" % title,
+          800, 800, '#000', '',
+          455, 230, 170, 60, '#fff', ImageFont.truetype(get_resource('fonts/JunicodeWL-Italic.ttf'), 50), '#000',
+          0, 230, 170, 60, '#fff', ImageFont.truetype(get_resource('fonts/JunicodeWL-Italic.ttf'), 50), '#000',
+          None, None
+          )
+
index 2fec331..666bcc9 100644 (file)
@@ -19,7 +19,7 @@ import sys
 from librarian import XMLNamespace, RDFNS, DCNS, WLNS, NCXNS, OPFNS, NoDublinCore
 from librarian.dcparser import BookInfo
 
-from librarian import functions
+from librarian import functions, get_resource
 
 functions.reg_person_name()
 
@@ -73,11 +73,6 @@ def xslt(xml, sheet):
         return xml.xslt(etree.parse(xsltf))
 
 
-_resdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'epub')
-def res(fname):
-    return os.path.join(_resdir, fname)
-
-
 def replace_characters(node):
     def replace_chars(text):
         if text is None:
@@ -257,13 +252,13 @@ def transform_chunk(chunk_xml, chunk_no, annotations, empty=False, _empty_html_s
             element.set('sub', str(subnumber))
     if empty:
         if not _empty_html_static:
-            _empty_html_static.append(open(res('emptyChunk.html')).read())
+            _empty_html_static.append(open(get_resource('epub/emptyChunk.html')).read())
         chars = set()
         output_html = _empty_html_static[0]
     else:
         find_annotations(annotations, chunk_xml, chunk_no)
         replace_by_verse(chunk_xml)
-        html_tree = xslt(chunk_xml, res('xsltScheme.xsl'))
+        html_tree = xslt(chunk_xml, get_resource('epub/xsltScheme.xsl'))
         chars = used_chars(html_tree.getroot())
         output_html = etree.tostring(html_tree, method="html", pretty_print=True)
     return output_html, toc, chars
@@ -293,7 +288,7 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir=
         chars = set()
         if first:
             # write book title page
-            html_tree = xslt(input_xml, res('xsltTitle.xsl'))
+            html_tree = xslt(input_xml, get_resource('epub/xsltTitle.xsl'))
             chars = used_chars(html_tree.getroot())
             zip.writestr('OPS/title.html',
                  etree.tostring(html_tree, method="html", pretty_print=True))
@@ -301,9 +296,9 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir=
             # write title page for every parent
             if sample is not None and sample <= 0:
                 chars = set()
-                html_string = open(res('emptyChunk.html')).read()
+                html_string = open(get_resource('epub/emptyChunk.html')).read()
             else:
-                html_tree = xslt(input_xml, res('xsltChunkTitle.xsl'))
+                html_tree = xslt(input_xml, get_resource('epub/xsltChunkTitle.xsl'))
                 chars = used_chars(html_tree.getroot())
                 html_string = etree.tostring(html_tree, method="html", pretty_print=True)
             zip.writestr('OPS/part%d.html' % chunk_counter, html_string)
@@ -391,10 +386,10 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir=
                        '<rootfiles><rootfile full-path="OPS/content.opf" ' \
                        'media-type="application/oebps-package+xml" />' \
                        '</rootfiles></container>')
-    for fname in 'style.css', 'logo_wolnelektury.png':
-        zip.write(res(fname), os.path.join('OPS', fname))
+    zip.write(get_resource('epub/style.css'), os.path.join('OPS', 'style.css'))
+    zip.write(get_resource('res/wl-logo-small.png'), os.path.join('OPS', 'logo_wolnelektury.png'))
 
-    opf = xslt(metadata, res('xsltContent.xsl'))
+    opf = xslt(metadata, get_resource('epub/xsltContent.xsl'))
     manifest = opf.find('.//' + OPFNS('manifest'))
     spine = opf.find('.//' + OPFNS('spine'))
 
@@ -425,7 +420,7 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir=
         spine.append(etree.fromstring(
             '<itemref idref="annotations" />'))
         replace_by_verse(annotations)
-        html_tree = xslt(annotations, res("xsltAnnotations.xsl"))
+        html_tree = xslt(annotations, get_resource('epub/xsltAnnotations.xsl'))
         chars = chars.union(used_chars(html_tree.getroot()))
         zip.writestr('OPS/annotations.html', etree.tostring(
                             html_tree, method="html", pretty_print=True))
@@ -436,7 +431,8 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir=
 
     os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'font-optimizer'))
     for fname in 'DejaVuSerif.ttf', 'DejaVuSerif-Bold.ttf', 'DejaVuSerif-Italic.ttf', 'DejaVuSerif-BoldItalic.ttf':
-        optimizer_call = ['perl', 'subset.pl', '--chars', ''.join(chars).encode('utf-8'), res('../fonts/' + fname), os.path.join(tmpdir, fname)]
+        optimizer_call = ['perl', 'subset.pl', '--chars', ''.join(chars).encode('utf-8'), 
+                          get_resource('fonts/' + fname), os.path.join(tmpdir, fname)]
         if verbose:
             print "Running font-optimizer"
             subprocess.check_call(optimizer_call)
diff --git a/librarian/epub/logo_wolnelektury.png b/librarian/epub/logo_wolnelektury.png
deleted file mode 100644 (file)
index 104d56a..0000000
Binary files a/librarian/epub/logo_wolnelektury.png and /dev/null differ
diff --git a/librarian/fonts/JunicodeWL-Italic.ttf b/librarian/fonts/JunicodeWL-Italic.ttf
new file mode 100644 (file)
index 0000000..f380498
Binary files /dev/null and b/librarian/fonts/JunicodeWL-Italic.ttf differ
diff --git a/librarian/fonts/JunicodeWL-Regular.ttf b/librarian/fonts/JunicodeWL-Regular.ttf
new file mode 100644 (file)
index 0000000..24afcdc
Binary files /dev/null and b/librarian/fonts/JunicodeWL-Regular.ttf differ
index 1989239..baf7be4 100644 (file)
@@ -32,7 +32,7 @@ functions.reg_ends_white()
 functions.reg_texcommand()
 
 STYLESHEETS = {
-    'wl2tex': 'xslt/wl2tex.xslt',
+    'wl2tex': 'pdf/wl2tex.xslt',
 }
 
 
@@ -224,7 +224,7 @@ def transform(provider, slug=None, file_path=None,
 
         # LaTeX -> PDF
         shutil.copy(get_resource('pdf/wl.sty'), temp)
-        shutil.copy(get_resource('pdf/wl-logo.png'), temp)
+        shutil.copy(get_resource('res/wl-logo.png'), temp)
 
         cwd = os.getcwd()
         os.chdir(temp)
diff --git a/librarian/pdf/JunicodeWL-Italic.ttf b/librarian/pdf/JunicodeWL-Italic.ttf
deleted file mode 100644 (file)
index f380498..0000000
Binary files a/librarian/pdf/JunicodeWL-Italic.ttf and /dev/null differ
diff --git a/librarian/pdf/JunicodeWL-Regular.ttf b/librarian/pdf/JunicodeWL-Regular.ttf
deleted file mode 100644 (file)
index 24afcdc..0000000
Binary files a/librarian/pdf/JunicodeWL-Regular.ttf and /dev/null differ
diff --git a/librarian/pdf/wl-logo.png b/librarian/pdf/wl-logo.png
deleted file mode 100644 (file)
index 03b46b5..0000000
Binary files a/librarian/pdf/wl-logo.png and /dev/null differ
diff --git a/librarian/pdf/wl2tex.xslt b/librarian/pdf/wl2tex.xslt
new file mode 100644 (file)
index 0000000..c3abdd6
--- /dev/null
@@ -0,0 +1,354 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+   This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+   Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+  
+-->
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+    xmlns:wl="http://wolnelektury.pl/functions"
+    xmlns:dc="http://purl.org/dc/elements/1.1/"
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
+
+<xsl:output encoding="utf-8" indent="yes" version="2.0" />
+
+<xsl:template match="utwor">
+    <TeXML xmlns="http://getfo.sourceforge.net/texml/ns1">
+        <TeXML escape="0">
+        \documentclass[a4paper, oneside, 11pt]{book}
+        \usepackage{wl}
+        </TeXML>
+
+        <xsl:choose>
+            <xsl:when test="@morefloats = 'new'">
+                <TeXML escape="0">
+                    \usepackage[maxfloats=64]{morefloats}
+                </TeXML>
+            </xsl:when>
+            <xsl:when test="@morefloats = 'old'">
+                <TeXML escape="0">
+                    \usepackage{morefloats}
+                </TeXML>
+            </xsl:when>
+            <xsl:when test="@morefloats = 'none'" />
+            <xsl:otherwise>
+                <TeXML escape="0">
+                    \IfFileExists{morefloats.sty}{
+                        \usepackage{morefloats}
+                    }{}
+                </TeXML>
+            </xsl:otherwise>
+        </xsl:choose>
+
+        <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
+        <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
+
+        <env name="document">
+            <cmd name="maketitle" />
+
+            <xsl:choose>
+                <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
+                    <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/autor_utworu" mode="title" />
+                    <!-- title in master -->
+                </xsl:when>
+                <xsl:otherwise>
+                    <!-- look for author title in dc -->
+                    <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
+                    <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='firstdctitle' />
+                </xsl:otherwise>
+            </xsl:choose>
+            <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
+            <xsl:apply-templates select="utwor" mode="part" />
+        </env>
+    </TeXML>
+</xsl:template>
+
+<xsl:template match="utwor" mode="part">
+    <!-- title for empty dc -->
+    <xsl:choose>
+        <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
+            <!-- title in master -->
+        </xsl:when>
+        <xsl:otherwise>
+            <!-- look for title in dc -->
+            <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
+            <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
+        </xsl:otherwise>
+    </xsl:choose>
+
+    <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
+    <xsl:apply-templates select="utwor" mode="part" />
+</xsl:template>
+
+<!-- =================== -->
+<!-- = MAIN TITLE PAGE = -->
+<!-- = (from DC)       = -->
+<!-- =================== -->
+
+<xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
+    <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
+</xsl:template>
+
+<xsl:template match="rdf:RDF" mode="titlepage">
+    <cmd name='title'><parm>
+        <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
+    </parm></cmd>
+    <cmd name='author'><parm>
+        <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
+    </parm></cmd>
+    <TeXML escape="0">
+        \def\sourceinfo{<xsl:apply-templates select=".//dc:source" mode="inline" />}
+        \def\bookurl{<xsl:value-of select=".//dc:identifier.url" />}
+        \def\rightsinfo{Ten utwór nie jest chroniony prawem autorskim i~znajduje się w~domenie publicznej,
+            co oznacza, że możesz go swobodnie wykorzystywać, publikować i~rozpowszechniać.}
+        <xsl:if test=".//dc:rights.license">
+            \def\rightsinfo{Ten utwór jest udostepniony na licencji
+            \href{<xsl:value-of select=".//dc:rights.license" />}{<xsl:value-of select=".//dc:rights" />}.}
+        </xsl:if>
+    </TeXML>
+</xsl:template>
+
+
+<!-- ============== -->
+<!-- = BOOK TITLE = -->
+<!-- = (from DC)  = -->
+<!-- ============== -->
+
+<xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
+    <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
+</xsl:template>
+
+<xsl:template match="rdf:RDF" mode="dctitle">
+    <cmd name="nazwapodutworu"><parm>
+        <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
+    </parm></cmd>
+</xsl:template>
+
+<xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
+    <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
+</xsl:template>
+
+<xsl:template match="rdf:RDF" mode="firstdctitle">
+    <cmd name="autorutworu"><parm>
+        <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
+    </parm></cmd>
+    <cmd name="nazwautworu"><parm>
+        <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
+    </parm></cmd>
+</xsl:template>
+
+
+<!-- ============================================================================== -->
+<!-- = MASTER TAG                                                                 = -->
+<!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
+<!-- ============================================================================== -->
+<!-- ==================================================================================== -->
+<!-- = BLOCK TAGS                                                                       = -->
+<!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
+<!-- ==================================================================================== -->
+
+<xsl:template 
+    match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|nota|dedykacja|dlugi_cytat|poezja_cyt|motto">
+    <cmd>
+        <xsl:attribute name="name">
+            <xsl:value-of select="wl:texcommand(name())" />
+        </xsl:attribute>
+        <parm><xsl:apply-templates/></parm>
+    </cmd>
+</xsl:template>
+
+<xsl:template match="lista_osob">
+    <cmd name="listaosob">
+        <parm><xsl:apply-templates select="naglowek_listy" /></parm>
+        <parm><xsl:apply-templates select="lista_osoba" /></parm>
+    </cmd>
+</xsl:template>
+
+<xsl:template match="kwestia">
+    <cmd name="kwestia">
+        <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
+    </cmd>
+</xsl:template>
+
+
+<!-- ========================================== -->
+<!-- = PARAGRAPH TAGS                         = -->
+<!-- = (can contain inline and special tags)  = -->
+<!-- ========================================== -->
+
+<!-- only in root -->
+<xsl:template match="autor_utworu" mode="title">
+    <cmd name="autorutworu"><parm>
+        <xsl:apply-templates mode="inline" />
+    </parm></cmd>
+</xsl:template>
+
+
+<xsl:template 
+    match="nazwa_utworu|podtytul|naglowek_akt|naglowek_czesc|srodtytul|naglowek_osoba|naglowek_podrozdzial|naglowek_scena|naglowek_rozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_dialog|akap_cd|motto_podpis|naglowek_listy">
+    <cmd>
+        <xsl:attribute name="name">
+            <xsl:value-of select="wl:texcommand(name())" />
+        </xsl:attribute>
+        <parm><xsl:apply-templates mode="inline"/></parm>
+    </cmd>
+</xsl:template>
+
+<xsl:template match="strofa">
+  <cmd name="strofa"><parm>
+    <xsl:choose>
+        <xsl:when test="count(br) > 0">
+            <xsl:call-template name="verse">
+                <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
+                <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
+            </xsl:call-template>
+            <xsl:for-each select="br">
+                <TeXML escape="0">\\{}</TeXML>
+                <!-- Each BR tag "consumes" text after it -->
+                <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
+                <xsl:call-template name="verse">
+                    <xsl:with-param name="verse-content"
+                        select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
+                    <xsl:with-param name="verse-type" select="following-sibling::*[count(preceding-sibling::br) = $lnum+1 and (name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd')][1]" />
+                </xsl:call-template>
+            </xsl:for-each>
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:call-template name="verse">
+                <xsl:with-param name="verse-content" select="text() | node()" />
+                <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
+            </xsl:call-template>
+        </xsl:otherwise>
+    </xsl:choose>
+  </parm></cmd>
+</xsl:template>
+
+
+<xsl:template name="verse">
+    <xsl:param name="verse-content" />
+    <xsl:param name="verse-type" />
+
+    <cmd>
+        <xsl:attribute name="name">
+            <xsl:choose>
+                <xsl:when test="$verse-type != ''">
+                    <xsl:value-of select='wl:texcommand(name($verse-type))' />
+                </xsl:when>
+                <xsl:otherwise>wers</xsl:otherwise>
+            </xsl:choose>
+        </xsl:attribute>
+        <xsl:if test="string($verse-content/@typ)">
+            <opt><xsl:value-of select="$verse-content/@typ" />em</opt>
+        </xsl:if>
+        <parm><xsl:apply-templates select="$verse-content" mode="inline"/></parm>
+    </cmd>
+</xsl:template>
+
+<!-- ================================================ -->
+<!-- = INLINE TAGS                                  = -->
+<!-- = (contain other inline tags and special tags) = -->
+<!-- ================================================ -->
+
+<xsl:template mode="inline"
+    match="pa|pe|pr|pt|mat|didask_tekst|slowo_obce|wyroznienie|osoba">
+    <cmd>
+        <xsl:attribute name="name">
+            <xsl:value-of select="wl:texcommand(name())" />
+        </xsl:attribute>
+        <parm><xsl:apply-templates mode="inline"/></parm>
+    </cmd>
+</xsl:template>
+
+
+
+<xsl:template match="tytul_dziela" mode="inline">
+    <cmd name="tytuldziela"><parm>
+        <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
+    </parm></cmd>
+</xsl:template>
+
+
+
+<!-- ============================================== -->
+<!-- = STANDALONE TAGS                            = -->
+<!-- = (cannot contain any other tags)            = -->
+<!-- ============================================== -->
+<xsl:template
+    match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
+    <cmd>
+        <xsl:attribute name="name">
+            <xsl:value-of select="wl:texcommand(name())" />
+        </xsl:attribute>
+    </cmd>
+</xsl:template>
+
+
+<!-- ================ -->
+<!-- = SPECIAL TAGS = -->
+<!-- ================ -->
+<!-- Themes -->
+
+
+<xsl:template match="begin|end|motyw">
+    <xsl:apply-templates select='.' mode="inline" />
+</xsl:template>
+
+<xsl:template match="begin" mode="inline" />
+<xsl:template match="end" mode="inline" />
+
+<xsl:template match="motyw" mode="inline">
+    <cmd name="motyw">
+        <xsl:if test="@moved">
+            <opt name="moved"><xsl:value-of select="@moved" /></opt>
+        </xsl:if>
+        <parm><xsl:apply-templates mode="inline" /></parm>
+    </cmd>
+</xsl:template>
+
+
+<!-- ============== -->
+<!-- = ADDED TAGS = -->
+<!-- ============== -->
+
+
+<xsl:template match="dywiz" mode="inline">
+    <cmd name="dywiz" />
+</xsl:template>
+
+<xsl:template match="nbsp" mode="inline">
+    <spec cat="tilde" />
+</xsl:template>
+
+<xsl:template match="alien" mode="inline">
+    <group>
+        <cmd name="alien" />
+        <xsl:apply-templates mode="inline" />
+    </group>
+</xsl:template>
+
+<!-- ================ -->
+<!-- = IGNORED TAGS = -->
+<!-- ================ -->
+<xsl:template match="extra|uwaga" />
+<xsl:template match="extra|uwaga" mode="inline" />
+
+<xsl:template match="nota_red" />
+
+<!-- ======== -->
+<!-- = TEXT = -->
+<!-- ======== -->
+<xsl:template match="text()" />
+<xsl:template match="text()" mode="inline">
+    <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
+      <xsl:text> </xsl:text>
+    </xsl:if>
+
+    <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
+
+    <xsl:if test="following-sibling::node() and wl:ends_white(.)">
+      <xsl:text> </xsl:text>
+    </xsl:if>
+</xsl:template>
+
+
+</xsl:stylesheet>
\ No newline at end of file
diff --git a/librarian/res/wl-logo-small.png b/librarian/res/wl-logo-small.png
new file mode 100644 (file)
index 0000000..104d56a
Binary files /dev/null and b/librarian/res/wl-logo-small.png differ
diff --git a/librarian/res/wl-logo.png b/librarian/res/wl-logo.png
new file mode 100644 (file)
index 0000000..03b46b5
Binary files /dev/null and b/librarian/res/wl-logo.png differ
diff --git a/librarian/xslt/wl2tex.xslt b/librarian/xslt/wl2tex.xslt
deleted file mode 100644 (file)
index c3abdd6..0000000
+++ /dev/null
@@ -1,354 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-   This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
-   Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
-  
--->
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
-    xmlns:wl="http://wolnelektury.pl/functions"
-    xmlns:dc="http://purl.org/dc/elements/1.1/"
-    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
-
-<xsl:output encoding="utf-8" indent="yes" version="2.0" />
-
-<xsl:template match="utwor">
-    <TeXML xmlns="http://getfo.sourceforge.net/texml/ns1">
-        <TeXML escape="0">
-        \documentclass[a4paper, oneside, 11pt]{book}
-        \usepackage{wl}
-        </TeXML>
-
-        <xsl:choose>
-            <xsl:when test="@morefloats = 'new'">
-                <TeXML escape="0">
-                    \usepackage[maxfloats=64]{morefloats}
-                </TeXML>
-            </xsl:when>
-            <xsl:when test="@morefloats = 'old'">
-                <TeXML escape="0">
-                    \usepackage{morefloats}
-                </TeXML>
-            </xsl:when>
-            <xsl:when test="@morefloats = 'none'" />
-            <xsl:otherwise>
-                <TeXML escape="0">
-                    \IfFileExists{morefloats.sty}{
-                        \usepackage{morefloats}
-                    }{}
-                </TeXML>
-            </xsl:otherwise>
-        </xsl:choose>
-
-        <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
-        <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
-
-        <env name="document">
-            <cmd name="maketitle" />
-
-            <xsl:choose>
-                <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
-                    <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/autor_utworu" mode="title" />
-                    <!-- title in master -->
-                </xsl:when>
-                <xsl:otherwise>
-                    <!-- look for author title in dc -->
-                    <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
-                    <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='firstdctitle' />
-                </xsl:otherwise>
-            </xsl:choose>
-            <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
-            <xsl:apply-templates select="utwor" mode="part" />
-        </env>
-    </TeXML>
-</xsl:template>
-
-<xsl:template match="utwor" mode="part">
-    <!-- title for empty dc -->
-    <xsl:choose>
-        <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
-            <!-- title in master -->
-        </xsl:when>
-        <xsl:otherwise>
-            <!-- look for title in dc -->
-            <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
-            <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
-        </xsl:otherwise>
-    </xsl:choose>
-
-    <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
-    <xsl:apply-templates select="utwor" mode="part" />
-</xsl:template>
-
-<!-- =================== -->
-<!-- = MAIN TITLE PAGE = -->
-<!-- = (from DC)       = -->
-<!-- =================== -->
-
-<xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
-    <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
-</xsl:template>
-
-<xsl:template match="rdf:RDF" mode="titlepage">
-    <cmd name='title'><parm>
-        <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
-    </parm></cmd>
-    <cmd name='author'><parm>
-        <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
-    </parm></cmd>
-    <TeXML escape="0">
-        \def\sourceinfo{<xsl:apply-templates select=".//dc:source" mode="inline" />}
-        \def\bookurl{<xsl:value-of select=".//dc:identifier.url" />}
-        \def\rightsinfo{Ten utwór nie jest chroniony prawem autorskim i~znajduje się w~domenie publicznej,
-            co oznacza, że możesz go swobodnie wykorzystywać, publikować i~rozpowszechniać.}
-        <xsl:if test=".//dc:rights.license">
-            \def\rightsinfo{Ten utwór jest udostepniony na licencji
-            \href{<xsl:value-of select=".//dc:rights.license" />}{<xsl:value-of select=".//dc:rights" />}.}
-        </xsl:if>
-    </TeXML>
-</xsl:template>
-
-
-<!-- ============== -->
-<!-- = BOOK TITLE = -->
-<!-- = (from DC)  = -->
-<!-- ============== -->
-
-<xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
-    <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
-</xsl:template>
-
-<xsl:template match="rdf:RDF" mode="dctitle">
-    <cmd name="nazwapodutworu"><parm>
-        <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
-    </parm></cmd>
-</xsl:template>
-
-<xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
-    <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
-</xsl:template>
-
-<xsl:template match="rdf:RDF" mode="firstdctitle">
-    <cmd name="autorutworu"><parm>
-        <xsl:apply-templates select=".//dc:creator_parsed/node()" mode="inline" />
-    </parm></cmd>
-    <cmd name="nazwautworu"><parm>
-        <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
-    </parm></cmd>
-</xsl:template>
-
-
-<!-- ============================================================================== -->
-<!-- = MASTER TAG                                                                 = -->
-<!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
-<!-- ============================================================================== -->
-<!-- ==================================================================================== -->
-<!-- = BLOCK TAGS                                                                       = -->
-<!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
-<!-- ==================================================================================== -->
-
-<xsl:template 
-    match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|nota|dedykacja|dlugi_cytat|poezja_cyt|motto">
-    <cmd>
-        <xsl:attribute name="name">
-            <xsl:value-of select="wl:texcommand(name())" />
-        </xsl:attribute>
-        <parm><xsl:apply-templates/></parm>
-    </cmd>
-</xsl:template>
-
-<xsl:template match="lista_osob">
-    <cmd name="listaosob">
-        <parm><xsl:apply-templates select="naglowek_listy" /></parm>
-        <parm><xsl:apply-templates select="lista_osoba" /></parm>
-    </cmd>
-</xsl:template>
-
-<xsl:template match="kwestia">
-    <cmd name="kwestia">
-        <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
-    </cmd>
-</xsl:template>
-
-
-<!-- ========================================== -->
-<!-- = PARAGRAPH TAGS                         = -->
-<!-- = (can contain inline and special tags)  = -->
-<!-- ========================================== -->
-
-<!-- only in root -->
-<xsl:template match="autor_utworu" mode="title">
-    <cmd name="autorutworu"><parm>
-        <xsl:apply-templates mode="inline" />
-    </parm></cmd>
-</xsl:template>
-
-
-<xsl:template 
-    match="nazwa_utworu|podtytul|naglowek_akt|naglowek_czesc|srodtytul|naglowek_osoba|naglowek_podrozdzial|naglowek_scena|naglowek_rozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_dialog|akap_cd|motto_podpis|naglowek_listy">
-    <cmd>
-        <xsl:attribute name="name">
-            <xsl:value-of select="wl:texcommand(name())" />
-        </xsl:attribute>
-        <parm><xsl:apply-templates mode="inline"/></parm>
-    </cmd>
-</xsl:template>
-
-<xsl:template match="strofa">
-  <cmd name="strofa"><parm>
-    <xsl:choose>
-        <xsl:when test="count(br) > 0">
-            <xsl:call-template name="verse">
-                <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
-                <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
-            </xsl:call-template>
-            <xsl:for-each select="br">
-                <TeXML escape="0">\\{}</TeXML>
-                <!-- Each BR tag "consumes" text after it -->
-                <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
-                <xsl:call-template name="verse">
-                    <xsl:with-param name="verse-content"
-                        select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
-                    <xsl:with-param name="verse-type" select="following-sibling::*[count(preceding-sibling::br) = $lnum+1 and (name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd')][1]" />
-                </xsl:call-template>
-            </xsl:for-each>
-        </xsl:when>
-        <xsl:otherwise>
-            <xsl:call-template name="verse">
-                <xsl:with-param name="verse-content" select="text() | node()" />
-                <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
-            </xsl:call-template>
-        </xsl:otherwise>
-    </xsl:choose>
-  </parm></cmd>
-</xsl:template>
-
-
-<xsl:template name="verse">
-    <xsl:param name="verse-content" />
-    <xsl:param name="verse-type" />
-
-    <cmd>
-        <xsl:attribute name="name">
-            <xsl:choose>
-                <xsl:when test="$verse-type != ''">
-                    <xsl:value-of select='wl:texcommand(name($verse-type))' />
-                </xsl:when>
-                <xsl:otherwise>wers</xsl:otherwise>
-            </xsl:choose>
-        </xsl:attribute>
-        <xsl:if test="string($verse-content/@typ)">
-            <opt><xsl:value-of select="$verse-content/@typ" />em</opt>
-        </xsl:if>
-        <parm><xsl:apply-templates select="$verse-content" mode="inline"/></parm>
-    </cmd>
-</xsl:template>
-
-<!-- ================================================ -->
-<!-- = INLINE TAGS                                  = -->
-<!-- = (contain other inline tags and special tags) = -->
-<!-- ================================================ -->
-
-<xsl:template mode="inline"
-    match="pa|pe|pr|pt|mat|didask_tekst|slowo_obce|wyroznienie|osoba">
-    <cmd>
-        <xsl:attribute name="name">
-            <xsl:value-of select="wl:texcommand(name())" />
-        </xsl:attribute>
-        <parm><xsl:apply-templates mode="inline"/></parm>
-    </cmd>
-</xsl:template>
-
-
-
-<xsl:template match="tytul_dziela" mode="inline">
-    <cmd name="tytuldziela"><parm>
-        <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
-    </parm></cmd>
-</xsl:template>
-
-
-
-<!-- ============================================== -->
-<!-- = STANDALONE TAGS                            = -->
-<!-- = (cannot contain any other tags)            = -->
-<!-- ============================================== -->
-<xsl:template
-    match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
-    <cmd>
-        <xsl:attribute name="name">
-            <xsl:value-of select="wl:texcommand(name())" />
-        </xsl:attribute>
-    </cmd>
-</xsl:template>
-
-
-<!-- ================ -->
-<!-- = SPECIAL TAGS = -->
-<!-- ================ -->
-<!-- Themes -->
-
-
-<xsl:template match="begin|end|motyw">
-    <xsl:apply-templates select='.' mode="inline" />
-</xsl:template>
-
-<xsl:template match="begin" mode="inline" />
-<xsl:template match="end" mode="inline" />
-
-<xsl:template match="motyw" mode="inline">
-    <cmd name="motyw">
-        <xsl:if test="@moved">
-            <opt name="moved"><xsl:value-of select="@moved" /></opt>
-        </xsl:if>
-        <parm><xsl:apply-templates mode="inline" /></parm>
-    </cmd>
-</xsl:template>
-
-
-<!-- ============== -->
-<!-- = ADDED TAGS = -->
-<!-- ============== -->
-
-
-<xsl:template match="dywiz" mode="inline">
-    <cmd name="dywiz" />
-</xsl:template>
-
-<xsl:template match="nbsp" mode="inline">
-    <spec cat="tilde" />
-</xsl:template>
-
-<xsl:template match="alien" mode="inline">
-    <group>
-        <cmd name="alien" />
-        <xsl:apply-templates mode="inline" />
-    </group>
-</xsl:template>
-
-<!-- ================ -->
-<!-- = IGNORED TAGS = -->
-<!-- ================ -->
-<xsl:template match="extra|uwaga" />
-<xsl:template match="extra|uwaga" mode="inline" />
-
-<xsl:template match="nota_red" />
-
-<!-- ======== -->
-<!-- = TEXT = -->
-<!-- ======== -->
-<xsl:template match="text()" />
-<xsl:template match="text()" mode="inline">
-    <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
-      <xsl:text> </xsl:text>
-    </xsl:if>
-
-    <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
-
-    <xsl:if test="following-sibling::node() and wl:ends_white(.)">
-      <xsl:text> </xsl:text>
-    </xsl:if>
-</xsl:template>
-
-
-</xsl:stylesheet>
\ No newline at end of file
index 5866cc3..e33ae13 100755 (executable)
@@ -14,7 +14,7 @@ from librarian.dcparser import BookInfo
 
 
 def utf_trunc(text, limit):
-""" truncates text to at most `limit' bytes in utf-8 """
+    """ truncates text to at most `limit' bytes in utf-8 """
     if text is None:
         return text
     orig_text = text
@@ -66,7 +66,7 @@ def virtualo(filenames, output_dir, verbose):
             product_elem[4][0][1].text = utf_trunc(info.author.last_name, 100)
             xml.append(product_elem)
 
-            cover.cover(600, 730, 
+            cover.virtualo_cover(
                 u' '.join(info.author.first_names + (info.author.last_name,)), 
                 info.title
                 ).save(os.path.join(outfile_dir, slug+'.jpg'))
index 98488dd..017cc57 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,7 @@ setup(
     maintainer_email='radek.czajka@gmail.com',
     url='http://github.com/fnp/librarian',
     packages=['librarian'],
-    package_data={'librarian': ['xslt/*.xslt', 'epub/*', 'pdf/*', 'fonts/*'] + 
+    package_data={'librarian': ['xslt/*.xslt', 'epub/*', 'pdf/*', 'fonts/*', 'res/*'] + 
                                 whole_tree(os.path.join(os.path.dirname(__file__), 'librarian'), 'font-optimizer')},
     include_package_data=True,
     install_requires=['lxml>=2.2'],