draw 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. .TH DRAW 2
  2. .SH NAME
  3. Image, draw, gendraw, drawreplxy, drawrepl,
  4. replclipr, line, poly, fillpoly, bezier, bezspline, fillbezier, fillbezspline, ellipse,
  5. fillellipse, arc, fillarc, icossin, icossin2, border, string, stringn,
  6. runestring, runestringn, stringbg, stringnbg, runestringbg,
  7. runestringnbg, _string, ARROW, drawsetdebug \- graphics functions
  8. .de PB
  9. .PP
  10. .ft L
  11. .nf
  12. ..
  13. .SH SYNOPSIS
  14. .PB
  15. #include <u.h>
  16. #include <libc.h>
  17. #include <draw.h>
  18. .PB
  19. typedef
  20. struct Image
  21. {
  22. Display *display; /* display holding data */
  23. int id; /* id of system-held Image */
  24. Rectangle r; /* rectangle in data area, local coords */
  25. Rectangle clipr; /* clipping region */
  26. ulong chan; /* pixel channel format descriptor */
  27. int depth; /* number of bits per pixel */
  28. int repl; /* flag: data replicates to tile clipr */
  29. Screen *screen; /* 0 if not a window */
  30. Image *next; /* next in list of windows */
  31. } Image;
  32. .PB
  33. typedef enum
  34. {
  35. /* Porter-Duff compositing operators */
  36. Clear = 0,
  37. .sp 0.1
  38. SinD = 8,
  39. DinS = 4,
  40. SoutD = 2,
  41. DoutS = 1,
  42. .sp 0.1
  43. S = SinD|SoutD,
  44. SoverD = SinD|SoutD|DoutS,
  45. SatopD = SinD|DoutS,
  46. SxorD = SoutD|DoutS,
  47. .sp 0.1
  48. D = DinS|DoutS,
  49. DoverS = DinS|DoutS|SoutD,
  50. DatopS = DinS|SoutD,
  51. DxorS = DoutS|SoutD, /* == SxorD */
  52. .sp 0.1
  53. Ncomp = 12,
  54. } Drawop;
  55. .PB
  56. .PD 0
  57. .ta +\w'\fL 'u +\w'\fL 'u +6n +4n
  58. void draw(Image *dst, Rectangle r, Image *src,
  59. Image *mask, Point p)
  60. .PB
  61. void drawop(Image *dst, Rectangle r, Image *src,
  62. Image *mask, Point p, Drawop op)
  63. .PB
  64. void gendraw(Image *dst, Rectangle r, Image *src, Point sp,
  65. Image *mask, Point mp)
  66. .PB
  67. void gendrawop(Image *dst, Rectangle r, Image *src, Point sp,
  68. Image *mask, Point mp, Drawop op)
  69. .PB
  70. int drawreplxy(int min, int max, int x)
  71. .PB
  72. Point drawrepl(Rectangle r, Point p)
  73. .PB
  74. void replclipr(Image *i, int repl, Rectangle clipr)
  75. .PB
  76. void line(Image *dst, Point p0, Point p1, int end0, int end1,
  77. int radius, Image *src, Point sp)
  78. .PB
  79. void lineop(Image *dst, Point p0, Point p1, int end0, int end1,
  80. int radius, Image *src, Point sp, Drawop op)
  81. .PB
  82. void poly(Image *dst, Point *p, int np, int end0, int end1,
  83. int radius, Image *src, Point sp)
  84. .PB
  85. void polyop(Image *dst, Point *p, int np, int end0, int end1,
  86. int radius, Image *src, Point sp, Drawop op)
  87. .PB
  88. void fillpoly(Image *dst, Point *p, int np, int wind,
  89. Image *src, Point sp)
  90. .PB
  91. void fillpolyop(Image *dst, Point *p, int np, int wind,
  92. Image *src, Point sp, Drawop op)
  93. .PB
  94. int bezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
  95. int end0, int end1, int radius, Image *src, Point sp)
  96. .PB
  97. int bezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
  98. int end0, int end1, int radius, Image *src, Point sp,
  99. Drawop op)
  100. .PB
  101. int bezspline(Image *dst, Point *pt, int npt, int end0, int end1,
  102. int radius, Image *src, Point sp)
  103. .PB
  104. int bezsplineop(Image *dst, Point *pt, int npt, int end0, int end1,
  105. int radius, Image *src, Point sp, Drawop op)
  106. .PB
  107. int bezsplinepts(Point *pt, int npt, Point **pp)
  108. .PB
  109. int fillbezier(Image *dst, Point p0, Point p1, Point p2, Point p3,
  110. int w, Image *src, Point sp)
  111. .PB
  112. int fillbezierop(Image *dst, Point p0, Point p1, Point p2, Point p3,
  113. int w, Image *src, Point sp, Drawop op)
  114. .PB
  115. int fillbezspline(Image *dst, Point *pt, int npt, int w,
  116. Image *src, Point sp)
  117. .PB
  118. int fillbezsplineop(Image *dst, Point *pt, int npt, int w,
  119. Image *src, Point sp, Drawop op)
  120. .PB
  121. void ellipse(Image *dst, Point c, int a, int b, int thick,
  122. Image *src, Point sp)
  123. .PB
  124. void ellipseop(Image *dst, Point c, int a, int b, int thick,
  125. Image *src, Point sp, Drawop op)
  126. .PB
  127. void fillellipse(Image *dst, Point c, int a, int b,
  128. Image *src, Point sp)
  129. .PB
  130. void fillellipseop(Image *dst, Point c, int a, int b,
  131. Image *src, Point sp, Drawop op)
  132. .PB
  133. void arc(Image *dst, Point c, int a, int b, int thick,
  134. Image *src, Point sp, int alpha, int phi)
  135. .PB
  136. void arcop(Image *dst, Point c, int a, int b, int thick,
  137. Image *src, Point sp, int alpha, int phi, Drawop op)
  138. .PB
  139. void fillarc(Image *dst, Point c, int a, int b, Image *src,
  140. Point sp, int alpha, int phi)
  141. .PB
  142. void fillarcop(Image *dst, Point c, int a, int b, Image *src,
  143. Point sp, int alpha, int phi, Drawop op)
  144. .PB
  145. int icossin(int deg, int *cosp, int *sinp)
  146. .PB
  147. int icossin2(int x, int y, int *cosp, int *sinp)
  148. .PB
  149. void border(Image *dst, Rectangle r, int i, Image *color, Point sp)
  150. .br
  151. .PB
  152. Point string(Image *dst, Point p, Image *src, Point sp,
  153. Font *f, char *s)
  154. .PB
  155. Point stringop(Image *dst, Point p, Image *src, Point sp,
  156. Font *f, char *s, Drawop op)
  157. .PB
  158. Point stringn(Image *dst, Point p, Image *src, Point sp,
  159. Font *f, char *s, int len)
  160. .PB
  161. Point stringnop(Image *dst, Point p, Image *src, Point sp,
  162. Font *f, char *s, int len, Drawop op)
  163. .PB
  164. Point runestring(Image *dst, Point p, Image *src, Point sp,
  165. Font *f, Rune *r)
  166. .PB
  167. Point runestringop(Image *dst, Point p, Image *src, Point sp,
  168. Font *f, Rune *r, Drawop op)
  169. .PB
  170. Point runestringn(Image *dst, Point p, Image *src, Point sp,
  171. Font *f, Rune *r, int len)
  172. .PB
  173. Point runestringnop(Image *dst, Point p, Image *src, Point sp,
  174. Font *f, Rune *r, int len, Drawop op)
  175. .PB
  176. Point stringbg(Image *dst, Point p, Image *src, Point sp,
  177. Font *f, char *s, Image *bg, Point bgp)
  178. .PB
  179. Point stringbgop(Image *dst, Point p, Image *src, Point sp,
  180. Font *f, char *s, Image *bg, Point bgp, Drawop op)
  181. .PB
  182. Point stringnbg(Image *dst, Point p, Image *src, Point sp,
  183. Font *f, char *s, int len, Image *bg, Point bgp)
  184. .PB
  185. Point stringnbgop(Image *dst, Point p, Image *src, Point sp,
  186. Font *f, char *s, int len, Image *bg, Point bgp, Drawop op)
  187. .PB
  188. Point runestringbg(Image *dst, Point p, Image *src, Point sp,
  189. Font *f, Rune *r, Image *bg, Point bgp)
  190. .PB
  191. Point runestringbgop(Image *dst, Point p, Image *src, Point sp,
  192. Font *f, Rune *r, Image *bg, Point bgp, Drawop op)
  193. .PB
  194. Point runestringnbg(Image *dst, Point p, Image *src, Point sp,
  195. Font *f, Rune *r, int len, Image *bg, Point bgp)
  196. .PB
  197. Point runestringnbgop(Image *dst, Point p, Image *src, Point sp,
  198. Font *f, Rune *r, int len, Image *bg, Point bgp, Drawop op)
  199. .PB
  200. Point _string(Image *dst, Point p, Image *src,
  201. Point sp, Font *f, char *s, Rune *r, int len,
  202. Rectangle clipr, Image *bg, Point bgp, Drawop op)
  203. .PB
  204. void drawsetdebug(int on)
  205. .PD
  206. .PB
  207. enum
  208. {
  209. /* line ends */
  210. Endsquare = 0,
  211. Enddisc = 1,
  212. Endarrow = 2,
  213. Endmask = 0x1F
  214. };
  215. .PB
  216. #define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
  217. .SH DESCRIPTION
  218. The
  219. .B Image
  220. type defines rectangular pictures and the methods to draw upon them;
  221. it is also the building block for higher level objects such as
  222. windows and fonts.
  223. In particular, a window is represented as an
  224. .BR Image ;
  225. no special operators are needed to draw on a window.
  226. .PP
  227. .TP 10
  228. .B r
  229. The coordinates of the rectangle in the plane for which the
  230. .B Image
  231. has defined pixel values.
  232. It should not be modified after the image is created.
  233. .TP
  234. .B clipr
  235. The clipping rectangle: operations that read or write
  236. the image will not access pixels outside
  237. .BR clipr .
  238. Frequently,
  239. .B clipr
  240. is the same as
  241. .BR r ,
  242. but it may differ; see in particular the discussion of
  243. .BR repl .
  244. The clipping region may be modified dynamically using
  245. .I replclipr
  246. .RI ( q.v. ).
  247. .TP
  248. .B chan
  249. The pixel channel format descriptor, as described in
  250. .IR image (6).
  251. The value should not be modified after the image is created.
  252. .TP
  253. .B depth
  254. The
  255. number of bits per pixel in the picture;
  256. it is identically
  257. .B chantodepth(chan)
  258. (see
  259. .IR graphics (2))
  260. and is provided as a convenience.
  261. The value should not be modified after the image is created.
  262. .TP
  263. .B repl
  264. A boolean value specifying whether the image is tiled to cover
  265. the plane when used as a source for a drawing operation.
  266. If
  267. .B repl
  268. is zero, operations are restricted to the intersection of
  269. .B r
  270. and
  271. .BR clipr .
  272. If
  273. .B repl
  274. is set,
  275. .B r
  276. defines the tile to be replicated and
  277. .B clipr
  278. defines the portion of the plane covered by the tiling, in other words,
  279. .B r
  280. is replicated to cover
  281. .BR clipr ;
  282. in such cases
  283. .B r
  284. and
  285. .B clipr
  286. are independent.
  287. .IP
  288. For example, a replicated image with
  289. .B r
  290. set to ((0,\ 0),\ (1,\ 1)) and
  291. .B clipr
  292. set to ((0,\ 0),\ (100,\ 100)),
  293. with the single pixel of
  294. .B r
  295. set to blue,
  296. behaves identically to an image with
  297. .B r
  298. and
  299. .B clipr
  300. both set to ((0,\ 0),\ (100,\ 100)) and all pixels set to blue.
  301. However,
  302. the first image requires far less memory.
  303. The replication flag may be modified dynamically using
  304. .I replclipr
  305. .RI ( q.v. ).
  306. .PP
  307. Most of the drawing functions come in two forms:
  308. a basic form, and an extended form that takes an extra
  309. .B Drawop
  310. to specify a Porter-Duff compositing operator to use.
  311. The basic forms assume the operator is
  312. .BR SoverD ,
  313. which suffices for the vast majority of applications.
  314. The extended forms are named by adding an
  315. .RB - op
  316. suffix to the basic form.
  317. Only the basic forms are listed below.
  318. .TP
  319. .BI draw( dst\fP,\fP\ r\fP,\fP\ src\fP,\fP\ mask\fP,\fP\ p )
  320. .I Draw
  321. is the standard drawing function.
  322. Only those pixels within the intersection of
  323. .IB dst ->r
  324. and
  325. .IB dst ->clipr
  326. will be affected;
  327. .I draw
  328. ignores
  329. .IB dst ->repl\fR.
  330. The operation proceeds as follows
  331. (this is a description of the behavior, not the implementation):
  332. .RS
  333. .IP 1.
  334. If
  335. .B repl
  336. is set in
  337. .I src
  338. or
  339. .IR mask ,
  340. replicate their contents to fill
  341. their clip rectangles.
  342. .IP 2.
  343. Translate
  344. .I src
  345. and
  346. .I mask
  347. so
  348. .I p
  349. is aligned with
  350. .IB r .min\fR.
  351. .IP 3.
  352. Set
  353. .I r
  354. to the intersection of
  355. .I r
  356. and
  357. .IB dst ->r\fR.
  358. .IP 4.
  359. Intersect
  360. .I r
  361. with
  362. .IB src ->clipr\fR.
  363. If
  364. .IB src ->repl
  365. is false, also intersect
  366. .I r
  367. with
  368. .IB src ->r\fR.
  369. .IP 5.
  370. Intersect
  371. .I r
  372. with
  373. .IB mask ->clipr\fR.
  374. If
  375. .IB mask ->repl
  376. is false, also intersect
  377. .I r
  378. with
  379. .IB mask ->r\fR.
  380. .IP 6.
  381. For each location in
  382. .IR r ,
  383. combine the
  384. .I dst
  385. pixel with the
  386. .I src
  387. pixel using the alpha value
  388. corresponding to the
  389. .I mask
  390. pixel.
  391. If the
  392. .I mask
  393. has an explicit alpha channel, the alpha value
  394. corresponding to the
  395. .I mask
  396. pixel is simply that pixel's alpha channel.
  397. Otherwise, the alpha value is the NTSC greyscale equivalent
  398. of the color value, with white meaning opaque and black transparent.
  399. In terms of the Porter-Duff compositing algebra,
  400. .I draw
  401. replaces the
  402. .I dst
  403. pixels with
  404. .RI ( src
  405. in
  406. .IR mask )
  407. over
  408. .IR dst .
  409. (In the extended form,
  410. ``over'' is replaced by
  411. .IR op ).
  412. .RE
  413. .IP
  414. The various
  415. pixel channel formats
  416. involved need not be identical.
  417. If the channels involved are smaller than 8-bits, they will
  418. be promoted before the calculation by replicating the extant bits;
  419. after the calculation, they will be truncated to their proper sizes.
  420. .TP
  421. \f5gendraw(\f2dst\fP, \f2r\fP, \f2src\fP, \f2p0\fP, \f2mask\fP, \f2p1\f5)\fP
  422. Similar to
  423. .I draw
  424. except that
  425. .I gendraw
  426. aligns the source and mask differently:
  427. .I src
  428. is aligned so
  429. .I p0
  430. corresponds to
  431. .IB r .min
  432. and
  433. .I mask
  434. is aligned so
  435. .I p1
  436. corresponds to
  437. .IB r .min .
  438. For most purposes with simple masks and source images,
  439. .B draw
  440. is sufficient, but
  441. .B gendraw
  442. is the general operator and the one all other drawing primitives are built upon.
  443. .TP
  444. .BI drawreplxy( min , max , x\f5)
  445. Clips
  446. .I x
  447. to be in the half-open interval [\fImin\fP, \fImax\fP) by adding
  448. or subtracting a multiple of \fImax-min\fP.
  449. .TP
  450. .BI drawrepl( r , p )
  451. Clips the point \fIp\fP to be within the rectangle \fIr\fP
  452. by translating the point horizontally by an integer multiple of rectangle width
  453. and vertically by the height.
  454. .TP
  455. .BI replclipr( i , repl , clipr\f5)
  456. Because the image data is stored on the server, local modifications to the
  457. .B Image
  458. data structure itself will have no effect.
  459. .I Repclipr
  460. modifies the local
  461. .B Image
  462. data structure's
  463. .B repl
  464. and
  465. .B clipr
  466. fields, and notifies the server of their modification.
  467. .TP
  468. \f5line(\f2dst\fP, \f2p0\fP, \f2p1\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
  469. Line
  470. draws in
  471. .I dst
  472. a line of width
  473. .RI 1+2* thick
  474. pixels joining points
  475. .I p0
  476. and
  477. .IR p1 .
  478. The line is drawn using pixels from the
  479. .I src
  480. image aligned so
  481. .I sp
  482. in the source corresponds to
  483. .I p0
  484. in the destination.
  485. The line touches both
  486. .I p0
  487. and
  488. .IR p1 ,
  489. and
  490. .I end0
  491. and
  492. .I end1
  493. specify how the ends of the line are drawn.
  494. .B Endsquare
  495. terminates the line perpendicularly to the direction of the line; a thick line with
  496. .B Endsquare
  497. on both ends will be a rectangle.
  498. .B Enddisc
  499. terminates the line by drawing a disc of diameter
  500. .RI 1+2* thick
  501. centered on the end point.
  502. .B Endarrow
  503. terminates the line with an arrowhead whose tip touches the endpoint.
  504. .IP
  505. The macro
  506. .B ARROW
  507. permits explicit control of the shape of the arrow.
  508. If all three parameters are zero, it produces the default arrowhead,
  509. otherwise,
  510. .I a
  511. sets the distance along line from end of the regular line to tip,
  512. .I b
  513. sets the distance along line from the barb to the tip,
  514. and
  515. .I c
  516. sets the distance perpendicular to the line from edge of line to the tip of the barb,
  517. all in pixels.
  518. .IP
  519. .I Line
  520. and the other geometrical operators are equivalent to calls to
  521. .I gendraw
  522. using a mask produced by the geometric procedure.
  523. .TP
  524. \f5poly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
  525. .I Poly
  526. draws a general polygon; it
  527. is conceptually equivalent to a series of calls to
  528. .I line
  529. joining adjacent points in the
  530. array of
  531. .B Points
  532. .IR p ,
  533. which has
  534. .I np
  535. elements.
  536. The ends of the polygon are specified as in
  537. .IR line ;
  538. interior lines are terminated with
  539. .B Enddisc
  540. to make smooth joins.
  541. The source is aligned so
  542. .I sp
  543. corresponds to
  544. .IB p [0]\f1.
  545. .TP
  546. \f5fillpoly(\f2dst\fP, \f2p\fP, \f2np\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
  547. .I Fillpoly
  548. is like
  549. .I poly
  550. but fills in the resulting polygon rather than outlining it.
  551. The source is aligned so
  552. .I sp
  553. corresponds to
  554. .IB p [0]\f1.
  555. The winding rule parameter
  556. .I wind
  557. resolves ambiguities about what to fill if the polygon is self-intersecting.
  558. If
  559. .I wind
  560. is
  561. .BR ~0 ,
  562. a pixel is inside the polygon if the polygon's winding number about the point
  563. is non-zero.
  564. If
  565. .I wind
  566. is
  567. .BR 1 ,
  568. a pixel is inside if the winding number is odd.
  569. Complementary values (0 or ~1) cause outside pixels to be filled.
  570. The meaning of other values is undefined.
  571. The polygon is closed with a line if necessary.
  572. .TP
  573. \f5bezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
  574. .I Bezier
  575. draws the
  576. cubic Bezier curve defined by
  577. .B Points
  578. .IR a ,
  579. .IR b ,
  580. .IR c ,
  581. and
  582. .IR d .
  583. The end styles are determined by
  584. .I end0
  585. and
  586. .IR end1 ;
  587. the thickness of the curve is
  588. .RI 1+2* thick .
  589. The source is aligned so
  590. .I sp
  591. in
  592. .I src
  593. corresponds to
  594. .I a
  595. in
  596. .IR dst .
  597. .TP
  598. \f5bezspline(\f2dst\fP, \f2p\fP, \f2end0\fP, \f2end1\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
  599. .I Bezspline
  600. takes the same arguments as
  601. .I poly
  602. but draws a quadratic B-spline (despite its name) rather than a polygon.
  603. If the first and last points in
  604. .I p
  605. are equal, the spline has periodic end conditions.
  606. .TP
  607. \f5bezsplinepts(\f2pt\fP, \f2npt\fP, \f2pp\fP)
  608. .I Bezsplinepts
  609. returns in
  610. .I pp
  611. a list of points making up the open polygon that
  612. .I bezspline
  613. would draw.
  614. The caller is responsible for freeing
  615. .IR *pp .
  616. .TP
  617. \f5fillbezier(\f2dst\fP, \f2a\fP, \f2b\fP, \f2c\fP, \f2d\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
  618. .I Fillbezier
  619. is to
  620. .I bezier
  621. as
  622. .I fillpoly
  623. is to
  624. .IR poly .
  625. .TP
  626. \f5fillbezspline(\f2dst\fP, \f2p\fP, \f2wind\fP, \f2src\fP, \f2sp\fP)
  627. .I Fillbezspline
  628. is like
  629. .I fillpoly
  630. but fills the quadratic B-spline rather than the polygon outlined by
  631. .IR p .
  632. The spline is closed with a line if necessary.
  633. .TP
  634. \f5ellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP)
  635. .I Ellipse
  636. draws in
  637. .I dst
  638. an ellipse centered on
  639. .I c
  640. with horizontal and vertical semiaxes
  641. .I a
  642. and
  643. .IR b .
  644. The source is aligned so
  645. .I sp
  646. in
  647. .I src
  648. corresponds to
  649. .I c
  650. in
  651. .IR dst .
  652. The ellipse is drawn with thickness
  653. .RI 1+2* thick .
  654. .TP
  655. \f5fillellipse(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP)
  656. .I Fillellipse
  657. is like
  658. .I ellipse
  659. but fills the ellipse rather than outlining it.
  660. .TP
  661. \f5arc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2thick\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
  662. .I Arc
  663. is like
  664. .IR ellipse ,
  665. but draws only that portion of the ellipse starting at angle
  666. .I alpha
  667. and extending through an angle of
  668. .IR phi .
  669. The angles are measured in degrees counterclockwise from the positive
  670. .I x
  671. axis.
  672. .TP
  673. \f5fillarc(\f2dst\fP, \f2c\fP, \f2a\fP, \f2b\fP, \f2src\fP, \f2sp\fP, \f2alpha\fP, \f2phi\fP)
  674. .I Fillarc
  675. is like
  676. .IR arc ,
  677. but fills the sector with the source color.
  678. .TP
  679. \f5icossin(\f2deg\fP, \f2cosp\fP, \f2sinp\fP)
  680. .I Icossin
  681. stores in
  682. .BI * cosp
  683. and
  684. .BI * sinp
  685. scaled integers representing the cosine and sine of the angle
  686. .IR deg ,
  687. measured in integer degrees.
  688. The values are scaled so cos(0) is 1024.
  689. .TP
  690. \f5icossin2(\f2x\fP, \f2y\fP, \f2cosp\fP, \f2sinp\fP)
  691. .I Icossin2
  692. is analogous to
  693. .IR icossin,
  694. with the angle represented not in degrees but implicitly by the point
  695. .RI ( x , y ).
  696. It is to
  697. .I icossin
  698. what
  699. .B atan2
  700. is to
  701. .B atan
  702. (see
  703. .IR sin (2)).
  704. .TP
  705. .BI border( dst\fP,\fP\ r\fP,\fP\ i\fP,\fP\ color\fP,\fP\ sp\fP)
  706. .I Border
  707. draws an outline of rectangle
  708. .I r
  709. in the specified
  710. .IR color .
  711. The outline has width
  712. .IR i ;
  713. if positive, the border goes inside the rectangle; negative, outside.
  714. The source is aligned so
  715. .I sp
  716. corresponds to
  717. .IB r .min .
  718. .TP
  719. .BI string( dst\fP,\fP\ p\fP,\fP\ src\fP,\fP\ sp\fP,\fP\ font\fP,\fP\ s )
  720. .I String
  721. draws in
  722. .I dst
  723. characters specified by the string
  724. .I s
  725. and
  726. .IR font ;
  727. it is equivalent to a series of calls to
  728. .I gendraw
  729. using source
  730. .I src
  731. and masks determined by the character shapes.
  732. The text is positioned with the left of the first character at
  733. .IB p .x
  734. and the top of the line of text at
  735. .IB p .y\f1.
  736. The source is positioned so
  737. .I sp
  738. in
  739. .I src
  740. corresponds to
  741. .I p
  742. in
  743. .IR dst .
  744. .I String
  745. returns a
  746. .B Point
  747. that is the position of the next character that would be drawn if the string were longer.
  748. .IP
  749. For characters with undefined
  750. or zero-width images in the font, the character at font position 0 (NUL) is drawn.
  751. .IP
  752. The other string routines are variants of this basic form, and
  753. have names that encode their variant behavior.
  754. Routines whose names contain
  755. .B rune
  756. accept a string of Runes rather than
  757. .SM UTF\c
  758. -encoded bytes.
  759. Routines ending in
  760. .B n
  761. accept an argument,
  762. .IR n ,
  763. that defines the number of characters to draw rather than accepting a NUL-terminated
  764. string.
  765. Routines containing
  766. .B bg
  767. draw the background behind the characters in the specified color
  768. .RI ( bg )
  769. and
  770. alignment
  771. .RI ( bgp );
  772. normally the text is drawn leaving the background intact.
  773. .IP
  774. The routine
  775. .I _string
  776. captures all this behavior into a single operator. Whether it draws a
  777. .SM UTF
  778. string
  779. or Rune string depends on whether
  780. .I s
  781. or
  782. .I r
  783. is null (the string length is always determined by
  784. .IR len ).
  785. If
  786. .I bg
  787. is non-null, it is used as a background color.
  788. The
  789. .I clipr
  790. argument allows further management of clipping when drawing the string;
  791. it is intersected with the usual clipping rectangles to further limit the extent of the text.
  792. .TP
  793. .BI drawsetdebug( on )
  794. Turns on or off debugging output (usually
  795. to a serial line) according to whether
  796. .I on
  797. is non-zero.
  798. .SH SOURCE
  799. .B /sys/src/libdraw
  800. .SH SEE ALSO
  801. .IR graphics (2),
  802. .IR stringsize (2),
  803. .IR color (6),
  804. .IR utf (6),
  805. .IR addpt (2)
  806. .PP
  807. T. Porter, T. Duff.
  808. ``Compositing Digital Images'',
  809. .I "Computer Graphics
  810. (Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.
  811. .SH DIAGNOSTICS
  812. These routines call the graphics error function on fatal errors.
  813. .SH BUGS
  814. Anti-aliased characters can be drawn by defining a font
  815. with multiple bits per pixel, but there are
  816. no anti-aliasing geometric primitives.