Font Convert Tool

Font Convert Tool is a font conversion utility. It first retrieves the Unicode of characters to be converted from multiple sources, including standard code pages, custom Unicode code tables, supplementary code tables (.txt files), and custom .cst files. The tool then extracts the vector data of corresponding characters from font files (e.g., .ttf, .ttc) based on these Unicode codes. Next, it converts the vector data into bitmap images and generates output files in .bin format. This process accomplishes a complete workflow from character selection to bitmap generation.

File Preparation

The required files for the Font Convert Tool are shown in the figure below:

../../_images/Import_Files.png

Input Files for Font Convert Tool

  • Codepage

    Standard codepages stored in the CodePage folder, commonly used files include CP936 for Chinese, CP20127 for ASCII, CP1252 for Western European languages on Windows, etc.

  • map.txt File

    A Font Tool custom supplementary Unicode codepage for specifying Unicode characters not included in the Codepage but intended for conversion, represented as hexadecimal numbers starting with 0x, as shown in the figure below:

../../_images/Map.png

Example Map File

  • cst File

    A Font Tool custom Unicode codepage that stores a collection of converted Codepage, map.txt, customerVals (configured in FontConfig.json), and other codepages.

  • *.ttf, *.ttc Files

    Font files stored in the Font folder.

  • FontConfig.json

    A configuration file for the Font Convert Tool to set conversion parameters, detailed as follows:

    JSON File Description

    Parameter Name

    Description

    codePages

    Path to Codepage. Multiple codepages are separated by ,.

    cstPaths

    Paths to Unicode codepage files. Multiple cst files are separated by ,.

    mappingPaths

    Supplementary Unicode codepages. Multiple map.txt files are separated by ,.

    customerVals

    User-defined continuous Unicode characters. Multiple groups are separated by ,.

    firstVal

    Starting Unicode value for customerVals, in hexadecimal starting with 0x.

    range

    Number of customerVals characters, in hexadecimal starting with 0x.

    fontSet

    Configurations for the font to be converted.

    bold

    Whether to bold the converted characters.

    true: bold

    false: not bold

    italic

    Whether to italicize the converted characters.

    true: italic

    false: not italic

    scanMode

    Storage method for converted character data.

    H: saved row-by-row

    V: saved column-by-column

    fontSize

    Size of converted characters.

    font

    Font file for conversion.

    renderMode

    Bit depth used for representing each pixel in the converted character bitmap with valid values of 1, 2, 4, 8.

    indexMethod

    Indexing method for the index block of the output bin file.

    0: address indexing

    1: offset indexing

    crop

    Whether to save only valid datas

    0: save all datas

    1: save only valid datas

Note

  1. codePages, cstPaths, customerVals, mappingPaths should list the Unicode codes to be converted, with duplicates resulting in a union of codes.

  2. cstPaths, mappingPaths need extensions, while codePages do not.

  3. Crop mode is currently effective only with address indexing (indexMethod = 0).

  • setting.ini A customization configuration file for the Font Convert Tool with parameters described as follows:

    Setting Description

    Parameter Name

    Description

    TransformAlgrithm

    Conversion adjustment algorithm currently supports gamma transformation

    An empty TransformAlgorithm parameter indicates that no transformation is performed.

    gamma

    gamma transformation value

    > 1 increases brightness

    < 1 decreases brightness

    = 1 means no transformation

    rotate

    Whether to rotate the character

    0: no rotation

    1: 90 degrees clockwise

    2: 90 degrees counterclockwise

    3: 180 degrees rotation

Operation Process

The Font Tool operation process is shown in the following figure:

../../_images/Font_Convertion_Process.png

Font Tool Operation Process

Note

Conversion Command: fontDictionary.exe [Path to FontConfig.json]

Output Files

Executing the conversion command generates two files in the Tool folder: *_font.bin and *_out.cst.

*_font.bin

*_font.bin is the bitmap file of the converted characters, intended for download to flash.

The file content consists of: Header + Index Block + Data Block. Illustrated below:

../../_images/Font_Bin_Structure.png

Font Bin Structure

Font Header

The structure of Font Header is shown below:

../../_images/Font_Head.png

Font Header Structure

The Font Header description is shown in the table below:

Font Header Description

Parameter Name

Description

Length

Bytes of Font Header

File Flag

Current bin file type

1 indicates a font data file.

Version

Version number

Font Size

Font size

Render Mode

Bit depth per pixel in converted character bitmap. Valid values are 1, 2, 4, 8.

Bold

Bold status of converted characters.

0: not bold

1: bold

Italic

Italic status of converted characters.

0: not italic

1: italic

Scan Mode

Character data storage method post-conversion.

0: row-by-row

1: column-by-column

Index Method

Indexing method for output bin file index block.

0: address index

1: offset index

Font Name Length

Bytes of font name

Font Name

Font Name

Index Block Structure

The structure of Index Block is shown below:

../../_images/Index_Block.png

Index Block Structure

Using an Index Buffer as an example:

  • Address Indexing

    This indexing stores address information for all characters. Characters not included in the conversion range are set to 0xFFFF (crop = 0) or 0xFFFFFFFF (crop = 1). The address for the Unicode character can be found by looking up the index table with the Unicode value.

    • crop = 0

      Each character occupies 2 Bytes in the data block's Index, with the index block size as \((0xFFFF + 1) * 2 = 128 KB\). For a character with Unicode n, the data address is \(Index Buffer[n*2] * (⌈fontSize / 8 ⌉ * fontSize * renderMode + 4)\), as referenced in the Data Block Structure.

    • crop = 1

      Each character occupies 4 Bytes in the data block's address, with the index block size as \((0xFFFF + 1) * 4 = 256 KB\). For a character with Unicode n, the data address is Index Buffer[n*4].

  • Offset Indexing (currently does not support crop)

    Assuming the number of characters to be converted is m , the size of the index area would be \(m * 2\) Bytes. The content of the index area consists of the Unicode codes of the characters to be converted, listed in order. For a character with Unicode n, first traverse the index area to check if it is contained. If the character is located at the k-th Byte of the index area, then the data address of the character is \(k / 2 * (⌈fontSize / 8 ⌉ * fontSize * renderMode + 4)\). Refer to the Data Block Structure.

Data Block Structure

The character bitmap data block saves all character bitmap information in the order of Unicode codes included in this conversion. Each saved character's data includes a 4-byte location header and a bitmap data part which is aligned to 8 bits, determined by font settings: \(bytes = ⌈fontSize / 8⌉ * fontSize * renderMode\).

Note

Example: If fontSize = 12 and renderMode = 4, the character's bitmap data size is \(2 * 12 * 4 = 96 Bytes\), with a total data size of \(4 + 96 = 100 Bytes\) per character.

*_out.cst

This file includes all Unicode codes used in this conversion and can serve as an input for future conversions. For instance, in subsequent conversions when only additional special characters are needed, the .cst file from a previous conversion can be referenced by including it in the cstPaths field of the FontConfig.json file, and any additional character Unicode codes can be included in customerVals or mappingPaths for quick configuration of the conversion range.