Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
gvusershape.c File Reference
#include "config.h"
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <util/gv_fopen.h>
#include <common/types.h>
#include <common/usershape.h>
#include <common/utils.h>
#include <gvc/gvplugin_loadimage.h>
#include <gvc/gvplugin.h>
#include <gvc/gvcint.h>
#include <gvc/gvcproc.h>
#include <util/agxbuf.h>
#include <util/alloc.h>
#include <util/gv_ctype.h>
#include <util/strview.h>
Include dependency graph for gvusershape.c:

Go to the source code of this file.

Data Structures

struct  knowntype_t
 
struct  match_t
 
struct  stream_t
 

Macros

#define HDRLEN   20
 
#define PNG_MAGIC   "\x89PNG\x0D\x0A\x1A\x0A"
 
#define PS_MAGIC   "%!PS-Adobe-"
 
#define BMP_MAGIC   "BM"
 
#define GIF_MAGIC   "GIF8"
 
#define JPEG_MAGIC   "\xFF\xD8\xFF"
 
#define PDF_MAGIC   "%PDF-"
 
#define EPS_MAGIC   "\xC5\xD0\xD3\xC6"
 
#define XML_MAGIC   "<?xml"
 
#define SVG_MAGIC   "<svg"
 
#define RIFF_MAGIC   "RIFF"
 
#define WEBP_MAGIC   "WEBP"
 
#define ICO_MAGIC   "\x00\x00\x01\x00"
 
#define KEY   "/MediaBox"
 
#define strc(x)   (*(x->s)?*(x->s):nxtc(x))
 
#define stradv(x)   (x->s++)
 
#define MAX_USERSHAPE_FILES_OPEN   50
 

Functions

shape_descfind_user_shape (const char *)
 
static imagetype_t imagetype (usershape_t *us)
 
static bool get_int_lsb_first (FILE *f, size_t sz, int *val)
 
static bool get_int_msb_first (FILE *f, size_t sz, int *val)
 
static double svg_units_convert (double n, char *u)
 
static int find_attribute (const char *s, match_t *result)
 
static void svg_size (usershape_t *us)
 
static void png_size (usershape_t *us)
 
static void ico_size (usershape_t *us)
 
static void webp_size (usershape_t *us)
 
static void gif_size (usershape_t *us)
 
static void bmp_size (usershape_t *us)
 
static void jpeg_size (usershape_t *us)
 
static void ps_size (usershape_t *us)
 
static char nxtc (stream_t *str)
 
static void skipWS (stream_t *str)
 
static int scanNum (char *tok, double *dp)
 
static void getNum (stream_t *str, char *buf)
 
static int boxof (stream_t *str, boxf *bp)
 
static int bboxPDF (FILE *fp, boxf *bp)
 
static void pdf_size (usershape_t *us)
 
static void usershape_close (void *p)
 
usershape_tgvusershape_find (const char *name)
 
bool gvusershape_file_access (usershape_t *us)
 
void gvusershape_file_release (usershape_t *us)
 
static void freeUsershape (usershape_t *us)
 
static usershape_tgvusershape_open (const char *name)
 
point gvusershape_size_dpi (usershape_t *us, pointf dpi)
 
point gvusershape_size (graph_t *g, char *name)
 

Variables

char * Gvimagepath
 
char * HTTPServerEnVar
 
static Dict_tImageDict
 
static knowntype_t knowntypes []
 
static Dtdisc_t ImageDictDisc
 

Macro Definition Documentation

◆ BMP_MAGIC

#define BMP_MAGIC   "BM"

Definition at line 59 of file gvusershape.c.

◆ EPS_MAGIC

#define EPS_MAGIC   "\xC5\xD0\xD3\xC6"

Definition at line 63 of file gvusershape.c.

◆ GIF_MAGIC

#define GIF_MAGIC   "GIF8"

Definition at line 60 of file gvusershape.c.

◆ HDRLEN

#define HDRLEN   20

Definition at line 55 of file gvusershape.c.

◆ ICO_MAGIC

#define ICO_MAGIC   "\x00\x00\x01\x00"

Definition at line 68 of file gvusershape.c.

◆ JPEG_MAGIC

#define JPEG_MAGIC   "\xFF\xD8\xFF"

Definition at line 61 of file gvusershape.c.

