网页端的utf8和gb2312 之间关于osd 传参数的乱码问题

(0)HZK16 点阵字库原理及实现

(1)utf8 和 unicode gb2312之间的转换

(2)gb2312 的拓展 gbk 实现了更多的文字编码 像“瞭望塔”的瞭子在gb2312中是没有的

华丽分割线

---------------------------author:pkf

----------------------------------time:2014-03

----------------------------------------qq:1327706646

(0)HZK16 点阵字库原理及实现

  

  HZK16字库是符合GB2312标准的16×16点阵字库,HZK16的GB2312-80支持的汉字有6763个,符号682个. 
  其中一级汉字有 3755个,按声序排列,二级汉字有3008个,按偏旁部首排列. 
  我们在一些应用场合根本用不到这么多汉字字模, 所以在应用时就可以只提取部分字体作为己用.
  HZK16字库里的16×16汉字一共需要256个点来显示, 也就是说需要32个字节才能达到显示一个普通汉字的目的.
  我们知道一个GB2312汉字是由两个字节编码的,范围为0xA1A1~0xFEFE. 
  A1-A9为符号区, B0到F7为汉字区. 每一个区有94个字符(注意:这只是编码的许可范围,不一定都有字型对应,比如符号区就有很多编码空白区域).
  下面以汉字"我"为例, 介绍如何在HZK16文件中找到它对应的32个字节的字模数据.
  前面说到一个汉字占两个字节,这两个中前一个字节为该汉字的区号,后一个字节为该字的位号.
  其中, 每个区记录94个汉字, 位号为该字在该区中的位置. 所以要找到"我"在hzk16库中的位置就必须得到它的区码和位码.
  区码:汉字的第一个字节-0xA0 (因为汉字编码是从0xA0区开始的, 所以文件最前面就是从0xA0区开始, 要算出相对区码)
  位码:汉字的第二个字节-0xA0
  这样我们就可以得到汉字在HZK16中的绝对偏移位置:
      offset=(94*(区码-1)+(位码-1))*32
    
    注解:
     1.区码减1是因为数组是以0为开始而区号位号是以1为开始的   2.(94*(区号-1)+位号-1)是一个汉字字模占用的字节数   3.最后乘以32是因为汉字库文应从该位置起的32字节信息记录该字的字模信息(前面提到一个汉字要有32个字节显示)
我画的图示:
|<---16位,2字节-->|+
○○○○○●○○●○○○○○○○ |    ->    0x04,0x80
○○○○●●●○●○●○○○○○ |    ->    0x0E,0xA0
○●●●●○○○●○○●○○○○ |    ->    0x78,0x90
○○○○●○○○●○○●○○○○ |    ->    0x08,0x90
○○○○●○○○●○○○○●○○ |    ->    0x08,0x84
●●●●●●●●●●●●●●●○ |    ->    0xFF,0xFE
○○○○●○○○●○○○○○○○ |    ->    0x08,0x80
○○○○●○○○●○○●○○○○ |16位->    0x08,0x90
○○○○●○●○●○○●○○○○ |2字节->    0x0A,0x90
○○○○●●○○○●●○○○○○ |    ->    0x0C,0x60
○○○●●○○○○●○○○○○○ |    ->    0x18,0x40
○●●○●○○○●○●○○○○○ |    ->    0x68,0xA0
○○○○●○○●○○●○○○○○ |    ->    0x09,0x20
○○○○●○●○○○○●○●○○ |    ->    0x0A,0x14
○○●○●○○○○○○●○●○○ |    ->    0x28,0x14
○○○●○○○○○○○○●●○○ +    ->    0x10,0x0C

