Graphviz 16.1.1~dev.20260906.1627
Loading...
Searching...
No Matches
gvusershape.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v2.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "config.h"
12#include <assert.h>
13#include <common/globals.h>
14#include <common/render.h>
15#include <common/types.h>
16#include <common/usershape.h>
17#include <common/utils.h>
18#include <errno.h>
19#include <gvc/gvcint.h>
20#include <gvc/gvcproc.h>
21#include <gvc/gvplugin.h>
23#include <limits.h>
24#include <math.h>
25#include <stdbool.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <util/agxbuf.h>
30#include <util/alloc.h>
31#include <util/gv_ctype.h>
32#include <util/gv_fopen.h>
33#include <util/optional.h>
34#include <util/streq.h>
35#include <util/strview.h>
36
38
39typedef struct {
40 char *template;
41 size_t size;
45
46#define HDRLEN 20
47
48#define PNG_MAGIC "\x89PNG\x0D\x0A\x1A\x0A"
49#define PS_MAGIC "%!PS-Adobe-"
50#define BMP_MAGIC "BM"
51#define GIF_MAGIC "GIF8"
52#define JPEG_MAGIC "\xFF\xD8\xFF"
53#define PDF_MAGIC "%PDF-"
54#define EPS_MAGIC "\xC5\xD0\xD3\xC6"
55#define XML_MAGIC "<?xml"
56#define SVG_MAGIC "<svg"
57#define RIFF_MAGIC "RIFF"
58#define WEBP_MAGIC "WEBP"
59#define ICO_MAGIC "\x00\x00\x01\x00"
60
62 {
64 sizeof(PNG_MAGIC) - 1,
65 FT_PNG,
66 "png",
67 },
68 {
70 sizeof(PS_MAGIC) - 1,
71 FT_PS,
72 "ps",
73 },
74 {
76 sizeof(BMP_MAGIC) - 1,
77 FT_BMP,
78 "bmp",
79 },
80 {
82 sizeof(GIF_MAGIC) - 1,
83 FT_GIF,
84 "gif",
85 },
86 {
88 sizeof(JPEG_MAGIC) - 1,
89 FT_JPEG,
90 "jpeg",
91 },
92 {
94 sizeof(PDF_MAGIC) - 1,
95 FT_PDF,
96 "pdf",
97 },
98 {
100 sizeof(EPS_MAGIC) - 1,
101 FT_EPS,
102 "eps",
103 },
104 {
105 XML_MAGIC,
106 sizeof(XML_MAGIC) - 1,
107 FT_XML,
108 "xml",
109 },
110 {
112 sizeof(RIFF_MAGIC) - 1,
113 FT_RIFF,
114 "riff",
115 },
116 {
117 ICO_MAGIC,
118 sizeof(ICO_MAGIC) - 1,
119 FT_ICO,
120 "ico",
121 },
122};
123
125 char header[HDRLEN] = {0};
126
127 if (us->f && fread(header, 1, HDRLEN, us->f) == HDRLEN) {
128 for (size_t i = 0; i < sizeof(knowntypes) / sizeof(knowntype_t); i++) {
129 if (!memcmp(header, knowntypes[i].template, knowntypes[i].size)) {
131 us->type = knowntypes[i].type;
132 if (us->type == FT_XML) {
133 // if we did not see the closing of the XML declaration, scan for it
134 if (memchr(header, '>', HDRLEN) == NULL) {
135 while (true) {
136 int c = fgetc(us->f);
137 if (c == EOF) {
138 return us->type;
139 } else if (c == '>') {
140 break;
141 }
142 }
143 }
144 /* check for SVG in case of XML */
145 char tag[sizeof(SVG_MAGIC) - 1] = {0};
146 if (fread(tag, 1, sizeof(tag), us->f) != sizeof(tag)) {
147 return us->type;
148 }
149 while (true) {
150 if (memcmp(tag, SVG_MAGIC, sizeof(SVG_MAGIC) - 1) == 0) {
151 us->stringtype = "svg";
152 return (us->type = FT_SVG);
153 }
154 int c = fgetc(us->f);
155 if (c == EOF) {
156 return us->type;
157 }
158 memmove(&tag[0], &tag[1], sizeof(tag) - 1);
159 tag[sizeof(tag) - 1] = (char)c;
160 }
161 } else if (us->type == FT_RIFF) {
162 /* check for WEBP in case of RIFF */
163 if (!memcmp(header + 8, WEBP_MAGIC, sizeof(WEBP_MAGIC) - 1)) {
164 us->stringtype = "webp";
165 return (us->type = FT_WEBP);
166 }
167 }
168 return us->type;
169 }
170 }
171 }
172
173 us->stringtype = "(lib)";
174 us->type = FT_NULL;
175
176 return FT_NULL;
177}
178
179static bool get_int_lsb_first(FILE *f, size_t sz, int *val) {
180 unsigned value = 0;
181 for (size_t i = 0; i < sz; i++) {
182 const int ch = fgetc(f);
183 if (feof(f))
184 return false;
185 value |= (unsigned)ch << 8 * i;
186 }
187 if (value > INT_MAX) {
188 return false;
189 }
190 *val = (int)value;
191 return true;
192}
193
194static bool get_int_msb_first(FILE *f, size_t sz, int *val) {
195 unsigned value = 0;
196 for (size_t i = 0; i < sz; i++) {
197 const int ch = fgetc(f);
198 if (feof(f))
199 return false;
200 value <<= 8;
201 value |= (unsigned)ch;
202 }
203 if (value > INT_MAX) {
204 return false;
205 }
206 *val = (int)value;
207 return true;
208}
209
210static double svg_units_convert(double n, char *u) {
211 if (streq(u, "in"))
212 return round(n * POINTS_PER_INCH);
213 if (streq(u, "px"))
214 return round(n * POINTS_PER_INCH / 96);
215 if (streq(u, "pc"))
216 return round(n * POINTS_PER_INCH / 6);
217 if (streq(u, "pt") || streq(u, "\"")) /* ugly!! - if there are no inits then
218 the %2s get the trailing '"' */
219 return round(n);
220 if (streq(u, "cm"))
221 return round(n * POINTS_PER_CM);
222 if (streq(u, "mm"))
223 return round(n * POINTS_PER_MM);
224 return 0;
225}
226
227typedef struct {
230} match_t;
231
232static int find_attribute(const char *s, match_t *result) {
233
234 // look for an attribute string matching ([a-z][a-zA-Z]*)="([^"]*)"
235 for (size_t i = 0; s[i] != '\0';) {
236 if (gv_islower(s[i])) {
237 result->key.data = &s[i];
238 result->key.size = 1;
239 ++i;
240 while (gv_isalpha(s[i])) {
241 ++i;
242 ++result->key.size;
243 }
244 if (s[i] == '=' && s[i + 1] == '"') {
245 i += 2;
246 result->value.data = &s[i];
247 result->value.size = 0;
248 while (s[i] != '"' && s[i] != '\0') {
249 ++i;
250 ++result->value.size;
251 }
252 if (s[i] == '"') {
253 // found a valid attribute
254 return 0;
255 }
256 }
257 } else {
258 ++i;
259 }
260 }
261
262 // no attribute found
263 return -1;
264}
265
266static void svg_size(usershape_t *us) {
267 double n;
268 char u[3];
269 agxbuf line = {0};
270 bool eof = false;
271
272 // authoritative constraints we learned from `height` and `width`
273 OPTIONAL(double) hard_height = {0};
274 OPTIONAL(double) hard_width = {0};
275
276 // fallback constraints we learned from `viewBox`
277 OPTIONAL(double) soft_height = {0};
278 OPTIONAL(double) soft_width = {0};
279
280 if (fseek(us->f, 0, SEEK_SET) < 0) {
281 us->w = 0;
282 us->h = 0;
283 return;
284 }
285
286 while (!eof && (!hard_width.has_value || !hard_height.has_value)) {
287 // read next line
288 while (true) {
289 int c = fgetc(us->f);
290 if (c == EOF) {
291 eof = true;
292 break;
293 } else if (c == '\n') {
294 break;
295 }
296 agxbputc(&line, (char)c);
297 }
298
299 const char *re_string = agxbuse(&line);
301 while (find_attribute(re_string, &match) == 0) {
302 re_string = match.value.data + match.value.size + 1;
303
304 if (strview_str_eq(match.key, "width")) {
305 char *value = strview_str(match.value);
306 if (sscanf(value, "%lf%2s", &n, u) == 2) {
307 OPTIONAL_SET(&hard_width, svg_units_convert(n, u));
308 } else if (sscanf(value, "%lf", &n) == 1) {
309 OPTIONAL_SET(&hard_width, svg_units_convert(n, "pt"));
310 }
311 free(value);
312 if (hard_height.has_value)
313 break;
314 } else if (strview_str_eq(match.key, "height")) {
315 char *value = strview_str(match.value);
316 if (sscanf(value, "%lf%2s", &n, u) == 2) {
317 OPTIONAL_SET(&hard_height, svg_units_convert(n, u));
318 } else if (sscanf(value, "%lf", &n) == 1) {
319 OPTIONAL_SET(&hard_height, svg_units_convert(n, "pt"));
320 }
321 free(value);
322 if (hard_width.has_value)
323 break;
324 } else if (strview_str_eq(match.key, "viewBox")) {
325 char *value = strview_str(match.value);
326 double w, h;
327 if (sscanf(value, "%*f %*f %lf %lf", &w, &h) == 2) {
328 OPTIONAL_SET(&soft_width, w);
329 OPTIONAL_SET(&soft_height, h);
330 }
331 free(value);
332 }
333 }
334
335 // if we have reached the end of a line and have seen `viewBox` but not
336 // `height` and/or `width`, let `viewBox` determine the dimensions
337 if (soft_height.has_value && soft_width.has_value) {
338 if (!hard_height.has_value) {
339 OPTIONAL_SET(&hard_height, OPTIONAL_VALUE(soft_height));
340 }
341 if (!hard_width.has_value) {
342 OPTIONAL_SET(&hard_width, OPTIONAL_VALUE(soft_width));
343 }
344 break;
345 }
346 }
347 us->dpi = 0;
348 const double h = OPTIONAL_VALUE_OR(hard_height, 0);
349 const double w = OPTIONAL_VALUE_OR(hard_width, 0);
350 assert(w >= 0 && w <= INT_MAX);
351 us->w = (int)w;
352 assert(h >= 0 && h <= INT_MAX);
353 us->h = (int)h;
354 agxbfree(&line);
355}
356
357static void png_size(usershape_t *us) {
358 int w, h;
359
360 us->dpi = 0;
361 fseek(us->f, 16, SEEK_SET);
362 if (get_int_msb_first(us->f, 4, &w) && get_int_msb_first(us->f, 4, &h)) {
363 us->w = w;
364 us->h = h;
365 }
366}
367
368static void ico_size(usershape_t *us) {
369 int w, h;
370
371 us->dpi = 0;
372 fseek(us->f, 6, SEEK_SET);
373 if (get_int_msb_first(us->f, 1, &w) && get_int_msb_first(us->f, 1, &h)) {
374 us->w = w;
375 us->h = h;
376 }
377}
378
379static void webp_size(usershape_t *us) {
380 int w, h;
381
382 us->dpi = 0;
383 fseek(us->f, 15, SEEK_SET);
384 if (fgetc(us->f) == 'X') { // VP8X
385 fseek(us->f, 24, SEEK_SET);
386 if (get_int_lsb_first(us->f, 4, &w) && get_int_lsb_first(us->f, 4, &h)) {
387 us->w = w;
388 us->h = h;
389 }
390 } else { // VP8
391 fseek(us->f, 26, SEEK_SET);
392 if (get_int_lsb_first(us->f, 2, &w) && get_int_lsb_first(us->f, 2, &h)) {
393 us->w = w;
394 us->h = h;
395 }
396 }
397}
398
399static void gif_size(usershape_t *us) {
400 int w, h;
401
402 us->dpi = 0;
403 fseek(us->f, 6, SEEK_SET);
404 if (get_int_lsb_first(us->f, 2, &w) && get_int_lsb_first(us->f, 2, &h)) {
405 us->w = w;
406 us->h = h;
407 }
408}
409
410static void bmp_size(usershape_t *us) {
411 int size_x_msw, size_x_lsw, size_y_msw, size_y_lsw;
412
413 us->dpi = 0;
414 fseek(us->f, 16, SEEK_SET);
415 if (get_int_lsb_first(us->f, 2, &size_x_msw) &&
416 get_int_lsb_first(us->f, 2, &size_x_lsw) &&
417 get_int_lsb_first(us->f, 2, &size_y_msw) &&
418 get_int_lsb_first(us->f, 2, &size_y_lsw)) {
419 us->w = size_x_msw << 16 | size_x_lsw;
420 us->h = size_y_msw << 16 | size_y_lsw;
421 }
422}
423
424static void jpeg_size(usershape_t *us) {
425 int marker, length, size_x, size_y;
426
427 /* These are the markers that follow 0xff in the file.
428 * Other markers implicitly have a 2-byte length field that follows.
429 */
430 static const unsigned char standalone_markers[] = {
431 0x01, /* Temporary */
432 0xd0, 0xd1, 0xd2, 0xd3, /* Reset */
433 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, /* Start of image */
434 0xd9, /* End of image */
435 };
436
437 us->dpi = 0;
438 if (fseek(us->f, 0, SEEK_SET) < 0) {
439 return;
440 }
441
442 while (true) {
443 /* Now we must be at a 0xff or at a series of 0xff's.
444 * If that is not the case, or if we're at EOF, then there's
445 * a parsing error.
446 */
447 if (!get_int_msb_first(us->f, 1, &marker)) {
448 agwarningf("Parsing of \"%s\" failed\n", us->name);
449 return;
450 }
451
452 if (marker == 0xff)
453 continue;
454
455 /* Ok.. marker now read. If it is not a stand-alone marker,
456 * then continue. If it's a Start Of Frame (0xc?), then we're there.
457 * If it's another marker with a length field, then skip ahead
458 * over that length field.
459 */
460
461 /* A stand-alone... */
462 if (memchr(standalone_markers, marker, sizeof(standalone_markers)))
463 continue;
464
465 /* Incase of a 0xc0 marker: */
466 if (marker == 0xc0) {
467 /* Skip length and 2 lengths. */
468 if (fseek(us->f, 3, SEEK_CUR) == 0 &&
469 get_int_msb_first(us->f, 2, &size_y) &&
470 get_int_msb_first(us->f, 2, &size_x)) {
471
472 /* Store length. */
473 us->h = size_y;
474 us->w = size_x;
475 }
476 return;
477 }
478
479 /* Incase of a 0xc2 marker: */
480 if (marker == 0xc2) {
481 /* Skip length and one more byte */
482 if (fseek(us->f, 3, SEEK_CUR) != 0)
483 return;
484
485 /* Get length and store. */
486 if (get_int_msb_first(us->f, 2, &size_y) &&
487 get_int_msb_first(us->f, 2, &size_x)) {
488 us->h = size_y;
489 us->w = size_x;
490 }
491 return;
492 }
493
494 /* Any other marker is assumed to be followed by 2 bytes length. */
495 if (!get_int_msb_first(us->f, 2, &length))
496 return;
497
498 fseek(us->f, length - 2, SEEK_CUR);
499 }
500}
501
502static void ps_size(usershape_t *us) {
503 char line[BUFSIZ];
504 int lx, ly, ux, uy;
505 char *linep;
506
507 us->dpi = 72;
508 if (fseek(us->f, 0, SEEK_SET) < 0) {
509 return;
510 }
511 bool saw_bb = false;
512 while (fgets(line, sizeof(line), us->f)) {
513 /* PostScript accepts \r as EOL, so using fgets () and looking for a
514 * bounding box comment at the beginning doesn't work in this case.
515 * As a heuristic, we first search for a bounding box comment in line.
516 * This obviously fails if not all of the numbers make it into the
517 * current buffer. This shouldn't be a problem, as the comment is
518 * typically near the beginning, and so should be read within the first
519 * BUFSIZ bytes (even on Windows where this is 512).
520 */
521 if (!(linep = strstr(line, "%%BoundingBox:")))
522 continue;
523 if (sscanf(linep, "%%%%BoundingBox: %d %d %d %d", &lx, &ly, &ux, &uy) ==
524 4) {
525 saw_bb = true;
526 break;
527 }
528 }
529 if (saw_bb) {
530 us->x = lx;
531 us->y = ly;
532 us->w = ux - lx;
533 us->h = uy - ly;
534 }
535}
536
537typedef struct {
538 FILE *fp;
540} stream_t;
541
542static void skipWS(stream_t *str) {
543 while (true) {
544 const int c = getc(str->fp);
545 if (gv_isspace(c)) {
546 continue;
547 }
548 if (c != EOF) {
549 (void)ungetc(c, str->fp);
550 }
551 break;
552 }
553}
554
555static int scanNum(char *tok, double *dp) {
556 char *endp;
557 double d = strtod(tok, &endp);
558
559 if (tok == endp)
560 return 1;
561 *dp = d;
562 return 0;
563}
564
565static char *getNum(stream_t *str) {
566 skipWS(str);
567 while (true) {
568 const int c = getc(str->fp);
569 if (gv_isdigit(c) || c == '.') {
570 agxbputc(&str->scratch, (char)c);
571 continue;
572 }
573 if (c != EOF) {
574 (void)ungetc(c, str->fp);
575 }
576 break;
577 }
578 return agxbuse(&str->scratch);
579}
580
581static int boxof(stream_t *str, boxf *bp) {
582 skipWS(str);
583 if (getc(str->fp) != '[')
584 return 1;
585 char *tok = getNum(str);
586 if (scanNum(tok, &bp->LL.x))
587 return 1;
588 tok = getNum(str);
589 if (scanNum(tok, &bp->LL.y))
590 return 1;
591 tok = getNum(str);
592 if (scanNum(tok, &bp->UR.x))
593 return 1;
594 tok = getNum(str);
595 if (scanNum(tok, &bp->UR.y))
596 return 1;
597 return 0;
598}
599
609static bool fstr(FILE *f, const char *needle) {
610 assert(f != NULL);
611 assert(needle != NULL);
612
613 // the algorithm in this function only works if the needle’s characters are
614 // distinct
615 for (size_t i = 0; needle[i] != '\0'; ++i) {
616 for (size_t j = i + 1; needle[j] != '\0'; ++j) {
617 assert(needle[i] != needle[j]);
618 }
619 }
620
621 for (size_t offset = 0;;) {
622 if (needle[offset] == '\0') {
623 return true;
624 }
625 const int c = getc(f);
626 if (c == EOF) {
627 break;
628 }
629 if (needle[offset] == c) {
630 ++offset;
631 } else if (needle[0] == c) {
632 offset = 1;
633 } else {
634 offset = 0;
635 }
636 }
637
638 return false;
639}
640
641static int bboxPDF(FILE *fp, boxf *bp) {
642 static const char KEY[] = "/MediaBox";
643 if (fstr(fp, KEY)) {
644 stream_t str = {.fp = fp};
645 const int rc = boxof(&str, bp);
646 agxbfree(&str.scratch);
647 return rc;
648 }
649
650 return 1;
651}
652
653static void pdf_size(usershape_t *us) {
654 boxf bb;
655
656 us->dpi = 0;
657 if (fseek(us->f, 0, SEEK_SET) < 0) {
658 return;
659 }
660 if (!bboxPDF(us->f, &bb)) {
661 us->x = bb.LL.x;
662 us->y = bb.LL.y;
663 us->w = bb.UR.x - bb.LL.x;
664 us->h = bb.UR.y - bb.LL.y;
665 }
666}
667
668static void usershape_close(void *p) {
669 usershape_t *us = p;
670
671 if (us->f)
672 fclose(us->f);
673 if (us->data && us->datafree)
674 us->datafree(us);
675 free(us);
676}
677
679 .key = offsetof(usershape_t, name),
680 .size = -1,
681 .freef = usershape_close,
682};
683
684usershape_t *gvusershape_find(const char *name) {
685 assert(name);
686 assert(name[0]);
687
688 if (!ImageDict)
689 return NULL;
690
691 return dtmatch(ImageDict, name);
692}
693
694#define MAX_USERSHAPE_FILES_OPEN 50
696 static int usershape_files_open_cnt;
697 const char *fn;
698
699 assert(us);
700 assert(us->name);
701 assert(us->name[0]);
702
703 if (us->f) {
704 if (fseek(us->f, 0, SEEK_SET) < 0) {
705 agwarningf("Failed to seek \"%s\" file handle\n", us->name);
706 return false;
707 }
708 } else {
709 if (!(fn = safefile(us->name))) {
710 agwarningf("Filename \"%s\" is unsafe\n", us->name);
711 return false;
712 }
713 us->f = gv_fopen(fn, "rb");
714 if (us->f == NULL) {
715 agwarningf("%s while opening %s\n", strerror(errno), fn);
716 return false;
717 }
718 if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN)
719 us->nocache = true;
720 else
721 usershape_files_open_cnt++;
722 }
723 assert(us->f);
724 return true;
725}
726
728 if (us->nocache) {
729 if (us->f) {
730 fclose(us->f);
731 us->f = NULL;
732 }
733 }
734}
735
736static void freeUsershape(usershape_t *us) {
737 if (us->name)
738 agstrfree(0, us->name, false);
739 free(us);
740}
741
742static usershape_t *gvusershape_open(const char *name) {
743 usershape_t *us;
744
745 assert(name);
746
747 if (!ImageDict)
749
750 if (!(us = gvusershape_find(name))) {
751 us = gv_alloc(sizeof(usershape_t));
752
753 us->name = agstrdup(0, name);
754 if (!gvusershape_file_access(us)) {
755 freeUsershape(us);
756 return NULL;
757 }
758
759 assert(us->f);
760
761 switch (imagetype(us)) {
762 case FT_NULL:
763 if (!(us->data = find_user_shape(us->name))) {
765 "\"%s\" was not found as a file or as a shape library member\n",
766 us->name);
767 freeUsershape(us);
768 return NULL;
769 }
770 break;
771 case FT_GIF:
772 gif_size(us);
773 break;
774 case FT_PNG:
775 png_size(us);
776 break;
777 case FT_BMP:
778 bmp_size(us);
779 break;
780 case FT_JPEG:
781 jpeg_size(us);
782 break;
783 case FT_PS:
784 ps_size(us);
785 break;
786 case FT_WEBP:
787 webp_size(us);
788 break;
789 case FT_SVG:
790 svg_size(us);
791 break;
792 case FT_PDF:
793 pdf_size(us);
794 break;
795 case FT_ICO:
796 ico_size(us);
797 break;
798 case FT_EPS: /* no eps_size code available */
799 default:
800 break;
801 }
803 dtinsert(ImageDict, us);
804 return us;
805 }
807 return us;
808}
809
810/* gvusershape_size_dpi:
811 * Return image size in points.
812 */
814 if (!us) {
815 return (point){.x = -1, .y = -1};
816 }
817 if (us->dpi != 0) {
818 dpi.x = dpi.y = us->dpi;
819 }
820 return (point){.x = (int)(us->w * POINTS_PER_INCH / dpi.x),
821 .y = (int)(us->h * POINTS_PER_INCH / dpi.y)};
822}
823
824/* gvusershape_size:
825 * Loads user image from file name if not already loaded.
826 * Return image size in points.
827 */
829 pointf dpi;
830 static char *oldpath;
831
832 /* no shape file, no shape size */
833 if (!name || (*name == '\0')) {
834 return (point){.x = -1, .y = -1};
835 }
836
837 if (!HTTPServerEnVar && (oldpath != Gvimagepath)) {
838 oldpath = Gvimagepath;
839 if (ImageDict) {
841 ImageDict = NULL;
842 }
843 }
844
845 if ((dpi.y = GD_drawing(g)->dpi) >= 1.0)
846 dpi.x = dpi.y;
847 else
848 dpi.x = dpi.y = DEFAULT_DPI;
849
850 usershape_t *const us = gvusershape_open(name);
851 return gvusershape_size_dpi(us, dpi);
852}
size_t match(char *str, char *pat)
return index of pattern pat in string str, or SIZE_MAX
Definition actions.c:91
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:97
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:325
static int agxbputc(agxbuf *xb, char c)
add character to buffer
Definition agxbuf.h:295
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define dtmatch(d, o)
Definition cdt.h:185
#define dtinsert(d, o)
Definition cdt.h:186
CDT_API Dtmethod_t * Dttree
Definition dttree.c:310
CDT_API int dtclose(Dt_t *)
Definition dtclose.c:10
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition dtopen.c:11
const char * safefile(const char *filename)
Definition utils.c:266
static Extype_t length(Exid_t *rhs, Exdisc_t *disc)
Definition compile.c:1615
#define POINTS_PER_MM
Definition geom.h:60
#define POINTS_PER_CM
Definition geom.h:59
#define POINTS_PER_INCH
Definition geom.h:58
char * HTTPServerEnVar
Definition globals.h:55
char * Gvimagepath
Definition globals.h:50
void free(void *)
node NULL
Definition grammar.y:181
void agwarningf(const char *fmt,...)
Definition agerror.c:175
#define GD_drawing(g)
Definition types.h:353
int agstrfree(Agraph_t *, const char *, bool is_html)
Definition refstr.c:417
char * agstrdup(Agraph_t *, const char *)
returns a pointer to a reference-counted copy of the argument string, creating one if necessary
Definition refstr.c:401
bool gvusershape_file_access(usershape_t *us)
replacements for ctype.h functions
static bool gv_islower(int c)
Definition gv_ctype.h:25
static bool gv_isdigit(int c)
Definition gv_ctype.h:41
static bool gv_isalpha(int c)
Definition gv_ctype.h:29
static bool gv_isspace(int c)
Definition gv_ctype.h:55
FILE * gv_fopen(const char *filename, const char *mode)
Definition gv_fopen.c:34
wrapper around fopen for internal library usage
static void ico_size(usershape_t *us)
static void freeUsershape(usershape_t *us)
#define XML_MAGIC
Definition gvusershape.c:55
#define HDRLEN
Definition gvusershape.c:46
#define MAX_USERSHAPE_FILES_OPEN
static bool get_int_msb_first(FILE *f, size_t sz, int *val)
#define RIFF_MAGIC
Definition gvusershape.c:57
#define PNG_MAGIC
Definition gvusershape.c:48
static bool get_int_lsb_first(FILE *f, size_t sz, int *val)
#define JPEG_MAGIC
Definition gvusershape.c:52
static char * getNum(stream_t *str)
static void skipWS(stream_t *str)
static Dtdisc_t ImageDictDisc
#define PS_MAGIC
Definition gvusershape.c:49
static int find_attribute(const char *s, match_t *result)
static void webp_size(usershape_t *us)
static bool fstr(FILE *f, const char *needle)
#define BMP_MAGIC
Definition gvusershape.c:50
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)
#define EPS_MAGIC
Definition gvusershape.c:54
#define ICO_MAGIC
Definition gvusershape.c:59
#define GIF_MAGIC
Definition gvusershape.c:51
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[]
Definition gvusershape.c:61
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)
#define PDF_MAGIC
Definition gvusershape.c:53
static Dict_t * ImageDict
Definition gvusershape.c:37
#define SVG_MAGIC
Definition gvusershape.c:56
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)
#define WEBP_MAGIC
Definition gvusershape.c:58
static void usershape_close(void *p)
textitem scanner parser str
Definition htmlparse.y:218
C analog of C++’s std::optional
#define OPTIONAL(type)
a container that may or may not contain a value
Definition optional.h:13
#define OPTIONAL_VALUE(me)
Definition optional.h:39
#define OPTIONAL_SET(me, value)
Definition optional.h:26
#define OPTIONAL_VALUE_OR(me, fallback)
Definition optional.h:53
shape_desc * find_user_shape(const char *)
Definition shapes.c:3938
static bool streq(const char *a, const char *b)
are a and b equal?
Definition streq.h:11
graph or subgraph
Definition cgraph.h:424
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
Definition cdt.h:98
int key
Definition cdt.h:85
imagetype_t type
Definition gvusershape.c:42
size_t size
Definition gvusershape.c:41
char * stringtype
Definition gvusershape.c:43
strview_t value
strview_t key
Definition geom.h:27
int x
Definition geom.h:27
double x
Definition geom.h:29
double y
Definition geom.h:29
FILE * fp
agxbuf scratch
a non-owning string reference
Definition strview.h:20
const char * data
start of the pointed to string
Definition strview.h:21
size_t size
extent of the string in bytes
Definition strview.h:22
const char * name
Definition usershape.h:54
char * stringtype
Definition usershape.h:60
FILE * f
Definition usershape.h:58
void(* datafree)(usershape_t *us)
Definition usershape.h:65
bool nocache
Definition usershape.h:57
void * data
Definition usershape.h:63
imagetype_t type
Definition usershape.h:59
double x
Definition usershape.h:61
double y
Definition usershape.h:61
double h
Definition usershape.h:61
double w
Definition usershape.h:61
Non-owning string references.
static bool strview_str_eq(strview_t a, const char *b)
compare a string reference to a string for equality
Definition strview.h:98
static char * strview_str(strview_t source)
make a heap-allocated string from this string view
Definition strview.h:41
static tok_t tok(const char *input, const char *separators)
begin tokenization of a new string
Definition tokenize.h:43
graphs, nodes and edges info: Agraphinfo_t, Agnodeinfo_t and Agedgeinfo_t
Definition grammar.c:90
imagetype_t
Definition usershape.h:24
@ FT_BMP
Definition usershape.h:25
@ FT_PS
Definition usershape.h:26
@ FT_ICO
Definition usershape.h:27
@ FT_NULL
Definition usershape.h:24
@ FT_EPS
Definition usershape.h:26
@ FT_SVG
Definition usershape.h:26
@ FT_WEBP
Definition usershape.h:27
@ FT_GIF
Definition usershape.h:25
@ FT_JPEG
Definition usershape.h:25
@ FT_RIFF
Definition usershape.h:27
@ FT_PNG
Definition usershape.h:25
@ FT_XML
Definition usershape.h:26
@ FT_PDF
Definition usershape.h:26