diff --git a/src/font/embedded.zig b/src/font/embedded.zig index 098aa3eb4..31b07ff31 100644 --- a/src/font/embedded.zig +++ b/src/font/embedded.zig @@ -34,3 +34,6 @@ pub const cozette = @embedFile("res/CozetteVector.ttf"); /// Monaspace has weird ligature behaviors we want to test in our shapers /// so we embed it here. pub const monaspace_neon = @embedFile("res/MonaspaceNeon-Regular.otf"); + +/// Terminus TTF is a scalable font with bitmap glyphs at various sizes. +pub const terminus_ttf = @embedFile("res/TerminusTTF-Regular.ttf"); diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index 3f180ad68..0a822cbc7 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -996,3 +996,55 @@ test "svg font table" { try testing.expectEqual(430, table.len); } + +const terminus_i = + \\........ + \\........ + \\...#.... + \\...#.... + \\........ + \\..##.... + \\...#.... + \\...#.... + \\...#.... + \\...#.... + \\...#.... + \\..###... + \\........ + \\........ + \\........ + \\........ +; +// Including the newline +const terminus_i_pitch = 9; + +test "bitmap glyph" { + const alloc = testing.allocator; + const testFont = font.embedded.terminus_ttf; + + var lib = try Library.init(); + defer lib.deinit(); + + var atlas = try font.Atlas.init(alloc, 512, .grayscale); + defer atlas.deinit(alloc); + + // Any glyph at 12pt @ 96 DPI is a bitmap + var ft_font = try Face.init(lib, testFont, .{ .size = .{ .points = 12 } }); + defer ft_font.deinit(); + + // glyph 77 = 'i' + const glyph = try ft_font.renderGlyph(alloc, &atlas, 77, .{}); + + // should render crisp + try testing.expectEqual(8, glyph.width); + try testing.expectEqual(16, glyph.height); + for (0..glyph.height) |y| { + for (0..glyph.width) |x| { + const pixel = terminus_i[y * terminus_i_pitch + x]; + try testing.expectEqual( + @as(u8, if (pixel == '#') 255 else 0), + atlas.data[(glyph.atlas_y + y) * atlas.size + (glyph.atlas_x + x)], + ); + } + } +} diff --git a/src/font/res/README.md b/src/font/res/README.md index 3195a8916..5ad4b274f 100644 --- a/src/font/res/README.md +++ b/src/font/res/README.md @@ -25,6 +25,9 @@ This project uses several fonts which fall under the SIL Open Font License (OFL- - [Copyright 2013 Google LLC](https://github.com/googlefonts/noto-emoji/blob/main/LICENSE) - Cozette (MIT) - [Copyright (c) 2020, Slavfox](https://github.com/slavfox/Cozette/blob/main/LICENSE) +- Terminus TTF (OFL-1.1) + - [Copyright (c) 2010-2020 Dimitar Toshkov Zhekov with Reserved Font Name "Terminus Font"](https://sourceforge.net/projects/terminus-font/) + - [Copyright (c) 2011-2023 Tilman Blumenbach with Reserved Font Name "Terminus (TTF)"](https://files.ax86.net/terminus-ttf/) A full copy of the OFL license can be found at [OFL.txt](./OFL.txt). An accompanying FAQ is also available at . diff --git a/src/font/res/TerminusTTF-Regular.ttf b/src/font/res/TerminusTTF-Regular.ttf new file mode 100644 index 000000000..d125e6347 Binary files /dev/null and b/src/font/res/TerminusTTF-Regular.ttf differ