abstract-document 6.8.7 → 6.9.3

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 (433) hide show
  1. package/CHANGELOG.md +150 -127
  2. package/LICENSE +21 -21
  3. package/README.md +45 -45
  4. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/group.d.ts.map +1 -1
  5. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/group.js +229 -92
  6. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/group.js.map +1 -1
  7. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/header-and-footer.js +69 -69
  8. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/hello.js +51 -51
  9. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/letter-dimensions.js +51 -51
  10. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/mixed-hyperlink-and-textrun.js +115 -115
  11. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/mixed-textrun-and-images.d.ts.map +1 -1
  12. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/mixed-textrun-and-images.js +175 -170
  13. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/mixed-textrun-and-images.js.map +1 -1
  14. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-images.d.ts.map +1 -1
  15. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-images.js +147 -142
  16. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-images.js.map +1 -1
  17. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.js +467 -467
  18. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-center-alignment.js +97 -97
  19. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-end-alignment.js +97 -97
  20. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment-that-linebreaks.js +96 -96
  21. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment.js +96 -96
  22. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-numbering.js +102 -102
  23. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-landscape.d.ts +3 -0
  24. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-landscape.d.ts.map +1 -0
  25. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-landscape.js +94 -0
  26. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-landscape.js.map +1 -0
  27. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-portrait.d.ts +3 -0
  28. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-portrait.d.ts.map +1 -0
  29. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-portrait.js +94 -0
  30. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-portrait.js.map +1 -0
  31. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/simple-table-colSpan-and-rowSpan.js +498 -498
  32. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/simple-table-without-rows.js +20 -20
  33. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.js +167 -167
  34. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-hyperlink.js +70 -70
  35. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-png.d.ts +3 -0
  36. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-png.d.ts.map +1 -0
  37. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-png.js +149 -0
  38. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-png.js.map +1 -0
  39. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-svg.d.ts +3 -0
  40. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-svg.d.ts.map +1 -0
  41. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-svg.js +149 -0
  42. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image-svg.js.map +1 -0
  43. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image.d.ts.map +1 -1
  44. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image.js +103 -98
  45. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-image.js.map +1 -1
  46. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment-that-linebreaks.js +68 -68
  47. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment.js +68 -68
  48. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment-that-linebreaks.js +68 -68
  49. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment.js +68 -68
  50. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment-that-linebreaks.js +68 -68
  51. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment.js +68 -68
  52. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun.js +68 -68
  53. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/toc-separator.d.ts +3 -0
  54. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/toc-separator.d.ts.map +1 -0
  55. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/toc-separator.js +67 -0
  56. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/toc-separator.js.map +1 -0
  57. package/lib/abstract-document-exporters/__tests__/docx2/test-defs/world.js +51 -51
  58. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/group.d.ts +3 -0
  59. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/group.d.ts.map +1 -0
  60. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/group.js +83 -0
  61. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/group.js.map +1 -0
  62. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/mixed-textrun-and-images.d.ts.map +1 -1
  63. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/mixed-textrun-and-images.js +6 -1
  64. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/mixed-textrun-and-images.js.map +1 -1
  65. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images-overflow.d.ts.map +1 -1
  66. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images-overflow.js +6 -1
  67. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images-overflow.js.map +1 -1
  68. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images.d.ts.map +1 -1
  69. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images.js +6 -1
  70. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images.js.map +1 -1
  71. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.d.ts +3 -0
  72. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.d.ts.map +1 -0
  73. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.js +105 -0
  74. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-auto-cell-widths.js.map +1 -0
  75. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-cell-padding-image.d.ts.map +1 -1
  76. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-cell-padding-image.js +6 -1
  77. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-cell-padding-image.js.map +1 -1
  78. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.d.ts +3 -0
  79. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.d.ts.map +1 -0
  80. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.js +104 -0
  81. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-fixed-cell-widths.js.map +1 -0
  82. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table.d.ts +3 -0
  83. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table.d.ts.map +1 -0
  84. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table.js +104 -0
  85. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/simple-table.js.map +1 -0
  86. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.d.ts.map +1 -1
  87. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.js +6 -1
  88. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.js.map +1 -1
  89. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-name.d.ts.map +1 -1
  90. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-name.js +6 -1
  91. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-name.js.map +1 -1
  92. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.d.ts.map +1 -1
  93. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.js +6 -1
  94. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.js.map +1 -1
  95. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-dasharray.d.ts.map +1 -1
  96. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-dasharray.js +6 -1
  97. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-dasharray.js.map +1 -1
  98. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-url.d.ts +3 -0
  99. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-url.d.ts.map +1 -0
  100. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-url.js +86 -0
  101. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image-url.js.map +1 -0
  102. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image.d.ts.map +1 -1
  103. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image.js +6 -1
  104. package/lib/abstract-document-exporters/__tests__/pdf/test-defs/single-image.js.map +1 -1
  105. package/lib/abstract-document-exporters/docx2/render-image.js +2 -2
  106. package/lib/abstract-document-exporters/docx2/render-image.js.map +1 -1
  107. package/lib/abstract-document-exporters/docx2/render.js +29 -17
  108. package/lib/abstract-document-exporters/docx2/render.js.map +1 -1
  109. package/lib/abstract-document-exporters/pdf/render-image.js +9 -4
  110. package/lib/abstract-document-exporters/pdf/render-image.js.map +1 -1
  111. package/package.json +3 -3
  112. package/src/abstract-document/__tests__/hello-world-abstract-doc.ts +245 -245
  113. package/src/abstract-document/__tests__/markdown/export-test-def.ts +10 -10
  114. package/src/abstract-document/__tests__/markdown/export.test.tsx +15 -15
  115. package/src/abstract-document/__tests__/markdown/test-defs/markdown-bold-italic.tsx +31 -31
  116. package/src/abstract-document/__tests__/markdown/test-defs/markdown-bold.tsx +31 -31
  117. package/src/abstract-document/__tests__/markdown/test-defs/markdown-empty-keepTogether.tsx +54 -54
  118. package/src/abstract-document/__tests__/markdown/test-defs/markdown-header.tsx +38 -38
  119. package/src/abstract-document/__tests__/markdown/test-defs/markdown-italic.tsx +31 -31
  120. package/src/abstract-document/__tests__/markdown/test-defs/markdown-keepTogether.tsx +61 -61
  121. package/src/abstract-document/__tests__/markdown/test-defs/markdown-subscript.tsx +45 -45
  122. package/src/abstract-document/__tests__/markdown/test-defs/markdown-superscript.tsx +38 -38
  123. package/src/abstract-document/__tests__/model-builder._test.ts +48 -48
  124. package/src/abstract-document/abstract-doc.ts +19 -19
  125. package/src/abstract-document/atoms/atom.ts +14 -14
  126. package/src/abstract-document/atoms/hyper-link.ts +27 -27
  127. package/src/abstract-document/atoms/image.ts +21 -21
  128. package/src/abstract-document/atoms/link-target.ts +15 -15
  129. package/src/abstract-document/atoms/text-field.ts +36 -36
  130. package/src/abstract-document/atoms/text-run.ts +25 -25
  131. package/src/abstract-document/atoms/toc-separator.ts +18 -18
  132. package/src/abstract-document/default-styles.ts +145 -145
  133. package/src/abstract-document/index.ts +89 -89
  134. package/src/abstract-document/markdown/markdown.ts +142 -142
  135. package/src/abstract-document/markdown/types.ts +78 -78
  136. package/src/abstract-document/numberings/numbering-definition.ts +17 -17
  137. package/src/abstract-document/numberings/numbering-format.ts +7 -7
  138. package/src/abstract-document/numberings/numbering-level-definition.ts +42 -42
  139. package/src/abstract-document/numberings/numbering.ts +3 -3
  140. package/src/abstract-document/page/master-page.ts +23 -23
  141. package/src/abstract-document/page/section.ts +27 -27
  142. package/src/abstract-document/primitives/font.ts +37 -37
  143. package/src/abstract-document/primitives/image-resource.ts +27 -27
  144. package/src/abstract-document/primitives/layout-foundation-color.ts +37 -37
  145. package/src/abstract-document/primitives/layout-foundation.ts +37 -37
  146. package/src/abstract-document/primitives/length.ts +11 -11
  147. package/src/abstract-document/primitives/point.ts +11 -11
  148. package/src/abstract-document/primitives/rect.ts +15 -15
  149. package/src/abstract-document/primitives/size.ts +13 -13
  150. package/src/abstract-document/resources.ts +101 -101
  151. package/src/abstract-document/section-elements/group.ts +28 -28
  152. package/src/abstract-document/section-elements/page-break.ts +14 -14
  153. package/src/abstract-document/section-elements/paragraph-numbering.ts +6 -6
  154. package/src/abstract-document/section-elements/paragraph.ts +32 -32
  155. package/src/abstract-document/section-elements/section-element.ts +17 -17
  156. package/src/abstract-document/section-elements/table.ts +34 -34
  157. package/src/abstract-document/styles/group-style.ts +30 -30
  158. package/src/abstract-document/styles/page-style.ts +76 -76
  159. package/src/abstract-document/styles/paragraph-style.ts +49 -49
  160. package/src/abstract-document/styles/position.ts +8 -8
  161. package/src/abstract-document/styles/style-key.ts +5 -5
  162. package/src/abstract-document/styles/style.ts +44 -44
  163. package/src/abstract-document/styles/table-cell-style.ts +59 -59
  164. package/src/abstract-document/styles/table-style.ts +46 -46
  165. package/src/abstract-document/styles/text-style.ts +77 -77
  166. package/src/abstract-document/table/table-cell.ts +31 -31
  167. package/src/abstract-document/table/table-row.ts +14 -14
  168. package/src/abstract-document/types.ts +3 -3
  169. package/src/abstract-document-exporters/__tests__/docx2/export-test-def.ts +10 -10
  170. package/src/abstract-document-exporters/__tests__/docx2/export.test.tsx +67 -67
  171. package/src/abstract-document-exporters/__tests__/docx2/test-defs/group.tsx +267 -114
  172. package/src/abstract-document-exporters/__tests__/docx2/test-defs/header-and-footer.tsx +110 -110
  173. package/src/abstract-document-exporters/__tests__/docx2/test-defs/hello.tsx +70 -70
  174. package/src/abstract-document-exporters/__tests__/docx2/test-defs/letter-dimensions.tsx +74 -74
  175. package/src/abstract-document-exporters/__tests__/docx2/test-defs/mixed-hyperlink-and-textrun.tsx +137 -137
  176. package/src/abstract-document-exporters/__tests__/docx2/test-defs/mixed-textrun-and-images.tsx +217 -212
  177. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-images.tsx +187 -182
  178. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-tables.tsx +553 -553
  179. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-center-alignment.tsx +119 -119
  180. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-end-alignment.tsx +119 -119
  181. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment-that-linebreaks.tsx +121 -121
  182. package/src/abstract-document-exporters/__tests__/docx2/test-defs/multiple-textrun-with-start-alignment.tsx +118 -118
  183. package/src/abstract-document-exporters/__tests__/docx2/test-defs/page-numbering.tsx +123 -123
  184. package/src/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-landscape.tsx +76 -0
  185. package/src/abstract-document-exporters/__tests__/docx2/test-defs/page-orientation-portrait.tsx +76 -0
  186. package/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table-colSpan-and-rowSpan.tsx +587 -587
  187. package/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table-without-rows.tsx +45 -45
  188. package/src/abstract-document-exporters/__tests__/docx2/test-defs/simple-table.tsx +210 -210
  189. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-hyperlink.tsx +89 -89
  190. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-image.tsx +142 -137
  191. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment-that-linebreaks.tsx +88 -88
  192. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-center-alignment.tsx +88 -88
  193. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment-that-linebreaks.tsx +88 -88
  194. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-end-alignment.tsx +88 -88
  195. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment-that-linebreaks.tsx +88 -88
  196. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun-with-start-alignment.tsx +88 -88
  197. package/src/abstract-document-exporters/__tests__/docx2/test-defs/single-textrun.tsx +87 -87
  198. package/src/abstract-document-exporters/__tests__/docx2/test-defs/toc-separator.tsx +67 -0
  199. package/src/abstract-document-exporters/__tests__/docx2/test-defs/world.tsx +70 -70
  200. package/src/abstract-document-exporters/__tests__/docx2/tmp/Group.docx +0 -0
  201. package/src/abstract-document-exporters/__tests__/docx2/tmp/Header and footer.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Header → footer.docx +0 -0
  202. package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink and textrun.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed hyperlink → textrun.docx +0 -0
  203. package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun and images.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Mixed textrun → images.docx +0 -0
  204. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple images.docx +0 -0
  205. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple tables.docx +0 -0
  206. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Center alignment.docx +0 -0
  207. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with End alignment.docx +0 -0
  208. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment that linebreaks.docx +0 -0
  209. package/src/abstract-document-exporters/__tests__/docx2/tmp/Multiple textrun with Start alignment.docx +0 -0
  210. package/src/abstract-document-exporters/__tests__/docx2/tmp/Page numbering.docx +0 -0
  211. package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan and rowSpan.docx and b/package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table colSpan → rowSpan.docx +0 -0
  212. package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table without rows.docx +0 -0
  213. package/src/abstract-document-exporters/__tests__/docx2/tmp/Simple table.docx +0 -0
  214. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single hyperlink.docx +0 -0
  215. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single image svg.docx +0 -0
  216. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single image.docx +0 -0
  217. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment that linebreaks.docx +0 -0
  218. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Center alignment.docx +0 -0
  219. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment that linebreaks.docx +0 -0
  220. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with End alignment.docx +0 -0
  221. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment that linebreaks.docx +0 -0
  222. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun with Start alignment.docx +0 -0
  223. package/src/abstract-document-exporters/__tests__/docx2/tmp/Single textrun.docx +0 -0
  224. package/src/abstract-document-exporters/__tests__/docx2/tmp/hello.docx +0 -0
  225. package/src/abstract-document-exporters/__tests__/docx2/tmp/letter-dimensions.docx +0 -0
  226. package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-landscape.docx +0 -0
  227. package/src/abstract-document-exporters/__tests__/docx2/tmp/page-orientation-portrait.docx +0 -0
  228. package/src/abstract-document-exporters/__tests__/docx2/tmp/tocSeparator.docx +0 -0
  229. package/src/abstract-document-exporters/__tests__/docx2/tmp/world.docx +0 -0
  230. package/src/abstract-document-exporters/__tests__/pdf/export-test-def.ts +10 -10
  231. package/src/abstract-document-exporters/__tests__/pdf/export.test.tsx +46 -46
  232. package/src/abstract-document-exporters/__tests__/pdf/test-defs/absolute-position-group.tsx +77 -77
  233. package/src/abstract-document-exporters/__tests__/pdf/test-defs/absolute-position-header-and-footer.tsx +205 -205
  234. package/src/abstract-document-exporters/__tests__/pdf/test-defs/absolute-position-paragraph.tsx +51 -51
  235. package/src/abstract-document-exporters/__tests__/pdf/test-defs/absolute-position-section-in-group.tsx +96 -96
  236. package/src/abstract-document-exporters/__tests__/pdf/test-defs/absolute-position-section-in-table.tsx +145 -145
  237. package/src/abstract-document-exporters/__tests__/pdf/test-defs/absolute-position-table.tsx +117 -117
  238. package/src/abstract-document-exporters/__tests__/pdf/test-defs/date.tsx +66 -66
  239. package/src/abstract-document-exporters/__tests__/pdf/test-defs/group-no-keep-together.tsx +1287 -1287
  240. package/src/abstract-document-exporters/__tests__/pdf/test-defs/group-paragraphs.tsx +1291 -1291
  241. package/src/abstract-document-exporters/__tests__/pdf/test-defs/group-tables.tsx +1314 -1314
  242. package/src/abstract-document-exporters/__tests__/pdf/test-defs/group-too-big-for-one-page.tsx +272 -272
  243. package/src/abstract-document-exporters/__tests__/pdf/test-defs/header-and-footer.tsx +162 -162
  244. package/src/abstract-document-exporters/__tests__/pdf/test-defs/hello.tsx +45 -45
  245. package/src/abstract-document-exporters/__tests__/pdf/test-defs/hyperlink-intenal-link-target.tsx +831 -831
  246. package/src/abstract-document-exporters/__tests__/pdf/test-defs/hyperlink-internal.tsx +811 -811
  247. package/src/abstract-document-exporters/__tests__/pdf/test-defs/margins-header-body-footer.tsx +1008 -1008
  248. package/src/abstract-document-exporters/__tests__/pdf/test-defs/mixed-hyperlink-and-textrun-no-underline.tsx +114 -114
  249. package/src/abstract-document-exporters/__tests__/pdf/test-defs/mixed-hyperlink-and-textrun-with-underline.tsx +114 -114
  250. package/src/abstract-document-exporters/__tests__/pdf/test-defs/mixed-hyperlink-and-textrun.tsx +113 -113
  251. package/src/abstract-document-exporters/__tests__/pdf/test-defs/mixed-textrun-and-images.tsx +109 -104
  252. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images-overflow.tsx +80 -75
  253. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-images.tsx +76 -71
  254. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-center-alignment.tsx +98 -98
  255. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-end-alignment.tsx +98 -98
  256. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-start-alignment-that-linebreaks.tsx +116 -116
  257. package/src/abstract-document-exporters/__tests__/pdf/test-defs/multiple-textrun-with-start-alignment.tsx +98 -98
  258. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-row-that-doesnt-fit-page.tsx +317 -317
  259. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-single-row.tsx +227 -227
  260. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-group.tsx +500 -500
  261. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-header.tsx +1555 -1555
  262. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-header2.tsx +824 -824
  263. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-margin-bottom.tsx +455 -455
  264. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-margin-top-single-table.tsx +354 -354
  265. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-margin-top.tsx +455 -455
  266. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-rowSpan-multipages.tsx +1567 -1567
  267. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-break-table-with-rowSpan.tsx +545 -545
  268. package/src/abstract-document-exporters/__tests__/pdf/test-defs/page-numbering.tsx +97 -97
  269. package/src/abstract-document-exporters/__tests__/pdf/test-defs/pagebreak.tsx +102 -102
  270. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-all-auto-cell-widths.tsx +119 -119
  271. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-all-fixed-cell-widths.tsx +119 -119
  272. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-background.tsx +182 -182
  273. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-cell-padding-image.tsx +205 -200
  274. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-cell-padding-text.tsx +338 -338
  275. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-center-alignment.tsx +114 -114
  276. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-colSpan-and-rowSpan.tsx +425 -425
  277. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-mix-auto-fix-cell-widths.tsx +119 -119
  278. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-padding.tsx +115 -115
  279. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-right-alignment.tsx +115 -115
  280. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-row-alignment.tsx +297 -297
  281. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-text-alignment-in-cell-wrapping.tsx +491 -491
  282. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-text-alignment-in-cell.tsx +248 -248
  283. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-with-default-colored-borders.tsx +223 -223
  284. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-with-header.tsx +482 -482
  285. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-with-multi-colored-borders.tsx +236 -236
  286. package/src/abstract-document-exporters/__tests__/pdf/test-defs/simple-table-with-single-colored-borders.tsx +236 -236
  287. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-figure.tsx +323 -323
  288. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-hyperlink-center.tsx +66 -66
  289. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-hyperlink-no-underline.tsx +70 -70
  290. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-hyperlink-right-aligned.tsx +66 -66
  291. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-hyperlink-with-underline.tsx +70 -70
  292. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-hyperlink.tsx +65 -65
  293. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-hex.tsx +277 -272
  294. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-name.tsx +277 -272
  295. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-color-url.tsx +102 -97
  296. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-svg-dasharray.tsx +90 -85
  297. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image-url.tsx +75 -0
  298. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-image.tsx +75 -70
  299. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-baseline-alphabetic.tsx +46 -46
  300. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-baseline-bottom.tsx +46 -46
  301. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-baseline-hanging.tsx +46 -46
  302. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-baseline-middle.tsx +46 -46
  303. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-baseline-top.tsx +46 -46
  304. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-super-subscript.tsx +98 -98
  305. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-center-alignment-that-linebreaks.tsx +81 -81
  306. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-center-alignment.tsx +66 -66
  307. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-end-alignment-that-linebreaks.tsx +81 -81
  308. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-end-alignment.tsx +66 -66
  309. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-justify-alignment.tsx +66 -66
  310. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-start-alignment-that-linebreaks.tsx +81 -81
  311. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun-with-start-alignment.tsx +66 -66
  312. package/src/abstract-document-exporters/__tests__/pdf/test-defs/single-textrun.tsx +45 -45
  313. package/src/abstract-document-exporters/__tests__/pdf/test-defs/table-of-content-separator.tsx +81 -81
  314. package/src/abstract-document-exporters/__tests__/pdf/test-defs/world.tsx +45 -45
  315. package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position group.pdf +2 -2
  316. package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position header and footer.pdf +2 -2
  317. package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position paragraph.pdf +2 -2
  318. package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in group.pdf +2 -2
  319. package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position section in table.pdf +2 -2
  320. package/src/abstract-document-exporters/__tests__/pdf/tmp/Absolute position table.pdf +2 -2
  321. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Paragraphs.pdf +2 -2
  322. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Paratraphs.pdf +912 -0
  323. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group Tables.pdf +2 -2
  324. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group no keeptogether.pdf +2 -2
  325. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group too big for one page.pdf +2 -2
  326. package/src/abstract-document-exporters/__tests__/pdf/tmp/Group.pdf +123 -0
  327. package/src/abstract-document-exporters/__tests__/pdf/tmp/Header and footer.pdf +2 -2
  328. package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal linktarget.pdf +2 -2
  329. package/src/abstract-document-exporters/__tests__/pdf/tmp/Hyperlink internal.pdf +2 -2
  330. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer.pdf +2 -2
  331. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer1.pdf +640 -0
  332. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer2.pdf +609 -0
  333. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer3.pdf +1188 -0
  334. package/src/abstract-document-exporters/__tests__/pdf/tmp/Margins header body footer4.pdf +1188 -0
  335. package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun no underline.pdf +2 -2
  336. package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun with underline.pdf +2 -2
  337. package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed hyperlink and textrun.pdf +2 -2
  338. package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun and images.pdf and b/package/src/abstract-document-exporters/__tests__/pdf/tmp/Mixed textrun → images.pdf +0 -0
  339. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images overflow.pdf +0 -0
  340. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple images.pdf +0 -0
  341. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Center alignment.pdf +2 -2
  342. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with End alignment.pdf +2 -2
  343. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment that linebreaks.pdf +2 -2
  344. package/src/abstract-document-exporters/__tests__/pdf/tmp/Multiple textrun with Start alignment.pdf +2 -2
  345. package/src/abstract-document-exporters/__tests__/pdf/tmp/Page numbering.pdf +2 -2
  346. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table row that doesnt fit page.pdf +2 -2
  347. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table single row.pdf +2 -2
  348. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with group.pdf +2 -2
  349. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header 2.pdf +2 -2
  350. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with header.pdf +2 -2
  351. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin bottom.pdf +2 -2
  352. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top single table.pdf +2 -2
  353. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with margin top.pdf +2 -2
  354. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan multipages.pdf +2 -2
  355. package/src/abstract-document-exporters/__tests__/pdf/tmp/Pagebreak table with rowSpan.pdf +2 -2
  356. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all auto.pdf +2 -2
  357. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table all fix.pdf +2 -2
  358. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table auto.pdf +133 -0
  359. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table background.pdf +2 -2
  360. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of image.pdf +0 -0
  361. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table cell padding of text.pdf +2 -2
  362. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table center alignment.pdf +2 -2
  363. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table colSpan and rowSpan.pdf +2 -2
  364. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table mix auto fix.pdf +2 -2
  365. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table one auto.pdf +133 -0
  366. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table padding.pdf +2 -2
  367. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table padding1.pdf +133 -0
  368. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table right alignment.pdf +2 -2
  369. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table row alignment.pdf +2 -2
  370. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell with wrapping.pdf +2 -2
  371. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table text alignment in cell.pdf +2 -2
  372. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with default colored borders.pdf +2 -2
  373. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with header.pdf +2 -2
  374. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with multi colored borders.pdf +2 -2
  375. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table with single colored borders.pdf +2 -2
  376. package/src/abstract-document-exporters/__tests__/pdf/tmp/Simple table.pdf +133 -0
  377. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single date.pdf +14 -14
  378. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single figure.pdf +2 -2
  379. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink centered.pdf +2 -2
  380. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink no underline.pdf +2 -2
  381. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink right aligned.pdf +2 -2
  382. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single hyperlink.pdf +2 -2
  383. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image from URL.pdf +0 -0
  384. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color hex.pdf +2 -2
  385. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color name.pdf +2 -2
  386. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color url.pdf +2 -2
  387. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg color.pdf +179 -0
  388. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image svg dasharray.pdf +2 -2
  389. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single image.pdf +0 -0
  390. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline alphabetic.pdf +2 -2
  391. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline bottom.pdf +2 -2
  392. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline hanging.pdf +2 -2
  393. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline middle.pdf +2 -2
  394. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun baseline top.pdf +2 -2
  395. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment that linebreaks.pdf +2 -2
  396. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Center alignment.pdf +2 -2
  397. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment that linebreaks.pdf +2 -2
  398. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with End alignment.pdf +2 -2
  399. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Justify alignment.pdf +2 -2
  400. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment that linebreaks.pdf +2 -2
  401. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with Start alignment.pdf +2 -2
  402. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun with super and subscripts.pdf +2 -2
  403. package/src/abstract-document-exporters/__tests__/pdf/tmp/Single textrun.pdf +2 -2
  404. package/src/abstract-document-exporters/__tests__/pdf/tmp/Table of content separator.pdf +2 -2
  405. package/src/abstract-document-exporters/__tests__/pdf/tmp/hello.pdf +2 -2
  406. package/src/abstract-document-exporters/__tests__/pdf/tmp/world.pdf +2 -2
  407. package/src/abstract-document-exporters/docx/document-container.ts +18 -18
  408. package/src/abstract-document-exporters/docx/docx-constants.ts +46 -46
  409. package/src/abstract-document-exporters/docx/docx-document-renderer.ts +1084 -1084
  410. package/src/abstract-document-exporters/docx/ref-container.ts +53 -53
  411. package/src/abstract-document-exporters/docx/string-utils.ts +39 -39
  412. package/src/abstract-document-exporters/docx/xml-writer.ts +333 -333
  413. package/src/abstract-document-exporters/docx2/render-image.ts +159 -159
  414. package/src/abstract-document-exporters/docx2/render.ts +516 -496
  415. package/src/abstract-document-exporters/index.ts +5 -5
  416. package/src/abstract-document-exporters/pdf/font.ts +76 -76
  417. package/src/abstract-document-exporters/pdf/measure.ts +418 -418
  418. package/src/abstract-document-exporters/pdf/paginate.ts +434 -434
  419. package/src/abstract-document-exporters/pdf/pre-process.ts +389 -389
  420. package/src/abstract-document-exporters/pdf/render-image.ts +221 -217
  421. package/src/abstract-document-exporters/pdf/render.ts +847 -847
  422. package/src/abstract-document-exporters/pdf/update-refs.ts +163 -163
  423. package/src/abstract-document-exporters/shared/get_resources.ts +71 -71
  424. package/src/abstract-document-jsx/index.ts +86 -86
  425. package/src/custom_typings/@textlint/markdown-to-ast/index.d.ts +1 -1
  426. package/src/custom_typings/json-diff/index.d.ts +1 -1
  427. package/src/custom_typings/markdown-parser/index.d.ts +1 -1
  428. package/src/custom_typings/pdf2json/index.d.ts +1 -1
  429. package/src/custom_typings/remark-parse/index.d.ts +1 -1
  430. package/src/custom_typings/remark-sub-super/index.d.ts +1 -1
  431. package/src/custom_typings/svg-to-pdfkit/index.d.ts +1 -1
  432. package/src/custom_typings/unified/index.d.ts +1 -1
  433. package/src/index.ts +5 -5
