aboutsummaryrefslogtreecommitdiff
path: root/man/man3/draw.3
blob: 39f2b81ab2eb52990d6c9c09c485da4812c27191 (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
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
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
.TH DRAW 3
.SH NAME
Image, draw, drawop, gendraw, gendrawop, drawreplxy, drawrepl,
replclipr, line, lineop, poly, polyop, fillpoly, fillpolyop, bezier, bezierop,
bezspline, bezsplineop, bezsplinepts, fillbezier, fillbezierop, 
fillbezspline, fillbezsplineop, ellipse, ellipseop, 
fillellipse, fillellipseop, arc, arcop, fillarc, fillarcop, 
icossin, icossin2, border, string, stringop, stringn, stringnop,
runestring, runestringop, runestringn, runestringnop, stringbg, 
stringbgop, stringnbg, stringnbgop, runestringbg, runestringbgop,
runestringnbg, runestringnbgop, _string, ARROW, drawsetdebug \- graphics functions
.de PB
.PP
.ft L
.nf
..
.SH SYNOPSIS
.de PB
.PP
.ft L
.nf
..
.PB
#include <u.h>
#include <libc.h>
#include <draw.h>
.PB
typedef
struct Image
{
	Display	*display;	/* display holding data */
	int		id;		/* id of system-held Image */
	Rectangle	r;		/* rectangle in data area, local coords */
	Rectangle clipr;	/* clipping region */
	ulong	chan;	/* pixel channel format descriptor */
	int		depth;	/* number of bits per pixel */
	int		repl;	/* flag: data replicates to tile clipr */
	Screen	*screen;	/* 0 if not a window */
	Image	*next;	/* next in list of windows */
} Image;
.PB
typedef enum
{
	/* Porter-Duff compositing operators */
	Clear	= 0,
.sp 0.1
	SinD	= 8,
	DinS	= 4,
	SoutD	= 2,
	DoutS	= 1,
.sp 0.1
	S		= SinD|SoutD,
	SoverD	= SinD|SoutD|DoutS,
	SatopD	= SinD|DoutS,
	SxorD	= SoutD|DoutS,
.sp 0.1
	D		= DinS|DoutS,
	DoverS	= DinS|DoutS|SoutD,
	DatopS	= DinS|SoutD,
	DxorS	= DoutS|SoutD,	/* == SxorD */
.sp 0.1
	Ncomp = 12,
} Drawop;
.PB
.PD 0
.ta +\w'\fL      'u +\w'\fL    'u +6n +4n
void	draw(Image *dst, Rectangle r, Image *src,
		Image *mask, Point p)
.PB
void	drawop(Image *dst, Rectangle r, Image *src,
		Image *mask, Point p, Drawop op)
.PB
void	gendraw(Image *dst, Rectangle r, Image *src, Point sp,
		Image *mask, Point mp)
.PB
void	gendrawop(Image *dst, Rectangle r, Image *src, Point sp,
		Image *mask, Point mp, Drawop op)
.PB
int	drawreplxy(int min, int max, int x)
.PB
Point	drawrepl(Rectangle r, Point p)
.PB
void	replclipr(Image *i, int repl, Rectangle clipr)
.PB
void	line(Image *dst, Point p0, Point p1, int end0, int end1,
		int radius, Image *src, Point sp)
.PB
void	lineop(Image *dst, Point p0, Point p1, int end0, int end1,
		int radius, Image *src, Point sp, Drawop op)
.PB
void	poly(Image *dst, Point *p, int np, int end0, int end1,
		int radius, Image *src, Point sp)
.PB
void	polyop(Image *dst, Point *p, int np, int end0, int end1,
		int radius, Image *src, Point sp, Drawop op)
.PB
void	fillpoly(Image *dst, Point *p, int np, int wind,
		Image *src, Point sp)
.PB
void	fillpolyop(Image *dst, Point *p, int np, int wind,
		Image *src, Point sp, Drawop op)
.PB
int	bezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
		int end0, int end1, int radius, Image *src, Point sp)
.PB
int	bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
		int end0, int end1, int radius, Image *src, Point sp,
		Drawop op)
.PB
int	bezspline(Image *dst, Point *pt, int npt, int end0, int end1,
		int radius, Image *src, Point sp)
.PB
int	bezsplineop(Image *dst, Point *pt, int npt, int end0, int end1,
		int radius, Image *src, Point sp, Drawop op)
.PB
int	bezsplinepts(Point *pt, int npt, Point **pp)
.PB
int	fillbezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
		int w, Image *src, Point sp)
.PB
int	fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
		int w, Image *src, Point sp, Drawop op)
.PB
int	fillbezspline(Image *dst, Point *pt, int npt, int w,
		Image *src, Point sp)
.PB
int	fillbezsplineop(Image *dst, Point *pt, int npt, int w,
		Image *src, Point sp, Drawop op)
.PB
void	ellipse(Image *dst, Point c, int a, int b, int thick,
		Image *src, Point sp)
.PB
void	ellipseop(Image *dst, Point c, int a, int b, int thick,
		Image *src, Point sp, Drawop op)
.PB
void	fillellipse(Image *dst, Point c, int a, int b,
		Image *src, Point sp)
.PB
void	fillellipseop(Image *dst, Point c, int a, int b,
		Image *src, Point sp, Drawop op)
.PB
void	arc(Image *dst, Point c, int a, int b, int thick,
		Image *src, Point sp, int alpha, int phi)
.PB
void	arcop(Image *dst, Point c, int a, int b, int thick,
		Image *src, Point sp, int alpha, int phi, Drawop op)
.PB
void	fillarc(Image *dst, Point c, int a, int b, Image *src,
		Point sp, int alpha, int phi)
.PB
void	fillarcop(Image *dst, Point c, int a, int b, Image *src,
		Point sp, int alpha, int phi, Drawop op)
.PB
int	icossin(int deg, int *cosp, int *sinp)
.PB
int	icossin2(int x, int y, int *cosp, int *sinp)
.PB
void	border(Image *dst, Rectangle r, int i, Image *color, Point sp)
.br
.PB
Point	string(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s)
.PB
Point	stringop(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s, Drawop op)
.PB
Point	stringn(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s, int len)
.PB
Point	stringnop(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s, int len, Drawop op)
.PB
Point	runestring(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r)
.PB
Point	runestringop(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r, Drawop op)
.PB
Point	runestringn(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r, int len)
.PB
Point	runestringnop(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r, int len, Drawop op)
.PB
Point	stringbg(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s, Image *bg, Point bgp)
.PB
Point	stringbgop(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s, Image *bg, Point bgp, Drawop op)
.PB
Point	stringnbg(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s, int len, Image *bg, Point bgp)
.PB
Point	stringnbgop(Image *dst, Point p, Image *src, Point sp,
		Font *f, char *s, int len, Image *bg, Point bgp, Drawop op)
.PB
Point	runestringbg(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r, Image *bg, Point bgp)
.PB
Point	runestringbgop(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r, Image *bg, Point bgp, Drawop op)
.PB
Point	runestringnbg(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r, int len, Image *bg, Point bgp)
.PB
Point	runestringnbgop(Image *dst, Point p, Image *src, Point sp,
		Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op)
.PB
Point	_string(Image *dst, Point p, Image *src,
		Point sp, Font *f, char *s, Rune *r, int len,
		Rectangle clipr, Image *bg, Point bgp, Drawop op)
