1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00

Merge pull request #17531 from calixteman/editor_free_highlight_print_save

[Editor] Add support for printing/saving free highlight annotations
This commit is contained in:
calixteman 2024-01-19 15:23:29 +01:00 committed by GitHub
commit f6c4b29aa2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 611 additions and 46 deletions

View file

@ -9324,5 +9324,324 @@
"structTreeParentId": null
}
}
},
{
"id": "tracemonkey-free-highlights",
"file": "pdfs/tracemonkey.pdf",
"md5": "9a192d8b1a7dc652a19835f6f08098bd",
"rounds": 1,
"lastPage": 1,
"type": "eq",
"print": true,
"annotationStorage": {
"pdfjs_internal_editor_0": {
"annotationType": 9,
"color": [83, 255, 188],
"opacity": 1,
"thickness": 20,
"quadPoints": null,
"outlines": {
"outline": [
null,
null,
null,
null,
74.55,
697.13,
78.51721472766205,
696.5192209591247,
79.29044208205713,
696.4224516456007,
80.05486887178773,
696.3379903011609,
80.81929566151834,
696.253528956721,
81.57617646110613,
696.1784636392651,
82.32551127055109,
696.1127943487935,
83.07484607999606,
696.047125058322,
83.81784340794434,
695.9886636959667,
84.55450325439585,
695.9374102617279,
null,
null,
null,
null,
85.65949302407317,
695.8605301103697,
null,
null,
null,
null,
87.03393143844572,
715.8149755833261,
85.48426194954816,
715.9204201846449,
84.87281761152917,
715.9671985492615,
84.26979673105028,
716.0185774379673,
83.66677585057136,
716.0699563266733,
83.07457849467843,
716.1266344280523,
82.4932046633715,
716.1886117421047,
81.9118308320646,
716.2505890561571,
81.34439691081282,
716.3184503202297,
80.7909028996162,
716.3921955343225,
null,
null,
null,
null,
77.95775603227756,
716.8481332058944
],
"points": [
[
76.25849755587352, 706.9926836109859, 86.14596273693202,
705.2879914026346, 88.1916451881855, 705.2879914026346,
90.23732763943899, 705.2879914026346, 92.28301009069247,
705.2879914026346, 94.32869254194594, 705.2879914026346
]
]
},
"pageIndex": 0,
"rect": [
73.94723907946947, 695.0685301103697, 87.64593143844571,
717.6401332058945
],
"rotation": 0,
"structTreeParentId": null
},
"pdfjs_internal_editor_1": {
"annotationType": 9,
"color": [128, 235, 255],
"opacity": 1,
"thickness": 20,
"quadPoints": null,
"outlines": {
"outline": [
null,
null,
null,
null,
260.9547742578311,
674.9666484352592,
265.0119754286617,
674.7200369564051,
265.85057115055446,
674.6816601253416,
266.8029560253001,
674.6436779453497,
267.7553409000457,
674.6056957653577,
268.641418670916,
674.586241754074,
269.46118933791087,
674.5853159114982,
null,
null,
null,
null,
270.6908453384032,
674.5839271476348,
null,
null,
null,
null,
270.6417128415015,
694.586095213411,
269.2921378713866,
694.5754310173227,
268.590908898233,
694.5902107638636,
267.72828093997174,
694.624035935381,
266.8656529817105,
694.6578611068985,
266.117024794879,
694.6914601264726,
265.48239637947734,
694.7248329941037,
null,
null,
null,
null,
262.2852690081439,
694.9245750690663
],
"points": [
[
261.6200216329875, 684.9456117521628, 271.8481748830951,
684.263717601745, 273.8938055331166, 684.263717601745,
276.6213130664787, 684.263717601745, 278.6669437165002,
684.6046646769539
]
]
},
"pageIndex": 0,
"rect": [
260.342789755033, 673.7919070919245, 271.30282984120134,
695.7165951247766
],
"rotation": 90,
"structTreeParentId": null
},
"pdfjs_internal_editor_2": {
"annotationType": 9,
"color": [255, 203, 230],
"opacity": 1,
"thickness": 20,
"quadPoints": null,
"outlines": {
"outline": [
null,
null,
null,
null,
350.1249530717911,
692.6633944602168,
345.38916289103776,
693.0766494920856,
344.5712435088917,
693.1558187178291,
343.92282969955727,
693.2395419718531,
343.2744158902228,
693.3232652258769,
342.6222941207318,
693.408487931081,
341.96646439108423,
693.4952100874651,
null,
null,
null,
null,
340.9827197966128,
693.6252933220413,
null,
null,
null,
null,
338.36438011302045,
673.7956810233082,
340.14908906785814,
673.5603604426211,
340.9899862433436,
673.4556612067797,
341.95789701237936,
673.3403909673718,
342.92580778141513,
673.2251207279638,
343.81937416539495,
673.1375137282872,
344.63859616431887,
673.0775699683421,
null,
null,
null,
null,
348.1346569560641,
672.7609372902139
],
"points": [
[
349.12980501392764, 682.7121658752152, 338.9013927576602,
683.734981200226, 336.1738161559889, 683.734981200226,
333.7871866295265, 684.4168580835666, 331.74150417827303,
684.7577965252368
]
]
},
"pageIndex": 0,
"rect": [
337.7523801130204, 671.9689372902138, 350.7369530717911,
694.4172933220414
],
"rotation": 180,
"structTreeParentId": null
},
"pdfjs_internal_editor_3": {
"annotationType": 9,
"color": [255, 79, 95],
"opacity": 1,
"thickness": 20,
"quadPoints": null,
"outlines": {
"outline": [
null,
null,
null,
null,
534.1504350586464,
715.0615382740357,
530.2182783647162,
715.0615382740357,
529.5364014813756,
715.0615382740357,
528.8545245980351,
715.0615382740357,
528.1726477146946,
715.0615382740357,
527.4339477577424,
715.0615382740357,
526.6384247271785,
715.0615382740357,
null,
null,
null,
null,
525.4451401813326,
715.0615382740357,
null,
null,
null,
null,
525.4451401813326,
695.0593098617794,
527.4339477577424,
695.0593098617794,
528.1726477146946,
695.0593098617794,
528.8545245980351,
695.0593098617794,
529.5364014813756,
695.0593098617794,
530.2182783647162,
695.0593098617794,
530.9001552480566,
695.0593098617794,
null,
null,
null,
null,
534.1504350586464,
695.0593098617794
],
"points": [
[
534.1504350586464, 705.0604240679075, 523.9222818085387,
705.0604240679075, 521.8766511585172, 705.0604240679075,
519.8310205084957, 705.0604240679075, 517.444451416804,
705.0604240679075
]
]
},
"pageIndex": 0,
"rect": [
524.8331556785345, 694.2672898060691, 534.7624195614445,
715.853558329746
],
"rotation": 270,
"structTreeParentId": null
}
}
}
]

