-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Solved a bug that printing images is not correct
- Loading branch information
Showing
10 changed files
with
103 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@node-escpos/core": patch | ||
"@node-escpos/usb-adapter": patch | ||
--- | ||
|
||
🐛 Solved a bug that printing images is not correct. | ||
🧾 Update demo of README. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,51 @@ | ||
import { Printer } from "@node-escpos/core"; | ||
import { Image, Printer } from "@node-escpos/core"; | ||
import USB from "@node-escpos/usb-adapter"; | ||
import { join } from "path"; | ||
import { describe, it } from "vitest"; | ||
|
||
describe("should work as expected", () => { | ||
it("printing", async () => { | ||
const device = new USB(); | ||
const printer = new Printer(device, {}); | ||
const device = new USB(); | ||
await new Promise<void>((resolve,reject) => { | ||
device.open(async function(err){ | ||
if(err){ | ||
reject(err); | ||
return | ||
} | ||
|
||
await new Promise<void>((resolve) => { | ||
printer | ||
.font("a") | ||
.align("ct") | ||
.style("bu") | ||
.size(1, 1) | ||
.text("The quick brown fox jumps over the lazy dog") | ||
.text("敏捷的棕色狐狸跳过懒狗") | ||
.barcode(1234567, "EAN13", { width: 50, height: 50 }) | ||
.table(["One", "Two", "Three"]) | ||
.tableCustom( | ||
[ | ||
{ text: "Left", align: "LEFT", width: 0.33, style: "B" }, | ||
{ text: "Center", align: "CENTER", width: 0.33 }, | ||
{ text: "Right", align: "RIGHT", width: 0.33 }, | ||
], | ||
{ encoding: "cp857", size: [1, 1] }, // Optional | ||
) | ||
.qrimage("https://github.com/song940/node-escpos") | ||
.then((printer) => { | ||
printer.cut(); | ||
printer.close(); | ||
}).finally(() => { | ||
resolve(); | ||
}); | ||
let printer = new Printer(device, {}); | ||
|
||
const tux = join(__dirname, '../assets/tux.png'); | ||
const image = await Image.load(tux); | ||
|
||
printer | ||
.font("a") | ||
.align("ct") | ||
.style("bu") | ||
.size(1, 1) | ||
.text("The quick brown fox jumps over the lazy dog") | ||
.text("敏捷的棕色狐狸跳过懒狗") | ||
.barcode(112233445566, "EAN13", { width: 50, height: 50 }) | ||
.table(["One", "Two", "Three"]) | ||
.tableCustom( | ||
[ | ||
{ text: "Left", align: "LEFT", width: 0.33, style: "B" }, | ||
{ text: "Center", align: "CENTER", width: 0.33 }, | ||
{ text: "Right", align: "RIGHT", width: 0.33 }, | ||
], | ||
{ encoding: "cp857", size: [1, 1] }, // Optional | ||
) | ||
|
||
// inject qrimage to printer | ||
printer = await printer.qrimage("https://github.com/node-escpos/driver") | ||
// inject image to printer | ||
printer = await printer.image(image, "s8") | ||
|
||
printer | ||
.cut() | ||
.close() | ||
.finally(resolve) | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"author": "Caspian <[email protected]> (https://github.com/dohooo)", | ||
"scripts": { | ||
"build": "pnpm -F '@node-escpos/*' build", | ||
"build:watch": "pnpm -F '@node-escpos/*' build:watch", | ||
"publish": "pnpm run build && changeset publish", | ||
"version": "changeset version" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters