~ubuntu-branches/ubuntu/hardy/texmacs/hardy

« back to all changes in this revision

Viewing changes to src/Window/PsDevice/printer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Treinen
  • Date: 2004-04-19 20:34:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040419203400-g4e34ih0315wcn8v
Tags: upstream-1.0.3-R2
ImportĀ upstreamĀ versionĀ 1.0.3-R2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : printer.cpp
 
4
* DESCRIPTION: Abstract device for printing post-script graphics
 
5
* COPYRIGHT  : (C) 1999  Joris van der Hoeven
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license and comes WITHOUT
 
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
 
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
 
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
11
******************************************************************************/
 
12
 
 
13
#include "PsDevice/printer.hpp"
 
14
#include "file.hpp"
 
15
#include "image_files.hpp"
 
16
#include "tex_files.hpp"
 
17
#include "analyze.hpp"
 
18
#include "iterator.hpp"
 
19
#include "merge_sort.hpp"
 
20
#include "scheme.hpp"
 
21
 
 
22
string PS_LINE ("ln");
 
23
string PS_FILL ("fl");
 
24
string PS_ARC ("ac");
 
25
string PS_POL_START ("sp");
 
26
string PS_POL_NEXT ("np");
 
27
string PS_POL_END ("ep");
 
28
string PS1 ("u");
 
29
string PS2 ("z");
 
30
 
 
31
/******************************************************************************
 
32
* constructors and destructors
 
33
******************************************************************************/
 
34
 
 
35
printer_rep::printer_rep (
 
36
  display dis2, url ps_file_name2, int dpi2, int nr_pages2,
 
37
  string page_type2, bool landscape2, double paper_w2, double paper_h2):
 
38
    dis (dis2), ps_file_name (ps_file_name2), dpi (dpi2),
 
39
    nr_pages (nr_pages2), page_type (page_type2),
 
40
    landscape (landscape2), paper_w (paper_w2), paper_h (paper_h2),
 
41
    linelen (0), fg (-1), bg (-1), ncols (0),
 
42
    lw (-1), nwidths (0), cfn (""), nfonts (0),
 
43
    xpos (0), ypos (0), tex_flag (false),
 
44
    defs ("?"), tex_chars ("?"), tex_width ("?"),
 
45
    tex_fonts ("?"), tex_font_chars (array<int>(0))    
 
46
{
 
47
  true_type =
 
48
    as_string (call ("get-preference", string ("font type"))) == "True type";
 
49
 
 
50
  black     = dis->black;
 
51
  white     = dis->white;
 
52
  red       = dis->red;
 
53
  green     = dis->green;
 
54
  blue      = dis->blue;
 
55
  yellow    = dis->yellow;
 
56
  magenta   = dis->magenta;
 
57
  orange    = dis->orange;
 
58
  brown     = dis->brown;
 
59
  pink      = dis->pink;
 
60
  light_grey= dis->light_grey;
 
61
  grey      = dis->grey;
 
62
  dark_grey = dis->dark_grey;
 
63
 
 
64
  string tex_pro, special_pro, color_pro, texps_pro;
 
65
  load_string ("$TEXMACS_PATH/misc/convert/tex.pro", tex_pro, true);
 
66
  load_string ("$TEXMACS_PATH/misc/convert/special.pro", special_pro, true);
 
67
  load_string ("$TEXMACS_PATH/misc/convert/color.pro", color_pro, true);
 
68
  load_string ("$TEXMACS_PATH/misc/convert/texps.pro", texps_pro, true);
 
69
  set_clipping (0, (int) (-(dpi*PIXEL*paper_h)/2.54),
 
70
                (int) ((dpi*PIXEL*paper_w)/2.54), 0);
 
71
  
 
72
  prologue   << "%!PS-Adobe-2.0\n"
 
73
             << "%%Creator: TeXmacs-" TEXMACS_VERSION "\n"
 
74
             << "%%Title: " << as_string (ps_file_name) << "\n"
 
75
             << "%%Pages: " << as_string (nr_pages) << "\n"
 
76
             << "%%PageOrder: Ascend\n";
 
77
  if (page_type != "user")
 
78
    prologue << "%%DocumentPaperSizes: " << page_type << "\n";
 
79
  if (landscape)
 
80
    prologue << "%%BoundingBox: 0 0 "
 
81
             << as_string ((int) (28.36*paper_h+ 0.5)) << " "
 
82
             << as_string ((int) (28.36*paper_w+ 0.5)) << "\n"
 
83
             << "%%Orientation: Landscape\n";
 
84
  else
 
85
    prologue << "%%BoundingBox: 0 0 "
 
86
             << as_string ((int) (28.36*paper_w+ 0.5)) << " "
 
87
             << as_string ((int) (28.36*paper_h+ 0.5)) << "\n";
 
88
  prologue   << "%%EndComments\n\n"
 
89
             << tex_pro << "\n"
 
90
             << special_pro << "\n"
 
91
             << texps_pro << "\n"
 
92
             << "TeXDict begin\n"
 
93
             << as_string ((int) (1864680.0*paper_w+ 0.5)) << " "
 
94
             << as_string ((int) (1864680.0*paper_h+ 0.5)) << " 1000 "
 
95
             << as_string (dpi) << " " << as_string (dpi)
 
96
             << " (TeXmacs) @start\n";
 
97
 
 
98
  define (PS_LINE, string ("/pt4 X /pt3 X /pt2 X /pt1 X\n") *
 
99
          string ("newpath pt1 pt2 moveto pt3 pt4 lineto stroke"));
 
100
  define (PS_FILL, string ("/pt4 X /pt3 X /pt2 X /pt1 X\n") *
 
101
          string ("newpath pt1 pt2 moveto pt3 pt2 lineto ") *
 
102
          string ("pt3 pt4 lineto pt1 pt4 lineto pt1 pt2 eofill stroke"));
 
103
  define (PS_ARC, string ("/a2 X /a1 X /r2 X /r1 X /pt2 X /pt1 X\n") *
 
104
          string ("newpath pt1 pt2 r1 r2 a1 a2 ellipse stroke"));
 
105
  define (PS_POL_START, string ("/pt2 X /pt1 X\n") *
 
106
          string ("newpath pt1 pt2 moveto"));
 
107
  define (PS_POL_NEXT, string ("/pt2 X /pt1 X\n") *
 
108
          string ("pt1 pt2 lineto"));
 
109
  define (PS_POL_END, string ("closepath eofill"));
 
110
  define (PS1, string ("gsave"));
 
111
  define (PS2, string ("1 -1 scale show grestore"));
 
112
 
 
113
  cur_page= 0;
 
114
  next_page ();
 
115
}
 
116
 
 
117
printer_rep::~printer_rep () {
 
118
  next_page ();
 
119
  body << "\n%%Trailer\n"
 
120
       << "end\n"
 
121
       << "userdict /end-hook known{end-hook} if\n"
 
122
       << "%%EOF\n";
 
123
 
 
124
  generate_tex_fonts ();
 
125
  prologue << "end\n"
 
126
           << "%%EndProlog\n\n"
 
127
           << "%%BeginSetup\n"
 
128
           << "%%Feature: *Resolution " << as_string (dpi) << "dpi\n"
 
129
           << "TeXDict begin\n";
 
130
  if (page_type != "user")
 
131
    prologue << "%%PaperSize: " << page_type << "\n";
 
132
  if (landscape)
 
133
    prologue << "@landscape\n";
 
134
  prologue << "%%EndSetup\n";
 
135
 
 
136
  string ps_text= prologue * "\n" * body;
 
137
  save_string (ps_file_name, ps_text);
 
138
}
 
139
 
 
140
int
 
141
printer_rep::get_type () {
 
142
  return PS_DEVICE_PRINTER;
 
143
}
 
144
 
 
145
/******************************************************************************
 
146
* subroutines for printing
 
147
******************************************************************************/
 
148
 
 
149
void
 
150
printer_rep::next_page () {
 
151
  if (cur_page > 0) print ("eop\n");
 
152
  if (cur_page >= nr_pages) return;
 
153
  cur_page++;
 
154
  body << "\n%%Page: " << as_string (cur_page) << " "
 
155
       << as_string (cur_page) << "\n"
 
156
       << as_string (cur_page) << " "
 
157
       << as_string (cur_page-1) << " bop\n";
 
158
 
 
159
  fg  = -1;
 
160
  bg  = -1;
 
161
  lw  = -1;
 
162
  cfn = "";
 
163
  xpos= 0;
 
164
  ypos= 0;
 
165
 }
 
166
 
 
167
void
 
168
printer_rep::define (string s, string defn) {
 
169
  if (defs->contains (s)) return;
 
170
  defs (defn)= s;
 
171
  prologue << "/" << s << " {" << defn << "} N\n";
 
172
}
 
173
 
 
174
void
 
175
printer_rep::sep () {
 
176
  if ((N(body) > 0) &&
 
177
      (body [N(body)-1] != ')') &&
 
178
      (body [N(body)-1] != '\n')) {
 
179
    body << " ";
 
180
    linelen++;
 
181
    tex_flag= false;
 
182
  }
 
183
}
 
184
 
 
185
void
 
186
printer_rep::cr () {
 
187
  body << "\n";
 
188
  linelen= 0;
 
189
  tex_flag= false;
 
190
}
 
191
 
 
192
void
 
193
printer_rep::print (string s) {
 
194
  if (N(s)==0) return;
 
195
  if ((linelen>0) && (linelen+N(s)>79)) {
 
196
    body << "\n";
 
197
    linelen= 0;
 
198
    tex_flag= false;
 
199
  }
 
200
  else if (s[0]!='(') sep ();
 
201
  if (tex_flag && (s[0]=='(')) {
 
202
    body->resize (N(body)-2);
 
203
    linelen -= 2;
 
204
    s= s (1,N(s));
 
205
  }
 
206
  body << s;
 
207
  linelen += N(s);
 
208
  tex_flag= false;
 
209
}
 
210
 
 
211
void
 
212
printer_rep::print (SI x, SI y) {
 
213
  x += ox; y += oy;
 
214
  if (x>=0) x= x/PIXEL; else x= (x-PIXEL+1)/PIXEL;
 
215
  if (y>=0) y= y/PIXEL; else y= (y-PIXEL+1)/PIXEL;
 
216
  print (as_string (x-dpi));
 
217
  print (as_string (-y-dpi));
 
218
}
 
219
 
 
220
void
 
221
printer_rep::move_to (SI x, SI y) {
 
222
  x += ox; y += oy;
 
223
  if (x>=0) x= x/PIXEL; else x= (x-PIXEL+1)/PIXEL;
 
224
  if (y>=0) y= y/PIXEL; else y= (y-PIXEL+1)/PIXEL;
 
225
  if (tex_flag && (xpos==x) && (ypos==y)) return;
 
226
  if (tex_flag && (ypos==y)) {
 
227
    body->resize (N(body)-1);
 
228
    linelen -= 1;
 
229
    tex_flag= false;
 
230
 
 
231
    int diff= x-xpos;
 
232
    if ((diff>=-4) && (diff<=4)) print (string ((char) ('p'+diff)));
 
233
    else {
 
234
      print (as_string (diff));
 
235
      print ("b");
 
236
    }
 
237
    xpos= x;
 
238
    return;
 
239
  }
 
240
  xpos= x; ypos= y;
 
241
  print (as_string (x-dpi));
 
242
  print (as_string (-y-dpi));
 
243
  print ("a");
 
244
}
 
245
 
 
246
void
 
247
printer_rep::select_color (color c) {
 
248
  int r, g, b;
 
249
  dis->get_rgb (c, r, g, b);
 
250
  r= 10000+ ((r*1000)/255);
 
251
  g= 10000+ ((g*1000)/255);
 
252
  b= 10000+ ((b*1000)/255);
 
253
  string rr= as_string (r); rr= rr(1,2) * "." * rr(2,5);
 
254
  string gg= as_string (g); gg= gg(1,2) * "." * gg(2,5);
 
255
  string bb= as_string (b); bb= bb(1,2) * "." * bb(2,5);
 
256
  string s = rr * " " * gg * " " * bb * " setrgbcolor";
 
257
  if (!defs->contains (s)) {
 
258
    define ("C" * as_string (ncols), s);
 
259
    ncols++;
 
260
  }
 
261
  print (defs[s]);
 
262
}
 
