-
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
[editor] Add an Ink editor #14989
[editor] Add an Ink editor #14989
Conversation
web/images/toolbarButton-inkMode.svg
Outdated
@@ -0,0 +1,9 @@ | |||
<?xml version='1.0' encoding='utf-8'?> |
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.
Duplicate file, please remove it.
src/display/editor/bezier_approx.js
Outdated
@@ -0,0 +1,677 @@ | |||
/** |
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.
First of all, that's a lot of code needed to support adding of Ink Annotations.
Secondly, it looks like this is available through NPM so can we please use that instead of "dumping" this code into the PDF.js repository (since that's not very maintainable)?
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.
First of all, that's a lot of code needed to support adding of Ink Annotations.
Yes it is but it helps to make the drawing nicer and it helps to reduce the size of the final InkList
when the annotation is saved.
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.
Do you have an example on how to use a node package in pdf.js ?
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.
Just including a Node.js package in a build is trivial, but that unfortunately doesn't take the gulp server
mode into account. However that should be possible to solve, but it's possibly non-trivial to implement; note e.g. the following development-specific build tasks.
In order to be able to move forward with this PR a bit more quickly, I'd accept that we temporarily add this code to the PDF.js library assuming the following:
- The new file is placed in its own directory in https://github.com/mozilla/pdf.js/tree/master/external/, and not inside of the
src/
-folder. - The commented-out code in the file is removed, since it seems unnecessary to include that.
- The automated comment in [editor] Add an Ink editor #14989 (review) is fixed.
- An issue is opened, which tracks removing that and using the npm package instead.
web/viewer.html
Outdated
@@ -270,6 +270,9 @@ | |||
<button id="editorFreeText" class="toolbarButton" title="Add FreeText Annotation" role="radio" aria-checked="false" tabindex="32" data-l10n-id="editor_free_text"> | |||
<span data-l10n-id="editor_free_text_label">FreeText Annotation</span> | |||
</button> | |||
<button id="editorInk" class="toolbarButton" title="Add Ink Annotation" role="radio" aria-checked="false" tabindex="32" data-l10n-id="editor_ink"> |
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.
Please fix the duplicated tabindex
.
src/display/editor/ink.js
Outdated
// https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm | ||
|
||
// The first point is the last point of the previous Bezier curve | ||
// so no need to push the firt point. |
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.
firt
-> first
1ff2d70
to
c2b66dd
Compare
It looks like Line 1547 in 2fbf14a
|
I added |
I suppose that you can temporarily move it back its original position, in the |
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/cfa5839bc6b302c/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/fc0148520bfe7e2/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/cfa5839bc6b302c/output.txt Total script time: 26.15 mins
Image differences available at: http://54.241.84.105:8877/cfa5839bc6b302c/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/fc0148520bfe7e2/output.txt Total script time: 28.90 mins
Image differences available at: http://54.193.163.58:8877/fc0148520bfe7e2/reftest-analyzer.html#web=eq.log |
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.
r=me, with comments addressed; thank you!
src/display/editor/ink.js
Outdated
// At some point this editor has been removed and | ||
// we're rebuilting it, hence we must add it to its | ||
// parent. |
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.
Spelling, grammar, and line-breaking nits:
// At some point this editor has been removed and | |
// we're rebuilting it, hence we must add it to its | |
// parent. | |
// At some point this editor was removed and we're rebuilding it, | |
// hence we must add it to its parent. |
super.remove(); | ||
|
||
// Destroy the canvas. | ||
this.canvas.width = this.canvas.heigth = 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.
Do you also want to set this.canvas = null;
to remove it completely?
src/display/editor/ink.js
Outdated
this.div.classList.add("editing"); | ||
|
||
if (this.width) { | ||
// This editor has been created in using copy (ctrl+c). |
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.
Grammar nits:
// This editor has been created in using copy (ctrl+c). | |
// This editor was created by copying (ctrl+c). |
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.
Also, please update the two similar sentences in https://github.com/mozilla/pdf.js/blob/master/src/display/editor/freetext.js while you're at it (I missed those previously).
src/display/editor/ink.js
Outdated
this.setDimensions(rect.width, rect.height); | ||
} | ||
}); | ||
observer.observe(this.div); |
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 the observer
removed automatically when the current InkEditor
-instance is removed, or do we (somehow) need to do that manually?
src/display/editor/ink.js
Outdated
this.#redraw(); | ||
} | ||
|
||
const observer = new ResizeObserver(entries => { |
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 does not require any changes here, however:
According to https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver#browser_compatibility, this isn't available in all Safari versions that we currently "support".
Given first of all that this isn't even enabled by default and secondly that our Safari-support is listed as partial, this isn't a big issue as far as I'm concerned.
Hence I'd suggest that we just add the following code:
diff --git a/web/app_options.js b/web/app_options.js
index 243aa9e11..d75277c56 100644
--- a/web/app_options.js
+++ b/web/app_options.js
@@ -38,6 +38,12 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
compatibilityParams.maxCanvasPixels = 5242880;
}
})();
+
+ (function checkResizeObserver() {
+ if (typeof ResizeObserver === "undefined") {
+ compatibilityParams.annotationEditorEnabled = false;
+ }
+ })();
}
const OptionKind = {
@@ -309,6 +315,9 @@ if (
kind: OptionKind.VIEWER,
};
+ defaultOptions.annotationEditorEnabled.compatibility =
+ compatibilityParams.annotationEditorEnabled;
+
defaultOptions.renderer.kind += OptionKind.PREFERENCE;
} else if (PDFJSDev.test("CHROME")) {
defaultOptions.disableTelemetry = {
- Approximate the drawn curve by a set of Bezier curves in using js code from https://github.com/soswow/fit-curves. The code has been slightly modified in order to make the linter happy.
/botio unittest |
From: Bot.io (Linux m4)ReceivedCommand cmd_unittest from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/ff53175b8885d0a/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_unittest from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/56b61bb15724963/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/ff53175b8885d0a/output.txt Total script time: 3.19 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/56b61bb15724963/output.txt Total script time: 6.74 mins
|
/botio integrationtest |
From: Bot.io (Windows)ReceivedCommand cmd_integrationtest from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/ff4b43101bf1e0d/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_integrationtest from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/ca85e75a8d5061f/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/ca85e75a8d5061f/output.txt Total script time: 4.50 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/ff4b43101bf1e0d/output.txt Total script time: 7.65 mins
|
js code from https://github.com/soswow/fit-curves.
The code has been slightly modified in order to make the linter
happy.