@syncfusion/ej2-pdf 1.0.22 → 23.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (518) hide show
  1. package/.eslintrc.json +260 -0
  2. package/.gitleaksignore +1 -0
  3. package/CHANGELOG.md +17 -0
  4. package/README.md +17 -0
  5. package/dist/ej2-pdf.umd.min.js +3 -13
  6. package/dist/ej2-pdf.umd.min.js.map +1 -11
  7. package/dist/es6/ej2-pdf.es2015.js +48245 -0
  8. package/dist/es6/ej2-pdf.es2015.js.map +1 -0
  9. package/dist/es6/ej2-pdf.es5.js +50124 -0
  10. package/dist/es6/ej2-pdf.es5.js.map +1 -0
  11. package/dist/global/ej2-pdf.min.js +11 -0
  12. package/dist/global/ej2-pdf.min.js.map +1 -0
  13. package/dist/global/index.d.ts +14 -0
  14. package/index.js +4 -8
  15. package/license +10 -3
  16. package/package.json +57 -15
  17. package/pdf.d.ts +4 -0
  18. package/pdf.js +4 -0
  19. package/src/global.js +1 -0
  20. package/src/index.d.ts +45 -98
  21. package/src/index.js +45 -96
  22. package/src/pdf/core/annotations/annotation-collection.d.ts +289 -0
  23. package/src/pdf/core/annotations/annotation-collection.js +744 -0
  24. package/src/pdf/core/annotations/annotation.d.ts +5845 -0
  25. package/src/pdf/core/annotations/annotation.js +14195 -0
  26. package/src/pdf/core/annotations/index.d.ts +4 -0
  27. package/src/pdf/core/annotations/index.js +4 -0
  28. package/src/pdf/core/annotations/pdf-appearance.d.ts +102 -0
  29. package/src/pdf/core/annotations/pdf-appearance.js +124 -0
  30. package/src/pdf/core/annotations/pdf-paddings.d.ts +8 -0
  31. package/src/pdf/core/annotations/pdf-paddings.js +22 -0
  32. package/src/pdf/core/base-stream.d.ts +86 -0
  33. package/src/pdf/core/base-stream.js +332 -0
  34. package/src/pdf/core/content-parser.d.ts +38 -0
  35. package/src/pdf/core/content-parser.js +359 -0
  36. package/src/pdf/core/decode-stream.d.ts +21 -0
  37. package/src/pdf/core/decode-stream.js +120 -0
  38. package/src/pdf/core/decrypt-stream.d.ts +11 -0
  39. package/src/pdf/core/decrypt-stream.js +53 -0
  40. package/src/pdf/core/enumerator.d.ts +1668 -0
  41. package/src/pdf/core/enumerator.js +1717 -0
  42. package/src/pdf/core/flate-stream.d.ts +13 -0
  43. package/src/pdf/core/flate-stream.js +329 -0
  44. package/src/pdf/core/fonts/index.d.ts +7 -0
  45. package/{dist/es6/implementation/graphics → src/pdf/core}/fonts/index.js +3 -4
  46. package/src/pdf/core/fonts/pdf-font-metrics.d.ts +66 -0
  47. package/src/pdf/core/fonts/pdf-font-metrics.js +192 -0
  48. package/src/pdf/core/fonts/pdf-standard-font.d.ts +1023 -0
  49. package/src/pdf/core/fonts/pdf-standard-font.js +1682 -0
  50. package/src/pdf/core/fonts/pdf-string-format.d.ts +236 -0
  51. package/src/pdf/core/fonts/pdf-string-format.js +213 -0
  52. package/src/pdf/core/fonts/string-layouter.d.ts +68 -0
  53. package/src/pdf/core/fonts/string-layouter.js +437 -0
  54. package/src/pdf/core/fonts/ttf-reader.d.ts +167 -0
  55. package/src/pdf/core/fonts/ttf-reader.js +1150 -0
  56. package/src/pdf/core/fonts/ttf-table.d.ts +132 -0
  57. package/src/pdf/core/fonts/ttf-table.js +74 -0
  58. package/src/pdf/core/fonts/unicode-true-type-font.d.ts +50 -0
  59. package/src/pdf/core/fonts/unicode-true-type-font.js +289 -0
  60. package/src/pdf/core/form/field.d.ts +3011 -0
  61. package/src/pdf/core/form/field.js +6828 -0
  62. package/src/pdf/core/form/form.d.ts +279 -0
  63. package/src/pdf/core/form/form.js +782 -0
  64. package/src/pdf/core/form/index.d.ts +2 -0
  65. package/src/pdf/core/form/index.js +2 -0
  66. package/src/pdf/core/graphics/images/image-decoder.d.ts +31 -0
  67. package/src/pdf/core/graphics/images/image-decoder.js +130 -0
  68. package/src/{implementation → pdf/core}/graphics/images/index.d.ts +0 -5
  69. package/{dist/es6/implementation → src/pdf/core}/graphics/images/index.js +0 -1
  70. package/src/pdf/core/graphics/images/pdf-bitmap.d.ts +73 -0
  71. package/src/pdf/core/graphics/images/pdf-bitmap.js +68 -0
  72. package/src/pdf/core/graphics/images/pdf-image.d.ts +201 -0
  73. package/src/pdf/core/graphics/images/pdf-image.js +201 -0
  74. package/src/pdf/core/graphics/index.d.ts +10 -0
  75. package/src/pdf/core/graphics/index.js +10 -0
  76. package/src/pdf/core/graphics/pdf-graphics.d.ts +956 -0
  77. package/src/pdf/core/graphics/pdf-graphics.js +1860 -0
  78. package/src/pdf/core/graphics/pdf-path.d.ts +34 -0
  79. package/src/pdf/core/graphics/pdf-path.js +177 -0
  80. package/src/pdf/core/graphics/pdf-stream-writer.d.ts +56 -0
  81. package/src/pdf/core/graphics/pdf-stream-writer.js +231 -0
  82. package/src/pdf/core/graphics/pdf-template.d.ts +79 -0
  83. package/src/pdf/core/graphics/pdf-template.js +100 -0
  84. package/src/pdf/core/graphics/rightToLeft/bidirectional.d.ts +69 -0
  85. package/src/pdf/core/graphics/rightToLeft/bidirectional.js +831 -0
  86. package/src/pdf/core/graphics/rightToLeft/index.d.ts +3 -0
  87. package/src/pdf/core/graphics/rightToLeft/index.js +3 -0
  88. package/src/pdf/core/graphics/rightToLeft/text-renderer.d.ts +13 -0
  89. package/src/pdf/core/graphics/rightToLeft/text-renderer.js +116 -0
  90. package/src/pdf/core/graphics/rightToLeft/text-shape.d.ts +48 -0
  91. package/src/pdf/core/graphics/rightToLeft/text-shape.js +289 -0
  92. package/src/pdf/core/import-export/fdf-document.d.ts +37 -0
  93. package/src/pdf/core/import-export/fdf-document.js +667 -0
  94. package/src/pdf/core/import-export/index.d.ts +5 -0
  95. package/src/pdf/core/import-export/index.js +5 -0
  96. package/src/pdf/core/import-export/json-document.d.ts +47 -0
  97. package/src/pdf/core/import-export/json-document.js +1547 -0
  98. package/src/pdf/core/import-export/xfdf-document.d.ts +146 -0
  99. package/src/pdf/core/import-export/xfdf-document.js +2920 -0
  100. package/src/pdf/core/import-export/xml-document.d.ts +14 -0
  101. package/src/pdf/core/import-export/xml-document.js +166 -0
  102. package/src/pdf/core/import-export/xml-writer.d.ts +69 -0
  103. package/src/pdf/core/import-export/xml-writer.js +494 -0
  104. package/src/pdf/core/pdf-catalog.d.ts +18 -0
  105. package/src/pdf/core/pdf-catalog.js +166 -0
  106. package/src/pdf/core/pdf-cross-reference.d.ts +80 -0
  107. package/src/pdf/core/pdf-cross-reference.js +1049 -0
  108. package/src/pdf/core/pdf-document.d.ts +821 -0
  109. package/src/pdf/core/pdf-document.js +1022 -0
  110. package/src/pdf/core/pdf-file-structure.d.ts +54 -0
  111. package/src/pdf/core/pdf-file-structure.js +65 -0
  112. package/src/pdf/core/pdf-outline.d.ts +362 -0
  113. package/src/pdf/core/pdf-outline.js +860 -0
  114. package/src/pdf/core/pdf-page.d.ts +589 -0
  115. package/src/pdf/core/pdf-page.js +1049 -0
  116. package/src/pdf/core/pdf-parser.d.ts +62 -0
  117. package/src/pdf/core/pdf-parser.js +1035 -0
  118. package/src/pdf/core/pdf-primitives.d.ts +87 -0
  119. package/src/pdf/core/pdf-primitives.js +305 -0
  120. package/src/pdf/core/predictor-stream.d.ts +15 -0
  121. package/src/pdf/core/predictor-stream.js +214 -0
  122. package/src/pdf/core/security/encryptor.d.ts +140 -0
  123. package/src/pdf/core/security/encryptor.js +1616 -0
  124. package/src/pdf/core/security/index.d.ts +1 -0
  125. package/src/pdf/core/security/index.js +1 -0
  126. package/src/pdf/core/utils.d.ts +678 -0
  127. package/src/pdf/core/utils.js +3607 -0
  128. package/src/pdf/index.d.ts +44 -0
  129. package/src/pdf/index.js +44 -0
  130. package/tslint.json +111 -0
  131. package/ReadMe.md +0 -17
  132. package/dist/es6/implementation/actions/action.js +0 -44
  133. package/dist/es6/implementation/actions/index.js +0 -2
  134. package/dist/es6/implementation/actions/uri-action.js +0 -38
  135. package/dist/es6/implementation/annotations/action-link-annotation.js +0 -29
  136. package/dist/es6/implementation/annotations/annotation-collection.js +0 -93
  137. package/dist/es6/implementation/annotations/annotation.js +0 -156
  138. package/dist/es6/implementation/annotations/document-link-annotation.js +0 -48
  139. package/dist/es6/implementation/annotations/index.js +0 -7
  140. package/dist/es6/implementation/annotations/link-annotation.js +0 -31
  141. package/dist/es6/implementation/annotations/pdf-text-web-link.js +0 -178
  142. package/dist/es6/implementation/annotations/uri-annotation.js +0 -64
  143. package/dist/es6/implementation/collections/dictionary.js +0 -71
  144. package/dist/es6/implementation/collections/index.js +0 -3
  145. package/dist/es6/implementation/collections/object-object-pair/dictionary.js +0 -84
  146. package/dist/es6/implementation/collections/object-object-pair/index.js +0 -1
  147. package/dist/es6/implementation/collections/utils.js +0 -8
  148. package/dist/es6/implementation/document/automatic-fields/automatic-field-info-collection.js +0 -17
  149. package/dist/es6/implementation/document/automatic-fields/automatic-field-info.js +0 -68
  150. package/dist/es6/implementation/document/automatic-fields/automatic-field.js +0 -145
  151. package/dist/es6/implementation/document/automatic-fields/composite-field.js +0 -61
  152. package/dist/es6/implementation/document/automatic-fields/index.js +0 -7
  153. package/dist/es6/implementation/document/automatic-fields/multiple-value-field.js +0 -36
  154. package/dist/es6/implementation/document/automatic-fields/page-count-field.js +0 -53
  155. package/dist/es6/implementation/document/automatic-fields/pdf-numbers-convertor.js +0 -91
  156. package/dist/es6/implementation/document/automatic-fields/pdf-page-number-field.js +0 -56
  157. package/dist/es6/implementation/document/automatic-fields/pdf-template-value-pair.js +0 -34
  158. package/dist/es6/implementation/document/automatic-fields/single-value-field.js +0 -47
  159. package/dist/es6/implementation/document/index.js +0 -11
  160. package/dist/es6/implementation/document/pdf-catalog.js +0 -38
  161. package/dist/es6/implementation/document/pdf-document-base.js +0 -71
  162. package/dist/es6/implementation/document/pdf-document-template.js +0 -204
  163. package/dist/es6/implementation/document/pdf-document.js +0 -175
  164. package/dist/es6/implementation/drawing/index.js +0 -1
  165. package/dist/es6/implementation/drawing/pdf-drawing.js +0 -80
  166. package/dist/es6/implementation/general/enum.js +0 -6
  167. package/dist/es6/implementation/general/index.js +0 -3
  168. package/dist/es6/implementation/general/pdf-cache-collection.js +0 -24
  169. package/dist/es6/implementation/general/pdf-collection.js +0 -26
  170. package/dist/es6/implementation/general/pdf-destination.js +0 -107
  171. package/dist/es6/implementation/graphics/brushes/index.js +0 -2
  172. package/dist/es6/implementation/graphics/brushes/pdf-brush.js +0 -6
  173. package/dist/es6/implementation/graphics/brushes/pdf-solid-brush.js +0 -53
  174. package/dist/es6/implementation/graphics/constants.js +0 -11
  175. package/dist/es6/implementation/graphics/enum.js +0 -100
  176. package/dist/es6/implementation/graphics/figures/base/element-layouter.js +0 -154
  177. package/dist/es6/implementation/graphics/figures/base/graphics-element.js +0 -18
  178. package/dist/es6/implementation/graphics/figures/base/index.js +0 -3
  179. package/dist/es6/implementation/graphics/figures/base/pdf-shape-element.js +0 -32
  180. package/dist/es6/implementation/graphics/figures/base/shape-layouter.js +0 -55
  181. package/dist/es6/implementation/graphics/figures/base/text-layouter.js +0 -123
  182. package/dist/es6/implementation/graphics/figures/enum.js +0 -11
  183. package/dist/es6/implementation/graphics/figures/index.js +0 -5
  184. package/dist/es6/implementation/graphics/figures/layout-element.js +0 -41
  185. package/dist/es6/implementation/graphics/figures/pdf-template.js +0 -110
  186. package/dist/es6/implementation/graphics/figures/text-element.js +0 -298
  187. package/dist/es6/implementation/graphics/fonts/enum.js +0 -45
  188. package/dist/es6/implementation/graphics/fonts/pdf-font-metrics.js +0 -122
  189. package/dist/es6/implementation/graphics/fonts/pdf-font.js +0 -159
  190. package/dist/es6/implementation/graphics/fonts/pdf-standard-font-metrics-factory.js +0 -357
  191. package/dist/es6/implementation/graphics/fonts/pdf-standard-font.js +0 -124
  192. package/dist/es6/implementation/graphics/fonts/pdf-string-format.js +0 -239
  193. package/dist/es6/implementation/graphics/fonts/string-layouter.js +0 -335
  194. package/dist/es6/implementation/graphics/fonts/string-tokenizer.js +0 -162
  195. package/dist/es6/implementation/graphics/images/byte-array.js +0 -82
  196. package/dist/es6/implementation/graphics/images/image-decoder.js +0 -167
  197. package/dist/es6/implementation/graphics/images/pdf-bitmap.js +0 -41
  198. package/dist/es6/implementation/graphics/images/pdf-image.js +0 -68
  199. package/dist/es6/implementation/graphics/index.js +0 -20
  200. package/dist/es6/implementation/graphics/pdf-color.js +0 -205
  201. package/dist/es6/implementation/graphics/pdf-graphics.js +0 -1034
  202. package/dist/es6/implementation/graphics/pdf-margins.js +0 -75
  203. package/dist/es6/implementation/graphics/pdf-pen.js +0 -180
  204. package/dist/es6/implementation/graphics/pdf-resources.js +0 -223
  205. package/dist/es6/implementation/graphics/pdf-transformation-matrix.js +0 -134
  206. package/dist/es6/implementation/graphics/pdf-transparency.js +0 -22
  207. package/dist/es6/implementation/graphics/unit-convertor.js +0 -33
  208. package/dist/es6/implementation/index.js +0 -85
  209. package/dist/es6/implementation/input-output/cross-table.js +0 -6
  210. package/dist/es6/implementation/input-output/enum.js +0 -5
  211. package/dist/es6/implementation/input-output/index.js +0 -8
  212. package/dist/es6/implementation/input-output/pdf-cross-table.js +0 -346
  213. package/dist/es6/implementation/input-output/pdf-dictionary-properties.js +0 -60
  214. package/dist/es6/implementation/input-output/pdf-main-object-collection.js +0 -115
  215. package/dist/es6/implementation/input-output/pdf-operators.js +0 -75
  216. package/dist/es6/implementation/input-output/pdf-stream-writer.js +0 -364
  217. package/dist/es6/implementation/input-output/pdf-writer.js +0 -44
  218. package/dist/es6/implementation/pages/enum.js +0 -51
  219. package/dist/es6/implementation/pages/index.js +0 -13
  220. package/dist/es6/implementation/pages/page-added-event-arguments.js +0 -19
  221. package/dist/es6/implementation/pages/pdf-document-page-collection.js +0 -120
  222. package/dist/es6/implementation/pages/pdf-page-base.js +0 -104
  223. package/dist/es6/implementation/pages/pdf-page-layer-collection.js +0 -115
  224. package/dist/es6/implementation/pages/pdf-page-layer.js +0 -160
  225. package/dist/es6/implementation/pages/pdf-page-settings.js +0 -126
  226. package/dist/es6/implementation/pages/pdf-page-size.js +0 -36
  227. package/dist/es6/implementation/pages/pdf-page-template-element.js +0 -510
  228. package/dist/es6/implementation/pages/pdf-page.js +0 -130
  229. package/dist/es6/implementation/pages/pdf-section-collection.js +0 -95
  230. package/dist/es6/implementation/pages/pdf-section-page-collection.js +0 -30
  231. package/dist/es6/implementation/pages/pdf-section-templates.js +0 -71
  232. package/dist/es6/implementation/pages/pdf-section.js +0 -388
  233. package/dist/es6/implementation/primitives/index.js +0 -8
  234. package/dist/es6/implementation/primitives/pdf-array.js +0 -199
  235. package/dist/es6/implementation/primitives/pdf-boolean.js +0 -66
  236. package/dist/es6/implementation/primitives/pdf-dictionary.js +0 -220
  237. package/dist/es6/implementation/primitives/pdf-name.js +0 -102
  238. package/dist/es6/implementation/primitives/pdf-number.js +0 -94
  239. package/dist/es6/implementation/primitives/pdf-reference.js +0 -195
  240. package/dist/es6/implementation/primitives/pdf-stream.js +0 -149
  241. package/dist/es6/implementation/primitives/pdf-string.js +0 -143
  242. package/dist/es6/implementation/structured-elements/grid/index.js +0 -1
  243. package/dist/es6/implementation/structured-elements/grid/pdf-grid-cell.js +0 -512
  244. package/dist/es6/implementation/structured-elements/grid/pdf-grid-column.js +0 -125
  245. package/dist/es6/implementation/structured-elements/grid/pdf-grid-row.js +0 -244
  246. package/dist/es6/implementation/structured-elements/grid/pdf-grid.js +0 -989
  247. package/dist/es6/implementation/structured-elements/grid/styles/index.js +0 -2
  248. package/dist/es6/implementation/structured-elements/grid/styles/pdf-borders.js +0 -145
  249. package/dist/es6/implementation/structured-elements/grid/styles/style.js +0 -267
  250. package/dist/es6/implementation/structured-elements/index.js +0 -1
  251. package/dist/es6/implementation/structured-elements/tables/light-tables/enum.js +0 -5
  252. package/dist/es6/index.js +0 -89
  253. package/dist/es6/interfaces/i-pdf-cache.js +0 -1
  254. package/dist/es6/interfaces/i-pdf-changable.js +0 -1
  255. package/dist/es6/interfaces/i-pdf-primitives.js +0 -1
  256. package/dist/es6/interfaces/i-pdf-wrapper.js +0 -1
  257. package/dist/es6/interfaces/i-pdf-writer.js +0 -1
  258. package/dist/es6/interfaces/index.js +0 -1
  259. package/dist//global//ej2-pdf.js +0 -15979
  260. package/implementation.d.ts +0 -4
  261. package/implementation.js +0 -8
  262. package/interfaces.d.ts +0 -4
  263. package/interfaces.js +0 -4
  264. package/src/implementation/actions/action.d.ts +0 -50
  265. package/src/implementation/actions/action.js +0 -44
  266. package/src/implementation/actions/index.d.ts +0 -6
  267. package/src/implementation/actions/index.js +0 -9
  268. package/src/implementation/actions/uri-action.d.ts +0 -33
  269. package/src/implementation/actions/uri-action.js +0 -39
  270. package/src/implementation/annotations/action-link-annotation.d.ts +0 -30
  271. package/src/implementation/annotations/action-link-annotation.js +0 -32
  272. package/src/implementation/annotations/annotation-collection.d.ts +0 -77
  273. package/src/implementation/annotations/annotation-collection.js +0 -91
  274. package/src/implementation/annotations/annotation.d.ts +0 -152
  275. package/src/implementation/annotations/annotation.js +0 -146
  276. package/src/implementation/annotations/document-link-annotation.d.ts +0 -89
  277. package/src/implementation/annotations/document-link-annotation.js +0 -51
  278. package/src/implementation/annotations/index.d.ts +0 -11
  279. package/src/implementation/annotations/index.js +0 -14
  280. package/src/implementation/annotations/link-annotation.d.ts +0 -23
  281. package/src/implementation/annotations/link-annotation.js +0 -33
  282. package/src/implementation/annotations/pdf-text-web-link.d.ts +0 -118
  283. package/src/implementation/annotations/pdf-text-web-link.js +0 -173
  284. package/src/implementation/annotations/uri-annotation.d.ts +0 -48
  285. package/src/implementation/annotations/uri-annotation.js +0 -65
  286. package/src/implementation/collections/dictionary.d.ts +0 -76
  287. package/src/implementation/collections/dictionary.js +0 -74
  288. package/src/implementation/collections/index.d.ts +0 -7
  289. package/src/implementation/collections/index.js +0 -10
  290. package/src/implementation/collections/object-object-pair/dictionary.d.ts +0 -62
  291. package/src/implementation/collections/object-object-pair/dictionary.js +0 -88
  292. package/src/implementation/collections/object-object-pair/index.d.ts +0 -5
  293. package/src/implementation/collections/object-object-pair/index.js +0 -8
  294. package/src/implementation/collections/utils.d.ts +0 -27
  295. package/src/implementation/collections/utils.js +0 -13
  296. package/src/implementation/document/automatic-fields/automatic-field-info-collection.d.ts +0 -31
  297. package/src/implementation/document/automatic-fields/automatic-field-info-collection.js +0 -21
  298. package/src/implementation/document/automatic-fields/automatic-field-info.d.ts +0 -67
  299. package/src/implementation/document/automatic-fields/automatic-field-info.js +0 -70
  300. package/src/implementation/document/automatic-fields/automatic-field.d.ts +0 -41
  301. package/src/implementation/document/automatic-fields/automatic-field.js +0 -143
  302. package/src/implementation/document/automatic-fields/composite-field.d.ts +0 -46
  303. package/src/implementation/document/automatic-fields/composite-field.js +0 -64
  304. package/src/implementation/document/automatic-fields/index.d.ts +0 -11
  305. package/src/implementation/document/automatic-fields/index.js +0 -14
  306. package/src/implementation/document/automatic-fields/multiple-value-field.d.ts +0 -18
  307. package/src/implementation/document/automatic-fields/multiple-value-field.js +0 -35
  308. package/src/implementation/document/automatic-fields/page-count-field.d.ts +0 -44
  309. package/src/implementation/document/automatic-fields/page-count-field.js +0 -53
  310. package/src/implementation/document/automatic-fields/pdf-numbers-convertor.d.ts +0 -53
  311. package/src/implementation/document/automatic-fields/pdf-numbers-convertor.js +0 -94
  312. package/src/implementation/document/automatic-fields/pdf-page-number-field.d.ts +0 -51
  313. package/src/implementation/document/automatic-fields/pdf-page-number-field.js +0 -56
  314. package/src/implementation/document/automatic-fields/pdf-template-value-pair.d.ts +0 -38
  315. package/src/implementation/document/automatic-fields/pdf-template-value-pair.js +0 -38
  316. package/src/implementation/document/automatic-fields/single-value-field.d.ts +0 -15
  317. package/src/implementation/document/automatic-fields/single-value-field.js +0 -46
  318. package/src/implementation/document/index.d.ts +0 -15
  319. package/src/implementation/document/index.js +0 -18
  320. package/src/implementation/document/pdf-catalog.d.ts +0 -32
  321. package/src/implementation/document/pdf-catalog.js +0 -38
  322. package/src/implementation/document/pdf-document-base.d.ts +0 -117
  323. package/src/implementation/document/pdf-document-base.js +0 -72
  324. package/src/implementation/document/pdf-document-template.d.ts +0 -166
  325. package/src/implementation/document/pdf-document-template.js +0 -207
  326. package/src/implementation/document/pdf-document.d.ts +0 -206
  327. package/src/implementation/document/pdf-document.js +0 -166
  328. package/src/implementation/drawing/index.d.ts +0 -5
  329. package/src/implementation/drawing/index.js +0 -8
  330. package/src/implementation/drawing/pdf-drawing.d.ts +0 -93
  331. package/src/implementation/drawing/pdf-drawing.js +0 -84
  332. package/src/implementation/general/enum.d.ts +0 -21
  333. package/src/implementation/general/enum.js +0 -10
  334. package/src/implementation/general/index.d.ts +0 -7
  335. package/src/implementation/general/index.js +0 -10
  336. package/src/implementation/general/pdf-cache-collection.d.ts +0 -33
  337. package/src/implementation/general/pdf-cache-collection.js +0 -27
  338. package/src/implementation/general/pdf-collection.d.ts +0 -26
  339. package/src/implementation/general/pdf-collection.js +0 -30
  340. package/src/implementation/general/pdf-destination.d.ts +0 -103
  341. package/src/implementation/general/pdf-destination.js +0 -103
  342. package/src/implementation/graphics/brushes/index.d.ts +0 -6
  343. package/src/implementation/graphics/brushes/index.js +0 -9
  344. package/src/implementation/graphics/brushes/pdf-brush.d.ts +0 -55
  345. package/src/implementation/graphics/brushes/pdf-brush.js +0 -10
  346. package/src/implementation/graphics/brushes/pdf-solid-brush.d.ts +0 -77
  347. package/src/implementation/graphics/brushes/pdf-solid-brush.js +0 -54
  348. package/src/implementation/graphics/constants.d.ts +0 -31
  349. package/src/implementation/graphics/constants.js +0 -15
  350. package/src/implementation/graphics/enum.d.ts +0 -392
  351. package/src/implementation/graphics/enum.js +0 -104
  352. package/src/implementation/graphics/figures/base/element-layouter.d.ts +0 -160
  353. package/src/implementation/graphics/figures/base/element-layouter.js +0 -156
  354. package/src/implementation/graphics/figures/base/graphics-element.d.ts +0 -16
  355. package/src/implementation/graphics/figures/base/graphics-element.js +0 -22
  356. package/src/implementation/graphics/figures/base/index.d.ts +0 -7
  357. package/src/implementation/graphics/figures/base/index.js +0 -10
  358. package/src/implementation/graphics/figures/base/pdf-shape-element.d.ts +0 -28
  359. package/src/implementation/graphics/figures/base/pdf-shape-element.js +0 -34
  360. package/src/implementation/graphics/figures/base/shape-layouter.d.ts +0 -80
  361. package/src/implementation/graphics/figures/base/shape-layouter.js +0 -57
  362. package/src/implementation/graphics/figures/base/text-layouter.d.ts +0 -107
  363. package/src/implementation/graphics/figures/base/text-layouter.js +0 -121
  364. package/src/implementation/graphics/figures/enum.d.ts +0 -37
  365. package/src/implementation/graphics/figures/enum.js +0 -15
  366. package/src/implementation/graphics/figures/index.d.ts +0 -9
  367. package/src/implementation/graphics/figures/index.js +0 -12
  368. package/src/implementation/graphics/figures/layout-element.d.ts +0 -57
  369. package/src/implementation/graphics/figures/layout-element.js +0 -43
  370. package/src/implementation/graphics/figures/pdf-template.d.ts +0 -113
  371. package/src/implementation/graphics/figures/pdf-template.js +0 -106
  372. package/src/implementation/graphics/figures/text-element.d.ts +0 -213
  373. package/src/implementation/graphics/figures/text-element.js +0 -289
  374. package/src/implementation/graphics/fonts/enum.d.ts +0 -179
  375. package/src/implementation/graphics/fonts/enum.js +0 -49
  376. package/src/implementation/graphics/fonts/index.d.ts +0 -12
  377. package/src/implementation/graphics/fonts/index.js +0 -15
  378. package/src/implementation/graphics/fonts/pdf-font-metrics.d.ts +0 -160
  379. package/src/implementation/graphics/fonts/pdf-font-metrics.js +0 -123
  380. package/src/implementation/graphics/fonts/pdf-font.d.ts +0 -187
  381. package/src/implementation/graphics/fonts/pdf-font.js +0 -158
  382. package/src/implementation/graphics/fonts/pdf-standard-font-metrics-factory.d.ts +0 -301
  383. package/src/implementation/graphics/fonts/pdf-standard-font-metrics-factory.js +0 -359
  384. package/src/implementation/graphics/fonts/pdf-standard-font.d.ts +0 -143
  385. package/src/implementation/graphics/fonts/pdf-standard-font.js +0 -121
  386. package/src/implementation/graphics/fonts/pdf-string-format.d.ts +0 -319
  387. package/src/implementation/graphics/fonts/pdf-string-format.js +0 -241
  388. package/src/implementation/graphics/fonts/string-layouter.d.ts +0 -255
  389. package/src/implementation/graphics/fonts/string-layouter.js +0 -336
  390. package/src/implementation/graphics/fonts/string-tokenizer.d.ts +0 -107
  391. package/src/implementation/graphics/fonts/string-tokenizer.js +0 -166
  392. package/src/implementation/graphics/images/byte-array.d.ts +0 -68
  393. package/src/implementation/graphics/images/byte-array.js +0 -86
  394. package/src/implementation/graphics/images/image-decoder.d.ts +0 -227
  395. package/src/implementation/graphics/images/image-decoder.js +0 -164
  396. package/src/implementation/graphics/images/index.js +0 -11
  397. package/src/implementation/graphics/images/pdf-bitmap.d.ts +0 -90
  398. package/src/implementation/graphics/images/pdf-bitmap.js +0 -41
  399. package/src/implementation/graphics/images/pdf-image.d.ts +0 -88
  400. package/src/implementation/graphics/images/pdf-image.js +0 -69
  401. package/src/implementation/graphics/index.d.ts +0 -24
  402. package/src/implementation/graphics/index.js +0 -27
  403. package/src/implementation/graphics/pdf-color.d.ts +0 -170
  404. package/src/implementation/graphics/pdf-color.js +0 -204
  405. package/src/implementation/graphics/pdf-graphics.d.ts +0 -1085
  406. package/src/implementation/graphics/pdf-graphics.js +0 -1017
  407. package/src/implementation/graphics/pdf-margins.d.ts +0 -82
  408. package/src/implementation/graphics/pdf-margins.js +0 -79
  409. package/src/implementation/graphics/pdf-pen.d.ts +0 -237
  410. package/src/implementation/graphics/pdf-pen.js +0 -181
  411. package/src/implementation/graphics/pdf-resources.d.ts +0 -147
  412. package/src/implementation/graphics/pdf-resources.js +0 -215
  413. package/src/implementation/graphics/pdf-transformation-matrix.d.ts +0 -143
  414. package/src/implementation/graphics/pdf-transformation-matrix.js +0 -136
  415. package/src/implementation/graphics/pdf-transparency.d.ts +0 -34
  416. package/src/implementation/graphics/pdf-transparency.js +0 -22
  417. package/src/implementation/graphics/unit-convertor.d.ts +0 -72
  418. package/src/implementation/graphics/unit-convertor.js +0 -37
  419. package/src/implementation/index.d.ts +0 -89
  420. package/src/implementation/index.js +0 -92
  421. package/src/implementation/input-output/cross-table.d.ts +0 -21
  422. package/src/implementation/input-output/cross-table.js +0 -10
  423. package/src/implementation/input-output/enum.d.ts +0 -16
  424. package/src/implementation/input-output/enum.js +0 -9
  425. package/src/implementation/input-output/index.d.ts +0 -12
  426. package/src/implementation/input-output/index.js +0 -15
  427. package/src/implementation/input-output/pdf-cross-table.d.ts +0 -249
  428. package/src/implementation/input-output/pdf-cross-table.js +0 -340
  429. package/src/implementation/input-output/pdf-dictionary-properties.d.ts +0 -283
  430. package/src/implementation/input-output/pdf-dictionary-properties.js +0 -64
  431. package/src/implementation/input-output/pdf-main-object-collection.d.ts +0 -120
  432. package/src/implementation/input-output/pdf-main-object-collection.js +0 -117
  433. package/src/implementation/input-output/pdf-operators.d.ts +0 -352
  434. package/src/implementation/input-output/pdf-operators.js +0 -79
  435. package/src/implementation/input-output/pdf-stream-writer.d.ts +0 -314
  436. package/src/implementation/input-output/pdf-stream-writer.js +0 -363
  437. package/src/implementation/input-output/pdf-writer.d.ts +0 -68
  438. package/src/implementation/input-output/pdf-writer.js +0 -48
  439. package/src/implementation/pages/enum.d.ts +0 -201
  440. package/src/implementation/pages/enum.js +0 -55
  441. package/src/implementation/pages/index.d.ts +0 -17
  442. package/src/implementation/pages/index.js +0 -20
  443. package/src/implementation/pages/page-added-event-arguments.d.ts +0 -30
  444. package/src/implementation/pages/page-added-event-arguments.js +0 -23
  445. package/src/implementation/pages/pdf-document-page-collection.d.ts +0 -92
  446. package/src/implementation/pages/pdf-document-page-collection.js +0 -121
  447. package/src/implementation/pages/pdf-page-base.d.ts +0 -121
  448. package/src/implementation/pages/pdf-page-base.js +0 -104
  449. package/src/implementation/pages/pdf-page-layer-collection.d.ts +0 -99
  450. package/src/implementation/pages/pdf-page-layer-collection.js +0 -113
  451. package/src/implementation/pages/pdf-page-layer.d.ts +0 -160
  452. package/src/implementation/pages/pdf-page-layer.js +0 -159
  453. package/src/implementation/pages/pdf-page-settings.d.ts +0 -111
  454. package/src/implementation/pages/pdf-page-settings.js +0 -126
  455. package/src/implementation/pages/pdf-page-size.d.ts +0 -159
  456. package/src/implementation/pages/pdf-page-size.js +0 -39
  457. package/src/implementation/pages/pdf-page-template-element.d.ts +0 -230
  458. package/src/implementation/pages/pdf-page-template-element.js +0 -509
  459. package/src/implementation/pages/pdf-page.d.ts +0 -153
  460. package/src/implementation/pages/pdf-page.js +0 -127
  461. package/src/implementation/pages/pdf-section-collection.d.ts +0 -109
  462. package/src/implementation/pages/pdf-section-collection.js +0 -91
  463. package/src/implementation/pages/pdf-section-page-collection.d.ts +0 -41
  464. package/src/implementation/pages/pdf-section-page-collection.js +0 -34
  465. package/src/implementation/pages/pdf-section-templates.d.ts +0 -64
  466. package/src/implementation/pages/pdf-section-templates.js +0 -74
  467. package/src/implementation/pages/pdf-section.d.ts +0 -319
  468. package/src/implementation/pages/pdf-section.js +0 -379
  469. package/src/implementation/primitives/index.d.ts +0 -12
  470. package/src/implementation/primitives/index.js +0 -15
  471. package/src/implementation/primitives/pdf-array.d.ts +0 -186
  472. package/src/implementation/primitives/pdf-array.js +0 -201
  473. package/src/implementation/primitives/pdf-boolean.d.ts +0 -84
  474. package/src/implementation/primitives/pdf-boolean.js +0 -70
  475. package/src/implementation/primitives/pdf-dictionary.d.ts +0 -311
  476. package/src/implementation/primitives/pdf-dictionary.js +0 -220
  477. package/src/implementation/primitives/pdf-name.d.ts +0 -121
  478. package/src/implementation/primitives/pdf-name.js +0 -106
  479. package/src/implementation/primitives/pdf-number.d.ts +0 -104
  480. package/src/implementation/primitives/pdf-number.js +0 -98
  481. package/src/implementation/primitives/pdf-reference.d.ts +0 -222
  482. package/src/implementation/primitives/pdf-reference.js +0 -192
  483. package/src/implementation/primitives/pdf-stream.d.ts +0 -111
  484. package/src/implementation/primitives/pdf-stream.js +0 -146
  485. package/src/implementation/primitives/pdf-string.d.ts +0 -212
  486. package/src/implementation/primitives/pdf-string.js +0 -147
  487. package/src/implementation/structured-elements/grid/index.d.ts +0 -0
  488. package/src/implementation/structured-elements/grid/index.js +0 -1
  489. package/src/implementation/structured-elements/grid/pdf-grid-cell.d.ts +0 -248
  490. package/src/implementation/structured-elements/grid/pdf-grid-cell.js +0 -504
  491. package/src/implementation/structured-elements/grid/pdf-grid-column.d.ts +0 -108
  492. package/src/implementation/structured-elements/grid/pdf-grid-column.js +0 -127
  493. package/src/implementation/structured-elements/grid/pdf-grid-row.d.ts +0 -207
  494. package/src/implementation/structured-elements/grid/pdf-grid-row.js +0 -246
  495. package/src/implementation/structured-elements/grid/pdf-grid.d.ts +0 -678
  496. package/src/implementation/structured-elements/grid/pdf-grid.js +0 -982
  497. package/src/implementation/structured-elements/grid/styles/index.d.ts +0 -5
  498. package/src/implementation/structured-elements/grid/styles/index.js +0 -9
  499. package/src/implementation/structured-elements/grid/styles/pdf-borders.d.ts +0 -126
  500. package/src/implementation/structured-elements/grid/styles/pdf-borders.js +0 -146
  501. package/src/implementation/structured-elements/grid/styles/style.d.ts +0 -250
  502. package/src/implementation/structured-elements/grid/styles/style.js +0 -269
  503. package/src/implementation/structured-elements/index.d.ts +0 -0
  504. package/src/implementation/structured-elements/index.js +0 -1
  505. package/src/implementation/structured-elements/tables/light-tables/enum.d.ts +0 -16
  506. package/src/implementation/structured-elements/tables/light-tables/enum.js +0 -9
  507. package/src/interfaces/i-pdf-cache.d.ts +0 -23
  508. package/src/interfaces/i-pdf-cache.js +0 -4
  509. package/src/interfaces/i-pdf-changable.d.ts +0 -17
  510. package/src/interfaces/i-pdf-changable.js +0 -4
  511. package/src/interfaces/i-pdf-primitives.d.ts +0 -45
  512. package/src/interfaces/i-pdf-primitives.js +0 -4
  513. package/src/interfaces/i-pdf-wrapper.d.ts +0 -13
  514. package/src/interfaces/i-pdf-wrapper.js +0 -4
  515. package/src/interfaces/i-pdf-writer.d.ts +0 -29
  516. package/src/interfaces/i-pdf-writer.js +0 -4
  517. package/src/interfaces/index.d.ts +0 -9
  518. package/src/interfaces/index.js +0 -4
