2 * PaperJam -- Common declarations
4 * (c) 2018 Martin Mares <mj@ucw.cz>
9 #include <unordered_map>
13 typedef unsigned int uint;
15 #define NONRET __attribute__((noreturn))
16 #define UNUSED __attribute__((unused))
17 #define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z)))
19 #include "pdf-tools.h"
21 /*** Representation of commands ***/
32 AT_TYPE_MASK = 0xffff,
33 AT_MANDATORY = 0x10000,
34 AT_POSITIONAL = 0x20000,
44 virtual bool given() { return false; }
45 virtual int as_int(int def) { return def; }
46 virtual double as_double(double def) { return def; }
47 virtual const string as_string(const string def) { return def; }
48 virtual string dump() { return "<undef>"; }
51 extern arg_val null_arg;
54 QPDFObjectHandle resources;
55 QPDFObjectHandle xobjects;
58 string new_resource(const string type);
59 out_context() { res_cnt = 0; }
64 double width; // Physical dimensions of media
66 BBox bbox; // Bounds useful contents
67 virtual void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { abort(); }
68 page(double _w=0, double _h=0) : width(_w), height(_h) { }
77 struct empty_page : public page {
78 void render(out_context *out UNUSED, pdf_matrix xform UNUSED) { }
79 empty_page(double _w=0, double _h=0) : page(_w, _h) { };
83 virtual vector<page *> process(vector <page *> &pages UNUSED) = 0;
88 const arg_def *arg_defs;
90 cmd_exec *(*constructor)(cmd *cmd);
95 unordered_map<string, arg_val *> args;
98 arg_val *arg(const string name)
100 auto it = args.find(name);
101 if (it != args.end())
108 struct pipeline_selector {
113 struct pipeline_branch {
114 vector<pipeline_selector> selectors;
115 list<cmd *> commands;
119 vector<pipeline_branch *> branches;
126 extern const char *in_name, *out_name;
127 extern bool recalc_bbox;
128 extern int debug_mode;
129 extern int debug_indent;
131 void debug(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
132 void warn(const char *msg, ...) FORMAT_CHECK(printf, 1, 2);
133 void die(const char *msg, ...) FORMAT_CHECK(printf, 1, 2) NONRET;
137 void parse(const char *in, list<cmd *> &cmds);
142 extern const cmd_def cmd_table[];
146 void debug_pages(vector<page *> &pages);
147 void process(list<cmd *> &cmds);
148 vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages);
149 vector<BBox> gs_bboxes(const char *in);