263
 
 
264
void
 
265
printer_rep::select_line_width (SI w) {
 
266
  w= w/PIXEL; if (w<1) w=1;
 
267
  string s = as_string (w) * " setlinewidth";
 
268
  if (!defs->contains (s)) {
 
269
    define ("W" * as_string (nwidths), s);
 
270
    nwidths++;
 
271
  }
 
272
  print (defs[s]);
 
273
}
 
274
 
 
275
/******************************************************************************
 
276
* subroutines for fonts
 
277
******************************************************************************/
 
278
 
 
279
static string
 
280
prepare_text (string s) {
 
281
  int i;
 
282
  string r;
 
283
  for (i=0; i<N(s); i++) {
 
284
    int c= ((unsigned char) s[i]);
 
285
    if ((s[i]=='(') || (s[i]==')') || (s[i]=='\\'))
 
286
      r << '\\' << s[i];
 
287
    else if ((c <= 32) || (c >= 128)) {
 
288
      r << '\\';
 
289
      r << ('0' + (c >> 6));
 
290
      r << ('0' + ((c >> 3) & 7));
 
291
      r << ('0' + (c & 7));
 
292
    }
 
293
    else r << s[i];
 
294
  }
 
295
  return r;
 
296
}
 
297
 
 
298
void
 
299
printer_rep::select_tex_font (string name) {
 
300
  if (cfn==name) return;
 
301
  cfn= name;
 
302
  print (tex_fonts [name]);
 
303
}
 
304
 
 
305
/******************************************************************************
 
306
* make tex characters and fonts
 
307
******************************************************************************/
 
308
 
 
309
static char* hex_string= "0123456789ABCDEF";
 
310
 
 
311
void
 
312
printer_rep::make_tex_char (string name, unsigned char c, bitmap_char bmc) {
 
313
  string char_name (name * "-" * as_string ((int) c));
 
314
  if (tex_chars->contains (char_name)) return;
 
315
  if (!tex_fonts->contains (name)) {
 
316
    tex_fonts (name)= "F" * as_string (nfonts);
 
317
    tex_font_chars (name)= array<int> (0);
 
318
    nfonts++;
 
319
  }
 
320
  tex_font_chars (name) << ((int) c);
 
321
 
 
322
  string hex_code;
 
323
  int i, j, count=0, cur= 0;
 
324
  for (j=0; j < bmc->height; j++)
 
325
    for (i=0; i < ((bmc->width+7) & (-8)); i++) {
 
326
      cur= cur << 1;
 
327
      if ((i<bmc->width) && (bmc->get_x(i,j)>0)) cur++;
 
328
      count++;
 
329
      if (count==4) {
 
330
        hex_code << hex_string[cur];
 
331
        cur  = 0;
 
332
        count= 0;
 
333
      }
 
334
    }
 
335
 
 
336
  int d1= bmc->width;
 
337
  int d2= bmc->height;
 
338
  int d3= 130+ bmc->xoff;
 
339
  int d4= 126+ bmc->yoff;
 
340
  int d5= bmc->lwidth;
 
341
  if ((d1<256) && (d2<256) && (d3<256) && (d4<256) && (d5<256)) {
 
342
    hex_code << as_hexadecimal (d1, 2) << as_hexadecimal (d2, 2)
 
343
             << as_hexadecimal (d3, 2) << as_hexadecimal (d4, 2)
 
344
             << as_hexadecimal (d5, 2);
 
345
    hex_code= "<" * hex_code * ">";
 
346
  }
 
347
  else {
 
348
    hex_code= "[<" * hex_code * ">";
 
349
    hex_code << as_string (d1) << " " << as_string (d2) << " "
 
350
             << as_string (d3) << " " << as_string (d4) << " "
 
351
             << as_string (d5) << " ";
 
352
  }
 
353
 
 
354
  tex_chars (char_name)= hex_code;
 
355
  tex_width (char_name)= as_string (d5);
 
356
}
 
357
 
 
358
void
 
