home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / mpel / mpelDash.c < prev    next >
C/C++ Source or Header  |  1991-12-12  |  3KB  |  107 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23.  
  24. #ifndef lint
  25. static char *rcsid = "$Id: mpelDash.c,v 1.4 88/11/03 20:29:57 paul Exp $";
  26. #endif
  27.  
  28. #include "X.h"
  29. #include "Xproto.h"
  30. #include "misc.h"
  31. #include "font.h"
  32. #include "gcstruct.h"
  33. #include "windowstr.h"
  34. #include "pixmapstr.h"
  35. #include "scrnintstr.h"
  36. #include "region.h"
  37.  
  38. #include "mfb.h"
  39.  
  40. #include "mistruct.h"
  41.  
  42. #include "ppc.h"
  43. #include "ppcProcs.h"
  44.  
  45. #include "ibmTrace.h"
  46.  
  47. #include "mpel.h"
  48. #include "mpelProcs.h"
  49.  
  50. #define barrel_shift16(v, s) \
  51.     (v = (v >> s) | (v << (16 - s)))
  52.  
  53. void
  54. mpel_do_dashline_gc( pGC )
  55. register GCPtr pGC;
  56. {
  57.     register unsigned int len = 0;
  58.     register unsigned int n;
  59.            mpelPrivGCPtr mpelPriv =
  60.         (mpelPrivGCPtr) ( (ppcPrivGCPtr) pGC->devPrivates[mfbGCPrivateIndex].ptr )->devPriv;
  61.  
  62.     /* check for dash pattern useable to mpel */
  63.     for ( n = 0; n < pGC->numInDashList ; n++ )
  64.         len += pGC->dash[n];
  65.  
  66.     if ( ( len < 16 && !( len & -len ) )
  67.       || ( len == 16 && !( pGC->numInDashList & 1 ) ) ) {
  68.         register int bit;
  69.         register int offset = 0;
  70.         register unsigned char *dp = &pGC->dash[0];
  71.         mpelUserLineStyle ULineStyle;
  72.  
  73.         ULineStyle.factor = 0;
  74.         ULineStyle.mask = 0;
  75.         /* encode dash pattern into bitmask */
  76.         while ( n-- > 0 && *dp ) {
  77.             ULineStyle.mask |= ( ( ( 1 << *dp ) - 1 ) << offset );
  78.             offset += *dp++;
  79.             if ( n-- > 0 )
  80.                 offset += *dp++;
  81.         }
  82.         /* replicate pattern over full 16 bits */
  83.         for ( bit = offset; bit < 16 ; bit++ ) {
  84.             ULineStyle.mask |=
  85.                 ( ULineStyle.mask & ( 1 << bit - offset ) )
  86.                     << offset;
  87.         }
  88.         /* shift pattern to implement offset - mod 16 */
  89.         /* is it legal for offset > length ?? */
  90.         if ( pGC->dashOffset )
  91.             barrel_shift16( ULineStyle.mask, pGC->dashOffset % 16 );
  92.  
  93.             pGC->ops->PolySegment = mpelPolySegment;
  94.         pGC->ops->Polylines = mpelZeroLine;
  95.         pGC->ops->PolyArc = mpelPolyArc;
  96.         mpelPriv->LineType = MPEL_USERLINESTYLE_CONT;
  97.         mpelPriv->LineStyle = ULineStyle;
  98.     }
  99.     else {
  100.             pGC->ops->PolySegment = miPolySegment;
  101.         pGC->ops->Polylines = ppcScrnZeroDash;
  102.         pGC->ops->PolyArc = miPolyArc;
  103.         mpelPriv->LineType = MPEL_SOLIDLINE;
  104.     }
  105.     return;
  106. }
  107.