zhui-plus 1.0.0 → 1.0.10

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.

Potentially problematic release.


This version of zhui-plus might be problematic. Click here for more details.

Files changed (820) hide show
  1. package/dist/Heatmap.js +689 -0
  2. package/dist/WSPlayer/PlaySDKInterface.js +1 -0
  3. package/dist/WSPlayer/WSPlayer.js +1 -0
  4. package/dist/WSPlayer/audioTalkWorker.js +1 -0
  5. package/dist/WSPlayer/commonThread/libH264Enc.js +21 -0
  6. package/dist/WSPlayer/commonThread/libH264Enc.wasm +0 -0
  7. package/dist/WSPlayer/commonThread/libIVSDrawer.js +21 -0
  8. package/dist/WSPlayer/commonThread/libIVSDrawer.wasm +0 -0
  9. package/dist/WSPlayer/commonThread/libRenderEngine.js +21 -0
  10. package/dist/WSPlayer/commonThread/libRenderEngine.wasm +0 -0
  11. package/dist/WSPlayer/commonThread/libmavasp_litepacket.data +50 -0
  12. package/dist/WSPlayer/commonThread/libmavasp_litepacket.js +21 -0
  13. package/dist/WSPlayer/commonThread/libmavasp_litepacket.wasm +0 -0
  14. package/dist/WSPlayer/icon/IotComboBackGround-alarm.png +0 -0
  15. package/dist/WSPlayer/icon/IotComboBackGround.png +0 -0
  16. package/dist/WSPlayer/icon/RecordHover.svg +13 -0
  17. package/dist/WSPlayer/icon/RecordNormal.svg +13 -0
  18. package/dist/WSPlayer/icon/Recording.svg +15 -0
  19. package/dist/WSPlayer/icon/arrow-b.svg +9 -0
  20. package/dist/WSPlayer/icon/arrow-l.svg +9 -0
  21. package/dist/WSPlayer/icon/arrow-lb.svg +10 -0
  22. package/dist/WSPlayer/icon/arrow-lt.svg +10 -0
  23. package/dist/WSPlayer/icon/arrow-r.svg +9 -0
  24. package/dist/WSPlayer/icon/arrow-rb.svg +10 -0
  25. package/dist/WSPlayer/icon/arrow-rt.svg +10 -0
  26. package/dist/WSPlayer/icon/arrow-t.svg +9 -0
  27. package/dist/WSPlayer/icon/close-all-hover.svg +18 -0
  28. package/dist/WSPlayer/icon/close-all.svg +18 -0
  29. package/dist/WSPlayer/icon/close.svg +16 -0
  30. package/dist/WSPlayer/icon/close_hover.svg +16 -0
  31. package/dist/WSPlayer/icon/default.png +0 -0
  32. package/dist/WSPlayer/icon/draw-triangle_off.svg +14 -0
  33. package/dist/WSPlayer/icon/draw-triangle_off_hover.svg +14 -0
  34. package/dist/WSPlayer/icon/draw-triangle_on.svg +15 -0
  35. package/dist/WSPlayer/icon/draw-triangle_on_hover.svg +15 -0
  36. package/dist/WSPlayer/icon/drops.png +0 -0
  37. package/dist/WSPlayer/icon/fullscreen-hover.svg +13 -0
  38. package/dist/WSPlayer/icon/fullscreen.svg +13 -0
  39. package/dist/WSPlayer/icon/hide-pantilt-on.svg +13 -0
  40. package/dist/WSPlayer/icon/hide-pantilt.svg +13 -0
  41. package/dist/WSPlayer/icon/mobile-speed-control-icon.svg +13 -0
  42. package/dist/WSPlayer/icon/more.svg +13 -0
  43. package/dist/WSPlayer/icon/play-h.png +0 -0
  44. package/dist/WSPlayer/icon/play-n.png +0 -0
  45. package/dist/WSPlayer/icon/play-p.png +0 -0
  46. package/dist/WSPlayer/icon/ptz-icon1.svg +4 -0
  47. package/dist/WSPlayer/icon/ptz-icon2.svg +13 -0
  48. package/dist/WSPlayer/icon/ptz-icon3.svg +10 -0
  49. package/dist/WSPlayer/icon/ptz-icon4.svg +10 -0
  50. package/dist/WSPlayer/icon/ptz-icon5.svg +12 -0
  51. package/dist/WSPlayer/icon/ptz-icon6.svg +14 -0
  52. package/dist/WSPlayer/icon/ptz-select-hover.svg +3 -0
  53. package/dist/WSPlayer/icon/ptz-select.svg +3 -0
  54. package/dist/WSPlayer/icon/record_pause.svg +5 -0
  55. package/dist/WSPlayer/icon/record_play.svg +5 -0
  56. package/dist/WSPlayer/icon/refresh-replay.svg +11 -0
  57. package/dist/WSPlayer/icon/refresh-replay_hover.svg +11 -0
  58. package/dist/WSPlayer/icon/screen-more-icon.svg +15 -0
  59. package/dist/WSPlayer/icon/screen_1.svg +11 -0
  60. package/dist/WSPlayer/icon/screen_16.svg +18 -0
  61. package/dist/WSPlayer/icon/screen_16_hover.svg +18 -0
  62. package/dist/WSPlayer/icon/screen_1_hover.svg +11 -0
  63. package/dist/WSPlayer/icon/screen_2.svg +18 -0
  64. package/dist/WSPlayer/icon/screen_25.svg +19 -0
  65. package/dist/WSPlayer/icon/screen_25_hover.svg +19 -0
  66. package/dist/WSPlayer/icon/screen_2_hover.svg +18 -0
  67. package/dist/WSPlayer/icon/screen_3.svg +13 -0
  68. package/dist/WSPlayer/icon/screen_3_hover.svg +13 -0
  69. package/dist/WSPlayer/icon/screen_4.svg +12 -0
  70. package/dist/WSPlayer/icon/screen_4_hover.svg +12 -0
  71. package/dist/WSPlayer/icon/screen_6.svg +16 -0
  72. package/dist/WSPlayer/icon/screen_6_hover.svg +16 -0
  73. package/dist/WSPlayer/icon/screen_8.svg +18 -0
  74. package/dist/WSPlayer/icon/screen_8_hover.svg +18 -0
  75. package/dist/WSPlayer/icon/screen_9.svg +17 -0
  76. package/dist/WSPlayer/icon/screen_9_hover.svg +17 -0
  77. package/dist/WSPlayer/icon/screen_custom_division.svg +9 -0
  78. package/dist/WSPlayer/icon/screen_custom_division_hover.svg +9 -0
  79. package/dist/WSPlayer/icon/screen_custom_division_merge.svg +3 -0
  80. package/dist/WSPlayer/icon/screen_custom_division_split.svg +6 -0
  81. package/dist/WSPlayer/icon/snapshot.svg +38 -0
  82. package/dist/WSPlayer/icon/snapshot_hover.svg +38 -0
  83. package/dist/WSPlayer/icon/speed_left.svg +15 -0
  84. package/dist/WSPlayer/icon/speed_right.svg +15 -0
  85. package/dist/WSPlayer/icon/spread.png +0 -0
  86. package/dist/WSPlayer/icon/tag-left-alarm.png +0 -0
  87. package/dist/WSPlayer/icon/tag-left-normal.png +0 -0
  88. package/dist/WSPlayer/icon/tag-middle-alarm.png +0 -0
  89. package/dist/WSPlayer/icon/tag-middle-normal.png +0 -0
  90. package/dist/WSPlayer/icon/tag-right-alarm.png +0 -0
  91. package/dist/WSPlayer/icon/tag-right-normal.png +0 -0
  92. package/dist/WSPlayer/icon/talk-off-hover.svg +11 -0
  93. package/dist/WSPlayer/icon/talk-off.svg +11 -0
  94. package/dist/WSPlayer/icon/talk-on.svg +9 -0
  95. package/dist/WSPlayer/icon/voice-have.svg +43 -0
  96. package/dist/WSPlayer/icon/voice-have_hover.svg +43 -0
  97. package/dist/WSPlayer/icon/voice-null.svg +38 -0
  98. package/dist/WSPlayer/icon/voice-null_hover.svg +38 -0
  99. package/dist/WSPlayer/icon/ws-ctrl-ellipsis-hover.svg +14 -0
  100. package/dist/WSPlayer/icon/ws-ctrl-ellipsis.svg +14 -0
  101. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-b-bg.png +0 -0
  102. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-bg.png +0 -0
  103. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-l-bg.png +0 -0
  104. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-lb-bg.png +0 -0
  105. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-lt-bg.png +0 -0
  106. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-r-bg.png +0 -0
  107. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-rb-bg.png +0 -0
  108. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-rt-bg.png +0 -0
  109. package/dist/WSPlayer/icon/wsplayer-mobile-pantilt-t-bg.png +0 -0
  110. package/dist/WSPlayer/jquery-3.6.0.min.js +2 -0
  111. package/dist/WSPlayer/multiThread/libStreamClient.js +21 -0
  112. package/dist/WSPlayer/multiThread/libStreamClient.wasm +0 -0
  113. package/dist/WSPlayer/multiThread/libStreamClient.worker.js +1 -0
  114. package/dist/WSPlayer/multiThread/libplay.data +0 -0
  115. package/dist/WSPlayer/multiThread/libplay.js +1 -0
  116. package/dist/WSPlayer/multiThread/libplay.wasm +0 -0
  117. package/dist/WSPlayer/multiThread/libplay.worker.js +1 -0
  118. package/dist/WSPlayer/player.css +1490 -0
  119. package/dist/WSPlayer/singleThread/VideoDecodeWorker.js +1439 -0
  120. package/dist/WSPlayer/singleThread/libStreamClient.js +21 -0
  121. package/dist/WSPlayer/singleThread/libStreamClient.wasm +0 -0
  122. package/dist/WSPlayer/singleThread/libplay.data +0 -0
  123. package/dist/WSPlayer/singleThread/libplay.js +1 -0
  124. package/dist/WSPlayer/singleThread/libplay.wasm +0 -0
  125. package/dist/WSPlayer/window.division.css +80 -0
  126. package/dist/index.js +467 -0
  127. package/dist/locale/af.js +193 -0
  128. package/dist/locale/af.min.js +3 -0
  129. package/dist/locale/af.min.js.map +1 -0
  130. package/dist/locale/af.min.mjs +3 -0
  131. package/dist/locale/af.min.mjs.map +1 -0
  132. package/dist/locale/af.mjs +186 -0
  133. package/dist/locale/ar-eg.js +193 -0
  134. package/dist/locale/ar-eg.min.js +3 -0
  135. package/dist/locale/ar-eg.min.js.map +1 -0
  136. package/dist/locale/ar-eg.min.mjs +3 -0
  137. package/dist/locale/ar-eg.min.mjs.map +1 -0
  138. package/dist/locale/ar-eg.mjs +186 -0
  139. package/dist/locale/ar.js +193 -0
  140. package/dist/locale/ar.min.js +3 -0
  141. package/dist/locale/ar.min.js.map +1 -0
  142. package/dist/locale/ar.min.mjs +3 -0
  143. package/dist/locale/ar.min.mjs.map +1 -0
  144. package/dist/locale/ar.mjs +186 -0
  145. package/dist/locale/az.js +194 -0
  146. package/dist/locale/az.min.js +3 -0
  147. package/dist/locale/az.min.js.map +1 -0
  148. package/dist/locale/az.min.mjs +3 -0
  149. package/dist/locale/az.min.mjs.map +1 -0
  150. package/dist/locale/az.mjs +187 -0
  151. package/dist/locale/bg.js +193 -0
  152. package/dist/locale/bg.min.js +3 -0
  153. package/dist/locale/bg.min.js.map +1 -0
  154. package/dist/locale/bg.min.mjs +3 -0
  155. package/dist/locale/bg.min.mjs.map +1 -0
  156. package/dist/locale/bg.mjs +186 -0
  157. package/dist/locale/bn.js +193 -0
  158. package/dist/locale/bn.min.js +3 -0
  159. package/dist/locale/bn.min.js.map +1 -0
  160. package/dist/locale/bn.min.mjs +3 -0
  161. package/dist/locale/bn.min.mjs.map +1 -0
  162. package/dist/locale/bn.mjs +186 -0
  163. package/dist/locale/ca.js +193 -0
  164. package/dist/locale/ca.min.js +3 -0
  165. package/dist/locale/ca.min.js.map +1 -0
  166. package/dist/locale/ca.min.mjs +3 -0
  167. package/dist/locale/ca.min.mjs.map +1 -0
  168. package/dist/locale/ca.mjs +186 -0
  169. package/dist/locale/ckb.js +193 -0
  170. package/dist/locale/ckb.min.js +3 -0
  171. package/dist/locale/ckb.min.js.map +1 -0
  172. package/dist/locale/ckb.min.mjs +3 -0
  173. package/dist/locale/ckb.min.mjs.map +1 -0
  174. package/dist/locale/ckb.mjs +186 -0
  175. package/dist/locale/cs.js +195 -0
  176. package/dist/locale/cs.min.js +3 -0
  177. package/dist/locale/cs.min.js.map +1 -0
  178. package/dist/locale/cs.min.mjs +3 -0
  179. package/dist/locale/cs.min.mjs.map +1 -0
  180. package/dist/locale/cs.mjs +188 -0
  181. package/dist/locale/da.js +193 -0
  182. package/dist/locale/da.min.js +3 -0
  183. package/dist/locale/da.min.js.map +1 -0
  184. package/dist/locale/da.min.mjs +3 -0
  185. package/dist/locale/da.min.mjs.map +1 -0
  186. package/dist/locale/da.mjs +186 -0
  187. package/dist/locale/de.js +195 -0
  188. package/dist/locale/de.min.js +3 -0
  189. package/dist/locale/de.min.js.map +1 -0
  190. package/dist/locale/de.min.mjs +3 -0
  191. package/dist/locale/de.min.mjs.map +1 -0
  192. package/dist/locale/de.mjs +188 -0
  193. package/dist/locale/el.js +193 -0
  194. package/dist/locale/el.min.js +3 -0
  195. package/dist/locale/el.min.js.map +1 -0
  196. package/dist/locale/el.min.mjs +3 -0
  197. package/dist/locale/el.min.mjs.map +1 -0
  198. package/dist/locale/el.mjs +186 -0
  199. package/dist/locale/en.js +193 -0
  200. package/dist/locale/en.min.js +3 -0
  201. package/dist/locale/en.min.js.map +1 -0
  202. package/dist/locale/en.min.mjs +3 -0
  203. package/dist/locale/en.min.mjs.map +1 -0
  204. package/dist/locale/en.mjs +186 -0
  205. package/dist/locale/eo.js +193 -0
  206. package/dist/locale/eo.min.js +3 -0
  207. package/dist/locale/eo.min.js.map +1 -0
  208. package/dist/locale/eo.min.mjs +3 -0
  209. package/dist/locale/eo.min.mjs.map +1 -0
  210. package/dist/locale/eo.mjs +186 -0
  211. package/dist/locale/es.js +193 -0
  212. package/dist/locale/es.min.js +3 -0
  213. package/dist/locale/es.min.js.map +1 -0
  214. package/dist/locale/es.min.mjs +3 -0
  215. package/dist/locale/es.min.mjs.map +1 -0
  216. package/dist/locale/es.mjs +186 -0
  217. package/dist/locale/et.js +193 -0
  218. package/dist/locale/et.min.js +3 -0
  219. package/dist/locale/et.min.js.map +1 -0
  220. package/dist/locale/et.min.mjs +3 -0
  221. package/dist/locale/et.min.mjs.map +1 -0
  222. package/dist/locale/et.mjs +186 -0
  223. package/dist/locale/eu.js +193 -0
  224. package/dist/locale/eu.min.js +3 -0
  225. package/dist/locale/eu.min.js.map +1 -0
  226. package/dist/locale/eu.min.mjs +3 -0
  227. package/dist/locale/eu.min.mjs.map +1 -0
  228. package/dist/locale/eu.mjs +186 -0
  229. package/dist/locale/fa.js +193 -0
  230. package/dist/locale/fa.min.js +3 -0
  231. package/dist/locale/fa.min.js.map +1 -0
  232. package/dist/locale/fa.min.mjs +3 -0
  233. package/dist/locale/fa.min.mjs.map +1 -0
  234. package/dist/locale/fa.mjs +186 -0
  235. package/dist/locale/fi.js +193 -0
  236. package/dist/locale/fi.min.js +3 -0
  237. package/dist/locale/fi.min.js.map +1 -0
  238. package/dist/locale/fi.min.mjs +3 -0
  239. package/dist/locale/fi.min.mjs.map +1 -0
  240. package/dist/locale/fi.mjs +186 -0
  241. package/dist/locale/fr.js +193 -0
  242. package/dist/locale/fr.min.js +3 -0
  243. package/dist/locale/fr.min.js.map +1 -0
  244. package/dist/locale/fr.min.mjs +3 -0
  245. package/dist/locale/fr.min.mjs.map +1 -0
  246. package/dist/locale/fr.mjs +186 -0
  247. package/dist/locale/he.js +193 -0
  248. package/dist/locale/he.min.js +3 -0
  249. package/dist/locale/he.min.js.map +1 -0
  250. package/dist/locale/he.min.mjs +3 -0
  251. package/dist/locale/he.min.mjs.map +1 -0
  252. package/dist/locale/he.mjs +186 -0
  253. package/dist/locale/hi.js +193 -0
  254. package/dist/locale/hi.min.js +3 -0
  255. package/dist/locale/hi.min.js.map +1 -0
  256. package/dist/locale/hi.min.mjs +3 -0
  257. package/dist/locale/hi.min.mjs.map +1 -0
  258. package/dist/locale/hi.mjs +186 -0
  259. package/dist/locale/hr.js +193 -0
  260. package/dist/locale/hr.min.js +3 -0
  261. package/dist/locale/hr.min.js.map +1 -0
  262. package/dist/locale/hr.min.mjs +3 -0
  263. package/dist/locale/hr.min.mjs.map +1 -0
  264. package/dist/locale/hr.mjs +186 -0
  265. package/dist/locale/hu.js +193 -0
  266. package/dist/locale/hu.min.js +3 -0
  267. package/dist/locale/hu.min.js.map +1 -0
  268. package/dist/locale/hu.min.mjs +3 -0
  269. package/dist/locale/hu.min.mjs.map +1 -0
  270. package/dist/locale/hu.mjs +186 -0
  271. package/dist/locale/hy-am.js +193 -0
  272. package/dist/locale/hy-am.min.js +3 -0
  273. package/dist/locale/hy-am.min.js.map +1 -0
  274. package/dist/locale/hy-am.min.mjs +3 -0
  275. package/dist/locale/hy-am.min.mjs.map +1 -0
  276. package/dist/locale/hy-am.mjs +186 -0
  277. package/dist/locale/id.js +193 -0
  278. package/dist/locale/id.min.js +3 -0
  279. package/dist/locale/id.min.js.map +1 -0
  280. package/dist/locale/id.min.mjs +3 -0
  281. package/dist/locale/id.min.mjs.map +1 -0
  282. package/dist/locale/id.mjs +186 -0
  283. package/dist/locale/it.js +193 -0
  284. package/dist/locale/it.min.js +3 -0
  285. package/dist/locale/it.min.js.map +1 -0
  286. package/dist/locale/it.min.mjs +3 -0
  287. package/dist/locale/it.min.mjs.map +1 -0
  288. package/dist/locale/it.mjs +186 -0
  289. package/dist/locale/ja.js +193 -0
  290. package/dist/locale/ja.min.js +3 -0
  291. package/dist/locale/ja.min.js.map +1 -0
  292. package/dist/locale/ja.min.mjs +3 -0
  293. package/dist/locale/ja.min.mjs.map +1 -0
  294. package/dist/locale/ja.mjs +186 -0
  295. package/dist/locale/kk.js +193 -0
  296. package/dist/locale/kk.min.js +3 -0
  297. package/dist/locale/kk.min.js.map +1 -0
  298. package/dist/locale/kk.min.mjs +3 -0
  299. package/dist/locale/kk.min.mjs.map +1 -0
  300. package/dist/locale/kk.mjs +186 -0
  301. package/dist/locale/km.js +193 -0
  302. package/dist/locale/km.min.js +3 -0
  303. package/dist/locale/km.min.js.map +1 -0
  304. package/dist/locale/km.min.mjs +3 -0
  305. package/dist/locale/km.min.mjs.map +1 -0
  306. package/dist/locale/km.mjs +186 -0
  307. package/dist/locale/ko.js +193 -0
  308. package/dist/locale/ko.min.js +3 -0
  309. package/dist/locale/ko.min.js.map +1 -0
  310. package/dist/locale/ko.min.mjs +3 -0
  311. package/dist/locale/ko.min.mjs.map +1 -0
  312. package/dist/locale/ko.mjs +186 -0
  313. package/dist/locale/ku.js +193 -0
  314. package/dist/locale/ku.min.js +3 -0
  315. package/dist/locale/ku.min.js.map +1 -0
  316. package/dist/locale/ku.min.mjs +3 -0
  317. package/dist/locale/ku.min.mjs.map +1 -0
  318. package/dist/locale/ku.mjs +186 -0
  319. package/dist/locale/ky.js +193 -0
  320. package/dist/locale/ky.min.js +3 -0
  321. package/dist/locale/ky.min.js.map +1 -0
  322. package/dist/locale/ky.min.mjs +3 -0
  323. package/dist/locale/ky.min.mjs.map +1 -0
  324. package/dist/locale/ky.mjs +186 -0
  325. package/dist/locale/lo.js +193 -0
  326. package/dist/locale/lo.min.js +3 -0
  327. package/dist/locale/lo.min.js.map +1 -0
  328. package/dist/locale/lo.min.mjs +3 -0
  329. package/dist/locale/lo.min.mjs.map +1 -0
  330. package/dist/locale/lo.mjs +186 -0
  331. package/dist/locale/lt.js +193 -0
  332. package/dist/locale/lt.min.js +3 -0
  333. package/dist/locale/lt.min.js.map +1 -0
  334. package/dist/locale/lt.min.mjs +3 -0
  335. package/dist/locale/lt.min.mjs.map +1 -0
  336. package/dist/locale/lt.mjs +186 -0
  337. package/dist/locale/lv.js +193 -0
  338. package/dist/locale/lv.min.js +3 -0
  339. package/dist/locale/lv.min.js.map +1 -0
  340. package/dist/locale/lv.min.mjs +3 -0
  341. package/dist/locale/lv.min.mjs.map +1 -0
  342. package/dist/locale/lv.mjs +186 -0
  343. package/dist/locale/mg.js +193 -0
  344. package/dist/locale/mg.min.js +3 -0
  345. package/dist/locale/mg.min.js.map +1 -0
  346. package/dist/locale/mg.min.mjs +3 -0
  347. package/dist/locale/mg.min.mjs.map +1 -0
  348. package/dist/locale/mg.mjs +186 -0
  349. package/dist/locale/mn.js +193 -0
  350. package/dist/locale/mn.min.js +3 -0
  351. package/dist/locale/mn.min.js.map +1 -0
  352. package/dist/locale/mn.min.mjs +3 -0
  353. package/dist/locale/mn.min.mjs.map +1 -0
  354. package/dist/locale/mn.mjs +186 -0
  355. package/dist/locale/ms.js +195 -0
  356. package/dist/locale/ms.min.js +3 -0
  357. package/dist/locale/ms.min.js.map +1 -0
  358. package/dist/locale/ms.min.mjs +3 -0
  359. package/dist/locale/ms.min.mjs.map +1 -0
  360. package/dist/locale/ms.mjs +188 -0
  361. package/dist/locale/my.js +193 -0
  362. package/dist/locale/my.min.js +3 -0
  363. package/dist/locale/my.min.js.map +1 -0
  364. package/dist/locale/my.min.mjs +3 -0
  365. package/dist/locale/my.min.mjs.map +1 -0
  366. package/dist/locale/my.mjs +186 -0
  367. package/dist/locale/nb-no.js +193 -0
  368. package/dist/locale/nb-no.min.js +3 -0
  369. package/dist/locale/nb-no.min.js.map +1 -0
  370. package/dist/locale/nb-no.min.mjs +3 -0
  371. package/dist/locale/nb-no.min.mjs.map +1 -0
  372. package/dist/locale/nb-no.mjs +186 -0
  373. package/dist/locale/nl.js +193 -0
  374. package/dist/locale/nl.min.js +3 -0
  375. package/dist/locale/nl.min.js.map +1 -0
  376. package/dist/locale/nl.min.mjs +3 -0
  377. package/dist/locale/nl.min.mjs.map +1 -0
  378. package/dist/locale/nl.mjs +186 -0
  379. package/dist/locale/no.js +193 -0
  380. package/dist/locale/no.min.js +3 -0
  381. package/dist/locale/no.min.js.map +1 -0
  382. package/dist/locale/no.min.mjs +3 -0
  383. package/dist/locale/no.min.mjs.map +1 -0
  384. package/dist/locale/no.mjs +186 -0
  385. package/dist/locale/pa.js +193 -0
  386. package/dist/locale/pa.min.js +3 -0
  387. package/dist/locale/pa.min.js.map +1 -0
  388. package/dist/locale/pa.min.mjs +3 -0
  389. package/dist/locale/pa.min.mjs.map +1 -0
  390. package/dist/locale/pa.mjs +186 -0
  391. package/dist/locale/pl.js +193 -0
  392. package/dist/locale/pl.min.js +3 -0
  393. package/dist/locale/pl.min.js.map +1 -0
  394. package/dist/locale/pl.min.mjs +3 -0
  395. package/dist/locale/pl.min.mjs.map +1 -0
  396. package/dist/locale/pl.mjs +186 -0
  397. package/dist/locale/pt-br.js +193 -0
  398. package/dist/locale/pt-br.min.js +3 -0
  399. package/dist/locale/pt-br.min.js.map +1 -0
  400. package/dist/locale/pt-br.min.mjs +3 -0
  401. package/dist/locale/pt-br.min.mjs.map +1 -0
  402. package/dist/locale/pt-br.mjs +186 -0
  403. package/dist/locale/pt.js +193 -0
  404. package/dist/locale/pt.min.js +3 -0
  405. package/dist/locale/pt.min.js.map +1 -0
  406. package/dist/locale/pt.min.mjs +3 -0
  407. package/dist/locale/pt.min.mjs.map +1 -0
  408. package/dist/locale/pt.mjs +186 -0
  409. package/dist/locale/ro.js +193 -0
  410. package/dist/locale/ro.min.js +3 -0
  411. package/dist/locale/ro.min.js.map +1 -0
  412. package/dist/locale/ro.min.mjs +3 -0
  413. package/dist/locale/ro.min.mjs.map +1 -0
  414. package/dist/locale/ro.mjs +186 -0
  415. package/dist/locale/ru.js +193 -0
  416. package/dist/locale/ru.min.js +3 -0
  417. package/dist/locale/ru.min.js.map +1 -0
  418. package/dist/locale/ru.min.mjs +3 -0
  419. package/dist/locale/ru.min.mjs.map +1 -0
  420. package/dist/locale/ru.mjs +186 -0
  421. package/dist/locale/sk.js +195 -0
  422. package/dist/locale/sk.min.js +3 -0
  423. package/dist/locale/sk.min.js.map +1 -0
  424. package/dist/locale/sk.min.mjs +3 -0
  425. package/dist/locale/sk.min.mjs.map +1 -0
  426. package/dist/locale/sk.mjs +188 -0
  427. package/dist/locale/sl.js +193 -0
  428. package/dist/locale/sl.min.js +3 -0
  429. package/dist/locale/sl.min.js.map +1 -0
  430. package/dist/locale/sl.min.mjs +3 -0
  431. package/dist/locale/sl.min.mjs.map +1 -0
  432. package/dist/locale/sl.mjs +186 -0
  433. package/dist/locale/sr.js +193 -0
  434. package/dist/locale/sr.min.js +3 -0
  435. package/dist/locale/sr.min.js.map +1 -0
  436. package/dist/locale/sr.min.mjs +3 -0
  437. package/dist/locale/sr.min.mjs.map +1 -0
  438. package/dist/locale/sr.mjs +186 -0
  439. package/dist/locale/sv.js +193 -0
  440. package/dist/locale/sv.min.js +3 -0
  441. package/dist/locale/sv.min.js.map +1 -0
  442. package/dist/locale/sv.min.mjs +3 -0
  443. package/dist/locale/sv.min.mjs.map +1 -0
  444. package/dist/locale/sv.mjs +186 -0
  445. package/dist/locale/sw.js +193 -0
  446. package/dist/locale/sw.min.js +3 -0
  447. package/dist/locale/sw.min.js.map +1 -0
  448. package/dist/locale/sw.min.mjs +3 -0
  449. package/dist/locale/sw.min.mjs.map +1 -0
  450. package/dist/locale/sw.mjs +186 -0
  451. package/dist/locale/ta.js +193 -0
  452. package/dist/locale/ta.min.js +3 -0
  453. package/dist/locale/ta.min.js.map +1 -0
  454. package/dist/locale/ta.min.mjs +3 -0
  455. package/dist/locale/ta.min.mjs.map +1 -0
  456. package/dist/locale/ta.mjs +186 -0
  457. package/dist/locale/te.js +193 -0
  458. package/dist/locale/te.min.js +3 -0
  459. package/dist/locale/te.min.js.map +1 -0
  460. package/dist/locale/te.min.mjs +3 -0
  461. package/dist/locale/te.min.mjs.map +1 -0
  462. package/dist/locale/te.mjs +186 -0
  463. package/dist/locale/th.js +193 -0
  464. package/dist/locale/th.min.js +3 -0
  465. package/dist/locale/th.min.js.map +1 -0
  466. package/dist/locale/th.min.mjs +3 -0
  467. package/dist/locale/th.min.mjs.map +1 -0
  468. package/dist/locale/th.mjs +186 -0
  469. package/dist/locale/tk.js +193 -0
  470. package/dist/locale/tk.min.js +3 -0
  471. package/dist/locale/tk.min.js.map +1 -0
  472. package/dist/locale/tk.min.mjs +3 -0
  473. package/dist/locale/tk.min.mjs.map +1 -0
  474. package/dist/locale/tk.mjs +186 -0
  475. package/dist/locale/tr.js +193 -0
  476. package/dist/locale/tr.min.js +3 -0
  477. package/dist/locale/tr.min.js.map +1 -0
  478. package/dist/locale/tr.min.mjs +3 -0
  479. package/dist/locale/tr.min.mjs.map +1 -0
  480. package/dist/locale/tr.mjs +186 -0
  481. package/dist/locale/ug-cn.js +193 -0
  482. package/dist/locale/ug-cn.min.js +3 -0
  483. package/dist/locale/ug-cn.min.js.map +1 -0
  484. package/dist/locale/ug-cn.min.mjs +3 -0
  485. package/dist/locale/ug-cn.min.mjs.map +1 -0
  486. package/dist/locale/ug-cn.mjs +186 -0
  487. package/dist/locale/uk.js +193 -0
  488. package/dist/locale/uk.min.js +3 -0
  489. package/dist/locale/uk.min.js.map +1 -0
  490. package/dist/locale/uk.min.mjs +3 -0
  491. package/dist/locale/uk.min.mjs.map +1 -0
  492. package/dist/locale/uk.mjs +186 -0
  493. package/dist/locale/uz-uz.js +193 -0
  494. package/dist/locale/uz-uz.min.js +3 -0
  495. package/dist/locale/uz-uz.min.js.map +1 -0
  496. package/dist/locale/uz-uz.min.mjs +3 -0
  497. package/dist/locale/uz-uz.min.mjs.map +1 -0
  498. package/dist/locale/uz-uz.mjs +186 -0
  499. package/dist/locale/vi.js +193 -0
  500. package/dist/locale/vi.min.js +3 -0
  501. package/dist/locale/vi.min.js.map +1 -0
  502. package/dist/locale/vi.min.mjs +3 -0
  503. package/dist/locale/vi.min.mjs.map +1 -0
  504. package/dist/locale/vi.mjs +186 -0
  505. package/dist/locale/zh-cn.js +193 -0
  506. package/dist/locale/zh-cn.min.js +3 -0
  507. package/dist/locale/zh-cn.min.js.map +1 -0
  508. package/dist/locale/zh-cn.min.mjs +3 -0
  509. package/dist/locale/zh-cn.min.mjs.map +1 -0
  510. package/dist/locale/zh-cn.mjs +186 -0
  511. package/dist/locale/zh-hk.js +193 -0
  512. package/dist/locale/zh-hk.min.js +3 -0
  513. package/dist/locale/zh-hk.min.js.map +1 -0
  514. package/dist/locale/zh-hk.min.mjs +3 -0
  515. package/dist/locale/zh-hk.min.mjs.map +1 -0
  516. package/dist/locale/zh-hk.mjs +186 -0
  517. package/dist/locale/zh-mo.js +193 -0
  518. package/dist/locale/zh-mo.min.js +3 -0
  519. package/dist/locale/zh-mo.min.js.map +1 -0
  520. package/dist/locale/zh-mo.min.mjs +3 -0
  521. package/dist/locale/zh-mo.min.mjs.map +1 -0
  522. package/dist/locale/zh-mo.mjs +186 -0
  523. package/dist/locale/zh-tw.js +193 -0
  524. package/dist/locale/zh-tw.min.js +3 -0
  525. package/dist/locale/zh-tw.min.js.map +1 -0
  526. package/dist/locale/zh-tw.min.mjs +3 -0
  527. package/dist/locale/zh-tw.min.mjs.map +1 -0
  528. package/dist/locale/zh-tw.mjs +186 -0
  529. package/dist/style.css +1 -1
  530. package/dist/test/demo.docx +0 -0
  531. package/dist/test/demo.et +0 -0
  532. package/dist/test/demo.ofd +0 -0
  533. package/dist/test/demo.pdf +0 -0
  534. package/dist/test/test.ofd +0 -0
  535. package/dist/test/unzip.ofd +0 -0
  536. package/dist/test/zip.ofd +0 -0
  537. package/dist/types/auto-imports.d.ts +9 -0
  538. package/dist/types/components.d.ts +55 -0
  539. package/dist/zhui-plus.cjs.js +1 -0
  540. package/dist/zhui-plus.es.js +2 -0
  541. package/dist/zhui.svg +1 -0
  542. package/package.json +90 -4
  543. package/packages/components/AI/index.ts +10 -0
  544. package/packages/components/AI/src/zh-aiChat.vue +841 -0
  545. package/packages/components/badge/__tests__/badge.test.ts +38 -0
  546. package/packages/components/badge/index.ts +10 -0
  547. package/packages/components/badge/src/zh-badge.vue +86 -0
  548. package/packages/components/badge/style.scss +1 -0
  549. package/packages/components/button/__tests__/button.test.ts +94 -0
  550. package/packages/components/button/__tests__/buttonGroup.test.ts +46 -0
  551. package/packages/components/button/index.ts +11 -0
  552. package/packages/components/button/src/zh-button-group.vue +50 -0
  553. package/packages/components/button/src/zh-button.vue +152 -0
  554. package/packages/components/button/style/index.css +140 -0
  555. package/packages/components/charts/geo.json +11147 -0
  556. package/packages/components/charts/index.ts +35 -0
  557. package/packages/components/charts/src/zh-barChart.vue +97 -0
  558. package/packages/components/charts/src/zh-baseChart.vue +196 -0
  559. package/packages/components/charts/src/zh-lineBarChart.vue +113 -0
  560. package/packages/components/charts/src/zh-lineChart.vue +93 -0
  561. package/packages/components/charts/src/zh-mapChart.vue +214 -0
  562. package/packages/components/charts/src/zh-pictorialBar.vue +72 -0
  563. package/packages/components/charts/src/zh-pieChart.vue +67 -0
  564. package/packages/components/charts/src/zh-radarChart.vue +131 -0
  565. package/packages/components/charts/src/zh-scatterChart.vue +152 -0
  566. package/packages/components/chat/index.ts +10 -0
  567. package/packages/components/chat/src/zh-chat.vue +889 -0
  568. package/packages/components/container/index.ts +18 -0
  569. package/packages/components/container/src/zh-aside.vue +34 -0
  570. package/packages/components/container/src/zh-container.vue +45 -0
  571. package/packages/components/container/src/zh-footer.vue +33 -0
  572. package/packages/components/container/src/zh-header.vue +34 -0
  573. package/packages/components/container/src/zh-main.vue +26 -0
  574. package/packages/components/directive/focus.ts +14 -0
  575. package/packages/components/directive/idCard.ts +12 -0
  576. package/packages/components/directive/index.ts +19 -0
  577. package/packages/components/directive/number.ts +10 -0
  578. package/packages/components/directive/permission.ts +57 -0
  579. package/packages/components/directive/phone.ts +12 -0
  580. package/packages/components/drawer/index.ts +10 -0
  581. package/packages/components/drawer/src/zh-drawer.vue +78 -0
  582. package/packages/components/drawer/style/animation.scss +35 -0
  583. package/packages/components/drawer/style/index.scss +52 -0
  584. package/packages/components/drawer/style/media.scss +6 -0
  585. package/packages/components/fileViewer/index.ts +9 -0
  586. package/packages/components/fileViewer/src/liteofd/annotLayer.ts +203 -0
  587. package/packages/components/fileViewer/src/liteofd/asn1js/LICENSE +15 -0
  588. package/packages/components/fileViewer/src/liteofd/asn1js/README.md +108 -0
  589. package/packages/components/fileViewer/src/liteofd/asn1js/asn1.js +627 -0
  590. package/packages/components/fileViewer/src/liteofd/asn1js/base64.js +103 -0
  591. package/packages/components/fileViewer/src/liteofd/asn1js/defs.js +138 -0
  592. package/packages/components/fileViewer/src/liteofd/asn1js/dumpASN1.js +79 -0
  593. package/packages/components/fileViewer/src/liteofd/asn1js/hex.js +69 -0
  594. package/packages/components/fileViewer/src/liteofd/asn1js/int10.js +106 -0
  595. package/packages/components/fileViewer/src/liteofd/asn1js/oids.js +2725 -0
  596. package/packages/components/fileViewer/src/liteofd/asn1js/rfcdef.js +10377 -0
  597. package/packages/components/fileViewer/src/liteofd/attrType.ts +173 -0
  598. package/packages/components/fileViewer/src/liteofd/contentLayer.ts +203 -0
  599. package/packages/components/fileViewer/src/liteofd/elements/AnnotationPathSvg.ts +122 -0
  600. package/packages/components/fileViewer/src/liteofd/elements/BaseSvg.ts +6 -0
  601. package/packages/components/fileViewer/src/liteofd/elements/ImageSvg.ts +212 -0
  602. package/packages/components/fileViewer/src/liteofd/elements/PathSvg.ts +460 -0
  603. package/packages/components/fileViewer/src/liteofd/elements/SignatureElement.ts +231 -0
  604. package/packages/components/fileViewer/src/liteofd/elements/TextSvg.ts +235 -0
  605. package/packages/components/fileViewer/src/liteofd/elements/ofdAnnotationElement.ts +133 -0
  606. package/packages/components/fileViewer/src/liteofd/elements/ofdPageContainer.ts +183 -0
  607. package/packages/components/fileViewer/src/liteofd/elements/ofdPageRender.ts +71 -0
  608. package/packages/components/fileViewer/src/liteofd/elements/signObject.json +10084 -0
  609. package/packages/components/fileViewer/src/liteofd/elements/signature.json +381 -0
  610. package/packages/components/fileViewer/src/liteofd/font/arithmetic_decoder.js +182 -0
  611. package/packages/components/fileViewer/src/liteofd/font/ascii_85_stream.js +98 -0
  612. package/packages/components/fileViewer/src/liteofd/font/ascii_hex_stream.js +79 -0
  613. package/packages/components/fileViewer/src/liteofd/font/base_stream.js +110 -0
  614. package/packages/components/fileViewer/src/liteofd/font/bidi.js +440 -0
  615. package/packages/components/fileViewer/src/liteofd/font/binary_cmap.js +326 -0
  616. package/packages/components/fileViewer/src/liteofd/font/calibri_factors.js +309 -0
  617. package/packages/components/fileViewer/src/liteofd/font/ccitt.js +1059 -0
  618. package/packages/components/fileViewer/src/liteofd/font/ccitt_stream.js +60 -0
  619. package/packages/components/fileViewer/src/liteofd/font/cff_font.js +139 -0
  620. package/packages/components/fileViewer/src/liteofd/font/cff_parser.js +1940 -0
  621. package/packages/components/fileViewer/src/liteofd/font/charsets.js +119 -0
  622. package/packages/components/fileViewer/src/liteofd/font/chunked_stream.js +94 -0
  623. package/packages/components/fileViewer/src/liteofd/font/cmap.js +726 -0
  624. package/packages/components/fileViewer/src/liteofd/font/colorspace.js +1336 -0
  625. package/packages/components/fileViewer/src/liteofd/font/core_utils.js +636 -0
  626. package/packages/components/fileViewer/src/liteofd/font/decode_stream.js +177 -0
  627. package/packages/components/fileViewer/src/liteofd/font/differences.js +906 -0
  628. package/packages/components/fileViewer/src/liteofd/font/encodings.js +301 -0
  629. package/packages/components/fileViewer/src/liteofd/font/flate_stream.js +413 -0
  630. package/packages/components/fileViewer/src/liteofd/font/font_loader.js +455 -0
  631. package/packages/components/fileViewer/src/liteofd/font/font_renderer.js +900 -0
  632. package/packages/components/fileViewer/src/liteofd/font/font_substitutions.js +553 -0
  633. package/packages/components/fileViewer/src/liteofd/font/fonts copy.js +3391 -0
  634. package/packages/components/fileViewer/src/liteofd/font/fonts.js +3585 -0
  635. package/packages/components/fileViewer/src/liteofd/font/fonts_utils.js +178 -0
  636. package/packages/components/fileViewer/src/liteofd/font/function.js +1241 -0
  637. package/packages/components/fileViewer/src/liteofd/font/glyf.js +701 -0
  638. package/packages/components/fileViewer/src/liteofd/font/glyphlist.js +4557 -0
  639. package/packages/components/fileViewer/src/liteofd/font/helvetica_factors.js +352 -0
  640. package/packages/components/fileViewer/src/liteofd/font/image.js +986 -0
  641. package/packages/components/fileViewer/src/liteofd/font/image_resizer.js +398 -0
  642. package/packages/components/fileViewer/src/liteofd/font/image_utils.js +286 -0
  643. package/packages/components/fileViewer/src/liteofd/font/jbig2_stream.js +74 -0
  644. package/packages/components/fileViewer/src/liteofd/font/jpeg_stream.js +106 -0
  645. package/packages/components/fileViewer/src/liteofd/font/jpg.js +1590 -0
  646. package/packages/components/fileViewer/src/liteofd/font/jpx.js +2349 -0
  647. package/packages/components/fileViewer/src/liteofd/font/jpx_stream.js +87 -0
  648. package/packages/components/fileViewer/src/liteofd/font/liberationsans_widths.js +429 -0
  649. package/packages/components/fileViewer/src/liteofd/font/lzw_stream.js +150 -0
  650. package/packages/components/fileViewer/src/liteofd/font/metrics.d.ts +1 -0
  651. package/packages/components/fileViewer/src/liteofd/font/metrics.js +3057 -0
  652. package/packages/components/fileViewer/src/liteofd/font/murmurhash3.js +135 -0
  653. package/packages/components/fileViewer/src/liteofd/font/myriadpro_factors.js +291 -0
  654. package/packages/components/fileViewer/src/liteofd/font/ofd_stream.js +402 -0
  655. package/packages/components/fileViewer/src/liteofd/font/opentype_file_builder.js +154 -0
  656. package/packages/components/fileViewer/src/liteofd/font/parser.js +1409 -0
  657. package/packages/components/fileViewer/src/liteofd/font/pattern.js +1005 -0
  658. package/packages/components/fileViewer/src/liteofd/font/predictor_stream.js +234 -0
  659. package/packages/components/fileViewer/src/liteofd/font/primitives.js +354 -0
  660. package/packages/components/fileViewer/src/liteofd/font/properties.json +2110 -0
  661. package/packages/components/fileViewer/src/liteofd/font/ps_parser.js +268 -0
  662. package/packages/components/fileViewer/src/liteofd/font/run_length_stream.js +61 -0
  663. package/packages/components/fileViewer/src/liteofd/font/segoeui_factors.js +308 -0
  664. package/packages/components/fileViewer/src/liteofd/font/standard_fonts.js +915 -0
  665. package/packages/components/fileViewer/src/liteofd/font/stream.js +99 -0
  666. package/packages/components/fileViewer/src/liteofd/font/to_unicode_map.js +111 -0
  667. package/packages/components/fileViewer/src/liteofd/font/translatedFont.js +3125 -0
  668. package/packages/components/fileViewer/src/liteofd/font/type1_font.js +443 -0
  669. package/packages/components/fileViewer/src/liteofd/font/type1_parser.js +804 -0
  670. package/packages/components/fileViewer/src/liteofd/font/unicode.js +274 -0
  671. package/packages/components/fileViewer/src/liteofd/font/util.js +1159 -0
  672. package/packages/components/fileViewer/src/liteofd/font/xfa_fonts.js +296 -0
  673. package/packages/components/fileViewer/src/liteofd/jbig2/arithmetic_decoder.js +183 -0
  674. package/packages/components/fileViewer/src/liteofd/jbig2/ccitt.js +1070 -0
  675. package/packages/components/fileViewer/src/liteofd/jbig2/core_utils.js +180 -0
  676. package/packages/components/fileViewer/src/liteofd/jbig2/is_node.js +27 -0
  677. package/packages/components/fileViewer/src/liteofd/jbig2/jbig2.js +2589 -0
  678. package/packages/components/fileViewer/src/liteofd/jbig2/jbig2_stream.js +81 -0
  679. package/packages/components/fileViewer/src/liteofd/jbig2/primitives.js +371 -0
  680. package/packages/components/fileViewer/src/liteofd/jbig2/stream.js +1348 -0
  681. package/packages/components/fileViewer/src/liteofd/jbig2/util.js +970 -0
  682. package/packages/components/fileViewer/src/liteofd/layer.ts +12 -0
  683. package/packages/components/fileViewer/src/liteofd/liteOfd.ts +185 -0
  684. package/packages/components/fileViewer/src/liteofd/ofdActions.ts +29 -0
  685. package/packages/components/fileViewer/src/liteofd/ofdCanvas.ts +19 -0
  686. package/packages/components/fileViewer/src/liteofd/ofdData.ts +28 -0
  687. package/packages/components/fileViewer/src/liteofd/ofdDocument.ts +109 -0
  688. package/packages/components/fileViewer/src/liteofd/ofdFont.ts +425 -0
  689. package/packages/components/fileViewer/src/liteofd/ofdRender.ts +259 -0
  690. package/packages/components/fileViewer/src/liteofd/ofdWriter.ts +142 -0
  691. package/packages/components/fileViewer/src/liteofd/ofdtools.ts +43 -0
  692. package/packages/components/fileViewer/src/liteofd/parser.ts +499 -0
  693. package/packages/components/fileViewer/src/liteofd/promiseCapability.ts +47 -0
  694. package/packages/components/fileViewer/src/liteofd/utils/commonFont.ts +15 -0
  695. package/packages/components/fileViewer/src/liteofd/utils/elementUtils.ts +362 -0
  696. package/packages/components/fileViewer/src/liteofd/utils/jsonToXml.ts +95 -0
  697. package/packages/components/fileViewer/src/liteofd/utils/ofdUtils.ts +301 -0
  698. package/packages/components/fileViewer/src/liteofd/utils/signatureUtil.ts +246 -0
  699. package/packages/components/fileViewer/src/liteofd/utils/sm3.ts +235 -0
  700. package/packages/components/fileViewer/src/liteofd/utils/utils.ts +489 -0
  701. package/packages/components/fileViewer/src/liteofd/utils/verify_signature_util.ts +41 -0
  702. package/packages/components/fileViewer/src/ofd/CircleLoading.vue +64 -0
  703. package/packages/components/fileViewer/src/ofd/OfdPreview.vue +456 -0
  704. package/packages/components/fileViewer/src/ofd/OfdViewer.vue +211 -0
  705. package/packages/components/fileViewer/src/ofd/PageIndicator.vue +88 -0
  706. package/packages/components/fileViewer/src/ofd/RatioIndicator.vue +271 -0
  707. package/packages/components/fileViewer/src/ofd/ToolTip.vue +81 -0
  708. package/packages/components/fileViewer/src/zh-fileViewer.vue +426 -0
  709. package/packages/components/form/index.ts +11 -0
  710. package/packages/components/form/src/zh-form-item.vue +299 -0
  711. package/packages/components/form/src/zh-form.vue +90 -0
  712. package/packages/components/hideNumber/index.ts +9 -0
  713. package/packages/components/hideNumber/src/zh-hide-number.vue +37 -0
  714. package/packages/components/icon/index.ts +10 -0
  715. package/packages/components/icon/src/zh-icon.vue +32 -0
  716. package/packages/components/image/index.ts +9 -0
  717. package/packages/components/image/src/zh-image.vue +245 -0
  718. package/packages/components/index.ts +112 -0
  719. package/packages/components/input/index.ts +10 -0
  720. package/packages/components/input/src/input.com.ts +30 -0
  721. package/packages/components/input/src/input.type.ts +1 -0
  722. package/packages/components/input/src/zh-input.vue +92 -0
  723. package/packages/components/input/style/index.scss +30 -0
  724. package/packages/components/layout/index.ts +12 -0
  725. package/packages/components/layout/src/zh-col.tsx +81 -0
  726. package/packages/components/layout/src/zh-row.tsx +58 -0
  727. package/packages/components/layout/style/row.scss +6 -0
  728. package/packages/components/map/index.ts +18 -0
  729. package/packages/components/map/src/zh-amap.vue +999 -0
  730. package/packages/components/map/src/zh-bmap.vue +1578 -0
  731. package/packages/components/map/src/zh-omap.vue +1522 -0
  732. package/packages/components/map/src/zh-smap.vue +1555 -0
  733. package/packages/components/map/src/zh-tmap.vue +1058 -0
  734. package/packages/components/message/index.ts +8 -0
  735. package/packages/components/message/src/data.com.ts +61 -0
  736. package/packages/components/message/src/message-icon.vue +60 -0
  737. package/packages/components/message/src/message.ts +89 -0
  738. package/packages/components/message/src/message.type.ts +40 -0
  739. package/packages/components/message/src/zh-message.vue +133 -0
  740. package/packages/components/message-box/index.ts +12 -0
  741. package/packages/components/message-box/src/messageBox.help.ts +40 -0
  742. package/packages/components/message-box/src/messageBox.ts +126 -0
  743. package/packages/components/message-box/src/zh-message-box.vue +94 -0
  744. package/packages/components/message-box/style/index.css +29 -0
  745. package/packages/components/noData/index.ts +9 -0
  746. package/packages/components/noData/src/zh-no-data.vue +42 -0
  747. package/packages/components/operationColumn/index.ts +9 -0
  748. package/packages/components/operationColumn/src/zh-operationColumn.vue +113 -0
  749. package/packages/components/provider/index.ts +11 -0
  750. package/packages/components/provider/src/zh-authControl.vue +28 -0
  751. package/packages/components/provider/src/zh-authProvider.vue +36 -0
  752. package/packages/components/qrcode/index.ts +9 -0
  753. package/packages/components/qrcode/src/zh-qrcode.vue +271 -0
  754. package/packages/components/radio/index.ts +10 -0
  755. package/packages/components/radio/src/zh-radio.vue +86 -0
  756. package/packages/components/searchForm/index.ts +9 -0
  757. package/packages/components/searchForm/src/zh-search-form.vue +340 -0
  758. package/packages/components/signature/index.ts +10 -0
  759. package/packages/components/signature/src/zh-signature.vue +355 -0
  760. package/packages/components/switch/index.ts +10 -0
  761. package/packages/components/switch/src/zh-switch.vue +162 -0
  762. package/packages/components/table/index.ts +10 -0
  763. package/packages/components/table/src/types.ts +62 -0
  764. package/packages/components/table/src/zh-table.vue +220 -0
  765. package/packages/components/upload/index.ts +15 -0
  766. package/packages/components/upload/src/zh-cupload.vue +147 -0
  767. package/packages/components/upload/src/zh-upload.vue +258 -0
  768. package/packages/components/upload/src/zh-uploadCard.vue +176 -0
  769. package/packages/components/upload/src/zh-uploadDialog.vue +165 -0
  770. package/packages/components/videoPlayer/index.ts +12 -0
  771. package/packages/components/videoPlayer/src/PlayerManager.js +706 -0
  772. package/packages/components/videoPlayer/src/api.js +354 -0
  773. package/packages/components/videoPlayer/src/errorHandler.ts +39 -0
  774. package/packages/components/videoPlayer/src/resourceLoader.ts +68 -0
  775. package/packages/components/videoPlayer/src/useDahuaPlayer.ts +242 -0
  776. package/packages/components/videoPlayer/src/zh-dhPlayer.vue +119 -0
  777. package/packages/components/videoPlayer/src/zh-hlsPlayer.vue +575 -0
  778. package/packages/resolver/index.ts +324 -0
  779. package/packages/styles/_element.scss +324 -0
  780. package/packages/styles/_variable.scss +136 -0
  781. package/packages/styles/index.scss +3 -0
  782. package/packages/tokens/tokens.ts +2 -0
  783. package/packages/types/form.ts +205 -0
  784. package/packages/types/index.ts +4 -0
  785. package/packages/types/player.ts +80 -0
  786. package/packages/types/provider.ts +4 -0
  787. package/packages/types/searchForm.ts +24 -0
  788. package/packages/utils/common/__tests__/common.test.ts +12 -0
  789. package/packages/utils/common/common.ts +68 -0
  790. package/packages/utils/constant.ts +12 -0
  791. package/packages/utils/copy.ts +20 -0
  792. package/packages/utils/data.ts +62 -0
  793. package/packages/utils/echarts/echarts.ts +34 -0
  794. package/packages/utils/event.ts +37 -0
  795. package/packages/utils/hooks/__tests__/hooks.test.ts +24 -0
  796. package/packages/utils/hooks/data.ts +100 -0
  797. package/packages/utils/hooks/hooks.util.ts +39 -0
  798. package/packages/utils/hooks/index.ts +1 -0
  799. package/packages/utils/hooks/useBreakpoint.ts +89 -0
  800. package/packages/utils/hooks/useEcharts.ts +56 -0
  801. package/packages/utils/hooks/useEventListener.ts +57 -0
  802. package/packages/utils/hooks/useLegendProcessor.ts +92 -0
  803. package/packages/utils/hooks/usePermission.ts +22 -0
  804. package/packages/utils/hooks/useTimeout.ts +45 -0
  805. package/packages/utils/is.ts +79 -0
  806. package/packages/utils/utils.ts +136 -0
  807. package/packages/utils/vue/util-modal.vue +61 -0
  808. package/types/auto-imports.d.ts +9 -0
  809. package/types/component.d.ts +6 -0
  810. package/types/components.d.ts +131 -0
  811. package/types/defaults.d.ts +5 -0
  812. package/types/el-components.d.ts +23 -0
  813. package/types/global.d.ts +130 -0
  814. package/types/index.d.ts +11 -0
  815. package/types/zh-components.d.ts +23 -0
  816. package/types/zhui.d.ts +76 -0
  817. package/.idea/workspace.xml +0 -72
  818. package/README.md +0 -1
  819. package/dist/zh-ui.es.js +0 -56706
  820. package/dist/zh-ui.umd.js +0 -67
