@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
package/lib/cjs/jsx/index.js
CHANGED
|
@@ -5566,6 +5566,21 @@ var PdfRenderError = class extends Error {
|
|
|
5566
5566
|
if (extra?.missingGlyphs) this.missingGlyphs = extra.missingGlyphs;
|
|
5567
5567
|
}
|
|
5568
5568
|
};
|
|
5569
|
+
var DEFAULT_PDF_CJK_FONT_FAMILY = "Noto Sans SC";
|
|
5570
|
+
var DEFAULT_PDF_CJK_FONT_FILES = Object.freeze({
|
|
5571
|
+
normal: Object.freeze({
|
|
5572
|
+
file: "NotoSansSC-Regular.ttf",
|
|
5573
|
+
family: DEFAULT_PDF_CJK_FONT_FAMILY,
|
|
5574
|
+
weight: "normal",
|
|
5575
|
+
integrity: "sha384-WYgE+CQjxrXCFCynsUOYE86llni41IspZsiH2huo8yxlgR2GKNE5fzeurmHXRfIe"
|
|
5576
|
+
}),
|
|
5577
|
+
bold: Object.freeze({
|
|
5578
|
+
file: "NotoSansSC-Bold.ttf",
|
|
5579
|
+
family: DEFAULT_PDF_CJK_FONT_FAMILY,
|
|
5580
|
+
weight: "bold",
|
|
5581
|
+
integrity: "sha384-jI+dGvcJGGgO8RayO+x2LHDI85inVoe36tfbBKtSD6SQ0A8VKi5s+0lG+of4qB6j"
|
|
5582
|
+
})
|
|
5583
|
+
});
|
|
5569
5584
|
var pdfFontUrlByteCache = /* @__PURE__ */ new Map();
|
|
5570
5585
|
function bytesToBase64Standard(bytes) {
|
|
5571
5586
|
if (typeof Buffer !== "undefined") {
|
|
@@ -5822,39 +5837,147 @@ function registerSubsetType0FontInDoc(pdfDoc, fontBytes, usedCodePoints, fontTag
|
|
|
5822
5837
|
);
|
|
5823
5838
|
return { type0FontRef, subset };
|
|
5824
5839
|
}
|
|
5825
|
-
|
|
5840
|
+
function buildCidUtf16ToUnicodeCmapString(usedCodePoints) {
|
|
5841
|
+
const bmpHexList = [];
|
|
5842
|
+
const suppHexList = [];
|
|
5843
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5844
|
+
for (const cp of usedCodePoints) {
|
|
5845
|
+
if (!Number.isInteger(cp) || cp <= 0 || cp === 65279 || seen.has(cp)) continue;
|
|
5846
|
+
seen.add(cp);
|
|
5847
|
+
const hex = toUtf16BeHex(String.fromCodePoint(cp), false);
|
|
5848
|
+
if (cp <= 65535) {
|
|
5849
|
+
bmpHexList.push(hex);
|
|
5850
|
+
} else {
|
|
5851
|
+
suppHexList.push(hex);
|
|
5852
|
+
}
|
|
5853
|
+
}
|
|
5854
|
+
bmpHexList.sort();
|
|
5855
|
+
suppHexList.sort();
|
|
5856
|
+
const bfBlocks = [];
|
|
5857
|
+
for (const list of [bmpHexList, suppHexList]) {
|
|
5858
|
+
for (let i = 0; i < list.length; i += 100) {
|
|
5859
|
+
const chunk = list.slice(i, i + 100);
|
|
5860
|
+
const lines = chunk.map((h) => `<${h}> <${h}>`).join("\n");
|
|
5861
|
+
bfBlocks.push(`${chunk.length} beginbfchar
|
|
5862
|
+
${lines}
|
|
5863
|
+
endbfchar`);
|
|
5864
|
+
}
|
|
5865
|
+
}
|
|
5866
|
+
const codespaceLines = suppHexList.length > 0 ? ["2 begincodespacerange", "<0000> <FFFF>", "<D800DC00> <DBFFDFFF>", "endcodespacerange"] : ["1 begincodespacerange", "<0000> <FFFF>", "endcodespacerange"];
|
|
5867
|
+
return [
|
|
5868
|
+
"/CIDInit /ProcSet findresource begin",
|
|
5869
|
+
"12 dict begin",
|
|
5870
|
+
"begincmap",
|
|
5871
|
+
"/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def",
|
|
5872
|
+
"/CMapName /Adobe-Identity-UCS def",
|
|
5873
|
+
"/CMapType 2 def",
|
|
5874
|
+
...codespaceLines,
|
|
5875
|
+
...bfBlocks,
|
|
5876
|
+
"endcmap",
|
|
5877
|
+
"CMapName currentdict /CMap defineresource pop",
|
|
5878
|
+
"end",
|
|
5879
|
+
"end"
|
|
5880
|
+
].join("\n");
|
|
5881
|
+
}
|
|
5882
|
+
function detectUsedPdfTextWeights(snapshot, effectiveData) {
|
|
5883
|
+
let usesNormal = false;
|
|
5884
|
+
let usesBold = false;
|
|
5885
|
+
if (snapshot.metadata?.watermarkText && snapshot.metadata?.watermarkConfig?.enabled !== false) {
|
|
5886
|
+
usesNormal = true;
|
|
5887
|
+
}
|
|
5888
|
+
if (snapshot.metadata?.batesConfig?.enabled) {
|
|
5889
|
+
usesNormal = true;
|
|
5890
|
+
}
|
|
5891
|
+
const totalPages = snapshot.document.pageOrder.length;
|
|
5892
|
+
const startPageOffset = Math.max(1, Number(snapshot.metadata?.startPageNumber ?? 1) || 1);
|
|
5893
|
+
snapshot.document.pageOrder.forEach((pageId, pIdx) => {
|
|
5894
|
+
const pageCtx = { pageNumber: startPageOffset + pIdx, totalPages: startPageOffset + totalPages - 1 };
|
|
5895
|
+
const map = snapshot.editState.elementsByPage[pageId] ?? {};
|
|
5896
|
+
const order = snapshot.editState.elementOrderByPage[pageId] ?? Object.keys(map);
|
|
5897
|
+
for (const id of order) {
|
|
5898
|
+
const el = map[id];
|
|
5899
|
+
if (!el || el.hidden) continue;
|
|
5900
|
+
if (el.type === "text" /* TEXT */) {
|
|
5901
|
+
if (el.richSpans?.length) {
|
|
5902
|
+
for (const span of el.richSpans) {
|
|
5903
|
+
const t = resolveTemplateString(span.text, void 0, effectiveData, pageCtx);
|
|
5904
|
+
if (!t) continue;
|
|
5905
|
+
const spanIsBold = span.bold !== void 0 ? span.bold : el.style?.fontWeight === "bold";
|
|
5906
|
+
if (spanIsBold) usesBold = true;
|
|
5907
|
+
else usesNormal = true;
|
|
5908
|
+
}
|
|
5909
|
+
} else {
|
|
5910
|
+
const t = resolveTemplateString(el.content, el.fieldKey || el.bindingField, effectiveData, pageCtx);
|
|
5911
|
+
if (t) {
|
|
5912
|
+
if (el.style?.fontWeight === "bold") usesBold = true;
|
|
5913
|
+
else usesNormal = true;
|
|
5914
|
+
}
|
|
5915
|
+
}
|
|
5916
|
+
} else if (el.type === "list" /* LIST */) {
|
|
5917
|
+
if (el.items?.length) {
|
|
5918
|
+
if (el.style?.fontWeight === "bold") usesBold = true;
|
|
5919
|
+
else usesNormal = true;
|
|
5920
|
+
}
|
|
5921
|
+
} else if (el.type === "stamp" /* STAMP */) {
|
|
5922
|
+
if (el.primaryText) usesBold = true;
|
|
5923
|
+
if (el.secondaryText) usesNormal = true;
|
|
5924
|
+
} else if (el.type === "table" /* TABLE */) {
|
|
5925
|
+
if (el.showHead !== false && el.columns?.length) {
|
|
5926
|
+
if ((el.headerStyle?.fontWeight ?? "bold") === "bold") usesBold = true;
|
|
5927
|
+
else usesNormal = true;
|
|
5928
|
+
}
|
|
5929
|
+
if (el.rows && el.rows.length > 0 || Boolean(el.bindingField && effectiveData)) {
|
|
5930
|
+
if (el.bodyStyle?.fontWeight === "bold") usesBold = true;
|
|
5931
|
+
else usesNormal = true;
|
|
5932
|
+
}
|
|
5933
|
+
if (el.showPageSubtotal || el.showGrandTotal) {
|
|
5934
|
+
usesBold = true;
|
|
5935
|
+
}
|
|
5936
|
+
} 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 */) {
|
|
5937
|
+
usesNormal = true;
|
|
5938
|
+
}
|
|
5939
|
+
}
|
|
5940
|
+
});
|
|
5941
|
+
return { usesNormal, usesBold };
|
|
5942
|
+
}
|
|
5943
|
+
async function resolveRenderFontsForExport(snapshot, effectiveData, options) {
|
|
5826
5944
|
const renderCfg = options?.render;
|
|
5827
|
-
const
|
|
5945
|
+
const hasExplicitRenderFonts = Array.isArray(renderCfg?.fonts);
|
|
5828
5946
|
const explicitMode = renderCfg?.cjkTextMode ?? options?.cjkTextMode;
|
|
5829
|
-
const requestedMode = explicitMode ?? (
|
|
5947
|
+
const requestedMode = explicitMode ?? (hasExplicitRenderFonts ? "subset-ttf" : "raster-hd");
|
|
5830
5948
|
if (requestedMode === "raster-hd" || requestedMode === "cid-vector") {
|
|
5831
|
-
return { effectiveMode: requestedMode };
|
|
5949
|
+
return { effectiveMode: requestedMode, hasExplicitRenderFonts };
|
|
5832
5950
|
}
|
|
5833
5951
|
const failedFonts = [];
|
|
5834
5952
|
let normalFontBytes;
|
|
5835
|
-
let boldFontBytes
|
|
5836
|
-
if (
|
|
5953
|
+
let boldFontBytes;
|
|
5954
|
+
if (hasExplicitRenderFonts && renderCfg?.fonts) {
|
|
5837
5955
|
const normalCandidates = renderCfg.fonts.map((f, index) => ({ f, index })).filter(({ f }) => f.weight !== "bold");
|
|
5838
5956
|
const boldCandidates = renderCfg.fonts.map((f, index) => ({ f, index })).filter(({ f }) => f.weight === "bold");
|
|
5839
|
-
const
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
|
|
5843
|
-
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5957
|
+
const { usesNormal, usesBold } = detectUsedPdfTextWeights(snapshot, effectiveData);
|
|
5958
|
+
let requiredWeightsFailed = renderCfg.fonts.length === 0;
|
|
5959
|
+
if (normalCandidates.length > 0 && boldCandidates.length === 0) {
|
|
5960
|
+
for (const { f, index } of normalCandidates) {
|
|
5961
|
+
try {
|
|
5962
|
+
normalFontBytes = await loadSingleFontCandidate(f);
|
|
5963
|
+
break;
|
|
5964
|
+
} catch (err) {
|
|
5965
|
+
failedFonts.push({
|
|
5966
|
+
index,
|
|
5967
|
+
family: f.family,
|
|
5968
|
+
weight: f.weight,
|
|
5969
|
+
url: f.url,
|
|
5970
|
+
reason: err?.message || String(err)
|
|
5971
|
+
});
|
|
5972
|
+
}
|
|
5852
5973
|
}
|
|
5853
|
-
|
|
5854
|
-
if (
|
|
5974
|
+
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
5975
|
+
} else if (normalCandidates.length === 0 && boldCandidates.length > 0) {
|
|
5855
5976
|
for (const { f, index } of boldCandidates) {
|
|
5856
5977
|
try {
|
|
5857
|
-
|
|
5978
|
+
const loadedBold = await loadSingleFontCandidate(f);
|
|
5979
|
+
normalFontBytes = loadedBold;
|
|
5980
|
+
boldFontBytes = loadedBold;
|
|
5858
5981
|
break;
|
|
5859
5982
|
} catch (err) {
|
|
5860
5983
|
failedFonts.push({
|
|
@@ -5866,50 +5989,106 @@ async function resolveRenderFontsForExport(snapshot, options) {
|
|
|
5866
5989
|
});
|
|
5867
5990
|
}
|
|
5868
5991
|
}
|
|
5992
|
+
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
5993
|
+
} else if (normalCandidates.length > 0 && boldCandidates.length > 0) {
|
|
5994
|
+
const needNormal = usesNormal || !usesBold;
|
|
5995
|
+
const needBold = usesBold;
|
|
5996
|
+
if (needNormal) {
|
|
5997
|
+
for (const { f, index } of normalCandidates) {
|
|
5998
|
+
try {
|
|
5999
|
+
normalFontBytes = await loadSingleFontCandidate(f);
|
|
6000
|
+
break;
|
|
6001
|
+
} catch (err) {
|
|
6002
|
+
failedFonts.push({
|
|
6003
|
+
index,
|
|
6004
|
+
family: f.family,
|
|
6005
|
+
weight: f.weight,
|
|
6006
|
+
url: f.url,
|
|
6007
|
+
reason: err?.message || String(err)
|
|
6008
|
+
});
|
|
6009
|
+
}
|
|
6010
|
+
}
|
|
6011
|
+
if (!normalFontBytes) requiredWeightsFailed = true;
|
|
6012
|
+
}
|
|
6013
|
+
if (!requiredWeightsFailed && needBold) {
|
|
6014
|
+
for (const { f, index } of boldCandidates) {
|
|
6015
|
+
try {
|
|
6016
|
+
boldFontBytes = await loadSingleFontCandidate(f);
|
|
6017
|
+
break;
|
|
6018
|
+
} catch (err) {
|
|
6019
|
+
failedFonts.push({
|
|
6020
|
+
index,
|
|
6021
|
+
family: f.family,
|
|
6022
|
+
weight: f.weight,
|
|
6023
|
+
url: f.url,
|
|
6024
|
+
reason: err?.message || String(err)
|
|
6025
|
+
});
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
if (!boldFontBytes) requiredWeightsFailed = true;
|
|
6029
|
+
if (!needNormal && boldFontBytes) {
|
|
6030
|
+
normalFontBytes = boldFontBytes;
|
|
6031
|
+
}
|
|
6032
|
+
}
|
|
5869
6033
|
}
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
index: failedFonts.length,
|
|
5878
|
-
reason: err?.message || String(err)
|
|
5879
|
-
});
|
|
6034
|
+
if (!requiredWeightsFailed && normalFontBytes && normalFontBytes.byteLength > 0) {
|
|
6035
|
+
return {
|
|
6036
|
+
effectiveMode: "subset-ttf",
|
|
6037
|
+
normalFontBytes,
|
|
6038
|
+
boldFontBytes,
|
|
6039
|
+
hasExplicitRenderFonts: true
|
|
6040
|
+
};
|
|
5880
6041
|
}
|
|
5881
|
-
}
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
(b) => b.type === "font" && Boolean(b.dataUri)
|
|
5885
|
-
);
|
|
5886
|
-
if (fontBinding?.dataUri) {
|
|
6042
|
+
} else {
|
|
6043
|
+
boldFontBytes = options?.customBoldFontBytes;
|
|
6044
|
+
if (options?.customFontBytes && options.customFontBytes.byteLength > 0) {
|
|
5887
6045
|
try {
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
normalFontBytes = decoded;
|
|
6046
|
+
inspectTrueTypeFont(options.customFontBytes);
|
|
6047
|
+
normalFontBytes = options.customFontBytes;
|
|
5891
6048
|
} catch (err) {
|
|
5892
6049
|
failedFonts.push({
|
|
5893
6050
|
index: failedFonts.length,
|
|
5894
|
-
family: fontBinding.name,
|
|
5895
6051
|
reason: err?.message || String(err)
|
|
5896
6052
|
});
|
|
5897
6053
|
}
|
|
5898
6054
|
}
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
6055
|
+
if (!normalFontBytes && snapshot?.resourceBindings) {
|
|
6056
|
+
const fontBinding = Object.values(snapshot.resourceBindings).find(
|
|
6057
|
+
(b) => b.type === "font" && Boolean(b.dataUri)
|
|
6058
|
+
);
|
|
6059
|
+
if (fontBinding?.dataUri) {
|
|
6060
|
+
try {
|
|
6061
|
+
const decoded = dataUriToBytes(fontBinding.dataUri);
|
|
6062
|
+
inspectTrueTypeFont(decoded);
|
|
6063
|
+
normalFontBytes = decoded;
|
|
6064
|
+
} catch (err) {
|
|
6065
|
+
failedFonts.push({
|
|
6066
|
+
index: failedFonts.length,
|
|
6067
|
+
family: fontBinding.name,
|
|
6068
|
+
reason: err?.message || String(err)
|
|
6069
|
+
});
|
|
6070
|
+
}
|
|
5906
6071
|
}
|
|
5907
6072
|
}
|
|
5908
|
-
|
|
6073
|
+
if (normalFontBytes && normalFontBytes.byteLength > 0) {
|
|
6074
|
+
if (boldFontBytes) {
|
|
6075
|
+
try {
|
|
6076
|
+
inspectTrueTypeFont(boldFontBytes);
|
|
6077
|
+
} catch {
|
|
6078
|
+
boldFontBytes = void 0;
|
|
6079
|
+
}
|
|
6080
|
+
}
|
|
6081
|
+
return {
|
|
6082
|
+
effectiveMode: "subset-ttf",
|
|
6083
|
+
normalFontBytes,
|
|
6084
|
+
boldFontBytes,
|
|
6085
|
+
hasExplicitRenderFonts: false
|
|
6086
|
+
};
|
|
6087
|
+
}
|
|
5909
6088
|
}
|
|
5910
6089
|
const fallbackPolicy = renderCfg?.fallback ?? "error";
|
|
5911
6090
|
const detailSummary = failedFonts.length > 0 ? failedFonts.map(
|
|
5912
|
-
(e) => `#${e.index}${e.family ? ` (${e.family})` : ""}${e.url ? ` [${e.url}]` : ""}: ${e.reason}`
|
|
6091
|
+
(e) => `#${e.index}${e.family ? ` (${e.family})` : ""}${e.weight ? ` [${e.weight}]` : ""}${e.url ? ` [${e.url}]` : ""}: ${e.reason}`
|
|
5913
6092
|
).join("; ") : "\u672A\u63D0\u4F9B\u53EF\u7528\u7684 TrueType (.ttf) \u5B57\u4F53\u5B57\u8282\u6216\u5730\u5740";
|
|
5914
6093
|
if (fallbackPolicy === "raster-hd" || fallbackPolicy === "cid-vector") {
|
|
5915
6094
|
renderCfg?.onWarning?.({
|
|
@@ -5917,7 +6096,7 @@ async function resolveRenderFontsForExport(snapshot, options) {
|
|
|
5917
6096
|
message: `\u4E2D\u6587\u5B57\u4F53\u52A0\u8F7D\u5931\u8D25\uFF0C\u5DF2\u6309\u663E\u5F0F\u56DE\u9000\u7B56\u7565\u5207\u6362\u81F3 '${fallbackPolicy}'\uFF1A${detailSummary}`,
|
|
5918
6097
|
details: { fallback: fallbackPolicy, failedFonts }
|
|
5919
6098
|
});
|
|
5920
|
-
return { effectiveMode: fallbackPolicy };
|
|
6099
|
+
return { effectiveMode: fallbackPolicy, hasExplicitRenderFonts };
|
|
5921
6100
|
}
|
|
5922
6101
|
throw new PdfRenderError(
|
|
5923
6102
|
"FONT_UNAVAILABLE",
|
|
@@ -5928,8 +6107,11 @@ async function resolveRenderFontsForExport(snapshot, options) {
|
|
|
5928
6107
|
function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preResolved) {
|
|
5929
6108
|
const requested = preResolved?.effectiveMode ?? options?.render?.cjkTextMode ?? options?.cjkTextMode ?? "raster-hd";
|
|
5930
6109
|
if (requested === "raster-hd") return null;
|
|
5931
|
-
|
|
5932
|
-
|
|
6110
|
+
const hasExplicitRenderFonts = Boolean(
|
|
6111
|
+
preResolved?.hasExplicitRenderFonts ?? Array.isArray(options?.render?.fonts)
|
|
6112
|
+
);
|
|
6113
|
+
let resolvedFontBytes = preResolved ? preResolved.normalFontBytes : hasExplicitRenderFonts ? void 0 : options?.customFontBytes;
|
|
6114
|
+
if ((!resolvedFontBytes || resolvedFontBytes.byteLength === 0) && !preResolved && !hasExplicitRenderFonts && snapshot?.resourceBindings) {
|
|
5933
6115
|
const fontBinding = Object.values(snapshot.resourceBindings).find(
|
|
5934
6116
|
(b) => b.type === "font" && Boolean(b.dataUri)
|
|
5935
6117
|
);
|
|
@@ -5955,6 +6137,24 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
5955
6137
|
usedCodePoints,
|
|
5956
6138
|
"UNVPDF+SubsetTTF"
|
|
5957
6139
|
);
|
|
6140
|
+
let boldType0FontRef;
|
|
6141
|
+
let boldSubset;
|
|
6142
|
+
const boldBytes = preResolved ? preResolved.boldFontBytes : hasExplicitRenderFonts ? void 0 : options?.customBoldFontBytes;
|
|
6143
|
+
if (boldBytes && boldBytes.byteLength > 0) {
|
|
6144
|
+
if (boldBytes === resolvedFontBytes) {
|
|
6145
|
+
boldType0FontRef = type0FontRef2;
|
|
6146
|
+
boldSubset = subset;
|
|
6147
|
+
} else {
|
|
6148
|
+
const regBold = registerSubsetType0FontInDoc(
|
|
6149
|
+
pdfDoc,
|
|
6150
|
+
boldBytes,
|
|
6151
|
+
usedCodePoints,
|
|
6152
|
+
"UNVPDF+SubsetTTFBold"
|
|
6153
|
+
);
|
|
6154
|
+
boldType0FontRef = regBold.type0FontRef;
|
|
6155
|
+
boldSubset = regBold.subset;
|
|
6156
|
+
}
|
|
6157
|
+
}
|
|
5958
6158
|
const missingItems = collectMissingGlyphsFromPdfUnit(
|
|
5959
6159
|
snapshot,
|
|
5960
6160
|
(cp) => (subset.codePointToGid[cp] ?? 0) > 0,
|
|
@@ -5962,7 +6162,7 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
5962
6162
|
formatPdfTableCell
|
|
5963
6163
|
);
|
|
5964
6164
|
if (missingItems.length > 0) {
|
|
5965
|
-
const missingPolicy = options?.render?.missingGlyph ?? "warn";
|
|
6165
|
+
const missingPolicy = options?.render?.missingGlyph ?? (hasExplicitRenderFonts ? "error" : "warn");
|
|
5966
6166
|
if (missingPolicy === "error") {
|
|
5967
6167
|
const desc = missingItems.map(
|
|
5968
6168
|
(m) => `${m.pageId ? `${m.pageId}/` : ""}${m.elementId}: ${m.chars.map((c, idx) => `'${c}' (${m.codePoints[idx]})`).join(", ")}`
|
|
@@ -5985,19 +6185,6 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
5985
6185
|
}
|
|
5986
6186
|
}
|
|
5987
6187
|
}
|
|
5988
|
-
let boldType0FontRef;
|
|
5989
|
-
let boldSubset;
|
|
5990
|
-
const boldBytes = preResolved?.boldFontBytes ?? options?.customBoldFontBytes;
|
|
5991
|
-
if (boldBytes && boldBytes.byteLength > 0) {
|
|
5992
|
-
const regBold = registerSubsetType0FontInDoc(
|
|
5993
|
-
pdfDoc,
|
|
5994
|
-
boldBytes,
|
|
5995
|
-
usedCodePoints,
|
|
5996
|
-
"UNVPDF+SubsetTTFBold"
|
|
5997
|
-
);
|
|
5998
|
-
boldType0FontRef = regBold.type0FontRef;
|
|
5999
|
-
boldSubset = regBold.subset;
|
|
6000
|
-
}
|
|
6001
6188
|
return {
|
|
6002
6189
|
mode: "subset-ttf",
|
|
6003
6190
|
type0FontRef: type0FontRef2,
|
|
@@ -6006,6 +6193,9 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
6006
6193
|
...boldType0FontRef ? { boldType0FontRef, boldSubset, boldPageFontKeys: /* @__PURE__ */ new WeakMap() } : {}
|
|
6007
6194
|
};
|
|
6008
6195
|
}
|
|
6196
|
+
const usedCidCodePoints = collectUsedCodePointsFromPdfUnit(snapshot, effectiveData);
|
|
6197
|
+
const cidToUnicodeCmap = buildCidUtf16ToUnicodeCmapString(usedCidCodePoints);
|
|
6198
|
+
const cidToUnicodeRef = pdfDoc.context.register(pdfDoc.context.flateStream(cidToUnicodeCmap));
|
|
6009
6199
|
const fontDescriptorRef = pdfDoc.context.register(
|
|
6010
6200
|
pdfDoc.context.obj({
|
|
6011
6201
|
Type: "FontDescriptor",
|
|
@@ -6039,7 +6229,8 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
|
|
|
6039
6229
|
Subtype: "Type0",
|
|
6040
6230
|
BaseFont: "STSong-Light",
|
|
6041
6231
|
Encoding: "UniGB-UTF16-H",
|
|
6042
|
-
DescendantFonts: [cidFontRef]
|
|
6232
|
+
DescendantFonts: [cidFontRef],
|
|
6233
|
+
ToUnicode: cidToUnicodeRef
|
|
6043
6234
|
})
|
|
6044
6235
|
);
|
|
6045
6236
|
return {
|
|
@@ -6190,7 +6381,7 @@ function encodeVectorCjkLineHex(line, state, overrideSubset) {
|
|
|
6190
6381
|
}
|
|
6191
6382
|
return hex;
|
|
6192
6383
|
}
|
|
6193
|
-
return toUtf16BeHex(line,
|
|
6384
|
+
return toUtf16BeHex(line.replace(/\uFEFF/g, ""), false);
|
|
6194
6385
|
}
|
|
6195
6386
|
function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height, style, state, noWrapSingleLine = false, colorType, overrideCharacterSpacing) {
|
|
6196
6387
|
const wantBold = style?.fontWeight === "bold";
|
|
@@ -8237,7 +8428,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
|
|
|
8237
8428
|
options?.accessibilityTagged ?? snapshot.accessibilityTagged ?? snapshot.metadata?.accessibilityTagged
|
|
8238
8429
|
);
|
|
8239
8430
|
const optimizeSize = Boolean(options?.optimizeSize);
|
|
8240
|
-
const preResolvedFonts = await resolveRenderFontsForExport(snapshot, options);
|
|
8431
|
+
const preResolvedFonts = await resolveRenderFontsForExport(snapshot, effectiveData, options);
|
|
8241
8432
|
const pdfDoc = await import_pdf_lib3.PDFDocument.create();
|
|
8242
8433
|
if (snapshot.metadata?.sanitized) {
|
|
8243
8434
|
pdfDoc.setTitle("");
|