@@ -0,0 +1,1860 @@
1
+ import { PdfPage } from './../pdf-page';
2
+ import { _PdfStreamWriter } from './pdf-stream-writer';
3
+ import { _floatToString, _addProcSet, _reverseMapBlendMode, _mapBlendMode, _getNewGuidString, _getBezierArc, _numberToString, _bytesToString, _stringToUnicodeArray } from './../utils';
4
+ import { _PdfDictionary, _PdfReference, _PdfName } from './../pdf-primitives';
5
+ import { PdfTrueTypeFont } from './../fonts/pdf-standard-font';
6
+ import { _PdfStringLayouter, _LineType, _StringTokenizer } from './../fonts/string-layouter';
7
+ import { PdfTextAlignment, PdfTextDirection, PdfSubSuperScript, PdfBlendMode, PdfLineJoin, PdfLineCap, PdfDashStyle, PdfFillMode } from './../enumerator';
8
+ import { PdfVerticalAlignment } from './../fonts/pdf-string-format';
9
+ import { PdfTemplate } from './pdf-template';
10
+ import { _PdfPath, _PathPointType } from './pdf-path';
11
+ import { _UnicodeTrueTypeFont } from '../fonts/unicode-true-type-font';
12
+ import { _RtlRenderer } from './../graphics/rightToLeft/text-renderer';
13
+ import { PdfImage } from './images/pdf-image';
14
+ /**
15
+ * Represents a graphics from a PDF page.
16
+ * ```typescript
17
+ * // Load an existing PDF document
18
+ * let document: PdfDocument = new PdfDocument(data, password);
19
+ * // Access first page
20
+ * let page: PdfPage = document.getPage(0);
21
+ * // Gets the graphics of the PDF page
22
+ * let graphics: PdfGraphics = page.graphics;
23
+ * //Create a new pen.
24
+ * let pen: PdfPen = new PdfPen([0, 0, 0], 1);
25
+ * //Draw line on the page graphics.
26
+ * graphics.drawLine(pen, 10, 10, 100, 100);
27
+ * // Save the document
28
+ * document.save('output.pdf');
29
+ * // Destroy the document
30
+ * document.destroy();
31
+ * ```
32
+ */
33
+ var PdfGraphics = /** @class */ (function () {
34
+ function PdfGraphics(size, content, xref, source) {
35
+ this._pendingResource = []; // eslint-disable-line
36
+ this._hasResourceReference = false;
37
+ if (source instanceof PdfPage) {
38
+ this._source = source._pageDictionary;
39
+ this._page = source;
40
+ }
41
+ else if (source instanceof PdfTemplate) {
42
+ this._source = source._content.dictionary;
43
+ this._template = source;
44
+ }
45
+ if (this._source && this._source.has('Resources')) {
46
+ var obj = this._source.getRaw('Resources'); // eslint-disable-line
47
+ if (obj instanceof _PdfReference) {
48
+ this._hasResourceReference = true;
49
+ this._resourceObject = xref._fetch(obj);
50
+ }
51
+ else if (obj instanceof _PdfDictionary) {
52
+ this._resourceObject = obj;
53
+ }
54
+ }
55
+ else {
56
+ this._resourceObject = new _PdfDictionary();
57
+ this._source.update('Resources', this._resourceObject);
58
+ }
59
+ this._crossReference = xref;
60
+ this._sw = new _PdfStreamWriter(content);
61
+ this._size = size;
62
+ _addProcSet('PDF', this._resourceObject);
63
+ this._initialize();
64
+ }
65
+ Object.defineProperty(PdfGraphics.prototype, "_matrix", {
66
+ get: function () {
67
+ if (typeof this._m === 'undefined') {
68
+ this._m = new _PdfTransformationMatrix();
69
+ }
70
+ return this._m;
71
+ },
72
+ enumerable: true,
73
+ configurable: true
74
+ });
75
+ Object.defineProperty(PdfGraphics.prototype, "_resources", {
76
+ get: function () {
77
+ var _this = this;
78
+ if (typeof this._resourceMap === 'undefined') {
79
+ this._resourceMap = new Map();
80
+ if (this._resourceObject.has('Font')) {
81
+ var fonts = this._resourceObject.get('Font');
82
+ if (fonts && fonts.size > 0) {
83
+ fonts.forEach(function (key, value) {
84
+ if (value !== null && typeof value !== 'undefined' && value instanceof _PdfReference) {
85
+ _this._resourceMap.set(value, _PdfName.get(key));
86
+ }
87
+ });
88
+ }
89
+ }
90
+ if (this._resourceObject.has('XObject')) {
91
+ var other = this._resourceObject.get('XObject');
92
+ if (other && other.size > 0) {
93
+ other.forEach(function (key, value) {
94
+ if (value !== null && typeof value !== 'undefined' && value instanceof _PdfReference) {
95
+ _this._resourceMap.set(value, _PdfName.get(key));
96
+ }
97
+ });
98
+ }
99
+ }
100
+ if (this._resourceObject.has('ExtGState')) {
101
+ var state = this._resourceObject.get('ExtGState');
102
+ if (state && state.size > 0) {
103
+ if (!this._transparencies) {
104
+ this._transparencies = new Map();
105
+ }
106
+ state.forEach(function (key, value) {
107
+ if (value !== null && typeof value !== 'undefined' && value instanceof _PdfReference) {
108
+ _this._setTransparencyData(value, _PdfName.get(key));
109
+ }
110
+ });
111
+ }
112
+ }
113
+ }
114
+ return this._resourceMap;
115
+ },
116
+ enumerable: true,
117
+ configurable: true
118
+ });
119
+ /**
120
+ * Save the current graphics state.
121
+ *
122
+ * @returns {PdfGraphicsState} graphics state.
123
+ * ```typescript
124
+ * // Load an existing PDF document
125
+ * let document: PdfDocument = new PdfDocument(data, password);
126
+ * // Access first page
127
+ * let page: PdfPage = document.getPage(0);
128
+ * // Gets the graphics of the PDF page
129
+ * let graphics: PdfGraphics = page.graphics;
130
+ * // Create a new font
131
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
132
+ * // Save the graphics
133
+ * let state: PdfGraphicsState = graphics.save();
134
+ * //Set graphics translate transform.
135
+ * graphics.translateTransform(100, 100);
136
+ * //Draws the String.
137
+ * graphics.drawString("Hello world!", font, [10, 20, 100, 200], undefined, new PdfBrush([0, 0, 255]));
138
+ * //Restore the graphics.
139
+ * graphics.restore(state);
140
+ * // Save the document
141
+ * document.save('output.pdf');
142
+ * // Destroy the document
143
+ * document.destroy();
144
+ * ```
145
+ */
146
+ PdfGraphics.prototype.save = function () {
147
+ var state = new PdfGraphicsState(this, this._matrix);
148
+ state._textRenderingMode = this._textRenderingMode;
149
+ state._charSpacing = this._characterSpacing;
150
+ state._textScaling = this._textScaling;
151
+ state._wordSpacing = this._wordSpacing;
152
+ state._currentBrush = this._currentBrush;
153
+ state._currentPen = this._currentPen;
154
+ state._currentFont = this._currentFont;
155
+ this._graphicsState.push(state);
156
+ this._sw._saveGraphicsState();
157
+ return state;
158
+ };
159
+ /**
160
+ * Restore the graphics state.
161
+ *
162
+ * @param {PdfGraphicsState} state graphics state.
163
+ * @returns {void} restore of the graphics state.
164
+ * ```typescript
165
+ * // Load an existing PDF document
166
+ * let document: PdfDocument = new PdfDocument(data, password);
167
+ * // Access first page
168
+ * let page: PdfPage = document.getPage(0);
169
+ * // Gets the graphics of the PDF page
170
+ * let graphics: PdfGraphics = page.graphics;
171
+ * // Create a new font
172
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
173
+ * // Save the graphics
174
+ * let state: PdfGraphicsState = graphics.save();
175
+ * //Set graphics translate transform.
176
+ * graphics.translateTransform(100, 100);
177
+ * //Draws the String.
178
+ * graphics.drawString("Hello world!", font, [10, 20, 100, 200], undefined, new PdfBrush([0, 0, 255]));
179
+ * //Restore the graphics.
180
+ * graphics.restore(state);
181
+ * // Save the document
182
+ * document.save('output.pdf');
183
+ * // Destroy the document
184
+ * document.destroy();
185
+ * ```
186
+ */
187
+ PdfGraphics.prototype.restore = function (state) {
188
+ if (this._graphicsState.length > 0) {
189
+ if (typeof state === 'undefined') {
190
+ this._doRestore();
191
+ }
192
+ else {
193
+ if (this._graphicsState.length > 0 && this._graphicsState.indexOf(state) !== -1) {
194
+ while (this._graphicsState.length > 0) {
195
+ if (this._doRestore() === state) {
196
+ break;
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ };
203
+ PdfGraphics.prototype._doRestore = function () {
204
+ var state = this._graphicsState.pop();
205
+ this._m = state._transformationMatrix;
206
+ this._currentBrush = state._currentBrush;
207
+ this._currentPen = state._currentPen;
208
+ this._currentFont = state._currentFont;
209
+ this._characterSpacing = state._charSpacing;
210
+ this._wordSpacing = state._wordSpacing;
211
+ this._textScaling = state._textScaling;
212
+ this._textRenderingMode = state._textRenderingMode;
213
+ this._sw._restoreGraphicsState();
214
+ return state;
215
+ };
216
+ PdfGraphics.prototype.drawRectangle = function (x, y, width, height, first, second) {
217
+ var pen;
218
+ var brush;
219
+ if (first instanceof PdfPen) {
220
+ pen = first;
221
+ if (second) {
222
+ brush = second;
223
+ }
224
+ }
225
+ else {
226
+ brush = first;
227
+ }
228
+ this._stateControl(pen, brush);
229
+ this._sw._appendRectangle(x, y, width, height);
230
+ this._drawGraphicsPath(pen, brush);
231
+ };
232
+ PdfGraphics.prototype.drawPolygon = function (points, first, second) {
233
+ if (points.length > 0) {
234
+ var pen = void 0;
235
+ var brush = void 0;
236
+ if (first instanceof PdfPen) {
237
+ pen = first;
238
+ if (second) {
239
+ brush = second;
240
+ }
241
+ }
242
+ else {
243
+ brush = first;
244
+ }
245
+ this._stateControl(pen, brush);
246
+ this._sw._beginPath(points[0][0], points[0][1]);
247
+ for (var i = 1; i < points.length; i++) {
248
+ this._sw._appendLineSegment(points[Number.parseInt(i.toString(), 10)][0], points[Number.parseInt(i.toString(), 10)][1]);
249
+ }
250
+ this._drawGraphicsPath(pen, brush, PdfFillMode.winding, true);
251
+ }
252
+ };
253
+ PdfGraphics.prototype.drawEllipse = function (x, y, width, height, first, second) {
254
+ var pen;
255
+ var brush;
256
+ if (first instanceof PdfPen) {
257
+ pen = first;
258
+ if (second) {
259
+ brush = second;
260
+ }
261
+ }
262
+ else {
263
+ brush = first;
264
+ }
265
+ this._stateControl(pen, brush);
266
+ this._constructArcPath(x, y, x + width, y + height, 0, 360);
267
+ this._drawGraphicsPath(pen, brush, PdfFillMode.winding, true);
268
+ };
269
+ /**
270
+ * Draw arc on the page graphics.
271
+ *
272
+ * @param {number} x value.
273
+ * @param {number} y value.
274
+ * @param {number} width value.
275
+ * @param {number} height value.
276
+ * @param {number} startAngle value.
277
+ * @param {number} sweepAngle value.
278
+ * @param {PdfPen} pen value.
279
+ * @returns {void} draw a arc.
280
+ * ```typescript
281
+ * // Load an existing PDF document
282
+ * let document: PdfDocument = new PdfDocument(data, password);
283
+ * // Access first page
284
+ * let page: PdfPage = document.getPage(0);
285
+ * // Gets the graphics of the PDF page
286
+ * let graphics: PdfGraphics = page.graphics;
287
+ * //Create a new pen.
288
+ * let pen: PdfPen = new PdfPen([0, 0, 0], 1);
289
+ * //Draw arc on the page graphics.
290
+ * graphics.drawArc(10, 20, 100, 200, 20, 30, pen);
291
+ * // Save the document
292
+ * document.save('output.pdf');
293
+ * // Destroy the document
294
+ * document.destroy();
295
+ * ```
296
+ */
297
+ PdfGraphics.prototype.drawArc = function (x, y, width, height, startAngle, sweepAngle, pen) {
298
+ if (sweepAngle !== 0) {
299
+ this._stateControl(pen);
300
+ this._constructArcPath(x, y, x + width, y + height, startAngle, sweepAngle);
301
+ this._drawGraphicsPath(pen, null, PdfFillMode.winding, false);
302
+ }
303
+ };
304
+ PdfGraphics.prototype.drawImage = function (arg1, arg2, arg3, arg4, arg5) {
305
+ if (typeof arg2 === 'number' && typeof arg3 === 'number' && typeof arg4 === 'undefined') {
306
+ var size = arg1.physicalDimension;
307
+ this.drawImage(arg1, arg2, arg3, size[0], size[1]);
308
+ }
309
+ else {
310
+ arg1._save();
311
+ var matrix = new _PdfTransformationMatrix();
312
+ this._getTranslateTransform(arg2, (arg3 + arg5), matrix);
313
+ this._getScaleTransform(arg4, arg5, matrix);
314
+ this._sw._write('q');
315
+ this._sw._modifyCtm(matrix);
316
+ var sourceDictionary = void 0;
317
+ var keyName = void 0;
318
+ var isNew = true;
319
+ if (this._resourceObject.has('XObject')) {
320
+ var obj = this._resourceObject.getRaw('XObject'); // eslint-disable-line
321
+ if (obj instanceof _PdfDictionary) {
322
+ sourceDictionary = obj;
323
+ }
324
+ if (sourceDictionary) {
325
+ isNew = false;
326
+ }
327
+ }
328
+ if (isNew) {
329
+ sourceDictionary = new _PdfDictionary(this._crossReference);
330
+ this._resourceObject.update('XObject', sourceDictionary);
331
+ }
332
+ if (typeof keyName === 'undefined') {
333
+ keyName = _PdfName.get(_getNewGuidString());
334
+ }
335
+ if (this._crossReference) {
336
+ this._updateImageResource(arg1, keyName, sourceDictionary, this._crossReference);
337
+ this._source.update('Resources', this._resourceObject);
338
+ this._source._updated = true;
339
+ }
340
+ else {
341
+ this._pendingResource.push({ 'resource': arg1, 'key': keyName, 'source': sourceDictionary });
342
+ }
343
+ this._sw._executeObject(keyName);
344
+ this._sw._write('Q');
345
+ this._sw._write('\r\n');
346
+ _addProcSet('ImageB', this._resourceObject);
347
+ _addProcSet('ImageC', this._resourceObject);
348
+ _addProcSet('ImageI', this._resourceObject);
349
+ _addProcSet('Text', this._resourceObject);
350
+ }
351
+ };
352
+ PdfGraphics.prototype._processResources = function (crossReference) {
353
+ if (this._pendingResource.length > 0) {
354
+ for (var i = 0; i < this._pendingResource.length; i++) {
355
+ var entry = this._pendingResource[Number.parseInt(i.toString(), 10)]; // eslint-disable-line
356
+ if (entry.resource instanceof PdfImage) {
357
+ this._updateImageResource(entry.resource, entry.key, entry.source, crossReference);
358
+ }
359
+ this._source.update('Resources', this._resourceObject);
360
+ this._source._updated = true;
361
+ }
362
+ this._pendingResource = [];
363
+ }
364
+ };
365
+ PdfGraphics.prototype._updateImageResource = function (image, keyName, source, crossReference) {
366
+ var ref;
367
+ if (image._reference) {
368
+ ref = image._reference;
369
+ }
370
+ else {
371
+ ref = crossReference._getNextReference();
372
+ image._reference = ref;
373
+ }
374
+ if (!crossReference._cacheMap.has(ref)) {
375
+ if (image && image._imageStream && image._imageStream.dictionary) {
376
+ crossReference._cacheMap.set(ref, image._imageStream);
377
+ image._imageStream.dictionary._updated = true;
378
+ }
379
+ }
380
+ source.update(keyName.name, ref);
381
+ this._resources.set(ref, keyName);
382
+ this._resourceObject._updated = true;
383
+ };
384
+ PdfGraphics.prototype._drawTemplate = function (template, bounds) {
385
+ var _this = this;
386
+ var scaleX = (template && template._size[0] > 0) ? bounds.width / template._size[0] : 1;
387
+ var scaleY = (template && template._size[1] > 0) ? bounds.height / template._size[1] : 1;
388
+ var needScale = !(scaleX === 1 && scaleY === 1);
389
+ var cropBox;
390
+ var mediaBox;
391
+ if (this._page) {
392
+ cropBox = this._page.cropBox;
393
+ mediaBox = this._page.mediaBox;
394
+ if (this._page._pageDictionary.has('CropBox') && this._page._pageDictionary.has('MediaBox')) {
395
+ if (cropBox[0] > 0 && cropBox[1] > 0 && mediaBox[0] < 0 && mediaBox[1] < 0) {
396
+ this.translateTransform(cropBox[0], -cropBox[1]);
397
+ bounds.x = -cropBox[0];
398
+ bounds.y = cropBox[1];
399
+ }
400
+ }
401
+ }
402
+ var state = this.save();
403
+ var matrix = new _PdfTransformationMatrix();
404
+ if (this._page) {
405
+ var needTransform = (this._page._pageDictionary.has('CropBox') &&
406
+ this._page._pageDictionary.has('MediaBox') && cropBox && mediaBox &&
407
+ cropBox[0] === mediaBox[0] && cropBox[1] === mediaBox[1] && cropBox[2] === mediaBox[2] && cropBox[3] === mediaBox[3]) ||
408
+ (this._page._pageDictionary.has('MediaBox') && mediaBox && mediaBox[3] === 0);
409
+ matrix._translate(bounds.x, -(bounds.y + ((this._page._origin[0] >= 0 || needTransform) ? bounds.height : 0)));
410
+ }
411
+ else {
412
+ matrix._translate(bounds.x, -(bounds.y + bounds.height));
413
+ }
414
+ if (needScale) {
415
+ if (template._isAnnotationTemplate && template._needScale) {
416
+ var scaleApplied = false;
417
+ if (template._content && template._content.dictionary) {
418
+ var dictionary = template._content.dictionary;
419
+ if (dictionary.has('Matrix') && dictionary.has('BBox')) {
420
+ var templateMatrix = dictionary.getArray('Matrix');
421
+ var templateBox = dictionary.getArray('BBox');
422
+ if (templateMatrix && templateBox && templateMatrix.length > 5 && templateBox.length > 3) {
423
+ var templateScaleX = Number.parseFloat(_numberToString(-templateMatrix[1]));
424
+ var templateScaleY = Number.parseFloat(_numberToString(templateMatrix[2]));
425
+ var roundScaleX = Number.parseFloat(_numberToString(scaleX));
426
+ var roundScaleY = Number.parseFloat(_numberToString(scaleY));
427
+ if (roundScaleX === templateScaleX &&
428
+ roundScaleY === templateScaleY &&
429
+ templateBox[2] === template._size[0] &&
430
+ templateBox[3] === template._size[1]) {
431
+ matrix = new _PdfTransformationMatrix();
432
+ matrix._translate(bounds.x - templateMatrix[4], bounds.y + templateMatrix[5]);
433
+ matrix._scale(1, 1);
434
+ scaleApplied = true;
435
+ }
436
+ }
437
+ }
438
+ }
439
+ if (!scaleApplied) {
440
+ matrix._scale(scaleX, scaleY);
441
+ }
442
+ }
443
+ else {
444
+ matrix._scale(scaleX, scaleY);
445
+ }
446
+ }
447
+ this._sw._modifyCtm(matrix);
448
+ var sourceDictionary;
449
+ var isReference = false;
450
+ var keyName;
451
+ var isNew = true;
452
+ var ref;
453
+ if (this._resourceObject.has('XObject')) {
454
+ var obj = this._resourceObject.getRaw('XObject'); // eslint-disable-line
455
+ if (obj instanceof _PdfReference) {
456
+ isReference = true;
457
+ sourceDictionary = this._crossReference._fetch(obj);
458
+ }
459
+ else if (obj instanceof _PdfDictionary) {
460
+ sourceDictionary = obj;
461
+ }
462
+ if (sourceDictionary) {
463
+ isNew = false;
464
+ this._resources.forEach(function (value, key) {
465
+ if (key && key instanceof _PdfReference) {
466
+ var base = _this._crossReference._fetch(key);
467
+ if (base && template && base === template._content) {
468
+ keyName = value;
469
+ ref = key;
470
+ }
471
+ }
472
+ });
473
+ }
474
+ }
475
+ if (isNew) {
476
+ sourceDictionary = new _PdfDictionary(this._crossReference);
477
+ this._resourceObject.update('XObject', sourceDictionary);
478
+ }
479
+ if (typeof keyName === 'undefined') {
480
+ keyName = _PdfName.get(_getNewGuidString());
481
+ if (template && template._content.reference) {
482
+ ref = template._content.reference;
483
+ }
484
+ else {
485
+ ref = this._crossReference._getNextReference();
486
+ }
487
+ if (!this._crossReference._cacheMap.has(ref)) {
488
+ if (template && template._content) {
489
+ this._crossReference._cacheMap.set(ref, template._content);
490
+ }
491
+ }
492
+ sourceDictionary.update(keyName.name, ref);
493
+ this._resources.set(ref, keyName);
494
+ this._resourceObject._updated = true;
495
+ }
496
+ if (isReference) {
497
+ this._resourceObject._updated = true;
498
+ }
499
+ if (this._hasResourceReference) {
500
+ this._source._updated = true;
501
+ }
502
+ this._sw._executeObject(keyName);
503
+ this.restore(state);
504
+ _addProcSet('ImageB', this._resourceObject);
505
+ _addProcSet('ImageC', this._resourceObject);
506
+ _addProcSet('ImageI', this._resourceObject);
507
+ _addProcSet('Text', this._resourceObject);
508
+ };
509
+ PdfGraphics.prototype._drawPath = function (path, pen, brush) {
510
+ if (pen || brush) {
511
+ this._stateControl(pen, brush, null);
512
+ this._buildUpPath(path._points, path._pathTypes);
513
+ this._drawGraphicsPath(pen, brush, path._fillMode, false);
514
+ }
515
+ };
516
+ /**
517
+ * Draw rounded rectangle on the page graphics.
518
+ *
519
+ * @param {number} x value.
520
+ * @param {number} y value.
521
+ * @param {number} width value.
522
+ * @param {number} height value.
523
+ * @param {number} radius value.
524
+ * @param {PdfPen} pen value.
525
+ * @param {PdfBrush} brush value.
526
+ * @returns {void} draw a rounded rectangle.
527
+ * ```typescript
528
+ * // Load an existing PDF document
529
+ * let document: PdfDocument = new PdfDocument(data, password);
530
+ * // Access first page
531
+ * let page: PdfPage = document.getPage(0);
532
+ * // Gets the graphics of the PDF page
533
+ * let graphics: PdfGraphics = page.graphics;
534
+ * //Create a new pen.
535
+ * let pen: PdfPen = new PdfPen([0, 0, 0], 1);
536
+ * //Create a new brush.
537
+ * let brush: PdfBrush = new PdfBrush([0, 0, 255]);
538
+ * //Draw rounded rectangle on the page graphics.
539
+ * graphics.drawRoundedRectangle(10, 20, 100, 200, 5, pen, brush);
540
+ * // Save the document
541
+ * document.save('output.pdf');
542
+ * // Destroy the document
543
+ * document.destroy();
544
+ * ```
545
+ */
546
+ PdfGraphics.prototype.drawRoundedRectangle = function (x, y, width, height, radius, pen, brush) {
547
+ if (pen === null) {
548
+ throw new Error('pen');
549
+ }
550
+ if (brush === null) {
551
+ throw new Error('brush');
552
+ }
553
+ var bounds = [x, y, width, height];
554
+ var diameter = radius * 2;
555
+ var size = [diameter, diameter];
556
+ var arc = [bounds[0], bounds[1], size[0], size[1]];
557
+ var path = new _PdfPath();
558
+ if (radius === 0) {
559
+ path._addRectangle(bounds[0], bounds[1], bounds[2], bounds[3]);
560
+ this._drawPath(path, pen, brush);
561
+ }
562
+ else {
563
+ path._isRoundedRectangle = true;
564
+ path._addArc(arc[0], arc[1], arc[2], arc[3], 180, 90);
565
+ arc[0] = (bounds[0] + bounds[2]) - diameter;
566
+ path._addArc(arc[0], arc[1], arc[2], arc[3], 270, 90);
567
+ arc[1] = (bounds[1] + bounds[3]) - diameter;
568
+ path._addArc(arc[0], arc[1], arc[2], arc[3], 0, 90);
569
+ arc[0] = bounds[0];
570
+ path._addArc(arc[0], arc[1], arc[2], arc[3], 90, 90);
571
+ path._closeFigure();
572
+ this._drawPath(path, pen, brush);
573
+ }
574
+ };
575
+ PdfGraphics.prototype._constructArcPath = function (x1, y1, x2, y2, start, sweep) {
576
+ var points = _getBezierArc(x1, y1, x2, y2, start, sweep);
577
+ if (points.length === 8) {
578
+ return;
579
+ }
580
+ var point = [points[0], points[1], points[2], points[3], points[4], points[5], points[6], points[7]];
581
+ this._sw._beginPath(point[0], point[1]);
582
+ for (var i = 0; i < points.length; i = i + 8) {
583
+ point = [points[Number.parseInt(i.toString(), 10)],
584
+ points[i + 1],
585
+ points[i + 2],
586
+ points[i + 3],
587
+ points[i + 4],
588
+ points[i + 5],
589
+ points[i + 6],
590
+ points[i + 7]];
591
+ this._sw._appendBezierSegment(point[2], point[3], point[4], point[5], point[6], point[7]);
592
+ }
593
+ };
594
+ PdfGraphics.prototype._writePen = function (pen) {
595
+ var lineWidth = pen._width;
596
+ var pattern = pen._dashPattern;
597
+ for (var i = 0; i < pattern.length; ++i) {
598
+ pattern[i] *= pen._width; // eslint-disable-line
599
+ }
600
+ this._sw._setLineDashPattern(pattern, pen._dashOffset * lineWidth);
601
+ this._sw._setLineWidth(pen._width);
602
+ this._sw._setLineJoin(pen._lineJoin);
603
+ this._sw._setLineCap(pen._lineCap);
604
+ if (pen._miterLimit > 0) {
605
+ this._sw._setMiterLimit(pen._miterLimit);
606
+ }
607
+ this._sw._setColor(pen._color, true);
608
+ };
609
+ /**
610
+ * Draw text on the page graphics.
611
+ *
612
+ * @param {string} value draw string.
613
+ * @param {PdfFont} font value.
614
+ * @param {number[]} bounds value.
615
+ * @param {PdfPen} pen value.
616
+ * @param {PdfBrush} brush value.
617
+ * @param {PdfStringFormat} format value.
618
+ * @returns {void} draw a string.
619
+ * ```typescript
620
+ * // Load an existing PDF document
621
+ * let document: PdfDocument = new PdfDocument(data, password);
622
+ * // Access first page
623
+ * let page: PdfPage = document.getPage(0);
624
+ * // Gets the graphics of the PDF page
625
+ * let graphics: PdfGraphics = page.graphics;
626
+ * // Create a new pen.
627
+ * let pen: PdfPen = new PdfPen([0, 0, 0], 1);
628
+ * // Create a new font.
629
+ * let font: PdfStandardFont = new PdfStandardFont(PdfFontFamily.symbol, 10);
630
+ * // Create a new string format
631
+ * let format: PdfStringFormat = new PdfStringFormat();
632
+ * format.alignment = PdfTextAlignment.center;
633
+ * // Draw text on the page graphics.
634
+ * graphics.drawString('Hello World', font, [10, 20, 100, 200], pen, new PdfBrush([0, 0, 255]), format);
635
+ * // Save the document
636
+ * document.save('output.pdf');
637
+ * // Destroy the document
638
+ * document.destroy();
639
+ * ```
640
+ */
641
+ PdfGraphics.prototype.drawString = function (value, font, bounds, pen, brush, format) {
642
+ var layouter = new _PdfStringLayouter();
643
+ var result = layouter._layout(value, font, format, [bounds[2], bounds[3]]);
644
+ if (!result._empty) {
645
+ var rect = this._checkCorrectLayoutRectangle(result._actualSize, bounds[0], bounds[1], format);
646
+ if (bounds[2] <= 0) {
647
+ bounds[0] = rect[0];
648
+ bounds[2] = rect[2];
649
+ }
650
+ if (bounds[3] <= 0) {
651
+ bounds[1] = rect[1];
652
+ bounds[3] = rect[3];
653
+ }
654
+ this._drawStringLayoutResult(result, font, pen, brush, bounds, format);
655
+ }
656
+ _addProcSet('Text', this._resourceObject);
657
+ };
658
+ PdfGraphics.prototype._buildUpPath = function (points, types) {
659
+ for (var i = 0; i < points.length; i++) {
660
+ var point = points[Number.parseInt(i.toString(), 10)];
661
+ var type = types[Number.parseInt(i.toString(), 10)];
662
+ switch (type & 0xf) {
663
+ case _PathPointType.start:
664
+ this._sw._beginPath(point[0], point[1]);
665
+ break;
666
+ case _PathPointType.bezier:
667
+ var result = this._getBezierPoint(points, types, i); // eslint-disable-line
668
+ i = result.index;
669
+ var first = result.point; // eslint-disable-line
670
+ result = this._getBezierPoint(points, types, i);
671
+ i = result.index;
672
+ var second = result.point; // eslint-disable-line
673
+ this._sw._appendBezierSegment(point[0], point[1], first[0], first[1], second[0], second[1]);
674
+ break;
675
+ case _PathPointType.line:
676
+ this._sw._appendLineSegment(point[0], point[1]);
677
+ break;
678
+ default:
679
+ throw new Error('Incorrect path formation.');
680
+ }
681
+ type = types[Number.parseInt(i.toString(), 10)];
682
+ if ((type & _PathPointType.closePath) === _PathPointType.closePath) {
683
+ this._sw._closePath();
684
+ }
685
+ }
686
+ };
687
+ PdfGraphics.prototype._getBezierPoint = function (points, types, index) {
688
+ if (types[Number.parseInt(index.toString(), 10)] !== _PathPointType.bezier) {
689
+ throw new Error('Malforming path.');
690
+ }
691
+ index++;
692
+ return { 'index': index, 'point': points[Number.parseInt(index.toString(), 10)] };
693
+ };
694
+ PdfGraphics.prototype._initialize = function () {
695
+ this._mediaBoxUpperRightBound = 0;
696
+ this._characterSpacing = -1;
697
+ this._wordSpacing = -1;
698
+ this._textScaling = -100;
699
+ this._textRenderingMode = -1;
700
+ this._graphicsState = [];
701
+ this._clipBounds = [0, 0, this._size[0], this._size[1]];
702
+ this._colorSpaceInitialized = false;
703
+ this._startCutIndex = -1;
704
+ };
705
+ PdfGraphics.prototype._initializeCurrentColorSpace = function () {
706
+ if (!this._colorSpaceInitialized) {
707
+ this._sw._setColorSpace('DeviceRGB', true);
708
+ this._sw._setColorSpace('DeviceRGB', false);
709
+ this._colorSpaceInitialized = true;
710
+ }
711
+ };
712
+ PdfGraphics.prototype._brushControl = function (brush) {
713
+ this._sw._setColor(brush._color, false);
714
+ this._currentBrush = brush;
715
+ };
716
+ PdfGraphics.prototype._penControl = function (pen) {
717
+ this._currentPen = pen;
718
+ this._writePen(pen);
719
+ this._currentPen = pen;
720
+ };
721
+ PdfGraphics.prototype._fontControl = function (font, format) {
722
+ var _this = this;
723
+ var size = font._metrics._getSize(format);
724
+ this._currentFont = font;
725
+ var fontDict;
726
+ var isReference = false;
727
+ var keyName;
728
+ var isNew = true;
729
+ var ref;
730
+ if (this._resourceObject.has('Font')) {
731
+ var obj = this._resourceObject.getRaw('Font'); // eslint-disable-line
732
+ if (obj !== null && typeof obj !== 'undefined') {
733
+ if (obj instanceof _PdfReference) {
734
+ isReference = true;
735
+ fontDict = this._crossReference._fetch(obj);
736
+ }
737
+ else if (obj instanceof _PdfDictionary) {
738
+ fontDict = obj;
739
+ }
740
+ }
741
+ if (typeof fontDict !== 'undefined' && fontDict !== null) {
742
+ isNew = false;
743
+ this._resources.forEach(function (value, key) {
744
+ if (key !== null && typeof key !== 'undefined') {
745
+ var dictionary = _this._crossReference._fetch(key);
746
+ if (dictionary && dictionary === font._dictionary) {
747
+ keyName = value;
748
+ ref = key;
749
+ }
750
+ }
751
+ });
752
+ }
753
+ }
754
+ if (isNew) {
755
+ fontDict = new _PdfDictionary(this._crossReference);
756
+ this._resourceObject.update('Font', fontDict);
757
+ }
758
+ if (typeof keyName === 'undefined') {
759
+ keyName = _PdfName.get(_getNewGuidString());
760
+ if (!ref) {
761
+ ref = this._crossReference._getNextReference();
762
+ }
763
+ if (font._dictionary) {
764
+ this._crossReference._cacheMap.set(ref, font._dictionary);
765
+ fontDict.update(keyName.name, ref);
766
+ this._resources.set(ref, keyName);
767
+ }
768
+ else if (font instanceof PdfTrueTypeFont) {
769
+ var internal = font._fontInternal;
770
+ if (internal && internal._fontDictionary) {
771
+ this._crossReference._cacheMap.set(ref, internal._fontDictionary);
772
+ }
773
+ fontDict.update(keyName.name, ref);
774
+ this._resources.set(ref, keyName);
775
+ }
776
+ }
777
+ if (isReference) {
778
+ this._resourceObject._updated = true;
779
+ }
780
+ if (this._hasResourceReference) {
781
+ this._source._updated = true;
782
+ }
783
+ this._sw._setFont(keyName.name, size);
784
+ };
785
+ PdfGraphics.prototype._stateControl = function (pen, brush, font, format) {
786
+ if (pen || brush) {
787
+ this._initializeCurrentColorSpace();
788
+ }
789
+ if (pen) {
790
+ this._penControl(pen);
791
+ }
792
+ if (brush) {
793
+ this._brushControl(brush);
794
+ }
795
+ if (font) {
796
+ this._fontControl(font, format);
797
+ }
798
+ };
799
+ PdfGraphics.prototype._drawStringLayoutResult = function (result, font, pen, brush, layoutRectangle, format) {
800
+ if (!result._empty) {
801
+ var allowPartialLines = (format && typeof format.lineLimit !== 'undefined' && !format.lineLimit);
802
+ var shouldClip = (typeof format === 'undefined' || (format && typeof format.noClip !== 'undefined'
803
+ && !format.noClip));
804
+ var clipRegion = allowPartialLines && shouldClip;
805
+ var state = void 0;
806
+ if (clipRegion) {
807
+ state = this.save();
808
+ var clipBounds = [layoutRectangle[0], layoutRectangle[1], result._actualSize[0], result._actualSize[1]];
809
+ if (layoutRectangle[2] > 0) {
810
+ clipBounds[2] = layoutRectangle[2];
811
+ }
812
+ if (format.lineAlignment === PdfVerticalAlignment.middle) {
813
+ clipBounds[1] += (layoutRectangle[3] - clipBounds[3]) / 2;
814
+ }
815
+ else if (format.lineAlignment === PdfVerticalAlignment.bottom) {
816
+ clipBounds[1] += (layoutRectangle[3] - clipBounds[3]);
817
+ }
818
+ this.setClip(clipBounds);
819
+ }
820
+ this._applyStringSettings(font, pen, brush, format);
821
+ var textScaling = (typeof format !== 'undefined' && format !== null) ? format.horizontalScalingFactor : 100.0;
822
+ if (textScaling !== this._textScaling) {
823
+ this._sw._setTextScaling(textScaling);
824
+ this._textScaling = textScaling;
825
+ }
826
+ var verticalAlignShift = this._getTextVerticalAlignShift(result._actualSize[1], layoutRectangle[3], format);
827
+ var height = (typeof format === 'undefined' || format === null || format.lineSpacing === 0) ?
828
+ font._metrics._getHeight(format) :
829
+ format.lineSpacing + font._metrics._getHeight(format);
830
+ var script = (format !== null && typeof format !== 'undefined' &&
831
+ format.subSuperScript === PdfSubSuperScript.subScript);
832
+ var shift = 0;
833
+ shift = (script) ? height - (font.height + font._metrics._getDescent(format)) : (height - font._metrics._getAscent(format));
834
+ if (format && format.lineAlignment === PdfVerticalAlignment.bottom) {
835
+ if (layoutRectangle[3] - result._actualSize[1] !== 0 &&
836
+ (layoutRectangle[3] - result._actualSize[1]) < (font._metrics._size / 2) - 1) {
837
+ if (Number.parseFloat(_numberToString(layoutRectangle[3])) <=
838
+ Number.parseFloat(_numberToString(font._metrics._getHeight(format)))) {
839
+ shift = -(height / font._metrics._size);
840
+ }
841
+ }
842
+ }
843
+ var matrix = new _PdfTransformationMatrix();
844
+ matrix._translate(layoutRectangle[0], (-(layoutRectangle[1] + font._metrics._getHeight(format)) -
845
+ (font._metrics._getDescent(format) > 0 ? -font._metrics._getDescent(format) : font._metrics._getDescent(format))) -
846
+ verticalAlignShift);
847
+ this._sw._modifyTM(matrix);
848
+ if (layoutRectangle[3] < font._metrics._size) {
849
+ if ((result._actualSize[1] - layoutRectangle[3]) < (font._metrics._size / 2) - 1) {
850
+ verticalAlignShift = 0;
851
+ }
852
+ }
853
+ if (verticalAlignShift !== 0) {
854
+ if (format !== null && format.lineAlignment === PdfVerticalAlignment.bottom) {
855
+ if (layoutRectangle[3] - result._actualSize[1] !== 0 &&
856
+ (layoutRectangle[3] - result._actualSize[1]) > (font._metrics._size / 2) - 1) {
857
+ verticalAlignShift -= (shift - (height - font._metrics._size)) / 2;
858
+ }
859
+ }
860
+ }
861
+ this._drawLayoutResult(result, font, format, layoutRectangle);
862
+ if (verticalAlignShift !== 0) {
863
+ this._sw._startNextLine(0, -(verticalAlignShift - result._lineHeight));
864
+ }
865
+ _addProcSet('Text', this._resourceObject);
866
+ this._sw._endText();
867
+ this._underlineStrikeoutText(brush, result, font, layoutRectangle, format);
868
+ if (clipRegion) {
869
+ this.restore(state);
870
+ }
871
+ }
872
+ };
873
+ PdfGraphics.prototype._getNextPage = function () {
874
+ var page;
875
+ var pageCount = this._crossReference._document.pageCount;
876
+ if (this._page._pageIndex < pageCount - 2) {
877
+ page = this._crossReference._document.getPage(this._page._pageIndex + 1);
878
+ }
879
+ return page;
880
+ };
881
+ PdfGraphics.prototype._applyStringSettings = function (font, pen, brush, format) {
882
+ var tm = _TextRenderingMode.fill;
883
+ if (pen != null && brush != null) {
884
+ tm = _TextRenderingMode.fillStroke;
885
+ }
886
+ else if (pen) {
887
+ tm = _TextRenderingMode.stroke;
888
+ }
889
+ else if (brush) {
890
+ tm = _TextRenderingMode.fill;
891
+ }
892
+ if (format && format.clipPath) {
893
+ tm |= _TextRenderingMode.clipFlag;
894
+ }
895
+ this._sw._beginText();
896
+ this._stateControl(pen, brush, font, format);
897
+ if (tm !== this._textRenderingMode) {
898
+ this._sw._setTextRenderingMode(tm);
899
+ this._textRenderingMode = tm;
900
+ }
901
+ var cs = (typeof format !== 'undefined' && format !== null) ? format.characterSpacing : 0;
902
+ if (cs !== this._characterSpacing) {
903
+ this._sw._setCharacterSpacing(cs);
904
+ this._characterSpacing = cs;
905
+ }
906
+ var ws = (typeof format !== 'undefined' && format !== null) ? format.wordSpacing : 0;
907
+ if (ws !== this._wordSpacing) {
908
+ this._sw._setWordSpacing(ws);
909
+ this._wordSpacing = ws;
910
+ }
911
+ };
912
+ PdfGraphics.prototype._drawLayoutResult = function (result, font, format, layoutRectangle) {
913
+ var height = (typeof format === 'undefined' || format === null || format.lineSpacing === 0) ?
914
+ font._metrics._getHeight(format) :
915
+ format.lineSpacing + font._metrics._getHeight(format);
916
+ var lines = result._lines;
917
+ var ttfFont = font;
918
+ var unicode = (ttfFont !== null && ttfFont.isUnicode);
919
+ for (var i = 0, len = lines.length; (i < len && i !== this._startCutIndex); i++) {
920
+ var lineInfo = lines[Number.parseInt(i.toString(), 10)];
921
+ var lineWidth = lineInfo._width;
922
+ var hAlignShift = this._getHorizontalAlignShift(lineWidth, layoutRectangle[2], format) +
923
+ this._getLineIndent(lineInfo, format, layoutRectangle[2], (i === 0));
924
+ if (hAlignShift !== 0) {
925
+ this._sw._startNextLine(hAlignShift, 0);
926
+ }
927
+ if (unicode) {
928
+ this._drawUnicodeLine(lineInfo, layoutRectangle[2], font, format);
929
+ }
930
+ else {
931
+ this._drawAsciiLine(lineInfo, layoutRectangle[2], format, font);
932
+ }
933
+ if ((i + 1 !== len)) {
934
+ var vAlignShift = this._getTextVerticalAlignShift(result._actualSize[1], layoutRectangle[3], format);
935
+ var matrix = new _PdfTransformationMatrix();
936
+ var baseline = ((-(layoutRectangle[1] + font._metrics._getHeight(format)) -
937
+ font._metrics._getDescent(format)) -
938
+ vAlignShift) -
939
+ (height * (i + 1));
940
+ matrix._translate(layoutRectangle[0], baseline);
941
+ this._sw._modifyTM(matrix);
942
+ }
943
+ }
944
+ };
945
+ PdfGraphics.prototype._drawUnicodeLine = function (lineInfo, width, font, format) {
946
+ var line = lineInfo._text;
947
+ var rtl = (format !== null && typeof format !== 'undefined' && format.rightToLeft);
948
+ var useWordSpace = (format !== null && typeof format !== 'undefined' && (format.wordSpacing !== 0 ||
949
+ format.alignment === PdfTextAlignment.justify));
950
+ var ttfFont = font;
951
+ var wordSpacing = this._justifyLine(lineInfo, width, format, ttfFont);
952
+ var rtlRender = new _RtlRenderer();
953
+ if (rtl || (format !== null && typeof format !== 'undefined' && format.textDirection !== PdfTextDirection.none)) {
954
+ var blocks = [];
955
+ var rightAlign = (format !== null && typeof format !== 'undefined' && format.alignment === PdfTextAlignment.right);
956
+ if (format !== null && typeof format !== 'undefined' && format.textDirection !== PdfTextDirection.none) {
957
+ blocks = rtlRender._layout(line, ttfFont, (format.textDirection === PdfTextDirection.rightToLeft) ? true : false, useWordSpace, format);
958
+ }
959
+ else {
960
+ blocks = rtlRender._layout(line, ttfFont, rightAlign, useWordSpace, format);
961
+ }
962
+ var words = [];
963
+ if (blocks.length > 1) {
964
+ if (format !== null && typeof format !== 'undefined' && format.textDirection !== PdfTextDirection.none) {
965
+ words = rtlRender._splitLayout(line, ttfFont, (format.textDirection === PdfTextDirection.rightToLeft) ? true : false, useWordSpace, format);
966
+ }
967
+ }
968
+ else {
969
+ words = [line];
970
+ }
971
+ this._drawUnicodeBlocks(blocks, words, ttfFont, format, wordSpacing);
972
+ }
973
+ else {
974
+ if (useWordSpace) {
975
+ var result = this._breakUnicodeLine(line, ttfFont, null);
976
+ var blocks = result.tokens;
977
+ var words = result.words;
978
+ this._drawUnicodeBlocks(blocks, words, ttfFont, format, wordSpacing);
979
+ }
980
+ else {
981
+ var token = this._convertToUnicode(line, ttfFont);
982
+ this._sw._showNextLineText(token, true);
983
+ }
984
+ }
985
+ };
986
+ PdfGraphics.prototype._drawUnicodeBlocks = function (blocks, words, font, format, wordSpacing) {
987
+ if (blocks !== null && typeof blocks !== 'undefined' && blocks.length > 0 && words !== null && typeof words !== 'undefined' &&
988
+ words.length > 0 && font !== null && typeof font !== 'undefined') {
989
+ this._sw._startNextLine();
990
+ var x = 0;
991
+ var xShift = 0;
992
+ var firstLineIndent = 0;
993
+ var paragraphIndent = 0;
994
+ try {
995
+ if (format !== null && typeof format !== 'undefined') {
996
+ firstLineIndent = format.firstLineIndent;
997
+ paragraphIndent = format.paragraphIndent;
998
+ format.firstLineIndent = 0;
999
+ format.paragraphIndent = 0;
1000
+ }
1001
+ var spaceWidth = font._getCharacterWidth(_StringTokenizer._whiteSpace, format) + wordSpacing;
1002
+ var characterSpacing = (format != null) ? format.characterSpacing : 0;
1003
+ var wordSpace = (format !== null && typeof format !== 'undefined' && wordSpacing === 0) ? format.wordSpacing : 0;
1004
+ spaceWidth += characterSpacing + wordSpace;
1005
+ for (var i = 0; i < blocks.length; i++) {
1006
+ var token = blocks[i]; //eslint-disable-line
1007
+ var word = words[i]; //eslint-disable-line
1008
+ var tokenWidth = 0;
1009
+ if (x !== 0) {
1010
+ this._sw._startNextLine(x, 0);
1011
+ }
1012
+ if (word.length > 0) {
1013
+ tokenWidth += font.measureString(word, format)[0];
1014
+ tokenWidth += characterSpacing;
1015
+ this._sw._showText(token);
1016
+ }
1017
+ if (i !== blocks.length - 1) {
1018
+ x = tokenWidth + spaceWidth;
1019
+ xShift += x;
1020
+ }
1021
+ }
1022
+ if (xShift > 0) {
1023
+ this._sw._startNextLine(-xShift, 0);
1024
+ }
1025
+ }
1026
+ finally {
1027
+ if (format !== null && typeof format !== 'undefined') {
1028
+ format.firstLineIndent = firstLineIndent;
1029
+ format.paragraphIndent = paragraphIndent;
1030
+ }
1031
+ }
1032
+ }
1033
+ };
1034
+ PdfGraphics.prototype._breakUnicodeLine = function (line, ttfFont, words) {
1035
+ var tokens = [];
1036
+ if (line !== null && typeof line !== 'undefined' && line.length > 0) {
1037
+ words = line.split(null);
1038
+ for (var i = 0; i < words.length; i++) {
1039
+ var word = words[i]; //eslint-disable-line
1040
+ var token = this._convertToUnicode(word, ttfFont);
1041
+ tokens[Number.parseInt(i.toString(), 10)] = token;
1042
+ }
1043
+ }
1044
+ return { tokens: tokens, words: words };
1045
+ };
1046
+ PdfGraphics.prototype._convertToUnicode = function (text, ttfFont) {
1047
+ var token = null;
1048
+ if (text !== null && typeof text !== 'undefined' && ttfFont !== null && typeof ttfFont !== 'undefined' &&
1049
+ ttfFont._fontInternal instanceof _UnicodeTrueTypeFont) {
1050
+ var ttfReader = ttfFont._fontInternal._ttfReader;
1051
+ ttfFont._setSymbols(text);
1052
+ token = ttfReader._convertString(text);
1053
+ var bytes = _stringToUnicodeArray(token);
1054
+ token = _bytesToString(bytes);
1055
+ }
1056
+ return token;
1057
+ };
1058
+ PdfGraphics.prototype._getTextVerticalAlignShift = function (textHeight, boundsHeight, format) {
1059
+ var shift = 0;
1060
+ if (boundsHeight >= 0 && (typeof format !== 'undefined' && format !== null) && format.lineAlignment !== PdfVerticalAlignment.top) {
1061
+ switch (format.lineAlignment) {
1062
+ case PdfVerticalAlignment.middle:
1063
+ shift = (boundsHeight - textHeight) / 2;
1064
+ break;
1065
+ case PdfVerticalAlignment.bottom:
1066
+ shift = boundsHeight - textHeight;
1067
+ break;
1068
+ }
1069
+ }
1070
+ return shift;
1071
+ };
1072
+ PdfGraphics.prototype._getHorizontalAlignShift = function (lineWidth, boundsWidth, format) {
1073
+ var shift = 0;
1074
+ if (boundsWidth >= 0 && (typeof format !== 'undefined' && format !== null) && format.alignment !== PdfTextAlignment.left) {
1075
+ switch (format.alignment) {
1076
+ case PdfTextAlignment.center:
1077
+ shift = (boundsWidth - lineWidth) / 2;
1078
+ break;
1079
+ case PdfTextAlignment.right:
1080
+ shift = boundsWidth - lineWidth;
1081
+ break;
1082
+ }
1083
+ }
1084
+ return shift;
1085
+ };
1086
+ PdfGraphics.prototype._getLineIndent = function (lineInfo, format, width, firstLine) {
1087
+ var lineIndent = 0;
1088
+ var firstParagraphLine = ((lineInfo._lineType & _LineType.firstParagraphLine) > 0);
1089
+ if (format && firstParagraphLine) {
1090
+ lineIndent = (firstLine) ? format.firstLineIndent : format.paragraphIndent;
1091
+ lineIndent = (width > 0) ? Math.min(width, lineIndent) : lineIndent;
1092
+ }
1093
+ return lineIndent;
1094
+ };
1095
+ PdfGraphics.prototype._drawAsciiLine = function (lineInfo, width, format, font) {
1096
+ this._justifyLine(lineInfo, width, format, font);
1097
+ var value = '';
1098
+ if (lineInfo._text.indexOf('(') !== -1 || lineInfo._text.indexOf(')') !== -1) {
1099
+ for (var i = 0; i < lineInfo._text.length; i++) {
1100
+ if (lineInfo._text[Number.parseInt(i.toString(), 10)] === '(') {
1101
+ value += '\\\('; // eslint-disable-line
1102
+ }
1103
+ else if (lineInfo._text[Number.parseInt(i.toString(), 10)] === ')') {
1104
+ value += '\\\)'; // eslint-disable-line
1105
+ }
1106
+ else {
1107
+ value += lineInfo._text[Number.parseInt(i.toString(), 10)];
1108
+ }
1109
+ }
1110
+ }
1111
+ if (value === '') {
1112
+ value = lineInfo._text;
1113
+ }
1114
+ this._sw._showNextLineText('(' + value + ')');
1115
+ };
1116
+ PdfGraphics.prototype._justifyLine = function (lineInfo, boundsWidth, format, font) {
1117
+ var line = lineInfo._text;
1118
+ var lineWidth = lineInfo._width;
1119
+ var shouldJustify = this._shouldJustify(lineInfo, boundsWidth, format, font);
1120
+ var hasWordSpacing = (format && format.wordSpacing !== 0);
1121
+ var whitespacesCount = font._getCharacterCount(line, [' ', '\t']);
1122
+ var wordSpace = 0;
1123
+ if (shouldJustify) {
1124
+ if (hasWordSpacing) {
1125
+ lineWidth -= (whitespacesCount * format.wordSpacing);
1126
+ }
1127
+ wordSpace = (boundsWidth - lineWidth) / whitespacesCount;
1128
+ this._sw._setWordSpacing(wordSpace);
1129
+ }
1130
+ else if (format && format.alignment === PdfTextAlignment.justify) {
1131
+ this._sw._setWordSpacing(0);
1132
+ }
1133
+ return wordSpace;
1134
+ };
1135
+ PdfGraphics.prototype._shouldJustify = function (lineInfo, boundsWidth, format, font) {
1136
+ var line = lineInfo._text;
1137
+ var lineWidth = lineInfo._width;
1138
+ var justifyStyle = (format && format.alignment === PdfTextAlignment.justify);
1139
+ var goodWidth = (boundsWidth >= 0 && lineWidth < boundsWidth);
1140
+ var whitespacesCount = font._getCharacterCount(line, [' ', '\t']);
1141
+ var hasSpaces = (whitespacesCount > 0 && line[0] !== ' ');
1142
+ var goodLineBreakStyle = ((lineInfo._lineType & _LineType.layoutBreak) > 0);
1143
+ return (justifyStyle && goodWidth && hasSpaces && (goodLineBreakStyle || format.alignment === PdfTextAlignment.justify));
1144
+ };
1145
+ PdfGraphics.prototype._underlineStrikeoutText = function (brush, result, font, layoutRectangle, format) {
1146
+ if (font.isUnderline || font.isStrikeout) {
1147
+ var linePen = this._createUnderlineStrikeoutPen(brush, font);
1148
+ if (typeof linePen !== 'undefined' && linePen !== null) {
1149
+ var shift = this._getTextVerticalAlignShift(result._actualSize[1], layoutRectangle[3], format);
1150
+ var underlineYOffset = layoutRectangle[1] + shift + font._metrics._getAscent(format) + 1.5 * linePen._width;
1151
+ var strikeoutYOffset = layoutRectangle[1] + shift + font._metrics._getHeight(format) / 2 + 1.5 * linePen._width;
1152
+ var lines = result._lines;
1153
+ for (var i = 0; i < result._lineCount; i++) {
1154
+ var lineInfo = lines[Number.parseInt(i.toString(), 10)];
1155
+ var lineWidth = lineInfo._width;
1156
+ var hShift = this._getHorizontalAlignShift(lineWidth, layoutRectangle[2], format);
1157
+ var lineIndent = this._getLineIndent(lineInfo, format, layoutRectangle[2], (i === 0));
1158
+ var x1 = layoutRectangle[0] + hShift;
1159
+ var x2 = (!this._shouldJustify(lineInfo, layoutRectangle[2], format, font)) ?
1160
+ x1 + lineWidth - lineIndent :
1161
+ x1 + layoutRectangle[2] - lineIndent;
1162
+ if (font.isUnderline) {
1163
+ this.drawLine(linePen, x1, underlineYOffset, x2, underlineYOffset);
1164
+ underlineYOffset += result._lineHeight;
1165
+ }
1166
+ if (font.isStrikeout) {
1167
+ this.drawLine(linePen, x1, strikeoutYOffset, x2, strikeoutYOffset);
1168
+ strikeoutYOffset += result._lineHeight;
1169
+ }
1170
+ }
1171
+ }
1172
+ }
1173
+ };
1174
+ /**
1175
+ * Draw line on the page graphics.
1176
+ *
1177
+ * @param {PdfPen} pen pen value.
1178
+ * @param {number} x1 value.
1179
+ * @param {number} y1 value.
1180
+ * @param {number} x2 value.
1181
+ * @param {number} y2 value.
1182
+ * @returns {void} draw a line.
1183
+ * ```typescript
1184
+ * // Load an existing PDF document
1185
+ * let document: PdfDocument = new PdfDocument(data, password);
1186
+ * // Access first page
1187
+ * let page: PdfPage = document.getPage(0);
1188
+ * // Gets the graphics of the PDF page
1189
+ * let graphics: PdfGraphics = page.graphics;
1190
+ * //Create a new pen.
1191
+ * let pen: PdfPen = new PdfPen([0, 0, 0], 1);
1192
+ * //Draw line on the page graphics.
1193
+ * graphics.drawLine(pen, 10, 10, 100, 100);
1194
+ * // Save the document
1195
+ * document.save('output.pdf');
1196
+ * // Destroy the document
1197
+ * document.destroy();
1198
+ * ```
1199
+ */
1200
+ PdfGraphics.prototype.drawLine = function (pen, x1, y1, x2, y2) {
1201
+ this._stateControl(pen);
1202
+ this._sw._beginPath(x1, y1);
1203
+ this._sw._appendLineSegment(x2, y2);
1204
+ this._sw._strokePath();
1205
+ _addProcSet('PDF', this._resourceObject);
1206
+ };
1207
+ PdfGraphics.prototype._createUnderlineStrikeoutPen = function (brush, font) {
1208
+ return new PdfPen(brush._color, font._metrics._size / 20);
1209
+ };
1210
+ PdfGraphics.prototype._checkCorrectLayoutRectangle = function (textSize, x, y, format) {
1211
+ var layoutedRectangle = [x, y, textSize[0], textSize[0]];
1212
+ if (format) {
1213
+ switch (format.alignment) {
1214
+ case PdfTextAlignment.center:
1215
+ layoutedRectangle[0] = layoutedRectangle[0] - layoutedRectangle[2] / 2;
1216
+ break;
1217
+ case PdfTextAlignment.right:
1218
+ layoutedRectangle[0] = layoutedRectangle[0] - layoutedRectangle[2];
1219
+ break;
1220
+ }
1221
+ switch (format.lineAlignment) {
1222
+ case PdfVerticalAlignment.middle:
1223
+ layoutedRectangle[1] = layoutedRectangle[1] - layoutedRectangle[3] / 2;
1224
+ break;
1225
+ case PdfVerticalAlignment.bottom:
1226
+ layoutedRectangle[1] = layoutedRectangle[1] - layoutedRectangle[3];
1227
+ break;
1228
+ }
1229
+ }
1230
+ return layoutedRectangle;
1231
+ };
1232
+ PdfGraphics.prototype._drawGraphicsPath = function (pen, brush, fillMode, needClosing) {
1233
+ if (typeof fillMode === 'undefined') {
1234
+ fillMode = PdfFillMode.winding;
1235
+ }
1236
+ var isBrush = (typeof brush !== 'undefined' && brush !== null);
1237
+ var isPen = (typeof pen !== 'undefined' && pen !== null);
1238
+ var isEvenOdd = fillMode === PdfFillMode.alternate;
1239
+ if (isPen && isBrush) {
1240
+ if (needClosing) {
1241
+ this._sw._closeFillStrokePath(isEvenOdd);
1242
+ }
1243
+ else {
1244
+ this._sw._fillStrokePath(isEvenOdd);
1245
+ }
1246
+ }
1247
+ else if (!isPen && !isBrush) {
1248
+ this._sw._endPath();
1249
+ }
1250
+ else if (isPen) {
1251
+ if (needClosing) {
1252
+ this._sw._closeStrokePath();
1253
+ }
1254
+ else {
1255
+ this._sw._strokePath();
1256
+ }
1257
+ }
1258
+ else {
1259
+ if (needClosing) {
1260
+ this._sw._closeFillPath(isEvenOdd);
1261
+ }
1262
+ else {
1263
+ this._sw._fillPath(isEvenOdd);
1264
+ }
1265
+ }
1266
+ };
1267
+ PdfGraphics.prototype._initializeCoordinates = function (page) {
1268
+ var cbox;
1269
+ if (page) {
1270
+ var location_1 = [0, 0];
1271
+ var needTransformation = false;
1272
+ if (page._pageDictionary.has('CropBox') && page._pageDictionary.has('MediaBox')) {
1273
+ cbox = page._pageDictionary.getArray('CropBox');
1274
+ var mbox = page._pageDictionary.getArray('MediaBox');
1275
+ if (cbox[0] === mbox[0] && cbox[1] === mbox[1] && cbox[2] === mbox[2] && cbox[3] === mbox[3]) {
1276
+ needTransformation = true;
1277
+ }
1278
+ if (cbox[0] > 0 && cbox[3] > 0 && mbox[0] < 0 && mbox[1] < 0) {
1279
+ this.translateTransform(cbox[0], -cbox[3]);
1280
+ location_1[0] = -cbox[0];
1281
+ location_1[1] = cbox[3];
1282
+ }
1283
+ else if (!page._pageDictionary.has('CropBox')) {
1284
+ needTransformation = true;
1285
+ }
1286
+ if (needTransformation) {
1287
+ this._sw._writeComment('Change co-ordinate system to left/top.');
1288
+ if (this._cropBox) {
1289
+ this.translateTransform(this._cropBox[0], -this._cropBox[3]);
1290
+ }
1291
+ else {
1292
+ if (-(page._origin[1]) < this._mediaBoxUpperRightBound || this._mediaBoxUpperRightBound === 0) {
1293
+ this.translateTransform(0, -this._size[1]);
1294
+ }
1295
+ else {
1296
+ this.translateTransform(0, -this._mediaBoxUpperRightBound);
1297
+ }
1298
+ }
1299
+ }
1300
+ }
1301
+ }
1302
+ else {
1303
+ this._sw._writeComment('Change co-ordinate system to left/top.');
1304
+ if (this._mediaBoxUpperRightBound !== (-this._size[1])) {
1305
+ if (this._cropBox) {
1306
+ cbox = this._cropBox;
1307
+ if (cbox[0] > 0 || cbox[1] > 0 || this._size[0] === cbox[2] || this._size[1] === cbox[3]) {
1308
+ this.translateTransform(cbox[0], -cbox[3]);
1309
+ }
1310
+ else {
1311
+ if (this._mediaBoxUpperRightBound === this._size[1] || this._mediaBoxUpperRightBound === 0) {
1312
+ this.translateTransform(0, -this._size[1]);
1313
+ }
1314
+ else {
1315
+ this.translateTransform(0, -this._mediaBoxUpperRightBound);
1316
+ }
1317
+ }
1318
+ }
1319
+ else {
1320
+ if (this._mediaBoxUpperRightBound === this._size[1] || this._mediaBoxUpperRightBound === 0) {
1321
+ this.translateTransform(0, -this._size[1]);
1322
+ }
1323
+ else {
1324
+ this.translateTransform(0, -this._mediaBoxUpperRightBound);
1325
+ }
1326
+ }
1327
+ }
1328
+ }
1329
+ };
1330
+ /**
1331
+ * Represents a scale transform of the graphics.
1332
+ *
1333
+ * @param {number} scaleX Scale factor in the x direction.
1334
+ * @param {number} scaleY Scale factor in the y direction.
1335
+ * @returns {void} scale transform.
1336
+ * ```typescript
1337
+ * // Load an existing PDF document
1338
+ * let document: PdfDocument = new PdfDocument(data, password);
1339
+ * // Access first page
1340
+ * let page: PdfPage = document.getPage(0);
1341
+ * // Gets the graphics of the PDF page
1342
+ * let graphics: PdfGraphics = page.graphics;
1343
+ * // Create a new font
1344
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
1345
+ * // Save the graphics
1346
+ * let state: PdfGraphicsState = graphics.save();
1347
+ * //Set graphics scale transform.
1348
+ * graphics.scaleTransform(0.5, 0.5);
1349
+ * //Draws the String.
1350
+ * graphics.drawString("Hello world!", font, [10, 20, 100, 200], undefined, new PdfBrush([0, 0, 255]));
1351
+ * //Restore the graphics.
1352
+ * graphics.restore(state);
1353
+ * // Save the document
1354
+ * document.save('output.pdf');
1355
+ * // Destroy the document
1356
+ * document.destroy();
1357
+ * ```
1358
+ */
1359
+ PdfGraphics.prototype.scaleTransform = function (scaleX, scaleY) {
1360
+ var matrix = new _PdfTransformationMatrix();
1361
+ matrix._scale(scaleX, scaleY);
1362
+ this._sw._modifyCtm(matrix);
1363
+ this._matrix._multiply(matrix);
1364
+ };
1365
+ /**
1366
+ * Represents a translate transform of the graphics.
1367
+ *
1368
+ * @param {number} x x-coordinate of the translation.
1369
+ * @param {number} y y-coordinate of the translation.
1370
+ * @returns {void} translate transform.
1371
+ * ```typescript
1372
+ * // Load an existing PDF document
1373
+ * let document: PdfDocument = new PdfDocument(data, password);
1374
+ * // Access first page
1375
+ * let page: PdfPage = document.getPage(0);
1376
+ * // Gets the graphics of the PDF page
1377
+ * let graphics: PdfGraphics = page.graphics;
1378
+ * // Create a new font
1379
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
1380
+ * // Save the graphics
1381
+ * let state: PdfGraphicsState = graphics.save();
1382
+ * //Set graphics translate transform.
1383
+ * graphics.translateTransform(100, 100);
1384
+ * //Draws the String.
1385
+ * graphics.drawString("Hello world!", font, [10, 20, 100, 200], undefined, new PdfBrush([0, 0, 255]));
1386
+ * //Restore the graphics.
1387
+ * graphics.restore(state);
1388
+ * // Save the document
1389
+ * document.save('output.pdf');
1390
+ * // Destroy the document
1391
+ * document.destroy();
1392
+ * ```
1393
+ */
1394
+ PdfGraphics.prototype.translateTransform = function (x, y) {
1395
+ var matrix = new _PdfTransformationMatrix();
1396
+ matrix._translate(x, -y);
1397
+ this._sw._modifyCtm(matrix);
1398
+ this._matrix._multiply(matrix);
1399
+ };
1400
+ /**
1401
+ * Represents a rotate transform of the graphics.
1402
+ *
1403
+ * @param {number} angle Angle of rotation in degrees
1404
+ * @returns {void} rotate transform.
1405
+ * ```typescript
1406
+ * // Load an existing PDF document
1407
+ * let document: PdfDocument = new PdfDocument(data, password);
1408
+ * // Access first page
1409
+ * let page: PdfPage = document.getPage(0);
1410
+ * // Gets the graphics of the PDF page
1411
+ * let graphics: PdfGraphics = page.graphics;
1412
+ * // Create a new font
1413
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
1414
+ * // Save the graphics
1415
+ * let state: PdfGraphicsState = graphics.save();
1416
+ * //Set graphics rotate transform.
1417
+ * graphics.rotateTransform(-90);
1418
+ * //Draws the String.
1419
+ * graphics.drawString("Hello world!", font, [10, 20, 100, 200], undefined, new PdfBrush([0, 0, 255]));
1420
+ * //Restore the graphics.
1421
+ * graphics.restore(state);
1422
+ * // Save the document
1423
+ * document.save('output.pdf');
1424
+ * // Destroy the document
1425
+ * document.destroy();
1426
+ * ```
1427
+ */
1428
+ PdfGraphics.prototype.rotateTransform = function (angle) {
1429
+ var matrix = new _PdfTransformationMatrix();
1430
+ matrix._rotate(-angle);
1431
+ this._sw._modifyCtm(matrix);
1432
+ this._matrix._multiply(matrix);
1433
+ };
1434
+ /**
1435
+ * Represents a clipping region of this graphics.
1436
+ *
1437
+ * @param {number[]} bounds Rectangle structure that represents the new clip region.
1438
+ * @param {PdfFillMode} mode Member of the PdfFillMode enumeration that specifies the filling operation to use.
1439
+ * @returns {void} clipping region.
1440
+ * ```typescript
1441
+ * // Load an existing PDF document
1442
+ * let document: PdfDocument = new PdfDocument(data, password);
1443
+ * // Access first page
1444
+ * let page: PdfPage = document.getPage(0);
1445
+ * // Gets the graphics of the PDF page
1446
+ * let graphics: PdfGraphics = page.graphics;
1447
+ * // Create a new font
1448
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
1449
+ * //Set clip.
1450
+ * graphics.setClip([0, 0, 50, 12], PdfFillMode.alternate);
1451
+ * //Draws the String.
1452
+ * graphics.drawString("Hello world!", font, [0, 0, 100, 200], undefined, new PdfBrush([0, 0, 255]));
1453
+ * // Save the document
1454
+ * document.save('output.pdf');
1455
+ * // Destroy the document
1456
+ * document.destroy();
1457
+ * ```
1458
+ */
1459
+ PdfGraphics.prototype.setClip = function (bounds, mode) {
1460
+ if (typeof mode === 'undefined') {
1461
+ mode = PdfFillMode.winding;
1462
+ }
1463
+ this._sw._appendRectangle(bounds[0], bounds[1], bounds[2], bounds[3]);
1464
+ this._sw._clipPath(mode === PdfFillMode.alternate);
1465
+ };
1466
+ /**
1467
+ * Represents a transparency of this graphics.
1468
+ *
1469
+ * @param {number} stroke transparency value.
1470
+ * @param {number} fill transparency value.
1471
+ * @param {PdfBlendMode} mode blend mode.
1472
+ * @returns {void} transparency of this graphics.
1473
+ * ```typescript
1474
+ * // Load an existing PDF document
1475
+ * let document: PdfDocument = new PdfDocument(data, password);
1476
+ * // Access first page
1477
+ * let page: PdfPage = document.getPage(0);
1478
+ * // Gets the graphics of the PDF page
1479
+ * let graphics: PdfGraphics = page.graphics;
1480
+ * // Create a new font
1481
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
1482
+ * //Set transparency.
1483
+ * graphics.setTransparency(0.5, 0.5, PdfBlendMode.multiply);
1484
+ * //Draws the String.
1485
+ * graphics.drawString("Hello world!", font, [0, 0, 100, 200], undefined, new PdfBrush([0, 0, 255]));
1486
+ * // Save the document
1487
+ * document.save('output.pdf');
1488
+ * // Destroy the document
1489
+ * document.destroy();
1490
+ * ```
1491
+ */
1492
+ PdfGraphics.prototype.setTransparency = function (stroke, fill, mode) {
1493
+ if (typeof fill === 'undefined') {
1494
+ fill = stroke;
1495
+ }
1496
+ if (typeof mode === 'undefined') {
1497
+ mode = PdfBlendMode.normal;
1498
+ }
1499
+ if (typeof this._transparencies === 'undefined') {
1500
+ this._transparencies = new Map();
1501
+ }
1502
+ var transparencyKey = 'CA:' + stroke.toString() + '_ca:' + fill.toString() + '_BM:' + mode.toString();
1503
+ var transparencyData;
1504
+ if (this._transparencies.size > 0) {
1505
+ this._transparencies.forEach(function (value, key) {
1506
+ if (value === transparencyKey) {
1507
+ transparencyData = key;
1508
+ }
1509
+ });
1510
+ }
1511
+ if (!transparencyData) {
1512
+ transparencyData = new _TransparencyData();
1513
+ var transparencyDict = new _PdfDictionary();
1514
+ transparencyDict.update('CA', stroke);
1515
+ transparencyDict.update('ca', fill);
1516
+ transparencyDict.update('BM', _reverseMapBlendMode(mode));
1517
+ var ref = this._crossReference._getNextReference();
1518
+ this._crossReference._cacheMap.set(ref, transparencyDict);
1519
+ transparencyData._dictionary = transparencyDict;
1520
+ transparencyData._key = transparencyKey;
1521
+ transparencyData._name = _PdfName.get(_getNewGuidString());
1522
+ transparencyData._reference = ref;
1523
+ var dictionary = void 0;
1524
+ var isReference = false;
1525
+ if (this._resourceObject.has('ExtGState')) {
1526
+ var obj = this._resourceObject.getRaw('ExtGState'); // eslint-disable-line
1527
+ if (obj !== null && typeof obj !== 'undefined') {
1528
+ if (obj instanceof _PdfReference) {
1529
+ isReference = true;
1530
+ dictionary = this._crossReference._fetch(obj);
1531
+ }
1532
+ else if (obj instanceof _PdfDictionary) {
1533
+ dictionary = obj;
1534
+ }
1535
+ }
1536
+ }
1537
+ else {
1538
+ dictionary = new _PdfDictionary(this._crossReference);
1539
+ this._resourceObject.update('ExtGState', dictionary);
1540
+ }
1541
+ dictionary.update(transparencyData._name.name, ref);
1542
+ if (isReference) {
1543
+ this._resourceObject._updated = true;
1544
+ }
1545
+ if (this._hasResourceReference) {
1546
+ this._source._updated = true;
1547
+ }
1548
+ }
1549
+ this._sw._setGraphicsState(transparencyData._name);
1550
+ };
1551
+ PdfGraphics.prototype._setTransparencyData = function (ref, name) {
1552
+ this._resourceMap.set(ref, name);
1553
+ var dictionary = this._crossReference._fetch(ref);
1554
+ var stroke = 0;
1555
+ var fill = 0;
1556
+ var mode = 0;
1557
+ if (dictionary.has('CA')) {
1558
+ stroke = dictionary.get('CA');
1559
+ }
1560
+ if (dictionary.has('ca')) {
1561
+ fill = dictionary.get('ca');
1562
+ }
1563
+ if (dictionary.has('ca')) {
1564
+ fill = dictionary.get('ca');
1565
+ }
1566
+ if (dictionary.has('BM')) {
1567
+ mode = _mapBlendMode(dictionary.get('BM'));
1568
+ }
1569
+ var tkey = 'CA:' + stroke.toString() + '_ca:' + fill.toString() + '_BM:' + mode.toString();
1570
+ var tdata = new _TransparencyData();
1571
+ tdata._dictionary = dictionary;
1572
+ tdata._key = tkey;
1573
+ tdata._name = name;
1574
+ tdata._reference = ref;
1575
+ this._transparencies.set(tdata, tkey);
1576
+ };
1577
+ PdfGraphics.prototype._getTranslateTransform = function (x, y, input) {
1578
+ input._translate(x, -y);
1579
+ return input;
1580
+ };
1581
+ PdfGraphics.prototype._getScaleTransform = function (x, y, input) {
1582
+ if (input === null || typeof input === 'undefined') {
1583
+ input = new _PdfTransformationMatrix();
1584
+ }
1585
+ input._scale(x, y);
1586
+ return input;
1587
+ };
1588
+ return PdfGraphics;
1589
+ }());
1590
+ export { PdfGraphics };
1591
+ var _PdfTransformationMatrix = /** @class */ (function () {
1592
+ function _PdfTransformationMatrix() {
1593
+ this._matrix = new _Matrix(1, 0, 0, 1, 0, 0);
1594
+ }
1595
+ _PdfTransformationMatrix.prototype._translate = function (x, y) {
1596
+ this._matrix._translate(x, y);
1597
+ };
1598
+ _PdfTransformationMatrix.prototype._scale = function (x, y) {
1599
+ this._matrix._elements[0] = x;
1600
+ this._matrix._elements[3] = y;
1601
+ };
1602
+ _PdfTransformationMatrix.prototype._rotate = function (angle) {
1603
+ angle = (angle * Math.PI) / 180;
1604
+ this._matrix._elements[0] = Math.cos(angle);
1605
+ this._matrix._elements[1] = Math.sin(angle);
1606
+ this._matrix._elements[2] = -Math.sin(angle);
1607
+ this._matrix._elements[3] = Math.cos(angle);
1608
+ };
1609
+ _PdfTransformationMatrix.prototype._multiply = function (matrix) {
1610
+ this._matrix._multiply(matrix._matrix);
1611
+ };
1612
+ _PdfTransformationMatrix.prototype._toString = function () {
1613
+ var builder = '';
1614
+ for (var i = 0, len = this._matrix._elements.length; i < len; i++) {
1615
+ builder += _floatToString(this._matrix._elements[Number.parseInt(i.toString(), 10)]) + ' ';
1616
+ }
1617
+ return builder;
1618
+ };
1619
+ return _PdfTransformationMatrix;
1620
+ }());
1621
+ export { _PdfTransformationMatrix };
1622
+ var _Matrix = /** @class */ (function () {
1623
+ function _Matrix(arg1, arg2, arg3, arg4, arg5, arg6) {
1624
+ if (typeof arg1 === 'undefined') {
1625
+ this._elements = [];
1626
+ }
1627
+ else if (typeof arg1 === 'number') {
1628
+ this._elements = [arg1, arg2, arg3, arg4, arg5, arg6];
1629
+ }
1630
+ else {
1631
+ this._elements = arg1;
1632
+ }
1633
+ }
1634
+ Object.defineProperty(_Matrix.prototype, "_offsetX", {
1635
+ get: function () {
1636
+ return this._elements[4];
1637
+ },
1638
+ enumerable: true,
1639
+ configurable: true
1640
+ });
1641
+ Object.defineProperty(_Matrix.prototype, "_offsetY", {
1642
+ get: function () {
1643
+ return this._elements[5];
1644
+ },
1645
+ enumerable: true,
1646
+ configurable: true
1647
+ });
1648
+ _Matrix.prototype._clone = function () {
1649
+ return new _Matrix(this._elements.slice());
1650
+ };
1651
+ _Matrix.prototype._translate = function (x, y) {
1652
+ this._elements[4] = x;
1653
+ this._elements[5] = y;
1654
+ };
1655
+ _Matrix.prototype._transform = function (points) {
1656
+ var x = points[0];
1657
+ var y = points[1];
1658
+ var x2 = x * this._elements[0] + y * this._elements[2] + this._offsetX;
1659
+ var y2 = x * this._elements[1] + y * this._elements[3] + this._offsetY;
1660
+ return [x2, y2];
1661
+ };
1662
+ _Matrix.prototype._multiply = function (matrix) {
1663
+ this._elements = [(this._elements[0] * matrix._elements[0] + this._elements[1] * matrix._elements[2]),
1664
+ (this._elements[0] * matrix._elements[1] + this._elements[1] * matrix._elements[3]),
1665
+ (this._elements[2] * matrix._elements[0] + this._elements[3] * matrix._elements[2]),
1666
+ (this._elements[2] * matrix._elements[1] + this._elements[3] * matrix._elements[3]),
1667
+ (this._offsetX * matrix._elements[0] + this._offsetY * matrix._elements[2] + matrix._offsetX),
1668
+ (this._offsetX * matrix._elements[1] + this._offsetY * matrix._elements[3] + matrix._offsetY)];
1669
+ };
1670
+ return _Matrix;
1671
+ }());
1672
+ export { _Matrix };
1673
+ /**
1674
+ * Represents a state of the graphics from a PDF page.
1675
+ * ```typescript
1676
+ * // Load an existing PDF document
1677
+ * let document: PdfDocument = new PdfDocument(data, password);
1678
+ * // Access first page
1679
+ * let page: PdfPage = document.getPage(0);
1680
+ * // Gets the graphics of the PDF page
1681
+ * let graphics: PdfGraphics = page.graphics;
1682
+ * // Create a new font
1683
+ * let font: PdfFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
1684
+ * // Save the graphics
1685
+ * let state: PdfGraphicsState = graphics.save();
1686
+ * //Set graphics translate transform.
1687
+ * graphics.translateTransform(100, 100);
1688
+ * //Draws the String.
1689
+ * graphics.drawString("Hello world!", font, [10, 20, 100, 200], undefined, new PdfBrush([0, 0, 255]));
1690
+ * //Restore the graphics.
1691
+ * graphics.restore(state);
1692
+ * // Save the document
1693
+ * document.save('output.pdf');
1694
+ * // Destroy the document
1695
+ * document.destroy();
1696
+ * ```
1697
+ */
1698
+ var PdfGraphicsState = /** @class */ (function () {
1699
+ /**
1700
+ * Initializes a new instance of the `PdfGraphicsState` class.
1701
+ *
1702
+ * @private
1703
+ * @param {PdfGraphics} graphics Graphics.
1704
+ * @param {_PdfTransformationMatrix} matrix Matrix.
1705
+ *
1706
+ */
1707
+ function PdfGraphicsState(graphics, matrix) {
1708
+ if (graphics) {
1709
+ this._g = graphics;
1710
+ this._transformationMatrix = matrix;
1711
+ }
1712
+ this._charSpacing = 0;
1713
+ this._wordSpacing = 0;
1714
+ this._textScaling = 100;
1715
+ this._textRenderingMode = _TextRenderingMode.fill;
1716
+ }
1717
+ return PdfGraphicsState;
1718
+ }());
1719
+ export { PdfGraphicsState };
1720
+ var _TransparencyData = /** @class */ (function () {
1721
+ function _TransparencyData() {
1722
+ }
1723
+ return _TransparencyData;
1724
+ }());
1725
+ export var _TextRenderingMode;
1726
+ (function (_TextRenderingMode) {
1727
+ _TextRenderingMode[_TextRenderingMode["fill"] = 0] = "fill";
1728
+ _TextRenderingMode[_TextRenderingMode["stroke"] = 1] = "stroke";
1729
+ _TextRenderingMode[_TextRenderingMode["fillStroke"] = 2] = "fillStroke";
1730
+ _TextRenderingMode[_TextRenderingMode["none"] = 3] = "none";
1731
+ _TextRenderingMode[_TextRenderingMode["clipFlag"] = 4] = "clipFlag";
1732
+ _TextRenderingMode[_TextRenderingMode["clipFill"] = 4] = "clipFill";
1733
+ _TextRenderingMode[_TextRenderingMode["clipStroke"] = 5] = "clipStroke";
1734
+ _TextRenderingMode[_TextRenderingMode["clipFillStroke"] = 6] = "clipFillStroke";
1735
+ _TextRenderingMode[_TextRenderingMode["clip"] = 7] = "clip";
1736
+ })(_TextRenderingMode || (_TextRenderingMode = {}));
1737
+ /**
1738
+ * Represents a brush for the PDF page.
1739
+ * ```typescript
1740
+ * // Load an existing PDF document
1741
+ * let document: PdfDocument = new PdfDocument(data, password);
1742
+ * // Access first page
1743
+ * let page: PdfPage = document.getPage(0);
1744
+ * // Gets the graphics of the PDF page
1745
+ * let graphics: PdfGraphics = page.graphics;
1746
+ * // Create a new brush
1747
+ * let brush: PdfBrush = new PdfBrush([0, 255, 255]);
1748
+ * // Draw a rectangle using brush
1749
+ * graphics.drawRectangle(10, 10, 100, 100, brush);
1750
+ * // Save the document
1751
+ * document.save('output.pdf');
1752
+ * // Destroy the document
1753
+ * document.destroy();
1754
+ * ```
1755
+ */
1756
+ var PdfBrush = /** @class */ (function () {
1757
+ /**
1758
+ * Initializes a new instance of the `PdfBrush` class.
1759
+ *
1760
+ * @param {number[]} color Color.
1761
+ * ```typescript
1762
+ * // Load an existing PDF document
1763
+ * let document: PdfDocument = new PdfDocument(data, password);
1764
+ * // Access first page
1765
+ * let page: PdfPage = document.getPage(0);
1766
+ * // Gets the graphics of the PDF page
1767
+ * let graphics: PdfGraphics = page.graphics;
1768
+ * // Create a new brush
1769
+ * let brush: PdfBrush = new PdfBrush([0, 255, 255]);
1770
+ * // Draw a rectangle using brush
1771
+ * graphics.drawRectangle(10, 10, 100, 100, brush);
1772
+ * // Save the document
1773
+ * document.save('output.pdf');
1774
+ * // Destroy the document
1775
+ * document.destroy();
1776
+ * ```
1777
+ */
1778
+ function PdfBrush(color) {
1779
+ this._color = typeof color !== 'undefined' ? color : [0, 0, 0];
1780
+ }
1781
+ return PdfBrush;
1782
+ }());
1783
+ export { PdfBrush };
1784
+ /**
1785
+ * Represents a pen for the PDF page.
1786
+ * ```typescript
1787
+ * // Load an existing PDF document
1788
+ * let document: PdfDocument = new PdfDocument(data, password);
1789
+ * // Access first page
1790
+ * let page: PdfPage = document.getPage(0);
1791
+ * // Gets the graphics of the PDF page
1792
+ * let graphics: PdfGraphics = page.graphics;
1793
+ * // Create a new pen
1794
+ * let pen: PdfPen = new PdfPen([0, 0, 0], 1);
1795
+ * // Draw a rectangle using pen
1796
+ * graphics.drawRectangle(150, 50, 50, 50, pen);
1797
+ * // Save the document
1798
+ * document.save('output.pdf');
1799
+ * // Destroy the document
1800
+ * document.destroy();
1801
+ * ```
1802
+ */
1803
+ var PdfPen = /** @class */ (function () {
1804
+ /**
1805
+ * Initializes a new instance of the `PdfPen` class.
1806
+ *
1807
+ * @param {number[]} color Color.
1808
+ * @param {number} width Width.
1809
+ * ```typescript
1810
+ * // Load an existing PDF document
1811
+ * let document: PdfDocument = new PdfDocument(data, password);
1812
+ * // Access first page
1813
+ * let page: PdfPage = document.getPage(0);
1814
+ * // Gets the graphics of the PDF page
1815
+ * let graphics: PdfGraphics = page.graphics;
1816
+ * // Create a new pen
1817
+ * let pen: PdfPen = new PdfPen([0, 0, 0], 1);
1818
+ * // Draw a rectangle using pen
1819
+ * graphics.drawRectangle(150, 50, 50, 50, pen);
1820
+ * // Save the document
1821
+ * document.save('output.pdf');
1822
+ * // Destroy the document
1823
+ * document.destroy();
1824
+ * ```
1825
+ */
1826
+ function PdfPen(color, width) {
1827
+ this._color = color;
1828
+ this._width = width;
1829
+ this._dashOffset = 0;
1830
+ this._dashPattern = [];
1831
+ this._dashStyle = PdfDashStyle.solid;
1832
+ this._miterLimit = 0;
1833
+ this._lineCap = PdfLineCap.flat;
1834
+ this._lineJoin = PdfLineJoin.miter;
1835
+ }
1836
+ return PdfPen;
1837
+ }());
1838
+ export { PdfPen };
1839
+ var _PdfUnitConvertor = /** @class */ (function () {
1840
+ function _PdfUnitConvertor() {
1841
+ this._horizontalResolution = 96;
1842
+ this._proportions = this._updateProportions(this._horizontalResolution);
1843
+ }
1844
+ _PdfUnitConvertor.prototype._updateProportions = function (pixel) {
1845
+ return [pixel / 2.54, pixel / 6.0, 1, pixel / 72.0, pixel, pixel / 300.0, pixel / 25.4];
1846
+ };
1847
+ _PdfUnitConvertor.prototype._convertUnits = function (value, from, to) {
1848
+ return this._convertFromPixels(this._convertToPixels(value, from), to);
1849
+ };
1850
+ _PdfUnitConvertor.prototype._convertFromPixels = function (value, to) {
1851
+ var index = to;
1852
+ return (value / this._proportions[Number.parseInt(index.toString(), 10)]);
1853
+ };
1854
+ _PdfUnitConvertor.prototype._convertToPixels = function (value, from) {
1855
+ var index = from;
1856
+ return (value * this._proportions[Number.parseInt(index.toString(), 10)]);
1857
+ };
1858
+ return _PdfUnitConvertor;
1859
+ }());
1860
+ export { _PdfUnitConvertor };