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