Skip to content

Annotation - Use border and background colors from MK dictionary #13006

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

Closed
wants to merge 1 commit into from

Conversation

calixteman
Copy link
Contributor

@calixteman
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.67.70.0:8877/51ac9b765ebaba0/output.txt

@calixteman
Copy link
Contributor Author

/botio-windows test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://3.101.106.178:8877/1aef28a4ddcac8d/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/51ac9b765ebaba0/output.txt

Total script time: 23.72 mins

  • Font tests: Passed
  • Unit tests: FAILED
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/51ac9b765ebaba0/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/1aef28a4ddcac8d/output.txt

Total script time: 29.69 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://3.101.106.178:8877/1aef28a4ddcac8d/reftest-analyzer.html#web=eq.log

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/a72984ad6b77272/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/a72984ad6b77272/output.txt

Total script time: 4.13 mins

Published

@timvandermeij
Copy link
Contributor

timvandermeij commented Feb 21, 2021

This PR needs a rebase. I'm also not really sure what to make of some of the reference test failures, mainly firefox-issue12716-page1. Does it also render like that in Adobe Reader/Acrobat, i.e., that only some checkboxes are now white but not all of them?

@calixteman
Copy link
Contributor Author

I played with acrobat DC and the background color is used when the widget has the focus.
When unfocused, an opaque (blue/violet) is used when the bg color is opaque and a transparent (still blue/violet) one when the bg color is transparent.

@calixteman calixteman force-pushed the 13003 branch 2 times, most recently from f576b14 to c7abd6d Compare February 21, 2021 17:41
@calixteman
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.67.70.0:8877/da935e061bd2bac/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://3.101.106.178:8877/293f14d24d00886/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/da935e061bd2bac/output.txt

Total script time: 23.84 mins

  • Font tests: Passed
  • Unit tests: FAILED
  • Integration Tests: FAILED
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/da935e061bd2bac/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/293f14d24d00886/output.txt

Total script time: 29.79 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://3.101.106.178:8877/293f14d24d00886/reftest-analyzer.html#web=eq.log

@Snuffleupagus
Copy link
Collaborator

Sorry to step in here, but that last version of this patch feels somewhat unfortunate in general, since:

  • It moves appearance from the CSS files and into the JS files, which is less maintainable.
  • It requires no less than two event listeners per element, just to manage the colours correctly.

I suppose that it might make sense to take a step back and consider how other PDF viewers (e.g. Adobe Reader and PDFium) handles fillable fields in general, since it seems that they don't necessarily always outline all fields the way that we currently do (and it rather seem to depend on the PDF file itself)!?

@calixteman
Copy link
Contributor Author

In either acrobat dc or pdfium, the bg color of an unfocused rendered input has alpha or not depending if bg color of the annotation has alpha. So I don't see how avoid to have default colors in js instead of css, please tell me if it's possible. Your point is fair and I tried to figure out a solution to avoid that but I didn't manage to.
About listeners, I agree too but I don't see how to do differently: any good ideas are welcome.
Anyway I can remove listeners and remove the color in js but then as pointed by Tim the rendering is different from what we've in Acrobat: some annotations are blue and some others are not.

@brendandahl
Copy link
Contributor

Not sure if this is really better, but we could leave defaults in css and use getComputedStyle. @Snuffleupagus any thoughts on a better way to do this?

@Snuffleupagus
Copy link
Collaborator

When looking at how e.g. Adobe Reader handles forms, it seems (at least to me) that things like e.g. the background of form fields are generally controlled by the PDF document itself rather than the viewer.

Hence my suggestion would be that we could perhaps simplify things overall by doing that in PDF.js as well, and stop setting e.g. a default background-color (in web/annotation_layer_builder.css or elsewhere) and instead defer that to the PDF document!?

@calixteman
Copy link
Contributor Author

For me the "blue" background is just added by the reader to indicate that there is a fillable form element so I think it's useful for the user.
@timvandermeij what do you think ?

@Snuffleupagus
Copy link
Collaborator

How about the following compromise, then:

  • Leave the default styling in the CSS, as before.
  • Let PDF documents with field colours, set in /MK dictionaries, simply override the defaults when present.

That should hopefully reduce the overall complexity somewhat here, and also guarantee that PDF documents renders as intended (by the document author).

@timvandermeij
Copy link
Contributor

I'll have a look at this once it's rebased, since then the patch will be simpler as all color function related changes have already been made in the square/circle annotation PR that was just merged, and with the comment above implemented.

@calixteman
Copy link
Contributor Author

How about the following compromise, then:

