laser-pdf 0.5.0

A Rust library for programmatic PDF generation with precise, predictable layout control.
Documentation
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
use crate::*;

use self::utils::add_optional_size_with_gap;

/// A container that arranges child elements vertically with optional gaps.
///
/// Elements are laid out from top to bottom with configurable spacing between them.
/// Supports page breaking and collapsing behavior for empty elements.
///
/// ## Gap Behavior
///
/// Gaps are only applied between elements that have actual height. Elements with
/// `None` height (collapsed elements) don't get gaps before or after them.
///
/// ## Collapse Behavior
///
/// When `collapse: true` (default):
/// - If all children have `None` height, the column returns `None` height
/// - If all children have `None` width, the column returns `None` width
/// - The gaps around a child with a `None` height are collapsed into one.
///
/// When `collapse: false`:
/// - Empty columns return `Some(0.0)` for height/width instead of `None`
/// - Useful when you need a column to always occupy space even when empty
/// - A child with a `None` height will still have a gap on either side
///
/// ## Page Breaking
///
/// In breakable contexts, when a child element causes a page break, the column's
/// accumulated height is reset and continues on the new page.
pub struct Column<C: Fn(ColumnContent) -> Option<()>> {
    /// Closure that gets called for adding the content.
    ///
    /// The closure is basically an internal iterator that produces elements by calling
    /// [ColumnContent::add]. For short circuiting with the `?` operator [ColumnContent::add] and
    /// this closure return an [Option].
    ///
    /// If the column is in a context that measures it before drawing (such as `BreakWhole`), this
    /// function will be called twice. In more complicated nested layouts it could be called more
    /// than that (though in real world layouts this effect should be minimal as not all containers
    /// need a measure pass before drawing). Because of this it's beneficial to keep expensive
    /// computations and allocation outside of this closure.
    pub content: C,
    /// Vertical spacing between elements in millimeters
    pub gap: f32,
    /// Whether to collapse to None size when all children are collapsed.
    /// When false, empty columns return Some(0.0) instead of None.
    pub collapse: bool,
}

impl<C: Fn(ColumnContent) -> Option<()>> Column<C> {
    pub fn new(content: C) -> Self {
        Column {
            content,
            gap: 0.,
            collapse: true,
        }
    }

    pub fn with_gap(self, gap: f32) -> Self {
        Column { gap, ..self }
    }

    pub fn with_collapse(self, collapse: bool) -> Self {
        Column { collapse, ..self }
    }
}

impl<C: Fn(ColumnContent) -> Option<()>> Element for Column<C> {
    fn first_location_usage(&self, ctx: FirstLocationUsageCtx) -> FirstLocationUsage {
        let mut ret = FirstLocationUsage::NoneHeight;

        (self.content)(ColumnContent {
            pass: Pass::InsufficientFirstHeight { ctx, ret: &mut ret },
            gap: self.gap,
        });

        if !self.collapse && ret == FirstLocationUsage::NoneHeight {
            ret = FirstLocationUsage::WillUse;
        }

        ret
    }

    fn measure(&self, mut ctx: MeasureCtx) -> ElementSize {
        let mut width = None;
        let mut height = None;
        let mut break_count = 0;

        (self.content)(ColumnContent {
            pass: Pass::Measure {
                text_pieces_cache: ctx.text_pieces_cache,
                width_constraint: ctx.width,
                breakable: ctx.breakable.as_mut().map(|b| BreakableMeasure {
                    break_count: &mut break_count,
                    extra_location_min_height: b.extra_location_min_height,
                    ..*b
                }),
                height_available: ctx.first_height,
                width: &mut width,
                height: &mut height,
            },
            gap: self.gap,
        });

        if let Some(breakable) = ctx.breakable {
            *breakable.break_count = break_count;
        }

        if !self.collapse {
            if height.is_none() && break_count == 0 {
                height = Some(0.);
            }

            if width.is_none() {
                width = Some(0.);
            }
        }

        ElementSize { width, height }
    }

    fn draw(&self, ctx: DrawCtx) -> ElementSize {
        let mut width = None;
        let mut height = None;
        let mut location_offset = 0;

        (self.content)(ColumnContent {
            pass: Pass::Draw {
                pdf: ctx.pdf,
                text_pieces_cache: ctx.text_pieces_cache,
                location: ctx.location,
                location_offset: &mut location_offset,
                width_constraint: ctx.width,
                breakable: ctx.breakable,
                height_available: ctx.first_height,
                width: &mut width,
                height: &mut height,
            },
            gap: self.gap,
        });

        if !self.collapse {
            if height.is_none() && location_offset == 0 {
                height = Some(0.);
            }

            if width.is_none() {
                width = Some(0.);
            }
        }

        ElementSize { width, height }
    }
}

pub struct ColumnContent<'a, 'b, 'r> {
    pass: Pass<'a, 'b, 'r>,
    gap: f32,
}

enum Pass<'a, 'b, 'r> {
    InsufficientFirstHeight {
        ctx: FirstLocationUsageCtx<'a>,
        ret: &'r mut FirstLocationUsage,
    },
    Measure {
        text_pieces_cache: &'a TextPiecesCache,
        width_constraint: WidthConstraint,
        breakable: Option<BreakableMeasure<'a>>,

        /// this is initially first_height and when breaking we set it to full height
        height_available: f32,
        width: &'r mut Option<f32>,
        height: &'r mut Option<f32>,
    },
    Draw {
        pdf: &'a mut Pdf,
        text_pieces_cache: &'a TextPiecesCache,
        location: Location,
        location_offset: &'r mut u32,
        width_constraint: WidthConstraint,
        breakable: Option<BreakableDraw<'b>>,

        /// this is initially first_height and when breaking we set it to full height
        height_available: f32,
        width: &'r mut Option<f32>,
        height: &'r mut Option<f32>,
    },
}

impl<'a, 'b, 'r> ColumnContent<'a, 'b, 'r> {
    pub fn add<E: Element>(mut self, element: &E) -> Option<Self> {
        match self.pass {
            Pass::InsufficientFirstHeight {
                ref mut ctx,
                ret: &mut ref mut ret,
            } => {
                let first_location_usage =
                    element.first_location_usage(FirstLocationUsageCtx { ..*ctx });

                if first_location_usage == FirstLocationUsage::NoneHeight {
                    Some(self)
                } else {
                    *ret = first_location_usage;
                    None
                }
            }
            Pass::Measure {
                text_pieces_cache,
                width_constraint,
                ref mut breakable,
                ref mut height_available,
                width: &mut ref mut width,
                height: &mut ref mut height,
            } => {
                // The gap is applied here, but will only be actually applied to the height and
                // position for subsequent elements if this element ends up having a height.
                let measure_ctx = MeasureCtx {
                    text_pieces_cache,
                    width: width_constraint,
                    first_height: *height_available
                        - height.unwrap_or(0.)
                        - if height.is_some() { self.gap } else { 0. },
                    breakable: None,
                };

                let size;

                if let Some(b) = breakable {
                    let mut break_count = 0;

                    // We ignore this because we also don't pass on preferred height.
                    let mut extra_location_min_height = None;

                    size = element.measure(MeasureCtx {
                        breakable: Some(BreakableMeasure {
                            full_height: b.full_height,
                            break_count: &mut break_count,
                            extra_location_min_height: &mut extra_location_min_height,
                        }),
                        ..measure_ctx
                    });

                    if break_count > 0 {
                        *height_available = b.full_height;
                        *height = None;
                        *b.break_count += break_count;
                    }
                } else {
                    size = element.measure(measure_ctx);
                }

                if let Some(h) = size.height {
                    if let Some(height) = height {
                        *height += self.gap;
                        *height += h;
                    } else {
                        *height = Some(h);
                    }
                }

                if let Some(w) = size.width {
                    if let Some(width) = width {
                        *width = width.max(w);
                    } else {
                        *width = Some(w);
                    }
                }

                Some(self)
            }
            Pass::Draw {
                pdf: &mut ref mut pdf,
                text_pieces_cache,
                ref mut location,
                location_offset: &mut ref mut location_offset,
                width_constraint,
                ref mut breakable,
                ref mut height_available,
                width: &mut ref mut width,
                height: &mut ref mut height,
            } => {
                // The gap is applied here, but will only be actually applied to the height and
                // position for subsequent elements if this element ends up having a height.
                let draw_ctx = DrawCtx {
                    pdf,
                    text_pieces_cache,
                    location: Location {
                        pos: if height.is_some() {
                            (location.pos.0, location.pos.1 - self.gap)
                        } else {
                            location.pos
                        },
                        ..*location
                    },
                    width: width_constraint,
                    first_height: *height_available
                        - height.unwrap_or(0.)
                        - if height.is_some() { self.gap } else { 0. },
                    preferred_height: None,
                    breakable: None,
                };

                let size = if let Some(b) = breakable {
                    let mut break_count = 0;

                    let size = element.draw(DrawCtx {
                        breakable: Some(BreakableDraw {
                            full_height: b.full_height,
                            preferred_height_break_count: 0,
                            do_break: &mut |pdf, location_idx, location_height| {
                                *height_available = b.full_height;

                                let location_height = if location_idx == 0 {
                                    add_optional_size_with_gap(location_height, *height, self.gap)
                                } else {
                                    location_height
                                };

                                let new_location = (b.do_break)(
                                    pdf,
                                    location_idx + *location_offset,
                                    location_height,
                                );

                                if location_idx + 1 > break_count {
                                    break_count = location_idx + 1;
                                    *location = new_location.clone();
                                }

                                new_location
                            },
                        }),
                        ..draw_ctx
                    });

                    if break_count > 0 {
                        *location_offset += break_count;
                        *height_available = b.full_height;
                        *height = None;
                    }

                    size
                } else {
                    element.draw(draw_ctx)
                };

                if let Some(h) = size.height {
                    if let Some(height) = height {
                        location.pos.1 -= self.gap;
                        *height += self.gap;

                        *height += h;
                    } else {
                        *height = Some(h);
                    }

                    location.pos.1 -= h;
                }

                if let Some(w) = size.width {
                    if let Some(width) = width {
                        *width = width.max(w);
                    } else {
                        *width = Some(w);
                    }
                }

                Some(self)
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{elements::force_break::ForceBreak, elements::none::NoneElement, test_utils::*};

    #[test]
    fn test_column_empty() {
        let element = Column {
            gap: 100.,
            collapse: true,
            content: |_| Some(()),
        };

        for output in ElementTestParams::default().run(&element) {
            output.assert_size(ElementSize {
                width: None,
                height: None,
            });

            if let Some(b) = output.breakable {
                b.assert_break_count(0)
                    .assert_extra_location_min_height(None);
            }
        }
    }

    #[test]
    fn test_column_with_multiple_nones() {
        use assert_passes::*;

        let element = BuildElement(|build_ctx, callback| {
            // we need to build this multiple times because AssertPasses keeps internal state
            let build = || {
                AssertPasses::new(
                    NoneElement,
                    match build_ctx.pass {
                        build_element::Pass::FirstLocationUsage { full_height } => {
                            vec![Pass::FirstLocationUsage {
                                width: build_ctx.width,
                                first_height: build_ctx.first_height,
                                full_height,
                            }]
                        }
                        build_element::Pass::Measure { full_height } => vec![Pass::Measure {
                            width: build_ctx.width,
                            first_height: build_ctx.first_height,
                            full_height,
                        }],
                        build_element::Pass::Draw { ref breakable, .. } => vec![Pass::Draw {
                            width: build_ctx.width,
                            first_height: build_ctx.first_height,
                            preferred_height: None,

                            page: 0,
                            layer: 0,
                            pos: (3., 12.),

                            breakable: breakable.as_ref().map(|b| BreakableDraw {
                                full_height: b.full_height,
                                preferred_height_break_count: 0,
                                breaks: Vec::new(),
                            }),
                        }],
                    },
                )
            };

            let none_0 = build();
            let none_1 = build();
            let none_2 = build();

            let element = Column {
                gap: 1.,
                collapse: true,
                content: |content| {
                    content.add(&none_0)?.add(&none_1)?.add(&none_2)?;

                    None
                },
            };

            callback.call(element)
        });

        for output in (ElementTestParams {
            first_height: 4.,
            full_height: 10.,
            width: 6.,
            pos: (3., 12.),
            ..Default::default()
        })
        .run(&element)
        {
            output.assert_size(ElementSize {
                width: None,
                height: None,
            });

            if let Some(b) = output.breakable {
                b.assert_break_count(0)
                    .assert_extra_location_min_height(None);
            }
        }
    }

    #[test]
    fn test_column() {
        use assert_passes::*;

        let element = BuildElement(|build_ctx, callback| {
            let less_first_height = build_ctx.first_height == 4.;

            let child_0 = AssertPasses::new(
                NoneElement,
                match build_ctx.pass {
                    build_element::Pass::FirstLocationUsage { full_height } => {
                        vec![Pass::FirstLocationUsage {
                            width: build_ctx.width,
                            first_height: build_ctx.first_height,
                            full_height,
                        }]
                    }
                    build_element::Pass::Measure { full_height } => vec![Pass::Measure {
                        width: build_ctx.width,
                        first_height: build_ctx.first_height,
                        full_height,
                    }],
                    build_element::Pass::Draw { ref breakable, .. } => vec![Pass::Draw {
                        width: build_ctx.width,
                        first_height: build_ctx.first_height,
                        preferred_height: None,

                        page: 0,
                        layer: 0,
                        pos: (3., 12.),

                        breakable: breakable.as_ref().map(|b| BreakableDraw {
                            full_height: b.full_height,
                            preferred_height_break_count: 0,
                            breaks: Vec::new(),
                        }),
                    }],
                },
            );

            let child_1 = AssertPasses::new(
                FakeText {
                    lines: 8,
                    line_height: 2.,
                    width: 5.,
                },
                match build_ctx.pass {
                    build_element::Pass::FirstLocationUsage { full_height } => {
                        vec![Pass::FirstLocationUsage {
                            width: build_ctx.width,
                            first_height: build_ctx.first_height,
                            full_height,
                        }]
                    }
                    build_element::Pass::Measure { full_height } => vec![Pass::Measure {
                        width: build_ctx.width,
                        first_height: build_ctx.first_height,
                        full_height,
                    }],
                    build_element::Pass::Draw { ref breakable, .. } => vec![Pass::Draw {
                        width: build_ctx.width,
                        first_height: build_ctx.first_height,
                        preferred_height: None,

                        page: 0,
                        layer: 0,
                        pos: (3., 12.),

                        breakable: breakable.as_ref().map(|b| BreakableDraw {
                            full_height: b.full_height,
                            preferred_height_break_count: 0,
                            breaks: if less_first_height {
                                vec![
                                    Break {
                                        page: 1,
                                        layer: 0,
                                        pos: (3., 12.),
                                    },
                                    Break {
                                        page: 2,
                                        layer: 0,
                                        pos: (3., 12.),
                                    },
                                ]
                            } else {
                                vec![Break {
                                    page: 1,
                                    layer: 0,
                                    pos: (3., 12.),
                                }]
                            },
                        }),
                    }],
                },
            );

            let child_2 = {
                let first_height = match (build_ctx.is_breakable(), less_first_height) {
                    (false, false) => 10. - 16. - 1.,
                    (false, true) => 4. - 16. - 1.,
                    (true, false) => 3.,
                    (true, true) => 7.,
                };

                AssertPasses::new(
                    ForceBreak,
                    match build_ctx.pass {
                        build_element::Pass::FirstLocationUsage { .. } => vec![],
                        build_element::Pass::Measure { full_height } => vec![Pass::Measure {
                            width: build_ctx.width,
                            first_height,
                            full_height,
                        }],
                        build_element::Pass::Draw { ref breakable, .. } => {
                            vec![if let Some(breakable) = breakable {
                                Pass::Draw {
                                    width: build_ctx.width,
                                    first_height,
                                    preferred_height: None,

                                    page: if less_first_height { 2 } else { 1 },
                                    layer: 0,
                                    pos: if less_first_height {
                                        (3., 12. - 3.)
                                    } else {
                                        (3., 12. - 7.)
                                    },

                                    breakable: Some(BreakableDraw {
                                        full_height: breakable.full_height,
                                        preferred_height_break_count: 0,
                                        breaks: if less_first_height {
                                            vec![Break {
                                                page: 3,
                                                layer: 0,
                                                pos: (3., 12.),
                                            }]
                                        } else {
                                            vec![Break {
                                                page: 2,
                                                layer: 0,
                                                pos: (3., 12.),
                                            }]
                                        },
                                    }),
                                }
                            } else {
                                Pass::Draw {
                                    width: build_ctx.width,
                                    first_height,
                                    preferred_height: None,

                                    page: 0,
                                    layer: 0,
                                    pos: (3., 12. - 16. - 1.),

                                    breakable: None,
                                }
                            }]
                        }
                    },
                )
            };

            let child_3 = {
                let first_height = match (build_ctx.is_breakable(), less_first_height) {
                    (false, false) => 10. - 16. - 1.,
                    (false, true) => 4. - 16. - 1.,
                    (true, _) => 10.,
                };

                AssertPasses::new(
                    FranticJumper {
                        jumps: vec![
                            (0, Some(0.)),
                            (5, Some(1.5)),
                            (3, Some(1.5)),
                            (3, Some(1.5)),
                        ],
                        size: ElementSize {
                            width: Some(5.5),
                            height: Some(1.5),
                        },
                    },
                    match build_ctx.pass {
                        build_element::Pass::FirstLocationUsage { .. } => vec![],
                        build_element::Pass::Measure { full_height } => vec![Pass::Measure {
                            width: build_ctx.width,
                            first_height,
                            full_height,
                        }],
                        build_element::Pass::Draw { ref breakable, .. } => {
                            vec![if let Some(breakable) = breakable {
                                let start_page = if less_first_height { 3 } else { 2 };

                                Pass::Draw {
                                    width: build_ctx.width,
                                    first_height,
                                    preferred_height: None,
                                    page: start_page,
                                    layer: 0,
                                    pos: (3., 12.),
                                    breakable: Some(BreakableDraw {
                                        full_height: breakable.full_height,
                                        preferred_height_break_count: 0,
                                        breaks: vec![
                                            Break {
                                                page: start_page + 1,
                                                layer: 0,
                                                pos: (3., 12.),
                                            },
                                            Break {
                                                page: start_page + 6,
                                                layer: 0,
                                                pos: (3., 12.),
                                            },
                                            Break {
                                                page: start_page + 4,
                                                layer: 0,
                                                pos: (3., 12.),
                                            },
                                            Break {
                                                page: start_page + 4,
                                                layer: 0,
                                                pos: (3., 12.),
                                            },
                                        ],
                                    }),
                                }
                            } else {
                                Pass::Draw {
                                    width: build_ctx.width,
                                    first_height,
                                    preferred_height: None,

                                    page: 0,
                                    layer: 0,
                                    pos: (3., 12. - 16. - 1.),

                                    breakable: None,
                                }
                            }]
                        }
                    },
                )
            };

            let child_4 = {
                let first_height = match (build_ctx.is_breakable(), less_first_height) {
                    (false, false) => 10. - 16. - 1. - 1.5 - 1.,
                    (false, true) => 4. - 16. - 1. - 1.5 - 1.,
                    (true, _) => 10. - 1.5 - 1.,
                };

                AssertPasses::new(
                    NoneElement,
                    match build_ctx.pass {
                        build_element::Pass::FirstLocationUsage { .. } => vec![],
                        build_element::Pass::Measure { full_height } => vec![Pass::Measure {
                            width: build_ctx.width,
                            first_height,
                            full_height,
                        }],
                        build_element::Pass::Draw { ref breakable, .. } => {
                            vec![if let Some(breakable) = breakable {
                                let start_page = if less_first_height { 3 } else { 2 } + 6;

                                Pass::Draw {
                                    width: build_ctx.width,
                                    first_height,
                                    preferred_height: None,
                                    page: start_page,
                                    layer: 0,
                                    pos: (3., 12. - 1.5 - 1.),
                                    breakable: Some(BreakableDraw {
                                        full_height: breakable.full_height,
                                        preferred_height_break_count: 0,
                                        breaks: vec![],
                                    }),
                                }
                            } else {
                                Pass::Draw {
                                    width: build_ctx.width,
                                    first_height,
                                    preferred_height: None,

                                    page: 0,
                                    layer: 0,
                                    pos: (3., 12. - 16. - 1. - 1.5 - 1.),

                                    breakable: None,
                                }
                            }]
                        }
                    },
                )
            };

            let element = Column {
                gap: 1.,
                collapse: false,
                content: |content| {
                    content
                        .add(&child_0)?
                        .add(&child_1)?
                        .add(&child_2)?
                        .add(&child_3)?
                        .add(&child_4)?;

                    Some(())
                },
            };

            callback.call(element)
        });

        for output in (ElementTestParams {
            first_height: 4.,
            full_height: 10.,
            width: 6.,
            pos: (3., 12.),
            ..Default::default()
        })
        .run(&element)
        {
            output.assert_size(ElementSize {
                width: Some(output.width.constrain(5.5)),
                height: Some(if output.breakable.is_some() {
                    1.5
                } else {
                    16. + 1. + 1.5
                }),
            });

            if let Some(b) = output.breakable {
                b.assert_break_count(if output.first_height == 4. { 9 } else { 8 })
                    .assert_extra_location_min_height(None);
            }
        }
    }
}