Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| CalloutStyle | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| resolveBarColor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| resolveBgColor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| resolveLabel | |
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 | * Per-call style overrides for {@see Pdf::addCallout()} / |
| 9 | * {@see Writer\Page::drawCallout()}. |
| 10 | * |
| 11 | * All colour fields are nullable: null means "use the |
| 12 | * {@see CalloutType}'s built-in default". The two scalar fields |
| 13 | * (padding, barWidth) always have a value — there's no per-type |
| 14 | * default for those. |
| 15 | */ |
| 16 | final class CalloutStyle |
| 17 | { |
| 18 | /** |
| 19 | * @param float $padding Internal padding around the body text. |
| 20 | * @param float $barWidth Left-edge bar thickness. |
| 21 | * @param array{float,float,float}|null $barColor Override the type's default bar colour. |
| 22 | * @param array{float,float,float}|null $bgColor Override the type's default background tint. `null` keeps the default; pass `[]`-style explicit-white to disable. |
| 23 | * @param array{float,float,float}|null $textColor Body text colour; null = theme default. |
| 24 | * @param bool $showLabel Whether to render the title row (e.g. "Note", "Warning"). |
| 25 | * @param string|null $labelOverride Title text override; null = use {@see CalloutType::defaultLabel()}. |
| 26 | */ |
| 27 | public function __construct( |
| 28 | public readonly float $padding = 8.0, |
| 29 | public readonly float $barWidth = 4.0, |
| 30 | public readonly ?array $barColor = null, |
| 31 | public readonly ?array $bgColor = null, |
| 32 | public readonly ?array $textColor = null, |
| 33 | public readonly bool $showLabel = true, |
| 34 | public readonly ?string $labelOverride = null, |
| 35 | ) {} |
| 36 | |
| 37 | /** |
| 38 | * @return array{float,float,float} |
| 39 | */ |
| 40 | public function resolveBarColor(CalloutType $type): array |
| 41 | { |
| 42 | return $this->barColor ?? $type->defaultBarColor(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return array{float,float,float} |
| 47 | */ |
| 48 | public function resolveBgColor(CalloutType $type): array |
| 49 | { |
| 50 | return $this->bgColor ?? $type->defaultBgColor(); |
| 51 | } |
| 52 | |
| 53 | public function resolveLabel(CalloutType $type): string |
| 54 | { |
| 55 | return $this->labelOverride ?? $type->defaultLabel(); |
| 56 | } |
| 57 | } |