@huaqiu/js-gerbv 0.1.15 → 0.1.27
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 +16 -3
- package/README.md +50 -6
- package/examples/example.js +266 -0
- package/examples/example.py +30 -0
- package/index.js +292 -19
- package/lib/add-text.js +552 -0
- package/lib/fill-holes.js +648 -0
- package/lib/hershey-futural.json +1 -0
- package/lib/spline.js +211 -0
- package/lib/system-font.js +166 -0
- package/package.json +8 -3
- package/prebuilds/darwin-arm64/gerbv_node.node +0 -0
- package/prebuilds/darwin-arm64/libX11.6.dylib +0 -0
- package/prebuilds/darwin-arm64/libXau.6.dylib +0 -0
- package/prebuilds/darwin-arm64/libXdmcp.6.dylib +0 -0
- package/prebuilds/darwin-arm64/libXext.6.dylib +0 -0
- package/prebuilds/darwin-arm64/libXrender.1.dylib +0 -0
- package/prebuilds/darwin-arm64/libbrotlicommon.1.dylib +0 -0
- package/prebuilds/darwin-arm64/libbrotlidec.1.dylib +0 -0
- package/prebuilds/darwin-arm64/libcairo.2.dylib +0 -0
- package/prebuilds/darwin-arm64/libfontconfig.1.dylib +0 -0
- package/prebuilds/darwin-arm64/libfreetype.6.dylib +0 -0
- package/prebuilds/darwin-arm64/libpixman-1.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libpng16.16.dylib +0 -0
- package/prebuilds/darwin-arm64/libxcb-render.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libxcb-shm.0.dylib +0 -0
- package/prebuilds/darwin-arm64/libxcb.1.dylib +0 -0
- package/prebuilds/darwin-arm64/meta.json +1 -1
- package/prebuilds/win32-x64/gerbv_node.node +0 -0
- package/prebuilds/win32-x64/libbrotlicommon.dll +0 -0
- package/prebuilds/win32-x64/libbrotlidec.dll +0 -0
- package/prebuilds/win32-x64/libbz2-1.dll +0 -0
- package/prebuilds/win32-x64/libcairo-2.dll +0 -0
- package/prebuilds/win32-x64/libexpat-1.dll +0 -0
- package/prebuilds/win32-x64/libfontconfig-1.dll +0 -0
- package/prebuilds/win32-x64/libfreetype-6.dll +0 -0
- package/prebuilds/win32-x64/libgraphite2.dll +0 -0
- package/prebuilds/win32-x64/libharfbuzz-0.dll +0 -0
- package/prebuilds/win32-x64/libpixman-1-0.dll +0 -0
- package/prebuilds/win32-x64/libpng16-16.dll +0 -0
- package/prebuilds/win32-x64/meta.json +1 -1
- package/scripts/cmake-build.js +8 -0
- package/scripts/pack-prebuild.js +110 -4
- package/scripts/smoke.js +216 -3
- package/src/addon.cc +525 -4
- package/src/export_png.cc +416 -0
- package/src/export_png.h +50 -0
package/scripts/smoke.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/** 冒烟:create*(x,y)
|
|
2
|
+
/** 冒烟:create*(x,y);颜色优先级;区域/DPI;多层 zIndex。 */
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const gerbv = require("../index.js");
|
|
@@ -17,12 +17,26 @@ const gerbv = require("../index.js");
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
20
|
+
img.setLayerColor("#888800");
|
|
21
|
+
img.setObjectColor("#ff0000");
|
|
22
|
+
img.setNetColor("#00ff00");
|
|
20
23
|
|
|
21
24
|
const pl = img.createPolyline(0, 0, 0.25);
|
|
22
25
|
pl.addPolylineLine(12.7, 0);
|
|
23
26
|
pl.addPolylineArc(6.35, 0, 6.35, 6.35, false);
|
|
27
|
+
pl.addPolylineSpline(
|
|
28
|
+
[
|
|
29
|
+
[8, 8],
|
|
30
|
+
[10, 4],
|
|
31
|
+
[12, 6],
|
|
32
|
+
],
|
|
33
|
+
{ degree: 3, steps: 16 }
|
|
34
|
+
);
|
|
24
35
|
pl.endPolyline();
|
|
25
36
|
|
|
37
|
+
img.setNetColor(null);
|
|
38
|
+
img.setObjectColor(null);
|
|
39
|
+
|
|
26
40
|
const poly = img.createPolygon(0, 0);
|
|
27
41
|
poly.addPolygonLine(12.7, 0);
|
|
28
42
|
poly.addPolygonLine(12.7, 10);
|
|
@@ -33,12 +47,43 @@ hole.addPolygonArc(3.8, 3.8, 5.0, 2.5, false);
|
|
|
33
47
|
hole.addPolygonBezier2(4.5, 5.5, 2.5, 5.0);
|
|
34
48
|
hole.endHole();
|
|
35
49
|
|
|
50
|
+
const poly2 = img.createPolygon(48, 0);
|
|
51
|
+
poly2.addPolygonLine(58, 0);
|
|
52
|
+
poly2.addPolygonSpline(
|
|
53
|
+
[
|
|
54
|
+
[60, 3],
|
|
55
|
+
[58, 6],
|
|
56
|
+
[48, 6],
|
|
57
|
+
],
|
|
58
|
+
{ degree: 3 }
|
|
59
|
+
);
|
|
60
|
+
poly2.addPolygonLine(48, 0);
|
|
61
|
+
const hole2 = poly2.createHole(50, 2);
|
|
62
|
+
hole2.addPolygonSpline(
|
|
63
|
+
[
|
|
64
|
+
[54, 1.5],
|
|
65
|
+
[55, 4],
|
|
66
|
+
[51, 4.5],
|
|
67
|
+
[50, 2],
|
|
68
|
+
],
|
|
69
|
+
{ degree: 3, steps: 20 }
|
|
70
|
+
);
|
|
71
|
+
hole2.endHole();
|
|
72
|
+
poly2.endArea();
|
|
73
|
+
|
|
36
74
|
poly.addCircleHole(9, 6, 2);
|
|
37
75
|
poly.endArea();
|
|
38
76
|
|
|
39
77
|
img.addRect(15, 0, 10, 8).addCircleHole(20, 4, 2.5).endArea();
|
|
40
78
|
img.addCircle(30, 4, 6).endArea();
|
|
41
79
|
img.addCircleRing(40, 4, 8, 1.5);
|
|
80
|
+
img.addText(0, 14, "ABC\n123", {
|
|
81
|
+
height: 2,
|
|
82
|
+
strokeWidth: 0.2,
|
|
83
|
+
align: "left",
|
|
84
|
+
angle: 15,
|
|
85
|
+
});
|
|
86
|
+
img.addText(20, 14, "中文", { height: 2, fontFile: "system" });
|
|
42
87
|
|
|
43
88
|
const buf = img.exportRs274x();
|
|
44
89
|
if (!buf || buf.length < 32) {
|
|
@@ -46,10 +91,178 @@ if (!buf || buf.length < 32) {
|
|
|
46
91
|
process.exit(1);
|
|
47
92
|
}
|
|
48
93
|
const text = buf.toString("utf8");
|
|
49
|
-
|
|
50
|
-
|
|
94
|
+
// 带孔:sanitize 后 H/V cut-in 单轮廓挖空(不依赖 LPC;兼容 onlinegerberviewer)
|
|
95
|
+
if (!text.includes("G36") || !text.includes("MOIN")) {
|
|
96
|
+
console.error("missing G36/MOIN");
|
|
51
97
|
process.exit(2);
|
|
52
98
|
}
|
|
99
|
+
{
|
|
100
|
+
// 单孔矩形:cut-in → 1x G36、无 %LPC*%
|
|
101
|
+
const one = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
102
|
+
one.addRect(5, 5, 10, 8).addCircleHole(10, 9, 3).endArea();
|
|
103
|
+
const ot = one.exportRs274x().toString("utf8");
|
|
104
|
+
const nG36 = (ot.match(/G36\*/g) || []).length;
|
|
105
|
+
if (nG36 !== 1) {
|
|
106
|
+
console.error("holed rect expected 1x G36 (cut-in), got", nG36);
|
|
107
|
+
process.exit(27);
|
|
108
|
+
}
|
|
109
|
+
if (ot.includes("%LPC*%")) {
|
|
110
|
+
console.error("holed rect should use cut-in, not %LPC*%");
|
|
111
|
+
process.exit(28);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// 圆环:两段半圆孔径描边,不应再为环本身增加折线 G36 挖孔
|
|
115
|
+
{
|
|
116
|
+
const ringOnly = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
117
|
+
ringOnly.addCircleRing(0, 0, 10, 1);
|
|
118
|
+
const rt = ringOnly.exportRs274x().toString("utf8");
|
|
119
|
+
if (rt.includes("%LPC*%") || rt.includes("G36")) {
|
|
120
|
+
console.error("addCircleRing must be stroke-only (no G36/LPC)", rt.slice(0, 200));
|
|
121
|
+
process.exit(25);
|
|
122
|
+
}
|
|
123
|
+
if (!(rt.includes("G02") || rt.includes("G03"))) {
|
|
124
|
+
console.error("addCircleRing expected G02/G03 arcs");
|
|
125
|
+
process.exit(26);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 挖孔关系:在外丢弃 / 部分相交裁剪 / 全在内保留 — 禁止越界 clear「负负得正」
|
|
130
|
+
{
|
|
131
|
+
const { sanitizeHoles } = require("../lib/fill-holes.js");
|
|
132
|
+
const outer = [
|
|
133
|
+
{ x: 0, y: 0 },
|
|
134
|
+
{ x: 10, y: 0 },
|
|
135
|
+
{ x: 10, y: 10 },
|
|
136
|
+
{ x: 0, y: 10 },
|
|
137
|
+
];
|
|
138
|
+
const inside = [
|
|
139
|
+
{ x: 2, y: 2 },
|
|
140
|
+
{ x: 4, y: 2 },
|
|
141
|
+
{ x: 4, y: 4 },
|
|
142
|
+
{ x: 2, y: 4 },
|
|
143
|
+
];
|
|
144
|
+
const outside = [
|
|
145
|
+
{ x: 20, y: 20 },
|
|
146
|
+
{ x: 22, y: 20 },
|
|
147
|
+
{ x: 22, y: 22 },
|
|
148
|
+
{ x: 20, y: 22 },
|
|
149
|
+
];
|
|
150
|
+
// 压边:一半在外
|
|
151
|
+
const partial = [
|
|
152
|
+
{ x: 8, y: 4 },
|
|
153
|
+
{ x: 12, y: 4 },
|
|
154
|
+
{ x: 12, y: 6 },
|
|
155
|
+
{ x: 8, y: 6 },
|
|
156
|
+
];
|
|
157
|
+
const sIn = sanitizeHoles(outer, [inside]);
|
|
158
|
+
const sOut = sanitizeHoles(outer, [outside]);
|
|
159
|
+
const sPart = sanitizeHoles(outer, [partial]);
|
|
160
|
+
if (sIn.length !== 1) {
|
|
161
|
+
console.error("sanitize: inside hole should keep 1 ring", sIn.length);
|
|
162
|
+
process.exit(20);
|
|
163
|
+
}
|
|
164
|
+
if (sOut.length !== 0) {
|
|
165
|
+
console.error("sanitize: outside hole should drop", sOut.length);
|
|
166
|
+
process.exit(21);
|
|
167
|
+
}
|
|
168
|
+
if (sPart.length < 1) {
|
|
169
|
+
console.error("sanitize: partial hole should clip to >=1 ring", sPart.length);
|
|
170
|
+
process.exit(22);
|
|
171
|
+
}
|
|
172
|
+
// 裁剪后顶点应大致落在 x<=10
|
|
173
|
+
for (const ring of sPart) {
|
|
174
|
+
for (const p of ring) {
|
|
175
|
+
if (p.x > 10.01) {
|
|
176
|
+
console.error("sanitize: clipped hole still outside", p);
|
|
177
|
+
process.exit(23);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 集成:外环旁的越界孔不得产生 LPC,且不应掏空邻近 copper
|
|
183
|
+
const imgH = gerbv.createImage({ unit: "inch" });
|
|
184
|
+
const a = imgH.createPolygon(0, 0);
|
|
185
|
+
a.addPolygonLine(1, 0).addPolygonLine(1, 1).addPolygonLine(0, 1);
|
|
186
|
+
const bad = a.createHole(2, 0.2); // 完全在外
|
|
187
|
+
bad.addPolygonLine(3, 0.2).addPolygonLine(3, 0.8).addPolygonLine(2, 0.8).endHole();
|
|
188
|
+
a.endArea();
|
|
189
|
+
const near = imgH.createPolygon(1.2, 0);
|
|
190
|
+
near.addPolygonLine(2.2, 0).addPolygonLine(2.2, 1).addPolygonLine(1.2, 1);
|
|
191
|
+
near.endArea();
|
|
192
|
+
const gbr = imgH.exportRs274x().toString("utf8");
|
|
193
|
+
// 外环旁越界孔已丢弃 → 整图不应有 LPC(邻块也无孔)
|
|
194
|
+
if (gbr.includes("%LPC*%")) {
|
|
195
|
+
console.error("outside hole must not emit LPC");
|
|
196
|
+
process.exit(24);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
img.setLayerColor("#00aaff");
|
|
200
|
+
const png = img.exportPng({
|
|
201
|
+
width: 320,
|
|
202
|
+
background: "#112233",
|
|
203
|
+
});
|
|
204
|
+
if (!png || png.length < 64 || png[0] !== 0x89 || png[1] !== 0x50) {
|
|
205
|
+
console.error("exportPng failed or not PNG", png && png.length);
|
|
206
|
+
process.exit(7);
|
|
207
|
+
}
|
|
208
|
+
const pngFg = img.exportPng({
|
|
209
|
+
width: 160,
|
|
210
|
+
background: "#000000",
|
|
211
|
+
foreground: "#ff00ff",
|
|
212
|
+
});
|
|
213
|
+
if (!pngFg || pngFg[0] !== 0x89) {
|
|
214
|
+
console.error("exportPng foreground override failed");
|
|
215
|
+
process.exit(11);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const pngDpi = img.exportPng({
|
|
219
|
+
dpi: 100,
|
|
220
|
+
region: { x: 0, y: 0, width: 20, height: 12 },
|
|
221
|
+
padding: 4,
|
|
222
|
+
background: "#000000",
|
|
223
|
+
});
|
|
224
|
+
if (!pngDpi || pngDpi[0] !== 0x89) {
|
|
225
|
+
console.error("exportPng dpi/region failed");
|
|
226
|
+
process.exit(8);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
{
|
|
230
|
+
const doc = gerbv.createDocument({ unit: "mm", precision: 4 });
|
|
231
|
+
const bottom = doc.createLayer({ name: "bottom", color: "#2244aa", zIndex: 0 });
|
|
232
|
+
bottom.addRect(0, 0, 20, 12).endArea();
|
|
233
|
+
const top = doc.createLayer({ name: "top", color: "#eeaa00", zIndex: 10 });
|
|
234
|
+
top.setObjectColor("#ff3344");
|
|
235
|
+
top.addFlashCircle(10, 6, 4);
|
|
236
|
+
top.setObjectColor(null);
|
|
237
|
+
top.setNetColor("#33ff66");
|
|
238
|
+
top.addLine(2, 2, 18, 10, 0.4);
|
|
239
|
+
top.setNetColor(null);
|
|
240
|
+
|
|
241
|
+
const multi = doc.exportPng({
|
|
242
|
+
dpi: 120,
|
|
243
|
+
region: { minX: 0, minY: 0, maxX: 20, maxY: 12 },
|
|
244
|
+
padding: 8,
|
|
245
|
+
background: "#0a0a12",
|
|
246
|
+
});
|
|
247
|
+
if (!multi || multi[0] !== 0x89) {
|
|
248
|
+
console.error("multi-layer export failed");
|
|
249
|
+
process.exit(9);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// 显式 zIndex:先传高层再传低层,仍应按 zIndex 叠
|
|
253
|
+
const reordered = gerbv.exportPngLayers(
|
|
254
|
+
[
|
|
255
|
+
{ image: top, zIndex: 5 },
|
|
256
|
+
{ image: bottom, zIndex: 1 },
|
|
257
|
+
],
|
|
258
|
+
{ width: 240, padding: 8, background: "#111" }
|
|
259
|
+
);
|
|
260
|
+
if (!reordered || reordered[0] !== 0x89) {
|
|
261
|
+
console.error("exportPngLayers zIndex failed");
|
|
262
|
+
process.exit(10);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
53
266
|
try {
|
|
54
267
|
img.createPolygon();
|
|
55
268
|
console.error("createPolygon without point should throw");
|