Hezhou Air724UG LuatOS-Air lvgl7-font (external font)

How to use the development board to implement the lvgl function of loading external fonts

directory name

Introduction

LVGL API fonts

Material preparation

  1. A set of EVB_Air724UG_A13 development board (other Hezhou supports LuatOS-Air development version is also available), including antenna SIM card, USB cable, and ST7735 screen.
  2. LuatOS-Air development environment: environment construction method

    image.png

step

Here we use lv_font_conv to generate external fonts

Install lv_font_conv

First install nodejs (click here to download the corresponding installation package). I will not introduce it here, just download and install it.

Open cmd and run

npm i lv_font_conv -g

You can install lv_font_conv and
run the lv_font_conv test on our cmd
 

image.png


The above content is displayed, which proves that lv_font_conv is running normally.

Introduction to lv_font_conv command

Commonly used commands:

  • --bpp - Bits per pixel (anti-aliasing)
  • --size - Output font size (pixels)
  • -o--output- output path (file or directory, depending on format)
  • --format - Output format
    • --format dump - Dump glyph images and font information for debugging
    • --format bin- Dump fonts in binary form (as described in the spec )
    • --format lvgl- Dump fonts in LittlevGL format
  • --force-fast-kern-format- Always use the faster kering storage format, but at a cost. If size differences occur, they will be displayed
  • --lcd - Generate bitmaps with 3x horizontal resolution for sub-pixel smoothing
  • --lcd-v - Generate bitmap with 3x vertical resolution for sub-pixel smoothing
  • --use-color-info- Try using glyph color information from the font to create grayscale icons. Since gray tones are simulated through transparency, this will only work well on contrasting backgrounds
  • --lv-include- Only with --format lvgl, to set the alternate pathlvgl.h

Font commands:

  • --font- The path to the font file (ttf/woff/woff2/otf). Can be used multiple times for merging
  • -r--range- a single glyph or range + optional mapping, belonging to a previously declared one --font. Can be used multiple times. example:
    • -r 0x1F450 - Single value, decimal or hexadecimal format
    • -r 0x1F450-0x1F470 - scope
    • -r '0x1F450=>0xF005' - Single glyph with mapping
    • -r '0x1F450-0x1F470=>0xF005' - Range with mapping
    • -r 0x1F450 -r 0x1F451-0x1F470 - 2 ranges
    • -r 0x1F450,0x1F451-0x1F470- Same as above, but defined as single -r
  • --symbols- A list of characters to copy (instead of the number format in -r)
    • --symbols 0123456789., - Extract characters to display numbers
  • --autohint-off - Don't force auto-prompts (the "light" is on by default)
  • --autohint-strong - Use more powerful autosuggestion (will break kerning)

Additional debugging options:

  • --no-compress - Disable built-in RLE compression
  • --no-prefilter - Disable bitmap line filter (XOR), used to improve compression ratio
  • --no-kerning - Remove kerning information to reduce size (not recommended)
  • --full-info - Do not shorten "font_info.json" (including pixel data)

We enter the following command to generate the .bin external font we want.

lv_font_conv --no-compress --format bin --font D:\8910\lvgl\Font-OPPOSans\OPPOSans-B.ttf -o D:\8910\lvgl\myfontd\opposans_b_20.bin --bpp 4 --size 20 -r 0x30-0x39 -r 0x41-0x5A -r 0x61-0x7A

Here, the opposans_b_20.bin module is generated through the OPPOSans-B.ttf font to load the font. Due to some space, only 1-9 numbers AZ and uppercase and lowercase letters are generated.

Font usage

    -- 创建标签
    label = lvgl.label_create(lvgl.scr_act(), nil)
    lvgl.label_set_text(label,"TEST1234") 
    -- 加载外部字体
    local font = lvgl.font_load("/lua/opposans_b_20.bin")
    lvgl.obj_set_style_local_text_font(label, lvgl.LABEL_PART_MAIN, lvgl.STATE_DEFAULT, font)

Test firmware and scripts

LuatOS-Air_V3201_RDA8910.pac
lvgl7-font.7z

display effect

Default font display effect
 

image.png


External font display effect

image.png

Reference documentation

LuatOS-SoC LVGL font

common problem

How to add Chinese characters to the font

The Unicode code is used to add Chinese characters. For example, if you want to add the two characters "Chinese" to the font, you only need to specify the Unicode of this character on the command line. The following naming is based on the above command and adds two "Chinese" characters. character command

lv_font_conv --no-compress --format bin --font D:\8910\lvgl\Font-OPPOSans\OPPOSans-B.ttf -o D:\8910\lvgl\myfontd\opposans_b_20.bin --bpp 4 --size 20 -r 0x30-0x39 -r 0x41-0x5A -r 0x61-0x7A -r 0x4E2D -r 0x6587

Here 0x4E2D is the Unicode code for "中", and 0x6587 is the Unicode code for "文"

Replace the corresponding files in the above script with the following two files to display the following effect
opposans_b_20.bin
widget.lua

undefined

Insufficient permissions error problem

cmd must have administrator rights, and the directory where the .bin file to be generated  and the .ttf font used must have write permissions for the user user
. For example:
 

6972b762-8bc1-4d4e-9a0c-2c869e562fdd.png


The above error occurs and administrator rights are required.

The permissions of the directory where the .bin file to be generated  and the .ttf font used are located are as follows:
 

image.png


If the permissions are insufficient, the following error will be reported:

image.png

Related information and purchase links

Guess you like

Origin blog.csdn.net/l531798151/article/details/132840340