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

📄 font_pcf.c

📁 the embedded GUI for SamSung s3c2410 cpu based board.is microwindows0.90
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * PCF font engine for Microwindows * Copyright (c) 2002, 2003 Greg Haerr <greg@censoft.com> * Copyright (c) 2001, 2002 by Century Embedded Technologies * * Supports dynamically loading .pcf and pcf.gz X11 fonts * * Written by Jordan Crouse * Bugfixed by Greg Haerr * * 28.01.2003: *   Patch for big-endian-machines by Klaus Fuerth <Fuerth.ELK@gmx.de> */#include <stdio.h>#include <string.h>#include <errno.h>#include <stdlib.h>#include "swap.h"#include "device.h"#include "devfont.h"#include "../drivers/genfont.h"extern MWPIXELVAL gr_background;extern MWBOOL gr_usebg;/* The user hase the option including ZLIB and being able to    *//* directly read compressed .pcf files, or to omit it and save  *//* space.  The following defines make life much easier          */#ifdef HAVE_PCFGZ_SUPPORT#include <zlib.h>#define FILEP gzFile#define FOPEN(path, mode)           gzopen(path, mode)#define FREAD(file, buffer, size)   gzread(file, buffer, size)#define FSEEK(file, offset, whence) gzseek(file, offset, whence)#define FCLOSE(file)                gzclose(file)#else#define FILEP  FILE *#define FOPEN(path, mode)           fopen(path, mode)#define FREAD(file, buffer, size)   fread(buffer, 1, size, file)#define FSEEK(file, offset, whence) fseek(file, offset, whence)#define FCLOSE(file)                fclose(file)#endif/* Handling routines for PCF fonts, use MWCOREFONT structure */static void pcf_unloadfont(PMWFONT font);/* these procs used when font ASCII indexed*/static MWFONTPROCS pcf_fontprocs = {	MWTF_ASCII,	gen_getfontinfo,	gen_gettextsize,	gen_gettextbits,	pcf_unloadfont,	corefont_drawtext,	NULL,			/* setfontsize */	NULL,			/* setfontrotation */	NULL,			/* setfontattr */};/* these procs used when font requires UC16 index*/static MWFONTPROCS pcf_fontprocs16 = {	MWTF_UC16,		/* routines expect unicode 16 */	gen_getfontinfo,	gen16_gettextsize,	gen_gettextbits,	pcf_unloadfont,	gen16_drawtext,	NULL,			/* setfontsize */	NULL,			/* setfontrotation */	NULL,			/* setfontattr */	NULL,			/* duplicate not yet implemented */};/* These are maintained statically for ease FIXME*/static struct toc_entry *toc;static unsigned long toc_size;/* Various definitions from the Free86 PCF code */#define PCF_VERSION "\01fcp"	/* reversed version #*/#define PCF_PROPERTIES		(1 << 0)#define PCF_ACCELERATORS	(1 << 1)#define PCF_METRICS		(1 << 2)#define PCF_BITMAPS		(1 << 3)#define PCF_INK_METRICS		(1 << 4)#define PCF_BDF_ENCODINGS	(1 << 5)#define PCF_SWIDTHS		(1 << 6)#define PCF_GLYPH_NAMES		(1 << 7)#define PCF_BDF_ACCELERATORS	(1 << 8)#define PCF_FORMAT_MASK		0xFFFFFF00#define PCF_DEFAULT_FORMAT	0x00000000#define PCF_LSB_FIRST 0x01#define PCF_MSB_FIRST 0x02/* A few structures that define the various fields within the file */struct toc_entry {	int type;	int format;	int size;	int offset;};struct prop_entry {	unsigned int name;	unsigned char is_string;	unsigned int value;};struct string_table {	unsigned char *name;	unsigned char *value;};struct metric_entry {	short leftBearing;	short rightBearing;	short width;	short ascent;	short descent;	short attributes;};struct encoding_entry {	unsigned short min_byte2;	/* min_char or min_byte2 */	unsigned short max_byte2;	/* max_char or max_byte2 */	unsigned short min_byte1;	/* min_byte1 (hi order) */	unsigned short max_byte1;	/* max_byte1 (hi order) */	unsigned short defaultchar;	unsigned long count;		/* count of map entries */	unsigned short *map;		/* font index -> glyph index */};/* This is used to quickly reverse the bits in a field */static unsigned char _reverse_byte[0x100] = {	0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,	0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,	0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,	0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,	0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,	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,	0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,	0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,	0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,	0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff};#if MW_CPU_BIG_ENDIAN/* Reverse the bits of size bytes */static voidreverse(unsigned char *buf, int size){        unsigned int i;	for (i=0; i < size; i++)	  buf[i] = _reverse_byte[buf[i]];}#endif/* Reverse and swap a short */static voidword_reverse_swap(unsigned char *buf){	unsigned char t;	t = _reverse_byte[buf[0]];	buf[0] = _reverse_byte[buf[1]];	buf[1] = t;}/* Get the offset of the given field */static intpcf_get_offset(int item){	int i;	for (i = 0; i < toc_size; i++)		if (item == toc[i].type)			return (toc[i].offset);	return -1;}#if LATER/* Read the properties from the file */static intpcf_readprops(FILEP file, struct prop_entry **prop,	      struct string_table **strings){	int offset;	int format;	int num_props;	unsigned long ssize;	int i;	struct string_table *s;	struct prop_entry *p;	unsigned char *string_buffer, *spos;	if ((offset = pcf_get_offset(PCF_PROPERTIES)) == -1)		return (-1);	FSEEK(file, offset, SEEK_SET);	FREAD(file, &format, sizeof(format));	FREAD(file, &num_props, sizeof(num_props));	p = *prop =		(struct prop_entry *) malloc(num_props *					     sizeof(struct prop_entry));	for (i = 0; i < num_props; i++) {		FREAD(file, &p[i].name, sizeof(p[i].name));		FREAD(file, &p[i].is_string, sizeof(p[i].is_string));		FREAD(file, &p[i].value, sizeof(p[i].value));	}	/* Pad to 32 bit multiples */	if (num_props & 3)		FSEEK(file, 4 - (num_props & 3), SEEK_CUR);	FREAD(file, &ssize, sizeof(ssize));	/* Read the entire set of strings into memory */	spos = string_buffer = (unsigned char *) ALLOCA(ssize);	FREAD(file, string_buffer, ssize);	/* Allocate the group of strings */	s = *strings =		(struct string_table *) malloc(num_props *					       sizeof(struct string_table));	for (i = 0; i < num_props; i++) {		s[i].name = (unsigned char *) strdup(spos);		spos += strlen(s[i].name) + 1;		if (p[i].is_string) {			s[i].value = (unsigned char *) strdup(spos);			spos += strlen(s[i].value) + 1;		} else			s[i].value = 0;	}	FREEA(string_buffer);	return (num_props);}#endif/* Read the actual bitmaps into memory */static intpcf_readbitmaps(FILEP file, unsigned char **bits, int *bits_size,	int *endian, unsigned long **offsets){	unsigned long *o;	unsigned char *b;	unsigned long bmsize[4];	unsigned int format, num_glyphs, offset;	unsigned int pad;	unsigned int i;	if ((offset = pcf_get_offset(PCF_BITMAPS)) == -1)		return (-1);	FSEEK(file, offset, SEEK_SET);	FREAD(file, &format, sizeof(format));	format = dwswap(format);	if (format & 8) *endian = PCF_LSB_FIRST;	else *endian = PCF_MSB_FIRST;	FREAD(file, &num_glyphs, sizeof(num_glyphs));	num_glyphs = dwswap(num_glyphs);	o = *offsets =		(unsigned long *) malloc(num_glyphs * sizeof(unsigned long));	FREAD(file, o, sizeof(unsigned long) * num_glyphs);	for (i=0; i < num_glyphs; i++)	    o[i] = dwswap(o[i]);	FREAD(file, bmsize, sizeof(bmsize));	for (i=0; i < (sizeof(bmsize)/sizeof(bmsize[0])); i++)	    bmsize[i] = dwswap(bmsize[i]);	pad = format & (3 << 0);	*bits_size = bmsize[pad] ? bmsize[pad] : 1;	b = *bits = (unsigned char *) malloc(*bits_size);	FREAD(file, b, *bits_size);	return num_glyphs;}/* This reads the metrics of the file */static intpcf_readmetrics(FILE * file, struct metric_entry **metrics){	int offset;	int format;	if ((offset = pcf_get_offset(PCF_METRICS)) == -1)		return -1;	FSEEK(file, offset, SEEK_SET);	FREAD(file, &format, sizeof(format));	format = dwswap(format);	if ((format & PCF_FORMAT_MASK) == PCF_DEFAULT_FORMAT) {		unsigned long size;		struct metric_entry *m;		int i;		FREAD(file, &size, sizeof(size));	/* 32 bits - Number of metrics */

⌨️ 快捷键说明

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