{"record":{"id":"0138368d8246d3f9","repo":"slint-ui/slint","slug":"fatal-swash-is-unable-to-parse-truetype-font","errorCode":null,"errorMessage":"fatal: swash is unable to parse truetype font","messagePattern":"fatal: swash is unable to parse truetype font","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/renderers/software/fonts/systemfonts.rs","lineNumber":30,"sourceCode":"use super::super::PhysicalLength;\nuse super::vectorfont::VectorFont;\n\nstruct CachedFontInfo {\n    swash_key: swash::CacheKey,\n    swash_offset: u32,\n}\n\ni_slint_core::thread_local! {\n    // swash font info cached and indexed by fontique blob id (unique incremental) and true type collection index\n    static SWASH_FONTS: RefCell<HashMap<(HashedBlob, u32), CachedFontInfo>> = Default::default();\n}\n\npub fn get_swash_font_info(blob: &fontique::Blob<u8>, index: u32) -> (swash::CacheKey, u32) {\n    SWASH_FONTS.with(|font_cache| {\n        let mut cache = font_cache.borrow_mut();\n        let info = cache.entry((blob.clone().into(), index)).or_insert_with(move || {\n            let font_ref = swash::FontRef::from_index(blob.data(), index as usize)\n                .expect(\"fatal: swash is unable to parse truetype font\");\n            CachedFontInfo { swash_key: font_ref.key, swash_offset: font_ref.offset }\n        });\n        (info.swash_key, info.swash_offset)\n    })\n}\n\nfn get_swash_font_info_for_query_font(font: &fontique::QueryFont) -> (swash::CacheKey, u32) {\n    get_swash_font_info(&font.blob, font.index)\n}\n\npub fn match_font(\n    request: &super::FontRequest,\n    scale_factor: super::ScaleFactor,\n    collection: &mut fontique::Collection,\n    source_cache: &mut fontique::SourceCache,\n) -> Option<VectorFont> {\n    if request.family.is_some() {\n        let requested_pixel_size: PhysicalLength =","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/renderers/software/fonts/systemfonts.rs#L12-L48","documentation":"`get_swash_font_info` parses a fontique font blob with `swash::FontRef::from_index` and panics if swash cannot parse the data as a TrueType/OpenType font. The software renderer assumes every font the system font enumeration (fontique) returns is parseable; a corrupt, DRM-protected, or non-TrueType font file breaks that assumption. The `or_insert_with` cache means the panic happens once per (blob, index) pair, on first use.","triggerScenarios":"Text rendering via the software renderer when a font selected by fontique for the query cannot be parsed by swash: broken/corrupted font files in font directories, fonts with unsupported formats (Type 1, bitmap-only), or an out-of-range `index` into a font collection (TTC) blob.","commonSituations":"Linux systems with damaged fonts in `~/.fonts` or `/usr/share/fonts`; containers/minimal images with malformed font packages; custom font loading via `slint::platform::software_renderer` where a bad `.ttf`/`.ttc` is registered; font collections where the requested index is out of bounds.","solutions":["Find and remove/repair the corrupt font file (validate all fonts with e.g. `fonttools ttx <file>` or `fc-validate`)","Clear font caches (`fc-cache -f`) after fixing fonts so fontique re-enumerates clean data","Restrict the fonts available to the app (point `FONTCONFIG_FILE`/`XDG_DATA_HOME` at a curated font dir with a known-good font like DejaVu)","Update Slint/fontique/swash — newer versions may skip unparsable fonts instead of panicking"],"exampleFix":"// validate fonts before shipping an embedded system image\n// before: broken-font.ttf present in the font dir\n$ fonttools ttx broken-font.ttf   # fails => remove it\n$ fc-cache -f\n// after: only valid fonts in the font directory\n$ ls fonts/  # DejaVuSans.ttf, Roboto-Regular.ttf ...","handlingStrategy":"fallback","validationCode":"// validate font files at deploy time\n$ fonttools ttx font.ttf  # or: fc-validate --all","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ship a curated, validated font set (e.g. DejaVu, Noto) instead of system font dirs","Run `fc-cache -f` and validate fonts in CI for embedded images","Sanitize user-supplied font directories before pointing fontique at them","Update Slint/fontique/swash so unparsable fonts are skipped rather than panicking"],"tags":["fonts","software-renderer","panic","truetype"],"backgroundTag":"font-parse-failed","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}