.PB
void	drawsetdebug(int on)
.PD
.PB
enum
{
	/* line ends */
	Endsquare	= 0,
	Enddisc		= 1,
	Endarrow	= 2,
	Endmask		= 0x1F
};
.PB
#define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
.SH DESCRIPTION
The
.B Image
type defines rectangular pictures and the methods to draw upon them;
it is also the building block for higher level objects such as
windows and fonts.
In particular, a window is represented as an
.BR Image ;
no special operators are needed to draw on a window.
.PP
.TP 10
.B r
The coordinates of the rectangle in the plane for which the
.B Image
has defined pixel values.
It should not be modified after the image is created.
.TP
.B clipr
The clipping rectangle: operations that read or write
the image will not access pixels outside
.BR clipr .
Frequently,
.B clipr
is the same as
.BR r ,
but it may differ; see in particular the discussion of
.BR repl .
The clipping region may be modified dynamically using
.I replclipr
.RI ( q.v. ).
.TP
.B chan
The pixel channel format descriptor, as described in
.IR image (7).
The value should not be modified after the image is created.
.TP
.B depth
The
number of bits per pixel in the picture;
it is identically
.B chantodepth(chan)
(see
.IR graphics (3))
and is provided as a convenience.
The value should not be modified after the image is created.
.TP
.B repl
A boolean value specifying whether the image is tiled to cover
the plane when used as a source for a drawing operation.
If
.B repl
is zero, operations are restricted to the intersection of
.B r
and
.BR clipr .
If
.B repl
is set,
.B r
defines the tile to be replicated and
.B clipr
defines the portion of the plane covered by the tiling, in other words,
.B r
is replicated to cover
.BR clipr ;
in such cases
.B r
and
.B clipr
are independent.
.IP
For example, a replicated image with
.B r
set to ((0,\ 0),\ (1,\ 1)) and
.B clipr
set to ((0,\ 0),\ (100,\ 100)),
with the single pixel of
.B r
set to blue,
behaves identically to an image with
.B r
and
.B clipr
both set to ((0,\ 0),\ (100,\ 100)) and all pixels set to blue.
However,
the first image requires far less memory.
The replication flag may be modified dynamically using
.I replclipr
.RI ( q.v. ).
.PP
Most of the drawing functions come in two forms:
a basic form, and an extended form that takes an extra
.B Drawop
to specify a Porter-Duff compositing operator to use.
The basic forms assume the operator is
.BR SoverD ,
which suffices for the vast majority of applications.
The extended forms are named by adding an
.RB - op
suffix to the basic form.
Only the basic forms are listed below.
.TP
.BI draw( dst\fP,\fP\ r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p )
.I Draw
is the standard drawing function.
Only those pixels within the intersection of
.IB dst ->r
and
.IB dst ->clipr
will be affected;
.I draw
ignores
.IB dst ->repl\fR.
The operation proceeds as follows
(this is a description of the behavior, not the implementation):
.RS
.IP 1.
If
.B repl
is set in
.I src
or
.IR mask ,
replicate their contents to fill
their clip rectangles.
.IP 2.
Translate
.I src
and
.I mask
so
.I p
is aligned with
.IB r .min\fR.
.IP 3.
Set
.I r
to the intersection of
.I r
and
.IB dst ->r\fR.
.IP 4.
Intersect
.I r
with
.IB src ->clipr\fR.
If
.IB src ->repl
is false, also intersect
.I r
with
.IB src ->r\fR.
.IP 5.
Intersect
.I r
with
.IB mask ->clipr\fR.
If
.IB mask ->repl
is false, also intersect
.I r
with
.IB mask ->r\fR.
.IP 6.
For each location in
.IR r ,
combine the
.I dst
pixel with the
.I src
pixel using the alpha value
corresponding to the
.I mask
pixel.
If the
.I mask
has an explicit alpha channel, the alpha value
corresponding to the
.I mask
pixel is simply that pixel's alpha channel.
Otherwise, the alpha value is the NTSC greyscale equivalent
of the color value, with white meaning opaque and black transparent.
In terms of the Porter-Duff compositing algebra,
.I draw
replaces the
.I dst
pixels with
.RI ( src
in
.IR mask )
over
.IR dst .
(In the extended form,
``over'' is replaced by
.IR op ).
.RE
.IP
The various
pixel channel formats
involved need not be identical.
If the channels involved are smaller than 8-bits, they will
be promoted before the calculation by replicating the extant bits;
after the calculation, they will be truncated to their proper sizes.
.TP
\f5gendraw(\f2dst\fP, \f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\f5)\fP
Similar to
.I draw
except that
.I gendraw
aligns the source and mask differently:
.I src
is aligned so
.I p0
corresponds to
.IB r .min
and
.I mask
is aligned so
.I p1
corresponds to
.IB r .min .
For most purposes with simple masks and source images,
.B draw
is sufficient, but
.B gendraw
is the general operator and the one all other drawing primitives are built upon.
.TP
.BI drawreplxy( min ,  max ,  x\f5)
Clips
.I x
to be in the half-open interval [\fImin\fP, \fImax\fP) by adding
or subtracting a multiple of \fImax-min\fP.
.TP
.BI drawrepl( r , p )
Clips the point \fIp\fP to be within the rectangle \fIr\fP
by translating the point horizontally by an integer multiple of rectangle width
and vertically by the height.
.TP
.BI replclipr( i ,  repl ,  clipr\f5)
Because the image data is stored on the server, local modifications to the
.B Image
data structure itself will have no effect.
.I Repclipr
modifies the local
.B Image
data structure's
.B repl
and
.B clipr
fields, and notifies the server of their modification.
.TP
\f5line(\f2dst\fP, \f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
Line
draws in
.I dst
a line of width
.RI 1+2* thick
pixels joining points
.I p0
and
.IR p1 .
The line is drawn using pixels from the
.I src
image aligned so
.I sp
in the source corresponds to
.I p0
in the destination.
The line touches both
.I p0
and
.IR p1 ,
and
.I end0
and
.I end1
specify how the ends of the line are drawn.
.B Endsquare
terminates the line perpendicularly to the direction of the line; a thick line with
.B Endsquare
on both ends will be a rectangle.
.B Enddisc
terminates the line by drawing a disc of diameter
.RI 1+2* thick
centered on the end point.
.B Endarrow
terminates the line with an arrowhead whose tip touches the endpoint.
.IP
The macro
.B ARROW
permits explicit control of the shape of the arrow.
If all three parameters are zero, it produces the default arrowhead,
otherwise,
.I a
sets the distance along line from end of the regular line to tip,
.I b
sets the distance along line from the barb to the tip,
and
.I c
sets the distance perpendicular to the line from edge of line to the tip of the barb,
all in pixels.
.IP
.I Line
and the other geometrical operators are equivalent to calls to
.I gendraw
using a mask produced by the geometric procedure.
.TP
\f5poly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.I Poly
draws a general polygon; it
is conceptually equivalent to a series of calls to
.I line
joining adjacent points in the
array of
.B Points
.IR p ,
which has
.I np
elements.
The ends of the polygon are specified as in
.IR line ;
interior lines are terminated with
.B Enddisc
to make smooth joins.
The source is aligned so
.I sp
corresponds to
.IB p [0]\f1.
.TP
\f5fillpoly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
.I Fillpoly
is like
.I poly
but fills in the resulting polygon rather than outlining it.
The source is aligned so
.I sp
corresponds to
.IB p [0]\f1.
The winding rule parameter
.I wind
resolves ambiguities about what to fill if the polygon is self-intersecting.
If
.I wind
is
.BR ~0 ,
a pixel is inside the polygon if the polygon's winding number about the point
is non-zero.
If
.I wind
is
.BR 1 ,
a pixel is inside if the winding number is odd.
Complementary values (0 or ~1) cause outside pixels to be filled.
The meaning of other values is undefined.
The polygon is closed with a line if necessary.
.TP
\f5bezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.I Bezier
draws the
cubic Bezier curve defined by
.B Points
.IR a ,
.IR b ,
.IR c ,
and
.IR d .
The end styles are determined by
.I end0
and
.IR end1 ;
the thickness of the curve is
.RI 1+2* thick .
The source is aligned so
.I sp
in
.I src
corresponds to
.I a
in
.IR dst .
.TP
\f5bezspline(\f2dst\fP, \f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.I Bezspline
takes the same arguments as
.I poly
but draws a quadratic B-spline (despite its name) rather than a polygon.
If the first and last points in
.I p
are equal, the spline has periodic end conditions.
.TP
\f5bezsplinepts(\f2pt\fP, \f2npt\fP, \f2pp\fP)
.I Bezsplinepts
returns in
.I pp
a list of points making up the open polygon that
.I bezspline
would draw.
The caller is responsible for freeing
.IR *pp .
.TP
\f5fillbezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
.I Fillbezier
is to
.I bezier
as
.I fillpoly
is to
.IR poly .
.TP
\f5fillbezspline(\f2dst\fP, \f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
.I Fillbezspline
is like
.I fillpoly
but fills the quadratic B-spline rather than the polygon outlined by
.IR p .
The spline is closed with a line if necessary.
.TP
\f5ellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.I Ellipse
draws in
.I dst
an ellipse centered on
.I c
with horizontal and vertical semiaxes
.I a
and
.IR b .
The source is aligned so
.I sp
in
.I src
corresponds to
.I c
in
.IR dst .
The ellipse is drawn with thickness
.RI 1+2* thick .
.TP
\f5fillellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP)
.I Fillellipse
is like
.I ellipse
but fills the ellipse rather than outlining it.
.TP
\f5arc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
.I Arc
is like
.IR ellipse ,
but draws only that portion of the ellipse starting at angle
.I alpha
and extending through an angle of
.IR phi .
The angles are measured in degrees counterclockwise from the positive
.I x
axis.
.TP
\f5fillarc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
.I Fillarc
is like
.IR arc ,
but fills the sector with the source color.
.TP
\f5icossin(\f2deg\fP, \f2cosp\fP, \f2sinp\fP)
.I Icossin
stores in
.BI * cosp
and
.BI * sinp
scaled integers representing the cosine and sine of the angle
.IR deg ,
measured in integer degrees.
The values are scaled so cos(0) is 1024.
.TP
\f5icossin2(\f2x\fP, \f2y\fP, \f2cosp\fP, \f2sinp\fP)
.I Icossin2
is analogous to
.IR icossin,
with the angle represented not in degrees but implicitly by the point
.RI ( x , y ).
It is to
.I icossin
what
.B atan2
is to
.B atan
(see
.IR sin (3)).
.TP
.BI border( dst\fP,\fP\ r\fP,\fP\ i\fP,\fP\ color\fP,\fP\ sp\fP)
.I Border
draws an outline of rectangle
.I r
in the specified
.IR color .
The outline has width
.IR i ;
if positive, the border goes inside the rectangle; negative, outside.
The source is aligned so
.I sp
corresponds to
.IB r .min .
.TP
.BI string( dst\fP,\fP\ p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ s )
.I String
draws in
.I dst
characters specified by the string
.I s
and
.IR font ;
it is equivalent to a series of calls to
.I gendraw
using source
.I src
and masks determined by the character shapes.
The text is positioned with the left of the first character at
.IB p .x
and the top of the line of text at
.IB p .y\f1.
The source is positioned so
.I sp
in
.I src
corresponds to
.I p
in
.IR dst .
.I String
returns a
.B Point
that is the position of the next character that would be drawn if the string were longer.
.IP
For characters with undefined
or zero-width images in the font, the character at font position 0 (NUL) is drawn.
.IP
The other string routines are variants of this basic form, and
have names that encode their variant behavior.
Routines whose names contain
.B rune
accept a string of Runes rather than
.SM UTF\c
-encoded bytes.
Routines ending in
.B n
accept an argument,
.IR n ,
that defines the number of characters to draw rather than accepting a NUL-terminated
string.
Routines containing
.B bg
draw the background behind the characters in the specified color
.RI ( bg )
and
alignment
.RI ( bgp );
normally the text is drawn leaving the background intact.
.IP
The routine
.I _string
captures all this behavior into a single operator.  Whether it draws a
.SM UTF
string
or Rune string depends on whether
.I s
or
.I r
is null (the string length is always determined by
.IR len ).
If
.I bg
is non-null, it is used as a background color.
The
.I clipr
argument allows further management of clipping when drawing the string;
it is intersected with the usual clipping rectangles to further limit the extent of the text.
.TP
.BI drawsetdebug( on )
Turns on or off debugging output (usually
to a serial line) according to whether
.I on
is non-zero.
.SH SOURCE
.B \*9/src/libdraw
.SH SEE ALSO
.IR graphics (3),
.IR stringsize (3),
.IR color (7),
.IR utf (7),
.IR addpt (3)
.PP
T. Porter, T. Duff.
``Compositing Digital Images'', 
.I "Computer Graphics
(Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.
.SH DIAGNOSTICS
These routines call the graphics error function on fatal errors.
.SH BUGS
Anti-aliased characters can be drawn by defining a font
with multiple bits per pixel, but there are
no anti-aliasing geometric primitives.