2
* Copyright (C) 2000, Matias Atria
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
/* postscript specials */
50
void epsf_special __PROTO((DviContext *dvi, char *prefix, char *arg));
52
/* Note: the given strings are modified in place */
53
static char *parse_epsf_special(EpsfBox *box, char **ret,
54
char *prefix, char *arg)
76
#define NKEYS (sizeof(keys) / sizeof(keys[0]))
92
/* this special has the form
93
* ["]file.ps["] [key=valye]*
96
/* scan the filename */
97
while(*arg == ' ' || *arg == '\t')
100
/* make a copy of the string */
104
for(name = ++ptr; *ptr && *ptr != '"'; ptr++);
106
for(name = ptr; *ptr && *ptr != ' ' && *ptr != '\t'; ptr++);
112
/* reset values to defaults */
113
for(i = 0; i < NKEYS; i++) {
114
value[i] = atof(keys[i].value);
119
buff_add(&buffer, "@beginspecial ", 0);
127
while(*ptr == ' ' || *ptr == '\t')
131
/* get the whole key=value pair */
132
for(; *ptr && *ptr != ' ' && *ptr != '\t'; ptr++);
135
/* now we shouldn't touch `ptr' anymore */
137
/* now work on this pair */
138
p = strchr(keyname, '=');
145
/* skip until closing quote */
146
while(*p && *p != '"')
150
_("%s: malformed value for key `%s'\n"),
157
for(i = 0; i < NKEYS; i++)
158
if(STRCEQ(keys[i].name, keyname))
161
warning(_("%s: unknown key `%s' ignored\n"),
165
if(keys[i].has_arg && val == NULL) {
166
warning(_("%s: no argument for key `%s', using defaults\n"),
169
} else if(!keys[i].has_arg && val) {
170
warning(_("%s: argument `%s' ignored for key `%s'\n"),
171
filename, val, keyname);
175
value[i] = atof(val);
177
/* put the argument */
178
buff_add(&buffer, val, 0);
179
buff_add(&buffer, " @", 2);
180
buff_add(&buffer, keyname, 0);
181
buff_add(&buffer, " ", 1);
183
/* remember that this option was given */
186
buff_add(&buffer, " @setspecial", 0);
188
/* now compute the bounding box (code comes from dvips) */
197
hsize = value[HSIZE];
199
vsize = value[VSIZE];
201
originx = value[HOFF];
203
originy = value[VOFF];
205
hscale = value[HSCALE] / 100.0;
207
vscale = value[VSCALE] / 100.0;
208
if(present[URX] && present[LLX])
209
hsize = value[URX] - value[LLX];
210
if(present[URY] && present[LLY])
211
vsize = value[URY] - value[LLY];
212
if(present[RWI] || present[RHI]) {
213
if(present[RWI] && !present[RHI])
214
hscale = vscale = value[RWI] / (10.0 * hsize);
215
else if(present[RHI] && !present[RWI])
216
hscale = vscale = value[RHI] / (10.0 * vsize);
218
hscale = value[RWI] / (10.0 * hsize);
219
vscale = value[RHI] / (10.0 * vsize);
225
box->bw = hsize * hscale;
226
box->bh = vsize * vscale;
227
box->angle = value[ANGLE];
234
void epsf_special(DviContext *dvi, char *prefix, char *arg)
238
EpsfBox box = {0, 0, 0, 0};
243
file = parse_epsf_special(&box, &special, prefix, arg);
247
* draw the bounding box. Notice that it is in PostScript units,
248
* so we have to convert it into pixels
250
xf = dvi->params.dpi * dvi->params.mag / (72.0 * dvi->params.hshrink);
251
vf = dvi->params.vdpi * dvi->params.mag / (72.0 * dvi->params.vshrink);
252
x = FROUND(box.ox * xf);
253
y = FROUND(box.oy * vf);
254
w = FROUND(box.bw * xf);
255
h = FROUND(box.bh * vf);
256
dvi->device.draw_rule(dvi, dvi->pos.hh + x, dvi->pos.vv + y - h + 1, w, h, 0);