56#define PNG_MAGIC "\x89PNG\x0D\x0A\x1A\x0A"
57#define PS_MAGIC "%!PS-Adobe-"
59#define GIF_MAGIC "GIF8"
60#define JPEG_MAGIC "\xFF\xD8\xFF\xE0"
61#define PDF_MAGIC "%PDF-"
62#define EPS_MAGIC "\xC5\xD0\xD3\xC6"
63#define XML_MAGIC "<?xml"
64#define SVG_MAGIC "<svg"
65#define RIFF_MAGIC "RIFF"
66#define WEBP_MAGIC "WEBP"
67#define ICO_MAGIC "\x00\x00\x01\x00"
97 }
else if (c ==
'>') {
104 if (fread(tag, 1,
sizeof(tag), us->
f) !=
sizeof(tag)) {
112 int c = fgetc(us->
f);
116 memmove(&tag[0], &tag[1],
sizeof(tag) - 1);
117 tag[
sizeof(tag) - 1] = (
char)c;
142 for (
size_t i = 0; i < sz; i++) {
146 value |= (unsigned)ch << 8 * i;
148 if (value > INT_MAX) {
159 for (
size_t i = 0; i < sz; i++) {
164 value |= (unsigned)ch;
166 if (value > INT_MAX) {
174 if (strcmp(u,
"in") == 0)
176 if (strcmp(u,
"px") == 0)
178 if (strcmp(u,
"pc") == 0)
180 if (strcmp(u,
"pt") == 0 || strcmp(u,
"\"") == 0)
182 if (strcmp(u,
"cm") == 0)
184 if (strcmp(u,
"mm") == 0)
197 for (
size_t i = 0;
s[i] !=
'\0'; ) {
198 if (
s[i] >=
'a' &&
s[i] <=
'z') {
202 while ((
s[i] >=
'a' &&
s[i] <=
'z') || (
s[i] >=
'A' &&
s[i] <=
'Z')) {
206 if (
s[i] ==
'=' &&
s[i + 1] ==
'"') {
210 while (
s[i] !=
'"' &&
s[i] !=
'\0') {
231 double n, x0, y0, x1, y1;
235 bool wFlag =
false, hFlag =
false;
237 fseek(us->
f, 0, SEEK_SET);
238 while (!eof && (!wFlag || !hFlag)) {
241 int c = fgetc(us->
f);
245 }
else if (c ==
'\n') {
251 const char *re_string =
agxbuse(&line);
258 if (sscanf(value,
"%lf%2s", &n, u) == 2) {
262 else if (sscanf(value,
"%lf", &n) == 1) {
272 if (sscanf(value,
"%lf%2s", &n, u) == 2) {
276 else if (sscanf(value,
"%lf", &n) == 1) {
286 if (sscanf(value,
"%lf %lf %lf %lf", &x0, &y0, &x1, &y1) == 4) {
299 assert(w >= 0 && w <= INT_MAX);
301 assert(h >= 0 && h <= INT_MAX);
311 fseek(us->
f, 16, SEEK_SET);
323 fseek(us->
f, 6, SEEK_SET);
335 fseek(us->
f, 15, SEEK_SET);
336 if (fgetc(us->
f) ==
'X') {
337 fseek(us->
f, 24, SEEK_SET);
344 fseek(us->
f, 26, SEEK_SET);
357 fseek(us->
f, 6, SEEK_SET);
365 int size_x_msw, size_x_lsw, size_y_msw, size_y_lsw;
368 fseek (us->
f, 16, SEEK_SET);
373 us->
w = size_x_msw << 16 | size_x_lsw;
374 us->
h = size_y_msw << 16 | size_y_lsw;
379 int marker, length, size_x, size_y;
384 static const unsigned char standalone_markers[] = {
386 0xd0, 0xd1, 0xd2, 0xd3,
412 if (memchr(standalone_markers, marker,
sizeof(standalone_markers)))
416 if (marker == 0xc0) {
418 if (fseek(us->
f, 3, SEEK_CUR) == 0 &&
430 if (marker == 0xc2) {
432 if (fseek(us->
f, 3, SEEK_CUR) != 0)
448 fseek (us->
f, length - 2, SEEK_CUR);
459 fseek(us->
f, 0, SEEK_SET);
461 while (fgets(line,
sizeof(line), us->
f)) {
470 if (!(linep = strstr (line,
"%%BoundingBox:")))
472 if (sscanf (linep,
"%%%%BoundingBox: %d %d %d %d", &lx, &ly, &ux, &uy) == 4) {
485#define KEY "/MediaBox"
502#define strc(x) (*(x->s)?*(x->s):nxtc(x))
503#define stradv(x) (x->s++)
519 double d = strtod(
tok, &endp);
521 if (
tok == endp)
return 1;
535 if (
len == BUFSIZ-1)
break;
548 if (
strc(
str) !=
'[')
return 1;
567 while (fgets(buf, BUFSIZ, fp)) {
568 if ((
s = strstr(buf,
KEY))) {
583 fseek(us->
f, 0, SEEK_SET);
622#define MAX_USERSHAPE_FILES_OPEN 50
625 static int usershape_files_open_cnt;
633 fseek(us->
f, 0, SEEK_SET);
639 us->
f = fopen(fn,
"rb");
641 agwarningf(
"%s while opening %s\n", strerror(errno), fn);
647 usershape_files_open_cnt++;
692 agwarningf(
"\"%s\" was not found as a file or as a shape library member\n", us->
name);
749 dpi.
x = dpi.
y = us->
dpi;
765 static char* oldpath;
769 if (!name || (*name ==
'\0')) {
785 dpi.
x = dpi.
y = (double)DEFAULT_DPI;
size_t match(char *str, char *pat)
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbputc(agxbuf *xb, char c)
add character to buffer
static char * agxbuse(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
CDT_API Dtmethod_t * Dttree
CDT_API int dtclose(Dt_t *)
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
const char * safefile(const char *filename)
static double len(glCompPoint p)
void agwarningf(const char *fmt,...)
int agstrfree(Agraph_t *, const char *)
char * agstrdup(Agraph_t *, const char *)
returns a pointer to a reference-counted copy of the argument string, creating one if necessary
bool gvusershape_file_access(usershape_t *us)
replacements for ctype.h functions
static bool gv_isdigit(int c)
static bool gv_isspace(int c)
static void ico_size(usershape_t *us)
static void freeUsershape(usershape_t *us)
static char nxtc(stream_t *str)
#define MAX_USERSHAPE_FILES_OPEN
static bool get_int_msb_first(FILE *f, size_t sz, int *val)
shape_desc * find_user_shape(const char *)
static bool get_int_lsb_first(FILE *f, size_t sz, int *val)
static void skipWS(stream_t *str)
static Dtdisc_t ImageDictDisc
static int find_attribute(const char *s, match_t *result)
static void webp_size(usershape_t *us)
usershape_t * gvusershape_find(const char *name)
void gvusershape_file_release(usershape_t *us)
point gvusershape_size(graph_t *g, char *name)
point gvusershape_size_dpi(usershape_t *us, pointf dpi)
static int boxof(stream_t *str, boxf *bp)
static void jpeg_size(usershape_t *us)
static usershape_t * gvusershape_open(const char *name)
static int bboxPDF(FILE *fp, boxf *bp)
static knowntype_t knowntypes[]
static void png_size(usershape_t *us)
static void gif_size(usershape_t *us)
static imagetype_t imagetype(usershape_t *us)
static int scanNum(char *tok, double *dp)
static Dict_t * ImageDict
static double svg_units_convert(double n, char *u)
static void pdf_size(usershape_t *us)
static void ps_size(usershape_t *us)
static void svg_size(usershape_t *us)
static void bmp_size(usershape_t *us)
static void getNum(stream_t *str, char *buf)
static void usershape_close(void *p)
char * buf
start of buffer
struct agxbuf::@59::@60 s
a non-owning string reference
const char * data
start of the pointed to string
size_t size
extent of the string in bytes
void(* datafree)(usershape_t *us)
Non-owning string references.
static bool strview_str_eq(strview_t a, const char *b)
compare a string reference to a string for equality
static char * strview_str(strview_t source)
make a heap-allocated string from this string view
static tok_t tok(const char *input, const char *separators)
begin tokenization of a new string
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t