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

📄 char_test.c

📁 一个手机平台的字体现实标准库转平台c源字库的脚本程序。
💻 C
字号:
#include <stdio.h>
#include <string.h>
#include "ch_in.h"
#include "index.h"
#include "gb2ucs.h"
#include "zifu.h"
#define SIZE  512
typedef unsigned short u16;
typedef unsigned char u8;
//char ph[SIZE];
//char ch[SIZE];
//char ch_out[2*SIZE];

u16 GetIndexInUcs2Table(u16 ucs)
/* GetIndexInUcs2Table
  * Get the index from ucs2->gbk table
  */
{
  int  First = 0;
  int  Last = 9554-1;
  int  Mid;

  while ( Last >= First ) 
  {
    Mid = (First + Last) >> 1;

    if(ucs < tab_ucs2gb[Mid].ucs)
    	Last = Mid - 1;

    else if(ucs > tab_ucs2gb[Mid].ucs)
    	First = Mid + 1;

    else if(ucs == tab_ucs2gb[Mid].ucs)
    	return tab_ucs2gb[Mid].gb;
  }

  return 0xffff;
}

main()
{
FILE * finp, * finc , * fout,* fout1;	
char * p1, * p2, * p3;
char str[SIZE];
char str1[66];
int count,count1;
int with, height,band;
with=height=band=0;

memset(str, 0, SIZE);
memset(str1, 0, sizeof(str1));	
p1=p2=p3=NULL;	

if((finp=fopen("ph_in.h","r"))==NULL)
{
	printf("output file err!\n");
	exit(0);	
}
	
if((fout=fopen("out.txt","w"))==NULL)
{
	printf("output file err!\n");
	exit(0);	
}


// /* ¤ */  {/*0x00a4,*/  
printf("input the character with pls:\n");
scanf("%d",&with);
printf("input the character height pls:\n");
scanf("%d",&height);
if(with%8==0)
band=with/8;
else
band=with/8+1;
band*=height;
band=band?band:32;
printf("charcater band %d\n",band);

fputs("unsinged char data[]={",fout);
fputc('\n',fout);

count=0;
while(fgets(str,sizeof(str),finp))
{
	p1=strstr(str,"/*");
	if(!p1)
	continue;
	p2=strstr(str,",*/");
	p2++,p2++,p2++;

	memcpy(str1,p1,(p2-p1));
	fputs(str1,fout);
	
			if(count>sizeof(data_index)/4)
		{
				fputs("/*to be add!*/{0}\n",fout);
					
				continue;	
		}
	
	{
		
		u16 temp;
		u16 templ,temph;
		char buf[20];
		memset(buf,0,20);

		
				
		{
			// 字符部分
			if((0x00a4<=data_index[count]&&data_index[count]<0x4e00)||(0xe7c7<=data_index[count]&&data_index[count]<=0xffe5))
			{
				temp=GetIndexInUcs2Table(data_index[count]);
			//	printf("%x %x\n",temp,data_index[count]);
				if(0xa1a1<=temp<=0xa9ef)
				{
				//	fputc('{',fout);
					temph=(temp&0xff00)>>8;
					templ=temp&0x00ff;
				//	printf("%x  %x\n",temp<<8,temp);
				//	printf("%x  %x %x\n",temp,templ,temph);
					if((0xa1<=temph&&temph<=0xa9)&&(0xa1<=templ&&templ<=0xfe))
					{
					
					for(count1=0;count1<band;count1++)
					{	
					
						sprintf(buf,"0x%02X",zifu[((temph-0xa1)*94+(templ-0xa1))*band+count1]);
									
						fputs(buf,fout);
						memset(buf,0,20);
					if(count1<31)
					fputc(',',fout);						
						//fputc(',',fout);	
					}	
					}
					

					fputs("},\n",fout);		
				}
				else
				continue;
			}	
			else if(data_index[count]>0x9fa5)
			{
				fputs("not found!{0}\n",fout);
				continue;
			}
			//汉字部分	
			else
			{	
			//	fputc('{',fout);
				temp=data_index[count];
				for(count1=0;count1<band;count1++)
				{	
					
					sprintf(buf,"0x%02X",ch_in[(temp-0x4e00)*band+count1]);
									
					fputs(buf,fout);
					memset(buf,0,20);
					if(count1<31)
					fputc(',',fout);	
				}
				fputs("},\n",fout);
			
			}
			count++;
					
		}
		
		
	}
	
		
	fputc('\n',fout);
	
}
fputc('}',fout);






fclose(finp);
fclose(fout);

	
}

⌨️ 快捷键说明

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