Carry vertical content on route-D floats
This commit is contained in:
1 parent
25adbc7bf0
commit
fb22be1a49
1 file changed
+44
@@ -189,6 +189,9 @@ pub struct Float {
|
|||||||
pub placement: FloatPlacement,
|
pub placement: FloatPlacement,
|
||||||
pub width: i64,
|
pub width: i64,
|
||||||
pub height: i64,
|
pub height: i64,
|
||||||
|
/// Vertical material carried by the float. Empty for a dimension-only float.
|
||||||
|
#[serde(default)]
|
||||||
|
pub content: Vec<VerticalItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
@@ -382,10 +385,26 @@ impl Unit {
|
|||||||
placement,
|
placement,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
content: Vec::new(),
|
||||||
})],
|
})],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build a float that carries vertical material.
|
||||||
|
pub fn float_with_content(
|
||||||
|
id: UnitId,
|
||||||
|
placement: FloatPlacement,
|
||||||
|
width: i64,
|
||||||
|
height: i64,
|
||||||
|
content: Vec<VerticalItem>,
|
||||||
|
) -> Self {
|
||||||
|
let mut unit = Self::float(id, placement, width, height);
|
||||||
|
if let Some(VerticalItem::Float(float)) = unit.items.first_mut() {
|
||||||
|
float.content = content;
|
||||||
|
}
|
||||||
|
unit
|
||||||
|
}
|
||||||
|
|
||||||
/// A vertical penalty item, corresponding to `\penalty`.
|
/// A vertical penalty item, corresponding to `\penalty`.
|
||||||
pub fn penalty(id: UnitId, value: i64) -> Self {
|
pub fn penalty(id: UnitId, value: i64) -> Self {
|
||||||
Self::vertical(id, vec![VerticalItem::Penalty(value)])
|
Self::vertical(id, vec![VerticalItem::Penalty(value)])
|
||||||
@@ -1266,6 +1285,7 @@ mod tests {
|
|||||||
placement: FloatPlacement::Top,
|
placement: FloatPlacement::Top,
|
||||||
width: 40,
|
width: 40,
|
||||||
height: 20,
|
height: 20,
|
||||||
|
content: Vec::new(),
|
||||||
}),
|
}),
|
||||||
VerticalItem::Box(VerticalBox {
|
VerticalItem::Box(VerticalBox {
|
||||||
width: 10,
|
width: 10,
|
||||||
@@ -1295,6 +1315,7 @@ mod tests {
|
|||||||
placement: FloatPlacement::Bottom,
|
placement: FloatPlacement::Bottom,
|
||||||
width: 40,
|
width: 40,
|
||||||
height: 30,
|
height: 30,
|
||||||
|
content: Vec::new(),
|
||||||
}),
|
}),
|
||||||
VerticalItem::Box(VerticalBox {
|
VerticalItem::Box(VerticalBox {
|
||||||
width: 10,
|
width: 10,
|
||||||
@@ -1461,11 +1482,13 @@ mod tests {
|
|||||||
placement: FloatPlacement::Top,
|
placement: FloatPlacement::Top,
|
||||||
width: 50 * 65_536,
|
width: 50 * 65_536,
|
||||||
height: 15 * 65_536,
|
height: 15 * 65_536,
|
||||||
|
content: Vec::new(),
|
||||||
},
|
},
|
||||||
Float {
|
Float {
|
||||||
placement: FloatPlacement::Bottom,
|
placement: FloatPlacement::Bottom,
|
||||||
width: 60 * 65_536,
|
width: 60 * 65_536,
|
||||||
height: 10 * 65_536,
|
height: 10 * 65_536,
|
||||||
|
content: Vec::new(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
sources: Vec::new(),
|
sources: Vec::new(),
|
||||||
@@ -1780,6 +1803,27 @@ mod tests {
|
|||||||
assert!(svg.contains(">A</text>"));
|
assert!(svg.contains(">A</text>"));
|
||||||
assert!(svg.contains("<rect"));
|
assert!(svg.contains("<rect"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn float_carries_vertical_content() {
|
||||||
|
let unit = Unit::float_with_content(
|
||||||
|
1,
|
||||||
|
FloatPlacement::Top,
|
||||||
|
100,
|
||||||
|
20,
|
||||||
|
vec![VerticalItem::Rule {
|
||||||
|
width: 100,
|
||||||
|
height: 2,
|
||||||
|
}],
|
||||||
|
);
|
||||||
|
let VerticalItem::Float(float) = &unit.items[0] else {
|
||||||
|
panic!("expected float");
|
||||||
|
};
|
||||||
|
assert_eq!(float.content.len(), 1);
|
||||||
|
let encoded = serde_json::to_string(float).unwrap();
|
||||||
|
let decoded: Float = serde_json::from_str(&encoded).unwrap();
|
||||||
|
assert_eq!(decoded.content.len(), 1);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn mark_and_float_constructors_build_page_items() {
|
fn mark_and_float_constructors_build_page_items() {
|
||||||
let document = Document::new(
|
let document = Document::new(
|
||||||
|
|||||||
Reference in new issue
Block a user