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

Ale add polygon editor #1

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pdfjs.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"stableVersion": "3.0.279",
"stableVersion": "3.1.21",
"baseVersion": "d0823066cc01a2f3d45ac46d8a653a74830d69ea",
"versionPrefix": "3.1."
}
}
9 changes: 9 additions & 0 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ class AnnotationFactory {
promises.push(
InkAnnotation.createNewAnnotation(xref, annotation, dependencies)
);
case AnnotationEditorType.POLYGON:
promises.push(
PolygonAnnotation.createNewAnnotation(xref, annotation, dependencies)
);
}
}

Expand Down Expand Up @@ -316,6 +320,11 @@ class AnnotationFactory {
InkAnnotation.createNewPrintAnnotation(xref, annotation)
);
break;
case AnnotationEditorType.POLYGON:
promises.push(
PolygonAnnotation.createNewPrintAnnotation(xref, annotation)
);
break;
}
}

Expand Down
41 changes: 39 additions & 2 deletions src/display/editor/annotation_editor_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { bindEvents, KeyboardManager } from "./tools.js";
import { AnnotationEditorType } from "../../shared/util.js";
import { FreeTextEditor } from "./freetext.js";
import { InkEditor } from "./ink.js";
import { PolygonEditor } from "./polygon.js";

/**
* @typedef {Object} AnnotationEditorLayerOptions
Expand Down Expand Up @@ -69,8 +70,9 @@ class AnnotationEditorLayer {
AnnotationEditorLayer._initialized = true;
FreeTextEditor.initialize(options.l10n);
InkEditor.initialize(options.l10n);
PolygonEditor.initialize(options.l10n);
}
options.uiManager.registerEditorTypes([FreeTextEditor, InkEditor]);
options.uiManager.registerEditorTypes([FreeTextEditor, InkEditor, PolygonEditor ]);

this.#uiManager = options.uiManager;
this.annotationStorage = options.annotationStorage;
Expand All @@ -95,7 +97,12 @@ class AnnotationEditorLayer {
*/
updateMode(mode = this.#uiManager.getMode()) {
this.#cleanup();
if (mode === AnnotationEditorType.INK) {

if (mode === AnnotationEditorType.POLYGON) {
// We always want to an ink editor ready to draw in.
this.addPolygonEditorIfNeeded(false);
this.disableClick();
} else if (mode === AnnotationEditorType.INK) {
// We always want to an ink editor ready to draw in.
this.addInkEditorIfNeeded(false);
this.disableClick();
Expand All @@ -109,6 +116,31 @@ class AnnotationEditorLayer {
mode === AnnotationEditorType.FREETEXT
);
this.div.classList.toggle("inkEditing", mode === AnnotationEditorType.INK);
this.div.classList.toggle(
"polygonEditing", mode === AnnotationEditorType.POLYGON);
}

addPolygonEditorIfNeeded(isCommitting) {
if (
!isCommitting &&
this.#uiManager.getMode() !== AnnotationEditorType.POLYGON
) {
return;
}

if (!isCommitting) {
// We're removing an editor but an empty one can already exist so in this
// case we don't need to create a new one.
for (const editor of this.#editors.values()) {
if (editor.isEmpty()) {
editor.setInBackground();
return;
}
}
}

const editor = this.#createAndAddNewEditor({ offsetX: 0, offsetY: 0 });
editor.setInBackground();
}

addInkEditorIfNeeded(isCommitting) {
Expand Down Expand Up @@ -230,6 +262,7 @@ class AnnotationEditorLayer {

if (!this.#isCleaningUp) {
this.addInkEditorIfNeeded(/* isCommitting = */ false);
this.addPolygonEditorIfNeeded(/* isCommitting = */ false);
}
}

Expand Down Expand Up @@ -353,6 +386,8 @@ class AnnotationEditorLayer {
return new FreeTextEditor(params);
case AnnotationEditorType.INK:
return new InkEditor(params);
case AnnotationEditorType.POLYGON:
return new PolygonEditor(params);
}
return null;
}
Expand All @@ -368,6 +403,8 @@ class AnnotationEditorLayer {
return FreeTextEditor.deserialize(data, this);
case AnnotationEditorType.INK:
return InkEditor.deserialize(data, this);
case AnnotationEditorType.POLYGON:
return PolygonEditor.deserialize(data, this);
}
return null;
}
Expand Down
Loading