Repository navigation
Read and write an annotation's alt text in the structure tree - #119
Open
KleiKodesh wants to merge 5 commits into
Open
KleiKodesh wants to merge 5 commits into
KleiKodesh wants to merge 5 commits into
Conversation
PDF.js writes a stamp's alternate description into the structure tree: a /Figure element with /Alt and an object reference to the stamp, the stamp's /StructParent, and a parent tree entry. There was no way to write that, so an engine saving PDF.js-style alt text had nowhere to put it. - EPDFAnnot_GetAltText() reads the /Alt of the element that lists the annotation, found through its /StructParent. - EPDFAnnot_SetAltText() writes it there. An annotation not yet in the tree gets a new /Figure element (under the tree's /Document element when that is the root's one kid), a /StructParent at the next parent tree key, and the catalog's /StructTreeRoot and /ParentTree when they are missing. An empty text removes the /Alt. A parent tree with /Kids is refused: only a flat /Nums is written. Writes go through the document, so in a layer they promote exactly the objects they change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PDF.js keeps a stamp's alternate description in the structure tree, not in the annotation: a
/Figureelement with/Altand an/OBJRto the stamp, the stamp's/StructParent, and a parent tree entry. An engine that wants to save alt text the way PDF.js reads it back had no API to write that.New functions in
epdf_annot.h:EPDFAnnot_GetAltText(annot, buffer, buflen)reads the/Altof the structure element that lists the annotation, found through its/StructParentand the parent tree (the same walkEPDFAnnot_GetStructurePosition()makes).EPDFAnnot_SetAltText(annot, alt)writes it:/Alt(an empty or NULL text removes it);/Figureelement (/P,/Pg,/Alt,/K= the/OBJR), appended to the tree's/Documentelement when the root's one kid is one, else to the root; the annotation gets/StructParent= the next parent tree key (/ParentTreeNextKey, past every key in use), and the parent tree's/Numsgets the entry in key order;/StructTreeRootand its/ParentTreeare created when missing;/Kids(only a flat/Numsis written), or a structure root or parent tree that isn't a dictionary.Every write to an existing object goes through
GetMutableIndirectObject()/GetMutableRoot(), so in a layer it promotes exactly the objects it changes.Tests
EPDFAnnotEmbedderTest.AltTextRoundTripsThroughTheStructureTree: two annotations get alt text on a document without a structure tree, read back, sit at root kids 0 and 1, a second write rewrites the element in place, and NULL removes it.epdf_c_api_test.clists the two new exports.