Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/unreleased/2026-11-28-headless-font-smoothing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Tooling: deterministic headless `FontSmoothing::On` and `--font-smoothing MODE` CLI flag.** Headless runs (`--snap`, `--frames`, `--video`, `--strip`, `--desktop`, `--snap-on-patch`, `App::headless_runtime`) no longer downgrade `FontSmoothing::On` to `Off` when the host Mac has `AppleFontSmoothing = 0` (globally or in `-currentHost` / ByHost preferences), matching how headless isolates theme, scale, scroll bars and accessibility preferences from the machine's user settings. Added `--font-smoothing MODE` (`on`, `off`, `windfoil`, `windfoil-chromium`, `windfoil-rgb`, `slug`, `hinted-gpu`, `hinted`, `direct-write`, `clear-type`) to override an app's font smoothing from the command line without rebuilding.
37 changes: 36 additions & 1 deletion crates/rune-text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ pub struct TextSystem {
pub smoothing: FontSmoothing,
/// The mode the app asked for ([`Self::set_font_smoothing`]).
requested: FontSmoothing,
/// Whether `FontSmoothing::On` honours the host macOS `AppleFontSmoothing` user setting
/// (`true` for live windows; `false` for deterministic headless runs and explicit overrides).
respect_user_smoothing: bool,
/// The `trak` table of the first font of a family slot at a weight, upright or italic.
primary_traks: FxHashMap<(Family, u32, bool), Option<Rc<Trak>>>,
/// The hidden-axis coordinates (`hidden_axes`) of the same first font.
Expand Down Expand Up @@ -537,6 +540,7 @@ impl TextSystem {
traks: Traks::new(),
smoothing: FontSmoothing::default(),
requested: FontSmoothing::default(),
respect_user_smoothing: true,
primary_traks: Default::default(),
primary_axes: Default::default(),
apple: Default::default(),
Expand Down Expand Up @@ -705,11 +709,42 @@ impl TextSystem {
pub fn set_font_smoothing(&mut self, mode: FontSmoothing) {
self.requested = mode;
self.smoothing = mode.drawn(self.lcd_ok());
self.apple.set_pipeline(self.smoothing.pipeline());
self.apple.set_pipeline(self.effective_pipeline(self.smoothing));
self.atlas.lcd = self.smoothing.lcd();
self.atlas.lcd_wanted = mode.lcd();
}

fn effective_pipeline(&self, mode: FontSmoothing) -> ApplePipeline {
if self.respect_user_smoothing {
mode.pipeline()
} else {
mode.pipeline_with_user_smoothing(true)
}
}

/// Controls whether [`FontSmoothing::On`] honours the host macOS `AppleFontSmoothing` user
/// setting (`true` by default, matching live AppKit/SwiftUI windows; `false` for
/// deterministic headless snapshots and explicit `--font-smoothing` overrides so `On`
/// always dilates regardless of the machine's `AppleFontSmoothing` preference). Re-applies
/// the active mode's pipeline immediately and returns whether it changed.
#[doc(hidden)]
pub fn set_respect_user_font_smoothing(&mut self, respect: bool) -> bool {
if self.respect_user_smoothing == respect {
return false;
}
self.respect_user_smoothing = respect;
let next = self.effective_pipeline(self.smoothing);
let changed = self.apple.pipeline() != next;
self.apple.set_pipeline(next);
changed
}

/// Whether [`FontSmoothing::On`] honours the host macOS `AppleFontSmoothing` preference.
#[doc(hidden)]
pub fn respect_user_font_smoothing(&self) -> bool {
self.respect_user_smoothing
}

/// Whether subpixel text draws here now: the renderer draws outlines and blends by channel,
/// and for ClearType, DirectWrite is there.
fn lcd_ok(&mut self) -> bool {
Expand Down
8 changes: 7 additions & 1 deletion crates/rune-text/src/raster/coretext_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,14 @@ impl FontSmoothing {
/// `On` draws as `Off` when the user turned smoothing off (`AppleFontSmoothing` 0), as AppKit
/// and SwiftUI then do.
pub fn pipeline(self) -> ApplePipeline {
self.pipeline_with_user_smoothing(smoothing_allowed_by_user())
}

/// [`Self::pipeline`] with macOS's `AppleFontSmoothing` user setting supplied explicitly
/// (`true` ignores a host `AppleFontSmoothing = 0`, as deterministic headless snapshots do).
pub(crate) fn pipeline_with_user_smoothing(self, user_smoothing_allowed: bool) -> ApplePipeline {
match self {
FontSmoothing::On if !smoothing_allowed_by_user() => ApplePipeline::UNSMOOTHED,
FontSmoothing::On if !user_smoothing_allowed => ApplePipeline::UNSMOOTHED,
FontSmoothing::On | FontSmoothing::Windfoil => ApplePipeline::SMOOTHED,
_ => ApplePipeline::UNSMOOTHED,
}
Expand Down
28 changes: 28 additions & 0 deletions crates/rune-text/src/raster/coretext_match_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,31 @@ fn off_draws_coverage_as_is_on_apple_platforms() {
assert_eq!(text.coverage_exponent([0.9, 0.9, 0.9, 1.0]), 1.0, "a window on this Mac draws Off as is");
}
}

#[test]
fn pipeline_with_user_smoothing_controls_on_without_changing_other_modes() {
assert_eq!(FontSmoothing::On.pipeline_with_user_smoothing(true), ApplePipeline::SMOOTHED);
assert_eq!(FontSmoothing::On.pipeline_with_user_smoothing(false), ApplePipeline::UNSMOOTHED);
assert_eq!(FontSmoothing::Off.pipeline_with_user_smoothing(true), ApplePipeline::UNSMOOTHED);
assert_eq!(FontSmoothing::Off.pipeline_with_user_smoothing(false), ApplePipeline::UNSMOOTHED);
assert_eq!(FontSmoothing::Windfoil.pipeline_with_user_smoothing(true), ApplePipeline::SMOOTHED);
assert_eq!(FontSmoothing::Windfoil.pipeline_with_user_smoothing(false), ApplePipeline::SMOOTHED);
}

#[test]
fn ignoring_user_font_smoothing_keeps_on_smoothed_and_off_unsmoothed() {
let mut text = TextSystem::default();
assert!(text.respect_user_font_smoothing());
text.set_font_smoothing(FontSmoothing::On);
// Simulate a host whose AppleFontSmoothing = 0 downgraded On's pipeline to UNSMOOTHED.
text.set_apple_pipeline(ApplePipeline::UNSMOOTHED);
assert!(text.set_respect_user_font_smoothing(false), "disabling user preference restores SMOOTHED immediately");
assert!(!text.respect_user_font_smoothing());
assert_eq!(text.apple_pipeline(), ApplePipeline::SMOOTHED);
assert!(!text.set_respect_user_font_smoothing(false), "setting the same flag is a no-op");

text.set_font_smoothing(FontSmoothing::Off);
assert_eq!(text.apple_pipeline(), ApplePipeline::UNSMOOTHED);
text.set_font_smoothing(FontSmoothing::On);
assert_eq!(text.apple_pipeline(), ApplePipeline::SMOOTHED);
}
9 changes: 9 additions & 0 deletions crates/rune/src/app/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub(crate) struct RuntimeConfig<S: 'static> {
pub(crate) tab_visits_controls: bool,
pub(crate) srgb_blend: bool,
pub(crate) font_smoothing: crate::FontSmoothing,
pub(crate) respect_user_font_smoothing: bool,
pub(crate) emoji_family: Option<String>,
pub(crate) max_native_materials: usize,
pub(crate) reveal_fps: f32,
Expand Down Expand Up @@ -86,6 +87,7 @@ impl<S: 'static> Clone for RuntimeConfig<S> {
tab_visits_controls: self.tab_visits_controls,
srgb_blend: self.srgb_blend,
font_smoothing: self.font_smoothing,
respect_user_font_smoothing: self.respect_user_font_smoothing,
emoji_family: self.emoji_family.clone(),
max_native_materials: self.max_native_materials,
reveal_fps: self.reveal_fps,
Expand All @@ -110,6 +112,7 @@ impl<S: 'static> Default for RuntimeConfig<S> {
tab_visits_controls: false,
srgb_blend: true,
font_smoothing: crate::FontSmoothing::default(),
respect_user_font_smoothing: true,
emoji_family: None,
max_native_materials: crate::MAX_NATIVE_MATERIALS,
reveal_fps: 0.0,
Expand All @@ -126,6 +129,7 @@ pub(crate) struct CoreConfig {
pub(crate) tab_visits_controls: bool,
pub(crate) srgb_blend: bool,
pub(crate) font_smoothing: crate::FontSmoothing,
pub(crate) respect_user_font_smoothing: bool,
pub(crate) emoji_family: Option<String>,
pub(crate) max_native_materials: usize,
pub(crate) wheel_glide: bool,
Expand All @@ -141,6 +145,7 @@ impl crate::runtime::RuntimeCore {
tab_visits_controls,
srgb_blend,
font_smoothing,
respect_user_font_smoothing,
emoji_family,
max_native_materials,
wheel_glide,
Expand All @@ -151,6 +156,7 @@ impl crate::runtime::RuntimeCore {
self.set_media_keys(media_keys);
self.set_tab_visits_controls(tab_visits_controls);
self.set_srgb_blend(srgb_blend);
self.set_respect_user_font_smoothing(respect_user_font_smoothing);
self.set_font_smoothing(font_smoothing);
if let Some(emoji) = emoji_family {
self.set_emoji_family(Some(&emoji));
Expand All @@ -177,6 +183,7 @@ impl<S: 'static> Runtime<S> {
tab_visits_controls,
srgb_blend,
font_smoothing,
respect_user_font_smoothing,
emoji_family,
max_native_materials,
reveal_fps,
Expand All @@ -197,6 +204,7 @@ impl<S: 'static> Runtime<S> {
tab_visits_controls,
srgb_blend,
font_smoothing,
respect_user_font_smoothing,
emoji_family,
max_native_materials,
wheel_glide,
Expand Down Expand Up @@ -410,6 +418,7 @@ mod tests {
assert!(cfg.srgb_blend);
assert!(!cfg.modifier_keys && !cfg.media_keys && !cfg.tab_visits_controls);
assert_eq!(cfg.font_smoothing, FontSmoothing::default());
assert!(cfg.respect_user_font_smoothing);
assert_eq!(cfg.emoji_family, None);
assert_eq!(cfg.max_native_materials, crate::MAX_NATIVE_MATERIALS);
assert_eq!(cfg.reveal_fps, 0.0);
Expand Down
4 changes: 3 additions & 1 deletion crates/rune/src/hot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ fn control_input_core(core: &mut RuntimeCore, app: &mut dyn AppDriver, command:
/// `{"id":3,"pause":true}`, `{"id":4,"step":0.05}`, or `{"id":5,"quit":true}`.
/// Every request and patch publishes a PNG + JSON tree, then a flushed completion marker.
#[inline]
fn headless<S: 'static>(spec: &AppSpec<S>, state: S, args: Args, runtime: crate::app::RuntimeConfig<S>) {
fn headless<S: 'static>(spec: &AppSpec<S>, state: S, args: Args, mut runtime: crate::app::RuntimeConfig<S>) {
assert!(enabled(), "--snap-on-patch requires --hot or RUNE_HOT=1 (use scripts/rune-dev)");
runtime.respect_user_font_smoothing = false;
if let Some(mode) = args.font_smoothing { runtime.font_smoothing = mode; }
let size = args.size.unwrap_or(spec.size);
let scale = args.scale.unwrap_or(2.0);
let (wake, sleep) = std::sync::mpsc::channel();
Expand Down
3 changes: 2 additions & 1 deletion crates/rune/src/playground/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ impl<S: 'static> App<S> {
let playground = self.playground.take();
let (chrome, titlebar, borderless) = (self.chrome, self.titlebar, self.window_options.borderless);
crate::credentials::note_headless_runtime();
let (spec, state, _, runtime) = self.into_parts(None);
let (spec, state, _, mut runtime) = self.into_parts(None);
runtime.respect_user_font_smoothing = false;
let mut rt = crate::tooling::runtime_for_configured(&spec, state, size, env, std::sync::Arc::new(|| {}), Some(runtime));
if let Some(playground) = playground.filter(Playground::is_enabled) {
rt.attach_playground(Live::new(playground, &spec, false));
Expand Down
11 changes: 11 additions & 0 deletions crates/rune/src/runtime/paint/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ impl RuntimeCore {
self.text.font_smoothing()
}

pub(crate) fn set_respect_user_font_smoothing(&mut self, respect: bool) {
if self.text.set_respect_user_font_smoothing(respect) {
self.commit.dirty = true;
}
}

#[cfg(test)]
pub(crate) fn respect_user_font_smoothing(&self) -> bool {
self.text.respect_user_font_smoothing()
}

pub fn clear_color(&self) -> [f32; 4] {
if self.transparent {
if !self.host.backdrop_opaque_fallback {
Expand Down
4 changes: 3 additions & 1 deletion crates/rune/src/text/pixel_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ pub struct Harness {

impl Harness {
pub fn new() -> Result<Harness, String> {
Ok(Harness { gpu: Gpu::try_new(Gpu::instance(), None)?, text: text_system()?, renderer: None })
let mut text = text_system()?;
text.set_respect_user_font_smoothing(false);
Ok(Harness { gpu: Gpu::try_new(Gpu::instance(), None)?, text, renderer: None })
}

/// `cases` in `pair`'s colours on a `size` (points) canvas at `scale`.
Expand Down
23 changes: 23 additions & 0 deletions crates/rune/src/tooling/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Args {
pub scale: Option<f32>,
pub theme: Option<String>,
pub scroll_bars: Option<crate::ScrollBars>,
pub font_smoothing: Option<crate::FontSmoothing>,
pub script: Option<PathBuf>,
pub frames: Option<usize>,
pub start: f64,
Expand Down Expand Up @@ -219,6 +220,7 @@ impl Args {
Some(FlagId::Scale) => a.scale = Some(parse_scale(&val(&mut i)).unwrap_or_else(|e| die(&e))),
Some(FlagId::Theme) => a.theme = Some(val(&mut i)),
Some(FlagId::ScrollBars) => a.scroll_bars = Some(parse_scroll_bars(&val(&mut i)).unwrap_or_else(|e| die(&e))),
Some(FlagId::FontSmoothing) => a.font_smoothing = Some(parse_font_smoothing(&val(&mut i)).unwrap_or_else(|e| die(&e))),
Some(FlagId::Script) => a.script = Some(val(&mut i).into()),
Some(FlagId::Frames) => a.frames = Some(num(&val(&mut i)) as usize),
Some(FlagId::Start) => {
Expand Down Expand Up @@ -370,6 +372,8 @@ pub(super) const HELP: &str = "usage: <app> [window]
--size WxH viewport in points --scale N device scale (default 2)
--theme dark|light system appearance
--scroll-bars MODE scroll bars: when-scrolling (headless default), always, automatic
--font-smoothing MODE font smoothing: on, off, windfoil, windfoil-chromium, windfoil-rgb,
slug, hinted-gpu, hinted, direct-write, clear-type
--script FILE.json timestamped input, replayed headless (move/down/up/tap/drag, keys,
{\"focus\":false}); a key with \"repeat\":true is a held key's auto-repeat;
{\"type\":\"mark\",\"name\":N} marks a time;
Expand Down Expand Up @@ -456,3 +460,22 @@ pub(crate) fn parse_scroll_bars(v: &str) -> Result<crate::ScrollBars, String> {
_ => Err(format!("--scroll-bars is when-scrolling, always or automatic: {v}")),
}
}

pub(crate) fn parse_font_smoothing(v: &str) -> Result<crate::FontSmoothing, String> {
use crate::FontSmoothing;
match v.trim().to_ascii_lowercase().as_str() {
"on" => Ok(FontSmoothing::On),
"off" => Ok(FontSmoothing::Off),
"windfoil" => Ok(FontSmoothing::Windfoil),
"windfoil-chromium" | "windfoilchromium" => Ok(FontSmoothing::WindfoilChromium),
"windfoil-rgb" | "windfoilrgb" => Ok(FontSmoothing::WindfoilRgb),
"slug" => Ok(FontSmoothing::Slug),
"hinted-gpu" | "hintedgpu" => Ok(FontSmoothing::HintedGpu),
"hinted" => Ok(FontSmoothing::Hinted),
"direct-write" | "directwrite" => Ok(FontSmoothing::DirectWrite),
"clear-type" | "cleartype" => Ok(FontSmoothing::ClearType),
_ => Err(format!(
"--font-smoothing is on, off, windfoil, windfoil-chromium, windfoil-rgb, slug, hinted-gpu, hinted, direct-write or clear-type: {v}"
)),
}
}
39 changes: 39 additions & 0 deletions crates/rune/src/tooling/args_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn flags_and_parser_stay_synchronized() {
"--scale" => (vec![], Some("2")),
"--theme" => (vec![], Some("dark")),
"--scroll-bars" => (vec![], Some("always")),
"--font-smoothing" => (vec![], Some("off")),
"--script" => (vec![], Some("script.json")),
"--frames" | "--every" | "--cols" | "--cpu-boot-threads" => (vec![], Some("4")),
"--fps" => (vec![], Some("60")),
Expand Down Expand Up @@ -290,3 +291,41 @@ fn flags_empty_without_dev_tooling() {
#[cfg(not(any(feature = "tooling", feature = "hot", debug_assertions)))]
assert!(flags().is_empty());
}

#[test]
fn font_smoothing_flag_parses_all_modes_and_rejects_unknown() {
use super::args::parse_font_smoothing;
use crate::FontSmoothing;

let cases = [
("on", FontSmoothing::On),
("On", FontSmoothing::On),
("off", FontSmoothing::Off),
("OFF", FontSmoothing::Off),
("windfoil", FontSmoothing::Windfoil),
("windfoil-chromium", FontSmoothing::WindfoilChromium),
("WindfoilChromium", FontSmoothing::WindfoilChromium),
("windfoil-rgb", FontSmoothing::WindfoilRgb),
("WindfoilRgb", FontSmoothing::WindfoilRgb),
("slug", FontSmoothing::Slug),
("hinted-gpu", FontSmoothing::HintedGpu),
("HintedGpu", FontSmoothing::HintedGpu),
("hinted", FontSmoothing::Hinted),
("direct-write", FontSmoothing::DirectWrite),
("DirectWrite", FontSmoothing::DirectWrite),
("clear-type", FontSmoothing::ClearType),
("ClearType", FontSmoothing::ClearType),
];
for (raw, expected) in cases {
assert_eq!(parse_font_smoothing(raw), Ok(expected), "parse {raw:?}");
let args = Args::parse_from(vec_s(&["--font-smoothing", raw]));
assert_eq!(args.font_smoothing, Some(expected), "argv {raw:?}");
}
// Every FontSmoothing::ALL variant is reachable by its Debug name.
for mode in FontSmoothing::ALL {
let name = format!("{mode:?}");
assert_eq!(parse_font_smoothing(&name), Ok(mode), "Debug name {name}");
}
assert!(parse_font_smoothing("unknown").is_err());
assert!(parse_font_smoothing("").is_err());
}
5 changes: 5 additions & 0 deletions crates/rune/src/tooling/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ define_flags! {
value: FlagValue::Required("MODE"),
description: "scroll bar mode: when-scrolling, always, or automatic",
},
FontSmoothing => {
name: "--font-smoothing",
value: FlagValue::Required("MODE"),
description: "font smoothing mode: on, off, windfoil, windfoil-chromium, windfoil-rgb, slug, hinted-gpu, hinted, direct-write, or clear-type",
},
Script => {
name: "--script",
value: FlagValue::Required("FILE.json"),
Expand Down
4 changes: 3 additions & 1 deletion crates/rune/src/tooling/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ fn try_headless_configured<S: 'static>(mut app: crate::app::App<S>, args: Args,
let wake = HeadlessWake::default();
let (spec, mut rt, shared, shortcuts, menus, state_ms) = {
let _startup = observability.scope_stages(None);
let (spec, state, shared, runtime) = app.into_parts(args.scene.as_deref());
let (spec, state, shared, mut runtime) = app.into_parts(args.scene.as_deref());
runtime.respect_user_font_smoothing = false;
if let Some(mode) = args.font_smoothing { runtime.font_smoothing = mode; }
shared.core.connect(wake.waker());
let shortcuts = crate::shortcuts::Guard::attach(&shared, wake.waker(), true, false);
let menus = crate::native_menu::MenuGuard::attach(&shared, true);
Expand Down
Loading
Loading