Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
gvloadimage_core.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 v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include "config.h"
12
13#include <stdbool.h>
14#include <stdlib.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#ifdef HAVE_SYS_MMAN_H
18#include <sys/mman.h>
19#endif
20
22#include <common/utils.h>
23#include <gvc/gvio.h>
24#include "core_loadimage_xdot.h"
25#include <util/agxbuf.h>
26
27extern shape_desc *find_user_shape(char *name);
28
39
40static void core_loadimage_svg(GVJ_t * job, usershape_t *us, boxf b, bool filled)
41{
42 (void)filled;
43
44 double width = (b.UR.x-b.LL.x);
45 double height = (b.UR.y-b.LL.y);
46 double originx = (b.UR.x+b.LL.x - width)/2;
47 double originy = (b.UR.y+b.LL.y + height)/2;
48 assert(job);
49 assert(us);
50 assert(us->name);
51
52 gvputs(job, "<image xlink:href=\"");
53 gvputs(job, us->name);
54 if (job->rotation) {
55
56// FIXME - this is messed up >>>
57 gvprintf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMidYMid meet\" x=\"%g\" y=\"%g\"",
58 height, width, originx, -originy);
59 gvprintf (job, " transform=\"rotate(%d %g %g)\"",
60 job->rotation, originx, -originy);
61// <<<
62 }
63 else {
64 gvprintf (job, "\" width=\"%gpx\" height=\"%gpx\" preserveAspectRatio=\"xMinYMin meet\" x=\"%g\" y=\"%g\"",
65 width, height, originx, -originy);
66 }
67 gvputs(job, "/>\n");
68}
69
70static void core_loadimage_fig(GVJ_t * job, usershape_t *us, boxf bf, bool filled)
71{
72 (void)filled;
73
74 int object_code = 2; /* always 2 for polyline */
75 int sub_type = 5; /* always 5 for image */
76 int line_style = 0; /* solid, dotted, dashed */
77 int thickness = 0;
78 int pen_color = 0;
79 int fill_color = -1;
80 int depth = 1;
81 int pen_style = -1; /* not used */
82 int area_fill = 0;
83 double style_val = 0.0;
84 int join_style = 0;
85 int cap_style = 0;
86 int radius = 0;
87 int forward_arrow = 0;
88 int backward_arrow = 0;
89 int npoints = 5;
90 int flipped = 0;
91
92 assert(job);
93 assert(us);
94 assert(us->name);
95
96 gvprintf(job, "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n %d %s\n",
97 object_code, sub_type, line_style, thickness, pen_color,
98 fill_color, depth, pen_style, area_fill, style_val, join_style,
99 cap_style, radius, forward_arrow, backward_arrow, npoints,
100 flipped, us->name);
101 gvprintf(job," %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f %.0f\n",
102 bf.LL.x, bf.LL.y,
103 bf.LL.x, bf.UR.y,
104 bf.UR.x, bf.UR.y,
105 bf.UR.x, bf.LL.y,
106 bf.LL.x, bf.LL.y);
107}
108
109static void core_loadimage_vrml(GVJ_t * job, usershape_t *us, boxf b, bool filled)
110{
111 (void)b;
112 (void)filled;
113
114 assert(job);
115 assert(job->obj);
116 assert(us);
117 assert(us->name);
118
119 assert(job->obj->u.n);
120
121 gvprintf(job, "Shape {\n");
122 gvprintf(job, " appearance Appearance {\n");
123 gvprintf(job, " material Material {\n");
124 gvprintf(job, " ambientIntensity 0.33\n");
125 gvprintf(job, " diffuseColor 1 1 1\n");
126 gvprintf(job, " }\n");
127 gvprintf(job, " texture ImageTexture { url \"%s\" }\n", us->name);
128 gvprintf(job, " }\n");
129 gvprintf(job, "}\n");
130}
131
132static void ps_freeimage(usershape_t *us)
133{
134#ifdef HAVE_SYS_MMAN_H
135 munmap(us->data, us->datasize);
136#else
137 free(us->data);
138#endif
139}
140
141/* usershape described by a postscript file */
142static void core_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, bool filled)
143{
144 (void)filled;
145
146 assert(job);
147 assert(us);
148 assert(us->name);
149
150 if (us->data) {
151 if (us->datafree != ps_freeimage) {
152 us->datafree(us); /* free incompatible cache data */
153 us->data = NULL;
154 us->datafree = NULL;
155 us->datasize = 0;
156 }
157 }
158
159 if (!us->data) { /* read file into cache */
160 int fd;
161 struct stat statbuf;
162
164 return;
165 fd = fileno(us->f);
166 switch (us->type) {
167 case FT_PS:
168 case FT_EPS:
169 fstat(fd, &statbuf);
170 us->datasize = (size_t)statbuf.st_size;
171#ifdef HAVE_SYS_MMAN_H
172 us->data = mmap(0, us->datasize, PROT_READ, MAP_PRIVATE, fd, 0);
173 if (us->data == MAP_FAILED)
174 us->data = NULL;
175#else
176 us->data = malloc(statbuf.st_size);
177 if (us->data != NULL)
178 read(fd, us->data, statbuf.st_size);
179#endif
180 us->must_inline = true;
181 break;
182 default:
183 break;
184 }
185 if (us->data)
188 }
189
190 if (us->data) {
191 gvprintf(job, "gsave %g %g translate newpath\n",
192 b.LL.x - (double)(us->x), b.LL.y - (double)(us->y));
193 if (us->must_inline)
194 epsf_emit_body(job, us);
195 else
196 gvprintf(job, "user_shape_%d\n", us->macro_id);
197 gvprintf(job, "grestore\n");
198 }
199}
200
201/* usershape described by a member of a postscript library */
202static void core_loadimage_pslib(GVJ_t * job, usershape_t *us, boxf b, bool filled)
203{
204 int i;
205 pointf AF[4];
206 shape_desc *shape;
207
208 assert(job);
209 assert(us);
210 assert(us->name);
211
212 if ((shape = us->data)) {
213 AF[0] = b.LL;
214 AF[2] = b.UR;
215 AF[1].x = AF[0].x;
216 AF[1].y = AF[2].y;
217 AF[3].x = AF[2].x;
218 AF[3].y = AF[0].y;
219 if (filled) {
220 gvprintf(job, "[ ");
221 for (i = 0; i < 4; i++)
222 gvprintf(job, "%g %g ", AF[i].x, AF[i].y);
223 gvprintf(job, "%g %g ", AF[0].x, AF[0].y);
224 gvprintf(job, "] %d true %s\n", 4, us->name);
225 }
226 gvprintf(job, "[ ");
227 for (i = 0; i < 4; i++)
228 gvprintf(job, "%g %g ", AF[i].x, AF[i].y);
229 gvprintf(job, "%g %g ", AF[0].x, AF[0].y);
230 gvprintf(job, "] %d false %s\n", 4, us->name);
231 }
232}
233
234static void core_loadimage_tk(GVJ_t * job, usershape_t *us, boxf b, bool filled)
235{
236 (void)filled;
237
238 gvprintf (job, "image create photo \"photo_%s\" -file \"%s\"\n",
239 us->name, us->name);
240 gvprintf (job, "$c create image %.2f %.2f -image \"photo_%s\"\n",
241 (b.UR.x + b.LL.x) / 2, (b.UR.y + b.LL.y) / 2, us->name);
242}
243
244static void core_loadimage_null(GVJ_t *gvc, usershape_t *us, boxf b, bool filled)
245{
246 /* null function - basically suppress the missing loader message */
247 (void)gvc;
248 (void)us;
249 (void)b;
250 (void)filled;
251}
252
256
260
264
268
272
276
280
284
286 {FORMAT_PNG_SVG, "png:svg", 1, &engine_svg, NULL},
287 {FORMAT_GIF_SVG, "gif:svg", 1, &engine_svg, NULL},
288 {FORMAT_JPEG_SVG, "jpeg:svg", 1, &engine_svg, NULL},
289 {FORMAT_JPEG_SVG, "jpe:svg", 1, &engine_svg, NULL},
290 {FORMAT_JPEG_SVG, "jpg:svg", 1, &engine_svg, NULL},
291
292 {FORMAT_PNG_FIG, "png:fig", 1, &engine_fig, NULL},
293 {FORMAT_GIF_FIG, "gif:fig", 1, &engine_fig, NULL},
294 {FORMAT_JPEG_FIG, "jpeg:fig", 1, &engine_fig, NULL},
295 {FORMAT_JPEG_FIG, "jpe:fig", 1, &engine_fig, NULL},
296 {FORMAT_JPEG_FIG, "jpg:fig", 1, &engine_fig, NULL},
297
298 {FORMAT_PNG_VRML, "png:vrml", 1, &engine_vrml, NULL},
299 {FORMAT_GIF_VRML, "gif:vrml", 1, &engine_vrml, NULL},
300 {FORMAT_JPEG_VRML, "jpeg:vrml", 1, &engine_vrml, NULL},
301 {FORMAT_JPEG_VRML, "jpe:vrml", 1, &engine_vrml, NULL},
302 {FORMAT_JPEG_VRML, "jpg:vrml", 1, &engine_vrml, NULL},
303
304 {FORMAT_PS_PS, "eps:ps", 1, &engine_ps, NULL},
305 {FORMAT_PS_PS, "ps:ps", 1, &engine_ps, NULL},
306 {FORMAT_PSLIB_PS, "(lib):ps", 1, &engine_pslib, NULL}, /* for pslib */
307
308 {FORMAT_PNG_MAP, "png:map", 1, &engine_null, NULL},
309 {FORMAT_GIF_MAP, "gif:map", 1, &engine_null, NULL},
310 {FORMAT_JPEG_MAP, "jpeg:map", 1, &engine_null, NULL},
311 {FORMAT_JPEG_MAP, "jpe:map", 1, &engine_null, NULL},
312 {FORMAT_JPEG_MAP, "jpg:map", 1, &engine_null, NULL},
313 {FORMAT_PS_MAP, "ps:map", 1, &engine_null, NULL},
314 {FORMAT_PS_MAP, "eps:map", 1, &engine_null, NULL},
315 {FORMAT_SVG_MAP, "svg:map", 1, &engine_null, NULL},
316
317 {FORMAT_PNG_DOT, "png:dot", 1, &engine_null, NULL},
318 {FORMAT_GIF_DOT, "gif:dot", 1, &engine_null, NULL},
319 {FORMAT_JPEG_DOT, "jpeg:dot", 1, &engine_null, NULL},
320 {FORMAT_JPEG_DOT, "jpe:dot", 1, &engine_null, NULL},
321 {FORMAT_JPEG_DOT, "jpg:dot", 1, &engine_null, NULL},
322 {FORMAT_PS_DOT, "ps:dot", 1, &engine_null, NULL},
323 {FORMAT_PS_DOT, "eps:dot", 1, &engine_null, NULL},
324 {FORMAT_SVG_DOT, "svg:dot", 1, &engine_null, NULL},
325
326 {FORMAT_PNG_XDOT, "png:xdot", 1, &engine_xdot, NULL},
327 {FORMAT_GIF_XDOT, "gif:xdot", 1, &engine_xdot, NULL},
328 {FORMAT_JPEG_XDOT, "jpeg:xdot", 1, &engine_xdot, NULL},
329 {FORMAT_JPEG_XDOT, "jpe:xdot", 1, &engine_xdot, NULL},
330 {FORMAT_JPEG_XDOT, "jpg:xdot", 1, &engine_xdot, NULL},
331 {FORMAT_PS_XDOT, "ps:xdot", 1, &engine_xdot, NULL},
332 {FORMAT_PS_XDOT, "eps:xdot", 1, &engine_xdot, NULL},
333 {FORMAT_SVG_XDOT, "svg:xdot", 1, &engine_xdot, NULL},
334
335 {FORMAT_SVG_SVG, "svg:svg", 1, &engine_svg, NULL},
336
337 {FORMAT_GIF_TK, "gif:tk", 1, &engine_tk, NULL},
338
339 {0, NULL, 0, NULL, NULL}
340};
void core_loadimage_xdot(GVJ_t *, usershape_t *, boxf, bool)
void * malloc(YYSIZE_T)
void free(void *)
node NULL
Definition grammar.y:163
void gvusershape_file_release(usershape_t *us)
bool gvusershape_file_access(usershape_t *us)
Agraph_t * read(FILE *f)
Definition gv.cpp:60
static GVC_t * gvc
Definition gv.cpp:23
int gvputs(GVJ_t *job, const char *s)
Definition gvdevice.c:264
void gvprintf(GVJ_t *job, const char *format,...)
Definition gvdevice.c:395
static void core_loadimage_ps(GVJ_t *job, usershape_t *us, boxf b, bool filled)
static gvloadimage_engine_t engine_ps
static void core_loadimage_pslib(GVJ_t *job, usershape_t *us, boxf b, bool filled)
static gvloadimage_engine_t engine_null
static gvloadimage_engine_t engine_pslib
static void ps_freeimage(usershape_t *us)
static void core_loadimage_svg(GVJ_t *job, usershape_t *us, boxf b, bool filled)
static gvloadimage_engine_t engine_svg
static gvloadimage_engine_t engine_vrml
static gvloadimage_engine_t engine_xdot
static void core_loadimage_fig(GVJ_t *job, usershape_t *us, boxf bf, bool filled)
static gvloadimage_engine_t engine_fig
format_type
@ FORMAT_SVG_XDOT
@ FORMAT_PS_MAP
@ FORMAT_GIF_FIG
@ FORMAT_JPEG_SVG
@ FORMAT_PNG_SVG
@ FORMAT_PNG_DOT
@ FORMAT_GIF_MAP
@ FORMAT_SVG_SVG
@ FORMAT_PNG_VRML
@ FORMAT_PS_DOT
@ FORMAT_GIF_XDOT
@ FORMAT_SVG_MAP
@ FORMAT_JPEG_MAP
@ FORMAT_GIF_SVG
@ FORMAT_GIF_DOT
@ FORMAT_PSLIB_PS
@ FORMAT_JPEG_DOT
@ FORMAT_GIF_VRML
@ FORMAT_SVG_DOT
@ FORMAT_PNG_MAP
@ FORMAT_PS_XDOT
@ FORMAT_PNG_FIG
@ FORMAT_JPEG_FIG
@ FORMAT_JPEG_VRML
@ FORMAT_JPEG_XDOT
@ FORMAT_GIF_TK
@ FORMAT_PNG_XDOT
@ FORMAT_PS_PS
gvplugin_installed_t gvloadimage_core_types[]
static void core_loadimage_tk(GVJ_t *job, usershape_t *us, boxf b, bool filled)
shape_desc * find_user_shape(char *name)
static gvloadimage_engine_t engine_tk
static void core_loadimage_null(GVJ_t *gvc, usershape_t *us, boxf b, bool filled)
static void core_loadimage_vrml(GVJ_t *job, usershape_t *us, boxf b, bool filled)
void epsf_emit_body(GVJ_t *job, usershape_t *us)
int rotation
Definition gvcjob.h:319
obj_state_t * obj
Definition gvcjob.h:269
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
ingroup plugin_api
Definition gvplugin.h:35
union obj_state_s::@89 u
node_t * n
Definition gvcjob.h:188
double x
Definition geom.h:29
double y
Definition geom.h:29
const char * name
Definition usershape.h:54
FILE * f
Definition usershape.h:58
void(* datafree)(usershape_t *us)
Definition usershape.h:65
size_t datasize
Definition usershape.h:64
bool must_inline
Definition usershape.h:56
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
@ FT_PS
Definition usershape.h:26
@ FT_EPS
Definition usershape.h:26