Jspice3
hplaser.c File Reference
#include "spice.h"
#include "plotdev.h"
Include dependency graph for hplaser.c:

Go to the source code of this file.

Data Structures

struct  hptext
 
struct  hplaser
 

Macros

#define ror(x, n)   ((x >> n) | (x << (8-n)))
 
#define swap(a, b)   {int t=a; a=b; b=t;}
 
#define OFFSETX   0
 
#define OFFSETY   90
 
#define RESOL   150
 

Functions

int HP_Init ()
 
int HP_NewViewport (GRAPH *graph)
 
int HP_Close ()
 
int HP_Halt ()
 
int HP_Pixel (int x, int y)
 
int HP_Line (int x1, int y1, int x2, int y2)
 
int HP_Box (int x1, int y1, int x2, int y2)
 
int HP_Arc (int x0, int y0, int radius, double theta1, double theta2)
 
int HP_Polygon (POLYGON *p)
 
int HP_Text (char *text, int x, int y)
 
int HP_DefineLinestyle (int linestyleid, int mask)
 
int HP_SetLinestyle (int linestyleid)
 

Variables

static FILE * plotfile
 

Macro Definition Documentation

#define OFFSETX   0

Definition at line 37 of file hplaser.c.

#define OFFSETY   90

Definition at line 38 of file hplaser.c.

#define RESOL   150

Definition at line 41 of file hplaser.c.

#define ror (   x,
 
)    ((x >> n) | (x << (8-n)))

Definition at line 33 of file hplaser.c.

#define swap (   a,
 
)    {int t=a; a=b; b=t;}

Definition at line 34 of file hplaser.c.

Function Documentation

int HP_Arc ( int  x0,
int  y0,
int  radius,
double  theta1,
double  theta2 
)

Definition at line 269 of file hplaser.c.

273 {
274  return (0);
275 }
int HP_Box ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 255 of file hplaser.c.

258 {
259  HP_Line(x1,y1,x1,y2);
260  HP_Line(x1,y2,x2,y2);
261  HP_Line(x2,y2,x2,y1);
262  HP_Line(x2,y1,x1,y1);
263  return (0);
264 }
int HP_Line(int x1, int y1, int x2, int y2)
Definition: hplaser.c:199
int HP_Close ( )

Definition at line 113 of file hplaser.c.

115 {
116  return (0);
117 }
int HP_DefineLinestyle ( int  linestyleid,
int  mask 
)

Definition at line 312 of file hplaser.c.

315 {
316  struct hplaser *hp = (struct hplaser *)currentgraph->devdep;
317 
318  if (linestyleid) {
319  hp->linestyle_stored = mask;
320  hp->linestyle = mask;
321  }
322 }
unsigned char linestyle
Definition: hplaser.c:29
if(TDesc==NULL)
Definition: cd.c:1326
char * devdep
Definition: ftegraph.h:144
GRAPH * currentgraph
Definition: graphdb.c:21
unsigned char linestyle_stored
Definition: hplaser.c:30
int HP_Halt ( )

Definition at line 121 of file hplaser.c.

