bitmapfunc.c revision 7f7f5e4e
1/* $Xorg: bitmapfunc.c,v 1.5 2001/02/09 02:04:02 xorgcvs Exp $ */ 2 3/* 4 5Copyright 1991, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27*/ 28 29/* $XFree86: xc/lib/font/bitmap/bitmapfunc.c,v 3.17 2002/09/19 13:21:58 tsi Exp $ */ 30 31/* 32 * Author: Keith Packard, MIT X Consortium 33 */ 34 35#ifdef HAVE_CONFIG_H 36#include <config.h> 37#endif 38 39/* 40 * Translate monolithic #defines to modular definitions 41 */ 42 43#ifdef PCFFORMAT 44#define XFONT_PCFFORMAT 1 45#endif 46 47#ifdef SNFFORMAT 48#define XFONT_SNFFORMAT 1 49#endif 50 51#ifdef BDFFORMAT 52#define XFONT_BDFFORMAT 1 53#endif 54 55#include <X11/fonts/fntfilst.h> 56#include <X11/fonts/bitmap.h> 57#include <X11/fonts/fontutil.h> 58#include <X11/fonts/bdfint.h> 59#include <X11/fonts/pcf.h> 60#include "snfstr.h" 61 62typedef struct _BitmapFileFunctions { 63 int (*ReadFont) (FontPtr /* pFont */, FontFilePtr /* file */, 64 int /* bit */, int /* byte */, 65 int /* glyph */, int /* scan */); 66 int (*ReadInfo) ( FontInfoPtr /* pFontInfo */, 67 FontFilePtr /* file */ ); 68} BitmapFileFunctionsRec, *BitmapFileFunctionsPtr; 69 70static int BitmapGetRenderIndex(FontRendererPtr renderer); 71 72/* 73 * the readers[] and renderers[] arrays must be in the same order, 74 * and also in the same order as scale[] and find_scale[] in bitscale.c 75 * 76 */ 77static BitmapFileFunctionsRec readers[] = { 78#if XFONT_PCFFORMAT 79 { pcfReadFont, pcfReadFontInfo} , 80 { pcfReadFont, pcfReadFontInfo} , 81# ifdef X_GZIP_FONT_COMPRESSION 82 { pcfReadFont, pcfReadFontInfo} , 83# endif 84# ifdef X_BZIP2_FONT_COMPRESSION 85 { pcfReadFont, pcfReadFontInfo} , 86# endif 87#endif 88#if XFONT_SNFFORMAT 89 { snfReadFont, snfReadFontInfo}, 90 { snfReadFont, snfReadFontInfo}, 91# ifdef X_GZIP_FONT_COMPRESSION 92 { snfReadFont, snfReadFontInfo} , 93# endif 94# ifdef X_BZIP2_FONT_COMPRESSION 95 { snfReadFont, snfReadFontInfo} , 96# endif 97#endif 98#if XFONT_BDFFORMAT 99 { bdfReadFont, bdfReadFontInfo} , 100 { bdfReadFont, bdfReadFontInfo} , 101# ifdef X_GZIP_FONT_COMPRESSION 102 { bdfReadFont, bdfReadFontInfo} , 103# endif 104# ifdef X_BZIP2_FONT_COMPRESSION 105 { bdfReadFont, bdfReadFontInfo} , 106# endif 107#endif 108}; 109 110 111#define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING) 112 113static int 114BitmapOpenBitmap (FontPathElementPtr fpe, FontPtr *ppFont, int flags, 115 FontEntryPtr entry, char *fileName, 116 fsBitmapFormat format, fsBitmapFormatMask fmask, 117 FontPtr non_cachable_font) /* We don't do licensing */ 118{ 119 FontFilePtr file; 120 FontPtr pFont; 121 int i; 122 int ret; 123 int bit, 124 byte, 125 glyph, 126 scan, 127 image; 128 129 i = BitmapGetRenderIndex(entry->u.bitmap.renderer); 130 file = FontFileOpen (fileName); 131 if (!file) 132 return BadFontName; 133 if (!(pFont = CreateFontRec())) { 134 fprintf(stderr, "Error: Couldn't allocate pFont (%ld)\n", 135 (unsigned long)sizeof(FontRec)); 136 FontFileClose (file); 137 return AllocError; 138 } 139 /* set up default values */ 140 FontDefaultFormat(&bit, &byte, &glyph, &scan); 141 /* get any changes made from above */ 142 ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image); 143 144 /* Fill in font record. Data format filled in by reader. */ 145 pFont->refcnt = 0; 146 147 ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan); 148 149 FontFileClose (file); 150 if (ret != Successful) { 151 free(pFont); 152 } else { 153 *ppFont = pFont; 154 } 155 return ret; 156} 157 158static int 159BitmapGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo, 160 FontEntryPtr entry, char *fileName) 161{ 162 FontFilePtr file; 163 int i; 164 int ret; 165 FontRendererPtr renderer; 166 167 renderer = FontFileMatchRenderer (fileName); 168 if (!renderer) 169 return BadFontName; 170 i = BitmapGetRenderIndex(renderer); 171 file = FontFileOpen (fileName); 172 if (!file) 173 return BadFontName; 174 ret = (*readers[i].ReadInfo) (pFontInfo, file); 175 FontFileClose (file); 176 return ret; 177} 178 179static FontRendererRec renderers[] = { 180#if XFONT_PCFFORMAT 181 { ".pcf", 4, BitmapOpenBitmap, BitmapOpenScalable, 182 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 183 CAPABILITIES }, 184 { ".pcf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable, 185 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 186 CAPABILITIES }, 187# ifdef X_GZIP_FONT_COMPRESSION 188 { ".pcf.gz", 7, 189 BitmapOpenBitmap, BitmapOpenScalable, 190 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 191 CAPABILITIES }, 192# endif 193# ifdef X_BZIP2_FONT_COMPRESSION 194 { ".pcf.bz2", 8, 195 BitmapOpenBitmap, BitmapOpenScalable, 196 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 197 CAPABILITIES }, 198# endif 199#endif 200#if XFONT_SNFFORMAT 201 { ".snf", 4, BitmapOpenBitmap, BitmapOpenScalable, 202 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 203 CAPABILITIES }, 204 { ".snf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable, 205 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 206 CAPABILITIES }, 207# ifdef X_GZIP_FONT_COMPRESSION 208 { ".snf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable, 209 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 210 CAPABILITIES }, 211# endif 212# ifdef X_BZIP2_FONT_COMPRESSION 213 { ".snf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable, 214 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 215 CAPABILITIES }, 216# endif 217#endif 218#if XFONT_BDFFORMAT 219 { ".bdf", 4, BitmapOpenBitmap, BitmapOpenScalable, 220 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 221 CAPABILITIES }, 222 { ".bdf.Z", 6, BitmapOpenBitmap, BitmapOpenScalable, 223 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 224 CAPABILITIES }, 225# ifdef X_GZIP_FONT_COMPRESSION 226 { ".bdf.gz", 7, BitmapOpenBitmap, BitmapOpenScalable, 227 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 228 CAPABILITIES }, 229# endif 230# ifdef X_BZIP2_FONT_COMPRESSION 231 { ".bdf.bz2", 8, BitmapOpenBitmap, BitmapOpenScalable, 232 BitmapGetInfoBitmap, BitmapGetInfoScalable, 0, 233 CAPABILITIES }, 234# endif 235#endif 236}; 237 238#define numRenderers (sizeof renderers / sizeof renderers[0]) 239 240void 241BitmapRegisterFontFileFunctions (void) 242{ 243 int i; 244 245 for (i = 0; i < numRenderers; i++) 246 FontFileRegisterRenderer (&renderers[i]); 247} 248 249/* 250 * compute offset into renderers array - used to find the font reader, 251 * the font info reader, and the bitmap scaling routine. All users 252 * of this routine must be kept in step with the renderer array. 253 */ 254static int 255BitmapGetRenderIndex(FontRendererPtr renderer) 256{ 257 return renderer - renderers; 258} 259