-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
base: master
Are you sure you want to change the base?
Conversation
@Snuffleupagus I updated the PR with your version of |
There was a problem hiding this 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.
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? |
That's a lot of text. I thought a commit message should fit on a single line. But I will do so when appropriate. |
7fb8170
to
c0f14a0
Compare
…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.
There was a problem hiding this 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 itissue18823.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
// Parse RBGroups entry. | ||
(rbGroups => { |
There was a problem hiding this comment.
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?
// Parse RBGroups entry. | |
(rbGroups => { | |
parseRBGroups(rbGroups) { |
// Parse RBGroups entry. | ||
(rbGroups => { | ||
if (!Array.isArray(rbGroups)) { | ||
return null; |
There was a problem hiding this comment.
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.
return null; | |
return; |
|
||
const parsedRbGroup = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
const parsedRbGroup = new Set(); | |
const parsedRbGroups = new Set(); |
|
||
return null; |
There was a problem hiding this comment.
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.
return null; |
// 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, |
There was a problem hiding this comment.
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.
// 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) { |
There was a problem hiding this comment.
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.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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.
this.#groups.get(otherId)._setVisible(INTERNAL, false, true); | |
this.#groups.get(otherId)?._setVisible(INTERNAL, false, true); |
} | ||
|
||
return null; | ||
})(config.get("RBGroups")); |
There was a problem hiding this comment.
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.
})(config.get("RBGroups")); | |
} | |
parseRBGroups(config.get("RBGroups")); |
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 propertymyRbGroups
to instances of theOptionalContentGroup
class.myRbGroups
takes an array ofSet
s , where eachSet
instance represents a radio button group theOptionalContentGroup
instance is a member of. Such aSet
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 totrue
, as required by the PDF spec.