◆ KEY

#define KEY   "/MediaBox"

Definition at line 486 of file gvusershape.c.

◆ MAX_USERSHAPE_FILES_OPEN

#define MAX_USERSHAPE_FILES_OPEN   50

Definition at line 623 of file gvusershape.c.

◆ PDF_MAGIC

#define PDF_MAGIC   "%PDF-"

Definition at line 62 of file gvusershape.c.

◆ PNG_MAGIC

#define PNG_MAGIC   "\x89PNG\x0D\x0A\x1A\x0A"

Definition at line 57 of file gvusershape.c.

◆ PS_MAGIC

#define PS_MAGIC   "%!PS-Adobe-"

Definition at line 58 of file gvusershape.c.

◆ RIFF_MAGIC

#define RIFF_MAGIC   "RIFF"

Definition at line 66 of file gvusershape.c.

◆ stradv

#define stradv (   x)    (x->s++)

Definition at line 504 of file gvusershape.c.

◆ strc

#define strc (   x)    (*(x->s)?*(x->s):nxtc(x))

Definition at line 503 of file gvusershape.c.

◆ SVG_MAGIC

#define SVG_MAGIC   "<svg"

Definition at line 65 of file gvusershape.c.

◆ WEBP_MAGIC

#define WEBP_MAGIC   "WEBP"

Definition at line 67 of file gvusershape.c.

◆ XML_MAGIC

#define XML_MAGIC   "<?xml"

Definition at line 64 of file gvusershape.c.

Function Documentation

◆ bboxPDF()

static int bboxPDF ( FILE *  fp,
boxf bp 
)
static

Definition at line 563 of file gvusershape.c.

References boxof(), KEY, and str.

Referenced by pdf_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bmp_size()

static void bmp_size ( usershape_t us)
static

Definition at line 365 of file gvusershape.c.

References usershape_s::dpi, usershape_s::f, get_int_lsb_first(), usershape_s::h, and usershape_s::w.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boxof()

static int boxof ( stream_t str,
boxf bp 
)
static

Definition at line 544 of file gvusershape.c.

References getNum(), boxf::LL, scanNum(), skipWS(), str, stradv, strc, tok(), boxf::UR, pointf_s::x, and pointf_s::y.

Referenced by bboxPDF().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_attribute()

static int find_attribute ( const char *  s,
match_t result 
)
static

Definition at line 195 of file gvusershape.c.

References strview_t::data, match_t::key, strview_t::size, and match_t::value.

Referenced by svg_size().

Here is the caller graph for this function:

◆ find_user_shape()

shape_desc * find_user_shape ( const char *  name)
extern

Definition at line 3962 of file shapes.c.

Referenced by gvusershape_open(), and user_shape().

Here is the caller graph for this function:

◆ freeUsershape()

static void freeUsershape ( usershape_t us)
static

Definition at line 664 of file gvusershape.c.

References agstrfree(), free(), and usershape_s::name.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_int_lsb_first()

static bool get_int_lsb_first ( FILE *  f,
size_t  sz,
int *  val 
)
static

Definition at line 139 of file gvusershape.c.

Referenced by bmp_size(), gif_size(), and webp_size().

Here is the caller graph for this function:

◆ get_int_msb_first()

static bool get_int_msb_first ( FILE *  f,
size_t  sz,
int *  val 
)
static

Definition at line 156 of file gvusershape.c.

Referenced by ico_size(), jpeg_size(), and png_size().

Here is the caller graph for this function:

◆ getNum()

static void getNum ( stream_t str,
char *  buf 
)
static

Definition at line 528 of file gvusershape.c.

References gv_isdigit(), len(), skipWS(), str, stradv, and strc.

Referenced by boxof().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gif_size()

static void gif_size ( usershape_t us)
static

Definition at line 353 of file gvusershape.c.

References usershape_s::dpi, usershape_s::f, get_int_lsb_first(), usershape_s::h, and usershape_s::w.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvusershape_file_release()

void gvusershape_file_release ( usershape_t us)

Definition at line 654 of file gvusershape.c.

References usershape_s::f, usershape_s::nocache, and NULL.

Referenced by cairo_loadimage(), core_loadimage_ps(), gd_loadimage(), gdiplus_loadimage(), gvloadimage_rsvg_load(), gvusershape_open(), lasi_loadimage_ps(), and quartz_loadimage().

