@syncfusion/ej2-pdf-export 31.1.17 → 31.2.2

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 (364) hide show
  1. package/dist/ej2-pdf-export.min.js +3 -3
  2. package/dist/ej2-pdf-export.umd.min.js +3 -3
  3. package/dist/ej2-pdf-export.umd.min.js.map +1 -1
  4. package/dist/es6/ej2-pdf-export.es2015.js +142 -23
  5. package/dist/es6/ej2-pdf-export.es2015.js.map +1 -1
  6. package/dist/es6/ej2-pdf-export.es5.js +148 -21
  7. package/dist/es6/ej2-pdf-export.es5.js.map +1 -1
  8. package/dist/global/ej2-pdf-export.min.js +3 -3
  9. package/dist/global/ej2-pdf-export.min.js.map +1 -1
  10. package/dist/global/index.d.ts +2 -2
  11. package/package.json +8 -45
  12. package/src/implementation/input-output/pdf-cross-table.js +2 -1
  13. package/src/implementation/input-output/pdf-writer.d.ts +77 -14
  14. package/src/implementation/input-output/pdf-writer.js +146 -20
  15. package/dist/ts/implementation/actions/action.d.ts +0 -50
  16. package/dist/ts/implementation/actions/action.ts +0 -76
  17. package/dist/ts/implementation/actions/index.d.ts +0 -6
  18. package/dist/ts/implementation/actions/index.ts +0 -6
  19. package/dist/ts/implementation/actions/uri-action.d.ts +0 -33
  20. package/dist/ts/implementation/actions/uri-action.ts +0 -52
  21. package/dist/ts/implementation/annotations/action-link-annotation.d.ts +0 -30
  22. package/dist/ts/implementation/annotations/action-link-annotation.ts +0 -43
  23. package/dist/ts/implementation/annotations/annotation-collection.d.ts +0 -77
  24. package/dist/ts/implementation/annotations/annotation-collection.ts +0 -159
  25. package/dist/ts/implementation/annotations/annotation.d.ts +0 -152
  26. package/dist/ts/implementation/annotations/annotation.ts +0 -241
  27. package/dist/ts/implementation/annotations/document-link-annotation.d.ts +0 -89
  28. package/dist/ts/implementation/annotations/document-link-annotation.ts +0 -118
  29. package/dist/ts/implementation/annotations/index.d.ts +0 -11
  30. package/dist/ts/implementation/annotations/index.ts +0 -11
  31. package/dist/ts/implementation/annotations/link-annotation.d.ts +0 -23
  32. package/dist/ts/implementation/annotations/link-annotation.ts +0 -32
  33. package/dist/ts/implementation/annotations/pdf-text-web-link.d.ts +0 -118
  34. package/dist/ts/implementation/annotations/pdf-text-web-link.ts +0 -268
  35. package/dist/ts/implementation/annotations/uri-annotation.d.ts +0 -48
  36. package/dist/ts/implementation/annotations/uri-annotation.ts +0 -86
  37. package/dist/ts/implementation/collections/dictionary.d.ts +0 -76
  38. package/dist/ts/implementation/collections/dictionary.ts +0 -150
  39. package/dist/ts/implementation/collections/index.d.ts +0 -7
  40. package/dist/ts/implementation/collections/index.ts +0 -7
  41. package/dist/ts/implementation/collections/object-object-pair/dictionary.d.ts +0 -62
  42. package/dist/ts/implementation/collections/object-object-pair/dictionary.ts +0 -125
  43. package/dist/ts/implementation/collections/object-object-pair/index.d.ts +0 -5
  44. package/dist/ts/implementation/collections/object-object-pair/index.ts +0 -5
  45. package/dist/ts/implementation/collections/utils.d.ts +0 -27
  46. package/dist/ts/implementation/collections/utils.ts +0 -38
  47. package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.d.ts +0 -31
  48. package/dist/ts/implementation/document/automatic-fields/automatic-field-info-collection.ts +0 -39
  49. package/dist/ts/implementation/document/automatic-fields/automatic-field-info.d.ts +0 -67
  50. package/dist/ts/implementation/document/automatic-fields/automatic-field-info.ts +0 -108
  51. package/dist/ts/implementation/document/automatic-fields/automatic-field.d.ts +0 -41
  52. package/dist/ts/implementation/document/automatic-fields/automatic-field.ts +0 -127
  53. package/dist/ts/implementation/document/automatic-fields/composite-field.d.ts +0 -46
  54. package/dist/ts/implementation/document/automatic-fields/composite-field.ts +0 -76
  55. package/dist/ts/implementation/document/automatic-fields/index.d.ts +0 -11
  56. package/dist/ts/implementation/document/automatic-fields/index.ts +0 -11
  57. package/dist/ts/implementation/document/automatic-fields/multiple-value-field.d.ts +0 -18
  58. package/dist/ts/implementation/document/automatic-fields/multiple-value-field.ts +0 -37
  59. package/dist/ts/implementation/document/automatic-fields/page-count-field.d.ts +0 -44
  60. package/dist/ts/implementation/document/automatic-fields/page-count-field.ts +0 -75
  61. package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.d.ts +0 -53
  62. package/dist/ts/implementation/document/automatic-fields/pdf-numbers-convertor.ts +0 -157
  63. package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.d.ts +0 -51
  64. package/dist/ts/implementation/document/automatic-fields/pdf-page-number-field.ts +0 -82
  65. package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.d.ts +0 -38
  66. package/dist/ts/implementation/document/automatic-fields/pdf-template-value-pair.ts +0 -60
  67. package/dist/ts/implementation/document/automatic-fields/single-value-field.d.ts +0 -15
  68. package/dist/ts/implementation/document/automatic-fields/single-value-field.ts +0 -48
  69. package/dist/ts/implementation/document/index.d.ts +0 -16
  70. package/dist/ts/implementation/document/index.ts +0 -16
  71. package/dist/ts/implementation/document/pdf-catalog.d.ts +0 -39
  72. package/dist/ts/implementation/document/pdf-catalog.ts +0 -65
  73. package/dist/ts/implementation/document/pdf-document-base.d.ts +0 -137
  74. package/dist/ts/implementation/document/pdf-document-base.ts +0 -187
  75. package/dist/ts/implementation/document/pdf-document-template.d.ts +0 -166
  76. package/dist/ts/implementation/document/pdf-document-template.ts +0 -310
  77. package/dist/ts/implementation/document/pdf-document.d.ts +0 -227
  78. package/dist/ts/implementation/document/pdf-document.ts +0 -361
  79. package/dist/ts/implementation/document/pdf-viewer-preferences.d.ts +0 -467
  80. package/dist/ts/implementation/document/pdf-viewer-preferences.ts +0 -578
  81. package/dist/ts/implementation/drawing/index.d.ts +0 -5
  82. package/dist/ts/implementation/drawing/index.ts +0 -5
  83. package/dist/ts/implementation/drawing/pdf-drawing.d.ts +0 -141
  84. package/dist/ts/implementation/drawing/pdf-drawing.ts +0 -218
  85. package/dist/ts/implementation/general/enum.d.ts +0 -21
  86. package/dist/ts/implementation/general/enum.ts +0 -21
  87. package/dist/ts/implementation/general/functions/index.d.ts +0 -6
  88. package/dist/ts/implementation/general/functions/index.ts +0 -6
  89. package/dist/ts/implementation/general/functions/pdf-function.d.ts +0 -44
  90. package/dist/ts/implementation/general/functions/pdf-function.ts +0 -66
  91. package/dist/ts/implementation/general/functions/pdf-sampled-function.d.ts +0 -25
  92. package/dist/ts/implementation/general/functions/pdf-sampled-function.ts +0 -63
  93. package/dist/ts/implementation/general/index.d.ts +0 -9
  94. package/dist/ts/implementation/general/index.ts +0 -9
  95. package/dist/ts/implementation/general/pdf-cache-collection.d.ts +0 -42
  96. package/dist/ts/implementation/general/pdf-cache-collection.ts +0 -97
  97. package/dist/ts/implementation/general/pdf-collection.d.ts +0 -26
  98. package/dist/ts/implementation/general/pdf-collection.ts +0 -41
  99. package/dist/ts/implementation/general/pdf-destination.d.ts +0 -103
  100. package/dist/ts/implementation/general/pdf-destination.ts +0 -170
  101. package/dist/ts/implementation/graphics/brushes/enum.d.ts +0 -236
  102. package/dist/ts/implementation/graphics/brushes/enum.ts +0 -237
  103. package/dist/ts/implementation/graphics/brushes/index.d.ts +0 -13
  104. package/dist/ts/implementation/graphics/brushes/index.ts +0 -13
  105. package/dist/ts/implementation/graphics/brushes/pdf-blend.d.ts +0 -105
  106. package/dist/ts/implementation/graphics/brushes/pdf-blend.ts +0 -294
  107. package/dist/ts/implementation/graphics/brushes/pdf-brush.d.ts +0 -51
  108. package/dist/ts/implementation/graphics/brushes/pdf-brush.ts +0 -63
  109. package/dist/ts/implementation/graphics/brushes/pdf-brushes.d.ts +0 -726
  110. package/dist/ts/implementation/graphics/brushes/pdf-brushes.ts +0 -2438
  111. package/dist/ts/implementation/graphics/brushes/pdf-color-blend.d.ts +0 -113
  112. package/dist/ts/implementation/graphics/brushes/pdf-color-blend.ts +0 -295
  113. package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.d.ts +0 -155
  114. package/dist/ts/implementation/graphics/brushes/pdf-gradient-brush.ts +0 -311
  115. package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.d.ts +0 -147
  116. package/dist/ts/implementation/graphics/brushes/pdf-linear-gradient-brush.ts +0 -406
  117. package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.d.ts +0 -122
  118. package/dist/ts/implementation/graphics/brushes/pdf-radial-gradient-brush.ts +0 -290
  119. package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.d.ts +0 -77
  120. package/dist/ts/implementation/graphics/brushes/pdf-solid-brush.ts +0 -107
  121. package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.d.ts +0 -161
  122. package/dist/ts/implementation/graphics/brushes/pdf-tiling-brush.ts +0 -304
  123. package/dist/ts/implementation/graphics/constants.d.ts +0 -31
  124. package/dist/ts/implementation/graphics/constants.ts +0 -31
  125. package/dist/ts/implementation/graphics/enum.d.ts +0 -413
  126. package/dist/ts/implementation/graphics/enum.ts +0 -413
  127. package/dist/ts/implementation/graphics/figures/arc.d.ts +0 -87
  128. package/dist/ts/implementation/graphics/figures/arc.ts +0 -133
  129. package/dist/ts/implementation/graphics/figures/base/draw-element.d.ts +0 -30
  130. package/dist/ts/implementation/graphics/figures/base/draw-element.ts +0 -59
  131. package/dist/ts/implementation/graphics/figures/base/element-layouter.d.ts +0 -161
  132. package/dist/ts/implementation/graphics/figures/base/element-layouter.ts +0 -260
  133. package/dist/ts/implementation/graphics/figures/base/fill-element.d.ts +0 -46
  134. package/dist/ts/implementation/graphics/figures/base/fill-element.ts +0 -72
  135. package/dist/ts/implementation/graphics/figures/base/graphics-element.d.ts +0 -16
  136. package/dist/ts/implementation/graphics/figures/base/graphics-element.ts +0 -34
  137. package/dist/ts/implementation/graphics/figures/base/index.d.ts +0 -9
  138. package/dist/ts/implementation/graphics/figures/base/index.ts +0 -9
  139. package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.d.ts +0 -40
  140. package/dist/ts/implementation/graphics/figures/base/pdf-shape-element.ts +0 -69
  141. package/dist/ts/implementation/graphics/figures/base/shape-layouter.d.ts +0 -131
  142. package/dist/ts/implementation/graphics/figures/base/shape-layouter.ts +0 -276
  143. package/dist/ts/implementation/graphics/figures/base/text-layouter.d.ts +0 -107
  144. package/dist/ts/implementation/graphics/figures/base/text-layouter.ts +0 -212
  145. package/dist/ts/implementation/graphics/figures/ellipse-part.d.ts +0 -48
  146. package/dist/ts/implementation/graphics/figures/ellipse-part.ts +0 -76
  147. package/dist/ts/implementation/graphics/figures/enum.d.ts +0 -79
  148. package/dist/ts/implementation/graphics/figures/enum.ts +0 -80
  149. package/dist/ts/implementation/graphics/figures/index.d.ts +0 -13
  150. package/dist/ts/implementation/graphics/figures/index.ts +0 -13
  151. package/dist/ts/implementation/graphics/figures/layout-element.d.ts +0 -73
  152. package/dist/ts/implementation/graphics/figures/layout-element.ts +0 -132
  153. package/dist/ts/implementation/graphics/figures/path.d.ts +0 -319
  154. package/dist/ts/implementation/graphics/figures/path.ts +0 -646
  155. package/dist/ts/implementation/graphics/figures/pdf-template.d.ts +0 -113
  156. package/dist/ts/implementation/graphics/figures/pdf-template.ts +0 -205
  157. package/dist/ts/implementation/graphics/figures/rectangle-area.d.ts +0 -64
  158. package/dist/ts/implementation/graphics/figures/rectangle-area.ts +0 -108
  159. package/dist/ts/implementation/graphics/figures/text-element.d.ts +0 -214
  160. package/dist/ts/implementation/graphics/figures/text-element.ts +0 -449
  161. package/dist/ts/implementation/graphics/fonts/enum.d.ts +0 -385
  162. package/dist/ts/implementation/graphics/fonts/enum.ts +0 -385
  163. package/dist/ts/implementation/graphics/fonts/index.d.ts +0 -16
  164. package/dist/ts/implementation/graphics/fonts/index.ts +0 -16
  165. package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.d.ts +0 -164
  166. package/dist/ts/implementation/graphics/fonts/pdf-font-metrics.ts +0 -248
  167. package/dist/ts/implementation/graphics/fonts/pdf-font.d.ts +0 -187
  168. package/dist/ts/implementation/graphics/fonts/pdf-font.ts +0 -316
  169. package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.d.ts +0 -301
  170. package/dist/ts/implementation/graphics/fonts/pdf-standard-font-metrics-factory.ts +0 -606
  171. package/dist/ts/implementation/graphics/fonts/pdf-standard-font.d.ts +0 -143
  172. package/dist/ts/implementation/graphics/fonts/pdf-standard-font.ts +0 -243
  173. package/dist/ts/implementation/graphics/fonts/pdf-string-format.d.ts +0 -321
  174. package/dist/ts/implementation/graphics/fonts/pdf-string-format.ts +0 -474
  175. package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.d.ts +0 -49
  176. package/dist/ts/implementation/graphics/fonts/pdf-true-type-font.ts +0 -165
  177. package/dist/ts/implementation/graphics/fonts/rtl/index.d.ts +0 -6
  178. package/dist/ts/implementation/graphics/fonts/rtl/index.ts +0 -6
  179. package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.d.ts +0 -62
  180. package/dist/ts/implementation/graphics/fonts/rtl/rtl-bidirectional.ts +0 -958
  181. package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.d.ts +0 -68
  182. package/dist/ts/implementation/graphics/fonts/rtl/rtl-text-shape.ts +0 -374
  183. package/dist/ts/implementation/graphics/fonts/rtl-renderer.d.ts +0 -23
  184. package/dist/ts/implementation/graphics/fonts/rtl-renderer.ts +0 -255
  185. package/dist/ts/implementation/graphics/fonts/string-layouter.d.ts +0 -254
  186. package/dist/ts/implementation/graphics/fonts/string-layouter.ts +0 -617
  187. package/dist/ts/implementation/graphics/fonts/string-tokenizer.d.ts +0 -109
  188. package/dist/ts/implementation/graphics/fonts/string-tokenizer.ts +0 -275
  189. package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.d.ts +0 -204
  190. package/dist/ts/implementation/graphics/fonts/ttf-OS2-Table.ts +0 -206
  191. package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.d.ts +0 -17
  192. package/dist/ts/implementation/graphics/fonts/ttf-apple-cmap-sub-table.ts +0 -18
  193. package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.d.ts +0 -17
  194. package/dist/ts/implementation/graphics/fonts/ttf-cmap-sub-table.ts +0 -18
  195. package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.d.ts +0 -13
  196. package/dist/ts/implementation/graphics/fonts/ttf-cmap-table.ts +0 -14
  197. package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.d.ts +0 -25
  198. package/dist/ts/implementation/graphics/fonts/ttf-glyph-header.ts +0 -26
  199. package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.d.ts +0 -25
  200. package/dist/ts/implementation/graphics/fonts/ttf-glyph-info.ts +0 -35
  201. package/dist/ts/implementation/graphics/fonts/ttf-head-table.d.ts +0 -94
  202. package/dist/ts/implementation/graphics/fonts/ttf-head-table.ts +0 -94
  203. package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.d.ts +0 -55
  204. package/dist/ts/implementation/graphics/fonts/ttf-horizontal-header-table.ts +0 -56
  205. package/dist/ts/implementation/graphics/fonts/ttf-loca-table.d.ts +0 -9
  206. package/dist/ts/implementation/graphics/fonts/ttf-loca-table.ts +0 -10
  207. package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.d.ts +0 -13
  208. package/dist/ts/implementation/graphics/fonts/ttf-long-hor-metric.ts +0 -14
  209. package/dist/ts/implementation/graphics/fonts/ttf-metrics.d.ts +0 -101
  210. package/dist/ts/implementation/graphics/fonts/ttf-metrics.ts +0 -106
  211. package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.d.ts +0 -57
  212. package/dist/ts/implementation/graphics/fonts/ttf-microsoft-cmap-sub-table.ts +0 -58
  213. package/dist/ts/implementation/graphics/fonts/ttf-name-record.d.ts +0 -33
  214. package/dist/ts/implementation/graphics/fonts/ttf-name-record.ts +0 -33
  215. package/dist/ts/implementation/graphics/fonts/ttf-name-table.d.ts +0 -22
  216. package/dist/ts/implementation/graphics/fonts/ttf-name-table.ts +0 -22
  217. package/dist/ts/implementation/graphics/fonts/ttf-post-table.d.ts +0 -41
  218. package/dist/ts/implementation/graphics/fonts/ttf-post-table.ts +0 -42
  219. package/dist/ts/implementation/graphics/fonts/ttf-reader.d.ts +0 -227
  220. package/dist/ts/implementation/graphics/fonts/ttf-reader.ts +0 -1267
  221. package/dist/ts/implementation/graphics/fonts/ttf-table-info.d.ts +0 -22
  222. package/dist/ts/implementation/graphics/fonts/ttf-table-info.ts +0 -26
  223. package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.d.ts +0 -25
  224. package/dist/ts/implementation/graphics/fonts/ttf-trimmed-cmap-sub-table.ts +0 -26
  225. package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.d.ts +0 -213
  226. package/dist/ts/implementation/graphics/fonts/unicode-true-type-font.ts +0 -592
  227. package/dist/ts/implementation/graphics/images/byte-array.d.ts +0 -74
  228. package/dist/ts/implementation/graphics/images/byte-array.ts +0 -137
  229. package/dist/ts/implementation/graphics/images/image-decoder.d.ts +0 -274
  230. package/dist/ts/implementation/graphics/images/image-decoder.ts +0 -439
  231. package/dist/ts/implementation/graphics/images/index.d.ts +0 -8
  232. package/dist/ts/implementation/graphics/images/index.ts +0 -8
  233. package/dist/ts/implementation/graphics/images/pdf-bitmap.d.ts +0 -90
  234. package/dist/ts/implementation/graphics/images/pdf-bitmap.ts +0 -110
  235. package/dist/ts/implementation/graphics/images/pdf-image.d.ts +0 -88
  236. package/dist/ts/implementation/graphics/images/pdf-image.ts +0 -132
  237. package/dist/ts/implementation/graphics/index.d.ts +0 -35
  238. package/dist/ts/implementation/graphics/index.ts +0 -46
  239. package/dist/ts/implementation/graphics/pdf-color.d.ts +0 -206
  240. package/dist/ts/implementation/graphics/pdf-color.ts +0 -484
  241. package/dist/ts/implementation/graphics/pdf-graphics.d.ts +0 -1210
  242. package/dist/ts/implementation/graphics/pdf-graphics.ts +0 -2556
  243. package/dist/ts/implementation/graphics/pdf-margins.d.ts +0 -82
  244. package/dist/ts/implementation/graphics/pdf-margins.ts +0 -124
  245. package/dist/ts/implementation/graphics/pdf-pen.d.ts +0 -237
  246. package/dist/ts/implementation/graphics/pdf-pen.ts +0 -370
  247. package/dist/ts/implementation/graphics/pdf-resources.d.ts +0 -122
  248. package/dist/ts/implementation/graphics/pdf-resources.ts +0 -300
  249. package/dist/ts/implementation/graphics/pdf-transformation-matrix.d.ts +0 -143
  250. package/dist/ts/implementation/graphics/pdf-transformation-matrix.ts +0 -246
  251. package/dist/ts/implementation/graphics/pdf-transparency.d.ts +0 -34
  252. package/dist/ts/implementation/graphics/pdf-transparency.ts +0 -93
  253. package/dist/ts/implementation/graphics/unit-convertor.d.ts +0 -72
  254. package/dist/ts/implementation/graphics/unit-convertor.ts +0 -96
  255. package/dist/ts/implementation/index.d.ts +0 -103
  256. package/dist/ts/implementation/index.ts +0 -103
  257. package/dist/ts/implementation/input-output/big-endian-writer.d.ts +0 -59
  258. package/dist/ts/implementation/input-output/big-endian-writer.ts +0 -121
  259. package/dist/ts/implementation/input-output/cross-table.d.ts +0 -21
  260. package/dist/ts/implementation/input-output/cross-table.ts +0 -21
  261. package/dist/ts/implementation/input-output/enum.d.ts +0 -16
  262. package/dist/ts/implementation/input-output/enum.ts +0 -16
  263. package/dist/ts/implementation/input-output/index.d.ts +0 -12
  264. package/dist/ts/implementation/input-output/index.ts +0 -12
  265. package/dist/ts/implementation/input-output/pdf-cross-table.d.ts +0 -259
  266. package/dist/ts/implementation/input-output/pdf-cross-table.ts +0 -536
  267. package/dist/ts/implementation/input-output/pdf-dictionary-properties.d.ts +0 -583
  268. package/dist/ts/implementation/input-output/pdf-dictionary-properties.ts +0 -586
  269. package/dist/ts/implementation/input-output/pdf-main-object-collection.d.ts +0 -120
  270. package/dist/ts/implementation/input-output/pdf-main-object-collection.ts +0 -194
  271. package/dist/ts/implementation/input-output/pdf-operators.d.ts +0 -361
  272. package/dist/ts/implementation/input-output/pdf-operators.ts +0 -363
  273. package/dist/ts/implementation/input-output/pdf-stream-writer.d.ts +0 -311
  274. package/dist/ts/implementation/input-output/pdf-stream-writer.ts +0 -681
  275. package/dist/ts/implementation/input-output/pdf-writer.d.ts +0 -122
  276. package/dist/ts/implementation/input-output/pdf-writer.ts +0 -164
  277. package/dist/ts/implementation/pages/enum.d.ts +0 -201
  278. package/dist/ts/implementation/pages/enum.ts +0 -201
  279. package/dist/ts/implementation/pages/index.d.ts +0 -17
  280. package/dist/ts/implementation/pages/index.ts +0 -17
  281. package/dist/ts/implementation/pages/page-added-event-arguments.d.ts +0 -30
  282. package/dist/ts/implementation/pages/page-added-event-arguments.ts +0 -39
  283. package/dist/ts/implementation/pages/pdf-document-page-collection.d.ts +0 -86
  284. package/dist/ts/implementation/pages/pdf-document-page-collection.ts +0 -180
  285. package/dist/ts/implementation/pages/pdf-page-base.d.ts +0 -121
  286. package/dist/ts/implementation/pages/pdf-page-base.ts +0 -181
  287. package/dist/ts/implementation/pages/pdf-page-layer-collection.d.ts +0 -99
  288. package/dist/ts/implementation/pages/pdf-page-layer-collection.ts +0 -348
  289. package/dist/ts/implementation/pages/pdf-page-layer.d.ts +0 -160
  290. package/dist/ts/implementation/pages/pdf-page-layer.ts +0 -271
  291. package/dist/ts/implementation/pages/pdf-page-settings.d.ts +0 -111
  292. package/dist/ts/implementation/pages/pdf-page-settings.ts +0 -192
  293. package/dist/ts/implementation/pages/pdf-page-size.d.ts +0 -159
  294. package/dist/ts/implementation/pages/pdf-page-size.ts +0 -162
  295. package/dist/ts/implementation/pages/pdf-page-template-element.d.ts +0 -240
  296. package/dist/ts/implementation/pages/pdf-page-template-element.ts +0 -663
  297. package/dist/ts/implementation/pages/pdf-page.d.ts +0 -153
  298. package/dist/ts/implementation/pages/pdf-page.ts +0 -235
  299. package/dist/ts/implementation/pages/pdf-section-collection.d.ts +0 -109
  300. package/dist/ts/implementation/pages/pdf-section-collection.ts +0 -187
  301. package/dist/ts/implementation/pages/pdf-section-page-collection.d.ts +0 -41
  302. package/dist/ts/implementation/pages/pdf-section-page-collection.ts +0 -61
  303. package/dist/ts/implementation/pages/pdf-section-templates.d.ts +0 -64
  304. package/dist/ts/implementation/pages/pdf-section-templates.ts +0 -96
  305. package/dist/ts/implementation/pages/pdf-section.d.ts +0 -327
  306. package/dist/ts/implementation/pages/pdf-section.ts +0 -644
  307. package/dist/ts/implementation/primitives/index.d.ts +0 -12
  308. package/dist/ts/implementation/primitives/index.ts +0 -12
  309. package/dist/ts/implementation/primitives/pdf-array.d.ts +0 -192
  310. package/dist/ts/implementation/primitives/pdf-array.ts +0 -386
  311. package/dist/ts/implementation/primitives/pdf-boolean.d.ts +0 -84
  312. package/dist/ts/implementation/primitives/pdf-boolean.ts +0 -119
  313. package/dist/ts/implementation/primitives/pdf-dictionary.d.ts +0 -362
  314. package/dist/ts/implementation/primitives/pdf-dictionary.ts +0 -513
  315. package/dist/ts/implementation/primitives/pdf-name.d.ts +0 -121
  316. package/dist/ts/implementation/primitives/pdf-name.ts +0 -218
  317. package/dist/ts/implementation/primitives/pdf-number.d.ts +0 -104
  318. package/dist/ts/implementation/primitives/pdf-number.ts +0 -165
  319. package/dist/ts/implementation/primitives/pdf-reference.d.ts +0 -223
  320. package/dist/ts/implementation/primitives/pdf-reference.ts +0 -430
  321. package/dist/ts/implementation/primitives/pdf-stream.d.ts +0 -161
  322. package/dist/ts/implementation/primitives/pdf-stream.ts +0 -306
  323. package/dist/ts/implementation/primitives/pdf-string.d.ts +0 -235
  324. package/dist/ts/implementation/primitives/pdf-string.ts +0 -397
  325. package/dist/ts/implementation/structured-elements/grid/index.d.ts +0 -4
  326. package/dist/ts/implementation/structured-elements/grid/index.ts +0 -10
  327. package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.d.ts +0 -597
  328. package/dist/ts/implementation/structured-elements/grid/layout/grid-layouter.ts +0 -2127
  329. package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.d.ts +0 -288
  330. package/dist/ts/implementation/structured-elements/grid/pdf-grid-cell.ts +0 -1225
  331. package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.d.ts +0 -108
  332. package/dist/ts/implementation/structured-elements/grid/pdf-grid-column.ts +0 -206
  333. package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.d.ts +0 -261
  334. package/dist/ts/implementation/structured-elements/grid/pdf-grid-row.ts +0 -470
  335. package/dist/ts/implementation/structured-elements/grid/pdf-grid.d.ts +0 -292
  336. package/dist/ts/implementation/structured-elements/grid/pdf-grid.ts +0 -853
  337. package/dist/ts/implementation/structured-elements/grid/styles/index.d.ts +0 -5
  338. package/dist/ts/implementation/structured-elements/grid/styles/index.ts +0 -5
  339. package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.d.ts +0 -146
  340. package/dist/ts/implementation/structured-elements/grid/styles/pdf-borders.ts +0 -238
  341. package/dist/ts/implementation/structured-elements/grid/styles/style.d.ts +0 -272
  342. package/dist/ts/implementation/structured-elements/grid/styles/style.ts +0 -423
  343. package/dist/ts/implementation/structured-elements/index.d.ts +0 -4
  344. package/dist/ts/implementation/structured-elements/index.ts +0 -10
  345. package/dist/ts/implementation/structured-elements/tables/light-tables/enum.d.ts +0 -16
  346. package/dist/ts/implementation/structured-elements/tables/light-tables/enum.ts +0 -16
  347. package/dist/ts/index.d.ts +0 -116
  348. package/dist/ts/index.ts +0 -116
  349. package/dist/ts/interfaces/i-pdf-cache.d.ts +0 -23
  350. package/dist/ts/interfaces/i-pdf-cache.ts +0 -23
  351. package/dist/ts/interfaces/i-pdf-changable.d.ts +0 -17
  352. package/dist/ts/interfaces/i-pdf-changable.ts +0 -17
  353. package/dist/ts/interfaces/i-pdf-clonable.d.ts +0 -12
  354. package/dist/ts/interfaces/i-pdf-clonable.ts +0 -12
  355. package/dist/ts/interfaces/i-pdf-primitives.d.ts +0 -45
  356. package/dist/ts/interfaces/i-pdf-primitives.ts +0 -45
  357. package/dist/ts/interfaces/i-pdf-true-type-font.d.ts +0 -18
  358. package/dist/ts/interfaces/i-pdf-true-type-font.ts +0 -48
  359. package/dist/ts/interfaces/i-pdf-wrapper.d.ts +0 -13
  360. package/dist/ts/interfaces/i-pdf-wrapper.ts +0 -13
  361. package/dist/ts/interfaces/i-pdf-writer.d.ts +0 -29
  362. package/dist/ts/interfaces/i-pdf-writer.ts +0 -29
  363. package/dist/ts/interfaces/index.d.ts +0 -10
  364. package/dist/ts/interfaces/index.ts +0 -10
