Optional Content Groups improvements #51
Open
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.
This PR solves a number of issues around Optional Content Groups (OCGs, aka "Layers"), including those reported in Bug 707999:
2e3298b — OCMD visibility is now computed correctly for
AllOn
andAnyOff
as well asAnyOn
andAllOff
(issue 2 in the bug report above).a313d32 — I fixed a bug in the
find_ocg
function that caused it to always return0
.e3dba5c — I added functions to query and select the default OCG configuration (issue 1 in the bug report above), in particular:
void pdf_default_layer_config_info(fz_context *ctx, pdf_document *doc, pdf_layer_config *info)
fetches the name and creator of the default configuration (likepdf_layer_config_info
).void pdf_select_default_layer_config(fz_context *ctx, pdf_document *doc)
activates the default layer configuration (likepdf_select_layer_config
).Furthermore:
pdf_layer_config_info
andpdf_select_layer_config
, so that when theconfig_num
/config
argument is-1
, they act on the default configuration.mudraw.c
so thatmutool draw -y l
also lists the default configuration, andmutool draw -y d
explicitly selects the default configuration.2c2cd91 — I added the missing logic to interpret visibility expressions (
VE
entry) inOCMD
dictionaries (issue 3 in the bug report).static
functions related to this as well (ve_new_stack
,ve_stack_pop
,ve_stack_push
,ve_stack_contains
,ve_stack_free
).pdf_is_ocg_hidden_imp
and passed around to nested calls topdf_is_ve_hidden
orpdf_is_ocg_hidden_imp
.da41599 — Wherever OCG objects are being compared, I replaced
pdf_objcmp_resolve
withpdf_objcmp
(so that the references are compared rather than the contents of the dictionary).2c54b56 — The logic to deal with radio button OCG UI elements was quite broken, I fixed it.
2c54b56 — I added functions to check whether link actions are visible and to "activate" actions with subtype
SetOCGState
.int pdf_is_link_hidden(fz_context *ctx, const char *usage, fz_link* link)
checks the visibility of the OCG defined by theOC
entry of the link dictionary.int pdf_is_link_set_ocg_state(fz_link* link)
checks whether apdf_link
object represents an action with subtypeSetOCGState
or a "normal" link.void pdf_activate_link_set_ocg_state(fz_context *ctx, pdf_document *doc, fz_link *link)
activates a link that represents an action with subtypeSetOCGState
, thus enabling/disabling/toggling OCGs as specified in theState
entry of the action dictionary.mupdf-gl
andmupdf-x11
to use these new functions, so that hidden links do not react to mouse events andSetOCGState
actions do what they are supposed to do when clicking on them.Here are a few test PDFs:
OptionalContentGroups.pdf
: basic example, with three OCGs and objects whose visibility is controlled by a single OCG or a visibility expression.OptionalContentGroupsTree.pdf
: a document with an OCG UI tree with radio buttons.OptionalContentGroupsControls.pdf
: a document with "buttons" and "check boxes" to control OCG visibility (implemented asSetOCGState
actions).NoughtsCrosses.pdf
: a document with complex logic that can be used by two humans to play noughts and crosses (tic-tac-toe).