2
0

annotation_spec.js 82 KB

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