Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Content Groups improvements #51

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

arklumpus
Copy link

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 and AnyOff as well as AnyOn and AllOff (issue 2 in the bug report above).

  • a313d32 — I fixed a bug in the find_ocg function that caused it to always return 0.

  • 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 (like pdf_layer_config_info).
    • void pdf_select_default_layer_config(fz_context *ctx, pdf_document *doc) activates the default layer configuration (like pdf_select_layer_config).

    Furthermore:

    • I modified pdf_layer_config_info and pdf_select_layer_config, so that when the config_num/config argument is -1, they act on the default configuration.
    • I modified mudraw.c so that mutool draw -y l also lists the default configuration, and mutool draw -y d explicitly selects the default configuration.
  • 2c2cd91 — I added the missing logic to interpret visibility expressions (VE entry) in OCMD dictionaries (issue 3 in the bug report).

    • This uses a stack to detect circular references, so there a few new static functions related to this as well (ve_new_stack, ve_stack_pop, ve_stack_push, ve_stack_contains, ve_stack_free).
    • If necessary, the stack is initialised in pdf_is_ocg_hidden_imp and passed around to nested calls to pdf_is_ve_hidden or pdf_is_ocg_hidden_imp.
  • da41599 — Wherever OCG objects are being compared, I replaced pdf_objcmp_resolve with pdf_objcmp (so that the references are compared rather than the contents of the dictionary).

    • This solves issues occurring with PDF files where multiple OCGs are defined with the same name (which are allowed by the spec).
    • Essentially, this extends the fix for Bug 702261 to other instances where OCGs are compared, thus also fixing Bug 707992.
  • 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 the OC entry of the link dictionary.
    • int pdf_is_link_set_ocg_state(fz_link* link) checks whether a pdf_link object represents an action with subtype SetOCGState 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 subtype SetOCGState, thus enabling/disabling/toggling OCGs as specified in the State entry of the action dictionary.
    • I modified mupdf-gl and mupdf-x11 to use these new functions, so that hidden links do not react to mouse events and SetOCGState actions do what they are supposed to do when clicking on them.

Here are a few test PDFs:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant