@huaqiu/js-gerbv 0.0.0-stage → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +151 -0
- package/LICENSE +674 -0
- package/README.md +105 -2
- package/include/config.h +34 -0
- package/include/gettext.h +9 -0
- package/index.js +382 -0
- package/package.json +46 -4
- package/prebuilds/darwin-arm64/gerbv_node.node +0 -0
- package/prebuilds/darwin-arm64/libglib-2.0.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libintl.8.dylib +0 -0
- package/prebuilds/darwin-arm64/libpcre2-8.0.dylib +0 -0
- package/prebuilds/darwin-arm64/meta.json +9 -0
- package/prebuilds/win32-x64/gerbv_node.node +0 -0
- package/prebuilds/win32-x64/libffi-8.dll +0 -0
- package/prebuilds/win32-x64/libgcc_s_seh-1.dll +0 -0
- package/prebuilds/win32-x64/libgio-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libglib-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libgmodule-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libgobject-2.0-0.dll +0 -0
- package/prebuilds/win32-x64/libiconv-2.dll +0 -0
- package/prebuilds/win32-x64/libintl-8.dll +0 -0
- package/prebuilds/win32-x64/libpcre2-8-0.dll +0 -0
- package/prebuilds/win32-x64/libstdc++-6.dll +0 -0
- package/prebuilds/win32-x64/libwinpthread-1.dll +0 -0
- package/prebuilds/win32-x64/meta.json +9 -0
- package/prebuilds/win32-x64/zlib1.dll +0 -0
- package/scripts/cmake-build.js +231 -0
- package/scripts/ensure-gerbv.js +42 -0
- package/scripts/pack-prebuild.js +208 -0
- package/scripts/smoke.js +74 -0
- package/shim/gdk/gdk.h +15 -0
- package/shim/gdk/gdkkeysyms.h +3 -0
- package/shim/gtk/gtk.h +7 -0
- package/src/addon.cc +740 -0
- package/src/gerber_min.c +67 -0
- package/src/gerbv_stubs.c +79 -0
- package/vcpkg.json +8 -0
package/README.md
CHANGED
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
#
|
|
1
|
+
# js-gerbv
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node N-API 封装 [efa/gerbv](https://github.com/efa/gerbv) 核心导出路径(RS-274X / Excellon)。
|
|
4
|
+
|
|
5
|
+
仓库:https://github.com/Huaqiu-Electronics/js-gerbv
|
|
6
|
+
|
|
7
|
+
> 与 libgerbv 一并使用时,整体按 **GPL-2.0-or-later** 义务理解(见 `package.json`)。根目录 `LICENSE` 为仓库初始文件。
|
|
8
|
+
|
|
9
|
+
## 布局
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
prebuilds/<platform>-<arch>/gerbv_node.node # CI / 本机 pack 产物
|
|
13
|
+
build/gerbv_node.node # 本地 cmake 输出
|
|
14
|
+
vendor/gerbv/ # 构建时浅克隆(gitignore)
|
|
15
|
+
index.js # 按平台加载
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`platform-arch` 例:`darwin-arm64`、`linux-x64`、`win32-x64`。Windows 还会拷贝 glib 等运行时 DLL 到同目录。
|
|
19
|
+
|
|
20
|
+
## 本机构建
|
|
21
|
+
|
|
22
|
+
| 平台 | 依赖 |
|
|
23
|
+
|------|------|
|
|
24
|
+
| macOS | `brew install glib pkg-config cmake`;Node ≥ 20 |
|
|
25
|
+
| Linux | `libglib2.0-dev pkg-config cmake` |
|
|
26
|
+
| Windows | CMake + vcpkg `glib:x64-windows`(设 `VCPKG_ROOT`),或 MSYS2 mingw64(自动检测 `C:/msys64`,需 `glib2`/`pkgconf`/`gcc`) |
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install
|
|
30
|
+
npm run build # ensure-gerbv → cmake → pack prebuild
|
|
31
|
+
npm run smoke
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
可选:`GERBV_SRC=/path/to/gerbv` 指向已有 efa/gerbv 树,跳过克隆。
|
|
35
|
+
|
|
36
|
+
## 在应用中使用
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
const gerbv = require("@huaqiu/js-gerbv");
|
|
40
|
+
// unit: 输入单位(native 侧换算为 inch);precision: 换算后 inch 小数位
|
|
41
|
+
const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
42
|
+
|
|
43
|
+
// 多段线:起点在 createPolyline;add* 只给下一点
|
|
44
|
+
const pl = img.createPolyline(0, 0, 0.25);
|
|
45
|
+
pl.addPolylineLine(12.7, 0);
|
|
46
|
+
pl.addPolylineArc(6.35, 0, 6.35, 6.35, false);
|
|
47
|
+
pl.endPolyline();
|
|
48
|
+
|
|
49
|
+
// 区域:起点在 createPolygon;add* 只给下一点
|
|
50
|
+
const poly = img.createPolygon(0, 0);
|
|
51
|
+
poly.addPolygonLine(12.7, 0);
|
|
52
|
+
poly.addPolygonArc(12.7, 6.35, 12.7, 12.7, false);
|
|
53
|
+
poly.addPolygonBezier2(6.35, 15, 0, 12.7);
|
|
54
|
+
|
|
55
|
+
const hole = poly.createHole(3, 3); // 起点在 createHole
|
|
56
|
+
hole.addPolygonArc(5, 5, 7, 3, false);
|
|
57
|
+
hole.addPolygonBezier2(5.5, 7, 3, 6);
|
|
58
|
+
hole.endHole();
|
|
59
|
+
|
|
60
|
+
poly.addCircleHole(9, 6, 2);
|
|
61
|
+
poly.endArea();
|
|
62
|
+
|
|
63
|
+
img.addRect(15, 0, 10, 8).addCircleHole(20, 4, 2.5).endArea();
|
|
64
|
+
img.addCircle(30, 4, 6).endArea();
|
|
65
|
+
img.addCircleRing(40, 4, 8, 1.5);
|
|
66
|
+
|
|
67
|
+
const buf = img.exportRs274x();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
输入单位由 `createImage({ unit })` 指定(`inch` 默认 / `mm`);内部与导出仍为 inch(`%MOIN*%`)。`precision` 为换算到 inch 后保留的小数位。
|
|
71
|
+
|
|
72
|
+
`createPolygon` / `createHole` / `createPolyline` 均带**起点**;后续 `add*` 只传下一点/终点。
|
|
73
|
+
|
|
74
|
+
| API | 说明 |
|
|
75
|
+
|-----|------|
|
|
76
|
+
| `createImage({ unit?, precision? })` | 返回方法式 image;换算在 native 侧 |
|
|
77
|
+
| `img.createPolyline(x,y,w)` | 多段线起点 + 线宽 |
|
|
78
|
+
| `pl.addPolylineLine(x,y)` | 直线到点 |
|
|
79
|
+
| `pl.addPolylineArc(cx,cy,x,y,cw?)` | 圆弧到点 |
|
|
80
|
+
| `pl.addPolylineBezier2/3(...)` | 贝塞尔到点 |
|
|
81
|
+
| `pl.endPolyline()` | 结束多段线 |
|
|
82
|
+
| `img.addLine` / `addArc` / `addBezier2/3` | 单段描边(完整起止) |
|
|
83
|
+
| `img.addFlashCircle(x,y,d)` | 光圈 flash |
|
|
84
|
+
| `img.addRect` / `addCircle` | 矩形/圆 region(需 `endArea`) |
|
|
85
|
+
| `img.addCircleRing(cx,cy,d,w)` | 圆环(外径 d、环宽 w) |
|
|
86
|
+
| `img.createPolygon(x,y)` | region 起点 |
|
|
87
|
+
| `poly/hole.addPolygonLine(x,y)` | 直线到点 |
|
|
88
|
+
| `poly/hole.addPolygonArc` / `Bezier2/3` | 弧/贝塞尔到点 |
|
|
89
|
+
| `poly.createHole(x,y)` / `hole.endHole()` | 任意轮廓孔 |
|
|
90
|
+
| `poly.addCircleHole(cx,cy,d)` | 整圆孔 |
|
|
91
|
+
| `poly.endArea()` | 写出外环 + 孔 |
|
|
92
|
+
| `img.exportRs274x()` / `exportDrill()` | 导出 Buffer |
|
|
93
|
+
|
|
94
|
+
安装(含已发布的 **darwin-arm64** prebuild,无需本机编):
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npm install @huaqiu/js-gerbv
|
|
98
|
+
# 或尚未上 npm 时:
|
|
99
|
+
npm install github:Huaqiu-Electronics/js-gerbv#v0.1.3
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
本地联调可用 `"@huaqiu/js-gerbv": "file:../js-gerbv"`。
|
|
103
|
+
|
|
104
|
+
## CI
|
|
105
|
+
|
|
106
|
+
`.github/workflows/ci.yml`:`macos-14` / `ubuntu-22.04` / `windows-2022` 矩阵编 prebuild 并上传 artifact。
|
package/include/config.h
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#ifndef GERBV_NODE_CONFIG_H
|
|
2
|
+
#define GERBV_NODE_CONFIG_H
|
|
3
|
+
|
|
4
|
+
#define VERSION "2.10.0-hqpcb-lite"
|
|
5
|
+
#define PACKAGE "gerbv"
|
|
6
|
+
#define PACKAGE_BUGREPORT ""
|
|
7
|
+
#define PACKAGE_NAME "gerbv"
|
|
8
|
+
#define PACKAGE_STRING "gerbv 2.10.0-hqpcb-lite"
|
|
9
|
+
#define PACKAGE_TARNAME "gerbv"
|
|
10
|
+
#define PACKAGE_VERSION "2.10.0-hqpcb-lite"
|
|
11
|
+
|
|
12
|
+
#define HAVE_CONFIG_H 1
|
|
13
|
+
#define HAVE_STRING_H 1
|
|
14
|
+
#define HAVE_STDLIB_H 1
|
|
15
|
+
#define HAVE_UNISTD_H 1
|
|
16
|
+
#define HAVE_LIBGEN_H 1
|
|
17
|
+
|
|
18
|
+
/* headless: no gettext catalog */
|
|
19
|
+
#undef ENABLE_NLS
|
|
20
|
+
#define gettext(str) (str)
|
|
21
|
+
#define dgettext(d, str) (str)
|
|
22
|
+
#define dcgettext(d, str, c) (str)
|
|
23
|
+
#define ngettext(a, b, n) ((n) == 1 ? (a) : (b))
|
|
24
|
+
#define gettext_noop(str) (str)
|
|
25
|
+
|
|
26
|
+
/* Prefer GDK stubs over cairo in public header */
|
|
27
|
+
#define RENDER_USING_GDK 1
|
|
28
|
+
|
|
29
|
+
#ifndef DEBUG
|
|
30
|
+
#define DEBUG 0
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#endif
|
|
34
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#ifndef GERBV_NODE_GETTEXT_H
|
|
2
|
+
#define GERBV_NODE_GETTEXT_H
|
|
3
|
+
#define gettext(String) (String)
|
|
4
|
+
#define dgettext(Domain, String) (String)
|
|
5
|
+
#define dcgettext(Domain, String, Type) (String)
|
|
6
|
+
#define ngettext(Msgid1, Msgid2, N) ((N) == 1 ? (Msgid1) : (Msgid2))
|
|
7
|
+
#define dngettext(Domain, Msgid1, Msgid2, N) ((N) == 1 ? (Msgid1) : (Msgid2))
|
|
8
|
+
#define gettext_noop(String) (String)
|
|
9
|
+
#endif
|
package/index.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 加载当前平台的 gerbv_node 原生插件。
|
|
3
|
+
*
|
|
4
|
+
* createPolygon(x,y) / createHole(x,y) / createPolyline(x,y,w):
|
|
5
|
+
* 起点在 create*;后续 add* 只给下一点 / 终点。
|
|
6
|
+
*/
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
|
|
12
|
+
function platformKey() {
|
|
13
|
+
return process.platform + "-" + process.arch;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function candidates() {
|
|
17
|
+
const key = platformKey();
|
|
18
|
+
const root = __dirname;
|
|
19
|
+
return [
|
|
20
|
+
path.join(root, "prebuilds", key, "gerbv_node.node"),
|
|
21
|
+
path.join(root, "build", "gerbv_node.node"),
|
|
22
|
+
path.join(root, "build", "Release", "gerbv_node.node"),
|
|
23
|
+
path.join(root, "build", "Debug", "gerbv_node.node"),
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function resolveAddon() {
|
|
28
|
+
for (const p of candidates()) {
|
|
29
|
+
if (fs.existsSync(p)) return p;
|
|
30
|
+
}
|
|
31
|
+
throw new Error(
|
|
32
|
+
"gerbv_node.node not found for " +
|
|
33
|
+
platformKey() +
|
|
34
|
+
".\nTried:\n - " +
|
|
35
|
+
candidates().join("\n - ") +
|
|
36
|
+
"\nBuild: npm run build (see https://github.com/Huaqiu-Electronics/js-gerbv)"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @param {unknown} obj */
|
|
41
|
+
function unwrap(obj) {
|
|
42
|
+
if (obj && typeof obj === "object" && "__handle" in obj) {
|
|
43
|
+
return /** @type {{ __handle: unknown }} */ (obj).__handle;
|
|
44
|
+
}
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function requireXY(api, x, y) {
|
|
49
|
+
if (typeof x !== "number" || typeof y !== "number" || Number.isNaN(x) || Number.isNaN(y)) {
|
|
50
|
+
throw new Error(api + "(x, y) requires numeric start point");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 矩形外环(左下角 + 宽高) */
|
|
55
|
+
function seedRectCmds(x, y, w, h) {
|
|
56
|
+
return [
|
|
57
|
+
{ t: "L", x, y },
|
|
58
|
+
{ t: "L", x: x + w, y },
|
|
59
|
+
{ t: "L", x: x + w, y: y + h },
|
|
60
|
+
{ t: "L", x, y: y + h },
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 圆形外环:右点起点 + 两段半圆弧 */
|
|
65
|
+
function seedCircleCmds(cx, cy, diam) {
|
|
66
|
+
const r = diam / 2;
|
|
67
|
+
return [
|
|
68
|
+
{ t: "L", x: cx + r, y: cy },
|
|
69
|
+
{ t: "A", cx, cy, x: cx - r, y: cy, cw: false },
|
|
70
|
+
{ t: "A", cx, cy, x: cx + r, y: cy, cw: false },
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {object} native
|
|
76
|
+
* @param {unknown} imageHandle
|
|
77
|
+
* @param {object[]} cmds
|
|
78
|
+
* @param {boolean} clear
|
|
79
|
+
*/
|
|
80
|
+
function replayContour(native, imageHandle, cmds, clear) {
|
|
81
|
+
if (!cmds.length) return;
|
|
82
|
+
const h = native.createPolygon(imageHandle, !!clear);
|
|
83
|
+
for (const c of cmds) {
|
|
84
|
+
if (c.t === "L") native.addPolygonLine(h, c.x, c.y);
|
|
85
|
+
else if (c.t === "A")
|
|
86
|
+
native.addPolygonArc(h, c.cx, c.cy, c.x, c.y, !!c.cw);
|
|
87
|
+
else if (c.t === "B2")
|
|
88
|
+
native.addPolygonBezier2(h, c.c1x, c.c1y, c.x, c.y);
|
|
89
|
+
else if (c.t === "B3")
|
|
90
|
+
native.addPolygonBezier3(h, c.c1x, c.c1y, c.c2x, c.c2y, c.x, c.y);
|
|
91
|
+
}
|
|
92
|
+
native.endPolygon(h);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 外环:add* 只追加下一点;createHole(x,y) / addCircleHole / endArea。
|
|
97
|
+
* @param {object[]} cmds
|
|
98
|
+
* @param {object} extras
|
|
99
|
+
*/
|
|
100
|
+
function wrapOuter(cmds, extras) {
|
|
101
|
+
const contour = {
|
|
102
|
+
addPolygonLine(x, y) {
|
|
103
|
+
cmds.push({ t: "L", x, y });
|
|
104
|
+
return contour;
|
|
105
|
+
},
|
|
106
|
+
addPolygonArc(cx, cy, x, y, clockwise) {
|
|
107
|
+
cmds.push({ t: "A", cx, cy, x, y, cw: !!clockwise });
|
|
108
|
+
return contour;
|
|
109
|
+
},
|
|
110
|
+
addPolygonBezier2(c1x, c1y, x, y) {
|
|
111
|
+
cmds.push({ t: "B2", c1x, c1y, x, y });
|
|
112
|
+
return contour;
|
|
113
|
+
},
|
|
114
|
+
addPolygonBezier3(c1x, c1y, c2x, c2y, x, y) {
|
|
115
|
+
cmds.push({ t: "B3", c1x, c1y, c2x, c2y, x, y });
|
|
116
|
+
return contour;
|
|
117
|
+
},
|
|
118
|
+
createHole: extras.createHole,
|
|
119
|
+
addCircleHole: extras.addCircleHole,
|
|
120
|
+
endArea: extras.endArea,
|
|
121
|
+
};
|
|
122
|
+
return contour;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 孔:起点已在 createHole(x,y);add* 只给下一点;endHole 结束。
|
|
127
|
+
* @param {object[]} cmds
|
|
128
|
+
*/
|
|
129
|
+
function wrapHole(cmds) {
|
|
130
|
+
let ended = false;
|
|
131
|
+
function ensureOpen(api) {
|
|
132
|
+
if (ended) throw new Error(api + ": hole already ended");
|
|
133
|
+
}
|
|
134
|
+
const hole = {
|
|
135
|
+
addPolygonLine(x, y) {
|
|
136
|
+
ensureOpen("addPolygonLine");
|
|
137
|
+
cmds.push({ t: "L", x, y });
|
|
138
|
+
return hole;
|
|
139
|
+
},
|
|
140
|
+
addPolygonArc(cx, cy, x, y, clockwise) {
|
|
141
|
+
ensureOpen("addPolygonArc");
|
|
142
|
+
cmds.push({ t: "A", cx, cy, x, y, cw: !!clockwise });
|
|
143
|
+
return hole;
|
|
144
|
+
},
|
|
145
|
+
addPolygonBezier2(c1x, c1y, x, y) {
|
|
146
|
+
ensureOpen("addPolygonBezier2");
|
|
147
|
+
cmds.push({ t: "B2", c1x, c1y, x, y });
|
|
148
|
+
return hole;
|
|
149
|
+
},
|
|
150
|
+
addPolygonBezier3(c1x, c1y, c2x, c2y, x, y) {
|
|
151
|
+
ensureOpen("addPolygonBezier3");
|
|
152
|
+
cmds.push({ t: "B3", c1x, c1y, c2x, c2y, x, y });
|
|
153
|
+
return hole;
|
|
154
|
+
},
|
|
155
|
+
endHole() {
|
|
156
|
+
ended = true;
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
return hole;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {object} native
|
|
164
|
+
* @param {unknown} imageHandle
|
|
165
|
+
* @param {object[]} seedOuter 至少含起点
|
|
166
|
+
*/
|
|
167
|
+
function wrapRegion(native, imageHandle, seedOuter) {
|
|
168
|
+
const outerCmds = seedOuter.slice();
|
|
169
|
+
/** @type {object[][]} */
|
|
170
|
+
const holes = [];
|
|
171
|
+
let finished = false;
|
|
172
|
+
|
|
173
|
+
const region = wrapOuter(outerCmds, {
|
|
174
|
+
createHole(x, y) {
|
|
175
|
+
if (finished) throw new Error("polygon already ended");
|
|
176
|
+
requireXY("createHole", x, y);
|
|
177
|
+
const holeCmds = [{ t: "L", x, y }];
|
|
178
|
+
holes.push(holeCmds);
|
|
179
|
+
return wrapHole(holeCmds);
|
|
180
|
+
},
|
|
181
|
+
addCircleHole(cx, cy, diam) {
|
|
182
|
+
if (finished) throw new Error("polygon already ended");
|
|
183
|
+
holes.push(seedCircleCmds(cx, cy, diam));
|
|
184
|
+
return region;
|
|
185
|
+
},
|
|
186
|
+
endArea() {
|
|
187
|
+
if (finished) return;
|
|
188
|
+
finished = true;
|
|
189
|
+
replayContour(native, imageHandle, outerCmds, false);
|
|
190
|
+
for (const holeCmds of holes) {
|
|
191
|
+
replayContour(native, imageHandle, holeCmds, true);
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
return region;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 多段线描边:createPolyline(x,y,width);add* 只给下一点;endPolyline。
|
|
200
|
+
* @param {object} native
|
|
201
|
+
* @param {unknown} imageHandle
|
|
202
|
+
* @param {number} x0
|
|
203
|
+
* @param {number} y0
|
|
204
|
+
* @param {number} width
|
|
205
|
+
*/
|
|
206
|
+
function wrapPolyline(native, imageHandle, x0, y0, width) {
|
|
207
|
+
let curX = x0;
|
|
208
|
+
let curY = y0;
|
|
209
|
+
let finished = false;
|
|
210
|
+
function ensureOpen(api) {
|
|
211
|
+
if (finished) throw new Error(api + ": polyline already ended");
|
|
212
|
+
}
|
|
213
|
+
const pl = {
|
|
214
|
+
addPolylineLine(x, y) {
|
|
215
|
+
ensureOpen("addPolylineLine");
|
|
216
|
+
native.addLine(imageHandle, curX, curY, x, y, width);
|
|
217
|
+
curX = x;
|
|
218
|
+
curY = y;
|
|
219
|
+
return pl;
|
|
220
|
+
},
|
|
221
|
+
addPolylineArc(cx, cy, x, y, clockwise) {
|
|
222
|
+
ensureOpen("addPolylineArc");
|
|
223
|
+
native.addArc(imageHandle, cx, cy, curX, curY, x, y, width, !!clockwise);
|
|
224
|
+
curX = x;
|
|
225
|
+
curY = y;
|
|
226
|
+
return pl;
|
|
227
|
+
},
|
|
228
|
+
addPolylineBezier2(c1x, c1y, x, y) {
|
|
229
|
+
ensureOpen("addPolylineBezier2");
|
|
230
|
+
native.addBezier2(imageHandle, curX, curY, c1x, c1y, x, y, width);
|
|
231
|
+
curX = x;
|
|
232
|
+
curY = y;
|
|
233
|
+
return pl;
|
|
234
|
+
},
|
|
235
|
+
addPolylineBezier3(c1x, c1y, c2x, c2y, x, y) {
|
|
236
|
+
ensureOpen("addPolylineBezier3");
|
|
237
|
+
native.addBezier3(
|
|
238
|
+
imageHandle,
|
|
239
|
+
curX,
|
|
240
|
+
curY,
|
|
241
|
+
c1x,
|
|
242
|
+
c1y,
|
|
243
|
+
c2x,
|
|
244
|
+
c2y,
|
|
245
|
+
x,
|
|
246
|
+
y,
|
|
247
|
+
width
|
|
248
|
+
);
|
|
249
|
+
curX = x;
|
|
250
|
+
curY = y;
|
|
251
|
+
return pl;
|
|
252
|
+
},
|
|
253
|
+
endPolyline() {
|
|
254
|
+
finished = true;
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
return pl;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* @param {object} native
|
|
262
|
+
* @param {unknown} handle
|
|
263
|
+
*/
|
|
264
|
+
function wrapImage(native, handle) {
|
|
265
|
+
const img = {
|
|
266
|
+
/** @internal */
|
|
267
|
+
__handle: handle,
|
|
268
|
+
addLine(x1, y1, x2, y2, width) {
|
|
269
|
+
native.addLine(handle, x1, y1, x2, y2, width);
|
|
270
|
+
return img;
|
|
271
|
+
},
|
|
272
|
+
addArc(cx, cy, x1, y1, x2, y2, width, clockwise) {
|
|
273
|
+
native.addArc(handle, cx, cy, x1, y1, x2, y2, width, !!clockwise);
|
|
274
|
+
return img;
|
|
275
|
+
},
|
|
276
|
+
addBezier2(x1, y1, c1x, c1y, x2, y2, width) {
|
|
277
|
+
native.addBezier2(handle, x1, y1, c1x, c1y, x2, y2, width);
|
|
278
|
+
return img;
|
|
279
|
+
},
|
|
280
|
+
addBezier3(x1, y1, c1x, c1y, c2x, c2y, x2, y2, width) {
|
|
281
|
+
native.addBezier3(handle, x1, y1, c1x, c1y, c2x, c2y, x2, y2, width);
|
|
282
|
+
return img;
|
|
283
|
+
},
|
|
284
|
+
addFlashCircle(x, y, diam) {
|
|
285
|
+
native.addFlashCircle(handle, x, y, diam);
|
|
286
|
+
return img;
|
|
287
|
+
},
|
|
288
|
+
addRect(x, y, width, height) {
|
|
289
|
+
return wrapRegion(native, handle, seedRectCmds(x, y, width, height));
|
|
290
|
+
},
|
|
291
|
+
addCircle(cx, cy, diam) {
|
|
292
|
+
return wrapRegion(native, handle, seedCircleCmds(cx, cy, diam));
|
|
293
|
+
},
|
|
294
|
+
addCircleRing(cx, cy, d, w) {
|
|
295
|
+
const region = wrapRegion(native, handle, seedCircleCmds(cx, cy, d));
|
|
296
|
+
const holeD = d - 2 * w;
|
|
297
|
+
if (w > 0 && holeD > 0) region.addCircleHole(cx, cy, holeD);
|
|
298
|
+
region.endArea();
|
|
299
|
+
return img;
|
|
300
|
+
},
|
|
301
|
+
/** @param {number} x @param {number} y */
|
|
302
|
+
createPolygon(x, y) {
|
|
303
|
+
requireXY("createPolygon", x, y);
|
|
304
|
+
return wrapRegion(native, handle, [{ t: "L", x, y }]);
|
|
305
|
+
},
|
|
306
|
+
/** @param {number} x @param {number} y @param {number} width */
|
|
307
|
+
createPolyline(x, y, width) {
|
|
308
|
+
requireXY("createPolyline", x, y);
|
|
309
|
+
if (typeof width !== "number" || !(width > 0)) {
|
|
310
|
+
throw new Error("createPolyline(x, y, width) requires positive width");
|
|
311
|
+
}
|
|
312
|
+
return wrapPolyline(native, handle, x, y, width);
|
|
313
|
+
},
|
|
314
|
+
exportRs274x() {
|
|
315
|
+
return native.exportRs274x(handle);
|
|
316
|
+
},
|
|
317
|
+
exportDrill() {
|
|
318
|
+
return native.exportDrill(handle);
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
return img;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const addonPath = resolveAddon();
|
|
325
|
+
const native = require(addonPath);
|
|
326
|
+
|
|
327
|
+
module.exports = {
|
|
328
|
+
backend: native.backend,
|
|
329
|
+
__addonPath: addonPath,
|
|
330
|
+
__platformKey: platformKey(),
|
|
331
|
+
/**
|
|
332
|
+
* @param {{ unit?: 'inch'|'mm'|'in', precision?: number }} [opts]
|
|
333
|
+
*/
|
|
334
|
+
createImage(opts) {
|
|
335
|
+
return wrapImage(native, native.createImage(opts || {}));
|
|
336
|
+
},
|
|
337
|
+
/** @deprecated 优先用 img.createPolygon(x, y) */
|
|
338
|
+
createPolygon(image, x, y) {
|
|
339
|
+
requireXY("createPolygon", x, y);
|
|
340
|
+
return wrapRegion(native, unwrap(image), [{ t: "L", x, y }]);
|
|
341
|
+
},
|
|
342
|
+
/** @deprecated */
|
|
343
|
+
addLine(image, x1, y1, x2, y2, width) {
|
|
344
|
+
native.addLine(unwrap(image), x1, y1, x2, y2, width);
|
|
345
|
+
},
|
|
346
|
+
addArc(image, cx, cy, x1, y1, x2, y2, width, clockwise) {
|
|
347
|
+
native.addArc(unwrap(image), cx, cy, x1, y1, x2, y2, width, !!clockwise);
|
|
348
|
+
},
|
|
349
|
+
addBezier2(image, x1, y1, c1x, c1y, x2, y2, width) {
|
|
350
|
+
native.addBezier2(unwrap(image), x1, y1, c1x, c1y, x2, y2, width);
|
|
351
|
+
},
|
|
352
|
+
addBezier3(image, x1, y1, c1x, c1y, c2x, c2y, x2, y2, width) {
|
|
353
|
+
native.addBezier3(
|
|
354
|
+
unwrap(image),
|
|
355
|
+
x1,
|
|
356
|
+
y1,
|
|
357
|
+
c1x,
|
|
358
|
+
c1y,
|
|
359
|
+
c2x,
|
|
360
|
+
c2y,
|
|
361
|
+
x2,
|
|
362
|
+
y2,
|
|
363
|
+
width
|
|
364
|
+
);
|
|
365
|
+
},
|
|
366
|
+
addFlashCircle(image, x, y, diam) {
|
|
367
|
+
native.addFlashCircle(unwrap(image), x, y, diam);
|
|
368
|
+
},
|
|
369
|
+
addRect(image, x, y, width, height) {
|
|
370
|
+
wrapRegion(
|
|
371
|
+
native,
|
|
372
|
+
unwrap(image),
|
|
373
|
+
seedRectCmds(x, y, width, height)
|
|
374
|
+
).endArea();
|
|
375
|
+
},
|
|
376
|
+
exportRs274x(image) {
|
|
377
|
+
return native.exportRs274x(unwrap(image));
|
|
378
|
+
},
|
|
379
|
+
exportDrill(image) {
|
|
380
|
+
return native.exportDrill(unwrap(image));
|
|
381
|
+
},
|
|
382
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huaqiu/js-gerbv",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.15",
|
|
4
|
+
"description": "Node N-API binding for libgerbv (efa/gerbv) RS-274X/Drill export",
|
|
5
|
+
"license": "GPL-2.0-or-later",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Huaqiu-Electronics/js-gerbv.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/Huaqiu-Electronics/js-gerbv/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/Huaqiu-Electronics/js-gerbv#readme",
|
|
14
|
+
"main": "index.js",
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"ensure-gerbv": "node scripts/ensure-gerbv.js",
|
|
21
|
+
"build": "node scripts/ensure-gerbv.js && node scripts/cmake-build.js && node scripts/pack-prebuild.js",
|
|
22
|
+
"pack": "node scripts/pack-prebuild.js",
|
|
23
|
+
"smoke": "node scripts/smoke.js",
|
|
24
|
+
"prepack": "node -e \"const fs=require('fs');if(!fs.existsSync('prebuilds')){console.error('missing prebuilds/; run npm run build');process.exit(1)}\"",
|
|
25
|
+
"install:deps": "npm install --no-fund --no-audit"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"index.js",
|
|
32
|
+
"prebuilds/**",
|
|
33
|
+
"src/**",
|
|
34
|
+
"include/**",
|
|
35
|
+
"shim/**",
|
|
36
|
+
"CMakeLists.txt",
|
|
37
|
+
"scripts/**",
|
|
38
|
+
"vcpkg.json",
|
|
39
|
+
"README.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"node-addon-api": "^8.9.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"node-api-headers": "^1.9.0"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|