123 {
124  struct hplaser *hp = (struct hplaser *)currentgraph->devdep;
125  struct hptext *old;
126  char *buf, *rgen, *c;
127  int len, i;
128 
129  /* dump the stuff */
130 
131  /* reset printer
132  * top margin 10
133  * X cursor position OFFSETX
134  * Y cursor position OFFSETY
135  * resolution RESOL dpi
136  * start raster graphics at current position
137  */
138  fprintf(plotfile,
139  "\033E\033&l0E\033*p%dX\033*p%dY\033*t%dR\033*r1A",
141 
142  buf = tmalloc(hp->bytpline+8);
143  sprintf(buf,"\033*b%dW",hp->bytpline);
144  len = strlen(buf);
145  c = buf + len;
146 
147  rgen = hp->base;
148  for (i = 0; i <= hp->maxy; i++) {
149  memcpy(c,rgen,hp->bytpline);
150  rgen += hp->bytpline;
151 
152  if (fwrite(buf,1,hp->bytpline+len,plotfile) != hp->bytpline+len) {
153  break;
154  }
155 
156  }
157  /* end raster graphics */
158  fprintf(plotfile,"\033*rB");
159 
160  /* now for the text */
161 
162  while (hp->textlist) {
163  /* x position, y position, text */
164  fprintf(plotfile,"\033*p%dX\033*p%dY%s",
165  hp->textlist->x,hp->textlist->y,hp->textlist->text);
166  txfree(hp->textlist->text);
167  old = hp->textlist;
168  hp->textlist = hp->textlist->next;
169  txfree((char*)old);
170  }
171 
172  /* form feed
173  * reset printer
174  */
175  fprintf(plotfile,"\033*rB\014\033E");
176 
177  txfree(buf);
178  txfree(hp->base);
179  fclose(plotfile);
180  return (0);
181 }
int y
Definition: hplaser.c:18
static char buf[MAXPROMPT]
Definition: arg.c:18
#define OFFSETY
Definition: hplaser.c:38
Definition: hplaser.c:16
#define RESOL
Definition: hplaser.c:41
#define OFFSETX
Definition: hplaser.c:37
char * tmalloc()
void txfree()
struct hptext * next
Definition: hplaser.c:20
struct hptext * textlist
Definition: hplaser.c:28
int bytpline
Definition: hplaser.c:24
char * text
Definition: hplaser.c:19
char * devdep
Definition: ftegraph.h:144
static FILE * plotfile
Definition: hplaser.c:14
Definition: cddefs.h:177
int x
Definition: hplaser.c:17
char * base
Definition: hplaser.c:27
int maxy
Definition: hplaser.c:26
GRAPH * currentgraph
Definition: graphdb.c:21
int HP_Init ( )

Definition at line 44 of file hplaser.c.

46 {
48  dispdev->numcolors = 2;
49 
50  /* 8" X 10.5" drawable area */
51  dispdev->width = 8*RESOL;
52  dispdev->height = 10*RESOL + RESOL/2;
53  return (0);
54 }
int numlinestyles
Definition: plotdev.h:67
#define RESOL
Definition: hplaser.c:41
DISPDEVICE * dispdev
Definition: display.c:112
int height
Definition: plotdev.h:66
int numcolors
Definition: plotdev.h:67
int width
Definition: plotdev.h:66
int HP_Line ( int  x1,
int  y1,
int  x2,
int  y2 
)

Definition at line 199 of file hplaser.c.

202 {
203 
204  struct hplaser *hp = (struct hplaser *)currentgraph->devdep;
205  int dx, dy, dy2, errterm = 0, next, lcnt;
206  char *rgen;
207  unsigned char cbuf, left, right;
208 
209  if (x2 < x1) {
210  swap(x1,x2);
211  swap(y1,y2);
212  }
213  dx = x2 - x1;
214 
215  next = hp->bytpline;
216  dy = y1 - y2;
217 
218  lcnt = hp->maxy - y1;
219  rgen = hp->base + (x1 >> 3) + lcnt*next;
220  left = 0x80 >> ((lcnt+x1) & 7);
221  right = hp->linestyle;
222 
223  if (y1 < y2) {
224  next = -next;
225  dy = -dy;
226  }
227  dy2 = dy;
228 
229  cbuf = 0x80 >> (x1 & 7);
230 
231  for (dy++; dy; dy--) {
232  errterm += dx;
233  if (errterm <= 0) {
234  if (left & right) *rgen |= cbuf;
235  rgen += next;
236  left = ror(left,1);
237  continue;
238  }
239  while (errterm > 0 && x1 != x2) {
240  if (left & right) *rgen |= cbuf;
241  left = ror(left,1);
242  cbuf = ror(cbuf,1);
243  if (cbuf & 0x80) rgen++;
244  x1++;
245  errterm -= dy2;
246  }
247  rgen += next;
248  left = ror(left,1);
249  }
250  return (0);
251 }
unsigned char linestyle
Definition: hplaser.c:29
if(TDesc==NULL)
Definition: cd.c:1326
int bytpline
Definition: hplaser.c:24
char * devdep
Definition: ftegraph.h:144
#define swap(a, b)
Definition: hplaser.c:34
#define ror(x, n)
Definition: hplaser.c:33
char * base
Definition: hplaser.c:27
int maxy
Definition: hplaser.c:26
GRAPH * currentgraph
Definition: graphdb.c:21
int HP_NewViewport ( GRAPH graph)

Definition at line 58 of file hplaser.c.

62 {
63  struct hplaser *hp;
64  int bpline;
65 
66  plotfile = fopen((char*)graph->devdep, "wb");
67  if (!plotfile) {
68  perror(graph->devdep);
69  graph->devdep = (char *) NULL;
70  return (1);
71  }
72  graph->devdep = tmalloc(sizeof(struct hplaser));
73  hp = (struct hplaser*)graph->devdep;
74 
75  switch (graph->graphtype) {
76  default:
77  case GR_PLOT:
78  case GR_GRAF:
79  case GR_MPLT:
80  /* square plotting area */
81  graph->absolute.width = dispdev->width;
82  graph->absolute.height = dispdev->width;
83  break;
84  case GR_SCED:
85  /* full page plot */
86  graph->absolute.width = dispdev->width;
87  graph->absolute.height = dispdev->height;
88  break;
89  }
90  /* bytes per line */
91  bpline = (graph->absolute.width + 7)/8;
92 
93  hp->base = malloc(graph->absolute.height*bpline);
94  if (hp->base == NULL) {
95  internalerror("Not enough memory for raster conversion");
96  return (1);
97  }
98  memset(hp->base,0,graph->absolute.height*bpline);
99 
100  graph->fontwidth = 15;
101  graph->fontheight = 30;
102 
103  hp->bytpline = bpline;
104  hp->maxx = graph->absolute.width - 1;
105  hp->maxy = graph->absolute.height - 1;
106  hp->linestyle = 0xff;
107  hp->linestyle_stored = 0xcc;
108  return (0);
109 }
struct graph::@2 absolute
int maxx
Definition: hplaser.c:25
unsigned char linestyle
Definition: hplaser.c:29
internalerror(char *message)
Definition: error.c:91
DISPDEVICE * dispdev
Definition: display.c:112
char * malloc()
int height
Definition: ftegraph.h:45
#define GR_SCED
Definition: ftegraph.h:23
char * tmalloc()
int fontwidth
Definition: ftegraph.h:82
#define NULL
Definition: spdefs.h:121
int graphtype
Definition: ftegraph.h:31
int fontheight
Definition: ftegraph.h:82
void perror()
int bytpline
Definition: hplaser.c:24
char * devdep
Definition: ftegraph.h:144
static FILE * plotfile
Definition: hplaser.c:14
int height
Definition: plotdev.h:66
char * base
Definition: hplaser.c:27
#define GR_PLOT
Definition: ftegraph.h:20
#define GR_MPLT
Definition: ftegraph.h:22
int width
Definition: plotdev.h:66
int maxy
Definition: hplaser.c:26
int width
Definition: ftegraph.h:45
unsigned char linestyle_stored
Definition: hplaser.c:30
#define GR_GRAF
Definition: ftegraph.h:21
int HP_Pixel ( int  x,
int  y 
)

Definition at line 185 of file hplaser.c.

188 {
189  unsigned char c;
190  struct hplaser *hp = (struct hplaser *)currentgraph->devdep;
191 
192  c = 0x80 >> (x & 7);
193  *(hp->base + ((x >> 3) + (hp->maxy-y)*hp->bytpline)) |= c;
194  return (0);
195 }
static double c
Definition: vectors.c:16
int bytpline
Definition: hplaser.c:24
char * devdep
Definition: ftegraph.h:144
char * base
Definition: hplaser.c:27
int maxy
Definition: hplaser.c:26
GRAPH * currentgraph
Definition: graphdb.c:21
int HP_Polygon ( POLYGON p)

Definition at line 279 of file hplaser.c.

282 {
283  int i, n = 2*p->nvertices - 2;
284 
285  for (i = 0; i < n; i += 2)
286  HP_Line(p->xy[i],p->xy[i+1],p->xy[i+2],p->xy[i+3]);
287 
288  return (0);
289 }
long * xy
Definition: plotdev.h:16
int nvertices
Definition: plotdev.h:15
int HP_Line(int x1, int y1, int x2, int y2)
Definition: hplaser.c:199
int HP_SetLinestyle ( int  linestyleid)

Definition at line 326 of file hplaser.c.

329 {
330  struct hplaser *hp = (struct hplaser *)currentgraph->devdep;
331 
332  if (linestyleid)
333  hp->linestyle = hp->linestyle_stored;
334  else
335  hp->linestyle = 0xff;
336  return (0);
337 }
unsigned char linestyle
Definition: hplaser.c:29
if(TDesc==NULL)
Definition: cd.c:1326
char * devdep
Definition: ftegraph.h:144
GRAPH * currentgraph
Definition: graphdb.c:21
unsigned char linestyle_stored
Definition: hplaser.c:30
int HP_Text ( char *  text,
int  x,
int  y 
)

Definition at line 293 of file hplaser.c.

297 {
298  struct hplaser *hp = (struct hplaser *)currentgraph->devdep;
299  struct hptext *hpt;
300 
301  hpt = (struct hptext *)tmalloc(sizeof(struct hptext));
302  hpt->x = x*(300/RESOL) + OFFSETX;
303  hpt->y = (hp->maxy - y)*(300/RESOL) + OFFSETY;
304  hpt->text = copy(text);
305  hpt->next = hp->textlist;
306  hp->textlist = hpt;
307  return (0);
308 }
#define OFFSETY
Definition: hplaser.c:38
Definition: hplaser.c:16
#define RESOL
Definition: hplaser.c:41
#define OFFSETX
Definition: hplaser.c:37
char * copy()
char * tmalloc()
struct hptext * textlist
Definition: hplaser.c:28
char * devdep
Definition: ftegraph.h:144
int maxy
Definition: hplaser.c:26
GRAPH * currentgraph
Definition: graphdb.c:21

Variable Documentation

FILE* plotfile
static

Definition at line 14 of file hplaser.c.