Important
Scribe is under active development. APIs may change and it hasn't yet proven itself in production.
Scribe is an open-source, MIT-licensed TrueType font parser and rasterizer for .NET. It powers text rendering in the Prowl game engine but is designed to work in any environment that can provide an IFontRenderer
.
- TrueType font parsing and glyph rasterization
- Font Families
- Dynamic atlas packing with optional expansion
- Flexible text layout engine with cursor hit testing
- Lightweight Markdown parser and layout engine
- Pluggable rendering backend through
IFontRenderer
- Optional layout caching with LRU eviction
- TTF Loader and Rasterizer Based Upon STBTrueType
- Unicode codepoint mapping, full glyph metrics (advance, bearings, bounds, vertical metrics) and kerning pairs
- Extracts glyph outlines and rasterizes to 8-bit alpha bitmaps
Add the package via NuGet:
dotnet add package Prowl.Scribe
var renderer = new MyFontRenderer(); // implements IFontRenderer
var scribe = new FontSystem(renderer);
// Load fonts, Will load all System Fonts with the passed FontFamilies as Priority
scribe.LoadSystemFonts("Arial");
// or: var font = scribe.AddFont(File.ReadAllBytes("path/to/font.ttf"));
// If you use SystemFonts its recommended to add priorities also for different platforms
// Not all operating systems have the same fonts. This is the priority list used in the Samples:
// "Segoe UI", "Arial", "Liberation Sans", "Consola", "Menlo", "Liberation Mono"
// Draw text will attempt to use preferredFont if available
var preferredFont = scribe.GetFont(fontFamily, FontStyle.Bold);
scribe.DrawText("Hello World!", position, FontColor.Blue, pixelSize, preferredFont)
var imageProvider = new MyImageProvider(); // implements IMarkdownImageProvider
// Get the fonts you would like the Markdown rendering to use
var font = fs.GetFont("Arial", FontStyle.Regular);
var mono = fs.GetFont("Consolas", FontStyle.Regular);
var bold = fs.GetFont("Arial", FontStyle.Bold);
var italic = fs.GetFont("Arial", FontStyle.Italic);
var boldItalic = fs.GetFont("Arial", FontStyle.BoldItalic);
// Create the markdown Settings
var settings = MarkdownLayoutSettings.Default(font, mono, bold, italic, boldItalic, width: 400);
// Parse your Markdown
var document = Markdown.Parse(YourMarkdown);
// Layout the markdown (relative to 0,0)
var markdownLayout = MarkdownLayoutEngine.Layout(document, scribe, settings, imageProvider);
// Render your Markdown at the specified position
MarkdownLayoutEngine.Render(markdownLayout, scribe, renderer, position, settings);
// You can also check if the mouse cursor is hovering over a Clickable Link!
bool isMouseOverLink = MarkdownLayoutEngine.TryGetLinkAt(markdownLayout, mouse, position, out var href);
Contributions, issues and feature requests are welcome! Feel free to fork this repository and submit a pull request.
Distributed under the MIT License. See LICENSE for details.