mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-23 08:38:06 +02:00
[Editor] Add support for saving/printing a newly added Highlight annotation (bug 1865708)
This commit is contained in:
parent
83f0029212
commit
f8f4432961
4 changed files with 335 additions and 1 deletions
|
@ -354,6 +354,15 @@ class AnnotationFactory {
|
|||
)
|
||||
);
|
||||
break;
|
||||
case AnnotationEditorType.HIGHLIGHT:
|
||||
promises.push(
|
||||
HighlightAnnotation.createNewAnnotation(
|
||||
xref,
|
||||
annotation,
|
||||
dependencies
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AnnotationEditorType.INK:
|
||||
promises.push(
|
||||
InkAnnotation.createNewAnnotation(xref, annotation, dependencies)
|
||||
|
@ -429,6 +438,18 @@ class AnnotationFactory {
|
|||
)
|
||||
);
|
||||
break;
|
||||
case AnnotationEditorType.HIGHLIGHT:
|
||||
promises.push(
|
||||
HighlightAnnotation.createNewPrintAnnotation(
|
||||
annotationGlobals,
|
||||
xref,
|
||||
annotation,
|
||||
{
|
||||
evaluatorOptions: options,
|
||||
}
|
||||
)
|
||||
);
|
||||
break;
|
||||
case AnnotationEditorType.INK:
|
||||
promises.push(
|
||||
InkAnnotation.createNewPrintAnnotation(
|
||||
|
@ -4432,6 +4453,94 @@ class HighlightAnnotation extends MarkupAnnotation {
|
|||
this.data.popupRef = null;
|
||||
}
|
||||
}
|
||||
|
||||
static createNewDict(annotation, xref, { apRef, ap }) {
|
||||
const { color, opacity, rect, rotation, user, quadPoints } = annotation;
|
||||
const highlight = new Dict(xref);
|
||||
highlight.set("Type", Name.get("Annot"));
|
||||
highlight.set("Subtype", Name.get("Highlight"));
|
||||
highlight.set("CreationDate", `D:${getModificationDate()}`);
|
||||
highlight.set("Rect", rect);
|
||||
highlight.set("F", 4);
|
||||
highlight.set("Border", [0, 0, 0]);
|
||||
highlight.set("Rotate", rotation);
|
||||
highlight.set("QuadPoints", quadPoints);
|
||||
|
||||
// Color.
|
||||
highlight.set(
|
||||
"C",
|
||||
Array.from(color, c => c / 255)
|
||||
);
|
||||
|
||||
// Opacity.
|
||||
highlight.set("CA", opacity);
|
||||
|
||||
if (user) {
|
||||
highlight.set(
|
||||
"T",
|
||||
isAscii(user) ? user : stringToUTF16String(user, /* bigEndian = */ true)
|
||||
);
|
||||
}
|
||||
|
||||
if (apRef || ap) {
|
||||
const n = new Dict(xref);
|
||||
highlight.set("AP", n);
|
||||
n.set("N", apRef || ap);
|
||||
}
|
||||
|
||||
return highlight;
|
||||
}
|
||||
|
||||
static async createNewAppearanceStream(annotation, xref, params) {
|
||||
const { color, rect, outlines, opacity } = annotation;
|
||||
|
||||
const appearanceBuffer = [
|
||||
`${getPdfColor(color, /* isFill */ true)}`,
|
||||
"/R0 gs",
|
||||
];
|
||||
|
||||
const buffer = [];
|
||||
for (const outline of outlines) {
|
||||
buffer.length = 0;
|
||||
buffer.push(
|
||||
`${numberToString(outline[0])} ${numberToString(outline[1])} m`
|
||||
);
|
||||
for (let i = 2, ii = outline.length; i < ii; i += 2) {
|
||||
buffer.push(
|
||||
`${numberToString(outline[i])} ${numberToString(outline[i + 1])} l`
|
||||
);
|
||||
}
|
||||
buffer.push("h");
|
||||
appearanceBuffer.push(buffer.join("\n"));
|
||||
}
|
||||
appearanceBuffer.push("f*");
|
||||
const appearance = appearanceBuffer.join("\n");
|
||||
|
||||
const appearanceStreamDict = new Dict(xref);
|
||||
appearanceStreamDict.set("FormType", 1);
|
||||
appearanceStreamDict.set("Subtype", Name.get("Form"));
|
||||
appearanceStreamDict.set("Type", Name.get("XObject"));
|
||||
appearanceStreamDict.set("BBox", rect);
|
||||
appearanceStreamDict.set("Length", appearance.length);
|
||||
|
||||
const resources = new Dict(xref);
|
||||
const extGState = new Dict(xref);
|
||||
resources.set("ExtGState", extGState);
|
||||
appearanceStreamDict.set("Resources", resources);
|
||||
const r0 = new Dict(xref);
|
||||
extGState.set("R0", r0);
|
||||
r0.set("BM", Name.get("Multiply"));
|
||||
|
||||
if (opacity !== 1) {
|
||||
r0.set("ca", opacity);
|
||||
r0.set("Type", Name.get("ExtGState"));
|
||||
}
|
||||
|
||||
const ap = new StringStream(appearance);
|
||||
ap.dict = appearanceStreamDict;
|
||||
|
||||
return ap;
|
||||
}
|
||||
}
|
||||
|
||||
class UnderlineAnnotation extends MarkupAnnotation {
|
||||
|
|
|
@ -72,6 +72,7 @@ const AnnotationEditorType = {
|
|||
DISABLE: -1,
|
||||
NONE: 0,
|
||||
FREETEXT: 3,
|
||||
HIGHLIGHT: 9,
|
||||
STAMP: 13,
|
||||
INK: 15,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue