- # Parse XSLT
- try:
- if file_path:
- if slug:
- raise ValueError('slug or file_path should be specified, not both')
- document = load_including_children(provider, file_path=file_path)
- else:
- if not slug:
- raise ValueError('either slug or file_path should be specified')
- document = load_including_children(provider, slug=slug)
-
- if cover:
- document.edoc.getroot().set('data-cover-width', str(cover.width))
- document.edoc.getroot().set('data-cover-height', str(cover.height))
- if flags:
- for flag in flags:
- document.edoc.getroot().set('flag-' + flag, 'yes')
-
- # check for LaTeX packages
- if morefloats:
- document.edoc.getroot().set('morefloats', morefloats.lower())
- elif package_available('morefloats', 'maxfloats=19'):
- document.edoc.getroot().set('morefloats', 'new')
+ if uri and provider:
+ f = provider.by_uri(uri)
+ text = f.read().decode('utf-8')
+ f.close()
+ elif wldoc is not None:
+ text = etree.tostring(wldoc.edoc, encoding=unicode)
+ provider = wldoc.provider
+ else:
+ raise ValueError('Neither a WLDocument, nor provider and URI were provided.')
+
+ text = re.sub(ur"([\u0400-\u04ff]+)", ur"<alien>\1</alien>", text)
+
+ document = WLDocument.from_string(text,
+ parse_dublincore=True, provider=provider)
+ document.swap_endlines()
+
+ for child_uri in document.book_info.parts:
+ child = load_including_children(provider=provider, uri=child_uri)
+ document.edoc.getroot().append(child.edoc.getroot())
+ return document
+
+
+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())))