{"record":{"id":"cd63b8e35305ed25","repo":"stride3d/stride","slug":"sdf-font-from-image-is-not-supported","errorCode":null,"errorMessage":"SDF Font from image is not supported!","messagePattern":"SDF Font from image is not supported!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Assets/SpriteFont/Compiler/SignedDistanceFieldFontCompiler.cs","lineNumber":129,"sourceCode":"\n            var glyphs = ImportFont(fontAsset, out lineSpacing, out baseLine);\n\n            Image<Rgba32> bitmap = GlyphPacker.ArrangeGlyphs(glyphs);\n\n            return SignedDistanceFieldFontWriter.CreateSpriteFontData(fontFactory, fontAsset, glyphs, lineSpacing, baseLine, bitmap);\n        }\n\n        static Glyph[] ImportFont(SpriteFontAsset options, out float lineSpacing, out float baseLine)\n        {\n            // Which importer knows how to read this source font?\n            IFontImporter importer;\n\n            var sourceExtension = (Path.GetExtension(options.FontSource.GetFontPath()) ?? \"\").ToLowerInvariant();\n            var bitmapFileExtensions = new List<string> { \".bmp\", \".png\", \".gif\" };\n            var importFromBitmap = bitmapFileExtensions.Contains(sourceExtension);\n            if (importFromBitmap)\n            {\n                throw new Exception(\"SDF Font from image is not supported!\");\n            }\n\n            importer = new SignedDistanceFieldFontImporter();\n\n            // create the list of character to import\n            var characters = GetCharactersToImport(options);\n\n            // Import the source font data.\n            importer.Import(options, characters);\n\n            lineSpacing = importer.LineSpacing;\n            baseLine = importer.BaseLine;\n\n            // Get all glyphs\n            var glyphs = new List<Glyph>(importer.Glyphs);\n\n            // Validate.\n            if (glyphs.Count == 0)","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Assets/SpriteFont/Compiler/SignedDistanceFieldFontCompiler.cs#L111-L147","documentation":"SignedDistanceFieldFontCompiler.ImportFont classifies the font source by file extension: .bmp, .png, or .gif are treated as bitmap sources, and generating signed distance fields from raster images is not supported by this importer, so it throws immediately. SDF fonts must be generated from a vector font file (TTF/OTF).","triggerScenarios":"Compiling an SDF font whose FontSource path ends in .bmp, .png, or .gif — the extension check flags importFromBitmap and throws before the SignedDistanceFieldFontImporter is even created.","commonSituations":"Pointing an SDF font asset at a texture image instead of the original TTF; migrating a legacy rasterized font project that referenced PNG atlases to SDF; a wrong FontSource path/extension.","solutions":["Set FontSource to the original vector font file (.ttf, .otf) the image was derived from.","If only the image exists, obtain the matching font file — an SDF font cannot be generated from a bitmap.","Use the regular rasterized sprite font pipeline for image-based sources instead.","Check the FontSource path for a wrong extension or a file that was renamed to an image extension."],"exampleFix":"// before (font asset)\n<FontSource>ui_font.png</FontSource>\n// after\n<FontSource>ui_font.ttf</FontSource>","handlingStrategy":"validation","validationCode":"var ext = (Path.GetExtension(fontAsset.FontSource.GetFontPath()) ?? \"\").ToLowerInvariant();\nif (new[] { \".bmp\", \".png\", \".gif\" }.Contains(ext))\n    throw new InvalidOperationException($\"SDF compilation requires a vector font (.ttf/.otf), got '{ext}'\");","typeGuard":"bool IsVectorFontSource(SpriteFontAsset asset) =>\n    !new[] { \".bmp\", \".png\", \".gif\" }.Contains((Path.GetExtension(asset.FontSource.GetFontPath()) ?? \"\").ToLowerInvariant());","tryCatchPattern":"try\n{\n    var font = SignedDistanceFieldFontCompiler.Compile(factory, fontAsset);\n}\ncatch (Exception ex) when (ex.Message == \"SDF Font from image is not supported!\")\n{\n    logger.LogError(\"FontSource for {Name} is a bitmap; supply the original vector font file\", fontAsset.Name);\n    throw; // fail the build — a bitmap source cannot be auto-converted\n}","preventionTips":["Always reference the original TTF/OTF in FontSource, never exported atlases.","Validate font source extensions during content import, before compilation.","When migrating rasterized fonts to SDF, locate the source font files first.","Use distinct asset extensions/folders for bitmap-based and vector-based font assets."],"tags":["fonts","sdf","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}