所以,'我'在HZK16 16*16点阵字库的存放的序列为:
一行一行地保存,共16行,每行2个字节, 共32个字节
04 80 0E A0 78 90 08 90 08 84 FF FE 08 80 08 90
0A 90 0C 60 18 40 68 A0 09 20 0A 14 28 14 10 0C
以上排列是横的,用点阵取字模的还有竖的排列,取摸工具在附件里面
    for(k=0; k<16; k++){
        for(j=0; j<2; j++){
            for(i=0; i<8; i++){
                flag = buffer[k*2+j]&key[i];
                printf("%s", flag?"●":"○");
http://www.cnblogs.com/nbsofer/archive/2012/11/01/2749026.html
http://blog.chinaunix.net/uid-24219701-id-3343764.html

(1)utf8 和 unicode gb2312之间的转换


int DeBaiFenStrin2Int(unsigned char *des,unsigned char *src,int size)
{

unsigned char *pSrc = src;
unsigned char *pDes = des;
unsigned char outPut[100]={0};
unsigned char inPut[100];

unsigned char *pOut=outPut;
unsigned char in[10]={0};//in[3];
unsigned char out[4]={0};
memset(in,0,sizeof(in));
memset(outPut,0,sizeof(outPut));
memset(inPut,0,sizeof(inPut));

int bufSize = size;
int i,j;
unsigned char *pOutPut =outPut;
memset(pDes,0,strlen(pDes));
while(bufSize>0)
{
memset(in,0,sizeof(in));
memset(outPut,0,sizeof(outPut));
if(*pSrc=='%'&&(pSrc+9)!=NULL)
{
pSrc++;
in[0]=*(pSrc);
pSrc++;
in[1]=*(pSrc);
pSrc++;
in[2]='';
out[0]=htoi(in);

pSrc++;
in[0]=*(pSrc);
pSrc++;
in[1]=*(pSrc);
pSrc++;
in[2]='';
out[1]=htoi(in);


pSrc++;
in[0]=*(pSrc);
pSrc++;
in[1]=*(pSrc);
pSrc++;
in[2]='';
out[2]=htoi(in);

UTF8ToGB2312(out, pOut, strlen(out));
*pDes=pOut[0];
pDes++;
*pDes=pOut[1];
pDes++;
bufSize-=9;
}
else
{
*pDes=0xa3;
pDes++;
*pDes=(*pSrc)+0x80;
pDes++;
pSrc++;
bufSize--;
}


}

(2)gb2312 的拓展 gbk 实现了更多的文字编码 像“瞭望塔”的瞭子在gb2312中是没有的

瞭望的瞭字 在gb2312中没有编码,在gbk中给出了编码

http://blog.csdn.net/zhouxiaoli521/article/details/5675626

http://ipseeker.cn/tools/pywb.php gb2312查询

http://www.mytju.com/classcode/tools/encode_utf8.asp utf8 查询

http://www.knowsky.com/resource/gb2312tbl.htm

http://www.verydemo.com/demo_c161_i856.html gb2312 查询表unicode gb2312对应表

http://blog.chinaunix.net/uid-20564848-id-73496.html  浅析unicode编码utf8编码和gb2312编码之间的转换关系 

http://blog.csdn.net/zhouxiaoli521/article/details/5675626 gbk 转gb2312

http://bbs.csdn.net/topics/390090950 dsp 端的a[]={'a','b','c'}取数组大小

更新2015-7-15 修复一个小bug

通过utf-8的包容性以及gb2312的定义可知,utf-8在数据表示方面可以占据1~6个字节,而汉字+字符的数据就是1~3个字节之类,出去其他的就可以认为1和3个字节

int DeBaiFenStrin2Int(unsigned char *des,unsigned char *src,int size)
{

unsigned char *pSrc = src;
unsigned char *pDes = des;
unsigned char outPut[100]={0};
unsigned char inPut[100];

unsigned char *pOut=outPut;
unsigned char in[10]={0};//in[3];
unsigned char out[4]={0};
memset(in,0,sizeof(in));
memset(outPut,0,sizeof(outPut));
memset(inPut,0,sizeof(inPut));

int bufSize = size;
int i,j;
unsigned char *pOutPut =outPut;
memset(pDes,0,strlen(pDes));
while(bufSize>0)
{
memset(in,0,sizeof(in));
memset(outPut,0,sizeof(outPut));
if(*pSrc=='%'&&(pSrc+9)!=NULL&&*(pSrc+1)<0x80)//此处稍加判断
{
pSrc++;
in[0]=*(pSrc);
pSrc++;
in[1]=*(pSrc);
pSrc++;
in[2]='';
out[0]=htoi(in);

pSrc++;
in[0]=*(pSrc);
pSrc++;
in[1]=*(pSrc);
pSrc++;
in[2]='';
out[1]=htoi(in);


pSrc++;
in[0]=*(pSrc);
pSrc++;
in[1]=*(pSrc);
pSrc++;
in[2]='';
out[2]=htoi(in);

UTF8ToGB2312(out, pOut, strlen(out));
*pDes=pOut[0];
pDes++;
*pDes=pOut[1];
pDes++;
bufSize-=9;
}
else
{
*pDes=0xa3;
pDes++;
*pDes=(*pSrc)+0x80;
pDes++;
pSrc++;
bufSize--;
}


}

return 0;
}

http://baike.haosou.com/doc/7105043-7328054.html

http://www.360doc.com/content/11/0726/16/7302658_135971963.shtml

48-0

65-A

97-a

原文地址:https://www.cnblogs.com/pengkunfan/p/4474472.html