feat(font): add the FreeType-only font backend (font-backend-freetype)
Ghostty can be built with -Dfont-backend=freetype, which uses FreeType without any font discovery. The Rust port only had fontconfig+freetype (default on Linux) and the CoreText variants. The new cargo feature `font-backend-freetype` on ghostty-font (forwarded by ghostty-cli and the root crate; non-Apple, non-wasm targets) behaves like Zig's mode: font-family discovery, fallback search and codepoint-map overrides are skipped (embedded fonts only); +list-fonts and +show-face print Zig's "built without a font discovery mechanism" message and exit 1; +version reports `.freetype`. The default backend is unchanged. Also registers the Rust-only benchmark tooling extensions (--time, --handler=full, ghostty-synthetic +sgr) in DEVIANT_FIXES.md. Note: `--all-features` now selects this backend for the workspace. Test Plan: - cargo test -p ghostty-font --features font-backend-freetype (198) - cargo build --features font-backend-freetype && ghostty +list-fonts
This commit is contained in:
1 parent
ebd603f3da
commit
ff1169abed
18 files changed
+327
-12
No files matched your search
@@ -4,6 +4,11 @@ use ghostty_config::config_struct;
|
||||
|
||||
use crate::error::Error;
|
||||
|
||||
/// Printed (without a trailing newline) by `+list-fonts` and `+show-face`
|
||||
/// when the build has no font discovery mechanism (Zig `Discover == void`,
|
||||
/// the `freetype` font backend).
|
||||
pub(crate) const NO_DISCOVERY_MESSAGE: &str = "Ghostty was built without a font discovery mechanism. This is a compile-time\noption. Please review how Ghostty was built from source, contact the\nmaintainer to enable a font discovery mechanism, and try again.";
|
||||
|
||||
config_struct! {
|
||||
pub struct Options {
|
||||
/// The font family to search for. If this is set, then only fonts
|
||||
@@ -51,6 +56,14 @@ pub fn run(args: &[impl AsRef<[u8]>]) -> Result<u8, Error> {
|
||||
|
||||
use std::{collections::HashMap, io::Write};
|
||||
|
||||
// Its possible to build Ghostty without font discovery!
|
||||
if !ghostty_font::HAS_DISCOVERY {
|
||||
let mut stderr = crate::zig_writer::ZigWriter::new(crate::zig_writer::stderr_sink(), 1024);
|
||||
write!(stderr, "{NO_DISCOVERY_MESSAGE}")?;
|
||||
stderr.flush()?;
|
||||
return Ok(1);
|
||||
}
|
||||
|
||||
// We'll be putting our fonts into a list categorized by family
|
||||
// so it is easier to read the output.
|
||||
let mut families: Vec<String> = Vec::new();
|
||||
@@ -118,3 +131,23 @@ pub fn run(args: &[impl AsRef<[u8]>]) -> Result<u8, Error> {
|
||||
stdout.flush()?;
|
||||
Ok(0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
/// Without a discovery mechanism (the `freetype` font backend, Zig
|
||||
/// `Discover == void`) `+list-fonts` prints the compile-time-option
|
||||
/// message and exits with 1, after parsing the arguments.
|
||||
#[cfg(feature = "font-backend-freetype")]
|
||||
#[test]
|
||||
fn freetype_backend_reports_no_discovery() {
|
||||
const { assert!(!ghostty_font::HAS_DISCOVERY) };
|
||||
assert_eq!(super::run(&[] as &[&[u8]]).expect("run"), 1);
|
||||
assert!(super::NO_DISCOVERY_MESSAGE.ends_with("try again."));
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "font-backend-freetype"))]
|
||||
#[test]
|
||||
fn default_backend_has_discovery() {
|
||||
const { assert!(ghostty_font::HAS_DISCOVERY) };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user