()
| 1006 | } |
| 1007 | |
| 1008 | async printResult() { |
| 1009 | if (!this.basePixelCanvas) { |
| 1010 | this.showError('没有可打印的图像'); |
| 1011 | return; |
| 1012 | } |
| 1013 | |
| 1014 | try { |
| 1015 | // 创建10倍放大的打印canvas |
| 1016 | const printCanvas = document.createElement('canvas'); |
| 1017 | const scale = 10; |
| 1018 | |
| 1019 | printCanvas.width = this.basePixelCanvas.width * scale; |
| 1020 | printCanvas.height = this.basePixelCanvas.height * scale; |
| 1021 | |
| 1022 | const ctx = printCanvas.getContext('2d'); |
| 1023 | ctx.imageSmoothingEnabled = false; |
| 1024 | |
| 1025 | // 最近邻放大 |
| 1026 | ctx.drawImage( |
| 1027 | this.basePixelCanvas, |
| 1028 | 0, 0, this.basePixelCanvas.width, this.basePixelCanvas.height, |
| 1029 | 0, 0, printCanvas.width, printCanvas.height |
| 1030 | ); |
| 1031 | |
| 1032 | // 绘制网格(按打印尺寸) |
| 1033 | if (document.getElementById('showPixelGrid').checked) { |
| 1034 | this.drawExportGrid(printCanvas, scale); |
| 1035 | } |
| 1036 | |
| 1037 | // 转换为dataURL并打印 |
| 1038 | const dataURL = printCanvas.toDataURL('image/png'); |
| 1039 | this.printFromDataURL(dataURL); |
| 1040 | this.showSuccess('打印窗口已打开!'); |
| 1041 | |
| 1042 | } catch (error) { |
| 1043 | console.error('Print failed:', error); |
| 1044 | this.showError('打印失败: ' + error.message); |
| 1045 | } |
| 1046 | } |
| 1047 | |
| 1048 | printFromDataURL(dataURL) { |
| 1049 | const printWindow = window.open('', '_blank'); |
nothing calls this directly
no test coverage detected