feat(font): port the Linux font engine
Ports the rest of ZIG/src/font for the freetype/fontconfig/harfbuzz backend: face loading and rasterization (synthetic bold/italic, color emoji bitmaps, glyph constraints for nerd font icons), fontconfig discovery, DeferredFace, Collection, CodepointResolver, CodepointMap, SharedGrid, opentype table parsers, the nerd font attribute table, and the harfbuzz shaper with feature parsing and shaping cache. Embedded fonts (JetBrains Mono 2.304 variable, Symbols Nerd Font 3.4.0, Noto emoji) and the test fonts from Ghostty live in res/ with their OFL/ MIT licenses. The crate opts into unsafe_code = "deny"; FFI is confined to ft.rs, fontconfig.rs and hb.rs with SAFETY comments. Glyph resampling uses an stb-style resampler that is not bit-identical to stb. Deferred to the next font pass (needs ghostty-terminal/config): shaper/run.zig, SharedGridSet.zig and the 23 terminal-driven shaper tests. Config-facing types are mirrored locally in config_types.rs. Test Plan: - cargo test -p ghostty-font (139 tests)
This commit is contained in:
1 parent
b9ac54e794
commit
fc7bb5c025
64 files changed
+35316
-23
No files matched your search
@@ -0,0 +1,91 @@
|
||||
//! Font backend selection. Port of `font/backend.zig`.
|
||||
//!
|
||||
//! The Rust rewrite only targets Linux, so [`OPTIONS`] always selects
|
||||
//! [`Backend::FontconfigFreetype`] (fontconfig discovery, FreeType rendering,
|
||||
//! HarfBuzz shaping). The other variants are kept for fidelity with the Zig
|
||||
//! enum and its helper predicates.
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Backend {
|
||||
/// FreeType for font rendering with no font discovery enabled.
|
||||
Freetype,
|
||||
/// Fontconfig for font discovery and FreeType for font rendering.
|
||||
FontconfigFreetype,
|
||||
/// CoreText for font discovery, rendering, and shaping (macOS).
|
||||
Coretext,
|
||||
/// CoreText for font discovery, FreeType for rendering, and
|
||||
/// HarfBuzz for shaping (macOS).
|
||||
CoretextFreetype,
|
||||
/// CoreText for font discovery and rendering, HarfBuzz for shaping
|
||||
CoretextHarfbuzz,
|
||||
/// CoreText for font discovery and rendering, no shaping.
|
||||
CoretextNoshape,
|
||||
/// Use the browser font system and the Canvas API (wasm).
|
||||
WebCanvas,
|
||||
}
|
||||
|
||||
impl Backend {
|
||||
/// Returns the default backend for a build environment.
|
||||
pub fn default_for_target() -> Backend {
|
||||
if cfg!(target_os = "macos") {
|
||||
Backend::Coretext
|
||||
} else {
|
||||
Backend::FontconfigFreetype
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_freetype(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Backend::Freetype | Backend::FontconfigFreetype | Backend::CoretextFreetype
|
||||
)
|
||||
}
|
||||
|
||||
pub fn has_coretext(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Backend::Coretext
|
||||
| Backend::CoretextFreetype
|
||||
| Backend::CoretextHarfbuzz
|
||||
| Backend::CoretextNoshape
|
||||
)
|
||||
}
|
||||
|
||||
pub fn has_fontconfig(self) -> bool {
|
||||
matches!(self, Backend::FontconfigFreetype)
|
||||
}
|
||||
|
||||
pub fn has_harfbuzz(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Backend::Freetype
|
||||
| Backend::FontconfigFreetype
|
||||
| Backend::CoretextFreetype
|
||||
| Backend::CoretextHarfbuzz
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Build options (the `font.options` of Zig).
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Options {
|
||||
pub backend: Backend,
|
||||
}
|
||||
|
||||
pub const OPTIONS: Options = Options {
|
||||
backend: Backend::FontconfigFreetype,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn linux_backend_capabilities() {
|
||||
let b = OPTIONS.backend;
|
||||
assert!(b.has_freetype());
|
||||
assert!(b.has_fontconfig());
|
||||
assert!(b.has_harfbuzz());
|
||||
assert!(!b.has_coretext());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user