# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
-import os
import re
import urllib
from .utils import XMLNamespace
message = unicode(args, encoding='utf-8', errors='ignore')
return message
+
class ParseError(UnicodeException):
pass
+
class ValidationError(UnicodeException):
pass
+class BuildError(Exception):
+ pass
+
+
class EmptyNamespace(XMLNamespace):
def __init__(self):
super(EmptyNamespace, self).__init__('')
slug = None
example = 'http://wolnelektury.pl/katalog/lektura/template/'
- _re_wl_uri = re.compile(r'http://(www\.)?wolnelektury.pl/katalog/lektura/'
- '(?P<slug>[-a-z0-9]+)/?$')
+ _re_wl_uri = re.compile(r'http://(www\.)?wolnelektury.pl/katalog/lektura/(?P<slug>[-a-z0-9]+)/?$')
def __init__(self, uri):
uri = unicode(uri)
class URLOpener(urllib.FancyURLopener):
version = 'FNP Librarian (http://git.nowoczesnapolska.org.pl/?p=librarian.git)'
urllib._urlopener = URLOpener()
-
logo_bottom = None
logo_width = None
+ logo_file = get_resource('res/wl-logo.png')
uses_dc_cover = False
format = 'JPEG'
if self.background_img:
background = Image.open(self.background_img)
- img.paste(background, None, background)
- del background
+ resized = background.resize((1024, background.height*1024/background.width), Image.ANTIALIAS)
+ resized = resized.convert('RGBA')
+ img.paste(resized, (0, 0), resized)
+ del background, resized
- # WL logo
if metr.logo_width:
- logo = Image.open(get_resource('res/wl-logo.png'))
- logo = logo.resize((metr.logo_width, logo.size[1] * metr.logo_width / logo.size[0]))
- img.paste(logo, ((metr.width - metr.logo_width) / 2, img.size[1] - logo.size[1] - metr.logo_bottom))
+ logo = Image.open(self.logo_file)
+ logo = logo.resize((metr.logo_width, logo.size[1] * metr.logo_width / logo.size[0]), Image.ANTIALIAS)
+ logo = logo.convert('RGBA')
+ img.paste(logo, ((metr.width - metr.logo_width) / 2,
+ img.size[1] - logo.size[1] - metr.logo_bottom), logo)
top = metr.author_top
tbox = TextBox(
--- /dev/null
+# -*- 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.
+#
+import urllib
+from urllib2 import urlopen, URLError
+
+from librarian import DCNS, BuildError
+from .. import Cover
+
+
+class EvensCover(Cover):
+ format_name = u"Evens cover image"
+ width = 1024
+ height = 1365
+ author_top = 900
+ title_top = 30
+ logo_bottom = 100
+
+ def __init__(self, doc, format=None, width=None, height=None):
+ super(EvensCover, self).__init__(doc, format=format, width=width, height=height)
+ self.doc = doc
+
+ def set_images(self, ctx):
+ cover_url = self.doc.meta.get(DCNS('relation.coverimage.url'))[0]
+ if cover_url.startswith('file://'):
+ cover_url = ctx.files_path + urllib.quote(cover_url[7:])
+ try:
+ self.background_img = urlopen(cover_url)
+ except URLError:
+ raise BuildError('Cannot open the cover image: %s' % cover_url)
+
+ if getattr(ctx, 'cover_logo', None):
+ self.logo_width = 150
+ self.logo_file = urlopen(ctx.cover_logo)
from librarian import OPFNS, NCXNS, XHTMLNS, DCNS
from librarian import core
from librarian.formats import Format
-from librarian.formats.cover.wolnelektury import WLCover
+from librarian.formats.cover.evens import EvensCover
from librarian.output import OutputFile
from librarian.renderers import Register, TreeRenderer, UnknownElement
from librarian.utils import Context, get_resource, extend_element
format_name = 'EPUB'
format_ext = 'epub'
- cover = WLCover
+ cover = EvensCover
renderers = Register()
def __init__(self, doc, cover=None, with_fonts=True):
# nav_map = toc_file[-1]
if self.cover is not None:
- cover_image = self.doc.meta.get(DCNS('relation.coverimage.url'))[0]
+ # cover_image = self.doc.meta.get(DCNS('relation.coverimage.url'))[0]
cover = self.cover(self.doc)
+ cover.set_images(ctx)
cover_output = cover.build()
cover_name = 'cover.%s' % cover.format_ext
zip.writestr(os.path.join('OPS', cover_name), cover_output.get_string())
wrap_tmpl = etree.parse(get_resource('formats/epub/res/chapter.html'))
for e in self.render(self.doc.edoc.getroot(), ctx):
- if not len(e) and not e.text.strip():
+ if not len(e) and not (e.text and e.text.strip()):
continue
wrap = deepcopy(wrap_tmpl)
extend_element(wrap.find('//*[@id="book-text"]'), e)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
- <title>Okładka</title>
+ <title>Cover</title>
<style type="text/css"> img { max-width: 100%; } </style>
</head>
<body style="oeb-column-number: 1;">
<div id="cover-image">
- <img alt="Okładka" />
+ <img alt="Cover" />
</div>
</body>
</html>
\ No newline at end of file