]> mj.ucw.cz Git - paperjam.git/blob - jam.h
b18aa82a4f95f218f23f67479bd2a1e97faa1584
[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 page_out {
41   QPDFObjectHandle resources;
42   QPDFObjectHandle xobjects;
43   string contents;
44   int res_cnt;
45   string new_resource(const string type);
46   page_out() { res_cnt = 0; }
47 };
48
49 struct page {
50   int index;
51   double width;
52   double height;
53   virtual void render(page_out *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
54   page(double _w=0, double _h=0) : width(_w), height(_h) { }
55 };
56
57 struct empty_page : public page {
58   void render(page_out *out UNUSED, pdf_matrix xform UNUSED) { }
59   empty_page(double _w=0, double _h=0) : page(_w, _h) { };
60 };
61
62 struct cmd_exec {
63   virtual vector<page *> process(vector <page *> &pages UNUSED) { abort(); }
64 };
65
66 struct cmd_def {
67   const char *name;
68   const arg_def *arg_defs;
69   bool has_pipeline;
70   cmd_exec *(*constructor)(cmd *cmd);
71 };
72
73 struct cmd {
74   const cmd_def *def;
75   vector<arg_val *> args;
76   pipeline *pipe;
77   cmd_exec *exec;
78 };
79
80 struct pipeline_selector {
81   int from;
82   int to;
83 };
84
85 struct pipeline_branch {
86   vector<pipeline_selector> selectors;
87   list<cmd *> commands;
88 };
89
90 struct pipeline {
91   vector<pipeline_branch *> branches;
92 };
93
94 // paperjam.cc
95
96 vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages);
97
98 // parse.cc
99
100 void parse(const char *in, list<cmd *> &cmds);
101
102 // cmds.cc
103
104 extern const cmd_def cmd_table[];