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

📄 bdfread.c

📁 unix vnc 协议源码. VNC是一款远程控制工具软件.
💻 C
📖 第 1 页 / 共 2 页
字号:
    }    pFont->info.allExist = TRUE;    i = 0;    for (char_row = pFont->info.firstRow;	    char_row <= pFont->info.lastRow;	    char_row++) {	if (bdfEncoding[char_row] == (CharInfoPtr *) NULL) {	    pFont->info.allExist = FALSE;	    for (char_col = pFont->info.firstCol;		    char_col <= pFont->info.lastCol;		    char_col++) {		bitmapFont->encoding[i++] = NullCharInfo;	    }	} else {	    for (char_col = pFont->info.firstCol;		    char_col <= pFont->info.lastCol;		    char_col++) {		if (!bdfEncoding[char_row][char_col])		    pFont->info.allExist = FALSE;		bitmapFont->encoding[i++] = bdfEncoding[char_row][char_col];	    }	}    }    for (i = 0; i < 256; i++)	if (bdfEncoding[i])	    xfree(bdfEncoding[i]);    return (TRUE);BAILOUT:    for (i = 0; i < 256; i++)	if (bdfEncoding[i])	    xfree(bdfEncoding[i]);    /* bdfFreeFontBits will clean up the rest */    return (FALSE);}/***====================================================================***/static BoolbdfReadHeader(file, pState)    FontFilePtr file;    bdfFileState *pState;{    unsigned char *line;    char        namebuf[BDFLINELEN];    char        lineBuf[BDFLINELEN];    line = bdfGetLine(file, lineBuf, BDFLINELEN);    if (!line || sscanf((char *) line, "STARTFONT %s", namebuf) != 1 ||	    !bdfStrEqual(namebuf, "2.1")) {	bdfError("bad 'STARTFONT'\n");	return (FALSE);    }    line = bdfGetLine(file, lineBuf, BDFLINELEN);    if (!line || sscanf((char *) line, "FONT %[^\n]", pState->fontName) != 1) {	bdfError("bad 'FONT'\n");	return (FALSE);    }    line = bdfGetLine(file, lineBuf, BDFLINELEN);    if (!line || !bdfIsPrefix(line, "SIZE")) {	bdfError("missing 'SIZE'\n");	return (FALSE);    }    if (sscanf((char *) line, "SIZE %f%d%d", &pState->pointSize,	       &pState->resolution_x, &pState->resolution_y) != 3) {	bdfError("bad 'SIZE'\n");	return (FALSE);    }    if (pState->pointSize < 1 ||	pState->resolution_x < 1 || pState->resolution_y < 1) {	bdfError("SIZE values must be > 0\n");	return (FALSE);    }    line = bdfGetLine(file, lineBuf, BDFLINELEN);    if (!line || !bdfIsPrefix(line, "FONTBOUNDINGBOX")) {	bdfError("missing 'FONTBOUNDINGBOX'\n");	return (FALSE);    }    return (TRUE);}/***====================================================================***/static BoolbdfReadProperties(file, pFont, pState)    FontFilePtr file;    FontPtr     pFont;    bdfFileState *pState;{    int         nProps, props_left,                nextProp;    char       *stringProps;    FontPropPtr props;    char        namebuf[BDFLINELEN],                secondbuf[BDFLINELEN],                thirdbuf[BDFLINELEN];    unsigned char *line;    char        lineBuf[BDFLINELEN];    BitmapFontPtr  bitmapFont = (BitmapFontPtr) pFont->fontPrivate;    line = bdfGetLine(file, lineBuf, BDFLINELEN);    if (!line || !bdfIsPrefix(line, "STARTPROPERTIES")) {	bdfError(file, "missing 'STARTPROPERTIES'\n");	return (FALSE);    }    if (sscanf((char *) line, "STARTPROPERTIES %d", &nProps) != 1) {	bdfError("bad 'STARTPROPERTIES'\n");	return (FALSE);    }    pFont->info.isStringProp = NULL;    pFont->info.props = NULL;    stringProps = (char *) xalloc((nProps + BDF_GENPROPS) * sizeof(char));    pFont->info.isStringProp = stringProps;    if (stringProps == NULL) {	bdfError("Couldn't allocate stringProps (%d*%d)\n",		 (nProps + BDF_GENPROPS), sizeof(Bool));	goto BAILOUT;    }    pFont->info.props = props = (FontPropPtr) xalloc((nProps + BDF_GENPROPS) *						     sizeof(FontPropRec));    if (props == NULL) {	bdfError("Couldn't allocate props (%d*%d)\n", nProps + BDF_GENPROPS,						      sizeof(FontPropRec));	goto BAILOUT;    }    nextProp = 0;    props_left = nProps;    while (props_left-- > 0) {	line = bdfGetLine(file, lineBuf, BDFLINELEN);	if (line == NULL || bdfIsPrefix(line, "ENDPROPERTIES")) {	    bdfError("\"STARTPROPERTIES %d\" followed by only %d properties\n",		     nProps, nProps - props_left - 1);	    goto BAILOUT;	}	while (*line && isspace(*line))	    line++;	switch (sscanf((char *) line, "%s%s%s", namebuf, secondbuf, thirdbuf)) {	default:	    bdfError("missing '%s' parameter value\n", namebuf);	    goto BAILOUT;	case 2:	    /*	     * Possibilites include: valid quoted string with no white space	     * valid integer value invalid value	     */	    if (secondbuf[0] == '"') {		stringProps[nextProp] = TRUE;		props[nextProp].value =		    bdfGetPropertyValue(line + strlen(namebuf) + 1);		if (!props[nextProp].value)		    goto BAILOUT;		break;	    } else if (bdfIsInteger(secondbuf)) {		stringProps[nextProp] = FALSE;		props[nextProp].value = atoi(secondbuf);		break;	    } else {		bdfError("invalid '%s' parameter value\n", namebuf);		goto BAILOUT;	    }	case 3:	    /*	     * Possibilites include: valid quoted string with some white space	     * invalid value (reject even if second string is integer)	     */	    if (secondbuf[0] == '"') {		stringProps[nextProp] = TRUE;		props[nextProp].value =		    bdfGetPropertyValue(line + strlen(namebuf) + 1);		if (!props[nextProp].value)		    goto BAILOUT;		break;	    } else {		bdfError("invalid '%s' parameter value\n", namebuf);		goto BAILOUT;	    }	}	props[nextProp].name = bdfForceMakeAtom(namebuf, NULL);	if (props[nextProp].name == None) {	    bdfError("Empty property name.\n");	    goto BAILOUT;	}	if (!bdfSpecialProperty(pFont, &props[nextProp],				stringProps[nextProp], pState))	    nextProp++;    }    line = bdfGetLine(file, lineBuf, BDFLINELEN);    if (!line || !bdfIsPrefix(line, "ENDPROPERTIES")) {	bdfError("missing 'ENDPROPERTIES'\n");	goto BAILOUT;    }    if (!pState->haveFontAscent || !pState->haveFontDescent) {	bdfError("missing 'FONT_ASCENT' or 'FONT_DESCENT' properties\n");	goto BAILOUT;    }    if (bitmapFont->bitmapExtra) {	bitmapFont->bitmapExtra->info.fontAscent = pFont->info.fontAscent;	bitmapFont->bitmapExtra->info.fontDescent = pFont->info.fontDescent;    }    if (!pState->pointSizeProp) {	props[nextProp].name = bdfForceMakeAtom("POINT_SIZE", NULL);	props[nextProp].value = (INT32) (pState->pointSize * 10.0);	stringProps[nextProp] = FALSE;	pState->pointSizeProp = &props[nextProp];	nextProp++;    }    if (!pState->fontProp) {	props[nextProp].name = bdfForceMakeAtom("FONT", NULL);	props[nextProp].value = (INT32) bdfForceMakeAtom(pState->fontName, NULL);	stringProps[nextProp] = TRUE;	pState->fontProp = &props[nextProp];	nextProp++;    }    if (!pState->weightProp) {	props[nextProp].name = bdfForceMakeAtom("WEIGHT", NULL);	props[nextProp].value = -1;	/* computed later */	stringProps[nextProp] = FALSE;	pState->weightProp = &props[nextProp];	nextProp++;    }    if (!pState->resolutionProp &&	pState->resolution_x == pState->resolution_y) {	props[nextProp].name = bdfForceMakeAtom("RESOLUTION", NULL);	props[nextProp].value = (INT32) ((pState->resolution_x * 100.0) / 72.27);	stringProps[nextProp] = FALSE;	pState->resolutionProp = &props[nextProp];	nextProp++;    }    if (!pState->resolutionXProp) {	props[nextProp].name = bdfForceMakeAtom("RESOLUTION_X", NULL);	props[nextProp].value = (INT32) pState->resolution_x;	stringProps[nextProp] = FALSE;	pState->resolutionProp = &props[nextProp];	nextProp++;    }    if (!pState->resolutionYProp) {	props[nextProp].name = bdfForceMakeAtom("RESOLUTION_Y", NULL);	props[nextProp].value = (INT32) pState->resolution_y;	stringProps[nextProp] = FALSE;	pState->resolutionProp = &props[nextProp];	nextProp++;    }    if (!pState->xHeightProp) {	props[nextProp].name = bdfForceMakeAtom("X_HEIGHT", NULL);	props[nextProp].value = -1;	/* computed later */	stringProps[nextProp] = FALSE;	pState->xHeightProp = &props[nextProp];	nextProp++;    }    if (!pState->quadWidthProp) {	props[nextProp].name = bdfForceMakeAtom("QUAD_WIDTH", NULL);	props[nextProp].value = -1;	/* computed later */	stringProps[nextProp] = FALSE;	pState->quadWidthProp = &props[nextProp];	nextProp++;    }    pFont->info.nprops = nextProp;    return (TRUE);BAILOUT:    if (pFont->info.isStringProp) {	xfree(pFont->info.isStringProp);	pFont->info.isStringProp = NULL;    }    if (pFont->info.props) {	xfree(pFont->info.props);	pFont->info.props = NULL;    }    while (line && bdfIsPrefix(line, "ENDPROPERTIES"))	line = bdfGetLine(file, lineBuf, BDFLINELEN);    return (FALSE);}/***====================================================================***/intbdfReadFont(pFont, file, bit, byte, glyph, scan)    FontPtr     pFont;    FontFilePtr file;    int         bit,                byte,                glyph,                scan;{    bdfFileState state;    xCharInfo  *min,               *max;    BitmapFontPtr  bitmapFont;    pFont->fontPrivate = 0;    bzero(&state, sizeof(bdfFileState));    bdfFileLineNum = 0;    if (!bdfReadHeader(file, &state))	goto BAILOUT;    bitmapFont = (BitmapFontPtr) xalloc(sizeof(BitmapFontRec));    if (!bitmapFont)	goto BAILOUT;    pFont->fontPrivate = (pointer) bitmapFont;    bitmapFont->metrics = 0;    bitmapFont->ink_metrics = 0;    bitmapFont->bitmaps = 0;    bitmapFont->encoding = 0;    bitmapFont->pDefault = NULL;    bitmapFont->bitmapExtra = (BitmapExtraPtr) xalloc(sizeof(BitmapExtraRec));    bitmapFont->bitmapExtra->glyphNames = 0;    bitmapFont->bitmapExtra->sWidths = 0;    if (!bdfReadProperties(file, pFont, &state))	goto BAILOUT;    if (!bdfReadCharacters(file, pFont, &state, bit, byte, glyph, scan))	goto BAILOUT;    if (state.haveDefaultCh) {	unsigned int r, c, cols;	r = pFont->info.defaultCh >> 8;	c = pFont->info.defaultCh & 0xFF;	if (pFont->info.firstRow <= r && r <= pFont->info.lastRow &&		pFont->info.firstCol <= c && c <= pFont->info.lastCol) {	    cols = pFont->info.lastCol - pFont->info.firstCol + 1;	    r = r - pFont->info.firstRow;	    c = c - pFont->info.firstCol;	    bitmapFont->pDefault = bitmapFont->encoding[r * cols + c];	}    }    pFont->bit = bit;    pFont->byte = byte;    pFont->glyph = glyph;    pFont->scan = scan;    pFont->info.anamorphic = FALSE;    pFont->info.cachable = TRUE;    bitmapComputeFontBounds(pFont);    if (FontCouldBeTerminal(&pFont->info)) {	bdfPadToTerminal(pFont);	bitmapComputeFontBounds(pFont);    }    FontComputeInfoAccelerators(&pFont->info);    if (bitmapFont->bitmapExtra)	FontComputeInfoAccelerators(&bitmapFont->bitmapExtra->info);    if (pFont->info.constantMetrics)	bitmapAddInkMetrics(pFont);    if (bitmapFont->bitmapExtra)	bitmapFont->bitmapExtra->info.inkMetrics = pFont->info.inkMetrics;    bitmapComputeFontInkBounds(pFont);/*    ComputeFontAccelerators (pFont); */    /* generate properties */    min = &pFont->info.ink_minbounds;    max = &pFont->info.ink_maxbounds;    if (state.xHeightProp && (state.xHeightProp->value == -1))	state.xHeightProp->value = state.exHeight ?	    state.exHeight : min->ascent;    if (state.quadWidthProp && (state.quadWidthProp->value == -1))	state.quadWidthProp->value = state.digitCount ?	    (INT32) (state.digitWidths / state.digitCount) :	    (min->characterWidth + max->characterWidth) / 2;    if (state.weightProp && (state.weightProp->value == -1))	state.weightProp->value = bitmapComputeWeight(pFont);    pFont->get_glyphs = bitmapGetGlyphs;    pFont->get_metrics = bitmapGetMetrics;    pFont->unload_font = bdfUnloadFont;    pFont->unload_glyphs = NULL;    return Successful;BAILOUT:    if (pFont->fontPrivate)	bdfFreeFontBits (pFont);    return AllocError;}bdfFreeFontBits(pFont)    FontPtr pFont;{    BitmapFontPtr  bitmapFont;    BitmapExtraPtr bitmapExtra;    int         i;    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;    bitmapExtra = (BitmapExtraPtr) bitmapFont->bitmapExtra;    xfree(bitmapFont->ink_metrics);    xfree(bitmapFont->encoding);    for (i = 0; i < bitmapFont->num_chars; i++)	xfree(bitmapFont->metrics[i].bits);    xfree(bitmapFont->metrics);    if (bitmapExtra)    {	xfree (bitmapExtra->glyphNames);	xfree (bitmapExtra->sWidths);	xfree (bitmapExtra);    }    xfree(pFont->info.props);    xfree(bitmapFont);}intbdfReadFontInfo(pFontInfo, file)    FontInfoPtr pFontInfo;    FontFilePtr file;{    FontRec     font;    int         ret;    ret = bdfReadFont(&font, file, MSBFirst, LSBFirst, 1, 1);    if (ret == Successful) {	*pFontInfo = font.info;	font.info.props = 0;	font.info.isStringProp = 0;	font.info.nprops = 0;	bdfFreeFontBits (&font);    }    return ret;}voidbdfUnloadFont(pFont)    FontPtr     pFont;{    bdfFreeFontBits (pFont);    xfree (pFont->devPrivates);    xfree(pFont);}static BoolbdfPadToTerminal(pFont)    FontPtr     pFont;{    BitmapFontPtr  bitmapFont;    BitmapExtraPtr bitmapExtra;    int         i;    int         new_size;    CharInfoRec new;    int         w,                h;    bitmapFont = (BitmapFontPtr) pFont->fontPrivate;    new.metrics.ascent = pFont->info.fontAscent;    new.metrics.descent = pFont->info.fontDescent;    new.metrics.leftSideBearing = 0;    new.metrics.rightSideBearing = pFont->info.minbounds.characterWidth;    new.metrics.characterWidth = new.metrics.rightSideBearing;    new_size = BYTES_FOR_GLYPH(&new, pFont->glyph);    for (i = 0; i < bitmapFont->num_chars; i++) {	new.bits = (char *) xalloc(new_size);	if (!new.bits)	    return FALSE;	FontCharReshape(pFont, &bitmapFont->metrics[i], &new);        new.metrics.attributes = bitmapFont->metrics[i].metrics.attributes;	xfree(bitmapFont->metrics[i].bits);	bitmapFont->metrics[i] = new;    }    bitmapExtra = bitmapFont->bitmapExtra;    if (bitmapExtra) {	w = GLYPHWIDTHPIXELS(&new);	h = GLYPHHEIGHTPIXELS(&new);	for (i = 0; i < GLYPHPADOPTIONS; i++)	    bitmapExtra->bitmapsSizes[i] = bitmapFont->num_chars *		(BYTES_PER_ROW(w, 1 << i) * h);    }    return TRUE;}

⌨️ 快捷键说明

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