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
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
|
.TH DRAW-IMAGE 2
.SH NAME
Image \-
pictures and drawing
.SH SYNOPSIS
.EX
include "draw.m";
draw := load Draw Draw->PATH;
# compositing operators
SinD: con 1<<3;
DinS: con 1<<2;
SoutD: con 1<<1;
DoutS: con 1<<0;
S: con SinD|SoutD;
SoverD: con SinD|SoutD|DoutS;
SatopD: con SinD|DoutS;
SxorD: con SoutD|DoutS;
D: con DinS|DoutS;
DoverS: con DinS|DoutS|SoutD;
DatopS: con DinS|SoutD;
DxorS: con DoutS|SoutD;
Clear: con 0;
Image: adt
{
r: Rect;
clipr: Rect;
chans: Chans;
depth: int;
repl: int;
display: ref Display;
screen: ref Screen;
draw: fn(dst: self ref Image, r: Rect, src: ref Image,
mask: ref Image, p: Point);
drawop: fn(dst: self ref Image, r: Rect, src: ref Image,
mask: ref Image, p: Point, op: int);
gendraw: fn(dst: self ref Image, r: Rect, src: ref Image,
p0: Point, mask: ref Image, p1: Point);
gendrawop: fn(dst: self ref Image, r: Rect, src: ref Image,
p0: Point, mask: ref Image, p1: Point, op: int);
line: fn(dst: self ref Image, p0,p1: Point,
end0,end1,thick: int,
src: ref Image, sp: Point);
lineop: fn(dst: self ref Image, p0,p1: Point,
end0,end1,thick: int,
src: ref Image, sp: Point, op: int);
poly: fn(dst: self ref Image, p: array of Point,
end0,end1,thick: int,
src: ref Image, sp: Point);
polyop: fn(dst: self ref Image, p: array of Point,
end0,end1,thick: int,
src: ref Image, sp: Point, op: int);
bezspline: fn(dst: self ref Image, p: array of Point,
end0,end1,thick: int,
src: ref Image, sp: Point);
bezsplineop: fn(dst: self ref Image, p: array of Point,
end0,end1,thick: int,
src: ref Image, sp: Point, op: int);
fillpoly: fn(dst: self ref Image, p: array of Point,
wind: int, src: ref Image, sp: Point);
fillpolyop: fn(dst: self ref Image, p: array of Point,
wind: int, src: ref Image, sp: Point, op: int);
fillbezspline: fn(dst: self ref Image, p: array of Point,
wind: int, src: ref Image, sp: Point);
fillbezsplineop: fn(dst: self ref Image, p: array of Point,
wind: int, src: ref Image, sp: Point, op: int);
ellipse: fn(dst: self ref Image, c: Point, a, b,
thick: int, src: ref Image, sp: Point);
ellipseop: fn(dst: self ref Image, c: Point, a, b,
thick: int, src: ref Image, sp: Point, op: int);
fillellipse:fn(dst: self ref Image, c: Point, a, b: int,
src: ref Image, sp: Point);
fillellipseop:fn(dst: self ref Image, c: Point, a, b: int,
src: ref Image, sp: Point, op: int);
arc: fn(dst: self ref Image, c: Point, a, b, thick: int,
src: ref Image, sp: Point, alpha, phi: int);
arcop: fn(dst: self ref Image, c: Point, a, b, thick: int,
src: ref Image, sp: Point,
alpha, phi: int, op: int);
fillarc: fn(dst: self ref Image, c: Point, a, b: int,
src: ref Image, sp: Point, alpha, phi: int);
fillarcop: fn(dst: self ref Image, c: Point, a, b: int,
src: ref Image, sp: Point,
alpha, phi: int, op: int);
bezier: fn(dst: self ref Image, a,b,c,d: Point,
end0,end1,thick: int,
src: ref Image, sp: Point);
bezierop: fn(dst: self ref Image, a,b,c,d: Point,
end0,end1,thick: int,
src: ref Image, sp: Point, op: int);
fillbezier: fn(dst: self ref Image, a,b,c,d: Point, wind:int,
src: ref Image, sp: Point);
fillbezierop: fn(dst: self ref Image, a,b,c,d: Point, wind:int,
src: ref Image, sp: Point, op: int);
arrow: fn(a,b,c: int): int;
text: fn(dst: self ref Image, p: Point, src: ref Image,
sp: Point, font: ref Font, str: string): Point;
textop: fn(dst: self ref Image, p: Point, src: ref Image,
sp: Point, font: ref Font, str: string,
op: int): Point;
textbg: fn(dst: self ref Image, p: Point, src: ref Image,
sp: Point, font: ref Font, str: string,
bg: ref Image, bgp: Point): Point;
textbgop: fn(dst: self ref Image, p: Point, src: ref Image,
sp: Point, font: ref Font, str: string,
bg: ref Image, bgp: Point, op: int): Point;
border: fn(dst: self ref Image, r: Rect, i: int,
src: ref Image, sp: Point);
borderop: fn(dst: self ref Image, r: Rect, i: int,
src: ref Image, sp: Point, op: int);
readpixels: fn(src: self ref Image, r: Rect,
data: array of byte): int;
writepixels:fn(dst: self ref Image, r: Rect,
data: array of byte): int;
name: fn(im: self ref Image, s: string, in: int): int;
top: fn(win: self ref Image);
bottom: fn(win: self ref Image);
flush: fn(win: self ref Image, func: int);
origin: fn(win: self ref Image, log, scr: Point): int;
};
.EE
.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.
Off-screen images can have an alpha channel, which gives each pixel an opacity
factor, which in turn allows non-rectangular images to be defined
(ie, pixels made fully transparent by the alpha channel
do not appear when the image is displayed).
Many drawing operations allow images to be shaped, or partial transparency added, by using the alpha
channel of another image as a mask (also called a `matte').
There are two functions in
.B Image
for each such operation.
One has an
.B op
suffix, and takes an explicit image compositing operator:
.BR S ,
.BR D ,
.BR SinD , ...,
.BR SoverD
and so on.
(See the Porter-Duff paper mentioned below for the meaning of each operation.)
The other function (without the
.B op
suffix) provides as its default operation the most common operation,
.BR SoverD ,
by which the source image, within its matte, is drawn over the destination image.
.PP
An
.B Image
has a pixel channel structure as described in
.IR colour (6),
represented by a value of the
.B Chans
adt,
defined in
.IR draw-display (2).
The channel structure of an image is fixed when the image is allocated.
.PP
.B Image
has the following components:
.TP 10
.B display
Tells on which display the image resides.
.TP
.B screen
If the image is a window on a
.B Screen
(see
.IR draw-screen (2)),
this field refers to that screen; otherwise it is nil.
.TP
.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 Image.r ,
but it may differ; see in particular the discussion of
.BR Image.repl .
The clipping region may be modified dynamically.
.TP
.B chans
The pixel channel structure of the image; 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 simply a convenience since it is necessarily equal to
.BR chans.depth() ,
and it 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 Image.repl
is zero, operations are restricted to the intersection of
.B Image.r
and
.BR Image.clipr .
If
.B Image.repl
is set,
.B Image.r
defines the tile to be replicated and
.B Image.clipr
defines the portion of the plane covered by the tiling, in other words,
.B Image.r
is replicated to cover
.BR Image.clipr ;
in such cases
.B Image.r
and
.B Image.clipr
are independent.
.IP
For example, a replicated image with
.B Image.r
set to ((0,\ 0),\ (1,\ 1)) and
.B Image.clipr
set to ((0,\ 0),\ (100,\ 100)),
with the single pixel of
.B Image.r
set to blue,
behaves identically to an image with
.B Image.r
and
.B Image.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 along with the clipping
rectangle.
.TP
.IB dst .draw( r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p\fP )
.PD0
.TP
.IB dst .drawop( r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p\fP,\fP\ op )
.PD
.B Draw
is the standard drawing function.
Only those pixels within the intersection of
.IB dst .r
and
.IB dst .clipr
will be affected;
.B 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 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 colour value,
with white meaning opaque and black transparent.
.RE
.IP
In terms of the Porter-Duff compositing algebra,
.I draw
replaces the
.I dst
pixels with
.RI ( src
in
.IR mask )
over
.IR dst .
.I Drawop
is almost identical, but applies the compositing operation
.I op
instead:
.RI ( src
in
.IR mask )
.I op
.IR dst .
.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.
For
.B draw
and
.B gendraw
only,
if
.I mask
is nil, no mask is used.
.TP
\f2dst\fP.\f5gendraw(\f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\fP)\fP
.PD0
.TP
\f2dst\fP.\f5gendrawop(\f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\fP\f5, \f2op\fP)\fP
.PD
Similar to \f5draw()\fP except that it 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 the other drawing primitives are built upon.
.TP
\f2dst\fP.\f5line(\f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5lineop(\f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B 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 Draw->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 Draw->Enddisc
terminates the line by drawing a disc of diameter
.RI 1+2* thick
centered on the end point.
.B Draw->Endarrow
terminates the line with an arrowhead whose tip touches the endpoint.
See the description of
.B arrow
for more information.
.IP
.B Line
and the other geometrical operators are equivalent to calls to
.B gendraw
using a mask produced by the geometric procedure.
.TP
\f2dst\fP.\f5poly(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5polyop(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B Poly
draws a general polygon; it
is equivalent to a series of calls to
.B line
joining adjacent points in the array of
.B Points
.IR p .
The ends of the polygon are specified as in
.BR 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
\f2dst\fP.\f5bezspline(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5bezsplineop(\f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B Bezspline
takes the same arguments as
.B 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
\f2dst\fP.\f5fillpoly(\f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5fillpolyop(\f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B Fillpoly
is like
.B 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 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
\f2dst\fP.\f5fillbezspline(\f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5fillbezsplineop(\f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B Fillbezspline
is like
.B 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
\f2dst\fP.\f5ellipse(\f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5ellipseop(\f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B 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
\f2dst\fP.\f5fillellipse(\f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5fillellipseop(\f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B Fillellipse
is like
.B ellipse
but fills the ellipse rather than outlining it.
.TP
.IB dst .arc(\fIc\fP,\ \fIa\fP,\ \fIb\fP,\ \fIthick\fP,\ \fIsrc\fP,\ \fIsp\fP,\ \fIalpha\fP,\ \fIphi\fP)
.PD0
.TP
.IB dst .arcop(\fIc\fP,\ \fIa\fP,\ \fIb\fP,\ \fIthick\fP,\ \fIsrc\fP,\ \fIsp\fP,\ \fIalpha\fP,\ \fIphi\fP,\ \fIop\fP)
.PD
.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
.IB dst .fillarc(\fIc\fP,\ \fIa\fP,\ \fIb\fP,\ \fIsrc\fP,\ \fIsp\fP,\ \fIalpha\fP,\ \fIphi\fP)
.PD0
.TP
.IB dst .fillarcop(\fIc\fP,\ \fIa\fP,\ \fIb\fP,\ \fIsrc\fP,\ \fIsp\fP,\ \fIalpha\fP,\ \fIphi\fP,\ \fIop\fP)
.PD
.I Fillarc
is like
.IR arc ,
but fills the sector with the source color.
.TP
\f2dst\fP.\f5bezier(\f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5bezierop(\f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B 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
\f2dst\fP.\f5fillbezier(\f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
.PD0
.TP
\f2dst\fP.\f5fillbezierop(\f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP, \f2op\fP)
.PD
.B Fillbezier
is to
.B bezier
as
.B fillpoly
is to
.BR poly .
.TP
.BI arrow( "a,\ b,\ c" )
.B Arrow
is a function to describe general arrowheads; its result is passed as
.I end
parameters to
.BR line ,
.BR poly ,
etc.
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.
.TP
.IB dst .border( r\fP,\fP\ i\fP,\fP\ src\fP,\fP\ sp\fP)
.PD0
.TP
.IB dst .borderop( r\fP,\fP\ i\fP,\fP\ src\fP,\fP\ sp\fP,\ \f2op\fP)
.PD
.I Border
draws in
.I dst
an outline of rectangle
.I r
in the given
.I src
colour.
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
.IB dst .text( p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ str\fP)
.PD0
.TP
.IB dst .textop( p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ str\fP,\ \f2op\fP)
.TP
.IB dst .textbg( p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ str\fP,\ \f2bg\fP,\ \f2bgp\fP)
.PD0
.TP
.IB dst .textbgop( p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ str\fP,\ \f2bg\fP,\ \f2bgp\fP,\ \f2op\fP)
.PD
.B Text
draws in
.I dst
characters specified by the string
.I str
and font
.IR font ;
it is equivalent to a series of calls to
.B 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 .
.B Text
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
.B Text
draws the text leaving the background intact.
.B Textbg
draws the background colour
.I bg
behind the characters, with the alignment specified by point
.IR bgp ;
it is otherwise the same as
.BR text .
.TP
.IB src .readpixels( r\fP,\fP\ data )
.B Readpixels
fills the
.I data
array with pixels from the specified rectangle of the
.I src
image.
The pixels are presented one horizontal line at a time,
starting with the top-left pixel of
.IR r .
Each scan line starts with a new byte in the array,
leaving the last byte of the previous line partially empty, if necessary.
Pixels are packed as tightly as possible within
.IR data ,
regardless of the rectangle being extracted.
Bytes are filled from most to least significant bit order,
as the
.I x
coordinate increases, aligned so
.IR x =0
would appear as the leftmost pixel of its byte.
Thus, for a 1-bit deep greyscale image,
the pixel at
.I x
offset 165 within the rectangle will be in a
.I data
byte with mask value
.B 16r04
regardless of the overall
rectangle: 165 mod 8 equals 5, and
.B "16r80\ >>\ 5" equals
.BR 16r04 .
It is an error to call
.B readpixels
with an array that is too small to hold the rectangle's pixels.
The return value is the number of bytes copied.
The arrangement of pixels in arrays of bytes is described in
.IR image (6).
.TP
.IB dst .writepixels( r\fP,\fP\ data )
.B Writepixels
copies pixel values from the
.I data
array to the specified rectangle in the
.I dst
image.
The format of the data is that produced by
.BR readpixels .
The return value is the number of bytes copied.
It is an error to call
.B writepixels
with an array that is too small to fill the rectangle.
.TP
.IB im .name( s , in )
Publish the image
.I im
on its display under name
.IR s ,
if
.I in is non-zero;
otherwise,
.I s
must be an already published name and it is withdrawn from publication.
A published image can be retrieved using
.B Display.namedimage
(see
.IR draw-display (2)).
This function returns -1 on error, typically because the name is already in use
(for
.I in
non-zero), or does not exist
(for
.I in
zero).
.TP
.IB win .top()
If the image
.I win
is a window,
.B top
pulls it to the ``top'' of the stack of windows on its
.BR Screen ,
perhaps obscuring other images.
If
.I win
is not a window,
.B top
has no effect.
.TP
.IB win .bottom()
If the image
.I win
is a window,
.B bottom
pulls it to the ``bottom'' of the stack of windows on its
.BR Screen ,
perhaps obscuring it.
If
.I win
is not a window,
.B bottom
has no effect.
.TP
.IB image .flush( flag )
The connection to a display has a buffer used to gather graphics requests
generated by calls to the draw library.
By default, the library flushes the buffer at the conclusion of any
call that affects the visible display
image itself.
The
.B flush
routine allows finer control of buffer management.
The
.I flag
has three possible values:
.B Flushoff
turns off all automatic flushing caused by writes to
.IR image ,
typically a window or the display image itself
(buffers may still be written when they fill or when other objects on the display
are modified);
.B Flushnow
causes the buffer to be flushed immediately;
and
.B Flushon
restores the default behaviour.
.TP
\f2win\fP.\f5origin(\f2log\fP, \f2scr\fP)
When a window is created (see
.IR draw-screen (2)),
the coordinate system within the window is identical to that of the screen:
the upper left corner of the window rectangle is its physical location on the display,
not for example (0, 0).
This symmetry may be broken, however:
.B origin
allows control of the location of the window on the display and the coordinate
system used by programs drawing on the window.
The first argument,
.IR log ,
sets the upper left corner of the logical (in-window) coordinate system without
changing the position of the window on the screen.
The second argument,
.IR scr ,
sets the upper left corner of physical (on-screen) coordinate system, that is, the
window's location on the display, without changing the internal coordinate system.
Therefore, changing
.I scr
without changing
.I log
moves the window without requiring the client using it to be notified of the change;
changing
.I log
without changing
.I scr
allows the client to set up a private coordinate system regardless of the window's
location.
It is permissible for values of
.I scr
to move some or all of the window off screen.
.B Origin
returns \-1 if the image is not a window or, in the case of changes to
.IR scr ,
if there are insufficient resources available to move the window;
otherwise it returns 1.
.SH SOURCE
.B /libdraw
.SH SEE ALSO
.IR draw-intro (2),
.IR draw-display (2),
.IR draw-point (2),
.IR draw-rect (2),
.IR draw-screen (2),
.IR colour (6),
.IR image (6),
.IR font (6)
.IR utf (6)
.PP
T. Porter, T. Duff.
``Compositing Digital Images'',
.I "Computer Graphics
(Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.
.SH DIAGNOSTICS
These functions raise exceptions if argument images are nil,
except for
.B draw
and
.B gendraw
where the mask image is optional and may be nil.
.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.
|