]> mj.ucw.cz Git - paperjam.git/blobdiff - jam.h
Implemented add-blank
[paperjam.git] / jam.h
diff --git a/jam.h b/jam.h
index ca5dd9c0472f9a7e29dc91e0431eaeb826531682..31510d8c2b5f3469d3e6ab831919df33b92d231a 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -6,6 +6,8 @@
 
 #include <vector>
 #include <list>
+#include <unordered_map>
+#include <cmath>
 
 using namespace std;
 
@@ -15,6 +17,16 @@ typedef unsigned int uint;
 #define UNUSED __attribute__((unused))
 #define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z)))
 
+static inline bool is_zero(double z)
+{
+  return fabs(z) < 0.001;
+}
+
+static inline bool is_equal(double x, double y)
+{
+  return is_zero(x-y);
+}
+
 #include "pdf-tools.h"
 
 /*** Representation of commands ***/
@@ -47,6 +59,8 @@ public:
   virtual string dump() { return "<undef>"; }
 };
 
+extern arg_val null_arg;
+
 struct out_context {
   QPDFObjectHandle resources;
   QPDFObjectHandle xobjects;
@@ -62,13 +76,14 @@ struct page {
   double height;
   BBox bbox;           // Bounds useful contents
   virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
-  page(double _w=0, double _h=0) : width(_w), height(_h) { }
-  page(page *p) {
-    index = p->index;
-    width = p->width;
-    height = p->height;
-    bbox = p->bbox;
-  }
+  page(double _w=0, double _h=0) : index(0), width(_w), height(_h), bbox() { }
+  page(page *p)
+    {
+      index = p->index;
+      width = p->width;
+      height = p->height;
+      bbox = p->bbox;
+    }
 };
 
 struct empty_page : public page {
@@ -89,9 +104,17 @@ struct cmd_def {
 
 struct cmd {
   const cmd_def *def;
-  vector<arg_val *> args;
+  unordered_map<string, arg_val *> args;
   pipeline *pipe;
   cmd_exec *exec;
+  arg_val *arg(const string name)
+    {
+      auto it = args.find(name);
+      if (it != args.end())
+       return it->second;
+      else
+       return &null_arg;
+    }
 };
 
 struct pipeline_selector {