File: pdraw.c

package info (click to toggle)
treetool 2.0.2-1
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 3,460 kB
  • ctags: 2,692
  • sloc: ansic: 26,504; makefile: 212
file content (791 lines) | stat: -rw-r--r-- 16,731 bytes parent folder | download | duplicates (5)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/time.h>

#include "list.h"
#include "generic.h"

#define PAGE_MARGIN_WIDTH 18.0
#define PAGE_MARGIN_HEIGHT 13.0
#define PAGE_FULL_HEIGHT 792.0
#define PAGE_FULL_WIDTH 612.0
#define PAGE_WIDTH (PAGE_FULL_WIDTH-PAGE_MARGIN_WIDTH-PAGE_MARGIN_WIDTH)
#define PAGE_HEIGHT (PAGE_FULL_HEIGHT-PAGE_MARGIN_HEIGHT-PAGE_MARGIN_HEIGHT)

typedef enum {
	pr_line,
	pr_text,
	pr_box,
	pr_circle,
	pr_none
	} print_command;

typedef struct {
	print_command c;	/* type, line, text, box, circle, etc... */
	int printed;		/* 1 if already printed */
	int linewidth;		/* linewidth, if it's a line */
	tcap_style capstyle;/* capstyle for lines */
	int r,g,b;			/* colors */
	int x1, y1, x2, y2;	/* coordinates */
	int sx, sy;			/* origin of text */
	char *s;			/* string for text, must be freed */
	char *fontname;		/* font name for text */
	int fontsize;		/* size for font */
	int macnum;			/* for quickdraw */
	int macstyle;
	} qentryd, *qentry;

#define qIsOnPage (!((q->x1>cr && q->x2>cr) || (q->y1<cb && q->y2<cb) || (q->x2<cl && q->x1<cl) || (q->y2>ct && q->y1>ct)))

static tcanvas printcanvas;
static list printq;
static FILE *outfile;
static tp_type outtype;
static int pw, ph;
static int maxx, maxy, minx, miny;
static int maxset;
static int cl, cr, ct, cb;
static int linewidth;
static int red,green,blue;
static tcap_style capstyle;
static double hres, vres;
static char *filename;

int pdraw_set_noneprinted()
{
	qentry q;

	startlist(printq);
	while((q=listnext(printq))!=NULL)
		q->printed=0;
	return(1);
}

int pdraw_shove_line_PICT(x1, y1, x2, y2, lw, ls)
int x1, y1, x2, y2;
int lw;
tcap_style ls;
{
	/* change linewidth if necessary */
	/* change capstyle if necessary */
	/* print endpoint first, then startpoint */
	x1*=72/hres;
	y1*=72/vres;
	x2*=72/hres;
	y2*=72/vres;
	fprintf(outfile,
		"%c%c%c%c%c%c%c%c%c%c",
		0, 0x20, y1/256, y1%256, x1/256, x1%256,
			y2/256, y2%256, x2/256, x2%256);
}

int pdraw_shove_text_PICT(x1, y1, s)
int x1, y1;
char *s;
{
	int i;
	x1*=72/hres;
	y1*=72/vres;
	fprintf(outfile,
		"%c%c%c%c%c%c%c",
		0, 0x28, y1/256, y1%256, x1/256, x1%256, strlen(s));
	for(i=0;s[i]!='\0';i++)
		fprintf(outfile, "%c", s[i]);
	/* padding after text */
	if(i%2==0)
		fprintf(outfile, "%c", 0);
}

int pdraw_shove_font_PICT(n, s, size)
int n;
int s;
int size;
{
	fprintf(outfile,
		"%c%c%c%c%c%c%c%c%c%c%c%c",
		0, 0x3, 0, n, 0, 0x4, s, 0, 0, 0xd, 0, size);
}

/* size of all data other than actual tree picture data in PICT file */
/* includes header, bounding box, initial drawing opcodes, and ending opcode */
#define HEADERSIZE 564

