annotation_spec.js 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. var _annotation = require("../../core/annotation.js");
  24. var _util = require("../../shared/util.js");
  25. var _test_utils = require("./test_utils.js");
  26. var _primitives = require("../../core/primitives.js");
  27. var _parser = require("../../core/parser.js");
  28. var _stream = require("../../core/stream.js");
  29. describe("annotation", function () {
  30. class PDFManagerMock {
  31. constructor(params) {
  32. this.docBaseUrl = params.docBaseUrl || null;
  33. }
  34. ensure(obj, prop, args) {
  35. return new Promise(function (resolve) {
  36. const value = obj[prop];
  37. if (typeof value === "function") {
  38. resolve(value.apply(obj, args));
  39. } else {
  40. resolve(value);
  41. }
  42. });
  43. }
  44. }
  45. let pdfManagerMock, idFactoryMock;
  46. beforeAll(function (done) {
  47. pdfManagerMock = new PDFManagerMock({
  48. docBaseUrl: null
  49. });
  50. idFactoryMock = (0, _test_utils.createIdFactory)(0);
  51. done();
  52. });
  53. afterAll(function () {
  54. pdfManagerMock = null;
  55. idFactoryMock = null;
  56. });
  57. describe("AnnotationFactory", function () {
  58. it("should get id for annotation", function (done) {
  59. const annotationDict = new _primitives.Dict();
  60. annotationDict.set("Type", _primitives.Name.get("Annot"));
  61. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  62. const annotationRef = _primitives.Ref.get(10, 0);
  63. const xref = new _test_utils.XRefMock([{
  64. ref: annotationRef,
  65. data: annotationDict
  66. }]);
  67. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  68. data
  69. }) => {
  70. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  71. expect(data.id).toEqual("10R");
  72. done();
  73. }, done.fail);
  74. });
  75. it("should handle, and get fallback IDs for, annotations that are not " + "indirect objects (issue 7569)", function (done) {
  76. const annotationDict = new _primitives.Dict();
  77. annotationDict.set("Type", _primitives.Name.get("Annot"));
  78. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  79. const xref = new _test_utils.XRefMock();
  80. const idFactory = (0, _test_utils.createIdFactory)(0);
  81. const annotation1 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(({
  82. data
  83. }) => {
  84. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  85. expect(data.id).toEqual("annot_p0_1");
  86. });
  87. const annotation2 = _annotation.AnnotationFactory.create(xref, annotationDict, pdfManagerMock, idFactory).then(({
  88. data
  89. }) => {
  90. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  91. expect(data.id).toEqual("annot_p0_2");
  92. });
  93. Promise.all([annotation1, annotation2]).then(done, done.fail);
  94. });
  95. it("should handle missing /Subtype", function (done) {
  96. const annotationDict = new _primitives.Dict();
  97. annotationDict.set("Type", _primitives.Name.get("Annot"));
  98. const annotationRef = _primitives.Ref.get(1, 0);
  99. const xref = new _test_utils.XRefMock([{
  100. ref: annotationRef,
  101. data: annotationDict
  102. }]);
  103. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  104. data
  105. }) => {
  106. expect(data.annotationType).toBeUndefined();
  107. done();
  108. }, done.fail);
  109. });
  110. });
  111. describe("getQuadPoints", function () {
  112. let dict, rect;
  113. beforeEach(function (done) {
  114. dict = new _primitives.Dict();
  115. rect = [];
  116. done();
  117. });
  118. afterEach(function () {
  119. dict = null;
  120. rect = null;
  121. });
  122. it("should ignore missing quadpoints", function () {
  123. expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
  124. });
  125. it("should ignore non-array values", function () {
  126. dict.set("QuadPoints", "foo");
  127. expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
  128. });
  129. it("should ignore arrays where the length is not a multiple of eight", function () {
  130. dict.set("QuadPoints", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  131. expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
  132. });
  133. it("should ignore quadpoints if one coordinate lies outside the rectangle", function () {
  134. rect = [10, 10, 20, 20];
  135. const inputs = [[11, 11, 12, 12, 9, 13, 14, 14], [11, 11, 12, 12, 13, 9, 14, 14], [11, 11, 12, 12, 21, 13, 14, 14], [11, 11, 12, 12, 13, 21, 14, 14]];
  136. for (const input of inputs) {
  137. dict.set("QuadPoints", input);
  138. expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual(null);
  139. }
  140. });
  141. it("should process valid quadpoints arrays", function () {
  142. rect = [10, 10, 20, 20];
  143. dict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18]);
  144. expect((0, _annotation.getQuadPoints)(dict, rect)).toEqual([[{
  145. x: 11,
  146. y: 11
  147. }, {
  148. x: 12,
  149. y: 12
  150. }, {
  151. x: 13,
  152. y: 13
  153. }, {
  154. x: 14,
  155. y: 14
  156. }], [{
  157. x: 15,
  158. y: 15
  159. }, {
  160. x: 16,
  161. y: 16
  162. }, {
  163. x: 17,
  164. y: 17
  165. }, {
  166. x: 18,
  167. y: 18
  168. }]]);
  169. });
  170. });
  171. describe("Annotation", function () {
  172. let dict, ref;
  173. beforeAll(function (done) {
  174. dict = new _primitives.Dict();
  175. ref = _primitives.Ref.get(1, 0);
  176. done();
  177. });
  178. afterAll(function () {
  179. dict = ref = null;
  180. });
  181. it("should set and get valid contents", function () {
  182. const annotation = new _annotation.Annotation({
  183. dict,
  184. ref
  185. });
  186. annotation.setContents("Foo bar baz");
  187. expect(annotation.contents).toEqual("Foo bar baz");
  188. });
  189. it("should not set and get invalid contents", function () {
  190. const annotation = new _annotation.Annotation({
  191. dict,
  192. ref
  193. });
  194. annotation.setContents(undefined);
  195. expect(annotation.contents).toEqual("");
  196. });
  197. it("should set and get a valid modification date", function () {
  198. const annotation = new _annotation.Annotation({
  199. dict,
  200. ref
  201. });
  202. annotation.setModificationDate("D:20190422");
  203. expect(annotation.modificationDate).toEqual("D:20190422");
  204. });
  205. it("should not set and get an invalid modification date", function () {
  206. const annotation = new _annotation.Annotation({
  207. dict,
  208. ref
  209. });
  210. annotation.setModificationDate(undefined);
  211. expect(annotation.modificationDate).toEqual(null);
  212. });
  213. it("should set and get flags", function () {
  214. const annotation = new _annotation.Annotation({
  215. dict,
  216. ref
  217. });
  218. annotation.setFlags(13);
  219. expect(annotation.hasFlag(_util.AnnotationFlag.INVISIBLE)).toEqual(true);
  220. expect(annotation.hasFlag(_util.AnnotationFlag.NOZOOM)).toEqual(true);
  221. expect(annotation.hasFlag(_util.AnnotationFlag.PRINT)).toEqual(true);
  222. expect(annotation.hasFlag(_util.AnnotationFlag.READONLY)).toEqual(false);
  223. });
  224. it("should be viewable and not printable by default", function () {
  225. const annotation = new _annotation.Annotation({
  226. dict,
  227. ref
  228. });
  229. expect(annotation.viewable).toEqual(true);
  230. expect(annotation.printable).toEqual(false);
  231. });
  232. it("should set and get a valid rectangle", function () {
  233. const annotation = new _annotation.Annotation({
  234. dict,
  235. ref
  236. });
  237. annotation.setRectangle([117, 694, 164.298, 720]);
  238. expect(annotation.rectangle).toEqual([117, 694, 164.298, 720]);
  239. });
  240. it("should not set and get an invalid rectangle", function () {
  241. const annotation = new _annotation.Annotation({
  242. dict,
  243. ref
  244. });
  245. annotation.setRectangle([117, 694, 164.298]);
  246. expect(annotation.rectangle).toEqual([0, 0, 0, 0]);
  247. });
  248. it("should reject a color if it is not an array", function () {
  249. const annotation = new _annotation.Annotation({
  250. dict,
  251. ref
  252. });
  253. annotation.setColor("red");
  254. expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
  255. });
  256. it("should set and get a transparent color", function () {
  257. const annotation = new _annotation.Annotation({
  258. dict,
  259. ref
  260. });
  261. annotation.setColor([]);
  262. expect(annotation.color).toEqual(null);
  263. });
  264. it("should set and get a grayscale color", function () {
  265. const annotation = new _annotation.Annotation({
  266. dict,
  267. ref
  268. });
  269. annotation.setColor([0.4]);
  270. expect(annotation.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
  271. });
  272. it("should set and get an RGB color", function () {
  273. const annotation = new _annotation.Annotation({
  274. dict,
  275. ref
  276. });
  277. annotation.setColor([0, 0, 1]);
  278. expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
  279. });
  280. it("should set and get a CMYK color", function () {
  281. const annotation = new _annotation.Annotation({
  282. dict,
  283. ref
  284. });
  285. annotation.setColor([0.1, 0.92, 0.84, 0.02]);
  286. expect(annotation.color).toEqual(new Uint8ClampedArray([234, 59, 48]));
  287. });
  288. it("should not set and get an invalid color", function () {
  289. const annotation = new _annotation.Annotation({
  290. dict,
  291. ref
  292. });
  293. annotation.setColor([0.4, 0.6]);
  294. expect(annotation.color).toEqual(new Uint8ClampedArray([0, 0, 0]));
  295. });
  296. });
  297. describe("AnnotationBorderStyle", function () {
  298. it("should set and get a valid width", function () {
  299. const borderStyle = new _annotation.AnnotationBorderStyle();
  300. borderStyle.setWidth(3);
  301. expect(borderStyle.width).toEqual(3);
  302. });
  303. it("should not set and get an invalid width", function () {
  304. const borderStyle = new _annotation.AnnotationBorderStyle();
  305. borderStyle.setWidth("three");
  306. expect(borderStyle.width).toEqual(1);
  307. });
  308. it("should set the width to zero, when the input is a `Name` (issue 10385)", function () {
  309. const borderStyleZero = new _annotation.AnnotationBorderStyle();
  310. borderStyleZero.setWidth(_primitives.Name.get("0"));
  311. const borderStyleFive = new _annotation.AnnotationBorderStyle();
  312. borderStyleFive.setWidth(_primitives.Name.get("5"));
  313. expect(borderStyleZero.width).toEqual(0);
  314. expect(borderStyleFive.width).toEqual(0);
  315. });
  316. it("should set and get a valid style", function () {
  317. const borderStyle = new _annotation.AnnotationBorderStyle();
  318. borderStyle.setStyle(_primitives.Name.get("D"));
  319. expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.DASHED);
  320. });
  321. it("should not set and get an invalid style", function () {
  322. const borderStyle = new _annotation.AnnotationBorderStyle();
  323. borderStyle.setStyle("Dashed");
  324. expect(borderStyle.style).toEqual(_util.AnnotationBorderStyleType.SOLID);
  325. });
  326. it("should set and get a valid dash array", function () {
  327. const borderStyle = new _annotation.AnnotationBorderStyle();
  328. borderStyle.setDashArray([1, 2, 3]);
  329. expect(borderStyle.dashArray).toEqual([1, 2, 3]);
  330. });
  331. it("should not set and get an invalid dash array", function () {
  332. const borderStyle = new _annotation.AnnotationBorderStyle();
  333. borderStyle.setDashArray([0, 0]);
  334. expect(borderStyle.dashArray).toEqual([3]);
  335. });
  336. it("should set and get a valid horizontal corner radius", function () {
  337. const borderStyle = new _annotation.AnnotationBorderStyle();
  338. borderStyle.setHorizontalCornerRadius(3);
  339. expect(borderStyle.horizontalCornerRadius).toEqual(3);
  340. });
  341. it("should not set and get an invalid horizontal corner radius", function () {
  342. const borderStyle = new _annotation.AnnotationBorderStyle();
  343. borderStyle.setHorizontalCornerRadius("three");
  344. expect(borderStyle.horizontalCornerRadius).toEqual(0);
  345. });
  346. it("should set and get a valid vertical corner radius", function () {
  347. const borderStyle = new _annotation.AnnotationBorderStyle();
  348. borderStyle.setVerticalCornerRadius(3);
  349. expect(borderStyle.verticalCornerRadius).toEqual(3);
  350. });
  351. it("should not set and get an invalid vertical corner radius", function () {
  352. const borderStyle = new _annotation.AnnotationBorderStyle();
  353. borderStyle.setVerticalCornerRadius("three");
  354. expect(borderStyle.verticalCornerRadius).toEqual(0);
  355. });
  356. });
  357. describe("MarkupAnnotation", function () {
  358. let dict, ref;
  359. beforeAll(function (done) {
  360. dict = new _primitives.Dict();
  361. ref = _primitives.Ref.get(1, 0);
  362. done();
  363. });
  364. afterAll(function () {
  365. dict = ref = null;
  366. });
  367. it("should set and get a valid creation date", function () {
  368. const markupAnnotation = new _annotation.MarkupAnnotation({
  369. dict,
  370. ref
  371. });
  372. markupAnnotation.setCreationDate("D:20190422");
  373. expect(markupAnnotation.creationDate).toEqual("D:20190422");
  374. });
  375. it("should not set and get an invalid creation date", function () {
  376. const markupAnnotation = new _annotation.MarkupAnnotation({
  377. dict,
  378. ref
  379. });
  380. markupAnnotation.setCreationDate(undefined);
  381. expect(markupAnnotation.creationDate).toEqual(null);
  382. });
  383. it("should not parse IRT/RT when not defined", function (done) {
  384. dict.set("Type", _primitives.Name.get("Annot"));
  385. dict.set("Subtype", _primitives.Name.get("Text"));
  386. const xref = new _test_utils.XRefMock([{
  387. ref,
  388. data: dict
  389. }]);
  390. _annotation.AnnotationFactory.create(xref, ref, pdfManagerMock, idFactoryMock).then(({
  391. data
  392. }) => {
  393. expect(data.inReplyTo).toBeUndefined();
  394. expect(data.replyType).toBeUndefined();
  395. done();
  396. }, done.fail);
  397. });
  398. it("should parse IRT and set default RT when not defined.", function (done) {
  399. const annotationRef = _primitives.Ref.get(819, 0);
  400. const annotationDict = new _primitives.Dict();
  401. annotationDict.set("Type", _primitives.Name.get("Annot"));
  402. annotationDict.set("Subtype", _primitives.Name.get("Text"));
  403. const replyRef = _primitives.Ref.get(820, 0);
  404. const replyDict = new _primitives.Dict();
  405. replyDict.set("Type", _primitives.Name.get("Annot"));
  406. replyDict.set("Subtype", _primitives.Name.get("Text"));
  407. replyDict.set("IRT", annotationRef);
  408. const xref = new _test_utils.XRefMock([{
  409. ref: annotationRef,
  410. data: annotationDict
  411. }, {
  412. ref: replyRef,
  413. data: replyDict
  414. }]);
  415. annotationDict.assignXref(xref);
  416. replyDict.assignXref(xref);
  417. _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
  418. data
  419. }) => {
  420. expect(data.inReplyTo).toEqual(annotationRef.toString());
  421. expect(data.replyType).toEqual("R");
  422. done();
  423. }, done.fail);
  424. });
  425. it("should parse IRT/RT for a group type", function (done) {
  426. const annotationRef = _primitives.Ref.get(819, 0);
  427. const annotationDict = new _primitives.Dict();
  428. annotationDict.set("Type", _primitives.Name.get("Annot"));
  429. annotationDict.set("Subtype", _primitives.Name.get("Text"));
  430. annotationDict.set("T", "ParentTitle");
  431. annotationDict.set("Contents", "ParentText");
  432. annotationDict.set("CreationDate", "D:20180423");
  433. annotationDict.set("M", "D:20190423");
  434. annotationDict.set("C", [0, 0, 1]);
  435. const popupRef = _primitives.Ref.get(820, 0);
  436. const popupDict = new _primitives.Dict();
  437. popupDict.set("Type", _primitives.Name.get("Annot"));
  438. popupDict.set("Subtype", _primitives.Name.get("Popup"));
  439. popupDict.set("Parent", annotationRef);
  440. annotationDict.set("Popup", popupRef);
  441. const replyRef = _primitives.Ref.get(821, 0);
  442. const replyDict = new _primitives.Dict();
  443. replyDict.set("Type", _primitives.Name.get("Annot"));
  444. replyDict.set("Subtype", _primitives.Name.get("Text"));
  445. replyDict.set("IRT", annotationRef);
  446. replyDict.set("RT", _primitives.Name.get("Group"));
  447. replyDict.set("T", "ReplyTitle");
  448. replyDict.set("Contents", "ReplyText");
  449. replyDict.set("CreationDate", "D:20180523");
  450. replyDict.set("M", "D:20190523");
  451. replyDict.set("C", [0.4]);
  452. const xref = new _test_utils.XRefMock([{
  453. ref: annotationRef,
  454. data: annotationDict
  455. }, {
  456. ref: popupRef,
  457. data: popupDict
  458. }, {
  459. ref: replyRef,
  460. data: replyDict
  461. }]);
  462. annotationDict.assignXref(xref);
  463. popupDict.assignXref(xref);
  464. replyDict.assignXref(xref);
  465. _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
  466. data
  467. }) => {
  468. expect(data.inReplyTo).toEqual(annotationRef.toString());
  469. expect(data.replyType).toEqual("Group");
  470. expect(data.title).toEqual("ParentTitle");
  471. expect(data.contents).toEqual("ParentText");
  472. expect(data.creationDate).toEqual("D:20180423");
  473. expect(data.modificationDate).toEqual("D:20190423");
  474. expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
  475. expect(data.hasPopup).toEqual(true);
  476. done();
  477. }, done.fail);
  478. });
  479. it("should parse IRT/RT for a reply type", function (done) {
  480. const annotationRef = _primitives.Ref.get(819, 0);
  481. const annotationDict = new _primitives.Dict();
  482. annotationDict.set("Type", _primitives.Name.get("Annot"));
  483. annotationDict.set("Subtype", _primitives.Name.get("Text"));
  484. annotationDict.set("T", "ParentTitle");
  485. annotationDict.set("Contents", "ParentText");
  486. annotationDict.set("CreationDate", "D:20180423");
  487. annotationDict.set("M", "D:20190423");
  488. annotationDict.set("C", [0, 0, 1]);
  489. const popupRef = _primitives.Ref.get(820, 0);
  490. const popupDict = new _primitives.Dict();
  491. popupDict.set("Type", _primitives.Name.get("Annot"));
  492. popupDict.set("Subtype", _primitives.Name.get("Popup"));
  493. popupDict.set("Parent", annotationRef);
  494. annotationDict.set("Popup", popupRef);
  495. const replyRef = _primitives.Ref.get(821, 0);
  496. const replyDict = new _primitives.Dict();
  497. replyDict.set("Type", _primitives.Name.get("Annot"));
  498. replyDict.set("Subtype", _primitives.Name.get("Text"));
  499. replyDict.set("IRT", annotationRef);
  500. replyDict.set("RT", _primitives.Name.get("R"));
  501. replyDict.set("T", "ReplyTitle");
  502. replyDict.set("Contents", "ReplyText");
  503. replyDict.set("CreationDate", "D:20180523");
  504. replyDict.set("M", "D:20190523");
  505. replyDict.set("C", [0.4]);
  506. const xref = new _test_utils.XRefMock([{
  507. ref: annotationRef,
  508. data: annotationDict
  509. }, {
  510. ref: popupRef,
  511. data: popupDict
  512. }, {
  513. ref: replyRef,
  514. data: replyDict
  515. }]);
  516. annotationDict.assignXref(xref);
  517. popupDict.assignXref(xref);
  518. replyDict.assignXref(xref);
  519. _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
  520. data
  521. }) => {
  522. expect(data.inReplyTo).toEqual(annotationRef.toString());
  523. expect(data.replyType).toEqual("R");
  524. expect(data.title).toEqual("ReplyTitle");
  525. expect(data.contents).toEqual("ReplyText");
  526. expect(data.creationDate).toEqual("D:20180523");
  527. expect(data.modificationDate).toEqual("D:20190523");
  528. expect(data.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
  529. expect(data.hasPopup).toEqual(false);
  530. done();
  531. }, done.fail);
  532. });
  533. });
  534. describe("TextAnnotation", function () {
  535. it("should not parse state model and state when not defined", function (done) {
  536. const annotationRef = _primitives.Ref.get(819, 0);
  537. const annotationDict = new _primitives.Dict();
  538. annotationDict.set("Type", _primitives.Name.get("Annot"));
  539. annotationDict.set("Subtype", _primitives.Name.get("Text"));
  540. annotationDict.set("Contents", "TestText");
  541. const replyRef = _primitives.Ref.get(820, 0);
  542. const replyDict = new _primitives.Dict();
  543. replyDict.set("Type", _primitives.Name.get("Annot"));
  544. replyDict.set("Subtype", _primitives.Name.get("Text"));
  545. replyDict.set("IRT", annotationRef);
  546. replyDict.set("RT", _primitives.Name.get("R"));
  547. replyDict.set("Contents", "ReplyText");
  548. const xref = new _test_utils.XRefMock([{
  549. ref: annotationRef,
  550. data: annotationDict
  551. }, {
  552. ref: replyRef,
  553. data: replyDict
  554. }]);
  555. annotationDict.assignXref(xref);
  556. replyDict.assignXref(xref);
  557. _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
  558. data
  559. }) => {
  560. expect(data.stateModel).toBeNull();
  561. expect(data.state).toBeNull();
  562. done();
  563. }, done.fail);
  564. });
  565. it("should correctly parse state model and state when defined", function (done) {
  566. const annotationRef = _primitives.Ref.get(819, 0);
  567. const annotationDict = new _primitives.Dict();
  568. annotationDict.set("Type", _primitives.Name.get("Annot"));
  569. annotationDict.set("Subtype", _primitives.Name.get("Text"));
  570. const replyRef = _primitives.Ref.get(820, 0);
  571. const replyDict = new _primitives.Dict();
  572. replyDict.set("Type", _primitives.Name.get("Annot"));
  573. replyDict.set("Subtype", _primitives.Name.get("Text"));
  574. replyDict.set("IRT", annotationRef);
  575. replyDict.set("RT", _primitives.Name.get("R"));
  576. replyDict.set("StateModel", "Review");
  577. replyDict.set("State", "Rejected");
  578. const xref = new _test_utils.XRefMock([{
  579. ref: annotationRef,
  580. data: annotationDict
  581. }, {
  582. ref: replyRef,
  583. data: replyDict
  584. }]);
  585. annotationDict.assignXref(xref);
  586. replyDict.assignXref(xref);
  587. _annotation.AnnotationFactory.create(xref, replyRef, pdfManagerMock, idFactoryMock).then(({
  588. data
  589. }) => {
  590. expect(data.stateModel).toEqual("Review");
  591. expect(data.state).toEqual("Rejected");
  592. done();
  593. }, done.fail);
  594. });
  595. });
  596. describe("LinkAnnotation", function () {
  597. it("should correctly parse a URI action", function (done) {
  598. const actionDict = new _primitives.Dict();
  599. actionDict.set("Type", _primitives.Name.get("Action"));
  600. actionDict.set("S", _primitives.Name.get("URI"));
  601. actionDict.set("URI", "http://www.ctan.org/tex-archive/info/lshort");
  602. const annotationDict = new _primitives.Dict();
  603. annotationDict.set("Type", _primitives.Name.get("Annot"));
  604. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  605. annotationDict.set("A", actionDict);
  606. const annotationRef = _primitives.Ref.get(820, 0);
  607. const xref = new _test_utils.XRefMock([{
  608. ref: annotationRef,
  609. data: annotationDict
  610. }]);
  611. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  612. data
  613. }) => {
  614. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  615. expect(data.url).toEqual("http://www.ctan.org/tex-archive/info/lshort");
  616. expect(data.unsafeUrl).toEqual("http://www.ctan.org/tex-archive/info/lshort");
  617. expect(data.dest).toBeUndefined();
  618. done();
  619. }, done.fail);
  620. });
  621. it("should correctly parse a URI action, where the URI entry " + "is missing a protocol", function (done) {
  622. const actionDict = new _primitives.Dict();
  623. actionDict.set("Type", _primitives.Name.get("Action"));
  624. actionDict.set("S", _primitives.Name.get("URI"));
  625. actionDict.set("URI", "www.hmrc.gov.uk");
  626. const annotationDict = new _primitives.Dict();
  627. annotationDict.set("Type", _primitives.Name.get("Annot"));
  628. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  629. annotationDict.set("A", actionDict);
  630. const annotationRef = _primitives.Ref.get(353, 0);
  631. const xref = new _test_utils.XRefMock([{
  632. ref: annotationRef,
  633. data: annotationDict
  634. }]);
  635. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  636. data
  637. }) => {
  638. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  639. expect(data.url).toEqual("http://www.hmrc.gov.uk/");
  640. expect(data.unsafeUrl).toEqual("http://www.hmrc.gov.uk");
  641. expect(data.dest).toBeUndefined();
  642. done();
  643. }, done.fail);
  644. });
  645. it("should correctly parse a URI action, where the URI entry " + "has an incorrect encoding (bug 1122280)", function (done) {
  646. const actionStream = new _stream.StringStream("<<\n" + "/Type /Action\n" + "/S /URI\n" + "/URI (http://www.example.com/\\303\\274\\303\\266\\303\\244)\n" + ">>\n");
  647. const parser = new _parser.Parser({
  648. lexer: new _parser.Lexer(actionStream),
  649. xref: null
  650. });
  651. const actionDict = parser.getObj();
  652. const annotationDict = new _primitives.Dict();
  653. annotationDict.set("Type", _primitives.Name.get("Annot"));
  654. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  655. annotationDict.set("A", actionDict);
  656. const annotationRef = _primitives.Ref.get(8, 0);
  657. const xref = new _test_utils.XRefMock([{
  658. ref: annotationRef,
  659. data: annotationDict
  660. }]);
  661. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  662. data
  663. }) => {
  664. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  665. expect(data.url).toEqual(new URL((0, _util.stringToUTF8String)("http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4")).href);
  666. expect(data.unsafeUrl).toEqual((0, _util.stringToUTF8String)("http://www.example.com/\xC3\xBC\xC3\xB6\xC3\xA4"));
  667. expect(data.dest).toBeUndefined();
  668. done();
  669. }, done.fail);
  670. });
  671. it("should correctly parse a GoTo action", function (done) {
  672. const actionDict = new _primitives.Dict();
  673. actionDict.set("Type", _primitives.Name.get("Action"));
  674. actionDict.set("S", _primitives.Name.get("GoTo"));
  675. actionDict.set("D", "page.157");
  676. const annotationDict = new _primitives.Dict();
  677. annotationDict.set("Type", _primitives.Name.get("Annot"));
  678. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  679. annotationDict.set("A", actionDict);
  680. const annotationRef = _primitives.Ref.get(798, 0);
  681. const xref = new _test_utils.XRefMock([{
  682. ref: annotationRef,
  683. data: annotationDict
  684. }]);
  685. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  686. data
  687. }) => {
  688. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  689. expect(data.url).toBeUndefined();
  690. expect(data.unsafeUrl).toBeUndefined();
  691. expect(data.dest).toEqual("page.157");
  692. done();
  693. }, done.fail);
  694. });
  695. it("should correctly parse a GoToR action, where the FileSpec entry " + "is a string containing a relative URL", function (done) {
  696. const actionDict = new _primitives.Dict();
  697. actionDict.set("Type", _primitives.Name.get("Action"));
  698. actionDict.set("S", _primitives.Name.get("GoToR"));
  699. actionDict.set("F", "../../0013/001346/134685E.pdf");
  700. actionDict.set("D", "4.3");
  701. actionDict.set("NewWindow", true);
  702. const annotationDict = new _primitives.Dict();
  703. annotationDict.set("Type", _primitives.Name.get("Annot"));
  704. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  705. annotationDict.set("A", actionDict);
  706. const annotationRef = _primitives.Ref.get(489, 0);
  707. const xref = new _test_utils.XRefMock([{
  708. ref: annotationRef,
  709. data: annotationDict
  710. }]);
  711. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  712. data
  713. }) => {
  714. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  715. expect(data.url).toBeUndefined();
  716. expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");
  717. expect(data.dest).toBeUndefined();
  718. expect(data.newWindow).toEqual(true);
  719. done();
  720. }, done.fail);
  721. });
  722. it("should correctly parse a GoToR action, containing a relative URL, " + 'with the "docBaseUrl" parameter specified', function (done) {
  723. const actionDict = new _primitives.Dict();
  724. actionDict.set("Type", _primitives.Name.get("Action"));
  725. actionDict.set("S", _primitives.Name.get("GoToR"));
  726. actionDict.set("F", "../../0013/001346/134685E.pdf");
  727. actionDict.set("D", "4.3");
  728. const annotationDict = new _primitives.Dict();
  729. annotationDict.set("Type", _primitives.Name.get("Annot"));
  730. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  731. annotationDict.set("A", actionDict);
  732. const annotationRef = _primitives.Ref.get(489, 0);
  733. const xref = new _test_utils.XRefMock([{
  734. ref: annotationRef,
  735. data: annotationDict
  736. }]);
  737. const pdfManager = new PDFManagerMock({
  738. docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"
  739. });
  740. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(({
  741. data
  742. }) => {
  743. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  744. expect(data.url).toEqual("http://www.example.com/0013/001346/134685E.pdf#4.3");
  745. expect(data.unsafeUrl).toEqual("../../0013/001346/134685E.pdf#4.3");
  746. expect(data.dest).toBeUndefined();
  747. done();
  748. }, done.fail);
  749. });
  750. it("should correctly parse a GoToR action, with named destination", function (done) {
  751. const actionDict = new _primitives.Dict();
  752. actionDict.set("Type", _primitives.Name.get("Action"));
  753. actionDict.set("S", _primitives.Name.get("GoToR"));
  754. actionDict.set("F", "http://www.example.com/test.pdf");
  755. actionDict.set("D", "15");
  756. const annotationDict = new _primitives.Dict();
  757. annotationDict.set("Type", _primitives.Name.get("Annot"));
  758. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  759. annotationDict.set("A", actionDict);
  760. const annotationRef = _primitives.Ref.get(495, 0);
  761. const xref = new _test_utils.XRefMock([{
  762. ref: annotationRef,
  763. data: annotationDict
  764. }]);
  765. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  766. data
  767. }) => {
  768. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  769. expect(data.url).toEqual("http://www.example.com/test.pdf#15");
  770. expect(data.unsafeUrl).toEqual("http://www.example.com/test.pdf#15");
  771. expect(data.dest).toBeUndefined();
  772. expect(data.newWindow).toBeFalsy();
  773. done();
  774. }, done.fail);
  775. });
  776. it("should correctly parse a GoToR action, with explicit destination array", function (done) {
  777. const actionDict = new _primitives.Dict();
  778. actionDict.set("Type", _primitives.Name.get("Action"));
  779. actionDict.set("S", _primitives.Name.get("GoToR"));
  780. actionDict.set("F", "http://www.example.com/test.pdf");
  781. actionDict.set("D", [14, _primitives.Name.get("XYZ"), null, 298.043, null]);
  782. const annotationDict = new _primitives.Dict();
  783. annotationDict.set("Type", _primitives.Name.get("Annot"));
  784. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  785. annotationDict.set("A", actionDict);
  786. const annotationRef = _primitives.Ref.get(489, 0);
  787. const xref = new _test_utils.XRefMock([{
  788. ref: annotationRef,
  789. data: annotationDict
  790. }]);
  791. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  792. data
  793. }) => {
  794. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  795. expect(data.url).toEqual(new URL("http://www.example.com/test.pdf#" + '[14,{"name":"XYZ"},null,298.043,null]').href);
  796. expect(data.unsafeUrl).toEqual("http://www.example.com/test.pdf#" + '[14,{"name":"XYZ"},null,298.043,null]');
  797. expect(data.dest).toBeUndefined();
  798. expect(data.newWindow).toBeFalsy();
  799. done();
  800. }, done.fail);
  801. });
  802. it("should correctly parse a Launch action, where the FileSpec dict " + 'contains a relative URL, with the "docBaseUrl" parameter specified', function (done) {
  803. const fileSpecDict = new _primitives.Dict();
  804. fileSpecDict.set("Type", _primitives.Name.get("FileSpec"));
  805. fileSpecDict.set("F", "Part II/Part II.pdf");
  806. fileSpecDict.set("UF", "Part II/Part II.pdf");
  807. const actionDict = new _primitives.Dict();
  808. actionDict.set("Type", _primitives.Name.get("Action"));
  809. actionDict.set("S", _primitives.Name.get("Launch"));
  810. actionDict.set("F", fileSpecDict);
  811. actionDict.set("NewWindow", true);
  812. const annotationDict = new _primitives.Dict();
  813. annotationDict.set("Type", _primitives.Name.get("Annot"));
  814. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  815. annotationDict.set("A", actionDict);
  816. const annotationRef = _primitives.Ref.get(88, 0);
  817. const xref = new _test_utils.XRefMock([{
  818. ref: annotationRef,
  819. data: annotationDict
  820. }]);
  821. const pdfManager = new PDFManagerMock({
  822. docBaseUrl: "http://www.example.com/test/pdfs/qwerty.pdf"
  823. });
  824. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManager, idFactoryMock).then(({
  825. data
  826. }) => {
  827. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  828. expect(data.url).toEqual(new URL("http://www.example.com/test/pdfs/Part II/Part II.pdf").href);
  829. expect(data.unsafeUrl).toEqual("Part II/Part II.pdf");
  830. expect(data.dest).toBeUndefined();
  831. expect(data.newWindow).toEqual(true);
  832. done();
  833. }, done.fail);
  834. });
  835. it("should recover valid URLs from JavaScript actions having certain " + "white-listed formats", function (done) {
  836. function checkJsAction(params) {
  837. const jsEntry = params.jsEntry;
  838. const expectedUrl = params.expectedUrl;
  839. const expectedUnsafeUrl = params.expectedUnsafeUrl;
  840. const expectedNewWindow = params.expectedNewWindow;
  841. const actionDict = new _primitives.Dict();
  842. actionDict.set("Type", _primitives.Name.get("Action"));
  843. actionDict.set("S", _primitives.Name.get("JavaScript"));
  844. actionDict.set("JS", jsEntry);
  845. const annotationDict = new _primitives.Dict();
  846. annotationDict.set("Type", _primitives.Name.get("Annot"));
  847. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  848. annotationDict.set("A", actionDict);
  849. const annotationRef = _primitives.Ref.get(46, 0);
  850. const xref = new _test_utils.XRefMock([{
  851. ref: annotationRef,
  852. data: annotationDict
  853. }]);
  854. return _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  855. data
  856. }) => {
  857. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  858. expect(data.url).toEqual(expectedUrl);
  859. expect(data.unsafeUrl).toEqual(expectedUnsafeUrl);
  860. expect(data.dest).toBeUndefined();
  861. expect(data.newWindow).toEqual(expectedNewWindow);
  862. });
  863. }
  864. const annotation1 = checkJsAction({
  865. jsEntry: 'function someFun() { return "qwerty"; } someFun();',
  866. expectedUrl: undefined,
  867. expectedUnsafeUrl: undefined,
  868. expectedNewWindow: undefined
  869. });
  870. const annotation2 = checkJsAction({
  871. jsEntry: "window.open('http://www.example.com/test.pdf')",
  872. expectedUrl: new URL("http://www.example.com/test.pdf").href,
  873. expectedUnsafeUrl: "http://www.example.com/test.pdf",
  874. expectedNewWindow: undefined
  875. });
  876. const annotation3 = checkJsAction({
  877. jsEntry: new _stream.StringStream('app.launchURL("http://www.example.com/test.pdf", true)'),
  878. expectedUrl: new URL("http://www.example.com/test.pdf").href,
  879. expectedUnsafeUrl: "http://www.example.com/test.pdf",
  880. expectedNewWindow: true
  881. });
  882. Promise.all([annotation1, annotation2, annotation3]).then(done, done.fail);
  883. });
  884. it("should correctly parse a Named action", function (done) {
  885. const actionDict = new _primitives.Dict();
  886. actionDict.set("Type", _primitives.Name.get("Action"));
  887. actionDict.set("S", _primitives.Name.get("Named"));
  888. actionDict.set("N", _primitives.Name.get("GoToPage"));
  889. const annotationDict = new _primitives.Dict();
  890. annotationDict.set("Type", _primitives.Name.get("Annot"));
  891. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  892. annotationDict.set("A", actionDict);
  893. const annotationRef = _primitives.Ref.get(12, 0);
  894. const xref = new _test_utils.XRefMock([{
  895. ref: annotationRef,
  896. data: annotationDict
  897. }]);
  898. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  899. data
  900. }) => {
  901. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  902. expect(data.url).toBeUndefined();
  903. expect(data.unsafeUrl).toBeUndefined();
  904. expect(data.action).toEqual("GoToPage");
  905. done();
  906. }, done.fail);
  907. });
  908. it("should correctly parse a simple Dest", function (done) {
  909. const annotationDict = new _primitives.Dict();
  910. annotationDict.set("Type", _primitives.Name.get("Annot"));
  911. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  912. annotationDict.set("Dest", _primitives.Name.get("LI0"));
  913. const annotationRef = _primitives.Ref.get(583, 0);
  914. const xref = new _test_utils.XRefMock([{
  915. ref: annotationRef,
  916. data: annotationDict
  917. }]);
  918. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  919. data
  920. }) => {
  921. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  922. expect(data.url).toBeUndefined();
  923. expect(data.unsafeUrl).toBeUndefined();
  924. expect(data.dest).toEqual("LI0");
  925. done();
  926. }, done.fail);
  927. });
  928. it("should correctly parse a simple Dest, with explicit destination array", function (done) {
  929. const annotationDict = new _primitives.Dict();
  930. annotationDict.set("Type", _primitives.Name.get("Annot"));
  931. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  932. annotationDict.set("Dest", [_primitives.Ref.get(17, 0), _primitives.Name.get("XYZ"), 0, 841.89, null]);
  933. const annotationRef = _primitives.Ref.get(10, 0);
  934. const xref = new _test_utils.XRefMock([{
  935. ref: annotationRef,
  936. data: annotationDict
  937. }]);
  938. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  939. data
  940. }) => {
  941. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  942. expect(data.url).toBeUndefined();
  943. expect(data.unsafeUrl).toBeUndefined();
  944. expect(data.dest).toEqual([{
  945. num: 17,
  946. gen: 0
  947. }, {
  948. name: "XYZ"
  949. }, 0, 841.89, null]);
  950. done();
  951. }, done.fail);
  952. });
  953. it("should correctly parse a Dest, which violates the specification " + "by containing a dictionary", function (done) {
  954. const destDict = new _primitives.Dict();
  955. destDict.set("Type", _primitives.Name.get("Action"));
  956. destDict.set("S", _primitives.Name.get("GoTo"));
  957. destDict.set("D", "page.157");
  958. const annotationDict = new _primitives.Dict();
  959. annotationDict.set("Type", _primitives.Name.get("Annot"));
  960. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  961. annotationDict.set("Dest", destDict);
  962. const annotationRef = _primitives.Ref.get(798, 0);
  963. const xref = new _test_utils.XRefMock([{
  964. ref: annotationRef,
  965. data: annotationDict
  966. }]);
  967. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  968. data
  969. }) => {
  970. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  971. expect(data.url).toBeUndefined();
  972. expect(data.unsafeUrl).toBeUndefined();
  973. expect(data.dest).toEqual("page.157");
  974. done();
  975. }, done.fail);
  976. });
  977. it("should not set quadpoints if not defined", function (done) {
  978. const annotationDict = new _primitives.Dict();
  979. annotationDict.set("Type", _primitives.Name.get("Annot"));
  980. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  981. const annotationRef = _primitives.Ref.get(121, 0);
  982. const xref = new _test_utils.XRefMock([{
  983. ref: annotationRef,
  984. data: annotationDict
  985. }]);
  986. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  987. data
  988. }) => {
  989. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  990. expect(data.quadPoints).toBeUndefined();
  991. done();
  992. }, done.fail);
  993. });
  994. it("should set quadpoints if defined", function (done) {
  995. const annotationDict = new _primitives.Dict();
  996. annotationDict.set("Type", _primitives.Name.get("Annot"));
  997. annotationDict.set("Subtype", _primitives.Name.get("Link"));
  998. annotationDict.set("Rect", [10, 10, 20, 20]);
  999. annotationDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
  1000. const annotationRef = _primitives.Ref.get(121, 0);
  1001. const xref = new _test_utils.XRefMock([{
  1002. ref: annotationRef,
  1003. data: annotationDict
  1004. }]);
  1005. _annotation.AnnotationFactory.create(xref, annotationRef, pdfManagerMock, idFactoryMock).then(({
  1006. data
  1007. }) => {
  1008. expect(data.annotationType).toEqual(_util.AnnotationType.LINK);
  1009. expect(data.quadPoints).toEqual([[{
  1010. x: 11,
  1011. y: 11
  1012. }, {
  1013. x: 12,
  1014. y: 12
  1015. }, {
  1016. x: 13,
  1017. y: 13
  1018. }, {
  1019. x: 14,
  1020. y: 14
  1021. }]]);
  1022. done();
  1023. }, done.fail);
  1024. });
  1025. });
  1026. describe("WidgetAnnotation", function () {
  1027. let widgetDict;
  1028. beforeEach(function (done) {
  1029. widgetDict = new _primitives.Dict();
  1030. widgetDict.set("Type", _primitives.Name.get("Annot"));
  1031. widgetDict.set("Subtype", _primitives.Name.get("Widget"));
  1032. done();
  1033. });
  1034. afterEach(function () {
  1035. widgetDict = null;
  1036. });
  1037. it("should handle unknown field names", function (done) {
  1038. const widgetRef = _primitives.Ref.get(20, 0);
  1039. const xref = new _test_utils.XRefMock([{
  1040. ref: widgetRef,
  1041. data: widgetDict
  1042. }]);
  1043. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
  1044. data
  1045. }) => {
  1046. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1047. expect(data.fieldName).toEqual("");
  1048. done();
  1049. }, done.fail);
  1050. });
  1051. it("should construct the field name when there are no ancestors", function (done) {
  1052. widgetDict.set("T", "foo");
  1053. const widgetRef = _primitives.Ref.get(21, 0);
  1054. const xref = new _test_utils.XRefMock([{
  1055. ref: widgetRef,
  1056. data: widgetDict
  1057. }]);
  1058. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
  1059. data
  1060. }) => {
  1061. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1062. expect(data.fieldName).toEqual("foo");
  1063. done();
  1064. }, done.fail);
  1065. });
  1066. it("should construct the field name when there are ancestors", function (done) {
  1067. const firstParent = new _primitives.Dict();
  1068. firstParent.set("T", "foo");
  1069. const secondParent = new _primitives.Dict();
  1070. secondParent.set("Parent", firstParent);
  1071. secondParent.set("T", "bar");
  1072. widgetDict.set("Parent", secondParent);
  1073. widgetDict.set("T", "baz");
  1074. const widgetRef = _primitives.Ref.get(22, 0);
  1075. const xref = new _test_utils.XRefMock([{
  1076. ref: widgetRef,
  1077. data: widgetDict
  1078. }]);
  1079. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
  1080. data
  1081. }) => {
  1082. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1083. expect(data.fieldName).toEqual("foo.bar.baz");
  1084. done();
  1085. }, done.fail);
  1086. });
  1087. it("should construct the field name if a parent is not a dictionary " + "(issue 8143)", function (done) {
  1088. const parentDict = new _primitives.Dict();
  1089. parentDict.set("Parent", null);
  1090. parentDict.set("T", "foo");
  1091. widgetDict.set("Parent", parentDict);
  1092. widgetDict.set("T", "bar");
  1093. const widgetRef = _primitives.Ref.get(22, 0);
  1094. const xref = new _test_utils.XRefMock([{
  1095. ref: widgetRef,
  1096. data: widgetDict
  1097. }]);
  1098. _annotation.AnnotationFactory.create(xref, widgetRef, pdfManagerMock, idFactoryMock).then(({
  1099. data
  1100. }) => {
  1101. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1102. expect(data.fieldName).toEqual("foo.bar");
  1103. done();
  1104. }, done.fail);
  1105. });
  1106. });
  1107. describe("TextWidgetAnnotation", function () {
  1108. let textWidgetDict;
  1109. beforeEach(function (done) {
  1110. textWidgetDict = new _primitives.Dict();
  1111. textWidgetDict.set("Type", _primitives.Name.get("Annot"));
  1112. textWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
  1113. textWidgetDict.set("FT", _primitives.Name.get("Tx"));
  1114. done();
  1115. });
  1116. afterEach(function () {
  1117. textWidgetDict = null;
  1118. });
  1119. it("should handle unknown text alignment, maximum length and flags", function (done) {
  1120. const textWidgetRef = _primitives.Ref.get(124, 0);
  1121. const xref = new _test_utils.XRefMock([{
  1122. ref: textWidgetRef,
  1123. data: textWidgetDict
  1124. }]);
  1125. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1126. data
  1127. }) => {
  1128. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1129. expect(data.textAlignment).toEqual(null);
  1130. expect(data.maxLen).toEqual(null);
  1131. expect(data.readOnly).toEqual(false);
  1132. expect(data.multiLine).toEqual(false);
  1133. expect(data.comb).toEqual(false);
  1134. done();
  1135. }, done.fail);
  1136. });
  1137. it("should not set invalid text alignment, maximum length and flags", function (done) {
  1138. textWidgetDict.set("Q", "center");
  1139. textWidgetDict.set("MaxLen", "five");
  1140. textWidgetDict.set("Ff", "readonly");
  1141. const textWidgetRef = _primitives.Ref.get(43, 0);
  1142. const xref = new _test_utils.XRefMock([{
  1143. ref: textWidgetRef,
  1144. data: textWidgetDict
  1145. }]);
  1146. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1147. data
  1148. }) => {
  1149. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1150. expect(data.textAlignment).toEqual(null);
  1151. expect(data.maxLen).toEqual(null);
  1152. expect(data.readOnly).toEqual(false);
  1153. expect(data.multiLine).toEqual(false);
  1154. expect(data.comb).toEqual(false);
  1155. done();
  1156. }, done.fail);
  1157. });
  1158. it("should set valid text alignment, maximum length and flags", function (done) {
  1159. textWidgetDict.set("Q", 1);
  1160. textWidgetDict.set("MaxLen", 20);
  1161. textWidgetDict.set("Ff", _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.MULTILINE);
  1162. const textWidgetRef = _primitives.Ref.get(84, 0);
  1163. const xref = new _test_utils.XRefMock([{
  1164. ref: textWidgetRef,
  1165. data: textWidgetDict
  1166. }]);
  1167. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1168. data
  1169. }) => {
  1170. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1171. expect(data.textAlignment).toEqual(1);
  1172. expect(data.maxLen).toEqual(20);
  1173. expect(data.readOnly).toEqual(true);
  1174. expect(data.multiLine).toEqual(true);
  1175. done();
  1176. }, done.fail);
  1177. });
  1178. it("should reject comb fields without a maximum length", function (done) {
  1179. textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);
  1180. const textWidgetRef = _primitives.Ref.get(46, 0);
  1181. const xref = new _test_utils.XRefMock([{
  1182. ref: textWidgetRef,
  1183. data: textWidgetDict
  1184. }]);
  1185. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1186. data
  1187. }) => {
  1188. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1189. expect(data.comb).toEqual(false);
  1190. done();
  1191. }, done.fail);
  1192. });
  1193. it("should accept comb fields with a maximum length", function (done) {
  1194. textWidgetDict.set("MaxLen", 20);
  1195. textWidgetDict.set("Ff", _util.AnnotationFieldFlag.COMB);
  1196. const textWidgetRef = _primitives.Ref.get(46, 0);
  1197. const xref = new _test_utils.XRefMock([{
  1198. ref: textWidgetRef,
  1199. data: textWidgetDict
  1200. }]);
  1201. _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1202. data
  1203. }) => {
  1204. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1205. expect(data.comb).toEqual(true);
  1206. done();
  1207. }, done.fail);
  1208. });
  1209. it("should only accept comb fields when the flags are valid", function (done) {
  1210. const invalidFieldFlags = [_util.AnnotationFieldFlag.MULTILINE, _util.AnnotationFieldFlag.PASSWORD, _util.AnnotationFieldFlag.FILESELECT];
  1211. let flags = _util.AnnotationFieldFlag.COMB + _util.AnnotationFieldFlag.MULTILINE + _util.AnnotationFieldFlag.PASSWORD + _util.AnnotationFieldFlag.FILESELECT;
  1212. let promise = Promise.resolve();
  1213. for (let i = 0, ii = invalidFieldFlags.length; i <= ii; i++) {
  1214. promise = promise.then(() => {
  1215. textWidgetDict.set("MaxLen", 20);
  1216. textWidgetDict.set("Ff", flags);
  1217. const textWidgetRef = _primitives.Ref.get(93, 0);
  1218. const xref = new _test_utils.XRefMock([{
  1219. ref: textWidgetRef,
  1220. data: textWidgetDict
  1221. }]);
  1222. return _annotation.AnnotationFactory.create(xref, textWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1223. data
  1224. }) => {
  1225. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1226. const valid = invalidFieldFlags.length === 0;
  1227. expect(data.comb).toEqual(valid);
  1228. if (!valid) {
  1229. flags -= invalidFieldFlags.pop();
  1230. }
  1231. });
  1232. });
  1233. }
  1234. promise.then(done, done.fail);
  1235. });
  1236. });
  1237. describe("ButtonWidgetAnnotation", function () {
  1238. let buttonWidgetDict;
  1239. beforeEach(function (done) {
  1240. buttonWidgetDict = new _primitives.Dict();
  1241. buttonWidgetDict.set("Type", _primitives.Name.get("Annot"));
  1242. buttonWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
  1243. buttonWidgetDict.set("FT", _primitives.Name.get("Btn"));
  1244. done();
  1245. });
  1246. afterEach(function () {
  1247. buttonWidgetDict = null;
  1248. });
  1249. it("should handle checkboxes with export value", function (done) {
  1250. buttonWidgetDict.set("V", _primitives.Name.get("1"));
  1251. const appearanceStatesDict = new _primitives.Dict();
  1252. const exportValueOptionsDict = new _primitives.Dict();
  1253. exportValueOptionsDict.set("Off", 0);
  1254. exportValueOptionsDict.set("Checked", 1);
  1255. appearanceStatesDict.set("D", exportValueOptionsDict);
  1256. buttonWidgetDict.set("AP", appearanceStatesDict);
  1257. const buttonWidgetRef = _primitives.Ref.get(124, 0);
  1258. const xref = new _test_utils.XRefMock([{
  1259. ref: buttonWidgetRef,
  1260. data: buttonWidgetDict
  1261. }]);
  1262. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1263. data
  1264. }) => {
  1265. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1266. expect(data.checkBox).toEqual(true);
  1267. expect(data.fieldValue).toEqual("1");
  1268. expect(data.radioButton).toEqual(false);
  1269. expect(data.exportValue).toEqual("Checked");
  1270. done();
  1271. }, done.fail);
  1272. });
  1273. it("should handle checkboxes without export value", function (done) {
  1274. buttonWidgetDict.set("V", _primitives.Name.get("1"));
  1275. const buttonWidgetRef = _primitives.Ref.get(124, 0);
  1276. const xref = new _test_utils.XRefMock([{
  1277. ref: buttonWidgetRef,
  1278. data: buttonWidgetDict
  1279. }]);
  1280. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1281. data
  1282. }) => {
  1283. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1284. expect(data.checkBox).toEqual(true);
  1285. expect(data.fieldValue).toEqual("1");
  1286. expect(data.radioButton).toEqual(false);
  1287. done();
  1288. }, done.fail);
  1289. });
  1290. it("should handle radio buttons with a field value", function (done) {
  1291. const parentDict = new _primitives.Dict();
  1292. parentDict.set("V", _primitives.Name.get("1"));
  1293. const normalAppearanceStateDict = new _primitives.Dict();
  1294. normalAppearanceStateDict.set("2", null);
  1295. const appearanceStatesDict = new _primitives.Dict();
  1296. appearanceStatesDict.set("N", normalAppearanceStateDict);
  1297. buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
  1298. buttonWidgetDict.set("Parent", parentDict);
  1299. buttonWidgetDict.set("AP", appearanceStatesDict);
  1300. const buttonWidgetRef = _primitives.Ref.get(124, 0);
  1301. const xref = new _test_utils.XRefMock([{
  1302. ref: buttonWidgetRef,
  1303. data: buttonWidgetDict
  1304. }]);
  1305. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1306. data
  1307. }) => {
  1308. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1309. expect(data.checkBox).toEqual(false);
  1310. expect(data.radioButton).toEqual(true);
  1311. expect(data.fieldValue).toEqual("1");
  1312. expect(data.buttonValue).toEqual("2");
  1313. done();
  1314. }, done.fail);
  1315. });
  1316. it("should handle radio buttons without a field value", function (done) {
  1317. const normalAppearanceStateDict = new _primitives.Dict();
  1318. normalAppearanceStateDict.set("2", null);
  1319. const appearanceStatesDict = new _primitives.Dict();
  1320. appearanceStatesDict.set("N", normalAppearanceStateDict);
  1321. buttonWidgetDict.set("Ff", _util.AnnotationFieldFlag.RADIO);
  1322. buttonWidgetDict.set("AP", appearanceStatesDict);
  1323. const buttonWidgetRef = _primitives.Ref.get(124, 0);
  1324. const xref = new _test_utils.XRefMock([{
  1325. ref: buttonWidgetRef,
  1326. data: buttonWidgetDict
  1327. }]);
  1328. _annotation.AnnotationFactory.create(xref, buttonWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1329. data
  1330. }) => {
  1331. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1332. expect(data.checkBox).toEqual(false);
  1333. expect(data.radioButton).toEqual(true);
  1334. expect(data.fieldValue).toEqual(null);
  1335. expect(data.buttonValue).toEqual("2");
  1336. done();
  1337. }, done.fail);
  1338. });
  1339. });
  1340. describe("ChoiceWidgetAnnotation", function () {
  1341. let choiceWidgetDict;
  1342. beforeEach(function (done) {
  1343. choiceWidgetDict = new _primitives.Dict();
  1344. choiceWidgetDict.set("Type", _primitives.Name.get("Annot"));
  1345. choiceWidgetDict.set("Subtype", _primitives.Name.get("Widget"));
  1346. choiceWidgetDict.set("FT", _primitives.Name.get("Ch"));
  1347. done();
  1348. });
  1349. afterEach(function () {
  1350. choiceWidgetDict = null;
  1351. });
  1352. it("should handle missing option arrays", function (done) {
  1353. const choiceWidgetRef = _primitives.Ref.get(122, 0);
  1354. const xref = new _test_utils.XRefMock([{
  1355. ref: choiceWidgetRef,
  1356. data: choiceWidgetDict
  1357. }]);
  1358. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1359. data
  1360. }) => {
  1361. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1362. expect(data.options).toEqual([]);
  1363. done();
  1364. }, done.fail);
  1365. });
  1366. it("should handle option arrays with array elements", function (done) {
  1367. const optionBarRef = _primitives.Ref.get(20, 0);
  1368. const optionBarStr = "Bar";
  1369. const optionOneRef = _primitives.Ref.get(10, 0);
  1370. const optionOneArr = ["bar_export", optionBarRef];
  1371. const options = [["foo_export", "Foo"], optionOneRef];
  1372. const expected = [{
  1373. exportValue: "foo_export",
  1374. displayValue: "Foo"
  1375. }, {
  1376. exportValue: "bar_export",
  1377. displayValue: "Bar"
  1378. }];
  1379. choiceWidgetDict.set("Opt", options);
  1380. const choiceWidgetRef = _primitives.Ref.get(123, 0);
  1381. const xref = new _test_utils.XRefMock([{
  1382. ref: choiceWidgetRef,
  1383. data: choiceWidgetDict
  1384. }, {
  1385. ref: optionBarRef,
  1386. data: optionBarStr
  1387. }, {
  1388. ref: optionOneRef,
  1389. data: optionOneArr
  1390. }]);
  1391. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1392. data
  1393. }) => {
  1394. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1395. expect(data.options).toEqual(expected);
  1396. done();
  1397. }, done.fail);
  1398. });
  1399. it("should handle option arrays with string elements", function (done) {
  1400. const optionBarRef = _primitives.Ref.get(10, 0);
  1401. const optionBarStr = "Bar";
  1402. const options = ["Foo", optionBarRef];
  1403. const expected = [{
  1404. exportValue: "Foo",
  1405. displayValue: "Foo"
  1406. }, {
  1407. exportValue: "Bar",
  1408. displayValue: "Bar"
  1409. }];
  1410. choiceWidgetDict.set("Opt", options);
  1411. const choiceWidgetRef = _primitives.Ref.get(981, 0);
  1412. const xref = new _test_utils.XRefMock([{
  1413. ref: choiceWidgetRef,
  1414. data: choiceWidgetDict
  1415. }, {
  1416. ref: optionBarRef,
  1417. data: optionBarStr
  1418. }]);
  1419. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1420. data
  1421. }) => {
  1422. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1423. expect(data.options).toEqual(expected);
  1424. done();
  1425. }, done.fail);
  1426. });
  1427. it("should handle inherited option arrays (issue 8094)", function (done) {
  1428. const options = [["Value1", "Description1"], ["Value2", "Description2"]];
  1429. const expected = [{
  1430. exportValue: "Value1",
  1431. displayValue: "Description1"
  1432. }, {
  1433. exportValue: "Value2",
  1434. displayValue: "Description2"
  1435. }];
  1436. const parentDict = new _primitives.Dict();
  1437. parentDict.set("Opt", options);
  1438. choiceWidgetDict.set("Parent", parentDict);
  1439. const choiceWidgetRef = _primitives.Ref.get(123, 0);
  1440. const xref = new _test_utils.XRefMock([{
  1441. ref: choiceWidgetRef,
  1442. data: choiceWidgetDict
  1443. }]);
  1444. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1445. data
  1446. }) => {
  1447. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1448. expect(data.options).toEqual(expected);
  1449. done();
  1450. }, done.fail);
  1451. });
  1452. it("should sanitize display values in option arrays (issue 8947)", function (done) {
  1453. const options = ["\xFE\xFF\x00F\x00o\x00o"];
  1454. const expected = [{
  1455. exportValue: "\xFE\xFF\x00F\x00o\x00o",
  1456. displayValue: "Foo"
  1457. }];
  1458. choiceWidgetDict.set("Opt", options);
  1459. const choiceWidgetRef = _primitives.Ref.get(984, 0);
  1460. const xref = new _test_utils.XRefMock([{
  1461. ref: choiceWidgetRef,
  1462. data: choiceWidgetDict
  1463. }]);
  1464. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1465. data
  1466. }) => {
  1467. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1468. expect(data.options).toEqual(expected);
  1469. done();
  1470. }, done.fail);
  1471. });
  1472. it("should handle array field values", function (done) {
  1473. const fieldValue = ["Foo", "Bar"];
  1474. choiceWidgetDict.set("V", fieldValue);
  1475. const choiceWidgetRef = _primitives.Ref.get(968, 0);
  1476. const xref = new _test_utils.XRefMock([{
  1477. ref: choiceWidgetRef,
  1478. data: choiceWidgetDict
  1479. }]);
  1480. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1481. data
  1482. }) => {
  1483. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1484. expect(data.fieldValue).toEqual(fieldValue);
  1485. done();
  1486. }, done.fail);
  1487. });
  1488. it("should handle string field values", function (done) {
  1489. const fieldValue = "Foo";
  1490. choiceWidgetDict.set("V", fieldValue);
  1491. const choiceWidgetRef = _primitives.Ref.get(978, 0);
  1492. const xref = new _test_utils.XRefMock([{
  1493. ref: choiceWidgetRef,
  1494. data: choiceWidgetDict
  1495. }]);
  1496. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1497. data
  1498. }) => {
  1499. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1500. expect(data.fieldValue).toEqual([fieldValue]);
  1501. done();
  1502. }, done.fail);
  1503. });
  1504. it("should handle unknown flags", function (done) {
  1505. const choiceWidgetRef = _primitives.Ref.get(166, 0);
  1506. const xref = new _test_utils.XRefMock([{
  1507. ref: choiceWidgetRef,
  1508. data: choiceWidgetDict
  1509. }]);
  1510. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1511. data
  1512. }) => {
  1513. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1514. expect(data.readOnly).toEqual(false);
  1515. expect(data.combo).toEqual(false);
  1516. expect(data.multiSelect).toEqual(false);
  1517. done();
  1518. }, done.fail);
  1519. });
  1520. it("should not set invalid flags", function (done) {
  1521. choiceWidgetDict.set("Ff", "readonly");
  1522. const choiceWidgetRef = _primitives.Ref.get(165, 0);
  1523. const xref = new _test_utils.XRefMock([{
  1524. ref: choiceWidgetRef,
  1525. data: choiceWidgetDict
  1526. }]);
  1527. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1528. data
  1529. }) => {
  1530. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1531. expect(data.readOnly).toEqual(false);
  1532. expect(data.combo).toEqual(false);
  1533. expect(data.multiSelect).toEqual(false);
  1534. done();
  1535. }, done.fail);
  1536. });
  1537. it("should set valid flags", function (done) {
  1538. choiceWidgetDict.set("Ff", _util.AnnotationFieldFlag.READONLY + _util.AnnotationFieldFlag.COMBO + _util.AnnotationFieldFlag.MULTISELECT);
  1539. const choiceWidgetRef = _primitives.Ref.get(512, 0);
  1540. const xref = new _test_utils.XRefMock([{
  1541. ref: choiceWidgetRef,
  1542. data: choiceWidgetDict
  1543. }]);
  1544. _annotation.AnnotationFactory.create(xref, choiceWidgetRef, pdfManagerMock, idFactoryMock).then(({
  1545. data
  1546. }) => {
  1547. expect(data.annotationType).toEqual(_util.AnnotationType.WIDGET);
  1548. expect(data.readOnly).toEqual(true);
  1549. expect(data.combo).toEqual(true);
  1550. expect(data.multiSelect).toEqual(true);
  1551. done();
  1552. }, done.fail);
  1553. });
  1554. });
  1555. describe("LineAnnotation", function () {
  1556. it("should set the line coordinates", function (done) {
  1557. const lineDict = new _primitives.Dict();
  1558. lineDict.set("Type", _primitives.Name.get("Annot"));
  1559. lineDict.set("Subtype", _primitives.Name.get("Line"));
  1560. lineDict.set("L", [1, 2, 3, 4]);
  1561. const lineRef = _primitives.Ref.get(122, 0);
  1562. const xref = new _test_utils.XRefMock([{
  1563. ref: lineRef,
  1564. data: lineDict
  1565. }]);
  1566. _annotation.AnnotationFactory.create(xref, lineRef, pdfManagerMock, idFactoryMock).then(({
  1567. data
  1568. }) => {
  1569. expect(data.annotationType).toEqual(_util.AnnotationType.LINE);
  1570. expect(data.lineCoordinates).toEqual([1, 2, 3, 4]);
  1571. done();
  1572. }, done.fail);
  1573. });
  1574. });
  1575. describe("FileAttachmentAnnotation", function () {
  1576. it("should correctly parse a file attachment", function (done) {
  1577. const fileStream = new _stream.StringStream("<<\n" + "/Type /EmbeddedFile\n" + "/Subtype /text#2Fplain\n" + ">>\n" + "stream\n" + "Test attachment" + "endstream\n");
  1578. const parser = new _parser.Parser({
  1579. lexer: new _parser.Lexer(fileStream),
  1580. xref: null,
  1581. allowStreams: true
  1582. });
  1583. const fileStreamRef = _primitives.Ref.get(18, 0);
  1584. const fileStreamDict = parser.getObj();
  1585. const embeddedFileDict = new _primitives.Dict();
  1586. embeddedFileDict.set("F", fileStreamRef);
  1587. const fileSpecRef = _primitives.Ref.get(19, 0);
  1588. const fileSpecDict = new _primitives.Dict();
  1589. fileSpecDict.set("Type", _primitives.Name.get("Filespec"));
  1590. fileSpecDict.set("Desc", "");
  1591. fileSpecDict.set("EF", embeddedFileDict);
  1592. fileSpecDict.set("UF", "Test.txt");
  1593. const fileAttachmentRef = _primitives.Ref.get(20, 0);
  1594. const fileAttachmentDict = new _primitives.Dict();
  1595. fileAttachmentDict.set("Type", _primitives.Name.get("Annot"));
  1596. fileAttachmentDict.set("Subtype", _primitives.Name.get("FileAttachment"));
  1597. fileAttachmentDict.set("FS", fileSpecRef);
  1598. fileAttachmentDict.set("T", "Topic");
  1599. fileAttachmentDict.set("Contents", "Test.txt");
  1600. const xref = new _test_utils.XRefMock([{
  1601. ref: fileStreamRef,
  1602. data: fileStreamDict
  1603. }, {
  1604. ref: fileSpecRef,
  1605. data: fileSpecDict
  1606. }, {
  1607. ref: fileAttachmentRef,
  1608. data: fileAttachmentDict
  1609. }]);
  1610. embeddedFileDict.assignXref(xref);
  1611. fileSpecDict.assignXref(xref);
  1612. fileAttachmentDict.assignXref(xref);
  1613. _annotation.AnnotationFactory.create(xref, fileAttachmentRef, pdfManagerMock, idFactoryMock).then(({
  1614. data
  1615. }) => {
  1616. expect(data.annotationType).toEqual(_util.AnnotationType.FILEATTACHMENT);
  1617. expect(data.file.filename).toEqual("Test.txt");
  1618. expect(data.file.content).toEqual((0, _util.stringToBytes)("Test attachment"));
  1619. done();
  1620. }, done.fail);
  1621. });
  1622. });
  1623. describe("PopupAnnotation", function () {
  1624. it("should inherit properties from its parent", function (done) {
  1625. const parentDict = new _primitives.Dict();
  1626. parentDict.set("Type", _primitives.Name.get("Annot"));
  1627. parentDict.set("Subtype", _primitives.Name.get("Text"));
  1628. parentDict.set("M", "D:20190423");
  1629. parentDict.set("C", [0, 0, 1]);
  1630. const popupDict = new _primitives.Dict();
  1631. popupDict.set("Type", _primitives.Name.get("Annot"));
  1632. popupDict.set("Subtype", _primitives.Name.get("Popup"));
  1633. popupDict.set("Parent", parentDict);
  1634. const popupRef = _primitives.Ref.get(13, 0);
  1635. const xref = new _test_utils.XRefMock([{
  1636. ref: popupRef,
  1637. data: popupDict
  1638. }]);
  1639. _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
  1640. data,
  1641. viewable
  1642. }) => {
  1643. expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
  1644. expect(data.modificationDate).toEqual("D:20190423");
  1645. expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
  1646. done();
  1647. }, done.fail);
  1648. });
  1649. it("should handle missing parent properties", function (done) {
  1650. const parentDict = new _primitives.Dict();
  1651. parentDict.set("Type", _primitives.Name.get("Annot"));
  1652. parentDict.set("Subtype", _primitives.Name.get("Text"));
  1653. const popupDict = new _primitives.Dict();
  1654. popupDict.set("Type", _primitives.Name.get("Annot"));
  1655. popupDict.set("Subtype", _primitives.Name.get("Popup"));
  1656. popupDict.set("Parent", parentDict);
  1657. const popupRef = _primitives.Ref.get(13, 0);
  1658. const xref = new _test_utils.XRefMock([{
  1659. ref: popupRef,
  1660. data: popupDict
  1661. }]);
  1662. _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
  1663. data,
  1664. viewable
  1665. }) => {
  1666. expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
  1667. expect(data.modificationDate).toEqual(null);
  1668. expect(data.color).toEqual(null);
  1669. done();
  1670. }, done.fail);
  1671. });
  1672. it("should inherit the parent flags when the Popup is not viewable, " + "but the parent is (PR 7352)", function (done) {
  1673. const parentDict = new _primitives.Dict();
  1674. parentDict.set("Type", _primitives.Name.get("Annot"));
  1675. parentDict.set("Subtype", _primitives.Name.get("Text"));
  1676. parentDict.set("F", 28);
  1677. const popupDict = new _primitives.Dict();
  1678. popupDict.set("Type", _primitives.Name.get("Annot"));
  1679. popupDict.set("Subtype", _primitives.Name.get("Popup"));
  1680. popupDict.set("F", 25);
  1681. popupDict.set("Parent", parentDict);
  1682. const popupRef = _primitives.Ref.get(13, 0);
  1683. const xref = new _test_utils.XRefMock([{
  1684. ref: popupRef,
  1685. data: popupDict
  1686. }]);
  1687. _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
  1688. data,
  1689. viewable
  1690. }) => {
  1691. expect(data.annotationType).toEqual(_util.AnnotationType.POPUP);
  1692. expect(data.annotationFlags).toEqual(25);
  1693. expect(viewable).toEqual(true);
  1694. done();
  1695. }, done.fail);
  1696. });
  1697. it("should correctly inherit Contents from group-master annotation " + "if parent has ReplyType == Group", function (done) {
  1698. const annotationRef = _primitives.Ref.get(819, 0);
  1699. const annotationDict = new _primitives.Dict();
  1700. annotationDict.set("Type", _primitives.Name.get("Annot"));
  1701. annotationDict.set("Subtype", _primitives.Name.get("Text"));
  1702. annotationDict.set("T", "Correct Title");
  1703. annotationDict.set("Contents", "Correct Text");
  1704. annotationDict.set("M", "D:20190423");
  1705. annotationDict.set("C", [0, 0, 1]);
  1706. const replyRef = _primitives.Ref.get(820, 0);
  1707. const replyDict = new _primitives.Dict();
  1708. replyDict.set("Type", _primitives.Name.get("Annot"));
  1709. replyDict.set("Subtype", _primitives.Name.get("Text"));
  1710. replyDict.set("IRT", annotationRef);
  1711. replyDict.set("RT", _primitives.Name.get("Group"));
  1712. replyDict.set("T", "Reply Title");
  1713. replyDict.set("Contents", "Reply Text");
  1714. replyDict.set("M", "D:20190523");
  1715. replyDict.set("C", [0.4]);
  1716. const popupRef = _primitives.Ref.get(821, 0);
  1717. const popupDict = new _primitives.Dict();
  1718. popupDict.set("Type", _primitives.Name.get("Annot"));
  1719. popupDict.set("Subtype", _primitives.Name.get("Popup"));
  1720. popupDict.set("T", "Wrong Title");
  1721. popupDict.set("Contents", "Wrong Text");
  1722. popupDict.set("Parent", replyRef);
  1723. popupDict.set("M", "D:20190623");
  1724. popupDict.set("C", [0.8]);
  1725. replyDict.set("Popup", popupRef);
  1726. const xref = new _test_utils.XRefMock([{
  1727. ref: annotationRef,
  1728. data: annotationDict
  1729. }, {
  1730. ref: replyRef,
  1731. data: replyDict
  1732. }, {
  1733. ref: popupRef,
  1734. data: popupDict
  1735. }]);
  1736. annotationDict.assignXref(xref);
  1737. popupDict.assignXref(xref);
  1738. replyDict.assignXref(xref);
  1739. _annotation.AnnotationFactory.create(xref, popupRef, pdfManagerMock, idFactoryMock).then(({
  1740. data
  1741. }) => {
  1742. expect(data.title).toEqual("Correct Title");
  1743. expect(data.contents).toEqual("Correct Text");
  1744. expect(data.modificationDate).toEqual("D:20190423");
  1745. expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
  1746. done();
  1747. }, done.fail);
  1748. });
  1749. });
  1750. describe("InkAnnotation", function () {
  1751. it("should handle a single ink list", function (done) {
  1752. const inkDict = new _primitives.Dict();
  1753. inkDict.set("Type", _primitives.Name.get("Annot"));
  1754. inkDict.set("Subtype", _primitives.Name.get("Ink"));
  1755. inkDict.set("InkList", [[1, 1, 1, 2, 2, 2, 3, 3]]);
  1756. const inkRef = _primitives.Ref.get(142, 0);
  1757. const xref = new _test_utils.XRefMock([{
  1758. ref: inkRef,
  1759. data: inkDict
  1760. }]);
  1761. _annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(({
  1762. data
  1763. }) => {
  1764. expect(data.annotationType).toEqual(_util.AnnotationType.INK);
  1765. expect(data.inkLists.length).toEqual(1);
  1766. expect(data.inkLists[0]).toEqual([{
  1767. x: 1,
  1768. y: 1
  1769. }, {
  1770. x: 1,
  1771. y: 2
  1772. }, {
  1773. x: 2,
  1774. y: 2
  1775. }, {
  1776. x: 3,
  1777. y: 3
  1778. }]);
  1779. done();
  1780. }, done.fail);
  1781. });
  1782. it("should handle multiple ink lists", function (done) {
  1783. const inkDict = new _primitives.Dict();
  1784. inkDict.set("Type", _primitives.Name.get("Annot"));
  1785. inkDict.set("Subtype", _primitives.Name.get("Ink"));
  1786. inkDict.set("InkList", [[1, 1, 1, 2], [3, 3, 4, 5]]);
  1787. const inkRef = _primitives.Ref.get(143, 0);
  1788. const xref = new _test_utils.XRefMock([{
  1789. ref: inkRef,
  1790. data: inkDict
  1791. }]);
  1792. _annotation.AnnotationFactory.create(xref, inkRef, pdfManagerMock, idFactoryMock).then(({
  1793. data
  1794. }) => {
  1795. expect(data.annotationType).toEqual(_util.AnnotationType.INK);
  1796. expect(data.inkLists.length).toEqual(2);
  1797. expect(data.inkLists[0]).toEqual([{
  1798. x: 1,
  1799. y: 1
  1800. }, {
  1801. x: 1,
  1802. y: 2
  1803. }]);
  1804. expect(data.inkLists[1]).toEqual([{
  1805. x: 3,
  1806. y: 3
  1807. }, {
  1808. x: 4,
  1809. y: 5
  1810. }]);
  1811. done();
  1812. }, done.fail);
  1813. });
  1814. });
  1815. describe("HightlightAnnotation", function () {
  1816. it("should not set quadpoints if not defined", function (done) {
  1817. const highlightDict = new _primitives.Dict();
  1818. highlightDict.set("Type", _primitives.Name.get("Annot"));
  1819. highlightDict.set("Subtype", _primitives.Name.get("Highlight"));
  1820. const highlightRef = _primitives.Ref.get(121, 0);
  1821. const xref = new _test_utils.XRefMock([{
  1822. ref: highlightRef,
  1823. data: highlightDict
  1824. }]);
  1825. _annotation.AnnotationFactory.create(xref, highlightRef, pdfManagerMock, idFactoryMock).then(({
  1826. data
  1827. }) => {
  1828. expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);
  1829. expect(data.quadPoints).toBeUndefined();
  1830. done();
  1831. }, done.fail);
  1832. });
  1833. it("should set quadpoints if defined", function (done) {
  1834. const highlightDict = new _primitives.Dict();
  1835. highlightDict.set("Type", _primitives.Name.get("Annot"));
  1836. highlightDict.set("Subtype", _primitives.Name.get("Highlight"));
  1837. highlightDict.set("Rect", [10, 10, 20, 20]);
  1838. highlightDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
  1839. const highlightRef = _primitives.Ref.get(121, 0);
  1840. const xref = new _test_utils.XRefMock([{
  1841. ref: highlightRef,
  1842. data: highlightDict
  1843. }]);
  1844. _annotation.AnnotationFactory.create(xref, highlightRef, pdfManagerMock, idFactoryMock).then(({
  1845. data
  1846. }) => {
  1847. expect(data.annotationType).toEqual(_util.AnnotationType.HIGHLIGHT);
  1848. expect(data.quadPoints).toEqual([[{
  1849. x: 11,
  1850. y: 11
  1851. }, {
  1852. x: 12,
  1853. y: 12
  1854. }, {
  1855. x: 13,
  1856. y: 13
  1857. }, {
  1858. x: 14,
  1859. y: 14
  1860. }]]);
  1861. done();
  1862. }, done.fail);
  1863. });
  1864. });
  1865. describe("UnderlineAnnotation", function () {
  1866. it("should not set quadpoints if not defined", function (done) {
  1867. const underlineDict = new _primitives.Dict();
  1868. underlineDict.set("Type", _primitives.Name.get("Annot"));
  1869. underlineDict.set("Subtype", _primitives.Name.get("Underline"));
  1870. const underlineRef = _primitives.Ref.get(121, 0);
  1871. const xref = new _test_utils.XRefMock([{
  1872. ref: underlineRef,
  1873. data: underlineDict
  1874. }]);
  1875. _annotation.AnnotationFactory.create(xref, underlineRef, pdfManagerMock, idFactoryMock).then(({
  1876. data
  1877. }) => {
  1878. expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);
  1879. expect(data.quadPoints).toBeUndefined();
  1880. done();
  1881. }, done.fail);
  1882. });
  1883. it("should set quadpoints if defined", function (done) {
  1884. const underlineDict = new _primitives.Dict();
  1885. underlineDict.set("Type", _primitives.Name.get("Annot"));
  1886. underlineDict.set("Subtype", _primitives.Name.get("Underline"));
  1887. underlineDict.set("Rect", [10, 10, 20, 20]);
  1888. underlineDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
  1889. const underlineRef = _primitives.Ref.get(121, 0);
  1890. const xref = new _test_utils.XRefMock([{
  1891. ref: underlineRef,
  1892. data: underlineDict
  1893. }]);
  1894. _annotation.AnnotationFactory.create(xref, underlineRef, pdfManagerMock, idFactoryMock).then(({
  1895. data
  1896. }) => {
  1897. expect(data.annotationType).toEqual(_util.AnnotationType.UNDERLINE);
  1898. expect(data.quadPoints).toEqual([[{
  1899. x: 11,
  1900. y: 11
  1901. }, {
  1902. x: 12,
  1903. y: 12
  1904. }, {
  1905. x: 13,
  1906. y: 13
  1907. }, {
  1908. x: 14,
  1909. y: 14
  1910. }]]);
  1911. done();
  1912. }, done.fail);
  1913. });
  1914. });
  1915. describe("SquigglyAnnotation", function () {
  1916. it("should not set quadpoints if not defined", function (done) {
  1917. const squigglyDict = new _primitives.Dict();
  1918. squigglyDict.set("Type", _primitives.Name.get("Annot"));
  1919. squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));
  1920. const squigglyRef = _primitives.Ref.get(121, 0);
  1921. const xref = new _test_utils.XRefMock([{
  1922. ref: squigglyRef,
  1923. data: squigglyDict
  1924. }]);
  1925. _annotation.AnnotationFactory.create(xref, squigglyRef, pdfManagerMock, idFactoryMock).then(({
  1926. data
  1927. }) => {
  1928. expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);
  1929. expect(data.quadPoints).toBeUndefined();
  1930. done();
  1931. }, done.fail);
  1932. });
  1933. it("should set quadpoints if defined", function (done) {
  1934. const squigglyDict = new _primitives.Dict();
  1935. squigglyDict.set("Type", _primitives.Name.get("Annot"));
  1936. squigglyDict.set("Subtype", _primitives.Name.get("Squiggly"));
  1937. squigglyDict.set("Rect", [10, 10, 20, 20]);
  1938. squigglyDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
  1939. const squigglyRef = _primitives.Ref.get(121, 0);
  1940. const xref = new _test_utils.XRefMock([{
  1941. ref: squigglyRef,
  1942. data: squigglyDict
  1943. }]);
  1944. _annotation.AnnotationFactory.create(xref, squigglyRef, pdfManagerMock, idFactoryMock).then(({
  1945. data
  1946. }) => {
  1947. expect(data.annotationType).toEqual(_util.AnnotationType.SQUIGGLY);
  1948. expect(data.quadPoints).toEqual([[{
  1949. x: 11,
  1950. y: 11
  1951. }, {
  1952. x: 12,
  1953. y: 12
  1954. }, {
  1955. x: 13,
  1956. y: 13
  1957. }, {
  1958. x: 14,
  1959. y: 14
  1960. }]]);
  1961. done();
  1962. }, done.fail);
  1963. });
  1964. });
  1965. describe("StrikeOutAnnotation", function () {
  1966. it("should not set quadpoints if not defined", function (done) {
  1967. const strikeOutDict = new _primitives.Dict();
  1968. strikeOutDict.set("Type", _primitives.Name.get("Annot"));
  1969. strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));
  1970. const strikeOutRef = _primitives.Ref.get(121, 0);
  1971. const xref = new _test_utils.XRefMock([{
  1972. ref: strikeOutRef,
  1973. data: strikeOutDict
  1974. }]);
  1975. _annotation.AnnotationFactory.create(xref, strikeOutRef, pdfManagerMock, idFactoryMock).then(({
  1976. data
  1977. }) => {
  1978. expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);
  1979. expect(data.quadPoints).toBeUndefined();
  1980. done();
  1981. }, done.fail);
  1982. });
  1983. it("should set quadpoints if defined", function (done) {
  1984. const strikeOutDict = new _primitives.Dict();
  1985. strikeOutDict.set("Type", _primitives.Name.get("Annot"));
  1986. strikeOutDict.set("Subtype", _primitives.Name.get("StrikeOut"));
  1987. strikeOutDict.set("Rect", [10, 10, 20, 20]);
  1988. strikeOutDict.set("QuadPoints", [11, 11, 12, 12, 13, 13, 14, 14]);
  1989. const strikeOutRef = _primitives.Ref.get(121, 0);
  1990. const xref = new _test_utils.XRefMock([{
  1991. ref: strikeOutRef,
  1992. data: strikeOutDict
  1993. }]);
  1994. _annotation.AnnotationFactory.create(xref, strikeOutRef, pdfManagerMock, idFactoryMock).then(({
  1995. data
  1996. }) => {
  1997. expect(data.annotationType).toEqual(_util.AnnotationType.STRIKEOUT);
  1998. expect(data.quadPoints).toEqual([[{
  1999. x: 11,
  2000. y: 11
  2001. }, {
  2002. x: 12,
  2003. y: 12
  2004. }, {
  2005. x: 13,
  2006. y: 13
  2007. }, {
  2008. x: 14,
  2009. y: 14
  2010. }]]);
  2011. done();
  2012. }, done.fail);
  2013. });
  2014. });
  2015. });