AAText
AAText draws TrueType and OpenType fonts antialiased on AmigaOS 3.2 RTG
screens: Workbench icon labels, menus, window and screen titles, Shell windows, GadTools,
ReAction and MUI programs, everything that draws text through graphics.library.
What is it?
The AmigaOS text system was designed for bitmap fonts: every glyph is a 1-bit mask with
jagged edges. TrueType support comes through diskfont.library and a font engine
(ttf.library or freetype2.library), but the result is still a 1-bit bitmap font. On
high-resolution RTG screens that text looks coarse and is hard to read.
AAText changes this step: it intercepts Text(), renders the glyphs with FreeType
in greyscale (or ClearType-style subpixels) and blends them with the background on screen.
- System
- AmigaOS 3.2 or newer, 68020 or better
- Graphics
- RTG with
cybergraphics.library(e.g. Picasso96) - Fonts
- TrueType / OpenType (CFF) installed with an
.otagfile - Font engine
- FreeType 2.15.0 (
freetype2.library2.15) - Tested on
- WinUAE (UAEGFX) and A1200 + PiStorm (Emu68)
- Languages
- English and Turkish
Highlights
- Zero configuration. Every TrueType font installed with a font manager
(an
.otagfile next to the.fontfile) is detected automatically and drawn in every size, using the code page from its.otag. Turkish and other letters work out of the box. - No replaced libraries. Functions are patched at run time, and the patches are removed cleanly on exit.
- Safe metrics. By default glyphs keep the cells of the system's bitmap font, so no window layout changes.
- Bitmap fonts and palette (AGA) screens are left untouched.
How it works
1. The function patch
At startup AAText uses exec.library/SetFunction() to put its own code in front
of graphics.library's Text(), and optionally TextLength(),
TextExtent() and TextFit(). The original address is kept; whenever
AAText cannot draw (bitmap font, palette screen, blacklisted program) the call goes to the
original function unchanged.
Every patch goes through a small assembly stub (src/stub.s). The stub
counts the tasks inside the code (aa_UseCount); the C side keeps the same task
from entering the patch twice (reentrancy). On exit AAText checks the jump table under
Forbid(): if the vectors still point to it, it restores the original addresses and
waits for the counter to drop to zero. If another program patched on top, it does not
remove itself and stays in pass-through mode: the system never jumps into freed
memory.
; the path of a Text(rp, string, count) call
application ──► graphics/Text() ──► AAText stub
│
├─ font has .otag? RTG screen? program blacklisted?
│ no ──► original Text() (bitmap drawing)
│
└─ yes ──► render.c: glyph cache ──► blend onto screen
(1-bit fallback if that fails)
2. Finding the font
The TextFont in a RastPort is the font diskfont opened. From the
font's name AAText reads the .otag file in FONTS:
(src/otag.c), takes the path of the font file and the code page, and opens a FreeType
face. Fonts that are not found, or are bitmap fonts, are left to the original
function.
3. Glyph rendering and cache
Glyphs are rendered with FreeType into 8-bit coverage maps in src/glyphs.c and
kept in an LRU cache. Slow work that needs a big stack, like loading a font, runs in AAText's
own helper task on its own stack instead of the caller's small one; FreeType's memory comes
from an exec memory pool (src/ft/).
4. Blended drawing
src/render.c reads the rectangle the text covers from the screen with
ReadPixelArray(), blends every pixel with the pen colour by the glyph's coverage
and writes it back with WritePixelArray() (read-modify-write). Gamma
correction, bold text and ClearType subpixel blending happen here. It uses RGBA buffers,
which Picasso96 writes about three times faster on WinUAE. Both functions clip against the
window layers, so windows on top stay intact.
Metrics modes
| Mode | Glyph widths | Patched | Effect |
|---|---|---|---|
| Safe (default) | Cells of the system's bitmap font | Text() | Window layouts never change; glyphs are centred in their cells. |
Real (real on) | TrueType widths + pair kerning (GPOS) | Text(), TextLength(), TextExtent(), TextFit() | Typographically correct; all measuring functions agree. |
In real mode the measuring functions must stay consistent: if a program places its cursor
by the width TextLength() returned, Text() has to draw exactly that
wide. src/metrics.c reimplements these functions with code derived from AROS.
Programs
AATextPrefs
Preferences program written with ReAction (English and Turkish). Gamma, hinting, LCD filter,
real widths, kerning and the program blacklist change with a live preview. It talks to the
running AAText through a message port (RELOAD, APPLY,
STATUS), so every change applies at once.
AATextManager
Font installer and diagnostics tool (window and Shell). It installs fonts like FTManager,
but writes the code page of a character set into the .otag (so Turkish needs no
ENV:ftcodepage) and stores the font path without a volume name. A selected font is
previewed in several sizes before it is installed.
- Diagnostics: checks every
.otaginFONTS:and the file it names; finds fonts whose path broke because the boot volume was renamed. - Repair: moved file, missing code page, old engine name
(
aatext→freetype2). A backup is made first.
freetype2.library 2.15 and harfbuzz.library
With 0.46 AAText's FreeType library became freetype2.library 2.15: the same
function order and the same .otag tags as 1.x, so fonts installed with FTManager and
programs written for 1.x keep working. The installer keeps the old 1.x library as
LIBS:freetype2.library.bak. harfbuzz.library, HarfBuzz 15.1.0 as a
shared library, comes in a separate archive.
Installation
The archive is on Aminet (util/wb/AAText.lha) and on the
GitHub Releases page. Unpack it and
double-click Install-AAText: the OS 3.2 Installer installs everything, adds AAText to
S:User-Startup and can remove it again.
By hand:
; copy to C:
Copy AAText C:
; in S:Startup-Sequence, AFTER the monitor drivers and BEFORE LoadWB:
Run >NIL: C:AAText
WBStartup: it must run before Workbench opens its windows.
All settings are described in docs/AAText.prefs.example.
Building
AAText is cross-compiled with bebbo's amiga-gcc in Docker. On Windows the scripts are PowerShell.
sh tools/fetch-freetype.sh # FreeType 2.15.0 -> third_party/ (sha256 checked)
.\build.ps1 # build/68020/AAText
.\build.ps1 DEBUG=1 # with serial kprintf output
.\build.ps1 CPU=68060 # build/68060/AAText
.\build.ps1 gui # AATextPrefs
.\build.ps1 manager # AATextManager
.\build.ps1 dist # build/dist/AAText.lha
On Linux or macOS:
docker run --rm -v "$PWD:/src" -w /src ghcr.io/rondoval/amiga-build-container make
Tests
The glyph, .otag, metrics and cache code is self-contained enough to run under
the AmigaOS emulator vamos:
sh tools/fetch-testfonts.sh # DejaVu fonts for the tests
.\test.ps1 Ag
.\test.ps1 -All # metrics, stress, auto, otag, baseline, capsize
Source map
| File | Purpose |
|---|---|
src/main.c | Startup, arguments, helper loop that loads fonts |
src/patch.c, src/stub.s | SetFunction() patches, safe removal, reentrancy guard |
src/render.c | Decision per Text() call; blended drawing, 1-bit fallback |
src/glyphs.c | FreeType faces, automatic detection, LRU glyph cache, private stack |
src/metrics.c | TextLength/TextExtent/TextFit in real metrics mode |
src/otag.c | .otag parser |
src/prefs.c, src/prefswrite.c | Reading the settings file and writing it back, keeping comments |
src/aamsg.h, src/aaclient.c | Message port interface of a running AAText |
src/prefsgui/ | AATextPrefs (ReAction) |
src/manager/ | AATextManager (window and Shell) |
src/ft/ | Minimal FreeType configuration, exec memory pool allocator |
License
AAText is released under the MIT License.
src/metrics.c is derived from AROS and is under the AROS Public License 1.1. Binary
releases contain FreeType 2.15.0: Portions of this software are copyright © The FreeType
Project (https://freetype.org). All rights reserved.