Here is the caller graph for this function:

◆ gvusershape_find()

usershape_t * gvusershape_find ( const char *  name)

Definition at line 609 of file gvusershape.c.

References dtmatch, ImageDict, and NULL.

Referenced by gvrender_usershape(), and gvusershape_open().

Here is the caller graph for this function:

◆ gvusershape_open()

static usershape_t * gvusershape_open ( const char *  name)
static

Definition at line 670 of file gvusershape.c.

References agstrdup(), agwarningf(), bmp_size(), usershape_s::data, dtinsert, dtopen(), Dttree, usershape_s::f, find_user_shape(), freeUsershape(), FT_BMP, FT_EPS, FT_GIF, FT_ICO, FT_JPEG, FT_NULL, FT_PDF, FT_PNG, FT_PS, FT_SVG, FT_WEBP, gif_size(), gv_alloc(), gvusershape_file_access(), gvusershape_file_release(), gvusershape_find(), ico_size(), ImageDict, ImageDictDisc, imagetype(), jpeg_size(), usershape_s::name, NULL, pdf_size(), png_size(), ps_size(), svg_size(), and webp_size().

Referenced by gvusershape_size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvusershape_size()

point gvusershape_size ( graph_t g,
char *  name 
)

Definition at line 762 of file gvusershape.c.

References dtclose(), GD_drawing, Gvimagepath, gvusershape_open(), gvusershape_size_dpi(), HTTPServerEnVar, ImageDict, NULL, point::x, pointf_s::x, point::y, and pointf_s::y.

Referenced by poly_init(), and size_html_img().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gvusershape_size_dpi()

point gvusershape_size_dpi ( usershape_t us,
pointf  dpi 
)

Definition at line 741 of file gvusershape.c.

References usershape_s::dpi, usershape_s::h, POINTS_PER_INCH, usershape_s::w, point::x, pointf_s::x, point::y, and pointf_s::y.

Referenced by gvrender_usershape(), and gvusershape_size().

Here is the caller graph for this function:

◆ ico_size()

static void ico_size ( usershape_t us)
static

Definition at line 319 of file gvusershape.c.

References usershape_s::dpi, usershape_s::f, get_int_msb_first(), usershape_s::h, and usershape_s::w.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imagetype()

static imagetype_t imagetype ( usershape_t us)
static

Definition at line 83 of file gvusershape.c.

References usershape_s::f, FT_NULL, FT_RIFF, FT_SVG, FT_WEBP, FT_XML, HDRLEN, knowntypes, NULL, usershape_s::stringtype, knowntype_t::stringtype, SVG_MAGIC, usershape_s::type, knowntype_t::type, and WEBP_MAGIC.

Referenced by gvusershape_open().

Here is the caller graph for this function:

◆ jpeg_size()

static void jpeg_size ( usershape_t us)
static

Definition at line 379 of file gvusershape.c.

References usershape_s::dpi, usershape_s::f, get_int_msb_first(), usershape_s::h, and usershape_s::w.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nxtc()

static char nxtc ( stream_t str)
static

Definition at line 494 of file gvusershape.c.

References stream_t::s, and str.

◆ pdf_size()

static void pdf_size ( usershape_t us)
static

Definition at line 579 of file gvusershape.c.

References bboxPDF(), usershape_s::dpi, usershape_s::f, usershape_s::h, boxf::LL, boxf::UR, usershape_s::w, pointf_s::x, usershape_s::x, pointf_s::y, and usershape_s::y.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_size()

static void png_size ( usershape_t us)
static

Definition at line 307 of file gvusershape.c.

References usershape_s::dpi, usershape_s::f, get_int_msb_first(), usershape_s::h, and usershape_s::w.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ps_size()

static void ps_size ( usershape_t us)
static

Definition at line 453 of file gvusershape.c.

References usershape_s::dpi, usershape_s::f, usershape_s::h, usershape_s::w, usershape_s::x, and usershape_s::y.

Referenced by gvusershape_open().

Here is the caller graph for this function:

◆ scanNum()

static int scanNum ( char *  tok,
double *  dp 
)
static

Definition at line 517 of file gvusershape.c.

References tok().

Referenced by boxof().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ skipWS()

static void skipWS ( stream_t str)
static

