+class PDFFormat(Format):
+ """ Base PDF format.
+
+ Available customization:
+ nofootnotes: Doesn't do footnotes.
+ nothemes: Doesn't do themes.
+ defaultleading: Default leading.
+ onehalfleading: Bigger leading.
+ doubleleading: Big leading.
+ nowlfont: Uses standard TeX font instead of JUnicodeWL.
+
+ """
+
+ cover_class = None
+ tex_passes = 1
+ style = get_resource('pdf/default.sty')
+ cover = None
+
+ @property
+ def has_cover(self):
+ """ For use in XSLT. """
+ return self.cover is not None
+
+ @property
+ def customization_str(self):
+ """ For use in XSLT. """
+ return u','.join(k for k, v in self.customization.items() if v)
+
+ def get_document(self):
+ document = load_including_children(self.wldoc)
+ root = document.edoc.getroot()
+ root.set('editors', u', '.join(sorted(
+ editor.readable() for editor in document.editors())))
+
+ # hack the tree
+ move_motifs_inside(document.edoc)
+ hack_motifs(document.edoc)
+ parse_creator(document.edoc)
+ substitute_hyphens(document.edoc)
+ fix_hanging(document.edoc)
+ return document
+
+ def get_texml(self):
+ style_filename = get_stylesheet("wl2tex")
+ functions.reg_get(self)
+ try:
+ style = etree.parse(style_filename)
+ texml = self.get_document().transform(style)
+ return texml
+ except (XMLSyntaxError, XSLTApplyError), e:
+ raise ParseError(e)
+
+ def get_tex_dir(self):
+ texml = self.get_texml()
+ temp = mkdtemp('-wl2pdf')
+ # Save TeX file
+ tex_path = os.path.join(temp, 'doc.tex')
+ with open(tex_path, 'w') as fout:
+ process(StringIO(texml), fout, 'utf-8')
+ if self.save_tex:
+ shutil.copy(tex_path, self.save_tex)
+ # Copy style
+ shutil.copy(get_resource('pdf/wl.cls'), temp)
+ shutil.copy(self.style, os.path.join(temp, 'style.sty'))
+ for sfile in ['wasysym.sty', 'uwasyvar.fd', 'uwasy.fd']:
+ shutil.copy(get_resource(os.path.join('styles/wasysym', sfile)), temp)
+
+ # Save attachments
+ if self.cover:
+ self.cover.for_pdf().dump_to(os.path.join(temp, 'makecover.sty'))
+ return temp
+
+ def get_pdf(self):
+ temp = self.get_tex_dir()
+ tex_path = os.path.join(temp, 'doc.tex')
+ try:
+ cwd = os.getcwd()
+ except OSError:
+ cwd = None
+ os.chdir(temp)
+
+ if self.verbose:
+ for i in range(self.tex_passes):
+ p = call(['xelatex', tex_path])
+ else:
+ for i in range(self.tex_passes):
+ p = call(['xelatex', '-interaction=batchmode', tex_path],
+ stdout=PIPE, stderr=PIPE)
+ if p:
+ raise ParseError("Error parsing .tex file")
+
+ if cwd is not None:
+ os.chdir(cwd)
+
+ output_file = NamedTemporaryFile(prefix='librarian', suffix='.pdf', delete=False)
+ pdf_path = os.path.join(temp, 'doc.pdf')
+ shutil.move(pdf_path, output_file.name)
+ shutil.rmtree(temp)
+ return IOFile.from_filename(output_file.name)
+
+ def build(self, verbose=False, save_tex=None, morefloats=None):
+ """ morefloats: new/old/none
+ """
+ self.verbose = verbose
+ self.save_tex = save_tex