Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| FontFace | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\HtmlToPdf\Layout; |
| 6 | |
| 7 | use Phpdftk\FontParser\OpenTypeData; |
| 8 | |
| 9 | /** |
| 10 | * One face inside a CSS font family — a single `OpenTypeData` with its |
| 11 | * `font-weight` / `font-style` metadata so {@see FontResolver} can run |
| 12 | * CSS Fonts 4 §6 font-matching (weight matching + style matching) over a |
| 13 | * multi-face family. |
| 14 | * |
| 15 | * Weight values follow the CSS 1–1000 keyword/integer system (400 = normal, |
| 16 | * 700 = bold). Style is the keyword string (`normal`, `italic`, or `oblique`) |
| 17 | * — normalised to lower-case at construction. |
| 18 | * |
| 19 | * The face has no "stretch" / "size" axis at Phase 1; those land alongside |
| 20 | * variable-font axis handling later. |
| 21 | */ |
| 22 | final readonly class FontFace |
| 23 | { |
| 24 | public OpenTypeData $data; |
| 25 | public int $weight; |
| 26 | public string $style; |
| 27 | |
| 28 | public function __construct( |
| 29 | OpenTypeData $data, |
| 30 | int $weight = 400, |
| 31 | string $style = 'normal', |
| 32 | ) { |
| 33 | if ($weight < 1 || $weight > 1000) { |
| 34 | throw new \InvalidArgumentException(sprintf( |
| 35 | 'FontFace weight must be 1-1000 per CSS Fonts 4 §3.2; got %d', |
| 36 | $weight, |
| 37 | )); |
| 38 | } |
| 39 | $lcStyle = strtolower($style); |
| 40 | if (!in_array($lcStyle, ['normal', 'italic', 'oblique'], true)) { |
| 41 | throw new \InvalidArgumentException(sprintf( |
| 42 | 'FontFace style must be normal|italic|oblique per CSS Fonts 4 §3.3; got "%s"', |
| 43 | $style, |
| 44 | )); |
| 45 | } |
| 46 | $this->data = $data; |
| 47 | $this->weight = $weight; |
| 48 | $this->style = $lcStyle; |
| 49 | } |
| 50 | } |