Compare commits

..
Author SHA1 Message Date
Dylan M. Taylor c5a8c92c40 style: rustfmt 2026-11-03 16:31:02 +00:00
Dylan M. Taylor ba61262eb0 fix(metafile): hold a placed pen width to what covers the frame 2026-11-03 11:50:57 +00:00
6 changed files with 41 additions and 24 deletions
+2 -2
View File
File diff suppressed because one or more lines are too long
+2 -5
View File
@@ -474,17 +474,14 @@ fn parse_blocks(lines: &[String], depth: usize, level: u8, refs: &Refs) -> Vec<F
let p = Para { align: a, inlines: parse_inlines(s, &Fmt::default(), depth, refs), ..Default::default() };
Cell { blocks: vec![FBlock::Para(p)], header, ..Default::default() }
};
// A document row keeps MAX_COLS cells: only those are built, so a wide header
// doesn't pad every sparse row below it out to its width.
let cols = aligns.len().min(wordcraft_doc::table::MAX_COLS);
table.rows.push(head.iter().zip(&aligns).take(cols).map(|(s, a)| cell(s, true, *a)).collect());
table.rows.push(head.iter().zip(&aligns).map(|(s, a)| cell(s, true, *a)).collect());
i += 2;
while let Some(l) = lines.get(i) {
if is_blank(l) || !l.contains('|') || interrupts(l) {
break;
}
let mut cells = split_row(l);
cells.resize(cols, String::new());
cells.resize(aligns.len(), String::new());
table.rows.push(cells.iter().zip(&aligns).map(|(s, a)| cell(s, false, *a)).collect());
i += 1;
}
-14
View File
@@ -714,17 +714,3 @@ fn exported_link_destinations_read_back_unchanged() {
assert_eq!(md("https://example.com/a b"), "[x](<https://example.com/a b>)");
assert_eq!(md("https://e.com/x\ny"), "[x](https://e.com/xy)");
}
#[test]
fn a_wide_table_builds_only_the_cells_a_row_keeps() {
// A 5,000-column header padded every one-cell row below it to 5,000 cells.
let n = 5000;
let md = format!("{}|\n{}|\n{}", "|h".repeat(n), "|-".repeat(n), "|x|\n".repeat(200));
let flow = parse(&md);
let FBlock::Table(t) = &flow.blocks[0] else { panic!("expected table") };
assert_eq!(t.rows.len(), 201);
assert!(t.rows.iter().all(|r| r.len() == wordcraft_doc::table::MAX_COLS));
// A narrow table is unchanged.
let FBlock::Table(t) = &parse("| a | b |\n| - | - |\n| x |\n").blocks[0] else { panic!("expected table") };
assert_eq!(t.rows[1].len(), 2);
}
+8 -2
View File
@@ -136,8 +136,14 @@ impl Picture {
match item {
Item::Path { segs, fill, stroke, even_odd } => {
let path = tf * bez(segs);
if in_range(path.bounding_box()) {
let stroke = stroke.map(|(c, w)| (c, f64::from(w) * k));
let bounds = path.bounding_box();
if in_range(bounds) {
// A pen wider than twice the distance across the frame and the path
// already covers the whole frame: wider adds nothing the frame shows, only
// work for the renderer flattening its round caps (the width is file data).
let u = bounds.union(r);
let widest = 2.0 * u.width().hypot(u.height());
let stroke = stroke.map(|(c, w)| (c, (f64::from(w) * k).min(widest)));
out.push(PlacedItem::Path { path, fill: *fill, stroke, even_odd: *even_odd });
}
}
+28
View File
@@ -891,6 +891,34 @@ fn place_fits_the_frame_scales_strokes_and_drops_far_paths() {
assert_eq!(stroke.map(|s| s.1), Some(8.0));
}
#[test]
fn a_huge_pen_is_held_to_what_covers_the_frame() {
// A pen of 1e30 units on a short path: round caps that wide took the renderer forever to
// flatten. Past twice the distance across the frame and the path it covers no more.
let path = |w: f32| crate::Picture {
width: 100.0,
height: 50.0,
items: vec![Item::Path {
segs: vec![Seg::Move(0.0, 0.0), Seg::Line(10.0, 0.0)],
fill: None,
stroke: Some(([0, 0, 0, 255], w)),
even_odd: true,
}],
};
let width = |w: f32| match pic_place(&path(w)).first() {
Some(crate::PlacedItem::Path { stroke, .. }) => stroke.map(|s| s.1),
_ => None,
};
let cap = 2.0 * 200f64.hypot(100.0);
assert_eq!(width(1e30), Some(cap));
assert_eq!(width(f32::MAX), Some(cap));
assert_eq!(width(4.0), Some(8.0), "an ordinary pen is untouched");
}
fn pic_place(pic: &crate::Picture) -> Vec<crate::PlacedItem> {
pic.place(kurbo::Rect::new(0.0, 0.0, 200.0, 100.0), [0.0; 4])
}
/// #1899: a crop keeps what the file says down to a sliver (a header's bar is 2.7% of a page-sized
/// metafile), and junk sides give a finite part of the source with some area.
#[test]
+1 -1
View File
File diff suppressed because one or more lines are too long