Paint float content in the route-D display list
This commit is contained in:
1 parent
fb22be1a49
commit
e791c94cfe
2 files changed
+68
-14
No files matched your search
@@ -1753,6 +1753,44 @@ mod tests {
|
||||
let svg = list.to_svg();
|
||||
assert!(svg.contains(">x</text>"));
|
||||
}
|
||||
#[test]
|
||||
fn float_content_is_painted_at_the_top_of_the_page() {
|
||||
let mut document = Document::new(1000, Vec::new());
|
||||
document.top_skip = 0;
|
||||
document.units.push(Unit::float_with_content(
|
||||
1,
|
||||
FloatPlacement::Top,
|
||||
100,
|
||||
20,
|
||||
vec![VerticalItem::Rule {
|
||||
width: 80,
|
||||
height: 2,
|
||||
}],
|
||||
));
|
||||
document.units.push(Unit::paragraph(2, "hello world"));
|
||||
let engine = Engine::layout(&document);
|
||||
let list = engine.pages()[0].display_list();
|
||||
assert!(list.items.iter().any(|item| matches!(
|
||||
item,
|
||||
DisplayItem::Rule {
|
||||
y: 0,
|
||||
width: 80,
|
||||
height: 2,
|
||||
..
|
||||
}
|
||||
)));
|
||||
let text_y = list
|
||||
.items
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
DisplayItem::Text { y, text, .. } if text == "h" => Some(y),
|
||||
_ => None,
|
||||
})
|
||||
.min()
|
||||
.unwrap();
|
||||
assert!(*text_y >= 20, "body text starts below the top float");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paragraph_display_list_paints_characters() {
|
||||
let document = Document::new(400, vec![Unit::paragraph(1, "hello world")]);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
use crate::cmr10::Cmr10Metrics;
|
||||
use crate::math::{self, MathAtom};
|
||||
use crate::paragraph::ParagraphFont;
|
||||
use crate::{FloatPlacement, Halign, HorizontalItem, Page, VerticalItem};
|
||||
use crate::{Float, FloatPlacement, Halign, HorizontalItem, Page, VerticalItem};
|
||||
|
||||
/// One absolute drawing primitive in scaled points.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
@@ -283,12 +283,7 @@ impl Page {
|
||||
.iter()
|
||||
.filter(|float| float.placement == FloatPlacement::Top)
|
||||
{
|
||||
list.push(DisplayItem::Rule {
|
||||
x: 0,
|
||||
y: float_y,
|
||||
width: float.width,
|
||||
height: float.height,
|
||||
});
|
||||
Self::paint_float(float, 0, float_y, &mut list);
|
||||
float_y += float.height;
|
||||
}
|
||||
y = top_height;
|
||||
@@ -435,14 +430,8 @@ impl Page {
|
||||
.iter()
|
||||
.filter(|float| float.placement == FloatPlacement::Bottom)
|
||||
{
|
||||
list.push(DisplayItem::Rule {
|
||||
x: 0,
|
||||
y: float_y,
|
||||
width: float.width,
|
||||
height: float.height,
|
||||
});
|
||||
Self::paint_float(float, 0, float_y, &mut list);
|
||||
float_y += float.height;
|
||||
list.width = list.width.max(float.width);
|
||||
}
|
||||
y = y.max(float_y);
|
||||
}
|
||||
@@ -462,6 +451,33 @@ impl Page {
|
||||
list
|
||||
}
|
||||
|
||||
/// Paint a float's vertical material, or a dimension rectangle when the
|
||||
/// float carries no content.
|
||||
fn paint_float(float: &Float, x: i64, y: i64, list: &mut DisplayList) {
|
||||
if float.content.is_empty() {
|
||||
list.push(DisplayItem::Rule {
|
||||
x,
|
||||
y,
|
||||
width: float.width,
|
||||
height: float.height,
|
||||
});
|
||||
list.width = list.width.max(float.width);
|
||||
return;
|
||||
}
|
||||
let page = Page {
|
||||
items: float.content.clone(),
|
||||
insertions: Vec::new(),
|
||||
marks: Vec::new(),
|
||||
floats: Vec::new(),
|
||||
sources: Vec::new(),
|
||||
hash: 0,
|
||||
};
|
||||
let mut content = page.display_list();
|
||||
content.place(x, y);
|
||||
list.items.extend(content.items);
|
||||
list.images.extend(content.images);
|
||||
list.width = list.width.max(content.width);
|
||||
}
|
||||
fn paint_math(
|
||||
atom: &MathAtom,
|
||||
font: &Cmr10Metrics,
|
||||
|
||||
Reference in new issue
Block a user