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,866 +0,0 @@
1
- import { concatTransformationMatrix, popGraphicsState, pushGraphicsState } from 'pdf-lib';
2
- import { isJapaneseLanguage, joinsLetters, leaderRuleGeometry, lineTextAlign, markerRuns, markerSetText, segmentOrientation } from 'postext';
3
- import { parseFontString } from '../fontString.js';
4
- import { alphaOf, alphaStateOp, beginActualTextSpan, cellPieces, counterFlipPx, cjkLineText, readText, compressedMarkSpacingPx, drawLinePx, drawMeasuredTextPx, drawTextPx, colorFromHex, endActualTextSpan, fillRectPx, setTrackingPx, textAdvancePx, paintInScript } from './primitives.js';
5
- import { paintChip } from './chip.js';
6
- import { renderScoreSegment } from './scoreRender.js';
7
- import { drawTaskBoxPx } from './taskBox.js';
8
- import { drawRightToLeftRun } from './rtlRun.js';
9
- import { pickSegmentColor, pickSegmentFont } from './fontHelpers.js';
10
- import { renderHeaderFooterSlot } from './headerFooter.js';
11
- import { renderResourceBlock, } from './renderResourceBlock.js';
12
- import { RefRun, refTarget, UriRuns } from './links.js';
13
- import { tagArtifact, tagContent } from './tagging.js';
14
- import { paintKunten, paintLineHighlights, paintLineMarks, paintRuby, paintSideMarker, paintWarichu } from './annotations.js';
15
- import { inkScaleOperators } from './inkScale.js';
16
- import { paintSwatchSegmentPdf } from './inlineIcon.js';
17
- import { drawShapedTextPx, drawStyledWordPx } from './shapedText.js';
18
- import { segmentLanguages, segmentOffsets, wordParts } from './directedLine.js';
19
- import { needsComplexShaping } from '../complexShaping.js';
20
- import { shapesAsCanvas, shapesSegmentLanguages, withinWideText, withSegmentLanguage } from '../shapingLanguage.js';
21
- import { wordSegments } from './wordPieces.js';
22
- /** The link destination of a footnote of the document being drawn
23
- * (`LinkRegistry.documentIndex`: note ids repeat from chapter to chapter).
24
- * A key no resource id takes: it opens with a NUL. */
25
- function footnoteDestination(linkRegistry, id) {
26
- return `\u0000fn${linkRegistry?.documentIndex ?? 0}:${id}`;
27
- }
28
- function renderMathRender(ctx, render, topLeftXPx, topLeftYPx, fallbackColor) {
29
- if (!render.paths.length || render.viewBox.width <= 0 || render.viewBox.height <= 0)
30
- return;
31
- const { scale: pxToPt, pageHeightPt } = ctx;
32
- const pxPerVb = render.widthPx / render.viewBox.width;
33
- const S = pxPerVb * pxToPt;
34
- const x = topLeftXPx * pxToPt - render.viewBox.minX * S;
35
- const y = pageHeightPt - topLeftYPx * pxToPt + render.viewBox.minY * S;
36
- // A formula on a mirrored page reads unmirrored in its box.
37
- counterFlipPx(ctx, topLeftXPx, render.widthPx, () => paintMathPaths(ctx, render, x, y, S, fallbackColor));
38
- }
39
- function paintMathPaths(ctx, render, x, y, S, fallbackColor) {
40
- for (const path of render.paths) {
41
- // MathJax fills are `currentColor` or a hex; an unpainted path (`none`,
42
- // as a stroke-only rule leaves after flattening) draws nothing, and any
43
- // other keyword falls back to the text colour.
44
- if (path.fill === 'none')
45
- continue;
46
- const color = path.fill.startsWith('#') ? colorFromHex(path.fill, ctx.colorSpace) : fallbackColor;
47
- // A translucent text colour: the constant alpha wraps the path (pdf-lib
48
- // would add an ExtGState per path otherwise).
49
- const gs = alphaStateOp(ctx, alphaOf(color));
50
- if (gs)
51
- ctx.page.pushOperators(pushGraphicsState(), gs);
52
- ctx.page.drawSvgPath(path.d, { x, y, scale: S, color });
53
- if (gs)
54
- ctx.page.pushOperators(popGraphicsState());
55
- }
56
- }
57
- /** Paint an inline formula segment on its line's baseline (body lines,
58
- * and caption, note and cell lines, #541). */
59
- export function renderMathSegment(ctx, seg, xPx, baselinePx, fallbackColor) {
60
- if (!seg.mathRender)
61
- return;
62
- renderMathRender(ctx, seg.mathRender, xPx, baselinePx - seg.mathRender.ascentPx, fallbackColor);
63
- }
64
- /**
65
- * The text of a segment of a composed line (see {@link renderSegments}):
66
- * a compressed CJK mark painted before its box (`inkOffset`) with the
67
- * character spacing that advances it to its box's end, a segment's own
68
- * tracking, a dash of a 破折号 stretched over its em (`inkScale`), the
69
- * orientation forced down a vertical line, and a ruby base's reading.
70
- */
71
- function paintComposedText(ctx, seg, x, baseline, font, size, color, colorHex, actualText, tracking, fontCache, blockFont, rubyElem,
72
- /** The character's text element, which its kanbun marks join. */
73
- textElem) {
74
- // A compressed CJK mark is painted before its box (`inkOffset`) and
75
- // advances to its box's end.
76
- // (Down a vertical line every cell is one em: no mark shown narrower.)
77
- const markSpacing = ctx.vertical ? undefined : compressedMarkSpacingPx(font, seg, size);
78
- if (markSpacing !== undefined)
79
- setTrackingPx(ctx, markSpacing);
80
- else if (seg.tracking !== undefined)
81
- setTrackingPx(ctx, tracking + seg.tracking);
82
- // A dash of a 破折号 is stretched over its em (`inkScale`); down a
83
- // vertical line it is shown turned with the frame (sideways), so the
84
- // stretch runs down the column.
85
- const stretch = inkScaleOperators(seg.inkScale);
86
- const orient = ctx.vertical && seg.inkScale !== undefined ? 'sideways' : segmentOrientation(seg);
87
- ctx.page.pushOperators(...stretch.before);
88
- // Characters the composer measured one by one are painted one by one,
89
- // each in its place (#770): a face may kern them in one string.
90
- const cells = ctx.vertical || markSpacing !== undefined || seg.inkScale !== undefined ? undefined : cellPieces(font, seg.text, seg.width, size, ctx.trackingPx ?? 0);
91
- if (!cells || !drawMeasuredTextPx(ctx, cells, x + (seg.inkOffset ?? 0), baseline + (seg.baselineShift ?? 0), font, size, color, ctx.trackingPx ?? 0, actualText)) {
92
- drawTextPx(ctx, seg.text, x + (seg.inkOffset ?? 0), baseline + (seg.baselineShift ?? 0), font, size, color, undefined, actualText, orient);
93
- }
94
- ctx.page.pushOperators(...stretch.after);
95
- if (markSpacing !== undefined || seg.tracking !== undefined)
96
- setTrackingPx(ctx, tracking);
97
- if (seg.ruby) {
98
- if (tracking !== 0)
99
- setTrackingPx(ctx, 0);
100
- paintRuby(ctx, seg.ruby, x, baseline, colorHex, fontCache, blockFont, rubyElem);
101
- if (tracking !== 0)
102
- setTrackingPx(ctx, tracking);
103
- }
104
- if (seg.kunten) {
105
- // Kanbun marks (#430).
106
- if (tracking !== 0)
107
- setTrackingPx(ctx, 0);
108
- paintKunten(ctx, seg.kunten, x, baseline, colorHex, fontCache, blockFont, textElem);
109
- if (tracking !== 0)
110
- setTrackingPx(ctx, tracking);
111
- }
112
- }
113
- /**
114
- * Paint a line's segments left to right starting at `startX`. When
115
- * `justifiedSpaceWidth` is set, spaces advance by it instead of their
116
- * measured width. `:ref` segments record a link annotation rectangle so the
117
- * reference is clickable in the final PDF.
118
- *
119
- * In a tagged render (`elem` set) the text joins `elem`, each inline formula
120
- * gets its own `Formula` element (alt text = its TeX) and each ref a `Link`
121
- * element; word spaces are painted as real space glyphs so text extraction
122
- * never has to infer them from the gaps of a justified line. A ref painted
123
- * as several runs (small capitals; the later runs flagged `refContinues`)
124
- * is still one `Link` element with one annotation over all its runs.
125
- *
126
- * A line of the CJK composer and any line down a vertical page (`composed`)
127
- * read the composer's fields — a segment's `tracking`, `inkOffset`,
128
- * `inkScale`, `autospace`, `ruby` and `warichu` — and are read as one
129
- * `/ActualText`. Any other line was set word by word and carries none of
130
- * them: its segments are painted as every line was before the CJK
131
- * features, with no further look at each one.
132
- *
133
- * A line that carries directions ({@link isDirected}: a right-to-left run
134
- * on it) is laid out in `line.order`, left to right on the sheet (flow
135
- * order on a mirrored page), each right-to-left segment shaped as one run
136
- * by HarfBuzz (`shapedText.ts`), its glyphs shown in visual order, as every
137
- * right-to-left PDF shows them. The segments are then painted, and tagged,
138
- * in logical order, each at the place `order` gave it: the content stream,
139
- * the marked-content sequences and the structure tree read the line as it
140
- * was written, and readers that order text by position (Poppler) place it
141
- * by its glyphs. A run of such a line in another language than the
142
- * document's ({@link segmentLanguages}) is a `Span` with its own `/Lang`,
143
- * and so is one of a composed line of a Japanese document, or of a
144
- * composed line holding Japanese text (#427).
145
- *
146
- * A segment in a language of its own (`VDTLineSegment.lang`) is shaped in
147
- * that language, as it was measured (`shapingLanguage.ts`, #764): a
148
- * Japanese word in a Chinese book takes the Japanese forms of a pan-CJK
149
- * face, a Catalan name in an English one its `l·l`. In a document that
150
- * keeps the host's language only Japanese has forms of its own, and a
151
- * word HarfBuzz shapes is told no language, as before.
152
- *
153
- * A word set in several styles (`VDTLineSegment.runs`, a bold letter in an
154
- * Arabic word) is shaped whole and each glyph painted in its run's style
155
- * (`drawStyledWordPx`).
156
- *
157
- * `segments` are the line's own, or, in a document shaped in its own
158
- * language, those with the pieces of a word measured whole joined
159
- * (`wordPieces.ts`).
160
- */
161
- function renderSegments(ctx, segments, startX, baseline, line, block, blockFont, blockSize, blockColor, fontCache, linkRegistry, elem, justifiedSpaceWidth,
162
- /** The character spacing the line is painted with (block + line, px);
163
- * a segment's own tracking (a justified CJK line) goes on top of it. */
164
- tracking = 0,
165
- /** The first line of a paragraph a drop cap opens (#623). */
166
- capLead) {
167
- let x = startX;
168
- const refRun = new RefRun();
169
- // The first word, which the drop cap opens: its text segments on this
170
- // line read as the whole word (the initial reads as nothing) and join
171
- // the word's `Span`.
172
- let capPrefix = capLead?.prefix;
173
- let capRest = capLead?.rest ?? 0;
174
- const uris = new UriRuns(ctx, line, linkRegistry, elem);
175
- const repeatedAt = repeatedHyphenSegment(line, segments);
176
- const composed = line.cjkComposed === true || ctx.vertical !== undefined;
177
- const directed = isDirected(line);
178
- // The order segments are laid out in, left to right (by default
179
- // theirs), and the x it gives each: they are painted in logical order.
180
- const order = directed && line.order && line.order.length === segments.length ? line.order : undefined;
181
- const xs = order ? segmentOffsets(segments, order, startX, (seg) => (seg.kind === 'space' ? (composed && seg.autospace ? seg.width : justifiedSpaceWidth ?? seg.width) : seg.width)) : undefined;
182
- // Runs in another language than the document's (tagged render only):
183
- // on a line with directions, and on a composed line in Japanese.
184
- const docLang = elem?.tree.options.lang;
185
- const langs = elem && (directed || (composed && japaneseLine(segments, docLang))) ? segmentLanguages(segments, docLang) : undefined;
186
- let langSpan;
187
- const textElemOf = (i) => {
188
- const lang = langs?.[i];
189
- if (!lang) {
190
- langSpan = undefined;
191
- return elem;
192
- }
193
- if (langSpan?.lang !== lang)
194
- langSpan = { lang, elem: elem.child('Span', { lang }) };
195
- return langSpan.elem;
196
- };
197
- // A composed CJK line (spread characters, Han–Latin spaces) reads as
198
- // written, not with the gaps between its pieces.
199
- // A vertical line is painted in runs and cells down the column: it reads
200
- // as the line too.
201
- const actualLine = !composed ? undefined : ctx.vertical ? segments.map(readText).join('') : cjkLineText(segments);
202
- let lineState;
203
- if (actualLine !== undefined) {
204
- const first = segments.find((s) => s.kind === 'text' && !s.chip && s.text !== '');
205
- const fontStr = first ? first.fontString ?? pickSegmentFont(!!first.bold, !!first.italic, block) : block.fontString;
206
- lineState = {
207
- font: fontCache.get(fontStr) ?? blockFont,
208
- text: first?.text ?? '',
209
- sizePx: parseFontString(fontStr)?.sizePx ?? blockSize,
210
- xPx: startX,
211
- baselinePx: baseline,
212
- };
213
- beginActualTextSpan(ctx, actualLine, lineState);
214
- }
215
- for (let i = 0; i < segments.length; i++) {
216
- const seg = segments[i];
217
- if (xs)
218
- x = xs[i];
219
- const textElem = langs ? textElemOf(i) : elem;
220
- if (seg.kind === 'space') {
221
- // A space inside a reference label (#702) is read in its `Link`.
222
- const inLink = uris.space(seg.text) ?? refRun.space(seg);
223
- if (ctx.tags && seg.text) {
224
- tagContent(ctx, inLink ?? textElem);
225
- // The gap of a poem's bayt holds the tab of its plain text (#378),
226
- // which no face draws: it reads as a space.
227
- drawTextPx(ctx, seg.text.replace(/\t/g, ' '), x, baseline, blockFont, blockSize, blockColor);
228
- }
229
- // A Han–Latin space keeps the width the composer set.
230
- x += composed && seg.autospace ? seg.width : justifiedSpaceWidth ?? seg.width;
231
- continue;
232
- }
233
- if (seg.leader) {
234
- // A leader (a contents row's, a tab stop's, #622): a layout artifact
235
- // under an empty `/ActualText`, so no text extraction reads it.
236
- uris.other();
237
- tagArtifact(ctx, { type: 'Layout' });
238
- if (seg.leader === 'rule') {
239
- const { dy, thickness } = leaderRuleGeometry(blockSize);
240
- fillRectPx(ctx, x, baseline + dy - thickness / 2, seg.width, thickness, blockColor);
241
- }
242
- else {
243
- const fontStr = seg.fontString ?? pickSegmentFont(!!seg.bold, !!seg.italic, block);
244
- const colorHex = seg.color ?? pickSegmentColor(!!seg.bold, !!seg.italic, block);
245
- drawTextPx(ctx, seg.text, x, baseline, fontCache.get(fontStr) ?? blockFont, parseFontString(fontStr)?.sizePx ?? blockSize, colorHex === block.color ? blockColor : colorFromHex(colorHex, ctx.colorSpace), undefined, '');
246
- }
247
- x += seg.width;
248
- continue;
249
- }
250
- if (seg.kind !== 'text' || seg.chip)
251
- uris.other();
252
- if (seg.kind === 'math') {
253
- if (elem) {
254
- const formula = elem.type === 'Formula' ? elem : elem.child('Formula', { alt: seg.mathRender?.tex ?? '' });
255
- tagContent(ctx, formula);
256
- }
257
- renderMathSegment(ctx, seg, x, baseline, blockColor);
258
- x += seg.width;
259
- continue;
260
- }
261
- if (seg.kind === 'score') {
262
- // A score system (#1172): a Figure in the structure tree, with the
263
- // score's alt text (each system its own, the first one carrying it).
264
- if (elem) {
265
- const figure = elem.type === 'Figure' ? elem : elem.child('Figure', { alt: block.score?.alt ?? '' });
266
- tagContent(ctx, figure);
267
- }
268
- renderScoreSegment(ctx, seg, x, baseline, block.color);
269
- x += seg.width;
270
- continue;
271
- }
272
- if (seg.kind === 'swatch') {
273
- paintSwatchSegmentPdf(ctx, seg, x, baseline, blockColor, fontCache, blockFont, elem);
274
- x += seg.width;
275
- continue;
276
- }
277
- if (seg.chip) {
278
- paintChip(ctx, seg.chip, x, baseline, fontCache, blockFont, blockSize, elem, (run) => {
279
- const hex = seg.chip.color ?? pickSegmentColor(!!run.bold, !!run.italic, block);
280
- return hex === block.color ? blockColor : colorFromHex(hex, ctx.colorSpace);
281
- });
282
- x += seg.width;
283
- continue;
284
- }
285
- if (composed && seg.warichu) {
286
- // A warichu note's part: its two rows, not its text (#195), with no
287
- // character spacing.
288
- if (tracking !== 0)
289
- setTrackingPx(ctx, 0);
290
- paintWarichu(ctx, seg.warichu, x, baseline, pickSegmentColor(!!seg.bold, !!seg.italic, block), fontCache, blockFont, elem);
291
- if (tracking !== 0)
292
- setTrackingPx(ctx, tracking);
293
- x += seg.width;
294
- continue;
295
- }
296
- const fontStr = seg.fontString ?? pickSegmentFont(!!seg.bold, !!seg.italic, block);
297
- const font = fontCache.get(fontStr) ?? blockFont;
298
- const size = parseFontString(fontStr)?.sizePx ?? blockSize;
299
- const colorHex = seg.color
300
- ?? (seg.refResourceId !== undefined && block.refColor
301
- ? block.refColor
302
- : pickSegmentColor(!!seg.bold, !!seg.italic, block));
303
- const color = colorHex === block.color ? blockColor : colorFromHex(colorHex, ctx.colorSpace);
304
- // A `:ref` links to its resource — one `Link` for all the runs of one
305
- // set in small capitals —, a Markdown link's words to its URL.
306
- const uriElem = uris.word(seg.refResourceId === undefined ? seg.href : undefined, x, seg.width, seg.text);
307
- // A footnote marker links to its note, like a `:ref` to its resource
308
- // and a cross-reference to its anchor (#264).
309
- const target = refTarget(seg) ?? (seg.footnoteId !== undefined ? footnoteDestination(linkRegistry, seg.footnoteId) : undefined);
310
- // A marker in the line gap (JLReq §4.2.3) links where its run is:
311
- // before its segment, which takes no advance.
312
- const side = seg.sideMarker?.runs[0];
313
- const link = side ? refRun.enter(seg, x + side.dx, textElem, target, -side.dx) : refRun.enter(seg, x, textElem, target, seg.width);
314
- // A page number of the index links to its page.
315
- const pageElem = seg.pageLink !== undefined && elem && !link ? elem.child('Link') : undefined;
316
- // A ruby base is the `RB` of a `Ruby` whose `RT` holds its reading (#194).
317
- const holder = link ?? pageElem ?? uriElem ?? textElem;
318
- const rubyElem = composed && seg.ruby && holder ? holder.child('Ruby') : undefined;
319
- // The hyphen repeated from the line before is painted but not read.
320
- let actualText = i === repeatedAt ? seg.text.slice(1) : undefined;
321
- let capHolder;
322
- if (capPrefix !== undefined || capRest > 0) {
323
- const at = Math.min(capRest, seg.text.length);
324
- actualText = (capPrefix ?? '') + seg.text.slice(at);
325
- capRest -= at;
326
- capPrefix = undefined;
327
- capHolder = capLead?.elem;
328
- }
329
- tagContent(ctx, rubyElem ? rubyElem.child('RB') : capHolder ?? holder);
330
- // On a line with directions each segment is one run: HarfBuzz shapes a
331
- // right-to-left one (and any complex text), and a word set in several
332
- // styles. The kashidas justification inserted are painted, not read.
333
- // A word with no letter is shaped in the script the layout measured it
334
- // in (`scriptContext`, #725), by HarfBuzz or by fontkit.
335
- const shaped = !seg.sideMarker && (seg.runs !== undefined || (directed && (seg.rtl || needsComplexShaping(seg.text))))
336
- && withSegmentLanguage(seg.lang, () => paintInScript(ctx, seg.scriptContext, () => paintShapedSegment(ctx, seg, x, baseline + (seg.baselineShift ?? 0), font, size, color, block, fontCache, actualText, kashidaOf(seg, line))));
337
- if (seg.sideMarker) {
338
- // Its run, not its text, with no character spacing.
339
- if (tracking !== 0)
340
- setTrackingPx(ctx, 0);
341
- paintSideMarker(ctx, seg.sideMarker, x, baseline, colorHex, fontCache, blockFont);
342
- if (tracking !== 0)
343
- setTrackingPx(ctx, tracking);
344
- }
345
- else if (shaped) {
346
- // Painted by HarfBuzz.
347
- }
348
- else {
349
- withSegmentLanguage(seg.lang, () => {
350
- if (!composed)
351
- paintInScript(ctx, seg.scriptContext, () => drawTextPx(ctx, seg.text, x, baseline + (seg.baselineShift ?? 0), font, size, color, undefined, actualText));
352
- else
353
- paintComposedText(ctx, seg, x, baseline, font, size, color, colorHex, actualText, tracking, fontCache, blockFont, rubyElem, holder);
354
- }, true);
355
- }
356
- if (seg.pageLink !== undefined && linkRegistry) {
357
- const { scale, pageHeightPt } = ctx;
358
- linkRegistry.addPageLink(ctx.page, sheetRect(ctx, [x * scale, pageHeightPt - (line.bbox.y + line.bbox.height) * scale, (x + seg.width) * scale, pageHeightPt - line.bbox.y * scale]), seg.pageLink, pageElem ? { elem: pageElem, contents: seg.text } : undefined);
359
- }
360
- const ref = refRun.leave(seg, segments[i + 1], target);
361
- if (ref && linkRegistry) {
362
- const { scale, pageHeightPt } = ctx;
363
- const x1 = ref.left * scale;
364
- const x2 = Math.max(ref.right, x + seg.width) * scale;
365
- const y2 = pageHeightPt - line.bbox.y * scale;
366
- const y1 = pageHeightPt - (line.bbox.y + line.bbox.height) * scale;
367
- linkRegistry.addLink(ctx.page, sheetRect(ctx, [x1, y1, x2, y2]), ref.resourceId, link ? { elem: link, contents: ref.text } : undefined);
368
- }
369
- x += seg.width;
370
- }
371
- uris.end();
372
- if (lineState)
373
- endActualTextSpan(ctx, lineState);
374
- }
375
- /** Whether a composed line is Japanese text: its document's language is
376
- * Japanese, or a segment's own. Its segments in other languages then take
377
- * a `Span` with their `/Lang`; other composed lines keep the structure
378
- * they always had. */
379
- function japaneseLine(segments, docLang) {
380
- return isJapaneseLanguage(docLang) || segments.some((s) => s.lang !== undefined && isJapaneseLanguage(s.lang));
381
- }
382
- /**
383
- * Paint a segment HarfBuzz shapes: a word set in several styles
384
- * (`runs`), each glyph in its run's face and colour, else the segment as
385
- * one run in its direction. False when HarfBuzz is not loaded: the caller
386
- * paints it the fontkit way.
387
- */
388
- function paintShapedSegment(ctx, seg, x, baseline, font, size, color, block, fontCache, actualText, hideTatweel) {
389
- const direction = seg.rtl ? 'rtl' : 'ltr';
390
- if (seg.runs && drawStyledWordPx(ctx, seg.text, x, baseline, font, size, color, wordParts(seg, font, color, ctx, (bold, italic) => ({ font: fontCache.get(pickSegmentFont(bold, italic, block)) ?? undefined, color: colorFromHex(pickSegmentColor(bold, italic, block), ctx.colorSpace) })), { direction, actualText, hideTatweel }))
391
- return true;
392
- return drawShapedTextPx(ctx, seg.text, x, baseline, font, size, color, { direction, actualText, hideTatweel });
393
- }
394
- /** Tracking: the block (column balancing; negative for a runt set short)
395
- * and the line (justification tracking) were measured with extra advance
396
- * after every glyph, so paint the line with the matching character
397
- * spacing (`Tc`, in points at the page scale) and reset it afterwards. */
398
- function renderLine(ctx, line, block, columnWidth, columnX, fontCache, linkRegistry, elem, capLead) {
399
- const tracking = (block.letterSpacing ?? 0) + (line.letterSpacing ?? 0);
400
- if (tracking !== 0)
401
- setTrackingPx(ctx, tracking);
402
- renderLineText(ctx, line, block, columnWidth, columnX, fontCache, linkRegistry, elem, tracking, trailingTracking(line, tracking), capLead);
403
- if (tracking !== 0)
404
- setTrackingPx(ctx, 0);
405
- }
406
- /** The tracking a line's measured width carries after its last glyph:
407
- * `tracking` when the line ends on text, else 0. It is advance, not ink,
408
- * so centring and right alignment leave it out (EF-153), as the canvas
409
- * and HTML backends do (`lineTrailingTracking` in postext). */
410
- function trailingTracking(line, tracking) {
411
- if (tracking === 0)
412
- return 0;
413
- const segments = line.segments;
414
- if (segments && segments.length > 0) {
415
- let i = segments.length - 1;
416
- // A mark hung past the line's end is outside it (CJK only).
417
- while (i > 0 && segments[i].hangs)
418
- i--;
419
- const last = segments[i];
420
- return last.kind === 'text' && last.text.length > 0 ? tracking : 0;
421
- }
422
- return /\S$/.test(line.text) ? tracking : 0;
423
- }
424
- function renderLineText(ctx, line, block, columnWidth, columnX, fontCache, linkRegistry, elem, tracking, trailing = 0, capLead) {
425
- const blockFont = fontCache.get(block.fontString);
426
- if (!blockFont)
427
- return;
428
- const blockSize = parseFontString(block.fontString)?.sizePx ?? 0;
429
- const blockColor = colorFromHex(block.color, ctx.colorSpace);
430
- // A line whose block runs against its frame (a right-to-left paragraph
431
- // on a left-to-right page, an English quotation in an Arabic book)
432
- // carries its span (`measure`): it is justified across it and set ragged
433
- // from its start side, the right, as the canvas sets it.
434
- const span = line.measure;
435
- const lineX = span ? span.x : line.bbox.x;
436
- const align = lineTextAlign(line, block.textAlign);
437
- const lineIndent = lineX - columnX;
438
- const effectiveWidth = span ? span.width : columnWidth - lineIndent;
439
- // Only a line of the CJK composer (or down a vertical page) has hung
440
- // marks and Han–Latin spaces (see `renderSegments`).
441
- const composed = line.cjkComposed === true || ctx.vertical !== undefined;
442
- // The pieces of a word the layout measured whole are painted as that
443
- // word, in a document shaped in its own language (#764).
444
- const segments = wordSegments(line, composed, (seg, text, sizeOf) => {
445
- const fontStr = seg.fontString ?? pickSegmentFont(!!seg.bold, !!seg.italic, block);
446
- return withSegmentLanguage(seg.lang, () => textAdvancePx(fontCache.get(fontStr) ?? blockFont, text, sizeOf(parseFontString(fontStr)?.sizePx ?? blockSize), tracking).advance);
447
- });
448
- // Last lines render ragged at natural width — except when overfull:
449
- // Knuth-Plass may accept a final line wider than the measure on the
450
- // assumption that its inter-word glue shrinks (TeX glue-setting semantics),
451
- // so honor that by compressing the spaces to fit the measure exactly.
452
- if (block.textAlign === 'justify' && segments && segments.length > 0) {
453
- let wordWidth = 0;
454
- let naturalWidth = 0;
455
- let spaceCount = 0;
456
- for (const seg of segments) {
457
- // A hung mark is outside the measure; a Han–Latin space keeps its
458
- // width.
459
- if (composed && seg.hangs)
460
- continue;
461
- if (seg.kind === 'space' && !(composed && seg.autospace))
462
- spaceCount++;
463
- else
464
- wordWidth += seg.width;
465
- naturalWidth += seg.width;
466
- }
467
- if (spaceCount > 0 && !line.tabbed && ((!line.isLastLine && !line.ragged) || naturalWidth > effectiveWidth)) {
468
- const justifiedSpaceWidth = (effectiveWidth - wordWidth) / spaceCount;
469
- renderSegments(ctx, segments, lineX, line.baseline, line, block, blockFont, blockSize, blockColor, fontCache, linkRegistry, elem, justifiedSpaceWidth, tracking, capLead);
470
- return;
471
- }
472
- }
473
- if ((align === 'center' || align === 'right') && segments) {
474
- // Hung marks stay out of the alignment, as trailing tracking does.
475
- let contentWidth = 0;
476
- for (const seg of segments)
477
- if (!(composed && seg.hangs))
478
- contentWidth += seg.width;
479
- const slack = Math.max(0, effectiveWidth - (contentWidth - trailing));
480
- const startX = lineX + (align === 'center' ? slack / 2 : slack);
481
- renderSegments(ctx, segments, startX, line.baseline, line, block, blockFont, blockSize, blockColor, fontCache, linkRegistry, elem, undefined, tracking, capLead);
482
- return;
483
- }
484
- // Ragged (left-aligned) rendering — also used for last lines of justified
485
- // blocks. Segments are needed when any of them styles differently from the
486
- // block (bold/italic/math/ref/own font or colour), and when one is in a
487
- // language of its own, which it is shaped in (#764; in a document that
488
- // keeps the host's language, on a line of the CJK composer only, which
489
- // names it in Japanese text, #427); otherwise one text object paints the
490
- // line.
491
- const ownLanguage = segments !== undefined && (line.cjkComposed === true || shapesSegmentLanguages()) && segments.some((s) => s.lang !== undefined);
492
- if (segments && (capLead !== undefined || isDirected(line) || ownLanguage || segments.some(composed ? composedSegmentIsStyled : segmentIsStyled))) {
493
- renderSegments(ctx, segments, lineX, line.baseline, line, block, blockFont, blockSize, blockColor, fontCache, linkRegistry, elem, undefined, tracking, capLead);
494
- return;
495
- }
496
- tagContent(ctx, capLead?.elem ?? elem);
497
- const plainSlack = Math.max(0, effectiveWidth - (line.bbox.width - trailing));
498
- const plainX = lineX + (align === 'right' ? plainSlack : align === 'center' ? plainSlack / 2 : 0);
499
- // Each word where the layout measured it (EF-137): the embedded face's
500
- // own widths could differ, most of all for a character it has no glyph
501
- // for, and would carry the rest of the line along.
502
- // The hyphen repeated from the line before is painted but not read.
503
- const actualText = capLead
504
- ? capLead.prefix + line.text.slice(capLead.rest)
505
- : line.repeatedHyphen && line.text.startsWith('-') ? line.text.slice(1) : undefined;
506
- // A line with right-to-left or joining letters and no directions (a VDT
507
- // from before the engine resolved bidi levels) is set as one text, cut
508
- // into bidi runs and shaped by HarfBuzz; with fontkit when HarfBuzz is
509
- // not loaded, which turns the whole line around.
510
- const complex = needsComplexShaping(line.text);
511
- if (segments && segments.length > 0 && !complex
512
- && drawMeasuredTextPx(ctx, measuredPieces(ctx, line, segments, blockFont, blockSize, tracking), plainX, line.baseline, blockFont, blockSize, blockColor, tracking, actualText))
513
- return;
514
- if (complex && drawShapedTextPx(ctx, line.text, plainX, line.baseline, blockFont, blockSize, blockColor, { base: block.direction, actualText }))
515
- return;
516
- drawTextPx(ctx, line.text, plainX, line.baseline, blockFont, blockSize, blockColor, undefined, actualText);
517
- }
518
- /** Whether a segment of a line set word by word paints differently from
519
- * the block's plain text, or is linked; an orientation mark (`:tcy`,
520
- * `:upright`, `:sideways`) keeps its segment apart. */
521
- function segmentIsStyled(s) {
522
- return s.bold || s.italic || s.runs !== undefined || s.sideMarker !== undefined || s.kind === 'math' || s.kind === 'score' || s.kind === 'swatch' || s.kind === 'chip' || s.refResourceId !== undefined || s.href !== undefined || s.pageLink !== undefined || s.fontString !== undefined || s.color !== undefined || s.baselineShift !== undefined
523
- || s.tcy !== undefined || s.orientation !== undefined || s.labelTab !== undefined || s.leader !== undefined
524
- // A word with no letter shaped in the script of its context (#725):
525
- // its line is painted word by word, each in its script.
526
- || s.scriptContext !== undefined;
527
- }
528
- /** {@link segmentIsStyled} for a line of the CJK composer or one down a
529
- * vertical page, whose segments may carry the composer's fields. */
530
- function composedSegmentIsStyled(s) {
531
- return segmentIsStyled(s) || s.tracking !== undefined || s.inkOffset !== undefined || s.hangs !== undefined || s.autospace !== undefined || s.ruby !== undefined || s.kunten !== undefined || s.warichu !== undefined;
532
- }
533
- /**
534
- * The index of the segment that opens with the hyphen repeated from the line
535
- * before (`VDTLine.repeatedHyphen`, "vencer-" | "-se"), or -1. The PDF paints
536
- * that segment with an `/ActualText` that leaves the hyphen out, so copying
537
- * and text extraction read the word once, as written ("vencer-se").
538
- */
539
- function repeatedHyphenSegment(line, segments) {
540
- if (!line.repeatedHyphen)
541
- return -1;
542
- const i = segments.findIndex((s) => s.kind !== 'space');
543
- const seg = segments[i];
544
- return seg && seg.kind === 'text' && !seg.chip && seg.text.startsWith('-') ? i : -1;
545
- }
546
- /** The pieces a line painted as one text is set from: its segments
547
- * ({@link withLineEndSpace}), and on a line of the CJK composer the
548
- * characters of a segment it measured one by one, each a piece of its own
549
- * (`cellPieces`, #770). */
550
- function measuredPieces(ctx, line, segments, font, sizePx, tracking) {
551
- const pieces = withLineEndSpace(segments, line.text);
552
- if (line.cjkComposed !== true || ctx.vertical)
553
- return pieces;
554
- let cut;
555
- pieces.forEach((piece, i) => {
556
- const cells = cellPieces(font, piece.text, piece.width, sizePx, tracking);
557
- if (cells)
558
- (cut ??= pieces.slice(0, i)).push(...cells);
559
- else
560
- cut?.push(piece);
561
- });
562
- return cut ?? pieces;
563
- }
564
- /** A ragged line's segments, plus the space that ends the line when its
565
- * text has one and the segments leave it out. The space takes no room
566
- * past the line, but it is painted, as it was when the whole text was one
567
- * run, so extracted text keeps the words either side of the break apart. */
568
- function withLineEndSpace(segments, text) {
569
- let shown = '';
570
- for (const seg of segments)
571
- shown += seg.text;
572
- if (text.length <= shown.length || !text.startsWith(shown))
573
- return segments;
574
- const rest = text.slice(shown.length);
575
- return /^\s+$/.test(rest) ? [...segments, { text: rest, width: 0 }] : segments;
576
- }
577
- /** Whether a line carries the engine's directions: an order to paint its
578
- * segments in, or a right-to-left segment. Absent on every left-to-right
579
- * line, which is painted as it always was. */
580
- function isDirected(line) {
581
- return line.order !== undefined || (line.segments?.some((s) => s.rtl) ?? false);
582
- }
583
- function renderBullet(ctx, block, fontCache, elem) {
584
- // A task item's drawn box (#765): paths in its `Lbl`, which reads as the
585
- // character the box stands for.
586
- if (block.bulletBox) {
587
- tagContent(ctx, elem);
588
- drawTaskBoxPx(ctx, block);
589
- return;
590
- }
591
- if (!block.bulletText ||
592
- !block.bulletFontString ||
593
- block.bulletOffsetX === undefined) {
594
- return;
595
- }
596
- const firstLine = block.lines[0];
597
- if (!firstLine)
598
- return;
599
- const font = fontCache.get(block.bulletFontString);
600
- if (!font)
601
- return;
602
- const size = parseFontString(block.bulletFontString)?.sizePx ?? 0;
603
- const colorHex = block.bulletColor ?? block.color;
604
- const color = colorFromHex(colorHex, ctx.colorSpace);
605
- // Canvas uses `textBaseline='middle'` at bulletY; pdf-lib draws from the
606
- // alphabetic baseline. Shift the baseline down by ~0.3em so the em-square
607
- // midline aligns at bulletY, matching canvas placement within hinting tolerance.
608
- // A marker set as text (a contents number) has its baseline at
609
- // `bulletBaselineY` (postext 1.5); `bulletY` stays its em-box midpoint.
610
- const baselineY = block.bulletBaselineY;
611
- const onBaseline = baselineY !== undefined;
612
- const midY = block.bulletY ?? firstLine.baseline;
613
- const baselinePx = onBaseline ? baselineY : midY + size * 0.3;
614
- tagContent(ctx, elem);
615
- // Ordered-list separator styled apart from the number (own font/colour),
616
- // with the prefix run before the number in the same style: drawn in
617
- // reading order, prefix, number, separator, so text extraction reads
618
- // (一) and not 一)(.
619
- const sepFontString = block.separatorText && block.separatorX !== undefined ? block.separatorFontString ?? block.bulletFontString : undefined;
620
- const sepFont = sepFontString !== undefined ? fontCache.get(sepFontString) : undefined;
621
- const sepSize = sepFontString !== undefined ? parseFontString(sepFontString)?.sizePx ?? size : size;
622
- const sepColor = colorFromHex(block.separatorColor ?? colorHex, ctx.colorSpace);
623
- const sepY = onBaseline ? baselineY : midY + sepSize * 0.3;
624
- // A marker of a right-to-left item reads in its direction (#664).
625
- const put = (text, x, y, f, s, c) => {
626
- if (block.bulletDirection)
627
- drawMarkerRuns(ctx, text, x, y, f, s, c, block.bulletDirection);
628
- else
629
- drawTextPx(ctx, text, x, y, f, s, c);
630
- };
631
- if (sepFont && block.prefixText && block.prefixX !== undefined) {
632
- put(block.prefixText, block.prefixX, sepY, sepFont, sepSize, sepColor);
633
- }
634
- put(block.bulletText, block.bulletOffsetX, baselinePx, font, size, color);
635
- if (sepFont && block.separatorText && block.separatorX !== undefined) {
636
- put(block.separatorText, block.separatorX, sepY, sepFont, sepSize, sepColor);
637
- }
638
- }
639
- /** A character past Latin-1: a text that holds one is cut into script
640
- * runs by the canvas (see `shapingLanguage.ts`). */
641
- const WIDE_MARKER_RE = /[^\u0000-\u00FF]/;
642
- /**
643
- * A marker that reads right to left (`VDTBlock.bulletDirection`, #664) at
644
- * `xPx`, its left edge in the flow: its runs (`markerRuns`, one bidi level
645
- * each, in visual order from the sheet's left) stand one after the other
646
- * along the flow's x axis, which on a mirrored page runs from the sheet's
647
- * right, each as wide as the face sets it; a right-to-left run is shaped
648
- * so and its brackets mirrored. They are drawn in reading order, so text
649
- * extraction reads `1-` whatever side the hyphen stands on.
650
- */
651
- function drawMarkerRuns(ctx, text, xPx, baselinePx, font, sizePx, color, direction) {
652
- const draw = () => {
653
- const runs = markerRuns(text, direction);
654
- if (ctx.mirror)
655
- runs.reverse();
656
- let at = xPx;
657
- const placed = runs.map((run) => {
658
- const x = at;
659
- at += textAdvancePx(font, run.text, sizePx, joinsLetters(run.text) ? 0 : ctx.trackingPx ?? 0).advance;
660
- return { run, x };
661
- });
662
- placed.sort((a, b) => a.run.start - b.run.start);
663
- for (const { run, x } of placed) {
664
- if (run.rtl)
665
- drawRightToLeftRun(ctx, run.text, x, baselinePx, font, sizePx, color);
666
- else
667
- drawTextPx(ctx, run.text, x, baselinePx, font, sizePx, color);
668
- }
669
- };
670
- // In a document shaped in its own language the layout measures the
671
- // marker, and the canvas paints it, as one text set right to left
672
- // (`markerSetText`, #770). A run of it with no letter is shaped there as
673
- // a piece of that text, not as a word of its own: when the text holds a
674
- // character past U+00FF (an Arabic letter or digit, the Arabic letter
675
- // mark before European digits read as an Arabic number) such a piece
676
- // has no script and takes the face's default forms. Amiri bold: `(١)`
677
- // is 1.501 em wide so, and 1.153 em with its brackets in Latin forms.
678
- if (shapesAsCanvas() && WIDE_MARKER_RE.test(markerSetText(text, direction)))
679
- withinWideText(true, draw);
680
- else
681
- draw();
682
- }
683
- function dropCapLead(cap, elem) {
684
- const prefix = cap.wordRest > 0 ? cap.word : `${cap.word} `;
685
- return { prefix, rest: cap.wordRest, ...(elem ? { elem: elem.child('Span', { actualText: prefix }) } : {}) };
686
- }
687
- /** A paragraph's drop cap (#623) and an opening mark hung before it, part
688
- * of the paragraph's text in a tagged render, read as nothing (the first
689
- * line reads the word whole, see {@link CapLead}). */
690
- function renderDropCap(ctx, cap, fontCache, elem) {
691
- const color = colorFromHex(cap.color, ctx.colorSpace);
692
- const paint = (text, fontString, x, baseline) => {
693
- const font = fontCache.get(fontString);
694
- if (!font)
695
- return;
696
- const size = parseFontString(fontString)?.sizePx ?? 0;
697
- tagContent(ctx, elem);
698
- drawTextPx(ctx, text, x, baseline, font, size, color, undefined, '');
699
- };
700
- if (cap.hang)
701
- paint(cap.hang.text, cap.hang.fontString, cap.hang.x, cap.hang.baselineY);
702
- paint(cap.text, cap.fontString, cap.x, cap.baselineY);
703
- }
704
- function renderStrikethrough(ctx, block) {
705
- if (!block.strikethroughText)
706
- return;
707
- tagArtifact(ctx, { type: 'Layout' });
708
- const color = colorFromHex(block.color, ctx.colorSpace);
709
- const thickness = Math.max(1, block.lines[0]?.bbox.height ? block.lines[0].bbox.height * 0.05 : 1);
710
- for (const line of block.lines) {
711
- const y = line.baseline - line.bbox.height * 0.28;
712
- drawLinePx(ctx, line.bbox.x, y, line.bbox.x + line.bbox.width, y, color, thickness);
713
- }
714
- }
715
- /** A rect of the page's frame in PDF points, on the sheet: through the
716
- * flow frame of a vertical page (`PageCtx.mapRectPt`), as it is on any
717
- * other. Annotation rects and destinations live outside the content
718
- * stream, so the frame's `cm` does not reach them. */
719
- function sheetRect(ctx, rect) {
720
- return ctx.mapRectPt ? ctx.mapRectPt(rect) : rect;
721
- }
722
- /** Annotation rectangle of a block's box, in PDF points, on the sheet. */
723
- function rectOfBlock(ctx, block) {
724
- const { scale, pageHeightPt } = ctx;
725
- const { x, y, width, height } = block.bbox;
726
- return sheetRect(ctx, [x * scale, pageHeightPt - (y + height) * scale, (x + width) * scale, pageHeightPt - y * scale]);
727
- }
728
- /**
729
- * A strip's caption (`VDTBlock.stripCaption`, #590), in the flow: the bar
730
- * behind it (layout), the target of a `:ref` naming the strip, then its
731
- * lines, painted as a paragraph's (turned on a vertical page) and tagged
732
- * into `elem` — the `Caption` of the strip's `Div`. The strip's picture is
733
- * painted on the sheet later (`renderComicPage`).
734
- */
735
- export function renderStripCaption(ctx, block, fontCache, linkRegistry, elem) {
736
- const caption = block.stripCaption;
737
- if (!caption || block.hidden)
738
- return;
739
- if (caption.id && linkRegistry) {
740
- const [left, , , top] = rectOfBlock(ctx, block);
741
- linkRegistry.addDestination(caption.id, ctx.page, left, top);
742
- }
743
- if (caption.bar) {
744
- tagArtifact(ctx, { type: 'Layout' });
745
- const { rect, background } = caption.bar;
746
- fillRectPx(ctx, block.bbox.x + rect.x, block.bbox.y + rect.y, rect.width, rect.height, colorFromHex(background, ctx.colorSpace));
747
- }
748
- for (const line of block.lines.slice(caption.firstLine, caption.firstLine + caption.lineCount)) {
749
- if (line.highlights)
750
- paintLineHighlights(ctx, line);
751
- renderLine(ctx, line, block, block.bbox.width, block.bbox.x, fontCache, linkRegistry, elem);
752
- if (line.marks)
753
- paintLineMarks(ctx, line, colorFromHex(block.color, ctx.colorSpace));
754
- }
755
- }
756
- export function renderBlock(ctx, block, columnWidth, columnX, fontCache, resourceCtx) {
757
- if (block.hidden)
758
- return;
759
- // A box printed upside down (#1229): drawn turned about its centre, a
760
- // point (x, y) of the page landing at (2cx − x, 2cy − y).
761
- if (block.turn) {
762
- const { scale, pageHeightPt } = ctx;
763
- ctx.page.pushOperators(pushGraphicsState(), concatTransformationMatrix(-1, 0, 0, -1, 2 * block.turn.cx * scale, 2 * (pageHeightPt - block.turn.cy * scale)));
764
- try {
765
- renderBlockUpright(ctx, block, columnWidth, columnX, fontCache, resourceCtx);
766
- }
767
- finally {
768
- ctx.page.pushOperators(popGraphicsState());
769
- }
770
- return;
771
- }
772
- renderBlockUpright(ctx, block, columnWidth, columnX, fontCache, resourceCtx);
773
- }
774
- function renderBlockUpright(ctx, block, columnWidth, columnX, fontCache, resourceCtx) {
775
- const structure = resourceCtx?.structure;
776
- const linkRegistry = resourceCtx?.linkRegistry;
777
- // The head row of a cut contents block repeated at the top of the column
778
- // it goes on in (#850): pagination furniture, as a split box's repeated
779
- // title is. A tagged render reads it as an artifact, not as a second
780
- // `TOCI`, and it carries no link (the head row it repeats has one).
781
- const repeatedTocHead = block.tocEntry?.continued === true || block.tocPart?.continued === true;
782
- // A row of the contents links to the page it lists: the whole row is
783
- // the annotation, its text the `Link` element in a tagged render.
784
- const targetPage = repeatedTocHead ? undefined : block.tocEntry?.pageIndex ?? block.tocPart?.pageIndex;
785
- if (block.designOverlay && repeatedTocHead) {
786
- renderHeaderFooterSlot(ctx, block.designOverlay, fontCache, resourceCtx?.images, structure ? { artifact: { type: 'Pagination' } } : undefined);
787
- return;
788
- }
789
- if (repeatedTocHead) {
790
- if (structure)
791
- tagArtifact(ctx, { type: 'Pagination' });
792
- if (block.type === 'listItem')
793
- renderBullet(ctx, block, fontCache, undefined);
794
- for (const line of block.lines)
795
- renderLine(ctx, line, block, block.bbox.width, block.bbox.x, fontCache, linkRegistry, undefined);
796
- return;
797
- }
798
- if (block.designOverlay) {
799
- // A heading's advanced design or a callout frame: the overlay's text is
800
- // the heading / the callout title, its boxes and icons are decoration.
801
- let link;
802
- const textElem = structure
803
- ? () => link ?? (targetPage !== undefined ? (link = structure.blockElem(block).child('Link')) : structure.blockElem(block))
804
- : undefined;
805
- renderHeaderFooterSlot(ctx, block.designOverlay, fontCache, resourceCtx?.images, textElem && structure
806
- ? { text: textElem, artifact: { type: 'Layout' }, figure: (alt, attributes, after) => structure.designFigure(alt, attributes, after) }
807
- : undefined);
808
- if (targetPage !== undefined && linkRegistry) {
809
- const contents = block.tocPart ? `${block.tocPart.number} ${block.tocPart.title}`.trim() : block.lines.map((l) => l.text).join(' ');
810
- linkRegistry.addPageLink(ctx.page, rectOfBlock(ctx, block), targetPage, link ? { elem: link, contents } : undefined);
811
- }
812
- return;
813
- }
814
- if (block.type === 'resource') {
815
- renderResourceBlock(ctx, block, fontCache, resourceCtx?.images ?? new Map(), resourceCtx?.linkRegistry, structure);
816
- return;
817
- }
818
- const blockElem = structure && (block.lines.length > 0 || block.bulletText) ? structure.blockElem(block) : undefined;
819
- const link = targetPage !== undefined && blockElem ? blockElem.child('Link') : undefined;
820
- const elem = link ?? blockElem;
821
- if (block.type === 'listItem') {
822
- renderBullet(ctx, block, fontCache, structure?.bulletElem(block) ?? elem);
823
- }
824
- // A drop cap (#623): the initial and the rest of its word are one `Span`
825
- // whose `/ActualText` is the word.
826
- const cap = block.dropCap;
827
- const capLead = cap ? dropCapLead(cap, elem) : undefined;
828
- if (cap)
829
- renderDropCap(ctx, cap, fontCache, capLead?.elem ?? elem);
830
- // A note is where its markers link to.
831
- if (block.footnoteNote !== undefined && linkRegistry) {
832
- // The top left of the note's box on the sheet.
833
- const [left, , , top] = rectOfBlock(ctx, block);
834
- linkRegistry.addDestination(footnoteDestination(linkRegistry, block.footnoteNote), ctx.page, left, top);
835
- }
836
- // Justify against the block's own measure (see the canvas backend): blocks
837
- // inside callouts are narrower than their column.
838
- void columnWidth;
839
- void columnX;
840
- block.lines.forEach((line, i) => {
841
- // Highlight bands (`:mark[…]`, #888), under the text.
842
- if (line.highlights)
843
- paintLineHighlights(ctx, line);
844
- renderLine(ctx, line, block, block.bbox.width, block.bbox.x, fontCache, linkRegistry, elem, i === 0 ? capLead : undefined);
845
- // Emphasis dots, proper-name and book-title lines (#193).
846
- if (line.marks)
847
- paintLineMarks(ctx, line, colorFromHex(block.color, ctx.colorSpace));
848
- });
849
- if (targetPage !== undefined && linkRegistry) {
850
- const contents = block.lines.map((l) => l.text).join(' ');
851
- linkRegistry.addPageLink(ctx.page, rectOfBlock(ctx, block), targetPage, link ? { elem: link, contents } : undefined);
852
- }
853
- if (block.strikethroughText) {
854
- renderStrikethrough(ctx, block);
855
- }
856
- }
857
- /** The tatweels of a segment its text read leaves out: the ones kashida
858
- * justification inserted (`VDTLineSegment.kashida`), so one the author
859
- * typed stays; every one on a line of a VDT that only counts them
860
- * (`VDTLine.kashida`, before the per-segment offsets). */
861
- function kashidaOf(seg, line) {
862
- if (seg.kashida)
863
- return seg.kashida.length;
864
- return line.kashida !== undefined && !line.segments?.some((s) => s.kashida);
865
- }
866
- //# sourceMappingURL=blockRender.js.map