| 1 |
/* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. |
| 2 |
|
| 3 |
Copyright (C) 2002-2020 by Jin-Hwan Cho and Shunsaku Hirata, |
| 4 |
the dvipdfmx project team. |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program; if not, write to the Free Software |
| 18 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifdef HAVE_CONFIG_H |
| 22 |
#include <config.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "system.h" |
| 28 |
#include "mem.h" |
| 29 |
#include "error.h" |
| 30 |
|
| 31 |
#include "dpxutil.h" |
| 32 |
#include "pdfparse.h" |
| 33 |
|
| 34 |
#include "specials.h" |
| 35 |
|
| 36 |
#include "spc_util.h" |
| 37 |
#include "spc_dvipdfmx.h" |
| 38 |
|
| 39 |
static int |
| 40 |
spc_handler_null (struct spc_env *spe, struct spc_arg *args) |
| 41 |
{ |
| 42 |
args->curptr = args->endptr; |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
static int |
| 48 |
spc_handler_dvipdfmx_catch_phantom (struct spc_env *spe, struct spc_arg *args) |
| 49 |
{ |
| 50 |
int mode, error; |
| 51 |
|
| 52 |
skip_white(&args->curptr, args->endptr); |
| 53 |
{ |
| 54 |
pdf_obj *b = parse_pdf_boolean(&args->curptr, args->endptr); |
| 55 |
if (!b) { |
| 56 |
WARN("A boolean value expected but not found..."); |
| 57 |
return -1; |
| 58 |
} |
| 59 |
mode = pdf_boolean_value(b); |
| 60 |
pdf_release_obj(b); |
| 61 |
} |
| 62 |
spc_set_linkmode(spe, mode); |
| 63 |
|
| 64 |
skip_white(&args->curptr, args->endptr); |
| 65 |
if (mode == 1 && args->curptr < args->endptr) { |
| 66 |
transform_info ti; |
| 67 |
|
| 68 |
transform_info_clear(&ti); |
| 69 |
error = spc_util_read_dimtrns(spe, &ti, args, 0); |
| 70 |
if (error) |
| 71 |
return -1; |
| 72 |
if (ti.flags & INFO_HAS_HEIGHT) { |
| 73 |
spc_set_phantom(spe, ti.height, ti.depth); |
| 74 |
} |
| 75 |
skip_white(&args->curptr, args->endptr); |
| 76 |
} |
| 77 |
|
| 78 |
return 0; |
| 79 |
} |
| 80 |
|
| 81 |
static struct spc_handler dvipdfmx_handlers[] = { |
| 82 |
{"config", spc_handler_null}, /* handled at bop */ |
| 83 |
{"catch_phantom", spc_handler_dvipdfmx_catch_phantom}, |
| 84 |
}; |
| 85 |
|
| 86 |
int |
| 87 |
spc_dvipdfmx_check_special (const char *buf, int len) |
| 88 |
{ |
| 89 |
int r = 0; |
| 90 |
const char *p, *endptr; |
| 91 |
|
| 92 |
p = buf; |
| 93 |
endptr = p + len; |
| 94 |
|
| 95 |
skip_white(&p, endptr); |
| 96 |
if (p + strlen("dvipdfmx:") <= endptr && |
| 97 |
!memcmp(p, "dvipdfmx:", strlen("dvipdfmx:"))) { |
| 98 |
r = 1; |
| 99 |
} |
| 100 |
|
| 101 |
return r; |
| 102 |
} |
| 103 |
|
| 104 |
int |
| 105 |
spc_dvipdfmx_setup_handler (struct spc_handler *sph, |
| 106 |
struct spc_env *spe, struct spc_arg *ap) |
| 107 |
{ |
| 108 |
int error = -1, i; |
| 109 |
char *q; |
| 110 |
|
| 111 |
ASSERT(sph && spe && ap); |
| 112 |
|
| 113 |
skip_white(&ap->curptr, ap->endptr); |
| 114 |
if (ap->curptr + strlen("dvipdfmx:") >= ap->endptr || |
| 115 |
memcmp(ap->curptr, "dvipdfmx:", strlen("dvipdfmx:"))) { |
| 116 |
spc_warn(spe, "Not dvipdfmx: special???"); |
| 117 |
return -1; |
| 118 |
} |
| 119 |
ap->curptr += strlen("dvipdfmx:"); |
| 120 |
|
| 121 |
skip_white(&ap->curptr, ap->endptr); |
| 122 |
q = parse_c_ident(&ap->curptr, ap->endptr); |
| 123 |
if (q) { |
| 124 |
for (i = 0; |
| 125 |
i < sizeof(dvipdfmx_handlers) / sizeof(struct spc_handler); i++) { |
| 126 |
if (!strcmp(q, dvipdfmx_handlers[i].key)) { |
| 127 |
ap->command = dvipdfmx_handlers[i].key; |
| 128 |
sph->key = "dvipdfmx:"; |
| 129 |
sph->exec = dvipdfmx_handlers[i].exec; |
| 130 |
skip_white(&ap->curptr, ap->endptr); |
| 131 |
error = 0; |
| 132 |
break; |
| 133 |
} |
| 134 |
} |
| 135 |
RELEASE(q); |
| 136 |
} |
| 137 |
|
| 138 |
return error; |
| 139 |
} |