({
newAnnotationsByPage,
structTreeRootRef,
structTreeRoot,
kids,
nums,
xref,
pdfManager,
newRefs,
cache
})
| 41767 | } |
| 41768 | } |
| 41769 | static async #writeKids({ |
| 41770 | newAnnotationsByPage, |
| 41771 | structTreeRootRef, |
| 41772 | structTreeRoot, |
| 41773 | kids, |
| 41774 | nums, |
| 41775 | xref, |
| 41776 | pdfManager, |
| 41777 | newRefs, |
| 41778 | cache |
| 41779 | }) { |
| 41780 | const objr = Name.get("OBJR"); |
| 41781 | let nextKey = -1; |
| 41782 | let structTreePageObjs; |
| 41783 | const buffer = []; |
| 41784 | for (const [pageIndex, elements] of newAnnotationsByPage) { |
| 41785 | const page = await pdfManager.getPage(pageIndex); |
| 41786 | const { |
| 41787 | ref: pageRef |
| 41788 | } = page; |
| 41789 | const isPageRef = pageRef instanceof Ref; |
| 41790 | for (const { |
| 41791 | accessibilityData, |
| 41792 | ref, |
| 41793 | parentTreeId, |
| 41794 | structTreeParent |
| 41795 | } of elements) { |
| 41796 | if (!accessibilityData?.type) { |
| 41797 | continue; |
| 41798 | } |
| 41799 | const { |
| 41800 | structParent |
| 41801 | } = accessibilityData; |
| 41802 | if (structTreeRoot && Number.isInteger(structParent) && structParent >= 0) { |
| 41803 | let objs = (structTreePageObjs ||= new Map()).get(pageIndex); |
| 41804 | if (objs === undefined) { |
| 41805 | const structTreePage = new StructTreePage(structTreeRoot, page.pageDict); |
| 41806 | objs = structTreePage.collectObjects(pageRef); |
| 41807 | structTreePageObjs.set(pageIndex, objs); |
| 41808 | } |
| 41809 | const objRef = objs?.get(structParent); |
| 41810 | if (objRef) { |
| 41811 | const tagDict = xref.fetch(objRef).clone(); |
| 41812 | StructTreeRoot.#writeProperties(tagDict, accessibilityData); |
| 41813 | buffer.length = 0; |
| 41814 | await writeObject(objRef, tagDict, buffer, xref); |
| 41815 | newRefs.push({ |
| 41816 | ref: objRef, |
| 41817 | data: buffer.join("") |
| 41818 | }); |
| 41819 | continue; |
| 41820 | } |
| 41821 | } |
| 41822 | nextKey = Math.max(nextKey, parentTreeId); |
| 41823 | const tagRef = xref.getNewTemporaryRef(); |
| 41824 | const tagDict = new Dict(xref); |
| 41825 | StructTreeRoot.#writeProperties(tagDict, accessibilityData); |
| 41826 | await this.#updateParentTag({ |
no test coverage detected