Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| InlineFragment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\HtmlToPdf\Layout; |
| 6 | |
| 7 | use Phpdftk\Css\Value\Color; |
| 8 | use Phpdftk\Text\ShapedRun; |
| 9 | |
| 10 | /** |
| 11 | * One positioned shaped-text fragment inside a {@see LineBox}. `x` is the |
| 12 | * fragment's left edge relative to the line box's left edge; `width` is |
| 13 | * the run's total advance. |
| 14 | * |
| 15 | * Multiple fragments per line allow a single line to mix runs from |
| 16 | * different inline parents (e.g. `<p>hello <em>world</em></p>` produces a |
| 17 | * "hello " fragment and a "world" fragment on the same line). |
| 18 | */ |
| 19 | final readonly class InlineFragment |
| 20 | { |
| 21 | public function __construct( |
| 22 | public float $x, |
| 23 | public float $width, |
| 24 | public ShapedRun $shapedRun, |
| 25 | /** |
| 26 | * Additional Y offset applied to the fragment's baseline relative |
| 27 | * to the line's main baseline. Used for `vertical-align: sub` / |
| 28 | * `super` — negative values lift the fragment (higher on the page), |
| 29 | * positive values drop it. Layout-space Y, top-down. |
| 30 | */ |
| 31 | public float $baselineShift = 0.0, |
| 32 | /** |
| 33 | * When non-null, the fragment originated inside an `<a href>` |
| 34 | * subtree; the painter emits a `/Link` annotation covering the |
| 35 | * fragment's rect, targeting this URI. |
| 36 | */ |
| 37 | public ?string $href = null, |
| 38 | /** |
| 39 | * `true` when the fragment's cascaded `font-weight` is bold-ish |
| 40 | * (≥ 600). The painter renders these in PDF text mode 2 (fill + |
| 41 | * stroke) as a fake-bold fallback when a real bold font isn't |
| 42 | * available. |
| 43 | */ |
| 44 | public bool $isBold = false, |
| 45 | /** |
| 46 | * `true` when the fragment's cascaded `font-style` is `italic` or |
| 47 | * `oblique`. The painter applies a skew transform in `Tm` as a |
| 48 | * fake-italic fallback for the same reason. |
| 49 | */ |
| 50 | public bool $isItalic = false, |
| 51 | /** |
| 52 | * Text-decoration lines effective for this fragment (per CSS Text |
| 53 | * Decoration 4 §2 the property applies to "all in-flow boxes" but |
| 54 | * propagates from the inline element where it was set). Values |
| 55 | * are CSS keywords from the `text-decoration-line` vocabulary: |
| 56 | * `'underline'` / `'overline'` / `'line-through'`. |
| 57 | * |
| 58 | * @var list<string> |
| 59 | */ |
| 60 | public array $decorationLines = [], |
| 61 | /** |
| 62 | * Per-fragment fill color. When non-null the painter sets the text |
| 63 | * fill colour to this before emitting the fragment, overriding the |
| 64 | * line's block-level default — needed for inline elements like |
| 65 | * `<a>` whose UA `color` differs from the surrounding paragraph. |
| 66 | */ |
| 67 | public ?Color $textColor = null, |
| 68 | /** |
| 69 | * Per-fragment inline background, propagated downward from an |
| 70 | * `InlineBox` whose cascade sets `background-color`. When non-null |
| 71 | * the painter fills a rect under the fragment in this colour before |
| 72 | * the text emits, matching browser inline-background rendering of |
| 73 | * elements like `<mark>`. |
| 74 | */ |
| 75 | public ?Color $backgroundColor = null, |
| 76 | /** |
| 77 | * Companion `<a title>` text. Lands on the link annotation's |
| 78 | * `/Contents` field — PDF viewers show this as a tooltip on hover. |
| 79 | */ |
| 80 | public ?string $linkTitle = null, |
| 81 | /** |
| 82 | * Per-fragment text-decoration colour (CSS Text Decoration 4 §3). |
| 83 | * When non-null the painter uses this when stroking the fragment's |
| 84 | * underline / overline / line-through, overriding the block-level |
| 85 | * default — so an inline element like |
| 86 | * `<u style="text-decoration-color: red">` paints a red underline |
| 87 | * even when the surrounding paragraph carries the cascaded default. |
| 88 | */ |
| 89 | public ?Color $decorationColor = null, |
| 90 | ) {} |
| 91 | } |