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);
}
void gr_color(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
gr_current_r = r;
gr_current_g = g;
gr_current_b = b;
gr_current_a = a;
}
void gr_clear()
{
if (gr_current_r == gr_current_g &&
gr_current_r == gr_current_b) {
memset(gr_draw->data, gr_current_r, gr_draw->height * gr_draw->row_bytes);
} else {
int x, y;
unsigned char* px = gr_draw->data;
for (y = 0; y < gr_draw->height; ++y) {
for (x = 0; x < gr_draw->width; ++x) {
*px++ = gr_current_r;
*px++ = gr_current_g;
*px++ = gr_current_b;
px++;
}
px += gr_draw->row_bytes - (gr_draw->width * gr_draw->pixel_bytes);
}
}
}
void gr_fill(int x1, int y1, int x2, int y2)
{
x1 += overscan_offset_x;
y1 += overscan_offset_y;
x2 += overscan_offset_x;
y2 += overscan_offset_y;
if (outside(x1, y1) || outside(x2-1, y2-1)) return;
unsigned char* p = gr_draw->data + y1 * gr_draw->row_bytes + x1 * gr_draw->pixel_bytes;
if (gr_current_a == 255) {
int x, y;
for (y = y1; y < y2; ++y) {
unsigned char* px = p;
for (x = x1; x < x2; ++x) {
*px++ = gr_current_r;
*px++ = gr_current_g;
*px++ = gr_current_b;
*px++ = 255;
}
p += gr_draw->row_bytes;
}
} else if (gr_current_a > 0) {
int x, y;
for (y = y1; y < y2; ++y) {
unsigned char* px = p;
for (x = x1; x < x2; ++x) {
*px = (*px * (255-gr_current_a) + gr_current_r * gr_current_a) / 255;
++px;
*px = (*px * (255-gr_current_a) + gr_current_g * gr_current_a) / 255;
++px;
*px = (*px * (255-gr_current_a) + gr_current_b * gr_current_a) / 255;
++px;
*px++ = 255;
}
p += gr_draw->row_bytes;
}
}
}
void gr_blit(GRSurface* source, int sx, int sy, int w, int h, int dx, int dy) {
if (source == NULL) return;
if (gr_draw->pixel_bytes != source->pixel_bytes) {
printf("gr_blit: source has wrong format\n");
return;
}
dx += overscan_offset_x;
dy += overscan_offset_y;
if (outside(dx, dy) || outside(dx+w-1, dy+h-1)) return;
unsigned char* src_p = source->data + sy*source->row_bytes + sx*source->pixel_bytes;
unsigned char* dst_p = gr_draw->data + dy*gr_draw->row_bytes + dx*gr_draw->pixel_bytes;
int i;
int j;
for (i = 0; i < h; ++i) {
if (source->pixel_bytes == 4 && source->alpha ==1) {
unsigned char *p0 = src_p;
unsigned char *p1 = dst_p;
unsigned char alpha = 255;
for (j = 0; j < w; j++) {
alpha = *(p0+3);
*p1 = (*p1 * (255-alpha) + *p0++ * alpha) / 255;
++p1;
*p1 = (*p1 * (255-alpha) + *p0++ * alpha) / 255;
++p1;
*p1 = (*p1 * (255-alpha) + *p0++ * alpha) / 255;
++p1;
*p1++ = 255;
++p0;
}
} else {
memcpy(dst_p, src_p, w * source->pixel_bytes);
}
src_p += source->row_bytes;
dst_p += gr_draw->row_bytes;
}
}
unsigned int gr_get_width(GRSurface* surface) {
if (surface == NULL) {
return 0;
}
return surface->width;
}
unsigned int gr_get_height(GRSurface* surface) {
if (surface == NULL) {
return 0;
}
return surface->height;
}
static void gr_init_font(void)
{
unsigned i, n, d;
void** font_data;
int bmp, pos;
unsigned char *in, data;
unsigned char *width, *height;
gr_font = calloc(sizeof(*gr_font), 1);
font_data = (void**)malloc(font.count * sizeof(void*));
width = malloc(font.count);
height = malloc(font.count);
for(n = 0; n < font.count; n++) {
if (n<95) {
font_data[n] = malloc(font.ewidth*font.eheight);
memset(font_data[n], 0, font.ewidth*font.eheight);
width[n] = font.ewidth;
height[n] = font.eheight;
}
else {
font_data[n] = malloc(font.cwidth*font.cheight);
memset(font_data[n], 0, font.cwidth * font.cheight);
width[n] = font.cwidth;
height[n] = font.cheight;
}
}
d = 0;
in = font.rundata;
while((data = *in++)) {
n = data & 0x7f;
for(i = 0; i < n; i++, d++) {
if (d<95*font.ewidth*font.eheight) {
bmp = d/(font.ewidth*font.eheight);
pos = d%(font.ewidth*font.eheight);
}
else {
bmp = (d-95*font.ewidth*font.eheight)/(font.cwidth*font.cheight)+95;
pos = (d-95*font.ewidth*font.eheight)%(font.cwidth*font.cheight);
}
((unsigned char*)(font_data[bmp]))[pos] = (data & 0x80) ? 0xff : 0;
}
}
gr_font->texture = malloc(sizeof(GRSurface));
gr_font->texture->width = font.ewidth;
gr_font->texture->height = font.eheight;
gr_font->texture->row_bytes = font.cwidth;
gr_font->texture->pixel_bytes = 1;
gr_font->count = font.count;
gr_font->unicodemap = font.unicodemap;
gr_font->cwidth = width;
gr_font->cheight = height;
gr_font->fontdata = font_data;
gr_font->ascent = font.cheight;
}
#if 0
// Exercises many of the gr_*() functions; useful for testing.
static void gr_test() {
GRSurface** images;
int frames;
int result = res_create_multi_surface("icon_installing", &frames, &images);
if (result < 0) {
printf("create surface %d\n", result);
gr_exit();
return;
}
time_t start = time(NULL);
int x;
for (x = 0; x <= 1200; ++x) {
if (x < 400) {
gr_color(0, 0, 0, 255);
} else {
gr_color(0, (x-400)%128, 0, 255);
}
gr_clear();
gr_color(255, 0, 0, 255);
gr_surface frame = images[x%frames];
gr_blit(frame, 0, 0, frame->width, frame->height, x, 0);
gr_color(255, 0, 0, 128);
gr_fill(400, 150, 600, 350);
gr_color(255, 255, 255, 255);
gr_text(500, 225, "hello, world!", 0);
gr_color(255, 255, 0, 128);
gr_text(300+x, 275, "pack my box with five dozen liquor jugs", 1);
gr_color(0, 0, 255, 128);
gr_fill(gr_draw->width - 200 - x, 300, gr_draw->width - x, 500);
gr_draw = gr_backend->flip(gr_backend);
}
printf("getting end time\n");
time_t end = time(NULL);
printf("got end time\n");
printf("start %ld end %ld\n", (long)start, (long)end);
if (end > start) {
printf("%.2f fps\n", ((double)x) / (end-start));
}
}
#endif
void gr_flip() {
gr_draw = gr_backend->flip(gr_backend);
}
int gr_init(void)
{
gr_init_font();
gr_vt_fd = open("/dev/tty0", O_RDWR | O_SYNC);
if (gr_vt_fd < 0) {
// This is non-fatal; post-Cupcake kernels don't have tty0.
perror("can't open /dev/tty0");
} else if (ioctl(gr_vt_fd, KDSETMODE, (void*) KD_GRAPHICS)) {
// However, if we do open tty0, we expect the ioctl to work.
perror("failed KDSETMODE to KD_GRAPHICS on tty0");
gr_exit();
return -1;
}
gr_backend = open_adf();
if (gr_backend) {
gr_draw = gr_backend->init(gr_backend);
if (!gr_draw) {
gr_backend->exit(gr_backend);
}
}
if (!gr_draw) {
gr_backend = open_fbdev();
gr_draw = gr_backend->init(gr_backend);
if (gr_draw == NULL) {
return -1;
}
}
overscan_offset_x = gr_draw->width * overscan_percent / 100;
overscan_offset_y = gr_draw->height * overscan_percent / 100;
gr_flip();
gr_flip();
return 0;
}
void gr_exit(void)
{
gr_backend->exit(gr_backend);
ioctl(gr_vt_fd, KDSETMODE, (void*) KD_TEXT);
close(gr_vt_fd);
gr_vt_fd = -1;
}
int gr_fb_width(void)
{
return gr_draw->width - 2*overscan_offset_x;
}
int gr_fb_height(void)
{
return gr_draw->height - 2*overscan_offset_y;
}
void gr_fb_blank(bool blank)
{
gr_backend->blank(gr_backend, blank);
}
3.4 minui/Android.mk中选择graphics_cn.c编译,使用宏控制:
ifeq ($(TARGET_RECOVERY_SUPPORT_CHINESE_FONT), true) LOCAL_SRC_FILES += graphics_cn.c else LOCAL_SRC_FILES += graphics.c endif
四. 至此汉化完成,我们定义TARGET_RECOVERY_SUPPORT_CHINESE_FONT即可,编译出来的界面即为中文界面,若遇到其他问题,相应的解决即可。
recovery 界面汉化过程详解的更多相关文章
- DevExpress控件汉化教程详解
所有Developer Express .NET产品都有本地化资源,比如按钮属性,控件属性描述,菜单项,确认和错误的信息等等,所有这些资源字符串可以很容易地被翻译成各种语言. 先看下面汉化前后的图片: ...
- BabyLinux制作过程详解
转:http://www.360doc.com/content/05/0915/14/1429_12641.shtml BabyLinux制作过程详解 作者:GuCuiwen email:win2li ...
- Linux启动过程详解(inittab、rc.sysinit、rcX.d、rc.local)
启动第一步--加载BIOS 当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关信息.设备启动顺序信息.硬 ...
- Hadoop Mapreduce分区、分组、二次排序过程详解[转]
原文地址:Hadoop Mapreduce分区.分组.二次排序过程详解[转]作者: 徐海蛟 教学用途 1.MapReduce中数据流动 (1)最简单的过程: map - reduce (2) ...
- Android Recovery的汉化 显示中文
Android Recovery的汉化 显示中文,有需要的朋友可以参考下. 首先下载开源的recovery源码,地址为https://github.com/xiaolu/android_bootabl ...
- mysql中SQL执行过程详解与用于预处理语句的SQL语法
mysql中SQL执行过程详解 客户端发送一条查询给服务器: 服务器先检查查询缓存,如果命中了缓存,则立刻返回存储在缓存中的结果.否则进入下一阶段. 服务器段进行SQL解析.预处理,在优化器生成对应的 ...
- Mysql加锁过程详解(5)-innodb 多版本并发控制原理详解
Mysql加锁过程详解(1)-基本知识 Mysql加锁过程详解(2)-关于mysql 幻读理解 Mysql加锁过程详解(3)-关于mysql 幻读理解 Mysql加锁过程详解(4)-select fo ...
- Mysql加锁过程详解(6)-数据库隔离级别(2)-通过例子理解事务的4种隔离级别
Mysql加锁过程详解(1)-基本知识 Mysql加锁过程详解(2)-关于mysql 幻读理解 Mysql加锁过程详解(3)-关于mysql 幻读理解 Mysql加锁过程详解(4)-select fo ...
- fabric网络环境启动过程详解
这篇文章对fabric的网络环境启动过程进行讲解,也就是我们上节讲到的启动测试fabric网络环境时运行network_setup.sh这个文件的执行流程 fabric网络环境启动过程详解 上一节我们 ...
随机推荐
- RabbitMQ集群简介
一个RabbitMQ消息代理是一个由一个或多个Erlang节点组成的逻辑组,其中的每个节点都共享users, virtual hosts, queues, exchanges, bindings, a ...
- shiro 获取请求头中的 rememberMe
前言: 上一篇提到了, 将 sessionId 放到请求头中去, 那rememberMe是否也可以放到请求头中去呢. 其实不管是sessionId还是rememberMe, shiro都会默认往coo ...
- DHCP服务器的搭建
dhcp笔记整理:http://services.linuxpanda.tech/DHCP/index.html 1 dhcp简介 DHCP原理 动态主机配置协议(Dynamic Host Confi ...
- 我们来说一说TCP神奇的40ms
本文由云+社区发表 TCP是一个复杂的协议,每个机制在带来优势的同时也会引入其他的问题. Nagel算法和delay ack机制是减少发送端和接收端包量的两个机制, 可以有效减少网络包量,避免拥塞.但 ...
- 使用Hexo搭建个人博客的终极资料
一.前言 Hexo 是一个基于 NodeJs 博客框架,可以快速的帮我们搭建一个博客系统,Hexo使用的是Markdown(下文简称MD)解析文章的,在几秒内即可利用靓丽的主体生成静态网页. 推荐使用 ...
- Apollo 9 — adminService 主/灰度版本发布
目录 Controller 层 Service 层 publish 方法 发送 ReleaseMessage 消息 总结 1. Controller 层 主版本发布即点击主版本发布按钮: 具体接口位置 ...
- fiddler抓取https请求(android/ios)
本文转载自:http://blog.csdn.net/songer_xing/article/details/53841401 备注:本人有这样的一个需求,先记录下,以后再进行整理. 在抓包过程中发现 ...
- [转]简单科普私钥、地址、助记词、Keystore的区别
本文转自:https://www.jianshu.com/p/d0a4a44685d3 很多人保管不好自己的虚拟财产,发生丢币的情况,很多都是因为不清楚私钥的概念. 私钥(Private Key) 比 ...
- [android] 利用广播实现ip拨号
广播接收者,broadcast receiver,安卓系统在使用时会产生很多的事件,比如:短信到来,电量低,拨打电话等等 界面布局,线性布局,EditText指定为电话号码,设置属性android:i ...
- 6.7 使用show profile 进行sql分析
1. 查看是否开启 show variables like 'profiling'; 2. 开启功能 set profiling = on 3. 运行sql #写的尽量耗时的sql,利于分析 sele ...