home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbtegblt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-04  |  5.5 KB  |  179 lines

  1. /* $XConsortium: cfbtegblt.c,v 5.4 91/05/04 11:52:53 keith Exp $ */
  2. /***********************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.  
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25. #include    "X.h"
  26. #include    "Xmd.h"
  27. #include    "Xproto.h"
  28. #include    "cfb.h"
  29. #include    "fontstruct.h"
  30. #include    "dixfontstr.h"
  31. #include    "gcstruct.h"
  32. #include    "windowstr.h"
  33. #include    "scrnintstr.h"
  34. #include    "pixmapstr.h"
  35. #include    "regionstr.h"
  36. #include    "cfbmskbits.h"
  37.  
  38. extern void miImageGlyphBlt();
  39.  
  40. /*
  41.     this works for fonts with glyphs <= 32 bits wide, on an
  42.     arbitrarily deep display.  Use cfbTEGlyphBlt8 for 8 bit displays.
  43.  
  44.     This should be called only with a terminal-emulator font;
  45. this means that the FIXED_METRICS flag is set, and that
  46. glyphbounds == charbounds.
  47.  
  48.     in theory, this goes faster; even if it doesn't, it reduces the
  49. flicker caused by writing a string over itself with image text (since
  50. the background gets repainted per character instead of per string.)
  51. this seems to be important for some converted X10 applications.
  52.  
  53.     Image text looks at the bits in the glyph and the fg and bg in the
  54. GC.  it paints a rectangle, as defined in the protocol dcoument,
  55. and the paints the characters.
  56.  
  57. */
  58.  
  59. void
  60. cfbTEGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  61.     DrawablePtr pDrawable;
  62.     GC         *pGC;
  63.     int     x, y;
  64.     unsigned int nglyph;
  65.     CharInfoPtr *ppci;        /* array of character info */
  66.     unsigned char *pglyphBase;    /* start of array of glyphs */
  67. {
  68.     FontPtr    pfont = pGC->font;
  69.     int widthDst;
  70.     unsigned long *pdstBase;    /* pointer to longword with top row 
  71.                    of current glyph */
  72.  
  73.     int w;            /* width of glyph and char */
  74.     int h;            /* height of glyph and char */
  75.     register int xpos=x;    /* current x%32  */
  76.     int ypos=y;            /* current y%32 */
  77.     register unsigned char *pglyph;
  78.     int widthGlyph;
  79.  
  80.     register unsigned long *pdst;/* pointer to current longword in dst */
  81.     int hTmp;            /* counter for height */
  82.     BoxRec bbox;        /* for clipping */
  83.  
  84.     register int wtmp,xtemp,width;
  85.     unsigned long bgfill,fgfill,*ptemp,tmpDst1,tmpDst2,*pdtmp;
  86.     int tmpx;
  87.  
  88.     xpos += pDrawable->x;
  89.     ypos += pDrawable->y;
  90.  
  91.     cfbGetLongWidthAndPointer (pDrawable, widthDst, pdstBase)
  92.  
  93.     wtmp = FONTMAXBOUNDS(pfont,characterWidth);
  94.     h = FONTASCENT(pfont) + FONTDESCENT(pfont);
  95.     widthGlyph = GLYPHWIDTHBYTESPADDED(*ppci);
  96.  
  97.     xpos += FONTMAXBOUNDS(pfont,leftSideBearing);
  98.     ypos -= FONTASCENT(pfont);
  99.  
  100.     bbox.x1 = xpos;
  101.     bbox.x2 = xpos + (wtmp * nglyph);
  102.     bbox.y1 = ypos;
  103.     bbox.y2 = ypos + h;
  104.  
  105.     fgfill = PFILL(pGC->fgPixel);
  106.     bgfill = PFILL(pGC->bgPixel);
  107.  
  108.     switch ((*pGC->pScreen->RectIn)(
  109.                 ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip, &bbox))
  110.     {
  111.       case rgnOUT:
  112.     break;
  113.       case rgnPART:
  114.     /* this is the WRONG thing to do, but it works.
  115.        calling the non-terminal text is easy, but slow, given
  116.        what we know about the font.
  117.  
  118.        the right thing to do is something like:
  119.         for each clip rectangle
  120.         compute at which row the glyph starts to be in it,
  121.            and at which row the glyph ceases to be in it
  122.         compute which is the first glyph inside the left
  123.             edge, and the last one inside the right edge
  124.         draw a fractional first glyph, using only
  125.             the rows we know are in
  126.         draw all the whole glyphs, using the appropriate rows
  127.         draw any pieces of the last glyph, using the right rows
  128.  
  129.        this way, the code would take advantage of knowing that
  130.        all glyphs are the same height and don't overlap.
  131.  
  132.        one day...
  133.     */
  134.     miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  135.     break;
  136.       case rgnIN:
  137.  
  138.         pdtmp = pdstBase + (widthDst * ypos);
  139.         while(nglyph--)
  140.         {
  141.  
  142.         pglyph = FONTGLYPHBITS(pglyphBase, *ppci++);
  143.             pdst = pdtmp;
  144.         hTmp = h;
  145.  
  146.         while (hTmp--)
  147.         {
  148.         x = xpos;
  149.         width = wtmp;
  150.              xtemp = 0;
  151.  
  152.         while (width > 0)
  153.         {
  154.             tmpx = x & PIM;
  155.             w = min(width, PPW - tmpx);
  156.             w = min(w, (32 - xtemp));
  157.  
  158.             ptemp = (unsigned long *)(pglyph + (xtemp >> 5));
  159.             getstipplepixels(ptemp,xtemp,w,0,&bgfill,&tmpDst1);
  160.             getstipplepixels(ptemp,xtemp,w,1,&fgfill,&tmpDst2);
  161.  
  162.             {
  163.             unsigned long tmpDst = tmpDst1 | tmpDst2;
  164.             unsigned long *pdsttmp = pdst + (x >> PWSH);
  165.             putbits(tmpDst,tmpx,w,pdsttmp,pGC->planemask);
  166.             }
  167.             x += w;
  168.             xtemp += w;
  169.             width -= w;
  170.         }
  171.         pglyph += widthGlyph;
  172.                 pdst += widthDst;
  173.         }
  174.         xpos += wtmp;
  175.         }     
  176.     break;
  177.     }
  178. }
  179.