X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/b6ec0976a383cc1823f4a199bc3e6dc40880b049..82f5d8f05bad9e5223426c210770602ca2a97c9b:/librarian/pdf.py?ds=sidebyside diff --git a/librarian/pdf.py b/librarian/pdf.py index 02438a6..f22a305 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -21,6 +21,7 @@ from librarian.dcparser import Person from librarian.parser import WLDocument from librarian import ParseError, DCNS, get_resource, OutputFile from librarian import functions +from librarian.cover import ImageCover as WLCover functions.reg_substitute_entities() @@ -33,13 +34,14 @@ STYLESHEETS = { 'wl2tex': 'pdf/wl2tex.xslt', } -CUSTOMIZATIONS = [ - 'nofootnotes', - 'nothemes', - 'onehalfleading', - 'doubleleading', - 'nowlfont', - ] +#CUSTOMIZATIONS = [ +# 'nofootnotes', +# 'nothemes', +# 'defaultleading', +# 'onehalfleading', +# 'doubleleading', +# 'nowlfont', +# ] def insert_tags(doc, split_re, tagname, exclude=None): """ inserts for every occurence of `split_re' in text nodes in the `doc' tree @@ -172,7 +174,8 @@ def package_available(package, args='', verbose=False): def transform(wldoc, verbose=False, save_tex=None, morefloats=None, - cover=None, flags=None, customizations=None): + cover=None, flags=None, customizations=None, + imgdir=""): """ produces a PDF file with XeLaTeX wldoc: a WLDocument @@ -189,8 +192,16 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, document = load_including_children(wldoc) if cover: - document.edoc.getroot().set('data-cover-width', str(cover.width)) - document.edoc.getroot().set('data-cover-height', str(cover.height)) + if cover is True: + cover = WLCover + the_cover = cover(document.book_info) + document.edoc.getroot().set('data-cover-width', str(the_cover.width)) + document.edoc.getroot().set('data-cover-height', str(the_cover.height)) + if the_cover.uses_dc_cover: + if document.book_info.cover_by: + document.edoc.getroot().set('data-cover-by', document.book_info.cover_by) + if document.book_info.cover_source: + document.edoc.getroot().set('data-cover-source', document.book_info.cover_source) if flags: for flag in flags: document.edoc.getroot().set('flag-' + flag, 'yes') @@ -206,10 +217,11 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, document.edoc.getroot().set('customizations', u','.join(customizations)) # hack the tree - move_motifs_inside(document.edoc) - hack_motifs(document.edoc) + #move_motifs_inside(document.edoc) + #hack_motifs(document.edoc) parse_creator(document.edoc) - substitute_hyphens(document.edoc) + if document.book_info.language == 'pol': + substitute_hyphens(document.edoc) fix_hanging(document.edoc) # wl -> TeXML @@ -217,14 +229,18 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, style = etree.parse(style_filename) texml = document.transform(style) - + etree.dump(texml.getroot()) # TeXML -> LaTeX temp = mkdtemp('-wl2pdf') if cover: - c = cover(document.book_info.author.readable(), document.book_info.title) - with open(os.path.join(temp, 'cover.png'), 'w') as f: - c.save(f) + with open(os.path.join(temp, 'cover.jpg'), 'w') as f: + the_cover.save(f) + + shutil.copy("logo.eps", temp) + for img in document.edoc.findall('//ilustr'): + shutil.copy(os.path.join(imgdir, img.get('src')), temp) + del document # no longer needed large object :) @@ -240,6 +256,7 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, # LaTeX -> PDF shutil.copy(get_resource('pdf/wl.cls'), temp) shutil.copy(get_resource('res/wl-logo.png'), temp) + shutil.copy('logo.eps', temp) cwd = os.getcwd() os.chdir(temp) @@ -260,6 +277,7 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, return OutputFile.from_filename(output_file.name) except (XMLSyntaxError, XSLTApplyError), e: + print e raise ParseError(e)