PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Type: imported PSD tabs render as whitespace, not a box (#1942)
Nigel Ihza Firdausy3eef2c6bb48f
diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rsindex 01b999d8c..df89f77c9 100644--- a/crates/text/src/layout.rs+++ b/crates/text/src/layout.rs@@ -495,6 +495,13 @@ impl Layouter {ptext.push('\n');continue;}+ // Imported PSD text can contain literal tab controls. Font shaping may+ // render those as .notdef boxes; a space preserves the one-byte source+ // and style/caret offsets while supplying a real whitespace advance.+ if ch == '\t' {+ ptext.push(' ');+ continue;+ }let style = &out.styles[style_at(prange.start + i)];let caps = style.caps;if caps == Caps::AllCaps || small_caps[style_at(prange.start + i)] == SmallCapsMode::Synthetic {diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rsindex 624839ed4..bbb21dc08 100644--- a/crates/text/src/tests.rs+++ b/crates/text/src/tests.rs@@ -47,6 +47,19 @@ fn registering_fonts_moves_the_generation() {assert!(fonts::generation() > g);}+#[test]+fn literal_psd_tabs_shape_as_whitespace_without_shifting_text_offsets() {+ let mut e = TextEngine::new();+ let src = "A\tB";+ let l = e.layout(&point(src, 20.0), 72.0);+ let plain = e.layout(&point("AB", 20.0), 72.0);+ assert_eq!(l.lines.len(), 1);+ assert!(l.glyphs.iter().all(|g| g.id != 0), "a tab must not render a tofu glyph");+ assert!(width(&l) > width(&plain), "the tab reserves whitespace");+ assert!(l.clusters.iter().all(|c| c.range.end <= src.len()), "the source byte offsets stay valid");+ assert!(l.caret(2).0 > l.caret(1).0, "caret moves across the tab");+}+#[test]fn metrics_are_stable_and_scale_with_dpi() {let mut e = TextEngine::new();