]> mj.ucw.cz Git - paperjam.git/blobdiff - pdf.cc
Allow bare identifiers as values of string arguments
[paperjam.git] / pdf.cc
diff --git a/pdf.cc b/pdf.cc
index f262f5ba6952554dde4444fbd572aaab2d4c547f..8f46d1674c5ecf112583f9955026058c2a008015 100644 (file)
--- a/pdf.cc
+++ b/pdf.cc
@@ -75,7 +75,7 @@ void in_page::render(out_context *out, pdf_matrix xform)
 
 void debug_pages(vector<page *> &pages)
 {
-  if (!debug_mode)
+  if (!debug_level)
     return;
 
   for (auto pg: pages)
@@ -109,8 +109,35 @@ vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages)
   return pages;
 }
 
+static void make_info_dict()
+{
+  // Create info dictionary if it did not exist yet
+  QPDFObjectHandle trailer = out_pdf.getTrailer();
+  QPDFObjectHandle info = trailer.getKey("/Info");
+  if (info.isNull())
+    {
+      info = QPDFObjectHandle::newDictionary();
+      trailer.replaceKey("/Info", info);
+    }
+  else
+    assert(info.isDictionary());
+
+  info.replaceKey("/Producer", unicode_string("PaperJam"));
+
+  // Copy entries from the source file's info dictionary
+  QPDFObjectHandle orig_trailer = in_pdf.getTrailer();
+  QPDFObjectHandle orig_info = orig_trailer.getKey("/Info");
+  if (!orig_info.isNull())
+    {
+      const string to_copy[] = { "/Title", "/Author", "/Subject", "/Keywords", "/Creator", "/CreationDate" };
+      for (string key: to_copy)
+       info.replaceOrRemoveKey(key, orig_info.getKey(key));
+    }
+}
+
 void process(list<cmd *> &cmds)
 {
+  debug("### Reading input");
   in_pdf.processFile(in_name);
   in_pdf.pushInheritedAttributesToPage();
   out_pdf.emptyPDF();
@@ -127,8 +154,10 @@ void process(list<cmd *> &cmds)
   if (recalc_bbox)
     do_recalc_bbox(pages, in_name);
 
+  debug("### Running commands");
   pages = run_command_list(cmds, pages);
 
+  debug("### Writing output");
   for (auto pg: pages)
     {
       out_context out;
@@ -157,21 +186,12 @@ void process(list<cmd *> &cmds)
     }
 
   // Produce info dictionary
-  QPDFObjectHandle trailer = out_pdf.getTrailer();
-  QPDFObjectHandle info = trailer.getKey("/Info");
-  if (info.isNull())
-    {
-      info = QPDFObjectHandle::newDictionary();
-      trailer.replaceKey("/Info", info);
-    }
-  else
-    assert(info.isDictionary());
-  // FIXME: More meta-data
-  info.replaceKey("/Producer", unicode_string("PaperJam"));
+  make_info_dict();
 
   // Write the output file
   QPDFWriter writer(out_pdf, out_name);
   writer.write();
+  debug("### Done");
 }
 
 /*** Re-calculation of bboxes ***/