int pdraw_shove_data_fork()
{
	qentry q;
	list savenode;
	char *cfont;
	int csize;
	int i, j;
	float mx, my;
	char hi, lo;

	int tt, tb, tr, tl;	/* total dimensions, calculated below */

	fprintf(outfile, "Treetool PICT file");
	for(i=strlen("Treetool PICT file");i<512;i++)
		fprintf(outfile, "%c", 0); 		/* application header */

	/* picture size, unimportant in PICT2 */
	fprintf(outfile, "%c%c", 0, 0);

	/* bounding box */
	/* first round to full pages */
	i=PAGE_FULL_HEIGHT;
	miny-=miny%i;
	maxy+=i-(maxy%i);
	i=PAGE_FULL_WIDTH;
	minx-=minx%i;
	maxx+=i-(maxx%i);
	/* next convert to 72bpi */
	miny*=72/vres;
	minx*=72/hres;
	maxy*=72/vres;
	maxx*=72/hres;
	hi=(miny>>8)%256; lo=miny%256;
	fprintf(outfile, "%c%c", hi, lo);
	hi=(minx>>8)%256; lo=minx%256;
	fprintf(outfile, "%c%c", hi, lo);
	hi=(maxy>>8)%256; lo=maxy%256;
	fprintf(outfile, "%c%c", hi, lo);
	hi=(maxx>>8)%256; lo=maxx%256;
	fprintf(outfile, "%c%c", hi, lo);

	/* vers opcode, vers number, header opcode */
	fprintf(outfile, "%c%c%c%c%c%c", 0x00, 0x11, 0x02, 0xff, 0x0c, 0x00);

	/* total size, bounding box, reserved, all -1 */
	for(i=0;i<24;i++)
		fprintf(outfile, "%c", -1);

	/* now ready for opcodes */
	fprintf(outfile, "%c", 0);
	fprintf(outfile, "%c", 0x1e); /* change default hilite */
	fprintf(outfile, "%c", 0); /* change text font */
	fprintf(outfile, "%c", 3);
	fprintf(outfile, "%c", 0);
	fprintf(outfile, "%c", 3);
	fprintf(outfile, "%c", 0); /* change size */
	fprintf(outfile, "%c", 0xd);
	fprintf(outfile, "%c", 0);
	fprintf(outfile, "%c", 12);
	/*fprintf(outfile, "%c", 0);		/* change foreground color */
	/*fprintf(outfile, "%c", 0x1a);*/

	startlist(printq);
	while((q=listnext(printq))!=NULL)
	{
		switch(q->c)
		{
			case pr_line:
				pdraw_shove_line_PICT(q->x1, q->y1, q->x2, q->y2,
					q->linewidth, q->capstyle);
				break;
			case pr_text:
				pdraw_shove_font_PICT(q->macnum, q->macstyle, q->fontsize);
				pdraw_shove_text_PICT(q->sx, q->sy, q->s);
			default:
				break;
		}
	}

	/* finish off with ending opcode */
	fprintf(outfile, "%c%c", 0, 255);
}

