Skip to content

Add Forme GPU font wrapper as a new TTF font type#11

Draft
Copilot wants to merge 10 commits into
masterfrom
copilot/add-forme-ttf-font-wrapper
Draft

Add Forme GPU font wrapper as a new TTF font type#11
Copilot wants to merge 10 commits into
masterfrom
copilot/add-forme-ttf-font-wrapper

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 7, 2026

Summary

Introduces AristurtleDev.Forme as a new GPU-accelerated font type alongside the existing FontStashSharp TTF wrapper.

Forme renders text directly from quadratic Bézier glyph outline data on the GPU using the Slug algorithm — no precomputed textures, distance fields, or rasterized atlases. Text remains crisp at any size and scale.

Changes

New file

  • FontManagement/FormeFontWrapper.cs — implements IFont using FormeRenderer + FormeFontDevice. Each DrawString call flushes the active SpriteBatch, uses FormeRenderer.Begin/DrawString/End (which saves and restores all GraphicsDevice state), then restarts the SpriteBatch. Supports .forme pre-processed cache files for faster startup. Guarded by #if !XNA.

Modified files

  • FontManagement/FontType.cs — adds Forme enum value.
  • FontManagement/FontManager.cs — adds CreateFormeFontIndex: loads from a pre-processed .forme file if present (falling back to raw TTF and saving the result), creates FormeFontDevice + FormeFontWrapper. Guarded by #if !XNA.
  • Renderer.cs — stores the GraphicsDevice and initializes a shared FormeRenderer on startup. Guarded by #if !XNA.
  • Rampastring.XNAUI.csproj:
    • MonoGame net8.0 targets bumped from 3.8.1.3033.8.4.1 (required by Forme.MonoGame 0.0.3; net48/XNA targets stay on 3.8.0.1641).
    • Added AristurtleDev.Forme 0.0.3 and AristurtleDev.Forme.MonoGame 0.0.3 (non-XNA only).

Usage

Add a Forme font in Fonts.ini:

[Fonts]
Count=1

[Font0]
Type=Forme
Path=NotoSans-Regular.ttf
Size=16

On first run the TTF is processed and a NotoSans-Regular.forme binary cache file is written next to the TTF. Subsequent runs load the cache directly, skipping reprocessing.

Notes

  • Glyphs are baked for Unicode Basic Latin (U+0020–U+007F) by default. For extended character support, pre-process the font with a custom CharacterSet via FormeFont.FromTtf and place the resulting .forme file next to the TTF.
  • FormeRenderer is shared across all Forme font instances and owned by Renderer.
  • The SpriteBatch flush-per-text-call pattern preserves correct draw order. FormeRenderer.Begin/End explicitly saves and restores all GraphicsDevice state, so SpriteBatch always resumes with correct settings.
  • XNA (net48) configurations are unaffected — all Forme code is behind #if !XNA guards.

Copilot AI and others added 2 commits April 7, 2026 11:14
@SadPencil SadPencil force-pushed the copilot/add-forme-ttf-font-wrapper branch from 79ee994 to d089693 Compare April 7, 2026 15:03
@SadPencil
Copy link
Copy Markdown
Member

SadPencil commented Apr 7, 2026

图片

Limitations that can't (or shouldn't) overcome

  1. Only one MonoGame version can be used, between .net 8 and .net 4.8 clients
  2. The client must enable HiDef
  3. No XNA support

Limitations maybe solvable
4. No RTL/HarfBuzz support for languages like Arabic. Left as a TODO or future work.
5. A cache. This must be done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants