Text: touching glyphs join without a seam (#415)

Cause: each glyph's fill was rasterised and composited on its own, so
where two glyphs share an edge (the crossbars of "ff") two half-covered
pixels composited to 0.75 coverage instead of 1: a thin light seam,
where After Effects draws the line as one outline.

Fix: consecutive fill passes of the same opaque colour, without Blur,
under Normal Inter-Character Blending are rasterised as one coverage
mask (the glyphs' outlines in layer space, wound the same way so
overlaps add up under NonZero). Characters of other colours, translucent
or blurred ones, strokes and the other blending modes are drawn one by
one as before.

Tests: text::tests::touching_glyphs_join_without_a_seam (two glyphs
sharing an edge mid-pixel: 0.75 before, 1.0 now; opposite windings and
overlaps stay filled; other colours and Multiply still composite one by
one).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-09 23:17:32 +07:00
co-authored by Claude Opus 5.5
parent 2a460986ee
commit 88e2e6470a
3 changed files with 104 additions and 15 deletions
+41
View File
@@ -485,3 +485,44 @@ fn caret_follows_animators_and_path_text() {
let glyph_c = glyph_paths(&c, ly).iter().map(|g| effectcraft_path::bounds(std::slice::from_ref(&g.0)).unwrap().center().y).collect::<Vec<_>>();
assert!(qt.y > glyph_c[1] && qt.y < glyph_c[2], "between the 2nd and 3rd characters: {} in {glyph_c:?}", qt.y);
}
/// Glyphs that touch or overlap are drawn as one outline, as After Effects draws a line of text:
/// no light seam where their anti-aliased edges meet (the crossbars of "ff", #415).
#[test]
fn touching_glyphs_join_without_a_seam() {
use kurbo::Shape;
let glyph = |x0: f64, x1: f64, fill: [f32; 4], reversed: bool| {
let path = kurbo::Rect::new(x0, 4.0, x1, 16.0).to_path(0.1);
PlacedGlyph {
local: if reversed { path.reverse_subpaths() } else { path },
m: Mat4::IDENTITY,
xf: CharXf::default(),
fill,
stroke: [0.0; 4],
stroke_width: 0.0,
apply_fill: true,
char_index: 0,
rest: [0.0; 2],
}
};
let draw = |glyphs: Vec<PlacedGlyph>, blend: BlendMode| {
let geom = TextGeom { doc: TextDoc::default(), glyphs, fill_stroke: 0, blend };
let mut img = crate::Image::new(24, 20);
draw_glyphs(&geom, &mut img, &Mat3::IDENTITY, 1.0, None);
img
};
let (white, red) = ([1.0; 4], [1.0, 0.0, 0.0, 1.0]);
// The shared edge runs through the middle of pixel column 10.
let seam = draw(vec![glyph(4.0, 10.5, white, false), glyph(10.5, 17.0, white, false)], BlendMode::Normal).get(10, 10);
assert!(seam[3] > 0.999 && seam[0] > 0.999, "touching glyphs leave no seam: {seam:?}");
// Outlines wound the other way (another font, a mirrored character) still add up.
let seam = draw(vec![glyph(4.0, 10.5, white, false), glyph(10.5, 17.0, white, true)], BlendMode::Normal).get(10, 10);
assert!(seam[3] > 0.999, "opposite windings join too: {seam:?}");
let overlap = draw(vec![glyph(4.0, 12.0, white, false), glyph(8.0, 17.0, white, true)], BlendMode::Normal).get(10, 10);
assert!(overlap[3] > 0.999, "and their overlap stays filled: {overlap:?}");
// Characters of other colours, or blended with each other, are still drawn one by one.
let two = draw(vec![glyph(4.0, 10.5, white, false), glyph(10.5, 17.0, red, false)], BlendMode::Normal).get(10, 10);
assert!((two[3] - 0.75).abs() < 0.02, "{two:?}");
let multiply = draw(vec![glyph(4.0, 10.5, white, false), glyph(10.5, 17.0, white, false)], BlendMode::Multiply).get(10, 10);
assert!(multiply[3] < 0.9, "{multiply:?}");
}