1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::*;
/// Forces a break after it. Breaking mostly means page breaking, but the same mechanism could be
/// used for columns or other advanced layout usecases.
///
/// This element takes up no space but causes the layout to continue on the next page or column when
/// used in a breakable context.
pub struct ForceBreak;
impl Element for ForceBreak {
fn first_location_usage(&self, _ctx: FirstLocationUsageCtx) -> FirstLocationUsage {
FirstLocationUsage::WillUse
}
fn measure(&self, ctx: MeasureCtx) -> ElementSize {
if let Some(breakable) = ctx.breakable {
*breakable.break_count = 1;
}
ElementSize {
width: None,
height: None,
}
}
fn draw(&self, ctx: DrawCtx) -> ElementSize {
if let Some(breakable) = ctx.breakable {
// Note: This passes None as the height even though it always returns WillUse from
// first_location_usage. Just because the first location has None height doesn't mean
// it was skipped. In fact it would be incorrect if this element were to return
// WillSkip. WillSkip implies that if the element is drawn with a full first height it
// has to then look the same.
(breakable.do_break)(ctx.pdf, 0, None);
}
ElementSize {
width: None,
height: None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::*;
#[test]
fn test_force_break() {
for output in ElementTestParams::default().run(&ForceBreak) {
output.assert_size(ElementSize {
width: None,
height: None,
});
if let Some(b) = output.breakable {
b.assert_break_count(1);
b.assert_extra_location_min_height(None);
}
}
}
}