@@ -1,847 +1,847 @@
1
- import * as AD from "../../abstract-document/index";
2
- import { preProcess } from "./pre-process";
3
- import { measure, measurePages } from "./measure";
4
- import { paginate, Page } from "./paginate";
5
- import { updatePageRefs } from "./update-refs";
6
- import BlobStream from "blob-stream";
7
- import { renderImage } from "./render-image";
8
- import { registerFonts, getFontNameStyle } from "./font";
9
-
10
- type RowSpans = Map<number, { rowSpanLeft: number; colSpan: number }>;
11
-
12
- export function exportToHTML5Blob(
13
- // tslint:disable-next-line:no-any
14
- pdfKit: any,
15
- doc: AD.AbstractDoc.AbstractDoc
16
- ): Promise<Blob> {
17
- return new Promise((resolve) => {
18
- const stream = BlobStream();
19
- exportToStream(pdfKit, stream, doc);
20
- stream.on("finish", () => {
21
- const blob = stream.toBlob("application/pdf");
22
- resolve(blob);
23
- });
24
- });
25
- }
26
-
27
- /**
28
- * On the client side the stream can be a BlobStream from the blob-stream package.
29
- * On the server-side the stream can be a file stream from the fs package.
30
- * @param pdfKit
31
- * @param blobStream
32
- * @param doc
33
- */
34
- export function exportToStream(pdfKit: any, blobStream: {}, doc: AD.AbstractDoc.AbstractDoc): void {
35
- const PDFDocument = pdfKit;
36
- const document = preProcess(doc);
37
-
38
- let pdf = new PDFDocument({
39
- compress: false,
40
- autoFirstPage: false,
41
- bufferPages: true,
42
- }) as any;
43
-
44
- registerFonts((fontName: string, fontSource: AD.Font.FontSource) => pdf.registerFont(fontName, fontSource), document);
45
-
46
- const desiredSizes = measure(pdfKit, document);
47
- const pages = paginate(pdfKit, document, desiredSizes);
48
- const updatedPages = updatePageRefs(pages);
49
- const pageDesiredSizes = measurePages(pdfKit, document, updatedPages);
50
-
51
- for (let page of updatedPages) {
52
- renderPage(document, pdf, pageDesiredSizes, page);
53
- }
54
-
55
- pdf.pipe(blobStream);
56
- pdf.end();
57
- }
58
-
59
- // // Can only be used on the server-side
60
- // export function exportToNodeStream(pdfKit: any, doc: AD.AbstractDoc.AbstractDoc, stream: any): void {
61
- // const PDFDocument = pdfKit;
62
- // const document = preProcess(doc);
63
- // const desiredSizes = measure(pdfKit, document);
64
- // let pdf = new PDFDocument({compress: false, autoFirstPage: false}) as any;
65
- // registerFonts(
66
- // (fontName: string, fontSource: AD.Font.FontSource) =>
67
- // pdf.registerFont(fontName, fontSource),
68
- // document
69
- // );
70
- // let pageNo = 0;
71
- // for (let section of document.children){
72
- // pageNo = renderSection(document, pdf, desiredSizes, section, pageNo);
73
- // }
74
- // pdf.pipe(stream);
75
- // pdf.end();
76
- // }
77
-
78
- function renderPage(
79
- parentResources: AD.Resources.Resources,
80
- pdf: any,
81
- desiredSizes: Map<{}, AD.Size.Size>,
82
- page: Page
83
- ): void {
84
- const section = page.section;
85
- const style = section.page.style;
86
- const resources = AD.Resources.mergeResources([parentResources, section]);
87
- const pageHeight = AD.PageStyle.getHeight(style);
88
- const contentRect = addPage(pdf, page);
89
-
90
- page.namedDestionations.forEach((dest) => {
91
- if (pdf.addNamedDestination) {
92
- pdf.addNamedDestination(dest);
93
- }
94
- });
95
-
96
- const headerX = style.headerMargins.left;
97
- const headerStart = style.headerMargins.top;
98
- let headerY = headerStart;
99
- for (let element of page.header) {
100
- const elementSize = getDesiredSize(element, desiredSizes);
101
- const isAbsolute = AD.Position.isPositionAbsolute(element);
102
- renderSectionElement(
103
- resources,
104
- pdf,
105
- desiredSizes,
106
- AD.Rect.create(headerX, isAbsolute ? headerStart : headerY, elementSize.width, elementSize.height),
107
- element
108
- );
109
- if (!isAbsolute) {
110
- headerY += elementSize.height;
111
- }
112
- }
113
- headerY += style.headerMargins.bottom;
114
-
115
- const footerHeight = page.footer.reduce(
116
- (a, b) => a + (AD.Position.isPositionAbsolute(b) ? 0 : getDesiredSize(b, desiredSizes).height),
117
- style.footerMargins.top + style.footerMargins.bottom
118
- );
119
- const footerX = style.footerMargins.left;
120
- const footerStart = pageHeight - (footerHeight - style.footerMargins.top);
121
- let footerY = footerStart;
122
- for (let element of page.footer) {
123
- const elementSize = getDesiredSize(element, desiredSizes);
124
- const isAbsolute = AD.Position.isPositionAbsolute(element);
125
- renderSectionElement(
126
- resources,
127
- pdf,
128
- desiredSizes,
129
- AD.Rect.create(footerX, isAbsolute ? footerStart : footerY, elementSize.width, elementSize.height),
130
- element
131
- );
132
- if (!isAbsolute) {
133
- footerY += elementSize.height;
134
- }
135
- }
136
-
137
- const elementStart = contentRect.y;
138
- let y = elementStart;
139
- for (const element of page.elements) {
140
- const elementSize = getDesiredSize(element, desiredSizes);
141
- const isAbsolute = AD.Position.isPositionAbsolute(element);
142
- renderSectionElement(
143
- resources,
144
- pdf,
145
- desiredSizes,
146
- AD.Rect.create(contentRect.x, isAbsolute ? elementStart : y, elementSize.width, elementSize.height),
147
- element
148
- );
149
- if (!isAbsolute) {
150
- y += elementSize.height;
151
- }
152
- }
153
- }
154
-
155
- function addPage(pdf: any, page: Page): AD.Rect.Rect {
156
- const section = page.section;
157
- const style = section.page.style;
158
- // This is rotated later depending on the orientation.
159
- const pageWidth = AD.PageStyle.getPaperWidth(style.paperSize);
160
- const pageHeight = AD.PageStyle.getPaperHeight(style.paperSize);
161
- const layout = style.orientation === "Landscape" ? "landscape" : "portrait";
162
- const pageOptions = {
163
- size: [pageWidth, pageHeight],
164
- layout: layout,
165
- margins: {
166
- top: 0,
167
- left: 0,
168
- right: 0,
169
- bottom: 0,
170
- },
171
- };
172
- pdf.addPage(pageOptions);
173
- return page.contentRect;
174
- }
175
-
176
- function renderSectionElement(
177
- parentResources: AD.Resources.Resources,
178
- pdf: {},
179
- desiredSizes: Map<{}, AD.Size.Size>,
180
- finalRect: AD.Rect.Rect,
181
- element: AD.SectionElement.SectionElement
182
- ): void {
183
- const resources = AD.Resources.mergeResources([parentResources, element]);
184
- switch (element.type) {
185
- case "Paragraph":
186
- renderParagraph(resources, pdf, desiredSizes, finalRect, element);
187
- return;
188
- case "Table":
189
- renderTable(resources, pdf, desiredSizes, finalRect, element);
190
- return;
191
- case "Group":
192
- renderGroup(resources, pdf, desiredSizes, finalRect, element);
193
- return;
194
- }
195
- }
196
-
197
- function renderGroup(
198
- resources: AD.Resources.Resources,
199
- pdf: {},
200
- desiredSizes: Map<{}, AD.Size.Size>,
201
- finalRect: AD.Rect.Rect,
202
- group: AD.Group.Group
203
- ): void {
204
- const finalX = finalRect.x + group.style.margins.left;
205
- const startY = finalRect.y + group.style.margins.top;
206
- let y = startY;
207
- for (const element of group.children) {
208
- const elementSize = getDesiredSize(element, desiredSizes);
209
- const isAbsolute = AD.Position.isPositionAbsolute(element);
210
- renderSectionElement(
211
- resources,
212
- pdf,
213
- desiredSizes,
214
- AD.Rect.create(finalX, isAbsolute ? startY : y, elementSize.width, elementSize.height),
215
- element
216
- );
217
- if (!isAbsolute) {
218
- y += elementSize.height;
219
- }
220
- }
221
- }
222
-
223
- function renderParagraph(
224
- resources: AD.Resources.Resources,
225
- pdf: {},
226
- desiredSizes: Map<{}, AD.Size.Size>,
227
- finalRect: AD.Rect.Rect,
228
- paragraph: AD.Paragraph.Paragraph
229
- ): void {
230
- const style = AD.Resources.getStyle(
231
- undefined,
232
- paragraph.style,
233
- "ParagraphStyle",
234
- paragraph.styleName,
235
- resources
236
- ) as AD.ParagraphStyle.ParagraphStyle;
237
- const availableWidth = finalRect.width - (style.margins.left + style.margins.right);
238
-
239
- let rows: Array<Array<AD.Atom.Atom>> = [];
240
- let currentRow: Array<AD.Atom.Atom> = [];
241
- let currentWidth = 0;
242
- let previousAtomType: string | undefined;
243
- for (const atom of paragraph.children) {
244
- if (!previousAtomType) {
245
- // First atom
246
- previousAtomType = atom.type;
247
- currentRow.push(atom);
248
- const atomSize = getDesiredSize(atom, desiredSizes);
249
- currentWidth = atomSize.width;
250
- continue;
251
- }
252
-
253
- if (atom.type !== "Image") {
254
- // Atom is Text
255
- if (previousAtomType === "Image") {
256
- // Previous was image
257
- rows.push(currentRow);
258
- currentRow = [];
259
- currentWidth = 0;
260
- previousAtomType = atom.type;
261
- }
262
- currentRow.push(atom);
263
- continue;
264
- }
265
-
266
- if (atom.type === "Image") {
267
- // Atom is Image
268
- if (previousAtomType !== "Image") {
269
- // Previous was not image
270
- rows.push(currentRow);
271
- currentRow = [];
272
- currentWidth = 0;
273
- previousAtomType = atom.type;
274
- }
275
- const atomSize = getDesiredSize(atom, desiredSizes);
276
- if (currentWidth + atomSize.width < availableWidth || currentRow.length === 0) {
277
- // Image fits in current row/current row is empty
278
- currentRow.push(atom);
279
- currentWidth += atomSize.width;
280
- } else {
281
- // Image does not fit in current row
282
- rows.push(currentRow);
283
- currentRow = [atom];
284
- currentWidth = atomSize.width;
285
- }
286
- }
287
- }
288
- if (currentRow.length > 0) {
289
- // Add any remaning children to a new row.
290
- rows.push(currentRow);
291
- }
292
-
293
- let y = finalRect.y + style.margins.top;
294
-
295
- for (let row of rows) {
296
- if (row.length === 0) {
297
- continue;
298
- }
299
-
300
- const rowWidth = row.reduce((a, b) => a + getDesiredSize(b, desiredSizes).width, 0);
301
- let x = finalRect.x;
302
-
303
- if (style.alignment === "Start" || style.alignment === "Justify") {
304
- x += style.margins.left;
305
- } else if (style.alignment === "End") {
306
- x -= style.margins.right;
307
- }
308
-
309
- if (row.length > 1 || row[0].type === "Image") {
310
- // Using continued with alignment "center" or "right" is broken:
311
- // https://github.com/foliojs/pdfkit/issues/240
312
- // Therefore we have to position it ourself
313
- // NOTE: Texts with multiple atoms with width over the available width are not supported.
314
- if (style.alignment === "Center") {
315
- x += 0.5 * (availableWidth - rowWidth);
316
- } else if (style.alignment === "End") {
317
- x += availableWidth - rowWidth;
318
- }
319
- }
320
-
321
- let rowHeight = 0;
322
-
323
- const lastIndex = row.length - 1;
324
- for (const [i, atom] of row.entries()) {
325
- const atomSize = getDesiredSize(atom, desiredSizes);
326
- renderAtom(
327
- resources,
328
- pdf,
329
- AD.Rect.create(x, y, atomSize.width, atomSize.height),
330
- style.textStyle,
331
- atom,
332
- parseAlignment(style.alignment),
333
- availableWidth,
334
- i === 0,
335
- i === lastIndex
336
- );
337
-
338
- x += atomSize.width;
339
- rowHeight = Math.max(rowHeight, atomSize.height);
340
- }
341
-
342
- y += rowHeight;
343
- }
344
- }
345
-
346
- function parseAlignment(paragraphAlignment: AD.ParagraphStyle.TextAlignment | undefined): AD.TextStyle.TextAlignment {
347
- switch (paragraphAlignment) {
348
- case "Start":
349
- return "left";
350
- case "Center":
351
- return "center";
352
- case "End":
353
- return "right";
354
- case "Justify":
355
- return "justify";
356
- default:
357
- return "left";
358
- }
359
- }
360
-
361
- function renderAtom(
362
- resources: AD.Resources.Resources,
363
- pdf: {},
364
- finalRect: AD.Rect.Rect,
365
- textStyle: AD.TextStyle.TextStyle,
366
- atom: AD.Atom.Atom,
367
- alignment: AD.TextStyle.TextAlignment,
368
- availableWidth: number,
369
- isFirstAtom: boolean,
370
- isLastAtom: boolean
371
- ): void {
372
- switch (atom.type) {
373
- case "TextField":
374
- renderTextField(resources, pdf, finalRect, textStyle, atom, alignment, isFirstAtom, isLastAtom, availableWidth);
375
- return;
376
- case "TextRun":
377
- renderTextRun(resources, pdf, finalRect, textStyle, atom, alignment, isFirstAtom, isLastAtom, availableWidth);
378
- return;
379
- case "Image":
380
- renderImage(resources, pdf, finalRect, textStyle, atom);
381
- return;
382
- case "HyperLink":
383
- renderHyperLink(resources, pdf, finalRect, textStyle, atom, alignment, isFirstAtom, isLastAtom, availableWidth);
384
- return;
385
- case "TocSeparator":
386
- renderTocSeparator(pdf, finalRect, textStyle, atom);
387
- return;
388
- case "LinkTarget":
389
- return;
390
- }
391
- }
392
-
393
- function renderTextField(
394
- resources: AD.Resources.Resources,
395
- pdf: {},
396
- finalRect: AD.Rect.Rect,
397
- textStyle: AD.TextStyle.TextStyle,
398
- textField: AD.TextField.TextField,
399
- alignment: AD.TextStyle.TextAlignment,
400
- isFirstAtom: boolean,
401
- isLastAtom: boolean,
402
- availableWidth: number
403
- ): void {
404
- const style = AD.Resources.getStyle(
405
- textStyle,
406
- textField.style,
407
- "TextStyle",
408
- textField.styleName,
409
- resources
410
- ) as AD.TextStyle.TextStyle;
411
- switch (textField.fieldType) {
412
- case "Date":
413
- drawText(
414
- pdf,
415
- finalRect,
416
- style,
417
- new Date(Date.now()).toDateString(),
418
- alignment,
419
- isFirstAtom,
420
- isLastAtom,
421
- availableWidth
422
- );
423
- return;
424
- case "PageNumber":
425
- case "TotalPages":
426
- case "PageNumberOf":
427
- if (textField.text) {
428
- drawText(pdf, finalRect, style, textField.text, alignment, isFirstAtom, isLastAtom, availableWidth);
429
- }
430
- return;
431
- }
432
- }
433
-
434
- function renderTextRun(
435
- resources: AD.Resources.Resources,
436
- pdf: {},
437
- finalRect: AD.Rect.Rect,
438
- textStyle: AD.TextStyle.TextStyle,
439
- textRun: AD.TextRun.TextRun,
440
- alignment: AD.TextStyle.TextAlignment,
441
- isFirstAtom: boolean,
442
- isLastAtom: boolean,
443
- availableWidth: number
444
- ): void {
445
- const style = AD.Resources.getNestedStyle(
446
- textStyle,
447
- textRun.style,
448
- "TextStyle",
449
- textRun.styleName,
450
- resources,
451
- textRun.nestedStyleNames || []
452
- ) as AD.TextStyle.TextStyle;
453
- const textAlignment = style.alignment ? style.alignment : alignment;
454
- drawText(pdf, finalRect, style, textRun.text, textAlignment, isFirstAtom, isLastAtom, availableWidth);
455
- }
456
-
457
- function renderHyperLink(
458
- resources: AD.Resources.Resources,
459
- pdf: {},
460
- finalRect: AD.Rect.Rect,
461
- textStyle: AD.TextStyle.TextStyle,
462
- hyperLink: AD.HyperLink.HyperLink,
463
- alignment: AD.TextStyle.TextAlignment,
464
- isFirstAtom: boolean,
465
- isLastAtom: boolean,
466
- availableWidth: number
467
- ): void {
468
- const style = AD.Resources.getStyle(
469
- textStyle,
470
- hyperLink.style,
471
- "TextStyle",
472
- hyperLink.styleName,
473
- resources
474
- ) as AD.TextStyle.TextStyle;
475
- const textAlignment = style.alignment ? style.alignment : alignment;
476
- drawHyperLink(pdf, finalRect, style, hyperLink, textAlignment, isFirstAtom, isLastAtom, availableWidth);
477
- }
478
-
479
- function renderTocSeparator(
480
- pdf: {},
481
- finalRect: AD.Rect.Rect,
482
- textStyle: AD.TextStyle.TextStyle,
483
- tocSeparator: AD.TocSeparator.TocSeparator
484
- ): void {
485
- drawDottedLine(pdf, finalRect, textStyle, tocSeparator);
486
- }
487
-
488
- function drawHyperLink(
489
- pdf: any,
490
- finalRect: AD.Rect.Rect,
491
- textStyle: AD.TextStyle.TextStyle,
492
- hyperLink: AD.HyperLink.HyperLink,
493
- alignment: AD.TextStyle.TextAlignment,
494
- isFirstAtom: boolean,
495
- isLastAtom: boolean,
496
- availableWidth: number
497
- ): void {
498
- const font = getFontNameStyle(textStyle);
499
- const isInternalLink = hyperLink.target.startsWith("#") && !hyperLink.target.startsWith("#page=");
500
- const fontSize = AD.TextStyle.calculateFontSize(textStyle, 10);
501
- const isSingleAtom = isFirstAtom && isLastAtom;
502
- let xUnderline = finalRect.x;
503
- if (alignment === "center") {
504
- xUnderline += 0.5 * (availableWidth - finalRect.width);
505
- } else if (alignment === "right") {
506
- xUnderline += availableWidth - finalRect.width;
507
- }
508
-
509
- pdf
510
- .font(font)
511
- .fontSize(fontSize)
512
- .fillColor(textStyle.color || "blue");
513
-
514
- applyTextOffset(pdf, textStyle);
515
-
516
- // Using continued with alignment "center" or "right" is broken:
517
- // https://github.com/foliojs/pdfkit/issues/240
518
- // so always set alignment to left and handle it through an x offset
519
- // if its just a single atom then we can use its alignment to partially support multi-line texts for other alignments
520
- if (isFirstAtom || alignment !== "left") {
521
- pdf.text(hyperLink.text, finalRect.x, finalRect.y, {
522
- width: availableWidth,
523
- align: isSingleAtom ? alignment : "left",
524
- goTo: isInternalLink ? hyperLink.target.substr(1) : undefined,
525
- indent: textStyle.indent || 0,
526
- continued: alignment !== "left" ? false : !isLastAtom,
527
- baseline: textStyle.baseline || "top",
528
- ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
529
- });
530
- if (textStyle.underline === undefined ? true : textStyle.underline) {
531
- pdf.underline(xUnderline, finalRect.y + 2, finalRect.width, finalRect.height, {
532
- align: isSingleAtom ? alignment : "left",
533
- color: "blue",
534
- });
535
- }
536
- } else {
537
- pdf.text(hyperLink.text, {
538
- align: "left",
539
- goTo: isInternalLink ? hyperLink.target.substr(1) : undefined,
540
- indent: textStyle.indent || 0,
541
- continued: !isLastAtom,
542
- ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
543
- });
544
- if (textStyle.underline === undefined ? true : textStyle.underline) {
545
- pdf.underline(xUnderline, finalRect.y + 2, finalRect.width, finalRect.height, {
546
- color: "blue",
547
- });
548
- }
549
- }
550
-
551
- resetTextOffset(pdf, textStyle);
552
-
553
- if (!isInternalLink) {
554
- pdf.link(xUnderline, finalRect.y, finalRect.width, finalRect.height, hyperLink.target);
555
- }
556
- }
557
-
558
- function drawText(
559
- pdf: any,
560
- finalRect: AD.Rect.Rect,
561
- textStyle: AD.TextStyle.TextStyle,
562
- text: string,
563
- alignment: AD.TextStyle.TextAlignment,
564
- isFirstAtom: boolean,
565
- isLastAtom: boolean,
566
- availableWidth: number
567
- ): void {
568
- const font = getFontNameStyle(textStyle);
569
- const fontSize = AD.TextStyle.calculateFontSize(textStyle, 10);
570
- const isSingleAtom = isFirstAtom && isLastAtom;
571
- pdf
572
- .font(font)
573
- .fontSize(fontSize)
574
- .fillColor(textStyle.color || "black");
575
-
576
- applyTextOffset(pdf, textStyle);
577
-
578
- // Using continued with alignment "center" or "right" is broken:
579
- // https://github.com/foliojs/pdfkit/issues/240
580
- // so always set alignment to left and handle it through an x offset
581
- // if its just a single atom then we can use its alignment to partially support multi-line texts for other alignments
582
- if (isFirstAtom || alignment !== "left") {
583
- pdf.text(text, finalRect.x, finalRect.y, {
584
- width: availableWidth,
585
- underline: textStyle.underline || false,
586
- align: isSingleAtom ? alignment : "left",
587
- indent: textStyle.indent || 0,
588
- continued: alignment !== "left" ? false : !isLastAtom,
589
- baseline: textStyle.baseline || "top",
590
- ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
591
- });
592
- } else {
593
- pdf.text(text, {
594
- underline: textStyle.underline || false,
595
- align: "left",
596
- indent: textStyle.indent || 0,
597
- continued: !isLastAtom,
598
- ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
599
- });
600
- }
601
-
602
- resetTextOffset(pdf, textStyle);
603
- }
604
-
605
- function drawDottedLine(
606
- pdf: any,
607
- finalRect: AD.Rect.Rect,
608
- textStyle: AD.TextStyle.TextStyle,
609
- tocSeparator: AD.TocSeparator.TocSeparator
610
- ): void {
611
- const font = getFontNameStyle(textStyle);
612
- const fontSize = AD.TextStyle.calculateFontSize(textStyle, 10);
613
-
614
- const charSpacing = tocSeparator.width ? tocSeparator.width : 5;
615
-
616
- const oneDotW = pdf.widthOfString(".", {
617
- width: finalRect.width,
618
- height: finalRect.height,
619
- characterSpacing: charSpacing,
620
- });
621
- const twoDotsW = pdf.widthOfString("..", {
622
- width: finalRect.width,
623
- height: finalRect.height,
624
- characterSpacing: charSpacing,
625
- });
626
- const numberOfDots = Math.floor((finalRect.width - oneDotW) / (twoDotsW - oneDotW)) + 1;
627
- if (twoDotsW - oneDotW === 0 || numberOfDots < 1) {
628
- return;
629
- }
630
-
631
- const dotsText = ".".repeat(numberOfDots);
632
- pdf
633
- .font(font)
634
- .fontSize(fontSize)
635
- .fillColor(textStyle.color || "black");
636
-
637
- applyTextOffset(pdf, textStyle);
638
-
639
- // Disable continued for the dotted line to get the positioning right
640
- pdf.text("", {
641
- continued: false,
642
- goTo: undefined,
643
- });
644
- pdf.text(dotsText, finalRect.x, finalRect.y, {
645
- width: finalRect.width,
646
- height: finalRect.height,
647
- align: "right",
648
- characterSpacing: charSpacing,
649
- });
650
- resetTextOffset(pdf, textStyle);
651
- }
652
-
653
- function renderTable(
654
- resources: AD.Resources.Resources,
655
- pdf: any,
656
- desiredSizes: Map<{}, AD.Size.Size>,
657
- finalRect: AD.Rect.Rect,
658
- table: AD.Table.Table
659
- ): void {
660
- const style = AD.Resources.getStyle(
661
- undefined,
662
- table.style,
663
- "TableStyle",
664
- table.styleName,
665
- resources
666
- ) as AD.TableStyle.TableStyle;
667
- const availableWidth = finalRect.width;
668
- let y = finalRect.y + style.margins.top;
669
- const rows = [...table.headerRows, ...table.children];
670
- for (let [index, row] of rows.entries()) {
671
- const rowSize = getDesiredSize(row, desiredSizes);
672
- let x = finalRect.x + style.margins.left;
673
- if (style.alignment === "Center") x += 0.5 * (availableWidth - rowSize.width);
674
- else if (style.alignment === "Right") x += availableWidth - rowSize.width;
675
- const rowRect = AD.Rect.create(x, y, rowSize.width, rowSize.height);
676
- const isTop = index === 0;
677
- const isBottom = index === rows.length - 1;
678
- renderRow(resources, pdf, desiredSizes, rowRect, style.cellStyle, table, row, index, isTop, isBottom);
679
- y += rowSize.height;
680
- }
681
- }
682
-
683
- function renderRow(
684
- resources: AD.Resources.Resources,
685
- pdf: {},
686
- desiredSizes: Map<{}, AD.Size.Size>,
687
- finalRect: AD.Rect.Rect,
688
- tableCellStyle: AD.TableCellStyle.TableCellStyle,
689
- table: AD.Table.Table,
690
- row: AD.TableRow.TableRow,
691
- rowIndex: number,
692
- isTop: boolean,
693
- isBottom: boolean
694
- ): void {
695
- let x = finalRect.x;
696
- const rowSize = getDesiredSize(row, desiredSizes);
697
- for (const [cellIndex, cell] of row.children.entries()) {
698
- if (cell.dummy) {
699
- const dummySize = getDesiredSize(cell, desiredSizes);
700
- x += dummySize.width;
701
- continue;
702
- }
703
-
704
- let height = rowSize.height;
705
- if (cell.rowSpan > 1) {
706
- for (let index = rowIndex + 1; index < rowIndex + cell.rowSpan; index++) {
707
- height += getDesiredSize([...table.headerRows, ...table.children][index], desiredSizes).height;
708
- }
709
- }
710
- const cellSize = getDesiredSize(cell, desiredSizes);
711
- const cellRect = AD.Rect.create(x, finalRect.y, cellSize.width, height);
712
- const isFirst = cellIndex === 0;
713
- const isLast = cellIndex === row.children.length - 1;
714
- renderCell(resources, pdf, desiredSizes, cellRect, tableCellStyle, cell, isFirst, isLast, isTop, isBottom);
715
- x += cellSize.width;
716
- }
717
- }
718
-
719
- function renderCell(
720
- resources: AD.Resources.Resources,
721
- pdf: any,
722
- desiredSizes: Map<{}, AD.Size.Size>,
723
- finalRect: AD.Rect.Rect,
724
- tableCellStyle: AD.TableCellStyle.TableCellStyle,
725
- cell: AD.TableCell.TableCell,
726
- isFirst: boolean,
727
- isLast: boolean,
728
- isTop: boolean,
729
- isBottom: boolean
730
- ): void {
731
- const style = AD.Resources.getStyle(
732
- tableCellStyle,
733
- cell.style,
734
- "TableCellStyle",
735
- cell.styleName,
736
- resources
737
- ) as AD.TableCellStyle.TableCellStyle;
738
- if (style.background) {
739
- pdf.rect(finalRect.x, finalRect.y, finalRect.width, finalRect.height).fill(style.background);
740
- }
741
-
742
- let x = finalRect.x + style.padding.left;
743
- const availableHeight = finalRect.height;
744
- let contentHeight = cell.children
745
- .map((c) => (AD.Position.isPositionAbsolute(c) ? 0 : getDesiredSize(c, desiredSizes).height))
746
- .reduce((a, b) => a + b, 0);
747
- const startY = finalRect.y + style.padding.top;
748
- let y = startY;
749
- if (style.verticalAlignment === "Middle")
750
- y += 0.5 * (availableHeight - contentHeight - style.padding.top - style.padding.bottom);
751
- else if (style.verticalAlignment === "Bottom")
752
- y += availableHeight - contentHeight - style.padding.top - style.padding.bottom;
753
-
754
- for (const element of cell.children) {
755
- const elementSize = getDesiredSize(element, desiredSizes);
756
- const isAbsolute = AD.Position.isPositionAbsolute(element);
757
- const elementRect = AD.Rect.create(x, isAbsolute ? startY : y, elementSize.width, elementSize.height);
758
- renderSectionElement(resources, pdf, desiredSizes, elementRect, element);
759
- if (!isAbsolute) {
760
- y += elementSize.height;
761
- }
762
- }
763
-
764
- //Needed to counter aliasing caused by the cells background fill
765
- const pixelFix = 0.3;
766
-
767
- if (style.borders.bottom) {
768
- const widthOffset = isBottom ? style.borders.bottom / 2 - pixelFix : 0;
769
- pdf
770
- .lineWidth(style.borders.bottom)
771
- .moveTo(finalRect.x, finalRect.y + finalRect.height - widthOffset)
772
- .lineTo(finalRect.x + finalRect.width, finalRect.y + finalRect.height - widthOffset)
773
- .stroke(borderColor(style, "bottom"));
774
- }
775
- if (style.borders.right) {
776
- const hasBottomBorderOffset = style.borders.bottom ? pixelFix : 0;
777
- const widthOffset = isLast ? style.borders.right / 2 - pixelFix : 0;
778
- pdf
779
- .lineWidth(style.borders.right)
780
- .moveTo(finalRect.x + finalRect.width - widthOffset, finalRect.y)
781
- .lineTo(finalRect.x + finalRect.width - widthOffset, finalRect.y + finalRect.height + hasBottomBorderOffset)
782
- .stroke(borderColor(style, "right"));
783
- }
784
- if (style.borders.left) {
785
- const hasBottomBorderOffset = style.borders.bottom ? pixelFix : 0;
786
- const widthOffset = isFirst ? style.borders.left / 2 - pixelFix : 0;
787
- pdf
788
- .lineWidth(style.borders.left)
789
- .moveTo(finalRect.x + widthOffset, finalRect.y)
790
- .lineTo(finalRect.x + widthOffset, finalRect.y + finalRect.height + hasBottomBorderOffset)
791
- .stroke(borderColor(style, "left"));
792
- }
793
- if (style.borders.top) {
794
- const hasRightBorderOffset = style.borders.right ? pixelFix : 0;
795
- const hasLeftBorderOffset = style.borders.left ? pixelFix : 0;
796
- const halfWidth = style.borders.top / 2 - pixelFix;
797
- const widthOffset = isTop ? halfWidth : 0;
798
- const notFirstOffset = !isFirst ? halfWidth : 0;
799
- pdf
800
- .lineWidth(style.borders.top)
801
- .moveTo(finalRect.x - notFirstOffset - hasLeftBorderOffset, finalRect.y + widthOffset)
802
- .lineTo(finalRect.x + finalRect.width + hasRightBorderOffset, finalRect.y + widthOffset)
803
- .stroke(borderColor(style, "top"));
804
- }
805
- }
806
-
807
- function borderColor(style: AD.TableCellStyle.TableCellStyle, edge: "top" | "bottom" | "left" | "right"): string {
808
- if (style.borderColors && style.borderColors[edge]) {
809
- return style.borderColors[edge];
810
- }
811
- if (style.borderColor) {
812
- return style.borderColor;
813
- }
814
- return "black";
815
- }
816
-
817
- function getDesiredSize(element: {}, desiredSizes: Map<{}, AD.Size.Size>): AD.Size.Size {
818
- const size = desiredSizes.get(element);
819
- if (size) {
820
- return size;
821
- }
822
- throw new Error("Could not find size for element!");
823
- }
824
-
825
- function applyTextOffset(pdf: any, textStyle: AD.TextStyle.TextStyle): void {
826
- const offset = calculateTextOffset(textStyle);
827
- if (offset < 0) {
828
- pdf.moveDown(Math.abs(offset));
829
- } else {
830
- pdf.moveUp(offset);
831
- }
832
- }
833
-
834
- function resetTextOffset(pdf: any, textStyle: AD.TextStyle.TextStyle): void {
835
- const offset = calculateTextOffset(textStyle);
836
- if (offset < 0) {
837
- pdf.moveUp(Math.abs(offset));
838
- } else {
839
- pdf.moveDown(offset);
840
- }
841
- }
842
-
843
- function calculateTextOffset(textStyle: AD.TextStyle.TextStyle): number {
844
- const defaultPosition = textStyle.superScript ? -0.5 : textStyle.subScript ? 0.5 : 0;
845
- const position = textStyle.verticalPosition !== undefined ? textStyle.verticalPosition : defaultPosition;
846
- return position;
847
- }
1
+ import * as AD from "../../abstract-document/index";
2
+ import { preProcess } from "./pre-process";
3
+ import { measure, measurePages } from "./measure";
4
+ import { paginate, Page } from "./paginate";
5
+ import { updatePageRefs } from "./update-refs";
6
+ import BlobStream from "blob-stream";
7
+ import { renderImage } from "./render-image";
8
+ import { registerFonts, getFontNameStyle } from "./font";
9
+
10
+ type RowSpans = Map<number, { rowSpanLeft: number; colSpan: number }>;
11
+
12
+ export function exportToHTML5Blob(
13
+ // tslint:disable-next-line:no-any
14
+ pdfKit: any,
15
+ doc: AD.AbstractDoc.AbstractDoc
16
+ ): Promise<Blob> {
17
+ return new Promise((resolve) => {
18
+ const stream = BlobStream();
19
+ exportToStream(pdfKit, stream, doc);
20
+ stream.on("finish", () => {
21
+ const blob = stream.toBlob("application/pdf");
22
+ resolve(blob);
23
+ });
24
+ });
25
+ }
26
+
27
+ /**
28
+ * On the client side the stream can be a BlobStream from the blob-stream package.
29
+ * On the server-side the stream can be a file stream from the fs package.
30
+ * @param pdfKit
31
+ * @param blobStream
32
+ * @param doc
33
+ */
34
+ export function exportToStream(pdfKit: any, blobStream: {}, doc: AD.AbstractDoc.AbstractDoc): void {
35
+ const PDFDocument = pdfKit;
36
+ const document = preProcess(doc);
37
+
38
+ let pdf = new PDFDocument({
39
+ compress: false,
40
+ autoFirstPage: false,
41
+ bufferPages: true,
42
+ }) as any;
43
+
44
+ registerFonts((fontName: string, fontSource: AD.Font.FontSource) => pdf.registerFont(fontName, fontSource), document);
45
+
46
+ const desiredSizes = measure(pdfKit, document);
47
+ const pages = paginate(pdfKit, document, desiredSizes);
48
+ const updatedPages = updatePageRefs(pages);
49
+ const pageDesiredSizes = measurePages(pdfKit, document, updatedPages);
50
+
51
+ for (let page of updatedPages) {
52
+ renderPage(document, pdf, pageDesiredSizes, page);
53
+ }
54
+
55
+ pdf.pipe(blobStream);
56
+ pdf.end();
57
+ }
58
+
59
+ // // Can only be used on the server-side
60
+ // export function exportToNodeStream(pdfKit: any, doc: AD.AbstractDoc.AbstractDoc, stream: any): void {
61
+ // const PDFDocument = pdfKit;
62
+ // const document = preProcess(doc);
63
+ // const desiredSizes = measure(pdfKit, document);
64
+ // let pdf = new PDFDocument({compress: false, autoFirstPage: false}) as any;
65
+ // registerFonts(
66
+ // (fontName: string, fontSource: AD.Font.FontSource) =>
67
+ // pdf.registerFont(fontName, fontSource),
68
+ // document
69
+ // );
70
+ // let pageNo = 0;
71
+ // for (let section of document.children){
72
+ // pageNo = renderSection(document, pdf, desiredSizes, section, pageNo);
73
+ // }
74
+ // pdf.pipe(stream);
75
+ // pdf.end();
76
+ // }
77
+
78
+ function renderPage(
79
+ parentResources: AD.Resources.Resources,
80
+ pdf: any,
81
+ desiredSizes: Map<{}, AD.Size.Size>,
82
+ page: Page
83
+ ): void {
84
+ const section = page.section;
85
+ const style = section.page.style;
86
+ const resources = AD.Resources.mergeResources([parentResources, section]);
87
+ const pageHeight = AD.PageStyle.getHeight(style);
88
+ const contentRect = addPage(pdf, page);
89
+
90
+ page.namedDestionations.forEach((dest) => {
91
+ if (pdf.addNamedDestination) {
92
+ pdf.addNamedDestination(dest);
93
+ }
94
+ });
95
+
96
+ const headerX = style.headerMargins.left;
97
+ const headerStart = style.headerMargins.top;
98
+ let headerY = headerStart;
99
+ for (let element of page.header) {
100
+ const elementSize = getDesiredSize(element, desiredSizes);
101
+ const isAbsolute = AD.Position.isPositionAbsolute(element);
102
+ renderSectionElement(
103
+ resources,
104
+ pdf,
105
+ desiredSizes,
106
+ AD.Rect.create(headerX, isAbsolute ? headerStart : headerY, elementSize.width, elementSize.height),
107
+ element
108
+ );
109
+ if (!isAbsolute) {
110
+ headerY += elementSize.height;
111
+ }
112
+ }
113
+ headerY += style.headerMargins.bottom;
114
+
115
+ const footerHeight = page.footer.reduce(
116
+ (a, b) => a + (AD.Position.isPositionAbsolute(b) ? 0 : getDesiredSize(b, desiredSizes).height),
117
+ style.footerMargins.top + style.footerMargins.bottom
118
+ );
119
+ const footerX = style.footerMargins.left;
120
+ const footerStart = pageHeight - (footerHeight - style.footerMargins.top);
121
+ let footerY = footerStart;
122
+ for (let element of page.footer) {
123
+ const elementSize = getDesiredSize(element, desiredSizes);
124
+ const isAbsolute = AD.Position.isPositionAbsolute(element);
125
+ renderSectionElement(
126
+ resources,
127
+ pdf,
128
+ desiredSizes,
129
+ AD.Rect.create(footerX, isAbsolute ? footerStart : footerY, elementSize.width, elementSize.height),
130
+ element
131
+ );
132
+ if (!isAbsolute) {
133
+ footerY += elementSize.height;
134
+ }
135
+ }
136
+
137
+ const elementStart = contentRect.y;
138
+ let y = elementStart;
139
+ for (const element of page.elements) {
140
+ const elementSize = getDesiredSize(element, desiredSizes);
141
+ const isAbsolute = AD.Position.isPositionAbsolute(element);
142
+ renderSectionElement(
143
+ resources,
144
+ pdf,
145
+ desiredSizes,
146
+ AD.Rect.create(contentRect.x, isAbsolute ? elementStart : y, elementSize.width, elementSize.height),
147
+ element
148
+ );
149
+ if (!isAbsolute) {
150
+ y += elementSize.height;
151
+ }
152
+ }
153
+ }
154
+
155
+ function addPage(pdf: any, page: Page): AD.Rect.Rect {
156
+ const section = page.section;
157
+ const style = section.page.style;
158
+ // This is rotated later depending on the orientation.
159
+ const pageWidth = AD.PageStyle.getPaperWidth(style.paperSize);
160
+ const pageHeight = AD.PageStyle.getPaperHeight(style.paperSize);
161
+ const layout = style.orientation === "Landscape" ? "landscape" : "portrait";
162
+ const pageOptions = {
163
+ size: [pageWidth, pageHeight],
164
+ layout: layout,
165
+ margins: {
166
+ top: 0,
167
+ left: 0,
168
+ right: 0,
169
+ bottom: 0,
170
+ },
171
+ };
172
+ pdf.addPage(pageOptions);
173
+ return page.contentRect;
174
+ }
175
+
176
+ function renderSectionElement(
177
+ parentResources: AD.Resources.Resources,
178
+ pdf: {},
179
+ desiredSizes: Map<{}, AD.Size.Size>,
180
+ finalRect: AD.Rect.Rect,
181
+ element: AD.SectionElement.SectionElement
182
+ ): void {
183
+ const resources = AD.Resources.mergeResources([parentResources, element]);
184
+ switch (element.type) {
185
+ case "Paragraph":
186
+ renderParagraph(resources, pdf, desiredSizes, finalRect, element);
187
+ return;
188
+ case "Table":
189
+ renderTable(resources, pdf, desiredSizes, finalRect, element);
190
+ return;
191
+ case "Group":
192
+ renderGroup(resources, pdf, desiredSizes, finalRect, element);
193
+ return;
194
+ }
195
+ }
196
+
197
+ function renderGroup(
198
+ resources: AD.Resources.Resources,
199
+ pdf: {},
200
+ desiredSizes: Map<{}, AD.Size.Size>,
201
+ finalRect: AD.Rect.Rect,
202
+ group: AD.Group.Group
203
+ ): void {
204
+ const finalX = finalRect.x + group.style.margins.left;
205
+ const startY = finalRect.y + group.style.margins.top;
206
+ let y = startY;
207
+ for (const element of group.children) {
208
+ const elementSize = getDesiredSize(element, desiredSizes);
209
+ const isAbsolute = AD.Position.isPositionAbsolute(element);
210
+ renderSectionElement(
211
+ resources,
212
+ pdf,
213
+ desiredSizes,
214
+ AD.Rect.create(finalX, isAbsolute ? startY : y, elementSize.width, elementSize.height),
215
+ element
216
+ );
217
+ if (!isAbsolute) {
218
+ y += elementSize.height;
219
+ }
220
+ }
221
+ }
222
+
223
+ function renderParagraph(
224
+ resources: AD.Resources.Resources,
225
+ pdf: {},
226
+ desiredSizes: Map<{}, AD.Size.Size>,
227
+ finalRect: AD.Rect.Rect,
228
+ paragraph: AD.Paragraph.Paragraph
229
+ ): void {
230
+ const style = AD.Resources.getStyle(
231
+ undefined,
232
+ paragraph.style,
233
+ "ParagraphStyle",
234
+ paragraph.styleName,
235
+ resources
236
+ ) as AD.ParagraphStyle.ParagraphStyle;
237
+ const availableWidth = finalRect.width - (style.margins.left + style.margins.right);
238
+
239
+ let rows: Array<Array<AD.Atom.Atom>> = [];
240
+ let currentRow: Array<AD.Atom.Atom> = [];
241
+ let currentWidth = 0;
242
+ let previousAtomType: string | undefined;
243
+ for (const atom of paragraph.children) {
244
+ if (!previousAtomType) {
245
+ // First atom
246
+ previousAtomType = atom.type;
247
+ currentRow.push(atom);
248
+ const atomSize = getDesiredSize(atom, desiredSizes);
249
+ currentWidth = atomSize.width;
250
+ continue;
251
+ }
252
+
253
+ if (atom.type !== "Image") {
254
+ // Atom is Text
255
+ if (previousAtomType === "Image") {
256
+ // Previous was image
257
+ rows.push(currentRow);
258
+ currentRow = [];
259
+ currentWidth = 0;
260
+ previousAtomType = atom.type;
261
+ }
262
+ currentRow.push(atom);
263
+ continue;
264
+ }
265
+
266
+ if (atom.type === "Image") {
267
+ // Atom is Image
268
+ if (previousAtomType !== "Image") {
269
+ // Previous was not image
270
+ rows.push(currentRow);
271
+ currentRow = [];
272
+ currentWidth = 0;
273
+ previousAtomType = atom.type;
274
+ }
275
+ const atomSize = getDesiredSize(atom, desiredSizes);
276
+ if (currentWidth + atomSize.width < availableWidth || currentRow.length === 0) {
277
+ // Image fits in current row/current row is empty
278
+ currentRow.push(atom);
279
+ currentWidth += atomSize.width;
280
+ } else {
281
+ // Image does not fit in current row
282
+ rows.push(currentRow);
283
+ currentRow = [atom];
284
+ currentWidth = atomSize.width;
285
+ }
286
+ }
287
+ }
288
+ if (currentRow.length > 0) {
289
+ // Add any remaning children to a new row.
290
+ rows.push(currentRow);
291
+ }
292
+
293
+ let y = finalRect.y + style.margins.top;
294
+
295
+ for (let row of rows) {
296
+ if (row.length === 0) {
297
+ continue;
298
+ }
299
+
300
+ const rowWidth = row.reduce((a, b) => a + getDesiredSize(b, desiredSizes).width, 0);
301
+ let x = finalRect.x;
302
+
303
+ if (style.alignment === "Start" || style.alignment === "Justify") {
304
+ x += style.margins.left;
305
+ } else if (style.alignment === "End") {
306
+ x -= style.margins.right;
307
+ }
308
+
309
+ if (row.length > 1 || row[0].type === "Image") {
310
+ // Using continued with alignment "center" or "right" is broken:
311
+ // https://github.com/foliojs/pdfkit/issues/240
312
+ // Therefore we have to position it ourself
313
+ // NOTE: Texts with multiple atoms with width over the available width are not supported.
314
+ if (style.alignment === "Center") {
315
+ x += 0.5 * (availableWidth - rowWidth);
316
+ } else if (style.alignment === "End") {
317
+ x += availableWidth - rowWidth;
318
+ }
319
+ }
320
+
321
+ let rowHeight = 0;
322
+
323
+ const lastIndex = row.length - 1;
324
+ for (const [i, atom] of row.entries()) {
325
+ const atomSize = getDesiredSize(atom, desiredSizes);
326
+ renderAtom(
327
+ resources,
328
+ pdf,
329
+ AD.Rect.create(x, y, atomSize.width, atomSize.height),
330
+ style.textStyle,
331
+ atom,
332
+ parseAlignment(style.alignment),
333
+ availableWidth,
334
+ i === 0,
335
+ i === lastIndex
336
+ );
337
+
338
+ x += atomSize.width;
339
+ rowHeight = Math.max(rowHeight, atomSize.height);
340
+ }
341
+
342
+ y += rowHeight;
343
+ }
344
+ }
345
+
346
+ function parseAlignment(paragraphAlignment: AD.ParagraphStyle.TextAlignment | undefined): AD.TextStyle.TextAlignment {
347
+ switch (paragraphAlignment) {
348
+ case "Start":
349
+ return "left";
350
+ case "Center":
351
+ return "center";
352
+ case "End":
353
+ return "right";
354
+ case "Justify":
355
+ return "justify";
356
+ default:
357
+ return "left";
358
+ }
359
+ }
360
+
361
+ function renderAtom(
362
+ resources: AD.Resources.Resources,
363
+ pdf: {},
364
+ finalRect: AD.Rect.Rect,
365
+ textStyle: AD.TextStyle.TextStyle,
366
+ atom: AD.Atom.Atom,
367
+ alignment: AD.TextStyle.TextAlignment,
368
+ availableWidth: number,
369
+ isFirstAtom: boolean,
370
+ isLastAtom: boolean
371
+ ): void {
372
+ switch (atom.type) {
373
+ case "TextField":
374
+ renderTextField(resources, pdf, finalRect, textStyle, atom, alignment, isFirstAtom, isLastAtom, availableWidth);
375
+ return;
376
+ case "TextRun":
377
+ renderTextRun(resources, pdf, finalRect, textStyle, atom, alignment, isFirstAtom, isLastAtom, availableWidth);
378
+ return;
379
+ case "Image":
380
+ renderImage(resources, pdf, finalRect, textStyle, atom);
381
+ return;
382
+ case "HyperLink":
383
+ renderHyperLink(resources, pdf, finalRect, textStyle, atom, alignment, isFirstAtom, isLastAtom, availableWidth);
384
+ return;
385
+ case "TocSeparator":
386
+ renderTocSeparator(pdf, finalRect, textStyle, atom);
387
+ return;
388
+ case "LinkTarget":
389
+ return;
390
+ }
391
+ }
392
+
393
+ function renderTextField(
394
+ resources: AD.Resources.Resources,
395
+ pdf: {},
396
+ finalRect: AD.Rect.Rect,
397
+ textStyle: AD.TextStyle.TextStyle,
398
+ textField: AD.TextField.TextField,
399
+ alignment: AD.TextStyle.TextAlignment,
400
+ isFirstAtom: boolean,
401
+ isLastAtom: boolean,
402
+ availableWidth: number
403
+ ): void {
404
+ const style = AD.Resources.getStyle(
405
+ textStyle,
406
+ textField.style,
407
+ "TextStyle",
408
+ textField.styleName,
409
+ resources
410
+ ) as AD.TextStyle.TextStyle;
411
+ switch (textField.fieldType) {
412
+ case "Date":
413
+ drawText(
414
+ pdf,
415
+ finalRect,
416
+ style,
417
+ new Date(Date.now()).toDateString(),
418
+ alignment,
419
+ isFirstAtom,
420
+ isLastAtom,
421
+ availableWidth
422
+ );
423
+ return;
424
+ case "PageNumber":
425
+ case "TotalPages":
426
+ case "PageNumberOf":
427
+ if (textField.text) {
428
+ drawText(pdf, finalRect, style, textField.text, alignment, isFirstAtom, isLastAtom, availableWidth);
429
+ }
430
+ return;
431
+ }
432
+ }
433
+
434
+ function renderTextRun(
435
+ resources: AD.Resources.Resources,
436
+ pdf: {},
437
+ finalRect: AD.Rect.Rect,
438
+ textStyle: AD.TextStyle.TextStyle,
439
+ textRun: AD.TextRun.TextRun,
440
+ alignment: AD.TextStyle.TextAlignment,
441
+ isFirstAtom: boolean,
442
+ isLastAtom: boolean,
443
+ availableWidth: number
444
+ ): void {
445
+ const style = AD.Resources.getNestedStyle(
446
+ textStyle,
447
+ textRun.style,
448
+ "TextStyle",
449
+ textRun.styleName,
450
+ resources,
451
+ textRun.nestedStyleNames || []
452
+ ) as AD.TextStyle.TextStyle;
453
+ const textAlignment = style.alignment ? style.alignment : alignment;
454
+ drawText(pdf, finalRect, style, textRun.text, textAlignment, isFirstAtom, isLastAtom, availableWidth);
455
+ }
456
+
457
+ function renderHyperLink(
458
+ resources: AD.Resources.Resources,
459
+ pdf: {},
460
+ finalRect: AD.Rect.Rect,
461
+ textStyle: AD.TextStyle.TextStyle,
462
+ hyperLink: AD.HyperLink.HyperLink,
463
+ alignment: AD.TextStyle.TextAlignment,
464
+ isFirstAtom: boolean,
465
+ isLastAtom: boolean,
466
+ availableWidth: number
467
+ ): void {
468
+ const style = AD.Resources.getStyle(
469
+ textStyle,
470
+ hyperLink.style,
471
+ "TextStyle",
472
+ hyperLink.styleName,
473
+ resources
474
+ ) as AD.TextStyle.TextStyle;
475
+ const textAlignment = style.alignment ? style.alignment : alignment;
476
+ drawHyperLink(pdf, finalRect, style, hyperLink, textAlignment, isFirstAtom, isLastAtom, availableWidth);
477
+ }
478
+
479
+ function renderTocSeparator(
480
+ pdf: {},
481
+ finalRect: AD.Rect.Rect,
482
+ textStyle: AD.TextStyle.TextStyle,
483
+ tocSeparator: AD.TocSeparator.TocSeparator
484
+ ): void {
485
+ drawDottedLine(pdf, finalRect, textStyle, tocSeparator);
486
+ }
487
+
488
+ function drawHyperLink(
489
+ pdf: any,
490
+ finalRect: AD.Rect.Rect,
491
+ textStyle: AD.TextStyle.TextStyle,
492
+ hyperLink: AD.HyperLink.HyperLink,
493
+ alignment: AD.TextStyle.TextAlignment,
494
+ isFirstAtom: boolean,
495
+ isLastAtom: boolean,
496
+ availableWidth: number
497
+ ): void {
498
+ const font = getFontNameStyle(textStyle);
499
+ const isInternalLink = hyperLink.target.startsWith("#") && !hyperLink.target.startsWith("#page=");
500
+ const fontSize = AD.TextStyle.calculateFontSize(textStyle, 10);
501
+ const isSingleAtom = isFirstAtom && isLastAtom;
502
+ let xUnderline = finalRect.x;
503
+ if (alignment === "center") {
504
+ xUnderline += 0.5 * (availableWidth - finalRect.width);
505
+ } else if (alignment === "right") {
506
+ xUnderline += availableWidth - finalRect.width;
507
+ }
508
+
509
+ pdf
510
+ .font(font)
511
+ .fontSize(fontSize)
512
+ .fillColor(textStyle.color || "blue");
513
+
514
+ applyTextOffset(pdf, textStyle);
515
+
516
+ // Using continued with alignment "center" or "right" is broken:
517
+ // https://github.com/foliojs/pdfkit/issues/240
518
+ // so always set alignment to left and handle it through an x offset
519
+ // if its just a single atom then we can use its alignment to partially support multi-line texts for other alignments
520
+ if (isFirstAtom || alignment !== "left") {
521
+ pdf.text(hyperLink.text, finalRect.x, finalRect.y, {
522
+ width: availableWidth,
523
+ align: isSingleAtom ? alignment : "left",
524
+ goTo: isInternalLink ? hyperLink.target.substr(1) : undefined,
525
+ indent: textStyle.indent || 0,
526
+ continued: alignment !== "left" ? false : !isLastAtom,
527
+ baseline: textStyle.baseline || "top",
528
+ ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
529
+ });
530
+ if (textStyle.underline === undefined ? true : textStyle.underline) {
531
+ pdf.underline(xUnderline, finalRect.y + 2, finalRect.width, finalRect.height, {
532
+ align: isSingleAtom ? alignment : "left",
533
+ color: "blue",
534
+ });
535
+ }
536
+ } else {
537
+ pdf.text(hyperLink.text, {
538
+ align: "left",
539
+ goTo: isInternalLink ? hyperLink.target.substr(1) : undefined,
540
+ indent: textStyle.indent || 0,
541
+ continued: !isLastAtom,
542
+ ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
543
+ });
544
+ if (textStyle.underline === undefined ? true : textStyle.underline) {
545
+ pdf.underline(xUnderline, finalRect.y + 2, finalRect.width, finalRect.height, {
546
+ color: "blue",
547
+ });
548
+ }
549
+ }
550
+
551
+ resetTextOffset(pdf, textStyle);
552
+
553
+ if (!isInternalLink) {
554
+ pdf.link(xUnderline, finalRect.y, finalRect.width, finalRect.height, hyperLink.target);
555
+ }
556
+ }
557
+
558
+ function drawText(
559
+ pdf: any,
560
+ finalRect: AD.Rect.Rect,
561
+ textStyle: AD.TextStyle.TextStyle,
562
+ text: string,
563
+ alignment: AD.TextStyle.TextAlignment,
564
+ isFirstAtom: boolean,
565
+ isLastAtom: boolean,
566
+ availableWidth: number
567
+ ): void {
568
+ const font = getFontNameStyle(textStyle);
569
+ const fontSize = AD.TextStyle.calculateFontSize(textStyle, 10);
570
+ const isSingleAtom = isFirstAtom && isLastAtom;
571
+ pdf
572
+ .font(font)
573
+ .fontSize(fontSize)
574
+ .fillColor(textStyle.color || "black");
575
+
576
+ applyTextOffset(pdf, textStyle);
577
+
578
+ // Using continued with alignment "center" or "right" is broken:
579
+ // https://github.com/foliojs/pdfkit/issues/240
580
+ // so always set alignment to left and handle it through an x offset
581
+ // if its just a single atom then we can use its alignment to partially support multi-line texts for other alignments
582
+ if (isFirstAtom || alignment !== "left") {
583
+ pdf.text(text, finalRect.x, finalRect.y, {
584
+ width: availableWidth,
585
+ underline: textStyle.underline || false,
586
+ align: isSingleAtom ? alignment : "left",
587
+ indent: textStyle.indent || 0,
588
+ continued: alignment !== "left" ? false : !isLastAtom,
589
+ baseline: textStyle.baseline || "top",
590
+ ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
591
+ });
592
+ } else {
593
+ pdf.text(text, {
594
+ underline: textStyle.underline || false,
595
+ align: "left",
596
+ indent: textStyle.indent || 0,
597
+ continued: !isLastAtom,
598
+ ...(textStyle.lineGap !== undefined ? { lineGap: textStyle.lineGap } : {}),
599
+ });
600
+ }
601
+
602
+ resetTextOffset(pdf, textStyle);
603
+ }
604
+
605
+ function drawDottedLine(
606
+ pdf: any,
607
+ finalRect: AD.Rect.Rect,
608
+ textStyle: AD.TextStyle.TextStyle,
609
+ tocSeparator: AD.TocSeparator.TocSeparator
610
+ ): void {
611
+ const font = getFontNameStyle(textStyle);
612
+ const fontSize = AD.TextStyle.calculateFontSize(textStyle, 10);
613
+
614
+ const charSpacing = tocSeparator.width ? tocSeparator.width : 5;
615
+
616
+ const oneDotW = pdf.widthOfString(".", {
617
+ width: finalRect.width,
618
+ height: finalRect.height,
619
+ characterSpacing: charSpacing,
620
+ });
621
+ const twoDotsW = pdf.widthOfString("..", {
622
+ width: finalRect.width,
623
+ height: finalRect.height,
624
+ characterSpacing: charSpacing,
625
+ });
626
+ const numberOfDots = Math.floor((finalRect.width - oneDotW) / (twoDotsW - oneDotW)) + 1;
627
+ if (twoDotsW - oneDotW === 0 || numberOfDots < 1) {
628
+ return;
629
+ }
630
+
631
+ const dotsText = ".".repeat(numberOfDots);
632
+ pdf
633
+ .font(font)
634
+ .fontSize(fontSize)
635
+ .fillColor(textStyle.color || "black");
636
+
637
+ applyTextOffset(pdf, textStyle);
638
+
639
+ // Disable continued for the dotted line to get the positioning right
640
+ pdf.text("", {
641
+ continued: false,
642
+ goTo: undefined,
643
+ });
644
+ pdf.text(dotsText, finalRect.x, finalRect.y, {
645
+ width: finalRect.width,
646
+ height: finalRect.height,
647
+ align: "right",
648
+ characterSpacing: charSpacing,
649
+ });
650
+ resetTextOffset(pdf, textStyle);
651
+ }
652
+
653
+ function renderTable(
654
+ resources: AD.Resources.Resources,
655
+ pdf: any,
656
+ desiredSizes: Map<{}, AD.Size.Size>,
657
+ finalRect: AD.Rect.Rect,
658
+ table: AD.Table.Table
659
+ ): void {
660
+ const style = AD.Resources.getStyle(
661
+ undefined,
662
+ table.style,
663
+ "TableStyle",
664
+ table.styleName,
665
+ resources
666
+ ) as AD.TableStyle.TableStyle;
667
+ const availableWidth = finalRect.width;
668
+ let y = finalRect.y + style.margins.top;
669
+ const rows = [...table.headerRows, ...table.children];
670
+ for (let [index, row] of rows.entries()) {
671
+ const rowSize = getDesiredSize(row, desiredSizes);
672
+ let x = finalRect.x + style.margins.left;
673
+ if (style.alignment === "Center") x += 0.5 * (availableWidth - rowSize.width);
674
+ else if (style.alignment === "Right") x += availableWidth - rowSize.width;
675
+ const rowRect = AD.Rect.create(x, y, rowSize.width, rowSize.height);
676
+ const isTop = index === 0;
677
+ const isBottom = index === rows.length - 1;
678
+ renderRow(resources, pdf, desiredSizes, rowRect, style.cellStyle, table, row, index, isTop, isBottom);
679
+ y += rowSize.height;
680
+ }
681
+ }
682
+
683
+ function renderRow(
684
+ resources: AD.Resources.Resources,
685
+ pdf: {},
686
+ desiredSizes: Map<{}, AD.Size.Size>,
687
+ finalRect: AD.Rect.Rect,
688
+ tableCellStyle: AD.TableCellStyle.TableCellStyle,
689
+ table: AD.Table.Table,
690
+ row: AD.TableRow.TableRow,
691
+ rowIndex: number,
692
+ isTop: boolean,
693
+ isBottom: boolean
694
+ ): void {
695
+ let x = finalRect.x;
696
+ const rowSize = getDesiredSize(row, desiredSizes);
697
+ for (const [cellIndex, cell] of row.children.entries()) {
698
+ if (cell.dummy) {
699
+ const dummySize = getDesiredSize(cell, desiredSizes);
700
+ x += dummySize.width;
701
+ continue;
702
+ }
703
+
704
+ let height = rowSize.height;
705
+ if (cell.rowSpan > 1) {
706
+ for (let index = rowIndex + 1; index < rowIndex + cell.rowSpan; index++) {
707
+ height += getDesiredSize([...table.headerRows, ...table.children][index], desiredSizes).height;
708
+ }
709
+ }
710
+ const cellSize = getDesiredSize(cell, desiredSizes);
711
+ const cellRect = AD.Rect.create(x, finalRect.y, cellSize.width, height);
712
+ const isFirst = cellIndex === 0;
713
+ const isLast = cellIndex === row.children.length - 1;
714
+ renderCell(resources, pdf, desiredSizes, cellRect, tableCellStyle, cell, isFirst, isLast, isTop, isBottom);
715
+ x += cellSize.width;
716
+ }
717
+ }
718
+
719
+ function renderCell(
720
+ resources: AD.Resources.Resources,
721
+ pdf: any,
722
+ desiredSizes: Map<{}, AD.Size.Size>,
723
+ finalRect: AD.Rect.Rect,
724
+ tableCellStyle: AD.TableCellStyle.TableCellStyle,
725
+ cell: AD.TableCell.TableCell,
726
+ isFirst: boolean,
727
+ isLast: boolean,
728
+ isTop: boolean,
729
+ isBottom: boolean
730
+ ): void {
731
+ const style = AD.Resources.getStyle(
732
+ tableCellStyle,
733
+ cell.style,
734
+ "TableCellStyle",
735
+ cell.styleName,
736
+ resources
737
+ ) as AD.TableCellStyle.TableCellStyle;
738
+ if (style.background) {
739
+ pdf.rect(finalRect.x, finalRect.y, finalRect.width, finalRect.height).fill(style.background);
740
+ }
741
+
742
+ let x = finalRect.x + style.padding.left;
743
+ const availableHeight = finalRect.height;
744
+ let contentHeight = cell.children
745
+ .map((c) => (AD.Position.isPositionAbsolute(c) ? 0 : getDesiredSize(c, desiredSizes).height))
746
+ .reduce((a, b) => a + b, 0);
747
+ const startY = finalRect.y + style.padding.top;
748
+ let y = startY;
749
+ if (style.verticalAlignment === "Middle")
750
+ y += 0.5 * (availableHeight - contentHeight - style.padding.top - style.padding.bottom);
751
+ else if (style.verticalAlignment === "Bottom")
752
+ y += availableHeight - contentHeight - style.padding.top - style.padding.bottom;
753
+
754
+ for (const element of cell.children) {
755
+ const elementSize = getDesiredSize(element, desiredSizes);
756
+ const isAbsolute = AD.Position.isPositionAbsolute(element);
757
+ const elementRect = AD.Rect.create(x, isAbsolute ? startY : y, elementSize.width, elementSize.height);
758
+ renderSectionElement(resources, pdf, desiredSizes, elementRect, element);
759
+ if (!isAbsolute) {
760
+ y += elementSize.height;
761
+ }
762
+ }
763
+
764
+ //Needed to counter aliasing caused by the cells background fill
765
+ const pixelFix = 0.3;
766
+
767
+ if (style.borders.bottom) {
768
+ const widthOffset = isBottom ? style.borders.bottom / 2 - pixelFix : 0;
769
+ pdf
770
+ .lineWidth(style.borders.bottom)
771
+ .moveTo(finalRect.x, finalRect.y + finalRect.height - widthOffset)
772
+ .lineTo(finalRect.x + finalRect.width, finalRect.y + finalRect.height - widthOffset)
773
+ .stroke(borderColor(style, "bottom"));
774
+ }
775
+ if (style.borders.right) {
776
+ const hasBottomBorderOffset = style.borders.bottom ? pixelFix : 0;
777
+ const widthOffset = isLast ? style.borders.right / 2 - pixelFix : 0;
778
+ pdf
779
+ .lineWidth(style.borders.right)
780
+ .moveTo(finalRect.x + finalRect.width - widthOffset, finalRect.y)
781
+ .lineTo(finalRect.x + finalRect.width - widthOffset, finalRect.y + finalRect.height + hasBottomBorderOffset)
782
+ .stroke(borderColor(style, "right"));
783
+ }
784
+ if (style.borders.left) {
785
+ const hasBottomBorderOffset = style.borders.bottom ? pixelFix : 0;
786
+ const widthOffset = isFirst ? style.borders.left / 2 - pixelFix : 0;
787
+ pdf
788
+ .lineWidth(style.borders.left)
789
+ .moveTo(finalRect.x + widthOffset, finalRect.y)
790
+ .lineTo(finalRect.x + widthOffset, finalRect.y + finalRect.height + hasBottomBorderOffset)
791
+ .stroke(borderColor(style, "left"));
792
+ }
793
+ if (style.borders.top) {
794
+ const hasRightBorderOffset = style.borders.right ? pixelFix : 0;
795
+ const hasLeftBorderOffset = style.borders.left ? pixelFix : 0;
796
+ const halfWidth = style.borders.top / 2 - pixelFix;
797
+ const widthOffset = isTop ? halfWidth : 0;
798
+ const notFirstOffset = !isFirst ? halfWidth : 0;
799
+ pdf
800
+ .lineWidth(style.borders.top)
801
+ .moveTo(finalRect.x - notFirstOffset - hasLeftBorderOffset, finalRect.y + widthOffset)
802
+ .lineTo(finalRect.x + finalRect.width + hasRightBorderOffset, finalRect.y + widthOffset)
803
+ .stroke(borderColor(style, "top"));
804
+ }
805
+ }
806
+
807
+ function borderColor(style: AD.TableCellStyle.TableCellStyle, edge: "top" | "bottom" | "left" | "right"): string {
808
+ if (style.borderColors && style.borderColors[edge]) {
809
+ return style.borderColors[edge];
810
+ }
811
+ if (style.borderColor) {
812
+ return style.borderColor;
813
+ }
814
+ return "black";
815
+ }
816
+
817
+ function getDesiredSize(element: {}, desiredSizes: Map<{}, AD.Size.Size>): AD.Size.Size {
818
+ const size = desiredSizes.get(element);
819
+ if (size) {
820
+ return size;
821
+ }
822
+ throw new Error("Could not find size for element!");
823
+ }
824
+
825
+ function applyTextOffset(pdf: any, textStyle: AD.TextStyle.TextStyle): void {
826
+ const offset = calculateTextOffset(textStyle);
827
+ if (offset < 0) {
828
+ pdf.moveDown(Math.abs(offset));
829
+ } else {
830
+ pdf.moveUp(offset);
831
+ }
832
+ }
833
+
834
+ function resetTextOffset(pdf: any, textStyle: AD.TextStyle.TextStyle): void {
835
+ const offset = calculateTextOffset(textStyle);
836
+ if (offset < 0) {
837
+ pdf.moveUp(Math.abs(offset));
838
+ } else {
839
+ pdf.moveDown(offset);
840
+ }
841
+ }
842
+
843
+ function calculateTextOffset(textStyle: AD.TextStyle.TextStyle): number {
844
+ const defaultPosition = textStyle.superScript ? -0.5 : textStyle.subScript ? 0.5 : 0;
845
+ const position = textStyle.verticalPosition !== undefined ? textStyle.verticalPosition : defaultPosition;
846
+ return position;
847
+ }