mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-24 09:08:07 +02:00
Add the possibility to compress/decompress the signature data in order to store them in the logins storage in Firefox (bug 1946171)
This commit is contained in:
parent
b4a6b1ba0b
commit
6b95095e14
15 changed files with 459 additions and 17 deletions
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
import { CommandManager } from "../../src/display/editor/tools.js";
|
||||
import { SignatureExtractor } from "../../src/display/editor/drawers/signaturedraw.js";
|
||||
|
||||
describe("editor", function () {
|
||||
describe("Command Manager", function () {
|
||||
|
@ -90,4 +91,51 @@ describe("editor", function () {
|
|||
manager.add({ ...makeDoUndo(5), mustExec: true });
|
||||
expect(x).toEqual(11);
|
||||
});
|
||||
|
||||
it("should check signature compression/decompression", async () => {
|
||||
let gen = n => new Float32Array(crypto.getRandomValues(new Uint16Array(n)));
|
||||
let outlines = [102, 28, 254, 4536, 10, 14532, 512].map(gen);
|
||||
const signature = {
|
||||
outlines,
|
||||
areContours: false,
|
||||
thickness: 1,
|
||||
width: 123,
|
||||
height: 456,
|
||||
};
|
||||
let compressed = await SignatureExtractor.compressSignature(signature);
|
||||
let decompressed = await SignatureExtractor.decompressSignature(compressed);
|
||||
expect(decompressed).toEqual(signature);
|
||||
|
||||
signature.thickness = 2;
|
||||
compressed = await SignatureExtractor.compressSignature(signature);
|
||||
decompressed = await SignatureExtractor.decompressSignature(compressed);
|
||||
expect(decompressed).toEqual(signature);
|
||||
|
||||
signature.areContours = true;
|
||||
compressed = await SignatureExtractor.compressSignature(signature);
|
||||
decompressed = await SignatureExtractor.decompressSignature(compressed);
|
||||
expect(decompressed).toEqual(signature);
|
||||
|
||||
// Numbers are small enough to be compressed with Uint8Array.
|
||||
gen = n =>
|
||||
new Float32Array(
|
||||
crypto.getRandomValues(new Uint8Array(n)).map(x => x / 10)
|
||||
);
|
||||
outlines = [100, 200, 300, 10, 80].map(gen);
|
||||
signature.outlines = outlines;
|
||||
compressed = await SignatureExtractor.compressSignature(signature);
|
||||
decompressed = await SignatureExtractor.decompressSignature(compressed);
|
||||
expect(decompressed).toEqual(signature);
|
||||
|
||||
// Numbers are large enough to be compressed with Uint16Array.
|
||||
gen = n =>
|
||||
new Float32Array(
|
||||
crypto.getRandomValues(new Uint16Array(n)).map(x => x / 10)
|
||||
);
|
||||
outlines = [100, 200, 300, 10, 80].map(gen);
|
||||
signature.outlines = outlines;
|
||||
compressed = await SignatureExtractor.compressSignature(signature);
|
||||
decompressed = await SignatureExtractor.decompressSignature(compressed);
|
||||
expect(decompressed).toEqual(signature);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -22,6 +22,7 @@ import {
|
|||
AnnotationType,
|
||||
createValidAbsoluteUrl,
|
||||
FeatureTest,
|
||||
getUuid,
|
||||
ImageKind,
|
||||
InvalidPDFException,
|
||||
normalizeUnicode,
|
||||
|
@ -63,6 +64,7 @@ import { ColorPicker } from "../../src/display/editor/color_picker.js";
|
|||
import { DOMSVGFactory } from "../../src/display/svg_factory.js";
|
||||
import { DrawLayer } from "../../src/display/draw_layer.js";
|
||||
import { GlobalWorkerOptions } from "../../src/display/worker_options.js";
|
||||
import { SignatureExtractor } from "../../src/display/editor/drawers/signaturedraw.js";
|
||||
import { TextLayer } from "../../src/display/text_layer.js";
|
||||
import { TouchManager } from "../../src/display/touch_manager.js";
|
||||
import { XfaLayer } from "../../src/display/xfa_layer.js";
|
||||
|
@ -87,6 +89,7 @@ const expectedAPI = Object.freeze({
|
|||
getDocument,
|
||||
getFilenameFromUrl,
|
||||
getPdfFilenameFromUrl,
|
||||
getUuid,
|
||||
getXfaPageViewport,
|
||||
GlobalWorkerOptions,
|
||||
ImageKind,
|
||||
|
@ -107,6 +110,7 @@ const expectedAPI = Object.freeze({
|
|||
ResponseException,
|
||||
setLayerDimensions,
|
||||
shadow,
|
||||
SignatureExtractor,
|
||||
stopEvent,
|
||||
SupportedImageMimeTypes,
|
||||
TextLayer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue