docvortex 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (364) hide show
  1. docvortex/__init__.py +21 -0
  2. docvortex/analyzers/__init__.py +3 -0
  3. docvortex/analyzers/native/__init__.py +37 -0
  4. docvortex/analyzers/native/_shared/__init__.py +3 -0
  5. docvortex/analyzers/native/_shared/hyperlink.py +16 -0
  6. docvortex/analyzers/native/_shared/image.py +8 -0
  7. docvortex/analyzers/native/_shared/markup/__init__.py +47 -0
  8. docvortex/analyzers/native/_shared/markup/anchors.py +30 -0
  9. docvortex/analyzers/native/_shared/markup/formula.py +37 -0
  10. docvortex/analyzers/native/_shared/markup/projector.py +57 -0
  11. docvortex/analyzers/native/_shared/markup/styles.py +19 -0
  12. docvortex/analyzers/native/_shared/mathml.py +17 -0
  13. docvortex/analyzers/native/_shared/names.py +7 -0
  14. docvortex/analyzers/native/_shared/xycut.py +414 -0
  15. docvortex/analyzers/native/contracts.py +44 -0
  16. docvortex/analyzers/native/csv.py +351 -0
  17. docvortex/analyzers/native/epub/__init__.py +18 -0
  18. docvortex/analyzers/native/epub/constants.py +45 -0
  19. docvortex/analyzers/native/epub/converter.py +80 -0
  20. docvortex/analyzers/native/epub/errors.py +20 -0
  21. docvortex/analyzers/native/epub/metadata.py +31 -0
  22. docvortex/analyzers/native/epub/package.py +649 -0
  23. docvortex/analyzers/native/epub/xhtml.py +306 -0
  24. docvortex/analyzers/native/html/__init__.py +6 -0
  25. docvortex/analyzers/native/html/anchors.py +271 -0
  26. docvortex/analyzers/native/html/constants.py +25 -0
  27. docvortex/analyzers/native/html/contracts.py +7 -0
  28. docvortex/analyzers/native/html/converter.py +117 -0
  29. docvortex/analyzers/native/html/document.py +389 -0
  30. docvortex/analyzers/native/html/errors.py +12 -0
  31. docvortex/analyzers/native/html/resources.py +365 -0
  32. docvortex/analyzers/native/html/selector.py +421 -0
  33. docvortex/analyzers/native/models.py +209 -0
  34. docvortex/analyzers/native/ofd/__init__.py +14 -0
  35. docvortex/analyzers/native/ofd/constants.py +59 -0
  36. docvortex/analyzers/native/ofd/converter.py +31 -0
  37. docvortex/analyzers/native/ofd/errors.py +16 -0
  38. docvortex/analyzers/native/ofd/geometry.py +215 -0
  39. docvortex/analyzers/native/ofd/images.py +124 -0
  40. docvortex/analyzers/native/ofd/metadata.py +53 -0
  41. docvortex/analyzers/native/ofd/models.py +170 -0
  42. docvortex/analyzers/native/ofd/package.py +346 -0
  43. docvortex/analyzers/native/ofd/path.py +201 -0
  44. docvortex/analyzers/native/ofd/reading_order.py +293 -0
  45. docvortex/analyzers/native/ofd/resources.py +122 -0
  46. docvortex/analyzers/native/ofd/scene.py +347 -0
  47. docvortex/analyzers/native/ofd/table.py +240 -0
  48. docvortex/analyzers/native/ofd/text.py +521 -0
  49. docvortex/analyzers/native/office/__init__.py +3 -0
  50. docvortex/analyzers/native/office/doc/__init__.py +3 -0
  51. docvortex/analyzers/native/office/doc/bookmarks.py +81 -0
  52. docvortex/analyzers/native/office/doc/doc_converter.py +573 -0
  53. docvortex/analyzers/native/office/doc/fib.py +261 -0
  54. docvortex/analyzers/native/office/doc/fields.py +101 -0
  55. docvortex/analyzers/native/office/doc/formatting.py +171 -0
  56. docvortex/analyzers/native/office/doc/images.py +162 -0
  57. docvortex/analyzers/native/office/doc/lists.py +356 -0
  58. docvortex/analyzers/native/office/doc/models.py +164 -0
  59. docvortex/analyzers/native/office/doc/parser.py +851 -0
  60. docvortex/analyzers/native/office/doc/pieces.py +256 -0
  61. docvortex/analyzers/native/office/doc/records.py +40 -0
  62. docvortex/analyzers/native/office/doc/sprm.py +269 -0
  63. docvortex/analyzers/native/office/doc/styles.py +215 -0
  64. docvortex/analyzers/native/office/docx/__init__.py +3 -0
  65. docvortex/analyzers/native/office/docx/context.py +71 -0
  66. docvortex/analyzers/native/office/docx/docx_converter.py +614 -0
  67. docvortex/analyzers/native/office/docx/equationxml.py +119 -0
  68. docvortex/analyzers/native/office/docx/fields.py +816 -0
  69. docvortex/analyzers/native/office/docx/formatting_types.py +23 -0
  70. docvortex/analyzers/native/office/docx/main.py +50 -0
  71. docvortex/analyzers/native/office/docx/numbering.py +491 -0
  72. docvortex/analyzers/native/office/docx/office_xml.py +57 -0
  73. docvortex/analyzers/native/office/docx/package_normalizer.py +248 -0
  74. docvortex/analyzers/native/office/docx/resources.py +526 -0
  75. docvortex/analyzers/native/office/docx/styles.py +693 -0
  76. docvortex/analyzers/native/office/docx/tables.py +515 -0
  77. docvortex/analyzers/native/office/equation/__init__.py +3 -0
  78. docvortex/analyzers/native/office/equation/image.py +470 -0
  79. docvortex/analyzers/native/office/equation/latex_dict.py +324 -0
  80. docvortex/analyzers/native/office/equation/mtef.py +885 -0
  81. docvortex/analyzers/native/office/equation/mtef_v5.py +941 -0
  82. docvortex/analyzers/native/office/equation/omml.py +561 -0
  83. docvortex/analyzers/native/office/equation/ooxml.py +62 -0
  84. docvortex/analyzers/native/office/errors.py +33 -0
  85. docvortex/analyzers/native/office/image.py +307 -0
  86. docvortex/analyzers/native/office/legacy/__init__.py +3 -0
  87. docvortex/analyzers/native/office/legacy/binary.py +43 -0
  88. docvortex/analyzers/native/office/legacy/officeart.py +362 -0
  89. docvortex/analyzers/native/office/legacy/ole.py +110 -0
  90. docvortex/analyzers/native/office/limits.py +12 -0
  91. docvortex/analyzers/native/office/odf/__init__.py +3 -0
  92. docvortex/analyzers/native/office/odf/chart.py +76 -0
  93. docvortex/analyzers/native/office/odf/constants.py +70 -0
  94. docvortex/analyzers/native/office/odf/converters.py +403 -0
  95. docvortex/analyzers/native/office/odf/errors.py +18 -0
  96. docvortex/analyzers/native/office/odf/metadata.py +91 -0
  97. docvortex/analyzers/native/office/odf/models.py +176 -0
  98. docvortex/analyzers/native/office/odf/package.py +270 -0
  99. docvortex/analyzers/native/office/odf/styles.py +329 -0
  100. docvortex/analyzers/native/office/odf/table.py +469 -0
  101. docvortex/analyzers/native/office/odf/text.py +1002 -0
  102. docvortex/analyzers/native/office/ooxml_chart.py +1016 -0
  103. docvortex/analyzers/native/office/opc.py +38 -0
  104. docvortex/analyzers/native/office/ppt/__init__.py +3 -0
  105. docvortex/analyzers/native/office/ppt/models.py +118 -0
  106. docvortex/analyzers/native/office/ppt/parser.py +1895 -0
  107. docvortex/analyzers/native/office/ppt/ppt_converter.py +292 -0
  108. docvortex/analyzers/native/office/ppt/records.py +131 -0
  109. docvortex/analyzers/native/office/ppt/style_text.py +247 -0
  110. docvortex/analyzers/native/office/pptx/__init__.py +3 -0
  111. docvortex/analyzers/native/office/pptx/context.py +113 -0
  112. docvortex/analyzers/native/office/pptx/lists.py +558 -0
  113. docvortex/analyzers/native/office/pptx/main.py +20 -0
  114. docvortex/analyzers/native/office/pptx/package_normalizer.py +321 -0
  115. docvortex/analyzers/native/office/pptx/pptx_converter.py +323 -0
  116. docvortex/analyzers/native/office/pptx/resources.py +329 -0
  117. docvortex/analyzers/native/office/pptx/shapes.py +393 -0
  118. docvortex/analyzers/native/office/pptx/text_styles.py +625 -0
  119. docvortex/analyzers/native/office/pptx/titles.py +178 -0
  120. docvortex/analyzers/native/office/rich_text.py +420 -0
  121. docvortex/analyzers/native/office/rtf/__init__.py +3 -0
  122. docvortex/analyzers/native/office/rtf/converter.py +708 -0
  123. docvortex/analyzers/native/office/rtf/lexer.py +213 -0
  124. docvortex/analyzers/native/office/rtf/math.py +339 -0
  125. docvortex/analyzers/native/office/rtf/models.py +185 -0
  126. docvortex/analyzers/native/office/rtf/parser.py +1553 -0
  127. docvortex/analyzers/native/office/spreadsheet/__init__.py +3 -0
  128. docvortex/analyzers/native/office/spreadsheet/html.py +81 -0
  129. docvortex/analyzers/native/office/spreadsheet/models.py +79 -0
  130. docvortex/analyzers/native/office/spreadsheet/projector.py +928 -0
  131. docvortex/analyzers/native/office/streams.py +18 -0
  132. docvortex/analyzers/native/office/xls/__init__.py +3 -0
  133. docvortex/analyzers/native/office/xls/chart.py +132 -0
  134. docvortex/analyzers/native/office/xls/embedded_chart.py +299 -0
  135. docvortex/analyzers/native/office/xls/models.py +109 -0
  136. docvortex/analyzers/native/office/xls/number_format.py +521 -0
  137. docvortex/analyzers/native/office/xls/parser.py +1145 -0
  138. docvortex/analyzers/native/office/xls/records.py +201 -0
  139. docvortex/analyzers/native/office/xls/strings.py +205 -0
  140. docvortex/analyzers/native/office/xls/xls_converter.py +354 -0
  141. docvortex/analyzers/native/office/xlsx/__init__.py +3 -0
  142. docvortex/analyzers/native/office/xlsx/main.py +20 -0
  143. docvortex/analyzers/native/office/xlsx/ooxml_ole.py +522 -0
  144. docvortex/analyzers/native/office/xlsx/package_normalizer.py +310 -0
  145. docvortex/analyzers/native/office/xlsx/xlsx_converter.py +716 -0
  146. docvortex/analyzers/native/pdf/__init__.py +3 -0
  147. docvortex/analyzers/native/pdf/auxiliary_text.py +1671 -0
  148. docvortex/analyzers/native/pdf/char_geometry.py +1662 -0
  149. docvortex/analyzers/native/pdf/code_blocks.py +535 -0
  150. docvortex/analyzers/native/pdf/formulas.py +1985 -0
  151. docvortex/analyzers/native/pdf/geometry.py +281 -0
  152. docvortex/analyzers/native/pdf/graphics.py +1501 -0
  153. docvortex/analyzers/native/pdf/index_blocks.py +268 -0
  154. docvortex/analyzers/native/pdf/inline/__init__.py +3 -0
  155. docvortex/analyzers/native/pdf/inline/common.py +112 -0
  156. docvortex/analyzers/native/pdf/inline/detection.py +590 -0
  157. docvortex/analyzers/native/pdf/inline/matching.py +1185 -0
  158. docvortex/analyzers/native/pdf/inline/materialize.py +457 -0
  159. docvortex/analyzers/native/pdf/inline/scripts.py +975 -0
  160. docvortex/analyzers/native/pdf/inline/types.py +385 -0
  161. docvortex/analyzers/native/pdf/line_layout.py +1106 -0
  162. docvortex/analyzers/native/pdf/line_merging.py +1223 -0
  163. docvortex/analyzers/native/pdf/models.py +246 -0
  164. docvortex/analyzers/native/pdf/native_text.py +1004 -0
  165. docvortex/analyzers/native/pdf/pipeline.py +1390 -0
  166. docvortex/analyzers/native/pdf/script_geometry.py +636 -0
  167. docvortex/analyzers/native/pdf/shared.py +30 -0
  168. docvortex/analyzers/native/pdf/spatial_text.py +383 -0
  169. docvortex/analyzers/native/pdf/table_annotations.py +446 -0
  170. docvortex/analyzers/native/pdf/table_constants.py +48 -0
  171. docvortex/analyzers/native/pdf/table_detection.py +227 -0
  172. docvortex/analyzers/native/pdf/table_filled_grid.py +218 -0
  173. docvortex/analyzers/native/pdf/table_geometry.py +40 -0
  174. docvortex/analyzers/native/pdf/table_materialization.py +444 -0
  175. docvortex/analyzers/native/pdf/table_recovery/__init__.py +15 -0
  176. docvortex/analyzers/native/pdf/table_recovery/candidate.py +356 -0
  177. docvortex/analyzers/native/pdf/table_recovery/contracts.py +154 -0
  178. docvortex/analyzers/native/pdf/table_recovery/engine.py +609 -0
  179. docvortex/analyzers/native/pdf/table_recovery/geometry.py +164 -0
  180. docvortex/analyzers/native/pdf/table_recovery/sparse_common.py +85 -0
  181. docvortex/analyzers/native/pdf/table_recovery/sparse_hybrid.py +804 -0
  182. docvortex/analyzers/native/pdf/table_recovery/sparse_multiline.py +1122 -0
  183. docvortex/analyzers/native/pdf/table_recovery/text.py +414 -0
  184. docvortex/analyzers/native/pdf/table_recovery/text_grid.py +618 -0
  185. docvortex/analyzers/native/pdf/table_recovery/vector.py +1931 -0
  186. docvortex/analyzers/native/pdf/table_rows.py +34 -0
  187. docvortex/analyzers/native/pdf/table_rules.py +1129 -0
  188. docvortex/analyzers/native/pdf/table_text_styles.py +283 -0
  189. docvortex/analyzers/native/pdf/tables.py +147 -0
  190. docvortex/analyzers/native/pdf/text_assembly/__init__.py +3 -0
  191. docvortex/analyzers/native/pdf/text_assembly/annotations.py +581 -0
  192. docvortex/analyzers/native/pdf/text_assembly/assembly.py +292 -0
  193. docvortex/analyzers/native/pdf/text_assembly/common.py +477 -0
  194. docvortex/analyzers/native/pdf/text_assembly/footnotes.py +394 -0
  195. docvortex/analyzers/native/pdf/text_assembly/merging.py +1274 -0
  196. docvortex/analyzers/native/pdf/text_assembly/rows.py +692 -0
  197. docvortex/analyzers/native/pdf/text_blocks.py +82 -0
  198. docvortex/analyzers/native/pdf/text_styles.py +55 -0
  199. docvortex/analyzers/native/pdf/title_analysis/__init__.py +3 -0
  200. docvortex/analyzers/native/pdf/title_analysis/body_profile.py +215 -0
  201. docvortex/analyzers/native/pdf/title_analysis/common.py +117 -0
  202. docvortex/analyzers/native/pdf/title_analysis/document_profile.py +164 -0
  203. docvortex/analyzers/native/pdf/title_analysis/lane_titles.py +758 -0
  204. docvortex/analyzers/native/pdf/title_analysis/page_titles.py +1024 -0
  205. docvortex/analyzers/native/pdf/title_analysis/prototype.py +194 -0
  206. docvortex/analyzers/native/pdf/title_analysis/structural.py +1081 -0
  207. docvortex/analyzers/native/pdf/titles.py +75 -0
  208. docvortex/analyzers/native/pdf/typography.py +19 -0
  209. docvortex/analyzers/native/pdf/visual_annotations.py +1262 -0
  210. docvortex/api.py +180 -0
  211. docvortex/assets/__init__.py +5 -0
  212. docvortex/assets/store.py +51 -0
  213. docvortex/cli.py +54 -0
  214. docvortex/codecs/__init__.py +3 -0
  215. docvortex/codecs/html/__init__.py +22 -0
  216. docvortex/codecs/html/contracts.py +236 -0
  217. docvortex/codecs/html/materializer.py +331 -0
  218. docvortex/codecs/html/parser.py +763 -0
  219. docvortex/codecs/html/resources.py +34 -0
  220. docvortex/codecs/json.py +17 -0
  221. docvortex/content/__init__.py +5 -0
  222. docvortex/content/inline.py +248 -0
  223. docvortex/content/markup/__init__.py +44 -0
  224. docvortex/content/markup/anchors.py +188 -0
  225. docvortex/content/markup/formula.py +280 -0
  226. docvortex/content/markup/projector.py +1237 -0
  227. docvortex/content/markup/styles.py +327 -0
  228. docvortex/content/mathml.py +167 -0
  229. docvortex/content/normalization.py +188 -0
  230. docvortex/content/spans.py +183 -0
  231. docvortex/content/table/__init__.py +18 -0
  232. docvortex/content/table/blocks.py +152 -0
  233. docvortex/content/table/content.py +425 -0
  234. docvortex/content/table/document.py +104 -0
  235. docvortex/content/table/html.py +399 -0
  236. docvortex/content/table/models.py +76 -0
  237. docvortex/content/table/rules.py +42 -0
  238. docvortex/content/table/structure.py +221 -0
  239. docvortex/content/tree.py +5 -0
  240. docvortex/document/__init__.py +3 -0
  241. docvortex/document/contracts.py +22 -0
  242. docvortex/document/detection.py +389 -0
  243. docvortex/document/filetypes.py +175 -0
  244. docvortex/document/page_range.py +167 -0
  245. docvortex/document/pdf/__init__.py +19 -0
  246. docvortex/document/pdf/classify.py +1138 -0
  247. docvortex/document/pdf/constants.py +132 -0
  248. docvortex/document/pdf/diagnostics.py +350 -0
  249. docvortex/document/pdf/document.py +582 -0
  250. docvortex/document/pdf/font_runtime.py +335 -0
  251. docvortex/document/pdf/geometry.py +31 -0
  252. docvortex/document/pdf/images.py +654 -0
  253. docvortex/document/pdf/native_annotations.py +367 -0
  254. docvortex/document/pdf/native_contracts.py +169 -0
  255. docvortex/document/pdf/native_coordinates.py +216 -0
  256. docvortex/document/pdf/native_lifecycle.py +16 -0
  257. docvortex/document/pdf/native_objects.py +902 -0
  258. docvortex/document/pdf/native_text_geometry.py +315 -0
  259. docvortex/document/pdf/pdfium.py +325 -0
  260. docvortex/document/pdf/raster.py +46 -0
  261. docvortex/document/pdf/text/__init__.py +62 -0
  262. docvortex/document/pdf/text/contracts.py +211 -0
  263. docvortex/document/pdf/text/extract.py +165 -0
  264. docvortex/document/pdf/text/geometry.py +16 -0
  265. docvortex/document/pdf/text/groups.py +162 -0
  266. docvortex/document/pdf/visual_geometry.py +201 -0
  267. docvortex/document/pdf/visuals.py +343 -0
  268. docvortex/document/source.py +92 -0
  269. docvortex/errors.py +21 -0
  270. docvortex/export/__init__.py +3 -0
  271. docvortex/export/bundle.py +98 -0
  272. docvortex/export/files.py +66 -0
  273. docvortex/export/middle.py +208 -0
  274. docvortex/foundation/__init__.py +3 -0
  275. docvortex/foundation/geometry.py +125 -0
  276. docvortex/foundation/hyperlink.py +65 -0
  277. docvortex/foundation/image.py +48 -0
  278. docvortex/foundation/image_encoding.py +30 -0
  279. docvortex/foundation/image_payload.py +280 -0
  280. docvortex/foundation/language.py +92 -0
  281. docvortex/foundation/platform.py +38 -0
  282. docvortex/foundation/text.py +153 -0
  283. docvortex/foundation/type_identity.py +20 -0
  284. docvortex/foundation/xml_names.py +20 -0
  285. docvortex/options.py +30 -0
  286. docvortex/postprocess/__init__.py +3 -0
  287. docvortex/postprocess/content.py +53 -0
  288. docvortex/postprocess/document.py +19 -0
  289. docvortex/postprocess/lists.py +236 -0
  290. docvortex/postprocess/page_blocks.py +214 -0
  291. docvortex/postprocess/pages.py +95 -0
  292. docvortex/postprocess/paragraphs.py +580 -0
  293. docvortex/postprocess/visual.py +715 -0
  294. docvortex/render/__init__.py +48 -0
  295. docvortex/render/_internal/__init__.py +3 -0
  296. docvortex/render/_internal/common/__init__.py +3 -0
  297. docvortex/render/_internal/common/context.py +43 -0
  298. docvortex/render/_internal/common/html_table.py +178 -0
  299. docvortex/render/_internal/common/index.py +33 -0
  300. docvortex/render/_internal/common/list_items.py +158 -0
  301. docvortex/render/_internal/common/planner.py +140 -0
  302. docvortex/render/_internal/docx/__init__.py +3 -0
  303. docvortex/render/_internal/docx/assets.py +202 -0
  304. docvortex/render/_internal/docx/inline.py +434 -0
  305. docvortex/render/_internal/docx/math.py +220 -0
  306. docvortex/render/_internal/docx/renderer.py +905 -0
  307. docvortex/render/_internal/docx/styles.py +195 -0
  308. docvortex/render/_internal/docx/table.py +442 -0
  309. docvortex/render/_internal/epub/__init__.py +5 -0
  310. docvortex/render/_internal/epub/assets.py +173 -0
  311. docvortex/render/_internal/epub/package.py +249 -0
  312. docvortex/render/_internal/epub/renderer.py +1156 -0
  313. docvortex/render/_internal/html/__init__.py +3 -0
  314. docvortex/render/_internal/html/inline.py +346 -0
  315. docvortex/render/_internal/html/renderer.py +1041 -0
  316. docvortex/render/_internal/html/sanitizer.py +478 -0
  317. docvortex/render/_internal/html/table.py +121 -0
  318. docvortex/render/_internal/latex/__init__.py +1 -0
  319. docvortex/render/_internal/latex/assets.py +85 -0
  320. docvortex/render/_internal/latex/inline.py +145 -0
  321. docvortex/render/_internal/latex/renderer.py +506 -0
  322. docvortex/render/_internal/latex/table.py +347 -0
  323. docvortex/render/_internal/markdown/__init__.py +3 -0
  324. docvortex/render/_internal/markdown/assets.py +78 -0
  325. docvortex/render/_internal/markdown/blocks.py +635 -0
  326. docvortex/render/_internal/markdown/escaping.py +51 -0
  327. docvortex/render/_internal/markdown/inline.py +260 -0
  328. docvortex/render/_internal/markdown/renderer.py +93 -0
  329. docvortex/render/_internal/markdown/table.py +281 -0
  330. docvortex/render/_internal/pdf/__init__.py +3 -0
  331. docvortex/render/_internal/pdf/assets.py +197 -0
  332. docvortex/render/_internal/pdf/formula.py +417 -0
  333. docvortex/render/_internal/pdf/inline.py +343 -0
  334. docvortex/render/_internal/pdf/renderer.py +734 -0
  335. docvortex/render/_internal/pdf/styles.py +206 -0
  336. docvortex/render/_internal/pdf/table.py +272 -0
  337. docvortex/render/_internal/structured_content/__init__.py +3 -0
  338. docvortex/render/_internal/structured_content/renderer.py +193 -0
  339. docvortex/render/api.py +199 -0
  340. docvortex/render/contracts.py +205 -0
  341. docvortex/render/docx.py +38 -0
  342. docvortex/render/epub.py +35 -0
  343. docvortex/render/fragments.py +70 -0
  344. docvortex/render/html.py +29 -0
  345. docvortex/render/latex.py +24 -0
  346. docvortex/render/markdown.py +50 -0
  347. docvortex/render/pdf.py +25 -0
  348. docvortex/render/structured_content.py +23 -0
  349. docvortex/resources/epub/docvortex.css +91 -0
  350. docvortex/resources/fasttext-langdetect/lid.176.ftz +0 -0
  351. docvortex/resources/fonts/DroidSansFallbackFull.ttf +0 -0
  352. docvortex/resources/fonts/NOTICE +190 -0
  353. docvortex/resources/fonts/manifest.json +9 -0
  354. docvortex/resources/html/docvortex.css +601 -0
  355. docvortex/resources/html/docvortex.min.css +1 -0
  356. docvortex/result.py +91 -0
  357. docvortex/schema.py +1141 -0
  358. docvortex/version.py +3 -0
  359. docvortex-0.2.1.dist-info/METADATA +193 -0
  360. docvortex-0.2.1.dist-info/RECORD +364 -0
  361. docvortex-0.2.1.dist-info/WHEEL +5 -0
  362. docvortex-0.2.1.dist-info/entry_points.txt +2 -0
  363. docvortex-0.2.1.dist-info/licenses/LICENSE.md +21 -0
  364. docvortex-0.2.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,283 @@
1
+ """使用 PDF 原生字符几何为高置信表格 HTML 恢复上下标。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ import html
6
+ from collections import defaultdict
7
+ from typing import Any
8
+
9
+ from ....document.pdf.text.contracts import Char
10
+
11
+ from ....schema import BBox
12
+ from .geometry import _bbox_union_many, _coerce_bbox
13
+ from .line_merging import _merge_overlapping_inline_text_clusters
14
+ from .models import _LineItem
15
+ from .native_text import _fill_native_typography
16
+ from .script_geometry import ScriptRole
17
+ from .table_recovery.candidate import serialize_native_table_html
18
+ from .table_recovery.contracts import (
19
+ NativeTableCell,
20
+ NativeTableGlyph,
21
+ NativeTableInput,
22
+ NativeTableResult,
23
+ NativeTableRule,
24
+ NativeTableText,
25
+ )
26
+ from .table_recovery.geometry import page_bbox_to_table_local
27
+ from .table_recovery.text import build_cell_text_parts
28
+ from .inline.scripts import _fraction_member_indices, _script_line_char_roles
29
+
30
+
31
+ def _table_char_map(chars: tuple[Char, ...]) -> dict[int, Char]:
32
+ """按合法 char_idx 建立页面字符查询表,重复索引保留首项。"""
33
+
34
+ output: dict[int, Char] = {}
35
+ for fallback_index, char in enumerate(chars):
36
+ char_idx = char.get("char_idx", fallback_index)
37
+ if isinstance(char_idx, bool) or not isinstance(char_idx, int):
38
+ continue
39
+ output.setdefault(char_idx, char)
40
+ return output
41
+
42
+
43
+ def _cell_glyphs(
44
+ result: NativeTableResult,
45
+ cell: NativeTableCell,
46
+ glyph_by_source: dict[int, NativeTableGlyph] | None = None,
47
+ ) -> list[NativeTableGlyph]:
48
+ """按 cell 的稳定字符来源收集并恢复视觉行内顺序。"""
49
+
50
+ if glyph_by_source is None:
51
+ glyph_by_source = {glyph.source_index: glyph for glyph in result.text.glyphs}
52
+ return sorted(
53
+ (glyph_by_source[source_index] for source_index in cell.source_char_indices if source_index in glyph_by_source),
54
+ key=lambda glyph: (glyph.visual_row, glyph.bbox[0], glyph.bbox[1], glyph.glyph_id),
55
+ )
56
+
57
+
58
+ def _cell_visual_lines(
59
+ glyphs: list[NativeTableGlyph],
60
+ chars_by_source: dict[int, Char],
61
+ page_size: tuple[float, float],
62
+ angle: int,
63
+ ) -> list[_LineItem]:
64
+ """把一个 cell 的 glyph 按 visual row 转换成正文公式分段使用的行。"""
65
+
66
+ grouped: dict[int, list[NativeTableGlyph]] = defaultdict(list)
67
+ for glyph in glyphs:
68
+ grouped[glyph.visual_row].append(glyph)
69
+
70
+ lines: list[_LineItem] = []
71
+ for visual_row, row_glyphs in sorted(grouped.items()):
72
+ ordered = sorted(row_glyphs, key=lambda glyph: (glyph.bbox[0], glyph.bbox[1], glyph.glyph_id))
73
+ chars = [chars_by_source[glyph.source_index] for glyph in ordered if glyph.source_index in chars_by_source]
74
+ bboxes = [bbox for char in chars if (bbox := _coerce_bbox(char.get("bbox"))) is not None]
75
+ if not chars or not bboxes:
76
+ continue
77
+ line = _LineItem(
78
+ text="".join(glyph.text for glyph in ordered),
79
+ bbox=_bbox_union_many(bboxes),
80
+ angle=angle,
81
+ source_index=visual_row,
82
+ chars=chars,
83
+ visual_row_id=visual_row,
84
+ )
85
+ _fill_native_typography(line, page_size)
86
+ lines.append(line)
87
+ return lines
88
+
89
+
90
+ def _rule_overlaps_boundary(
91
+ rule_bbox: BBox,
92
+ boundary_y: float,
93
+ boundary_left: float,
94
+ boundary_right: float,
95
+ tolerance: float,
96
+ ) -> bool:
97
+ """判断局部横线是否与一个逻辑 cell 的水平边界重合。"""
98
+
99
+ rule_y = (rule_bbox[1] + rule_bbox[3]) / 2.0
100
+ if abs(rule_y - boundary_y) > tolerance:
101
+ return False
102
+ overlap = min(rule_bbox[2], boundary_right) - max(rule_bbox[0], boundary_left)
103
+ rule_width = rule_bbox[2] - rule_bbox[0]
104
+ boundary_width = boundary_right - boundary_left
105
+ return overlap > 0 and overlap / max(1e-6, min(rule_width, boundary_width)) >= 0.5
106
+
107
+
108
+ def _non_grid_fraction_rules(
109
+ table_input: NativeTableInput,
110
+ result: NativeTableResult,
111
+ ) -> list[NativeTableRule]:
112
+ """移除与恢复后 cell 边界重合的横线,仅保留可能的分式线。"""
113
+
114
+ tolerance = max(0.75, 0.12 * result.text.median_glyph_height)
115
+ output: list[NativeTableRule] = []
116
+ for rule in table_input.drawing_lines:
117
+ if rule.orientation != "horizontal":
118
+ continue
119
+ local_bbox = page_bbox_to_table_local(rule.bbox, table_input.table_bbox, table_input.angle)
120
+ if local_bbox is None:
121
+ continue
122
+ is_grid_rule = any(
123
+ _rule_overlaps_boundary(
124
+ local_bbox,
125
+ boundary_y,
126
+ cell.bbox[0],
127
+ cell.bbox[2],
128
+ max(tolerance, rule.width),
129
+ )
130
+ for cell in result.cells
131
+ for boundary_y in (cell.bbox[1], cell.bbox[3])
132
+ )
133
+ if not is_grid_rule:
134
+ output.append(rule)
135
+ return output
136
+
137
+
138
+ def _drop_shifted_word_prefixes(chars: list[dict[str, Any]], roles: list[ScriptRole]) -> None:
139
+ """拒绝普通字母词仅首字母偏移的弱候选,完整同基线词由精炼层闭合。"""
140
+
141
+ start = 0
142
+ while start < len(chars):
143
+ if not str(chars[start].get("char", "")).isalpha():
144
+ start += 1
145
+ continue
146
+ end = start + 1
147
+ while end < len(chars) and str(chars[end].get("char", "")).isalpha():
148
+ end += 1
149
+ if end - start >= 2 and roles[start] != "body" and all(role == "body" for role in roles[start + 1 : end]):
150
+ roles[start] = "body"
151
+ start = end
152
+
153
+
154
+ def _cell_script_roles(
155
+ glyphs: list[NativeTableGlyph],
156
+ chars_by_source: dict[int, Char],
157
+ page_size: tuple[float, float],
158
+ angle: int,
159
+ tight_bboxes: dict[int, BBox],
160
+ origins: dict[int, tuple[float, float]],
161
+ fraction_members: set[int],
162
+ ) -> dict[int, ScriptRole]:
163
+ """在 cell 内按正文同款二维公式分段和字符几何返回稳定角色。"""
164
+
165
+ lines = _cell_visual_lines(glyphs, chars_by_source, page_size, angle)
166
+ if not lines:
167
+ return {}
168
+ segmented_lines = _merge_overlapping_inline_text_clusters(lines, page_size, [])
169
+ roles_by_source: dict[int, ScriptRole] = {}
170
+ for line in segmented_lines:
171
+ chars, roles, _body_counts, _formula_flags = _script_line_char_roles(
172
+ line,
173
+ page_size,
174
+ tight_bboxes,
175
+ origins,
176
+ fraction_members,
177
+ )
178
+ _drop_shifted_word_prefixes(chars, roles)
179
+ for char, role in zip(chars, roles, strict=True):
180
+ char_idx = char.get("char_idx")
181
+ if not isinstance(char_idx, int) or role == "body":
182
+ continue
183
+ previous = roles_by_source.get(char_idx)
184
+ roles_by_source[char_idx] = role if previous in {None, role} else "body"
185
+ return {source_index: role for source_index, role in roles_by_source.items() if role != "body"}
186
+
187
+
188
+ def _render_styled_cell(
189
+ cell: NativeTableCell,
190
+ glyphs: list[NativeTableGlyph],
191
+ median_height: float,
192
+ roles: dict[int, ScriptRole],
193
+ ) -> str:
194
+ """按旧文本重建规则安全插入平坦的 sup/sub 标签。"""
195
+
196
+ parts = build_cell_text_parts(glyphs, median_height)
197
+ if "".join(text for text, _source_index in parts) != cell.content:
198
+ return html.escape(cell.content, quote=False)
199
+
200
+ rendered: list[str] = []
201
+ active_role: ScriptRole = "body"
202
+ active_parts: list[str] = []
203
+
204
+ def flush() -> None:
205
+ """提交当前同角色片段,并只生成受信的上下标标签。"""
206
+
207
+ nonlocal active_parts
208
+ if not active_parts:
209
+ return
210
+ content = html.escape("".join(active_parts), quote=False)
211
+ if active_role == "sup":
212
+ rendered.append(f"<sup>{content}</sup>")
213
+ elif active_role == "sub":
214
+ rendered.append(f"<sub>{content}</sub>")
215
+ else:
216
+ rendered.append(content)
217
+ active_parts = []
218
+
219
+ for text, source_index in parts:
220
+ role = roles.get(source_index, "body") if source_index is not None else "body"
221
+ if role != active_role:
222
+ flush()
223
+ active_role = role
224
+ active_parts.append(text)
225
+ flush()
226
+ return "".join(rendered)
227
+
228
+
229
+ def render_native_table_html_with_scripts(
230
+ result: NativeTableResult,
231
+ table_input: NativeTableInput,
232
+ tight_bboxes: dict[int, BBox],
233
+ origins: dict[int, tuple[float, float]],
234
+ ) -> str:
235
+ """为高置信原生表格恢复上下标,证据不足时返回原始 HTML。"""
236
+
237
+ if not tight_bboxes or not origins:
238
+ return result.html
239
+ if not isinstance(getattr(result, "text", None), NativeTableText):
240
+ return result.html
241
+ chars_by_source = _table_char_map(table_input.chars)
242
+ fraction_rules = _non_grid_fraction_rules(table_input, result)
243
+ # 一张表只建立一次来源索引;保持原字典推导式的后项覆盖语义。
244
+ glyph_by_source = {glyph.source_index: glyph for glyph in result.text.glyphs}
245
+ cell_glyphs = {(cell.row, cell.col): _cell_glyphs(result, cell, glyph_by_source) for cell in result.cells}
246
+ cell_roles: dict[tuple[int, int], dict[int, ScriptRole]] = {}
247
+ for cell in result.cells:
248
+ key = (cell.row, cell.col)
249
+ glyphs = cell_glyphs[key]
250
+ cell_chars = [chars_by_source[glyph.source_index] for glyph in glyphs if glyph.source_index in chars_by_source]
251
+ fraction_members = _fraction_member_indices(
252
+ table_input.page_size,
253
+ cell_chars,
254
+ tight_bboxes,
255
+ fraction_rules,
256
+ table_input.angle,
257
+ )
258
+ roles = _cell_script_roles(
259
+ glyphs,
260
+ chars_by_source,
261
+ table_input.page_size,
262
+ table_input.angle,
263
+ tight_bboxes,
264
+ origins,
265
+ fraction_members,
266
+ )
267
+ if roles:
268
+ cell_roles[key] = roles
269
+ if not cell_roles:
270
+ return result.html
271
+ return serialize_native_table_html(
272
+ result.rows,
273
+ result.cells,
274
+ render_cell=lambda cell: _render_styled_cell(
275
+ cell,
276
+ cell_glyphs[(cell.row, cell.col)],
277
+ result.text.median_glyph_height,
278
+ cell_roles.get((cell.row, cell.col), {}),
279
+ ),
280
+ )
281
+
282
+
283
+ __all__ = ["render_native_table_html_with_scripts"]
@@ -0,0 +1,147 @@
1
+ """PDF 表格的兼容入口;实现按检测、注释和物化职责组织。"""
2
+
3
+ from .table_annotations import (
4
+ _build_table_annotation as _build_table_annotation,
5
+ _collect_caption_rows as _collect_caption_rows,
6
+ _collect_footnote_rows as _collect_footnote_rows,
7
+ _extract_auxiliary_table_note_marker as _extract_auxiliary_table_note_marker,
8
+ _table_core_references_marker as _table_core_references_marker,
9
+ _line_has_compact_marker_token as _line_has_compact_marker_token,
10
+ _line_has_superscript_marker as _line_has_superscript_marker,
11
+ _table_note_body_reference_height as _table_note_body_reference_height,
12
+ _visual_row_text as _visual_row_text,
13
+ _is_table_note_text as _is_table_note_text,
14
+ _find_table_caption as _find_table_caption,
15
+ _find_caption_number_peers as _find_caption_number_peers,
16
+ _merge_table_candidate_annotations as _merge_table_candidate_annotations,
17
+ )
18
+ from .table_constants import (
19
+ _TABLE_CAPTION_RE as _TABLE_CAPTION_RE,
20
+ _TABLE_CONTINUATION_RE as _TABLE_CONTINUATION_RE,
21
+ _TABLE_NOTE_RE as _TABLE_NOTE_RE,
22
+ _AUXILIARY_TABLE_NOTE_RE as _AUXILIARY_TABLE_NOTE_RE,
23
+ _TABLE_SPLIT_NUMBER_RE as _TABLE_SPLIT_NUMBER_RE,
24
+ _FILLED_GRID_MIN_PAGE_AREA_RATIO as _FILLED_GRID_MIN_PAGE_AREA_RATIO,
25
+ _FILLED_GRID_MAX_PAGE_AREA_RATIO as _FILLED_GRID_MAX_PAGE_AREA_RATIO,
26
+ _FILLED_GRID_MIN_PAGE_WIDTH_RATIO as _FILLED_GRID_MIN_PAGE_WIDTH_RATIO,
27
+ _FILLED_GRID_MIN_PAGE_HEIGHT_RATIO as _FILLED_GRID_MIN_PAGE_HEIGHT_RATIO,
28
+ )
29
+ from .table_detection import (
30
+ _detect_table_candidates as _detect_table_candidates,
31
+ _externalize_table_continuation_captions as _externalize_table_continuation_captions,
32
+ )
33
+ from .table_filled_grid import (
34
+ _detect_filled_grid_table_candidates as _detect_filled_grid_table_candidates,
35
+ _select_maximal_filled_grid_cells as _select_maximal_filled_grid_cells,
36
+ _bbox_is_contained_with_tolerance as _bbox_is_contained_with_tolerance,
37
+ _group_filled_grid_cells_into_bands as _group_filled_grid_cells_into_bands,
38
+ _filled_grid_band_covers_outer_width as _filled_grid_band_covers_outer_width,
39
+ )
40
+ from .table_rows import (
41
+ _clip_visual_row_to_corridor as _clip_visual_row_to_corridor,
42
+ )
43
+ from .table_materialization import (
44
+ _recover_native_table_html as _recover_native_table_html,
45
+ _materialize_table_blocks as _materialize_table_blocks,
46
+ _materialize_table_annotations as _materialize_table_annotations,
47
+ _split_table_annotation_visual_groups as _split_table_annotation_visual_groups,
48
+ _build_table_annotation_blocks as _build_table_annotation_blocks,
49
+ _merge_table_annotation_content as _merge_table_annotation_content,
50
+ _table_body_materialization_bbox as _table_body_materialization_bbox,
51
+ _candidate_projection_line_indices as _candidate_projection_line_indices,
52
+ _expand_candidate_same_baseline_members as _expand_candidate_same_baseline_members,
53
+ )
54
+ from .table_rules import (
55
+ _build_fragments as _build_fragments,
56
+ _cluster_fragment_rows as _cluster_fragment_rows,
57
+ _build_rule_table_candidates as _build_rule_table_candidates,
58
+ _expand_candidates_to_connected_rule_grids as _expand_candidates_to_connected_rule_grids,
59
+ _build_closed_rule_grid_candidates as _build_closed_rule_grid_candidates,
60
+ _closed_grid_vertical_track_positions as _closed_grid_vertical_track_positions,
61
+ _count_occupied_closed_grid_columns as _count_occupied_closed_grid_columns,
62
+ _connected_rule_grid_bboxes as _connected_rule_grid_bboxes,
63
+ _connected_rule_grid_components as _connected_rule_grid_components,
64
+ _connected_horizontal_rule_bboxes as _connected_horizontal_rule_bboxes,
65
+ _rule_bands_share_grid_tracks as _rule_bands_share_grid_tracks,
66
+ _group_long_horizontal_rules as _group_long_horizontal_rules,
67
+ _rows_inside_rule_interval as _rows_inside_rule_interval,
68
+ _every_rule_interval_has_multi_cell_row as _every_rule_interval_has_multi_cell_row,
69
+ _rule_intervals_are_column_compatible as _rule_intervals_are_column_compatible,
70
+ _continuous_table_row_segments as _continuous_table_row_segments,
71
+ _table_segment_reaches_boundaries as _table_segment_reaches_boundaries,
72
+ _table_rows_align_with_rule_span as _table_rows_align_with_rule_span,
73
+ _count_aligned_vertical_rules as _count_aligned_vertical_rules,
74
+ _compact_fully_ruled_grid_column_count as _compact_fully_ruled_grid_column_count,
75
+ _full_height_vertical_rule_positions as _full_height_vertical_rule_positions,
76
+ _looks_like_page_column_prose as _looks_like_page_column_prose,
77
+ _count_repeated_fill_bands as _count_repeated_fill_bands,
78
+ _longest_dense_multi_cell_rows as _longest_dense_multi_cell_rows,
79
+ _expand_rule_table_candidate as _expand_rule_table_candidate,
80
+ _count_stable_columns as _count_stable_columns,
81
+ _merge_table_candidates as _merge_table_candidates,
82
+ _median_fragment_height as _median_fragment_height,
83
+ )
84
+ from ....document.pdf.text.contracts import (
85
+ Char as Char,
86
+ )
87
+ from .table_recovery import (
88
+ NativeTableInput as NativeTableInput,
89
+ NativeTableRectangle as NativeTableRectangle,
90
+ NativeTableRule as NativeTableRule,
91
+ coerce_native_table_rectangles as coerce_native_table_rectangles,
92
+ coerce_native_table_rules as coerce_native_table_rules,
93
+ recover_native_pdf_table as recover_native_pdf_table,
94
+ )
95
+ from .table_text_styles import (
96
+ render_native_table_html_with_scripts as render_native_table_html_with_scripts,
97
+ )
98
+ from ....foundation.text import (
99
+ merge_text_line_contents as merge_text_line_contents,
100
+ )
101
+ from .spatial_text import (
102
+ project_pdf_table_text as project_pdf_table_text,
103
+ )
104
+ from ....schema import (
105
+ BBox as BBox,
106
+ )
107
+ from ....document.pdf.document import (
108
+ PDFPathInfo as PDFPathInfo,
109
+ )
110
+ from ....foundation.language import (
111
+ detect_lang as detect_lang,
112
+ )
113
+ from .models import (
114
+ _Fragment as _Fragment,
115
+ _LineItem as _LineItem,
116
+ _LocalAxisLine as _LocalAxisLine,
117
+ _PageSource as _PageSource,
118
+ _TableAnnotation as _TableAnnotation,
119
+ _TableCandidate as _TableCandidate,
120
+ _VisualRow as _VisualRow,
121
+ )
122
+ from .geometry import (
123
+ _bbox_area as _bbox_area,
124
+ _bbox_axis_overlap_ratio as _bbox_axis_overlap_ratio,
125
+ _bbox_center_x as _bbox_center_x,
126
+ _bbox_center_y as _bbox_center_y,
127
+ _bbox_overlap_in_smaller as _bbox_overlap_in_smaller,
128
+ _bbox_union as _bbox_union,
129
+ _bbox_union_many as _bbox_union_many,
130
+ _coerce_bbox as _coerce_bbox,
131
+ _expand_bbox as _expand_bbox,
132
+ _point_in_bbox as _point_in_bbox,
133
+ _rotate_bbox_from_upright as _rotate_bbox_from_upright,
134
+ _rotate_bbox_to_upright as _rotate_bbox_to_upright,
135
+ _transform_axis_lines as _transform_axis_lines,
136
+ )
137
+ from .line_layout import (
138
+ _font_signatures_share_family as _font_signatures_share_family,
139
+ _line_effective_height as _line_effective_height,
140
+ _line_tight_output_bbox as _line_tight_output_bbox,
141
+ )
142
+ from .line_merging import (
143
+ _same_baseline_geometry as _same_baseline_geometry,
144
+ )
145
+ from .native_text import (
146
+ _normalize_native_run_text as _normalize_native_run_text,
147
+ )
@@ -0,0 +1,3 @@
1
+ """按职责拆分的 Flash PDF 内部实现。"""
2
+
3
+ __all__: list[str] = []