@@ -0,0 +1,3391 @@
1
+ /* Copyright 2012 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+
16
+ import {
17
+ assert,
18
+ bytesToString,
19
+ FONT_IDENTITY_MATRIX,
20
+ FormatError,
21
+ info,
22
+ shadow,
23
+ string32,
24
+ warn,
25
+ } from "./util.js";
26
+ import { CFFCompiler, CFFParser } from "./cff_parser.js";
27
+ import {
28
+ FontFlags,
29
+ MacStandardGlyphOrdering,
30
+ normalizeFontName,
31
+ recoverGlyphName,
32
+ SEAC_ANALYSIS_ENABLED,
33
+ } from "./fonts_utils.js";
34
+ import {
35
+ getCharUnicodeCategory,
36
+ getUnicodeForGlyph,
37
+ getUnicodeRangeFor,
38
+ mapSpecialUnicodeValues,
39
+ } from "./unicode.js";
40
+ import { getDingbatsGlyphsUnicode, getGlyphsUnicode } from "./glyphlist.js";
41
+ import {
42
+ getEncoding,
43
+ MacRomanEncoding,
44
+ StandardEncoding,
45
+ SymbolSetEncoding,
46
+ WinAnsiEncoding,
47
+ ZapfDingbatsEncoding,
48
+ } from "./encodings.js";
49
+ import {
50
+ getGlyphMapForStandardFonts,
51
+ getNonStdFontMap,
52
+ getSerifFonts,
53
+ getStdFontMap,
54
+ getSupplementalGlyphMapForArialBlack,
55
+ getSupplementalGlyphMapForCalibri,
56
+ } from "./standard_fonts.js";
57
+ import { IdentityToUnicodeMap, ToUnicodeMap } from "./to_unicode_map.js";
58
+ import { CFFFont } from "./cff_font.js";
59
+ import { FontRendererFactory } from "./font_renderer.js";
60
+ import { getFontBasicMetrics } from "./metrics.js";
61
+ import { GlyfTable } from "./glyf.js";
62
+ import { IdentityCMap } from "./cmap.js";
63
+ import { OpenTypeFileBuilder } from "./opentype_file_builder.js";
64
+ import { readUint32 } from "./core_utils.js";
65
+ import { Stream } from "./stream.js";
66
+ import { Type1Font } from "./type1_font.js";
67
+
68
+ // Unicode Private Use Areas:
69
+ const PRIVATE_USE_AREAS = [
70
+ [0xe000, 0xf8ff], // BMP (0)
71
+ [0x100000, 0x10fffd], // PUP (16)
72
+ ];
73
+
74
+ // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
75
+ // except for Type 3 fonts
76
+ const PDF_GLYPH_SPACE_UNITS = 1000;
77
+
78
+ const EXPORT_DATA_PROPERTIES = [
79
+ "ascent",
80
+ "bbox",
81
+ "black",
82
+ "bold",
83
+ "charProcOperatorList",
84
+ "composite",
85
+ "cssFontInfo",
86
+ "data",
87
+ "defaultVMetrics",
88
+ "defaultWidth",
89
+ "descent",
90
+ "fallbackName",
91
+ "fontMatrix",
92
+ "isInvalidPDFjsFont",
93
+ "isType3Font",
94
+ "italic",
95
+ "loadedName",
96
+ "mimetype",
97
+ "missingFile",
98
+ "name",
99
+ "remeasure",
100
+ "subtype",
101
+ "systemFontInfo",
102
+ "type",
103
+ "vertical",
104
+ ];
105
+
106
+ const EXPORT_DATA_EXTRA_PROPERTIES = [
107
+ "cMap",
108
+ "defaultEncoding",
109
+ "differences",
110
+ "isMonospace",
111
+ "isSerifFont",
112
+ "isSymbolicFont",
113
+ "seacMap",
114
+ "toFontChar",
115
+ "toUnicode",
116
+ "vmetrics",
117
+ "widths",
118
+ ];
119
+
120
+ function adjustWidths(properties) {
121
+ if (!properties.fontMatrix) {
122
+ return;
123
+ }
124
+ if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
125
+ return;
126
+ }
127
+ // adjusting width to fontMatrix scale
128
+ const scale = 0.001 / properties.fontMatrix[0];
129
+ const glyphsWidths = properties.widths;
130
+ for (const glyph in glyphsWidths) {
131
+ glyphsWidths[glyph] *= scale;
132
+ }
133
+ properties.defaultWidth *= scale;
134
+ }
135
+
136
+ function adjustTrueTypeToUnicode(properties, isSymbolicFont, nameRecords) {
137
+ if (properties.isInternalFont) {
138
+ return;
139
+ }
140
+ if (properties.hasIncludedToUnicodeMap) {
141
+ return; // The font dictionary has a `ToUnicode` entry.
142
+ }
143
+ if (properties.hasEncoding) {
144
+ return; // The font dictionary has an `Encoding` entry.
145
+ }
146
+ if (properties.toUnicode instanceof IdentityToUnicodeMap) {
147
+ return;
148
+ }
149
+ if (!isSymbolicFont) {
150
+ return; // A non-symbolic font should default to `StandardEncoding`.
151
+ }
152
+ if (nameRecords.length === 0) {
153
+ return;
154
+ }
155
+
156
+ // Try to infer if the fallback encoding should really be `WinAnsiEncoding`.
157
+ if (properties.defaultEncoding === WinAnsiEncoding) {
158
+ return;
159
+ }
160
+ for (const r of nameRecords) {
161
+ if (!isWinNameRecord(r)) {
162
+ return; // Not Windows, hence `WinAnsiEncoding` wouldn't make sense.
163
+ }
164
+ }
165
+ const encoding = WinAnsiEncoding;
166
+
167
+ const toUnicode = [],
168
+ glyphsUnicodeMap = getGlyphsUnicode();
169
+ for (const charCode in encoding) {
170
+ const glyphName = encoding[charCode];
171
+ if (glyphName === "") {
172
+ continue;
173
+ }
174
+ const unicode = glyphsUnicodeMap[glyphName];
175
+ if (unicode === undefined) {
176
+ continue;
177
+ }
178
+ toUnicode[charCode] = String.fromCharCode(unicode);
179
+ }
180
+ if (toUnicode.length > 0) {
181
+ properties.toUnicode.amend(toUnicode);
182
+ }
183
+ }
184
+
185
+ function adjustType1ToUnicode(properties, builtInEncoding) {
186
+ if (properties.isInternalFont) {
187
+ return;
188
+ }
189
+ if (properties.hasIncludedToUnicodeMap) {
190
+ return; // The font dictionary has a `ToUnicode` entry.
191
+ }
192
+ if (builtInEncoding === properties.defaultEncoding) {
193
+ return; // No point in trying to adjust `toUnicode` if the encodings match.
194
+ }
195
+ if (properties.toUnicode instanceof IdentityToUnicodeMap) {
196
+ return;
197
+ }
198
+ const toUnicode = [],
199
+ glyphsUnicodeMap = getGlyphsUnicode();
200
+ for (const charCode in builtInEncoding) {
201
+ if (properties.hasEncoding) {
202
+ if (
203
+ properties.baseEncodingName ||
204
+ properties.differences[charCode] !== undefined
205
+ ) {
206
+ continue; // The font dictionary has an `Encoding`/`Differences` entry.
207
+ }
208
+ }
209
+ const glyphName = builtInEncoding[charCode];
210
+ const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
211
+ if (unicode !== -1) {
212
+ toUnicode[charCode] = String.fromCharCode(unicode);
213
+ }
214
+ }
215
+ if (toUnicode.length > 0) {
216
+ properties.toUnicode.amend(toUnicode);
217
+ }
218
+ }
219
+
220
+ /**
221
+ * NOTE: This function should only be called at the *end* of font-parsing,
222
+ * after e.g. `adjustType1ToUnicode` has run, to prevent any issues.
223
+ */
224
+ function amendFallbackToUnicode(properties) {
225
+ if (!properties.fallbackToUnicode) {
226
+ return;
227
+ }
228
+ if (properties.toUnicode instanceof IdentityToUnicodeMap) {
229
+ return;
230
+ }
231
+ const toUnicode = [];
232
+ for (const charCode in properties.fallbackToUnicode) {
233
+ if (properties.toUnicode.has(charCode)) {
234
+ continue; // The font dictionary has a `ToUnicode` entry.
235
+ }
236
+ toUnicode[charCode] = properties.fallbackToUnicode[charCode];
237
+ }
238
+ if (toUnicode.length > 0) {
239
+ properties.toUnicode.amend(toUnicode);
240
+ }
241
+ }
242
+
243
+ class Glyph {
244
+ constructor(
245
+ originalCharCode,
246
+ fontChar,
247
+ unicode,
248
+ accent,
249
+ width,
250
+ vmetric,
251
+ operatorListId,
252
+ isSpace,
253
+ isInFont
254
+ ) {
255
+ this.originalCharCode = originalCharCode;
256
+ this.fontChar = fontChar;
257
+ this.unicode = unicode;
258
+ this.accent = accent;
259
+ this.width = width;
260
+ this.vmetric = vmetric;
261
+ this.operatorListId = operatorListId;
262
+ this.isSpace = isSpace;
263
+ this.isInFont = isInFont;
264
+ }
265
+
266
+ /**
267
+ * This property, which is only used by `PartialEvaluator.getTextContent`,
268
+ * is purposely made non-serializable.
269
+ * @type {Object}
270
+ */
271
+ get category() {
272
+ return shadow(
273
+ this,
274
+ "category",
275
+ getCharUnicodeCategory(this.unicode),
276
+ /* nonSerializable = */ true
277
+ );
278
+ }
279
+ }
280
+
281
+ function int16(b0, b1) {
282
+ return (b0 << 8) + b1;
283
+ }
284
+
285
+ function writeSignedInt16(bytes, index, value) {
286
+ bytes[index + 1] = value;
287
+ bytes[index] = value >>> 8;
288
+ }
289
+
290
+ function signedInt16(b0, b1) {
291
+ const value = (b0 << 8) + b1;
292
+ return value & (1 << 15) ? value - 0x10000 : value;
293
+ }
294
+
295
+ function writeUint32(bytes, index, value) {
296
+ bytes[index + 3] = value & 0xff;
297
+ bytes[index + 2] = value >>> 8;
298
+ bytes[index + 1] = value >>> 16;
299
+ bytes[index] = value >>> 24;
300
+ }
301
+
302
+ function int32(b0, b1, b2, b3) {
303
+ return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
304
+ }
305
+
306
+ function string16(value) {
307
+ return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
308
+ }
309
+
310
+ function safeString16(value) {
311
+ // clamp value to the 16-bit int range
312
+ if (value > 0x7fff) {
313
+ value = 0x7fff;
314
+ } else if (value < -0x8000) {
315
+ value = -0x8000;
316
+ }
317
+ return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
318
+ }
319
+
320
+ function isTrueTypeFile(file) {
321
+ const header = file.peekBytes(4);
322
+ return (
323
+ readUint32(header, 0) === 0x00010000 || bytesToString(header) === "true"
324
+ );
325
+ }
326
+
327
+ function isTrueTypeCollectionFile(file) {
328
+ const header = file.peekBytes(4);
329
+ return bytesToString(header) === "ttcf";
330
+ }
331
+
332
+ function isOpenTypeFile(file) {
333
+ const header = file.peekBytes(4);
334
+ return bytesToString(header) === "OTTO";
335
+ }
336
+
337
+ function isType1File(file) {
338
+ const header = file.peekBytes(2);
339
+ // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
340
+ if (header[0] === 0x25 && header[1] === 0x21) {
341
+ return true;
342
+ }
343
+ // ... obviously some fonts violate that part of the specification,
344
+ // please refer to the comment in |Type1Font| below (pfb file header).
345
+ if (header[0] === 0x80 && header[1] === 0x01) {
346
+ return true;
347
+ }
348
+ return false;
349
+ }
350
+
351
+ /**
352
+ * Compared to other font formats, the header in CFF files is not constant
353
+ * but contains version numbers. To reduce the possibility of misclassifying
354
+ * font files as CFF, it's recommended to check for other font formats first.
355
+ */
356
+ function isCFFFile(file) {
357
+ const header = file.peekBytes(4);
358
+ if (
359
+ /* major version, [1, 255] */ header[0] >= 1 &&
360
+ /* minor version, [0, 255]; header[1] */
361
+ /* header size, [0, 255]; header[2] */
362
+ /* offset(0) size, [1, 4] */ header[3] >= 1 &&
363
+ header[3] <= 4
364
+ ) {
365
+ return true;
366
+ }
367
+ return false;
368
+ }
369
+
370
+ function getFontFileType(file, { type, subtype, composite }) {
371
+ let fileType, fileSubtype;
372
+
373
+ if (isTrueTypeFile(file) || isTrueTypeCollectionFile(file)) {
374
+ fileType = composite ? "CIDFontType2" : "TrueType";
375
+ } else if (isOpenTypeFile(file)) {
376
+ fileType = composite ? "CIDFontType2" : "OpenType";
377
+ } else if (isType1File(file)) {
378
+ if (composite) {
379
+ fileType = "CIDFontType0";
380
+ } else {
381
+ fileType = type === "MMType1" ? "MMType1" : "Type1";
382
+ }
383
+ } else if (isCFFFile(file)) {
384
+ if (composite) {
385
+ fileType = "CIDFontType0";
386
+ fileSubtype = "CIDFontType0C";
387
+ } else {
388
+ fileType = type === "MMType1" ? "MMType1" : "Type1";
389
+ fileSubtype = "Type1C";
390
+ }
391
+ } else {
392
+ warn("getFontFileType: Unable to detect correct font file Type/Subtype.");
393
+ fileType = type;
394
+ fileSubtype = subtype;
395
+ }
396
+
397
+ return [fileType, fileSubtype];
398
+ }
399
+
400
+ function applyStandardFontGlyphMap(map, glyphMap) {
401
+ for (const charCode in glyphMap) {
402
+ map[+charCode] = glyphMap[charCode];
403
+ }
404
+ }
405
+
406
+ function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
407
+ const toFontChar = [];
408
+ let unicode;
409
+ for (let i = 0, ii = encoding.length; i < ii; i++) {
410
+ unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
411
+ if (unicode !== -1) {
412
+ toFontChar[i] = unicode;
413
+ }
414
+ }
415
+ for (const charCode in differences) {
416
+ unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
417
+ if (unicode !== -1) {
418
+ toFontChar[+charCode] = unicode;
419
+ }
420
+ }
421
+ return toFontChar;
422
+ }
423
+
424
+ // Please refer to:
425
+ // - https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
426
+ function isMacNameRecord(r) {
427
+ return r.platform === 1 && r.encoding === 0 && r.language === 0;
428
+ }
429
+
430
+ // Please refer to:
431
+ // - https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6name.html
432
+ // - https://learn.microsoft.com/en-us/typography/opentype/spec/name#windows-language-ids
433
+ function isWinNameRecord(r) {
434
+ return r.platform === 3 && r.encoding === 1 && r.language === 0x409;
435
+ }
436
+
437
+ function convertCidString(charCode, cid, shouldThrow = false) {
438
+ switch (cid.length) {
439
+ case 1:
440
+ return cid.charCodeAt(0);
441
+ case 2:
442
+ return (cid.charCodeAt(0) << 8) | cid.charCodeAt(1);
443
+ }
444
+ const msg = `Unsupported CID string (charCode ${charCode}): "${cid}".`;
445
+ if (shouldThrow) {
446
+ throw new FormatError(msg);
447
+ }
448
+ warn(msg);
449
+ return cid;
450
+ }
451
+
452
+ /**
453
+ * Rebuilds the char code to glyph ID map by moving all char codes to the
454
+ * private use area. This is done to avoid issues with various problematic
455
+ * unicode areas where either a glyph won't be drawn or is deformed by a
456
+ * shaper.
457
+ * @returns {Object} Two properties:
458
+ * 'toFontChar' - maps original char codes(the value that will be read
459
+ * from commands such as show text) to the char codes that will be used in the
460
+ * font that we build
461
+ * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
462
+ */
463
+ function adjustMapping(charCodeToGlyphId, hasGlyph, newGlyphZeroId, toUnicode) {
464
+ const newMap = Object.create(null);
465
+ const toUnicodeExtraMap = new Map();
466
+ const toFontChar = [];
467
+ const usedGlyphIds = new Set();
468
+ let privateUseAreaIndex = 0;
469
+ const privateUseOffetStart = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
470
+ let nextAvailableFontCharCode = privateUseOffetStart;
471
+ let privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
472
+ const isInPrivateArea = code =>
473
+ (PRIVATE_USE_AREAS[0][0] <= code && code <= PRIVATE_USE_AREAS[0][1]) ||
474
+ (PRIVATE_USE_AREAS[1][0] <= code && code <= PRIVATE_USE_AREAS[1][1]);
475
+ for (let originalCharCode in charCodeToGlyphId) {
476
+ originalCharCode |= 0;
477
+ let glyphId = charCodeToGlyphId[originalCharCode];
478
+ // For missing glyphs don't create the mappings so the glyph isn't
479
+ // drawn.
480
+ if (!hasGlyph(glyphId)) {
481
+ continue;
482
+ }
483
+ if (nextAvailableFontCharCode > privateUseOffetEnd) {
484
+ privateUseAreaIndex++;
485
+ if (privateUseAreaIndex >= PRIVATE_USE_AREAS.length) {
486
+ warn("Ran out of space in font private use area.");
487
+ break;
488
+ }
489
+ nextAvailableFontCharCode = PRIVATE_USE_AREAS[privateUseAreaIndex][0];
490
+ privateUseOffetEnd = PRIVATE_USE_AREAS[privateUseAreaIndex][1];
491
+ }
492
+ const fontCharCode = nextAvailableFontCharCode++;
493
+ if (glyphId === 0) {
494
+ glyphId = newGlyphZeroId;
495
+ }
496
+
497
+ // Fix for bug 1778484:
498
+ // The charcodes are moved into a private use area to fix some rendering
499
+ // issues (https://github.com/mozilla/pdf.js/pull/9340) but when printing
500
+ // to PDF the generated font will contain wrong chars. We can avoid that by
501
+ // adding the unicode to the cmap and the print backend will then map the
502
+ // glyph ids to the correct unicode.
503
+ try {
504
+ // 这里的toUnicode的第一个是null导致了崩溃,因为toUnicode和pdf.js中的toUnicode数组不一样!!!
505
+ let unicode = toUnicode.get(originalCharCode);
506
+ if (typeof unicode === "string") {
507
+ unicode = unicode.codePointAt(0);
508
+ }
509
+ if (unicode && !isInPrivateArea(unicode) && !usedGlyphIds.has(glyphId)) {
510
+ toUnicodeExtraMap.set(unicode, glyphId);
511
+ usedGlyphIds.add(glyphId);
512
+ }
513
+ } catch (e) {
514
+ console.log("adjustingmapp tounicode err", e)
515
+ }
516
+
517
+
518
+ newMap[fontCharCode] = glyphId;
519
+ toFontChar[originalCharCode] = fontCharCode;
520
+ }
521
+ return {
522
+ toFontChar,
523
+ charCodeToGlyphId: newMap,
524
+ toUnicodeExtraMap,
525
+ nextAvailableFontCharCode,
526
+ };
527
+ }
528
+
529
+ function getRanges(glyphs, toUnicodeExtraMap, numGlyphs) {
530
+ // Array.sort() sorts by characters, not numerically, so convert to an
531
+ // array of characters.
532
+ const codes = [];
533
+ for (const charCode in glyphs) {
534
+ // Remove an invalid glyph ID mappings to make OTS happy.
535
+ if (glyphs[charCode] >= numGlyphs) {
536
+ continue;
537
+ }
538
+ codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
539
+ }
540
+ if (toUnicodeExtraMap) {
541
+ for (const [unicode, glyphId] of toUnicodeExtraMap) {
542
+ if (glyphId >= numGlyphs) {
543
+ continue;
544
+ }
545
+ codes.push({ fontCharCode: unicode, glyphId });
546
+ }
547
+ }
548
+ // Some fonts have zero glyphs and are used only for text selection, but
549
+ // there needs to be at least one to build a valid cmap table.
550
+ if (codes.length === 0) {
551
+ codes.push({ fontCharCode: 0, glyphId: 0 });
552
+ }
553
+ codes.sort(function fontGetRangesSort(a, b) {
554
+ return a.fontCharCode - b.fontCharCode;
555
+ });
556
+
557
+ // Split the sorted codes into ranges.
558
+ const ranges = [];
559
+ const length = codes.length;
560
+ for (let n = 0; n < length; ) {
561
+ const start = codes[n].fontCharCode;
562
+ const codeIndices = [codes[n].glyphId];
563
+ ++n;
564
+ let end = start;
565
+ while (n < length && end + 1 === codes[n].fontCharCode) {
566
+ codeIndices.push(codes[n].glyphId);
567
+ ++end;
568
+ ++n;
569
+ if (end === 0xffff) {
570
+ break;
571
+ }
572
+ }
573
+ ranges.push([start, end, codeIndices]);
574
+ }
575
+
576
+ return ranges;
577
+ }
578
+
579
+
580
+ function createCmapTable(glyphs, toUnicodeExtraMap, numGlyphs) {
581
+ const ranges = getRanges(glyphs, toUnicodeExtraMap, numGlyphs);
582
+ const numTables = ranges.at(-1)[1] > 0xffff ? 2 : 1;
583
+ let cmap =
584
+ "\x00\x00" + // version
585
+ string16(numTables) + // numTables
586
+ "\x00\x03" + // platformID
587
+ "\x00\x01" + // encodingID
588
+ string32(4 + numTables * 8); // start of the table record
589
+
590
+ let i, ii, j, jj;
591
+ for (i = ranges.length - 1; i >= 0; --i) {
592
+ if (ranges[i][0] <= 0xffff) {
593
+ break;
594
+ }
595
+ }
596
+ const bmpLength = i + 1;
597
+
598
+ if (ranges[i][0] < 0xffff && ranges[i][1] === 0xffff) {
599
+ ranges[i][1] = 0xfffe;
600
+ }
601
+ const trailingRangesCount = ranges[i][1] < 0xffff ? 1 : 0;
602
+ const segCount = bmpLength + trailingRangesCount;
603
+ const searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
604
+
605
+ // Fill up the 4 parallel arrays describing the segments.
606
+ let startCount = "";
607
+ let endCount = "";
608
+ let idDeltas = "";
609
+ let idRangeOffsets = "";
610
+ let glyphsIds = "";
611
+ let bias = 0;
612
+
613
+ let range, start, end, codes;
614
+ for (i = 0, ii = bmpLength; i < ii; i++) {
615
+ range = ranges[i];
616
+ start = range[0];
617
+ end = range[1];
618
+ startCount += string16(start);
619
+ endCount += string16(end);
620
+ codes = range[2];
621
+ let contiguous = true;
622
+ for (j = 1, jj = codes.length; j < jj; ++j) {
623
+ if (codes[j] !== codes[j - 1] + 1) {
624
+ contiguous = false;
625
+ break;
626
+ }
627
+ }
628
+ if (!contiguous) {
629
+ const offset = (segCount - i) * 2 + bias * 2;
630
+ bias += end - start + 1;
631
+
632
+ idDeltas += string16(0);
633
+ idRangeOffsets += string16(offset);
634
+
635
+ for (j = 0, jj = codes.length; j < jj; ++j) {
636
+ glyphsIds += string16(codes[j]);
637
+ }
638
+ } else {
639
+ const startCode = codes[0];
640
+
641
+ idDeltas += string16((startCode - start) & 0xffff);
642
+ idRangeOffsets += string16(0);
643
+ }
644
+ }
645
+
646
+ if (trailingRangesCount > 0) {
647
+ endCount += "\xFF\xFF";
648
+ startCount += "\xFF\xFF";
649
+ idDeltas += "\x00\x01";
650
+ idRangeOffsets += "\x00\x00";
651
+ }
652
+
653
+ const format314 =
654
+ "\x00\x00" + // language
655
+ string16(2 * segCount) +
656
+ string16(searchParams.range) +
657
+ string16(searchParams.entry) +
658
+ string16(searchParams.rangeShift) +
659
+ endCount +
660
+ "\x00\x00" +
661
+ startCount +
662
+ idDeltas +
663
+ idRangeOffsets +
664
+ glyphsIds;
665
+
666
+ let format31012 = "";
667
+ let header31012 = "";
668
+ if (numTables > 1) {
669
+ cmap +=
670
+ "\x00\x03" + // platformID
671
+ "\x00\x0A" + // encodingID
672
+ string32(4 + numTables * 8 + 4 + format314.length); // start of the table record
673
+ format31012 = "";
674
+ for (i = 0, ii = ranges.length; i < ii; i++) {
675
+ range = ranges[i];
676
+ start = range[0];
677
+ codes = range[2];
678
+ let code = codes[0];
679
+ for (j = 1, jj = codes.length; j < jj; ++j) {
680
+ if (codes[j] !== codes[j - 1] + 1) {
681
+ end = range[0] + j - 1;
682
+ format31012 +=
683
+ string32(start) + // startCharCode
684
+ string32(end) + // endCharCode
685
+ string32(code); // startGlyphID
686
+ start = end + 1;
687
+ code = codes[j];
688
+ }
689
+ }
690
+ format31012 +=
691
+ string32(start) + // startCharCode
692
+ string32(range[1]) + // endCharCode
693
+ string32(code); // startGlyphID
694
+ }
695
+ header31012 =
696
+ "\x00\x0C" + // format
697
+ "\x00\x00" + // reserved
698
+ string32(format31012.length + 16) + // length
699
+ "\x00\x00\x00\x00" + // language
700
+ string32(format31012.length / 12); // nGroups
701
+ }
702
+
703
+ return (
704
+ cmap +
705
+ "\x00\x04" + // format
706
+ string16(format314.length + 4) + // length
707
+ format314 +
708
+ header31012 +
709
+ format31012
710
+ );
711
+ }
712
+
713
+ function validateOS2Table(os2, file) {
714
+ file.pos = (file.start || 0) + os2.offset;
715
+ const version = file.getUint16();
716
+ // TODO verify all OS/2 tables fields, but currently we validate only those
717
+ // that give us issues
718
+ file.skip(60); // skipping type, misc sizes, panose, unicode ranges
719
+ const selection = file.getUint16();
720
+ if (version < 4 && selection & 0x0300) {
721
+ return false;
722
+ }
723
+ const firstChar = file.getUint16();
724
+ const lastChar = file.getUint16();
725
+ if (firstChar > lastChar) {
726
+ return false;
727
+ }
728
+ file.skip(6); // skipping sTypoAscender/Descender/LineGap
729
+ const usWinAscent = file.getUint16();
730
+ if (usWinAscent === 0) {
731
+ // makes font unreadable by windows
732
+ return false;
733
+ }
734
+
735
+ // OS/2 appears to be valid, resetting some fields
736
+ os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
737
+ return true;
738
+ }
739
+
740
+ function createOS2Table(charstrings, override) {
741
+ override ||= {
742
+ unitsPerEm: 0,
743
+ yMax: 0,
744
+ yMin: 0,
745
+ ascent: 0,
746
+ descent: 0,
747
+ };
748
+
749
+ let ulUnicodeRange1 = 0;
750
+ let ulUnicodeRange2 = 0;
751
+ let ulUnicodeRange3 = 0;
752
+ let ulUnicodeRange4 = 0;
753
+
754
+ let firstCharIndex = null;
755
+ let lastCharIndex = 0;
756
+ let position = -1;
757
+
758
+ if (charstrings) {
759
+ for (let code in charstrings) {
760
+ code |= 0;
761
+ if (firstCharIndex > code || !firstCharIndex) {
762
+ firstCharIndex = code;
763
+ }
764
+ if (lastCharIndex < code) {
765
+ lastCharIndex = code;
766
+ }
767
+
768
+ position = getUnicodeRangeFor(code, position);
769
+ if (position < 32) {
770
+ ulUnicodeRange1 |= 1 << position;
771
+ } else if (position < 64) {
772
+ ulUnicodeRange2 |= 1 << (position - 32);
773
+ } else if (position < 96) {
774
+ ulUnicodeRange3 |= 1 << (position - 64);
775
+ } else if (position < 123) {
776
+ ulUnicodeRange4 |= 1 << (position - 96);
777
+ } else {
778
+ throw new FormatError(
779
+ "Unicode ranges Bits > 123 are reserved for internal usage"
780
+ );
781
+ }
782
+ }
783
+ if (lastCharIndex > 0xffff) {
784
+ // OS2 only supports a 16 bit int. The spec says if supplementary
785
+ // characters are used the field should just be set to 0xFFFF.
786
+ lastCharIndex = 0xffff;
787
+ }
788
+ } else {
789
+ // TODO
790
+ firstCharIndex = 0;
791
+ lastCharIndex = 255;
792
+ }
793
+
794
+ const bbox = [0, 0, 0, 0];
795
+ const unitsPerEm =
796
+ override.unitsPerEm ||
797
+ 1 / (FONT_IDENTITY_MATRIX)[0];
798
+
799
+ // if the font units differ to the PDF glyph space units
800
+ // then scale up the values
801
+ const scale = unitsPerEm / PDF_GLYPH_SPACE_UNITS
802
+
803
+ const typoAscent =
804
+ override.ascent || Math.round(scale * (bbox[3]));
805
+ let typoDescent =
806
+ override.descent || Math.round(scale * (bbox[1]));
807
+ if (typoDescent > 0 && bbox[1] < 0) {
808
+ typoDescent = -typoDescent; // fixing incorrect descent
809
+ }
810
+ const winAscent = override.yMax || typoAscent;
811
+ const winDescent = -override.yMin || -typoDescent;
812
+
813
+ return (
814
+ "\x00\x03" + // version
815
+ "\x02\x24" + // xAvgCharWidth
816
+ "\x01\xF4" + // usWeightClass
817
+ "\x00\x05" + // usWidthClass
818
+ "\x00\x00" + // fstype (0 to let the font loads via font-face on IE)
819
+ "\x02\x8A" + // ySubscriptXSize
820
+ "\x02\xBB" + // ySubscriptYSize
821
+ "\x00\x00" + // ySubscriptXOffset
822
+ "\x00\x8C" + // ySubscriptYOffset
823
+ "\x02\x8A" + // ySuperScriptXSize
824
+ "\x02\xBB" + // ySuperScriptYSize
825
+ "\x00\x00" + // ySuperScriptXOffset
826
+ "\x01\xDF" + // ySuperScriptYOffset
827
+ "\x00\x31" + // yStrikeOutSize
828
+ "\x01\x02" + // yStrikeOutPosition
829
+ "\x00\x00" + // sFamilyClass
830
+ "\x00\x00\x06" +
831
+ String.fromCharCode(0x00) +
832
+ "\x00\x00\x00\x00\x00\x00" + // Panose
833
+ string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
834
+ string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
835
+ string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
836
+ string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
837
+ "\x2A\x32\x31\x2A" + // achVendID
838
+ string16(0) + // fsSelection
839
+ string16(firstCharIndex) + // usFirstCharIndex
840
+ string16(lastCharIndex) + // usLastCharIndex
841
+ string16(typoAscent) + // sTypoAscender
842
+ string16(typoDescent) + // sTypoDescender
843
+ "\x00\x64" + // sTypoLineGap (7%-10% of the unitsPerEM value)
844
+ string16(winAscent) + // usWinAscent
845
+ string16(winDescent) + // usWinDescent
846
+ "\x00\x00\x00\x00" + // ulCodePageRange1 (Bits 0-31)
847
+ "\x00\x00\x00\x00" + // ulCodePageRange2 (Bits 32-63)
848
+ string16(0) + // usDefaultChar
849
+ string16(firstCharIndex) + // usBreakChar
850
+ "\x00\x03"
851
+ ); // usMaxContext
852
+ }
853
+
854
+ function createPostTable(properties) {
855
+ const angle = Math.floor(properties.italicAngle * 2 ** 16);
856
+ return (
857
+ "\x00\x03\x00\x00" + // Version number
858
+ string32(angle) + // italicAngle
859
+ "\x00\x00" + // underlinePosition
860
+ "\x00\x00" + // underlineThickness
861
+ string32(properties.fixedPitch ? 1 : 0) + // isFixedPitch
862
+ "\x00\x00\x00\x00" + // minMemType42
863
+ "\x00\x00\x00\x00" + // maxMemType42
864
+ "\x00\x00\x00\x00" + // minMemType1
865
+ "\x00\x00\x00\x00"
866
+ ); // maxMemType1
867
+ }
868
+
869
+ function createPostscriptName(name) {
870
+ // See https://docs.microsoft.com/en-us/typography/opentype/spec/recom#name.
871
+ return name.replaceAll(/[^\x21-\x7E]|[[\](){}<>/%]/g, "").slice(0, 63);
872
+ }
873
+
874
+ function createNameTable(name, proto) {
875
+ if (!proto) {
876
+ proto = [[], []]; // no strings and unicode strings
877
+ }
878
+
879
+ const strings = [
880
+ proto[0][0] || "Original licence", // 0.Copyright
881
+ proto[0][1] || name, // 1.Font family
882
+ proto[0][2] || "Unknown", // 2.Font subfamily (font weight)
883
+ proto[0][3] || "uniqueID", // 3.Unique ID
884
+ proto[0][4] || name, // 4.Full font name
885
+ proto[0][5] || "Version 0.11", // 5.Version
886
+ proto[0][6] || createPostscriptName(name), // 6.Postscript name
887
+ proto[0][7] || "Unknown", // 7.Trademark
888
+ proto[0][8] || "Unknown", // 8.Manufacturer
889
+ proto[0][9] || "Unknown", // 9.Designer
890
+ ];
891
+
892
+ // Mac want 1-byte per character strings while Windows want
893
+ // 2-bytes per character, so duplicate the names table
894
+ const stringsUnicode = [];
895
+ let i, ii, j, jj, str;
896
+ for (i = 0, ii = strings.length; i < ii; i++) {
897
+ str = proto[1][i] || strings[i];
898
+
899
+ const strBufUnicode = [];
900
+ for (j = 0, jj = str.length; j < jj; j++) {
901
+ strBufUnicode.push(string16(str.charCodeAt(j)));
902
+ }
903
+ stringsUnicode.push(strBufUnicode.join(""));
904
+ }
905
+
906
+ const names = [strings, stringsUnicode];
907
+ const platforms = ["\x00\x01", "\x00\x03"];
908
+ const encodings = ["\x00\x00", "\x00\x01"];
909
+ const languages = ["\x00\x00", "\x04\x09"];
910
+
911
+ const namesRecordCount = strings.length * platforms.length;
912
+ let nameTable =
913
+ "\x00\x00" + // format
914
+ string16(namesRecordCount) + // Number of names Record
915
+ string16(namesRecordCount * 12 + 6); // Storage
916
+
917
+ // Build the name records field
918
+ let strOffset = 0;
919
+ for (i = 0, ii = platforms.length; i < ii; i++) {
920
+ const strs = names[i];
921
+ for (j = 0, jj = strs.length; j < jj; j++) {
922
+ str = strs[j];
923
+ const nameRecord =
924
+ platforms[i] + // platform ID
925
+ encodings[i] + // encoding ID
926
+ languages[i] + // language ID
927
+ string16(j) + // name ID
928
+ string16(str.length) +
929
+ string16(strOffset);
930
+ nameTable += nameRecord;
931
+ strOffset += str.length;
932
+ }
933
+ }
934
+
935
+ nameTable += strings.join("") + stringsUnicode.join("");
936
+ return nameTable;
937
+ }
938
+
939
+ /**
940
+ *
941
+ * 'Font' is the class the outside world should use, it encapsulate all the font
942
+ * decoding logics whatever type it is (assuming the font type is supported).
943
+ */
944
+ class Font {
945
+
946
+ constructor(name, file, properties) {
947
+ console.log("fonts.js constructor ", name, file, properties)
948
+ this.name = name;
949
+ this.psName = null;
950
+ this.mimetype = null;
951
+ this.disableFontFace = false;
952
+
953
+ this.loadedName = properties.loadedName;
954
+ this.isType3Font = properties.isType3Font;
955
+ this.missingFile = false;
956
+ this.cssFontInfo = properties.cssFontInfo;
957
+
958
+ this._charsCache = Object.create(null);
959
+ this._glyphCache = Object.create(null);
960
+
961
+ let isSerifFont = !!(properties.flags & FontFlags.Serif);
962
+ // Fallback to checking the font name, in order to improve text-selection,
963
+ // since the /Flags-entry is often wrong (fixes issue13845.pdf).
964
+ if (!isSerifFont && !properties.isSimulatedFlags) {
965
+ const baseName = name.replaceAll(/[,_]/g, "-").split("-", 1)[0],
966
+ serifFonts = getSerifFonts();
967
+ for (const namePart of baseName.split("+")) {
968
+ if (serifFonts[namePart]) {
969
+ isSerifFont = true;
970
+ break;
971
+ }
972
+ }
973
+ }
974
+ this.isSerifFont = isSerifFont;
975
+
976
+ this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
977
+ this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
978
+
979
+ let { type, subtype } = properties;
980
+ this.type = type;
981
+ this.subtype = subtype;
982
+ this.systemFontInfo = properties.systemFontInfo;
983
+
984
+ const matches = name.match(/^InvalidPDFjsFont_(.*)_\d+$/);
985
+ this.isInvalidPDFjsFont = !!matches;
986
+ if (this.isInvalidPDFjsFont) {
987
+ this.fallbackName = matches[1];
988
+ } else if (this.isMonospace) {
989
+ this.fallbackName = "monospace";
990
+ } else if (this.isSerifFont) {
991
+ this.fallbackName = "serif";
992
+ } else {
993
+ this.fallbackName = "sans-serif";
994
+ }
995
+ console.log("this.fallbackName", this.fallbackName)
996
+ if (this.systemFontInfo?.guessFallback) {
997
+ // Once the fallback name is guessed, we don't want to guess it again.
998
+ this.systemFontInfo.guessFallback = false;
999
+ this.systemFontInfo.css += `,${this.fallbackName}`;
1000
+ }
1001
+
1002
+ this.differences = properties.differences;
1003
+ this.widths = properties.widths;
1004
+ this.defaultWidth = properties.defaultWidth;
1005
+ this.composite = properties.composite;
1006
+ this.cMap = properties.cMap;
1007
+ this.capHeight = properties.capHeight / PDF_GLYPH_SPACE_UNITS;
1008
+ this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
1009
+ this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
1010
+ this.lineHeight = this.ascent - this.descent;
1011
+ this.fontMatrix = properties.fontMatrix;
1012
+ this.bbox = properties.bbox;
1013
+ this.defaultEncoding = properties.defaultEncoding;
1014
+
1015
+ this.toUnicode = properties.toUnicode;
1016
+ this.toFontChar = [];
1017
+
1018
+ if (properties.type === "Type3") {
1019
+ for (let charCode = 0; charCode < 256; charCode++) {
1020
+ this.toFontChar[charCode] =
1021
+ this.differences[charCode] || properties.defaultEncoding[charCode];
1022
+ }
1023
+ return;
1024
+ }
1025
+
1026
+ this.cidEncoding = properties.cidEncoding || "";
1027
+ this.vertical = !!properties.vertical;
1028
+ if (this.vertical) {
1029
+ this.vmetrics = properties.vmetrics;
1030
+ this.defaultVMetrics = properties.defaultVMetrics;
1031
+ }
1032
+ // OFD已经读取了字体数据,这里的isEmpty来读取不需要了,直接注释掉
1033
+ // if (!file || file.isEmpty) {
1034
+ // if (file) {
1035
+ // // Some bad PDF generators will include empty font files,
1036
+ // // attempting to recover by assuming that no file exists.
1037
+ // warn('Font file is empty in "' + name + '" (' + this.loadedName + ")");
1038
+ // }
1039
+ // this.fallbackToSystemFont(properties);
1040
+ // return;
1041
+ // }
1042
+ // Parse the font file to determine the correct type/subtype, rather than
1043
+ // relying on the (often incorrect) data in the font dictionary; (see e.g.
1044
+ // issue6782.pdf, issue7598.pdf, and issue9949.pdf).
1045
+ // debugger
1046
+ [type, subtype] = getFontFileType(file, properties);
1047
+ properties.type = type;
1048
+ properties.subtype = subtype
1049
+
1050
+ if (type !== this.type || subtype !== this.subtype) {
1051
+ info(
1052
+ "Inconsistent font file Type/SubType, expected: " +
1053
+ `${this.type}/${this.subtype} but found: ${type}/${subtype}.`
1054
+ );
1055
+ }
1056
+ // 根据传入的字体信息,获取字体的数据
1057
+ if ( file.length === 18872 ) debugger
1058
+ let data;
1059
+ try {
1060
+ switch (type) {
1061
+ case "MMType1":
1062
+ info("MMType1 font (" + name + "), falling back to Type1.");
1063
+ /* falls through */
1064
+ case "Type1":
1065
+ case "CIDFontType0":
1066
+ this.mimetype = "font/opentype";
1067
+
1068
+ const cff =
1069
+ subtype === "Type1C" || subtype === "CIDFontType0C"
1070
+ ? new CFFFont(file, properties)
1071
+ : new Type1Font(name, file, properties);
1072
+
1073
+ adjustWidths(properties);
1074
+
1075
+ // Wrap the CFF data inside an OTF font file 将cff字体数据包装到OTF字体文件中
1076
+ data = this.convert(name, cff, properties);
1077
+ // type1 的字体数据
1078
+ // debugger
1079
+ break;
1080
+
1081
+ case "OpenType":
1082
+ case "TrueType":
1083
+ case "CIDFontType2":
1084
+ this.mimetype = "font/opentype";
1085
+ // Repair the TrueType file. It is can be damaged in the point of
1086
+ // view of the sanitizer
1087
+ // 这里将原始加载的file数据,也就是cvt的字节的,转成了字体的数据,也就是pos/2的字体数据
1088
+ // 本身是131072的数据量,转换之后是822916的数据
1089
+ data = this.checkAndRepair(name, file, properties);
1090
+ // opentype的字体数据
1091
+ if (this.isOpenType) {
1092
+ adjustWidths(properties);
1093
+
1094
+ type = "OpenType";
1095
+ }
1096
+ break;
1097
+
1098
+ default:
1099
+ throw new FormatError(`Font ${type} is not supported`);
1100
+ }
1101
+ } catch (e) {
1102
+ warn(e);
1103
+ console.error("fonts.js constructor error", e)
1104
+ this.fallbackToSystemFont(properties);
1105
+ return;
1106
+ }
1107
+ // zxlog("fonts.js constructor properties", properties)
1108
+ amendFallbackToUnicode(properties);
1109
+ this.data = data;
1110
+
1111
+ // Transfer some properties again that could change during font conversion
1112
+ this.type = type;
1113
+ this.subtype = subtype;
1114
+ this.fontMatrix = properties.fontMatrix;
1115
+ this.widths = properties.widths;
1116
+ this.defaultWidth = properties.defaultWidth;
1117
+ this.toUnicode = properties.toUnicode;
1118
+ this.seacMap = properties.seacMap;
1119
+ // try {
1120
+ //
1121
+ // } catch(e) {
1122
+ // console.log("create font err", e)
1123
+ // }
1124
+ }
1125
+
1126
+ get renderer() {
1127
+ const renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
1128
+ return shadow(this, "renderer", renderer);
1129
+ }
1130
+
1131
+ exportData(extraProperties = false) {
1132
+ // 导出字体数据,包含了字体的基本数据信息,这个额外属性
1133
+ const exportDataProperties = extraProperties
1134
+ ? [...EXPORT_DATA_PROPERTIES, ...EXPORT_DATA_EXTRA_PROPERTIES]
1135
+ : EXPORT_DATA_PROPERTIES;
1136
+
1137
+ const data = Object.create(null);
1138
+ let property, value;
1139
+ for (property of exportDataProperties) {
1140
+ value = this[property];
1141
+ // Ignore properties that haven't been explicitly set.
1142
+ if (value !== undefined) {
1143
+ data[property] = value;
1144
+ }
1145
+ }
1146
+ return data;
1147
+ }
1148
+
1149
+ fallbackToSystemFont(properties) {
1150
+ this.missingFile = true;
1151
+ // The file data is not specified. Trying to fix the font name
1152
+ // to be used with the canvas.font.
1153
+ const { name, type } = this;
1154
+ let fontName = normalizeFontName(name);
1155
+ const stdFontMap = getStdFontMap(),
1156
+ nonStdFontMap = getNonStdFontMap();
1157
+ const isStandardFont = !!stdFontMap[fontName];
1158
+ const isMappedToStandardFont = !!(
1159
+ nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]
1160
+ );
1161
+
1162
+ fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
1163
+
1164
+ const fontBasicMetricsMap = getFontBasicMetrics();
1165
+ const metrics = fontBasicMetricsMap[fontName];
1166
+ if (metrics) {
1167
+ if (isNaN(this.ascent)) {
1168
+ this.ascent = metrics.ascent / PDF_GLYPH_SPACE_UNITS;
1169
+ }
1170
+ if (isNaN(this.descent)) {
1171
+ this.descent = metrics.descent / PDF_GLYPH_SPACE_UNITS;
1172
+ }
1173
+ if (isNaN(this.capHeight)) {
1174
+ this.capHeight = metrics.capHeight / PDF_GLYPH_SPACE_UNITS;
1175
+ }
1176
+ }
1177
+
1178
+ this.bold = /bold/gi.test(fontName);
1179
+ this.italic = /oblique|italic/gi.test(fontName);
1180
+
1181
+ // Use 'name' instead of 'fontName' here because the original
1182
+ // name ArialBlack for example will be replaced by Helvetica.
1183
+ this.black = /Black/g.test(name);
1184
+
1185
+ // Use 'name' instead of 'fontName' here because the original
1186
+ // name ArialNarrow for example will be replaced by Helvetica.
1187
+ const isNarrow = /Narrow/g.test(name);
1188
+
1189
+ // if at least one width is present, remeasure all chars when exists
1190
+ this.remeasure =
1191
+ (!isStandardFont || isNarrow) && Object.keys(this.widths).length > 0;
1192
+ if (
1193
+ (isStandardFont || isMappedToStandardFont) &&
1194
+ type === "CIDFontType2" &&
1195
+ this.cidEncoding.startsWith("Identity-")
1196
+ ) {
1197
+ const cidToGidMap = properties.cidToGidMap;
1198
+ // Standard fonts might be embedded as CID font without glyph mapping.
1199
+ // Building one based on GlyphMapForStandardFonts.
1200
+ const map = [];
1201
+ applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
1202
+
1203
+ if (/Arial-?Black/i.test(name)) {
1204
+ applyStandardFontGlyphMap(map, getSupplementalGlyphMapForArialBlack());
1205
+ } else if (/Calibri/i.test(name)) {
1206
+ applyStandardFontGlyphMap(map, getSupplementalGlyphMapForCalibri());
1207
+ }
1208
+
1209
+ // Always update the glyph mapping with the `cidToGidMap` when it exists
1210
+ // (fixes issue12418_reduced.pdf).
1211
+ if (cidToGidMap) {
1212
+ for (const charCode in map) {
1213
+ const cid = map[charCode];
1214
+ if (cidToGidMap[cid] !== undefined) {
1215
+ map[+charCode] = cidToGidMap[cid];
1216
+ }
1217
+ }
1218
+ // When the /CIDToGIDMap is "incomplete", fallback to the included
1219
+ // /ToUnicode-map regardless of its encoding (fixes issue11915.pdf).
1220
+ if (
1221
+ cidToGidMap.length !== this.toUnicode.length &&
1222
+ properties.hasIncludedToUnicodeMap &&
1223
+ this.toUnicode instanceof IdentityToUnicodeMap
1224
+ ) {
1225
+ this.toUnicode.forEach(function (charCode, unicodeCharCode) {
1226
+ const cid = map[charCode];
1227
+ if (cidToGidMap[cid] === undefined) {
1228
+ map[+charCode] = unicodeCharCode;
1229
+ }
1230
+ });
1231
+ }
1232
+ }
1233
+
1234
+ if (!(this.toUnicode instanceof IdentityToUnicodeMap)) {
1235
+ this.toUnicode.forEach(function (charCode, unicodeCharCode) {
1236
+ map[+charCode] = unicodeCharCode;
1237
+ });
1238
+ }
1239
+ this.toFontChar = map;
1240
+ this.toUnicode = new ToUnicodeMap(map);
1241
+ } else if (/Symbol/i.test(fontName)) {
1242
+ this.toFontChar = buildToFontChar(
1243
+ SymbolSetEncoding,
1244
+ getGlyphsUnicode(),
1245
+ this.differences
1246
+ );
1247
+ } else if (/Dingbats/i.test(fontName)) {
1248
+ this.toFontChar = buildToFontChar(
1249
+ ZapfDingbatsEncoding,
1250
+ getDingbatsGlyphsUnicode(),
1251
+ this.differences
1252
+ );
1253
+ } else if (isStandardFont) {
1254
+ const map = buildToFontChar(
1255
+ this.defaultEncoding,
1256
+ getGlyphsUnicode(),
1257
+ this.differences
1258
+ );
1259
+
1260
+ if (
1261
+ type === "CIDFontType2" &&
1262
+ !this.cidEncoding.startsWith("Identity-") &&
1263
+ !(this.toUnicode instanceof IdentityToUnicodeMap)
1264
+ ) {
1265
+ this.toUnicode.forEach(function (charCode, unicodeCharCode) {
1266
+ map[+charCode] = unicodeCharCode;
1267
+ });
1268
+ }
1269
+ this.toFontChar = map;
1270
+ } else {
1271
+ const glyphsUnicodeMap = getGlyphsUnicode();
1272
+ const map = [];
1273
+ this.toUnicode.forEach((charCode, unicodeCharCode) => {
1274
+ try {
1275
+ if (!this.composite) {
1276
+ const glyphName =
1277
+ this.differences[charCode] || this.defaultEncoding[charCode];
1278
+ const unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
1279
+ if (unicode !== -1) {
1280
+ unicodeCharCode = unicode;
1281
+ }
1282
+ }
1283
+ map[+charCode] = unicodeCharCode;
1284
+ } catch (e) {
1285
+ // debugger
1286
+ console.log("to unicode err", e)
1287
+ }
1288
+
1289
+ });
1290
+
1291
+ // Attempt to improve the glyph mapping for (some) composite fonts that
1292
+ // appear to lack meaningful ToUnicode data.
1293
+ if (this.composite && this.toUnicode instanceof IdentityToUnicodeMap) {
1294
+ if (/Tahoma|Verdana/i.test(name)) {
1295
+ // Fixes issue15719.pdf and issue11242_reduced.pdf.
1296
+ applyStandardFontGlyphMap(map, getGlyphMapForStandardFonts());
1297
+ }
1298
+ }
1299
+ this.toFontChar = map;
1300
+ }
1301
+
1302
+ amendFallbackToUnicode(properties);
1303
+ this.loadedName = fontName.split("-", 1)[0];
1304
+ }
1305
+
1306
+ checkAndRepair(name, font) {
1307
+ const VALID_TABLES = [
1308
+ "OS/2",
1309
+ "cmap",
1310
+ "head",
1311
+ "hhea",
1312
+ "hmtx",
1313
+ "maxp",
1314
+ "name",
1315
+ "post",
1316
+ "loca",
1317
+ "glyf",
1318
+ "fpgm",
1319
+ "prep",
1320
+ "cvt ",
1321
+ "CFF ",
1322
+ ];
1323
+
1324
+ function readTables(file, numTables) {
1325
+ const tables = Object.create(null);
1326
+ tables["OS/2"] = null;
1327
+ tables.cmap = null;
1328
+ tables.head = null;
1329
+ tables.hhea = null;
1330
+ tables.hmtx = null;
1331
+ tables.maxp = null;
1332
+ tables.name = null;
1333
+ tables.post = null;
1334
+
1335
+ for (let i = 0; i < numTables; i++) {
1336
+ const table = readTableEntry(file);
1337
+ if (!VALID_TABLES.includes(table.tag)) {
1338
+ continue; // skipping table if it's not a required or optional table
1339
+ }
1340
+ if (table.length === 0) {
1341
+ continue; // skipping empty tables
1342
+ }
1343
+ tables[table.tag] = table;
1344
+ }
1345
+ return tables;
1346
+ }
1347
+
1348
+ function readTableEntry(file) {
1349
+ const tag = file.getString(4);
1350
+
1351
+ const checksum = file.getInt32() >>> 0;
1352
+ const offset = file.getInt32() >>> 0;
1353
+ const length = file.getInt32() >>> 0;
1354
+
1355
+ // Read the table associated data
1356
+ const previousPosition = file.pos;
1357
+ file.pos = file.start || 0;
1358
+ file.skip(offset);
1359
+ const data = file.getBytes(length);
1360
+ file.pos = previousPosition;
1361
+
1362
+ if (tag === "head") {
1363
+ // clearing checksum adjustment
1364
+ data[8] = data[9] = data[10] = data[11] = 0;
1365
+ data[17] |= 0x20; // Set font optimized for cleartype flag.
1366
+ }
1367
+
1368
+ return {
1369
+ tag,
1370
+ checksum,
1371
+ length,
1372
+ offset,
1373
+ data,
1374
+ };
1375
+ }
1376
+
1377
+ function readOpenTypeHeader(ttf) {
1378
+ return {
1379
+ version: ttf.getString(4),
1380
+ numTables: ttf.getUint16(),
1381
+ searchRange: ttf.getUint16(),
1382
+ entrySelector: ttf.getUint16(),
1383
+ rangeShift: ttf.getUint16(),
1384
+ };
1385
+ }
1386
+
1387
+ function readTrueTypeCollectionHeader(ttc) {
1388
+ const ttcTag = ttc.getString(4);
1389
+ assert(ttcTag === "ttcf", "Must be a TrueType Collection font.");
1390
+
1391
+ const majorVersion = ttc.getUint16();
1392
+ const minorVersion = ttc.getUint16();
1393
+ const numFonts = ttc.getInt32() >>> 0;
1394
+ const offsetTable = [];
1395
+ for (let i = 0; i < numFonts; i++) {
1396
+ offsetTable.push(ttc.getInt32() >>> 0);
1397
+ }
1398
+
1399
+ const header = {
1400
+ ttcTag,
1401
+ majorVersion,
1402
+ minorVersion,
1403
+ numFonts,
1404
+ offsetTable,
1405
+ };
1406
+ switch (majorVersion) {
1407
+ case 1:
1408
+ return header;
1409
+ case 2:
1410
+ header.dsigTag = ttc.getInt32() >>> 0;
1411
+ header.dsigLength = ttc.getInt32() >>> 0;
1412
+ header.dsigOffset = ttc.getInt32() >>> 0;
1413
+ return header;
1414
+ }
1415
+ throw new FormatError(
1416
+ `Invalid TrueType Collection majorVersion: ${majorVersion}.`
1417
+ );
1418
+ }
1419
+
1420
+ function readTrueTypeCollectionData(ttc, fontName) {
1421
+ const { numFonts, offsetTable } = readTrueTypeCollectionHeader(ttc);
1422
+ const fontNameParts = fontName.split("+");
1423
+ let fallbackData;
1424
+
1425
+ for (let i = 0; i < numFonts; i++) {
1426
+ ttc.pos = (ttc.start || 0) + offsetTable[i];
1427
+ const potentialHeader = readOpenTypeHeader(ttc);
1428
+ const potentialTables = readTables(ttc, potentialHeader.numTables);
1429
+
1430
+ if (!potentialTables.name) {
1431
+ throw new FormatError(
1432
+ 'TrueType Collection font must contain a "name" table.'
1433
+ );
1434
+ }
1435
+ const [nameTable] = readNameTable(potentialTables.name);
1436
+
1437
+ for (let j = 0, jj = nameTable.length; j < jj; j++) {
1438
+ for (let k = 0, kk = nameTable[j].length; k < kk; k++) {
1439
+ const nameEntry = nameTable[j][k]?.replaceAll(/\s/g, "");
1440
+ if (!nameEntry) {
1441
+ continue;
1442
+ }
1443
+ if (nameEntry === fontName) {
1444
+ return {
1445
+ header: potentialHeader,
1446
+ tables: potentialTables,
1447
+ };
1448
+ }
1449
+ if (fontNameParts.length < 2) {
1450
+ continue;
1451
+ }
1452
+ for (const part of fontNameParts) {
1453
+ if (nameEntry === part) {
1454
+ fallbackData = {
1455
+ name: part,
1456
+ header: potentialHeader,
1457
+ tables: potentialTables,
1458
+ };
1459
+ }
1460
+ }
1461
+ }
1462
+ }
1463
+ }
1464
+ if (fallbackData) {
1465
+ warn(
1466
+ `TrueType Collection does not contain "${fontName}" font, ` +
1467
+ `falling back to "${fallbackData.name}" font instead.`
1468
+ );
1469
+ return {
1470
+ header: fallbackData.header,
1471
+ tables: fallbackData.tables,
1472
+ };
1473
+ }
1474
+ throw new FormatError(
1475
+ `TrueType Collection does not contain "${fontName}" font.`
1476
+ );
1477
+ }
1478
+
1479
+ /**
1480
+ * Read the appropriate subtable from the cmap according to 9.6.6.4 from
1481
+ * PDF spec
1482
+ */
1483
+ function readCmapTable(cmap, file, isSymbolicFont, hasEncoding) {
1484
+ if (!cmap) {
1485
+ warn("No cmap table available.");
1486
+ return {
1487
+ platformId: -1,
1488
+ encodingId: -1,
1489
+ mappings: [],
1490
+ hasShortCmap: false,
1491
+ };
1492
+ }
1493
+ let segment;
1494
+ let start = (file.start || 0) + cmap.offset;
1495
+ file.pos = start;
1496
+
1497
+ file.skip(2); // version
1498
+ const numTables = file.getUint16();
1499
+
1500
+ let potentialTable;
1501
+ let canBreak = false;
1502
+ // There's an order of preference in terms of which cmap subtable to
1503
+ // use:
1504
+ // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
1505
+ // - symbolic fonts the preference is a 3,0 table then a 1,0 table
1506
+ // The following takes advantage of the fact that the tables are sorted
1507
+ // to work.
1508
+ for (let i = 0; i < numTables; i++) {
1509
+ const platformId = file.getUint16();
1510
+ const encodingId = file.getUint16();
1511
+ const offset = file.getInt32() >>> 0;
1512
+ let useTable = false;
1513
+
1514
+ // Sometimes there are multiple of the same type of table. Default
1515
+ // to choosing the first table and skip the rest.
1516
+ if (
1517
+ potentialTable?.platformId === platformId &&
1518
+ potentialTable?.encodingId === encodingId
1519
+ ) {
1520
+ continue;
1521
+ }
1522
+
1523
+ if (
1524
+ platformId === 0 &&
1525
+ (encodingId === /* Unicode Default */ 0 ||
1526
+ encodingId === /* Unicode 1.1 */ 1 ||
1527
+ encodingId === /* Unicode BMP */ 3)
1528
+ ) {
1529
+ useTable = true;
1530
+ // Continue the loop since there still may be a higher priority
1531
+ // table.
1532
+ } else if (platformId === 1 && encodingId === 0) {
1533
+ useTable = true;
1534
+ // Continue the loop since there still may be a higher priority
1535
+ // table.
1536
+ } else if (
1537
+ platformId === 3 &&
1538
+ encodingId === 1 &&
1539
+ (hasEncoding || !potentialTable)
1540
+ ) {
1541
+ useTable = true;
1542
+ if (!isSymbolicFont) {
1543
+ canBreak = true;
1544
+ }
1545
+ } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
1546
+ useTable = true;
1547
+
1548
+ let correctlySorted = true;
1549
+ if (i < numTables - 1) {
1550
+ const nextBytes = file.peekBytes(2),
1551
+ nextPlatformId = int16(nextBytes[0], nextBytes[1]);
1552
+ if (nextPlatformId < platformId) {
1553
+ correctlySorted = false;
1554
+ }
1555
+ }
1556
+ if (correctlySorted) {
1557
+ canBreak = true;
1558
+ }
1559
+ }
1560
+
1561
+ if (useTable) {
1562
+ potentialTable = {
1563
+ platformId,
1564
+ encodingId,
1565
+ offset,
1566
+ };
1567
+ }
1568
+ if (canBreak) {
1569
+ break;
1570
+ }
1571
+ }
1572
+
1573
+ if (potentialTable) {
1574
+ file.pos = start + potentialTable.offset;
1575
+ }
1576
+ if (!potentialTable || file.peekByte() === -1) {
1577
+ warn("Could not find a preferred cmap table.");
1578
+ return {
1579
+ platformId: -1,
1580
+ encodingId: -1,
1581
+ mappings: [],
1582
+ hasShortCmap: false,
1583
+ };
1584
+ }
1585
+
1586
+ const format = file.getUint16();
1587
+ let hasShortCmap = false;
1588
+ const mappings = [];
1589
+ let j, glyphId;
1590
+
1591
+ // TODO(mack): refactor this cmap subtable reading logic out
1592
+ if (format === 0) {
1593
+ file.skip(2 + 2); // length + language
1594
+
1595
+ for (j = 0; j < 256; j++) {
1596
+ const index = file.getByte();
1597
+ if (!index) {
1598
+ continue;
1599
+ }
1600
+ mappings.push({
1601
+ charCode: j,
1602
+ glyphId: index,
1603
+ });
1604
+ }
1605
+ hasShortCmap = true;
1606
+ } else if (format === 2) {
1607
+ file.skip(2 + 2); // length + language
1608
+
1609
+ const subHeaderKeys = [];
1610
+ let maxSubHeaderKey = 0;
1611
+ // Read subHeaderKeys. If subHeaderKeys[i] === 0, then i is a
1612
+ // single-byte character. Otherwise, i is the first byte of a
1613
+ // multi-byte character, and the value is 8*index into
1614
+ // subHeaders.
1615
+ for (let i = 0; i < 256; i++) {
1616
+ const subHeaderKey = file.getUint16() >> 3;
1617
+ subHeaderKeys.push(subHeaderKey);
1618
+ maxSubHeaderKey = Math.max(subHeaderKey, maxSubHeaderKey);
1619
+ }
1620
+ // Read subHeaders. The number of entries is determined
1621
+ // dynamically based on the subHeaderKeys found above.
1622
+ const subHeaders = [];
1623
+ for (let i = 0; i <= maxSubHeaderKey; i++) {
1624
+ subHeaders.push({
1625
+ firstCode: file.getUint16(),
1626
+ entryCount: file.getUint16(),
1627
+ idDelta: signedInt16(file.getByte(), file.getByte()),
1628
+ idRangePos: file.pos + file.getUint16(),
1629
+ });
1630
+ }
1631
+ for (let i = 0; i < 256; i++) {
1632
+ if (subHeaderKeys[i] === 0) {
1633
+ // i is a single-byte code.
1634
+ file.pos = subHeaders[0].idRangePos + 2 * i;
1635
+ glyphId = file.getUint16();
1636
+ mappings.push({
1637
+ charCode: i,
1638
+ glyphId,
1639
+ });
1640
+ } else {
1641
+ // i is the first byte of a two-byte code.
1642
+ const s = subHeaders[subHeaderKeys[i]];
1643
+ for (j = 0; j < s.entryCount; j++) {
1644
+ const charCode = (i << 8) + j + s.firstCode;
1645
+ file.pos = s.idRangePos + 2 * j;
1646
+ glyphId = file.getUint16();
1647
+ if (glyphId !== 0) {
1648
+ glyphId = (glyphId + s.idDelta) % 65536;
1649
+ }
1650
+ mappings.push({
1651
+ charCode,
1652
+ glyphId,
1653
+ });
1654
+ }
1655
+ }
1656
+ }
1657
+ } else if (format === 4) {
1658
+ file.skip(2 + 2); // length + language
1659
+
1660
+ // re-creating the table in format 4 since the encoding
1661
+ // might be changed
1662
+ const segCount = file.getUint16() >> 1;
1663
+ file.skip(6); // skipping range fields
1664
+ const segments = [];
1665
+ let segIndex;
1666
+ for (segIndex = 0; segIndex < segCount; segIndex++) {
1667
+ segments.push({ end: file.getUint16() });
1668
+ }
1669
+ file.skip(2);
1670
+ for (segIndex = 0; segIndex < segCount; segIndex++) {
1671
+ segments[segIndex].start = file.getUint16();
1672
+ }
1673
+
1674
+ for (segIndex = 0; segIndex < segCount; segIndex++) {
1675
+ segments[segIndex].delta = file.getUint16();
1676
+ }
1677
+
1678
+ let offsetsCount = 0,
1679
+ offsetIndex;
1680
+ for (segIndex = 0; segIndex < segCount; segIndex++) {
1681
+ segment = segments[segIndex];
1682
+ const rangeOffset = file.getUint16();
1683
+ if (!rangeOffset) {
1684
+ segment.offsetIndex = -1;
1685
+ continue;
1686
+ }
1687
+
1688
+ offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
1689
+ segment.offsetIndex = offsetIndex;
1690
+ offsetsCount = Math.max(
1691
+ offsetsCount,
1692
+ offsetIndex + segment.end - segment.start + 1
1693
+ );
1694
+ }
1695
+
1696
+ const offsets = [];
1697
+ for (j = 0; j < offsetsCount; j++) {
1698
+ offsets.push(file.getUint16());
1699
+ }
1700
+
1701
+ for (segIndex = 0; segIndex < segCount; segIndex++) {
1702
+ segment = segments[segIndex];
1703
+ start = segment.start;
1704
+ const end = segment.end;
1705
+ const delta = segment.delta;
1706
+ offsetIndex = segment.offsetIndex;
1707
+
1708
+ for (j = start; j <= end; j++) {
1709
+ if (j === 0xffff) {
1710
+ continue;
1711
+ }
1712
+
1713
+ glyphId = offsetIndex < 0 ? j : offsets[offsetIndex + j - start];
1714
+ glyphId = (glyphId + delta) & 0xffff;
1715
+ mappings.push({
1716
+ charCode: j,
1717
+ glyphId,
1718
+ });
1719
+ }
1720
+ }
1721
+ } else if (format === 6) {
1722
+ file.skip(2 + 2); // length + language
1723
+
1724
+ // Format 6 is a 2-bytes dense mapping, which means the font data
1725
+ // lives glue together even if they are pretty far in the unicode
1726
+ // table. (This looks weird, so I can have missed something), this
1727
+ // works on Linux but seems to fails on Mac so let's rewrite the
1728
+ // cmap table to a 3-1-4 style
1729
+ const firstCode = file.getUint16();
1730
+ const entryCount = file.getUint16();
1731
+
1732
+ for (j = 0; j < entryCount; j++) {
1733
+ glyphId = file.getUint16();
1734
+ const charCode = firstCode + j;
1735
+
1736
+ mappings.push({
1737
+ charCode,
1738
+ glyphId,
1739
+ });
1740
+ }
1741
+ } else if (format === 12) {
1742
+ file.skip(2 + 4 + 4); // reserved + length + language
1743
+
1744
+ const nGroups = file.getInt32() >>> 0;
1745
+ for (j = 0; j < nGroups; j++) {
1746
+ const startCharCode = file.getInt32() >>> 0;
1747
+ const endCharCode = file.getInt32() >>> 0;
1748
+ let glyphCode = file.getInt32() >>> 0;
1749
+
1750
+ for (
1751
+ let charCode = startCharCode;
1752
+ charCode <= endCharCode;
1753
+ charCode++
1754
+ ) {
1755
+ mappings.push({
1756
+ charCode,
1757
+ glyphId: glyphCode++,
1758
+ });
1759
+ }
1760
+ }
1761
+ } else {
1762
+ warn("cmap table has unsupported format: " + format);
1763
+ return {
1764
+ platformId: -1,
1765
+ encodingId: -1,
1766
+ mappings: [],
1767
+ hasShortCmap: false,
1768
+ };
1769
+ }
1770
+
1771
+ // removing duplicate entries
1772
+ mappings.sort(function (a, b) {
1773
+ return a.charCode - b.charCode;
1774
+ });
1775
+ for (let i = 1; i < mappings.length; i++) {
1776
+ if (mappings[i - 1].charCode === mappings[i].charCode) {
1777
+ mappings.splice(i, 1);
1778
+ i--;
1779
+ }
1780
+ }
1781
+
1782
+ return {
1783
+ platformId: potentialTable.platformId,
1784
+ encodingId: potentialTable.encodingId,
1785
+ mappings,
1786
+ hasShortCmap,
1787
+ };
1788
+ }
1789
+
1790
+ function sanitizeMetrics(
1791
+ file,
1792
+ header,
1793
+ metrics,
1794
+ headTable,
1795
+ numGlyphs,
1796
+ dupFirstEntry
1797
+ ) {
1798
+ if (!header) {
1799
+ if (metrics) {
1800
+ metrics.data = null;
1801
+ }
1802
+ return;
1803
+ }
1804
+
1805
+ file.pos = (file.start || 0) + header.offset;
1806
+ file.pos += 4; // version
1807
+ file.pos += 2; // ascent
1808
+ file.pos += 2; // descent
1809
+ file.pos += 2; // linegap
1810
+ file.pos += 2; // adv_width_max
1811
+ file.pos += 2; // min_sb1
1812
+ file.pos += 2; // min_sb2
1813
+ file.pos += 2; // max_extent
1814
+ file.pos += 2; // caret_slope_rise
1815
+ file.pos += 2; // caret_slope_run
1816
+ const caretOffset = file.getUint16();
1817
+ file.pos += 8; // reserved
1818
+ file.pos += 2; // format
1819
+ let numOfMetrics = file.getUint16();
1820
+
1821
+ if (caretOffset !== 0) {
1822
+ const macStyle = int16(headTable.data[44], headTable.data[45]);
1823
+ if (!(macStyle & 2)) {
1824
+ // Suppress OTS warnings about the `caretOffset` in the hhea-table.
1825
+ header.data[22] = 0;
1826
+ header.data[23] = 0;
1827
+ }
1828
+ }
1829
+
1830
+ if (numOfMetrics > numGlyphs) {
1831
+ info(
1832
+ `The numOfMetrics (${numOfMetrics}) should not be ` +
1833
+ `greater than the numGlyphs (${numGlyphs}).`
1834
+ );
1835
+ // Reduce numOfMetrics if it is greater than numGlyphs
1836
+ numOfMetrics = numGlyphs;
1837
+ header.data[34] = (numOfMetrics & 0xff00) >> 8;
1838
+ header.data[35] = numOfMetrics & 0x00ff;
1839
+ }
1840
+
1841
+ const numOfSidebearings = numGlyphs - numOfMetrics;
1842
+ const numMissing =
1843
+ numOfSidebearings - ((metrics.length - numOfMetrics * 4) >> 1);
1844
+
1845
+ if (numMissing > 0) {
1846
+ // For each missing glyph, we set both the width and lsb to 0 (zero).
1847
+ // Since we need to add two properties for each glyph, this explains
1848
+ // the use of |numMissing * 2| when initializing the typed array.
1849
+ const entries = new Uint8Array(metrics.length + numMissing * 2);
1850
+ entries.set(metrics.data);
1851
+ if (dupFirstEntry) {
1852
+ // Set the sidebearing value of the duplicated glyph.
1853
+ entries[metrics.length] = metrics.data[2];
1854
+ entries[metrics.length + 1] = metrics.data[3];
1855
+ }
1856
+ metrics.data = entries;
1857
+ }
1858
+ }
1859
+
1860
+ function sanitizeGlyph(
1861
+ source,
1862
+ sourceStart,
1863
+ sourceEnd,
1864
+ dest,
1865
+ destStart,
1866
+ hintsValid
1867
+ ) {
1868
+ const glyphProfile = {
1869
+ length: 0,
1870
+ sizeOfInstructions: 0,
1871
+ };
1872
+ if (
1873
+ sourceStart < 0 ||
1874
+ sourceStart >= source.length ||
1875
+ sourceEnd > source.length ||
1876
+ sourceEnd - sourceStart <= 12
1877
+ ) {
1878
+ // If the offsets are wrong or the glyph is too small, remove it.
1879
+ return glyphProfile;
1880
+ }
1881
+ const glyf = source.subarray(sourceStart, sourceEnd);
1882
+
1883
+ // Sanitize the glyph bounding box.
1884
+ const xMin = signedInt16(glyf[2], glyf[3]);
1885
+ const yMin = signedInt16(glyf[4], glyf[5]);
1886
+ const xMax = signedInt16(glyf[6], glyf[7]);
1887
+ const yMax = signedInt16(glyf[8], glyf[9]);
1888
+
1889
+ if (xMin > xMax) {
1890
+ writeSignedInt16(glyf, 2, xMax);
1891
+ writeSignedInt16(glyf, 6, xMin);
1892
+ }
1893
+ if (yMin > yMax) {
1894
+ writeSignedInt16(glyf, 4, yMax);
1895
+ writeSignedInt16(glyf, 8, yMin);
1896
+ }
1897
+
1898
+ const contoursCount = signedInt16(glyf[0], glyf[1]);
1899
+ if (contoursCount < 0) {
1900
+ if (contoursCount < -1) {
1901
+ // OTS doesn't like contour count to be less than -1.
1902
+ // The glyph data offsets are very likely wrong and
1903
+ // having something lower than -1, very likely, implies
1904
+ // to have some garbage data.
1905
+ return glyphProfile;
1906
+ }
1907
+ // complex glyph, writing as is
1908
+ dest.set(glyf, destStart);
1909
+ glyphProfile.length = glyf.length;
1910
+ return glyphProfile;
1911
+ }
1912
+
1913
+ let i,
1914
+ j = 10,
1915
+ flagsCount = 0;
1916
+ for (i = 0; i < contoursCount; i++) {
1917
+ const endPoint = (glyf[j] << 8) | glyf[j + 1];
1918
+ flagsCount = endPoint + 1;
1919
+ j += 2;
1920
+ }
1921
+ // skipping instructions
1922
+ const instructionsStart = j;
1923
+ const instructionsLength = (glyf[j] << 8) | glyf[j + 1];
1924
+ glyphProfile.sizeOfInstructions = instructionsLength;
1925
+ j += 2 + instructionsLength;
1926
+ const instructionsEnd = j;
1927
+ // validating flags
1928
+ let coordinatesLength = 0;
1929
+ for (i = 0; i < flagsCount; i++) {
1930
+ const flag = glyf[j++];
1931
+ if (flag & 0xc0) {
1932
+ // reserved flags must be zero, cleaning up
1933
+ glyf[j - 1] = flag & 0x3f;
1934
+ }
1935
+ let xLength = 2;
1936
+ if (flag & 2) {
1937
+ xLength = 1;
1938
+ } else if (flag & 16) {
1939
+ xLength = 0;
1940
+ }
1941
+ let yLength = 2;
1942
+ if (flag & 4) {
1943
+ yLength = 1;
1944
+ } else if (flag & 32) {
1945
+ yLength = 0;
1946
+ }
1947
+ const xyLength = xLength + yLength;
1948
+ coordinatesLength += xyLength;
1949
+ if (flag & 8) {
1950
+ const repeat = glyf[j++];
1951
+ if (repeat === 0) {
1952
+ // The repeat count should be non-zero when the repeat flag is set.
1953
+ glyf[j - 1] ^= 8;
1954
+ }
1955
+ i += repeat;
1956
+ coordinatesLength += repeat * xyLength;
1957
+ }
1958
+ }
1959
+ // glyph without coordinates will be rejected
1960
+ if (coordinatesLength === 0) {
1961
+ return glyphProfile;
1962
+ }
1963
+ let glyphDataLength = j + coordinatesLength;
1964
+ if (glyphDataLength > glyf.length) {
1965
+ // not enough data for coordinates
1966
+ return glyphProfile;
1967
+ }
1968
+ if (!hintsValid && instructionsLength > 0) {
1969
+ dest.set(glyf.subarray(0, instructionsStart), destStart);
1970
+ dest.set([0, 0], destStart + instructionsStart);
1971
+ dest.set(
1972
+ glyf.subarray(instructionsEnd, glyphDataLength),
1973
+ destStart + instructionsStart + 2
1974
+ );
1975
+ glyphDataLength -= instructionsLength;
1976
+ if (glyf.length - glyphDataLength > 3) {
1977
+ glyphDataLength = (glyphDataLength + 3) & ~3;
1978
+ }
1979
+ glyphProfile.length = glyphDataLength;
1980
+ return glyphProfile;
1981
+ }
1982
+ if (glyf.length - glyphDataLength > 3) {
1983
+ // truncating and aligning to 4 bytes the long glyph data
1984
+ glyphDataLength = (glyphDataLength + 3) & ~3;
1985
+ dest.set(glyf.subarray(0, glyphDataLength), destStart);
1986
+ glyphProfile.length = glyphDataLength;
1987
+ return glyphProfile;
1988
+ }
1989
+ // glyph data is fine
1990
+ dest.set(glyf, destStart);
1991
+ glyphProfile.length = glyf.length;
1992
+ return glyphProfile;
1993
+ }
1994
+
1995
+ function sanitizeHead(head, numGlyphs, locaLength) {
1996
+ const data = head.data;
1997
+
1998
+ // Validate version:
1999
+ // Should always be 0x00010000
2000
+ const version = int32(data[0], data[1], data[2], data[3]);
2001
+ if (version >> 16 !== 1) {
2002
+ info("Attempting to fix invalid version in head table: " + version);
2003
+ data[0] = 0;
2004
+ data[1] = 1;
2005
+ data[2] = 0;
2006
+ data[3] = 0;
2007
+ }
2008
+
2009
+ const indexToLocFormat = int16(data[50], data[51]);
2010
+ if (indexToLocFormat < 0 || indexToLocFormat > 1) {
2011
+ info(
2012
+ "Attempting to fix invalid indexToLocFormat in head table: " +
2013
+ indexToLocFormat
2014
+ );
2015
+
2016
+ // The value of indexToLocFormat should be 0 if the loca table
2017
+ // consists of short offsets, and should be 1 if the loca table
2018
+ // consists of long offsets.
2019
+ //
2020
+ // The number of entries in the loca table should be numGlyphs + 1.
2021
+ //
2022
+ // Using this information, we can work backwards to deduce if the
2023
+ // size of each offset in the loca table, and thus figure out the
2024
+ // appropriate value for indexToLocFormat.
2025
+
2026
+ const numGlyphsPlusOne = numGlyphs + 1;
2027
+ if (locaLength === numGlyphsPlusOne << 1) {
2028
+ // 0x0000 indicates the loca table consists of short offsets
2029
+ data[50] = 0;
2030
+ data[51] = 0;
2031
+ } else if (locaLength === numGlyphsPlusOne << 2) {
2032
+ // 0x0001 indicates the loca table consists of long offsets
2033
+ data[50] = 0;
2034
+ data[51] = 1;
2035
+ } else {
2036
+ throw new FormatError(
2037
+ "Could not fix indexToLocFormat: " + indexToLocFormat
2038
+ );
2039
+ }
2040
+ }
2041
+ }
2042
+
2043
+ function sanitizeGlyphLocations(
2044
+ loca,
2045
+ glyf,
2046
+ numGlyphs,
2047
+ isGlyphLocationsLong,
2048
+ hintsValid,
2049
+ dupFirstEntry,
2050
+ maxSizeOfInstructions
2051
+ ) {
2052
+ let itemSize, itemDecode, itemEncode;
2053
+ if (isGlyphLocationsLong) {
2054
+ itemSize = 4;
2055
+ itemDecode = function fontItemDecodeLong(data, offset) {
2056
+ return (
2057
+ (data[offset] << 24) |
2058
+ (data[offset + 1] << 16) |
2059
+ (data[offset + 2] << 8) |
2060
+ data[offset + 3]
2061
+ );
2062
+ };
2063
+ itemEncode = function fontItemEncodeLong(data, offset, value) {
2064
+ data[offset] = (value >>> 24) & 0xff;
2065
+ data[offset + 1] = (value >> 16) & 0xff;
2066
+ data[offset + 2] = (value >> 8) & 0xff;
2067
+ data[offset + 3] = value & 0xff;
2068
+ };
2069
+ } else {
2070
+ itemSize = 2;
2071
+ itemDecode = function fontItemDecode(data, offset) {
2072
+ return (data[offset] << 9) | (data[offset + 1] << 1);
2073
+ };
2074
+ itemEncode = function fontItemEncode(data, offset, value) {
2075
+ data[offset] = (value >> 9) & 0xff;
2076
+ data[offset + 1] = (value >> 1) & 0xff;
2077
+ };
2078
+ }
2079
+ // The first glyph is duplicated.
2080
+ const numGlyphsOut = dupFirstEntry ? numGlyphs + 1 : numGlyphs;
2081
+ const locaDataSize = itemSize * (1 + numGlyphsOut);
2082
+ // Resize loca table to account for duplicated glyph.
2083
+ const locaData = new Uint8Array(locaDataSize);
2084
+ locaData.set(loca.data.subarray(0, locaDataSize));
2085
+ loca.data = locaData;
2086
+ // removing the invalid glyphs
2087
+ const oldGlyfData = glyf.data;
2088
+ const oldGlyfDataLength = oldGlyfData.length;
2089
+ const newGlyfData = new Uint8Array(oldGlyfDataLength);
2090
+
2091
+ // The spec says the offsets should be in ascending order, however
2092
+ // this is not true for some fonts or they use the offset of 0 to mark a
2093
+ // glyph as missing. OTS requires the offsets to be in order and not to
2094
+ // be zero, so we must sort and rebuild the loca table and potentially
2095
+ // re-arrange the glyf data.
2096
+ let i, j;
2097
+ const locaEntries = [];
2098
+ // There are numGlyphs + 1 loca table entries.
2099
+ for (i = 0, j = 0; i < numGlyphs + 1; i++, j += itemSize) {
2100
+ let offset = itemDecode(locaData, j);
2101
+ if (offset > oldGlyfDataLength) {
2102
+ offset = oldGlyfDataLength;
2103
+ }
2104
+ locaEntries.push({
2105
+ index: i,
2106
+ offset,
2107
+ endOffset: 0,
2108
+ });
2109
+ }
2110
+ locaEntries.sort((a, b) => a.offset - b.offset);
2111
+ // Now the offsets are sorted, calculate the end offset of each glyph.
2112
+ // The last loca entry's endOffset is not calculated since it's the end
2113
+ // of the data and will be stored on the previous entry's endOffset.
2114
+ for (i = 0; i < numGlyphs; i++) {
2115
+ locaEntries[i].endOffset = locaEntries[i + 1].offset;
2116
+ }
2117
+ // Re-sort so glyphs aren't out of order.
2118
+ locaEntries.sort((a, b) => a.index - b.index);
2119
+ // Calculate the endOffset of the "first" glyph correctly when there are
2120
+ // *multiple* empty ones at the start of the data (fixes issue14618.pdf).
2121
+ for (i = 0; i < numGlyphs; i++) {
2122
+ const { offset, endOffset } = locaEntries[i];
2123
+ if (offset !== 0 || endOffset !== 0) {
2124
+ break;
2125
+ }
2126
+ const nextOffset = locaEntries[i + 1].offset;
2127
+ if (nextOffset === 0) {
2128
+ continue;
2129
+ }
2130
+ locaEntries[i].endOffset = nextOffset;
2131
+ break;
2132
+ }
2133
+
2134
+ const missingGlyphs = Object.create(null);
2135
+ let writeOffset = 0;
2136
+ itemEncode(locaData, 0, writeOffset);
2137
+ for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
2138
+ const glyphProfile = sanitizeGlyph(
2139
+ oldGlyfData,
2140
+ locaEntries[i].offset,
2141
+ locaEntries[i].endOffset,
2142
+ newGlyfData,
2143
+ writeOffset,
2144
+ hintsValid
2145
+ );
2146
+ const newLength = glyphProfile.length;
2147
+ if (newLength === 0) {
2148
+ missingGlyphs[i] = true;
2149
+ }
2150
+ if (glyphProfile.sizeOfInstructions > maxSizeOfInstructions) {
2151
+ maxSizeOfInstructions = glyphProfile.sizeOfInstructions;
2152
+ }
2153
+ writeOffset += newLength;
2154
+ itemEncode(locaData, j, writeOffset);
2155
+ }
2156
+
2157
+ if (writeOffset === 0) {
2158
+ // glyf table cannot be empty -- redoing the glyf and loca tables
2159
+ // to have single glyph with one point
2160
+ const simpleGlyph = new Uint8Array([
2161
+ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0,
2162
+ ]);
2163
+ for (i = 0, j = itemSize; i < numGlyphsOut; i++, j += itemSize) {
2164
+ itemEncode(locaData, j, simpleGlyph.length);
2165
+ }
2166
+ glyf.data = simpleGlyph;
2167
+ } else if (dupFirstEntry) {
2168
+ // Browsers will not display a glyph at position 0. Typically glyph 0
2169
+ // is notdef, but a number of fonts put a valid glyph there so it must
2170
+ // be duplicated and appended.
2171
+ const firstEntryLength = itemDecode(locaData, itemSize);
2172
+ if (newGlyfData.length > firstEntryLength + writeOffset) {
2173
+ glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
2174
+ } else {
2175
+ glyf.data = new Uint8Array(firstEntryLength + writeOffset);
2176
+ glyf.data.set(newGlyfData.subarray(0, writeOffset));
2177
+ }
2178
+ glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
2179
+ itemEncode(
2180
+ loca.data,
2181
+ locaData.length - itemSize,
2182
+ writeOffset + firstEntryLength
2183
+ );
2184
+ } else {
2185
+ glyf.data = newGlyfData.subarray(0, writeOffset);
2186
+ }
2187
+ return {
2188
+ missingGlyphs,
2189
+ maxSizeOfInstructions,
2190
+ };
2191
+ }
2192
+
2193
+ function readPostScriptTable(post, maxpNumGlyphs) {
2194
+ const start = (font.start || 0) + post.offset;
2195
+ font.pos = start;
2196
+
2197
+ const length = post.length,
2198
+ end = start + length;
2199
+ const version = font.getInt32();
2200
+ // skip rest to the tables
2201
+ font.skip(28);
2202
+
2203
+ let glyphNames;
2204
+ let valid = true;
2205
+ let i;
2206
+
2207
+ switch (version) {
2208
+ case 0x00010000:
2209
+ glyphNames = MacStandardGlyphOrdering;
2210
+ break;
2211
+ case 0x00020000:
2212
+ const numGlyphs = font.getUint16();
2213
+ if (numGlyphs !== maxpNumGlyphs) {
2214
+ valid = false;
2215
+ break;
2216
+ }
2217
+ const glyphNameIndexes = [];
2218
+ for (i = 0; i < numGlyphs; ++i) {
2219
+ const index = font.getUint16();
2220
+ if (index >= 32768) {
2221
+ valid = false;
2222
+ break;
2223
+ }
2224
+ glyphNameIndexes.push(index);
2225
+ }
2226
+ if (!valid) {
2227
+ break;
2228
+ }
2229
+ const customNames = [],
2230
+ strBuf = [];
2231
+ while (font.pos < end) {
2232
+ const stringLength = font.getByte();
2233
+ strBuf.length = stringLength;
2234
+ for (i = 0; i < stringLength; ++i) {
2235
+ strBuf[i] = String.fromCharCode(font.getByte());
2236
+ }
2237
+ customNames.push(strBuf.join(""));
2238
+ }
2239
+ glyphNames = [];
2240
+ for (i = 0; i < numGlyphs; ++i) {
2241
+ const j = glyphNameIndexes[i];
2242
+ if (j < 258) {
2243
+ glyphNames.push(MacStandardGlyphOrdering[j]);
2244
+ continue;
2245
+ }
2246
+ glyphNames.push(customNames[j - 258]);
2247
+ }
2248
+ break;
2249
+ case 0x00030000:
2250
+ break;
2251
+ default:
2252
+ warn("Unknown/unsupported post table version " + version);
2253
+ valid = false;
2254
+ // if (propertiesObj.defaultEncoding) {
2255
+ // glyphNames = propertiesObj.defaultEncoding;
2256
+ // }
2257
+ break;
2258
+ }
2259
+ // propertiesObj.glyphNames = glyphNames;
2260
+ return valid;
2261
+ }
2262
+
2263
+ function readNameTable(nameTable) {
2264
+ const start = (font.start || 0) + nameTable.offset;
2265
+ font.pos = start;
2266
+
2267
+ const names = [[], []],
2268
+ records = [];
2269
+ const length = nameTable.length,
2270
+ end = start + length;
2271
+ const format = font.getUint16();
2272
+ const FORMAT_0_HEADER_LENGTH = 6;
2273
+ if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
2274
+ // unsupported name table format or table "too" small
2275
+ return [names, records];
2276
+ }
2277
+ const numRecords = font.getUint16();
2278
+ const stringsStart = font.getUint16();
2279
+ const NAME_RECORD_LENGTH = 12;
2280
+ let i, ii;
2281
+
2282
+ for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {
2283
+ const r = {
2284
+ platform: font.getUint16(),
2285
+ encoding: font.getUint16(),
2286
+ language: font.getUint16(),
2287
+ name: font.getUint16(),
2288
+ length: font.getUint16(),
2289
+ offset: font.getUint16(),
2290
+ };
2291
+ // using only Macintosh and Windows platform/encoding names
2292
+ if (isMacNameRecord(r) || isWinNameRecord(r)) {
2293
+ records.push(r);
2294
+ }
2295
+ }
2296
+ for (i = 0, ii = records.length; i < ii; i++) {
2297
+ const record = records[i];
2298
+ if (record.length <= 0) {
2299
+ continue; // Nothing to process, ignoring.
2300
+ }
2301
+ const pos = start + stringsStart + record.offset;
2302
+ if (pos + record.length > end) {
2303
+ continue; // outside of name table, ignoring
2304
+ }
2305
+ font.pos = pos;
2306
+ const nameIndex = record.name;
2307
+ if (record.encoding) {
2308
+ // unicode
2309
+ let str = "";
2310
+ for (let j = 0, jj = record.length; j < jj; j += 2) {
2311
+ str += String.fromCharCode(font.getUint16());
2312
+ }
2313
+ names[1][nameIndex] = str;
2314
+ } else {
2315
+ names[0][nameIndex] = font.getString(record.length);
2316
+ }
2317
+ }
2318
+ return [names, records];
2319
+ }
2320
+
2321
+ // prettier-ignore
2322
+ const TTOpsStackDeltas = [
2323
+ 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
2324
+ -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
2325
+ 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
2326
+ 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
2327
+ 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
2328
+ -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
2329
+ -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2330
+ -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
2331
+ -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
2332
+ // 0xC0-DF == -1 and 0xE0-FF == -2
2333
+
2334
+ function sanitizeTTProgram(table, ttContext) {
2335
+ let data = table.data;
2336
+ let i = 0,
2337
+ j,
2338
+ n,
2339
+ b,
2340
+ funcId,
2341
+ pc,
2342
+ lastEndf = 0,
2343
+ lastDeff = 0;
2344
+ const stack = [];
2345
+ const callstack = [];
2346
+ const functionsCalled = [];
2347
+ let tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;
2348
+ let inFDEF = false,
2349
+ ifLevel = 0,
2350
+ inELSE = 0;
2351
+ for (let ii = data.length; i < ii; ) {
2352
+ const op = data[i++];
2353
+ // The TrueType instruction set docs can be found at
2354
+ // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
2355
+ if (op === 0x40) {
2356
+ // NPUSHB - pushes n bytes
2357
+ n = data[i++];
2358
+ if (inFDEF || inELSE) {
2359
+ i += n;
2360
+ } else {
2361
+ for (j = 0; j < n; j++) {
2362
+ stack.push(data[i++]);
2363
+ }
2364
+ }
2365
+ } else if (op === 0x41) {
2366
+ // NPUSHW - pushes n words
2367
+ n = data[i++];
2368
+ if (inFDEF || inELSE) {
2369
+ i += n * 2;
2370
+ } else {
2371
+ for (j = 0; j < n; j++) {
2372
+ b = data[i++];
2373
+ stack.push((b << 8) | data[i++]);
2374
+ }
2375
+ }
2376
+ } else if ((op & 0xf8) === 0xb0) {
2377
+ // PUSHB - pushes bytes
2378
+ n = op - 0xb0 + 1;
2379
+ if (inFDEF || inELSE) {
2380
+ i += n;
2381
+ } else {
2382
+ for (j = 0; j < n; j++) {
2383
+ stack.push(data[i++]);
2384
+ }
2385
+ }
2386
+ } else if ((op & 0xf8) === 0xb8) {
2387
+ // PUSHW - pushes words
2388
+ n = op - 0xb8 + 1;
2389
+ if (inFDEF || inELSE) {
2390
+ i += n * 2;
2391
+ } else {
2392
+ for (j = 0; j < n; j++) {
2393
+ b = data[i++];
2394
+ stack.push((b << 8) | data[i++]);
2395
+ }
2396
+ }
2397
+ } else if (op === 0x2b && !tooComplexToFollowFunctions) {
2398
+ // CALL
2399
+ if (!inFDEF && !inELSE) {
2400
+ // collecting information about which functions are used
2401
+ funcId = stack.at(-1);
2402
+ if (isNaN(funcId)) {
2403
+ info("TT: CALL empty stack (or invalid entry).");
2404
+ } else {
2405
+ ttContext.functionsUsed[funcId] = true;
2406
+ if (funcId in ttContext.functionsStackDeltas) {
2407
+ const newStackLength =
2408
+ stack.length + ttContext.functionsStackDeltas[funcId];
2409
+ if (newStackLength < 0) {
2410
+ warn("TT: CALL invalid functions stack delta.");
2411
+ ttContext.hintsValid = false;
2412
+ return;
2413
+ }
2414
+ stack.length = newStackLength;
2415
+ } else if (
2416
+ funcId in ttContext.functionsDefined &&
2417
+ !functionsCalled.includes(funcId)
2418
+ ) {
2419
+ callstack.push({ data, i, stackTop: stack.length - 1 });
2420
+ functionsCalled.push(funcId);
2421
+ pc = ttContext.functionsDefined[funcId];
2422
+ if (!pc) {
2423
+ warn("TT: CALL non-existent function");
2424
+ ttContext.hintsValid = false;
2425
+ return;
2426
+ }
2427
+ data = pc.data;
2428
+ i = pc.i;
2429
+ }
2430
+ }
2431
+ }
2432
+ } else if (op === 0x2c && !tooComplexToFollowFunctions) {
2433
+ // FDEF
2434
+ if (inFDEF || inELSE) {
2435
+ warn("TT: nested FDEFs not allowed");
2436
+ tooComplexToFollowFunctions = true;
2437
+ }
2438
+ inFDEF = true;
2439
+ // collecting information about which functions are defined
2440
+ lastDeff = i;
2441
+ funcId = stack.pop();
2442
+ ttContext.functionsDefined[funcId] = { data, i };
2443
+ } else if (op === 0x2d) {
2444
+ // ENDF - end of function
2445
+ if (inFDEF) {
2446
+ inFDEF = false;
2447
+ lastEndf = i;
2448
+ } else {
2449
+ pc = callstack.pop();
2450
+ if (!pc) {
2451
+ warn("TT: ENDF bad stack");
2452
+ ttContext.hintsValid = false;
2453
+ return;
2454
+ }
2455
+ funcId = functionsCalled.pop();
2456
+ data = pc.data;
2457
+ i = pc.i;
2458
+ ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;
2459
+ }
2460
+ } else if (op === 0x89) {
2461
+ // IDEF - instruction definition
2462
+ if (inFDEF || inELSE) {
2463
+ warn("TT: nested IDEFs not allowed");
2464
+ tooComplexToFollowFunctions = true;
2465
+ }
2466
+ inFDEF = true;
2467
+ // recording it as a function to track ENDF
2468
+ lastDeff = i;
2469
+ } else if (op === 0x58) {
2470
+ // IF
2471
+ ++ifLevel;
2472
+ } else if (op === 0x1b) {
2473
+ // ELSE
2474
+ inELSE = ifLevel;
2475
+ } else if (op === 0x59) {
2476
+ // EIF
2477
+ if (inELSE === ifLevel) {
2478
+ inELSE = 0;
2479
+ }
2480
+ --ifLevel;
2481
+ } else if (op === 0x1c) {
2482
+ // JMPR
2483
+ if (!inFDEF && !inELSE) {
2484
+ const offset = stack.at(-1);
2485
+ // only jumping forward to prevent infinite loop
2486
+ if (offset > 0) {
2487
+ i += offset - 1;
2488
+ }
2489
+ }
2490
+ }
2491
+ // Adjusting stack not extactly, but just enough to get function id
2492
+ if (!inFDEF && !inELSE) {
2493
+ let stackDelta = 0;
2494
+ if (op <= 0x8e) {
2495
+ stackDelta = TTOpsStackDeltas[op];
2496
+ } else if (op >= 0xc0 && op <= 0xdf) {
2497
+ stackDelta = -1;
2498
+ } else if (op >= 0xe0) {
2499
+ stackDelta = -2;
2500
+ }
2501
+ if (op >= 0x71 && op <= 0x75) {
2502
+ n = stack.pop();
2503
+ if (!isNaN(n)) {
2504
+ stackDelta = -n * 2;
2505
+ }
2506
+ }
2507
+ while (stackDelta < 0 && stack.length > 0) {
2508
+ stack.pop();
2509
+ stackDelta++;
2510
+ }
2511
+ while (stackDelta > 0) {
2512
+ stack.push(NaN); // pushing any number into stack
2513
+ stackDelta--;
2514
+ }
2515
+ }
2516
+ }
2517
+ ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
2518
+ const content = [data];
2519
+ if (i > data.length) {
2520
+ content.push(new Uint8Array(i - data.length));
2521
+ }
2522
+ if (lastDeff > lastEndf) {
2523
+ warn("TT: complementing a missing function tail");
2524
+ // new function definition started, but not finished
2525
+ // complete function by [CLEAR, ENDF]
2526
+ content.push(new Uint8Array([0x22, 0x2d]));
2527
+ }
2528
+ foldTTTable(table, content);
2529
+ }
2530
+
2531
+ function checkInvalidFunctions(ttContext, maxFunctionDefs) {
2532
+ if (ttContext.tooComplexToFollowFunctions) {
2533
+ return;
2534
+ }
2535
+ if (ttContext.functionsDefined.length > maxFunctionDefs) {
2536
+ warn("TT: more functions defined than expected");
2537
+ ttContext.hintsValid = false;
2538
+ return;
2539
+ }
2540
+ for (let j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
2541
+ if (j > maxFunctionDefs) {
2542
+ warn("TT: invalid function id: " + j);
2543
+ ttContext.hintsValid = false;
2544
+ return;
2545
+ }
2546
+ if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
2547
+ warn("TT: undefined function: " + j);
2548
+ ttContext.hintsValid = false;
2549
+ return;
2550
+ }
2551
+ }
2552
+ }
2553
+
2554
+ function foldTTTable(table, content) {
2555
+ if (content.length > 1) {
2556
+ // concatenating the content items
2557
+ let newLength = 0;
2558
+ let j, jj;
2559
+ for (j = 0, jj = content.length; j < jj; j++) {
2560
+ newLength += content[j].length;
2561
+ }
2562
+ newLength = (newLength + 3) & ~3;
2563
+ const result = new Uint8Array(newLength);
2564
+ let pos = 0;
2565
+ for (j = 0, jj = content.length; j < jj; j++) {
2566
+ result.set(content[j], pos);
2567
+ pos += content[j].length;
2568
+ }
2569
+ table.data = result;
2570
+ table.length = newLength;
2571
+ }
2572
+ }
2573
+
2574
+ function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {
2575
+ const ttContext = {
2576
+ functionsDefined: [],
2577
+ functionsUsed: [],
2578
+ functionsStackDeltas: [],
2579
+ tooComplexToFollowFunctions: false,
2580
+ hintsValid: true,
2581
+ };
2582
+ if (fpgm) {
2583
+ sanitizeTTProgram(fpgm, ttContext);
2584
+ }
2585
+ if (prep) {
2586
+ sanitizeTTProgram(prep, ttContext);
2587
+ }
2588
+ if (fpgm) {
2589
+ checkInvalidFunctions(ttContext, maxFunctionDefs);
2590
+ }
2591
+ if (cvt && cvt.length & 1) {
2592
+ const cvtData = new Uint8Array(cvt.length + 1);
2593
+ cvtData.set(cvt.data);
2594
+ cvt.data = cvtData;
2595
+ }
2596
+ return ttContext.hintsValid;
2597
+ }
2598
+
2599
+ // debugger
2600
+ // The following steps modify the original font data, making copy
2601
+ font = new Stream(font.bytes);
2602
+
2603
+ let header, tables;
2604
+ if (isTrueTypeCollectionFile(font)) {
2605
+ const ttcData = readTrueTypeCollectionData(font, this.name);
2606
+ header = ttcData.header;
2607
+ tables = ttcData.tables;
2608
+ } else {
2609
+ header = readOpenTypeHeader(font);
2610
+ tables = readTables(font, header.numTables);
2611
+ }
2612
+ console.log("read tables", tables)
2613
+ let cff, cffFile;
2614
+
2615
+ const isTrueType = !tables["CFF "];
2616
+ if (!isTrueType) {
2617
+ const isComposite = true;
2618
+ // OpenType font (skip composite fonts with non-default glyph mapping).
2619
+ // if (
2620
+ // (header.version === "OTTO" && !isComposite) ||
2621
+ // !tables.head ||
2622
+ // !tables.hhea ||
2623
+ // !tables.maxp ||
2624
+ // !tables.post
2625
+ // ) {
2626
+ // // No major tables: throwing everything at `CFFFont`.
2627
+ // cffFile = new Stream(tables["CFF "].data);
2628
+ // cff = new CFFFont(cffFile, properties);
2629
+ //
2630
+ // adjustWidths(properties);
2631
+ //
2632
+ // return this.convert(name, cff, properties);
2633
+ // }
2634
+
2635
+ delete tables.glyf;
2636
+ delete tables.loca;
2637
+ delete tables.fpgm;
2638
+ delete tables.prep;
2639
+ delete tables["cvt "];
2640
+ this.isOpenType = true;
2641
+ } else {
2642
+ if (!tables.loca) {
2643
+ throw new FormatError('Required "loca" table is not found');
2644
+ }
2645
+ if (!tables.glyf) {
2646
+ warn('Required "glyf" table is not found -- trying to recover.');
2647
+ // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
2648
+ tables.glyf = {
2649
+ tag: "glyf",
2650
+ data: new Uint8Array(0),
2651
+ };
2652
+ }
2653
+ this.isOpenType = false;
2654
+ }
2655
+
2656
+ if (!tables.maxp) {
2657
+ throw new FormatError('Required "maxp" table is not found');
2658
+ }
2659
+
2660
+ font.pos = (font.start || 0) + tables.maxp.offset;
2661
+ let version = font.getInt32();
2662
+ const numGlyphs = font.getUint16();
2663
+
2664
+ if (version !== 0x00010000 && version !== 0x00005000) {
2665
+ // https://learn.microsoft.com/en-us/typography/opentype/spec/maxp
2666
+ if (tables.maxp.length === 6) {
2667
+ version = 0x0005000;
2668
+ } else if (tables.maxp.length >= 32) {
2669
+ version = 0x00010000;
2670
+ } else {
2671
+ throw new FormatError(`"maxp" table has a wrong version number`);
2672
+ }
2673
+ writeUint32(tables.maxp.data, 0, version);
2674
+ }
2675
+
2676
+ // if (properties.scaleFactors?.length === numGlyphs && isTrueType) {
2677
+ // const { scaleFactors } = properties;
2678
+ // const isGlyphLocationsLong = int16(
2679
+ // tables.head.data[50],
2680
+ // tables.head.data[51]
2681
+ // );
2682
+ //
2683
+ // const glyphs = new GlyfTable({
2684
+ // glyfTable: tables.glyf.data,
2685
+ // isGlyphLocationsLong,
2686
+ // locaTable: tables.loca.data,
2687
+ // numGlyphs,
2688
+ // });
2689
+ // glyphs.scale(scaleFactors);
2690
+ //
2691
+ // const { glyf, loca, isLocationLong } = glyphs.write();
2692
+ // tables.glyf.data = glyf;
2693
+ // tables.loca.data = loca;
2694
+ //
2695
+ // if (isLocationLong !== !!isGlyphLocationsLong) {
2696
+ // tables.head.data[50] = 0;
2697
+ // tables.head.data[51] = isLocationLong ? 1 : 0;
2698
+ // }
2699
+ //
2700
+ // const metrics = tables.hmtx.data;
2701
+ //
2702
+ // for (let i = 0; i < numGlyphs; i++) {
2703
+ // const j = 4 * i;
2704
+ // const advanceWidth = Math.round(
2705
+ // scaleFactors[i] * int16(metrics[j], metrics[j + 1])
2706
+ // );
2707
+ // metrics[j] = (advanceWidth >> 8) & 0xff;
2708
+ // metrics[j + 1] = advanceWidth & 0xff;
2709
+ // const lsb = Math.round(
2710
+ // scaleFactors[i] * signedInt16(metrics[j + 2], metrics[j + 3])
2711
+ // );
2712
+ // writeSignedInt16(metrics, j + 2, lsb);
2713
+ // }
2714
+ // }
2715
+
2716
+ // Glyph 0 is duplicated and appended.
2717
+ let numGlyphsOut = numGlyphs + 1;
2718
+ let dupFirstEntry = true;
2719
+ if (numGlyphsOut > 0xffff) {
2720
+ dupFirstEntry = false;
2721
+ numGlyphsOut = numGlyphs;
2722
+ warn("Not enough space in glyfs to duplicate first glyph.");
2723
+ }
2724
+ let maxFunctionDefs = 0;
2725
+ let maxSizeOfInstructions = 0;
2726
+ if (version >= 0x00010000 && tables.maxp.length >= 32) {
2727
+ // maxZones can be invalid
2728
+ font.pos += 8;
2729
+ const maxZones = font.getUint16();
2730
+ if (maxZones > 2) {
2731
+ // reset to 2 if font has invalid maxZones
2732
+ tables.maxp.data[14] = 0;
2733
+ tables.maxp.data[15] = 2;
2734
+ }
2735
+ font.pos += 4;
2736
+ maxFunctionDefs = font.getUint16();
2737
+ font.pos += 4;
2738
+ maxSizeOfInstructions = font.getUint16();
2739
+ }
2740
+
2741
+ tables.maxp.data[4] = numGlyphsOut >> 8;
2742
+ tables.maxp.data[5] = numGlyphsOut & 255;
2743
+
2744
+ const hintsValid = sanitizeTTPrograms(
2745
+ tables.fpgm,
2746
+ tables.prep,
2747
+ tables["cvt "],
2748
+ maxFunctionDefs
2749
+ );
2750
+ if (!hintsValid) {
2751
+ delete tables.fpgm;
2752
+ delete tables.prep;
2753
+ delete tables["cvt "];
2754
+ }
2755
+
2756
+ // Ensure the hmtx table contains the advance width and
2757
+ // sidebearings information for numGlyphs in the maxp table
2758
+ sanitizeMetrics(
2759
+ font,
2760
+ tables.hhea,
2761
+ tables.hmtx,
2762
+ tables.head,
2763
+ numGlyphsOut,
2764
+ dupFirstEntry
2765
+ );
2766
+
2767
+ if (!tables.head) {
2768
+ throw new FormatError('Required "head" table is not found');
2769
+ }
2770
+
2771
+ sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
2772
+
2773
+ let missingGlyphs = Object.create(null);
2774
+ if (isTrueType) {
2775
+ const isGlyphLocationsLong = int16(
2776
+ tables.head.data[50],
2777
+ tables.head.data[51]
2778
+ );
2779
+ const glyphsInfo = sanitizeGlyphLocations(
2780
+ tables.loca,
2781
+ tables.glyf,
2782
+ numGlyphs,
2783
+ isGlyphLocationsLong,
2784
+ hintsValid,
2785
+ dupFirstEntry,
2786
+ maxSizeOfInstructions
2787
+ );
2788
+ missingGlyphs = glyphsInfo.missingGlyphs;
2789
+
2790
+ // Some fonts have incorrect maxSizeOfInstructions values, so we use
2791
+ // the computed value instead.
2792
+ if (version >= 0x00010000 && tables.maxp.length >= 32) {
2793
+ tables.maxp.data[26] = glyphsInfo.maxSizeOfInstructions >> 8;
2794
+ tables.maxp.data[27] = glyphsInfo.maxSizeOfInstructions & 255;
2795
+ }
2796
+ }
2797
+ if (!tables.hhea) {
2798
+ throw new FormatError('Required "hhea" table is not found');
2799
+ }
2800
+
2801
+ // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
2802
+ // Sometimes it's 0. That needs to be fixed
2803
+ if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
2804
+ tables.hhea.data[10] = 0xff;
2805
+ tables.hhea.data[11] = 0xff;
2806
+ }
2807
+
2808
+ // Extract some more font properties from the OpenType head and
2809
+ // hhea tables; yMin and descent value are always negative.
2810
+ const metricsOverride = {
2811
+ unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
2812
+ yMax: signedInt16(tables.head.data[42], tables.head.data[43]),
2813
+ yMin: signedInt16(tables.head.data[38], tables.head.data[39]),
2814
+ ascent: signedInt16(tables.hhea.data[4], tables.hhea.data[5]),
2815
+ descent: signedInt16(tables.hhea.data[6], tables.hhea.data[7]),
2816
+ lineGap: signedInt16(tables.hhea.data[8], tables.hhea.data[9]),
2817
+ };
2818
+
2819
+ // PDF FontDescriptor metrics lie -- using data from actual font.
2820
+ this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
2821
+ this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
2822
+ this.lineGap = metricsOverride.lineGap / metricsOverride.unitsPerEm;
2823
+
2824
+ if (this.cssFontInfo?.lineHeight) {
2825
+ this.lineHeight = this.cssFontInfo.metrics.lineHeight;
2826
+ this.lineGap = this.cssFontInfo.metrics.lineGap;
2827
+ } else {
2828
+ this.lineHeight = this.ascent - this.descent + this.lineGap;
2829
+ }
2830
+
2831
+ // The 'post' table has glyphs names.
2832
+ if (tables.post) {
2833
+ readPostScriptTable(tables.post, numGlyphs);
2834
+ }
2835
+
2836
+ // The original 'post' table is not needed, replace it.
2837
+ tables.post = {
2838
+ tag: "post",
2839
+ data: createPostTable({fixedPitch: true}),
2840
+ };
2841
+
2842
+ const charCodeToGlyphId = [];
2843
+
2844
+ // Helper function to try to skip mapping of empty glyphs.
2845
+ function hasGlyph(glyphId) {
2846
+ return !missingGlyphs[glyphId];
2847
+ }
2848
+
2849
+ if (charCodeToGlyphId.length === 0) {
2850
+ // defines at least one glyph
2851
+ charCodeToGlyphId[0] = 0;
2852
+ }
2853
+
2854
+ // Typically glyph 0 is duplicated and the mapping must be updated, but if
2855
+ // there isn't enough room to duplicate, the glyph id is left the same. In
2856
+ // this case, glyph 0 may not work correctly, but that is better than
2857
+ // having the whole font fail.
2858
+ let glyphZeroId = numGlyphsOut - 1;
2859
+ if (!dupFirstEntry) {
2860
+ glyphZeroId = 0;
2861
+ }
2862
+
2863
+ // Converting glyphs and ids into font's cmap table
2864
+ // debugger
2865
+ const newMapping = adjustMapping(
2866
+ charCodeToGlyphId,
2867
+ hasGlyph,
2868
+ glyphZeroId
2869
+ );
2870
+ this.toFontChar = newMapping.toFontChar;
2871
+ tables.cmap = {
2872
+ tag: "cmap",
2873
+ data: createCmapTable(
2874
+ newMapping.charCodeToGlyphId,
2875
+ newMapping.toUnicodeExtraMap,
2876
+ numGlyphsOut
2877
+ ),
2878
+ };
2879
+
2880
+ if (!tables["OS/2"] || !validateOS2Table(tables["OS/2"], font)) {
2881
+ tables["OS/2"] = {
2882
+ tag: "OS/2",
2883
+ data: createOS2Table(
2884
+ newMapping.charCodeToGlyphId,
2885
+ metricsOverride
2886
+ ),
2887
+ };
2888
+ }
2889
+
2890
+ // Re-creating 'name' table
2891
+ if (!tables.name) {
2892
+ tables.name = {
2893
+ tag: "name",
2894
+ data: createNameTable(this.name),
2895
+ };
2896
+ } else {
2897
+ // ... using existing 'name' table as prototype
2898
+ const [namePrototype, nameRecords] = readNameTable(tables.name);
2899
+
2900
+ tables.name.data = createNameTable(name, namePrototype);
2901
+ this.psName = namePrototype[0][6] || null;
2902
+ }
2903
+
2904
+ const builder = new OpenTypeFileBuilder(header.version);
2905
+ // debugger
2906
+ for (const tableTag in tables) {
2907
+ builder.addTable(tableTag, tables[tableTag].data);
2908
+ }
2909
+ return builder.toArray();
2910
+ }
2911
+
2912
+ convert(fontName, font, properties) {
2913
+ // TODO: Check the charstring widths to determine this.
2914
+ properties.fixedPitch = false;
2915
+
2916
+ if (properties.builtInEncoding) {
2917
+ // For Type1 fonts that do not include either `ToUnicode` or `Encoding`
2918
+ // data, attempt to use the `builtInEncoding` to improve text selection.
2919
+ adjustType1ToUnicode(properties, properties.builtInEncoding);
2920
+ }
2921
+
2922
+ // Type 1 fonts have a notdef inserted at the beginning, so glyph 0
2923
+ // becomes glyph 1. In a CFF font glyph 0 is appended to the end of the
2924
+ // char strings.
2925
+ let glyphZeroId = 1;
2926
+ if (font instanceof CFFFont) {
2927
+ glyphZeroId = font.numGlyphs - 1;
2928
+ }
2929
+ const mapping = font.getGlyphMapping(properties);
2930
+ let newMapping = null;
2931
+ let newCharCodeToGlyphId = mapping;
2932
+ let toUnicodeExtraMap = null;
2933
+
2934
+ // When `cssFontInfo` is set, the font is used to render text in the HTML
2935
+ // view (e.g. with Xfa) so nothing must be moved in the private use area.
2936
+ if (!properties.cssFontInfo) {
2937
+ newMapping = adjustMapping(
2938
+ mapping,
2939
+ font.hasGlyphId.bind(font),
2940
+ glyphZeroId,
2941
+ this.toUnicode
2942
+ );
2943
+ this.toFontChar = newMapping.toFontChar;
2944
+ newCharCodeToGlyphId = newMapping.charCodeToGlyphId;
2945
+ toUnicodeExtraMap = newMapping.toUnicodeExtraMap;
2946
+ }
2947
+ const numGlyphs = font.numGlyphs;
2948
+
2949
+ function getCharCodes(charCodeToGlyphId, glyphId) {
2950
+ let charCodes = null;
2951
+ for (const charCode in charCodeToGlyphId) {
2952
+ if (glyphId === charCodeToGlyphId[charCode]) {
2953
+ (charCodes ||= []).push(charCode | 0);
2954
+ }
2955
+ }
2956
+ return charCodes;
2957
+ }
2958
+
2959
+ function createCharCode(charCodeToGlyphId, glyphId) {
2960
+ for (const charCode in charCodeToGlyphId) {
2961
+ if (glyphId === charCodeToGlyphId[charCode]) {
2962
+ return charCode | 0;
2963
+ }
2964
+ }
2965
+ newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
2966
+ glyphId;
2967
+ return newMapping.nextAvailableFontCharCode++;
2968
+ }
2969
+
2970
+ const seacs = font.seacs;
2971
+ if (newMapping && SEAC_ANALYSIS_ENABLED && seacs?.length) {
2972
+ const matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
2973
+ const charset = font.getCharset();
2974
+ const seacMap = Object.create(null);
2975
+ for (let glyphId in seacs) {
2976
+ glyphId |= 0;
2977
+ const seac = seacs[glyphId];
2978
+ const baseGlyphName = StandardEncoding[seac[2]];
2979
+ const accentGlyphName = StandardEncoding[seac[3]];
2980
+ const baseGlyphId = charset.indexOf(baseGlyphName);
2981
+ const accentGlyphId = charset.indexOf(accentGlyphName);
2982
+ if (baseGlyphId < 0 || accentGlyphId < 0) {
2983
+ continue;
2984
+ }
2985
+ const accentOffset = {
2986
+ x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
2987
+ y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5],
2988
+ };
2989
+
2990
+ const charCodes = getCharCodes(mapping, glyphId);
2991
+ if (!charCodes) {
2992
+ // There's no point in mapping it if the char code was never mapped
2993
+ // to begin with.
2994
+ continue;
2995
+ }
2996
+ for (const charCode of charCodes) {
2997
+ // Find a fontCharCode that maps to the base and accent glyphs.
2998
+ // If one doesn't exists, create it.
2999
+ const charCodeToGlyphId = newMapping.charCodeToGlyphId;
3000
+ const baseFontCharCode = createCharCode(
3001
+ charCodeToGlyphId,
3002
+ baseGlyphId
3003
+ );
3004
+ const accentFontCharCode = createCharCode(
3005
+ charCodeToGlyphId,
3006
+ accentGlyphId
3007
+ );
3008
+ seacMap[charCode] = {
3009
+ baseFontCharCode,
3010
+ accentFontCharCode,
3011
+ accentOffset,
3012
+ };
3013
+ }
3014
+ }
3015
+ properties.seacMap = seacMap;
3016
+ }
3017
+
3018
+ const unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
3019
+
3020
+ // debugger
3021
+ const builder = new OpenTypeFileBuilder("\x4F\x54\x54\x4F");
3022
+ // PostScript Font Program
3023
+ builder.addTable("CFF ", font.data);
3024
+ // OS/2 and Windows Specific metrics
3025
+ builder.addTable("OS/2", createOS2Table(properties, newCharCodeToGlyphId));
3026
+ // Character to glyphs mapping
3027
+ // debugger
3028
+ const cmapobj = createCmapTable(
3029
+ newCharCodeToGlyphId,
3030
+ toUnicodeExtraMap,
3031
+ numGlyphs
3032
+ );
3033
+ builder.addTable(
3034
+ "cmap",
3035
+ createCmapTable(newCharCodeToGlyphId, toUnicodeExtraMap, numGlyphs)
3036
+ );
3037
+ // Font header
3038
+ builder.addTable(
3039
+ "head",
3040
+ "\x00\x01\x00\x00" + // Version number
3041
+ "\x00\x00\x10\x00" + // fontRevision
3042
+ "\x00\x00\x00\x00" + // checksumAdjustement
3043
+ "\x5F\x0F\x3C\xF5" + // magicNumber
3044
+ "\x00\x00" + // Flags
3045
+ safeString16(unitsPerEm) + // unitsPerEM
3046
+ "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + // creation date
3047
+ "\x00\x00\x00\x00\x9e\x0b\x7e\x27" + // modifification date
3048
+ "\x00\x00" + // xMin
3049
+ safeString16(properties.descent) + // yMin
3050
+ "\x0F\xFF" + // xMax
3051
+ safeString16(properties.ascent) + // yMax
3052
+ string16(properties.italicAngle ? 2 : 0) + // macStyle
3053
+ "\x00\x11" + // lowestRecPPEM
3054
+ "\x00\x00" + // fontDirectionHint
3055
+ "\x00\x00" + // indexToLocFormat
3056
+ "\x00\x00"
3057
+ ); // glyphDataFormat
3058
+
3059
+ // Horizontal header
3060
+ builder.addTable(
3061
+ "hhea",
3062
+ "\x00\x01\x00\x00" + // Version number
3063
+ safeString16(properties.ascent) + // Typographic Ascent
3064
+ safeString16(properties.descent) + // Typographic Descent
3065
+ "\x00\x00" + // Line Gap
3066
+ "\xFF\xFF" + // advanceWidthMax
3067
+ "\x00\x00" + // minLeftSidebearing
3068
+ "\x00\x00" + // minRightSidebearing
3069
+ "\x00\x00" + // xMaxExtent
3070
+ safeString16(properties.capHeight) + // caretSlopeRise
3071
+ safeString16(Math.tan(properties.italicAngle) * properties.xHeight) + // caretSlopeRun
3072
+ "\x00\x00" + // caretOffset
3073
+ "\x00\x00" + // -reserved-
3074
+ "\x00\x00" + // -reserved-
3075
+ "\x00\x00" + // -reserved-
3076
+ "\x00\x00" + // -reserved-
3077
+ "\x00\x00" + // metricDataFormat
3078
+ string16(numGlyphs)
3079
+ ); // Number of HMetrics
3080
+
3081
+ // Horizontal metrics
3082
+ builder.addTable(
3083
+ "hmtx",
3084
+ (function fontFieldsHmtx() {
3085
+ const charstrings = font.charstrings;
3086
+ const cffWidths = font.cff ? font.cff.widths : null;
3087
+ let hmtx = "\x00\x00\x00\x00"; // Fake .notdef
3088
+ for (let i = 1, ii = numGlyphs; i < ii; i++) {
3089
+ let width = 0;
3090
+ if (charstrings) {
3091
+ const charstring = charstrings[i - 1];
3092
+ width = "width" in charstring ? charstring.width : 0;
3093
+ } else if (cffWidths) {
3094
+ width = Math.ceil(cffWidths[i] || 0);
3095
+ }
3096
+ hmtx += string16(width) + string16(0);
3097
+ }
3098
+ return hmtx;
3099
+ })()
3100
+ );
3101
+
3102
+ // Maximum profile
3103
+ builder.addTable(
3104
+ "maxp",
3105
+ "\x00\x00\x50\x00" + string16(numGlyphs) // Version number
3106
+ ); // Num of glyphs
3107
+
3108
+ // Naming tables
3109
+ builder.addTable("name", createNameTable(fontName));
3110
+
3111
+ // PostScript information
3112
+ builder.addTable("post", createPostTable(properties));
3113
+
3114
+ return builder.toArray();
3115
+ }
3116
+
3117
+ get spaceWidth() {
3118
+ // trying to estimate space character width
3119
+ const possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
3120
+ let width;
3121
+ for (const glyphName of possibleSpaceReplacements) {
3122
+ // if possible, getting width by glyph name
3123
+ if (glyphName in this.widths) {
3124
+ width = this.widths[glyphName];
3125
+ break;
3126
+ }
3127
+ const glyphsUnicodeMap = getGlyphsUnicode();
3128
+ const glyphUnicode = glyphsUnicodeMap[glyphName];
3129
+ // finding the charcode via unicodeToCID map
3130
+ let charcode = 0;
3131
+ if (this.composite && this.cMap.contains(glyphUnicode)) {
3132
+ charcode = this.cMap.lookup(glyphUnicode);
3133
+
3134
+ if (typeof charcode === "string") {
3135
+ charcode = convertCidString(glyphUnicode, charcode);
3136
+ }
3137
+ }
3138
+ // ... via toUnicode map
3139
+
3140
+ // setting it to unicode if negative or undefined
3141
+ if (charcode <= 0) {
3142
+ charcode = glyphUnicode;
3143
+ }
3144
+ // trying to get width via charcode
3145
+ width = this.widths[charcode];
3146
+ if (width) {
3147
+ break; // the non-zero width found
3148
+ }
3149
+ }
3150
+ return shadow(this, "spaceWidth", width || this.defaultWidth);
3151
+ }
3152
+
3153
+ /**
3154
+ * @private
3155
+ */
3156
+ _charToGlyph(charcode, isSpace = false) {
3157
+ let glyph = this._glyphCache[charcode];
3158
+ // All `Glyph`-properties, except `isSpace` in multi-byte strings,
3159
+ // depend indirectly on the `charcode`.
3160
+ if (glyph?.isSpace === isSpace) {
3161
+ return glyph;
3162
+ }
3163
+ let fontCharCode, width, operatorListId;
3164
+
3165
+ let widthCode = charcode;
3166
+ if (this.cMap?.contains(charcode)) {
3167
+ widthCode = this.cMap.lookup(charcode);
3168
+
3169
+ if (typeof widthCode === "string") {
3170
+ widthCode = convertCidString(charcode, widthCode);
3171
+ }
3172
+ }
3173
+ width = this.widths[widthCode];
3174
+ if (typeof width !== "number") {
3175
+ width = this.defaultWidth;
3176
+ }
3177
+ const vmetric = this.vmetrics?.[widthCode];
3178
+
3179
+ let unicode = this.toUnicode.get(charcode) || charcode;
3180
+ if (typeof unicode === "number") {
3181
+ unicode = String.fromCharCode(unicode);
3182
+ }
3183
+
3184
+ let isInFont = this.toFontChar[charcode] !== undefined;
3185
+ // First try the toFontChar map, if it's not there then try falling
3186
+ // back to the char code.
3187
+ fontCharCode = this.toFontChar[charcode] || charcode;
3188
+ if (this.missingFile) {
3189
+ const glyphName =
3190
+ this.differences[charcode] || this.defaultEncoding[charcode];
3191
+ if (
3192
+ (glyphName === ".notdef" || glyphName === "") &&
3193
+ this.type === "Type1"
3194
+ ) {
3195
+ // .notdef glyphs should be invisible in non-embedded Type1 fonts, so
3196
+ // replace them with spaces.
3197
+ fontCharCode = 0x20;
3198
+ }
3199
+ fontCharCode = mapSpecialUnicodeValues(fontCharCode);
3200
+ }
3201
+
3202
+ if (this.isType3Font) {
3203
+ // Font char code in this case is actually a glyph name.
3204
+ operatorListId = fontCharCode;
3205
+ }
3206
+
3207
+ let accent = null;
3208
+ if (this.seacMap?.[charcode]) {
3209
+ isInFont = true;
3210
+ const seac = this.seacMap[charcode];
3211
+ fontCharCode = seac.baseFontCharCode;
3212
+ accent = {
3213
+ fontChar: String.fromCodePoint(seac.accentFontCharCode),
3214
+ offset: seac.accentOffset,
3215
+ };
3216
+ }
3217
+
3218
+ let fontChar = "";
3219
+ if (typeof fontCharCode === "number") {
3220
+ if (fontCharCode <= 0x10ffff) {
3221
+ fontChar = String.fromCodePoint(fontCharCode);
3222
+ } else {
3223
+ warn(`charToGlyph - invalid fontCharCode: ${fontCharCode}`);
3224
+ }
3225
+ }
3226
+ // unicode中的57344-63743属于私有化使用,所以无法直接在console中显示形状,可能是某个字体的文件里面去获取的值
3227
+ // 这就是为什么我们无法直接从这里拿到这个character的显示出来的值,类似A-Z这样,而是从字体文件中拿到
3228
+
3229
+ glyph = new Glyph(
3230
+ charcode,
3231
+ fontChar,
3232
+ unicode,
3233
+ accent,
3234
+ width,
3235
+ vmetric,
3236
+ operatorListId,
3237
+ isSpace,
3238
+ isInFont
3239
+ );
3240
+ return (this._glyphCache[charcode] = glyph);
3241
+ }
3242
+
3243
+ charsToGlyphs(chars) {
3244
+ // If we translated this string before, just grab it from the cache.
3245
+ let glyphs = this._charsCache[chars];
3246
+ if (glyphs) {
3247
+ return glyphs;
3248
+ }
3249
+ glyphs = [];
3250
+
3251
+ if (this.cMap) {
3252
+ // Composite fonts have multi-byte strings, convert the string from
3253
+ // single-byte to multi-byte.
3254
+ const c = Object.create(null),
3255
+ ii = chars.length;
3256
+ let i = 0;
3257
+ while (i < ii) {
3258
+ this.cMap.readCharCode(chars, i, c);
3259
+ const { charcode, length } = c;
3260
+ i += length;
3261
+ // Space is char with code 0x20 and length 1 in multiple-byte codes.
3262
+ const glyph = this._charToGlyph(
3263
+ charcode,
3264
+ length === 1 && chars.charCodeAt(i - 1) === 0x20
3265
+ );
3266
+ glyphs.push(glyph);
3267
+ }
3268
+ } else {
3269
+ for (let i = 0, ii = chars.length; i < ii; ++i) {
3270
+ const charcode = chars.charCodeAt(i);
3271
+ const glyph = this._charToGlyph(charcode, charcode === 0x20);
3272
+ glyphs.push(glyph);
3273
+ }
3274
+ }
3275
+
3276
+ // Enter the translated string into the cache.
3277
+ return (this._charsCache[chars] = glyphs);
3278
+ }
3279
+
3280
+ /**
3281
+ * Chars can have different sizes (depends on the encoding).
3282
+ * @param {String} a string encoded with font encoding.
3283
+ * @returns {Array<Array<number>>} the positions of each char in the string.
3284
+ */
3285
+ getCharPositions(chars) {
3286
+ // This function doesn't use a cache because
3287
+ // it's called only when saving or printing.
3288
+ const positions = [];
3289
+
3290
+ if (this.cMap) {
3291
+ const c = Object.create(null);
3292
+ let i = 0;
3293
+ while (i < chars.length) {
3294
+ this.cMap.readCharCode(chars, i, c);
3295
+ const length = c.length;
3296
+ positions.push([i, i + length]);
3297
+ i += length;
3298
+ }
3299
+ } else {
3300
+ for (let i = 0, ii = chars.length; i < ii; ++i) {
3301
+ positions.push([i, i + 1]);
3302
+ }
3303
+ }
3304
+
3305
+ return positions;
3306
+ }
3307
+
3308
+ get glyphCacheValues() {
3309
+ return Object.values(this._glyphCache);
3310
+ }
3311
+
3312
+ /**
3313
+ * Encode a js string using font encoding.
3314
+ * The resulting array contains an encoded string at even positions
3315
+ * (can be empty) and a non-encoded one at odd positions.
3316
+ * @param {String} a js string.
3317
+ * @returns {Array<String>} an array of encoded strings or non-encoded ones.
3318
+ */
3319
+ encodeString(str) {
3320
+ const buffers = [];
3321
+ const currentBuf = [];
3322
+
3323
+ // buffers will contain: encoded, non-encoded, encoded, ...
3324
+ // currentBuf is pushed in buffers each time there is a change.
3325
+ // So when buffers.length is odd then the last string is an encoded one
3326
+ // and currentBuf contains non-encoded chars.
3327
+ const hasCurrentBufErrors = () => buffers.length % 2 === 1;
3328
+
3329
+ const getCharCode =
3330
+ this.toUnicode instanceof IdentityToUnicodeMap
3331
+ ? unicode => this.toUnicode.charCodeOf(unicode)
3332
+ : unicode => this.toUnicode.charCodeOf(String.fromCodePoint(unicode));
3333
+
3334
+ for (let i = 0, ii = str.length; i < ii; i++) {
3335
+ const unicode = str.codePointAt(i);
3336
+ if (unicode > 0xd7ff && (unicode < 0xe000 || unicode > 0xfffd)) {
3337
+ // unicode is represented by two uint16
3338
+ i++;
3339
+ }
3340
+ if (this.toUnicode) {
3341
+ const charCode = getCharCode(unicode);
3342
+ if (charCode !== -1) {
3343
+ if (hasCurrentBufErrors()) {
3344
+ buffers.push(currentBuf.join(""));
3345
+ currentBuf.length = 0;
3346
+ }
3347
+ const charCodeLength = this.cMap
3348
+ ? this.cMap.getCharCodeLength(charCode)
3349
+ : 1;
3350
+ for (let j = charCodeLength - 1; j >= 0; j--) {
3351
+ currentBuf.push(String.fromCharCode((charCode >> (8 * j)) & 0xff));
3352
+ }
3353
+ continue;
3354
+ }
3355
+ }
3356
+
3357
+ // unicode can't be encoded
3358
+ if (!hasCurrentBufErrors()) {
3359
+ buffers.push(currentBuf.join(""));
3360
+ currentBuf.length = 0;
3361
+ }
3362
+ currentBuf.push(String.fromCodePoint(unicode));
3363
+ }
3364
+
3365
+ buffers.push(currentBuf.join(""));
3366
+
3367
+ return buffers;
3368
+ }
3369
+ }
3370
+
3371
+ class ErrorFont {
3372
+ constructor(error) {
3373
+ this.error = error;
3374
+ this.loadedName = "g_font_error";
3375
+ this.missingFile = true;
3376
+ }
3377
+
3378
+ charsToGlyphs() {
3379
+ return [];
3380
+ }
3381
+
3382
+ encodeString(chars) {
3383
+ return [chars];
3384
+ }
3385
+
3386
+ exportData(extraProperties = false) {
3387
+ return { error: this.error };
3388
+ }
3389
+ }
3390
+
3391
+ export { ErrorFont, Font };