Definition at line 507 of file gvusershape.c.

References gv_isspace(), str, stradv, and strc.

Referenced by boxof(), and getNum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ svg_size()

static void svg_size ( usershape_t us)
static

Definition at line 229 of file gvusershape.c.

References agxbfree(), agxbputc(), agxbuse(), strview_t::data, usershape_s::dpi, usershape_s::f, find_attribute(), free(), usershape_s::h, match(), strview_str(), strview_str_eq(), svg_units_convert(), match_t::value, and usershape_s::w.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ svg_units_convert()

static double svg_units_convert ( double  n,
char *  u 
)
static

Definition at line 174 of file gvusershape.c.

References POINTS_PER_CM, POINTS_PER_INCH, and POINTS_PER_MM.

Referenced by svg_size().

Here is the caller graph for this function:

◆ usershape_close()

static void usershape_close ( void *  p)
static

Definition at line 593 of file gvusershape.c.

References usershape_s::data, usershape_s::datafree, usershape_s::f, and free().

Here is the call graph for this function:

◆ webp_size()

static void webp_size ( usershape_t us)
static

Definition at line 331 of file gvusershape.c.

References usershape_s::dpi, usershape_s::f, get_int_lsb_first(), usershape_s::h, and usershape_s::w.

Referenced by gvusershape_open().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ Gvimagepath

char* Gvimagepath
extern

Definition at line 48 of file globals.h.

Referenced by graph_init(), gvusershape_size(), and safefile().

◆ HTTPServerEnVar

char* HTTPServerEnVar
extern

Definition at line 52 of file globals.h.

Referenced by dotneato_args_initialize(), graph_init(), gvusershape_size(), and safefile().

◆ ImageDict

Dict_t* ImageDict
static

Definition at line 46 of file gvusershape.c.

Referenced by gvusershape_find(), gvusershape_open(), and gvusershape_size().

◆ ImageDictDisc

Dtdisc_t ImageDictDisc
static
Initial value:
= {
.key = offsetof(usershape_t, name),
.size = -1,
.freef = usershape_close,
}
static void usershape_close(void *p)

Definition at line 603 of file gvusershape.c.

Referenced by gvusershape_open().

◆ knowntypes

knowntype_t knowntypes[]
static
Initial value:
= {
{ PNG_MAGIC, sizeof(PNG_MAGIC)-1, FT_PNG, "png", },
{ PS_MAGIC, sizeof(PS_MAGIC)-1, FT_PS, "ps", },
{ BMP_MAGIC, sizeof(BMP_MAGIC)-1, FT_BMP, "bmp", },
{ GIF_MAGIC, sizeof(GIF_MAGIC)-1, FT_GIF, "gif", },
{ JPEG_MAGIC, sizeof(JPEG_MAGIC)-1, FT_JPEG, "jpeg", },
{ PDF_MAGIC, sizeof(PDF_MAGIC)-1, FT_PDF, "pdf", },
{ EPS_MAGIC, sizeof(EPS_MAGIC)-1, FT_EPS, "eps", },
{ XML_MAGIC, sizeof(XML_MAGIC)-1, FT_XML, "xml", },
{ RIFF_MAGIC, sizeof(RIFF_MAGIC)-1, FT_RIFF, "riff", },
{ ICO_MAGIC, sizeof(ICO_MAGIC)-1, FT_ICO, "ico", },
}
#define XML_MAGIC
Definition gvusershape.c:64
#define RIFF_MAGIC
Definition gvusershape.c:66
#define PNG_MAGIC
Definition gvusershape.c:57
#define JPEG_MAGIC
Definition gvusershape.c:61
#define PS_MAGIC
Definition gvusershape.c:58
#define BMP_MAGIC
Definition gvusershape.c:59
#define EPS_MAGIC
Definition gvusershape.c:63
#define ICO_MAGIC
Definition gvusershape.c:68
#define GIF_MAGIC
Definition gvusershape.c:60
#define PDF_MAGIC
Definition gvusershape.c:62
@ FT_BMP
Definition usershape.h:25
@ FT_PS
Definition usershape.h:26
@ FT_ICO
Definition usershape.h:27
@ FT_EPS
Definition usershape.h:26
@ 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

Definition at line 70 of file gvusershape.c.

Referenced by imagetype().