mizerarc.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  1. /************************************************************
  2. Copyright 1989, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Author: Bob Scheifler, MIT X Consortium
  20. ********************************************************/
  21. /* Derived from:
  22. * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
  23. * by M. L. V. Pitteway
  24. * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
  25. */
  26. #ifdef HAVE_DIX_CONFIG_H
  27. #include <dix-config.h>
  28. #endif
  29. #include <math.h>
  30. #include <X11/X.h>
  31. #include <X11/Xprotostr.h>
  32. #include "regionstr.h"
  33. #include "gcstruct.h"
  34. #include "pixmapstr.h"
  35. #include "mi.h"
  36. #include "mizerarc.h"
  37. #define FULLCIRCLE (360 * 64)
  38. #define OCTANT (45 * 64)
  39. #define QUADRANT (90 * 64)
  40. #define HALFCIRCLE (180 * 64)
  41. #define QUADRANT3 (270 * 64)
  42. #ifndef M_PI
  43. #define M_PI 3.14159265358979323846
  44. #endif
  45. #define Dsin(d) ((d) == 0 ? 0.0 : ((d) == QUADRANT ? 1.0 : \
  46. ((d) == HALFCIRCLE ? 0.0 : \
  47. ((d) == QUADRANT3 ? -1.0 : sin((double)d*(M_PI/11520.0))))))
  48. #define Dcos(d) ((d) == 0 ? 1.0 : ((d) == QUADRANT ? 0.0 : \
  49. ((d) == HALFCIRCLE ? -1.0 : \
  50. ((d) == QUADRANT3 ? 0.0 : cos((double)d*(M_PI/11520.0))))))
  51. #define EPSILON45 64
  52. typedef struct {
  53. int skipStart;
  54. int haveStart;
  55. DDXPointRec startPt;
  56. int haveLast;
  57. int skipLast;
  58. DDXPointRec endPt;
  59. int dashIndex;
  60. int dashOffset;
  61. int dashIndexInit;
  62. int dashOffsetInit;
  63. } DashInfo;
  64. static miZeroArcPtRec oob = {65536, 65536, 0};
  65. /*
  66. * (x - l)^2 / (W/2)^2 + (y + H/2)^2 / (H/2)^2 = 1
  67. *
  68. * where l is either 0 or .5
  69. *
  70. * alpha = 4(W^2)
  71. * beta = 4(H^2)
  72. * gamma = 0
  73. * u = 2(W^2)H
  74. * v = 4(H^2)l
  75. * k = -4(H^2)(l^2)
  76. *
  77. */
  78. _X_EXPORT Bool
  79. miZeroArcSetup(arc, info, ok360)
  80. xArc *arc;
  81. miZeroArcRec *info;
  82. Bool ok360;
  83. {
  84. int l;
  85. int angle1, angle2;
  86. int startseg, endseg;
  87. int startAngle, endAngle;
  88. int i, overlap;
  89. miZeroArcPtRec start, end;
  90. l = arc->width & 1;
  91. if (arc->width == arc->height)
  92. {
  93. info->alpha = 4;
  94. info->beta = 4;
  95. info->k1 = -8;
  96. info->k3 = -16;
  97. info->b = 12;
  98. info->a = (arc->width << 2) - 12;
  99. info->d = 17 - (arc->width << 1);
  100. if (l)
  101. {
  102. info->b -= 4;
  103. info->a += 4;
  104. info->d -= 7;
  105. }
  106. }
  107. else if (!arc->width || !arc->height)
  108. {
  109. info->alpha = 0;
  110. info->beta = 0;
  111. info->k1 = 0;
  112. info->k3 = 0;
  113. info->a = -(int)arc->height;
  114. info->b = 0;
  115. info->d = -1;
  116. }
  117. else
  118. {
  119. /* initial conditions */
  120. info->alpha = (arc->width * arc->width) << 2;
  121. info->beta = (arc->height * arc->height) << 2;
  122. info->k1 = info->beta << 1;
  123. info->k3 = info->k1 + (info->alpha << 1);
  124. info->b = l ? 0 : -info->beta;
  125. info->a = info->alpha * arc->height;
  126. info->d = info->b - (info->a >> 1) - (info->alpha >> 2);
  127. if (l)
  128. info->d -= info->beta >> 2;
  129. info->a -= info->b;
  130. /* take first step, d < 0 always */
  131. info->b -= info->k1;
  132. info->a += info->k1;
  133. info->d += info->b;
  134. /* octant change, b < 0 always */
  135. info->k1 = -info->k1;
  136. info->k3 = -info->k3;
  137. info->b = -info->b;
  138. info->d = info->b - info->a - info->d;
  139. info->a = info->a - (info->b << 1);
  140. }
  141. info->dx = 1;
  142. info->dy = 0;
  143. info->w = (arc->width + 1) >> 1;
  144. info->h = arc->height >> 1;
  145. info->xorg = arc->x + (arc->width >> 1);
  146. info->yorg = arc->y;
  147. info->xorgo = info->xorg + l;
  148. info->yorgo = info->yorg + arc->height;
  149. if (!arc->width)
  150. {
  151. if (!arc->height)
  152. {
  153. info->x = 0;
  154. info->y = 0;
  155. info->initialMask = 0;
  156. info->startAngle = 0;
  157. info->endAngle = 0;
  158. info->start = oob;
  159. info->end = oob;
  160. return FALSE;
  161. }
  162. info->x = 0;
  163. info->y = 1;
  164. }
  165. else
  166. {
  167. info->x = 1;
  168. info->y = 0;
  169. }
  170. angle1 = arc->angle1;
  171. angle2 = arc->angle2;
  172. if ((angle1 == 0) && (angle2 >= FULLCIRCLE))
  173. {
  174. startAngle = 0;
  175. endAngle = 0;
  176. }
  177. else
  178. {
  179. if (angle2 > FULLCIRCLE)
  180. angle2 = FULLCIRCLE;
  181. else if (angle2 < -FULLCIRCLE)
  182. angle2 = -FULLCIRCLE;
  183. if (angle2 < 0)
  184. {
  185. startAngle = angle1 + angle2;
  186. endAngle = angle1;
  187. }
  188. else
  189. {
  190. startAngle = angle1;
  191. endAngle = angle1 + angle2;
  192. }
  193. if (startAngle < 0)
  194. startAngle = FULLCIRCLE - (-startAngle) % FULLCIRCLE;
  195. if (startAngle >= FULLCIRCLE)
  196. startAngle = startAngle % FULLCIRCLE;
  197. if (endAngle < 0)
  198. endAngle = FULLCIRCLE - (-endAngle) % FULLCIRCLE;
  199. if (endAngle >= FULLCIRCLE)
  200. endAngle = endAngle % FULLCIRCLE;
  201. }
  202. info->startAngle = startAngle;
  203. info->endAngle = endAngle;
  204. if (ok360 && (startAngle == endAngle) && arc->angle2 &&
  205. arc->width && arc->height)
  206. {
  207. info->initialMask = 0xf;
  208. info->start = oob;
  209. info->end = oob;
  210. return TRUE;
  211. }
  212. startseg = startAngle / OCTANT;
  213. if (!arc->height || (((startseg + 1) & 2) && arc->width))
  214. {
  215. start.x = Dcos(startAngle) * ((arc->width + 1) / 2.0);
  216. if (start.x < 0)
  217. start.x = -start.x;
  218. start.y = -1;
  219. }
  220. else
  221. {
  222. start.y = Dsin(startAngle) * (arc->height / 2.0);
  223. if (start.y < 0)
  224. start.y = -start.y;
  225. start.y = info->h - start.y;
  226. start.x = 65536;
  227. }
  228. endseg = endAngle / OCTANT;
  229. if (!arc->height || (((endseg + 1) & 2) && arc->width))
  230. {
  231. end.x = Dcos(endAngle) * ((arc->width + 1) / 2.0);
  232. if (end.x < 0)
  233. end.x = -end.x;
  234. end.y = -1;
  235. }
  236. else
  237. {
  238. end.y = Dsin(endAngle) * (arc->height / 2.0);
  239. if (end.y < 0)
  240. end.y = -end.y;
  241. end.y = info->h - end.y;
  242. end.x = 65536;
  243. }
  244. info->firstx = start.x;
  245. info->firsty = start.y;
  246. info->initialMask = 0;
  247. overlap = arc->angle2 && (endAngle <= startAngle);
  248. for (i = 0; i < 4; i++)
  249. {
  250. if (overlap ?
  251. ((i * QUADRANT <= endAngle) || ((i + 1) * QUADRANT > startAngle)) :
  252. ((i * QUADRANT <= endAngle) && ((i + 1) * QUADRANT > startAngle)))
  253. info->initialMask |= (1 << i);
  254. }
  255. start.mask = info->initialMask;
  256. end.mask = info->initialMask;
  257. startseg >>= 1;
  258. endseg >>= 1;
  259. overlap = overlap && (endseg == startseg);
  260. if (start.x != end.x || start.y != end.y || !overlap)
  261. {
  262. if (startseg & 1)
  263. {
  264. if (!overlap)
  265. info->initialMask &= ~(1 << startseg);
  266. if (start.x > end.x || start.y > end.y)
  267. end.mask &= ~(1 << startseg);
  268. }
  269. else
  270. {
  271. start.mask &= ~(1 << startseg);
  272. if (((start.x < end.x || start.y < end.y) ||
  273. (start.x == end.x && start.y == end.y && (endseg & 1))) &&
  274. !overlap)
  275. end.mask &= ~(1 << startseg);
  276. }
  277. if (endseg & 1)
  278. {
  279. end.mask &= ~(1 << endseg);
  280. if (((start.x > end.x || start.y > end.y) ||
  281. (start.x == end.x && start.y == end.y && !(startseg & 1))) &&
  282. !overlap)
  283. start.mask &= ~(1 << endseg);
  284. }
  285. else
  286. {
  287. if (!overlap)
  288. info->initialMask &= ~(1 << endseg);
  289. if (start.x < end.x || start.y < end.y)
  290. start.mask &= ~(1 << endseg);
  291. }
  292. }
  293. /* take care of case when start and stop are both near 45 */
  294. /* handle here rather than adding extra code to pixelization loops */
  295. if (startAngle &&
  296. ((start.y < 0 && end.y >= 0) || (start.y >= 0 && end.y < 0)))
  297. {
  298. i = (startAngle + OCTANT) % OCTANT;
  299. if (i < EPSILON45 || i > OCTANT - EPSILON45)
  300. {
  301. i = (endAngle + OCTANT) % OCTANT;
  302. if (i < EPSILON45 || i > OCTANT - EPSILON45)
  303. {
  304. if (start.y < 0)
  305. {
  306. i = Dsin(startAngle) * (arc->height / 2.0);
  307. if (i < 0)
  308. i = -i;
  309. if (info->h - i == end.y)
  310. start.mask = end.mask;
  311. }
  312. else
  313. {
  314. i = Dsin(endAngle) * (arc->height / 2.0);
  315. if (i < 0)
  316. i = -i;
  317. if (info->h - i == start.y)
  318. end.mask = start.mask;
  319. }
  320. }
  321. }
  322. }
  323. if (startseg & 1)
  324. {
  325. info->start = start;
  326. info->end = oob;
  327. }
  328. else
  329. {
  330. info->end = start;
  331. info->start = oob;
  332. }
  333. if (endseg & 1)
  334. {
  335. info->altend = end;
  336. if (info->altend.x < info->end.x || info->altend.y < info->end.y)
  337. {
  338. miZeroArcPtRec tmp;
  339. tmp = info->altend;
  340. info->altend = info->end;
  341. info->end = tmp;
  342. }
  343. info->altstart = oob;
  344. }
  345. else
  346. {
  347. info->altstart = end;
  348. if (info->altstart.x < info->start.x ||
  349. info->altstart.y < info->start.y)
  350. {
  351. miZeroArcPtRec tmp;
  352. tmp = info->altstart;
  353. info->altstart = info->start;
  354. info->start = tmp;
  355. }
  356. info->altend = oob;
  357. }
  358. if (!info->start.x || !info->start.y)
  359. {
  360. info->initialMask = info->start.mask;
  361. info->start = info->altstart;
  362. }
  363. if (!arc->width && (arc->height == 1))
  364. {
  365. /* kludge! */
  366. info->initialMask |= info->end.mask;
  367. info->initialMask |= info->initialMask << 1;
  368. info->end.x = 0;
  369. info->end.mask = 0;
  370. }
  371. return FALSE;
  372. }
  373. #define Pixelate(xval,yval) \
  374. { \
  375. pts->x = xval; \
  376. pts->y = yval; \
  377. pts++; \
  378. }
  379. #define DoPix(idx,xval,yval) if (mask & (1 << idx)) Pixelate(xval, yval);
  380. DDXPointPtr
  381. miZeroArcPts(arc, pts)
  382. xArc *arc;
  383. DDXPointPtr pts;
  384. {
  385. miZeroArcRec info;
  386. int x, y, a, b, d, mask;
  387. int k1, k3, dx, dy;
  388. Bool do360;
  389. do360 = miZeroArcSetup(arc, &info, TRUE);
  390. MIARCSETUP();
  391. mask = info.initialMask;
  392. if (!(arc->width & 1))
  393. {
  394. DoPix(1, info.xorgo, info.yorg);
  395. DoPix(3, info.xorgo, info.yorgo);
  396. }
  397. if (!info.end.x || !info.end.y)
  398. {
  399. mask = info.end.mask;
  400. info.end = info.altend;
  401. }
  402. if (do360 && (arc->width == arc->height) && !(arc->width & 1))
  403. {
  404. int yorgh = info.yorg + info.h;
  405. int xorghp = info.xorg + info.h;
  406. int xorghn = info.xorg - info.h;
  407. while (1)
  408. {
  409. Pixelate(info.xorg + x, info.yorg + y);
  410. Pixelate(info.xorg - x, info.yorg + y);
  411. Pixelate(info.xorg - x, info.yorgo - y);
  412. Pixelate(info.xorg + x, info.yorgo - y);
  413. if (a < 0)
  414. break;
  415. Pixelate(xorghp - y, yorgh - x);
  416. Pixelate(xorghn + y, yorgh - x);
  417. Pixelate(xorghn + y, yorgh + x);
  418. Pixelate(xorghp - y, yorgh + x);
  419. MIARCCIRCLESTEP(;);
  420. }
  421. if (x > 1 && pts[-1].x == pts[-5].x && pts[-1].y == pts[-5].y)
  422. pts -= 4;
  423. x = info.w;
  424. y = info.h;
  425. }
  426. else if (do360)
  427. {
  428. while (y < info.h || x < info.w)
  429. {
  430. MIARCOCTANTSHIFT(;);
  431. Pixelate(info.xorg + x, info.yorg + y);
  432. Pixelate(info.xorgo - x, info.yorg + y);
  433. Pixelate(info.xorgo - x, info.yorgo - y);
  434. Pixelate(info.xorg + x, info.yorgo - y);
  435. MIARCSTEP(;,;);
  436. }
  437. }
  438. else
  439. {
  440. while (y < info.h || x < info.w)
  441. {
  442. MIARCOCTANTSHIFT(;);
  443. if ((x == info.start.x) || (y == info.start.y))
  444. {
  445. mask = info.start.mask;
  446. info.start = info.altstart;
  447. }
  448. DoPix(0, info.xorg + x, info.yorg + y);
  449. DoPix(1, info.xorgo - x, info.yorg + y);
  450. DoPix(2, info.xorgo - x, info.yorgo - y);
  451. DoPix(3, info.xorg + x, info.yorgo - y);
  452. if ((x == info.end.x) || (y == info.end.y))
  453. {
  454. mask = info.end.mask;
  455. info.end = info.altend;
  456. }
  457. MIARCSTEP(;,;);
  458. }
  459. }
  460. if ((x == info.start.x) || (y == info.start.y))
  461. mask = info.start.mask;
  462. DoPix(0, info.xorg + x, info.yorg + y);
  463. DoPix(2, info.xorgo - x, info.yorgo - y);
  464. if (arc->height & 1)
  465. {
  466. DoPix(1, info.xorgo - x, info.yorg + y);
  467. DoPix(3, info.xorg + x, info.yorgo - y);
  468. }
  469. return pts;
  470. }
  471. #undef DoPix
  472. #define DoPix(idx,xval,yval) \
  473. if (mask & (1 << idx)) \
  474. { \
  475. arcPts[idx]->x = xval; \
  476. arcPts[idx]->y = yval; \
  477. arcPts[idx]++; \
  478. }
  479. static void
  480. miZeroArcDashPts(
  481. GCPtr pGC,
  482. xArc *arc,
  483. DashInfo *dinfo,
  484. register DDXPointPtr points,
  485. int maxPts,
  486. register DDXPointPtr *evenPts,
  487. register DDXPointPtr *oddPts )
  488. {
  489. miZeroArcRec info;
  490. int x, y, a, b, d, mask;
  491. int k1, k3, dx, dy;
  492. int dashRemaining;
  493. DDXPointPtr arcPts[4];
  494. DDXPointPtr startPts[5], endPts[5];
  495. int deltas[5];
  496. DDXPointPtr startPt, pt, lastPt, pts;
  497. int i, j, delta, ptsdelta, seg, startseg;
  498. for (i = 0; i < 4; i++)
  499. arcPts[i] = points + (i * maxPts);
  500. (void)miZeroArcSetup(arc, &info, FALSE);
  501. MIARCSETUP();
  502. mask = info.initialMask;
  503. startseg = info.startAngle / QUADRANT;
  504. startPt = arcPts[startseg];
  505. if (!(arc->width & 1))
  506. {
  507. DoPix(1, info.xorgo, info.yorg);
  508. DoPix(3, info.xorgo, info.yorgo);
  509. }
  510. if (!info.end.x || !info.end.y)
  511. {
  512. mask = info.end.mask;
  513. info.end = info.altend;
  514. }
  515. while (y < info.h || x < info.w)
  516. {
  517. MIARCOCTANTSHIFT(;);
  518. if ((x == info.firstx) || (y == info.firsty))
  519. startPt = arcPts[startseg];
  520. if ((x == info.start.x) || (y == info.start.y))
  521. {
  522. mask = info.start.mask;
  523. info.start = info.altstart;
  524. }
  525. DoPix(0, info.xorg + x, info.yorg + y);
  526. DoPix(1, info.xorgo - x, info.yorg + y);
  527. DoPix(2, info.xorgo - x, info.yorgo - y);
  528. DoPix(3, info.xorg + x, info.yorgo - y);
  529. if ((x == info.end.x) || (y == info.end.y))
  530. {
  531. mask = info.end.mask;
  532. info.end = info.altend;
  533. }
  534. MIARCSTEP(;,;);
  535. }
  536. if ((x == info.firstx) || (y == info.firsty))
  537. startPt = arcPts[startseg];
  538. if ((x == info.start.x) || (y == info.start.y))
  539. mask = info.start.mask;
  540. DoPix(0, info.xorg + x, info.yorg + y);
  541. DoPix(2, info.xorgo - x, info.yorgo - y);
  542. if (arc->height & 1)
  543. {
  544. DoPix(1, info.xorgo - x, info.yorg + y);
  545. DoPix(3, info.xorg + x, info.yorgo - y);
  546. }
  547. for (i = 0; i < 4; i++)
  548. {
  549. seg = (startseg + i) & 3;
  550. pt = points + (seg * maxPts);
  551. if (seg & 1)
  552. {
  553. startPts[i] = pt;
  554. endPts[i] = arcPts[seg];
  555. deltas[i] = 1;
  556. }
  557. else
  558. {
  559. startPts[i] = arcPts[seg] - 1;
  560. endPts[i] = pt - 1;
  561. deltas[i] = -1;
  562. }
  563. }
  564. startPts[4] = startPts[0];
  565. endPts[4] = startPt;
  566. startPts[0] = startPt;
  567. if (startseg & 1)
  568. {
  569. if (startPts[4] != endPts[4])
  570. endPts[4]--;
  571. deltas[4] = 1;
  572. }
  573. else
  574. {
  575. if (startPts[0] > startPts[4])
  576. startPts[0]--;
  577. if (startPts[4] < endPts[4])
  578. endPts[4]--;
  579. deltas[4] = -1;
  580. }
  581. if (arc->angle2 < 0)
  582. {
  583. DDXPointPtr tmps, tmpe;
  584. int tmpd;
  585. tmpd = deltas[0];
  586. tmps = startPts[0] - tmpd;
  587. tmpe = endPts[0] - tmpd;
  588. startPts[0] = endPts[4] - deltas[4];
  589. endPts[0] = startPts[4] - deltas[4];
  590. deltas[0] = -deltas[4];
  591. startPts[4] = tmpe;
  592. endPts[4] = tmps;
  593. deltas[4] = -tmpd;
  594. tmpd = deltas[1];
  595. tmps = startPts[1] - tmpd;
  596. tmpe = endPts[1] - tmpd;
  597. startPts[1] = endPts[3] - deltas[3];
  598. endPts[1] = startPts[3] - deltas[3];
  599. deltas[1] = -deltas[3];
  600. startPts[3] = tmpe;
  601. endPts[3] = tmps;
  602. deltas[3] = -tmpd;
  603. tmps = startPts[2] - deltas[2];
  604. startPts[2] = endPts[2] - deltas[2];
  605. endPts[2] = tmps;
  606. deltas[2] = -deltas[2];
  607. }
  608. for (i = 0; i < 5 && startPts[i] == endPts[i]; i++)
  609. ;
  610. if (i == 5)
  611. return;
  612. pt = startPts[i];
  613. for (j = 4; startPts[j] == endPts[j]; j--)
  614. ;
  615. lastPt = endPts[j] - deltas[j];
  616. if (dinfo->haveLast &&
  617. (pt->x == dinfo->endPt.x) && (pt->y == dinfo->endPt.y))
  618. {
  619. startPts[i] += deltas[i];
  620. }
  621. else
  622. {
  623. dinfo->dashIndex = dinfo->dashIndexInit;
  624. dinfo->dashOffset = dinfo->dashOffsetInit;
  625. }
  626. if (!dinfo->skipStart && (info.startAngle != info.endAngle))
  627. {
  628. dinfo->startPt = *pt;
  629. dinfo->haveStart = TRUE;
  630. }
  631. else if (!dinfo->skipLast && dinfo->haveStart &&
  632. (lastPt->x == dinfo->startPt.x) &&
  633. (lastPt->y == dinfo->startPt.y) &&
  634. (lastPt != startPts[i]))
  635. endPts[j] = lastPt;
  636. if (info.startAngle != info.endAngle)
  637. {
  638. dinfo->haveLast = TRUE;
  639. dinfo->endPt = *lastPt;
  640. }
  641. dashRemaining = pGC->dash[dinfo->dashIndex] - dinfo->dashOffset;
  642. for (i = 0; i < 5; i++)
  643. {
  644. pt = startPts[i];
  645. lastPt = endPts[i];
  646. delta = deltas[i];
  647. while (pt != lastPt)
  648. {
  649. if (dinfo->dashIndex & 1)
  650. {
  651. pts = *oddPts;
  652. ptsdelta = -1;
  653. }
  654. else
  655. {
  656. pts = *evenPts;
  657. ptsdelta = 1;
  658. }
  659. while ((pt != lastPt) && --dashRemaining >= 0)
  660. {
  661. *pts = *pt;
  662. pts += ptsdelta;
  663. pt += delta;
  664. }
  665. if (dinfo->dashIndex & 1)
  666. *oddPts = pts;
  667. else
  668. *evenPts = pts;
  669. if (dashRemaining <= 0)
  670. {
  671. if (++(dinfo->dashIndex) == pGC->numInDashList)
  672. dinfo->dashIndex = 0;
  673. dashRemaining = pGC->dash[dinfo->dashIndex];
  674. }
  675. }
  676. }
  677. dinfo->dashOffset = pGC->dash[dinfo->dashIndex] - dashRemaining;
  678. }
  679. _X_EXPORT void
  680. miZeroPolyArc(pDraw, pGC, narcs, parcs)
  681. DrawablePtr pDraw;
  682. GCPtr pGC;
  683. int narcs;
  684. xArc *parcs;
  685. {
  686. int maxPts = 0;
  687. int n, maxw = 0;
  688. xArc *arc;
  689. int i;
  690. DDXPointPtr points, pts, oddPts = NULL;
  691. DDXPointPtr pt;
  692. int numPts;
  693. Bool dospans;
  694. int *widths = NULL;
  695. XID fgPixel = pGC->fgPixel;
  696. DashInfo dinfo;
  697. for (arc = parcs, i = narcs; --i >= 0; arc++)
  698. {
  699. if (!miCanZeroArc(arc))
  700. miPolyArc(pDraw, pGC, 1, arc);
  701. else
  702. {
  703. if (arc->width > arc->height)
  704. n = arc->width + (arc->height >> 1);
  705. else
  706. n = arc->height + (arc->width >> 1);
  707. if (n > maxPts)
  708. maxPts = n;
  709. }
  710. }
  711. if (!maxPts)
  712. return;
  713. numPts = maxPts << 2;
  714. dospans = (pGC->fillStyle != FillSolid);
  715. if (dospans)
  716. {
  717. widths = (int *)ALLOCATE_LOCAL(sizeof(int) * numPts);
  718. if (!widths)
  719. return;
  720. maxw = 0;
  721. }
  722. if (pGC->lineStyle != LineSolid)
  723. {
  724. numPts <<= 1;
  725. dinfo.haveStart = FALSE;
  726. dinfo.skipStart = FALSE;
  727. dinfo.haveLast = FALSE;
  728. dinfo.dashIndexInit = 0;
  729. dinfo.dashOffsetInit = 0;
  730. miStepDash((int)pGC->dashOffset, &dinfo.dashIndexInit,
  731. (unsigned char *) pGC->dash, (int)pGC->numInDashList,
  732. &dinfo.dashOffsetInit);
  733. }
  734. points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * numPts);
  735. if (!points)
  736. {
  737. if (dospans)
  738. {
  739. DEALLOCATE_LOCAL(widths);
  740. }
  741. return;
  742. }
  743. for (arc = parcs, i = narcs; --i >= 0; arc++)
  744. {
  745. if (miCanZeroArc(arc))
  746. {
  747. if (pGC->lineStyle == LineSolid)
  748. pts = miZeroArcPts(arc, points);
  749. else
  750. {
  751. pts = points;
  752. oddPts = &points[(numPts >> 1) - 1];
  753. dinfo.skipLast = i;
  754. miZeroArcDashPts(pGC, arc, &dinfo,
  755. oddPts + 1, maxPts, &pts, &oddPts);
  756. dinfo.skipStart = TRUE;
  757. }
  758. n = pts - points;
  759. if (!dospans)
  760. (*pGC->ops->PolyPoint)(pDraw, pGC, CoordModeOrigin, n, points);
  761. else
  762. {
  763. if (n > maxw)
  764. {
  765. while (maxw < n)
  766. widths[maxw++] = 1;
  767. }
  768. if (pGC->miTranslate)
  769. {
  770. for (pt = points; pt != pts; pt++)
  771. {
  772. pt->x += pDraw->x;
  773. pt->y += pDraw->y;
  774. }
  775. }
  776. (*pGC->ops->FillSpans)(pDraw, pGC, n, points, widths, FALSE);
  777. }
  778. if (pGC->lineStyle != LineDoubleDash)
  779. continue;
  780. if ((pGC->fillStyle == FillSolid) ||
  781. (pGC->fillStyle == FillStippled))
  782. {
  783. DoChangeGC(pGC, GCForeground, (XID *)&pGC->bgPixel, 0);
  784. ValidateGC(pDraw, pGC);
  785. }
  786. pts = &points[numPts >> 1];
  787. oddPts++;
  788. n = pts - oddPts;
  789. if (!dospans)
  790. (*pGC->ops->PolyPoint)(pDraw, pGC, CoordModeOrigin, n, oddPts);
  791. else
  792. {
  793. if (n > maxw)
  794. {
  795. while (maxw < n)
  796. widths[maxw++] = 1;
  797. }
  798. if (pGC->miTranslate)
  799. {
  800. for (pt = oddPts; pt != pts; pt++)
  801. {
  802. pt->x += pDraw->x;
  803. pt->y += pDraw->y;
  804. }
  805. }
  806. (*pGC->ops->FillSpans)(pDraw, pGC, n, oddPts, widths, FALSE);
  807. }
  808. if ((pGC->fillStyle == FillSolid) ||
  809. (pGC->fillStyle == FillStippled))
  810. {
  811. DoChangeGC(pGC, GCForeground, &fgPixel, 0);
  812. ValidateGC(pDraw, pGC);
  813. }
  814. }
  815. }
  816. DEALLOCATE_LOCAL(points);
  817. if (dospans)
  818. {
  819. DEALLOCATE_LOCAL(widths);
  820. }
  821. }