本帖最后由 lvben5d 于 2019-7-11 13:44 编辑
// 字体起始地址 索引1是 GB2312的偏移地址 索引5 ASCII 大家一起CHECK下?
const u32 FontBaseAdd[] ={
0x3b7d0, 0x0, 0x3bfc0, 0x66c0, 0x3b7c0, 0x3cf80, 0x3c2c0, 0x3d580
};
u32 getFontAddress(u8 gb2312_msb, u8 gb2312_lsb, u8 fontid, u8 FontBytes)
{
uint32_t Address =0;
//15 x 16 GB2312 字符
if(gb2312_msb ==0xA9 && gb2312_lsb >=0xA1)
Address = (282 + (gb2312_lsb - 0xA1 )) * 32 + FontBaseAdd[fontid];
else if (gb2312_msb>=0xA1 && gb2312_msb<=0xA3 && gb2312_lsb>=0xA1)
Address =((gb2312_msb - 0xA1) * 94 + (gb2312_lsb - 0xA1)) * 32+ FontBaseAdd[fontid];
else if(gb2312_msb >=0xB0 && gb2312_msb <= 0xF7 && gb2312_lsb >=0xA1)
Address = ((gb2312_msb - 0xB0) * 94 + (gb2312_lsb - 0xA1)+ 846) * 32+ FontBaseAdd[fontid];
//8x16 | 5x7 | 5x8 ASCII 标准字符 | 粗体
uint32_t AscFontBytes = FontBytes * 8;
//if (fontid > 5) AscFontBytes +=2; 16不等宽字符,数据多2字节
if (fontid >1 && gb2312_msb==0 && gb2312_lsb>=0x20 && gb2312_lsb<= 0x7E)
Address = (gb2312_lsb - 0x20) * AscFontBytes + FontBaseAdd[fontid];
return Address;
}
|