FAQ TBarCode DLL / TBarCode Library
How to Encode Chinese Characters in Han Xin Code?
How to Encode Chinese Characters in Han Xin Code?
Han Xin Code provides a special support for encoding Chinese characters with character set GB18030 (using 2 -4 bytes depending on character).
Usage in TBarCode Library:
Using Unicode input:
- Switch the Codepage to GB18030 with BCSetCodePage
- Provide the characters in Unicode format* with BCSetTextW
∗UTF-16 on Windows, UTF-32 on Linux, but no UTF-8 (!) - Unicode input will be converted to GB18030 format for the barcode
Example:
BCSetCodePage(pBarCode, e_CodePage::eCodePage_GB18030); WCHAR unicode[] = L"数"; /*Unicode U+6570*/ BCSetTextW(pBarCode, unicode, wcslen(unicode));
⇒ Barcode will contain the GB18030 Byte sequence CA FD. A barcode reader should read this as 数.
Using GB18030 input:
- Disable Codepage conversion with BCSetEncodingMode (pBC, eEncMode_LowByte or eEncMode_ByteStream)
- Provide the GB18030 characters as Byte sequence with BCSetTextA
- The Bytes are encoded “as is” without any further conversion.
Example:
BCSetEncodingMode(pBarCode, eEncMode_ByteStream);
unsigned char bytes[] = { 0xCA, 0xFD }; /* GB18030 数 CAFD */
BCSetTextA(pBarCode, (LPCSTR) bytes, sizeof(bytes));
⇒ A barcode reader should read this as 数
More resources:
- Unicode table: https://unicode-table.com
- Online Converter: https://r12a.github.io/app-encodings/
- Offline Converter: https://www.microsoft.com/en-ca/download/details.aspx?id=40334
- Android Apps to test Han Xin with Chinese characters: Vintasoft Barcode Scanner (need to enable Han Xin in 2D options first)