home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mi / mifillarc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  16.8 KB  |  800 lines

  1. /************************************************************
  2. Copyright 1989 by The Massachusetts Institute of Technology
  3.  
  4. Permission to use, copy, modify, and distribute this
  5. software and its documentation for any purpose and without
  6. fee is hereby granted, provided that the above copyright
  7. notice appear in all copies and that both that copyright
  8. notice and this permission notice appear in supporting
  9. documentation, and that the name of MIT not be used in
  10. advertising or publicity pertaining to distribution of the
  11. software without specific prior written permission.
  12. M.I.T. makes no representation about the suitability of
  13. this software for any purpose. It is provided "as is"
  14. without any express or implied warranty.
  15.  
  16. Author:  Bob Scheifler, MIT X Consortium
  17.  
  18. ********************************************************/
  19.  
  20. /* $XConsortium: mifillarc.c,v 5.15 91/07/01 17:02:41 keith Exp $ */
  21.  
  22. #include <math.h>
  23. #include "X.h"
  24. #include "Xprotostr.h"
  25. #include "miscstruct.h"
  26. #include "gcstruct.h"
  27. #include "pixmapstr.h"
  28. #include "mifpoly.h"
  29. #include "mi.h"
  30. #include "mifillarc.h"
  31.  
  32. #define QUADRANT (90 * 64)
  33. #define HALFCIRCLE (180 * 64)
  34. #define QUADRANT3 (270 * 64)
  35.  
  36. #ifndef M_PI
  37. #define M_PI    3.14159265358979323846
  38. #endif
  39.  
  40. #define Dsin(d)    sin((double)d*(M_PI/11520.0))
  41. #define Dcos(d)    cos((double)d*(M_PI/11520.0))
  42.  
  43. /* could use 64-bit integers */
  44. typedef struct _miFillArcD {
  45.     int xorg, yorg;
  46.     int y;
  47.     int dx, dy;
  48.     double e;
  49.     double ym, yk, xm, xk;
  50. } miFillArcDRec;
  51.  
  52. void
  53. miFillArcSetup(arc, info)
  54.     register xArc *arc;
  55.     register miFillArcRec *info;
  56. {
  57.     info->y = arc->height >> 1;
  58.     info->dy = arc->height & 1;
  59.     info->yorg = arc->y + info->y;
  60.     info->dx = arc->width & 1;
  61.     info->xorg = arc->x + (arc->width >> 1) + info->dx;
  62.     info->dx = 1 - info->dx;
  63.     if (arc->width == arc->height)
  64.     {
  65.     /* (2x - 2xorg)^2 = d^2 - (2y - 2yorg)^2 */
  66.     /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
  67.     info->ym = 8;
  68.     info->xm = 8;
  69.     info->yk = info->y << 3;
  70.     if (!info->dx)
  71.     {
  72.         info->xk = 0;
  73.         info->e = -1;
  74.     }
  75.     else
  76.     {
  77.         info->y++;
  78.         info->yk += 4;
  79.         info->xk = -4;
  80.         info->e = - (info->y << 3);
  81.     }
  82.     }
  83.     else
  84.     {
  85.     /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */
  86.     /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
  87.     info->ym = (arc->width * arc->width) << 3;
  88.     info->xm = (arc->height * arc->height) << 3;
  89.     info->yk = info->y * info->ym;
  90.     if (!info->dy)
  91.         info->yk -= info->ym >> 1;
  92.     if (!info->dx)
  93.     {
  94.         info->xk = 0;
  95.         info->e = - (info->xm >> 3);
  96.     }
  97.     else
  98.     {
  99.         info->y++;
  100.         info->yk += info->ym;
  101.         info->xk = -(info->xm >> 1);
  102.         info->e = info->xk - info->yk;
  103.     }
  104.     }
  105. }
  106.  
  107. static void
  108. miFillArcDSetup(arc, info)
  109.     register xArc *arc;
  110.     register miFillArcDRec *info;
  111. {
  112.     /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */
  113.     /* even: xorg = yorg = 0   odd:  xorg = .5, yorg = -.5 */
  114.     info->y = arc->height >> 1;
  115.     info->dy = arc->height & 1;
  116.     info->yorg = arc->y + info->y;
  117.     info->dx = arc->width & 1;
  118.     info->xorg = arc->x + (arc->width >> 1) + info->dx;
  119.     info->dx = 1 - info->dx;
  120.     info->ym = ((double)arc->width) * (arc->width * 8);
  121.     info->xm = ((double)arc->height) * (arc->height * 8);
  122.     info->yk = info->y * info->ym;
  123.     if (!info->dy)
  124.     info->yk -= info->ym / 2.0;
  125.     if (!info->dx)
  126.     {
  127.     info->xk = 0;
  128.     info->e = - (info->xm / 8.0);
  129.     }
  130.     else
  131.     {
  132.     info->y++;
  133.     info->yk += info->ym;
  134.     info->xk = -info->xm / 2.0;
  135.     info->e = info->xk - info->yk;
  136.     }
  137. }
  138.  
  139. static void
  140. miGetArcEdge(arc, edge, k, top, left)
  141.     register xArc *arc;
  142.     register miSliceEdgePtr edge;
  143.     int k;
  144.     Bool top, left;
  145. {
  146.     register int xady, y;
  147.  
  148.     y = arc->height >> 1;
  149.     if (!(arc->width & 1))
  150.     y++;
  151.     if (!top)
  152.     {
  153.     y = -y;
  154.     if (arc->height & 1)
  155.         y--;
  156.     }
  157.     xady = k + y * edge->dx;
  158.     if (xady <= 0)
  159.     edge->x = - ((-xady) / edge->dy + 1);
  160.     else
  161.     edge->x = (xady - 1) / edge->dy;
  162.     edge->e = xady - edge->x * edge->dy;
  163.     if ((top && (edge->dx < 0)) || (!top && (edge->dx > 0)))
  164.     edge->e = edge->dy - edge->e + 1;
  165.     if (left)
  166.     edge->x++;
  167.     edge->x += arc->x + (arc->width >> 1);
  168.     if (edge->dx > 0)
  169.     {
  170.     edge->deltax = 1;
  171.     edge->stepx = edge->dx / edge->dy;
  172.     edge->dx = edge->dx % edge->dy;
  173.     }
  174.     else
  175.     {
  176.     edge->deltax = -1;
  177.     edge->stepx = - ((-edge->dx) / edge->dy);
  178.     edge->dx = (-edge->dx) % edge->dy;
  179.     }
  180.     if (!top)
  181.     {
  182.     edge->deltax = -edge->deltax;
  183.     edge->stepx = -edge->stepx;
  184.     }
  185. }
  186.  
  187. void
  188. miEllipseAngleToSlope (angle, width, height, dxp, dyp, d_dxp, d_dyp)
  189.     int        angle;
  190.     int        width;
  191.     int        height;
  192.     int        *dxp;
  193.     int        *dyp;
  194.     double  *d_dxp;
  195.     double  *d_dyp;
  196. {
  197.     int        dx, dy;
  198.     double  d_dx, d_dy, scale;
  199.     Bool    negative_dx, negative_dy;
  200.  
  201.     switch (angle) {
  202.     case 0:
  203.     *dxp = -1;
  204.     *dyp = 0;
  205.     if (d_dxp) {
  206.         *d_dxp = width / 2.0;
  207.         *d_dyp = 0;
  208.     }
  209.     break;
  210.     case QUADRANT:
  211.     *dxp = 0;
  212.     *dyp = 1;
  213.     if (d_dxp) {
  214.         *d_dxp = 0;
  215.         *d_dyp = - height / 2.0;
  216.     }
  217.     break;
  218.     case HALFCIRCLE:
  219.     *dxp = 1;
  220.     *dyp = 0;
  221.     if (d_dxp) {
  222.         *d_dxp = - width / 2.0;
  223.         *d_dyp = 0;
  224.     }
  225.     break;
  226.     case QUADRANT3:
  227.     *dxp = 0;
  228.     *dyp = -1;
  229.     if (d_dxp) {
  230.         *d_dxp = 0;
  231.         *d_dyp = height / 2.0;
  232.     }
  233.     break;
  234.     default:
  235.     d_dx = Dcos(angle) * width;
  236.     d_dy = Dsin(angle) * height;
  237.     if (d_dxp) {
  238.         *d_dxp = d_dx / 2.0;
  239.         *d_dyp = - d_dy / 2.0;
  240.     }
  241.     negative_dx = FALSE;
  242.     if (d_dx < 0.0)
  243.     {
  244.         d_dx = -d_dx;
  245.         negative_dx = TRUE;
  246.     }
  247.     negative_dy = FALSE;
  248.     if (d_dy < 0.0)
  249.     {
  250.         d_dy = -d_dy;
  251.         negative_dy = TRUE;
  252.     }
  253.     scale = d_dx;
  254.     if (d_dy > d_dx)
  255.         scale = d_dy;
  256.     dx = floor ((d_dx * 32768) / scale + 0.5);
  257.     if (negative_dx)
  258.         dx = -dx;
  259.     *dxp = dx;
  260.     dy = floor ((d_dy * 32768) / scale + 0.5);
  261.     if (negative_dy)
  262.         dy = -dy;
  263.     *dyp = dy;
  264.     break;
  265.     }
  266. }
  267.  
  268. static void
  269. miGetPieEdge(arc, angle, edge, top, left)
  270.     register xArc *arc;
  271.     register int angle;
  272.     register miSliceEdgePtr edge;
  273.     Bool top, left;
  274. {
  275.     register int k, signdx, signdy;
  276.     int    dx, dy;
  277.  
  278.     miEllipseAngleToSlope (angle, arc->width, arc->height, &dx, &dy, 0, 0);
  279.  
  280.     if (dy == 0)
  281.     {
  282.     edge->x = left ? -65536 : 65536;
  283.     edge->stepx = 0;
  284.     edge->e = 0;
  285.     edge->dx = -1;
  286.     return;
  287.     }
  288.     if (dx == 0)
  289.     {
  290.     edge->x = arc->x + (arc->width >> 1);
  291.     if (left && (arc->width & 1))
  292.         edge->x++;
  293.     else if (!left && !(arc->width & 1))
  294.         edge->x--;
  295.     edge->stepx = 0;
  296.     edge->e = 0;
  297.     edge->dx = -1;
  298.     return;
  299.     }
  300.     if (dy < 0) {
  301.     dx = -dx;
  302.     dy = -dy;
  303.     }
  304.     k = (arc->height & 1) ? dx : 0;
  305.     if (arc->width & 1)
  306.     k += dy;
  307.     edge->dx = dx << 1;
  308.     edge->dy = dy << 1;
  309.     miGetArcEdge(arc, edge, k, top, left);
  310. }
  311.  
  312. void
  313. miFillArcSliceSetup(arc, slice, pGC)
  314.     register xArc *arc;
  315.     register miArcSliceRec *slice;
  316.     GCPtr pGC;
  317. {
  318.     register int angle1, angle2;
  319.  
  320.     angle1 = arc->angle1;
  321.     if (arc->angle2 < 0)
  322.     {
  323.     angle2 = angle1;
  324.     angle1 += arc->angle2;
  325.     }
  326.     else
  327.     angle2 = angle1 + arc->angle2;
  328.     while (angle1 < 0)
  329.     angle1 += FULLCIRCLE;
  330.     while (angle1 >= FULLCIRCLE)
  331.     angle1 -= FULLCIRCLE;
  332.     while (angle2 < 0)
  333.     angle2 += FULLCIRCLE;
  334.     while (angle2 >= FULLCIRCLE)
  335.     angle2 -= FULLCIRCLE;
  336.     slice->min_top_y = 0;
  337.     slice->max_top_y = arc->height >> 1;
  338.     slice->min_bot_y = 1 - (arc->height & 1);
  339.     slice->max_bot_y = slice->max_top_y - 1;
  340.     slice->flip_top = FALSE;
  341.     slice->flip_bot = FALSE;
  342.     if (pGC->arcMode == ArcPieSlice)
  343.     {
  344.     slice->edge1_top = (angle1 < HALFCIRCLE);
  345.     slice->edge2_top = (angle2 <= HALFCIRCLE);
  346.     if ((angle2 == 0) || (angle1 == HALFCIRCLE))
  347.     {
  348.         if (angle2 ? slice->edge2_top : slice->edge1_top)
  349.         slice->min_top_y = slice->min_bot_y;
  350.         else
  351.         slice->min_top_y = arc->height;
  352.         slice->min_bot_y = 0;
  353.     }
  354.     else if ((angle1 == 0) || (angle2 == HALFCIRCLE))
  355.     {
  356.         slice->min_top_y = slice->min_bot_y;
  357.         if (angle1 ? slice->edge1_top : slice->edge2_top)
  358.         slice->min_bot_y = arc->height;
  359.         else
  360.         slice->min_bot_y = 0;
  361.     }
  362.     else if (slice->edge1_top == slice->edge2_top)
  363.     {
  364.         if (angle2 < angle1)
  365.         {
  366.         slice->flip_top = slice->edge1_top;
  367.         slice->flip_bot = !slice->edge1_top;
  368.         }
  369.         else if (slice->edge1_top)
  370.         {
  371.         slice->min_top_y = 1;
  372.         slice->min_bot_y = arc->height;
  373.         }
  374.         else
  375.         {
  376.         slice->min_bot_y = 0;
  377.         slice->min_top_y = arc->height;
  378.         }
  379.     }
  380.     miGetPieEdge(arc, angle1, &slice->edge1,
  381.              slice->edge1_top, !slice->edge1_top);
  382.     miGetPieEdge(arc, angle2, &slice->edge2,
  383.              slice->edge2_top, slice->edge2_top);
  384.     }
  385.     else
  386.     {
  387.     double w2, h2, x1, y1, x2, y2, dx, dy, scale;
  388.     int signdx, signdy, y, k;
  389.  
  390.     w2 = (double)arc->width / 2.0;
  391.     h2 = (double)arc->height / 2.0;
  392.     if ((angle1 == 0) || (angle1 == HALFCIRCLE))
  393.     {
  394.         x1 = angle1 ? -w2 : w2;
  395.         y1 = 0.0;
  396.     }
  397.     else if ((angle1 == QUADRANT) || (angle1 == QUADRANT3))
  398.     {
  399.         x1 = 0.0;
  400.         y1 = (angle1 == QUADRANT) ? h2 : -h2;
  401.     }
  402.     else
  403.     {
  404.         x1 = Dcos(angle1) * w2;
  405.         y1 = Dsin(angle1) * h2;
  406.     }
  407.     if ((angle2 == 0) || (angle2 == HALFCIRCLE))
  408.     {
  409.         x2 = angle2 ? -w2 : w2;
  410.         y2 = 0.0;
  411.     }
  412.     else if ((angle2 == QUADRANT) || (angle2 == QUADRANT3))
  413.     {
  414.         x2 = 0.0;
  415.         y2 = (angle2 == QUADRANT) ? h2 : -h2;
  416.     }
  417.     else
  418.     {
  419.         x2 = Dcos(angle2) * w2;
  420.         y2 = Dsin(angle2) * h2;
  421.     }
  422.     dx = x2 - x1;
  423.     dy = y2 - y1;
  424.     if (arc->height & 1)
  425.     {
  426.         y1 -= 0.5;
  427.         y2 -= 0.5;
  428.     }
  429.     if (arc->width & 1)
  430.     {
  431.         x1 += 0.5;
  432.         x2 += 0.5;
  433.     }
  434.     if (dy < 0.0)
  435.     {
  436.         dy = -dy;
  437.         signdy = -1;
  438.     }
  439.     else
  440.         signdy = 1;
  441.     if (dx < 0.0)
  442.     {
  443.         dx = -dx;
  444.         signdx = -1;
  445.     }
  446.     else
  447.         signdx = 1;
  448.     scale = (dx > dy) ? dx : dy;
  449.     slice->edge1.dx = floor((dx * 32768) / scale + .5);
  450.     slice->edge1.dy = floor((dy * 32768) / scale + .5);
  451.     if (!slice->edge1.dy)
  452.     {
  453.         if (signdx < 0)
  454.         {
  455.         y = floor(y1 + 1.0);
  456.         if (y >= 0)
  457.         {
  458.             slice->min_top_y = y;
  459.             slice->min_bot_y = arc->height;
  460.         }
  461.         else
  462.         {
  463.             slice->max_bot_y = -y - (arc->height & 1);
  464.         }
  465.         }
  466.         else
  467.         {
  468.         y = floor(y1);
  469.         if (y >= 0)
  470.             slice->max_top_y = y;
  471.         else
  472.         {
  473.             slice->min_top_y = arc->height;
  474.             slice->min_bot_y = -y - (arc->height & 1);
  475.         }
  476.         }
  477.         slice->edge1_top = TRUE;
  478.         slice->edge1.x = 65536;
  479.         slice->edge1.stepx = 0;
  480.         slice->edge1.e = 0;
  481.         slice->edge1.dx = -1;
  482.         slice->edge2 = slice->edge1;
  483.         slice->edge2_top = FALSE;
  484.     }
  485.     else if (!slice->edge1.dx)
  486.     {
  487.         if (signdy < 0)
  488.         x1 -= 1.0;
  489.         slice->edge1.x = ceil(x1);
  490.         slice->edge1_top = signdy < 0;
  491.         slice->edge1.x += arc->x + (arc->width >> 1);
  492.         slice->edge1.stepx = 0;
  493.         slice->edge1.e = 0;
  494.         slice->edge1.dx = -1;
  495.         slice->edge2_top = !slice->edge1_top;
  496.         slice->edge2 = slice->edge1;
  497.     }
  498.     else
  499.     {
  500.         if (signdx < 0)
  501.         slice->edge1.dx = -slice->edge1.dx;
  502.         if (signdy < 0)
  503.         slice->edge1.dx = -slice->edge1.dx;
  504.         k = ceil(((x1 + x2) * slice->edge1.dy - (y1 + y2) * slice->edge1.dx) / 2.0);
  505.         slice->edge2.dx = slice->edge1.dx;
  506.         slice->edge2.dy = slice->edge1.dy;
  507.         slice->edge1_top = signdy < 0;
  508.         slice->edge2_top = !slice->edge1_top;
  509.         miGetArcEdge(arc, &slice->edge1, k,
  510.              slice->edge1_top, !slice->edge1_top);
  511.         miGetArcEdge(arc, &slice->edge2, k,
  512.              slice->edge2_top, slice->edge2_top);
  513.     }
  514.     }
  515. }
  516.  
  517. #define ADDSPANS() \
  518.     pts->x = xorg - x; \
  519.     pts->y = yorg - y; \
  520.     *wids = slw; \
  521.     pts++; \
  522.     wids++; \
  523.     if (miFillArcLower(slw)) \
  524.     { \
  525.     pts->x = xorg - x; \
  526.     pts->y = yorg + y + dy; \
  527.     pts++; \
  528.     *wids++ = slw; \
  529.     }
  530.  
  531. static void
  532. miFillEllipseI(pDraw, pGC, arc)
  533.     DrawablePtr pDraw;
  534.     GCPtr pGC;
  535.     xArc *arc;
  536. {
  537.     register int x, y, e;
  538.     int yk, xk, ym, xm, dx, dy, xorg, yorg;
  539.     int slw;
  540.     miFillArcRec info;
  541.     DDXPointPtr points;
  542.     register DDXPointPtr pts;
  543.     int *widths;
  544.     register int *wids;
  545.  
  546.     points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height);
  547.     if (!points)
  548.     return;
  549.     widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height);
  550.     if (!widths)
  551.     {
  552.     DEALLOCATE_LOCAL(points);
  553.     return;
  554.     }
  555.     miFillArcSetup(arc, &info);
  556.     MIFILLARCSETUP();
  557.     if (pGC->miTranslate)
  558.     {
  559.     xorg += pDraw->x;
  560.     yorg += pDraw->y;
  561.     }
  562.     pts = points;
  563.     wids = widths;
  564.     while (y > 0)
  565.     {
  566.     MIFILLARCSTEP(slw);
  567.     ADDSPANS();
  568.     }
  569.     (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
  570.     DEALLOCATE_LOCAL(widths);
  571.     DEALLOCATE_LOCAL(points);
  572. }
  573.  
  574. static void
  575. miFillEllipseD(pDraw, pGC, arc)
  576.     DrawablePtr pDraw;
  577.     GCPtr pGC;
  578.     xArc *arc;
  579. {
  580.     register int x, y;
  581.     int xorg, yorg, dx, dy, slw;
  582.     double e, yk, xk, ym, xm;
  583.     miFillArcDRec info;
  584.     DDXPointPtr points;
  585.     register DDXPointPtr pts;
  586.     int *widths;
  587.     register int *wids;
  588.  
  589.     points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height);
  590.     if (!points)
  591.     return;
  592.     widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height);
  593.     if (!widths)
  594.     {
  595.     DEALLOCATE_LOCAL(points);
  596.     return;
  597.     }
  598.     miFillArcDSetup(arc, &info);
  599.     MIFILLARCSETUP();
  600.     if (pGC->miTranslate)
  601.     {
  602.     xorg += pDraw->x;
  603.     yorg += pDraw->y;
  604.     }
  605.     pts = points;
  606.     wids = widths;
  607.     while (y > 0)
  608.     {
  609.     MIFILLARCSTEP(slw);
  610.     ADDSPANS();
  611.     }
  612.     (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
  613.     DEALLOCATE_LOCAL(widths);
  614.     DEALLOCATE_LOCAL(points);
  615. }
  616.  
  617. #define ADDSPAN(l,r) \
  618.     if (r >= l) \
  619.     { \
  620.     pts->x = l; \
  621.     pts->y = ya; \
  622.     pts++; \
  623.     *wids++ = r - l + 1; \
  624.     }
  625.  
  626. #define ADDSLICESPANS(flip) \
  627.     if (!flip) \
  628.     { \
  629.     ADDSPAN(xl, xr); \
  630.     } \
  631.     else \
  632.     { \
  633.     xc = xorg - x; \
  634.     ADDSPAN(xc, xr); \
  635.     xc += slw - 1; \
  636.     ADDSPAN(xl, xc); \
  637.     }
  638.  
  639. static void
  640. miFillArcSliceI(pDraw, pGC, arc)
  641.     DrawablePtr pDraw;
  642.     GCPtr pGC;
  643.     xArc *arc;
  644. {
  645.     int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
  646.     register int x, y, e;
  647.     miFillArcRec info;
  648.     miArcSliceRec slice;
  649.     int ya, xl, xr, xc;
  650.     DDXPointPtr points;
  651.     register DDXPointPtr pts;
  652.     int *widths;
  653.     register int *wids;
  654.  
  655.     miFillArcSetup(arc, &info);
  656.     miFillArcSliceSetup(arc, &slice, pGC);
  657.     MIFILLARCSETUP();
  658.     slw = arc->height;
  659.     if (slice.flip_top || slice.flip_bot)
  660.     slw += (arc->height >> 1) + 1;
  661.     points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw);
  662.     if (!points)
  663.     return;
  664.     widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw);
  665.     if (!widths)
  666.     {
  667.     DEALLOCATE_LOCAL(points);
  668.     return;
  669.     }
  670.     if (pGC->miTranslate)
  671.     {
  672.     xorg += pDraw->x;
  673.     yorg += pDraw->y;
  674.     slice.edge1.x += pDraw->x;
  675.     slice.edge2.x += pDraw->x;
  676.     }
  677.     pts = points;
  678.     wids = widths;
  679.     while (y > 0)
  680.     {
  681.     MIFILLARCSTEP(slw);
  682.     MIARCSLICESTEP(slice.edge1);
  683.     MIARCSLICESTEP(slice.edge2);
  684.     if (miFillSliceUpper(slice))
  685.     {
  686.         ya = yorg - y;
  687.         MIARCSLICEUPPER(xl, xr, slice, slw);
  688.         ADDSLICESPANS(slice.flip_top);
  689.     }
  690.     if (miFillSliceLower(slice))
  691.     {
  692.         ya = yorg + y + dy;
  693.         MIARCSLICELOWER(xl, xr, slice, slw);
  694.         ADDSLICESPANS(slice.flip_bot);
  695.     }
  696.     }
  697.     (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
  698.     DEALLOCATE_LOCAL(widths);
  699.     DEALLOCATE_LOCAL(points);
  700. }
  701.  
  702. static void
  703. miFillArcSliceD(pDraw, pGC, arc)
  704.     DrawablePtr pDraw;
  705.     GCPtr pGC;
  706.     xArc *arc;
  707. {
  708.     register int x, y;
  709.     int dx, dy, xorg, yorg, slw;
  710.     double e, yk, xk, ym, xm;
  711.     miFillArcDRec info;
  712.     miArcSliceRec slice;
  713.     int ya, xl, xr, xc;
  714.     DDXPointPtr points;
  715.     register DDXPointPtr pts;
  716.     int *widths;
  717.     register int *wids;
  718.  
  719.     miFillArcDSetup(arc, &info);
  720.     miFillArcSliceSetup(arc, &slice, pGC);
  721.     MIFILLARCSETUP();
  722.     slw = arc->height;
  723.     if (slice.flip_top || slice.flip_bot)
  724.     slw += (arc->height >> 1) + 1;
  725.     points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw);
  726.     if (!points)
  727.     return;
  728.     widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw);
  729.     if (!widths)
  730.     {
  731.     DEALLOCATE_LOCAL(points);
  732.     return;
  733.     }
  734.     if (pGC->miTranslate)
  735.     {
  736.     xorg += pDraw->x;
  737.     yorg += pDraw->y;
  738.     slice.edge1.x += pDraw->x;
  739.     slice.edge2.x += pDraw->x;
  740.     }
  741.     pts = points;
  742.     wids = widths;
  743.     while (y > 0)
  744.     {
  745.     MIFILLARCSTEP(slw);
  746.     MIARCSLICESTEP(slice.edge1);
  747.     MIARCSLICESTEP(slice.edge2);
  748.     if (miFillSliceUpper(slice))
  749.     {
  750.         ya = yorg - y;
  751.         MIARCSLICEUPPER(xl, xr, slice, slw);
  752.         ADDSLICESPANS(slice.flip_top);
  753.     }
  754.     if (miFillSliceLower(slice))
  755.     {
  756.         ya = yorg + y + dy;
  757.         MIARCSLICELOWER(xl, xr, slice, slw);
  758.         ADDSLICESPANS(slice.flip_bot);
  759.     }
  760.     }
  761.     (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE);
  762.     DEALLOCATE_LOCAL(widths);
  763.     DEALLOCATE_LOCAL(points);
  764. }
  765.  
  766. /* MIPOLYFILLARC -- The public entry for the PolyFillArc request.
  767.  * Since we don't have to worry about overlapping segments, we can just
  768.  * fill each arc as it comes.
  769.  */
  770. void
  771. miPolyFillArc(pDraw, pGC, narcs, parcs)
  772.     DrawablePtr    pDraw;
  773.     GCPtr    pGC;
  774.     int        narcs;
  775.     xArc    *parcs;
  776. {
  777.     register int i;
  778.     register xArc *arc;
  779.  
  780.     for(i = narcs, arc = parcs; --i >= 0; arc++)
  781.     {
  782.     if (miFillArcEmpty(arc))
  783.         continue;;
  784.     if ((arc->angle2 >= FULLCIRCLE) || (arc->angle2 <= -FULLCIRCLE))
  785.     {
  786.         if (miCanFillArc(arc))
  787.         miFillEllipseI(pDraw, pGC, arc);
  788.         else
  789.         miFillEllipseD(pDraw, pGC, arc);
  790.     }
  791.     else
  792.     {
  793.         if (miCanFillArc(arc))
  794.         miFillArcSliceI(pDraw, pGC, arc);
  795.         else
  796.         miFillArcSliceD(pDraw, pGC, arc);
  797.     }
  798.     }
  799. }
  800.