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

  1. /*
  2.  * $XConsortium: bitmapfuncs.c,v 1.3 91/06/12 14:35:17 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. typedef struct _BitmapFileFunctions {
  30.     int         (*ReadFont) ( /* pFont, file, bit, byte, glyph, scan */ );
  31.     int         (*ReadInfo) ( /* pFontInfo, file */ );
  32. }           BitmapFileFunctionsRec, *BitmapFileFunctionsPtr;
  33.  
  34. extern int  pcfReadFont(), pcfReadFontInfo();
  35. extern int  snfReadFont(), snfReadFontInfo();
  36. extern int  bdfReadFont(), bdfReadFontInfo();
  37. int        BitmapOpenBitmap ();
  38. extern int  BitmapOpenScalable ();
  39. int        BitmapGetInfoBitmap ();
  40. extern int  BitmapGetInfoScalable ();
  41.  
  42. /*
  43.  * these two arrays must be in the same order
  44.  */
  45. static BitmapFileFunctionsRec readers[] = {
  46.     pcfReadFont, pcfReadFontInfo,
  47.     snfReadFont, snfReadFontInfo,
  48.     bdfReadFont, bdfReadFontInfo,
  49. };
  50.  
  51. static FontRendererRec    renderers[] = {
  52.     ".pcf", 4,
  53.     BitmapOpenBitmap, BitmapOpenScalable,
  54.     BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
  55.     ".snf", 4,
  56.     BitmapOpenBitmap, BitmapOpenScalable,
  57.     BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
  58.     ".bdf", 4,
  59.     BitmapOpenBitmap, BitmapOpenScalable,
  60.     BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
  61. };
  62.  
  63. BitmapOpenBitmap (fpe, ppFont, flags, entry, fileName, format, fmask)
  64.     FontPathElementPtr    fpe;
  65.     FontPtr        *ppFont;
  66.     int            flags;
  67.     FontEntryPtr    entry;
  68.     char        *fileName;
  69.     fsBitmapFormat    format;
  70.     fsBitmapFormatMask    fmask;
  71. {
  72.     FILE       *file;
  73.     FontPtr     pFont;
  74.     int         i;
  75.     int         ret;
  76.     int         bit,
  77.                 byte,
  78.                 glyph,
  79.                 scan,
  80.         image;
  81.  
  82.     /*
  83.      * compute offset into renderers array - same offset is
  84.      * useful in the file functions array
  85.      */
  86.     i = entry->u.bitmap.renderer - renderers;
  87.     file = fopen(fileName, "r");
  88.     if (!file)
  89.     return BadFontName;
  90.     pFont = (FontPtr) xalloc(sizeof(FontRec));
  91.     if (!pFont) {
  92.     fclose(file);
  93.     return AllocError;
  94.     }
  95.     /* set up default values */
  96.     FontDefaultFormat(&bit, &byte, &glyph, &scan);
  97.     /* get any changes made from above */
  98.     ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
  99.  
  100.     /* Fill in font record. Data format filled in by reader. */
  101.     pFont->refcnt = 0;
  102.     pFont->maxPrivate = -1;
  103.     pFont->devPrivates = (pointer *) 0;
  104.  
  105.     ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan);
  106.  
  107.     fclose(file);
  108.     if (ret != Successful)
  109.     xfree(pFont);
  110.     else
  111.     *ppFont = pFont;
  112.     return ret;
  113. }
  114.  
  115. BitmapGetInfoBitmap (fpe, pFontInfo, entry, fileName)
  116.     FontPathElementPtr    fpe;
  117.     FontInfoPtr        pFontInfo;
  118.     FontEntryPtr    entry;
  119.     char        *fileName;
  120. {
  121.     FILE    *file;
  122.     int        i;
  123.     int        ret;
  124.     FontRendererPtr renderer;
  125.  
  126.     renderer = FontFileMatchRenderer (fileName);
  127.     if (!renderer)
  128.     return BadFontName;
  129.     i = renderer - renderers;
  130.     file = fopen (fileName, "r");
  131.     if (!file)
  132.     return BadFontName;
  133.     ret = (*readers[i].ReadInfo) (pFontInfo, file);
  134.     fclose (file);
  135.     return ret;
  136. }
  137.  
  138. #define numRenderers    (sizeof renderers / sizeof renderers[0])
  139.  
  140. BitmapRegisterFontFileFunctions ()
  141. {
  142.     int        i;
  143.  
  144.     for (i = 0; i < numRenderers; i++)
  145.     FontFileRegisterRenderer (&renderers[i]);
  146. }
  147.