Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge main into rfx-text

vangel76eb1726fbb06b
diff --cc crates/text/src/layout.rs
index 646a0377a,8f6928885..b8e221274
--- a/crates/text/src/layout.rs
+++ b/crates/text/src/layout.rs
@@@ -628,7 -597,7 +628,15 @@@ fn run_at(runs: &[(Range<usize>, TextSt
}
/// Lay out one paragraph (no newlines) whose text starts at byte `base` of the whole string.
- fn paragraph(text: &str, base: usize, runs: &[(Range<usize>, TextStyle)], primaries: &[Resolved], para: &ParagraphStyle, width: Option<f32>) -> Vec<ParaLine> {
-fn paragraph(text: &str, base: usize, runs: &[(Range<usize>, TextStyle)], primaries: &[Resolved], variation_ids: &[u32], para: &ParagraphStyle, width: Option<f32>) -> Vec<ParaLine> {
++fn paragraph(
++ text: &str,
++ base: usize,
++ runs: &[(Range<usize>, TextStyle)],
++ primaries: &[Resolved],
++ variation_ids: &[u32],
++ para: &ParagraphStyle,
++ width: Option<f32>,
++) -> Vec<ParaLine> {
let rtl_para = para.rtl == Some(true);
let margins_for = |first: bool| -> (f32, f32) {
let fi = if first { para.indent_first } else { 0.0 };
@@@ -942,8 -917,10 +968,10 @@@
carets.sort_by_key(|c| c.0);
carets.dedup_by_key(|c| c.0);
// Line metrics: the tallest face and the largest leading on the line.
- let (mut asc, mut desc, mut adv) = (0.0f32, 0.0f32, 0.0f32);
+ let (mut asc, mut desc, mut adv, mut first) = (0.0f32, 0.0f32, 0.0f32, 0.0f32);
- let mut seen: Vec<usize> = chars.iter().filter(|c| c.0 >= r.start && c.0 < r.end).map(|c| c.6).collect();
+ let char_start = chars.partition_point(|c| c.0 < r.start);
+ let char_end = chars.partition_point(|c| c.0 < r.end);
+ let mut seen: Vec<usize> = chars[char_start..char_end].iter().map(|c| c.6).collect();
seen.sort_unstable();
seen.dedup();
if seen.is_empty() {
@@@ -1538,25 -1463,15 +1594,34 @@@ mod tests
assert!(r.lines[0].x + r.lines[0].width > 401.0, "closing quote hangs right");
}
+ /// After Effects 2026 (EXPORTER read-back t7): right-to-left point text with any justified
+ /// code (justify last left / centre / right, justify all) sits flush right at its anchor, as
+ /// right-aligned text does.
+ #[test]
+ fn rtl_point_text_with_a_justified_paragraph_is_flush_at_its_start() {
+ let text = "Right to left";
+ let s = st(30.0);
+ let at = |align: Align, last: Align| {
+ let p = ParagraphStyle { align, justify_last: last, rtl: Some(true), ..Default::default() };
+ let l = layout_rich_uncached(text, &[(0..text.len(), s.clone())], &[p]);
+ (l.lines[0].x, l.lines[0].x + l.lines[0].width)
+ };
+ let right = at(Align::Right, Align::Left);
+ for last in [Align::Left, Align::Center, Align::Right, Align::Justify] {
+ let got = at(Align::Justify, last);
+ assert!((got.0 - right.0).abs() < 1e-3 && (got.1 - right.1).abs() < 1e-3, "{last:?}: {got:?} vs right-aligned {right:?}");
+ }
+ }
+
+ #[test]
+ fn oversized_layout_requests_are_bounded_without_caching() {
+ let text = "a".repeat(MAX_LAYOUT_BYTES + 1);
+ let layout = layout(&text, &TextStyle::default(), &ParagraphStyle::default());
+ assert_eq!(layout.text_len, text.len());
+ assert!(layout.lines.is_empty() && layout.glyphs.is_empty());
+ assert!(layout_rich_uncached("ok", &[], &[]).lines.len() == 1);
+ }
+
#[test]
fn rtl_paragraph_carets_run_right_to_left() {
let text = "\u{5d0}\u{5d1}\u{5d2}";