Use Images and Fonts on System without File System
Build source for incore images and fonts, and load them for your MiniGUI apps.
Table of Contents
Overview
We often need to embed raw data of images and/or fonts into the final executable of a MiniGUI app, for example:
The operating system does not provide support for file system.
You need to protect your digital intellectual properties such as icons.
For such purpose, MiniGUI provides a set of APIs and tools to embed arbitrary data into the final executable.
Note that, in MiniGUI terms, we often call the embedded data as incore data, incore resource, or inner resource.
For a complete sample, please refer to:
https://github.com/VincentWei/mg-samples/tree/master/incore-data
Tools for Generating Incore Data
We provide tools in mg-tools to generate source files for your incore data:
bin2c: a general tool for converting a binary file to a C source file. This tool generates aunsigned chararray for your program.vbf2c: this tool generates aVBFINFOstruct from a MiniGUI VBF font file for your program.upf2c: this tool generates aUPFINFOstruct from a MiniGUI UPF font file for your program. It also generates an external function to return the pointer to the struct instead of exporting a global symbol of the struct name.
To generate an incore source file for a UPF file, you can call upf2c:
This command generates a source file named unifont_160_50.c:
To generate the source file for incore images or RBF fonts, you can use bin2c:
This command generates a large C source file which defines some unsigned char arrays for the PNG files in res/ subdirectory, one array for each file:
The variable name for one file is consisted of the file name and the _png__ prefix and _data suffix.
APIs for Managing Incore Data
For fonts and images, MiniGUI provides basic APIs to load them from incore data:
For fonts, you should load an incore font before using it, generally before creating any main window, and destroy the font before exiting MiniGUI:
For incore images, you can use the basic functions (LoadBitmapFromMem and UnloadBitmap) to load and destroy the BITMAP object. Or you can use the MiniGUI resource manager to manage the objects using the reference count mechanism.
By using the MiniGUI resource manager, you can use the original file name to load a resource from incore resource. If there is an incore resource for a specific file name, the resource manager will load it from the incore resource, otherwise it will try to load it from the file. On the other hand, the resource manager will maintain a reference count for every loaded resource, and really release the object only if the reference count reaches 0. In this way, you can avoid some bugs about object life cycle.
The following sample uses the resource manager to maintain the incore images:
Restrictions
Note that, currently, MiniGUI does not support incore TrueType fonts.
Last updated