mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #19339 from calixteman/signature_tools
[Editor] (WIP) Add a new tool in order to add an handwritten signature to a pdf (bug 1942343)
This commit is contained in:
commit
42c2b7b657
18 changed files with 839 additions and 9 deletions
|
@ -162,7 +162,8 @@
|
|||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.annotationEditorLayer :is(.freeTextEditor, .inkEditor, .stampEditor) {
|
||||
.annotationEditorLayer
|
||||
:is(.freeTextEditor, .inkEditor, .stampEditor, .signatureEditor) {
|
||||
position: absolute;
|
||||
background: transparent;
|
||||
z-index: 1;
|
||||
|
@ -220,7 +221,13 @@
|
|||
}
|
||||
|
||||
.annotationEditorLayer
|
||||
:is(.freeTextEditor, .inkEditor, .stampEditor, .highlightEditor),
|
||||
:is(
|
||||
.freeTextEditor,
|
||||
.inkEditor,
|
||||
.stampEditor,
|
||||
.highlightEditor,
|
||||
.signatureEditor
|
||||
),
|
||||
.textLayer {
|
||||
.editToolbar {
|
||||
--editor-toolbar-delete-image: url(images/editor-toolbar-delete.svg);
|
||||
|
@ -622,7 +629,7 @@
|
|||
}
|
||||
|
||||
.annotationEditorLayer {
|
||||
:is(.freeTextEditor, .inkEditor, .stampEditor) {
|
||||
:is(.freeTextEditor, .inkEditor, .stampEditor, .signatureEditor) {
|
||||
& > .resizers {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
|
|
|
@ -27,6 +27,7 @@ import { AnnotationEditorParamsType } from "pdfjs-lib";
|
|||
* @property {HTMLButtonElement} editorStampAddImage
|
||||
* @property {HTMLInputElement} editorFreeHighlightThickness
|
||||
* @property {HTMLButtonElement} editorHighlightShowAll
|
||||
* @property {HTMLButtonElement} editorSignatureAddSignature
|
||||
*/
|
||||
|
||||
class AnnotationEditorParams {
|
||||
|
@ -51,6 +52,7 @@ class AnnotationEditorParams {
|
|||
editorStampAddImage,
|
||||
editorFreeHighlightThickness,
|
||||
editorHighlightShowAll,
|
||||
editorSignatureAddSignature,
|
||||
}) {
|
||||
const { eventBus } = this;
|
||||
|
||||
|
@ -94,6 +96,9 @@ class AnnotationEditorParams {
|
|||
this.setAttribute("aria-pressed", !checked);
|
||||
dispatchEvent("HIGHLIGHT_SHOW_ALL", !checked);
|
||||
});
|
||||
editorSignatureAddSignature.addEventListener("click", () => {
|
||||
dispatchEvent("CREATE");
|
||||
});
|
||||
|
||||
eventBus._on("annotationeditorparamschanged", evt => {
|
||||
for (const [type, value] of evt.details) {
|
||||
|
|
|
@ -536,6 +536,10 @@ const PDFViewerApplication = {
|
|||
typeof AbortSignal.any === "function") &&
|
||||
annotationEditorMode !== AnnotationEditorType.DISABLE
|
||||
) {
|
||||
const editorSignatureButton = appConfig.toolbar?.editorSignatureButton;
|
||||
if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) {
|
||||
editorSignatureButton.parentElement.hidden = false;
|
||||
}
|
||||
this.annotationEditorParams = new AnnotationEditorParams(
|
||||
appConfig.annotationEditorParams,
|
||||
eventBus
|
||||
|
|
|
@ -228,6 +228,11 @@ const defaultOptions = {
|
|||
value: typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME"),
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
enableSignatureEditor: {
|
||||
/** @type {boolean} */
|
||||
value: typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING"),
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
enableUpdatedAddImage: {
|
||||
// We'll probably want to make some experiments before enabling this
|
||||
// in Firefox release, but it has to be temporary.
|
||||
|
|
|
@ -39,6 +39,7 @@ class EditorUndoBar {
|
|||
freetext: "pdfjs-editor-undo-bar-message-freetext",
|
||||
stamp: "pdfjs-editor-undo-bar-message-stamp",
|
||||
ink: "pdfjs-editor-undo-bar-message-ink",
|
||||
signature: "pdfjs-editor-undo-bar-message-signature",
|
||||
_multiple: "pdfjs-editor-undo-bar-message-multiple",
|
||||
});
|
||||
|
||||
|
|
6
web/images/toolbarButton-editorSignature.svg
Normal file
6
web/images/toolbarButton-editorSignature.svg
Normal file
|
@ -0,0 +1,6 @@
|
|||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 7.5" width="12" height="12">
|
||||
<path d="M1.5,4.5c.75,0,1.31.75,1.68,1.49A4.47,4.47,0,0,1,7.5,2.25C10.5,2.25,12,5,12,7.5h-.75V9.38a.37.37,0,0,1-.37.38H9.38A.38.38,0,0,1,9,9.38V8.25H5.25V9.38a.37.37,0,0,1-.37.38H3.38A.37.37,0,0,1,3,9.38V7.5H1.5a1.5,1.5,0,0,1,0-3Z" transform="translate(0 -2.25)"/>
|
||||
</svg>
|
After Width: | Height: | Size: 571 B |
|
@ -119,6 +119,18 @@ class Toolbar {
|
|||
data: { action: "pdfjs.image.icon_click" },
|
||||
},
|
||||
},
|
||||
{
|
||||
element: options.editorSignatureButton,
|
||||
eventName: "switchannotationeditormode",
|
||||
eventDetails: {
|
||||
get mode() {
|
||||
const { classList } = options.editorSignatureButton;
|
||||
return classList.contains("toggled")
|
||||
? AnnotationEditorType.NONE
|
||||
: AnnotationEditorType.SIGNATURE;
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Bind the event listeners for click and various other actions.
|
||||
|
@ -274,6 +286,8 @@ class Toolbar {
|
|||
editorInkParamsToolbar,
|
||||
editorStampButton,
|
||||
editorStampParamsToolbar,
|
||||
editorSignatureButton,
|
||||
editorSignatureParamsToolbar,
|
||||
} = this.#opts;
|
||||
|
||||
toggleExpandedBtn(
|
||||
|
@ -296,12 +310,18 @@ class Toolbar {
|
|||
mode === AnnotationEditorType.STAMP,
|
||||
editorStampParamsToolbar
|
||||
);
|
||||
toggleExpandedBtn(
|
||||
editorSignatureButton,
|
||||
mode === AnnotationEditorType.SIGNATURE,
|
||||
editorSignatureParamsToolbar
|
||||
);
|
||||
|
||||
const isDisable = mode === AnnotationEditorType.DISABLE;
|
||||
editorFreeTextButton.disabled = isDisable;
|
||||
editorHighlightButton.disabled = isDisable;
|
||||
editorInkButton.disabled = isDisable;
|
||||
editorStampButton.disabled = isDisable;
|
||||
editorSignatureButton.disabled = isDisable;
|
||||
}
|
||||
|
||||
#updateUIState(resetNumPages = false) {
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
--toolbarButton-editorHighlight-icon: url(images/toolbarButton-editorHighlight.svg);
|
||||
--toolbarButton-editorInk-icon: url(images/toolbarButton-editorInk.svg);
|
||||
--toolbarButton-editorStamp-icon: url(images/toolbarButton-editorStamp.svg);
|
||||
--toolbarButton-editorSignature-icon: url(images/toolbarButton-editorSignature.svg);
|
||||
--toolbarButton-menuArrow-icon: url(images/toolbarButton-menuArrow.svg);
|
||||
--toolbarButton-sidebarToggle-icon: url(images/toolbarButton-sidebarToggle.svg);
|
||||
--toolbarButton-secondaryToolbarToggle-icon: url(images/toolbarButton-secondaryToolbarToggle.svg);
|
||||
|
@ -572,6 +573,10 @@ body {
|
|||
mask-image: var(--toolbarButton-editorStamp-icon);
|
||||
}
|
||||
|
||||
#editorSignatureButton::before {
|
||||
mask-image: var(--toolbarButton-editorSignature-icon);
|
||||
}
|
||||
|
||||
#printButton::before {
|
||||
mask-image: var(--toolbarButton-print-icon);
|
||||
}
|
||||
|
@ -1119,7 +1124,7 @@ dialog :link {
|
|||
z-index: 30000;
|
||||
cursor: default;
|
||||
|
||||
#editorStampAddImage::before {
|
||||
:is(#editorStampAddImage, #editorSignatureAddSignature)::before {
|
||||
mask-image: var(--editorParams-stampAddImage-icon);
|
||||
}
|
||||
|
||||
|
|
|
@ -318,6 +318,18 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="editorSignature" class="toolbarButtonWithContainer" hidden="true">
|
||||
<button id="editorSignatureButton" class="toolbarButton" type="button" disabled="disabled" title="Add or edit signatures" role="radio" aria-expanded="false" aria-haspopup="true" aria-controls="editorSignatureParamsToolbar" tabindex="0">
|
||||
<span>Add or edit signatures</span>
|
||||
</button>
|
||||
<div class="editorParamsToolbar hidden doorHangerRight menu" id="editorSignatureParamsToolbar">
|
||||
<div class="menuContainer">
|
||||
<button id="editorSignatureAddSignature" class="toolbarButton labeled" type="button" title="Add signature" tabindex="0">
|
||||
<span class="editorParamsLabel">Add signature</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="editorModeSeparator" class="verticalToolbarSeparator"></div>
|
||||
|
|
|
@ -68,6 +68,10 @@ function getViewerConfiguration() {
|
|||
editorStampParamsToolbar: document.getElementById(
|
||||
"editorStampParamsToolbar"
|
||||
),
|
||||
editorSignatureButton: document.getElementById("editorSignatureButton"),
|
||||
editorSignatureParamsToolbar: document.getElementById(
|
||||
"editorSignatureParamsToolbar"
|
||||
),
|
||||
download: document.getElementById("downloadButton"),
|
||||
},
|
||||
secondaryToolbar: {
|
||||
|
@ -217,6 +221,9 @@ function getViewerConfiguration() {
|
|||
editorInkThickness: document.getElementById("editorInkThickness"),
|
||||
editorInkOpacity: document.getElementById("editorInkOpacity"),
|
||||
editorStampAddImage: document.getElementById("editorStampAddImage"),
|
||||
editorSignatureAddSignature: document.getElementById(
|
||||
"editorSignatureAddSignature"
|
||||
),
|
||||
editorFreeHighlightThickness: document.getElementById(
|
||||
"editorFreeHighlightThickness"
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue