feat: add disable_system_fonts option to ignore system typefaces#28
Open
lhoward wants to merge 1 commit into
Open
feat: add disable_system_fonts option to ignore system typefaces#28lhoward wants to merge 1 commit into
lhoward wants to merge 1 commit into
Conversation
Adds a new boolean engine property that installs a private, in-memory fontconfig configuration containing only the directories of fonts declared in the bundle's FontManifest.json. With no <dir> entries pointing at /usr/share/fonts (or any other system path), Skia inside the engine sees only bundled fonts and renders missing glyphs as tofu rather than falling back to a system typeface. Useful for embedded targets where the host font set may be unpredictable, sparse, or visually inconsistent with the app's design. The config is materialized via memfd_create() and exposed to the engine through FONTCONFIG_FILE=/proc/self/fd/N, so nothing is written to the on-disk filesystem and the anonymous file is freed by the kernel when the engine fd is closed at shutdown. No new build-time dependencies — fontconfig itself is reached transitively through libflutter_engine.so's existing libfontconfig.so.1 runtime link, and the embedder source never includes a fontconfig header. The option is exposed on FlutterDesktopEngineProperties (defaults to false, so existing callers are source- and behaviorally unchanged) and threaded through DartProject in the C++ wrapper. Fixes: flutter-elinux/flutter-elinux#14 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
afcf6d3 to
6316198
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
disable_system_fontsboolean toFlutterDesktopEngineProperties. When set, the engine installs a private fontconfig configuration containing only the directories of fonts declared in the bundle'sFontManifest.json, so Skia sees no system fonts and renders missing glyphs as tofu rather than falling back to a system typeface.Useful on embedded targets where the host font set may be unpredictable, sparse, or visually inconsistent with the app's intended design.
How it works
flutter_assets/FontManifest.jsonand collect the unique parent directories of each declared font asset.<dir>entries, no system paths, no<cachedir>(the bundle is small; in-memory rebuild on each startup is microseconds, and we avoid assuming any writable home directory exists on the target).memfd_create()anonymous file and expose it to the engine viaFONTCONFIG_FILE=/proc/self/fd/N. Nothing is written to the on-disk filesystem; the kernel frees the memfd when the fd is closed at engine shutdown.The embedder itself never
#includes a fontconfig header or links a fontconfig symbol — the actual parsing happens insidelibflutter_engine.so, which already haslibfontconfig.so.1as a runtime dependency. So no new build-time dependencies (nolibfontconfig-dev, no CMake changes).API surface
FlutterDesktopEngineProperties.disable_system_fonts(new trailing field, defaults tofalsevia zero-init — source-compatible)flutter::DartProject::set_disable_system_fonts(bool)/disable_system_fonts()in the C++ wrapperTest plan
swift buildof the FlutterSwift wrapper that consumes this embedder builds cleanmemfd_create()+/proc/self/fd/Nsemantics: opening the proc path gives a fresh open file description with offset 0, so fontconfig reads the full XML from byte 0 even though the writer's fd is at EOF--enable-fontconfigengine and a bundle containing only a custom font — confirm system Roboto/DejaVu is no longer reachable🤖 Generated with Claude Code