@@ -1,1267 +0,0 @@
1
- /**
2
- * TtfReader.ts class for EJ2-PDF
3
- */
4
- import { TtfTableInfo } from './ttf-table-info';
5
- import { Dictionary } from './../../collections/dictionary';
6
- import { TtfNameTable } from './ttf-name-table';
7
- import { TtfNameRecord } from './ttf-name-record';
8
- import { TtfHeadTable } from './ttf-head-table';
9
- import { TtfMetrics } from './ttf-metrics';
10
- import { TtfHorizontalHeaderTable } from './ttf-horizontal-header-table';
11
- import { TtfOS2Table } from './ttf-OS2-Table';
12
- import { TtfPostTable } from './ttf-post-table';
13
- import { TtfLongHorMetric } from './ttf-long-hor-metric';
14
- import { TtfCmapSubTable } from './ttf-cmap-sub-table';
15
- import { TtfCmapTable } from './ttf-cmap-table';
16
- import { TtfGlyphInfo } from './ttf-glyph-info';
17
- import { TtfLocaTable } from './ttf-loca-table';
18
- import { TtfAppleCmapSubTable } from './ttf-apple-cmap-sub-table';
19
- import { TtfMicrosoftCmapSubTable } from './ttf-microsoft-cmap-sub-table';
20
- import { TtfTrimmedCmapSubTable } from './ttf-trimmed-cmap-sub-table';
21
- import { TtfGlyphHeader } from './ttf-glyph-header';
22
- import { Rectangle } from './../../drawing/pdf-drawing';
23
- import { StringTokenizer } from './string-tokenizer';
24
- import { TtfCmapFormat, TtfCmapEncoding, TtfPlatformID } from './enum';
25
- import { TtfMicrosoftEncodingID, TtfMacintoshEncodingID, TtfCompositeGlyphFlags } from './enum';
26
- import { BigEndianWriter } from './../../input-output/big-endian-writer';
27
- export class TtfReader {
28
- //Fields
29
- private fontData : Uint8Array;
30
- private readonly int32Size : number = 4;
31
- private offset : number;
32
- public tableDirectory : Dictionary<string, TtfTableInfo>;
33
- private isTtcFont : boolean = false;
34
- private isMacTtf : boolean = false;
35
- private lowestPosition : number;
36
- private metricsName : string = '';
37
- public metrics : TtfMetrics;
38
- private maxMacIndex : number;
39
- private isFontPresent : boolean;
40
- private isMacTTF : boolean = false;
41
- private missedGlyphs : number = 0;
42
- private tableNames : string[] = ['cvt ', 'fpgm', 'glyf', 'head', 'hhea', 'hmtx', 'loca', 'maxp', 'prep'];
43
- private entrySelectors : number[] = [0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4];
44
- _isOpenTypeFont: boolean = false;
45
- /**
46
- * Width table.
47
- */
48
- private width : number[];
49
- /**
50
- * Indicates whether loca table is short.
51
- */
52
- public bIsLocaShort : boolean;
53
- /**
54
- * Glyphs for Macintosh or Symbol fonts.
55
- */
56
- private macintoshDictionary : Dictionary<number, TtfGlyphInfo>;
57
- /**
58
- * Glyphs for Microsoft or Symbol fonts.
59
- */
60
- private microsoftDictionary : Dictionary<number, TtfGlyphInfo>;
61
- /**
62
- * Glyphs for Macintosh or Symbol fonts (glyph index - key, glyph - value).
63
- */
64
- private internalMacintoshGlyphs : Dictionary<number, TtfGlyphInfo>;
65
- /**
66
- * Glyphs for Microsoft or Symbol fonts (glyph index - key, glyph - value).
67
- */
68
- private internalMicrosoftGlyphs : Dictionary<number, TtfGlyphInfo>;
69
- //Properties
70
- /**
71
- * Gets glyphs for Macintosh or Symbol fonts (char - key, glyph - value).
72
- */
73
- private get macintosh() : Dictionary<number, TtfGlyphInfo> {
74
- if (this.macintoshDictionary === null || this.macintoshDictionary === undefined) {
75
- this.macintoshDictionary = new Dictionary<number, TtfGlyphInfo>();
76
- }
77
- return this.macintoshDictionary;
78
- }
79
- /**
80
- * Gets glyphs for Microsoft or Symbol fonts (char - key, glyph - value).
81
- */
82
- private get microsoft() : Dictionary<number, TtfGlyphInfo> {
83
- if (this.microsoftDictionary === null || this.microsoftDictionary === undefined) {
84
- this.microsoftDictionary = new Dictionary<number, TtfGlyphInfo>();
85
- }
86
- return this.microsoftDictionary;
87
- }
88
- /**
89
- * Gets glyphs for Macintosh or Symbol fonts (glyph index - key, glyph - value).
90
- */
91
- private get macintoshGlyphs() : Dictionary<number, TtfGlyphInfo> {
92
- if (this.internalMacintoshGlyphs === null || this.internalMacintoshGlyphs === undefined) {
93
- this.internalMacintoshGlyphs = new Dictionary<number, TtfGlyphInfo>();
94
- }
95
- return this.internalMacintoshGlyphs;
96
- }
97
- /**
98
- * Gets glyphs for Microsoft Unicode fonts (glyph index - key, glyph - value).
99
- */
100
- private get microsoftGlyphs() : Dictionary<number, TtfGlyphInfo> {
101
- if (this.internalMicrosoftGlyphs === null || this.internalMicrosoftGlyphs === undefined) {
102
- this.internalMicrosoftGlyphs = new Dictionary<number, TtfGlyphInfo>();
103
- }
104
- return this.internalMicrosoftGlyphs;
105
- }
106
- //Constructors
107
- public constructor(fontData : Uint8Array) {
108
- this.fontData = fontData;
109
- this.initialize();
110
- }
111
- //Implementation
112
- private initialize() : void {
113
- if (this.metrics === undefined) {
114
- this.metrics = new TtfMetrics();
115
- }
116
- this.readFontDictionary();
117
- let nameTable : TtfNameTable = this.readNameTable();
118
- let headTable : TtfHeadTable = this.readHeadTable();
119
- this.initializeFontName(nameTable);
120
- this.metrics.macStyle = headTable.macStyle;
121
- }
122
- private readFontDictionary() : void {
123
- this.offset = 0;
124
- let version : number = this.checkPreambula();
125
- //this.offset += 4;
126
- let numTables : number = this.readInt16(this.offset);
127
- let searchRange : number = this.readInt16(this.offset);
128
- let entrySelector : number = this.readInt16(this.offset);
129
- let rangeShift : number = this.readInt16(this.offset);
130
- if (this.tableDirectory === undefined) {
131
- this.tableDirectory = new Dictionary<string, TtfTableInfo>();
132
- }
133
- for (let i : number = 0; i < numTables; ++i) {
134
- let table : TtfTableInfo = new TtfTableInfo();
135
- let tableKey : string = this.readString(this.int32Size);
136
- table.checksum = this.readInt32(this.offset);
137
- table.offset = this.readInt32(this.offset);
138
- table.length = this.readInt32(this.offset);
139
- this.tableDirectory.setValue(tableKey, table);
140
- }
141
- this.lowestPosition = this.offset;
142
- if (!this.isTtcFont) {
143
- this.fixOffsets();
144
- }
145
- }
146
- private fixOffsets() : void {
147
- let minOffset : number = Number.MAX_VALUE;
148
- // Search for a smallest offset and compare it with the lowest position found.
149
- let tableKeys : string[] = this.tableDirectory.keys();
150
- for (let i : number = 0; i < tableKeys.length; i++) {
151
- let value : TtfTableInfo = this.tableDirectory.getValue(tableKeys[i]);
152
- let offset : number = value.offset;
153
- if (minOffset > offset) {
154
- minOffset = offset;
155
- if (minOffset <= this.lowestPosition) {
156
- break;
157
- }
158
- }
159
- }
160
- let shift : number = minOffset - this.lowestPosition;
161
- if (shift !== 0) {
162
- let table : Dictionary<string, TtfTableInfo> = new Dictionary<string, TtfTableInfo>();
163
- for (let i : number = 0; i < tableKeys.length; i++) {
164
- let value : TtfTableInfo = this.tableDirectory.getValue(tableKeys[i]);
165
- value.offset -= shift;
166
- table.setValue(tableKeys[i], value);
167
- }
168
- this.tableDirectory = table;
169
- }
170
- }
171
- private checkPreambula() : number {
172
- let version : number = this.readInt32(this.offset);
173
- this.isMacTtf = (version === 0x74727565) ? true : false;
174
- if (version !== 0x10000 && version !== 0x74727565 && version !== 0x4f54544f) {
175
- this.isTtcFont = true;
176
- this.offset = 0;
177
- let fontTag : string = this.readString(4);
178
- if (fontTag !== 'ttcf') {
179
- throw new Error('Can not read TTF font data');
180
- }
181
- //skip 4
182
- this.offset += 4;
183
- let ttcIdentificationNumber : number = this.readInt32(this.offset);
184
- if (ttcIdentificationNumber < 0) {
185
- throw new Error('Can not read TTF font data');
186
- }
187
- this.offset = this.readInt32(this.offset);
188
- version = this.readInt32(this.offset);
189
- }
190
- if (version === 0x4f54544f) {
191
- this._isOpenTypeFont = true;
192
- }
193
- return version;
194
- }
195
- private readNameTable() : TtfNameTable {
196
- let tableInfo : TtfTableInfo = this.getTable('name');
197
- this.offset = tableInfo.offset;
198
- let table : TtfNameTable = new TtfNameTable();
199
- table.formatSelector = this.readUInt16(this.offset);
200
- table.recordsCount = this.readUInt16(this.offset);
201
- table.offset = this.readUInt16(this.offset);
202
- table.nameRecords = [];
203
- let recordSize : number = 12;
204
- let position : number = this.offset;
205
- for (let i : number = 0; i < table.recordsCount; i++) {
206
- this.offset = position;
207
- let record : TtfNameRecord = new TtfNameRecord();
208
- record.platformID = this.readUInt16(this.offset);
209
- record.encodingID = this.readUInt16(this.offset);
210
- record.languageID = this.readUInt16(this.offset);
211
- record.nameID = this.readUInt16(this.offset);
212
- record.length = this.readUInt16(this.offset);
213
- record.offset = this.readUInt16(this.offset);
214
- this.offset = tableInfo.offset + table.offset + record.offset;
215
- let unicode : boolean = (record.platformID === 0 || record.platformID === 3);
216
- record.name = this.readString(record.length, unicode);
217
- table.nameRecords[i] = record;
218
- position += recordSize;
219
- }
220
- return table;
221
- }
222
- private readHeadTable() : TtfHeadTable {
223
- let tableInfo : TtfTableInfo = this.getTable('head');
224
- this.offset = tableInfo.offset;
225
- let table : TtfHeadTable = new TtfHeadTable();
226
- table.version = this.readFixed(this.offset);
227
- table.fontRevision = this.readFixed(this.offset);
228
- table.checkSumAdjustment = this.readUInt32(this.offset);
229
- table.magicNumber = this.readUInt32(this.offset);
230
- table.flags = this.readUInt16(this.offset);
231
- table.unitsPerEm = this.readUInt16(this.offset);
232
- table.created = this.readInt64(this.offset);
233
- table.modified = this.readInt64(this.offset);
234
- table.xMin = this.readInt16(this.offset);
235
- table.yMin = this.readInt16(this.offset);
236
- table.xMax = this.readInt16(this.offset);
237
- table.yMax = this.readInt16(this.offset);
238
- table.macStyle = this.readUInt16(this.offset);
239
- table.lowestReadableSize = this.readUInt16(this.offset);
240
- table.fontDirectionHint = this.readInt16(this.offset);
241
- table.indexToLocalFormat = this.readInt16(this.offset);
242
- table.glyphDataFormat = this.readInt16(this.offset);
243
- return table;
244
- }
245
- private readHorizontalHeaderTable() : TtfHorizontalHeaderTable {
246
- let tableInfo : TtfTableInfo = this.getTable('hhea');
247
- this.offset = tableInfo.offset;
248
- let table : TtfHorizontalHeaderTable = new TtfHorizontalHeaderTable();
249
- table.version = this.readFixed(this.offset);
250
- table.ascender = this.readInt16(this.offset);
251
- table.descender = this.readInt16(this.offset);
252
- table.lineGap = this.readInt16(this.offset);
253
- table.advanceWidthMax = this.readUInt16(this.offset);
254
- table.minLeftSideBearing = this.readInt16(this.offset);
255
- table.minRightSideBearing = this.readInt16(this.offset);
256
- table.xMaxExtent = this.readInt16(this.offset);
257
- table.caretSlopeRise = this.readInt16(this.offset);
258
- table.caretSlopeRun = this.readInt16(this.offset);
259
- //skip 2 * 5
260
- this.offset += 10;
261
- table.metricDataFormat = this.readInt16(this.offset);
262
- table.numberOfHMetrics = this.readUInt16(this.offset);
263
- return table;
264
- }
265
- private readOS2Table() : TtfOS2Table {
266
- let tableInfo : TtfTableInfo = this.getTable('OS/2');
267
- this.offset = tableInfo.offset;
268
- let table : TtfOS2Table = new TtfOS2Table();
269
- table.version = this.readUInt16(this.offset);
270
- table.xAvgCharWidth = this.readInt16(this.offset);
271
- table.usWeightClass = this.readUInt16(this.offset);
272
- table.usWidthClass = this.readUInt16(this.offset);
273
- table.fsType = this.readInt16(this.offset);
274
- table.ySubscriptXSize = this.readInt16(this.offset);
275
- table.ySubscriptYSize = this.readInt16(this.offset);
276
- table.ySubscriptXOffset = this.readInt16(this.offset);
277
- table.ySubscriptYOffset = this.readInt16(this.offset);
278
- table.ySuperscriptXSize = this.readInt16(this.offset);
279
- table.ySuperscriptYSize = this.readInt16(this.offset);
280
- table.ySuperscriptXOffset = this.readInt16(this.offset);
281
- table.ySuperscriptYOffset = this.readInt16(this.offset);
282
- table.yStrikeoutSize = this.readInt16(this.offset);
283
- table.yStrikeoutPosition = this.readInt16(this.offset);
284
- table.sFamilyClass = this.readInt16(this.offset);
285
- table.panose = this.readBytes(10);
286
- table.ulUnicodeRange1 = this.readUInt32(this.offset);
287
- table.ulUnicodeRange2 = this.readUInt32(this.offset);
288
- table.ulUnicodeRange3 = this.readUInt32(this.offset);
289
- table.ulUnicodeRange4 = this.readUInt32(this.offset);
290
- table.vendorIdentifier = this.readBytes(4);
291
- table.fsSelection = this.readUInt16(this.offset);
292
- table.usFirstCharIndex = this.readUInt16(this.offset);
293
- table.usLastCharIndex = this.readUInt16(this.offset);
294
- table.sTypoAscender = this.readInt16(this.offset);
295
- table.sTypoDescender = this.readInt16(this.offset);
296
- table.sTypoLineGap = this.readInt16(this.offset);
297
- table.usWinAscent = this.readUInt16(this.offset);
298
- table.usWinDescent = this.readUInt16(this.offset);
299
- table.ulCodePageRange1 = this.readUInt32(this.offset);
300
- table.ulCodePageRange2 = this.readUInt32(this.offset);
301
- if (table.version > 1) {
302
- table.sxHeight = this.readInt16(this.offset);
303
- table.sCapHeight = this.readInt16(this.offset);
304
- table.usDefaultChar = this.readUInt16(this.offset);
305
- table.usBreakChar = this.readUInt16(this.offset);
306
- table.usMaxContext = this.readUInt16(this.offset);
307
- } else {
308
- table.sxHeight = 0;
309
- table.sCapHeight = 0;
310
- table.usDefaultChar = 0;
311
- table.usBreakChar = 0;
312
- table.usMaxContext = 0;
313
- }
314
- return table;
315
- }
316
- private readPostTable() : TtfPostTable {
317
- let tableInfo : TtfTableInfo = this.getTable('post');
318
- this.offset = tableInfo.offset;
319
- let table : TtfPostTable = new TtfPostTable();
320
- table.formatType = this.readFixed(this.offset);
321
- table.italicAngle = this.readFixed(this.offset);
322
- table.underlinePosition = this.readInt16(this.offset);
323
- table.underlineThickness = this.readInt16(this.offset);
324
- table.isFixedPitch = this.readUInt32(this.offset);
325
- table.minType42 = this.readUInt32(this.offset);
326
- table.maxType42 = this.readUInt32(this.offset);
327
- table.minType1 = this.readUInt32(this.offset);
328
- table.maxType1 = this.readUInt32(this.offset);
329
- return table;
330
- }
331
- /**
332
- * Reads Width of the glyphs.
333
- */
334
- private readWidthTable(glyphCount : number, unitsPerEm : number) : number[] {
335
- let tableInfo : TtfTableInfo = this.getTable('hmtx');
336
- this.offset = tableInfo.offset;
337
- let width : number[] = [];
338
- for (let i : number = 0; i < glyphCount; i++) {
339
- let glyph : TtfLongHorMetric = new TtfLongHorMetric();
340
- glyph.advanceWidth = this.readUInt16(this.offset);
341
- glyph.lsb = this.readInt16(this.offset);
342
- let glyphWidth : number = glyph.advanceWidth * 1000 / unitsPerEm;
343
- width.push(Math.floor(glyphWidth));
344
- }
345
- return width;
346
- }
347
- /**
348
- * Reads the cmap table.
349
- */
350
- private readCmapTable() : TtfCmapSubTable[] {
351
- let tableInfo : TtfTableInfo = this.getTable('cmap');
352
- this.offset = tableInfo.offset;
353
- let table : TtfCmapTable = new TtfCmapTable();
354
- table.version = this.readUInt16(this.offset);
355
- table.tablesCount = this.readUInt16(this.offset);
356
- let position : number = this.offset;
357
- let subTables : TtfCmapSubTable[] = [];
358
- for (let i : number = 0; i < table.tablesCount; i++) {
359
- this.offset = position;
360
- let subTable : TtfCmapSubTable = new TtfCmapSubTable();
361
- subTable.platformID = this.readUInt16(this.offset);
362
- subTable.encodingID = this.readUInt16(this.offset);
363
- subTable.offset = this.readUInt32(this.offset);
364
- position = this.offset;
365
- this.readCmapSubTable(subTable);
366
- subTables[i] = subTable;
367
- }
368
- return subTables;
369
- }
370
- /**
371
- * Reads the cmap sub table.
372
- */
373
- private readCmapSubTable(subTable : TtfCmapSubTable) : void {
374
- let tableInfo : TtfTableInfo = this.getTable('cmap');
375
- this.offset = tableInfo.offset + subTable.offset;
376
- let format : TtfCmapFormat = this.readUInt16(this.offset) as TtfCmapFormat;
377
- let encoding : TtfCmapEncoding = this.getCmapEncoding(subTable.platformID, subTable.encodingID);
378
- let platform : TtfPlatformID = (encoding === TtfCmapEncoding.Macintosh) ? TtfPlatformID.Macintosh : TtfPlatformID.Microsoft;
379
- if (encoding !== TtfCmapEncoding.Unknown) {
380
- switch (format) {
381
- case TtfCmapFormat.Apple:
382
- this.readAppleCmapTable(subTable, encoding);
383
- break;
384
- case TtfCmapFormat.Microsoft:
385
- this.readMicrosoftCmapTable(subTable, encoding);
386
- break;
387
- case TtfCmapFormat.Trimmed:
388
- this.readTrimmedCmapTable(subTable, encoding);
389
- break;
390
- }
391
- }
392
- }
393
- /**
394
- * Reads Symbol cmap table.
395
- */
396
- private readAppleCmapTable(subTable : TtfCmapSubTable, encoding : TtfCmapEncoding) : void {
397
- let tableInfo : TtfTableInfo = this.getTable('cmap');
398
- this.offset = tableInfo.offset + subTable.offset;
399
- let table : TtfAppleCmapSubTable = new TtfAppleCmapSubTable();
400
- table.format = this.readUInt16(this.offset);
401
- table.length = this.readUInt16(this.offset);
402
- table.version = this.readUInt16(this.offset);
403
- if (this.maxMacIndex === null || this.maxMacIndex === undefined) {
404
- this.maxMacIndex = 0;
405
- }
406
- for (let i : number = 0; i < 256; ++i) {
407
- let glyphInfo : TtfGlyphInfo = new TtfGlyphInfo();
408
- glyphInfo.index = this.readByte(this.offset) as number;
409
- glyphInfo.width = this.getWidth(glyphInfo.index);
410
- glyphInfo.charCode = i;
411
- this.macintosh.setValue(i, glyphInfo);
412
- this.addGlyph(glyphInfo, encoding);
413
- // NOTE: this code fixes char codes that extends 0x100. However, it might corrupt something.
414
- this.maxMacIndex = Math.max(i, this.maxMacIndex);
415
- }
416
- }
417
- /**
418
- * Reads Symbol cmap table.
419
- */
420
- private readMicrosoftCmapTable(subTable : TtfCmapSubTable, encoding : TtfCmapEncoding) : void {
421
- let tableInfo : TtfTableInfo = this.getTable('cmap');
422
- this.offset = tableInfo.offset + subTable.offset;
423
- let collection : Dictionary<number, TtfGlyphInfo> = (encoding === TtfCmapEncoding.Unicode) ? this.microsoft : this.macintosh;
424
- let table : TtfMicrosoftCmapSubTable = new TtfMicrosoftCmapSubTable();
425
- table.format = this.readUInt16(this.offset);
426
- table.length = this.readUInt16(this.offset);
427
- table.version = this.readUInt16(this.offset);
428
- table.segCountX2 = this.readUInt16(this.offset);
429
- table.searchRange = this.readUInt16(this.offset);
430
- table.entrySelector = this.readUInt16(this.offset);
431
- table.rangeShift = this.readUInt16(this.offset);
432
- let segCount : number = table.segCountX2 / 2;
433
- table.endCount = this.readUshortArray(segCount);
434
- table.reservedPad = this.readUInt16(this.offset);
435
- table.startCount = this.readUshortArray(segCount);
436
- table.idDelta = this.readUshortArray(segCount);
437
- table.idRangeOffset = this.readUshortArray(segCount);
438
- let length : number = (table.length / 2 - 8) - (segCount * 4);
439
- table.glyphID = this.readUshortArray(length);
440
- // Process glyphIdArray array.
441
- let codeOffset : number = 0;
442
- let index : number = 0;
443
- for (let j : number = 0; j < segCount; j++) {
444
- for (let k : number = table.startCount[j]; k <= table.endCount[j] && k !== 65535; k++) {
445
- if (table.idRangeOffset[j] === 0) {
446
- codeOffset = (k + table.idDelta[j]) & 65535;
447
- } else {
448
- index = j + table.idRangeOffset[j] / 2 - segCount + k - table.startCount[j];
449
- if (index >= table.glyphID.length) {
450
- continue;
451
- }
452
- codeOffset = (table.glyphID[index] + table.idDelta[j]) & 65535;
453
- }
454
- let glyph : TtfGlyphInfo = new TtfGlyphInfo();
455
- glyph.index = codeOffset;
456
- glyph.width = this.getWidth(glyph.index);
457
- let id : number = (encoding === TtfCmapEncoding.Symbol) ? ((k & 0xff00) === 0xf000 ? k & 0xff : k) : k;
458
- glyph.charCode = id;
459
- collection.setValue(id, glyph);
460
- this.addGlyph(glyph, encoding);
461
- }
462
- }
463
- }
464
- /**
465
- * Reads Trimed cmap table.
466
- */
467
- private readTrimmedCmapTable(subTable : TtfCmapSubTable, encoding : TtfCmapEncoding) : void {
468
- let tableInfo : TtfTableInfo = this.getTable('cmap');
469
- this.offset = tableInfo.offset + subTable.offset;
470
- let table : TtfTrimmedCmapSubTable = new TtfTrimmedCmapSubTable();
471
- table.format = this.readUInt16(this.offset);
472
- table.length = this.readUInt16(this.offset);
473
- table.version = this.readUInt16(this.offset);
474
- table.firstCode = this.readUInt16(this.offset);
475
- table.entryCount = this.readUInt16(this.offset);
476
- for (let i : number = 0; i < table.entryCount; ++i) {
477
- let glyphInfo : TtfGlyphInfo = new TtfGlyphInfo();
478
- glyphInfo.index = this.readUInt16(this.offset);
479
- glyphInfo.width = this.getWidth(glyphInfo.index);
480
- glyphInfo.charCode = i + table.firstCode;
481
- this.macintosh.setValue(i, glyphInfo);
482
- this.addGlyph(glyphInfo, encoding);
483
- // NOTE: this code fixes char codes that extends 0x100. However, it might corrupt something.
484
- this.maxMacIndex = Math.max(i, this.maxMacIndex);
485
- }
486
- }
487
- private initializeFontName(nameTable : TtfNameTable) : void {
488
- for (let i : number = 0; i < nameTable.recordsCount; i++) {
489
- let record : TtfNameRecord = nameTable.nameRecords[i];
490
- if (record.nameID === 1) {
491
- //font family
492
- this.metrics.fontFamily = record.name;
493
- } else if (record.nameID === 6) {
494
- //post script name
495
- this.metrics.postScriptName = record.name;
496
- }
497
- /* tslint:disable */
498
- if (this.metrics.fontFamily !== null && this.metrics.fontFamily !== undefined && this.metrics.postScriptName !== null && this.metrics.postScriptName !== undefined) {
499
- break;
500
- }
501
- /* tslint:disable */
502
- }
503
- }
504
- private getTable(name : string) : TtfTableInfo {
505
- // if (name === null) {
506
- // throw new Error('Argument Null Exception : name');
507
- // }
508
- let table : TtfTableInfo = new TtfTableInfo();
509
- let obj : TtfTableInfo;
510
- if (this.tableDirectory.containsKey(name)) {
511
- obj = this.tableDirectory.getValue(name);
512
- }
513
- if (obj !== null && obj !== undefined) {
514
- table = obj as TtfTableInfo;
515
- }
516
- return table;
517
- }
518
- /**
519
- * Returns width of the glyph.
520
- */
521
- private getWidth(glyphCode : number) : number {
522
- glyphCode = (glyphCode < this.width.length) ? glyphCode : this.width.length - 1;
523
- return this.width[glyphCode];
524
- }
525
- /**
526
- * Gets CMAP encoding based on platform ID and encoding ID.
527
- */
528
- /* tslint:disable */
529
- private getCmapEncoding(platformID : number, encodingID : number) : TtfCmapEncoding {
530
- let format : TtfCmapEncoding = TtfCmapEncoding.Unknown;
531
- if (platformID == (TtfPlatformID.Microsoft as number) && encodingID == (TtfMicrosoftEncodingID.Undefined as number)) {
532
- // When building a symbol font for Windows,
533
- // the platform ID should be 3 and the encoding ID should be 0.
534
- format = TtfCmapEncoding.Symbol;
535
- } else if (platformID == (TtfPlatformID.Microsoft as number) && encodingID == (TtfMicrosoftEncodingID.Unicode as number)) {
536
- // When building a Unicode font for Windows,
537
- // the platform ID should be 3 and the encoding ID should be 1.
538
- format = TtfCmapEncoding.Unicode;
539
- } else if (platformID == (TtfPlatformID.Macintosh as number) && encodingID == (TtfMacintoshEncodingID.Roman as number)) {
540
- // When building a font that will be used on the Macintosh,
541
- // the platform ID should be 1 and the encoding ID should be 0.
542
- format = TtfCmapEncoding.Macintosh;
543
- }
544
- return format;
545
- }
546
- /* tslint:enable */
547
- /**
548
- * Adds glyph to the collection.
549
- */
550
- private addGlyph(glyph : TtfGlyphInfo, encoding : TtfCmapEncoding) : void {
551
- let collection : Dictionary<number, TtfGlyphInfo> = null;
552
- switch (encoding) {
553
- case TtfCmapEncoding.Unicode:
554
- collection = this.microsoftGlyphs;
555
- break;
556
- case TtfCmapEncoding.Macintosh:
557
- case TtfCmapEncoding.Symbol:
558
- collection = this.macintoshGlyphs;
559
- break;
560
- }
561
- collection.setValue(glyph.index, glyph);
562
- }
563
- /**
564
- * Initializes metrics.
565
- */
566
- /* tslint:disable */
567
- private initializeMetrics(nameTable : TtfNameTable, headTable : TtfHeadTable, horizontalHeadTable : TtfHorizontalHeaderTable, os2Table : TtfOS2Table, postTable : TtfPostTable, cmapTables : TtfCmapSubTable[]) : void {
568
- /* tslint:enable */
569
- // if (cmapTables === null) {
570
- // throw new Error('ArgumentNullException : cmapTables');
571
- // }
572
- this.initializeFontName(nameTable);
573
- // Get font encoding.
574
- let bSymbol : boolean = false;
575
- for (let i : number = 0; i < cmapTables.length; i++) {
576
- let subTable : TtfCmapSubTable = cmapTables[i];
577
- let encoding : TtfCmapEncoding = this.getCmapEncoding(subTable.platformID, subTable.encodingID);
578
- if (encoding === TtfCmapEncoding.Symbol) {
579
- bSymbol = true;
580
- break;
581
- }
582
- }
583
- this.metrics.isSymbol = bSymbol;
584
- this.metrics.macStyle = headTable.macStyle;
585
- this.metrics.isFixedPitch = (postTable.isFixedPitch !== 0);
586
- this.metrics.italicAngle = postTable.italicAngle;
587
- let factor : number = 1000 / headTable.unitsPerEm;
588
- this.metrics.winAscent = os2Table.sTypoAscender * factor;
589
- this.metrics.macAscent = horizontalHeadTable.ascender * factor;
590
- //m_metrics.MacAscent = os2Table.UsWinAscent * factor;
591
- // NOTE: This is stange workaround. The value is good if os2Table.SCapHeight != 0, otherwise it should be properly computed.
592
- this.metrics.capHeight = (os2Table.sCapHeight !== 0) ? os2Table.sCapHeight : 0.7 * headTable.unitsPerEm * factor;
593
- this.metrics.winDescent = os2Table.sTypoDescender * factor;
594
- this.metrics.macDescent = horizontalHeadTable.descender * factor;
595
- //m_metrics.MacDescent = -os2Table.UsWinDescent * factor;
596
- this.metrics.leading = (os2Table.sTypoAscender - os2Table.sTypoDescender + os2Table.sTypoLineGap) * factor;
597
- this.metrics.lineGap = Math.ceil(horizontalHeadTable.lineGap * factor);
598
- let left : number = headTable.xMin * factor;
599
- let top : number = Math.ceil(this.metrics.macAscent + this.metrics.lineGap);
600
- let right : number = headTable.xMax * factor;
601
- let bottom : number = this.metrics.macDescent;
602
- this.metrics.fontBox = new Rectangle(left, top, right, bottom);
603
- // NOTE: Strange!
604
- this.metrics.stemV = 80;
605
- this.metrics.widthTable = this.updateWidth();
606
- this.metrics.contains = this.tableDirectory.containsKey('CFF ');
607
- this.metrics.subScriptSizeFactor = headTable.unitsPerEm / os2Table.ySubscriptYSize;
608
- this.metrics.superscriptSizeFactor = headTable.unitsPerEm / os2Table.ySuperscriptYSize;
609
- }
610
- /**
611
- * Updates chars structure which is used in the case of ansi encoding (256 bytes).
612
- */
613
- private updateWidth() : number[] {
614
- let count : number = 256;
615
- let bytes : number[] = [];
616
- if (this.metrics.isSymbol) {
617
- for (let i : number = 0; i < count; i++) {
618
- let glyphInfo : TtfGlyphInfo = this.getGlyph(String.fromCharCode(i));
619
- bytes[i] = (glyphInfo.empty) ? 0 : glyphInfo.width;
620
- }
621
- } else {
622
- let byteToProcess : number[] = [];
623
- let unknown : string = '?';
624
- let space : string = String.fromCharCode(32);
625
- for (let i : number = 0; i < count; i++) {
626
- byteToProcess[0] = i;
627
- let text : string = this.getString(byteToProcess, 0, byteToProcess.length);
628
- let ch : string = (text.length > 0) ? text[0] : unknown;
629
- let glyphInfo : TtfGlyphInfo = this.getGlyph(ch);
630
- if (!glyphInfo.empty) {
631
- bytes[i] = glyphInfo.width;
632
- } else {
633
- glyphInfo = this.getGlyph(space);
634
- bytes[i] = (glyphInfo.empty) ? 0 : glyphInfo.width;
635
- }
636
- }
637
- }
638
- return bytes;
639
- }
640
- /**
641
- * Returns default glyph.
642
- */
643
- private getDefaultGlyph() : TtfGlyphInfo {
644
- let glyph : TtfGlyphInfo = this.getGlyph(StringTokenizer.whiteSpace);
645
- return glyph;
646
- }
647
- /**
648
- * Reads unicode string from byte array.
649
- */
650
- private getString(byteToProcess : number[], start : number, length : number) : string {
651
- let result : string = '';
652
- for (let index : number = 0; index < length; index++) {
653
- result += String.fromCharCode(byteToProcess[index + start]);
654
- }
655
- return result;
656
- }
657
- /**
658
- * Reads loca table.
659
- */
660
- private readLocaTable(bShort : boolean) : TtfLocaTable {
661
- let tableInfo : TtfTableInfo = this.getTable('loca');
662
- this.offset = tableInfo.offset;
663
- let table : TtfLocaTable = new TtfLocaTable();
664
- let buffer : number[] = null;
665
- if (bShort) {
666
- let len : number = tableInfo.length / 2;
667
- buffer = [];
668
- for (let i : number = 0; i < len; i++) {
669
- buffer[i] = this.readUInt16(this.offset) * 2;
670
- }
671
- } else {
672
- let len : number = tableInfo.length / 4;
673
- buffer = [];
674
- for (let i : number = 0; i < len; i++) {
675
- buffer[i] = this.readUInt32(this.offset);
676
- }
677
- }
678
- table.offsets = buffer;
679
- return table;
680
- }
681
- /**
682
- * Updates hash table of used glyphs.
683
- */
684
- private updateGlyphChars(glyphChars : Dictionary<number, number>, locaTable : TtfLocaTable) : void {
685
- // if (glyphChars === null) {
686
- // throw new Error('Argument Null Exception : glyphChars');
687
- // }
688
- // Add zero key.
689
- if (!glyphChars.containsKey(0)) {
690
- glyphChars.setValue(0, 0);
691
- }
692
- let clone : Dictionary<number, number> = new Dictionary<number, number>();
693
- let glyphCharKeys : number[] = glyphChars.keys();
694
- for (let i : number = 0; i < glyphCharKeys.length; i++) {
695
- clone.setValue(glyphCharKeys[i], glyphChars.getValue(glyphCharKeys[i]));
696
- }
697
- for (let i : number = 0; i < glyphCharKeys.length; i++) {
698
- let nextKey : number = glyphCharKeys[i];
699
- this.processCompositeGlyph(glyphChars, nextKey, locaTable);
700
- }
701
- }
702
- /**
703
- * Checks if glyph is composite or not.
704
- */
705
- private processCompositeGlyph(glyphChars : Dictionary<number, number>, glyph : number, locaTable : TtfLocaTable) : void {
706
- // if (glyphChars === null) {
707
- // throw new Error('Argument Null Exception : glyphChars');
708
- // }
709
- // Is in range.
710
- if (glyph < locaTable.offsets.length - 1) {
711
- let glyphOffset : number = locaTable.offsets[glyph];
712
- if (glyphOffset !== locaTable.offsets[glyph + 1]) {
713
- let tableInfo : TtfTableInfo = this.getTable('glyf');
714
- this.offset = tableInfo.offset + glyphOffset;
715
- let glyphHeader : TtfGlyphHeader = new TtfGlyphHeader();
716
- glyphHeader.numberOfContours = this.readInt16(this.offset);
717
- glyphHeader.xMin = this.readInt16(this.offset);
718
- glyphHeader.yMin = this.readInt16(this.offset);
719
- glyphHeader.xMax = this.readInt16(this.offset);
720
- glyphHeader.yMax = this.readInt16(this.offset);
721
- // Glyph is composite.
722
- if (glyphHeader.numberOfContours < 0) {
723
- let skipBytes : number = 0;
724
- let entry : boolean = true;
725
- while (entry) {
726
- let flags : number = this.readUInt16(this.offset);
727
- let glyphIndex : number = this.readUInt16(this.offset);
728
- if (!glyphChars.containsKey(glyphIndex)) {
729
- glyphChars.setValue(glyphIndex, 0);
730
- }
731
- if ((flags & TtfCompositeGlyphFlags.MoreComponents) === 0) {
732
- break;
733
- }
734
- skipBytes = ((flags & TtfCompositeGlyphFlags.Arg1And2AreWords) !== 0) ? 4 : 2;
735
- if ((flags & TtfCompositeGlyphFlags.WeHaveScale) !== 0) {
736
- skipBytes += 2;
737
- } else if ((flags & TtfCompositeGlyphFlags.WeHaveAnXyScale) !== 0) {
738
- skipBytes += 4;
739
- } else if ((flags & TtfCompositeGlyphFlags.WeHaveTwoByTwo) !== 0) {
740
- skipBytes += 2 * 4;
741
- }
742
- this.offset += skipBytes;
743
- }
744
- }
745
- }
746
- }
747
- }
748
- /**
749
- * Creates new glyph tables based on chars that are used for output.
750
- */
751
- /* tslint:disable */
752
- private generateGlyphTable(glyphChars : Dictionary<number, number>, locaTable : TtfLocaTable, newLocaTable : number[], newGlyphTable : number[]) : { glyphTableSize : number, newLocaTable : number[], newGlyphTable : number[] } {
753
- /* tslint:enable */
754
- // if (glyphChars === null) {
755
- // throw new Error('Argument Null Exception : glyphChars');
756
- // }
757
- newLocaTable = [];
758
- // Sorting used glyphs keys.
759
- let activeGlyphs : number[] = glyphChars.keys();
760
- activeGlyphs.sort((a : number, b : number) => a - b);
761
- let glyphSize : number = 0;
762
- for (let i : number = 0; i < activeGlyphs.length; i++) {
763
- let glyphIndex : number = activeGlyphs[i];
764
- if (locaTable.offsets.length > 0) {
765
- glyphSize += locaTable.offsets[glyphIndex + 1] - locaTable.offsets[glyphIndex];
766
- }
767
- }
768
- let glyphSizeAligned : number = this.align(glyphSize);
769
- newGlyphTable = [];
770
- for (let i : number = 0; i < glyphSizeAligned; i++) {
771
- newGlyphTable.push(0);
772
- }
773
- let nextGlyphOffset : number = 0;
774
- let nextGlyphIndex : number = 0;
775
- let table : TtfTableInfo = this.getTable('glyf');
776
- // Creating NewLocaTable - that would hold offsets for filtered glyphs.
777
- for (let i : number = 0; i < locaTable.offsets.length; i++) {
778
- newLocaTable.push(nextGlyphOffset);
779
- if (nextGlyphIndex < activeGlyphs.length && activeGlyphs[nextGlyphIndex] === i) {
780
- ++nextGlyphIndex;
781
- newLocaTable[i] = nextGlyphOffset;
782
- let oldGlyphOffset : number = locaTable.offsets[i];
783
- let oldNextGlyphOffset : number = locaTable.offsets[i + 1] - oldGlyphOffset;
784
- if (oldNextGlyphOffset > 0) {
785
- this.offset = table.offset + oldGlyphOffset;
786
- let result : { buffer : number[], written : number } = this.read(newGlyphTable, nextGlyphOffset, oldNextGlyphOffset);
787
- newGlyphTable = result.buffer;
788
- nextGlyphOffset += oldNextGlyphOffset;
789
- }
790
- }
791
- }
792
- return { glyphTableSize : glyphSize, newLocaTable : newLocaTable, newGlyphTable : newGlyphTable };
793
- }
794
- /**
795
- * Updates new Loca table.
796
- */
797
- /* tslint:disable */
798
- private updateLocaTable(newLocaTable : number[], bLocaIsShort : boolean, newLocaTableOut : number[]) : { newLocaUpdated : number[], newLocaSize : number } {
799
- /* tslint:enable */
800
- if (newLocaTable === null) {
801
- throw new Error('Argument Null Exception : newLocaTable');
802
- }
803
- let size : number = (bLocaIsShort) ? newLocaTable.length * 2 : newLocaTable.length * 4;
804
- let count : number = this.align(size);
805
- //BigEndianWiter
806
- let writer : BigEndianWriter = new BigEndianWriter(count);
807
- for (let i : number = 0; i < newLocaTable.length; i++) {
808
- let value : number = newLocaTable[i];
809
- if (bLocaIsShort) {
810
- value /= 2;
811
- writer.writeShort(value);
812
- } else {
813
- writer.writeInt(value);
814
- }
815
- }
816
- return { newLocaUpdated : writer.data, newLocaSize : size };
817
- }
818
- /**
819
- * Aligns number to be divisible on 4.
820
- */
821
- private align(value : number) : number {
822
- return (value + 3) & (~3);
823
- }
824
- /**
825
- * Returns font program data.
826
- */
827
- /* tslint:disable */
828
- private getFontProgram(newLocaTableOut : number[], newGlyphTable : number[], glyphTableSize : number, locaTableSize : number) : number[] {
829
- /* tslint:enable */
830
- if (newLocaTableOut === null) {
831
- throw new Error('Argument Null Exception : newLocaTableOut');
832
- }
833
- if (newGlyphTable === null) {
834
- throw new Error('Argument Null Exception : newGlyphTable');
835
- }
836
- let tableNames : string[] = this.tableNames;
837
- let result : {fontProgramLength : number, numTables : number} = this.getFontProgramLength(newLocaTableOut, newGlyphTable, 0);
838
- let fontProgramLength : number = result.fontProgramLength;
839
- let numTables : number = result.numTables;
840
- let writer : BigEndianWriter = new BigEndianWriter(fontProgramLength);
841
- writer.writeInt(0x10000);
842
- writer.writeShort(numTables);
843
- let entrySelector : number = this.entrySelectors[numTables];
844
- writer.writeShort((1 << (entrySelector & 31)) * 16);
845
- writer.writeShort(entrySelector);
846
- writer.writeShort((numTables - (1 << (entrySelector & 31))) * 16);
847
- // Writing to destination buffer - checksums && sizes of used tables.
848
- this.writeCheckSums(writer, numTables, newLocaTableOut, newGlyphTable, glyphTableSize, locaTableSize);
849
- // // Writing to destination buffer - used glyphs.
850
- this.writeGlyphs(writer, newLocaTableOut, newGlyphTable);
851
- return writer.data;
852
- }
853
- /* tslint:disable */
854
- private getFontProgramLength(newLocaTableOut : number[], newGlyphTable : number[], numTables : number) : {fontProgramLength : number, numTables : number} {
855
- /* tslint:enable */
856
- if (newLocaTableOut === null) {
857
- throw new Error('Argument Null Exception : newLocaTableOut');
858
- }
859
- if (newGlyphTable === null) {
860
- throw new Error('Argument Null Exception : newGlyphTable');
861
- }
862
- // glyf and loca are used by default;
863
- numTables = 2;
864
- let tableNames : string[] = this.tableNames;
865
- let fontProgramLength : number = 0;
866
- for (let i : number = 0; i < tableNames.length; i++) {
867
- let tableName : string = tableNames[i];
868
- if (tableName !== 'glyf' && tableName !== 'loca') {
869
- let table : TtfTableInfo = this.getTable(tableName);
870
- if (!table.empty) {
871
- ++numTables;
872
- fontProgramLength += this.align(table.length);
873
- }
874
- }
875
- }
876
- fontProgramLength += newLocaTableOut.length;
877
- fontProgramLength += newGlyphTable.length;
878
- let usedTablesSize : number = numTables * 16 + (3 * 4);
879
- fontProgramLength += usedTablesSize;
880
- return { fontProgramLength : fontProgramLength, numTables : numTables};
881
- }
882
- /**
883
- * Writing to destination buffer - checksums and sizes of used tables.
884
- */
885
- /* tslint:disable */
886
- private writeCheckSums(writer : BigEndianWriter, numTables : number, newLocaTableOut : number[], newGlyphTable : number[], glyphTableSize : number, locaTableSize : number) : void {
887
- /* tslint:enable */
888
- if (writer === null) {
889
- throw new Error('Argument Null Exception : writer');
890
- }
891
- if (newLocaTableOut === null) {
892
- throw new Error('Argument Null Exception : newLocaTableOut');
893
- }
894
- if (newGlyphTable === null) {
895
- throw new Error('Argument Null Exception : newGlyphTable');
896
- }
897
- let tableNames : string[] = this.tableNames;
898
- let usedTablesSize : number = numTables * 16 + (3 * 4);
899
- let nextTableSize : number = 0;
900
- for (let i : number = 0; i < tableNames.length; i++) {
901
- let tableName : string = tableNames[i];
902
- let tableInfo : TtfTableInfo = this.getTable(tableName);
903
- if (tableInfo.empty) {
904
- continue;
905
- }
906
- writer.writeString(tableName);
907
- if (tableName === 'glyf') {
908
- let checksum : number = this.calculateCheckSum(newGlyphTable);
909
- writer.writeInt(checksum);
910
- nextTableSize = glyphTableSize;
911
- } else if (tableName === 'loca') {
912
- let checksum : number = this.calculateCheckSum(newLocaTableOut);
913
- writer.writeInt(checksum);
914
- nextTableSize = locaTableSize;
915
- } else {
916
- writer.writeInt(tableInfo.checksum);
917
- nextTableSize = tableInfo.length;
918
- }
919
- writer.writeUInt(usedTablesSize);
920
- writer.writeUInt(nextTableSize);
921
- usedTablesSize += this.align(nextTableSize);
922
- }
923
- }
924
- /**
925
- * Gets checksum from source buffer.
926
- */
927
- private calculateCheckSum(bytes : number[]) : number {
928
- if (bytes === null) {
929
- throw new Error('Argument Null Exception : bytes');
930
- }
931
- let pos : number = 0;
932
- let byte1 : number = 0;
933
- let byte2 : number = 0;
934
- let byte3 : number = 0;
935
- let byte4 : number = 0;
936
-
937
- for (let i : number = 0; i < (bytes.length + 1) / 4; i++) {
938
- byte4 += (bytes[pos++] & 255);
939
- byte3 += (bytes[pos++] & 255);
940
- byte2 += (bytes[pos++] & 255);
941
- byte1 += (bytes[pos++] & 255);
942
- }
943
- let result : number = byte1;
944
- result += (byte2 << 8);
945
- result += (byte3 << 16);
946
- result += (byte4 << 24);
947
- return result;
948
- }
949
- /**
950
- * Writing to destination buffer - used glyphs.
951
- */
952
- private writeGlyphs(writer : BigEndianWriter, newLocaTable : number[], newGlyphTable : number[]) : void {
953
- if (writer === null) {
954
- throw new Error('Argument Null Exception : writer');
955
- }
956
- if (newLocaTable === null) {
957
- throw new Error('Argument Null Exception : newLocaTableOut');
958
- }
959
- if (newGlyphTable === null) {
960
- throw new Error('Argument Null Exception : newGlyphTable');
961
- }
962
- let tableNames : string[] = this.tableNames;
963
- for (let i : number = 0; i < tableNames.length; i++) {
964
- let tableName : string = tableNames[i];
965
- let tableInfo : TtfTableInfo = this.getTable(tableName);
966
- if (tableInfo.empty) {
967
- continue;
968
- }
969
- if (tableName === 'glyf') {
970
- writer.writeBytes(newGlyphTable);
971
- } else if (tableName === 'loca') {
972
- writer.writeBytes(newLocaTable);
973
- } else {
974
- let count : number = this.align(tableInfo.length);
975
- let buff : number[] = [];
976
- for (let i : number = 0; i < count; i++) {
977
- buff.push(0);
978
- }
979
- this.offset = tableInfo.offset;
980
- let result : {buffer : number[], written : number} = this.read(buff, 0, tableInfo.length);
981
- writer.writeBytes(result.buffer);
982
- }
983
- }
984
- }
985
- //public methods
986
- /**
987
- * Sets position value of font data.
988
- */
989
- public setOffset(offset : number) : void {
990
- this.offset = offset;
991
- }
992
- /**
993
- * Creates font Internals
994
- * @private
995
- */
996
- public createInternals() : void {
997
- this.metrics = new TtfMetrics();
998
- let nameTable : TtfNameTable = this.readNameTable();
999
- let headTable : TtfHeadTable = this.readHeadTable();
1000
- this.bIsLocaShort = (headTable.indexToLocalFormat === 0);
1001
- let horizontalHeadTable : TtfHorizontalHeaderTable = this.readHorizontalHeaderTable();
1002
- let os2Table : TtfOS2Table = this.readOS2Table();
1003
- let postTable : TtfPostTable = this.readPostTable();
1004
- this.width = this.readWidthTable(horizontalHeadTable.numberOfHMetrics, headTable.unitsPerEm);
1005
- let subTables : TtfCmapSubTable[] = this.readCmapTable();
1006
- this.initializeMetrics(nameTable, headTable, horizontalHeadTable, os2Table, postTable, subTables);
1007
- }
1008
- /**
1009
- * Gets glyph's info by char code.
1010
- */
1011
- public getGlyph(charCode : string ) : TtfGlyphInfo
1012
- public getGlyph(charCode : number ) : TtfGlyphInfo
1013
- public getGlyph(charCode ?: string | number) : TtfGlyphInfo {
1014
- if (typeof charCode === 'number') {
1015
- let obj1 : object = null;
1016
- if (!this.metrics.isSymbol && this.microsoftGlyphs != null) {
1017
- if (this.microsoftGlyphs.containsKey(charCode)) {
1018
- obj1 = this.microsoftGlyphs.getValue(charCode);
1019
- }
1020
- } else if (this.metrics.isSymbol && this.macintoshGlyphs != null) {
1021
- if (this.macintoshGlyphs.containsKey(charCode)) {
1022
- obj1 = this.macintoshGlyphs.getValue(charCode);
1023
- }
1024
- }
1025
- let glyph : TtfGlyphInfo = (obj1 != null) ? obj1 as TtfGlyphInfo : this.getDefaultGlyph();
1026
- return glyph;
1027
- } else {
1028
- let obj : object = null;
1029
- let code : number = charCode.charCodeAt(0);
1030
- if (!this.metrics.isSymbol && this.microsoft !== null) {
1031
- if (this.microsoft.containsKey(code)) {
1032
- obj = this.microsoft.getValue(code);
1033
- if (code !== StringTokenizer.whiteSpace.charCodeAt(0)) {
1034
- this.isFontPresent = true;
1035
- }
1036
- } else if (code !== StringTokenizer.whiteSpace.charCodeAt(0)) {
1037
- this.isFontPresent = false;
1038
- }
1039
- } else if (this.metrics.isSymbol && this.macintosh !== null || this.isMacTTF) {
1040
- // NOTE: this code fixes char codes that extends 0x100. However, it might corrupt something.
1041
- if (this.maxMacIndex !== 0) {
1042
- code %= this.maxMacIndex + 1;
1043
- } else {
1044
- code = ((code & 0xff00) === 0xf000 ? code & 0xff : code);
1045
- }
1046
- if (this.macintosh.containsKey(code)) {
1047
- obj = this.macintosh.getValue(code);
1048
- this.isFontPresent = true;
1049
- }
1050
- }
1051
- // Fix for StackOverFlow exception in XPS to PDF converter
1052
- if (charCode === StringTokenizer.whiteSpace && obj === null) {
1053
- obj = new TtfGlyphInfo();
1054
- }
1055
- let glyph : TtfGlyphInfo = (obj !== null) ? obj as TtfGlyphInfo : this.getDefaultGlyph();
1056
- return glyph;
1057
- }
1058
- }
1059
- /**
1060
- * Gets hash table with chars indexed by glyph index.
1061
- */
1062
- public getGlyphChars(chars : Dictionary<string, string>) : Dictionary<number, number> {
1063
- if (chars === null || chars === undefined) {
1064
- throw new Error('Argument Null Exception : chars');
1065
- }
1066
- let dictionary : Dictionary<number, number> = new Dictionary<number, number>();
1067
- let charKeys : string[] = chars.keys();
1068
- for (let i : number = 0; i < charKeys.length; i++) {
1069
- let ch : string = charKeys[i];
1070
- let glyph : TtfGlyphInfo = this.getGlyph(ch);
1071
- if (!glyph.empty) {
1072
- dictionary.setValue(glyph.index, ch.charCodeAt(0));
1073
- }
1074
- }
1075
- return dictionary;
1076
- }
1077
- /**
1078
- * Gets all glyphs.
1079
- */
1080
- public getAllGlyphs() : TtfGlyphInfo[] {
1081
- let allGlyphInfo : TtfGlyphInfo[] = [];
1082
- let info : TtfGlyphInfo = new TtfGlyphInfo();
1083
- let index : number = 0;
1084
- for (let i : number = 0; i < this.width.length; i++) {
1085
- let width : number = this.width[i];
1086
- info.index = index;
1087
- info.width = width;
1088
- allGlyphInfo.push(info);
1089
- index++;
1090
- }
1091
- return allGlyphInfo;
1092
- }
1093
- /**
1094
- * Reads a font's program.
1095
- * @private
1096
- */
1097
- public readFontProgram(chars : Dictionary<string, string>) : number[] {
1098
- let glyphChars : Dictionary<number, number> = this.getGlyphChars(chars);
1099
- let locaTable : TtfLocaTable = this.readLocaTable(this.bIsLocaShort);
1100
- if (glyphChars.size() < chars.size()) {
1101
- this.missedGlyphs = chars.size() - glyphChars.size();
1102
- }
1103
- this.updateGlyphChars(glyphChars, locaTable);
1104
- /* tslint:disable */
1105
- let result1 : { glyphTableSize : number, newLocaTable : number[], newGlyphTable : number[] } = this.generateGlyphTable(glyphChars, locaTable, null, null);
1106
- /* tslint:enable */
1107
- let glyphTableSize : number = result1.glyphTableSize;
1108
- let newLocaTable : number[] = result1.newLocaTable;
1109
- let newGlyphTable : number[] = result1.newGlyphTable;
1110
- let result2 : { newLocaUpdated : number[], newLocaSize : number } = this.updateLocaTable(newLocaTable, this.bIsLocaShort, null);
1111
- let newLocaSize : number = result2.newLocaSize;
1112
- let newLocaUpdated : number[] = result2.newLocaUpdated;
1113
- let fontProgram : number[] = this.getFontProgram(newLocaUpdated, newGlyphTable, glyphTableSize, newLocaSize);
1114
- return fontProgram;
1115
- }
1116
- _readCompactFontFormatTable(): number[] {
1117
- const tableInfo: TtfTableInfo = this.getTable('CFF ');
1118
- const length: number = tableInfo.length;
1119
- const offset: number = tableInfo.offset;
1120
- const cffData: number[] = new Array(length);
1121
- this.setOffset(offset);
1122
- const result : {buffer : number[], written : number} = this.read(cffData, 0, length);
1123
- return result.buffer;
1124
- }
1125
- /**
1126
- * Reconverts string to be in proper format saved into PDF file.
1127
- */
1128
- public convertString(text : string) : string {
1129
- if (text === null) {
1130
- throw new Error('Argument Null Exception : text');
1131
- }
1132
- let glyph : string = '';
1133
- let i : number = 0;
1134
- for (let k : number = 0; k < text.length; k++) {
1135
- let ch : string = text[k];
1136
- let glyphInfo : TtfGlyphInfo = this.getGlyph(ch);
1137
- if (!glyphInfo.empty) {
1138
- glyph += String.fromCharCode(glyphInfo.index);
1139
- i++;
1140
- }
1141
- }
1142
- return glyph;
1143
- }
1144
- /**
1145
- * Gets char width.
1146
- */
1147
- public getCharWidth(code : string) : number {
1148
- let glyphInfo : TtfGlyphInfo = this.getGlyph(code);
1149
- glyphInfo = (!glyphInfo.empty) ? glyphInfo : this.getDefaultGlyph();
1150
- let codeWidth : number = (!glyphInfo.empty) ? glyphInfo.width : 0;
1151
- return codeWidth;
1152
- }
1153
- //Stream reader
1154
- private readString(length : number) : string
1155
- private readString(length : number, isUnicode : boolean) : string
1156
- private readString(length : number, isUnicode ?: boolean) : string {
1157
- if (isUnicode === undefined) {
1158
- return this.readString(length, false);
1159
- } else {
1160
- //let buffer : number[] = this.readBytes(length);
1161
- let result : string = '';
1162
- if (isUnicode) {
1163
- for (let i : number = 0; i < length; i++) {
1164
- if (i % 2 !== 0) {
1165
- result += String.fromCharCode(this.fontData[this.offset]);
1166
- }
1167
- this.offset += 1;
1168
- }
1169
- } else {
1170
- for (let i : number = 0; i < length; i++) {
1171
- result += String.fromCharCode(this.fontData[this.offset]);
1172
- this.offset += 1;
1173
- }
1174
- }
1175
- return result;
1176
- }
1177
- }
1178
- private readFixed(offset : number) : number {
1179
- let integer : number = this.readInt16(offset);
1180
- let sFraction : number = this.readInt16(offset + 2);
1181
- let fraction : number = sFraction / 16384;
1182
- return integer + fraction;
1183
- }
1184
- private readInt32(offset : number) : number {
1185
- let i1 : number = this.fontData[offset + 3];
1186
- let i2 : number = this.fontData[offset + 2];
1187
- let i3 : number = this.fontData[offset + 1];
1188
- let i4 : number = this.fontData[offset];
1189
- this.offset += 4;
1190
- return i1 + (i2 << 8) + (i3 << 16) + (i4 << 24);
1191
- }
1192
- private readUInt32(offset : number) : number {
1193
- let i1 : number = this.fontData[offset + 3];
1194
- let i2 : number = this.fontData[offset + 2];
1195
- let i3 : number = this.fontData[offset + 1];
1196
- let i4 : number = this.fontData[offset];
1197
- this.offset += 4;
1198
- return (i1 | i2 << 8 | i3 << 16 | i4 << 24);
1199
- }
1200
- // private readInt16(offset : number) : number {
1201
- // let result : number = (this.fontData[offset] << 8) + this.fontData[offset + 1];
1202
- // this.offset += 2;
1203
- // return result;
1204
- // }
1205
- private readInt16(offset : number) : number {
1206
- let result : number = (this.fontData[offset] << 8) + this.fontData[offset + 1];
1207
- result = result & (1 << 15) ? result - 0x10000 : result;
1208
- this.offset += 2;
1209
- return result;
1210
- }
1211
- private readInt64(offset : number) : number {
1212
- let low : number = this.readInt32(offset + 4);
1213
- let n : number = this.readInt32(offset) * 4294967296.0 + low;
1214
- if (low < 0) {
1215
- n += 4294967296;
1216
- }
1217
- return n;
1218
- }
1219
- private readUInt16(offset : number) : number {
1220
- let result : number = (this.fontData[offset] << 8) | this.fontData[offset + 1];
1221
- this.offset += 2;
1222
- return result;
1223
- }
1224
- /**
1225
- * Reads ushort array.
1226
- */
1227
- private readUshortArray(length : number) : number[] {
1228
- let buffer : number[] = [];
1229
- for (let i : number = 0; i < length; i++) {
1230
- buffer[i] = this.readUInt16(this.offset);
1231
- }
1232
- return buffer;
1233
- }
1234
- private readBytes(length : number) : number[] {
1235
- let result : number[] = [];
1236
- for (let i : number = 0; i < length; i++) {
1237
- result.push(this.fontData[this.offset]);
1238
- this.offset += 1;
1239
- }
1240
- return result;
1241
- }
1242
- private readByte(offset : number) : number {
1243
- let result : number = this.fontData[offset];
1244
- this.offset += 1;
1245
- return result;
1246
- }
1247
- /**
1248
- * Reads bytes to array in BigEndian order.
1249
- * @private
1250
- */
1251
- public read(buffer : number[], index : number, count : number) : { buffer : number[], written : number } {
1252
- if (buffer === null) {
1253
- throw new Error('Argument Null Exception : buffer');
1254
- }
1255
- let written : number = 0;
1256
- let read : number = 0;
1257
- do {
1258
- for (let i : number = 0; (i < count - written) && (this.offset + i < this.fontData.length); i++) {
1259
- buffer[index + i] = this.fontData[this.offset + i];
1260
- }
1261
- read = count - written;
1262
- this.offset += read;
1263
- written += read;
1264
- } while (written < count);
1265
- return { buffer : buffer, written : written };
1266
- }
1267
- }