/* usershape described by a postscript file */ static void core_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, bool filled) { FILE *out; assert(job); assert(us); assert(us->name); assert(us->f); out = job->output_file; assert(out); if (us->data) { if (us->datafree != ps_freeimage) { us->datafree(us); /* free incompatible cache data */ us->data = NULL; us->datafree = NULL; us->datasize = 0; } } if (!us->data) { /* read file into cache */ int fd = fileno(us->f); struct stat statbuf; fseek(us->f, 0, SEEK_SET); switch (us->type) { case FT_PS: case FT_EPS: fstat(fd, &statbuf); us->datasize = statbuf.st_size; #if HAVE_SYS_MMAN_H us->data = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); #else us->data = malloc(statbuf.st_size); read(fd, us->data, statbuf.st_size); #endif us->must_inline = true; break; default: break; } if (us->data) us->datafree = ps_freeimage; } if (us->data) { fprintf(out, "gsave %g %g translate newpath\n", b.LL.x - us->x, b.LL.y - us->y); if (us->must_inline) epsf_emit_body(us, out); else fprintf(out, "user_shape_%d\n", us->macro_id); fprintf(out, "grestore\n"); } }
/* usershape described by a postscript file */ static void lasi_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, boolean filled) { assert(job); assert(us); assert(us->name); if (us->data) { if (us->datafree != ps_freeimage) { us->datafree(us); /* free incompatible cache data */ us->data = NULL; us->datafree = NULL; us->datasize = 0; } } if (!us->data) { /* read file into cache */ int fd; struct stat statbuf; if (!gvusershape_file_access(us)) return; fd = fileno(us->f); switch (us->type) { case FT_PS: case FT_EPS: fstat(fd, &statbuf); us->datasize = statbuf.st_size; #if HAVE_SYS_MMAN_H us->data = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); #else us->data = malloc(statbuf.st_size); read(fd, us->data, statbuf.st_size); #endif us->must_inline = TRUE; break; default: break; } if (us->data) us->datafree = ps_freeimage; gvusershape_file_release(us); } if (us->data) { gvprintf(job, "gsave %g %g translate newpath\n", b.LL.x - (double)(us->x), b.LL.y - (double)(us->y)); if (us->must_inline) epsf_emit_body(job, us); else gvprintf(job, "user_shape_%d\n", us->macro_id); gvprintf(job, "grestore\n"); } }