@yudaocode/univer-pdfs 1.6.214 → 1.6.215
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/PDF_BROWSER_RENDERING_CONTRACT.md +16 -12
- package/lib/cjs/index.js +316 -72
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/jsx/index.js +262 -71
- package/lib/cjs/jsx/index.js.map +1 -1
- package/lib/es/{chunk-4A226M74.js → chunk-DYTQBEM7.js} +312 -73
- package/lib/es/chunk-DYTQBEM7.js.map +1 -0
- package/lib/es/index.js +11 -1
- package/lib/es/index.js.map +1 -1
- package/lib/es/jsx/index.js +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/jsx/index.d.ts +2 -2
- package/lib/types/jsx/jsx-dev-runtime.d.ts +1 -1
- package/lib/types/jsx/jsx-runtime.d.ts +1 -1
- package/lib/types/{jsx-dev-runtime-Ch1WuW58.d.ts → jsx-dev-runtime-BFeiWVJj.d.ts} +51 -3
- package/package.json +1 -1
- package/lib/es/chunk-4A226M74.js.map +0 -1
|
@@ -6626,6 +6626,64 @@ var PdfRenderError = class extends Error {
|
|
|
6626
6626
|
if (extra?.missingGlyphs) this.missingGlyphs = extra.missingGlyphs;
|
|
6627
6627
|
}
|
|
6628
6628
|
};
|
|
6629
|
+
var DEFAULT_PDF_CJK_FONT_PACKAGE = "@yudaocode/univer-pdf-fonts";
|
|
6630
|
+
var DEFAULT_PDF_CJK_FONT_VERSION = "1.0.0";
|
|
6631
|
+
var DEFAULT_PDF_CJK_FONT_FAMILY = "Noto Sans SC";
|
|
6632
|
+
var DEFAULT_PDF_CJK_FONT_FILES = Object.freeze({
|
|
6633
|
+
normal: Object.freeze({
|
|
6634
|
+
file: "NotoSansSC-Regular.ttf",
|
|
6635
|
+
family: DEFAULT_PDF_CJK_FONT_FAMILY,
|
|
6636
|
+
weight: "normal",
|
|
6637
|
+
integrity: "sha384-WYgE+CQjxrXCFCynsUOYE86llni41IspZsiH2huo8yxlgR2GKNE5fzeurmHXRfIe"
|
|
6638
|
+
}),
|
|
6639
|
+
bold: Object.freeze({
|
|
6640
|
+
file: "NotoSansSC-Bold.ttf",
|
|
6641
|
+
family: DEFAULT_PDF_CJK_FONT_FAMILY,
|
|
6642
|
+
weight: "bold",
|
|
6643
|
+
integrity: "sha384-jI+dGvcJGGgO8RayO+x2LHDI85inVoe36tfbBKtSD6SQ0A8VKi5s+0lG+of4qB6j"
|
|
6644
|
+
})
|
|
6645
|
+
});
|
|
6646
|
+
function createPdfCjkFontSources(options) {
|
|
6647
|
+
const ver = (options?.version ?? DEFAULT_PDF_CJK_FONT_VERSION).trim() || DEFAULT_PDF_CJK_FONT_VERSION;
|
|
6648
|
+
const family = options?.family ?? DEFAULT_PDF_CJK_FONT_FAMILY;
|
|
6649
|
+
const rawBase = (options?.baseUrl ?? `https://cdn.jsdmirror.com/npm/${DEFAULT_PDF_CJK_FONT_PACKAGE}@${ver}/fonts`).replace(/\{version\}/g, ver);
|
|
6650
|
+
const cleanBase = rawBase.replace(/\/+$/, "");
|
|
6651
|
+
let requestedWeights;
|
|
6652
|
+
if (options?.weights === "both") {
|
|
6653
|
+
requestedWeights = ["normal", "bold"];
|
|
6654
|
+
} else if (options?.weights === "normal" || options?.weights === "bold") {
|
|
6655
|
+
requestedWeights = [options.weights];
|
|
6656
|
+
} else if (Array.isArray(options?.weights) && options.weights.length > 0) {
|
|
6657
|
+
requestedWeights = [];
|
|
6658
|
+
for (const w of options.weights) {
|
|
6659
|
+
if ((w === "normal" || w === "bold") && !requestedWeights.includes(w)) {
|
|
6660
|
+
requestedWeights.push(w);
|
|
6661
|
+
}
|
|
6662
|
+
}
|
|
6663
|
+
if (requestedWeights.length === 0) {
|
|
6664
|
+
requestedWeights = ["normal"];
|
|
6665
|
+
}
|
|
6666
|
+
} else {
|
|
6667
|
+
requestedWeights = ["normal"];
|
|
6668
|
+
}
|
|
6669
|
+
return requestedWeights.map((weight) => {
|
|
6670
|
+
const preset = DEFAULT_PDF_CJK_FONT_FILES[weight];
|
|
6671
|
+
let integrity;
|
|
6672
|
+
if (options?.integrity && typeof options.integrity === "object") {
|
|
6673
|
+
integrity = options.integrity[weight];
|
|
6674
|
+
} else if (options?.integrity === false) {
|
|
6675
|
+
integrity = void 0;
|
|
6676
|
+
} else if (options?.integrity === true || options?.integrity === void 0 && ver === DEFAULT_PDF_CJK_FONT_VERSION) {
|
|
6677
|
+
integrity = preset.integrity;
|
|
6678
|
+
}
|
|
6679
|
+
return {
|
|
6680
|
+
url: `${cleanBase}/${preset.file}`,
|
|
6681
|
+
family,
|
|
6682
|
+
weight,
|
|
6683
|
+
...integrity ? { integrity } : {}
|
|
6684
|
+
};
|
|
6685
|
+
});
|
|
6686
|
+
}
|
|
6629
6687
|
var pdfFontUrlByteCache = /* @__PURE__ */ new Map();
|
|
6630
6688
|
function clearPdfFontUrlCache() {
|
|
6631
6689
|
pdfFontUrlByteCache.clear();
|
|
@@ -6961,39 +7019,147 @@ function registerSubsetType0FontInDoc(pdfDoc, fontBytes, usedCodePoints, fontTag
|
|
|
6961
7019
|
);
|
|
6962
7020
|
return { type0FontRef, subset };
|
|
6963
7021
|
}
|
|
6964
|
-
|
|
7022
|
+
function buildCidUtf16ToUnicodeCmapString(usedCodePoints) {
|
|
7023
|
+
const bmpHexList = [];
|
|
7024
|
+
const suppHexList = [];
|
|
7025
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7026
|
+
for (const cp of usedCodePoints) {
|
|
7027
|
+
if (!Number.isInteger(cp) || cp <= 0 || cp === 65279 || seen.has(cp)) continue;
|
|
7028
|
+
seen.add(cp);
|
|
7029
|
+
const hex = toUtf16BeHex(String.fromCodePoint(cp), false);
|
|
7030
|
+
if (cp <= 65535) {
|
|
7031
|
+
bmpHexList.push(hex);
|
|
7032
|
+
} else {
|
|
7033
|
+
suppHexList.push(hex);
|
|
7034
|
+
}
|
|
7035
|
+
}
|
|
7036
|
+
bmpHexList.sort();
|
|
7037
|
+
suppHexList.sort();
|
|
7038
|
+
const bfBlocks = [];
|
|
7039
|
+
for (const list of [bmpHexList, suppHexList]) {
|
|
7040
|
+
for (let i = 0; i < list.length; i += 100) {
|
|
7041
|
+
const chunk = list.slice(i, i + 100);
|
|
7042
|
+
const lines = chunk.map((h) => `<${h}> <${h}>`).join("\n");
|
|
7043
|
+
bfBlocks.push(`${chunk.length} beginbfchar
|
|
7044
|
+
${lines}
|
|
7045
|
+
endbfchar`);
|
|
7046
|
+
}
|
|
7047
|
+
}
|
|
7048
|
+
const codespaceLines = suppHexList.length > 0 ? ["2 begincodespacerange", "<0000> <FFFF>", "<D800DC00> <DBFFDFFF>", "endcodespacerange"] : ["1 begincodespacerange", "<0000> <FFFF>", "endcodespacerange"];
|
|
7049
|
+
return [
|
|
7050
|
+
"/CIDInit /ProcSet findresource begin",
|
|
7051
|
+
"12 dict begin",
|
|
7052
|
+
"begincmap",
|
|
7053
|
+
"/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def",
|
|
7054
|
+
"/CMapName /Adobe-Identity-UCS def",
|
|
7055
|
+
"/CMapType 2 def",
|
|
7056
|
+
...codespaceLines,
|
|
7057
|
+
...bfBlocks,
|
|
7058
|
+
"endcmap",
|
|
7059
|
+
"CMapName currentdict /CMap defineresource pop",
|
|
7060
|
+
"end",
|
|
7061
|
+
"end"
|
|
7062
|
+
].join("\n");
|
|
7063
|
+
}
|
|
7064
|
+
function detectUsedPdfTextWeights(snapshot, effectiveData) {
|
|
7065
|
+
let usesNormal = false;
|
|
7066
|
+
let usesBold = false;
|
|
7067
|
+
if (snapshot.metadata?.watermarkText && snapshot.metadata?.watermarkConfig?.enabled !== false) {
|
|
7068
|
+
usesNormal = true;
|
|
7069
|
+
}
|
|
7070
|
+
if (snapshot.metadata?.batesConfig?.enabled) {
|
|
7071
|
+
usesNormal = true;
|
|
7072
|
+
}
|
|
7073
|
+
const totalPages = snapshot.document.pageOrder.length;
|
|
7074
|
+
const startPageOffset = Math.max(1, Number(snapshot.metadata?.startPageNumber ?? 1) || 1);
|
|
7075
|
+
snapshot.document.pageOrder.forEach((pageId, pIdx) => {
|
|
7076
|
+
const pageCtx = { pageNumber: startPageOffset + pIdx, totalPages: startPageOffset + totalPages - 1 };
|
|
7077
|
+
const map = snapshot.editState.elementsByPage[pageId] ?? {};
|
|
7078
|
+
const order = snapshot.editState.elementOrderByPage[pageId] ?? Object.keys(map);
|
|
7079
|
+
for (const id of order) {
|
|
7080
|
+
const el = map[id];
|
|
7081
|
+
if (!el || el.hidden) continue;
|
|
7082
|
+
if (el.type === "text" /* TEXT */) {
|
|
7083
|
+
if (el.richSpans?.length) {
|
|
7084
|
+
for (const span of el.richSpans) {
|
|
7085
|
+
const t = resolveTemplateString(span.text, void 0, effectiveData, pageCtx);
|
|
7086
|
+
if (!t) continue;
|
|
7087
|
+
const spanIsBold = span.bold !== void 0 ? span.bold : el.style?.fontWeight === "bold";
|
|
7088
|
+
if (spanIsBold) usesBold = true;
|
|
7089
|
+
else usesNormal = true;
|
|
7090
|
+
}
|
|
7091
|
+
} else {
|
|
7092
|
+
const t = resolveTemplateString(el.content, el.fieldKey || el.bindingField, effectiveData, pageCtx);
|
|
7093
|
+
if (t) {
|
|
7094
|
+
if (el.style?.fontWeight === "bold") usesBold = true;
|
|
7095
|
+
else usesNormal = true;
|
|
7096
|
+
}
|
|
7097
|
+
}
|
|
7098
|
+
} else if (el.type === "list" /* LIST */) {
|
|
7099
|
+
if (el.items?.length) {
|
|
7100
|
+
if (el.style?.fontWeight === "bold") usesBold = true;
|
|
7101
|
+
else usesNormal = true;
|
|
7102
|
+
}
|
|
7103
|
+
} else if (el.type === "stamp" /* STAMP */) {
|
|
7104
|
+
if (el.primaryText) usesBold = true;
|
|
7105
|
+
if (el.secondaryText) usesNormal = true;
|
|
7106
|
+
} else if (el.type === "table" /* TABLE */) {
|
|
7107
|
+
if (el.showHead !== false && el.columns?.length) {
|
|
7108
|
+
if ((el.headerStyle?.fontWeight ?? "bold") === "bold") usesBold = true;
|
|
7109
|
+
else usesNormal = true;
|
|
7110
|
+
}
|
|
7111
|
+
if (el.rows && el.rows.length > 0 || Boolean(el.bindingField && effectiveData)) {
|
|
7112
|
+
if (el.bodyStyle?.fontWeight === "bold") usesBold = true;
|
|
7113
|
+
else usesNormal = true;
|
|
7114
|
+
}
|
|
7115
|
+
if (el.showPageSubtotal || el.showGrandTotal) {
|
|
7116
|
+
usesBold = true;
|
|
7117
|
+
}
|
|
7118
|
+
} else if (el.type === "checkbox" /* CHECKBOX */ || el.type === "radioGroup" /* RADIO_GROUP */ || el.type === "select" /* SELECT */ || el.type === "dateTime" /* DATE_TIME */ || el.type === "barcode" /* BARCODE */ || el.type === "redaction" /* REDACTION */ || el.type === "annotation" /* ANNOTATION */) {
|
|
7119
|
+
usesNormal = true;
|
|
7120
|
+
}
|
|
7121
|
+
}
|
|
7122
|
+
});
|
|
7123
|
+
return { usesNormal, usesBold };
|
|
7124
|
+
}
|
|
7125
|
+
async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
6965
7126
|
const renderCfg = options?.render;
|
|
6966
|
-
const
|
|
7127
|
+
const hasExplicitRenderFonts = Array.isArray(renderCfg?.fonts);
|
|
6967
7128
|
const explicitMode = renderCfg?.cjkTextMode ?? options?.cjkTextMode;
|
|
6968
|
-
const requestedMode = explicitMode ?? (
|
|
7129
|
+
const requestedMode = explicitMode ?? (hasExplicitRenderFonts ? "subset-ttf" : "raster-hd");
|
|
6969
7130
|
if (requestedMode === "raster-hd" || requestedMode === "cid-vector") {
|
|
6970
|
-
return { effectiveMode: requestedMode };
|
|
7131
|
+
return { effectiveMode: requestedMode, hasExplicitRenderFonts };
|
|
6971
7132
|
}
|
|
6972
7133
|
const failedFonts = [];
|
|
6973
7134
|
let normalFontBytes;
|
|
6974
|
-
let boldFontBytes
|
|
6975
|
-
if (
|
|
7135
|
+
let boldFontBytes;
|
|
7136
|
+
if (hasExplicitRenderFonts && renderCfg?.fonts) {
|
|
6976
7137
|
const normalCandidates = renderCfg.fonts.map((f, index) => ({ f, index })).filter(({ f }) => f.weight !== "bold");
|
|
6977
7138
|
const boldCandidates = renderCfg.fonts.map((f, index) => ({ f, index })).filter(({ f }) => f.weight === "bold");
|
|
6978
|
-
const
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
6983
|
-
|
|
6984
|
-
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
6988
|
-
|
|
6989
|
-
|
|
6990
|
-
|
|
7139
|
+
const { usesNormal, usesBold } = detectUsedPdfTextWeights(snapshot, effectiveData);
|
|
7140
|
+
let requiredWeightsFailed = renderCfg.fonts.length === 0;
|
|
7141
|
+
if (normalCandidates.length > 0 && boldCandidates.length === 0) {
|
|
7142
|
+
for (const { f, index } of normalCandidates) {
|
|
7143
|
+
try {
|
|
7144
|
+
normalFontBytes = await loadSingleFontCandidate(f);
|
|
7145
|
+
break;
|
|
7146
|
+
} catch (err) {
|
|
7147
|
+
failedFonts.push({
|
|
7148
|
+
index,
|
|
7149
|
+
family: f.family,
|
|
7150
|
+
weight: f.weight,
|
|
7151
|
+
url: f.url,
|
|
7152
|
+
reason: err?.message || String(err)
|
|
7153
|
+
});
|
|
7154
|
+
}
|
|
6991
7155
|
}
|
|
6992
|
-
|
|
6993
|
-
if (
|
|
7156
|
+
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
7157
|
+
} else if (normalCandidates.length === 0 && boldCandidates.length > 0) {
|
|
6994
7158
|
for (const { f, index } of boldCandidates) {
|
|
6995
7159
|
try {
|
|
6996
|
-
|
|
7160
|
+
const loadedBold = await loadSingleFontCandidate(f);
|
|
7161
|
+
normalFontBytes = loadedBold;
|
|
7162
|
+
boldFontBytes = loadedBold;
|
|
6997
7163
|
break;
|
|
6998
7164
|
} catch (err) {
|
|
6999
7165
|
failedFonts.push({
|
|
@@ -7005,50 +7171,106 @@ async function resolveRenderFontsForExport(snapshot, options) {
|
|
|
7005
7171
|
});
|
|
7006
7172
|
}
|
|
7007
7173
|
}
|
|
7174
|
+
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
7175
|
+
} else if (normalCandidates.length > 0 && boldCandidates.length > 0) {
|
|
7176
|
+
const needNormal = usesNormal || !usesBold;
|
|
7177
|
+
const needBold = usesBold;
|
|
7178
|
+
if (needNormal) {
|
|
7179
|
+
for (const { f, index } of normalCandidates) {
|
|
7180
|
+
try {
|
|
7181
|
+
normalFontBytes = await loadSingleFontCandidate(f);
|
|
7182
|
+
break;
|
|
7183
|
+
} catch (err) {
|
|
7184
|
+
failedFonts.push({
|
|
7185
|
+
index,
|
|
7186
|
+
family: f.family,
|
|
7187
|
+
weight: f.weight,
|
|
7188
|
+
url: f.url,
|
|
7189
|
+
reason: err?.message || String(err)
|
|
7190
|
+
});
|
|
7191
|
+
}
|
|
7192
|
+
}
|
|
7193
|
+
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
7194
|
+
}
|
|
7195
|
+
if (!requiredWeightsFailed && needBold) {
|
|
7196
|
+
for (const { f, index } of boldCandidates) {
|
|
7197
|
+
try {
|
|
7198
|
+
boldFontBytes = await loadSingleFontCandidate(f);
|
|
7199
|
+
break;
|
|
7200
|
+
} catch (err) {
|
|
7201
|
+
failedFonts.push({
|
|
7202
|
+
index,
|
|
7203
|
+
family: f.family,
|
|
7204
|
+
weight: f.weight,
|
|
7205
|
+
url: f.url,
|
|
7206
|
+
reason: err?.message || String(err)
|
|
7207
|
+
});
|
|
7208
|
+
}
|
|
7209
|
+
}
|
|
7210
|
+
if (!boldFontBytes) requiredWeightsFailed = true;
|
|
7211
|
+
if (!needNormal && boldFontBytes) {
|
|
7212
|
+
normalFontBytes = boldFontBytes;
|
|
7213
|
+
}
|
|
7214
|
+
}
|
|
7008
7215
|
}
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
index: failedFonts.length,
|
|
7017
|
-
reason: err?.message || String(err)
|
|
7018
|
-
});
|
|
7216
|
+
if (!requiredWeightsFailed && normalFontBytes && normalFontBytes.byteLength > 0) {
|
|
7217
|
+
return {
|
|
7218
|
+
effectiveMode: "subset-ttf",
|
|
7219
|
+
normalFontBytes,
|
|
7220
|
+
boldFontBytes,
|
|
7221
|
+
hasExplicitRenderFonts: true
|
|
7222
|
+
};
|
|
7019
7223
|
}
|
|
7020
|
-
}
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
(b) => b.type === "font" && Boolean(b.dataUri)
|
|
7024
|
-
);
|
|
7025
|
-
if (fontBinding?.dataUri) {
|
|
7224
|
+
} else {
|
|
7225
|
+
boldFontBytes = options?.customBoldFontBytes;
|
|
7226
|
+
if (options?.customFontBytes && options.customFontBytes.byteLength > 0) {
|
|
7026
7227
|
try {
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
normalFontBytes = decoded;
|
|
7228
|
+
inspectTrueTypeFont(options.customFontBytes);
|
|
7229
|
+
normalFontBytes = options.customFontBytes;
|
|
7030
7230
|
} catch (err) {
|
|
7031
7231
|
failedFonts.push({
|
|
7032
7232
|
index: failedFonts.length,
|
|
7033
|
-
family: fontBinding.name,
|
|
7034
7233
|
reason: err?.message || String(err)
|
|
7035
7234
|
});
|
|
7036
7235
|
}
|
|
7037
7236
|
}
|
|
7038
|
-
|
|
7039
|
-
|
|
7040
|
-
|
|
7041
|
-
|
|
7042
|
-
|
|
7043
|
-
|
|
7044
|
-
|
|
7237
|
+
if (!normalFontBytes && snapshot?.resourceBindings) {
|
|
7238
|
+
const fontBinding = Object.values(snapshot.resourceBindings).find(
|
|
7239
|
+
(b) => b.type === "font" && Boolean(b.dataUri)
|
|
7240
|
+
);
|
|
7241
|
+
if (fontBinding?.dataUri) {
|
|
7242
|
+
try {
|
|
7243
|
+
const decoded = dataUriToBytes(fontBinding.dataUri);
|
|
7244
|
+
inspectTrueTypeFont(decoded);
|
|
7245
|
+
normalFontBytes = decoded;
|
|
7246
|
+
} catch (err) {
|
|
7247
|
+
failedFonts.push({
|
|
7248
|
+
index: failedFonts.length,
|
|
7249
|
+
family: fontBinding.name,
|
|
7250
|
+
reason: err?.message || String(err)
|
|
7251
|
+
});
|
|
7252
|
+
}
|
|
7253
|
+
}
|
|
7254
|
+
}
|
|
7255
|
+
if (normalFontBytes && normalFontBytes.byteLength > 0) {
|
|
7256
|
+
if (boldFontBytes) {
|
|
7257
|
+
try {
|
|
7258
|
+
inspectTrueTypeFont(boldFontBytes);
|
|
7259
|
+
} catch {
|
|
7260
|
+
boldFontBytes = void 0;
|
|
7261
|
+
}
|
|
7045
7262
|
}
|
|
7263
|
+
return {
|
|
7264
|
+
effectiveMode: "subset-ttf",
|
|
7265
|
+
normalFontBytes,
|
|
7266
|
+
boldFontBytes,
|
|
7267
|
+
hasExplicitRenderFonts: false
|
|
7268
|
+
};
|
|
7046
7269
|
}
|
|
7047
|
-
return { effectiveMode: "subset-ttf", normalFontBytes, boldFontBytes };
|
|
7048
7270
|
}
|
|
7049
7271
|
const fallbackPolicy = renderCfg?.fallback ?? "error";
|
|
7050
7272
|
const detailSummary = failedFonts.length > 0 ? failedFonts.map(
|
|
7051
|
-
(e) => `#${e.index}${e.family ? ` (${e.family})` : ""}${e.url ? ` [${e.url}]` : ""}: ${e.reason}`
|
|
7273
|
+
(e) => `#${e.index}${e.family ? ` (${e.family})` : ""}${e.weight ? ` [${e.weight}]` : ""}${e.url ? ` [${e.url}]` : ""}: ${e.reason}`
|
|
7052
7274
|
).join("; ") : "\u672A\u63D0\u4F9B\u53EF\u7528\u7684 TrueType (.ttf) \u5B57\u4F53\u5B57\u8282\u6216\u5730\u5740";
|
|
7053
7275
|
if (fallbackPolicy === "raster-hd" || fallbackPolicy === "cid-vector") {
|
|
7054
7276
|
renderCfg?.onWarning?.({
|
|
@@ -7056,7 +7278,7 @@ async function resolveRenderFontsForExport(snapshot, options) {
|
|
|
7056
7278
|
message: `\u4E2D\u6587\u5B57\u4F53\u52A0\u8F7D\u5931\u8D25\uFF0C\u5DF2\u6309\u663E\u5F0F\u56DE\u9000\u7B56\u7565\u5207\u6362\u81F3 '${fallbackPolicy}'\uFF1A${detailSummary}`,
|
|
7057
7279
|
details: { fallback: fallbackPolicy, failedFonts }
|
|
7058
7280
|
});
|
|
7059
|
-
return { effectiveMode: fallbackPolicy };
|
|
7281
|
+
return { effectiveMode: fallbackPolicy, hasExplicitRenderFonts };
|
|
7060
7282
|
}
|
|
7061
7283
|
throw new PdfRenderError(
|
|
7062
7284
|
"FONT_UNAVAILABLE",
|
|
@@ -7067,8 +7289,11 @@ async function resolveRenderFontsForExport(snapshot, options) {
|
|
|
7067
7289
|
function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preResolved) {
|
|
7068
7290
|
const requested = preResolved?.effectiveMode ?? options?.render?.cjkTextMode ?? options?.cjkTextMode ?? "raster-hd";
|
|
7069
7291
|
if (requested === "raster-hd") return null;
|
|
7070
|
-
|
|
7071
|
-
|
|
7292
|
+
const hasExplicitRenderFonts = Boolean(
|
|
7293
|
+
preResolved?.hasExplicitRenderFonts ?? Array.isArray(options?.render?.fonts)
|
|
7294
|
+
);
|
|
7295
|
+
let resolvedFontBytes = preResolved ? preResolved.normalFontBytes : hasExplicitRenderFonts ? void 0 : options?.customFontBytes;
|
|
7296
|
+
if ((!resolvedFontBytes || resolvedFontBytes.byteLength === 0) && !preResolved && !hasExplicitRenderFonts && snapshot?.resourceBindings) {
|
|
7072
7297
|
const fontBinding = Object.values(snapshot.resourceBindings).find(
|
|
7073
7298
|
(b) => b.type === "font" && Boolean(b.dataUri)
|
|
7074
7299
|
);
|
|
@@ -7094,6 +7319,24 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
7094
7319
|
usedCodePoints,
|
|
7095
7320
|
"UNVPDF+SubsetTTF"
|
|
7096
7321
|
);
|
|
7322
|
+
let boldType0FontRef;
|
|
7323
|
+
let boldSubset;
|
|
7324
|
+
const boldBytes = preResolved ? preResolved.boldFontBytes : hasExplicitRenderFonts ? void 0 : options?.customBoldFontBytes;
|
|
7325
|
+
if (boldBytes && boldBytes.byteLength > 0) {
|
|
7326
|
+
if (boldBytes === resolvedFontBytes) {
|
|
7327
|
+
boldType0FontRef = type0FontRef2;
|
|
7328
|
+
boldSubset = subset;
|
|
7329
|
+
} else {
|
|
7330
|
+
const regBold = registerSubsetType0FontInDoc(
|
|
7331
|
+
pdfDoc,
|
|
7332
|
+
boldBytes,
|
|
7333
|
+
usedCodePoints,
|
|
7334
|
+
"UNVPDF+SubsetTTFBold"
|
|
7335
|
+
);
|
|
7336
|
+
boldType0FontRef = regBold.type0FontRef;
|
|
7337
|
+
boldSubset = regBold.subset;
|
|
7338
|
+
}
|
|
7339
|
+
}
|
|
7097
7340
|
const missingItems = collectMissingGlyphsFromPdfUnit(
|
|
7098
7341
|
snapshot,
|
|
7099
7342
|
(cp) => (subset.codePointToGid[cp] ?? 0) > 0,
|
|
@@ -7101,7 +7344,7 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
7101
7344
|
formatPdfTableCell
|
|
7102
7345
|
);
|
|
7103
7346
|
if (missingItems.length > 0) {
|
|
7104
|
-
const missingPolicy = options?.render?.missingGlyph ?? "warn";
|
|
7347
|
+
const missingPolicy = options?.render?.missingGlyph ?? (hasExplicitRenderFonts ? "error" : "warn");
|
|
7105
7348
|
if (missingPolicy === "error") {
|
|
7106
7349
|
const desc = missingItems.map(
|
|
7107
7350
|
(m) => `${m.pageId ? `${m.pageId}/` : ""}${m.elementId}: ${m.chars.map((c, idx) => `'${c}' (${m.codePoints[idx]})`).join(", ")}`
|
|
@@ -7124,19 +7367,6 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
7124
7367
|
}
|
|
7125
7368
|
}
|
|
7126
7369
|
}
|
|
7127
|
-
let boldType0FontRef;
|
|
7128
|
-
let boldSubset;
|
|
7129
|
-
const boldBytes = preResolved?.boldFontBytes ?? options?.customBoldFontBytes;
|
|
7130
|
-
if (boldBytes && boldBytes.byteLength > 0) {
|
|
7131
|
-
const regBold = registerSubsetType0FontInDoc(
|
|
7132
|
-
pdfDoc,
|
|
7133
|
-
boldBytes,
|
|
7134
|
-
usedCodePoints,
|
|
7135
|
-
"UNVPDF+SubsetTTFBold"
|
|
7136
|
-
);
|
|
7137
|
-
boldType0FontRef = regBold.type0FontRef;
|
|
7138
|
-
boldSubset = regBold.subset;
|
|
7139
|
-
}
|
|
7140
7370
|
return {
|
|
7141
7371
|
mode: "subset-ttf",
|
|
7142
7372
|
type0FontRef: type0FontRef2,
|
|
@@ -7145,6 +7375,9 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
7145
7375
|
...boldType0FontRef ? { boldType0FontRef, boldSubset, boldPageFontKeys: /* @__PURE__ */ new WeakMap() } : {}
|
|
7146
7376
|
};
|
|
7147
7377
|
}
|
|
7378
|
+
const usedCidCodePoints = collectUsedCodePointsFromPdfUnit(snapshot, effectiveData);
|
|
7379
|
+
const cidToUnicodeCmap = buildCidUtf16ToUnicodeCmapString(usedCidCodePoints);
|
|
7380
|
+
const cidToUnicodeRef = pdfDoc.context.register(pdfDoc.context.flateStream(cidToUnicodeCmap));
|
|
7148
7381
|
const fontDescriptorRef = pdfDoc.context.register(
|
|
7149
7382
|
pdfDoc.context.obj({
|
|
7150
7383
|
Type: "FontDescriptor",
|
|
@@ -7178,7 +7411,8 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
7178
7411
|
Subtype: "Type0",
|
|
7179
7412
|
BaseFont: "STSong-Light",
|
|
7180
7413
|
Encoding: "UniGB-UTF16-H",
|
|
7181
|
-
DescendantFonts: [cidFontRef]
|
|
7414
|
+
DescendantFonts: [cidFontRef],
|
|
7415
|
+
ToUnicode: cidToUnicodeRef
|
|
7182
7416
|
})
|
|
7183
7417
|
);
|
|
7184
7418
|
return {
|
|
@@ -7329,7 +7563,7 @@ function encodeVectorCjkLineHex(line, state, overrideSubset) {
|
|
|
7329
7563
|
}
|
|
7330
7564
|
return hex;
|
|
7331
7565
|
}
|
|
7332
|
-
return toUtf16BeHex(line,
|
|
7566
|
+
return toUtf16BeHex(line.replace(/\uFEFF/g, ""), false);
|
|
7333
7567
|
}
|
|
7334
7568
|
function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height, style, state, noWrapSingleLine = false, colorType, overrideCharacterSpacing) {
|
|
7335
7569
|
const wantBold = style?.fontWeight === "bold";
|
|
@@ -9447,7 +9681,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
9447
9681
|
options?.accessibilityTagged ?? snapshot.accessibilityTagged ?? snapshot.metadata?.accessibilityTagged
|
|
9448
9682
|
);
|
|
9449
9683
|
const optimizeSize = Boolean(options?.optimizeSize);
|
|
9450
|
-
const preResolvedFonts = await resolveRenderFontsForExport(snapshot, options);
|
|
9684
|
+
const preResolvedFonts = await resolveRenderFontsForExport(snapshot, effectiveData, options);
|
|
9451
9685
|
const pdfDoc = await PDFDocument2.create();
|
|
9452
9686
|
if (snapshot.metadata?.sanitized) {
|
|
9453
9687
|
pdfDoc.setTitle("");
|
|
@@ -13145,7 +13379,7 @@ function buildCompositeTestGlyph(compGidA, compGidB) {
|
|
|
13145
13379
|
view.setInt16(24, 80, false);
|
|
13146
13380
|
return buf;
|
|
13147
13381
|
}
|
|
13148
|
-
var DEFAULT_FIXTURE_CJK_TEXT = "\u987A\u4E30\u7535\u5B50\u9762\u5355\u4E09\u8054\u91C7\u8D2D\u51FA\u5E93\u5957\u6253\u6A21\u677F\u542B\u8FFD\u6EAF\u7801\u660E\u7EC6\u8868\u4E0E\u7B7E\u6536\u7EA2\u7AE0\u828B\u9053\u4F01\u4E1A\u7EA7\u62A5\u8868\u8BA2\u5355\u7F16\u53F7\u5BA2\u6237\u540D\u79F0\u6536\u8D27\u5730\u5740\u5546\u54C1\u89C4\u683C\u6570\u91CF\u5355\u4EF7\u91D1\u989D\u5408\u8BA1\u5DF2\u6838\u9A8C\u4FDD\u4EF7\u8FD0\u8F93\u6B21\u65E5\u8FBE\u9646\u8FD0\u4E13\u7968\u666E\u7968\u4E0A\u6D77\u6D66\u4E1C\u5F20\u6C5F\u9AD8\u79D1\u6280\u56ED\u533A\u5317\u4EAC\u6DF1\u5733\u676D\u5DDE\u4E2D\u6587\u77E2\u91CF\u53EF\u68C0\u7D22\u5B57\u4F53\u5B50\u96C6\u5316\u6D4B\u8BD5\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D\u5341\u767E\u5343\u4E07\u96F6\u5143\u89D2\u5206\u5E74\u6708\u65E5\u65F6\u5206\u79D2\u9875\u5171\u7B2C\u5185\u90E8\u8D44\u6599\u590D\u5370\u65E0\u6548\u8D22\u52A1\u4E13\u7528\u7AE0\u4ED3\u5E93\u7B7E\u7AE0\u9879\u76EE\u6458\u8981\u5BA1\u6279\u4EBA\u65E5\u671F\u8BF4\u660E\u72B6\u6001\u901A\u8FC7\u5F85\u5BA1\u6BD4\u4F8B\u589E\u957F\u7387\u5B8C\u6210\u5EA6\u6708\u5EA6\u5B63\u5EA6\u5E74\u5EA6\u5DE5\u4E1A\u4F20\u611F\u5668\u6A21\u5757\u63A7\u5236\u5668\u7CBE\u5BC6\u7EC4\u4EF6\u534E\u4E1C\u534E\u5357\u534E\u5317\u7ECF\u8425\u7B80\u62A5\u6838\u5FC3\u6B63\u5E38\u884C\u51FA\u88C1\u5207\u5916\u6EA2\u90BB\u683C\u5F20\u5DE5\u636E\u6001\u5165\u8DE8\u8868\u5934\u6591\u9A6C\u7EB9\u8FDE\u7EED\u6027\u8BC1\u5E8F\u5DE6\u5BF9\u9F50\u9876\u90E8\u5E95\u53F3\u7F29\u5C0F\u5B57\u81EA\u9002\u5E94\u591A\u6BB5\u6DF7\u6392\u957F\u6587\u672C\u793A\u4F8B\u5168\u89D2\u6807\u70B9\u5907\u6CE8\u751F\u50FB\u56FE\u6807\u7F3A\u8BCA\u65AD\u5DEE\u9519\u4EA4\u4ED8\u56FA\u9AD8\u5C06\u5728\u4E25\u7EDD\u5411\u4E0B\u65B9\u5143\u7D20\u4F4D\u8FB9\u4E4B\u5C45\u5782\u76F4\u7387\u5F53\u7D27\u51D1\u52A8\u81F3\u4F4E\u4FDD\u7559\u6536\u7F16\u5907\u54C1\u5957\u9996\u4FB5\u5165\u4EC5\u672B\u5C3E\u73B0\u91CD\u53E0\u680F\u51C6\u7248\u5730\u5B9A\u5BB9\u500D\u540E\xD7\xA5\uFFE5\uFF0C\u3002\uFF1A\uFF1B\uFF01\uFF1F\uFF08\uFF09\u3010\u3011\u300A\u300B\uFF05\u2014\xB7\u201C\u201D\u2018\u2019\uFF5C\u2605";
|
|
13382
|
+
var DEFAULT_FIXTURE_CJK_TEXT = "\u987A\u4E30\u7535\u5B50\u9762\u5355\u4E09\u8054\u91C7\u8D2D\u51FA\u5E93\u5957\u6253\u6A21\u677F\u542B\u8FFD\u6EAF\u7801\u660E\u7EC6\u8868\u4E0E\u7B7E\u6536\u7EA2\u7AE0\u828B\u9053\u4F01\u4E1A\u7EA7\u62A5\u8868\u8BA2\u5355\u7F16\u53F7\u5BA2\u6237\u540D\u79F0\u6536\u8D27\u5730\u5740\u5546\u54C1\u89C4\u683C\u6570\u91CF\u5355\u4EF7\u91D1\u989D\u5408\u8BA1\u5DF2\u6838\u9A8C\u4FDD\u4EF7\u8FD0\u8F93\u6B21\u65E5\u8FBE\u9646\u8FD0\u4E13\u7968\u666E\u7968\u4E0A\u6D77\u6D66\u4E1C\u5F20\u6C5F\u9AD8\u79D1\u6280\u56ED\u533A\u5317\u4EAC\u6DF1\u5733\u676D\u5DDE\u4E2D\u6587\u77E2\u91CF\u53EF\u68C0\u7D22\u5B57\u4F53\u5B50\u96C6\u5316\u6D4B\u8BD5\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D\u5341\u767E\u5343\u4E07\u96F6\u5143\u89D2\u5206\u5E74\u6708\u65E5\u65F6\u5206\u79D2\u9875\u5171\u7B2C\u5185\u90E8\u8D44\u6599\u590D\u5370\u65E0\u6548\u8D22\u52A1\u4E13\u7528\u7AE0\u4ED3\u5E93\u7B7E\u7AE0\u9879\u76EE\u6458\u8981\u5BA1\u6279\u4EBA\u65E5\u671F\u8BF4\u660E\u72B6\u6001\u901A\u8FC7\u5F85\u5BA1\u6BD4\u4F8B\u589E\u957F\u7387\u5B8C\u6210\u5EA6\u6708\u5EA6\u5B63\u5EA6\u5E74\u5EA6\u5DE5\u4E1A\u4F20\u611F\u5668\u6A21\u5757\u63A7\u5236\u5668\u7CBE\u5BC6\u7EC4\u4EF6\u534E\u4E1C\u534E\u5357\u534E\u5317\u7ECF\u8425\u7B80\u62A5\u6838\u5FC3\u6B63\u5E38\u884C\u51FA\u88C1\u5207\u5916\u6EA2\u90BB\u683C\u5F20\u5DE5\u636E\u6001\u5165\u8DE8\u8868\u5934\u6591\u9A6C\u7EB9\u8FDE\u7EED\u6027\u8BC1\u5E8F\u5DE6\u5BF9\u9F50\u9876\u90E8\u5E95\u53F3\u7F29\u5C0F\u5B57\u81EA\u9002\u5E94\u591A\u6BB5\u6DF7\u6392\u957F\u6587\u672C\u793A\u4F8B\u5168\u89D2\u6807\u70B9\u5907\u6CE8\u751F\u50FB\u56FE\u6807\u7F3A\u8BCA\u65AD\u5DEE\u9519\u4EA4\u4ED8\u56FA\u9AD8\u5C06\u5728\u4E25\u7EDD\u5411\u4E0B\u65B9\u5143\u7D20\u4F4D\u8FB9\u4E4B\u5C45\u5782\u76F4\u7387\u5F53\u7D27\u51D1\u52A8\u81F3\u4F4E\u4FDD\u7559\u6536\u7F16\u5907\u54C1\u5957\u9996\u4FB5\u5165\u4EC5\u672B\u5C3E\u73B0\u91CD\u53E0\u680F\u51C6\u7248\u5730\u5B9A\u5BB9\u500D\u540E\u77ED\u897F\u6846\u8D85\u7684\u754C\u6700\u6574\u5217\u5F0F\u5BBD\u503C\u5E01\u5305\u88C5\u663E\u7A84\u9ED8\u8BA4\u7167\u5F00\u542F\u6D41\u8F6C\u5F02\u672A\u5149\u6805\u517C\xD7\xA5\uFFE5\uFF0C\u3001\u3002\uFF1A\uFF1B\uFF01\uFF1F\uFF08\uFF09\u3010\u3011\u300A\u300B\uFF05\u2014\u2013\xB7\u201C\u201D\u2018\u2019\uFF5C\u2605";
|
|
13149
13383
|
function buildMinimalTestTrueTypeFont(extraCodePoints) {
|
|
13150
13384
|
const cpSet = /* @__PURE__ */ new Set();
|
|
13151
13385
|
for (let ascii = 32; ascii <= 126; ascii++) {
|
|
@@ -15954,6 +16188,11 @@ export {
|
|
|
15954
16188
|
parseSvgToVectorCommands,
|
|
15955
16189
|
drawVectorSvgOnPdfPage,
|
|
15956
16190
|
PdfRenderError,
|
|
16191
|
+
DEFAULT_PDF_CJK_FONT_PACKAGE,
|
|
16192
|
+
DEFAULT_PDF_CJK_FONT_VERSION,
|
|
16193
|
+
DEFAULT_PDF_CJK_FONT_FAMILY,
|
|
16194
|
+
DEFAULT_PDF_CJK_FONT_FILES,
|
|
16195
|
+
createPdfCjkFontSources,
|
|
15957
16196
|
clearPdfFontUrlCache,
|
|
15958
16197
|
resolveTemplateString,
|
|
15959
16198
|
validatePdfTemplateVariables,
|
|
@@ -16020,4 +16259,4 @@ export {
|
|
|
16020
16259
|
renderJsxToPdfmeTemplate,
|
|
16021
16260
|
exportJsxToPdfBytes
|
|
16022
16261
|
};
|
|
16023
|
-
//# sourceMappingURL=chunk-
|
|
16262
|
+
//# sourceMappingURL=chunk-DYTQBEM7.js.map
|