#include "fntfilst.h"
#include "bitmap.h"
#include "fontutil.h"
#include "bdfint.h"
#include "pcf.h"
#include "snfstr.h"
typedef struct _BitmapFileFunctions {
int (*ReadFont) (FontPtr , FontFilePtr ,
int , int ,
int , int );
int (*ReadInfo) ( FontInfoPtr ,
FontFilePtr );
} BitmapFileFunctionsRec, *BitmapFileFunctionsPtr;
static BitmapFileFunctionsRec readers[] = {
#ifdef PCFFORMAT
{ pcfReadFont, pcfReadFontInfo} ,
{ pcfReadFont, pcfReadFontInfo} ,
#ifdef X_GZIP_FONT_COMPRESSION
{ pcfReadFont, pcfReadFontInfo} ,
#endif
#endif
#ifdef SNFFORMAT
{ snfReadFont, snfReadFontInfo},
{ snfReadFont, snfReadFontInfo},
#ifdef X_GZIP_FONT_COMPRESSION
{ snfReadFont, snfReadFontInfo} ,
#endif
#endif
#ifdef BDFFORMAT
{ bdfReadFont, bdfReadFontInfo} ,
{ bdfReadFont, bdfReadFontInfo} ,
#ifdef X_GZIP_FONT_COMPRESSION
{ bdfReadFont, bdfReadFontInfo} ,
#endif
#endif
#ifdef PCFFORMAT
{ pmfReadFont, pcfReadFontInfo} ,
#endif
};
#define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
static FontRendererRec renderers[] = {
#ifdef PCFFORMAT
{ ".pcf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
{ ".pcf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#ifdef X_GZIP_FONT_COMPRESSION
{ ".pcf.gz", 7,
BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#endif
#endif
#ifdef SNFFORMAT
{ ".snf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
{ ".snf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#ifdef X_GZIP_FONT_COMPRESSION
{ ".snf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#endif
#endif
#ifdef BDFFORMAT
{ ".bdf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
{ ".bdf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#ifdef X_GZIP_FONT_COMPRESSION
{ ".bdf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
#endif
#endif
#ifdef PCFFORMAT
{ ".pmf", 4, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES }
#endif
};
int
BitmapOpenBitmap (FontPathElementPtr fpe, FontPtr *ppFont, int flags,
FontEntryPtr entry, char *fileName,
fsBitmapFormat format, fsBitmapFormatMask fmask,
FontPtr non_cachable_font)
{
FontFilePtr file;
FontPtr pFont;
int i;
int ret;
int bit,
byte,
glyph,
scan,
image;
i = BitmapGetRenderIndex(entry->u.bitmap.renderer);
file = FontFileOpen (fileName);
if (!file)
return BadFontName;
if (!(pFont = CreateFontRec())) {
fprintf(stderr, "Error: Couldn't allocate pFont (%ld)\n",
(unsigned long)sizeof(FontRec));
FontFileClose (file);
return AllocError;
}
FontDefaultFormat(&bit, &byte, &glyph, &scan);
ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
pFont->refcnt = 0;
ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan);
FontFileClose (file);
if (ret != Successful) {
xfree(pFont);
} else {
*ppFont = pFont;
}
return ret;
}
int
BitmapGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo,
FontEntryPtr entry, char *fileName)
{
FontFilePtr file;
int i;
int ret;
FontRendererPtr renderer;
renderer = FontFileMatchRenderer (fileName);
if (!renderer)
return BadFontName;
i = BitmapGetRenderIndex(renderer);
file = FontFileOpen (fileName);
if (!file)
return BadFontName;
ret = (*readers[i].ReadInfo) (pFontInfo, file);
FontFileClose (file);
return ret;
}
#define numRenderers (sizeof renderers / sizeof renderers[0])
void
BitmapRegisterFontFileFunctions (void)
{
int i;
for (i = 0; i < numRenderers; i++)
FontFileRegisterRenderer (&renderers[i]);
}
int
BitmapGetRenderIndex(FontRendererPtr renderer)
{
return renderer - renderers;
}