index.js 13 KB

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