diff options
Diffstat (limited to 'src/bitmap/snfread.c')
-rw-r--r-- | src/bitmap/snfread.c | 115 |
1 files changed, 55 insertions, 60 deletions
diff --git a/src/bitmap/snfread.c b/src/bitmap/snfread.c index 04982bc..375fa5a 100644 --- a/src/bitmap/snfread.c +++ b/src/bitmap/snfread.c @@ -49,8 +49,12 @@ other dealings in this Software without prior written authorization from The Open Group. */ +/* $XFree86: xc/lib/font/bitmap/snfread.c,v 1.11 2003/01/12 03:55:46 tsi Exp $ */ +#ifndef FONTMODULE #include <ctype.h> +#endif + #include "fntfilst.h" #include "bitmap.h" #include "snfstr.h" @@ -73,23 +77,20 @@ snfError (message, va_alist) va_list args; #if NeedVarargsPrototypes - va_start (args, message); + va_start(args, message); #else - va_start (args); + va_start(args); #endif fprintf(stderr, "SNF Error: "); vfprintf(stderr, message, args); - va_end (args); + va_end(args); } - -static void snfUnloadFont(); + +static void snfUnloadFont(FontPtr pFont); static int -snfReadCharInfo(file, charInfo, base) - FontFilePtr file; - CharInfoPtr charInfo; - char *base; +snfReadCharInfo(FontFilePtr file, CharInfoPtr charInfo, char *base) { snfCharInfoRec snfCharInfo; @@ -109,9 +110,7 @@ snfReadCharInfo(file, charInfo, base) } static int -snfReadxCharInfo(file, charInfo) - FontFilePtr file; - xCharInfo *charInfo; +snfReadxCharInfo(FontFilePtr file, xCharInfo *charInfo) { snfCharInfoRec snfCharInfo; @@ -124,9 +123,7 @@ snfReadxCharInfo(file, charInfo) } static void -snfCopyInfo(snfInfo, pFontInfo) - snfFontInfoPtr snfInfo; - FontInfoPtr pFontInfo; +snfCopyInfo(snfFontInfoPtr snfInfo, FontInfoPtr pFontInfo) { pFontInfo->firstCol = snfInfo->firstCol; pFontInfo->lastCol = snfInfo->lastCol; @@ -152,10 +149,7 @@ snfCopyInfo(snfInfo, pFontInfo) } static int -snfReadProps(snfInfo, pFontInfo, file) - snfFontInfoPtr snfInfo; - FontInfoPtr pFontInfo; - FontFilePtr file; +snfReadProps(snfFontInfoPtr snfInfo, FontInfoPtr pFontInfo, FontFilePtr file) { char *strings; FontPropPtr pfp; @@ -168,7 +162,7 @@ snfReadProps(snfInfo, pFontInfo, file) BYTESOFSTRINGINFO(snfInfo); propspace = (char *) xalloc(bytestoalloc); if (!propspace) { - snfError("snfReadProps(): Couldn't allocate propspace (%d)\n", bytestoalloc); + snfError("snfReadProps(): Couldn't allocate propspace (%d)\n", bytestoalloc); return AllocError; } @@ -195,10 +189,8 @@ snfReadProps(snfInfo, pFontInfo, file) return Successful; } -int -snfReadHeader(snfInfo, file) - snfFontInfoPtr snfInfo; - FontFilePtr file; +static int +snfReadHeader(snfFontInfoPtr snfInfo, FontFilePtr file) { if (FontFileRead(file, (char *) snfInfo, sizeof *snfInfo) != sizeof *snfInfo) return BadFontName; @@ -213,8 +205,7 @@ static int snf_set; static int snf_bit, snf_byte, snf_glyph, snf_scan; void -SnfSetFormat (bit, byte, glyph, scan) - int bit, byte, glyph, scan; +SnfSetFormat (int bit, int byte, int glyph, int scan) { snf_bit = bit; snf_byte = byte; @@ -223,9 +214,8 @@ SnfSetFormat (bit, byte, glyph, scan) snf_set = 1; } -void -SnfGetFormat (bit, byte, glyph, scan) - int *bit, *byte, *glyph, *scan; +static void +SnfGetFormat (int *bit, int *byte, int *glyph, int *scan) { if (!snf_set) FontDefaultFormat (&snf_bit, &snf_byte, &snf_glyph, &snf_scan); @@ -236,17 +226,12 @@ SnfGetFormat (bit, byte, glyph, scan) } int -snfReadFont(pFont, file, bit, byte, glyph, scan) - FontPtr pFont; - FontFilePtr file; - int bit, - byte, - glyph, - scan; +snfReadFont(FontPtr pFont, FontFilePtr file, + int bit, int byte, int glyph, int scan) { snfFontInfoRec fi; unsigned bytestoalloc; - int i; + int i, j; char *fontspace; BitmapFontPtr bitmapFont; int num_chars; @@ -283,7 +268,8 @@ snfReadFont(pFont, file, bit, byte, glyph, scan) metrics_off = bytestoalloc; bytestoalloc += num_chars * sizeof(CharInfoRec); /* metrics */ encoding_off = bytestoalloc; - bytestoalloc += num_chars * sizeof(CharInfoPtr); /* encoding */ + bytestoalloc += NUM_SEGMENTS(num_chars) * sizeof(CharInfoPtr**); + /* encoding */ props_off = bytestoalloc; bytestoalloc += fi.nProps * sizeof(FontPropRec); /* props */ isStringProp_off = bytestoalloc; @@ -295,14 +281,13 @@ snfReadFont(pFont, file, bit, byte, glyph, scan) fontspace = (char *) xalloc(bytestoalloc); if (!fontspace) { - snfError("snfReadFont(): Couldn't allocate fontspace (%d)\n", bytestoalloc); + snfError("snfReadFont(): Couldn't allocate fontspace (%d)\n", bytestoalloc); return AllocError; } - bitmaps = (char *) xalloc (bitmapsSize); if (!bitmaps) { - snfError("snfReadFont(): Couldn't allocate bitmaps (%d)\n", bitmapsSize); + snfError("snfReadFont(): Couldn't allocate bitmaps (%d)\n", bitmapsSize); xfree (fontspace); return AllocError; } @@ -313,7 +298,7 @@ snfReadFont(pFont, file, bit, byte, glyph, scan) bitmapFont = (BitmapFontPtr) fontspace; bitmapFont->num_chars = num_chars; bitmapFont->metrics = (CharInfoPtr) (fontspace + metrics_off); - bitmapFont->encoding = (CharInfoPtr *) (fontspace + encoding_off); + bitmapFont->encoding = (CharInfoPtr **) (fontspace + encoding_off); bitmapFont->bitmaps = bitmaps; bitmapFont->pDefault = NULL; bitmapFont->bitmapExtra = NULL; @@ -329,16 +314,30 @@ snfReadFont(pFont, file, bit, byte, glyph, scan) */ ret = Successful; + memset(bitmapFont->encoding, 0, + NUM_SEGMENTS(num_chars)*sizeof(CharInfoPtr*)); for (i = 0; ret == Successful && i < num_chars; i++) { ret = snfReadCharInfo(file, &bitmapFont->metrics[i], bitmaps); - if (bitmapFont->metrics[i].bits) - bitmapFont->encoding[i] = &bitmapFont->metrics[i]; - else - bitmapFont->encoding[i] = 0; + if (bitmapFont->metrics[i].bits) { + if (!bitmapFont->encoding[SEGMENT_MAJOR(i)]) { + bitmapFont->encoding[SEGMENT_MAJOR(i)]= + (CharInfoPtr*)xcalloc(BITMAP_FONT_SEGMENT_SIZE, + sizeof(CharInfoPtr)); + if (!bitmapFont->encoding[SEGMENT_MAJOR(i)]) { + ret = AllocError; + break; + } + } + ACCESSENCODINGL(bitmapFont->encoding,i) = &bitmapFont->metrics[i]; + } } if (ret != Successful) { xfree(bitmaps); + if(bitmapFont->encoding) { + for(j=0; j<SEGMENT_MAJOR(i); j++) + xfree(bitmapFont->encoding[i]); + } xfree(fontspace); return ret; } @@ -346,23 +345,23 @@ snfReadFont(pFont, file, bit, byte, glyph, scan) * read the glyphs */ - if (FontFileRead(file, (char *) bitmaps, bitmapsSize) != bitmapsSize) { + if (FontFileRead(file, bitmaps, bitmapsSize) != bitmapsSize) { xfree(bitmaps); xfree(fontspace); return BadFontName; } if (def_bit != bit) - BitOrderInvert(bitmaps, bitmapsSize); + BitOrderInvert((unsigned char *)bitmaps, bitmapsSize); if ((def_byte == def_bit) != (bit == byte)) { switch (bit == byte ? def_scan : scan) { case 1: break; case 2: - TwoByteSwap(bitmaps, bitmapsSize); + TwoByteSwap((unsigned char *)bitmaps, bitmapsSize); break; case 4: - FourByteSwap(bitmaps, bitmapsSize); + FourByteSwap((unsigned char *)bitmaps, bitmapsSize); break; } } @@ -457,9 +456,7 @@ snfReadFont(pFont, file, bit, byte, glyph, scan) } int -snfReadFontInfo(pFontInfo, file) - FontInfoPtr pFontInfo; - FontFilePtr file; +snfReadFontInfo(FontInfoPtr pFontInfo, FontFilePtr file) { int ret; snfFontInfoRec fi; @@ -473,19 +470,19 @@ snfReadFontInfo(pFontInfo, file) pFontInfo->props = (FontPropPtr) xalloc(fi.nProps * sizeof(FontPropRec)); if (!pFontInfo->props) { - snfError("snfReadFontInfo(): Couldn't allocate props (%d*%d)\n", fi.nProps, sizeof(FontPropRec)); + snfError("snfReadFontInfo(): Couldn't allocate props (%d*%d)\n", fi.nProps, sizeof(FontPropRec)); return AllocError; } pFontInfo->isStringProp = (char *) xalloc(fi.nProps * sizeof(char)); if (!pFontInfo->isStringProp) { - snfError("snfReadFontInfo(): Couldn't allocate isStringProp (%d*%d)\n", fi.nProps, sizeof(char)); + snfError("snfReadFontInfo(): Couldn't allocate isStringProp (%d*%d)\n", fi.nProps, sizeof(char)); xfree(pFontInfo->props); return AllocError; } num_chars = n2dChars(&fi); bytestoskip = num_chars * sizeof(snfCharInfoRec); /* charinfos */ bytestoskip += BYTESOFGLYPHINFO(&fi); - FontFileSkip(file, bytestoskip); + (void)FontFileSkip(file, bytestoskip); ret = snfReadProps(&fi, pFontInfo, file); if (ret != Successful) { @@ -515,15 +512,13 @@ snfReadFontInfo(pFontInfo, file) } static void -snfUnloadFont(pFont) - FontPtr pFont; +snfUnloadFont(FontPtr pFont) { BitmapFontPtr bitmapFont; bitmapFont = (BitmapFontPtr) pFont->fontPrivate; xfree (bitmapFont->bitmaps); xfree (bitmapFont); - xfree (pFont->devPrivates); - xfree (pFont); + DestroyFontRec (pFont); } |