From: Radek Czajka Date: Fri, 7 Feb 2014 15:31:02 +0000 (+0100) Subject: Fixes #3031: Sponsor info in PDF. X-Git-Tag: 1.7~111 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/3df78775bc9e2e4d861bc0eaa4deadd354dda518?ds=sidebyside Fixes #3031: Sponsor info in PDF. --- diff --git a/librarian/__init__.py b/librarian/__init__.py index bf15d13..b257b79 100644 --- a/librarian/__init__.py +++ b/librarian/__init__.py @@ -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") +PLMETNS = XMLNamespace("http://dl.psnc.pl/schemas/plmet/") WLNS = EmptyNamespace() diff --git a/librarian/dcparser.py b/librarian/dcparser.py index ab1e714..12bb24f 100644 --- a/librarian/dcparser.py +++ b/librarian/dcparser.py @@ -10,7 +10,7 @@ import re 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 @@ -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( PLMETNS('digitisationSponsor'), 'sponsors', multiple=True, default=[]), + Field( WLNS('digitisationSponsorNote'), 'sponsor_note', required=False), ) @classmethod diff --git a/librarian/pdf.py b/librarian/pdf.py index 2154985..af258fc 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -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 .sponsor import sponsor_logo 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) - texml = document.transform(style) - # 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) diff --git a/librarian/pdf/wl.cls b/librarian/pdf/wl.cls index a9ace8e..8907b08 100644 --- a/librarian/pdf/wl.cls +++ b/librarian/pdf/wl.cls @@ -126,6 +126,8 @@ Letters={SmallCaps,UppercaseSmallCaps} \pagestyle{plain} \usepackage{fancyhdr} +\usepackage{marginnote} + \makeatletter @@ -238,6 +240,13 @@ Letters={SmallCaps,UppercaseSmallCaps} \color{theme} \noindent \rule{\linewidth}{0.4pt} + \ifdefined\sponsors + \marginnote{% + \centering% + \sponsors% + } + \fi + \rightsinfo \vspace{.6em} diff --git a/librarian/pdf/wl2tex.xslt b/librarian/pdf/wl2tex.xslt index ca948da..c120fb0 100644 --- a/librarian/pdf/wl2tex.xslt +++ b/librarian/pdf/wl2tex.xslt @@ -110,6 +110,24 @@ \def\funders{Publikację ufundowali i ufundowały: .} + + + \def\sponsors{ + \scriptsize + + + + + + Sfinansowano ze~środków: + + + + \vspace{1em} + + + } + @@ -404,6 +422,18 @@ + + + + + \includegraphics[height=0.25\textwidth,width=0.25\textwidth,keepaspectratio]{} + + + + + + + diff --git a/librarian/res/sponsors/nck.png b/librarian/res/sponsors/nck.png new file mode 100644 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 index 0000000..15d9107 --- /dev/null +++ b/librarian/sponsor.py @@ -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()) diff --git a/setup.py b/setup.py index 7bcbbc2..732f145 100755 --- 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'], - 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=[