← All changes
|
includes/Templates/Thermal/Thermal_Text_Layout.php
+14
-5
1.10.3
→
1.10.17
View file →
| @@ -258,24 +258,33 @@ | ||
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Compute the leading-space padding that aligns a line of the given width. |
| 261 | 261 | * |
| 262 | + * The padding is emitted as literal spaces INSIDE the run it indents, so under a `<size>` | |
| 263 | + * multiplier each one is $scale cells wide -- as is each character of the text. Callers that | |
| 264 | + * emit bytes to a printer must pass the multiplier in force; a count taken at scale 1 lays | |
| 265 | + * down $scale times the margin asked for and wraps the line. Callers that place glyphs at | |
| 266 | + * computed cell positions (the raster emitter) already fold the multiplier into $text_width | |
| 267 | + * and leave $scale at 1. | |
| 268 | + * | |
| 262 | 269 | * @param string $align The alignment mode (left|center|right). |
| 263 | - * @param int $text_width The display width of the line's plain text. | |
| 270 | + * @param int $text_width The display width of the line's plain text, in unscaled cells. | |
| 264 | 271 | * @param int $columns The paper width in character cells. |
| 272 | + * @param int $scale The text width multiplier in force. Default 1. | |
| 265 | 273 | * |
| 266 | 274 | * @return int The number of leading spaces (clamped at 0). |
| 267 | 275 | */ |
| 268 | - public static function alignment_padding( string $align, int $text_width, int $columns ): int { | |
| 269 | - $remaining = $columns - $text_width; | |
| 276 | + public static function alignment_padding( string $align, int $text_width, int $columns, int $scale = 1 ): int { | |
| 277 | + $scale = max( 1, $scale ); | |
| 278 | + $remaining = $columns - ( $text_width * $scale ); | |
| 270 | 279 | if ( $remaining <= 0 ) { |
| 271 | 280 | return 0; |
| 272 | 281 | } |
| 273 | 282 | if ( 'center' === $align ) { |
| 274 | - return (int) floor( $remaining / 2 ); | |
| 283 | + return (int) floor( (int) floor( $remaining / 2 ) / $scale ); | |
| 275 | 284 | } |
| 276 | 285 | if ( 'right' === $align ) { |
| 277 | - return $remaining; | |
| 286 | + return (int) floor( $remaining / $scale ); | |
| 278 | 287 | } |
| 279 | 288 | |
| 280 | 289 | return 0; |
| 281 | 290 | } |