mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-08-30 12:12:40 +08:00
+33
-15
@@ -376,6 +376,27 @@ async function queryLocalFonts() {
|
|||||||
return available;
|
return available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function autoLoadDocumentLocalFonts(openSeq) {
|
||||||
|
if (!externalDocumentFontNames().length || !canReadLocalFonts()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
setProgress("正在匹配字体", 62, STATUS.fonts);
|
||||||
|
try {
|
||||||
|
const available = state.systemFontCatalog.length ? state.systemFontCatalog : await queryLocalFonts();
|
||||||
|
if (openSeq !== state.openSeq) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return await loadDocumentLocalFonts(available, openSeq);
|
||||||
|
} catch (err) {
|
||||||
|
if (err && err.name === "NotAllowedError") {
|
||||||
|
setStatus("未授权读取系统字体");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
setStatus(String(err.message || err));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadDocumentLocalFonts(available, openSeq = state.openSeq) {
|
async function loadDocumentLocalFonts(available, openSeq = state.openSeq) {
|
||||||
const docFonts = state.doc?.fonts || [];
|
const docFonts = state.doc?.fonts || [];
|
||||||
const docNames = externalDocumentFontNames();
|
const docNames = externalDocumentFontNames();
|
||||||
@@ -729,8 +750,8 @@ async function openDocument(options = {}) {
|
|||||||
await ensureWASM();
|
await ensureWASM();
|
||||||
}
|
}
|
||||||
const openSeq = options.openSeq || (state.openSeq += 1);
|
const openSeq = options.openSeq || (state.openSeq += 1);
|
||||||
const autoFonts = !options.skipAutoFonts && state.systemFontCatalog.length > 0;
|
const resetLocalFonts = !options.skipAutoFonts;
|
||||||
if (autoFonts) {
|
if (resetLocalFonts) {
|
||||||
state.localFonts = [];
|
state.localFonts = [];
|
||||||
updateFontSummary();
|
updateFontSummary();
|
||||||
renderFontList();
|
renderFontList();
|
||||||
@@ -742,7 +763,7 @@ async function openDocument(options = {}) {
|
|||||||
if (openSeq !== state.openSeq) {
|
if (openSeq !== state.openSeq) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const doc = callWASM("ofdgoOpen", state.ofdBytes, autoFonts ? uploadedFonts() : allFonts());
|
const doc = callWASM("ofdgoOpen", state.ofdBytes, resetLocalFonts ? uploadedFonts() : allFonts());
|
||||||
if (openSeq !== state.openSeq) {
|
if (openSeq !== state.openSeq) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -752,20 +773,17 @@ async function openDocument(options = {}) {
|
|||||||
state.pageIndex = pageIndex;
|
state.pageIndex = pageIndex;
|
||||||
state.scale = 1;
|
state.scale = 1;
|
||||||
state.fitMode = options.fitMode || "width";
|
state.fitMode = options.fitMode || "width";
|
||||||
if (!options.skipAutoFonts && state.systemFontCatalog.length > 0) {
|
if (!options.skipAutoFonts && await autoLoadDocumentLocalFonts(openSeq)) {
|
||||||
setProgress("正在匹配字体", 62, STATUS.fonts);
|
if (openSeq !== state.openSeq) {
|
||||||
if (await loadDocumentLocalFonts(state.systemFontCatalog, openSeq)) {
|
|
||||||
if (openSeq !== state.openSeq) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await openDocument({
|
|
||||||
pageIndex,
|
|
||||||
fitMode: state.fitMode,
|
|
||||||
skipAutoFonts: true,
|
|
||||||
openSeq,
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await openDocument({
|
||||||
|
pageIndex,
|
||||||
|
fitMode: state.fitMode,
|
||||||
|
skipAutoFonts: true,
|
||||||
|
openSeq,
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (openSeq !== state.openSeq) {
|
if (openSeq !== state.openSeq) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user