]> mj.ucw.cz Git - paperjam.git/blob - jam.h
Flip and switch parameters
[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_SWITCH,
22   AT_TYPE_MASK = 0xffff,
23   AT_MANDATORY = 0x10000,
24   AT_POSITIONAL = 0x20000,
25 };
26
27 struct arg_def {
28   const char *name;
29   uint type;
30 };
31
32 class arg_val {
33 public:
34   virtual bool given() { return false; }
35   virtual int as_int(int def) { return def; }
36   virtual double as_double(double def) { return def; }
37   virtual const string as_string(const string def) { return def; }
38   virtual string dump() { return "<undef>"; }
39 };
40
41 struct out_context {
42   QPDFObjectHandle resources;
43   QPDFObjectHandle xobjects;
44   string contents;
45   int res_cnt;
46   string new_resource(const string type);
47   out_context() { res_cnt = 0; }
48 };
49
50 struct page {
51   int index;
52   double width;         // Physical dimensions of media
53   double height;
54   BBox bbox;            // Bounds useful contents
55   virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
56   page(double _w=0, double _h=0) : width(_w), height(_h) { }
57   page(page *p) {
58     index = p->index;
59     width = p->width;
60     height = p->height;
61     bbox = p->bbox;
62   }
63 };
64
65 struct empty_page : public page {
66   void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { }
67   empty_page(double _w=0, double _h=0) : page(_w, _h) { };
68 };
69
70 struct cmd_exec {
71   virtual vector<page *> process(vector <page *> &pages UNUSED) { abort(); }
72 };
73
74 struct cmd_def {
75   const char *name;
76   const arg_def *arg_defs;
77   bool has_pipeline;
78   cmd_exec *(*constructor)(cmd *cmd);
79 };
80
81 struct cmd {
82   const cmd_def *def;
83   vector<arg_val *> args;
84   pipeline *pipe;
85   cmd_exec *exec;
86 };
87
88 struct pipeline_selector {
89   int from;
90   int to;
91 };
92
93 struct pipeline_branch {
94   vector<pipeline_selector> selectors;
95   list<cmd *> commands;
96 };
97
98 struct pipeline {
99   vector<pipeline_branch *> branches;
100 };
101
102 // paperjam.cc
103
104 vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages);
105
106 // parse.cc
107
108 void parse(const char *in, list<cmd *> &cmds);
109 void help();
110
111 // cmds.cc
112
113 extern const cmd_def cmd_table[];
114
115 // gs.cc
116
117 vector<BBox> gs_bboxes(const char *in);