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

implementing optional content radiobutton groups #18825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agrahn
Copy link

@agrahn agrahn commented Sep 30, 2024

This PR implements OC radio button groups. It could resolve #18823.

The suggested code parses the /RBGroups entry in the optional content configuration dict and adds the property myRbGroups to instances of the OptionalContentGroup class. myRbGroups takes an array of Sets , where each Set instance represents a radio button group the OptionalContentGroup instance is a member of. Such a Set instance contains all OCG ids within the corresponding RB group. The RB groups an OCG is associated with are processed when its visibility is set to true, as required by the PDF spec.

@agrahn
Copy link
Author

agrahn commented Oct 1, 2024

@Snuffleupagus I updated the PR with your version of pdf_layer_viewer.js from master. Only two changed files remain for review :).

Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch; based on an initial look I've left a number of inline comments.

Please remember to include the information from #18825 (comment) in the commit message as well, such that the patch is easier to understand also on the Git command line.

src/core/catalog.js Outdated Show resolved Hide resolved
src/core/catalog.js Outdated Show resolved Hide resolved
src/core/catalog.js Outdated Show resolved Hide resolved
src/core/catalog.js Outdated Show resolved Hide resolved
src/core/catalog.js Outdated Show resolved Hide resolved
src/core/catalog.js Outdated Show resolved Hide resolved
src/display/optional_content_config.js Outdated Show resolved Hide resolved
@agrahn
Copy link
Author

agrahn commented Oct 2, 2024

Thank you, @Snuffleupagus, for your comments. I am going to work through all of them. Is it OK to do the code changes locally and to force-push them afterwards?

src/core/catalog.js Outdated Show resolved Hide resolved
@agrahn
Copy link
Author

agrahn commented Oct 2, 2024

Please remember to include the information from #18825 (comment) in the commit message as well, such that the patch is easier to understand also on the Git command line.

That's a lot of text. I thought a commit message should fit on a single line. But I will do so when appropriate.

@agrahn agrahn force-pushed the rbgroups branch 2 times, most recently from 7fb8170 to c0f14a0 Compare October 2, 2024 13:56
…ozilla#18823.

The code parses the /RBGroups entry in the OC configuration dict and adds the property `rbGroups' to instances of the OptionalContentGroup class. rbGroups takes an array of Sets, where each Set instance represents an RB group the OptionalContentGroup instance is a member of. Such a Set instance contains all OCG ids within the corresponding RB group. RB groups an OCG is associated with are processed when its visibility is set to true, as required by the PDF spec.
Copy link
Collaborator

@Snuffleupagus Snuffleupagus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs tests, and I'd suggest adding a couple of reference tests for this.

  • Add the PDF document that you attached in [Feature]: Optional Content Radio Button Groups #18823 (comment) to the test/pdfs/ folder, but name it issue18823.pdf.
  • Run node test/add_test.mjs test/pdfs/issue18823.pdf in the root of your local PDF.js Git-clone.
  • Open the test/test_manifest.json file and find the newly added test-case. Here we also want to add another test-case for a non-default optionalContent-state.

To make this process slightly less daunting I've done these steps in the following diff, which you're obviously welcome to copy and include as-is in your patch: master...Snuffleupagus:pdf.js:issue-18823-test

Comment on lines +646 to +647
// Parse RBGroups entry.
(rbGroups => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we define this as a separate function similar to the other existing helpers, and just invoke it directly below, rather than using an IIFE here?

Suggested change
// Parse RBGroups entry.
(rbGroups => {
parseRBGroups(rbGroups) {

// Parse RBGroups entry.
(rbGroups => {
if (!Array.isArray(rbGroups)) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't need to return anything.

Suggested change
return null;
return;

Comment on lines +657 to +658

const parsedRbGroup = new Set();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
const parsedRbGroup = new Set();
const parsedRbGroups = new Set();

Comment on lines +668 to +669

return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this function shouldn't need to return anything.

Suggested change
return null;

Comment on lines +240 to +241
// If my visibility is about to be set to `true' and if I belong to one or
// more radiobutton groups, hide all other OCGs in these radiobutton groups,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd suggest re-wording this slightly to remove my/I usage, and also let's fix the quoting around true.

Suggested change
// If my visibility is about to be set to `true' and if I belong to one or
// more radiobutton groups, hide all other OCGs in these radiobutton groups,
// If the visibility is about to be set to `true` and the group belongs to
// any radiobutton groups, hide all other OCGs in these radiobutton groups,

// If my visibility is about to be set to `true' and if I belong to one or
// more radiobutton groups, hide all other OCGs in these radiobutton groups,
// provided that radiobutton state relationships are to be preserved.
if (visible && preserveRB && group.rbGroups.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do the preserveRB check first, since without that nothing else matters here.

Suggested change
if (visible && preserveRB && group.rbGroups.length) {
if (preserveRB && visible && group.rbGroups.length) {

// more radiobutton groups, hide all other OCGs in these radiobutton groups,
// provided that radiobutton state relationships are to be preserved.
if (visible && preserveRB && group.rbGroups.length) {
for (const rbGrp of group.rbGroups) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const rbGrp of group.rbGroups) {
for (const rbGroup of group.rbGroups) {

for (const rbGrp of group.rbGroups) {
for (const otherId of rbGrp) {
if (otherId !== id) {
this.#groups.get(otherId)._setVisible(INTERNAL, false, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For added safety, to prevent any future errors here.

Suggested change
this.#groups.get(otherId)._setVisible(INTERNAL, false, true);
this.#groups.get(otherId)?._setVisible(INTERNAL, false, true);

}

return null;
})(config.get("RBGroups"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the IIFE, this become.

Suggested change
})(config.get("RBGroups"));
}
parseRBGroups(config.get("RBGroups"));

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

Successfully merging this pull request may close these issues.

[Feature]: Optional Content Radio Button Groups
2 participants