Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TableStyle | |
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| alignmentFor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Pdf\Writer; |
| 6 | |
| 7 | /** |
| 8 | * Styling for {@see Table} rendering. All fields have sensible defaults |
| 9 | * so `new TableStyle()` produces a readable table. |
| 10 | * |
| 11 | * The body font / size are inherited from the surrounding `Pdf` |
| 12 | * context (or from `Theme` for `Writer\Page::drawTable()`). To override |
| 13 | * locally, pass a per-call style. |
| 14 | */ |
| 15 | final class TableStyle |
| 16 | { |
| 17 | /** |
| 18 | * @param float $cellPadding Inside each cell, in points. |
| 19 | * @param array{float,float,float} $borderColor RGB 0-1; only used when `$borderWidth > 0`. |
| 20 | * @param float $borderWidth 0 disables borders entirely. |
| 21 | * @param array{float,float,float}|null $headerBgColor Header row fill; null = no header background. |
| 22 | * @param bool $headerBold Use the bold font variant for the header row. |
| 23 | * @param list<Alignment> $cellAlignments Per-column alignment; missing entries default to Left. |
| 24 | */ |
| 25 | public function __construct( |
| 26 | public readonly float $cellPadding = 4.0, |
| 27 | public readonly array $borderColor = [0.7, 0.7, 0.7], |
| 28 | public readonly float $borderWidth = 0.5, |
| 29 | public readonly ?array $headerBgColor = [0.93, 0.93, 0.93], |
| 30 | public readonly bool $headerBold = true, |
| 31 | public readonly array $cellAlignments = [], |
| 32 | ) {} |
| 33 | |
| 34 | public function alignmentFor(int $columnIndex): Alignment |
| 35 | { |
| 36 | return $this->cellAlignments[$columnIndex] ?? Alignment::Left; |
| 37 | } |
| 38 | } |