Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LineBox
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 totalWidth
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\HtmlToPdf\Layout;
6
7/**
8 * One laid-out line inside an inline formatting context.
9 *
10 * `y` is the line's top edge in the parent block's coordinate space;
11 * `height` is the line's allocated vertical space (typically 1.2 × the
12 * dominant font-size for Latin until proper baseline alignment ships).
13 * `fragments` are placed left-to-right in logical order; bidi visual
14 * reorder happens before this stage.
15 */
16final class LineBox
17{
18    /** @param list<InlineFragment> $fragments */
19    public function __construct(
20        public float $y,
21        public float $height,
22        public array $fragments,
23    ) {}
24
25    public function totalWidth(): float
26    {
27        $right = 0.0;
28        foreach ($this->fragments as $f) {
29            $right = max($right, $f->x + $f->width);
30        }
31        return $right;
32    }
33}