@hufe921/jsofd 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hufe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # jsofd
2
+
3
+ Generate OFD fixed-layout documents (Chinese national standard **GB/T 33190-2016**) in JavaScript / TypeScript — with a **jsPDF-compatible API**.
4
+
5
+ [![CI](https://github.com/Hufe921/jsOFD/actions/workflows/ci.yml/badge.svg)](https://github.com/Hufe921/jsOFD/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Hufe921/jsOFD/blob/main/LICENSE)
7
+
8
+ ```ts
9
+ import { jsOFD } from '@hufe921/jsofd';
10
+
11
+ const doc = new jsOFD({ unit: 'mm', format: 'a4' });
12
+ doc.setFont('simhei');
13
+ doc.setFontSize(16);
14
+ doc.text('会议纪要', 105, 40, { align: 'center' });
15
+ doc.setFont('simsun');
16
+ doc.text('jsOFD 把 jsPDF 的编程模型移植到国产版式标准上。', 25, 60, { maxWidth: 160 });
17
+ doc.save('meeting.ofd');
18
+ ```
19
+
20
+ ## 特性
21
+
22
+ - **jsPDF 兼容 API** — `text` / `rect` / `addImage` / `addPage` / `output` / `save` 等方法名、参数、选项一一对应,已有代码改一个 import 即可迁移
23
+ - **完整文本排版** — 对齐(含两端对齐)、自动断行(中英混排)、字距、行距、基线锚点、旋转、渲染模式
24
+ - **矢量图形与图像** — 线条 / 矩形 / 圆 / 椭圆 / 贝塞尔,PNG / JPEG 原样嵌入不转码,自动去重
25
+ - **中文字体嵌入** — `addFontTtf()` 解析 TTF/TTC(cmap / hmtx / OS-2)并按 GB/T 33190 要求嵌入 TrueType 文件,任何阅读器中渲染一致
26
+ - **PDF → OFD 转换** — `jsofd/pdf` 子路径,基于 pdfjs 算子重放(v4 / v6 均适配)
27
+ - **高级排版** — `autoPaging` 自动分页、`headerFooter` 页眉页脚、`table` 表格引擎(自动分页重复表头)、`context2d` Canvas 适配器、`html` 语义渲染、`addAnnotation` 批注
28
+ - **零依赖核心** — ZIP / PNG 编码 / 字体解析全部自研;pdfjs 仅在转换时作为可选 peer 依赖引入
29
+ - **交互与元数据** — 超链接、书签大纲、附件、文档属性、阅读器初始视图
30
+
31
+ ## 安装
32
+
33
+ ```sh
34
+ npm install @hufe921/jsofd
35
+ ```
36
+
37
+ PDF → OFD 转换需要同时安装可选 peer 依赖:
38
+
39
+ ```sh
40
+ npm install @hufe921/jsofd pdfjs-dist
41
+ ```
42
+
43
+ ## 输出
44
+
45
+ ```ts
46
+ doc.save('file.ofd'); // 浏览器:触发下载
47
+ doc.output('arraybuffer'); // 任何环境:返回字节(还有 uint8array / bloburl / dataurlstring …)
48
+ ```
49
+
50
+ Node.js(ESM 下 `save()` 仅浏览器可用,写盘请用 `output()`):
51
+
52
+ ```js
53
+ import { writeFileSync } from 'node:fs';
54
+ writeFileSync('file.ofd', Buffer.from(doc.output('arraybuffer')));
55
+ ```
56
+
57
+ ## 文档
58
+
59
+ 完整文档(中文):[指南与 API 参考](https://github.com/Hufe921/jsOFD#readme)。
60
+
61
+ ## 许可
62
+
63
+ [MIT](./LICENSE)