Commits

Anonymous committed f4f3814

Coverpage support

Comments (0)

Files changed (3)

sphinx/builders/pdf.py

 from sphinx.writers.pdf import PDFWriter
 from sphinx.util.console import darkgreen
 from sphinx.util import SEP
+from sphinx.util import ustrftime
 import rst2pdf.log
 import logging
 from pprint import pprint
     
         for entry in self.document_data:
             docname, targetname, title, author = entry[:4]
-            print docname, targetname, title, author
             docwriter = PDFWriter(self,
                             stylesheets=self.config.pdf_stylesheets,
                             language=self.config.pdf_language,
                             )
             tgt_file = path.join(self.outdir, targetname + self.out_suffix)
             destination = FileOutput(destination_path=tgt_file, encoding='utf-8')
-            doctree = self.assemble_doctree(docname)
+            doctree = self.assemble_doctree(docname,title,author)
             docwriter.write(doctree, destination)
         
     def init_document_data(self):
                 docname = docname[:-5]
             self.titles.append((docname, entry[2]))
 
-    def assemble_doctree(self, indexfile):
-        print indexfile
-        self.docnames = set([indexfile])
-        self.info(darkgreen(indexfile) + " ", nonl=1)
+    def assemble_doctree(self, docname, title, author):
+        self.docnames = set([docname])
+        self.info(darkgreen(docname) + " ", nonl=1)
         def process_tree(docname, tree):
             tree = tree.deepcopy()
             for toctreenode in tree.traverse(addnodes.toctree):
                 toctreenode.parent.replace(toctreenode, newnodes)
             return tree
 
-        tree = self.env.get_doctree(indexfile)
+        tree = self.env.get_doctree(docname)
         
-        tree = process_tree(indexfile, tree)
+        tree = process_tree(docname, tree)
 
         if self.config.language:
             langmod = languages.get_language(self.config.language[:2])
         contTrans.startnode=pending
         contTrans.apply()
 
-        # Generate cover page
+        if self.config.pdf_use_coverpage:
+            # Generate cover page
+            spacer=docutils.core.publish_doctree('.. raw:: pdf\n\n    Spacer 0 3cm\n\n')[0]
+            doctitle=nodes.title()
+            doctitle.append(nodes.Text(title))
+            docsubtitle=nodes.subtitle()
+            docsubtitle.append(nodes.Text('%s %s'%(_('version'),self.config.version)))
+            authornode=nodes.paragraph()
+            authornode.append(nodes.Text(author))
+            authornode['classes']=['author']
+            date=nodes.paragraph()
+            date.append(nodes.Text(ustrftime(self.config.today_fmt or _('%B %d, %Y'))))
+            date['classes']=['author']
+            tree.insert(0,pb)
+            tree.insert(0,date)
+            tree.insert(0,spacer)
+            tree.insert(0,authornode)
+            tree.insert(0,spacer)
+            tree.insert(0,docsubtitle)
+            tree.insert(0,doctitle)
         
         for pendingnode in tree.traverse(addnodes.pending_xref):
             # This needs work, need to keep track of all targets
         pdf_inline_footnotes = (True, None),
         pdf_verbosity = (0,None),
         pdf_use_index = (True, None),
+        pdf_use_coverpage = (True, None),
     )
 
     def __init__(self, dirname, filename, overrides, tags):
 # If false, no index is generated.
 #pdf_use_index = True
 
+# If false, no coverpage is generated.
+#pdf_use_coverpage = True
+
 
 '''