home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-16  |  18.1 KB  |  790 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24. /* $XConsortium: cfbline.c,v 1.19 91/08/13 18:48:42 keith Exp $ */
  25. #include "X.h"
  26.  
  27. #include "gcstruct.h"
  28. #include "windowstr.h"
  29. #include "pixmapstr.h"
  30. #include "regionstr.h"
  31. #include "scrnintstr.h"
  32. #include "mistruct.h"
  33.  
  34. #include "cfb.h"
  35. #include "cfbmskbits.h"
  36.  
  37. /* single-pixel lines on a color frame buffer
  38.  
  39.    NON-SLOPED LINES
  40.    horizontal lines are always drawn left to right; we have to
  41. move the endpoints right by one after they're swapped.
  42.    horizontal lines will be confined to a single band of a
  43. region.  the code finds that band (giving up if the lower
  44. bound of the band is above the line we're drawing); then it
  45. finds the first box in that band that contains part of the
  46. line.  we clip the line to subsequent boxes in that band.
  47.    vertical lines are always drawn top to bottom (y-increasing.)
  48. this requires adding one to the y-coordinate of each endpoint
  49. after swapping.
  50.  
  51.    SLOPED LINES
  52.    when clipping a sloped line, we bring the second point inside
  53. the clipping box, rather than one beyond it, and then add 1 to
  54. the length of the line before drawing it.  this lets us use
  55. the same box for finding the outcodes for both endpoints.  since
  56. the equation for clipping the second endpoint to an edge gives us
  57. 1 beyond the edge, we then have to move the point towards the
  58. first point by one step on the major axis.
  59.    eventually, there will be a diagram here to explain what's going
  60. on.  the method uses Cohen-Sutherland outcodes to determine
  61. outsideness, and a method similar to Pike's layers for doing the
  62. actual clipping.
  63.  
  64. */
  65.  
  66. #define OUTCODES(result, x, y, pbox) \
  67.     if (x < pbox->x1) \
  68.     result |= OUT_LEFT; \
  69.     else if (x >= pbox->x2) \
  70.     result |= OUT_RIGHT; \
  71.     if (y < pbox->y1) \
  72.     result |= OUT_ABOVE; \
  73.     else if (y >= pbox->y2) \
  74.     result |= OUT_BELOW;
  75.  
  76. /*
  77. #define SignTimes(sign, n) ((sign) * ((int)(n)))
  78. */
  79.  
  80. #define SignTimes(sign, n) \
  81.     ( ((sign)<0) ? -(n) : (n) )
  82.  
  83. #define SWAPINT(i, j) \
  84. {  register int _t = i; \
  85.    i = j; \
  86.    j = _t; \
  87. }
  88.  
  89. #define SWAPPT(i, j) \
  90. {  register DDXPointRec _t; \
  91.    _t = i; \
  92.    i = j; \
  93.    j = _t; \
  94. }
  95.  
  96. void
  97. #ifdef POLYSEGMENT
  98. cfbSegmentSS (pDrawable, pGC, nseg, pSeg)
  99.     DrawablePtr    pDrawable;
  100.     GCPtr    pGC;
  101.     int        nseg;
  102.     register xSegment    *pSeg;
  103. #else
  104. cfbLineSS (pDrawable, pGC, mode, npt, pptInit)
  105.     DrawablePtr pDrawable;
  106.     GCPtr    pGC;
  107.     int        mode;        /* Origin or Previous */
  108.     int        npt;        /* number of points */
  109.     DDXPointPtr pptInit;
  110. #endif
  111. {
  112.     int nboxInit;
  113.     register int nbox;
  114.     BoxPtr pboxInit;
  115.     register BoxPtr pbox;
  116. #ifndef POLYSEGMENT
  117.     register DDXPointPtr ppt;    /* pointer to list of translated points */
  118. #endif
  119.  
  120.     unsigned int oc1;        /* outcode of point 1 */
  121.     unsigned int oc2;        /* outcode of point 2 */
  122.  
  123.     unsigned long *addrl;        /* address of destination pixmap */
  124.     int nlwidth;        /* width in longwords of destination pixmap */
  125.     int xorg, yorg;        /* origin of window */
  126.  
  127.     int adx;        /* abs values of dx and dy */
  128.     int ady;
  129.     int signdx;        /* sign of dx and dy */
  130.     int signdy;
  131.     int e, e1, e2;        /* bresenham error and increments */
  132.     int len;            /* length of segment */
  133.     int axis;            /* major axis */
  134.  
  135.                 /* a bunch of temporaries */
  136.     int tmp;
  137.     register int y1, y2;
  138.     register int x1, x2;
  139.     RegionPtr cclip;
  140.     cfbPrivGCPtr    devPriv;
  141.     unsigned long   xor, and;
  142.     int            alu;
  143.  
  144.     devPriv = (cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr); 
  145.     cclip = devPriv->pCompositeClip;
  146.     pboxInit = REGION_RECTS(cclip);
  147.     nboxInit = REGION_NUM_RECTS(cclip);
  148.  
  149.     cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrl)
  150.  
  151.     alu = devPriv->rop;
  152.     xor = devPriv->xor;
  153.     and = devPriv->and;
  154.     xorg = pDrawable->x;
  155.     yorg = pDrawable->y;
  156. #ifdef POLYSEGMENT
  157.     while (nseg--)
  158. #else
  159.     ppt = pptInit;
  160.     x2 = ppt->x + xorg;
  161.     y2 = ppt->y + yorg;
  162.     while(--npt)
  163. #endif
  164.     {
  165.     nbox = nboxInit;
  166.     pbox = pboxInit;
  167.  
  168. #ifdef POLYSEGMENT
  169.     x1 = pSeg->x1 + xorg;
  170.     y1 = pSeg->y1 + yorg;
  171.     x2 = pSeg->x2 + xorg;
  172.     y2 = pSeg->y2 + yorg;
  173.     pSeg++;
  174. #else
  175.     x1 = x2;
  176.     y1 = y2;
  177.     ++ppt;
  178.     if (mode == CoordModePrevious)
  179.     {
  180.         xorg = x1;
  181.         yorg = y1;
  182.     }
  183.     x2 = ppt->x + xorg;
  184.     y2 = ppt->y + yorg;
  185. #endif
  186.  
  187.     if (x1 == x2)
  188.     {
  189.         /* make the line go top to bottom of screen, keeping
  190.            endpoint semantics
  191.         */
  192.         if (y1 > y2)
  193.         {
  194.         register int tmp;
  195.  
  196.         tmp = y2;
  197.         y2 = y1 + 1;
  198.         y1 = tmp + 1;
  199. #ifdef POLYSEGMENT
  200.         if (pGC->capStyle != CapNotLast)
  201.             y1--;
  202. #endif
  203.         }
  204. #ifdef POLYSEGMENT
  205.         else if (pGC->capStyle != CapNotLast)
  206.         y2++;
  207. #endif
  208.         /* get to first band that might contain part of line */
  209.         while ((nbox) && (pbox->y2 <= y1))
  210.         {
  211.         pbox++;
  212.         nbox--;
  213.         }
  214.  
  215.         if (nbox)
  216.         {
  217.         /* stop when lower edge of box is beyond end of line */
  218.         while((nbox) && (y2 >= pbox->y1))
  219.         {
  220.             if ((x1 >= pbox->x1) && (x1 < pbox->x2))
  221.             {
  222.             int y1t, y2t;
  223.             /* this box has part of the line in it */
  224.             y1t = max(y1, pbox->y1);
  225.             y2t = min(y2, pbox->y2);
  226.             if (y1t != y2t)
  227.             {
  228.                 cfbVertS (alu, and, xor,
  229.                       addrl, nlwidth, 
  230.                       x1, y1t, y2t-y1t);
  231.             }
  232.             }
  233.             nbox--;
  234.             pbox++;
  235.         }
  236.         }
  237. #ifndef POLYSEGMENT
  238.         y2 = ppt->y + yorg;
  239. #endif
  240.     }
  241.     else if (y1 == y2)
  242.     {
  243.         /* force line from left to right, keeping
  244.            endpoint semantics
  245.         */
  246.         if (x1 > x2)
  247.         {
  248.         register int tmp;
  249.  
  250.         tmp = x2;
  251.         x2 = x1 + 1;
  252.         x1 = tmp + 1;
  253. #ifdef POLYSEGMENT
  254.         if (pGC->capStyle != CapNotLast)
  255.             x1--;
  256. #endif
  257.         }
  258. #ifdef POLYSEGMENT
  259.         else if (pGC->capStyle != CapNotLast)
  260.         x2++;
  261. #endif
  262.  
  263.         /* find the correct band */
  264.         while( (nbox) && (pbox->y2 <= y1))
  265.         {
  266.         pbox++;
  267.         nbox--;
  268.         }
  269.  
  270.         /* try to draw the line, if we haven't gone beyond it */
  271.         if ((nbox) && (pbox->y1 <= y1))
  272.         {
  273.         /* when we leave this band, we're done */
  274.         tmp = pbox->y1;
  275.         while((nbox) && (pbox->y1 == tmp))
  276.         {
  277.             int    x1t, x2t;
  278.  
  279.             if (pbox->x2 <= x1)
  280.             {
  281.             /* skip boxes until one might contain start point */
  282.             nbox--;
  283.             pbox++;
  284.             continue;
  285.             }
  286.  
  287.             /* stop if left of box is beyond right of line */
  288.             if (pbox->x1 >= x2)
  289.             {
  290.             nbox = 0;
  291.             break;
  292.             }
  293.  
  294.             x1t = max(x1, pbox->x1);
  295.             x2t = min(x2, pbox->x2);
  296.             if (x1t != x2t)
  297.             {
  298.             cfbHorzS (alu, and, xor,
  299.                   addrl, nlwidth, 
  300.                   x1t, y1, x2t-x1t);
  301.             }
  302.             nbox--;
  303.             pbox++;
  304.         }
  305.         }
  306. #ifndef POLYSEGMENT
  307.         x2 = ppt->x + xorg;
  308. #endif
  309.     }
  310.     else    /* sloped line */
  311.     {
  312.         signdx = 1;
  313.         if ((adx = x2 - x1) < 0)
  314.         {
  315.         adx = -adx;
  316.         signdx = -1;
  317.         }
  318.         signdy = 1;
  319.         if ((ady = y2 - y1) < 0)
  320.         {
  321.         ady = -ady;
  322.         signdy = -1;
  323.         }
  324.  
  325.         if (adx > ady)
  326.         {
  327.         axis = X_AXIS;
  328.         e1 = ady << 1;
  329.         e2 = e1 - (adx << 1);
  330.         e = e1 - adx;
  331.  
  332.         }
  333.         else
  334.         {
  335.         axis = Y_AXIS;
  336.         e1 = adx << 1;
  337.         e2 = e1 - (ady << 1);
  338.         e = e1 - ady;
  339.         }
  340.  
  341.         /* we have bresenham parameters and two points.
  342.            all we have to do now is clip and draw.
  343.         */
  344.  
  345.         while(nbox--)
  346.         {
  347.         oc1 = 0;
  348.         oc2 = 0;
  349.         OUTCODES(oc1, x1, y1, pbox);
  350.         OUTCODES(oc2, x2, y2, pbox);
  351.         if ((oc1 | oc2) == 0)
  352.         {
  353.             if (axis == X_AXIS)
  354.             len = adx;
  355.             else
  356.             len = ady;
  357. #ifdef POLYSEGMENT
  358.             if (pGC->capStyle != CapNotLast)
  359.             len++;
  360. #endif
  361.             cfbBresS (alu, and, xor,
  362.               addrl, nlwidth,
  363.               signdx, signdy, axis, x1, y1,
  364.               e, e1, e2, len);
  365.             break;
  366.         }
  367.         else if (oc1 & oc2)
  368.         {
  369.             pbox++;
  370.         }
  371.         else
  372.         {
  373.                 /*
  374.                   * let the mfb helper routine do our work;
  375.                   * better than duplicating code...
  376.                   */
  377.                 BoxRec box;
  378.                     DDXPointRec pt1Copy;    /* clipped start point */
  379.                     DDXPointRec pt2Copy;    /* clipped end point */
  380.                     int err;            /* modified bresenham error term */
  381.                     int clip1, clip2;        /* clippedness of the endpoints */
  382.                 
  383.                     int clipdx, clipdy;        /* difference between clipped and
  384.                                          unclipped start point */
  385.             DDXPointRec    pt1;
  386.                 
  387.         
  388.                 pt1.x = pt1Copy.x = x1;
  389.             pt1.y = pt1Copy.y = y1;
  390.                 pt2Copy.x = x2;
  391.             pt2Copy.y = y2;
  392.                 box.x1 = pbox->x1;
  393.                 box.y1 = pbox->y1;
  394.                 box.x2 = pbox->x2-1;
  395.                 box.y2 = pbox->y2-1;
  396.                 clip1 = 0;
  397.                 clip2 = 0;
  398.         
  399.             if (mfbClipLine (pbox, box,
  400.                      &pt1, &pt1Copy, &pt2Copy, 
  401.                      adx, ady, signdx, signdy, axis,
  402.                      &clip1, &clip2) == 1)
  403.             {
  404.                 if (axis == X_AXIS)
  405.                 len = abs(pt2Copy.x - pt1Copy.x);
  406.                 else
  407.                 len = abs(pt2Copy.y - pt1Copy.y);
  408.     
  409. #ifdef POLYSEGMENT
  410.                 if (clip2 != 0 || pGC->capStyle != CapNotLast)
  411.                 len++;
  412. #else
  413.                 len += (clip2 != 0);
  414. #endif
  415.                 if (len)
  416.                 {
  417.                 /* unwind bresenham error term to first point */
  418.                 if (clip1)
  419.                 {
  420.                     clipdx = abs(pt1Copy.x - x1);
  421.                     clipdy = abs(pt1Copy.y - y1);
  422.                     if (axis == X_AXIS)
  423.                     err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
  424.                     else
  425.                     err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
  426.                 }
  427.                 else
  428.                     err = e;
  429.                 cfbBresS   
  430.                      (alu, and, xor,
  431.                       addrl, nlwidth,
  432.                       signdx, signdy, axis, pt1Copy.x, pt1Copy.y,
  433.                       err, e1, e2, len);
  434.                 }
  435.             }
  436.             pbox++;
  437.         }
  438.         } /* while (nbox--) */
  439.     } /* sloped line */
  440.     } /* while (nline--) */
  441.  
  442. #ifndef POLYSEGMENT
  443.     /* paint the last point if the end style isn't CapNotLast.
  444.        (Assume that a projecting, butt, or round cap that is one
  445.         pixel wide is the same as the single pixel of the endpoint.)
  446.     */
  447.  
  448.     if ((pGC->capStyle != CapNotLast) &&
  449.     ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
  450.      (ppt->y + yorg != pptInit->y + pDrawable->y) ||
  451.      (ppt == pptInit + 1)))
  452.     {
  453.     nbox = nboxInit;
  454.     pbox = pboxInit;
  455.     while (nbox--)
  456.     {
  457.         if ((x2 >= pbox->x1) &&
  458.         (y2 >= pbox->y1) &&
  459.         (x2 <  pbox->x2) &&
  460.         (y2 <  pbox->y2))
  461.         {
  462.         unsigned long mask;
  463.         unsigned long scrbits;
  464.  
  465.         mask = cfbmask[x2 & PIM];
  466.         addrl += (y2 * nlwidth) + (x2 >> PWSH);
  467.         scrbits = *addrl;
  468.         *addrl = (scrbits & ~mask) |
  469.              (DoRRop (scrbits, and, xor) & mask);
  470.         break;
  471.         }
  472.         else
  473.         pbox++;
  474.     }
  475.     }
  476. #endif
  477. }
  478.  
  479. /*
  480.  * Draw dashed 1-pixel lines.
  481.  */
  482.  
  483. void
  484. #ifdef POLYSEGMENT
  485. cfbSegmentSD (pDrawable, pGC, nseg, pSeg)
  486.     DrawablePtr    pDrawable;
  487.     register GCPtr    pGC;
  488.     int        nseg;
  489.     register xSegment    *pSeg;
  490. #else
  491. cfbLineSD( pDrawable, pGC, mode, npt, pptInit)
  492.     DrawablePtr pDrawable;
  493.     register GCPtr pGC;
  494.     int mode;        /* Origin or Previous */
  495.     int npt;        /* number of points */
  496.     DDXPointPtr pptInit;
  497. #endif
  498. {
  499.     int nboxInit;
  500.     register int nbox;
  501.     BoxPtr pboxInit;
  502.     register BoxPtr pbox;
  503. #ifndef POLYSEGMENT
  504.     register DDXPointPtr ppt;    /* pointer to list of translated points */
  505. #endif
  506.  
  507.     register unsigned int oc1;        /* outcode of point 1 */
  508.     register unsigned int oc2;        /* outcode of point 2 */
  509.  
  510.     unsigned long *addrl;        /* address of destination pixmap */
  511.     int nlwidth;        /* width in longwords of destination pixmap */
  512.     int xorg, yorg;        /* origin of window */
  513.  
  514.     int adx;        /* abs values of dx and dy */
  515.     int ady;
  516.     int signdx;        /* sign of dx and dy */
  517.     int signdy;
  518.     int e, e1, e2;        /* bresenham error and increments */
  519.     int len;            /* length of segment */
  520.     int axis;            /* major axis */
  521.     int x1, x2, y1, y2;
  522.     RegionPtr cclip;
  523.     cfbRRopRec        rrops[2];
  524.     unsigned char   *pDash;
  525.     int            dashOffset;
  526.     int            numInDashList;
  527.     int            dashIndex;
  528.     int            isDoubleDash;
  529.     int            dashIndexTmp, dashOffsetTmp;
  530.     int            unclippedlen;
  531.     cfbPrivGCPtr    devPriv;
  532.  
  533.     devPriv = (cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr); 
  534.     cclip = devPriv->pCompositeClip;
  535.     rrops[0].rop = devPriv->rop;
  536.     rrops[0].and = devPriv->and;
  537.     rrops[0].xor = devPriv->xor;
  538.     if (pGC->alu == GXcopy)
  539.     {
  540.     rrops[1].rop = GXcopy;
  541.     rrops[1].and = 0;
  542.     rrops[1].xor = PFILL (pGC->bgPixel);
  543.     }
  544.     else
  545.     {
  546.         rrops[1].rop = cfbReduceRasterOp (pGC->alu,
  547.                       pGC->bgPixel, pGC->planemask,
  548.                       &rrops[1].and, &rrops[1].xor);
  549.     }
  550.     pboxInit = REGION_RECTS(cclip);
  551.     nboxInit = REGION_NUM_RECTS(cclip);
  552.  
  553.     cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrl)
  554.  
  555.     /* compute initial dash values */
  556.      
  557.     pDash = (unsigned char *) pGC->dash;
  558.     numInDashList = pGC->numInDashList;
  559.     isDoubleDash = (pGC->lineStyle == LineDoubleDash);
  560.     dashIndex = 0;
  561.     dashOffset = 0;
  562.     miStepDash ((int)pGC->dashOffset, &dashIndex, pDash,
  563.         numInDashList, &dashOffset);
  564.  
  565.     xorg = pDrawable->x;
  566.     yorg = pDrawable->y;
  567. #ifdef POLYSEGMENT
  568.     while (nseg--)
  569. #else
  570.     ppt = pptInit;
  571.     x2 = ppt->x + xorg;
  572.     y2 = ppt->y + yorg;
  573.     while(--npt)
  574. #endif
  575.     {
  576.     nbox = nboxInit;
  577.     pbox = pboxInit;
  578.  
  579. #ifdef POLYSEGMENT
  580.     x1 = pSeg->x1 + xorg;
  581.     y1 = pSeg->y1 + yorg;
  582.     x2 = pSeg->x2 + xorg;
  583.     y2 = pSeg->y2 + yorg;
  584.     pSeg++;
  585. #else
  586.     x1 = x2;
  587.     y1 = y2;
  588.     ++ppt;
  589.     if (mode == CoordModePrevious)
  590.     {
  591.         xorg = x1;
  592.         yorg = y1;
  593.     }
  594.     x2 = ppt->x + xorg;
  595.     y2 = ppt->y + yorg;
  596. #endif
  597.  
  598.     adx = x2 - x1;
  599.     ady = y2 - y1;
  600.     signdx = sign(adx);
  601.     signdy = sign(ady);
  602.     adx = abs(adx);
  603.     ady = abs(ady);
  604.  
  605.     if (adx > ady)
  606.     {
  607.         axis = X_AXIS;
  608.         e1 = ady << 1;
  609.         e2 = e1 - (adx << 1);
  610.         e = e1 - adx;
  611.         unclippedlen = adx;
  612.     }
  613.     else
  614.     {
  615.         axis = Y_AXIS;
  616.         e1 = adx << 1;
  617.         e2 = e1 - (ady << 1);
  618.         e = e1 - ady;
  619.         unclippedlen = ady;
  620.     }
  621.  
  622.     /* we have bresenham parameters and two points.
  623.        all we have to do now is clip and draw.
  624.     */
  625.  
  626.     while(nbox--)
  627.     {
  628.         oc1 = 0;
  629.         oc2 = 0;
  630.         OUTCODES(oc1, x1, y1, pbox);
  631.         OUTCODES(oc2, x2, y2, pbox);
  632.         if ((oc1 | oc2) == 0)
  633.         {
  634. #ifdef POLYSEGMENT
  635.         if (pGC->capStyle != CapNotLast)
  636.             unclippedlen++;
  637.         dashIndexTmp = dashIndex;
  638.         dashOffsetTmp = dashOffset;
  639.         cfbBresD (rrops,
  640.               &dashIndexTmp, pDash, numInDashList,
  641.               &dashOffsetTmp, isDoubleDash,
  642.               addrl, nlwidth,
  643.               signdx, signdy, axis, x1, y1,
  644.               e, e1, e2, unclippedlen);
  645.         break;
  646. #else
  647.         cfbBresD (rrops,
  648.               &dashIndex, pDash, numInDashList,
  649.               &dashOffset, isDoubleDash,
  650.               addrl, nlwidth,
  651.               signdx, signdy, axis, x1, y1,
  652.               e, e1, e2, unclippedlen);
  653.         goto dontStep;
  654. #endif
  655.         }
  656.         else if (oc1 & oc2)
  657.         {
  658.         pbox++;
  659.         }
  660.         else /* have to clip */
  661.         {
  662.         /*
  663.          * let the mfb helper routine do our work;
  664.          * better than duplicating code...
  665.          */
  666.         BoxRec box;
  667.         DDXPointRec pt1Copy;    /* clipped start point */
  668.         DDXPointRec pt2Copy;    /* clipped end point */
  669.         int err;            /* modified bresenham error term */
  670.         int clip1, clip2;        /* clippedness of the endpoints */
  671.         
  672.         int clipdx, clipdy;        /* difference between clipped and
  673.                            unclipped start point */
  674.         DDXPointRec    pt1;
  675.     
  676.         pt1.x = pt1Copy.x = x1;
  677.         pt1.y = pt1Copy.y = y1;
  678.         pt2Copy.x = x2;
  679.         pt2Copy.y = y2;
  680.         box.x1 = pbox->x1;
  681.         box.y1 = pbox->y1;
  682.         box.x2 = pbox->x2-1;
  683.         box.y2 = pbox->y2-1;
  684.         clip1 = 0;
  685.         clip2 = 0;
  686.     
  687.         if (mfbClipLine (pbox, box,
  688.                        &pt1, &pt1Copy, &pt2Copy, 
  689.                        adx, ady, signdx, signdy, axis,
  690.                        &clip1, &clip2) == 1)
  691.         {
  692.     
  693.             dashIndexTmp = dashIndex;
  694.             dashOffsetTmp = dashOffset;
  695.             if (clip1)
  696.             {
  697.                 int dlen;
  698.     
  699.                 if (axis == X_AXIS)
  700.                 dlen = abs(pt1Copy.x - x1);
  701.                 else
  702.                 dlen = abs(pt1Copy.y - y1);
  703.                 miStepDash (dlen, &dashIndexTmp, pDash,
  704.                     numInDashList, &dashOffsetTmp);
  705.             }
  706.             if (axis == X_AXIS)
  707.                 len = abs(pt2Copy.x - pt1Copy.x);
  708.             else
  709.                 len = abs(pt2Copy.y - pt1Copy.y);
  710.     
  711. #ifdef POLYSEGMENT
  712.             if (clip2 != 0 || pGC->capStyle != CapNotLast)
  713.                 len++;
  714. #else
  715.             len += (clip2 != 0);
  716. #endif
  717.             if (len)
  718.             {
  719.                 /* unwind bresenham error term to first point */
  720.                 if (clip1)
  721.                 {
  722.                 clipdx = abs(pt1Copy.x - x1);
  723.                 clipdy = abs(pt1Copy.y - y1);
  724.                 if (axis == X_AXIS)
  725.                     err = e+((clipdy*e2) + ((clipdx-clipdy)*e1));
  726.                 else
  727.                     err = e+((clipdx*e2) + ((clipdy-clipdx)*e1));
  728.                 }
  729.                 else
  730.                 err = e;
  731.                 cfbBresD (rrops,
  732.                         &dashIndexTmp, pDash, numInDashList,
  733.                         &dashOffsetTmp, isDoubleDash,
  734.                         addrl, nlwidth,
  735.                         signdx, signdy, axis, pt1Copy.x, pt1Copy.y,
  736.                         err, e1, e2, len);
  737.             }
  738.         }
  739.         pbox++;
  740.         }
  741.     } /* while (nbox--) */
  742. #ifndef POLYSEGMENT
  743.     /*
  744.      * walk the dash list around to the next line
  745.      */
  746.     miStepDash (unclippedlen, &dashIndex, pDash,
  747.             numInDashList, &dashOffset);
  748. dontStep:    ;
  749. #endif
  750.     } /* while (nline--) */
  751.  
  752. #ifndef POLYSEGMENT
  753.     /* paint the last point if the end style isn't CapNotLast.
  754.        (Assume that a projecting, butt, or round cap that is one
  755.         pixel wide is the same as the single pixel of the endpoint.)
  756.     */
  757.  
  758.     if ((pGC->capStyle != CapNotLast) &&
  759.         ((dashIndex & 1) == 0 || isDoubleDash) &&
  760.     ((ppt->x + xorg != pptInit->x + pDrawable->x) ||
  761.      (ppt->y + yorg != pptInit->y + pDrawable->y) ||
  762.      (ppt == pptInit + 1)))
  763.     {
  764.     nbox = nboxInit;
  765.     pbox = pboxInit;
  766.     while (nbox--)
  767.     {
  768.         if ((x2 >= pbox->x1) &&
  769.         (y2 >= pbox->y1) &&
  770.         (x2 <  pbox->x2) &&
  771.         (y2 <  pbox->y2))
  772.         {
  773.         unsigned long    mask;
  774.         int        pix;
  775.  
  776.         pix = 0;
  777.         if (dashIndex & 1)
  778.             pix = 1;
  779.         mask = cfbmask[x2 & PIM];
  780.         addrl += (y2 * nlwidth) + (x2 >> PWSH);
  781.         *addrl = DoMaskRRop (*addrl, rrops[pix].and, rrops[pix].xor, mask);
  782.         break;
  783.         }
  784.         else
  785.         pbox++;
  786.     }
  787.     }
  788. #endif
  789. }
  790.