<span style="font-family: Arial, Helvetica, sans-serif;">网上已经很多开源的实现方式支持4.4的中文显示, 之前也修改过4.4的中文, 切到5.0发现需要修改。 修改的前提是得懂两个地方:</span>
1: 中文的头文件是如何生成和实现显示到屏幕点击打开链接的
头文件的生成需要两部:
1: 从 TTF 文件导出文字图片 (可以查看生成的图片显示的内容, 每行一个字符的竖直排列)
2: 从图片生成头文件
推荐看下
XIAOLU, 读一下 fontcn.py 文件基本上就了解了如何生成 中文头文件的。
2: 4.4 和 5.0 UI显示部分的区别
4.4以及之前的Recovery都是UI显示都是在 通过一个叫 pixelflinger 的中间件然后往FB上输出内容的。
5.0之后弃用了pixelflinger, 直接往FB上输出内容。
所以只需要针对之前的gr_text 做相应的修改就可以了。(其余的部分网上已经有代码了)
void gr_text(int x, int y, const char *s, int bold)
{
GRFont *gfont = gr_font;
unsigned off, width, height, n;
wchar_t ch;
//if (!font->texture) return;
if (gr_current_a == 0) return;
//bold = bold && (font->texture->height != font->cheight);
x += overscan_offset_x;
y += overscan_offset_y;
while(*s) {
if(*((unsigned char*)(s)) < 0x20) {
s++;
continue;
}
off = getCharID(s);
n = utf8_mbtowc(&ch, s, strlen(s));
if(n <= 0){
break;
}
s += n;
if(off<95){
width = font.ewidth;
height = font.eheight;
}else{
width = font.cwidth;
height = font.cheight;
}
unsigned char* src_p = gfont->fontdata[off];
unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes;
text_blend(src_p, width, dst_p, gr_draw->row_bytes, width, height);
x += width;
}
}