From: Radek Czajka Date: Mon, 17 Jan 2011 15:37:06 +0000 (+0100) Subject: epub: subtitle fix X-Git-Tag: 1.7~220 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/1e0f8d82649a23f695333d5ef4588e8b60afbe99 epub: subtitle fix epub: editorial page, title page update epubs for asbis more cover generation --- diff --git a/librarian/cover.py b/librarian/cover.py index c946d43..20cca66 100644 --- a/librarian/cover.py +++ b/librarian/cover.py @@ -43,7 +43,7 @@ def cover(author, title, if background_img: background = Image.open(background_img) - img.paste(background) + img.paste(background, None, background) del background # WL logo @@ -72,9 +72,9 @@ def virtualo_cover(author, title): 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', + 580, 783, '#fff', get_resource('res/cover-prestigio.png'), + 446, 118, 62, 60, '#fff', ImageFont.truetype(get_resource('fonts/JunicodeWL-Italic.ttf'), 50), '#000', + 0, 118, 62, 60, '#fff', ImageFont.truetype(get_resource('fonts/JunicodeWL-Italic.ttf'), 50), '#000', None, None ) diff --git a/librarian/dcparser.py b/librarian/dcparser.py index 07a90d7..49a33d4 100644 --- a/librarian/dcparser.py +++ b/librarian/dcparser.py @@ -38,6 +38,9 @@ class Person(object): names = [ name for name in parts[1].split() if len(name) ] # all non-whitespace tokens return cls(surname, *names) + def readable(self): + return u" ".join(self.first_names + (self.last_name,)) + def __eq__(self, right): return self.last_name == right.last_name and self.first_names == right.first_names diff --git a/librarian/epub.py b/librarian/epub.py index 666bcc9..ad84ab0 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -8,6 +8,7 @@ from __future__ import with_statement import os import os.path import subprocess +from StringIO import StringIO from copy import deepcopy from lxml import etree import zipfile @@ -105,7 +106,7 @@ def find_annotations(annotations, source, part_no): child.clear() child.tail = tail child.text = number - if child.tag not in ('extra', 'podtytul'): + if child.tag not in ('extra',): find_annotations(annotations, child, part_no) @@ -264,7 +265,7 @@ def transform_chunk(chunk_xml, chunk_no, annotations, empty=False, _empty_html_s return output_html, toc, chars -def transform(provider, slug=None, file_path=None, output_file=None, output_dir=None, make_dir=False, verbose=False, sample=None): +def transform(provider, slug=None, file_path=None, output_file=None, output_dir=None, make_dir=False, verbose=False, sample=None, cover_fn=None): """ produces a EPUB file provider: a DocProvider @@ -273,6 +274,7 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir= output_dir: path to directory to save output file to; either this or output_file must be present make_dir: writes output to //.epub instead of /.epub sample=n: generate sample e-book (with at least n paragraphs) + cover_fn: function(author, title) -> cover image """ def transform_file(input_xml, chunk_counter=1, first=True, sample=None): @@ -393,6 +395,21 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir= manifest = opf.find('.//' + OPFNS('manifest')) spine = opf.find('.//' + OPFNS('spine')) + if cover_fn: + cover = StringIO() + cover_fn(book_info.author.readable(), book_info.title).save(cover, format='JPEG') + zip.writestr(os.path.join('OPS', 'cover.jpg'), cover.getvalue()) + del cover + zip.writestr('OPS/cover.html', open(get_resource('epub/cover.html')).read()) + manifest.append(etree.fromstring( + '')) + manifest.append(etree.fromstring( + '')) + spine.insert(0, etree.fromstring('')) + opf.getroot()[0].append(etree.fromstring('')) + opf.getroot().append(etree.fromstring('')) + + annotations = etree.Element('annotations') toc_file = etree.fromstring('Przypisy'\ '' % {'i': toc_counter})) + toc_counter += 1 manifest.append(etree.fromstring( '')) spine.append(etree.fromstring( @@ -425,6 +443,18 @@ def transform(provider, slug=None, file_path=None, output_file=None, output_dir= zip.writestr('OPS/annotations.html', etree.tostring( html_tree, method="html", pretty_print=True)) + nav_map.append(etree.fromstring( + 'Strona redakcyjna'\ + '' % {'i': toc_counter})) + manifest.append(etree.fromstring( + '')) + spine.append(etree.fromstring( + '')) + html_tree = xslt(input_xml, get_resource('epub/xsltLast.xsl')) + chars.update(used_chars(html_tree.getroot())) + zip.writestr('OPS/last.html', etree.tostring( + html_tree, method="html", pretty_print=True)) + # strip fonts tmpdir = mkdtemp('-librarian-epub') cwd = os.getcwd() diff --git a/librarian/epub/cover.html b/librarian/epub/cover.html new file mode 100644 index 0000000..bbe8508 --- /dev/null +++ b/librarian/epub/cover.html @@ -0,0 +1,13 @@ + + + + + Okładka + + + +
+ Okładka +
+ + \ No newline at end of file diff --git a/librarian/epub/style.css b/librarian/epub/style.css index 21a82a8..55ac117 100644 --- a/librarian/epub/style.css +++ b/librarian/epub/style.css @@ -37,6 +37,11 @@ body a { text-decoration: none; + color: #00e; +} + +a img { + border: 0; } #book-text @@ -157,13 +162,11 @@ p .title-page { margin-top: 1.5em; - margin-bottom: 1.5em; } .title { font-size: 3em; - margin-bottom: 1.5em; text-align: center; line-height: 1.5em; font-weight: bold; @@ -337,3 +340,10 @@ p.info img margin-left: 2em; margin-right: 2em; } + +p.minor { + font-size: 0.75em; +} +p.footer { + margin-top: 2em; +} diff --git a/librarian/epub/xsltLast.xsl b/librarian/epub/xsltLast.xsl new file mode 100644 index 0000000..6cb2748 --- /dev/null +++ b/librarian/epub/xsltLast.xsl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + <xsl:text>Strona redakcyjna</xsl:text> + + + +
+

+ + + Ten utwór jest udostepniony na licencji + + + + + + + + + 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ć. Jeśli utwór opatrzony jest dodatkowymi materiałami + (przypisy, motywy literackie etc.) które podlegają prawu autorskiemu, to + te dodatkowe materiały udostępnione są na licencji + Creative Commons + Uznanie Autorstwa - Na Tych Samych Warunkach 3.0 PL. + + +

+ +

Źródło: + + + + + , + + +

+ + +

Na podstawie:

+
+ + +

+ Opracowanie redakcyjne i przypisy: + +

+
+ +

 

+

+ Plik wygenerowany dnia . +

+ +
+ + +
+ + + + + + +
+
+ + + + +
\ No newline at end of file diff --git a/librarian/epub/xsltScheme.xsl b/librarian/epub/xsltScheme.xsl index bb96350..8b384c3 100644 --- a/librarian/epub/xsltScheme.xsl +++ b/librarian/epub/xsltScheme.xsl @@ -19,6 +19,7 @@ + @@ -101,7 +102,7 @@ -

+

@@ -287,8 +288,6 @@ - - diff --git a/librarian/epub/xsltTitle.xsl b/librarian/epub/xsltTitle.xsl index e8afdac..347f038 100644 --- a/librarian/epub/xsltTitle.xsl +++ b/librarian/epub/xsltTitle.xsl @@ -1,5 +1,6 @@ - @@ -8,7 +9,7 @@ - + @@ -17,7 +18,7 @@ -
+
@@ -30,30 +31,27 @@
-

Publikacja zrealizowana w ramach projektu WolneLektury.pl

- -

Na podstawie:

-
-

- - - Ten utwór jest udostepniony na licencji - - - - - - - - - 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ć - - -

+

 

+ + + +

- WolneLektury.pl + Utwór opracowany został w ramach projektu Wolne Lektury przez Fundację Nowoczesna Polska. +

+ +
@@ -69,55 +67,61 @@ -
- -
+

+ +

-
- -
+

+ +

+
+ + +

+ tłum. +

+
+ + + -
+

-

+
-
+

-

+
-

+

-

+

-
+

-

+
- - - - \ No newline at end of file diff --git a/librarian/functions.py b/librarian/functions.py index e5023b3..08f920d 100644 --- a/librarian/functions.py +++ b/librarian/functions.py @@ -91,8 +91,7 @@ def reg_person_name(): """ Converts "Name, Forename" to "Forename Name" """ if isinstance(text, list): text = ''.join(text) - p = Person.from_text(text) - return ' '.join(p.first_names + (p.last_name,)) + return Person.from_text(text).readable() _register_function(person_name) diff --git a/librarian/res/cover-prestigio.png b/librarian/res/cover-prestigio.png new file mode 100644 index 0000000..b56843f Binary files /dev/null and b/librarian/res/cover-prestigio.png differ diff --git a/scripts/book2partner b/scripts/book2partner index e33ae13..6f2beac 100755 --- a/scripts/book2partner +++ b/scripts/book2partner @@ -86,6 +86,29 @@ def virtualo(filenames, output_dir, verbose): xml_file.close() +def asbis(filenames, output_dir, verbose): + try: + for main_input in input_filenames: + if options.verbose: + print main_input + path, fname = os.path.realpath(main_input).rsplit('/', 1) + provider = DirDocProvider(path) + slug, ext = os.path.splitext(fname) + + if output_dir != '': + try: + os.makedirs(output_dir) + except: + pass + outfile = os.path.join(output_dir, slug + '.epub') + epub.transform(provider, file_path=main_input, output_file=outfile, cover_fn=cover.asbis_cover) + except ParseError, e: + print '%(file)s:%(name)s:%(message)s' % { + 'file': main_input, + 'name': e.__class__.__name__, + 'message': e.message + } + if __name__ == '__main__': @@ -101,6 +124,8 @@ if __name__ == '__main__': help='specifies the directory for output') parser.add_option('--virtualo', action='store_true', dest='virtualo', default=False, help='prepare files for Virtualo API') + parser.add_option('--asbis', action='store_true', dest='asbis', default=False, + help='prepare files for Asbis') options, input_filenames = parser.parse_args() @@ -110,3 +135,6 @@ if __name__ == '__main__': if options.virtualo: virtualo(input_filenames, options.output_dir, options.verbose) + if options.asbis: + asbis(input_filenames, options.output_dir, options.verbose) + \ No newline at end of file