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

📄 dvbs_font.c

📁 凌阳公司机sunplus1002在这个芯片做为机顶盒主芯片下的嵌入式字体库。
💻 C
字号:
/****************************************************** Module Name:	DVBS Font Module Module Description:	Provide interfaces to operate Font base. Copyright ? 2006 Sunplus, Inc. All rights reserved. History: Created by jw.zhao on 4/13/2006 		Modeifed by jw.zhao on 4/24/2006		*******************************************************/#include <stdlib.h>#include <stdio.h>#include "DVBS_Font.h"#include "UNICODE_TO_BIG5.h"/*********VARIABLES**********///UINT8 *g_pu8GlyphResult = NULL;	//for return the glyph dataFont *g_pCurrentFont = NULL;/**********DECLARATION**************************/INT32 getGlyphDataOffset(INT16 n16Character);INT32 lookupOffsetTable(UINT16 n16Character);INT32 Search(UINT16 n16Character);UINT16 getCode(UINT16 n16Character);/***************************************************Prototype:	Font *DVBS_CreateFont(UINT8 * pu8ArrayStartAddress, UINT8 u8Type)Parameters:	pu8ArrayStartAddress - the name of the font data array			u8Type - the type of the font data array, single byte or double bytesReturns:		a pointer of the created fontDescription:	get a font handler from the data arrayRestrictions:	none***************************************************/Font *DVBS_CreateFont(UINT8 * pu8ArrayStartAddress, UINT8 u8Type){	Font *pf = (Font *) malloc(sizeof(Font));	UINT8 *p = pu8ArrayStartAddress;		pf->pu8ArrayStartAddress = pu8ArrayStartAddress;	pf->u8Type = u8Type;	pf->u8AlignedMode = NO_BYTE_ALIGNED;	pf->u8Height= getValue16(p);	p += SIZE_OF_HEIGHT;	pf->u8Width = getValue16(p);	p += SIZE_OF_WIDTH;	pf->u16MinCharCode = getValue16(p);	p += SIZE_OF_MIN_CHAR_CODE;	pf->u16MaxCharCode = getValue16(p);	p += (SIZE_OF_MAX_CHAR_CODE + SIZE_OF_CODE_PAGE);	pf->u16FontFlag = getValue16(p);	p += SIZE_OF_FLAG;	pf->u32CharCounts = getValue32(p);//	ecos_printf("\n\ncounts=%d\n\n\n",pf->u32CharCounts);	if((pf->u16FontFlag & 0x0001) == 1 && u8Type == TYPE_DOUBLE) 		pf->u32CharCounts += 96;	p += SIZE_OF_CHAR_COUNTS;	if (u8Type == TYPE_SINGLE) {		pf->pu8GlyphDataStartAddress = (INT8 *) p;		pf->u16HeadSize = 16;	} else if (u8Type == TYPE_DOUBLE) {		//we won't use the scope		pf->u16HeadSize = 20;		pf->pu8GlyphDataStartAddress = (INT8 *)(p+4);	}	return pf;}/***************************************************INT8* DVBS_FontGetBitmap(INT16 n16Character)Parameters:	n16Character - the charactor,just the codeReturns:		a pointer of the charactor's glyph dataDescription:	get the glyph dataRestrictions:	none***************************************************/INT8* DVBS_FontGetBitmap(INT16 n16Character){	UINT8 *pu8GlyphResult = NULL;        //ecos_printf("!!!!!!!!!%s\n", __FUNCTION__);    if(g_pCurrentFont == NULL) return NULL;		n16Character = DVBS_TranslateCode(n16Character, DEFAULT);		INT32 n32Offset = 0;	UINT8 u8Height = DVBS_FontGetHeight();	UINT8 u8Width = DVBS_FontGetWidth(n16Character);	UINT16 u16Size =  (u8Width * u8Height+ 7) / 8 + 3;	UINT8 * pu8Address = NULL;	if ((g_pCurrentFont->u16FontFlag & 0x0001) == 0) {	//fixed width		n32Offset = getGlyphDataOffset(n16Character); 	//find in a code table, 2 bytes per code		if (n32Offset == INVALID_OFFSET) {            return NULL;		    }		pu8Address= (UINT8 *)(g_pCurrentFont->pu8ArrayStartAddress + n32Offset);			} else {					//volatile width		n32Offset = lookupOffsetTable(n16Character);		if (n32Offset == INVALID_OFFSET){			return NULL;		    }		pu8Address =	(UINT8 *)(g_pCurrentFont->pu8ArrayStartAddress + n32Offset + 1);	}	pu8GlyphResult = (UINT8 *) malloc(sizeof(UINT8) * u16Size);	INT8 InfoArray[3] = {u8Width, u8Height, g_pCurrentFont->u8AlignedMode};	memcpy(pu8GlyphResult, InfoArray, 3);	memcpy(pu8GlyphResult + 3, pu8Address, u16Size - 3);	return pu8GlyphResult;}/***************************************************INT32 DVBS_FontGetHeight(void)Parameters:	noneReturns:		the height of the current used fontDescription:	get the height of the fontRestrictions:	none***************************************************/INT32 DVBS_FontGetHeight(void){	return g_pCurrentFont->u8Height;}/***************************************************INT32 DVBS_FontGetWidth(INT16 n16Character)Parameters:	n16Character - the characterReturns:		the width of the characterDescription:	get the width of the characterRestrictions:	none***************************************************/INT32 DVBS_FontGetWidth(INT16 n16Character){	if ((g_pCurrentFont->u16FontFlag & 0x0001) == 0) {	//fixed width		return g_pCurrentFont->u8Width;	} else {					//volatile width		INT32 n32Offset = lookupOffsetTable(n16Character);		if(n32Offset == INVALID_OFFSET) 		{						return 0;		}		return *(UINT8*) (g_pCurrentFont->pu8ArrayStartAddress + n32Offset);	}}/***************************************************void DVBS_SetCurrentFont(Font * pfont)Parameters:	pfont - the font need to be usedReturns:		noneDescription:	set a font for useingRestrictions:	none***************************************************/void DVBS_SetCurrentFont(Font * pfont){	g_pCurrentFont = pfont;}/**************PRIVATE FOUNCTION********************INT32 getGlyphDataOffset(INT16 n16Character)Parameters:	n16Character - the code of charactorReturns:		the offset to the data array start addressDescription:	fixed width font used only				get the offset of a charactor in a font data arrayRestrictions:	input wrong code return -1***************************************************/INT32 getGlyphDataOffset(INT16 n16Character){	if ((n16Character > g_pCurrentFont->u16MaxCharCode) || (n16Character < g_pCurrentFont->u16MinCharCode)) {		return INVALID_OFFSET;				//an unavailable code	}	INT32 n32RetOffset = 0;	INT16 n16Position = 0;	UINT8 u8Height = DVBS_FontGetHeight();	UINT8 u8Width = DVBS_FontGetWidth( n16Character);	n16Position = Search(n16Character);	if(n16Position == -1) return INVALID_OFFSET;	if((g_pCurrentFont->u16FontFlag & 0x0004) == 0) {	//part code with index		n32RetOffset = g_pCurrentFont->u16HeadSize + g_pCurrentFont->u32CharCounts * 2 + ((u8Height * u8Width+ 7) / 8) * n16Position;	}else{			//full code ,no index		n32RetOffset = g_pCurrentFont->u16HeadSize + ((u8Height * u8Width+ 7) / 8) * n16Position;	}	return n32RetOffset;}/***************************************************INT32 lookupOffsetTable(INT16 n16Character)Parameters:	n16Character - the code of charactorReturns:		offset to the data array start addressDescription:	the offset to the data array start addressDescription:	used for unfixed width font base				get the offset of a charactor in a font data arrayRestrictions:	***************************************************/INT32 lookupOffsetTable(UINT16 n16Character){	if ((n16Character> g_pCurrentFont->u16MaxCharCode) || (n16Character < g_pCurrentFont->u16MinCharCode)) {			//	ecos_printf("INVALID_OFFSET:0x%x,0x%x,0x%x\n\n",n16Character,g_pCurrentFont->u16MinCharCode, g_pCurrentFont->u16MaxCharCode);		return INVALID_OFFSET;	}		INT16 n16Position = 0;	INT32 n32Offset = INVALID_OFFSET;		n16Position = Search(n16Character);	if(n16Position == -1)	{//		ecos_printf("search position fail===\n");		return INVALID_OFFSET;	}	if(g_pCurrentFont->u8Type == TYPE_SINGLE){		n32Offset = getValue32(g_pCurrentFont->pu8GlyphDataStartAddress + n16Position * 4);	}else{		n32Offset = getValue32(g_pCurrentFont->pu8GlyphDataStartAddress + n16Position * 6 + 2);	}	return n32Offset;		}/***************************************************Prototype:	INT32 Search(INT16 n16Character)Parameters:	n16Character - the characterReturns:		the position ,the index in the font base Description:	get the character position in all character queueRestrictions:	***************************************************/INT32 Search(UINT16 n16Character){	UINT16 min = 0;	UINT16 max = g_pCurrentFont->u32CharCounts;//-1+1 actually	UINT16 mid = max / 2;	if ( (g_pCurrentFont->u16FontFlag & 0x0004) == 0 ) {	//part code		while (1) {			if ((max == min + 1)				&& (n16Character < getCode(max))				&& (n16Character > getCode(min))) {				return -1;		//the character is not included in the font base			}			if (getCode(mid) == n16Character) {				return  mid;			} else if (getCode(mid) > n16Character) {				max = mid;				mid = (max + min) / 2;			} else {				min = mid;				mid = (max + min) / 2;			}		}	} else {			//full code		return	(n16Character -( g_pCurrentFont->u16MinCharCode) );	}}/***************************************************UINT16 getCode(INT16 n16Position)Parameters:	n16Position - the position of the charactor in all charactors queueReturns:		the code of the character Description:	only used in search function. get the code of a charactorRestrictions:	***************************************************/UINT16 getCode(UINT16 n16Position){	UINT16 u16RetCode = 0;	if((g_pCurrentFont->u16FontFlag & 0x0001) == 0) {	//fixed width ,part code, index size 2		u16RetCode = getValue16(g_pCurrentFont->pu8GlyphDataStartAddress + n16Position * 2);	}else if(g_pCurrentFont->u8Type == TYPE_DOUBLE){	//unfixed width,double byte font base ,part code ,index size 6		u16RetCode = getValue16(g_pCurrentFont->pu8GlyphDataStartAddress + n16Position * 6);	}	return u16RetCode;}/***************************************************INT16 DVBS_TranslateCode(INT16 sourceCode, Translate_t mode)Parameters:		source_code - the code of a charactor				mode - change the code mode of a charactor to another mode,eg:gb2312 to big5Returns:		the changed code of the charactorDescription:	get the destin code of a charactorRestrictions:	must less than 2^31 codes***************************************************/INT16 DVBS_TranslateCode(INT16 sourceCode, Translate_t mode){	INT16 code = 0;	UINT16 i = 0;	INT16 *p = (INT16 *) UniCode_To_BIG5;	switch (mode) {	case DEFAULT:		return sourceCode;	case UNICODETOBIG5:		for (i = 0; i < table_size; i++) {			if (*p == sourceCode) {				return *++p;			} else				p += 2;		}		break;	case BIG5TOUNICODE:		for (i = 0; i < table_size; i++) {			if (*(p + 1) == sourceCode) {				return *p;			} else				p += 2;		}		break;	case BIG5TOGB:	case UNICODETOGB:	case GBTOUNICODE:	case GBTOBIG5:		;	}	return code;}

⌨️ 快捷键说明

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