Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sp-epsf.c File Reference
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mdvi.h"
#include "private.h"
+ Include dependency graph for sp-epsf.c:

Go to the source code of this file.

Data Structures

struct  EpsfBox
 

Macros

#define LLX   0
 
#define LLY   1
 
#define URX   2
 
#define URY   3
 
#define RWI   4
 
#define RHI   5
 
#define HOFF   6
 
#define VOFF   7
 
#define HSIZE   8
 
#define VSIZE   9
 
#define HSCALE   10
 
#define VSCALE   11
 
#define ANGLE   12
 
#define CLIP   13
 
#define NKEYS   (sizeof(keys) / sizeof(keys[0]))
 

Functions

void epsf_special __PROTO ((DviContext *dvi, char *prefix, char *arg))
 
static char * parse_epsf_special (EpsfBox *box, char **ret, char *prefix, char *arg)
 
void epsf_special (DviContext *dvi, char *prefix, char *arg)
 

Macro Definition Documentation

#define ANGLE   12

Definition at line 50 of file sp-epsf.c.

#define CLIP   13

Definition at line 51 of file sp-epsf.c.

#define HOFF   6

Definition at line 44 of file sp-epsf.c.

#define HSCALE   10

Definition at line 48 of file sp-epsf.c.

#define HSIZE   8

Definition at line 46 of file sp-epsf.c.

#define LLX   0

Definition at line 38 of file sp-epsf.c.

#define LLY   1

Definition at line 39 of file sp-epsf.c.

#define NKEYS   (sizeof(keys) / sizeof(keys[0]))
#define RHI   5

Definition at line 43 of file sp-epsf.c.

#define RWI   4

Definition at line 42 of file sp-epsf.c.

#define URX   2

Definition at line 40 of file sp-epsf.c.

#define URY   3

Definition at line 41 of file sp-epsf.c.

#define VOFF   7

Definition at line 45 of file sp-epsf.c.

#define VSCALE   11

Definition at line 49 of file sp-epsf.c.

#define VSIZE   9

Definition at line 47 of file sp-epsf.c.

Function Documentation

void epsf_special __PROTO ( (DviContext *dvi, char *prefix, char *arg)  )
void epsf_special ( DviContext dvi,
char *  prefix,
char *  arg 
)

Definition at line 235 of file sp-epsf.c.

236 {
237  char *file;
238  char *special;
239  char *psfile;
240  char *tmp;
241  EpsfBox box = {0, 0, 0, 0};
242  int x, y;
243  int w, h;
244  double xf, vf;
245  struct stat buf;
246 
247  file = parse_epsf_special(&box, &special, prefix, arg);
248  if (file != NULL)
249  mdvi_free (special);
250 
251  xf = dvi->params.dpi * dvi->params.mag / (72.0 * dvi->params.hshrink);
252  vf = dvi->params.vdpi * dvi->params.mag / (72.0 * dvi->params.vshrink);
253  w = FROUND(box.bw * xf);
254  h = FROUND(box.bh * vf);
255  x = FROUND(box.ox * xf) + dvi->pos.hh;
256  y = FROUND(box.oy * vf) + dvi->pos.vv - h + 1;
257 
258  if (!file || !dvi->device.draw_ps) {
259  dvi->device.draw_rule (dvi, x, y, w, h, 0);
260  return;
261  }
262 
263  if (file[0] == '/') { /* Absolute path */
264  if (stat (file, &buf) == 0)
265  dvi->device.draw_ps (dvi, file, x, y, w, h);
266  else
267  dvi->device.draw_rule (dvi, x, y, w, h, 0);
268  return;
269  }
270 
271  tmp = mdvi_strrstr (dvi->filename, "/");
272  if (tmp) { /* Document directory */
273  int path_len = strlen (dvi->filename) - strlen (tmp + 1);
274  int file_len = strlen (file);
275 
276  psfile = mdvi_malloc (path_len + file_len + 1);
277  psfile[0] = '\0';
278  strncat (psfile, dvi->filename, path_len);
279  strncat (psfile, file, file_len);
280 
281  if (stat (psfile, &buf) == 0) {
282  dvi->device.draw_ps (dvi, psfile, x, y, w, h);
283  mdvi_free (psfile);
284 
285  return;
286  }
287 
288  mdvi_free (psfile);
289  }
290 
291  psfile = mdvi_build_path_from_cwd (file);
292  if (stat (psfile, &buf) == 0) { /* Current working dir */
293  dvi->device.draw_ps (dvi, psfile, x, y, w, h);
294  mdvi_free (psfile);
295 
296  return;
297  }
298 
299  mdvi_free (psfile);
300 
301  psfile = kpse_find_pict (file);
302  if (psfile) { /* kpse */
303  dvi->device.draw_ps (dvi, psfile, x, y, w, h);
304  } else {
305  dvi->device.draw_rule(dvi, x, y, w, h, 0);
306  }
307 
308  free (psfile);
309 }
static char* parse_epsf_special ( EpsfBox box,
char **  ret,
char *  prefix,
char *  arg 
)
static

Definition at line 56 of file sp-epsf.c.

