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

📄 fontproc.c

📁 显示汉字和英文字母点阵字库
💻 C
字号:
/******************************************************************************************
* 文件名称:fontproc.c
* 功    能:字库处理模块,用于生成字符串位图并可截取位图指定部分用于显示。
* 版权所有 (C)2007
* 当前版本:V1.0
* 作    者:jing.sw
* 修改记录:修改日期、 修改内容、版本号、修改者
*           2005-6-9  第一次创建 V1.0 by jing.sw
*******************************************************************************************/
#include "fontProc.h"
#include "Char_18x23.c"

static unsigned char Mat24[24][3];
static unsigned char Mat16[16][2];
static unsigned char Mat12[12][2];

/* Exported structure definition. */
CHARFONTBis_t ASCII_18x23 = {
	ASCII_18x23_bits,
	ASCII_18x23_offset,
	ASCII_18x23_width,
};

/******************************************************************************************
* 函数名称:fontInit
* 功    能:初始化字库模块(将字库调入内存)
* 参数说明:无
* 返 回 值:  返回 0-成功,else-失败
*******************************************************************************************/
FILE *OpenFontLib(char *fontName)
{
	FILE *fontfd;
	if((fontfd=fopen(fontName,"rb"))==NULL)
	{
		printf ("Error! Can't open %s font!\n", fontName);
		return NULL;
	}
	return fontfd;
}

FILE *FontInit(char *fontName)
{
	FILE *fontfd;
	fontfd = OpenFontLib(fontName);
	if (fontfd==NULL)
	{
		printf("Cann't Open HZK %s!\n", fontName);
		return NULL;
	}
	return fontfd;
}

int GetFontMat(FILE *hzkfd, unsigned char *HZ, int nLen, int fontType, unsigned char *pPixelBuf, int nBmpWidth, int nBmpHeight, int nOffsetX, int nOffsetY, unsigned char nPaletteVal, BOOL nEraseLastInfoFlag)
{
	int qu;
	int wei;
	int en;
	int m,n,k,l;
	unsigned char *PrintPixel;
	unsigned char *str = HZ;
	int nIndex = 0;
	int nStrOffset;
	int nstart;
	int nfirstOffsetX = nOffsetX;
	int nColOffset;
	int nRowOffset;
	int OffsetVal;

	nColOffset = nOffsetX;
	nRowOffset = nOffsetY;

	while (1)
	{
		if (((str-HZ)>=nLen) ||(nColOffset>nBmpWidth))
		{
			break;
		}

		if ((str[0]>128) && (str[1]>128))
		{
			if (fontType == HZK24)
			{
				qu  = str[0]-32-128;
				wei = str[1]-32-128;
				
				fseek (hzkfd, (94*(qu-1)+(wei-1))*(FONT_BIT_SIZE24*(FONT_BIT_SIZE24/8)), SEEK_SET);
				fread (Mat24, 72, 1, hzkfd);
					
				for(m=0; m<FONT_BIT_SIZE24; m++)
				{
					if (nColOffset>=0)
					{
						PrintPixel = pPixelBuf+(nRowOffset+m)*nBmpWidth+nColOffset;
						nstart = 0;
						OffsetVal = FONT_BIT_SIZE24;
					}
					else if (abs(nColOffset)<FONT_BIT_SIZE24)
					{
						PrintPixel = pPixelBuf+(nRowOffset+m)*nBmpWidth;
						nstart = abs(nColOffset)%FONT_BIT_SIZE24;
						OffsetVal = FONT_BIT_SIZE24;
					}
					else
					{
						OffsetVal = FONT_BIT_SIZE24;
						break;
					}
					for(nIndex=0, n=nstart; n<FONT_BIT_SIZE24; n++)
					{
						if ((nIndex+nColOffset)>=nBmpWidth)  //列: 最后一个象素可能有问题
						{
							break;
						}
						l = n/8;
						k = n%8;
						if(Mat24[m][l]&(0x80>>k))
						{
							PrintPixel[nIndex] = nPaletteVal;
						}
						else if (nEraseLastInfoFlag==TRUE)
						{
							PrintPixel[nIndex] = 0;
						}
						nIndex++;
					}
				}
				nColOffset += OffsetVal;
				str +=2;
			}	    
		}
		else
		{
			unsigned char *pChar;
			int BitsIndex;
			int ASCIIwidth;

			en = str[0]-32;
			BitsIndex   = ASCII_18x23.offset[en];
			ASCIIwidth = ASCII_18x23.width[en];

			for(m=0; m<23; m++)
			{
				nIndex = 0;
				pChar = &ASCII_18x23.bits[BitsIndex+m];

				if (nColOffset>=0)
				{
					PrintPixel = pPixelBuf+(nRowOffset+m)*nBmpWidth+nColOffset;
					nstart = 0;
					OffsetVal = ASCIIwidth;
				}
				else if (abs(nColOffset)<ASCIIwidth)
				{
					PrintPixel = pPixelBuf+(nRowOffset+m)*nBmpWidth;
					nstart = abs(nColOffset)%ASCIIwidth;
					OffsetVal = ASCIIwidth;
				}
				else
				{
					OffsetVal = ASCIIwidth;
					break;
				}
				for(n=nstart; n<ASCIIwidth; n++)
				{
					char ch;
					ch = (n/8) ? pChar[0]: pChar[1];
					k = n%8;

					if ((n+nColOffset)>=nBmpWidth)  //列: 最后一个象素可能有问题
					{
						break;
					}
					if(ch&(0x80>>k))
					{
						PrintPixel[nIndex] = nPaletteVal;
					}
					else if (nEraseLastInfoFlag==TRUE)
					{
						PrintPixel[nIndex] = 0;
					}
					nIndex++;
				}
			}
			nColOffset += OffsetVal;
			str += 1;
		}
	}
	return 0;
}

int FillBackGround(unsigned char *pPixelBuf, int nBmpWidth, int nBmpHeight, FILLAREABis_t FillPos, unsigned char nPaletteVal, BOOL nEraseForeFlag)
{
	int m,n;
	unsigned char *PrintPixel;
	int nRowEnd;
	int nColEnd;

	if ((FillPos.y+FillPos.height)>nBmpHeight)
	{
		nRowEnd = (nBmpHeight-FillPos.y);
	}
	else
	{
		nRowEnd = FillPos.height;
	}

	for (n=0; n<nRowEnd; n++)
	{
		PrintPixel = pPixelBuf + nBmpWidth*(FillPos.y+n) + FillPos.x;

		if ((FillPos.x+FillPos.width)>nBmpWidth)
		{
			nColEnd = (nBmpWidth-FillPos.x);
		}
		else
		{
			nColEnd = FillPos.width;
		}
		for (m=0; m<nColEnd; m++)
		{
			if (nEraseForeFlag==TRUE)
			{
				PrintPixel[m] = nPaletteVal;
			}
			else if (PrintPixel[m]==0)
			{
				PrintPixel[m] = nPaletteVal;
			}
		}
	}
	return 0;
}

⌨️ 快捷键说明

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