https://github.com/takwolf/bdffont-dotnet
A library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts
https://github.com/takwolf/bdffont-dotnet
bdf bitmap-font bitmap-fonts font fonts
Last synced: 11 months ago
JSON representation
A library for manipulating Glyph Bitmap Distribution Format (BDF) Fonts
- Host: GitHub
- URL: https://github.com/takwolf/bdffont-dotnet
- Owner: TakWolf
- License: mit
- Created: 2025-03-23T22:10:37.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-13T07:37:56.000Z (11 months ago)
- Last Synced: 2025-07-15T17:58:20.767Z (11 months ago)
- Topics: bdf, bitmap-font, bitmap-fonts, font, fonts
- Language: C#
- Homepage: https://www.nuget.org/packages/BdfFont
- Size: 3.88 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BdfFont.NET
[](https://dotnet.microsoft.com)
[](https://www.nuget.org/packages/BdfFont)
BdfFont is a library for manipulating [Glyph Bitmap Distribution Format (BDF) Fonts](https://en.wikipedia.org/wiki/Glyph_Bitmap_Distribution_Format).
## Installation
```shell
dotnet add package BdfFont
```
## Usage
### Create
```csharp
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(font.Glyphs.Average(glyph => glyph.DeviceWidthX * 10));
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.UnderlinePosition = -2;
font.Properties.UnderlineThickness = 1;
font.Properties.FontVersion = "1.0.0";
font.Properties.Copyright = "Copyright (c) TakWolf";
font.Save(Path.Combine(outputsDir, "my-font.bdf"));
```
### Load
```csharp
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.04.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.04.bdf"));
```
## References
- [X11 - Bitmap Distribution Format - Version 2.1](https://www.x.org/docs/BDF/bdf.pdf)
- [Adobe - Glyph Bitmap Distribution Format (BDF) Specification - Version 2.2](https://adobe-type-tools.github.io/font-tech-notes/pdfs/5005.BDF_Spec.pdf)
- [X Logical Font Description Conventions - X Consortium Standard](https://www.x.org/releases/current/doc/xorg-docs/xlfd/xlfd.html)
## License
[MIT License](LICENSE)