SDF Font Rendering Module >=26.1
The package dev.anvilcraft.lib.v2.font provides an SDF (Signed Distance Field) based font rendering system that supports loading arbitrary system AWT fonts and using them for Minecraft GUI text rendering, complete with a configuration screen and styled text support.
Availability
This module is only available in Minecraft 26.1.
Architecture Overview
- Entry Layer —
AnvilLibFontis the@Modentry point (CLIENT-only), providesgetSelectFont()to get the currently configured AWT Font, and registersFontConfigScreenas the config screen - Discovery Layer —
FontManagersingleton discovers all system fonts via AWTGraphicsEnvironment, builds a font family Trie index, and providesgetFont(String name)andgetFamilyNames()/getFamilyFontNames() - Configuration Layer —
AnvilLibFontConfigis a JSON-based config (stored atconfig/anvillib/anvillib-font-client.json), reading/writingfontFamilyandfontselections via Gson - Rendering Layer —
SdfTextRendereris the main renderer supportingdrawString,drawFormatted,drawComponent,drawCentered, anddrawWrappedmethods - Atlas Layer —
SdfGlyphAtlasis a multi-page CPU-side SDF glyph atlas with 1024x1024 pages, pre-warming ASCII 32-126, lazy-rendering other codepoints, using the Dead Reckoning EDT algorithm for SDF computation - Layout Layer —
SdfTextLayoutperforms CPU-side glyph layout, grouping glyphs by atlas page and outputtingPageQuadswith UV coordinates per glyph - Upload Layer —
SdfAtlasTextureuploads atlas pages to the GPU asRED8textures (LINEAR + CLAMP filtering) - State Layer —
SdfTextRenderStateimplementsLibGuiElementRenderState, building quad vertices for SDF text rendering through theALFPipelines.SDF_TEXTpipeline
Document Index
| Document | Contents |
|---|---|
| Core API | AnvilLibFont, FontManager, SdfTextRenderer, SdfGlyphAtlas, SdfTextLayout, GUI extension methods |
Quick Start
java
// 1. Get the currently configured font
Font font = AnvilLibFont.getSelectFont();
// 2. Draw text in GuiGraphics
graphics.anvillib$text(font, "Hello SDF Text", x, y, 0xFFFFFFFF);
// 3. Draw centered text
graphics.anvillib$centeredText(font, Component.literal("Centered"), x, y, 0xFFFFFF00);
// 4. Draw text with word wrap
graphics.anvillib$textWithWordWrap(font, FormattedText.of("Long text..."), x, y, width, 0xFFFFFFFF);
// 5. Draw text with backdrop color outline
graphics.anvillib$textWithBackdrop(font, "Backdrop Text", x, y, 0xFFFFFFFF, 0x80000000);Dependency Management
groovy
dependencies {
implementation "dev.anvilcraft.lib:anvillib-font-neoforge-26.1:2.0.0"
}This module depends on
module.rendering(usesLibGuiElementRenderState) and is client-side only (@Mod(dist = Dist.CLIENT)).
Notes
AnvilLibFont.getSelectFont()returns an AWTjava.awt.FontinstanceSdfGlyphAtlasuses a static cache keyed by font name + style + size; identical parameters reuse the atlas- Atlas pages are 1024x1024; glyphs are rendered lazily on demand
- GUI extension methods are injected into
GuiGraphicsvia Mixin (GuiGraphicsExtractorMixin) and exposed through theGuiGraphicsExtractorExtensioninterface - Supported text styles: bold, italic, underline, strikethrough, obfuscated