@huaqiu/js-gerbv 0.1.15 → 0.1.26
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/CMakeLists.txt
CHANGED
|
@@ -20,10 +20,23 @@ endif()
|
|
|
20
20
|
|
|
21
21
|
set(NODE_ADDON_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
22
22
|
|
|
23
|
-
# glib-2.0:Unix 用 pkg-config;Windows 优先 vcpkg / CMAKE_PREFIX_PATH
|
|
23
|
+
# glib-2.0 / cairo:Unix 用 pkg-config;Windows 优先 vcpkg / CMAKE_PREFIX_PATH
|
|
24
24
|
find_package(PkgConfig)
|
|
25
25
|
if(PkgConfig_FOUND)
|
|
26
26
|
pkg_check_modules(GLIB IMPORTED_TARGET glib-2.0)
|
|
27
|
+
pkg_check_modules(CAIRO IMPORTED_TARGET cairo)
|
|
28
|
+
endif()
|
|
29
|
+
if(NOT TARGET PkgConfig::CAIRO)
|
|
30
|
+
find_path(CAIRO_INCLUDE_DIR cairo.h PATH_SUFFIXES cairo)
|
|
31
|
+
find_library(CAIRO_LIBRARY NAMES cairo)
|
|
32
|
+
if(NOT CAIRO_INCLUDE_DIR OR NOT CAIRO_LIBRARY)
|
|
33
|
+
message(FATAL_ERROR
|
|
34
|
+
"cairo not found. Install via brew/apt (cairo), or vcpkg install cairo")
|
|
35
|
+
endif()
|
|
36
|
+
add_library(PkgConfig::CAIRO INTERFACE IMPORTED)
|
|
37
|
+
set_target_properties(PkgConfig::CAIRO PROPERTIES
|
|
38
|
+
INTERFACE_INCLUDE_DIRECTORIES "${CAIRO_INCLUDE_DIR}"
|
|
39
|
+
INTERFACE_LINK_LIBRARIES "${CAIRO_LIBRARY}")
|
|
27
40
|
endif()
|
|
28
41
|
if(NOT TARGET PkgConfig::GLIB)
|
|
29
42
|
find_package(unofficial-glib CONFIG QUIET)
|
|
@@ -102,7 +115,7 @@ else()
|
|
|
102
115
|
target_compile_options(gerbv_core PRIVATE -Wno-deprecated-declarations -Wno-unused-parameter)
|
|
103
116
|
endif()
|
|
104
117
|
|
|
105
|
-
add_library(gerbv_node SHARED src/addon.cc)
|
|
118
|
+
add_library(gerbv_node SHARED src/addon.cc src/export_png.cc)
|
|
106
119
|
set_target_properties(gerbv_node PROPERTIES
|
|
107
120
|
PREFIX ""
|
|
108
121
|
SUFFIX ".node"
|
|
@@ -128,7 +141,7 @@ target_include_directories(gerbv_node PRIVATE
|
|
|
128
141
|
${_NAPI_INC}
|
|
129
142
|
)
|
|
130
143
|
target_compile_definitions(gerbv_node PRIVATE NAPI_VERSION=8 HAVE_CONFIG_H RENDER_USING_GDK)
|
|
131
|
-
target_link_libraries(gerbv_node PRIVATE gerbv_core)
|
|
144
|
+
target_link_libraries(gerbv_node PRIVATE gerbv_core PkgConfig::CAIRO)
|
|
132
145
|
if(APPLE)
|
|
133
146
|
target_link_options(gerbv_node PRIVATE -undefined dynamic_lookup)
|
|
134
147
|
elseif(WIN32)
|
package/README.md
CHANGED
|
@@ -21,9 +21,9 @@ index.js # 按平台加载
|
|
|
21
21
|
|
|
22
22
|
| 平台 | 依赖 |
|
|
23
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
|
|
24
|
+
| macOS | `brew install glib cairo pkg-config cmake`;Node ≥ 20 |
|
|
25
|
+
| Linux | `libglib2.0-dev libcairo2-dev pkg-config cmake` |
|
|
26
|
+
| Windows | CMake + vcpkg `glib:x64-windows` / `cairo`(设 `VCPKG_ROOT`),或 MSYS2 mingw64(`glib2`/`cairo`/`pkgconf`/`gcc`) |
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
npm install
|
|
@@ -44,6 +44,7 @@ const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
|
44
44
|
const pl = img.createPolyline(0, 0, 0.25);
|
|
45
45
|
pl.addPolylineLine(12.7, 0);
|
|
46
46
|
pl.addPolylineArc(6.35, 0, 6.35, 6.35, false);
|
|
47
|
+
pl.addPolylineSpline([[8, 8], [10, 4], [12, 6]], { degree: 3 });
|
|
47
48
|
pl.endPolyline();
|
|
48
49
|
|
|
49
50
|
// 区域:起点在 createPolygon;add* 只给下一点
|
|
@@ -54,7 +55,7 @@ poly.addPolygonBezier2(6.35, 15, 0, 12.7);
|
|
|
54
55
|
|
|
55
56
|
const hole = poly.createHole(3, 3); // 起点在 createHole
|
|
56
57
|
hole.addPolygonArc(5, 5, 7, 3, false);
|
|
57
|
-
hole.
|
|
58
|
+
hole.addPolygonSpline([[5.5, 7], [4, 6], [3, 3]], { degree: 3 });
|
|
58
59
|
hole.endHole();
|
|
59
60
|
|
|
60
61
|
poly.addCircleHole(9, 6, 2);
|
|
@@ -63,21 +64,61 @@ poly.endArea();
|
|
|
63
64
|
img.addRect(15, 0, 10, 8).addCircleHole(20, 4, 2.5).endArea();
|
|
64
65
|
img.addCircle(30, 4, 6).endArea();
|
|
65
66
|
img.addCircleRing(40, 4, 8, 1.5);
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
img.addText(0, 12, "SILK", { height: 2, strokeWidth: 0.2 });
|
|
68
|
+
// 中文:fontFile:"system"(或省略)用系统默认 TTF/OTF;也可传具体路径
|
|
69
|
+
img.addText(0, 8, "中文", { height: 2, fontFile: "system" });
|
|
70
|
+
// createPolygon + createHole:H/V cut-in 单轮廓挖空(兼容忽略 LPC 的在线查看器)
|
|
71
|
+
|
|
72
|
+
img.setLayerColor("#c9a227");
|
|
73
|
+
img.setObjectColor("#ff4d4f"); // 对象色
|
|
74
|
+
img.setNetColor("#40c463"); // 网络色(最高优先)
|
|
75
|
+
// 绘制后可 setObjectColor(null) / setNetColor(null) 清除
|
|
76
|
+
|
|
77
|
+
const gbr = img.exportRs274x();
|
|
78
|
+
const png = img.exportPng({
|
|
79
|
+
dpi: 150,
|
|
80
|
+
region: { x: 0, y: 0, width: 50, height: 30 },
|
|
81
|
+
background: "#1a1a2e",
|
|
82
|
+
padding: 24,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// 多层(zIndex 升序叠加,小的在下)
|
|
86
|
+
const doc = createDocument({ unit: "mm", precision: 6 });
|
|
87
|
+
const mask = doc.createLayer({ name: "F.Mask", color: "#1b4332", zIndex: 0 });
|
|
88
|
+
const copper = doc.createLayer({ name: "F.Cu", color: "#d4b21a", zIndex: 5 });
|
|
89
|
+
const multi = doc.exportPng({ dpi: 150, region: { minX: 0, minY: 0, maxX: 50, maxY: 30 } });
|
|
68
90
|
```
|
|
69
91
|
|
|
70
92
|
输入单位由 `createImage({ unit })` 指定(`inch` 默认 / `mm`);内部与导出仍为 inch(`%MOIN*%`)。`precision` 为换算到 inch 后保留的小数位。
|
|
71
93
|
|
|
94
|
+
颜色优先级(绘制时写入每个图元):**网络色 > 对象色 > 层色**。
|
|
95
|
+
|
|
72
96
|
`createPolygon` / `createHole` / `createPolyline` 均带**起点**;后续 `add*` 只传下一点/终点。
|
|
73
97
|
|
|
98
|
+
示例:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
node examples/example.js # 或 python3 examples/example.py
|
|
102
|
+
# → examples/out/
|
|
103
|
+
# demo / shapes / holes / strokes / text / multi / drill (.gbr|.png|.exc)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
hqpcb-lite 工程另见 `PCB_V5/lite/samples/demo_gerbv_png.py`。
|
|
107
|
+
|
|
74
108
|
| API | 说明 |
|
|
75
109
|
|-----|------|
|
|
76
110
|
| `createImage({ unit?, precision? })` | 返回方法式 image;换算在 native 侧 |
|
|
111
|
+
| `createDocument({ unit?, precision? })` | 多图层文档 |
|
|
112
|
+
| `doc.createLayer({ name?, color?, zIndex? })` | 新建层(默认 zIndex=创建序) |
|
|
113
|
+
| `img.setLayerColor` / `setColor` | 层默认色 |
|
|
114
|
+
| `img.setObjectColor(c\|null)` | 对象色 |
|
|
115
|
+
| `img.setNetColor(c\|null)` | 网络色(最高优先) |
|
|
116
|
+
| `img.addText(x,y,text,opts?)` | 矢量文字;ASCII 默认 Hershey;`fontFile:"system"`/路径或非 ASCII 自动系统字体;`height`/`angle`/`\\n` |
|
|
77
117
|
| `img.createPolyline(x,y,w)` | 多段线起点 + 线宽 |
|
|
78
118
|
| `pl.addPolylineLine(x,y)` | 直线到点 |
|
|
79
119
|
| `pl.addPolylineArc(cx,cy,x,y,cw?)` | 圆弧到点 |
|
|
80
120
|
| `pl.addPolylineBezier2/3(...)` | 贝塞尔到点 |
|
|
121
|
+
| `pl.addPolylineSpline(points, opts?)` | B 样条到点;`points` 末点为终点;`degree`/`steps`/`knots` |
|
|
81
122
|
| `pl.endPolyline()` | 结束多段线 |
|
|
82
123
|
| `img.addLine` / `addArc` / `addBezier2/3` | 单段描边(完整起止) |
|
|
83
124
|
| `img.addFlashCircle(x,y,d)` | 光圈 flash |
|
|
@@ -86,10 +127,13 @@ const buf = img.exportRs274x();
|
|
|
86
127
|
| `img.createPolygon(x,y)` | region 起点 |
|
|
87
128
|
| `poly/hole.addPolygonLine(x,y)` | 直线到点 |
|
|
88
129
|
| `poly/hole.addPolygonArc` / `Bezier2/3` | 弧/贝塞尔到点 |
|
|
130
|
+
| `poly/hole.addPolygonSpline(points, opts?)` | B 样条边(同 polyline) |
|
|
89
131
|
| `poly.createHole(x,y)` / `hole.endHole()` | 任意轮廓孔 |
|
|
90
132
|
| `poly.addCircleHole(cx,cy,d)` | 整圆孔 |
|
|
91
133
|
| `poly.endArea()` | 写出外环 + 孔 |
|
|
92
134
|
| `img.exportRs274x()` / `exportDrill()` | 导出 Buffer |
|
|
135
|
+
| `img.exportPng({ dpi?, region?, width?, … })` | 单层 PNG;可裁区域 / 按 DPI |
|
|
136
|
+
| `doc.exportPng` / `exportPngLayers([{image,zIndex},…], opts)` | 多层 PNG;按 zIndex 升序叠加 |
|
|
93
137
|
|
|
94
138
|
安装(含已发布的 **darwin-arm64** prebuild,无需本机编):
|
|
95
139
|
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* js-gerbv 示例集:形状 / 挖孔 / 描边 / 文字 / 多层 / 钻孔。
|
|
4
|
+
*
|
|
5
|
+
* node examples/example.js [outDir]
|
|
6
|
+
*
|
|
7
|
+
* 输出(默认 examples/out/):
|
|
8
|
+
* demo.* 综合:折线 + 带孔多边形 + 圆环
|
|
9
|
+
* shapes.* 矩形/圆/环/flash/弧/贝塞尔
|
|
10
|
+
* holes.* 圆孔 / 样条孔 / 越界孔丢弃
|
|
11
|
+
* strokes.* 多段线:直线·弧·贝塞尔·样条
|
|
12
|
+
* text.* ASCII Hershey + 中文系统字体
|
|
13
|
+
* multi.png 阻焊 / 铜皮 / 丝印叠层
|
|
14
|
+
* drill.exc Excellon 钻孔
|
|
15
|
+
*/
|
|
16
|
+
"use strict";
|
|
17
|
+
|
|
18
|
+
const fs = require("fs");
|
|
19
|
+
const path = require("path");
|
|
20
|
+
const gerbv = require("../index.js");
|
|
21
|
+
|
|
22
|
+
const outDir = path.resolve(process.argv[2] || path.join(__dirname, "out"));
|
|
23
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
24
|
+
|
|
25
|
+
const BG = "#102a43";
|
|
26
|
+
/** PNG 分辨率:相对原先 150dpi 放大 10 倍 */
|
|
27
|
+
const DPI = 1500;
|
|
28
|
+
const wrote = [];
|
|
29
|
+
|
|
30
|
+
function save(name, buf) {
|
|
31
|
+
const p = path.join(outDir, name);
|
|
32
|
+
fs.writeFileSync(p, buf);
|
|
33
|
+
wrote.push(p);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function png(img, region, dpi = DPI) {
|
|
37
|
+
return img.exportPng({
|
|
38
|
+
dpi,
|
|
39
|
+
region,
|
|
40
|
+
padding: 200,
|
|
41
|
+
background: BG,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ── 1. 综合 demo ──────────────────────────────────────────────
|
|
46
|
+
{
|
|
47
|
+
const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
48
|
+
img.setLayerColor("#c9a227");
|
|
49
|
+
|
|
50
|
+
const pl = img.createPolyline(0, 0, 0.3);
|
|
51
|
+
pl.addPolylineLine(20, 0);
|
|
52
|
+
pl.addPolylineArc(10, 0, 10, 10, false);
|
|
53
|
+
pl.addPolylineSpline(
|
|
54
|
+
[
|
|
55
|
+
[14, 14],
|
|
56
|
+
[18, 8],
|
|
57
|
+
[22, 12],
|
|
58
|
+
],
|
|
59
|
+
{ degree: 3, steps: 24 }
|
|
60
|
+
);
|
|
61
|
+
pl.endPolyline();
|
|
62
|
+
|
|
63
|
+
img.setObjectColor("#ff4d4f");
|
|
64
|
+
const poly = img.createPolygon(0, 0);
|
|
65
|
+
poly.addPolygonLine(15, 0);
|
|
66
|
+
poly.addPolygonSpline(
|
|
67
|
+
[
|
|
68
|
+
[18, 4],
|
|
69
|
+
[15, 8],
|
|
70
|
+
[15, 12],
|
|
71
|
+
],
|
|
72
|
+
{ degree: 3 }
|
|
73
|
+
);
|
|
74
|
+
poly.addPolygonLine(0, 12);
|
|
75
|
+
const hole = poly.createHole(5, 4);
|
|
76
|
+
hole.addPolygonSpline(
|
|
77
|
+
[
|
|
78
|
+
[9, 3],
|
|
79
|
+
[10, 7],
|
|
80
|
+
[6, 9],
|
|
81
|
+
[5, 4],
|
|
82
|
+
],
|
|
83
|
+
{ degree: 3, steps: 32 }
|
|
84
|
+
);
|
|
85
|
+
hole.endHole();
|
|
86
|
+
poly.endArea();
|
|
87
|
+
img.setObjectColor(null);
|
|
88
|
+
|
|
89
|
+
img.setNetColor("#40c463");
|
|
90
|
+
img.addCircleRing(25, 6, 8, 1.2);
|
|
91
|
+
img.addFlashCircle(25, 6, 1.5);
|
|
92
|
+
img.setNetColor(null);
|
|
93
|
+
|
|
94
|
+
save("demo.gbr", img.exportRs274x());
|
|
95
|
+
save("demo.png", png(img, { x: -2, y: -2, width: 36, height: 18 }));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ── 2. 基础形状 ───────────────────────────────────────────────
|
|
99
|
+
{
|
|
100
|
+
const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
101
|
+
img.setLayerColor("#d4b21a");
|
|
102
|
+
|
|
103
|
+
img.addRect(0, 0, 8, 5).endArea();
|
|
104
|
+
img.addCircle(14, 2.5, 5).endArea();
|
|
105
|
+
img.addCircleRing(22, 2.5, 6, 1.0);
|
|
106
|
+
img.addFlashCircle(22, 2.5, 1.2);
|
|
107
|
+
|
|
108
|
+
img.setObjectColor("#5b8def");
|
|
109
|
+
img.addLine(0, 8, 10, 8, 0.4);
|
|
110
|
+
img.addArc(16, 8, 13, 8, 19, 8, 0.35, false);
|
|
111
|
+
img.addBezier2(0, 11, 5, 14, 10, 11, 0.3);
|
|
112
|
+
img.addBezier3(12, 11, 14, 15, 18, 7, 22, 11, 0.3);
|
|
113
|
+
img.setObjectColor(null);
|
|
114
|
+
|
|
115
|
+
save("shapes.gbr", img.exportRs274x());
|
|
116
|
+
save("shapes.png", png(img, { x: -1, y: -1, width: 28, height: 16 }));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── 3. 挖孔(H/V cut-in;越界孔丢弃)───────────────────────
|
|
120
|
+
{
|
|
121
|
+
const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
122
|
+
img.setLayerColor("#e67700");
|
|
123
|
+
|
|
124
|
+
// 矩形 + 圆孔
|
|
125
|
+
img.addRect(0, 0, 12, 10).addCircleHole(4, 5, 3).endArea();
|
|
126
|
+
|
|
127
|
+
// 圆盘 + 样条孔
|
|
128
|
+
const disk = img.addCircle(20, 5, 9);
|
|
129
|
+
const h = disk.createHole(18, 4);
|
|
130
|
+
h.addPolygonSpline(
|
|
131
|
+
[
|
|
132
|
+
[21, 3],
|
|
133
|
+
[22, 6],
|
|
134
|
+
[19, 7.5],
|
|
135
|
+
[18, 4],
|
|
136
|
+
],
|
|
137
|
+
{ degree: 3, steps: 28 }
|
|
138
|
+
);
|
|
139
|
+
h.endHole();
|
|
140
|
+
disk.endArea();
|
|
141
|
+
|
|
142
|
+
// 越界孔应被 sanitize 丢弃,不掏空邻块
|
|
143
|
+
const a = img.createPolygon(28, 0);
|
|
144
|
+
a.addPolygonLine(38, 0).addPolygonLine(38, 10).addPolygonLine(28, 10);
|
|
145
|
+
const bad = a.createHole(40, 2);
|
|
146
|
+
bad.addPolygonLine(46, 2).addPolygonLine(46, 8).addPolygonLine(40, 8).endHole();
|
|
147
|
+
a.endArea();
|
|
148
|
+
img.addRect(39, 1, 8, 8).endArea();
|
|
149
|
+
|
|
150
|
+
save("holes.gbr", img.exportRs274x());
|
|
151
|
+
save("holes.png", png(img, { x: -1, y: -1, width: 50, height: 12 }));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── 4. 描边路径 ───────────────────────────────────────────────
|
|
155
|
+
{
|
|
156
|
+
const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
157
|
+
img.setLayerColor("#69db7c");
|
|
158
|
+
|
|
159
|
+
const a = img.createPolyline(0, 2, 0.35);
|
|
160
|
+
a.addPolylineLine(8, 2).endPolyline();
|
|
161
|
+
|
|
162
|
+
const b = img.createPolyline(10, 0, 0.35);
|
|
163
|
+
b.addPolylineArc(14, 0, 14, 4, false).addPolylineLine(18, 4).endPolyline();
|
|
164
|
+
|
|
165
|
+
const c = img.createPolyline(0, 8, 0.3);
|
|
166
|
+
c.addPolylineBezier2(4, 12, 8, 8)
|
|
167
|
+
.addPolylineBezier3(10, 4, 14, 12, 18, 8)
|
|
168
|
+
.endPolyline();
|
|
169
|
+
|
|
170
|
+
const d = img.createPolyline(20, 1, 0.3);
|
|
171
|
+
d.addPolylineSpline(
|
|
172
|
+
[
|
|
173
|
+
[24, 6],
|
|
174
|
+
[28, 0],
|
|
175
|
+
[32, 5],
|
|
176
|
+
[36, 2],
|
|
177
|
+
],
|
|
178
|
+
{ degree: 3, steps: 32 }
|
|
179
|
+
);
|
|
180
|
+
d.endPolyline();
|
|
181
|
+
|
|
182
|
+
save("strokes.gbr", img.exportRs274x());
|
|
183
|
+
save("strokes.png", png(img, { x: -1, y: -1, width: 40, height: 14 }));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ── 5. 文字 ───────────────────────────────────────────────────
|
|
187
|
+
{
|
|
188
|
+
const img = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
189
|
+
img.setLayerColor("#f8f9fa");
|
|
190
|
+
|
|
191
|
+
img.addText(1, 10, "HQPCB", { height: 3, strokeWidth: 0.28 });
|
|
192
|
+
img.addText(1, 6, "R1 C2\nU3", {
|
|
193
|
+
height: 1.6,
|
|
194
|
+
strokeWidth: 0.15,
|
|
195
|
+
lineGap: 1.3,
|
|
196
|
+
});
|
|
197
|
+
img.addText(18, 9, "angled", {
|
|
198
|
+
height: 2,
|
|
199
|
+
strokeWidth: 0.2,
|
|
200
|
+
angle: 25,
|
|
201
|
+
});
|
|
202
|
+
img.addText(1, 2, "中文丝印", { height: 2.4, fontFile: "system" });
|
|
203
|
+
img.addText(20, 2.5, "居中", {
|
|
204
|
+
height: 1.8,
|
|
205
|
+
fontFile: "system",
|
|
206
|
+
align: "center",
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
save("text.gbr", img.exportRs274x());
|
|
210
|
+
save("text.png", png(img, { x: -1, y: -1, width: 32, height: 14 }));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ── 6. 多层叠图 ───────────────────────────────────────────────
|
|
214
|
+
{
|
|
215
|
+
const doc = gerbv.createDocument({ unit: "mm", precision: 6 });
|
|
216
|
+
const mask = doc.createLayer({ name: "mask", color: "#1b4332", zIndex: 0 });
|
|
217
|
+
mask.addRect(-1, -1, 28, 16).endArea();
|
|
218
|
+
|
|
219
|
+
const copper = doc.createLayer({ name: "copper", color: "#d4b21a", zIndex: 5 });
|
|
220
|
+
copper.addRect(0, 0, 26, 14).endArea();
|
|
221
|
+
copper.addCircleRing(8, 7, 5, 0.8);
|
|
222
|
+
copper.addFlashCircle(8, 7, 1.2);
|
|
223
|
+
copper.addRect(14, 3, 10, 8).addCircleHole(19, 7, 3).endArea();
|
|
224
|
+
|
|
225
|
+
const silk = doc.createLayer({ name: "silk", color: "#f5f5f5", zIndex: 10 });
|
|
226
|
+
silk.addLine(2, 2, 24, 2, 0.3);
|
|
227
|
+
silk.addText(2, 10, "HQPCB", { height: 2.5, strokeWidth: 0.25 });
|
|
228
|
+
silk.addText(19, 5, "PAD", { height: 1.2, strokeWidth: 0.12, align: "center" });
|
|
229
|
+
silk.addText(2, 12.5, "中文", { height: 1.8, fontFile: "system" });
|
|
230
|
+
|
|
231
|
+
save(
|
|
232
|
+
"multi.png",
|
|
233
|
+
doc.exportPng({
|
|
234
|
+
dpi: DPI,
|
|
235
|
+
region: { minX: -2, minY: -2, maxX: 28, maxY: 16 },
|
|
236
|
+
padding: 160,
|
|
237
|
+
background: "#0b132b",
|
|
238
|
+
})
|
|
239
|
+
);
|
|
240
|
+
save("multi-copper.gbr", copper.exportRs274x());
|
|
241
|
+
save("multi-silk.gbr", silk.exportRs274x());
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ── 7. 钻孔 ───────────────────────────────────────────────────
|
|
245
|
+
{
|
|
246
|
+
const drill = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
247
|
+
const holes = [
|
|
248
|
+
[2, 2, 0.8],
|
|
249
|
+
[6, 2, 0.8],
|
|
250
|
+
[10, 2, 1.0],
|
|
251
|
+
[4, 6, 1.2],
|
|
252
|
+
[8, 6, 0.6],
|
|
253
|
+
];
|
|
254
|
+
for (const [x, y, d] of holes) drill.addFlashCircle(x, y, d);
|
|
255
|
+
save("drill.exc", drill.exportDrill());
|
|
256
|
+
|
|
257
|
+
// 可视化:同坐标画 flash
|
|
258
|
+
const vis = gerbv.createImage({ unit: "mm", precision: 6 });
|
|
259
|
+
vis.setLayerColor("#adb5bd");
|
|
260
|
+
for (const [x, y, d] of holes) vis.addFlashCircle(x, y, d);
|
|
261
|
+
save("drill.png", png(vis, { x: 0, y: 0, width: 12, height: 9 }));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
for (const p of wrote) console.log("wrote", p);
|
|
265
|
+
console.log("backend=", gerbv.backend);
|
|
266
|
+
console.log("total", wrote.length, "files →", outDir);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""调用 examples/example.js,生成全部示例输出。
|
|
3
|
+
|
|
4
|
+
用法:
|
|
5
|
+
python3 examples/example.py [outDir]
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import shutil
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main() -> int:
|
|
19
|
+
node = shutil.which("node")
|
|
20
|
+
if not node:
|
|
21
|
+
print("error: node not found", file=sys.stderr)
|
|
22
|
+
return 1
|
|
23
|
+
script = ROOT / "examples" / "example.js"
|
|
24
|
+
out = Path(sys.argv[1]).resolve() if len(sys.argv) > 1 else ROOT / "examples" / "out"
|
|
25
|
+
r = subprocess.run([node, str(script), str(out)], cwd=str(ROOT))
|
|
26
|
+
return r.returncode
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if __name__ == "__main__":
|
|
30
|
+
raise SystemExit(main())
|