#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef PCFFORMAT
#define XFONT_PCFFORMAT 1
#endif
#ifdef SNFFORMAT
#define XFONT_SNFFORMAT 1
#endif
#ifdef BDFFORMAT
#define XFONT_BDFFORMAT 1
#endif
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
#include <X11/fonts/fontutil.h>
#include <X11/fonts/bdfint.h>
#include <X11/fonts/pcf.h>
#include "snfstr.h"
typedef struct _BitmapFileFunctions {
int (*ReadFont) (FontPtr , FontFilePtr ,
int , int ,
int , int );
int (*ReadInfo) ( FontInfoPtr ,
FontFilePtr );
} BitmapFileFunctionsRec, *BitmapFileFunctionsPtr;
static int BitmapGetRenderIndex(FontRendererPtr renderer);
static BitmapFileFunctionsRec readers[] = {
#if XFONT_PCFFORMAT
{ pcfReadFont, pcfReadFontInfo} ,
{ pcfReadFont, pcfReadFontInfo} ,
# ifdef X_GZIP_FONT_COMPRESSION
{ pcfReadFont, pcfReadFontInfo} ,
# endif
# ifdef X_BZIP2_FONT_COMPRESSION
{ pcfReadFont, pcfReadFontInfo} ,
# endif
#endif
#if XFONT_SNFFORMAT
{ snfReadFont, snfReadFontInfo},
{ snfReadFont, snfReadFontInfo},
# ifdef X_GZIP_FONT_COMPRESSION
{ snfReadFont, snfReadFontInfo} ,
# endif
# ifdef X_BZIP2_FONT_COMPRESSION
{ snfReadFont, snfReadFontInfo} ,
# endif
#endif
#if XFONT_BDFFORMAT
{ bdfReadFont, bdfReadFontInfo} ,
{ bdfReadFont, bdfReadFontInfo} ,
# ifdef X_GZIP_FONT_COMPRESSION
{ bdfReadFont, bdfReadFontInfo} ,
# endif
# ifdef X_BZIP2_FONT_COMPRESSION
{ bdfReadFont, bdfReadFontInfo} ,
# endif
#endif
};
#define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
static 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) {
free(pFont);
} else {
*ppFont = pFont;
}
return ret;
}
static 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;
}
static FontRendererRec renderers[] = {
#if XFONT_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
# ifdef X_BZIP2_FONT_COMPRESSION
{ ".pcf.bz2", 8,
BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
# endif
#endif
#if XFONT_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
# ifdef X_BZIP2_FONT_COMPRESSION
{ ".snf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
# endif
#endif
#if XFONT_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
# ifdef X_BZIP2_FONT_COMPRESSION
{ ".bdf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable,
BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
CAPABILITIES },
# endif
#endif
};
#define numRenderers (sizeof renderers / sizeof renderers[0])
void
BitmapRegisterFontFileFunctions (void)
{
int i;
for (i = 0; i < numRenderers; i++)
FontFileRegisterRenderer (&renderers[i]);
}
static int
BitmapGetRenderIndex(FontRendererPtr renderer)
{
return renderer - renderers;
}