int pdraw_shove_q_PICT()
{
	int num_bytes;
	int i;
	char byte3, byte2, byte1, byte0;
	qentry q;

	/* counts up size for mac-binary format, then writes header,
		then calls pdraw_shove_data_fork */
	
	num_bytes=HEADERSIZE;

	startlist(printq);
	while((q=listnext(printq))!=NULL)
	{
		switch(q->c)
		{
			case pr_line:
				num_bytes+=10;				/* for line drawing opcode */
				break;
			case pr_text:
				num_bytes+=12;				/* for font opcode */
				num_bytes+=7+strlen(q->s);	/* for text drawing opcode */
				if(strlen(q->s)%2==0)
					num_bytes++;			/* padding byte */
			default:
				break;
		}
	}

	/* write header */
	fprintf(outfile, "%c", 0);					/* version */
	fprintf(outfile, "%c", strlen(filename));	/* filename length */
	for(i=0;i<63 && filename[i]!='\0';i++)		/* filename */
		fprintf(outfile, "%c", filename[i]);
	for(;i<63;i++)								/* pad to 63 bytes */
		fprintf(outfile, "%c", 0);
	fprintf(outfile, "%s", "PICT");				/* file type */
	fprintf(outfile, "%s", "MDPL");				/* file creator */
	fprintf(outfile, "%c", 0);					/* finder flags */
	fprintf(outfile, "%c", 0);					/* zero byte--unused */
	fprintf(outfile, "%c%c", 0, 0);				/* vertical position */
	fprintf(outfile, "%c%c", 0, 0);				/* horizontal position */
	fprintf(outfile, "%c%c", 0, 0);				/* folder id */
	fprintf(outfile, "%c", 0);					/* protected flag */
	fprintf(outfile, "%c", 0);					/* zero byte--unused */
	byte3=(num_bytes>>24)%256;
	byte2=(num_bytes>>16)%256;
	byte1=(num_bytes>>8)%256;
	byte0=num_bytes%256;
	fprintf(outfile, "%c%c%c%c",
		byte3, byte2, byte1, byte0);			/* data fork length */
	fprintf(outfile, "%c%c%c%c", 0, 0, 0, 0);	/* resource fork length, 0 */
	fprintf(outfile, "%c%c%c%c", 0, 0, 0, 0);	/* creation data */
	fprintf(outfile, "%c%c%c%c", 0, 0, 0, 0);	/* last modified data */
	for(i=0;i<27;i++)
		fprintf(outfile, "%c", 0);				/* zero fill--reserved */
	fprintf(outfile, "%c%c", 0, 0);				/* type and ID */

	/* write PICT fork */
	pdraw_shove_data_fork();

	/* write padding */
	if(num_bytes%128!=0)	/* must pad data fork */
		for(i=0;i<128-(num_bytes%128);i++)
			fprintf(outfile, "%c", 0);


}

pdraw_shove_header(filename, docfonts)
char *filename;
list docfonts;
{
	time_t t;
	char hostname[40];
	char username[15];
	list c;

	fprintf(outfile, "%%!PS-Adobe-3.0\n");
	fprintf(outfile, "%%%%Creator: Treetool1.0\n");
	time(&t);
	fprintf(outfile, "%%%%CreationDate: %s", ctime(&t));
	gethostname(hostname, 40);
	fprintf(outfile, "%%%%For: %s@%s\n", getlogin(), hostname);
	fprintf(outfile, "%%%%Pages: (atend)\n");
	fprintf(outfile, "%%%%Title: %s\n", filename);
	if(!listemptyp(docfonts))
	{
		fprintf(outfile, "%%%%DocumentNeededResources:\n");
		lfor(docfonts, c)
			fprintf(outfile, "%%%%+ font %s\n", nodeobj(c));
	}
	fprintf(outfile, "%%%%EndComments\n");
}

pdraw_shove_docsetup(offx, offy, magx, magy)
double offx, offy, magx, magy;
{
	fprintf(outfile, "%%%%BeginSetup\n");
	fprintf(outfile,
		"/ln { newpath moveto lineto stroke closepath } bind def\n");
	fprintf(outfile,
		"/tx { newpath moveto show closepath } bind def\n");
	fprintf(outfile,
		"/sl { setlinewidth } def\n");
	fprintf(outfile,
		"/sc { setlinecap } def\n");
	fprintf(outfile,
		"/sr { setrgbcolor } def\n");
	fprintf(outfile,
		"/sf { exch findfont exch scalefont setfont } def\n");
	fprintf(outfile,
		"/tr { translate } def\n");
	fprintf(outfile,
		"/sp { 1 sc 1 sl 0.0 0.0 0.0 sr\n");
	fprintf(outfile,
		"\t%.5lf %.5lf tr %.5lf %.5lf scale tr } def\n",
		offx, offy, magx, magy);
	fprintf(outfile, "%%%%EndSetup\n");
}

pdraw_shove_pagesetup(num)
int num;
{
	fprintf(outfile, "%%%%Page: tree %d\n", num);
	fprintf(outfile, "%%%%PageResources: (atend)\n");
	fprintf(outfile, "%%%%BeginPageSetup\n");
	fprintf(outfile, "/pgsave save def\n");
	fprintf(outfile, "%%%%EndPageSetup\n");
}

