]> mj.ucw.cz Git - paperjam.git/blobdiff - jam.h
Measure bboxes by Ghostscripting
[paperjam.git] / jam.h
diff --git a/jam.h b/jam.h
index f5d2ca1d5e5a9c122cf86b44bd734dd593ddc280..a966cea36d72bce230f9b775284f190ef8ef05eb 100644 (file)
--- a/jam.h
+++ b/jam.h
@@ -15,6 +15,7 @@ struct cmd;
 
 enum arg_type {
   AT_STRING,
+  AT_INT,
   AT_DOUBLE,
   AT_DIMEN,
   AT_TYPE_MASK = 0xffff,
@@ -30,25 +31,43 @@ struct arg_def {
 class arg_val {
 public:
   virtual bool given() { return false; }
-  explicit virtual operator double() { abort(); }
-  explicit virtual operator string() { abort(); }
-  double double_default(double def) { return given() ? (double) *this : def; }
-  const string string_default(const string def) { return given() ? (string) *this : def; }
+  virtual int as_int(int def) { return def; }
+  virtual double as_double(double def) { return def; }
+  virtual const string as_string(const string def) { return def; }
   virtual string dump() { return "<undef>"; }
 };
 
-struct page_out {
+struct out_context {
+  QPDFObjectHandle resources;
+  QPDFObjectHandle xobjects;
+  string contents;
+  int res_cnt;
+  string new_resource(const string type);
+  out_context() { res_cnt = 0; }
 };
 
 struct page {
-  double width;
+  int index;
+  double width;                // Physical dimensions of media
   double height;
-  virtual void render(page_out *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
-  page(double _w, double _h) : width(_w), height(_h) { }
+  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;
+  }
+};
+
+struct empty_page : public page {
+  void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { }
+  empty_page(double _w=0, double _h=0) : page(_w, _h) { };
 };
 
 struct cmd_exec {
-  virtual vector<page *> process(vector <page *> pages UNUSED) { abort(); }
+  virtual vector<page *> process(vector <page *> &pages UNUSED) { abort(); }
 };
 
 struct cmd_def {
@@ -79,10 +98,19 @@ struct pipeline {
   vector<pipeline_branch *> branches;
 };
 
+// paperjam.cc
+
+vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages);
+
 // parse.cc
 
-void parse(const char *in, list<cmd *> *cmds);
+void parse(const char *in, list<cmd *> &cmds);
+void help();
 
 // cmds.cc
 
 extern const cmd_def cmd_table[];
+
+// gs.cc
+
+vector<BBox> gs_bboxes(const char *in);