External font display method and system based on LVGL, terminal and medium
By generating a custom .bin font information file and adding parsed .c files to LVGL, the problem that LVGL cannot display Chinese and other non-ASCII characters is solved, and efficient RAM usage and simplified file management are achieved, and multi-level pixel clarity is supported.
Patent Information
- Application Number
- CN202411734056.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-04
AI Technical Summary
In the prior art, the LVGL GUI system framework cannot display Chinese and other non-ASCII characters, and the existing solutions take up too much RAM, complex file management, and cannot achieve 1bpp clarity.
Provide an external font display method based on LVGL. By generating a custom .bin font information file and adding a .c file for parsing in LVGL, it realizes the storage and parsing of .bin font information file and displays the generated text characters.
The non-ASCII character display of the LVGL framework is implemented, which avoids the problem of excessive RAM consumption, simplifies file management, supports multi-level pixel clarity, including 1bpp, and solves the problems of excessive file size and unsightly display.
Smart Images

Figure CN119558271A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of embedded software technology, in particular to an external font display method and system based on LVGL, and also to a corresponding computer terminal and a computer-readable storage medium. Background Art
[0002] There are two main GUI (graphical user interface) solutions used in electronic devices with embedded systems. High-end electronic devices use the Android GUI system framework, while low-end electronic devices use the miniGUI system framework. The Android GUI system framework has a large amount of code and cannot be saved in electronic devices with limited storage space. The miniGUI system framework has outdated functions, the graphics effects are not rich enough, and the code size is still not small enough.
[0003] LVGL (Light and Versatile Graphics Library) is a new GUI system framework with the advantages of small code size and easy UI (user interface) development. It can load the firmware of electronic devices with only 16MB of flash memory. However, the LVGL system framework currently only supports a few English fonts, but not Chinese fonts; therefore, electronic devices that use LVGL as the GUI system framework can only display English and common English characters (i.e., ASCII international standard characters), but cannot display Chinese and common Chinese characters.
[0004] In the prior art, in order to achieve the purpose of displaying Chinese or other characters, the font generation tool .c file of the LVGL official website is usually used. The information and pixel bitmap of the characters in the font are stored in a large array mode, and directly loaded into the RAM, that is, the memory, when the program is running. However, if the font is very large or there are many text symbols in the font, this method of directly loading the .c file can be easily displayed on a device medium with a large RAM space such as a computer, but it is a great waste of RAM space on devices with small RAM space such as microcontrollers, and it may even be unusable. At the same time, because the generation tool of the official website is used, the characters need to be converted to utf-8 encoding first, then enter the official website, and then enter for conversion, and offline conversion is not possible. And it is impossible to change information such as font spacing, baseline, and line spacing, the degree of customization is poor, and the operation is complicated.
[0005] Another existing solution is to use a .bin binary file, save part of the font information to a .c file, then put part of the font information into a .bin file, save it to an external flash storage, and then each .bin file corresponds to a .c file for parsing. Because the information of each font is different and needs to be saved and parsed separately, a font needs two files to be used. There are many files, and it is difficult to manage when there are many fonts. Moreover, due to the binary format processing problem, the .bin file generated by this method has a large file gap when the unicode encoding of the characters is not continuous, which wastes a lot of storage space. Summary of the invention
[0006] In view of the above-mentioned deficiencies in the prior art, the present invention provides an external font display method and system based on LVGL, and also provides a corresponding computer terminal and computer-readable storage medium.
[0007] According to one aspect of the present invention, there is provided an external font display method based on LVGL, comprising:
[0008] Provide one or more customized .bin font information files;
[0009] Add a .c file for parsing in LVGL, and use the .c file to save and parse one or more .bin font information files;
[0010] Based on the parsing result, one or more of the .bin font information files are called in the LVGL to display the generated text characters.
[0011] Preferably, the providing of one or more customized .bin font information files includes:
[0012] Provide a txt text file and vector font file of the text characters to be generated, a .bin font library file name, a font size, and the pixel clarity of the generated text characters; wherein the txt text file is in utf-8 encoding format;
[0013] Open the txt text file with the c language file IO, convert the recognition type of the text characters to be generated stored therein from utf-8 encoding to the corresponding unicode encoding, and save the unicode encoding and the number of characters in a linked list;
[0014] Using the freetype tool library to obtain basic font information of the text characters to be generated in the vector font file, and modifying the basic information of the characters based on the basic font information;
[0015] Select a custom font pixel clarity, obtain the bitmap information of the character, and integrate the bitmap information with the basic font information to obtain the font bitmap information; obtain the font common information required for the font of the text character to be generated; save the number of characters, character unicode encoding, character offset storage location address, character basic information, font bitmap information and font common information in binary into a .bin file through a set arrangement method, and generate a custom .bin font library information file named with the .bin font library file name.
[0016] Preferably, the txt text file providing the text characters to be generated includes:
[0017] Provide a txt text file, input the text of the text characters to be generated directly into the txt text file, and save the txt text file in utf-8 encoding format to obtain the txt text file of the text characters to be generated.
[0018] Preferably, the pixel definition of the user-defined text characters includes: storing information of one pixel in a size of 1, 2, 4 or 8 bits, respectively, to obtain corresponding pixel definitions of 1, 2, 4 or 8 levels.
[0019] Preferably, the font public information includes: the minimum and maximum values of the UTF-8 encoding of the characters, the maximum value of the memory occupied by the character bitmap information, the total number of characters in the font library, the selected pixel definition, the maximum line height required for the characters obtained by parsing the font size, and the character baseline.
[0020] Preferably, the basic character information includes: the step width, character width, character height, x-axis offset pixels and y-axis offset pixels of the next character.
[0021] Preferably, the basic font information of the text character to be generated includes: width, height and offset of the font.
[0022] Preferably, the set arrangement method is used to perform multi-level storage of the number of characters, character encoding, character offset storage position, character font basic information and character font bitmap information, including:
[0023] Define file offsets OFV1, OFV2, and OFV3 to create file hole filling data; where:
[0024] The offset OFV1 is used to free up the first 16 bytes as a file hole for writing font public information, and write character unicode codes from here;
[0025] The offset OFV2 is used to free up the number of characters × 2 bytes as a file hole for storing the character unicode encoding; the character unicode encoding is stored after the font public information, and the character offset storage location address is written from here; the number of characters is accumulated and synchronously obtained when the utf-8 to unicode conversion of the text characters to be generated in the txt text file is saved in the linked list;
[0026] The offset OFV3 is used to free up the number of characters × 4 bytes as a file hole for storing the address of the character offset storage position; the character offset storage position address is stored after each character unicode encoding segment, and the basic information of the character is written from here;
[0027] Repeat and loop the above process until all the required data of the text characters to be generated are filled in;
[0028] After the filling is completed, all the data of the font public information is obtained by calculation, and all the data of the font public information is written into the 16 bytes vacated in the offset OFV1 from the beginning of the file. At this point, the writing of the .bin font library information file is completed.
[0029] Preferably, the adding of a .c file for parsing in LVGL comprises:
[0030] Create a .c file in the LVGL framework, and create a structure of common font information, a structure of basic character information, and a structure containing a file name variable, a data buff, and basic character information required for generating a font of a text character to be generated in the .c file;
[0031] The using of the .c file to save and parse one or more .bin character library information files comprises:
[0032] By means of structure pointers and in conjunction with the arrangement method set in the .bin font information file, the c language file IO is used to extract the font characters to be displayed from the .bin font information file in batches and save them in three structures for parsing.
[0033] Preferably, the algorithm of the arrangement method set in conjunction with the .bin font information file includes:
[0034] Set file offset OFS1=6, which is the location where the number of characters in the font common information is saved, and open the .bin font information file to read the number of characters;
[0035] Open up a heap memory space of m1 = 2 × the number of characters, file offset OFS2 = 16, which is the number of bytes of font public information, open the .bin font information file, and fill 2 × the number of characters bytes of information into the newly opened heap memory space m1 starting from file offset OFS2, that is, fill in the unicode codes of all characters;
[0036] Define i=0, traverse the data in the heap memory space m1 by two bytes and compare them with the required character unicode code to find out whether there is the required character. i+1 is added every time a character is searched. After the required character is found, the required character position is the i-th one among all characters.
[0037] Release the heap memory space m1, set the file offset OFS3 = 16 + 2 × number of characters + i × 4, open the .bin font information file, offset OFS3 bytes to read the character offset storage location address OFS4 of the required character;
[0038] Open the .bin font information file, offset OFS4 bytes, and read the basic character information and font bitmap information of the required character;
[0039] At this point, the coordinated reading of the .bin font information file and the .c file is completed.
[0040] Preferably, based on the parsing result, calling one or more of the .bin font information files in the LVGL to display the generated text characters includes:
[0041] A font creation function of the LVGL architecture is used to create a font name, the font name is bound to the file name of the .bin font information file, and the corresponding font name is called through the character display function of the LVGL architecture to display the corresponding characters.
[0042] According to another aspect of the present invention, there is provided an external font display system based on LVGL, comprising:
[0043] bin file building module, which is used to provide one or more customized .bin font information files;
[0044] c file building module, the module is used to add a .c file for parsing in LVGL, and use the .c file to save and parse one or more .bin font information files;
[0045] A character display module, based on the parsing result, calls one or more of the .bin font information files in the LVGL to display the generated text characters.
[0046] According to a third aspect of the present invention, there is provided a computer terminal comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, can be used to execute any one of the methods described above in the present invention, or to run the system described above in the present invention.
[0047] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can be used to execute any of the methods described above in the present invention, or to run the system described above in the present invention.
[0048] Due to the adoption of the above technical solution, the present invention has at least one of the following beneficial effects compared with the prior art:
[0049] The present invention adopts a custom font file to solve the problem that the LVGL framework itself cannot display characters other than ASCII characters, such as Chinese characters.
[0050] The present invention utilizes a method flow for generating a character library file, which can quickly generate a character library file, is convenient and quick, and solves the problem in the prior art that the file operation required for displaying Chinese or other text characters is complicated and cannot be converted offline.
[0051] The present invention adopts external flash to save .bin font information files, that is, on the computer, the bin file is directly saved in the hard disk, and on the single-chip microcomputer, the bin file 3zcex is usually used to load code and data into the nonvolatile memory (such as flash memory) or other memory of the embedded system, and does not directly occupy the RAM space, thereby solving the problem of excessive RAM occupation by the internal font method of using .c font files in the prior art.
[0052] The present invention adopts a new font binary data storage format and algorithm, which can achieve the goal of multiple .bin font information files only need to be parsed with one .c file, solving the problem in the prior art that one .bin font information file requires one .c file to parse, resulting in a large number of files, complex operations, and troublesome management. At the same time, it also solves the problem of excessive file size caused by file gaps in .bin font information files and the problem of inability to achieve 1bpp clarity. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0054] Figure 1 The figure is a flowchart of an external font display method based on LVGL in one embodiment of the present invention.
[0055] Figure 2 The figure is a schematic diagram of component modules of an external font display system based on LVGL in one embodiment of the present invention.
[0056] Figure 3 It is a schematic diagram of the working content of the bin file construction module in a preferred embodiment of the present invention.
[0057] Figure 4 It is a schematic diagram of the working contents of the c file construction module and the character display module in a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0058] The following is a detailed description of the embodiments of the present invention: This embodiment is implemented on the premise of the technical solution of the present invention, and a detailed implementation method and a specific operation process are given. It should be pointed out that for ordinary technicians in this field, several variations and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.
[0059] In the prior art, the LVGL framework itself is usually unable to display characters other than ASCII characters, such as Chinese. To solve this problem, one solution is to use the font generation tool .c file on the LVGL official website, but this solution has the problem that the operation of generating the required files is complicated and cannot be converted offline; another solution is to use a .bin binary file, save part of the font information to the .c file, and then put part of the font information into the .bin file, and save it to an external flash storage. In this solution, one .bin font information file requires one .c file to parse, resulting in more files, complex operations, and troublesome management. At the same time, there is a problem that the file gap of the .bin font information file usually leads to a large file size and cannot achieve 1bpp clarity.
[0060] In response to the above problems, an embodiment of the present invention provides an external font generation and parsing method based on LVGL, which realizes non-ASCII character display of LVGL, and at the same time overcomes the problems of memory and storage occupation, excessive files, complex operation and management, and inability to achieve 1bpp clarity in the prior art.
[0061] Specifically, Figure 1 As shown, the LVGL-based external font generation and parsing method provided in this embodiment may include the following operations:
[0062] S1, providing one or more customized .bin font information files;
[0063] S2, adding a .c file for parsing in LVGL, and using the .c file to save and parse one or more .bin font information files;
[0064] S3, based on the parsing result, calls one or more .bin font information files in LVGL to display the generated text characters.
[0065] In order to solve the problem that the prior art requires multiple .c files to correspond to multiple .bin files for parsing, and to achieve the effect that all the font information required can be stored in the .bin file, and only one .c file is needed for parsing, in some preferred implementations, the above S1, providing one or more customized .bin font information files, may further include the following operations:
[0066] S11, providing a txt text file and a vector font file of the text characters to be generated, a .bin font library file name, a font size, and a pixel definition of the generated text characters; wherein the txt text file is in utf-8 encoding format;
[0067] S12, opening the txt text file with the c language file IO, converting the recognition type of the text characters to be generated stored therein from utf-8 encoding to the corresponding unicode encoding, and saving the unicode encoding and the number of characters in a linked list;
[0068] S13, using the freetype tool library to obtain basic font information of the text character to be generated in the vector font file, and modifying the basic character information based on the basic font information;
[0069] S14, select the pixel clarity of the customized generated text characters, obtain the font bitmap information through the freetype library, and integrate the bitmap information and the basic font information to obtain the font bitmap information; obtain the font common information required for the font of the text characters to be generated; save the number of characters, character unicode encoding, character offset storage location address, character basic information, font bitmap information and font common information in binary into a .bin file through a set arrangement method, and generate a customized .bin font library information file named with the .bin font library file name.
[0070] In order to solve the problem that the character display position may not be aesthetically pleasing or occupy too much storage space, the spacing and clarity of the characters can be adjusted to make them display aesthetically or sacrifice clarity to limit the storage space they occupy, in some preferred implementations, the above S11, providing a txt text file of the text characters to be generated, can further include the following operations:
[0071] Provide a txt text file, input the text of the text characters to be generated directly into the txt text file, and save the txt text file in utf-8 encoding format to obtain the txt text file of the text characters to be generated.
[0072] In some preferred embodiments, the pixel clarity of the text characters generated in the above S11 may further include: storing the information of a pixel in the size of 1, 2, 4 or 8 bits, and obtaining the corresponding pixel clarity of 1, 2, 4 or 8 levels. The traditional black and white dot matrix font is a 1-bit bitmap, that is, a pixel information is only 0 and 1, and occupies 1 bit to store. The effect is that in the character frame (that is, a character is in an invisible frame), the pixels of the part with information (that is, the part of the word) are pure black, and the pixels without information are pure white. Because the pixel points are actually square when enlarged, obvious jagged edges will appear in oblique strokes such as left and right strokes. The clarity of 2 / 4 / 8 bits is also called grayscale dot matrix font. The information of a pixel is stored by more bits, and can be expressed as multiple gray levels after analysis. That is, multi-level gray levels can be used to achieve anti-aliasing effects in the jagged parts, and the look and feel of the characters is smoother (for example, the characters in the document will have a "semi-transparent" blur at the edges, which is a similar principle). But relatively speaking, the higher the definition, the larger the storage space occupied by a single character, so which one to use depends on the situation. The 8-bit character bitmap obtained by freetype parsing is calculated to the required level of definition by the user and saved in the .bin file. LVGL will parse the bitmap according to different algorithms according to the set 1 / 2 / 4 / 8 (also saved in .bin) for display.
[0073] In some preferred implementations, the above S13, basic font information of the text characters to be generated, may further include: width, height and offset of the font.
[0074] In some preferred implementations, the above S13, basic character information, may further include: the step width, character width, character height, x-axis offset pixels, and y-axis offset pixels of the next character.
[0075] In some preferred implementations, the above S14, font public information, includes: the minimum and maximum values of the character UTF-8 encoding, the maximum value of the memory occupied by the character bitmap information, the total number of characters in the font library, the selected pixel definition, the maximum line height required for the character obtained by parsing the font size, and the character baseline. Among them:
[0076] The minimum and maximum values of the character utf-8 encoding are obtained by getting each character encoding according to the txt file that the user wants to use and then arranging them.
[0077] The maximum value of the memory occupied by the character bitmap information, that is, the maximum value of the memory occupied by the dot matrix data of a character. The size occupied is obtained after parsing a single character to obtain the bitmap through the freetype library. After parsing all characters, the maximum value is saved.
[0078] The total number of characters in the font is obtained by parsing the txt file to obtain the character encoding.
[0079] The selected pixel definition, that is, the number of bits occupied by a pixel, is called the anti-aliasing multiple and is obtained based on the user input, that is, the pixel definition level of 1 / 2 / 4 / 8.
[0080] The maximum line height required by the font is obtained by parsing the corresponding font size through the freetype library.
[0081] The character baseline is obtained by parsing the corresponding font size through the freetype library.
[0082] In order to solve the problem that the font display position may be offset and unsightly, and achieve the effect of beautiful display such as the spacing of custom characters, in some preferred embodiments, the above S13, the correction processing of the basic information of the characters, can further include the following operations: based on the basic information of the font, the part of the basic information of the characters that does not meet the corresponding set threshold is corrected, for example: the part where the font spacing is less than the set threshold and / or the font deviates from the baseline by a distance greater than the set threshold can be corrected, and the y-axis offset pixels can be adjusted to raise the font based on the baseline. The correction process can be effective when adjusting the position when setting the character center in the button control in LVGL, and can also be adjusted in the .c file, i.e., parsing.
[0083] In order to solve the problem of .c file cooperating with parsing .bin, and to achieve the effect that the required data can be searched, parsed, and takes up little space, in some preferred implementations, the arrangement method set in S14 above may further include the following operations:
[0084] The number of characters, character encoding, character offset storage position, character font basic information and character font bitmap information are stored in multiple levels.
[0085] in:
[0086] The compilation method is the structure of the entire .bin file, which is described in detail here.
[0087] A .bin file contains five parts:
[0088] 1. Font Public Information
[0089] 2. Unicode encoding of all characters.
[0090] 3. The file location where the corresponding encoded character data is located
[0091] 4. Basic character information and character bitmap
[0092] However, the data in the file is not written in the above order, but after writing is completed, it presents the above status to cooperate with the .c file to obtain information.
[0093] This arrangement method is designed to solve the problem: because the bitmap size of each character is different, and the characters in the user's txt file are most likely not arranged in the order of unicode encoding and are not continuous (such as the encoding of abc is 0x61, 0x62, 0x63, if the user enters ac or c1a), how to arrange the only information to cooperate with the .c file so that the character information can be found through unicode encoding?
[0094] Here is an example: if we only save the character information and bitmap in character order, then it is very likely that data like (0x62) will appear in the bitmap data of a (0x61). When we parse it, we cannot determine whether it is the letter b encoding to start a new character parsing or a part of the bitmap of a. Moreover, each character bitmap is different, and we don't know when to end the parsing of the character and whether it will affect the next character. There are many problems.
[0095] Therefore, it is important to design a system that cooperates with .bin binary data storage and .c parsing.
[0096] The method for arranging the information of the .bin font file includes:
[0097] First, define three file offsets to create file holes to fill in data.
[0098] 1. OFV1 = 16. The meaning of this offset is to free up the first 16 bytes for subsequent writing of the font public information structure data, and to start writing the character unicode encoding from this beginning.
[0099] 2.OFF2 = number of characters × 2 + 16. The meaning of this offset is to free up the number of characters * 2 bytes to store the unicode encoding of the characters, and store it after the font public information, and write the file offset address of the character information from the beginning. The number of characters is accumulated and obtained synchronously when the utf-8 to unicode conversion is performed after the user input and saved in the linked list, which is a variable. The number of characters * 2 is because the unicode encoding of each character is specified as 2 bytes.
[0100] 3.OFF3 = number of characters × 2 + number of characters × 4 + 16. The meaning of this offset is to free up 4 bytes of space for storing the file offset address of the character information after the unicode encoding segment of each character, and write the basic information of the character from here. The number of characters * 4 is because the address of each character saved in the file is specified to be 4 bytes.
[0101] Repeat and loop the above process until all the required data of the text characters to be generated are filled in;
[0102] After the filling is completed, all the data of the font public information is obtained by calculation, and all the data of the font public information is written into the 16 bytes vacated in the offset OFV1 from the beginning of the file. At this point, the writing of the .bin font library information file is completed.
[0103] The following uses the characters "a0b" in a txt file as an example to illustrate the multi-level saving method:
[0104] 1. Convert it from utf-8 encoding to unicode encoding in the character linked list, sort it according to the unicode encoding as "0ab" and save it in the linked list, and get the number of characters as 3.
[0105] 2. The unicode code of the character '0' is stored after the offset of OFV1 (16) bytes, and OFV1 is incremented by 2.
[0106] 3. After the offset of OFV2 (2×3+16) bytes, the data OFS3 (3×2+3×4+16) is stored, and OFV2 is increased by 4.
[0107] 4. The basic information and bitmap data of the character '0' (hereinafter referred to as information) are stored after the OFV3 (2×3+4×3+16) byte offset, and OFV3 is then added with the number of bytes of the information of the character '0'.
[0108] 5. At this time, OFV1=18, OFV2=26, OFV3=34+the number of bytes of information of the character '0'.
[0109] 6. Repeat and loop the above process until all the required data of the three characters "0ab" are filled in. At this time, only the first 16 bytes are empty.
[0110] 7. After the above process is completed, we also calculate all the data of the font library public information (such as the largest and smallest unicode codes, the number of characters, etc.), and write it from the beginning of the file, which is exactly 16 bytes. At this point, the .bin file is written. In order to solve the problem of parsing .bin files and achieve the effect that one .c file can parse multiple .bin font files, in some preferred implementations, the above S2 can further include the following operations:
[0111] S21, add .c files for parsing in LVGL, including:
[0112] Create a .c file in the LVGL framework, and create a structure of font common information, a structure of character basic information, and a structure containing a file name variable, data buff, and character basic information in the .c file;
[0113] In this step, the file name variable is just a char* (i.e. string) type variable in the structure, but when used, the .bin file is passed in.
[0114] S22, using the .c file to save and parse one or more .bin font information files, including:
[0115] Through the structure pointer method, in conjunction with the algorithm of the arrangement method, the font characters to be displayed are extracted from the .bin font information file in batches using C language file IO, and saved in three structures for parsing.
[0116] In some preferred implementations, further, the above S22, in conjunction with the algorithm of the arrangement method, may further include:
[0117] According to the requirements of LVGL, it is necessary to obtain the character information and bitmap only through the unicode encoding of the required characters. Therefore, the following coordinated parsing is performed in the .c file:
[0118] 1. Set the file offset OFS1 = 6, which is the storage location of the number of characters in the public information, and open the .bin font information file to read the number of characters.
[0119] 2. Open up a heap memory space of m1=2×number of characters, file offset OFS2=16 (number of public information bytes), open the .bin font information file, and fill 2×number of characters bytes of information starting from OFS2 into the newly opened heap memory space m1, that is, fill in the unicode codes of all characters in the font.
[0120] 3. Define i=0, where i is a counting parameter, that is, +1 each time during the loop search, and the character is the number when the loop is exited after finding it; traverse the data in the heap memory space m1 by two bytes and compare it with the required character unicode code to find out whether there is the required character. At the same time, search for a character i+1 each time. After finding the character, the required character position is the i-th one among all characters.
[0121] 4. Release the heap memory space m1, set the file offset OFS3 = 16 (number of public information bytes) + 2 × number of characters + i × 4, open the bin font information file, offset OFS3 bytes to read the offset address OFS4 of the required character.
[0122] 5. Open the .bin font information file, offset OFS4 bytes, and you can read the 5-bit basic information of the required character (i.e. the basic character information) and the subsequent bitmap information (i.e. the font bitmap information) (the bitmap width is the character width in the basic information × the character height × the bit clarity in the public information / 8, which is also known).
[0123] At this point, the coordinated reading of the .bin font information file and the .c file is completed.
[0124] In order to solve the problem of displaying characters in the lvgl framework and achieve the effect of displaying the required characters, in some preferred implementations, the above S3, based on the parsing result, calls one or more .bin font information files in LVGL to display the generated text characters, and may further include the following operations:
[0125] Use the font creation function of the LVGL architecture to create a font name, bind the font name to the file name of the .bin font information file, call the corresponding font name through the character display function of the LVGL architecture, and display the corresponding characters.
[0126] Based on the same inventive concept, an embodiment of the present invention further provides an external font display system based on LVGL.
[0127] Specifically, Figure 2 As shown, the LVGL-based external font display system provided in this embodiment may include the following modules:
[0128] bin file building module, which is used to provide one or more customized .bin font information files;
[0129] c file building module, which is used to add .c files for parsing in LVGL, and use the .c files to save and parse one or more .bin font information files;
[0130] The character display module calls one or more .bin font information files in LVGL based on the parsing results to display the generated text characters.
[0131] The working contents of each functional module of the display system in the above embodiment of the present invention are further described in detail below.
[0132] bin file building module, use the font file generation program to generate the .bin font information file. Figure 3 As shown, the work content of this module includes:
[0133] Step 1, prepare a txt text file, enter the text you want to generate directly into it and save it in utf8 format. And a vector TTF / .OTF font containing the required characters, enter its file name, the .bin file name you want to generate, and enter the optional 1 / 2 / 4 / 8 level of pixel clarity in the font file generation program to generate a custom .bin binary font file.
[0134] Step 2, the following process will be performed in the program: open the txt file with C language file IO, convert the character recognition type saved in it to the corresponding unicode encoding, and save the encoding and the number of characters in the linked list. Use the freetype tool library to find the basic information of the font such as width, height, offset, etc. in the vector TTF / .OTF font. At this time, we can process the font information (such as correcting the font spacing too narrow / the font is too far from the baseline, etc.). After processing the font information, extract the public information required by the font and save it in the .bin file, then use the algorithm to calculate the custom font clarity, process the font bitmap information, and integrate it with the basic information, and then save all the character information in the invented special arrangement (the special arrangement method is saved in multiple levels through the number of characters, character encoding, character offset storage location, character basic information, character bitmap, etc.) in a two-level system to the .bin file.
[0135] The program example of the font file generation program is as follows:
[0136] CodeNode*oneNode=node->next;
[0137] memset(&utf8_Header,0,sizeof(utf8_Header));
[0138] utf8_Header.line_height=face->size->metrics.height / 64;
[0139] utf8_Header.base_line=-face->size->metrics.descender / 64;
[0140] utf8_Header.charSum=codeSum;
[0141] utf8_Header.min=oneNode->code;
[0142]
[0143]
[0144] c file to build the module and add the .c file for parsing in LVGL.
[0145] Character display module, displays characters.
[0146] like Figure 4 As shown, the work contents of the above two modules include:
[0147] Create a .c file, in which you create the common information of the font library, basic information of the characters, and three structures containing the file name, data buff, and basic information of the characters. Through the structure pointer, the information of the characters that need to be displayed is passed in, and the algorithm of the arrangement method is used. The file IO of the C language is used to extract the required information in batches and save it into the structure for parsing.
[0148] Create a desired font name through lvgl's font creation function, bind it to the .bin font library file name, and then call it in lvgl's character display function to display the desired character effect on the device screen.
[0149] It should be noted that the steps in the method provided by the present invention can be implemented by using the corresponding components in the system, and those skilled in the art can refer to the technical solution of the system to implement the step flow of the method, and can also refer to the technical solution of the method to implement the composition of the system, that is, the embodiments in the system and the embodiments in the method can be understood as preferred examples of each other, which will not be elaborated here.
[0150] The technical solution provided by the above embodiment of the present invention is further described in detail below in conjunction with a specific application case.
[0151] This specific application case displays a variety of Chinese characters in the LVGL simulator of Windows Visual Studio, including the following working process:
[0152] 1. Install the LVGL simulator and operating environment of Windows Visual Studio, prepare the required Chinese character txt files and vector text font files, and prepare multiple fonts.
[0153] 2. Import the prepared file into the program and run it to generate the required .bin files of various font sizes and resolutions.
[0154] 3. Add the required parsing .c files in the LVGL framework.
[0155] 4. Create multiple fonts in the LVGL display program, bind the font name to the .bin file by parsing the interface in the file, and the required Chinese characters can be displayed accordingly.
[0156] It can be seen from the above specific application cases that the technical solution provided by the above embodiments of the present invention can successfully display the required Chinese characters, while overcoming the problems of memory and storage occupancy, excessive files, complex operation and management, and inability to achieve 1bpp clarity in the prior art.
[0157] An embodiment of the present invention further provides a computer terminal, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the processor can be used to execute any method of the above-mentioned embodiments of the present invention, or to run any system of the above-mentioned embodiments of the present invention.
[0158] Optionally, the memory is used to store programs; the memory may include volatile memory (English: volatile memory), such as random-access memory (English: random-access memory, abbreviated: RAM), such as static random-access memory (English: static random-access memory, abbreviated: SRAM), double data rate synchronous dynamic random access memory (English: Double Data Rate Synchronous Dynamic Random Access Memory, abbreviated: DDR SDRAM), etc.; the memory may also include non-volatile memory (English: non-volatile memory), such as flash memory (English: flash memory). The memory is used to store computer programs (such as applications, functional modules, etc. that implement the above method), computer instructions, etc., and the above computer programs, computer instructions, etc. can be partitioned and stored in one or more memories. And the above computer programs, computer instructions, data, etc. can be called by the processor.
[0159] The above-mentioned computer programs, computer instructions, etc. may be stored in one or more memories in partitions, and the above-mentioned computer programs, computer instructions, data, etc. may be called by a processor.
[0160] The processor is used to execute the computer program stored in the memory to implement the various steps of the method or various modules of the system involved in the above embodiments. For details, please refer to the relevant descriptions in the above method and system embodiments.
[0161] The processor and the memory may be independent structures or integrated structures. When the processor and the memory are independent structures, the memory and the processor may be coupled and connected via a bus.
[0162] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it can be used to execute any method of the above embodiments of the present invention, or to run any system of the above embodiments of the present invention.
[0163] Among them, computer-readable media include computer storage media and communication media, wherein the communication media include any media that facilitates the transmission of computer programs from one place to another. The storage medium can be any available medium that can be accessed by a general or special-purpose computer. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and the storage medium can be located in an ASIC. In addition, the ASIC can be located in a user device. Of course, the processor and the storage medium can also be present in a communication device as discrete components.
[0164] The LVGL-based external font display method, system, terminal and medium provided by the above-mentioned embodiments of the present invention adopt a customized font file, which solves the problem that the LVGL framework itself cannot display characters other than ASCII characters, such as Chinese characters; the method flow for generating a font file can be used to quickly generate a font file, which is convenient and quick, and solves the problem that the file operation required for displaying Chinese or other text characters in the prior art is complicated and cannot be converted offline; an external flash is used to save the .bin font information file, which solves the problem that the internal font method using the .c font file in the prior art occupies too much RAM; a new font binary data storage format and algorithm is adopted, which can achieve that multiple .bin font information files only need to be parsed with one .c file, which solves the problem that one .bin font information file needs one .c file to parse in the prior art, resulting in more files, complicated operation and troublesome management, and also solves the problem of too large file size caused by the file gap of the .bin font information file and the problem of inability to achieve 1bpp clarity.
[0165] All matters not covered in the above embodiments of the present invention are well known in the art.
[0166] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art may make various modifications or variations within the scope of the claims, which do not affect the essence of the present invention.
Claims
1. A method for displaying external fonts based on LVGL, characterized in that: include: Provide one or more customized .bin font information files; Add a .c file for parsing in LVGL, and use the .c file to save and parse one or more .bin font information files; Based on the parsing result, one or more of the .bin font information files are called in the LVGL to display the generated text characters.
2. The external font display method based on LVGL according to claim 1, characterized in that: The providing of one or more customized .bin font information files includes: Provide a txt text file and vector font file of the text characters to be generated, a .bin font library file name, a font size, and the pixel clarity of the generated text characters; wherein the txt text file is in utf-8 encoding format; Open the txt text file with the c language file IO, convert the recognition type of the text characters to be generated stored therein from utf-8 encoding to the corresponding unicode encoding, and save the unicode encoding and the number of characters in a linked list; Using the freetype tool library to obtain basic font information of the text characters to be generated in the vector font file, and modifying the basic information of the characters based on the basic font information; Select the pixel clarity of the customized generated text characters, obtain the bitmap information of the characters, and integrate the bitmap information and the basic font information to obtain the font bitmap information; obtain the font common information required for the font of the text characters to be generated; save the number of characters, character unicode encoding, character offset storage location address, character basic information, font bitmap information and font common information in binary into a .bin file through a set arrangement method, and generate a customized .bin font library information file named with the .bin font library file name.
3. The external font display method based on LVGL according to claim 2, characterized in that: The txt file providing the text characters to be generated includes: Provide a txt text file, input the text of the text characters to be generated directly into the txt text file, and save the txt text file in utf-8 encoding format to obtain the txt text file of the text characters to be generated; The pixel definition of the generated text characters includes: storing information of one pixel in a size of 1, 2, 4 or 8 bits respectively, and obtaining corresponding pixel definition of 1, 2, 4 or 8 levels; The font public information includes: the minimum and maximum values of the character UTF-8 encoding, the maximum value of the memory occupied by the character bitmap information, the total number of characters in the font library, the selected pixel definition, the maximum line height required for the character obtained by parsing the font size, and the character baseline; The basic character information includes: the step width, character width, character height, x-axis offset pixels and y-axis offset pixels of the next character; The basic font information of the text character to be generated includes: the width, height and offset of the font.
4. The external font display method based on LVGL according to claim 2, characterized in that: The set arrangement method is used to store the number of characters, character encoding, character offset storage position, character font basic information and character font bitmap information in multiple levels, including: Define file offsets OFV1, OFV2, and OFV3 to create file hole filling data; where: The offset OFV1 is used to free up the first 16 bytes as a file hole for writing font public information, and write character unicode codes from here; The offset OFV2 is used to free up the number of characters × 2 bytes as a file hole for storing the character unicode encoding; the character unicode encoding is stored after the font public information, and the character offset storage location address is written from here; the number of characters is accumulated and synchronously obtained when the utf-8 to unicode conversion of the text characters to be generated in the txt text file is saved in the linked list; The offset OFV3 is used to free up the number of characters × 4 bytes as a file hole for storing the address of the character offset storage position; the character offset storage position address is stored after each character unicode encoding segment, and the basic information of the character is written from here; Repeat and loop the above process until all the required data of the text characters to be generated are filled in; After the filling is completed, all the data of the font public information is obtained by calculation, and all the data of the font public information is written into the 16 bytes vacated in the offset OFV1 from the beginning of the file. At this point, the writing of the .bin font library information file is completed.
5. The external font display method based on LVGL according to claim 1, characterized in that: The .c file added for parsing in LVGL includes: Create a .c file in the LVGL framework, and create a structure of common font information, a structure of basic character information, and a structure containing a file name variable, a data buff, and basic character information required for generating a font of a text character to be generated in the .c file; The using of the .c file to save and parse one or more .bin character library information files comprises: By means of structure pointers and in conjunction with the arrangement method set in the .bin font information file, the c language file IO is used to extract the font characters to be displayed from the .bin font information file in batches and save them in three structures for parsing.
6. The external font display method based on LVGL according to claim 5, characterized in that: The algorithm of the arrangement method set in conjunction with the .bin font information file includes: Set file offset OFS1=6, which is the location where the number of characters in the font common information is saved, and open the .bin font information file to read the number of characters; Open up a heap memory space of m1 = 2 × the number of characters, file offset OFS2 = 16, which is the number of bytes of font public information, open the .bin font information file, and fill 2 × the number of characters bytes of information into the newly opened heap memory space m1 starting from file offset OFS2, that is, fill in the unicode codes of all characters; Define i=0, traverse the data in the heap memory space m1 by two bytes and compare them with the required character unicode code to find out whether there is the required character. i+1 is added every time a character is searched. After the required character is found, the required character position is the i-th one among all characters. Release the heap memory space m1, set the file offset OFS3 = 16 + 2 × number of characters + i × 4, open the .bin font information file, offset OFS3 bytes to read the character offset storage location address OFS4 of the required character; Open the .bin font information file, offset OFS4 bytes, and read the basic character information and font bitmap information of the required character; At this point, the coordinated reading of the .bin font information file and the .c file is completed.
7. The external font display method based on LVGL according to claim 1, characterized in that: Based on the parsing result, calling one or more .bin font information files in the LVGL to display the generated text characters includes: A font creation function of the LVGL architecture is used to create a font name, the font name is bound to the file name of the .bin font information file, and the corresponding font name is called through the character display function of the LVGL architecture to display the corresponding characters.
8. An external font display system based on LVGL, characterized in that: include: bin file building module, which is used to provide one or more customized .bin font information files; c file building module, the module is used to add a .c file for parsing in LVGL, and use the .c file to save and parse one or more .bin font information files; A character display module, based on the parsing result, calls one or more of the .bin font information files in the LVGL to display the generated text characters.
9. A computer terminal comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, it can be used to perform the method described in any one of claims 1 to 7, or to run the system described in claim 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it can be used to perform the method described in any one of claims 1 to 7, or to run the system described in claim 8.