Merge pull request #21480 from Snuffleupagus/mathML-FileSpec

A couple of small tweaks of the `StructElementNode.prototype.mathML` getter
This commit is contained in:
Jonas Jenwald 2026-06-21 23:44:28 +02:00 committed by GitHub
commit 28a7606c14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 22 deletions

View File

@ -718,8 +718,7 @@ class Page {
"_parseStructTree", "_parseStructTree",
[structTreeRoot] [structTreeRoot]
); );
const data = await this.pdfManager.ensure(structTree, "serializable"); return await this.pdfManager.ensure(structTree, "serializable");
return data;
} catch (ex) { } catch (ex) {
warn(`getStructTree: "${ex}".`); warn(`getStructTree: "${ex}".`);
return null; return null;

View File

@ -20,9 +20,10 @@ import {
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
import { Dict, isDict, isName, Name, Ref, RefSetCache } from "./primitives.js"; import { Dict, isDict, isName, Name, Ref, RefSetCache } from "./primitives.js";
import { lookupNormalRect, MissingDataException } from "./core_utils.js";
import { stringToAsciiOrUTF16BE, stringToPDFString } from "./string_utils.js"; import { stringToAsciiOrUTF16BE, stringToPDFString } from "./string_utils.js";
import { BaseStream } from "./base_stream.js"; import { BaseStream } from "./base_stream.js";
import { lookupNormalRect } from "./core_utils.js"; import { FileSpec } from "./file_spec.js";
import { NumberTree } from "./name_number_tree.js"; import { NumberTree } from "./name_number_tree.js";
const MAX_DEPTH = 40; const MAX_DEPTH = 40;
@ -594,24 +595,18 @@ class StructElementNode {
} }
for (let af of AFs) { for (let af of AFs) {
af = this.xref.fetchIfRef(af); af = this.xref.fetchIfRef(af);
if (!isDict(af, "Filespec")) { if (
!isDict(af, "Filespec") ||
!isName(af.get("AFRelationship"), "Supplement")
) {
continue; continue;
} }
if (!isName(af.get("AFRelationship"), "Supplement")) { const fileStream = FileSpec.pickPlatformItem(af.get("EF"));
continue; if (
} !(fileStream instanceof BaseStream) ||
const ef = af.get("EF"); !isDict(fileStream.dict, "EmbeddedFile") ||
if (!(ef instanceof Dict)) { !isName(fileStream.dict.get("Subtype"), "application/mathml+xml")
continue; ) {
}
const fileStream = ef.get("UF") || ef.get("F");
if (!(fileStream instanceof BaseStream)) {
continue;
}
if (!isName(fileStream.dict.get("Type"), "EmbeddedFile")) {
continue;
}
if (!isName(fileStream.dict.get("Subtype"), "application/mathml+xml")) {
continue; continue;
} }
// The default encoding for xml files is UTF-8. // The default encoding for xml files is UTF-8.
@ -909,9 +904,16 @@ class StructTreePage {
obj.alt = stringToPDFString(alt); obj.alt = stringToPDFString(alt);
} }
if (obj.role === "Formula") { if (obj.role === "Formula") {
const { mathML } = node; try {
if (mathML) { const { mathML } = node;
obj.mathML = mathML; if (mathML) {
obj.mathML = mathML;
}
} catch (ex) {
if (ex instanceof MissingDataException) {
throw ex;
}
warn(`Ignoring mathML: "${ex}".`);
} }
} }