π‘ Custom Fonts
Typography is a key element of a professional HMI. Artok allows you to import any TrueType (.ttf) or OpenType (.otf) font and convert it into a high-performance bitmap format optimized for your specific hardware.
βοΈ How Fonts Work in Artokβ
Unlike a PC, an MCU does not scale vector fonts in real-time. Instead, the Asset Packer rasterizes the font into a bitmap at a specific pixel size.
Anti-Aliasing (Smoothing)β
Artok supports multi-level anti-aliasing to ensure text looks crisp even on small, low-resolution screens.
- 1-bit: No smoothing (jagged edges), lowest memory.
- 2-bit: Light smoothing, balanced memory.
- 4-bit: High-quality smoothing (Standard), recommended for most UIs.
π Importing and Subsettingβ
Fonts are often the largest files in an embedded project. To save space, Artok uses Subsettingβonly including the characters you actually need.
| Range Name | Description | Characters |
|---|---|---|
| Basic Latin | Standard English characters. | A-Z, a-z, 0-9, Punctuation |
| Symbols | UI Icons (built-in). | π, βοΈ, π, πΆ |
| Custom Range | User-defined characters. | e.g., "0123456789.:" for a clock |
| CJK | Chinese, Japanese, Korean. | Requires large Flash (Sectors). |
π¨ Visual Styling in Studioβ
In the Inspector Panel, once a font is imported, you can apply these styles to any Label or Button:
- Size: Defined in pixels (e.g., 24px).
- Line Height: Adjust spacing between multiple lines of text.
- Letter Spacing: Fine-tune the horizontal gap between characters (Kerning).
- Decorations: Apply Underline or Strikethrough dynamically.
β‘ Runtime API (Lua)β
You can switch fonts at runtime based on the system state or language selection.
-- Change the font of a label
lbl_header:set_style_text_font("ROBOTO_BOLD_24")
-- Change color and alignment
lbl_header:set_style_text_color(0xFFFFFF)
lbl_header:set_style_text_align(LV_TEXT_ALIGN_CENTER)
-- Use a symbol font for an icon
btn_settings:set_text(SYMBOL_SETTINGS .. " Setup")
A full Latin-1 character set at 24px with 4-bit anti-aliasing can take up ~25 KB of Flash. If you include Chinese (CJK), this can jump to 2-5 MB. Always use Custom Ranges for CJK to only include the specific glyphs used in your UI.
π The Icon Font Trickβ
For the best performance, avoid using small PNG images for icons. Instead, use an Icon Font (like FontAwesome).
- Import the
.ttficon font. - Select the specific icons you need in the Asset Packer.
- Display them in a Label using their Unicode hex code. This uses 10x less memory than images.
π Next Stepsβ
- Asset Packer β See how fonts are bundled into your project.
- Label β The primary widget for displaying your custom fonts.
- Bit Depth (BPP) β Understand how color depth affects font smoothing.