-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Support comb textfields for printing #12177
Conversation
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.
Looks good with these comments addressed. (I only checked the last commit for this PR since the rest is in other PRs.)
@@ -987,6 +987,22 @@ class WidgetAnnotation extends Annotation { | |||
const vPadding = defaultPadding + Math.abs(descent) * fontSize; | |||
const defaultAppearance = this.data.defaultAppearance; | |||
|
|||
if (this.data.comb) { |
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.
Since comb
is a specific property of text widget annotations (and not other widget annotations), this code should live in the TextWidgetAnnotation
class instead.
src/core/annotation.js
Outdated
let first = true; | ||
for (const character of value) { | ||
if (first) { | ||
buf += ` (${character}) Tj`; |
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.
To reduce the number of intermediate strings being created, we normally don't append strings to strings. Instead, we push all strings to an array and join them at the end, which is a bit more efficient. Can we do that here as well? Look at
Lines 113 to 131 in 50bc4a1
const romanBuf = []; | |
let pos; | |
// Thousands | |
while (number >= 1000) { | |
number -= 1000; | |
romanBuf.push("M"); | |
} | |
// Hundreds | |
pos = (number / 100) | 0; | |
number %= 100; | |
romanBuf.push(ROMAN_NUMBER_MAP[pos]); | |
// Tens | |
pos = (number / 10) | 0; | |
number %= 10; | |
romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]); | |
// Ones | |
romanBuf.push(ROMAN_NUMBER_MAP[20 + number]); | |
const romanStr = romanBuf.join(""); |
Moreover, this will also fix the line let buf = ...
above since that is longer than the 80 character limit. If we split that large string into two strings we can simply push those into the array so it fits with the character limit again (I'm surprised ESLint doesn't complain about this already...).
test/unit/annotation_spec.js
Outdated
}, done.fail) | ||
.then(appearance => { | ||
expect(appearance).toEqual( | ||
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 2 2 Tm (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj 8.00 0 Td (a) Tj ET Q EMC" |
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 line also exceeds the 80 character limit. Please split it up by concatenating smaller substrings.
src/core/annotation.js
Outdated
@@ -987,6 +987,22 @@ class WidgetAnnotation extends Annotation { | |||
const vPadding = defaultPadding + Math.abs(descent) * fontSize; | |||
const defaultAppearance = this.data.defaultAppearance; | |||
|
|||
if (this.data.comb) { | |||
const combWidth = (totalWidth / this.data.maxLen).toFixed(2); |
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.
To prevent this method from being too big, I would suggest to move the comb handling code to a private method named _getCombAppearance
similar to what you did for the multiline strings.
fa8fd5a
to
06b0c71
Compare
/botio-linux preview |
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/d16429acffb4e81/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/d16429acffb4e81/output.txt Total script time: 3.48 mins Published |
The combs work fine, it's only the multiline text fields that don't work. For completeness I'm attaching the document where the comb is rendered, but the multiline is not: |
This requires a rebase after the multiline text PR. |
/botio-linux preview |
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 1 Live output at: http://54.67.70.0:8877/8be6a46f4f79845/output.txt |
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 2 Live output at: http://54.67.70.0:8877/6d6248273243b79/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 1 Live output at: http://54.215.176.217:8877/2ccc06a49e28fae/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/8be6a46f4f79845/output.txt Total script time: 3.37 mins Published |
From: Bot.io (Linux m4)FailedFull output at http://54.67.70.0:8877/6d6248273243b79/output.txt Total script time: 27.16 mins
Image differences available at: http://54.67.70.0:8877/6d6248273243b79/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.215.176.217:8877/2ccc06a49e28fae/output.txt Total script time: 30.07 mins
Image differences available at: http://54.215.176.217:8877/2ccc06a49e28fae/reftest-analyzer.html#web=eq.log |
Nice work! |
No description provided.