postext-pdf 1.63.2 → 1.63.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 (338) hide show
  1. package/dist/__bench__/arabicShaping.bench.test.js +1 -1
  2. package/dist/__bench__/arabicShaping.bench.test.js.map +1 -1
  3. package/dist/__tests__/accessibility.test.js +1 -1
  4. package/dist/__tests__/accessibility.test.js.map +1 -1
  5. package/dist/__tests__/boxBorderInside.test.js +1 -1
  6. package/dist/__tests__/boxBorderInside.test.js.map +1 -1
  7. package/dist/__tests__/boxShape.test.js +2 -2
  8. package/dist/__tests__/boxShape.test.js.map +1 -1
  9. package/dist/__tests__/canvasShaping.test.d.ts +1 -1
  10. package/dist/__tests__/canvasShaping.test.d.ts.map +1 -1
  11. package/dist/__tests__/canvasShaping.test.js +1 -1
  12. package/dist/__tests__/canvasShaping.test.js.map +1 -1
  13. package/dist/__tests__/comic.test.js +1 -1
  14. package/dist/__tests__/comic.test.js.map +1 -1
  15. package/dist/__tests__/comicMarkPairs.test.js +1 -1
  16. package/dist/__tests__/comicMarkPairs.test.js.map +1 -1
  17. package/dist/__tests__/composedDecorationImages.test.js +1 -1
  18. package/dist/__tests__/composedDecorationImages.test.js.map +1 -1
  19. package/dist/__tests__/composedFrameBoxes.test.js +1 -1
  20. package/dist/__tests__/composedFrameBoxes.test.js.map +1 -1
  21. package/dist/__tests__/composedPage.test.js +2 -2
  22. package/dist/__tests__/composedPage.test.js.map +1 -1
  23. package/dist/__tests__/declaredFiles.test.js +1 -1
  24. package/dist/__tests__/declaredFiles.test.js.map +1 -1
  25. package/dist/__tests__/dottedText.test.js +3 -3
  26. package/dist/__tests__/dottedText.test.js.map +1 -1
  27. package/dist/__tests__/headerFooter.test.js +2 -2
  28. package/dist/__tests__/headerFooter.test.js.map +1 -1
  29. package/dist/__tests__/pathBlock.test.js +2 -2
  30. package/dist/__tests__/pathBlock.test.js.map +1 -1
  31. package/dist/__tests__/printMaster.test.js +1 -1
  32. package/dist/__tests__/printMaster.test.js.map +1 -1
  33. package/dist/__tests__/rtlPdf.test.js +1 -1
  34. package/dist/__tests__/rtlPdf.test.js.map +1 -1
  35. package/dist/__tests__/shapingLanguage.test.js +1 -1
  36. package/dist/__tests__/shapingLanguage.test.js.map +1 -1
  37. package/dist/__tests__/shapingLanguageRuns.test.js +1 -1
  38. package/dist/__tests__/shapingLanguageRuns.test.js.map +1 -1
  39. package/dist/__tests__/shapingLanguageRunsDocument.test.js +1 -1
  40. package/dist/__tests__/shapingLanguageRunsDocument.test.js.map +1 -1
  41. package/dist/__tests__/sharedGlyphReadback.test.d.ts +1 -1
  42. package/dist/__tests__/sharedGlyphReadback.test.d.ts.map +1 -1
  43. package/dist/__tests__/sharedGlyphReadback.test.js +1 -1
  44. package/dist/__tests__/sharedGlyphReadback.test.js.map +1 -1
  45. package/dist/__tests__/svgVector.test.js +2 -2
  46. package/dist/__tests__/svgVector.test.js.map +1 -1
  47. package/dist/faceFiles.js +1 -1
  48. package/dist/faceFiles.js.map +1 -1
  49. package/dist/fontCache/fontFiles.d.ts +172 -0
  50. package/dist/fontCache/fontFiles.d.ts.map +1 -0
  51. package/dist/fontCache/fontFiles.js +81 -0
  52. package/dist/fontCache/fontFiles.js.map +1 -0
  53. package/dist/fontCache/glyphTables.d.ts +38 -0
  54. package/dist/fontCache/glyphTables.d.ts.map +1 -0
  55. package/dist/fontCache/glyphTables.js +107 -0
  56. package/dist/fontCache/glyphTables.js.map +1 -0
  57. package/dist/fontCache.d.ts +5 -189
  58. package/dist/fontCache.d.ts.map +1 -1
  59. package/dist/fontCache.js +5 -184
  60. package/dist/fontCache.js.map +1 -1
  61. package/dist/index.d.ts +2 -2
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +2 -2
  64. package/dist/index.js.map +1 -1
  65. package/dist/pdf-backend/blocks/blockRender/lineText.d.ts +23 -0
  66. package/dist/pdf-backend/blocks/blockRender/lineText.d.ts.map +1 -0
  67. package/dist/pdf-backend/blocks/blockRender/lineText.js +200 -0
  68. package/dist/pdf-backend/blocks/blockRender/lineText.js.map +1 -0
  69. package/dist/pdf-backend/blocks/blockRender/markers.d.ts +23 -0
  70. package/dist/pdf-backend/blocks/blockRender/markers.d.ts.map +1 -0
  71. package/dist/pdf-backend/blocks/blockRender/markers.js +140 -0
  72. package/dist/pdf-backend/blocks/blockRender/markers.js.map +1 -0
  73. package/dist/pdf-backend/blocks/blockRender/segments.d.ts +74 -0
  74. package/dist/pdf-backend/blocks/blockRender/segments.d.ts.map +1 -0
  75. package/dist/pdf-backend/blocks/blockRender/segments.js +409 -0
  76. package/dist/pdf-backend/blocks/blockRender/segments.js.map +1 -0
  77. package/dist/pdf-backend/{blockRender.d.ts → blocks/blockRender.d.ts} +7 -10
  78. package/dist/pdf-backend/blocks/blockRender.d.ts.map +1 -0
  79. package/dist/pdf-backend/blocks/blockRender.js +146 -0
  80. package/dist/pdf-backend/blocks/blockRender.js.map +1 -0
  81. package/dist/pdf-backend/{chip.d.ts → blocks/chip.d.ts} +3 -3
  82. package/dist/pdf-backend/blocks/chip.d.ts.map +1 -0
  83. package/dist/pdf-backend/{chip.js → blocks/chip.js} +5 -5
  84. package/dist/pdf-backend/blocks/chip.js.map +1 -0
  85. package/dist/pdf-backend/{inlineIcon.d.ts → blocks/inlineIcon.d.ts} +3 -3
  86. package/dist/pdf-backend/blocks/inlineIcon.d.ts.map +1 -0
  87. package/dist/pdf-backend/{inlineIcon.js → blocks/inlineIcon.js} +3 -3
  88. package/dist/pdf-backend/blocks/inlineIcon.js.map +1 -0
  89. package/dist/pdf-backend/blocks/renderResourceBlock/lines.d.ts +37 -0
  90. package/dist/pdf-backend/blocks/renderResourceBlock/lines.d.ts.map +1 -0
  91. package/dist/pdf-backend/blocks/renderResourceBlock/lines.js +271 -0
  92. package/dist/pdf-backend/blocks/renderResourceBlock/lines.js.map +1 -0
  93. package/dist/pdf-backend/blocks/renderResourceBlock/overlays.d.ts +21 -0
  94. package/dist/pdf-backend/blocks/renderResourceBlock/overlays.d.ts.map +1 -0
  95. package/dist/pdf-backend/blocks/renderResourceBlock/overlays.js +164 -0
  96. package/dist/pdf-backend/blocks/renderResourceBlock/overlays.js.map +1 -0
  97. package/dist/pdf-backend/blocks/renderResourceBlock/preload.d.ts +27 -0
  98. package/dist/pdf-backend/blocks/renderResourceBlock/preload.d.ts.map +1 -0
  99. package/dist/pdf-backend/blocks/renderResourceBlock/preload.js +330 -0
  100. package/dist/pdf-backend/blocks/renderResourceBlock/preload.js.map +1 -0
  101. package/dist/pdf-backend/blocks/renderResourceBlock/rasterize.d.ts +38 -0
  102. package/dist/pdf-backend/blocks/renderResourceBlock/rasterize.d.ts.map +1 -0
  103. package/dist/pdf-backend/blocks/renderResourceBlock/rasterize.js +218 -0
  104. package/dist/pdf-backend/blocks/renderResourceBlock/rasterize.js.map +1 -0
  105. package/dist/pdf-backend/blocks/renderResourceBlock/table.d.ts +17 -0
  106. package/dist/pdf-backend/blocks/renderResourceBlock/table.d.ts.map +1 -0
  107. package/dist/pdf-backend/blocks/renderResourceBlock/table.js +203 -0
  108. package/dist/pdf-backend/blocks/renderResourceBlock/table.js.map +1 -0
  109. package/dist/pdf-backend/blocks/renderResourceBlock.d.ts +59 -0
  110. package/dist/pdf-backend/blocks/renderResourceBlock.d.ts.map +1 -0
  111. package/dist/pdf-backend/blocks/renderResourceBlock.js +201 -0
  112. package/dist/pdf-backend/blocks/renderResourceBlock.js.map +1 -0
  113. package/dist/pdf-backend/{scoreRender.d.ts → blocks/scoreRender.d.ts} +2 -2
  114. package/dist/pdf-backend/blocks/scoreRender.d.ts.map +1 -0
  115. package/dist/pdf-backend/{scoreRender.js → blocks/scoreRender.js} +2 -2
  116. package/dist/pdf-backend/blocks/scoreRender.js.map +1 -0
  117. package/dist/pdf-backend/{taskBox.d.ts → blocks/taskBox.d.ts} +1 -1
  118. package/dist/pdf-backend/blocks/taskBox.d.ts.map +1 -0
  119. package/dist/pdf-backend/{taskBox.js → blocks/taskBox.js} +1 -1
  120. package/dist/pdf-backend/blocks/taskBox.js.map +1 -0
  121. package/dist/pdf-backend/index.d.ts +8 -114
  122. package/dist/pdf-backend/index.d.ts.map +1 -1
  123. package/dist/pdf-backend/index.js +16 -614
  124. package/dist/pdf-backend/index.js.map +1 -1
  125. package/dist/pdf-backend/{comic.d.ts → page/comic.d.ts} +6 -6
  126. package/dist/pdf-backend/page/comic.d.ts.map +1 -0
  127. package/dist/pdf-backend/{comic.js → page/comic.js} +4 -4
  128. package/dist/pdf-backend/page/comic.js.map +1 -0
  129. package/dist/pdf-backend/{headerFooter.d.ts → page/headerFooter.d.ts} +4 -4
  130. package/dist/pdf-backend/page/headerFooter.d.ts.map +1 -0
  131. package/dist/pdf-backend/{headerFooter.js → page/headerFooter.js} +8 -8
  132. package/dist/pdf-backend/page/headerFooter.js.map +1 -0
  133. package/dist/pdf-backend/{pageDecorations.d.ts → page/pageDecorations.d.ts} +1 -1
  134. package/dist/pdf-backend/page/pageDecorations.d.ts.map +1 -0
  135. package/dist/pdf-backend/{pageDecorations.js → page/pageDecorations.js} +1 -1
  136. package/dist/pdf-backend/page/pageDecorations.js.map +1 -0
  137. package/dist/pdf-backend/page/pageLabels.d.ts.map +1 -0
  138. package/dist/pdf-backend/page/pageLabels.js.map +1 -0
  139. package/dist/pdf-backend/primitives/actualText.d.ts +91 -0
  140. package/dist/pdf-backend/primitives/actualText.d.ts.map +1 -0
  141. package/dist/pdf-backend/primitives/actualText.js +154 -0
  142. package/dist/pdf-backend/primitives/actualText.js.map +1 -0
  143. package/dist/pdf-backend/primitives/color.d.ts +22 -0
  144. package/dist/pdf-backend/primitives/color.d.ts.map +1 -0
  145. package/dist/pdf-backend/primitives/color.js +116 -0
  146. package/dist/pdf-backend/primitives/color.js.map +1 -0
  147. package/dist/pdf-backend/primitives/matrix.d.ts +55 -0
  148. package/dist/pdf-backend/primitives/matrix.d.ts.map +1 -0
  149. package/dist/pdf-backend/primitives/matrix.js +124 -0
  150. package/dist/pdf-backend/primitives/matrix.js.map +1 -0
  151. package/dist/pdf-backend/primitives/measuredText.d.ts +61 -0
  152. package/dist/pdf-backend/primitives/measuredText.d.ts.map +1 -0
  153. package/dist/pdf-backend/primitives/measuredText.js +142 -0
  154. package/dist/pdf-backend/primitives/measuredText.js.map +1 -0
  155. package/dist/pdf-backend/primitives/shapedRuns.d.ts +49 -0
  156. package/dist/pdf-backend/primitives/shapedRuns.d.ts.map +1 -0
  157. package/dist/pdf-backend/primitives/shapedRuns.js +367 -0
  158. package/dist/pdf-backend/primitives/shapedRuns.js.map +1 -0
  159. package/dist/pdf-backend/primitives/shapes.d.ts +35 -0
  160. package/dist/pdf-backend/primitives/shapes.d.ts.map +1 -0
  161. package/dist/pdf-backend/primitives/shapes.js +166 -0
  162. package/dist/pdf-backend/primitives/shapes.js.map +1 -0
  163. package/dist/pdf-backend/primitives/textShows.d.ts +90 -0
  164. package/dist/pdf-backend/primitives/textShows.d.ts.map +1 -0
  165. package/dist/pdf-backend/primitives/textShows.js +167 -0
  166. package/dist/pdf-backend/primitives/textShows.js.map +1 -0
  167. package/dist/pdf-backend/primitives.d.ts +16 -308
  168. package/dist/pdf-backend/primitives.d.ts.map +1 -1
  169. package/dist/pdf-backend/primitives.js +15 -1195
  170. package/dist/pdf-backend/primitives.js.map +1 -1
  171. package/dist/pdf-backend/renderToPdf/composedFrames.d.ts +19 -0
  172. package/dist/pdf-backend/renderToPdf/composedFrames.d.ts.map +1 -0
  173. package/dist/pdf-backend/renderToPdf/composedFrames.js +156 -0
  174. package/dist/pdf-backend/renderToPdf/composedFrames.js.map +1 -0
  175. package/dist/pdf-backend/renderToPdf/metadata.d.ts +31 -0
  176. package/dist/pdf-backend/renderToPdf/metadata.d.ts.map +1 -0
  177. package/dist/pdf-backend/renderToPdf/metadata.js +85 -0
  178. package/dist/pdf-backend/renderToPdf/metadata.js.map +1 -0
  179. package/dist/pdf-backend/renderToPdf/paintPage.d.ts +16 -0
  180. package/dist/pdf-backend/renderToPdf/paintPage.d.ts.map +1 -0
  181. package/dist/pdf-backend/renderToPdf/paintPage.js +348 -0
  182. package/dist/pdf-backend/renderToPdf/paintPage.js.map +1 -0
  183. package/dist/pdf-backend/renderToPdf/warnings.d.ts +114 -0
  184. package/dist/pdf-backend/renderToPdf/warnings.d.ts.map +1 -0
  185. package/dist/pdf-backend/renderToPdf/warnings.js +35 -0
  186. package/dist/pdf-backend/renderToPdf/warnings.js.map +1 -0
  187. package/dist/pdf-backend/structure/links.d.ts.map +1 -0
  188. package/dist/pdf-backend/structure/links.js.map +1 -0
  189. package/dist/pdf-backend/structure/outlines.d.ts.map +1 -0
  190. package/dist/pdf-backend/structure/outlines.js.map +1 -0
  191. package/dist/pdf-backend/structure/structureFlow.d.ts.map +1 -0
  192. package/dist/pdf-backend/structure/structureFlow.js.map +1 -0
  193. package/dist/pdf-backend/{tagging.d.ts → structure/tagging.d.ts} +1 -1
  194. package/dist/pdf-backend/structure/tagging.d.ts.map +1 -0
  195. package/dist/pdf-backend/structure/tagging.js.map +1 -0
  196. package/dist/pdf-backend/{annotations.d.ts → text/annotations.d.ts} +3 -3
  197. package/dist/pdf-backend/text/annotations.d.ts.map +1 -0
  198. package/dist/pdf-backend/{annotations.js → text/annotations.js} +3 -3
  199. package/dist/pdf-backend/text/annotations.js.map +1 -0
  200. package/dist/pdf-backend/{directedLine.d.ts → text/directedLine.d.ts} +1 -1
  201. package/dist/pdf-backend/text/directedLine.d.ts.map +1 -0
  202. package/dist/pdf-backend/{directedLine.js → text/directedLine.js} +1 -1
  203. package/dist/pdf-backend/text/directedLine.js.map +1 -0
  204. package/dist/pdf-backend/text/fallbackSpaces.d.ts.map +1 -0
  205. package/dist/pdf-backend/text/fallbackSpaces.js.map +1 -0
  206. package/dist/pdf-backend/text/fontHelpers.d.ts.map +1 -0
  207. package/dist/pdf-backend/text/fontHelpers.js.map +1 -0
  208. package/dist/pdf-backend/text/inkScale.d.ts.map +1 -0
  209. package/dist/pdf-backend/text/inkScale.js.map +1 -0
  210. package/dist/pdf-backend/{rtlRun.d.ts → text/rtlRun.d.ts} +1 -1
  211. package/dist/pdf-backend/text/rtlRun.d.ts.map +1 -0
  212. package/dist/pdf-backend/{rtlRun.js → text/rtlRun.js} +2 -2
  213. package/dist/pdf-backend/text/rtlRun.js.map +1 -0
  214. package/dist/pdf-backend/text/shapedText/shaping.d.ts +70 -0
  215. package/dist/pdf-backend/text/shapedText/shaping.d.ts.map +1 -0
  216. package/dist/pdf-backend/text/shapedText/shaping.js +380 -0
  217. package/dist/pdf-backend/text/shapedText/shaping.js.map +1 -0
  218. package/dist/pdf-backend/{shapedText.d.ts → text/shapedText.d.ts} +2 -2
  219. package/dist/pdf-backend/text/shapedText.d.ts.map +1 -0
  220. package/dist/pdf-backend/text/shapedText.js +311 -0
  221. package/dist/pdf-backend/text/shapedText.js.map +1 -0
  222. package/dist/pdf-backend/{verticalText.d.ts → text/verticalText.d.ts} +1 -1
  223. package/dist/pdf-backend/text/verticalText.d.ts.map +1 -0
  224. package/dist/pdf-backend/{verticalText.js → text/verticalText.js} +4 -4
  225. package/dist/pdf-backend/text/verticalText.js.map +1 -0
  226. package/dist/pdf-backend/text/wordPieces.d.ts.map +1 -0
  227. package/dist/pdf-backend/{wordPieces.js → text/wordPieces.js} +1 -1
  228. package/dist/pdf-backend/text/wordPieces.js.map +1 -0
  229. package/dist/pdf-backend/{pathBlock.d.ts → vector/pathBlock.d.ts} +1 -1
  230. package/dist/pdf-backend/vector/pathBlock.d.ts.map +1 -0
  231. package/dist/pdf-backend/{pathBlock.js → vector/pathBlock.js} +1 -1
  232. package/dist/pdf-backend/vector/pathBlock.js.map +1 -0
  233. package/dist/pdf-backend/vector/svgVector/emit.d.ts +11 -0
  234. package/dist/pdf-backend/vector/svgVector/emit.d.ts.map +1 -0
  235. package/dist/pdf-backend/vector/svgVector/emit.js +281 -0
  236. package/dist/pdf-backend/vector/svgVector/emit.js.map +1 -0
  237. package/dist/pdf-backend/vector/svgVector/geometry.d.ts +18 -0
  238. package/dist/pdf-backend/vector/svgVector/geometry.d.ts.map +1 -0
  239. package/dist/pdf-backend/vector/svgVector/geometry.js +382 -0
  240. package/dist/pdf-backend/vector/svgVector/geometry.js.map +1 -0
  241. package/dist/pdf-backend/vector/svgVector/style.d.ts +37 -0
  242. package/dist/pdf-backend/vector/svgVector/style.d.ts.map +1 -0
  243. package/dist/pdf-backend/vector/svgVector/style.js +314 -0
  244. package/dist/pdf-backend/vector/svgVector/style.js.map +1 -0
  245. package/dist/pdf-backend/vector/svgVector/walk.d.ts +15 -0
  246. package/dist/pdf-backend/vector/svgVector/walk.d.ts.map +1 -0
  247. package/dist/pdf-backend/vector/svgVector/walk.js +405 -0
  248. package/dist/pdf-backend/vector/svgVector/walk.js.map +1 -0
  249. package/dist/pdf-backend/vector/svgVector/xml.d.ts +20 -0
  250. package/dist/pdf-backend/vector/svgVector/xml.d.ts.map +1 -0
  251. package/dist/pdf-backend/vector/svgVector/xml.js +160 -0
  252. package/dist/pdf-backend/vector/svgVector/xml.js.map +1 -0
  253. package/dist/pdf-backend/{svgVector.d.ts → vector/svgVector.d.ts} +2 -12
  254. package/dist/pdf-backend/vector/svgVector.d.ts.map +1 -0
  255. package/dist/pdf-backend/vector/svgVector.js +95 -0
  256. package/dist/pdf-backend/vector/svgVector.js.map +1 -0
  257. package/dist/pdf-backend/vector/tint.d.ts.map +1 -0
  258. package/dist/pdf-backend/{tint.js → vector/tint.js} +1 -1
  259. package/dist/pdf-backend/vector/tint.js.map +1 -0
  260. package/dist/worker/client.d.ts +1 -1
  261. package/dist/worker/client.d.ts.map +1 -1
  262. package/dist/worker/client.js +1 -1
  263. package/dist/worker/client.js.map +1 -1
  264. package/package.json +3 -3
  265. package/dist/pdf-backend/annotations.d.ts.map +0 -1
  266. package/dist/pdf-backend/annotations.js.map +0 -1
  267. package/dist/pdf-backend/blockRender.d.ts.map +0 -1
  268. package/dist/pdf-backend/blockRender.js +0 -866
  269. package/dist/pdf-backend/blockRender.js.map +0 -1
  270. package/dist/pdf-backend/chip.d.ts.map +0 -1
  271. package/dist/pdf-backend/chip.js.map +0 -1
  272. package/dist/pdf-backend/comic.d.ts.map +0 -1
  273. package/dist/pdf-backend/comic.js.map +0 -1
  274. package/dist/pdf-backend/directedLine.d.ts.map +0 -1
  275. package/dist/pdf-backend/directedLine.js.map +0 -1
  276. package/dist/pdf-backend/fallbackSpaces.d.ts.map +0 -1
  277. package/dist/pdf-backend/fallbackSpaces.js.map +0 -1
  278. package/dist/pdf-backend/fontHelpers.d.ts.map +0 -1
  279. package/dist/pdf-backend/fontHelpers.js.map +0 -1
  280. package/dist/pdf-backend/headerFooter.d.ts.map +0 -1
  281. package/dist/pdf-backend/headerFooter.js.map +0 -1
  282. package/dist/pdf-backend/inkScale.d.ts.map +0 -1
  283. package/dist/pdf-backend/inkScale.js.map +0 -1
  284. package/dist/pdf-backend/inlineIcon.d.ts.map +0 -1
  285. package/dist/pdf-backend/inlineIcon.js.map +0 -1
  286. package/dist/pdf-backend/links.d.ts.map +0 -1
  287. package/dist/pdf-backend/links.js.map +0 -1
  288. package/dist/pdf-backend/outlines.d.ts.map +0 -1
  289. package/dist/pdf-backend/outlines.js.map +0 -1
  290. package/dist/pdf-backend/pageDecorations.d.ts.map +0 -1
  291. package/dist/pdf-backend/pageDecorations.js.map +0 -1
  292. package/dist/pdf-backend/pageLabels.d.ts.map +0 -1
  293. package/dist/pdf-backend/pageLabels.js.map +0 -1
  294. package/dist/pdf-backend/pathBlock.d.ts.map +0 -1
  295. package/dist/pdf-backend/pathBlock.js.map +0 -1
  296. package/dist/pdf-backend/renderResourceBlock.d.ts +0 -120
  297. package/dist/pdf-backend/renderResourceBlock.d.ts.map +0 -1
  298. package/dist/pdf-backend/renderResourceBlock.js +0 -1351
  299. package/dist/pdf-backend/renderResourceBlock.js.map +0 -1
  300. package/dist/pdf-backend/rtlRun.d.ts.map +0 -1
  301. package/dist/pdf-backend/rtlRun.js.map +0 -1
  302. package/dist/pdf-backend/scoreRender.d.ts.map +0 -1
  303. package/dist/pdf-backend/scoreRender.js.map +0 -1
  304. package/dist/pdf-backend/shapedText.d.ts.map +0 -1
  305. package/dist/pdf-backend/shapedText.js +0 -682
  306. package/dist/pdf-backend/shapedText.js.map +0 -1
  307. package/dist/pdf-backend/structureFlow.d.ts.map +0 -1
  308. package/dist/pdf-backend/structureFlow.js.map +0 -1
  309. package/dist/pdf-backend/svgVector.d.ts.map +0 -1
  310. package/dist/pdf-backend/svgVector.js +0 -1610
  311. package/dist/pdf-backend/svgVector.js.map +0 -1
  312. package/dist/pdf-backend/tagging.d.ts.map +0 -1
  313. package/dist/pdf-backend/tagging.js.map +0 -1
  314. package/dist/pdf-backend/taskBox.d.ts.map +0 -1
  315. package/dist/pdf-backend/taskBox.js.map +0 -1
  316. package/dist/pdf-backend/tint.d.ts.map +0 -1
  317. package/dist/pdf-backend/tint.js.map +0 -1
  318. package/dist/pdf-backend/verticalText.d.ts.map +0 -1
  319. package/dist/pdf-backend/verticalText.js.map +0 -1
  320. package/dist/pdf-backend/wordPieces.d.ts.map +0 -1
  321. package/dist/pdf-backend/wordPieces.js.map +0 -1
  322. /package/dist/pdf-backend/{pageLabels.d.ts → page/pageLabels.d.ts} +0 -0
  323. /package/dist/pdf-backend/{pageLabels.js → page/pageLabels.js} +0 -0
  324. /package/dist/pdf-backend/{links.d.ts → structure/links.d.ts} +0 -0
  325. /package/dist/pdf-backend/{links.js → structure/links.js} +0 -0
  326. /package/dist/pdf-backend/{outlines.d.ts → structure/outlines.d.ts} +0 -0
  327. /package/dist/pdf-backend/{outlines.js → structure/outlines.js} +0 -0
  328. /package/dist/pdf-backend/{structureFlow.d.ts → structure/structureFlow.d.ts} +0 -0
  329. /package/dist/pdf-backend/{structureFlow.js → structure/structureFlow.js} +0 -0
  330. /package/dist/pdf-backend/{tagging.js → structure/tagging.js} +0 -0
  331. /package/dist/pdf-backend/{fallbackSpaces.d.ts → text/fallbackSpaces.d.ts} +0 -0
  332. /package/dist/pdf-backend/{fallbackSpaces.js → text/fallbackSpaces.js} +0 -0
  333. /package/dist/pdf-backend/{fontHelpers.d.ts → text/fontHelpers.d.ts} +0 -0
  334. /package/dist/pdf-backend/{fontHelpers.js → text/fontHelpers.js} +0 -0
  335. /package/dist/pdf-backend/{inkScale.d.ts → text/inkScale.d.ts} +0 -0
  336. /package/dist/pdf-backend/{inkScale.js → text/inkScale.js} +0 -0
  337. /package/dist/pdf-backend/{wordPieces.d.ts → text/wordPieces.d.ts} +0 -0
  338. /package/dist/pdf-backend/{tint.d.ts → vector/tint.d.ts} +0 -0
