56 bool must_inline =
false;
57 while (fgets(line,
sizeof(line), fp)) {
59 (line,
"%%%%BoundingBox: %d %d %d %d", &lx, &ly, &ux, &uy) == 4) {
62 if (line[0] !=
'%' && strstr(line,
"read")) must_inline =
true;
63 if (saw_bb && must_inline)
break;
74 fstat(fileno(fp), &statbuf);
75 char *contents = us->
data =
gv_calloc((
size_t)statbuf.st_size + 1,
sizeof(
char));
77 size_t rc = fread(contents, (
size_t)statbuf.st_size, 1, fp);
79 contents[statbuf.st_size] =
'\0';
106 const double dx = us->
w;
107 const double dy = us->
h;
139 bool use_stdlib =
true;
143 for (
int i = 0; use_stdlib && (p = arglib[i]); i++) {
149 for (
const char **
s = stdlib; *
s;
s++) {
154 for (
int i = 0; (p = arglib[i]) != 0; i++) {
159 agwarningf(
"can't find library file %s\n", p);
161 else if ((fp =
gv_fopen(safepath,
"r"))) {
163 char bp[BUFSIZ] = {0};
164 size_t r = fread(bp, 1,
sizeof(bp), fp);
166 if (r <
sizeof(bp)) {
173 agwarningf(
"can't open library file %s\n", safepath);
189 if (!strncasecmp(p,
"%%EOF", 5) || !strncasecmp(p,
"%%BEGIN", 7) ||
190 !strncasecmp(p,
"%%END", 5) || !strncasecmp(p,
"%%TRAILER", 9)) {
192 while (*p !=
'\0' && *p !=
'\r' && *p !=
'\n') p++;
193 if (*p ==
'\r' && p[1] ==
'\n') p += 2;
198 while (*p !=
'\0' && *p !=
'\r' && *p !=
'\n') {
202 if (*p ==
'\r' && p[1] ==
'\n') p += 2;
215 gvprintf(job,
"/user_shape_%d {\n", us->macro_id);
216 gvputs(job,
"%%BeginDocument:\n");
218 gvputs(job,
"%%EndDocument\n");
219 gvputs(job,
"} bind def\n");
235 while ((c = *(
unsigned char*)
s++)) {
238 else if ((c & 0xFC) == 0xC0) {
277 agwarningf(
"UTF-8 input uses non-Latin1 characters which cannot be handled by this PostScript driver\n");
static WUR char * agxbuse(agxbuf *xb)
static int agxbputc(agxbuf *xb, char c)
add character to buffer
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
static void * gv_alloc(size_t size)
CDT_API Dtmethod_t * Dtoset
ordered set (self-adjusting tree)
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
const char * safefile(const char *filename)
char * utf8ToLatin1(char *s)
static void ins(Dict_t *d, Dtlink_t **set, Agedge_t *e)
#define PS2INCH(a_points)
char * agget(void *obj, char *name)
void agwarningf(const char *fmt,...)
char * agnameof(void *)
returns a string descriptor for the object.
FILE * gv_fopen(const char *filename, const char *mode)
wrapper around fopen for internal library usage
size_t gvwrite(GVJ_t *job, const char *s, size_t len)
int gvputc(GVJ_t *job, int c)
int gvputs(GVJ_t *job, const char *s)
void gvprintf(GVJ_t *job, const char *format,...)
textitem scanner parser str
static void ps_image_free(void *shape)
void epsf_free(node_t *n)
static Dict_t * EPSF_contents
static Dtdisc_t ImageDictDisc
void epsf_define(GVJ_t *job)
void epsf_init(node_t *n)
static usershape_t * user_init(const char *str)
char * ps_string(char *ins, int chset)
void cat_libfile(GVJ_t *job, const char **arglib, const char **stdlib)
void epsf_emit_body(GVJ_t *job, usershape_t *us)
static int charsetOf(char *s)
platform abstraction for case-insensitive string functions