home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / dec / qdss / qdtext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-19  |  6.6 KB  |  220 lines

  1. /***********************************************************
  2. Copyright 1987, 1988 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. #include "X.h"
  26. #include "Xproto.h"
  27. #include "gcstruct.h"
  28. #include "windowstr.h"
  29. #include "qd.h"
  30. #include "qdgc.h"
  31. #include "servermd.h"
  32. #include "fontstruct.h"
  33. #include "dixfontstr.h"
  34. #define SFEncodedFontPtr        FontPtr
  35. #define SFEncodedFontRec        FontRec
  36. #define SFCharSetPtr            FontInfoPtr
  37. #define SFCharSetRec            FontInfoRec
  38.  
  39.  
  40. void
  41. qdImageTextPix( pDraw, pGC, x0, y0, nChars, pStr)
  42.     DrawablePtr pDraw;
  43.     GCPtr    pGC;
  44.     int        x0, y0;
  45.     int        nChars;
  46.     char *    pStr;
  47. {
  48.     CHECK_MOVED(pGC, pDraw);
  49.     if (QD_PIX_DATA((PixmapPtr)pDraw) == NULL) {
  50.     /* make dummy window and use that as the drawable */
  51.     SETUP_PIXMAP_AS_WINDOW(pDraw, pGC);
  52.     /*
  53.      * tlImageText is somewhat faster than qdImageTextKerned,
  54.      * but in the interest of simplicity, we just go for the more
  55.      * general case, without testing to see if that is needed.
  56.      */
  57.     qdImageTextKerned(pDraw, pGC, x0, y0, nChars, pStr);
  58.     CLEANUP_PIXMAP_AS_WINDOW(pGC);
  59.     }
  60.     else
  61.     miImageText8( pDraw, pGC, x0, y0, nChars, pStr);
  62. }
  63.  
  64. int
  65. qdPolyTextPix( pDraw, pGC, x0, y0, nChars, pStr)
  66.     DrawablePtr pDraw;
  67.     GCPtr    pGC;
  68.     int        x0, y0;
  69.     int     nChars;
  70.     char *    pStr;
  71. {
  72.     CHECK_MOVED(pGC, pDraw);
  73.     if (QD_PIX_DATA((PixmapPtr)pDraw) == NULL) {
  74.     int width;
  75.     /* make dummy window and use that as the drawable */
  76.     SETUP_PIXMAP_AS_WINDOW(pDraw, pGC);
  77.     width = tlPolyText( pDraw, pGC, x0, y0, nChars, pStr);
  78.     CLEANUP_PIXMAP_AS_WINDOW(pGC);
  79.     return width;
  80.     }
  81.     else
  82.     return miPolyText8( pDraw, pGC, x0, y0, nChars, pStr);
  83. }
  84.  
  85. qdImageTextKerned( pDraw, pGC, x0, y0, nChars, pStr)
  86.     DrawablePtr pDraw;
  87.     GCPtr    pGC;
  88.     int        x0, y0;
  89.     int     nChars;
  90.     char *    pStr;
  91. {
  92.     xRectangle rect;
  93.     register unsigned char *p;
  94.     register int i, w;
  95.     SFEncodedFontPtr pFont= pGC->font;
  96.     int chfirst = FONTFIRSTCOL(pFont);
  97.     int chlast = FONTLASTCOL(pFont);
  98.     unsigned long n;
  99.     int        ic;
  100. #ifdef NEW_FONTS
  101.     register CharInfoPtr *ppCI = pFont->ppCI - chfirst;
  102. #else
  103.     register CharInfoPtr *pci;
  104. #endif /* NEW_FONTS */
  105.     int saveAlu = pGC->alu;
  106.     int saveFgPixel = pGC->fgPixel;
  107.  
  108.     if(!(pci = (CharInfoPtr *)ALLOCATE_LOCAL(nChars*sizeof(CharInfoPtr)))) {
  109.     DEALLOCATE_LOCAL(chars);
  110.     return(-1);
  111.     }
  112. /*
  113.     Choose Linear8Bit encoding by clues in qdgc.c,
  114.     fonts/lib/font/bitmap/bitmap.c
  115. */
  116.     GetGlyphs(pFont, nChars, pStr, Linear8Bit, &n, pci);
  117.  
  118.     /* calculate width of string pStr */
  119.     for (w = 0, i = nChars, p = (unsigned char*)pStr; --i >= 0; ) {
  120.     register ch = *p++;
  121.     if (ch < chfirst || ch > chlast) {
  122.         ch=    FONTDEFAULTCH(pFont);
  123.         if (ch < chfirst || ch > chlast) continue;
  124.         /* SKK: else default characterWidth.... */
  125.     }
  126. #ifdef NEW_FONTS
  127.     w += ppCI[ch]->metrics.characterWidth;
  128. #else
  129.     w += pci[i]->metrics.characterWidth;
  130. #endif /* NEW_FONTS */
  131.     }
  132.     DEALLOCATE_LOCAL(pci);
  133.  
  134.     rect.x = x0;
  135.     rect.y = y0 - FONTASCENT(pFont);
  136.     rect.width = w;
  137.     rect.height = FONTASCENT(pFont)+FONTDESCENT(pFont);
  138.     pGC->alu = GXcopy;
  139.     pGC->fgPixel = pGC->bgPixel;
  140.     tlSolidRects(pDraw, pGC, 1, &rect);
  141.     pGC->fgPixel = saveFgPixel;
  142.     tlPolyTextSolid( pDraw, pGC, x0, y0, nChars, pStr);
  143.     pGC->alu = saveAlu;
  144. }
  145.  
  146. void
  147. qdPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci)
  148.     DrawablePtr pDrawable;
  149.     GC         *pGC;
  150.     int     x, y;
  151.     unsigned int nglyph;
  152.     CharInfoPtr *ppci;        /* array of character info */
  153.  
  154. {
  155.     int width, height;
  156.     int nbyLine;            /* bytes per line of padded pixmap */
  157.     SFEncodedFontRec     *pfont;
  158.     register int i;
  159.     register int j;
  160.     unsigned char *pbits;        /* buffer for PutImage */
  161.     register unsigned char *pb;        /* temp pointer into buffer */
  162.     register CharInfoPtr pci;        /* currect char info */
  163.     register unsigned char *pglyph;    /* pointer bits in glyph */
  164.     int gWidth, gHeight;        /* width and height of glyph */
  165.     register int nbyGlyphWidth;        /* bytes per scanline of glyph */
  166.     int nbyPadGlyph;            /* server padded line of glyph */
  167.     QDPixRec dummyPixmap[1];
  168.  
  169.     if ((pDrawable->type == DRAWABLE_WINDOW) &&
  170.     (pGC->miTranslate))
  171.     {
  172.     x += pGC->lastWinOrg.x;
  173.     y += pGC->lastWinOrg.y;
  174.     }
  175.  
  176.     pfont=    pGC->font;
  177.     width = FONTMAXBOUNDS(pfont,rightSideBearing) - 
  178.         FONTMINBOUNDS(pfont,leftSideBearing);
  179.     height = FONTASCENT(pfont)+FONTDESCENT(pfont);
  180.  
  181.     nbyLine = PixmapBytePad(width, 1);
  182.     pbits = (unsigned char *)ALLOCATE_LOCAL(height*nbyLine);
  183.     if (!pbits)
  184.         return ;
  185.  
  186.     dummyPixmap->pixmap.drawable.type = DRAWABLE_PIXMAP;
  187.     dummyPixmap->pixmap.drawable.depth = 1;
  188.     dummyPixmap->pixmap.drawable.pScreen = pDrawable->pScreen;
  189.     QDPIX_X(dummyPixmap) = 0;
  190.     QDPIX_Y(dummyPixmap) = 0;
  191.     dummyPixmap->planes = 0;
  192.  
  193.     while(nglyph--) {
  194.     pci = *ppci++;
  195.     pglyph = FONTGLYPHBITS(0,pci);
  196.     gWidth = GLYPHWIDTHPIXELS(pci);
  197.     gHeight = GLYPHHEIGHTPIXELS(pci);
  198.     nbyGlyphWidth = GLYPHWIDTHBYTESPADDED(pci);
  199.     nbyPadGlyph = PixmapBytePad(gWidth, 1);
  200.  
  201.     for (i=0, pb = pbits; i<gHeight; i++, pb = pbits+(i*nbyPadGlyph))
  202.         for (j = 0; j < nbyGlyphWidth; j++)
  203.         *pb++ = *pglyph++;
  204.  
  205.     QDPIX_WIDTH(&dummyPixmap->pixmap) = gWidth;
  206.     QDPIX_HEIGHT(&dummyPixmap->pixmap) = gHeight;
  207.     dummyPixmap->pixmap.devKind = PixmapBytePad(gWidth, 1);
  208.     QD_PIX_DATA(&dummyPixmap->pixmap) = pbits;
  209.     qdPushPixels(pGC, &dummyPixmap->pixmap, pDrawable,
  210.              gWidth, gHeight,
  211.              x + pci->metrics.leftSideBearing,
  212.              y - pci->metrics.ascent);
  213.     /* hack to prevent CopyPixmapFromOffscreen */
  214.     QD_PIX_DATA(&dummyPixmap->pixmap) = (unsigned char *)1;
  215.     tlCancelPixmap(dummyPixmap);
  216.     x += pci->metrics.characterWidth;
  217.     }
  218.     DEALLOCATE_LOCAL(pbits);
  219. }
  220.