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.
- docvortex/__init__.py +21 -0
- docvortex/analyzers/__init__.py +3 -0
- docvortex/analyzers/native/__init__.py +37 -0
- docvortex/analyzers/native/_shared/__init__.py +3 -0
- docvortex/analyzers/native/_shared/hyperlink.py +16 -0
- docvortex/analyzers/native/_shared/image.py +8 -0
- docvortex/analyzers/native/_shared/markup/__init__.py +47 -0
- docvortex/analyzers/native/_shared/markup/anchors.py +30 -0
- docvortex/analyzers/native/_shared/markup/formula.py +37 -0
- docvortex/analyzers/native/_shared/markup/projector.py +57 -0
- docvortex/analyzers/native/_shared/markup/styles.py +19 -0
- docvortex/analyzers/native/_shared/mathml.py +17 -0
- docvortex/analyzers/native/_shared/names.py +7 -0
- docvortex/analyzers/native/_shared/xycut.py +414 -0
- docvortex/analyzers/native/contracts.py +44 -0
- docvortex/analyzers/native/csv.py +351 -0
- docvortex/analyzers/native/epub/__init__.py +18 -0
- docvortex/analyzers/native/epub/constants.py +45 -0
- docvortex/analyzers/native/epub/converter.py +80 -0
- docvortex/analyzers/native/epub/errors.py +20 -0
- docvortex/analyzers/native/epub/metadata.py +31 -0
- docvortex/analyzers/native/epub/package.py +649 -0
- docvortex/analyzers/native/epub/xhtml.py +306 -0
- docvortex/analyzers/native/html/__init__.py +6 -0
- docvortex/analyzers/native/html/anchors.py +271 -0
- docvortex/analyzers/native/html/constants.py +25 -0
- docvortex/analyzers/native/html/contracts.py +7 -0
- docvortex/analyzers/native/html/converter.py +117 -0
- docvortex/analyzers/native/html/document.py +389 -0
- docvortex/analyzers/native/html/errors.py +12 -0
- docvortex/analyzers/native/html/resources.py +365 -0
- docvortex/analyzers/native/html/selector.py +421 -0
- docvortex/analyzers/native/models.py +209 -0
- docvortex/analyzers/native/ofd/__init__.py +14 -0
- docvortex/analyzers/native/ofd/constants.py +59 -0
- docvortex/analyzers/native/ofd/converter.py +31 -0
- docvortex/analyzers/native/ofd/errors.py +16 -0
- docvortex/analyzers/native/ofd/geometry.py +215 -0
- docvortex/analyzers/native/ofd/images.py +124 -0
- docvortex/analyzers/native/ofd/metadata.py +53 -0
- docvortex/analyzers/native/ofd/models.py +170 -0
- docvortex/analyzers/native/ofd/package.py +346 -0
- docvortex/analyzers/native/ofd/path.py +201 -0
- docvortex/analyzers/native/ofd/reading_order.py +293 -0
- docvortex/analyzers/native/ofd/resources.py +122 -0
- docvortex/analyzers/native/ofd/scene.py +347 -0
- docvortex/analyzers/native/ofd/table.py +240 -0
- docvortex/analyzers/native/ofd/text.py +521 -0
- docvortex/analyzers/native/office/__init__.py +3 -0
- docvortex/analyzers/native/office/doc/__init__.py +3 -0
- docvortex/analyzers/native/office/doc/bookmarks.py +81 -0
- docvortex/analyzers/native/office/doc/doc_converter.py +573 -0
- docvortex/analyzers/native/office/doc/fib.py +261 -0
- docvortex/analyzers/native/office/doc/fields.py +101 -0
- docvortex/analyzers/native/office/doc/formatting.py +171 -0
- docvortex/analyzers/native/office/doc/images.py +162 -0
- docvortex/analyzers/native/office/doc/lists.py +356 -0
- docvortex/analyzers/native/office/doc/models.py +164 -0
- docvortex/analyzers/native/office/doc/parser.py +851 -0
- docvortex/analyzers/native/office/doc/pieces.py +256 -0
- docvortex/analyzers/native/office/doc/records.py +40 -0
- docvortex/analyzers/native/office/doc/sprm.py +269 -0
- docvortex/analyzers/native/office/doc/styles.py +215 -0
- docvortex/analyzers/native/office/docx/__init__.py +3 -0
- docvortex/analyzers/native/office/docx/context.py +71 -0
- docvortex/analyzers/native/office/docx/docx_converter.py +614 -0
- docvortex/analyzers/native/office/docx/equationxml.py +119 -0
- docvortex/analyzers/native/office/docx/fields.py +816 -0
- docvortex/analyzers/native/office/docx/formatting_types.py +23 -0
- docvortex/analyzers/native/office/docx/main.py +50 -0
- docvortex/analyzers/native/office/docx/numbering.py +491 -0
- docvortex/analyzers/native/office/docx/office_xml.py +57 -0
- docvortex/analyzers/native/office/docx/package_normalizer.py +248 -0
- docvortex/analyzers/native/office/docx/resources.py +526 -0
- docvortex/analyzers/native/office/docx/styles.py +693 -0
- docvortex/analyzers/native/office/docx/tables.py +515 -0
- docvortex/analyzers/native/office/equation/__init__.py +3 -0
- docvortex/analyzers/native/office/equation/image.py +470 -0
- docvortex/analyzers/native/office/equation/latex_dict.py +324 -0
- docvortex/analyzers/native/office/equation/mtef.py +885 -0
- docvortex/analyzers/native/office/equation/mtef_v5.py +941 -0
- docvortex/analyzers/native/office/equation/omml.py +561 -0
- docvortex/analyzers/native/office/equation/ooxml.py +62 -0
- docvortex/analyzers/native/office/errors.py +33 -0
- docvortex/analyzers/native/office/image.py +307 -0
- docvortex/analyzers/native/office/legacy/__init__.py +3 -0
- docvortex/analyzers/native/office/legacy/binary.py +43 -0
- docvortex/analyzers/native/office/legacy/officeart.py +362 -0
- docvortex/analyzers/native/office/legacy/ole.py +110 -0
- docvortex/analyzers/native/office/limits.py +12 -0
- docvortex/analyzers/native/office/odf/__init__.py +3 -0
- docvortex/analyzers/native/office/odf/chart.py +76 -0
- docvortex/analyzers/native/office/odf/constants.py +70 -0
- docvortex/analyzers/native/office/odf/converters.py +403 -0
- docvortex/analyzers/native/office/odf/errors.py +18 -0
- docvortex/analyzers/native/office/odf/metadata.py +91 -0
- docvortex/analyzers/native/office/odf/models.py +176 -0
- docvortex/analyzers/native/office/odf/package.py +270 -0
- docvortex/analyzers/native/office/odf/styles.py +329 -0
- docvortex/analyzers/native/office/odf/table.py +469 -0
- docvortex/analyzers/native/office/odf/text.py +1002 -0
- docvortex/analyzers/native/office/ooxml_chart.py +1016 -0
- docvortex/analyzers/native/office/opc.py +38 -0
- docvortex/analyzers/native/office/ppt/__init__.py +3 -0
- docvortex/analyzers/native/office/ppt/models.py +118 -0
- docvortex/analyzers/native/office/ppt/parser.py +1895 -0
- docvortex/analyzers/native/office/ppt/ppt_converter.py +292 -0
- docvortex/analyzers/native/office/ppt/records.py +131 -0
- docvortex/analyzers/native/office/ppt/style_text.py +247 -0
- docvortex/analyzers/native/office/pptx/__init__.py +3 -0
- docvortex/analyzers/native/office/pptx/context.py +113 -0
- docvortex/analyzers/native/office/pptx/lists.py +558 -0
- docvortex/analyzers/native/office/pptx/main.py +20 -0
- docvortex/analyzers/native/office/pptx/package_normalizer.py +321 -0
- docvortex/analyzers/native/office/pptx/pptx_converter.py +323 -0
- docvortex/analyzers/native/office/pptx/resources.py +329 -0
- docvortex/analyzers/native/office/pptx/shapes.py +393 -0
- docvortex/analyzers/native/office/pptx/text_styles.py +625 -0
- docvortex/analyzers/native/office/pptx/titles.py +178 -0
- docvortex/analyzers/native/office/rich_text.py +420 -0
- docvortex/analyzers/native/office/rtf/__init__.py +3 -0
- docvortex/analyzers/native/office/rtf/converter.py +708 -0
- docvortex/analyzers/native/office/rtf/lexer.py +213 -0
- docvortex/analyzers/native/office/rtf/math.py +339 -0
- docvortex/analyzers/native/office/rtf/models.py +185 -0
- docvortex/analyzers/native/office/rtf/parser.py +1553 -0
- docvortex/analyzers/native/office/spreadsheet/__init__.py +3 -0
- docvortex/analyzers/native/office/spreadsheet/html.py +81 -0
- docvortex/analyzers/native/office/spreadsheet/models.py +79 -0
- docvortex/analyzers/native/office/spreadsheet/projector.py +928 -0
- docvortex/analyzers/native/office/streams.py +18 -0
- docvortex/analyzers/native/office/xls/__init__.py +3 -0
- docvortex/analyzers/native/office/xls/chart.py +132 -0
- docvortex/analyzers/native/office/xls/embedded_chart.py +299 -0
- docvortex/analyzers/native/office/xls/models.py +109 -0
- docvortex/analyzers/native/office/xls/number_format.py +521 -0
- docvortex/analyzers/native/office/xls/parser.py +1145 -0
- docvortex/analyzers/native/office/xls/records.py +201 -0
- docvortex/analyzers/native/office/xls/strings.py +205 -0
- docvortex/analyzers/native/office/xls/xls_converter.py +354 -0
- docvortex/analyzers/native/office/xlsx/__init__.py +3 -0
- docvortex/analyzers/native/office/xlsx/main.py +20 -0
- docvortex/analyzers/native/office/xlsx/ooxml_ole.py +522 -0
- docvortex/analyzers/native/office/xlsx/package_normalizer.py +310 -0
- docvortex/analyzers/native/office/xlsx/xlsx_converter.py +716 -0
- docvortex/analyzers/native/pdf/__init__.py +3 -0
- docvortex/analyzers/native/pdf/auxiliary_text.py +1671 -0
- docvortex/analyzers/native/pdf/char_geometry.py +1662 -0
- docvortex/analyzers/native/pdf/code_blocks.py +535 -0
- docvortex/analyzers/native/pdf/formulas.py +1985 -0
- docvortex/analyzers/native/pdf/geometry.py +281 -0
- docvortex/analyzers/native/pdf/graphics.py +1501 -0
- docvortex/analyzers/native/pdf/index_blocks.py +268 -0
- docvortex/analyzers/native/pdf/inline/__init__.py +3 -0
- docvortex/analyzers/native/pdf/inline/common.py +112 -0
- docvortex/analyzers/native/pdf/inline/detection.py +590 -0
- docvortex/analyzers/native/pdf/inline/matching.py +1185 -0
- docvortex/analyzers/native/pdf/inline/materialize.py +457 -0
- docvortex/analyzers/native/pdf/inline/scripts.py +975 -0
- docvortex/analyzers/native/pdf/inline/types.py +385 -0
- docvortex/analyzers/native/pdf/line_layout.py +1106 -0
- docvortex/analyzers/native/pdf/line_merging.py +1223 -0
- docvortex/analyzers/native/pdf/models.py +246 -0
- docvortex/analyzers/native/pdf/native_text.py +1004 -0
- docvortex/analyzers/native/pdf/pipeline.py +1390 -0
- docvortex/analyzers/native/pdf/script_geometry.py +636 -0
- docvortex/analyzers/native/pdf/shared.py +30 -0
- docvortex/analyzers/native/pdf/spatial_text.py +383 -0
- docvortex/analyzers/native/pdf/table_annotations.py +446 -0
- docvortex/analyzers/native/pdf/table_constants.py +48 -0
- docvortex/analyzers/native/pdf/table_detection.py +227 -0
- docvortex/analyzers/native/pdf/table_filled_grid.py +218 -0
- docvortex/analyzers/native/pdf/table_geometry.py +40 -0
- docvortex/analyzers/native/pdf/table_materialization.py +444 -0
- docvortex/analyzers/native/pdf/table_recovery/__init__.py +15 -0
- docvortex/analyzers/native/pdf/table_recovery/candidate.py +356 -0
- docvortex/analyzers/native/pdf/table_recovery/contracts.py +154 -0
- docvortex/analyzers/native/pdf/table_recovery/engine.py +609 -0
- docvortex/analyzers/native/pdf/table_recovery/geometry.py +164 -0
- docvortex/analyzers/native/pdf/table_recovery/sparse_common.py +85 -0
- docvortex/analyzers/native/pdf/table_recovery/sparse_hybrid.py +804 -0
- docvortex/analyzers/native/pdf/table_recovery/sparse_multiline.py +1122 -0
- docvortex/analyzers/native/pdf/table_recovery/text.py +414 -0
- docvortex/analyzers/native/pdf/table_recovery/text_grid.py +618 -0
- docvortex/analyzers/native/pdf/table_recovery/vector.py +1931 -0
- docvortex/analyzers/native/pdf/table_rows.py +34 -0
- docvortex/analyzers/native/pdf/table_rules.py +1129 -0
- docvortex/analyzers/native/pdf/table_text_styles.py +283 -0
- docvortex/analyzers/native/pdf/tables.py +147 -0
- docvortex/analyzers/native/pdf/text_assembly/__init__.py +3 -0
- docvortex/analyzers/native/pdf/text_assembly/annotations.py +581 -0
- docvortex/analyzers/native/pdf/text_assembly/assembly.py +292 -0
- docvortex/analyzers/native/pdf/text_assembly/common.py +477 -0
- docvortex/analyzers/native/pdf/text_assembly/footnotes.py +394 -0
- docvortex/analyzers/native/pdf/text_assembly/merging.py +1274 -0
- docvortex/analyzers/native/pdf/text_assembly/rows.py +692 -0
- docvortex/analyzers/native/pdf/text_blocks.py +82 -0
- docvortex/analyzers/native/pdf/text_styles.py +55 -0
- docvortex/analyzers/native/pdf/title_analysis/__init__.py +3 -0
- docvortex/analyzers/native/pdf/title_analysis/body_profile.py +215 -0
- docvortex/analyzers/native/pdf/title_analysis/common.py +117 -0
- docvortex/analyzers/native/pdf/title_analysis/document_profile.py +164 -0
- docvortex/analyzers/native/pdf/title_analysis/lane_titles.py +758 -0
- docvortex/analyzers/native/pdf/title_analysis/page_titles.py +1024 -0
- docvortex/analyzers/native/pdf/title_analysis/prototype.py +194 -0
- docvortex/analyzers/native/pdf/title_analysis/structural.py +1081 -0
- docvortex/analyzers/native/pdf/titles.py +75 -0
- docvortex/analyzers/native/pdf/typography.py +19 -0
- docvortex/analyzers/native/pdf/visual_annotations.py +1262 -0
- docvortex/api.py +180 -0
- docvortex/assets/__init__.py +5 -0
- docvortex/assets/store.py +51 -0
- docvortex/cli.py +54 -0
- docvortex/codecs/__init__.py +3 -0
- docvortex/codecs/html/__init__.py +22 -0
- docvortex/codecs/html/contracts.py +236 -0
- docvortex/codecs/html/materializer.py +331 -0
- docvortex/codecs/html/parser.py +763 -0
- docvortex/codecs/html/resources.py +34 -0
- docvortex/codecs/json.py +17 -0
- docvortex/content/__init__.py +5 -0
- docvortex/content/inline.py +248 -0
- docvortex/content/markup/__init__.py +44 -0
- docvortex/content/markup/anchors.py +188 -0
- docvortex/content/markup/formula.py +280 -0
- docvortex/content/markup/projector.py +1237 -0
- docvortex/content/markup/styles.py +327 -0
- docvortex/content/mathml.py +167 -0
- docvortex/content/normalization.py +188 -0
- docvortex/content/spans.py +183 -0
- docvortex/content/table/__init__.py +18 -0
- docvortex/content/table/blocks.py +152 -0
- docvortex/content/table/content.py +425 -0
- docvortex/content/table/document.py +104 -0
- docvortex/content/table/html.py +399 -0
- docvortex/content/table/models.py +76 -0
- docvortex/content/table/rules.py +42 -0
- docvortex/content/table/structure.py +221 -0
- docvortex/content/tree.py +5 -0
- docvortex/document/__init__.py +3 -0
- docvortex/document/contracts.py +22 -0
- docvortex/document/detection.py +389 -0
- docvortex/document/filetypes.py +175 -0
- docvortex/document/page_range.py +167 -0
- docvortex/document/pdf/__init__.py +19 -0
- docvortex/document/pdf/classify.py +1138 -0
- docvortex/document/pdf/constants.py +132 -0
- docvortex/document/pdf/diagnostics.py +350 -0
- docvortex/document/pdf/document.py +582 -0
- docvortex/document/pdf/font_runtime.py +335 -0
- docvortex/document/pdf/geometry.py +31 -0
- docvortex/document/pdf/images.py +654 -0
- docvortex/document/pdf/native_annotations.py +367 -0
- docvortex/document/pdf/native_contracts.py +169 -0
- docvortex/document/pdf/native_coordinates.py +216 -0
- docvortex/document/pdf/native_lifecycle.py +16 -0
- docvortex/document/pdf/native_objects.py +902 -0
- docvortex/document/pdf/native_text_geometry.py +315 -0
- docvortex/document/pdf/pdfium.py +325 -0
- docvortex/document/pdf/raster.py +46 -0
- docvortex/document/pdf/text/__init__.py +62 -0
- docvortex/document/pdf/text/contracts.py +211 -0
- docvortex/document/pdf/text/extract.py +165 -0
- docvortex/document/pdf/text/geometry.py +16 -0
- docvortex/document/pdf/text/groups.py +162 -0
- docvortex/document/pdf/visual_geometry.py +201 -0
- docvortex/document/pdf/visuals.py +343 -0
- docvortex/document/source.py +92 -0
- docvortex/errors.py +21 -0
- docvortex/export/__init__.py +3 -0
- docvortex/export/bundle.py +98 -0
- docvortex/export/files.py +66 -0
- docvortex/export/middle.py +208 -0
- docvortex/foundation/__init__.py +3 -0
- docvortex/foundation/geometry.py +125 -0
- docvortex/foundation/hyperlink.py +65 -0
- docvortex/foundation/image.py +48 -0
- docvortex/foundation/image_encoding.py +30 -0
- docvortex/foundation/image_payload.py +280 -0
- docvortex/foundation/language.py +92 -0
- docvortex/foundation/platform.py +38 -0
- docvortex/foundation/text.py +153 -0
- docvortex/foundation/type_identity.py +20 -0
- docvortex/foundation/xml_names.py +20 -0
- docvortex/options.py +30 -0
- docvortex/postprocess/__init__.py +3 -0
- docvortex/postprocess/content.py +53 -0
- docvortex/postprocess/document.py +19 -0
- docvortex/postprocess/lists.py +236 -0
- docvortex/postprocess/page_blocks.py +214 -0
- docvortex/postprocess/pages.py +95 -0
- docvortex/postprocess/paragraphs.py +580 -0
- docvortex/postprocess/visual.py +715 -0
- docvortex/render/__init__.py +48 -0
- docvortex/render/_internal/__init__.py +3 -0
- docvortex/render/_internal/common/__init__.py +3 -0
- docvortex/render/_internal/common/context.py +43 -0
- docvortex/render/_internal/common/html_table.py +178 -0
- docvortex/render/_internal/common/index.py +33 -0
- docvortex/render/_internal/common/list_items.py +158 -0
- docvortex/render/_internal/common/planner.py +140 -0
- docvortex/render/_internal/docx/__init__.py +3 -0
- docvortex/render/_internal/docx/assets.py +202 -0
- docvortex/render/_internal/docx/inline.py +434 -0
- docvortex/render/_internal/docx/math.py +220 -0
- docvortex/render/_internal/docx/renderer.py +905 -0
- docvortex/render/_internal/docx/styles.py +195 -0
- docvortex/render/_internal/docx/table.py +442 -0
- docvortex/render/_internal/epub/__init__.py +5 -0
- docvortex/render/_internal/epub/assets.py +173 -0
- docvortex/render/_internal/epub/package.py +249 -0
- docvortex/render/_internal/epub/renderer.py +1156 -0
- docvortex/render/_internal/html/__init__.py +3 -0
- docvortex/render/_internal/html/inline.py +346 -0
- docvortex/render/_internal/html/renderer.py +1041 -0
- docvortex/render/_internal/html/sanitizer.py +478 -0
- docvortex/render/_internal/html/table.py +121 -0
- docvortex/render/_internal/latex/__init__.py +1 -0
- docvortex/render/_internal/latex/assets.py +85 -0
- docvortex/render/_internal/latex/inline.py +145 -0
- docvortex/render/_internal/latex/renderer.py +506 -0
- docvortex/render/_internal/latex/table.py +347 -0
- docvortex/render/_internal/markdown/__init__.py +3 -0
- docvortex/render/_internal/markdown/assets.py +78 -0
- docvortex/render/_internal/markdown/blocks.py +635 -0
- docvortex/render/_internal/markdown/escaping.py +51 -0
- docvortex/render/_internal/markdown/inline.py +260 -0
- docvortex/render/_internal/markdown/renderer.py +93 -0
- docvortex/render/_internal/markdown/table.py +281 -0
- docvortex/render/_internal/pdf/__init__.py +3 -0
- docvortex/render/_internal/pdf/assets.py +197 -0
- docvortex/render/_internal/pdf/formula.py +417 -0
- docvortex/render/_internal/pdf/inline.py +343 -0
- docvortex/render/_internal/pdf/renderer.py +734 -0
- docvortex/render/_internal/pdf/styles.py +206 -0
- docvortex/render/_internal/pdf/table.py +272 -0
- docvortex/render/_internal/structured_content/__init__.py +3 -0
- docvortex/render/_internal/structured_content/renderer.py +193 -0
- docvortex/render/api.py +199 -0
- docvortex/render/contracts.py +205 -0
- docvortex/render/docx.py +38 -0
- docvortex/render/epub.py +35 -0
- docvortex/render/fragments.py +70 -0
- docvortex/render/html.py +29 -0
- docvortex/render/latex.py +24 -0
- docvortex/render/markdown.py +50 -0
- docvortex/render/pdf.py +25 -0
- docvortex/render/structured_content.py +23 -0
- docvortex/resources/epub/docvortex.css +91 -0
- docvortex/resources/fasttext-langdetect/lid.176.ftz +0 -0
- docvortex/resources/fonts/DroidSansFallbackFull.ttf +0 -0
- docvortex/resources/fonts/NOTICE +190 -0
- docvortex/resources/fonts/manifest.json +9 -0
- docvortex/resources/html/docvortex.css +601 -0
- docvortex/resources/html/docvortex.min.css +1 -0
- docvortex/result.py +91 -0
- docvortex/schema.py +1141 -0
- docvortex/version.py +3 -0
- docvortex-0.2.1.dist-info/METADATA +193 -0
- docvortex-0.2.1.dist-info/RECORD +364 -0
- docvortex-0.2.1.dist-info/WHEEL +5 -0
- docvortex-0.2.1.dist-info/entry_points.txt +2 -0
- docvortex-0.2.1.dist-info/licenses/LICENSE.md +21 -0
- docvortex-0.2.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"""PPTX 图片、图表与公式资源,复用当前转换器的单文档状态。"""
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
from typing import Any, Optional
|
|
5
|
+
from loguru import logger
|
|
6
|
+
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
|
7
|
+
from ..ooxml_chart import extract_chart_html_from_ooxml
|
|
8
|
+
from ..image import serialize_office_image
|
|
9
|
+
from ..equation.ooxml import is_mathtype_equation_prog_id
|
|
10
|
+
from .....schema import BlockType
|
|
11
|
+
|
|
12
|
+
from .context import DRAWINGML_NS, RELATIONSHIP_NS, SVG_BLIP_NS, OMML_NS
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _PptxResources:
|
|
16
|
+
"""集中维护图片、图表与公式资源,不改变文档生命周期和公开入口。"""
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def _pptx_ole_format(shape: Any) -> Any | None:
|
|
20
|
+
"""安全返回 PPTX graphic-frame 的 OLE format。"""
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
return shape.ole_format
|
|
24
|
+
except (AttributeError, KeyError, ValueError):
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
def _is_equation_ole_shape(self, shape: Any) -> bool:
|
|
28
|
+
"""判断 PPTX OLE shape 的 ProgID 是否为 MathType/Equation 公式。"""
|
|
29
|
+
|
|
30
|
+
ole_format = self._pptx_ole_format(shape)
|
|
31
|
+
return bool(ole_format is not None and is_mathtype_equation_prog_id(getattr(ole_format, "prog_id", None)))
|
|
32
|
+
|
|
33
|
+
def _decode_pptx_ole_equation(self, shape: Any) -> str | None:
|
|
34
|
+
"""解码 PPTX 内嵌公式 OLE;链接、图标和坏对象返回空。"""
|
|
35
|
+
|
|
36
|
+
ole_format = self._pptx_ole_format(shape)
|
|
37
|
+
if ole_format is None:
|
|
38
|
+
return None
|
|
39
|
+
prog_id = getattr(ole_format, "prog_id", None)
|
|
40
|
+
if not is_mathtype_equation_prog_id(prog_id):
|
|
41
|
+
return None
|
|
42
|
+
if bool(getattr(ole_format, "show_as_icon", False)):
|
|
43
|
+
return None
|
|
44
|
+
if self._safe_shape_type(shape) != MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT:
|
|
45
|
+
return None
|
|
46
|
+
try:
|
|
47
|
+
blob = ole_format.blob
|
|
48
|
+
except (AttributeError, KeyError, ValueError):
|
|
49
|
+
blob = None
|
|
50
|
+
latex = self._ooxml_equation_decoder.decode(
|
|
51
|
+
blob,
|
|
52
|
+
prog_id=prog_id,
|
|
53
|
+
)
|
|
54
|
+
if latex is not None:
|
|
55
|
+
return latex
|
|
56
|
+
|
|
57
|
+
warning_key = (
|
|
58
|
+
str(getattr(getattr(shape, "part", None), "partname", "")),
|
|
59
|
+
getattr(shape, "shape_id", None),
|
|
60
|
+
)
|
|
61
|
+
if warning_key not in self._mtef_warned_shapes:
|
|
62
|
+
self._mtef_warned_shapes.add(warning_key)
|
|
63
|
+
logger.warning(
|
|
64
|
+
"PPTX_MTEF_FALLBACK: part={!r}, shape_id={!r} has an invalid or unsupported equation OLE object",
|
|
65
|
+
warning_key[0],
|
|
66
|
+
warning_key[1],
|
|
67
|
+
)
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
def _pptx_ole_shape_omml(self, shape: Any) -> list[str]:
|
|
71
|
+
"""提取 OLE 兼容容器内可表达的 OMML,作为 MTEF 的高优先级分支。"""
|
|
72
|
+
|
|
73
|
+
element = getattr(shape, "_element", None)
|
|
74
|
+
if element is None:
|
|
75
|
+
return []
|
|
76
|
+
equations: list[str] = []
|
|
77
|
+
for math in element.findall(f".//{{{OMML_NS}}}oMath"):
|
|
78
|
+
latex = self._convert_math_node_to_latex(math)
|
|
79
|
+
if latex:
|
|
80
|
+
equations.append(latex)
|
|
81
|
+
return equations
|
|
82
|
+
|
|
83
|
+
def _handle_tables(self, shape):
|
|
84
|
+
"""将PowerPoint表格转换为HTML格式。
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
shape: 包含表格的形状对象。
|
|
88
|
+
parent_slide: 父幻灯片组。
|
|
89
|
+
slide_ind: 当前幻灯片索引。
|
|
90
|
+
doc: 文档对象(此实现中未使用)。
|
|
91
|
+
slide_size: 幻灯片尺寸。
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
str: 表格的HTML字符串,如果没有表格则返回None。
|
|
95
|
+
"""
|
|
96
|
+
if not shape.has_table:
|
|
97
|
+
return None
|
|
98
|
+
|
|
99
|
+
table = shape.table
|
|
100
|
+
table_xml = shape._element
|
|
101
|
+
|
|
102
|
+
# 开始构建HTML表格
|
|
103
|
+
html_parts = ['<table border="1">']
|
|
104
|
+
|
|
105
|
+
# 跟踪已被合并单元格占用的位置
|
|
106
|
+
# 格式: {(row, col): True}
|
|
107
|
+
occupied_cells = {}
|
|
108
|
+
|
|
109
|
+
for row_idx, row in enumerate(table.rows):
|
|
110
|
+
html_parts.append(" <tr>")
|
|
111
|
+
|
|
112
|
+
for col_idx, cell in enumerate(row.cells):
|
|
113
|
+
# 跳过被合并占用的单元格
|
|
114
|
+
if (row_idx, col_idx) in occupied_cells:
|
|
115
|
+
continue
|
|
116
|
+
# 获取单元格XML以读取跨度信息
|
|
117
|
+
cell_xml = table_xml.xpath(f".//a:tbl/a:tr[{row_idx + 1}]/a:tc[{col_idx + 1}]")
|
|
118
|
+
|
|
119
|
+
if not cell_xml:
|
|
120
|
+
continue
|
|
121
|
+
|
|
122
|
+
cell_xml = cell_xml[0]
|
|
123
|
+
|
|
124
|
+
# 解析行跨度和列跨度
|
|
125
|
+
row_span = cell_xml.get("rowSpan")
|
|
126
|
+
col_span = cell_xml.get("gridSpan")
|
|
127
|
+
|
|
128
|
+
row_span = int(row_span) if row_span else 1
|
|
129
|
+
col_span = int(col_span) if col_span else 1
|
|
130
|
+
|
|
131
|
+
# 标记被此单元格占用的位置
|
|
132
|
+
for r in range(row_idx, row_idx + row_span):
|
|
133
|
+
for c in range(col_idx, col_idx + col_span):
|
|
134
|
+
if (r, c) != (row_idx, col_idx):
|
|
135
|
+
occupied_cells[(r, c)] = True
|
|
136
|
+
|
|
137
|
+
# 确定标签类型:第一行使用<th>,其他使用<td>
|
|
138
|
+
tag = "th" if row_idx == 0 else "td"
|
|
139
|
+
|
|
140
|
+
# 构建属性字符串
|
|
141
|
+
attrs = []
|
|
142
|
+
if row_span > 1:
|
|
143
|
+
attrs.append(f'rowspan="{row_span}"')
|
|
144
|
+
if col_span > 1:
|
|
145
|
+
attrs.append(f'colspan="{col_span}"')
|
|
146
|
+
|
|
147
|
+
attr_str = " " + " ".join(attrs) if attrs else ""
|
|
148
|
+
|
|
149
|
+
# 获取单元格文本内容
|
|
150
|
+
cell_text = cell.text.strip() if cell.text else ""
|
|
151
|
+
# 转义HTML特殊字符,防止XSS
|
|
152
|
+
cell_text = cell_text.replace("&", "&").replace("<", "<").replace(">", ">")
|
|
153
|
+
|
|
154
|
+
html_parts.append(f" <{tag}{attr_str}>{cell_text}</{tag}>")
|
|
155
|
+
|
|
156
|
+
html_parts.append(" </tr>")
|
|
157
|
+
|
|
158
|
+
html_parts.append("</table>")
|
|
159
|
+
|
|
160
|
+
self.cur_page.append(
|
|
161
|
+
{
|
|
162
|
+
"type": BlockType.TABLE,
|
|
163
|
+
"content": "\n".join(html_parts),
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
return None
|
|
168
|
+
|
|
169
|
+
def _handle_chart(self, shape) -> None:
|
|
170
|
+
"""按原有图片、图表与公式资源规则执行 _handle_chart,保持输入顺序与降级行为。"""
|
|
171
|
+
try:
|
|
172
|
+
chart_part = shape.chart.part
|
|
173
|
+
chart_xml = chart_part.blob
|
|
174
|
+
except Exception as e:
|
|
175
|
+
logger.warning(f"Warning: chart XML cannot be loaded: {e}")
|
|
176
|
+
return
|
|
177
|
+
|
|
178
|
+
workbook_bytes = None
|
|
179
|
+
try:
|
|
180
|
+
chart_workbook = chart_part.chart_workbook
|
|
181
|
+
xlsx_part = chart_workbook.xlsx_part
|
|
182
|
+
if xlsx_part is not None:
|
|
183
|
+
workbook_bytes = xlsx_part.blob
|
|
184
|
+
except Exception as e:
|
|
185
|
+
logger.warning(f"Warning: chart workbook cannot be loaded: {e}")
|
|
186
|
+
|
|
187
|
+
try:
|
|
188
|
+
chart_html = extract_chart_html_from_ooxml(chart_xml, workbook_bytes)
|
|
189
|
+
except Exception as e:
|
|
190
|
+
logger.warning(f"Warning: chart HTML cannot be extracted: {e}")
|
|
191
|
+
return
|
|
192
|
+
|
|
193
|
+
if not chart_html:
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
self.cur_page.append(
|
|
197
|
+
{
|
|
198
|
+
"type": BlockType.CHART,
|
|
199
|
+
"content": chart_html,
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def _handle_pictures(self, shape):
|
|
204
|
+
"""按原有图片、图表与公式资源规则执行 _handle_pictures,保持输入顺序与降级行为。"""
|
|
205
|
+
image_data = self._get_shape_image_data(shape)
|
|
206
|
+
if image_data is None:
|
|
207
|
+
return
|
|
208
|
+
|
|
209
|
+
image_bytes, content_type = image_data
|
|
210
|
+
|
|
211
|
+
latex = self._image_equation_decoder.decode(
|
|
212
|
+
image_bytes,
|
|
213
|
+
content_type=content_type,
|
|
214
|
+
)
|
|
215
|
+
if latex:
|
|
216
|
+
self.cur_page.append(
|
|
217
|
+
{
|
|
218
|
+
"type": BlockType.EQUATION,
|
|
219
|
+
"content": latex,
|
|
220
|
+
}
|
|
221
|
+
)
|
|
222
|
+
return
|
|
223
|
+
|
|
224
|
+
if content_type == "image/svg+xml":
|
|
225
|
+
image_block = {
|
|
226
|
+
"type": BlockType.IMAGE,
|
|
227
|
+
"image_base64": self._bytes_to_data_uri(image_bytes, content_type),
|
|
228
|
+
}
|
|
229
|
+
self.cur_page.append(image_block)
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
img_base64 = serialize_office_image(
|
|
233
|
+
image_bytes,
|
|
234
|
+
content_type=content_type,
|
|
235
|
+
)
|
|
236
|
+
if img_base64 is None:
|
|
237
|
+
return
|
|
238
|
+
|
|
239
|
+
image_block = {
|
|
240
|
+
"type": BlockType.IMAGE,
|
|
241
|
+
"image_base64": img_base64,
|
|
242
|
+
}
|
|
243
|
+
self.cur_page.append(image_block)
|
|
244
|
+
return
|
|
245
|
+
|
|
246
|
+
def _decode_pptx_shape_image_equation(self, shape: Any) -> str | None:
|
|
247
|
+
"""从普通 picture 或 OLE preview 的 WMF/GIF comment 恢复公式。"""
|
|
248
|
+
|
|
249
|
+
image_data = self._get_shape_image_data(shape)
|
|
250
|
+
if image_data is None:
|
|
251
|
+
return None
|
|
252
|
+
image_bytes, content_type = image_data
|
|
253
|
+
return self._image_equation_decoder.decode(
|
|
254
|
+
image_bytes,
|
|
255
|
+
content_type=content_type,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
@staticmethod
|
|
259
|
+
def _bytes_to_data_uri(image_bytes: bytes, content_type: str) -> str:
|
|
260
|
+
"""按原有图片、图表与公式资源规则执行 _bytes_to_data_uri,保持输入顺序与降级行为。"""
|
|
261
|
+
encoded = base64.b64encode(image_bytes).decode("utf-8")
|
|
262
|
+
return f"data:{content_type};base64,{encoded}"
|
|
263
|
+
|
|
264
|
+
@staticmethod
|
|
265
|
+
def _find_first_embedded_image_rid(shape) -> Optional[str]:
|
|
266
|
+
"""按原有图片、图表与公式资源规则执行 _find_first_embedded_image_rid,保持输入顺序与降级行为。"""
|
|
267
|
+
svg_blips = shape._element.findall(f".//{{{SVG_BLIP_NS}}}svgBlip")
|
|
268
|
+
for svg_blip in svg_blips:
|
|
269
|
+
relationship_id = svg_blip.get(f"{{{RELATIONSHIP_NS}}}embed")
|
|
270
|
+
if relationship_id:
|
|
271
|
+
return relationship_id
|
|
272
|
+
|
|
273
|
+
blips = shape._element.findall(f".//{{{DRAWINGML_NS}}}blip")
|
|
274
|
+
for blip in blips:
|
|
275
|
+
relationship_id = blip.get(f"{{{RELATIONSHIP_NS}}}embed")
|
|
276
|
+
if relationship_id:
|
|
277
|
+
return relationship_id
|
|
278
|
+
|
|
279
|
+
return None
|
|
280
|
+
|
|
281
|
+
@staticmethod
|
|
282
|
+
def _has_blip_without_relationship(shape) -> bool:
|
|
283
|
+
"""判断图片节点是否只有空blip,避免把空fallback误报为图片资源缺失。"""
|
|
284
|
+
if not hasattr(shape, "_element"):
|
|
285
|
+
return False
|
|
286
|
+
|
|
287
|
+
blips = [
|
|
288
|
+
*shape._element.findall(f".//{{{SVG_BLIP_NS}}}svgBlip"),
|
|
289
|
+
*shape._element.findall(f".//{{{DRAWINGML_NS}}}blip"),
|
|
290
|
+
]
|
|
291
|
+
if not blips:
|
|
292
|
+
return False
|
|
293
|
+
|
|
294
|
+
for blip in blips:
|
|
295
|
+
if blip.get(f"{{{RELATIONSHIP_NS}}}embed") or blip.get(f"{{{RELATIONSHIP_NS}}}link"):
|
|
296
|
+
return False
|
|
297
|
+
return True
|
|
298
|
+
|
|
299
|
+
def _get_shape_image_data(self, shape) -> Optional[tuple[bytes, Optional[str]]]:
|
|
300
|
+
"""按原有图片、图表与公式资源规则执行 _get_shape_image_data,保持输入顺序与降级行为。"""
|
|
301
|
+
relationship_id = None
|
|
302
|
+
if hasattr(shape, "_element"):
|
|
303
|
+
relationship_id = self._find_first_embedded_image_rid(shape)
|
|
304
|
+
|
|
305
|
+
if relationship_id:
|
|
306
|
+
try:
|
|
307
|
+
image_part = shape.part.related_part(relationship_id)
|
|
308
|
+
image_bytes = image_part.blob
|
|
309
|
+
except Exception as e:
|
|
310
|
+
logger.warning(f"Warning: embedded image relation {relationship_id} cannot be loaded: {e}")
|
|
311
|
+
else:
|
|
312
|
+
return image_bytes, getattr(image_part, "content_type", None)
|
|
313
|
+
|
|
314
|
+
if self._has_blip_without_relationship(shape):
|
|
315
|
+
logger.debug("Skipping PPTX picture with empty blip and no image relation")
|
|
316
|
+
return None
|
|
317
|
+
|
|
318
|
+
try:
|
|
319
|
+
image = shape.image
|
|
320
|
+
except KeyError as e:
|
|
321
|
+
logger.warning(f"Warning: shape image relation cannot be loaded: {e}")
|
|
322
|
+
return None
|
|
323
|
+
except ValueError as e:
|
|
324
|
+
logger.warning(f"Warning: shape image cannot be loaded: {e}")
|
|
325
|
+
return None
|
|
326
|
+
except AttributeError:
|
|
327
|
+
return None
|
|
328
|
+
|
|
329
|
+
return image.blob, None
|