-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Fix issue with space offsets in TJs #6019
Conversation
var font = textState.font; | ||
var offset = (typeof previousChars === 'string' ? 0 : | ||
previousChars / 1000) || 0; |
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.
I think that you can actually simplify this expression by instead doing e.g.
var offset = (isNum(previousChars) ? previousChars / 1000 : 0);
#5813 is also (partially) touching this code, however, in a code block that you removed here. Will this PR also fix the issue mentioned there? |
It really great that you've included a reduced test-case! Since I know from first hand experiences that it's sometimes difficult to create working test-cases, I took the liberty of providing a cleaned-up version of the PDF file: https://www.dropbox.com/s/efo05mrfo1fa2k4/pr6019.pdf?dl=0. (If you use this file instead, please don't forget to update the |
textChunk.str.push(' '); | ||
} | ||
} else if (fakeSpaces > SPACE_FACTOR) { | ||
buildTextGeometry(items[j], textChunk, items[j - 1]); |
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.
When j === 0
, this will result in j - 1
being out of range of the array. As we've seen before, e.g. in #5663 (comment), that can slow things down in some browsers. Hence I'm wondering if it makes sense to try and avoid that, e.g. do this instead:
buildTextGeometry(items[j], textChunk, (j > 0 ? items[j - 1] : 0));
@timvandermeij in regards to #5813, it doesn't completely fix his issue, but they do work in concert when you just take the changes from within @Snuffleupagus what did you use to make your pdf? I only have a grasp of the obj streams well enough to screw with them. |
4e416de
to
1f8a26b
Compare
/botio test |
From: Bot.io (Linux)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/2719f1e31e43d89/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.22.172.223:8877/eb75e62f2da9bcc/output.txt |
From: Bot.io (Windows)FailedFull output at http://107.22.172.223:8877/eb75e62f2da9bcc/output.txt Total script time: 17.91 mins
Image differences available at: http://107.22.172.223:8877/eb75e62f2da9bcc/reftest-analyzer.html#web=eq.log |
From: Bot.io (Linux)FailedFull output at http://107.21.233.14:8877/2719f1e31e43d89/output.txt Total script time: 18.81 mins
Image differences available at: http://107.21.233.14:8877/2719f1e31e43d89/reftest-analyzer.html#web=eq.log |
The test results seem both good and (perhaps) less good. In e.g. |
In the vertical, if I add the offset instead of subtract it, it looks fine. But that doesn't seem to match up with the spec. I'll keep digging. |
I don't understand the |
Let's get this PR rolling again. @brendandahl Do you have any idea on how the |
Vmetrics come from DW2 array in the font dictionary. There's alot more info in 9.7.4.3 Glyph Metrics in CIDFonts, but the number you're seeing is negative is because in the PDF coordinate system the origin starts at the bottom left, so a negative moves down. |
1f8a26b
to
726beb4
Compare
Oh, it's actually possible that some of the movement, in the vertical text, seen in the earlier testing of this patch exposed an issue which has since been fixed by PR #6391. /botio test |
From: Bot.io (Linux)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/a366e510b2f5a6d/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.22.172.223:8877/35637fd01871341/output.txt |
@@ -1130,7 +1133,8 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { | |||
var offset; | |||
for (var j = 0, jj = items.length; j < jj; j++) { | |||
if (typeof items[j] === 'string') { | |||
buildTextGeometry(items[j], textChunk); | |||
buildTextGeometry(items[j], textChunk, | |||
(j > 0 ? items[j - 1] : 0)); |
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.
How about passing in null
instead when j === 0
, i.e changing it to
(j > 0 ? items[j - 1] : null)
? That way, you'll avoid a pointless division at line 958.
Also, can you please add one more space to the indentation of this line.
From: Bot.io (Windows)FailedFull output at http://107.22.172.223:8877/35637fd01871341/output.txt Total script time: 18.40 mins
Image differences available at: http://107.22.172.223:8877/35637fd01871341/reftest-analyzer.html#web=eq.log |
From: Bot.io (Linux)FailedFull output at http://107.21.233.14:8877/a366e510b2f5a6d/output.txt Total script time: 20.01 mins
Image differences available at: http://107.21.233.14:8877/a366e510b2f5a6d/reftest-analyzer.html#web=eq.log |
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/fc737bf3c7f97aa/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/fc737bf3c7f97aa/output.txt Total script time: 0.68 mins Published |
Let me know if you're ready for me to squash this. Or if there are any additional comments. |
@@ -953,8 +953,9 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { | |||
}); | |||
} | |||
|
|||
function buildTextGeometry(chars, textChunk) { | |||
function buildTextGeometry(chars, textChunk, previousChars) { |
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.
Is there a way to handle previousChar in the if below? It does not look logical handle that in two places
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.
I could handle it below, but I felt like figuring out the offset
made sense here, where as below it's just passing in the previous character. It doesn't have a concept of an offset. Though that is debatable, looking at the else
down there. I'll push another commit that changes this. There's still going to end up being a check up here to make a decision on 0
or not.
@kalley In the generated preview above and with the tracemonkey demo paper, text selection on the first paragrapher (and others) is larger than before and seems buggy. Is it normal ? |
@SamyCookie nope, that's not normal. I may need to go back to the drawing board a little after #6391. I think originally I had completely removed any offset logic from that |
2426ba7
to
85fa33c
Compare
Looks like what @SamyCookie found is fixed now, and my initial visual test of the taro-text looks correct as well. Though, there now seems to be a problem with issue6387.pdf. |
Strangely, changing the |
The broken PDF was fixed by #6588. Thanks for looking into the issue. |
We were having issues in multiple documents with spaces in a table-like text block that used TJs when selecting text.
master:
this branch:
because of the math involved in calculating the offsets in spaced text (TJ), you can't really separate out that logic into two separate operations.
Reference equation from the spec is on page 252.
I wasn't sure if just adding the pdf to the test_manifest was enough, so let me know if you need more than that.