在写打印机程序的时候,需要将汉字字库文件(.hz或者.zf文件)里面二进制数据提取出来放到Flash里面,我当时采用的是16进制的无符号16位数组存储,因为字库涉及版权问题,就不予以上传,下面是C++实现源码:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string.h>
using namespace std;
#define HZ_NUM 3755
#define HZ_HEIGHT 16
#define HZ_WIDTH 16
#define LINE_NUM HZ_HEIGHT*HZ_WIDTH/8
int main()
{
FILE *input;
FILE *output;
unsigned char temp;
char high,low;
int i=0;
if((input = fopen("font.hz","rb")) == NULL || (output = fopen("font.rtf","w")) == NULL)
{
return -1;
}
temp = fgetc(input);
while(!feof(input) && i<(HZ_NUM*LINE_NUM))
{
low = temp & 0x0F;
high = temp >> 4;
if(i%2==0)
fprintf(output,"0x%x%x",high,low);
else
fprintf(output,"%x%x,",high,low);
temp = fgetc(input);
i++;
if(i%2==0)
fprintf(output," ");
if(i%LINE_NUM==0)
fprintf(output,"\n");
}
printf("二进制文件成功转化位十六进制文件");
fclose(input);
fclose(output);
return 0;
}