Skip to content
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

Merged
merged 1 commit into from
Jun 9, 2022
Merged

[editor] Add an Ink editor #14989

merged 1 commit into from
Jun 9, 2022

Conversation

calixteman
Copy link
Contributor

@calixteman calixteman marked this pull request as draft June 4, 2022 21:39
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='utf-8'?>
Copy link
Collaborator

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.

@@ -0,0 +1,677 @@
/**
Copy link
Collaborator

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)?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 ?

Copy link
Collaborator

@Snuffleupagus Snuffleupagus Jun 6, 2022

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:

web/toolbar.js Show resolved Hide resolved
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">
Copy link
Collaborator

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.

// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

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

firt -> first

@Snuffleupagus Snuffleupagus linked an issue Jun 6, 2022 that may be closed by this pull request
@calixteman calixteman force-pushed the ink1 branch 2 times, most recently from 1ff2d70 to c2b66dd Compare June 8, 2022 14:26
@calixteman calixteman marked this pull request as ready for review June 8, 2022 14:28
@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Jun 8, 2022

It looks like gulp ci-test failed, i.e. what GitHub action runs, and I'd guess that you need to extend this line to fix that:

["examples/node/domstubs.js", "web/*.js", "!web/{pdfjs,viewer}.js"],

@calixteman
Copy link
Contributor Author

It looks like gulp ci-test failed, i.e. what GitHub action runs, and I'd guess that you need to extend this line to fix that:

["examples/node/domstubs.js", "web/*.js", "!web/{pdfjs,viewer}.js"],

I added external/fit_curve/fit_curve.js but it doesn't work because external is a the same level as display in lib-legacy.
So changing ../../../external into ../../external is ok but then gulp server isn't.

@Snuffleupagus
Copy link
Collaborator

I added external/fit_curve/fit_curve.js but it doesn't work because external is a the same level as display in lib-legacy.
So changing ../../../external into ../../external is ok but then gulp server isn't.

I suppose that you can temporarily move it back its original position, in the src/display/editor/ folder, but that makes fixing the follow-up issue even more important (in my opinion).

@Snuffleupagus
Copy link
Collaborator

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Jun 8, 2022

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/cfa5839bc6b302c/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 8, 2022

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/fc0148520bfe7e2/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 8, 2022

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/cfa5839bc6b302c/output.txt

Total script time: 26.15 mins

  • Font tests: Passed
  • Unit tests: FAILED
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 52

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

@pdfjsbot
Copy link

pdfjsbot commented Jun 8, 2022

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/fc0148520bfe7e2/output.txt

Total script time: 28.90 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  different ref/snapshot: 1

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

@calixteman calixteman requested a review from Snuffleupagus June 9, 2022 14:25
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.

r=me, with comments addressed; thank you!

Comment on lines 94 to 96
// At some point this editor has been removed and
// we're rebuilting it, hence we must add it to its
// parent.
Copy link
Collaborator

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:

Suggested change
// 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;
Copy link
Collaborator

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?

this.div.classList.add("editing");

if (this.width) {
// This editor has been created in using copy (ctrl+c).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Grammar nits:

Suggested change
// This editor has been created in using copy (ctrl+c).
// This editor was created by copying (ctrl+c).

Copy link
Collaborator

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).

this.setDimensions(rect.width, rect.height);
}
});
observer.observe(this.div);
Copy link
Collaborator

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?

this.#redraw();
}

const observer = new ResizeObserver(entries => {
Copy link
Collaborator

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.
@calixteman
Copy link
Contributor Author

/botio unittest

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/ff53175b8885d0a/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/56b61bb15724963/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/ff53175b8885d0a/output.txt

Total script time: 3.19 mins

  • Unit Tests: FAILED

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/56b61bb15724963/output.txt

Total script time: 6.74 mins

  • Unit Tests: Passed

@calixteman
Copy link
Contributor Author

/botio integrationtest

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Windows)


Received

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

Live output at: http://54.193.163.58:8877/ff4b43101bf1e0d/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.241.84.105:8877/ca85e75a8d5061f/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/ca85e75a8d5061f/output.txt

Total script time: 4.50 mins

  • Integration Tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Jun 9, 2022

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/ff4b43101bf1e0d/output.txt

Total script time: 7.65 mins

  • Integration Tests: Passed

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

Successfully merging this pull request may close these issues.

Add support for drawing
3 participants