CosmosTTF 3.0.0
See the version list below for details.
dotnet add package CosmosTTF --version 3.0.0
NuGet\Install-Package CosmosTTF -Version 3.0.0
<PackageReference Include="CosmosTTF" Version="3.0.0" />
paket add CosmosTTF --version 3.0.0
#r "nuget: CosmosTTF, 3.0.0"
// 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 | Versions 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. |
-
net6.0
- Cosmos.Debug.Kernel (>= 0.1.0-localbuild20240307102856)
- Cosmos.System2 (>= 0.1.0-localbuild20240307102856)
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.