← All changes
|
includes/Templates/Thermal/Thermal_Text_Layout.php
+9
-100
1.10.25
→
1.10.17
View file →
| @@ -15,10 +15,15 @@ | ||
| 15 | 15 | * FULLWIDTH YEN as one cell while the others measured two, and two copies of the |
| 16 | 16 | * no-mbstring fallback called mb_convert_encoding() — itself an mbstring |
| 17 | 17 | * function — so a host without the extension took a fatal. |
| 18 | 18 | * |
| 19 | - * A per-lane instance owns the paper columns and nested applied magnification. | |
| 20 | - * The existing static primitives remain available to raster and other emitters. | |
| 19 | + * Deliberately stateless and static rather than a trait. Four private copies that | |
| 20 | + * *looked* locally defined are how the drift happened in the first place; | |
| 21 | + * `display_width()` called on `$this` is indistinguishable from a method the | |
| 22 | + * emitter owns, whereas `Thermal_Text_Layout::display_width()` names its source | |
| 23 | + * at every call. | |
| 24 | + * Being static also keeps `columns` an argument instead of an implicit property | |
| 25 | + * contract, and lets the layout be exercised on its own. | |
| 21 | 26 | * |
| 22 | 27 | * Text emission itself stays with each emitter: only the measuring moved. |
| 23 | 28 | * |
| 24 | 29 | * @author Paul Kilmurray <[email protected]> |
| @@ -34,107 +39,11 @@ | ||
| 34 | 39 | */ |
| 35 | 40 | final class Thermal_Text_Layout { |
| 36 | 41 | |
| 37 | 42 | /** |
| 38 | - * Paper width in character columns. | |
| 39 | - * | |
| 40 | - * @var int | |
| 43 | + * Not instantiable: every member is a pure static function. | |
| 41 | 44 | */ |
| 42 | - private $columns; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * Command-specific magnification ceiling (8 for ESC/POS, 6 for StarPRNT). | |
| 46 | - * | |
| 47 | - * @var int | |
| 48 | - */ | |
| 49 | - private $max_magnification; | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * Applied sizes; the base entry is normal size. | |
| 53 | - * | |
| 54 | - * @var array | |
| 55 | - */ | |
| 56 | - private $sizes = array( | |
| 57 | - array( | |
| 58 | - 'width' => 1, | |
| 59 | - 'height' => 1, | |
| 60 | - ), | |
| 61 | - ); | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * Construct per-lane metrics. | |
| 65 | - * | |
| 66 | - * @param int $columns Paper width in character columns. | |
| 67 | - * @param int $max_magnification Largest multiplier the lane can encode. | |
| 68 | - */ | |
| 69 | - public function __construct( int $columns, int $max_magnification ) { | |
| 70 | - $this->columns = $columns; | |
| 71 | - $this->max_magnification = $max_magnification; | |
| 72 | - } | |
| 73 | - | |
| 74 | - /** | |
| 75 | - * Return the paper width in character columns. | |
| 76 | - * | |
| 77 | - * @return int | |
| 78 | - */ | |
| 79 | - public function columns(): int { | |
| 80 | - return $this->columns; | |
| 81 | - } | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * Enter a size wrapper, replacing (not multiplying) the parent scale. | |
| 85 | - * | |
| 86 | - * @param int $width Requested width multiplier. | |
| 87 | - * @param int $height Requested height multiplier. | |
| 88 | - * @return void | |
| 89 | - */ | |
| 90 | - public function enter_size( int $width, int $height ): void { | |
| 91 | - $this->sizes[] = array( | |
| 92 | - 'width' => max( 1, min( $this->max_magnification, $width ) ), | |
| 93 | - 'height' => max( 1, min( $this->max_magnification, $height ) ), | |
| 94 | - ); | |
| 95 | - } | |
| 96 | - | |
| 97 | - /** | |
| 98 | - * Leave a size wrapper and restore its parent. | |
| 99 | - * | |
| 100 | - * @return void | |
| 101 | - */ | |
| 102 | - public function leave_size(): void { | |
| 103 | - if ( count( $this->sizes ) > 1 ) { | |
| 104 | - array_pop( $this->sizes ); | |
| 105 | - } | |
| 106 | - } | |
| 107 | - | |
| 108 | - /** | |
| 109 | - * Return the magnification actually encoded by the lane. | |
| 110 | - * | |
| 111 | - * @return array{width: int, height: int} | |
| 112 | - */ | |
| 113 | - public function applied_scale(): array { | |
| 114 | - return $this->sizes[ count( $this->sizes ) - 1 ]; | |
| 115 | - } | |
| 116 | - | |
| 117 | - /** | |
| 118 | - * Count leading spaces using printed columns and the applied width scale. | |
| 119 | - * | |
| 120 | - * @param string $align Alignment mode (left|center|right). | |
| 121 | - * @param string $text Normalized plain text. | |
| 122 | - * @return int Number of literal spaces, each occupying the applied width. | |
| 123 | - */ | |
| 124 | - public function measure_padding( string $align, string $text ): int { | |
| 125 | - return self::alignment_padding( $align, self::display_width( $text ), $this->columns, $this->applied_scale()['width'] ); | |
| 126 | - } | |
| 127 | - | |
| 128 | - /** | |
| 129 | - * Resolve row widths using the existing unscaled paper-column contract. | |
| 130 | - * | |
| 131 | - * @param array $cols Column AST nodes. | |
| 132 | - * @return array | |
| 133 | - */ | |
| 134 | - public function measure_row_widths( array $cols ): array { | |
| 135 | - return self::resolve_row_widths( $cols, $this->columns ); | |
| 136 | - } | |
| 45 | + private function __construct() {} | |
| 137 | 46 | |
| 138 | 47 | /** |
| 139 | 48 | * Normalize text by replacing non-ASCII typographic characters. |
| 140 | 49 | * |