* Leave the _default styling_ in the CSS, as before.

* Let PDF documents with field colours, set in /MK dictionaries, simply _override_ the defaults when present.

That should hopefully reduce the overall complexity somewhat here, and also guarantee that PDF documents renders as intended (by the document author).

Ok so if I understand correctly:

  • no bg color in MK: use "blue" one when unfocused and white when focused (current behaviour)
  • else: use the color as bg when unfocused and focused.

But if bg color is white or transparent and there is no border, there is no way for the user that there is something modifiable.
And we'll probably have the same issue as pointed by @timvandermeij: #13006 (comment).

My goal was to have exactly the same behaviour as in either Acrobat or chrome.

*/
setBorderAndBackgroundColors(mk) {
if (mk instanceof Dict) {
this.borderColor = getRgbColor(mk.getArray("BC"), undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

Transparent is indicated by null instead of undefined as indicated on line 202.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find in the spec what's the default color (transparent or whatever), so undefined stands for "use HTML default".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wait, does that mean that we now use both undefined and null, but they have very slightly different meaning in the display-layer?
If so, that sounds like a recipe for confusion...

@@ -976,6 +1016,15 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
);
}

this._setBorderAndBackgroundColors(element);

const { fontColor } = this.data.defaultAppearanceData;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary only here and not elsewhere? Moreover, checkbox widgets don't contain text AFAIK, so what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checkboxes contains text for the on state: most of the time one char using ZapfDingbats font.

@Snuffleupagus
Copy link
Collaborator

But if bg color is white or transparent and there is no border, there is no way for the user that there is something modifiable.

In that case the PDF document itself is responsible for that behaviour, so I don't really see this as a big problem.
Hence my suggestion above to not mess with "default" colours in the JS files, to avoid e.g. the focus/blur event listeners.

My goal was to have exactly the same behaviour as in either Acrobat or chrome.

Of course I understand that, but there's something to be said for simplicity of the overall implementation as well (in my opinion).

@calixteman
Copy link
Contributor Author

But if bg color is white or transparent and there is no border, there is no way for the user that there is something modifiable.

In that case the PDF document itself is responsible for that behaviour, so I don't really see this as a big problem.

Yes you're right.
But when a form has been created and tested with Acrobat, some creators saw the blue background and so maybe for this reason they didn't set a background and/or border.
I've the impress (maybe I'm wrong) that removing this blue bg can diminish the quality of the user xp.
I really understand your concern and I don't want to bikeshed but I'm really not sure it's good for the user.

Hence my suggestion above to not mess with "default" colours in the JS files, to avoid e.g. the focus/blur event listeners.

My goal was to have exactly the same behaviour as in either Acrobat or chrome.

Of course I understand that, but there's something to be said for simplicity of the overall implementation as well (in my opinion).

@Snuffleupagus
Copy link
Collaborator

But when a form has been created and tested with Acrobat, some creators saw the blue background and so maybe for this reason they didn't set a background and/or border.

Please keep in mind that the "default" blue background, in Adobe Reader, mentioned is actually a setting which can be toggled on/off in the options (and that the particular colour used is also customizable); hence I'm not entirely convinced by this argument.

I'm mostly worried about readability/maintainability of the solution, especially since these types of changes feel like they have the potential to require additional fixes later on for various edge-cases in "weird" PDF documents.
(Since especially for Annotations it seems that many PDF generators aren't really following the specification all that well.)

 - aims to fix mozilla#13003;
 - pass the colors to js sandbox;
 - fix checkbox color.
@calixteman
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Mar 6, 2021

From: Bot.io (Linux m4)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.67.70.0:8877/e1f2f4022f08ef5/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Mar 6, 2021

From: Bot.io (Windows)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://3.101.106.178:8877/2c0e3b29e6a2f95/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Mar 6, 2021

From: Bot.io (Linux m4)


Failed

Full output at http://54.67.70.0:8877/e1f2f4022f08ef5/output.txt

Total script time: 25.56 mins

  • Font tests: Passed
  • Unit tests: FAILED
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://54.67.70.0:8877/e1f2f4022f08ef5/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

pdfjsbot commented Mar 6, 2021

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/2c0e3b29e6a2f95/output.txt

Total script time: 30.66 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED

Image differences available at: http://3.101.106.178:8877/2c0e3b29e6a2f95/reftest-analyzer.html#web=eq.log

@calixteman
Copy link
Contributor Author

I'm closing this PR and I'll open a new one.

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

Successfully merging this pull request may close these issues.

PDF rendering problem: Checkboxes have black background
5 participants