@@ -1,1351 +0,0 @@
1
- /**
2
- * PDF rendering of resource blocks (issue #49 §7).
3
- *
4
- * Draws an embedded `Resource` (bitmap / svg / table) plus its caption into a
5
- * pdf-lib page. Image payloads live out-of-band (IndexedDB in the sandbox); the
6
- * host supplies their raw bytes via {@link RenderToPdfOptions.resourceBytes},
7
- * which {@link preloadResourceImages} embeds into the document up front (PDF
8
- * embedding is async; page rendering is sync).
9
- *
10
- * The bytes are sniffed, so the host never has to say what it hands over:
11
- * - `%PDF` → the first page is embedded as a form XObject and drawn
12
- * verbatim (vector print masters: an SVG's
13
- * `Resource.svg.pdfFileId`, named on every use of the SVG in
14
- * the VDT, is asked for first, outside single-ink mode);
15
- * - SVG → single-ink recolouring when `diagramStyle.singleInk` is on,
16
- * then vector emission through {@link svgToVectorDrawing}, with
17
- * `text` set in fonts loaded through the document's
18
- * {@link FontCache} (same provider as the body text); SVGs
19
- * outside the supported subset are rasterised (browser only) at
20
- * {@link RASTER_DPI} for their largest placement;
21
- * - PNG / JPEG / WebP / GIF → `embedPng` / `embedJpg` (WebP is decoded to
22
- * PNG via a canvas first; browser only).
23
- * A missing or undecodable payload leaves the map entry absent and the
24
- * renderer draws a neutral placeholder.
25
- *
26
- * Inline `:ref` segments render in the link colour and, via {@link LinkRegistry},
27
- * become clickable link annotations targeting the resource embed's destination.
28
- */
29
- import { paintScoreBody } from './scoreRender.js';
30
- import { PDFHexString, popGraphicsState, pushGraphicsState, setFillingColor } from 'pdf-lib';
31
- import { altWithLabels, figureLabelLeaderPaths, figureLabelMatrix, labelPlateBox, resourceBlockIcons, undrawnLabels, unmirrorLabelLayout, applySingleInkToSvg, fontFaceRule, injectSvgStyle, sniffFontFormat, svgDeclaredFontFamilies, pageComics, playMarkTriangle, qrModuleRuns, resolveColorValue, tableCellFillRects, tableFrameOutline, uncroppedPictureBox } from 'postext';
32
- import { drawRoundedBox, roundedRectSvgPath } from './headerFooter.js';
33
- import { renderPathBlock } from './pathBlock.js';
34
- import { pdfUri } from './links.js';
35
- import { parseFontString } from '../fontString.js';
36
- import { declarationOf, fontFilesOf, inDeclarationOrder } from '../fontCache.js';
37
- import { parseUnicodeRange } from '../unicodeRange.js';
38
- import { widthOfTextAtSize } from '../faceFiles.js';
39
- import { beginActualTextSpan, cellPieces, cjkLineText, compressedMarkSpacingPx, drawMeasuredTextPx, drawTextPx, setTrackingPx, endActualTextSpan, drawLinePx, fillRectPx, fillRectsPx, colorFromHex, outerRectMap, popFrame, pushFrame, quarterTurnMatrix, pushClipOutline, pushClipRect, popClip, strokeOutlinePx, counterFlipPx, paintInScript, textAdvancePx, } from './primitives.js';
40
- import { RefRun, refTarget, UriRuns } from './links.js';
41
- import { paintChip } from './chip.js';
42
- import { renderMathSegment } from './blockRender.js';
43
- import { paintKunten, paintLineHighlights, paintLineMarks, paintRuby, paintWarichu } from './annotations.js';
44
- import { tagArtifact, tagContent } from './tagging.js';
45
- import { sheetMatrixToPdf } from './comic.js';
46
- import { svgToVectorDrawing, drawVectorDrawing, } from './svgVector.js';
47
- import { inkScaleOperators } from './inkScale.js';
48
- import { paintSwatchSegmentPdf } from './inlineIcon.js';
49
- import { drawShapedTextPx, drawStyledWordPx } from './shapedText.js';
50
- import { segmentLanguages, segmentOffsets, wordParts } from './directedLine.js';
51
- import { withSegmentLanguage } from '../shapingLanguage.js';
52
- import { wordSegments } from './wordPieces.js';
53
- import { loadComplexShaper, needsComplexShaping } from '../complexShaping.js';
54
- import { embedDeviceRaster, embedPrintRaster } from '../print/images.js';
55
- import { alphaStencil, tintedDrawing } from './tint.js';
56
- /** Resolution of the raster fallback for SVGs the vector path cannot emit,
57
- * relative to the figure's largest placement on the page. Diagrams are line
58
- * art with small type, so this sits above the 300 dpi photographs need. */
59
- export const RASTER_DPI = 600;
60
- /** Identify a payload from its leading bytes. */
61
- export function sniffBytes(bytes) {
62
- const at = (i) => bytes[i] ?? -1;
63
- if (at(0) === 0x25 && at(1) === 0x50 && at(2) === 0x44 && at(3) === 0x46)
64
- return 'pdf'; // %PDF
65
- if (at(0) === 0x89 && at(1) === 0x50 && at(2) === 0x4e && at(3) === 0x47)
66
- return 'png';
67
- if (at(0) === 0xff && at(1) === 0xd8)
68
- return 'jpeg';
69
- if (at(0) === 0x47 && at(1) === 0x49 && at(2) === 0x46 && at(3) === 0x38)
70
- return 'gif';
71
- if (at(0) === 0x52 && at(1) === 0x49 && at(2) === 0x46 && at(3) === 0x46
72
- && at(8) === 0x57 && at(9) === 0x45 && at(10) === 0x42 && at(11) === 0x50)
73
- return 'webp';
74
- // SVG: optional BOM / whitespace, then `<` (XML declaration, comment,
75
- // doctype or the root element itself).
76
- let i = 0;
77
- if (at(0) === 0xef && at(1) === 0xbb && at(2) === 0xbf)
78
- i = 3;
79
- while (i < bytes.length && (at(i) === 0x20 || at(i) === 0x09 || at(i) === 0x0a || at(i) === 0x0d))
80
- i++;
81
- if (at(i) === 0x3c) {
82
- const head = new TextDecoder().decode(bytes.subarray(i, Math.min(bytes.length, i + 4096)));
83
- if (/<svg[\s>]/i.test(head) || /^<\?xml/i.test(head) || head.startsWith('<!'))
84
- return 'svg';
85
- }
86
- return 'unknown';
87
- }
88
- /** A PNG of `bitmap`, drawn on whatever canvas the environment has (a
89
- * worker has `OffscreenCanvas`, a document has both). */
90
- async function bitmapToPng(bitmap) {
91
- if (typeof OffscreenCanvas !== 'undefined') {
92
- const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
93
- const c2d = canvas.getContext('2d');
94
- if (!c2d)
95
- return null;
96
- c2d.drawImage(bitmap, 0, 0);
97
- const pngBlob = await canvas.convertToBlob({ type: 'image/png' });
98
- return new Uint8Array(await pngBlob.arrayBuffer());
99
- }
100
- if (typeof document === 'undefined')
101
- return null;
102
- const canvas = document.createElement('canvas');
103
- canvas.width = bitmap.width;
104
- canvas.height = bitmap.height;
105
- const c2d = canvas.getContext('2d');
106
- if (!c2d)
107
- return null;
108
- c2d.drawImage(bitmap, 0, 0);
109
- const pngBlob = await new Promise((res) => canvas.toBlob(res, 'image/png'));
110
- if (!pngBlob)
111
- return null;
112
- return new Uint8Array(await pngBlob.arrayBuffer());
113
- }
114
- /** Decode WebP bytes to PNG bytes via a canvas. Browser (or worker) only. */
115
- async function webpToPng(bytes) {
116
- if (typeof createImageBitmap === 'undefined')
117
- return null;
118
- try {
119
- const blob = new Blob([bytes], { type: 'image/webp' });
120
- return await bitmapToPng(await createImageBitmap(blob));
121
- }
122
- catch {
123
- return null;
124
- }
125
- }
126
- /** Rasterise SVG markup to PNG bytes at the given pixel size, through an
127
- * `Image` and a canvas of the document. Browser main thread only (a
128
- * worker cannot decode SVG); returns null elsewhere or when the SVG does
129
- * not decode. The default {@link SvgRasterizer}. */
130
- export async function rasterizeSvgWithDom(svgText, widthPx, heightPx) {
131
- if (typeof document === 'undefined' || typeof URL === 'undefined' || typeof Image === 'undefined')
132
- return null;
133
- const blob = new Blob([svgText], { type: 'image/svg+xml' });
134
- const url = URL.createObjectURL(blob);
135
- try {
136
- const img = new Image();
137
- await new Promise((resolve, reject) => {
138
- img.onload = () => resolve();
139
- img.onerror = () => reject(new Error('SVG decode failed'));
140
- img.src = url;
141
- });
142
- const canvas = document.createElement('canvas');
143
- canvas.width = Math.max(1, Math.round(widthPx));
144
- canvas.height = Math.max(1, Math.round(heightPx));
145
- const c2d = canvas.getContext('2d');
146
- if (!c2d)
147
- return null;
148
- c2d.drawImage(img, 0, 0, canvas.width, canvas.height);
149
- const pngBlob = await new Promise((res) => canvas.toBlob(res, 'image/png'));
150
- if (!pngBlob)
151
- return null;
152
- return new Uint8Array(await pngBlob.arrayBuffer());
153
- }
154
- catch {
155
- return null;
156
- }
157
- finally {
158
- URL.revokeObjectURL(url);
159
- }
160
- }
161
- /** Generic CSS families that never name a loadable font. */
162
- const GENERIC_FAMILIES = new Set([
163
- 'serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui', 'ui-serif', 'ui-sans-serif',
164
- 'ui-monospace', 'ui-rounded', 'emoji', 'math', 'fangsong', 'inherit', 'initial',
165
- ]);
166
- /** A canvas font string for one family / weight / style (size is irrelevant
167
- * to the cache key). */
168
- function svgFontString(family, weight, italic) {
169
- return `${italic ? 'italic ' : ''}${weight} 16px ${family}`;
170
- }
171
- /** The character of a numeric reference; nothing for one out of range. */
172
- function charOf(cp) {
173
- return Number.isInteger(cp) && cp >= 0 && cp <= 0x10ffff ? String.fromCodePoint(cp) : '';
174
- }
175
- /** The characters an SVG's text may set: those of its markup outside tags,
176
- * entities decoded — more than its text nodes (a `<style>` sheet counts
177
- * too), which only asks a sliced face for a file more. */
178
- export function svgCodePoints(svgText) {
179
- const text = svgText
180
- .replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1')
181
- .replace(/<[^>]*>/g, ' ')
182
- .replace(/&#x([0-9a-f]+);/gi, (_, hex) => charOf(parseInt(hex, 16)))
183
- .replace(/&#(\d+);/g, (_, dec) => charOf(parseInt(dec, 10)))
184
- .replace(/&(lt|gt|amp|quot|apos);/g, (_, name) => ({ lt: '<', gt: '>', amp: '&', quot: '"', apos: "'" })[name] ?? '');
185
- const out = new Set();
186
- for (const ch of text) {
187
- const cp = ch.codePointAt(0);
188
- if (cp > 0x20)
189
- out.add(cp);
190
- }
191
- out.add(0x20);
192
- return out;
193
- }
194
- /** Fonts an SVG's text would need, as font strings the {@link FontCache}
195
- * can preload: every named (non-generic) family of each run, so the
196
- * resolver can fall through the `font-family` list in order. */
197
- export function collectSvgFontStrings(svgText) {
198
- const wanted = new Set();
199
- const probe = (families, weight, italic) => {
200
- for (const f of families)
201
- if (!GENERIC_FAMILIES.has(f.toLowerCase()))
202
- wanted.add(svgFontString(f, weight, italic));
203
- return { widthOf: () => 0, pdfFont: null };
204
- };
205
- svgToVectorDrawing(svgText, { fonts: probe, probe: true });
206
- return [...wanted];
207
- }
208
- /** Resolve SVG font requests against the preloaded cache: the first named
209
- * family of the list that loaded wins; generic families never match. */
210
- export function fontResolverFor(fontCache) {
211
- const fonts = new Map();
212
- return (families, weight, italic) => {
213
- for (const f of families) {
214
- if (GENERIC_FAMILIES.has(f.toLowerCase()))
215
- continue;
216
- const pdfFont = fontCache.get(svgFontString(f, weight, italic));
217
- if (!pdfFont)
218
- continue;
219
- let vf = fonts.get(pdfFont);
220
- if (!vf) {
221
- vf = { pdfFont, widthOf: (text, size) => widthOfTextAtSize(pdfFont, text, size) };
222
- fonts.set(pdfFont, vf);
223
- }
224
- return vf;
225
- }
226
- return null;
227
- };
228
- }
229
- /** Before an SVG with text is rasterised through an `<img>` — which cannot
230
- * see any page font — embed the faces its runs ask for as `@font-face` data
231
- * URIs, fetched from the same provider the body text uses (#630: the
232
- * engine's `fontFaceRule` / `injectSvgStyle`). Families the provider cannot
233
- * supply are skipped (the image falls back to a system face, as the screen
234
- * preview would), and so are those the SVG declares itself. */
235
- export async function inlineSvgFontsForRaster(svgText, fontStrings, provider) {
236
- let css = '';
237
- const codePoints = svgCodePoints(svgText);
238
- const declared = new Set(svgDeclaredFontFamilies(svgText).map((f) => f.toLowerCase()));
239
- for (const fs of fontStrings) {
240
- const parsed = parseFontString(fs);
241
- if (!parsed || declared.has(parsed.family.toLowerCase()))
242
- continue;
243
- const answer = await provider(parsed.family, parsed.weight, parsed.style, { codePoints }).catch(() => null);
244
- // A face of several files is one @font-face per file: the browser
245
- // looks each character up in them in turn. Files given with their
246
- // ranges are declared as the page declared them, each rule with its
247
- // range and the one declared last at the end, so the picture takes a
248
- // character from the file the page did.
249
- const files = answer ? fontFilesOf(answer) : [];
250
- const rangesOf = (file) => {
251
- const unicodeRange = declarationOf(file)?.unicodeRange;
252
- return unicodeRange === undefined ? undefined : parseUnicodeRange(unicodeRange);
253
- };
254
- const ranged = files.some((file) => rangesOf(file) !== undefined);
255
- for (const bytes of ranged ? inDeclarationOrder(files) : files) {
256
- if (bytes.length === 0)
257
- continue;
258
- const rule = fontFaceRule(parsed.family, parsed.weight, parsed.style, bytes, sniffFontFormat(bytes) ?? 'ttf');
259
- const ranges = rangesOf(bytes);
260
- css += ranges && rule.endsWith('}')
261
- ? `${rule.slice(0, -1)};unicode-range:${ranges.map(([lo, hi]) => `U+${lo.toString(16)}${hi > lo ? `-${hi.toString(16)}` : ''}`).join(',')}}`
262
- : rule;
263
- }
264
- }
265
- return injectSvgStyle(svgText, css);
266
- }
267
- /** Largest placement of each `fileId` in points, to size raster fallbacks. */
268
- function largestPlacements(doc, blocks) {
269
- const scale = 72 / doc.config.page.dpi;
270
- const out = new Map();
271
- const note = (fileId, wPx, hPx) => {
272
- const w = wPx * scale;
273
- const h = hPx * scale;
274
- const prev = out.get(fileId);
275
- if (!prev || w * h > prev.w * prev.h)
276
- out.set(fileId, { w, h });
277
- };
278
- for (const block of blocks) {
279
- const rb = block.resourceBlock;
280
- // A cropped picture is drawn at its uncropped size.
281
- if (rb?.fileId)
282
- note(rb.fileId, rb.bodyRect.width / (rb.bodySource?.width ?? 1), rb.bodyRect.height / (rb.bodySource?.height ?? 1));
283
- for (const cell of rb?.table?.cells ?? []) {
284
- if (cell.image)
285
- note(cell.image.fileId, cell.image.rect.width, cell.image.rect.height);
286
- }
287
- const overlay = block.designOverlay;
288
- if (overlay) {
289
- for (const b of overlay.blocks)
290
- if (b.kind === 'image')
291
- note(b.fileId, b.bbox.width / (b.crop?.width ?? 1), b.bbox.height / (b.crop?.height ?? 1));
292
- }
293
- }
294
- // Image elements of the page design slots (a logo on a title page).
295
- for (const page of doc.pages) {
296
- // A cover crop (#923) draws the whole picture larger than its box.
297
- for (const slot of [page.header, page.footer, page.openerBand, page.composed?.decoration]) {
298
- if (!slot)
299
- continue;
300
- for (const b of slot.blocks)
301
- if (b.kind === 'image')
302
- note(b.fileId, b.bbox.width / (b.crop?.width ?? 1), b.bbox.height / (b.crop?.height ?? 1));
303
- }
304
- // Comic panels: the whole picture is drawn at its box, which a crop
305
- // makes larger than the panel.
306
- for (const art of comicArts(page))
307
- note(art.fileId, art.box.width, art.box.height);
308
- }
309
- return out;
310
- }
311
- /** The pictures of the page's comics (its comic page or half of a spread,
312
- * its strips): each panel's art and pop-out cut-out. */
313
- function comicArts(page) {
314
- const out = [];
315
- for (const comic of pageComics(page)) {
316
- for (const panel of comic.panels) {
317
- if (panel.art)
318
- out.push(panel.art);
319
- if (panel.pop)
320
- out.push(panel.pop);
321
- }
322
- }
323
- return out;
324
- }
325
- /**
326
- * Embed every bitmap / svg / print-master resource referenced in the
327
- * document. Returns a map of `fileId → EmbeddedResource` consumed by
328
- * {@link renderResourceBlock} and the design-overlay image blocks. A missing or
329
- * undecodable payload is simply absent from the map and the renderer draws a
330
- * placeholder.
331
- */
332
- export async function preloadResourceImages(pdfDoc, doc, bytesProvider, fontCache, fontProvider,
333
- /** Map to add to (a book renders several documents into one PDF; a
334
- * resource is embedded once for all of them). */
335
- into,
336
- /** How to rasterise an SVG outside the vector subset; the document's
337
- * own `Image` by default (a worker hands the job to its host). */
338
- rasterizeSvg = rasterizeSvgWithDom,
339
- /** A colour-managed print render: pictures are separated into CMYK
340
- * through its profile (and flattened for PDF/X-1a). */
341
- printMode,
342
- /** The device colour space a render without a print mode is forced to
343
- * (#800): its pictures are written in it, as its flat colours are. */
344
- deviceSpace) {
345
- const out = into ?? new Map();
346
- if (!bytesProvider)
347
- return out;
348
- /** A bitmap embedded as the render wants it. */
349
- const embedRaster = (data, format) => printMode
350
- ? embedPrintRaster(pdfDoc, data, format, printMode)
351
- : deviceSpace === 'grayscale' || deviceSpace === 'cmyk'
352
- ? embedDeviceRaster(pdfDoc, data, format, deviceSpace)
353
- : format === 'png' ? pdfDoc.embedPng(data) : pdfDoc.embedJpg(data);
354
- // Inline resources live in doc.blocks; floated resources only exist on
355
- // their page's float band (page.floats), so both must be walked.
356
- const blocks = [...doc.blocks];
357
- for (const page of doc.pages) {
358
- if (page.floats)
359
- blocks.push(...page.floats);
360
- }
361
- const placements = largestPlacements(doc, blocks);
362
- // Pictures painted in a colour of their own (`VDTDesignImageBlock.tint`,
363
- // #995): a bitmap among them also gets the stencil of its alpha.
364
- const tintedIds = new Set();
365
- for (const block of blocks)
366
- for (const b of block.designOverlay?.blocks ?? [])
367
- if (b.kind === 'image' && b.tint)
368
- tintedIds.add(b.fileId);
369
- // A tinted inline symbol (#1058).
370
- for (const block of blocks)
371
- for (const icon of resourceBlockIcons(block.resourceBlock))
372
- if (icon.fileId && icon.color)
373
- tintedIds.add(icon.fileId);
374
- for (const block of blocks)
375
- for (const icon of lineIcons(block))
376
- if (icon.fileId && icon.color)
377
- tintedIds.add(icon.fileId);
378
- for (const page of doc.pages) {
379
- for (const slot of [page.header, page.footer, page.openerBand, page.composed?.decoration]) {
380
- for (const b of slot?.blocks ?? [])
381
- if (b.kind === 'image' && b.tint)
382
- tintedIds.add(b.fileId);
383
- }
384
- }
385
- /** A raster embedded as `fileId`, with its stencil when the picture is tinted. */
386
- const setImage = async (fileId, image, data, format) => {
387
- const stencil = tintedIds.has(fileId) ? await alphaStencil(pdfDoc, data, format) : null;
388
- out.set(fileId, { kind: 'image', image, ...(stencil ? { stencil } : {}) });
389
- };
390
- const ds = doc.config.diagramStyle;
391
- const inkHex = ds?.singleInk
392
- ? resolveColorValue(ds.inkColor, doc.config.colorPalette, ds.inkColor).hex
393
- : null;
394
- // SVGs whose raster fallback keeps its markup as it is (#630:
395
- // `diagramStyle.inlineFonts: false`, a resource's `svg.inlineFonts: false`).
396
- const inlineFonts = ds?.inlineFonts !== false;
397
- const keepMarkup = new Set();
398
- for (const block of blocks) {
399
- const svg = block.resourceBlock?.resource?.svg;
400
- if (svg?.inlineFonts === false && svg.fileId)
401
- keepMarkup.add(svg.fileId);
402
- }
403
- // Vector print masters (`svg.pdfFileId`) by the SVG's own `fileId`: every
404
- // use of the picture names its master — the figure, a table cell, a
405
- // design image or box icon — so the master is embedded wherever the SVG
406
- // is drawn, in whichever chapter of a book draws it first. Single-ink
407
- // mode recolours SVG markup, which a master is not, so it keeps the SVG.
408
- const masters = new Map();
409
- const noteMaster = (fileId, pdfFileId) => {
410
- if (fileId && pdfFileId && !masters.has(fileId))
411
- masters.set(fileId, pdfFileId);
412
- };
413
- if (!inkHex) {
414
- for (const block of blocks) {
415
- const svg = block.resourceBlock?.resource?.svg;
416
- noteMaster(svg?.fileId, svg?.pdfFileId);
417
- for (const cell of block.resourceBlock?.table?.cells ?? [])
418
- noteMaster(cell.image?.fileId, cell.image?.pdfFileId);
419
- for (const b of block.designOverlay?.blocks ?? [])
420
- if (b.kind === 'image')
421
- noteMaster(b.fileId, b.pdfFileId);
422
- }
423
- for (const page of doc.pages) {
424
- for (const slot of [page.header, page.footer, page.openerBand, page.composed?.decoration]) {
425
- for (const b of slot?.blocks ?? [])
426
- if (b.kind === 'image')
427
- noteMaster(b.fileId, b.pdfFileId);
428
- }
429
- for (const art of comicArts(page))
430
- noteMaster(art.fileId, art.pdfFileId);
431
- }
432
- }
433
- /** Embed a print master for `fileId`; false when there is none, or it
434
- * does not decode (the SVG is embedded instead). */
435
- const embedMaster = async (fileId) => {
436
- const masterId = masters.get(fileId);
437
- const bytes = masterId ? bytesProvider(masterId) : undefined;
438
- if (!bytes || sniffBytes(bytes) !== 'pdf')
439
- return false;
440
- try {
441
- const [page] = await pdfDoc.embedPdf(bytes, [0]);
442
- if (!page)
443
- return false;
444
- out.set(fileId, { kind: 'page', page });
445
- return true;
446
- }
447
- catch {
448
- return false;
449
- }
450
- };
451
- /** Embed one payload by `fileId` (format hint from the resource when known). */
452
- const embed = async (fileId, format) => {
453
- if (out.has(fileId))
454
- return;
455
- if (await embedMaster(fileId))
456
- return;
457
- const bytes = bytesProvider(fileId);
458
- if (!bytes)
459
- return;
460
- try {
461
- const sniffed = sniffBytes(bytes);
462
- const fmt = sniffed !== 'unknown' ? sniffed : (format ?? '').toLowerCase().replace('jpg', 'jpeg');
463
- if (fmt === 'pdf') {
464
- const [page] = await pdfDoc.embedPdf(bytes, [0]);
465
- if (page)
466
- out.set(fileId, { kind: 'page', page });
467
- return;
468
- }
469
- if (fmt === 'svg') {
470
- let svgText = new TextDecoder().decode(bytes);
471
- if (inkHex)
472
- svgText = applySingleInkToSvg(svgText, inkHex);
473
- let fonts;
474
- let wanted = [];
475
- if (fontCache) {
476
- // Text runs need their fonts embedded before the sync conversion.
477
- wanted = collectSvgFontStrings(svgText);
478
- if (wanted.length > 0) {
479
- const codePoints = svgCodePoints(svgText);
480
- await fontCache.preloadFontStrings(new Map(wanted.map((fs) => [fs, codePoints])));
481
- }
482
- fonts = fontResolverFor(fontCache);
483
- }
484
- // Right-to-left or joining text in the drawing is shaped by HarfBuzz
485
- // (loaded here when the document's own text did not need it).
486
- if (fonts && needsComplexShaping(svgText))
487
- await loadComplexShaper();
488
- const drawing = svgToVectorDrawing(svgText, { fonts });
489
- if (drawing) {
490
- // Pictures inside the drawing become image XObjects.
491
- for (const shape of drawing.shapes) {
492
- if (shape.kind !== 'image')
493
- continue;
494
- try {
495
- shape.pdfImage = await embedRaster(shape.data, shape.format === 'png' ? 'png' : 'jpeg');
496
- }
497
- catch {
498
- shape.pdfImage = undefined;
499
- }
500
- }
501
- out.set(fileId, { kind: 'vector', drawing });
502
- return;
503
- }
504
- const size = placements.get(fileId) ?? { w: 360, h: 270 };
505
- const rasterSvg = wanted.length > 0 && fontProvider && inlineFonts && !keepMarkup.has(fileId)
506
- ? await inlineSvgFontsForRaster(svgText, wanted, fontProvider)
507
- : svgText;
508
- const png = await rasterizeSvg(rasterSvg, (size.w / 72) * RASTER_DPI, (size.h / 72) * RASTER_DPI);
509
- if (png)
510
- await setImage(fileId, await embedRaster(png, 'png'), png, 'png');
511
- return;
512
- }
513
- let image = null;
514
- let data = bytes;
515
- let dataFormat = 'png';
516
- if (fmt === 'jpeg') {
517
- image = await embedRaster(bytes, 'jpeg');
518
- dataFormat = 'jpeg';
519
- }
520
- else if (fmt === 'webp') {
521
- const png = await webpToPng(bytes);
522
- if (png) {
523
- image = await embedRaster(png, 'png');
524
- data = png;
525
- }
526
- }
527
- else {
528
- // png / gif-first-frame / unknown all go through embedPng.
529
- image = await embedRaster(bytes, 'png');
530
- }
531
- if (image)
532
- await setImage(fileId, image, data, dataFormat);
533
- }
534
- catch (err) {
535
- // Undecodable — leave absent; renderer falls back to a placeholder.
536
- if (typeof process !== 'undefined' && process.env?.POSTEXT_SVG_DEBUG)
537
- console.warn('embed failed:', fileId, err.message);
538
- }
539
- };
540
- for (const block of blocks) {
541
- const rb = block.resourceBlock;
542
- if (rb && rb.fileId && (rb.kind === 'bitmap' || rb.kind === 'svg' || rb.kind === 'video')) {
543
- await embed(rb.fileId, rb.format);
544
- }
545
- // Images embedded in table cells draw through the same map.
546
- for (const cell of rb?.table?.cells ?? []) {
547
- if (cell.image)
548
- await embed(cell.image.fileId, cell.image.format);
549
- }
550
- // The pictures of inline symbols in its caption, notes, labels and
551
- // cells (#1058).
552
- for (const icon of resourceBlockIcons(rb))
553
- if (icon.fileId)
554
- await embed(icon.fileId, icon.svg ? 'svg' : icon.format);
555
- // And of its own lines: an exercise's activity icons (#1226).
556
- for (const icon of lineIcons(block))
557
- if (icon.fileId)
558
- await embed(icon.fileId, icon.svg ? 'svg' : icon.format);
559
- // Callout icons and markers (`kind: 'resource'`) draw through the same map.
560
- const iconFileId = block.callout?.iconFileId;
561
- if (iconFileId)
562
- await embed(iconFileId, block.callout?.iconFormat);
563
- const markerFileId = block.callout?.markerFileId;
564
- if (markerFileId)
565
- await embed(markerFileId, block.callout?.markerFormat);
566
- // Pictures of a box's decoration (a label icon) draw through the map too.
567
- for (const b of block.designOverlay?.blocks ?? []) {
568
- if (b.kind === 'image')
569
- await embed(b.fileId, undefined);
570
- }
571
- }
572
- // Image elements of the page design slots (a logo on a title page, the
573
- // chapter motif in a running head, a part page's pictures, the pictures
574
- // of a composed page's decoration).
575
- for (const page of doc.pages) {
576
- for (const slot of [page.header, page.footer, page.openerBand, page.composed?.decoration]) {
577
- if (!slot)
578
- continue;
579
- for (const b of slot.blocks)
580
- if (b.kind === 'image')
581
- await embed(b.fileId, undefined);
582
- }
583
- // The pictures of a comic page's panels.
584
- for (const art of comicArts(page))
585
- await embed(art.fileId, art.format);
586
- }
587
- return out;
588
- }
589
- /** The inline symbols of a block's own lines that draw a picture. */
590
- function lineIcons(block) {
591
- const out = [];
592
- for (const line of block.lines ?? [])
593
- for (const seg of line.segments ?? [])
594
- if (seg.swatch?.icon?.fileId)
595
- out.push(seg.swatch.icon);
596
- return out;
597
- }
598
- /** Draw an embedded resource fitted to a box in document pixels (top-down). */
599
- export function drawEmbeddedResource(ctx, res, xPx, yPx, wPx, hPx,
600
- /** Paint the picture's silhouette in this colour (`#rrggbb`, #995): a
601
- * vector drawing is recoloured, a bitmap goes through the stencil of
602
- * its alpha. A print master (an embedded PDF page) cannot be
603
- * recoloured and is drawn as it is. */
604
- tint) {
605
- const { scale, pageHeightPt } = ctx;
606
- const box = {
607
- x: xPx * scale,
608
- y: pageHeightPt - (yPx + hPx) * scale,
609
- width: wPx * scale,
610
- height: hPx * scale,
611
- };
612
- // A picture on a mirrored page reads unmirrored in its box.
613
- counterFlipPx(ctx, xPx, wPx, () => {
614
- if (res.kind === 'image') {
615
- if (tint && res.stencil) {
616
- ctx.page.pushOperators(pushGraphicsState(), setFillingColor(colorFromHex(tint, ctx.colorSpace)));
617
- ctx.page.drawImage(res.stencil.image, box);
618
- ctx.page.pushOperators(popGraphicsState());
619
- }
620
- else
621
- ctx.page.drawImage(res.image, box);
622
- }
623
- else if (res.kind === 'page')
624
- ctx.page.drawPage(res.page, box);
625
- else
626
- drawVectorDrawing(ctx, tint ? tintedDrawing(res.drawing, tint) : res.drawing, xPx, yPx, wPx, hPx);
627
- });
628
- }
629
- function pickFont(bold, italic, fonts) {
630
- if (bold && italic)
631
- return fonts.boldItalic;
632
- if (bold)
633
- return fonts.bold;
634
- if (italic)
635
- return fonts.italic;
636
- return fonts.normal;
637
- }
638
- /** Paint one absolutely-positioned rich-text line; records ref link rects.
639
- * In a tagged render the text joins `elem` (refs get a `Link` child) and
640
- * word spaces are painted as real glyphs; without `elem` the line joins
641
- * whatever sequence is open (an artifact for repeated table headers). */
642
- /** A caption, note or cell line. A tracked line (a table header set with
643
- * `headerLetterSpacing`) was measured with the tracking in its widths, so
644
- * it is painted with the matching character spacing (`Tc`, in points at
645
- * the page scale), reset afterwards. Ruby readings, warichu rows and the
646
- * marks of the line are painted as on a body line (#429): a reading in
647
- * the `RT` of a `Ruby` whose `RB` is its base, the marks as artifacts. */
648
- function paintLine(ctx, line, fonts, fontCache, color, linkColor, linkRegistry, resolveRefId, labelColor = color, elem) {
649
- const tracking = line.letterSpacing ?? 0;
650
- // Highlight bands (`:mark[…]`, #888), under the text.
651
- if (line.highlights)
652
- paintLineHighlights(ctx, line);
653
- if (tracking !== 0)
654
- setTrackingPx(ctx, tracking);
655
- paintLineRuns(ctx, line, fonts, fontCache, color, linkColor, linkRegistry, resolveRefId, labelColor, elem, tracking);
656
- if (tracking !== 0)
657
- setTrackingPx(ctx, 0);
658
- if (line.marks)
659
- paintLineMarks(ctx, line, color);
660
- }
661
- function paintLineRuns(ctx, line, fonts, fontCache, color, linkColor, linkRegistry, resolveRefId, labelColor, elem, tracking = 0) {
662
- const baseFont = fontCache.get(fonts.normal);
663
- if (!baseFont)
664
- return;
665
- const baseSize = parseFontString(fonts.normal)?.sizePx ?? 0;
666
- if (line.segments && line.segments.length > 0) {
667
- const refRun = new RefRun();
668
- let x = line.bbox.x;
669
- const uris = new UriRuns(ctx, line, linkRegistry, elem);
670
- // Only a line of the CJK composer carries its fields (a segment's
671
- // tracking, ink offset and scale); any other is painted as every line
672
- // was before them (see `renderSegments` in blockRender.ts).
673
- const composed = line.cjkComposed === true || ctx.vertical !== undefined;
674
- // The pieces of a word the layout measured whole are painted as that
675
- // word, in a document shaped in its own language (#764).
676
- const segs = wordSegments(line, composed, (seg, text, sizeOf) => {
677
- const fontStr = seg.fontString ?? pickFont(!!seg.bold, !!seg.italic, fonts);
678
- return withSegmentLanguage(seg.lang, () => textAdvancePx(fontCache.get(fontStr) ?? baseFont, text, sizeOf(parseFontString(fontStr)?.sizePx ?? baseSize), tracking).advance);
679
- }) ?? line.segments;
680
- // A composed CJK line reads as written, not with its gaps.
681
- const actualLine = composed ? cjkLineText(segs) : undefined;
682
- let lineState;
683
- if (actualLine !== undefined) {
684
- const first = segs.find((s) => s.kind === 'text' && !s.chip && s.text !== '');
685
- const fontStr = first ? first.fontString ?? pickFont(!!first.bold, !!first.italic, fonts) : fonts.normal;
686
- lineState = {
687
- font: fontCache.get(fontStr) ?? baseFont,
688
- text: first?.text ?? '',
689
- sizePx: parseFontString(fontStr)?.sizePx ?? baseSize,
690
- xPx: line.bbox.x,
691
- baselinePx: line.baseline,
692
- };
693
- beginActualTextSpan(ctx, actualLine, lineState);
694
- }
695
- // A line with right-to-left runs is laid out in `order` and painted
696
- // in logical order, each right-to-left segment shaped as one run (see
697
- // `renderSegments` in blockRender.ts).
698
- const directed = line.order !== undefined || segs.some((s) => s.rtl);
699
- const order = directed && line.order?.length === segs.length ? line.order : undefined;
700
- const xs = order ? segmentOffsets(segs, order, line.bbox.x, (s) => s.width) : undefined;
701
- const langs = elem && directed ? segmentLanguages(segs, elem.tree.options.lang) : undefined;
702
- let langSpan;
703
- for (let i = 0; i < segs.length; i++) {
704
- const seg = segs[i];
705
- if (xs)
706
- x = xs[i];
707
- const lang = langs?.[i];
708
- if (lang && langSpan?.lang !== lang)
709
- langSpan = { lang, elem: elem.child('Span', { lang }) };
710
- else if (!lang)
711
- langSpan = undefined;
712
- const textElem = langSpan?.elem ?? elem;
713
- if (seg.kind === 'space') {
714
- // A space inside a reference label (#702) is read in its `Link`.
715
- const inLink = uris.space(seg.text) ?? refRun.space(seg, resolveRefId(seg));
716
- if (ctx.tags && seg.text) {
717
- tagContent(ctx, inLink ?? textElem);
718
- drawTextPx(ctx, seg.text, x, line.baseline, baseFont, baseSize, color);
719
- }
720
- x += seg.width;
721
- continue;
722
- }
723
- if (seg.kind !== 'text' || seg.chip)
724
- uris.other();
725
- if (seg.kind === 'math') {
726
- // An inline formula (#541): vector paths, as in the text, tagged
727
- // as a `Formula` with its TeX for alternate text.
728
- if (elem)
729
- tagContent(ctx, elem.type === 'Formula' ? elem : elem.child('Formula', { alt: seg.mathRender?.tex ?? '' }));
730
- renderMathSegment(ctx, seg, x, line.baseline, color);
731
- x += seg.width;
732
- continue;
733
- }
734
- if (seg.kind === 'swatch') {
735
- paintSwatchSegmentPdf(ctx, seg, x, line.baseline, color, fontCache, baseFont, elem);
736
- x += seg.width;
737
- continue;
738
- }
739
- if (seg.chip) {
740
- const chipColor = seg.chip.color ? colorFromHex(seg.chip.color, ctx.colorSpace) : color;
741
- paintChip(ctx, seg.chip, x, line.baseline, fontCache, baseFont, baseSize, elem, () => chipColor);
742
- x += seg.width;
743
- continue;
744
- }
745
- if (composed && seg.warichu) {
746
- // A warichu note's part: its two rows, not its text (#195), with
747
- // no character spacing.
748
- if (tracking !== 0)
749
- setTrackingPx(ctx, 0);
750
- paintWarichu(ctx, seg.warichu, x, line.baseline, color, fontCache, baseFont, textElem);
751
- if (tracking !== 0)
752
- setTrackingPx(ctx, tracking);
753
- x += seg.width;
754
- continue;
755
- }
756
- const fontStr = seg.fontString ?? pickFont(!!seg.bold, !!seg.italic, fonts);
757
- const font = fontCache.get(fontStr) ?? baseFont;
758
- const size = parseFontString(fontStr)?.sizePx ?? baseSize;
759
- const refId = resolveRefId(seg);
760
- const segColor = refId !== undefined ? linkColor : seg.captionLabel ? labelColor : color;
761
- // A `:ref` links to its resource — a ref painted as several runs
762
- // (small capitals) is one link —, a Markdown link's words to its URL.
763
- const uriElem = uris.word(refId === undefined ? seg.href : undefined, x, seg.width, seg.text);
764
- const link = refId !== undefined ? refRun.enter(seg, x, textElem, refId, seg.width) : undefined;
765
- // A ruby base is the `RB` of a `Ruby` whose `RT` holds its reading.
766
- const holder = link ?? uriElem ?? textElem;
767
- const rubyElem = composed && seg.ruby && holder ? holder.child('Ruby') : undefined;
768
- tagContent(ctx, rubyElem ? rubyElem.child('RB') : holder);
769
- const baseline = line.baseline + (seg.baselineShift ?? 0);
770
- const direction = seg.rtl ? 'rtl' : 'ltr';
771
- // A segment that names its language is shaped in it (#764), in a
772
- // document shaped in its own.
773
- withSegmentLanguage(seg.lang, () => {
774
- if (seg.runs && drawStyledWordPx(ctx, seg.text, x, baseline, font, size, segColor, wordParts(seg, font, segColor, ctx, (bold, italic) => ({ font: fontCache.get(pickFont(bold, italic, fonts)) ?? undefined, color: segColor })), { direction })) {
775
- // A word set in several styles, shaped whole.
776
- }
777
- else if (directed && (seg.rtl || needsComplexShaping(seg.text)) && paintInScript(ctx, seg.scriptContext, () => drawShapedTextPx(ctx, seg.text, x, baseline, font, size, segColor, { direction }))) {
778
- // One run in its direction, shaped by HarfBuzz; a word with no
779
- // letter in the script the layout measured it in (#725).
780
- }
781
- else if (!composed) {
782
- paintInScript(ctx, seg.scriptContext, () => drawTextPx(ctx, seg.text, x, baseline, font, size, segColor));
783
- }
784
- else {
785
- // A justified CJK line spreads its characters per segment.
786
- // A compressed CJK mark advances to its box's end (see blockRender).
787
- const markSpacing = compressedMarkSpacingPx(font, seg, size);
788
- if (markSpacing !== undefined)
789
- setTrackingPx(ctx, markSpacing);
790
- else if (seg.tracking !== undefined)
791
- setTrackingPx(ctx, (tracking + seg.tracking));
792
- const stretch = inkScaleOperators(seg.inkScale);
793
- ctx.page.pushOperators(...stretch.before);
794
- // Characters the composer measured one by one, each in its
795
- // place (see `paintComposedText` in blockRender.ts, #770).
796
- const cells = ctx.vertical || markSpacing !== undefined || seg.inkScale !== undefined ? undefined : cellPieces(font, seg.text, seg.width, size, ctx.trackingPx ?? 0);
797
- if (!cells || !drawMeasuredTextPx(ctx, cells, x + (seg.inkOffset ?? 0), line.baseline + (seg.baselineShift ?? 0), font, size, segColor, ctx.trackingPx ?? 0)) {
798
- drawTextPx(ctx, seg.text, x + (seg.inkOffset ?? 0), line.baseline + (seg.baselineShift ?? 0), font, size, segColor);
799
- }
800
- ctx.page.pushOperators(...stretch.after);
801
- if (markSpacing !== undefined || seg.tracking !== undefined)
802
- setTrackingPx(ctx, tracking);
803
- if (seg.ruby) {
804
- if (tracking !== 0)
805
- setTrackingPx(ctx, 0);
806
- paintRuby(ctx, seg.ruby, x, line.baseline, segColor, fontCache, baseFont, rubyElem);
807
- if (tracking !== 0)
808
- setTrackingPx(ctx, tracking);
809
- }
810
- if (seg.kunten) {
811
- // Kanbun marks (#430), with the character's text.
812
- if (tracking !== 0)
813
- setTrackingPx(ctx, 0);
814
- paintKunten(ctx, seg.kunten, x, line.baseline, segColor, fontCache, baseFont, holder);
815
- if (tracking !== 0)
816
- setTrackingPx(ctx, tracking);
817
- }
818
- }
819
- });
820
- const ref = refId !== undefined ? refRun.leave(seg, segs[i + 1], refId, segs[i + 1] ? resolveRefId(segs[i + 1]) : undefined) : undefined;
821
- if (ref && linkRegistry) {
822
- const { scale, pageHeightPt } = ctx;
823
- const x1 = ref.left * scale;
824
- const y2 = pageHeightPt - (line.bbox.y) * scale;
825
- const y1 = pageHeightPt - (line.bbox.y + line.bbox.height) * scale;
826
- const x2 = Math.max(ref.right, x + seg.width) * scale;
827
- const rect = [x1, y1, x2, y2];
828
- linkRegistry.addLink(ctx.page, ctx.mapRectPt ? ctx.mapRectPt(rect) : rect, ref.resourceId, link ? { elem: link, contents: ref.text } : undefined);
829
- }
830
- x += seg.width;
831
- }
832
- uris.end();
833
- if (lineState)
834
- endActualTextSpan(ctx, lineState);
835
- return;
836
- }
837
- tagContent(ctx, elem);
838
- drawTextPx(ctx, line.text, line.bbox.x, line.baseline, baseFont, baseSize, color);
839
- }
840
- /** Layout attributes of a figure: its bounding box on the page (PDF user
841
- * space, bottom-up) and block placement. */
842
- export function figureLayout(ctx, xPx, yPx, wPx, hPx) {
843
- const { scale, pageHeightPt } = ctx;
844
- const rect = [
845
- xPx * scale,
846
- pageHeightPt - (yPx + hPx) * scale,
847
- (xPx + wPx) * scale,
848
- pageHeightPt - yPx * scale,
849
- ];
850
- const bbox = ctx.page.doc.context.obj(ctx.mapRectPt ? ctx.mapRectPt(rect) : rect);
851
- return [{ owner: 'Layout', entries: { BBox: bbox, Placement: 'Block' } }];
852
- }
853
- /** Plain text of a resource caption, for figure alt text fallbacks. */
854
- function captionText(rb) {
855
- return rb.captionLines.map((l) => l.text).join(' ').replace(/\s+/g, ' ').trim();
856
- }
857
- /** Alt text of a figure: the resource's `altText`, else its caption, else
858
- * its label (`Figure 1.2`) — PDF/UA-1 §7.3 requires one on every figure.
859
- * A video's text says what the picture is, in its type's name (`Video: …`):
860
- * the reader hears a poster that links to a video, not a still. */
861
- function figureAlt(rb) {
862
- const label = `${rb.captionPrefix} ${rb.number}`.trim();
863
- const text = rb.resource.altText?.trim() || rb.score?.alt || captionText(rb);
864
- // Labels drawn as text are read as text, after the picture (#860).
865
- if (rb.kind !== 'video')
866
- return altWithLabels(text || label, undrawnLabels(rb.labels));
867
- const name = rb.captionPrefix.trim() || 'Video';
868
- // A Chinese or Japanese name takes the full-width colon (视频:…).
869
- const colon = /[\u3040-\u30ff\u3400-\u9fff]$/.test(name) ? ':' : ': ';
870
- return text ? `${name}${colon}${text}` : label || name;
871
- }
872
- /** Rows whose every cell is a header cell: the column-header rows, which
873
- * a continuation slice repeats and an accessible render then flags as
874
- * artifacts (the reader already met them on the first slice). */
875
- function headerRows(cells) {
876
- const rows = new Map();
877
- for (const cell of cells)
878
- rows.set(cell.row, (rows.get(cell.row) ?? true) && cell.isHeader);
879
- const out = new Set();
880
- for (const [row, allHeader] of rows)
881
- if (allHeader)
882
- out.add(row);
883
- return out;
884
- }
885
- /** Build the `TR` › `TH` / `TD` elements of a table slice: one element per
886
- * cell in row / column order, with span and scope attributes. Cells of
887
- * repeated header rows on a continuation slice get no element. */
888
- function tableCellElems(table, cells, continued) {
889
- const out = new Map();
890
- const heads = headerRows(cells);
891
- const ordered = [...cells].sort((a, b) => a.row - b.row || a.col - b.col);
892
- let row;
893
- let rowIndex = -1;
894
- for (const cell of ordered) {
895
- if (continued && heads.has(cell.row))
896
- continue;
897
- if (cell.row !== rowIndex) {
898
- rowIndex = cell.row;
899
- row = table.child('TR');
900
- }
901
- const entries = {};
902
- if (cell.colSpan > 1)
903
- entries.ColSpan = cell.colSpan;
904
- if (cell.rowSpan > 1)
905
- entries.RowSpan = cell.rowSpan;
906
- if (cell.isHeader)
907
- entries.Scope = heads.has(cell.row) ? 'Column' : 'Row';
908
- const attrs = Object.keys(entries).length > 0
909
- ? { attributes: [{ owner: 'Table', entries }] }
910
- : {};
911
- out.set(cell, row.child(cell.isHeader ? 'TH' : 'TD', attrs));
912
- }
913
- return out;
914
- }
915
- function renderTable(ctx, rb, bx, by, fontCache, images, linkColor, linkRegistry, tableElem) {
916
- const t = rb.table;
917
- if (!t)
918
- return;
919
- // Cell grid, fills and rules are layout; the reader gets the cell text.
920
- tagArtifact(ctx, { type: 'Layout' });
921
- const cellElems = tableElem ? tableCellElems(tableElem, t.cells, !!rb.slice?.continued) : undefined;
922
- const borderColor = colorFromHex(t.borderColor, ctx.colorSpace);
923
- const bodyColor = colorFromHex(t.color, ctx.colorSpace);
924
- const headerColor = colorFromHex(t.headerColor, ctx.colorSpace);
925
- const bodyFonts = {
926
- normal: t.fontString,
927
- bold: t.boldFontString,
928
- italic: t.italicFontString,
929
- boldItalic: t.boldItalicFontString,
930
- };
931
- const headerFonts = {
932
- normal: t.headerFontString,
933
- bold: t.headerBoldFontString,
934
- italic: t.headerItalicFontString,
935
- boldItalic: t.headerBoldItalicFontString,
936
- };
937
- // A rounded frame clips the fills to the frame line and the inner rules
938
- // to its outer contour, then is stroked round on top.
939
- const rounded = t.frameRadii !== undefined;
940
- const outline = (outset) => tableFrameOutline(t, bx, by, rb.bodyRect.width, outset);
941
- const clipTo = (outset) => {
942
- pushClipOutline(ctx, outline(outset));
943
- tagArtifact(ctx, { type: 'Layout' });
944
- };
945
- const unclip = () => {
946
- popClip(ctx);
947
- tagArtifact(ctx, { type: 'Layout' });
948
- };
949
- // Cell backgrounds (the cell's own fill, else the header tint / the body
950
- // or zebra fill). Each opaque fill runs across the edges it shares with
951
- // the cells painted after it, in the same fill operation, so a viewer
952
- // shows no seam between two cells (see `tableCellFillRects`).
953
- if (rounded)
954
- clipTo(0);
955
- for (const { fill, rects } of tableCellFillRects(t)) {
956
- fillRectsPx(ctx, rects, colorFromHex(fill, ctx.colorSpace));
957
- }
958
- if (rounded)
959
- unclip();
960
- // Borders: the full cell grid, horizontal rules only, or the outer frame.
961
- // `drawLinePx` strokes exactly `borderWidthPx` (scaled to pt), so fractional
962
- // hairlines such as 0.5pt survive.
963
- if (t.strokes) {
964
- // Booktabs (#625): the layout's strokes, each its own (fractional) width.
965
- for (const s of t.strokes)
966
- drawLinePx(ctx, bx + s.x1, by + s.y1, bx + s.x2, by + s.y2, borderColor, s.widthPx);
967
- }
968
- else if (t.borderWidthPx > 0) {
969
- const rules = t.rules ?? 'grid';
970
- const bw = t.borderWidthPx;
971
- if (rules === 'outer') {
972
- if (!rounded) {
973
- const tableHeight = t.rowEdges[t.rowEdges.length - 1] ?? rb.bodyRect.height;
974
- const x = bx, y = by, width = rb.bodyRect.width, height = tableHeight;
975
- drawLinePx(ctx, x, y, x + width, y, borderColor, bw);
976
- drawLinePx(ctx, x, y + height, x + width, y + height, borderColor, bw);
977
- drawLinePx(ctx, x, y, x, y + height, borderColor, bw);
978
- drawLinePx(ctx, x + width, y, x + width, y + height, borderColor, bw);
979
- }
980
- }
981
- else {
982
- if (rounded)
983
- clipTo(bw / 2);
984
- for (const cell of t.cells) {
985
- const { x, y, width, height } = cell.rect;
986
- drawLinePx(ctx, x, y, x + width, y, borderColor, bw);
987
- drawLinePx(ctx, x, y + height, x + width, y + height, borderColor, bw);
988
- if (rules === 'grid') {
989
- drawLinePx(ctx, x, y, x, y + height, borderColor, bw);
990
- drawLinePx(ctx, x + width, y, x + width, y + height, borderColor, bw);
991
- }
992
- }
993
- if (rounded)
994
- unclip();
995
- }
996
- if (rounded && (rules === 'grid' || rules === 'outer'))
997
- strokeOutlinePx(ctx, outline(0), borderColor, bw);
998
- }
999
- // Cell images (bitmap / SVG resources embedded in cells), then text.
1000
- for (const cell of t.cells) {
1001
- const img = cell.image;
1002
- if (!img)
1003
- continue;
1004
- const { x, y, width, height } = img.rect;
1005
- const cellElem = cellElems?.get(cell);
1006
- if (cellElems) {
1007
- if (cellElem) {
1008
- tagContent(ctx, cellElem.child('Figure', {
1009
- alt: img.altText?.trim() || img.resourceId,
1010
- attributes: figureLayout(ctx, x, y, width, height),
1011
- }));
1012
- }
1013
- else {
1014
- tagArtifact(ctx, { type: 'Layout' });
1015
- }
1016
- }
1017
- const embedded = images.get(img.fileId);
1018
- if (embedded)
1019
- drawEmbeddedResource(ctx, embedded, x, y, width, height);
1020
- else {
1021
- ctx.onMissingImage?.(img.fileId, img.resourceId);
1022
- fillRectPx(ctx, x, y, width, height, colorFromHex('#eeeeee', ctx.colorSpace));
1023
- }
1024
- }
1025
- // Cell content.
1026
- for (const cell of t.cells) {
1027
- const fonts = cell.isHeader ? headerFonts : bodyFonts;
1028
- const color = cell.isHeader ? headerColor : bodyColor;
1029
- const cellElem = cellElems?.get(cell);
1030
- if (cellElems && !cellElem)
1031
- tagArtifact(ctx, { type: 'Layout' });
1032
- for (const line of cell.lines) {
1033
- paintLine(ctx, line, fonts, fontCache, color, linkColor, linkRegistry, refTarget, color, cellElem);
1034
- }
1035
- }
1036
- }
1037
- function drawPlaceholder(ctx, rb, x, y) {
1038
- // A video with no poster: a dark frame its overlays read on (#454).
1039
- const fill = colorFromHex(rb.kind === 'video' ? '#1f1f1f' : '#eeeeee', ctx.colorSpace);
1040
- fillRectPx(ctx, x, y, rb.bodyRect.width, rb.bodyRect.height, fill);
1041
- }
1042
- /** The play mark and the QR code of a video's poster (#454) as vectors,
1043
- * over the body at (`bx`, `by`) px. On a mirrored page they are turned
1044
- * back about the body, so they sit where they are printed in the other
1045
- * outputs and the code reads. */
1046
- function drawVideoOverlays(ctx, video, bx, by, bw) {
1047
- if (!video.playMark && !video.qr)
1048
- return;
1049
- const { scale, pageHeightPt } = ctx;
1050
- // `drawSvgPath` reads its path top-down from this origin, in points.
1051
- const origin = { x: 0, y: pageHeightPt };
1052
- const pt = (v) => String(Math.round(v * scale * 1000) / 1000);
1053
- const alpha = (a) => (a < 1 ? { opacity: a, borderOpacity: a } : {});
1054
- counterFlipPx(ctx, bx, bw, () => {
1055
- const mark = video.playMark;
1056
- if (mark) {
1057
- const { x, y, width: w, height: h } = mark.rect;
1058
- const ox = bx + x;
1059
- const oy = by + y;
1060
- const tri = playMarkTriangle(mark)
1061
- .map(([px, py], i) => `${i === 0 ? 'M' : 'L'} ${pt(ox + px)} ${pt(oy + py)}`)
1062
- .join(' ') + ' Z';
1063
- const color = colorFromHex(mark.color, ctx.colorSpace);
1064
- const background = colorFromHex(mark.background, ctx.colorSpace);
1065
- if (mark.shape === 'triangle') {
1066
- ctx.page.drawSvgPath(tri, {
1067
- ...origin, color, borderColor: background, borderWidth: h * 0.08 * scale,
1068
- ...(mark.backgroundOpacity < 1 ? { borderOpacity: mark.backgroundOpacity } : {}),
1069
- });
1070
- }
1071
- else {
1072
- if (mark.shape === 'circle') {
1073
- ctx.page.drawEllipse({
1074
- x: (ox + w / 2) * scale, y: pageHeightPt - (oy + h / 2) * scale,
1075
- xScale: (w / 2) * scale, yScale: (h / 2) * scale,
1076
- color: background, ...alpha(mark.backgroundOpacity),
1077
- });
1078
- }
1079
- else {
1080
- ctx.page.drawSvgPath(roundedRectSvgPath(ctx, ox, oy, w, h, h * 0.24), { ...origin, color: background, ...alpha(mark.backgroundOpacity) });
1081
- }
1082
- ctx.page.drawSvgPath(tri, { ...origin, color });
1083
- }
1084
- }
1085
- const qr = video.qr;
1086
- if (qr) {
1087
- const { x, y, width: w, height: h } = qr.rect;
1088
- const ox = bx + x;
1089
- const oy = by + y;
1090
- const background = colorFromHex(qr.background, ctx.colorSpace);
1091
- if (qr.radius > 0)
1092
- ctx.page.drawSvgPath(roundedRectSvgPath(ctx, ox, oy, w, h, qr.radius), { ...origin, color: background });
1093
- else
1094
- fillRectPx(ctx, ox, oy, w, h, background);
1095
- // One path for every dark module: no seams between them.
1096
- const d = qrModuleRuns(qr)
1097
- .map((r) => `M ${pt(ox + r.x)} ${pt(oy + r.y)} h ${pt(r.w)} v ${pt(r.h)} h ${pt(-r.w)} Z`)
1098
- .join(' ');
1099
- if (d)
1100
- ctx.page.drawSvgPath(d, { ...origin, color: colorFromHex(qr.color, ctx.colorSpace) });
1101
- }
1102
- });
1103
- }
1104
- /**
1105
- * The labels of a `:::figure` drawn on its picture (#860), its body's
1106
- * top-left corner at (`bx`, `by`): each one through its matrix, its plate
1107
- * and halo as layout artifacts, then its lines. In a tagged render the
1108
- * labels are read after the picture, in the order written: a `Div` beside
1109
- * the figure holding one `P` per label (`figureLabelsElem`).
1110
- */
1111
- function paintFigureLabels(ctx, block, rb, bx, by, fontCache, linkColor, linkRegistry, structure) {
1112
- const drawn = (rb.labels ?? []).filter((l) => l.layout);
1113
- if (drawn.length === 0)
1114
- return;
1115
- // Their leaders first (#1057), under every label: vector lines, a layout
1116
- // artifact, in the frame the labels' geometry is in.
1117
- for (const path of figureLabelLeaderPaths(rb, bx, by)) {
1118
- tagArtifact(ctx, { type: 'Layout' });
1119
- renderPathBlock(ctx, path);
1120
- }
1121
- const group = structure ? structure.figureLabelsElem(block) : undefined;
1122
- for (const label of drawn) {
1123
- let layout = label.layout;
1124
- // A vertical label on a mirrored page (#955) is painted from its
1125
- // unmirrored layout, in the frame reflected back about the body: the
1126
- // page's mirror then puts it where its anchor says, its cells running
1127
- // down the column and standing upright.
1128
- const unmirror = layout.mirrored === true && ctx.mirror === true && !rb.rotation;
1129
- if (unmirror) {
1130
- layout = unmirrorLabelLayout(layout, rb.bodyRect.width);
1131
- pushFrame(ctx, sheetMatrixToPdf([-1, 0, 0, 1, 2 * bx + rb.bodyRect.width, 0], ctx.scale, ctx.pageHeightPt));
1132
- ctx.mirror = false;
1133
- }
1134
- const m = figureLabelMatrix(layout, bx, by);
1135
- pushFrame(ctx, sheetMatrixToPdf(m, ctx.scale, ctx.pageHeightPt));
1136
- // A vertical label (#902): the matrix turned its frame a quarter turn,
1137
- // and the vertical painter stands each character upright in its cell.
1138
- const outerVertical = ctx.vertical;
1139
- if (layout.vertical) {
1140
- ctx.vertical = { region: layout.vertical.region, uprightDigits: layout.vertical.uprightDigits, axes: layout.vertical.centralBaselines };
1141
- }
1142
- else
1143
- delete ctx.vertical;
1144
- try {
1145
- const fonts = { normal: layout.fontString, bold: layout.boldFontString, italic: layout.italicFontString, boldItalic: layout.boldItalicFontString };
1146
- const plate = layout.background;
1147
- if (plate) {
1148
- tagArtifact(ctx, { type: 'Layout' });
1149
- const r = plate.rect;
1150
- // A plate with an outline or round corners (#1058), as a design box.
1151
- if (plate.border || plate.radiusPx)
1152
- drawRoundedBox(ctx, r.x, r.y, r.width, r.height, labelPlateBox(plate));
1153
- else if (plate.color)
1154
- fillRectPx(ctx, r.x, r.y, r.width, r.height, colorFromHex(plate.color, ctx.colorSpace));
1155
- }
1156
- if (layout.halo && layout.halo.widthPx > 0) {
1157
- // The glyphs stroked hollow under the text: painted once more, an
1158
- // artifact, so the words are read once.
1159
- const halo = colorFromHex(layout.halo.color, ctx.colorSpace);
1160
- tagArtifact(ctx, { type: 'Layout' });
1161
- ctx.textOutline = { color: halo, widthPx: 2 * layout.halo.widthPx, hollow: true };
1162
- try {
1163
- for (const line of layout.lines)
1164
- paintLine(ctx, line.highlights ? { ...line, highlights: undefined } : line, fonts, fontCache, halo, halo, undefined, () => undefined, halo);
1165
- }
1166
- finally {
1167
- delete ctx.textOutline;
1168
- }
1169
- }
1170
- // A legend (#1058) is read as a list, one item per row.
1171
- const list = layout.legend ? group?.child('L', { attributes: [{ owner: 'List', entries: { ListNumbering: 'None' } }] }) : undefined;
1172
- const elem = list ? undefined : group?.child('P');
1173
- const color = colorFromHex(layout.color, ctx.colorSpace);
1174
- if (!elem && !list && structure)
1175
- tagArtifact(ctx, { type: 'Layout' });
1176
- for (const line of layout.lines)
1177
- paintLine(ctx, line, fonts, fontCache, color, linkColor, linkRegistry, refTarget, color, list ? list.child('LI').child('LBody') : elem);
1178
- }
1179
- finally {
1180
- popFrame(ctx);
1181
- if (unmirror) {
1182
- popFrame(ctx);
1183
- ctx.mirror = true;
1184
- }
1185
- if (outerVertical)
1186
- ctx.vertical = outerVertical;
1187
- else
1188
- delete ctx.vertical;
1189
- }
1190
- }
1191
- }
1192
- export function renderResourceBlock(ctx, block, fontCache, images, linkRegistry, structure) {
1193
- const rb = block.resourceBlock;
1194
- if (!rb)
1195
- return;
1196
- const { scale, pageHeightPt } = ctx;
1197
- // A rotated block: its geometry is in the upright frame. A quarter-turn
1198
- // matrix lands that frame on the page — set up so the `*Px` helpers, which
1199
- // flip y against the page height, keep working unchanged inside it — and
1200
- // the rects that live outside the content stream (link annotations,
1201
- // structure bounding boxes) go through the same matrix.
1202
- const rot = rb.rotation;
1203
- let matrix;
1204
- // A turned block's text is horizontal in its own frame: an upright
1205
- // figure on a vertical page sets its caption and cells across.
1206
- const outerVertical = rot ? ctx.vertical : undefined;
1207
- if (rot) {
1208
- matrix = quarterTurnMatrix(rot, scale, pageHeightPt);
1209
- // Inside a vertical page's frame the block's rects go through both.
1210
- pushFrame(ctx, matrix);
1211
- delete ctx.vertical;
1212
- }
1213
- const bx = (rot ? 0 : block.bbox.x) + rb.bodyRect.x;
1214
- const by = (rot ? 0 : block.bbox.y) + rb.bodyRect.y;
1215
- const bw = rb.bodyRect.width;
1216
- const bh = rb.bodyRect.height;
1217
- const linkColor = colorFromHex(rb.linkColor, ctx.colorSpace);
1218
- const continued = !!rb.slice?.continued;
1219
- // Structure: a `Figure` (alt text required) or a `Table` (its alt text as
1220
- // the summary), shared by the slices of a split table.
1221
- let owner;
1222
- if (structure) {
1223
- if (rb.kind === 'table') {
1224
- const alt = rb.resource.altText?.trim();
1225
- owner = structure.resourceElem(block, 'Table', alt
1226
- ? { attributes: [{ owner: 'Table', entries: { Summary: PDFHexString.fromText(alt) } }] }
1227
- : {});
1228
- }
1229
- else {
1230
- owner = structure.resourceElem(block, 'Figure', {
1231
- alt: figureAlt(rb),
1232
- attributes: figureLayout(ctx, bx, by, bw, bh),
1233
- });
1234
- }
1235
- }
1236
- if (rb.kind === 'bitmap' || rb.kind === 'svg' || rb.kind === 'video') {
1237
- const embedded = rb.fileId ? images.get(rb.fileId) : undefined;
1238
- const src = rb.bodySource;
1239
- if (embedded && src) {
1240
- // A picture cropped within its safe area (#442): the whole picture at
1241
- // its uncropped box, clipped to the body (the figure's content opened
1242
- // inside the clip, which closes marked content); on a mirrored page
1243
- // the box is reflected about the body, as the picture is turned back
1244
- // in it.
1245
- let full = uncroppedPictureBox(bx, by, bw, bh, src);
1246
- if (ctx.mirror)
1247
- full = { ...full, x: 2 * bx + bw - full.x - full.width };
1248
- pushClipRect(ctx, bx, by, bw, bh);
1249
- tagContent(ctx, owner);
1250
- drawEmbeddedResource(ctx, embedded, full.x, full.y, full.width, full.height);
1251
- popClip(ctx);
1252
- tagArtifact(ctx, { type: 'Layout' });
1253
- }
1254
- else if (embedded) {
1255
- tagContent(ctx, owner);
1256
- drawEmbeddedResource(ctx, embedded, bx, by, bw, bh);
1257
- }
1258
- else {
1259
- tagContent(ctx, owner);
1260
- if (rb.fileId)
1261
- ctx.onMissingImage?.(rb.fileId, rb.resource.id);
1262
- drawPlaceholder(ctx, rb, bx, by);
1263
- }
1264
- const video = rb.video;
1265
- if (video) {
1266
- tagContent(ctx, owner);
1267
- drawVideoOverlays(ctx, video, bx, by, bw);
1268
- // The poster opens the video (#454).
1269
- const uri = video.linkPoster && video.link ? pdfUri(video.link) : undefined;
1270
- if (uri && linkRegistry) {
1271
- const rect = [bx * scale, pageHeightPt - (by + bh) * scale, (bx + bw) * scale, pageHeightPt - by * scale];
1272
- const box = ctx.mapRectPt ? ctx.mapRectPt(rect) : rect;
1273
- const elem = owner?.child('Link');
1274
- linkRegistry.addUriLink(ctx.page, box, uri, elem ? { elem, contents: `${figureAlt(rb)} (${video.link})` } : undefined);
1275
- }
1276
- }
1277
- // A figure's labels, over the picture (#860).
1278
- if (rb.labels)
1279
- paintFigureLabels(ctx, block, rb, bx, by, fontCache, linkColor, linkRegistry, structure);
1280
- }
1281
- else if (rb.kind === 'table') {
1282
- renderTable(ctx, rb, bx, by, fontCache, images, linkColor, linkRegistry, owner);
1283
- }
1284
- else if (rb.kind === 'score') {
1285
- // A music example (#1172): its systems down the body, vector.
1286
- tagContent(ctx, owner);
1287
- paintScoreBody(ctx, rb, bx, by, bw);
1288
- }
1289
- // Named destination for inline refs: top-left of the placed block (the
1290
- // first slice of a split table; continuations are not targets).
1291
- if (linkRegistry && rb.resource.id && !rb.slice?.continued) {
1292
- // On the sheet: the block's box is in the page's frame, which a vertical
1293
- // page turns (not the block's own turned frame).
1294
- const pageMap = rot ? outerRectMap(ctx) : ctx.mapRectPt;
1295
- const box = [
1296
- block.bbox.x * scale, pageHeightPt - (block.bbox.y + block.bbox.height) * scale,
1297
- (block.bbox.x + block.bbox.width) * scale, pageHeightPt - block.bbox.y * scale,
1298
- ];
1299
- const [left, , , top] = pageMap ? pageMap(box) : box;
1300
- linkRegistry.addDestination(rb.resource.id, ctx.page, left, top);
1301
- }
1302
- // Caption bar (behind the caption lines).
1303
- if (rb.captionBar) {
1304
- tagArtifact(ctx, { type: 'Layout' });
1305
- const { rect, background } = rb.captionBar;
1306
- fillRectPx(ctx, rect.x, rect.y, rect.width, rect.height, colorFromHex(background, ctx.colorSpace));
1307
- }
1308
- // Caption — the first slice's is the `Caption` of the figure / table; the
1309
- // repeated (continued) caption of a later slice is an artifact.
1310
- const captionColor = colorFromHex(rb.captionColor, ctx.colorSpace);
1311
- const captionLabelColor = colorFromHex(rb.captionLabelColor, ctx.colorSpace);
1312
- const captionFonts = {
1313
- normal: rb.captionFontString,
1314
- bold: rb.captionBoldFontString,
1315
- italic: rb.captionItalicFontString,
1316
- boldItalic: rb.captionBoldItalicFontString,
1317
- };
1318
- if (structure && rb.captionLines.length > 0 && continued)
1319
- tagArtifact(ctx, { type: 'Layout' });
1320
- const captionElem = structure && owner && rb.captionLines.length > 0 && !continued
1321
- ? structure.captionElem(owner, rb.kind === 'table' && !!rb.slice?.continues)
1322
- : undefined;
1323
- for (const line of rb.captionLines) {
1324
- paintLine(ctx, line, captionFonts, fontCache, captionColor, linkColor, linkRegistry, refTarget, captionLabelColor, captionElem);
1325
- }
1326
- // Note.
1327
- const noteColor = colorFromHex(rb.noteColor, ctx.colorSpace);
1328
- const noteFonts = {
1329
- normal: rb.noteFontString,
1330
- bold: rb.noteBoldFontString,
1331
- italic: rb.noteItalicFontString,
1332
- boldItalic: rb.noteBoldItalicFontString,
1333
- };
1334
- const noteElem = structure && rb.noteLines.length > 0 ? structure.noteElem(block) : undefined;
1335
- for (const line of rb.noteLines) {
1336
- paintLine(ctx, line, noteFonts, fontCache, noteColor, linkColor, linkRegistry, refTarget, noteColor, noteElem);
1337
- }
1338
- // The "continued" marker of a table slice that goes on is a layout cue.
1339
- if (rb.continuesLines && rb.continuesLines.length > 0) {
1340
- tagArtifact(ctx, { type: 'Layout' });
1341
- for (const line of rb.continuesLines) {
1342
- paintLine(ctx, line, noteFonts, fontCache, noteColor, linkColor, linkRegistry, (seg) => seg.refResourceId);
1343
- }
1344
- }
1345
- if (matrix) {
1346
- popFrame(ctx);
1347
- if (outerVertical)
1348
- ctx.vertical = outerVertical;
1349
- }
1350
- }
1351
- //# sourceMappingURL=renderResourceBlock.js.map