Skip to content

Commit

Permalink
[edition] Add a FreeText editor (mozilla#14970)
Browse files Browse the repository at this point in the history
- add a basic UI to edit some text in a pdf;
- an editor can be moved, suppressed, cut, copied, pasted, selected;
- add an undo/redo manager.
  • Loading branch information
calixteman authored and rousek committed Aug 10, 2022
1 parent 6257919 commit d3a89a0
Show file tree
Hide file tree
Showing 28 changed files with 2,321 additions and 18 deletions.
4 changes: 4 additions & 0 deletions extensions/chromium/preferences_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@
],
"default": 2
},
"annotationEditorEnabled": {
"type": "boolean",
"default": false
},
"enablePermissions": {
"type": "boolean",
"default": false
Expand Down
7 changes: 7 additions & 0 deletions l10n/en-US/viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,10 @@ password_cancel=Cancel
printing_not_supported=Warning: Printing is not fully supported by this browser.
printing_not_ready=Warning: The PDF is not fully loaded for printing.
web_fonts_disabled=Web fonts are disabled: unable to use embedded PDF fonts.

# Editor
editor_none.title=Disable Annotation Editing
editor_none_label=Disable Editing
freetext_default_content=Enter some text…
editor_free_text.title=Add FreeText Annotation
editor_free_text_label=FreeText Annotation
23 changes: 22 additions & 1 deletion src/display/annotation_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* limitations under the License.
*/

import { AnnotationEditor } from "./editor/editor.js";
import { MurmurHash3_64 } from "../shared/murmurhash3.js";
import { objectFromMap } from "../shared/util.js";

Expand Down Expand Up @@ -62,6 +63,14 @@ class AnnotationStorage {
return this._storage.get(key);
}

/**
* Remove a value from the storage.
* @param {string} key
*/
removeKey(key) {
this._storage.delete(key);
}

/**
* Set the value for a given key
*
Expand Down Expand Up @@ -123,7 +132,19 @@ class AnnotationStorage {
* @ignore
*/
get serializable() {
return this._storage.size > 0 ? this._storage : null;
if (this._storage.size === 0) {
return null;
}

const clone = new Map();
for (const [key, value] of this._storage) {
if (value instanceof AnnotationEditor) {
clone.set(key, value.serialize());
} else {
clone.set(key, value);
}
}
return clone;
}

/**
Expand Down
Loading

0 comments on commit d3a89a0

Please sign in to comment.