feat(转换能力): 新增PDF解析、可编辑OFD转换及WebUI打开能力
build.yaml / build (push) Successful in 39s

This commit is contained in:
xiaoqidun committed 2026-09-24 16:18:38 +08:00
1 parent 697a059162
commit 86330dddd7
8 files changed
+606 -12

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@
<body>
<div class="app">
<header class="toolbar app-bar">
<input id="ofdInput" class="file-input" type="file" accept=".ofd">
<input id="ofdInput" class="file-input" type="file" accept=".ofd,.pdf">
<input id="fontInput" class="file-input" type="file" accept=".ttf,.otf,.ttc,font/*" multiple>
<input id="fontDirectoryInput" class="file-input" type="file" webkitdirectory multiple>
<div class="tool-group">
+15 -7
View File
@@ -2916,7 +2916,7 @@ async function openOFDFromDrop(event) {
return;
}
const file = event.dataTransfer.files[0];
if (file && isOFDFile(file)) {
if (file && isDocumentFile(file)) {
await requestLocalFontsBeforeOpen();
}
await openOFD(file);
@@ -3317,7 +3317,7 @@ async function openOFD(file) {
if (!file) {
return;
}
if (!isOFDFile(file)) {
if (!isDocumentFile(file)) {
el.ofdInput.value = "";
showError(new Error("选择 OFD 文件"), !state.doc);
return;
@@ -3330,12 +3330,20 @@ async function openOFD(file) {
const openSeq = ++state.openSeq;
setBusy(true, "正在读取文档", 10, STATUS.opening);
try {
const bytes = new Uint8Array(await file.arrayBuffer());
let bytes = new Uint8Array(await file.arrayBuffer());
if (openSeq !== state.openSeq) {
return;
}
if (/\.pdf$/i.test(file.name || "")) {
setProgress("正在转换 PDF", 25);
await ensureWASM();
if (openSeq !== state.openSeq) return;
const converted = await callWASM("ofdgoConvertPDF", bytes);
if (openSeq !== state.openSeq) return;
bytes = converted.bytes;
}
state.ofdBytes = bytes;
state.fileName = file.name || "ofdgo.ofd";
state.fileName = (file.name || "ofdgo.ofd").replace(/\.pdf$/i, ".ofd");
state.editing = false;
state.composite = null;
state.annotationCreate = null;
@@ -3368,14 +3376,14 @@ async function openOFD(file) {
await openDocument({ pageIndex: 0, resetScroll: true, openSeq });
} catch (err) {
if (openSeq === state.openSeq) {
showError(err, true);
showError(err, !state.doc);
setBusy(false);
}
}
}
function isOFDFile(file) {
return /\.ofd$/i.test(file.name || "");
function isDocumentFile(file) {
return /\.(ofd|pdf)$/i.test(file.name || "");
}
async function openSelectedFonts(event) {
+2 -1
View File
@@ -11,7 +11,8 @@
{
"action": "./",
"accept": {
"application/ofd": [".ofd"]
"application/ofd": [".ofd"],
"application/pdf": [".pdf"]
},
"launch_type": "multiple-clients"
}