AtlatestRepositorysigil-fontconfig
sigil-fontconfig / treeREADME.md
1
# sigil-fontconfig3
Font discovery for Sigil through pure dynamic FFI. The system must supply4
`libfontconfig` 2.12.5 or later; no C extension or external font lookup process is used.6
```scheme7
(import (sigil fontconfig))8
(define font9
(fc-font-match (fc-pattern family: "JetBrains Mono" style: "Regular" size: 7)))10
(fc-font-file font)11
(fc-font-index font)12
(fc-font-list (fc-pattern family: "JetBrains Mono"))13
```15
`fc-pattern` accepts optional `family:`, `style:` and point `size:` fields.16
`fc-font-match` applies system substitutions and defaults, returning a font17
record or `#f` when no font matches. Fontconfig may substitute an unavailable18
family; inspect `fc-font-family` to identify the chosen font.20
`fc-font-list` lists installed fonts, optionally filtered by a pattern. Listing21
uses exact property matching without fallback. Results expose `fc-font-file`,22
`fc-font-index`, `fc-font-family` and `fc-font-style`. They contain copied Sigil23
data; native patterns and sets are destroyed before returning. File and index24
can be passed directly to `ft-new-face` from sigil-freetype.26
These two legacy functions use the process default and initialize it lazily.27
They leave its shared caches available to other library users. Legacy listing28
rejects a native set larger than 65536 records before copying its entries.30
For UI discovery independent of a page renderer, use an owned inventory:32
```scheme33
(define context34
(make-fc-context35
files: '("fonts/JetBrainsMono-Regular.ttf" "fonts/JetBrainsMono-Bold.ttf")36
directories: '("/usr/share/fonts/truetype/jetbrains-mono")37
cache-directory: "/absolute/private/ui-font-cache"38
max-fonts: 4096))39
(dynamic-wind40
(lambda () #f)41
(lambda ()42
(fc-context-match context (fc-pattern family: "JetBrains Mono" style: "Regular"))43
(fc-context-sort context (fc-pattern family: "JetBrains Mono"))44
(fc-context-list context))45
(lambda () (fc-context-close! context)))46
```48
The context starts empty and scans only explicit files/directories. It loads no49
system or user configuration, inherits no cache directories or sysroot, and50
disables its own automatic rescans. It never replaces the process default or51
changes environment variables. Directory scanning is synchronous; select52
specific font roots, not broad filesystem roots. `max-fonts:` bounds the53
completed inventory and returned copies (default 4096, positive exact integer54
below 1000000); it is not a native scan-memory or time limit. The bound counts55
font patterns, including named instances in variable-font files.56
Directory inventories require an explicit absolute `cache-directory:`;57
create a private writable directory before calling. Only that cache path is58
loaded into the context. File-only inventories need no disk cache.60
Owned matching/sorting applies normal weight, roman slant, normal width and61
the standard numeric/boolean matching defaults directly. Unspecified point62
size uses 12 points at 75 DPI. Name languages come from the first selected63
locale, normalized without a default configuration, with a weak English fallback.64
The legacy system API still calls Fontconfig's default-substitution function.65
The owned path never calls it, including on Fontconfig 2.17 and later where66
that function initializes the process default.67
The uint64 string-union representation assumes little-endian LP64 targets;68
the driver checks its layout and weak binding against the native header.70
`fc-context-match` returns one copied record or `#f`.71
`fc-context-list` optionally accepts one pattern.72
`fc-context-sort` returns copied candidates in Fontconfig preference order;73
its default `trim?: #t` removes candidates adding no character coverage.74
Use `trim?: #f` to retain all candidates. Consumers should check actual glyph75
coverage in their face loader. No native patterns or charsets escape. Results76
survive later calls and closing their context.78
Close is idempotent; subsequent discovery calls raise an error.79
`fc-context-closed?` exposes this state. Pointer finalization also covers80
abandoned contexts, while explicit close clears that finalizer before release.81
Missing libraries, invalid arguments and native allocation failures raise errors.82
Static compilation tools may import the module without a dynamic loader;83
an attempted native operation then reports the saved load failure.85
The implementation follows the upstream86
[Fontconfig developer reference](https://fontconfig.pages.freedesktop.org/fontconfig/fontconfig-devel/)87
for explicit configurations, application font inventories and sorted sets.89
Use `guix shell -m manifest.scm` for Fontconfig, its native test compiler,90
JetBrains Mono and Noto Sans/Serif,91
then `sigil deps install`, `sigil build` and `sigil scripts/ci-test.sgl`.92
Or run the ordered gate directly:94
```text95
guix shell -m manifest.scm -- sigil scripts/ci-test.sgl96
```98
The shipped driver copies just the four test faces into a temporary inventory99
and supplies private process-default configuration and cache directories.100
To supply fixtures without the manifest, set `SIGIL_FONTCONFIG_TEST_DIRECTORY`101
to an absolute owned directory containing `JetBrainsMono-Regular.ttf`,102
`JetBrainsMono-Bold.ttf`, `NotoSans.ttf` and `NotoSerif.ttf`.103
`SIGIL_FONTCONFIG_TEST_CACHE` optionally selects an absolute private writable104
cache directory for the owned-directory tests; otherwise the driver creates105
one temporarily. These variables are required when running individual test106
files without the driver. No desktop font configuration is needed.108
The driver runs `test/test-00-isolation.sgl` alone in a fresh process before109
the other two suites. Its sentinel cache must remain empty after owned110
matching, sorting and listing, then become nonempty when `FcConfigGetCurrent`111
explicitly initializes that default. This positive control makes prior default112
initialization fail the test. Plain `sigil test` is not the ordered gate: file113
discovery order is unspecified. The separate default pointer-identity control114
checks preservation after initialization.116
The driver sets `SIGIL_FONTCONFIG_ISOLATION_FIRST=1` only for the fresh117
isolation process. Without that marker, plain `sigil test` skips isolation118
with a clear message; marked runs still reject prior default initialization.119
It compiles `test/value-abi.c`, exports `SIGIL_FONTCONFIG_VALUE_ABI`, and runs120
the separate by-value layout/weak-binding test. That test reports a skip when121
no receipt is supplied by the driver.123
BSD-3-Clause.