]> mj.ucw.cz Git - paperjam.git/blobdiff - pdf.cc
Better error messages from instantiating and running of commands
[paperjam.git] / pdf.cc
diff --git a/pdf.cc b/pdf.cc
index cf281f50dcfcb6191e608cce842521bb10bbc7e5..f262f5ba6952554dde4444fbd572aaab2d4c547f 100644 (file)
--- a/pdf.cc
+++ b/pdf.cc
@@ -62,7 +62,7 @@ void in_page::render(out_context *out, pdf_matrix xform)
 {
   // Convert page to xobject
   if (xobject.isNull())
-    xobject = out_pdf.makeIndirectObject( page_to_xobject(&out_pdf, out_pdf.copyForeignObject(pdf_page)) );
+    xobject = out->pdf->makeIndirectObject( page_to_xobject(out->pdf, out->pdf->copyForeignObject(pdf_page)) );
   string xobj_res = out->new_resource("XO");
   out->xobjects.replaceKey(xobj_res, xobject);
 
@@ -94,7 +94,14 @@ vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages)
     {
       debug("# Executing %s", c->def->name);
       debug_indent += 4;
-      pages = c->exec->process(pages);
+      try
+       {
+         pages = c->exec->process(pages);
+       }
+      catch (exception &e)
+       {
+         die("Error in %s: %s", c->def->name, e.what());
+       }
       debug_indent -= 4;
       debug_pages(pages);
     }
@@ -125,10 +132,11 @@ void process(list<cmd *> &cmds)
   for (auto pg: pages)
     {
       out_context out;
+      out.pdf = &out_pdf;
       out.resources = QPDFObjectHandle::newDictionary();
       out.resources.replaceKey("/ProcSet", QPDFObjectHandle::parse("[/PDF]"));
       out.xobjects = QPDFObjectHandle::newDictionary();
-      out.resources.replaceKey("/XObject", out.xobjects);
+      out.egstates = QPDFObjectHandle::newDictionary();
       pg->render(&out, pdf_matrix());
 
       QPDFObjectHandle contents = QPDFObjectHandle::newStream(&out_pdf, out.contents);
@@ -140,6 +148,10 @@ void process(list<cmd *> &cmds)
       // FIXME:
       // out_page.replaceKey("/CropBox", pg->image_box.to_array());
       out_page.replaceKey("/Contents", contents);
+      if (!out.xobjects.getKeys().empty())
+       out.resources.replaceKey("/XObject", out.xobjects);
+      if (!out.egstates.getKeys().empty())
+       out.resources.replaceKey("/ExtGState", out.egstates);
       out_page.replaceKey("/Resources", out.resources);
       out_pdf.addPage(out_page, false);
     }