]> mj.ucw.cz Git - paperjam.git/blob - jam.h
Remember bounding boxes of page contents
[paperjam.git] / jam.h
1 #include <vector>
2 #include <list>
3
4 using namespace std;
5
6 #include "pdf-tools.h"
7
8 typedef unsigned int uint;
9
10 #define NONRET __attribute__((noreturn))
11 #define UNUSED __attribute__((unused))
12
13 struct pipeline;
14 struct cmd;
15
16 enum arg_type {
17   AT_STRING,
18   AT_INT,
19   AT_DOUBLE,
20   AT_DIMEN,
21   AT_TYPE_MASK = 0xffff,
22   AT_MANDATORY = 0x10000,
23   AT_POSITIONAL = 0x20000,
24 };
25
26 struct arg_def {
27   const char *name;
28   uint type;
29 };
30
31 class arg_val {
32 public:
33   virtual bool given() { return false; }
34   virtual int as_int(int def) { return def; }
35   virtual double as_double(double def) { return def; }
36   virtual const string as_string(const string def) { return def; }
37   virtual string dump() { return "<undef>"; }
38 };
39
40 struct out_context {
41   QPDFObjectHandle resources;
42   QPDFObjectHandle xobjects;
43   string contents;
44   int res_cnt;
45   string new_resource(const string type);
46   out_context() { res_cnt = 0; }
47 };
48
49 struct page {
50   int index;
51   double width;         // Physical dimensions of media
52   double height;
53   BBox bbox;            // Bounds useful contents
54   virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
55   page(double _w=0, double _h=0) : width(_w), height(_h) { }
56   page(page *p) {
57     index = p->index;
58     width = p->width;
59     height = p->height;
60     bbox = p->bbox;
61   }
62 };
63
64 struct empty_page : public page {
65   void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { }
66   empty_page(double _w=0, double _h=0) : page(_w, _h) { };
67 };
68
69 struct cmd_exec {
70   virtual vector<page *> process(vector <page *> &pages UNUSED) { abort(); }
71 };
72
73 struct cmd_def {
74   const char *name;
75   const arg_def *arg_defs;
76   bool has_pipeline;
77   cmd_exec *(*constructor)(cmd *cmd);
78 };
79
80 struct cmd {
81   const cmd_def *def;
82   vector<arg_val *> args;
83   pipeline *pipe;
84   cmd_exec *exec;
85 };
86
87 struct pipeline_selector {
88   int from;
89   int to;
90 };
91
92 struct pipeline_branch {
93   vector<pipeline_selector> selectors;
94   list<cmd *> commands;
95 };
96
97 struct pipeline {
98   vector<pipeline_branch *> branches;
99 };
100
101 // paperjam.cc
102
103 vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages);
104
105 // parse.cc
106
107 void parse(const char *in, list<cmd *> &cmds);
108
109 // cmds.cc
110
111 extern const cmd_def cmd_table[];