From 81b6cdf0d2fce00bd33bc273ce2daf0ce08eb258 Mon Sep 17 00:00:00 2001 From: nrq6993-a11y Date: Thu, 15 Oct 2026 03:15:08 +0300 Subject: [PATCH 1/2] text: apply anti-alias mode shaping when rasterizing type Photoshop's Sharp/Crisp/Strong/Smooth settings only changed metadata; shape edge coverage per mode (fixes storytold/photocraft#5902). Co-authored-by: Cursor --- crates/text/src/render.rs | 24 +++++++++++++++++++++++- crates/text/src/tests.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/crates/text/src/render.rs b/crates/text/src/render.rs index af29dd10d6..7fff345a6d 100644 --- a/crates/text/src/render.rs +++ b/crates/text/src/render.rs @@ -19,6 +19,28 @@ pub const FAUX_BOLD_RADIUS: f32 = 0.036; /// Largest raster we produce (pixels), as a guard against absurd sizes. const MAX_PIXELS: u64 = 256 * 1024 * 1024; +/// Maps raw area-coverage to the opacity Photoshop's anti-alias modes imply. Exponents above 1 thin +/// the fringe (sharper); below 1 widen it (stronger smoothing). +fn shape_antialias_coverage(cv: f32, mode: AntiAlias) -> f32 { + if !cv.is_finite() { + return 0.0; + } + let cv = cv.clamp(0.0, 1.0); + match mode { + AntiAlias::None => { + if cv >= 0.5 { + 1.0 + } else { + 0.0 + } + } + AntiAlias::Smooth => cv, + AntiAlias::Strong => cv.powf(0.55), + AntiAlias::Crisp => cv.powf(1.35), + AntiAlias::Sharp | AntiAlias::Windows | AntiAlias::WindowsLcd => cv.powf(2.2), + } +} + /// Rendered text: pixels in document space plus the covered rectangle. pub struct Rendered { pub surface: Surface, @@ -277,7 +299,7 @@ pub fn rasterize_warped(layout: &TextLayout, transform: &Affine, format: PixelFo let comps = color_in(&format, c); let a = c.alpha.clamp(0.0, 1.0); for (i, &cv) in cov.iter().enumerate() { - let cv = if antialias == AntiAlias::None { if cv >= 0.5 { 1.0 } else { 0.0 } } else { cv }; + let cv = shape_antialias_coverage(cv, antialias); let s = cv * a; if s <= 0.0 { continue; diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rs index 13de665ccd..c6cc6b2ce4 100644 --- a/crates/text/src/tests.rs +++ b/crates/text/src/tests.rs @@ -1930,6 +1930,35 @@ fn engine_data_antialias_numbers_match_photoshop() { } } +/// Anti-alias modes must change edge coverage (storytold/photocraft#5902). +#[test] +fn antialias_modes_change_edge_fringe() { + use photocraft_doc::text::AntiAlias; + + let fringe_mass = |mode: AntiAlias| { + let mut e = TextEngine::new(); + let layer = TextLayer { antialias: mode, ..point("O", 48.0) }; + let (_, r) = e.render(&layer, 72.0, PixelFormat::RGBA8); + let n = r.surface.channels(); + r.surface + .read_region(r.rect) + .chunks_exact(n) + .map(|p| f64::from(p[n - 1])) + .filter(|&a| a > 0.02 && a < 0.98) + .sum::() + }; + + let none = fringe_mass(AntiAlias::None); + let sharp = fringe_mass(AntiAlias::Sharp); + let smooth = fringe_mass(AntiAlias::Smooth); + let strong = fringe_mass(AntiAlias::Strong); + + assert_eq!(none, 0.0, "aliased-off edges are hard"); + assert!(strong > smooth + 1.0, "strong smooths more than smooth: {strong} vs {smooth}"); + assert!(smooth > sharp + 0.5, "sharp thins the fringe vs smooth: {sharp} vs {smooth}"); + assert!(sharp > 0.0); +} + /// Type on a path (#218): along a vertical line the type runs top to bottom with its glyphs /// turned, along a curve it follows the curve, and glyphs beyond the end are not drawn. #[test] From 801e229d762e2ae71c3760b999c3373492675798 Mon Sep 17 00:00:00 2001 From: nrq6993-a11y Date: Fri, 16 Oct 2026 06:47:56 +0300 Subject: [PATCH 2/2] style(text): rustfmt antialias fringe_mass chain for #5902 (PR #5907) --- crates/text/src/tests.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rs index c6cc6b2ce4..d9ad588d1a 100644 --- a/crates/text/src/tests.rs +++ b/crates/text/src/tests.rs @@ -1940,12 +1940,7 @@ fn antialias_modes_change_edge_fringe() { let layer = TextLayer { antialias: mode, ..point("O", 48.0) }; let (_, r) = e.render(&layer, 72.0, PixelFormat::RGBA8); let n = r.surface.channels(); - r.surface - .read_region(r.rect) - .chunks_exact(n) - .map(|p| f64::from(p[n - 1])) - .filter(|&a| a > 0.02 && a < 0.98) - .sum::() + r.surface.read_region(r.rect).chunks_exact(n).map(|p| f64::from(p[n - 1])).filter(|&a| a > 0.02 && a < 0.98).sum::() }; let none = fringe_mass(AntiAlias::None);