高通字库
版本 V1.0 · 更新于 2026-05-23

2.3 多国语言编码范围

GT30L24A3W

GT30L24A3W 芯片支持的 UTF-8 到 UTF-16 编码转换参考

UTF-8 转 UTF-16 编码函数

高通字库芯片内部使用 UTF-16 编码存储字符。以下函数实现 UTF-8 输入到 UTF-16 的转换, 支持 1/2/3 字节 UTF-8 编码。

utf8_to_utf16.c
/*
  功能:  UTF-8编码转UTF-16编码
  pUTF8: UTF-8编码数据
  pUTF16:UTF-16编码数据
  return:UTF-16字符的字节长度
*/
unsigned char UTF8toUTF16(unsigned char *pUTF8, unsigned short *pUTF16)
{
  unsigned char bytes[3];
  unsigned short unicode16;

  bytes[0] = *pUTF8++;
  if (bytes[0] < 0x80) {
    *pUTF16 = bytes[0];
    return 1;
  }

  bytes[1] = *pUTF8++;
  if (bytes[0] >= 0xC0 && bytes[0] < 0xE0) {
    // 2字节 UTF-8
    unicode16  = (bytes[0] & 0x1F) << 6;
    unicode16 |= (bytes[1] & 0x3F);
    *pUTF16 = unicode16;
    return 2;
  }

  bytes[2] = *pUTF8++;
  if (bytes[0] >= 0xE0 && bytes[0] < 0xF0) {
    // 3字节 UTF-8
    unicode16  = (bytes[0] & 0x0F) << 12;
    unicode16 |= (bytes[1] & 0x3F) << 6;
    unicode16 |= (bytes[2] & 0x3F);
    *pUTF16 = unicode16;
    return 3;
  }

  return 0;
}

注意事项

  • GT30L24A3W 芯片支持 24 种语言的 Unicode 编码范围
  • 详细的字符集编码范围请参考 2.2 UTF8 转 Unicode
  • 函数已集成在 MindCraft 生成的字库库文件中,可直接调用