Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
gvloadimage_lasi.cpp
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 <cstdio>
14#include <cstdlib>
15#include <sys/stat.h>
16#include <sys/types.h>
17#ifdef HAVE_SYS_MMAN_H
18#include <sys/mman.h>
19#endif
20
21#include <cgraph/agxbuf.h>
22#include <common/render.h>
23#include <common/utils.h>
24#include <gvc/gvio.h>
26
27typedef enum {
30
31static void ps_freeimage(usershape_t *us) {
32#ifdef HAVE_SYS_MMAN_H
33 munmap(us->data, us->datasize);
34#else
35 delete[] us->data;
36#endif
37}
38
39extern "C" {
40
42static void lasi_loadimage_ps(GVJ_t *job, usershape_t *us, boxf b, bool) {
43 assert(job);
44 assert(us);
45 assert(us->name);
46
47 if (us->data) {
48 if (us->datafree != ps_freeimage) {
49 us->datafree(us); // free incompatible cache data
50 us->data = nullptr;
51 us->datafree = nullptr;
52 us->datasize = 0;
53 }
54 }
55
56 if (!us->data) { // read file into cache
57 int fd;
58 struct stat statbuf;
59
61 return;
62 fd = fileno(us->f);
63 switch (us->type) {
64 case FT_PS:
65 case FT_EPS:
66 fstat(fd, &statbuf);
67 us->datasize = statbuf.st_size;
68#ifdef HAVE_SYS_MMAN_H
69 us->data = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
70 if (us->data == MAP_FAILED)
71 us->data = nullptr;
72#else
73 us->data = new char[statbuf.st_size];
74 fread(us->data, 1, (size_t)statbuf.st_size, us->f);
75#endif
76 us->must_inline = true;
77 break;
78 default:
79 break;
80 }
81 if (us->data)
84 }
85
86 if (us->data) {
87 gvprintf(job, "gsave %g %g translate newpath\n", b.LL.x - (double)(us->x),
88 b.LL.y - (double)(us->y));
89 if (us->must_inline)
90 epsf_emit_body(job, us);
91 else
92 gvprintf(job, "user_shape_%d\n", us->macro_id);
93 gvprintf(job, "grestore\n");
94 }
95}
96}
97
99
100extern "C" {
101
103 {FORMAT_PS_PS, "eps:lasi", -5, &engine_ps, nullptr},
104 {FORMAT_PS_PS, "ps:lasi", -5, &engine_ps, nullptr},
105 {0, nullptr, 0, nullptr, nullptr}};
106}
void gvusershape_file_release(usershape_t *us)
bool gvusershape_file_access(usershape_t *us)
void gvprintf(GVJ_t *job, const char *format,...)
Definition gvdevice.c:394
static gvloadimage_engine_t engine_ps
gvplugin_installed_t gvloadimage_lasi_types[]
static void ps_freeimage(usershape_t *us)
static void lasi_loadimage_ps(GVJ_t *job, usershape_t *us, boxf b, bool)
usershape described by a postscript file
@ FORMAT_PS_PS
void epsf_emit_body(GVJ_t *job, usershape_t *us)
Definition geom.h:41
pointf LL
Definition geom.h:41
ingroup plugin_api
Definition gvplugin.h:35
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