Skip to content

Text widget annotations: implement comb support #7649

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

Merged
merged 2 commits into from
Sep 22, 2016

Conversation

timvandermeij
Copy link
Contributor

@timvandermeij timvandermeij commented Sep 19, 2016

This is another part of #7613.

@@ -715,6 +715,8 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
// Process field flags for the display layer.
this.data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) &&
this.data.maxLen !== null && !this.data.multiLine;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that you're missing a number of field checks here, please see the specification text:

(PDF 1.5) May be set only if the MaxLen entry is present in the text field dictionary (see Table 229) and _if the Multiline, Password, and FileSelect flags are clear_. If set, the field shall be automatically divided into as many equally spaced positions, or combs, as the value of MaxLen, and the text is laid out into those combs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I thought we didn't need it because we do not support the Password and FileSelect flags anyway, but it makes sense to add these checks anyway to prevent any issues. I'll update the patch.

@@ -77,6 +77,22 @@
border: 1px solid transparent;
}

.annotationLayer .textWidgetAnnotation input.comb {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't you want to add these rules to the corresponding file in /test as well, to enable testing of comb fields once we have better tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll do that.

@timvandermeij timvandermeij force-pushed the interactive-forms-tx-comb branch from 90a2107 to 5b1f510 Compare September 20, 2016 19:43
@timvandermeij
Copy link
Contributor Author

I have addressed the comments and managed to adjust the reference test for text widget annotations to include a field that uses combs.

@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/434cf638d7a1547/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/434cf638d7a1547/output.txt

Total script time: 1.02 mins

Published

@timvandermeij
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/7de759130fe7a06/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/ad6cc3caae12396/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/ad6cc3caae12396/output.txt

Total script time: 24.78 mins

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

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

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/7de759130fe7a06/output.txt

Total script time: 29.39 mins

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

Image differences available at: http://107.21.233.14:8877/7de759130fe7a06/reftest-analyzer.html#web=eq.log

@timvandermeij timvandermeij force-pushed the interactive-forms-tx-comb branch from 5b1f510 to 6100ab4 Compare September 20, 2016 20:34
@timvandermeij
Copy link
Contributor Author

I pushed a new commit to fix an issue in the a unit test. No other changes have been made.

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/d258015cb323cbb/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/913c5d457a4bf41/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/d258015cb323cbb/output.txt

Total script time: 1.72 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/913c5d457a4bf41/output.txt

Total script time: 2.08 mins

  • Unit Tests: Passed

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.

Looks mostly fine, but I think that the format of AnnotationFieldFlag is making things more difficult to follow. Please see inline comments.

});

it('should set valid text alignment, maximum length and flags',
function() {
var flags = 0;
flags |= 1 << (AnnotationFieldFlag.READONLY - 1);
flags |= 1 << (AnnotationFieldFlag.MULTILINE - 1);
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Sep 21, 2016

Choose a reason for hiding this comment

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

As far as I'm concerted, the current way that the AnnotationFieldFlag are defined makes the unit-tests unnecessarily convoluted and difficult to understand.

What would be a lot clearer is if you changed AnnotationFieldFlag to the same form as AnnotationFlag, since that means you could change the hasFieldFlags method in src/core/annotation.js to just:

return !!(this.data.fieldFlags & flag);

and specifying the flags in the unit-tests would be so much more straightforward:

var flags = AnnotationFieldFlag.READONLY + AnnotationFieldFlag.MULTILINE;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really good point. I'll definitely look into that.

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 pushed a new commit that fixes this.

* area, causing horizontal scrolling. We avoid this by extending the width
* when the element has focus and revert this when it loses focus.
*/
width: 115%;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's unfortunate that this sort of hack is necessary, but I'm also not able to come up with a better solution :-(

Copy link
Contributor Author

@timvandermeij timvandermeij Sep 21, 2016

Choose a reason for hiding this comment

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

I agree, but after searching for a couple of hours there really isn't another way with CSS only. The real problem is that letter spacing is always applied on the right side of a character, whereas we would want to tune that or turn it off for the last character. Since that's not possible, we need this workaround. There are JS-based solutions, but they are even uglier and require much more code, so this is the cleanest solution IMO.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just want to make it absolutely clear that I didn't mean to complain about your solution here, but rather about the (missing) features of the web platform that made the workaround necessary!

expect(textWidgetAnnotation.data.comb).toEqual(true);
});

it('should only accept comb fields when the flags are valid', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be possible to simplify this particular test a bit, so I'd like to see an updated version based on the AnnotationFieldFlag comment above.

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'll try that. I'm not sure how much simpler it will become though as we still need the loops to remove the flags one-by-one, but we'll see.

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 pushed a new commit that fixes this.

Directly use the hexadecimal representation, just like the
`AnnotationFlags`, to avoid calculations and to improve readability.
This allows us to simplify the unit tests for text widget annotations as
well.
@timvandermeij timvandermeij force-pushed the interactive-forms-tx-comb branch from d38d0f8 to 375229d Compare September 21, 2016 19:15
@timvandermeij
Copy link
Contributor Author

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/6ed923ea3044355/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/6ed923ea3044355/output.txt

Total script time: 1.00 mins

Published

@timvandermeij
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/48fa394f3e9134e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/ac30c3c5b18469c/output.txt

@pdfjsbot
Copy link

From: Bot.io (Windows)


Failed

Full output at http://107.22.172.223:8877/48fa394f3e9134e/output.txt

Total script time: 24.63 mins

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

Image differences available at: http://107.22.172.223:8877/48fa394f3e9134e/reftest-analyzer.html#web=eq.log

@pdfjsbot
Copy link

From: Bot.io (Linux)


Failed

Full output at http://107.21.233.14:8877/ac30c3c5b18469c/output.txt

Total script time: 29.08 mins

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

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

@Snuffleupagus
Copy link
Collaborator

Much better, thank you! With the changes to AnnotationFieldFlags, the code and especially the unit-tests are now much simpler to deal with.

/botio makeref

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.22.172.223:8877/6841f4c21ab4c77/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

Command cmd_makeref from @Snuffleupagus received. Current queue size: 0

Live output at: http://107.21.233.14:8877/81cb41574c520d9/output.txt

@Snuffleupagus Snuffleupagus merged commit 6c263c1 into mozilla:master Sep 22, 2016
@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/6841f4c21ab4c77/output.txt

Total script time: 24.88 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/81cb41574c520d9/output.txt

Total script time: 28.37 mins

  • Lint: Passed
  • Make references: Passed
  • Check references: Passed

@timvandermeij timvandermeij deleted the interactive-forms-tx-comb branch September 22, 2016 20:18
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
…tx-comb

Text widget annotations: implement comb support
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.

3 participants