View file

@ -4708,6 +4708,125 @@ describe("annotation", function () {
OPS.endAnnotation,
]);
});
it("should create a new free Highlight annotation", async function () {
partialEvaluator.xref = new XRefMock();
const task = new WorkerTask("test free Highlight creation");
const data = await AnnotationFactory.saveNewAnnotations(
partialEvaluator,
task,
[
{
annotationType: AnnotationEditorType.HIGHLIGHT,
rect: [12, 34, 56, 78],
rotation: 0,
opacity: 1,
color: [0, 0, 0],
thickness: 3.14,
quadPoints: null,
outlines: {
outline: Float64Array.from([
NaN,
NaN,
8,
9,
10,
11,
NaN,
NaN,
12,
13,
14,
15,
]),
points: [Float64Array.from([16, 17, 18, 19])],
},
},
]
);
const base = data.annotations[0].data.replace(/\(D:\d+\)/, "(date)");
expect(base).toEqual(
"1 0 obj\n" +
"<< /Type /Annot /Subtype /Ink /CreationDate (date) /Rect [12 34 56 78] " +
"/InkList [[16 17 18 19]] /F 4 /Rotate 0 /IT /InkHighlight /BS << /W 3.14>> " +
"/C [0 0 0] /CA 1 /AP << /N 2 0 R>>>>\n" +
"endobj\n"
);
const appearance = data.dependencies[0].data;
expect(appearance).toEqual(
"2 0 obj\n" +
"<< /FormType 1 /Subtype /Form /Type /XObject /BBox [12 34 56 78] " +
"/Length 30 /Resources << /ExtGState << /R0 << /BM /Multiply>>>>>>>> " +
"stream\n" +
"0 g\n" +
"/R0 gs\n" +
"10 11 m\n" +
"14 15 l\n" +
"h f\n" +
"endstream\n" +
"endobj\n"
);
});
it("should render a new free Highlight annotation for printing", async function () {
partialEvaluator.xref = new XRefMock();
const task = new WorkerTask("test free Highlight printing");
const highlightAnnotation = (
await AnnotationFactory.printNewAnnotations(
annotationGlobalsMock,
partialEvaluator,
task,
[
{
annotationType: AnnotationEditorType.HIGHLIGHT,
rect: [12, 34, 56, 78],
rotation: 0,
opacity: 0.5,
color: [0, 255, 0],
thickness: 3.14,
quadPoints: null,
outlines: {
outline: Float64Array.from([
NaN,
NaN,
8,
9,
10,
11,
NaN,
NaN,
12,
13,
14,
15,
]),
points: [Float64Array.from([16, 17, 18, 19])],
},
},
]
)
)[0];
const { opList } = await highlightAnnotation.getOperatorList(
partialEvaluator,
task,
RenderingIntentFlag.PRINT,
false,
null
);
expect(opList.argsArray.length).toEqual(6);
expect(opList.fnArray).toEqual([
OPS.beginAnnotation,
OPS.setFillRGBColor,
OPS.setGState,
OPS.constructPath,
OPS.fill,
OPS.endAnnotation,
]);
});
});
describe("UnderlineAnnotation", function () {