from librarian import DirDocProvider, ParseError
from librarian.parser import WLDocument
-from librarian.cover import DefaultEbookCover
+from librarian.cover import make_cover
class Option(object):
# Add cover support, if any.
if cls.uses_cover:
if options.image_cache:
- def cover_class(*args, **kwargs):
- return DefaultEbookCover(image_cache=options.image_cache, *args, **kwargs)
+ def cover_class(book_info, *args, **kwargs):
+ return make_cover(book_info, image_cache=options.image_cache, *args, **kwargs)
transform_args['cover'] = cover_class
elif not cls.cover_optional or options.with_cover:
- transform_args['cover'] = DefaultEbookCover
+ transform_args['cover'] = make_cover
# Do some real work
try:
dir_y = 1 if corner_y == 0 else -1
for offset in (-1, 0, 1):
draw.line((corner_x, corner_y + dir_y * metr.bleed + offset,
- corner_x + dir_x * metr.bleed * line_ratio, corner_y + dir_y * metr.bleed + offset),
+ corner_x + dir_x * metr.bleed * line_ratio, corner_y + dir_y * metr.bleed + offset),
fill='black' if offset == 0 else 'white', width=1)
draw.line((corner_x + dir_x * metr.bleed + offset, corner_y,
corner_x + dir_x * metr.bleed + offset, corner_y + dir_y * metr.bleed * line_ratio),
format = 'PNG'
-DefaultEbookCover = LogoWLCover
+class KMLUCover(LogoWLCover):
+ gradient_logo_height = 58
+ gradient_logo_spacing = 25
+ gradient_logos = [
+ 'res/kmlu-logo-white.png',
+ 'res/wl-logo-white.png',
+ 'res/fnp-logo-white.png',
+ ]
+
+
+COVER_CLASSES = {
+ 'default': LogoWLCover,
+ 'kmlu': KMLUCover,
+}
+
+
+def make_cover(book_info, *args, **kwargs):
+ cover_class = COVER_CLASSES[book_info.cover_class]
+ return cover_class(book_info, *args, **kwargs)
Field(DCNS('type'), 'type', required=False, multiple=True),
Field(DCNS('contributor.editor'), 'editors',
- as_person, salias='editor', multiple=True, default=[]),
+ as_person, salias='editor', multiple=True, required=False),
Field(DCNS('contributor.technical_editor'), 'technical_editors',
- as_person, salias='technical_editor', multiple=True, default=[]),
- Field(DCNS('contributor.funding'), 'funders', salias='funder', multiple=True, default=[]),
+ as_person, salias='technical_editor', multiple=True, required=False),
+ Field(DCNS('contributor.funding'), 'funders', salias='funder', multiple=True, required=False),
Field(DCNS('contributor.thanks'), 'thanks', required=False),
Field(DCNS('date'), 'created_at'),
Field(DCNS('rights.license'), 'license', required=False),
Field(DCNS('rights'), 'license_description'),
- Field(PLMETNS('digitisationSponsor'), 'sponsors', multiple=True, default=[]),
+ Field(PLMETNS('digitisationSponsor'), 'sponsors', multiple=True, required=False),
Field(WLNS('digitisationSponsorNote'), 'sponsor_note', required=False),
Field(WLNS('developmentStage'), 'stage', required=False),
)
Field(DCNS('subject.genre'), 'genres', salias='genre', multiple=True, required=False),
Field(DCNS('contributor.translator'), 'translators',
- as_person, salias='translator', multiple=True, default=[]),
+ as_person, salias='translator', multiple=True, required=False),
Field(DCNS('relation.hasPart'), 'parts', WLURI, strict=as_wluri_strict, multiple=True, required=False),
Field(DCNS('relation.isVariantOf'), 'variant_of', WLURI, strict=as_wluri_strict, required=False),
# WLCover-specific.
Field(WLNS('coverBarColor'), 'cover_bar_color', required=False),
Field(WLNS('coverBoxPosition'), 'cover_box_position', required=False),
+ Field(WLNS('coverClass'), 'cover_class', default=['default']),
Field('pdf-id', 'isbn_pdf', required=False),
Field('epub-id', 'isbn_epub', required=False),
Field('mobi-id', 'isbn_mobi', required=False),
from shutil import rmtree
from librarian import RDFNS, WLNS, NCXNS, OPFNS, XHTMLNS, DCNS, OutputFile
-from librarian.cover import DefaultEbookCover
+from librarian.cover import make_cover
from librarian import functions, get_resource
if cover:
if cover is True:
- cover = DefaultEbookCover
+ cover = make_cover
cover_file = StringIO()
bound_cover = cover(document.book_info)
#
from librarian import ValidationError, NoDublinCore, ParseError, NoProvider
from librarian import RDFNS
-from librarian.cover import DefaultEbookCover
+from librarian.cover import make_cover
from librarian import dcparser
from xml.parsers.expat import ExpatError
def as_cover(self, cover_class=None, *args, **kwargs):
if cover_class is None:
- cover_class = DefaultEbookCover
+ cover_class = make_cover
return cover_class(self.book_info, *args, **kwargs).output_file()
# for debugging only
from librarian.parser import WLDocument
from librarian import ParseError, DCNS, get_resource, OutputFile
from librarian import functions
-from librarian.cover import DefaultEbookCover
+from librarian.cover import make_cover
from .sponsor import sponsor_logo
if cover:
if cover is True:
- cover = DefaultEbookCover
+ cover = make_cover
bound_cover = cover(book_info, width=1200)
root.set('data-cover-width', str(bound_cover.width))
root.set('data-cover-height', str(bound_cover.height))