]> mj.ucw.cz Git - paperjam.git/blobdiff - jam.h
debian/control: debhelper 10 (Stretch) is sufficient
[paperjam.git] / jam.h
diff --git a/jam.h b/jam.h
index 47d80be2e534b5d811958d27c8225fd3d2888e00..ae563337e7ca890a9af239951a694de64dd6404f 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -7,6 +7,7 @@
 #include <vector>
 #include <list>
 #include <unordered_map>
+#include <cmath>
 
 using namespace std;
 
@@ -16,6 +17,23 @@ 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) < 1e-6;
+}
+
+static inline bool is_equal(double x, double y)
+{
+  return is_zero(x-y);
+}
+
+void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
+void warn(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
+void die(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
+
+// This one is called during execution of commands and propagated as an exception
+void err(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
+
 #include "pdf-tools.h"
 
 /*** Representation of commands ***/
@@ -37,6 +55,7 @@ enum arg_type {
 struct arg_def {
   const char *name;
   uint type;
+  const char *help;
 };
 
 class arg_val {
@@ -51,8 +70,10 @@ public:
 extern arg_val null_arg;
 
 struct out_context {
+  QPDF *pdf;
   QPDFObjectHandle resources;
   QPDFObjectHandle xobjects;
+  QPDFObjectHandle egstates;
   string contents;
   int res_cnt;
   string new_resource(const string type);
@@ -60,22 +81,25 @@ struct out_context {
 };
 
 struct page {
-  int index;
+  int index;           // Position in the source PDF, 0 for synthesized pages
   double width;                // Physical dimensions of media
   double height;
-  BBox bbox;           // Bounds useful contents
+  BBox image_box;      // 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;
-  }
+  virtual void debug_dump() = 0;
+  page(double _w=0, double _h=0) : index(0), width(_w), height(_h), image_box() { }
+  page(page *p)
+    {
+      index = p->index;
+      width = p->width;
+      height = p->height;
+      image_box = p->image_box;
+    }
 };
 
 struct empty_page : public page {
   void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { }
+  void debug_dump() { debug("Empty page"); }
   empty_page(double _w=0, double _h=0) : page(_w, _h) { };
 };
 
@@ -88,6 +112,7 @@ struct cmd_def {
   const arg_def *arg_defs;
   bool has_pipeline;
   cmd_exec *(*constructor)(cmd *cmd);
+  const char *help;
 };
 
 struct cmd {
@@ -125,12 +150,15 @@ struct pipeline {
 
 extern const char *in_name, *out_name;
 extern bool recalc_bbox;
-extern int debug_mode;
+extern int debug_level;
 extern int debug_indent;
 
-void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
-void warn(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
-void die(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
+class paperjam_error : public exception {
+  string message;
+public:
+  paperjam_error(string m) : message(m) { }
+  const char *what() const noexcept override { return message.c_str(); }
+};
 
 // parse.cc