BdfFont 0.0.2

dotnet add package BdfFont --version 0.0.2
                    
NuGet\Install-Package BdfFont -Version 0.0.2
                    
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="BdfFont" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BdfFont" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="BdfFont" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BdfFont --version 0.0.2
                    
#r "nuget: BdfFont, 0.0.2"
                    
#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.
#addin nuget:?package=BdfFont&version=0.0.2
                    
Install BdfFont as a Cake Addin
#tool nuget:?package=BdfFont&version=0.0.2
                    
Install BdfFont as a Cake Tool

BdfFont.NET

.NET NuGet

BdfFont is a library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts.

Installation

dotnet add package BdfFont

Usage

Create

using BdfSpec;

var outputsDir = Path.Combine("build");
if (Directory.Exists(outputsDir))
{
    Directory.Delete(outputsDir, true);
}
Directory.CreateDirectory(outputsDir);

var font = new BdfFont(
    pointSize: 16,
    resolution: (75, 75),
    boundingBox: (16, 16, 0, -2));

font.Glyphs.Add(new BdfGlyph(
    name: "A",
    encoding: 65,
    scalableWidth: (500, 0),
    deviceWidth: (8, 0),
    boundingBox: (8, 16, 0, -2),
    bitmap: [
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 1, 1, 0, 0, 0],
        [0, 0, 1, 0, 0, 1, 0, 0],
        [0, 0, 1, 0, 0, 1, 0, 0],
        [0, 1, 0, 0, 0, 0, 1, 0],
        [0, 1, 0, 0, 0, 0, 1, 0],
        [0, 1, 1, 1, 1, 1, 1, 0],
        [0, 1, 0, 0, 0, 0, 1, 0],
        [0, 1, 0, 0, 0, 0, 1, 0],
        [0, 1, 0, 0, 0, 0, 1, 0],
        [0, 1, 0, 0, 0, 0, 1, 0],
        [0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0]
    ]));

font.Properties.Foundry = "Pixel Font Studio";
font.Properties.FamilyName = "My Font";
font.Properties.WeightName = "Medium";
font.Properties.Slant = "R";
font.Properties.SetWidthName = "Normal";
font.Properties.AddStyleName = "Sans Serif";
font.Properties.PixelSize = font.PointSize;
font.Properties.PointSize = font.PointSize * 10;
font.Properties.ResolutionX = font.ResolutionX;
font.Properties.ResolutionY = font.ResolutionY;
font.Properties.Spacing = "P";
font.Properties.AverageWidth = Convert.ToInt32(Math.Round(font.Glyphs.Sum(glyph => glyph.DeviceWidthX * 10) / Convert.ToDouble(font.Glyphs.Count)));
font.Properties.CharsetRegistry = "ISO10646";
font.Properties.CharsetEncoding = "1";
font.GenerateNameAsXlfd();

font.Properties.DefaultChar = -1;
font.Properties.FontAscent = 14;
font.Properties.FontDescent = 2;
font.Properties.XHeight = 7;
font.Properties.CapHeight = 10;

font.Properties.FontVersion = "1.0.0";
font.Properties.Copyright = "Copyright (c) TakWolf";

font.Save(Path.Combine(outputsDir, "my-font.bdf"));

Load

using BdfSpec;

var outputsDir = Path.Combine("build");
if (Directory.Exists(outputsDir))
{
    Directory.Delete(outputsDir, true);
}
Directory.CreateDirectory(outputsDir);

var font = BdfFont.Load(Path.Combine("assets", "unifont", "unifont-16.0.02.bdf"));
Console.WriteLine($"name: {font.Name}");
Console.WriteLine($"size: {font.PointSize}");
Console.WriteLine($"ascent: {font.Properties.FontAscent}");
Console.WriteLine($"descent: {font.Properties.FontDescent}");
Console.WriteLine();
foreach (var glyph in font.Glyphs)
{
    Console.WriteLine($"char: {char.ConvertFromUtf32(glyph.Encoding)} ({glyph.Encoding:X4})");
    Console.WriteLine($"glyphName: {glyph.Name}");
    Console.WriteLine($"advanceWidth: {glyph.DeviceWidthX}");
    Console.WriteLine($"dimensions: {glyph.Dimensions}");
    Console.WriteLine($"offset: {glyph.Offset}");
    foreach (var bitmapRow in glyph.Bitmap)
    {
        var text = string.Join("", bitmapRow).Replace("0", "  ").Replace("1", "██");
        Console.WriteLine($"{text}*");
    }
    Console.WriteLine();
}
font.Save(Path.Combine(outputsDir, "unifont-16.0.02.bdf"));

Test Fonts

References

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.2 230 4/6/2025
0.0.1 636 3/24/2025