index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. const RenderingStates = {
  2. INITIAL: 0,
  3. RUNNING: 1,
  4. PAUSED: 2,
  5. FINISHED: 3
  6. }
  7. const ALIGN = {
  8. 0: 'left',
  9. 1: 'center',
  10. 2: 'right'
  11. }
  12. const ALIGNMAP = {
  13. left: 0,
  14. center: 1,
  15. right: 2
  16. }
  17. const MARGIN_DISTANCE = 10
  18. const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  19. const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  20. // Represent the percentage of the height of a single-line field over
  21. // the font size. Acrobat seems to use this value.
  22. const LINE_FACTOR = 1.35;
  23. const LINE_DESCENT_FACTOR = 0.35;
  24. const MARKUP = ['highlight', 'underline', 'squiggly', 'strikeout']
  25. /**
  26. * Refer to the `WorkerTransport.getRenderingIntent`-method in the API, to see
  27. * how these flags are being used:
  28. * - ANY, DISPLAY, and PRINT are the normal rendering intents, note the
  29. * `PDFPageProxy.{render, getOperatorList, getAnnotations}`-methods.
  30. * - ANNOTATIONS_FORMS, ANNOTATIONS_STORAGE, ANNOTATIONS_DISABLE control which
  31. * annotations are rendered onto the canvas (i.e. by being included in the
  32. * operatorList), note the `PDFPageProxy.{render, getOperatorList}`-methods
  33. * and their `annotationMode`-option.
  34. * - OPLIST is used with the `PDFPageProxy.getOperatorList`-method, note the
  35. * `OperatorList`-constructor (on the worker-thread).
  36. */
  37. const RenderingIntentFlag = {
  38. ANY: 0x01,
  39. DISPLAY: 0x02,
  40. PRINT: 0x04,
  41. ANNOTATIONS_FORMS: 0x10,
  42. ANNOTATIONS_STORAGE: 0x20,
  43. ANNOTATIONS_DISABLE: 0x40,
  44. OPLIST: 0x100,
  45. };
  46. const AnnotationEditorPrefix = "pdfjs_internal_editor_";
  47. const AnnotationEditorType = {
  48. DISABLE: -1,
  49. NONE: 0,
  50. FREETEXT: 3,
  51. INK: 15,
  52. };
  53. const AnnotationEditorParamsType = {
  54. FREETEXT_SIZE: 1,
  55. FREETEXT_COLOR: 2,
  56. FREETEXT_OPACITY: 3,
  57. INK_COLOR: 11,
  58. INK_THICKNESS: 12,
  59. INK_OPACITY: 13,
  60. };
  61. // Permission flags from Table 22, Section 7.6.3.2 of the PDF specification.
  62. const PermissionFlag = {
  63. PRINT: 0x04,
  64. MODIFY_CONTENTS: 0x08,
  65. COPY: 0x10,
  66. MODIFY_ANNOTATIONS: 0x20,
  67. FILL_INTERACTIVE_FORMS: 0x100,
  68. COPY_FOR_ACCESSIBILITY: 0x200,
  69. ASSEMBLE: 0x400,
  70. PRINT_HIGH_QUALITY: 0x800,
  71. };
  72. const TextRenderingMode = {
  73. FILL: 0,
  74. STROKE: 1,
  75. FILL_STROKE: 2,
  76. INVISIBLE: 3,
  77. FILL_ADD_TO_PATH: 4,
  78. STROKE_ADD_TO_PATH: 5,
  79. FILL_STROKE_ADD_TO_PATH: 6,
  80. ADD_TO_PATH: 7,
  81. FILL_STROKE_MASK: 3,
  82. ADD_TO_PATH_FLAG: 4,
  83. };
  84. const ImageKind = {
  85. GRAYSCALE_1BPP: 1,
  86. RGB_24BPP: 2,
  87. RGBA_32BPP: 3,
  88. };
  89. const AnnotationType = {
  90. TEXT: 1,
  91. LINK: 2,
  92. FREETEXT: 3,
  93. LINE: 4,
  94. SQUARE: 5,
  95. CIRCLE: 6,
  96. POLYGON: 7,
  97. POLYLINE: 8,
  98. HIGHLIGHT: 9,
  99. UNDERLINE: 10,
  100. SQUIGGLY: 11,
  101. STRIKEOUT: 12,
  102. STAMP: 13,
  103. CARET: 14,
  104. INK: 15,
  105. POPUP: 16,
  106. FILEATTACHMENT: 17,
  107. SOUND: 18,
  108. MOVIE: 19,
  109. WIDGET: 20,
  110. SCREEN: 21,
  111. PRINTERMARK: 22,
  112. TRAPNET: 23,
  113. WATERMARK: 24,
  114. THREED: 25,
  115. REDACT: 26,
  116. };
  117. const AnnotationTypeString = {
  118. 1: 'text',
  119. 2: 'link',
  120. 3: 'freetext',
  121. 4: 'line',
  122. 5: 'square',
  123. 6: 'circle',
  124. 7: 'polygon',
  125. 8: 'polyline',
  126. 9: 'highlight',
  127. 10: 'underline',
  128. 11: 'squiggly',
  129. 12: 'strikeout',
  130. 13: 'stamp',
  131. 14: 'caret',
  132. 15: 'ink',
  133. 16: 'popup',
  134. 17: 'fileattachment',
  135. 18: 'sound',
  136. 19: 'movie',
  137. 20: 'widget',
  138. 21: 'screen',
  139. 22: 'printermark',
  140. 23: 'trapnet',
  141. 24: 'watermark',
  142. 25: 'threed',
  143. 26: 'redact',
  144. };
  145. const WidgetType = {
  146. PUSHBUTTON: 0,
  147. CHECKBOX: 1,
  148. RADIOBUTTON: 2,
  149. TEXTFIELD: 3,
  150. COMBOBOX: 4,
  151. LISTBOX: 5,
  152. SIGNATUREFIELDS: 6,
  153. UNKNOWN: 0XFF
  154. }
  155. const WidgetTypeString = {
  156. 0: 'pushbutton',
  157. 1: 'checkbox',
  158. 2: 'radiobutton',
  159. 3: 'textfield',
  160. 4: 'combobox',
  161. 5: 'listbox',
  162. 6: 'signaturefields',
  163. 0xff: 'unknown',
  164. }
  165. const TextFiledSpecial = {
  166. normal: 0,
  167. date: 1
  168. }
  169. const TextFiledSpecialString = {
  170. 0: 'normal',
  171. 1: 'date'
  172. }
  173. const AnnotationFlags = {
  174. AnnotationFlagInvisible: 1, // 1
  175. AnnotationFlagHidden: 1 << 1, // 10 2
  176. AnnotationFlagPrint: 1 << 2, // 100 4
  177. AnnotationFlagNoZoom: 1 << 3, // 1000 8
  178. AnnotationFlagNoRotate: 1 << 4, // 10000 16
  179. AnnotationFlagNoView: 1 << 5, // 100000 32
  180. AnnotationFlagReadOnly: 1 << 6, // 1000000 64
  181. AnnotationFlagLocked: 1 << 7, // 10000000 128
  182. AnnotationFlagToggleNoView: 1 << 8, // 100000000 256
  183. AnnotationFlagLockedContents: 1 << 9, // 1000000000 512
  184. };
  185. const LineType = {
  186. UNKNOWN: -1,
  187. NONE: 0,
  188. OPENARROW: 1,
  189. CLOSEDARROW: 2,
  190. SQUARE: 3,
  191. CIRCLE: 4,
  192. DIAMOND: 5,
  193. BUTT: 6,
  194. ROPENARROW: 7,
  195. RCLOSEDARROW: 8,
  196. SLASH: 9,
  197. }
  198. const LineTypeString = {
  199. '-1': 'Unknown',
  200. 0: 'None',
  201. 1: 'OpenArrow',
  202. 2: 'closedarrow',
  203. 3: 'square',
  204. 4: 'circle',
  205. 5: 'diamond',
  206. 6: 'butt',
  207. 7: 'ropenarrow',
  208. 8: 'rclosedarrow',
  209. 9: 'slash',
  210. }
  211. const CheckStyle = {
  212. none: -1,
  213. check: 0,
  214. circle: 1,
  215. cross: 2,
  216. diamond: 3,
  217. square: 4,
  218. star: 5,
  219. }
  220. const CheckStyleString = {
  221. 1: 'none',
  222. 0: 'check',
  223. 1: 'circle',
  224. 2: 'cross',
  225. 3: 'diamond',
  226. 4: 'square',
  227. 5: 'star',
  228. }
  229. const StampType = {
  230. UNKNOWN: 0,
  231. STANDARD: 1,
  232. IMAGE: 2,
  233. TEXT: 3,
  234. DIGITAL: 4,
  235. }
  236. const StampTypeString = {
  237. 0: 'unknown',
  238. 1: 'standard',
  239. 2: 'image',
  240. 3: 'text',
  241. 4: 'digital',
  242. }
  243. const TextStampColor = {
  244. white: 0,
  245. red: 1,
  246. green: 2,
  247. blu: 3,
  248. }
  249. const TextStampColorString = {
  250. 0: 'white',
  251. 1: 'red',
  252. 2: 'green',
  253. 3: 'blu',
  254. }
  255. const ActionType = {
  256. Unknown: 0,
  257. GoTo: 1,
  258. GoToR: 2,
  259. GoToE: 3,
  260. Launch: 4,
  261. Thread: 5,
  262. URI: 6,
  263. Sound: 7,
  264. Movie: 8,
  265. Hide: 9,
  266. Named: 10,
  267. SubmitForm: 11,
  268. ResetForm: 12,
  269. ImportData: 13,
  270. JavaScript: 14,
  271. SetOCGState: 15,
  272. Rendition: 16,
  273. Trans: 17,
  274. GoTo3DView: 18,
  275. UOP: 19, //unlock uop
  276. Error: 0xff
  277. }
  278. const ActionTypeString = {
  279. 0: 'unknown',
  280. 1: 'goto',
  281. 2: 'gotor',
  282. 3: 'gotoe',
  283. 4: 'launch',
  284. 5: 'thread',
  285. 6: 'uri',
  286. 7: 'sound',
  287. 8: 'movie',
  288. 9: 'hide',
  289. 10: 'named',
  290. 11: 'submitform',
  291. 12: 'resetform',
  292. 13: 'importdata',
  293. 14: 'javascript',
  294. 15: 'setocgstate',
  295. 16: 'rendition',
  296. 17: 'trans',
  297. 18: 'goto3dview',
  298. 19: 'uop',
  299. 0xff: 'error',
  300. }
  301. const BorderStyleInt = {
  302. solid: 0,
  303. dashded: 1,
  304. beveled: 2,
  305. inset: 3,
  306. underline: 4,
  307. }
  308. const BorderStyleString = {
  309. 0: 'solid',
  310. 1: 'dashded',
  311. 2: 'beveled',
  312. 3: 'inset',
  313. 4: 'underline',
  314. }
  315. const TextStampShape = {
  316. rect: 0,
  317. leftTriangle: 1,
  318. rightTriangle: 2,
  319. none: 3,
  320. }
  321. const TextStampShapeString = {
  322. 0: 'rect',
  323. 1: 'leftTriangle',
  324. 2: 'rightTriangle',
  325. 3: 'none',
  326. }
  327. const AnnotationStateModelType = {
  328. MARKED: "Marked",
  329. REVIEW: "Review",
  330. };
  331. const AnnotationMarkedState = {
  332. MARKED: "Marked",
  333. UNMARKED: "Unmarked",
  334. };
  335. const AnnotationReviewState = {
  336. ACCEPTED: "Accepted",
  337. REJECTED: "Rejected",
  338. CANCELLED: "Cancelled",
  339. COMPLETED: "Completed",
  340. NONE: "None",
  341. };
  342. const AnnotationReplyType = {
  343. GROUP: "Group",
  344. REPLY: "R",
  345. };
  346. const AnnotationFlag = {
  347. INVISIBLE: 0x01,
  348. HIDDEN: 0x02,
  349. PRINT: 0x04,
  350. NOZOOM: 0x08,
  351. NOROTATE: 0x10,
  352. NOVIEW: 0x20,
  353. READONLY: 0x40,
  354. LOCKED: 0x80,
  355. TOGGLENOVIEW: 0x100,
  356. LOCKEDCONTENTS: 0x200,
  357. };
  358. const AnnotationFieldFlag = {
  359. READONLY: 0x0000001,
  360. REQUIRED: 0x0000002,
  361. NOEXPORT: 0x0000004,
  362. MULTILINE: 0x0001000,
  363. PASSWORD: 0x0002000,
  364. NOTOGGLETOOFF: 0x0004000,
  365. RADIO: 0x0008000,
  366. PUSHBUTTON: 0x0010000,
  367. COMBO: 0x0020000,
  368. EDIT: 0x0040000,
  369. SORT: 0x0080000,
  370. FILESELECT: 0x0100000,
  371. MULTISELECT: 0x0200000,
  372. DONOTSPELLCHECK: 0x0400000,
  373. DONOTSCROLL: 0x0800000,
  374. COMB: 0x1000000,
  375. RICHTEXT: 0x2000000,
  376. RADIOSINUNISON: 0x2000000,
  377. COMMITONSELCHANGE: 0x4000000,
  378. };
  379. const AnnotationBorderStyleType = {
  380. SOLID: 1,
  381. DASHED: 2,
  382. BEVELED: 3,
  383. INSET: 4,
  384. UNDERLINE: 5,
  385. };
  386. const AnnotationActionEventType = {
  387. E: "Mouse Enter",
  388. X: "Mouse Exit",
  389. D: "Mouse Down",
  390. U: "Mouse Up",
  391. Fo: "Focus",
  392. Bl: "Blur",
  393. PO: "PageOpen",
  394. PC: "PageClose",
  395. PV: "PageVisible",
  396. PI: "PageInvisible",
  397. K: "Keystroke",
  398. F: "Format",
  399. V: "Validate",
  400. C: "Calculate",
  401. };
  402. const DocumentActionEventType = {
  403. WC: "WillClose",
  404. WS: "WillSave",
  405. DS: "DidSave",
  406. WP: "WillPrint",
  407. DP: "DidPrint",
  408. };
  409. const PageActionEventType = {
  410. O: "PageOpen",
  411. C: "PageClose",
  412. };
  413. const StreamType = {
  414. UNKNOWN: "UNKNOWN",
  415. FLATE: "FLATE",
  416. LZW: "LZW",
  417. DCT: "DCT",
  418. JPX: "JPX",
  419. JBIG: "JBIG",
  420. A85: "A85",
  421. AHX: "AHX",
  422. CCF: "CCF",
  423. RLX: "RLX", // PDF short name is 'RL', but telemetry requires three chars.
  424. };
  425. const FontType = {
  426. UNKNOWN: "UNKNOWN",
  427. TYPE1: "TYPE1",
  428. TYPE1STANDARD: "TYPE1STANDARD",
  429. TYPE1C: "TYPE1C",
  430. CIDFONTTYPE0: "CIDFONTTYPE0",
  431. CIDFONTTYPE0C: "CIDFONTTYPE0C",
  432. TRUETYPE: "TRUETYPE",
  433. CIDFONTTYPE2: "CIDFONTTYPE2",
  434. TYPE3: "TYPE3",
  435. OPENTYPE: "OPENTYPE",
  436. TYPE0: "TYPE0",
  437. MMTYPE1: "MMTYPE1",
  438. };
  439. const VerbosityLevel = {
  440. ERRORS: 0,
  441. WARNINGS: 1,
  442. INFOS: 5,
  443. };
  444. const CMapCompressionType = {
  445. NONE: 0,
  446. BINARY: 1,
  447. };
  448. // All the possible operations for an operator list.
  449. const OPS = {
  450. // Intentionally start from 1 so it is easy to spot bad operators that will be
  451. // 0's.
  452. // PLEASE NOTE: We purposely keep any removed operators commented out, since
  453. // re-numbering the list would risk breaking third-party users.
  454. dependency: 1,
  455. setLineWidth: 2,
  456. setLineCap: 3,
  457. setLineJoin: 4,
  458. setMiterLimit: 5,
  459. setDash: 6,
  460. setRenderingIntent: 7,
  461. setFlatness: 8,
  462. setGState: 9,
  463. save: 10,
  464. restore: 11,
  465. transform: 12,
  466. moveTo: 13,
  467. lineTo: 14,
  468. curveTo: 15,
  469. curveTo2: 16,
  470. curveTo3: 17,
  471. closePath: 18,
  472. rectangle: 19,
  473. stroke: 20,
  474. closeStroke: 21,
  475. fill: 22,
  476. eoFill: 23,
  477. fillStroke: 24,
  478. eoFillStroke: 25,
  479. closeFillStroke: 26,
  480. closeEOFillStroke: 27,
  481. endPath: 28,
  482. clip: 29,
  483. eoClip: 30,
  484. beginText: 31,
  485. endText: 32,
  486. setCharSpacing: 33,
  487. setWordSpacing: 34,
  488. setHScale: 35,
  489. setLeading: 36,
  490. setFont: 37,
  491. setTextRenderingMode: 38,
  492. setTextRise: 39,
  493. moveText: 40,
  494. setLeadingMoveText: 41,
  495. setTextMatrix: 42,
  496. nextLine: 43,
  497. showText: 44,
  498. showSpacedText: 45,
  499. nextLineShowText: 46,
  500. nextLineSetSpacingShowText: 47,
  501. setCharWidth: 48,
  502. setCharWidthAndBounds: 49,
  503. setStrokeColorSpace: 50,
  504. setFillColorSpace: 51,
  505. setStrokeColor: 52,
  506. setStrokeColorN: 53,
  507. setFillColor: 54,
  508. setFillColorN: 55,
  509. setStrokeGray: 56,
  510. setFillGray: 57,
  511. setStrokeRGBColor: 58,
  512. setFillRGBColor: 59,
  513. setStrokeCMYKColor: 60,
  514. setFillCMYKColor: 61,
  515. shadingFill: 62,
  516. beginInlineImage: 63,
  517. beginImageData: 64,
  518. endInlineImage: 65,
  519. paintXObject: 66,
  520. markPoint: 67,
  521. markPointProps: 68,
  522. beginMarkedContent: 69,
  523. beginMarkedContentProps: 70,
  524. endMarkedContent: 71,
  525. beginCompat: 72,
  526. endCompat: 73,
  527. paintFormXObjectBegin: 74,
  528. paintFormXObjectEnd: 75,
  529. beginGroup: 76,
  530. endGroup: 77,
  531. // beginAnnotations: 78,
  532. // endAnnotations: 79,
  533. beginAnnotation: 80,
  534. endAnnotation: 81,
  535. // paintJpegXObject: 82,
  536. paintImageMaskXObject: 83,
  537. paintImageMaskXObjectGroup: 84,
  538. paintImageXObject: 85,
  539. paintInlineImageXObject: 86,
  540. paintInlineImageXObjectGroup: 87,
  541. paintImageXObjectRepeat: 88,
  542. paintImageMaskXObjectRepeat: 89,
  543. paintSolidColorImageMask: 90,
  544. constructPath: 91,
  545. };
  546. const UNSUPPORTED_FEATURES = {
  547. forms: "forms",
  548. javaScript: "javaScript",
  549. signatures: "signatures",
  550. smask: "smask",
  551. shadingPattern: "shadingPattern",
  552. errorTilingPattern: "errorTilingPattern",
  553. errorExtGState: "errorExtGState",
  554. errorXObject: "errorXObject",
  555. errorFontLoadType3: "errorFontLoadType3",
  556. errorFontState: "errorFontState",
  557. errorFontMissing: "errorFontMissing",
  558. errorFontTranslate: "errorFontTranslate",
  559. errorColorSpace: "errorColorSpace",
  560. errorOperatorList: "errorOperatorList",
  561. errorFontToUnicode: "errorFontToUnicode",
  562. errorFontLoadNative: "errorFontLoadNative",
  563. errorFontBuildPath: "errorFontBuildPath",
  564. errorFontGetPath: "errorFontGetPath",
  565. errorMarkedContent: "errorMarkedContent",
  566. errorContentSubStream: "errorContentSubStream",
  567. };
  568. const PasswordResponses = {
  569. NEED_PASSWORD: 1,
  570. INCORRECT_PASSWORD: 2,
  571. };
  572. class PixelsPerInch {
  573. static CSS = 96.0;
  574. static PDF = 72.0;
  575. static PDF_TO_CSS_UNITS = 1;
  576. }
  577. const ANNOTATION_TYPE = {
  578. ink: 'Ink',
  579. freetext: 'freetext',
  580. text: 'Text',
  581. square: 'Square',
  582. circle: 'Circle',
  583. line: 'Line',
  584. arrow: 'Line',
  585. image: 'Image',
  586. };
  587. export {
  588. RenderingStates,
  589. MARGIN_DISTANCE,
  590. IDENTITY_MATRIX,
  591. FONT_IDENTITY_MATRIX,
  592. LINE_FACTOR,
  593. MARKUP,
  594. LINE_DESCENT_FACTOR,
  595. RenderingIntentFlag,
  596. AnnotationEditorPrefix,
  597. AnnotationEditorType,
  598. AnnotationEditorParamsType,
  599. PermissionFlag,
  600. TextRenderingMode,
  601. ImageKind,
  602. AnnotationType,
  603. AnnotationTypeString,
  604. WidgetType,
  605. WidgetTypeString,
  606. AnnotationFlags,
  607. TextFiledSpecial,
  608. TextFiledSpecialString,
  609. LineType,
  610. LineTypeString,
  611. CheckStyle,
  612. CheckStyleString,
  613. StampType,
  614. StampTypeString,
  615. TextStampColor,
  616. TextStampColorString,
  617. ActionType,
  618. ActionTypeString,
  619. BorderStyleInt,
  620. BorderStyleString,
  621. TextStampShape,
  622. TextStampShapeString,
  623. AnnotationStateModelType,
  624. AnnotationMarkedState,
  625. AnnotationReviewState,
  626. AnnotationReplyType,
  627. AnnotationFlag,
  628. AnnotationFieldFlag,
  629. AnnotationBorderStyleType,
  630. AnnotationActionEventType,
  631. DocumentActionEventType,
  632. PageActionEventType,
  633. StreamType,
  634. FontType,
  635. VerbosityLevel,
  636. CMapCompressionType,
  637. OPS,
  638. PixelsPerInch,
  639. UNSUPPORTED_FEATURES,
  640. PasswordResponses,
  641. ANNOTATION_TYPE,
  642. ALIGN,
  643. ALIGNMAP
  644. }