2017-01-10 01:40:57 +09:00
|
|
|
|
/* Copyright 2017 Mozilla Foundation
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
2017-04-17 05:30:27 +09:00
|
|
|
|
|
|
|
|
|
import {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
Annotation,
|
|
|
|
|
AnnotationBorderStyle,
|
|
|
|
|
AnnotationFactory,
|
|
|
|
|
getQuadPoints,
|
|
|
|
|
MarkupAnnotation,
|
2020-01-02 20:00:16 +09:00
|
|
|
|
} from "../../src/core/annotation.js";
|
2017-04-17 05:30:27 +09:00
|
|
|
|
import {
|
|
|
|
|
AnnotationBorderStyleType,
|
2022-06-01 22:42:46 +09:00
|
|
|
|
AnnotationEditorType,
|
2017-04-17 05:30:27 +09:00
|
|
|
|
AnnotationFieldFlag,
|
|
|
|
|
AnnotationFlag,
|
|
|
|
|
AnnotationType,
|
2020-07-23 00:10:59 +09:00
|
|
|
|
OPS,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag,
|
2017-04-17 05:30:27 +09:00
|
|
|
|
stringToBytes,
|
|
|
|
|
stringToUTF8String,
|
2020-01-02 20:00:16 +09:00
|
|
|
|
} from "../../src/shared/util.js";
|
2020-12-11 10:32:18 +09:00
|
|
|
|
import {
|
2023-01-30 22:12:06 +09:00
|
|
|
|
CMAP_URL,
|
2020-12-11 10:32:18 +09:00
|
|
|
|
createIdFactory,
|
|
|
|
|
STANDARD_FONT_DATA_URL,
|
|
|
|
|
XRefMock,
|
|
|
|
|
} from "./test_utils.js";
|
|
|
|
|
import {
|
|
|
|
|
DefaultCMapReaderFactory,
|
|
|
|
|
DefaultStandardFontDataFactory,
|
|
|
|
|
} from "../../src/display/api.js";
|
2020-08-05 21:40:31 +09:00
|
|
|
|
import { Dict, Name, Ref, RefSetCache } from "../../src/core/primitives.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
|
import { Lexer, Parser } from "../../src/core/parser.js";
|
2024-01-28 21:47:00 +09:00
|
|
|
|
import { FlateStream } from "../../src/core/flate_stream.js";
|
2020-07-23 00:10:59 +09:00
|
|
|
|
import { PartialEvaluator } from "../../src/core/evaluator.js";
|
2020-01-02 20:00:16 +09:00
|
|
|
|
import { StringStream } from "../../src/core/stream.js";
|
2020-07-23 00:10:59 +09:00
|
|
|
|
import { WorkerTask } from "../../src/core/worker.js";
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("annotation", function () {
|
2018-03-21 09:43:40 +09:00
|
|
|
|
class PDFManagerMock {
|
|
|
|
|
constructor(params) {
|
2020-07-23 00:10:59 +09:00
|
|
|
|
this.pdfDocument = {
|
2020-08-23 06:33:19 +09:00
|
|
|
|
catalog: {
|
2023-09-07 21:14:35 +09:00
|
|
|
|
baseUrl: params.docBaseUrl || null,
|
2020-08-23 06:33:19 +09:00
|
|
|
|
},
|
2020-07-23 00:10:59 +09:00
|
|
|
|
};
|
2022-10-19 00:07:47 +09:00
|
|
|
|
this.evaluatorOptions = {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
isEvalSupported: true,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
isOffscreenCanvasSupported: false,
|
|
|
|
|
};
|
2018-03-21 09:43:40 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ensure(obj, prop, args) {
|
2020-04-14 19:28:14 +09:00
|
|
|
|
return new Promise(function (resolve) {
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const value = obj[prop];
|
|
|
|
|
if (typeof value === "function") {
|
|
|
|
|
resolve(value.apply(obj, args));
|
|
|
|
|
} else {
|
|
|
|
|
resolve(value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-07-23 00:10:59 +09:00
|
|
|
|
|
2020-08-23 06:33:19 +09:00
|
|
|
|
ensureCatalog(prop, args) {
|
|
|
|
|
return this.ensure(this.pdfDocument.catalog, prop, args);
|
2020-07-23 00:10:59 +09:00
|
|
|
|
}
|
2020-10-29 03:16:56 +09:00
|
|
|
|
|
|
|
|
|
ensureDoc(prop, args) {
|
|
|
|
|
return this.ensure(this.pdfDocument, prop, args);
|
|
|
|
|
}
|
2020-07-23 00:10:59 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 10:32:18 +09:00
|
|
|
|
const fontDataReader = new DefaultStandardFontDataFactory({
|
|
|
|
|
baseUrl: STANDARD_FONT_DATA_URL,
|
|
|
|
|
});
|
|
|
|
|
|
2023-09-07 21:14:35 +09:00
|
|
|
|
class HandlerMock {
|
|
|
|
|
constructor() {
|
|
|
|
|
this.inputs = [];
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 00:10:59 +09:00
|
|
|
|
send(name, data) {
|
|
|
|
|
this.inputs.push({ name, data });
|
2023-09-07 21:14:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 10:32:18 +09:00
|
|
|
|
sendWithPromise(name, data) {
|
|
|
|
|
if (name !== "FetchStandardFontData") {
|
|
|
|
|
return Promise.reject(new Error(`Unsupported mock ${name}.`));
|
|
|
|
|
}
|
|
|
|
|
return fontDataReader.fetch(data);
|
2023-09-07 21:14:35 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-01 19:05:07 +09:00
|
|
|
|
|
2023-09-07 21:14:35 +09:00
|
|
|
|
let annotationGlobalsMock, pdfManagerMock, idFactoryMock, partialEvaluator;
|
2016-05-25 00:35:45 +09:00
|
|
|
|
|
2021-03-21 19:33:39 +09:00
|
|
|
|
beforeAll(async function () {
|
2016-10-01 19:05:07 +09:00
|
|
|
|
pdfManagerMock = new PDFManagerMock({
|
|
|
|
|
docBaseUrl: null,
|
|
|
|
|
});
|
2020-08-27 23:04:17 +09:00
|
|
|
|
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock =
|
|
|
|
|
await AnnotationFactory.createGlobals(pdfManagerMock);
|
|
|
|
|
|
2021-01-09 01:12:58 +09:00
|
|
|
|
const CMapReaderFactory = new DefaultCMapReaderFactory({
|
2023-01-30 22:12:06 +09:00
|
|
|
|
baseUrl: CMAP_URL,
|
2021-01-09 01:12:58 +09:00
|
|
|
|
});
|
2020-08-27 23:04:17 +09:00
|
|
|
|
|
|
|
|
|
const builtInCMapCache = new Map();
|
|
|
|
|
builtInCMapCache.set(
|
|
|
|
|
"UniJIS-UTF16-H",
|
2021-01-09 01:12:58 +09:00
|
|
|
|
await CMapReaderFactory.fetch({ name: "UniJIS-UTF16-H" })
|
2020-08-27 23:04:17 +09:00
|
|
|
|
);
|
|
|
|
|
builtInCMapCache.set(
|
|
|
|
|
"Adobe-Japan1-UCS2",
|
2021-01-09 01:12:58 +09:00
|
|
|
|
await CMapReaderFactory.fetch({ name: "Adobe-Japan1-UCS2" })
|
2020-08-27 23:04:17 +09:00
|
|
|
|
);
|
|
|
|
|
|
2019-04-20 19:36:49 +09:00
|
|
|
|
idFactoryMock = createIdFactory(/* pageIndex = */ 0);
|
2020-07-23 00:10:59 +09:00
|
|
|
|
partialEvaluator = new PartialEvaluator({
|
|
|
|
|
xref: new XRefMock(),
|
|
|
|
|
handler: new HandlerMock(),
|
|
|
|
|
pageIndex: 0,
|
|
|
|
|
idFactory: createIdFactory(/* pageIndex = */ 0),
|
2020-08-05 21:40:31 +09:00
|
|
|
|
fontCache: new RefSetCache(),
|
2020-08-27 23:04:17 +09:00
|
|
|
|
builtInCMapCache,
|
2021-06-08 20:58:52 +09:00
|
|
|
|
standardFontDataCache: new Map(),
|
2023-05-10 22:31:07 +09:00
|
|
|
|
systemFontCache: new Map(),
|
2020-07-23 00:10:59 +09:00
|
|
|
|
});
|
2016-05-25 00:35:45 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterAll(function () {
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock = null;
|
2016-10-01 19:05:07 +09:00
|
|
|
|
pdfManagerMock = null;
|
2017-01-09 00:51:30 +09:00
|
|
|
|
idFactoryMock = null;
|
2020-07-23 00:10:59 +09:00
|
|
|
|
partialEvaluator = null;
|
2016-05-25 00:35:45 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("AnnotationFactory", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should get id for annotation", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-08-26 23:01:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(10, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.id).toEqual("10R");
|
2016-08-26 23:01:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
it(
|
|
|
|
|
"should handle, and get fallback IDs for, annotations that are not " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"indirect objects (issue 7569)",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-08-26 23:01:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock();
|
2019-04-20 19:36:49 +09:00
|
|
|
|
const idFactory = createIdFactory(/* pageIndex = */ 0);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const annotation1 = AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
annotationDict,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactory
|
|
|
|
|
).then(({ data }) => {
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.id).toEqual("annot_p0_1");
|
|
|
|
|
});
|
2016-08-26 23:01:25 +09:00
|
|
|
|
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const annotation2 = AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
annotationDict,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactory
|
|
|
|
|
).then(({ data }) => {
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.id).toEqual("annot_p0_2");
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
await Promise.all([annotation1, annotation2]);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle missing /Subtype", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-07-24 21:32:48 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(1, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toBeUndefined();
|
2016-07-24 21:32:48 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("getQuadPoints", function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
let dict, rect;
|
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
|
beforeEach(function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
dict = new Dict();
|
|
|
|
|
rect = [];
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterEach(function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
dict = null;
|
|
|
|
|
rect = null;
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should ignore missing quadpoints", function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
expect(getQuadPoints(dict, rect)).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should ignore non-array values", function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
dict.set("QuadPoints", "foo");
|
|
|
|
|
expect(getQuadPoints(dict, rect)).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should ignore arrays where the length is not a multiple of eight", function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
dict.set("QuadPoints", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
|
|
|
expect(getQuadPoints(dict, rect)).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should ignore quadpoints if one coordinate lies outside the rectangle", function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
rect = [10, 10, 20, 20];
|
|
|
|
|
const inputs = [
|
|
|
|
|
[11, 11, 12, 12, 9, 13, 14, 14], // Smaller than lower x coordinate.
|
|
|
|
|
[11, 11, 12, 12, 13, 9, 14, 14], // Smaller than lower y coordinate.
|
|
|
|
|
[11, 11, 12, 12, 21, 13, 14, 14], // Larger than upper x coordinate.
|
|
|
|
|
[11, 11, 12, 12, 13, 21, 14, 14], // Larger than upper y coordinate.
|
|
|
|
|
];
|
|
|
|
|
for (const input of inputs) {
|
|
|
|
|
dict.set("QuadPoints", input);
|
|
|
|
|
expect(getQuadPoints(dict, rect)).toEqual(null);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-12-06 05:27:38 +09:00
|
|
|
|
it("should process quadpoints in the standard order", function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
rect = [10, 10, 20, 20];
|
2021-05-16 17:58:34 +09:00
|
|
|
|
dict.set(
|
|
|
|
|
"QuadPoints",
|
|
|
|
|
[10, 20, 20, 20, 10, 10, 20, 10, 11, 19, 19, 19, 11, 11, 19, 11]
|
|
|
|
|
);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
expect(getQuadPoints(dict, rect)).toEqual([
|
|
|
|
|
[
|
2020-12-06 05:27:38 +09:00
|
|
|
|
{ x: 10, y: 20 },
|
|
|
|
|
{ x: 20, y: 20 },
|
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
|
{ x: 20, y: 10 },
|
2019-07-28 03:57:52 +09:00
|
|
|
|
],
|
|
|
|
|
[
|
2020-12-06 05:27:38 +09:00
|
|
|
|
{ x: 11, y: 19 },
|
|
|
|
|
{ x: 19, y: 19 },
|
|
|
|
|
{ x: 11, y: 11 },
|
|
|
|
|
{ x: 19, y: 11 },
|
2019-07-28 03:57:52 +09:00
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
});
|
2020-12-06 05:27:38 +09:00
|
|
|
|
|
|
|
|
|
it("should normalize and process quadpoints in non-standard orders", function () {
|
|
|
|
|
rect = [10, 10, 20, 20];
|
|
|
|
|
const nonStandardOrders = [
|
|
|
|
|
// Bottom left, bottom right, top right and top left.
|
|
|
|
|
[10, 20, 20, 20, 20, 10, 10, 10],
|
|
|
|
|
|
|
|
|
|
// Top left, top right, bottom left and bottom right.
|
|
|
|
|
[10, 10, 20, 10, 10, 20, 20, 20],
|
|
|
|
|
|
|
|
|
|
// Top left, top right, bottom right and bottom left.
|
|
|
|
|
[10, 10, 20, 10, 20, 20, 10, 20],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const nonStandardOrder of nonStandardOrders) {
|
|
|
|
|
dict.set("QuadPoints", nonStandardOrder);
|
|
|
|
|
expect(getQuadPoints(dict, rect)).toEqual([
|
|
|
|
|
[
|
|
|
|
|
{ x: 10, y: 20 },
|
|
|
|
|
{ x: 20, y: 20 },
|
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
|
{ x: 20, y: 10 },
|
|
|
|
|
],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("Annotation", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
let dict, ref;
|
2016-07-24 21:32:48 +09:00
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
|
beforeAll(function () {
|
2016-07-24 21:32:48 +09:00
|
|
|
|
dict = new Dict();
|
2019-05-26 00:40:14 +09:00
|
|
|
|
ref = Ref.get(1, 0);
|
2016-07-24 21:32:48 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterAll(function () {
|
2016-07-24 21:32:48 +09:00
|
|
|
|
dict = ref = null;
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get valid contents", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2019-05-18 22:52:17 +09:00
|
|
|
|
annotation.setContents("Foo bar baz");
|
|
|
|
|
|
2021-09-25 00:30:56 +09:00
|
|
|
|
expect(annotation._contents).toEqual({ str: "Foo bar baz", dir: "ltr" });
|
2019-05-18 22:52:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get invalid contents", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2019-05-18 22:52:17 +09:00
|
|
|
|
annotation.setContents(undefined);
|
|
|
|
|
|
2021-09-25 00:30:56 +09:00
|
|
|
|
expect(annotation._contents).toEqual({ str: "", dir: "ltr" });
|
2019-05-18 22:52:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a valid modification date", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2019-04-22 04:21:01 +09:00
|
|
|
|
annotation.setModificationDate("D:20190422");
|
|
|
|
|
|
|
|
|
|
expect(annotation.modificationDate).toEqual("D:20190422");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid modification date", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2019-04-22 04:21:01 +09:00
|
|
|
|
annotation.setModificationDate(undefined);
|
|
|
|
|
|
|
|
|
|
expect(annotation.modificationDate).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get flags", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-11-22 07:25:17 +09:00
|
|
|
|
annotation.setFlags(13);
|
|
|
|
|
|
|
|
|
|
expect(annotation.hasFlag(AnnotationFlag.INVISIBLE)).toEqual(true);
|
|
|
|
|
expect(annotation.hasFlag(AnnotationFlag.NOZOOM)).toEqual(true);
|
|
|
|
|
expect(annotation.hasFlag(AnnotationFlag.PRINT)).toEqual(true);
|
|
|
|
|
expect(annotation.hasFlag(AnnotationFlag.READONLY)).toEqual(false);
|
2020-10-01 03:58:45 +09:00
|
|
|
|
expect(annotation.hasFlag(AnnotationFlag.HIDDEN)).toEqual(false);
|
2015-11-22 07:25:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should be viewable and not printable by default", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-11-22 07:25:17 +09:00
|
|
|
|
|
|
|
|
|
expect(annotation.viewable).toEqual(true);
|
|
|
|
|
expect(annotation.printable).toEqual(false);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a valid rectangle", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-21 05:01:47 +09:00
|
|
|
|
annotation.setRectangle([117, 694, 164.298, 720]);
|
|
|
|
|
|
|
|
|
|
expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid rectangle", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-21 05:01:47 +09:00
|
|
|
|
annotation.setRectangle([117, 694, 164.298]);
|
|
|
|
|
|
|
|
|
|
expect(annotation.rectangle).toEqual([0, 0, 0, 0]);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should reject a color if it is not an array", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-15 23:59:25 +09:00
|
|
|
|
annotation.setColor("red");
|
|
|
|
|
|
2018-06-12 00:25:40 +09:00
|
|
|
|
expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
2015-07-15 23:59:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a transparent color", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-15 23:59:25 +09:00
|
|
|
|
annotation.setColor([]);
|
|
|
|
|
|
|
|
|
|
expect(annotation.color).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a grayscale color", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-15 23:59:25 +09:00
|
|
|
|
annotation.setColor([0.4]);
|
|
|
|
|
|
2018-06-12 00:25:40 +09:00
|
|
|
|
expect(annotation.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
|
2015-07-15 23:59:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get an RGB color", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-15 23:59:25 +09:00
|
|
|
|
annotation.setColor([0, 0, 1]);
|
|
|
|
|
|
2018-06-12 00:25:40 +09:00
|
|
|
|
expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
2015-07-15 23:59:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a CMYK color", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-15 23:59:25 +09:00
|
|
|
|
annotation.setColor([0.1, 0.92, 0.84, 0.02]);
|
|
|
|
|
|
2018-06-12 00:25:40 +09:00
|
|
|
|
expect(annotation.color).toEqual(new Uint8ClampedArray([234, 59, 48]));
|
2015-07-15 23:59:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid color", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const annotation = new Annotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2015-07-15 23:59:25 +09:00
|
|
|
|
annotation.setColor([0.4, 0.6]);
|
|
|
|
|
|
2018-06-12 00:25:40 +09:00
|
|
|
|
expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
|
2015-07-15 23:59:25 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("AnnotationBorderStyle", function () {
|
|
|
|
|
it("should set and get a valid width", function () {
|
2021-12-24 22:10:19 +09:00
|
|
|
|
const borderStyleInt = new AnnotationBorderStyle();
|
|
|
|
|
borderStyleInt.setWidth(3);
|
|
|
|
|
const borderStyleNum = new AnnotationBorderStyle();
|
|
|
|
|
borderStyleNum.setWidth(2.5);
|
2014-12-26 05:04:01 +09:00
|
|
|
|
|
2021-12-24 22:10:19 +09:00
|
|
|
|
expect(borderStyleInt.width).toEqual(3);
|
|
|
|
|
expect(borderStyleNum.width).toEqual(2.5);
|
2014-12-26 05:04:01 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid width", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setWidth("three");
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.width).toEqual(1);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set the width to zero, when the input is a `Name` (issue 10385)", function () {
|
2019-01-04 18:33:15 +09:00
|
|
|
|
const borderStyleZero = new AnnotationBorderStyle();
|
|
|
|
|
borderStyleZero.setWidth(Name.get("0"));
|
|
|
|
|
const borderStyleFive = new AnnotationBorderStyle();
|
|
|
|
|
borderStyleFive.setWidth(Name.get("5"));
|
2018-12-31 20:21:28 +09:00
|
|
|
|
|
2019-01-04 18:33:15 +09:00
|
|
|
|
expect(borderStyleZero.width).toEqual(0);
|
|
|
|
|
expect(borderStyleFive.width).toEqual(0);
|
2018-12-31 20:21:28 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a valid style", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2015-07-18 04:51:24 +09:00
|
|
|
|
borderStyle.setStyle(Name.get("D"));
|
2014-12-26 05:04:01 +09:00
|
|
|
|
|
|
|
|
|
expect(borderStyle.style).toEqual(AnnotationBorderStyleType.DASHED);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid style", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setStyle("Dashed");
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.style).toEqual(AnnotationBorderStyleType.SOLID);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a valid dash array", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setDashArray([1, 2, 3]);
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.dashArray).toEqual([1, 2, 3]);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid dash array", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setDashArray([0, 0]);
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.dashArray).toEqual([3]);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a valid horizontal corner radius", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setHorizontalCornerRadius(3);
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.horizontalCornerRadius).toEqual(3);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid horizontal corner radius", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setHorizontalCornerRadius("three");
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.horizontalCornerRadius).toEqual(0);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a valid vertical corner radius", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setVerticalCornerRadius(3);
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.verticalCornerRadius).toEqual(3);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid vertical corner radius", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const borderStyle = new AnnotationBorderStyle();
|
2014-12-26 05:04:01 +09:00
|
|
|
|
borderStyle.setVerticalCornerRadius("three");
|
|
|
|
|
|
|
|
|
|
expect(borderStyle.verticalCornerRadius).toEqual(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-02-15 05:27:53 +09:00
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("MarkupAnnotation", function () {
|
2019-05-25 22:25:52 +09:00
|
|
|
|
let dict, ref;
|
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
|
beforeAll(function () {
|
2019-05-25 22:25:52 +09:00
|
|
|
|
dict = new Dict();
|
2019-05-26 00:40:14 +09:00
|
|
|
|
ref = Ref.get(1, 0);
|
2019-05-25 22:25:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterAll(function () {
|
2019-05-25 22:25:52 +09:00
|
|
|
|
dict = ref = null;
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should set and get a valid creation date", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const markupAnnotation = new MarkupAnnotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2019-05-25 22:25:52 +09:00
|
|
|
|
markupAnnotation.setCreationDate("D:20190422");
|
|
|
|
|
|
|
|
|
|
expect(markupAnnotation.creationDate).toEqual("D:20190422");
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
it("should not set and get an invalid creation date", function () {
|
2023-07-06 20:03:11 +09:00
|
|
|
|
const markupAnnotation = new MarkupAnnotation({
|
|
|
|
|
dict,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals: annotationGlobalsMock,
|
2023-07-06 20:03:11 +09:00
|
|
|
|
evaluatorOptions: pdfManagerMock.evaluatorOptions,
|
|
|
|
|
});
|
2019-05-25 22:25:52 +09:00
|
|
|
|
markupAnnotation.setCreationDate(undefined);
|
|
|
|
|
|
|
|
|
|
expect(markupAnnotation.creationDate).toEqual(null);
|
|
|
|
|
});
|
2019-05-15 04:14:35 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should not parse IRT/RT when not defined", async function () {
|
2019-05-15 04:14:35 +09:00
|
|
|
|
dict.set("Type", Name.get("Annot"));
|
|
|
|
|
dict.set("Subtype", Name.get("Text"));
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([{ ref, data: dict }]);
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
ref,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
idFactoryMock
|
2019-05-15 04:14:35 +09:00
|
|
|
|
);
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.inReplyTo).toBeUndefined();
|
|
|
|
|
expect(data.replyType).toBeUndefined();
|
2019-05-15 04:14:35 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should parse IRT and set default RT when not defined", async function () {
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const annotationRef = Ref.get(819, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const replyRef = Ref.get(820, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const replyDict = new Dict();
|
|
|
|
|
replyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
replyDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
replyDict.set("IRT", annotationRef);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
{ ref: replyRef, data: replyDict },
|
|
|
|
|
]);
|
|
|
|
|
annotationDict.assignXref(xref);
|
|
|
|
|
replyDict.assignXref(xref);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-05-15 04:14:35 +09:00
|
|
|
|
xref,
|
|
|
|
|
replyRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
|
|
|
|
expect(data.replyType).toEqual("R");
|
2019-05-15 04:14:35 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should parse IRT/RT for a group type", async function () {
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const annotationRef = Ref.get(819, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
annotationDict.set("T", "ParentTitle");
|
|
|
|
|
annotationDict.set("Contents", "ParentText");
|
|
|
|
|
annotationDict.set("CreationDate", "D:20180423");
|
|
|
|
|
annotationDict.set("M", "D:20190423");
|
|
|
|
|
annotationDict.set("C", [0, 0, 1]);
|
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const popupRef = Ref.get(820, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const popupDict = new Dict();
|
|
|
|
|
popupDict.set("Type", Name.get("Annot"));
|
|
|
|
|
popupDict.set("Subtype", Name.get("Popup"));
|
|
|
|
|
popupDict.set("Parent", annotationRef);
|
|
|
|
|
annotationDict.set("Popup", popupRef);
|
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const replyRef = Ref.get(821, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const replyDict = new Dict();
|
|
|
|
|
replyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
replyDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
replyDict.set("IRT", annotationRef);
|
|
|
|
|
replyDict.set("RT", Name.get("Group"));
|
|
|
|
|
replyDict.set("T", "ReplyTitle");
|
|
|
|
|
replyDict.set("Contents", "ReplyText");
|
|
|
|
|
replyDict.set("CreationDate", "D:20180523");
|
|
|
|
|
replyDict.set("M", "D:20190523");
|
|
|
|
|
replyDict.set("C", [0.4]);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
{ ref: popupRef, data: popupDict },
|
|
|
|
|
{ ref: replyRef, data: replyDict },
|
|
|
|
|
]);
|
|
|
|
|
annotationDict.assignXref(xref);
|
|
|
|
|
popupDict.assignXref(xref);
|
|
|
|
|
replyDict.assignXref(xref);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-05-15 04:14:35 +09:00
|
|
|
|
xref,
|
|
|
|
|
replyRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
|
|
|
|
expect(data.replyType).toEqual("Group");
|
2021-09-25 00:30:56 +09:00
|
|
|
|
expect(data.titleObj).toEqual({ str: "ParentTitle", dir: "ltr" });
|
|
|
|
|
expect(data.contentsObj).toEqual({ str: "ParentText", dir: "ltr" });
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.creationDate).toEqual("D:20180423");
|
|
|
|
|
expect(data.modificationDate).toEqual("D:20190423");
|
|
|
|
|
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
2023-06-15 18:59:59 +09:00
|
|
|
|
expect(data.popupRef).toEqual("820R");
|
2019-05-15 04:14:35 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should parse IRT/RT for a reply type", async function () {
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const annotationRef = Ref.get(819, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
annotationDict.set("T", "ParentTitle");
|
|
|
|
|
annotationDict.set("Contents", "ParentText");
|
|
|
|
|
annotationDict.set("CreationDate", "D:20180423");
|
|
|
|
|
annotationDict.set("M", "D:20190423");
|
|
|
|
|
annotationDict.set("C", [0, 0, 1]);
|
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const popupRef = Ref.get(820, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const popupDict = new Dict();
|
|
|
|
|
popupDict.set("Type", Name.get("Annot"));
|
|
|
|
|
popupDict.set("Subtype", Name.get("Popup"));
|
|
|
|
|
popupDict.set("Parent", annotationRef);
|
|
|
|
|
annotationDict.set("Popup", popupRef);
|
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const replyRef = Ref.get(821, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const replyDict = new Dict();
|
|
|
|
|
replyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
replyDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
replyDict.set("IRT", annotationRef);
|
|
|
|
|
replyDict.set("RT", Name.get("R"));
|
|
|
|
|
replyDict.set("T", "ReplyTitle");
|
|
|
|
|
replyDict.set("Contents", "ReplyText");
|
|
|
|
|
replyDict.set("CreationDate", "D:20180523");
|
|
|
|
|
replyDict.set("M", "D:20190523");
|
|
|
|
|
replyDict.set("C", [0.4]);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
{ ref: popupRef, data: popupDict },
|
|
|
|
|
{ ref: replyRef, data: replyDict },
|
|
|
|
|
]);
|
|
|
|
|
annotationDict.assignXref(xref);
|
|
|
|
|
popupDict.assignXref(xref);
|
|
|
|
|
replyDict.assignXref(xref);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-05-15 04:14:35 +09:00
|
|
|
|
xref,
|
|
|
|
|
replyRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
|
|
|
|
expect(data.replyType).toEqual("R");
|
2021-09-25 00:30:56 +09:00
|
|
|
|
expect(data.titleObj).toEqual({ str: "ReplyTitle", dir: "ltr" });
|
|
|
|
|
expect(data.contentsObj).toEqual({ str: "ReplyText", dir: "ltr" });
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.creationDate).toEqual("D:20180523");
|
|
|
|
|
expect(data.modificationDate).toEqual("D:20190523");
|
|
|
|
|
expect(data.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
|
2023-06-15 18:59:59 +09:00
|
|
|
|
expect(data.popupRef).toEqual(null);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("TextAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should not parse state model and state when not defined", async function () {
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const annotationRef = Ref.get(819, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
annotationDict.set("Contents", "TestText");
|
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const replyRef = Ref.get(820, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const replyDict = new Dict();
|
|
|
|
|
replyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
replyDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
replyDict.set("IRT", annotationRef);
|
|
|
|
|
replyDict.set("RT", Name.get("R"));
|
|
|
|
|
replyDict.set("Contents", "ReplyText");
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
{ ref: replyRef, data: replyDict },
|
|
|
|
|
]);
|
|
|
|
|
annotationDict.assignXref(xref);
|
|
|
|
|
replyDict.assignXref(xref);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-05-15 04:14:35 +09:00
|
|
|
|
xref,
|
|
|
|
|
replyRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.stateModel).toBeNull();
|
|
|
|
|
expect(data.state).toBeNull();
|
2019-05-15 04:14:35 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse state model and state when defined", async function () {
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const annotationRef = Ref.get(819, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const replyRef = Ref.get(820, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const replyDict = new Dict();
|
|
|
|
|
replyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
replyDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
replyDict.set("IRT", annotationRef);
|
|
|
|
|
replyDict.set("RT", Name.get("R"));
|
|
|
|
|
replyDict.set("StateModel", "Review");
|
|
|
|
|
replyDict.set("State", "Rejected");
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
{ ref: replyRef, data: replyDict },
|
|
|
|
|
]);
|
|
|
|
|
annotationDict.assignXref(xref);
|
|
|
|
|
replyDict.assignXref(xref);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-05-15 04:14:35 +09:00
|
|
|
|
xref,
|
|
|
|
|
replyRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.stateModel).toEqual("Review");
|
|
|
|
|
expect(data.state).toEqual("Rejected");
|
2019-05-15 04:14:35 +09:00
|
|
|
|
});
|
2019-05-25 22:25:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("LinkAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a URI action", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("URI"));
|
|
|
|
|
actionDict.set("URI", "http://www.ctan.org/tex-archive/info/lshort");
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(820, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toEqual("http://www.ctan.org/tex-archive/info/lshort");
|
|
|
|
|
expect(data.unsafeUrl).toEqual(
|
|
|
|
|
"http://www.ctan.org/tex-archive/info/lshort"
|
|
|
|
|
);
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it(
|
|
|
|
|
"should correctly parse a URI action, where the URI entry " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"is missing a protocol",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("URI"));
|
|
|
|
|
actionDict.set("URI", "www.hmrc.gov.uk");
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
2016-08-26 23:01:25 +09:00
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
2016-03-26 18:00:25 +09:00
|
|
|
|
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const annotationRef = Ref.get(353, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
]);
|
2016-03-26 18:00:25 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
xref,
|
2016-08-26 23:01:25 +09:00
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2017-01-09 00:51:30 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toEqual("http://www.hmrc.gov.uk/");
|
2021-09-26 21:16:28 +09:00
|
|
|
|
expect(data.unsafeUrl).toEqual("www.hmrc.gov.uk");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.dest).toBeUndefined();
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2016-09-30 18:44:24 +09:00
|
|
|
|
it(
|
|
|
|
|
"should correctly parse a URI action, where the URI entry " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"has an incorrect encoding (bug 1122280)",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionStream = new StringStream(
|
2016-09-30 18:44:24 +09:00
|
|
|
|
"<<\n" +
|
|
|
|
|
"/Type /Action\n" +
|
|
|
|
|
"/S /URI\n" +
|
|
|
|
|
"/URI (http://www.example.com/\\303\\274\\303\\266\\303\\244)\n" +
|
|
|
|
|
">>\n"
|
|
|
|
|
);
|
2019-06-23 23:01:45 +09:00
|
|
|
|
const parser = new Parser({
|
|
|
|
|
lexer: new Lexer(actionStream),
|
|
|
|
|
xref: null,
|
|
|
|
|
});
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = parser.getObj();
|
2016-09-30 18:44:24 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-09-30 18:44:24 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(8, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-09-30 18:44:24 +09:00
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toEqual(
|
|
|
|
|
new URL(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
stringToUTF8String(
|
|
|
|
|
"http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4"
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
)
|
2021-04-18 01:23:40 +09:00
|
|
|
|
).href
|
|
|
|
|
);
|
|
|
|
|
expect(data.unsafeUrl).toEqual(
|
2021-09-26 21:16:28 +09:00
|
|
|
|
"http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
2016-09-30 18:44:24 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a GoTo action", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("GoTo"));
|
|
|
|
|
actionDict.set("D", "page.157");
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(798, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toBeUndefined();
|
|
|
|
|
expect(data.unsafeUrl).toBeUndefined();
|
|
|
|
|
expect(data.dest).toEqual("page.157");
|
2016-03-26 18:00:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it(
|
|
|
|
|
"should correctly parse a GoToR action, where the FileSpec entry " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"is a string containing a relative URL",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("GoToR"));
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
actionDict.set("F", "../../0013/001346/134685E.pdf");
|
|
|
|
|
actionDict.set("D", "4.3");
|
|
|
|
|
actionDict.set("NewWindow", true);
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(489, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-08-26 23:01:25 +09:00
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
]);
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toBeUndefined();
|
|
|
|
|
expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
|
|
|
|
expect(data.newWindow).toEqual(true);
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2016-10-01 19:05:07 +09:00
|
|
|
|
it(
|
|
|
|
|
"should correctly parse a GoToR action, containing a relative URL, " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
'with the "docBaseUrl" parameter specified',
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-10-01 19:05:07 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("GoToR"));
|
|
|
|
|
actionDict.set("F", "../../0013/001346/134685E.pdf");
|
|
|
|
|
actionDict.set("D", "4.3");
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-10-01 19:05:07 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(489, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-10-01 19:05:07 +09:00
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
]);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const pdfManager = new PDFManagerMock({
|
2016-10-01 19:05:07 +09:00
|
|
|
|
docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf",
|
|
|
|
|
});
|
2023-09-07 21:14:35 +09:00
|
|
|
|
const annotationGlobals =
|
|
|
|
|
await AnnotationFactory.createGlobals(pdfManager);
|
2016-10-01 19:05:07 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toEqual(
|
|
|
|
|
"http://www.example.com/0013/001346/134685E.pdf#4.3"
|
|
|
|
|
);
|
|
|
|
|
expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
2016-10-01 19:05:07 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a GoToR action, with named destination", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("GoToR"));
|
|
|
|
|
actionDict.set("F", "http://www.example.com/test.pdf");
|
2016-03-26 18:00:25 +09:00
|
|
|
|
actionDict.set("D", "15");
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(495, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toEqual("http://www.example.com/test.pdf#15");
|
|
|
|
|
expect(data.unsafeUrl).toEqual("http://www.example.com/test.pdf#15");
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
|
|
|
|
expect(data.newWindow).toBeFalsy();
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a GoToR action, with explicit destination array", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("GoToR"));
|
|
|
|
|
actionDict.set("F", "http://www.example.com/test.pdf");
|
|
|
|
|
actionDict.set("D", [14, Name.get("XYZ"), null, 298.043, null]);
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
[api-minor] Let `LinkAnnotation`/`PDFLinkService_getDestinationHash` return a stringified version of the destination array for explicit destinations
Currently for explicit destinations, compared to named destinations, we manually try to build a hash that often times is a quite poor representation of the *actual* destination. (Currently this only, kind of, works for `\XYZ` destinations.)
For PDF files using explicit destinations, this can make it difficult/impossible to obtain a link to a specific section of the document through the URL.
Note that in practice most PDF files, especially newer ones, use named destinations and these are thus unnaffected by this patch.
This patch also fixes an existing issue in `PDFLinkService_getDestinationHash`, where a named destination consisting of only a number would not be handled correctly.
With the added, and already existing, type checks in place for destinations, I really don't think that this patch exposes any "sensitive" internal destination code not already accessible through normal hash parameters.
*Please note:* Just trying to improve the algorithm that generates the hash is unfortunately not possible in general, since there are a number of cases where it will simply never work well.
- First of all, note that `getDestinationHash` currently relies on the `_pagesRefCache`, hence it's possible that the hash returned is empty during e.g. ranged/streamed loading of a PDF file.
- Second of all, the currently computed hash is actually dependent on the document rotation. With named destinations, the fetched internal destination array is rotational invariant (as it should be), but this will not hold in general for the hash. We can easily avoid this issue by using a stringified destination array.
- Third of all, note that according to the PDF specification[1], `GoToR` destinations may actually contain explicit destination arrays. Since we cannot really construct a hash in `annotation.js`, we currently have no good way to support those. Even though this case seems *very* rare in practice (I've not actually seen such a PDF file), it's in the specification, and this patch allows us to support that for "free".
---
[1] http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G11.1951685
2016-05-15 19:12:47 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(489, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2016-10-21 20:29:15 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toEqual(
|
|
|
|
|
new URL(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"http://www.example.com/test.pdf#" +
|
|
|
|
|
'[14,{"name":"XYZ"},null,298.043,null]'
|
2021-04-18 01:23:40 +09:00
|
|
|
|
).href
|
|
|
|
|
);
|
|
|
|
|
expect(data.unsafeUrl).toEqual(
|
|
|
|
|
"http://www.example.com/test.pdf#" +
|
|
|
|
|
'[14,{"name":"XYZ"},null,298.043,null]'
|
|
|
|
|
);
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
|
|
|
|
expect(data.newWindow).toBeFalsy();
|
2016-10-21 20:29:15 +09:00
|
|
|
|
});
|
2016-03-26 18:00:25 +09:00
|
|
|
|
|
2016-11-09 00:38:22 +09:00
|
|
|
|
it(
|
|
|
|
|
"should correctly parse a Launch action, where the FileSpec dict " +
|
|
|
|
|
'contains a relative URL, with the "docBaseUrl" parameter specified',
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const fileSpecDict = new Dict();
|
|
|
|
|
fileSpecDict.set("Type", Name.get("FileSpec"));
|
2016-10-21 20:29:15 +09:00
|
|
|
|
fileSpecDict.set("F", "Part II/Part II.pdf");
|
2018-08-12 01:50:31 +09:00
|
|
|
|
fileSpecDict.set("UF", "Part II/Part II.pdf");
|
2016-11-09 00:38:22 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-11-09 00:38:22 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("Launch"));
|
|
|
|
|
actionDict.set("F", fileSpecDict);
|
|
|
|
|
actionDict.set("NewWindow", true);
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-11-09 00:38:22 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(88, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-11-09 00:38:22 +09:00
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
]);
|
2016-10-01 19:05:07 +09:00
|
|
|
|
const pdfManager = new PDFManagerMock({
|
2016-10-21 20:29:15 +09:00
|
|
|
|
docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf",
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
});
|
2023-09-07 21:14:35 +09:00
|
|
|
|
const annotationGlobals =
|
|
|
|
|
await AnnotationFactory.createGlobals(pdfManager);
|
2016-11-09 00:38:22 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobals,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toEqual(
|
|
|
|
|
new URL("http://www.example.com/test/pdfs/Part II/Part II.pdf").href
|
|
|
|
|
);
|
|
|
|
|
expect(data.unsafeUrl).toEqual("Part II/Part II.pdf");
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
|
|
|
|
expect(data.newWindow).toEqual(true);
|
2016-11-09 00:38:22 +09:00
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
it(
|
2016-11-09 00:38:22 +09:00
|
|
|
|
"should recover valid URLs from JavaScript actions having certain " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"white-listed formats",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2016-11-09 00:38:22 +09:00
|
|
|
|
function checkJsAction(params) {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const jsEntry = params.jsEntry;
|
|
|
|
|
const expectedUrl = params.expectedUrl;
|
|
|
|
|
const expectedUnsafeUrl = params.expectedUnsafeUrl;
|
|
|
|
|
const expectedNewWindow = params.expectedNewWindow;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("JavaScript"));
|
2016-10-21 20:29:15 +09:00
|
|
|
|
actionDict.set("JS", jsEntry);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-09-30 23:32:22 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
2016-03-26 18:00:25 +09:00
|
|
|
|
annotationDict.set("A", actionDict);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(46, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2019-05-15 04:14:35 +09:00
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
]);
|
2016-11-09 00:38:22 +09:00
|
|
|
|
|
|
|
|
|
return AnnotationFactory.create(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
xref,
|
2016-11-09 00:38:22 +09:00
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2016-11-09 00:38:22 +09:00
|
|
|
|
idFactoryMock
|
2018-03-21 09:43:40 +09:00
|
|
|
|
).then(({ data }) => {
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
2016-11-09 00:38:22 +09:00
|
|
|
|
expect(data.url).toEqual(expectedUrl);
|
|
|
|
|
expect(data.unsafeUrl).toEqual(expectedUnsafeUrl);
|
|
|
|
|
expect(data.dest).toBeUndefined();
|
2017-02-27 20:08:41 +09:00
|
|
|
|
expect(data.newWindow).toEqual(expectedNewWindow);
|
2016-11-09 00:38:22 +09:00
|
|
|
|
});
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
}
|
2018-03-21 09:43:40 +09:00
|
|
|
|
|
2016-11-09 00:38:22 +09:00
|
|
|
|
// Check that we reject a 'JS' entry containing arbitrary JavaScript.
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const annotation1 = checkJsAction({
|
2016-11-09 00:38:22 +09:00
|
|
|
|
jsEntry: 'function someFun() { return "qwerty"; } someFun();',
|
|
|
|
|
expectedUrl: undefined,
|
|
|
|
|
expectedUnsafeUrl: undefined,
|
2017-02-27 20:08:41 +09:00
|
|
|
|
expectedNewWindow: undefined,
|
2016-11-09 00:38:22 +09:00
|
|
|
|
});
|
2018-03-21 09:43:40 +09:00
|
|
|
|
|
2016-11-09 00:38:22 +09:00
|
|
|
|
// Check that we accept a white-listed {string} 'JS' entry.
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const annotation2 = checkJsAction({
|
2016-11-09 00:38:22 +09:00
|
|
|
|
jsEntry: "window.open('http://www.example.com/test.pdf')",
|
|
|
|
|
expectedUrl: new URL("http://www.example.com/test.pdf").href,
|
|
|
|
|
expectedUnsafeUrl: "http://www.example.com/test.pdf",
|
2021-09-25 21:46:40 +09:00
|
|
|
|
expectedNewWindow: false,
|
2016-11-09 00:38:22 +09:00
|
|
|
|
});
|
2018-03-21 09:43:40 +09:00
|
|
|
|
|
|
|
|
|
// Check that we accept a white-listed {Stream} 'JS' entry.
|
|
|
|
|
const annotation3 = checkJsAction({
|
|
|
|
|
jsEntry: new StringStream(
|
|
|
|
|
'app.launchURL("http://www.example.com/test.pdf", true)'
|
|
|
|
|
),
|
|
|
|
|
expectedUrl: new URL("http://www.example.com/test.pdf").href,
|
|
|
|
|
expectedUnsafeUrl: "http://www.example.com/test.pdf",
|
|
|
|
|
expectedNewWindow: true,
|
2016-11-09 00:38:22 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
await Promise.all([annotation1, annotation2, annotation3]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a Named action", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const actionDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
actionDict.set("Type", Name.get("Action"));
|
|
|
|
|
actionDict.set("S", Name.get("Named"));
|
|
|
|
|
actionDict.set("N", Name.get("GoToPage"));
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("A", actionDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(12, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toBeUndefined();
|
|
|
|
|
expect(data.unsafeUrl).toBeUndefined();
|
|
|
|
|
expect(data.action).toEqual("GoToPage");
|
2016-03-26 18:00:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a simple Dest", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("Dest", Name.get("LI0"));
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const annotationRef = Ref.get(583, 0);
|
2016-08-26 23:01:25 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toBeUndefined();
|
|
|
|
|
expect(data.unsafeUrl).toBeUndefined();
|
|
|
|
|
expect(data.dest).toEqual("LI0");
|
2016-03-26 18:00:25 +09:00
|
|
|
|
});
|
2016-09-30 23:32:22 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a simple Dest, with explicit destination array", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-09-30 23:32:22 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
2019-05-26 00:40:14 +09:00
|
|
|
|
annotationDict.set("Dest", [
|
|
|
|
|
Ref.get(17, 0),
|
|
|
|
|
Name.get("XYZ"),
|
2016-09-30 23:32:22 +09:00
|
|
|
|
0,
|
|
|
|
|
841.89,
|
|
|
|
|
null,
|
|
|
|
|
]);
|
|
|
|
|
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const annotationRef = Ref.get(10, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toBeUndefined();
|
|
|
|
|
expect(data.unsafeUrl).toBeUndefined();
|
|
|
|
|
expect(data.dest).toEqual([
|
2021-05-12 00:08:26 +09:00
|
|
|
|
Ref.get(17, 0),
|
|
|
|
|
Name.get("XYZ"),
|
2021-04-18 01:23:40 +09:00
|
|
|
|
0,
|
|
|
|
|
841.89,
|
|
|
|
|
null,
|
|
|
|
|
]);
|
2016-09-30 23:32:22 +09:00
|
|
|
|
});
|
2017-08-25 20:40:50 +09:00
|
|
|
|
|
|
|
|
|
it(
|
|
|
|
|
"should correctly parse a Dest, which violates the specification " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"by containing a dictionary",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
|
const destDict = new Dict();
|
2017-08-25 20:40:50 +09:00
|
|
|
|
destDict.set("Type", Name.get("Action"));
|
|
|
|
|
destDict.set("S", Name.get("GoTo"));
|
|
|
|
|
destDict.set("D", "page.157");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2017-08-25 20:40:50 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
// The /Dest must be a Name or an Array, refer to ISO 32000-1:2008
|
|
|
|
|
// section 12.3.3, but there are PDF files where it's a dictionary.
|
|
|
|
|
annotationDict.set("Dest", destDict);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2020-01-24 17:48:21 +09:00
|
|
|
|
const annotationRef = Ref.get(798, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
|
|
|
|
]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.url).toBeUndefined();
|
|
|
|
|
expect(data.unsafeUrl).toBeUndefined();
|
|
|
|
|
expect(data.dest).toEqual("page.157");
|
2017-08-25 20:40:50 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should not set quadpoints if not defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
|
|
|
|
|
const annotationRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.quadPoints).toBeUndefined();
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints if defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const annotationDict = new Dict();
|
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
|
|
|
|
annotationDict.set("Subtype", Name.get("Link"));
|
|
|
|
|
annotationDict.set("Rect", [10, 10, 20, 20]);
|
2020-12-06 05:27:38 +09:00
|
|
|
|
annotationDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
|
|
|
|
|
const annotationRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: annotationRef, data: annotationDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
annotationRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINK);
|
|
|
|
|
expect(data.quadPoints).toEqual([
|
|
|
|
|
[
|
|
|
|
|
{ x: 10, y: 20 },
|
|
|
|
|
{ x: 20, y: 20 },
|
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
|
{ x: 20, y: 10 },
|
|
|
|
|
],
|
|
|
|
|
]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
2016-03-26 18:00:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("WidgetAnnotation", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
let widgetDict;
|
2016-11-02 08:07:31 +09:00
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
|
beforeEach(function () {
|
2016-11-02 08:07:31 +09:00
|
|
|
|
widgetDict = new Dict();
|
|
|
|
|
widgetDict.set("Type", Name.get("Annot"));
|
|
|
|
|
widgetDict.set("Subtype", Name.get("Widget"));
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterEach(function () {
|
2016-11-02 08:07:31 +09:00
|
|
|
|
widgetDict = null;
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle unknown field names", async function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const widgetRef = Ref.get(20, 0);
|
2016-11-02 08:07:31 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: widgetRef, data: widgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
widgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.fieldName).toEqual("");
|
2016-11-02 08:07:31 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should construct the field name when there are no ancestors", async function () {
|
2016-11-02 08:07:31 +09:00
|
|
|
|
widgetDict.set("T", "foo");
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const widgetRef = Ref.get(21, 0);
|
2016-11-02 08:07:31 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: widgetRef, data: widgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
widgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.fieldName).toEqual("foo");
|
2016-11-02 08:07:31 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should construct the field name when there are ancestors", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const firstParent = new Dict();
|
2016-11-02 08:07:31 +09:00
|
|
|
|
firstParent.set("T", "foo");
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const secondParent = new Dict();
|
2016-11-02 08:07:31 +09:00
|
|
|
|
secondParent.set("Parent", firstParent);
|
|
|
|
|
secondParent.set("T", "bar");
|
|
|
|
|
|
|
|
|
|
widgetDict.set("Parent", secondParent);
|
|
|
|
|
widgetDict.set("T", "baz");
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const widgetRef = Ref.get(22, 0);
|
2016-11-02 08:07:31 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: widgetRef, data: widgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
widgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.fieldName).toEqual("foo.bar.baz");
|
2016-11-02 08:07:31 +09:00
|
|
|
|
});
|
2017-03-10 07:51:52 +09:00
|
|
|
|
|
|
|
|
|
it(
|
|
|
|
|
"should construct the field name if a parent is not a dictionary " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"(issue 8143)",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const parentDict = new Dict();
|
2017-03-10 07:51:52 +09:00
|
|
|
|
parentDict.set("Parent", null);
|
|
|
|
|
parentDict.set("T", "foo");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2017-03-10 07:51:52 +09:00
|
|
|
|
widgetDict.set("Parent", parentDict);
|
|
|
|
|
widgetDict.set("T", "bar");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const widgetRef = Ref.get(22, 0);
|
2017-03-10 07:51:52 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: widgetRef, data: widgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
widgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.fieldName).toEqual("foo.bar");
|
2017-03-10 07:51:52 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
2016-11-02 08:07:31 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("TextWidgetAnnotation", function () {
|
2020-08-27 23:04:17 +09:00
|
|
|
|
let textWidgetDict, helvRefObj, gothRefObj;
|
2016-09-13 21:57:11 +09:00
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
|
beforeEach(function () {
|
2016-09-13 21:57:11 +09:00
|
|
|
|
textWidgetDict = new Dict();
|
|
|
|
|
textWidgetDict.set("Type", Name.get("Annot"));
|
|
|
|
|
textWidgetDict.set("Subtype", Name.get("Widget"));
|
|
|
|
|
textWidgetDict.set("FT", Name.get("Tx"));
|
2020-08-05 21:40:31 +09:00
|
|
|
|
|
|
|
|
|
const helvDict = new Dict();
|
|
|
|
|
helvDict.set("BaseFont", Name.get("Helvetica"));
|
|
|
|
|
helvDict.set("Type", Name.get("Font"));
|
|
|
|
|
helvDict.set("Subtype", Name.get("Type1"));
|
|
|
|
|
|
2020-08-27 23:04:17 +09:00
|
|
|
|
const gothDict = new Dict();
|
|
|
|
|
gothDict.set("BaseFont", Name.get("MSGothic"));
|
|
|
|
|
gothDict.set("Type", Name.get("Font"));
|
|
|
|
|
gothDict.set("Subtype", Name.get("Type0"));
|
|
|
|
|
gothDict.set("Encoding", Name.get("UniJIS-UTF16-H"));
|
|
|
|
|
gothDict.set("Name", Name.get("MSGothic"));
|
|
|
|
|
|
|
|
|
|
const cidSysInfoDict = new Dict();
|
|
|
|
|
cidSysInfoDict.set("Ordering", "Japan1");
|
|
|
|
|
cidSysInfoDict.set("Registry", "Adobe");
|
|
|
|
|
cidSysInfoDict.set("Supplement", "5");
|
|
|
|
|
|
|
|
|
|
const fontDescriptorDict = new Dict();
|
|
|
|
|
fontDescriptorDict.set("FontName", Name.get("MSGothic"));
|
|
|
|
|
fontDescriptorDict.set("CapHeight", "680");
|
|
|
|
|
|
|
|
|
|
const gothDescendantDict = new Dict();
|
|
|
|
|
gothDescendantDict.set("BaseFont", Name.get("MSGothic"));
|
|
|
|
|
gothDescendantDict.set("CIDSystemInfo", cidSysInfoDict);
|
|
|
|
|
gothDescendantDict.set("Subtype", Name.get("CIDFontType2"));
|
|
|
|
|
gothDescendantDict.set("Type", Name.get("Font"));
|
|
|
|
|
gothDescendantDict.set("FontDescriptor", fontDescriptorDict);
|
|
|
|
|
|
|
|
|
|
gothDict.set("DescendantFonts", [gothDescendantDict]);
|
|
|
|
|
|
|
|
|
|
const helvRef = Ref.get(314, 0);
|
|
|
|
|
const gothRef = Ref.get(159, 0);
|
|
|
|
|
helvRefObj = { ref: helvRef, data: helvDict };
|
|
|
|
|
gothRefObj = { ref: gothRef, data: gothDict };
|
2020-08-05 21:40:31 +09:00
|
|
|
|
const resourceDict = new Dict();
|
|
|
|
|
const fontDict = new Dict();
|
2020-08-27 23:04:17 +09:00
|
|
|
|
fontDict.set("Helv", helvRef);
|
2020-08-05 21:40:31 +09:00
|
|
|
|
resourceDict.set("Font", fontDict);
|
|
|
|
|
|
|
|
|
|
textWidgetDict.set("DA", "/Helv 5 Tf");
|
|
|
|
|
textWidgetDict.set("DR", resourceDict);
|
|
|
|
|
textWidgetDict.set("Rect", [0, 0, 32, 10]);
|
2016-09-13 21:57:11 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterEach(function () {
|
2020-08-27 23:04:17 +09:00
|
|
|
|
textWidgetDict = helvRefObj = gothRefObj = null;
|
2016-09-13 21:57:11 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle unknown text alignment, maximum length and flags", async function () {
|
2020-11-04 00:53:21 +09:00
|
|
|
|
textWidgetDict.set("DV", "foo");
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const textWidgetRef = Ref.get(124, 0);
|
2016-09-13 21:57:11 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: textWidgetRef, data: textWidgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.textAlignment).toEqual(null);
|
2022-08-19 02:27:53 +09:00
|
|
|
|
expect(data.maxLen).toEqual(0);
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.readOnly).toEqual(false);
|
|
|
|
|
expect(data.hidden).toEqual(false);
|
|
|
|
|
expect(data.multiLine).toEqual(false);
|
|
|
|
|
expect(data.comb).toEqual(false);
|
|
|
|
|
expect(data.defaultFieldValue).toEqual("foo");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not set invalid text alignment, maximum length and flags", async function () {
|
2016-09-13 21:57:11 +09:00
|
|
|
|
textWidgetDict.set("Q", "center");
|
|
|
|
|
textWidgetDict.set("MaxLen", "five");
|
2016-09-15 04:51:21 +09:00
|
|
|
|
textWidgetDict.set("Ff", "readonly");
|
2016-09-13 21:57:11 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const textWidgetRef = Ref.get(43, 0);
|
2016-09-13 21:57:11 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: textWidgetRef, data: textWidgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.textAlignment).toEqual(null);
|
2022-08-19 02:27:53 +09:00
|
|
|
|
expect(data.maxLen).toEqual(0);
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.readOnly).toEqual(false);
|
|
|
|
|
expect(data.hidden).toEqual(false);
|
|
|
|
|
expect(data.multiLine).toEqual(false);
|
|
|
|
|
expect(data.comb).toEqual(false);
|
2016-09-13 21:57:11 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set valid text alignment, maximum length and flags", async function () {
|
2016-09-13 21:57:11 +09:00
|
|
|
|
textWidgetDict.set("Q", 1);
|
|
|
|
|
textWidgetDict.set("MaxLen", 20);
|
2016-09-22 04:06:44 +09:00
|
|
|
|
textWidgetDict.set(
|
|
|
|
|
"Ff",
|
|
|
|
|
AnnotationFieldFlag.READONLY + AnnotationFieldFlag.MULTILINE
|
|
|
|
|
);
|
2016-09-13 21:57:11 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const textWidgetRef = Ref.get(84, 0);
|
2016-09-13 21:57:11 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: textWidgetRef, data: textWidgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.textAlignment).toEqual(1);
|
|
|
|
|
expect(data.maxLen).toEqual(20);
|
|
|
|
|
expect(data.readOnly).toEqual(true);
|
|
|
|
|
expect(data.hidden).toEqual(false);
|
|
|
|
|
expect(data.multiLine).toEqual(true);
|
2016-09-13 21:57:11 +09:00
|
|
|
|
});
|
2016-09-20 07:04:11 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should reject comb fields without a maximum length", async function () {
|
2016-09-22 04:06:44 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.COMB);
|
2016-09-20 07:04:11 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const textWidgetRef = Ref.get(46, 0);
|
2016-09-20 07:04:11 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: textWidgetRef, data: textWidgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.comb).toEqual(false);
|
2016-09-20 07:04:11 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should accept comb fields with a maximum length", async function () {
|
2016-09-20 07:04:11 +09:00
|
|
|
|
textWidgetDict.set("MaxLen", 20);
|
2016-09-22 04:06:44 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.COMB);
|
2016-09-20 07:04:11 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const textWidgetRef = Ref.get(46, 0);
|
2016-09-20 07:04:11 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: textWidgetRef, data: textWidgetDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.comb).toEqual(true);
|
2016-09-20 07:04:11 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should only accept comb fields when the flags are valid", async function () {
|
2020-01-24 17:48:21 +09:00
|
|
|
|
const invalidFieldFlags = [
|
2018-03-21 09:43:40 +09:00
|
|
|
|
AnnotationFieldFlag.MULTILINE,
|
|
|
|
|
AnnotationFieldFlag.PASSWORD,
|
|
|
|
|
AnnotationFieldFlag.FILESELECT,
|
2016-09-20 07:04:11 +09:00
|
|
|
|
];
|
|
|
|
|
|
2016-09-22 04:06:44 +09:00
|
|
|
|
// Start with all invalid flags set and remove them one by one.
|
|
|
|
|
// The field may only use combs when all invalid flags are unset.
|
2018-08-12 01:50:31 +09:00
|
|
|
|
let flags =
|
|
|
|
|
AnnotationFieldFlag.COMB +
|
|
|
|
|
AnnotationFieldFlag.MULTILINE +
|
2016-09-22 04:06:44 +09:00
|
|
|
|
AnnotationFieldFlag.PASSWORD +
|
|
|
|
|
AnnotationFieldFlag.FILESELECT;
|
2016-09-20 07:04:11 +09:00
|
|
|
|
|
2018-03-21 09:43:40 +09:00
|
|
|
|
let promise = Promise.resolve();
|
|
|
|
|
for (let i = 0, ii = invalidFieldFlags.length; i <= ii; i++) {
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
|
textWidgetDict.set("MaxLen", 20);
|
|
|
|
|
textWidgetDict.set("Ff", flags);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const textWidgetRef = Ref.get(93, 0);
|
2018-03-21 09:43:40 +09:00
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
).then(({ data }) => {
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
|
|
|
|
|
const valid = invalidFieldFlags.length === 0;
|
|
|
|
|
expect(data.comb).toEqual(valid);
|
|
|
|
|
|
|
|
|
|
// Remove the last invalid flag for the next iteration.
|
|
|
|
|
if (!valid) {
|
2018-10-24 20:08:08 +09:00
|
|
|
|
flags -= invalidFieldFlags.pop();
|
2018-03-21 09:43:40 +09:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-09-20 07:04:11 +09:00
|
|
|
|
}
|
2021-04-18 01:23:40 +09:00
|
|
|
|
await promise;
|
2016-09-20 07:04:11 +09:00
|
|
|
|
});
|
2020-08-05 21:40:31 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render regular text for printing", async function () {
|
2020-08-05 21:40:31 +09:00
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
2020-08-27 23:04:17 +09:00
|
|
|
|
helvRefObj,
|
2020-08-05 21:40:31 +09:00
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-05 21:40:31 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-05 21:40:31 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "test\\print" });
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
" 2 3.07 Td (test\\\\print) Tj ET Q EMC"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render regular text in Japanese for printing", async function () {
|
2020-08-27 23:04:17 +09:00
|
|
|
|
textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
|
|
|
|
|
textWidgetDict.set("DA", "/Goth 5 Tf");
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
gothRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-27 23:04:17 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-27 23:04:17 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value: "こんにちは世界の",
|
|
|
|
|
});
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
const utf16String =
|
|
|
|
|
"\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
"/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 0 Tm" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
` 2 3.07 Td (${utf16String}) Tj ET Q EMC`
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render regular text for printing using normal appearance", async function () {
|
2020-09-20 00:47:38 +09:00
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
|
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
const normalAppearanceStream = new StringStream("0.1 0.2 0.3 rg");
|
|
|
|
|
normalAppearanceStream.dict = normalAppearanceDict;
|
|
|
|
|
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceStream);
|
|
|
|
|
textWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
2020-08-27 23:04:17 +09:00
|
|
|
|
helvRefObj,
|
2020-09-20 00:47:38 +09:00
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-09-20 00:47:38 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-20 00:47:38 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"271R",
|
|
|
|
|
[0, 0, 32, 10],
|
|
|
|
|
[32, 0, 0, 10, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
|
2020-09-20 00:47:38 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render auto-sized text for printing", async function () {
|
2020-08-05 21:40:31 +09:00
|
|
|
|
textWidgetDict.set("DA", "/Helv 0 Tf");
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
2020-08-27 23:04:17 +09:00
|
|
|
|
helvRefObj,
|
2020-08-05 21:40:31 +09:00
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-05 21:40:31 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-05 21:40:31 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "test (print)" });
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
2022-01-28 06:51:30 +09:00
|
|
|
|
"/Tx BMC q BT /Helv 5.92 Tf 0 g 1 0 0 1 0 0 Tm" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
" 2 3.07 Td (test \\(print\\)) Tj ET Q EMC"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render auto-sized text in Japanese for printing", async function () {
|
2020-08-27 23:04:17 +09:00
|
|
|
|
textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
|
|
|
|
|
textWidgetDict.set("DA", "/Goth 0 Tf");
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
gothRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-27 23:04:17 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-27 23:04:17 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value: "こんにちは世界の",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
const utf16String =
|
|
|
|
|
"\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
|
|
|
|
|
expect(appearance).toEqual(
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"/Tx BMC q BT /Goth 5.92 Tf 0 g 1 0 0 1 0 0 Tm" +
|
|
|
|
|
` 2 3.07 Td (${utf16String}) Tj ET Q EMC`
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should not render a password for printing", async function () {
|
2020-08-05 21:40:31 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.PASSWORD);
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
2020-08-27 23:04:17 +09:00
|
|
|
|
helvRefObj,
|
2020-08-05 21:40:31 +09:00
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-05 21:40:31 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-05 21:40:31 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "mypassword" });
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render multiline text for printing", async function () {
|
2020-08-06 23:07:13 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.MULTILINE);
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
2020-08-27 23:04:17 +09:00
|
|
|
|
helvRefObj,
|
2020-08-06 23:07:13 +09:00
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-06 23:07:13 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-06 23:07:13 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value:
|
|
|
|
|
"a aa aaa aaaa aaaaa aaaaaa " +
|
|
|
|
|
"pneumonoultramicroscopicsilicovolcanoconiosis",
|
|
|
|
|
});
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 10 Tm " +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"2 -6.93 Td (a aa aaa ) Tj\n" +
|
|
|
|
|
"0 -8 Td (aaaa aaaaa ) Tj\n" +
|
|
|
|
|
"0 -8 Td (aaaaaa ) Tj\n" +
|
|
|
|
|
"0 -8 Td (pneumonoultr) Tj\n" +
|
|
|
|
|
"0 -8 Td (amicroscopi) Tj\n" +
|
|
|
|
|
"0 -8 Td (csilicovolca) Tj\n" +
|
|
|
|
|
"0 -8 Td (noconiosis) Tj ET Q EMC"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render multiline text in Japanese for printing", async function () {
|
2020-08-27 23:04:17 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.MULTILINE);
|
|
|
|
|
textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
|
|
|
|
|
textWidgetDict.set("DA", "/Goth 5 Tf");
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
gothRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-27 23:04:17 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-27 23:04:17 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value: "こんにちは世界の",
|
|
|
|
|
});
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
"/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 10 Tm " +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"2 -6.93 Td (\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f) Tj\n" +
|
|
|
|
|
"0 -8 Td (\x4e\x16\x75\x4c\x30\x6e) Tj ET Q EMC"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render multiline text with various EOL for printing", async function () {
|
2020-08-06 23:07:13 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.MULTILINE);
|
|
|
|
|
textWidgetDict.set("Rect", [0, 0, 128, 10]);
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
2020-08-27 23:04:17 +09:00
|
|
|
|
helvRefObj,
|
2020-08-06 23:07:13 +09:00
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const expectedAppearance =
|
|
|
|
|
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 10 Tm " +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"2 -6.93 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(Lorem ipsum dolor sit amet, consectetur adipiscing elit.) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(Aliquam vitae felis ac lectus bibendum ultricies quis non) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"( diam.) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(Morbi id porttitor quam, a iaculis dui.) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(Pellentesque habitant morbi tristique senectus et netus ) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(et malesuada fames ac turpis egestas.) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td () Tj\n" +
|
|
|
|
|
"0 -8 Td () Tj\n" +
|
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(Nulla consectetur, ligula in tincidunt placerat, velit ) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(augue consectetur orci, sed mattis libero nunc ut massa.) Tj\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"0 -8 Td " +
|
2020-08-06 23:07:13 +09:00
|
|
|
|
"(Etiam facilisis tempus interdum.) Tj ET Q EMC";
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-06 23:07:13 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-06 23:07:13 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value:
|
|
|
|
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r" +
|
|
|
|
|
"Aliquam vitae felis ac lectus bibendum ultricies quis non diam.\n" +
|
|
|
|
|
"Morbi id porttitor quam, a iaculis dui.\r\n" +
|
|
|
|
|
"Pellentesque habitant morbi tristique senectus et " +
|
|
|
|
|
"netus et malesuada fames ac turpis egestas.\n\r\n\r" +
|
|
|
|
|
"Nulla consectetur, ligula in tincidunt placerat, " +
|
|
|
|
|
"velit augue consectetur orci, sed mattis libero nunc ut massa.\r" +
|
|
|
|
|
"Etiam facilisis tempus interdum.",
|
|
|
|
|
});
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-10-19 00:07:47 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(appearance).toEqual(expectedAppearance);
|
2020-08-06 23:07:13 +09:00
|
|
|
|
});
|
2020-08-06 23:45:17 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render comb for printing", async function () {
|
2020-08-06 23:45:17 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.COMB);
|
|
|
|
|
textWidgetDict.set("MaxLen", 4);
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
2020-08-27 23:04:17 +09:00
|
|
|
|
helvRefObj,
|
2020-08-06 23:45:17 +09:00
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-06 23:45:17 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-06 23:45:17 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "aa(aa)a\\" });
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 2 3.07 Tm" +
|
2022-05-18 06:10:02 +09:00
|
|
|
|
" (a) Tj 8 0 Td (a) Tj 8 0 Td (\\() Tj" +
|
|
|
|
|
" 8 0 Td (a) Tj 8 0 Td (a) Tj" +
|
|
|
|
|
" 8 0 Td (\\)) Tj 8 0 Td (a) Tj" +
|
|
|
|
|
" 8 0 Td (\\\\) Tj ET Q EMC"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render comb with Japanese text for printing", async function () {
|
2020-08-27 23:04:17 +09:00
|
|
|
|
textWidgetDict.set("Ff", AnnotationFieldFlag.COMB);
|
|
|
|
|
textWidgetDict.set("MaxLen", 4);
|
|
|
|
|
textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
|
|
|
|
|
textWidgetDict.set("DA", "/Goth 5 Tf");
|
|
|
|
|
textWidgetDict.set("Rect", [0, 0, 32, 10]);
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
gothRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-27 23:04:17 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-27 23:04:17 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value: "こんにちは世界の",
|
|
|
|
|
});
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"/Tx BMC q BT /Goth 5 Tf 1 0 0 1 2 3.07 Tm" +
|
2022-05-18 06:10:02 +09:00
|
|
|
|
" (\x30\x53) Tj 8 0 Td (\x30\x93) Tj 8 0 Td (\x30\x6b) Tj" +
|
|
|
|
|
" 8 0 Td (\x30\x61) Tj 8 0 Td (\x30\x6f) Tj" +
|
|
|
|
|
" 8 0 Td (\x4e\x16) Tj 8 0 Td (\x75\x4c) Tj" +
|
|
|
|
|
" 8 0 Td (\x30\x6e) Tj ET Q EMC"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should save text", async function () {
|
2020-08-04 02:44:04 +09:00
|
|
|
|
const textWidgetRef = Ref.get(123, 0);
|
2020-08-27 23:04:17 +09:00
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
helvRefObj,
|
|
|
|
|
]);
|
2020-08-04 02:44:04 +09:00
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-04 02:44:04 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-04 02:44:04 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "hello world" });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [oldData, newData] = data;
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(newData.ref).toEqual(Ref.get(2, 0));
|
|
|
|
|
|
2021-09-02 18:41:20 +09:00
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Tx /DA (/Helv 5 Tf) /DR " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> /Rect [0 0 32 10] " +
|
|
|
|
|
"/V (hello world) /AP << /N 2 0 R>> /M (date)>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
expect(newData.data).toEqual(
|
2023-02-08 03:26:46 +09:00
|
|
|
|
"2 0 obj\n<< /Subtype /Form /Resources " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Length 74>> stream\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2 3.07 Td (hello world) Tj " +
|
2021-04-18 01:23:40 +09:00
|
|
|
|
"ET Q EMC\nendstream\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-19 23:39:54 +09:00
|
|
|
|
it("should save rotated text", async function () {
|
|
|
|
|
const textWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
helvRefObj,
|
|
|
|
|
]);
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
|
|
|
|
const annotation = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2022-06-19 23:39:54 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value: "hello world",
|
|
|
|
|
rotation: 90,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [oldData, newData] = data;
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(newData.ref).toEqual(Ref.get(2, 0));
|
|
|
|
|
|
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Tx /DA (/Helv 5 Tf) /DR " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> /Rect [0 0 32 10] " +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"/V (hello world) /MK << /R 90>> /AP << /N 2 0 R>> /M (date)>>\nendobj\n"
|
2022-06-19 23:39:54 +09:00
|
|
|
|
);
|
|
|
|
|
expect(newData.data).toEqual(
|
2023-02-08 03:26:46 +09:00
|
|
|
|
"2 0 obj\n<< /Subtype /Form /Resources " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] /Matrix [0 1 -1 0 32 0] /Length 74>> stream\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2 2.94 Td (hello world) Tj " +
|
2022-06-19 23:39:54 +09:00
|
|
|
|
"ET Q EMC\nendstream\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2023-04-28 04:50:27 +09:00
|
|
|
|
it("should compress and save text", async function () {
|
|
|
|
|
const textWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
helvRefObj,
|
|
|
|
|
]);
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
|
|
|
|
const annotation = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2023-04-28 04:50:27 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
const value = "a".repeat(256);
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [oldData, newData] = data;
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(newData.ref).toEqual(Ref.get(2, 0));
|
|
|
|
|
|
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Tx /DA (/Helv 5 Tf) /DR " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> /Rect [0 0 32 10] " +
|
|
|
|
|
`/V (${value}) /AP << /N 2 0 R>> /M (date)>>\nendobj\n`
|
|
|
|
|
);
|
|
|
|
|
|
2024-01-28 21:47:00 +09:00
|
|
|
|
const compressedStream = newData.data.substring(
|
|
|
|
|
newData.data.indexOf("stream\n") + "stream\n".length,
|
|
|
|
|
newData.data.indexOf("\nendstream")
|
|
|
|
|
);
|
|
|
|
|
// Ensure that the data was in fact (significantly) compressed.
|
|
|
|
|
expect(compressedStream.length).toBeLessThan(value.length / 3);
|
|
|
|
|
|
2023-04-28 04:50:27 +09:00
|
|
|
|
expect(newData.data).toEqual(
|
|
|
|
|
"2 0 obj\n<< /Subtype /Form /Resources " +
|
2024-01-28 21:47:00 +09:00
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> /BBox [0 0 32 10] " +
|
|
|
|
|
`/Filter /FlateDecode /Length ${compressedStream.length}>> stream\n` +
|
2023-04-28 04:50:27 +09:00
|
|
|
|
`${compressedStream}\nendstream\nendobj\n`
|
|
|
|
|
);
|
2024-01-28 21:47:00 +09:00
|
|
|
|
|
|
|
|
|
// Given that the exact compression-output may differ between environments
|
|
|
|
|
// and browsers, ensure that the resulting data can be correctly decoded
|
|
|
|
|
// by our `FlateStream`-implementation since that simulates opening the
|
|
|
|
|
// generated data with the PDF.js library.
|
|
|
|
|
const flateStream = new FlateStream(new StringStream(compressedStream));
|
|
|
|
|
expect(flateStream.getString()).toEqual(
|
|
|
|
|
`/Tx BMC q BT /Helv 5 Tf 1 0 0 1 0 0 Tm 2 3.07 Td (${value}) Tj ET Q EMC`
|
|
|
|
|
);
|
2023-04-28 04:50:27 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should get field object for usage in JS sandbox", async function () {
|
2020-10-01 03:58:45 +09:00
|
|
|
|
const textWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xDictRef = Ref.get(141, 0);
|
|
|
|
|
const dDictRef = Ref.get(262, 0);
|
|
|
|
|
const next0Ref = Ref.get(314, 0);
|
|
|
|
|
const next1Ref = Ref.get(271, 0);
|
|
|
|
|
const next2Ref = Ref.get(577, 0);
|
|
|
|
|
const next00Ref = Ref.get(413, 0);
|
|
|
|
|
const xDict = new Dict();
|
|
|
|
|
const dDict = new Dict();
|
|
|
|
|
const next0Dict = new Dict();
|
|
|
|
|
const next1Dict = new Dict();
|
|
|
|
|
const next2Dict = new Dict();
|
|
|
|
|
const next00Dict = new Dict();
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
{ ref: xDictRef, data: xDict },
|
|
|
|
|
{ ref: dDictRef, data: dDict },
|
|
|
|
|
{ ref: next0Ref, data: next0Dict },
|
|
|
|
|
{ ref: next00Ref, data: next00Dict },
|
|
|
|
|
{ ref: next1Ref, data: next1Dict },
|
|
|
|
|
{ ref: next2Ref, data: next2Dict },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const JS = Name.get("JavaScript");
|
|
|
|
|
const additionalActionsDict = new Dict();
|
|
|
|
|
const eDict = new Dict();
|
|
|
|
|
eDict.set("JS", "hello()");
|
|
|
|
|
eDict.set("S", JS);
|
|
|
|
|
additionalActionsDict.set("E", eDict);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
// Test the cycle detection here.
|
2020-10-01 03:58:45 +09:00
|
|
|
|
xDict.set("JS", "world()");
|
|
|
|
|
xDict.set("S", JS);
|
|
|
|
|
xDict.set("Next", [next0Ref, next1Ref, next2Ref, xDictRef]);
|
|
|
|
|
|
|
|
|
|
next0Dict.set("JS", "olleh()");
|
|
|
|
|
next0Dict.set("S", JS);
|
|
|
|
|
next0Dict.set("Next", next00Ref);
|
|
|
|
|
|
|
|
|
|
next00Dict.set("JS", "foo()");
|
|
|
|
|
next00Dict.set("S", JS);
|
|
|
|
|
next00Dict.set("Next", next0Ref);
|
|
|
|
|
|
|
|
|
|
next1Dict.set("JS", "dlrow()");
|
|
|
|
|
next1Dict.set("S", JS);
|
|
|
|
|
next1Dict.set("Next", xDictRef);
|
|
|
|
|
|
|
|
|
|
next2Dict.set("JS", "oof()");
|
|
|
|
|
next2Dict.set("S", JS);
|
|
|
|
|
|
|
|
|
|
dDict.set("JS", "bar()");
|
|
|
|
|
dDict.set("S", JS);
|
|
|
|
|
dDict.set("Next", dDictRef);
|
|
|
|
|
additionalActionsDict.set("D", dDictRef);
|
|
|
|
|
|
|
|
|
|
additionalActionsDict.set("X", xDictRef);
|
|
|
|
|
textWidgetDict.set("AA", additionalActionsDict);
|
|
|
|
|
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-10-01 03:58:45 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-10-01 03:58:45 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const fieldObject = await annotation.getFieldObject();
|
|
|
|
|
const actions = fieldObject.actions;
|
|
|
|
|
expect(actions["Mouse Enter"]).toEqual(["hello()"]);
|
|
|
|
|
expect(actions["Mouse Exit"]).toEqual([
|
|
|
|
|
"world()",
|
|
|
|
|
"olleh()",
|
|
|
|
|
"foo()",
|
|
|
|
|
"dlrow()",
|
|
|
|
|
"oof()",
|
|
|
|
|
]);
|
|
|
|
|
expect(actions["Mouse Down"]).toEqual(["bar()"]);
|
2020-10-01 03:58:45 +09:00
|
|
|
|
});
|
2020-08-27 23:04:17 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should save Japanese text", async function () {
|
2020-08-27 23:04:17 +09:00
|
|
|
|
textWidgetDict.get("DR").get("Font").set("Goth", gothRefObj.ref);
|
|
|
|
|
textWidgetDict.set("DA", "/Goth 5 Tf");
|
|
|
|
|
|
|
|
|
|
const textWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: textWidgetRef, data: textWidgetDict },
|
|
|
|
|
gothRefObj,
|
|
|
|
|
]);
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-27 23:04:17 +09:00
|
|
|
|
xref,
|
|
|
|
|
textWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-27 23:04:17 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, {
|
|
|
|
|
value: "こんにちは世界の",
|
|
|
|
|
});
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
const utf16String =
|
|
|
|
|
"\x30\x53\x30\x93\x30\x6b\x30\x61\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [oldData, newData] = data;
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(newData.ref).toEqual(Ref.get(2, 0));
|
|
|
|
|
|
2021-09-02 18:41:20 +09:00
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Tx /DA (/Goth 5 Tf) /DR " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /Rect [0 0 32 10] " +
|
|
|
|
|
`/V (\xfe\xff${utf16String}) /AP << /N 2 0 R>> /M (date)>>\nendobj\n`
|
|
|
|
|
);
|
|
|
|
|
expect(newData.data).toEqual(
|
2023-02-08 03:26:46 +09:00
|
|
|
|
"2 0 obj\n<< /Subtype /Form /Resources " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R /Goth 159 0 R>>>> /BBox [0 0 32 10] /Length 79>> stream\n" +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
`/Tx BMC q BT /Goth 5 Tf 1 0 0 1 0 0 Tm 2 3.07 Td (${utf16String}) Tj ` +
|
2021-04-18 01:23:40 +09:00
|
|
|
|
"ET Q EMC\nendstream\nendobj\n"
|
|
|
|
|
);
|
2020-08-27 23:04:17 +09:00
|
|
|
|
});
|
2016-09-13 21:57:11 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("ButtonWidgetAnnotation", function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
let buttonWidgetDict;
|
2016-11-04 21:01:42 +09:00
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
|
beforeEach(function () {
|
2016-12-16 07:49:46 +09:00
|
|
|
|
buttonWidgetDict = new Dict();
|
|
|
|
|
buttonWidgetDict.set("Type", Name.get("Annot"));
|
|
|
|
|
buttonWidgetDict.set("Subtype", Name.get("Widget"));
|
|
|
|
|
buttonWidgetDict.set("FT", Name.get("Btn"));
|
2016-11-04 21:01:42 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterEach(function () {
|
2016-12-16 07:49:46 +09:00
|
|
|
|
buttonWidgetDict = null;
|
2016-11-04 21:01:42 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle checkboxes with export value", async function () {
|
2021-07-15 02:31:09 +09:00
|
|
|
|
buttonWidgetDict.set("V", Name.get("Checked"));
|
|
|
|
|
buttonWidgetDict.set("DV", Name.get("Off"));
|
2018-07-07 09:51:10 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
2020-08-22 22:45:33 +09:00
|
|
|
|
const normalAppearanceDict = new Dict();
|
2018-07-07 09:51:10 +09:00
|
|
|
|
|
2020-08-22 22:45:33 +09:00
|
|
|
|
normalAppearanceDict.set("Off", 0);
|
|
|
|
|
normalAppearanceDict.set("Checked", 1);
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
2018-07-07 09:51:10 +09:00
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2018-07-07 09:51:10 +09:00
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.checkBox).toEqual(true);
|
2021-07-15 02:31:09 +09:00
|
|
|
|
expect(data.fieldValue).toEqual("Checked");
|
|
|
|
|
expect(data.defaultFieldValue).toEqual("Off");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.radioButton).toEqual(false);
|
|
|
|
|
expect(data.exportValue).toEqual("Checked");
|
2018-07-07 09:51:10 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle checkboxes without export value", async function () {
|
2021-07-15 02:31:09 +09:00
|
|
|
|
buttonWidgetDict.set("V", Name.get("Checked"));
|
|
|
|
|
buttonWidgetDict.set("DV", Name.get("Off"));
|
2016-11-04 21:01:42 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-12-16 07:49:46 +09:00
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
2016-11-04 21:01:42 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.checkBox).toEqual(true);
|
2021-07-15 02:31:09 +09:00
|
|
|
|
expect(data.fieldValue).toEqual("Checked");
|
|
|
|
|
expect(data.defaultFieldValue).toEqual("Off");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.radioButton).toEqual(false);
|
2016-11-04 21:01:42 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle checkboxes without /Off appearance", async function () {
|
2021-07-15 02:31:09 +09:00
|
|
|
|
buttonWidgetDict.set("V", Name.get("Checked"));
|
|
|
|
|
buttonWidgetDict.set("DV", Name.get("Off"));
|
2020-08-22 22:45:33 +09:00
|
|
|
|
|
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
normalAppearanceDict.set("Checked", 1);
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-08-22 22:45:33 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-22 22:45:33 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.checkBox).toEqual(true);
|
2021-07-15 02:31:09 +09:00
|
|
|
|
expect(data.fieldValue).toEqual("Checked");
|
|
|
|
|
expect(data.defaultFieldValue).toEqual("Off");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.radioButton).toEqual(false);
|
|
|
|
|
expect(data.exportValue).toEqual("Checked");
|
2020-08-22 22:45:33 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render checkbox with fallback font for printing", async function () {
|
2020-10-22 00:21:33 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
const checkedAppearanceDict = new Dict();
|
|
|
|
|
const uncheckedAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
const checkedStream = new StringStream("/ 12 Tf (4) Tj");
|
|
|
|
|
checkedStream.dict = checkedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
const uncheckedStream = new StringStream("");
|
|
|
|
|
uncheckedStream.dict = uncheckedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
|
|
|
|
checkedAppearanceDict.set("FormType", 1);
|
|
|
|
|
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
|
|
|
|
normalAppearanceDict.set("Checked", checkedStream);
|
|
|
|
|
normalAppearanceDict.set("Off", uncheckedStream);
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
2021-05-31 18:54:33 +09:00
|
|
|
|
const checkboxEvaluator = partialEvaluator.clone({ ignoreErrors: true });
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-10-22 00:21:33 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-10-22 00:21:33 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true });
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList } = await annotation.getOperatorList(
|
2021-05-31 18:54:33 +09:00
|
|
|
|
checkboxEvaluator,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray.length).toEqual(5);
|
|
|
|
|
expect(opList.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.dependency,
|
|
|
|
|
OPS.setFont,
|
|
|
|
|
OPS.showText,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"124R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[3][0][0].unicode).toEqual("4");
|
2020-10-22 00:21:33 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render checkboxes for printing", async function () {
|
2020-07-23 00:10:59 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
const checkedAppearanceDict = new Dict();
|
2020-07-31 21:39:11 +09:00
|
|
|
|
const uncheckedAppearanceDict = new Dict();
|
2020-07-23 00:10:59 +09:00
|
|
|
|
|
2020-07-31 21:39:11 +09:00
|
|
|
|
const checkedStream = new StringStream("0.1 0.2 0.3 rg");
|
|
|
|
|
checkedStream.dict = checkedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
const uncheckedStream = new StringStream("0.3 0.2 0.1 rg");
|
|
|
|
|
uncheckedStream.dict = uncheckedAppearanceDict;
|
2020-07-23 00:10:59 +09:00
|
|
|
|
|
|
|
|
|
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
|
|
|
|
checkedAppearanceDict.set("FormType", 1);
|
|
|
|
|
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
2020-07-31 21:39:11 +09:00
|
|
|
|
normalAppearanceDict.set("Checked", checkedStream);
|
|
|
|
|
normalAppearanceDict.set("Off", uncheckedStream);
|
2020-07-23 00:10:59 +09:00
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-07-23 00:10:59 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-07-23 00:10:59 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true });
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList: opList1 } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList1.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList1.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList1.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"124R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList1.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
|
2021-04-18 01:23:40 +09:00
|
|
|
|
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: false });
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList: opList2 } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList2.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList2.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList2.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"124R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList2.argsArray[1]).toEqual(new Uint8ClampedArray([76, 51, 26]));
|
2020-07-23 00:10:59 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render checkboxes for printing twice", async function () {
|
2020-09-25 02:13:09 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
const checkedAppearanceDict = new Dict();
|
|
|
|
|
const uncheckedAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
const checkedStream = new StringStream("0.1 0.2 0.3 rg");
|
|
|
|
|
checkedStream.dict = checkedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
const uncheckedStream = new StringStream("0.3 0.2 0.1 rg");
|
|
|
|
|
uncheckedStream.dict = uncheckedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
|
|
|
|
checkedAppearanceDict.set("FormType", 1);
|
|
|
|
|
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
|
|
|
|
normalAppearanceDict.set("Checked", checkedStream);
|
|
|
|
|
normalAppearanceDict.set("Off", uncheckedStream);
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
buttonWidgetDict.set("AS", Name.get("Off"));
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(1249, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-09-25 02:13:09 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-25 02:13:09 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 2; i++) {
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true });
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"1249R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[1]).toEqual(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
new Uint8ClampedArray([26, 51, 76])
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-09-25 02:13:09 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render checkboxes for printing using normal appearance", async function () {
|
2020-09-20 00:47:38 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
const checkedAppearanceDict = new Dict();
|
|
|
|
|
const uncheckedAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
const checkedStream = new StringStream("0.1 0.2 0.3 rg");
|
|
|
|
|
checkedStream.dict = checkedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
const uncheckedStream = new StringStream("0.3 0.2 0.1 rg");
|
|
|
|
|
uncheckedStream.dict = uncheckedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
|
|
|
|
checkedAppearanceDict.set("FormType", 1);
|
|
|
|
|
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
|
|
|
|
normalAppearanceDict.set("Checked", checkedStream);
|
|
|
|
|
normalAppearanceDict.set("Off", uncheckedStream);
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
buttonWidgetDict.set("AS", Name.get("Checked"));
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-09-20 00:47:38 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-20 00:47:38 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"124R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
|
2020-09-20 00:47:38 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should save checkboxes", async function () {
|
2020-08-04 02:44:04 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
normalAppearanceDict.set("Checked", Ref.get(314, 0));
|
|
|
|
|
normalAppearanceDict.set("Off", Ref.get(271, 0));
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
buttonWidgetDict.set("V", Name.get("Off"));
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-04 02:44:04 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-04 02:44:04 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true });
|
|
|
|
|
|
|
|
|
|
const [oldData] = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2021-09-02 18:41:20 +09:00
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Btn " +
|
|
|
|
|
"/AP << /N << /Checked 314 0 R /Off 271 0 R>>>> " +
|
|
|
|
|
"/V /Checked /AS /Checked /M (date)>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: false });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-19 23:39:54 +09:00
|
|
|
|
it("should save rotated checkboxes", async function () {
|
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
normalAppearanceDict.set("Checked", Ref.get(314, 0));
|
|
|
|
|
normalAppearanceDict.set("Off", Ref.get(271, 0));
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
buttonWidgetDict.set("V", Name.get("Off"));
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
|
|
|
|
const annotation = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2022-06-19 23:39:54 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true, rotation: 180 });
|
|
|
|
|
|
|
|
|
|
const [oldData] = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Btn " +
|
|
|
|
|
"/AP << /N << /Checked 314 0 R /Off 271 0 R>>>> " +
|
|
|
|
|
"/V /Checked /AS /Checked /M (date) /MK << /R 180>>>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: false });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle radio buttons with a field value", async function () {
|
2020-07-23 00:29:35 +09:00
|
|
|
|
const parentDict = new Dict();
|
|
|
|
|
parentDict.set("V", Name.get("1"));
|
|
|
|
|
|
|
|
|
|
const normalAppearanceStateDict = new Dict();
|
|
|
|
|
normalAppearanceStateDict.set("2", null);
|
|
|
|
|
|
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
|
|
|
|
buttonWidgetDict.set("Parent", parentDict);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-07-23 00:29:35 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-07-23 00:29:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.checkBox).toEqual(false);
|
|
|
|
|
expect(data.radioButton).toEqual(true);
|
|
|
|
|
expect(data.fieldValue).toEqual("1");
|
|
|
|
|
expect(data.buttonValue).toEqual("2");
|
2020-07-23 00:29:35 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle radio buttons with a field value that's not an ASCII string", async function () {
|
2020-09-17 01:47:25 +09:00
|
|
|
|
const parentDict = new Dict();
|
|
|
|
|
parentDict.set("V", Name.get("\x91I=\x91\xf0\x93\xe0\x97e3"));
|
|
|
|
|
|
|
|
|
|
const normalAppearanceStateDict = new Dict();
|
|
|
|
|
normalAppearanceStateDict.set("\x91I=\x91\xf0\x93\xe0\x97e3", null);
|
|
|
|
|
|
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
|
|
|
|
buttonWidgetDict.set("Parent", parentDict);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-09-17 01:47:25 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-17 01:47:25 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.checkBox).toEqual(false);
|
|
|
|
|
expect(data.radioButton).toEqual(true);
|
|
|
|
|
expect(data.fieldValue).toEqual("‚I=‚ðfiàŠe3");
|
|
|
|
|
expect(data.buttonValue).toEqual("‚I=‚ðfiàŠe3");
|
2020-09-17 01:47:25 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle radio buttons without a field value", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const normalAppearanceStateDict = new Dict();
|
2017-02-08 07:44:31 +09:00
|
|
|
|
normalAppearanceStateDict.set("2", null);
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
2017-02-08 07:44:31 +09:00
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2017-02-08 07:44:31 +09:00
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.checkBox).toEqual(false);
|
|
|
|
|
expect(data.radioButton).toEqual(true);
|
|
|
|
|
expect(data.fieldValue).toEqual(null);
|
|
|
|
|
expect(data.buttonValue).toEqual("2");
|
2017-02-08 07:44:31 +09:00
|
|
|
|
});
|
2020-07-23 00:29:35 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render radio buttons for printing", async function () {
|
2020-07-23 00:29:35 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
const checkedAppearanceDict = new Dict();
|
|
|
|
|
const uncheckedAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
const checkedStream = new StringStream("0.1 0.2 0.3 rg");
|
|
|
|
|
checkedStream.dict = checkedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
const uncheckedStream = new StringStream("0.3 0.2 0.1 rg");
|
|
|
|
|
uncheckedStream.dict = uncheckedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
|
|
|
|
checkedAppearanceDict.set("FormType", 1);
|
|
|
|
|
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
|
|
|
|
normalAppearanceDict.set("Checked", checkedStream);
|
|
|
|
|
normalAppearanceDict.set("Off", uncheckedStream);
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-07-23 00:29:35 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-07-23 00:29:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true });
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList: opList1 } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList1.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList1.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList1.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"124R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList1.argsArray[1]).toEqual(new Uint8ClampedArray([26, 51, 76]));
|
2021-04-18 01:23:40 +09:00
|
|
|
|
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: false });
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList: opList2 } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList2.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList2.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList2.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"124R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList2.argsArray[1]).toEqual(new Uint8ClampedArray([76, 51, 26]));
|
2020-07-23 00:29:35 +09:00
|
|
|
|
});
|
2020-08-04 02:44:04 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render radio buttons for printing using normal appearance", async function () {
|
2020-09-20 00:47:38 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
const checkedAppearanceDict = new Dict();
|
|
|
|
|
const uncheckedAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
const checkedStream = new StringStream("0.1 0.2 0.3 rg");
|
|
|
|
|
checkedStream.dict = checkedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
const uncheckedStream = new StringStream("0.3 0.2 0.1 rg");
|
|
|
|
|
uncheckedStream.dict = uncheckedAppearanceDict;
|
|
|
|
|
|
|
|
|
|
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
|
|
|
|
checkedAppearanceDict.set("FormType", 1);
|
|
|
|
|
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
|
|
|
|
normalAppearanceDict.set("Checked", checkedStream);
|
|
|
|
|
normalAppearanceDict.set("Off", uncheckedStream);
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
buttonWidgetDict.set("AS", Name.get("Off"));
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-09-20 00:47:38 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-20 00:47:38 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList } = await annotation.getOperatorList(
|
2021-04-18 01:23:40 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2021-11-07 02:36:49 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
false,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray.length).toEqual(3);
|
|
|
|
|
expect(opList.fnArray).toEqual([
|
2021-04-18 01:23:40 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setFillRGBColor,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[0]).toEqual([
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
"124R",
|
|
|
|
|
[0, 0, 0, 0],
|
|
|
|
|
[0, 0, 0, 0, 0, 0],
|
|
|
|
|
[1, 0, 0, 1, 0, 0],
|
2021-11-07 02:36:49 +09:00
|
|
|
|
false,
|
[api-minor] Add `intent` support to the `PDFPageProxy.getOperatorList` method (issue 13704)
With this patch, the `PDFPageProxy.getOperatorList` method will now return `PDFOperatorList`-instances that also include Annotation-operatorLists (when those exist). Hence this closes a small, but potentially confusing, gap between the `render` and `getOperatorList` methods.
Previously we've been somewhat reluctant to do this, as explained below, but given that there's actual use-cases where it's required probably means that we'll *have* to implement it now.
Since we still need the ability to separate "normal" rendering operations from direct `getOperatorList` calls in the worker-thread, this API-change unfortunately causes the *internal* renderingIntent to become a bit "messy" which is indeed unfortunate (note the `"oplist-"` strings in various spots). As-is I suppose that it's not all that bad, but we may want to consider changing the *internal* renderingIntent to e.g. a bitfield in the future.
Besides fixing issue 13704, this patch would also be necessary if someone ever tries to implement e.g. issue 10165 (since currently `PDFPageProxy.getOperatorList` doesn't include Annotation-operatorLists).
*Please note:* This patch is *also* tagged "api-minor" for a second reason, which is that we're now including the Annotation-id in the `beginAnnotation` argument. The reason for this is to allow correlating the Annotation-data returned by `PDFPageProxy.getAnnotations`, with its corresponding operatorList-data (for those Annotations that have it).
2021-07-10 23:47:39 +09:00
|
|
|
|
]);
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[1]).toEqual(new Uint8ClampedArray([76, 51, 26]));
|
2020-09-20 00:47:38 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should save radio buttons", async function () {
|
2020-08-04 02:44:04 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
normalAppearanceDict.set("Checked", Ref.get(314, 0));
|
|
|
|
|
normalAppearanceDict.set("Off", Ref.get(271, 0));
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const parentRef = Ref.get(456, 0);
|
|
|
|
|
|
|
|
|
|
const parentDict = new Dict();
|
|
|
|
|
parentDict.set("V", Name.get("Off"));
|
|
|
|
|
parentDict.set("Kids", [buttonWidgetRef]);
|
|
|
|
|
buttonWidgetDict.set("Parent", parentRef);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
{ ref: parentRef, data: parentDict },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
parentDict.xref = xref;
|
|
|
|
|
buttonWidgetDict.xref = xref;
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-04 02:44:04 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-04 02:44:04 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true });
|
|
|
|
|
|
|
|
|
|
let data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [radioData, parentData] = data;
|
2021-09-02 18:41:20 +09:00
|
|
|
|
radioData.data = radioData.data.replace(/\(D:\d+\)/, "(date)");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(radioData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(radioData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Btn /Ff 32768 " +
|
|
|
|
|
"/AP << /N << /Checked 314 0 R /Off 271 0 R>>>> " +
|
|
|
|
|
"/Parent 456 0 R /AS /Checked /M (date)>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
expect(parentData.ref).toEqual(Ref.get(456, 0));
|
|
|
|
|
expect(parentData.data).toEqual(
|
|
|
|
|
"456 0 obj\n<< /V /Checked /Kids [123 0 R]>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: false });
|
|
|
|
|
|
|
|
|
|
data = await annotation.save(partialEvaluator, task, annotationStorage);
|
|
|
|
|
expect(data).toEqual(null);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should save radio buttons without a field value", async function () {
|
2020-09-15 21:23:08 +09:00
|
|
|
|
const appearanceStatesDict = new Dict();
|
|
|
|
|
const normalAppearanceDict = new Dict();
|
|
|
|
|
|
|
|
|
|
normalAppearanceDict.set("Checked", Ref.get(314, 0));
|
|
|
|
|
normalAppearanceDict.set("Off", Ref.get(271, 0));
|
|
|
|
|
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
|
|
|
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
|
|
|
|
buttonWidgetDict.set("AP", appearanceStatesDict);
|
|
|
|
|
|
|
|
|
|
const buttonWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const parentRef = Ref.get(456, 0);
|
|
|
|
|
|
|
|
|
|
const parentDict = new Dict();
|
|
|
|
|
parentDict.set("Kids", [buttonWidgetRef]);
|
|
|
|
|
buttonWidgetDict.set("Parent", parentRef);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
{ ref: parentRef, data: parentDict },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
parentDict.xref = xref;
|
|
|
|
|
buttonWidgetDict.xref = xref;
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-09-15 21:23:08 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-15 21:23:08 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: true });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [radioData, parentData] = data;
|
2021-09-02 18:41:20 +09:00
|
|
|
|
radioData.data = radioData.data.replace(/\(D:\d+\)/, "(date)");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(radioData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(radioData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Btn /Ff 32768 " +
|
|
|
|
|
"/AP << /N << /Checked 314 0 R /Off 271 0 R>>>> " +
|
|
|
|
|
"/Parent 456 0 R /AS /Checked /M (date)>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
expect(parentData.ref).toEqual(Ref.get(456, 0));
|
|
|
|
|
expect(parentData.data).toEqual(
|
|
|
|
|
"456 0 obj\n<< /Kids [123 0 R] /V /Checked>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should save nothing", async function () {
|
2020-09-09 02:07:10 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-09-09 02:07:10 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-09 02:07:10 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
2021-02-18 21:51:08 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data).toEqual(null);
|
2020-09-09 02:07:10 +09:00
|
|
|
|
});
|
2020-09-07 00:14:56 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle push buttons", async function () {
|
2020-09-07 00:14:56 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
|
2020-10-01 03:58:45 +09:00
|
|
|
|
|
|
|
|
|
const actionDict = new Dict();
|
|
|
|
|
actionDict.set("S", Name.get("JavaScript"));
|
|
|
|
|
actionDict.set("JS", "do_something();");
|
|
|
|
|
buttonWidgetDict.set("A", actionDict);
|
2020-09-07 00:14:56 +09:00
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-09-07 00:14:56 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-07 00:14:56 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.pushButton).toEqual(true);
|
|
|
|
|
expect(data.actions.Action).toEqual(["do_something();"]);
|
2020-09-07 00:14:56 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle push buttons that act as a tooltip only", async function () {
|
2020-09-07 00:14:56 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
|
|
|
|
|
buttonWidgetDict.set("TU", "An alternative text");
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-09-07 00:14:56 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-09-07 00:14:56 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.pushButton).toEqual(true);
|
|
|
|
|
expect(data.alternativeText).toEqual("An alternative text");
|
2020-09-07 00:14:56 +09:00
|
|
|
|
});
|
2020-10-16 02:42:36 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle URL in A dict in push buttons", async function () {
|
2020-10-16 02:42:36 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
|
|
|
|
|
|
|
|
|
|
const actionDict = new Dict();
|
|
|
|
|
actionDict.set("S", Name.get("JavaScript"));
|
|
|
|
|
actionDict.set(
|
|
|
|
|
"JS",
|
|
|
|
|
"app.launchURL('https://developer.mozilla.org/en-US/', true)"
|
|
|
|
|
);
|
|
|
|
|
buttonWidgetDict.set("A", actionDict);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-10-16 02:42:36 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-10-16 02:42:36 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.url).toEqual("https://developer.mozilla.org/en-US/");
|
2020-10-16 02:42:36 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle URL in AA dict in push buttons", async function () {
|
2020-10-16 02:42:36 +09:00
|
|
|
|
const buttonWidgetRef = Ref.get(124, 0);
|
|
|
|
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
// D stands for MouseDown.
|
2020-10-16 02:42:36 +09:00
|
|
|
|
const dDict = new Dict();
|
|
|
|
|
dDict.set("S", Name.get("JavaScript"));
|
|
|
|
|
dDict.set(
|
|
|
|
|
"JS",
|
|
|
|
|
"app.launchURL('https://developer.mozilla.org/en-US/', true)"
|
|
|
|
|
);
|
|
|
|
|
const actionDict = new Dict();
|
|
|
|
|
actionDict.set("D", dDict);
|
|
|
|
|
buttonWidgetDict.set("AA", actionDict);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-10-16 02:42:36 +09:00
|
|
|
|
xref,
|
|
|
|
|
buttonWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-10-16 02:42:36 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.url).toEqual("https://developer.mozilla.org/en-US/");
|
2020-10-16 02:42:36 +09:00
|
|
|
|
});
|
2016-11-04 21:01:42 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("ChoiceWidgetAnnotation", function () {
|
2020-08-05 21:40:31 +09:00
|
|
|
|
let choiceWidgetDict, fontRefObj;
|
2016-09-26 00:08:17 +09:00
|
|
|
|
|
2021-04-11 03:21:31 +09:00
|
|
|
|
beforeEach(function () {
|
2016-09-26 00:08:17 +09:00
|
|
|
|
choiceWidgetDict = new Dict();
|
|
|
|
|
choiceWidgetDict.set("Type", Name.get("Annot"));
|
|
|
|
|
choiceWidgetDict.set("Subtype", Name.get("Widget"));
|
|
|
|
|
choiceWidgetDict.set("FT", Name.get("Ch"));
|
2020-08-05 21:40:31 +09:00
|
|
|
|
|
|
|
|
|
const helvDict = new Dict();
|
|
|
|
|
helvDict.set("BaseFont", Name.get("Helvetica"));
|
|
|
|
|
helvDict.set("Type", Name.get("Font"));
|
|
|
|
|
helvDict.set("Subtype", Name.get("Type1"));
|
|
|
|
|
|
|
|
|
|
const fontRef = Ref.get(314, 0);
|
|
|
|
|
fontRefObj = { ref: fontRef, data: helvDict };
|
|
|
|
|
const resourceDict = new Dict();
|
|
|
|
|
const fontDict = new Dict();
|
|
|
|
|
fontDict.set("Helv", fontRef);
|
|
|
|
|
resourceDict.set("Font", fontDict);
|
|
|
|
|
|
|
|
|
|
choiceWidgetDict.set("DA", "/Helv 5 Tf");
|
|
|
|
|
choiceWidgetDict.set("DR", resourceDict);
|
|
|
|
|
choiceWidgetDict.set("Rect", [0, 0, 32, 10]);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
afterEach(function () {
|
2020-08-05 21:40:31 +09:00
|
|
|
|
choiceWidgetDict = fontRefObj = null;
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle missing option arrays", async function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(122, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-09-26 00:08:17 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.options).toEqual([]);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle option arrays with array elements", async function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const optionBarRef = Ref.get(20, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const optionBarStr = "Bar";
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const optionOneRef = Ref.get(10, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const optionOneArr = ["bar_export", optionBarRef];
|
2016-12-17 21:34:18 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const options = [["foo_export", "Foo"], optionOneRef];
|
|
|
|
|
const expected = [
|
2017-11-19 00:47:32 +09:00
|
|
|
|
{ exportValue: "foo_export", displayValue: "Foo" },
|
|
|
|
|
{ exportValue: "bar_export", displayValue: "Bar" },
|
2016-09-26 00:08:17 +09:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
choiceWidgetDict.set("Opt", options);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(123, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-12-17 21:34:18 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
{ ref: optionBarRef, data: optionBarStr },
|
|
|
|
|
{ ref: optionOneRef, data: optionOneArr },
|
2016-09-26 00:08:17 +09:00
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.options).toEqual(expected);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle option arrays with string elements", async function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const optionBarRef = Ref.get(10, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const optionBarStr = "Bar";
|
2016-12-17 21:34:18 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const options = ["Foo", optionBarRef];
|
|
|
|
|
const expected = [
|
2017-11-19 00:47:32 +09:00
|
|
|
|
{ exportValue: "Foo", displayValue: "Foo" },
|
|
|
|
|
{ exportValue: "Bar", displayValue: "Bar" },
|
2016-09-26 00:08:17 +09:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
choiceWidgetDict.set("Opt", options);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(981, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-12-17 21:34:18 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
{ ref: optionBarRef, data: optionBarStr },
|
2016-09-26 00:08:17 +09:00
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.options).toEqual(expected);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle inherited option arrays (issue 8094)", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const options = [
|
2017-02-26 07:34:26 +09:00
|
|
|
|
["Value1", "Description1"],
|
|
|
|
|
["Value2", "Description2"],
|
|
|
|
|
];
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const expected = [
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
|
{ exportValue: "Value1", displayValue: "Description1" },
|
|
|
|
|
{ exportValue: "Value2", displayValue: "Description2" },
|
2017-02-26 07:34:26 +09:00
|
|
|
|
];
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const parentDict = new Dict();
|
2017-02-26 07:34:26 +09:00
|
|
|
|
parentDict.set("Opt", options);
|
|
|
|
|
|
|
|
|
|
choiceWidgetDict.set("Parent", parentDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(123, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2017-02-26 07:34:26 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.options).toEqual(expected);
|
2017-11-19 00:47:32 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should decode form values", async function () {
|
2020-08-22 22:02:29 +09:00
|
|
|
|
const encodedString = "\xFE\xFF\x00F\x00o\x00o";
|
|
|
|
|
const decodedString = "Foo";
|
2017-11-19 00:47:32 +09:00
|
|
|
|
|
2020-08-22 22:02:29 +09:00
|
|
|
|
choiceWidgetDict.set("Opt", [encodedString]);
|
|
|
|
|
choiceWidgetDict.set("V", encodedString);
|
2020-11-04 00:53:21 +09:00
|
|
|
|
choiceWidgetDict.set("DV", Name.get("foo"));
|
2017-11-19 00:47:32 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(984, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2017-11-19 00:47:32 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.fieldValue).toEqual([decodedString]);
|
|
|
|
|
expect(data.defaultFieldValue).toEqual("foo");
|
|
|
|
|
expect(data.options).toEqual([
|
|
|
|
|
{ exportValue: decodedString, displayValue: decodedString },
|
|
|
|
|
]);
|
2017-02-26 07:34:26 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should convert the field value to an array", async function () {
|
2020-08-19 06:04:56 +09:00
|
|
|
|
const inputs = [null, "Foo", ["Foo", "Bar"]];
|
|
|
|
|
const outputs = [[], ["Foo"], ["Foo", "Bar"]];
|
2016-09-26 00:08:17 +09:00
|
|
|
|
|
2020-08-19 05:55:59 +09:00
|
|
|
|
let promise = Promise.resolve();
|
|
|
|
|
for (let i = 0, ii = inputs.length; i < ii; i++) {
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
|
choiceWidgetDict.set("V", inputs[i]);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
|
2020-08-19 05:55:59 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(968, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
]);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
|
2020-08-19 05:55:59 +09:00
|
|
|
|
return AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-19 05:55:59 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
).then(({ data }) => {
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.fieldValue).toEqual(outputs[i]);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-04-18 01:23:40 +09:00
|
|
|
|
await promise;
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle unknown flags", async function () {
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(166, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-09-26 00:08:17 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.readOnly).toEqual(false);
|
|
|
|
|
expect(data.hidden).toEqual(false);
|
|
|
|
|
expect(data.combo).toEqual(false);
|
|
|
|
|
expect(data.multiSelect).toEqual(false);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should not set invalid flags", async function () {
|
2016-09-26 00:08:17 +09:00
|
|
|
|
choiceWidgetDict.set("Ff", "readonly");
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(165, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-09-26 00:08:17 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.readOnly).toEqual(false);
|
|
|
|
|
expect(data.hidden).toEqual(false);
|
|
|
|
|
expect(data.combo).toEqual(false);
|
|
|
|
|
expect(data.multiSelect).toEqual(false);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set valid flags", async function () {
|
2016-09-26 00:08:17 +09:00
|
|
|
|
choiceWidgetDict.set(
|
|
|
|
|
"Ff",
|
|
|
|
|
AnnotationFieldFlag.READONLY +
|
|
|
|
|
AnnotationFieldFlag.COMBO +
|
|
|
|
|
AnnotationFieldFlag.MULTISELECT
|
|
|
|
|
);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(512, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2016-09-26 00:08:17 +09:00
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
|
|
|
|
expect(data.readOnly).toEqual(true);
|
|
|
|
|
expect(data.hidden).toEqual(false);
|
|
|
|
|
expect(data.combo).toEqual(true);
|
|
|
|
|
expect(data.multiSelect).toEqual(true);
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
2020-08-05 21:40:31 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should render choice for printing", async function () {
|
2020-08-05 21:40:31 +09:00
|
|
|
|
const choiceWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
fontRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-05 21:40:31 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-05 21:40:31 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "a value" });
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2021-04-18 01:23:40 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
2022-03-27 06:45:50 +09:00
|
|
|
|
[
|
|
|
|
|
"/Tx BMC q",
|
|
|
|
|
"1 1 32 10 re W n",
|
|
|
|
|
"BT",
|
|
|
|
|
"/Helv 5 Tf",
|
|
|
|
|
"1 0 0 1 0 10 Tm",
|
|
|
|
|
"ET Q EMC",
|
|
|
|
|
].join("\n")
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render choice with multiple selections but one is visible for printing", async function () {
|
|
|
|
|
choiceWidgetDict.set("Ff", AnnotationFieldFlag.MULTISELECT);
|
|
|
|
|
choiceWidgetDict.set("Opt", [
|
|
|
|
|
["A", "a"],
|
|
|
|
|
["B", "b"],
|
|
|
|
|
["C", "c"],
|
|
|
|
|
["D", "d"],
|
|
|
|
|
]);
|
|
|
|
|
choiceWidgetDict.set("V", ["A"]);
|
|
|
|
|
|
|
|
|
|
const choiceWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
fontRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
|
|
|
|
const annotation = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2022-03-27 06:45:50 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: ["A", "C"] });
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2022-03-27 06:45:50 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
[
|
|
|
|
|
"/Tx BMC q",
|
|
|
|
|
"1 1 32 10 re W n",
|
|
|
|
|
"0.600006 0.756866 0.854904 rg",
|
|
|
|
|
"1 3.25 32 6.75 re f",
|
|
|
|
|
"BT",
|
|
|
|
|
"/Helv 5 Tf",
|
|
|
|
|
"1 0 0 1 0 10 Tm",
|
2022-05-18 06:10:02 +09:00
|
|
|
|
"2 -5.88 Td (a) Tj",
|
|
|
|
|
"0 -6.75 Td (b) Tj",
|
2022-03-27 06:45:50 +09:00
|
|
|
|
"ET Q EMC",
|
|
|
|
|
].join("\n")
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render choice with multiple selections for printing", async function () {
|
|
|
|
|
choiceWidgetDict.set("Ff", AnnotationFieldFlag.MULTISELECT);
|
|
|
|
|
choiceWidgetDict.set("Opt", [
|
|
|
|
|
["A", "a"],
|
|
|
|
|
["B", "b"],
|
|
|
|
|
["C", "c"],
|
|
|
|
|
["D", "d"],
|
|
|
|
|
]);
|
|
|
|
|
choiceWidgetDict.set("V", ["A"]);
|
|
|
|
|
|
|
|
|
|
const choiceWidgetRef = Ref.get(271, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
fontRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test print");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
|
|
|
|
const annotation = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2022-03-27 06:45:50 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: ["B", "C"] });
|
|
|
|
|
|
|
|
|
|
const appearance = await annotation._getAppearance(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
2022-10-19 00:07:47 +09:00
|
|
|
|
RenderingIntentFlag.PRINT,
|
2022-03-27 06:45:50 +09:00
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
[
|
|
|
|
|
"/Tx BMC q",
|
|
|
|
|
"1 1 32 10 re W n",
|
|
|
|
|
"0.600006 0.756866 0.854904 rg",
|
|
|
|
|
"1 3.25 32 6.75 re f",
|
|
|
|
|
"1 -3.5 32 6.75 re f",
|
|
|
|
|
"BT",
|
|
|
|
|
"/Helv 5 Tf",
|
|
|
|
|
"1 0 0 1 0 10 Tm",
|
2022-05-18 06:10:02 +09:00
|
|
|
|
"2 -5.88 Td (b) Tj",
|
|
|
|
|
"0 -6.75 Td (c) Tj",
|
2022-03-27 06:45:50 +09:00
|
|
|
|
"ET Q EMC",
|
|
|
|
|
].join("\n")
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-19 23:39:54 +09:00
|
|
|
|
it("should save rotated choice", async function () {
|
|
|
|
|
choiceWidgetDict.set("Opt", ["A", "B", "C"]);
|
|
|
|
|
choiceWidgetDict.set("V", "A");
|
|
|
|
|
|
|
|
|
|
const choiceWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
fontRefObj,
|
|
|
|
|
]);
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
|
|
|
|
const annotation = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2022-06-19 23:39:54 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "C", rotation: 270 });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [oldData, newData] = data;
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(newData.ref).toEqual(Ref.get(2, 0));
|
|
|
|
|
|
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Ch /DA (/Helv 5 Tf) /DR " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> " +
|
|
|
|
|
"/Rect [0 0 32 10] /Opt [(A) (B) (C)] /V (C) " +
|
2022-10-19 00:07:47 +09:00
|
|
|
|
"/MK << /R 270>> /AP << /N 2 0 R>> /M (date)>>\nendobj\n"
|
2022-06-19 23:39:54 +09:00
|
|
|
|
);
|
|
|
|
|
expect(newData.data).toEqual(
|
|
|
|
|
[
|
|
|
|
|
"2 0 obj",
|
2023-02-08 03:26:46 +09:00
|
|
|
|
"<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
|
|
|
|
|
"/BBox [0 0 32 10] /Matrix [0 -1 1 0 0 10] /Length 170>> stream",
|
2022-06-19 23:39:54 +09:00
|
|
|
|
"/Tx BMC q",
|
|
|
|
|
"1 1 10 32 re W n",
|
|
|
|
|
"0.600006 0.756866 0.854904 rg",
|
|
|
|
|
"1 11.75 10 6.75 re f",
|
|
|
|
|
"BT",
|
|
|
|
|
"/Helv 5 Tf",
|
|
|
|
|
"1 0 0 1 0 32 Tm",
|
|
|
|
|
"2 -5.88 Td (A) Tj",
|
|
|
|
|
"0 -6.75 Td (B) Tj",
|
|
|
|
|
"0 -6.75 Td (C) Tj",
|
|
|
|
|
"ET Q EMC",
|
|
|
|
|
"endstream",
|
|
|
|
|
"endobj\n",
|
|
|
|
|
].join("\n")
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should save choice", async function () {
|
2020-08-04 02:44:04 +09:00
|
|
|
|
choiceWidgetDict.set("Opt", ["A", "B", "C"]);
|
|
|
|
|
choiceWidgetDict.set("V", "A");
|
|
|
|
|
|
|
|
|
|
const choiceWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
2022-01-28 06:51:30 +09:00
|
|
|
|
fontRefObj,
|
2020-08-04 02:44:04 +09:00
|
|
|
|
]);
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const annotation = await AnnotationFactory.create(
|
2020-08-04 02:44:04 +09:00
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-08-04 02:44:04 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: "C" });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [oldData, newData] = data;
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
2022-01-28 06:51:30 +09:00
|
|
|
|
expect(newData.ref).toEqual(Ref.get(2, 0));
|
2021-04-18 01:23:40 +09:00
|
|
|
|
|
2021-09-02 18:41:20 +09:00
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Ch /DA (/Helv 5 Tf) /DR " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> " +
|
|
|
|
|
"/Rect [0 0 32 10] /Opt [(A) (B) (C)] /V (C) " +
|
2022-01-28 06:51:30 +09:00
|
|
|
|
"/AP << /N 2 0 R>> /M (date)>>\nendobj\n"
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(newData.data).toEqual(
|
2022-03-27 06:45:50 +09:00
|
|
|
|
[
|
|
|
|
|
"2 0 obj",
|
2023-02-08 03:26:46 +09:00
|
|
|
|
"<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
|
|
|
|
|
"/BBox [0 0 32 10] /Length 133>> stream",
|
2022-03-27 06:45:50 +09:00
|
|
|
|
"/Tx BMC q",
|
|
|
|
|
"1 1 32 10 re W n",
|
|
|
|
|
"0.600006 0.756866 0.854904 rg",
|
|
|
|
|
"1 3.25 32 6.75 re f",
|
|
|
|
|
"BT",
|
|
|
|
|
"/Helv 5 Tf",
|
|
|
|
|
"1 0 0 1 0 10 Tm",
|
2022-05-18 06:10:02 +09:00
|
|
|
|
"2 -5.88 Td (C) Tj",
|
2022-03-27 06:45:50 +09:00
|
|
|
|
"ET Q EMC",
|
|
|
|
|
"endstream",
|
|
|
|
|
"endobj\n",
|
|
|
|
|
].join("\n")
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should save choice with multiple selections", async function () {
|
|
|
|
|
choiceWidgetDict.set("Ff", AnnotationFieldFlag.MULTISELECT);
|
|
|
|
|
choiceWidgetDict.set("Opt", [
|
|
|
|
|
["A", "a"],
|
|
|
|
|
["B", "b"],
|
|
|
|
|
["C", "c"],
|
|
|
|
|
["D", "d"],
|
|
|
|
|
]);
|
|
|
|
|
choiceWidgetDict.set("V", ["A"]);
|
|
|
|
|
|
|
|
|
|
const choiceWidgetRef = Ref.get(123, 0);
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: choiceWidgetRef, data: choiceWidgetDict },
|
|
|
|
|
fontRefObj,
|
|
|
|
|
]);
|
|
|
|
|
const task = new WorkerTask("test save");
|
|
|
|
|
partialEvaluator.xref = xref;
|
|
|
|
|
|
|
|
|
|
const annotation = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
choiceWidgetRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2022-03-27 06:45:50 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
const annotationStorage = new Map();
|
|
|
|
|
annotationStorage.set(annotation.data.id, { value: ["B", "C"] });
|
|
|
|
|
|
|
|
|
|
const data = await annotation.save(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
annotationStorage
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(data.length).toEqual(2);
|
|
|
|
|
const [oldData, newData] = data;
|
|
|
|
|
expect(oldData.ref).toEqual(Ref.get(123, 0));
|
|
|
|
|
expect(newData.ref).toEqual(Ref.get(2, 0));
|
|
|
|
|
|
|
|
|
|
oldData.data = oldData.data.replace(/\(D:\d+\)/, "(date)");
|
|
|
|
|
expect(oldData.data).toEqual(
|
|
|
|
|
"123 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Widget /FT /Ch /DA (/Helv 5 Tf) /DR " +
|
|
|
|
|
"<< /Font << /Helv 314 0 R>>>> /Rect [0 0 32 10] /Ff 2097152 /Opt " +
|
|
|
|
|
"[[(A) (a)] [(B) (b)] [(C) (c)] [(D) (d)]] /V [(B) (C)] /AP " +
|
|
|
|
|
"<< /N 2 0 R>> /M (date)>>\nendobj\n"
|
|
|
|
|
);
|
|
|
|
|
expect(newData.data).toEqual(
|
|
|
|
|
[
|
|
|
|
|
"2 0 obj",
|
2023-02-08 03:26:46 +09:00
|
|
|
|
"<< /Subtype /Form /Resources << /Font << /Helv 314 0 R>>>> " +
|
|
|
|
|
"/BBox [0 0 32 10] /Length 171>> stream",
|
2022-03-27 06:45:50 +09:00
|
|
|
|
"/Tx BMC q",
|
|
|
|
|
"1 1 32 10 re W n",
|
|
|
|
|
"0.600006 0.756866 0.854904 rg",
|
|
|
|
|
"1 3.25 32 6.75 re f",
|
|
|
|
|
"1 -3.5 32 6.75 re f",
|
|
|
|
|
"BT",
|
|
|
|
|
"/Helv 5 Tf",
|
|
|
|
|
"1 0 0 1 0 10 Tm",
|
2022-05-18 06:10:02 +09:00
|
|
|
|
"2 -5.88 Td (b) Tj",
|
|
|
|
|
"0 -6.75 Td (c) Tj",
|
2022-03-27 06:45:50 +09:00
|
|
|
|
"ET Q EMC",
|
|
|
|
|
"endstream",
|
|
|
|
|
"endobj\n",
|
|
|
|
|
].join("\n")
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
2020-08-04 02:44:04 +09:00
|
|
|
|
});
|
2016-09-26 00:08:17 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("LineAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set the line coordinates", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const lineDict = new Dict();
|
2017-04-03 03:50:17 +09:00
|
|
|
|
lineDict.set("Type", Name.get("Annot"));
|
|
|
|
|
lineDict.set("Subtype", Name.get("Line"));
|
|
|
|
|
lineDict.set("L", [1, 2, 3, 4]);
|
2022-05-11 00:36:29 +09:00
|
|
|
|
lineDict.set("LE", ["Square", "Circle"]);
|
2017-04-03 03:50:17 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const lineRef = Ref.get(122, 0);
|
2017-04-03 03:50:17 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: lineRef, data: lineDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
lineRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINE);
|
|
|
|
|
expect(data.lineCoordinates).toEqual([1, 2, 3, 4]);
|
2022-05-11 00:36:29 +09:00
|
|
|
|
expect(data.lineEndings).toEqual(["None", "None"]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should set the line endings", async function () {
|
|
|
|
|
const lineDict = new Dict();
|
|
|
|
|
lineDict.set("Type", Name.get("Annot"));
|
|
|
|
|
lineDict.set("Subtype", Name.get("Line"));
|
|
|
|
|
lineDict.set("L", [1, 2, 3, 4]);
|
|
|
|
|
lineDict.set("LE", [Name.get("Square"), Name.get("Circle")]);
|
|
|
|
|
|
|
|
|
|
const lineRef = Ref.get(122, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: lineRef, data: lineDict }]);
|
|
|
|
|
|
|
|
|
|
const { data } = await AnnotationFactory.create(
|
|
|
|
|
xref,
|
|
|
|
|
lineRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2022-05-11 00:36:29 +09:00
|
|
|
|
idFactoryMock
|
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.LINE);
|
|
|
|
|
expect(data.lineCoordinates).toEqual([1, 2, 3, 4]);
|
|
|
|
|
expect(data.lineEndings).toEqual(["Square", "Circle"]);
|
2017-04-03 03:50:17 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("FileAttachmentAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should correctly parse a file attachment", async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const fileStream = new StringStream(
|
2017-01-12 22:11:22 +09:00
|
|
|
|
"<<\n" +
|
|
|
|
|
"/Type /EmbeddedFile\n" +
|
|
|
|
|
"/Subtype /text#2Fplain\n" +
|
|
|
|
|
">>\n" +
|
|
|
|
|
"stream\n" +
|
|
|
|
|
"Test attachment" +
|
|
|
|
|
"endstream\n"
|
|
|
|
|
);
|
2019-06-23 23:01:45 +09:00
|
|
|
|
const parser = new Parser({
|
|
|
|
|
lexer: new Lexer(fileStream),
|
|
|
|
|
xref: null,
|
|
|
|
|
allowStreams: true,
|
|
|
|
|
});
|
2016-02-15 05:27:53 +09:00
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const fileStreamRef = Ref.get(18, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const fileStreamDict = parser.getObj();
|
2016-02-15 05:27:53 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const embeddedFileDict = new Dict();
|
2017-01-12 22:11:22 +09:00
|
|
|
|
embeddedFileDict.set("F", fileStreamRef);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const fileSpecRef = Ref.get(19, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const fileSpecDict = new Dict();
|
2017-01-12 22:11:22 +09:00
|
|
|
|
fileSpecDict.set("Type", Name.get("Filespec"));
|
|
|
|
|
fileSpecDict.set("Desc", "");
|
|
|
|
|
fileSpecDict.set("EF", embeddedFileDict);
|
|
|
|
|
fileSpecDict.set("UF", "Test.txt");
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const fileAttachmentRef = Ref.get(20, 0);
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const fileAttachmentDict = new Dict();
|
2017-01-12 22:11:22 +09:00
|
|
|
|
fileAttachmentDict.set("Type", Name.get("Annot"));
|
|
|
|
|
fileAttachmentDict.set("Subtype", Name.get("FileAttachment"));
|
|
|
|
|
fileAttachmentDict.set("FS", fileSpecRef);
|
|
|
|
|
fileAttachmentDict.set("T", "Topic");
|
|
|
|
|
fileAttachmentDict.set("Contents", "Test.txt");
|
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const xref = new XRefMock([
|
2017-01-12 22:11:22 +09:00
|
|
|
|
{ ref: fileStreamRef, data: fileStreamDict },
|
|
|
|
|
{ ref: fileSpecRef, data: fileSpecDict },
|
|
|
|
|
{ ref: fileAttachmentRef, data: fileAttachmentDict },
|
|
|
|
|
]);
|
|
|
|
|
embeddedFileDict.assignXref(xref);
|
|
|
|
|
fileSpecDict.assignXref(xref);
|
|
|
|
|
fileAttachmentDict.assignXref(xref);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-03-21 09:43:40 +09:00
|
|
|
|
xref,
|
|
|
|
|
fileAttachmentRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-03-21 09:43:40 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.FILEATTACHMENT);
|
|
|
|
|
expect(data.file.filename).toEqual("Test.txt");
|
|
|
|
|
expect(data.file.content).toEqual(stringToBytes("Test attachment"));
|
2016-02-15 05:27:53 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
2016-05-25 00:35:45 +09:00
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("PopupAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should inherit properties from its parent", async function () {
|
2019-04-22 04:21:01 +09:00
|
|
|
|
const parentDict = new Dict();
|
|
|
|
|
parentDict.set("Type", Name.get("Annot"));
|
|
|
|
|
parentDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
parentDict.set("M", "D:20190423");
|
|
|
|
|
parentDict.set("C", [0, 0, 1]);
|
|
|
|
|
|
|
|
|
|
const popupDict = new Dict();
|
|
|
|
|
popupDict.set("Type", Name.get("Annot"));
|
|
|
|
|
popupDict.set("Subtype", Name.get("Popup"));
|
|
|
|
|
popupDict.set("Parent", parentDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const popupRef = Ref.get(13, 0);
|
2019-04-22 04:21:01 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: popupRef, data: popupDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-04-22 04:21:01 +09:00
|
|
|
|
xref,
|
|
|
|
|
popupRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-04-22 04:21:01 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.POPUP);
|
|
|
|
|
expect(data.modificationDate).toEqual("D:20190423");
|
|
|
|
|
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
2019-04-22 04:21:01 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle missing parent properties", async function () {
|
2019-04-22 04:21:01 +09:00
|
|
|
|
const parentDict = new Dict();
|
|
|
|
|
parentDict.set("Type", Name.get("Annot"));
|
|
|
|
|
parentDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
|
|
|
|
|
const popupDict = new Dict();
|
|
|
|
|
popupDict.set("Type", Name.get("Annot"));
|
|
|
|
|
popupDict.set("Subtype", Name.get("Popup"));
|
|
|
|
|
popupDict.set("Parent", parentDict);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const popupRef = Ref.get(13, 0);
|
2019-04-22 04:21:01 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: popupRef, data: popupDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-04-22 04:21:01 +09:00
|
|
|
|
xref,
|
|
|
|
|
popupRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-04-22 04:21:01 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.POPUP);
|
|
|
|
|
expect(data.modificationDate).toEqual(null);
|
|
|
|
|
expect(data.color).toEqual(null);
|
2019-04-22 04:21:01 +09:00
|
|
|
|
});
|
|
|
|
|
|
2016-05-25 00:35:45 +09:00
|
|
|
|
it(
|
|
|
|
|
"should inherit the parent flags when the Popup is not viewable, " +
|
2018-03-21 09:43:40 +09:00
|
|
|
|
"but the parent is (PR 7352)",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const parentDict = new Dict();
|
2016-05-25 00:35:45 +09:00
|
|
|
|
parentDict.set("Type", Name.get("Annot"));
|
|
|
|
|
parentDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
parentDict.set("F", 28); // viewable
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2018-08-12 01:50:31 +09:00
|
|
|
|
const popupDict = new Dict();
|
2016-05-25 00:35:45 +09:00
|
|
|
|
popupDict.set("Type", Name.get("Annot"));
|
|
|
|
|
popupDict.set("Subtype", Name.get("Popup"));
|
2023-10-25 16:41:22 +09:00
|
|
|
|
popupDict.set("F", 56); // not viewable
|
2019-05-15 04:14:35 +09:00
|
|
|
|
popupDict.set("Parent", parentDict);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const popupRef = Ref.get(13, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: popupRef, data: popupDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data, viewable } = await AnnotationFactory.create(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
xref,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
popupRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2017-01-09 00:51:30 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.POPUP);
|
|
|
|
|
// We should not modify the `annotationFlags` returned through
|
|
|
|
|
// e.g., the API.
|
2023-10-25 16:41:22 +09:00
|
|
|
|
expect(data.annotationFlags).toEqual(56);
|
2021-04-18 01:23:40 +09:00
|
|
|
|
// The popup should inherit the `viewable` property of the parent.
|
|
|
|
|
expect(viewable).toEqual(true);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
}
|
2019-05-15 04:14:35 +09:00
|
|
|
|
);
|
|
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
it(
|
2019-05-15 04:14:35 +09:00
|
|
|
|
"should correctly inherit Contents from group-master annotation " +
|
|
|
|
|
"if parent has ReplyType == Group",
|
2021-04-18 01:23:40 +09:00
|
|
|
|
async function () {
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const annotationRef = Ref.get(819, 0);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const annotationDict = new Dict();
|
2016-03-26 18:00:25 +09:00
|
|
|
|
annotationDict.set("Type", Name.get("Annot"));
|
2019-05-15 04:14:35 +09:00
|
|
|
|
annotationDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
annotationDict.set("T", "Correct Title");
|
|
|
|
|
annotationDict.set("Contents", "Correct Text");
|
|
|
|
|
annotationDict.set("M", "D:20190423");
|
|
|
|
|
annotationDict.set("C", [0, 0, 1]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const replyRef = Ref.get(820, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const replyDict = new Dict();
|
|
|
|
|
replyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
replyDict.set("Subtype", Name.get("Text"));
|
|
|
|
|
replyDict.set("IRT", annotationRef);
|
|
|
|
|
replyDict.set("RT", Name.get("Group"));
|
|
|
|
|
replyDict.set("T", "Reply Title");
|
|
|
|
|
replyDict.set("Contents", "Reply Text");
|
|
|
|
|
replyDict.set("M", "D:20190523");
|
|
|
|
|
replyDict.set("C", [0.4]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2020-02-23 04:53:47 +09:00
|
|
|
|
const popupRef = Ref.get(821, 0);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
const popupDict = new Dict();
|
|
|
|
|
popupDict.set("Type", Name.get("Annot"));
|
|
|
|
|
popupDict.set("Subtype", Name.get("Popup"));
|
|
|
|
|
popupDict.set("T", "Wrong Title");
|
|
|
|
|
popupDict.set("Contents", "Wrong Text");
|
|
|
|
|
popupDict.set("Parent", replyRef);
|
|
|
|
|
popupDict.set("M", "D:20190623");
|
|
|
|
|
popupDict.set("C", [0.8]);
|
|
|
|
|
replyDict.set("Popup", popupRef);
|
|
|
|
|
|
|
|
|
|
const xref = new XRefMock([
|
|
|
|
|
{ ref: annotationRef, data: annotationDict },
|
2019-07-28 03:57:52 +09:00
|
|
|
|
{ ref: replyRef, data: replyDict },
|
2019-05-15 04:14:35 +09:00
|
|
|
|
{ ref: popupRef, data: popupDict },
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
]);
|
2019-05-15 04:14:35 +09:00
|
|
|
|
annotationDict.assignXref(xref);
|
|
|
|
|
popupDict.assignXref(xref);
|
|
|
|
|
replyDict.assignXref(xref);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
xref,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
popupRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-05-15 04:14:35 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
2021-09-25 00:30:56 +09:00
|
|
|
|
expect(data.titleObj).toEqual({ str: "Correct Title", dir: "ltr" });
|
|
|
|
|
expect(data.contentsObj).toEqual({ str: "Correct Text", dir: "ltr" });
|
2021-04-18 01:23:40 +09:00
|
|
|
|
expect(data.modificationDate).toEqual("D:20190423");
|
|
|
|
|
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
2019-05-15 04:14:35 +09:00
|
|
|
|
}
|
|
|
|
|
);
|
2016-05-25 00:35:45 +09:00
|
|
|
|
});
|
2018-09-30 23:29:16 +09:00
|
|
|
|
|
2022-06-01 22:42:46 +09:00
|
|
|
|
describe("FreeTextAnnotation", () => {
|
2022-06-09 03:05:25 +09:00
|
|
|
|
it("should create a new FreeText annotation", async () => {
|
2022-06-01 22:42:46 +09:00
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test FreeText creation");
|
|
|
|
|
const data = await AnnotationFactory.saveNewAnnotations(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
annotationType: AnnotationEditorType.FREETEXT,
|
|
|
|
|
rect: [12, 34, 56, 78],
|
2022-06-23 22:47:45 +09:00
|
|
|
|
rotation: 0,
|
2022-06-01 22:42:46 +09:00
|
|
|
|
fontSize: 10,
|
|
|
|
|
color: [0, 0, 0],
|
|
|
|
|
value: "Hello PDF.js World!",
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const base = data.annotations[0].data.replace(/\(D:\d+\)/, "(date)");
|
|
|
|
|
expect(base).toEqual(
|
|
|
|
|
"2 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /FreeText /CreationDate (date) " +
|
|
|
|
|
"/Rect [12 34 56 78] /DA (/Helv 10 Tf 0 g) /Contents (Hello PDF.js World!) " +
|
|
|
|
|
"/F 4 /Border [0 0 0] /Rotate 0 /AP << /N 3 0 R>>>>\n" +
|
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const font = data.dependencies[0].data;
|
|
|
|
|
expect(font).toEqual(
|
|
|
|
|
"1 0 obj\n" +
|
|
|
|
|
"<< /BaseFont /Helvetica /Type /Font /Subtype /Type1 /Encoding " +
|
|
|
|
|
"/WinAnsiEncoding>>\n" +
|
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const appearance = data.dependencies[1].data;
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
"3 0 obj\n" +
|
2023-07-05 21:58:09 +09:00
|
|
|
|
"<< /FormType 1 /Subtype /Form /Type /XObject /BBox [12 34 56 78] " +
|
|
|
|
|
"/Resources << /Font << /Helv 1 0 R>>>> /Matrix [1 0 0 1 -12 -34] " +
|
|
|
|
|
"/Length 98>> stream\n" +
|
2022-06-01 22:42:46 +09:00
|
|
|
|
"q\n" +
|
2023-07-05 21:58:09 +09:00
|
|
|
|
"1 0 0 1 0 0 cm\n" +
|
|
|
|
|
"12 34 44 44 re W n\n" +
|
2022-06-01 22:42:46 +09:00
|
|
|
|
"BT\n" +
|
2023-07-05 21:58:09 +09:00
|
|
|
|
"0 g\n" +
|
|
|
|
|
"0 Tc /Helv 10 Tf\n" +
|
|
|
|
|
"12 68 Td (Hello PDF.js World!) Tj\n" +
|
2022-06-01 22:42:46 +09:00
|
|
|
|
"ET\n" +
|
|
|
|
|
"Q\n" +
|
|
|
|
|
"endstream\n" +
|
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
});
|
2022-06-22 18:46:02 +09:00
|
|
|
|
|
|
|
|
|
it("should render an added FreeText annotation for printing", async function () {
|
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test FreeText printing");
|
|
|
|
|
const freetextAnnotation = (
|
2023-09-07 21:14:35 +09:00
|
|
|
|
await AnnotationFactory.printNewAnnotations(
|
|
|
|
|
annotationGlobalsMock,
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
annotationType: AnnotationEditorType.FREETEXT,
|
|
|
|
|
rect: [12, 34, 56, 78],
|
|
|
|
|
rotation: 0,
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
color: [0, 0, 0],
|
|
|
|
|
value: "A",
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
)
|
2022-06-22 18:46:02 +09:00
|
|
|
|
)[0];
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList } = await freetextAnnotation.getOperatorList(
|
2022-06-22 18:46:02 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
RenderingIntentFlag.PRINT,
|
|
|
|
|
false,
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.fnArray.length).toEqual(16);
|
|
|
|
|
expect(opList.fnArray).toEqual([
|
2022-06-22 18:46:02 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.save,
|
2023-07-05 21:58:09 +09:00
|
|
|
|
OPS.transform,
|
2022-06-22 18:46:02 +09:00
|
|
|
|
OPS.constructPath,
|
|
|
|
|
OPS.clip,
|
|
|
|
|
OPS.endPath,
|
|
|
|
|
OPS.beginText,
|
|
|
|
|
OPS.setFillRGBColor,
|
2023-07-05 21:58:09 +09:00
|
|
|
|
OPS.setCharSpacing,
|
2022-06-22 18:46:02 +09:00
|
|
|
|
OPS.dependency,
|
|
|
|
|
OPS.setFont,
|
|
|
|
|
OPS.moveText,
|
|
|
|
|
OPS.showText,
|
|
|
|
|
OPS.endText,
|
|
|
|
|
OPS.restore,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
|
|
|
|
});
|
2022-08-03 19:03:49 +09:00
|
|
|
|
|
|
|
|
|
it("should extract the text from a FreeText annotation", async function () {
|
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test FreeText text extraction");
|
|
|
|
|
const freetextAnnotation = (
|
2023-09-07 21:14:35 +09:00
|
|
|
|
await AnnotationFactory.printNewAnnotations(
|
|
|
|
|
annotationGlobalsMock,
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
annotationType: AnnotationEditorType.FREETEXT,
|
|
|
|
|
rect: [12, 34, 56, 78],
|
|
|
|
|
rotation: 0,
|
|
|
|
|
fontSize: 10,
|
|
|
|
|
color: [0, 0, 0],
|
|
|
|
|
value: "Hello PDF.js\nWorld !",
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
)
|
2022-08-03 19:03:49 +09:00
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
|
|
await freetextAnnotation.extractTextContent(partialEvaluator, task, [
|
|
|
|
|
-Infinity,
|
|
|
|
|
-Infinity,
|
|
|
|
|
Infinity,
|
|
|
|
|
Infinity,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(freetextAnnotation.data.textContent).toEqual([
|
|
|
|
|
"Hello PDF.js",
|
|
|
|
|
"World !",
|
|
|
|
|
]);
|
|
|
|
|
});
|
2022-06-01 22:42:46 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("InkAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle a single ink list", async function () {
|
2018-09-30 23:29:16 +09:00
|
|
|
|
const inkDict = new Dict();
|
|
|
|
|
inkDict.set("Type", Name.get("Annot"));
|
|
|
|
|
inkDict.set("Subtype", Name.get("Ink"));
|
|
|
|
|
inkDict.set("InkList", [[1, 1, 1, 2, 2, 2, 3, 3]]);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const inkRef = Ref.get(142, 0);
|
2018-09-30 23:29:16 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: inkRef, data: inkDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-09-30 23:29:16 +09:00
|
|
|
|
xref,
|
|
|
|
|
inkRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-09-30 23:29:16 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.INK);
|
|
|
|
|
expect(data.inkLists.length).toEqual(1);
|
|
|
|
|
expect(data.inkLists[0]).toEqual([
|
|
|
|
|
{ x: 1, y: 1 },
|
|
|
|
|
{ x: 1, y: 2 },
|
|
|
|
|
{ x: 2, y: 2 },
|
|
|
|
|
{ x: 3, y: 3 },
|
|
|
|
|
]);
|
2018-09-30 23:29:16 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should handle multiple ink lists", async function () {
|
2018-09-30 23:29:16 +09:00
|
|
|
|
const inkDict = new Dict();
|
|
|
|
|
inkDict.set("Type", Name.get("Annot"));
|
|
|
|
|
inkDict.set("Subtype", Name.get("Ink"));
|
|
|
|
|
inkDict.set("InkList", [
|
|
|
|
|
[1, 1, 1, 2],
|
|
|
|
|
[3, 3, 4, 5],
|
|
|
|
|
]);
|
|
|
|
|
|
2019-05-26 00:40:14 +09:00
|
|
|
|
const inkRef = Ref.get(143, 0);
|
2018-09-30 23:29:16 +09:00
|
|
|
|
const xref = new XRefMock([{ ref: inkRef, data: inkDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2018-09-30 23:29:16 +09:00
|
|
|
|
xref,
|
|
|
|
|
inkRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2018-09-30 23:29:16 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.INK);
|
|
|
|
|
expect(data.inkLists.length).toEqual(2);
|
|
|
|
|
expect(data.inkLists[0]).toEqual([
|
|
|
|
|
{ x: 1, y: 1 },
|
|
|
|
|
{ x: 1, y: 2 },
|
|
|
|
|
]);
|
|
|
|
|
expect(data.inkLists[1]).toEqual([
|
|
|
|
|
{ x: 3, y: 3 },
|
|
|
|
|
{ x: 4, y: 5 },
|
|
|
|
|
]);
|
2018-09-30 23:29:16 +09:00
|
|
|
|
});
|
2022-06-09 03:05:25 +09:00
|
|
|
|
|
|
|
|
|
it("should create a new Ink annotation", async function () {
|
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test Ink creation");
|
|
|
|
|
const data = await AnnotationFactory.saveNewAnnotations(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
annotationType: AnnotationEditorType.INK,
|
|
|
|
|
rect: [12, 34, 56, 78],
|
2022-06-23 22:47:45 +09:00
|
|
|
|
rotation: 0,
|
2022-06-09 03:05:25 +09:00
|
|
|
|
thickness: 1,
|
2022-07-25 05:19:09 +09:00
|
|
|
|
opacity: 1,
|
2022-06-09 03:05:25 +09:00
|
|
|
|
color: [0, 0, 0],
|
|
|
|
|
paths: [
|
|
|
|
|
{
|
|
|
|
|
bezier: [
|
|
|
|
|
10, 11, 12, 13, 14, 15, 16, 17, 22, 23, 24, 25, 26, 27,
|
|
|
|
|
],
|
|
|
|
|
points: [1, 2, 3, 4, 5, 6, 7, 8],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
bezier: [
|
|
|
|
|
910, 911, 912, 913, 914, 915, 916, 917, 922, 923, 924, 925,
|
|
|
|
|
926, 927,
|
|
|
|
|
],
|
|
|
|
|
points: [91, 92, 93, 94, 95, 96, 97, 98],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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] " +
|
2023-05-31 01:24:49 +09:00
|
|
|
|
"/InkList [[1 2 3 4 5 6 7 8] [91 92 93 94 95 96 97 98]] /F 4 " +
|
|
|
|
|
"/Rotate 0 /BS << /W 1>> /C [0 0 0] /CA 1 /AP << /N 2 0 R>>>>\n" +
|
2022-06-09 03:05:25 +09:00
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const appearance = data.dependencies[0].data;
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
"2 0 obj\n" +
|
2023-05-31 01:24:49 +09:00
|
|
|
|
"<< /FormType 1 /Subtype /Form /Type /XObject /BBox [12 34 56 78] /Length 129>> stream\n" +
|
2022-06-14 01:23:10 +09:00
|
|
|
|
"1 w 1 J 1 j\n" +
|
2022-06-09 03:05:25 +09:00
|
|
|
|
"0 G\n" +
|
|
|
|
|
"10 11 m\n" +
|
|
|
|
|
"12 13 14 15 16 17 c\n" +
|
|
|
|
|
"22 23 24 25 26 27 c\n" +
|
|
|
|
|
"S\n" +
|
|
|
|
|
"910 911 m\n" +
|
|
|
|
|
"912 913 914 915 916 917 c\n" +
|
|
|
|
|
"922 923 924 925 926 927 c\n" +
|
|
|
|
|
"S\n" +
|
|
|
|
|
"endstream\n" +
|
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
});
|
2022-06-15 23:57:33 +09:00
|
|
|
|
|
2022-07-25 05:19:09 +09:00
|
|
|
|
it("should create a new Ink annotation with some transparency", async function () {
|
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test Ink creation");
|
|
|
|
|
const data = await AnnotationFactory.saveNewAnnotations(
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
annotationType: AnnotationEditorType.INK,
|
|
|
|
|
rect: [12, 34, 56, 78],
|
|
|
|
|
rotation: 0,
|
|
|
|
|
thickness: 1,
|
|
|
|
|
opacity: 0.12,
|
|
|
|
|
color: [0, 0, 0],
|
|
|
|
|
paths: [
|
|
|
|
|
{
|
|
|
|
|
bezier: [
|
|
|
|
|
10, 11, 12, 13, 14, 15, 16, 17, 22, 23, 24, 25, 26, 27,
|
|
|
|
|
],
|
|
|
|
|
points: [1, 2, 3, 4, 5, 6, 7, 8],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
bezier: [
|
|
|
|
|
910, 911, 912, 913, 914, 915, 916, 917, 922, 923, 924, 925,
|
|
|
|
|
926, 927,
|
|
|
|
|
],
|
|
|
|
|
points: [91, 92, 93, 94, 95, 96, 97, 98],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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] " +
|
2023-05-31 01:24:49 +09:00
|
|
|
|
"/InkList [[1 2 3 4 5 6 7 8] [91 92 93 94 95 96 97 98]] /F 4 " +
|
|
|
|
|
"/Rotate 0 /BS << /W 1>> /C [0 0 0] /CA 0.12 /AP << /N 2 0 R>>>>\n" +
|
2022-07-25 05:19:09 +09:00
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const appearance = data.dependencies[0].data;
|
|
|
|
|
expect(appearance).toEqual(
|
|
|
|
|
"2 0 obj\n" +
|
2023-05-31 01:24:49 +09:00
|
|
|
|
"<< /FormType 1 /Subtype /Form /Type /XObject /BBox [12 34 56 78] /Length 136 /Resources " +
|
2022-07-25 05:19:09 +09:00
|
|
|
|
"<< /ExtGState << /R0 << /CA 0.12 /Type /ExtGState>>>>>>>> stream\n" +
|
|
|
|
|
"1 w 1 J 1 j\n" +
|
|
|
|
|
"0 G\n" +
|
|
|
|
|
"/R0 gs\n" +
|
|
|
|
|
"10 11 m\n" +
|
|
|
|
|
"12 13 14 15 16 17 c\n" +
|
|
|
|
|
"22 23 24 25 26 27 c\n" +
|
|
|
|
|
"S\n" +
|
|
|
|
|
"910 911 m\n" +
|
|
|
|
|
"912 913 914 915 916 917 c\n" +
|
|
|
|
|
"922 923 924 925 926 927 c\n" +
|
|
|
|
|
"S\n" +
|
|
|
|
|
"endstream\n" +
|
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2022-06-15 23:57:33 +09:00
|
|
|
|
it("should render an added Ink annotation for printing", async function () {
|
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test Ink printing");
|
|
|
|
|
const inkAnnotation = (
|
2023-09-07 21:14:35 +09:00
|
|
|
|
await AnnotationFactory.printNewAnnotations(
|
|
|
|
|
annotationGlobalsMock,
|
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
annotationType: AnnotationEditorType.INK,
|
|
|
|
|
rect: [12, 34, 56, 78],
|
|
|
|
|
rotation: 0,
|
|
|
|
|
thickness: 3,
|
|
|
|
|
opacity: 1,
|
|
|
|
|
color: [0, 255, 0],
|
|
|
|
|
paths: [
|
|
|
|
|
{
|
|
|
|
|
bezier: [1, 2, 3, 4, 5, 6, 7, 8],
|
|
|
|
|
// Useless in the printing case.
|
|
|
|
|
points: [1, 2, 3, 4, 5, 6, 7, 8],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
)
|
2022-06-15 23:57:33 +09:00
|
|
|
|
)[0];
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
const { opList } = await inkAnnotation.getOperatorList(
|
2022-06-15 23:57:33 +09:00
|
|
|
|
partialEvaluator,
|
|
|
|
|
task,
|
|
|
|
|
RenderingIntentFlag.PRINT,
|
|
|
|
|
false,
|
|
|
|
|
null
|
|
|
|
|
);
|
|
|
|
|
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray.length).toEqual(8);
|
|
|
|
|
expect(opList.fnArray).toEqual([
|
2022-06-15 23:57:33 +09:00
|
|
|
|
OPS.beginAnnotation,
|
|
|
|
|
OPS.setLineWidth,
|
2022-06-14 01:23:10 +09:00
|
|
|
|
OPS.setLineCap,
|
|
|
|
|
OPS.setLineJoin,
|
2022-06-15 23:57:33 +09:00
|
|
|
|
OPS.setStrokeRGBColor,
|
|
|
|
|
OPS.constructPath,
|
|
|
|
|
OPS.stroke,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Linewidth.
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[1]).toEqual([3]);
|
2022-06-14 01:23:10 +09:00
|
|
|
|
// LineCap.
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[2]).toEqual([1]);
|
2022-06-14 01:23:10 +09:00
|
|
|
|
// LineJoin.
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[3]).toEqual([1]);
|
2022-06-15 23:57:33 +09:00
|
|
|
|
// Color.
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[4]).toEqual(new Uint8ClampedArray([0, 255, 0]));
|
2022-06-15 23:57:33 +09:00
|
|
|
|
// Path.
|
2022-06-27 18:41:37 +09:00
|
|
|
|
expect(opList.argsArray[5][0]).toEqual([OPS.moveTo, OPS.curveTo]);
|
|
|
|
|
expect(opList.argsArray[5][1]).toEqual([1, 2, 3, 4, 5, 6, 7, 8]);
|
2022-06-15 23:57:33 +09:00
|
|
|
|
// Min-max.
|
2024-01-25 05:16:58 +09:00
|
|
|
|
expect(opList.argsArray[5][2]).toEqual([1, 2, 1, 2]);
|
2022-06-15 23:57:33 +09:00
|
|
|
|
});
|
2018-09-30 23:29:16 +09:00
|
|
|
|
});
|
2019-07-28 03:57:52 +09:00
|
|
|
|
|
2023-11-21 04:03:34 +09:00
|
|
|
|
describe("HighlightAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints to null if not defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const highlightDict = new Dict();
|
|
|
|
|
highlightDict.set("Type", Name.get("Annot"));
|
|
|
|
|
highlightDict.set("Subtype", Name.get("Highlight"));
|
|
|
|
|
|
|
|
|
|
const highlightRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: highlightRef, data: highlightDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
highlightRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.HIGHLIGHT);
|
|
|
|
|
expect(data.quadPoints).toEqual(null);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints if defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const highlightDict = new Dict();
|
|
|
|
|
highlightDict.set("Type", Name.get("Annot"));
|
|
|
|
|
highlightDict.set("Subtype", Name.get("Highlight"));
|
|
|
|
|
highlightDict.set("Rect", [10, 10, 20, 20]);
|
2020-12-06 05:27:38 +09:00
|
|
|
|
highlightDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
|
|
|
|
|
const highlightRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: highlightRef, data: highlightDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
highlightRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.HIGHLIGHT);
|
|
|
|
|
expect(data.quadPoints).toEqual([
|
|
|
|
|
[
|
|
|
|
|
{ x: 10, y: 20 },
|
|
|
|
|
{ x: 20, y: 20 },
|
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
|
{ x: 20, y: 10 },
|
|
|
|
|
],
|
|
|
|
|
]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
2020-10-21 19:00:34 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints to null when empty", async function () {
|
2020-10-21 19:00:34 +09:00
|
|
|
|
const highlightDict = new Dict();
|
|
|
|
|
highlightDict.set("Type", Name.get("Annot"));
|
|
|
|
|
highlightDict.set("Subtype", Name.get("Highlight"));
|
|
|
|
|
highlightDict.set("Rect", [10, 10, 20, 20]);
|
|
|
|
|
highlightDict.set("QuadPoints", []);
|
|
|
|
|
|
|
|
|
|
const highlightRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: highlightRef, data: highlightDict }]);
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2020-10-21 19:00:34 +09:00
|
|
|
|
xref,
|
|
|
|
|
highlightRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2020-10-21 19:00:34 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.HIGHLIGHT);
|
|
|
|
|
expect(data.quadPoints).toEqual(null);
|
2020-10-21 19:00:34 +09:00
|
|
|
|
});
|
2023-11-21 04:03:34 +09:00
|
|
|
|
|
|
|
|
|
it("should create a new Highlight annotation", async function () {
|
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test 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],
|
|
|
|
|
quadPoints: [1, 2, 3, 4, 5, 6, 7],
|
|
|
|
|
outlines: [
|
|
|
|
|
[8, 9, 10, 11],
|
|
|
|
|
[12, 13, 14, 15],
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const base = data.annotations[0].data.replace(/\(D:\d+\)/, "(date)");
|
|
|
|
|
expect(base).toEqual(
|
|
|
|
|
"1 0 obj\n" +
|
|
|
|
|
"<< /Type /Annot /Subtype /Highlight /CreationDate (date) /Rect [12 34 56 78] " +
|
|
|
|
|
"/F 4 /Border [0 0 0] /Rotate 0 /QuadPoints [1 2 3 4 5 6 7] /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 47 /Resources << /ExtGState << /R0 << /BM /Multiply>>>>>>>> stream\n" +
|
|
|
|
|
"0 g\n" +
|
|
|
|
|
"/R0 gs\n" +
|
|
|
|
|
"8 9 m\n" +
|
|
|
|
|
"10 11 l\n" +
|
|
|
|
|
"h\n" +
|
|
|
|
|
"12 13 m\n" +
|
|
|
|
|
"14 15 l\n" +
|
|
|
|
|
"h\n" +
|
|
|
|
|
"f*\n" +
|
|
|
|
|
"endstream\n" +
|
|
|
|
|
"endobj\n"
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render a new Highlight annotation for printing", async function () {
|
|
|
|
|
partialEvaluator.xref = new XRefMock();
|
|
|
|
|
const task = new WorkerTask("test 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],
|
|
|
|
|
quadPoints: [1, 2, 3, 4, 5, 6, 7],
|
|
|
|
|
outlines: [[8, 9, 10, 11]],
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
)[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.eoFill,
|
|
|
|
|
OPS.endAnnotation,
|
|
|
|
|
]);
|
|
|
|
|
});
|
2024-01-18 00:42:35 +09:00
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
]);
|
|
|
|
|
});
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("UnderlineAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints to null if not defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const underlineDict = new Dict();
|
|
|
|
|
underlineDict.set("Type", Name.get("Annot"));
|
|
|
|
|
underlineDict.set("Subtype", Name.get("Underline"));
|
|
|
|
|
|
|
|
|
|
const underlineRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: underlineRef, data: underlineDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
underlineRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.UNDERLINE);
|
|
|
|
|
expect(data.quadPoints).toEqual(null);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints if defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const underlineDict = new Dict();
|
|
|
|
|
underlineDict.set("Type", Name.get("Annot"));
|
|
|
|
|
underlineDict.set("Subtype", Name.get("Underline"));
|
|
|
|
|
underlineDict.set("Rect", [10, 10, 20, 20]);
|
2020-12-06 05:27:38 +09:00
|
|
|
|
underlineDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
|
|
|
|
|
const underlineRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: underlineRef, data: underlineDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
underlineRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.UNDERLINE);
|
|
|
|
|
expect(data.quadPoints).toEqual([
|
|
|
|
|
[
|
|
|
|
|
{ x: 10, y: 20 },
|
|
|
|
|
{ x: 20, y: 20 },
|
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
|
{ x: 20, y: 10 },
|
|
|
|
|
],
|
|
|
|
|
]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("SquigglyAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints to null if not defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const squigglyDict = new Dict();
|
|
|
|
|
squigglyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
squigglyDict.set("Subtype", Name.get("Squiggly"));
|
|
|
|
|
|
|
|
|
|
const squigglyRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: squigglyRef, data: squigglyDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
squigglyRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.SQUIGGLY);
|
|
|
|
|
expect(data.quadPoints).toEqual(null);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints if defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const squigglyDict = new Dict();
|
|
|
|
|
squigglyDict.set("Type", Name.get("Annot"));
|
|
|
|
|
squigglyDict.set("Subtype", Name.get("Squiggly"));
|
|
|
|
|
squigglyDict.set("Rect", [10, 10, 20, 20]);
|
2020-12-06 05:27:38 +09:00
|
|
|
|
squigglyDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
|
|
|
|
|
const squigglyRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: squigglyRef, data: squigglyDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
squigglyRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.SQUIGGLY);
|
|
|
|
|
expect(data.quadPoints).toEqual([
|
|
|
|
|
[
|
|
|
|
|
{ x: 10, y: 20 },
|
|
|
|
|
{ x: 20, y: 20 },
|
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
|
{ x: 20, y: 10 },
|
|
|
|
|
],
|
|
|
|
|
]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-14 19:28:14 +09:00
|
|
|
|
describe("StrikeOutAnnotation", function () {
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints to null if not defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const strikeOutDict = new Dict();
|
|
|
|
|
strikeOutDict.set("Type", Name.get("Annot"));
|
|
|
|
|
strikeOutDict.set("Subtype", Name.get("StrikeOut"));
|
|
|
|
|
|
|
|
|
|
const strikeOutRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: strikeOutRef, data: strikeOutDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
strikeOutRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.STRIKEOUT);
|
|
|
|
|
expect(data.quadPoints).toEqual(null);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
it("should set quadpoints if defined", async function () {
|
2019-07-28 03:57:52 +09:00
|
|
|
|
const strikeOutDict = new Dict();
|
|
|
|
|
strikeOutDict.set("Type", Name.get("Annot"));
|
|
|
|
|
strikeOutDict.set("Subtype", Name.get("StrikeOut"));
|
|
|
|
|
strikeOutDict.set("Rect", [10, 10, 20, 20]);
|
2020-12-06 05:27:38 +09:00
|
|
|
|
strikeOutDict.set("QuadPoints", [10, 20, 20, 20, 10, 10, 20, 10]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
|
|
|
|
|
const strikeOutRef = Ref.get(121, 0);
|
|
|
|
|
const xref = new XRefMock([{ ref: strikeOutRef, data: strikeOutDict }]);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
|
|
2021-04-18 01:23:40 +09:00
|
|
|
|
const { data } = await AnnotationFactory.create(
|
2019-07-28 03:57:52 +09:00
|
|
|
|
xref,
|
|
|
|
|
strikeOutRef,
|
2023-09-07 21:14:35 +09:00
|
|
|
|
annotationGlobalsMock,
|
2019-07-28 03:57:52 +09:00
|
|
|
|
idFactoryMock
|
2021-04-18 01:23:40 +09:00
|
|
|
|
);
|
|
|
|
|
expect(data.annotationType).toEqual(AnnotationType.STRIKEOUT);
|
|
|
|
|
expect(data.quadPoints).toEqual([
|
|
|
|
|
[
|
|
|
|
|
{ x: 10, y: 20 },
|
|
|
|
|
{ x: 20, y: 20 },
|
|
|
|
|
{ x: 10, y: 10 },
|
|
|
|
|
{ x: 20, y: 10 },
|
|
|
|
|
],
|
|
|
|
|
]);
|
2019-07-28 03:57:52 +09:00
|
|
|
|
});
|
|
|
|
|
});
|
2014-12-26 05:04:01 +09:00
|
|
|
|
});
|