Android的Recovery快速汉化

来源:互联网 发布:广联达算量软件视频 编辑:程序博客网 时间:2024/05/16 15:45
1.git clone https://github.com/xiaolu/cwm_recovery_cn
2.拷到cwm_recovery_cn/minui/font_10x18_cn.h到yourandroidsource/bootable/recovery/minui/中 (此文件为汉字字库文件)
3.修改yourandroidsource/bootable/recovery/minui/graphics.c
    1).添加全局变量const unsigned cw_en = 10;
    2).添加getGBCharID和getUNICharID两个函数
int getGBCharID(unsigned c1, unsigned c2)
{
    if (c1 >= 0xB0 && c1 <=0xF7 && c2>=0xA1 && c2<=0xFE)
    {
        return (c1-0xB0)*94+c2-0xA1;
    }
    return -1;
}


int getUNICharID(unsigned short unicode)
{
    int i;
    for (i = 0; i < UNICODE_NUM; i++) {
        if (unicode == unicodemap[i]) return i;
    }
    return -1;
}

    3).修改gr_text函数如下:
int gr_text(int x, int y, const char *s)
{
    GGLContext *gl = gr_context;
    GRFont *font = gr_font;
    unsigned off;
    unsigned off2;
    unsigned off3;
    int id;
    unsigned short unicode;


    y -= font->ascent;


    gl->bindTexture(gl, &font->texture);
    gl->texEnvi(gl, GGL_TEXTURE_ENV, GGL_TEXTURE_ENV_MODE, GGL_REPLACE);
    gl->texGeni(gl, GGL_S, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
    gl->texGeni(gl, GGL_T, GGL_TEXTURE_GEN_MODE, GGL_ONE_TO_ONE);
    gl->enable(gl, GGL_TEXTURE_2D);


    while((off = *s++)) {
        if (off < 0x80)
        {
            off -= 32;
            if (off < 96) {
                if ((x + cw_en) >= gr_fb_width()) return x;
                gl->texCoord2i(gl, (off * font->cwidth) - x, 0 - y);
                gl->recti(gl, x, y, x + cw_en, y + font->cheight);
            }
            x += cw_en;
        }
        else
        {
            if ((off & 0xF0) == 0xE0)
            {
                off2 = *s++;
                off3 = *s++;
                unicode = (off & 0x1F) << 12;
                unicode |= (off2 & 0x3F) << 6;
                unicode |= (off3 & 0x3F);
                id = getUNICharID(unicode);
                //LOGI("%X %X %X  %X  %d", off, off2, off3, unicode, id);
                if (id >= 0) {
                    if ((x + font->cwidth) >= gr_fb_width()) return x;
                    gl->texCoord2i(gl, ((id % 96) * font->cwidth) - x, (id / 96 + 1) * font->cheight - y);
                    gl->recti(gl, x, y, x + font->cwidth, y + font->cheight);
                    x += font->cwidth;
                } else {
                    x += font->cwidth;
                }
            } else {
                x += cw_en;
            }
        }
    }


    return x;
}

4.找一个yourandroidsource/bootable/recovery/recovery.c中的ui_print,填上"你好世界",我这里选择wipe_data()一个ui_print!下图是汉化结果截图:


剩下的就是英译汉的工作了,根据英文和程序的意思状英文译为汉语!


参考文档同《Android的Recovery中font_10x10.h字库文件制作
原创粉丝点击