pdraw_shove_pagetrailer(pagefonts)
list pagefonts;
{
	list c;

	fprintf(outfile, "showpage\n");
	fprintf(outfile, "pgsave restore\n");
	fprintf(outfile, "%%%%PageTrailer\n");
	fprintf(outfile, "%%%%PageResources:\n");
	if(!listemptyp(pagefonts))
		lfor(pagefonts, c)
			fprintf(outfile, "%%%%+ font %s\n", nodeobj(c));
}

pdraw_shove_doctrailer(num)
int num;
{
	fprintf(outfile, "%%%%Trailer\n");
	fprintf(outfile, "%%%%Pages: %d\n", num);
	fprintf(outfile, "%%%%EOF\n");
}

int pdraw_shove_color(r, g, b)
int r, g, b;
{
	double rr, gg, bb;

	red=r;
	green=g;
	blue=b;
	rr=r/65536.0;
	gg=g/65536.0;
	bb=b/65536.0;
	fprintf(outfile, "%.5f %.5f %.5f sr\n",
		rr, gg, bb);
}

int pdraw_shove_line(x1, y1, x2, y2, lw, ls, r, g, b)
int x1, y1, x2, y2;
int lw;
tcap_style ls;
int r, g, b;
{
	/* change linewidth if necessary */
	if(lw!=linewidth)
	{
		linewidth=lw;
		if(linewidth==0)
			linewidth=1;
		fprintf(outfile, "%d sl\n", lw);
	}
	/* change capstyle if necessary */
	if(ls!=capstyle)
	{
		capstyle=ls;
		switch(ls)
		{
			case tcap_butt:
			case tcap_notlast:
				fprintf(outfile, "%d sc\n", 0);
				break;
			case tcap_round:
				fprintf(outfile, "%d sc\n", 1);
				break;
			case tcap_projecting:
				fprintf(outfile, "%d sc\n", 2);
				break;
			case tcap_none:
			default:
				break;
		}
	}
	/* change color if necessary */
	if(r!=red || g!=green || b!=blue)
		pdraw_shove_color(r, g, b);
	/* print endpoint first, then startpoint */
	fprintf(outfile,
		"%d %d %d %d ln\n",
		x2, y2, x1, y1);
}

int pdraw_shove_text(x1, y1, s, r, g, b)
int x1, y1;
char *s;
int r, g, b;
{
	/* change color if necessary */
	if(r!=red || g!=green || b!=blue)
		pdraw_shove_color(r, g, b);
	/* print string first, then point */
	fprintf(outfile,
		"(%s) %d %d tx\n",
		s, x1, y1);
}

int pdraw_shove_font(n, s)
char *n;
int s;
{
	fprintf(outfile,
		"/%s %d sf\n",
		n, s);
}

