mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
font/freetype: Add test for crisp bitmap font rendering
Now we can be certain that bitmap fonts stay crisp. :^)
This commit is contained in:
@ -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");
|
||||
|
@ -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)],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 <https://openfontlicense.org/>.
|
||||
|
BIN
src/font/res/TerminusTTF-Regular.ttf
Normal file
BIN
src/font/res/TerminusTTF-Regular.ttf
Normal file
Binary file not shown.
Reference in New Issue
Block a user