⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bdfread.c

📁 unix vnc 协议源码. VNC是一款远程控制工具软件.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: bdfread.c,v 1.22 94/04/17 20:17:10 gildea Exp $ *//************************************************************************Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.                        All Rights ReservedPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the name of Digital not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.************************************************************************//*Copyright (c) 1994  X ConsortiumPermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shallnot be used in advertising or otherwise to promote the sale, use orother dealings in this Software without prior written authorizationfrom the X Consortium.*/#include <ctype.h>#include "fntfilst.h"/* use bitmap structure */#include "bitmap.h"#include "bdfint.h"#define INDICES 256#define MAXENCODING 0xFFFF#define BDFLINELEN  1024extern int  bitmapGetGlyphs(), bitmapGetMetrics();extern int  bitmapGetBitmaps(), bitmapGetExtents();void        bdfUnloadFont();static Bool bdfPadToTerminal();extern int  bdfFileLineNum;/***====================================================================***/static BoolbdfReadBitmap(pCI, file, bit, byte, glyph, scan, sizes)    CharInfoPtr pCI;    FontFilePtr file;    int         bit,                byte,                glyph,                scan;    CARD32      sizes[GLYPHPADOPTIONS];{    int         widthBits,                widthBytes,                widthHexChars;    int         height,                row;    int         i,                inLineLen,                nextByte;    Bool        badbits;    unsigned char *pInBits,               *picture,               *line = NULL;    char        lineBuf[BDFLINELEN];    widthBits = GLYPHWIDTHPIXELS(pCI);    height = GLYPHHEIGHTPIXELS(pCI);    widthBytes = BYTES_PER_ROW(widthBits, glyph);    if (widthBytes * height > 0) {	picture = (unsigned char *) xalloc(widthBytes * height);	if (!picture)	    goto BAILOUT;    } else	picture = NULL;    pCI->bits = (char *) picture;    if (sizes) {	for (i = 0; i < GLYPHPADOPTIONS; i++)	    sizes[i] += BYTES_PER_ROW(widthBits, (1 << i)) * height;    }    badbits = FALSE;    nextByte = 0;    widthHexChars = BYTES_PER_ROW(widthBits, 1);/* 5/31/89 (ef) -- hack, hack, hack.  what *am* I supposed to do with *//*		0 width characters? */    for (row = 0; row < height; row++) {	line = bdfGetLine(file, lineBuf, BDFLINELEN);	if (!line)	    break;	if (widthBits == 0) {	    if ((!line) || (bdfIsPrefix(line, "ENDCHAR")))		break;	    else		continue;	}	pInBits = line;	inLineLen = strlen((char *) pInBits);	if (inLineLen & 1) {	    bdfError("odd number of characters in hex encoding\n");	    line[inLineLen++] = '0';	    line[inLineLen] = '\0';	}	inLineLen >>= 1;	i = inLineLen;	if (i > widthHexChars)	    i = widthHexChars;	for (; i > 0; i--, pInBits += 2)	    picture[nextByte++] = bdfHexByte(pInBits);	/* pad if line is too short */	if (inLineLen < widthHexChars) {	    for (i = widthHexChars - inLineLen; i > 0; i--)		picture[nextByte++] = 0;	} else {	    unsigned char mask;	    mask = 0xff << (8 - (widthBits & 0x7));	    if (mask && picture[nextByte - 1] & ~mask) {		picture[nextByte - 1] &= mask;		badbits = TRUE;	    } else if (inLineLen > widthHexChars)		badbits = TRUE;	}	if (widthBytes > widthHexChars) {	    i = widthBytes - widthHexChars;	    while (i-- > 0)		picture[nextByte++] = 0;	}    }    if ((line && (!bdfIsPrefix(line, "ENDCHAR"))) || (height == 0))	line = bdfGetLine(file, lineBuf, BDFLINELEN);    if ((!line) || (!bdfIsPrefix(line, "ENDCHAR"))) {	bdfError("missing 'ENDCHAR'\n");	goto BAILOUT;    }    if (nextByte != height * widthBytes) {	bdfError("bytes != rows * bytes_per_row (%d != %d * %d)\n",		 nextByte, height, widthBytes);	goto BAILOUT;    }    if (picture != NULL) {	if (bit == LSBFirst)	    BitOrderInvert(picture, nextByte);	if (bit != byte) {	    if (scan == 2)		TwoByteSwap(picture, nextByte);	    else if (scan == 4)		FourByteSwap(picture, nextByte);	}    }    return (TRUE);BAILOUT:    if (picture)	xfree(picture);    pCI->bits = NULL;    return (FALSE);}/***====================================================================***/static BoolbdfSkipBitmap(file, height)    FontFilePtr file;    int         height;{    unsigned char *line;    int         i = 0;    char        lineBuf[BDFLINELEN];    do {	line = bdfGetLine(file, lineBuf, BDFLINELEN);	i++;    } while (line && !bdfIsPrefix(line, "ENDCHAR") && i <= height);    if (i > 1 && line && !bdfIsPrefix(line, "ENDCHAR")) {	bdfError("Error in bitmap, missing 'ENDCHAR'\n");	return (FALSE);    }    return (TRUE);}/***====================================================================***/static BoolbdfReadCharacters(file, pFont, pState, bit, byte, glyph, scan)    FontFilePtr file;    FontPtr     pFont;    bdfFileState *pState;    int         bit,                byte,                glyph,                scan;{    unsigned char *line;    register CharInfoPtr ci;    int         i,                ndx,                nchars,                nignored;    unsigned int char_row, char_col;    int         numEncodedGlyphs = 0;    CharInfoPtr *bdfEncoding[256];    BitmapFontPtr  bitmapFont;    BitmapExtraPtr bitmapExtra;    CARD32     *bitmapsSizes;    char        lineBuf[BDFLINELEN];    int         nencoding;    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;    bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra;    if (bitmapExtra) {	bitmapsSizes = bitmapExtra->bitmapsSizes;	for (i = 0; i < GLYPHPADOPTIONS; i++)	    bitmapsSizes[i] = 0;    } else	bitmapsSizes = NULL;    bzero(bdfEncoding, sizeof(bdfEncoding));    bitmapFont->metrics = NULL;    ndx = 0;    line = bdfGetLine(file, lineBuf, BDFLINELEN);    if ((!line) || (sscanf((char *) line, "CHARS %d", &nchars) != 1)) {	bdfError("bad 'CHARS' in bdf file\n");	return (FALSE);    }    if (nchars < 1) {	bdfError("invalid number of CHARS in BDF file\n");	return (FALSE);    }    ci = (CharInfoPtr) xalloc(nchars * sizeof(CharInfoRec));    if (!ci) {	bdfError("Couldn't allocate pCI (%d*%d)\n", nchars,		 sizeof(CharInfoRec));	goto BAILOUT;    }    bitmapFont->metrics = ci;    if (bitmapExtra) {	bitmapExtra->glyphNames = (Atom *) xalloc(nchars * sizeof(Atom));	if (!bitmapExtra->glyphNames) {	    bdfError("Couldn't allocate glyphNames (%d*%d)\n",		     nchars, sizeof(Atom));	    goto BAILOUT;	}    }    if (bitmapExtra) {	bitmapExtra->sWidths = (int *) xalloc(nchars * sizeof(int));	if (!bitmapExtra->sWidths) {	    bdfError("Couldn't allocate sWidth (%d *%d)\n",		     nchars, sizeof(int));	    return FALSE;	}    }    line = bdfGetLine(file, lineBuf, BDFLINELEN);    pFont->info.firstRow = 256;    pFont->info.lastRow = 0;    pFont->info.firstCol = 256;    pFont->info.lastCol = 0;    nignored = 0;    for (ndx = 0; (ndx < nchars) && (line) && (bdfIsPrefix(line, "STARTCHAR"));) {	int         t;	int         wx;		/* x component of width */	int         wy;		/* y component of width */	int         bw;		/* bounding-box width */	int         bh;		/* bounding-box height */	int         bl;		/* bounding-box left */	int         bb;		/* bounding-box bottom */	int         enc,	            enc2;	/* encoding */	unsigned char *p;	/* temp pointer into line */	char        charName[100];	int         ignore;	if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) {	    bdfError("bad character name in BDF file\n");	    goto BAILOUT;	/* bottom of function, free and return error */	}	if (bitmapExtra)	    bitmapExtra->glyphNames[ndx] = bdfForceMakeAtom(charName, NULL);	line = bdfGetLine(file, lineBuf, BDFLINELEN);	if (!line || (t = sscanf((char *) line, "ENCODING %d %d", &enc, &enc2)) < 1) {	    bdfError("bad 'ENCODING' in BDF file\n");	    goto BAILOUT;	}	if (enc < -1 || t == 2 && enc2 < -1) {	    bdfError("bad ENCODING value");	    goto BAILOUT;	}	if (t == 2 && enc == -1)	    enc = enc2;	ignore = 0;	if (enc == -1) {	    if (!bitmapExtra) {		nignored++;		ignore = 1;	    }	} else if (enc > MAXENCODING) {	    bdfError("char '%s' has encoding too large (%d)\n",		     charName, enc);	} else {	    char_row = (enc >> 8) & 0xFF;	    char_col = enc & 0xFF;	    if (char_row < pFont->info.firstRow)		pFont->info.firstRow = char_row;	    if (char_row > pFont->info.lastRow)		pFont->info.lastRow = char_row;	    if (char_col < pFont->info.firstCol)		pFont->info.firstCol = char_col;	    if (char_col > pFont->info.lastCol)		pFont->info.lastCol = char_col;	    if (bdfEncoding[char_row] == (CharInfoPtr *) NULL) {		bdfEncoding[char_row] =		    (CharInfoPtr *) xalloc(256 * sizeof(CharInfoPtr));		if (!bdfEncoding[char_row]) {		    bdfError("Couldn't allocate row %d of encoding (%d*%d)\n",			     char_row, INDICES, sizeof(CharInfoPtr));		    goto BAILOUT;		}		for (i = 0; i < 256; i++)		    bdfEncoding[char_row][i] = (CharInfoPtr) NULL;	    }	    if (bdfEncoding[char_row] != NULL) {		bdfEncoding[char_row][char_col] = ci;		numEncodedGlyphs++;	    }	}	line = bdfGetLine(file, lineBuf, BDFLINELEN);	if ((!line) || (sscanf((char *) line, "SWIDTH %d %d", &wx, &wy) != 2)) {	    bdfError("bad 'SWIDTH'\n");	    goto BAILOUT;	}	if (wy != 0) {	    bdfError("SWIDTH y value must be zero\n");	    goto BAILOUT;	}	if (bitmapExtra)	    bitmapExtra->sWidths[ndx] = wx;/* 5/31/89 (ef) -- we should be able to ditch the character and recover *//*		from all of these.					*/	line = bdfGetLine(file, lineBuf, BDFLINELEN);	if ((!line) || (sscanf((char *) line, "DWIDTH %d %d", &wx, &wy) != 2)) {	    bdfError("bad 'DWIDTH'\n");	    goto BAILOUT;	}	if (wy != 0) {	    bdfError("DWIDTH y value must be zero\n");	    goto BAILOUT;	}	line = bdfGetLine(file, lineBuf, BDFLINELEN);	if ((!line) || (sscanf((char *) line, "BBX %d %d %d %d", &bw, &bh, &bl, &bb) != 4)) {	    bdfError("bad 'BBX'\n");	    goto BAILOUT;	}	if ((bh < 0) || (bw < 0)) {	    bdfError("character '%s' has a negative sized bitmap, %dx%d\n",		     charName, bw, bh);	    goto BAILOUT;	}	line = bdfGetLine(file, lineBuf, BDFLINELEN);	if ((line) && (bdfIsPrefix(line, "ATTRIBUTES"))) {	    for (p = line + strlen("ATTRIBUTES ");		    (*p == ' ') || (*p == '\t');		    p++)		 /* empty for loop */ ;	    ci->metrics.attributes = bdfHexByte(p) << 8 + bdfHexByte(p + 2);	    line = bdfGetLine(file, lineBuf, BDFLINELEN);	} else	    ci->metrics.attributes = 0;	if (!line || !bdfIsPrefix(line, "BITMAP")) {	    bdfError("missing 'BITMAP'\n");	    goto BAILOUT;	}	/* collect data for generated properties */	if ((strlen(charName) == 1)) {	    if ((charName[0] >= '0') && (charName[0] <= '9')) {		pState->digitWidths += wx;		pState->digitCount++;	    } else if (charName[0] == 'x') {		pState->exHeight = (bh + bb) <= 0 ? bh : bh + bb;	    }	}	if (!ignore) {	    ci->metrics.leftSideBearing = bl;	    ci->metrics.rightSideBearing = bl + bw;	    ci->metrics.ascent = bh + bb;	    ci->metrics.descent = -bb;	    ci->metrics.characterWidth = wx;	    ci->bits = NULL;	    bdfReadBitmap(ci, file, bit, byte, glyph, scan, bitmapsSizes);	    ci++;	    ndx++;	} else	    bdfSkipBitmap(file, bh);	line = bdfGetLine(file, lineBuf, BDFLINELEN);	/* get STARTCHAR or							 * ENDFONT */    }    if (ndx + nignored != nchars) {	bdfError("%d too few characters\n", nchars - (ndx + nignored));	goto BAILOUT;    }    nchars = ndx;    bitmapFont->num_chars = nchars;    if ((line) && (bdfIsPrefix(line, "STARTCHAR"))) {	bdfError("more characters than specified\n");	goto BAILOUT;    }    if ((!line) || (!bdfIsPrefix(line, "ENDFONT"))) {	bdfError("missing 'ENDFONT'\n");	goto BAILOUT;    }    if (numEncodedGlyphs == 0)	bdfWarning("No characters with valid encodings\n");    nencoding = (pFont->info.lastRow - pFont->info.firstRow + 1) *	(pFont->info.lastCol - pFont->info.firstCol + 1);    bitmapFont->encoding = (CharInfoPtr *) xalloc(nencoding * sizeof(CharInfoPtr));    if (!bitmapFont->encoding) {	bdfError("Couldn't allocate ppCI (%d,%d)\n",		 nencoding,		 sizeof(CharInfoPtr));	goto BAILOUT;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -