JS -- hidden annotations must be built in case a script show them

* in some pdf, there are actions with "event.source.hidden = ..."
 * in order to handle visibility when printing, annotationStorage is extended to store multiple properties (value, hidden, editable, ...)
This commit is contained in:
Calixte Denizet 2020-11-03 16:04:08 +01:00
parent 1c17e078ec
commit b11592a756
9 changed files with 210 additions and 100 deletions

View File

@ -300,7 +300,6 @@ class Annotation {
_isViewable(flags) { _isViewable(flags) {
return ( return (
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE) &&
!this._hasFlag(flags, AnnotationFlag.HIDDEN) &&
!this._hasFlag(flags, AnnotationFlag.NOVIEW) !this._hasFlag(flags, AnnotationFlag.NOVIEW)
); );
} }
@ -311,11 +310,18 @@ class Annotation {
_isPrintable(flags) { _isPrintable(flags) {
return ( return (
this._hasFlag(flags, AnnotationFlag.PRINT) && this._hasFlag(flags, AnnotationFlag.PRINT) &&
!this._hasFlag(flags, AnnotationFlag.INVISIBLE) && !this._hasFlag(flags, AnnotationFlag.INVISIBLE)
!this._hasFlag(flags, AnnotationFlag.HIDDEN)
); );
} }
isHidden(annotationStorage) {
const data = annotationStorage && annotationStorage[this.data.id];
if (data && "hidden" in data) {
return data.hidden;
}
return this._hasFlag(this.flags, AnnotationFlag.HIDDEN);
}
/** /**
* @type {boolean} * @type {boolean}
*/ */
@ -984,7 +990,7 @@ class WidgetAnnotation extends Annotation {
} }
data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY); data.readOnly = this.hasFieldFlag(AnnotationFieldFlag.READONLY);
data.hidden = this.hasFieldFlag(AnnotationFieldFlag.HIDDEN); data.hidden = this._hasFlag(data.annotationFlags, AnnotationFlag.HIDDEN);
// Hide signatures because we cannot validate them, and unset the fieldValue // Hide signatures because we cannot validate them, and unset the fieldValue
// since it's (most likely) a `Dict` which is non-serializable and will thus // since it's (most likely) a `Dict` which is non-serializable and will thus
@ -1145,7 +1151,8 @@ class WidgetAnnotation extends Annotation {
} }
async save(evaluator, task, annotationStorage) { async save(evaluator, task, annotationStorage) {
const value = annotationStorage[this.data.id]; const value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
if (value === this.data.fieldValue || value === undefined) { if (value === this.data.fieldValue || value === undefined) {
return null; return null;
} }
@ -1229,7 +1236,8 @@ class WidgetAnnotation extends Annotation {
if (!annotationStorage || isPassword) { if (!annotationStorage || isPassword) {
return null; return null;
} }
const value = annotationStorage[this.data.id]; const value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
if (value === undefined) { if (value === undefined) {
// The annotation hasn't been rendered so use the appearance // The annotation hasn't been rendered so use the appearance
return null; return null;
@ -1712,7 +1720,9 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
} }
if (annotationStorage) { if (annotationStorage) {
const value = annotationStorage[this.data.id]; const value =
annotationStorage[this.data.id] &&
annotationStorage[this.data.id].value;
if (value === undefined) { if (value === undefined) {
return super.getOperatorList( return super.getOperatorList(
evaluator, evaluator,
@ -1767,7 +1777,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
} }
async _saveCheckbox(evaluator, task, annotationStorage) { async _saveCheckbox(evaluator, task, annotationStorage) {
const value = annotationStorage[this.data.id]; const value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
if (value === undefined) { if (value === undefined) {
return null; return null;
} }
@ -1809,7 +1820,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
} }
async _saveRadioButton(evaluator, task, annotationStorage) { async _saveRadioButton(evaluator, task, annotationStorage) {
const value = annotationStorage[this.data.id]; const value =
annotationStorage[this.data.id] && annotationStorage[this.data.id].value;
if (value === undefined) { if (value === undefined) {
return null; return null;
} }

View File

@ -347,7 +347,10 @@ class Page {
// is resolved with the complete operator list for a single annotation. // is resolved with the complete operator list for a single annotation.
const opListPromises = []; const opListPromises = [];
for (const annotation of annotations) { for (const annotation of annotations) {
if (isAnnotationRenderable(annotation, intent)) { if (
isAnnotationRenderable(annotation, intent) &&
!annotation.isHidden(annotationStorage)
) {
opListPromises.push( opListPromises.push(
annotation annotation
.getOperatorList( .getOperatorList(

View File

@ -490,7 +490,9 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
// NOTE: We cannot set the values using `element.value` below, since it // NOTE: We cannot set the values using `element.value` below, since it
// prevents the AnnotationLayer rasterizer in `test/driver.js` // prevents the AnnotationLayer rasterizer in `test/driver.js`
// from parsing the elements correctly for the reference tests. // from parsing the elements correctly for the reference tests.
const textContent = storage.getOrCreateValue(id, this.data.fieldValue); const textContent = storage.getOrCreateValue(id, {
value: this.data.fieldValue,
}).value;
if (this.data.multiLine) { if (this.data.multiLine) {
element = document.createElement("textarea"); element = document.createElement("textarea");
@ -504,7 +506,7 @@ class TextWidgetAnnotationElement extends WidgetAnnotationElement {
element.setAttribute("id", id); element.setAttribute("id", id);
element.addEventListener("input", function (event) { element.addEventListener("input", function (event) {
storage.setValue(id, event.target.value); storage.setValue(id, { value: event.target.value });
}); });
element.addEventListener("blur", function (event) { element.addEventListener("blur", function (event) {
@ -631,10 +633,9 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
const storage = this.annotationStorage; const storage = this.annotationStorage;
const data = this.data; const data = this.data;
const id = data.id; const id = data.id;
const value = storage.getOrCreateValue( const value = storage.getOrCreateValue(id, {
id, value: data.fieldValue && data.fieldValue !== "Off",
data.fieldValue && data.fieldValue !== "Off" }).value;
);
this.container.className = "buttonWidgetAnnotation checkBox"; this.container.className = "buttonWidgetAnnotation checkBox";
@ -647,7 +648,7 @@ class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement {
} }
element.addEventListener("change", function (event) { element.addEventListener("change", function (event) {
storage.setValue(id, event.target.checked); storage.setValue(id, { value: event.target.checked });
}); });
this.container.appendChild(element); this.container.appendChild(element);
@ -673,10 +674,9 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
const storage = this.annotationStorage; const storage = this.annotationStorage;
const data = this.data; const data = this.data;
const id = data.id; const id = data.id;
const value = storage.getOrCreateValue( const value = storage.getOrCreateValue(id, {
id, value: data.fieldValue === data.buttonValue,
data.fieldValue === data.buttonValue }).value;
);
const element = document.createElement("input"); const element = document.createElement("input");
element.disabled = data.readOnly; element.disabled = data.readOnly;
@ -692,11 +692,11 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
if (radio !== event.target) { if (radio !== event.target) {
storage.setValue( storage.setValue(
radio.parentNode.getAttribute("data-annotation-id"), radio.parentNode.getAttribute("data-annotation-id"),
false { value: false }
); );
} }
} }
storage.setValue(id, event.target.checked); storage.setValue(id, { value: event.target.checked });
}); });
this.container.appendChild(element); this.container.appendChild(element);
@ -753,10 +753,10 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
// two field types is implemented, we should use the same pattern as the // two field types is implemented, we should use the same pattern as the
// other interactive widgets where the return value of `getOrCreateValue` is // other interactive widgets where the return value of `getOrCreateValue` is
// used and the full array of field values is stored. // used and the full array of field values is stored.
storage.getOrCreateValue( storage.getOrCreateValue(id, {
id, value:
this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined,
); });
const selectElement = document.createElement("select"); const selectElement = document.createElement("select");
selectElement.disabled = this.data.readOnly; selectElement.disabled = this.data.readOnly;
@ -784,7 +784,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
selectElement.addEventListener("input", function (event) { selectElement.addEventListener("input", function (event) {
const options = event.target.options; const options = event.target.options;
const value = options[options.selectedIndex].value; const value = options[options.selectedIndex].value;
storage.setValue(id, value); storage.setValue(id, { value });
}); });
this.container.appendChild(selectElement); this.container.appendChild(selectElement);
@ -1622,6 +1622,9 @@ class AnnotationLayer {
}); });
if (element.isRenderable) { if (element.isRenderable) {
const rendered = element.render(); const rendered = element.render();
if (data.hidden) {
rendered.style.visibility = "hidden";
}
if (Array.isArray(rendered)) { if (Array.isArray(rendered)) {
for (const renderedElement of rendered) { for (const renderedElement of rendered) {
parameters.div.appendChild(renderedElement); parameters.div.appendChild(renderedElement);

View File

@ -59,10 +59,22 @@ class AnnotationStorage {
* @param {Object} value * @param {Object} value
*/ */
setValue(key, value) { setValue(key, value) {
if (this._storage.get(key) !== value) { const obj = this._storage.get(key);
let modified = false;
if (obj !== undefined) {
for (const [entry, val] of Object.entries(value)) {
if (obj[entry] !== val) {
modified = true;
obj[entry] = val;
}
}
} else {
this._storage.set(key, value);
modified = true;
}
if (modified) {
this._setModified(); this._setModified();
} }
this._storage.set(key, value);
} }
getAll() { getAll() {

View File

@ -179,6 +179,7 @@
!devicen.pdf !devicen.pdf
!cmykjpeg.pdf !cmykjpeg.pdf
!issue840.pdf !issue840.pdf
!160F-2019.pdf
!issue4402_reduced.pdf !issue4402_reduced.pdf
!issue845r.pdf !issue845r.pdf
!issue3405r.pdf !issue3405r.pdf

BIN
test/pdfs/160F-2019.pdf Normal file

Binary file not shown.

View File

@ -2207,6 +2207,19 @@
"lastPage": 1, "lastPage": 1,
"type": "load" "type": "load"
}, },
{ "id": "160F-2019",
"file": "pdfs/160F-2019.pdf",
"md5": "71591f11ee717e12887f529c84d5ae89",
"rounds": 1,
"type": "eq",
"print": true,
"annotationStorage": {
"427R": {
"hidden": false,
"value": "hello world"
}
}
},
{ "id": "issue6342-eq", { "id": "issue6342-eq",
"file": "pdfs/issue6342.pdf", "file": "pdfs/issue6342.pdf",
"md5": "2ea85ca8d17117798f105be88bdb2bfd", "md5": "2ea85ca8d17117798f105be88bdb2bfd",
@ -2811,7 +2824,9 @@
"type": "eq", "type": "eq",
"print": true, "print": true,
"annotationStorage": { "annotationStorage": {
"2795R": "氏 名 又 は 名 称 Full name" "2795R": {
"value": "氏 名 又 は 名 称 Full name"
}
} }
}, },
{ "id": "issue7598", { "id": "issue7598",
@ -3675,7 +3690,9 @@
"type": "eq", "type": "eq",
"print": true, "print": true,
"annotationStorage": { "annotationStorage": {
"1605R": true "1605R": {
"value": true
}
} }
}, },
{ "id": "clippath", { "id": "clippath",
@ -4179,11 +4196,21 @@
"type": "eq", "type": "eq",
"print": true, "print": true,
"annotationStorage": { "annotationStorage": {
"29R": true, "29R": {
"33R": true, "value": true
"37R": true, },
"65R": true, "33R": {
"69R": true "value": true
},
"37R": {
"value": true
},
"65R": {
"value": true
},
"69R": {
"value": true
}
} }
}, },
{ "id": "issue1171.pdf", { "id": "issue1171.pdf",
@ -4577,13 +4604,27 @@
"type": "eq", "type": "eq",
"print": true, "print": true,
"annotationStorage": { "annotationStorage": {
"61R": "Single line, unlimited length", "61R": {
"62R": "Single lin", "value": "Single line, unlimited length"
"63R": "Single line, center aligned", },
"64R": "Single line, right aligned", "62R": {
"65R": "", "value": "Single lin"
"66R": "zyxwvutsrqponmlkjihgfedcba", },
"67R": "Multiline\nstring" "63R": {
"value": "Single line, center aligned"
},
"64R": {
"value": "Single line, right aligned"
},
"65R": {
"value": ""
},
"66R": {
"value": "zyxwvutsrqponmlkjihgfedcba"
},
"67R": {
"value": "Multiline\nstring"
}
} }
}, },
{ "id": "annotation-choice-widget-annotations", { "id": "annotation-choice-widget-annotations",
@ -4607,11 +4648,21 @@
"type": "eq", "type": "eq",
"print": true, "print": true,
"annotationStorage": { "annotationStorage": {
"57R": "Ipsum", "57R": {
"58R": "Lorem", "value": "Ipsum"
"59R": "Dolor", },
"62R": "Sit", "58R": {
"63R": "" "value": "Lorem"
},
"59R": {
"value": "Dolor"
},
"62R": {
"value": "Sit"
},
"63R": {
"value": ""
}
} }
}, },
{ "id": "issue12233-forms", { "id": "issue12233-forms",
@ -4630,7 +4681,9 @@
"type": "eq", "type": "eq",
"print": true, "print": true,
"annotationStorage": { "annotationStorage": {
"20R": true "20R": {
"value": true
}
} }
}, },
{ "id": "issue11931", { "id": "issue11931",
@ -4666,15 +4719,33 @@
"type": "eq", "type": "eq",
"print": true, "print": true,
"annotationStorage": { "annotationStorage": {
"105R": true, "105R": {
"106R": false, "value": true
"107R": false, },
"108R": true, "106R": {
"109R": false, "value": false
"110R": false, },
"111R": true, "107R": {
"112R": false, "value": false
"113R": false },
"108R": {
"value": true
},
"109R": {
"value": false
},
"110R": {
"value": false
},
"111R": {
"value": true
},
"112R": {
"value": false
},
"113R": {
"value": false
}
} }
}, },
{ "id": "annotation-polyline-polygon", { "id": "annotation-polyline-polygon",

View File

@ -1602,7 +1602,7 @@ describe("annotation", function () {
.then(annotation => { .then(annotation => {
const id = annotation.data.id; const id = annotation.data.id;
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[id] = "test\\print"; annotationStorage[id] = { value: "test\\print" };
return annotation._getAppearance( return annotation._getAppearance(
partialEvaluator, partialEvaluator,
task, task,
@ -1687,7 +1687,7 @@ describe("annotation", function () {
.then(annotation => { .then(annotation => {
const id = annotation.data.id; const id = annotation.data.id;
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[id] = "test (print)"; annotationStorage[id] = { value: "test (print)" };
return annotation._getAppearance( return annotation._getAppearance(
partialEvaluator, partialEvaluator,
task, task,
@ -1723,7 +1723,7 @@ describe("annotation", function () {
.then(annotation => { .then(annotation => {
const id = annotation.data.id; const id = annotation.data.id;
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[id] = "mypassword"; annotationStorage[id] = { value: "mypassword" };
return annotation._getAppearance( return annotation._getAppearance(
partialEvaluator, partialEvaluator,
task, task,
@ -1756,9 +1756,11 @@ describe("annotation", function () {
.then(annotation => { .then(annotation => {
const id = annotation.data.id; const id = annotation.data.id;
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[id] = annotationStorage[id] = {
"a aa aaa aaaa aaaaa aaaaaa " + value:
"pneumonoultramicroscopicsilicovolcanoconiosis"; "a aa aaa aaaa aaaaa aaaaaa " +
"pneumonoultramicroscopicsilicovolcanoconiosis",
};
return annotation._getAppearance( return annotation._getAppearance(
partialEvaluator, partialEvaluator,
task, task,
@ -1823,15 +1825,17 @@ describe("annotation", function () {
.then(annotation => { .then(annotation => {
const id = annotation.data.id; const id = annotation.data.id;
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[id] = annotationStorage[id] = {
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r" + value:
"Aliquam vitae felis ac lectus bibendum ultricies quis non diam.\n" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r" +
"Morbi id porttitor quam, a iaculis dui.\r\n" + "Aliquam vitae felis ac lectus bibendum ultricies quis non diam.\n" +
"Pellentesque habitant morbi tristique senectus et " + "Morbi id porttitor quam, a iaculis dui.\r\n" +
"netus et malesuada fames ac turpis egestas.\n\r\n\r" + "Pellentesque habitant morbi tristique senectus et " +
"Nulla consectetur, ligula in tincidunt placerat, " + "netus et malesuada fames ac turpis egestas.\n\r\n\r" +
"velit augue consectetur orci, sed mattis libero nunc ut massa.\r" + "Nulla consectetur, ligula in tincidunt placerat, " +
"Etiam facilisis tempus interdum."; "velit augue consectetur orci, sed mattis libero nunc ut massa.\r" +
"Etiam facilisis tempus interdum.",
};
return annotation._getAppearance( return annotation._getAppearance(
partialEvaluator, partialEvaluator,
task, task,
@ -1865,7 +1869,7 @@ describe("annotation", function () {
.then(annotation => { .then(annotation => {
const id = annotation.data.id; const id = annotation.data.id;
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[id] = "aa(aa)a\\"; annotationStorage[id] = { value: "aa(aa)a\\" };
return annotation._getAppearance( return annotation._getAppearance(
partialEvaluator, partialEvaluator,
task, task,
@ -1898,7 +1902,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = "hello world"; annotationStorage[annotation.data.id] = { value: "hello world" };
return annotation.save(partialEvaluator, task, annotationStorage); return annotation.save(partialEvaluator, task, annotationStorage);
}, done.fail) }, done.fail)
.then(data => { .then(data => {
@ -2151,7 +2155,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return annotation.getOperatorList( return annotation.getOperatorList(
partialEvaluator, partialEvaluator,
task, task,
@ -2209,7 +2213,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return Promise.all([ return Promise.all([
annotation, annotation,
annotation.getOperatorList( annotation.getOperatorList(
@ -2234,7 +2238,7 @@ describe("annotation", function () {
}, done.fail) }, done.fail)
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = false; annotationStorage[annotation.data.id] = { value: false };
return annotation.getOperatorList( return annotation.getOperatorList(
partialEvaluator, partialEvaluator,
task, task,
@ -2292,7 +2296,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return Promise.all([ return Promise.all([
annotation, annotation,
annotation.getOperatorList( annotation.getOperatorList(
@ -2317,7 +2321,7 @@ describe("annotation", function () {
}) })
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return annotation.getOperatorList( return annotation.getOperatorList(
partialEvaluator, partialEvaluator,
task, task,
@ -2424,7 +2428,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return Promise.all([ return Promise.all([
annotation, annotation,
annotation.save(partialEvaluator, task, annotationStorage), annotation.save(partialEvaluator, task, annotationStorage),
@ -2443,7 +2447,7 @@ describe("annotation", function () {
}, done.fail) }, done.fail)
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = false; annotationStorage[annotation.data.id] = { value: false };
return annotation.save(partialEvaluator, task, annotationStorage); return annotation.save(partialEvaluator, task, annotationStorage);
}, done.fail) }, done.fail)
.then(data => { .then(data => {
@ -2586,7 +2590,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return Promise.all([ return Promise.all([
annotation, annotation,
annotation.getOperatorList( annotation.getOperatorList(
@ -2611,7 +2615,7 @@ describe("annotation", function () {
}, done.fail) }, done.fail)
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = false; annotationStorage[annotation.data.id] = { value: false };
return annotation.getOperatorList( return annotation.getOperatorList(
partialEvaluator, partialEvaluator,
task, task,
@ -2729,7 +2733,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return Promise.all([ return Promise.all([
annotation, annotation,
annotation.save(partialEvaluator, task, annotationStorage), annotation.save(partialEvaluator, task, annotationStorage),
@ -2755,7 +2759,7 @@ describe("annotation", function () {
}, done.fail) }, done.fail)
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = false; annotationStorage[annotation.data.id] = { value: false };
return annotation.save(partialEvaluator, task, annotationStorage); return annotation.save(partialEvaluator, task, annotationStorage);
}, done.fail) }, done.fail)
.then(data => { .then(data => {
@ -2800,7 +2804,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = true; annotationStorage[annotation.data.id] = { value: true };
return Promise.all([ return Promise.all([
annotation, annotation,
annotation.save(partialEvaluator, task, annotationStorage), annotation.save(partialEvaluator, task, annotationStorage),
@ -3247,7 +3251,7 @@ describe("annotation", function () {
.then(annotation => { .then(annotation => {
const id = annotation.data.id; const id = annotation.data.id;
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[id] = "a value"; annotationStorage[id] = { value: "a value" };
return annotation._getAppearance( return annotation._getAppearance(
partialEvaluator, partialEvaluator,
task, task,
@ -3282,7 +3286,7 @@ describe("annotation", function () {
) )
.then(annotation => { .then(annotation => {
const annotationStorage = {}; const annotationStorage = {};
annotationStorage[annotation.data.id] = "C"; annotationStorage[annotation.data.id] = { value: "C" };
return annotation.save(partialEvaluator, task, annotationStorage); return annotation.save(partialEvaluator, task, annotationStorage);
}, done.fail) }, done.fail)
.then(data => { .then(data => {

View File

@ -19,12 +19,16 @@ describe("AnnotationStorage", function () {
describe("GetOrCreateValue", function () { describe("GetOrCreateValue", function () {
it("should get and set a new value in the annotation storage", function (done) { it("should get and set a new value in the annotation storage", function (done) {
const annotationStorage = new AnnotationStorage(); const annotationStorage = new AnnotationStorage();
let value = annotationStorage.getOrCreateValue("123A", "hello world"); let value = annotationStorage.getOrCreateValue("123A", {
value: "hello world",
}).value;
expect(value).toEqual("hello world"); expect(value).toEqual("hello world");
// the second argument is the default value to use // the second argument is the default value to use
// if the key isn't in the storage // if the key isn't in the storage
value = annotationStorage.getOrCreateValue("123A", "an other string"); value = annotationStorage.getOrCreateValue("123A", {
value: "an other string",
}).value;
expect(value).toEqual("hello world"); expect(value).toEqual("hello world");
done(); done();
}); });
@ -33,8 +37,8 @@ describe("AnnotationStorage", function () {
describe("SetValue", function () { describe("SetValue", function () {
it("should set a new value in the annotation storage", function (done) { it("should set a new value in the annotation storage", function (done) {
const annotationStorage = new AnnotationStorage(); const annotationStorage = new AnnotationStorage();
annotationStorage.setValue("123A", "an other string"); annotationStorage.setValue("123A", { value: "an other string" });
const value = annotationStorage.getAll()["123A"]; const value = annotationStorage.getAll()["123A"].value;
expect(value).toEqual("an other string"); expect(value).toEqual("an other string");
done(); done();
}); });
@ -46,15 +50,15 @@ describe("AnnotationStorage", function () {
called = true; called = true;
}; };
annotationStorage.onSetModified = callback; annotationStorage.onSetModified = callback;
annotationStorage.getOrCreateValue("asdf", "original"); annotationStorage.getOrCreateValue("asdf", { value: "original" });
expect(called).toBe(false); expect(called).toBe(false);
// not changing value // not changing value
annotationStorage.setValue("asdf", "original"); annotationStorage.setValue("asdf", { value: "original" });
expect(called).toBe(false); expect(called).toBe(false);
// changing value // changing value
annotationStorage.setValue("asdf", "modified"); annotationStorage.setValue("asdf", { value: "modified" });
expect(called).toBe(true); expect(called).toBe(true);
done(); done();
}); });
@ -68,15 +72,15 @@ describe("AnnotationStorage", function () {
called = true; called = true;
}; };
annotationStorage.onResetModified = callback; annotationStorage.onResetModified = callback;
annotationStorage.getOrCreateValue("asdf", "original"); annotationStorage.getOrCreateValue("asdf", { value: "original" });
// not changing value // not changing value
annotationStorage.setValue("asdf", "original"); annotationStorage.setValue("asdf", { value: "original" });
annotationStorage.resetModified(); annotationStorage.resetModified();
expect(called).toBe(false); expect(called).toBe(false);
// changing value // changing value
annotationStorage.setValue("asdf", "modified"); annotationStorage.setValue("asdf", { value: "modified" });
annotationStorage.resetModified(); annotationStorage.resetModified();
expect(called).toBe(true); expect(called).toBe(true);
done(); done();