3 This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
5 Copyright (C) 2002-2012 by Jin-Hwan Cho and Shunsaku Hirata,
6 the dvipdfmx project team.
8 Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
42 #include "pdfximage.h"
53 spc_handler_postscriptbox (struct spc_env *spe, struct spc_arg *ap)
57 char filename[256], *fullname;
63 if (ap->curptr >= ap->endptr) {
64 spc_warn(spe, "No width/height/filename given for postscriptbox special.");
68 /* input is not NULL terminated */
69 len = (int) (ap->endptr - ap->curptr);
71 memcpy(buf, ap->curptr, len);
74 transform_info_clear(&ti);
77 if (sscanf(buf, "{%lfpt}{%lfpt}{%255[^}]}",
78 &ti.width, &ti.height, filename) != 3) {
79 spc_warn(spe, "Syntax error in postscriptbox special?");
82 ap->curptr = ap->endptr;
84 ti.width *= 72.0 / 72.27;
85 ti.height *= 72.0 / 72.27;
87 fullname = kpse_find_pict(filename);
89 spc_warn(spe, "Image file \"%s\" not found.", filename);
93 fp = MFOPEN(fullname, FOPEN_R_MODE);
95 spc_warn(spe, "Could not open image file: %s", fullname);
101 ti.flags |= (INFO_HAS_WIDTH|INFO_HAS_HEIGHT);
104 const char *p = mfgets(buf, 512, fp);
107 if (mps_scan_bbox(&p, p + strlen(p), &ti.bbox) >= 0) {
108 ti.flags |= INFO_HAS_USER_BBOX;
114 form_id = pdf_ximage_findresource(filename, 0, NULL);
116 spc_warn(spe, "Failed to load image file: %s", filename);
120 pdf_dev_put_image(form_id, &ti, spe->x_user, spe->y_user);
126 spc_handler_null (struct spc_env *spe, struct spc_arg *args)
128 args->curptr = args->endptr;
133 static struct spc_handler misc_handlers[] = {
134 {"postscriptbox", spc_handler_postscriptbox},
135 {"landscape", spc_handler_null}, /* handled at bop */
136 {"papersize", spc_handler_null}, /* handled at bop */
137 {"src:", spc_handler_null}, /* simply ignore */
138 {"pos:", spc_handler_null}, /* simply ignore */
139 {"om:", spc_handler_null} /* simply ignore */
144 spc_misc_check_special (const char *buffer, long size)
146 const char *p, *endptr;
152 skip_white(&p, endptr);
153 size = (long) (endptr - p);
155 i < sizeof(misc_handlers)/sizeof(struct spc_handler); i++) {
156 if (size >= strlen(misc_handlers[i].key) &&
157 !strncmp(p, misc_handlers[i].key,
158 strlen(misc_handlers[i].key))) {
167 spc_misc_setup_handler (struct spc_handler *handle,
168 struct spc_env *spe, struct spc_arg *args)
173 ASSERT(handle && spe && args);
175 skip_white(&args->curptr, args->endptr);
178 while (args->curptr < args->endptr &&
179 isalpha(args->curptr[0])) {
183 if (args->curptr < args->endptr &&
184 args->curptr[0] == ':') {
188 keylen = (int) (args->curptr - key);
194 i < sizeof(misc_handlers)/sizeof(struct spc_handler); i++) {
195 if (keylen == strlen(misc_handlers[i].key) &&
196 !strncmp(key, misc_handlers[i].key, keylen)) {
198 skip_white(&args->curptr, args->endptr);
200 args->command = misc_handlers[i].key;
202 handle->key = "???:";
203 handle->exec = misc_handlers[i].exec;