Graphviz 14.1.2~dev.20260123.1158
Loading...
Searching...
No Matches
gvusershape.c File Reference
#include "config.h"
#include <assert.h>
#include <common/globals.h>
#include <common/render.h>
#include <common/types.h>
#include <common/usershape.h>
#include <common/utils.h>
#include <errno.h>
#include <gvc/gvcint.h>
#include <gvc/gvcproc.h>
#include <gvc/gvplugin.h>
#include <gvc/gvplugin_loadimage.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <util/agxbuf.h>
#include <util/alloc.h>
#include <util/gv_ctype.h>
#include <util/gv_fopen.h>
#include <util/optional.h>
#include <util/streq.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 MAX_USERSHAPE_FILES_OPEN   50
 

Functions

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 void skipWS (stream_t *str)
 
static int scanNum (char *tok, double *dp)
 
static char * getNum (stream_t *str)
 
static int boxof (stream_t *str, boxf *bp)
 
static bool fstr (FILE *f, const char *needle)
 
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

static Dict_tImageDict
 
static knowntype_t knowntypes []
 
static Dtdisc_t ImageDictDisc
 

Macro Definition Documentation

◆ BMP_MAGIC

#define BMP_MAGIC   "BM"

Definition at line 50 of file gvusershape.c.

◆ EPS_MAGIC

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

Definition at line 54 of file gvusershape.c.

◆ GIF_MAGIC

#define GIF_MAGIC   "GIF8"

Definition at line 51 of file gvusershape.c.

◆ HDRLEN

#define HDRLEN   20

Definition at line 46 of file gvusershape.c.

◆ ICO_MAGIC

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

Definition at line 59 of file gvusershape.c.

◆ JPEG_MAGIC

#define JPEG_MAGIC   "\xFF\xD8\xFF"

Definition at line 52 of file gvusershape.c.

◆ MAX_USERSHAPE_FILES_OPEN

#define MAX_USERSHAPE_FILES_OPEN   50

Definition at line 682 of file gvusershape.c.

◆ PDF_MAGIC

#define PDF_MAGIC   "%PDF-"

Definition at line 53 of file gvusershape.c.

◆ PNG_MAGIC

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

Definition at line 48 of file gvusershape.c.

◆ PS_MAGIC

#define PS_MAGIC   "%!PS-Adobe-"

Definition at line 49 of file gvusershape.c.

◆ RIFF_MAGIC

#define RIFF_MAGIC   "RIFF"

Definition at line 57 of file gvusershape.c.

◆ SVG_MAGIC

#define SVG_MAGIC   "<svg"

Definition at line 56 of file gvusershape.c.

◆ WEBP_MAGIC

#define WEBP_MAGIC   "WEBP"

Definition at line 58 of file gvusershape.c.

◆ XML_MAGIC

#define XML_MAGIC   "<?xml"

Definition at line 55 of file gvusershape.c.

Function Documentation

◆ bboxPDF()

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

Definition at line 631 of file gvusershape.c.

References agxbfree(), boxof(), stream_t::fp, fstr(), 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 405 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 571 of file gvusershape.c.

References getNum(), boxf::LL, scanNum(), skipWS(), str, 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 232 of file gvusershape.c.

References strview_t::data, gv_isalpha(), gv_islower(), match_t::key, strview_t::size, and match_t::value.

Referenced by svg_size().

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

◆ freeUsershape()

static void freeUsershape ( usershape_t us)
static

Definition at line 721 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:

◆ fstr()

static bool fstr ( FILE *  f,
const char *  needle 
)
static

scan a file until a string is found

This is essentially strstr, but taking a FILE * as the haystack instead of a char *. Note that the position of f will be immediately after the given string if this function returns true.

Parameters
fFile to seek
needleSubstring to look for
Returns
True if the substring was found

Definition at line 599 of file gvusershape.c.

References NULL.

Referenced by bboxPDF().

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 179 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 194 of file gvusershape.c.

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

Here is the caller graph for this function:

◆ getNum()

static char * getNum ( stream_t str)
static

Definition at line 555 of file gvusershape.c.

References agxbputc(), agxbuse(), gv_isdigit(), skipWS(), and str.

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 394 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 712 of file gvusershape.c.

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

Referenced by cairo_loadimage(), core_loadimage_ps(), gd_loadimage(), gdiplus_loadimage(), gdk_loadimage(), gvloadimage_process_file(), 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 672 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 727 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 813 of file gvusershape.c.

References dtclose(), GD_drawing, Gvimagepath, gvusershape_open(), gvusershape_size_dpi(), HTTPServerEnVar, ImageDict, NULL, pointf_s::x, 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 798 of file gvusershape.c.

References usershape_s::dpi, usershape_s::h, POINTS_PER_INCH, usershape_s::w, point::x, pointf_s::x, 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 363 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 124 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 419 of file gvusershape.c.

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

Referenced by gvusershape_open().

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

◆ pdf_size()

static void pdf_size ( usershape_t us)
static

Definition at line 643 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 352 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 494 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 545 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 532 of file gvusershape.c.

References gv_isspace(), and str.

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 266 of file gvusershape.c.

References agxbfree(), agxbputc(), agxbuse(), strview_t::data, usershape_s::dpi, usershape_s::f, find_attribute(), free(), usershape_s::h, optional_double_t::has_value, match(), optional_double_set(), optional_double_value_or(), strview_str(), strview_str_eq(), svg_units_convert(), match_t::value, optional_double_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 210 of file gvusershape.c.

References POINTS_PER_CM, POINTS_PER_INCH, POINTS_PER_MM, and streq().

Referenced by svg_size().

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

◆ usershape_close()

static void usershape_close ( void *  p)
static

Definition at line 656 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 374 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

◆ ImageDict

Dict_t* ImageDict
static

Definition at line 37 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 666 of file gvusershape.c.

Referenced by gvusershape_open().

◆ knowntypes

knowntype_t knowntypes[]
static

Definition at line 61 of file gvusershape.c.

Referenced by imagetype().