Merge pull request #20244 from calixteman/fix_deleting_popup
[Editor] Fix saving a deleted popup
This commit is contained in:
commit
3f0d39b024
@ -1810,8 +1810,8 @@ class MarkupAnnotation extends Annotation {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const retRef = { ref: annotationRef };
|
const retRef = { ref: annotationRef };
|
||||||
if (annotation.popup) {
|
const { popup } = annotation;
|
||||||
const popup = annotation.popup;
|
if (popup) {
|
||||||
if (popup.deleted) {
|
if (popup.deleted) {
|
||||||
annotationDict.delete("Popup");
|
annotationDict.delete("Popup");
|
||||||
annotationDict.delete("Contents");
|
annotationDict.delete("Contents");
|
||||||
|
|||||||
@ -309,7 +309,7 @@ class Dict {
|
|||||||
}
|
}
|
||||||
|
|
||||||
delete(key) {
|
delete(key) {
|
||||||
delete this._map[key];
|
this._map.delete(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1749,7 +1749,14 @@ class AnnotationEditor {
|
|||||||
* @returns {Object | null}
|
* @returns {Object | null}
|
||||||
*/
|
*/
|
||||||
serialize(isForCopying = false, context = null) {
|
serialize(isForCopying = false, context = null) {
|
||||||
unreachable("An editor must be serializable");
|
return {
|
||||||
|
annotationType: this.mode,
|
||||||
|
pageIndex: this.pageIndex,
|
||||||
|
rect: this.getPDFRect(),
|
||||||
|
rotation: this.rotation,
|
||||||
|
structTreeParentId: this._structTreeParentId,
|
||||||
|
popupRef: this._initialData?.popupRef || "",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -833,21 +833,14 @@ class FreeTextEditor extends AnnotationEditor {
|
|||||||
return this.serializeDeleted();
|
return this.serializeDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
const rect = this.getPDFRect();
|
|
||||||
const color = AnnotationEditor._colorManager.convert(
|
const color = AnnotationEditor._colorManager.convert(
|
||||||
this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.color
|
this.isAttachedToDOM ? getComputedStyle(this.editorDiv).color : this.color
|
||||||
);
|
);
|
||||||
|
const serialized = Object.assign(super.serialize(isForCopying), {
|
||||||
const serialized = {
|
|
||||||
annotationType: AnnotationEditorType.FREETEXT,
|
|
||||||
color,
|
color,
|
||||||
fontSize: this.#fontSize,
|
fontSize: this.#fontSize,
|
||||||
value: this.#serializeContent(),
|
value: this.#serializeContent(),
|
||||||
pageIndex: this.pageIndex,
|
});
|
||||||
rect,
|
|
||||||
rotation: this.rotation,
|
|
||||||
structTreeParentId: this._structTreeParentId,
|
|
||||||
};
|
|
||||||
this.addComment(serialized);
|
this.addComment(serialized);
|
||||||
|
|
||||||
if (isForCopying) {
|
if (isForCopying) {
|
||||||
|
|||||||
@ -1036,23 +1036,17 @@ class HighlightEditor extends AnnotationEditor {
|
|||||||
return this.serializeDeleted();
|
return this.serializeDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
const rect = this.getPDFRect();
|
|
||||||
const color = AnnotationEditor._colorManager.convert(
|
const color = AnnotationEditor._colorManager.convert(
|
||||||
this._uiManager.getNonHCMColor(this.color)
|
this._uiManager.getNonHCMColor(this.color)
|
||||||
);
|
);
|
||||||
|
const serialized = super.serialize(isForCopying);
|
||||||
const serialized = {
|
Object.assign(serialized, {
|
||||||
annotationType: AnnotationEditorType.HIGHLIGHT,
|
|
||||||
color,
|
color,
|
||||||
opacity: this.opacity,
|
opacity: this.opacity,
|
||||||
thickness: this.#thickness,
|
thickness: this.#thickness,
|
||||||
quadPoints: this.#serializeBoxes(),
|
quadPoints: this.#serializeBoxes(),
|
||||||
outlines: this.#serializeOutlines(rect),
|
outlines: this.#serializeOutlines(serialized.rect),
|
||||||
pageIndex: this.pageIndex,
|
});
|
||||||
rect,
|
|
||||||
rotation: this.#getRotation(),
|
|
||||||
structTreeParentId: this._structTreeParentId,
|
|
||||||
};
|
|
||||||
this.addComment(serialized);
|
this.addComment(serialized);
|
||||||
|
|
||||||
if (this.annotationElementId && !this.#hasElementChanged(serialized)) {
|
if (this.annotationElementId && !this.#hasElementChanged(serialized)) {
|
||||||
|
|||||||
@ -247,7 +247,7 @@ class InkEditor extends DrawingEditor {
|
|||||||
return this.serializeDeleted();
|
return this.serializeDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { lines, points, rect } = this.serializeDraw(isForCopying);
|
const { lines, points } = this.serializeDraw(isForCopying);
|
||||||
const {
|
const {
|
||||||
_drawingOptions: {
|
_drawingOptions: {
|
||||||
stroke,
|
stroke,
|
||||||
@ -255,8 +255,7 @@ class InkEditor extends DrawingEditor {
|
|||||||
"stroke-width": thickness,
|
"stroke-width": thickness,
|
||||||
},
|
},
|
||||||
} = this;
|
} = this;
|
||||||
const serialized = {
|
const serialized = Object.assign(super.serialize(isForCopying), {
|
||||||
annotationType: AnnotationEditorType.INK,
|
|
||||||
color: AnnotationEditor._colorManager.convert(stroke),
|
color: AnnotationEditor._colorManager.convert(stroke),
|
||||||
opacity,
|
opacity,
|
||||||
thickness,
|
thickness,
|
||||||
@ -264,11 +263,7 @@ class InkEditor extends DrawingEditor {
|
|||||||
lines,
|
lines,
|
||||||
points,
|
points,
|
||||||
},
|
},
|
||||||
pageIndex: this.pageIndex,
|
});
|
||||||
rect,
|
|
||||||
rotation: this.rotation,
|
|
||||||
structTreeParentId: this._structTreeParentId,
|
|
||||||
};
|
|
||||||
this.addComment(serialized);
|
this.addComment(serialized);
|
||||||
|
|
||||||
if (isForCopying) {
|
if (isForCopying) {
|
||||||
|
|||||||
@ -374,21 +374,16 @@ class SignatureEditor extends DrawingEditor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { lines, points, rect } = this.serializeDraw(isForCopying);
|
const { lines, points } = this.serializeDraw(isForCopying);
|
||||||
const {
|
const {
|
||||||
_drawingOptions: { "stroke-width": thickness },
|
_drawingOptions: { "stroke-width": thickness },
|
||||||
} = this;
|
} = this;
|
||||||
const serialized = {
|
const serialized = Object.assign(super.serialize(isForCopying), {
|
||||||
annotationType: AnnotationEditorType.SIGNATURE,
|
|
||||||
isSignature: true,
|
isSignature: true,
|
||||||
areContours: this.#isExtracted,
|
areContours: this.#isExtracted,
|
||||||
color: [0, 0, 0],
|
color: [0, 0, 0],
|
||||||
thickness: this.#isExtracted ? 0 : thickness,
|
thickness: this.#isExtracted ? 0 : thickness,
|
||||||
pageIndex: this.pageIndex,
|
});
|
||||||
rect,
|
|
||||||
rotation: this.rotation,
|
|
||||||
structTreeParentId: this._structTreeParentId,
|
|
||||||
};
|
|
||||||
this.addComment(serialized);
|
this.addComment(serialized);
|
||||||
if (isForCopying) {
|
if (isForCopying) {
|
||||||
serialized.paths = { lines, points };
|
serialized.paths = { lines, points };
|
||||||
|
|||||||
@ -842,15 +842,10 @@ class StampEditor extends AnnotationEditor {
|
|||||||
return this.serializeDeleted();
|
return this.serializeDeleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
const serialized = {
|
const serialized = Object.assign(super.serialize(isForCopying), {
|
||||||
annotationType: AnnotationEditorType.STAMP,
|
|
||||||
bitmapId: this.#bitmapId,
|
bitmapId: this.#bitmapId,
|
||||||
pageIndex: this.pageIndex,
|
|
||||||
rect: this.getPDFRect(),
|
|
||||||
rotation: this.rotation,
|
|
||||||
isSvg: this.#isSvg,
|
isSvg: this.#isSvg,
|
||||||
structTreeParentId: this._structTreeParentId,
|
});
|
||||||
};
|
|
||||||
this.addComment(serialized);
|
this.addComment(serialized);
|
||||||
|
|
||||||
if (isForCopying) {
|
if (isForCopying) {
|
||||||
|
|||||||
@ -5023,6 +5023,63 @@ describe("annotation", function () {
|
|||||||
"endobj\n"
|
"endobj\n"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should update an existing Highlight annotation in removing its popup", async function () {
|
||||||
|
const popupRef = Ref.get(111, 0);
|
||||||
|
const highlightDict = new Dict();
|
||||||
|
highlightDict.set("Type", Name.get("Annot"));
|
||||||
|
highlightDict.set("Subtype", Name.get("Highlight"));
|
||||||
|
highlightDict.set("Rotate", 0);
|
||||||
|
highlightDict.set("CreationDate", "D:20190423");
|
||||||
|
highlightDict.set("Contents", "Hello PDF.js World !");
|
||||||
|
highlightDict.set("Popup", popupRef);
|
||||||
|
const highlightRef = Ref.get(143, 0);
|
||||||
|
|
||||||
|
const highlightPopupDict = new Dict();
|
||||||
|
highlightPopupDict.set("Type", Name.get("Annot"));
|
||||||
|
highlightPopupDict.set("Subtype", Name.get("Popup"));
|
||||||
|
highlightPopupDict.set("Open", false);
|
||||||
|
highlightPopupDict.set("Rect", [1, 2, 3, 4]);
|
||||||
|
highlightPopupDict.set("Parent", highlightRef);
|
||||||
|
|
||||||
|
const xref = (partialEvaluator.xref = new XRefMock([
|
||||||
|
{ ref: highlightRef, data: highlightDict },
|
||||||
|
{ ref: popupRef, data: highlightPopupDict },
|
||||||
|
]));
|
||||||
|
const changes = new RefSetCache();
|
||||||
|
|
||||||
|
const task = new WorkerTask("test Highlight update");
|
||||||
|
await AnnotationFactory.saveNewAnnotations(
|
||||||
|
partialEvaluator,
|
||||||
|
task,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
annotationType: AnnotationEditorType.HIGHLIGHT,
|
||||||
|
rotation: 90,
|
||||||
|
popup: {
|
||||||
|
contents: "",
|
||||||
|
deleted: true,
|
||||||
|
rect: [1, 2, 3, 4],
|
||||||
|
},
|
||||||
|
id: "143R",
|
||||||
|
ref: highlightRef,
|
||||||
|
oldAnnotation: highlightDict,
|
||||||
|
popupRef,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
null,
|
||||||
|
changes
|
||||||
|
);
|
||||||
|
|
||||||
|
const data = await writeChanges(changes, xref);
|
||||||
|
const base = data[0].data.replaceAll(/\(D:\d+\)/g, "(date)");
|
||||||
|
expect(base).toEqual(
|
||||||
|
"143 0 obj\n" +
|
||||||
|
"<< /Type /Annot /Subtype /Highlight /Rotate 90 /CreationDate (date) /M (date) " +
|
||||||
|
"/F 4>>\n" +
|
||||||
|
"endobj\n"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("UnderlineAnnotation", function () {
|
describe("UnderlineAnnotation", function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user