Fixes #3031: Sponsor info in PDF.
authorRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Fri, 7 Feb 2014 15:31:02 +0000 (16:31 +0100)
committerRadek Czajka <radekczajka@nowoczesnapolska.org.pl>
Fri, 7 Feb 2014 15:31:02 +0000 (16:31 +0100)
librarian/__init__.py
librarian/dcparser.py
librarian/pdf.py
librarian/pdf/wl.cls
librarian/pdf/wl2tex.xslt
librarian/res/sponsors/nck.png [new file with mode: 0644]
librarian/sponsor.py [new file with mode: 0644]
setup.py

index bf15d13..b257b79 100644 (file)
@@ -72,6 +72,7 @@ XINS = XMLNamespace("http://www.w3.org/2001/XInclude")
 XHTMLNS = XMLNamespace("http://www.w3.org/1999/xhtml")
 NCXNS = XMLNamespace("http://www.daisy.org/z3986/2005/ncx/")
 OPFNS = XMLNamespace("http://www.idpf.org/2007/opf")
 XHTMLNS = XMLNamespace("http://www.w3.org/1999/xhtml")
 NCXNS = XMLNamespace("http://www.daisy.org/z3986/2005/ncx/")
 OPFNS = XMLNamespace("http://www.idpf.org/2007/opf")
+PLMETNS = XMLNamespace("http://dl.psnc.pl/schemas/plmet/")
 
 WLNS = EmptyNamespace()
 
 
 WLNS = EmptyNamespace()
 
index ab1e714..12bb24f 100644 (file)
@@ -10,7 +10,7 @@ import re
 from librarian.util import roman_to_int
 
 from librarian import (ValidationError, NoDublinCore, ParseError, DCNS, RDFNS,
 from librarian.util import roman_to_int
 
 from librarian import (ValidationError, NoDublinCore, ParseError, DCNS, RDFNS,
-                       XMLNS, WLURI, WLNS)
+                       XMLNS, WLURI, WLNS, PLMETNS)
 
 import lxml.etree as etree # ElementTree API using libxml2
 from lxml.etree import XMLSyntaxError
 
 import lxml.etree as etree # ElementTree API using libxml2
 from lxml.etree import XMLSyntaxError
@@ -242,6 +242,9 @@ class WorkInfo(object):
         Field( DCNS('identifier.url'), 'url', WLURI, strict=as_wluri_strict),
         Field( DCNS('rights.license'), 'license', required=False),
         Field( DCNS('rights'), 'license_description'),
         Field( DCNS('identifier.url'), 'url', WLURI, strict=as_wluri_strict),
         Field( DCNS('rights.license'), 'license', required=False),
         Field( DCNS('rights'), 'license_description'),
+
+        Field( PLMETNS('digitisationSponsor'), 'sponsors', multiple=True, default=[]),
+        Field( WLNS('digitisationSponsorNote'), 'sponsor_note', required=False),
     )
 
     @classmethod
     )
 
     @classmethod
index 2154985..af258fc 100644 (file)
@@ -28,6 +28,7 @@ from librarian.parser import WLDocument
 from librarian import ParseError, DCNS, get_resource, OutputFile
 from librarian import functions
 from librarian.cover import DefaultEbookCover
 from librarian import ParseError, DCNS, get_resource, OutputFile
 from librarian import functions
 from librarian.cover import DefaultEbookCover
+from .sponsor import sponsor_logo
 
 
 functions.reg_substitute_entities()
 
 
 functions.reg_substitute_entities()
@@ -247,11 +248,23 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None,
         style_filename = get_stylesheet("wl2tex")
         style = etree.parse(style_filename)
 
         style_filename = get_stylesheet("wl2tex")
         style = etree.parse(style_filename)
 
-        texml = document.transform(style)
-
         # TeXML -> LaTeX
         temp = mkdtemp('-wl2pdf')
 
         # TeXML -> LaTeX
         temp = mkdtemp('-wl2pdf')
 
+        for sponsor in book_info.sponsors:
+            ins = etree.Element("data-sponsor", name=sponsor)
+            logo = sponsor_logo(sponsor)
+            if logo:
+                fname = 'sponsor-%s' % os.path.basename(logo)
+                shutil.copy(logo, os.path.join(temp, fname))
+                ins.set('src', fname)
+            root.insert(0, ins)
+                
+        if book_info.sponsor_note:
+            root.set("sponsor-note", book_info.sponsor_note)
+
+        texml = document.transform(style)
+
         if cover:
             with open(os.path.join(temp, 'cover.png'), 'w') as f:
                 bound_cover.save(f)
         if cover:
             with open(os.path.join(temp, 'cover.png'), 'w') as f:
                 bound_cover.save(f)
index a9ace8e..8907b08 100644 (file)
@@ -126,6 +126,8 @@ Letters={SmallCaps,UppercaseSmallCaps}
 
 \pagestyle{plain}
 \usepackage{fancyhdr}
 
 \pagestyle{plain}
 \usepackage{fancyhdr}
+\usepackage{marginnote}
+
 
 \makeatletter
 
 
 \makeatletter
 
@@ -238,6 +240,13 @@ Letters={SmallCaps,UppercaseSmallCaps}
     \color{theme}
     \noindent \rule{\linewidth}{0.4pt}
 
     \color{theme}
     \noindent \rule{\linewidth}{0.4pt}
 
+    \ifdefined\sponsors
+        \marginnote{%
+            \centering%
+            \sponsors%
+        }
+    \fi
+
     \rightsinfo
     \vspace{.6em}
 
     \rightsinfo
     \vspace{.6em}
 
index ca948da..c120fb0 100644 (file)
                     \def\funders{Publikację ufundowali i ufundowały:
                         <TeXML escape="1"><xsl:value-of select="@funders" /></TeXML>.}
                 </xsl:if>
                     \def\funders{Publikację ufundowali i ufundowały:
                         <TeXML escape="1"><xsl:value-of select="@funders" /></TeXML>.}
                 </xsl:if>
+
+                <xsl:if test="@sponsor-note|data-sponsor">
+                    \def\sponsors{
+                        \scriptsize
+                        <xsl:choose>
+                            <xsl:when test="@sponsor-note">
+                                <TeXML escape="1"><xsl:value-of select="@sponsor-note" /></TeXML>
+                            </xsl:when>
+                            <xsl:otherwise>
+                                Sfinansowano ze~środków:
+                            </xsl:otherwise>
+                        </xsl:choose>
+
+                        \vspace{1em}
+
+                        <xsl:apply-templates select="data-sponsor" mode="sponsor" />
+                    }
+                </xsl:if>
             </TeXML>
 
             <cmd name="editorialsection" />
             </TeXML>
 
             <cmd name="editorialsection" />
     </xsl:if>
 </xsl:template>
 
     </xsl:if>
 </xsl:template>
 
+<xsl:template match="data-sponsor" mode="sponsor">
+    <cmd name="par"><parm>
+    <xsl:choose>
+        <xsl:when test="@src">
+            \includegraphics[height=0.25\textwidth,width=0.25\textwidth,keepaspectratio]{<xsl:value-of select="@src" />}
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:value-of select="@name" />
+        </xsl:otherwise>
+    </xsl:choose>
+    </parm></cmd>
+</xsl:template>
 
 <!-- ============== -->
 <!-- = ADDED TAGS = -->
 
 <!-- ============== -->
 <!-- = ADDED TAGS = -->
diff --git a/librarian/res/sponsors/nck.png b/librarian/res/sponsors/nck.png
new file mode 100644 (file)
index 0000000..e53f19c
Binary files /dev/null and b/librarian/res/sponsors/nck.png differ
diff --git a/librarian/sponsor.py b/librarian/sponsor.py
new file mode 100644 (file)
index 0000000..15d9107
--- /dev/null
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from librarian import get_resource
+
+def sponsor_logo(name):
+    return {
+        'Narodowe Centrum Kultury': get_resource('res/sponsors/nck.png')
+    }.get(name.strip())
index 7bcbbc2..732f145 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,8 @@ setup(
     maintainer_email='radoslaw.czajka@nowoczesnapolska.org.pl',
     url='http://github.com/fnp/librarian',
     packages=['librarian'],
     maintainer_email='radoslaw.czajka@nowoczesnapolska.org.pl',
     url='http://github.com/fnp/librarian',
     packages=['librarian'],
-    package_data={'librarian': ['xslt/*.xslt', 'epub/*', 'mobi/*', 'pdf/*', 'fb2/*', 'fonts/*', 'res/*'] +
+    package_data={'librarian': ['xslt/*.xslt', 'epub/*', 'mobi/*', 'pdf/*', 'fb2/*', 'fonts/*'] +
+                                whole_tree(os.path.join(os.path.dirname(__file__), 'librarian'), 'res') +
                                 whole_tree(os.path.join(os.path.dirname(__file__), 'librarian'), 'font-optimizer')},
     include_package_data=True,
     install_requires=[
                                 whole_tree(os.path.join(os.path.dirname(__file__), 'librarian'), 'font-optimizer')},
     include_package_data=True,
     install_requires=[