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

📄 pcfread.c

📁 unix vnc 协议源码. VNC是一款远程控制工具软件.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: pcfread.c /main/18 1996/09/28 16:48:33 rws $ *//*Copyright (c) 1990  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.*//* * Author:  Keith Packard, MIT X Consortium */#include "fntfilst.h"#include "bitmap.h"#include "pcf.h"#ifndef MAX#define   MAX(a,b)    (((a)>(b)) ? a : b)#endif/* Read PCF font files */void        pcfUnloadFont();static int  position;static intpcfGetLSB32(file)    FontFilePtr file;{    int         c;    c = FontFileGetc(file);    c |= FontFileGetc(file) << 8;    c |= FontFileGetc(file) << 16;    c |= FontFileGetc(file) << 24;    position += 4;    return c;}static intpcfGetINT32(file, format)    FontFilePtr file;    CARD32      format;{    int         c;    if (PCF_BYTE_ORDER(format) == MSBFirst) {	c = FontFileGetc(file) << 24;	c |= FontFileGetc(file) << 16;	c |= FontFileGetc(file) << 8;	c |= FontFileGetc(file);    } else {	c = FontFileGetc(file);	c |= FontFileGetc(file) << 8;	c |= FontFileGetc(file) << 16;	c |= FontFileGetc(file) << 24;    }    position += 4;    return c;}static intpcfGetINT16(file, format)    FontFilePtr file;    CARD32      format;{    int         c;    if (PCF_BYTE_ORDER(format) == MSBFirst) {	c = FontFileGetc(file) << 8;	c |= FontFileGetc(file);    } else {	c = FontFileGetc(file);	c |= FontFileGetc(file) << 8;    }    position += 2;    return c;}#define pcfGetINT8(file, format) (position++, FontFileGetc(file))static      PCFTablePtrpcfReadTOC(file, countp)    FontFilePtr file;    int        *countp;{    CARD32      version;    PCFTablePtr tables;    int         count;    int         i;    position = 0;    version = pcfGetLSB32(file);    if (version != PCF_FILE_VERSION)	return (PCFTablePtr) NULL;    count = pcfGetLSB32(file);    tables = (PCFTablePtr) xalloc(count * sizeof(PCFTableRec));    if (!tables)	return (PCFTablePtr) NULL;    for (i = 0; i < count; i++) {	tables[i].type = pcfGetLSB32(file);	tables[i].format = pcfGetLSB32(file);	tables[i].size = pcfGetLSB32(file);	tables[i].offset = pcfGetLSB32(file);    }    *countp = count;    return tables;}/* * PCF supports two formats for metrics, both the regular * jumbo size, and 'lite' metrics, which are useful * for most fonts which have even vaguely reasonable * metrics */staticpcfGetMetric(file, format, metric)    FontFilePtr file;    CARD32      format;    xCharInfo  *metric;{    metric->leftSideBearing = pcfGetINT16(file, format);    metric->rightSideBearing = pcfGetINT16(file, format);    metric->characterWidth = pcfGetINT16(file, format);    metric->ascent = pcfGetINT16(file, format);    metric->descent = pcfGetINT16(file, format);    metric->attributes = pcfGetINT16(file, format);}staticpcfGetCompressedMetric(file, format, metric)    FontFilePtr file;    CARD32      format;    xCharInfo  *metric;{    metric->leftSideBearing = pcfGetINT8(file, format) - 0x80;    metric->rightSideBearing = pcfGetINT8(file, format) - 0x80;    metric->characterWidth = pcfGetINT8(file, format) - 0x80;    metric->ascent = pcfGetINT8(file, format) - 0x80;    metric->descent = pcfGetINT8(file, format) - 0x80;    metric->attributes = 0;}/* * Position the file to the begining of the specified table * in the font file */static BoolpcfSeekToType(file, tables, ntables, type, formatp, sizep)    FontFilePtr file;    PCFTablePtr tables;    int         ntables;    CARD32      type;    CARD32     *formatp;    CARD32     *sizep;{    int         i;    for (i = 0; i < ntables; i++)	if (tables[i].type == type) {	    if (position > tables[i].offset)		return FALSE;	    if (!FontFileSkip(file, tables[i].offset - position))		return FALSE;	    position = tables[i].offset;	    *sizep = tables[i].size;	    *formatp = tables[i].format;	    return TRUE;	}    return FALSE;}static BoolpcfHasType (tables, ntables, type)    PCFTablePtr tables;    int         ntables;    CARD32      type;{    int         i;    for (i = 0; i < ntables; i++)	if (tables[i].type == type)	    return TRUE;    return FALSE;}/* * pcfGetProperties  * * Reads the font properties from the font file, filling in the FontInfo rec * supplied.  Used by by both ReadFont and ReadFontInfo routines. */static BoolpcfGetProperties(pFontInfo, file, tables, ntables)    FontInfoPtr pFontInfo;    FontFilePtr file;    PCFTablePtr tables;    int         ntables;{    FontPropPtr props = 0;    int         nprops;    char       *isStringProp = 0;    CARD32      format;    int         i;    int         size;    int         string_size;    char       *strings;    /* font properties */    if (!pcfSeekToType(file, tables, ntables, PCF_PROPERTIES, &format, &size))	goto Bail;    format = pcfGetLSB32(file);    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))	goto Bail;    nprops = pcfGetINT32(file, format);    props = (FontPropPtr) xalloc(nprops * sizeof(FontPropRec));    if (!props)	goto Bail;    isStringProp = (char *) xalloc(nprops * sizeof(char));    if (!isStringProp)	goto Bail;    for (i = 0; i < nprops; i++) {	props[i].name = pcfGetINT32(file, format);	isStringProp[i] = pcfGetINT8(file, format);	props[i].value = pcfGetINT32(file, format);    }    /* pad the property array */    /*     * clever here - nprops is the same as the number of odd-units read, as     * only isStringProp are odd length     */    if (nprops & 3)    {	i = 4 - (nprops & 3);	FontFileSkip(file, i);	position += i;    }    string_size = pcfGetINT32(file, format);    strings = (char *) xalloc(string_size);    if (!strings) {	goto Bail;    }    FontFileRead(file, strings, string_size);    position += string_size;    for (i = 0; i < nprops; i++) {	props[i].name = MakeAtom(strings + props[i].name,				 strlen(strings + props[i].name), TRUE);	if (isStringProp[i]) {	    props[i].value = MakeAtom(strings + props[i].value,				      strlen(strings + props[i].value), TRUE);	}    }    xfree(strings);    pFontInfo->isStringProp = isStringProp;    pFontInfo->props = props;    pFontInfo->nprops = nprops;    return TRUE;Bail:    xfree(isStringProp);    xfree(props);    return FALSE;}/* * pcfReadAccel * * Fill in the accelerator information from the font file; used * to read both BDF_ACCELERATORS and old style ACCELERATORS */static BoolpcfGetAccel(pFontInfo, file, tables, ntables, type)    FontInfoPtr pFontInfo;    FontFilePtr file;    PCFTablePtr	tables;    int		ntables;    CARD32	type;{    CARD32      format;    int		size;    if (!pcfSeekToType(file, tables, ntables, type, &format, &size))	goto Bail;    format = pcfGetLSB32(file);    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&	!PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS))     {	goto Bail;    }    pFontInfo->noOverlap = pcfGetINT8(file, format);    pFontInfo->constantMetrics = pcfGetINT8(file, format);    pFontInfo->terminalFont = pcfGetINT8(file, format);    pFontInfo->constantWidth = pcfGetINT8(file, format);    pFontInfo->inkInside = pcfGetINT8(file, format);    pFontInfo->inkMetrics = pcfGetINT8(file, format);    pFontInfo->drawDirection = pcfGetINT8(file, format);    pFontInfo->anamorphic = FALSE;    pFontInfo->cachable = TRUE;     /* natural alignment */ pcfGetINT8(file, format);    pFontInfo->fontAscent = pcfGetINT32(file, format);    pFontInfo->fontDescent = pcfGetINT32(file, format);    pFontInfo->maxOverlap = pcfGetINT32(file, format);    pcfGetMetric(file, format, &pFontInfo->minbounds);    pcfGetMetric(file, format, &pFontInfo->maxbounds);    if (PCF_FORMAT_MATCH(format, PCF_ACCEL_W_INKBOUNDS)) {	pcfGetMetric(file, format, &pFontInfo->ink_minbounds);	pcfGetMetric(file, format, &pFontInfo->ink_maxbounds);    } else {	pFontInfo->ink_minbounds = pFontInfo->minbounds;	pFontInfo->ink_maxbounds = pFontInfo->maxbounds;    }    return TRUE;Bail:    return FALSE;}intpcfReadFont(pFont, file, bit, byte, glyph, scan)    FontPtr     pFont;    FontFilePtr file;    int         bit,                byte,                glyph,                scan;{    CARD32      format;    CARD32      size;    BitmapFontPtr  bitmapFont = 0;    int         i;    PCFTablePtr tables = 0;    int         ntables;    int         nmetrics;    int         nbitmaps;    int         sizebitmaps;    int         nink_metrics;    CharInfoPtr metrics = 0;    xCharInfo  *ink_metrics = 0;    char       *bitmaps = 0;    CharInfoPtr *encoding = 0;    int         nencoding;    int         encodingOffset;    CARD32      bitmapSizes[GLYPHPADOPTIONS];    CARD32     *offsets = 0;    Bool	hasBDFAccelerators;    pFont->info.props = 0;    if (!(tables = pcfReadTOC(file, &ntables)))	goto Bail;    /* properties */    if (!pcfGetProperties(&pFont->info, file, tables, ntables))	goto Bail;    /* Use the old accelerators if no BDF accelerators are in the file */    hasBDFAccelerators = pcfHasType (tables, ntables, PCF_BDF_ACCELERATORS);    if (!hasBDFAccelerators)	if (!pcfGetAccel (&pFont->info, file, tables, ntables, PCF_ACCELERATORS))	    goto Bail;    /* metrics */    if (!pcfSeekToType(file, tables, ntables, PCF_METRICS, &format, &size)) {	goto Bail;    }    format = pcfGetLSB32(file);    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT) &&	    !PCF_FORMAT_MATCH(format, PCF_COMPRESSED_METRICS)) {	goto Bail;    }    if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))	nmetrics = pcfGetINT32(file, format);    else	nmetrics = pcfGetINT16(file, format);    metrics = (CharInfoPtr) xalloc(nmetrics * sizeof(CharInfoRec));    if (!metrics) {	goto Bail;    }    for (i = 0; i < nmetrics; i++)	if (PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))	    pcfGetMetric(file, format, &(metrics + i)->metrics);	else	    pcfGetCompressedMetric(file, format, &(metrics + i)->metrics);    /* bitmaps */    if (!pcfSeekToType(file, tables, ntables, PCF_BITMAPS, &format, &size))	goto Bail;    format = pcfGetLSB32(file);    if (!PCF_FORMAT_MATCH(format, PCF_DEFAULT_FORMAT))	goto Bail;    nbitmaps = pcfGetINT32(file, format);    if (nbitmaps != nmetrics)	goto Bail;    offsets = (CARD32 *) xalloc(nbitmaps * sizeof(CARD32));    if (!offsets)	goto Bail;    for (i = 0; i < nbitmaps; i++)	offsets[i] = pcfGetINT32(file, format);    for (i = 0; i < GLYPHPADOPTIONS; i++)	bitmapSizes[i] = pcfGetINT32(file, format);    sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX(format)];    /* guard against completely empty font */    bitmaps = (char *) xalloc(sizebitmaps ? sizebitmaps : 1);    if (!bitmaps)	goto Bail;    FontFileRead(file, bitmaps, sizebitmaps);    position += sizebitmaps;    if (PCF_BIT_ORDER(format) != bit)	BitOrderInvert(bitmaps, sizebitmaps);    if ((PCF_BYTE_ORDER(format) == PCF_BIT_ORDER(format)) != (bit == byte)) {

⌨️ 快捷键说明

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