int pdraw_shove_q()
{
	qentry q;
	list savenode;
	char *cfont;
	int csize;
	int i, j;
	float mx, my;
	list docfonts, cf, cq;
	int pnum;

	int tt, tb, tr, tl;	/* total dimensions, calculated below */

	mx=PAGE_WIDTH/pw;
	my=PAGE_HEIGHT/ph;

	/*fprintf(outfile, "%%! TreeTool print file\n");*/
	/*fprintf(outfile, "%s\n", LINETO);*/
	/*fprintf(outfile, "%s\n", TEXTTO);*/
	/*fprintf(outfile, "1 setlinecap\n");*/
	/*fprintf(outfile, "1 setlinewidth\n");*/

	if(minx>0)
		tl=minx/pw;
	else
		tl=minx/pw-1;
	if(maxx>0)
		tr=maxx/pw;
	else
		tr=maxx/pw-1;
	if(miny>0)
		tb=miny/ph;
	else
		tb=miny/ph-1;
	if(maxy>0)
		tt=maxy/ph;
	else
		tt=maxy/ph-1;

#define thisqentry(c) ((qentry)nodeobj(c))
#define thisfontname(c) ((char *)nodeobj(c))
	
	docfonts=newlist();
	lfor(printq, cq)
		if(thisqentry(cq)->c==pr_text)
		{
			lfor(docfonts, cf)
				if(strcmp(thisfontname(cf), thisqentry(cq)->fontname)==0)
					break;
			if(cf!=NULL)
				addnode(docfonts, thisfontname(cf));
		}
	pdraw_shove_header(filename, docfonts);
	pdraw_shove_docsetup(PAGE_MARGIN_WIDTH, PAGE_MARGIN_HEIGHT, mx, my);
	freelist(docfonts);


	pnum=0;
	for(i=tl;i<=tr;i++)
	for(j=tt;j>=tb;j--)
	{
		pdraw_set_noneprinted();

		/* calculate cl,cr,ct,cb */
		cl=pw*i;
		cr=pw*(i+1);
		cb=ph*j;
		ct=ph*(j+1);

		/* check if any on page */
		startlist(printq);
		while((q=listnext(printq))!=NULL)
			if(qIsOnPage)
				break;


		if(q!=NULL)
		{
			pnum++;
			pdraw_shove_pagesetup(pnum);
			/* we've determined there's something on this page */

			/* translate by the number of pages */
			fprintf(outfile, "%d %d sp\n", -pw*i, -ph*j);
			/* initial linewidth is 1 */
			/* initial cap style is round */
			linewidth=1;
			capstyle=tcap_round;
			red=0;
			green=0;
			blue=0;

			/* print non text */
			startlist(printq);
			while((q=listnext(printq))!=NULL)
			{
				if(qIsOnPage)
					/* on page */
					switch(q->c)
					{
						case pr_line:
							pdraw_shove_line(q->x1, q->y1, q->x2, q->y2,
								q->linewidth, q->capstyle,
								q->r, q->g, q->b);
							break;
						default:
							break;
					}
			}

			/* print text */
			fprintf(outfile, "0 sc\n");

			docfonts=newlist();
			startlist(printq);
			while((q=listnext(printq))!=NULL)
			{
				/* find a text to be printed */
				if(q->c==pr_text && !q->printed)
				{
					if(qIsOnPage)
					{
						/* on page */
						addnode(docfonts, q->fontname);
						pdraw_shove_font(q->fontname, q->fontsize);
						pdraw_shove_text(q->sx, q->sy, q->s,
							q->r, q->g, q->b);
						q->printed=1;
						cfont=q->fontname;
						csize=q->fontsize;
						savenode=listnode(printq);
						/* find all others of this font and size */
						while((q=listnext(printq))!=NULL)
						{
							if(q->c==pr_text && !q->printed)
							{
								if(qIsOnPage)
								{
									/* on page */
									if(strcmp(cfont, q->fontname)==0 &&
											csize==q->fontsize)
									{
										/* same font */
										pdraw_shove_text(q->sx, q->sy, q->s,
											q->r, q->g, q->b);
										q->printed=1;
									} /* if same font and size */

								} /* if on page */
							} /* if pr_text */

						} /* end of search for more of same font */

						setnode(printq, savenode);

					} /* if on page */
				} /* if pr_text, find a text */

			} /* end of print text */

			pdraw_shove_pagetrailer(docfonts);
			freelist(docfonts);
		
		} /* end of something on this page */

	} /* end of each page */
	pdraw_shove_doctrailer(pnum);
}

qentry pdraw_new(t, x1, y1, x2, y2, l, lw, ls, r, g, b)
/* allocate new q entry, and throw on end of q */
/* and update min/max */
/* also, convert coordinates */
print_command t;
int x1, y1, x2, y2, l;
int lw;
tcap_style ls;
int r, g, b;
{
	qentry tmp;

	tmp=(qentry)malloc(sizeof(qentryd));
	if(tmp==NULL)
		return(NULL);

	tmp->c=t;
	tmp->linewidth=lw;
	tmp->capstyle=ls;
	tmp->printed=0;
	tmp->r=r;
	tmp->g=g;
	tmp->b=b;
	if(l==0)
		tmp->s=NULL;
	else
	{
		tmp->s=(char *)malloc(l+1);
		if(tmp->s==NULL)
		{
			free(tmp);
			return(NULL);
		}
	}
	if(outtype==tp_postscript)
	{
		y1=-y1;
		y2=-y2;
	}
	if(maxset)
	{
		if(x2>maxx)
			maxx=x2;
		if(x1<minx)
			minx=x1;
		if(y1>maxy)
			maxy=y1;
		if(y2<miny)
			miny=y2;
	}
	else
	{
		maxx=x2;
		maxy=y1;
		minx=x1;
		miny=y2;
		maxset=1;
	}
	tmp->x1=x1;
	tmp->y1=y1;
	tmp->x2=x2;
	tmp->y2=y2;
	addnode(printq, tmp);
	return(tmp);
}

int pdraw_start(c, f, fname, pagew, pageh, type)
/* page size in normalized canvas pixels */
/* this area will be expanded to fill one paper page */
tcanvas c;
FILE *f;
char *fname;
int pagew, pageh;
tp_type type;
{
	if(c==NULL)
		return(0);
	if(titem_type(c)!=lt_canvas)
		return(0);
	if(f==NULL)
		return(0);

	printcanvas=c;
	printq=newlist();
	outfile=f;
	outtype=type;
	filename=fname;
	maxset=0;
	pw=pagew;
	ph=pageh;
	/* use to convert to 72dpi */
	hres=tdisplay_dpi_x(c);
	vres=tdisplay_dpi_y(c);

	return(1);
}

int pdraw_end()
{
	qentry q;

	/* actually print it all out */
	if(outtype==tp_postscript)
		pdraw_shove_q();
	else if(outtype==tp_PICT)
		pdraw_shove_q_PICT();

	startlist(printq);
	while((q=listnext(printq))!=NULL)
	{
		if(q->s!=NULL)
			free(q->s);
		free(q);
	}
	freelist(printq);
	outfile=NULL;
	return(1);
}

int pdraw_text(gc, x, y, s, l)
tcontext gc;
int x, y;
char *s;
int l;
{
	int bx, by, bw, bh;
	qentry q;
	tfont font;
	tcolor c;
	int r, g, b;

	bx=x;
	by=y;
	tcontext_get_font(gc, &font);
	tfont_get_extents(font, s, l, &bx, &by, &bw, &bh);
	tcontext_get_foreground(gc, &c);
	tcolor_values(c, &r, &g, &b);

	q=pdraw_new(pr_text, bx, by, bx+bw, by+bh, l, 0, tcap_none, r, g, b);
	if(q==NULL)
		return(0);

	strncpy(q->s, s, l);
	q->s[l]='\0';
	q->fontname=(char *)tfont_get_lasername(font);
	q->fontsize=(int)tfont_get_lasersize(font);
	q->macnum=tfont_get_mac_number(font);
	q->macstyle=tfont_get_mac_style(font);
	q->sx=x;
	if(outtype==tp_postscript)
		q->sy=-y;
	else
		q->sy=y;

	return(1);
}

pdraw_arc(gc, x, y, w, h, a1, a2)
tcontext gc;
int x, y, w, h, a1, a2;
{
	/* don't need yet */
}

pdraw_line(gc, x1, y1, x2, y2)
tcontext gc;
int x1, y1, x2, y2;
{
	int lw;
	tcap_style ls;
	int r, g, b;
	tcolor c;

	tcontext_get_linewidth(gc, &lw);
	tcontext_get_capstyle(gc, &ls);
	tcontext_get_foreground(gc, &c);
	tcolor_values(c, &r, &g, &b);

	if(pdraw_new(pr_line, x1, y1, x2, y2, 0, lw, ls, r, g, b)==NULL)
		return(0);
	else
		return(1);
}

pdraw_rect(gc, x, y, w, h)
tcontext gc;
int x, y, w, h;
{
	/* don't need yet */
}