58 {
59  static struct {
60  char *name;
61  int has_arg;
62  char *value;
63  } keys[] = {
64  {"llx", 1, "0"},
65  {"lly", 1, "0"},
66  {"urx", 1, "0"},
67  {"ury", 1, "0"},
68  {"rwi", 1, "0"},
69  {"rhi", 1, "0"},
70  {"hoffset", 1, "0"},
71  {"voffset", 1, "0"},
72  {"hsize", 1, "612"},
73  {"vsize", 1, "792"},
74  {"hscale", 1, "100"},
75  {"vscale", 1, "100"},
76  {"angle", 1, "0"},
77  {"clip", 0, "0"}
78  };
79 #define NKEYS (sizeof(keys) / sizeof(keys[0]))
80  char *ptr;
81  char *filename;
82  double value[NKEYS];
83  Uchar present[NKEYS];
84  Buffer buffer;
85  char *name;
86  int i;
87  double originx;
88  double originy;
89  double hsize;
90  double vsize;
91  double hscale;
92  double vscale;
93 
94  /* this special has the form
95  * ["]file.ps["] [key=valye]*
96  */
97 
98  /* scan the filename */
99  while(*arg == ' ' || *arg == '\t')
100  arg++;
101 
102  /* make a copy of the string */
103  ptr = arg;
104 
105  if(*ptr == '"')
106  for(name = ++ptr; *ptr && *ptr != '"'; ptr++);
107  else
108  for(name = ptr; *ptr && *ptr != ' ' && *ptr != '\t'; ptr++);
109  if(ptr == name)
110  return NULL;
111  *ptr++ = 0;
112  filename = name;
113 
114  /* reset values to defaults */
115  for(i = 0; i < NKEYS; i++) {
116  value[i] = atof(keys[i].value);
117  present[i] = 0;
118  }
119 
120  buff_init(&buffer);
121  buff_add(&buffer, "@beginspecial ", 0);
122 
123  while(*ptr) {
124  const char *keyname;
125  char *val;
126  char *p;
127 
128  while(*ptr == ' ' || *ptr == '\t')
129  ptr++;
130  keyname = ptr;
131 
132  /* get the whole key=value pair */
133  for(; *ptr && *ptr != ' ' && *ptr != '\t'; ptr++);
134 
135  if(*ptr) *ptr++ = 0;
136  /* now we shouldn't touch `ptr' anymore */
137 
138  /* now work on this pair */
139  p = strchr(keyname, '=');
140  if(p == NULL)
141  val = NULL;
142  else {
143  *p++ = 0;
144  if(*p == '"') {
145  val = ++p;
146  /* skip until closing quote */
147  while(*p && *p != '"')
148  p++;
149  if(*p != '"')
150  mdvi_warning(
151  _("%s: malformed value for key `%s'\n"),
152  filename, keyname);
153  } else
154  val = p;
155  }
156 
157  /* lookup the key */
158  for(i = 0; i < NKEYS; i++)
159  if(STRCEQ(keys[i].name, keyname))
160  break;
161  if(i == NKEYS) {
162  mdvi_warning(_("%s: unknown key `%s' ignored\n"),
163  filename, keyname);
164  continue;
165  }
166  if(keys[i].has_arg && val == NULL) {
167  mdvi_warning(_("%s: no argument for key `%s', using defaults\n"),
168  filename, keyname);
169  val = keys[i].value;
170  } else if(!keys[i].has_arg && val) {
171  mdvi_warning(_("%s: argument `%s' ignored for key `%s'\n"),
172  filename, val, keyname);
173  val = NULL;
174  }
175  if(val)
176  value[i] = atof(val);
177 
178  /* put the argument */
179  buff_add(&buffer, val, 0);
180  buff_add(&buffer, " @", 2);
181  buff_add(&buffer, keyname, 0);
182  buff_add(&buffer, " ", 1);
183 
184  /* remember that this option was given */
185  present[i] = 0xff;
186  }
187  buff_add(&buffer, " @setspecial", 0);
188 
189  /* now compute the bounding box (code comes from dvips) */
190  originx = 0;
191  originy = 0;
192  hscale = 1;
193  vscale = 1;
194  hsize = 0;
195  vsize = 0;
196 
197  if(present[HSIZE])
198  hsize = value[HSIZE];
199  if(present[VSIZE])
200  vsize = value[VSIZE];
201  if(present[HOFF])
202  originx = value[HOFF];
203  if(present[VOFF])
204  originy = value[VOFF];
205  if(present[HSCALE])
206  hscale = value[HSCALE] / 100.0;
207  if(present[VSCALE])
208  vscale = value[VSCALE] / 100.0;
209  if(present[URX] && present[LLX])
210  hsize = value[URX] - value[LLX];
211  if(present[URY] && present[LLY])
212  vsize = value[URY] - value[LLY];
213  if(present[RWI] || present[RHI]) {
214  if(present[RWI] && !present[RHI])
215  hscale = vscale = value[RWI] / (10.0 * hsize);
216  else if(present[RHI] && !present[RWI])
217  hscale = vscale = value[RHI] / (10.0 * vsize);
218  else {
219  hscale = value[RWI] / (10.0 * hsize);
220  vscale = value[RHI] / (10.0 * vsize);
221  }
222  }
223 
224  box->ox = originx;
225  box->oy = originy;
226  box->bw = hsize * hscale;
227  box->bh = vsize * vscale;
228  box->angle = value[ANGLE];
229 
230  *ret = buffer.data;
231 
232  return filename;
233 }

+ Here is the caller graph for this function: