Skip to content

ProwlEngine/Prowl.Scribe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scribe logo image

Github top languages GitHub version GitHub license GitHub issues GitHub stars Discord

Important

Scribe is under active development. APIs may change and it hasn't yet proven itself in production.

A Fast & Flexible Font System for .NET

📚 Documentation: Coming Soon 📚

Table of Contents

  1. About The Project
  2. Features
  3. Getting Started
  4. Contributing
  5. License

📝 About The Project 📝

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.

✨ Features ✨

  • 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

🚀 Getting Started 🚀

Installation

Add the package via NuGet:

dotnet add package Prowl.Scribe

Basic Usage

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)

Markdown Rendering

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);

MarkdownShowcase

🤝 Contributing 🤝

Contributions, issues and feature requests are welcome! Feel free to fork this repository and submit a pull request.

📄 License 📄

Distributed under the MIT License. See LICENSE for details.

About

An MIT Licensed .NET TTF Parser and Rasterizer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages