Skip to content

ExtraBinoss/MSDFGen-Sharp

Repository files navigation

MSDFGen-Sharp

Raw MSDF Rendered Glyph
Raw MSDF A Rendered A
Original MSDF output High-quality rendered result

A comprehensive C# port of the original msdfgen and msdf-atlas-gen projects. This library provides high-quality Multi-channel Signed Distance Field (MSDF) generation for fonts and vector graphics, maintaining an almost 1:1 correspondence with the CLI and core functionality of Chlumsky's original implementation.

🏗 Project Architecture

The repository is organized into several components to separate core logic, extensions, and CLI tools:

Core

  • Msdfgen.Core: The heart of the project. Contains the fundamental algorithms for MSDF generation, including math utilities, edge coloring, and shape processing.
  • MsdfAtlasGen: Implements the logic for packing multiple glyphs into a single texture atlas and managing atlas metadata.
  • Msdfgen.Extensions: Provides integration with third-party libraries like FreeType and ImageSharp for font loading and image processing.

CLI Tools

  • MsdfAtlasGen.Cli: The primary command-line tool for generating font atlases and exporting metadata (FNT, JSON, etc.).
  • Msdfgen.Cli: A diagnostic CLI tool for generating single-glyph MSDFs and testing core features.

Note

MSDFGen-Sharp is a port of the original msdfgen and msdf-atlas-gen projects. It is not a direct port of the original CLI tools. If you want to use the original CLI tools, you can find them here MSDFGen and here MSDFAtlasGen.

📦 Installation

To use MSDF-Sharp in your project, install the package from NuGet:

dotnet add package MSDF-Sharp

Alternatively, you can find it on NuGet.org.

✨ Key Features

  • Multi-channel Signed Distance Fields (MSDF): Superior sharpness for text rendering at any scale.
  • Font Atlas Generation: Efficiently pack multiple glyphs into a single texture.
  • Advanced Error Correction: Integrated "Indiscriminate" and "Auto" modes to eliminate artifacts.
  • Overlap Support: Properly handles complex glyphs with self-intersecting contours.
  • Multi-threaded: Built-in support for parallel glyph generation.
  • Compatibility: Generates standard BMFont (.fnt), JSON, and CSV metadata.

🛠 Building and Running

This project requires .NET 9.0 SDK. You can download it from here.

Refer to the MsdfAtlasGen.Cli and Msdfgen.Cli READMEs for more information on how to build and run the projects.

📄 License

This project is licensed under the MIT License. It utilizes several third-party libraries:

🎨 Showcase

Font Atlases and Renders

Below are examples of generated MSDF atlases and how they appear when rendered.

Font MSDF Atlas Rendered Showcase
Roboto Regular Roboto Atlas Roboto Render
Barbarian (Fantasy) Barbarian Atlas Barbarian Render

📚 Authors Note

If you find this project useful, please consider giving it a star on GitHub. It helps me keep track of the project's popularity and inspires me to continue working on it.

Thank you for using MSDF-Sharp!

About

MSDFGen port to C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages