Font

Principle

The Font module contains the C part of the MicroVG implementation, which manages vectorial fonts. This module is composed of two elements:

  • an implementation of Abstraction Layer APIs to manipulate font files,
  • an implementation of Abstraction Layer APIs for MicroVG drawings.

Functional Description

The Font module implements the MicroVG VectorFont framework. It provides Abstraction Layer APIs that consist in opening and decoding a font file and getting the font’s characteristics.

A font file:

  • is either a TTF or an OTF,
  • is identified by the resource name,
  • can be stored as internal resource or external (see External Fonts).

No data is stored in the Java heap. The implementation is responsible for the font’s cycle life: allocation and release.

A font is used to draw a string with a color or with a linear gradient.

Abstraction Layer API

There are two separate Abstraction Layer API header files (see LLVG_FONT: Vector Font):

  • LLVG_FONT_impl.h specifies the Abstraction Layer APIs used to open and retrieve the font’s characteristics.
  • LLVG_PAINTER_impl.h lists the Abstraction Layer APIs called by VectorGraphicsPainter to draw a string with the font.
MicroVG Font Abstraction Layer

Font Abstraction Layer API

  • MicroVG library calls the BSP functions through the header files LLVG_FONT_impl.h and LLVG_PAINTER_impl.h.
  • The C module MicroVG provides a default implementation of LLVG_FONT_impl.h over FreeType.
  • This C module also provides an implementation of LLVG_PAINTER_impl.c that synchronizes the drawing with the MicroUI Graphics Engine and redirects the drawing itself to a third-party drawer.
  • A C module dedicated to a GPU provides an implementation of this drawer. It also redirects the complex layout to a third party C module.
  • The drawer also manages the Gradient.
  • The C module Harfbuzz provides an implementation of complex layout.
  • These files are automatically copied in the BSP project when fetching the C modules during the VEE Port build.

External Memory

Principle

MicroVG does not provide some Low Level API to make the distinction between a font loaded from different kind of memories (internal or external, byte-addressable or not). The Low Level implementation (C Modules MicroVG and FreeType) features the font management from an external memory which is not byte-addressable when the VEE Port provides an implementation of the External Resources Loader.

Configuration File

A Vector Font file is a simple resource. To specify this resource as an external resource, the font file path must be listed in a .externresources.list file in addition with the .resources.list file (see Application Resources).

Process

The following steps describe how to setup the loading of an external resource from the application:

  1. Add the font to the application project resources (typically in the source folder src/main/resources and in the package fonts).
  2. Create / open the configuration files (e.g. application.resources.list and application.externresources.list).
  3. In both files, add the relative path of the font (e.g. /fonts/myFont.ttf).
  4. Build the application: the processed external resources are copied into the external resources folder ([application_output_folder]/externalResources).
  5. Deploy the external resources to the external memory (SDCard, flash, etc.) of the device.
  6. (optional) Configure the External Resources Loader to load from this source.
  7. Build the application and run it on the device.
  8. The application loads the external resource using ej.microvg.VectorFont.loadFont().
  9. FreeType (C Modules) recognizes this resource as external resource; it configures itself to manage this resource differently than an internal resource (see Library: FreeType to have more details).
  10. The application can use the font.

Simulation

The Simulator automatically manages the external resources like internal resources. All images listed in *.externresources.list files are copied in the external resources folder, and this folder is added to the Simulator’s classpath.

Use

The MicroVG Font APIs are available in the class ej.microvg. VectorFont.