Unhardcode font resolution
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 7.8k
- Forks
- 1.2k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 49
Description
Currently when fonts are loaded they receive a hardcoded path:
https://github.com/stride3d/stride/blob/master/sources/engine/Stride.Graphics/Font/FontHelper.cs#L6
and will only be resolved using the odb filesystem:
https://github.com/stride3d/stride/blob/master/sources/engine/Stride.Graphics/Font/FontManager.cs#L266
So im requesting a change to un-hardcode this. In a perfect-scenario this uses the VFS, and the path resolution can be set by the project.
This makes it hard for full-code-only projects which load assets from a custom structure on runtime to load fonts. A workaround for this currently is:
private SpriteFont FontNewDynamic(
float defaultSize,
string fontName,
FontStyle style,
FontAntiAliasMode antiAliasMode = FontAntiAliasMode.Default,
bool useKerning = false,
float extraSpacing = 0f,
float extraLineSpacing = 0f,
char defaultCharacter = ' '
)
{
const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
var fontManager = ((FontSystem)this.Font).GetType().GetProperty("FontManager", flags)?.GetValue(this.Font);
if (fontManager?.GetType().GetField("cachedFontFaces", flags)?.GetValue(fontManager) is not Dictionary<string, Face> cachedFontFaces
|| fontManager.GetType().GetField("freetypeLibrary", flags)?.GetValue(fontManager) is not Library freetypeLibrary)
return this.Font.NewDynamic(defaultSize, fontName, style, antiAliasMode, useKerning, extraSpacing, extraLineSpacing, defaultCharacter);
using var fontStream = File.OpenRead($"Assets/Fonts/{fontName}.ttf");
var newFontData = new byte[fontStream.Length];
fontStream.Read(newFontData, 0, newFontData.Length);
lock (freetypeLibrary)
cachedFontFaces[FontHelper.GetFontPath(fontName, style)] = freetypeLibrary.NewMemoryFace(newFontData, 0);
return this.Font.NewDynamic(defaultSize, fontName, style, antiAliasMode, useKerning, extraSpacing, extraLineSpacing, defaultCharacter);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with sources/engine/Stride.Graphics/Font/FontHelper.cs at the hardcoded path and FontManager.cs around line 266 to trace how font files are resolved. Compare that flow with the VFS and the provided runtime workaround; done means a project-configurable resolution path lets full-code-only projects load fonts from custom runtime structures without reflection-based access.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100