|
352 | 352 | }
|
353 | 353 |
|
354 | 354 | if (command.type === 'image') {
|
355 |
| - result += `<div class='placeholder ${command.type} ${align}'><div style='width: ${command.width / 4 * 3}px; height: ${command.height / 4 * 3}px;'>image</div></div>`; |
| 355 | + let canvas = document.createElement('canvas'); |
| 356 | + canvas.width = command.width; |
| 357 | + canvas.height = command.height; |
| 358 | + |
| 359 | + let ctx = canvas.getContext('2d'); |
| 360 | + ctx.fillStyle = 'black'; |
| 361 | + |
| 362 | + for (let x = 0; x < command.width; x++) { |
| 363 | + for (let y = 0; y < command.height; y++) { |
| 364 | + let bit = 0; |
| 365 | + |
| 366 | + if (command.value == 'raster') { |
| 367 | + let byte = (y * (command.width >> 3)) + (x >> 3) + 8; |
| 368 | + bit = (command.payload[byte] >> (7 - (x % 8))) & 1; |
| 369 | + } |
| 370 | + else { |
| 371 | + let skip = 4; |
| 372 | + |
| 373 | + if (encoder.language == 'esc-pos') { |
| 374 | + skip = 5; |
| 375 | + } |
| 376 | + |
| 377 | + let byte = (x * 3) + Math.floor(y / 8) + skip; |
| 378 | + bit = (command.payload[byte] >> (7 - (y % 8))) & 1; |
| 379 | + } |
| 380 | + |
| 381 | + if (bit) { |
| 382 | + ctx.fillRect(x, y, 1, 1); |
| 383 | + } |
| 384 | + } |
| 385 | + } |
| 386 | + |
| 387 | + result += `<div class='placeholder ${command.type} ${align}'><img src='${canvas.toDataURL()}' style='width: ${command.width / 4 * 3}px; height: ${command.height / 4 * 3}px;'></div>`; |
356 | 388 | }
|
357 | 389 |
|
358 | 390 | if (command.type === 'cut') {
|
|
759 | 791 |
|
760 | 792 | #output[data-format="text"] .placeholder {
|
761 | 793 | width: 100%;
|
762 |
| - margin-bottom: 1px; |
| 794 | + } |
| 795 | + #output[data-format="text"] .placeholder * { |
| 796 | + display: block; |
763 | 797 | }
|
764 | 798 | #output[data-format="text"] .placeholder div {
|
765 | 799 | background: #ddd;
|
|
771 | 805 | justify-content: center;
|
772 | 806 | font-size: 8px;
|
773 | 807 | }
|
774 |
| - #output[data-format="text"] .placeholder.qrcode div { |
| 808 | + #output[data-format="text"] .placeholder.qrcode * { |
775 | 809 | width: calc(var(--width-a) * 16);
|
776 | 810 | height: calc(var(--width-a) * 16);
|
777 | 811 | }
|
778 |
| - #output[data-format="text"] .placeholder.pdf417 div { |
| 812 | + #output[data-format="text"] .placeholder.pdf417 * { |
779 | 813 | height: calc(var(--height-a) * 6);
|
780 | 814 | }
|
781 |
| - #output[data-format="text"] .placeholder.center div { |
| 815 | + #output[data-format="text"] .placeholder.center * { |
782 | 816 | margin: 0 auto;
|
783 | 817 | }
|
784 |
| - #output[data-format="text"] .placeholder.right div { |
| 818 | + #output[data-format="text"] .placeholder.right * { |
785 | 819 | margin-left: auto;
|
786 | 820 | }
|
787 | 821 |
|
|
0 commit comments