Symbian平台编码问题

Symbian应用中文名及日文显示
本文介绍如何将Symbian应用程序名称改为中文,并提供了解决Nokia7610手机上显示Shift-JIS编码日文字符串的方法。包括资源文件修改步骤和编码转换的实现。
 自己在开发时遇到的一些问题:

1. 
Symbian应用程序改为中文名称

    • 修改资源文件xxx_caption.rss:
        Code:
#include “xxx.loc”
RESOURCE CAPTION_DATA
{
    caption 
= qtn_app_caption_string;
    shortcaption 
= qtn_app_short_caption_string;
}


    打开xxx.loc 用记事本或UltraEdit转成UTF-8编码
        Code:
CHARACTER_SET UTF8    //必须加这行

#define qtn_app_caption_string “程序中文名”
#define qtn_app_short_caption_string “显示名”

2
Nokia 7610中文机上显示Shift-JIS编码的日文串

   
Symbian平台以Unicode编码,可以表示、显示所有字符,只需将本地编码转为Unicode即可。
   •
因为中文机上没有日文字库,所以不能用类CcnvCharacterSetConverter提供的方法
     (但
可实现GBK -> Unicode)
    Code:    
CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
converter
->PrepareToConvertToOrFromL(KCharacterSetIdentifierShiftJis, CEikonEnv::Static()->FsSession());
/***************************************************
*上一行会异常退出,因目标平台没有SJIS字库
*但可以实现GBK -> Unicode,只需将KcharacterSetIdentifierShiftJis
*改为KCharacterSetIdentifierGbk
***************************************************/
TInt state 
= CCnvCharacterSetConverter::KStateDefault;
……
TInt ctu 
= converter->ConvertToUnicode(bufPtr, srcPtr, state);

在网上找了一个实现SJISUnicode转换的函数

    Code:
#include "cp.h"

#define is_zen(c) 
        ((0x81 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0x9f) 
        || (0xe0 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xfc))
#define is_han(c) 
        ((0xa0 <= ((unsigned char) (c)) && ((unsigned char) (c)) <= 0xdf))

s32_t skip_bytes(char c)
{
  if(is_zen(c)) {
    return 2;
  } else if (is_han(c)) {
    return 1;
  }
  return 0;
}

s32_t jis2utf8(char **srcbuf, s32_t *srclen, char **outbuf, s32_t *outlen) {
  unsigned char *dst;
  unsigned char *src;
  unsigned short utf8code;
  int sjiscode;
  s32_t  len;
  unsigned char *to2;

  if (! (srcbuf && srclen && outbuf && outlen))
    return 0;

  src = (unsigned char *)*srcbuf;
  dst = to2 = (u8_t*)malloc(*outlen);
  while (*src && ((dst - to2) < (*outlen - 4))) {
    len = skip_bytes(*src);
    if ( len == 2 ) {
      sjiscode = (int)(*src++ & 0xff);
      sjiscode = (int)((sjiscode << 8)|(*src++ & 0xff));
    } else {
      sjiscode = (int)(*src++ & 0xff);
    }

 utf8code = cp[sjiscode];// convert sjis code to utf8 (cp[] is conversion table array) 

    if ( utf8code <= 0x7f ) {
      *dst++ = (char)(utf8code & 0xff);
    }
   else if ( utf8code <= 0x7ff ){
      *dst++ = (char)( 0xc0 | ((utf8code >> 6) & 0xff));
      *dst++ = (char)( 0x80 | ( utf8code & 0x3f ));
    } else {
      *dst++ = (char)( 0xe0 | ((utf8code >> 12) & 0x0f));
      *dst++ = (char)( 0x80 | ((utf8code >> 6)  & 0x3f));
      *dst++ = (char)( 0x80 | (utf8code & 0x3f));
    }

  }
  *dst++='';
  memcpy(*outbuf,to2,*outlen);
  free(to2);
  return strlen(*outbuf);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值