home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mi / miglblt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  6.6 KB  |  226 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.  
  25. /* $XConsortium: miglblt.c,v 5.5 91/07/18 22:53:03 keith Exp $ */
  26.  
  27. #include    "X.h"
  28. #include    "Xmd.h"
  29. #include    "Xproto.h"
  30. #include    "misc.h"
  31. #include    "fontstruct.h"
  32. #include    "dixfontstr.h"
  33. #include    "gcstruct.h"
  34. #include    "windowstr.h"
  35. #include    "scrnintstr.h"
  36. #include    "pixmap.h"
  37. #include    "servermd.h"
  38.  
  39. extern void QueryGlyphExtents();
  40.  
  41. /*
  42.     machine-independent glyph blt.
  43.     assumes that glyph bits in snf are written in bytes,
  44. have same bit order as the server's bitmap format,
  45. and are byte padded.  this corresponds to the snf distributed
  46. with the sample server.
  47.  
  48.     get a scratch GC.
  49.     in the scratch GC set alu = GXcopy, fg = 1, bg = 0
  50.     allocate a bitmap big enough to hold the largest glyph in the font
  51.     validate the scratch gc with the bitmap
  52.     for each glyph
  53.     carefully put the bits of the glyph in a buffer,
  54.         padded to the server pixmap scanline padding rules
  55.     fake a call to PutImage from the buffer into the bitmap
  56.     use the bitmap in a call to PushPixels
  57. */
  58.  
  59. void
  60. miPolyGlyphBlt(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.     int width, height;
  69.     PixmapPtr pPixmap;
  70.     int nbyLine;            /* bytes per line of padded pixmap */
  71.     FontPtr pfont;
  72.     GCPtr pGCtmp;
  73.     register int i;
  74.     register int j;
  75.     unsigned char *pbits;        /* buffer for PutImage */
  76.     register unsigned char *pb;        /* temp pointer into buffer */
  77.     register CharInfoPtr pci;        /* currect char info */
  78.     register unsigned char *pglyph;    /* pointer bits in glyph */
  79.     int gWidth, gHeight;        /* width and height of glyph */
  80.     register int nbyGlyphWidth;        /* bytes per scanline of glyph */
  81.     int nbyPadGlyph;            /* server padded line of glyph */
  82.  
  83.     XID gcvals[3];
  84.  
  85.     if (pGC->miTranslate)
  86.     {
  87.     x += pDrawable->x;
  88.     y += pDrawable->y;
  89.     }
  90.  
  91.     pfont = pGC->font;
  92.     width = FONTMAXBOUNDS(pfont,rightSideBearing) - 
  93.         FONTMINBOUNDS(pfont,leftSideBearing);
  94.     height = FONTMAXBOUNDS(pfont,ascent) +
  95.          FONTMAXBOUNDS(pfont,descent);
  96.  
  97.     pPixmap = (*pDrawable->pScreen->CreatePixmap)(pDrawable->pScreen,
  98.                           width, height, 1);
  99.     if (!pPixmap)
  100.     return;
  101.  
  102.     pGCtmp = GetScratchGC(1, pDrawable->pScreen);
  103.     if (!pGCtmp)
  104.     {
  105.     (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
  106.     return;
  107.     }
  108.  
  109.     gcvals[0] = GXcopy;
  110.     gcvals[1] = 1;
  111.     gcvals[2] = 0;
  112.  
  113.     DoChangeGC(pGCtmp, GCFunction|GCForeground|GCBackground, gcvals, 0);
  114.  
  115.     nbyLine = PixmapBytePad(width, 1);
  116.     pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
  117.     if (!pbits)
  118.     {
  119.     (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
  120.     FreeScratchGC(pGCtmp);
  121.         return;
  122.     }
  123.     while(nglyph--)
  124.     {
  125.     pci = *ppci++;
  126.     pglyph = FONTGLYPHBITS(pglyphBase, pci);
  127.     gWidth = GLYPHWIDTHPIXELS(pci);
  128.     gHeight = GLYPHHEIGHTPIXELS(pci);
  129.     if (gWidth && gHeight)
  130.     {
  131.         nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
  132.         nbyPadGlyph = PixmapBytePad(gWidth, 1);
  133.  
  134.         if (nbyGlyphWidth == nbyPadGlyph
  135. #if GLYPHPADBYTES != 4
  136.             && (((int) pglyph) & 3) == 0
  137. #endif
  138.         )
  139.         {
  140.         pb = pglyph;
  141.         }
  142.         else
  143.         {
  144.         for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
  145.             for (j = 0; j < nbyGlyphWidth; j++)
  146.             *pb++ = *pglyph++;
  147.         pb = pbits;
  148.         }
  149.  
  150.         if ((pGCtmp->serialNumber) != (pPixmap->drawable.serialNumber))
  151.         ValidateGC((DrawablePtr)pPixmap, pGCtmp);
  152.         (*pGCtmp->ops->PutImage)(pPixmap, pGCtmp, pPixmap->drawable.depth,
  153.                 0, 0, gWidth, gHeight, 
  154.                 0, XYBitmap, pb);
  155.  
  156.         if ((pGC->serialNumber) != (pDrawable->serialNumber))
  157.         ValidateGC(pDrawable, pGC);
  158.         (*pGC->ops->PushPixels)(pGC, pPixmap, pDrawable,
  159.                    gWidth, gHeight,
  160.                    x + pci->metrics.leftSideBearing,
  161.                    y - pci->metrics.ascent);
  162.     }
  163.     x += pci->metrics.characterWidth;
  164.     }
  165.     (*pDrawable->pScreen->DestroyPixmap)(pPixmap);
  166.     DEALLOCATE_LOCAL(pbits);
  167.     FreeScratchGC(pGCtmp);
  168. }
  169.  
  170.  
  171. void
  172. miImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
  173.     DrawablePtr pDrawable;
  174.     GC         *pGC;
  175.     int     x, y;
  176.     unsigned int nglyph;
  177.     CharInfoPtr *ppci;        /* array of character info */
  178.     unsigned char *pglyphBase;    /* start of array of glyphs */
  179. {
  180.     ExtentInfoRec info;        /* used by QueryGlyphExtents() */
  181.     XID gcvals[3];
  182.     int oldAlu, oldFS;
  183.     unsigned long    oldFG;
  184.     xRectangle backrect;
  185.  
  186.     QueryGlyphExtents(pGC->font, ppci, (unsigned long)nglyph, &info);
  187.  
  188.     if (info.overallWidth >= 0)
  189.     {
  190.         backrect.x = x;
  191.         backrect.width = info.overallWidth;
  192.     }
  193.     else
  194.     {
  195.     backrect.x = x + info.overallWidth;
  196.     backrect.width = -info.overallWidth;
  197.     }
  198.     backrect.y = y - FONTASCENT(pGC->font);
  199.     backrect.height = FONTASCENT(pGC->font) + FONTDESCENT(pGC->font);
  200.  
  201.     oldAlu = pGC->alu;
  202.     oldFG = pGC->fgPixel;
  203.     oldFS = pGC->fillStyle;
  204.  
  205.     /* fill in the background */
  206.     gcvals[0] = GXcopy;
  207.     gcvals[1] = pGC->bgPixel;
  208.     gcvals[2] = FillSolid;
  209.     DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
  210.     ValidateGC(pDrawable, pGC);
  211.     (*pGC->ops->PolyFillRect)(pDrawable, pGC, 1, &backrect);
  212.  
  213.     /* put down the glyphs */
  214.     gcvals[0] = oldFG;
  215.     DoChangeGC(pGC, GCForeground, gcvals, 0);
  216.     ValidateGC(pDrawable, pGC);
  217.     (*pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase);
  218.  
  219.     /* put all the toys away when done playing */
  220.     gcvals[0] = oldAlu;
  221.     gcvals[1] = oldFG;
  222.     gcvals[2] = oldFS;
  223.     DoChangeGC(pGC, GCFunction|GCForeground|GCFillStyle, gcvals, 0);
  224.  
  225. }
  226.