359
printer_rep::generate_tex_fonts () {
 
360
  hashset<string> done;
 
361
  iterator<string> it= iterate (tex_fonts);
 
362
  while (it->busy ()) {
 
363
    string fn_name= it->next ();
 
364
    array<int> a= tex_font_chars [fn_name];
 
365
    merge_sort (a);
 
366
 
 
367
    int i, d, l;
 
368
    string name = tex_fonts [fn_name], ttf;
 
369
    int    pos  = search_forwards (".", fn_name);
 
370
    string root = (pos==-1? fn_name: fn_name (0, pos));
 
371
    if (true_type && (pos!=-1) && ends (fn_name, "pk"))
 
372
      ttf= pk_to_true_type (root);
 
373
 
 
374
    if (ttf != "") {
 
375
      root= upcase_all (root);
 
376
      if (!done->contains (root)) {
 
377
        prologue << "%%BeginFont: " << root << "\n";
 
378
        prologue << ttf;
 
379
        prologue << "\n%%EndFont\n";
 
380
        done->insert (root);
 
381
      }
 
382
 
 
383
      array<string> cum;
 
384
      cum << "{}" * as_string (N(a));
 
385
      for (i=0; i<N(a); i++) {
 
386
        string w= tex_width [fn_name * "-" * as_string (a[i])];
 
387
        d= (i==0? a[0]: (a[i]-a[i-1]-1));
 
388
        if (d>0) cum << as_string (d) * "[";
 
389
        cum << w * " ";
 
390
      }
 
391
      d= 255-a[i-1];
 
392
      if (d>0) cum << as_string (d) * "[";
 
393
 
 
394
      int szpos = pos-1;
 
395
      while ((szpos>0) && is_numeric (fn_name[szpos-1])) szpos--;
 
396
      double sz = as_double (fn_name (szpos, pos));
 
397
      double dpi= as_double (fn_name (pos+1, N(fn_name)-2));
 
398
      string mag= as_string (83.022 * (sz/10.0) * (dpi/600.0));
 
399
 
 
400
      string fdef;
 
401
      for (i=N(cum)-1; i>=0; i--) fdef << cum[i];
 
402
      fdef= "/" * name * " " * fdef * " " * mag * " /" * root * " rf";
 
403
      for (i=0, l=0; i<N(fdef); i++, l++)
 
404
        if ((l<70) || (fdef[i]!=' ')) prologue << fdef[i];
 
405
        else { prologue << '\n'; l=-1; }
 
406
      prologue << "\n";
 
407
    }
 
408
    else {
 
409
      prologue << "/" << tex_fonts [fn_name]
 
410
               << " " << as_string (N(a))
 
411
               << " " << as_string (a[N(a)-1]+1) << " df\n";
 
412
      for (i=0; i<N(a); i++) {
 
413
        int end;
 
414
        string hex_code= tex_chars [fn_name * "-" * as_string (a[i])];
 
415
        for (end=1; end < N(hex_code); end++)
 
416
          if (hex_code[end-1]=='>') break;
 
417
        string after= hex_code (end, N(hex_code));
 
418
        if ((i>0) && (a[i]==(a[i-1]+1))) after << "I";
 
419
        else after << as_string (a[i]) << " D";
 
420
        if (i==(N(a)-1)) after << " E";
 
421
        hex_code= hex_code (0, end);
 
422
      
 
423
        int j, l, n= N(hex_code);
 
424
        for (j=0; j<n; j+=79) {
 
425
          if (n < (j+79)) prologue << hex_code (j, n);
 
426
          else prologue << hex_code (j, j+79) << "\n";
 
427
        }
 
428
        l= 79-(n%79);
 
429
        if (l<N(after)) prologue << "\n";
 
430
        prologue << after << "\n";
 
431
      }
 
432
    }
 
433
  }
 
434
}
 
435
 
 
436
/******************************************************************************
 
437
* graphical routines
 
438
******************************************************************************/
 
439
 
 
440
color
 
441
printer_rep::rgb (int r, int g, int b) {
 
442
  return dis->rgb (r, g, b);
 
443
}
 
444
 
 
445
void
 
446
printer_rep::get_rgb (color col, int& r, int& g, int& b) {
 
447
  dis->get_rgb (col, r, g, b);
 
448
}
 
449
 
 
450
color
 
451
printer_rep::get_color () {
 
452
  return fg;
 
453
}
 
454
 
 
455
color
 
456
printer_rep::get_background () {
 
457
  return bg;
 
458
}
 
459
 
 
460
void
 
461
printer_rep::set_color (color c) {
 
462
  if (fg==c) return;
 
463
  fg= c;
 
464
  select_color (c);
 
465
}
 
466
 
 
467
void
 
468
printer_rep::set_background (color c) {
 
469
  if (bg==c) return;
 
470
  bg= c;
 
471
}
 
472
 
 
473
void
 
474
printer_rep::draw (int ch, bitmap_font fn, SI x, SI y) {
 
475
  bitmap_char bmc= fn->get(ch);
 
476
  if (nil (bmc)) return;
 
477
  string name= fn->res_name;
 
478
  unsigned char c= ch;
 
479
  if (true_type) ec_to_cm (name, c);
 
480
  make_tex_char (name, c, bmc);
 
481
  select_tex_font (name);
 
482
  move_to (x, y);
 
483
  print ("(" * prepare_text (string ((char) c)) * ")p");
 
484
  tex_flag= true;
 
485
  xpos += bmc->lwidth;
 
486
}
 
487
 
 
488
void
 
489
printer_rep::set_line_style (SI w, int type) {
 
490
  (void) type;
 
491
  if (lw == w) return;
 
492
  lw= w;
 
493
  select_line_width (w);
 
494
}
 
495
 
 
496
void
 
497
printer_rep::line (SI x1, SI y1, SI x2, SI y2) {
 
498
  print (x1, y1);
 
499
  print (x2, y2);
 
500
  print (PS_LINE);
 
501
}
 
502
 
 
503
void
 
504
printer_rep::clear (SI x1, SI y1, SI x2, SI y2) {
 
505
  select_color (bg);
 
506
  print (x1, y1);
 
507
  print (x2, y2);
 
508
  print (PS_FILL);
 
509
  select_color (fg);
 
510
}
 
511
 
 
512
void
 
513
printer_rep::fill (SI x1, SI y1, SI x2, SI y2) {
 
514
  if ((x1<x2) && (y1<y2)) {
 
515
    print (x1, y1);
 
516
    print (x2, y2);
 
517
    print (PS_FILL);
 
518
  }
 
519
}
 
520
 
 
521
void
 
522
printer_rep::arc (SI x1, SI y1, SI x2, SI y2, int alpha, int delta) {
 
523
  print ((x1+x2)/2, (y1+y2)/2);
 
524
  print (as_string ((x2-x1)/(2*PIXEL)));
 
525
  print (as_string ((y1-y2)/(2*PIXEL)));
 
526
  print (as_string (((double) alpha)/64));
 
527
  print (as_string (((double) (alpha+delta))/64));
 
528
  print (PS_ARC);
 
529
}
 
530
 
 
531
void
 
532
printer_rep::polygon (array<SI> x, array<SI> y) {
 
533
  int i, n= N(x);
 
534
  if ((N(y) != n) || (n<1)) return;
 
535
  print (x[0], y[0]);
 
536
  print (PS_POL_START);
 
537
  for (i=1; i<n; i++) {
 
538
    print (x[i], y[i]);
 
539
    print (PS_POL_NEXT);
 
540
  }
 
541
  print (PS_POL_END);
 
542
}
 
543
 
 
544
void
 
545
printer_rep::xpm (url file_name, SI x, SI y) {
 
546
  (void) file_name; (void) x; (void) y;
 
547
  fatal_error ("Not yet implemented", "printer_rep::xpm");
 
548
}
 
549
 
 
550
/*
 
551
string
 
552
incorporate_postscript (string s) {
 
553
  int i;
 
554
  string r;
 
555
  for (i=0; i<N(s); )
 
556
    if (s[i] == '%') {
 
557
      for (; (i<N(s)) && (s[i]!='\n'); i++);
 
558
      if (i<N(s)) i++;
 
559
    }
 
560
    else {
 
561
      for (; (i<N(s)) && (s[i]!='\n'); ) r << s[i++];
 
562
      if (i<N(s)) { r << s[i++]; }
 
563
    }
 
564
  return r;
 
565
}
 
566
*/
 
