Paint paragraph glyphs in the route-D display list
This commit is contained in:
1 parent
d07ff59d31
commit
38bacdfbd5
4 files changed
+271
-193
No files matched your search
@@ -61,6 +61,7 @@ pub enum VerticalItem {
|
||||
Mark(Mark),
|
||||
Float(Float),
|
||||
Halign(Halign),
|
||||
Paragraph(Paragraph),
|
||||
}
|
||||
|
||||
impl Halign {
|
||||
@@ -356,10 +357,7 @@ impl Unit {
|
||||
Self {
|
||||
id,
|
||||
source,
|
||||
items: vec![VerticalItem::Box(VerticalBox {
|
||||
width: paragraph.width.max(style.line_width),
|
||||
height: paragraph.height,
|
||||
})],
|
||||
items: vec![VerticalItem::Paragraph(paragraph)],
|
||||
paragraph_style: Some(style),
|
||||
}
|
||||
}
|
||||
@@ -611,6 +609,20 @@ impl Engine {
|
||||
}
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
VerticalItem::Paragraph(paragraph) => {
|
||||
if current.items.is_empty() && top_float_height(¤t) == 0 {
|
||||
used = document.top_skip.max(paragraph.height);
|
||||
} else if used + paragraph.height
|
||||
> document.page_goal - insertion_height - bottom_float_height(¤t)
|
||||
{
|
||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||
used = document.top_skip.max(paragraph.height);
|
||||
insertion_height = 0;
|
||||
} else {
|
||||
used += paragraph.height;
|
||||
}
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
VerticalItem::Glue(amount) => {
|
||||
if !current.items.is_empty() {
|
||||
used += amount;
|
||||
@@ -751,6 +763,7 @@ impl Engine {
|
||||
VerticalItem::Mark(_) => 0,
|
||||
VerticalItem::Float(float) => float.height,
|
||||
VerticalItem::Halign(halign) => halign.height,
|
||||
VerticalItem::Paragraph(paragraph) => paragraph.height,
|
||||
})
|
||||
.sum();
|
||||
if checkpoint.used + edited_height > next.page_goal && !checkpoint.page_items.is_empty() {
|
||||
@@ -827,6 +840,20 @@ impl Engine {
|
||||
}
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
VerticalItem::Paragraph(paragraph) => {
|
||||
if current.items.is_empty() && top_float_height(¤t) == 0 {
|
||||
used = next.top_skip.max(paragraph.height);
|
||||
} else if used + paragraph.height
|
||||
> next.page_goal - insertion_height - bottom_float_height(¤t)
|
||||
{
|
||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||
used = next.top_skip.max(paragraph.height);
|
||||
insertion_height = 0;
|
||||
} else {
|
||||
used += paragraph.height;
|
||||
}
|
||||
current.items.push(item.clone());
|
||||
}
|
||||
VerticalItem::Glue(amount) => {
|
||||
if !current.items.is_empty() {
|
||||
used += amount;
|
||||
@@ -1252,6 +1279,21 @@ mod tests {
|
||||
assert_eq!(halign.cell_box(2, 0), Some((30, 110)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_display_list_paints_characters() {
|
||||
let document = Document::new(400, vec![Unit::paragraph(1, "hello world")]);
|
||||
let engine = Engine::layout(&document);
|
||||
let list = engine.pages()[0].display_list();
|
||||
let texts = list
|
||||
.items
|
||||
.iter()
|
||||
.filter(|item| matches!(item, DisplayItem::Text { .. }))
|
||||
.count();
|
||||
assert!(texts >= 10, "expected painted characters, got {texts}");
|
||||
let svg = list.to_svg();
|
||||
assert!(svg.contains(">h</text>"));
|
||||
assert!(svg.contains(">w</text>"));
|
||||
}
|
||||
#[test]
|
||||
fn halign_display_list_paints_cells_and_rules() {
|
||||
let unit = Unit::halign_from_source(1, r"A & B \\ \hline C & D", 2, 10);
|
||||
|
||||
Reference in new issue
Block a user