mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-06 04:36:56 -06:00
Merge pull request #9406
This commit is contained in:
@@ -1513,12 +1513,19 @@ fn at_y(items: &[Placed], y: f32) -> Vec<Placed> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The fills of a merge's top edge for a continuation `by` points shorter than its row.
|
||||
/// Shorten a merge's continuation backgrounds by the height removed from its first row.
|
||||
fn shorter(items: &[Placed], by: f32) -> Vec<Placed> {
|
||||
let shorten = |rect: &Rect| Rect::new(rect.x, rect.y, rect.w, rect.h - by);
|
||||
items
|
||||
.iter()
|
||||
.map(|it| match it {
|
||||
Placed::Fill { rect, color } => Placed::Fill { rect: Rect::new(rect.x, rect.y, rect.w, (rect.h - by).max(0.0)), color: *color },
|
||||
Placed::Fill { rect, color } => Placed::Fill { rect: shorten(rect), color: *color },
|
||||
Placed::Clip { rect, spin, items } => {
|
||||
let rect = shorten(rect);
|
||||
// Keep the original picture geometry, including any tile that crosses the new bottom.
|
||||
let items = items.iter().filter(|it| !matches!(it, Placed::Image { rect: image, .. } if !rect.intersects(image))).cloned().collect();
|
||||
Placed::Clip { rect, spin: *spin, items }
|
||||
}
|
||||
other => other.clone(),
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -19971,6 +19971,89 @@ fn header_margin_table_area() {
|
||||
}
|
||||
}
|
||||
|
||||
/// #9383: the final part of a split continuation row keeps its own background extent.
|
||||
#[test]
|
||||
fn a_split_merge_continuation_picture_ends_at_the_following_row() {
|
||||
use display::Draw;
|
||||
use wordcraft_doc::props::{CellPicture, HeightRule, LineSpacing, PictureRepeat, Rgb, VMerge};
|
||||
|
||||
let paragraph = |text: &str| {
|
||||
let mut p = Paragraph::with_text(text, Default::default());
|
||||
p.props.line_spacing = Some(LineSpacing::Exactly(14.0));
|
||||
p.props.space_before = Some(0.0);
|
||||
p.props.space_after = Some(0.0);
|
||||
wordcraft_doc::para_block(p)
|
||||
};
|
||||
let shade = Rgb(220, 185, 70);
|
||||
let tile = [30.0, 7.0];
|
||||
for split in [false, true] {
|
||||
let mut d = pagination_fixture_document("");
|
||||
d.last_section.page_h = 320.0;
|
||||
d.last_section.margin_top = 40.0;
|
||||
d.last_section.margin_bottom = 40.0;
|
||||
let media = d.add_media(vec![0u8; 8], "png");
|
||||
let mut table = Table::new(3, 2, 200.0);
|
||||
let start = &mut table.rows[0].cells[0];
|
||||
start.props.vmerge = VMerge::Restart;
|
||||
start.props.shading = Some(shade);
|
||||
start.props.picture = Some(Box::new(CellPicture { media: media.clone(), size: tile, repeat: PictureRepeat::Tile, align: [0.0, 0.0] }));
|
||||
start.blocks = vec![paragraph("Merged")];
|
||||
table.rows[0].cells[1].blocks = vec![paragraph("Start")];
|
||||
table.rows[1].cells[0].props.vmerge = VMerge::Continue;
|
||||
table.rows[1].cells[1].blocks = (0..if split { 26 } else { 3 }).map(|_| paragraph("Continued")).collect();
|
||||
table.rows[2].cells[0].blocks = vec![paragraph("Following")];
|
||||
if !split {
|
||||
// The short continuation moves on whole, so it still opens its second page.
|
||||
table.rows[0].props.height = Some(220.0);
|
||||
table.rows[0].props.height_rule = HeightRule::Exact;
|
||||
table.rows[1].props.cant_split = true;
|
||||
}
|
||||
d.body = vec![Arc::new(Block::Table(table)), paragraph("Aftertable")];
|
||||
|
||||
let layout = lay(&d);
|
||||
let parts: Vec<_> = (0..layout.pages.len()).filter_map(|i| cell_rect(&layout, i, 1, 0).map(|rect| (i, rect))).collect();
|
||||
assert_eq!(parts.len(), if split { 2 } else { 1 }, "split={split}: {parts:?}");
|
||||
let &(last, continuation) = parts.last().unwrap();
|
||||
assert!(last > 0, "the final fragment opens a later page");
|
||||
let following = cell_rect(&layout, last, 2, 0).expect("the next row shares the final page");
|
||||
let draws = display::page_display(&d, &layout.pages[last], &display::DisplayOptions::default());
|
||||
let (clip, tiles) = draws
|
||||
.iter()
|
||||
.find_map(|draw| match draw {
|
||||
Draw::Clip { rect, items } if items.iter().any(|item| matches!(item, Draw::Image { media: key, .. } if *key == media)) => {
|
||||
Some((rect, items))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.expect("continued background picture");
|
||||
assert!((clip.y - continuation.y).abs() < 0.01 && (clip.h - continuation.h).abs() < 0.01, "split={split}: {clip:?} vs {continuation:?}");
|
||||
assert!(clip.bottom() <= following.y + 0.01, "the picture ends before the following row");
|
||||
assert!(
|
||||
draws.iter().any(|draw| matches!(draw, Draw::Fill { rect, color, .. }
|
||||
if *color == shade && *rect == *clip)),
|
||||
"solid shading has the same extent"
|
||||
);
|
||||
|
||||
let images: Vec<_> = tiles
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
Draw::Image { rect, media: key, .. } if *key == media => Some(rect),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert!(images.iter().all(|image| clip.intersects(image) && image.w == tile[0] && image.h == tile[1]));
|
||||
assert!(images.iter().any(|image| (image.y - clip.y).abs() < 0.01), "the first tile stays at the top");
|
||||
assert!(images.iter().any(|image| image.bottom() >= clip.bottom() - 0.01), "the last tile reaches the clipped edge");
|
||||
for following_text in ["Following", "Aftertable"] {
|
||||
assert!(
|
||||
draws.iter().any(|draw| matches!(draw, Draw::Glyphs { text, glyphs, .. }
|
||||
if text == following_text && !glyphs.is_empty() && glyphs.iter().all(|g| g.2 > clip.bottom()))),
|
||||
"{following_text} is drawn below the background"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod shape_alpha;
|
||||
|
||||
/// A row with a background picture split over two pages: each part draws its own piece of the
|
||||
|
||||
Reference in New Issue
Block a user