CosmosTTF 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CosmosTTF --version 3.0.0                
NuGet\Install-Package CosmosTTF -Version 3.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CosmosTTF" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CosmosTTF --version 3.0.0                
#r "nuget: CosmosTTF, 3.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CosmosTTF as a Cake Addin
#addin nuget:?package=CosmosTTF&version=3.0.0

// Install CosmosTTF as a Cake Tool
#tool nuget:?package=CosmosTTF&version=3.0.0                

CosmosTTF

Fast TrueType Font rendering in Cosmos

How to use

Most of CosmosTTF happens within the static TTFManager class.

Loading Fonts

To load a font, simply call TTFManager.RegisterFont(string name, byte[] data) - remember the name you are supplying here! This name is used in other methods to find the font again. The data is supposed to be a clean byte array containing the raw content of a .TTF file.

Writing text to the screen

With CGS

To write text on the screen, you can use Canvas.DrawStringTTF or Canvas.DrawStringTTFChecked, these are two extension methods defined on the CGS canvas. The difference between them is that the "Checked" method does not draw outside the specified bounds, or at least it tries to do so.

Without CGS

Now, what if you arent using CGS (or atleast arent using it directly)? Well, you can use TTFManager.RenderGlyphAsBitmap for that. TTFManager.RenderGlyphAsBitmap will return a RenderedGlyph struct, containing, most importantly, the output Cosmos.System.Graphics.Bitmap bitmap and the yOff and xOff. When you use the bitmap to draw to your canvas, yOff should be added immediately - xOff should be added to the total X offset after it. Now, if you want more accurate metrics, you are gonna have to use TTFManager.GetGlyphHMetrics for that, it gives you both the left side bearing & xAdvance.

Measuring strings

You can measure the width of a string using the TTFManager.GetTTFWidth method. It returns the width of the string in pixels. This width, as of right now, is without the left side bearing (kinda like DrawStringTTF does not respect LSB yet)

Manual usage

If you prefer to leave TTFManager alone and do something different, you can use the Font class in the namespace LunarLabs.Fonts.

Some fonts are not working! How to fix?

Whilst most TTF fonts work, a few dont. Additionally, italic fonts might look cut off a bit.

This project is powered by a slightly modified version of LunarFonts by Relfos!

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CosmosTTF:

Package Downloads
com.Samma.forgium

boost your CosmosOS browser with Forgium, The best Html + Css 2/3 Renderer for cosmos yet.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.1 448 3/9/2024
4.0.0 152 3/9/2024
3.0.0 145 3/7/2024
2.0.0 170 1/23/2024
1.0.0 114 1/23/2024