summaryrefslogtreecommitdiff
path: root/dviware/dvi2qms/qmsdev.c
blob: 4c6afde8c722adde5de2f17d9434bc26e9f86a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* qmsdev.c The qms output driver for dviqms program.
 * Copyright 1985 Massachusetts Institute of Technology.
 * Author: cjl@oz
 */

#include <stdio.h>
#include "dev.h"

#define DEV_DPI             300 /* Device dots per inch */
#define DEV_XOFFSET	    300
#define DEV_YOFFSET	    300

FILE *dev_out;
long dev_h,dev_v;
unsigned long dev_options;
char dev_hex[] = "0123456789ABCDEF";

dev_setc(ch,xsize)
     unsigned long ch;
     int xsize;
{
  if (ch < '\040' || ch == '^' || ch == '\177') {
    putc('^',dev_out);
    putc('$',dev_out);
    putc(dev_hex[(ch >> 4) & 017],dev_out);
    putc(dev_hex[ch & 017],dev_out);
  } else putc(ch,dev_out);
  dev_h += xsize;
}

dev_position(x,y)
     long x,y;
{
  if (dev_h != x) fprintf(dev_out,"^IH%04.4d",(dev_h = x) + DEV_XOFFSET);
  if (dev_v != y) fprintf(dev_out,"^IV%04.4d",(dev_v = y) + DEV_YOFFSET);
}

dev_draw_box(h,w)
     long h,w;
{
  fprintf(dev_out,"^JR-%04.4d^LS%04.4d%04.4d",h,w,h);
  dev_v -= h;
  dev_h += w;
}

dev_eop()
{
  fprintf(dev_out,"^G^-\f");
  fflush(dev_out);
  fprintf(dev_out,"^IH%04.4d^IV%04.4d",DEV_XOFFSET,DEV_YOFFSET);
  dev_h = dev_v = 0;
}

#define QUIC_ON		"\r^PY^-\r"
#define QUIC_OFF	"\r^-^PN^-\r"
#define DEFAULT_FONT	"^IS%05.5d^-"
#define DELETE_FONTS	"^DFEA^G^-"
#define CLEAR_OVERLAYS	"^DOC^Z^-"
#define SYNTAX		"^ISYNTAX%1.1d%1.1d%1.1d%1.1d%1.1d^-"
#define PORTRAIT	"^IOP^-"
#define LANDSCAPE	"^IOL^-"
#define V_MARGINS	"^IMV%04.4d%04.4d^-"
#define H_MARGINS	"^IMH%04.4d%04.4d^-"
#define CHAR_SP		"^IC%04.4d^-"
#define LINE_SP		"^IL%04.4d^-"

hard_init()
{
  fprintf(dev_out,QUIC_ON);		/* Turn on QUIC */
  fprintf(dev_out,DELETE_FONTS);	/* Delete all downloaded fonts */
  fprintf(dev_out,CLEAR_OVERLAYS);	/* Clear all overlays */
  fprintf(dev_out,DEFAULT_FONT,10);	/* Select the font I like */
  soft_init();
}

soft_init()
{
  fprintf(dev_out,QUIC_ON);		/* Turn on QUIC */
  fprintf(dev_out,SYNTAX,0,0,0,1,0);	/* Ensure correct SYNTAX */
  if (dev_options & DEV_INIT_LANDSCAPE) {
    fprintf(dev_out,LANDSCAPE);		/* Landscape page orientation */
    fprintf(dev_out,V_MARGINS,0,2550);	/* Vertical margins */
    fprintf(dev_out,H_MARGINS,0,4200);	/* Horizontal margins */
  } else {
    fprintf(dev_out,PORTRAIT);		/* Portrait page orientation */
    fprintf(dev_out,V_MARGINS,0,4200);	/* Vertical margins */
    fprintf(dev_out,H_MARGINS,0,2550);	/* Horizontal margins */
  }
  fprintf(dev_out,CHAR_SP,0);		/* Turn off char spacing */
  fprintf(dev_out,LINE_SP,0);		/* Turn off line spacing */
  page_init();
}

page_init()
{
  fprintf(dev_out,"^IH%04.4d^IV%04.4d",DEV_XOFFSET,DEV_YOFFSET);
  dev_h = dev_v = 0;
}     

dev_init(f,options,dpi)
     FILE *f;
     unsigned long options;
     long *dpi;
{
  dev_out = f;
  *dpi = DEV_DPI;
  dev_options = options;
  hard_init();
}

dev_term()
{
  fprintf(dev_out,QUIC_OFF);
  fflush(dev_out);
}


dev_print_log(f)
     FILE *f;
{
  register int ch;

  if (dev_h || dev_v) putc('\f',dev_out);
  fprintf(dev_out,V_MARGINS,100,3300);	/* Vertical margins */
  fprintf(dev_out,H_MARGINS,100,2550);	/* Horizontal margins */
  fprintf(dev_out,DEFAULT_FONT,10);	/* Select the font I like */
  fprintf(dev_out,"^IH%04.4d^IV%04.4d",100,100);
  fprintf(dev_out,QUIC_OFF);
  while (!ferror(f) && (ch = getc(f)) != EOF) {
    if (ch == '\n') putc('\r',dev_out);
    if (ch == '^') putc(ch,dev_out);
    putc(ch,dev_out);
  }
  putc('\f',dev_out);
  fflush(dev_out);
  fprintf(dev_out,QUIC_ON);
}

dev_special(nchars,f)
     int nchars;
     FILE *f;
{
  while (nchars-- > 0) putc(getc(f),dev_out);
  soft_init();
}