recovery 界面汉化过程详解

一. 主要是针对recovery汉化,主要汉化对象是界面显示为中文。

 

二. 基于中文的汉化,有两种方式,一种是基于GB2312的编码格式汉化,另外一种是基于unicode编码格式汉化。下面介绍unicode中文汉化。

 

三. 汉化主要需要修改四个文件,汉化步骤:

    3.1 default_device.cpp修改,主界面汉化

             

         增加中文的界面,但是由于是unicode编码,所以在source insight里面显示乱码:

       

 

         这些看似乱码,我们可以这样获取,桌面新建txt文档,使用notepad++工具打开, 选择格式,以UTF-8 无BOM格式编码,里面写入需要显示的汉字,然后保存,然后把新建的txt使用source insight打开即可。

          

          

          

 

    3.2 unicode的中文字库获取,网上可以下载, eg:fontcn30_18x48.h

          

 

    3.3 针对unicode的解析源文件graphics_cn.c

 

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdbool.h>
#include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/types.h> #include <linux/fb.h> #include <linux/kd.h> #include <time.h> #include "fontcn30_18x48.h" //#include "font_10x18.h" #include "minui.h" #include "graphics.h" typedef struct { GRSurface* texture; unsigned offset[97]; void** fontdata; unsigned count; unsigned *unicodemap; unsigned char *cwidth; unsigned char *cheight; unsigned ascent; } GRFont; static GRFont* gr_font = NULL; static minui_backend* gr_backend = NULL; static int overscan_percent = OVERSCAN_PERCENT; static int overscan_offset_x = 0; static int overscan_offset_y = 0; static int gr_vt_fd = -1; const unsigned cw_en = 10; static unsigned char gr_current_r = 255; static unsigned char gr_current_g = 255; static unsigned char gr_current_b = 255; static unsigned char gr_current_a = 255; static GRSurface* gr_draw = NULL; static bool outside(int x, int y) { return x < 0 || x >= gr_draw->width || y < 0 || y >= gr_draw->height; } int getUNICharID(unsigned short unicode, void* pFont) { int i; GRFont *gfont = (GRFont*) pFont; if (!gfont) gfont = gr_font; for (i = 0; i < gfont->count; i++) { if (unicode == gfont->unicodemap[i]) return i; } return -1; } int gr_measure(const char *s) { return 0; } void gr_font_size(int *x, int *y) { *x = gr_font->cwidth[100]; *y = gr_font->cheight[100]; } static void text_blend(unsigned char* src_p, int src_row_bytes, unsigned char* dst_p, int dst_row_bytes, int width, int height) { int i, j; for (j = 0; j < height; ++j) { unsigned char* sx = src_p; unsigned char* px = dst_p; for (i = 0; i < width; ++i) { unsigned char a = *sx++; if (gr_current_a < 255) a = ((int)a * gr_current_a) / 255; if (a == 255) { *px++ = gr_current_r; *px++ = gr_current_g; *px++ = gr_current_b; *px++ = 255; } else if (a > 0) { *px = (*px * (255-a) + gr_current_r * a) / 255; ++px; *px = (*px * (255-a) + gr_current_g * a) / 255; ++px; *px = (*px * (255-a) + gr_current_b * a) / 255; ++px; *px++ = 255; } else { px += 3; *px++ = 255; } } src_p += src_row_bytes; dst_p += dst_row_bytes; } } void gr_text(int x, int y, const char *s, int bold) { GRFont *font = gr_font; unsigned off, n , width, height; unsigned off2; unsigned off3; wchar_t ch; int id; unsigned short unicode; if (!font->texture) return; if (gr_current_a == 0) return; x += overscan_offset_x; y += overscan_offset_y; //printf("--------%X %X %X %X\n", s[0], s[1], s[2], s[3]); while((off = *s++)) { if (off < 0x80) { //ASCII 不处理 } else { if ((off & 0xF0) == 0xE0) { off2 = *s++; off3 = *s++; unicode = (off & 0x1F) << 12; unicode |= (off2 & 0x3F) << 6; unicode |= (off3 & 0x3F); id = getUNICharID(unicode, font); //printf("%X %X %X %X %d\n", off, off2, off3, unicode, id); if (id >= 0) { width = font->cwidth[id]; height = font->cheight[id]; unsigned char* src_p = font->fontdata[id]; unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes; text_blend(src_p, font->texture->row_bytes,dst_p, gr_draw->row_bytes,width, height); x += width; } else { x += width; } } else { x += cw_en; } } } } void gr_texticon(int x, int y, GRSurface* icon) { if (icon == NULL) return; if (icon->pixel_bytes != 1) { printf("gr_texticon: source has wrong format\n"); return; } x += overscan_offset_x; y += overscan_offset_y; if (outside(x, y) || outside(x+icon->width-1, y+icon->height-1)) return; unsigned char* src_p = icon->data; unsigned char* dst_p = gr_draw->data + y*gr_draw->row_bytes + x*gr_draw->pixel_bytes; text_blend(src_p, icon->row_bytes, dst_p, gr_draw->row_bytes, icon->width, icon->height); } 

转载于:https://www.cnblogs.com/codeking100/p/10340617.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值