567
 
 
568
void
 
569
printer_rep::postscript (
 
570
  url image, SI w, SI h, SI x, SI y,
 
571
  int x1, int y1, int x2, int y2)
 
572
{
 
573
  double sc_x= (72.0/dpi) * ((double) (w/PIXEL)) / ((double) (x2-x1));
 
574
  double sc_y= (72.0/dpi) * ((double) (h/PIXEL)) / ((double) (y2-y1));
 
575
  cr ();
 
576
  cr ();
 
577
 
 
578
  print (x, y);
 
579
  print ("a");
 
580
  print ("currentpoint");
 
581
  print ("currentpoint");
 
582
  print ("translate");
 
583
  print (as_string (sc_x));
 
584
  print (as_string (sc_y));
 
585
  print ("scale");
 
586
  print ("neg");
 
587
  print ("exch");
 
588
  print ("neg");
 
589
  print ("exch");
 
590
  print ("translate");
 
591
  print (x, y);
 
592
  print ("a");
 
593
  cr ();
 
594
  /* Black Black 248 3155 a currentpoint currentpoint translate
 
595
     0.37114 0.37114 scale neg exch neg exch translate 248 3155 a */
 
596
 
 
597
  print ("@beginspecial");
 
598
  print (as_string (x1));
 
599
  print ("@llx");
 
600
  print (as_string (y1));
 
601
  print ("@lly");
 
602
  print (as_string (x2));
 
603
  print ("@urx");
 
604
  print (as_string (y2));
 
605
  print ("@ury");
 
606
  print (as_string (10*(x2-x1)));
 
607
  print ("@rwi");
 
608
  print ("@clip");
 
609
  print ("@setspecial");
 
610
  cr ();
 
611
  /* @beginspecial 0 @llx 0 @lly 613.291260 @urx 613.291260 @ury 6110 @rwi
 
612
     @clip @setspecial */
 
613
  
 
614
  string ps_image= ps_load (image);
 
615
  string imtext= is_ramdisc (image)? "inline image": as_string (image);
 
616
  body << "%%BeginDocument: " << imtext  << "\n";
 
617
  body << ps_image; // incorporate_postscript (ps_image);
 
618
  body << "%%EndDocument";
 
619
  cr ();
 
620
 
 
621
  print ("@endspecial");
 
622
  print (x, y);
 
623
  print ("a");
 
624
  print ("currentpoint");
 
625
  print ("currentpoint");
 
626
  print ("translate");
 
627
  print (as_string (1/sc_x));
 
628
  print (as_string (1/sc_y));
 
629
  print ("scale");
 
630
  print ("neg");
 
631
  print ("exch");
 
632
  print ("neg");
 
633
  print ("exch");
 
634
  print ("translate");
 
635
  print (x, y);
 
636
  print ("a");
 
637
  cr ();
 
638
  cr ();
 
639
  
 
640
  /* @endspecial 248 3155 a currentpoint currentpoint translate
 
641
     1 0.37114 div 1 0.37114 div scale neg exch neg exch translate
 
642
     248 3155 a 660 3073 a ... */
 
643
 
 
644
  (void) w; (void) h;
 
645
}
 
646
 
 
647
bool
 
648
printer_rep::check_event (int type) {
 
649
  (void) type;
 
650
  return false;
 
651
}
 
652
 
 
653
void
 
654
printer_rep::apply_shadow (SI x1, SI y1, SI x2, SI y2) {
 
655
  (void) x1; (void) y1; (void) x2; (void) y2;
 
656
}
 
657
 
 
658
/******************************************************************************
 
659
* user interface
 
660
******************************************************************************/
 
661
 
 
662
ps_device
 
663
printer (display dis, url ps_file_name, int dpi, int nr_pages,
 
664
         string page_type, bool landscape, double paper_w, double paper_h)
 
665
{
 
666
  return new printer_rep (dis, ps_file_name, dpi, nr_pages,
 
667
                          page_type, landscape, paper_w, paper_h);
 
668
}