home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / lib / font / bitmap / bitmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-30  |  4.6 KB  |  160 lines

  1. /*
  2.  * $XConsortium: bitmap.c,v 1.3 91/05/30 19:06:55 keith Exp $
  3.  *
  4.  * Copyright 1991 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. #include    "fontfilest.h"
  27. #include    "bitmap.h"
  28.  
  29. int         bitmapGetGlyphs(), bitmapGetMetrics();
  30. int         bitmapGetBitmaps(), bitmapGetExtents();
  31. void        bitmapComputeFontBounds ();
  32. void        bitmapComputeFontInkBounds ();
  33.  
  34. int
  35. bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
  36.     FontPtr     pFont;
  37.     unsigned long count;
  38.     register unsigned char *chars;
  39.     FontEncoding charEncoding;
  40.     unsigned long *glyphCount;    /* RETURN */
  41.     CharInfoPtr *glyphs;    /* RETURN */
  42. {
  43.     BitmapFontPtr  bitmapFont;
  44.     unsigned int firstCol;
  45.     register unsigned int numCols;
  46.     unsigned int firstRow;
  47.     unsigned int numRows;
  48.     CharInfoPtr *glyphsBase;
  49.     register unsigned int c;
  50.     register CharInfoPtr pci;
  51.     unsigned int r;
  52.     CharInfoPtr *encoding;
  53.     CharInfoPtr pDefault;
  54.  
  55.     bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
  56.     encoding = bitmapFont->encoding;
  57.     pDefault = bitmapFont->pDefault;
  58.     firstCol = pFont->info.firstCol;
  59.     numCols = pFont->info.lastCol - firstCol + 1;
  60.     glyphsBase = glyphs;
  61.     switch (charEncoding) {
  62.  
  63.     case Linear8Bit:
  64.     case TwoD8Bit:
  65.     if (pFont->info.firstRow > 0)
  66.         break;
  67.     if (pFont->info.allExist && pDefault) {
  68.         while (count--) {
  69.         c = (*chars++) - firstCol;
  70.         if (c < numCols)
  71.             *glyphs++ = encoding[c];
  72.         else
  73.             *glyphs++ = pDefault;
  74.         }
  75.     } else {
  76.         while (count--) {
  77.         c = (*chars++) - firstCol;
  78.         if (c < numCols && (pci = encoding[c]))
  79.             *glyphs++ = pci;
  80.         else if (pDefault)
  81.             *glyphs++ = pDefault;
  82.         }
  83.     }
  84.     break;
  85.     case Linear16Bit:
  86.     if (pFont->info.allExist && pDefault) {
  87.         while (count--) {
  88.         c = *chars++ << 8;
  89.         c = (c | *chars++) - firstCol;
  90.         if (c < numCols)
  91.             *glyphs++ = encoding[c];
  92.         else
  93.             *glyphs++ = pDefault;
  94.         }
  95.     } else {
  96.         while (count--) {
  97.         c = *chars++ << 8;
  98.         c = (c | *chars++) - firstCol;
  99.         if (c < numCols && (pci = encoding[c]))
  100.             *glyphs++ = pci;
  101.         else if (pDefault)
  102.             *glyphs++ = pDefault;
  103.         }
  104.     }
  105.     break;
  106.  
  107.     case TwoD16Bit:
  108.     firstRow = pFont->info.firstRow;
  109.     numRows = pFont->info.lastRow - firstRow + 1;
  110.     while (count--) {
  111.         r = (*chars++) - firstRow;
  112.         c = (*chars++) - firstCol;
  113.         if (r < numRows && c < numCols &&
  114.             (pci = encoding[r * numCols + c]))
  115.         *glyphs++ = pci;
  116.         else if (pDefault)
  117.         *glyphs++ = pDefault;
  118.     }
  119.     break;
  120.     }
  121.     *glyphCount = glyphs - glyphsBase;
  122.     return Successful;
  123. }
  124.  
  125. static CharInfoRec nonExistantChar;
  126.  
  127. int
  128. bitmapGetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
  129.     FontPtr     pFont;
  130.     unsigned long count;
  131.     register unsigned char *chars;
  132.     FontEncoding charEncoding;
  133.     unsigned long *glyphCount;    /* RETURN */
  134.     xCharInfo **glyphs;        /* RETURN */
  135. {
  136.     int         ret;
  137.     xCharInfo  *ink_metrics;
  138.     CharInfoPtr metrics;
  139.     BitmapFontPtr  bitmapFont;
  140.     CharInfoPtr    oldDefault;
  141.     int         i;
  142.  
  143.     bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
  144.     oldDefault = bitmapFont->pDefault;
  145.     bitmapFont->pDefault = &nonExistantChar;
  146.     ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs);
  147.     if (ret == Successful) {
  148.     if (bitmapFont->ink_metrics) {
  149.         metrics = bitmapFont->metrics;
  150.         ink_metrics = bitmapFont->ink_metrics;
  151.         for (i = 0; i < *glyphCount; i++) {
  152.         if (glyphs[i] != (xCharInfo *) & nonExistantChar)
  153.             glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics);
  154.         }
  155.     }
  156.     }
  157.     bitmapFont->pDefault = oldDefault;
  158.     return ret;
  159. }
  160.