home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbtegblt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-25  |  8.8 KB  |  321 lines

  1. /* $XConsortium: mfbtegblt.c,v 5.7 91/05/26 09:02:16 rws Exp $ */
  2. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  3. /***********************************************************
  4. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  5. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Digital or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.  
  16.  
  17. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ******************************************************************/
  26. #include    "X.h"
  27. #include    "Xmd.h"
  28. #include    "Xproto.h"
  29. #include    "mfb.h"
  30. #include    "fontstruct.h"
  31. #include    "dixfontstr.h"
  32. #include    "gcstruct.h"
  33. #include    "windowstr.h"
  34. #include    "scrnintstr.h"
  35. #include    "pixmapstr.h"
  36. #include    "regionstr.h"
  37. #include    "maskbits.h"
  38.  
  39. /*
  40.     this works for fonts with glyphs <= 32 bits wide.
  41.  
  42.     This should be called only with a terminal-emulator font;
  43. this means that the FIXED_METRICS flag is set, and that
  44. glyphbounds == charbounds.
  45.  
  46.     in theory, this goes faster; even if it doesn't, it reduces the
  47. flicker caused by writing a string over itself with image text (since
  48. the background gets repainted per character instead of per string.)
  49. this seems to be important for some converted X10 applications.
  50.  
  51.     Image text looks at the bits in the glyph and the fg and bg in the
  52. GC.  it paints a rectangle, as defined in the protocol dcoument,
  53. and the paints the characters.
  54.  
  55.    to avoid source proliferation, this file is compiled
  56. two times:
  57.     MFBTEGLYPHBLT        OP
  58.     mfbTEGlyphBltWhite        (white text, black bg )
  59.     mfbTEGlyphBltBlack    ~    (black text, white bg )
  60.  
  61. */
  62.  
  63. #if defined(NO_3_60_CG4) && defined(FASTPUTBITS) && defined(FASTGETBITS)
  64. #define FASTCHARS
  65. #endif
  66.  
  67. /*
  68.  * this macro "knows" that only characters <= 8 bits wide will
  69.  * fit this case (which is why it is independent of GLYPHPADBYTES)
  70.  */
  71.  
  72. #if (BITMAP_BIT_ORDER == MSBFirst) && (GLYPHPADBYTES != 4)
  73. #if GLYPHPADBYTES == 1
  74. #define ShiftAmnt   24
  75. #else
  76. #define ShiftAmnt   16
  77. #endif
  78.  
  79. #define GetBits4    c = (*char1++ << ShiftAmnt) | \
  80.             SCRRIGHT (*char2++ << ShiftAmnt, xoff2) | \
  81.             SCRRIGHT (*char3++ << ShiftAmnt, xoff3) | \
  82.             SCRRIGHT (*char4++ << ShiftAmnt, xoff4);
  83. #else
  84. #define GetBits4    c = *char1++ | \
  85.             SCRRIGHT (*char2++, xoff2) | \
  86.             SCRRIGHT (*char3++, xoff3) | \
  87.             SCRRIGHT (*char4++, xoff4);
  88. #endif
  89.  
  90.  
  91. #if GLYPHPADBYTES == 1
  92. typedef    unsigned char    *glyphPointer;
  93. #define USE_LEFTBITS
  94. #endif
  95.  
  96. #if GLYPHPADBYTES == 2
  97. typedef unsigned short    *glyphPointer;
  98. #define USE_LEFTBITS
  99. #endif
  100.  
  101. #if GLYPHPADBYTES == 4
  102. typedef unsigned int    *glyphPointer;
  103. #endif
  104.  
  105. #ifdef USE_LEFTBITS
  106. #define GetBits1    getleftbits (char1, widthGlyph, c); \
  107.             c &= glyphMask; \
  108.             char1 = (glyphPointer) (((char *) char1) + glyphBytes);
  109. #else
  110. #define GetBits1    c = *char1++;
  111. #endif
  112.  
  113. void
  114. MFBTEGLYPHBLT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  115.     DrawablePtr pDrawable;
  116.     GC         *pGC;
  117.     int     x, y;
  118.     unsigned int nglyph;
  119.     CharInfoPtr *ppci;        /* array of character info */
  120.     unsigned char *pglyphBase;    /* start of array of glyphs */
  121. {
  122.     FontPtr    pfont = pGC->font;
  123.     int widthDst;
  124.     unsigned int *pdstBase;    /* pointer to longword with top row 
  125.                    of current glyph */
  126.  
  127.     int h;            /* height of glyph and char */
  128.     register int xpos;        /* current x  */
  129.     int ypos;            /* current y */
  130.     int widthGlyph;
  131.  
  132.     int hTmp;            /* counter for height */
  133.     register int startmask, endmask;
  134.     int nfirst;            /* used if glyphs spans a longword boundary */
  135.     BoxRec bbox;        /* for clipping */
  136.     int    widthGlyphs;
  137.     register unsigned int  *dst;
  138.     register unsigned int  c;
  139.     register int        xoff1, xoff2, xoff3, xoff4;
  140.     register glyphPointer   char1, char2, char3, char4;
  141.  
  142. #ifdef USE_LEFTBITS
  143.     register int        glyphMask;
  144.     register unsigned int  tmpSrc;
  145.     register int        glyphBytes;
  146. #endif
  147.  
  148.     if (!(pGC->planemask & 1))
  149.     return;
  150.  
  151.     if (pDrawable->type == DRAWABLE_WINDOW)
  152.     {
  153.     pdstBase = (unsigned int *)
  154.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  155.     widthDst = (int)
  156.           (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind) >> 2;
  157.     }
  158.     else
  159.     {
  160.     pdstBase = (unsigned int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  161.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  162.     }
  163.  
  164.     xpos = x + pDrawable->x;
  165.     ypos = y + pDrawable->y;
  166.  
  167.     widthGlyph = FONTMAXBOUNDS(pfont,characterWidth);
  168.     h = FONTASCENT(pfont) + FONTDESCENT(pfont);
  169.  
  170.     xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
  171.     ypos -= FONTASCENT(pfont);
  172.  
  173.     bbox.x1 = xpos;
  174.     bbox.x2 = xpos + (widthGlyph * nglyph);
  175.     bbox.y1 = ypos;
  176.     bbox.y2 = ypos + h;
  177.  
  178.     switch ((*pGC->pScreen->RectIn)(
  179.                 ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  180.     {
  181.       case rgnPART:
  182.     /* this is the WRONG thing to do, but it works.
  183.        calling the non-terminal text is easy, but slow, given
  184.        what we know about the font.
  185.  
  186.        the right thing to do is something like:
  187.         for each clip rectangle
  188.         compute at which row the glyph starts to be in it,
  189.            and at which row the glyph ceases to be in it
  190.         compute which is the first glyph inside the left
  191.             edge, and the last one inside the right edge
  192.         draw a fractional first glyph, using only
  193.             the rows we know are in
  194.         draw all the whole glyphs, using the appropriate rows
  195.         draw any pieces of the last glyph, using the right rows
  196.  
  197.        this way, the code would take advantage of knowing that
  198.        all glyphs are the same height and don't overlap.
  199.  
  200.        one day...
  201.     */
  202.     CLIPTETEXT(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  203.       case rgnOUT:
  204.     return;
  205.     }
  206.     pdstBase += widthDst * ypos;
  207.     widthGlyphs = widthGlyph << 2;
  208.  
  209. #ifdef USE_LEFTBITS
  210.     glyphMask = endtab[widthGlyph];
  211.     glyphBytes = GLYPHWIDTHBYTESPADDED(*ppci);
  212. #endif
  213.  
  214.     if (nglyph >= 4 && widthGlyphs <= 32)
  215.     {
  216.     while (nglyph >= 4)
  217.     {
  218.         nglyph -= 4;
  219.         xoff1 = xpos & 0x1f;
  220.         xoff2 = widthGlyph;
  221.         xoff3 = xoff2 + widthGlyph;
  222.         xoff4 = xoff3 + widthGlyph;
  223.         char1 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
  224.         char2 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
  225.         char3 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
  226.         char4 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
  227.  
  228.         hTmp = h;
  229.         dst = pdstBase + (xpos >> 5);
  230.  
  231. #ifndef FASTCHARS
  232.         if (xoff1 + widthGlyphs <= 32)
  233.         {
  234.         maskpartialbits (xoff1, widthGlyphs, startmask);
  235. #endif
  236.         while (hTmp--)
  237.         {
  238.             GetBits4
  239. #ifdef FASTCHARS
  240. # if BITMAP_BIT_ORDER == MSBFirst
  241.             c >>= 32 - widthGlyphs;
  242. # endif
  243.             FASTPUTBITS(OP(c), xoff1, widthGlyphs, dst);
  244. #else
  245.             *(dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
  246. #endif
  247.             dst += widthDst;
  248.         }
  249. #ifndef FASTCHARS
  250.         }
  251.         else
  252.         {
  253.         mask32bits (xoff1, widthGlyphs, startmask, endmask);
  254.         nfirst = 32 - xoff1;
  255.         while (hTmp--)
  256.         {
  257.             GetBits4
  258.             dst[0] = dst[0] & ~startmask |
  259.                  OP(SCRRIGHT(c,xoff1)) & startmask;
  260.             dst[1] = dst[1] & ~endmask |
  261.                  OP(SCRLEFT(c,nfirst)) & endmask;
  262.             dst += widthDst;
  263.         }
  264.         }
  265. #endif
  266.         xpos += widthGlyphs;
  267.     }
  268.     }
  269.  
  270.     while(nglyph--)
  271.     {
  272.     xoff1 = xpos & 0x1f;
  273.     char1 = (glyphPointer) FONTGLYPHBITS(pglyphBase,(*ppci++));
  274.     hTmp = h;
  275.     dst = pdstBase + (xpos >> 5);
  276.  
  277. #ifndef FASTCHARS
  278.     if (xoff1 + widthGlyph <= 32)
  279.     {
  280.         maskpartialbits (xoff1, widthGlyph, startmask);
  281. #endif
  282.         while (hTmp--)
  283.         {
  284. #ifdef FASTCHARS
  285. #ifdef USE_LEFTBITS
  286.         FASTGETBITS (char1,0,widthGlyph,c);
  287.         char1 = (glyphPointer) (((char *) char1) + glyphBytes);
  288. #else
  289.         c = *char1++;
  290. #if BITMAP_BIT_ORDER == MSBFirst
  291.         c >>= 32 - widthGlyph;
  292. #endif
  293. #endif
  294.         FASTPUTBITS (OP(c),xoff1,widthGlyph,dst);
  295. #else
  296.         GetBits1
  297.         (*dst) = (*dst) & ~startmask | OP(SCRRIGHT(c, xoff1)) & startmask;
  298. #endif
  299.         dst += widthDst;
  300.         }
  301. #ifndef FASTCHARS
  302.     }
  303.     else
  304.     {
  305.         mask32bits (xoff1, widthGlyph, startmask, endmask);
  306.         nfirst = 32 - xoff1;
  307.         while (hTmp--)
  308.         {
  309.         GetBits1
  310.         dst[0] = dst[0] & ~startmask |
  311.              OP(SCRRIGHT(c,xoff1)) & startmask;
  312.         dst[1] = dst[1] & ~endmask |
  313.              OP(SCRLEFT(c,nfirst)) & endmask;
  314.         dst += widthDst;
  315.         }
  316.     }
  317. #endif
  318.     xpos += widthGlyph;
  319.     }
  320. }
  321.