2 * PaperJam -- Common declarations
4 * (c) 2018 Martin Mares <mj@ucw.cz>
9 #include <unordered_map>
14 typedef unsigned int uint;
16 #define NONRET __attribute__((noreturn))
17 #define UNUSED __attribute__((unused))
18 #define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z)))
20 static inline bool is_zero(double z)
22 return fabs(z) < 0.001;
25 static inline bool is_equal(double x, double y)
30 #include "pdf-tools.h"
32 /*** Representation of commands ***/
43 AT_TYPE_MASK = 0xffff,
44 AT_MANDATORY = 0x10000,
45 AT_POSITIONAL = 0x20000,
55 virtual bool given() { return false; }
56 virtual int as_int(int def) { return def; }
57 virtual double as_double(double def) { return def; }
58 virtual const string as_string(const string def) { return def; }
59 virtual string dump() { return "<undef>"; }
62 extern arg_val null_arg;
65 QPDFObjectHandle resources;
66 QPDFObjectHandle xobjects;
69 string new_resource(const string type);
70 out_context() { res_cnt = 0; }
75 double width; // Physical dimensions of media
77 BBox bbox; // Bounds useful contents
78 virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
79 page(double _w=0, double _h=0) : index(0), width(_w), height(_h), bbox() { }
89 struct empty_page : public page {
90 void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { }
91 empty_page(double _w=0, double _h=0) : page(_w, _h) { };
95 virtual vector<page *> process(vector <page *> &pages UNUSED) = 0;
100 const arg_def *arg_defs;
102 cmd_exec *(*constructor)(cmd *cmd);
107 unordered_map<string, arg_val *> args;
110 arg_val *arg(const string name)
112 auto it = args.find(name);
113 if (it != args.end())
120 struct pipeline_selector {
125 struct pipeline_branch {
126 vector<pipeline_selector> selectors;
127 list<cmd *> commands;
131 vector<pipeline_branch *> branches;
138 extern const char *in_name, *out_name;
139 extern bool recalc_bbox;
140 extern int debug_mode;
141 extern int debug_indent;
143 void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
144 void warn(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
145 void die(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
149 void parse(const char *in, list<cmd *> &cmds);
154 extern const cmd_def cmd_table[];
158 void debug_pages(vector<page *> &pages);
159 void process(list<cmd *> &cmds);
160 vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages);
161 vector<BBox> gs_bboxes(const char *in);