From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- writerfilter/CppunitTest_writerfilter_dmapper.mk | 55 + .../CppunitTest_writerfilter_filters_test.mk | 61 + writerfilter/CppunitTest_writerfilter_misc.mk | 43 + writerfilter/CppunitTest_writerfilter_rtftok.mk | 50 + writerfilter/CustomTarget_source.mk | 110 + writerfilter/IwyuFilter_writerfilter.yaml | 66 + writerfilter/Library_writerfilter.mk | 136 + writerfilter/Makefile | 7 + writerfilter/Module_writerfilter.mk | 24 + writerfilter/README | 20 + writerfilter/documentation/KnownIssues.txt | 27 + writerfilter/documentation/TODO | 13 + writerfilter/documentation/doxygen/Doxyfile | 1254 ++ .../documentation/doxygen/images/doctok.png | Bin 0 -> 7291 bytes .../doxygen/images/ooxmlimportchain.png | Bin 0 -> 22605 bytes writerfilter/documentation/ooxml/model.rng | 436 + writerfilter/documentation/sprms.txt | 7 + writerfilter/documentation/tablesInDoc.txt | 153 + writerfilter/inc/dmapper/DomainMapperFactory.hxx | 54 + writerfilter/inc/dmapper/GraphicZOrderHelper.hxx | 36 + writerfilter/inc/dmapper/resourcemodel.hxx | 406 + writerfilter/inc/ooxml/OOXMLDocument.hxx | 258 + writerfilter/inc/ooxml/QNameToString.hxx | 36 + writerfilter/inc/pch/precompiled_writerfilter.cxx | 12 + writerfilter/inc/pch/precompiled_writerfilter.hxx | 115 + writerfilter/inc/rtftok/RTFDocument.hxx | 52 + .../qa/cppunittests/dmapper/CellColorHandler.cxx | 70 + .../qa/cppunittests/dmapper/DomainMapper.cxx | 82 + .../dmapper/DomainMapperTableHandler.cxx | 72 + .../qa/cppunittests/dmapper/DomainMapper_Impl.cxx | 109 + .../qa/cppunittests/dmapper/GraphicImport.cxx | 170 + .../qa/cppunittests/dmapper/PropertyMap.cxx | 68 + .../qa/cppunittests/dmapper/TextEffectsHandler.cxx | 74 + .../dmapper/data/1cell-insidev-rightborder.docx | Bin 0 -> 13204 bytes .../dmapper/data/draw-shape-inline-effect.docx | Bin 0 -> 16534 bytes .../dmapper/data/floating-table-header.docx | Bin 0 -> 15046 bytes .../dmapper/data/group-shape-rotation.docx | Bin 0 -> 24177 bytes .../dmapper/data/inline-anchored-zorder.docx | Bin 0 -> 16684 bytes .../data/inline-inshape-anchored-zorder.docx | Bin 0 -> 17243 bytes .../dmapper/data/large-para-top-margin.docx | Bin 0 -> 23126 bytes .../dmapper/data/num-restart-style-parent.docx | Bin 0 -> 12336 bytes .../dmapper/data/page-break-footer-table.docx | Bin 0 -> 15416 bytes .../dmapper/data/relfromh-insidemargin.docx | Bin 0 -> 16119 bytes .../dmapper/data/semi-transparent-text.docx | Bin 0 -> 12738 bytes .../qa/cppunittests/dmapper/data/tdf129205.docx | Bin 0 -> 13237 bytes .../cppunittests/dmapper/data/wrap-poly-crop.docx | Bin 0 -> 15018 bytes writerfilter/qa/cppunittests/filters-test/README | 7 + .../filters-test/data/fail/CVE-2005-2971-1.rtf | Bin 0 -> 10867 bytes .../filters-test/data/fail/CVE-2010-3451-1.rtf | Bin 0 -> 4091 bytes .../filters-test/data/fail/EDB-18749-1.rtf | Bin 0 -> 3287 bytes .../filters-test/data/fail/destinationtest-1.rtf | Bin 0 -> 196 bytes .../filters-test/data/fail/destinationtest-2.rtf | Bin 0 -> 155 bytes .../filters-test/data/fail/nopropertyset-1.rtf | Bin 0 -> 99 bytes .../filters-test/data/fail/popstate-1.rtf | Bin 0 -> 198 bytes .../filters-test/data/fail/popstate-2.rtf | 1 + .../filters-test/data/fail/propheight-1.rtf | Bin 0 -> 1560 bytes ...b341ad4c8608af9396952724a0-128299-minimized.rtf | 57 + .../filters-test/data/fail/tablemanager-5.rtf | Bin 0 -> 1941 bytes .../filters-test/data/fail/tablemanager-6.rtf | Bin 0 -> 2417 bytes .../filters-test/data/fail/tablemanager-7.rtf | Bin 0 -> 1333 bytes .../filters-test/data/fail/topcontext-1.rtf | Bin 0 -> 458 bytes .../filters-test/data/fail/topcontext-2.rtf | Bin 0 -> 1300 bytes .../filters-test/data/fail/topcontext-3.rtf | 28 + .../filters-test/data/indeterminate/.gitignore | 0 .../filters-test/data/pass/CVE-2005-2964-1.rtf | Bin 0 -> 10869 bytes .../filters-test/data/pass/CVE-2005-2972-1.rtf | Bin 0 -> 4055 bytes .../filters-test/data/pass/CVE-2005-2972-2.rtf | Bin 0 -> 4055 bytes .../filters-test/data/pass/CVE-2007-0245-1.rtf | Bin 0 -> 11167 bytes .../filters-test/data/pass/CVE-2010-3333-1.rtf | Bin 0 -> 11289 bytes .../filters-test/data/pass/CVE-2010-3452-1.rtf | 1 + .../filters-test/data/pass/CVE-2014-1761-1.rtf | Bin 0 -> 27562 bytes .../filters-test/data/pass/CVE-2014-1761-2.rtf | Bin 0 -> 27564 bytes .../data/pass/CVE-pseudo-2009-0238-1.rtf | Bin 0 -> 11289 bytes .../filters-test/data/pass/EDB-18754-1.rtf | Bin 0 -> 93727 bytes .../filters-test/data/pass/EDB-18940-1.rtf | Bin 0 -> 14334 bytes .../data/pass/TCI-TN65GP-DDRHDLL-partial.rtf | 1719 ++ .../filters-test/data/pass/abi3623.rtf | 7 + .../filters-test/data/pass/abi4817.rtf | 6 + .../filters-test/data/pass/fdo49666.rtf | 13 + .../filters-test/data/pass/fdo64656.rtf | 10 + .../cppunittests/filters-test/data/pass/i74153.rtf | 8 + .../cppunittests/filters-test/data/pass/i84172.rtf | 11 + .../filters-test/data/pass/parser-state-1.rtf | Bin 0 -> 1546 bytes .../filters-test/data/pass/rhbz960019.rtf | 12 + ...7381c4a46d642c79a4b1817dc0-101375-minimized.rtf | 62 + ...7381c4a46d642c79a4b1817dc0-108116-minimized.rtf | 62 + .../sf_edeb1eb341ad4c8608af9396952724a0-41170.rtf | Bin 0 -> 4055 bytes .../filters-test/data/pass/tablemanager-1.rtf | Bin 0 -> 106 bytes .../filters-test/data/pass/tablemanager-2.rtf | Bin 0 -> 121 bytes .../filters-test/data/pass/tablemanager-3.rtf | Bin 0 -> 54 bytes .../filters-test/data/pass/tablemanager-4.rtf | Bin 0 -> 324 bytes .../filters-test/data/pass/valuelist-1.rtf | Bin 0 -> 1408 bytes .../qa/cppunittests/filters-test/filters-test.cxx | 79 + writerfilter/qa/cppunittests/misc/misc.cxx | 178 + .../cppunittests/rtftok/data/left-margin-dedup.rtf | 26 + .../rtftok/data/picture-in-textframe.rtf | 29 + .../qa/cppunittests/rtftok/rtfsdrimport.cxx | 71 + writerfilter/qa/cppunittests/rtftok/rtfsprm.cxx | 83 + writerfilter/qa/documents/Bookmark1.doc | Bin 0 -> 24576 bytes writerfilter/qa/documents/Bookmark1.docx | Bin 0 -> 10729 bytes writerfilter/qa/documents/CellAlignment.doc | Bin 0 -> 26624 bytes writerfilter/qa/documents/Footnote.doc | Bin 0 -> 24064 bytes writerfilter/qa/documents/Footnote.docx | Bin 0 -> 11742 bytes writerfilter/qa/documents/HeaderFooter.doc | Bin 0 -> 23040 bytes writerfilter/qa/documents/HeaderFooter.docx | Bin 0 -> 12913 bytes writerfilter/qa/documents/IndentedTable.doc | Bin 0 -> 27136 bytes writerfilter/qa/documents/IndentedTable1.docx | Bin 0 -> 10667 bytes writerfilter/qa/documents/MergedTable.doc | Bin 0 -> 24576 bytes writerfilter/qa/documents/MergedTable.docx | Bin 0 -> 10530 bytes writerfilter/qa/documents/MergedTable_3_3.doc | Bin 0 -> 24576 bytes writerfilter/qa/documents/MergedTable_3_3.docx | Bin 0 -> 10431 bytes writerfilter/qa/documents/MultiMergedTable.docx | Bin 0 -> 10641 bytes writerfilter/qa/documents/MultiWrapping1.docx | Bin 0 -> 21123 bytes .../qa/documents/Paragraph with footnote.doc | Bin 0 -> 24064 bytes .../qa/documents/Paragraph with footnote.docx | Bin 0 -> 13217 bytes writerfilter/qa/documents/Picture1.docx | Bin 0 -> 82050 bytes writerfilter/qa/documents/RedlineTest.docx | Bin 0 -> 10322 bytes writerfilter/qa/documents/RowHeight.doc | Bin 0 -> 27648 bytes writerfilter/qa/documents/RowHeight.docx | Bin 0 -> 10504 bytes writerfilter/qa/documents/StandardFontAlbertus.doc | Bin 0 -> 24064 bytes writerfilter/qa/documents/Table5CellBorders.doc | Bin 0 -> 24064 bytes writerfilter/qa/documents/Table5CellBorders.docx | Bin 0 -> 10420 bytes .../qa/documents/TableDifferentColumns.doc | Bin 0 -> 24064 bytes .../qa/documents/TableDifferentColumns.docx | Bin 0 -> 10440 bytes writerfilter/qa/documents/TablePreferredWidth.doc | Bin 0 -> 24576 bytes writerfilter/qa/documents/TablePreferredWidth.docx | Bin 0 -> 10393 bytes writerfilter/qa/documents/TableRowProperties.doc | Bin 0 -> 25600 bytes writerfilter/qa/documents/TableRowProperties.docx | Bin 0 -> 10622 bytes writerfilter/qa/documents/VertAlign1.doc | Bin 0 -> 24576 bytes writerfilter/qa/documents/WordOLE.docx | Bin 0 -> 17324 bytes writerfilter/qa/documents/align1.doc | Bin 0 -> 24576 bytes writerfilter/qa/documents/bookmark2.doc | Bin 0 -> 24576 bytes .../qa/documents/docx/numbering/num-1.docx | Bin 0 -> 11288 bytes .../Word DocumentOffice 2007 Format Sample6.docx | Bin 0 -> 302738 bytes .../docx/pictures/i97645 New example.docx | Bin 0 -> 102969 bytes .../qa/documents/docx/pictures/test-image.docx | Bin 0 -> 24026 bytes .../qa/documents/docx/pictures/test-image1.docx | Bin 0 -> 61174 bytes writerfilter/qa/documents/docx/pictures/test.docx | Bin 0 -> 22007 bytes .../documents/docx/redlines/test-review-brk.docx | Bin 0 -> 10621 bytes .../documents/docx/redlines/test-review-para.docx | Bin 0 -> 10682 bytes .../documents/docx/redlines/test-review-stack.docx | Bin 0 -> 10598 bytes .../qa/documents/docx/tables/Table in B2.docx | Bin 0 -> 10353 bytes .../qa/documents/docx/tables/nested-tables.docx | Bin 0 -> 11079 bytes .../qa/documents/docx/tables/nested-tables2.docx | Bin 0 -> 10521 bytes .../qa/documents/docx/tables/nested-tables3.docx | Bin 0 -> 11482 bytes .../qa/documents/docx/tables/nested-tables4.docx | Bin 0 -> 13956 bytes .../qa/documents/docx/tables/nested-tables5.docx | Bin 0 -> 10761 bytes .../qa/documents/docx/tables/parentinvguid.docx | Bin 0 -> 139481 bytes .../qa/documents/docx/tables/table in A1.docx | Bin 0 -> 10340 bytes .../qa/documents/docx/tables/table-styles.docx | Bin 0 -> 13859 bytes .../qa/documents/docx/tables/test-grid.docx | Bin 0 -> 10978 bytes .../qa/documents/docx/tables/test-paras.docx | Bin 0 -> 13586 bytes .../qa/documents/docx/tables/test-simple.docx | Bin 0 -> 10527 bytes .../qa/documents/docx/tables/two-tables.docx | Bin 0 -> 10619 bytes .../docx/tables/updatejpegprocessing.docx | Bin 0 -> 24439 bytes .../qa/documents/docx/tables/~$sted-tables3.docx | Bin 0 -> 162 bytes .../qa/documents/docx/test-page-format.docx | Bin 0 -> 20846 bytes writerfilter/qa/documents/fields.doc | Bin 0 -> 34816 bytes writerfilter/qa/documents/fields.docx | 1 + writerfilter/qa/documents/multimerge2.docx | 2 + writerfilter/qa/documents/runProperties.doc | Bin 0 -> 25600 bytes writerfilter/qa/documents/runProperties.docx | Bin 0 -> 11239 bytes writerfilter/qa/documents/table_4_4.doc | Bin 0 -> 25600 bytes writerfilter/qa/documents/table_4_4.docx | Bin 0 -> 11131 bytes writerfilter/qa/documents/table_style.docx | Bin 0 -> 12649 bytes writerfilter/qa/ooxml/watch-generated-code.sh | 50 + writerfilter/source/dmapper/BorderHandler.cxx | 213 + writerfilter/source/dmapper/BorderHandler.hxx | 81 + writerfilter/source/dmapper/CellColorHandler.cxx | 331 + writerfilter/source/dmapper/CellColorHandler.hxx | 70 + writerfilter/source/dmapper/CellMarginHandler.cxx | 177 + writerfilter/source/dmapper/CellMarginHandler.hxx | 68 + writerfilter/source/dmapper/ConversionHelper.cxx | 669 + writerfilter/source/dmapper/ConversionHelper.hxx | 64 + writerfilter/source/dmapper/DomainMapper.cxx | 4017 ++++ writerfilter/source/dmapper/DomainMapper.hxx | 184 + .../source/dmapper/DomainMapperTableHandler.cxx | 1496 ++ .../source/dmapper/DomainMapperTableHandler.hxx | 128 + .../source/dmapper/DomainMapperTableManager.cxx | 863 + .../source/dmapper/DomainMapperTableManager.hxx | 144 + writerfilter/source/dmapper/DomainMapper_Impl.cxx | 7319 +++++++ writerfilter/source/dmapper/DomainMapper_Impl.hxx | 1085 ++ writerfilter/source/dmapper/FFDataHandler.cxx | 190 + writerfilter/source/dmapper/FFDataHandler.hxx | 103 + writerfilter/source/dmapper/FieldTypes.hxx | 307 + writerfilter/source/dmapper/FontTable.cxx | 298 + writerfilter/source/dmapper/FontTable.hxx | 108 + writerfilter/source/dmapper/FormControlHelper.cxx | 375 + writerfilter/source/dmapper/FormControlHelper.hxx | 57 + writerfilter/source/dmapper/GraphicHelpers.cxx | 330 + writerfilter/source/dmapper/GraphicHelpers.hxx | 83 + writerfilter/source/dmapper/GraphicImport.cxx | 1585 ++ writerfilter/source/dmapper/GraphicImport.hxx | 138 + writerfilter/source/dmapper/LatentStyleHandler.cxx | 71 + writerfilter/source/dmapper/LatentStyleHandler.hxx | 41 + writerfilter/source/dmapper/LoggedResources.cxx | 400 + writerfilter/source/dmapper/LoggedResources.hxx | 137 + writerfilter/source/dmapper/MeasureHandler.cxx | 136 + writerfilter/source/dmapper/MeasureHandler.hxx | 65 + writerfilter/source/dmapper/ModelEventListener.cxx | 117 + writerfilter/source/dmapper/ModelEventListener.hxx | 45 + writerfilter/source/dmapper/NumberingManager.cxx | 1166 ++ writerfilter/source/dmapper/NumberingManager.hxx | 260 + writerfilter/source/dmapper/OLEHandler.cxx | 316 + writerfilter/source/dmapper/OLEHandler.hxx | 102 + writerfilter/source/dmapper/PageBordersHandler.cxx | 142 + writerfilter/source/dmapper/PageBordersHandler.hxx | 69 + writerfilter/source/dmapper/PropertyIds.cxx | 377 + writerfilter/source/dmapper/PropertyIds.hxx | 376 + writerfilter/source/dmapper/PropertyMap.cxx | 2039 ++ writerfilter/source/dmapper/PropertyMap.hxx | 607 + writerfilter/source/dmapper/PropertyMapHelper.cxx | 100 + writerfilter/source/dmapper/PropertyMapHelper.hxx | 41 + writerfilter/source/dmapper/SdtHelper.cxx | 253 + writerfilter/source/dmapper/SdtHelper.hxx | 128 + .../source/dmapper/SectionColumnHandler.cxx | 93 + .../source/dmapper/SectionColumnHandler.hxx | 66 + writerfilter/source/dmapper/SettingsTable.cxx | 891 + writerfilter/source/dmapper/SettingsTable.hxx | 112 + writerfilter/source/dmapper/SmartTagHandler.cxx | 128 + writerfilter/source/dmapper/SmartTagHandler.hxx | 72 + writerfilter/source/dmapper/StyleSheetTable.cxx | 1645 ++ writerfilter/source/dmapper/StyleSheetTable.hxx | 151 + writerfilter/source/dmapper/TDefTableHandler.cxx | 458 + writerfilter/source/dmapper/TDefTableHandler.hxx | 76 + writerfilter/source/dmapper/TableData.hxx | 357 + writerfilter/source/dmapper/TableManager.cxx | 501 + writerfilter/source/dmapper/TableManager.hxx | 515 + .../source/dmapper/TablePositionHandler.cxx | 156 + .../source/dmapper/TablePositionHandler.hxx | 83 + .../source/dmapper/TablePropertiesHandler.cxx | 394 + .../source/dmapper/TablePropertiesHandler.hxx | 98 + writerfilter/source/dmapper/TagLogger.cxx | 237 + writerfilter/source/dmapper/TagLogger.hxx | 69 + writerfilter/source/dmapper/TblStylePrHandler.cxx | 259 + writerfilter/source/dmapper/TblStylePrHandler.hxx | 86 + writerfilter/source/dmapper/TextEffectsHandler.cxx | 803 + writerfilter/source/dmapper/TextEffectsHandler.hxx | 76 + writerfilter/source/dmapper/ThemeTable.cxx | 564 + writerfilter/source/dmapper/ThemeTable.hxx | 63 + .../source/dmapper/TrackChangesHandler.cxx | 95 + .../source/dmapper/TrackChangesHandler.hxx | 44 + writerfilter/source/dmapper/WrapPolygonHandler.cxx | 217 + writerfilter/source/dmapper/WrapPolygonHandler.hxx | 88 + .../source/dmapper/domainmapperfactory.cxx | 39 + writerfilter/source/dmapper/util.cxx | 71 + writerfilter/source/dmapper/util.hxx | 38 + writerfilter/source/filter/RtfFilter.cxx | 220 + writerfilter/source/filter/WriterFilter.cxx | 366 + writerfilter/source/ooxml/Handler.cxx | 403 + writerfilter/source/ooxml/Handler.hxx | 163 + .../source/ooxml/OOXMLBinaryObjectReference.cxx | 71 + .../source/ooxml/OOXMLBinaryObjectReference.hxx | 48 + writerfilter/source/ooxml/OOXMLDocumentImpl.cxx | 879 + writerfilter/source/ooxml/OOXMLDocumentImpl.hxx | 142 + writerfilter/source/ooxml/OOXMLFactory.cxx | 216 + writerfilter/source/ooxml/OOXMLFactory.hxx | 109 + .../source/ooxml/OOXMLFastContextHandler.cxx | 2191 +++ .../source/ooxml/OOXMLFastContextHandler.hxx | 605 + .../source/ooxml/OOXMLFastDocumentHandler.cxx | 195 + .../source/ooxml/OOXMLFastDocumentHandler.hxx | 94 + writerfilter/source/ooxml/OOXMLFastHelper.hxx | 65 + writerfilter/source/ooxml/OOXMLParserState.cxx | 280 + writerfilter/source/ooxml/OOXMLParserState.hxx | 124 + writerfilter/source/ooxml/OOXMLPropertySet.cxx | 859 + writerfilter/source/ooxml/OOXMLPropertySet.hxx | 402 + writerfilter/source/ooxml/OOXMLStreamImpl.cxx | 443 + writerfilter/source/ooxml/OOXMLStreamImpl.hxx | 86 + writerfilter/source/ooxml/README | 13 + writerfilter/source/ooxml/factory_ns.py | 76 + writerfilter/source/ooxml/factoryimpl.py | 215 + writerfilter/source/ooxml/factoryimpl_ns.py | 759 + writerfilter/source/ooxml/factoryinc.py | 49 + writerfilter/source/ooxml/model.xml | 19197 +++++++++++++++++++ writerfilter/source/ooxml/modelpreprocess.py | 90 + writerfilter/source/ooxml/qnametostr.py | 64 + writerfilter/source/ooxml/resourceids.py | 60 + writerfilter/source/ooxml/tox.ini | 2 + writerfilter/source/rtftok/README | 12 + writerfilter/source/rtftok/rtfcharsets.cxx | 55 + writerfilter/source/rtftok/rtfcharsets.hxx | 30 + writerfilter/source/rtftok/rtfcontrolwords.cxx | 1900 ++ writerfilter/source/rtftok/rtfcontrolwords.hxx | 2056 ++ .../source/rtftok/rtfdispatchdestination.cxx | 676 + writerfilter/source/rtftok/rtfdispatchflag.cxx | 1239 ++ writerfilter/source/rtftok/rtfdispatchsymbol.cxx | 432 + writerfilter/source/rtftok/rtfdispatchvalue.cxx | 1801 ++ writerfilter/source/rtftok/rtfdocumentfactory.cxx | 28 + writerfilter/source/rtftok/rtfdocumentimpl.cxx | 3853 ++++ writerfilter/source/rtftok/rtfdocumentimpl.hxx | 988 + writerfilter/source/rtftok/rtffly.hxx | 144 + writerfilter/source/rtftok/rtflistener.hxx | 75 + writerfilter/source/rtftok/rtflookahead.cxx | 101 + writerfilter/source/rtftok/rtflookahead.hxx | 63 + .../source/rtftok/rtfreferenceproperties.cxx | 40 + .../source/rtftok/rtfreferenceproperties.hxx | 39 + writerfilter/source/rtftok/rtfreferencetable.cxx | 29 + writerfilter/source/rtftok/rtfreferencetable.hxx | 38 + writerfilter/source/rtftok/rtfsdrimport.cxx | 1151 ++ writerfilter/source/rtftok/rtfsdrimport.hxx | 115 + writerfilter/source/rtftok/rtfskipdestination.cxx | 43 + writerfilter/source/rtftok/rtfskipdestination.hxx | 39 + writerfilter/source/rtftok/rtfsprm.cxx | 448 + writerfilter/source/rtftok/rtfsprm.hxx | 107 + writerfilter/source/rtftok/rtftokenizer.cxx | 331 + writerfilter/source/rtftok/rtftokenizer.hxx | 87 + writerfilter/source/rtftok/rtfvalue.cxx | 210 + writerfilter/source/rtftok/rtfvalue.hxx | 96 + writerfilter/util/writerfilter.component | 32 + 309 files changed, 87359 insertions(+) create mode 100644 writerfilter/CppunitTest_writerfilter_dmapper.mk create mode 100644 writerfilter/CppunitTest_writerfilter_filters_test.mk create mode 100644 writerfilter/CppunitTest_writerfilter_misc.mk create mode 100644 writerfilter/CppunitTest_writerfilter_rtftok.mk create mode 100644 writerfilter/CustomTarget_source.mk create mode 100644 writerfilter/IwyuFilter_writerfilter.yaml create mode 100644 writerfilter/Library_writerfilter.mk create mode 100644 writerfilter/Makefile create mode 100644 writerfilter/Module_writerfilter.mk create mode 100644 writerfilter/README create mode 100644 writerfilter/documentation/KnownIssues.txt create mode 100644 writerfilter/documentation/TODO create mode 100644 writerfilter/documentation/doxygen/Doxyfile create mode 100644 writerfilter/documentation/doxygen/images/doctok.png create mode 100644 writerfilter/documentation/doxygen/images/ooxmlimportchain.png create mode 100644 writerfilter/documentation/ooxml/model.rng create mode 100644 writerfilter/documentation/sprms.txt create mode 100644 writerfilter/documentation/tablesInDoc.txt create mode 100644 writerfilter/inc/dmapper/DomainMapperFactory.hxx create mode 100644 writerfilter/inc/dmapper/GraphicZOrderHelper.hxx create mode 100644 writerfilter/inc/dmapper/resourcemodel.hxx create mode 100644 writerfilter/inc/ooxml/OOXMLDocument.hxx create mode 100644 writerfilter/inc/ooxml/QNameToString.hxx create mode 100644 writerfilter/inc/pch/precompiled_writerfilter.cxx create mode 100644 writerfilter/inc/pch/precompiled_writerfilter.hxx create mode 100644 writerfilter/inc/rtftok/RTFDocument.hxx create mode 100644 writerfilter/qa/cppunittests/dmapper/CellColorHandler.cxx create mode 100644 writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx create mode 100644 writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx create mode 100644 writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx create mode 100644 writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx create mode 100644 writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx create mode 100644 writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/1cell-insidev-rightborder.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/draw-shape-inline-effect.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/floating-table-header.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/group-shape-rotation.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/inline-inshape-anchored-zorder.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/large-para-top-margin.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/num-restart-style-parent.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/page-break-footer-table.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/relfromh-insidemargin.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/tdf129205.docx create mode 100644 writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx create mode 100644 writerfilter/qa/cppunittests/filters-test/README create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2005-2971-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2010-3451-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/EDB-18749-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-2.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/nopropertyset-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/popstate-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/popstate-2.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/propheight-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/sf_edeb1eb341ad4c8608af9396952724a0-128299-minimized.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-5.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-6.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-7.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-2.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-3.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/indeterminate/.gitignore create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2005-2964-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2005-2972-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2005-2972-2.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2007-0245-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2010-3333-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2010-3452-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2014-1761-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-2014-1761-2.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/CVE-pseudo-2009-0238-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/EDB-18754-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/EDB-18940-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/TCI-TN65GP-DDRHDLL-partial.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/abi3623.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/abi4817.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/fdo49666.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/fdo64656.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/i74153.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/i84172.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/parser-state-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/rhbz960019.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/sf_2063317381c4a46d642c79a4b1817dc0-101375-minimized.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/sf_2063317381c4a46d642c79a4b1817dc0-108116-minimized.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/sf_edeb1eb341ad4c8608af9396952724a0-41170.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/tablemanager-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/tablemanager-2.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/tablemanager-3.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/tablemanager-4.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/data/pass/valuelist-1.rtf create mode 100644 writerfilter/qa/cppunittests/filters-test/filters-test.cxx create mode 100644 writerfilter/qa/cppunittests/misc/misc.cxx create mode 100644 writerfilter/qa/cppunittests/rtftok/data/left-margin-dedup.rtf create mode 100644 writerfilter/qa/cppunittests/rtftok/data/picture-in-textframe.rtf create mode 100644 writerfilter/qa/cppunittests/rtftok/rtfsdrimport.cxx create mode 100644 writerfilter/qa/cppunittests/rtftok/rtfsprm.cxx create mode 100644 writerfilter/qa/documents/Bookmark1.doc create mode 100644 writerfilter/qa/documents/Bookmark1.docx create mode 100644 writerfilter/qa/documents/CellAlignment.doc create mode 100644 writerfilter/qa/documents/Footnote.doc create mode 100644 writerfilter/qa/documents/Footnote.docx create mode 100644 writerfilter/qa/documents/HeaderFooter.doc create mode 100644 writerfilter/qa/documents/HeaderFooter.docx create mode 100644 writerfilter/qa/documents/IndentedTable.doc create mode 100644 writerfilter/qa/documents/IndentedTable1.docx create mode 100644 writerfilter/qa/documents/MergedTable.doc create mode 100644 writerfilter/qa/documents/MergedTable.docx create mode 100644 writerfilter/qa/documents/MergedTable_3_3.doc create mode 100644 writerfilter/qa/documents/MergedTable_3_3.docx create mode 100644 writerfilter/qa/documents/MultiMergedTable.docx create mode 100644 writerfilter/qa/documents/MultiWrapping1.docx create mode 100644 writerfilter/qa/documents/Paragraph with footnote.doc create mode 100644 writerfilter/qa/documents/Paragraph with footnote.docx create mode 100644 writerfilter/qa/documents/Picture1.docx create mode 100644 writerfilter/qa/documents/RedlineTest.docx create mode 100644 writerfilter/qa/documents/RowHeight.doc create mode 100644 writerfilter/qa/documents/RowHeight.docx create mode 100644 writerfilter/qa/documents/StandardFontAlbertus.doc create mode 100644 writerfilter/qa/documents/Table5CellBorders.doc create mode 100644 writerfilter/qa/documents/Table5CellBorders.docx create mode 100644 writerfilter/qa/documents/TableDifferentColumns.doc create mode 100644 writerfilter/qa/documents/TableDifferentColumns.docx create mode 100644 writerfilter/qa/documents/TablePreferredWidth.doc create mode 100644 writerfilter/qa/documents/TablePreferredWidth.docx create mode 100644 writerfilter/qa/documents/TableRowProperties.doc create mode 100644 writerfilter/qa/documents/TableRowProperties.docx create mode 100644 writerfilter/qa/documents/VertAlign1.doc create mode 100644 writerfilter/qa/documents/WordOLE.docx create mode 100644 writerfilter/qa/documents/align1.doc create mode 100644 writerfilter/qa/documents/bookmark2.doc create mode 100644 writerfilter/qa/documents/docx/numbering/num-1.docx create mode 100644 writerfilter/qa/documents/docx/pictures/Word DocumentOffice 2007 Format Sample6.docx create mode 100644 writerfilter/qa/documents/docx/pictures/i97645 New example.docx create mode 100644 writerfilter/qa/documents/docx/pictures/test-image.docx create mode 100644 writerfilter/qa/documents/docx/pictures/test-image1.docx create mode 100644 writerfilter/qa/documents/docx/pictures/test.docx create mode 100644 writerfilter/qa/documents/docx/redlines/test-review-brk.docx create mode 100644 writerfilter/qa/documents/docx/redlines/test-review-para.docx create mode 100644 writerfilter/qa/documents/docx/redlines/test-review-stack.docx create mode 100644 writerfilter/qa/documents/docx/tables/Table in B2.docx create mode 100644 writerfilter/qa/documents/docx/tables/nested-tables.docx create mode 100644 writerfilter/qa/documents/docx/tables/nested-tables2.docx create mode 100644 writerfilter/qa/documents/docx/tables/nested-tables3.docx create mode 100644 writerfilter/qa/documents/docx/tables/nested-tables4.docx create mode 100644 writerfilter/qa/documents/docx/tables/nested-tables5.docx create mode 100644 writerfilter/qa/documents/docx/tables/parentinvguid.docx create mode 100644 writerfilter/qa/documents/docx/tables/table in A1.docx create mode 100644 writerfilter/qa/documents/docx/tables/table-styles.docx create mode 100644 writerfilter/qa/documents/docx/tables/test-grid.docx create mode 100644 writerfilter/qa/documents/docx/tables/test-paras.docx create mode 100644 writerfilter/qa/documents/docx/tables/test-simple.docx create mode 100644 writerfilter/qa/documents/docx/tables/two-tables.docx create mode 100644 writerfilter/qa/documents/docx/tables/updatejpegprocessing.docx create mode 100644 writerfilter/qa/documents/docx/tables/~$sted-tables3.docx create mode 100644 writerfilter/qa/documents/docx/test-page-format.docx create mode 100644 writerfilter/qa/documents/fields.doc create mode 100644 writerfilter/qa/documents/fields.docx create mode 100644 writerfilter/qa/documents/multimerge2.docx create mode 100644 writerfilter/qa/documents/runProperties.doc create mode 100644 writerfilter/qa/documents/runProperties.docx create mode 100644 writerfilter/qa/documents/table_4_4.doc create mode 100644 writerfilter/qa/documents/table_4_4.docx create mode 100644 writerfilter/qa/documents/table_style.docx create mode 100755 writerfilter/qa/ooxml/watch-generated-code.sh create mode 100644 writerfilter/source/dmapper/BorderHandler.cxx create mode 100644 writerfilter/source/dmapper/BorderHandler.hxx create mode 100644 writerfilter/source/dmapper/CellColorHandler.cxx create mode 100644 writerfilter/source/dmapper/CellColorHandler.hxx create mode 100644 writerfilter/source/dmapper/CellMarginHandler.cxx create mode 100644 writerfilter/source/dmapper/CellMarginHandler.hxx create mode 100644 writerfilter/source/dmapper/ConversionHelper.cxx create mode 100644 writerfilter/source/dmapper/ConversionHelper.hxx create mode 100644 writerfilter/source/dmapper/DomainMapper.cxx create mode 100644 writerfilter/source/dmapper/DomainMapper.hxx create mode 100644 writerfilter/source/dmapper/DomainMapperTableHandler.cxx create mode 100644 writerfilter/source/dmapper/DomainMapperTableHandler.hxx create mode 100644 writerfilter/source/dmapper/DomainMapperTableManager.cxx create mode 100644 writerfilter/source/dmapper/DomainMapperTableManager.hxx create mode 100644 writerfilter/source/dmapper/DomainMapper_Impl.cxx create mode 100644 writerfilter/source/dmapper/DomainMapper_Impl.hxx create mode 100644 writerfilter/source/dmapper/FFDataHandler.cxx create mode 100644 writerfilter/source/dmapper/FFDataHandler.hxx create mode 100644 writerfilter/source/dmapper/FieldTypes.hxx create mode 100644 writerfilter/source/dmapper/FontTable.cxx create mode 100644 writerfilter/source/dmapper/FontTable.hxx create mode 100644 writerfilter/source/dmapper/FormControlHelper.cxx create mode 100644 writerfilter/source/dmapper/FormControlHelper.hxx create mode 100644 writerfilter/source/dmapper/GraphicHelpers.cxx create mode 100644 writerfilter/source/dmapper/GraphicHelpers.hxx create mode 100644 writerfilter/source/dmapper/GraphicImport.cxx create mode 100644 writerfilter/source/dmapper/GraphicImport.hxx create mode 100644 writerfilter/source/dmapper/LatentStyleHandler.cxx create mode 100644 writerfilter/source/dmapper/LatentStyleHandler.hxx create mode 100644 writerfilter/source/dmapper/LoggedResources.cxx create mode 100644 writerfilter/source/dmapper/LoggedResources.hxx create mode 100644 writerfilter/source/dmapper/MeasureHandler.cxx create mode 100644 writerfilter/source/dmapper/MeasureHandler.hxx create mode 100644 writerfilter/source/dmapper/ModelEventListener.cxx create mode 100644 writerfilter/source/dmapper/ModelEventListener.hxx create mode 100644 writerfilter/source/dmapper/NumberingManager.cxx create mode 100644 writerfilter/source/dmapper/NumberingManager.hxx create mode 100644 writerfilter/source/dmapper/OLEHandler.cxx create mode 100644 writerfilter/source/dmapper/OLEHandler.hxx create mode 100644 writerfilter/source/dmapper/PageBordersHandler.cxx create mode 100644 writerfilter/source/dmapper/PageBordersHandler.hxx create mode 100644 writerfilter/source/dmapper/PropertyIds.cxx create mode 100644 writerfilter/source/dmapper/PropertyIds.hxx create mode 100644 writerfilter/source/dmapper/PropertyMap.cxx create mode 100644 writerfilter/source/dmapper/PropertyMap.hxx create mode 100644 writerfilter/source/dmapper/PropertyMapHelper.cxx create mode 100644 writerfilter/source/dmapper/PropertyMapHelper.hxx create mode 100644 writerfilter/source/dmapper/SdtHelper.cxx create mode 100644 writerfilter/source/dmapper/SdtHelper.hxx create mode 100644 writerfilter/source/dmapper/SectionColumnHandler.cxx create mode 100644 writerfilter/source/dmapper/SectionColumnHandler.hxx create mode 100644 writerfilter/source/dmapper/SettingsTable.cxx create mode 100644 writerfilter/source/dmapper/SettingsTable.hxx create mode 100644 writerfilter/source/dmapper/SmartTagHandler.cxx create mode 100644 writerfilter/source/dmapper/SmartTagHandler.hxx create mode 100644 writerfilter/source/dmapper/StyleSheetTable.cxx create mode 100644 writerfilter/source/dmapper/StyleSheetTable.hxx create mode 100644 writerfilter/source/dmapper/TDefTableHandler.cxx create mode 100644 writerfilter/source/dmapper/TDefTableHandler.hxx create mode 100644 writerfilter/source/dmapper/TableData.hxx create mode 100644 writerfilter/source/dmapper/TableManager.cxx create mode 100644 writerfilter/source/dmapper/TableManager.hxx create mode 100644 writerfilter/source/dmapper/TablePositionHandler.cxx create mode 100644 writerfilter/source/dmapper/TablePositionHandler.hxx create mode 100644 writerfilter/source/dmapper/TablePropertiesHandler.cxx create mode 100644 writerfilter/source/dmapper/TablePropertiesHandler.hxx create mode 100644 writerfilter/source/dmapper/TagLogger.cxx create mode 100644 writerfilter/source/dmapper/TagLogger.hxx create mode 100644 writerfilter/source/dmapper/TblStylePrHandler.cxx create mode 100644 writerfilter/source/dmapper/TblStylePrHandler.hxx create mode 100644 writerfilter/source/dmapper/TextEffectsHandler.cxx create mode 100644 writerfilter/source/dmapper/TextEffectsHandler.hxx create mode 100644 writerfilter/source/dmapper/ThemeTable.cxx create mode 100644 writerfilter/source/dmapper/ThemeTable.hxx create mode 100644 writerfilter/source/dmapper/TrackChangesHandler.cxx create mode 100644 writerfilter/source/dmapper/TrackChangesHandler.hxx create mode 100644 writerfilter/source/dmapper/WrapPolygonHandler.cxx create mode 100644 writerfilter/source/dmapper/WrapPolygonHandler.hxx create mode 100644 writerfilter/source/dmapper/domainmapperfactory.cxx create mode 100644 writerfilter/source/dmapper/util.cxx create mode 100644 writerfilter/source/dmapper/util.hxx create mode 100644 writerfilter/source/filter/RtfFilter.cxx create mode 100644 writerfilter/source/filter/WriterFilter.cxx create mode 100644 writerfilter/source/ooxml/Handler.cxx create mode 100644 writerfilter/source/ooxml/Handler.hxx create mode 100644 writerfilter/source/ooxml/OOXMLBinaryObjectReference.cxx create mode 100644 writerfilter/source/ooxml/OOXMLBinaryObjectReference.hxx create mode 100644 writerfilter/source/ooxml/OOXMLDocumentImpl.cxx create mode 100644 writerfilter/source/ooxml/OOXMLDocumentImpl.hxx create mode 100644 writerfilter/source/ooxml/OOXMLFactory.cxx create mode 100644 writerfilter/source/ooxml/OOXMLFactory.hxx create mode 100644 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx create mode 100644 writerfilter/source/ooxml/OOXMLFastContextHandler.hxx create mode 100644 writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx create mode 100644 writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx create mode 100644 writerfilter/source/ooxml/OOXMLFastHelper.hxx create mode 100644 writerfilter/source/ooxml/OOXMLParserState.cxx create mode 100644 writerfilter/source/ooxml/OOXMLParserState.hxx create mode 100644 writerfilter/source/ooxml/OOXMLPropertySet.cxx create mode 100644 writerfilter/source/ooxml/OOXMLPropertySet.hxx create mode 100644 writerfilter/source/ooxml/OOXMLStreamImpl.cxx create mode 100644 writerfilter/source/ooxml/OOXMLStreamImpl.hxx create mode 100644 writerfilter/source/ooxml/README create mode 100644 writerfilter/source/ooxml/factory_ns.py create mode 100644 writerfilter/source/ooxml/factoryimpl.py create mode 100644 writerfilter/source/ooxml/factoryimpl_ns.py create mode 100644 writerfilter/source/ooxml/factoryinc.py create mode 100644 writerfilter/source/ooxml/model.xml create mode 100644 writerfilter/source/ooxml/modelpreprocess.py create mode 100644 writerfilter/source/ooxml/qnametostr.py create mode 100644 writerfilter/source/ooxml/resourceids.py create mode 100644 writerfilter/source/ooxml/tox.ini create mode 100644 writerfilter/source/rtftok/README create mode 100644 writerfilter/source/rtftok/rtfcharsets.cxx create mode 100644 writerfilter/source/rtftok/rtfcharsets.hxx create mode 100644 writerfilter/source/rtftok/rtfcontrolwords.cxx create mode 100644 writerfilter/source/rtftok/rtfcontrolwords.hxx create mode 100644 writerfilter/source/rtftok/rtfdispatchdestination.cxx create mode 100644 writerfilter/source/rtftok/rtfdispatchflag.cxx create mode 100644 writerfilter/source/rtftok/rtfdispatchsymbol.cxx create mode 100644 writerfilter/source/rtftok/rtfdispatchvalue.cxx create mode 100644 writerfilter/source/rtftok/rtfdocumentfactory.cxx create mode 100644 writerfilter/source/rtftok/rtfdocumentimpl.cxx create mode 100644 writerfilter/source/rtftok/rtfdocumentimpl.hxx create mode 100644 writerfilter/source/rtftok/rtffly.hxx create mode 100644 writerfilter/source/rtftok/rtflistener.hxx create mode 100644 writerfilter/source/rtftok/rtflookahead.cxx create mode 100644 writerfilter/source/rtftok/rtflookahead.hxx create mode 100644 writerfilter/source/rtftok/rtfreferenceproperties.cxx create mode 100644 writerfilter/source/rtftok/rtfreferenceproperties.hxx create mode 100644 writerfilter/source/rtftok/rtfreferencetable.cxx create mode 100644 writerfilter/source/rtftok/rtfreferencetable.hxx create mode 100644 writerfilter/source/rtftok/rtfsdrimport.cxx create mode 100644 writerfilter/source/rtftok/rtfsdrimport.hxx create mode 100644 writerfilter/source/rtftok/rtfskipdestination.cxx create mode 100644 writerfilter/source/rtftok/rtfskipdestination.hxx create mode 100644 writerfilter/source/rtftok/rtfsprm.cxx create mode 100644 writerfilter/source/rtftok/rtfsprm.hxx create mode 100644 writerfilter/source/rtftok/rtftokenizer.cxx create mode 100644 writerfilter/source/rtftok/rtftokenizer.hxx create mode 100644 writerfilter/source/rtftok/rtfvalue.cxx create mode 100644 writerfilter/source/rtftok/rtfvalue.hxx create mode 100644 writerfilter/util/writerfilter.component (limited to 'writerfilter') diff --git a/writerfilter/CppunitTest_writerfilter_dmapper.mk b/writerfilter/CppunitTest_writerfilter_dmapper.mk new file mode 100644 index 000000000..7fe8b9035 --- /dev/null +++ b/writerfilter/CppunitTest_writerfilter_dmapper.mk @@ -0,0 +1,55 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,writerfilter_dmapper)) + +$(eval $(call gb_CppunitTest_use_externals,writerfilter_dmapper,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_dmapper, \ + writerfilter/qa/cppunittests/dmapper/CellColorHandler \ + writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler \ + writerfilter/qa/cppunittests/dmapper/DomainMapper \ + writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl \ + writerfilter/qa/cppunittests/dmapper/GraphicImport \ + writerfilter/qa/cppunittests/dmapper/TextEffectsHandler \ + writerfilter/qa/cppunittests/dmapper/PropertyMap \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,writerfilter_dmapper, \ + basegfx \ + comphelper \ + cppu \ + oox \ + sal \ + test \ + unotest \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,writerfilter_dmapper)) + +$(eval $(call gb_CppunitTest_use_ure,writerfilter_dmapper)) +$(eval $(call gb_CppunitTest_use_vcl,writerfilter_dmapper)) + +$(eval $(call gb_CppunitTest_use_rdb,writerfilter_dmapper,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,writerfilter_dmapper,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,writerfilter_dmapper)) + +# we need to explicitly depend on library writerfilter because it is not implied +# by a link relation +$(call gb_CppunitTest_get_target,writerfilter_dmapper) : $(call gb_Library_get_target,writerfilter) + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/CppunitTest_writerfilter_filters_test.mk b/writerfilter/CppunitTest_writerfilter_filters_test.mk new file mode 100644 index 000000000..a08c66675 --- /dev/null +++ b/writerfilter/CppunitTest_writerfilter_filters_test.mk @@ -0,0 +1,61 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,writerfilter_filters_test)) + +$(eval $(call gb_CppunitTest_use_external,writerfilter_filters_test,boost_headers)) + +$(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_filters_test, \ + writerfilter/qa/cppunittests/filters-test/filters-test \ +)) + +ifeq ($(DISABLE_CVE_TESTS),TRUE) +$(eval $(call gb_CppunitTest_add_defs,writerfilter_filters_test,\ + -DDISABLE_CVE_TESTS \ +)) +endif + +$(eval $(call gb_CppunitTest_use_libraries,writerfilter_filters_test, \ + comphelper \ + cppu \ + cppuhelper \ + sal \ + test \ + unotest \ + vcl \ + writerfilter \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,writerfilter_filters_test)) + +$(eval $(call gb_CppunitTest_use_ure,writerfilter_filters_test)) +$(eval $(call gb_CppunitTest_use_vcl,writerfilter_filters_test)) + +$(eval $(call gb_CppunitTest_use_components,writerfilter_filters_test,\ + configmgr/source/configmgr \ + framework/util/fwk \ + i18npool/util/i18npool \ + svtools/util/svt \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + writerfilter/util/writerfilter \ + vcl/vcl.common \ +)) + + + +$(eval $(call gb_CppunitTest_use_configuration,writerfilter_filters_test)) + +# we need to explicitly depend on library writerfilter because it is not implied +# by a link relation +$(call gb_CppunitTest_get_target,writerfilter_filters_test) : $(call gb_Library_get_target,writerfilter) + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/CppunitTest_writerfilter_misc.mk b/writerfilter/CppunitTest_writerfilter_misc.mk new file mode 100644 index 000000000..1b45ec716 --- /dev/null +++ b/writerfilter/CppunitTest_writerfilter_misc.mk @@ -0,0 +1,43 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,writerfilter_misc)) + +$(eval $(call gb_CppunitTest_use_sdk_api,writerfilter_misc)) + +$(eval $(call gb_CppunitTest_use_custom_headers,writerfilter_misc,\ + writerfilter/source \ +)) + +$(eval $(call gb_CppunitTest_set_include,writerfilter_misc,\ + $$(INCLUDE) \ + -I$(SRCDIR)/writerfilter/inc \ + -I$(SRCDIR)/writerfilter/source \ + -I$(SRCDIR)/writerfilter/source/dmapper \ +)) + +$(eval $(call gb_CppunitTest_use_external,writerfilter_misc,boost_headers)) + +$(eval $(call gb_CppunitTest_use_libraries,writerfilter_misc, \ + writerfilter \ + cppu \ + sal \ + salhelper \ +)) + +$(eval $(call gb_CppunitTest_use_externals,writerfilter_misc,\ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_misc, \ + writerfilter/qa/cppunittests/misc/misc \ +)) + + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/CppunitTest_writerfilter_rtftok.mk b/writerfilter/CppunitTest_writerfilter_rtftok.mk new file mode 100644 index 000000000..db038292e --- /dev/null +++ b/writerfilter/CppunitTest_writerfilter_rtftok.mk @@ -0,0 +1,50 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,writerfilter_rtftok)) + +$(eval $(call gb_CppunitTest_use_externals,writerfilter_rtftok,\ + boost_headers \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_rtftok, \ + writerfilter/qa/cppunittests/rtftok/rtfsdrimport \ + writerfilter/qa/cppunittests/rtftok/rtfsprm \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,writerfilter_rtftok, \ + basegfx \ + comphelper \ + cppu \ + oox \ + sal \ + test \ + unotest \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,writerfilter_rtftok)) + +$(eval $(call gb_CppunitTest_use_ure,writerfilter_rtftok)) +$(eval $(call gb_CppunitTest_use_vcl,writerfilter_rtftok)) + +$(eval $(call gb_CppunitTest_use_rdb,writerfilter_rtftok,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,writerfilter_rtftok,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,writerfilter_rtftok)) + +# we need to explicitly depend on library writerfilter because it is not implied +# by a link relation +$(call gb_CppunitTest_get_target,writerfilter_rtftok) : $(call gb_Library_get_target,writerfilter) + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/CustomTarget_source.mk b/writerfilter/CustomTarget_source.mk new file mode 100644 index 000000000..8d7b3d22b --- /dev/null +++ b/writerfilter/CustomTarget_source.mk @@ -0,0 +1,110 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CustomTarget_CustomTarget,writerfilter/source)) + +writerfilter_WORK := $(call gb_CustomTarget_get_workdir,writerfilter/source) +writerfilter_SRC := $(SRCDIR)/writerfilter/source + +writerfilter_PYTHONCOMMAND := $(call gb_ExternalExecutable_get_command,python) +writerfilter_XMLLINTCOMMAND := $(call gb_ExternalExecutable_get_command,xmllint) + +writerfilter_OOXMLNAMESPACES= \ + dml-baseStylesheet \ + dml-baseTypes \ + dml-chartDrawing \ + dml-documentProperties \ + dml-graphicalObject \ + dml-shape3DCamera \ + dml-shape3DLighting \ + dml-shape3DScene \ + dml-shape3DStyles \ + dml-shapeEffects \ + dml-shapeGeometry \ + dml-shapeLineProperties \ + dml-shapeProperties \ + dml-styleDefaults \ + dml-stylesheet \ + dml-textCharacter \ + dml-wordprocessingDrawing \ + shared-math \ + shared-relationshipReference \ + sml-customXmlMappings \ + vml-main \ + vml-officeDrawing \ + vml-wordprocessingDrawing \ + wp14 \ + w14 \ + a14 \ + wml + +writerfilter_ALL = \ + $(writerfilter_GEN_ooxml_Factory_cxx) \ + $(writerfilter_GEN_ooxml_Factory_hxx) \ + $(writerfilter_GEN_ooxml_FactoryValues_hxx) \ + $(writerfilter_GEN_ooxml_QNameToStr_cxx) \ + $(writerfilter_GEN_ooxml_ResourceIds_hxx) \ + $(writerfilter_GEN_ooxml_Model_validated) \ + $(writerfilter_GEN_ooxml_Model_processed) \ + $(patsubst %,$(writerfilter_WORK)/ooxml/OOXMLFactory_%.hxx,$(writerfilter_OOXMLNAMESPACES)) \ + $(patsubst %,$(writerfilter_WORK)/ooxml/OOXMLFactory_%.cxx,$(writerfilter_OOXMLNAMESPACES)) \ + +writerfilter_DEP_ooxml_Namespaces_txt=$(call gb_CustomTarget_get_workdir,oox/generated)/misc/namespaces.txt +writerfilter_GEN_ooxml_FactoryValues_hxx=$(writerfilter_WORK)/ooxml/OOXMLFactory_values.hxx +writerfilter_GEN_ooxml_Factory_cxx=$(writerfilter_WORK)/ooxml/OOXMLFactory_generated.cxx +writerfilter_GEN_ooxml_Factory_hxx=$(writerfilter_WORK)/ooxml/OOXMLFactory_generated.hxx +writerfilter_GEN_ooxml_Model_validated=$(writerfilter_WORK)/ooxml/model.validated +writerfilter_GEN_ooxml_Model_processed=$(writerfilter_WORK)/ooxml/model_preprocessed.xml +writerfilter_GEN_ooxml_QNameToStr_cxx=$(writerfilter_WORK)/ooxml/qnametostr.cxx +writerfilter_GEN_ooxml_ResourceIds_hxx=$(writerfilter_WORK)/ooxml/resourceids.hxx +writerfilter_SRC_ooxml_Model=$(writerfilter_SRC)/ooxml/model.xml +writerfilter_SRC_ooxml_Preprocess_py=$(writerfilter_SRC)/ooxml/modelpreprocess.py +writerfilter_SRC_ooxml_QNameToStr_py=$(writerfilter_SRC)/ooxml/qnametostr.py +writerfilter_SRC_ooxml_ResourceIds_py=$(writerfilter_SRC)/ooxml/resourceids.py + +$(writerfilter_GEN_ooxml_Factory_cxx) : $(writerfilter_SRC)/ooxml/factoryimpl.py $(writerfilter_DEP_ooxml_Namespaces_txt) $(writerfilter_GEN_ooxml_Model_processed) + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) + $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $< $(writerfilter_DEP_ooxml_Namespaces_txt) $(writerfilter_GEN_ooxml_Model_processed)) > $@ + +$(writerfilter_GEN_ooxml_Factory_hxx) : $(writerfilter_SRC)/ooxml/factoryinc.py $(writerfilter_GEN_ooxml_Model_processed) + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) + $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed)) > $@ + +$(writerfilter_GEN_ooxml_Model_validated) : $(writerfilter_SRC)/../documentation/ooxml/model.rng $(writerfilter_SRC_ooxml_Model) + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,VAL,1) + $(call gb_Helper_abbreviate_dirs,\ + $(writerfilter_XMLLINTCOMMAND) --noout --relaxng $(writerfilter_SRC)/../documentation/ooxml/model.rng $(writerfilter_SRC_ooxml_Model) > $@ 2>&1 \ + || (cat $@; false)) + +$(writerfilter_GEN_ooxml_Model_processed) : $(writerfilter_SRC_ooxml_Preprocess_py) $(writerfilter_DEP_ooxml_Namespaces_txt) $(writerfilter_GEN_ooxml_Model_validated) + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) + $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $(writerfilter_SRC_ooxml_Preprocess_py) $(writerfilter_DEP_ooxml_Namespaces_txt) $(writerfilter_SRC_ooxml_Model)) > $@ + +$(writerfilter_GEN_ooxml_QNameToStr_cxx): $(writerfilter_SRC_ooxml_QNameToStr_py) $(writerfilter_GEN_ooxml_Model_processed) + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) + $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $(writerfilter_SRC_ooxml_QNameToStr_py) $(writerfilter_GEN_ooxml_Model_processed)) > $@ + +$(writerfilter_GEN_ooxml_ResourceIds_hxx) : $(writerfilter_SRC_ooxml_ResourceIds_py) $(writerfilter_GEN_ooxml_Model_processed) | $(writerfilter_WORK)/ooxml/.dir + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) + $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $(writerfilter_SRC_ooxml_ResourceIds_py) $(writerfilter_GEN_ooxml_Model_processed)) > $@ + +$(writerfilter_WORK)/ooxml/OOXMLFactory%.cxx : $(writerfilter_SRC)/ooxml/factoryimpl_ns.py $(writerfilter_GEN_ooxml_Model_processed) + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) + $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed) $@) > $@ + +$(writerfilter_WORK)/ooxml/OOXMLFactory%.hxx : $(writerfilter_SRC)/ooxml/factory_ns.py $(writerfilter_GEN_ooxml_Model_processed) + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,PY ,1) + $(call gb_Helper_abbreviate_dirs, $(writerfilter_PYTHONCOMMAND) $< $(writerfilter_GEN_ooxml_Model_processed) $@) > $@ + + +$(call gb_CustomTarget_get_target,writerfilter/source) : $(writerfilter_ALL) + +$(writerfilter_ALL) :| $(call gb_ExternalExecutable_get_dependencies,python) $(call gb_ExternalExecutable_get_dependencies,xmllint) $(writerfilter_WORK)/ooxml/.dir + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/IwyuFilter_writerfilter.yaml b/writerfilter/IwyuFilter_writerfilter.yaml new file mode 100644 index 000000000..2dd4de4a4 --- /dev/null +++ b/writerfilter/IwyuFilter_writerfilter.yaml @@ -0,0 +1,66 @@ +--- +assumeFilename: writerfilter/source/filter/WriterFilter.cxx +blacklist: + writerfilter/source/dmapper/BorderHandler.cxx: + # Needed for method parameter type + - tools/color.hxx + writerfilter/source/dmapper/ConversionHelper.cxx: + # Actually used + - com/sun/star/table/BorderLine2.hpp + - com/sun/star/lang/Locale.hpp + writerfilter/source/dmapper/DomainMapperTableManager.cxx: + # Needed for rtl::math::round + - rtl/math.hxx + writerfilter/source/dmapper/GraphicImport.cxx: + # Actually used + - com/sun/star/drawing/XShape.hpp + - com/sun/star/graphic/XGraphic.hpp + - com/sun/star/lang/XMultiServiceFactory.hpp + - com/sun/star/uno/XComponentContext.hpp + # Needed for rtl::math::round + - rtl/math.hxx + writerfilter/source/dmapper/NumberingManager.cxx: + # Actually used + - com/sun/star/lang/XMultiServiceFactory.hpp + - com/sun/star/container/XNameContainer.hpp + writerfilter/source/dmapper/DomainMapper_Impl.cxx: + # Actually used + - com/sun/star/uno/XComponentContext.hpp + writerfilter/source/dmapper/OLEHandler.cxx: + # Actually used + - com/sun/star/drawing/XShape.hpp + - com/sun/star/graphic/XGraphic.hpp + - com/sun/star/text/XTextDocument.hpp + - com/sun/star/text/WrapTextMode.hpp + - com/sun/star/uno/XComponentContext.hpp + writerfilter/source/dmapper/TDefTableHandler.cxx: + # Needed for method parameter type + - tools/color.hxx + writerfilter/source/dmapper/TablePositionHandler.cxx: + # Actually used + - com/sun/star/beans/PropertyValue.hpp + writerfilter/source/dmapper/PropertyMap.cxx: + # Actually used + - com/sun/star/beans/PropertyValue.hpp + - com/sun/star/text/XTextColumns.hpp + writerfilter/source/dmapper/StyleSheetTable.cxx: + # Actually used + - com/sun/star/text/XTextDocument.hpp + writerfilter/source/ooxml/OOXMLPropertySet.cxx: + # Actually used + - com/sun/star/drawing/XShape.hpp + writerfilter/source/rtftok/rtfsdrimport.hxx: + # IWYU assumes std::stack in a header is OK, but that's not + # the case for all of LO's supported platforms. + # See . + - dmapper/GraphicZOrderHelper.hxx + writerfilter/source/rtftok/rtfvalue.cxx: + # complete type is needed + - com/sun/star/embed/XEmbeddedObject.hpp + writerfilter/source/rtftok/rtftokenizer.cxx: + # Actually used + - com/sun/star/task/XStatusIndicator.hpp + writerfilter/source/filter/RtfFilter.cxx: + - comphelper/scopeguard.hxx + writerfilter/source/filter/WriterFilter.cxx: + - comphelper/scopeguard.hxx diff --git a/writerfilter/Library_writerfilter.mk b/writerfilter/Library_writerfilter.mk new file mode 100644 index 000000000..add7c20bb --- /dev/null +++ b/writerfilter/Library_writerfilter.mk @@ -0,0 +1,136 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Library_Library,writerfilter)) + +$(eval $(call gb_Library_use_custom_headers,writerfilter,\ + officecfg/registry \ + oox/generated \ + writerfilter/source \ +)) + +$(eval $(call gb_Library_set_precompiled_header,writerfilter,writerfilter/inc/pch/precompiled_writerfilter)) + +$(eval $(call gb_Library_set_include,writerfilter,\ + $$(INCLUDE) \ + -I$(SRCDIR)/writerfilter/inc \ + -I$(SRCDIR)/writerfilter/source \ +)) + +$(eval $(call gb_Library_use_sdk_api,writerfilter)) + +$(eval $(call gb_Library_set_componentfile,writerfilter,writerfilter/util/writerfilter)) + +$(eval $(call gb_Library_use_libraries,writerfilter,\ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + editeng \ + i18nlangtag \ + i18nutil \ + msfilter \ + oox \ + sal \ + salhelper \ + sax \ + sfx \ + sot \ + svt \ + svxcore \ + tl \ + utl \ + vcl \ +)) + +$(eval $(call gb_Library_use_externals,writerfilter,\ + boost_headers \ + icui18n \ + icuuc \ + icu_headers \ + libxml2 \ +)) + +$(eval $(call gb_Library_add_exception_objects,writerfilter,\ + writerfilter/source/rtftok/rtfcharsets \ + writerfilter/source/rtftok/rtfcontrolwords \ + writerfilter/source/rtftok/rtfdispatchdestination \ + writerfilter/source/rtftok/rtfdispatchflag \ + writerfilter/source/rtftok/rtfdispatchsymbol \ + writerfilter/source/rtftok/rtfdispatchvalue \ + writerfilter/source/rtftok/rtfdocumentfactory \ + writerfilter/source/rtftok/rtfdocumentimpl \ + writerfilter/source/rtftok/rtflookahead \ + writerfilter/source/rtftok/rtfreferenceproperties \ + writerfilter/source/rtftok/rtfreferencetable \ + writerfilter/source/rtftok/rtfsdrimport \ + writerfilter/source/rtftok/rtfskipdestination \ + writerfilter/source/rtftok/rtfsprm \ + writerfilter/source/rtftok/rtftokenizer \ + writerfilter/source/rtftok/rtfvalue \ + writerfilter/source/dmapper/BorderHandler \ + writerfilter/source/dmapper/CellColorHandler \ + writerfilter/source/dmapper/CellMarginHandler \ + writerfilter/source/dmapper/ConversionHelper \ + writerfilter/source/dmapper/DomainMapper \ + writerfilter/source/dmapper/DomainMapperTableHandler \ + writerfilter/source/dmapper/DomainMapperTableManager \ + writerfilter/source/dmapper/DomainMapper_Impl \ + writerfilter/source/dmapper/domainmapperfactory \ + writerfilter/source/dmapper/FFDataHandler \ + writerfilter/source/dmapper/FontTable \ + writerfilter/source/dmapper/FormControlHelper \ + writerfilter/source/dmapper/GraphicHelpers \ + writerfilter/source/dmapper/GraphicImport \ + writerfilter/source/dmapper/LatentStyleHandler \ + writerfilter/source/dmapper/LoggedResources \ + writerfilter/source/dmapper/MeasureHandler \ + writerfilter/source/dmapper/TrackChangesHandler \ + writerfilter/source/dmapper/ModelEventListener \ + writerfilter/source/dmapper/NumberingManager \ + writerfilter/source/dmapper/OLEHandler \ + writerfilter/source/dmapper/PageBordersHandler \ + writerfilter/source/dmapper/PropertyIds \ + writerfilter/source/dmapper/PropertyMap \ + writerfilter/source/dmapper/PropertyMapHelper \ + writerfilter/source/dmapper/SdtHelper \ + writerfilter/source/dmapper/SectionColumnHandler \ + writerfilter/source/dmapper/SettingsTable \ + writerfilter/source/dmapper/SmartTagHandler \ + writerfilter/source/dmapper/StyleSheetTable \ + writerfilter/source/dmapper/TDefTableHandler \ + writerfilter/source/dmapper/TableManager \ + writerfilter/source/dmapper/TablePositionHandler \ + writerfilter/source/dmapper/TablePropertiesHandler \ + writerfilter/source/dmapper/TagLogger \ + writerfilter/source/dmapper/TextEffectsHandler \ + writerfilter/source/dmapper/TblStylePrHandler \ + writerfilter/source/dmapper/ThemeTable \ + writerfilter/source/dmapper/WrapPolygonHandler \ + writerfilter/source/dmapper/util \ + writerfilter/source/filter/RtfFilter \ + writerfilter/source/filter/WriterFilter \ + writerfilter/source/ooxml/Handler \ + writerfilter/source/ooxml/OOXMLBinaryObjectReference \ + writerfilter/source/ooxml/OOXMLDocumentImpl \ + writerfilter/source/ooxml/OOXMLFactory \ + writerfilter/source/ooxml/OOXMLFastContextHandler \ + writerfilter/source/ooxml/OOXMLFastDocumentHandler \ + writerfilter/source/ooxml/OOXMLParserState \ + writerfilter/source/ooxml/OOXMLPropertySet \ + writerfilter/source/ooxml/OOXMLStreamImpl \ +)) + +$(eval $(call gb_Library_add_generated_exception_objects,writerfilter,\ + $(patsubst %,CustomTarget/writerfilter/source/ooxml/OOXMLFactory_%,$(writerfilter_OOXMLNAMESPACES)) \ + CustomTarget/writerfilter/source/ooxml/OOXMLFactory_generated \ + CustomTarget/writerfilter/source/ooxml/qnametostr \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/Makefile b/writerfilter/Makefile new file mode 100644 index 000000000..ccb1c85a0 --- /dev/null +++ b/writerfilter/Makefile @@ -0,0 +1,7 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- + +module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +include $(module_directory)/../solenv/gbuild/partial_build.mk + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/Module_writerfilter.mk b/writerfilter/Module_writerfilter.mk new file mode 100644 index 000000000..46d7af0ff --- /dev/null +++ b/writerfilter/Module_writerfilter.mk @@ -0,0 +1,24 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Module_Module,writerfilter)) + +$(eval $(call gb_Module_add_targets,writerfilter,\ + CustomTarget_source \ + Library_writerfilter \ +)) + +$(eval $(call gb_Module_add_slowcheck_targets,writerfilter,\ + CppunitTest_writerfilter_filters_test \ + CppunitTest_writerfilter_misc \ + CppunitTest_writerfilter_dmapper \ + CppunitTest_writerfilter_rtftok \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/README b/writerfilter/README new file mode 100644 index 000000000..7a9c8cc57 --- /dev/null +++ b/writerfilter/README @@ -0,0 +1,20 @@ +The writerfilter module contains import filters for Writer, using its UNO API. + +Import filter for docx and rtf. + +== Module contents == + * documentation: RNG schema for the OOXML tokenizer, etc. + * inc: module-global headers (can be included by any files under source) + * qa: cppunit tests + * source: the filters themselves + * util: UNO passive registration config + +== Source contents == + * dmapper: the domain mapper, hiding UNO from the tokenizers, used by DOCX and RTF import + * The incoming traffic of dmapper can be dumped into an XML file in /tmp in + dbgutil builds, start soffice with the `SW_DEBUG_WRITERFILTER=1` + environment variable if you want that. + * filter: the UNO filter service implementations, invoked by UNO and calling + the dmapper + one of the tokenizers + * ooxml: the docx tokenizer + * rtftok: the rtf tokenizer diff --git a/writerfilter/documentation/KnownIssues.txt b/writerfilter/documentation/KnownIssues.txt new file mode 100644 index 000000000..6c84daf0f --- /dev/null +++ b/writerfilter/documentation/KnownIssues.txt @@ -0,0 +1,27 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +- footnotes/endnotes: font index cannot be applied to Writer's footnote symbol +in the footnote area +- border types: width of border lines are changed to fit Writer's defaults, +triple borders unsupported +- there are no unlocked (writeable) sections within a read only document in +Writer +- multiple fields are either unsupported or drastically converted (see +DomainMapper_Impl.cxx) +- borders cannot be applied to whole document (from sections) diff --git a/writerfilter/documentation/TODO b/writerfilter/documentation/TODO new file mode 100644 index 000000000..2f85ab6a2 --- /dev/null +++ b/writerfilter/documentation/TODO @@ -0,0 +1,13 @@ +Import + +- Change Tracking +- Tables + - attributes + - merged cells +- Shapes + - Shapes generated by Word + - Shapes generated by PowerPoint and imported via clipboard +- Pictures +- OLE objects +- Sections +- Fields diff --git a/writerfilter/documentation/doxygen/Doxyfile b/writerfilter/documentation/doxygen/Doxyfile new file mode 100644 index 000000000..15414b828 --- /dev/null +++ b/writerfilter/documentation/doxygen/Doxyfile @@ -0,0 +1,1254 @@ +# Doxyfile 1.4.6 +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = writerfilter + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = $(WORKSTAMP) + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = NO + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = YES + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = ../../inc ../../source + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = *.cxx *.hxx *.java + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = CVS + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = images + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = YES + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = $(SOLARINC) + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate an inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = YES + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = YES + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 512 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 4 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = YES + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = YES + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/writerfilter/documentation/doxygen/images/doctok.png b/writerfilter/documentation/doxygen/images/doctok.png new file mode 100644 index 000000000..15adb9670 Binary files /dev/null and b/writerfilter/documentation/doxygen/images/doctok.png differ diff --git a/writerfilter/documentation/doxygen/images/ooxmlimportchain.png b/writerfilter/documentation/doxygen/images/ooxmlimportchain.png new file mode 100644 index 000000000..509f1cab5 Binary files /dev/null and b/writerfilter/documentation/doxygen/images/ooxmlimportchain.png differ diff --git a/writerfilter/documentation/ooxml/model.rng b/writerfilter/documentation/ooxml/model.rng new file mode 100644 index 000000000..a29e14992 --- /dev/null +++ b/writerfilter/documentation/ooxml/model.rng @@ -0,0 +1,436 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/writerfilter/documentation/sprms.txt b/writerfilter/documentation/sprms.txt new file mode 100644 index 000000000..6250de9e4 --- /dev/null +++ b/writerfilter/documentation/sprms.txt @@ -0,0 +1,7 @@ +0x2461: extra alignment: + + 4: distributed + 8: justify low + 5: justify middle + 7: justify high + 9: Thai Distribute diff --git a/writerfilter/documentation/tablesInDoc.txt b/writerfilter/documentation/tablesInDoc.txt new file mode 100644 index 000000000..50c58a4e2 --- /dev/null +++ b/writerfilter/documentation/tablesInDoc.txt @@ -0,0 +1,153 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +All paragraphs in tables: + + sprms: + 0x2416 (sprmPFInTable) indicates a paragraph is in a table + 0x6649 (sprmPTableDepth) demarks the nesting depth of the paragraph + +paragraph at nesting depth 1: + + end of cell: 0x7 + end of row: 0x7 + sprm 0x2417(sprmFTtp) + + the end of a row has its own 0x7 + +paragraphs at nesting depth > 1; + + end of cell: 0xd + sprm 0x244b(sprmPCell) + end of row 0xd + sprm 0x244b(sprmPCell) + sprm 0x244c(sprmPRow) + + the end of a row has its own 0xd + +Algorithm to detect table structure: + +Datastructures: + +RowData: + int getCellCount() + // return number of cells in row + Handle getStart(i) + // get handle for start of cell i + Handle getEnd(i) + // get handle for end off cell i + Properties getProperties() + // return properties of row + +TableData: + void addCell(Handle start, Handle end) + // insert cell starting at start and ending at end into the + // current row + void endRow(properties) + // end current row and save properties for that row, begin new row + int getRowCount + // return number of rows in table + RowData getRow(i) + // get data for row i + +prevTableDepth + depth in table hierarchy of previous paragraph + +curTableDepth + depth in table hierarchy of current paragraph + +bInCell + true if current paragraph is in a cell + +bEndCell + true if current paragraph if the last paragraph of a cell + +bEndRow + true if current paragraph is the end of a row + +paragraphHandle + handle for current paragraph + +initial: + create stack of TableData + +final: + handle remaining TableData on stack + +creating StreamHandler: + push new TableData on stack + +destroying StreamHandler: + handle TableData on top of stack + pop TableData from stack + +StreamHandler::substream: + push new TableData on stack + handle TableData on top of stack + pop TableData from stack + +starting paragraph group: + paragraphHandle = currentHandle; + bInCell = false; + bCellEnd = false; + bRowEnd = false; + +ending paragraph group: + difference = curTableDepth - prevTableDepth + + if (difference > 0) + push difference new TableData onto stack + else if (difference < 0) + { + repeat difference times + { + handle top of stack + pop stack + } + } + precTableDepth = curTableDepth + + if (bInCell) + { + if (handleStart is null) + handleStart = paragraphHandle; + + if (bCellEnd) + { + stack.top().addCell(handleStart, paragraphHandle); + clear handleStart + } + + if (bRowEnd) + { + stack.top().endRow(properties) + } + + +in StreamHandler::props: + save properties + +PropertiesHandler::sprm: + sprm 0x6649: + save value in curTableDepth + sprm 0x2416: + bInCell = true + sprm 0x244b: + bCellEnd = true + sprm 0x2417: + bRowEnd = true + +text: + 0x7: + bCellEnd = true diff --git a/writerfilter/inc/dmapper/DomainMapperFactory.hxx b/writerfilter/inc/dmapper/DomainMapperFactory.hxx new file mode 100644 index 000000000..624805cad --- /dev/null +++ b/writerfilter/inc/dmapper/DomainMapperFactory.hxx @@ -0,0 +1,54 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_INC_DMAPPER_DOMAINMAPPERFACTORY_HXX +#define INCLUDED_WRITERFILTER_INC_DMAPPER_DOMAINMAPPERFACTORY_HXX + +#include + +#include +#include +#include +#include + +namespace utl +{ +class MediaDescriptor; +} + +namespace writerfilter +{ +namespace dmapper +{ +enum class SourceDocumentType +{ + OOXML, + RTF +}; + +/// Interface to create a DomainMapper instance. +class DomainMapperFactory +{ +public: + static Stream::Pointer_t + createMapper(css::uno::Reference const& xContext, + css::uno::Reference const& xInputStream, + css::uno::Reference const& xModel, bool bRepairStorage, + SourceDocumentType eDocumentType, utl::MediaDescriptor const& rMediaDesc); +}; + +// export just for test +SAL_DLLPUBLIC_EXPORT std::tuple, std::vector> +splitFieldCommand(const OUString& rCommand); + +} // namespace dmapper +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_INC_DMAPPER_DOMAINMAPPERFACTORY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/dmapper/GraphicZOrderHelper.hxx b/writerfilter/inc/dmapper/GraphicZOrderHelper.hxx new file mode 100644 index 000000000..c566eec17 --- /dev/null +++ b/writerfilter/inc/dmapper/GraphicZOrderHelper.hxx @@ -0,0 +1,36 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_INC_DMAPPER_GRAPHICZORDERHELPER_HXX +#define INCLUDED_WRITERFILTER_INC_DMAPPER_GRAPHICZORDERHELPER_HXX + +#include +#include + +namespace writerfilter +{ +namespace dmapper +{ +class GraphicZOrderHelper +{ +public: + void addItem(css::uno::Reference const& props, + sal_Int32 relativeHeight); + sal_Int32 findZOrder(sal_Int32 relativeHeight, bool bOldStyle = false); + +private: + using Items = std::map>; + Items items; +}; + +} // namespace dmapper +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_INC_DMAPPER_GRAPHICZORDERHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/dmapper/resourcemodel.hxx b/writerfilter/inc/dmapper/resourcemodel.hxx new file mode 100644 index 000000000..284e9982f --- /dev/null +++ b/writerfilter/inc/dmapper/resourcemodel.hxx @@ -0,0 +1,406 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX +#define INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX + +#include +#include +#include +#include +#include + +/** + @file resourcemodel.hxx + + The classes in this file define the interfaces for the resource + model of the DocTokenizer: + + @image html doctok.png + + A resource is a set of events that describe an object. A resource + is only an abstract concept. It is not instantiated to a class. + + A reference to a resource represents the object that the resource + describes. The reference can be resolved thereby generating the + events of the resource. + + A handler receives the events generated by resolving a + reference. There are several types of handlers each accepting their + specific set of events. + + References always have a parameter determining the kind of handler + they send the events they generate to. The set of events generated + by resolving the reference is a subset of the events received by + the handler. +*/ + + +typedef sal_uInt32 Id; + +namespace writerfilter { + +/** + Reference to a resource that generates events and sends them to a + handler. + + The reference can be resolved, i.e. the resource generates its + events. The events must be suitable for the handler type given by + the template parameter. + + @attention The parameter of the template does not determine the + type of the reference's target. It determines the type of the handler! + + Example: + + A Word document can be represented as a stream of events. Event + types in a Word document are text, properties, tables, starts and + ends of groups. These can be handled by a stream handler (@see + Stream). Thus a reference to a Word document is resolved by + sending these events to a stream handler. +*/ + +template +class SAL_DLLPUBLIC_TEMPLATE Reference : public virtual SvRefBase +{ +public: + /** + Pointer to reference + + @attention The ownership of a reference is transferred when + the reference is passed. + */ + typedef tools::SvRef< Reference > Pointer_t; + + /** + Resolves the reference. + + The events of the references target resource are generated and + send to a handler. + + @param rHandler handler which receives the events + */ + virtual void resolve(T & rHandler) = 0; + + Reference() = default; + Reference(Reference const &) = default; + Reference(Reference &&) = default; + Reference & operator =(Reference const &) = default; + Reference & operator =(Reference &&) = default; + +protected: + ~Reference() override {} +}; + +class Value; +class Sprm; + +/** + Handler for properties. + */ +class Properties : public virtual SvRefBase +{ +public: + /** + Receives an attribute. + + @param name name of the attribute + @param val value of the attribute + */ + virtual void attribute(Id name, Value & val) = 0; + + /** + Receives a SPRM. + + @param sprm the SPRM received + */ + virtual void sprm(Sprm & sprm) = 0; + +protected: + ~Properties() override {} +}; + +/** + Handler for tables. + */ +class Table : public virtual SvRefBase +{ +public: + typedef tools::SvRef Pointer_t; + + /** + Receives an entry of the table. + + @param pos position of the entry in the table + @param ref reference to properties of the entry + */ + virtual void entry(int pos, writerfilter::Reference::Pointer_t ref) = 0; + +protected: + ~Table() override {} +}; + +/** + Handler for binary objects. + */ +class BinaryObj +{ +public: + /** + Receives binary data of the object. + + @param buf pointer to buffer containing the data + @param len size of buffer + */ + virtual void data(const sal_uInt8* buf, size_t len) = 0; + +protected: + ~BinaryObj() {} +}; + +const sal_uInt8 cFieldStart = 0x13; +const sal_uInt8 cFieldSep = 0x14; +const sal_uInt8 cFieldEnd = 0x15; + +/** + Handler for a stream. + */ +class Stream : public virtual SvRefBase +{ +public: + + /** + Pointer to this stream. + */ + typedef tools::SvRef Pointer_t; + + /** + Receives start mark for group with the same section properties. + */ + virtual void startSectionGroup() = 0; + + /** + Receives end mark for group with the same section properties. + */ + virtual void endSectionGroup() = 0; + + /// The current section is the last one in this body text. + virtual void markLastSectionGroup( ) { }; + + /** + Receives start mark for group with the same paragraph properties. + */ + virtual void startParagraphGroup() = 0; + + /** + Receives end mark for group with the same paragraph properties. + */ + virtual void endParagraphGroup() = 0; + + virtual void markLastParagraphInSection( ) { }; + + /** + Receives start mark for group with the same character properties. + */ + virtual void startCharacterGroup() = 0; + + /** + Receives end mark for group with the same character properties. + */ + virtual void endCharacterGroup() = 0; + + /** + Receives a shape. + */ + virtual void startShape(css::uno::Reference const& xShape) = 0; + + virtual void endShape( ) = 0; + + /** + Receives 8-bit per character text. + + @param data buffer containing the text + @param len number of characters in the text + */ + virtual void text(const sal_uInt8 * data, size_t len) = 0; + + /** + Receives 16-bit per character text. + + @param data buffer containing the text + @param len number of characters in the text. + */ + virtual void utext(const sal_uInt8 * data, size_t len) = 0; + + /** + * Offset in EMUs for a shape. + * + * Call *before* an ooxml::CT_PosH/V_posOffset sprm is sent. + */ + virtual void positionOffset(const OUString& rText, bool bVertical) = 0; + /// Returns the last set offsets of a shape in HMM. + virtual css::awt::Point getPositionOffset() = 0; + /** + * Horizontal and vertical alignment for a shape. + * + * Call *before* an ooxml:CT_PosH/V_align sprm is sent. + */ + virtual void align(const OUString& rText, bool bVertical) = 0; + virtual void positivePercentage(const OUString& rText) = 0; + + /** + Receives properties of the current run of text. + + @param ref reference to the properties + */ + virtual void props(writerfilter::Reference::Pointer_t ref) = 0; + + /** + Receives table. + + @param name name of the table + @param ref reference to the table + */ + virtual void table(Id name, + writerfilter::Reference
::Pointer_t ref) = 0; + + /** + Receives a substream. + + @param name name of the substream + @param ref reference to the substream + */ + virtual void substream(Id name, + writerfilter::Reference::Pointer_t ref) = 0; + + /** + Debugging: Receives information about current point in stream. + + @param info the information + */ + virtual void info(const std::string & info) = 0; + + /// Receives start mark for glossary document entry. + virtual void startGlossaryEntry() = 0; + + /// Receives end mark for glossary document entry. + virtual void endGlossaryEntry() = 0; + +protected: + ~Stream() override {} +}; + +/** + A value. + + The methods of this class may throw exceptions if a certain aspect + makes no sense for a certain value, e.g. the integer value of a + string. + */ +class Value : public virtual SvRefBase +{ +public: + /** + Pointer to a value. + */ + typedef tools::SvRef Pointer_t; + + /** + Returns integer representation of the value. + */ + virtual int getInt() const = 0; + + /** + Returns string representation of the value. + */ + virtual OUString getString() const = 0; + + /** + Returns representation of the value as uno::Any. + */ + virtual css::uno::Any getAny() const = 0; + + /** + Returns properties of this value. + */ + virtual writerfilter::Reference::Pointer_t getProperties() = 0; + + /** + Returns binary object of this value. + */ + virtual writerfilter::Reference::Pointer_t getBinary() = 0; + + /** + Returns string representation of this value. + */ +#ifdef DBG_UTIL + virtual std::string toString() const = 0; +#endif +}; + +/** + An SPRM: Section, Paragraph and Run Modifier + + */ +class Sprm : public virtual SvRefBase +{ +public: + typedef tools::SvRef Pointer_t; + + /** + Returns id of the SPRM. + */ + virtual sal_uInt32 getId() const = 0; + + /** + Returns value of the SPRM. + */ + virtual Value::Pointer_t getValue() = 0; + + /** + Returns reference to properties contained in the SPRM. + + */ + virtual writerfilter::Reference::Pointer_t getProps() = 0; + + /** + Returns name of sprm. + */ +#ifdef DBG_UTIL + virtual std::string getName() const = 0; +#endif + + /** + Returns string representation of sprm. + */ +#ifdef DBG_UTIL + virtual std::string toString() const = 0; +#endif + +protected: + ~Sprm() override {} +}; + +typedef sal_Int32 Token_t; + +} + +#endif // INCLUDED_WRITERFILTER_INC_DMAPPER_RESOURCEMODEL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx new file mode 100644 index 000000000..82dd78c77 --- /dev/null +++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx @@ -0,0 +1,258 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_INC_OOXML_OOXMLDOCUMENT_HXX +#define INCLUDED_WRITERFILTER_INC_OOXML_OOXMLDOCUMENT_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + @file OOXMLDocument.hxx + +

Import of OOXML WordprocessingML Documents

+ + The following picture shows the classes involved in importing OOXML + WordprocessingML documents. + + @image html ooxmlimportchain.png + + The DOCX consists of parts. Each part is an XML document. The + OOXMLDocument opens the DOCX and creates a SAX parser for the part + containing the main document content. The OOXMLDocument creates a + SAX handler, too. This handler is set as the handler for the events + created by the parser. Finally the OOXMLDocument initiates the + parsing process. + + The SAX handler hosts a stack of contexts. Each context is an + instance of a class derived from OOXMLContext. There is a context + class for each in the model.xml. + + For a detailed information about how the contexts are handled see + the documentation for OOXMLContext. + + The contexts know how to convert an element in OOXML to the + intermediate format that the domain mapper understands. They + enumerate the according entity in OOXML by sending the according + events to the domain mapper. + + The domain mapper knows how to convert the intermediate format to + API calls. It takes the events sent by the contexts and uses the + core API to insert the according elements to the core. + */ + +namespace writerfilter { +namespace ooxml +{ + +class OOXMLStream : public virtual SvRefBase +{ +public: + enum StreamType_t { UNKNOWN, DOCUMENT, STYLES, WEBSETTINGS, FONTTABLE, NUMBERING, + FOOTNOTES, ENDNOTES, COMMENTS, THEME, CUSTOMXML, CUSTOMXMLPROPS, GLOSSARY, CHARTS, EMBEDDINGS, SETTINGS, VBAPROJECT, FOOTER, HEADER, VBADATA }; + typedef tools::SvRef Pointer_t; + + /** + Returns fast parser for this stream. + */ + virtual css::uno::Reference getFastParser() = 0; + + virtual css::uno::Reference getDocumentStream() = 0; + + /** + Returns component context for this stream. + */ + virtual css::uno::Reference getContext() = 0; + + /** + Returns target URL from relationships for a given id. + + @param rId the id to look for + + @return the URL found or an empty string + */ + virtual OUString getTargetForId(const OUString & rId) = 0; + + virtual const OUString & getTarget() const = 0; + + virtual css::uno::Reference + getFastTokenHandler() = 0; + +}; + +class OOXMLDocument : public writerfilter::Reference +{ +public: + /** + Pointer to this stream. + */ + typedef tools::SvRef Pointer_t; + + /** + Resolves this document to a stream handler. + + @param rStream stream handler to resolve this document to + */ + virtual void resolve(Stream & rStream) override = 0; + + /** + Resolves a footnote to a stream handler. + + A footnote is resolved if either the note type or + note id matches. + + @param rStream stream handler to resolve to + @param rNoteType type of footnote to resolve + @param rNoteId id of the footnote to resolve + */ + virtual void resolveFootnote(Stream & rStream, + Id aNoteType, + const sal_Int32 nNoteId) = 0; + /** + Resolves an endnote to a stream handler. + + An endnote is resolved if either the note type or + note id matches. + + @param rStream stream handler to resolve to + @param rNoteType type of footnote to resolve + @param rNoteId id of the endnote to resolve + */ + virtual void resolveEndnote(Stream & rStream, + Id aNoteType, + const sal_Int32 NoteId) = 0; + + /** + Resolves a comment to a stream handler. + + @param rStream stream handler to resolve to + @param rComment id of the comment to resolve + */ + virtual void resolveComment(Stream & rStream, + const sal_Int32 nCommentId) = 0; + + /** + Resolves a picture to a stream handler. + + @param rStream stream handler to resolve to + @param rPictureId id of the picture to resolve + */ + virtual void resolvePicture(Stream & rStream, + const OUString & rPictureId) = 0; + + /** + Resolves a header to a stream handler. + + @param rStream stream handler to resolve to + @param type type of header to resolve: + NS_ooxml::LN_Value_ST_HrdFtr_even header on even page + NS_ooxml::LN_Value_ST_HrdFtr_default header on right page + NS_ooxml::LN_Value_ST_HrdFtr_first header on first page + + @param rId id of the header + */ + virtual void resolveHeader(Stream & rStream, + const sal_Int32 type, + const OUString & rId) = 0; + + /** + Resolves a footer to a stream handler. + + @param rStream stream handler to resolve to + @param type type of footer to resolve: + NS_ooxml::LN_Value_ST_HrdFtr_even header on even page + NS_ooxml::LN_Value_ST_HrdFtr_default header on right page + NS_ooxml::LN_Value_ST_HrdFtr_first header on first page + + @param rId id of the header + */ + virtual void resolveFooter(Stream & rStream, + const sal_Int32 type, + const OUString & rId) = 0; + + + /** + Returns target URL from relationships for a given id. + + @param rId the id to look for + + @return the URL found or an empty string + */ + virtual OUString getTargetForId(const OUString & rId) = 0; + + virtual void setModel(css::uno::Reference xModel) = 0; + virtual css::uno::Reference getModel() = 0; + virtual void setDrawPage(css::uno::Reference xDrawPage) = 0; + virtual css::uno::Reference getDrawPage() = 0; + virtual css::uno::Reference getInputStreamForId(const OUString & rId) = 0; + virtual void setXNoteId(const sal_Int32 nId) = 0; + virtual sal_Int32 getXNoteId() const = 0; + virtual const OUString & getTarget() const = 0; + virtual css::uno::Reference getShapeContext( ) = 0; + virtual void setShapeContext( css::uno::Reference xContext ) = 0; + /// Push context of drawingML shapes, so nested shapes are handled separately. + virtual void pushShapeContext() = 0; + /// Pop context of a previously pushed drawingML shape. + virtual void popShapeContext() = 0; + virtual css::uno::Reference getThemeDom( ) = 0; + virtual css::uno::Reference getGlossaryDocDom( ) = 0; + virtual css::uno::Sequence > getGlossaryDomList() = 0; + virtual css::uno::Sequence > getCustomXmlDomList( ) = 0; + virtual css::uno::Sequence > getCustomXmlDomPropsList( ) = 0; + virtual css::uno::Sequence getEmbeddingsList() = 0; +}; + + +class OOXMLDocumentFactory +{ +public: + static OOXMLStream::Pointer_t + createStream(const css::uno::Reference& rContext, + const css::uno::Reference& rStream, + bool bRepairStorage); + + static OOXMLStream::Pointer_t + createStream(const OOXMLStream::Pointer_t& pStream, + OOXMLStream::StreamType_t nStreamType); + + static OOXMLStream::Pointer_t + createStream(const OOXMLStream::Pointer_t& pStream, const OUString & rId); + + static OOXMLDocument * + createDocument(const OOXMLStream::Pointer_t& pStream, + const css::uno::Reference& xStatusIndicator, + bool bSkipImage, const css::uno::Sequence& rDescriptor); + +}; + +std::string fastTokenToId(sal_uInt32 nToken); + +}} +#endif // INCLUDED_WRITERFILTER_INC_OOXML_OOXMLDOCUMENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/ooxml/QNameToString.hxx b/writerfilter/inc/ooxml/QNameToString.hxx new file mode 100644 index 000000000..9cdf13de1 --- /dev/null +++ b/writerfilter/inc/ooxml/QNameToString.hxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_INC_OOXML_QNAMETOSTRING_HXX +#define INCLUDED_WRITERFILTER_INC_OOXML_QNAMETOSTRING_HXX + +#include +#include + +namespace writerfilter +{ + +#ifdef DBG_UTIL + std::string QNameToString(Id); +#endif + +} + +#endif // INCLUDED_WRITERFILTER_INC_OOXML_QNAMETOSTRING_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/pch/precompiled_writerfilter.cxx b/writerfilter/inc/pch/precompiled_writerfilter.cxx new file mode 100644 index 000000000..135ea5e8c --- /dev/null +++ b/writerfilter/inc/pch/precompiled_writerfilter.cxx @@ -0,0 +1,12 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "precompiled_writerfilter.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/pch/precompiled_writerfilter.hxx b/writerfilter/inc/pch/precompiled_writerfilter.hxx new file mode 100644 index 000000000..165ea77c7 --- /dev/null +++ b/writerfilter/inc/pch/precompiled_writerfilter.hxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + This file has been autogenerated by update_pch.sh. It is possible to edit it + manually (such as when an include file has been moved/renamed/removed). All such + manual changes will be rewritten by the next run of update_pch.sh (which presumably + also fixes all possible problems, so it's usually better to use it). + + Generated on 2020-04-25 20:56:04 using: + ./bin/update_pch writerfilter writerfilter --cutoff=5 --exclude:system --exclude:module --exclude:local + + If after updating build fails, use the following command to locate conflicting headers: + ./bin/update_pch_bisect ./writerfilter/inc/pch/precompiled_writerfilter.hxx "make writerfilter.build" --find-conflicts +*/ + +#if PCH_LEVEL >= 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // PCH_LEVEL >= 1 +#if PCH_LEVEL >= 2 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // PCH_LEVEL >= 2 +#if PCH_LEVEL >= 3 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // PCH_LEVEL >= 3 +#if PCH_LEVEL >= 4 +#endif // PCH_LEVEL >= 4 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/inc/rtftok/RTFDocument.hxx b/writerfilter/inc/rtftok/RTFDocument.hxx new file mode 100644 index 000000000..55b1fbee3 --- /dev/null +++ b/writerfilter/inc/rtftok/RTFDocument.hxx @@ -0,0 +1,52 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_INC_RTFTOK_RTFDOCUMENT_HXX +#define INCLUDED_WRITERFILTER_INC_RTFTOK_RTFDOCUMENT_HXX + +#include +#include +#include +#include +#include +#include +#include + +namespace writerfilter +{ +namespace rtftok +{ +/// The RTFDocument opens and resolves the RTF document. +class RTFDocument : public writerfilter::Reference +{ +public: + /// Pointer to this stream. + using Pointer_t = tools::SvRef; + + /// Resolves this document to a stream handler. + void resolve(Stream& rHandler) override = 0; +}; + +/// Interface to create an RTFDocument instance. +class RTFDocumentFactory +{ +public: + static RTFDocument::Pointer_t + createDocument(css::uno::Reference const& xContext, + css::uno::Reference const& xInputStream, + css::uno::Reference const& xDstDoc, + css::uno::Reference const& xFrame, + css::uno::Reference const& xStatusIndicator, + const utl::MediaDescriptor& rMediaDescriptor); +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_INC_RTFTOK_RTFDOCUMENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/CellColorHandler.cxx b/writerfilter/qa/cppunittests/dmapper/CellColorHandler.cxx new file mode 100644 index 000000000..646d0968b --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/CellColorHandler.cxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/CellColorHandler.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, test129205) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf129205.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + drawing::FillStyle eFillStyle = drawing::FillStyle::FillStyle_NONE; + xPara->getPropertyValue("FillStyle") >>= eFillStyle; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: drawing::FillStyle_NONE + // - Actual : FillStyle_SOLID + // i.e. the paragraph had a solid fill, making the header image invisible. + CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, eFillStyle); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx new file mode 100644 index 000000000..d6e6830b8 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper.cxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/DomainMapper.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testLargeParaTopMargin) +{ + // Given a document with a paragraph with a large "before" spacing. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "large-para-top-margin.docx"; + getComponent() = loadFromDesktop(aURL); + + // When checking the first paragraph. + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + + // Then assert its top margin. + sal_Int32 nParaTopMargin{}; + xPara->getPropertyValue("ParaTopMargin") >>= nParaTopMargin; + // in the document. + sal_Int32 nExpected = convertTwipToMm100(37050); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 65352 + // - Actual : 0 + // i.e. the paragraph margin was lost, which shifted the paragraph to the right (no top margin + // -> wrap around a TextBox), which shifted the triangle shape out of the page frame. + CPPUNIT_ASSERT_EQUAL(nExpected, nParaTopMargin); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx new file mode 100644 index 000000000..a1a7595ce --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/DomainMapperTableHandler.cxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/DomainMapperTableHandler.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, test1cellInsidevRightborder) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "1cell-insidev-rightborder.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xTables(xTextDocument->getTextTables(), uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xCell(xTable->getCellByName("A1"), uno::UNO_QUERY); + table::BorderLine2 aBorder; + xCell->getPropertyValue("RightBorder") >>= aBorder; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 18 + // i.e. the request to have no table-level right border was lost on import. + CPPUNIT_ASSERT_EQUAL(static_cast(0), aBorder.LineWidth); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx new file mode 100644 index 000000000..ade216411 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/DomainMapper_Impl.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testPageBreakFooterTable) +{ + // Load a document which refers to a footer which ends with a table, and there is a page break + // in the body text right after the footer reference. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "page-break-footer-table.docx"; + getComponent() = loadFromDesktop(aURL); + + // Check the last paragraph. + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara; + while (xParaEnum->hasMoreElements()) + { + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + } + style::BreakType eType = style::BreakType_NONE; + xPara->getPropertyValue("BreakType") >>= eType; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 + // - Actual : 0 + // i.e. there was no page break before the last paragraph. + CPPUNIT_ASSERT_EQUAL(style::BreakType_PAGE_BEFORE, eType); +} + +CPPUNIT_TEST_FIXTURE(Test, testNumberingRestartStyleParent) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "num-restart-style-parent.docx"; + getComponent() = loadFromDesktop(aURL); + + // The paragraphs are A 1 2 B 1 2. + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara; + OUStringLiteral aProp("ListLabelString"); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("A."), xPara->getPropertyValue(aProp).get()); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("1."), xPara->getPropertyValue(aProp).get()); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2."), xPara->getPropertyValue(aProp).get()); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("B."), xPara->getPropertyValue(aProp).get()); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1. + // - Actual : 3. + // i.e. the numbering was not restarted after B. + CPPUNIT_ASSERT_EQUAL(OUString("1."), xPara->getPropertyValue(aProp).get()); + xPara.set(xParaEnum->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("2."), xPara->getPropertyValue(aProp).get()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx new file mode 100644 index 000000000..28a0cc178 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/GraphicImport.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testGroupShapeRotation) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "group-shape-rotation.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + sal_Int32 nVertPosition = 0; + xShape->getPropertyValue("VertOrientPosition") >>= nVertPosition; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1221 + // - Actual : -2048 + // i.e. the group shape had a so low vertical position that the line shape did not point into + // it. + CPPUNIT_ASSERT_EQUAL(static_cast(1221), nVertPosition); +} + +CPPUNIT_TEST_FIXTURE(Test, testDrawShapeInlineEffect) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "draw-shape-inline-effect.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + sal_Int32 nBottomMargin = 0; + xShape->getPropertyValue("BottomMargin") >>= nBottomMargin; + // 273 in mm100 is 98425 EMUs from the file. + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 273 + // - Actual : 0 + // i.e. the layout result had less pages than expected (compared to Word). + CPPUNIT_ASSERT_EQUAL(static_cast(273), nBottomMargin); +} + +CPPUNIT_TEST_FIXTURE(Test, testInlineAnchoredZOrder) +{ + // Load a document which has two shapes: an inline one and an anchored one. The inline has no + // explicit ZOrder, the anchored one has, and it's set to a value so it's visible. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "inline-anchored-zorder.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xOval(xDrawPage->getByIndex(1), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Oval 2 + // - Actual : + // i.e. the rectangle (with no name) was on top of the oval one, not the other way around. + CPPUNIT_ASSERT_EQUAL(OUString("Oval 2"), xOval->getName()); +} + +CPPUNIT_TEST_FIXTURE(Test, testInlineInShapeAnchoredZOrder) +{ + // This document has a textbox shape and then an inline shape inside that. + // The ZOrder of the inline shape is larger than the hosting textbox, so the image is visible. + OUString aURL + = m_directories.getURLFromSrc(DATA_DIRECTORY) + "inline-inshape-anchored-zorder.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xOval(xDrawPage->getByIndex(1), uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Picture 1 + // - Actual : Text Box 2 + // i.e. the image was behind the textbox that was hosting it. + CPPUNIT_ASSERT_EQUAL(OUString("Picture 1"), xOval->getName()); +} + +CPPUNIT_TEST_FIXTURE(Test, testRelfromhInsidemargin) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "relfromh-insidemargin.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + sal_Int16 nRelation = 0; + xShape->getPropertyValue("HoriOrientRelation") >>= nRelation; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 7 (PAGE_FRAME) + // - Actual : 0 (FRAME) + // i.e. the horizontal position was relative to the paragraph area, not to the entire page. + CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, nRelation); + bool bPageToggle = false; + xShape->getPropertyValue("PageToggle") >>= bPageToggle; + CPPUNIT_ASSERT(bPageToggle); +} + +CPPUNIT_TEST_FIXTURE(Test, testWrapPolyCrop) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "wrap-poly-crop.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xDrawPageSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + drawing::PointSequenceSequence aContour; + xShape->getPropertyValue("ContourPolyPolygon") >>= aContour; + auto aPolyPolygon = basegfx::utils::UnoPointSequenceSequenceToB2DPolyPolygon(aContour); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), aPolyPolygon.count()); + auto aPolygon = aPolyPolygon.getB2DPolygon(0); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(4), aPolygon.count()); + + // Ideally this would be 2352, because the graphic size in mm100, using the graphic's DPI is + // 10582, the lower 33% of the graphic is cropped, and the wrap polygon covers the middle third + // of the area vertically. Which means 10582*2/3 = 7054.67 is the cropped height, and the top of + // the middle third is 2351.55. + // Then there is a 15 twips shift from the origo, so it's 2351.55 + 26.46 = 2378.01 in mm100. + // + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2368 + // - Actual : 3542 + // i.e. the wrap polygon covered a larger-than-correct area, which end the end means 3 lines + // were wrapping around the image, not only 2 as Word does it. + CPPUNIT_ASSERT_EQUAL(2368., aPolygon.getB2DPoint(0).getY()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx new file mode 100644 index 000000000..71b3ab80e --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/PropertyMap.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testFloatingTableHeader) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "floating-table-header.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xModel(getComponent(), uno::UNO_QUERY); + uno::Reference xTextViewCursorSupplier( + xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference xCursor(xTextViewCursorSupplier->getViewCursor(), + uno::UNO_QUERY); + xCursor->jumpToLastPage(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 3 + // i.e. a document which is 1 page in Word was imported as a 3 page one. + CPPUNIT_ASSERT_EQUAL(static_cast(1), xCursor->getPage()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx b/writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx new file mode 100644 index 000000000..d48a35e25 --- /dev/null +++ b/writerfilter/qa/cppunittests/dmapper/TextEffectsHandler.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/dmapper/TextEffectsHandler.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/dmapper/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testSemiTransparentText) +{ + // Load a document with a single paragraph: second text portion has semi-transparent text. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "semi-transparent-text.docx"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xParaEnumAccess(xTextDocument->getText(), + uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xPortionEnum = xPara->createEnumeration(); + xPortionEnum->nextElement(); + uno::Reference xPortion(xPortionEnum->nextElement(), uno::UNO_QUERY); + sal_Int16 nCharTransparence = 0; + xPortion->getPropertyValue("CharTransparence") >>= nCharTransparence; + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 74 + // - Actual : 0 + // i.e. text was imported as regular text with solid color only. + CPPUNIT_ASSERT_EQUAL(static_cast(74), nCharTransparence); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/dmapper/data/1cell-insidev-rightborder.docx b/writerfilter/qa/cppunittests/dmapper/data/1cell-insidev-rightborder.docx new file mode 100644 index 000000000..d0bc40e23 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/1cell-insidev-rightborder.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/draw-shape-inline-effect.docx b/writerfilter/qa/cppunittests/dmapper/data/draw-shape-inline-effect.docx new file mode 100644 index 000000000..3eb5b0e2f Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/draw-shape-inline-effect.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/floating-table-header.docx b/writerfilter/qa/cppunittests/dmapper/data/floating-table-header.docx new file mode 100644 index 000000000..3840b2550 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/floating-table-header.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/group-shape-rotation.docx b/writerfilter/qa/cppunittests/dmapper/data/group-shape-rotation.docx new file mode 100644 index 000000000..c9fee726b Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/group-shape-rotation.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx b/writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx new file mode 100644 index 000000000..93932c470 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/inline-anchored-zorder.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/inline-inshape-anchored-zorder.docx b/writerfilter/qa/cppunittests/dmapper/data/inline-inshape-anchored-zorder.docx new file mode 100644 index 000000000..3792285f4 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/inline-inshape-anchored-zorder.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/large-para-top-margin.docx b/writerfilter/qa/cppunittests/dmapper/data/large-para-top-margin.docx new file mode 100644 index 000000000..34f24a3e2 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/large-para-top-margin.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/num-restart-style-parent.docx b/writerfilter/qa/cppunittests/dmapper/data/num-restart-style-parent.docx new file mode 100644 index 000000000..f908d94b5 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/num-restart-style-parent.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/page-break-footer-table.docx b/writerfilter/qa/cppunittests/dmapper/data/page-break-footer-table.docx new file mode 100644 index 000000000..376a1fb1e Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/page-break-footer-table.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/relfromh-insidemargin.docx b/writerfilter/qa/cppunittests/dmapper/data/relfromh-insidemargin.docx new file mode 100644 index 000000000..1f7a281e8 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/relfromh-insidemargin.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx b/writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx new file mode 100644 index 000000000..6c0f8a79c Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/semi-transparent-text.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/tdf129205.docx b/writerfilter/qa/cppunittests/dmapper/data/tdf129205.docx new file mode 100644 index 000000000..4289254d0 Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/tdf129205.docx differ diff --git a/writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx b/writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx new file mode 100644 index 000000000..1835a130d Binary files /dev/null and b/writerfilter/qa/cppunittests/dmapper/data/wrap-poly-crop.docx differ diff --git a/writerfilter/qa/cppunittests/filters-test/README b/writerfilter/qa/cppunittests/filters-test/README new file mode 100644 index 000000000..2cc9fb3cb --- /dev/null +++ b/writerfilter/qa/cppunittests/filters-test/README @@ -0,0 +1,7 @@ +Files with the string 'CVE' in their name are encrypted to avoid +problems with virus checkers on source code download.; use: + +mdecrypt --bare -a arcfour -o hex -k 435645 -s 3 foo.doc # to unencrypt +mcrypt --bare -a arcfour -o hex -k 435645 -s 3 foo.doc # to create new tests + +to get access to the plain files for manual testing. diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2005-2971-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2005-2971-1.rtf new file mode 100644 index 000000000..5cd42052c Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2005-2971-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2010-3451-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2010-3451-1.rtf new file mode 100644 index 000000000..0c639810d Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/CVE-2010-3451-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/EDB-18749-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/EDB-18749-1.rtf new file mode 100644 index 000000000..18795f5be Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/EDB-18749-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-1.rtf new file mode 100644 index 000000000..63465b073 Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-2.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-2.rtf new file mode 100644 index 000000000..f0152b0fa Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/destinationtest-2.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/nopropertyset-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/nopropertyset-1.rtf new file mode 100644 index 000000000..59c3630a7 Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/nopropertyset-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/popstate-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/popstate-1.rtf new file mode 100644 index 000000000..041891713 Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/popstate-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/popstate-2.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/popstate-2.rtf new file mode 100644 index 000000000..273bb135c --- /dev/null +++ b/writerfilter/qa/cppunittests/filters-test/data/fail/popstate-2.rtf @@ -0,0 +1 @@ +\\rttt\noTidqtpúúúúúúëúúúúúúúúúúúúúúúúdôp{\"pb18}\€p{\"ptxtbr } diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/propheight-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/propheight-1.rtf new file mode 100644 index 000000000..130ff3f23 Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/propheight-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/sf_edeb1eb341ad4c8608af9396952724a0-128299-minimized.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/sf_edeb1eb341ad4c8608af9396952724a0-128299-minimized.rtf new file mode 100644 index 000000000..45597c085 --- /dev/null +++ b/writerfilter/qa/cppunittests/filters-test/data/fail/sf_edeb1eb341ad4c8608af9396952724a0-128299-minimized.rtf @@ -0,0 +1,57 @@ +{\rtf1\ansi\ansicpg1252\deff0 +{\fonttbl +{\f0\fnil\fcharset0\fprq0\fttruetype Times New Roman;} +{\f1\fnil\fcharset0\fprq0\fttruetype Nimbus Sans L;} +{\f2\fnil\fcharset0\fprq0\fttruetype Dingbats;} +{\f3\fnil\fcharset0\fprq0\fttruetype Symbol;} +{\f4\fnil\fcharset0\fprq0\fttruetype Courier New;}} +{\colortbl +\red0\green0\blue0; +\red255\green255\blue255;} +{\stylesheet +{\s1\fi-431\li720\sbasedon28\snext28 Contents 1;} +{\s2\fi-431\li1440\sbasedon28\snext28 Contents 2;} +{\s3\fi-431\li2160\sbasedon28\snext28 Contents 3;} +{\s8\fi-431\li720\sbasedon28 Lower Roman List;} +{\s5\tx431\sbasedon24\snext28 Numbered Heading 1;} +{\s6\tx431\sbasedon25\snext28 Numbered Heading 2;} +{\s7\fi-431\li720 Square List;} +{\*\cs11\sbasedon28 Endnote Text;} +{\s4\fi-431\li2880\sbasedon28\snext28 Contents 4;} +{\s9\fi-431\li720 Diamond List;} +{\s10\fi-431\li720 Numbered List;} +{\*\cs12\fs20\super Endnote Reference;} +{\s13\fi-431\li720 Triangle List;} +{\s14\tx431\sbasedon26\snext28 Numbered Heading 3;} +{\s15\fi-431\li720 Dashed List;} +{\s16\fi-431\li720\sbasedon10 Upper Roman List;} +{\s17\sb440\sa60\f1\fs24\b\sbasedon28\snext28 Heading 4;} +{\s18\fi-431\li720 Heart List;} +{\s34\fi-431\li720 Box List;} +{\s20\fi-431\li720\sbasedon10 Upper Case List;} +{\s21\fi-431\li720 Bullet List;} +{\s22\fi-431\li720 Hand List;} +{\*\cs23\fs20\sbasedon28 Footnote Text;} +{\s24\sb440\sa60\f1\fs34\b\sbasedon28\snext28 Heading 1;} +{\s25\sb440\sa60\f1\fs28\b\sbasedon28\snext28 Heading 2;} +{\s19\qc\sb240\sa120\f1\fs32\b\sbasedon28\snext28 Contents Header;} +{\s27\fi-431\li720 Tick List;} +{\s26\sb440\sa60\f1\fs24\b\sbasedon28\snext28 Heading 3;} +{\s29\fi-431\li720\sbasedon10 Lower Case List;} +{\s30\li1440\ri1440\sa120\sbasedon28 Block Text;} +{\s36\f4\sbasedon28 Plain Text;} +{\s32\tx1584\sbasedon5\snext28 Section Heading;} +{\s33\fi-431\li720 Implies List;} +{\s28\f0\fs24\lang1033 Normal;} +{\s35\fi-431\li720 Star List;} +{\*\cs31\fs20\super Footnote Reference;} +{\s37\tx1584\sbasedon5\snext28 Chapter Heading;}} +{\*\listtable +{\list\listtemplateid1002\listsimple{\listlevel\levelnfc0\levelstartat1\levelspAce0\levelfollow0\fi-431\li720{\leveltext\'02\'00.{}{\levelnumbers\'01;}}\listid1000}} +{\*\listoverridetable +{\listoverride\listoverridecount0\listid1000\levelnfc0\levelstartat1\levelspace0\levelfollow0\fi-431\li720{\leveltext\'02\'00.;}{\levelnumbers\'01;}\ls1}} + +\kerning0\cf0\ftnbj\fet2\ftnstart1\ftnnar\aftnnar\ftnstart1\aftnstart1\aenddoc\facingp\titlepg\revprop3{\info}\deftab720\viewkind1\paperw12240\paperh15840\margl1440\margr1440\widowctl +\sectd\sbknone\colsx360\pgncont\ltrsect +{\listtext\pard\fi-431\li720 1. }\pard\plain{\ltrpar\ql\fi-431\li720\s28{\*\abilist\abilistid1000\abilistparentid0\abilistlevel1\abistartat1{\abifieldfont NULL}{\abilistdecimal .}{\abilistdelim %L.}{\abiliststyle Numbered List}}{\*\pn\pnql\pnstart1\pnlvlbody\pndec{\pntxtb AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}{\pntxta .}}\fn-431\li720\ls1\ilvl0\itap0{\s28\f0\fs24\lang1033{\*\listtag0}\abinodiroverride\ltrch test}{\s28\f0\fs24\lang1033{\*\listtag1001}\par} +}\pard\plain\ltrpar\ql\s28\itap0{\s28\f0\fs24\lang1033{\*\listtag0}\par}} diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-5.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-5.rtf new file mode 100644 index 000000000..a03be130d Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-5.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-6.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-6.rtf new file mode 100644 index 000000000..67a0ea175 Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-6.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-7.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-7.rtf new file mode 100644 index 000000000..df41b1f88 Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/tablemanager-7.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-1.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-1.rtf new file mode 100644 index 000000000..7cdb94ab2 Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-1.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-2.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-2.rtf new file mode 100644 index 000000000..c0bd2691c Binary files /dev/null and b/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-2.rtf differ diff --git a/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-3.rtf b/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-3.rtf new file mode 100644 index 000000000..112162397 --- /dev/null +++ b/writerfilter/qa/cppunittests/filters-test/data/fail/topcontext-3.rtf @@ -0,0 +1,28 @@ +{\ul\001ll\fJ + {Ystylesheet;{;}} +{bbbbbbbbbbbbbbbbb{O\00\80\00\tc\DD\00\FFDD\BED@DDD\F7bTr\00\00*i\\FF\FB\FB\FB\FB\FB\FB\FB\FB\FB\FB\FB\FB\FB\FB\FB\FF\ +\\\BD\EB||){Tb\FD\00\00\00p\FFA\00\00\00r \00\00\00\BB +\88\83AA4A\FC\E5C\E5\F5\E5\E5\FF\80\E5\E5\E5\D3O\006\FA\00\00\EB\F8\E5 \00\00\\98\00xtesÕ·\D3^t000c\00\00\00\00ppu\00\00\00\00\00\E5\D1\E5\80\00\00\00\FA\F8\E5'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb{O\00\80\00\tc\A5\\iL\\00\E5\F2\E5\E5\E5\80\E8\E5\E5\E5\FF\FFbTUEQU\00\00\00\00\80\00\00\AD\E5\E5\E5\E5C\00\00\00\E5\E5\E5\E5\E5\E5I \00\{P\FFig\\ +{O\00\80\00d +#include +#include +#include +#include + +using namespace ::com::sun::star; + +/** + * Unit test invoking writerfilter/ only. + * + * This does only minimal testing, checking if the filter crashes and returns + * the expected bool value for given inputs. More fine-grained tests can be + * found under sw/qa/extras/rtfimport/. + */ +class RtfTest : public test::FiltersTest, public test::BootstrapFixture +{ +public: + virtual void setUp() override; + + virtual bool load(const OUString&, const OUString& rURL, const OUString&, SfxFilterFlags, + SotClipboardFormatId, unsigned int) override; + +private: + uno::Reference m_xFilter; +}; + +void RtfTest::setUp() +{ + test::BootstrapFixture::setUp(); + + m_xFilter.set(m_xSFactory->createInstance("com.sun.star.comp.Writer.RtfFilter"), + uno::UNO_QUERY_THROW); +} + +bool RtfTest::load(const OUString&, const OUString& rURL, const OUString&, SfxFilterFlags, + SotClipboardFormatId, unsigned int) +{ + uno::Sequence aDescriptor = { beans::PropertyValue( + "URL", sal_Int32(0), uno::makeAny(rURL), beans::PropertyState_DIRECT_VALUE) }; + try + { + return m_xFilter->filter(aDescriptor); + } + catch (const lang::WrappedTargetRuntimeException& rWrapped) + { + io::WrongFormatException e; + if (rWrapped.TargetException >>= e) + { + return false; + } + throw; + } + catch (const std::exception&) + { + return false; + } +} + +CPPUNIT_TEST_FIXTURE(RtfTest, testFilter) +{ +#ifndef DISABLE_CVE_TESTS + testDir(OUString(), + m_directories.getURLFromSrc("/writerfilter/qa/cppunittests/filters-test/data/")); +#endif +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/misc/misc.cxx b/writerfilter/qa/cppunittests/misc/misc.cxx new file mode 100644 index 000000000..983e6fc87 --- /dev/null +++ b/writerfilter/qa/cppunittests/misc/misc.cxx @@ -0,0 +1,178 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +namespace { + +class WriterfilterMiscTest + : public ::CppUnit::TestFixture +{ +public: + void testTwipConversions(); + void testFieldParameters(); + + CPPUNIT_TEST_SUITE(WriterfilterMiscTest); + CPPUNIT_TEST(testTwipConversions); + CPPUNIT_TEST(testFieldParameters); + CPPUNIT_TEST_SUITE_END(); +}; + +void WriterfilterMiscTest::testTwipConversions() +{ + using writerfilter::dmapper::ConversionHelper::convertTwipToMM100; + using writerfilter::dmapper::ConversionHelper::convertTwipToMM100Unsigned; + + CPPUNIT_ASSERT_EQUAL(sal_Int32(-2), convertTwipToMM100(-1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-17639), convertTwipToMM100(-10000)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(-70556), convertTwipToMM100(-40000)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), convertTwipToMM100(1)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(17639), convertTwipToMM100(10000)); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), convertTwipToMM100(40000)); + + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-1)); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-10000)); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(-40000)); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), convertTwipToMM100Unsigned(1)); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(17639), convertTwipToMM100Unsigned(10000)); + CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), convertTwipToMM100Unsigned(40000)); +} + +void WriterfilterMiscTest::testFieldParameters() +{ + using writerfilter::dmapper::splitFieldCommand; + std::tuple, std::vector > result; + + result = splitFieldCommand("PAGEREF last_page"); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand(" PAGEREF last_page "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + + result = splitFieldCommand("pageref last_page"); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("pageref \"last_page\""); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("\"PAGEREF\" \"last_page\" \"\" "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("\"PAGEREF\"\"last_page\" "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("PAGEREF\"last_page\" "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("\"PAGEREF\"last_page \"\""); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("\"PAGEREF\"last_page \"\""); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT_EQUAL(OUString(), std::get<1>(result)[1]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("pageref \"last\\\\pa\\\"ge\""); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last\\pa\"ge"), std::get<1>(result)[0]); + CPPUNIT_ASSERT(std::get<2>(result).empty()); + + result = splitFieldCommand("PAGEREF\"last_page\"\\*"); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<2>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("\\*"), std::get<2>(result)[0]); + + result = splitFieldCommand("PAGEREF last_page \\b foobar "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(size_t(1), std::get<1>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("last_page"), std::get<1>(result)[0]); + CPPUNIT_ASSERT_EQUAL(size_t(2), std::get<2>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("\\B"), std::get<2>(result)[0]); + CPPUNIT_ASSERT_EQUAL(OUString("foobar"), std::get<2>(result)[1]); + + result = splitFieldCommand("PAGEREF\\bfoobar\\A\"\""); + CPPUNIT_ASSERT_EQUAL(OUString("PAGEREF"), std::get<0>(result)); + CPPUNIT_ASSERT(std::get<1>(result).empty()); + CPPUNIT_ASSERT_EQUAL(size_t(4), std::get<2>(result).size()); + CPPUNIT_ASSERT_EQUAL(OUString("\\B"), std::get<2>(result)[0]); + CPPUNIT_ASSERT_EQUAL(OUString("foobar"), std::get<2>(result)[1]); + CPPUNIT_ASSERT_EQUAL(OUString("\\A"), std::get<2>(result)[2]); + CPPUNIT_ASSERT_EQUAL(OUString(), std::get<2>(result)[3]); + + for (auto prefix : {"#", "$", "%", "&", "'", "(", ")", "*", "+", ",", + "-", ".", "/", ":", ";", "<", ">", "?", "@", "[", + "]", "^", "_", "`", "{", "|", "}", "~"}) + { + OUString test(OUString::createFromAscii(prefix) + "PAGE"); + result = splitFieldCommand(test + " "); + CPPUNIT_ASSERT_EQUAL(test, std::get<0>(result)); + } + result = splitFieldCommand("\\PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<0>(result)); + result = splitFieldCommand("\\ PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("\\ "), std::get<0>(result)); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<1>(result)[0]); + result = splitFieldCommand("\\\\PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("\\PAGE"), std::get<0>(result)); + result = splitFieldCommand("\"PAGE\" "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE"), std::get<0>(result)); + result = splitFieldCommand("\"PAGE "); + CPPUNIT_ASSERT_EQUAL(OUString("PAGE "), std::get<0>(result)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(WriterfilterMiscTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/rtftok/data/left-margin-dedup.rtf b/writerfilter/qa/cppunittests/rtftok/data/left-margin-dedup.rtf new file mode 100644 index 000000000..8536694a2 --- /dev/null +++ b/writerfilter/qa/cppunittests/rtftok/data/left-margin-dedup.rtf @@ -0,0 +1,26 @@ +{\rtf1 +{\fonttbl +{\f0 Times New Roman;} +{\f3\froman\fcharset2\fprq2 Symbol;} +} +{\stylesheet +{\ql Normal;} +{\s44\ql\fi-288\li360 Table Text Bullet;} +{\s59\ql\li720 List Paragraph;} +} +{\*\listtable +{\list +{\listlevel\levelnfc23\leveljc0\leveljcn0\levelfollow0 +\levelstartat1\levelspace0\levelindent0 +{\leveltext\'01\u-3913 ?;} +{\levelnumbers;} +\f3\fbias0 \fi-360\li1305 } +{\listname ;} +\listid845246918} +} +{\*\listoverridetable +{\listoverride\listid845246918\listoverridecount0\ls27} +} +\pard\plain\s44\ql\fi-360\li720\ls27 P1\par +\pard\plain\s59\ql\fi-360\li720\ls27 P2\par +} diff --git a/writerfilter/qa/cppunittests/rtftok/data/picture-in-textframe.rtf b/writerfilter/qa/cppunittests/rtftok/data/picture-in-textframe.rtf new file mode 100644 index 000000000..ec0a07690 --- /dev/null +++ b/writerfilter/qa/cppunittests/rtftok/data/picture-in-textframe.rtf @@ -0,0 +1,29 @@ +{\rtf1 +\paperw10080\paperh12960\margl1066\margr1066\margt1642\margb1066 +\pard\plain +{\shp +{\*\shpinst\shpleft31\shptop105\shpright4108\shpbottom3887\shpfhdr0\shpwr2\shpwrk3\shpfblwtxt0 +{\sp +{\sn shapeType} +{\sv 202} +} +{\shptxt \pard\plain +before +{\*\shppict +{\pict +{\*\picprop\shplid1025 +{\sp +{\sn shapeType} +{\sv 75} +} +} +\picscalex23\picscaley24\piccropl0\piccropr0\piccropt0\piccropb0\picw30372\pich22437\picwgoal17219\pichgoal12720\pngblip +47494638396110001000d5ff00000000ffffffc0c0c0555f00ffffaafcfcfcf6f6f6eaeaeae6e6e6e4e4e4e3e3e3c2c2c2c1c1c1bcbcbcb5b5b5b3b3b3b0b0b0adadada5a5a5a2a2a2a1a1a19f9f9f9494948a8a8a8888888686867b7b7b6c6c6c5c5c5c4e4e4e4b4b4b4747474646463d3d3d3c3c3c2e2e2e2525251b1b1b18181810101009090906060603030300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021f90401000002002c0000000010001000000684408170482c0a06c8a4728924389f506833b281302a8e6b164b18103024c52111504cca67332102e0042e9a40d9319f8300a343c1200f54e47f7e2a00001e0b0a7d0d728a010d838400261a7c0d94947784252700127e9d159f6c8411140019080ea7a9a85f842122281612b1b3b25d6b1f29291d0fbbbdbc5d5e51c34e4cc64a46c94341003b +} +} +after\par +} +} +} +\par +} diff --git a/writerfilter/qa/cppunittests/rtftok/rtfsdrimport.cxx b/writerfilter/qa/cppunittests/rtftok/rtfsdrimport.cxx new file mode 100644 index 000000000..64c679f6e --- /dev/null +++ b/writerfilter/qa/cppunittests/rtftok/rtfsdrimport.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/rtftok/rtfsdrimport.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/rtftok/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testPictureInTextframe) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "picture-in-textframe.rtf"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage = xTextDocument->getDrawPage(); + uno::Reference xInnerShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); + text::TextContentAnchorType eAnchorType = text::TextContentAnchorType_AT_PARAGRAPH; + xInnerShape->getPropertyValue("AnchorType") >>= eAnchorType; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 4 + // i.e. the properties of the inner shape (including its anchor type and bitmap fill) were lost + // on import. + CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, eAnchorType); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/cppunittests/rtftok/rtfsprm.cxx b/writerfilter/qa/cppunittests/rtftok/rtfsprm.cxx new file mode 100644 index 000000000..9f5ec63e8 --- /dev/null +++ b/writerfilter/qa/cppunittests/rtftok/rtfsprm.cxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for writerfilter/source/rtftok/rtfsprm.cxx. +class Test : public test::BootstrapFixture, public unotest::MacrosTest +{ +private: + uno::Reference mxComponent; + +public: + void setUp() override; + void tearDown() override; + uno::Reference& getComponent() { return mxComponent; } +}; + +void Test::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void Test::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +char const DATA_DIRECTORY[] = "/writerfilter/qa/cppunittests/rtftok/data/"; + +CPPUNIT_TEST_FIXTURE(Test, testLeftMarginDedup) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "left-margin-dedup.rtf"; + getComponent() = loadFromDesktop(aURL); + uno::Reference xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference xText(xTextDocument->getText(), uno::UNO_QUERY); + uno::Reference xParagraphs = xText->createEnumeration(); + uno::Reference xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); + sal_Int32 nLeftMargin = 0; + xParagraph->getPropertyValue("ParaLeftMargin") >>= nLeftMargin; + CPPUNIT_ASSERT_EQUAL(static_cast(1270), nLeftMargin); + + uno::Reference xParagraphState(xParagraph, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, + xParagraphState->getPropertyState("ParaLeftMargin")); + + xParagraph.set(xParagraphs->nextElement(), uno::UNO_QUERY); + nLeftMargin = 0; + xParagraph->getPropertyValue("ParaLeftMargin") >>= nLeftMargin; + CPPUNIT_ASSERT_EQUAL(static_cast(1270), nLeftMargin); + + xParagraphState.set(xParagraph, uno::UNO_QUERY); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 (DIRECT_VALUE) + // - Actual : 1 (DEFAULT_VALUE) + // i.e. the left margin was not a direct formatting, which means left margin from the numbering + // was used instead. + CPPUNIT_ASSERT_EQUAL(beans::PropertyState_DIRECT_VALUE, + xParagraphState->getPropertyState("ParaLeftMargin")); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/qa/documents/Bookmark1.doc b/writerfilter/qa/documents/Bookmark1.doc new file mode 100644 index 000000000..71565d979 Binary files /dev/null and b/writerfilter/qa/documents/Bookmark1.doc differ diff --git a/writerfilter/qa/documents/Bookmark1.docx b/writerfilter/qa/documents/Bookmark1.docx new file mode 100644 index 000000000..a00eab97a Binary files /dev/null and b/writerfilter/qa/documents/Bookmark1.docx differ diff --git a/writerfilter/qa/documents/CellAlignment.doc b/writerfilter/qa/documents/CellAlignment.doc new file mode 100644 index 000000000..57a6745b4 Binary files /dev/null and b/writerfilter/qa/documents/CellAlignment.doc differ diff --git a/writerfilter/qa/documents/Footnote.doc b/writerfilter/qa/documents/Footnote.doc new file mode 100644 index 000000000..9098c91a9 Binary files /dev/null and b/writerfilter/qa/documents/Footnote.doc differ diff --git a/writerfilter/qa/documents/Footnote.docx b/writerfilter/qa/documents/Footnote.docx new file mode 100644 index 000000000..a20d2747a Binary files /dev/null and b/writerfilter/qa/documents/Footnote.docx differ diff --git a/writerfilter/qa/documents/HeaderFooter.doc b/writerfilter/qa/documents/HeaderFooter.doc new file mode 100644 index 000000000..9b023b485 Binary files /dev/null and b/writerfilter/qa/documents/HeaderFooter.doc differ diff --git a/writerfilter/qa/documents/HeaderFooter.docx b/writerfilter/qa/documents/HeaderFooter.docx new file mode 100644 index 000000000..1c550b4d5 Binary files /dev/null and b/writerfilter/qa/documents/HeaderFooter.docx differ diff --git a/writerfilter/qa/documents/IndentedTable.doc b/writerfilter/qa/documents/IndentedTable.doc new file mode 100644 index 000000000..b96ca77b0 Binary files /dev/null and b/writerfilter/qa/documents/IndentedTable.doc differ diff --git a/writerfilter/qa/documents/IndentedTable1.docx b/writerfilter/qa/documents/IndentedTable1.docx new file mode 100644 index 000000000..2499549d3 Binary files /dev/null and b/writerfilter/qa/documents/IndentedTable1.docx differ diff --git a/writerfilter/qa/documents/MergedTable.doc b/writerfilter/qa/documents/MergedTable.doc new file mode 100644 index 000000000..0061045f6 Binary files /dev/null and b/writerfilter/qa/documents/MergedTable.doc differ diff --git a/writerfilter/qa/documents/MergedTable.docx b/writerfilter/qa/documents/MergedTable.docx new file mode 100644 index 000000000..f379c0704 Binary files /dev/null and b/writerfilter/qa/documents/MergedTable.docx differ diff --git a/writerfilter/qa/documents/MergedTable_3_3.doc b/writerfilter/qa/documents/MergedTable_3_3.doc new file mode 100644 index 000000000..13b727590 Binary files /dev/null and b/writerfilter/qa/documents/MergedTable_3_3.doc differ diff --git a/writerfilter/qa/documents/MergedTable_3_3.docx b/writerfilter/qa/documents/MergedTable_3_3.docx new file mode 100644 index 000000000..6fd7447bd Binary files /dev/null and b/writerfilter/qa/documents/MergedTable_3_3.docx differ diff --git a/writerfilter/qa/documents/MultiMergedTable.docx b/writerfilter/qa/documents/MultiMergedTable.docx new file mode 100644 index 000000000..34fcdac2d Binary files /dev/null and b/writerfilter/qa/documents/MultiMergedTable.docx differ diff --git a/writerfilter/qa/documents/MultiWrapping1.docx b/writerfilter/qa/documents/MultiWrapping1.docx new file mode 100644 index 000000000..ce58b09b8 Binary files /dev/null and b/writerfilter/qa/documents/MultiWrapping1.docx differ diff --git a/writerfilter/qa/documents/Paragraph with footnote.doc b/writerfilter/qa/documents/Paragraph with footnote.doc new file mode 100644 index 000000000..eaf22b5ef Binary files /dev/null and b/writerfilter/qa/documents/Paragraph with footnote.doc differ diff --git a/writerfilter/qa/documents/Paragraph with footnote.docx b/writerfilter/qa/documents/Paragraph with footnote.docx new file mode 100644 index 000000000..fbaac59dc Binary files /dev/null and b/writerfilter/qa/documents/Paragraph with footnote.docx differ diff --git a/writerfilter/qa/documents/Picture1.docx b/writerfilter/qa/documents/Picture1.docx new file mode 100644 index 000000000..0a55180a9 Binary files /dev/null and b/writerfilter/qa/documents/Picture1.docx differ diff --git a/writerfilter/qa/documents/RedlineTest.docx b/writerfilter/qa/documents/RedlineTest.docx new file mode 100644 index 000000000..dda53c63f Binary files /dev/null and b/writerfilter/qa/documents/RedlineTest.docx differ diff --git a/writerfilter/qa/documents/RowHeight.doc b/writerfilter/qa/documents/RowHeight.doc new file mode 100644 index 000000000..5db85a486 Binary files /dev/null and b/writerfilter/qa/documents/RowHeight.doc differ diff --git a/writerfilter/qa/documents/RowHeight.docx b/writerfilter/qa/documents/RowHeight.docx new file mode 100644 index 000000000..ffdb7808b Binary files /dev/null and b/writerfilter/qa/documents/RowHeight.docx differ diff --git a/writerfilter/qa/documents/StandardFontAlbertus.doc b/writerfilter/qa/documents/StandardFontAlbertus.doc new file mode 100644 index 000000000..f68d3d6cd Binary files /dev/null and b/writerfilter/qa/documents/StandardFontAlbertus.doc differ diff --git a/writerfilter/qa/documents/Table5CellBorders.doc b/writerfilter/qa/documents/Table5CellBorders.doc new file mode 100644 index 000000000..ab72e558b Binary files /dev/null and b/writerfilter/qa/documents/Table5CellBorders.doc differ diff --git a/writerfilter/qa/documents/Table5CellBorders.docx b/writerfilter/qa/documents/Table5CellBorders.docx new file mode 100644 index 000000000..6b2781756 Binary files /dev/null and b/writerfilter/qa/documents/Table5CellBorders.docx differ diff --git a/writerfilter/qa/documents/TableDifferentColumns.doc b/writerfilter/qa/documents/TableDifferentColumns.doc new file mode 100644 index 000000000..b1871cf3f Binary files /dev/null and b/writerfilter/qa/documents/TableDifferentColumns.doc differ diff --git a/writerfilter/qa/documents/TableDifferentColumns.docx b/writerfilter/qa/documents/TableDifferentColumns.docx new file mode 100644 index 000000000..0503327dd Binary files /dev/null and b/writerfilter/qa/documents/TableDifferentColumns.docx differ diff --git a/writerfilter/qa/documents/TablePreferredWidth.doc b/writerfilter/qa/documents/TablePreferredWidth.doc new file mode 100644 index 000000000..a436d441c Binary files /dev/null and b/writerfilter/qa/documents/TablePreferredWidth.doc differ diff --git a/writerfilter/qa/documents/TablePreferredWidth.docx b/writerfilter/qa/documents/TablePreferredWidth.docx new file mode 100644 index 000000000..719b3888a Binary files /dev/null and b/writerfilter/qa/documents/TablePreferredWidth.docx differ diff --git a/writerfilter/qa/documents/TableRowProperties.doc b/writerfilter/qa/documents/TableRowProperties.doc new file mode 100644 index 000000000..ee3e845ad Binary files /dev/null and b/writerfilter/qa/documents/TableRowProperties.doc differ diff --git a/writerfilter/qa/documents/TableRowProperties.docx b/writerfilter/qa/documents/TableRowProperties.docx new file mode 100644 index 000000000..775d63c97 Binary files /dev/null and b/writerfilter/qa/documents/TableRowProperties.docx differ diff --git a/writerfilter/qa/documents/VertAlign1.doc b/writerfilter/qa/documents/VertAlign1.doc new file mode 100644 index 000000000..57158b6f2 Binary files /dev/null and b/writerfilter/qa/documents/VertAlign1.doc differ diff --git a/writerfilter/qa/documents/WordOLE.docx b/writerfilter/qa/documents/WordOLE.docx new file mode 100644 index 000000000..4cf08d425 Binary files /dev/null and b/writerfilter/qa/documents/WordOLE.docx differ diff --git a/writerfilter/qa/documents/align1.doc b/writerfilter/qa/documents/align1.doc new file mode 100644 index 000000000..9317432b3 Binary files /dev/null and b/writerfilter/qa/documents/align1.doc differ diff --git a/writerfilter/qa/documents/bookmark2.doc b/writerfilter/qa/documents/bookmark2.doc new file mode 100644 index 000000000..83cdcadff Binary files /dev/null and b/writerfilter/qa/documents/bookmark2.doc differ diff --git a/writerfilter/qa/documents/docx/numbering/num-1.docx b/writerfilter/qa/documents/docx/numbering/num-1.docx new file mode 100644 index 000000000..b5e5ffb0b Binary files /dev/null and b/writerfilter/qa/documents/docx/numbering/num-1.docx differ diff --git a/writerfilter/qa/documents/docx/pictures/Word DocumentOffice 2007 Format Sample6.docx b/writerfilter/qa/documents/docx/pictures/Word DocumentOffice 2007 Format Sample6.docx new file mode 100644 index 000000000..eb0d4c256 Binary files /dev/null and b/writerfilter/qa/documents/docx/pictures/Word DocumentOffice 2007 Format Sample6.docx differ diff --git a/writerfilter/qa/documents/docx/pictures/i97645 New example.docx b/writerfilter/qa/documents/docx/pictures/i97645 New example.docx new file mode 100644 index 000000000..6cda8590a Binary files /dev/null and b/writerfilter/qa/documents/docx/pictures/i97645 New example.docx differ diff --git a/writerfilter/qa/documents/docx/pictures/test-image.docx b/writerfilter/qa/documents/docx/pictures/test-image.docx new file mode 100644 index 000000000..fff642451 Binary files /dev/null and b/writerfilter/qa/documents/docx/pictures/test-image.docx differ diff --git a/writerfilter/qa/documents/docx/pictures/test-image1.docx b/writerfilter/qa/documents/docx/pictures/test-image1.docx new file mode 100644 index 000000000..bdcc8e088 Binary files /dev/null and b/writerfilter/qa/documents/docx/pictures/test-image1.docx differ diff --git a/writerfilter/qa/documents/docx/pictures/test.docx b/writerfilter/qa/documents/docx/pictures/test.docx new file mode 100644 index 000000000..72e3c01f3 Binary files /dev/null and b/writerfilter/qa/documents/docx/pictures/test.docx differ diff --git a/writerfilter/qa/documents/docx/redlines/test-review-brk.docx b/writerfilter/qa/documents/docx/redlines/test-review-brk.docx new file mode 100644 index 000000000..7c884505f Binary files /dev/null and b/writerfilter/qa/documents/docx/redlines/test-review-brk.docx differ diff --git a/writerfilter/qa/documents/docx/redlines/test-review-para.docx b/writerfilter/qa/documents/docx/redlines/test-review-para.docx new file mode 100644 index 000000000..9bb87be94 Binary files /dev/null and b/writerfilter/qa/documents/docx/redlines/test-review-para.docx differ diff --git a/writerfilter/qa/documents/docx/redlines/test-review-stack.docx b/writerfilter/qa/documents/docx/redlines/test-review-stack.docx new file mode 100644 index 000000000..18b3e3063 Binary files /dev/null and b/writerfilter/qa/documents/docx/redlines/test-review-stack.docx differ diff --git a/writerfilter/qa/documents/docx/tables/Table in B2.docx b/writerfilter/qa/documents/docx/tables/Table in B2.docx new file mode 100644 index 000000000..4295cec35 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/Table in B2.docx differ diff --git a/writerfilter/qa/documents/docx/tables/nested-tables.docx b/writerfilter/qa/documents/docx/tables/nested-tables.docx new file mode 100644 index 000000000..844b29de8 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/nested-tables.docx differ diff --git a/writerfilter/qa/documents/docx/tables/nested-tables2.docx b/writerfilter/qa/documents/docx/tables/nested-tables2.docx new file mode 100644 index 000000000..0602ba4fa Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/nested-tables2.docx differ diff --git a/writerfilter/qa/documents/docx/tables/nested-tables3.docx b/writerfilter/qa/documents/docx/tables/nested-tables3.docx new file mode 100644 index 000000000..7b61d1472 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/nested-tables3.docx differ diff --git a/writerfilter/qa/documents/docx/tables/nested-tables4.docx b/writerfilter/qa/documents/docx/tables/nested-tables4.docx new file mode 100644 index 000000000..6a17180a4 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/nested-tables4.docx differ diff --git a/writerfilter/qa/documents/docx/tables/nested-tables5.docx b/writerfilter/qa/documents/docx/tables/nested-tables5.docx new file mode 100644 index 000000000..2247b64a7 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/nested-tables5.docx differ diff --git a/writerfilter/qa/documents/docx/tables/parentinvguid.docx b/writerfilter/qa/documents/docx/tables/parentinvguid.docx new file mode 100644 index 000000000..8f859fe43 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/parentinvguid.docx differ diff --git a/writerfilter/qa/documents/docx/tables/table in A1.docx b/writerfilter/qa/documents/docx/tables/table in A1.docx new file mode 100644 index 000000000..d4161eaaa Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/table in A1.docx differ diff --git a/writerfilter/qa/documents/docx/tables/table-styles.docx b/writerfilter/qa/documents/docx/tables/table-styles.docx new file mode 100644 index 000000000..2136f9d0f Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/table-styles.docx differ diff --git a/writerfilter/qa/documents/docx/tables/test-grid.docx b/writerfilter/qa/documents/docx/tables/test-grid.docx new file mode 100644 index 000000000..09f95d1a0 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/test-grid.docx differ diff --git a/writerfilter/qa/documents/docx/tables/test-paras.docx b/writerfilter/qa/documents/docx/tables/test-paras.docx new file mode 100644 index 000000000..0cef4ae05 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/test-paras.docx differ diff --git a/writerfilter/qa/documents/docx/tables/test-simple.docx b/writerfilter/qa/documents/docx/tables/test-simple.docx new file mode 100644 index 000000000..2c0c08427 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/test-simple.docx differ diff --git a/writerfilter/qa/documents/docx/tables/two-tables.docx b/writerfilter/qa/documents/docx/tables/two-tables.docx new file mode 100644 index 000000000..d2e99d3ac Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/two-tables.docx differ diff --git a/writerfilter/qa/documents/docx/tables/updatejpegprocessing.docx b/writerfilter/qa/documents/docx/tables/updatejpegprocessing.docx new file mode 100644 index 000000000..f62eb61df Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/updatejpegprocessing.docx differ diff --git a/writerfilter/qa/documents/docx/tables/~$sted-tables3.docx b/writerfilter/qa/documents/docx/tables/~$sted-tables3.docx new file mode 100644 index 000000000..bfea337b7 Binary files /dev/null and b/writerfilter/qa/documents/docx/tables/~$sted-tables3.docx differ diff --git a/writerfilter/qa/documents/docx/test-page-format.docx b/writerfilter/qa/documents/docx/test-page-format.docx new file mode 100644 index 000000000..eba8dea3e Binary files /dev/null and b/writerfilter/qa/documents/docx/test-page-format.docx differ diff --git a/writerfilter/qa/documents/fields.doc b/writerfilter/qa/documents/fields.doc new file mode 100644 index 000000000..8ad1a3738 Binary files /dev/null and b/writerfilter/qa/documents/fields.doc differ diff --git a/writerfilter/qa/documents/fields.docx b/writerfilter/qa/documents/fields.docx new file mode 100644 index 000000000..4eaa60393 --- /dev/null +++ b/writerfilter/qa/documents/fields.docx @@ -0,0 +1 @@ +PK\"%ã·øåÙƒÑÚšl µw%ë=–“^i7+ÙÇä%¿g&á”0ÞAÉ6€l4¼¾ \ No newline at end of file diff --git a/writerfilter/qa/documents/multimerge2.docx b/writerfilter/qa/documents/multimerge2.docx new file mode 100644 index 000000000..8f594c137 --- /dev/null +++ b/writerfilter/qa/documents/multimerge2.docx @@ -0,0 +1,2 @@ +PKÀQ¥òÑ +¤×8ãAÈO1~ÛëÝqé‚Ãk 6$N{9›êÍ+P9Y ¢†vuÇGD²ìÃï»ÆoR€”wàͳ¶ ÌIÊŠ~‰‰˜ \ No newline at end of file diff --git a/writerfilter/qa/documents/runProperties.doc b/writerfilter/qa/documents/runProperties.doc new file mode 100644 index 000000000..b8b5854df Binary files /dev/null and b/writerfilter/qa/documents/runProperties.doc differ diff --git a/writerfilter/qa/documents/runProperties.docx b/writerfilter/qa/documents/runProperties.docx new file mode 100644 index 000000000..8e14dc923 Binary files /dev/null and b/writerfilter/qa/documents/runProperties.docx differ diff --git a/writerfilter/qa/documents/table_4_4.doc b/writerfilter/qa/documents/table_4_4.doc new file mode 100644 index 000000000..ad8500dc2 Binary files /dev/null and b/writerfilter/qa/documents/table_4_4.doc differ diff --git a/writerfilter/qa/documents/table_4_4.docx b/writerfilter/qa/documents/table_4_4.docx new file mode 100644 index 000000000..484d7f150 Binary files /dev/null and b/writerfilter/qa/documents/table_4_4.docx differ diff --git a/writerfilter/qa/documents/table_style.docx b/writerfilter/qa/documents/table_style.docx new file mode 100644 index 000000000..3cf6e9fbd Binary files /dev/null and b/writerfilter/qa/documents/table_style.docx differ diff --git a/writerfilter/qa/ooxml/watch-generated-code.sh b/writerfilter/qa/ooxml/watch-generated-code.sh new file mode 100755 index 000000000..22dc44011 --- /dev/null +++ b/writerfilter/qa/ooxml/watch-generated-code.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +if [ ! -e bin/get_config_variables ]; then + cd ../../.. +fi + +. bin/get_config_variables SRCDIR + +if [ "$PWD" != "$SRCDIR" ]; then + echo "error: not in the expected SRCDIR" + exit 1 +fi + +cd writerfilter +echo 'include Makefile' > watch.mk +echo 'watch:' >> watch.mk +echo $'\techo $(writerfilter_ALL)' >> watch.mk +mydir=workdir/CustomTarget/writerfilter +writerfilter_ALL=$(make -sr -f watch.mk watch|sed "s|$SRCDIR/$mydir/||g") +rm watch.mk +cd - >/dev/null + +case $1 in +reference) + rm -rf $mydir-reference + mkdir -p $mydir-reference/source/ooxml + for i in $writerfilter_ALL + do + cp $mydir/"$i" $mydir-reference/"$i" + done + ;; +compare) + for i in $writerfilter_ALL + do + if [ "$(basename "$i")" == "model_preprocessed.xml" ]; then + continue + fi + diff -u $mydir-reference/"$i" $mydir/"$i" + done + ;; +*) + echo "usage: $0 [ reference | compare ]" + echo + echo "$0 first saves a reference output of all generated files by writerfilter, then" + echo "allows comparing against it. This helps seeing the effect of changes made on" + echo "the code generator scripts." + ;; +esac + +# vi:set shiftwidth=4 expandtab: diff --git a/writerfilter/source/dmapper/BorderHandler.cxx b/writerfilter/source/dmapper/BorderHandler.cxx new file mode 100644 index 000000000..5769daa5b --- /dev/null +++ b/writerfilter/source/dmapper/BorderHandler.cxx @@ -0,0 +1,213 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "BorderHandler.hxx" +#include "TDefTableHandler.hxx" +#include "PropertyMap.hxx" +#include "ConversionHelper.hxx" +#include +#include +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + + +BorderHandler::BorderHandler( bool bOOXML ) : +LoggedProperties("BorderHandler"), +m_nLineWidth(15), // Word default, in twips +m_nLineType(0), +m_nLineColor(0), +m_nLineDistance(0), +m_bShadow(false), +m_bOOXML( bOOXML ) +{ + m_aFilledLines.fill(false); + m_aBorderLines.fill(table::BorderLine2()); +} + +BorderHandler::~BorderHandler() +{ +} + +void BorderHandler::lcl_attribute(Id rName, Value & rVal) +{ + sal_Int32 nIntValue = rVal.getInt(); + switch( rName ) + { + case NS_ooxml::LN_CT_Border_sz: + // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2. + m_nLineWidth = nIntValue * 5 / 2; + appendGrabBag("sz", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Border_val: + m_nLineType = nIntValue; + appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue)); + break; + case NS_ooxml::LN_CT_Border_color: + m_nLineColor = nIntValue; + appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue))); + break; + case NS_ooxml::LN_CT_Border_space: // border distance in points + m_nLineDistance = ConversionHelper::convertTwipToMM100( nIntValue * 20 ); + appendGrabBag("space", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Border_shadow: + m_bShadow = nIntValue; + break; + case NS_ooxml::LN_CT_Border_frame: + case NS_ooxml::LN_CT_Border_themeTint: + appendGrabBag("themeTint", OUString::number(nIntValue, 16)); + break; + case NS_ooxml::LN_CT_Border_themeColor: + appendGrabBag("themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue)); + break; + default: + OSL_FAIL( "unknown attribute"); + } +} + +void BorderHandler::lcl_sprm(Sprm & rSprm) +{ + BorderPosition pos; + const bool rtl = false; // TODO detect + OUString aBorderPos; + switch( rSprm.getId()) + { + case NS_ooxml::LN_CT_TblBorders_top: + pos = BorderPosition::Top; + aBorderPos = "top"; + break; + case NS_ooxml::LN_CT_TblBorders_start: + pos = rtl ? BorderPosition::Right : BorderPosition::Left; + aBorderPos = "start"; + break; + case NS_ooxml::LN_CT_TblBorders_left: + pos = BorderPosition::Left; + aBorderPos = "left"; + break; + case NS_ooxml::LN_CT_TblBorders_bottom: + pos = BorderPosition::Bottom; + aBorderPos = "bottom"; + break; + case NS_ooxml::LN_CT_TblBorders_end: + pos = rtl ? BorderPosition::Left : BorderPosition::Right; + aBorderPos = "end"; + break; + case NS_ooxml::LN_CT_TblBorders_right: + pos = BorderPosition::Right; + aBorderPos = "right"; + break; + case NS_ooxml::LN_CT_TblBorders_insideH: + pos = BorderPosition::Horizontal; + aBorderPos = "insideH"; + break; + case NS_ooxml::LN_CT_TblBorders_insideV: + pos = BorderPosition::Vertical; + aBorderPos = "insideV"; + break; + default: + return; + } + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties) + { + std::vector aSavedGrabBag; + if (!m_aInteropGrabBagName.isEmpty()) + { + aSavedGrabBag = m_aInteropGrabBag; + m_aInteropGrabBag.clear(); + } + pProperties->resolve(*this); + if (!m_aInteropGrabBagName.isEmpty()) + { + aSavedGrabBag.push_back(getInteropGrabBag(aBorderPos)); + m_aInteropGrabBag = aSavedGrabBag; + } + } + ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, + m_aBorderLines[ pos ], m_bOOXML ); + m_aFilledLines[ pos ] = true; +} + +PropertyMapPtr BorderHandler::getProperties() +{ + static const o3tl::enumarray aPropNames = + { + PROP_TOP_BORDER, + PROP_LEFT_BORDER, + PROP_BOTTOM_BORDER, + PROP_RIGHT_BORDER, + META_PROP_HORIZONTAL_BORDER, + META_PROP_VERTICAL_BORDER + }; + PropertyMapPtr pPropertyMap(new PropertyMap); + // don't fill in default properties + if( m_bOOXML ) + { + for( auto nProp: o3tl::enumrange()) + { + if ( m_aFilledLines[nProp] ) { + pPropertyMap->Insert( aPropNames[nProp], uno::makeAny( m_aBorderLines[nProp] ) ); + } + } + } + return pPropertyMap; +} + +table::BorderLine2 BorderHandler::getBorderLine() +{ + table::BorderLine2 aBorderLine; + ConversionHelper::MakeBorderLine( m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, m_bOOXML ); + return aBorderLine; +} + + +void BorderHandler::enableInteropGrabBag(const OUString& aName) +{ + m_aInteropGrabBagName = aName; +} + +beans::PropertyValue BorderHandler::getInteropGrabBag(const OUString& aName) +{ + beans::PropertyValue aRet; + if (aName.isEmpty()) + aRet.Name = m_aInteropGrabBagName; + else + aRet.Name = aName; + + aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag); + return aRet; +} + +void BorderHandler::appendGrabBag(const OUString& aKey, const OUString& aValue) +{ + beans::PropertyValue aProperty; + aProperty.Name = aKey; + aProperty.Value <<= aValue; + m_aInteropGrabBag.push_back(aProperty); +} + +} //namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/BorderHandler.hxx b/writerfilter/source/dmapper/BorderHandler.hxx new file mode 100644 index 000000000..6eec32327 --- /dev/null +++ b/writerfilter/source/dmapper/BorderHandler.hxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_BORDERHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_BORDERHANDLER_HXX + +#include +#include "LoggedResources.hxx" +#include "PropertyMap.hxx" +#include +#include +#include + +namespace writerfilter { +namespace dmapper +{ +class PropertyMap; +class BorderHandler : public LoggedProperties +{ +private: + //todo: order is a guess + enum class BorderPosition + { + Top, + Left, + Bottom, + Right, + Horizontal, + Vertical, + LAST = Vertical + }; + + //values of the current border + sal_Int32 m_nLineWidth; + sal_Int32 m_nLineType; + sal_Int32 m_nLineColor; + sal_Int32 m_nLineDistance; + bool m_bShadow; + bool m_bOOXML; + + o3tl::enumarray m_aFilledLines; + o3tl::enumarray m_aBorderLines; + OUString m_aInteropGrabBagName; + std::vector m_aInteropGrabBag; + void appendGrabBag(const OUString& aKey, const OUString& aValue); + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +public: + explicit BorderHandler( bool bOOXML ); + virtual ~BorderHandler() override; + + PropertyMapPtr getProperties(); + css::table::BorderLine2 getBorderLine(); + sal_Int32 getLineDistance() const { return m_nLineDistance;} + bool getShadow() const { return m_bShadow;} + void enableInteropGrabBag(const OUString& aName); + css::beans::PropertyValue getInteropGrabBag(const OUString& aName = OUString()); +}; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/CellColorHandler.cxx b/writerfilter/source/dmapper/CellColorHandler.cxx new file mode 100644 index 000000000..805f6e1bb --- /dev/null +++ b/writerfilter/source/dmapper/CellColorHandler.cxx @@ -0,0 +1,331 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "CellColorHandler.hxx" +#include "PropertyMap.hxx" +#include "TDefTableHandler.hxx" +#include +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + +CellColorHandler::CellColorHandler() : +LoggedProperties("CellColorHandler"), +m_nShadingPattern( drawing::ShadingPattern::CLEAR ), +m_nColor( 0xffffffff ), +m_nFillColor( 0xffffffff ), +m_bAutoFillColor( true ), +m_bFillSpecified( false ), + m_OutputFormat( Form ) +{ +} + +CellColorHandler::~CellColorHandler() +{ +} + +// ST_Shd strings are converted to integers by the tokenizer, store strings in +// the InteropGrabBag +static uno::Any lcl_ConvertShd(sal_Int32 nIntValue) +{ + OUString aRet; + // This should be in sync with the ST_Shd list in ooxml's model.xml. + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_Shd_clear: aRet = "clear"; break; + case NS_ooxml::LN_Value_ST_Shd_solid: aRet = "solid"; break; + case NS_ooxml::LN_Value_ST_Shd_pct5: aRet = "pct5"; break; + case NS_ooxml::LN_Value_ST_Shd_pct10: aRet = "pct10"; break; + case NS_ooxml::LN_Value_ST_Shd_pct20: aRet = "pct20"; break; + case NS_ooxml::LN_Value_ST_Shd_pct25: aRet = "pct25"; break; + case NS_ooxml::LN_Value_ST_Shd_pct30: aRet = "pct30"; break; + case NS_ooxml::LN_Value_ST_Shd_pct40: aRet = "pct40"; break; + case NS_ooxml::LN_Value_ST_Shd_pct50: aRet = "pct50"; break; + case NS_ooxml::LN_Value_ST_Shd_pct60: aRet = "pct60"; break; + case NS_ooxml::LN_Value_ST_Shd_pct70: aRet = "pct70"; break; + case NS_ooxml::LN_Value_ST_Shd_pct75: aRet = "pct75"; break; + case NS_ooxml::LN_Value_ST_Shd_pct80: aRet = "pct80"; break; + case NS_ooxml::LN_Value_ST_Shd_pct90: aRet = "pct90"; break; + case NS_ooxml::LN_Value_ST_Shd_horzStripe: aRet = "horzStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_vertStripe: aRet = "vertStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_reverseDiagStripe: aRet = "reverseDiagStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_diagStripe: aRet = "diagStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_horzCross: aRet = "horzCross"; break; + case NS_ooxml::LN_Value_ST_Shd_diagCross: aRet = "diagCross"; break; + case NS_ooxml::LN_Value_ST_Shd_thinHorzStripe: aRet = "thinHorzStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_thinVertStripe: aRet = "thinVertStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_thinReverseDiagStripe: aRet = "thinReverseDiagStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_thinDiagStripe: aRet = "thinDiagStripe"; break; + case NS_ooxml::LN_Value_ST_Shd_thinHorzCross: aRet = "thinHorzCross"; break; + case NS_ooxml::LN_Value_ST_Shd_thinDiagCross: aRet = "thinDiagCross"; break; + case NS_ooxml::LN_Value_ST_Shd_pct12: aRet = "pct12"; break; + case NS_ooxml::LN_Value_ST_Shd_pct15: aRet = "pct15"; break; + case NS_ooxml::LN_Value_ST_Shd_pct35: aRet = "pct35"; break; + case NS_ooxml::LN_Value_ST_Shd_pct37: aRet = "pct37"; break; + case NS_ooxml::LN_Value_ST_Shd_pct45: aRet = "pct45"; break; + case NS_ooxml::LN_Value_ST_Shd_pct55: aRet = "pct55"; break; + case NS_ooxml::LN_Value_ST_Shd_pct62: aRet = "pct62"; break; + case NS_ooxml::LN_Value_ST_Shd_pct65: aRet = "pct65"; break; + case NS_ooxml::LN_Value_ST_Shd_pct85: aRet = "pct85"; break; + case NS_ooxml::LN_Value_ST_Shd_pct87: aRet = "pct87"; break; + case NS_ooxml::LN_Value_ST_Shd_pct95: aRet = "pct95"; break; + case NS_ooxml::LN_Value_ST_Shd_nil: aRet = "nil"; break; + } + return uno::makeAny(aRet); +} + +void CellColorHandler::lcl_attribute(Id rName, Value & rVal) +{ + sal_Int32 nIntValue = rVal.getInt(); + switch( rName ) + { + case NS_ooxml::LN_CT_Shd_val: + { + createGrabBag("val", lcl_ConvertShd(nIntValue)); + m_nShadingPattern = nIntValue; + } + break; + case NS_ooxml::LN_CT_Shd_fill: + createGrabBag("fill", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue)))); + if( nIntValue == sal_Int32(COL_AUTO) ) + nIntValue = 0xffffff; //fill color auto means white + else + m_bAutoFillColor = false; + + m_nFillColor = nIntValue; + m_bFillSpecified = true; + break; + case NS_ooxml::LN_CT_Shd_color: + createGrabBag("color", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue)))); + if( nIntValue == sal_Int32(COL_AUTO) ) + nIntValue = 0; //shading color auto means black + //color of the shading + m_nColor = nIntValue; + break; + case NS_ooxml::LN_CT_Shd_themeFill: + createGrabBag("themeFill", uno::makeAny(TDefTableHandler::getThemeColorTypeString(nIntValue))); + break; + case NS_ooxml::LN_CT_Shd_themeFillShade: + createGrabBag("themeFillShade", uno::makeAny(OUString::number(nIntValue, 16))); + break; + case NS_ooxml::LN_CT_Shd_themeFillTint: + createGrabBag("themeFillTint", uno::makeAny(OUString::number(nIntValue, 16))); + break; + case NS_ooxml::LN_CT_Shd_themeColor: + createGrabBag("themeColor", uno::makeAny(TDefTableHandler::getThemeColorTypeString(nIntValue))); + break; + case NS_ooxml::LN_CT_Shd_themeShade: + createGrabBag("themeShade", uno::makeAny(OUString::number(nIntValue, 16))); + break; + case NS_ooxml::LN_CT_Shd_themeTint: + createGrabBag("themeTint", uno::makeAny(OUString::number(nIntValue, 16))); + break; + default: + OSL_FAIL( "unknown attribute"); + } +} + +void CellColorHandler::lcl_sprm(Sprm &) {} + +TablePropertyMapPtr CellColorHandler::getProperties() +{ + TablePropertyMapPtr pPropertyMap(new TablePropertyMap); + + // Code from binary word filter (the values are out of 1000) + sal_Int32 nWW8BrushStyle = 0; + switch (m_nShadingPattern) + { + // Clear-Brush + case NS_ooxml::LN_Value_ST_Shd_clear: nWW8BrushStyle = 0; break; + // Solid-Brush + case NS_ooxml::LN_Value_ST_Shd_solid: nWW8BrushStyle = 1000; break; + // Percent values + case NS_ooxml::LN_Value_ST_Shd_pct5: nWW8BrushStyle = 50; break; + case NS_ooxml::LN_Value_ST_Shd_pct10: nWW8BrushStyle = 100; break; + case NS_ooxml::LN_Value_ST_Shd_pct20: nWW8BrushStyle = 200; break; + case NS_ooxml::LN_Value_ST_Shd_pct25: nWW8BrushStyle = 250; break; + case NS_ooxml::LN_Value_ST_Shd_pct30: nWW8BrushStyle = 300; break; + case NS_ooxml::LN_Value_ST_Shd_pct40: nWW8BrushStyle = 400; break; + case NS_ooxml::LN_Value_ST_Shd_pct50: nWW8BrushStyle = 500; break; + case NS_ooxml::LN_Value_ST_Shd_pct60: nWW8BrushStyle = 600; break; + case NS_ooxml::LN_Value_ST_Shd_pct70: nWW8BrushStyle = 700; break; + case NS_ooxml::LN_Value_ST_Shd_pct75: nWW8BrushStyle = 750; break; + case NS_ooxml::LN_Value_ST_Shd_pct80: nWW8BrushStyle = 800; break; + case NS_ooxml::LN_Value_ST_Shd_pct90: nWW8BrushStyle = 900; break; + // Special cases + case NS_ooxml::LN_Value_ST_Shd_horzStripe: nWW8BrushStyle = 333; break; // Dark Horizontal + case NS_ooxml::LN_Value_ST_Shd_vertStripe: nWW8BrushStyle = 333; break; // Dark Vertical + case NS_ooxml::LN_Value_ST_Shd_reverseDiagStripe: nWW8BrushStyle = 333; break; // Dark Forward Diagonal + case NS_ooxml::LN_Value_ST_Shd_diagStripe: nWW8BrushStyle = 333; break; // Dark Backward Diagonal + case NS_ooxml::LN_Value_ST_Shd_horzCross: nWW8BrushStyle = 333; break; // Dark Cross + case NS_ooxml::LN_Value_ST_Shd_diagCross: nWW8BrushStyle = 333; break; // Dark Diagonal Cross + case NS_ooxml::LN_Value_ST_Shd_thinHorzStripe: nWW8BrushStyle = 333; break; // Horizontal + case NS_ooxml::LN_Value_ST_Shd_thinVertStripe: nWW8BrushStyle = 333; break; // Vertical + case NS_ooxml::LN_Value_ST_Shd_thinReverseDiagStripe: nWW8BrushStyle = 333; break; // Forward Diagonal + case NS_ooxml::LN_Value_ST_Shd_thinDiagStripe: nWW8BrushStyle = 333; break; // Backward Diagonal + case NS_ooxml::LN_Value_ST_Shd_thinHorzCross: nWW8BrushStyle = 333; break; // Cross + case NS_ooxml::LN_Value_ST_Shd_thinDiagCross: nWW8BrushStyle = 333; break; // 25 Diagonal Cross + // Different shading types + case NS_ooxml::LN_Value_ST_Shd_pct12: nWW8BrushStyle = 125; break; + case NS_ooxml::LN_Value_ST_Shd_pct15: nWW8BrushStyle = 150; break; + case NS_ooxml::LN_Value_ST_Shd_pct35: nWW8BrushStyle = 350; break; + case NS_ooxml::LN_Value_ST_Shd_pct37: nWW8BrushStyle = 375; break; + case NS_ooxml::LN_Value_ST_Shd_pct45: nWW8BrushStyle = 450; break; + case NS_ooxml::LN_Value_ST_Shd_pct55: nWW8BrushStyle = 550; break; + case NS_ooxml::LN_Value_ST_Shd_pct62: nWW8BrushStyle = 625; break; + case NS_ooxml::LN_Value_ST_Shd_pct65: nWW8BrushStyle = 650; break; + case NS_ooxml::LN_Value_ST_Shd_pct85: nWW8BrushStyle = 850; break; + case NS_ooxml::LN_Value_ST_Shd_pct87: nWW8BrushStyle = 875; break; + case NS_ooxml::LN_Value_ST_Shd_pct95: nWW8BrushStyle = 950; break; + } + + sal_Int32 nApplyColor = 0; + if( !nWW8BrushStyle ) + { + // Clear-Brush + if ( m_bFillSpecified && m_bAutoFillColor ) + nApplyColor = sal_Int32(COL_AUTO); + else + nApplyColor = m_nFillColor; + } + else + { + sal_Int32 nFore = m_nColor; + sal_Int32 nBack = m_nFillColor; + + sal_uInt32 nRed = ((nFore & 0xff0000)>>0x10) * nWW8BrushStyle; + sal_uInt32 nGreen = ((nFore & 0xff00)>>0x8) * nWW8BrushStyle; + sal_uInt32 nBlue = (nFore & 0xff) * nWW8BrushStyle; + nRed += ((nBack & 0xff0000)>>0x10) * (1000L - nWW8BrushStyle); + nGreen += ((nBack & 0xff00)>>0x8)* (1000L - nWW8BrushStyle); + nBlue += (nBack & 0xff) * (1000L - nWW8BrushStyle); + + nApplyColor = ( (nRed/1000) << 0x10 ) + ((nGreen/1000) << 8) + nBlue/1000; + } + + // Check if it is a 'Character' + if (m_OutputFormat == Character) + { + sal_Int32 nShadingPattern = drawing::ShadingPattern::CLEAR; + switch (m_nShadingPattern) + { + case NS_ooxml::LN_Value_ST_Shd_clear: nShadingPattern = drawing::ShadingPattern::CLEAR; break; + case NS_ooxml::LN_Value_ST_Shd_solid: nShadingPattern = drawing::ShadingPattern::SOLID; break; + case NS_ooxml::LN_Value_ST_Shd_pct5: nShadingPattern = drawing::ShadingPattern::PCT5; break; + case NS_ooxml::LN_Value_ST_Shd_pct10: nShadingPattern = drawing::ShadingPattern::PCT10; break; + case NS_ooxml::LN_Value_ST_Shd_pct20: nShadingPattern = drawing::ShadingPattern::PCT20; break; + case NS_ooxml::LN_Value_ST_Shd_pct25: nShadingPattern = drawing::ShadingPattern::PCT25; break; + case NS_ooxml::LN_Value_ST_Shd_pct30: nShadingPattern = drawing::ShadingPattern::PCT30; break; + case NS_ooxml::LN_Value_ST_Shd_pct40: nShadingPattern = drawing::ShadingPattern::PCT40; break; + case NS_ooxml::LN_Value_ST_Shd_pct50: nShadingPattern = drawing::ShadingPattern::PCT50; break; + case NS_ooxml::LN_Value_ST_Shd_pct60: nShadingPattern = drawing::ShadingPattern::PCT60; break; + case NS_ooxml::LN_Value_ST_Shd_pct70: nShadingPattern = drawing::ShadingPattern::PCT70; break; + case NS_ooxml::LN_Value_ST_Shd_pct75: nShadingPattern = drawing::ShadingPattern::PCT75; break; + case NS_ooxml::LN_Value_ST_Shd_pct80: nShadingPattern = drawing::ShadingPattern::PCT80; break; + case NS_ooxml::LN_Value_ST_Shd_pct90: nShadingPattern = drawing::ShadingPattern::PCT90; break; + case NS_ooxml::LN_Value_ST_Shd_horzStripe: nShadingPattern = drawing::ShadingPattern::HORZ_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_vertStripe: nShadingPattern = drawing::ShadingPattern::VERT_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_reverseDiagStripe: nShadingPattern = drawing::ShadingPattern::REVERSE_DIAG_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_diagStripe: nShadingPattern = drawing::ShadingPattern::DIAG_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_horzCross: nShadingPattern = drawing::ShadingPattern::HORZ_CROSS; break; + case NS_ooxml::LN_Value_ST_Shd_diagCross: nShadingPattern = drawing::ShadingPattern::DIAG_CROSS; break; + case NS_ooxml::LN_Value_ST_Shd_thinHorzStripe: nShadingPattern = drawing::ShadingPattern::THIN_HORZ_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_thinVertStripe: nShadingPattern = drawing::ShadingPattern::THIN_VERT_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_thinReverseDiagStripe: nShadingPattern = drawing::ShadingPattern::THIN_REVERSE_DIAG_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_thinDiagStripe: nShadingPattern = drawing::ShadingPattern::THIN_DIAG_STRIPE; break; + case NS_ooxml::LN_Value_ST_Shd_thinHorzCross: nShadingPattern = drawing::ShadingPattern::THIN_HORZ_CROSS; break; + case NS_ooxml::LN_Value_ST_Shd_thinDiagCross: nShadingPattern = drawing::ShadingPattern::THIN_DIAG_CROSS; break; + case NS_ooxml::LN_Value_ST_Shd_pct12: nShadingPattern = drawing::ShadingPattern::PCT12; break; + case NS_ooxml::LN_Value_ST_Shd_pct15: nShadingPattern = drawing::ShadingPattern::PCT15; break; + case NS_ooxml::LN_Value_ST_Shd_pct35: nShadingPattern = drawing::ShadingPattern::PCT35; break; + case NS_ooxml::LN_Value_ST_Shd_pct37: nShadingPattern = drawing::ShadingPattern::PCT37; break; + case NS_ooxml::LN_Value_ST_Shd_pct45: nShadingPattern = drawing::ShadingPattern::PCT45; break; + case NS_ooxml::LN_Value_ST_Shd_pct55: nShadingPattern = drawing::ShadingPattern::PCT55; break; + case NS_ooxml::LN_Value_ST_Shd_pct62: nShadingPattern = drawing::ShadingPattern::PCT62; break; + case NS_ooxml::LN_Value_ST_Shd_pct65: nShadingPattern = drawing::ShadingPattern::PCT65; break; + case NS_ooxml::LN_Value_ST_Shd_pct85: nShadingPattern = drawing::ShadingPattern::PCT85; break; + case NS_ooxml::LN_Value_ST_Shd_pct87: nShadingPattern = drawing::ShadingPattern::PCT87; break; + case NS_ooxml::LN_Value_ST_Shd_pct95: nShadingPattern = drawing::ShadingPattern::PCT95; break; + } + + // Write the shading pattern property + pPropertyMap->Insert(PROP_CHAR_SHADING_VALUE, uno::makeAny( nShadingPattern )); + } + + if (m_OutputFormat == Paragraph && m_nShadingPattern != NS_ooxml::LN_Value_ST_Shd_nil) + { + if (nWW8BrushStyle || !m_bAutoFillColor) + pPropertyMap->Insert(PROP_FILL_STYLE, uno::makeAny(drawing::FillStyle_SOLID)); + else if (m_bFillSpecified) // m_bAutoFillColor == true + pPropertyMap->Insert(PROP_FILL_STYLE, uno::makeAny(drawing::FillStyle_NONE)); + + pPropertyMap->Insert(PROP_FILL_COLOR, uno::makeAny(nApplyColor)); + } + else if ( nWW8BrushStyle || !m_bAutoFillColor || m_bFillSpecified ) + pPropertyMap->Insert( m_OutputFormat == Form ? PROP_BACK_COLOR + : PROP_CHAR_BACK_COLOR, uno::makeAny( nApplyColor )); + + createGrabBag("originalColor", uno::makeAny(OUString::fromUtf8(msfilter::util::ConvertColor(nApplyColor)))); + + return pPropertyMap; +} + +void CellColorHandler::createGrabBag(const OUString& aName, const uno::Any& rAny) +{ + if (m_aInteropGrabBagName.isEmpty()) + return; + + beans::PropertyValue aValue; + aValue.Name = aName; + aValue.Value = rAny; + m_aInteropGrabBag.push_back(aValue); +} + +void CellColorHandler::enableInteropGrabBag(const OUString& aName) +{ + m_aInteropGrabBagName = aName; +} + +beans::PropertyValue CellColorHandler::getInteropGrabBag() +{ + beans::PropertyValue aRet; + aRet.Name = m_aInteropGrabBagName; + aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag); + return aRet; +} + +void CellColorHandler::disableInteropGrabBag() +{ + m_aInteropGrabBagName.clear(); + m_aInteropGrabBag.clear(); +} + +bool CellColorHandler::isInteropGrabBagEnabled() const +{ + return !(m_aInteropGrabBagName.isEmpty()); +} + +} //namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/CellColorHandler.hxx b/writerfilter/source/dmapper/CellColorHandler.hxx new file mode 100644 index 000000000..4ec63c217 --- /dev/null +++ b/writerfilter/source/dmapper/CellColorHandler.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_CELLCOLORHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_CELLCOLORHANDLER_HXX + +#include "LoggedResources.hxx" +#include "PropertyMap.hxx" +#include + +#include + +namespace writerfilter { +namespace dmapper +{ +class TablePropertyMap; +class CellColorHandler : public LoggedProperties +{ +public: + enum OutputFormat { Form, Paragraph, Character }; // for what part of the document +private: + sal_Int32 m_nShadingPattern; + sal_Int32 m_nColor; + sal_Int32 m_nFillColor; + bool m_bAutoFillColor; + bool m_bFillSpecified; + OutputFormat m_OutputFormat; + + OUString m_aInteropGrabBagName; + std::vector m_aInteropGrabBag; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + + void createGrabBag(const OUString& aName, const css::uno::Any& rValue); + +public: + CellColorHandler( ); + virtual ~CellColorHandler() override; + + TablePropertyMapPtr getProperties(); + + void setOutputFormat( OutputFormat format ) { m_OutputFormat = format; } + + void enableInteropGrabBag(const OUString& aName); + css::beans::PropertyValue getInteropGrabBag(); + void disableInteropGrabBag(); + bool isInteropGrabBagEnabled() const; +}; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/CellMarginHandler.cxx b/writerfilter/source/dmapper/CellMarginHandler.cxx new file mode 100644 index 000000000..8b7b5fa77 --- /dev/null +++ b/writerfilter/source/dmapper/CellMarginHandler.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "CellMarginHandler.hxx" +#include "ConversionHelper.hxx" +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; +using namespace ::writerfilter; + +CellMarginHandler::CellMarginHandler() : +LoggedProperties("CellMarginHandler"), +m_nValue( 0 ), +m_nWidth( 0 ), +m_nType( 0 ), +m_nLeftMargin( 0 ), +m_bLeftMarginValid( false ), +m_nRightMargin( 0 ), +m_bRightMarginValid( false ), +m_nTopMargin( 0 ), +m_bTopMarginValid( false ), +m_nBottomMargin( 0 ), +m_bBottomMarginValid( false ) +{ +} + +CellMarginHandler::~CellMarginHandler() +{ +} + +void CellMarginHandler::lcl_attribute(Id rName, Value & rVal) +{ + sal_Int32 nIntValue = rVal.getInt(); + switch( rName ) + { + case NS_ooxml::LN_CT_TblWidth_w: + m_nWidth = nIntValue; + m_nValue = ConversionHelper::convertTwipToMM100Unsigned( nIntValue ); + break; + case NS_ooxml::LN_CT_TblWidth_type: + SAL_WARN_IF(NS_ooxml::LN_Value_ST_TblWidth_dxa != sal::static_int_cast(nIntValue), "writerfilter", "CellMarginHandler: cell margins work for absolute values only"); + m_nType = nIntValue; + break; + default: + SAL_WARN("writerfilter", "CellMarginHandler::lcl_attribute: unknown attribute"); + } +} + +void CellMarginHandler::createGrabBag(const OUString& aName) +{ + if (m_aInteropGrabBagName.isEmpty()) + return; + + beans::PropertyValue aRet; + aRet.Name = aName; + + OUString sType; + switch (m_nType) + { + case NS_ooxml::LN_Value_ST_TblWidth_nil: sType = "nil"; break; + case NS_ooxml::LN_Value_ST_TblWidth_pct: sType = "pct"; break; + case NS_ooxml::LN_Value_ST_TblWidth_dxa: sType = "dxa"; break; + case NS_ooxml::LN_Value_ST_TblWidth_auto: sType = "auto"; break; + } + uno::Sequence aSeq( comphelper::InitPropertySequence({ + { "w", uno::Any(m_nWidth) }, + { "type", uno::Any(sType) } + })); + + aRet.Value <<= aSeq; + m_aInteropGrabBag.push_back(aRet); +} + +void CellMarginHandler::lcl_sprm(Sprm & rSprm) +{ + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties) + { + pProperties->resolve( *this ); + const bool rtl = false; // TODO + switch( rSprm.getId() ) + { + case NS_ooxml::LN_CT_TblCellMar_top: + case NS_ooxml::LN_CT_TcMar_top: + m_nTopMargin = m_nValue; + m_bTopMarginValid = true; + createGrabBag("top"); + break; + case NS_ooxml::LN_CT_TblCellMar_start: + case NS_ooxml::LN_CT_TcMar_start: + if( rtl ) + { + m_nRightMargin = m_nValue; + m_bRightMarginValid = true; + } + else + { + m_nLeftMargin = m_nValue; + m_bLeftMarginValid = true; + } + createGrabBag("start"); + break; + case NS_ooxml::LN_CT_TblCellMar_left: + case NS_ooxml::LN_CT_TcMar_left: + m_nLeftMargin = m_nValue; + m_bLeftMarginValid = true; + createGrabBag("left"); + break; + case NS_ooxml::LN_CT_TblCellMar_bottom: + case NS_ooxml::LN_CT_TcMar_bottom: + m_nBottomMargin = m_nValue; + m_bBottomMarginValid = true; + createGrabBag("bottom"); + break; + case NS_ooxml::LN_CT_TblCellMar_end: + case NS_ooxml::LN_CT_TcMar_end: + if( rtl ) + { + m_nLeftMargin = m_nValue; + m_bLeftMarginValid = true; + } + else + { + m_nRightMargin = m_nValue; + m_bRightMarginValid = true; + } + createGrabBag("end"); + break; + case NS_ooxml::LN_CT_TblCellMar_right: + case NS_ooxml::LN_CT_TcMar_right: + m_nRightMargin = m_nValue; + m_bRightMarginValid = true; + createGrabBag("right"); + break; + default: + SAL_WARN("writerfilter", "CellMarginHandler::lcl_sprm: unknown sprm"); + } + } + m_nValue = 0; +} + +void CellMarginHandler::enableInteropGrabBag(const OUString& aName) +{ + m_aInteropGrabBagName = aName; +} + +beans::PropertyValue CellMarginHandler::getInteropGrabBag() +{ + beans::PropertyValue aRet; + aRet.Name = m_aInteropGrabBagName; + aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag); + return aRet; +} + +} //namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/CellMarginHandler.hxx b/writerfilter/source/dmapper/CellMarginHandler.hxx new file mode 100644 index 000000000..349611b10 --- /dev/null +++ b/writerfilter/source/dmapper/CellMarginHandler.hxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_CELLMARGINHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_CELLMARGINHANDLER_HXX + +#include "LoggedResources.hxx" +#include +#include + +namespace writerfilter { +namespace dmapper +{ +class TablePropertyMap; +class CellMarginHandler : public LoggedProperties +{ +private: + sal_Int32 m_nValue; ///< Converted value. + sal_Int32 m_nWidth; ///< Original value. + sal_Int32 m_nType; ///< Unit of the value (dxa, etc). + + OUString m_aInteropGrabBagName; + std::vector m_aInteropGrabBag; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + + void createGrabBag(const OUString& aName); + +public: + sal_Int32 m_nLeftMargin; + bool m_bLeftMarginValid; + sal_Int32 m_nRightMargin; + bool m_bRightMarginValid; + sal_Int32 m_nTopMargin; + bool m_bTopMarginValid; + sal_Int32 m_nBottomMargin; + bool m_bBottomMarginValid; + +public: + CellMarginHandler( ); + virtual ~CellMarginHandler() override; + + void enableInteropGrabBag(const OUString& aName); + css::beans::PropertyValue getInteropGrabBag(); + +}; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/ConversionHelper.cxx b/writerfilter/source/dmapper/ConversionHelper.cxx new file mode 100644 index 000000000..9baac3034 --- /dev/null +++ b/writerfilter/source/dmapper/ConversionHelper.cxx @@ -0,0 +1,669 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "ConversionHelper.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace com::sun::star; + +namespace writerfilter::dmapper::ConversionHelper{ + +/// Convert OOXML border style to WW8 that editeng can handle. +static sal_Int32 lcl_convertBorderStyleFromToken(sal_Int32 nOOXMLType) +{ + switch (nOOXMLType) + { + case NS_ooxml::LN_Value_ST_Border_nil: return 255; + case NS_ooxml::LN_Value_ST_Border_none: return 0; + case NS_ooxml::LN_Value_ST_Border_single: return 1; + case NS_ooxml::LN_Value_ST_Border_thick: return 2; + case NS_ooxml::LN_Value_ST_Border_double: return 3; + case NS_ooxml::LN_Value_ST_Border_dotted: return 6; + case NS_ooxml::LN_Value_ST_Border_dashed: return 7; + case NS_ooxml::LN_Value_ST_Border_dotDash: return 8; + case NS_ooxml::LN_Value_ST_Border_dotDotDash: return 9; + case NS_ooxml::LN_Value_ST_Border_triple: return 10; + case NS_ooxml::LN_Value_ST_Border_thinThickSmallGap: return 11; + case NS_ooxml::LN_Value_ST_Border_thickThinSmallGap: return 12; + case NS_ooxml::LN_Value_ST_Border_thinThickThinSmallGap: return 13; + case NS_ooxml::LN_Value_ST_Border_thinThickMediumGap: return 14; + case NS_ooxml::LN_Value_ST_Border_thickThinMediumGap: return 15; + case NS_ooxml::LN_Value_ST_Border_thinThickThinMediumGap: return 16; + case NS_ooxml::LN_Value_ST_Border_thinThickLargeGap: return 17; + case NS_ooxml::LN_Value_ST_Border_thickThinLargeGap: return 18; + case NS_ooxml::LN_Value_ST_Border_thinThickThinLargeGap: return 19; + case NS_ooxml::LN_Value_ST_Border_wave: return 20; + case NS_ooxml::LN_Value_ST_Border_doubleWave: return 21; + case NS_ooxml::LN_Value_ST_Border_dashSmallGap: return 22; + case NS_ooxml::LN_Value_ST_Border_dashDotStroked: return 23; + case NS_ooxml::LN_Value_ST_Border_threeDEmboss: return 24; + case NS_ooxml::LN_Value_ST_Border_threeDEngrave: return 25; + case NS_ooxml::LN_Value_ST_Border_outset: return 26; + case NS_ooxml::LN_Value_ST_Border_inset: return 27; + case NS_ooxml::LN_Value_ST_Border_apples: return 64; + case NS_ooxml::LN_Value_ST_Border_archedScallops: return 65; + case NS_ooxml::LN_Value_ST_Border_babyPacifier: return 66; + case NS_ooxml::LN_Value_ST_Border_babyRattle: return 67; + case NS_ooxml::LN_Value_ST_Border_balloons3Colors: return 68; + case NS_ooxml::LN_Value_ST_Border_balloonsHotAir: return 69; + case NS_ooxml::LN_Value_ST_Border_basicBlackDashes: return 70; + case NS_ooxml::LN_Value_ST_Border_basicBlackDots: return 71; + case NS_ooxml::LN_Value_ST_Border_basicBlackSquares: return 72; + case NS_ooxml::LN_Value_ST_Border_basicThinLines: return 73; + case NS_ooxml::LN_Value_ST_Border_basicWhiteDashes: return 74; + case NS_ooxml::LN_Value_ST_Border_basicWhiteDots: return 75; + case NS_ooxml::LN_Value_ST_Border_basicWhiteSquares: return 76; + case NS_ooxml::LN_Value_ST_Border_basicWideInline: return 77; + case NS_ooxml::LN_Value_ST_Border_basicWideMidline: return 78; + case NS_ooxml::LN_Value_ST_Border_basicWideOutline: return 79; + case NS_ooxml::LN_Value_ST_Border_bats: return 80; + case NS_ooxml::LN_Value_ST_Border_birds: return 81; + case NS_ooxml::LN_Value_ST_Border_birdsFlight: return 82; + case NS_ooxml::LN_Value_ST_Border_cabins: return 83; + case NS_ooxml::LN_Value_ST_Border_cakeSlice: return 84; + case NS_ooxml::LN_Value_ST_Border_candyCorn: return 85; + case NS_ooxml::LN_Value_ST_Border_celticKnotwork: return 86; + case NS_ooxml::LN_Value_ST_Border_certificateBanner: return 87; + case NS_ooxml::LN_Value_ST_Border_chainLink: return 88; + case NS_ooxml::LN_Value_ST_Border_champagneBottle: return 89; + case NS_ooxml::LN_Value_ST_Border_checkedBarBlack: return 90; + case NS_ooxml::LN_Value_ST_Border_checkedBarColor: return 91; + case NS_ooxml::LN_Value_ST_Border_checkered: return 92; + case NS_ooxml::LN_Value_ST_Border_christmasTree: return 93; + case NS_ooxml::LN_Value_ST_Border_circlesLines: return 94; + case NS_ooxml::LN_Value_ST_Border_circlesRectangles: return 95; + case NS_ooxml::LN_Value_ST_Border_classicalWave: return 96; + case NS_ooxml::LN_Value_ST_Border_clocks: return 97; + case NS_ooxml::LN_Value_ST_Border_compass: return 98; + case NS_ooxml::LN_Value_ST_Border_confetti: return 99; + case NS_ooxml::LN_Value_ST_Border_confettiGrays: return 100; + case NS_ooxml::LN_Value_ST_Border_confettiOutline: return 101; + case NS_ooxml::LN_Value_ST_Border_confettiStreamers: return 102; + case NS_ooxml::LN_Value_ST_Border_confettiWhite: return 103; + case NS_ooxml::LN_Value_ST_Border_cornerTriangles: return 104; + case NS_ooxml::LN_Value_ST_Border_couponCutoutDashes: return 105; + case NS_ooxml::LN_Value_ST_Border_couponCutoutDots: return 106; + case NS_ooxml::LN_Value_ST_Border_crazyMaze: return 107; + case NS_ooxml::LN_Value_ST_Border_creaturesButterfly: return 108; + case NS_ooxml::LN_Value_ST_Border_creaturesFish: return 109; + case NS_ooxml::LN_Value_ST_Border_creaturesInsects: return 110; + case NS_ooxml::LN_Value_ST_Border_creaturesLadyBug: return 111; + case NS_ooxml::LN_Value_ST_Border_crossStitch: return 112; + case NS_ooxml::LN_Value_ST_Border_cup: return 113; + case NS_ooxml::LN_Value_ST_Border_decoArch: return 114; + case NS_ooxml::LN_Value_ST_Border_decoArchColor: return 115; + case NS_ooxml::LN_Value_ST_Border_decoBlocks: return 116; + case NS_ooxml::LN_Value_ST_Border_diamondsGray: return 117; + case NS_ooxml::LN_Value_ST_Border_doubleD: return 118; + case NS_ooxml::LN_Value_ST_Border_doubleDiamonds: return 119; + case NS_ooxml::LN_Value_ST_Border_earth1: return 120; + case NS_ooxml::LN_Value_ST_Border_earth2: return 121; + case NS_ooxml::LN_Value_ST_Border_eclipsingSquares1: return 122; + case NS_ooxml::LN_Value_ST_Border_eclipsingSquares2: return 123; + case NS_ooxml::LN_Value_ST_Border_eggsBlack: return 124; + case NS_ooxml::LN_Value_ST_Border_fans: return 125; + case NS_ooxml::LN_Value_ST_Border_film: return 126; + case NS_ooxml::LN_Value_ST_Border_firecrackers: return 127; + case NS_ooxml::LN_Value_ST_Border_flowersBlockPrint: return 128; + case NS_ooxml::LN_Value_ST_Border_flowersDaisies: return 129; + case NS_ooxml::LN_Value_ST_Border_flowersModern1: return 130; + case NS_ooxml::LN_Value_ST_Border_flowersModern2: return 131; + case NS_ooxml::LN_Value_ST_Border_flowersPansy: return 132; + case NS_ooxml::LN_Value_ST_Border_flowersRedRose: return 133; + case NS_ooxml::LN_Value_ST_Border_flowersRoses: return 134; + case NS_ooxml::LN_Value_ST_Border_flowersTeacup: return 135; + case NS_ooxml::LN_Value_ST_Border_flowersTiny: return 136; + case NS_ooxml::LN_Value_ST_Border_gems: return 137; + case NS_ooxml::LN_Value_ST_Border_gingerbreadMan: return 138; + case NS_ooxml::LN_Value_ST_Border_gradient: return 139; + case NS_ooxml::LN_Value_ST_Border_handmade1: return 140; + case NS_ooxml::LN_Value_ST_Border_handmade2: return 141; + case NS_ooxml::LN_Value_ST_Border_heartBalloon: return 142; + case NS_ooxml::LN_Value_ST_Border_heartGray: return 143; + case NS_ooxml::LN_Value_ST_Border_hearts: return 144; + case NS_ooxml::LN_Value_ST_Border_heebieJeebies: return 145; + case NS_ooxml::LN_Value_ST_Border_holly: return 146; + case NS_ooxml::LN_Value_ST_Border_houseFunky: return 147; + case NS_ooxml::LN_Value_ST_Border_hypnotic: return 148; + case NS_ooxml::LN_Value_ST_Border_iceCreamCones: return 149; + case NS_ooxml::LN_Value_ST_Border_lightBulb: return 150; + case NS_ooxml::LN_Value_ST_Border_lightning1: return 151; + case NS_ooxml::LN_Value_ST_Border_lightning2: return 152; + case NS_ooxml::LN_Value_ST_Border_mapPins: return 153; + case NS_ooxml::LN_Value_ST_Border_mapleLeaf: return 154; + case NS_ooxml::LN_Value_ST_Border_mapleMuffins: return 155; + case NS_ooxml::LN_Value_ST_Border_marquee: return 156; + case NS_ooxml::LN_Value_ST_Border_marqueeToothed: return 157; + case NS_ooxml::LN_Value_ST_Border_moons: return 158; + case NS_ooxml::LN_Value_ST_Border_mosaic: return 159; + case NS_ooxml::LN_Value_ST_Border_musicNotes: return 160; + case NS_ooxml::LN_Value_ST_Border_northwest: return 161; + case NS_ooxml::LN_Value_ST_Border_ovals: return 162; + case NS_ooxml::LN_Value_ST_Border_packages: return 163; + case NS_ooxml::LN_Value_ST_Border_palmsBlack: return 164; + case NS_ooxml::LN_Value_ST_Border_palmsColor: return 165; + case NS_ooxml::LN_Value_ST_Border_paperClips: return 166; + case NS_ooxml::LN_Value_ST_Border_papyrus: return 167; + case NS_ooxml::LN_Value_ST_Border_partyFavor: return 168; + case NS_ooxml::LN_Value_ST_Border_partyGlass: return 169; + case NS_ooxml::LN_Value_ST_Border_pencils: return 170; + case NS_ooxml::LN_Value_ST_Border_people: return 171; + case NS_ooxml::LN_Value_ST_Border_peopleWaving: return 172; + case NS_ooxml::LN_Value_ST_Border_peopleHats: return 173; + case NS_ooxml::LN_Value_ST_Border_poinsettias: return 174; + case NS_ooxml::LN_Value_ST_Border_postageStamp: return 175; + case NS_ooxml::LN_Value_ST_Border_pumpkin1: return 176; + case NS_ooxml::LN_Value_ST_Border_pushPinNote2: return 177; + case NS_ooxml::LN_Value_ST_Border_pushPinNote1: return 178; + case NS_ooxml::LN_Value_ST_Border_pyramids: return 179; + case NS_ooxml::LN_Value_ST_Border_pyramidsAbove: return 180; + case NS_ooxml::LN_Value_ST_Border_quadrants: return 181; + case NS_ooxml::LN_Value_ST_Border_rings: return 182; + case NS_ooxml::LN_Value_ST_Border_safari: return 183; + case NS_ooxml::LN_Value_ST_Border_sawtooth: return 184; + case NS_ooxml::LN_Value_ST_Border_sawtoothGray: return 185; + case NS_ooxml::LN_Value_ST_Border_scaredCat: return 186; + case NS_ooxml::LN_Value_ST_Border_seattle: return 187; + case NS_ooxml::LN_Value_ST_Border_shadowedSquares: return 188; + case NS_ooxml::LN_Value_ST_Border_sharksTeeth: return 189; + case NS_ooxml::LN_Value_ST_Border_shorebirdTracks: return 190; + case NS_ooxml::LN_Value_ST_Border_skyrocket: return 191; + case NS_ooxml::LN_Value_ST_Border_snowflakeFancy: return 192; + case NS_ooxml::LN_Value_ST_Border_snowflakes: return 193; + case NS_ooxml::LN_Value_ST_Border_sombrero: return 194; + case NS_ooxml::LN_Value_ST_Border_southwest: return 195; + case NS_ooxml::LN_Value_ST_Border_stars: return 196; + case NS_ooxml::LN_Value_ST_Border_starsTop: return 197; + case NS_ooxml::LN_Value_ST_Border_stars3d: return 198; + case NS_ooxml::LN_Value_ST_Border_starsBlack: return 199; + case NS_ooxml::LN_Value_ST_Border_starsShadowed: return 200; + case NS_ooxml::LN_Value_ST_Border_sun: return 201; + case NS_ooxml::LN_Value_ST_Border_swirligig: return 202; + case NS_ooxml::LN_Value_ST_Border_tornPaper: return 203; + case NS_ooxml::LN_Value_ST_Border_tornPaperBlack: return 204; + case NS_ooxml::LN_Value_ST_Border_trees: return 205; + case NS_ooxml::LN_Value_ST_Border_triangleParty: return 206; + case NS_ooxml::LN_Value_ST_Border_triangles: return 207; + case NS_ooxml::LN_Value_ST_Border_tribal1: return 208; + case NS_ooxml::LN_Value_ST_Border_tribal2: return 209; + case NS_ooxml::LN_Value_ST_Border_tribal3: return 210; + case NS_ooxml::LN_Value_ST_Border_tribal4: return 211; + case NS_ooxml::LN_Value_ST_Border_tribal5: return 212; + case NS_ooxml::LN_Value_ST_Border_tribal6: return 213; + case NS_ooxml::LN_Value_ST_Border_twistedLines1: return 214; + case NS_ooxml::LN_Value_ST_Border_twistedLines2: return 215; + case NS_ooxml::LN_Value_ST_Border_vine: return 216; + case NS_ooxml::LN_Value_ST_Border_waveline: return 217; + case NS_ooxml::LN_Value_ST_Border_weavingAngles: return 218; + case NS_ooxml::LN_Value_ST_Border_weavingBraid: return 219; + case NS_ooxml::LN_Value_ST_Border_weavingRibbon: return 220; + case NS_ooxml::LN_Value_ST_Border_weavingStrips: return 221; + case NS_ooxml::LN_Value_ST_Border_whiteFlowers: return 222; + case NS_ooxml::LN_Value_ST_Border_woodwork: return 223; + case NS_ooxml::LN_Value_ST_Border_xIllusions: return 224; + case NS_ooxml::LN_Value_ST_Border_zanyTriangles: return 225; + case NS_ooxml::LN_Value_ST_Border_zigZag: return 226; + case NS_ooxml::LN_Value_ST_Border_zigZagStitch: return 227; + default: break; + } + return 0; +} + +void MakeBorderLine( sal_Int32 nLineThickness, sal_Int32 nLineToken, + sal_Int32 nLineColor, + table::BorderLine2& rToFill, bool bIsOOXML ) +{ + static const Color aBorderDefColor[] = + { + // The first item means automatic color (COL_AUTO), but we + // do not use it anyway (see the next statement) .-) + // See also GetLineIndex in sw/source/filter/ww8/ww8par6.cxx + COL_AUTO, COL_BLACK, COL_LIGHTBLUE, COL_LIGHTCYAN, COL_LIGHTGREEN, + COL_LIGHTMAGENTA, COL_LIGHTRED, COL_YELLOW, COL_WHITE, COL_BLUE, + COL_CYAN, COL_GREEN, COL_MAGENTA, COL_RED, COL_BROWN, COL_GRAY, + COL_LIGHTGRAY + }; + if(!bIsOOXML && sal::static_int_cast(nLineColor) < SAL_N_ELEMENTS(aBorderDefColor)) + nLineColor = sal_Int32(aBorderDefColor[nLineColor]); + //no auto color for borders + if (nLineColor == sal_Int32(COL_AUTO)) + nLineColor = sal_Int32(COL_BLACK); + + sal_Int32 nLineType = lcl_convertBorderStyleFromToken(nLineToken); + + // Map to our border types, we should use of one equal line + // thickness, or one of smaller thickness. If too small we + // can make the deficit up in additional white space or + // object size + SvxBorderLineStyle const nLineStyle( + ::editeng::ConvertBorderStyleFromWord(nLineType)); + rToFill.LineStyle = static_cast(nLineStyle); + double const fConverted( (SvxBorderLineStyle::NONE == nLineStyle) ? 0.0 : + ::editeng::ConvertBorderWidthFromWord(nLineStyle, nLineThickness, + nLineType)); + rToFill.LineWidth = convertTwipToMM100(fConverted); + rToFill.Color = nLineColor; +} + +namespace { +void lcl_SwapQuotesInField(OUString &rFmt) +{ + //Swap unescaped " and ' with ' and " + sal_Int32 nLen = rFmt.getLength(); + OUStringBuffer aBuffer( rFmt ); + const sal_Unicode* pFmt = rFmt.getStr(); + for (sal_Int32 nI = 0; nI < nLen; ++nI) + { + if ((pFmt[nI] == '\"') && (!nI || pFmt[nI-1] != '\\')) + aBuffer[nI] = '\''; + else if ((pFmt[nI] == '\'') && (!nI || pFmt[nI-1] != '\\')) + aBuffer[nI] = '\"'; + } + rFmt = aBuffer.makeStringAndClear(); +} +bool lcl_IsNotAM(OUString const & rFmt, sal_Int32 nPos) +{ + return ( + (nPos == rFmt.getLength() - 1) || + ( + (rFmt[nPos+1] != 'M') && + (rFmt[nPos+1] != 'm') + ) + ); +} +} + +OUString ConvertMSFormatStringToSO( + const OUString& rFormat, lang::Locale& rLocale, bool bHijri) +{ + OUString sFormat(rFormat); + lcl_SwapQuotesInField(sFormat); + + //#102782#, #102815#, #108341# & #111944# have to work at the same time :-) + bool bForceJapanese(false); + bool bForceNatNum(false); + sal_Int32 nLen = sFormat.getLength(); + sal_Int32 nI = 0; +// const sal_Unicode* pFormat = sFormat.getStr(); + OUStringBuffer aNewFormat( sFormat ); + while (nI < nLen) + { + if (aNewFormat[nI] == '\\') + nI++; + else if (aNewFormat[nI] == '\"') + { + ++nI; + //While not at the end and not at an unescaped end quote + while ((nI < nLen) && ((aNewFormat[nI] != '\"') && (aNewFormat[nI-1] != '\\'))) + ++nI; + } + else //normal unquoted section + { + sal_Unicode nChar = aNewFormat[nI]; + if (nChar == 'O') + { + aNewFormat[nI] = 'M'; + bForceNatNum = true; + } + else if (nChar == 'o') + { + aNewFormat[nI] = 'm'; + bForceNatNum = true; + } + else if ((nChar == 'A') && lcl_IsNotAM(sFormat, nI)) + { + aNewFormat[nI] = 'D'; + bForceNatNum = true; + } + else if ((nChar == 'g') || (nChar == 'G')) + bForceJapanese = true; + else if ((nChar == 'a') && lcl_IsNotAM(sFormat, nI)) + bForceJapanese = true; + else if (nChar == 'E') + { + if ((nI != nLen-1) && (aNewFormat[nI+1] == 'E')) + { + //todo: this cannot be the right way to replace a part of the string! + aNewFormat[nI] = 'Y'; + aNewFormat[nI + 1] = 'Y'; + aNewFormat.insert(nI + 2, "YY"); + nLen+=2; + nI+=3; + } + bForceJapanese = true; + } + else if (nChar == 'e') + { + if ((nI != nLen-1) && (aNewFormat[nI+1] == 'e')) + { + //todo: this cannot be the right way to replace a part of the string! + aNewFormat[nI] = 'y'; + aNewFormat[nI + 1] = 'y'; + aNewFormat.insert(nI + 2, "yy"); + nLen+=2; + nI+=3; + } + bForceJapanese = true; + } + else if (nChar == '/') + { + // MM We have to escape '/' in case it's used as a char + //todo: this cannot be the right way to replace a part of the string! + aNewFormat[nI] = '\\'; + aNewFormat.insert(nI + 1, "/"); + nI++; + nLen++; + } + } + ++nI; + } + + if (bForceNatNum) + bForceJapanese = true; + + if (bForceJapanese) + { + rLocale.Language = "ja"; + rLocale.Country = "JP"; + } + + if (bForceNatNum) + { + aNewFormat.insert( 0, "[NatNum1][$-411]"); + } + + if (bHijri) + { + aNewFormat.insert( 0, "[~hijri]"); + } + return aNewFormat.makeStringAndClear(); + +} + +sal_Int32 convertTwipToMM100(sal_Int32 _t) +{ + // It appears that MSO handles large twip values specially, probably legacy 16bit handling, + // anything that's bigger than 32767 appears to be simply ignored. + if( _t >= 0x8000 ) + return 0; + return ::convertTwipToMm100( _t ); +} + +double convertTwipToMM100Double(sal_Int32 _t) +{ + // It appears that MSO handles large twip values specially, probably legacy 16bit handling, + // anything that's bigger than 32767 appears to be simply ignored. + if( _t >= 0x8000 ) + return 0.0; + return _t * 254.0 / 144.0; +} + +sal_uInt32 convertTwipToMM100Unsigned(sal_Int32 _t) +{ + if( _t < 0 ) + return 0; + return convertTwipToMM100( _t ); +} + +text::RubyAdjust convertRubyAlign( sal_Int32 nIntValue ) +{ + text::RubyAdjust rubyAdjust = text::RubyAdjust_LEFT; + switch( nIntValue ) + { + case NS_ooxml::LN_Value_ST_RubyAlign_center: + case NS_ooxml::LN_Value_ST_RubyAlign_rightVertical: + rubyAdjust = text::RubyAdjust_CENTER; + break; + case NS_ooxml::LN_Value_ST_RubyAlign_distributeLetter: + rubyAdjust = text::RubyAdjust_BLOCK; + break; + case NS_ooxml::LN_Value_ST_RubyAlign_distributeSpace: + rubyAdjust = text::RubyAdjust_INDENT_BLOCK; + break; + case NS_ooxml::LN_Value_ST_RubyAlign_left: + rubyAdjust = text::RubyAdjust_LEFT; + break; + case NS_ooxml::LN_Value_ST_RubyAlign_right: + rubyAdjust = text::RubyAdjust_RIGHT; + break; + } + return rubyAdjust; +} + +sal_Int16 convertTableJustification( sal_Int32 nIntValue ) +{ + sal_Int16 nOrient = text::HoriOrientation::LEFT_AND_WIDTH; + switch( nIntValue ) + { + case NS_ooxml::LN_Value_ST_Jc_center: + nOrient = text::HoriOrientation::CENTER; + break; + case NS_ooxml::LN_Value_ST_Jc_right: + case NS_ooxml::LN_Value_ST_Jc_end: + nOrient = text::HoriOrientation::RIGHT; + break; + case NS_ooxml::LN_Value_ST_Jc_left: + case NS_ooxml::LN_Value_ST_Jc_start: + //no break + default:; + + } + return nOrient; +} + +sal_Int16 ConvertNumberingType(sal_Int32 nFmt) +{ + sal_Int16 nRet; + switch(nFmt) + { + case NS_ooxml::LN_Value_ST_NumberFormat_decimal: + nRet = style::NumberingType::ARABIC; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_upperRoman: + nRet = style::NumberingType::ROMAN_UPPER; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman: + nRet = style::NumberingType::ROMAN_LOWER; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_ordinal: + nRet = style::NumberingType::TEXT_NUMBER; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_bullet: + nRet = style::NumberingType::CHAR_SPECIAL; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_none: + nRet = style::NumberingType::NUMBER_NONE; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_upperLetter: + nRet = style::NumberingType::CHARS_UPPER_LETTER_N; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter: + nRet = style::NumberingType::CHARS_LOWER_LETTER_N; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_iroha: + nRet = style::NumberingType::IROHA_HALFWIDTH_JA; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_irohaFullWidth: + nRet = style::NumberingType::IROHA_FULLWIDTH_JA; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_aiueo: + nRet = style::NumberingType::AIU_HALFWIDTH_JA; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_aiueoFullWidth: + nRet = style::NumberingType::AIU_FULLWIDTH_JA; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_hebrew2: + nRet = style::NumberingType::CHARS_HEBREW; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_thaiLetters: + nRet = style::NumberingType::CHARS_THAI; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_russianLower: + nRet = style::NumberingType::CHARS_CYRILLIC_LOWER_LETTER_RU; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_russianUpper: + nRet = style::NumberingType::CHARS_CYRILLIC_UPPER_LETTER_RU; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedCircleChinese: + case NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedCircle: + case NS_ooxml::LN_Value_ST_NumberFormat_ideographEnclosedCircle: + nRet = style::NumberingType::CIRCLE_NUMBER; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_ideographTraditional: + nRet = style::NumberingType::TIAN_GAN_ZH; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_ideographZodiac: + nRet = style::NumberingType::DI_ZI_ZH; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_ganada: + nRet = style::NumberingType::HANGUL_SYLLABLE_KO; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_chosung: + nRet = style::NumberingType::HANGUL_JAMO_KO; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_koreanLegal: + case NS_ooxml::LN_Value_ST_NumberFormat_koreanDigital: + case NS_ooxml::LN_Value_ST_NumberFormat_koreanCounting: + case NS_ooxml::LN_Value_ST_NumberFormat_koreanDigital2: + nRet = style::NumberingType::NUMBER_HANGUL_KO; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_ideographLegalTraditional: + nRet = style::NumberingType::NUMBER_UPPER_ZH_TW; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_arabicAlpha: + nRet = style::NumberingType::CHARS_ARABIC; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_hindiVowels: + nRet = style::NumberingType::CHARS_NEPALI; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_japaneseLegal: + nRet = style::NumberingType::NUMBER_TRADITIONAL_JA; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_chineseCounting: + case NS_ooxml::LN_Value_ST_NumberFormat_japaneseCounting: + case NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseCounting: + case NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseCountingThousand: + case NS_ooxml::LN_Value_ST_NumberFormat_ideographDigital: + case NS_ooxml::LN_Value_ST_NumberFormat_chineseCountingThousand: + nRet = style::NumberingType::NUMBER_LOWER_ZH; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_chineseLegalSimplified: + nRet = style::NumberingType::NUMBER_UPPER_ZH; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_hebrew1: + //91726 + nRet = style::NumberingType::NUMBER_HEBREW; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth: + case NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth2: + nRet = style::NumberingType::FULLWIDTH_ARABIC; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_cardinalText: + nRet = style::NumberingType::TEXT_CARDINAL; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_ordinalText: + nRet = style::NumberingType::TEXT_ORDINAL; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_chicago: + nRet = style::NumberingType::SYMBOL_CHICAGO; + break; + case NS_ooxml::LN_Value_ST_NumberFormat_decimalZero: + nRet = style::NumberingType::ARABIC_ZERO; + break; + default: nRet = style::NumberingType::ARABIC; + } +/* TODO: Lots of additional values are available - some are supported in the I18 framework + NS_ooxml::LN_Value_ST_NumberFormat_hex = 91685; + NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth = 91691; + NS_ooxml::LN_Value_ST_NumberFormat_decimalHalfWidth = 91692; + NS_ooxml::LN_Value_ST_NumberFormat_japaneseDigitalTenThousand = 91694; + NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedFullstop = 91703; + NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedParen = 91704; + NS_ooxml::LN_Value_ST_NumberFormat_ideographZodiacTraditional = 91709; + NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseDigital = 91713; + NS_ooxml::LN_Value_ST_NumberFormat_chineseLegalSimplified = 91715; + NS_ooxml::LN_Value_ST_NumberFormat_chineseCountingThousand = 91716; + NS_ooxml::LN_Value_ST_NumberFormat_koreanLegal = 91719; + NS_ooxml::LN_Value_ST_NumberFormat_vietnameseCounting = 91721; + NS_ooxml::LN_Value_ST_NumberFormat_numberInDash = 91725; + NS_ooxml::LN_Value_ST_NumberFormat_arabicAbjad: + NS_ooxml::LN_Value_ST_NumberFormat_hindiConsonants = 91731; + NS_ooxml::LN_Value_ST_NumberFormat_hindiNumbers = 91732; + NS_ooxml::LN_Value_ST_NumberFormat_hindiCounting = 91733; + NS_ooxml::LN_Value_ST_NumberFormat_thaiNumbers = 91735; + NS_ooxml::LN_Value_ST_NumberFormat_thaiCounting = 91736;*/ + return nRet; +} + +sal_Int16 ConvertCustomNumberFormat(const OUString& rFormat) +{ + sal_Int16 nRet = -1; + + if (rFormat == "001, 002, 003, ...") + { + nRet = style::NumberingType::ARABIC_ZERO3; + } + else if (rFormat == "0001, 0002, 0003, ...") + { + nRet = style::NumberingType::ARABIC_ZERO4; + } + else if (rFormat == "00001, 00002, 00003, ...") + { + nRet = style::NumberingType::ARABIC_ZERO5; + } + + return nRet; +} + +util::DateTime ConvertDateStringToDateTime( const OUString& rDateTime ) +{ + util::DateTime aDateTime; + //xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z + //OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const + sal_Int32 nIndex = 0; + OUString sDate = rDateTime.getToken( 0, 'T', nIndex ); + // HACK: this is broken according to the spec, but MSOffice always treats the time as local, + // and writes it as Z (=UTC+0) + OUString sTime = rDateTime.getToken( 0, 'Z', nIndex ); + nIndex = 0; + aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() ); + aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() ); + if (nIndex != -1) + aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() ); + + nIndex = 0; + aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() ); + aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() ); + if (nIndex != -1) + aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() ); + + return aDateTime; +} + + +} //namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/ConversionHelper.hxx b/writerfilter/source/dmapper/ConversionHelper.hxx new file mode 100644 index 000000000..707ac7424 --- /dev/null +++ b/writerfilter/source/dmapper/ConversionHelper.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_CONVERSIONHELPER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_CONVERSIONHELPER_HXX + +#include +#include +#include +#include +#include + +namespace com::sun::star{ + namespace lang{ + struct Locale; + } + namespace table{ + struct BorderLine2; + } +} + +namespace writerfilter { +namespace dmapper{ +namespace ConversionHelper{ + + // create a border line and return the distance value + void MakeBorderLine(sal_Int32 nLineThickness, + sal_Int32 nLineType, + sal_Int32 nLineColor, + css::table::BorderLine2& rToFill, + bool bIsOOXML); + //convert the number format string form MS format to SO format + OUString ConvertMSFormatStringToSO(const OUString& rFormat, css::lang::Locale& rLocale, bool bHijri); + // export just for test + SAL_DLLPUBLIC_EXPORT sal_Int32 convertTwipToMM100(sal_Int32 _t); + SAL_DLLPUBLIC_EXPORT double convertTwipToMM100Double(sal_Int32 _t); + SAL_DLLPUBLIC_EXPORT sal_uInt32 convertTwipToMM100Unsigned(sal_Int32 _t); + sal_Int16 convertTableJustification( sal_Int32 nIntValue ); + css::text::RubyAdjust convertRubyAlign( sal_Int32 nIntValue ); + sal_Int16 ConvertNumberingType(sal_Int32 nFmt); + sal_Int16 ConvertCustomNumberFormat(const OUString& rFormat); + + css::util::DateTime ConvertDateStringToDateTime(const OUString& rDateTime); +} // namespace ConversionHelper +} //namespace dmapper +} // namespace writerfilter +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx new file mode 100644 index 000000000..76fc96b9f --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -0,0 +1,4017 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "BorderHandler.hxx" +#include "PageBordersHandler.hxx" + +#include "util.hxx" +#include "SdtHelper.hxx" +#include "TagLogger.hxx" +#include "TDefTableHandler.hxx" +#include "DomainMapper_Impl.hxx" +#include "ConversionHelper.hxx" +#include "ModelEventListener.hxx" +#include "MeasureHandler.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "TextEffectsHandler.hxx" +#include "CellColorHandler.hxx" +#include "SectionColumnHandler.hxx" +#include "GraphicHelpers.hxx" +#include +#include +#include +#include + +using namespace ::com::sun::star; +using namespace oox; + +namespace writerfilter::dmapper{ + +struct +{ + sal_Int32 h; + bool orient; + sal_Int32 w; +} CT_PageSz; + + +DomainMapper::DomainMapper( const uno::Reference< uno::XComponentContext >& xContext, + uno::Reference const& xInputStream, + uno::Reference const& xModel, + bool bRepairStorage, + SourceDocumentType eDocumentType, + utl::MediaDescriptor const & rMediaDesc) : + LoggedProperties("DomainMapper"), + LoggedTable("DomainMapper"), + LoggedStream("DomainMapper"), + m_pImpl(new DomainMapper_Impl(*this, xContext, xModel, eDocumentType, rMediaDesc)), + mbIsSplitPara(false) + ,mbHasControls(false) +{ + // #i24363# tab stops relative to indent + m_pImpl->SetDocumentSettingsProperty( + getPropertyName( PROP_TABS_RELATIVE_TO_INDENT ), + uno::makeAny( false ) ); + m_pImpl->SetDocumentSettingsProperty( + getPropertyName( PROP_SURROUND_TEXT_WRAP_SMALL ), + uno::makeAny( true ) ); + m_pImpl->SetDocumentSettingsProperty( + getPropertyName( PROP_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING ), + uno::makeAny( true ) ); + + // Don't load the default style definitions to avoid weird mix + m_pImpl->SetDocumentSettingsProperty("StylesNoDefault", uno::makeAny(true)); + m_pImpl->SetDocumentSettingsProperty("MsWordCompTrailingBlanks", uno::makeAny(true)); + m_pImpl->SetDocumentSettingsProperty("HeaderSpacingBelowLastPara", + uno::makeAny(true)); + + m_pImpl->SetDocumentSettingsProperty("TabAtLeftIndentForParagraphsInList", uno::makeAny(true)); + + // Initialize RDF metadata, to be able to add statements during the import. + try + { + uno::Reference xDocumentMetadataAccess(xModel, uno::UNO_QUERY_THROW); + uno::Reference xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); + OUString aBaseURL = rMediaDesc.getUnpackedValueOrDefault("URL", OUString()); + const uno::Reference xModel_(xModel, + uno::UNO_QUERY_THROW); + const uno::Reference xBaseURI(sfx2::createBaseURI(xContext, xModel_, aBaseURL, OUString())); + const uno::Reference xHandler; + xDocumentMetadataAccess->loadMetadataFromStorage(xStorage, xBaseURI, xHandler); + } + catch (const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "failed to initialize RDF metadata"); + } + + if (eDocumentType == SourceDocumentType::OOXML) { + // tdf#108350 + // In Word since version 2007, the default document font is Calibri 11 pt. + // If a DOCX document doesn't contain font information, we should assume + // the intended font to provide best layout match. + try + { + uno::Reference< beans::XPropertySet > xDefProps(GetTextFactory()->createInstance("com.sun.star.text.Defaults"), + uno::UNO_QUERY_THROW); + xDefProps->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), css::uno::Any(OUString("Calibri"))); + xDefProps->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT), css::uno::Any(double(11))); + } + catch (const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "failed to initialize default font"); + } + } + + //import document properties + try + { + uno::Reference< embed::XStorage > xDocumentStorage = + comphelper::OStorageHelper::GetStorageOfFormatFromInputStream(OFOPXML_STORAGE_FORMAT_STRING, xInputStream, xContext, bRepairStorage ); + + uno::Reference< uno::XInterface > xTemp = xContext->getServiceManager()->createInstanceWithContext( + "com.sun.star.document.OOXMLDocumentPropertiesImporter", + xContext); + + uno::Reference< document::XOOXMLDocumentPropertiesImporter > xImporter( xTemp, uno::UNO_QUERY_THROW ); + uno::Reference< document::XDocumentPropertiesSupplier > xPropSupplier( xModel, uno::UNO_QUERY_THROW); + xImporter->importProperties( xDocumentStorage, xPropSupplier->getDocumentProperties() ); + } + catch( const uno::Exception& ) {} +} + +DomainMapper::~DomainMapper() +{ + try + { + uno::Reference< text::XDocumentIndexesSupplier> xIndexesSupplier( m_pImpl->GetTextDocument(), uno::UNO_QUERY ); + sal_Int32 nIndexes = 0; + if( xIndexesSupplier.is() ) + { + uno::Reference< container::XIndexAccess > xIndexes = xIndexesSupplier->getDocumentIndexes(); + nIndexes = xIndexes->getCount(); + } + // If we have page references, those need updating as well, similar to the indexes. + uno::Reference xTextFieldsSupplier(m_pImpl->GetTextDocument(), uno::UNO_QUERY); + if(xTextFieldsSupplier.is()) + { + uno::Reference xEnumeration = xTextFieldsSupplier->getTextFields()->createEnumeration(); + while(xEnumeration->hasMoreElements()) + { + ++nIndexes; + xEnumeration->nextElement(); + } + } + + mbHasControls |= m_pImpl->m_pSdtHelper->hasElements(); + if ( nIndexes || mbHasControls ) + { + //index update has to wait until first view is created + uno::Reference< document::XEventBroadcaster > xBroadcaster(xIndexesSupplier, uno::UNO_QUERY); + if (xBroadcaster.is()) + xBroadcaster->addEventListener(uno::Reference< document::XEventListener >(new ModelEventListener(nIndexes, mbHasControls))); + } + + + // Apply the document settings after everything else + m_pImpl->GetSettingsTable()->ApplyProperties( m_pImpl->GetTextDocument( ) ); + + // now that importing is finished, re-enable default styles for any that were never defined/imported. + m_pImpl->SetDocumentSettingsProperty("StylesNoDefault", uno::makeAny(false)); + + // Grab-bag handling + comphelper::SequenceAsHashMap aProperties; + + // Add the saved w:themeFontLang setting + aProperties["ThemeFontLangProps"] <<= m_pImpl->GetSettingsTable()->GetThemeFontLangProperties(); + + // Add the saved compat settings + aProperties["CompatSettings"] <<= m_pImpl->GetSettingsTable()->GetCompatSettings(); + + // Add the saved DocumentProtection settings + aProperties["DocumentProtection"] <<= m_pImpl->GetSettingsTable()->GetDocumentProtectionSettings(); + + // Add the saved w:hypenationZone setting + aProperties["HyphenationZone"] <<= m_pImpl->GetSettingsTable()->GetHypenationZone(); + + // Add the saved w:doNotHyphenateCaps setting + aProperties["NoHyphenateCaps"] <<= m_pImpl->GetSettingsTable()->GetNoHyphenateCaps(); + + uno::Reference xDocProps(m_pImpl->GetTextDocument(), uno::UNO_QUERY); + if (xDocProps.is()) + { + comphelper::SequenceAsHashMap aGrabBag(xDocProps->getPropertyValue("InteropGrabBag")); + aGrabBag.update(aProperties); + xDocProps->setPropertyValue("InteropGrabBag", uno::Any(aGrabBag.getAsConstPropertyValueList())); + } + } + catch( const uno::Exception& ) {} + +#ifdef DBG_UTIL + TagLogger::getInstance().endDocument(); +#endif +} + +void DomainMapper::lcl_attribute(Id nName, Value & val) +{ + if (m_pImpl->hasTableManager() && m_pImpl->getTableManager().attribute(nName, val)) + return; + + static const int nSingleLineSpacing = 240; + sal_Int32 nIntValue = val.getInt(); + OUString sStringValue = val.getString(); + + SectionPropertyMap * pSectionContext = m_pImpl->GetSectionContext(); + switch( nName ) + { + case NS_ooxml::LN_CT_Lvl_start: + break; + case NS_ooxml::LN_CT_Lvl_numFmt: + break; + case NS_ooxml::LN_CT_Lvl_isLgl: + break; + case NS_ooxml::LN_CT_Lvl_legacy: + break; + case NS_ooxml::LN_CT_AbstractNum_nsid: + break; + case NS_ooxml::LN_CT_AbstractNum_tmpl: + break; + case NS_ooxml::LN_CT_Border_sz: + break; + case NS_ooxml::LN_CT_Border_val: + break; + case NS_ooxml::LN_CT_Border_space: + break; + case NS_ooxml::LN_CT_Border_shadow: + break; + case NS_ooxml::LN_CT_Border_frame: + break; + case NS_ooxml::LN_headerr: + break; + case NS_ooxml::LN_footerr: + break; + case NS_ooxml::LN_endnote: + break; + case NS_ooxml::LN_CT_Bookmark_name: + m_pImpl->SetBookmarkName( sStringValue ); + break; + case NS_ooxml::LN_CT_MarkupRangeBookmark_id: + // add a bookmark range -- this remembers a bookmark starting here + // or, if the bookmark was already started or, if the bookmark was + // already started before, writes out the bookmark + m_pImpl->StartOrEndBookmark( sStringValue ); + break; + case NS_ooxml::LN_CT_MarkupRange_displacedByCustomXml: + break; + case NS_ooxml::LN_NUMBERING: + break; + case NS_ooxml::LN_FONTTABLE: + break; + case NS_ooxml::LN_STYLESHEET: + break; + + case NS_ooxml::LN_CT_Sym_char: + m_pImpl->SetSymbolChar(nIntValue); + break; + case NS_ooxml::LN_CT_Sym_font: + m_pImpl->SetSymbolFont(sStringValue); + break; + case NS_ooxml::LN_CT_Underline_val: + if (m_pImpl->GetTopContext()) + handleUnderlineType(nIntValue, m_pImpl->GetTopContext()); + break; + case NS_ooxml::LN_CT_Color_val: + if (m_pImpl->GetTopContext()) + m_pImpl->GetTopContext()->Insert(PROP_CHAR_COLOR, uno::makeAny( nIntValue ) ); + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "val", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue))); + break; + case NS_ooxml::LN_CT_Underline_color: + if (m_pImpl->GetTopContext()) + { + m_pImpl->GetTopContext()->Insert(PROP_CHAR_UNDERLINE_HAS_COLOR, uno::makeAny( true ) ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_UNDERLINE_COLOR, uno::makeAny( nIntValue ) ); + } + break; + + case NS_ooxml::LN_CT_TabStop_val: + if (sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_ST_TabJc_clear) + { + m_pImpl->m_aCurrentTabStop.bDeleted = true; + } + else + { + m_pImpl->m_aCurrentTabStop.bDeleted = false; + m_pImpl->m_aCurrentTabStop.Alignment = getTabAlignFromValue(nIntValue); + } + break; + case NS_ooxml::LN_CT_TabStop_leader: + m_pImpl->m_aCurrentTabStop.FillChar = getFillCharFromValue(nIntValue); + break; + case NS_ooxml::LN_CT_TabStop_pos: + m_pImpl->m_aCurrentTabStop.Position = ConversionHelper::convertTwipToMM100(nIntValue); + break; + + case NS_ooxml::LN_CT_Fonts_ascii: + if (m_pImpl->GetTopContext()) + { + m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sStringValue )); + if (m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH) && m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)->isSet(PROP_NUMBERING_RULES)) + { + // Font of the paragraph mark should be used for the numbering as well. + uno::Reference xCharStyle(m_pImpl->GetCurrentNumberingCharStyle()); + if (xCharStyle.is()) + xCharStyle->setPropertyValue("CharFontName", uno::makeAny(sStringValue)); + } + } + break; + case NS_ooxml::LN_CT_Fonts_asciiTheme: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "asciiTheme", ThemeTable::getStringForTheme(nIntValue)); + if (m_pImpl->GetTopContext()) + { + uno::Any aPropValue = uno::makeAny( m_pImpl->GetThemeTable()->getFontNameForTheme( nIntValue ) ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME, aPropValue ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_FONT_NAME_ASCII, aPropValue, true, CHAR_GRAB_BAG ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_NAME_ASCII, uno::makeAny( ThemeTable::getStringForTheme(nIntValue) ), true, CHAR_GRAB_BAG); + } + break; + case NS_ooxml::LN_CT_Fonts_hAnsi: + break;//unsupported + case NS_ooxml::LN_CT_Fonts_hAnsiTheme: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "hAnsiTheme", ThemeTable::getStringForTheme(nIntValue)); + if (m_pImpl->GetTopContext()) + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_NAME_H_ANSI, uno::makeAny( ThemeTable::getStringForTheme(nIntValue) ), true, CHAR_GRAB_BAG); + break; + case NS_ooxml::LN_CT_Fonts_eastAsia: + if (m_pImpl->GetTopContext()) + m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( sStringValue )); + break; + case NS_ooxml::LN_CT_Fonts_eastAsiaTheme: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "eastAsiaTheme", ThemeTable::getStringForTheme(nIntValue)); + if (m_pImpl->GetTopContext()) + { + uno::Any aPropValue = uno::makeAny( m_pImpl->GetThemeTable()->getFontNameForTheme( nIntValue ) ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME_ASIAN, aPropValue ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_FONT_NAME_EAST_ASIA, aPropValue, true, CHAR_GRAB_BAG ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_NAME_EAST_ASIA, uno::makeAny( ThemeTable::getStringForTheme(nIntValue) ), true, CHAR_GRAB_BAG); + } + break; + case NS_ooxml::LN_CT_Fonts_cs: + if (m_pImpl->GetTopContext()) + m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME_COMPLEX, uno::makeAny( sStringValue )); + break; + case NS_ooxml::LN_CT_Fonts_cstheme: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "cstheme", ThemeTable::getStringForTheme(nIntValue)); + if (m_pImpl->GetTopContext()) + { + uno::Any aPropValue = uno::makeAny( m_pImpl->GetThemeTable()->getFontNameForTheme( nIntValue ) ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_FONT_NAME_COMPLEX, aPropValue ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_FONT_NAME_CS, aPropValue, true, CHAR_GRAB_BAG ); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_NAME_CS, uno::makeAny( ThemeTable::getStringForTheme(nIntValue) ), true, CHAR_GRAB_BAG); + } + break; + case NS_ooxml::LN_CT_Spacing_before: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "before", OUString::number(nIntValue)); + if (m_pImpl->GetTopContext()) + // Don't overwrite NS_ooxml::LN_CT_Spacing_beforeAutospacing. + m_pImpl->GetTopContext()->Insert( + PROP_PARA_TOP_MARGIN, + uno::makeAny(static_cast(convertTwipToMm100(nIntValue))), false); + break; + case NS_ooxml::LN_CT_Spacing_beforeLines: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "beforeLines", OUString::number(nIntValue)); + // We would need to make sure that this doesn't overwrite any + // NS_ooxml::LN_CT_Spacing_before in parent styles before style + // sheet support can be enabled. + if (m_pImpl->GetTopContext() && !IsStyleSheetImport()) + m_pImpl->GetTopContext()->Insert(PROP_PARA_TOP_MARGIN, uno::makeAny(ConversionHelper::convertTwipToMM100(nIntValue * nSingleLineSpacing / 100)), false); + break; + case NS_ooxml::LN_CT_Spacing_after: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "after", OUString::number(nIntValue)); + if (m_pImpl->GetTopContext()) + { + // Don't overwrite NS_ooxml::LN_CT_Spacing_afterAutospacing. + m_pImpl->GetTopContext()->Insert(PROP_PARA_BOTTOM_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100( nIntValue ) ), false); + + uno::Any aContextualSpacingFromStyle = m_pImpl->GetPropertyFromParaStyleSheet(PROP_PARA_CONTEXT_MARGIN); + if (aContextualSpacingFromStyle.hasValue()) + // Setting "after" spacing means Writer doesn't inherit + // contextual spacing anymore from style, but Word does. + m_pImpl->GetTopContext()->Insert(PROP_PARA_CONTEXT_MARGIN, aContextualSpacingFromStyle); + } + break; + case NS_ooxml::LN_CT_Spacing_afterLines: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "afterLines", OUString::number(nIntValue)); + // We would need to make sure that this doesn't overwrite any + // NS_ooxml::LN_CT_Spacing_after in parent styles before style + // sheet support can be enabled. + if (m_pImpl->GetTopContext() && !IsStyleSheetImport()) + m_pImpl->GetTopContext()->Insert(PROP_PARA_BOTTOM_MARGIN, uno::makeAny(ConversionHelper::convertTwipToMM100(nIntValue * nSingleLineSpacing / 100)), false); + break; + case NS_ooxml::LN_CT_Spacing_line: //91434 + case NS_ooxml::LN_CT_Spacing_lineRule: //91435 + { + style::LineSpacing aSpacing; + PropertyMapPtr pTopContext = m_pImpl->GetTopContext(); + std::optional aLineSpacingVal; + if (pTopContext && (aLineSpacingVal = pTopContext->getProperty(PROP_PARA_LINE_SPACING)) ) + { + aLineSpacingVal->second >>= aSpacing; + } + else + { + //default to single line spacing + aSpacing.Mode = style::LineSpacingMode::FIX; + aSpacing.Height = sal_Int16(ConversionHelper::convertTwipToMM100( nSingleLineSpacing )); + } + if( nName == NS_ooxml::LN_CT_Spacing_line ) + { + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "line", OUString::number(nIntValue)); + //now set the value depending on the Mode + if( aSpacing.Mode == style::LineSpacingMode::PROP ) + aSpacing.Height = sal_Int16(nIntValue * 100 / nSingleLineSpacing ); + else + aSpacing.Height = sal_Int16(ConversionHelper::convertTwipToMM100( nIntValue )); + } + else //NS_ooxml::LN_CT_Spacing_lineRule: + { + // exactly, atLeast, auto + if( sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_LineSpacingRule_auto) + { + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "lineRule", "auto"); + if (aSpacing.Height >= 0) + { + aSpacing.Mode = style::LineSpacingMode::PROP; + //reinterpret the already set value + aSpacing.Height = sal_Int16( aSpacing.Height * 100 / ConversionHelper::convertTwipToMM100( nSingleLineSpacing )); + } + else + { + // Negative value still means a positive height, + // just the mode is "exact". + aSpacing.Mode = style::LineSpacingMode::FIX; + aSpacing.Height *= -1; + } + } + else if( sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_LineSpacingRule_atLeast) + { + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "lineRule", "atLeast"); + aSpacing.Mode = style::LineSpacingMode::MINIMUM; + } + else // NS_ooxml::LN_Value_doc_ST_LineSpacingRule_exact + { + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "lineRule", "exact"); + aSpacing.Mode = style::LineSpacingMode::FIX; + } + } + if (pTopContext) + pTopContext->Insert(PROP_PARA_LINE_SPACING, uno::makeAny( aSpacing )); + } + break; + case NS_ooxml::LN_CT_Ind_start: + case NS_ooxml::LN_CT_Ind_left: + if (m_pImpl->GetTopContext()) + { + // Word inherits FirstLineIndent property of the numbering, even if ParaLeftMargin is set, Writer does not. + // So copy it explicitly, if necessary. + sal_Int32 nFirstLineIndent = m_pImpl->getCurrentNumberingProperty("FirstLineIndent"); + sal_Int32 nIndentAt = m_pImpl->getCurrentNumberingProperty("IndentAt"); + + sal_Int32 nParaLeftMargin = ConversionHelper::convertTwipToMM100(nIntValue); + if (nParaLeftMargin != 0 && nIndentAt == nParaLeftMargin) + // Avoid direct left margin when it's the same as from the + // numbering. + break; + + if (nFirstLineIndent != 0) + m_pImpl->GetTopContext()->Insert(PROP_PARA_FIRST_LINE_INDENT, uno::makeAny(nFirstLineIndent), /*bOverwrite=*/false); + + m_pImpl->GetTopContext()->Insert(PROP_PARA_LEFT_MARGIN, + uno::makeAny(nParaLeftMargin)); + } + break; + case NS_ooxml::LN_CT_Ind_end: + case NS_ooxml::LN_CT_Ind_right: + if (m_pImpl->GetTopContext()) + { + // Word inherits FirstLineIndent/ParaLeftMargin property of the numbering, even if ParaRightMargin is set, Writer does not. + // So copy it explicitly, if necessary. + sal_Int32 nFirstLineIndent = m_pImpl->getCurrentNumberingProperty("FirstLineIndent"); + sal_Int32 nParaLeftMargin = m_pImpl->getCurrentNumberingProperty("IndentAt"); + + if (nFirstLineIndent != 0) + m_pImpl->GetTopContext()->Insert(PROP_PARA_FIRST_LINE_INDENT, uno::makeAny(nFirstLineIndent), /*bOverwrite=*/false); + if (nParaLeftMargin != 0) + m_pImpl->GetTopContext()->Insert(PROP_PARA_LEFT_MARGIN, uno::makeAny(nParaLeftMargin), /*bOverwrite=*/false); + + m_pImpl->GetTopContext()->Insert( + PROP_PARA_RIGHT_MARGIN, uno::makeAny( ConversionHelper::convertTwipToMM100(nIntValue ) )); + } + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "right", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Ind_hanging: + if (m_pImpl->GetTopContext()) + { + sal_Int32 nValue = ConversionHelper::convertTwipToMM100( nIntValue ); + m_pImpl->GetTopContext()->Insert( + PROP_PARA_FIRST_LINE_INDENT, uno::makeAny( - nValue )); + + // See above, need to inherit left margin from list style when first is set. + sal_Int32 nParaLeftMargin = m_pImpl->getCurrentNumberingProperty("IndentAt"); + if (nParaLeftMargin != 0) + m_pImpl->GetTopContext()->Insert(PROP_PARA_LEFT_MARGIN, uno::makeAny(nParaLeftMargin), /*bOverwrite=*/false); + } + break; + case NS_ooxml::LN_CT_Ind_firstLine: + if (m_pImpl->GetTopContext()) + { + sal_Int32 nFirstLineIndent + = m_pImpl->getCurrentNumberingProperty("FirstLineIndent"); + sal_Int32 nParaFirstLineIndent = ConversionHelper::convertTwipToMM100(nIntValue); + if (nParaFirstLineIndent != 0 && nFirstLineIndent == nParaFirstLineIndent) + // Avoid direct first margin when it's the same as from the + // numbering. + break; + m_pImpl->GetTopContext()->Insert(PROP_PARA_FIRST_LINE_INDENT, + uno::makeAny(nParaFirstLineIndent)); + } + break; + case NS_ooxml::LN_CT_Ind_rightChars: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "rightChars", OUString::number(nIntValue)); + break; + + case NS_ooxml::LN_CT_EastAsianLayout_id: + break; + case NS_ooxml::LN_CT_EastAsianLayout_combine: + if (m_pImpl->GetTopContext()) + m_pImpl->GetTopContext()->Insert(PROP_CHAR_COMBINE_IS_ON, uno::makeAny ( nIntValue != 0 )); + break; + case NS_ooxml::LN_CT_EastAsianLayout_combineBrackets: + if (m_pImpl->GetTopContext()) + { + OUString sCombinePrefix = getBracketStringFromEnum(nIntValue); + OUString sCombineSuffix = getBracketStringFromEnum(nIntValue, false); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_COMBINE_PREFIX, uno::makeAny ( sCombinePrefix )); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_COMBINE_SUFFIX, uno::makeAny ( sCombineSuffix )); + } + break; + case NS_ooxml::LN_CT_EastAsianLayout_vert: + if (m_pImpl->GetTopContext()) + { + sal_Int16 nRotationAngle = (nIntValue ? 900 : 0); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_ROTATION, uno::makeAny ( nRotationAngle )); + } + break; + case NS_ooxml::LN_CT_EastAsianLayout_vertCompress: + if (m_pImpl->GetTopContext()) + m_pImpl->GetTopContext()->Insert(PROP_CHAR_ROTATION_IS_FIT_TO_LINE, uno::makeAny ( nIntValue != 0 )); + break; + + case NS_ooxml::LN_CT_PageSz_code: + break; + case NS_ooxml::LN_CT_PageSz_h: + { + sal_Int32 nHeight = ConversionHelper::convertTwipToMM100(nIntValue); + CT_PageSz.h = PaperInfo::sloppyFitPageDimension(nHeight); + } + break; + case NS_ooxml::LN_CT_PageSz_orient: + CT_PageSz.orient = (nIntValue != static_cast(NS_ooxml::LN_Value_ST_PageOrientation_portrait)); + break; + case NS_ooxml::LN_CT_PageSz_w: + { + sal_Int32 nWidth = ConversionHelper::convertTwipToMM100(nIntValue); + CT_PageSz.w = PaperInfo::sloppyFitPageDimension(nWidth); + } + break; + + case NS_ooxml::LN_CT_PageMar_top: + m_pImpl->SetPageMarginTwip( PAGE_MAR_TOP, nIntValue ); + break; + case NS_ooxml::LN_CT_PageMar_right: + m_pImpl->SetPageMarginTwip( PAGE_MAR_RIGHT, nIntValue ); + break; + case NS_ooxml::LN_CT_PageMar_bottom: + m_pImpl->SetPageMarginTwip( PAGE_MAR_BOTTOM, nIntValue ); + break; + case NS_ooxml::LN_CT_PageMar_left: + m_pImpl->SetPageMarginTwip( PAGE_MAR_LEFT, nIntValue ); + break; + case NS_ooxml::LN_CT_PageMar_header: + m_pImpl->SetPageMarginTwip( PAGE_MAR_HEADER, nIntValue ); + break; + case NS_ooxml::LN_CT_PageMar_footer: + m_pImpl->SetPageMarginTwip( PAGE_MAR_FOOTER, nIntValue ); + break; + case NS_ooxml::LN_CT_PageMar_gutter: + m_pImpl->SetPageMarginTwip( PAGE_MAR_GUTTER, nIntValue ); + break; + case NS_ooxml::LN_CT_Language_val: //90314 + case NS_ooxml::LN_CT_Language_eastAsia: //90315 + case NS_ooxml::LN_CT_Language_bidi: //90316 + { + if (nName == NS_ooxml::LN_CT_Language_eastAsia) + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "eastAsia", sStringValue); + else if (nName == NS_ooxml::LN_CT_Language_val) + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "val", sStringValue); + else if (nName == NS_ooxml::LN_CT_Language_bidi) + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "bidi", sStringValue); + lang::Locale aLocale( LanguageTag::convertToLocale( sStringValue)); + if (m_pImpl->GetTopContext()) + m_pImpl->GetTopContext()->Insert(NS_ooxml::LN_CT_Language_val== nName ? PROP_CHAR_LOCALE : + NS_ooxml::LN_CT_Language_eastAsia == nName ? PROP_CHAR_LOCALE_ASIAN : PROP_CHAR_LOCALE_COMPLEX, + uno::makeAny( aLocale ) ); + } + break; + // See SwWW8ImplReader::GetParagraphAutoSpace() on why these are 100 and 280 + case NS_ooxml::LN_CT_Spacing_beforeAutospacing: + { + sal_Int32 default_spacing = -1; + if (nIntValue) + { + m_pImpl->SetParaAutoBefore(true); + + default_spacing = 100; + if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing()) + { + // 49 is just the old value that should be removed, once the + // root cause in SwTabFrm::MakeAll() is fixed. + if (m_pImpl->GetSettingsTable()->GetView() == NS_ooxml::LN_Value_doc_ST_View_web) + default_spacing = 49; + else + default_spacing = 280; + } + // required at export (here mainly for StyleSheets) to determine if the setting has changed from grab_bag + m_pImpl->GetTopContext()->Insert(PROP_PARA_TOP_MARGIN, uno::makeAny(ConversionHelper::convertTwipToMM100(default_spacing))); + } + m_pImpl->GetTopContext()->Insert( PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING, uno::makeAny( ConversionHelper::convertTwipToMM100(default_spacing) ),true, PARA_GRAB_BAG ); + } + break; + case NS_ooxml::LN_CT_Spacing_afterAutospacing: + { + sal_Int32 default_spacing = -1; + if (nIntValue) + { + default_spacing = 100; + if (!m_pImpl->GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing()) + { + if (m_pImpl->GetSettingsTable()->GetView() == NS_ooxml::LN_Value_doc_ST_View_web) + default_spacing = 49; + else + default_spacing = 280; + } + m_pImpl->GetTopContext()->Insert(PROP_PARA_BOTTOM_MARGIN, uno::makeAny(ConversionHelper::convertTwipToMM100(default_spacing))); + } + m_pImpl->GetTopContext()->Insert( PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING, uno::makeAny( ConversionHelper::convertTwipToMM100(default_spacing) ),true, PARA_GRAB_BAG ); + } + break; + case NS_ooxml::LN_CT_SmartTagRun_uri: + m_pImpl->getSmartTagHandler().setURI(val.getString()); + break; + case NS_ooxml::LN_CT_SmartTagRun_element: + m_pImpl->getSmartTagHandler().setElement(val.getString()); + break; + case NS_ooxml::LN_CT_Br_type : + //TODO: attributes for break (0x12) are not supported + break; + case NS_ooxml::LN_CT_Fonts_hint : + /* assigns script type to ambiguous characters, values can be: + NS_ooxml::LN_Value_ST_Hint_default + NS_ooxml::LN_Value_ST_Hint_eastAsia + NS_ooxml::LN_Value_ST_Hint_cs + */ + //TODO: unsupported? + break; + case NS_ooxml::LN_CT_TblBorders_right: + case NS_ooxml::LN_CT_TblBorders_top: + case NS_ooxml::LN_CT_TblBorders_left: + case NS_ooxml::LN_CT_TblBorders_bottom: + //todo: handle cell mar + break; + case NS_ooxml::LN_blip: // contains the binary graphic + case NS_ooxml::LN_shape: + { + //looks a bit like a hack - and it is. The graphic import is split into the inline_inline part and + //afterwards the adding of the binary data. + m_pImpl->GetGraphicImport( IMPORT_AS_DETECTED_INLINE )->attribute(nName, val); + m_pImpl->ImportGraphic( val.getProperties(), IMPORT_AS_DETECTED_INLINE ); + } + break; + case NS_ooxml::LN_Value_math_ST_Jc_centerGroup: + case NS_ooxml::LN_Value_math_ST_Jc_center: + m_pImpl->appendStarMath(val); + m_pImpl->adjustLastPara(sal_Int8(style::ParagraphAdjust::ParagraphAdjust_CENTER)); + break; + case NS_ooxml::LN_Value_math_ST_Jc_left: + m_pImpl->appendStarMath(val); + m_pImpl->adjustLastPara(sal_Int8(style::ParagraphAdjust::ParagraphAdjust_LEFT)); + break; + case NS_ooxml::LN_Value_math_ST_Jc_right: + m_pImpl->appendStarMath(val); + m_pImpl->adjustLastPara(sal_Int8(style::ParagraphAdjust::ParagraphAdjust_RIGHT)); + break; + case NS_ooxml::LN_starmath: + m_pImpl->appendStarMath(val); + break; + case NS_ooxml::LN_CT_FramePr_dropCap: + case NS_ooxml::LN_CT_FramePr_lines: + case NS_ooxml::LN_CT_FramePr_hAnchor: + case NS_ooxml::LN_CT_FramePr_vAnchor: + case NS_ooxml::LN_CT_FramePr_x: + case NS_ooxml::LN_CT_FramePr_xAlign: + case NS_ooxml::LN_CT_FramePr_y: + case NS_ooxml::LN_CT_FramePr_yAlign: + case NS_ooxml::LN_CT_FramePr_hRule: + case NS_ooxml::LN_CT_FramePr_w: + case NS_ooxml::LN_CT_FramePr_h: + case NS_ooxml::LN_CT_FramePr_wrap: + case NS_ooxml::LN_CT_FramePr_hSpace: + case NS_ooxml::LN_CT_FramePr_vSpace: + { + ParagraphProperties* pParaProperties = nullptr; + // handle frame properties at styles + if( m_pImpl->GetTopContextType() == CONTEXT_STYLESHEET ) + pParaProperties = dynamic_cast< ParagraphProperties*>( m_pImpl->GetTopContextOfType( CONTEXT_STYLESHEET ).get() ); + else + pParaProperties = dynamic_cast< ParagraphProperties*>( m_pImpl->GetTopContextOfType( CONTEXT_PARAGRAPH ).get() ); + + if( pParaProperties ) + { + switch( nName ) + { + case NS_ooxml::LN_CT_FramePr_dropCap: + pParaProperties->SetDropCap( nIntValue ); + break; + case NS_ooxml::LN_CT_FramePr_lines: + pParaProperties->SetLines( nIntValue ); + break; + case NS_ooxml::LN_CT_FramePr_hAnchor: + switch(nIntValue) + { + case NS_ooxml::LN_Value_doc_ST_HAnchor_text: //relative to column + nIntValue = text::RelOrientation::FRAME; break; + case NS_ooxml::LN_Value_doc_ST_HAnchor_margin: nIntValue = text::RelOrientation::PAGE_PRINT_AREA; break; + case NS_ooxml::LN_Value_doc_ST_HAnchor_page: nIntValue = text::RelOrientation::PAGE_FRAME; break; + default:; + } + pParaProperties->SethAnchor( nIntValue ); + break; + case NS_ooxml::LN_CT_FramePr_vAnchor: + switch(nIntValue) + { + case NS_ooxml::LN_Value_doc_ST_VAnchor_text: //relative to paragraph + nIntValue = text::RelOrientation::FRAME; break; + case NS_ooxml::LN_Value_doc_ST_VAnchor_margin:nIntValue = text::RelOrientation::PAGE_PRINT_AREA ; break; + case NS_ooxml::LN_Value_doc_ST_VAnchor_page: nIntValue = text::RelOrientation::PAGE_FRAME; break; + default:; + } + pParaProperties->SetvAnchor( nIntValue ); + break; + case NS_ooxml::LN_CT_FramePr_x: + pParaProperties->Setx( ConversionHelper::convertTwipToMM100(nIntValue )); + pParaProperties->SetxAlign( text::HoriOrientation::NONE ); + break; + case NS_ooxml::LN_CT_FramePr_xAlign: + switch( nIntValue ) + { + case NS_ooxml::LN_Value_doc_ST_XAlign_center : nIntValue = text::HoriOrientation::CENTER; break; + case NS_ooxml::LN_Value_doc_ST_XAlign_right : nIntValue = text::HoriOrientation::RIGHT; break; + case NS_ooxml::LN_Value_doc_ST_XAlign_inside : nIntValue = text::HoriOrientation::INSIDE; break; + case NS_ooxml::LN_Value_doc_ST_XAlign_outside : nIntValue = text::HoriOrientation::OUTSIDE; break; + case NS_ooxml::LN_Value_doc_ST_XAlign_left : nIntValue = text::HoriOrientation::LEFT; break; + default: nIntValue = text::HoriOrientation::NONE; + } + pParaProperties->SetxAlign( nIntValue ); + break; + case NS_ooxml::LN_CT_FramePr_y: + pParaProperties->Sety( ConversionHelper::convertTwipToMM100(nIntValue )); + pParaProperties->SetyAlign( text::VertOrientation::NONE ); + break; + case NS_ooxml::LN_CT_FramePr_yAlign: + switch( nIntValue ) + { + case NS_ooxml::LN_Value_doc_ST_YAlign_top : + case NS_ooxml::LN_Value_doc_ST_YAlign_inside :nIntValue = text::VertOrientation::TOP; break; + case NS_ooxml::LN_Value_doc_ST_YAlign_center :nIntValue = text::VertOrientation::CENTER;break; + case NS_ooxml::LN_Value_doc_ST_YAlign_bottom : + case NS_ooxml::LN_Value_doc_ST_YAlign_outside :nIntValue = text::VertOrientation::BOTTOM;break; + case NS_ooxml::LN_Value_doc_ST_YAlign_inline : + { + // HACK: This is for bnc#780851, where a table has one cell that has w:framePr, + // which causes that paragraph to be converted to a text frame, and the original + // paragraph object no longer exists, which makes table creation fail and furthermore + // it would be missing in the table layout anyway. So actually no letting that paragraph + // be a text frame "fixes" it. I'm not sure what "inline" is supposed to mean in practice + // anyway, so as long as this doesn't cause trouble elsewhere ... + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH); + if( pContext ) + { + ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pContext.get() ); + if (pParaContext) + pParaContext->SetFrameMode(false); + } + nIntValue = text::VertOrientation::NONE; + break; + } + default: + nIntValue = text::VertOrientation::NONE; + break; + } + pParaProperties->SetyAlign( nIntValue ); + break; + case NS_ooxml::LN_CT_FramePr_hRule: + switch( nIntValue ) + { + case NS_ooxml::LN_Value_doc_ST_HeightRule_exact: + nIntValue = text::SizeType::FIX; + break; + case NS_ooxml::LN_Value_doc_ST_HeightRule_atLeast: + nIntValue = text::SizeType::MIN; + break; + case NS_ooxml::LN_Value_doc_ST_HeightRule_auto: + //no break; + default:; + nIntValue = text::SizeType::VARIABLE; + } + pParaProperties->SethRule( nIntValue ); + break; + case NS_ooxml::LN_CT_FramePr_wrap: + { + //should be either LN_Value_doc_ST_Wrap_notBeside or LN_Value_doc_ST_Wrap_around or LN_Value_doc_ST_Wrap_auto + OSL_ENSURE( sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_around || + sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_notBeside || + sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_through || + sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_none || + sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_auto, + "wrap not around, not_Beside, through, none or auto?"); + if( sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_through || + sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_auto ) + pParaProperties->SetWrap ( text::WrapTextMode_DYNAMIC ) ; + else if (sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_around) + pParaProperties->SetWrap(text::WrapTextMode_PARALLEL); + else if (sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_Wrap_none) + pParaProperties->SetWrap ( text::WrapTextMode_THROUGH ) ; + else + pParaProperties->SetWrap ( text::WrapTextMode_NONE ) ; + } + break; + case NS_ooxml::LN_CT_FramePr_w: + pParaProperties->Setw(ConversionHelper::convertTwipToMM100(nIntValue)); + break; + case NS_ooxml::LN_CT_FramePr_h: + pParaProperties->Seth(ConversionHelper::convertTwipToMM100(nIntValue)); + break; + case NS_ooxml::LN_CT_FramePr_hSpace: + pParaProperties->SethSpace( ConversionHelper::convertTwipToMM100(nIntValue )); + break; + case NS_ooxml::LN_CT_FramePr_vSpace: + pParaProperties->SetvSpace( ConversionHelper::convertTwipToMM100(nIntValue )); + break; + default:; + } + } + } + break; + case NS_ooxml::LN_CT_TrackChange_author: + m_pImpl->SetCurrentRedlineAuthor( sStringValue ); + break; + case NS_ooxml::LN_CT_TrackChange_date: + m_pImpl->SetCurrentRedlineDate( sStringValue ); + break; + case NS_ooxml::LN_CT_Markup_id: + m_pImpl->SetCurrentRedlineId( nIntValue ); + break; + case NS_ooxml::LN_EG_RangeMarkupElements_commentRangeStart: + m_pImpl->AddAnnotationPosition( true, nIntValue ); + break; + case NS_ooxml::LN_EG_RangeMarkupElements_commentRangeEnd: + m_pImpl->AddAnnotationPosition( false, nIntValue ); + break; + case NS_ooxml::LN_CT_Comment_initials: + m_pImpl->SetCurrentRedlineInitials(sStringValue); + break; + case NS_ooxml::LN_token: + m_pImpl->SetCurrentRedlineToken( nIntValue ); + break; + case NS_ooxml::LN_CT_LineNumber_start: + case NS_ooxml::LN_CT_LineNumber_distance: + case NS_ooxml::LN_CT_LineNumber_countBy: + case NS_ooxml::LN_CT_LineNumber_restart: + { + //line numbering in Writer is a global document setting + //in Word is a section setting + //if line numbering is switched on anywhere in the document it's set at the global settings + LineNumberSettings aSettings = m_pImpl->GetLineNumberSettings(); + switch( nName ) + { + case NS_ooxml::LN_CT_LineNumber_countBy: + aSettings.nInterval = nIntValue; + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if( pSectionContext ) + pSectionContext->SetLnnMod( nIntValue ); + break; + case NS_ooxml::LN_CT_LineNumber_start: + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if( pSectionContext ) + pSectionContext->SetLnnMin( nIntValue ); + break; + case NS_ooxml::LN_CT_LineNumber_distance: + aSettings.nDistance = ConversionHelper::convertTwipToMM100( nIntValue ); + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if( pSectionContext ) + pSectionContext->SetdxaLnn( nIntValue ); + break; + case NS_ooxml::LN_CT_LineNumber_restart: + aSettings.bRestartAtEachPage = nIntValue == static_cast(NS_ooxml::LN_Value_ST_LineNumberRestart_newPage); + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if( pSectionContext ) + pSectionContext->SetLnc( nIntValue ); + break; + default:; + } + m_pImpl->SetLineNumberSettings( aSettings ); + } + break; + case NS_ooxml::LN_CT_FtnEdnRef_customMarkFollows: + m_pImpl->StartCustomFootnote(m_pImpl->GetTopContext()); + break; + case NS_ooxml::LN_CT_FtnEdnRef_id: + // footnote or endnote reference id - not needed + break; + case NS_ooxml::LN_CT_Color_themeColor: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue)); + break; + case NS_ooxml::LN_CT_Color_themeTint: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "themeTint", OUString::number(nIntValue, 16)); + break; + case NS_ooxml::LN_CT_Color_themeShade: + m_pImpl->appendGrabBag(m_pImpl->m_aSubInteropGrabBag, "themeShade", OUString::number(nIntValue, 16)); + break; + case NS_ooxml::LN_CT_DocGrid_linePitch: + { + //see SwWW8ImplReader::SetDocumentGrid + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + { + pSectionContext->SetGridLinePitch( ConversionHelper::convertTwipToMM100( nIntValue ) ); + } + } + break; + case NS_ooxml::LN_CT_DocGrid_charSpace: + { + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + { + pSectionContext->SetDxtCharSpace( nIntValue ); + } + } + break; + case NS_ooxml::LN_CT_DocGrid_type: + { + if (pSectionContext != nullptr) + { + switch( nIntValue ) + { + case NS_ooxml::LN_Value_doc_ST_DocGrid_default: + pSectionContext->SetGridType(text::TextGridMode::NONE); + break; + case NS_ooxml::LN_Value_doc_ST_DocGrid_lines: + pSectionContext->SetGridType(text::TextGridMode::LINES); + break; + case NS_ooxml::LN_Value_doc_ST_DocGrid_linesAndChars: + pSectionContext->SetGridType(text::TextGridMode::LINES_AND_CHARS); + pSectionContext->SetGridSnapToChars( false ); + break; + case NS_ooxml::LN_Value_doc_ST_DocGrid_snapToChars: + pSectionContext->SetGridType(text::TextGridMode::LINES_AND_CHARS); + pSectionContext->SetGridSnapToChars( true ); + break; + default : + OSL_FAIL("unknown SwTextGrid value"); + } + } + } + break; + case NS_ooxml::LN_CT_SdtBlock_sdtContent: + m_pImpl->SetSdt(true); + break; + case NS_ooxml::LN_CT_SdtBlock_sdtEndContent: + m_pImpl->SetSdt(false); + + // It's not possible to insert the relevant property to the character context here: + // the previous, already sent character context may be still active, so the property would be lost. + if (m_pImpl->m_pSdtHelper->isOutsideAParagraph()) + m_pImpl->setParaSdtEndDeferred(true); + else + m_pImpl->setSdtEndDeferred(true); + + if (m_pImpl->m_pSdtHelper->isInsideDropDownControl()) + m_pImpl->m_pSdtHelper->createDropDownControl(); + else if (m_pImpl->m_pSdtHelper->validateDateFormat()) + m_pImpl->m_pSdtHelper->createDateContentControl(); + break; + case NS_ooxml::LN_CT_SdtListItem_displayText: + // TODO handle when this is != value + break; + case NS_ooxml::LN_CT_SdtListItem_value: + m_pImpl->m_pSdtHelper->getDropDownItems().push_back(sStringValue); + break; + case NS_ooxml::LN_CT_SdtDate_fullDate: + m_pImpl->m_pSdtHelper->getDate().append(sStringValue); + break; + case NS_ooxml::LN_CT_Background_color: + if (m_pImpl->GetSettingsTable()->GetDisplayBackgroundShape()) + m_pImpl->m_oBackgroundColor = nIntValue; + break; + case NS_ooxml::LN_CT_PageNumber_start: + if (pSectionContext != nullptr) + pSectionContext->SetPageNumber(nIntValue); + break; + case NS_ooxml::LN_CT_PageNumber_fmt: + if (pSectionContext) + { + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_NumberFormat_decimal: + // 1, 2, ... + pSectionContext->SetPageNumberType(style::NumberingType::ARABIC); + break; + case NS_ooxml::LN_Value_ST_NumberFormat_upperLetter: + // A, B, ... + pSectionContext->SetPageNumberType(style::NumberingType::CHARS_UPPER_LETTER_N); + break; + case NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter: + // a, b, ... + pSectionContext->SetPageNumberType(style::NumberingType::CHARS_LOWER_LETTER_N); + break; + case NS_ooxml::LN_Value_ST_NumberFormat_upperRoman: + // I, II, ... + pSectionContext->SetPageNumberType(style::NumberingType::ROMAN_UPPER); + break; + case NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman: + // i, ii, ... + pSectionContext->SetPageNumberType(style::NumberingType::ROMAN_LOWER); + break; + } + } + break; + case NS_ooxml::LN_CT_FtnEdn_type: + // This is the "separator" footnote, ignore its linebreaks/text. + if (static_cast(nIntValue) == NS_ooxml::LN_Value_doc_ST_FtnEdn_separator) + m_pImpl->SetSkipFootnoteState( SkipFootnoteSeparator::ON ); + else + m_pImpl->SetSkipFootnoteState( SkipFootnoteSeparator::OFF ); + break; + case NS_ooxml::LN_CT_FtnEdn_id: + { + SkipFootnoteSeparator eSkip = m_pImpl->GetSkipFootnoteState(); + if ( eSkip == SkipFootnoteSeparator::ON ) + m_pImpl->SetSkipFootnoteState( SkipFootnoteSeparator::SKIPPING ); + else if ( eSkip == SkipFootnoteSeparator::SKIPPING ) + m_pImpl->SetSkipFootnoteState( SkipFootnoteSeparator::OFF ); + } + break; + case NS_ooxml::LN_CT_DataBinding_prefixMappings: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_DataBinding_prefixMappings", sStringValue); + break; + case NS_ooxml::LN_CT_DataBinding_xpath: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_DataBinding_xpath", sStringValue); + break; + case NS_ooxml::LN_CT_DataBinding_storeItemID: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_DataBinding_storeItemID", sStringValue); + break; + case NS_ooxml::LN_CT_PTab_leader: + case NS_ooxml::LN_CT_PTab_relativeTo: + case NS_ooxml::LN_CT_PTab_alignment: + break; + case NS_ooxml::LN_CT_Cnf_lastRowLastColumn: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "lastRowLastColumn", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_lastRowFirstColumn: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "lastRowFirstColumn", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_firstRowLastColumn: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "firstRowLastColumn", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_oddHBand: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "oddHBand", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_firstRowFirstColumn: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "firstRowFirstColumn", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_evenVBand: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "evenVBand", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_evenHBand: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "evenHBand", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_lastColumn: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "lastColumn", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_firstColumn: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "firstColumn", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_oddVBand: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "oddVBand", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_lastRow: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "lastRow", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_firstRow: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "firstRow", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Cnf_val: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "val", sStringValue); + break; + case NS_ooxml::LN_CT_DocPartName_val: + { + m_sGlossaryEntryName = sStringValue; + break; + } + case NS_ooxml::LN_CT_DocPartGallery_val: + { + const OUString& sGlossaryEntryGallery = sStringValue; + if(m_pImpl->GetTopContext()) + { + OUString sName = sGlossaryEntryGallery + ":" + m_sGlossaryEntryName; + // Add glossary entry name as a first paragraph in section + m_pImpl->appendTextPortion(sName, m_pImpl->GetTopContext()); + } + break; + } + case NS_ooxml::LN_CT_PermStart_ed: + { + m_pImpl->setPermissionRangeEd(sStringValue); + break; + } + case NS_ooxml::LN_CT_PermStart_edGrp: + { + m_pImpl->setPermissionRangeEdGrp(sStringValue); + break; + } + case NS_ooxml::LN_CT_PermStart_id: + { + m_pImpl->startOrEndPermissionRange(nIntValue); + break; + } + case NS_ooxml::LN_CT_PermEnd_id: + { + m_pImpl->startOrEndPermissionRange(nIntValue); + break; + } + case NS_ooxml::LN_CT_NumFmt_val: + { + try + { + uno::Reference xFtnEdnSettings; + if (m_pImpl->IsInFootnoteProperties()) + { + uno::Reference xFootnotesSupplier( + m_pImpl->GetTextDocument(), uno::UNO_QUERY); + if (xFootnotesSupplier.is()) + xFtnEdnSettings = xFootnotesSupplier->getFootnoteSettings(); + } + else + { + uno::Reference xEndnotesSupplier( + m_pImpl->GetTextDocument(), uno::UNO_QUERY); + if (xEndnotesSupplier.is()) + xFtnEdnSettings = xEndnotesSupplier->getEndnoteSettings(); + } + if (xFtnEdnSettings.is()) + { + sal_Int16 nNumType = ConversionHelper::ConvertNumberingType(nIntValue); + xFtnEdnSettings->setPropertyValue(getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny(nNumType)); + } + } + catch (const uno::Exception&) + { + } + } + break; + default: + SAL_WARN("writerfilter", "DomainMapper::lcl_attribute: unhandled token: " << nName); + } +} + +void DomainMapper::lcl_sprm(Sprm & rSprm) +{ + if (!m_pImpl->hasTableManager() || !m_pImpl->getTableManager().sprm(rSprm)) + sprmWithProps(rSprm, m_pImpl->GetTopContext()); +} + +// In rtl-paragraphs the meaning of left/right are to be exchanged +static bool ExchangeLeftRight(const PropertyMapPtr& rContext, DomainMapper_Impl& rImpl) +{ + bool bExchangeLeftRight = false; + sal_Int32 aAdjust; + uno::Any aPropPara = rImpl.GetAnyProperty(PROP_WRITING_MODE, rContext); + if( (aPropPara >>= aAdjust) && aAdjust == text::WritingMode2::RL_TB ) + bExchangeLeftRight = true; + return bExchangeLeftRight; +} + +void DomainMapper::sprmWithProps( Sprm& rSprm, const PropertyMapPtr& rContext ) +{ + // These SPRM's are not specific to any section, so it's expected that there is no context yet. + switch (rSprm.getId()) + { + case NS_ooxml::LN_background_background: + return; + break; + default: + break; + } + + OSL_ENSURE(rContext.get(), "PropertyMap has to be valid!"); + if(!rContext) + return ; + + sal_uInt32 nSprmId = rSprm.getId(); + //needed for page properties + SectionPropertyMap * pSectionContext = m_pImpl->GetSectionContext(); + Value::Pointer_t pValue = rSprm.getValue(); + sal_Int32 nIntValue = pValue->getInt(); + const OUString sStringValue = pValue->getString(); + + switch(nSprmId) + { + case NS_ooxml::LN_CT_PPrBase_jc: + { + bool bExchangeLeftRight = !IsRTFImport() && ExchangeLeftRight(rContext, *m_pImpl); + handleParaJustification(nIntValue, rContext, bExchangeLeftRight); + break; + } + case NS_ooxml::LN_CT_PPrBase_keepLines: + rContext->Insert(PROP_PARA_SPLIT, uno::makeAny(nIntValue == 0)); + break; + case NS_ooxml::LN_CT_PPrBase_keepNext: + rContext->Insert(PROP_PARA_KEEP_TOGETHER, uno::makeAny( nIntValue != 0 ) ); + break; + case NS_ooxml::LN_CT_PPrBase_pageBreakBefore: + rContext->Insert(PROP_BREAK_TYPE, uno::makeAny(nIntValue ? style::BreakType_PAGE_BEFORE : style::BreakType_NONE)); + break; + case NS_ooxml::LN_CT_NumPr_ilvl: + if (nIntValue < 0 || 10 <= nIntValue) // Writer can't do everything + { + SAL_INFO("writerfilter", + "unsupported numbering level " << nIntValue); + break; + } + if( IsStyleSheetImport() ) + { + //style sheets cannot have a numbering rule attached + StyleSheetPropertyMap* pStyleSheetPropertyMap = dynamic_cast< StyleSheetPropertyMap* >( rContext.get() ); + if (pStyleSheetPropertyMap) + pStyleSheetPropertyMap->SetListLevel( static_cast(nIntValue) ); + } + else + rContext->Insert( PROP_NUMBERING_LEVEL, uno::makeAny( static_cast(nIntValue) )); + break; + case NS_ooxml::LN_CT_NumPr_numId: + { + //convert the ListTable entry to a NumberingRules property and apply it + ListsManager::Pointer pListTable = m_pImpl->GetListTable(); + ListDef::Pointer pList = pListTable->GetList( nIntValue ); + if( IsStyleSheetImport() ) + { + //style sheets cannot have a numbering rule attached + StyleSheetPropertyMap* pStyleSheetPropertyMap = dynamic_cast< StyleSheetPropertyMap* >( rContext.get() ); + if (pStyleSheetPropertyMap) + pStyleSheetPropertyMap->SetListId( nIntValue ); + } + if( pList ) + { + if( !IsStyleSheetImport() ) + { + uno::Any aRules = uno::makeAny( pList->GetNumberingRules( ) ); + rContext->Insert( PROP_NUMBERING_RULES, aRules ); + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH); + if (pContext) + { + assert(dynamic_cast(pContext.get())); + static_cast(pContext.get())->SetListId(pList->GetId()); + } + + // Indentation can came from: + // 1) Paragraph style's numbering's indentation: the current non-style numId has priority over it. + // 2) Numbering's indentation: Writer handles that natively, so it should not be set on rContext. + // 3) Paragraph style's indentation: ditto. + // 4) Direct paragraph formatting: that will came later. + // So no situation where keeping indentation at this point would make sense -> erase. + rContext->Erase(PROP_PARA_FIRST_LINE_INDENT); + rContext->Erase(PROP_PARA_LEFT_MARGIN); + rContext->Erase(PROP_PARA_RIGHT_MARGIN); + } + } + else + { + if( !IsStyleSheetImport() ) + { + // eg. disabled numbering using non-existent numId "0" + rContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny( OUString() ) ); + // disable inheritance of indentation of parent styles + rContext->Insert( PROP_PARA_LEFT_MARGIN, uno::makeAny( sal_Int32(0) ), /*bOverwrite=*/false); + rContext->Insert( PROP_PARA_FIRST_LINE_INDENT, + uno::makeAny( sal_Int32(0) ), /*bOverwrite=*/false); + } + } + } + break; + case NS_ooxml::LN_CT_PPrBase_suppressLineNumbers: + rContext->Insert(PROP_PARA_LINE_NUMBER_COUNT, uno::makeAny( nIntValue == 0 ) ); + break; + case NS_ooxml::LN_inTbl: + break; + case NS_ooxml::LN_tblDepth: + //not handled via sprm but via text( 0x07 ) + break; + case NS_ooxml::LN_CT_FramePr_w: + break; + case NS_ooxml::LN_CT_FramePr_wrap: + break; + + case NS_ooxml::LN_CT_PrBase_pBdr: //paragraph border + resolveSprmProps(*this, rSprm); + break; + case NS_ooxml::LN_CT_PBdr_top: + case NS_ooxml::LN_CT_PBdr_left: + case NS_ooxml::LN_CT_PBdr_bottom: + case NS_ooxml::LN_CT_PBdr_right: + case NS_ooxml::LN_CT_PBdr_between: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pBorderHandler = std::make_shared( true ); + pProperties->resolve(*pBorderHandler); + PropertyIds eBorderId = PropertyIds( 0 ); + PropertyIds eBorderDistId = PropertyIds( 0 ); + switch( nSprmId ) + { + case NS_ooxml::LN_CT_PBdr_top: + eBorderId = PROP_TOP_BORDER; + eBorderDistId = PROP_TOP_BORDER_DISTANCE; + break; + case NS_ooxml::LN_CT_PBdr_left: + eBorderId = PROP_LEFT_BORDER; + eBorderDistId = PROP_LEFT_BORDER_DISTANCE; + break; + case NS_ooxml::LN_CT_PBdr_bottom: + eBorderId = PROP_BOTTOM_BORDER ; + eBorderDistId = PROP_BOTTOM_BORDER_DISTANCE; + break; + case NS_ooxml::LN_CT_PBdr_right: + eBorderId = PROP_RIGHT_BORDER; + eBorderDistId = PROP_RIGHT_BORDER_DISTANCE ; + break; + case NS_ooxml::LN_CT_PBdr_between: + //not supported + break; + default:; + } + if( eBorderId ) + rContext->Insert( eBorderId, uno::makeAny( pBorderHandler->getBorderLine()) ); + if(eBorderDistId) + rContext->Insert(eBorderDistId, uno::makeAny( pBorderHandler->getLineDistance())); + if ( nSprmId == NS_ooxml::LN_CT_PBdr_right ) + { + table::ShadowFormat aFormat; + // Word only allows shadows on visible borders + if ( pBorderHandler->getShadow() && pBorderHandler->getBorderLine().LineStyle != table::BorderLineStyle::NONE ) + aFormat = writerfilter::dmapper::PropertyMap::getShadowFromBorder(pBorderHandler->getBorderLine()); + rContext->Insert(PROP_PARA_SHADOW_FORMAT, uno::makeAny(aFormat)); + } + } + } + break; + case NS_ooxml::LN_CT_PBdr_bar: + break; + case NS_ooxml::LN_CT_PPrBase_suppressAutoHyphens: + rContext->Insert(PROP_PARA_IS_HYPHENATION, uno::makeAny( nIntValue == 0 )); + break; + case NS_ooxml::LN_CT_FramePr_h: + break; + case NS_ooxml::LN_CT_PrBase_shd: + { + //contains fore color, back color and shadow percentage, results in a brush + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pCellColorHandler = std::make_shared(); + pCellColorHandler->setOutputFormat( CellColorHandler::Paragraph ); + bool bEnableTempGrabBag = !pCellColorHandler->isInteropGrabBagEnabled(); + if( bEnableTempGrabBag ) + pCellColorHandler->enableInteropGrabBag( "TempShdPropsGrabBag" ); + + pProperties->resolve(*pCellColorHandler); + rContext->InsertProps(pCellColorHandler->getProperties().get()); + + rContext->Insert(PROP_CHAR_THEME_FILL, pCellColorHandler->getInteropGrabBag().Value, true, PARA_GRAB_BAG); + if(bEnableTempGrabBag) + pCellColorHandler->disableInteropGrabBag(); + } + } + break; + case NS_ooxml::LN_CT_FramePr_vSpace: + break; // sprmPDyaFromText + case NS_ooxml::LN_CT_FramePr_hSpace: + break; // sprmPDxaFromText + case NS_ooxml::LN_CT_FramePr_anchorLock: + break; + case NS_ooxml::LN_CT_PPrBase_widowControl: + { + uno::Any aVal( uno::makeAny( sal_Int8(nIntValue ? 2 : 0 ))); + rContext->Insert( PROP_PARA_WIDOWS, aVal ); + rContext->Insert( PROP_PARA_ORPHANS, aVal ); + } + break; // sprmPFWidowControl + case NS_ooxml::LN_CT_PPrBase_overflowPunct: + rContext->Insert(PROP_PARA_IS_HANGING_PUNCTUATION, uno::makeAny( nIntValue == 0 )); + break; + case NS_ooxml::LN_CT_PPrBase_topLinePunct: + break; + case NS_ooxml::LN_CT_PPrBase_autoSpaceDE: + break; + case NS_ooxml::LN_CT_PPrBase_autoSpaceDN: + break; + case NS_ooxml::LN_CT_PPrBase_textAlignment: + { + sal_Int16 nAlignment = 0; + switch (nIntValue) + { + case NS_ooxml::LN_Value_doc_ST_TextAlignment_top: + nAlignment = 2; + break; + case NS_ooxml::LN_Value_doc_ST_TextAlignment_center: + nAlignment = 3; + break; + case NS_ooxml::LN_Value_doc_ST_TextAlignment_baseline: + nAlignment = 1; + break; + case NS_ooxml::LN_Value_doc_ST_TextAlignment_bottom: + nAlignment = 4; + break; + case NS_ooxml::LN_Value_doc_ST_TextAlignment_auto: + default: + break; + } + rContext->Insert( PROP_PARA_VERT_ALIGNMENT, uno::makeAny( nAlignment) ); + } + break; + case NS_ooxml::LN_CT_PPrBase_textDirection: + break; + case NS_ooxml::LN_CT_PPrBase_outlineLvl: + { + sal_Int16 nLvl = static_cast< sal_Int16 >( nIntValue ); + if( IsStyleSheetImport() ) + { + + StyleSheetPropertyMap* pStyleSheetPropertyMap = dynamic_cast< StyleSheetPropertyMap* >( rContext.get() ); + if (pStyleSheetPropertyMap) + pStyleSheetPropertyMap->SetOutlineLevel( nLvl ); + } + else + { + nLvl = nLvl >= WW_OUTLINE_MIN && nLvl < WW_OUTLINE_MAX? nLvl+1 : 0; //0 means no outline level set on + rContext->Insert(PROP_OUTLINE_LEVEL, uno::makeAny ( nLvl )); + } + } + break; + case NS_ooxml::LN_CT_PPrBase_bidi: + { + // Four situations to handle: + // 1.) bidi same as previous setting: no adjust change + // 2.) no previous adjust: set appropriate default for this bidi + // 3.) previous adjust and bidi different from previous: swap adjusts + // 4.) previous adjust and no previous bidi: RTL swaps adjust + + const sal_Int16 nWritingMode = nIntValue ? text::WritingMode2::RL_TB : text::WritingMode2::LR_TB; + sal_Int16 nParentBidi = -1; + m_pImpl->GetPropertyFromParaStyleSheet(PROP_WRITING_MODE) >>= nParentBidi; + // Paragraph justification reverses its meaning in an RTL context. + // 1. Only make adjustments if the BiDi changes. + if ( nParentBidi != nWritingMode && !IsRTFImport() ) + { + style::ParagraphAdjust eAdjust = style::ParagraphAdjust(-1); + // 2. no adjust property exists yet + if ( !(m_pImpl->GetAnyProperty(PROP_PARA_ADJUST, rContext) >>= eAdjust) ) + { + // RTL defaults to right adjust + eAdjust = nIntValue ? style::ParagraphAdjust_RIGHT : style::ParagraphAdjust_LEFT; + rContext->Insert(PROP_PARA_ADJUST, uno::makeAny( eAdjust ), /*bOverwrite=*/false); + } + // 3,4. existing adjust: if RTL, then swap. If LTR, but previous was RTL, also swap. + else if ( nIntValue || nParentBidi == sal_Int16(text::WritingMode2::RL_TB) ) + { + if ( eAdjust == style::ParagraphAdjust_RIGHT ) + rContext->Insert(PROP_PARA_ADJUST, uno::makeAny( style::ParagraphAdjust_LEFT )); + else if ( eAdjust == style::ParagraphAdjust_LEFT ) + rContext->Insert(PROP_PARA_ADJUST, uno::makeAny( style::ParagraphAdjust_RIGHT )); + } + } + rContext->Insert(PROP_WRITING_MODE, uno::makeAny( nWritingMode )); + } + + break; + case NS_ooxml::LN_EG_SectPrContents_bidi: + if (pSectionContext != nullptr) + { + const sal_Int16 writingMode = (nIntValue != 0) ? sal_Int16(text::WritingMode2::RL_TB) : sal_Int16(text::WritingMode2::LR_TB); + pSectionContext->Insert(PROP_WRITING_MODE, uno::makeAny(writingMode)); + } + break; + case NS_ooxml::LN_EG_RPrBase_highlight: + { + // OOXML import uses an ID + if( IsOOXMLImport() ) + { + sal_Int32 nColor = 0; + if( getColorFromId(nIntValue, nColor) ) + rContext->Insert(PROP_CHAR_HIGHLIGHT, uno::makeAny( nColor )); + } + // RTF import uses the actual color value + else if( IsRTFImport() ) + { + rContext->Insert(PROP_CHAR_HIGHLIGHT, uno::makeAny( nIntValue )); + } + } + break; + case NS_ooxml::LN_EG_RPrBase_em: + rContext->Insert(PROP_CHAR_EMPHASIS, uno::makeAny ( getEmphasisValue (nIntValue))); + break; + case NS_ooxml::LN_EG_RPrBase_emboss: + case NS_ooxml::LN_EG_RPrBase_b: + case NS_ooxml::LN_EG_RPrBase_bCs: + case NS_ooxml::LN_EG_RPrBase_i: + case NS_ooxml::LN_EG_RPrBase_iCs: + case NS_ooxml::LN_EG_RPrBase_strike: + case NS_ooxml::LN_EG_RPrBase_dstrike: + case NS_ooxml::LN_EG_RPrBase_outline: + case NS_ooxml::LN_EG_RPrBase_shadow: + case NS_ooxml::LN_EG_RPrBase_caps: + case NS_ooxml::LN_EG_RPrBase_smallCaps: + case NS_ooxml::LN_EG_RPrBase_vanish: + case NS_ooxml::LN_EG_RPrBase_webHidden: + { + PropertyIds ePropertyId = PROP_CHAR_WEIGHT; //initialized to prevent warning! + switch( nSprmId ) + { + case NS_ooxml::LN_EG_RPrBase_b: + case NS_ooxml::LN_EG_RPrBase_bCs: + ePropertyId = nSprmId != NS_ooxml::LN_EG_RPrBase_bCs ? PROP_CHAR_WEIGHT : PROP_CHAR_WEIGHT_COMPLEX; + break; + case NS_ooxml::LN_EG_RPrBase_i: + case NS_ooxml::LN_EG_RPrBase_iCs: + ePropertyId = nSprmId == NS_ooxml::LN_EG_RPrBase_i ? PROP_CHAR_POSTURE : PROP_CHAR_POSTURE_COMPLEX; + break; + case NS_ooxml::LN_EG_RPrBase_strike: + case NS_ooxml::LN_EG_RPrBase_dstrike: + ePropertyId = PROP_CHAR_STRIKEOUT; + break; + case NS_ooxml::LN_EG_RPrBase_outline: + ePropertyId = PROP_CHAR_CONTOURED; + break; + case NS_ooxml::LN_EG_RPrBase_shadow: + ePropertyId = PROP_CHAR_SHADOWED; + break; + case NS_ooxml::LN_EG_RPrBase_caps: + case NS_ooxml::LN_EG_RPrBase_smallCaps: + ePropertyId = PROP_CHAR_CASE_MAP; + break; + case NS_ooxml::LN_EG_RPrBase_vanish: + case NS_ooxml::LN_EG_RPrBase_webHidden: + ePropertyId = PROP_CHAR_HIDDEN; + break; + case NS_ooxml::LN_EG_RPrBase_emboss: + ePropertyId = PROP_CHAR_RELIEF; + break; + } + //expected: 0,1,128,129 + if(nIntValue != 128) //inherited from paragraph - ignore + { + if( nIntValue == 129) //inverted style sheet value + { + //get value from style sheet and invert it + sal_Int16 nStyleValue = 0; + uno::Any aStyleVal = m_pImpl->GetPropertyFromParaStyleSheet(ePropertyId); + if( !aStyleVal.hasValue() ) + { + nIntValue = NS_ooxml::LN_EG_RPrBase_smallCaps == nSprmId ? + 4 : 1; + } + else if(aStyleVal.getValueTypeClass() == uno::TypeClass_FLOAT ) + { + double fDoubleValue = 0; + //only in case of awt::FontWeight + aStyleVal >>= fDoubleValue; + nIntValue = fDoubleValue > 100. ? 0 : 1; + } + else if((aStyleVal >>= nStyleValue) || + (nStyleValue = static_cast(comphelper::getEnumAsINT32(aStyleVal))) >= 0 ) + { + nIntValue = NS_ooxml::LN_EG_RPrBase_smallCaps == nSprmId ? + nStyleValue ? 0 : 4 : + nStyleValue ? 0 : 1; + } + else + { + OSL_FAIL( "what type was it"); + } + } + + switch( nSprmId ) + { + case NS_ooxml::LN_EG_RPrBase_b: + case NS_ooxml::LN_EG_RPrBase_bCs: + { + uno::Any aBold( uno::makeAny( nIntValue ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) ); + + rContext->Insert(ePropertyId, aBold ); + if( nSprmId != NS_ooxml::LN_EG_RPrBase_bCs ) + rContext->Insert(PROP_CHAR_WEIGHT_ASIAN, aBold ); + + uno::Reference xCharStyle(m_pImpl->GetCurrentNumberingCharStyle()); + if (xCharStyle.is()) + xCharStyle->setPropertyValue(getPropertyName(PROP_CHAR_WEIGHT), aBold); + if (nSprmId == NS_ooxml::LN_EG_RPrBase_b) + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "b", OUString::number(nIntValue)); + else if (nSprmId == NS_ooxml::LN_EG_RPrBase_bCs) + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "bCs", OUString::number(nIntValue)); + } + break; + case NS_ooxml::LN_EG_RPrBase_i: + case NS_ooxml::LN_EG_RPrBase_iCs: + { + uno::Any aPosture( uno::makeAny( nIntValue ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) ); + rContext->Insert( ePropertyId, aPosture ); + if (nSprmId != NS_ooxml::LN_EG_RPrBase_iCs) + rContext->Insert(PROP_CHAR_POSTURE_ASIAN, aPosture ); + if (nSprmId == NS_ooxml::LN_EG_RPrBase_i) + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "i", OUString::number(nIntValue)); + } + break; + case NS_ooxml::LN_EG_RPrBase_strike: + rContext->Insert(ePropertyId, + uno::makeAny( nIntValue ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) ); + break; + case NS_ooxml::LN_EG_RPrBase_dstrike: + rContext->Insert(ePropertyId, + uno::makeAny( nIntValue ? awt::FontStrikeout::DOUBLE : awt::FontStrikeout::NONE ) ); + break; + case NS_ooxml::LN_EG_RPrBase_outline: + case NS_ooxml::LN_EG_RPrBase_shadow: + case NS_ooxml::LN_EG_RPrBase_vanish: + case NS_ooxml::LN_EG_RPrBase_webHidden: + rContext->Insert(ePropertyId, uno::makeAny( nIntValue != 0 )); + break; + case NS_ooxml::LN_EG_RPrBase_smallCaps: + // If smallcaps would be just disabled and another casemap is already inserted, don't do anything. + if (nIntValue || !rContext->isSet(ePropertyId) ) + rContext->Insert(ePropertyId, uno::makeAny( nIntValue ? style::CaseMap::SMALLCAPS : style::CaseMap::NONE)); + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "smallCaps", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_EG_RPrBase_caps: + rContext->Insert(ePropertyId, + uno::makeAny( nIntValue ? style::CaseMap::UPPERCASE : style::CaseMap::NONE)); + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "caps", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_EG_RPrBase_emboss: + rContext->Insert(ePropertyId, + uno::makeAny( nIntValue ? awt::FontRelief::EMBOSSED : awt::FontRelief::NONE )); + break; + + } + } + } + break; + case NS_ooxml::LN_EG_RPrBase_sz: + case NS_ooxml::LN_EG_RPrBase_szCs: + { + //multiples of half points (12pt == 24) + double fVal = double(nIntValue) / 2.; + uno::Any aVal = uno::makeAny( fVal ); + if( NS_ooxml::LN_EG_RPrBase_szCs == nSprmId ) + { + rContext->Insert( PROP_CHAR_HEIGHT_COMPLEX, aVal ); + } + else + { + const RubyInfo &aInfo = m_pImpl->GetRubyInfo(); + if (aInfo.nSprmId == NS_ooxml::LN_CT_Ruby_rt && aInfo.nHps > 0 ) + { + fVal = double(aInfo.nHps) / 2.; + aVal <<= fVal; + } + else if (aInfo.nSprmId == NS_ooxml::LN_CT_Ruby_rubyBase && aInfo.nHpsBaseText > 0 ) + { + fVal = double(aInfo.nHpsBaseText) / 2.; + aVal <<= fVal; + } + //Asian get the same value as Western + rContext->Insert( PROP_CHAR_HEIGHT, aVal ); + rContext->Insert( PROP_CHAR_HEIGHT_ASIAN, aVal ); + + uno::Reference xCharStyle(m_pImpl->GetCurrentNumberingCharStyle()); + if (xCharStyle.is()) + xCharStyle->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT), aVal); + } + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, (nSprmId == NS_ooxml::LN_EG_RPrBase_sz ? OUString("sz") : OUString("szCs")), OUString::number(nIntValue)); + } + break; + case NS_ooxml::LN_EG_RPrBase_position: + // The spec says 0 is the same as the lack of the value, so don't parse that. + if ( nIntValue ) + { + if ( !IsStyleSheetImport() ) + m_pImpl->deferCharacterProperty( nSprmId, uno::makeAny( nIntValue )); + else + { + // DON'T FIXME: Truly calculating this for Character Styles will be tricky, + // because it depends on the final fontsize - regardless of + // where it is set. So at the style level, + // the escapement value would need to be grabbagged. + // At appendText time the final fontsize needs to be determined, and then + // the escapement can be calculated from the grabbag'd half-point value + // and directly applied. Yuck. + // It seems best to just treat charstyle escapement like + // pre-commit e70df84352d3670508a4666c97df44f82c1ce934 + // which just assigned default values and ignored the actual/given escapement. + sal_Int16 nEscapement = nIntValue > 0 ? DFLT_ESC_AUTO_SUPER : DFLT_ESC_AUTO_SUB; + sal_Int8 nProp = DFLT_ESC_PROP; + rContext->Insert(PROP_CHAR_ESCAPEMENT, uno::makeAny( nEscapement ) ); + rContext->Insert(PROP_CHAR_ESCAPEMENT_HEIGHT, uno::makeAny( nProp ) ); + } + } + break; + case NS_ooxml::LN_EG_RPrBase_spacing: + { + //Kerning half point values + //TODO: there are two kerning values - + // in ww8par6.cxx NS_sprm::LN_CHpsKern is used as boolean AutoKerning + sal_Int16 nResult = static_cast(ConversionHelper::convertTwipToMM100(nIntValue)); + if (m_pImpl->IsInComments()) + { + nResult = static_cast(nIntValue); + } + rContext->Insert(PROP_CHAR_CHAR_KERNING, uno::makeAny(nResult)); + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "spacing", OUString::number(nIntValue)); + } + break; + case NS_ooxml::LN_EG_RPrBase_kern: // auto kerning is bound to a minimum font size in Word - but not in Writer :-( + rContext->Insert(PROP_CHAR_AUTO_KERNING, uno::makeAny( nIntValue != 0 ) ); + break; + case NS_ooxml::LN_EG_RPrBase_w: + // ST_TextScale must fall between 1% and 600% according to spec, otherwise resets to 100% according to experience + if ((1 <= nIntValue) && (nIntValue <= 600)) + { + rContext->Insert(PROP_CHAR_SCALE_WIDTH, + uno::makeAny( sal_Int16(nIntValue) )); + } + else + { + rContext->Insert(PROP_CHAR_SCALE_WIDTH, + uno::makeAny( sal_Int16(100) )); + } + break; + case NS_ooxml::LN_EG_RPrBase_imprint: + // FontRelief: NONE, EMBOSSED, ENGRAVED + rContext->Insert(PROP_CHAR_RELIEF, + uno::makeAny( nIntValue ? awt::FontRelief::ENGRAVED : awt::FontRelief::NONE )); + break; + case NS_ooxml::LN_EG_RPrBase_effect: + // The file-format has many character animations. We have only + // one, so we use it always. Suboptimal solution though. + if (nIntValue != NS_ooxml::LN_Value_ST_TextEffect_none) + rContext->Insert(PROP_CHAR_FLASH, uno::makeAny( true )); + else + rContext->Insert(PROP_CHAR_FLASH, uno::makeAny( false )); + break; + case NS_ooxml::LN_EG_RPrBase_rtl: + break; + case NS_ooxml::LN_EG_RPrBase_shd: + { + //contains fore color, back color and shadow percentage, results in a brush + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pCellColorHandler = std::make_shared(); + pCellColorHandler->setOutputFormat( CellColorHandler::Character ); + pProperties->resolve(*pCellColorHandler); + rContext->InsertProps(pCellColorHandler->getProperties().get()); + m_pImpl->GetTopContext()->Insert(PROP_CHAR_SHADING_MARKER, uno::makeAny(true), true, CHAR_GRAB_BAG ); + } + break; + } + case NS_ooxml::LN_EG_SectPrContents_type: + /* break type + 0 - No break + 1 - New Column + 2 - New page + 3 - Even page + 4 - odd page + */ + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + { + //continuous break only allowed if it is not the only section break + SectionPropertyMap* pLastContext = m_pImpl->GetLastSectionContext(); + if ( nIntValue != static_cast(NS_ooxml::LN_Value_ST_SectionMark_continuous) || pLastContext || m_pImpl->GetParaSectpr() ) + pSectionContext->SetBreakType( nIntValue ); + } + break; + case NS_ooxml::LN_EG_SectPrContents_titlePg: + { + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + pSectionContext->SetTitlePage( nIntValue > 0 );//section has title page + } + break; + case 165: + { + //page height, rounded to default values, default: 0x3dc0 twip + sal_Int32 nHeight = ConversionHelper::convertTwipToMM100( nIntValue ); + rContext->Insert( PROP_HEIGHT, uno::makeAny( PaperInfo::sloppyFitPageDimension( nHeight ) ) ); + } + break; + case NS_ooxml::LN_EG_SectPrContents_textDirection: + { + /* 0 HoriLR 1 Vert TR 2 Vert TR 3 Vert TT 4 HoriLT + only 0 and 1 can be imported correctly + */ + text::WritingMode nDirection = text::WritingMode_LR_TB; + switch( nIntValue ) + { + case NS_ooxml::LN_Value_ST_TextDirection_lrTb: + case NS_ooxml::LN_Value_ST_TextDirection_lrTbV: + nDirection = text::WritingMode_LR_TB; + break; + case NS_ooxml::LN_Value_ST_TextDirection_tbRl: + case NS_ooxml::LN_Value_ST_TextDirection_btLr: + nDirection = text::WritingMode_TB_RL; + break; + default:; + } + + PropertyMap * pTargetContext = rContext.get(); + + if (pSectionContext) + { + pTargetContext = pSectionContext; + } + + pTargetContext->Insert(PROP_WRITING_MODE, uno::makeAny( sal_Int16(nDirection) ) ); + } + break; // sprmSTextFlow + // the following are not part of the official documentation + case NS_ooxml::LN_CT_Tabs_tab: + resolveSprmProps(*this, rSprm); + m_pImpl->IncorporateTabStop(m_pImpl->m_aCurrentTabStop); + m_pImpl->m_aCurrentTabStop = DeletableTabStop(); + break; + case NS_ooxml::LN_CT_PPrBase_tabs: + { + // Initialize tab stop vector from style sheet + // fdo#81033: for RTF, a tab stop is inherited from the style if it + // is also applied to the paragraph directly, and cleared if it is + // not applied to the paragraph directly => don't InitTabStopFromStyle + if ( !IsRTFImport() ) + { + uno::Any aValue = m_pImpl->GetPropertyFromParaStyleSheet(PROP_PARA_TAB_STOPS); + uno::Sequence< style::TabStop > aStyleTabStops; + if(aValue >>= aStyleTabStops) + { + m_pImpl->InitTabStopFromStyle( aStyleTabStops ); + } + } + resolveSprmProps(*this, rSprm); + rContext->Insert(PROP_PARA_TAB_STOPS, uno::makeAny( m_pImpl->GetCurrentTabStopAndClear())); + } + break; + + case NS_ooxml::LN_CT_DocDefaults_pPrDefault: + case NS_ooxml::LN_CT_DocDefaults_rPrDefault: + GetStyleSheetTable()->sprm( rSprm ); + break; + case NS_ooxml::LN_EG_RPrBase_bdr: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pBorderHandler = std::make_shared( true ); + pProperties->resolve(*pBorderHandler); + + rContext->Insert( PROP_CHAR_TOP_BORDER, uno::makeAny( pBorderHandler->getBorderLine())); + rContext->Insert( PROP_CHAR_BOTTOM_BORDER, uno::makeAny( pBorderHandler->getBorderLine())); + rContext->Insert( PROP_CHAR_LEFT_BORDER, uno::makeAny( pBorderHandler->getBorderLine())); + rContext->Insert( PROP_CHAR_RIGHT_BORDER, uno::makeAny( pBorderHandler->getBorderLine())); + + rContext->Insert( PROP_CHAR_TOP_BORDER_DISTANCE, uno::makeAny( pBorderHandler->getLineDistance())); + rContext->Insert( PROP_CHAR_BOTTOM_BORDER_DISTANCE, uno::makeAny( pBorderHandler->getLineDistance())); + rContext->Insert( PROP_CHAR_LEFT_BORDER_DISTANCE, uno::makeAny( pBorderHandler->getLineDistance())); + rContext->Insert( PROP_CHAR_RIGHT_BORDER_DISTANCE, uno::makeAny( pBorderHandler->getLineDistance())); + + table::ShadowFormat aFormat; + // Word only allows shadows on visible borders + if ( pBorderHandler->getShadow() && pBorderHandler->getBorderLine().LineStyle != table::BorderLineStyle::NONE ) + aFormat = writerfilter::dmapper::PropertyMap::getShadowFromBorder(pBorderHandler->getBorderLine()); + rContext->Insert(PROP_CHAR_SHADOW_FORMAT, uno::makeAny(aFormat)); + } + } + break; + case NS_ooxml::LN_CT_PPr_sectPr: + case NS_ooxml::LN_EG_RPrBase_color: + case NS_ooxml::LN_EG_RPrBase_rFonts: + case NS_ooxml::LN_EG_RPrBase_eastAsianLayout: + case NS_ooxml::LN_EG_RPrBase_u: + case NS_ooxml::LN_EG_RPrBase_lang: + case NS_ooxml::LN_CT_PPrBase_spacing: + case NS_ooxml::LN_CT_PPrBase_ind: + case NS_ooxml::LN_CT_RPrDefault_rPr: + case NS_ooxml::LN_CT_PPrDefault_pPr: + case NS_ooxml::LN_CT_Style_pPr: + case NS_ooxml::LN_CT_Style_rPr: + case NS_ooxml::LN_CT_PPr_rPr: + case NS_ooxml::LN_CT_PPrBase_numPr: + { + bool bTempGrabBag = !m_pImpl->isInteropGrabBagEnabled(); + if (nSprmId == NS_ooxml::LN_CT_PPr_sectPr) + m_pImpl->SetParaSectpr(true); + else if (nSprmId == NS_ooxml::LN_EG_RPrBase_color && bTempGrabBag) + // if DomainMapper grab bag is not enabled, enable it temporarily + m_pImpl->enableInteropGrabBag("TempColorPropsGrabBag"); + resolveSprmProps(*this, rSprm); + if (nSprmId == NS_ooxml::LN_CT_PPrBase_spacing) + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "spacing", m_pImpl->m_aSubInteropGrabBag); + else if (nSprmId == NS_ooxml::LN_EG_RPrBase_rFonts) + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "rFonts", m_pImpl->m_aSubInteropGrabBag); + else if (nSprmId == NS_ooxml::LN_EG_RPrBase_lang) + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "lang", m_pImpl->m_aSubInteropGrabBag); + else if (nSprmId == NS_ooxml::LN_EG_RPrBase_color) + { + for (const auto& rItem : m_pImpl->m_aSubInteropGrabBag) + { + if (rItem.Name == "val") + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_ORIGINAL_COLOR, rItem.Value, true, CHAR_GRAB_BAG); + else if (rItem.Name == "themeColor") + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_COLOR, rItem.Value, true, CHAR_GRAB_BAG); + else if (rItem.Name == "themeShade") + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_COLOR_SHADE, rItem.Value, true, CHAR_GRAB_BAG); + else if (rItem.Name == "themeTint") + m_pImpl->GetTopContext()->Insert(PROP_CHAR_THEME_COLOR_TINT, rItem.Value, true, CHAR_GRAB_BAG); + } + if (bTempGrabBag) + //disable and clear DomainMapper grab bag if it wasn't enabled before + m_pImpl->disableInteropGrabBag(); + + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "color", m_pImpl->m_aSubInteropGrabBag); + } + else if (nSprmId == NS_ooxml::LN_CT_PPrBase_ind) + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ind", m_pImpl->m_aSubInteropGrabBag); + } + break; + case NS_ooxml::LN_CT_PPrBase_wordWrap: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "wordWrap", ""); + break; + case NS_ooxml::LN_EG_SectPrContents_footnotePr: + case NS_ooxml::LN_EG_SectPrContents_endnotePr: + m_pImpl->SetInFootnoteProperties( NS_ooxml::LN_EG_SectPrContents_footnotePr == nSprmId ); + resolveSprmProps(*this, rSprm); + break; + case NS_ooxml::LN_EG_SectPrContents_lnNumType: + { + resolveSprmProps(*this, rSprm); + LineNumberSettings aSettings = m_pImpl->GetLineNumberSettings(); + m_pImpl->SetLineNumberSettings( aSettings ); + //apply settings at XLineNumberingProperties + try + { + uno::Reference< text::XLineNumberingProperties > xLineNumberingProperties( m_pImpl->GetTextDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xLineNumberingPropSet = xLineNumberingProperties->getLineNumberingProperties(); + if( aSettings.nInterval == 0 ) + xLineNumberingPropSet->setPropertyValue(getPropertyName( PROP_IS_ON ), uno::makeAny(false) ); + else + { + xLineNumberingPropSet->setPropertyValue(getPropertyName( PROP_IS_ON ), uno::makeAny(true) ); + if( aSettings.nInterval ) + xLineNumberingPropSet->setPropertyValue(getPropertyName( PROP_INTERVAL ), uno::makeAny(static_cast(aSettings.nInterval)) ); + if( aSettings.nDistance != -1 ) + xLineNumberingPropSet->setPropertyValue(getPropertyName( PROP_DISTANCE ), uno::makeAny(aSettings.nDistance) ); + else + { + // set Auto value (0.5 cm) + xLineNumberingPropSet->setPropertyValue(getPropertyName( PROP_DISTANCE ), uno::makeAny(static_cast(500)) ); + if( pSectionContext ) + pSectionContext->SetdxaLnn( static_cast(283) ); + } + xLineNumberingPropSet->setPropertyValue(getPropertyName( PROP_RESTART_AT_EACH_PAGE ), uno::makeAny(aSettings.bRestartAtEachPage) ); + } + } + catch( const uno::Exception& ) + { + } + + } + break; + case NS_ooxml::LN_CT_PPrBase_framePr: + // Avoid frames if we're inside a structured document tag, would just cause outer tables fail to create. + if (!m_pImpl->GetSdt()) + { + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH); + if( pContext ) + { + // If there is a deferred page break applied to this framed paragraph, + // create a dummy paragraph without extra properties, + // so that the anchored frame will be on the correct page (similar to shapes). + if (pContext->isSet(PROP_BREAK_TYPE)) + { + pContext->Erase(PROP_BREAK_TYPE); + + lcl_startParagraphGroup(); + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); + lcl_startCharacterGroup(); + sal_uInt8 const sBreak[] = { 0xd }; + lcl_text(sBreak, 1); + lcl_endCharacterGroup(); + lcl_endParagraphGroup(); + } + + ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pContext.get() ); + if (pParaContext) + pParaContext->SetFrameMode(); + + if (!IsInHeaderFooter()) + m_pImpl->m_bIsActualParagraphFramed = true; + } + else + { + //TODO: What about style sheet import of frame properties + } + resolveSprmProps(*this, rSprm); + } + break; + case NS_ooxml::LN_EG_SectPrContents_pgSz: + { + PaperInfo aLetter(PAPER_LETTER); + CT_PageSz.w = aLetter.getWidth(); + CT_PageSz.h = aLetter.getHeight(); + } + CT_PageSz.orient = false; + resolveSprmProps(*this, rSprm); + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + { + pSectionContext->Insert( PROP_HEIGHT, uno::makeAny( CT_PageSz.h ) ); + pSectionContext->Insert( PROP_IS_LANDSCAPE, uno::makeAny( CT_PageSz.orient )); + pSectionContext->Insert( PROP_WIDTH, uno::makeAny( CT_PageSz.w ) ); + } + break; + + case NS_ooxml::LN_EG_SectPrContents_pgMar: + m_pImpl->InitPageMargins(); + resolveSprmProps(*this, rSprm); + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + { + const PageMar& rPageMar = m_pImpl->GetPageMargins(); + pSectionContext->SetTopMargin( rPageMar.top ); + pSectionContext->SetRightMargin( rPageMar.right ); + pSectionContext->SetBottomMargin( rPageMar.bottom ); + pSectionContext->SetLeftMargin( rPageMar.left ); + pSectionContext->SetHeaderTop( rPageMar.header ); + pSectionContext->SetHeaderBottom( rPageMar.footer ); + } + break; + + case NS_ooxml::LN_EG_SectPrContents_cols: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + + tools::SvRef< SectionColumnHandler > pSectHdl( new SectionColumnHandler ); + pProperties->resolve(*pSectHdl); + if(pSectionContext && !m_pImpl->isInIndexContext()) + { + if( pSectHdl->IsEqualWidth() ) + { + pSectionContext->SetEvenlySpaced( true ); + pSectionContext->SetColumnCount( static_cast(pSectHdl->GetNum() - 1) ); + pSectionContext->SetColumnDistance( pSectHdl->GetSpace() ); + pSectionContext->SetSeparatorLine( pSectHdl->IsSeparator() ); + } + else if( !pSectHdl->GetColumns().empty() ) + { + pSectionContext->SetEvenlySpaced( false ); + pSectionContext->SetColumnDistance( pSectHdl->GetSpace() ); + pSectionContext->SetColumnCount( static_cast(pSectHdl->GetColumns().size() -1)); + std::vector::const_iterator tmpIter = pSectHdl->GetColumns().begin(); + for (; tmpIter != pSectHdl->GetColumns().end(); ++tmpIter) + { + pSectionContext->AppendColumnWidth( tmpIter->nWidth ); + if ((tmpIter != pSectHdl->GetColumns().end() - 1) || (tmpIter->nSpace > 0)) + pSectionContext->AppendColumnSpacing( tmpIter->nSpace ); + } + pSectionContext->SetSeparatorLine( pSectHdl->IsSeparator() ); + } + else if( pSectHdl->GetNum() > 0 ) + { + pSectionContext->SetColumnCount( static_cast(pSectHdl->GetNum()) - 1 ); + pSectionContext->SetColumnDistance( pSectHdl->GetSpace() ); + pSectionContext->SetSeparatorLine( pSectHdl->IsSeparator() ); + } + } + + else if ( pSectionContext ) + { + FieldContextPtr pContext = m_pImpl->GetTopFieldContext(); + uno::Reference< beans::XPropertySet > xTOC = pContext->GetTOC(); + if( xTOC.is() ) + { + uno::Reference xTextColumns; + xTOC->getPropertyValue(getPropertyName( PROP_TEXT_COLUMNS )) >>= xTextColumns; + if (xTextColumns.is()) + { + uno::Reference< beans::XPropertySet > xColumnPropSet( xTextColumns, uno::UNO_QUERY_THROW ); + xColumnPropSet->setPropertyValue( getPropertyName( PROP_AUTOMATIC_DISTANCE ), uno::makeAny( pSectHdl->GetSpace() )); + xTOC->setPropertyValue( getPropertyName( PROP_TEXT_COLUMNS ), uno::makeAny( xTextColumns ) ); + } + } + } + } + } + break; + case NS_ooxml::LN_EG_SectPrContents_docGrid: + resolveSprmProps(*this, rSprm); + break; + case NS_ooxml::LN_EG_SectPrContents_pgBorders: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties && pSectionContext ) + { + tools::SvRef< PageBordersHandler > pHandler( new PageBordersHandler ); + pProperties->resolve( *pHandler ); + + // Set the borders to the context and apply them to the styles + pHandler->SetBorders( pSectionContext ); + } + } + break; + + case NS_ooxml::LN_CT_PPrBase_snapToGrid: + if (!IsStyleSheetImport()||!m_pImpl->isInteropGrabBagEnabled()) + { + rContext->Insert( PROP_SNAP_TO_GRID, uno::makeAny(bool(nIntValue))); + } + else + { + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "snapToGrid", OUString::number(nIntValue)); + } + break; + case NS_ooxml::LN_CT_PPrBase_pStyle: + { + StyleSheetTablePtr pStyleTable = m_pImpl->GetStyleSheetTable(); + const OUString sConvertedStyleName = pStyleTable->ConvertStyleName( sStringValue, true ); + m_pImpl->SetCurrentParaStyleName( sConvertedStyleName ); + if (m_pImpl->GetTopContext() && m_pImpl->GetTopContextType() != CONTEXT_SECTION) + m_pImpl->GetTopContext()->Insert( PROP_PARA_STYLE_NAME, uno::makeAny( sConvertedStyleName )); + } + break; + case NS_ooxml::LN_EG_RPrBase_rStyle: + { + OUString sConvertedName( m_pImpl->GetStyleSheetTable()->ConvertStyleName( sStringValue, true ) ); + if (m_pImpl->CheckFootnoteStyle()) + m_pImpl->SetHasFootnoteStyle(m_pImpl->GetFootnoteContext()->GetFootnoteStyle() == sConvertedName); + + // First check if the style exists in the document. + StyleSheetEntryPtr pEntry = m_pImpl->GetStyleSheetTable( )->FindStyleSheetByConvertedStyleName( sConvertedName ); + bool bExists = pEntry && ( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR ); + // Add the property if the style exists, but do not add it elements in TOC: + // they will receive later another style references from TOC + if ( bExists && m_pImpl->GetTopContext() && !m_pImpl->IsInTOC()) + m_pImpl->GetTopContext()->Insert( PROP_CHAR_STYLE_NAME, uno::makeAny( sConvertedName ) ); + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins + { + resolveSprmProps(*this, rSprm);//contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right + } + break; + case NS_ooxml::LN_CT_TblCellMar_top: + case NS_ooxml::LN_CT_TblCellMar_start: + case NS_ooxml::LN_CT_TblCellMar_left: + case NS_ooxml::LN_CT_TblCellMar_bottom: + case NS_ooxml::LN_CT_TblCellMar_end: + case NS_ooxml::LN_CT_TblCellMar_right: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + MeasureHandlerPtr pMeasureHandler( new MeasureHandler ); + pProperties->resolve(*pMeasureHandler); + sal_Int32 nMeasureValue = pMeasureHandler->getMeasureValue(); + PropertyIds eId = META_PROP_CELL_MAR_TOP; + bool rtl = false; // TODO + switch(nSprmId) + { + case NS_ooxml::LN_CT_TblCellMar_top: + break; + case NS_ooxml::LN_CT_TblCellMar_start: + eId = rtl ? META_PROP_CELL_MAR_RIGHT : META_PROP_CELL_MAR_LEFT; + break; + case NS_ooxml::LN_CT_TblCellMar_left: + eId = META_PROP_CELL_MAR_LEFT; + break; + case NS_ooxml::LN_CT_TblCellMar_bottom: + eId = META_PROP_CELL_MAR_BOTTOM; + break; + case NS_ooxml::LN_CT_TblCellMar_end: + eId = rtl ? META_PROP_CELL_MAR_LEFT : META_PROP_CELL_MAR_RIGHT; + break; + case NS_ooxml::LN_CT_TblCellMar_right: + eId = META_PROP_CELL_MAR_RIGHT; + break; + default:; + } + rContext->Insert( eId, uno::makeAny(nMeasureValue), false); + } + } + break; + case NS_ooxml::LN_EG_RPrBase_noProof: // no grammar and spell checking, unsupported + break; + case NS_ooxml::LN_anchor_anchor: // at_character drawing + case NS_ooxml::LN_inline_inline: // as_character drawing + { + if ( m_pImpl->IsDiscardHeaderFooter() ) + break; + //tdf112342: Break before images as well, if there are page break + if (m_pImpl->isBreakDeferred(BreakType::PAGE_BREAK)) + { + m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH) + ->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); + m_pImpl->clearDeferredBreak(PAGE_BREAK); + } + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + GraphicImportType eGraphicType = + (NS_ooxml::LN_anchor_anchor == + sal::static_int_cast(nSprmId)) ? + IMPORT_AS_DETECTED_ANCHOR : + IMPORT_AS_DETECTED_INLINE; + GraphicImportPtr pGraphicImport = + m_pImpl->GetGraphicImport(eGraphicType); + pProperties->resolve(*pGraphicImport); + m_pImpl->ImportGraphic(pProperties, eGraphicType); + if( !pGraphicImport->IsGraphic() ) + { + m_pImpl->ResetGraphicImport(); + // todo: It's a shape, now start shape import + } + } + } + break; + case NS_ooxml::LN_EG_RPrBase_vertAlign: + { + sal_Int16 nEscapement = 0; + sal_Int8 nProp = DFLT_ESC_PROP; + if ( sStringValue == "superscript" ) + nEscapement = DFLT_ESC_AUTO_SUPER; + else if ( sStringValue == "subscript" ) + nEscapement = DFLT_ESC_AUTO_SUB; + else + nProp = 100; + + rContext->Insert(PROP_CHAR_ESCAPEMENT, uno::makeAny( nEscapement ) ); + rContext->Insert(PROP_CHAR_ESCAPEMENT_HEIGHT, uno::makeAny( nProp ) ); + } + break; + case NS_ooxml::LN_CT_FtnProps_pos: + //footnotes in word can be at page end or beneath text - writer supports only the first + //endnotes in word can be at section end or document end - writer supports only the latter + // -> so this property can be ignored + break; + case NS_ooxml::LN_CT_FtnProps_numFmt: + case NS_ooxml::LN_CT_EdnProps_numFmt: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + pProperties->resolve(*this); + } + } + break; + case NS_ooxml::LN_EG_FtnEdnNumProps_numStart: + case NS_ooxml::LN_EG_FtnEdnNumProps_numRestart: + { + try + { + uno::Reference< beans::XPropertySet > xFtnEdnSettings; + if( m_pImpl->IsInFootnoteProperties() ) + { + uno::Reference< text::XFootnotesSupplier> xFootnotesSupplier( m_pImpl->GetTextDocument(), uno::UNO_QUERY ); + if (xFootnotesSupplier.is()) + xFtnEdnSettings = xFootnotesSupplier->getFootnoteSettings(); + } + else + { + uno::Reference< text::XEndnotesSupplier> xEndnotesSupplier( m_pImpl->GetTextDocument(), uno::UNO_QUERY ); + if (xEndnotesSupplier.is()) + xFtnEdnSettings = xEndnotesSupplier->getEndnoteSettings(); + } + if( NS_ooxml::LN_EG_FtnEdnNumProps_numStart == nSprmId && xFtnEdnSettings.is()) + { + xFtnEdnSettings->setPropertyValue( + getPropertyName( PROP_START_AT), + uno::makeAny( sal_Int16( nIntValue - 1 ))); + } + else if( NS_ooxml::LN_EG_FtnEdnNumProps_numRestart == nSprmId && xFtnEdnSettings.is()) + { + sal_Int16 nFootnoteCounting = 0; + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_RestartNumber_continuous: nFootnoteCounting = text::FootnoteNumbering::PER_DOCUMENT; break; + case NS_ooxml::LN_Value_ST_RestartNumber_eachPage: nFootnoteCounting = text::FootnoteNumbering::PER_PAGE; break; + case NS_ooxml::LN_Value_ST_RestartNumber_eachSect: nFootnoteCounting = text::FootnoteNumbering::PER_CHAPTER; break; + default: break; + } + xFtnEdnSettings->setPropertyValue( + getPropertyName( PROP_FOOTNOTE_COUNTING ), + uno::makeAny( nFootnoteCounting )); + } + else if (xFtnEdnSettings.is()) + { + sal_Int16 nNumType = ConversionHelper::ConvertNumberingType( nIntValue ); + xFtnEdnSettings->setPropertyValue( + getPropertyName( PROP_NUMBERING_TYPE), + uno::makeAny( nNumType )); + } + } + catch( const uno::Exception& ) + { + } + } + break; + case NS_ooxml::LN_paratrackchange: + m_pImpl->StartParaMarkerChange( ); + [[fallthrough]]; + case NS_ooxml::LN_CT_PPr_pPrChange: + case NS_ooxml::LN_CT_ParaRPr_rPrChange: + case NS_ooxml::LN_trackchange: + case NS_ooxml::LN_EG_RPrContent_rPrChange: + case NS_ooxml::LN_EG_RangeMarkupElements_customXmlDelRangeStart: + case NS_ooxml::LN_EG_RangeMarkupElements_customXmlDelRangeEnd: + case NS_ooxml::LN_EG_RangeMarkupElements_customXmlMoveFromRangeStart: + case NS_ooxml::LN_EG_RangeMarkupElements_customXmlMoveFromRangeEnd: + case NS_ooxml::LN_EG_RangeMarkupElements_customXmlMoveToRangeStart: + case NS_ooxml::LN_EG_RangeMarkupElements_customXmlMoveToRangeEnd: + { + HandleRedline( rSprm ); + } + break; + case NS_ooxml::LN_endtrackchange: + m_pImpl->RemoveTopRedline(); + break; + case NS_ooxml::LN_CT_RPrChange_rPr: + { + // Push all the current 'Character' properties to the stack, so that we don't store them + // as 'tracked changes' by mistake + m_pImpl->PushProperties(CONTEXT_CHARACTER); + + // Resolve all the properties that are under the 'rPrChange'->'rPr' XML node + resolveSprmProps(*this, rSprm ); + + // Get all the properties that were processed in the 'rPrChange'->'rPr' XML node + uno::Sequence< beans::PropertyValue > currentRedlineRevertProperties = m_pImpl->GetTopContext()->GetPropertyValues(); + + // Pop back out the character properties that were on the run + m_pImpl->PopProperties(CONTEXT_CHARACTER); + + // Store these properties in the current redline object (do it after the PopProperties() above, since + // otherwise it'd be stored in the content dropped there). + m_pImpl->SetCurrentRedlineRevertProperties( currentRedlineRevertProperties ); + } + break; + case NS_ooxml::LN_CT_PPrChange_pPr: + { + // Push all the current 'Paragraph' properties to the stack, so that we don't store them + // as 'tracked changes' by mistake + m_pImpl->PushProperties(CONTEXT_PARAGRAPH); + + // Resolve all the properties that are under the 'pPrChange'->'pPr' XML node + resolveSprmProps(*this, rSprm ); + + // Get all the properties that were processed in the 'pPrChange'->'pPr' XML node + uno::Sequence< beans::PropertyValue > currentRedlineRevertProperties = m_pImpl->GetTopContext()->GetPropertyValues(); + + // Pop back out the character properties that were on the run + m_pImpl->PopProperties(CONTEXT_PARAGRAPH); + + // Store these properties in the current redline object (do it after the PopProperties() above, since + // otherwise it'd be stored in the content dropped there). + m_pImpl->SetCurrentRedlineRevertProperties( currentRedlineRevertProperties ); + } + break; + case NS_ooxml::LN_object: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pOLEHandler = std::make_shared(*this); + pProperties->resolve(*pOLEHandler); + if ( pOLEHandler->isOLEObject( ) ) + { + OUString sStreamName = pOLEHandler->copyOLEOStream( m_pImpl->GetTextDocument() ); + if( !sStreamName.isEmpty() ) + { + m_pImpl->appendOLE( sStreamName, pOLEHandler ); + } + } + } + } + break; + case NS_ooxml::LN_EG_HdrFtrReferences_headerReference: // header reference - not needed + case NS_ooxml::LN_EG_HdrFtrReferences_footerReference: // footer reference - not needed + break; + case NS_ooxml::LN_EG_RPrBase_snapToGrid: // "Use document grid settings for inter-paragraph spacing" + break; + case NS_ooxml::LN_CT_PPrBase_contextualSpacing: + rContext->Insert(PROP_PARA_CONTEXT_MARGIN, uno::makeAny( nIntValue != 0 )); + break; + case NS_ooxml::LN_CT_PPrBase_mirrorIndents: // mirrorIndents + rContext->Insert(PROP_MIRROR_INDENTS, uno::makeAny( nIntValue != 0 ), true, PARA_GRAB_BAG); + break; + case NS_ooxml::LN_EG_SectPrContents_formProt: //section protection + { + if( pSectionContext ) + pSectionContext->Insert( PROP_IS_PROTECTED, uno::makeAny( bool(nIntValue) ) ); + } + break; + case NS_ooxml::LN_EG_SectPrContents_vAlign: + { + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if( pSectionContext ) + { + drawing::TextVerticalAdjust nVA = drawing::TextVerticalAdjust_TOP; + switch( nIntValue ) + { + case NS_ooxml::LN_Value_ST_VerticalJc_center: //92367 + nVA = drawing::TextVerticalAdjust_CENTER; + break; + case NS_ooxml::LN_Value_ST_VerticalJc_both: //92368 - justify + nVA = drawing::TextVerticalAdjust_BLOCK; + break; + case NS_ooxml::LN_Value_ST_VerticalJc_bottom: //92369 + nVA = drawing::TextVerticalAdjust_BOTTOM; + break; + default: + break; + } + pSectionContext->Insert( PROP_TEXT_VERTICAL_ADJUST, uno::makeAny( nVA ), true, PARA_GRAB_BAG ); + } + } + break; + case NS_ooxml::LN_EG_RPrBase_fitText: + break; + case NS_ooxml::LN_ffdata: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties.get() != nullptr) + { + FFDataHandler::Pointer_t pFFDataHandler(new FFDataHandler()); + + pProperties->resolve(*pFFDataHandler); + m_pImpl->SetFieldFFData(pFFDataHandler); + } + } + break; + case NS_ooxml::LN_CT_SdtPr_dropDownList: + case NS_ooxml::LN_CT_SdtPr_comboBox: + { + m_pImpl->m_pSdtHelper->setInsideDropDownControl(true); + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties.get() != nullptr) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_SdtDropDownList_listItem: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties.get() != nullptr) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_SdtPr_date: + { + resolveSprmProps(*this, rSprm); + m_pImpl->m_pSdtHelper->setDateFieldStartRange(GetCurrentTextRange()->getEnd()); + } + break; + case NS_ooxml::LN_CT_SdtDate_dateFormat: + { + m_pImpl->m_pSdtHelper->getDateFormat().append(sStringValue); + } + break; + case NS_ooxml::LN_CT_SdtDate_storeMappedDataAs: + { + } + break; + case NS_ooxml::LN_CT_SdtDate_calendar: + { + } + break; + case NS_ooxml::LN_CT_SdtDate_lid: + { + m_pImpl->m_pSdtHelper->getLocale().append(sStringValue); + } + break; + case NS_ooxml::LN_CT_SdtPr_dataBinding: + case NS_ooxml::LN_CT_SdtPr_equation: + case NS_ooxml::LN_CT_SdtPr_checkbox: + case NS_ooxml::LN_CT_SdtPr_docPartObj: + case NS_ooxml::LN_CT_SdtPr_docPartList: + case NS_ooxml::LN_CT_SdtPr_picture: + case NS_ooxml::LN_CT_SdtPr_citation: + case NS_ooxml::LN_CT_SdtPr_group: + case NS_ooxml::LN_CT_SdtPr_text: + case NS_ooxml::LN_CT_SdtPr_id: + case NS_ooxml::LN_CT_SdtPr_alias: + { + // this is an unsupported SDT property, create a grab bag for it + OUString sName; + switch (nSprmId) + { + case NS_ooxml::LN_CT_SdtPr_dataBinding: sName = "ooxml:CT_SdtPr_dataBinding"; break; + case NS_ooxml::LN_CT_SdtPr_equation: sName = "ooxml:CT_SdtPr_equation"; break; + case NS_ooxml::LN_CT_SdtPr_checkbox: sName = "ooxml:CT_SdtPr_checkbox"; break; + case NS_ooxml::LN_CT_SdtPr_docPartObj: sName = "ooxml:CT_SdtPr_docPartObj"; break; + case NS_ooxml::LN_CT_SdtPr_docPartList: sName = "ooxml:CT_SdtPr_docPartList"; break; + case NS_ooxml::LN_CT_SdtPr_picture: sName = "ooxml:CT_SdtPr_picture"; break; + case NS_ooxml::LN_CT_SdtPr_citation: sName = "ooxml:CT_SdtPr_citation"; break; + case NS_ooxml::LN_CT_SdtPr_group: sName = "ooxml:CT_SdtPr_group"; break; + case NS_ooxml::LN_CT_SdtPr_text: sName = "ooxml:CT_SdtPr_text"; break; + case NS_ooxml::LN_CT_SdtPr_id: sName = "ooxml:CT_SdtPr_id"; break; + case NS_ooxml::LN_CT_SdtPr_alias: sName = "ooxml:CT_SdtPr_alias"; break; + default: assert(false); + }; + enableInteropGrabBag(sName); + + // process subitems + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties.get() != nullptr) + pProperties->resolve(*this); + + if (nSprmId == NS_ooxml::LN_CT_SdtPr_alias) + { + beans::PropertyValue aValue; + aValue.Name = sName; + aValue.Value <<= sStringValue; + m_pImpl->m_pSdtHelper->appendToInteropGrabBag(aValue); + } + else + m_pImpl->m_pSdtHelper->appendToInteropGrabBag(getInteropGrabBag()); + m_pImpl->m_pSdtHelper->setOutsideAParagraph(m_pImpl->IsOutsideAParagraph()); + m_pImpl->disableInteropGrabBag(); + } + break; + case NS_ooxml::LN_CT_SdtCheckbox_checked: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtCheckbox_checked", sStringValue); + break; + case NS_ooxml::LN_CT_SdtCheckbox_checkedState: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtCheckbox_checkedState", sStringValue); + break; + case NS_ooxml::LN_CT_SdtCheckbox_uncheckedState: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtCheckbox_uncheckedState", sStringValue); + break; + case NS_ooxml::LN_CT_SdtDocPart_docPartGallery: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtDocPart_docPartGallery", sStringValue); + break; + case NS_ooxml::LN_CT_SdtDocPart_docPartCategory: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtDocPart_docPartCategory", sStringValue); + break; + case NS_ooxml::LN_CT_SdtDocPart_docPartUnique: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_SdtDocPart_docPartUnique", sStringValue); + break; + case NS_ooxml::LN_EG_SectPrContents_pgNumType: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + pProperties->resolve(*this); + } + } + break; + case NS_ooxml::LN_tblStart: + { + if (m_pImpl->hasTableManager()) + { + bool bTableStartsAtCellStart = m_pImpl->m_nTableDepth > 0 && m_pImpl->m_nTableCellDepth > m_pImpl->m_nLastTableCellParagraphDepth + 1; + m_pImpl->getTableManager().setTableStartsAtCellStart(bTableStartsAtCellStart); + } + /* + * Hack for Importing Section Properties + * LO is not able to import section properties if first element in the + * section is a table. So in case first element is a table add a dummy para + * and remove it again when lcl_endSectionGroup is called + */ + if(m_pImpl->m_nTableDepth == 0 && m_pImpl->GetIsFirstParagraphInSection() + && !m_pImpl->GetIsDummyParaAddedForTableInSection() && !m_pImpl->GetIsTextFrameInserted() + && !IsInHeaderFooter()) + { + m_pImpl->AddDummyParaForTableInSection(); + } + + // if first paragraph style in table has break-before-page, transfer that setting to the table itself. + if( m_pImpl->m_nTableDepth == 0 ) + { + const uno::Any aBreakType = uno::makeAny(style::BreakType_PAGE_BEFORE); + const PropertyMapPtr pParagraphProps = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH); + if( pParagraphProps && pParagraphProps->isSet(PROP_PARA_STYLE_NAME) ) + { + StyleSheetEntryPtr pStyle; + OUString sStyleName; + pParagraphProps->getProperty(PROP_PARA_STYLE_NAME)->second >>= sStyleName; + if( !sStyleName.isEmpty() && GetStyleSheetTable() ) + pStyle = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( sStyleName ); + + if( pStyle && pStyle->pProperties + && pStyle->pProperties->isSet(PROP_BREAK_TYPE) + && pStyle->pProperties->getProperty(PROP_BREAK_TYPE)->second == aBreakType ) + { + pParagraphProps->Insert(PROP_BREAK_TYPE, aBreakType); + } + } + } + + m_pImpl->m_nTableDepth++; + } + break; + case NS_ooxml::LN_tblEnd: + m_pImpl->m_nTableDepth--; + break; + case NS_ooxml::LN_tcStart: + m_pImpl->m_nTableCellDepth++; + break; + case NS_ooxml::LN_tcEnd: + m_pImpl->m_nTableCellDepth--; + m_pImpl->m_nLastTableCellParagraphDepth = 0; + break; + case NS_ooxml::LN_glow_glow: + case NS_ooxml::LN_shadow_shadow: + case NS_ooxml::LN_reflection_reflection: + case NS_ooxml::LN_textOutline_textOutline: + case NS_ooxml::LN_textFill_textFill: + case NS_ooxml::LN_scene3d_scene3d: + case NS_ooxml::LN_props3d_props3d: + case NS_ooxml::LN_ligatures_ligatures: + case NS_ooxml::LN_numForm_numForm: + case NS_ooxml::LN_numSpacing_numSpacing: + case NS_ooxml::LN_stylisticSets_stylisticSets: + case NS_ooxml::LN_cntxtAlts_cntxtAlts: + { + tools::SvRef pTextEffectsHandlerPtr( new TextEffectsHandler(nSprmId) ); + std::optional aPropertyId = pTextEffectsHandlerPtr->getGrabBagPropertyId(); + if(aPropertyId) + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + pProperties->resolve(*pTextEffectsHandlerPtr); + + beans::PropertyValue aGrabBag = pTextEffectsHandlerPtr->getInteropGrabBag(); + rContext->Insert(*aPropertyId, uno::makeAny(aGrabBag), true, CHAR_GRAB_BAG); + + sal_Int16 nTransparency = TextEffectsHandler::GetTextFillSolidFillAlpha(aGrabBag); + if (nTransparency != 0) + { + rContext->Insert(PROP_CHAR_TRANSPARENCE, uno::makeAny(nTransparency)); + } + } + } + } + break; + case NS_ooxml::LN_CT_SdtPr_rPr: + { + // Make sure properties from a previous SDT are not merged with the current ones. + m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear(); + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblLook: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + pProperties->resolve(*this); + m_pImpl->getTableManager().finishTableLook(); + } + } + break; + case NS_ooxml::LN_CT_TrPrBase_cnfStyle: + { + m_pImpl->enableInteropGrabBag("cnfStyle"); + resolveSprmProps(*this, rSprm); + + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(PROP_ROW_CNF_STYLE, uno::makeAny(comphelper::containerToSequence(m_pImpl->m_aInteropGrabBag)), true, ROW_GRAB_BAG); + m_pImpl->getTableManager().insertRowProps(pPropMap); + + m_pImpl->disableInteropGrabBag(); + } + break; + case NS_ooxml::LN_CT_TcPrBase_cnfStyle: + { + m_pImpl->enableInteropGrabBag("cnfStyle"); + resolveSprmProps(*this, rSprm); + + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(PROP_CELL_CNF_STYLE, uno::makeAny(comphelper::containerToSequence(m_pImpl->m_aInteropGrabBag)), true, CELL_GRAB_BAG); + m_pImpl->getTableManager().cellProps(pPropMap); + + m_pImpl->disableInteropGrabBag(); + } + break; + case NS_ooxml::LN_CT_PPrBase_cnfStyle: + { + m_pImpl->enableInteropGrabBag("cnfStyle"); + resolveSprmProps(*this, rSprm); + rContext->Insert(PROP_PARA_CNF_STYLE, uno::makeAny(comphelper::containerToSequence(m_pImpl->m_aInteropGrabBag)), true, PARA_GRAB_BAG); + m_pImpl->disableInteropGrabBag(); + } + break; + case NS_ooxml::LN_EG_RunInnerContent_sym: + { + resolveSprmProps(*this, rSprm); + SymbolData aSymbolData = m_pImpl->GetSymbolData(); + uno::Any aVal = uno::makeAny( aSymbolData.sFont ); + auto xFootnote = rContext->GetFootnote(); + if (!xFootnote.is() && m_pImpl->IsInCustomFootnote()) + xFootnote = m_pImpl->GetFootnoteContext()->GetFootnote(); + if (xFootnote.is()) + { + // DOCX can have different labels for the footnote reference and the footnote area. + // This skips the one from the footnote area and just uses the reference one. + if (!m_pImpl->IsInFootOrEndnote()) + { + auto xAnchorRange = xFootnote->getAnchor(); + auto xAnchorCursor(xAnchorRange->getText()->createTextCursorByRange(xAnchorRange)); + + // append a dummy character, so the following properties will be set as + // as SwpHints::SwTextAttr instead of the SwAttrSet of the paragraph, + // which would be removed by SwXText::Impl::finishOrAppendParagraph + xAnchorCursor->collapseToEnd(); + uno::Reference xHackRange(xAnchorCursor, uno::UNO_QUERY); + xHackRange->setString("x"); + + uno::Reference xAnchorProps(xAnchorRange, uno::UNO_QUERY); + xAnchorProps->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), aVal); + xAnchorProps->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_ASIAN), aVal); + xAnchorProps->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_COMPLEX), aVal); + xAnchorProps->setPropertyValue(getPropertyName(PROP_CHAR_FONT_CHAR_SET), uno::makeAny(awt::CharSet::SYMBOL)); + + // remove the dummy char + xHackRange->setString(""); + + OUString sLabel = xFootnote->getLabel() + OUStringChar(aSymbolData.cSymbol); + xFootnote->setLabel(sLabel); + } + } + else //it's a _real_ symbol + { + rContext->Insert(PROP_CHAR_FONT_NAME, aVal); + rContext->Insert(PROP_CHAR_FONT_NAME_ASIAN, aVal); + rContext->Insert(PROP_CHAR_FONT_NAME_COMPLEX, aVal); + rContext->Insert(PROP_CHAR_FONT_CHAR_SET, uno::makeAny(awt::CharSet::SYMBOL)); + utext( reinterpret_cast < const sal_uInt8 * >( &(aSymbolData.cSymbol) ), 1 ); + } + } + break; + case NS_ooxml::LN_EG_RunInnerContent_ruby: + { + RubyInfo aInfo ; + m_pImpl->SetRubyInfo(aInfo); + } + break; + case NS_ooxml::LN_CT_RubyPr: + case NS_ooxml::LN_CT_Ruby_rt: + case NS_ooxml::LN_CT_Ruby_rubyBase: + { + m_pImpl->SetRubySprmId(nSprmId); + if (nSprmId == NS_ooxml::LN_CT_RubyPr) + { + resolveSprmProps(*this, rSprm); + } + } + break; + case NS_ooxml::LN_EG_RubyContent_r: + { + const RubyInfo & aInfo = m_pImpl->GetRubyInfo(); + if (aInfo.nSprmId == NS_ooxml::LN_CT_Ruby_rubyBase) + { + rContext->Insert(PROP_RUBY_TEXT, uno::makeAny(aInfo.sRubyText)); + rContext->Insert(PROP_RUBY_STYLE, uno::makeAny(aInfo.sRubyStyle)); + rContext->Insert(PROP_RUBY_ADJUST, uno::makeAny(static_cast(ConversionHelper::convertRubyAlign(aInfo.nRubyAlign)))); + if ( aInfo.nRubyAlign == NS_ooxml::LN_Value_ST_RubyAlign_rightVertical ) + rContext->Insert(PROP_RUBY_POSITION, uno::makeAny(css::text::RubyPosition::INTER_CHARACTER)); + + m_pImpl->SetRubySprmId(0); + } + } + break; + case NS_ooxml::LN_CT_RubyPr_rubyAlign: + case NS_ooxml::LN_CT_RubyPr_hps: + case NS_ooxml::LN_CT_RubyPr_hpsBaseText: + { + RubyInfo aInfo = m_pImpl->GetRubyInfo(); + switch(nSprmId) + { + case NS_ooxml::LN_CT_RubyPr_rubyAlign: + aInfo.nRubyAlign = nIntValue; + break; + case NS_ooxml::LN_CT_RubyPr_hps: + aInfo.nHps= nIntValue; + break; + case NS_ooxml::LN_CT_RubyPr_hpsBaseText: + aInfo.nHpsBaseText = nIntValue; + break; + } + m_pImpl->SetRubyInfo(aInfo); + } + break; + case NS_ooxml::LN_CT_SmartTagRun_smartTagPr: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties && m_pImpl->GetTopContextType() == CONTEXT_PARAGRAPH) + pProperties->resolve(m_pImpl->getSmartTagHandler()); + } + break; + case NS_ooxml::LN_CT_DocPartPr_name: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties.get() != nullptr) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_DocPartPr_category: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties.get() != nullptr) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_DocPartCategory_gallery: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties.get() != nullptr) + pProperties->resolve(*this); + } + break; + default: + { +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("unhandled"); + TagLogger::getInstance().attribute("id", nSprmId); + TagLogger::getInstance().attribute("name", rSprm.getName()); + TagLogger::getInstance().endElement(); +#endif + } + } +} + +void DomainMapper::processDeferredCharacterProperties( const std::map< sal_Int32, uno::Any >& deferredCharacterProperties ) +{ + assert( m_pImpl->GetTopContextType() == CONTEXT_CHARACTER ); + PropertyMapPtr rContext = m_pImpl->GetTopContext(); + for( const auto& rProp : deferredCharacterProperties ) + { + sal_Int32 Id = rProp.first; + sal_Int32 nIntValue = 0; + OUString sStringValue; + rProp.second >>= nIntValue; + rProp.second >>= sStringValue; + switch( Id ) + { + case NS_ooxml::LN_EG_RPrBase_position: + { + double nEscapement = 0; + sal_Int8 nProp = 0; + if ( nIntValue ) + { + nProp = 100; + double fFontSize = 0; + m_pImpl->GetAnyProperty(PROP_CHAR_HEIGHT, rContext) >>= fFontSize; + if ( fFontSize ) + // nIntValue is in half-points, fontsize is in points, escapement is a percentage. + nEscapement = round( nIntValue/2.0 / fFontSize * 100 ); + else + nEscapement = nIntValue > 0 ? DFLT_ESC_SUPER : DFLT_ESC_SUB; + } + if ( nEscapement > MAX_ESC_POS ) + nEscapement = MAX_ESC_POS; + else if ( nEscapement < -MAX_ESC_POS ) + nEscapement = -MAX_ESC_POS; + + rContext->Insert(PROP_CHAR_ESCAPEMENT, uno::makeAny( sal_Int16(nEscapement) ) ); + rContext->Insert(PROP_CHAR_ESCAPEMENT_HEIGHT, uno::makeAny( nProp ) ); + } + break; + default: + SAL_WARN( "writerfilter", "Unhandled property in processDeferredCharacterProperty()" ); + break; + } + } +} + +void DomainMapper::lcl_entry(writerfilter::Reference::Pointer_t ref) +{ + ref->resolve(*this); +} + +void DomainMapper::data(const sal_uInt8* /*buf*/, size_t /*len*/) +{ +} + +void DomainMapper::lcl_startSectionGroup() +{ + if (!m_pImpl->isInIndexContext() && !m_pImpl->isInBibliographyContext()) + { + m_pImpl->PushProperties(CONTEXT_SECTION); + } + m_pImpl->SetIsFirstParagraphInSection(true); + m_pImpl->SetIsFirstParagraphInSectionAfterRedline(true); +} + +void DomainMapper::lcl_endSectionGroup() +{ + if (!m_pImpl->isInIndexContext() && !m_pImpl->isInBibliographyContext()) + { + m_pImpl->CheckUnregisteredFrameConversion(); + m_pImpl->ExecuteFrameConversion(); + // When pasting, it's fine to not have any paragraph inside the document at all. + if (m_pImpl->GetIsFirstParagraphInSection() && m_pImpl->IsNewDoc()) + { + // This section has no paragraph at all (e.g. they are all actually in a frame). + // If this section has a page break, there would be nothing to apply to the page + // style, so force a dummy paragraph. + lcl_startParagraphGroup(); + lcl_startCharacterGroup(); + sal_uInt8 const sBreak[] = { 0xd }; + lcl_text(sBreak, 1); + lcl_endCharacterGroup(); + lcl_endParagraphGroup(); + } + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_SECTION); + SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); + OSL_ENSURE(pSectionContext, "SectionContext unavailable!"); + if(pSectionContext) + { + pSectionContext->CloseSectionGroup( *m_pImpl ); + // Remove the dummy paragraph if added for + // handling the section properties if section starts with a table + if (m_pImpl->GetIsDummyParaAddedForTableInSection()) + m_pImpl->RemoveDummyParaForTableInSection(); + } + m_pImpl->SetIsTextFrameInserted( false ); + m_pImpl->PopProperties(CONTEXT_SECTION); + } +} + +void DomainMapper::lcl_startParagraphGroup() +{ + if (m_pImpl->hasTableManager()) + m_pImpl->getTableManager().startParagraphGroup(); + /* + * Add new para properties only if paragraph is not split + * or the top context is not of paragraph properties + * Set mbIsSplitPara to false as it has been handled + */ + if (!mbIsSplitPara) + m_pImpl->PushProperties(CONTEXT_PARAGRAPH); + mbIsSplitPara = false; + if (m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH) != m_pImpl->GetTopContext()) + m_pImpl->PushProperties(CONTEXT_PARAGRAPH); + + if (m_pImpl->GetTopContext()) + { + if (!m_pImpl->IsInShape()) + { + const OUString& sDefaultParaStyle = m_pImpl->GetDefaultParaStyleName(); + m_pImpl->GetTopContext()->Insert( PROP_PARA_STYLE_NAME, uno::makeAny( sDefaultParaStyle ) ); + m_pImpl->SetCurrentParaStyleName( sDefaultParaStyle ); + } + if (m_pImpl->isBreakDeferred(PAGE_BREAK)) + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); + else if (m_pImpl->isBreakDeferred(COLUMN_BREAK)) + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_COLUMN_BEFORE)); + + if (m_pImpl->isParaSdtEndDeferred()) + m_pImpl->GetTopContext()->Insert(PROP_PARA_SDT_END_BEFORE, uno::makeAny(true), true, PARA_GRAB_BAG); + } + m_pImpl->SetIsFirstRun(true); + m_pImpl->SetIsOutsideAParagraph(false); + m_pImpl->clearDeferredBreaks(); + m_pImpl->setParaSdtEndDeferred(false); +} + +void DomainMapper::lcl_endParagraphGroup() +{ + m_pImpl->PopProperties(CONTEXT_PARAGRAPH); + if (m_pImpl->hasTableManager()) + m_pImpl->getTableManager().endParagraphGroup(); + //frame conversion has to be executed after table conversion + m_pImpl->ExecuteFrameConversion(); + m_pImpl->SetIsOutsideAParagraph(true); +} + +void DomainMapper::markLastParagraphInSection( ) +{ + m_pImpl->SetIsLastParagraphInSection( true ); +} + +void DomainMapper::markLastSectionGroup( ) +{ + m_pImpl->SetIsLastSectionGroup( true ); +} + +void DomainMapper::lcl_startShape(uno::Reference const& xShape) +{ + assert(xShape.is()); + + if (m_pImpl->GetTopContext()) + { + // If there is a deferred page break, handle it now, so that the + // started shape will be on the correct page. + if (m_pImpl->isBreakDeferred(PAGE_BREAK)) + { + m_pImpl->clearDeferredBreak(PAGE_BREAK); + lcl_startCharacterGroup(); + sal_uInt8 const sBreak[] = { 0xd }; + lcl_text(sBreak, 1); + lcl_endCharacterGroup(); + lcl_endParagraphGroup(); + lcl_startParagraphGroup(); + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); + } + m_pImpl->PushShapeContext( xShape ); + lcl_startParagraphGroup(); + } + else + { + // No context? Then this image should not appear directly inside the + // document, just save it for later usage. + m_pImpl->PushPendingShape(xShape); + } + + m_pImpl->SetIsFirstParagraphInShape(true); + +} + +void DomainMapper::lcl_endShape( ) +{ + if (m_pImpl->GetTopContext()) + { + // End the current table, if there are any. Otherwise the unavoidable + // empty paragraph at the end of the shape text will cause problems: if + // the shape text ends with a table, the extra paragraph will be + // handled as an additional row of the ending table. + if (m_pImpl->hasTableManager()) + m_pImpl->getTableManager().endTable(); + + lcl_endParagraphGroup(); + m_pImpl->PopShapeContext( ); + // A shape is always inside a paragraph (anchored or inline). + m_pImpl->SetIsOutsideAParagraph(false); + } +} + +void DomainMapper::PushStyleSheetProperties( const PropertyMapPtr& pStyleProperties, bool bAffectTableMngr ) +{ + m_pImpl->PushStyleProperties( pStyleProperties ); + if ( bAffectTableMngr ) + m_pImpl->getTableManager( ).SetStyleProperties( pStyleProperties ); +} + +void DomainMapper::PopStyleSheetProperties( bool bAffectTableMngr ) +{ + m_pImpl->PopProperties( CONTEXT_STYLESHEET ); + if ( bAffectTableMngr ) + { + PropertyMapPtr emptyPtr; + m_pImpl->getTableManager( ).SetStyleProperties( emptyPtr ); + } +} + +void DomainMapper::PushListProperties( const ::tools::SvRef& pListProperties ) +{ + m_pImpl->PushListProperties( pListProperties ); +} + +void DomainMapper::PopListProperties() +{ + m_pImpl->PopProperties( CONTEXT_LIST ); +} + +void DomainMapper::lcl_startCharacterGroup() +{ + m_pImpl->PushProperties(CONTEXT_CHARACTER); + if (m_pImpl->isSdtEndDeferred()) + { + // Fields have an empty character group before the real one, so don't + // call setSdtEndDeferred(false) here, that will happen only in lcl_utext(). + m_pImpl->GetTopContext()->Insert(PROP_SDT_END_BEFORE, uno::makeAny(true), true, CHAR_GRAB_BAG); + } +} + +void DomainMapper::lcl_endCharacterGroup() +{ + if (m_pImpl->CheckFootnoteStyle()) + { + m_pImpl->SetCheckFootnoteStyle(m_pImpl->IsInCustomFootnote()); + m_pImpl->SetHasFootnoteStyle(false); + } + m_pImpl->PopProperties(CONTEXT_CHARACTER); +} + +void DomainMapper::lcl_text(const sal_uInt8 * data_, size_t len) +{ + //TODO: Determine the right text encoding (FIB?) + OUString sText( reinterpret_cast(data_), len, RTL_TEXTENCODING_MS_1252 ); +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("text"); + TagLogger::getInstance().chars(sText); + TagLogger::getInstance().endElement(); +#endif + + try + { + if(len == 1) + { + switch(*data_) + { + case 0x02: return; //footnote character + case 0x08: // Lock field if in field context + if (m_pImpl->IsOpenField()) + m_pImpl->SetFieldLocked(); + return; + case 0x0c: //page break + m_pImpl->deferBreak(PAGE_BREAK); + return; + case 0x0e: //column break + m_pImpl->deferBreak(COLUMN_BREAK); + return; + case 0x07: + m_pImpl->getTableManager().text(data_, len); + return; + case 0x0d: + { + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH); + if (pContext && m_pImpl->isBreakDeferred(COLUMN_BREAK)) + { + pContext->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_COLUMN_BEFORE)); + m_pImpl->clearDeferredBreak(COLUMN_BREAK); + } + finishParagraph(); + return; + } + case cFieldStart: + m_pImpl->PushFieldContext(); + return; + case cFieldSep: + // delimiter not necessarily available + // appears only if field contains further content + m_pImpl->CloseFieldCommand(); + return; + case cFieldEnd: + m_pImpl->PopFieldContext(); + return; + default: + break; + } + } + + // GetTopContext() is changed by inserted breaks, but we want to keep the current context + PropertyMapPtr pContext = m_pImpl->GetTopContext(); + if (!m_pImpl->GetFootnoteContext()) + { + if (m_pImpl->isBreakDeferred(PAGE_BREAK)) + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); + else if (m_pImpl->isBreakDeferred(COLUMN_BREAK)) + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_COLUMN_BEFORE)); + m_pImpl->clearDeferredBreaks(); + } + + if (pContext && pContext->GetFootnote().is() && m_pImpl->IsInCustomFootnote()) + { + pContext->GetFootnote()->setLabel(sText); + m_pImpl->EndCustomFootnote(); + //otherwise ignore sText + } + else if (m_pImpl->IsOpenFieldCommand() && !m_pImpl->IsForceGenericFields()) + { + m_pImpl->AppendFieldCommand(sText); + } + else if( m_pImpl->IsOpenField() && m_pImpl->IsFieldResultAsString()) + /*depending on the success of the field insert operation this result will be + set at the field or directly inserted into the text*/ + m_pImpl->AppendFieldResult(sText); + else + { + if (pContext == nullptr) + pContext = new PropertyMap(); + + m_pImpl->appendTextPortion( sText, pContext ); + } + } + catch( const uno::RuntimeException& ) + { + TOOLS_WARN_EXCEPTION("writerfilter", ""); + } +} + +void DomainMapper::lcl_positionOffset(const OUString& rText, bool bVertical) +{ + if (bVertical) + m_pImpl->m_aPositionOffsets.second = rText; + else + m_pImpl->m_aPositionOffsets.first = rText; +} + +awt::Point DomainMapper::getPositionOffset() +{ + awt::Point aRet; + aRet.X = oox::drawingml::convertEmuToHmm(m_pImpl->m_aPositionOffsets.first.toInt32()); + aRet.Y = oox::drawingml::convertEmuToHmm(m_pImpl->m_aPositionOffsets.second.toInt32()); + return aRet; +} + +void DomainMapper::lcl_align(const OUString& rText, bool bVertical) +{ + if (bVertical) + m_pImpl->m_aAligns.second = rText; + else + m_pImpl->m_aAligns.first = rText; +} + +void DomainMapper::lcl_positivePercentage(const OUString& rText) +{ + m_pImpl->m_aPositivePercentages.push(rText); +} + +void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len) +{ + // All these fixed values are defined as static const sal_Unicode codepoints in the fast parser, + // like uFtnEdnRef = 0x2, uFtnEdnSep = 0x3, ... and have a len of 1, if they aren't valid unicode. + + OUString sText(reinterpret_cast(data_), len); + const RubyInfo & aInfo = m_pImpl->GetRubyInfo(); + if (aInfo.nSprmId == NS_ooxml::LN_CT_Ruby_rt) + { + PropertyMapPtr pContext = m_pImpl->GetTopContext(); + PropertyValueVector_t aProps = comphelper::sequenceToContainer< PropertyValueVector_t >(pContext->GetPropertyValues()); + OUString sStyle = getOrCreateCharStyle(aProps, /*bAlwaysCreate=*/false); + m_pImpl->SetRubyText(sText,sStyle); + return; + } + + if (len == 1) + { + // If the footnote contains a Footnote Reference Mark, it can't be a custom footnote + // ****** + // This code block is wrong, as it should also be in m_pImpl->IsInFootOrEndnote(). + // The main problem is that + // + // assert(len != 1 || sText[0] != 0x2) + // + // is triggered by the unit test SwLayoutWriter::testForcepoint75, so all these pseudo + // value handling is broken. + // But this is just a symptom, as I guess it's possible to generate broken DOCX documents, + // which might be problematic, triggering *funny* code paths left and right. + // ****** + if (sText[0] == 0x2) + { + m_pImpl->EndCustomFootnote(); + return; + } + + if (m_pImpl->IsInCustomFootnote()) + { + if (sText[0] != 0xd && sText[0] != 0x3) + { + // DOCX can have different labels for the footnote reference and the footnote area. + // This skips the one from the footnote area and just uses the reference one. + if (!m_pImpl->IsInFootOrEndnote()) + { + if (PropertyMapPtr pFootnoteContext = m_pImpl->GetFootnoteContext()) + { + auto xFootnote = pFootnoteContext->GetFootnote(); + xFootnote->setLabel(xFootnote->getLabel() + sText); + } + } + return; + } + else + m_pImpl->SetHasFootnoteStyle(true); + } + } + + if (m_pImpl->isSdtEndDeferred()) + { + // In case we have a field context, then save the property there, so + // SDT's ending right before a field start are handled as well. + PropertyMapPtr pContext = m_pImpl->GetTopContext(); + if (m_pImpl->IsOpenField()) + pContext = m_pImpl->GetTopFieldContext()->getProperties(); + pContext->Insert(PROP_SDT_END_BEFORE, uno::makeAny(true), true, CHAR_GRAB_BAG); + m_pImpl->setSdtEndDeferred(false); + } + + bool bNewLine = len == 1 && (sText[0] == 0x0d || sText[0] == 0x07); + if (m_pImpl->m_pSdtHelper->isInsideDropDownControl()) + { + if (bNewLine) + // Dropdown control has single-line texts, so in case of newline, create the control. + m_pImpl->m_pSdtHelper->createDropDownControl(); + else + { + m_pImpl->m_pSdtHelper->getSdtTexts().append(sText); + return; + } + } + else if (!m_pImpl->m_pSdtHelper->isInteropGrabBagEmpty()) + { + // Ignore grabbag when we have a date field, it can conflict during export + if(m_pImpl->m_pSdtHelper->validateDateFormat()) + { + m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear(); + } + else + { + + // there are unsupported SDT properties in the document + // save them in the paragraph interop grab bag + if (m_pImpl->IsDiscardHeaderFooter()) + { + // Unless we're supposed to ignore this header/footer. + m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear(); + return; + } + if((m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_checkbox") || + m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_text") || + m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_dataBinding") || + m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_citation") || + (m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_id") && + m_pImpl->m_pSdtHelper->getInteropGrabBagSize() == 1)) && !m_pImpl->m_pSdtHelper->isOutsideAParagraph()) + { + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_CHARACTER); + + if (m_pImpl->IsOpenField()) + // We have a field, insert the SDT properties to the field's grab-bag, so they won't be lost. + pContext = m_pImpl->GetTopFieldContext()->getProperties(); + + pContext->Insert(PROP_SDTPR, uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, CHAR_GRAB_BAG); + } + else + m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)->Insert(PROP_SDTPR, + uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, PARA_GRAB_BAG); + } + } + else if (len == 1 && sText[0] == 0x03) + { + // This is the uFtnEdnSep, remember that the document has a separator. + m_pImpl->m_bHasFtnSep = true; + return; + } + else if (len == 1 && sText[0] == '\t' ) + { + if ( m_pImpl->m_bCheckFirstFootnoteTab && m_pImpl->IsInFootOrEndnote() ) + { + // Allow MSO to emulate LO footnote text starting at left margin - only meaningful with hanging indent + m_pImpl->m_bCheckFirstFootnoteTab = false; + sal_Int32 nFirstLineIndent = 0; + m_pImpl->GetAnyProperty(PROP_PARA_FIRST_LINE_INDENT, m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH)) >>= nFirstLineIndent; + if ( nFirstLineIndent < 0 ) + m_pImpl->m_bIgnoreNextTab = true; + } + + if ( m_pImpl->m_bIgnoreNextTab ) + { + m_pImpl->m_bIgnoreNextTab = false; + return; + } + } + else if (m_pImpl->m_pSdtHelper->validateDateFormat()) + { + if(IsInHeaderFooter() && m_pImpl->IsDiscardHeaderFooter()) + { + m_pImpl->m_pSdtHelper->getDateFormat().truncate(); + m_pImpl->m_pSdtHelper->getLocale().truncate(); + return; + } + } + if (!m_pImpl->hasTableManager()) + return; + + SkipFootnoteSeparator eSkip = m_pImpl->GetSkipFootnoteState(); + if ( eSkip == SkipFootnoteSeparator::ON || eSkip == SkipFootnoteSeparator::SKIPPING ) + { + m_pImpl->SetSkipFootnoteState( SkipFootnoteSeparator::SKIPPING ); + return; + } + + try + { + m_pImpl->getTableManager().utext(data_, len); + + if (bNewLine) + { + const bool bSingleParagraph = m_pImpl->GetIsFirstParagraphInSection() && m_pImpl->GetIsLastParagraphInSection(); + const bool bSingleParagraphAfterRedline = m_pImpl->GetIsFirstParagraphInSection(true) && m_pImpl->GetIsLastParagraphInSection(); + PropertyMapPtr pContext = m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH); + if (!m_pImpl->GetFootnoteContext()) + { + if (m_pImpl->isBreakDeferred(PAGE_BREAK)) + { + if (m_pImpl->GetSettingsTable()->GetSplitPgBreakAndParaMark()) + { + if ( m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun() ) + { + m_pImpl->m_bIsSplitPara = true; + finishParagraph(); + lcl_startParagraphGroup(); + } + + + pContext->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); + m_pImpl->clearDeferredBreaks(); + } + } + else if (m_pImpl->isBreakDeferred(COLUMN_BREAK)) + { + if ( m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun() ) + { + mbIsSplitPara = true; + finishParagraph(); + lcl_startParagraphGroup(); + } + + pContext->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_COLUMN_BEFORE)); + m_pImpl->clearDeferredBreaks(); + } + } + + // If the paragraph contains only the section properties and it has + // no runs, we should not create a paragraph for it in Writer, unless that would remove the whole section. + SectionPropertyMap* pSectionContext = m_pImpl->GetSectionContext(); + bool bRemove = (!m_pImpl->GetParaChanged() && m_pImpl->GetRemoveThisPara()) || + (!m_pImpl->GetParaChanged() && m_pImpl->GetParaSectpr() + && !bSingleParagraphAfterRedline + && !m_pImpl->GetIsDummyParaAddedForTableInSection() + && !( pSectionContext && pSectionContext->GetBreakType() != -1 && pContext && pContext->isSet(PROP_BREAK_TYPE) ) + && !m_pImpl->GetIsPreviousParagraphFramed()); + + const bool bNoNumbering = bRemove || (!m_pImpl->GetParaChanged() && m_pImpl->GetParaSectpr() && bSingleParagraph); + PropertyMapPtr xContext = bNoNumbering ? m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH) : PropertyMapPtr(); + if (xContext) + { + // tdf#97417 delete numbering of the paragraph + // it will be deleted anyway, and the numbering would be copied + // to the next paragraph in sw SplitNode and then be applied to + // every following paragraph + xContext->Erase(PROP_NUMBERING_RULES); + static_cast(xContext.get())->SetListId(-1);; + xContext->Erase(PROP_NUMBERING_LEVEL); + } + m_pImpl->SetParaSectpr(false); + finishParagraph(bRemove); + if (bRemove) + m_pImpl->RemoveLastParagraph(); + } + else + { + // GetTopContext() is changed by inserted breaks, but we want to keep the current context + PropertyMapPtr pContext = m_pImpl->GetTopContext(); + if (!m_pImpl->GetFootnoteContext()) + { + if (m_pImpl->isBreakDeferred(PAGE_BREAK)) + { + /* If PAGEBREAK appears in first paragraph of the section or + * after first run of any paragraph then need to split paragraph + * to handle it properly. + */ + if (m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun()) + { + m_pImpl->m_bIsSplitPara = true; + finishParagraph(); + lcl_startParagraphGroup(); + } + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_PAGE_BEFORE)); + } + else if (m_pImpl->isBreakDeferred(COLUMN_BREAK)) + { + if (m_pImpl->GetIsFirstParagraphInSection() || !m_pImpl->IsFirstRun()) + { + mbIsSplitPara = true; + finishParagraph(); + lcl_startParagraphGroup(); + } + m_pImpl->GetTopContext()->Insert(PROP_BREAK_TYPE, uno::makeAny(style::BreakType_COLUMN_BEFORE)); + } + m_pImpl->clearDeferredBreaks(); + } + + if (pContext && pContext->GetFootnote().is()) + { + pContext->GetFootnote()->setLabel( sText ); + //otherwise ignore sText + } + else if (m_pImpl->IsOpenFieldCommand() && !m_pImpl->IsForceGenericFields()) + { + m_pImpl->AppendFieldCommand(sText); + } + else if( m_pImpl->IsOpenField() && m_pImpl->IsFieldResultAsString()) + /*depending on the success of the field insert operation this result will be + set at the field or directly inserted into the text*/ + m_pImpl->AppendFieldResult(sText); + else + { + if (pContext == nullptr) + pContext = new PropertyMap(); + + m_pImpl->appendTextPortion( sText, pContext ); + } + + } + m_pImpl->SetIsFirstRun(false); + } + catch( const uno::RuntimeException& ) + { + } +} + +void DomainMapper::lcl_props(writerfilter::Reference::Pointer_t ref) +{ + ref->resolve(*this); +} + +void DomainMapper::lcl_table(Id name, writerfilter::Reference
::Pointer_t ref) +{ + m_pImpl->SetAnyTableImport(true); + switch(name) + { + case NS_ooxml::LN_FONTTABLE: + + // create a font table object that listens to the attributes + // each entry call inserts a new font entry + ref->resolve( *m_pImpl->GetFontTable() ); + break; + case NS_ooxml::LN_STYLESHEET: + //same as above to import style sheets + m_pImpl->SetStyleSheetImport( true ); + ref->resolve( *m_pImpl->GetStyleSheetTable() ); + m_pImpl->GetStyleSheetTable()->ApplyStyleSheets(m_pImpl->GetFontTable()); + m_pImpl->SetStyleSheetImport( false ); + break; + case NS_ooxml::LN_NUMBERING: + { + + //the same for list tables + ref->resolve( *m_pImpl->GetListTable() ); + m_pImpl->GetListTable( )->CreateNumberingRules( ); + } + break; + case NS_ooxml::LN_THEMETABLE: + m_pImpl->GetThemeTable()->setThemeFontLangProperties( + m_pImpl->GetSettingsTable()->GetThemeFontLangProperties() ); + ref->resolve ( *m_pImpl->GetThemeTable() ); + break; + case NS_ooxml::LN_settings_settings: + ref->resolve ( *m_pImpl->GetSettingsTable() ); + m_pImpl->ApplySettingsTable(); + break; + default: + OSL_FAIL( "which table is to be filled here?"); + } + m_pImpl->SetAnyTableImport(false); +} + +void DomainMapper::lcl_substream(Id rName, ::writerfilter::Reference::Pointer_t ref) +{ + m_pImpl->substream(rName, ref); +} + +void DomainMapper::lcl_startGlossaryEntry() +{ + uno::Reference< text::XTextRange > xTextRange = GetCurrentTextRange(); + m_pImpl->setGlossaryEntryStart(xTextRange); +} + +void DomainMapper::lcl_endGlossaryEntry() +{ + m_pImpl->appendGlossaryEntry(); +} + +void DomainMapper::handleUnderlineType(const Id nId, const ::tools::SvRef& rContext) +{ + sal_Int16 nUnderline = awt::FontUnderline::NONE; + + switch (nId) + { + case NS_ooxml::LN_Value_ST_Underline_none: + nUnderline = awt::FontUnderline::NONE; + break; + case NS_ooxml::LN_Value_ST_Underline_words: + rContext->Insert(PROP_CHAR_WORD_MODE, uno::makeAny(true)); + [[fallthrough]]; + case NS_ooxml::LN_Value_ST_Underline_single: + nUnderline = awt::FontUnderline::SINGLE; + break; + case NS_ooxml::LN_Value_ST_Underline_double: + nUnderline = awt::FontUnderline::DOUBLE; + break; + case NS_ooxml::LN_Value_ST_Underline_dotted: + nUnderline = awt::FontUnderline::DOTTED; + break; + case NS_ooxml::LN_Value_ST_Underline_dash: + nUnderline = awt::FontUnderline::DASH; + break; + case NS_ooxml::LN_Value_ST_Underline_dotDash: + nUnderline = awt::FontUnderline::DASHDOT; + break; + case NS_ooxml::LN_Value_ST_Underline_dotDotDash: + nUnderline = awt::FontUnderline::DASHDOTDOT; + break; + case NS_ooxml::LN_Value_ST_Underline_thick: + nUnderline = awt::FontUnderline::BOLD; + break; + case NS_ooxml::LN_Value_ST_Underline_wave: + nUnderline = awt::FontUnderline::WAVE; + break; + case NS_ooxml::LN_Value_ST_Underline_dottedHeavy: + nUnderline = awt::FontUnderline::BOLDDOTTED; + break; + case NS_ooxml::LN_Value_ST_Underline_dashedHeavy: + nUnderline = awt::FontUnderline::BOLDDASH; + break; + case NS_ooxml::LN_Value_ST_Underline_dashLong: + nUnderline = awt::FontUnderline::LONGDASH; + break; + case NS_ooxml::LN_Value_ST_Underline_dashLongHeavy: + nUnderline = awt::FontUnderline::BOLDLONGDASH; + break; + case NS_ooxml::LN_Value_ST_Underline_dashDotHeavy: + nUnderline = awt::FontUnderline::BOLDDASHDOT; + break; + case NS_ooxml::LN_Value_ST_Underline_dashDotDotHeavy: + nUnderline = awt::FontUnderline::BOLDDASHDOTDOT; + break; + case NS_ooxml::LN_Value_ST_Underline_wavyHeavy: + nUnderline = awt::FontUnderline::BOLDWAVE; + break; + case NS_ooxml::LN_Value_ST_Underline_wavyDouble: + nUnderline = awt::FontUnderline::DOUBLEWAVE; + break; + } + rContext->Insert(PROP_CHAR_UNDERLINE, uno::makeAny(nUnderline)); +} + +void DomainMapper::handleParaJustification(const sal_Int32 nIntValue, const ::tools::SvRef& rContext, const bool bExchangeLeftRight) +{ + style::ParagraphAdjust nAdjust = style::ParagraphAdjust_LEFT; + style::ParagraphAdjust nLastLineAdjust = style::ParagraphAdjust_LEFT; + OUString aStringValue = "left"; + switch(nIntValue) + { + case NS_ooxml::LN_Value_ST_Jc_center: + nAdjust = style::ParagraphAdjust_CENTER; + aStringValue = "center"; + break; + case NS_ooxml::LN_Value_ST_Jc_right: + case NS_ooxml::LN_Value_ST_Jc_end: + nAdjust = bExchangeLeftRight ? style::ParagraphAdjust_LEFT : style::ParagraphAdjust_RIGHT; + aStringValue = "right"; + break; + case NS_ooxml::LN_Value_ST_Jc_distribute: + nLastLineAdjust = style::ParagraphAdjust_BLOCK; + [[fallthrough]]; + case NS_ooxml::LN_Value_ST_Jc_both: + nAdjust = style::ParagraphAdjust_BLOCK; + aStringValue = "both"; + break; + case NS_ooxml::LN_Value_ST_Jc_left: + case NS_ooxml::LN_Value_ST_Jc_start: + default: + nAdjust = bExchangeLeftRight ? style::ParagraphAdjust_RIGHT : style::ParagraphAdjust_LEFT; + break; + } + rContext->Insert( PROP_PARA_ADJUST, uno::makeAny( nAdjust ) ); + rContext->Insert( PROP_PARA_LAST_LINE_ADJUST, uno::makeAny( nLastLineAdjust ) ); + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "jc", aStringValue); +} + +bool DomainMapper::getColorFromId(const Id nId, sal_Int32 &nColor) +{ + nColor = 0; + if ((nId < NS_ooxml::LN_Value_ST_HighlightColor_black) || (nId > NS_ooxml::LN_Value_ST_HighlightColor_lightGray)) + return false; + + switch (nId) + { + case NS_ooxml::LN_Value_ST_HighlightColor_black: nColor=0x000000; break; + case NS_ooxml::LN_Value_ST_HighlightColor_blue: nColor=0x0000ff; break; + case NS_ooxml::LN_Value_ST_HighlightColor_cyan: nColor=0x00ffff; break; + case NS_ooxml::LN_Value_ST_HighlightColor_green: nColor=0x00ff00; break; + case NS_ooxml::LN_Value_ST_HighlightColor_magenta: nColor=0xff00ff; break; + case NS_ooxml::LN_Value_ST_HighlightColor_red: nColor=0xff0000; break; + case NS_ooxml::LN_Value_ST_HighlightColor_yellow: nColor=0xffff00; break; + case NS_ooxml::LN_Value_ST_HighlightColor_white: nColor=0xffffff; break; + case NS_ooxml::LN_Value_ST_HighlightColor_darkBlue: nColor=0x000080; break; + case NS_ooxml::LN_Value_ST_HighlightColor_darkCyan: nColor=0x008080; break; + case NS_ooxml::LN_Value_ST_HighlightColor_darkGreen: nColor=0x008000; break; + case NS_ooxml::LN_Value_ST_HighlightColor_darkMagenta: nColor=0x800080; break; + case NS_ooxml::LN_Value_ST_HighlightColor_darkRed: nColor=0x800000; break; + case NS_ooxml::LN_Value_ST_HighlightColor_darkYellow: nColor=0x808000; break; + case NS_ooxml::LN_Value_ST_HighlightColor_darkGray: nColor=0x808080; break; + case NS_ooxml::LN_Value_ST_HighlightColor_lightGray: nColor=0xC0C0C0; break; + default: + return false; + } + return true; +} + +sal_Int16 DomainMapper::getEmphasisValue(const sal_Int32 nIntValue) +{ + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_Em_dot: + return text::FontEmphasis::DOT_ABOVE; + case NS_ooxml::LN_Value_ST_Em_comma: + return text::FontEmphasis::ACCENT_ABOVE; + case NS_ooxml::LN_Value_ST_Em_circle: + return text::FontEmphasis::CIRCLE_ABOVE; + case NS_ooxml::LN_Value_ST_Em_underDot: + return text::FontEmphasis::DOT_BELOW; + default: + return text::FontEmphasis::NONE; + } +} + +OUString DomainMapper::getBracketStringFromEnum(const sal_Int32 nIntValue, const bool bIsPrefix) +{ + switch(nIntValue) + { + case NS_ooxml::LN_Value_ST_CombineBrackets_round: + if (bIsPrefix) + return "("; + return ")"; + + case NS_ooxml::LN_Value_ST_CombineBrackets_square: + if (bIsPrefix) + return "["; + return "]"; + + case NS_ooxml::LN_Value_ST_CombineBrackets_angle: + if (bIsPrefix) + return "<"; + return ">"; + + case NS_ooxml::LN_Value_ST_CombineBrackets_curly: + if (bIsPrefix) + return "{"; + return "}"; + + case NS_ooxml::LN_Value_ST_CombineBrackets_none: + default: + return OUString(); + } +} + +style::TabAlign DomainMapper::getTabAlignFromValue(const sal_Int32 nIntValue) +{ + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_TabJc_start: + case NS_ooxml::LN_Value_ST_TabJc_left: + case NS_ooxml::LN_Value_ST_TabJc_bar: // bar not supported + case NS_ooxml::LN_Value_ST_TabJc_num: // num not supported + return style::TabAlign_LEFT; + case NS_ooxml::LN_Value_ST_TabJc_center: + return style::TabAlign_CENTER; + case NS_ooxml::LN_Value_ST_TabJc_end: + case NS_ooxml::LN_Value_ST_TabJc_right: + return style::TabAlign_RIGHT; + case NS_ooxml::LN_Value_ST_TabJc_decimal: + return style::TabAlign_DECIMAL; + } + return style::TabAlign_LEFT; +} + +sal_Unicode DomainMapper::getFillCharFromValue(const sal_Int32 nIntValue) +{ + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_TabTlc_dot: + return u'.'; + case NS_ooxml::LN_Value_ST_TabTlc_hyphen: + return u'-'; + case NS_ooxml::LN_Value_ST_TabTlc_underscore: + case NS_ooxml::LN_Value_ST_TabTlc_heavy: // FIXME ??? + return u'_'; + case NS_ooxml::LN_Value_ST_TabTlc_middleDot: // middleDot + return u'\x00b7'; + case NS_ooxml::LN_Value_ST_TabTlc_none: + default: + return u' '; // blank space + } +} + +bool DomainMapper::IsOOXMLImport() const +{ + return m_pImpl->IsOOXMLImport(); +} + +bool DomainMapper::IsRTFImport() const +{ + return m_pImpl->IsRTFImport(); +} + +uno::Reference < lang::XMultiServiceFactory > const & DomainMapper::GetTextFactory() const +{ + return m_pImpl->GetTextFactory(); +} + +uno::Reference< text::XTextRange > DomainMapper::GetCurrentTextRange() +{ + if (m_pImpl->HasTopText()) + return m_pImpl->GetTopTextAppend()->getEnd(); + return m_pImpl->m_xInsertTextRange; +} + +OUString DomainMapper::getOrCreateCharStyle( PropertyValueVector_t& rCharProperties, bool bAlwaysCreate ) +{ + StyleSheetTablePtr pStyleSheets = m_pImpl->GetStyleSheetTable(); + return pStyleSheets->getOrCreateCharStyle( rCharProperties, bAlwaysCreate ); +} + +StyleSheetTablePtr const & DomainMapper::GetStyleSheetTable( ) +{ + return m_pImpl->GetStyleSheetTable( ); +} + +GraphicZOrderHelper* DomainMapper::graphicZOrderHelper() +{ + if (zOrderHelper == nullptr) + zOrderHelper.reset( new GraphicZOrderHelper ); + return zOrderHelper.get(); +} + +GraphicNamingHelper& DomainMapper::GetGraphicNamingHelper() +{ + if (m_pGraphicNamingHelper == nullptr) + m_pGraphicNamingHelper.reset(new GraphicNamingHelper()); + return *m_pGraphicNamingHelper; +} + +uno::Reference DomainMapper::PopPendingShape() +{ + return m_pImpl->PopPendingShape(); +} + +bool DomainMapper::IsInHeaderFooter() const +{ + return m_pImpl->IsInHeaderFooter(); +} + +bool DomainMapper::IsInShape() const { return m_pImpl->IsInShape(); } + +bool DomainMapper::IsInTable() const +{ + return m_pImpl->hasTableManager() && m_pImpl->getTableManager().isInCell(); +} + +OUString DomainMapper::GetListStyleName(sal_Int32 nListId) const +{ + return m_pImpl->GetListStyleName( nListId ); +} + +bool DomainMapper::IsStyleSheetImport() const +{ + return m_pImpl->IsStyleSheetImport(); +} + +void DomainMapper::enableInteropGrabBag(const OUString& aName) +{ + m_pImpl->m_aInteropGrabBagName = aName; +} + +beans::PropertyValue DomainMapper::getInteropGrabBag() +{ + beans::PropertyValue aRet; + aRet.Name = m_pImpl->m_aInteropGrabBagName; + aRet.Value <<= comphelper::containerToSequence(m_pImpl->m_aInteropGrabBag); + + m_pImpl->m_aInteropGrabBag.clear(); + m_pImpl->m_aInteropGrabBagName.clear(); + return aRet; +} + +void DomainMapper::HandleRedline( Sprm& rSprm ) +{ + sal_uInt32 nSprmId = rSprm.getId(); + + m_pImpl->AddNewRedline( nSprmId ); + + if (nSprmId == NS_ooxml::LN_CT_PPr_pPrChange) + { + m_pImpl->SetCurrentRedlineToken(XML_ParagraphFormat); + } + else if (nSprmId == NS_ooxml::LN_CT_TrPr_ins) + { + m_pImpl->SetCurrentRedlineToken(XML_tableRowInsert); + } + else if (nSprmId == NS_ooxml::LN_CT_TrPr_del) + { + m_pImpl->SetCurrentRedlineToken(XML_tableRowDelete); + } + else if (nSprmId == NS_ooxml::LN_CT_TcPrBase_cellIns) + { + m_pImpl->SetCurrentRedlineToken(XML_tableCellInsert); + } + else if (nSprmId == NS_ooxml::LN_CT_TcPrBase_cellDel) + { + m_pImpl->SetCurrentRedlineToken(XML_tableCellDelete); + } + + resolveSprmProps(*this, rSprm ); + // now the properties author, date and id should be available + sal_Int32 nToken = m_pImpl->GetCurrentRedlineToken(); + switch( nToken & 0xffff ) + { + case XML_mod: + case XML_ins: + case XML_del: + case XML_moveTo: + case XML_moveFrom: + case XML_ParagraphFormat: + case XML_tableRowInsert: + case XML_tableRowDelete: + case XML_tableCellInsert: + case XML_tableCellDelete: + break; + default: OSL_FAIL( "redline token other than mod, ins, del, moveTo, moveFrom or table row" ); break; + } + m_pImpl->EndParaMarkerChange( ); + m_pImpl->SetCurrentRedlineIsRead(); +} + +void DomainMapper::finishParagraph(const bool bRemove) +{ + if (m_pImpl->m_pSdtHelper->validateDateFormat()) + m_pImpl->m_pSdtHelper->createDateContentControl(); + m_pImpl->finishParagraph(m_pImpl->GetTopContextOfType(CONTEXT_PARAGRAPH), bRemove); +} + +} //namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper.hxx b/writerfilter/source/dmapper/DomainMapper.hxx new file mode 100644 index 000000000..c8281f933 --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapper.hxx @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPER_HXX + +#include +#include "LoggedResources.hxx" +#include "PropertyMap.hxx" +#include +#include + +#include +#include +#include + +namespace com::sun::star{ + namespace beans{ + struct PropertyValue; + } + namespace io{ + class XInputStream; + } + namespace uno{ + class XComponentContext; + } + namespace lang{ + class XMultiServiceFactory; + } + namespace text{ + class XTextRange; + } +} + +namespace utl +{ +class MediaDescriptor; +} + +typedef std::vector PropertyValueVector_t; + +namespace writerfilter { +namespace dmapper +{ + +class PropertyMap; +class DomainMapper_Impl; +class ListsManager; +class StyleSheetTable; +class GraphicZOrderHelper; +class GraphicNamingHelper; + +typedef tools::SvRef StyleSheetTablePtr; + +class DomainMapper : public LoggedProperties, public LoggedTable, + public BinaryObj, public LoggedStream +{ + std::unique_ptr m_pImpl; + +public: + DomainMapper(const css::uno::Reference& xContext, + css::uno::Reference const& xInputStream, + css::uno::Reference const& xModel, + bool bRepairStorage, + SourceDocumentType eDocumentType, + utl::MediaDescriptor const & rMediaDesc); + virtual ~DomainMapper() override; + + // Stream + virtual void markLastParagraphInSection() override; + virtual void markLastSectionGroup() override; + + // BinaryObj + virtual void data(const sal_uInt8* buf, size_t len) override; + + void sprmWithProps( Sprm& sprm, const PropertyMapPtr& pContext ); + + void PushStyleSheetProperties( const PropertyMapPtr& pStyleProperties, bool bAffectTableMngr = false ); + void PopStyleSheetProperties( bool bAffectTableMngr = false ); + + void PushListProperties( const ::tools::SvRef& pListProperties ); + void PopListProperties(); + OUString GetListStyleName(sal_Int32 nListId) const; + + bool IsOOXMLImport() const; + bool IsRTFImport() const; + css::uno::Reference const & GetTextFactory() const; + css::uno::Reference GetCurrentTextRange(); + + OUString getOrCreateCharStyle( PropertyValueVector_t& rCharProperties, bool bAlwaysCreate ); + StyleSheetTablePtr const & GetStyleSheetTable( ); + GraphicZOrderHelper* graphicZOrderHelper(); + GraphicNamingHelper& GetGraphicNamingHelper(); + + /// Return the first from the pending (not inserted to the document) shapes, if there are any. + css::uno::Reference PopPendingShape(); + + bool IsInHeaderFooter() const; + bool IsInTable() const; + bool IsStyleSheetImport() const; + bool IsInShape() const; + + void hasControls( const bool bSet ) { mbHasControls = bSet; } + + /** + @see DomainMapper_Impl::processDeferredCharacterProperties() + */ + void processDeferredCharacterProperties(const std::map& rDeferredCharacterProperties); + + /// Enable storing of seen tokens in a named grab bag. + void enableInteropGrabBag(const OUString& aName); + /// Get the stored tokens and clear the internal storage. + css::beans::PropertyValue getInteropGrabBag(); + + void HandleRedline( Sprm& rSprm ); + +private: + // Stream + virtual void lcl_startSectionGroup() override; + virtual void lcl_endSectionGroup() override; + virtual void lcl_startParagraphGroup() override; + virtual void lcl_endParagraphGroup() override; + virtual void lcl_startCharacterGroup() override; + virtual void lcl_endCharacterGroup() override; + virtual void lcl_startShape(css::uno::Reference const& xShape) override; + virtual void lcl_endShape( ) override; + + virtual void lcl_text(const sal_uInt8 * data, size_t len) override; + virtual void lcl_utext(const sal_uInt8 * data, size_t len) override; + virtual void lcl_positionOffset(const OUString& rText, bool bVertical) override; + virtual css::awt::Point getPositionOffset() override; + virtual void lcl_align(const OUString& rText, bool bVertical) override; + virtual void lcl_positivePercentage(const OUString& rText) override; + virtual void lcl_props(writerfilter::Reference::Pointer_t ref) override; + virtual void lcl_table(Id name, + writerfilter::Reference
::Pointer_t ref) override; + virtual void lcl_substream(Id name, + ::writerfilter::Reference::Pointer_t ref) override; + virtual void lcl_startGlossaryEntry() override; + virtual void lcl_endGlossaryEntry() override; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + + // Table + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) override; + + void finishParagraph(const bool bRemove = false); + + static void handleUnderlineType(const Id nId, const ::tools::SvRef& rContext); + void handleParaJustification(const sal_Int32 nIntValue, const ::tools::SvRef& rContext, const bool bExchangeLeftRight); + static bool getColorFromId(const Id, sal_Int32 &nColor); + static sal_Int16 getEmphasisValue(const sal_Int32 nIntValue); + static OUString getBracketStringFromEnum(const sal_Int32 nIntValue, const bool bIsPrefix = true); + static css::style::TabAlign getTabAlignFromValue(const sal_Int32 nIntValue); + static sal_Unicode getFillCharFromValue(const sal_Int32 nIntValue); + bool mbIsSplitPara; + bool mbHasControls; + std::unique_ptr< GraphicZOrderHelper > zOrderHelper; + std::unique_ptr m_pGraphicNamingHelper; + OUString m_sGlossaryEntryName; +}; + +} // namespace dmapper +} // namespace writerfilter +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx new file mode 100644 index 000000000..c32b33af1 --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -0,0 +1,1496 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "DomainMapperTableHandler.hxx" +#include "DomainMapper_Impl.hxx" +#include "StyleSheetTable.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "TablePositionHandler.hxx" +#include "TagLogger.hxx" +#include "util.hxx" +#include +#include +#include +#include + +#ifdef DBG_UTIL +#include "PropertyMapHelper.hxx" +#include +#endif + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; +using namespace ::std; + +#define DEF_BORDER_DIST 190 //0,19cm +#define CNF_FIRST_ROW 0x800 +#define CNF_LAST_ROW 0x400 +#define CNF_FIRST_COLUMN 0x200 +#define CNF_LAST_COLUMN 0x100 +#define CNF_ODD_VBAND 0x080 +#define CNF_EVEN_VBAND 0x040 +#define CNF_ODD_HBAND 0x020 +#define CNF_EVEN_HBAND 0x010 +#define CNF_FIRST_ROW_LAST_COLUMN 0x008 +#define CNF_FIRST_ROW_FIRST_COLUMN 0x004 +#define CNF_LAST_ROW_LAST_COLUMN 0x002 +#define CNF_LAST_ROW_FIRST_COLUMN 0x001 +#define CNF_ALL 0xFFF + +DomainMapperTableHandler::DomainMapperTableHandler( + css::uno::Reference const& xText, + DomainMapper_Impl& rDMapper_Impl) + : m_xText(xText), + m_rDMapper_Impl( rDMapper_Impl ), + m_bHadFootOrEndnote(false) +{ +} + +DomainMapperTableHandler::~DomainMapperTableHandler() +{ +} + +void DomainMapperTableHandler::startTable(const TablePropertyMapPtr& pProps) +{ + m_aTableProperties = pProps; + m_aTableRanges.clear(); + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablehandler.table"); + + if (pProps.get() != nullptr) + pProps->dumpXml(); +#endif +} + +static void lcl_mergeBorder( PropertyIds nId, const PropertyMapPtr& pOrig, const PropertyMapPtr& pDest ) +{ + std::optional pOrigVal = pOrig->getProperty(nId); + + if ( pOrigVal ) + { + pDest->Insert( nId, pOrigVal->second, false ); + } +} + +static void lcl_computeCellBorders( const PropertyMapPtr& pTableBorders, const PropertyMapPtr& pCellProps, + sal_Int32 nCell, sal_Int32 nRow, bool bIsEndCol, bool bIsEndRow, bool bMergedVertically ) +{ + std::optional pVerticalVal = pCellProps->getProperty(META_PROP_VERTICAL_BORDER); + std::optional pHorizontalVal = pCellProps->getProperty(META_PROP_HORIZONTAL_BORDER); + + // Handle the vertical and horizontal borders + uno::Any aVertProp; + if ( !pVerticalVal) + { + pVerticalVal = pTableBorders->getProperty(META_PROP_VERTICAL_BORDER); + if ( pVerticalVal ) + aVertProp = pVerticalVal->second; + } + else + { + aVertProp = pVerticalVal->second; + pCellProps->Erase( pVerticalVal->first ); + } + + uno::Any aHorizProp; + if ( !pHorizontalVal ) + { + pHorizontalVal = pTableBorders->getProperty(META_PROP_HORIZONTAL_BORDER); + if ( pHorizontalVal ) + aHorizProp = pHorizontalVal->second; + } + else + { + aHorizProp = pHorizontalVal->second; + pCellProps->Erase( pHorizontalVal->first ); + } + + if ( nCell == 0 ) + { + lcl_mergeBorder( PROP_LEFT_BORDER, pTableBorders, pCellProps ); + // counts if there are multiple cells in this row. + if (pVerticalVal && !bIsEndCol) + pCellProps->Insert( PROP_RIGHT_BORDER, aVertProp, false ); + } + + if ( bIsEndCol ) + { + lcl_mergeBorder( PROP_RIGHT_BORDER, pTableBorders, pCellProps ); + if ( pVerticalVal ) + pCellProps->Insert( PROP_LEFT_BORDER, aVertProp, false ); + } + + if ( nCell > 0 && !bIsEndCol ) + { + if ( pVerticalVal ) + { + pCellProps->Insert( PROP_RIGHT_BORDER, aVertProp, false ); + pCellProps->Insert( PROP_LEFT_BORDER, aVertProp, false ); + } + } + + if ( nRow == 0 ) + { + lcl_mergeBorder( PROP_TOP_BORDER, pTableBorders, pCellProps ); + if ( pHorizontalVal && !bMergedVertically ) + pCellProps->Insert( PROP_BOTTOM_BORDER, aHorizProp, false ); + } + + if ( bMergedVertically ) + lcl_mergeBorder( PROP_BOTTOM_BORDER, pTableBorders, pCellProps ); + + if ( bIsEndRow ) + { + lcl_mergeBorder( PROP_BOTTOM_BORDER, pTableBorders, pCellProps ); + if ( pHorizontalVal ) + pCellProps->Insert( PROP_TOP_BORDER, aHorizProp, false ); + } + + if ( nRow > 0 && !bIsEndRow ) + { + if ( pHorizontalVal ) + { + pCellProps->Insert( PROP_TOP_BORDER, aHorizProp, false ); + pCellProps->Insert( PROP_BOTTOM_BORDER, aHorizProp, false ); + } + } +} + +#ifdef DBG_UTIL + +static void lcl_debug_BorderLine(table::BorderLine const & rLine) +{ + TagLogger::getInstance().startElement("BorderLine"); + TagLogger::getInstance().attribute("Color", rLine.Color); + TagLogger::getInstance().attribute("InnerLineWidth", rLine.InnerLineWidth); + TagLogger::getInstance().attribute("OuterLineWidth", rLine.OuterLineWidth); + TagLogger::getInstance().attribute("LineDistance", rLine.LineDistance); + TagLogger::getInstance().endElement(); +} + +static void lcl_debug_TableBorder(table::TableBorder const & rBorder) +{ + TagLogger::getInstance().startElement("TableBorder"); + lcl_debug_BorderLine(rBorder.TopLine); + TagLogger::getInstance().attribute("IsTopLineValid", sal_uInt32(rBorder.IsTopLineValid)); + lcl_debug_BorderLine(rBorder.BottomLine); + TagLogger::getInstance().attribute("IsBottomLineValid", sal_uInt32(rBorder.IsBottomLineValid)); + lcl_debug_BorderLine(rBorder.LeftLine); + TagLogger::getInstance().attribute("IsLeftLineValid", sal_uInt32(rBorder.IsLeftLineValid)); + lcl_debug_BorderLine(rBorder.RightLine); + TagLogger::getInstance().attribute("IsRightLineValid", sal_uInt32(rBorder.IsRightLineValid)); + lcl_debug_BorderLine(rBorder.VerticalLine); + TagLogger::getInstance().attribute("IsVerticalLineValid", sal_uInt32(rBorder.IsVerticalLineValid)); + lcl_debug_BorderLine(rBorder.HorizontalLine); + TagLogger::getInstance().attribute("IsHorizontalLineValid", sal_uInt32(rBorder.IsHorizontalLineValid)); + TagLogger::getInstance().attribute("Distance", rBorder.Distance); + TagLogger::getInstance().attribute("IsDistanceValid", sal_uInt32(rBorder.IsDistanceValid)); + TagLogger::getInstance().endElement(); +} +#endif + +struct TableInfo +{ + sal_Int32 nLeftBorderDistance; + sal_Int32 nRightBorderDistance; + sal_Int32 nTopBorderDistance; + sal_Int32 nBottomBorderDistance; + sal_Int32 nTblLook; + sal_Int32 nNestLevel; + PropertyMapPtr pTableDefaults; + PropertyMapPtr pTableBorders; + TableStyleSheetEntry* pTableStyle; + css::beans::PropertyValues aTableProperties; + std::vector< PropertyIds > aTablePropertyIds; + + TableInfo() + : nLeftBorderDistance(DEF_BORDER_DIST) + , nRightBorderDistance(DEF_BORDER_DIST) + , nTopBorderDistance(0) + , nBottomBorderDistance(0) + , nTblLook(0x4a0) + , nNestLevel(0) + , pTableDefaults(new PropertyMap) + , pTableBorders(new PropertyMap) + , pTableStyle(nullptr) + { + } + +}; + +namespace +{ + +bool lcl_extractTableBorderProperty(const PropertyMapPtr& pTableProperties, const PropertyIds nId, TableInfo const & rInfo, table::BorderLine2& rLine) +{ + if (!pTableProperties) + return false; + + const std::optional aTblBorder = pTableProperties->getProperty(nId); + if( aTblBorder ) + { + OSL_VERIFY(aTblBorder->second >>= rLine); + + rInfo.pTableBorders->Insert( nId, uno::makeAny( rLine ) ); + rInfo.pTableDefaults->Erase( nId ); + + return true; + } + + return false; +} + +void lcl_extractHoriOrient(std::vector& rFrameProperties, sal_Int32& nHoriOrient) +{ + // Shifts the frame left by the given value. + for (const beans::PropertyValue & rFrameProperty : rFrameProperties) + { + if (rFrameProperty.Name == "HoriOrient") + { + sal_Int32 nValue = rFrameProperty.Value.get(); + if (nValue != text::HoriOrientation::NONE) + nHoriOrient = nValue; + return; + } + } +} + +void lcl_DecrementHoriOrientPosition(std::vector& rFrameProperties, sal_Int32 nAmount) +{ + // Shifts the frame left by the given value. + for (beans::PropertyValue & rPropertyValue : rFrameProperties) + { + if (rPropertyValue.Name == "HoriOrientPosition") + { + sal_Int32 nValue = rPropertyValue.Value.get(); + nValue -= nAmount; + rPropertyValue.Value <<= nValue; + return; + } + } +} + +void lcl_adjustBorderDistance(TableInfo& rInfo, const table::BorderLine2& rLeftBorder, + const table::BorderLine2& rRightBorder) +{ + // MS Word appears to do these things to adjust the cell horizontal area: + // + // bll = left borderline width + // blr = right borderline width + // cea = cell's edit area rectangle + // cea_w = cea width + // cml = cell's left margin (padding) defined in cell settings + // cmr = cell's right margin (padding) defined in cell settings + // cw = cell width (distance between middles of left borderline and right borderline) + // pad_l = actual cea left padding = (its left pos relative to middle of bll) + // pad_r = actual cea right padding = abs (its right pos relative to middle of blr) + // + // pad_l = max(bll/2, cml) -> cea does not overlap left borderline + // cea_w = cw-max(pad_l+blr/2, cml+cmr) -> cea does not overlap right borderline + // pad_r = max(pad_l+blr/2, cml+cmr) - pad_l + // + // It means that e.g. for border widths of 6 pt (~2.12 mm), left margin 0 mm, and right margin + // 2 mm, actual left and right margins will (unexpectedly) coincide with inner edges of cell's + // borderlines - the right margin won't create spacing between right of edit rectangle and the + // inner edge of right borderline. + + const sal_Int32 nActualL + = std::max(rLeftBorder.LineWidth / 2, rInfo.nLeftBorderDistance); + const sal_Int32 nActualR + = std::max(nActualL + rRightBorder.LineWidth / 2, + rInfo.nLeftBorderDistance + rInfo.nRightBorderDistance) + - nActualL; + rInfo.nLeftBorderDistance = nActualL; + rInfo.nRightBorderDistance = nActualR; +} + +} + +TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo & rInfo, std::vector& rFrameProperties) +{ + // will receive the table style if any + TableStyleSheetEntry* pTableStyle = nullptr; + + if( m_aTableProperties ) + { + //create properties from the table attributes + //...pPropMap->Insert( PROP_LEFT_MARGIN, uno::makeAny( m_nLeftMargin - m_nGapHalf )); + //pPropMap->Insert( PROP_HORI_ORIENT, uno::makeAny( text::HoriOrientation::RIGHT )); + sal_Int32 nGapHalf = 0; + sal_Int32 nLeftMargin = 0; + + comphelper::SequenceAsHashMap aGrabBag; + + if (nullptr != m_rDMapper_Impl.getTableManager().getCurrentTableRealPosition()) + { + TablePositionHandler *pTablePositions = m_rDMapper_Impl.getTableManager().getCurrentTableRealPosition(); + + uno::Sequence< beans::PropertyValue > aGrabBagTS( 10 ); + + aGrabBagTS[0].Name = "bottomFromText"; + aGrabBagTS[0].Value <<= pTablePositions->getBottomFromText(); + + aGrabBagTS[1].Name = "horzAnchor"; + aGrabBagTS[1].Value <<= pTablePositions->getHorzAnchor(); + + aGrabBagTS[2].Name = "leftFromText"; + aGrabBagTS[2].Value <<= pTablePositions->getLeftFromText(); + + aGrabBagTS[3].Name = "rightFromText"; + aGrabBagTS[3].Value <<= pTablePositions->getRightFromText(); + + aGrabBagTS[4].Name = "tblpX"; + aGrabBagTS[4].Value <<= pTablePositions->getX(); + + aGrabBagTS[5].Name = "tblpXSpec"; + aGrabBagTS[5].Value <<= pTablePositions->getXSpec(); + + aGrabBagTS[6].Name = "tblpY"; + aGrabBagTS[6].Value <<= pTablePositions->getY(); + + aGrabBagTS[7].Name = "tblpYSpec"; + aGrabBagTS[7].Value <<= pTablePositions->getYSpec(); + + aGrabBagTS[8].Name = "topFromText"; + aGrabBagTS[8].Value <<= pTablePositions->getTopFromText(); + + aGrabBagTS[9].Name = "vertAnchor"; + aGrabBagTS[9].Value <<= pTablePositions->getVertAnchor(); + + aGrabBag["TablePosition"] <<= aGrabBagTS; + } + + std::optional aTableStyleVal = m_aTableProperties->getProperty(META_PROP_TABLE_STYLE_NAME); + if(aTableStyleVal) + { + // Apply table style properties recursively + OUString sTableStyleName; + aTableStyleVal->second >>= sTableStyleName; + StyleSheetTablePtr pStyleSheetTable = m_rDMapper_Impl.GetStyleSheetTable(); + const StyleSheetEntryPtr pStyleSheet = pStyleSheetTable->FindStyleSheetByISTD( sTableStyleName ); + pTableStyle = dynamic_cast( pStyleSheet.get( ) ); + m_aTableProperties->Erase( aTableStyleVal->first ); + + aGrabBag["TableStyleName"] <<= sTableStyleName; + + if( pStyleSheet ) + { + // First get the style properties, then the table ones + PropertyMapPtr pTableProps( m_aTableProperties.get() ); + TablePropertyMapPtr pEmptyProps( new TablePropertyMap ); + + m_aTableProperties = pEmptyProps; + + PropertyMapPtr pMergedProperties = pStyleSheet->GetMergedInheritedProperties(pStyleSheetTable); + + table::BorderLine2 aBorderLine; + TableInfo rStyleInfo; + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_TOP_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag["TableStyleTopBorder"] <<= aBorderLine; + } + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_BOTTOM_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag["TableStyleBottomBorder"] <<= aBorderLine; + } + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_LEFT_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag["TableStyleLeftBorder"] <<= aBorderLine; + } + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_RIGHT_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag["TableStyleRightBorder"] <<= aBorderLine; + } + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("mergedProps"); + if (pMergedProperties) + pMergedProperties->dumpXml(); + TagLogger::getInstance().endElement(); +#endif + + m_aTableProperties->InsertProps(pMergedProperties); + m_aTableProperties->InsertProps(pTableProps); + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("TableProperties"); + m_aTableProperties->dumpXml(); + TagLogger::getInstance().endElement(); +#endif + if (pTableStyle) + { + // apply tblHeader setting of the table style + PropertyMapPtr pHeaderStyleProps = pTableStyle->GetProperties(CNF_FIRST_ROW); + if ( pHeaderStyleProps->getProperty(PROP_HEADER_ROW_COUNT) ) + m_aTableProperties->Insert(PROP_HEADER_ROW_COUNT, uno::makeAny( sal_Int32(1)), false); + } + } + } + + // This is the one preserving just all the table look attributes. + std::optional oTableLook = m_aTableProperties->getProperty(META_PROP_TABLE_LOOK); + if (oTableLook) + { + aGrabBag["TableStyleLook"] = oTableLook->second; + m_aTableProperties->Erase(oTableLook->first); + } + + // This is just the "val" attribute's numeric value. + const std::optional aTblLook = m_aTableProperties->getProperty(PROP_TBL_LOOK); + if(aTblLook) + { + aTblLook->second >>= rInfo.nTblLook; + m_aTableProperties->Erase( aTblLook->first ); + } + + // apply cell margin settings of the table style + const std::optional oLeftMargin = m_aTableProperties->getProperty(META_PROP_CELL_MAR_LEFT); + if (oLeftMargin) + { + oLeftMargin->second >>= rInfo.nLeftBorderDistance; + m_aTableProperties->Erase(oLeftMargin->first); + } + const std::optional oRightMargin = m_aTableProperties->getProperty(META_PROP_CELL_MAR_RIGHT); + if (oRightMargin) + { + oRightMargin->second >>= rInfo.nRightBorderDistance; + m_aTableProperties->Erase(oRightMargin->first); + } + const std::optional oTopMargin = m_aTableProperties->getProperty(META_PROP_CELL_MAR_TOP); + if (oTopMargin) + { + oTopMargin->second >>= rInfo.nTopBorderDistance; + m_aTableProperties->Erase(oTopMargin->first); + } + const std::optional oBottomMargin = m_aTableProperties->getProperty(META_PROP_CELL_MAR_BOTTOM); + if (oBottomMargin) + { + oBottomMargin->second >>= rInfo.nBottomBorderDistance; + m_aTableProperties->Erase(oBottomMargin->first); + } + + // Set the table default attributes for the cells + rInfo.pTableDefaults->InsertProps(m_aTableProperties.get()); + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("TableDefaults"); + rInfo.pTableDefaults->dumpXml(); + TagLogger::getInstance().endElement(); +#endif + + if (!aGrabBag.empty()) + { + m_aTableProperties->Insert( PROP_TABLE_INTEROP_GRAB_BAG, uno::makeAny( aGrabBag.getAsConstPropertyValueList() ) ); + } + + m_aTableProperties->getValue( TablePropertyMap::GAP_HALF, nGapHalf ); + + std::optional oLeftMarginFromStyle = m_aTableProperties->getProperty(PROP_LEFT_MARGIN); + if (oLeftMarginFromStyle) + { + oLeftMarginFromStyle->second >>= nLeftMargin; + // don't need to erase, we will push back the adjusted value + // of this (or the direct formatting, if that exists) later + } + m_aTableProperties->getValue( TablePropertyMap::LEFT_MARGIN, nLeftMargin ); + + m_aTableProperties->getValue( TablePropertyMap::CELL_MAR_LEFT, + rInfo.nLeftBorderDistance ); + m_aTableProperties->getValue( TablePropertyMap::CELL_MAR_RIGHT, + rInfo.nRightBorderDistance ); + m_aTableProperties->getValue( TablePropertyMap::CELL_MAR_TOP, + rInfo.nTopBorderDistance ); + m_aTableProperties->getValue( TablePropertyMap::CELL_MAR_BOTTOM, + rInfo.nBottomBorderDistance ); + + table::TableBorderDistances aDistances; + aDistances.IsTopDistanceValid = + aDistances.IsBottomDistanceValid = + aDistances.IsLeftDistanceValid = + aDistances.IsRightDistanceValid = true; + aDistances.TopDistance = static_cast( rInfo.nTopBorderDistance ); + aDistances.BottomDistance = static_cast( rInfo.nBottomBorderDistance ); + aDistances.LeftDistance = static_cast( rInfo.nLeftBorderDistance ); + aDistances.RightDistance = static_cast( rInfo.nRightBorderDistance ); + + m_aTableProperties->Insert( PROP_TABLE_BORDER_DISTANCES, uno::makeAny( aDistances ) ); + + if (!rFrameProperties.empty()) + lcl_DecrementHoriOrientPosition(rFrameProperties, rInfo.nLeftBorderDistance); + + // Set table above/bottom spacing to 0. + m_aTableProperties->Insert( PROP_TOP_MARGIN, uno::makeAny( sal_Int32( 0 ) ) ); + m_aTableProperties->Insert( PROP_BOTTOM_MARGIN, uno::makeAny( sal_Int32( 0 ) ) ); + + //table border settings + table::TableBorder aTableBorder; + table::BorderLine2 aBorderLine, aLeftBorder, aRightBorder; + + if (lcl_extractTableBorderProperty(m_aTableProperties.get(), PROP_TOP_BORDER, rInfo, aBorderLine)) + { + aTableBorder.TopLine = aBorderLine; + aTableBorder.IsTopLineValid = true; + } + if (lcl_extractTableBorderProperty(m_aTableProperties.get(), PROP_BOTTOM_BORDER, rInfo, aBorderLine)) + { + aTableBorder.BottomLine = aBorderLine; + aTableBorder.IsBottomLineValid = true; + } + if (lcl_extractTableBorderProperty(m_aTableProperties.get(), PROP_LEFT_BORDER, rInfo, aLeftBorder)) + { + aTableBorder.LeftLine = aLeftBorder; + aTableBorder.IsLeftLineValid = true; + } + if (lcl_extractTableBorderProperty(m_aTableProperties.get(), PROP_RIGHT_BORDER, rInfo, + aRightBorder)) + { + aTableBorder.RightLine = aRightBorder; + aTableBorder.IsRightLineValid = true; + } + if (lcl_extractTableBorderProperty(m_aTableProperties.get(), META_PROP_HORIZONTAL_BORDER, rInfo, aBorderLine)) + { + aTableBorder.HorizontalLine = aBorderLine; + aTableBorder.IsHorizontalLineValid = true; + } + if (lcl_extractTableBorderProperty(m_aTableProperties.get(), META_PROP_VERTICAL_BORDER, rInfo, aBorderLine)) + { + aTableBorder.VerticalLine = aBorderLine; + aTableBorder.IsVerticalLineValid = true; + } + + aTableBorder.Distance = 0; + aTableBorder.IsDistanceValid = false; + + m_aTableProperties->Insert( PROP_TABLE_BORDER, uno::makeAny( aTableBorder ) ); + +#ifdef DBG_UTIL + lcl_debug_TableBorder(aTableBorder); +#endif + + // Table position in Office is computed in 2 different ways : + // - top level tables: the goal is to have in-cell text starting at table indent pos (tblInd), + // so table's position depends on table's cells margin + // - nested tables: the goal is to have left-most border starting at table_indent pos + + // Only top level table position depends on border width of Column A. + if ( !m_aCellProperties.empty() && !m_aCellProperties[0].empty() ) + { + // aLeftBorder already contains tblBorder; overwrite if cell is different. + std::optional aCellBorder + = m_aCellProperties[0][0]->getProperty(PROP_LEFT_BORDER); + if ( aCellBorder ) + aCellBorder->second >>= aLeftBorder; + aCellBorder = m_aCellProperties[0][0]->getProperty(PROP_RIGHT_BORDER); + if (aCellBorder) + aCellBorder->second >>= aRightBorder; + } + if (rInfo.nNestLevel == 1 && aLeftBorder.LineWidth && !rFrameProperties.empty()) + { + lcl_DecrementHoriOrientPosition(rFrameProperties, aLeftBorder.LineWidth * 0.5); + } + lcl_adjustBorderDistance(rInfo, aLeftBorder, aRightBorder); + + // tdf#106742: since MS Word 2013 (compatibilityMode >= 15), top-level tables are handled the same as nested tables; + // the default behavior when DOCX doesn't define "compatibilityMode" option is to add the cell spacing + + // Undefined should not be possible any more for DOCX, but it is for RTF. + // In any case, continue to treat undefined as version 12 during import. + sal_Int32 nMode = m_rDMapper_Impl.GetSettingsTable()->GetWordCompatibilityMode(); + + if (((nMode < 0) || (0 < nMode && nMode <= 14)) && rInfo.nNestLevel == 1) + { + const sal_Int32 nAdjustedMargin = nLeftMargin - nGapHalf - rInfo.nLeftBorderDistance; + m_aTableProperties->Insert( PROP_LEFT_MARGIN, uno::makeAny( nAdjustedMargin ) ); + } + else + { + // Writer starts a table in the middle of the border. + // Word starts a table at the left edge of the border, + // so emulate that by adding the half the width. (also see docxattributeoutput) + if ( rInfo.nNestLevel > 1 && nLeftMargin < 0 ) + nLeftMargin = 0; + const sal_Int32 nAdjustedMargin = nLeftMargin - nGapHalf + (aLeftBorder.LineWidth / 2); + m_aTableProperties->Insert( PROP_LEFT_MARGIN, uno::makeAny( nAdjustedMargin ) ); + } + + sal_Int32 nTableWidth = 0; + sal_Int32 nTableWidthType = text::SizeType::FIX; + m_aTableProperties->getValue( TablePropertyMap::TABLE_WIDTH, nTableWidth ); + m_aTableProperties->getValue( TablePropertyMap::TABLE_WIDTH_TYPE, nTableWidthType ); + if( nTableWidthType == text::SizeType::FIX ) + { + if( nTableWidth > 0 ) + m_aTableProperties->Insert( PROP_WIDTH, uno::makeAny( nTableWidth )); + else + { + // tdf#109524: If there is no width for the table, make it simply 100% by default. + // TODO: use cell contents to evaluate width (according to ECMA-376-1:2016 17.18.87) + nTableWidth = 100; + nTableWidthType = text::SizeType::VARIABLE; + } + } + if (nTableWidthType != text::SizeType::FIX) + { + m_aTableProperties->Insert( PROP_RELATIVE_WIDTH, uno::makeAny( sal_Int16( nTableWidth ) ) ); + m_aTableProperties->Insert( PROP_IS_WIDTH_RELATIVE, uno::makeAny( true ) ); + } + + sal_Int32 nHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH; + // Fetch Horizontal Orientation in rFrameProperties if not set in m_aTableProperties + if ( !m_aTableProperties->getValue( TablePropertyMap::HORI_ORIENT, nHoriOrient ) ) + lcl_extractHoriOrient( rFrameProperties, nHoriOrient ); + m_aTableProperties->Insert( PROP_HORI_ORIENT, uno::makeAny( sal_Int16(nHoriOrient) ) ); + //fill default value - if not available + m_aTableProperties->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny( sal_Int32(0)), false); + + // if table is only a single row, and row is set as don't split, set the same value for the whole table. + if( m_aRowProperties.size() == 1 && m_aRowProperties[0] ) + { + std::optional oSplitAllowed = m_aRowProperties[0]->getProperty(PROP_IS_SPLIT_ALLOWED); + if( oSplitAllowed ) + { + bool bRowCanSplit = true; + oSplitAllowed->second >>= bRowCanSplit; + if( !bRowCanSplit ) + m_aTableProperties->Insert( PROP_SPLIT, uno::makeAny(bRowCanSplit) ); + } + } + + rInfo.aTableProperties = m_aTableProperties->GetPropertyValues(); + rInfo.aTablePropertyIds = m_aTableProperties->GetPropertyIds(); + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("debug.tableprops"); + m_aTableProperties->dumpXml(); + TagLogger::getInstance().endElement(); +#endif + + } + + return pTableStyle; +} + +CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(TableInfo & rInfo, std::vector& rMerges) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("getCellProperties"); +#endif + + CellPropertyValuesSeq_t aCellProperties( m_aCellProperties.size() ); + + if ( m_aCellProperties.empty() ) + { + #ifdef DBG_UTIL + TagLogger::getInstance().endElement(); + #endif + return aCellProperties; + } + // std::vector< std::vector > m_aCellProperties + PropertyMapVector2::const_iterator aRowOfCellsIterator = m_aCellProperties.begin(); + PropertyMapVector2::const_iterator aRowOfCellsIteratorEnd = m_aCellProperties.end(); + PropertyMapVector2::const_iterator aLastRowIterator = m_aCellProperties.end() - 1; + sal_Int32 nRow = 0; + + css::uno::Sequence* pCellProperties = aCellProperties.getArray(); + PropertyMapVector1::const_iterator aRowIter = m_aRowProperties.begin(); + while( aRowOfCellsIterator != aRowOfCellsIteratorEnd ) + { + //aRowOfCellsIterator points to a vector of PropertyMapPtr + PropertyMapVector1::const_iterator aCellIterator = aRowOfCellsIterator->begin(); + PropertyMapVector1::const_iterator aCellIteratorEnd = aRowOfCellsIterator->end(); + + sal_Int32 nRowStyleMask = 0; + + if (aRowOfCellsIterator==m_aCellProperties.begin()) + { + if(rInfo.nTblLook&0x20) + nRowStyleMask |= CNF_FIRST_ROW; // first row style used + } + else if (aRowOfCellsIterator==aLastRowIterator) + { + if(rInfo.nTblLook&0x40) + nRowStyleMask |= CNF_LAST_ROW; // last row style used + } + else if (*aRowIter && (*aRowIter)->isSet(PROP_TBL_HEADER)) + nRowStyleMask |= CNF_FIRST_ROW; // table header implies first row + if(!nRowStyleMask) // if no row style used yet + { + // banding used only if not first and or last row style used + if(!(rInfo.nTblLook&0x200)) + { // hbanding used + int n = nRow + 1; + if(rInfo.nTblLook&0x20) + n++; + if(n & 1) + nRowStyleMask = CNF_ODD_HBAND; + else + nRowStyleMask = CNF_EVEN_HBAND; + } + } + + sal_Int32 nCell = 0; + pCellProperties[nRow].realloc( aRowOfCellsIterator->size() ); + beans::PropertyValues* pSingleCellProperties = pCellProperties[nRow].getArray(); + + while( aCellIterator != aCellIteratorEnd ) + { + PropertyMapPtr pAllCellProps( new PropertyMap ); + + PropertyMapVector1::const_iterator aLastCellIterator = aRowOfCellsIterator->end() - 1; + bool bIsEndCol = aCellIterator == aLastCellIterator; + bool bIsEndRow = aRowOfCellsIterator == aLastRowIterator; + + //aCellIterator points to a PropertyMapPtr; + if( *aCellIterator ) + { + // remove directly applied insideV/H borders since they are meaningless without a context (tdf#82177) + (*aCellIterator)->Erase(META_PROP_VERTICAL_BORDER); + (*aCellIterator)->Erase(META_PROP_HORIZONTAL_BORDER); + + pAllCellProps->InsertProps(rInfo.pTableDefaults); + + sal_Int32 nCellStyleMask = 0; + if (aCellIterator==aRowOfCellsIterator->begin()) + { + if(rInfo.nTblLook&0x80) + nCellStyleMask = CNF_FIRST_COLUMN; // first col style used + } + else if (bIsEndCol) + { + if(rInfo.nTblLook&0x100) + nCellStyleMask = CNF_LAST_COLUMN; // last col style used + } + if(!nCellStyleMask) // if no cell style is used yet + { + if(!(rInfo.nTblLook&0x400)) + { // vbanding used + int n = nCell + 1; + if(rInfo.nTblLook&0x80) + n++; + if(n & 1) + nCellStyleMask = CNF_ODD_VBAND; + else + nCellStyleMask = CNF_EVEN_VBAND; + } + } + sal_Int32 nCnfStyleMask = nCellStyleMask + nRowStyleMask; + if(nCnfStyleMask == CNF_FIRST_COLUMN + CNF_FIRST_ROW) + nCnfStyleMask |= CNF_FIRST_ROW_FIRST_COLUMN; + else if(nCnfStyleMask == CNF_FIRST_COLUMN + CNF_LAST_ROW) + nCnfStyleMask |= CNF_LAST_ROW_FIRST_COLUMN; + else if(nCnfStyleMask == CNF_LAST_COLUMN + CNF_FIRST_ROW) + nCnfStyleMask |= CNF_FIRST_ROW_LAST_COLUMN; + else if(nCnfStyleMask == CNF_LAST_COLUMN + CNF_LAST_ROW) + nCnfStyleMask |= CNF_LAST_ROW_LAST_COLUMN; + + if ( rInfo.pTableStyle ) + { + PropertyMapPtr pStyleProps = rInfo.pTableStyle->GetProperties( nCnfStyleMask ); + + // Check if we need to clean up some empty border definitions to match what Word does. + static const PropertyIds pBorders[] = + { + PROP_TOP_BORDER, PROP_LEFT_BORDER, PROP_BOTTOM_BORDER, PROP_RIGHT_BORDER + }; + for (const PropertyIds& rBorder : pBorders) + { + std::optional oStyleCellBorder = pStyleProps->getProperty(rBorder); + std::optional oRowCellBorder; + std::optional oDirectCellBorder = (*aCellIterator)->getProperty(rBorder); + if (oStyleCellBorder && oDirectCellBorder) + { + // We have a cell border from the table style and as direct formatting as well. + table::BorderLine2 aStyleCellBorder = oStyleCellBorder->second.get(); + table::BorderLine2 aDirectCellBorder = oDirectCellBorder->second.get(); + if (aStyleCellBorder.LineStyle != table::BorderLineStyle::NONE && aDirectCellBorder.LineStyle == table::BorderLineStyle::NONE) + { + // The style one would be visible, but then cleared away as direct formatting. + // Delete both, so that table formatting can become visible. + pStyleProps->Erase(rBorder); + (*aCellIterator)->Erase(rBorder); + } + else + { + std::optional oTableBorder = rInfo.pTableBorders->getProperty(rBorder); + if (oTableBorder) + { + table::BorderLine2 aTableBorder = oTableBorder->second.get(); + // Both style and direct formatting says that the cell has no border. + bool bNoCellBorder = aStyleCellBorder.LineStyle == table::BorderLineStyle::NONE && aDirectCellBorder.LineStyle == table::BorderLineStyle::NONE; + if (aTableBorder.LineStyle != table::BorderLineStyle::NONE && bNoCellBorder) + { + // But at a table-level, there is a border, then again delete both cell properties. + pStyleProps->Erase(rBorder); + (*aCellIterator)->Erase(rBorder); + } + } + } + } + } + + pAllCellProps->InsertProps( pStyleProps ); + } + + // Remove properties from style/row that aren't allowed in cells + pAllCellProps->Erase( PROP_HEADER_ROW_COUNT ); + pAllCellProps->Erase( PROP_TBL_HEADER ); + + // Then add the cell properties + pAllCellProps->InsertProps(*aCellIterator); + std::swap(*(*aCellIterator), *pAllCellProps ); + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("cell"); + TagLogger::getInstance().attribute("cell", nCell); + TagLogger::getInstance().attribute("row", nRow); +#endif + + // Do not apply horizontal and vertical borders to a one cell table. + if (m_aCellProperties.size() <= 1 && aRowOfCellsIterator->size() <= 1) + { + rInfo.pTableBorders->Erase(META_PROP_HORIZONTAL_BORDER); + rInfo.pTableBorders->Erase(META_PROP_VERTICAL_BORDER); + } + // Do not apply vertical borders to a one column table. + else if (m_aCellProperties.size() > 1 && aRowOfCellsIterator->size() <= 1) + { + bool isOneCol = true; + for (size_t i = nRow; i < m_aCellProperties.size(); i++) + { + if (m_aCellProperties[i].size() > 1) + { + isOneCol = false; + break; + } + } + if (isOneCol) + rInfo.pTableBorders->Erase(META_PROP_VERTICAL_BORDER); + } + // Do not apply horizontal borders to a one row table. + else if (m_aCellProperties.size() == 1 && aRowOfCellsIterator->size() > 1) + { + rInfo.pTableBorders->Erase(META_PROP_HORIZONTAL_BORDER); + } + + // tdf#129452 Checking if current cell is vertically merged with all the other cells below to the bottom. + // This must be done in order to apply the bottom border of the table to the first cell in a vertical merge. + bool bMergedVertically = bool(m_aCellProperties[nRow][nCell]->getProperty(PROP_VERTICAL_MERGE)); + + for (size_t i = nRow + 1; bMergedVertically && i < m_aCellProperties.size(); i++) + if ( m_aCellProperties[i].size() > sal::static_int_cast(nCell) ) + bMergedVertically = bool(m_aCellProperties[i][nCell]->getProperty(PROP_VERTICAL_MERGE)); + + lcl_computeCellBorders( rInfo.pTableBorders, *aCellIterator, nCell, nRow, bIsEndCol, bIsEndRow, bMergedVertically ); + + //now set the default left+right border distance TODO: there's an sprm containing the default distance! + aCellIterator->get()->Insert( PROP_LEFT_BORDER_DISTANCE, + uno::makeAny(rInfo.nLeftBorderDistance ), false); + aCellIterator->get()->Insert( PROP_RIGHT_BORDER_DISTANCE, + uno::makeAny(rInfo.nRightBorderDistance ), false); + aCellIterator->get()->Insert( PROP_TOP_BORDER_DISTANCE, + uno::makeAny(rInfo.nTopBorderDistance ), false); + aCellIterator->get()->Insert( PROP_BOTTOM_BORDER_DISTANCE, + uno::makeAny(rInfo.nBottomBorderDistance ), false); + + // Horizontal merge is not a UNO property, extract that info here to rMerges, and then remove it from the map. + const std::optional aHorizontalMergeVal = (*aCellIterator)->getProperty(PROP_HORIZONTAL_MERGE); + if (aHorizontalMergeVal) + { + if (aHorizontalMergeVal->second.get()) + { + // first cell in a merge + HorizontallyMergedCell aMerge(nRow, nCell); + rMerges.push_back(aMerge); + } + else if (!rMerges.empty()) + { + // resuming an earlier merge + HorizontallyMergedCell& rMerge = rMerges.back(); + rMerge.m_nLastRow = nRow; + rMerge.m_nLastCol = nCell; + } + (*aCellIterator)->Erase(PROP_HORIZONTAL_MERGE); + } + pSingleCellProperties[nCell] = (*aCellIterator)->GetPropertyValues(); +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif + } + ++nCell; + ++aCellIterator; + } + ++nRow; + ++aRowOfCellsIterator; + ++aRowIter; + } + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif + + return aCellProperties; +} + +/// Do all cells in this row have a CellHideMark property? +static bool lcl_hideMarks(PropertyMapVector1& rCellProperties) +{ + for (const PropertyMapPtr & p : rCellProperties) + { + // if anything is vertically merged, the row must not be set to fixed + // as Writer's layout doesn't handle that well + if (!p->isSet(PROP_CELL_HIDE_MARK) || p->isSet(PROP_VERTICAL_MERGE)) + return false; + } + return true; +} + +/// Are all cells in this row empty? +static bool lcl_emptyRow(std::vector& rTableRanges, sal_Int32 nRow) +{ + if (nRow >= static_cast(rTableRanges.size())) + { + SAL_WARN("writerfilter.dmapper", "m_aCellProperties not in sync with rTableRanges?"); + return false; + } + + RowSequence_t rRowSeq = rTableRanges[nRow]; + if (!rRowSeq.hasElements()) + { + SAL_WARN("writerfilter.dmapper", "m_aCellProperties not in sync with rTableRanges?"); + return false; + } + + if (!rRowSeq[0][0].is()) + { + // This can happen when we can't import the table, e.g. we're inside a + // comment. + SAL_WARN("writerfilter.dmapper", "rRowSeq[0][0] is an empty reference"); + return false; + } + + uno::Reference xTextRangeCompare(rRowSeq[0][0]->getText(), uno::UNO_QUERY); + try + { + // See SwXText::Impl::ConvertCell(), we need to compare the start of + // the start and the end of the end. However for our text ranges, only + // the starts are set, so compareRegionStarts() does what we need. + bool bRangesAreNotEqual = std::any_of(rRowSeq.begin(), rRowSeq.end(), + [&xTextRangeCompare](const CellSequence_t& rCellSeq) { + return xTextRangeCompare->compareRegionStarts(rCellSeq[0], rCellSeq[1]) != 0; }); + if (bRangesAreNotEqual) + return false; + } + catch (const lang::IllegalArgumentException&) + { + TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", "compareRegionStarts() failed"); + return false; + } + return true; +} + +css::uno::Sequence DomainMapperTableHandler::endTableGetRowProperties() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("getRowProperties"); +#endif + + css::uno::Sequence aRowProperties( m_aRowProperties.size() ); + sal_Int32 nRow = 0; + for( const auto& rRow : m_aRowProperties ) + { +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("rowProps.row"); +#endif + if (rRow) + { + //set default to 'break across pages" + rRow->Insert( PROP_IS_SPLIT_ALLOWED, uno::makeAny(true ), false ); + // tblHeader is only our property, remove before the property map hits UNO + rRow->Erase(PROP_TBL_HEADER); + + if (lcl_hideMarks(m_aCellProperties[nRow]) && lcl_emptyRow(m_aTableRanges, nRow)) + { + // We have CellHideMark on all cells, and also all cells are empty: + // Force the row height to be exactly as specified, and not just as the minimum suggestion. + rRow->Insert(PROP_SIZE_TYPE, uno::makeAny(text::SizeType::FIX)); + } + + aRowProperties[nRow] = rRow->GetPropertyValues(); +#ifdef DBG_UTIL + rRow->dumpXml(); + lcl_DumpPropertyValues(aRowProperties[nRow]); +#endif + } + ++nRow; +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif + } + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif + + return aRowProperties; +} + +// table style has got bigger precedence than docDefault style, +// but lower precedence than the paragraph styles and direct paragraph formatting +void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParagraph rParaProp, std::vector< PropertyIds > aAllTableParaProperties, css::beans::PropertyValues rCellProperties) +{ + for( auto const& eId : aAllTableParaProperties ) + { + // apply paragraph and character properties of the table style on table paragraphs + // if there is no direct paragraph formatting + if ( !rParaProp.m_pPropertyMap->isSet(eId) ) + { + OUString sPropertyName = getPropertyName(eId); + auto pCellProp = std::find_if(rCellProperties.begin(), rCellProperties.end(), + [&](const beans::PropertyValue& rProp) { return rProp.Name == sPropertyName; }); + // this cell applies the table style property + if (pCellProp != rCellProperties.end()) + { + bool bDocDefault; + // handle paragraph background color defined in CellColorHandler + if (eId == PROP_FILL_COLOR) + { + // table style defines paragraph background color, use the correct property name + auto pFillStyleProp = std::find_if(rCellProperties.begin(), rCellProperties.end(), + [&](const beans::PropertyValue& rProp) { return rProp.Name == "FillStyle"; }); + if ( pFillStyleProp != rCellProperties.end() && + pFillStyleProp->Value == uno::makeAny(drawing::FillStyle_SOLID) ) + { + sPropertyName = "ParaBackColor"; + } + else + { + // FillStyle_NONE, skip table style usage for paragraph background color + continue; + } + } + OUString sParaStyleName; + rParaProp.m_rPropertySet->getPropertyValue("ParaStyleName") >>= sParaStyleName; + StyleSheetEntryPtr pEntry = m_rDMapper_Impl.GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(sParaStyleName); + uno::Any aParaStyle = m_rDMapper_Impl.GetPropertyFromStyleSheet(eId, pEntry, true, true, &bDocDefault); + // A very strange compatibility rule says that the DEFAULT style's specified fontsize of 11 or 12 + // or a specified left justify will always be overridden by the table-style. + // Normally this rule is applied, so always do this unless a compatSetting indicates otherwise. + bool bCompatOverride = false; + if ( (eId == PROP_CHAR_HEIGHT || eId == PROP_PARA_ADJUST) && sParaStyleName == m_rDMapper_Impl.GetDefaultParaStyleName() ) + { + if ( eId == PROP_CHAR_HEIGHT ) + bCompatOverride = aParaStyle == uno::Any(double(11)) || aParaStyle == uno::Any(double(12)); + else if ( eId == PROP_PARA_ADJUST ) + { + style::ParagraphAdjust eAdjust(style::ParagraphAdjust_CENTER); + aParaStyle >>= eAdjust; + bCompatOverride = eAdjust == style::ParagraphAdjust_LEFT; + } + + // The wording is confusing here. Normally, the paragraph style DOES override the table-style. + // But for these two special situations, do not override the table-style. So the default is false. + // If false, then "CompatOverride" the normal behaviour, and apply the table-style's value. + bCompatOverride &= !m_rDMapper_Impl.GetSettingsTable()->GetCompatSettingValue("overrideTableStyleFontSizeAndJustification"); + } + + // use table style when no paragraph style setting or a docDefault value is applied instead of it + if ( aParaStyle == uno::Any() || bDocDefault || bCompatOverride ) try + { + // check property state of paragraph + uno::Reference xParagraph( + rParaProp.m_rEndParagraph->getText()->createTextCursorByRange(rParaProp.m_rEndParagraph), uno::UNO_QUERY_THROW ); + // select paragraph + xParagraph->gotoStartOfParagraph( true ); + uno::Reference< beans::XPropertyState > xParaProperties( xParagraph, uno::UNO_QUERY_THROW ); + if ( xParaProperties->getPropertyState(sPropertyName) == css::beans::PropertyState_DEFAULT_VALUE ) + { + if ( eId != PROP_FILL_COLOR ) + { + // apply style setting when the paragraph doesn't modify it + rParaProp.m_rPropertySet->setPropertyValue( sPropertyName, pCellProp->Value ); + } + else + { + // we need this for complete import of table-style based paragraph background color + rParaProp.m_rPropertySet->setPropertyValue( "FillColor", pCellProp->Value ); + rParaProp.m_rPropertySet->setPropertyValue( "FillStyle", uno::makeAny(drawing::FillStyle_SOLID) ); + } + } + else + { + // apply style setting only on text portions without direct modification of it + uno::Reference xParaEnumAccess(xParagraph, uno::UNO_QUERY); + uno::Reference xParaEnum = xParaEnumAccess->createEnumeration(); + uno::Reference xRunEnumAccess(xParaEnum->nextElement(), uno::UNO_QUERY); + uno::Reference xRunEnum = xRunEnumAccess->createEnumeration(); + while ( xRunEnum->hasMoreElements() ) + { + uno::Reference xRun(xRunEnum->nextElement(), uno::UNO_QUERY); + uno::Reference< beans::XPropertyState > xRunProperties( xRun, uno::UNO_QUERY_THROW ); + if ( xRunProperties->getPropertyState(sPropertyName) == css::beans::PropertyState_DEFAULT_VALUE ) + { + uno::Reference< beans::XPropertySet > xRunPropertySet( xRun, uno::UNO_QUERY_THROW ); + xRunPropertySet->setPropertyValue( sPropertyName, pCellProp->Value ); + } + } + } + } + catch ( const uno::Exception & ) + { + TOOLS_INFO_EXCEPTION("writerfilter.dmapper", "Exception during table style correction"); + } + } + } + } +} + +void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel, bool bTableStartsAtCellStart) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablehandler.endTable"); +#endif + + // If we want to make this table a floating one. + std::vector aFrameProperties = comphelper::sequenceToContainer > + (m_rDMapper_Impl.getTableManager().getCurrentTablePosition()); + TableInfo aTableInfo; + aTableInfo.nNestLevel = nestedTableLevel; + aTableInfo.pTableStyle = endTableGetTableStyle(aTableInfo, aFrameProperties); + // expands to uno::Sequence< Sequence< beans::PropertyValues > > + + std::vector aMerges; + CellPropertyValuesSeq_t aCellProperties = endTableGetCellProperties(aTableInfo, aMerges); + + css::uno::Sequence aRowProperties = endTableGetRowProperties(); + +#ifdef DBG_UTIL + lcl_DumpPropertyValueSeq(aRowProperties); +#endif + + if (!m_aTableRanges.empty()) + { + uno::Reference xStart; + uno::Reference xEnd; + + bool bFloating = !aFrameProperties.empty(); + + // OOXML table style may contain paragraph properties, apply these on cell paragraphs + if ( m_aTableRanges[0].hasElements() && m_aTableRanges[0][0].hasElements() ) + { + // collect all paragraph properties used in table styles + PropertyMapPtr pAllTableProps( new PropertyMap ); + pAllTableProps->InsertProps(aTableInfo.pTableDefaults); + if ( aTableInfo.pTableStyle ) + pAllTableProps->InsertProps(aTableInfo.pTableStyle->GetProperties( CNF_ALL )); + for (const auto& eId : pAllTableProps->GetPropertyIds()) + { + if ( !isParagraphProperty(eId) && !isCharacterProperty(eId) ) + pAllTableProps->Erase(eId); + } + std::vector< PropertyIds > aAllTableParaProperties = pAllTableProps->GetPropertyIds(); + + if ( !aAllTableParaProperties.empty() ) + { + TableParagraphVectorPtr pTableParagraphs = m_rDMapper_Impl.getTableManager().getCurrentParagraphs(); + for (size_t nRow = 0; nRow < m_aTableRanges.size(); ++nRow) + { + for (size_t nCell = 0; nCell < m_aTableRanges[nRow].size(); ++nCell) + { + auto rStartPara = m_aTableRanges[nRow][nCell][0]; + if (!rStartPara.is()) + continue; + auto rEndPara = m_aTableRanges[nRow][nCell][1]; + uno::Reference xTextRangeCompare(rStartPara->getText(), uno::UNO_QUERY); + bool bApply = false; + // search paragraphs of the cell + std::vector::iterator aIt = pTableParagraphs->begin(); + while ( aIt != pTableParagraphs->end() ) try + { + if (!bApply && xTextRangeCompare->compareRegionStarts(rStartPara, aIt->m_rStartParagraph) == 0) + bApply = true; + if (bApply) + { + bool bEndOfApply = (xTextRangeCompare->compareRegionEnds(rEndPara, aIt->m_rEndParagraph) == 0); + ApplyParagraphPropertiesFromTableStyle(*aIt, aAllTableParaProperties, aCellProperties[nRow][nCell]); + // erase processed paragraph from list of pending paragraphs + aIt = pTableParagraphs->erase(aIt); + if (bEndOfApply) + break; + } + else + ++aIt; + } + catch( const lang::IllegalArgumentException & ) + { + // skip compareRegion with nested tables + ++aIt; + } + } + } + } + } + + // Additional checks: if we can do this. + if (bFloating && m_aTableRanges[0].hasElements() && m_aTableRanges[0][0].hasElements()) + { + xStart = m_aTableRanges[0][0][0]; + uno::Sequence< uno::Sequence< uno::Reference > >& rLastRow = m_aTableRanges[m_aTableRanges.size() - 1]; + if (rLastRow.hasElements()) + { + uno::Sequence< uno::Reference >& rLastCell = rLastRow[rLastRow.getLength() - 1]; + xEnd = rLastCell[1]; + } + } + uno::Reference xTable; + try + { + if (m_xText.is()) + { + xTable = m_xText->convertToTable(comphelper::containerToSequence(m_aTableRanges), aCellProperties, aRowProperties, aTableInfo.aTableProperties); + + if (xTable.is()) + { + if (!aMerges.empty()) + { + static const std::vector aBorderNames + = { "TopBorder", "LeftBorder", "BottomBorder", "RightBorder" }; + + // Perform horizontal merges in reverse order, so the fact that merging changes the position of cells won't cause a problem for us. + for (std::vector::reverse_iterator it = aMerges.rbegin(); it != aMerges.rend(); ++it) + { + uno::Reference xCellRange(xTable, uno::UNO_QUERY_THROW); + uno::Reference xFirstCell( + xCellRange->getCellByPosition(it->m_nFirstCol, it->m_nFirstRow), + uno::UNO_QUERY_THROW); + OUString aFirst + = xFirstCell->getPropertyValue("CellName").get(); + // tdf#105852: Only try to merge if m_nLastCol is set (i.e. there were some merge continuation cells) + if (it->m_nLastCol != -1) + { + // Save border properties of the first cell + // before merge. + table::BorderLine2 aBorderValues[4]; + for (size_t i = 0; i < aBorderNames.size(); ++i) + xFirstCell->getPropertyValue(aBorderNames[i]) + >>= aBorderValues[i]; + + uno::Reference xLastCell( + xCellRange->getCellByPosition(it->m_nLastCol, it->m_nLastRow), + uno::UNO_QUERY_THROW); + OUString aLast + = xLastCell->getPropertyValue("CellName").get(); + + uno::Reference xCursor = xTable->createCursorByCellName(aFirst); + xCursor->gotoCellByName(aLast, true); + + xCursor->mergeRange(); + + // Handle conflicting properties: mergeRange() + // takes the last cell, Word takes the first + // cell. + for (size_t i = 0; i < aBorderNames.size(); ++i) + { + if (aBorderValues[i].LineStyle != table::BorderLineStyle::NONE) + xFirstCell->setPropertyValue( + aBorderNames[i], uno::makeAny(aBorderValues[i])); + } + } + } + } + } + } + } + catch ( const lang::IllegalArgumentException & ) + { + TOOLS_INFO_EXCEPTION("writerfilter.dmapper", "Conversion to table error"); +#ifdef DBG_UTIL + TagLogger::getInstance().chars(std::string("failed to import table!")); +#endif + } + catch ( const uno::Exception & ) + { + TOOLS_INFO_EXCEPTION("writerfilter.dmapper", "Exception during table creation"); + } + + // If we have a table with a start and an end position, we should make it a floating one. + // Unless the table had a foot or endnote, as Writer doesn't support those in TextFrames. + if (xTable.is() && xStart.is() && xEnd.is() && !m_bHadFootOrEndnote) + { + uno::Reference xTableProperties(xTable, uno::UNO_QUERY); + bool bIsRelative = false; + xTableProperties->getPropertyValue("IsWidthRelative") >>= bIsRelative; + if (!bIsRelative) + { + beans::PropertyValue aValue; + aValue.Name = "Width"; + aValue.Value = xTableProperties->getPropertyValue("Width"); + aFrameProperties.push_back(aValue); + } + else + { + beans::PropertyValue aValue; + aValue.Name = "FrameWidthPercent"; + aValue.Value = xTableProperties->getPropertyValue("RelativeWidth"); + aFrameProperties.push_back(aValue); + + // Applying the relative width to the frame, needs to have the table width to be 100% of the frame width + xTableProperties->setPropertyValue("RelativeWidth", uno::makeAny(sal_Int16(100))); + } + + // A non-zero left margin would move the table out of the frame, move the frame itself instead. + xTableProperties->setPropertyValue("LeftMargin", uno::makeAny(sal_Int32(0))); + + // In case the document ends with a table, we're called after + // SectionPropertyMap::CloseSectionGroup(), so we'll have no idea + // about the text area width, nor can fix this by delaying the text + // frame conversion: just do it here. + // Also, when the anchor is within a table, then do it here as well, + // as xStart/xEnd would not point to the start/end at conversion + // time anyway. + // Next exception: it's pointless to delay the conversion if the + // table is not in the body text. + sal_Int32 nTableWidth = 0; + m_aTableProperties->getValue(TablePropertyMap::TABLE_WIDTH, nTableWidth); + sal_Int32 nTableWidthType = text::SizeType::FIX; + m_aTableProperties->getValue(TablePropertyMap::TABLE_WIDTH_TYPE, nTableWidthType); + if (m_rDMapper_Impl.GetSectionContext() && nestedTableLevel <= 1 && !m_rDMapper_Impl.IsInHeaderFooter()) + m_rDMapper_Impl.m_aPendingFloatingTables.emplace_back(xStart, xEnd, comphelper::containerToSequence(aFrameProperties), nTableWidth, nTableWidthType); + else + { + // m_xText points to the body text, get the current xText from m_rDMapper_Impl, in case e.g. we would be in a header. + uno::Reference xTextAppendAndConvert(m_rDMapper_Impl.GetTopTextAppend(), uno::UNO_QUERY); + // Only execute the conversion if the table is not anchored at + // the start of an outer table cell, that's not yet + // implemented. + if (xTextAppendAndConvert.is() && !bTableStartsAtCellStart) + xTextAppendAndConvert->convertToTextFrame(xStart, xEnd, comphelper::containerToSequence(aFrameProperties)); + } + } + + // We're right after a table conversion. + m_rDMapper_Impl.m_bConvertedTable = true; + } + + m_aTableProperties.clear(); + m_aCellProperties.clear(); + m_aRowProperties.clear(); + m_bHadFootOrEndnote = false; + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); + TagLogger::getInstance().endElement(); +#endif +} + +void DomainMapperTableHandler::startRow(const TablePropertyMapPtr& pProps) +{ + m_aRowProperties.push_back( pProps.get() ); + m_aCellProperties.emplace_back( ); + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("table.row"); + if (pProps != nullptr) + pProps->dumpXml(); +#endif + + m_aRowRanges.clear(); +} + +void DomainMapperTableHandler::endRow() +{ + m_aTableRanges.push_back(comphelper::containerToSequence(m_aRowRanges)); +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void DomainMapperTableHandler::startCell(const css::uno::Reference< css::text::XTextRange > & start, + const TablePropertyMapPtr& pProps ) +{ + sal_uInt32 nRow = m_aRowProperties.size(); + if ( pProps ) + m_aCellProperties[nRow - 1].push_back( pProps.get() ); + else + { + // Adding an empty cell properties map to be able to get + // the table defaults properties + TablePropertyMapPtr pEmptyProps( new TablePropertyMap( ) ); + m_aCellProperties[nRow - 1].push_back( pEmptyProps.get() ); + } + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("table.cell"); + TagLogger::getInstance().startElement("table.cell.start"); + TagLogger::getInstance().chars(XTextRangeToString(start)); + TagLogger::getInstance().endElement(); + if (pProps) + pProps->printProperties(); +#endif + + //add a new 'row' of properties + m_aCellRange.clear(); + uno::Reference xStart; + if (start) + xStart = start->getStart(); + m_aCellRange.push_back(xStart); +} + +void DomainMapperTableHandler::endCell(const css::uno::Reference< css::text::XTextRange > & end) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("table.cell.end"); + TagLogger::getInstance().chars(XTextRangeToString(end)); + TagLogger::getInstance().endElement(); + TagLogger::getInstance().endElement(); +#endif + + uno::Reference xEnd; + if (end) + xEnd = end->getEnd(); + m_aCellRange.push_back(xEnd); + m_aRowRanges.push_back(comphelper::containerToSequence(m_aCellRange)); +} + +void DomainMapperTableHandler::setHadFootOrEndnote(bool bHadFootOrEndnote) +{ + m_bHadFootOrEndnote = bHadFootOrEndnote; +} + +DomainMapper_Impl& DomainMapperTableHandler::getDomainMapperImpl() +{ + return m_rDMapper_Impl; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx new file mode 100644 index 000000000..545f60919 --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEHANDLER_HXX + +#include "PropertyMap.hxx" +#include + +#include + +namespace writerfilter { +namespace dmapper { + +typedef css::uno::Sequence< css::uno::Reference< css::text::XTextRange > > CellSequence_t; +typedef css::uno::Sequence RowSequence_t; + +typedef css::uno::Sequence< css::uno::Sequence > CellPropertyValuesSeq_t; + +typedef std::vector PropertyMapVector1; +typedef std::vector PropertyMapVector2; + +class DomainMapper_Impl; +class TableStyleSheetEntry; +struct TableInfo; + +/// A horizontally merged cell is in fact a range of cells till its merge is performed. +struct HorizontallyMergedCell +{ + sal_Int32 m_nFirstRow; + sal_Int32 m_nFirstCol; + sal_Int32 m_nLastRow; + sal_Int32 m_nLastCol; + HorizontallyMergedCell(sal_Int32 nFirstRow, sal_Int32 nFirstCol) + : m_nFirstRow(nFirstRow) + , m_nFirstCol(nFirstCol) + , m_nLastRow(nFirstRow) + , m_nLastCol(-1) + { + } +}; + +/// Class to handle events generated by TableManager::resolveCurrentTable(). +class DomainMapperTableHandler final : public virtual SvRefBase +{ + css::uno::Reference m_xText; + DomainMapper_Impl& m_rDMapper_Impl; + std::vector< css::uno::Reference > m_aCellRange; + std::vector m_aRowRanges; + std::vector m_aTableRanges; + + // properties + PropertyMapVector2 m_aCellProperties; + PropertyMapVector1 m_aRowProperties; + TablePropertyMapPtr m_aTableProperties; + + /// Did we have a foot or endnote in this table? + bool m_bHadFootOrEndnote; + + TableStyleSheetEntry * endTableGetTableStyle(TableInfo & rInfo, std::vector& rFrameProperties); + CellPropertyValuesSeq_t endTableGetCellProperties(TableInfo & rInfo, std::vector& rMerges); + css::uno::Sequence endTableGetRowProperties(); + +public: + typedef tools::SvRef Pointer_t; + + DomainMapperTableHandler(css::uno::Reference const& xText, + DomainMapper_Impl& rDMapper_Impl); + ~DomainMapperTableHandler() override; + + /** + Handle start of table. + + @param pProps properties of the table + */ + void startTable(const TablePropertyMapPtr& pProps); + + void ApplyParagraphPropertiesFromTableStyle(TableParagraph rParaProp, std::vector< PropertyIds > aAllTableProperties, css::beans::PropertyValues rCellProperties); + + /// Handle end of table. + void endTable(unsigned int nestedTableLevel, bool bTableStartsAtCellStart); + /** + Handle start of row. + + @param pProps properties of the row + */ + void startRow(const TablePropertyMapPtr& pProps); + /// Handle end of row. + void endRow(); + /** + Handle start of cell. + + @param rT start handle of the cell + @param pProps properties of the cell + */ + void startCell(const css::uno::Reference< css::text::XTextRange > & start, const TablePropertyMapPtr& pProps); + /** + Handle end of cell. + + @param rT end handle of cell + */ + void endCell(const css::uno::Reference< css::text::XTextRange > & end); + + void setHadFootOrEndnote(bool bHadFootOrEndnote); + + DomainMapper_Impl& getDomainMapperImpl(); +}; + +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx new file mode 100644 index 000000000..a19b9395e --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx @@ -0,0 +1,863 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include +#include "DomainMapperTableManager.hxx" +#include "ConversionHelper.hxx" +#include "MeasureHandler.hxx" +#include "TagLogger.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; +using namespace ::std; + +DomainMapperTableManager::DomainMapperTableManager() : + m_nRow(0), + m_nCell(), + m_nGridSpan(1), + m_aGridBefore(), + m_nGridAfter(0), + m_nHeaderRepeat(0), + m_nTableWidth(0), + m_bIsInShape(false), + m_aTmpPosition(), + m_aTmpTableProperties(), + m_bPushCurrentWidth(false), + m_bTableSizeTypeInserted(false), + m_nLayoutType(0), + m_aParagraphsToEndTable(), + m_pTablePropsHandler(new TablePropertiesHandler()) +{ + m_pTablePropsHandler->SetTableManager( this ); +} + + +DomainMapperTableManager::~DomainMapperTableManager() +{ +} + +bool DomainMapperTableManager::attribute(Id nName, Value const & rValue) +{ + bool bRet = true; + + switch (nName) + { + case NS_ooxml::LN_CT_TblLook_val: + { + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(PROP_TBL_LOOK, uno::makeAny(rValue.getInt())); + insertTableProps(pPropMap); + m_aTableLook["val"] <<= static_cast(rValue.getInt()); + } + break; + case NS_ooxml::LN_CT_TblLook_noVBand: + m_aTableLook["noVBand"] <<= static_cast(rValue.getInt()); + break; + case NS_ooxml::LN_CT_TblLook_noHBand: + m_aTableLook["noHBand"] <<= static_cast(rValue.getInt()); + break; + case NS_ooxml::LN_CT_TblLook_lastColumn: + m_aTableLook["lastColumn"] <<= static_cast(rValue.getInt()); + break; + case NS_ooxml::LN_CT_TblLook_lastRow: + m_aTableLook["lastRow"] <<= static_cast(rValue.getInt()); + break; + case NS_ooxml::LN_CT_TblLook_firstColumn: + m_aTableLook["firstColumn"] <<= static_cast(rValue.getInt()); + break; + case NS_ooxml::LN_CT_TblLook_firstRow: + m_aTableLook["firstRow"] <<= static_cast(rValue.getInt()); + break; + default: + bRet = false; + } + + return bRet; +} + +void DomainMapperTableManager::finishTableLook() +{ + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(META_PROP_TABLE_LOOK, uno::makeAny(m_aTableLook.getAsConstPropertyValueList())); + m_aTableLook.clear(); + insertTableProps(pPropMap); +} + +bool DomainMapperTableManager::sprm(Sprm & rSprm) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.sprm"); + string sSprm = rSprm.toString(); + TagLogger::getInstance().chars(sSprm); + TagLogger::getInstance().endElement(); +#endif + bool bRet = TableManager::sprm(rSprm); + if( !bRet ) + { + bRet = m_pTablePropsHandler->sprm( rSprm ); + } + + if ( !bRet ) + { + bRet = true; + sal_uInt32 nSprmId = rSprm.getId(); + Value::Pointer_t pValue = rSprm.getValue(); + sal_Int32 nIntValue = ((pValue.get() != nullptr) ? pValue->getInt() : 0); + switch ( nSprmId ) + { + case NS_ooxml::LN_CT_TblPrBase_tblW: + case NS_ooxml::LN_CT_TblPrBase_tblInd: + { + //contains unit and value + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + MeasureHandlerPtr pMeasureHandler( new MeasureHandler ); + pProperties->resolve(*pMeasureHandler); + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + if (nSprmId == sal_uInt32(NS_ooxml::LN_CT_TblPrBase_tblInd)) + { + pPropMap->setValue( TablePropertyMap::LEFT_MARGIN, pMeasureHandler->getMeasureValue() ); + } + else + { + m_nTableWidth = pMeasureHandler->getMeasureValue(); + if( m_nTableWidth ) + { + pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::FIX ); + pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth ); + m_bTableSizeTypeInserted = true; + } + else if( sal::static_int_cast(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_pct ) + { + sal_Int32 nPercent = pMeasureHandler->getValue() / 50; + if(nPercent > 100) + nPercent = 100; + pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::VARIABLE ); + pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, nPercent ); + m_bTableSizeTypeInserted = true; + } + else if( sal::static_int_cast(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_auto ) + { + /* + This attribute specifies the width type of table. This is used as part of the table layout + algorithm specified by the tblLayout element.(See 17.4.64 and 17.4.65 of the ISO/IEC 29500-1:2011.) + If this value is 'auto', the table layout has to use the preferred widths on the table items to generate + the final sizing of the table, but then must use the contents of each cell to determine final column widths. + (See 17.18.87 of the ISO/IEC 29500-1:2011.) + */ + IntVectorPtr pCellWidths = getCurrentCellWidths(); + // Check whether all cells have fixed widths in the given row of table. + bool bFixed = std::find(pCellWidths->begin(), pCellWidths->end(), -1) == pCellWidths->end(); + if (!bFixed) + { + // Set the width type of table with 'Auto' and set the width value to 0 (as per grid values) + pPropMap->setValue( TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::VARIABLE ); + pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, 0 ); + m_bTableSizeTypeInserted = true; + } + else if (getTableDepth() > 1) + { + // tdf#131819 limiting the fix for nested tables temporarily + // TODO revert the fix for tdf#104876 and reopen it + m_bTableSizeTypeInserted = true; + } + } + } +#ifdef DBG_UTIL + pPropMap->dumpXml(); +#endif + insertTableProps(pPropMap); + } + } + break; + case NS_ooxml::LN_CT_TrPrBase_tblHeader: + // if nIntValue == 1 then the row is a repeated header line + // to prevent later rows from increasing the repeating m_nHeaderRepeat is set to NULL when repeating stops + if( nIntValue > 0 && m_nHeaderRepeat == static_cast(m_nRow) ) + { + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + + // FIXME: DOCX tables with more than 10 repeating header lines imported + // without repeating header lines to mimic an MSO workaround for its usability bug. + // Explanation: it's very hard to set and modify repeating header rows in Word, + // often resulting tables with a special workaround: setting all table rows as + // repeating header, because exceeding the pages by "unlimited" header rows turns off the + // table headers automatically in MSO. 10-row limit is a reasonable temporary limit + // to handle DOCX tables with "unlimited" repeating header, till the same "turn off + // exceeding header" feature is ready (see tdf#88496). +#define HEADER_ROW_LIMIT_FOR_MSO_WORKAROUND 10 + if ( m_nHeaderRepeat == HEADER_ROW_LIMIT_FOR_MSO_WORKAROUND ) + { + m_nHeaderRepeat = -1; + pPropMap->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny(sal_Int32(0))); + } + else + { + ++m_nHeaderRepeat; + pPropMap->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny( m_nHeaderRepeat )); + } + insertTableProps(pPropMap); + } + else + { + if ( nIntValue == 0 && m_nRow == 0 ) + { + // explicit tblHeader=0 in the first row must overwrite table style + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny(sal_Int32(0))); + insertTableProps(pPropMap); + } + m_nHeaderRepeat = -1; + } + if (nIntValue) + { + // Store the info that this is a header, we'll need that when we apply table styles. + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->Insert( PROP_TBL_HEADER, uno::makeAny(nIntValue)); + insertRowProps(pPropMap); + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblStyle: //table style name + { + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->Insert( META_PROP_TABLE_STYLE_NAME, uno::makeAny( pValue->getString() )); + insertTableProps(pPropMap); + } + break; + case NS_ooxml::LN_CT_TblGridBase_gridCol: + { + if (nIntValue == -1) + getCurrentGrid()->clear(); + else + getCurrentGrid()->push_back( nIntValue ); + } + break; + case NS_ooxml::LN_CT_TcPrBase_vMerge : //vertical merge + { + // values can be: LN_Value_ST_Merge_restart, LN_Value_ST_Merge_continue, in reality the second one is a 0 + TablePropertyMapPtr pMergeProps( new TablePropertyMap ); + pMergeProps->Insert( PROP_VERTICAL_MERGE, uno::makeAny( sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_ST_Merge_restart ) ); + cellProps( pMergeProps); + } + break; + case NS_ooxml::LN_CT_TcPrBase_hMerge: + { + // values can be: LN_Value_ST_Merge_restart, LN_Value_ST_Merge_continue, in reality the second one is a 0 + TablePropertyMapPtr pMergeProps(new TablePropertyMap()); + pMergeProps->Insert(PROP_HORIZONTAL_MERGE, uno::makeAny( sal::static_int_cast(nIntValue) == NS_ooxml::LN_Value_ST_Merge_restart )); + cellProps(pMergeProps); + } + break; + case NS_ooxml::LN_CT_TcPrBase_gridSpan: //number of grid positions spanned by this cell + { +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.GridSpan"); + TagLogger::getInstance().attribute("gridSpan", nIntValue); + TagLogger::getInstance().endElement(); +#endif + m_nGridSpan = nIntValue; + } + break; + case NS_ooxml::LN_CT_TcPrBase_textDirection: + { + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + bool bInsertCellProps = true; + switch ( nIntValue ) + { + case NS_ooxml::LN_Value_ST_TextDirection_tbRl: + // Binary filter takes BiDirection into account ( but I have no idea about that here ) + // or even what it is. But... here's where to handle it if it becomes an issue + pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::TB_RL )); + SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue ); + break; + case NS_ooxml::LN_Value_ST_TextDirection_btLr: + pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::BT_LR )); + break; + case NS_ooxml::LN_Value_ST_TextDirection_lrTbV: + pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::LR_TB )); + break; + case NS_ooxml::LN_Value_ST_TextDirection_tbRlV: + pPropMap->Insert( PROP_FRM_DIRECTION, uno::makeAny( text::WritingMode2::TB_RL )); + break; + case NS_ooxml::LN_Value_ST_TextDirection_lrTb: + case NS_ooxml::LN_Value_ST_TextDirection_tbLrV: + default: + // Ignore - we can't handle these + bInsertCellProps = false; + break; + } + if ( bInsertCellProps ) + cellProps( pPropMap ); + break; + } + case NS_ooxml::LN_CT_TcPrBase_tcW: + { + // Contains unit and value, but unit is not interesting for + // us, later we'll just distribute these values in a + // 0..10000 scale. + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + MeasureHandlerPtr pMeasureHandler(new MeasureHandler()); + pProperties->resolve(*pMeasureHandler); + if (sal::static_int_cast(pMeasureHandler->getUnit()) == NS_ooxml::LN_Value_ST_TblWidth_auto) + getCurrentCellWidths()->push_back(sal_Int32(-1)); + else + // store the original value to limit rounding mistakes, if it's there in a recognized measure (twip) + getCurrentCellWidths()->push_back(pMeasureHandler->getMeasureValue() ? pMeasureHandler->getValue() : sal_Int32(0)); + if (getTableDepthDifference() > 0) + m_bPushCurrentWidth = true; + } + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblpPr: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + // Ignore in shape text, those tables should be always non-floating ones. + if (!m_bIsInShape && pProperties) + { + TablePositionHandlerPtr pHandler = m_aTmpPosition.back(); + if ( !pHandler ) + { + m_aTmpPosition.pop_back(); + pHandler = new TablePositionHandler; + m_aTmpPosition.push_back( pHandler ); + } + pProperties->resolve(*m_aTmpPosition.back()); + } + } + break; + case NS_ooxml::LN_CT_TrPrBase_gridBefore: + m_aGridBefore.back( ) = nIntValue; + break; + case NS_ooxml::LN_CT_TrPrBase_gridAfter: + m_nGridAfter = nIntValue; + break; + case NS_ooxml::LN_CT_TblPrBase_tblCaption: + // To-Do: Not yet preserved + break; + case NS_ooxml::LN_CT_TblPrBase_tblDescription: + // To-Do: Not yet preserved + break; + case NS_ooxml::LN_CT_TrPrBase_tblCellSpacing: + // To-Do: Not yet preserved + break; + case NS_ooxml::LN_CT_TblPrBase_tblCellSpacing: + // To-Do: Not yet preserved + break; + case NS_ooxml::LN_CT_TblPrBase_bidiVisual: + { + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(PROP_WRITING_MODE, uno::makeAny(sal_Int16(nIntValue ? text::WritingMode2::RL_TB : text::WritingMode2::LR_TB))); + insertTableProps(pPropMap); + break; + } + default: + bRet = false; + +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + } + } + return bRet; +} + +DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurrentGrid( ) +{ + return m_aTableGrid.back( ); +} + +sal_uInt32 DomainMapperTableManager::getCurrentGridBefore( ) +{ + return m_aGridBefore.back( ); +} + +DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurrentSpans( ) +{ + return m_aGridSpans.back( ); +} + +DomainMapperTableManager::IntVectorPtr const & DomainMapperTableManager::getCurrentCellWidths( ) +{ + return m_aCellWidths.back( ); +} + +uno::Sequence DomainMapperTableManager::getCurrentTablePosition( ) +{ + if ( !m_aTablePositions.empty( ) && m_aTablePositions.back() ) + return m_aTablePositions.back( )->getTablePosition(); + else + return uno::Sequence< beans::PropertyValue >(); +} + +TablePositionHandler* DomainMapperTableManager::getCurrentTableRealPosition() +{ + if ( !m_aTablePositions.empty( ) && m_aTablePositions.back() ) + return m_aTablePositions.back().get(); + else + return nullptr; +} + +TableParagraphVectorPtr DomainMapperTableManager::getCurrentParagraphs( ) +{ + return m_aParagraphsToEndTable.top( ); +} + +void DomainMapperTableManager::setIsInShape(bool bIsInShape) +{ + m_bIsInShape = bIsInShape; +} + +void DomainMapperTableManager::startLevel( ) +{ + TableManager::startLevel( ); + + // If requested, pop the value that was pushed too early. + std::optional oCurrentWidth; + if (m_bPushCurrentWidth && !m_aCellWidths.empty() && !m_aCellWidths.back()->empty()) + { + oCurrentWidth = m_aCellWidths.back()->back(); + m_aCellWidths.back()->pop_back(); + } + std::optional oParagraph; + if (getTableDepthDifference() > 0 && !m_aParagraphsToEndTable.empty() && !m_aParagraphsToEndTable.top()->empty()) + { + oParagraph = m_aParagraphsToEndTable.top()->back(); + m_aParagraphsToEndTable.top()->pop_back(); + } + + IntVectorPtr pNewGrid = std::make_shared>(); + IntVectorPtr pNewSpans = std::make_shared>(); + IntVectorPtr pNewCellWidths = std::make_shared>(); + TablePositionHandlerPtr pNewPositionHandler; + m_aTableGrid.push_back( pNewGrid ); + m_aGridSpans.push_back( pNewSpans ); + m_aCellWidths.push_back( pNewCellWidths ); + m_aTablePositions.push_back( pNewPositionHandler ); + // empty name will be replaced by the table style name, if it exists + m_aTableStyleNames.push_back( OUString() ); + + TablePositionHandlerPtr pTmpPosition; + TablePropertyMapPtr pTmpProperties( new TablePropertyMap( ) ); + m_aTmpPosition.push_back( pTmpPosition ); + m_aTmpTableProperties.push_back( pTmpProperties ); + m_nCell.push_back( 0 ); + m_aGridBefore.push_back( 0 ); + m_nTableWidth = 0; + m_nLayoutType = 0; + TableParagraphVectorPtr pNewParagraphs = std::make_shared>(); + m_aParagraphsToEndTable.push( pNewParagraphs ); + + // And push it back to the right level. + if (oCurrentWidth) + m_aCellWidths.back()->push_back(*oCurrentWidth); + if (oParagraph) + m_aParagraphsToEndTable.top()->push_back(*oParagraph); +} + +void DomainMapperTableManager::endLevel( ) +{ + if (m_aTableGrid.empty()) + { + SAL_WARN("writerfilter.dmapper", "Table stack is empty"); + return; + } + + m_aTableGrid.pop_back( ); + m_aGridSpans.pop_back( ); + + // Do the same trick as in startLevel(): pop the value that was pushed too early. + std::optional oCurrentWidth; + if (m_bPushCurrentWidth && !m_aCellWidths.empty() && !m_aCellWidths.back()->empty()) + oCurrentWidth = m_aCellWidths.back()->back(); + m_aCellWidths.pop_back( ); + // And push it back to the right level. + if (oCurrentWidth && !m_aCellWidths.empty() && !m_aCellWidths.back()->empty()) + m_aCellWidths.back()->push_back(*oCurrentWidth); + + m_nCell.pop_back( ); + m_aGridBefore.pop_back( ); + m_nTableWidth = 0; + m_nLayoutType = 0; + + m_aTmpPosition.pop_back( ); + m_aTmpTableProperties.pop_back( ); + + TableManager::endLevel( ); +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("dmappertablemanager.endLevel"); + PropertyMapPtr pProps = getTableProps().get(); + if (pProps.get() != nullptr) + getTableProps()->dumpXml(); + + TagLogger::getInstance().endElement(); +#endif + + // Pop back the table position after endLevel as it's used + // in the endTable method called in endLevel. + m_aTablePositions.pop_back(); + m_aTableStyleNames.pop_back(); + m_aParagraphsToEndTable.pop(); +} + +void DomainMapperTableManager::endOfCellAction() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().element("endOFCellAction"); +#endif + + if (m_aGridSpans.empty()) + throw std::out_of_range("empty spans"); + m_aGridSpans.back()->push_back(m_nGridSpan); + m_nGridSpan = 1; + ++m_nCell.back( ); +} + +bool DomainMapperTableManager::shouldInsertRow(IntVectorPtr pCellWidths, IntVectorPtr pTableGrid, size_t nGrids, bool& rIsIncompleteGrid) +{ + if (pCellWidths->empty()) + return false; + if (m_nLayoutType == NS_ooxml::LN_Value_doc_ST_TblLayout_fixed) + return true; + if (pCellWidths->size() == (nGrids + m_nGridAfter)) + return true; + rIsIncompleteGrid = true; + return nGrids + m_nGridAfter > pTableGrid->size(); +} + +void DomainMapperTableManager::endOfRowAction() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("endOfRowAction"); +#endif + + // Compare the table position and style with the previous ones. We may need to split + // into two tables if those are different. We surely don't want to do anything + // if we don't have any row yet. + TablePositionHandlerPtr pTmpPosition = m_aTmpPosition.back(); + TablePropertyMapPtr pTablePropMap = m_aTmpTableProperties.back( ); + TablePositionHandlerPtr pCurrentPosition = m_aTablePositions.back(); + bool bSamePosition = ( pTmpPosition == pCurrentPosition ) || + ( pTmpPosition && pCurrentPosition && *pTmpPosition == *pCurrentPosition ); + bool bIsSetTableStyle = pTablePropMap->isSet(META_PROP_TABLE_STYLE_NAME); + OUString sTableStyleName; + bool bSameTableStyle = ( !bIsSetTableStyle && m_aTableStyleNames.back().isEmpty()) || + ( bIsSetTableStyle && + (pTablePropMap->getProperty(META_PROP_TABLE_STYLE_NAME)->second >>= sTableStyleName) && + sTableStyleName == m_aTableStyleNames.back() ); + if ( (!bSamePosition || !bSameTableStyle) && m_nRow > 0 ) + { + // Save the grid infos to have them survive the end/start level + IntVectorPtr pTmpTableGrid = m_aTableGrid.back(); + IntVectorPtr pTmpGridSpans = m_aGridSpans.back(); + IntVectorPtr pTmpCellWidths = m_aCellWidths.back(); + sal_uInt32 nTmpCell = m_nCell.back(); + sal_uInt32 nTmpGridBefore = m_aGridBefore.back(); + TableParagraphVectorPtr pTableParagraphs = getCurrentParagraphs(); + + // endLevel and startLevel are taking care of the non finished row + // to carry it over to the next table + setKeepUnfinishedRow( true ); + endLevel(); + setKeepUnfinishedRow( false ); + startLevel(); + + m_aTableGrid.pop_back(); + m_aGridSpans.pop_back(); + m_aCellWidths.pop_back(); + m_nCell.pop_back(); + m_aGridBefore.pop_back(); + m_aTableGrid.push_back(pTmpTableGrid); + m_aGridSpans.push_back(pTmpGridSpans); + m_aCellWidths.push_back(pTmpCellWidths); + m_nCell.push_back(nTmpCell); + m_aGridBefore.push_back(nTmpGridBefore); + m_aParagraphsToEndTable.pop( ); + m_aParagraphsToEndTable.push( pTableParagraphs ); + } + // save table style in the first row for comparison + if ( m_nRow == 0 && pTablePropMap->isSet(META_PROP_TABLE_STYLE_NAME) ) + { + pTablePropMap->getProperty(META_PROP_TABLE_STYLE_NAME)->second >>= sTableStyleName; + m_aTableStyleNames.pop_back(); + m_aTableStyleNames.push_back( sTableStyleName ); + } + + // Push the tmp position now that we compared it + m_aTablePositions.pop_back(); + m_aTablePositions.push_back( pTmpPosition ); + m_aTmpPosition.back().clear( ); + + + IntVectorPtr pTableGrid = getCurrentGrid( ); + IntVectorPtr pCellWidths = getCurrentCellWidths( ); + if(!m_nTableWidth && !pTableGrid->empty()) + { +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tableWidth"); +#endif + + for( const auto& rCell : *pTableGrid ) + { +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("col"); + TagLogger::getInstance().attribute("width", rCell); + TagLogger::getInstance().endElement(); +#endif + + m_nTableWidth = o3tl::saturating_add(m_nTableWidth, rCell); + } + if (m_nTableWidth) + // convert sum of grid twip values to 1/100 mm with rounding up to avoid table width loss + m_nTableWidth = static_cast(ceil(ConversionHelper::convertTwipToMM100Double(m_nTableWidth))); + + if (m_nTableWidth > 0 && !m_bTableSizeTypeInserted) + { + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->setValue( TablePropertyMap::TABLE_WIDTH, m_nTableWidth ); + insertTableProps(pPropMap); + } + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif + } + + IntVectorPtr pCurrentSpans = getCurrentSpans( ); + + if( m_aGridBefore.back() > 0 ) + { + //fill missing gridBefore elements with '1' + pCurrentSpans->insert( pCurrentSpans->begin( ), m_aGridBefore.back(), 1 ); + } + if( pCurrentSpans->size() < m_aGridBefore.back() + m_nCell.back( )) + { + //fill missing elements with '1' + pCurrentSpans->insert( pCurrentSpans->end( ), m_aGridBefore.back() + m_nCell.back( ) - pCurrentSpans->size(), 1 ); + } + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("gridSpans"); + { + for (const auto& rGridSpan : *pCurrentSpans) + { + TagLogger::getInstance().startElement("gridSpan"); + TagLogger::getInstance().attribute("span", rGridSpan); + TagLogger::getInstance().endElement(); + } + } + TagLogger::getInstance().endElement(); +#endif + + //calculate number of used grids - it has to match the size of m_aTableGrid + size_t nGrids = std::accumulate(pCurrentSpans->begin(), pCurrentSpans->end(), sal::static_int_cast(0)); + + // sj: the grid is having no units... it is containing only relative values. + // a table with a grid of "1:2:1" looks identical as if the table is having + // a grid of "20:40:20" and it doesn't have to do something with the tableWidth + // -> so we have get the sum of each grid entry for the fullWidthRelative: + int nFullWidthRelative = 0; + for (int i : (*pTableGrid)) + nFullWidthRelative = o3tl::saturating_add(nFullWidthRelative, i); + + bool bIsIncompleteGrid = false; + if( pTableGrid->size() == ( nGrids + m_nGridAfter ) && m_nCell.back( ) > 0 ) + { + /* + * If table width property set earlier is smaller than the current table width, + * then replace the TABLE_WIDTH property, set earlier. + */ + sal_Int32 nTableWidth(0); + sal_Int32 nTableWidthType(text::SizeType::VARIABLE); + pTablePropMap->getValue(TablePropertyMap::TABLE_WIDTH, nTableWidth); + pTablePropMap->getValue(TablePropertyMap::TABLE_WIDTH_TYPE, nTableWidthType); + if ((nTableWidthType == text::SizeType::FIX) && (nTableWidth < m_nTableWidth)) + { + pTablePropMap->setValue(TablePropertyMap::TABLE_WIDTH, m_nTableWidth); + } + if (nTableWidthType == text::SizeType::VARIABLE ) + { + if(nTableWidth > 100 || nTableWidth <= 0) + { + if(getTableDepth() > 1 && !m_bTableSizeTypeInserted) + { + pTablePropMap->setValue(TablePropertyMap::TABLE_WIDTH, sal_Int32(100)); + pTablePropMap->setValue(TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::VARIABLE); + } + else + { + pTablePropMap->setValue(TablePropertyMap::TABLE_WIDTH, m_nTableWidth); + pTablePropMap->setValue(TablePropertyMap::TABLE_WIDTH_TYPE, text::SizeType::FIX); + } + } + } + uno::Sequence< text::TableColumnSeparator > aSeparators( m_aGridBefore.back() + m_nCell.back( ) - 1 ); + text::TableColumnSeparator* pSeparators = aSeparators.getArray(); + double nLastRelPos = 0.0; + sal_uInt32 nBorderGridIndex = 0; + + size_t nWidthsBound = m_aGridBefore.back() + m_nCell.back() - 1; + if (nWidthsBound) + { + if (nFullWidthRelative == 0) + throw o3tl::divide_by_zero(); + + ::std::vector< sal_Int32 >::const_iterator aSpansIter = pCurrentSpans->begin( ); + for( size_t nBorder = 0; nBorder < nWidthsBound; ++nBorder ) + { + double fGridWidth = 0.; + for ( sal_Int32 nGridCount = *aSpansIter; nGridCount > 0; --nGridCount ) + fGridWidth += (*pTableGrid)[nBorderGridIndex++]; + + double nRelPos = (fGridWidth * 10000) / nFullWidthRelative; + + pSeparators[nBorder].Position = rtl::math::round(nRelPos + nLastRelPos); + pSeparators[nBorder].IsVisible = true; + nLastRelPos = nLastRelPos + nRelPos; + ++aSpansIter; + } + } + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, uno::makeAny( aSeparators ) ); + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("rowProperties"); + pPropMap->dumpXml(); + TagLogger::getInstance().endElement(); +#endif + insertRowProps(pPropMap); + } + else if (shouldInsertRow(pCellWidths, pTableGrid, nGrids, bIsIncompleteGrid)) + { + // If we're here, then the number of cells does not equal to the amount + // defined by the grid, even after taking care of + // gridSpan/gridBefore/gridAfter. Handle this by ignoring the grid and + // providing the separators based on the provided cell widths, as long + // as we have a fixed layout; + // On the other hand even if the layout is not fixed, but the cell widths + // provided equal the total number of cells, and there are no after/before cells + // then use the cell widths to calculate the column separators. + // Also handle autofit tables with incomplete grids, when rows can have + // different widths and last cells can be wider, than their values. + uno::Sequence< text::TableColumnSeparator > aSeparators(pCellWidths->size() - 1); + text::TableColumnSeparator* pSeparators = aSeparators.getArray(); + sal_Int16 nSum = 0; + sal_uInt32 nPos = 0; + + if (bIsIncompleteGrid) + nFullWidthRelative = 0; + + // Avoid divide by zero (if there's no grid, position using cell widths). + if( nFullWidthRelative == 0 ) + for (size_t i = 0; i < pCellWidths->size(); ++i) + nFullWidthRelative += (*pCellWidths)[i]; + + if (bIsIncompleteGrid) + { + /* + * If table width property set earlier is smaller than the current table row width, + * then replace the TABLE_WIDTH property, set earlier. + */ + sal_Int32 nFullWidth = static_cast(ceil(ConversionHelper::convertTwipToMM100Double(nFullWidthRelative))); + sal_Int32 nTableWidth(0); + sal_Int32 nTableWidthType(text::SizeType::VARIABLE); + pTablePropMap->getValue(TablePropertyMap::TABLE_WIDTH, nTableWidth); + pTablePropMap->getValue(TablePropertyMap::TABLE_WIDTH_TYPE, nTableWidthType); + if (nTableWidth < nFullWidth) + { + pTablePropMap->setValue(TablePropertyMap::TABLE_WIDTH, nFullWidth); + } + } + + size_t nWidthsBound = pCellWidths->size() - 1; + if (nWidthsBound) + { + if (nFullWidthRelative == 0) + throw o3tl::divide_by_zero(); + + // At incomplete table grids, last cell width can be smaller, than its final width. + // Correct it based on the last but one column width and their span values. + if ( bIsIncompleteGrid && pCurrentSpans->size()-1 == nWidthsBound ) + { + auto aSpansIter = std::next(pCurrentSpans->begin( ), nWidthsBound - 1); + sal_Int32 nFixLastCellWidth = (*pCellWidths)[nWidthsBound-1] / *aSpansIter * *std::next(aSpansIter); + if (nFixLastCellWidth > (*pCellWidths)[nWidthsBound]) + nFullWidthRelative += nFixLastCellWidth - (*pCellWidths)[nWidthsBound]; + } + + for (size_t i = 0; i < nWidthsBound; ++i) + { + nSum += (*pCellWidths)[i]; + pSeparators[nPos].Position = (nSum * 10000) / nFullWidthRelative; // Relative position + pSeparators[nPos].IsVisible = true; + nPos++; + } + } + + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->Insert( PROP_TABLE_COLUMN_SEPARATORS, uno::makeAny( aSeparators ) ); +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("rowProperties"); + pPropMap->dumpXml(); + TagLogger::getInstance().endElement(); +#endif + insertRowProps(pPropMap); + } + + // Now that potentially opened table is closed, save the table properties + TableManager::insertTableProps(pTablePropMap); + + m_aTmpTableProperties.pop_back(); + TablePropertyMapPtr pEmptyTableProps( new TablePropertyMap() ); + m_aTmpTableProperties.push_back( pEmptyTableProps ); + + ++m_nRow; + m_nCell.back( ) = 0; + m_aGridBefore.back( ) = 0; + getCurrentGrid()->clear(); + pCurrentSpans->clear(); + pCellWidths->clear(); + + m_nGridAfter = 0; + m_bTableSizeTypeInserted = false; + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void DomainMapperTableManager::clearData() +{ + m_nRow = m_nHeaderRepeat = m_nTableWidth = m_nLayoutType = 0; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.hxx b/writerfilter/source/dmapper/DomainMapperTableManager.hxx new file mode 100644 index 000000000..50d5f2ff2 --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapperTableManager.hxx @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEMANAGER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEMANAGER_HXX + +#include "TablePropertiesHandler.hxx" +#include "TablePositionHandler.hxx" + +#include "TableManager.hxx" +#include "PropertyMap.hxx" +#include +#include +#include + +namespace writerfilter { +namespace dmapper { + +class DomainMapper; + +class DomainMapperTableManager : public TableManager +{ + typedef std::shared_ptr< std::vector > IntVectorPtr; + + sal_uInt32 m_nRow; + ::std::vector< sal_uInt32 > m_nCell; + sal_uInt32 m_nGridSpan; + ::std::vector< sal_uInt32 > m_aGridBefore; ///< number of grid columns in the parent table's table grid which must be skipped before the contents of this table row are added to the parent table + sal_uInt32 m_nGridAfter; ///< number of grid columns in the parent table's table grid which shall be left after the last cell in the table row + sal_Int32 m_nHeaderRepeat; //counter of repeated headers - if == -1 then the repeating stops + sal_Int32 m_nTableWidth; //might be set directly or has to be calculated from the column positions + /// Are we in a shape (text append stack is not empty) or in the body document? + bool m_bIsInShape; + std::vector< OUString > m_aTableStyleNames; + /// Grab-bag of table look attributes for preserving. + comphelper::SequenceAsHashMap m_aTableLook; + std::vector< TablePositionHandlerPtr > m_aTablePositions; + std::vector< TablePositionHandlerPtr > m_aTmpPosition; ///< Temporarily stores the position to compare it later + std::vector< TablePropertyMapPtr > m_aTmpTableProperties; ///< Temporarily stores the table properties until end of row + + ::std::vector< IntVectorPtr > m_aTableGrid; + ::std::vector< IntVectorPtr > m_aGridSpans; + /// If this is true, then we pushed a width before the next level started, and that should be carried over when starting the next level. + bool m_bPushCurrentWidth; + /// Individual table cell width values, used only in case the number of cells doesn't match the table grid. + ::std::vector< IntVectorPtr > m_aCellWidths; + /// Remember if table width was already set, when we lack a w:tblW, it should be set manually at the end. + bool m_bTableSizeTypeInserted; + /// Table layout algorithm, IOW if we should consider fixed column width or not. + sal_uInt32 m_nLayoutType; + /// Collected table paragraphs for table style handling + std::stack< TableParagraphVectorPtr > m_aParagraphsToEndTable; + + std::unique_ptr m_pTablePropsHandler; + PropertyMapPtr m_pStyleProps; + + bool shouldInsertRow(IntVectorPtr pCellWidths, IntVectorPtr pTableGrid, size_t nGrids, bool& rIsIncompleteGrid); + + virtual void clearData() override; + +public: + + DomainMapperTableManager(); + virtual ~DomainMapperTableManager() override; + + // use this method to avoid adding the properties for the table + // but in the provided properties map. + void SetStyleProperties( PropertyMapPtr pProperties ) { m_pStyleProps = pProperties; }; + + virtual bool sprm(Sprm & rSprm) override; + bool attribute(Id nName, Value const & val); + + virtual void startLevel( ) override; + virtual void endLevel( ) override; + + virtual void endOfCellAction() override; + virtual void endOfRowAction() override; + + IntVectorPtr const & getCurrentGrid( ); + IntVectorPtr const & getCurrentSpans( ); + IntVectorPtr const & getCurrentCellWidths( ); + sal_uInt32 getCurrentGridBefore( ); + TableParagraphVectorPtr getCurrentParagraphs( ); + + /// Turn the attributes collected so far in m_aTableLook into a property and clear the container. + void finishTableLook(); + css::uno::Sequence getCurrentTablePosition(); + TablePositionHandler* getCurrentTableRealPosition(); + + virtual void cellProps(const TablePropertyMapPtr& pProps) override + { + if ( m_pStyleProps ) + m_pStyleProps->InsertProps(pProps.get()); + else + TableManager::cellProps( pProps ); + }; + + virtual void insertRowProps(const TablePropertyMapPtr& pProps) override + { + if ( m_pStyleProps ) + m_pStyleProps->InsertProps(pProps.get()); + else + TableManager::insertRowProps( pProps ); + }; + + virtual void insertTableProps(const TablePropertyMapPtr& pProps) override + { + if ( m_pStyleProps ) + m_pStyleProps->InsertProps(pProps.get()); + else + m_aTmpTableProperties.back()->InsertProps(pProps.get()); + }; + + void SetLayoutType(sal_uInt32 nLayoutType) + { + m_nLayoutType = nLayoutType; + } + + using TableManager::isInCell; + + void setIsInShape(bool bIsInShape); + +}; + +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPERTABLEMANAGER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx new file mode 100644 index 000000000..12aa623de --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -0,0 +1,7319 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include +#include "DomainMapper_Impl.hxx" +#include "ConversionHelper.hxx" +#include "SdtHelper.hxx" +#include "DomainMapperTableHandler.hxx" +#include "TagLogger.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace ::com::sun::star; +using namespace oox; +namespace writerfilter::dmapper{ + +//line numbering for header/footer +static void lcl_linenumberingHeaderFooter( const uno::Reference& xStyles, const OUString& rname, DomainMapper_Impl* dmapper ) +{ + const StyleSheetEntryPtr pEntry = dmapper->GetStyleSheetTable()->FindStyleSheetByISTD( rname ); + if (!pEntry) + return; + const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast( pEntry->pProperties.get() ); + if ( !pStyleSheetProperties ) + return; + sal_Int32 nListId = pStyleSheetProperties->GetListId(); + if( xStyles.is() ) + { + if( xStyles->hasByName( rname ) ) + { + uno::Reference< style::XStyle > xStyle; + xStyles->getByName( rname ) >>= xStyle; + if( !xStyle.is() ) + return; + uno::Reference xPropertySet( xStyle, uno::UNO_QUERY ); + xPropertySet->setPropertyValue( getPropertyName( PROP_PARA_LINE_NUMBER_COUNT ), uno::makeAny( nListId >= 0 ) ); + } + } +} + +// Populate Dropdown Field properties from FFData structure +static void lcl_handleDropdownField( const uno::Reference< beans::XPropertySet >& rxFieldProps, const FFDataHandler::Pointer_t& pFFDataHandler ) +{ + if ( rxFieldProps.is() ) + { + if ( !pFFDataHandler->getName().isEmpty() ) + rxFieldProps->setPropertyValue( "Name", uno::makeAny( pFFDataHandler->getName() ) ); + + const FFDataHandler::DropDownEntries_t& rEntries = pFFDataHandler->getDropDownEntries(); + uno::Sequence< OUString > sItems( rEntries.size() ); + ::std::copy( rEntries.begin(), rEntries.end(), sItems.begin()); + if ( sItems.hasElements() ) + rxFieldProps->setPropertyValue( "Items", uno::makeAny( sItems ) ); + + sal_Int32 nResult = pFFDataHandler->getDropDownResult().toInt32(); + if ( nResult ) + rxFieldProps->setPropertyValue( "SelectedItem", uno::makeAny( sItems[ nResult ] ) ); + if ( !pFFDataHandler->getHelpText().isEmpty() ) + rxFieldProps->setPropertyValue( "Help", uno::makeAny( pFFDataHandler->getHelpText() ) ); + } +} + +static void lcl_handleTextField( const uno::Reference< beans::XPropertySet >& rxFieldProps, const FFDataHandler::Pointer_t& pFFDataHandler ) +{ + if ( rxFieldProps.is() && pFFDataHandler ) + { + rxFieldProps->setPropertyValue + (getPropertyName(PROP_HINT), + uno::makeAny(pFFDataHandler->getStatusText())); + rxFieldProps->setPropertyValue + (getPropertyName(PROP_HELP), + uno::makeAny(pFFDataHandler->getHelpText())); + rxFieldProps->setPropertyValue + (getPropertyName(PROP_CONTENT), + uno::makeAny(pFFDataHandler->getTextDefault())); + } +} + +namespace { + +struct FieldConversion +{ + const char* cFieldServiceName; + FieldId eFieldId; +}; + +} + +typedef std::unordered_map FieldConversionMap_t; + +/// Gives access to the parent field context of the topmost one, if there is any. +static FieldContextPtr GetParentFieldContext(const std::deque& rFieldStack) +{ + if (rFieldStack.size() < 2) + { + return nullptr; + } + + return rFieldStack[rFieldStack.size() - 2]; +} + +/// Decides if the pInner field inside pOuter is allowed in Writer core, depending on their type. +static bool IsFieldNestingAllowed(const FieldContextPtr& pOuter, const FieldContextPtr& pInner) +{ + if (!pOuter->GetFieldId()) + { + return true; + } + + if (!pInner->GetFieldId()) + { + return true; + } + + switch (*pOuter->GetFieldId()) + { + case FIELD_IF: + { + switch (*pInner->GetFieldId()) + { + case FIELD_MERGEFIELD: + { + return false; + } + default: + break; + } + break; + } + default: + break; + } + + return true; +} + +uno::Any FloatingTableInfo::getPropertyValue(const OUString &propertyName) +{ + for( beans::PropertyValue const & propVal : std::as_const(m_aFrameProperties) ) + if( propVal.Name == propertyName ) + return propVal.Value ; + return uno::Any() ; +} + +DomainMapper_Impl::DomainMapper_Impl( + DomainMapper& rDMapper, + uno::Reference const& xContext, + uno::Reference const& xModel, + SourceDocumentType eDocumentType, + utl::MediaDescriptor const & rMediaDesc) : + m_eDocumentType( eDocumentType ), + m_rDMapper( rDMapper ), + m_xTextDocument( xModel, uno::UNO_QUERY ), + m_xTextFactory( xModel, uno::UNO_QUERY ), + m_xComponentContext( xContext ), + m_bForceGenericFields(!utl::ConfigManager::IsFuzzing() && officecfg::Office::Common::Filter::Microsoft::Import::ForceImportWWFieldsAsGenericFields::get(m_xComponentContext)), + m_bSetUserFieldContent( false ), + m_bSetCitation( false ), + m_bSetDateValue( false ), + m_bIsFirstSection( true ), + m_bIsColumnBreakDeferred( false ), + m_bIsPageBreakDeferred( false ), + m_bSdtEndDeferred(false), + m_bParaSdtEndDeferred(false), + m_bStartTOC(false), + m_bStartTOCHeaderFooter(false), + m_bStartedTOC(false), + m_bStartIndex(false), + m_bStartBibliography(false), + m_nStartGenericField(0), + m_bTextInserted(false), + m_sCurrentPermId(0), + m_pLastSectionContext( ), + m_pLastCharacterContext(), + m_sCurrentParaStyleName(), + m_sDefaultParaStyleName(), + m_bInStyleSheetImport( false ), + m_bInAnyTableImport( false ), + m_eInHeaderFooterImport( HeaderFooterImportState::none ), + m_bDiscardHeaderFooter( false ), + m_bInFootOrEndnote(false), + m_bHasFootnoteStyle(false), + m_bCheckFootnoteStyle(false), + m_eSkipFootnoteState(SkipFootnoteSeparator::OFF), + m_bLineNumberingSet( false ), + m_bIsInFootnoteProperties( false ), + m_bIsParaMarkerChange( false ), + m_bParaChanged( false ), + m_bIsFirstParaInSection( true ), + m_bIsFirstParaInSectionAfterRedline( true ), + m_bDummyParaAddedForTableInSection( false ), + m_bTextFrameInserted(false), + m_bIsPreviousParagraphFramed( false ), + m_bIsLastParaInSection( false ), + m_bIsLastSectionGroup( false ), + m_bIsInComments( false ), + m_bParaSectpr( false ), + m_bUsingEnhancedFields( false ), + m_bSdt(false), + m_bIsFirstRun(false), + m_bIsOutsideAParagraph(true), + m_xAnnotationField(), + m_nAnnotationId( -1 ), + m_aAnnotationPositions(), + m_aSmartTagHandler(m_xComponentContext, m_xTextDocument), + m_xInsertTextRange(rMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference())), + m_bIsNewDoc(!rMediaDesc.getUnpackedValueOrDefault("InsertMode", false)), + m_bIsReadGlossaries(rMediaDesc.getUnpackedValueOrDefault("ReadGlossaries", false)), + m_nTableDepth(0), + m_nTableCellDepth(0), + m_nLastTableCellParagraphDepth(0), + m_bHasFtn(false), + m_bHasFtnSep(false), + m_bCheckFirstFootnoteTab(false), + m_bIgnoreNextTab(false), + m_bIsSplitPara(false), + m_bIsActualParagraphFramed( false ), + m_vTextFramesForChaining(), + m_bParaHadField(false), + m_bParaAutoBefore(false), + m_bFirstParagraphInCell(true), + m_bSaveFirstParagraphInCell(false) + +{ + m_aBaseUrl = rMediaDesc.getUnpackedValueOrDefault( + utl::MediaDescriptor::PROP_DOCUMENTBASEURL(), OUString()); + if (m_aBaseUrl.isEmpty()) { + m_aBaseUrl = rMediaDesc.getUnpackedValueOrDefault( + utl::MediaDescriptor::PROP_URL(), OUString()); + } + + appendTableManager( ); + GetBodyText(); + uno::Reference< text::XTextAppend > xBodyTextAppend( m_xBodyText, uno::UNO_QUERY ); + m_aTextAppendStack.push(TextAppendContext(xBodyTextAppend, + m_bIsNewDoc ? uno::Reference() : m_xBodyText->createTextCursorByRange(m_xInsertTextRange))); + + //todo: does it makes sense to set the body text as static text interface? + uno::Reference< text::XTextAppendAndConvert > xBodyTextAppendAndConvert( m_xBodyText, uno::UNO_QUERY ); + m_pTableHandler = new DomainMapperTableHandler(xBodyTextAppendAndConvert, *this); + getTableManager( ).setHandler(m_pTableHandler); + + getTableManager( ).startLevel(); + m_bUsingEnhancedFields = !utl::ConfigManager::IsFuzzing() && officecfg::Office::Common::Filter::Microsoft::Import::ImportWWFieldsAsEnhancedFields::get(m_xComponentContext); + + m_pSdtHelper = new SdtHelper(*this); + + m_aRedlines.push(std::vector()); +} + + +DomainMapper_Impl::~DomainMapper_Impl() +{ + ChainTextFrames(); + // Don't remove last paragraph when pasting, sw expects that empty paragraph. + if (m_bIsNewDoc) + RemoveLastParagraph(); + if (hasTableManager()) + { + getTableManager().endLevel(); + popTableManager(); + } +} + +uno::Reference< container::XNameContainer > const & DomainMapper_Impl::GetPageStyles() +{ + if(!m_xPageStyles1.is()) + { + uno::Reference< style::XStyleFamiliesSupplier > xSupplier( m_xTextDocument, uno::UNO_QUERY ); + if (xSupplier.is()) + xSupplier->getStyleFamilies()->getByName("PageStyles") >>= m_xPageStyles1; + } + return m_xPageStyles1; +} + +OUString DomainMapper_Impl::GetUnusedPageStyleName() +{ + static const char DEFAULT_STYLE[] = "Converted"; + if (!m_xNextUnusedPageStyleNo) + { + const uno::Sequence< OUString > aPageStyleNames = GetPageStyles()->getElementNames(); + sal_Int32 nMaxIndex = 0; + // find the highest number x in each style with the name "DEFAULT_STYLE+x" and + // return an incremented name + + for ( const auto& rStyleName : aPageStyleNames ) + { + if ( rStyleName.startsWith( DEFAULT_STYLE ) ) + { + sal_Int32 nIndex = rStyleName.copy( strlen( DEFAULT_STYLE ) ).toInt32(); + if ( nIndex > nMaxIndex ) + nMaxIndex = nIndex; + } + } + m_xNextUnusedPageStyleNo = nMaxIndex + 1; + } + + OUString sPageStyleName = DEFAULT_STYLE + OUString::number( *m_xNextUnusedPageStyleNo ); + *m_xNextUnusedPageStyleNo = *m_xNextUnusedPageStyleNo + 1; + return sPageStyleName; +} + +uno::Reference< text::XText > const & DomainMapper_Impl::GetBodyText() +{ + if(!m_xBodyText.is()) + { + if (m_xInsertTextRange.is()) + m_xBodyText = m_xInsertTextRange->getText(); + else if (m_xTextDocument.is()) + m_xBodyText = m_xTextDocument->getText(); + } + return m_xBodyText; +} + + +uno::Reference< beans::XPropertySet > const & DomainMapper_Impl::GetDocumentSettings() +{ + if( !m_xDocumentSettings.is() && m_xTextFactory.is()) + { + m_xDocumentSettings.set( m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY ); + } + return m_xDocumentSettings; +} + + +void DomainMapper_Impl::SetDocumentSettingsProperty( const OUString& rPropName, const uno::Any& rValue ) +{ + uno::Reference< beans::XPropertySet > xSettings = GetDocumentSettings(); + if( xSettings.is() ) + { + try + { + xSettings->setPropertyValue( rPropName, rValue ); + } + catch( const uno::Exception& ) + { + } + } +} +void DomainMapper_Impl::RemoveDummyParaForTableInSection() +{ + SetIsDummyParaAddedForTableInSection(false); + PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_SECTION); + SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); + if (!pSectionContext) + return; + + if (m_aTextAppendStack.empty()) + return; + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (!xTextAppend.is()) + return; + + uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange(pSectionContext->GetStartingRange()); + + // Remove the extra NumPicBullets from the document, + // which get attached to the first paragraph in the + // document + ListsManager::Pointer pListTable = GetListTable(); + pListTable->DisposeNumPicBullets(); + + uno::Reference xEnumerationAccess(xCursor, uno::UNO_QUERY); + if (xEnumerationAccess.is() && m_aTextAppendStack.size() == 1 ) + { + uno::Reference xEnumeration = xEnumerationAccess->createEnumeration(); + uno::Reference xParagraph(xEnumeration->nextElement(), uno::UNO_QUERY); + xParagraph->dispose(); + } +} +void DomainMapper_Impl::AddDummyParaForTableInSection() +{ + // Shapes can't have sections. + if (IsInShape()) + return; + + if (!m_aTextAppendStack.empty()) + { + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is()) + { + xTextAppend->finishParagraph( uno::Sequence< beans::PropertyValue >() ); + SetIsDummyParaAddedForTableInSection(true); + } + } +} + +void DomainMapper_Impl::RemoveLastParagraph( ) +{ + if (m_bDiscardHeaderFooter) + return; + + if (m_aTextAppendStack.empty()) + return; + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (!xTextAppend.is()) + return; + try + { + uno::Reference< text::XTextCursor > xCursor; + if (m_bIsNewDoc) + { + xCursor = xTextAppend->createTextCursor(); + xCursor->gotoEnd(false); + } + else + xCursor = m_aTextAppendStack.top().xCursor; + uno::Reference xEnumerationAccess(xCursor, uno::UNO_QUERY); + // Keep the character properties of the last but one paragraph, even if + // it's empty. This works for headers/footers, and maybe in other cases + // as well, but surely not in textboxes. + // fdo#58327: also do this at the end of the document: when pasting, + // a table before the cursor position would be deleted + // (but only for paste/insert, not load; otherwise it can happen that + // flys anchored at the disposed paragraph are deleted (fdo47036.rtf)) + bool const bEndOfDocument(m_aTextAppendStack.size() == 1); + if ((IsInHeaderFooter() || (bEndOfDocument && !m_bIsNewDoc)) + && xEnumerationAccess.is()) + { + uno::Reference xEnumeration = xEnumerationAccess->createEnumeration(); + uno::Reference xParagraph(xEnumeration->nextElement(), uno::UNO_QUERY); + xParagraph->dispose(); + } + else if (xCursor.is()) + { + xCursor->goLeft( 1, true ); + // If this is a text on a shape, possibly the text has the trailing + // newline removed already. + if (xCursor->getString() == SAL_NEWLINE_STRING || + // tdf#105444 comments need an exception, if SAL_NEWLINE_STRING defined as "\r\n" + (sizeof(SAL_NEWLINE_STRING)-1 == 2 && xCursor->getString() == "\n")) + { + uno::Reference xDocProps(GetTextDocument(), uno::UNO_QUERY); + const OUString aRecordChanges("RecordChanges"); + uno::Any aPreviousValue(xDocProps->getPropertyValue(aRecordChanges)); + + // disable redlining for this operation, otherwise we might + // end up with an unwanted recorded deletion + xDocProps->setPropertyValue(aRecordChanges, uno::Any(false)); + + // delete + xCursor->setString(OUString()); + + // restore again + xDocProps->setPropertyValue(aRecordChanges, aPreviousValue); + } + } + } + catch( const uno::Exception& ) + { + } +} + + +void DomainMapper_Impl::SetIsLastSectionGroup( bool bIsLast ) +{ + m_bIsLastSectionGroup = bIsLast; +} + +void DomainMapper_Impl::SetIsLastParagraphInSection( bool bIsLast ) +{ + m_bIsLastParaInSection = bIsLast; +} + + +void DomainMapper_Impl::SetIsFirstParagraphInSection( bool bIsFirst ) +{ + m_bIsFirstParaInSection = bIsFirst; +} + +void DomainMapper_Impl::SetIsFirstParagraphInSectionAfterRedline( bool bIsFirstAfterRedline ) +{ + m_bIsFirstParaInSectionAfterRedline = bIsFirstAfterRedline; +} + +bool DomainMapper_Impl::GetIsFirstParagraphInSection( bool bAfterRedline ) const +{ + // Anchored objects may include multiple paragraphs, + // and none of them should be considered the first para in section. + return ( bAfterRedline ? m_bIsFirstParaInSectionAfterRedline : m_bIsFirstParaInSection ) + && !IsInShape() + && !m_bIsInComments + && !IsInFootOrEndnote(); +} + +void DomainMapper_Impl::SetIsFirstParagraphInShape(bool bIsFirst) +{ + m_bIsFirstParaInShape = bIsFirst; +} + +void DomainMapper_Impl::SetIsDummyParaAddedForTableInSection( bool bIsAdded ) +{ + m_bDummyParaAddedForTableInSection = bIsAdded; +} + + +void DomainMapper_Impl::SetIsTextFrameInserted( bool bIsInserted ) +{ + m_bTextFrameInserted = bIsInserted; +} + + +void DomainMapper_Impl::SetParaSectpr(bool bParaSectpr) +{ + m_bParaSectpr = bParaSectpr; +} + + +void DomainMapper_Impl::SetSdt(bool bSdt) +{ + m_bSdt = bSdt; + + if (m_bSdt && !m_aTextAppendStack.empty()) + { + m_xSdtEntryStart = GetTopTextAppend()->getEnd(); + } + else + { + m_xSdtEntryStart.clear(); + } +} + + +void DomainMapper_Impl::PushProperties(ContextType eId) +{ + PropertyMapPtr pInsert(eId == CONTEXT_SECTION ? + (new SectionPropertyMap( m_bIsFirstSection )) : + eId == CONTEXT_PARAGRAPH ? new ParagraphPropertyMap : new PropertyMap); + if(eId == CONTEXT_SECTION) + { + if( m_bIsFirstSection ) + m_bIsFirstSection = false; + // beginning with the second section group a section has to be inserted + // into the document + SectionPropertyMap* pSectionContext_ = dynamic_cast< SectionPropertyMap* >( pInsert.get() ); + if (!m_aTextAppendStack.empty()) + { + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is() && pSectionContext_) + pSectionContext_->SetStart( xTextAppend->getEnd() ); + } + } + if(eId == CONTEXT_PARAGRAPH && m_bIsSplitPara) + { + m_aPropertyStacks[eId].push( GetTopContextOfType(eId)); + m_bIsSplitPara = false; + } + else + { + m_aPropertyStacks[eId].push( pInsert ); + } + m_aContextStack.push(eId); + + m_pTopContext = m_aPropertyStacks[eId].top(); +} + + +void DomainMapper_Impl::PushStyleProperties( const PropertyMapPtr& pStyleProperties ) +{ + m_aPropertyStacks[CONTEXT_STYLESHEET].push( pStyleProperties ); + m_aContextStack.push(CONTEXT_STYLESHEET); + + m_pTopContext = m_aPropertyStacks[CONTEXT_STYLESHEET].top(); +} + + +void DomainMapper_Impl::PushListProperties(const PropertyMapPtr& pListProperties) +{ + m_aPropertyStacks[CONTEXT_LIST].push( pListProperties ); + m_aContextStack.push(CONTEXT_LIST); + m_pTopContext = m_aPropertyStacks[CONTEXT_LIST].top(); +} + + +void DomainMapper_Impl::PopProperties(ContextType eId) +{ + OSL_ENSURE(!m_aPropertyStacks[eId].empty(), "section stack already empty"); + if ( m_aPropertyStacks[eId].empty() ) + return; + + if ( eId == CONTEXT_SECTION ) + { + if (m_aPropertyStacks[eId].size() == 1) // tdf#112202 only top level !!! + { + m_pLastSectionContext = m_aPropertyStacks[eId].top(); + } + } + else if (eId == CONTEXT_CHARACTER) + { + m_pLastCharacterContext = m_aPropertyStacks[eId].top(); + // Sadly an assert about deferredCharacterProperties being empty is not possible + // here, because appendTextPortion() may not be called for every character section. + deferredCharacterProperties.clear(); + } + + if (!IsInFootOrEndnote() && IsInCustomFootnote() && !m_aPropertyStacks[eId].empty()) + { + PropertyMapPtr pRet = m_aPropertyStacks[eId].top(); + if (pRet->GetFootnote().is() && m_pFootnoteContext.is()) + EndCustomFootnote(); + } + + m_aPropertyStacks[eId].pop(); + m_aContextStack.pop(); + if(!m_aContextStack.empty() && !m_aPropertyStacks[m_aContextStack.top()].empty()) + + m_pTopContext = m_aPropertyStacks[m_aContextStack.top()].top(); + else + { + // OSL_ENSURE(eId == CONTEXT_SECTION, "this should happen at a section context end"); + m_pTopContext.clear(); + } +} + + +PropertyMapPtr DomainMapper_Impl::GetTopContextOfType(ContextType eId) +{ + PropertyMapPtr pRet; + if(!m_aPropertyStacks[eId].empty()) + pRet = m_aPropertyStacks[eId].top(); + return pRet; +} + +bool DomainMapper_Impl::HasTopText() const +{ + return !m_aTextAppendStack.empty(); +} + +uno::Reference< text::XTextAppend > const & DomainMapper_Impl::GetTopTextAppend() +{ + OSL_ENSURE(!m_aTextAppendStack.empty(), "text append stack is empty" ); + return m_aTextAppendStack.top().xTextAppend; +} + +FieldContextPtr const & DomainMapper_Impl::GetTopFieldContext() +{ + SAL_WARN_IF(m_aFieldStack.empty(), "writerfilter.dmapper", "Field stack is empty"); + return m_aFieldStack.back(); +} + +void DomainMapper_Impl::InitTabStopFromStyle( const uno::Sequence< style::TabStop >& rInitTabStops ) +{ + OSL_ENSURE(m_aCurrentTabStops.empty(), "tab stops already initialized"); + for( const auto& rTabStop : rInitTabStops) + { + m_aCurrentTabStops.emplace_back(rTabStop); + } +} + +void DomainMapper_Impl::IncorporateTabStop( const DeletableTabStop & rTabStop ) +{ + sal_Int32 nConverted = rTabStop.Position; + auto aIt = std::find_if(m_aCurrentTabStops.begin(), m_aCurrentTabStops.end(), + [&nConverted](const DeletableTabStop& rCurrentTabStop) { return rCurrentTabStop.Position == nConverted; }); + if( aIt != m_aCurrentTabStops.end() ) + { + if( rTabStop.bDeleted ) + m_aCurrentTabStops.erase( aIt ); + else + *aIt = rTabStop; + } + else + m_aCurrentTabStops.push_back( rTabStop ); +} + + +uno::Sequence< style::TabStop > DomainMapper_Impl::GetCurrentTabStopAndClear() +{ + std::vector aRet; + for (const DeletableTabStop& rStop : m_aCurrentTabStops) + { + if (!rStop.bDeleted) + aRet.push_back(rStop); + } + m_aCurrentTabStops.clear(); + return comphelper::containerToSequence(aRet); +} + +OUString DomainMapper_Impl::GetCurrentParaStyleName() +{ + OUString sName; + // use saved currParaStyleName as a fallback, in case no particular para style name applied. + // tdf#134784 except in the case of first paragraph of shapes to avoid bad fallback. + // TODO fix this "highly inaccurate" m_sCurrentParaStyleName + if ( !m_bIsFirstParaInShape ) + sName = m_sCurrentParaStyleName; + + PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH); + if ( pParaContext && pParaContext->isSet(PROP_PARA_STYLE_NAME) ) + pParaContext->getProperty(PROP_PARA_STYLE_NAME)->second >>= sName; + + // In rare situations the name might still be blank, so use the default style, + // despite documentation that states, "If this attribute is not specified for any style, + // then no properties shall be applied to objects of the specified type." + // Word, however, assigns "Normal" style even in these situations. + if ( !m_bInStyleSheetImport && sName.isEmpty() ) + sName = GetDefaultParaStyleName(); + + return sName; +} + +OUString DomainMapper_Impl::GetDefaultParaStyleName() +{ + // After import the default style won't change and is frequently requested: cache the LO style name. + // TODO assert !InStyleSheetImport? This function really only makes sense once import is finished anyway. + if ( m_sDefaultParaStyleName.isEmpty() ) + { + const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindDefaultParaStyle(); + if ( pEntry && !pEntry->sConvertedStyleName.isEmpty() ) + { + if ( !m_bInStyleSheetImport ) + m_sDefaultParaStyleName = pEntry->sConvertedStyleName; + return pEntry->sConvertedStyleName; + } + else + return "Standard"; + } + return m_sDefaultParaStyleName; +} + +uno::Any DomainMapper_Impl::GetPropertyFromStyleSheet(PropertyIds eId, StyleSheetEntryPtr pEntry, const bool bDocDefaults, const bool bPara, bool* pIsDocDefault) +{ + while(pEntry) + { + if(pEntry->pProperties) + { + std::optional aProperty = + pEntry->pProperties->getProperty(eId); + if( aProperty ) + { + if (pIsDocDefault) + *pIsDocDefault = pEntry->pProperties->isDocDefault(eId); + + return aProperty->second; + } + } + //search until the property is set or no parent is available + StyleSheetEntryPtr pNewEntry; + if ( !pEntry->sBaseStyleIdentifier.isEmpty() ) + pNewEntry = GetStyleSheetTable()->FindStyleSheetByISTD(pEntry->sBaseStyleIdentifier); + + SAL_WARN_IF( pEntry == pNewEntry, "writerfilter.dmapper", "circular loop in style hierarchy?"); + + if (pEntry == pNewEntry) //fdo#49587 + break; + + pEntry = pNewEntry; + } + // not found in style, try the document's DocDefault properties + if ( bDocDefaults && bPara ) + { + const PropertyMapPtr& pDefaultParaProps = GetStyleSheetTable()->GetDefaultParaProps(); + if ( pDefaultParaProps ) + { + std::optional aProperty = pDefaultParaProps->getProperty(eId); + if ( aProperty ) + { + if (pIsDocDefault) + *pIsDocDefault = true; + + return aProperty->second; + } + } + } + if ( bDocDefaults && isCharacterProperty(eId) ) + { + const PropertyMapPtr& pDefaultCharProps = GetStyleSheetTable()->GetDefaultCharProps(); + if ( pDefaultCharProps ) + { + std::optional aProperty = pDefaultCharProps->getProperty(eId); + if ( aProperty ) + { + if (pIsDocDefault) + *pIsDocDefault = true; + + return aProperty->second; + } + } + } + + if (pIsDocDefault) + *pIsDocDefault = false; + + return uno::Any(); +} + +uno::Any DomainMapper_Impl::GetPropertyFromParaStyleSheet(PropertyIds eId) +{ + StyleSheetEntryPtr pEntry; + if ( m_bInStyleSheetImport ) + pEntry = GetStyleSheetTable()->GetCurrentEntry(); + else + pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(GetCurrentParaStyleName()); + return GetPropertyFromStyleSheet(eId, pEntry, /*bDocDefaults=*/true, /*bPara=*/true); +} + +uno::Any DomainMapper_Impl::GetPropertyFromCharStyleSheet(PropertyIds eId, const PropertyMapPtr& rContext) +{ + if ( m_bInStyleSheetImport || eId == PROP_CHAR_STYLE_NAME || !isCharacterProperty(eId) ) + return uno::Any(); + + StyleSheetEntryPtr pEntry; + OUString sCharStyleName; + if ( GetAnyProperty(PROP_CHAR_STYLE_NAME, rContext) >>= sCharStyleName ) + pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(sCharStyleName); + return GetPropertyFromStyleSheet(eId, pEntry, /*bDocDefaults=*/false, /*bPara=*/false); +} + +uno::Any DomainMapper_Impl::GetAnyProperty(PropertyIds eId, const PropertyMapPtr& rContext) +{ + // first look in directly applied attributes + if ( rContext ) + { + std::optional aProperty = rContext->getProperty(eId); + if ( aProperty ) + return aProperty->second; + } + + // then look whether it was inherited from a directly applied character style + if ( eId != PROP_CHAR_STYLE_NAME && isCharacterProperty(eId) ) + { + uno::Any aRet = GetPropertyFromCharStyleSheet(eId, rContext); + if ( aRet.hasValue() ) + return aRet; + } + + // then look in current paragraph style, and docDefaults + return GetPropertyFromParaStyleSheet(eId); +} + +OUString DomainMapper_Impl::GetListStyleName(sal_Int32 nListId) +{ + auto const pList(GetListTable()->GetList( nListId )); + return pList ? pList->GetStyleName() : OUString(); +} + +ListsManager::Pointer const & DomainMapper_Impl::GetListTable() +{ + if(!m_pListTable) + m_pListTable = + new ListsManager( m_rDMapper, m_xTextFactory ); + return m_pListTable; +} + + +void DomainMapper_Impl::deferBreak( BreakType deferredBreakType) +{ + switch (deferredBreakType) + { + case COLUMN_BREAK: + m_bIsColumnBreakDeferred = true; + break; + case PAGE_BREAK: + // See SwWW8ImplReader::HandlePageBreakChar(), page break should be + // ignored inside tables. + if (m_nTableDepth > 0) + return; + + m_bIsPageBreakDeferred = true; + break; + default: + return; + } +} + +bool DomainMapper_Impl::isBreakDeferred( BreakType deferredBreakType ) +{ + switch (deferredBreakType) + { + case COLUMN_BREAK: + return m_bIsColumnBreakDeferred; + case PAGE_BREAK: + return m_bIsPageBreakDeferred; + default: + return false; + } +} + +void DomainMapper_Impl::clearDeferredBreak(BreakType deferredBreakType) +{ + switch (deferredBreakType) + { + case COLUMN_BREAK: + m_bIsColumnBreakDeferred = false; + break; + case PAGE_BREAK: + m_bIsPageBreakDeferred = false; + break; + default: + break; + } +} + +void DomainMapper_Impl::clearDeferredBreaks() +{ + m_bIsColumnBreakDeferred = false; + m_bIsPageBreakDeferred = false; +} + +void DomainMapper_Impl::setSdtEndDeferred(bool bSdtEndDeferred) +{ + m_bSdtEndDeferred = bSdtEndDeferred; +} + +bool DomainMapper_Impl::isSdtEndDeferred() const +{ + return m_bSdtEndDeferred; +} + +void DomainMapper_Impl::setParaSdtEndDeferred(bool bParaSdtEndDeferred) +{ + m_bParaSdtEndDeferred = bParaSdtEndDeferred; +} + +bool DomainMapper_Impl::isParaSdtEndDeferred() const +{ + return m_bParaSdtEndDeferred; +} + +static void lcl_MoveBorderPropertiesToFrame(std::vector& rFrameProperties, + uno::Reference const& xStartTextRange, + uno::Reference const& xEndTextRange ) +{ + try + { + if (!xStartTextRange.is()) //rhbz#1077780 + return; + uno::Reference xRangeCursor = xStartTextRange->getText()->createTextCursorByRange( xStartTextRange ); + xRangeCursor->gotoRange( xEndTextRange, true ); + + uno::Reference xTextRangeProperties(xRangeCursor, uno::UNO_QUERY); + if(!xTextRangeProperties.is()) + return ; + + static PropertyIds const aBorderProperties[] = + { + PROP_LEFT_BORDER, + PROP_RIGHT_BORDER, + PROP_TOP_BORDER, + PROP_BOTTOM_BORDER, + PROP_LEFT_BORDER_DISTANCE, + PROP_RIGHT_BORDER_DISTANCE, + PROP_TOP_BORDER_DISTANCE, + PROP_BOTTOM_BORDER_DISTANCE + }; + + for( size_t nProperty = 0; nProperty < SAL_N_ELEMENTS( aBorderProperties ); ++nProperty) + { + OUString sPropertyName = getPropertyName(aBorderProperties[nProperty]); + beans::PropertyValue aValue; + aValue.Name = sPropertyName; + aValue.Value = xTextRangeProperties->getPropertyValue(sPropertyName); + rFrameProperties.push_back(aValue); + if( nProperty < 4 ) + xTextRangeProperties->setPropertyValue( sPropertyName, uno::makeAny(table::BorderLine2())); + } + } + catch( const uno::Exception& ) + { + } +} + + +static void lcl_AddRangeAndStyle( + ParagraphPropertiesPtr const & pToBeSavedProperties, + uno::Reference< text::XTextAppend > const& xTextAppend, + const PropertyMapPtr& pPropertyMap, + TextAppendContext const & rAppendContext) +{ + uno::Reference xParaCursor( + xTextAppend->createTextCursorByRange( rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition : xTextAppend->getEnd()), uno::UNO_QUERY_THROW ); + pToBeSavedProperties->SetEndingRange(xParaCursor->getStart()); + xParaCursor->gotoStartOfParagraph( false ); + + pToBeSavedProperties->SetStartingRange(xParaCursor->getStart()); + if(pPropertyMap) + { + std::optional aParaStyle = pPropertyMap->getProperty(PROP_PARA_STYLE_NAME); + if( aParaStyle ) + { + OUString sName; + aParaStyle->second >>= sName; + pToBeSavedProperties->SetParaStyleName(sName); + } + } +} + + +//define some default frame width - 0cm ATM: this allow the frame to be wrapped around the text +static constexpr sal_Int32 DEFAULT_FRAME_MIN_WIDTH = 0; +static constexpr sal_Int32 DEFAULT_FRAME_MIN_HEIGHT = 0; +static constexpr sal_Int32 DEFAULT_VALUE = 0; + +void DomainMapper_Impl::CheckUnregisteredFrameConversion( ) +{ + if (m_aTextAppendStack.empty()) + return; + TextAppendContext& rAppendContext = m_aTextAppendStack.top(); + // n#779642: ignore fly frame inside table as it could lead to messy situations + if (!rAppendContext.pLastParagraphProperties) + return; + if (!rAppendContext.pLastParagraphProperties->IsFrameMode()) + return; + if (!hasTableManager()) + return; + if (getTableManager().isInTable()) + return; + try + { + StyleSheetEntryPtr pParaStyle = + GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName()); + + std::vector aFrameProperties; + + if ( pParaStyle ) + { + const ParagraphProperties* pStyleProperties = dynamic_cast( pParaStyle->pProperties.get() ); + if (!pStyleProperties) + return; + sal_Int32 nWidth = + rAppendContext.pLastParagraphProperties->Getw() > 0 ? + rAppendContext.pLastParagraphProperties->Getw() : + pStyleProperties->Getw(); + bool bAutoWidth = nWidth < 1; + if( bAutoWidth ) + nWidth = DEFAULT_FRAME_MIN_WIDTH; + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_WIDTH), nWidth)); + + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HEIGHT), + rAppendContext.pLastParagraphProperties->Geth() > 0 ? + rAppendContext.pLastParagraphProperties->Geth() : + pStyleProperties->Geth() > 0 ? pStyleProperties->Geth() : DEFAULT_FRAME_MIN_HEIGHT)); + + sal_Int16 nhRule = sal_Int16( + rAppendContext.pLastParagraphProperties->GethRule() >= 0 ? + rAppendContext.pLastParagraphProperties->GethRule() : + pStyleProperties->GethRule()); + if ( nhRule < 0 ) + { + if ( rAppendContext.pLastParagraphProperties->Geth() >= 0 || + pStyleProperties->GethRule() >= 0 ) + { + // [MS-OE376] Word uses a default value of "atLeast" for + // this attribute when the value of the h attribute is not 0. + nhRule = text::SizeType::MIN; + } + else + { + nhRule = text::SizeType::VARIABLE; + } + } + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_SIZE_TYPE), nhRule)); + + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_WIDTH_TYPE), bAutoWidth ? text::SizeType::MIN : text::SizeType::FIX)); + + sal_Int16 nHoriOrient = sal_Int16( + rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ? + rAppendContext.pLastParagraphProperties->GetxAlign() : + pStyleProperties->GetxAlign() >= 0 ? pStyleProperties->GetxAlign() : text::HoriOrientation::NONE ); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HORI_ORIENT), nHoriOrient)); + + //set a non negative default value + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HORI_ORIENT_POSITION), + rAppendContext.pLastParagraphProperties->IsxValid() ? + rAppendContext.pLastParagraphProperties->Getx() : + pStyleProperties->IsxValid() ? pStyleProperties->Getx() : DEFAULT_VALUE)); + + //Default the anchor in case FramePr_hAnchor is missing ECMA 17.3.1.11 + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HORI_ORIENT_RELATION), sal_Int16( + rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ? + rAppendContext.pLastParagraphProperties->GethAnchor() : + pStyleProperties->GethAnchor() >=0 ? pStyleProperties->GethAnchor() : text::RelOrientation::FRAME ))); + + sal_Int16 nVertOrient = sal_Int16( + rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ? + rAppendContext.pLastParagraphProperties->GetyAlign() : + pStyleProperties->GetyAlign() >= 0 ? pStyleProperties->GetyAlign() : text::VertOrientation::NONE ); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT), nVertOrient)); + + //set a non negative default value + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT_POSITION), + rAppendContext.pLastParagraphProperties->IsyValid() ? + rAppendContext.pLastParagraphProperties->Gety() : + pStyleProperties->IsyValid() ? pStyleProperties->Gety() : DEFAULT_VALUE)); + + //Default the anchor in case FramePr_vAnchor is missing ECMA 17.3.1.11 + if (rAppendContext.pLastParagraphProperties->GetWrap() == text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE && + pStyleProperties->GetWrap() == text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE) + { + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT_RELATION), sal_Int16( + rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ? + rAppendContext.pLastParagraphProperties->GetvAnchor() : + pStyleProperties->GetvAnchor() >= 0 ? pStyleProperties->GetvAnchor() : text::RelOrientation::FRAME))); + } + else + { + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT_RELATION), sal_Int16( + rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ? + rAppendContext.pLastParagraphProperties->GetvAnchor() : + pStyleProperties->GetvAnchor() >= 0 ? pStyleProperties->GetvAnchor() : text::RelOrientation::PAGE_PRINT_AREA))); + } + + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_SURROUND), + rAppendContext.pLastParagraphProperties->GetWrap() != text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE + ? rAppendContext.pLastParagraphProperties->GetWrap() + : pStyleProperties->GetWrap() != text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE + ? pStyleProperties->GetWrap() + : text::WrapTextMode_NONE )); + + /** FDO#73546 : distL & distR should be unsigned integers + Swapped the array elements 11,12 & 13,14 since 11 & 12 are + LEFT & RIGHT margins and 13,14 are TOP and BOTTOM margins respectively. + */ + sal_Int32 nRightDist; + sal_Int32 nLeftDist = nRightDist = + rAppendContext.pLastParagraphProperties->GethSpace() >= 0 ? + rAppendContext.pLastParagraphProperties->GethSpace() : + pStyleProperties->GethSpace() >= 0 ? pStyleProperties->GethSpace() : 0; + + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_LEFT_MARGIN), nHoriOrient == text::HoriOrientation::LEFT ? 0 : nLeftDist)); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_RIGHT_MARGIN), nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nRightDist)); + + sal_Int32 nBottomDist; + sal_Int32 nTopDist = nBottomDist = + rAppendContext.pLastParagraphProperties->GetvSpace() >= 0 ? + rAppendContext.pLastParagraphProperties->GetvSpace() : + pStyleProperties->GetvSpace() >= 0 ? pStyleProperties->GetvSpace() : 0; + + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_TOP_MARGIN), nVertOrient == text::VertOrientation::TOP ? 0 : nTopDist)); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_BOTTOM_MARGIN), nVertOrient == text::VertOrientation::BOTTOM ? 0 : nBottomDist)); + // If there is no fill, the Word default is 100% transparency. + // Otherwise CellColorHandler has priority, and this setting + // will be ignored. + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_BACK_COLOR_TRANSPARENCY), sal_Int32(100))); + + uno::Sequence aGrabBag( comphelper::InitPropertySequence({ + { "ParaFrameProperties", uno::Any(rAppendContext.pLastParagraphProperties->IsFrameMode()) } + })); + aFrameProperties.push_back(comphelper::makePropertyValue("FrameInteropGrabBag", aGrabBag)); + + lcl_MoveBorderPropertiesToFrame(aFrameProperties, + rAppendContext.pLastParagraphProperties->GetStartingRange(), + rAppendContext.pLastParagraphProperties->GetEndingRange()); + } + else + { + sal_Int32 nWidth = rAppendContext.pLastParagraphProperties->Getw(); + bool bAutoWidth = nWidth < 1; + if( bAutoWidth ) + nWidth = DEFAULT_FRAME_MIN_WIDTH; + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_WIDTH), nWidth)); + + sal_Int16 nhRule = sal_Int16(rAppendContext.pLastParagraphProperties->GethRule()); + if ( nhRule < 0 ) + { + if ( rAppendContext.pLastParagraphProperties->Geth() >= 0 ) + { + // [MS-OE376] Word uses a default value of atLeast for + // this attribute when the value of the h attribute is not 0. + nhRule = text::SizeType::MIN; + } + else + { + nhRule = text::SizeType::VARIABLE; + } + } + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_SIZE_TYPE), nhRule)); + + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_WIDTH_TYPE), bAutoWidth ? text::SizeType::MIN : text::SizeType::FIX)); + + sal_Int16 nHoriOrient = sal_Int16( + rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ? + rAppendContext.pLastParagraphProperties->GetxAlign() : + text::HoriOrientation::NONE ); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HORI_ORIENT), nHoriOrient)); + + sal_Int16 nVertOrient = sal_Int16( + rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ? + rAppendContext.pLastParagraphProperties->GetyAlign() : + text::VertOrientation::NONE ); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT), nVertOrient)); + + sal_Int32 nVertDist = rAppendContext.pLastParagraphProperties->GethSpace(); + if( nVertDist < 0 ) + nVertDist = 0; + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_LEFT_MARGIN), nVertOrient == text::VertOrientation::TOP ? 0 : nVertDist)); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_RIGHT_MARGIN), nVertOrient == text::VertOrientation::BOTTOM ? 0 : nVertDist)); + + sal_Int32 nHoriDist = rAppendContext.pLastParagraphProperties->GetvSpace(); + if( nHoriDist < 0 ) + nHoriDist = 0; + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_TOP_MARGIN), nHoriOrient == text::HoriOrientation::LEFT ? 0 : nHoriDist)); + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_BOTTOM_MARGIN), nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nHoriDist)); + + if( rAppendContext.pLastParagraphProperties->Geth() > 0 ) + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HEIGHT), rAppendContext.pLastParagraphProperties->Geth())); + + if( rAppendContext.pLastParagraphProperties->IsxValid() ) + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HORI_ORIENT_POSITION), rAppendContext.pLastParagraphProperties->Getx())); + + if( rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ) + aFrameProperties.push_back(comphelper::makePropertyValue("HoriOrientRelation", sal_Int16(rAppendContext.pLastParagraphProperties->GethAnchor()))); + + if( rAppendContext.pLastParagraphProperties->IsyValid() ) + aFrameProperties.push_back(comphelper::makePropertyValue(getPropertyName(PROP_VERT_ORIENT_POSITION), rAppendContext.pLastParagraphProperties->Gety())); + + if( rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ) + aFrameProperties.push_back(comphelper::makePropertyValue("VertOrientRelation", sal_Int16(rAppendContext.pLastParagraphProperties->GetvAnchor()))); + + if( rAppendContext.pLastParagraphProperties->GetWrap() >= text::WrapTextMode_NONE ) + aFrameProperties.push_back(comphelper::makePropertyValue("Surround", rAppendContext.pLastParagraphProperties->GetWrap())); + + lcl_MoveBorderPropertiesToFrame(aFrameProperties, + rAppendContext.pLastParagraphProperties->GetStartingRange(), + rAppendContext.pLastParagraphProperties->GetEndingRange()); + } + + //frame conversion has to be executed after table conversion + RegisterFrameConversion( + rAppendContext.pLastParagraphProperties->GetStartingRange(), + rAppendContext.pLastParagraphProperties->GetEndingRange(), + aFrameProperties ); + } + catch( const uno::Exception& ) + { + } +} + +/// Check if the style or its parent has a list id, recursively. +static sal_Int32 lcl_getListId(const StyleSheetEntryPtr& rEntry, const StyleSheetTablePtr& rStyleTable, bool & rNumberingFromBaseStyle) +{ + const StyleSheetPropertyMap* pEntryProperties = dynamic_cast(rEntry->pProperties.get()); + if (!pEntryProperties) + return -1; + + sal_Int32 nListId = pEntryProperties->GetListId(); + // The style itself has a list id. + if (nListId >= 0) + return nListId; + + // The style has no parent. + if (rEntry->sBaseStyleIdentifier.isEmpty()) + return -1; + + const StyleSheetEntryPtr pParent = rStyleTable->FindStyleSheetByISTD(rEntry->sBaseStyleIdentifier); + // No such parent style or loop in the style hierarchy. + if (!pParent || pParent == rEntry) + return -1; + + rNumberingFromBaseStyle = true; + + return lcl_getListId(pParent, rStyleTable, rNumberingFromBaseStyle); +} + +void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, const bool bRemove ) +{ + if (m_bDiscardHeaderFooter) + return; + + if (!m_aFieldStack.empty()) + { + FieldContextPtr pFieldContext = m_aFieldStack.back(); + if (pFieldContext && !pFieldContext->IsCommandCompleted()) + { + std::vector aCommandParts = pFieldContext->GetCommandParts(); + if (!aCommandParts.empty() && aCommandParts[0] == "IF") + { + // Conditional text field conditions don't support linebreaks in Writer. + return; + } + } + + if (pFieldContext && pFieldContext->IsCommandCompleted()) + { + if (pFieldContext->GetFieldId() == FIELD_IF) + { + // Conditional text fields can't contain newlines, finish the paragraph later. + FieldParagraph aFinish{pPropertyMap, bRemove}; + pFieldContext->GetParagraphsToFinish().push_back(aFinish); + return; + } + } + } + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("finishParagraph"); +#endif + + m_nLastTableCellParagraphDepth = m_nTableCellDepth; + ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() ); + if (m_aTextAppendStack.empty()) + return; + TextAppendContext& rAppendContext = m_aTextAppendStack.top(); + uno::Reference< text::XTextAppend > xTextAppend(rAppendContext.xTextAppend); +#ifdef DBG_UTIL + TagLogger::getInstance().attribute("isTextAppend", sal_uInt32(xTextAppend.is())); +#endif + + const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() ); + OSL_ENSURE( pEntry.get(), "no style sheet found" ); + const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast(pEntry ? pEntry->pProperties.get() : nullptr); + bool isNumberingViaStyle(false); + bool isNumberingViaRule = pParaContext && pParaContext->GetListId() > -1; + sal_Int32 nListId = -1; + if ( !bRemove && pStyleSheetProperties && pParaContext ) + { + //apply numbering level/style to paragraph if it was set at the style, but only if the paragraph itself + //does not specify the numbering + const sal_Int16 nListLevel = pStyleSheetProperties->GetListLevel(); + if ( !isNumberingViaRule && nListLevel >= 0 ) + pParaContext->Insert( PROP_NUMBERING_LEVEL, uno::makeAny(nListLevel), false ); + + bool bNumberingFromBaseStyle = false; + nListId = pEntry ? lcl_getListId(pEntry, GetStyleSheetTable(), bNumberingFromBaseStyle) : -1; + auto const pList(GetListTable()->GetList(nListId)); + if (pList && nListId >= 0 && !pParaContext->isSet(PROP_NUMBERING_STYLE_NAME)) + { + if ( !isNumberingViaRule ) + { + isNumberingViaStyle = true; + // Since LO7.0/tdf#131321 fixed the loss of numbering in styles, this OUGHT to be obsolete, + // but now other new/critical LO7.0 code expects it, and perhaps some corner cases still need it as well. + // So we skip it only for default outline styles, which are recognized by NumberingManager. + if (!GetCurrentParaStyleName().startsWith("Heading ") || nListLevel >= pList->GetDefaultParentLevels()) + pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny(pList->GetStyleName()), true ); + } + else if ( !pList->isOutlineNumbering(nListLevel) ) + { + // After ignoring anything related to the special Outline levels, + // we have direct numbering, as well as paragraph-style numbering. + // Apply the style if it uses the same list as the direct numbering, + // otherwise the directly-applied-to-paragraph status will be lost, + // and the priority of the numbering-style-indents will be lowered. tdf#133000 + if ( nListId == pParaContext->GetListId() ) + pParaContext->Insert( PROP_NUMBERING_STYLE_NAME, uno::makeAny(pList->GetStyleName()), true ); + } + } + + if ( isNumberingViaStyle ) + { + // When numbering is defined by the paragraph style, then the para-style indents have priority. + // But since import has just copied para-style's PROP_NUMBERING_STYLE_NAME directly onto the paragraph, + // the numbering indents now have the priority. + // So now import must also copy the para-style indents directly onto the paragraph to compensate. + std::optional oProperty; + const StyleSheetEntryPtr pParent = (!pEntry->sBaseStyleIdentifier.isEmpty()) ? GetStyleSheetTable()->FindStyleSheetByISTD(pEntry->sBaseStyleIdentifier) : nullptr; + const StyleSheetPropertyMap* pParentProperties = dynamic_cast(pParent ? pParent->pProperties.get() : nullptr); + if (!pEntry->sBaseStyleIdentifier.isEmpty()) + { + oProperty = pStyleSheetProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT); + if ( oProperty + // If the numbering comes from a base style, indent of the base style has also priority. + || (bNumberingFromBaseStyle && pParentProperties && (oProperty = pParentProperties->getProperty(PROP_PARA_FIRST_LINE_INDENT))) ) + pParaContext->Insert(PROP_PARA_FIRST_LINE_INDENT, oProperty->second, /*bOverwrite=*/false); + } + oProperty = pStyleSheetProperties->getProperty(PROP_PARA_LEFT_MARGIN); + if ( oProperty + || (bNumberingFromBaseStyle && pParentProperties && (oProperty = pParentProperties->getProperty(PROP_PARA_LEFT_MARGIN))) ) + pParaContext->Insert(PROP_PARA_LEFT_MARGIN, oProperty->second, /*bOverwrite=*/false); + + // We're inheriting properties from a numbering style. Make sure a possible right margin is inherited from the base style. + sal_Int32 nParaRightMargin; + if ( pParentProperties && (oProperty = pParentProperties->getProperty(PROP_PARA_RIGHT_MARGIN)) && (nParaRightMargin = oProperty->second.get()) != 0 ) + { + // If we're setting the right margin, we should set the first / left margin as well from the numbering style. + const sal_Int32 nFirstLineIndent = getNumberingProperty(nListId, nListLevel, "FirstLineIndent"); + const sal_Int32 nParaLeftMargin = getNumberingProperty(nListId, nListLevel, "IndentAt"); + if (nFirstLineIndent != 0) + pParaContext->Insert(PROP_PARA_FIRST_LINE_INDENT, uno::makeAny(nFirstLineIndent), /*bOverwrite=*/false); + if (nParaLeftMargin != 0) + pParaContext->Insert(PROP_PARA_LEFT_MARGIN, uno::makeAny(nParaLeftMargin), /*bOverwrite=*/false); + + pParaContext->Insert(PROP_PARA_RIGHT_MARGIN, uno::makeAny(nParaRightMargin), /*bOverwrite=*/false); + } + } + } + + // apply AutoSpacing: it has priority over all other margin settings + // (note that numbering with autoSpacing is handled separately later on) + const bool bAllowAdjustments = !GetSettingsTable()->GetDoNotUseHTMLParagraphAutoSpacing(); + sal_Int32 nBeforeAutospacing = -1; + bool bIsAutoSet = pParaContext && pParaContext->isSet(PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING); + // apply INHERITED autospacing only if top margin is not set + if ( bIsAutoSet || (pParaContext && !pParaContext->isSet(PROP_PARA_TOP_MARGIN)) ) + GetAnyProperty(PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING, pPropertyMap) >>= nBeforeAutospacing; + if ( nBeforeAutospacing > -1 && pParaContext ) + { + if ( bAllowAdjustments ) + { + if ( GetIsFirstParagraphInShape() || + (GetIsFirstParagraphInSection() && GetSectionContext() && GetSectionContext()->IsFirstSection()) || + (m_bFirstParagraphInCell && m_nTableDepth > 0 && m_nTableDepth == m_nTableCellDepth) ) + { + nBeforeAutospacing = 0; + // export requires grabbag to match top_margin, so keep them in sync + if ( bIsAutoSet ) + pParaContext->Insert( PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING, uno::makeAny( sal_Int32(0) ),true, PARA_GRAB_BAG ); + } + } + pParaContext->Insert(PROP_PARA_TOP_MARGIN, uno::makeAny(nBeforeAutospacing)); + } + + sal_Int32 nAfterAutospacing = -1; + bIsAutoSet = pParaContext && pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING); + bool bApplyAutospacing = bIsAutoSet || (pParaContext && !pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN)); + if ( bApplyAutospacing ) + GetAnyProperty(PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING, pPropertyMap) >>= nAfterAutospacing; + if ( nAfterAutospacing > -1 && pParaContext ) + { + pParaContext->Insert(PROP_PARA_BOTTOM_MARGIN, uno::makeAny(nAfterAutospacing)); + bApplyAutospacing = bAllowAdjustments; + } + else + bApplyAutospacing = false; + + // tell TableManager to reset the bottom margin if it determines that this is the cell's last paragraph. + if ( hasTableManager() && getTableManager().isInCell() ) + getTableManager().setCellLastParaAfterAutospacing( bApplyAutospacing ); + + + if (xTextAppend.is() && pParaContext && hasTableManager() && !getTableManager().isIgnore()) + { + try + { + /*the following combinations of previous and current frame settings can occur: + (1) - no old frame and no current frame -> no special action + (2) - no old frame and current DropCap -> save DropCap for later use, don't call finishParagraph + remove character properties of the DropCap? + (3) - no old frame and current Frame -> save Frame for later use + (4) - old DropCap and no current frame -> add DropCap to the properties of the finished paragraph, delete previous setting + (5) - old DropCap and current frame -> add DropCap to the properties of the finished paragraph, save current frame settings + (6) - old Frame and new DropCap -> add old Frame, save DropCap for later use + (7) - old Frame and new same Frame -> continue + (8) - old Frame and new different Frame -> add old Frame, save new Frame for later use + (9) - old Frame and no current frame -> add old Frame, delete previous settings + + old _and_ new DropCap must not occur + */ + + bool bIsDropCap = + pParaContext->IsFrameMode() && + sal::static_int_cast(pParaContext->GetDropCap()) != NS_ooxml::LN_Value_doc_ST_DropCap_none; + + style::DropCapFormat aDrop; + ParagraphPropertiesPtr pToBeSavedProperties; + bool bKeepLastParagraphProperties = false; + if( bIsDropCap ) + { + uno::Reference xParaCursor( + xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW); + //select paragraph + xParaCursor->gotoStartOfParagraph( true ); + uno::Reference< beans::XPropertyState > xParaProperties( xParaCursor, uno::UNO_QUERY_THROW ); + xParaProperties->setPropertyToDefault(getPropertyName(PROP_CHAR_ESCAPEMENT)); + xParaProperties->setPropertyToDefault(getPropertyName(PROP_CHAR_HEIGHT)); + //handles (2) and part of (6) + pToBeSavedProperties = new ParagraphProperties(*pParaContext); + sal_Int32 nCount = xParaCursor->getString().getLength(); + pToBeSavedProperties->SetDropCapLength(nCount > 0 && nCount < 255 ? static_cast(nCount) : 1); + } + if( rAppendContext.pLastParagraphProperties ) + { + if( sal::static_int_cast(rAppendContext.pLastParagraphProperties->GetDropCap()) != NS_ooxml::LN_Value_doc_ST_DropCap_none) + { + //handles (4) and part of (5) + //create a DropCap property, add it to the property sequence of finishParagraph + sal_Int32 nLines = rAppendContext.pLastParagraphProperties->GetLines(); + aDrop.Lines = nLines > 0 && nLines < SAL_MAX_INT8 ? static_cast(nLines) : 2; + aDrop.Count = rAppendContext.pLastParagraphProperties->GetDropCapLength(); + sal_Int32 nHSpace = rAppendContext.pLastParagraphProperties->GethSpace(); + aDrop.Distance = nHSpace > 0 && nHSpace < SAL_MAX_INT16 ? static_cast(nHSpace) : 0; + //completes (5) + if( pParaContext->IsFrameMode() ) + pToBeSavedProperties = new ParagraphProperties(*pParaContext); + } + else if(*rAppendContext.pLastParagraphProperties == *pParaContext ) + { + //handles (7) + rAppendContext.pLastParagraphProperties->SetEndingRange(rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition : xTextAppend->getEnd()); + bKeepLastParagraphProperties = true; + } + else + { + //handles (8)(9) and completes (6) + CheckUnregisteredFrameConversion( ); + + // If different frame properties are set on this paragraph, keep them. + if ( !bIsDropCap && pParaContext->IsFrameMode() ) + { + pToBeSavedProperties = new ParagraphProperties(*pParaContext); + lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap, rAppendContext); + } + } + } + else + { + // (1) doesn't need handling + + if( !bIsDropCap && pParaContext->IsFrameMode() ) + { + pToBeSavedProperties = new ParagraphProperties(*pParaContext); + lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap, rAppendContext); + } + } + std::vector aProperties; + if (pPropertyMap) + { + aProperties = comphelper::sequenceToContainer< std::vector >(pPropertyMap->GetPropertyValues()); + } + // TODO: this *should* work for RTF but there are test failures, maybe rtftok doesn't distinguish between formatting for the paragraph marker and for the paragraph as a whole; needs investigation + if (pPropertyMap && IsOOXMLImport()) + { + // tdf#64222 filter out the "paragraph marker" formatting and + // set it as a separate paragraph property, not a empty hint at + // end of paragraph + std::vector charProperties; + for (auto it = aProperties.begin(); it != aProperties.end(); ) + { + // this condition isn't ideal but as it happens all + // RES_CHRATR_* have names that start with "Char" + if (it->Name.startsWith("Char")) + { + charProperties.emplace_back(it->Name, it->Value); + // as testN793262 demonstrates, font size in rPr must + // affect the paragraph size => also insert empty hint! +// it = aProperties.erase(it); + } + ++it; + } + if (!charProperties.empty()) + { + aProperties.push_back(beans::PropertyValue("ListAutoFormat", + 0, uno::makeAny(comphelper::containerToSequence(charProperties)), beans::PropertyState_DIRECT_VALUE)); + } + } + if( !bIsDropCap ) + { + if( aDrop.Lines > 1 ) + { + beans::PropertyValue aValue; + aValue.Name = getPropertyName(PROP_DROP_CAP_FORMAT); + aValue.Value <<= aDrop; + aProperties.push_back(aValue); + } + uno::Reference< text::XTextRange > xTextRange; + if (rAppendContext.xInsertPosition.is()) + { + xTextRange = xTextAppend->finishParagraphInsert( comphelper::containerToSequence(aProperties), rAppendContext.xInsertPosition ); + rAppendContext.xCursor->gotoNextParagraph(false); + if (rAppendContext.pLastParagraphProperties) + rAppendContext.pLastParagraphProperties->SetEndingRange(xTextRange->getEnd()); + } + else + { + uno::Reference xCursor; + if (m_bParaHadField && !m_bIsInComments && !xTOCMarkerCursor.is()) + { + // Workaround to make sure char props of the field are not lost. + // Not relevant for editeng-based comments. + // Not relevant for fields inside a TOC field. + OUString const sMarker("X"); + xCursor = xTextAppend->getText()->createTextCursor(); + if (xCursor.is()) + xCursor->gotoEnd(false); + PropertyMapPtr pEmpty(new PropertyMap()); + appendTextPortion(sMarker, pEmpty); + } + + // Check if top / bottom margin has to be updated, now that we know the numbering status of both the previous and + // the current text node. + auto itNumberingRules = std::find_if(aProperties.begin(), aProperties.end(), [](const beans::PropertyValue& rValue) + { + return rValue.Name == "NumberingRules"; + }); + + assert( isNumberingViaRule == (itNumberingRules != aProperties.end()) ); + isNumberingViaRule = (itNumberingRules != aProperties.end()); + if (m_xPreviousParagraph.is() && (isNumberingViaRule || isNumberingViaStyle)) + { + // This textnode has numbering. Look up the numbering style name of the current and previous paragraph. + OUString aCurrentNumberingName; + OUString aPreviousNumberingName; + if (isNumberingViaRule) + { + uno::Reference xCurrentNumberingRules(itNumberingRules->Value, uno::UNO_QUERY); + if (xCurrentNumberingRules.is()) + aCurrentNumberingName = xCurrentNumberingRules->getName(); + if (m_xPreviousParagraph.is()) + { + uno::Reference xPreviousNumberingRules(m_xPreviousParagraph->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + if (xPreviousNumberingRules.is()) + aPreviousNumberingName = xPreviousNumberingRules->getName(); + } + } + else if ( m_xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("NumberingStyleName") && + // don't update before tables + (m_nTableDepth == 0 || !m_bFirstParagraphInCell)) + { + aCurrentNumberingName = GetListStyleName(nListId); + m_xPreviousParagraph->getPropertyValue("NumberingStyleName") >>= aPreviousNumberingName; + } + + if (!aPreviousNumberingName.isEmpty() && aCurrentNumberingName == aPreviousNumberingName) + { + uno::Sequence aPrevPropertiesSeq; + m_xPreviousParagraph->getPropertyValue("ParaInteropGrabBag") >>= aPrevPropertiesSeq; + auto aPrevProperties = comphelper::sequenceToContainer< std::vector >(aPrevPropertiesSeq); + bool bParaAutoBefore = m_bParaAutoBefore || std::any_of(aPrevProperties.begin(), aPrevProperties.end(), [](const beans::PropertyValue& rValue) + { + return rValue.Name == "ParaTopMarginBeforeAutoSpacing"; + }); + // if style based spacing was set to auto in the previous paragraph, style of the actual paragraph must be the same + if (bParaAutoBefore && !m_bParaAutoBefore && m_xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("ParaStyleName")) + { + auto itParaStyle = std::find_if(aProperties.begin(), aProperties.end(), [](const beans::PropertyValue& rValue) + { + return rValue.Name == "ParaStyleName"; + }); + bParaAutoBefore = itParaStyle != aProperties.end() && + m_xPreviousParagraph->getPropertyValue("ParaStyleName") == itParaStyle->Value; + } + // There was a previous textnode and it had the same numbering. + if (bParaAutoBefore) + { + // This before spacing is set to auto, set before space to 0. + auto itParaTopMargin = std::find_if(aProperties.begin(), aProperties.end(), [](const beans::PropertyValue& rValue) + { + return rValue.Name == "ParaTopMargin"; + }); + if (itParaTopMargin != aProperties.end()) + itParaTopMargin->Value <<= static_cast(0); + else + aProperties.push_back(comphelper::makePropertyValue("ParaTopMargin", static_cast(0))); + } + + bool bPrevParaAutoAfter = std::any_of(aPrevProperties.begin(), aPrevProperties.end(), [](const beans::PropertyValue& rValue) + { + return rValue.Name == "ParaBottomMarginAfterAutoSpacing"; + }); + if (bPrevParaAutoAfter) + { + // Previous after spacing is set to auto, set previous after space to 0. + m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", uno::makeAny(static_cast(0))); + } + } + } + + xTextRange = xTextAppend->finishParagraph( comphelper::containerToSequence(aProperties) ); + m_xPreviousParagraph.set(xTextRange, uno::UNO_QUERY); + + if (m_xPreviousParagraph.is() && // null for SvxUnoTextBase + (isNumberingViaStyle || isNumberingViaRule)) + { + assert(dynamic_cast(pPropertyMap.get())); + // Use lcl_getListId(), so we find the list ID in parent styles as well. + bool bNumberingFromBaseStyle = false; + sal_Int32 const nListId2( isNumberingViaStyle + ? lcl_getListId(pEntry, GetStyleSheetTable(), bNumberingFromBaseStyle) + : static_cast(pPropertyMap.get())->GetListId()); + if (ListDef::Pointer const& pList = m_pListTable->GetList(nListId2)) + { // styles could refer to non-existing lists... + AbstractListDef::Pointer const& pAbsList = + pList->GetAbstractDefinition(); + if (pAbsList && + // SvxUnoTextRange doesn't have ListId + m_xPreviousParagraph->getPropertySetInfo()->hasPropertyByName("ListId")) + { + OUString paraId; + m_xPreviousParagraph->getPropertyValue("ListId") >>= paraId; + if (!paraId.isEmpty()) // must be on some list? + { + OUString const listId = pAbsList->MapListId(paraId); + if (listId != paraId) + { + m_xPreviousParagraph->setPropertyValue("ListId", uno::makeAny(listId)); + } + } + } + if (pList->GetCurrentLevel()) + { + sal_Int16 nOverrideLevel = pList->GetCurrentLevel()->GetStartOverride(); + if (nOverrideLevel != -1 && m_aListOverrideApplied.find(nListId2) == m_aListOverrideApplied.end()) + { + // Apply override: we have override instruction for this level + // And this was not done for this list before: we can do this only once on first occurrence + // of list with override + // TODO: Not tested variant with different levels override in different lists. + // Probably m_aListOverrideApplied as a set of overridden listids is not sufficient + // and we need to register level overrides separately. + m_xPreviousParagraph->setPropertyValue("ParaIsNumberingRestart", uno::makeAny(true)); + m_xPreviousParagraph->setPropertyValue("NumberingStartValue", uno::makeAny(nOverrideLevel)); + m_aListOverrideApplied.insert(nListId2); + } + } + } + } + + if (!rAppendContext.m_aAnchoredObjects.empty() && !IsInHeaderFooter()) + { + // Remember what objects are anchored to this paragraph. + // That list is only used for Word compat purposes, and + // it is only relevant for body text. + AnchoredObjectsInfo aInfo; + aInfo.m_xParagraph = xTextRange; + aInfo.m_aAnchoredObjects = rAppendContext.m_aAnchoredObjects; + m_aAnchoredObjectAnchors.push_back(aInfo); + rAppendContext.m_aAnchoredObjects.clear(); + } + + // We're no longer right after a table conversion. + m_bConvertedTable = false; + + if (xCursor.is()) + { + xCursor->goLeft(1, true); + xCursor->setString(OUString()); + } + } + getTableManager( ).handle(xTextRange); + m_aSmartTagHandler.handle(xTextRange); + + if (xTextRange.is()) + { + // Get the end of paragraph character inserted + uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( ); + if (rAppendContext.xInsertPosition.is()) + xCur->gotoRange( rAppendContext.xInsertPosition, false ); + else + xCur->gotoEnd( false ); + + // tdf#77417 trim right white spaces in table cells in 2010 compatibility mode + sal_Int32 nMode = GetSettingsTable()->GetWordCompatibilityMode(); + if ( m_nTableDepth > 0 && nMode > 0 && nMode <= 14 ) + { + // skip new line + xCur->goLeft(1, false); + while ( xCur->goLeft(1, true) ) + { + OUString sChar = xCur->getString(); + if ( sChar == " " || sChar == "\t" || sChar == OUStringChar(u'\x00A0') ) + xCur->setString(""); + else + break; + } + xCur->goRight(2, false); + } + + xCur->goLeft( 1 , true ); + // Extend the redline ranges for empty paragraphs + if ( !m_bParaChanged && m_previousRedline ) + CreateRedline( xCur, m_previousRedline ); + CheckParaMarkerRedline( xCur ); + } + + css::uno::Reference xParaProps(xTextRange, uno::UNO_QUERY); + + // table style precedence and not hidden shapes anchored to hidden empty table paragraphs + if (xParaProps && (m_nTableDepth > 0 || !m_aAnchoredObjectAnchors.empty()) ) + { + // table style has got bigger precedence than docDefault style + // collect these pending paragraph properties to process in endTable() + uno::Reference xCur = xTextRange->getText( )->createTextCursor( ); + xCur->gotoEnd(false); + xCur->goLeft(1, false); + uno::Reference xCur2 = xTextRange->getText()->createTextCursorByRange(xCur); + uno::Reference xParaCursor(xCur2, uno::UNO_QUERY_THROW); + xParaCursor->gotoStartOfParagraph(false); + if (m_nTableDepth > 0) + { + TableParagraph aPending{xParaCursor, xCur, pParaContext, xParaProps}; + getTableManager().getCurrentParagraphs()->push_back(aPending); + } + + // hidden empty paragraph with a not hidden shape, set as not hidden + std::optional pHidden; + if ( !m_aAnchoredObjectAnchors.empty() && (pHidden = pParaContext->getProperty(PROP_CHAR_HIDDEN)) ) + { + bool bIsHidden = {}; // -Werror=maybe-uninitialized + pHidden->second >>= bIsHidden; + if (bIsHidden) + { + bIsHidden = false; + pHidden = GetTopContext()->getProperty(PROP_CHAR_HIDDEN); + if (pHidden) + pHidden->second >>= bIsHidden; + if (!bIsHidden) + { + uno::Reference xCur3 = xTextRange->getText()->createTextCursorByRange(xParaCursor); + xCur3->goRight(1, true); + if (xCur3->getString() == SAL_NEWLINE_STRING) + { + uno::Reference< beans::XPropertySet > xProp( xCur3, uno::UNO_QUERY ); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_HIDDEN), uno::makeAny(false)); + } + } + } + } + } + + // tdf#118521 set paragraph top or bottom margin based on the paragraph style + // if we already set the other margin with direct formatting + if (xParaProps) + { + const bool bTopSet = pParaContext->isSet(PROP_PARA_TOP_MARGIN); + const bool bBottomSet = pParaContext->isSet(PROP_PARA_BOTTOM_MARGIN); + const bool bContextSet = pParaContext->isSet(PROP_PARA_CONTEXT_MARGIN); + if ( !(bTopSet == bBottomSet && bBottomSet == bContextSet) ) + { + + if ( !bTopSet ) + { + uno::Any aMargin = GetPropertyFromParaStyleSheet(PROP_PARA_TOP_MARGIN); + if ( aMargin != uno::Any() ) + xParaProps->setPropertyValue("ParaTopMargin", aMargin); + } + if ( !bBottomSet ) + { + uno::Any aMargin = GetPropertyFromParaStyleSheet(PROP_PARA_BOTTOM_MARGIN); + if ( aMargin != uno::Any() ) + xParaProps->setPropertyValue("ParaBottomMargin", aMargin); + } + if ( !bContextSet ) + { + uno::Any aMargin = GetPropertyFromParaStyleSheet(PROP_PARA_CONTEXT_MARGIN); + if ( aMargin != uno::Any() ) + xParaProps->setPropertyValue("ParaContextMargin", aMargin); + } + } + } + + // Left, Right, and Hanging settings are also grouped. Ensure that all or none are set. + if (xParaProps) + { + const bool bLeftSet = pParaContext->isSet(PROP_PARA_LEFT_MARGIN); + const bool bRightSet = pParaContext->isSet(PROP_PARA_RIGHT_MARGIN); + const bool bFirstSet = pParaContext->isSet(PROP_PARA_FIRST_LINE_INDENT); + if ( !(bLeftSet == bRightSet && bRightSet == bFirstSet) ) + { + if ( !bLeftSet ) + { + uno::Any aMargin = GetPropertyFromParaStyleSheet(PROP_PARA_LEFT_MARGIN); + if ( aMargin != uno::Any() ) + xParaProps->setPropertyValue("ParaLeftMargin", aMargin); + else if (isNumberingViaStyle) + { + const sal_Int32 nParaLeftMargin = getNumberingProperty(nListId, pStyleSheetProperties->GetListLevel(), "IndentAt"); + if (nParaLeftMargin != 0) + xParaProps->setPropertyValue("ParaLeftMargin", uno::makeAny(nParaLeftMargin)); + } + } + if ( !bRightSet ) + { + uno::Any aMargin = GetPropertyFromParaStyleSheet(PROP_PARA_RIGHT_MARGIN); + if ( aMargin != uno::Any() ) + xParaProps->setPropertyValue("ParaRightMargin", aMargin); + } + if ( !bFirstSet ) + { + uno::Any aMargin = GetPropertyFromParaStyleSheet(PROP_PARA_FIRST_LINE_INDENT); + if ( aMargin != uno::Any() ) + xParaProps->setPropertyValue("ParaFirstLineIndent", aMargin); + else if (isNumberingViaStyle) + { + const sal_Int32 nFirstLineIndent = getNumberingProperty(nListId, pStyleSheetProperties->GetListLevel(), "FirstLineIndent"); + if (nFirstLineIndent != 0) + xParaProps->setPropertyValue("ParaFirstLineIndent", uno::makeAny(nFirstLineIndent)); + } + } + } + } + + // fix table paragraph properties + if ( xTextRange.is() && xParaProps && m_nTableDepth > 0 ) + { + uno::Sequence< beans::PropertyValue > aParaProps = pParaContext->GetPropertyValues(false); + uno::Reference xCur = xTextRange->getText()->createTextCursorByRange(xTextRange); + uno::Reference< beans::XPropertyState > xRunProperties( xCur, uno::UNO_QUERY_THROW ); + // tdf#90069 in tables, apply paragraph level character style also on + // paragraph level to support its copy during insertion of new table rows + for( const auto& rParaProp : std::as_const(aParaProps) ) + { + if ( rParaProp.Name.startsWith("Char") && rParaProp.Name != "CharStyleName" && rParaProp.Name != "CharInteropGrabBag" && + // all text portions contain the same value, so next setPropertyValue() won't overwrite part of them + xRunProperties->getPropertyState(rParaProp.Name) == css::beans::PropertyState_DIRECT_VALUE ) + { + uno::Reference xRunPropertySet(xCur, uno::UNO_QUERY); + xParaProps->setPropertyValue( rParaProp.Name, xRunPropertySet->getPropertyValue(rParaProp.Name) ); + } + } + + // tdf#128959 table paragraphs haven't got window and orphan controls + uno::Any aAny = uno::makeAny(static_cast(0)); + xParaProps->setPropertyValue("ParaOrphans", aAny); + xParaProps->setPropertyValue("ParaWidows", aAny); + } + } + if( !bKeepLastParagraphProperties ) + rAppendContext.pLastParagraphProperties = pToBeSavedProperties; + } + catch(const lang::IllegalArgumentException&) + { + OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::finishParagraph" ); + } + catch(const uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", "finishParagraph()" ); + } + + } + + bool bIgnoreFrameState = IsInHeaderFooter(); + if( (!bIgnoreFrameState && pParaContext && pParaContext->IsFrameMode()) || (bIgnoreFrameState && GetIsPreviousParagraphFramed()) ) + SetIsPreviousParagraphFramed(true); + else + SetIsPreviousParagraphFramed(false); + + m_bParaChanged = false; + m_bRemoveThisParagraph = false; + if( !IsInHeaderFooter() && !IsInShape() && (!pParaContext || !pParaContext->IsFrameMode()) ) + { // If the paragraph is in a frame, shape or header/footer, it's not a paragraph of the section itself. + SetIsFirstParagraphInSection(false); + // count first not deleted paragraph as first paragraph in section to avoid of + // its deletion later, resulting loss of the associated page break + if (!m_previousRedline) + { + SetIsFirstParagraphInSectionAfterRedline(false); + SetIsLastParagraphInSection(false); + } + } + m_previousRedline.clear(); + + if (m_bIsFirstParaInShape) + m_bIsFirstParaInShape = false; + + if (pParaContext) + { + // Reset the frame properties for the next paragraph + pParaContext->ResetFrameProperties(); + } + + SetIsOutsideAParagraph(true); + m_bParaHadField = false; + + // don't overwrite m_bFirstParagraphInCell in table separator nodes + // and in text boxes anchored to the first paragraph of table cells + if (m_nTableDepth > 0 && m_nTableDepth == m_nTableCellDepth && !IsInShape()) + m_bFirstParagraphInCell = false; + + m_bParaAutoBefore = false; + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif + +} + +void DomainMapper_Impl::appendTextPortion( const OUString& rString, const PropertyMapPtr& pPropertyMap ) +{ + if (m_bDiscardHeaderFooter) + return; + + if (m_aTextAppendStack.empty()) + return; + // Before placing call to processDeferredCharacterProperties(), TopContextType should be CONTEXT_CHARACTER + // processDeferredCharacterProperties() invokes only if character inserted + if( pPropertyMap == m_pTopContext && !deferredCharacterProperties.empty() && (GetTopContextType() == CONTEXT_CHARACTER) ) + processDeferredCharacterProperties(); + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is() && hasTableManager() && !getTableManager().isIgnore()) + { + try + { + // If we are in comments, then disable CharGrabBag, comment text doesn't support that. + uno::Sequence< beans::PropertyValue > aValues = pPropertyMap->GetPropertyValues(/*bCharGrabBag=*/!m_bIsInComments); + + if (m_bStartTOC || m_bStartIndex || m_bStartBibliography) + for( auto& rValue : aValues ) + { + if (rValue.Name == "CharHidden") + rValue.Value <<= false; + } + + uno::Reference< text::XTextRange > xTextRange; + if (m_aTextAppendStack.top().xInsertPosition.is()) + { + xTextRange = xTextAppend->insertTextPortion(rString, aValues, m_aTextAppendStack.top().xInsertPosition); + m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), true); + } + else + { + if (m_bStartTOC || m_bStartIndex || m_bStartBibliography || m_nStartGenericField != 0) + { + if (IsInHeaderFooter() && !m_bStartTOCHeaderFooter) + { + xTextRange = xTextAppend->appendTextPortion(rString, aValues); + } + else + { + m_bStartedTOC = true; + uno::Reference< text::XTextCursor > xTOCTextCursor = xTextAppend->getEnd()->getText( )->createTextCursor( ); + assert(xTOCTextCursor.is()); + xTOCTextCursor->gotoEnd(false); + if (m_nStartGenericField != 0) + { + xTOCTextCursor->goLeft(1, false); + } + xTextRange = xTextAppend->insertTextPortion(rString, aValues, xTOCTextCursor); + SAL_WARN_IF(!xTextRange.is(), "writerfilter.dmapper", "insertTextPortion failed"); + if (!xTextRange.is()) + throw uno::Exception("insertTextPortion failed", nullptr); + m_bTextInserted = true; + xTOCTextCursor->gotoRange(xTextRange->getEnd(), true); + if (m_nStartGenericField == 0) + { + m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor)); + } + } + } + else + { +#if !defined(MACOSX) // TODO: check layout differences and support all platforms, if needed + sal_Int32 nPos = 0; + OUString sFontName; + OUString sDoubleSpace(" "); + PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_CHARACTER); + // tdf#123703 workaround for longer space sequences of the old or compatible RTF documents + if (GetSettingsTable()->GetLongerSpaceSequence() && !IsOpenFieldCommand() && (nPos = rString.indexOf(sDoubleSpace)) != -1 && + // monospaced fonts have no longer space sequences, regardless of \fprq2 (not monospaced) font setting + // fix for the base monospaced font Courier + (!pContext || !pContext->isSet(PROP_CHAR_FONT_NAME) || + ((pContext->getProperty(PROP_CHAR_FONT_NAME)->second >>= sFontName) && sFontName.indexOf("Courier") == -1))) + { + // an RTF space character is longer by an extra six-em-space in an old-style RTF space sequence, + // insert them to keep RTF document layout formatted by consecutive spaces + const sal_Unicode aExtraSpace[5] = { 0x2006, 0x20, 0x2006, 0x20, 0 }; + const sal_Unicode aExtraSpace2[4] = { 0x20, 0x2006, 0x20, 0 }; + xTextRange = xTextAppend->appendTextPortion(rString.replaceAll(sDoubleSpace, aExtraSpace, nPos) + .replaceAll(sDoubleSpace, aExtraSpace2, nPos), aValues); + } + else +#endif + xTextRange = xTextAppend->appendTextPortion(rString, aValues); + } + } + + // reset moveFrom data of non-terminating runs of the paragraph + if ( m_pParaMarkerRedlineMoveFrom ) + { + m_pParaMarkerRedlineMoveFrom.clear(); + } + CheckRedline( xTextRange ); + m_bParaChanged = true; + + //getTableManager( ).handle(xTextRange); + } + catch(const lang::IllegalArgumentException&) + { + OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::appendTextPortion" ); + } + catch(const uno::Exception&) + { + OSL_FAIL( "Exception in DomainMapper_Impl::appendTextPortion" ); + } + } +} + +void DomainMapper_Impl::appendTextContent( + const uno::Reference< text::XTextContent >& xContent, + const uno::Sequence< beans::PropertyValue >& xPropertyValues + ) +{ + SAL_WARN_IF(m_aTextAppendStack.empty(), "writerfilter.dmapper", "no text append stack"); + if (m_aTextAppendStack.empty()) + return; + uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( m_aTextAppendStack.top().xTextAppend, uno::UNO_QUERY ); + OSL_ENSURE( xTextAppendAndConvert.is(), "trying to append a text content without XTextAppendAndConvert" ); + if (xTextAppendAndConvert.is() && hasTableManager() && !getTableManager().isIgnore()) + { + try + { + if (m_aTextAppendStack.top().xInsertPosition.is()) + xTextAppendAndConvert->insertTextContentWithProperties( xContent, xPropertyValues, m_aTextAppendStack.top().xInsertPosition ); + else + xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues ); + } + catch(const lang::IllegalArgumentException&) + { + } + catch(const uno::Exception&) + { + } + } +} + +void DomainMapper_Impl::appendOLE( const OUString& rStreamName, const std::shared_ptr& pOLEHandler ) +{ + try + { + uno::Reference< text::XTextContent > xOLE( m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xOLEProperties(xOLE, uno::UNO_QUERY_THROW); + + OUString aCLSID = pOLEHandler->getCLSID(m_xComponentContext); + if (aCLSID.isEmpty()) + xOLEProperties->setPropertyValue(getPropertyName( PROP_STREAM_NAME ), + uno::makeAny( rStreamName )); + else + xOLEProperties->setPropertyValue("CLSID", uno::makeAny(aCLSID)); + + OUString aDrawAspect = pOLEHandler->GetDrawAspect(); + if(!aDrawAspect.isEmpty()) + xOLEProperties->setPropertyValue("DrawAspect", uno::makeAny(aDrawAspect)); + + awt::Size aSize = pOLEHandler->getSize(); + if( !aSize.Width ) + aSize.Width = 1000; + if( !aSize.Height ) + aSize.Height = 1000; + xOLEProperties->setPropertyValue(getPropertyName( PROP_WIDTH ), + uno::makeAny(aSize.Width)); + xOLEProperties->setPropertyValue(getPropertyName( PROP_HEIGHT ), + uno::makeAny(aSize.Height)); + + OUString aVisAreaWidth = pOLEHandler->GetVisAreaWidth(); + if(!aVisAreaWidth.isEmpty()) + xOLEProperties->setPropertyValue("VisibleAreaWidth", uno::makeAny(aVisAreaWidth)); + + OUString aVisAreaHeight = pOLEHandler->GetVisAreaHeight(); + if(!aVisAreaHeight.isEmpty()) + xOLEProperties->setPropertyValue("VisibleAreaHeight", uno::makeAny(aVisAreaHeight)); + + uno::Reference< graphic::XGraphic > xGraphic = pOLEHandler->getReplacement(); + xOLEProperties->setPropertyValue(getPropertyName( PROP_GRAPHIC ), + uno::makeAny(xGraphic)); + uno::Reference xReplacementProperties(pOLEHandler->getShape(), uno::UNO_QUERY); + if (xReplacementProperties.is()) + { + OUString pProperties[] = { + "AnchorType", + "Surround", + "SurroundContour", + "HoriOrient", + "HoriOrientPosition", + "VertOrient", + "VertOrientPosition", + "VertOrientRelation", + "HoriOrientRelation" + }; + for (const OUString & s : pProperties) + xOLEProperties->setPropertyValue(s, xReplacementProperties->getPropertyValue(s)); + } + else + // mimic the treatment of graphics here... it seems anchoring as character + // gives a better ( visually ) result + xOLEProperties->setPropertyValue(getPropertyName( PROP_ANCHOR_TYPE ), uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) ); + // remove ( if valid ) associated shape ( used for graphic replacement ) + SAL_WARN_IF(m_aAnchoredStack.empty(), "writerfilter.dmapper", "no anchor stack"); + if (!m_aAnchoredStack.empty()) + m_aAnchoredStack.top( ).bToRemove = true; + RemoveLastParagraph(); + SAL_WARN_IF(m_aTextAppendStack.empty(), "writerfilter.dmapper", "no text stack"); + if (!m_aTextAppendStack.empty()) + m_aTextAppendStack.pop(); + + appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() ); + + if (!aCLSID.isEmpty()) + pOLEHandler->importStream(m_xComponentContext, GetTextDocument(), xOLE); + + } + catch( const uno::Exception& ) + { + OSL_FAIL( "Exception in creation of OLE object" ); + } + +} + +void DomainMapper_Impl::appendStarMath( const Value& val ) +{ + uno::Reference< embed::XEmbeddedObject > formula; + val.getAny() >>= formula; + if( formula.is() ) + { + try + { + uno::Reference< text::XTextContent > xStarMath( m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xStarMathProperties(xStarMath, uno::UNO_QUERY_THROW); + + xStarMathProperties->setPropertyValue(getPropertyName( PROP_EMBEDDED_OBJECT ), + val.getAny()); + // tdf#66405: set zero margins for embedded object + xStarMathProperties->setPropertyValue(getPropertyName( PROP_LEFT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_RIGHT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_TOP_MARGIN ), + uno::makeAny(sal_Int32(0))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), + uno::makeAny(sal_Int32(0))); + + uno::Reference< uno::XInterface > xInterface( formula->getComponent(), uno::UNO_QUERY ); + // set zero margins for object's component + uno::Reference< beans::XPropertySet > xComponentProperties( xInterface, uno::UNO_QUERY_THROW ); + xComponentProperties->setPropertyValue(getPropertyName( PROP_LEFT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xComponentProperties->setPropertyValue(getPropertyName( PROP_RIGHT_MARGIN ), + uno::makeAny(sal_Int32(0))); + xComponentProperties->setPropertyValue(getPropertyName( PROP_TOP_MARGIN ), + uno::makeAny(sal_Int32(0))); + xComponentProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), + uno::makeAny(sal_Int32(0))); + Size size( 1000, 1000 ); + if( oox::FormulaImportBase* formulaimport = dynamic_cast< oox::FormulaImportBase* >( xInterface.get())) + size = formulaimport->getFormulaSize(); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_WIDTH ), + uno::makeAny( sal_Int32(size.Width()))); + xStarMathProperties->setPropertyValue(getPropertyName( PROP_HEIGHT ), + uno::makeAny( sal_Int32(size.Height()))); + xStarMathProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), + uno::makeAny(text::TextContentAnchorType_AS_CHARACTER)); + // mimic the treatment of graphics here... it seems anchoring as character + // gives a better ( visually ) result + appendTextContent(xStarMath, uno::Sequence()); + } + catch( const uno::Exception& ) + { + OSL_FAIL( "Exception in creation of StarMath object" ); + } + } +} + +void DomainMapper_Impl::adjustLastPara(sal_Int8 nAlign) +{ + PropertyMapPtr pLastPara = GetTopContextOfType(dmapper::CONTEXT_PARAGRAPH); + pLastPara->Insert(PROP_PARA_ADJUST, uno::makeAny(nAlign), true); +} + +uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter( + uno::Reference< text::XTextRange > const & xBefore ) +{ + uno::Reference< beans::XPropertySet > xRet; + if (m_aTextAppendStack.empty()) + return xRet; + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if(xTextAppend.is()) + { + try + { + uno::Reference< text::XParagraphCursor > xCursor( + xTextAppend->createTextCursorByRange( xBefore ), uno::UNO_QUERY_THROW); + //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls + xCursor->gotoStartOfParagraph( false ); + if (m_aTextAppendStack.top().xInsertPosition.is()) + xCursor->gotoRange( m_aTextAppendStack.top().xInsertPosition, true ); + else + xCursor->gotoEnd( true ); + //the paragraph after this new section is already inserted + xCursor->goLeft(1, true); + css::uno::Reference xTextRange(xCursor, css::uno::UNO_QUERY_THROW); + + if (css::uno::Reference xIndexSupplier{ + GetTextDocument(), css::uno::UNO_QUERY }) + { + css::uno::Reference xCompare( + xTextAppend, css::uno::UNO_QUERY); + const auto xIndexAccess = xIndexSupplier->getDocumentIndexes(); + for (sal_Int32 i = xIndexAccess->getCount(); i > 0; --i) + { + if (css::uno::Reference xIndex{ + xIndexAccess->getByIndex(i - 1), css::uno::UNO_QUERY }) + { + const auto xIndexTextRange = xIndex->getAnchor(); + if (xCompare->compareRegionStarts(xTextRange, xIndexTextRange) == 0 + && xCompare->compareRegionEnds(xTextRange, xIndexTextRange) == 0) + { + // The boundaries coincide with an index: trying to attach a section + // to the range will insert the section inside the index. goRight will + // extend the range outside of the index, so that created section will + // be around it. Alternatively we could return index section itself + // instead : xRet.set(xIndex, uno::UNO_QUERY) - to set its properties, + // like columns/fill. + xCursor->goRight(1, true); + break; + } + } + } + } + + uno::Reference< text::XTextContent > xSection( m_xTextFactory->createInstance("com.sun.star.text.TextSection"), uno::UNO_QUERY_THROW ); + xSection->attach( xTextRange ); + xRet.set(xSection, uno::UNO_QUERY ); + } + catch(const uno::Exception&) + { + } + + } + + return xRet; +} + +void DomainMapper_Impl::appendGlossaryEntry() +{ + appendTextSectionAfter(m_xGlossaryEntryStart); +} + +void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType) +{ + m_aHeaderFooterStack.push(HeaderFooterContext(m_bTextInserted, m_nTableDepth)); + m_bTextInserted = false; + m_nTableDepth = 0; + + const PropertyIds ePropIsOn = bHeader? PROP_HEADER_IS_ON: PROP_FOOTER_IS_ON; + const PropertyIds ePropShared = bHeader? PROP_HEADER_IS_SHARED: PROP_FOOTER_IS_SHARED; + const PropertyIds ePropTextLeft = bHeader? PROP_HEADER_TEXT_LEFT: PROP_FOOTER_TEXT_LEFT; + const PropertyIds ePropText = bHeader? PROP_HEADER_TEXT: PROP_FOOTER_TEXT; + + m_bDiscardHeaderFooter = true; + m_eInHeaderFooterImport + = bHeader ? HeaderFooterImportState::header : HeaderFooterImportState::footer; + + //get the section context + PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION); + //ask for the header/footer name of the given type + SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); + if(pSectionContext) + { + // clear the "Link To Previous" flag so that the header/footer + // content is not copied from the previous section + pSectionContext->ClearHeaderFooterLinkToPrevious(bHeader, eType); + + if (!m_bIsNewDoc) + { + return; // TODO sw cannot Undo insert header/footer without crashing + } + + uno::Reference< beans::XPropertySet > xPageStyle = + pSectionContext->GetPageStyle( + *this, + eType == SectionPropertyMap::PAGE_FIRST ); + if (!xPageStyle.is()) + return; + try + { + bool bLeft = eType == SectionPropertyMap::PAGE_LEFT; + bool bFirst = eType == SectionPropertyMap::PAGE_FIRST; + if ((!bLeft && !GetSettingsTable()->GetEvenAndOddHeaders()) || (GetSettingsTable()->GetEvenAndOddHeaders())) + { + //switch on header/footer use + xPageStyle->setPropertyValue( + getPropertyName(ePropIsOn), + uno::makeAny(true)); + + // If the 'Different Even & Odd Pages' flag is turned on - do not ignore it + // Even if the 'Even' header/footer is blank - the flag should be imported (so it would look in LO like in Word) + if (!bFirst && GetSettingsTable()->GetEvenAndOddHeaders()) + xPageStyle->setPropertyValue(getPropertyName(ePropShared), uno::makeAny(false)); + + //set the interface + uno::Reference< text::XText > xText; + xPageStyle->getPropertyValue(getPropertyName(bLeft? ePropTextLeft: ePropText)) >>= xText; + + m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >(xText, uno::UNO_QUERY_THROW), + m_bIsNewDoc + ? uno::Reference() + : xText->createTextCursorByRange(xText->getStart()))); + m_bDiscardHeaderFooter = false; // set only on success! + } + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper"); + } + } +} + +void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType) +{ + PushPageHeaderFooter(/* bHeader = */ true, eType); +} + +void DomainMapper_Impl::PushPageFooter(SectionPropertyMap::PageType eType) +{ + PushPageHeaderFooter(/* bHeader = */ false, eType); +} + +void DomainMapper_Impl::PopPageHeaderFooter() +{ + //header and footer always have an empty paragraph at the end + //this has to be removed + RemoveLastParagraph( ); + + if (!m_aTextAppendStack.empty()) + { + if (!m_bDiscardHeaderFooter) + { + m_aTextAppendStack.pop(); + } + m_bDiscardHeaderFooter = false; + } + m_eInHeaderFooterImport = HeaderFooterImportState::none; + + if (!m_aHeaderFooterStack.empty()) + { + m_bTextInserted = m_aHeaderFooterStack.top().getTextInserted(); + m_nTableDepth = m_aHeaderFooterStack.top().getTableDepth(); + m_aHeaderFooterStack.pop(); + } +} + +void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote ) +{ + SAL_WARN_IF(m_bInFootOrEndnote, "writerfilter.dmapper", "PushFootOrEndnote() is called from another foot or endnote"); + m_bInFootOrEndnote = true; + m_bCheckFirstFootnoteTab = true; + m_bSaveFirstParagraphInCell = m_bFirstParagraphInCell; + try + { + // Redlines outside the footnote should not affect footnote content + m_aRedlines.push(std::vector< RedlineParamsPtr >()); + + // IMHO character styles from footnote labels should be ignored in the edit view of Writer. + // This adds a hack on top of the following hack to save the style name in the context. + PropertyMapPtr pTopContext = GetTopContext(); + OUString sFootnoteCharStyleName; + std::optional< PropertyMap::Property > aProp = pTopContext->getProperty(PROP_CHAR_STYLE_NAME); + if (aProp) + aProp->second >>= sFootnoteCharStyleName; + + // Remove style reference, if any. This reference did appear here as a side effect of tdf#43017 + // Seems it is not required by LO, but causes side effects during editing. So remove it + // for footnotes/endnotes to restore original LO behavior here. + pTopContext->Erase(PROP_CHAR_STYLE_NAME); + + uno::Reference< text::XText > xFootnoteText; + if (GetTextFactory().is()) + xFootnoteText.set( GetTextFactory()->createInstance( + bIsFootnote ? + OUString( "com.sun.star.text.Footnote" ) : OUString( "com.sun.star.text.Endnote" )), + uno::UNO_QUERY_THROW ); + uno::Reference< text::XFootnote > xFootnote( xFootnoteText, uno::UNO_QUERY_THROW ); + pTopContext->SetFootnote(xFootnote, sFootnoteCharStyleName); + uno::Sequence< beans::PropertyValue > aFontProperties = pTopContext->GetPropertyValues(); + appendTextContent( uno::Reference< text::XTextContent >( xFootnoteText, uno::UNO_QUERY_THROW ), aFontProperties ); + m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >( xFootnoteText, uno::UNO_QUERY_THROW ), + xFootnoteText->createTextCursorByRange(xFootnoteText->getStart()))); + + // Redlines for the footnote anchor in the main text content + std::vector< RedlineParamsPtr > aFootnoteRedline = std::move(m_aRedlines.top()); + m_aRedlines.pop(); + CheckRedline( xFootnote->getAnchor( ) ); + m_aRedlines.push( aFootnoteRedline ); + + // Try scanning for custom footnote labels + if (!sFootnoteCharStyleName.isEmpty()) + StartCustomFootnote(pTopContext); + else + EndCustomFootnote(); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "PushFootOrEndnote"); + } +} + +void DomainMapper_Impl::CreateRedline(uno::Reference const& xRange, + const RedlineParamsPtr& pRedline) +{ + if ( pRedline ) + { + try + { + OUString sType; + switch ( pRedline->m_nToken & 0xffff ) + { + case XML_mod: + sType = getPropertyName( PROP_FORMAT ); + break; + case XML_moveTo: + case XML_ins: + sType = getPropertyName( PROP_INSERT ); + break; + case XML_moveFrom: + m_pParaMarkerRedlineMoveFrom = pRedline.get(); + [[fallthrough]]; + case XML_del: + sType = getPropertyName( PROP_DELETE ); + break; + case XML_ParagraphFormat: + sType = getPropertyName( PROP_PARAGRAPH_FORMAT ); + break; + default: + throw lang::IllegalArgumentException("illegal redline token type", nullptr, 0); + } + beans::PropertyValues aRedlineProperties( 3 ); + beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray( ); + pRedlineProperties[0].Name = getPropertyName( PROP_REDLINE_AUTHOR ); + pRedlineProperties[0].Value <<= pRedline->m_sAuthor; + pRedlineProperties[1].Name = getPropertyName( PROP_REDLINE_DATE_TIME ); + pRedlineProperties[1].Value <<= ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate ); + pRedlineProperties[2].Name = getPropertyName( PROP_REDLINE_REVERT_PROPERTIES ); + pRedlineProperties[2].Value <<= pRedline->m_aRevertProperties; + if (!m_bIsActualParagraphFramed) + { + uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW ); + xRedline->makeRedline( sType, aRedlineProperties ); + } + else + { + aFramedRedlines.push_back( uno::makeAny(xRange) ); + aFramedRedlines.push_back( uno::makeAny(sType) ); + aFramedRedlines.push_back( uno::makeAny(aRedlineProperties) ); + } + } + catch( const uno::Exception & ) + { + OSL_FAIL( "Exception in makeRedline" ); + } + } +} + +void DomainMapper_Impl::CheckParaMarkerRedline( uno::Reference< text::XTextRange > const& xRange ) +{ + if ( m_pParaMarkerRedline ) + { + CreateRedline( xRange, m_pParaMarkerRedline ); + if ( m_pParaMarkerRedline ) + { + m_pParaMarkerRedline.clear(); + m_currentRedline.clear(); + } + } + else if ( m_pParaMarkerRedlineMoveFrom ) + { + // terminating moveFrom redline removes also the paragraph mark + m_pParaMarkerRedlineMoveFrom->m_nToken = XML_del; + CreateRedline( xRange, m_pParaMarkerRedlineMoveFrom ); + } + if ( m_pParaMarkerRedlineMoveFrom ) + { + m_pParaMarkerRedlineMoveFrom.clear(); + } +} + +void DomainMapper_Impl::CheckRedline( uno::Reference< text::XTextRange > const& xRange ) +{ + // Writer core "officially" does not like overlapping redlines, and its UNO interface is stupid enough + // to not prevent that. However, in practice in fact everything appears to work fine (except for the debug warnings + // about redline table corruption, which may possibly be harmless in reality). So leave this as it is, since this + // is a better representation of how the changes happened. If this will ever become a problem, overlapping redlines + // will need to be merged into one, just like doing the changes in the UI does, which will lose some information + // (and so if that happens, it may be better to fix Writer). + // Create the redlines here from lowest (formats) to highest (inserts/removals) priority, since the last one is + // what Writer presents graphically, so this will show deletes as deleted text and not as just formatted text being there. + bool bUsedRange = m_aRedlines.top().size() > 0 || (GetTopContextOfType(CONTEXT_CHARACTER) && + GetTopContextOfType(CONTEXT_CHARACTER)->Redlines().size() > 0); + + // only export ParagraphFormat, when there is no other redline in the same text portion to avoid missing redline compression, + // but always export the first ParagraphFormat redline in a paragraph to keep the paragraph style change data for rejection + if( (!bUsedRange || !m_bParaChanged) && GetTopContextOfType(CONTEXT_PARAGRAPH) ) + { + std::vector& avRedLines = GetTopContextOfType(CONTEXT_PARAGRAPH)->Redlines(); + for( const auto& rRedline : avRedLines ) + CreateRedline( xRange, rRedline ); + } + if( GetTopContextOfType(CONTEXT_CHARACTER) ) + { + std::vector& avRedLines = GetTopContextOfType(CONTEXT_CHARACTER)->Redlines(); + for( const auto& rRedline : avRedLines ) + CreateRedline( xRange, rRedline ); + } + for (const auto& rRedline : m_aRedlines.top() ) + CreateRedline( xRange, rRedline ); +} + +void DomainMapper_Impl::StartParaMarkerChange( ) +{ + m_bIsParaMarkerChange = true; +} + +void DomainMapper_Impl::EndParaMarkerChange( ) +{ + m_bIsParaMarkerChange = false; + m_previousRedline = m_currentRedline; + m_currentRedline.clear(); +} + +void DomainMapper_Impl::StartCustomFootnote(const PropertyMapPtr pContext) +{ + if (pContext == m_pFootnoteContext) + return; + + assert(pContext->GetFootnote().is()); + m_bHasFootnoteStyle = true; + m_bCheckFootnoteStyle = !pContext->GetFootnoteStyle().isEmpty(); + m_pFootnoteContext = pContext; +} + +void DomainMapper_Impl::EndCustomFootnote() +{ + m_bHasFootnoteStyle = false; + m_bCheckFootnoteStyle = false; +} + +void DomainMapper_Impl::PushAnnotation() +{ + try + { + m_bIsInComments = true; + if (!GetTextFactory().is()) + return; + m_xAnnotationField.set( GetTextFactory()->createInstance( "com.sun.star.text.TextField.Annotation" ), + uno::UNO_QUERY_THROW ); + uno::Reference< text::XText > xAnnotationText; + m_xAnnotationField->getPropertyValue("TextRange") >>= xAnnotationText; + m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >( xAnnotationText, uno::UNO_QUERY_THROW ), + m_bIsNewDoc ? uno::Reference() : xAnnotationText->createTextCursorByRange(xAnnotationText->getStart()))); + } + catch( const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper"); + } +} + + +void DomainMapper_Impl::PopFootOrEndnote() +{ + if (!IsRTFImport()) + RemoveLastParagraph(); + + // In case the foot or endnote did not contain a tab. + m_bIgnoreNextTab = false; + + if (!m_aTextAppendStack.empty()) + m_aTextAppendStack.pop(); + + if (m_aRedlines.size() == 1) + { + SAL_WARN("writerfilter.dmapper", "PopFootOrEndnote() is called without PushFootOrEndnote()?"); + return; + } + m_aRedlines.pop(); + m_eSkipFootnoteState = SkipFootnoteSeparator::OFF; + m_bInFootOrEndnote = false; + m_pFootnoteContext = nullptr; + m_bFirstParagraphInCell = m_bSaveFirstParagraphInCell; +} + +void DomainMapper_Impl::PopAnnotation() +{ + RemoveLastParagraph(); + + m_bIsInComments = false; + m_aTextAppendStack.pop(); + + try + { + // See if the annotation will be a single position or a range. + if (m_nAnnotationId == -1 || !m_aAnnotationPositions[m_nAnnotationId].m_xStart.is() || !m_aAnnotationPositions[m_nAnnotationId].m_xEnd.is()) + { + uno::Sequence< beans::PropertyValue > aEmptyProperties; + uno::Reference< text::XTextContent > xContent( m_xAnnotationField, uno::UNO_QUERY_THROW ); + appendTextContent( xContent, aEmptyProperties ); + CheckRedline( xContent->getAnchor( ) ); + } + else + { + AnnotationPosition& aAnnotationPosition = m_aAnnotationPositions[m_nAnnotationId]; + // Create a range that points to the annotation start/end. + uno::Reference const xText = aAnnotationPosition.m_xStart->getText(); + uno::Reference const xCursor = xText->createTextCursorByRange(aAnnotationPosition.m_xStart); + + bool bMarker = false; + uno::Reference xTextRangeCompare(xText, uno::UNO_QUERY); + if (xTextRangeCompare->compareRegionStarts(aAnnotationPosition.m_xStart, aAnnotationPosition.m_xEnd) == 0) + { + // Insert a marker so that comment around an anchored image is not collapsed during + // insertion. + xText->insertString(xCursor, "x", false); + bMarker = true; + } + + xCursor->gotoRange(aAnnotationPosition.m_xEnd, true); + uno::Reference const xTextRange(xCursor, uno::UNO_QUERY_THROW); + + // Attach the annotation to the range. + uno::Reference const xTextAppend = m_aTextAppendStack.top().xTextAppend; + xTextAppend->insertTextContent(xTextRange, uno::Reference(m_xAnnotationField, uno::UNO_QUERY_THROW), !xCursor->isCollapsed()); + + if (bMarker) + { + // Remove the marker. + xCursor->goLeft(1, true); + xCursor->setString(OUString()); + } + } + m_aAnnotationPositions.erase( m_nAnnotationId ); + } + catch (uno::Exception const&) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "Cannot insert annotation field"); + } + + m_xAnnotationField.clear(); + m_nAnnotationId = -1; +} + +void DomainMapper_Impl::PushPendingShape( const uno::Reference< drawing::XShape > & xShape ) +{ + m_aPendingShapes.push_back(xShape); +} + +uno::Reference DomainMapper_Impl::PopPendingShape() +{ + uno::Reference xRet; + if (!m_aPendingShapes.empty()) + { + xRet = m_aPendingShapes.front(); + m_aPendingShapes.pop_front(); + } + return xRet; +} + +void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape > & xShape ) +{ + // Append these early, so the context and the table manager stack will be + // in sync, even if the text append stack is empty. + appendTableManager(); + appendTableHandler(); + getTableManager().startLevel(); + + if (m_aTextAppendStack.empty()) + return; + uno::Reference xTextAppend = m_aTextAppendStack.top().xTextAppend; + + try + { + uno::Reference< lang::XServiceInfo > xSInfo( xShape, uno::UNO_QUERY_THROW ); + if (xSInfo->supportsService("com.sun.star.drawing.GroupShape")) + { + // Textboxes in shapes do not support styles, so check saved style information and apply properties directly to the child shapes. + const uno::Reference xShapes(xShape, uno::UNO_QUERY); + const sal_uInt32 nShapeCount = xShapes.is() ? xShapes->getCount() : 0; + for ( sal_uInt32 i = 0; i < nShapeCount; ++i ) + { + try + { + uno::Reference xSyncedPropertySet(xShapes->getByIndex(i), uno::UNO_QUERY_THROW); + comphelper::SequenceAsHashMap aGrabBag( xSyncedPropertySet->getPropertyValue("CharInteropGrabBag") ); + + // only VML import has checked for style. Don't apply default parastyle properties to other imported shapes + // - except for fontsize - to maintain compatibility with previous versions of LibreOffice. + const bool bOnlyApplyCharHeight = !aGrabBag["mso-pStyle"].hasValue(); + + OUString sStyleName; + aGrabBag["mso-pStyle"] >>= sStyleName; + StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByISTD( sStyleName ); + if ( !pEntry ) + { + // Use default style even in ambiguous cases (where multiple styles were defined) since MOST styles inherit + // MOST of their properties from the default style. In the ambiguous case, we have to accept some kind of compromise + // and the default paragraph style ought to be the safest one... (compared to DocDefaults or program defaults) + pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetDefaultParaStyleName() ); + } + if ( pEntry ) + { + // The Ids here come from oox/source/vml/vmltextbox.cxx. + // It probably could safely expand to all Ids that shapes support. + const PropertyIds eIds[] = { + PROP_CHAR_HEIGHT, + PROP_CHAR_FONT_NAME, + PROP_CHAR_WEIGHT, + PROP_CHAR_CHAR_KERNING, + PROP_CHAR_COLOR, + PROP_PARA_ADJUST + }; + const uno::Reference xSyncedPropertyState(xSyncedPropertySet, uno::UNO_QUERY_THROW); + for ( const auto& eId : eIds ) + { + try + { + if ( bOnlyApplyCharHeight && eId != PROP_CHAR_HEIGHT ) + continue; + + const OUString sPropName = getPropertyName(eId); + if ( beans::PropertyState_DEFAULT_VALUE == xSyncedPropertyState->getPropertyState(sPropName) ) + { + const uno::Any aProp = GetPropertyFromStyleSheet(eId, pEntry, /*bDocDefaults=*/true, /*bPara=*/true); + if ( aProp.hasValue() ) + xSyncedPropertySet->setPropertyValue( sPropName, aProp ); + } + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", "PushShapeContext() text stylesheet property exception" ); + } + } + } + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", "PushShapeContext()" ); + } + } + + // A GroupShape doesn't implement text::XTextRange, but appending + // an empty reference to the stacks still makes sense, because this + // way bToRemove can be set, and we won't end up with duplicated + // shapes for OLE objects. + m_aTextAppendStack.push(TextAppendContext(uno::Reference(xShape, uno::UNO_QUERY), uno::Reference())); + uno::Reference xTxtContent(xShape, uno::UNO_QUERY); + m_aAnchoredStack.push(AnchoredContext(xTxtContent)); + } + else if (xSInfo->supportsService("com.sun.star.drawing.OLE2Shape")) + { + // OLE2Shape from oox should be converted to a TextEmbeddedObject for sw. + m_aTextAppendStack.push(TextAppendContext(uno::Reference(xShape, uno::UNO_QUERY), uno::Reference())); + uno::Reference xTextContent(xShape, uno::UNO_QUERY); + m_aAnchoredStack.push(AnchoredContext(xTextContent)); + uno::Reference xShapePropertySet(xShape, uno::UNO_QUERY); + + m_xEmbedded.set(m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW); + uno::Reference xEmbeddedProperties(m_xEmbedded, uno::UNO_QUERY_THROW); + xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_EMBEDDED_OBJECT), xShapePropertySet->getPropertyValue(getPropertyName(PROP_EMBEDDED_OBJECT))); + xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), uno::makeAny(text::TextContentAnchorType_AS_CHARACTER)); + // So that the original bitmap-only shape will be replaced by the embedded object. + m_aAnchoredStack.top().bToRemove = true; + m_aTextAppendStack.pop(); + appendTextContent(m_xEmbedded, uno::Sequence()); + } + else + { + uno::Reference< text::XTextRange > xShapeText( xShape, uno::UNO_QUERY_THROW); + // Add the shape to the text append stack + m_aTextAppendStack.push( TextAppendContext(uno::Reference< text::XTextAppend >( xShape, uno::UNO_QUERY_THROW ), + m_bIsNewDoc ? uno::Reference() : m_xBodyText->createTextCursorByRange(xShapeText->getStart() ))); + + // Add the shape to the anchored objects stack + uno::Reference< text::XTextContent > xTxtContent( xShape, uno::UNO_QUERY_THROW ); + m_aAnchoredStack.push( AnchoredContext(xTxtContent) ); + + uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY_THROW ); +#ifdef DBG_UTIL + TagLogger::getInstance().unoPropertySet(xProps); +#endif + text::TextContentAnchorType nAnchorType(text::TextContentAnchorType_AT_PARAGRAPH); + xProps->getPropertyValue(getPropertyName( PROP_ANCHOR_TYPE )) >>= nAnchorType; + bool checkZOrderStatus = false; + if (xSInfo->supportsService("com.sun.star.text.TextFrame")) + { + SetIsTextFrameInserted(true); + // Extract the special "btLr text frame" mode, requested by oox, if needed. + // Extract vml ZOrder from FrameInteropGrabBag + uno::Reference xShapePropertySet(xShape, uno::UNO_QUERY); + uno::Sequence aGrabBag; + xShapePropertySet->getPropertyValue("FrameInteropGrabBag") >>= aGrabBag; + + for (const auto& rProp : std::as_const(aGrabBag)) + { + if (rProp.Name == "VML-Z-ORDER") + { + GraphicZOrderHelper* pZOrderHelper = m_rDMapper.graphicZOrderHelper(); + sal_Int32 zOrder(0); + rProp.Value >>= zOrder; + xShapePropertySet->setPropertyValue( "ZOrder", uno::makeAny(pZOrderHelper->findZOrder(zOrder))); + pZOrderHelper->addItem(xShapePropertySet, zOrder); + xShapePropertySet->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::makeAny( zOrder >= 0 ) ); + checkZOrderStatus = true; + } + else if ( rProp.Name == "TxbxHasLink" ) + { + //Chaining of textboxes will happen in ~DomainMapper_Impl + //i.e when all the textboxes are read and all its attributes + //have been set ( basically the Name/LinkedDisplayName ) + //which is set in Graphic Import. + m_vTextFramesForChaining.push_back(xShape); + } + } + + uno::Reference xTextContent(xShape, uno::UNO_QUERY_THROW); + uno::Reference xTextRange(xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW); + xTextAppend->insertTextContent(xTextRange, xTextContent, false); + + uno::Reference xPropertySet(xTextContent, uno::UNO_QUERY); + // we need to re-set this value to xTextContent, then only values are preserved. + xPropertySet->setPropertyValue("FrameInteropGrabBag",uno::makeAny(aGrabBag)); + } + else if (nAnchorType == text::TextContentAnchorType_AS_CHARACTER) + { + // Fix spacing for as-character objects. If the paragraph has CT_Spacing_after set, + // it needs to be set on the object too, as that's what object placement code uses. + PropertyMapPtr paragraphContext = GetTopContextOfType( CONTEXT_PARAGRAPH ); + std::optional aPropMargin = paragraphContext->getProperty(PROP_PARA_BOTTOM_MARGIN); + if(aPropMargin) + xProps->setPropertyValue( getPropertyName( PROP_BOTTOM_MARGIN ), aPropMargin->second ); + } + else + { + uno::Reference xShapePropertySet(xShape, uno::UNO_QUERY); + uno::Sequence aGrabBag; + xShapePropertySet->getPropertyValue("InteropGrabBag") >>= aGrabBag; + for (const auto& rProp : std::as_const(aGrabBag)) + { + if (rProp.Name == "VML-Z-ORDER") + { + GraphicZOrderHelper* pZOrderHelper = m_rDMapper.graphicZOrderHelper(); + sal_Int32 zOrder(0); + rProp.Value >>= zOrder; + xShapePropertySet->setPropertyValue( "ZOrder", uno::makeAny(pZOrderHelper->findZOrder(zOrder))); + pZOrderHelper->addItem(xShapePropertySet, zOrder); + xShapePropertySet->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::makeAny( zOrder >= 0 ) ); + checkZOrderStatus = true; + } + else if ( rProp.Name == "TxbxHasLink" ) + { + //Chaining of textboxes will happen in ~DomainMapper_Impl + //i.e when all the textboxes are read and all its attributes + //have been set ( basically the Name/LinkedDisplayName ) + //which is set in Graphic Import. + m_vTextFramesForChaining.push_back(xShape); + } + } + + if(IsSdtEndBefore()) + { + uno::Reference< beans::XPropertySetInfo > xPropSetInfo; + if(xShapePropertySet.is()) + { + xPropSetInfo = xShapePropertySet->getPropertySetInfo(); + if (xPropSetInfo.is() && xPropSetInfo->hasPropertyByName("InteropGrabBag")) + { + uno::Sequence aShapeGrabBag( comphelper::InitPropertySequence({ + { "SdtEndBefore", uno::Any(true) } + })); + xShapePropertySet->setPropertyValue("InteropGrabBag",uno::makeAny(aShapeGrabBag)); + } + } + } + } + if (!IsInHeaderFooter() && !checkZOrderStatus) + xProps->setPropertyValue( + getPropertyName( PROP_OPAQUE ), + uno::makeAny( true ) ); + } + m_bParaChanged = true; + getTableManager().setIsInShape(true); + } + catch ( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "Exception when adding shape"); + } +} +/* + * Updating chart height and width after reading the actual values from wp:extent +*/ +void DomainMapper_Impl::UpdateEmbeddedShapeProps(const uno::Reference< drawing::XShape > & xShape) +{ + if (!xShape.is()) + return; + + uno::Reference xEmbeddedProperties(m_xEmbedded, uno::UNO_QUERY_THROW); + awt::Size aSize = xShape->getSize( ); + xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_WIDTH), uno::makeAny(sal_Int32(aSize.Width))); + xEmbeddedProperties->setPropertyValue(getPropertyName(PROP_HEIGHT), uno::makeAny(sal_Int32(aSize.Height))); +} + + +void DomainMapper_Impl::PopShapeContext() +{ + if (hasTableManager()) + { + getTableManager().endLevel(); + popTableManager(); + } + if ( !m_aAnchoredStack.empty() ) + { + // For OLE object replacement shape, the text append context was already removed + // or the OLE object couldn't be inserted. + if ( !m_aAnchoredStack.top().bToRemove ) + { + RemoveLastParagraph(); + if (!m_aTextAppendStack.empty()) + m_aTextAppendStack.pop(); + } + + uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( ).xTextContent; + try + { + appendTextContent( xObj, uno::Sequence< beans::PropertyValue >() ); + } + catch ( const uno::RuntimeException& ) + { + // this is normal: the shape is already attached + } + + const uno::Reference xShape( xObj, uno::UNO_QUERY_THROW ); + // Remove the shape if required (most likely replacement shape for OLE object) + // or anchored to a discarded header or footer + if ( m_aAnchoredStack.top().bToRemove || m_bDiscardHeaderFooter ) + { + try + { + uno::Reference xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + if ( xDrawPage.is() ) + xDrawPage->remove( xShape ); + } + catch( const uno::Exception& ) + { + } + } + + // Relative width calculations deferred until section's margins are defined. + // Being cautious: only deferring undefined/minimum-width shapes in order to avoid causing potential regressions + css::awt::Size aShapeSize; + try + { + aShapeSize = xShape->getSize(); + } + catch (const css::uno::RuntimeException& e) + { + // May happen e.g. when text frame has no frame format + // See sw/qa/extras/ooxmlimport/data/n779627.docx + SAL_WARN("writerfilter.dmapper", "getSize failed. " << e.Message); + } + if( aShapeSize.Width <= 2 ) + { + const uno::Reference xShapePropertySet( xShape, uno::UNO_QUERY ); + SectionPropertyMap* pSectionContext = GetSectionContext(); + if ( pSectionContext && (!hasTableManager() || !getTableManager().isInTable()) && + xShapePropertySet->getPropertySetInfo()->hasPropertyByName(getPropertyName(PROP_RELATIVE_WIDTH)) ) + { + pSectionContext->addRelativeWidthShape(xShape); + } + } + + m_aAnchoredStack.pop(); + } +} + +bool DomainMapper_Impl::IsSdtEndBefore() +{ + bool bIsSdtEndBefore = false; + PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_CHARACTER); + if(pContext) + { + const uno::Sequence< beans::PropertyValue > currentCharProps = pContext->GetPropertyValues(); + for (const auto& rCurrentCharProp : currentCharProps) + { + if (rCurrentCharProp.Name == "CharInteropGrabBag") + { + uno::Sequence aCharGrabBag; + rCurrentCharProp.Value >>= aCharGrabBag; + for (const auto& rProp : std::as_const(aCharGrabBag)) + { + if(rProp.Name == "SdtEndBefore") + { + rProp.Value >>= bIsSdtEndBefore; + } + } + } + } + } + return bIsSdtEndBefore; +} + +bool DomainMapper_Impl::IsDiscardHeaderFooter() const +{ + return m_bDiscardHeaderFooter; +} + +// called from TableManager::closeCell() +void DomainMapper_Impl::ClearPreviousParagraph() +{ + // in table cells, set bottom auto margin of last paragraph to 0, except in paragraphs with numbering + if ((m_nTableDepth == (m_nTableCellDepth + 1)) + && m_xPreviousParagraph.is() + && hasTableManager() && getTableManager().isCellLastParaAfterAutospacing()) + { + uno::Reference xPreviousNumberingRules(m_xPreviousParagraph->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + if ( !xPreviousNumberingRules.is() || xPreviousNumberingRules->getName().isEmpty() ) + m_xPreviousParagraph->setPropertyValue("ParaBottomMargin", uno::makeAny(static_cast(0))); + } + + m_xPreviousParagraph.clear(); + + // next table paragraph will be first paragraph in a cell + m_bFirstParagraphInCell = true; +} + +static sal_Int16 lcl_ParseNumberingType( const OUString& rCommand ) +{ + sal_Int16 nRet = style::NumberingType::PAGE_DESCRIPTOR; + + // The command looks like: " PAGE \* Arabic " + // tdf#132185: but may as well be "PAGE \* Arabic" + OUString sNumber; + constexpr OUStringLiteral rSeparator("\\* "); + if (sal_Int32 nStartIndex = rCommand.indexOf(rSeparator); nStartIndex >= 0) + { + nStartIndex += rSeparator.getLength(); + sNumber = rCommand.getToken(0, ' ', nStartIndex); + } + + if( !sNumber.isEmpty() ) + { + //todo: might make sense to hash this list, too + struct NumberingPairs + { + const sal_Char* cWordName; + sal_Int16 nType; + }; + static const NumberingPairs aNumberingPairs[] = + { + {"Arabic", style::NumberingType::ARABIC} + ,{"ROMAN", style::NumberingType::ROMAN_UPPER} + ,{"roman", style::NumberingType::ROMAN_LOWER} + ,{"ALPHABETIC", style::NumberingType::CHARS_UPPER_LETTER} + ,{"alphabetic", style::NumberingType::CHARS_LOWER_LETTER} + ,{"CircleNum", style::NumberingType::CIRCLE_NUMBER} + ,{"ThaiArabic", style::NumberingType::CHARS_THAI} + ,{"ThaiCardText", style::NumberingType::CHARS_THAI} + ,{"ThaiLetter", style::NumberingType::CHARS_THAI} +// ,{"SBCHAR", style::NumberingType::} +// ,{"DBCHAR", style::NumberingType::} +// ,{"DBNUM1", style::NumberingType::} +// ,{"DBNUM2", style::NumberingType::} +// ,{"DBNUM3", style::NumberingType::} +// ,{"DBNUM4", style::NumberingType::} + ,{"Aiueo", style::NumberingType::AIU_FULLWIDTH_JA} + ,{"Iroha", style::NumberingType::IROHA_FULLWIDTH_JA} +// ,{"ZODIAC1", style::NumberingType::} +// ,{"ZODIAC2", style::NumberingType::} +// ,{"ZODIAC3", style::NumberingType::} +// ,{"CHINESENUM1", style::NumberingType::} +// ,{"CHINESENUM2", style::NumberingType::} +// ,{"CHINESENUM3", style::NumberingType::} + ,{"ArabicAlpha", style::NumberingType::CHARS_ARABIC} + ,{"ArabicAbjad", style::NumberingType::FULLWIDTH_ARABIC} +/* possible values: +style::NumberingType:: + + CHARS_UPPER_LETTER_N + CHARS_LOWER_LETTER_N + TRANSLITERATION + NATIVE_NUMBERING + CIRCLE_NUMBER + NUMBER_LOWER_ZH + NUMBER_UPPER_ZH + NUMBER_UPPER_ZH_TW + TIAN_GAN_ZH + DI_ZI_ZH + NUMBER_TRADITIONAL_JA + AIU_HALFWIDTH_JA + IROHA_HALFWIDTH_JA + NUMBER_UPPER_KO + NUMBER_HANGUL_KO + HANGUL_JAMO_KO + HANGUL_SYLLABLE_KO + HANGUL_CIRCLED_JAMO_KO + HANGUL_CIRCLED_SYLLABLE_KO + CHARS_HEBREW + CHARS_NEPALI + CHARS_KHMER + CHARS_LAO + CHARS_TIBETAN + CHARS_CYRILLIC_UPPER_LETTER_BG + CHARS_CYRILLIC_LOWER_LETTER_BG + CHARS_CYRILLIC_UPPER_LETTER_N_BG + CHARS_CYRILLIC_LOWER_LETTER_N_BG + CHARS_CYRILLIC_UPPER_LETTER_RU + CHARS_CYRILLIC_LOWER_LETTER_RU + CHARS_CYRILLIC_UPPER_LETTER_N_RU + CHARS_CYRILLIC_LOWER_LETTER_N_RU + CHARS_CYRILLIC_UPPER_LETTER_SR + CHARS_CYRILLIC_LOWER_LETTER_SR + CHARS_CYRILLIC_UPPER_LETTER_N_SR + CHARS_CYRILLIC_LOWER_LETTER_N_SR*/ + + }; + for(const NumberingPairs& rNumberingPair : aNumberingPairs) + { + if( /*sCommand*/sNumber.equalsAscii(rNumberingPair.cWordName )) + { + nRet = rNumberingPair.nType; + break; + } + } + + } + return nRet; +} + + +static OUString lcl_ParseFormat( const OUString& rCommand ) +{ + // The command looks like: " DATE \@"dd MMMM yyyy" or "09/02/2014" + // Remove whitespace permitted by standard between \@ and " + OUString command; + sal_Int32 delimPos = rCommand.indexOf("\\@"); + if (delimPos != -1) + { + sal_Int32 wsChars = rCommand.indexOf('\"') - delimPos - 2; + command = rCommand.replaceAt(delimPos+2, wsChars, ""); + } + else + command = rCommand; + + return msfilter::util::findQuotedText(command, "\\@\"", '\"'); +} +/*------------------------------------------------------------------------- +extract a parameter (with or without quotes) between the command and the following backslash + -----------------------------------------------------------------------*/ +static OUString lcl_ExtractToken(OUString const& rCommand, + sal_Int32 & rIndex, bool & rHaveToken, bool & rIsSwitch) +{ + rHaveToken = false; + rIsSwitch = false; + + OUStringBuffer token; + bool bQuoted(false); + for (; rIndex < rCommand.getLength(); ++rIndex) + { + sal_Unicode const currentChar(rCommand[rIndex]); + switch (currentChar) + { + case '\\': + { + if (rIndex == rCommand.getLength() - 1) + { + SAL_INFO("writerfilter.dmapper", "field: trailing escape"); + ++rIndex; + return OUString(); + } + sal_Unicode const nextChar(rCommand[rIndex+1]); + if (bQuoted || '\\' == nextChar) + { + ++rIndex; // read 2 chars + token.append(nextChar); + } + else // field switch (case insensitive) + { + rHaveToken = true; + if (token.isEmpty()) + { + rIsSwitch = true; + rIndex += 2; // read 2 chars + return rCommand.copy(rIndex - 2, 2).toAsciiUpperCase(); + } + else + { // leave rIndex, read it again next time + return token.makeStringAndClear(); + } + } + } + break; + case '\"': + if (bQuoted || !token.isEmpty()) + { + rHaveToken = true; + if (bQuoted) + { + ++rIndex; + } + return token.makeStringAndClear(); + } + else + { + bQuoted = true; + } + break; + case ' ': + if (bQuoted) + { + token.append(' '); + } + else + { + if (!token.isEmpty()) + { + rHaveToken = true; + ++rIndex; + return token.makeStringAndClear(); + } + } + break; + case '=': + if (token.isEmpty()) + { + rHaveToken = true; + ++rIndex; + return "FORMULA"; + } + break; + default: + token.append(currentChar); + break; + } + } + assert(rIndex == rCommand.getLength()); + if (bQuoted) + { + // MS Word allows this, so just emit a debug message + SAL_INFO("writerfilter.dmapper", + "field argument with unterminated quote"); + } + rHaveToken = !token.isEmpty(); + return token.makeStringAndClear(); +} + +std::tuple, std::vector > splitFieldCommand(const OUString& rCommand) +{ + OUString sType; + std::vector arguments; + std::vector switches; + sal_Int32 nStartIndex(0); + // tdf#54584: Field may be prepended by a backslash + // This is not an escapement, but already escaped literal "\" + // MS Word allows this, so just skip it + if ((rCommand.getLength() >= nStartIndex + 2) && + (rCommand[nStartIndex] == L'\\') && + (rCommand[nStartIndex + 1] != L'\\') && + (rCommand[nStartIndex + 1] != L' ')) + { + ++nStartIndex; + } + + do + { + bool bHaveToken; + bool bIsSwitch; + OUString const token = + lcl_ExtractToken(rCommand, nStartIndex, bHaveToken, bIsSwitch); + assert(nStartIndex <= rCommand.getLength()); + if (bHaveToken) + { + if (sType.isEmpty()) + { + sType = token.toAsciiUpperCase(); + } + else if (bIsSwitch || !switches.empty()) + { + switches.push_back(token); + } + else + { + arguments.push_back(token); + } + } + } while (nStartIndex < rCommand.getLength()); + + return std::make_tuple(sType, arguments, switches); +} + +static OUString lcl_ExctractVariableAndHint( const OUString& rCommand, OUString& rHint ) +{ + // the first word after "ASK " is the variable + // the text after the variable and before a '\' is the hint + // if no hint is set the variable is used as hint + // the quotes of the hint have to be removed + sal_Int32 nIndex = rCommand.indexOf( ' ', 2); //find last space after 'ASK' + if (nIndex == -1) + return OUString(); + while(rCommand[nIndex] == ' ') + ++nIndex; + OUString sShortCommand( rCommand.copy( nIndex ) ); //cut off the " ASK " + + sShortCommand = sShortCommand.getToken(0, '\\'); + nIndex = 0; + OUString sRet = sShortCommand.getToken( 0, ' ', nIndex); + if( nIndex > 0) + rHint = sShortCommand.copy( nIndex ); + if( rHint.isEmpty() ) + rHint = sRet; + return sRet; +} + + +static bool lcl_FindInCommand( + const OUString& rCommand, + sal_Unicode cSwitch, + OUString& rValue ) +{ + bool bRet = false; + OUString sSearch = "\\" + OUStringChar( cSwitch ); + sal_Int32 nIndex = rCommand.indexOf( sSearch ); + if( nIndex >= 0 ) + { + bRet = true; + //find next '\' or end of string + sal_Int32 nEndIndex = rCommand.indexOf( '\\', nIndex + 1); + if( nEndIndex < 0 ) + nEndIndex = rCommand.getLength() ; + if( nEndIndex - nIndex > 3 ) + rValue = rCommand.copy( nIndex + 3, nEndIndex - nIndex - 3); + } + return bRet; +} + + +void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale) +{ + PropertyMapPtr pTopContext = GetTopContext(); + std::optional pLocale = pTopContext->getProperty(PROP_CHAR_LOCALE); + if( pLocale ) + pLocale->second >>= rLocale; + else + { + PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH); + pLocale = pParaContext->getProperty(PROP_CHAR_LOCALE); + if( pLocale ) + { + pLocale->second >>= rLocale; + } + } +} + +/*------------------------------------------------------------------------- + extract the number format from the command and apply the resulting number + format to the XPropertySet + -----------------------------------------------------------------------*/ +void DomainMapper_Impl::SetNumberFormat( const OUString& rCommand, + uno::Reference< beans::XPropertySet > const& xPropertySet, + bool const bDetectFormat) +{ + OUString sFormatString = lcl_ParseFormat( rCommand ); + // find \h - hijri/luna calendar todo: what about saka/era calendar? + bool bHijri = 0 < rCommand.indexOf("\\h "); + lang::Locale aUSLocale; + aUSLocale.Language = "en"; + aUSLocale.Country = "US"; + + //determine current locale - todo: is it necessary to initialize this locale? + lang::Locale aCurrentLocale = aUSLocale; + GetCurrentLocale( aCurrentLocale ); + OUString sFormat = ConversionHelper::ConvertMSFormatStringToSO( sFormatString, aCurrentLocale, bHijri); + //get the number formatter and convert the string to a format value + try + { + sal_Int32 nKey = 0; + uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW ); + if( bDetectFormat ) + { + uno::Reference< util::XNumberFormatter> xFormatter(util::NumberFormatter::create(m_xComponentContext), uno::UNO_QUERY_THROW); + xFormatter->attachNumberFormatsSupplier( xNumberSupplier ); + nKey = xFormatter->detectNumberFormat( 0, rCommand ); + } + else + { + nKey = xNumberSupplier->getNumberFormats()->addNewConverted( sFormat, aUSLocale, aCurrentLocale ); + } + xPropertySet->setPropertyValue( + getPropertyName(PROP_NUMBER_FORMAT), + uno::makeAny( nKey )); + } + catch(const uno::Exception&) + { + } +} + +static uno::Any lcl_getGrabBagValue( const uno::Sequence& grabBag, OUString const & name ) +{ + auto pProp = std::find_if(grabBag.begin(), grabBag.end(), + [&name](const beans::PropertyValue& rProp) { return rProp.Name == name; }); + if (pProp != grabBag.end()) + return pProp->Value; + return uno::Any(); +} + +//Link the text frames. +void DomainMapper_Impl::ChainTextFrames() +{ + //can't link textboxes if there are not even two of them... + if( 2 > m_vTextFramesForChaining.size() ) + return ; + + struct TextFramesForChaining { + css::uno::Reference< css::drawing::XShape > xShape; + sal_Int32 nId; + sal_Int32 nSeq; + OUString s_mso_next_textbox; + bool bShapeNameSet; + TextFramesForChaining(): nId(0), nSeq(0), bShapeNameSet(false) {} + } ; + typedef std::map ChainMap; + + try + { + ChainMap aTextFramesForChainingHelper; + OUString sChainNextName("ChainNextName"); + + //learn about ALL of the textboxes and their chaining values first - because frames are processed in no specific order. + for( const auto& rTextFrame : m_vTextFramesForChaining ) + { + uno::Reference xTextContent(rTextFrame, uno::UNO_QUERY_THROW); + uno::Reference xPropertySet(xTextContent, uno::UNO_QUERY); + uno::Reference xPropertySetInfo; + if( xPropertySet.is() ) + xPropertySetInfo = xPropertySet->getPropertySetInfo(); + uno::Sequence aGrabBag; + uno::Reference xServiceInfo(xPropertySet, uno::UNO_QUERY); + + TextFramesForChaining aChainStruct; + OUString sShapeName; + OUString sLinkChainName; + + //The chaining name and the shape name CAN be different in .docx. + //MUST use LinkDisplayName/ChainName as the shape name for establishing links. + if ( xServiceInfo->supportsService("com.sun.star.text.TextFrame") ) + { + xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= aGrabBag; + xPropertySet->getPropertyValue("LinkDisplayName") >>= sShapeName; + } + else + { + xPropertySet->getPropertyValue("InteropGrabBag") >>= aGrabBag; + xPropertySet->getPropertyValue("ChainName") >>= sShapeName; + } + + lcl_getGrabBagValue( aGrabBag, "Txbx-Id") >>= aChainStruct.nId; + lcl_getGrabBagValue( aGrabBag, "Txbx-Seq") >>= aChainStruct.nSeq; + lcl_getGrabBagValue( aGrabBag, "LinkChainName") >>= sLinkChainName; + lcl_getGrabBagValue( aGrabBag, "mso-next-textbox") >>= aChainStruct.s_mso_next_textbox; + + //Sometimes the shape names have not been imported. If not, we may have a fallback name. + //Set name later, only if required for linking. + if( sShapeName.isEmpty() ) + aChainStruct.bShapeNameSet = false; + else + { + aChainStruct.bShapeNameSet = true; + sLinkChainName = sShapeName; + } + + if( !sLinkChainName.isEmpty() ) + { + aChainStruct.xShape = rTextFrame; + aTextFramesForChainingHelper[sLinkChainName] = aChainStruct; + } + } + + //if mso-next-textbox tags are provided, create those vml-style links first. Afterwards we will make dml-style id/seq links. + for (auto& msoItem : aTextFramesForChainingHelper) + { + //if no mso-next-textbox, we are done. + //if it points to itself, we are done. + if( !msoItem.second.s_mso_next_textbox.isEmpty() + && msoItem.second.s_mso_next_textbox != msoItem.first ) + { + ChainMap::iterator nextFinder=aTextFramesForChainingHelper.find(msoItem.second.s_mso_next_textbox); + if( nextFinder != aTextFramesForChainingHelper.end() ) + { + //if the frames have no name yet, then set them. LinkDisplayName / ChainName are read-only. + if( !msoItem.second.bShapeNameSet ) + { + uno::Reference< container::XNamed > xNamed( msoItem.second.xShape, uno::UNO_QUERY ); + if ( xNamed.is() ) + { + xNamed->setName( msoItem.first ); + msoItem.second.bShapeNameSet = true; + } + } + if( !nextFinder->second.bShapeNameSet ) + { + uno::Reference< container::XNamed > xNamed( nextFinder->second.xShape, uno::UNO_QUERY ); + if ( xNamed.is() ) + { + xNamed->setName( nextFinder->first ); + nextFinder->second.bShapeNameSet = true; + } + } + + uno::Reference xTextContent(msoItem.second.xShape, uno::UNO_QUERY_THROW); + uno::Reference xPropertySet(xTextContent, uno::UNO_QUERY); + + //The reverse chaining happens automatically, so only one direction needs to be set + xPropertySet->setPropertyValue(sChainNextName, uno::makeAny(nextFinder->first)); + + //the last item in an mso-next-textbox chain is indistinguishable from id/seq items. Now that it is handled, remove it. + if( nextFinder->second.s_mso_next_textbox.isEmpty() ) + aTextFramesForChainingHelper.erase(nextFinder->first); + } + } + } + + //TODO: Perhaps allow reverse sequences when mso-layout-flow-alt = "bottom-to-top" + const sal_Int32 nDirection = 1; + + //Finally - go through and attach the chains based on matching ID and incremented sequence number (dml-style). + for (const auto& rOuter : aTextFramesForChainingHelper) + { + if( rOuter.second.s_mso_next_textbox.isEmpty() ) //non-empty ones already handled earlier - so skipping them now. + { + for (const auto& rInner : aTextFramesForChainingHelper) + { + if ( rInner.second.nId == rOuter.second.nId ) + { + if ( rInner.second.nSeq == ( rOuter.second.nSeq + nDirection ) ) + { + uno::Reference xTextContent(rOuter.second.xShape, uno::UNO_QUERY_THROW); + uno::Reference xPropertySet(xTextContent, uno::UNO_QUERY); + + //The reverse chaining happens automatically, so only one direction needs to be set + xPropertySet->setPropertyValue(sChainNextName, uno::makeAny(rInner.first)); + break ; //there cannot be more than one next frame + } + } + } + } + } + m_vTextFramesForChaining.clear(); //clear the vector + } + catch (const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper"); + } +} + +uno::Reference DomainMapper_Impl::FindOrCreateFieldMaster(const char* pFieldMasterService, const OUString& rFieldMasterName) +{ + // query master, create if not available + uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters(); + uno::Reference< beans::XPropertySet > xMaster; + OUString sFieldMasterService( OUString::createFromAscii(pFieldMasterService) ); + OUStringBuffer aFieldMasterName; + OUString sDatabaseDataSourceName = GetSettingsTable()->GetCurrentDatabaseDataSource(); + bool bIsMergeField = sFieldMasterService.endsWith("Database"); + aFieldMasterName.appendAscii( pFieldMasterService ); + aFieldMasterName.append('.'); + if ( bIsMergeField && !sDatabaseDataSourceName.isEmpty() ) + { + aFieldMasterName.append(sDatabaseDataSourceName); + aFieldMasterName.append('.'); + } + aFieldMasterName.append(rFieldMasterName); + OUString sFieldMasterName = aFieldMasterName.makeStringAndClear(); + if(xFieldMasterAccess->hasByName(sFieldMasterName)) + { + //get the master + xMaster.set(xFieldMasterAccess->getByName(sFieldMasterName), uno::UNO_QUERY_THROW); + } + else if( m_xTextFactory.is() ) + { + //create the master + xMaster.set( m_xTextFactory->createInstance(sFieldMasterService), uno::UNO_QUERY_THROW); + if ( !bIsMergeField || sDatabaseDataSourceName.isEmpty() ) + { + //set the master's name + xMaster->setPropertyValue( + getPropertyName(PROP_NAME), + uno::makeAny(rFieldMasterName)); + } else { + // set database data, based on the "databasename.tablename" of sDatabaseDataSourceName + xMaster->setPropertyValue( + getPropertyName(PROP_DATABASE_NAME), + uno::makeAny(sDatabaseDataSourceName.copy(0, sDatabaseDataSourceName.indexOf('.')))); + xMaster->setPropertyValue( + getPropertyName(PROP_COMMAND_TYPE), + uno::makeAny(sal_Int32(0))); + xMaster->setPropertyValue( + getPropertyName(PROP_DATATABLE_NAME), + uno::makeAny(sDatabaseDataSourceName.copy(sDatabaseDataSourceName.indexOf('.') + 1))); + xMaster->setPropertyValue( + getPropertyName(PROP_DATACOLUMN_NAME), + uno::makeAny(rFieldMasterName)); + } + } + return xMaster; +} + +void DomainMapper_Impl::PushFieldContext() +{ + m_bParaHadField = true; + if(m_bDiscardHeaderFooter) + return; +#ifdef DBG_UTIL + TagLogger::getInstance().element("pushFieldContext"); +#endif + + uno::Reference xCrsr; + if (!m_aTextAppendStack.empty()) + { + uno::Reference xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is()) + xCrsr = xTextAppend->createTextCursorByRange( + m_aTextAppendStack.top().xInsertPosition.is() + ? m_aTextAppendStack.top().xInsertPosition + : xTextAppend->getEnd()); + } + + uno::Reference< text::XTextRange > xStart; + if (xCrsr.is()) + xStart = xCrsr->getStart(); + m_aFieldStack.push_back(new FieldContext(xStart)); +} +/*------------------------------------------------------------------------- +//the current field context waits for the completion of the command + -----------------------------------------------------------------------*/ +bool DomainMapper_Impl::IsOpenFieldCommand() const +{ + return !m_aFieldStack.empty() && !m_aFieldStack.back()->IsCommandCompleted(); +} +/*------------------------------------------------------------------------- +//the current field context waits for the completion of the command + -----------------------------------------------------------------------*/ +bool DomainMapper_Impl::IsOpenField() const +{ + return !m_aFieldStack.empty(); +} + +// Mark top field context as containing a fixed field +void DomainMapper_Impl::SetFieldLocked() +{ + if (IsOpenField()) + m_aFieldStack.back()->SetFieldLocked(); +} + +HeaderFooterContext::HeaderFooterContext(bool bTextInserted, sal_Int32 nTableDepth) + : m_bTextInserted(bTextInserted) + , m_nTableDepth(nTableDepth) +{ +} + +bool HeaderFooterContext::getTextInserted() const +{ + return m_bTextInserted; +} + +sal_Int32 HeaderFooterContext::getTableDepth() const { return m_nTableDepth; } + +FieldContext::FieldContext(uno::Reference< text::XTextRange > const& xStart) + : m_bFieldCommandCompleted(false) + , m_xStartRange( xStart ) + , m_bFieldLocked( false ) +{ + m_pProperties = new PropertyMap(); +} + + +FieldContext::~FieldContext() +{ +} + + +void FieldContext::AppendCommand(const OUString& rPart) +{ + m_sCommand += rPart; +} + +::std::vector FieldContext::GetCommandParts() const +{ + ::std::vector aResult; + sal_Int32 nIndex = 0; + bool bInString = false; + OUString sPart; + while (nIndex != -1) + { + OUString sToken = GetCommand().getToken(0, ' ', nIndex); + bool bInStringNext = bInString; + + if (sToken.isEmpty()) + continue; + + if (sToken[0] == '"') + { + bInStringNext = true; + sToken = sToken.copy(1); + } + if (sToken.endsWith("\"")) + { + bInStringNext = false; + sToken = sToken.copy(0, sToken.getLength() - 1); + } + + if (bInString) + { + sPart += " " + sToken; + if (!bInStringNext) + { + aResult.push_back(sPart); + } + } + else + { + if (bInStringNext) + { + sPart = sToken; + } + else + { + aResult.push_back(sToken); + } + } + + bInString = bInStringNext; + } + + return aResult; +} + +/*------------------------------------------------------------------------- +//collect the pieces of the command + -----------------------------------------------------------------------*/ +void DomainMapper_Impl::AppendFieldCommand(OUString const & rPartOfCommand) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("appendFieldCommand"); + TagLogger::getInstance().chars(rPartOfCommand); + TagLogger::getInstance().endElement(); +#endif + + FieldContextPtr pContext = m_aFieldStack.back(); + OSL_ENSURE( pContext.get(), "no field context available"); + if( pContext ) + { + pContext->AppendCommand( rPartOfCommand ); + } +} + + +typedef std::multimap < sal_Int32, OUString > TOCStyleMap; + + +static ww::eField GetWW8FieldId(OUString const& rType) +{ + std::unordered_map mapID + { + {"ADDRESSBLOCK", ww::eADDRESSBLOCK}, + {"ADVANCE", ww::eADVANCE}, + {"ASK", ww::eASK}, + {"AUTONUM", ww::eAUTONUM}, + {"AUTONUMLGL", ww::eAUTONUMLGL}, + {"AUTONUMOUT", ww::eAUTONUMOUT}, + {"AUTOTEXT", ww::eAUTOTEXT}, + {"AUTOTEXTLIST", ww::eAUTOTEXTLIST}, + {"AUTHOR", ww::eAUTHOR}, + {"BARCODE", ww::eBARCODE}, + {"BIDIOUTLINE", ww::eBIDIOUTLINE}, + {"DATE", ww::eDATE}, + {"COMMENTS", ww::eCOMMENTS}, + {"COMPARE", ww::eCOMPARE}, + {"CONTROL", ww::eCONTROL}, + {"CREATEDATE", ww::eCREATEDATE}, + {"DATABASE", ww::eDATABASE}, + {"DDEAUTOREF", ww::eDDEAUTOREF}, + {"DDEREF", ww::eDDEREF}, + {"DOCPROPERTY", ww::eDOCPROPERTY}, + {"DOCVARIABLE", ww::eDOCVARIABLE}, + {"EDITTIME", ww::eEDITTIME}, + {"EMBED", ww::eEMBED}, + {"EQ", ww::eEQ}, + {"FILLIN", ww::eFILLIN}, + {"FILENAME", ww::eFILENAME}, + {"FILESIZE", ww::eFILESIZE}, + {"FOOTREF", ww::eFOOTREF}, +// {"FORMULA", ww::}, + {"FORMCHECKBOX", ww::eFORMCHECKBOX}, + {"FORMDROPDOWN", ww::eFORMDROPDOWN}, + {"FORMTEXT", ww::eFORMTEXT}, + {"GLOSSREF", ww::eGLOSSREF}, + {"GOTOBUTTON", ww::eGOTOBUTTON}, + {"GREETINGLINE", ww::eGREETINGLINE}, + {"HTMLCONTROL", ww::eHTMLCONTROL}, + {"HYPERLINK", ww::eHYPERLINK}, + {"IF", ww::eIF}, + {"INFO", ww::eINFO}, + {"INCLUDEPICTURE", ww::eINCLUDEPICTURE}, + {"INCLUDETEXT", ww::eINCLUDETEXT}, + {"INCLUDETIFF", ww::eINCLUDETIFF}, + {"KEYWORDS", ww::eKEYWORDS}, + {"LASTSAVEDBY", ww::eLASTSAVEDBY}, + {"LINK", ww::eLINK}, + {"LISTNUM", ww::eLISTNUM}, + {"MACRO", ww::eMACRO}, + {"MACROBUTTON", ww::eMACROBUTTON}, + {"MERGEDATA", ww::eMERGEDATA}, + {"MERGEFIELD", ww::eMERGEFIELD}, + {"MERGEINC", ww::eMERGEINC}, + {"MERGEREC", ww::eMERGEREC}, + {"MERGESEQ", ww::eMERGESEQ}, + {"NEXT", ww::eNEXT}, + {"NEXTIF", ww::eNEXTIF}, + {"NOTEREF", ww::eNOTEREF}, + {"PAGE", ww::ePAGE}, + {"PAGEREF", ww::ePAGEREF}, + {"PLUGIN", ww::ePLUGIN}, + {"PRINT", ww::ePRINT}, + {"PRINTDATE", ww::ePRINTDATE}, + {"PRIVATE", ww::ePRIVATE}, + {"QUOTE", ww::eQUOTE}, + {"RD", ww::eRD}, + {"REF", ww::eREF}, + {"REVNUM", ww::eREVNUM}, + {"SAVEDATE", ww::eSAVEDATE}, + {"SECTION", ww::eSECTION}, + {"SECTIONPAGES", ww::eSECTIONPAGES}, + {"SEQ", ww::eSEQ}, + {"SET", ww::eSET}, + {"SKIPIF", ww::eSKIPIF}, + {"STYLEREF", ww::eSTYLEREF}, + {"SUBSCRIBER", ww::eSUBSCRIBER}, + {"SUBJECT", ww::eSUBJECT}, + {"SYMBOL", ww::eSYMBOL}, + {"TA", ww::eTA}, + {"TEMPLATE", ww::eTEMPLATE}, + {"TIME", ww::eTIME}, + {"TITLE", ww::eTITLE}, + {"TOA", ww::eTOA}, + {"USERINITIALS", ww::eUSERINITIALS}, + {"USERADDRESS", ww::eUSERADDRESS}, + {"USERNAME", ww::eUSERNAME}, + + {"TOC", ww::eTOC}, + {"TC", ww::eTC}, + {"NUMCHARS", ww::eNUMCHARS}, + {"NUMWORDS", ww::eNUMWORDS}, + {"NUMPAGES", ww::eNUMPAGES}, + {"INDEX", ww::eINDEX}, + {"XE", ww::eXE}, + {"BIBLIOGRAPHY", ww::eBIBLIOGRAPHY}, + {"CITATION", ww::eCITATION}, + }; + auto const it = mapID.find(rType); + return (it == mapID.end()) ? ww::eNONE : it->second; +} + +static const FieldConversionMap_t & lcl_GetFieldConversion() +{ + static const FieldConversionMap_t aFieldConversionMap + { +// {"ADDRESSBLOCK", {"", FIELD_ADDRESSBLOCK }}, +// {"ADVANCE", {"", FIELD_ADVANCE }}, + {"ASK", {"SetExpression", FIELD_ASK }}, + {"AUTONUM", {"SetExpression", FIELD_AUTONUM }}, + {"AUTONUMLGL", {"SetExpression", FIELD_AUTONUMLGL }}, + {"AUTONUMOUT", {"SetExpression", FIELD_AUTONUMOUT }}, + {"AUTHOR", {"DocInfo.CreateAuthor", FIELD_AUTHOR }}, + {"DATE", {"DateTime", FIELD_DATE }}, + {"COMMENTS", {"DocInfo.Description", FIELD_COMMENTS }}, + {"CREATEDATE", {"DocInfo.CreateDateTime", FIELD_CREATEDATE }}, + {"DOCPROPERTY", {"", FIELD_DOCPROPERTY }}, + {"DOCVARIABLE", {"User", FIELD_DOCVARIABLE }}, + {"EDITTIME", {"DocInfo.EditTime", FIELD_EDITTIME }}, + {"EQ", {"", FIELD_EQ }}, + {"FILLIN", {"Input", FIELD_FILLIN }}, + {"FILENAME", {"FileName", FIELD_FILENAME }}, +// {"FILESIZE", {"", FIELD_FILESIZE }}, + {"FORMULA", {"TableFormula", FIELD_FORMULA }}, + {"FORMCHECKBOX", {"", FIELD_FORMCHECKBOX }}, + {"FORMDROPDOWN", {"DropDown", FIELD_FORMDROPDOWN }}, + {"FORMTEXT", {"Input", FIELD_FORMTEXT }}, + {"GOTOBUTTON", {"", FIELD_GOTOBUTTON }}, + {"HYPERLINK", {"", FIELD_HYPERLINK }}, + {"IF", {"ConditionalText", FIELD_IF }}, +// {"INFO", {"", FIELD_INFO }}, + {"INCLUDEPICTURE", {"", FIELD_INCLUDEPICTURE}}, + {"KEYWORDS", {"DocInfo.KeyWords", FIELD_KEYWORDS }}, + {"LASTSAVEDBY", {"DocInfo.ChangeAuthor", FIELD_LASTSAVEDBY }}, + {"MACROBUTTON", {"Macro", FIELD_MACROBUTTON }}, + {"MERGEFIELD", {"Database", FIELD_MERGEFIELD }}, + {"MERGEREC", {"DatabaseNumberOfSet", FIELD_MERGEREC }}, +// {"MERGESEQ", {"", FIELD_MERGESEQ }}, + {"NEXT", {"DatabaseNextSet", FIELD_NEXT }}, + {"NEXTIF", {"DatabaseNextSet", FIELD_NEXTIF }}, + {"PAGE", {"PageNumber", FIELD_PAGE }}, + {"PAGEREF", {"GetReference", FIELD_PAGEREF }}, + {"REF", {"GetReference", FIELD_REF }}, + {"REVNUM", {"DocInfo.Revision", FIELD_REVNUM }}, + {"SAVEDATE", {"DocInfo.Change", FIELD_SAVEDATE }}, +// {"SECTION", {"", FIELD_SECTION }}, +// {"SECTIONPAGES", {"", FIELD_SECTIONPAGES }}, + {"SEQ", {"SetExpression", FIELD_SEQ }}, + {"SET", {"SetExpression", FIELD_SET }}, +// {"SKIPIF", {"", FIELD_SKIPIF }}, +// {"STYLEREF", {"", FIELD_STYLEREF }}, + {"SUBJECT", {"DocInfo.Subject", FIELD_SUBJECT }}, + {"SYMBOL", {"", FIELD_SYMBOL }}, + {"TEMPLATE", {"TemplateName", FIELD_TEMPLATE }}, + {"TIME", {"DateTime", FIELD_TIME }}, + {"TITLE", {"DocInfo.Title", FIELD_TITLE }}, + {"USERINITIALS", {"Author", FIELD_USERINITIALS }}, +// {"USERADDRESS", {"", FIELD_USERADDRESS }}, + {"USERNAME", {"Author", FIELD_USERNAME }}, + + + {"TOC", {"com.sun.star.text.ContentIndex", FIELD_TOC }}, + {"TC", {"com.sun.star.text.ContentIndexMark", FIELD_TC }}, + {"NUMCHARS", {"CharacterCount", FIELD_NUMCHARS }}, + {"NUMWORDS", {"WordCount", FIELD_NUMWORDS }}, + {"NUMPAGES", {"PageCount", FIELD_NUMPAGES }}, + {"INDEX", {"com.sun.star.text.DocumentIndex", FIELD_INDEX }}, + {"XE", {"com.sun.star.text.DocumentIndexMark", FIELD_XE }}, + {"BIBLIOGRAPHY",{"com.sun.star.text.Bibliography", FIELD_BIBLIOGRAPHY }}, + {"CITATION", {"com.sun.star.text.TextField.Bibliography",FIELD_CITATION }}, + }; + + return aFieldConversionMap; +} + +static const FieldConversionMap_t & lcl_GetEnhancedFieldConversion() +{ + static const FieldConversionMap_t aEnhancedFieldConversionMap = + { + {"FORMCHECKBOX", {"FormFieldmark", FIELD_FORMCHECKBOX}}, + {"FORMDROPDOWN", {"FormFieldmark", FIELD_FORMDROPDOWN}}, + {"FORMTEXT", {"Fieldmark", FIELD_FORMTEXT}}, + }; + + return aEnhancedFieldConversionMap; +} + +void DomainMapper_Impl::handleFieldSet + (const FieldContextPtr& pContext, + uno::Reference< uno::XInterface > const & xFieldInterface, + uno::Reference< beans::XPropertySet > const& xFieldProperties) +{ + OUString sVariable, sHint; + + sVariable = lcl_ExctractVariableAndHint(pContext->GetCommand(), sHint); + + // remove surrounding "" if exists + if(sHint.getLength() >= 2) + { + OUString sTmp = sHint.trim(); + if (sTmp.startsWith("\"") && sTmp.endsWith("\"")) + { + sHint = sTmp.copy(1, sTmp.getLength() - 2); + } + } + + // determine field master name + uno::Reference< beans::XPropertySet > xMaster = + FindOrCreateFieldMaster + ("com.sun.star.text.FieldMaster.SetExpression", sVariable ); + + // a set field is a string + xMaster->setPropertyValue(getPropertyName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING)); + + // attach the master to the field + uno::Reference< text::XDependentTextField > xDependentField + ( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + + xFieldProperties->setPropertyValue(getPropertyName(PROP_HINT), uno::makeAny( sHint )); + xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny( sHint )); + xFieldProperties->setPropertyValue(getPropertyName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING)); + + // Mimic MS Word behavior (hide the SET) + xFieldProperties->setPropertyValue(getPropertyName(PROP_IS_VISIBLE), uno::makeAny(false)); +} + +void DomainMapper_Impl::handleFieldAsk + (const FieldContextPtr& pContext, + uno::Reference< uno::XInterface > & xFieldInterface, + uno::Reference< beans::XPropertySet > const& xFieldProperties) +{ + //doesn the command contain a variable name? + OUString sVariable, sHint; + + sVariable = lcl_ExctractVariableAndHint( pContext->GetCommand(), + sHint ); + if(!sVariable.isEmpty()) + { + // determine field master name + uno::Reference< beans::XPropertySet > xMaster = + FindOrCreateFieldMaster + ("com.sun.star.text.FieldMaster.SetExpression", sVariable ); + // An ASK field is always a string of characters + xMaster->setPropertyValue(getPropertyName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING)); + + // attach the master to the field + uno::Reference< text::XDependentTextField > xDependentField + ( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + + // set input flag at the field + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_INPUT), uno::makeAny( true )); + // set the prompt + xFieldProperties->setPropertyValue( + getPropertyName(PROP_HINT), + uno::makeAny( sHint )); + xFieldProperties->setPropertyValue(getPropertyName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING)); + // The ASK has no field value to display + xFieldProperties->setPropertyValue(getPropertyName(PROP_IS_VISIBLE), uno::makeAny(false)); + } + else + { + //don't insert the field + //todo: maybe import a 'normal' input field here? + xFieldInterface = nullptr; + } +} + +/** + * Converts a Microsoft Word field formula into LibreOffice syntax + * @param input The Microsoft Word field formula, with no leading '=' sign + * @return An equivalent LibreOffice field formula + */ +OUString DomainMapper_Impl::convertFieldFormula(const OUString& input) { + + OUString listSeparator = m_pSettingsTable->GetListSeparator(); + + /* Replace logical condition functions with LO equivalent operators */ + OUString changed = input.replaceAll(" <> ", " NEQ "); + changed = changed.replaceAll(" <= ", " LEQ "); + changed = changed.replaceAll(" >= ", " GEQ "); + changed = changed.replaceAll(" = " , " EQ "); + changed = changed.replaceAll(" < " , " L "); + changed = changed.replaceAll(" > " , " G "); + + changed = changed.replaceAll("<>", " NEQ "); + changed = changed.replaceAll("<=", " LEQ "); + changed = changed.replaceAll(">=", " GEQ "); + changed = changed.replaceAll("=" , " EQ "); + changed = changed.replaceAll("<" , " L "); + changed = changed.replaceAll(">" , " G "); + + /* Replace function calls with infix keywords for AND(), OR(), and ROUND(). Nothing needs to be + * done for NOT(). This simple regex will work properly with most common cases. However, it may + * not work correctly when the arguments are nested subcalls to other functions, like + * ROUND(MIN(1,2),MAX(3,4)). See TDF#134765. */ + icu::ErrorCode status; + icu::UnicodeString usInput(changed.getStr()); + const uint32_t rMatcherFlags = UREGEX_CASE_INSENSITIVE; + OUString regex = "\\b(AND|OR|ROUND)\\s*\\(\\s*([^" + listSeparator + "]+)\\s*" + listSeparator + "\\s*([^)]+)\\s*\\)"; + icu::UnicodeString usRegex(regex.getStr()); + icu::RegexMatcher rmatch1(usRegex, usInput, rMatcherFlags, status); + usInput = rmatch1.replaceAll(icu::UnicodeString("(($2) $1 ($3))"), status); + + /* Assumes any remaining list separators separate arguments to functions that accept lists + * (SUM, MIN, MAX, MEAN, etc.) */ + usInput.findAndReplace(icu::UnicodeString(listSeparator.getStr()), "|"); + + /* Surround single cell references with angle brackets. + * If there is ever added a function name that ends with a digit, this regex will need to be revisited. */ + icu::RegexMatcher rmatch2("\\b([A-Z]{1,3}[0-9]+)\\b(?![(])", usInput, rMatcherFlags, status); + usInput = rmatch2.replaceAll(icu::UnicodeString("<$1>"), status); + + /* Cell references must be upper case */ + icu::RegexMatcher rmatch3("<[a-z]{1,3}[0-9]+>", usInput, rMatcherFlags, status); + icu::UnicodeString replacedCellRefs; + while (rmatch3.find(status) && status.isSuccess()) { + rmatch3.appendReplacement(replacedCellRefs, rmatch3.group(status).toUpper(), status); + } + rmatch3.appendTail(replacedCellRefs); + + /* Fix up cell ranges */ + icu::RegexMatcher rmatch4("<([A-Z]{1,3}[0-9]+)>:<([A-Z]{1,3}[0-9]+)>", replacedCellRefs, rMatcherFlags, status); + usInput = rmatch4.replaceAll(icu::UnicodeString("<$1:$2>"), status); + + /* Fix up user defined names */ + icu::RegexMatcher rmatch5("DEFINED\\s*\\(<([A-Z]+[0-9]+)>\\)", usInput, rMatcherFlags, status); + usInput = rmatch5.replaceAll(icu::UnicodeString("DEFINED($1)"), status); + + return OUString(usInput.getTerminatedBuffer()); +} + +void DomainMapper_Impl::handleFieldFormula + (const FieldContextPtr& pContext, + uno::Reference< beans::XPropertySet > const& xFieldProperties) +{ + OUString command = pContext->GetCommand().trim(); + + // Remove number formatting from \# to end of command + // TODO: handle custom number formatting + sal_Int32 delimPos = command.indexOf("\\#"); + if (delimPos != -1) + { + command = command.replaceAt(delimPos, command.getLength() - delimPos, "").trim(); + } + + // command must contains = and at least another char + if (command.getLength() < 2) + return; + + // we don't copy the = symbol from the command + OUString formula = convertFieldFormula(command.copy(1)); + + // grab-bag the original and converted formula + if (getTableManager().isInTable()) + { + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(PROP_CELL_FORMULA, uno::makeAny(command.copy(1)), true, CELL_GRAB_BAG); + pPropMap->Insert(PROP_CELL_FORMULA_CONVERTED, uno::makeAny(formula), true, CELL_GRAB_BAG); + getTableManager().cellProps(pPropMap); + } + xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny(formula)); + xFieldProperties->setPropertyValue(getPropertyName(PROP_NUMBER_FORMAT), uno::makeAny(sal_Int32(0))); + xFieldProperties->setPropertyValue("IsShowFormula", uno::makeAny(false)); +} + +void DomainMapper_Impl::handleRubyEQField( const FieldContextPtr& pContext) +{ + const OUString & rCommand(pContext->GetCommand()); + sal_Int32 nIndex = 0, nEnd = 0; + RubyInfo aInfo ; + nIndex = rCommand.indexOf("\\* jc" ); + if (nIndex != -1) + { + nIndex += 5; + sal_uInt32 nJc = rCommand.getToken(0, ' ',nIndex).toInt32(); + const sal_Int32 aRubyAlignValues[] = + { + NS_ooxml::LN_Value_ST_RubyAlign_center, + NS_ooxml::LN_Value_ST_RubyAlign_distributeLetter, + NS_ooxml::LN_Value_ST_RubyAlign_distributeSpace, + NS_ooxml::LN_Value_ST_RubyAlign_left, + NS_ooxml::LN_Value_ST_RubyAlign_right, + NS_ooxml::LN_Value_ST_RubyAlign_rightVertical, + }; + aInfo.nRubyAlign = aRubyAlignValues[(nJc nIndex) + { + aInfo.sRubyText = sPart1.copy(nIndex+1,nEnd-nIndex-1); + } + + PropertyMapPtr pRubyContext(new PropertyMap()); + pRubyContext->InsertProps(GetTopContext()); + if (aInfo.nHps > 0) + { + double fVal = double(aInfo.nHps) / 2.; + uno::Any aVal = uno::makeAny( fVal ); + + pRubyContext->Insert(PROP_CHAR_HEIGHT, aVal); + pRubyContext->Insert(PROP_CHAR_HEIGHT_ASIAN, aVal); + } + PropertyValueVector_t aProps = comphelper::sequenceToContainer< PropertyValueVector_t >(pRubyContext->GetPropertyValues()); + aInfo.sRubyStyle = m_rDMapper.getOrCreateCharStyle(aProps, /*bAlwaysCreate=*/false); + PropertyMapPtr pCharContext(new PropertyMap()); + if (m_pLastCharacterContext) + pCharContext->InsertProps(m_pLastCharacterContext); + pCharContext->InsertProps(pContext->getProperties()); + pCharContext->Insert(PROP_RUBY_TEXT, uno::makeAny( aInfo.sRubyText ) ); + pCharContext->Insert(PROP_RUBY_ADJUST, uno::makeAny(static_cast(ConversionHelper::convertRubyAlign(aInfo.nRubyAlign)))); + if ( aInfo.nRubyAlign == NS_ooxml::LN_Value_ST_RubyAlign_rightVertical ) + pCharContext->Insert(PROP_RUBY_POSITION, uno::makeAny(css::text::RubyPosition::INTER_CHARACTER)); + pCharContext->Insert(PROP_RUBY_STYLE, uno::makeAny(aInfo.sRubyStyle)); + appendTextPortion(sPart2, pCharContext); + +} + +void DomainMapper_Impl::handleAutoNum + (const FieldContextPtr& pContext, + uno::Reference< uno::XInterface > const & xFieldInterface, + uno::Reference< beans::XPropertySet > const& xFieldProperties) +{ + //create a sequence field master "AutoNr" + uno::Reference< beans::XPropertySet > xMaster = + FindOrCreateFieldMaster + ("com.sun.star.text.FieldMaster.SetExpression", + "AutoNr"); + + xMaster->setPropertyValue( getPropertyName(PROP_SUB_TYPE), + uno::makeAny(text::SetVariableType::SEQUENCE)); + + //apply the numbering type + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + // attach the master to the field + uno::Reference< text::XDependentTextField > xDependentField + ( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); +} + +void DomainMapper_Impl::handleAuthor + (OUString const& rFirstParam, + uno::Reference< beans::XPropertySet > const& xFieldProperties, + FieldId eFieldId ) +{ + if ( eFieldId != FIELD_USERINITIALS ) + xFieldProperties->setPropertyValue + ( getPropertyName(PROP_FULL_NAME), uno::makeAny( true )); + + if (!rFirstParam.isEmpty()) + { + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), + uno::makeAny( true )); + //PROP_CURRENT_PRESENTATION is set later anyway + } +} + + void DomainMapper_Impl::handleDocProperty + (const FieldContextPtr& pContext, + OUString const& rFirstParam, + uno::Reference< uno::XInterface > & xFieldInterface) +{ + //some docproperties should be imported as document statistic fields, some as DocInfo fields + //others should be user fields + if (rFirstParam.isEmpty()) + return; + + constexpr sal_uInt8 SET_ARABIC = 0x01; + constexpr sal_uInt8 SET_DATE = 0x04; + struct DocPropertyMap + { + const sal_Char* pDocPropertyName; + const sal_Char* pServiceName; + sal_uInt8 nFlags; + }; + static const DocPropertyMap aDocProperties[] = + { + {"CreateTime", "DocInfo.CreateDateTime", SET_DATE}, + {"Characters", "CharacterCount", SET_ARABIC}, + {"Comments", "DocInfo.Description", 0}, + {"Keywords", "DocInfo.KeyWords", 0}, + {"LastPrinted", "DocInfo.PrintDateTime", 0}, + {"LastSavedBy", "DocInfo.ChangeAuthor", 0}, + {"LastSavedTime", "DocInfo.ChangeDateTime", SET_DATE}, + {"Paragraphs", "ParagraphCount", SET_ARABIC}, + {"RevisionNumber", "DocInfo.Revision", 0}, + {"Subject", "DocInfo.Subject", 0}, + {"Template", "TemplateName", 0}, + {"Title", "DocInfo.Title", 0}, + {"TotalEditingTime", "DocInfo.EditTime", 0}, + {"Words", "WordCount", SET_ARABIC} + + //other available DocProperties: + //Bytes, Category, CharactersWithSpaces, Company + //HyperlinkBase, + //Lines, Manager, NameofApplication, ODMADocId, Pages, + //Security, + }; + uno::Reference xDocumentPropertiesSupplier(m_xTextDocument, uno::UNO_QUERY); + uno::Reference xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); + uno::Reference xUserDefinedProps(xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW); + uno::Reference xPropertySetInfo = xUserDefinedProps->getPropertySetInfo(); + //search for a field mapping + OUString sFieldServiceName; + size_t nMap = 0; + for( ; nMap < SAL_N_ELEMENTS(aDocProperties); ++nMap ) + { + if ((rFirstParam.equalsAscii(aDocProperties[nMap].pDocPropertyName)) && (!xPropertySetInfo->hasPropertyByName(rFirstParam))) + { + sFieldServiceName = + OUString::createFromAscii + (aDocProperties[nMap].pServiceName); + break; + } + } + OUString sServiceName("com.sun.star.text.TextField."); + bool bIsCustomField = false; + if(sFieldServiceName.isEmpty()) + { + //create a custom property field + sServiceName += "DocInfo.Custom"; + bIsCustomField = true; + } + else + { + sServiceName += sFieldServiceName; + } + if (m_xTextFactory.is()) + xFieldInterface = m_xTextFactory->createInstance(sServiceName); + uno::Reference xFieldProperties( xFieldInterface, uno::UNO_QUERY_THROW); + if( bIsCustomField ) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NAME), uno::makeAny(rFirstParam)); + pContext->SetCustomField( xFieldProperties ); + } + else + { + if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC)) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( style::NumberingType::ARABIC )); + else if(0 != (aDocProperties[nMap].nFlags & SET_DATE)) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_DATE), + uno::makeAny( true )); + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + } + } +} + +static uno::Sequence< beans::PropertyValues > lcl_createTOXLevelHyperlinks( bool bHyperlinks, const OUString& sChapterNoSeparator, + const uno::Sequence< beans::PropertyValues >& aLevel ) +{ + //create a copy of the level and add two new entries - hyperlink start and end + bool bChapterNoSeparator = !sChapterNoSeparator.isEmpty(); + sal_Int32 nAdd = (bHyperlinks && bChapterNoSeparator) ? 4 : 2; + uno::Sequence< beans::PropertyValues > aNewLevel( aLevel.getLength() + nAdd); + beans::PropertyValues* pNewLevel = aNewLevel.getArray(); + if( bHyperlinks ) + { + beans::PropertyValues aHyperlink(1); + aHyperlink[0].Name = getPropertyName( PROP_TOKEN_TYPE ); + aHyperlink[0].Value <<= getPropertyName( PROP_TOKEN_HYPERLINK_START ); + pNewLevel[0] = aHyperlink; + aHyperlink[0].Value <<= getPropertyName( PROP_TOKEN_HYPERLINK_END ); + pNewLevel[aNewLevel.getLength() -1] = aHyperlink; + } + if( bChapterNoSeparator ) + { + beans::PropertyValues aChapterNo(2); + aChapterNo[0].Name = getPropertyName( PROP_TOKEN_TYPE ); + aChapterNo[0].Value <<= getPropertyName( PROP_TOKEN_CHAPTER_INFO ); + aChapterNo[1].Name = getPropertyName( PROP_CHAPTER_FORMAT ); + //todo: is ChapterFormat::Number correct? + aChapterNo[1].Value <<= sal_Int16(text::ChapterFormat::NUMBER); + pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 4 : 2) ] = aChapterNo; + + beans::PropertyValues aChapterSeparator(2); + aChapterSeparator[0].Name = getPropertyName( PROP_TOKEN_TYPE ); + aChapterSeparator[0].Value <<= getPropertyName( PROP_TOKEN_TEXT ); + aChapterSeparator[1].Name = getPropertyName( PROP_TEXT ); + aChapterSeparator[1].Value <<= sChapterNoSeparator; + pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator; + } + //copy the 'old' entries except the last (page no) + std::copy(aLevel.begin(), std::prev(aLevel.end()), std::next(aNewLevel.begin())); + //copy page no entry (last or last but one depending on bHyperlinks + sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3); + pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1]; + + return aNewLevel; +} + +/// Returns title of the TOC placed in paragraph(s) before TOC field inside STD-frame +OUString DomainMapper_Impl::extractTocTitle() +{ + if (!m_xSdtEntryStart.is()) + return OUString(); + + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if(!xTextAppend.is()) + return OUString(); + + // try-catch was added in the same way as inside appendTextSectionAfter() + try + { + uno::Reference xCursor(xTextAppend->createTextCursorByRange(m_xSdtEntryStart), uno::UNO_QUERY_THROW); + if (!xCursor.is()) + return OUString(); + + //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls + xCursor->gotoStartOfParagraph( false ); + if (m_aTextAppendStack.top().xInsertPosition.is()) + xCursor->gotoRange( m_aTextAppendStack.top().xInsertPosition, true ); + else + xCursor->gotoEnd( true ); + + // the paragraph after this new section might have been already inserted + OUString sResult = xCursor->getString(); + if (sResult.endsWith(SAL_NEWLINE_STRING)) + sResult = sResult.copy(0, sResult.getLength() - SAL_N_ELEMENTS(SAL_NEWLINE_STRING) + 1); + + return sResult; + } + catch(const uno::Exception&) + { + } + + return OUString(); +} + +css::uno::Reference +DomainMapper_Impl::StartIndexSectionChecked(const OUString& sServiceName) +{ + if (m_bParaChanged) + { + finishParagraph(GetTopContextOfType(CONTEXT_PARAGRAPH), false); // resets m_bParaChanged + PopProperties(CONTEXT_PARAGRAPH); + PushProperties(CONTEXT_PARAGRAPH); + SetIsFirstRun(true); + // The first paragraph of the index that is continuation of just finished one needs to be + // removed when finished (unless more content will arrive, which will set m_bParaChanged) + m_bRemoveThisParagraph = true; + } + const auto& xTextAppend = GetTopTextAppend(); + const auto xTextRange = xTextAppend->getEnd(); + const auto xRet = createSectionForRange(xTextRange, xTextRange, sServiceName, false); + if (!m_aTextAppendStack.top().xInsertPosition) + { + try + { + m_bStartedTOC = true; + uno::Reference xTOCTextCursor + = xTextRange->getText()->createTextCursor(); + assert(xTOCTextCursor.is()); + xTOCTextCursor->gotoEnd(false); + m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor)); + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", + "DomainMapper_Impl::StartIndexSectionChecked:"); + } + } + return xRet; +} + +void DomainMapper_Impl::handleToc + (const FieldContextPtr& pContext, + const OUString & sTOCServiceName) +{ + OUString sValue; + if (IsInHeaderFooter()) + m_bStartTOCHeaderFooter = true; + bool bTableOfFigures = false; + bool bHyperlinks = false; + bool bFromOutline = false; + bool bFromEntries = false; + bool bHideTabLeaderPageNumbers = false ; + bool bIsTabEntry = false ; + bool bNewLine = false ; + bool bParagraphOutlineLevel = false; + + sal_Int16 nMaxLevel = 10; + OUString sTemplate; + OUString sChapterNoSeparator; + OUString sFigureSequence; + uno::Reference< beans::XPropertySet > xTOC; + OUString aBookmarkName; + +// \a Builds a table of figures but does not include the captions's label and number + if( lcl_FindInCommand( pContext->GetCommand(), 'a', sValue )) + { //make it a table of figures + bTableOfFigures = true; + } +// \b Uses a bookmark to specify area of document from which to build table of contents + if( lcl_FindInCommand( pContext->GetCommand(), 'b', sValue )) + { + aBookmarkName = sValue.trim().replaceAll("\"",""); + } + if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue )) +// \c Builds a table of figures of the given label + { + //todo: sValue contains the label's name + bTableOfFigures = true; + sFigureSequence = sValue.trim(); + sFigureSequence = sFigureSequence.replaceAll("\"", "").replaceAll("'",""); + } +// \d Defines the separator between sequence and page numbers + if( lcl_FindInCommand( pContext->GetCommand(), 'd', sValue )) + { + //todo: insert the chapter number into each level and insert the separator additionally + sChapterNoSeparator = sValue; + } +// \f Builds a table of contents using TC entries instead of outline levels + if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue )) + { + //todo: sValue can contain a TOC entry identifier - use unclear + bFromEntries = true; + } +// \h Hyperlinks the entries and page numbers within the table of contents + if( lcl_FindInCommand( pContext->GetCommand(), 'h', sValue )) + { + //todo: make all entries to hyperlinks + bHyperlinks = true; + } +// \l Defines the TC entries field level used to build a table of contents +// if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue )) +// { + //todo: entries can only be included completely +// } +// \n Builds a table of contents or a range of entries, such as 1-9 in a table of contents without page numbers +// if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue )) +// { + //todo: what does the description mean? +// } +// \o Builds a table of contents by using outline levels instead of TC entries + if( lcl_FindInCommand( pContext->GetCommand(), 'o', sValue )) + { + bFromOutline = true; + if (sValue.isEmpty()) + nMaxLevel = WW_OUTLINE_MAX; + else + { + sal_Int32 nIndex = 0; + sValue.getToken( 0, '-', nIndex ); + nMaxLevel = static_cast(nIndex != -1 ? sValue.copy(nIndex).toInt32() : 0); + } + } +// \p Defines the separator between the table entry and its page number +// \s Builds a table of contents by using a sequence type +// \t Builds a table of contents by using style names other than the standard outline styles + if( lcl_FindInCommand( pContext->GetCommand(), 't', sValue )) + { + OUString sToken = sValue.getToken(1, '"'); + sTemplate = sToken.isEmpty() ? sValue : sToken; + } +// \u Builds a table of contents by using the applied paragraph outline level + if( lcl_FindInCommand( pContext->GetCommand(), 'u', sValue )) + { + bFromOutline = true; + bParagraphOutlineLevel = true; + //todo: what doesn 'the applied paragraph outline level' refer to? + } +// \w Preserve tab characters within table entries + if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue )) + { + bIsTabEntry = true ; + } +// \x Preserve newline characters within table entries + if( lcl_FindInCommand( pContext->GetCommand(), 'x', sValue )) + { + bNewLine = true ; + } +// \z Hides page numbers within the table of contents when shown in Web Layout View + if( lcl_FindInCommand( pContext->GetCommand(), 'z', sValue )) + { + bHideTabLeaderPageNumbers = true ; + } + + //if there's no option then it should be created from outline + if( !bFromOutline && !bFromEntries && sTemplate.isEmpty() ) + bFromOutline = true; + + const OUString aTocTitle = extractTocTitle(); + + if (m_xTextFactory.is() && ! m_aTextAppendStack.empty()) + { + const auto& xTextAppend = GetTopTextAppend(); + if (aTocTitle.isEmpty() || bTableOfFigures) + { + // reset marker of the TOC title + m_xSdtEntryStart.clear(); + + // Create section before setting m_bStartTOC: finishing paragraph + // inside StartIndexSectionChecked could do the wrong thing otherwise + xTOC = StartIndexSectionChecked(bTableOfFigures ? "com.sun.star.text.IllustrationsIndex" + : sTOCServiceName); + + const auto xTextCursor = xTextAppend->getText()->createTextCursor(); + if (xTextCursor) + xTextCursor->gotoEnd(false); + xTOCMarkerCursor = xTextCursor; + } + else + { + // create TOC section + css::uno::Reference xTextRangeEndOfTocHeader = GetTopTextAppend()->getEnd(); + xTOC = createSectionForRange(m_xSdtEntryStart, xTextRangeEndOfTocHeader, sTOCServiceName, false); + + // init [xTOCMarkerCursor] + uno::Reference< text::XText > xText = xTextAppend->getText(); + uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); + xTOCMarkerCursor = xCrsr; + + // create header of the TOC with the TOC title inside + const OUString aObjectType("com.sun.star.text.IndexHeaderSection"); + createSectionForRange(m_xSdtEntryStart, xTextRangeEndOfTocHeader, aObjectType, true); + } + } + + m_bStartTOC = true; + + if (xTOC.is()) + xTOC->setPropertyValue(getPropertyName( PROP_TITLE ), uno::makeAny(aTocTitle)); + + if (!aBookmarkName.isEmpty()) + xTOC->setPropertyValue(getPropertyName(PROP_TOC_BOOKMARK), uno::makeAny(aBookmarkName)); + if( !bTableOfFigures && xTOC.is() ) + { + xTOC->setPropertyValue( getPropertyName( PROP_LEVEL ), uno::makeAny( nMaxLevel ) ); + xTOC->setPropertyValue( getPropertyName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline )); + xTOC->setPropertyValue( getPropertyName( PROP_CREATE_FROM_MARKS ), uno::makeAny( bFromEntries )); + xTOC->setPropertyValue( getPropertyName( PROP_HIDE_TAB_LEADER_AND_PAGE_NUMBERS ), uno::makeAny( bHideTabLeaderPageNumbers )); + xTOC->setPropertyValue( getPropertyName( PROP_TAB_IN_TOC ), uno::makeAny( bIsTabEntry )); + xTOC->setPropertyValue( getPropertyName( PROP_TOC_NEW_LINE ), uno::makeAny( bNewLine )); + xTOC->setPropertyValue( getPropertyName( PROP_TOC_PARAGRAPH_OUTLINE_LEVEL ), uno::makeAny( bParagraphOutlineLevel )); + if( !sTemplate.isEmpty() ) + { + //the string contains comma separated the names and related levels + //like: "Heading 1,1,Heading 2,2" + TOCStyleMap aMap; + sal_Int32 nLevel; + sal_Int32 nPosition = 0; + while( nPosition >= 0) + { + OUString sStyleName = sTemplate.getToken( 0, ',', nPosition ); + //empty tokens should be skipped + while( sStyleName.isEmpty() && nPosition > 0 ) + sStyleName = sTemplate.getToken( 0, ',', nPosition ); + nLevel = sTemplate.getToken( 0, ',', nPosition ).toInt32(); + if( !nLevel ) + nLevel = 1; + if( !sStyleName.isEmpty() ) + aMap.emplace(nLevel, sStyleName); + } + uno::Reference< container::XIndexReplace> xParaStyles; + xTOC->getPropertyValue(getPropertyName(PROP_LEVEL_PARAGRAPH_STYLES)) >>= xParaStyles; + for( nLevel = 1; nLevel < 10; ++nLevel) + { + sal_Int32 nLevelCount = aMap.count( nLevel ); + if( nLevelCount ) + { + TOCStyleMap::iterator aTOCStyleIter = aMap.find( nLevel ); + + uno::Sequence< OUString> aStyles( nLevelCount ); + for ( sal_Int32 nStyle = 0; nStyle < nLevelCount; ++nStyle, ++aTOCStyleIter ) + { + aStyles[nStyle] = aTOCStyleIter->second; + } + xParaStyles->replaceByIndex(nLevel - 1, uno::makeAny(aStyles)); + } + } + xTOC->setPropertyValue(getPropertyName(PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES), uno::makeAny( true )); + + } + if(bHyperlinks || !sChapterNoSeparator.isEmpty()) + { + uno::Reference< container::XIndexReplace> xLevelFormats; + xTOC->getPropertyValue(getPropertyName(PROP_LEVEL_FORMAT)) >>= xLevelFormats; + sal_Int32 nLevelCount = xLevelFormats->getCount(); + //start with level 1, 0 is the header level + for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel) + { + uno::Sequence< beans::PropertyValues > aLevel; + xLevelFormats->getByIndex( nLevel ) >>= aLevel; + + uno::Sequence< beans::PropertyValues > aNewLevel = lcl_createTOXLevelHyperlinks( + bHyperlinks, sChapterNoSeparator, + aLevel ); + xLevelFormats->replaceByIndex( nLevel, uno::makeAny( aNewLevel ) ); + } + } + } + else if (bTableOfFigures && xTOC.is()) + { + if (!sFigureSequence.isEmpty()) + xTOC->setPropertyValue(getPropertyName(PROP_LABEL_CATEGORY), + uno::makeAny(sFigureSequence)); + + if ( bHyperlinks ) + { + uno::Reference< container::XIndexReplace> xLevelFormats; + xTOC->getPropertyValue(getPropertyName(PROP_LEVEL_FORMAT)) >>= xLevelFormats; + uno::Sequence< beans::PropertyValues > aLevel; + xLevelFormats->getByIndex( 1 ) >>= aLevel; + + uno::Sequence< beans::PropertyValues > aNewLevel = lcl_createTOXLevelHyperlinks( + bHyperlinks, sChapterNoSeparator, + aLevel ); + xLevelFormats->replaceByIndex( 1, uno::makeAny( aNewLevel ) ); + } + } + pContext->SetTOC( xTOC ); + m_bParaHadField = false; +} + +uno::Reference DomainMapper_Impl::createSectionForRange( + uno::Reference< css::text::XTextRange > xStart, + uno::Reference< css::text::XTextRange > xEnd, + const OUString & sObjectType, + bool stepLeft) +{ + if (!xStart.is()) + return uno::Reference(); + if (!xEnd.is()) + return uno::Reference(); + + uno::Reference< beans::XPropertySet > xRet; + if (m_aTextAppendStack.empty()) + return xRet; + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if(xTextAppend.is()) + { + try + { + uno::Reference< text::XParagraphCursor > xCursor( + xTextAppend->createTextCursorByRange( xStart ), uno::UNO_QUERY_THROW); + //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls + xCursor->gotoStartOfParagraph( false ); + xCursor->gotoRange( xEnd, true ); + //the paragraph after this new section is already inserted + if (stepLeft) + xCursor->goLeft(1, true); + uno::Reference< text::XTextContent > xSection( m_xTextFactory->createInstance(sObjectType), uno::UNO_QUERY_THROW ); + xSection->attach( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW) ); + xRet.set(xSection, uno::UNO_QUERY ); + } + catch(const uno::Exception&) + { + } + } + + return xRet; +} + +void DomainMapper_Impl::handleBibliography + (const FieldContextPtr& pContext, + const OUString & sTOCServiceName) +{ + if (m_aTextAppendStack.empty()) + { + // tdf#130214: a workaround to avoid crash on import errors + SAL_WARN("writerfilter.dmapper", "no text append stack"); + return; + } + // Create section before setting m_bStartTOC and m_bStartBibliography: finishing paragraph + // inside StartIndexSectionChecked could do the wrong thing otherwise + const auto xTOC = StartIndexSectionChecked(sTOCServiceName); + m_bStartTOC = true; + m_bStartBibliography = true; + + if (xTOC.is()) + xTOC->setPropertyValue(getPropertyName( PROP_TITLE ), uno::makeAny(OUString())); + + pContext->SetTOC( xTOC ); + m_bParaHadField = false; + + uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY ); + appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() ); +} + +void DomainMapper_Impl::handleIndex + (const FieldContextPtr& pContext, + const OUString & sTOCServiceName) +{ + // Create section before setting m_bStartTOC and m_bStartIndex: finishing paragraph + // inside StartIndexSectionChecked could do the wrong thing otherwise + const auto xTOC = StartIndexSectionChecked(sTOCServiceName); + + m_bStartTOC = true; + m_bStartIndex = true; + OUString sValue; + OUString sIndexEntryType = "I"; // Default value for field flag '\f' is 'I'. + + if (xTOC.is()) + { + xTOC->setPropertyValue(getPropertyName( PROP_TITLE ), uno::makeAny(OUString())); + + if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue )) + { + xTOC->setPropertyValue("IsCommaSeparated", uno::makeAny(true)); + } + if( lcl_FindInCommand( pContext->GetCommand(), 'h', sValue )) + { + xTOC->setPropertyValue("UseAlphabeticalSeparators", uno::makeAny(true)); + } + if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue )) + { + if(!sValue.isEmpty()) + sIndexEntryType = sValue ; + xTOC->setPropertyValue(getPropertyName( PROP_INDEX_ENTRY_TYPE ), uno::makeAny(sIndexEntryType)); + } + } + pContext->SetTOC( xTOC ); + m_bParaHadField = false; + + uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY ); + appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() ); + + if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue )) + { + sValue = sValue.replaceAll("\"", ""); + uno::Reference xTextColumns; + xTOC->getPropertyValue(getPropertyName( PROP_TEXT_COLUMNS )) >>= xTextColumns; + if (xTextColumns.is()) + { + xTextColumns->setColumnCount( sValue.toInt32() ); + xTOC->setPropertyValue( getPropertyName( PROP_TEXT_COLUMNS ), uno::makeAny( xTextColumns ) ); + } + } +} + +static auto InsertFieldmark(std::stack & rTextAppendStack, + uno::Reference const& xFormField, + uno::Reference const& xStartRange, + std::optional const oFieldId) -> void +{ + uno::Reference const xTextContent(xFormField, uno::UNO_QUERY_THROW); + uno::Reference const& xTextAppend(rTextAppendStack.top().xTextAppend); + uno::Reference const xCursor = + xTextAppend->createTextCursorByRange(xStartRange); + if (rTextAppendStack.top().xInsertPosition.is()) + { + uno::Reference const xCompare( + rTextAppendStack.top().xTextAppend, + uno::UNO_QUERY); + if (xCompare->compareRegionStarts(xStartRange, rTextAppendStack.top().xInsertPosition) < 0) + { + SAL_WARN("writerfilter.dmapper", "invalid field mark positions"); + assert(false); + } + xCursor->gotoRange(rTextAppendStack.top().xInsertPosition, true); + } + else + { + xCursor->gotoEnd(true); + } + xTextAppend->insertTextContent(xCursor, xTextContent, true); + if (oFieldId + && (oFieldId == FIELD_FORMCHECKBOX || oFieldId == FIELD_FORMDROPDOWN)) + { + return; // only a single CH_TXT_ATR_FORMELEMENT! + } + // problem: the fieldmark must be inserted in CloseFieldCommand(), because + // attach() takes 2 positions, not 3! + // FAIL: AppendTextNode() ignores the content index! + // plan B: insert a spurious paragraph break now and join + // it in PopFieldContext()! + xCursor->gotoRange(xTextContent->getAnchor()->getEnd(), false); + xCursor->goLeft(1, false); // skip CH_TXT_ATR_FIELDEND + xTextAppend->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, false); + xCursor->goLeft(1, false); // back to previous paragraph + rTextAppendStack.push(TextAppendContext(xTextAppend, xCursor)); +} + +static auto PopFieldmark(std::stack & rTextAppendStack, + uno::Reference const& xCursor, + std::optional const oFieldId) -> void +{ + if (oFieldId + && (oFieldId == FIELD_FORMCHECKBOX || oFieldId == FIELD_FORMDROPDOWN)) + { + return; // only a single CH_TXT_ATR_FORMELEMENT! + } + xCursor->gotoRange(rTextAppendStack.top().xInsertPosition, false); + xCursor->goRight(1, true); + xCursor->setString(OUString()); // undo SplitNode from CloseFieldCommand() + // note: paragraph properties will be overwritten + // by finishParagraph() anyway so ignore here + rTextAppendStack.pop(); +} + +void DomainMapper_Impl::CloseFieldCommand() +{ + if(m_bDiscardHeaderFooter) + return; +#ifdef DBG_UTIL + TagLogger::getInstance().element("closeFieldCommand"); +#endif + + FieldContextPtr pContext; + if(!m_aFieldStack.empty()) + pContext = m_aFieldStack.back(); + OSL_ENSURE( pContext.get(), "no field context available"); + if( pContext ) + { + m_bSetUserFieldContent = false; + m_bSetCitation = false; + m_bSetDateValue = false; + const FieldConversionMap_t& aFieldConversionMap = lcl_GetFieldConversion(); + + try + { + uno::Reference< uno::XInterface > xFieldInterface; + + const auto& [sType, vArguments, vSwitches]{ splitFieldCommand(pContext->GetCommand()) }; + (void)vSwitches; + OUString const sFirstParam(vArguments.empty() ? OUString() : vArguments.front()); + + // apply font size to the form control + if (!m_aTextAppendStack.empty() && m_pLastCharacterContext && ( m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT) || m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME ))) + { + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is()) + { + uno::Reference< text::XTextCursor > xCrsr = xTextAppend->getText()->createTextCursor(); + if (xCrsr.is()) + { + xCrsr->gotoEnd(false); + uno::Reference< beans::XPropertySet > xProp( xCrsr, uno::UNO_QUERY ); + if (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT)) + { + xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT), m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT)->second); + if (m_pLastCharacterContext->isSet(PROP_CHAR_HEIGHT_COMPLEX)) + xProp->setPropertyValue(getPropertyName(PROP_CHAR_HEIGHT_COMPLEX), m_pLastCharacterContext->getProperty(PROP_CHAR_HEIGHT_COMPLEX)->second); + } + if (m_pLastCharacterContext->isSet(PROP_CHAR_FONT_NAME)) + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), m_pLastCharacterContext->getProperty(PROP_CHAR_FONT_NAME)->second); + } + } + } + + FieldConversionMap_t::const_iterator const aIt = aFieldConversionMap.find(sType); + if (aIt != aFieldConversionMap.end() + && (!m_bForceGenericFields + // these need to convert ffData to properties... + || (aIt->second.eFieldId == FIELD_FORMCHECKBOX) + || (aIt->second.eFieldId == FIELD_FORMDROPDOWN) + || (aIt->second.eFieldId == FIELD_FORMTEXT))) + { + pContext->SetFieldId(aIt->second.eFieldId); + bool bCreateEnhancedField = false; + uno::Reference< beans::XPropertySet > xFieldProperties; + bool bCreateField = true; + switch (aIt->second.eFieldId) + { + case FIELD_HYPERLINK: + case FIELD_DOCPROPERTY: + case FIELD_TOC: + case FIELD_INDEX: + case FIELD_XE: + case FIELD_BIBLIOGRAPHY: + case FIELD_CITATION: + case FIELD_TC: + case FIELD_EQ: + case FIELD_INCLUDEPICTURE: + case FIELD_SYMBOL: + case FIELD_GOTOBUTTON: + bCreateField = false; + break; + case FIELD_FORMCHECKBOX : + case FIELD_FORMTEXT : + case FIELD_FORMDROPDOWN : + { + // If we use 'enhanced' fields then FIELD_FORMCHECKBOX, + // FIELD_FORMTEXT & FIELD_FORMDROPDOWN are treated specially + if ( m_bUsingEnhancedFields ) + { + bCreateField = false; + bCreateEnhancedField = true; + } + // for non enhanced fields checkboxes are displayed + // as an awt control not a field + else if ( aIt->second.eFieldId == FIELD_FORMCHECKBOX ) + bCreateField = false; + break; + } + default: + { + FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); + if (pOuter) + { + if (!IsFieldNestingAllowed(pOuter, m_aFieldStack.back())) + { + // Parent field can't host this child field: don't create a child field + // in this case. + bCreateField = false; + } + } + break; + } + } + if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) ) + { + bCreateField = false; + } + + if( bCreateField || bCreateEnhancedField ) + { + //add the service prefix + OUString sServiceName("com.sun.star.text."); + if ( bCreateEnhancedField ) + { + const FieldConversionMap_t& aEnhancedFieldConversionMap = lcl_GetEnhancedFieldConversion(); + FieldConversionMap_t::const_iterator aEnhancedIt = + aEnhancedFieldConversionMap.find(sType); + if ( aEnhancedIt != aEnhancedFieldConversionMap.end()) + sServiceName += OUString::createFromAscii(aEnhancedIt->second.cFieldServiceName ); + } + else + { + sServiceName += "TextField." + OUString::createFromAscii(aIt->second.cFieldServiceName ); + } + +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("fieldService"); + TagLogger::getInstance().chars(sServiceName); + TagLogger::getInstance().endElement(); +#endif + + if (m_xTextFactory.is()) + { + xFieldInterface = m_xTextFactory->createInstance(sServiceName); + xFieldProperties.set( xFieldInterface, uno::UNO_QUERY_THROW); + } + } + switch( aIt->second.eFieldId ) + { + case FIELD_ADDRESSBLOCK: break; + case FIELD_ADVANCE : break; + case FIELD_ASK : + handleFieldAsk(pContext, xFieldInterface, xFieldProperties); + break; + case FIELD_AUTONUM : + case FIELD_AUTONUMLGL : + case FIELD_AUTONUMOUT : + handleAutoNum(pContext, xFieldInterface, xFieldProperties); + break; + case FIELD_AUTHOR : + case FIELD_USERNAME : + case FIELD_USERINITIALS : + handleAuthor(sFirstParam, + xFieldProperties, + aIt->second.eFieldId); + break; + case FIELD_DATE: + if (xFieldProperties.is()) + { + // Get field fixed property from the context handler + if (pContext->IsFieldLocked()) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_FIXED), + uno::makeAny( true )); + m_bSetDateValue = true; + } + else + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_FIXED), + uno::makeAny( false )); + + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_DATE), + uno::makeAny( true )); + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + } + break; + case FIELD_COMMENTS : + { + // OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" COMMENTS") ); + // A parameter with COMMENTS shouldn't set fixed + // ( or at least the binary filter doesn't ) + // If we set fixed then we won't export a field cmd. + // Additionally the para in COMMENTS is more like an + // instruction to set the document property comments + // with the param ( e.g. each COMMENT with a param will + // overwrite the Comments document property + // #TODO implement the above too + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), uno::makeAny( false )); + //PROP_CURRENT_PRESENTATION is set later anyway + } + break; + case FIELD_CREATEDATE : + { + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_DATE ), uno::makeAny( true )); + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + } + break; + case FIELD_DOCPROPERTY : + handleDocProperty(pContext, sFirstParam, + xFieldInterface); + break; + case FIELD_DOCVARIABLE : + { + //create a user field and type + uno::Reference< beans::XPropertySet > xMaster = + FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.User", sFirstParam); + uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + m_bSetUserFieldContent = true; + } + break; + case FIELD_EDITTIME : + //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + break; + case FIELD_EQ: + { + OUString aCommand = pContext->GetCommand().trim(); + + msfilter::util::EquationResult aResult(msfilter::util::ParseCombinedChars(aCommand)); + if (!aResult.sType.isEmpty() && m_xTextFactory.is()) + { + xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField." + aResult.sType); + xFieldProperties = + uno::Reference< beans::XPropertySet >( xFieldInterface, + uno::UNO_QUERY_THROW); + xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny(aResult.sResult)); + } + else + { + //merge Read_SubF_Ruby into filter/.../util.cxx and reuse that ? + sal_Int32 nSpaceIndex = aCommand.indexOf(' '); + if(nSpaceIndex > 0) + aCommand = aCommand.copy(nSpaceIndex).trim(); + if (aCommand.startsWith("\\s")) + { + aCommand = aCommand.copy(2); + if (aCommand.startsWith("\\do")) + { + aCommand = aCommand.copy(3); + sal_Int32 nStartIndex = aCommand.indexOf('('); + sal_Int32 nEndIndex = aCommand.indexOf(')'); + if (nStartIndex > 0 && nEndIndex > 0) + { + // nDown is the requested "lower by" value in points. + sal_Int32 nDown = aCommand.copy(0, nStartIndex).toInt32(); + OUString aContent = aCommand.copy(nStartIndex + 1, nEndIndex - nStartIndex - 1); + PropertyMapPtr pCharContext = GetTopContext(); + // dHeight is the font size of the current style. + double dHeight = 0; + if ((GetPropertyFromParaStyleSheet(PROP_CHAR_HEIGHT) >>= dHeight) && dHeight != 0) + // Character escapement should be given in negative percents for subscripts. + pCharContext->Insert(PROP_CHAR_ESCAPEMENT, uno::makeAny( sal_Int16(- 100 * nDown / dHeight) ) ); + appendTextPortion(aContent, pCharContext); + } + } + } + else if (aCommand.startsWith("\\* jc")) + { + handleRubyEQField(pContext); + } + } + } + break; + case FIELD_FILLIN : + if (xFieldProperties.is()) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_HINT), uno::makeAny( pContext->GetCommand().getToken(1, '\"'))); + break; + case FIELD_FILENAME: + { + sal_Int32 nNumberingTypeIndex = pContext->GetCommand().indexOf("\\p"); + if (xFieldProperties.is()) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_FILE_FORMAT), + uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME_AND_EXT )); + } + break; + case FIELD_FILESIZE : break; + case FIELD_FORMULA : + handleFieldFormula(pContext, xFieldProperties); + break; + case FIELD_FORMCHECKBOX : + case FIELD_FORMDROPDOWN : + case FIELD_FORMTEXT : + { + uno::Reference< text::XTextField > xTextField( xFieldInterface, uno::UNO_QUERY ); + if ( !xTextField.is() ) + { + FFDataHandler::Pointer_t + pFFDataHandler(pContext->getFFDataHandler()); + FormControlHelper::Pointer_t + pFormControlHelper(new FormControlHelper + (m_bUsingEnhancedFields ? aIt->second.eFieldId : FIELD_FORMCHECKBOX, + + m_xTextDocument, pFFDataHandler)); + pContext->setFormControlHelper(pFormControlHelper); + uno::Reference< text::XFormField > xFormField( xFieldInterface, uno::UNO_QUERY ); + uno::Reference< container::XNamed > xNamed( xFormField, uno::UNO_QUERY ); + if ( xNamed.is() ) + { + if ( pFFDataHandler && !pFFDataHandler->getName().isEmpty() ) + xNamed->setName( pFFDataHandler->getName() ); + pContext->SetFormField( xFormField ); + } + InsertFieldmark(m_aTextAppendStack, + xFormField, pContext->GetStartRange(), + pContext->GetFieldId()); + } + else + { + if ( aIt->second.eFieldId == FIELD_FORMDROPDOWN ) + lcl_handleDropdownField( xFieldProperties, pContext->getFFDataHandler() ); + else + lcl_handleTextField( xFieldProperties, pContext->getFFDataHandler() ); + } + } + break; + case FIELD_GOTOBUTTON : break; + case FIELD_HYPERLINK: + { + ::std::vector aParts = pContext->GetCommandParts(); + + // Syntax is either: + // HYPERLINK "" \l "link" + // or + // HYPERLINK \l "link" + // Make sure "HYPERLINK" doesn't end up as part of link in the second case. + if (!aParts.empty() && aParts[0] == "HYPERLINK") + aParts.erase(aParts.begin()); + + ::std::vector::const_iterator aItEnd = aParts.end(); + ::std::vector::const_iterator aPartIt = aParts.begin(); + + OUString sURL; + OUString sTarget; + + while (aPartIt != aItEnd) + { + if ( *aPartIt == "\\l" ) + { + ++aPartIt; + + if (aPartIt == aItEnd) + break; + + sURL += "#" + *aPartIt; + } + else if (*aPartIt == "\\m" || *aPartIt == "\\n" || *aPartIt == "\\h") + { + } + else if ( *aPartIt == "\\o" || *aPartIt == "\\t" ) + { + ++aPartIt; + + if (aPartIt == aItEnd) + break; + + sTarget = *aPartIt; + } + else + { + sURL = *aPartIt; + } + + ++aPartIt; + } + + if (!sURL.isEmpty()) + { + if (sURL.startsWith("file:///")) + { + // file:///absolute\\path\\to\\file => invalid file URI (Writer cannot open) + // convert all double backslashes to slashes: + sURL = sURL.replaceAll("\\\\", "/"); + + // file:///absolute\path\to\file => invalid file URI (Writer cannot open) + // convert all backslashes to slashes: + sURL = sURL.replace('\\', '/'); + } + // Try to make absolute any relative URLs, except + // for relative same-document URLs that only contain + // a fragment part: + else if (!sURL.startsWith("#")) { + try { + sURL = rtl::Uri::convertRelToAbs( + m_aBaseUrl, sURL); + } catch (rtl::MalformedUriException & e) { + SAL_WARN( + "writerfilter.dmapper", + "MalformedUriException " + << e.getMessage()); + } + } + pContext->SetHyperlinkURL(sURL); + } + + if (!sTarget.isEmpty()) + pContext->SetHyperlinkTarget(sTarget); + } + break; + case FIELD_IF : break; + case FIELD_INFO : break; + case FIELD_INCLUDEPICTURE: break; + case FIELD_KEYWORDS : + { + if (!sFirstParam.isEmpty()) + { + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); + //PROP_CURRENT_PRESENTATION is set later anyway + } + } + break; + case FIELD_LASTSAVEDBY : break; + case FIELD_MACROBUTTON: + { + //extract macro name + sal_Int32 nIndex = sizeof(" MACROBUTTON "); + OUString sMacro = pContext->GetCommand().getToken( 0, ' ', nIndex); + if (xFieldProperties.is()) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_MACRO_NAME), uno::makeAny( sMacro )); + + //extract quick help text + if(xFieldProperties.is() && pContext->GetCommand().getLength() > nIndex + 1) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_HINT), + uno::makeAny( pContext->GetCommand().copy( nIndex ))); + } + } + break; + case FIELD_MERGEFIELD : + { + //todo: create a database field and fieldmaster pointing to a column, only + //create a user field and type + uno::Reference< beans::XPropertySet > xMaster = + FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.Database", sFirstParam); + + // xFieldProperties->setPropertyValue( + // "FieldCode", + // uno::makeAny( pContext->GetCommand().copy( nIndex + 1 ))); + uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + } + break; + case FIELD_MERGEREC : break; + case FIELD_MERGESEQ : break; + case FIELD_NEXT : break; + case FIELD_NEXTIF : break; + case FIELD_PAGE : + if (xFieldProperties.is()) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + xFieldProperties->setPropertyValue( + getPropertyName(PROP_SUB_TYPE), + uno::makeAny( text::PageNumberType_CURRENT )); + } + + break; + case FIELD_PAGEREF: + case FIELD_REF: + if (xFieldProperties.is() && !m_bStartTOC) + { + bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF; + + // Do we need a GetReference (default) or a GetExpression field? + uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY ); + uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters(); + + if (!xFieldMasterAccess->hasByName( + "com.sun.star.text.FieldMaster.SetExpression." + + sFirstParam)) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_REFERENCE_FIELD_SOURCE), + uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) ); + xFieldProperties->setPropertyValue( + getPropertyName(PROP_SOURCE_NAME), + uno::makeAny(sFirstParam) ); + sal_Int16 nFieldPart = (bPageRef ? text::ReferenceFieldPart::PAGE : text::ReferenceFieldPart::TEXT); + OUString sValue; + if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue )) + { + //above-below + nFieldPart = text::ReferenceFieldPart::UP_DOWN; + } + else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue )) + { + //number + nFieldPart = text::ReferenceFieldPart::NUMBER; + } + else if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue )) + { + //number-no-context + nFieldPart = text::ReferenceFieldPart::NUMBER_NO_CONTEXT; + } + else if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue )) + { + //number-full-context + nFieldPart = text::ReferenceFieldPart::NUMBER_FULL_CONTEXT; + } + xFieldProperties->setPropertyValue( + getPropertyName( PROP_REFERENCE_FIELD_PART ), uno::makeAny( nFieldPart )); + } + else if( m_xTextFactory.is() ) + { + xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField.GetExpression"); + xFieldProperties.set(xFieldInterface, uno::UNO_QUERY); + xFieldProperties->setPropertyValue( + getPropertyName(PROP_CONTENT), + uno::makeAny(sFirstParam)); + xFieldProperties->setPropertyValue(getPropertyName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING)); + } + } + break; + case FIELD_REVNUM : break; + case FIELD_SAVEDATE : + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + break; + case FIELD_SECTION : break; + case FIELD_SECTIONPAGES : break; + case FIELD_SEQ : + { + // command looks like: " SEQ Table \* ARABIC " + OUString sCmd(pContext->GetCommand()); + // find the sequence name, e.g. "SEQ" + OUString sSeqName = msfilter::util::findQuotedText(sCmd, "SEQ ", '\\'); + sSeqName = sSeqName.trim(); + + // create a sequence field master using the sequence name + uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster( + "com.sun.star.text.FieldMaster.SetExpression", + sSeqName); + + xMaster->setPropertyValue( + getPropertyName(PROP_SUB_TYPE), + uno::makeAny(text::SetVariableType::SEQUENCE)); + + // apply the numbering type + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + + // attach the master to the field + uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW ); + xDependentField->attachTextFieldMaster( xMaster ); + + OUString sFormula = sSeqName + "+1"; + OUString sValue; + if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue )) + { + sFormula = sSeqName; + } + else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue )) + { + sFormula = sValue; + } + // TODO \s isn't handled, but the spec isn't easy to understand without + // an example for this one. + xFieldProperties->setPropertyValue( + getPropertyName(PROP_CONTENT), + uno::makeAny(sFormula)); + + // Take care of the numeric formatting definition, default is Arabic + sal_Int16 nNumberingType = lcl_ParseNumberingType(pContext->GetCommand()); + if (nNumberingType == style::NumberingType::PAGE_DESCRIPTOR) + nNumberingType = style::NumberingType::ARABIC; + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny(nNumberingType)); + } + break; + case FIELD_SET : + handleFieldSet(pContext, xFieldInterface, xFieldProperties); + break; + case FIELD_SKIPIF : break; + case FIELD_STYLEREF : break; + case FIELD_SUBJECT : + { + if (!sFirstParam.isEmpty()) + { + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); + //PROP_CURRENT_PRESENTATION is set later anyway + } + } + break; + case FIELD_SYMBOL: + { + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + OUString sSymbol( sal_Unicode( sFirstParam.startsWithIgnoreAsciiCase("0x") ? sFirstParam.copy(2).toUInt32(16) : sFirstParam.toUInt32() ) ); + OUString sFont; + bool bHasFont = lcl_FindInCommand( pContext->GetCommand(), 'f', sFont); + if ( bHasFont ) + { + sFont = sFont.trim(); + if (sFont.startsWith("\"")) + sFont = sFont.copy(1); + if (sFont.endsWith("\"")) + sFont = sFont.copy(0,sFont.getLength()-1); + } + + + + if (xTextAppend.is()) + { + uno::Reference< text::XText > xText = xTextAppend->getText(); + uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); + if (xCrsr.is()) + { + xCrsr->gotoEnd(false); + xText->insertString(xCrsr, sSymbol, true); + uno::Reference< beans::XPropertySet > xProp( xCrsr, uno::UNO_QUERY ); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_CHAR_SET), uno::makeAny(awt::CharSet::SYMBOL)); + if(bHasFont) + { + uno::Any aVal = uno::makeAny( sFont ); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME), aVal); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_ASIAN), aVal); + xProp->setPropertyValue(getPropertyName(PROP_CHAR_FONT_NAME_COMPLEX), aVal); + + } + } + } + } + break; + case FIELD_TEMPLATE: break; + case FIELD_TIME : + { + if (pContext->IsFieldLocked()) + { + xFieldProperties->setPropertyValue( + getPropertyName(PROP_IS_FIXED), + uno::makeAny( true )); + m_bSetDateValue = true; + } + SetNumberFormat( pContext->GetCommand(), xFieldProperties ); + } + break; + case FIELD_TITLE : + { + if (!sFirstParam.isEmpty()) + { + xFieldProperties->setPropertyValue( + getPropertyName( PROP_IS_FIXED ), uno::makeAny( true )); + //PROP_CURRENT_PRESENTATION is set later anyway + } + } + break; + case FIELD_USERADDRESS : //todo: user address collects street, city ... + break; + case FIELD_INDEX: + handleIndex(pContext, + OUString::createFromAscii(aIt->second.cFieldServiceName)); + break; + case FIELD_BIBLIOGRAPHY: + handleBibliography(pContext, + OUString::createFromAscii(aIt->second.cFieldServiceName)); + break; + case FIELD_TOC: + handleToc(pContext, + OUString::createFromAscii(aIt->second.cFieldServiceName)); + break; + case FIELD_XE: + { + if( !m_xTextFactory.is() ) + break; + + uno::Reference< beans::XPropertySet > xTC( + m_xTextFactory->createInstance( + OUString::createFromAscii(aIt->second.cFieldServiceName)), + uno::UNO_QUERY_THROW); + if (!sFirstParam.isEmpty()) + { + xTC->setPropertyValue("PrimaryKey", + uno::makeAny(sFirstParam)); + } + uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY ); + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + if (xTextAppend.is()) + { + uno::Reference< text::XText > xText = xTextAppend->getText(); + uno::Reference< text::XTextCursor > xCrsr = xText->createTextCursor(); + if (xCrsr.is()) + { + xCrsr->gotoEnd(false); + xText->insertTextContent(uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ), xToInsert, false); + } + } + } + break; + case FIELD_CITATION: + { + if( !m_xTextFactory.is() ) + break; + + xFieldInterface = m_xTextFactory->createInstance( + OUString::createFromAscii(aIt->second.cFieldServiceName)); + uno::Reference< beans::XPropertySet > xTC(xFieldInterface, + uno::UNO_QUERY_THROW); + OUString sCmd(pContext->GetCommand());//sCmd is the entire instrText including the index e.g. CITATION Kra06 \l 1033 + if( !sCmd.isEmpty()){ + uno::Sequence aValues( comphelper::InitPropertySequence({ + { "Identifier", uno::Any(sCmd) } + })); + xTC->setPropertyValue("Fields", uno::makeAny(aValues)); + } + uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY ); + + uno::Sequence aValues + = m_aFieldStack.back()->getProperties()->GetPropertyValues(); + appendTextContent(xToInsert, aValues); + m_bSetCitation = true; + } + break; + + case FIELD_TC : + { + if( !m_xTextFactory.is() ) + break; + + uno::Reference< beans::XPropertySet > xTC( + m_xTextFactory->createInstance( + OUString::createFromAscii(aIt->second.cFieldServiceName)), + uno::UNO_QUERY_THROW); + if (!sFirstParam.isEmpty()) + { + xTC->setPropertyValue(getPropertyName(PROP_ALTERNATIVE_TEXT), + uno::makeAny(sFirstParam)); + } + OUString sValue; + // \f TC entry in doc with multiple tables + // if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue )) + // { + // todo: unsupported + // } + if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue )) + // \l Outline Level + { + sal_Int32 nLevel = sValue.toInt32(); + if( !sValue.isEmpty() && nLevel >= 0 && nLevel <= 10 ) + xTC->setPropertyValue(getPropertyName(PROP_LEVEL), uno::makeAny( static_cast(nLevel) )); + } + // if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue )) + // \n Suppress page numbers + // { + //todo: unsupported feature + // } + pContext->SetTC( xTC ); + } + break; + case FIELD_NUMCHARS: + case FIELD_NUMWORDS: + case FIELD_NUMPAGES: + if (xFieldProperties.is()) + xFieldProperties->setPropertyValue( + getPropertyName(PROP_NUMBERING_TYPE), + uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) )); + break; + } + } + else + { + /* Unsupported fields will be handled here for docx file. + * To handle unsupported fields used fieldmark API. + */ + OUString aCode( pContext->GetCommand().trim() ); + // Don't waste resources on wrapping shapes inside a fieldmark. + if (sType != "SHAPE" && m_xTextFactory.is() && !m_aTextAppendStack.empty()) + { + xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.Fieldmark"); + + uno::Reference const xFormField(xFieldInterface, uno::UNO_QUERY); + InsertFieldmark(m_aTextAppendStack, xFormField, pContext->GetStartRange(), + pContext->GetFieldId()); + xFormField->setFieldType(ODF_UNHANDLED); + ++m_nStartGenericField; + pContext->SetFormField( xFormField ); + uno::Reference const xNameCont(xFormField->getParameters()); + // note: setting the code to empty string is *required* in + // m_bForceGenericFields mode, or the export will write + // the ODF_UNHANDLED string! + assert(!m_bForceGenericFields || aCode.isEmpty()); + xNameCont->insertByName(ODF_CODE_PARAM, uno::makeAny(aCode)); + ww::eField const id(GetWW8FieldId(sType)); + if (id != ww::eNONE) + { // tdf#129247 tdf#134264 set WW8 id for WW8 export + xNameCont->insertByName(ODF_ID_PARAM, uno::makeAny(OUString::number(id))); + } + } + else + m_bParaHadField = false; + } + //set the text field if there is any + pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) ); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter.dmapper", "Exception in CloseFieldCommand()" ); + } + pContext->SetCommandCompleted(); + } +} +/*------------------------------------------------------------------------- +//the _current_ fields require a string type result while TOCs accept richt results + -----------------------------------------------------------------------*/ +bool DomainMapper_Impl::IsFieldResultAsString() +{ + bool bRet = false; + OSL_ENSURE( !m_aFieldStack.empty(), "field stack empty?"); + FieldContextPtr pContext = m_aFieldStack.back(); + OSL_ENSURE( pContext.get(), "no field context available"); + if( pContext ) + { + bRet = pContext->GetTextField().is() + || pContext->GetFieldId() == FIELD_FORMDROPDOWN + || pContext->GetFieldId() == FIELD_FILLIN; + } + + if (!bRet) + { + FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); + if (pOuter) + { + if (!IsFieldNestingAllowed(pOuter, m_aFieldStack.back())) + { + // Child field has no backing SwField, but the parent has: append is still possible. + bRet = pOuter->GetTextField().is(); + } + } + } + return bRet; +} + +void DomainMapper_Impl::AppendFieldResult(OUString const& rString) +{ + assert(!m_aFieldStack.empty()); + FieldContextPtr pContext = m_aFieldStack.back(); + SAL_WARN_IF(!pContext, "writerfilter.dmapper", "no field context"); + if (pContext) + { + FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); + if (pOuter) + { + if (!IsFieldNestingAllowed(pOuter, pContext)) + { + // Child can't host the field result, forward to parent. + pOuter->AppendResult(rString); + return; + } + } + + pContext->AppendResult(rString); + } +} + +// Calculates css::DateTime based on ddddd.sssss since 1900-1-0 +static util::DateTime lcl_dateTimeFromSerial(const double& dSerial) +{ + const sal_uInt32 secondsPerDay = 86400; + const sal_uInt16 secondsPerHour = 3600; + + DateTime d(Date(30, 12, 1899)); + d.AddDays( static_cast(dSerial) ); + + double frac = std::modf(dSerial, &o3tl::temporary(double())); + sal_uInt32 seconds = frac * secondsPerDay; + + util::DateTime date; + date.Year = d.GetYear(); + date.Month = d.GetMonth(); + date.Day = d.GetDay(); + date.Hours = seconds / secondsPerHour; + date.Minutes = (seconds % secondsPerHour) / 60; + date.Seconds = seconds % 60; + + return date; +} + +void DomainMapper_Impl::SetFieldResult(OUString const& rResult) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("setFieldResult"); + TagLogger::getInstance().chars(rResult); +#endif + + FieldContextPtr pContext = m_aFieldStack.back(); + OSL_ENSURE( pContext.get(), "no field context available"); + + if (m_aFieldStack.size() > 1) + { + // This is a nested field. See if the parent supports nesting on the Writer side. + FieldContextPtr pParentContext = m_aFieldStack[m_aFieldStack.size() - 2]; + if (pParentContext) + { + std::vector aParentParts = pParentContext->GetCommandParts(); + // Conditional text fields don't support nesting in Writer. + if (!aParentParts.empty() && aParentParts[0] == "IF") + { + return; + } + } + } + + if( pContext ) + { + uno::Reference xTextField = pContext->GetTextField(); + try + { + OSL_ENSURE( xTextField.is() + //||m_xTOC.is() ||m_xTC.is() + //||m_sHyperlinkURL.getLength() + , "DomainMapper_Impl::SetFieldResult: field not created" ); + if(xTextField.is()) + { + try + { + if( m_bSetUserFieldContent ) + { + // user field content has to be set at the field master + uno::Reference< text::XDependentTextField > xDependentField( xTextField, uno::UNO_QUERY_THROW ); + xDependentField->getTextFieldMaster()->setPropertyValue( + getPropertyName(PROP_CONTENT), + uno::makeAny( rResult )); + } + else if ( m_bSetCitation ) + { + + uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); + // In case of SetExpression, the field result contains the content of the variable. + uno::Reference xServiceInfo(xTextField, uno::UNO_QUERY); + + bool bIsSetbiblio = xServiceInfo->supportsService("com.sun.star.text.TextField.Bibliography"); + if( bIsSetbiblio ) + { + uno::Any aProperty = xFieldProperties->getPropertyValue("Fields"); + uno::Sequence aValues ; + aProperty >>= aValues; + beans::PropertyValue propertyVal; + sal_Int32 nTitleFoundIndex = -1; + for (sal_Int32 i = 0; i < aValues.getLength(); ++i) + { + propertyVal = aValues[i]; + if (propertyVal.Name == "Title") + { + nTitleFoundIndex = i; + break; + } + } + if (nTitleFoundIndex != -1) + { + OUString titleStr; + uno::Any aValue(propertyVal.Value); + aValue >>= titleStr; + titleStr += rResult; + propertyVal.Value <<= titleStr; + aValues[nTitleFoundIndex] = propertyVal; + } + else + { + aValues.realloc(aValues.getLength() + 1); + propertyVal.Name = "Title"; + propertyVal.Value <<= rResult; + aValues[aValues.getLength() - 1] = propertyVal; + } + xFieldProperties->setPropertyValue("Fields", + uno::makeAny(aValues)); + } + } + else if ( m_bSetDateValue ) + { + uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW ); + + uno::Reference xFormatter(util::NumberFormatter::create(m_xComponentContext), uno::UNO_QUERY_THROW); + xFormatter->attachNumberFormatsSupplier( xNumberSupplier ); + sal_Int32 nKey = 0; + + uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); + + xFieldProperties->getPropertyValue( "NumberFormat" ) >>= nKey; + xFieldProperties->setPropertyValue( + "DateTimeValue", + uno::makeAny( lcl_dateTimeFromSerial( xFormatter->convertStringToNumber( nKey, rResult ) ) ) ); + } + else + { + uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW); + // In case of SetExpression, and Input fields the field result contains the content of the variable. + uno::Reference xServiceInfo(xTextField, uno::UNO_QUERY); + // there are fields with a content property, which aren't working correctly with + // a generalized try catch of the content, property, so just restrict content + // handling to these explicit services. + const bool bHasContent = xServiceInfo->supportsService("com.sun.star.text.TextField.SetExpression") || + xServiceInfo->supportsService("com.sun.star.text.TextField.Input"); + // If we already have content set, then use the current presentation + OUString sValue; + if (bHasContent) + { + // this will throw for field types without Content + uno::Any aValue(xFieldProperties->getPropertyValue( + getPropertyName(PROP_CONTENT))); + aValue >>= sValue; + } + xFieldProperties->setPropertyValue( + getPropertyName(bHasContent && sValue.isEmpty()? PROP_CONTENT : PROP_CURRENT_PRESENTATION), + uno::makeAny( rResult )); + } + } + catch( const beans::UnknownPropertyException& ) + { + //some fields don't have a CurrentPresentation (DateTime) + } + } + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "DomainMapper_Impl::SetFieldResult"); + } + } +} + +void DomainMapper_Impl::SetFieldFFData(const FFDataHandler::Pointer_t& pFFDataHandler) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("setFieldFFData"); +#endif + + if (!m_aFieldStack.empty()) + { + FieldContextPtr pContext = m_aFieldStack.back(); + if (pContext) + { + pContext->setFFDataHandler(pFFDataHandler); + } + } + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void DomainMapper_Impl::PopFieldContext() +{ + if(m_bDiscardHeaderFooter) + return; +#ifdef DBG_UTIL + TagLogger::getInstance().element("popFieldContext"); +#endif + + if (m_aFieldStack.empty()) + return; + + FieldContextPtr pContext = m_aFieldStack.back(); + OSL_ENSURE( pContext.get(), "no field context available"); + if( pContext ) + { + if( !pContext->IsCommandCompleted() ) + CloseFieldCommand(); + + if (!pContext->GetResult().isEmpty()) + { + uno::Reference< beans::XPropertySet > xFieldProperties = pContext->GetCustomField(); + if(xFieldProperties.is()) + SetNumberFormat( pContext->GetResult(), xFieldProperties, true ); + SetFieldResult( pContext->GetResult() ); + } + + //insert the field, TC or TOC + uno::Reference< text::XTextAppend > xTextAppend; + if (!m_aTextAppendStack.empty()) + xTextAppend = m_aTextAppendStack.top().xTextAppend; + if(xTextAppend.is()) + { + try + { + uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange()); + uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY ); + if( xToInsert.is() ) + { + if (m_bStartedTOC || m_bStartIndex || m_bStartBibliography) + { + // inside SDT, last empty paragraph is also part of index + if (!m_bParaChanged && !m_xSdtEntryStart) + { + // End of index is the first item on a new paragraph - this paragraph + // should not be part of index + auto xCursor + = xTextAppend->createTextCursorByRange(xTextAppend->getEnd()); + xCursor->gotoEnd(false); + xCursor->goLeft(1, true); + // delete + xCursor->setString(OUString()); + // But a new paragraph should be started after the index instead + xTextAppend->finishParagraph(css::beans::PropertyValues()); + } + m_bStartedTOC = false; + m_aTextAppendStack.pop(); + m_bTextInserted = false; + m_bParaChanged = true; // the paragraph must stay anyway + } + m_bStartTOC = false; + m_bStartIndex = false; + m_bStartBibliography = false; + if (IsInHeaderFooter() && m_bStartTOCHeaderFooter) + m_bStartTOCHeaderFooter = false; + } + else + { + xToInsert.set(pContext->GetTC(), uno::UNO_QUERY); + if( !xToInsert.is() && !m_bStartTOC && !m_bStartIndex && !m_bStartBibliography ) + xToInsert = pContext->GetTextField(); + if( xToInsert.is() && !m_bStartTOC && !m_bStartIndex && !m_bStartBibliography) + { + PropertyMap aMap; + // Character properties of the field show up here the + // last (always empty) run. Inherit character + // properties from there. + // Also merge in the properties from the field context, + // e.g. SdtEndBefore. + if (m_pLastCharacterContext) + aMap.InsertProps(m_pLastCharacterContext); + aMap.InsertProps(m_aFieldStack.back()->getProperties()); + appendTextContent(xToInsert, aMap.GetPropertyValues()); + CheckRedline( xToInsert->getAnchor( ) ); + } + else + { + FormControlHelper::Pointer_t pFormControlHelper(pContext->getFormControlHelper()); + if (pFormControlHelper.get() != nullptr) + { + uno::Reference< text::XFormField > xFormField( pContext->GetFormField() ); + assert(xCrsr.is()); + if (pFormControlHelper->hasFFDataHandler()) + { + xToInsert.set(xFormField, uno::UNO_QUERY); + if (xFormField.is() && xToInsert.is()) + { + PopFieldmark(m_aTextAppendStack, xCrsr, + pContext->GetFieldId()); + pFormControlHelper->processField( xFormField ); + } + else + { + pFormControlHelper->insertControl(xCrsr); + } + } + else + { + PopFieldmark(m_aTextAppendStack, xCrsr, + pContext->GetFieldId()); + uno::Reference(xFormField, uno::UNO_QUERY_THROW)->dispose(); // presumably invalid? + } + } + else if (!pContext->GetHyperlinkURL().isEmpty() && xCrsr.is()) + { + xCrsr->gotoEnd( true ); + + // Draw components (like comments) need hyperlinks set differently + SvxUnoTextRangeBase* pDrawText = dynamic_cast(xCrsr.get()); + if ( pDrawText ) + pDrawText->attachField( std::make_unique(pContext->GetHyperlinkURL(), xCrsr->getString(), SvxURLFormat::AppDefault) ); + else + { + uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW ); + xCrsrProperties->setPropertyValue(getPropertyName(PROP_HYPER_LINK_U_R_L), uno:: + makeAny(pContext->GetHyperlinkURL())); + + if (!pContext->GetHyperlinkTarget().isEmpty()) + xCrsrProperties->setPropertyValue("HyperLinkTarget", uno::makeAny(pContext->GetHyperlinkTarget())); + + if (m_bStartTOC) { + OUString sDisplayName("Index Link"); + xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::makeAny(sDisplayName)); + xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::makeAny(sDisplayName)); + } + else + { + uno::Any aAny = xCrsrProperties->getPropertyValue("CharStyleName"); + OUString charStyle; + if (css::uno::fromAny(aAny, &charStyle)) + { + if (charStyle.isEmpty()) + { + xCrsrProperties->setPropertyValue("VisitedCharStyleName", uno::makeAny(OUString("Default Style"))); + xCrsrProperties->setPropertyValue("UnvisitedCharStyleName", uno::makeAny(OUString("Default Style"))); + } + else if (charStyle.equalsIgnoreAsciiCase("Internet Link")) + { + xCrsrProperties->setPropertyValue("CharStyleName", uno::makeAny(OUString("Default Style"))); + } + else + { + xCrsrProperties->setPropertyValue("VisitedCharStyleName", aAny); + xCrsrProperties->setPropertyValue("UnvisitedCharStyleName", aAny); + } + } + } + } + } + else if (m_nStartGenericField != 0) + { + --m_nStartGenericField; + PopFieldmark(m_aTextAppendStack, xCrsr, pContext->GetFieldId()); + if(m_bTextInserted) + { + m_bTextInserted = false; + } + } + } + } + } + catch(const lang::IllegalArgumentException&) + { + OSL_FAIL( "IllegalArgumentException in PopFieldContext()" ); + } + catch(const uno::Exception&) + { + OSL_FAIL( "exception in PopFieldContext()" ); + } + } + + //TOCs have to include all the imported content + } + + std::vector aParagraphsToFinish; + if (pContext) + { + aParagraphsToFinish = pContext->GetParagraphsToFinish(); + } + + //remove the field context + m_aFieldStack.pop_back(); + + // Finish the paragraph(s) now that the field is closed. + for (const auto& rFinish : aParagraphsToFinish) + { + finishParagraph(rFinish.m_pPropertyMap, rFinish.m_bRemove); + } +} + + +void DomainMapper_Impl::SetBookmarkName( const OUString& rBookmarkName ) +{ + BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( m_sCurrentBkmkId ); + if( aBookmarkIter != m_aBookmarkMap.end() ) + { + // fields are internal bookmarks: consume redundant "normal" bookmark + if ( IsOpenField() ) + { + FFDataHandler::Pointer_t pFFDataHandler(GetTopFieldContext()->getFFDataHandler()); + if (pFFDataHandler && pFFDataHandler->getName() == rBookmarkName) + { + // HACK: At the END marker, StartOrEndBookmark will START + // a bookmark which will eventually be abandoned, not created. + m_aBookmarkMap.erase(aBookmarkIter); + return; + } + } + + aBookmarkIter->second.m_sBookmarkName = rBookmarkName; + } + else + m_sCurrentBkmkName = rBookmarkName; +} + +// This method was used as-is for DomainMapper_Impl::startOrEndPermissionRange() implementation. +void DomainMapper_Impl::StartOrEndBookmark( const OUString& rId ) +{ + /* + * Add the dummy paragraph to handle section properties + * iff the first element in the section is a table. If the dummy para is not added yet, then add it; + * So bookmark is not attached to the wrong paragraph. + */ + if(hasTableManager() && getTableManager().isInCell() && m_nTableDepth == 0 && GetIsFirstParagraphInSection() + && !GetIsDummyParaAddedForTableInSection() &&!GetIsTextFrameInserted()) + { + AddDummyParaForTableInSection(); + } + + bool bIsAfterDummyPara = GetIsDummyParaAddedForTableInSection() && GetIsFirstParagraphInSection(); + if (m_aTextAppendStack.empty()) + return; + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( rId ); + //is the bookmark name already registered? + try + { + if( aBookmarkIter != m_aBookmarkMap.end() ) + { + if (m_xTextFactory.is()) + { + uno::Reference< text::XTextContent > xBookmark( m_xTextFactory->createInstance( "com.sun.star.text.Bookmark" ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextCursor > xCursor; + uno::Reference< text::XText > xText = aBookmarkIter->second.m_xTextRange->getText(); + if( aBookmarkIter->second.m_bIsStartOfText && !bIsAfterDummyPara) + { + xCursor = xText->createTextCursorByRange( xText->getStart() ); + } + else + { + xCursor = xText->createTextCursorByRange( aBookmarkIter->second.m_xTextRange ); + xCursor->goRight( 1, false ); + } + + xCursor->gotoRange( xTextAppend->getEnd(), true ); + // A Paragraph was recently finished, and a new Paragraph has not been started as yet + // then move the bookmark-End to the earlier paragraph + if (IsOutsideAParagraph()) + { + xCursor->goLeft( 1, false ); + } + uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW ); + assert(!aBookmarkIter->second.m_sBookmarkName.isEmpty()); + //todo: make sure the name is not used already! + xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName ); + xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() ); + } + m_aBookmarkMap.erase( aBookmarkIter ); + m_sCurrentBkmkId.clear(); + } + else + { + //otherwise insert a text range as marker + bool bIsStart = true; + uno::Reference< text::XTextRange > xCurrent; + if (xTextAppend.is()) + { + uno::Reference const xCursor = + xTextAppend->createTextCursorByRange( + m_aTextAppendStack.top().xInsertPosition.is() + ? m_aTextAppendStack.top().xInsertPosition + : xTextAppend->getEnd() ); + + if (!xCursor) + return; + + if (!bIsAfterDummyPara) + bIsStart = !xCursor->goLeft(1, false); + xCurrent = xCursor->getStart(); + } + m_sCurrentBkmkId = rId; + m_aBookmarkMap.emplace( rId, BookmarkInsertPosition( bIsStart, m_sCurrentBkmkName, xCurrent ) ); + m_sCurrentBkmkName.clear(); + } + } + catch( const uno::Exception& ) + { + //TODO: What happens to bookmarks where start and end are at different XText objects? + } +} + +void DomainMapper_Impl::setPermissionRangeEd(const OUString& user) +{ + PermMap_t::iterator aPremIter = m_aPermMap.find(m_sCurrentPermId); + if (aPremIter != m_aPermMap.end()) + aPremIter->second.m_Ed = user; + else + m_sCurrentPermEd = user; +} + +void DomainMapper_Impl::setPermissionRangeEdGrp(const OUString& group) +{ + PermMap_t::iterator aPremIter = m_aPermMap.find(m_sCurrentPermId); + if (aPremIter != m_aPermMap.end()) + aPremIter->second.m_EdGrp = group; + else + m_sCurrentPermEdGrp = group; +} + +// This method is based on implementation from DomainMapper_Impl::StartOrEndBookmark() +void DomainMapper_Impl::startOrEndPermissionRange(sal_Int32 permissinId) +{ + /* + * Add the dummy paragraph to handle section properties + * if the first element in the section is a table. If the dummy para is not added yet, then add it; + * So permission is not attached to the wrong paragraph. + */ + if (getTableManager().isInCell() && m_nTableDepth == 0 && GetIsFirstParagraphInSection() + && !GetIsDummyParaAddedForTableInSection() && !GetIsTextFrameInserted()) + { + AddDummyParaForTableInSection(); + } + + if (m_aTextAppendStack.empty()) + return; + + const bool bIsAfterDummyPara = GetIsDummyParaAddedForTableInSection() && GetIsFirstParagraphInSection(); + + uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; + PermMap_t::iterator aPermIter = m_aPermMap.find(permissinId); + + //is the bookmark name already registered? + try + { + if (aPermIter == m_aPermMap.end()) + { + //otherwise insert a text range as marker + bool bIsStart = true; + uno::Reference< text::XTextRange > xCurrent; + if (xTextAppend.is()) + { + uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange(xTextAppend->getEnd()); + + if (!bIsAfterDummyPara) + bIsStart = !xCursor->goLeft(1, false); + xCurrent = xCursor->getStart(); + } + + // register the start of the new permission + m_sCurrentPermId = permissinId; + m_aPermMap.emplace(permissinId, PermInsertPosition(bIsStart, permissinId, m_sCurrentPermEd, m_sCurrentPermEdGrp, xCurrent)); + + // clean up + m_sCurrentPermEd.clear(); + m_sCurrentPermEdGrp.clear(); + } + else + { + if (m_xTextFactory.is()) + { + uno::Reference< text::XTextCursor > xCursor; + uno::Reference< text::XText > xText = aPermIter->second.m_xTextRange->getText(); + if (aPermIter->second.m_bIsStartOfText && !bIsAfterDummyPara) + { + xCursor = xText->createTextCursorByRange(xText->getStart()); + } + else + { + xCursor = xText->createTextCursorByRange(aPermIter->second.m_xTextRange); + xCursor->goRight(1, false); + } + + xCursor->gotoRange(xTextAppend->getEnd(), true); + // A Paragraph was recently finished, and a new Paragraph has not been started as yet + // then move the bookmark-End to the earlier paragraph + if (IsOutsideAParagraph()) + { + xCursor->goLeft(1, false); + } + + // create a new bookmark using specific bookmark name pattern for permissions + uno::Reference< text::XTextContent > xPerm(m_xTextFactory->createInstance("com.sun.star.text.Bookmark"), uno::UNO_QUERY_THROW); + uno::Reference< container::XNamed > xPermNamed(xPerm, uno::UNO_QUERY_THROW); + xPermNamed->setName(aPermIter->second.createBookmarkName()); + + // add new bookmark + const bool bAbsorb = !xCursor->isCollapsed(); + uno::Reference< text::XTextRange > xCurrent(xCursor, uno::UNO_QUERY_THROW); + xTextAppend->insertTextContent(xCurrent, xPerm, bAbsorb); + } + + // remove processed permission + m_aPermMap.erase(aPermIter); + + // clean up + m_sCurrentPermId = 0; + m_sCurrentPermEd.clear(); + m_sCurrentPermEdGrp.clear(); + } + } + catch (const uno::Exception&) + { + //TODO: What happens to bookmarks where start and end are at different XText objects? + } +} + +void DomainMapper_Impl::AddAnnotationPosition( + const bool bStart, + const sal_Int32 nAnnotationId) +{ + if (m_aTextAppendStack.empty()) + return; + + // Create a cursor, pointing to the current position. + uno::Reference xTextAppend = m_aTextAppendStack.top().xTextAppend; + uno::Reference xCurrent; + if (xTextAppend.is()) + { + uno::Reference xCursor; + if (m_bIsNewDoc) + xCursor = xTextAppend->createTextCursorByRange(xTextAppend->getEnd()); + else + xCursor = m_aTextAppendStack.top().xCursor; + if (xCursor.is()) + xCurrent = xCursor->getStart(); + } + + // And save it, to be used by PopAnnotation() later. + AnnotationPosition& aAnnotationPosition = m_aAnnotationPositions[ nAnnotationId ]; + if (bStart) + { + aAnnotationPosition.m_xStart = xCurrent; + } + else + { + aAnnotationPosition.m_xEnd = xCurrent; + } + m_aAnnotationPositions[ nAnnotationId ] = aAnnotationPosition; +} + +GraphicImportPtr const & DomainMapper_Impl::GetGraphicImport(GraphicImportType eGraphicImportType) +{ + if(!m_pGraphicImport) + m_pGraphicImport = new GraphicImport( m_xComponentContext, m_xTextFactory, m_rDMapper, eGraphicImportType, m_aPositionOffsets, m_aAligns, m_aPositivePercentages ); + return m_pGraphicImport; +} +/*------------------------------------------------------------------------- + reset graphic import if the last import resulted in a shape, not a graphic + -----------------------------------------------------------------------*/ +void DomainMapper_Impl::ResetGraphicImport() +{ + m_pGraphicImport.clear(); +} + + +void DomainMapper_Impl::ImportGraphic(const writerfilter::Reference< Properties >::Pointer_t& ref, GraphicImportType eGraphicImportType) +{ + GetGraphicImport(eGraphicImportType); + if( eGraphicImportType != IMPORT_AS_DETECTED_INLINE && eGraphicImportType != IMPORT_AS_DETECTED_ANCHOR ) + { + //create the graphic + ref->resolve( *m_pGraphicImport ); + } + + //insert it into the document at the current cursor position + + uno::Reference xTextContent + (m_pGraphicImport->GetGraphicObject()); + + // In case the SDT starts with the text portion of the graphic, then set the SDT properties here. + bool bHasGrabBag = false; + uno::Reference xPropertySet(xTextContent, uno::UNO_QUERY); + if (xPropertySet.is()) + { + uno::Reference xPropertySetInfo = xPropertySet->getPropertySetInfo(); + bHasGrabBag = xPropertySetInfo->hasPropertyByName("FrameInteropGrabBag"); + // In case we're outside a paragraph, then the SDT properties are stored in the paragraph grab-bag, not the frame one. + if (!m_pSdtHelper->isInteropGrabBagEmpty() && bHasGrabBag && !m_pSdtHelper->isOutsideAParagraph()) + { + comphelper::SequenceAsHashMap aFrameGrabBag(xPropertySet->getPropertyValue("FrameInteropGrabBag")); + aFrameGrabBag["SdtPr"] <<= m_pSdtHelper->getInteropGrabBagAndClear(); + xPropertySet->setPropertyValue("FrameInteropGrabBag", uno::makeAny(aFrameGrabBag.getAsConstPropertyValueList())); + } + } + + /* Set "SdtEndBefore" property on Drawing. + * It is required in a case when Drawing appears immediately after first run i.e. + * there is no text/space/tab in between two runs. + * In this case "SdtEndBefore" property needs to be set on Drawing. + */ + if(IsSdtEndBefore()) + { + if(xPropertySet.is() && bHasGrabBag) + { + uno::Sequence aFrameGrabBag( comphelper::InitPropertySequence({ + { "SdtEndBefore", uno::Any(true) } + })); + xPropertySet->setPropertyValue("FrameInteropGrabBag",uno::makeAny(aFrameGrabBag)); + } + } + + + // Update the shape properties if it is embedded object. + if(m_xEmbedded.is()){ + if (m_pGraphicImport->GetXShapeObject()) + m_pGraphicImport->GetXShapeObject()->setPosition( + m_pGraphicImport->GetGraphicObjectPosition()); + + uno::Reference xShape = m_pGraphicImport->GetXShapeObject(); + UpdateEmbeddedShapeProps(xShape); + if (eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) + { + uno::Reference xEmbeddedProps(m_xEmbedded, uno::UNO_QUERY); + xEmbeddedProps->setPropertyValue("AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER)); + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + xEmbeddedProps->setPropertyValue("HoriOrient", xShapeProps->getPropertyValue("HoriOrient")); + xEmbeddedProps->setPropertyValue("HoriOrientPosition", xShapeProps->getPropertyValue("HoriOrientPosition")); + xEmbeddedProps->setPropertyValue("HoriOrientRelation", xShapeProps->getPropertyValue("HoriOrientRelation")); + xEmbeddedProps->setPropertyValue("VertOrient", xShapeProps->getPropertyValue("VertOrient")); + xEmbeddedProps->setPropertyValue("VertOrientPosition", xShapeProps->getPropertyValue("VertOrientPosition")); + xEmbeddedProps->setPropertyValue("VertOrientRelation", xShapeProps->getPropertyValue("VertOrientRelation")); + //tdf123873 fix missing textwrap import + xEmbeddedProps->setPropertyValue("TextWrap", xShapeProps->getPropertyValue("TextWrap")); + } + } + //insert it into the document at the current cursor position + OSL_ENSURE( xTextContent.is(), "DomainMapper_Impl::ImportGraphic"); + if( xTextContent.is()) + { + appendTextContent( xTextContent, uno::Sequence< beans::PropertyValue >() ); + + if (eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR && !m_aTextAppendStack.empty()) + { + // Remember this object is anchored to the current paragraph. + AnchoredObjectInfo aInfo; + aInfo.m_xAnchoredObject = xTextContent; + if (m_pGraphicImport) + { + // We still have the graphic import around, remember the original margin, so later + // SectionPropertyMap::HandleIncreasedAnchoredObjectSpacing() can use it. + aInfo.m_nLeftMargin = m_pGraphicImport->GetLeftMarginOrig(); + } + m_aTextAppendStack.top().m_aAnchoredObjects.push_back(aInfo); + } + } + + // Clear the reference, so in case the embedded object is inside a + // TextFrame, we won't try to resize it (to match the size of the + // TextFrame) here. + m_xEmbedded.clear(); + m_pGraphicImport.clear(); +} + + +void DomainMapper_Impl::SetLineNumbering( sal_Int32 nLnnMod, sal_uInt32 nLnc, sal_Int32 ndxaLnn ) +{ + if( !m_bLineNumberingSet ) + { + try + { + uno::Reference< text::XLineNumberingProperties > xLineProperties( m_xTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProperties = xLineProperties->getLineNumberingProperties(); + uno::Any aTrue( uno::makeAny( true )); + xProperties->setPropertyValue( getPropertyName( PROP_IS_ON ), aTrue); + xProperties->setPropertyValue( getPropertyName( PROP_COUNT_EMPTY_LINES ), aTrue ); + xProperties->setPropertyValue( getPropertyName( PROP_COUNT_LINES_IN_FRAMES ), uno::makeAny( false ) ); + xProperties->setPropertyValue( getPropertyName( PROP_INTERVAL ), uno::makeAny( static_cast< sal_Int16 >( nLnnMod ))); + xProperties->setPropertyValue( getPropertyName( PROP_DISTANCE ), uno::makeAny( ConversionHelper::convertTwipToMM100(ndxaLnn) )); + xProperties->setPropertyValue( getPropertyName( PROP_NUMBER_POSITION ), uno::makeAny( style::LineNumberPosition::LEFT)); + xProperties->setPropertyValue( getPropertyName( PROP_NUMBERING_TYPE ), uno::makeAny( style::NumberingType::ARABIC)); + xProperties->setPropertyValue( getPropertyName( PROP_RESTART_AT_EACH_PAGE ), uno::makeAny( nLnc == NS_ooxml::LN_Value_ST_LineNumberRestart_newPage )); + } + catch( const uno::Exception& ) + {} + } + m_bLineNumberingSet = true; + uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( GetTextDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xStyles; + xStyleFamilies->getByName(getPropertyName( PROP_PARAGRAPH_STYLES )) >>= xStyles; + lcl_linenumberingHeaderFooter( xStyles, "Header", this ); + lcl_linenumberingHeaderFooter( xStyles, "Footer", this ); +} + + +void DomainMapper_Impl::SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue ) +{ + nValue = ConversionHelper::convertTwipToMM100(nValue); + switch(eElement) + { + case PAGE_MAR_TOP : m_aPageMargins.top = nValue; break; + case PAGE_MAR_RIGHT : m_aPageMargins.right = nValue; break; + case PAGE_MAR_BOTTOM : m_aPageMargins.bottom = nValue; break; + case PAGE_MAR_LEFT : m_aPageMargins.left = nValue; break; + case PAGE_MAR_HEADER : m_aPageMargins.header = nValue; break; + case PAGE_MAR_FOOTER : m_aPageMargins.footer = nValue; break; + case PAGE_MAR_GUTTER : break; + } +} + + +PageMar::PageMar() + : top(ConversionHelper::convertTwipToMM100( sal_Int32(1440))) + // This is strange, the RTF spec says it's 1800, but it's clearly 1440 in Word + // OOXML seems not to specify a default value + , right(ConversionHelper::convertTwipToMM100( sal_Int32(1440))) + , bottom(top) + , left(right) + , header(ConversionHelper::convertTwipToMM100(sal_Int32(720))) + , footer(header) +{ +} + + +void DomainMapper_Impl::RegisterFrameConversion( + uno::Reference< text::XTextRange > const& xFrameStartRange, + uno::Reference< text::XTextRange > const& xFrameEndRange, + const std::vector& rFrameProperties + ) +{ + OSL_ENSURE( + m_aFrameProperties.empty() && !m_xFrameStartRange.is() && !m_xFrameEndRange.is(), + "frame properties not removed"); + m_aFrameProperties = rFrameProperties; + m_xFrameStartRange = xFrameStartRange; + m_xFrameEndRange = xFrameEndRange; +} + + +void DomainMapper_Impl::ExecuteFrameConversion() +{ + if( m_xFrameStartRange.is() && m_xFrameEndRange.is() && !m_bDiscardHeaderFooter ) + { + try + { + uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( GetTopTextAppend(), uno::UNO_QUERY_THROW ); + // convert redline ranges to cursor movement and character length + std::vector redPos, redLen; + for( size_t i = 0; i < aFramedRedlines.size(); i+=3) + { + uno::Reference< text::XTextRange > xRange; + aFramedRedlines[i] >>= xRange; + uno::Reference xRangeCursor = GetTopTextAppend()->createTextCursorByRange( xRange ); + if (xRangeCursor.is()) + { + sal_Int32 nLen = xRange->getString().getLength(); + redLen.push_back(nLen); + xRangeCursor->gotoRange(m_xFrameStartRange, true); + redPos.push_back(xRangeCursor->getString().getLength() - nLen); + } + else + { + // failed createTextCursorByRange(), for example, table inside the frame + redLen.push_back(-1); + redPos.push_back(-1); + } + } + + const uno::Reference< text::XTextContent >& xTextContent = xTextAppendAndConvert->convertToTextFrame( + m_xFrameStartRange, + m_xFrameEndRange, + comphelper::containerToSequence(m_aFrameProperties) ); + + // create redlines in the previous frame + for( size_t i = 0; i < aFramedRedlines.size(); i+=3) + { + OUString sType; + beans::PropertyValues aRedlineProperties( 3 ); + // skip failed createTextCursorByRange() + if (redPos[i/3] == -1) + continue; + aFramedRedlines[i+1] >>= sType; + aFramedRedlines[i+2] >>= aRedlineProperties; + uno::Reference< text::XTextFrame > xFrame( xTextContent, uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextCursor > xCrsr = xFrame->getText()->createTextCursor(); + xCrsr->goRight(redPos[i/3], false); + xCrsr->goRight(redLen[i/3], true); + uno::Reference < text::XRedline > xRedline( xCrsr, uno::UNO_QUERY_THROW ); + xRedline->makeRedline( sType, aRedlineProperties ); + } + } + catch( const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION( "writerfilter.dmapper", "Exception caught when converting to frame"); + } + + m_bIsActualParagraphFramed = false; + aFramedRedlines.clear(); + } + m_xFrameStartRange = nullptr; + m_xFrameEndRange = nullptr; + m_aFrameProperties.clear(); +} + +void DomainMapper_Impl::AddNewRedline( sal_uInt32 sprmId ) +{ + RedlineParamsPtr pNew( new RedlineParams ); + pNew->m_nToken = XML_mod; + if ( !m_bIsParaMarkerChange ) + { + // applies to the whole , applies to the whole , + // so keep those two in CONTEXT_CHARACTERS and CONTEXT_PARAGRAPH, which will take + // care of their scope (i.e. when they should be used and discarded). + // Let's keep the rest the same way they used to be handled (explicitly dropped + // from a global stack by endtrackchange), but quite possibly they should not be handled + // that way either (I don't know). + if( sprmId == NS_ooxml::LN_EG_RPrContent_rPrChange ) + GetTopContextOfType( CONTEXT_CHARACTER )->Redlines().push_back( pNew ); + else if( sprmId == NS_ooxml::LN_CT_PPr_pPrChange ) + GetTopContextOfType( CONTEXT_PARAGRAPH )->Redlines().push_back( pNew ); + else if( sprmId != NS_ooxml::LN_CT_ParaRPr_rPrChange ) + m_aRedlines.top().push_back( pNew ); + } + else + { + m_pParaMarkerRedline = pNew; + } + // Newly read data will go into this redline. + m_currentRedline = pNew; +} + +void DomainMapper_Impl::SetCurrentRedlineIsRead() +{ + m_currentRedline.clear(); +} + +sal_Int32 DomainMapper_Impl::GetCurrentRedlineToken( ) const +{ + assert(m_currentRedline); + return m_currentRedline->m_nToken; +} + +void DomainMapper_Impl::SetCurrentRedlineAuthor( const OUString& sAuthor ) +{ + if (!m_xAnnotationField.is()) + { + if (m_currentRedline) + m_currentRedline->m_sAuthor = sAuthor; + else + SAL_INFO("writerfilter.dmapper", "numberingChange not implemented"); + } + else + m_xAnnotationField->setPropertyValue("Author", uno::makeAny(sAuthor)); +} + +void DomainMapper_Impl::SetCurrentRedlineInitials( const OUString& sInitials ) +{ + if (m_xAnnotationField.is()) + m_xAnnotationField->setPropertyValue("Initials", uno::makeAny(sInitials)); +} + +void DomainMapper_Impl::SetCurrentRedlineDate( const OUString& sDate ) +{ + if (!m_xAnnotationField.is()) + { + if (m_currentRedline) + m_currentRedline->m_sDate = sDate; + else + SAL_INFO("writerfilter.dmapper", "numberingChange not implemented"); + } + else + m_xAnnotationField->setPropertyValue("DateTimeValue", uno::makeAny(ConversionHelper::ConvertDateStringToDateTime(sDate))); +} + +void DomainMapper_Impl::SetCurrentRedlineId( sal_Int32 sId ) +{ + if (m_xAnnotationField.is()) + { + m_nAnnotationId = sId; + } + else + { + // This should be an assert, but somebody had the smart idea to reuse this function also for comments and whatnot, + // and in some cases the id is actually not handled, which may be in fact a bug. + if( !m_currentRedline) + SAL_INFO("writerfilter.dmapper", "no current redline"); + } +} + +void DomainMapper_Impl::SetCurrentRedlineToken( sal_Int32 nToken ) +{ + assert(m_currentRedline); + m_currentRedline->m_nToken = nToken; +} + +void DomainMapper_Impl::SetCurrentRedlineRevertProperties( const uno::Sequence& aProperties ) +{ + assert(m_currentRedline); + m_currentRedline->m_aRevertProperties = aProperties; +} + + +// This removes only the last redline stored here, those stored in contexts are automatically removed when +// the context is destroyed. +void DomainMapper_Impl::RemoveTopRedline( ) +{ + if (m_aRedlines.top().empty()) + { + SAL_WARN("writerfilter.dmapper", "RemoveTopRedline called with empty stack"); + throw uno::Exception("RemoveTopRedline failed", nullptr); + } + m_aRedlines.top().pop_back( ); + m_currentRedline.clear(); +} + +void DomainMapper_Impl::ApplySettingsTable() +{ + if (m_pSettingsTable && m_xTextFactory.is()) + { + try + { + uno::Reference< beans::XPropertySet > xTextDefaults(m_xTextFactory->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY_THROW ); + sal_Int32 nDefTab = m_pSettingsTable->GetDefaultTabStop(); + xTextDefaults->setPropertyValue( getPropertyName( PROP_TAB_STOP_DISTANCE ), uno::makeAny(nDefTab) ); + if (m_pSettingsTable->GetLinkStyles()) + { + // If linked styles are enabled, set paragraph defaults from Word's default template + xTextDefaults->setPropertyValue(getPropertyName(PROP_PARA_BOTTOM_MARGIN), uno::makeAny(ConversionHelper::convertTwipToMM100(200))); + style::LineSpacing aSpacing; + aSpacing.Mode = style::LineSpacingMode::PROP; + aSpacing.Height = sal_Int16(115); + xTextDefaults->setPropertyValue(getPropertyName(PROP_PARA_LINE_SPACING), uno::makeAny(aSpacing)); + } + + if (m_pSettingsTable->GetZoomFactor() || m_pSettingsTable->GetView()) + { + std::vector aViewProps; + if (m_pSettingsTable->GetZoomFactor()) + { + aViewProps.emplace_back("ZoomFactor", -1, uno::makeAny(m_pSettingsTable->GetZoomFactor()), beans::PropertyState_DIRECT_VALUE); + aViewProps.emplace_back("VisibleBottom", -1, uno::makeAny(sal_Int32(0)), beans::PropertyState_DIRECT_VALUE); + aViewProps.emplace_back("ZoomType", -1, + uno::makeAny(m_pSettingsTable->GetZoomType()), + beans::PropertyState_DIRECT_VALUE); + } + uno::Reference xBox = document::IndexedPropertyValues::create(m_xComponentContext); + xBox->insertByIndex(sal_Int32(0), uno::makeAny(comphelper::containerToSequence(aViewProps))); + uno::Reference xViewDataSupplier(m_xTextDocument, uno::UNO_QUERY); + xViewDataSupplier->setViewData(xBox); + } + + uno::Reference< beans::XPropertySet > xSettings(m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + + if (m_pSettingsTable->GetDoNotExpandShiftReturn()) + xSettings->setPropertyValue( "DoNotJustifyLinesWithManualBreak", uno::makeAny(true) ); + if (m_pSettingsTable->GetUsePrinterMetrics()) + xSettings->setPropertyValue("PrinterIndependentLayout", uno::makeAny(document::PrinterIndependentLayout::DISABLED)); + if( m_pSettingsTable->GetEmbedTrueTypeFonts()) + xSettings->setPropertyValue( getPropertyName( PROP_EMBED_FONTS ), uno::makeAny(true) ); + if( m_pSettingsTable->GetEmbedSystemFonts()) + xSettings->setPropertyValue( getPropertyName( PROP_EMBED_SYSTEM_FONTS ), uno::makeAny(true) ); + xSettings->setPropertyValue("AddParaTableSpacing", uno::makeAny(m_pSettingsTable->GetDoNotUseHTMLParagraphAutoSpacing())); + if (m_pSettingsTable->GetNoLeading()) + { + xSettings->setPropertyValue("AddExternalLeading", uno::makeAny(!m_pSettingsTable->GetNoLeading())); + } + if( m_pSettingsTable->GetProtectForm() ) + xSettings->setPropertyValue("ProtectForm", uno::makeAny( true )); + if( m_pSettingsTable->GetReadOnly() ) + xSettings->setPropertyValue("LoadReadonly", uno::makeAny( true )); + } + catch(const uno::Exception&) + { + } + } +} + +uno::Reference DomainMapper_Impl::GetCurrentNumberingRules(sal_Int32* pListLevel) +{ + uno::Reference xRet; + try + { + OUString aStyle = GetCurrentParaStyleName(); + if (aStyle.isEmpty()) + return xRet; + const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(aStyle); + if (!pEntry) + return xRet; + const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast(pEntry->pProperties.get()); + if (!pStyleSheetProperties) + return xRet; + sal_Int32 nListId = pStyleSheetProperties->GetListId(); + if (nListId < 0) + return xRet; + if (pListLevel) + *pListLevel = pStyleSheetProperties->GetListLevel(); + + // So we are in a paragraph style and it has numbering. Look up the relevant numbering rules. + auto const pList(GetListTable()->GetList(nListId)); + OUString aListName; + if (pList) + { + aListName = pList->GetStyleName(); + } + uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY_THROW); + uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xNumberingStyles; + xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles; + uno::Reference xStyle(xNumberingStyles->getByName(aListName), uno::UNO_QUERY); + xRet.set(xStyle->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("writerfilter.dmapper", "GetCurrentNumberingRules: exception caught"); + } + return xRet; +} + +uno::Reference DomainMapper_Impl::GetCurrentNumberingCharStyle() +{ + uno::Reference xRet; + try + { + sal_Int32 nListLevel = -1; + uno::Reference xLevels; + if ( GetTopContextType() == CONTEXT_PARAGRAPH ) + xLevels = GetCurrentNumberingRules(&nListLevel); + if (!xLevels.is()) + { + if (IsOOXMLImport()) + return xRet; + + PropertyMapPtr pContext = m_pTopContext; + if (IsRTFImport() && !IsOpenField()) + { + // Looking up the paragraph context explicitly (and not just taking + // the top context) is necessary for RTF, where formatting of a run + // and of the paragraph mark is not separated. + // We know that the formatting inside a field won't affect the + // paragraph marker formatting, though. + pContext = GetTopContextOfType(CONTEXT_PARAGRAPH); + if (!pContext) + return xRet; + } + + // In case numbering rules is not found via a style, try the direct formatting instead. + std::optional oProp = pContext->getProperty(PROP_NUMBERING_RULES); + if (oProp) + { + xLevels.set(oProp->second, uno::UNO_QUERY); + // Found the rules, then also try to look up our numbering level. + oProp = pContext->getProperty(PROP_NUMBERING_LEVEL); + if (oProp) + oProp->second >>= nListLevel; + else + nListLevel = 0; + } + + if (!xLevels.is()) + return xRet; + } + uno::Sequence aProps; + xLevels->getByIndex(nListLevel) >>= aProps; + auto pProp = std::find_if(aProps.begin(), aProps.end(), + [](const beans::PropertyValue& rProp) { return rProp.Name == "CharStyleName"; }); + if (pProp != aProps.end()) + { + OUString aCharStyle; + pProp->Value >>= aCharStyle; + uno::Reference xCharacterStyles; + uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY); + uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + xStyleFamilies->getByName("CharacterStyles") >>= xCharacterStyles; + xRet.set(xCharacterStyles->getByName(aCharStyle), uno::UNO_QUERY_THROW); + } + } + catch( const uno::Exception& ) + { + } + return xRet; +} + +SectionPropertyMap * DomainMapper_Impl::GetSectionContext() +{ + SectionPropertyMap* pSectionContext = nullptr; + //the section context is not available before the first call of startSectionGroup() + if( !IsAnyTableImport() ) + { + PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_SECTION); + pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() ); + } + + return pSectionContext; +} + +void DomainMapper_Impl::deferCharacterProperty(sal_Int32 id, const css::uno::Any& value) +{ + deferredCharacterProperties[ id ] = value; +} + +void DomainMapper_Impl::processDeferredCharacterProperties() +{ + // Actually process in DomainMapper, so that it's the same source file like normal processing. + if( !deferredCharacterProperties.empty()) + { + m_rDMapper.processDeferredCharacterProperties( deferredCharacterProperties ); + deferredCharacterProperties.clear(); + } +} + +sal_Int32 DomainMapper_Impl::getNumberingProperty(const sal_Int32 nListId, sal_Int32 nNumberingLevel, const OUString& aProp) +{ + sal_Int32 nRet = 0; + if ( nListId < 0 ) + return nRet; + + try + { + if (nNumberingLevel < 0) // It seems it's valid to omit numbering level, and in that case it means zero. + nNumberingLevel = 0; + + auto const pList(GetListTable()->GetList(nListId)); + assert(pList); + const OUString aListName = pList->GetStyleName(); + const uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY_THROW); + const uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xNumberingStyles; + xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles; + const uno::Reference xStyle(xNumberingStyles->getByName(aListName), uno::UNO_QUERY); + const uno::Reference xNumberingRules(xStyle->getPropertyValue("NumberingRules"), uno::UNO_QUERY); + if (xNumberingRules.is()) + { + uno::Sequence aProps; + xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; + auto pProp = std::find_if(aProps.begin(), aProps.end(), + [&aProp](const beans::PropertyValue& rProp) { return rProp.Name == aProp; }); + if (pProp != aProps.end()) + pProp->Value >>= nRet; + } + } + catch( const uno::Exception& ) + { + // This can happen when the doc contains some hand-crafted invalid list level. + } + + return nRet; +} + +sal_Int32 DomainMapper_Impl::getCurrentNumberingProperty(const OUString& aProp) +{ + sal_Int32 nRet = 0; + + std::optional pProp = m_pTopContext->getProperty(PROP_NUMBERING_RULES); + uno::Reference xNumberingRules; + if (pProp) + xNumberingRules.set(pProp->second, uno::UNO_QUERY); + pProp = m_pTopContext->getProperty(PROP_NUMBERING_LEVEL); + // Default numbering level is the first one. + sal_Int32 nNumberingLevel = 0; + if (pProp) + pProp->second >>= nNumberingLevel; + if (xNumberingRules.is()) + { + uno::Sequence aProps; + xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; + auto pPropVal = std::find_if(aProps.begin(), aProps.end(), + [&aProp](const beans::PropertyValue& rProp) { return rProp.Name == aProp; }); + if (pPropVal != aProps.end()) + pPropVal->Value >>= nRet; + } + + return nRet; +} + + +void DomainMapper_Impl::enableInteropGrabBag(const OUString& aName) +{ + m_aInteropGrabBagName = aName; +} + +void DomainMapper_Impl::disableInteropGrabBag() +{ + m_aInteropGrabBagName.clear(); + m_aInteropGrabBag.clear(); + m_aSubInteropGrabBag.clear(); +} + +bool DomainMapper_Impl::isInteropGrabBagEnabled() const +{ + return !(m_aInteropGrabBagName.isEmpty()); +} + +void DomainMapper_Impl::appendGrabBag(std::vector& rInteropGrabBag, const OUString& aKey, const OUString& aValue) +{ + if (m_aInteropGrabBagName.isEmpty()) + return; + beans::PropertyValue aProperty; + aProperty.Name = aKey; + aProperty.Value <<= aValue; + rInteropGrabBag.push_back(aProperty); +} + +void DomainMapper_Impl::appendGrabBag(std::vector& rInteropGrabBag, const OUString& aKey, std::vector& rValue) +{ + if (m_aInteropGrabBagName.isEmpty()) + return; + beans::PropertyValue aProperty; + aProperty.Name = aKey; + aProperty.Value <<= comphelper::containerToSequence(rValue); + rValue.clear(); + rInteropGrabBag.push_back(aProperty); +} + +void DomainMapper_Impl::substream(Id rName, + ::writerfilter::Reference::Pointer_t const& ref) +{ +#ifndef NDEBUG + size_t contextSize(m_aContextStack.size()); + size_t propSize[NUMBER_OF_CONTEXTS]; + for (int i = 0; i < NUMBER_OF_CONTEXTS; ++i) { + propSize[i] = m_aPropertyStacks[i].size(); + } +#endif + + // Save "has footnote" state, which is specific to a section in the body + // text, so state from substreams is not relevant. + bool bHasFtn = m_bHasFtn; + + //finalize any waiting frames before starting alternate streams + CheckUnregisteredFrameConversion(); + ExecuteFrameConversion(); + + appendTableManager(); + // Appending a TableManager resets its TableHandler, so we need to append + // that as well, or tables won't be imported properly in headers/footers. + appendTableHandler(); + getTableManager().startLevel(); + + //import of page header/footer + //Ensure that only one header/footer per section is pushed + + switch( rName ) + { + case NS_ooxml::LN_headerl: + PushPageHeader(SectionPropertyMap::PAGE_LEFT); + break; + case NS_ooxml::LN_headerr: + PushPageHeader(SectionPropertyMap::PAGE_RIGHT); + break; + case NS_ooxml::LN_headerf: + PushPageHeader(SectionPropertyMap::PAGE_FIRST); + break; + case NS_ooxml::LN_footerl: + PushPageFooter(SectionPropertyMap::PAGE_LEFT); + break; + case NS_ooxml::LN_footerr: + PushPageFooter(SectionPropertyMap::PAGE_RIGHT); + break; + case NS_ooxml::LN_footerf: + PushPageFooter(SectionPropertyMap::PAGE_FIRST); + break; + case NS_ooxml::LN_footnote: + case NS_ooxml::LN_endnote: + PushFootOrEndnote( NS_ooxml::LN_footnote == rName ); + break; + case NS_ooxml::LN_annotation : + PushAnnotation(); + break; + } + ref->resolve(m_rDMapper); + + switch( rName ) + { + case NS_ooxml::LN_headerl: + case NS_ooxml::LN_headerr: + case NS_ooxml::LN_headerf: + case NS_ooxml::LN_footerl: + case NS_ooxml::LN_footerr: + case NS_ooxml::LN_footerf: + PopPageHeaderFooter(); + break; + case NS_ooxml::LN_footnote: + case NS_ooxml::LN_endnote: + PopFootOrEndnote(); + break; + case NS_ooxml::LN_annotation : + PopAnnotation(); + break; + } + + getTableManager().endLevel(); + popTableManager(); + m_bHasFtn = bHasFtn; + + switch(rName) + { + case NS_ooxml::LN_footnote: + case NS_ooxml::LN_endnote: + m_pTableHandler->setHadFootOrEndnote(true); + m_bHasFtn = true; + break; + } + + // check that stacks are the same as before substream + assert(m_aContextStack.size() == contextSize); + for (int i = 0; i < NUMBER_OF_CONTEXTS; ++i) { + assert(m_aPropertyStacks[i].size() == propSize[i]); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx new file mode 100644 index 000000000..dc0693eca --- /dev/null +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -0,0 +1,1085 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPER_IMPL_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_DOMAINMAPPER_IMPL_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DomainMapper.hxx" +#include "DomainMapperTableManager.hxx" +#include "DomainMapperTableHandler.hxx" +#include "PropertyMap.hxx" +#include "FontTable.hxx" +#include "NumberingManager.hxx" +#include "StyleSheetTable.hxx" +#include "SettingsTable.hxx" +#include "ThemeTable.hxx" +#include "GraphicImport.hxx" +#include "OLEHandler.hxx" +#include "FFDataHandler.hxx" +#include "SmartTagHandler.hxx" +#include "FormControlHelper.hxx" +#include + +namespace com::sun::star{ + namespace awt{ + struct Size; + } + namespace lang{ + class XMultiServiceFactory; + struct Locale; + } + namespace text + { + class XTextField; + class XFormField; + } + namespace beans{ class XPropertySet;} +} + +namespace writerfilter { +namespace dmapper { + +class SdtHelper; + +struct PageMar +{ + sal_Int32 top; + sal_Int32 right; + sal_Int32 bottom; + sal_Int32 left; + sal_Int32 header; + sal_Int32 footer; + public: + PageMar(); +}; +enum PageMarElement +{ + PAGE_MAR_TOP, + PAGE_MAR_RIGHT, + PAGE_MAR_BOTTOM, + PAGE_MAR_LEFT, + PAGE_MAR_HEADER, + PAGE_MAR_FOOTER, + PAGE_MAR_GUTTER +}; + +/// property stack element +enum ContextType +{ + CONTEXT_SECTION, + CONTEXT_PARAGRAPH, + CONTEXT_CHARACTER, + CONTEXT_STYLESHEET, + CONTEXT_LIST +}; +enum { NUMBER_OF_CONTEXTS = CONTEXT_LIST + 1 }; + +enum BreakType +{ + PAGE_BREAK, + COLUMN_BREAK +}; + +/** + * Two special footnotes are a separator line, and a continuation line. + * In MSOffice, these can contain text as well, but LO doesn't implement this + * rarely used feature, so the separator text needs to be skipped. (tdf#123262) + * Three-way logic is needed because there is no guaranteed on-off event. + * OFF == not in footnote separator + * ON == in footnote separator + * SKIPPING == ON status has been recognized. + */ +enum class SkipFootnoteSeparator +{ + OFF, + ON, + SKIPPING +}; + +/** + * Storage for state that is relevant outside a header/footer, but not inside it. + * + * In case some state of DomainMapper_Impl should be reset before handling the + * header/footer and should be restored once handling of header/footer is done, + * then you can use this class to do so. + */ +class HeaderFooterContext +{ + bool m_bTextInserted; + sal_Int32 m_nTableDepth; + +public: + explicit HeaderFooterContext(bool bTextInserted, sal_Int32 nTableDepth); + bool getTextInserted() const; + sal_Int32 getTableDepth() const; +}; + +/// Information about a paragraph to be finished after a field end. +struct FieldParagraph +{ + PropertyMapPtr m_pPropertyMap; + bool m_bRemove = false; +}; + +/// field stack element +class FieldContext : public virtual SvRefBase +{ + bool m_bFieldCommandCompleted; + css::uno::Reference m_xStartRange; + + OUString m_sCommand; + OUString m_sResult; + std::optional m_eFieldId; + bool m_bFieldLocked; + + css::uno::Reference m_xTextField; + css::uno::Reference m_xFormField; + css::uno::Reference m_xTOC; + css::uno::Reference m_xTC; // TOX entry + css::uno::Reference m_xCustomField; + + OUString m_sHyperlinkURL; + /// A frame for the hyperlink when one exists. + OUString m_sHyperlinkTarget; + + FFDataHandler::Pointer_t m_pFFDataHandler; + FormControlHelper::Pointer_t m_pFormControlHelper; + /// (Character) properties of the field itself. + PropertyMapPtr m_pProperties; + + std::vector m_aParagraphsToFinish; + +public: + explicit FieldContext(css::uno::Reference const& xStart); + ~FieldContext() override; + + const css::uno::Reference& GetStartRange() const { return m_xStartRange; } + + void AppendCommand(const OUString& rPart); + const OUString& GetCommand() const {return m_sCommand; } + + void SetFieldId(FieldId eFieldId ) { m_eFieldId = eFieldId; } + std::optional const & GetFieldId() const { return m_eFieldId; } + + void AppendResult(OUString const& rResult) { m_sResult += rResult; } + const OUString& GetResult() const { return m_sResult; } + + void SetCommandCompleted() { m_bFieldCommandCompleted = true; } + bool IsCommandCompleted() const { return m_bFieldCommandCompleted; } + + void SetFieldLocked() { m_bFieldLocked = true; } + bool IsFieldLocked() const { return m_bFieldLocked; } + + const css::uno::Reference& GetCustomField() const { return m_xCustomField; } + void SetCustomField(css::uno::Reference const& xCustomField) { m_xCustomField = xCustomField; } + const css::uno::Reference& GetTextField() const { return m_xTextField;} + void SetTextField(css::uno::Reference const& xTextField) { m_xTextField = xTextField;} + const css::uno::Reference& GetFormField() const { return m_xFormField;} + void SetFormField(css::uno::Reference const& xFormField) { m_xFormField = xFormField;} + + void SetTOC(css::uno::Reference const& xTOC) { m_xTOC = xTOC; } + const css::uno::Reference& GetTOC() const { return m_xTOC; } + + void SetTC(css::uno::Reference const& xTC) { m_xTC = xTC; } + const css::uno::Reference& GetTC() const { return m_xTC; } + + void SetHyperlinkURL( const OUString& rURL ) { m_sHyperlinkURL = rURL; } + const OUString& GetHyperlinkURL() const { return m_sHyperlinkURL; } + void SetHyperlinkTarget(const OUString& rTarget) { m_sHyperlinkTarget = rTarget; } + const OUString& GetHyperlinkTarget() const { return m_sHyperlinkTarget; } + + void setFFDataHandler(FFDataHandler::Pointer_t pFFDataHandler) { m_pFFDataHandler = pFFDataHandler; } + const FFDataHandler::Pointer_t& getFFDataHandler() const { return m_pFFDataHandler; } + + void setFormControlHelper(FormControlHelper::Pointer_t pFormControlHelper) { m_pFormControlHelper = pFormControlHelper; } + const FormControlHelper::Pointer_t& getFormControlHelper() const { return m_pFormControlHelper; } + const PropertyMapPtr& getProperties() const { return m_pProperties; } + + ::std::vector GetCommandParts() const; + + std::vector& GetParagraphsToFinish() { return m_aParagraphsToFinish; } +}; + +struct TextAppendContext +{ + css::uno::Reference xTextAppend; + css::uno::Reference xInsertPosition; + css::uno::Reference xCursor; + ParagraphPropertiesPtr pLastParagraphProperties; + + /** + * Objects anchored to the current paragraph, may affect the paragraph + * spacing. + */ + std::vector m_aAnchoredObjects; + + TextAppendContext(const css::uno::Reference& xAppend, const css::uno::Reference& xCur) + : xTextAppend(xAppend) + { + xCursor.set(xCur, css::uno::UNO_QUERY); + xInsertPosition = xCursor; + } +}; + +struct AnchoredContext +{ + css::uno::Reference xTextContent; + bool bToRemove; + + explicit AnchoredContext(const css::uno::Reference& xContent) + : xTextContent(xContent), bToRemove(false) + { + } +}; + +typedef tools::SvRef FieldContextPtr; + +/*------------------------------------------------------------------------- + extended tab stop struct + -----------------------------------------------------------------------*/ +struct DeletableTabStop : public css::style::TabStop +{ + bool bDeleted; + explicit DeletableTabStop() + : bDeleted(false) + { + // same defaults as SvxXMLTabStopContext_Impl + FillChar = ' '; + DecimalChar = ','; + } + DeletableTabStop(const css::style::TabStop& rTabStop) + : TabStop(rTabStop), + bDeleted(false) + { + } +}; +/// helper to remember bookmark start position +struct BookmarkInsertPosition +{ + bool m_bIsStartOfText; + OUString m_sBookmarkName; + css::uno::Reference m_xTextRange; + BookmarkInsertPosition(bool bIsStartOfText, const OUString& rName, css::uno::Reference const& xTextRange): + m_bIsStartOfText( bIsStartOfText ), + m_sBookmarkName( rName ), + m_xTextRange( xTextRange ) + {} +}; + +struct PermInsertPosition +{ + bool m_bIsStartOfText; + sal_Int32 m_Id; + OUString m_Ed; + OUString m_EdGrp; + + css::uno::Reference m_xTextRange; + + PermInsertPosition(bool bIsStartOfText, sal_Int32 id, const OUString& ed, const OUString& edGrp, css::uno::Reference const& xTextRange) + : m_bIsStartOfText(bIsStartOfText) + , m_Id(id) + , m_Ed(ed) + , m_EdGrp(edGrp) + , m_xTextRange(xTextRange) + {} + + OUString createBookmarkName() const + { + OUString bookmarkName; + + assert((!m_Ed.isEmpty()) || (!m_EdGrp.isEmpty())); + + if (m_Ed.isEmpty()) + { + bookmarkName += "permission-for-group:" + + OUString::number(m_Id) + + ":" + + m_EdGrp; + } + else + { + bookmarkName += "permission-for-user:" + + OUString::number(m_Id) + + ":" + + m_Ed; + } + + //todo: make sure the name is not used already! + return bookmarkName; + } +}; + +/// Stores the start/end positions of an annotation before its insertion. +struct AnnotationPosition +{ + css::uno::Reference m_xStart; + css::uno::Reference m_xEnd; +}; + +struct RubyInfo +{ + OUString sRubyText; + OUString sRubyStyle; + sal_uInt32 nSprmId; + sal_uInt32 nRubyAlign; + sal_uInt32 nHps; + sal_uInt32 nHpsBaseText; + + RubyInfo(): + nSprmId(0), + nRubyAlign(0), + nHps(0), + nHpsBaseText(0) + { + } +}; + +struct LineNumberSettings +{ + sal_Int32 nDistance; + sal_Int32 nInterval; + bool bRestartAtEachPage; + LineNumberSettings() : + nDistance(-1) + ,nInterval(0) + ,bRestartAtEachPage(true) + {} + +}; + +/// Contains information about a table that will be potentially converted to a floating one at the section end. +struct FloatingTableInfo +{ + css::uno::Reference m_xStart; + css::uno::Reference m_xEnd; + css::uno::Sequence m_aFrameProperties; + sal_Int32 m_nTableWidth; + sal_Int32 m_nTableWidthType; + /// Break type of the section that contains this table. + sal_Int32 m_nBreakType = -1; + + FloatingTableInfo(css::uno::Reference const& xStart, + css::uno::Reference const& xEnd, + const css::uno::Sequence& aFrameProperties, + sal_Int32 nTableWidth, sal_Int32 nTableWidthType) + : m_xStart(xStart), + m_xEnd(xEnd), + m_aFrameProperties(aFrameProperties), + m_nTableWidth(nTableWidth), + m_nTableWidthType(nTableWidthType) + { + } + css::uno::Any getPropertyValue(const OUString &propertyName); +}; + +/// Stores original/in-file-format info about a single anchored object. +struct AnchoredObjectInfo +{ + css::uno::Reference m_xAnchoredObject; + sal_Int32 m_nLeftMargin = 0; +}; + +/// Stores info about objects anchored to a given paragraph. +struct AnchoredObjectsInfo +{ + css::uno::Reference m_xParagraph; + std::vector m_aAnchoredObjects; +}; + +struct SymbolData +{ + sal_Unicode cSymbol; + OUString sFont; + SymbolData(): + cSymbol(), + sFont() + { } +}; + +class DomainMapper; +class DomainMapper_Impl final +{ +public: + typedef std::map < OUString, BookmarkInsertPosition > BookmarkMap_t; + typedef std::map < sal_Int32, PermInsertPosition > PermMap_t; + +private: + SourceDocumentType m_eDocumentType; + DomainMapper& m_rDMapper; + OUString m_aBaseUrl; + css::uno::Reference m_xTextDocument; + css::uno::Reference m_xDocumentSettings; + css::uno::Reference m_xTextFactory; + css::uno::Reference m_xComponentContext; + css::uno::Reference m_xPageStyles1; + // cache next available number, expensive to repeatedly compute + std::optional m_xNextUnusedPageStyleNo; + css::uno::Reference m_xBodyText; + css::uno::Reference m_xEmbedded; + + std::stack m_aTextAppendStack; + std::stack m_aAnchoredStack; + std::stack m_aHeaderFooterStack; + std::deque m_aFieldStack; + bool m_bForceGenericFields; + bool m_bSetUserFieldContent; + bool m_bSetCitation; + bool m_bSetDateValue; + bool m_bIsFirstSection; + bool m_bIsColumnBreakDeferred; + bool m_bIsPageBreakDeferred; + /// If we want to set "sdt end" on the next character context. + bool m_bSdtEndDeferred; + /// If we want to set "paragraph sdt end" on the next paragraph context. + bool m_bParaSdtEndDeferred; + bool m_bStartTOC; + bool m_bStartTOCHeaderFooter; + /// If we got any text that is the pre-rendered result of the TOC field. + bool m_bStartedTOC; + bool m_bStartIndex; + bool m_bStartBibliography; + unsigned int m_nStartGenericField; + bool m_bTextInserted; + LineNumberSettings m_aLineNumberSettings; + + BookmarkMap_t m_aBookmarkMap; + OUString m_sCurrentBkmkId; + OUString m_sCurrentBkmkName; + + PermMap_t m_aPermMap; + sal_Int32 m_sCurrentPermId; + OUString m_sCurrentPermEd; + OUString m_sCurrentPermEdGrp; + + PageMar m_aPageMargins; + SymbolData m_aSymbolData; + + // TableManagers are stacked: one for each stream to avoid any confusion + std::stack< tools::SvRef< DomainMapperTableManager > > m_aTableManagers; + tools::SvRef m_pTableHandler; + // List of document lists overrides. They are applied only once on first occurrence in document + std::set m_aListOverrideApplied; + + //each context needs a stack of currently used attributes + std::stack m_aPropertyStacks[NUMBER_OF_CONTEXTS]; + std::stack m_aContextStack; + FontTablePtr m_pFontTable; + ListsManager::Pointer m_pListTable; + std::deque< css::uno::Reference > m_aPendingShapes; + StyleSheetTablePtr m_pStyleSheetTable; + ThemeTablePtr m_pThemeTable; + SettingsTablePtr m_pSettingsTable; + GraphicImportPtr m_pGraphicImport; + + + PropertyMapPtr m_pTopContext; + PropertyMapPtr m_pLastSectionContext; + PropertyMapPtr m_pLastCharacterContext; + + ::std::vector m_aCurrentTabStops; + OUString m_sCurrentParaStyleName; //highly inaccurate. Overwritten by "overlapping" paragraphs like comments, flys. + OUString m_sDefaultParaStyleName; //caches the ConvertedStyleName of the default paragraph style + bool m_bInStyleSheetImport; //in import of fonts, styles, lists or lfos + bool m_bInAnyTableImport; //in import of fonts, styles, lists or lfos + enum class HeaderFooterImportState + { + none, + header, + footer, + } m_eInHeaderFooterImport; + bool m_bDiscardHeaderFooter; + bool m_bInFootOrEndnote; + PropertyMapPtr m_pFootnoteContext; + bool m_bHasFootnoteStyle; + bool m_bCheckFootnoteStyle; + /// Skip paragraphs from the footnote + SkipFootnoteSeparator m_eSkipFootnoteState; + + bool m_bLineNumberingSet; + bool m_bIsInFootnoteProperties; + + RubyInfo m_aRubyInfo; + //registered frame properties + std::vector m_aFrameProperties; + css::uno::Reference m_xFrameStartRange; + css::uno::Reference m_xFrameEndRange; + + // Redline stack + std::stack< std::vector< RedlineParamsPtr > > m_aRedlines; + // The redline currently read, may be also stored by a context instead of m_aRedlines. + RedlineParamsPtr m_currentRedline; + RedlineParamsPtr m_previousRedline; + RedlineParamsPtr m_pParaMarkerRedline; + bool m_bIsParaMarkerChange; + // redline data of the terminating run, if it's a moveFrom deletion + RedlineParamsPtr m_pParaMarkerRedlineMoveFrom; + + /// If the current paragraph has any runs. + bool m_bParaChanged; + bool m_bIsFirstParaInSection; + bool m_bIsFirstParaInSectionAfterRedline; + bool m_bIsFirstParaInShape = false; + bool m_bDummyParaAddedForTableInSection; + bool m_bTextFrameInserted; + bool m_bIsPreviousParagraphFramed; + bool m_bIsLastParaInSection; + bool m_bIsLastSectionGroup; + bool m_bIsInComments; + /// If the current paragraph contains section property definitions. + bool m_bParaSectpr; + bool m_bUsingEnhancedFields; + /// If the current paragraph is inside a structured document element. + bool m_bSdt; + bool m_bIsFirstRun; + bool m_bIsOutsideAParagraph; + /// This is a continuation of already finished paragraph - e.g., first in an index section + bool m_bRemoveThisParagraph = false; + + css::uno::Reference< css::text::XTextCursor > xTOCMarkerCursor; + + //annotation import + css::uno::Reference< css::beans::XPropertySet > m_xAnnotationField; + sal_Int32 m_nAnnotationId; + std::unordered_map< sal_Int32, AnnotationPosition > m_aAnnotationPositions; + + void GetCurrentLocale(css::lang::Locale& rLocale); + void SetNumberFormat(const OUString& rCommand, css::uno::Reference const& xPropertySet, bool bDetectFormat = false); + /// @throws css::uno::Exception + css::uno::Reference FindOrCreateFieldMaster(const char* pFieldMasterService, const OUString& rFieldMasterName); + css::uno::Reference const & GetDocumentSettings(); + + std::map deferredCharacterProperties; + SmartTagHandler m_aSmartTagHandler; + + css::uno::Reference m_xGlossaryEntryStart; + css::uno::Reference m_xSdtEntryStart; + +public: + css::uno::Reference m_xInsertTextRange; +private: + bool m_bIsNewDoc; + bool m_bIsReadGlossaries; +public: + DomainMapper_Impl( + DomainMapper& rDMapper, + css::uno::Reference < css::uno::XComponentContext > const& xContext, + css::uno::Reference< css::lang::XComponent > const& xModel, + SourceDocumentType eDocumentType, + utl::MediaDescriptor const & rMediaDesc); + ~DomainMapper_Impl(); + + SectionPropertyMap* GetLastSectionContext( ) + { + return dynamic_cast< SectionPropertyMap* >( m_pLastSectionContext.get( ) ); + } + + css::uno::Reference const & GetPageStyles(); + OUString GetUnusedPageStyleName(); + css::uno::Reference const & GetBodyText(); + const css::uno::Reference& GetTextFactory() const + { + return m_xTextFactory; + } + const css::uno::Reference& GetTextDocument() const + { + return m_xTextDocument; + } + void SetDocumentSettingsProperty( const OUString& rPropName, const css::uno::Any& rValue ); + + void CreateRedline(css::uno::Reference const& xRange, const RedlineParamsPtr& pRedline); + + void CheckParaMarkerRedline(css::uno::Reference const& xRange); + + void CheckRedline(css::uno::Reference const& xRange); + + void StartParaMarkerChange( ); + void EndParaMarkerChange( ); + void ChainTextFrames(); + + void RemoveDummyParaForTableInSection(); + void AddDummyParaForTableInSection(); + void RemoveLastParagraph( ); + void SetIsLastParagraphInSection( bool bIsLast ); + bool GetIsLastParagraphInSection() const { return m_bIsLastParaInSection;} + void SetRubySprmId( sal_uInt32 nSprmId) { m_aRubyInfo.nSprmId = nSprmId ; } + void SetRubyText( OUString const &sText, OUString const &sStyle) { + m_aRubyInfo.sRubyText = sText; + m_aRubyInfo.sRubyStyle = sStyle; + } + const RubyInfo & GetRubyInfo() const { return m_aRubyInfo;} + void SetRubyInfo(const RubyInfo & rInfo) { m_aRubyInfo = rInfo;} + + void SetIsLastSectionGroup( bool bIsLast ); + bool GetIsLastSectionGroup() const { return m_bIsLastSectionGroup;} + void SetIsFirstParagraphInSection( bool bIsFirst ); + void SetIsFirstParagraphInSectionAfterRedline( bool bIsFirstAfterRedline ); + bool GetIsFirstParagraphInSection( bool bAfterRedline = false ) const; + void SetIsFirstParagraphInShape(bool bIsFirst); + bool GetIsFirstParagraphInShape() const { return m_bIsFirstParaInShape; } + void SetIsDummyParaAddedForTableInSection( bool bIsAdded ); + bool GetIsDummyParaAddedForTableInSection() const { return m_bDummyParaAddedForTableInSection;} + + /// Track if a textframe has been inserted into this section + void SetIsTextFrameInserted( bool bIsInserted ); + bool GetIsTextFrameInserted() const { return m_bTextFrameInserted;} + + void SetIsPreviousParagraphFramed( bool bIsFramed ) { m_bIsPreviousParagraphFramed = bIsFramed; } + bool GetIsPreviousParagraphFramed() const { return m_bIsPreviousParagraphFramed; } + void SetParaSectpr(bool bParaSectpr); + bool GetParaSectpr() const { return m_bParaSectpr;} + + void SetSymbolChar( sal_Int32 nSymbol) { m_aSymbolData.cSymbol = sal_Unicode(nSymbol); } + void SetSymbolFont( OUString const &rName ) { m_aSymbolData.sFont = rName; } + const SymbolData & GetSymbolData() const { return m_aSymbolData;} + + /// Setter method for m_bSdt. + void SetSdt(bool bSdt); + /// Getter method for m_bSdt. + bool GetSdt() const { return m_bSdt;} + bool GetParaChanged() const { return m_bParaChanged;} + bool GetRemoveThisPara() const { return m_bRemoveThisParagraph; } + + void deferBreak( BreakType deferredBreakType ); + bool isBreakDeferred( BreakType deferredBreakType ); + void clearDeferredBreaks(); + void clearDeferredBreak(BreakType deferredBreakType); + + void setSdtEndDeferred(bool bSdtEndDeferred); + bool isSdtEndDeferred() const; + void setParaSdtEndDeferred(bool bParaSdtEndDeferred); + bool isParaSdtEndDeferred() const; + + void finishParagraph( const PropertyMapPtr& pPropertyMap, const bool bRemove = false); + void appendTextPortion( const OUString& rString, const PropertyMapPtr& pPropertyMap ); + void appendTextContent(const css::uno::Reference&, const css::uno::Sequence&); + void appendOLE( const OUString& rStreamName, const std::shared_ptr& pOleHandler ); + void appendStarMath( const Value& v); + void adjustLastPara(sal_Int8 nAlign); + css::uno::Reference appendTextSectionAfter(css::uno::Reference const & xBefore); + + /// AutoText import: each entry is placed in the separate section + void appendGlossaryEntry(); + /// Remember where entry was started + void setGlossaryEntryStart( css::uno::Reference const & xStart ) + { + m_xGlossaryEntryStart = xStart; + } + + // push the new properties onto the stack and make it the 'current' property map + void PushProperties(ContextType eId); + void PushStyleProperties(const PropertyMapPtr& pStyleProperties); + void PushListProperties(const PropertyMapPtr& pListProperties); + void PopProperties(ContextType eId); + + ContextType GetTopContextType() const { return m_aContextStack.top(); } + const PropertyMapPtr& GetTopContext() const + { + return m_pTopContext; + } + PropertyMapPtr GetTopContextOfType(ContextType eId); + + bool HasTopText() const; + css::uno::Reference const & GetTopTextAppend(); + FieldContextPtr const & GetTopFieldContext(); + + FontTablePtr const & GetFontTable() + { + if(!m_pFontTable) + m_pFontTable = new FontTable(); + return m_pFontTable; + } + StyleSheetTablePtr const & GetStyleSheetTable() + { + if(!m_pStyleSheetTable) + m_pStyleSheetTable = new StyleSheetTable( m_rDMapper, m_xTextDocument, m_bIsNewDoc ); + return m_pStyleSheetTable; + } + OUString GetListStyleName(sal_Int32 nListId); + ListsManager::Pointer const & GetListTable(); + ThemeTablePtr const & GetThemeTable() + { + if(!m_pThemeTable) + m_pThemeTable = new ThemeTable; + return m_pThemeTable; + } + + SettingsTablePtr const & GetSettingsTable() + { + if( !m_pSettingsTable ) + m_pSettingsTable = new SettingsTable(m_rDMapper); + return m_pSettingsTable; + } + + GraphicImportPtr const & GetGraphicImport( GraphicImportType eGraphicImportType ); + void ResetGraphicImport(); + // this method deletes the current m_pGraphicImport after import + void ImportGraphic(const writerfilter::Reference< Properties>::Pointer_t&, GraphicImportType eGraphicImportType ); + + void InitTabStopFromStyle(const css::uno::Sequence& rInitTabStops); + void IncorporateTabStop( const DeletableTabStop &aTabStop ); + css::uno::Sequence GetCurrentTabStopAndClear(); + + void SetCurrentParaStyleName(const OUString& sStringValue) {m_sCurrentParaStyleName = sStringValue;} + OUString GetCurrentParaStyleName(); + OUString GetDefaultParaStyleName(); + + // specified style - including inherited properties. Indicate whether paragraph defaults should be checked. + css::uno::Any GetPropertyFromStyleSheet(PropertyIds eId, StyleSheetEntryPtr pEntry, const bool bDocDefaults, const bool bPara, bool* bIsDocDefault = nullptr); + // current paragraph style - including inherited properties + css::uno::Any GetPropertyFromParaStyleSheet(PropertyIds eId); + // context's character style - including inherited properties + css::uno::Any GetPropertyFromCharStyleSheet(PropertyIds eId, const PropertyMapPtr& rContext); + // get property first from the given context, or secondly via inheritance from styles/docDefaults + css::uno::Any GetAnyProperty(PropertyIds eId, const PropertyMapPtr& rContext); + void SetStyleSheetImport( bool bSet ) { m_bInStyleSheetImport = bSet;} + bool IsStyleSheetImport()const { return m_bInStyleSheetImport;} + void SetAnyTableImport( bool bSet ) { m_bInAnyTableImport = bSet;} + bool IsAnyTableImport()const { return m_bInAnyTableImport;} + bool IsInShape()const { return m_aAnchoredStack.size() > 0;} + + void PushShapeContext(const css::uno::Reference& xShape); + void PopShapeContext(); + void UpdateEmbeddedShapeProps(const css::uno::Reference& xShape); + /// Add a pending shape: it's currently inserted into the document, but it should be removed before the import finishes. + void PushPendingShape(const css::uno::Reference& xShape); + /// Get the first pending shape, if there are any. + css::uno::Reference PopPendingShape(); + + void PushPageHeader(SectionPropertyMap::PageType eType); + void PushPageFooter(SectionPropertyMap::PageType eType); + + void PopPageHeaderFooter(); + bool IsInHeaderFooter() const { return m_eInHeaderFooterImport != HeaderFooterImportState::none; } + + bool IsInTOC() const { return m_bStartTOC; } + + void PushFootOrEndnote( bool bIsFootnote ); + void PopFootOrEndnote(); + bool IsInFootOrEndnote() const { return m_bInFootOrEndnote; } + + void StartCustomFootnote(const PropertyMapPtr pContext); + void EndCustomFootnote(); + bool IsInCustomFootnote() const { return m_bHasFootnoteStyle; } + bool CheckFootnoteStyle() const { return m_bCheckFootnoteStyle; } + void SetHasFootnoteStyle(bool bVal) { m_bHasFootnoteStyle = bVal; } + void SetCheckFootnoteStyle(bool bVal) { m_bCheckFootnoteStyle = bVal; } + + const PropertyMapPtr& GetFootnoteContext() const { return m_pFootnoteContext; } + + SkipFootnoteSeparator GetSkipFootnoteState() const { return m_eSkipFootnoteState; } + void SetSkipFootnoteState(SkipFootnoteSeparator eId) { m_eSkipFootnoteState = eId; } + + void PushAnnotation(); + void PopAnnotation(); + + /// A field context starts with a cFieldStart. + void PushFieldContext(); + //the current field context waits for the completion of the command + bool IsOpenFieldCommand() const; + bool IsOpenField() const; + //mark field in current context as locked (fixed) + void SetFieldLocked(); + //collect the pieces of the command + void AppendFieldCommand(OUString const & rPartOfCommand); + void handleRubyEQField( const FieldContextPtr& pContext); + void handleFieldSet + (const FieldContextPtr& pContext, + css::uno::Reference< css::uno::XInterface > const & xFieldInterface, + css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties); + void handleFieldAsk + (const FieldContextPtr& pContext, + css::uno::Reference< css::uno::XInterface > & xFieldInterface, + css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties); + OUString convertFieldFormula(const OUString& input); + void handleFieldFormula + (const FieldContextPtr& pContext, + css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties); + void handleAutoNum + (const FieldContextPtr& pContext, + css::uno::Reference< css::uno::XInterface > const & xFieldInterface, + css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties); + static void handleAuthor + (OUString const& rFirstParam, + css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties, + FieldId eFieldId); + void handleDocProperty + (const FieldContextPtr& pContext, + OUString const& rFirstParam, + css::uno::Reference< css::uno::XInterface > & xFieldInterface); + void handleToc + (const FieldContextPtr& pContext, + const OUString & sTOCServiceName); + void handleIndex + (const FieldContextPtr& pContext, + const OUString & sTOCServiceName); + + void handleBibliography + (const FieldContextPtr& pContext, + const OUString & sTOCServiceName); + /// The field command has to be closed (cFieldSep appeared). + void CloseFieldCommand(); + //the _current_ fields require a string type result while TOCs accept richt results + bool IsFieldResultAsString(); + void AppendFieldResult(OUString const& rResult); + //apply the result text to the related field + void SetFieldResult(OUString const& rResult); + // set FFData of top field context + void SetFieldFFData( const FFDataHandler::Pointer_t& pFFDataHandler ); + /// The end of field is reached (cFieldEnd appeared) - the command might still be open. + void PopFieldContext(); + + /// Returns title of the TOC placed in paragraph(s) before TOC field inside STD-frame + OUString extractTocTitle(); + css::uno::Reference createSectionForRange(css::uno::Reference< css::text::XTextRange > xStart, css::uno::Reference< css::text::XTextRange > xEnd, const OUString & sObjectType, bool stepLeft); + + void SetBookmarkName( const OUString& rBookmarkName ); + void StartOrEndBookmark( const OUString& rId ); + + void setPermissionRangeEd(const OUString& user); + void setPermissionRangeEdGrp(const OUString& group); + void startOrEndPermissionRange(sal_Int32 permissinId); + + void AddAnnotationPosition( + const bool bStart, + const sal_Int32 nAnnotationId ); + + bool hasTableManager() const + { + return !m_aTableManagers.empty(); + } + + DomainMapperTableManager& getTableManager() + { + return *m_aTableManagers.top(); + } + + void appendTableManager( ) + { + tools::SvRef pMngr(new DomainMapperTableManager()); + m_aTableManagers.push( pMngr ); + } + + void appendTableHandler( ) + { + if (m_pTableHandler) + m_aTableManagers.top()->setHandler(m_pTableHandler); + } + + void popTableManager( ) + { + if (hasTableManager()) + m_aTableManagers.pop(); + } + + void SetLineNumbering( sal_Int32 nLnnMod, sal_uInt32 nLnc, sal_Int32 ndxaLnn ); + bool IsLineNumberingSet() const {return m_bLineNumberingSet;} + + DeletableTabStop m_aCurrentTabStop; + + /// If we're right after the end of a table. + bool m_bConvertedTable = false; + + bool IsOOXMLImport() const { return m_eDocumentType == SourceDocumentType::OOXML; } + + bool IsRTFImport() const { return m_eDocumentType == SourceDocumentType::RTF; } + + void InitPageMargins() { m_aPageMargins = PageMar(); } + void SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue ); + const PageMar& GetPageMargins() const {return m_aPageMargins;} + + const LineNumberSettings& GetLineNumberSettings() const { return m_aLineNumberSettings;} + void SetLineNumberSettings(const LineNumberSettings& rSet) { m_aLineNumberSettings = rSet;} + + void SetInFootnoteProperties(bool bSet) { m_bIsInFootnoteProperties = bSet;} + bool IsInFootnoteProperties() const { return m_bIsInFootnoteProperties;} + + bool IsInComments() const { return m_bIsInComments; }; + + void CheckUnregisteredFrameConversion( ); + + void RegisterFrameConversion(css::uno::Reference const& xFrameStartRange, + css::uno::Reference const& xFrameEndRange, + const std::vector& aFrameProperties); + void ExecuteFrameConversion(); + + void AddNewRedline( sal_uInt32 sprmId ); + + sal_Int32 GetCurrentRedlineToken( ) const; + void SetCurrentRedlineAuthor( const OUString& sAuthor ); + void SetCurrentRedlineDate( const OUString& sDate ); + void SetCurrentRedlineId( sal_Int32 nId ); + void SetCurrentRedlineToken( sal_Int32 nToken ); + void SetCurrentRedlineRevertProperties( const css::uno::Sequence& aProperties ); + void SetCurrentRedlineIsRead(); + void RemoveTopRedline( ); + void SetCurrentRedlineInitials( const OUString& sInitials ); + bool IsFirstRun() const { return m_bIsFirstRun;} + void SetIsFirstRun(bool bval) { m_bIsFirstRun = bval;} + bool IsOutsideAParagraph() const { return m_bIsOutsideAParagraph;} + void SetIsOutsideAParagraph(bool bval) { m_bIsOutsideAParagraph = bval;} + + void ApplySettingsTable(); + + css::uno::Reference GetCurrentXText() { + return m_aTextAppendStack.empty() ? nullptr : m_aTextAppendStack.top().xTextAppend; + } + + SectionPropertyMap * GetSectionContext(); + /// If the current paragraph has a numbering style associated, this method returns its character style (part of the numbering rules) + css::uno::Reference GetCurrentNumberingCharStyle(); + /// If the current paragraph has a numbering style associated, this method returns its numbering rules + css::uno::Reference GetCurrentNumberingRules(sal_Int32* pListLevel); + + /** + Used for attributes/sprms which cannot be evaluated immediately (e.g. they depend + on another one that comes in the same CONTEXT_CHARACTER). The property will be processed + again in DomainMapper::processDeferredCharacterProperties(). + */ + void deferCharacterProperty(sal_Int32 id, const css::uno::Any& value); + /** + Processes properties deferred using deferCharacterProperty(). To be called whenever the top + CONTEXT_CHARACTER is going to be used (e.g. by appendText()). + */ + void processDeferredCharacterProperties(); + + sal_Int32 getNumberingProperty(const sal_Int32 nListId, sal_Int32 nListLevel, const OUString& aProp); + /// Get a property of the current numbering style's current level. + sal_Int32 getCurrentNumberingProperty(const OUString& aProp); + + /// If we're importing into a new document, or just pasting to an existing one. + bool IsNewDoc() const { return m_bIsNewDoc;} + + /// If we're importing autotext. + bool IsReadGlossaries() const { return m_bIsReadGlossaries;} + + tools::SvRef m_pSdtHelper; + + /// Document background color, applied to every page style. + std::optional m_oBackgroundColor; + + /** + * This contains the raw table depth. m_nTableDepth > 0 is the same as + * getTableManager().isInTable(), unless we're in the first paragraph of a + * table, or first paragraph after a table, as the table manager is only + * updated once we ended the paragraph (and know if the para has the + * inTbl SPRM or not). + */ + sal_Int32 m_nTableDepth; + /// Raw table cell depth. + sal_Int32 m_nTableCellDepth; + /// Table cell depth of the last finished paragraph. + sal_Int32 m_nLastTableCellParagraphDepth; + + /// If the current section has footnotes. + bool m_bHasFtn; + /// If the current section has a footnote separator. + bool m_bHasFtnSep; + + /// If the next tab should be ignored, used for footnotes. + bool m_bCheckFirstFootnoteTab; + bool m_bIgnoreNextTab; + /// Pending floating tables: they may be converted to text frames at the section end. + std::vector m_aPendingFloatingTables; + + /// Paragraphs with anchored objects in the current section. + std::vector m_aAnchoredObjectAnchors; + + /// Append a property to a sub-grabbag if necessary (e.g. 'lineRule', 'auto') + void appendGrabBag(std::vector& rInteropGrabBag, const OUString& aKey, const OUString& aValue); + void appendGrabBag(std::vector& rInteropGrabBag, const OUString& aKey, std::vector& rValue); + + /// Enable, disable and check status of grabbags + void enableInteropGrabBag(const OUString& aName); + void disableInteropGrabBag(); + bool isInteropGrabBagEnabled() const; + + /// Name of m_aInteropGrabBag. + OUString m_aInteropGrabBagName; + + /// A toplevel dmapper grabbag, like 'pPr'. + std::vector m_aInteropGrabBag; + + /// A sub-grabbag of m_aInteropGrabBag, like 'spacing'. + std::vector m_aSubInteropGrabBag; + + /// ST_PositionOffset values we received + std::pair m_aPositionOffsets; + /// ST_AlignH/V values we received + std::pair m_aAligns; + /// ST_PositivePercentage values we received + std::queue m_aPositivePercentages; + bool isInIndexContext() const { return m_bStartIndex;} + bool isInBibliographyContext() const { return m_bStartBibliography;} + SmartTagHandler& getSmartTagHandler() { return m_aSmartTagHandler; } + + void substream(Id rName, ::writerfilter::Reference::Pointer_t const& ref); + + /// If the document needs to split paragraph. + bool m_bIsSplitPara; + + /// Check if "SdtEndBefore" property is set + bool IsSdtEndBefore(); + + bool IsDiscardHeaderFooter() const; + + bool IsForceGenericFields() const { return m_bForceGenericFields; } + + void SetParaAutoBefore(bool bParaAutoBefore) { m_bParaAutoBefore = bParaAutoBefore; } + + /// Forget about the previous paragraph, as it's not inside the same + /// start/end node. + void ClearPreviousParagraph(); + + /// Handle redline text portions in frames: + /// store their data, and create them after frame creation + bool m_bIsActualParagraphFramed; + std::vector aFramedRedlines; + +private: + void PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType); + // Start a new index section; if needed, finish current paragraph + css::uno::Reference StartIndexSectionChecked(const OUString& sServiceName); + std::vector > m_vTextFramesForChaining ; + /// Current paragraph had at least one field in it. + bool m_bParaHadField; + css::uno::Reference m_xPreviousParagraph; + /// Current paragraph has automatic before spacing. + bool m_bParaAutoBefore; + /// Current paragraph in a table is first paragraph of a cell + bool m_bFirstParagraphInCell; + bool m_bSaveFirstParagraphInCell; +}; + +} //namespace dmapper +} //namespace writerfilter +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/FFDataHandler.cxx b/writerfilter/source/dmapper/FFDataHandler.cxx new file mode 100644 index 000000000..507327cf8 --- /dev/null +++ b/writerfilter/source/dmapper/FFDataHandler.cxx @@ -0,0 +1,190 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "FFDataHandler.hxx" +#include "TagLogger.hxx" + +#include + +namespace writerfilter::dmapper { + +/************************ + * class: FFDataHandler * + ************************/ + +FFDataHandler::FFDataHandler() : +LoggedProperties("FFDataHandler"), +m_nCheckboxHeight(0), +m_bCheckboxAutoHeight(false), +m_nCheckboxChecked(-1), +m_nCheckboxDefault(-1), +m_nTextMaxLength(0) +{ +} + + +FFDataHandler::~FFDataHandler() +{ +} + + +bool FFDataHandler::getCheckboxChecked() const +{ + if (m_nCheckboxChecked != -1) + return m_nCheckboxChecked; + else if (m_nCheckboxDefault != -1) + return m_nCheckboxDefault; + else + return false; +} + + +void FFDataHandler::lcl_sprm(Sprm & r_Sprm) +{ + switch(r_Sprm.getId()) + { + case NS_ooxml::LN_CT_FFData_name: + { + m_sName = r_Sprm.getValue()->getString(); + } + break; + case NS_ooxml::LN_CT_FFData_helpText: + { + resolveSprm(r_Sprm); + } + break; + case NS_ooxml::LN_CT_FFData_statusText: + { + resolveSprm(r_Sprm); + } + break; + case NS_ooxml::LN_CT_FFData_entryMacro: + { + m_sEntryMacro = r_Sprm.getValue()->getString(); + } + break; + case NS_ooxml::LN_CT_FFData_exitMacro: + { + m_sExitMacro = r_Sprm.getValue()->getString(); + } + break; + case NS_ooxml::LN_CT_FFCheckBox_size: + { + m_nCheckboxHeight = r_Sprm.getValue()->getInt(); + } + break; + case NS_ooxml::LN_CT_FFCheckBox_sizeAuto: + { + m_bCheckboxAutoHeight = r_Sprm.getValue()->getInt(); + } + break; + case NS_ooxml::LN_CT_FFCheckBox_checked: + { + m_nCheckboxChecked = r_Sprm.getValue()->getInt(); + } + break; + case NS_ooxml::LN_CT_FFCheckBox_default: + { + m_nCheckboxDefault = r_Sprm.getValue()->getInt(); + } + break; + case NS_ooxml::LN_CT_FFData_checkBox: + { + resolveSprm(r_Sprm); + } + break; + case NS_ooxml::LN_CT_FFDDList_result: + { + m_sDropDownResult = r_Sprm.getValue()->getString(); + } + break; + case NS_ooxml::LN_CT_FFDDList_listEntry: + { + m_DropDownEntries.push_back(r_Sprm.getValue()->getString()); + } + break; + case NS_ooxml::LN_CT_FFData_ddList: + { + resolveSprm(r_Sprm); + } + break; + case NS_ooxml::LN_CT_FFTextInput_type: + { + m_sTextType = r_Sprm.getValue()->getString(); + } + break; + case NS_ooxml::LN_CT_FFTextInput_default: + { + m_sTextDefault = r_Sprm.getValue()->getString(); + } + break; + case NS_ooxml::LN_CT_FFTextInput_maxLength: + { + m_nTextMaxLength = r_Sprm.getValue()->getInt(); + } + break; + case NS_ooxml::LN_CT_FFTextInput_format: + { + m_sTextFormat = r_Sprm.getValue()->getString(); + } + break; + case NS_ooxml::LN_CT_FFData_textInput: + { + resolveSprm(r_Sprm); + } + break; + default: +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + break; + } +} + +void FFDataHandler::resolveSprm(Sprm & r_Sprm) +{ + writerfilter::Reference::Pointer_t pProperties = r_Sprm.getProps(); + if( pProperties) + pProperties->resolve(*this); +} + +void FFDataHandler::lcl_attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_FFHelpText_val: + { + m_sHelpText = val.getString(); + } + break; + case NS_ooxml::LN_CT_FFStatusText_val: + { + m_sStatusText = val.getString(); + } + break; + default: +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + break; + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/FFDataHandler.hxx b/writerfilter/source/dmapper/FFDataHandler.hxx new file mode 100644 index 000000000..84ac070e5 --- /dev/null +++ b/writerfilter/source/dmapper/FFDataHandler.hxx @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FFDATAHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FFDATAHANDLER_HXX +#include "LoggedResources.hxx" +#include +#include +namespace writerfilter { +namespace dmapper { +class FFDataHandler : public LoggedProperties +{ +public: + // typedefs + typedef ::tools::SvRef Pointer_t; + typedef ::std::vector DropDownEntries_t; + + // constructor + FFDataHandler(); + // destructor + virtual ~FFDataHandler() override; + + // member: name + const OUString & getName() const { return m_sName;} + + // member: helpText + const OUString & getHelpText() const { return m_sHelpText;} + + // member: statusText + const OUString & getStatusText() const { return m_sStatusText;} + + const OUString & getEntryMacro() const { return m_sEntryMacro;} + const OUString & getExitMacro() const { return m_sExitMacro;} + + // member: checkboxHeight + sal_uInt32 getCheckboxHeight() const { return m_nCheckboxHeight;} + + // member: checkboxAutoHeight + bool getCheckboxAutoHeight() const { return m_bCheckboxAutoHeight;} + + // member: checkboxChecked or checkboxDefault (if the previous is not set) + bool getCheckboxChecked() const; + + // member: dropDownResult + const OUString & getDropDownResult() const { return m_sDropDownResult;} + + // member: dropDownEntries + const DropDownEntries_t & getDropDownEntries() const { return m_DropDownEntries;} + + // member: textDefault + const OUString & getTextDefault() const { return m_sTextDefault;} + + const OUString & getTextType() const { return m_sTextType; } + const OUString & getTextFormat() const { return m_sTextFormat; } + sal_uInt16 getTextMaxLength() const { return m_nTextMaxLength; } + + // sprm + void resolveSprm(Sprm & r_sprm); + +private: + OUString m_sName; + OUString m_sHelpText; + OUString m_sStatusText; + OUString m_sEntryMacro; + OUString m_sExitMacro; + sal_uInt32 m_nCheckboxHeight; + bool m_bCheckboxAutoHeight; + int m_nCheckboxChecked; + int m_nCheckboxDefault; + OUString m_sDropDownResult; + DropDownEntries_t m_DropDownEntries; + OUString m_sTextDefault; + OUString m_sTextType; + OUString m_sTextFormat; + sal_uInt16 m_nTextMaxLength; + + // sprm + void lcl_sprm(Sprm & r_sprm) override; + + // attribute + void lcl_attribute(Id name, Value & val) override; +}; + + +}} +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FFDATAHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/FieldTypes.hxx b/writerfilter/source/dmapper/FieldTypes.hxx new file mode 100644 index 000000000..af390fe20 --- /dev/null +++ b/writerfilter/source/dmapper/FieldTypes.hxx @@ -0,0 +1,307 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FIELDTYPES_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FIELDTYPES_HXX + +namespace writerfilter { +namespace dmapper { + +enum FieldId +{ + /* ADDRESSBLOCK \d \* MERGEFORMAT -> Addressblock completely unsupported*/ + FIELD_ADDRESSBLOCK + /* ADVANCE \d downvalue \l leftvalue \r rightvalue \u upvalue \x xvalue \y yvalue -> unsupported*/ + ,FIELD_ADVANCE + /* ASK bookmarkname "hint" \d defaultanswer \o \* MERGEFORMAT -> + the hint is not always quoted, inputfield with default answer, prompt before merge (\o) + */ + ,FIELD_ASK + /* AUTONUM \* Numberingswitch -> + mapped to sequence field "AutoNr" + */ + ,FIELD_AUTONUM + /* AUTONUMLGL \* Numberingswitch -> + mapped to sequence field "AutoNr" + */ + ,FIELD_AUTONUMLGL + /* AUTONUMOUT \* Numberingswitch -> + mapped to sequence field "AutoNr" + */ + ,FIELD_AUTONUMOUT + /* AUTHOR NewAuthor \* defaultswitch \* MERGEFORMAT -> + mapped to sequence field "AutoNr" + */ + ,FIELD_AUTHOR + /* COMMENTS "comment" \* MERGEFORMAT -> + Docinfo-Comments + */ + ,FIELD_COMMENTS + /* CREATEDATE \h \* MERGEFORMAT -> + docinfo-created-date + */ + ,FIELD_CREATEDATE + /* DATE \@ "number format" \s \* MERGEFORMAT -> + ww8filterimprovement: multiple languages now supported + */ + ,FIELD_DATE + /* DOCPROPERTY propertyname \* MERGEFORMAT -> + ww8filterimprovement: some fields imported as functionally equivalent fields if possible, + the others imported as UserField + */ + ,FIELD_DOCPROPERTY + /* DOCVARIABLE Name \* MERGEFORMAT -> + ww8filterimprovement: now imported as user fields + */ + ,FIELD_DOCVARIABLE + /* EDITTIME \# "displayformat" \* Numberingswitch \* MERGEFORMAT -> + DocInfo-Modified-Date + ww8filterimprovement: multiple languages now supported + */ + ,FIELD_EDITTIME + ,FIELD_EQ + /* FILLIN "text to fill in" \d defaultanswer \o \* MERGEFORMAT -> + Function-InputField + */ + ,FIELD_FILLIN + /* FILENAME \p \* * MERGEFORMAT -> + file name (\p with path) + */ + ,FIELD_FILENAME + /* FILESIZE \* NumberingType \* MERGEFORMAT -> + not imported in old ww8 filter, see lcl_ParseNumberingType + todo find alternative field + */ + ,FIELD_FILESIZE + /* =formula \# "number format" + todo find alternative field + */ + ,FIELD_FORMULA + /* FORMCHECKBOX */ + ,FIELD_FORMCHECKBOX + /* FORMDROPDOWN */ + ,FIELD_FORMDROPDOWN + /* FORMTEXT */ + ,FIELD_FORMTEXT + /* GOTOBUTTON text \* MERGEFORMAT -> + not imported in old ww8 filter + todo find alternative field + */ + ,FIELD_GOTOBUTTON + /* HYPERLINK "link" \* MERGEFORMAT -> + not imported in old ww8 filter + ww8filterimprovement: now imported as hyperlink + */ + ,FIELD_HYPERLINK + /* IF condition "then text" "else text" -> + not imported in old ww8 filter + ww8filterimprovement: now imported + todo: condition, if text, else text still missing + */ + ,FIELD_IF + /* INFO NameOfInfo \* MERGEFORMAT -> old + todo: filter imports wrong? + */ + ,FIELD_INFO + /* INCLUDEPICTURE path \* MERGEFORMAT-> + old filter imports an embedded picture + */ + ,FIELD_INCLUDEPICTURE + /* KEYWORDS keyword \* defaultswitch \* Numberingswitch \* MERGEFORMAT -> + DocInfo Keywords + */ + ,FIELD_KEYWORDS + /* LASTSAVEDBY \* MERGEFORMAT -> + DocInfo-Modified-Author + */ + ,FIELD_LASTSAVEDBY + /* MACROBUTTON MacroName quick help text -> + Macro field + */ + ,FIELD_MACROBUTTON + /* MERGEFIELD ColumName \b prefix \f suffix \* MERGEFORMAT -> + ww8filterimprovement: column-only API now supported + */ + ,FIELD_MERGEFIELD + /* MERGEREC \* MERGEFORMAT -> + RecordNumber field, maybe without db name + todo: currently unchecked + */ + ,FIELD_MERGEREC + /* MERGESEQ \* MERGEFORMAT -> + not imported in old ww8 filter + ww8filterimprovement: now imported + todo: currently unchecked + */ + ,FIELD_MERGESEQ + /* NEXT text -> + Next record + todo: currently unchecked + */ + ,FIELD_NEXT + /* NEXTIF condition + todo: condition not imported + */ + ,FIELD_NEXTIF + /* PAGE \* Numberingswitch \* MERGEFORMAT -> + see lcl_ParseNumberingType + */ + ,FIELD_PAGE + ,FIELD_PAGEREF + /* REF targetbkm \f \* MERGEFORMAT -> + imports a ShowVariable (bookmarkname)? + \h hyperlink to paragraph + \p relative to para above/below + \f reference number + \d separator number separator + \n paragraph number + \r paragraph number in relative context + \t suppress non delimiters + \w paragraph number in full context + \* Upper/Lower... + */ + ,FIELD_REF + /* REVNUM \* Numberingswitch \* MERGEFORMAT -> + DocInfo-revision number + */ + ,FIELD_REVNUM + /* SAVEDATE \@ "NumberFormat"\* MERGEFORMAT -> + DocInfo-modified-date + */ + ,FIELD_SAVEDATE + /* SECTION \* NumberFormat \* MERGEFORMAT -> + not imported in old ww8 filter see lcl_ParseNumberingType + todo: find alternative + */ + ,FIELD_SECTION + /* SECTIONPAGES \* NumberFormat \* MERGEFORMAT -> + not imported in old ww8 filter see lcl_ParseNumberingType + todo: find alternative + */ + ,FIELD_SECTIONPAGES + /* SEQ sequencename \h \c \n \r \s \* MERGEFORMAT -> + number range name:sequencename value:sequencename+1 + todo: only partially implemented, switches unsupported + */ + ,FIELD_SEQ + /* SET bookmarkname newtext \* MERGEFORMAT -> + SetVariable bookmarkname = newtext + todo: not implemented yet + */ + ,FIELD_SET + /* SKIPIF condition \* MERGEFORMAT -> + ?? + todo: not implemented yet + */ + ,FIELD_SKIPIF + /* STYLEREF stylename \* MERGEFORMAT -> + not imported in old ww8 filter + todo: add an equivalent field type + */ + ,FIELD_STYLEREF + /* SUBJECT subject \* Defaultswitch \* MERGEFORMAT -> + DocInfo - subject + */ + ,FIELD_SUBJECT + /* SYMBOL symbolnumber \* MERGEFORMAT -> + inserts a special char (symbolnumber) + todo: find alternative + */ + ,FIELD_SYMBOL + /* TEMPLATE \* Defaultswitch \* MERGEFORMAT + TemplateName field + */ + ,FIELD_TEMPLATE + /* TIME \@ "number format" \* MERGEFORMAT + ww8filterimprovement: multiple languages now supported + */ + ,FIELD_TIME + /* TITLE \* Defaultswitch \* MERGEFORMAT -> + DocInfo-title + */ + ,FIELD_TITLE + /* USERINITIALS newinitials \* MERGEFORMAT -> + ExtendedUser field (SHORTCUT) + */ + ,FIELD_USERINITIALS + /* USERADDRESS \* MERGEFORMAT -> + not imported in old ww8 filter + todo: find alternative + */ + ,FIELD_USERADDRESS + /* USERNAME newusername \* MERGEFORMAT -> + not imported in old ww8 filter + todo: import as extended user field(s) + */ + ,FIELD_USERNAME + /* + TOC options: + \a Builds a table of figures but does not include the captions's label and number + \b Uses a bookmark to specify area of document from which to build table of contents + \c Builds a table of figures of the given label + \d Defines the separator between sequence and page numbers + \f Builds a table of contents using TC entries instead of outline levels + \h Hyperlinks the entries and page numbers within the table of contents + \l Defines the TC entries field level used to build a table of contents + \n Builds a table of contents or a range of entries, such as 1-9, in a table of contents without page numbers + \o Builds a table of contents by using outline levels instead of TC entries + \p Defines the separator between the table entry and its page number + \s Builds a table of contents by using a sequence type + \t Builds a table of contents by using style names other than the standard outline styles + \u Builds a table of contents by using the applied paragraph outline level + \w Preserve tab characters within table entries + \x Preserve newline characters within table entries + \z Hides page numbers within the table of contents when shown in Web Layout View + */ + ,FIELD_TOC + /* + TOC entry: text + \f TC entry in doc with multiple tables + \l Outline Level + \n Suppress page numbers + example: TOC "EntryText \f \l 2 \n + */ + ,FIELD_TC + /* document statistic - number of characters + */ + ,FIELD_NUMCHARS + /* document statistic - number of words + */ + ,FIELD_NUMWORDS + /* document statistic - number of pages + */ + ,FIELD_NUMPAGES + /* Document alphabetical index + */ + ,FIELD_INDEX + /* Document alphabetical index marks + */ + ,FIELD_XE + /** + * Bibliography + */ + ,FIELD_BIBLIOGRAPHY + /* Citation + */ + ,FIELD_CITATION +}; + +}} +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FIELDTYPES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/FontTable.cxx b/writerfilter/source/dmapper/FontTable.cxx new file mode 100644 index 000000000..c98177db5 --- /dev/null +++ b/writerfilter/source/dmapper/FontTable.cxx @@ -0,0 +1,298 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "FontTable.hxx" +#include +#include +#include +#include +#include +#include + +using namespace com::sun::star; + +namespace writerfilter::dmapper +{ + +struct FontTable_Impl +{ + std::unique_ptr xEmbeddedFontHelper; + std::vector< FontEntry::Pointer_t > aFontEntries; + FontEntry::Pointer_t pCurrentEntry; + FontTable_Impl() {} +}; + +FontTable::FontTable() +: LoggedProperties("FontTable") +, LoggedTable("FontTable") +, LoggedStream("FontTable") +, m_pImpl( new FontTable_Impl ) +{ +} + +FontTable::~FontTable() +{ +} + +void FontTable::lcl_attribute(Id Name, Value & val) +{ + SAL_WARN_IF( !m_pImpl->pCurrentEntry, "writerfilter.dmapper", "current entry has to be set here" ); + if(!m_pImpl->pCurrentEntry) + return ; + int nIntValue = val.getInt(); + OUString sValue = val.getString(); + switch(Name) + { + case NS_ooxml::LN_CT_Pitch_val: + if (static_cast(nIntValue) == NS_ooxml::LN_Value_ST_Pitch_fixed) + ; + else if (static_cast(nIntValue) == NS_ooxml::LN_Value_ST_Pitch_variable) + ; + else if (static_cast(nIntValue) == NS_ooxml::LN_Value_ST_Pitch_default) + ; + else + SAL_WARN("writerfilter.dmapper", "FontTable::lcl_attribute: unhandled NS_ooxml::CT_Pitch_val: " << nIntValue); + break; + case NS_ooxml::LN_CT_Font_name: + m_pImpl->pCurrentEntry->sFontName = sValue; + break; + case NS_ooxml::LN_CT_Charset_val: + // w:characterSet has higher priority, set only if that one is not set + if( m_pImpl->pCurrentEntry->nTextEncoding == RTL_TEXTENCODING_DONTKNOW ) + { + m_pImpl->pCurrentEntry->nTextEncoding = rtl_getTextEncodingFromWindowsCharset( nIntValue ); + if( IsStarSymbol( m_pImpl->pCurrentEntry->sFontName )) + m_pImpl->pCurrentEntry->nTextEncoding = RTL_TEXTENCODING_SYMBOL; + } + break; + case NS_ooxml::LN_CT_Charset_characterSet: + { + OString tmp; + sValue.convertToString( &tmp, RTL_TEXTENCODING_ASCII_US, OUSTRING_TO_OSTRING_CVTFLAGS ); + m_pImpl->pCurrentEntry->nTextEncoding = rtl_getTextEncodingFromMimeCharset( tmp.getStr() ); + // Older LO versions used to write incorrect character set for OpenSymbol, fix. + if( IsStarSymbol( m_pImpl->pCurrentEntry->sFontName )) + m_pImpl->pCurrentEntry->nTextEncoding = RTL_TEXTENCODING_SYMBOL; + break; + } + default: ; + } +} + +void FontTable::lcl_sprm(Sprm& rSprm) +{ + SAL_WARN_IF( !m_pImpl->pCurrentEntry, "writerfilter.dmapper", "current entry has to be set here" ); + if(!m_pImpl->pCurrentEntry) + return ; + sal_uInt32 nSprmId = rSprm.getId(); + + switch(nSprmId) + { + case NS_ooxml::LN_CT_Font_charset: + case NS_ooxml::LN_CT_Font_pitch: + resolveSprm( rSprm ); + break; + case NS_ooxml::LN_CT_Font_embedRegular: + case NS_ooxml::LN_CT_Font_embedBold: + case NS_ooxml::LN_CT_Font_embedItalic: + case NS_ooxml::LN_CT_Font_embedBoldItalic: + { + writerfilter::Reference< Properties >::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + EmbeddedFontHandler handler(*this, m_pImpl->pCurrentEntry->sFontName, + nSprmId == NS_ooxml::LN_CT_Font_embedRegular ? "" + : nSprmId == NS_ooxml::LN_CT_Font_embedBold ? "b" + : nSprmId == NS_ooxml::LN_CT_Font_embedItalic ? "i" + : /*NS_ooxml::LN_CT_Font_embedBoldItalic*/ "bi" ); + pProperties->resolve( handler ); + } + break; + } + case NS_ooxml::LN_CT_Font_altName: + break; + case NS_ooxml::LN_CT_Font_panose1: + break; + case NS_ooxml::LN_CT_Font_family: + break; + case NS_ooxml::LN_CT_Font_sig: + break; + case NS_ooxml::LN_CT_Font_notTrueType: + break; + default: + SAL_WARN("writerfilter.dmapper", "FontTable::lcl_sprm: unhandled token: " << nSprmId); + break; + } +} + +void FontTable::resolveSprm(Sprm & r_Sprm) +{ + writerfilter::Reference::Pointer_t pProperties = r_Sprm.getProps(); + if( pProperties ) + pProperties->resolve(*this); +} + +void FontTable::lcl_entry(writerfilter::Reference::Pointer_t ref) +{ + //create a new font entry + SAL_WARN_IF( m_pImpl->pCurrentEntry, "writerfilter.dmapper", "current entry has to be NULL here" ); + m_pImpl->pCurrentEntry = new FontEntry; + ref->resolve(*this); + //append it to the table + m_pImpl->aFontEntries.push_back( m_pImpl->pCurrentEntry ); + m_pImpl->pCurrentEntry.clear(); +} + +void FontTable::lcl_startSectionGroup() +{ +} + +void FontTable::lcl_endSectionGroup() +{ +} + +void FontTable::lcl_startParagraphGroup() +{ +} + +void FontTable::lcl_endParagraphGroup() +{ +} + +void FontTable::lcl_startCharacterGroup() +{ +} + +void FontTable::lcl_endCharacterGroup() +{ +} + +void FontTable::lcl_text(const sal_uInt8*, size_t ) +{ +} + +void FontTable::lcl_utext(const sal_uInt8* , size_t) +{ +} + +void FontTable::lcl_props(writerfilter::Reference::Pointer_t) +{ +} + +void FontTable::lcl_table(Id, writerfilter::Reference
::Pointer_t) +{ +} + +void FontTable::lcl_substream(Id, ::writerfilter::Reference::Pointer_t) +{ +} + +void FontTable::lcl_startShape(uno::Reference const&) +{ +} + +void FontTable::lcl_endShape( ) +{ +} + +FontEntry::Pointer_t FontTable::getFontEntry(sal_uInt32 nIndex) +{ + return (m_pImpl->aFontEntries.size() > nIndex) + ? m_pImpl->aFontEntries[nIndex] + : FontEntry::Pointer_t(); +} + +sal_uInt32 FontTable::size() +{ + return m_pImpl->aFontEntries.size(); +} + +bool FontTable::addEmbeddedFont(const css::uno::Reference& stream, + const OUString& fontName, const char* extra, + std::vector key) +{ + if (!m_pImpl->xEmbeddedFontHelper) + m_pImpl->xEmbeddedFontHelper.reset(new EmbeddedFontsHelper); + return m_pImpl->xEmbeddedFontHelper->addEmbeddedFont(stream, fontName, extra, key); +} + +EmbeddedFontHandler::EmbeddedFontHandler(FontTable& rFontTable, const OUString& _fontName, const char* _style ) +: LoggedProperties("EmbeddedFontHandler") +, fontTable( rFontTable ) +, fontName( _fontName ) +, style( _style ) +{ +} + +EmbeddedFontHandler::~EmbeddedFontHandler() +{ + if( !inputStream.is()) + return; + std::vector< unsigned char > key( 32 ); + if( !fontKey.isEmpty()) + { // key for unobfuscating + // 1 3 5 7 10 2 5 7 20 2 5 7 9 1 3 5 + // {62E79491-959F-41E9-B76B-6B32631DEA5C} + static const int pos[ 16 ] = { 35, 33, 31, 29, 27, 25, 22, 20, 17, 15, 12, 10, 7, 5, 3, 1 }; + for( int i = 0; + i < 16; + ++i ) + { + int v1 = fontKey[ pos[ i ]]; + int v2 = fontKey[ pos[ i ] + 1 ]; + assert(( v1 >= '0' && v1 <= '9' ) || ( v1 >= 'A' && v1 <= 'F' )); + assert(( v2 >= '0' && v2 <= '9' ) || ( v2 >= 'A' && v2 <= 'F' )); + int val = ( v1 - ( v1 <= '9' ? '0' : 'A' - 10 )) * 16 + v2 - ( v2 <= '9' ? '0' : 'A' - 10 ); + key[ i ] = val; + key[ i + 16 ] = val; + } + } + fontTable.addEmbeddedFont( inputStream, fontName, style, key ); + inputStream->closeInput(); +} + +void EmbeddedFontHandler::lcl_attribute( Id name, Value& val ) +{ + OUString sValue = val.getString(); + switch( name ) + { + case NS_ooxml::LN_CT_FontRel_fontKey: + fontKey = sValue; + break; + case NS_ooxml::LN_CT_Rel_id: + break; + case NS_ooxml::LN_CT_FontRel_subsetted: + break; // TODO? Let's just ignore this for now and hope + // it doesn't break anything. + case NS_ooxml::LN_inputstream: // the actual font data as stream + val.getAny() >>= inputStream; + break; + default: + break; + } +} + +void EmbeddedFontHandler::lcl_sprm( Sprm& ) +{ +} + + +}//namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/FontTable.hxx b/writerfilter/source/dmapper/FontTable.hxx new file mode 100644 index 000000000..edb8b1480 --- /dev/null +++ b/writerfilter/source/dmapper/FontTable.hxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FONTTABLE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FONTTABLE_HXX + +#include +#include +#include "LoggedResources.hxx" +#include + +namespace writerfilter { +namespace dmapper +{ + +struct FontTable_Impl; +struct FontEntry : public virtual SvRefBase +{ + typedef tools::SvRef Pointer_t; + + OUString sFontName; + sal_Int32 nTextEncoding; + FontEntry() : + nTextEncoding( RTL_TEXTENCODING_DONTKNOW ) + {} +}; + +class FontTable : public LoggedProperties, public LoggedTable + /*,public BinaryObj*/, public LoggedStream +{ + std::unique_ptr m_pImpl; + + public: + FontTable(); + virtual ~FontTable() override; + + sal_uInt32 size(); + FontEntry::Pointer_t getFontEntry(sal_uInt32 nIndex); + + bool addEmbeddedFont(const css::uno::Reference& stream, + const OUString& fontName, const char* extra, + std::vector key); + + private: + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + void resolveSprm(Sprm & r_sprm); + + // Table + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) override; + + // Stream + virtual void lcl_startSectionGroup() override; + virtual void lcl_endSectionGroup() override; + virtual void lcl_startParagraphGroup() override; + virtual void lcl_endParagraphGroup() override; + virtual void lcl_startCharacterGroup() override; + virtual void lcl_endCharacterGroup() override; + virtual void lcl_text(const sal_uInt8 * data, size_t len) override; + virtual void lcl_utext(const sal_uInt8 * data, size_t len) override; + virtual void lcl_props(writerfilter::Reference::Pointer_t ref) override; + virtual void lcl_table(Id name, + writerfilter::Reference
::Pointer_t ref) override; + virtual void lcl_substream(Id name, + ::writerfilter::Reference::Pointer_t ref) override; + virtual void lcl_startShape(css::uno::Reference const& xShape) override; + virtual void lcl_endShape( ) override; +}; +typedef tools::SvRef< FontTable > FontTablePtr; + +class EmbeddedFontHandler : public LoggedProperties +{ +public: + EmbeddedFontHandler(FontTable& rFontTable, const OUString& fontName, const char* style); + virtual ~EmbeddedFontHandler() override; +private: + virtual void lcl_attribute( Id name, Value& val ) override; + virtual void lcl_sprm( Sprm& rSprm ) override; + FontTable& fontTable; + OUString fontName; + const char* const style; + OUString fontKey; + css::uno::Reference inputStream; +}; + + +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/FormControlHelper.cxx b/writerfilter/source/dmapper/FormControlHelper.cxx new file mode 100644 index 000000000..9c89bc0ad --- /dev/null +++ b/writerfilter/source/dmapper/FormControlHelper.cxx @@ -0,0 +1,375 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FormControlHelper.hxx" +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + +struct FormControlHelper::FormControlHelper_Impl : public virtual SvRefBase +{ + FieldId m_eFieldId; + awt::Size aSize; + uno::Reference rDrawPage; + uno::Reference rForm; + uno::Reference rFormComponent; + uno::Reference rServiceFactory; + uno::Reference rTextDocument; + + uno::Reference const & getDrawPage(); + uno::Reference const & getServiceFactory(); + uno::Reference const & getForm(); + uno::Reference getFormComps(); +}; + +uno::Reference const & FormControlHelper::FormControlHelper_Impl::getDrawPage() +{ + if (! rDrawPage.is()) + { + uno::Reference + xDrawPageSupplier(rTextDocument, uno::UNO_QUERY); + if (xDrawPageSupplier.is()) + rDrawPage = xDrawPageSupplier->getDrawPage(); + } + + return rDrawPage; +} + +uno::Reference const & FormControlHelper::FormControlHelper_Impl::getServiceFactory() +{ + if (! rServiceFactory.is()) + rServiceFactory.set(rTextDocument, uno::UNO_QUERY); + + return rServiceFactory; +} + +uno::Reference const & FormControlHelper::FormControlHelper_Impl::getForm() +{ + if (! rForm.is()) + { + uno::Reference xFormsSupplier(getDrawPage(), uno::UNO_QUERY); + + if (xFormsSupplier.is()) + { + uno::Reference xFormsNamedContainer(xFormsSupplier->getForms()); + static const char sDOCXForm[] = "DOCX-Standard"; + + OUString sFormName(sDOCXForm); + sal_uInt16 nUnique = 0; + + while (xFormsNamedContainer->hasByName(sFormName)) + { + ++nUnique; + sFormName = sDOCXForm + OUString::number(nUnique); + } + + uno::Reference xForm(getServiceFactory()->createInstance("com.sun.star.form.component.Form")); + if (xForm.is()) + { + uno::Reference + xFormProperties(xForm, uno::UNO_QUERY); + uno::Any aAny(sFormName); + xFormProperties->setPropertyValue("Name", aAny); + } + + rForm.set(xForm, uno::UNO_QUERY); + + uno::Reference xForms(xFormsNamedContainer, uno::UNO_QUERY); + uno::Any aAny(xForm); + xForms->insertByIndex(xForms->getCount(), aAny); + } + } + + return rForm; +} + +uno::Reference FormControlHelper::FormControlHelper_Impl::getFormComps() +{ + uno::Reference xIndexContainer(getForm(), uno::UNO_QUERY); + + return xIndexContainer; +} + +FormControlHelper::FormControlHelper(FieldId eFieldId, + uno::Reference const& xTextDocument, + FFDataHandler::Pointer_t const & pFFData) + : m_pFFData(pFFData), m_pImpl(new FormControlHelper_Impl) +{ + m_pImpl->m_eFieldId = eFieldId; + m_pImpl->rTextDocument = xTextDocument; +} + +FormControlHelper::~FormControlHelper() +{ +} + +bool FormControlHelper::createCheckbox(uno::Reference const& xTextRange, + const OUString & rControlName) +{ + if ( !m_pFFData ) + return false; + uno::Reference + xServiceFactory(m_pImpl->getServiceFactory()); + + if (! xServiceFactory.is()) + return false; + + uno::Reference xInterface = xServiceFactory->createInstance("com.sun.star.form.component.CheckBox"); + + if (!xInterface.is()) + return false; + + m_pImpl->rFormComponent.set(xInterface, uno::UNO_QUERY); + if (!m_pImpl->rFormComponent.is()) + return false; + + uno::Reference xPropSet(xInterface, uno::UNO_QUERY); + + sal_uInt32 nCheckBoxHeight = 16 * m_pFFData->getCheckboxHeight(); + + if (m_pFFData->getCheckboxAutoHeight()) + { + uno::Reference xTextRangeProps(xTextRange, uno::UNO_QUERY); + + try + { + float fCheckBoxHeight = 0.0; + xTextRangeProps->getPropertyValue("CharHeight") >>= fCheckBoxHeight; + nCheckBoxHeight = static_cast(floor(fCheckBoxHeight * 35.3)); + } + catch (beans::UnknownPropertyException &) + { + } + } + + m_pImpl->aSize.Width = nCheckBoxHeight; + m_pImpl->aSize.Height = m_pImpl->aSize.Width; + + if (!m_pFFData->getStatusText().isEmpty()) + { + xPropSet->setPropertyValue("HelpText", uno::Any(m_pFFData->getStatusText())); + } + + xPropSet->setPropertyValue("DefaultState", uno::Any(m_pFFData->getCheckboxChecked())); + + if (!m_pFFData->getHelpText().isEmpty()) + { + xPropSet->setPropertyValue("HelpF1Text", uno::Any(m_pFFData->getHelpText())); + } + + xPropSet->setPropertyValue("Name", uno::Any(rControlName)); + + return true; +} + +void FormControlHelper::processField(uno::Reference const& xFormField) +{ + // Set field type first before adding parameters. + if (m_pImpl->m_eFieldId == FIELD_FORMTEXT ) + { + xFormField->setFieldType(ODF_FORMTEXT); + } + else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX ) + { + xFormField->setFieldType(ODF_FORMCHECKBOX); + } + else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN ) + { + xFormField->setFieldType(ODF_FORMDROPDOWN); + } + + uno::Reference xNameCont = xFormField->getParameters(); + uno::Reference xNamed( xFormField, uno::UNO_QUERY ); + if ( m_pFFData && xNamed.is() && xNameCont.is() ) + { + OUString sTmp = m_pFFData->getEntryMacro(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "EntryMacro", uno::makeAny(sTmp) ); + sTmp = m_pFFData->getExitMacro(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "ExitMacro", uno::makeAny(sTmp) ); + + sTmp = m_pFFData->getHelpText(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Help", uno::makeAny(sTmp) ); + + sTmp = m_pFFData->getStatusText(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Hint", uno::makeAny(sTmp) ); + + if (m_pImpl->m_eFieldId == FIELD_FORMTEXT ) + { + sTmp = m_pFFData->getName(); + try + { + if ( !sTmp.isEmpty() ) + xNamed->setName( sTmp ); + } + catch ( uno::Exception& ) + { + TOOLS_INFO_EXCEPTION("writerfilter", "Set Formfield name failed"); + } + + sTmp = m_pFFData->getTextType(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Type", uno::makeAny(sTmp) ); + + const sal_uInt16 nMaxLength = m_pFFData->getTextMaxLength(); + if ( nMaxLength ) + { + xNameCont->insertByName( "MaxLength", uno::makeAny(nMaxLength) ); + } + + sTmp = m_pFFData->getTextDefault(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Content", uno::makeAny(sTmp) ); + + sTmp = m_pFFData->getTextFormat(); + if ( !sTmp.isEmpty() ) + xNameCont->insertByName( "Format", uno::makeAny(sTmp) ); + } + else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX ) + { + uno::Reference xPropSet(xFormField, uno::UNO_QUERY); + uno::Any aAny; + aAny <<= m_pFFData->getCheckboxChecked(); + if ( xPropSet.is() ) + xPropSet->setPropertyValue("Checked", aAny); + } + else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN ) + { + const FFDataHandler::DropDownEntries_t& rEntries = m_pFFData->getDropDownEntries(); + if (!rEntries.empty()) + { + if ( xNameCont->hasByName(ODF_FORMDROPDOWN_LISTENTRY) ) + xNameCont->replaceByName(ODF_FORMDROPDOWN_LISTENTRY, uno::makeAny(comphelper::containerToSequence(rEntries))); + else + xNameCont->insertByName(ODF_FORMDROPDOWN_LISTENTRY, uno::makeAny(comphelper::containerToSequence(rEntries))); + + sal_Int32 nResult = m_pFFData->getDropDownResult().toInt32(); + if ( nResult ) + { + if ( xNameCont->hasByName(ODF_FORMDROPDOWN_RESULT) ) + xNameCont->replaceByName(ODF_FORMDROPDOWN_RESULT, uno::makeAny( nResult ) ); + else + xNameCont->insertByName(ODF_FORMDROPDOWN_RESULT, uno::makeAny( nResult ) ); + } + } + } + } +} + +void FormControlHelper::insertControl(uno::Reference const& xTextRange) +{ + bool bCreated = false; + if ( !m_pFFData ) + return; + uno::Reference xFormCompsByName(m_pImpl->getForm(), uno::UNO_QUERY); + uno::Reference xFormComps(m_pImpl->getFormComps()); + if (! xFormComps.is()) + return; + + sal_Int32 nControl = 0; + bool bDone = false; + OUString sControlName; + + do + { + OUString sTmp = "Control" + OUString::number(nControl); + + nControl++; + if (! xFormCompsByName->hasByName(sTmp)) + { + sControlName = sTmp; + bDone = true; + } + } + while (! bDone); + + switch (m_pImpl->m_eFieldId) + { + case FIELD_FORMCHECKBOX: + bCreated = createCheckbox(xTextRange, sControlName); + break; + default: + break; + } + + if (!bCreated) + return; + + uno::Any aAny(m_pImpl->rFormComponent); + xFormComps->insertByIndex(xFormComps->getCount(), aAny); + + if (! m_pImpl->getServiceFactory().is()) + return; + + uno::Reference xInterface = m_pImpl->getServiceFactory()->createInstance("com.sun.star.drawing.ControlShape"); + + if (! xInterface.is()) + return; + + uno::Reference xShape(xInterface, uno::UNO_QUERY); + + if (! xShape.is()) + return; + + xShape->setSize(m_pImpl->aSize); + + uno::Reference xShapeProps(xShape, uno::UNO_QUERY); + + sal_uInt16 nTmp = sal_uInt16(text::TextContentAnchorType_AS_CHARACTER); + xShapeProps->setPropertyValue("AnchorType", uno::makeAny(nTmp)); + + nTmp = text::VertOrientation::CENTER; + xShapeProps->setPropertyValue("VertOrient", uno::makeAny(nTmp)); + + xShapeProps->setPropertyValue("TextRange", uno::Any(xTextRange)); + + uno::Reference xControlShape(xShape, uno::UNO_QUERY); + uno::Reference xControlModel(m_pImpl->rFormComponent, uno::UNO_QUERY); + xControlShape->setControl(xControlModel); + + m_pImpl->getDrawPage()->add(xShape); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/FormControlHelper.hxx b/writerfilter/source/dmapper/FormControlHelper.hxx new file mode 100644 index 000000000..dd7f7d38c --- /dev/null +++ b/writerfilter/source/dmapper/FormControlHelper.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FORMCONTROLHELPER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FORMCONTROLHELPER_HXX + +#include "FFDataHandler.hxx" +#include +#include +#include +#include "FieldTypes.hxx" + +namespace writerfilter { +namespace dmapper { + +class FormControlHelper : public virtual SvRefBase +{ +public: + typedef tools::SvRef Pointer_t; + FormControlHelper(FieldId eFieldId, + css::uno::Reference const& rTextDocument, + FFDataHandler::Pointer_t const & pFFData); + ~FormControlHelper() override; + + void insertControl(css::uno::Reference const& xTextRange); + void processField(css::uno::Reference const& xFormField); + bool hasFFDataHandler() const { return (m_pFFData != nullptr); } +private: + FFDataHandler::Pointer_t m_pFFData; + struct FormControlHelper_Impl; + tools::SvRef m_pImpl; + + bool createCheckbox(css::uno::Reference const& xTextRange, + const OUString & rControlName); +}; + +} +} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_FORMCONTROLHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/GraphicHelpers.cxx b/writerfilter/source/dmapper/GraphicHelpers.cxx new file mode 100644 index 000000000..a2275d95b --- /dev/null +++ b/writerfilter/source/dmapper/GraphicHelpers.cxx @@ -0,0 +1,330 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "GraphicHelpers.hxx" +#include "TagLogger.hxx" +#include +#include "PropertyIds.hxx" + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +namespace writerfilter::dmapper { + +using namespace com::sun::star; + +PositionHandler::PositionHandler( std::pair& rPositionOffsets, std::pair& rAligns ) : +LoggedProperties("PositionHandler"), +m_nOrient(text::VertOrientation::NONE), +m_nRelation(text::RelOrientation::FRAME), +m_nPosition(0), +m_rPositionOffsets(rPositionOffsets), +m_rAligns(rAligns) +{ +} + +PositionHandler::~PositionHandler( ) +{ +} + +void PositionHandler::lcl_attribute( Id aName, Value& rVal ) +{ + sal_Int32 nIntValue = rVal.getInt( ); + switch ( aName ) + { + case NS_ooxml::LN_CT_PosV_relativeFrom: + { + switch ( nIntValue ) + { + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_margin: + m_nRelation = text::RelOrientation::PAGE_PRINT_AREA; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_page: + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_topMargin: // fallthrough intended + m_nRelation = text::RelOrientation::PAGE_FRAME; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_bottomMargin: + m_nRelation = text::RelOrientation::PAGE_PRINT_AREA_BOTTOM; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_paragraph: + m_nRelation = text::RelOrientation::FRAME; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_line: + m_nRelation = text::RelOrientation::TEXT_LINE; + break; + + // TODO There are some other unhandled values + default: + SAL_WARN("writerfilter", "unhandled case (" << nIntValue << ") in NS_ooxml::LN_CT_PosV_relativeFrom"); + } + } + break; + + case NS_ooxml::LN_CT_PosH_relativeFrom: + { + switch ( nIntValue ) + { + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_margin: + m_nRelation = text::RelOrientation::PAGE_PRINT_AREA; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_page: + m_nRelation = text::RelOrientation::PAGE_FRAME; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_insideMargin: + m_nRelation = text::RelOrientation::PAGE_FRAME; + m_bPageToggle = true; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_column: + m_nRelation = text::RelOrientation::FRAME; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_character: + m_nRelation = text::RelOrientation::CHAR; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_leftMargin: + m_nRelation = text::RelOrientation::PAGE_LEFT; + break; + + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_rightMargin: + m_nRelation = text::RelOrientation::PAGE_RIGHT; + break; + + // TODO There are some other unhandled values + default: + SAL_WARN("writerfilter", "unhandled case (" << nIntValue << ") in NS_ooxml::LN_CT_PosH_relativeFrom"); + } + } + break; + default: +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + break; + } +} + +void PositionHandler::lcl_sprm(Sprm& rSprm) +{ + sal_uInt32 nSprmId = rSprm.getId(); + + switch (nSprmId) + { + case NS_ooxml::LN_CT_PosH_posOffset: + m_nPosition = oox::drawingml::convertEmuToHmm(m_rPositionOffsets.first.toInt32()); + m_rPositionOffsets.first.clear(); + break; + case NS_ooxml::LN_CT_PosV_posOffset: + m_nPosition = oox::drawingml::convertEmuToHmm(m_rPositionOffsets.second.toInt32()); + m_rPositionOffsets.second.clear(); + break; + case NS_ooxml::LN_CT_PosH_align: + { + OUString& rAlign = m_rAligns.first; + if (rAlign == "left") + m_nOrient = text::HoriOrientation::LEFT; + else if (rAlign == "right") + m_nOrient = text::HoriOrientation::RIGHT; + else if (rAlign == "center") + m_nOrient = text::HoriOrientation::CENTER; + else if (rAlign == "inside") + m_nOrient = text::HoriOrientation::INSIDE; + else if (rAlign == "outside") + m_nOrient = text::HoriOrientation::OUTSIDE; + rAlign.clear(); + break; + } + case NS_ooxml::LN_CT_PosV_align: + { + OUString& rAlign = m_rAligns.second; + if (rAlign == "top") + m_nOrient = text::VertOrientation::TOP; + else if (rAlign == "bottom") + m_nOrient = text::VertOrientation::BOTTOM; + else if (rAlign == "center") + m_nOrient = text::VertOrientation::CENTER; + else if (rAlign == "inside") + m_nOrient = text::VertOrientation::NONE; + else if (rAlign == "outside") + m_nOrient = text::VertOrientation::NONE; + rAlign.clear(); + break; + } + } +} + +sal_Int16 PositionHandler::orientation() const +{ + if( m_nRelation == text::RelOrientation::TEXT_LINE ) + { // It appears that to 'line of text' alignment is backwards to other alignments, + // 'top' meaning putting on top of the line instead of having top at the line. + if( m_nOrient == text::VertOrientation::TOP ) + return text::VertOrientation::BOTTOM; + else if( m_nOrient == text::VertOrientation::BOTTOM ) + return text::VertOrientation::TOP; + } + return m_nOrient; +} + +WrapHandler::WrapHandler( ) : +LoggedProperties("WrapHandler"), + m_nType( 0 ), + m_nSide( 0 ) +{ +} + +WrapHandler::~WrapHandler( ) +{ +} + +void WrapHandler::lcl_attribute( Id aName, Value& rVal ) +{ + switch ( aName ) + { + case NS_ooxml::LN_CT_Wrap_type: + m_nType = sal_Int32( rVal.getInt( ) ); + break; + case NS_ooxml::LN_CT_Wrap_side: + m_nSide = sal_Int32( rVal.getInt( ) ); + break; + default:; + } +} + +void WrapHandler::lcl_sprm( Sprm& ) +{ +} + +text::WrapTextMode WrapHandler::getWrapMode( ) const +{ + // The wrap values do not map directly to our wrap mode, + // e.g. none in .docx actually means through in LO. + text::WrapTextMode nMode = text::WrapTextMode_THROUGH; + + switch ( m_nType ) + { + case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_square: + // through and tight are somewhat complicated, approximate + case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_tight: + case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_through: + { + switch ( m_nSide ) + { + case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_left: + nMode = text::WrapTextMode_LEFT; + break; + case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapSide_right: + nMode = text::WrapTextMode_RIGHT; + break; + default: + nMode = text::WrapTextMode_PARALLEL; + } + } + break; + case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_topAndBottom: + nMode = text::WrapTextMode_NONE; + break; + case NS_ooxml::LN_Value_vml_wordprocessingDrawing_ST_WrapType_none: + default: + nMode = text::WrapTextMode_THROUGH; + } + + return nMode; +} + + +void GraphicZOrderHelper::addItem(uno::Reference const& props, sal_Int32 const relativeHeight) +{ + items[ relativeHeight ] = props; +} + +// The relativeHeight value in .docx is an arbitrary number, where only the relative ordering matters. +// But in Writer, the z-order is index in 0..(numitems-1) range, so whenever a new item needs to be +// added in the proper z-order, it is necessary to find the proper index. +sal_Int32 GraphicZOrderHelper::findZOrder( sal_Int32 relativeHeight, bool bOldStyle ) +{ + // std::map is iterated sorted by key + auto it = std::find_if(items.cbegin(), items.cend(), + [relativeHeight, bOldStyle](const Items::value_type& rItem) { + // Old-style ordering differs in what should happen when there is already an item with the same z-order: + // we belong under it in case of new-style, but we belong above it in case of old-style. + return bOldStyle ? (rItem.first > relativeHeight) : (rItem.first >= relativeHeight); + } + ); + sal_Int32 itemZOrderOffset(0); // before the item + if( it == items.end()) // we're topmost + { + if( items.empty()) + return 0; + --it; + itemZOrderOffset = 1; // after the topmost + } + // SwXFrame::getPropertyValue throws uno::RuntimeException + // when its GetFrameFormat() returns nullptr + try { + sal_Int32 itemZOrder(0); + if( it->second->getPropertyValue(getPropertyName( PROP_Z_ORDER )) >>= itemZOrder ) + return itemZOrder + itemZOrderOffset; + } + catch (const uno::RuntimeException&) { + SAL_WARN("writerfilter", "Exception when getting item z-order"); + } + SAL_WARN( "writerfilter", "findZOrder() didn't find item z-order" ); + return 0; // this should not(?) happen +} + +GraphicNamingHelper::GraphicNamingHelper() + : m_nCounter(0) +{ +} + +OUString GraphicNamingHelper::NameGraphic(const OUString& rTemplate) +{ + OUString aRet = rTemplate; + + if (aRet.isEmpty()) + { + // Empty template: then auto-generate a unique name. + OUString aPrefix(SvxResId(STR_ObjNameSingulGRAF)); + aRet += aPrefix + OUString::number(++m_nCounter); + } + + return aRet; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/GraphicHelpers.hxx b/writerfilter/source/dmapper/GraphicHelpers.hxx new file mode 100644 index 000000000..d28f2fb50 --- /dev/null +++ b/writerfilter/source/dmapper/GraphicHelpers.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_GRAPHICHELPERS_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_GRAPHICHELPERS_HXX + +#include "LoggedResources.hxx" +#include + +#include + +namespace writerfilter { +namespace dmapper +{ + +class PositionHandler: public LoggedProperties +{ +public: + PositionHandler( std::pair& rPositionOffsets, std::pair& rAligns ); + virtual ~PositionHandler( ) override; + sal_Int16 orientation() const; + sal_Int16 relation() const { return m_nRelation;} + sal_Int32 position() const { return m_nPosition;} + bool GetPageToggle() const { return m_bPageToggle; } + private: + virtual void lcl_attribute( Id aName, Value& rVal ) override; + virtual void lcl_sprm( Sprm& rSprm ) override; + sal_Int16 m_nOrient; + sal_Int16 m_nRelation; + sal_Int32 m_nPosition; + std::pair& m_rPositionOffsets; + std::pair& m_rAligns; + bool m_bPageToggle = false; +}; + +class WrapHandler: public LoggedProperties +{ +public: + WrapHandler( ); + virtual ~WrapHandler( ) override; + + css::text::WrapTextMode getWrapMode( ) const; + + private: + virtual void lcl_attribute( Id aName, Value& rVal ) override; + virtual void lcl_sprm( Sprm& rSprm ) override; + + sal_Int32 m_nType; + sal_Int32 m_nSide; +}; + +/// Keeps track of the next available unique automatic name. +class GraphicNamingHelper +{ + int m_nCounter; + +public: + GraphicNamingHelper(); + /// Name a graphic based on rTemplate. + OUString NameGraphic(const OUString& rTemplate); +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx new file mode 100644 index 000000000..372e9f408 --- /dev/null +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -0,0 +1,1585 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "DomainMapper.hxx" +#include +#include + +#include "ConversionHelper.hxx" +#include "GraphicHelpers.hxx" +#include "GraphicImport.hxx" +#include "PropertyMap.hxx" +#include "TagLogger.hxx" +#include "WrapPolygonHandler.hxx" +#include "util.hxx" + +#include + +using namespace css; + +namespace +{ +bool isTopGroupObj(const uno::Reference& xShape) +{ + SdrObject* pObject = GetSdrObjectFromXShape(xShape); + if (!pObject) + return false; + + if (pObject->getParentSdrObjectFromSdrObject()) + return false; + + return pObject->IsGroupObject(); +} +} + +namespace writerfilter::dmapper +{ + +namespace { + +class XInputStreamHelper : public cppu::WeakImplHelper +{ + const sal_uInt8* m_pBuffer; + const sal_Int32 m_nLength; + sal_Int32 m_nPosition; +public: + XInputStreamHelper(const sal_uInt8* buf, size_t len); + + virtual ::sal_Int32 SAL_CALL readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) override; + virtual ::sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) override; + virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) override; + virtual ::sal_Int32 SAL_CALL available( ) override; + virtual void SAL_CALL closeInput( ) override; +}; + +} + +XInputStreamHelper::XInputStreamHelper(const sal_uInt8* buf, size_t len) : + m_pBuffer( buf ), + m_nLength( len ), + m_nPosition( 0 ) +{ +} + +sal_Int32 XInputStreamHelper::readBytes( uno::Sequence& aData, sal_Int32 nBytesToRead ) +{ + return readSomeBytes( aData, nBytesToRead ); +} + +sal_Int32 XInputStreamHelper::readSomeBytes( uno::Sequence& aData, sal_Int32 nMaxBytesToRead ) +{ + sal_Int32 nRet = 0; + if( nMaxBytesToRead > 0 ) + { + if( nMaxBytesToRead > m_nLength - m_nPosition ) + nRet = m_nLength - m_nPosition; + else + nRet = nMaxBytesToRead; + aData.realloc( nRet ); + sal_Int8* pData = aData.getArray(); + if( nRet ) + { + memcpy( pData, m_pBuffer + m_nPosition, nRet ); + m_nPosition += nRet; + } + } + return nRet; +} + + +void XInputStreamHelper::skipBytes( sal_Int32 nBytesToSkip ) +{ + if( nBytesToSkip < 0 || m_nPosition + nBytesToSkip > m_nLength) + throw io::BufferSizeExceededException(); + m_nPosition += nBytesToSkip; +} + + +sal_Int32 XInputStreamHelper::available( ) +{ + return m_nLength - m_nPosition; +} + + +void XInputStreamHelper::closeInput( ) +{ +} + +namespace { + +struct GraphicBorderLine +{ + sal_Int32 nLineWidth; + bool bHasShadow; + + GraphicBorderLine() : + nLineWidth(0) + ,bHasShadow(false) + {} + + bool isEmpty() const + { + return nLineWidth == 0 && !bHasShadow; + } + +}; + +} + +class GraphicImport_Impl +{ +private: + sal_Int32 nXSize; + bool bXSizeValid; + sal_Int32 nYSize; + bool bYSizeValid; + +public: + GraphicImportType eGraphicImportType; + DomainMapper& rDomainMapper; + + sal_Int32 nLeftPosition; + sal_Int32 nTopPosition; + + bool bUseSimplePos; + sal_Int32 zOrder; + + sal_Int16 nHoriOrient; + sal_Int16 nHoriRelation; + bool bPageToggle = false; + sal_Int16 nVertOrient; + sal_Int16 nVertRelation; + text::WrapTextMode nWrap; + bool bLayoutInCell; + bool bAllowOverlap = true; + bool bOpaque; + bool bBehindDoc; + bool bContour; + bool bContourOutside; + WrapPolygon::Pointer_t mpWrapPolygon; + + sal_Int32 nLeftMargin; + sal_Int32 nLeftMarginOrig = 0; + sal_Int32 nRightMargin; + sal_Int32 nTopMargin; + sal_Int32 nBottomMargin; + + bool bShadow; + sal_Int32 nShadowXDistance; + sal_Int32 nShadowYDistance; + sal_Int32 nShadowColor; + sal_Int32 nShadowTransparence; + + sal_Int32 nContrast; + sal_Int32 nBrightness; + + static constexpr sal_Int32 nFillColor = 0xffffffff; + + drawing::ColorMode eColorMode; + + GraphicBorderLine aBorders[4]; + + bool bIsGraphic; + + bool bSizeProtected; + bool bPositionProtected; + bool bHidden; + + sal_Int32 nShapeOptionType; + + OUString sName; + OUString sAlternativeText; + OUString title; + OUString sHyperlinkURL; + std::pair& m_rPositionOffsets; + std::pair& m_rAligns; + std::queue& m_rPositivePercentages; + OUString sAnchorId; + comphelper::SequenceAsHashMap m_aInteropGrabBag; + std::optional m_oEffectExtentLeft; + std::optional m_oEffectExtentTop; + std::optional m_oEffectExtentRight; + std::optional m_oEffectExtentBottom; + + GraphicImport_Impl(GraphicImportType eImportType, DomainMapper& rDMapper, std::pair& rPositionOffsets, std::pair& rAligns, std::queue& rPositivePercentages) : + nXSize(0) + ,bXSizeValid(false) + ,nYSize(0) + ,bYSizeValid(false) + ,eGraphicImportType( eImportType ) + ,rDomainMapper( rDMapper ) + ,nLeftPosition(0) + ,nTopPosition(0) + ,bUseSimplePos(false) + ,zOrder(-1) + ,nHoriOrient( text::HoriOrientation::NONE ) + ,nHoriRelation( text::RelOrientation::FRAME ) + ,nVertOrient( text::VertOrientation::NONE ) + ,nVertRelation( text::RelOrientation::FRAME ) + ,nWrap(text::WrapTextMode_NONE) + ,bLayoutInCell(true) + ,bOpaque( !rDMapper.IsInHeaderFooter() ) + ,bBehindDoc(false) + ,bContour(false) + ,bContourOutside(true) + ,nLeftMargin(319) + ,nRightMargin(319) + ,nTopMargin(0) + ,nBottomMargin(0) + ,bShadow(false) + ,nShadowXDistance(0) + ,nShadowYDistance(0) + ,nShadowColor(0) + ,nShadowTransparence(0) + ,nContrast(0) + ,nBrightness(0) + ,eColorMode( drawing::ColorMode_STANDARD ) + ,bIsGraphic(false) + ,bSizeProtected(false) + ,bPositionProtected(false) + ,bHidden(false) + ,nShapeOptionType(0) + ,m_rPositionOffsets(rPositionOffsets) + ,m_rAligns(rAligns) + ,m_rPositivePercentages(rPositivePercentages) + { + if (eGraphicImportType == GraphicImportType::IMPORT_AS_DETECTED_INLINE + && !rDMapper.IsInShape()) + { + zOrder = 0; + } + } + + void setXSize(sal_Int32 _nXSize) + { + nXSize = _nXSize; + bXSizeValid = true; + } + + sal_uInt32 getXSize() const + { + return nXSize; + } + + bool isXSizeValid() const + { + return bXSizeValid; + } + + void setYSize(sal_Int32 _nYSize) + { + nYSize = _nYSize; + bYSizeValid = true; + } + + sal_uInt32 getYSize() const + { + return nYSize; + } + + bool isYSizeValis () const + { + return bYSizeValid; + } + + void applyMargins(const uno::Reference< beans::XPropertySet >& xGraphicObjectProperties) const + { + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_LEFT_MARGIN ), uno::makeAny(nLeftMargin)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_RIGHT_MARGIN ), uno::makeAny(nRightMargin)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_TOP_MARGIN ), uno::makeAny(nTopMargin)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_BOTTOM_MARGIN ), uno::makeAny(nBottomMargin)); + } + + void applyPosition(const uno::Reference< beans::XPropertySet >& xGraphicObjectProperties) const + { + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_HORI_ORIENT ), + uno::makeAny(nHoriOrient)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_VERT_ORIENT ), + uno::makeAny(nVertOrient)); + } + + void applyRelativePosition(const uno::Reference< beans::XPropertySet >& xGraphicObjectProperties, bool bRelativeOnly = false) const + { + if (!bRelativeOnly) + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_HORI_ORIENT_POSITION), + uno::makeAny(nLeftPosition)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_HORI_ORIENT_RELATION ), + uno::makeAny(nHoriRelation)); + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_PAGE_TOGGLE), + uno::makeAny(bPageToggle)); + if (!bRelativeOnly) + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_VERT_ORIENT_POSITION), + uno::makeAny(nTopPosition)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_VERT_ORIENT_RELATION ), + uno::makeAny(nVertRelation)); + } + + void applyZOrder(uno::Reference const & xGraphicObjectProperties) const + { + if (zOrder >= 0) + { + // tdf#120760 Send objects with behinddoc=true to the back. + sal_Int32 nZOrder = zOrder; + if (bBehindDoc && rDomainMapper.IsInHeaderFooter()) + nZOrder -= SAL_MAX_INT32; + GraphicZOrderHelper* pZOrderHelper = rDomainMapper.graphicZOrderHelper(); + bool bOldStyle = eGraphicImportType == GraphicImportType::IMPORT_AS_DETECTED_INLINE; + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_Z_ORDER), + uno::makeAny(pZOrderHelper->findZOrder(nZOrder, bOldStyle))); + pZOrderHelper->addItem(xGraphicObjectProperties, nZOrder); + } + } + + void applyName(uno::Reference const & xGraphicObjectProperties) const + { + try + { + // Ask the graphic naming helper to find out the name for this + // object: It's around till the end of the import, so it remembers + // what's the first free name. + uno::Reference< container::XNamed > xNamed( xGraphicObjectProperties, uno::UNO_QUERY_THROW ); + xNamed->setName(rDomainMapper.GetGraphicNamingHelper().NameGraphic(sName)); + + if ( sHyperlinkURL.getLength() > 0 ) + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_HYPER_LINK_U_R_L ), + uno::makeAny ( sHyperlinkURL )); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_DESCRIPTION ), + uno::makeAny( sAlternativeText )); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_TITLE ), + uno::makeAny( title )); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("writerfilter", "failed"); + } + } + + /// Getter for m_aInteropGrabBag, but also merges in the values from other members if they are set. + comphelper::SequenceAsHashMap const & getInteropGrabBag() + { + comphelper::SequenceAsHashMap aEffectExtent; + if (m_oEffectExtentLeft) + aEffectExtent["l"] <<= *m_oEffectExtentLeft; + if (m_oEffectExtentTop) + aEffectExtent["t"] <<= *m_oEffectExtentTop; + if (m_oEffectExtentRight) + aEffectExtent["r"] <<= *m_oEffectExtentRight; + if (m_oEffectExtentBottom) + aEffectExtent["b"] <<= *m_oEffectExtentBottom; + if (!aEffectExtent.empty()) + m_aInteropGrabBag["CT_EffectExtent"] <<= aEffectExtent.getAsConstPropertyValueList(); + return m_aInteropGrabBag; + } +}; + +GraphicImport::GraphicImport(uno::Reference const& xComponentContext, + uno::Reference const& xTextFactory, + DomainMapper& rDMapper, + GraphicImportType eImportType, + std::pair& rPositionOffsets, + std::pair& rAligns, + std::queue& rPositivePercentages) +: LoggedProperties("GraphicImport") +, LoggedTable("GraphicImport") +, LoggedStream("GraphicImport") +, m_pImpl(new GraphicImport_Impl(eImportType, rDMapper, rPositionOffsets, rAligns, rPositivePercentages)) +, m_xComponentContext(xComponentContext) +, m_xTextFactory(xTextFactory) +{ +} + +GraphicImport::~GraphicImport() +{ +} + +com::sun::star::awt::Point GraphicImport::GetGraphicObjectPosition() +{ + return (com::sun::star::awt::Point(m_pImpl->nLeftPosition, m_pImpl->nTopPosition)); +} + +void GraphicImport::handleWrapTextValue(sal_uInt32 nVal) +{ + switch (nVal) + { + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_bothSides: // 90920; + m_pImpl->nWrap = text::WrapTextMode_PARALLEL; + break; + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_left: // 90921; + m_pImpl->nWrap = text::WrapTextMode_LEFT; + break; + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_right: // 90922; + m_pImpl->nWrap = text::WrapTextMode_RIGHT; + break; + case NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_largest: // 90923; + m_pImpl->nWrap = text::WrapTextMode_DYNAMIC; + break; + default:; + } +} + +void GraphicImport::putPropertyToFrameGrabBag( const OUString& sPropertyName, const uno::Any& aPropertyValue ) +{ + beans::PropertyValue aProperty; + aProperty.Name = sPropertyName; + aProperty.Value = aPropertyValue; + + if (!m_xShape.is()) + return; + + uno::Reference< beans::XPropertySet > xSet(m_xShape, uno::UNO_QUERY_THROW); + + uno::Reference< beans::XPropertySetInfo > xSetInfo(xSet->getPropertySetInfo()); + if (!xSetInfo.is()) + return; + + OUString aGrabBagPropName; + uno::Reference xServiceInfo(m_xShape, uno::UNO_QUERY_THROW); + if (xServiceInfo->supportsService("com.sun.star.text.TextFrame")) + aGrabBagPropName = "FrameInteropGrabBag"; + else + aGrabBagPropName = "InteropGrabBag"; + + if (xSetInfo->hasPropertyByName(aGrabBagPropName)) + { + //Add pProperty to the end of the Sequence for aGrabBagPropName + uno::Sequence aTmp; + xSet->getPropertyValue(aGrabBagPropName) >>= aTmp; + std::vector aGrabBag(comphelper::sequenceToContainer >(aTmp)); + aGrabBag.push_back(aProperty); + + xSet->setPropertyValue(aGrabBagPropName, uno::makeAny(comphelper::containerToSequence(aGrabBag))); + } +} + +void GraphicImport::lcl_attribute(Id nName, Value& rValue) +{ + sal_Int32 nIntValue = rValue.getInt(); + switch( nName ) + { + case NS_ooxml::LN_CT_Hyperlink_URL://90682; + m_pImpl->sHyperlinkURL = rValue.getString(); + break; + case NS_ooxml::LN_blip: //the binary graphic data in a shape + { + writerfilter::Reference::Pointer_t pProperties = rValue.getProperties(); + if( pProperties ) + { + pProperties->resolve(*this); + } + } + break; + case NS_ooxml::LN_payload : + { + writerfilter::Reference::Pointer_t pPictureData = rValue.getBinary(); + if( pPictureData ) + pPictureData->resolve(*this); + } + break; + + //border properties + case NS_ooxml::LN_CT_Border_sz: + m_pImpl->aBorders[BORDER_TOP].nLineWidth = nIntValue; + break; + case NS_ooxml::LN_CT_Border_val: + //graphic borders don't support different line types + break; + case NS_ooxml::LN_CT_Border_space: + break; + case NS_ooxml::LN_CT_Border_shadow: + m_pImpl->aBorders[BORDER_TOP].bHasShadow = nIntValue != 0; + break; + case NS_ooxml::LN_CT_Border_frame: + break; + case NS_ooxml::LN_CT_PositiveSize2D_cx: + case NS_ooxml::LN_CT_PositiveSize2D_cy: + { + sal_Int32 nDim = oox::drawingml::convertEmuToHmm(nIntValue); + // drawingML equivalent of oox::vml::ShapeType::getAbsRectangle(): + // make sure a shape isn't hidden implicitly just because it has + // zero height or width. + if (nDim == 0) + nDim = 1; + + if( nName == NS_ooxml::LN_CT_PositiveSize2D_cx ) + m_pImpl->setXSize(nDim); + else + m_pImpl->setYSize(nDim); + } + break; + case NS_ooxml::LN_CT_EffectExtent_l: + m_pImpl->m_oEffectExtentLeft = nIntValue; + break; + case NS_ooxml::LN_CT_EffectExtent_t: + m_pImpl->m_oEffectExtentTop = nIntValue; + break; + case NS_ooxml::LN_CT_EffectExtent_r: + m_pImpl->m_oEffectExtentRight = nIntValue; + break; + case NS_ooxml::LN_CT_EffectExtent_b: + m_pImpl->m_oEffectExtentBottom = nIntValue; + break; + case NS_ooxml::LN_CT_NonVisualDrawingProps_id:// 90650; + //id of the object - ignored + break; + case NS_ooxml::LN_CT_NonVisualDrawingProps_name:// 90651; + //name of the object + m_pImpl->sName = rValue.getString(); + break; + case NS_ooxml::LN_CT_NonVisualDrawingProps_descr:// 90652; + //alternative text + m_pImpl->sAlternativeText = rValue.getString(); + break; + case NS_ooxml::LN_CT_NonVisualDrawingProps_title: + //alternative text + m_pImpl->title = rValue.getString(); + break; + case NS_ooxml::LN_CT_NonVisualDrawingProps_hidden: + m_pImpl->bHidden = (nIntValue == 1); + break; + case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noChangeAspect://90644; + //disallow aspect ratio change - ignored + break; + case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noMove:// 90645; + m_pImpl->bPositionProtected = true; + break; + case NS_ooxml::LN_CT_GraphicalObjectFrameLocking_noResize: // 90646; + m_pImpl->bSizeProtected = true; + break; + case NS_ooxml::LN_CT_Anchor_distT: // 90983; + case NS_ooxml::LN_CT_Anchor_distB: // 90984; + case NS_ooxml::LN_CT_Anchor_distL: // 90985; + case NS_ooxml::LN_CT_Anchor_distR: // 90986; + { + m_pImpl->nShapeOptionType = nName; + ProcessShapeOptions(rValue); + } + break; + case NS_ooxml::LN_CT_Anchor_simplePos_attr: // 90987; + m_pImpl->bUseSimplePos = nIntValue > 0; + break; + case NS_ooxml::LN_CT_Anchor_relativeHeight: // 90988; + m_pImpl->zOrder = nIntValue; + break; + case NS_ooxml::LN_CT_Anchor_behindDoc: // 90989; - in background + if (nIntValue > 0) + { + m_pImpl->bOpaque = false; + m_pImpl->bBehindDoc = true; + } + break; + case NS_ooxml::LN_CT_Anchor_locked: // 90990; - ignored + break; + case NS_ooxml::LN_CT_Anchor_layoutInCell: // 90991; - ignored + m_pImpl->bLayoutInCell = nIntValue != 0; + break; + case NS_ooxml::LN_CT_Anchor_hidden: // 90992; - ignored + break; + case NS_ooxml::LN_CT_Anchor_allowOverlap: + m_pImpl->bAllowOverlap = nIntValue != 0; + break; + case NS_ooxml::LN_CT_Anchor_wp14_anchorId: + case NS_ooxml::LN_CT_Inline_wp14_anchorId: + { + OUStringBuffer aBuffer = OUString::number(nIntValue, 16); + OUStringBuffer aString; + comphelper::string::padToLength(aString, 8 - aBuffer.getLength(), '0'); + aString.append(aBuffer.getStr()); + m_pImpl->sAnchorId = aString.makeStringAndClear().toAsciiUpperCase(); + } + break; + case NS_ooxml::LN_CT_Point2D_x: // 90405; + m_pImpl->nLeftPosition = ConversionHelper::convertTwipToMM100(nIntValue); + m_pImpl->nHoriRelation = text::RelOrientation::PAGE_FRAME; + m_pImpl->nHoriOrient = text::HoriOrientation::NONE; + break; + case NS_ooxml::LN_CT_Point2D_y: // 90406; + m_pImpl->nTopPosition = ConversionHelper::convertTwipToMM100(nIntValue); + m_pImpl->nVertRelation = text::RelOrientation::PAGE_FRAME; + m_pImpl->nVertOrient = text::VertOrientation::NONE; + break; + case NS_ooxml::LN_CT_WrapTight_wrapText: // 90934; + m_pImpl->bContour = true; + m_pImpl->bContourOutside = true; + + handleWrapTextValue(rValue.getInt()); + + break; + case NS_ooxml::LN_CT_WrapThrough_wrapText: + m_pImpl->bContour = true; + m_pImpl->bContourOutside = false; + + handleWrapTextValue(rValue.getInt()); + + break; + case NS_ooxml::LN_CT_WrapSquare_wrapText: //90928; + handleWrapTextValue(rValue.getInt()); + break; + case NS_ooxml::LN_shape: + { + uno::Reference< drawing::XShape> xShape; + rValue.getAny( ) >>= xShape; + if ( xShape.is( ) ) + { + // Is it a graphic image + bool bUseShape = true; + try + { + uno::Reference< beans::XPropertySet > xShapeProps + ( xShape, uno::UNO_QUERY_THROW ); + + uno::Reference xGraphic; + xShapeProps->getPropertyValue("Graphic") >>= xGraphic; + + sal_Int32 nRotation = 0; + xShapeProps->getPropertyValue("RotateAngle") >>= nRotation; + + css::beans::PropertyValues aGrabBag; + xShapeProps->getPropertyValue("InteropGrabBag") >>= aGrabBag; + // if the shape contains effects in the grab bag, we should not transform it + // in a XTextContent so those effects can be preserved + bool bContainsEffects = std::any_of(aGrabBag.begin(), aGrabBag.end(), [](const auto& rProp) { + return rProp.Name == "EffectProperties" + || rProp.Name == "3DEffectProperties" + || rProp.Name == "ArtisticEffectProperties"; + }); + + xShapeProps->getPropertyValue("Shadow") >>= m_pImpl->bShadow; + if (m_pImpl->bShadow) + { + xShapeProps->getPropertyValue("ShadowXDistance") >>= m_pImpl->nShadowXDistance; + xShapeProps->getPropertyValue("ShadowYDistance") >>= m_pImpl->nShadowYDistance; + xShapeProps->getPropertyValue("ShadowColor") >>= m_pImpl->nShadowColor; + xShapeProps->getPropertyValue("ShadowTransparence") >>= m_pImpl->nShadowTransparence; + } + + xShapeProps->getPropertyValue("GraphicColorMode") >>= m_pImpl->eColorMode; + xShapeProps->getPropertyValue("AdjustLuminance") >>= m_pImpl->nBrightness; + xShapeProps->getPropertyValue("AdjustContrast") >>= m_pImpl->nContrast; + + // fdo#70457: transform XShape into a SwXTextGraphicObject only if there's no rotation + if ( nRotation == 0 && !bContainsEffects ) + m_xGraphicObject = createGraphicObject( xGraphic, xShapeProps ); + + bUseShape = !m_xGraphicObject.is( ); + + if ( !bUseShape ) + { + // Define the object size + uno::Reference< beans::XPropertySet > xGraphProps( m_xGraphicObject, + uno::UNO_QUERY ); + awt::Size aSize = xShape->getSize( ); + xGraphProps->setPropertyValue("Height", + uno::makeAny( aSize.Height ) ); + xGraphProps->setPropertyValue("Width", + uno::makeAny( aSize.Width ) ); + + text::GraphicCrop aGraphicCrop( 0, 0, 0, 0 ); + uno::Reference< beans::XPropertySet > xSourceGraphProps( xShape, uno::UNO_QUERY ); + uno::Any aAny = xSourceGraphProps->getPropertyValue("GraphicCrop"); + if(aAny >>= aGraphicCrop) { + xGraphProps->setPropertyValue("GraphicCrop", + uno::makeAny( aGraphicCrop ) ); + } + + // We need to drop the shape here somehow + uno::Reference< lang::XComponent > xShapeComponent( xShape, uno::UNO_QUERY ); + xShapeComponent->dispose( ); + } + } + catch( const beans::UnknownPropertyException & ) + { + // It isn't a graphic image + } + + if ( bUseShape ) + m_xShape = xShape; + + if ( m_xShape.is( ) ) + { + uno::Reference< beans::XPropertySet > xShapeProps + (m_xShape, uno::UNO_QUERY_THROW); + + + xShapeProps->setPropertyValue + (getPropertyName(PROP_ANCHOR_TYPE), + uno::makeAny + (text::TextContentAnchorType_AS_CHARACTER)); + + // In Word, if a shape is anchored inline, that + // excludes being in the background. + xShapeProps->setPropertyValue("Opaque", uno::makeAny(true)); + + uno::Reference xServiceInfo(m_xShape, uno::UNO_QUERY_THROW); + + // TextFrames can't be rotated. But for anything else, + // make sure that setting size doesn't affect rotation, + // that would not match Word's definition of rotation. + bool bKeepRotation = false; + if (!xServiceInfo->supportsService("com.sun.star.text.TextFrame")) + { + bKeepRotation = true; + xShapeProps->setPropertyValue + (getPropertyName(PROP_TEXT_RANGE), + uno::makeAny + (m_pImpl->rDomainMapper.GetCurrentTextRange())); + } + + awt::Size aSize(m_xShape->getSize()); + + if (m_pImpl->isXSizeValid()) + aSize.Width = m_pImpl->getXSize(); + if (m_pImpl->isYSizeValis()) + aSize.Height = m_pImpl->getYSize(); + + sal_Int32 nRotation = 0; + if (bKeepRotation) + { + // Use internal API, getPropertyValue(RotateAngle) + // would use GetObjectRotation(), which is not what + // we want. + if (SdrObject* pShape = GetSdrObjectFromXShape(m_xShape)) + nRotation = pShape->GetRotateAngle(); + } + m_xShape->setSize(aSize); + if (bKeepRotation) + { + xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(nRotation)); + if (nRotation == 0) + { + // Include effect extent in the margin to bring Writer layout closer + // to Word. But do this for non-rotated shapes only, where effect + // extents map to increased margins as-is. + if (m_pImpl->m_oEffectExtentLeft) + { + m_pImpl->nLeftMargin += oox::drawingml::convertEmuToHmm( + *m_pImpl->m_oEffectExtentLeft); + } + if (m_pImpl->m_oEffectExtentTop) + { + m_pImpl->nTopMargin += oox::drawingml::convertEmuToHmm( + *m_pImpl->m_oEffectExtentTop); + } + if (m_pImpl->m_oEffectExtentRight) + { + m_pImpl->nRightMargin += oox::drawingml::convertEmuToHmm( + *m_pImpl->m_oEffectExtentRight); + } + if (m_pImpl->m_oEffectExtentBottom) + { + m_pImpl->nBottomMargin += oox::drawingml::convertEmuToHmm( + *m_pImpl->m_oEffectExtentBottom); + } + } + } + + m_pImpl->bIsGraphic = true; + + if (!m_pImpl->sAnchorId.isEmpty()) + { + putPropertyToFrameGrabBag("AnchorId", uno::makeAny(m_pImpl->sAnchorId)); + } + } + + if (bUseShape && m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) + { + // If we are here, this is a drawingML shape. For those, only dmapper (and not oox) knows the anchoring infos (just like for Writer pictures). + // But they aren't Writer pictures, either (which are already handled above). + uno::Reference< beans::XPropertySet > xShapeProps(m_xShape, uno::UNO_QUERY_THROW); + + // This needs to be AT_PARAGRAPH by default and not AT_CHARACTER, otherwise shape will move when the user inserts a new paragraph. + text::TextContentAnchorType eAnchorType = text::TextContentAnchorType_AT_PARAGRAPH; + + if (m_pImpl->bHidden) + { + xShapeProps->setPropertyValue("Visible", uno::makeAny(false)); + xShapeProps->setPropertyValue("Printable", uno::makeAny(false)); + } + + // Avoid setting AnchorType for TextBoxes till SwTextBoxHelper::syncProperty() doesn't handle transition. + bool bTextBox = false; + xShapeProps->getPropertyValue("TextBox") >>= bTextBox; + if (m_pImpl->nVertRelation == text::RelOrientation::TEXT_LINE && !bTextBox) + eAnchorType = text::TextContentAnchorType_AT_CHARACTER; + + xShapeProps->setPropertyValue("AnchorType", uno::makeAny(eAnchorType)); + if (m_pImpl->bLayoutInCell && bTextBox && m_pImpl->rDomainMapper.IsInTable() + && m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME) + m_pImpl->nHoriRelation = text::RelOrientation::FRAME; + if(m_pImpl->rDomainMapper.IsInTable()) + xShapeProps->setPropertyValue(getPropertyName(PROP_FOLLOW_TEXT_FLOW), + uno::makeAny(m_pImpl->bLayoutInCell)); + //only the position orientation is handled in applyPosition() + m_pImpl->applyPosition(xShapeProps); + + uno::Reference xServiceInfo(m_xShape, uno::UNO_QUERY_THROW); + if (xServiceInfo->supportsService("com.sun.star.drawing.GroupShape") || + xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape")) + { + // You would expect that position and rotation are + // independent, but they are not. Till we are not + // there yet to handle all scaling, translation and + // rotation with a single transformation matrix, + // make sure there is no graphic rotation set when we set + // the position. + sal_Int32 nRotation = 0; + if (xServiceInfo->supportsService("com.sun.star.drawing.GraphicObjectShape")) + { + xShapeProps->getPropertyValue("RotateAngle") >>= nRotation; + } + if (nRotation) + xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(sal_Int32(0))); + + // Position of the groupshape should be set after children have been added. + // Long-term we should get rid of positioning group + // shapes, though. Do it for top-level ones with + // absolute page position as a start. + // fdo#80555: also set position for graphic shapes here + if (!isTopGroupObj(m_xShape) + || m_pImpl->nHoriRelation != text::RelOrientation::PAGE_FRAME + || m_pImpl->nVertRelation != text::RelOrientation::PAGE_FRAME) + m_xShape->setPosition( + awt::Point(m_pImpl->nLeftPosition, m_pImpl->nTopPosition)); + + if (nRotation) + xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(nRotation)); + } + + + m_pImpl->applyRelativePosition(xShapeProps, /*bRelativeOnly=*/true); + + xShapeProps->setPropertyValue("SurroundContour", uno::makeAny(m_pImpl->bContour)); + m_pImpl->applyMargins(xShapeProps); + xShapeProps->setPropertyValue("Opaque", uno::makeAny(m_pImpl->bOpaque)); + xShapeProps->setPropertyValue("Surround", uno::makeAny(static_cast(m_pImpl->nWrap))); + m_pImpl->applyZOrder(xShapeProps); + m_pImpl->applyName(xShapeProps); + xShapeProps->setPropertyValue("AllowOverlap", + uno::makeAny(m_pImpl->bAllowOverlap)); + + // Get the grab-bag set by oox, merge with our one and then put it back. + comphelper::SequenceAsHashMap aInteropGrabBag(xShapeProps->getPropertyValue("InteropGrabBag")); + aInteropGrabBag.update(m_pImpl->getInteropGrabBag()); + xShapeProps->setPropertyValue("InteropGrabBag", uno::makeAny(aInteropGrabBag.getAsConstPropertyValueList())); + } + else if (bUseShape && m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE) + { + uno::Reference< beans::XPropertySet > xShapeProps(m_xShape, uno::UNO_QUERY_THROW); + m_pImpl->applyMargins(xShapeProps); + m_pImpl->applyZOrder(xShapeProps); + comphelper::SequenceAsHashMap aInteropGrabBag(xShapeProps->getPropertyValue("InteropGrabBag")); + aInteropGrabBag.update(m_pImpl->getInteropGrabBag()); + xShapeProps->setPropertyValue("InteropGrabBag", uno::makeAny(aInteropGrabBag.getAsConstPropertyValueList())); + } + } + } + break; + case NS_ooxml::LN_CT_Inline_distT: + m_pImpl->nTopMargin = 0; + break; + case NS_ooxml::LN_CT_Inline_distB: + m_pImpl->nBottomMargin = 0; + break; + case NS_ooxml::LN_CT_Inline_distL: + m_pImpl->nLeftMargin = 0; + break; + case NS_ooxml::LN_CT_Inline_distR: + m_pImpl->nRightMargin = 0; + break; + case NS_ooxml::LN_CT_GraphicalObjectData_uri: + rValue.getString(); + //TODO: does it need to be handled? + break; + case NS_ooxml::LN_CT_SizeRelH_relativeFrom: + { + switch (nIntValue) + { + case NS_ooxml::LN_ST_SizeRelFromH_margin: + if (m_xShape.is()) + { + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::FRAME)); + } + break; + case NS_ooxml::LN_ST_SizeRelFromH_leftMargin: + case NS_ooxml::LN_ST_SizeRelFromH_outsideMargin: + if (m_xShape.is()) + { + // Here we handle the relative size of the width of some shape. + // The size of the shape's width is going to be relative to the size of the left margin. + // E.g.: (left margin = 8 && relative size = 150%) -> width of some shape = 12. + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::PAGE_LEFT)); + } + break; + case NS_ooxml::LN_ST_SizeRelFromH_rightMargin: + case NS_ooxml::LN_ST_SizeRelFromH_insideMargin: + if (m_xShape.is()) + { + // Same as the left margin above. + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::PAGE_RIGHT)); + } + break; + case NS_ooxml::LN_ST_SizeRelFromH_page: + if (m_xShape.is()) + { + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RelativeWidthRelation", uno::makeAny(text::RelOrientation::PAGE_FRAME)); + } + break; + default: + SAL_WARN("writerfilter", "GraphicImport::lcl_attribute: unhandled NS_ooxml::LN_CT_SizeRelH_relativeFrom value: " << nIntValue); + break; + } + } + break; + case NS_ooxml::LN_CT_SizeRelV_relativeFrom: + { + switch (nIntValue) + { + case NS_ooxml::LN_ST_SizeRelFromV_margin: + if (m_xShape.is()) + { + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RelativeHeightRelation", uno::makeAny(text::RelOrientation::FRAME)); + } + break; + case NS_ooxml::LN_ST_SizeRelFromV_page: + if (m_xShape.is()) + { + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RelativeHeightRelation", uno::makeAny(text::RelOrientation::PAGE_FRAME)); + } + break; + case NS_ooxml::LN_ST_SizeRelFromV_bottomMargin: + if (m_xShape.is()) + { + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("RelativeHeightRelation", uno::makeAny(text::RelOrientation::PAGE_PRINT_AREA_BOTTOM)); + } + break; + default: + SAL_WARN("writerfilter", "GraphicImport::lcl_attribute: unhandled NS_ooxml::LN_CT_SizeRelV_relativeFrom value: " << nIntValue); + break; + } + } + break; + default: +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + break; + } +} + +uno::Reference GraphicImport::GetGraphicObject() +{ + uno::Reference xResult; + + if (m_xGraphicObject.is()) + xResult = m_xGraphicObject; + else if (m_xShape.is()) + { + xResult.set(m_xShape, uno::UNO_QUERY_THROW); + } + + return xResult; +} + + +void GraphicImport::ProcessShapeOptions(Value const & rValue) +{ + sal_Int32 nIntValue = rValue.getInt(); + switch( m_pImpl->nShapeOptionType ) + { + case NS_ooxml::LN_CT_Anchor_distL: + m_pImpl->nLeftMargin = nIntValue / 360; + m_pImpl->nLeftMarginOrig = m_pImpl->nLeftMargin; + break; + case NS_ooxml::LN_CT_Anchor_distT: + //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins() + m_pImpl->nTopMargin = nIntValue / 360; + break; + case NS_ooxml::LN_CT_Anchor_distR: + //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustLRWrapForWordMargins() + m_pImpl->nRightMargin = nIntValue / 360; + break; + case NS_ooxml::LN_CT_Anchor_distB: + //todo: changes have to be applied depending on the orientation, see SwWW8ImplReader::AdjustULWrapForWordMargins() + m_pImpl->nBottomMargin = nIntValue / 360; + break; + default: + OSL_FAIL( "shape option unsupported?"); + } +} + + +void GraphicImport::lcl_sprm(Sprm& rSprm) +{ + sal_uInt32 nSprmId = rSprm.getId(); + + switch(nSprmId) + { + case NS_ooxml::LN_CT_Inline_extent: // 90911; + case NS_ooxml::LN_CT_Inline_effectExtent: // 90912; + case NS_ooxml::LN_CT_Inline_docPr: // 90913; + case NS_ooxml::LN_CT_Inline_cNvGraphicFramePr: // 90914; + case NS_ooxml::LN_CT_NonVisualGraphicFrameProperties_graphicFrameLocks:// 90657 + case NS_ooxml::LN_CT_Inline_a_graphic:// 90915 + case NS_ooxml::LN_CT_Anchor_simplePos_elem: // 90975; + case NS_ooxml::LN_CT_Anchor_extent: // 90978; + case NS_ooxml::LN_CT_Anchor_effectExtent: // 90979; + case NS_ooxml::LN_EG_WrapType_wrapSquare: // 90945; + case NS_ooxml::LN_EG_WrapType_wrapTight: // 90946; + case NS_ooxml::LN_EG_WrapType_wrapThrough: + case NS_ooxml::LN_CT_Anchor_docPr: // 90980; + case NS_ooxml::LN_CT_Anchor_cNvGraphicFramePr: // 90981; + case NS_ooxml::LN_CT_Anchor_a_graphic: // 90982; + case NS_ooxml::LN_CT_WrapPath_start: // 90924; + case NS_ooxml::LN_CT_WrapPath_lineTo: // 90925; + case NS_ooxml::LN_graphic_graphic: + case NS_ooxml::LN_pic_pic: + case NS_ooxml::LN_dgm_relIds: + case NS_ooxml::LN_lc_lockedCanvas: + case NS_ooxml::LN_c_chart: + case NS_ooxml::LN_wps_wsp: + case NS_ooxml::LN_wpg_wgp: + case NS_ooxml::LN_sizeRelH_sizeRelH: + case NS_ooxml::LN_sizeRelV_sizeRelV: + case NS_ooxml::LN_hlinkClick_hlinkClick: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + pProperties->resolve(*this); + } + + // We'll map these to PARALLEL, save the original wrap type. + if (nSprmId == NS_ooxml::LN_EG_WrapType_wrapTight) + m_pImpl->m_aInteropGrabBag["EG_WrapType"] <<= OUString("wrapTight"); + else if (nSprmId == NS_ooxml::LN_EG_WrapType_wrapThrough) + m_pImpl->m_aInteropGrabBag["EG_WrapType"] <<= OUString("wrapThrough"); + } + break; + case NS_ooxml::LN_CT_WrapTight_wrapPolygon: + case NS_ooxml::LN_CT_WrapThrough_wrapPolygon: + { + WrapPolygonHandler aHandler; + + resolveSprmProps(aHandler, rSprm); + + m_pImpl->mpWrapPolygon = aHandler.getPolygon(); + + // Save the wrap path in case we can't handle it natively: drawinglayer shapes, TextFrames. + m_pImpl->m_aInteropGrabBag["CT_WrapPath"] <<= m_pImpl->mpWrapPolygon->getPointSequenceSequence(); + } + break; + case NS_ooxml::LN_CT_Anchor_positionH: // 90976; + { + // Use a special handler for the positioning + auto pHandler = std::make_shared( m_pImpl->m_rPositionOffsets, m_pImpl->m_rAligns ); + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + pProperties->resolve( *pHandler ); + if( !m_pImpl->bUseSimplePos ) + { + m_pImpl->nHoriRelation = pHandler->relation(); + m_pImpl->bPageToggle = pHandler->GetPageToggle(); + m_pImpl->nHoriOrient = pHandler->orientation(); + m_pImpl->nLeftPosition = pHandler->position(); + + // Left adjustments: if horizontally aligned to left of margin, then remove the + // left wrapping. + if (m_pImpl->nHoriOrient == text::HoriOrientation::LEFT) + { + if (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA) + { + m_pImpl->nLeftMargin = 0; + } + } + } + } + } + break; + case NS_ooxml::LN_CT_Anchor_positionV: // 90977; + { + // Use a special handler for the positioning + auto pHandler = std::make_shared( m_pImpl->m_rPositionOffsets, m_pImpl->m_rAligns); + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + pProperties->resolve( *pHandler ); + if( !m_pImpl->bUseSimplePos ) + { + m_pImpl->nVertRelation = pHandler->relation(); + m_pImpl->nVertOrient = pHandler->orientation(); + m_pImpl->nTopPosition = pHandler->position(); + } + } + } + break; + case NS_ooxml::LN_CT_SizeRelH_pctWidth: + case NS_ooxml::LN_CT_SizeRelV_pctHeight: + if (m_pImpl->m_rPositivePercentages.empty()) + break; + + if (m_xShape.is()) + { + sal_Int16 nPositivePercentage = rtl::math::round(m_pImpl->m_rPositivePercentages.front().toDouble() / oox::drawingml::PER_PERCENT); + + if (nPositivePercentage) + { + uno::Reference xPropertySet(m_xShape, uno::UNO_QUERY); + OUString aProperty = nSprmId == NS_ooxml::LN_CT_SizeRelH_pctWidth ? OUString("RelativeWidth") : OUString("RelativeHeight"); + + sal_Int32 nTextPreRotateAngle = 0; + uno::Any aAny; + if (xPropertySet->getPropertySetInfo()->hasPropertyByName( + "CustomShapeGeometry")) + { + aAny = xPropertySet->getPropertyValue("CustomShapeGeometry"); + } + comphelper::SequenceAsHashMap aCustomShapeGeometry(aAny); + auto it = aCustomShapeGeometry.find("TextPreRotateAngle"); + if (it != aCustomShapeGeometry.end()) + { + nTextPreRotateAngle = it->second.get(); + } + if (nTextPreRotateAngle == 0) + { + xPropertySet->setPropertyValue(aProperty, + uno::makeAny(nPositivePercentage)); + } + } + } + + // Make sure the token is consumed even if xShape is an empty + // reference. + m_pImpl->m_rPositivePercentages.pop(); + break; + case NS_ooxml::LN_EG_WrapType_wrapNone: // 90944; - doesn't contain attributes + //depending on the behindDoc attribute text wraps through behind or in front of the object + m_pImpl->nWrap = text::WrapTextMode_THROUGH; + + // Wrap though means the margins defined earlier should not be + // respected. + m_pImpl->nLeftMargin = 0; + m_pImpl->nTopMargin = 0; + m_pImpl->nRightMargin = 0; + m_pImpl->nBottomMargin = 0; + break; + case NS_ooxml::LN_EG_WrapType_wrapTopAndBottom: // 90948; + m_pImpl->nWrap = text::WrapTextMode_NONE; + break; + case NS_ooxml::LN_CT_GraphicalObject_graphicData:// 90660; + { + m_pImpl->bIsGraphic = true; + + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_NonVisualDrawingProps_a_hlinkClick: // 90689; + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + pProperties->resolve( *this ); + } + break; + default: + SAL_WARN("writerfilter", "GraphicImport::lcl_sprm: unhandled token: " << nSprmId); + break; + } +} + +void GraphicImport::lcl_entry(writerfilter::Reference::Pointer_t /*ref*/) +{ +} + +uno::Reference GraphicImport::createGraphicObject(uno::Reference const & rxGraphic, + uno::Reference const & xShapeProps) +{ + uno::Reference xGraphicObject; + try + { + if (rxGraphic.is()) + { + uno::Reference< beans::XPropertySet > xGraphicObjectProperties( + m_xTextFactory->createInstance("com.sun.star.text.TextGraphicObject"), + uno::UNO_QUERY_THROW); + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_GRAPHIC), uno::makeAny(rxGraphic)); + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_ANCHOR_TYPE), + uno::makeAny( m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR ? + text::TextContentAnchorType_AT_CHARACTER : + text::TextContentAnchorType_AS_CHARACTER )); + xGraphicObject.set( xGraphicObjectProperties, uno::UNO_QUERY_THROW ); + + //shapes have only one border + table::BorderLine2 aBorderLine; + GraphicBorderLine& rBorderLine = m_pImpl->aBorders[0]; + if (rBorderLine.isEmpty() && xShapeProps.is() && xShapeProps->getPropertyValue("LineStyle").get() != drawing::LineStyle_NONE) + { + // In case we got no border tokens and we have the + // original shape, then use its line properties as the + // border. + aBorderLine.Color = xShapeProps->getPropertyValue("LineColor").get(); + aBorderLine.LineWidth = xShapeProps->getPropertyValue("LineWidth").get(); + } + else + { + aBorderLine.Color = 0; + aBorderLine.InnerLineWidth = 0; + aBorderLine.OuterLineWidth = static_cast(rBorderLine.nLineWidth); + aBorderLine.LineDistance = 0; + } + PropertyIds const aBorderProps[] = + { + PROP_LEFT_BORDER, + PROP_RIGHT_BORDER, + PROP_TOP_BORDER, + PROP_BOTTOM_BORDER + }; + + for(PropertyIds const & rBorderProp : aBorderProps) + xGraphicObjectProperties->setPropertyValue(getPropertyName(rBorderProp), uno::makeAny(aBorderLine)); + + // setting graphic object shadow properties + if (m_pImpl->bShadow) + { + // Shadow width is approximated by average of X and Y + table::ShadowFormat aShadow; + sal_uInt32 nShadowColor = m_pImpl->nShadowColor & 0x00FFFFFF; // The shadow color we get is RGB only. + sal_Int32 nShadowWidth = (abs(m_pImpl->nShadowXDistance) + + abs(m_pImpl->nShadowYDistance)) / 2; + + aShadow.ShadowWidth = nShadowWidth; + sal_uInt8 nShadowTransparence = float(m_pImpl->nShadowTransparence) * 2.55; + nShadowColor |= (nShadowTransparence << 24); // Add transparence to the color. + aShadow.Color = nShadowColor; + // Distances -ve for top and right, +ve for bottom and left + if (m_pImpl->nShadowXDistance > 0) + { + if (m_pImpl->nShadowYDistance > 0) + aShadow.Location = table::ShadowLocation_BOTTOM_RIGHT; + else + aShadow.Location = table::ShadowLocation_TOP_RIGHT; + } + else + { + if (m_pImpl->nShadowYDistance > 0) + aShadow.Location = table::ShadowLocation_BOTTOM_LEFT; + else + aShadow.Location = table::ShadowLocation_TOP_LEFT; + } + + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_SHADOW_FORMAT), uno::makeAny(aShadow)); + } + + // setting properties for all types + if( m_pImpl->bPositionProtected ) + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_POSITION_PROTECTED ), + uno::makeAny(true)); + if( m_pImpl->bSizeProtected ) + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_SIZE_PROTECTED ), + uno::makeAny(true)); + + sal_Int32 nWidth = - m_pImpl->nLeftPosition; + if (m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) + { + //adjust margins + if( (m_pImpl->nHoriOrient == text::HoriOrientation::LEFT && + (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA || + m_pImpl->nHoriRelation == text::RelOrientation::FRAME) ) || + (m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE && + m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA )) + m_pImpl->nLeftMargin = 0; + if((m_pImpl->nHoriOrient == text::HoriOrientation::RIGHT && + (m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA || + m_pImpl->nHoriRelation == text::RelOrientation::FRAME) ) || + (m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE && + m_pImpl->nHoriRelation == text::RelOrientation::PAGE_PRINT_AREA )) + m_pImpl->nRightMargin = 0; + // adjust top/bottom margins + if( m_pImpl->nVertOrient == text::VertOrientation::TOP && + ( m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA || + m_pImpl->nVertRelation == text::RelOrientation::PAGE_FRAME)) + m_pImpl->nTopMargin = 0; + if( m_pImpl->nVertOrient == text::VertOrientation::BOTTOM && + ( m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA || + m_pImpl->nVertRelation == text::RelOrientation::PAGE_FRAME)) + m_pImpl->nBottomMargin = 0; + if( m_pImpl->nVertOrient == text::VertOrientation::BOTTOM && + m_pImpl->nVertRelation == text::RelOrientation::PAGE_PRINT_AREA ) + m_pImpl->nBottomMargin = 0; + //adjust alignment + if( m_pImpl->nHoriOrient == text::HoriOrientation::INSIDE && + m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME ) + { + // convert 'left to page' to 'from left - to page text area' + m_pImpl->nHoriOrient = text::HoriOrientation::NONE; + m_pImpl->nHoriRelation = text::RelOrientation::PAGE_PRINT_AREA; + m_pImpl->nLeftPosition = - nWidth; + } + else if( m_pImpl->nHoriOrient == text::HoriOrientation::OUTSIDE && + m_pImpl->nHoriRelation == text::RelOrientation::PAGE_FRAME ) + { + // convert 'right to page' to 'from left 0 to right page border' + m_pImpl->nHoriOrient = text::HoriOrientation::NONE; + m_pImpl->nHoriRelation = text::RelOrientation::PAGE_RIGHT; + m_pImpl->nLeftPosition = 0; + } + + m_pImpl->applyPosition(xGraphicObjectProperties); + m_pImpl->applyRelativePosition(xGraphicObjectProperties); + if( !m_pImpl->bOpaque ) + { + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_OPAQUE ), uno::makeAny(m_pImpl->bOpaque)); + } + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_SURROUND ), + uno::makeAny(static_cast(m_pImpl->nWrap))); + if( m_pImpl->rDomainMapper.IsInTable()) + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_FOLLOW_TEXT_FLOW ), + uno::makeAny(m_pImpl->bLayoutInCell)); + + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_SURROUND_CONTOUR ), + uno::makeAny(m_pImpl->bContour)); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_CONTOUR_OUTSIDE ), + uno::makeAny(m_pImpl->bContourOutside)); + m_pImpl->applyMargins(xGraphicObjectProperties); + } + + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_ADJUST_CONTRAST ), + uno::makeAny(static_cast(m_pImpl->nContrast))); + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_ADJUST_LUMINANCE ), + uno::makeAny(static_cast(m_pImpl->nBrightness))); + if(m_pImpl->eColorMode != drawing::ColorMode_STANDARD) + { + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_GRAPHIC_COLOR_MODE ), + uno::makeAny(m_pImpl->eColorMode)); + } + + xGraphicObjectProperties->setPropertyValue(getPropertyName( PROP_BACK_COLOR ), + uno::makeAny( GraphicImport_Impl::nFillColor )); + m_pImpl->applyZOrder(xGraphicObjectProperties); + + //there seems to be no way to detect the original size via _real_ API + uno::Reference< beans::XPropertySet > xGraphicProperties(rxGraphic, uno::UNO_QUERY_THROW); + + if (m_pImpl->mpWrapPolygon.get() != nullptr) + { + uno::Any aContourPolyPolygon; + awt::Size aGraphicSize; + WrapPolygon::Pointer_t pCorrected; + xGraphicProperties->getPropertyValue(getPropertyName(PROP_SIZE100th_M_M)) >>= aGraphicSize; + if (aGraphicSize.Width && aGraphicSize.Height) + { + pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygon(aGraphicSize); + } + else + { + xGraphicProperties->getPropertyValue(getPropertyName(PROP_SIZE_PIXEL)) >>= aGraphicSize; + if (aGraphicSize.Width && aGraphicSize.Height) + { + pCorrected = m_pImpl->mpWrapPolygon->correctWordWrapPolygonPixel(aGraphicSize); + } + } + + text::GraphicCrop aGraphicCrop; + xShapeProps->getPropertyValue("GraphicCrop") >>= aGraphicCrop; + if (aGraphicCrop.Top != 0 || aGraphicCrop.Bottom != 0 || aGraphicCrop.Left != 0 + || aGraphicCrop.Right != 0) + { + // Word's wrap polygon deals with a canvas which has the size of the already + // cropped graphic, correct our polygon to have the same render result. + pCorrected = pCorrected->correctCrop(aGraphicSize, aGraphicCrop); + } + + if (pCorrected) + { + aContourPolyPolygon <<= pCorrected->getPointSequenceSequence(); + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_CONTOUR_POLY_POLYGON), + aContourPolyPolygon); + // We should bring it to front, even if wp:anchor's behindDoc="1", + // because otherwise paragraph background (if set) overlaps the graphic + // TODO: if paragraph's background becomes bottommost, then remove this hack + xGraphicObjectProperties->setPropertyValue("Opaque", uno::makeAny(true)); + } + } + + + if(m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_INLINE || m_pImpl->eGraphicImportType == IMPORT_AS_DETECTED_ANCHOR) + { + if( m_pImpl->getXSize() && m_pImpl->getYSize() ) + xGraphicObjectProperties->setPropertyValue(getPropertyName(PROP_SIZE), + uno::makeAny( awt::Size( m_pImpl->getXSize(), m_pImpl->getYSize() ))); + m_pImpl->applyMargins(xGraphicObjectProperties); + m_pImpl->applyName(xGraphicObjectProperties); + } + + // Handle horizontal flip. + bool bMirrored = false; + xShapeProps->getPropertyValue("IsMirrored") >>= bMirrored; + if (bMirrored) + { + xGraphicObjectProperties->setPropertyValue("HoriMirroredOnEvenPages", + uno::makeAny(true)); + xGraphicObjectProperties->setPropertyValue("HoriMirroredOnOddPages", + uno::makeAny(true)); + } + } + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("writerfilter", ""); + } + return xGraphicObject; +} + + +void GraphicImport::data(const sal_uInt8* buf, size_t len) +{ + beans::PropertyValues aMediaProperties( 1 ); + aMediaProperties[0].Name = getPropertyName(PROP_INPUT_STREAM); + + uno::Reference< io::XInputStream > xIStream = new XInputStreamHelper( buf, len ); + aMediaProperties[0].Value <<= xIStream; + + uno::Reference xPropertySet; + uno::Reference xGraphicProvider(graphic::GraphicProvider::create(m_xComponentContext)); + uno::Reference xGraphic = xGraphicProvider->queryGraphic(aMediaProperties); + m_xGraphicObject = createGraphicObject(xGraphic, xPropertySet); +} + + +void GraphicImport::lcl_startSectionGroup() +{ +} + + +void GraphicImport::lcl_endSectionGroup() +{ +} + + +void GraphicImport::lcl_startParagraphGroup() +{ +} + + +void GraphicImport::lcl_endParagraphGroup() +{ +} + + +void GraphicImport::lcl_startCharacterGroup() +{ +} + + +void GraphicImport::lcl_endCharacterGroup() +{ +} + + +void GraphicImport::lcl_text(const sal_uInt8 * /*_data*/, size_t /*len*/) +{ +} + + +void GraphicImport::lcl_utext(const sal_uInt8 * /*_data*/, size_t /*len*/) +{ +} + + +void GraphicImport::lcl_props(writerfilter::Reference::Pointer_t /*ref*/) +{ +} + + +void GraphicImport::lcl_table(Id /*name*/, writerfilter::Reference
::Pointer_t /*ref*/) +{ +} + + +void GraphicImport::lcl_substream(Id /*name*/, ::writerfilter::Reference::Pointer_t /*ref*/) +{ +} + +void GraphicImport::lcl_startShape(uno::Reference const&) +{ +} + +void GraphicImport::lcl_endShape( ) +{ +} + +bool GraphicImport::IsGraphic() const +{ + return m_pImpl->bIsGraphic; +} + +sal_Int32 GraphicImport::GetLeftMarginOrig() const +{ + return m_pImpl->nLeftMarginOrig; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/GraphicImport.hxx b/writerfilter/source/dmapper/GraphicImport.hxx new file mode 100644 index 000000000..a2495849b --- /dev/null +++ b/writerfilter/source/dmapper/GraphicImport.hxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_GRAPHICIMPORT_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_GRAPHICIMPORT_HXX + +#include +#include + +#include "LoggedResources.hxx" + +#include +#include + +namespace com::sun::star { + namespace uno + { + class XComponentContext; + } + namespace lang + { + class XMultiServiceFactory; + } + namespace text + { + class XTextContent; + } + namespace drawing + { + class XShape; + } + namespace beans + { + struct PropertyValue; + } +} + +namespace writerfilter +{ +namespace dmapper +{ +class GraphicImport_Impl; +class DomainMapper; + +enum GraphicImportType +{ + IMPORT_AS_DETECTED_INLINE, + IMPORT_AS_DETECTED_ANCHOR +}; + +class GraphicImport : public LoggedProperties, public LoggedTable + ,public BinaryObj, public LoggedStream +{ + std::unique_ptr m_pImpl; + + css::uno::Reference m_xComponentContext; + css::uno::Reference m_xTextFactory; + + css::uno::Reference m_xGraphicObject; + + css::uno::Reference m_xShape; + void ProcessShapeOptions(Value const & val); + + css::uno::Reference + createGraphicObject(css::uno::Reference const & rxGraphic, + css::uno::Reference const & xShapeProps); + + void putPropertyToFrameGrabBag( const OUString& sPropertyName, const css::uno::Any& aPropertyValue ); + +public: + explicit GraphicImport( css::uno::Reference const& xComponentContext, + css::uno::Reference const& xTextFactory, + DomainMapper& rDomainMapper, + GraphicImportType eGraphicImportType, + std::pair& rPositionOffsets, + std::pair& rAligns, + std::queue& rPositivePercentages); + virtual ~GraphicImport() override; + + // BinaryObj + virtual void data(const sal_uInt8* buffer, size_t len) override; + + css::uno::Reference GetGraphicObject(); + const css::uno::Reference& GetXShapeObject() const { return m_xShape;} + bool IsGraphic() const; + sal_Int32 GetLeftMarginOrig() const; + + com::sun::star::awt::Point GetGraphicObjectPosition(); + + private: + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + + // Table + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) override; + + // Stream + virtual void lcl_startSectionGroup() override; + virtual void lcl_endSectionGroup() override; + virtual void lcl_startParagraphGroup() override; + virtual void lcl_endParagraphGroup() override; + virtual void lcl_startCharacterGroup() override; + virtual void lcl_endCharacterGroup() override; + virtual void lcl_text(const sal_uInt8 * data, size_t len) override; + virtual void lcl_utext(const sal_uInt8 * data, size_t len) override; + virtual void lcl_props(writerfilter::Reference::Pointer_t ref) override; + virtual void lcl_table(Id name, + writerfilter::Reference
::Pointer_t ref) override; + virtual void lcl_substream(Id name, writerfilter::Reference::Pointer_t ref) override; + virtual void lcl_startShape(css::uno::Reference const& xShape) override; + virtual void lcl_endShape() override; + + void handleWrapTextValue(sal_uInt32 nVal); +}; + +typedef tools::SvRef GraphicImportPtr; + +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/LatentStyleHandler.cxx b/writerfilter/source/dmapper/LatentStyleHandler.cxx new file mode 100644 index 000000000..bc381d21f --- /dev/null +++ b/writerfilter/source/dmapper/LatentStyleHandler.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include "LatentStyleHandler.hxx" +#include "TagLogger.hxx" +#include + +namespace writerfilter::dmapper +{ +using namespace ::com::sun::star; + +LatentStyleHandler::LatentStyleHandler() + : LoggedProperties("LatentStyleHandler") +{ +} + +LatentStyleHandler::~LatentStyleHandler() = default; + +void LatentStyleHandler::lcl_attribute(Id nId, Value& rVal) +{ + beans::PropertyValue aValue; + bool bFound = true; + switch (nId) + { + case NS_ooxml::LN_CT_LsdException_name: + aValue.Name = "name"; + break; + case NS_ooxml::LN_CT_LsdException_locked: + aValue.Name = "locked"; + break; + case NS_ooxml::LN_CT_LsdException_uiPriority: + aValue.Name = "uiPriority"; + break; + case NS_ooxml::LN_CT_LsdException_semiHidden: + aValue.Name = "semiHidden"; + break; + case NS_ooxml::LN_CT_LsdException_unhideWhenUsed: + aValue.Name = "unhideWhenUsed"; + break; + case NS_ooxml::LN_CT_LsdException_qFormat: + aValue.Name = "qFormat"; + break; + default: + bFound = false; +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + break; + } + if (bFound) + { + aValue.Value <<= rVal.getString(); + m_aAttributes.push_back(aValue); + } +} + +void LatentStyleHandler::lcl_sprm(Sprm& /*rSprm*/) {} + +const std::vector& LatentStyleHandler::getAttributes() const +{ + return m_aAttributes; +} + +} // namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/LatentStyleHandler.hxx b/writerfilter/source/dmapper/LatentStyleHandler.hxx new file mode 100644 index 000000000..00eb6005c --- /dev/null +++ b/writerfilter/source/dmapper/LatentStyleHandler.hxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_LATENTSTYLEHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_LATENTSTYLEHANDLER_HXX + +#include "LoggedResources.hxx" +#include +#include + +namespace writerfilter +{ +namespace dmapper +{ +/// Handler for a latent style (w:lsdException element) +class LatentStyleHandler : public LoggedProperties +{ + std::vector m_aAttributes; + + // Properties + void lcl_attribute(Id nId, Value& rVal) override; + void lcl_sprm(Sprm& sprm) override; + +public: + LatentStyleHandler(); + ~LatentStyleHandler() override; + + const std::vector& getAttributes() const; +}; + +} // namespace dmapper +} // namespace writerfilter + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/LoggedResources.cxx b/writerfilter/source/dmapper/LoggedResources.cxx new file mode 100644 index 000000000..d8857911e --- /dev/null +++ b/writerfilter/source/dmapper/LoggedResources.cxx @@ -0,0 +1,400 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "LoggedResources.hxx" +#include "TagLogger.hxx" +#include + +using namespace ::com::sun::star; + +namespace writerfilter +{ + +#ifdef DBG_UTIL + +LoggedResourcesHelper::LoggedResourcesHelper(const std::string & sPrefix) +: msPrefix(sPrefix) +{ +} + +LoggedResourcesHelper::~LoggedResourcesHelper() +{ +} + +void LoggedResourcesHelper::startElement(const std::string & sElement) +{ + TagLogger::getInstance().startElement(msPrefix + "." + sElement); +} + +void LoggedResourcesHelper::endElement() +{ + TagLogger::getInstance().endElement(); +} + +void LoggedResourcesHelper::chars(const OUString & rChars) +{ + TagLogger::getInstance().chars(rChars); +} + +void LoggedResourcesHelper::chars(const std::string & rChars) +{ + TagLogger::getInstance().chars(rChars); +} + +void LoggedResourcesHelper::attribute(const std::string & rName, const std::string & rValue) +{ + TagLogger::getInstance().attribute(rName, rValue); +} + +void LoggedResourcesHelper::attribute(const std::string & rName, sal_uInt32 nValue) +{ + TagLogger::getInstance().attribute(rName, nValue); +} + +#endif + + +LoggedStream::LoggedStream( +#ifdef DBG_UTIL + const std::string & sPrefix +) : mHelper(sPrefix) +#else + const std::string& +) +#endif +{ +} + +LoggedStream::~LoggedStream() +{ +} + +void LoggedStream::startSectionGroup() +{ +#ifdef DBG_UTIL + mHelper.startElement("section"); +#endif + + lcl_startSectionGroup(); +} + +void LoggedStream::endSectionGroup() +{ + lcl_endSectionGroup(); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::startParagraphGroup() +{ +#ifdef DBG_UTIL + mHelper.startElement("paragraph"); +#endif + + lcl_startParagraphGroup(); +} + +void LoggedStream::endParagraphGroup() +{ + lcl_endParagraphGroup(); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + + +void LoggedStream::startCharacterGroup() +{ +#ifdef DBG_UTIL + mHelper.startElement("charactergroup"); +#endif + + lcl_startCharacterGroup(); +} + +void LoggedStream::endCharacterGroup() +{ + lcl_endCharacterGroup(); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::startShape(uno::Reference const& xShape) +{ +#ifdef DBG_UTIL + mHelper.startElement("shape"); +#endif + + lcl_startShape(xShape); +} + +void LoggedStream::endShape() +{ + lcl_endShape(); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::text(const sal_uInt8 * data, size_t len) +{ +#ifdef DBG_UTIL + mHelper.startElement("text"); + + OUString sText( reinterpret_cast(data), len, RTL_TEXTENCODING_MS_1252 ); + + mHelper.startElement("data"); + LoggedResourcesHelper::chars(sText); + LoggedResourcesHelper::endElement(); +#endif + + lcl_text(data, len); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::utext(const sal_uInt8 * data, size_t len) +{ +#ifdef DBG_UTIL + mHelper.startElement("utext"); + mHelper.startElement("data"); + + OUString sText( reinterpret_cast(data), len); + + LoggedResourcesHelper::chars(sText); + + LoggedResourcesHelper::endElement(); +#endif + + lcl_utext(data, len); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::positionOffset(const OUString& rText, bool bVertical) +{ +#ifdef DBG_UTIL + mHelper.startElement("positionOffset"); + LoggedResourcesHelper::attribute("vertical", static_cast(bVertical)); + LoggedResourcesHelper::chars(rText); +#endif + + lcl_positionOffset(rText, bVertical); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::align(const OUString& rText, bool bVertical) +{ +#ifdef DBG_UTIL + mHelper.startElement("align"); + LoggedResourcesHelper::attribute("vertical", static_cast(bVertical)); + LoggedResourcesHelper::chars(rText); +#endif + + lcl_align(rText, bVertical); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::positivePercentage(const OUString& rText) +{ +#ifdef DBG_UTIL + mHelper.startElement("positivePercentage"); + LoggedResourcesHelper::chars(rText); +#endif + + lcl_positivePercentage(rText); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::props(writerfilter::Reference::Pointer_t ref) +{ +#ifdef DBG_UTIL + mHelper.startElement("props"); +#endif + + lcl_props(ref); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::table(Id name, writerfilter::Reference
::Pointer_t ref) +{ +#ifdef DBG_UTIL + mHelper.startElement("table"); + LoggedResourcesHelper::attribute("name", QNameToString(name)); +#endif + + lcl_table(name, ref); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::substream(Id name, writerfilter::Reference::Pointer_t ref) +{ +#ifdef DBG_UTIL + mHelper.startElement("substream"); + LoggedResourcesHelper::attribute("name", QNameToString(name)); +#endif + + lcl_substream(name, ref); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::info(const std::string & _info) +{ +#ifdef DBG_UTIL + mHelper.startElement("info"); + LoggedResourcesHelper::attribute("text", _info); +#else + (void)_info; +#endif + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::startGlossaryEntry() +{ +#ifdef DBG_UTIL + mHelper.startElement("startGlossaryEntry"); +#endif + + lcl_startGlossaryEntry(); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +void LoggedStream::endGlossaryEntry() +{ +#ifdef DBG_UTIL + mHelper.startElement("endGlossaryEntry"); +#endif + + lcl_endGlossaryEntry(); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +LoggedProperties::LoggedProperties( +#ifdef DBG_UTIL + const std::string & sPrefix +) : mHelper(sPrefix) +#else + const std::string& +) +#endif +{ +} + +LoggedProperties::~LoggedProperties() +{ +} + +void LoggedProperties::attribute(Id name, Value & val) +{ +#ifdef DBG_UTIL + mHelper.startElement("attribute"); + LoggedResourcesHelper::attribute("name", QNameToString(name)); + LoggedResourcesHelper::attribute("value", val.toString()); + LoggedResourcesHelper::endElement(); +#endif + + lcl_attribute(name, val); +} + +void LoggedProperties::sprm(Sprm & rSprm) +{ +#ifdef DBG_UTIL + mHelper.startElement("sprm"); + LoggedResourcesHelper::attribute("name", QNameToString(rSprm.getId())); + LoggedResourcesHelper::chars(rSprm.toString()); +#endif + + lcl_sprm(rSprm); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +LoggedTable::LoggedTable( +#ifdef DBG_UTIL + const std::string & sPrefix +) : mHelper(sPrefix) +#else + const std::string& +) +#endif +{ +} + +LoggedTable::~LoggedTable() +{ +} + +void LoggedTable::entry(int pos, writerfilter::Reference::Pointer_t ref) +{ +#ifdef DBG_UTIL + mHelper.startElement("entry"); + LoggedResourcesHelper::attribute("pos", pos); +#else + (void)pos; +#endif + + lcl_entry(ref); + +#ifdef DBG_UTIL + LoggedResourcesHelper::endElement(); +#endif +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/LoggedResources.hxx b/writerfilter/source/dmapper/LoggedResources.hxx new file mode 100644 index 000000000..0be0f2ba4 --- /dev/null +++ b/writerfilter/source/dmapper/LoggedResources.hxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_LOGGEDRESOURCES_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_LOGGEDRESOURCES_HXX + +#include + + +namespace writerfilter +{ + +#ifdef DBG_UTIL +class LoggedResourcesHelper final +{ +public: + explicit LoggedResourcesHelper(const std::string & sPrefix); + ~LoggedResourcesHelper(); + + void startElement(const std::string & sElement); + static void endElement(); + static void chars(const OUString & rChars); + static void chars(const std::string & rChars); + static void attribute(const std::string & rName, const std::string & rValue); + static void attribute(const std::string & rName, sal_uInt32 nValue); + +private: + std::string msPrefix; +}; +#endif + +class LoggedStream : public Stream +{ +public: + explicit LoggedStream(const std::string & sPrefix); + virtual ~LoggedStream() override; + + void startSectionGroup() override; + void endSectionGroup() override; + void startParagraphGroup() override; + void endParagraphGroup() override; + void startCharacterGroup() override; + void endCharacterGroup() override; + void startShape(css::uno::Reference const& xShape) override; + void endShape() override; + void text(const sal_uInt8 * data, size_t len) override; + void utext(const sal_uInt8 * data, size_t len) override; + void positionOffset(const OUString& rText, bool bVertical) override; + void align(const OUString& rText, bool bVertical) override; + void positivePercentage(const OUString& rText) override; + void props(writerfilter::Reference::Pointer_t ref) override; + void table(Id name, writerfilter::Reference
::Pointer_t ref) override; + void substream(Id name, writerfilter::Reference::Pointer_t ref) override; + void info(const std::string & info) override; + void startGlossaryEntry() override; + void endGlossaryEntry() override; + +protected: + virtual void lcl_startSectionGroup() = 0; + virtual void lcl_endSectionGroup() = 0; + virtual void lcl_startParagraphGroup() = 0; + virtual void lcl_endParagraphGroup() = 0; + virtual void lcl_startCharacterGroup() = 0; + virtual void lcl_endCharacterGroup() = 0; + virtual void lcl_startShape(css::uno::Reference const& xShape) = 0; + virtual void lcl_endShape() = 0; + virtual void lcl_text(const sal_uInt8 * data, size_t len) = 0; + virtual void lcl_utext(const sal_uInt8 * data, size_t len) = 0; + virtual void lcl_positionOffset(const OUString& /*rText*/, bool /*bVertical*/) { } + virtual css::awt::Point getPositionOffset() override { return css::awt::Point(); } + virtual void lcl_align(const OUString& /*rText*/, bool /*bVertical*/) { } + virtual void lcl_positivePercentage(const OUString& /*rText*/) { } + virtual void lcl_props(writerfilter::Reference::Pointer_t ref) = 0; + virtual void lcl_table(Id name, writerfilter::Reference
::Pointer_t ref) = 0; + virtual void lcl_substream(Id name, writerfilter::Reference::Pointer_t ref) = 0; + virtual void lcl_startGlossaryEntry() { } + virtual void lcl_endGlossaryEntry() { } + +#ifdef DBG_UTIL + LoggedResourcesHelper mHelper; +#endif +}; + +class LoggedProperties : public Properties +{ +public: + explicit LoggedProperties(const std::string & sPrefix); + virtual ~LoggedProperties() override; + + void attribute(Id name, Value & val) override; + void sprm(Sprm & sprm) override; + +protected: + virtual void lcl_attribute(Id name, Value & val) = 0; + virtual void lcl_sprm(Sprm & sprm) = 0; + +#ifdef DBG_UTIL + LoggedResourcesHelper mHelper; +#endif +}; + +class LoggedTable : public Table +{ +public: + explicit LoggedTable(const std::string & sPrefix); + virtual ~LoggedTable() override; + + void entry(int pos, writerfilter::Reference::Pointer_t ref) override; + +protected: + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) = 0; + +#ifdef DBG_UTIL + LoggedResourcesHelper mHelper; +#endif +}; + +} +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_LOGGEDRESOURCES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/MeasureHandler.cxx b/writerfilter/source/dmapper/MeasureHandler.cxx new file mode 100644 index 000000000..5eea9a5c6 --- /dev/null +++ b/writerfilter/source/dmapper/MeasureHandler.cxx @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "MeasureHandler.hxx" +#include "ConversionHelper.hxx" +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + + +MeasureHandler::MeasureHandler() : +LoggedProperties("MeasureHandler"), +m_nMeasureValue( 0 ), +m_nUnit( -1 ), +m_nRowHeightSizeType( text::SizeType::MIN ) +{ +} + + +MeasureHandler::~MeasureHandler() +{ +} + + +void MeasureHandler::lcl_attribute(Id rName, Value & rVal) +{ + sal_Int32 nIntValue = rVal.getInt(); + switch( rName ) + { + case NS_ooxml::LN_CT_TblWidth_type: + { + //can be: NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct, + // NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto; + m_nUnit = nIntValue; + + if (!m_aInteropGrabBagName.isEmpty()) + { + beans::PropertyValue aValue; + aValue.Name = "type"; + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_TblWidth_nil: aValue.Value <<= OUString("nil"); break; + case NS_ooxml::LN_Value_ST_TblWidth_pct: aValue.Value <<= OUString("pct"); break; + case NS_ooxml::LN_Value_ST_TblWidth_dxa: aValue.Value <<= OUString("dxa"); break; + case NS_ooxml::LN_Value_ST_TblWidth_auto: aValue.Value <<= OUString("auto"); break; + } + m_aInteropGrabBag.push_back(aValue); + } + } + break; + case NS_ooxml::LN_CT_Height_hRule: + { + OUString sHeightType = rVal.getString(); + if ( sHeightType == "exact" ) + m_nRowHeightSizeType = text::SizeType::FIX; + } + break; + case NS_ooxml::LN_CT_TblWidth_w: + m_nMeasureValue = nIntValue; + if (!m_aInteropGrabBagName.isEmpty()) + { + beans::PropertyValue aValue; + aValue.Name = "w"; + aValue.Value <<= nIntValue; + m_aInteropGrabBag.push_back(aValue); + } + break; + case NS_ooxml::LN_CT_Height_val: // a string value + { + m_nUnit = NS_ooxml::LN_Value_ST_TblWidth_dxa; + OUString sHeight = rVal.getString(); + m_nMeasureValue = sHeight.toInt32(); + } + break; + default: + OSL_FAIL( "unknown attribute"); + } +} + + +void MeasureHandler::lcl_sprm(Sprm &) {} + + +sal_Int32 MeasureHandler::getMeasureValue() const +{ + sal_Int32 nRet = 0; + if( m_nMeasureValue != 0 && m_nUnit >= 0 ) + { + // TODO m_nUnit 3 - twip, other values unknown :-( + if( m_nUnit == 3 || sal::static_int_cast(m_nUnit) == NS_ooxml::LN_Value_ST_TblWidth_dxa) + { + nRet = ConversionHelper::convertTwipToMM100( m_nMeasureValue ); + } + //todo: handle additional width types: + //NS_ooxml::LN_Value_ST_TblWidth_nil, NS_ooxml::LN_Value_ST_TblWidth_pct, + //NS_ooxml::LN_Value_ST_TblWidth_dxa, NS_ooxml::LN_Value_ST_TblWidth_auto; + } + return nRet; +} + +void MeasureHandler::enableInteropGrabBag(const OUString& aName) +{ + m_aInteropGrabBagName = aName; +} + +beans::PropertyValue MeasureHandler::getInteropGrabBag() +{ + beans::PropertyValue aRet; + aRet.Name = m_aInteropGrabBagName; + aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag); + return aRet; +} + +} //namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/MeasureHandler.hxx b/writerfilter/source/dmapper/MeasureHandler.hxx new file mode 100644 index 000000000..abf4beb88 --- /dev/null +++ b/writerfilter/source/dmapper/MeasureHandler.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_MEASUREHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_MEASUREHANDLER_HXX + +#include "LoggedResources.hxx" +#include +#include + +namespace writerfilter { +namespace dmapper +{ +/** Handler for sprms that contain a measure and a unit + - Left indent of tables + - Preferred width of tables + */ +class MeasureHandler : public LoggedProperties +{ + sal_Int32 m_nMeasureValue; + sal_Int32 m_nUnit; + sal_Int16 m_nRowHeightSizeType; //table row height type + + OUString m_aInteropGrabBagName; + std::vector m_aInteropGrabBag; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +public: + MeasureHandler(); + virtual ~MeasureHandler() override; + + sal_Int32 getMeasureValue() const; + + sal_Int32 getValue() const { return m_nMeasureValue; } + sal_Int32 getUnit() const { return m_nUnit; } + + sal_Int16 GetRowHeightSizeType() const { return m_nRowHeightSizeType;} + void enableInteropGrabBag(const OUString& aName); + css::beans::PropertyValue getInteropGrabBag(); +}; +typedef tools::SvRef + < MeasureHandler > MeasureHandlerPtr; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/ModelEventListener.cxx b/writerfilter/source/dmapper/ModelEventListener.cxx new file mode 100644 index 000000000..8e20f7ad9 --- /dev/null +++ b/writerfilter/source/dmapper/ModelEventListener.cxx @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "ModelEventListener.hxx" +#include "PropertyIds.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + + +ModelEventListener::ModelEventListener(bool bIndexes, bool bControls) + : m_bIndexes(bIndexes), + m_bControls(bControls) +{ +} + + +ModelEventListener::~ModelEventListener() +{ +} + + +void ModelEventListener::notifyEvent( const document::EventObject& rEvent ) +{ + if ( rEvent.EventName == "OnFocus" && m_bIndexes) + { + try + { + //remove listener + uno::Reference(rEvent.Source, uno::UNO_QUERY_THROW )->removeEventListener( + uno::Reference(this)); + + // If we have PAGEREF fields, update fields as well. + uno::Reference xTextFieldsSupplier(rEvent.Source, uno::UNO_QUERY); + uno::Reference xEnumeration = xTextFieldsSupplier->getTextFields()->createEnumeration(); + sal_Int32 nIndex = 0; + while(xEnumeration->hasMoreElements()) + { + try + { + uno::Reference xPropertySet(xEnumeration->nextElement(), uno::UNO_QUERY); + sal_Int16 nSource = 0; + xPropertySet->getPropertyValue(getPropertyName(PROP_REFERENCE_FIELD_SOURCE)) >>= nSource; + sal_Int16 nPart = 0; + xPropertySet->getPropertyValue(getPropertyName(PROP_REFERENCE_FIELD_PART)) >>= nPart; + if (nSource == text::ReferenceFieldSource::BOOKMARK && nPart == text::ReferenceFieldPart::PAGE) + ++nIndex; + } + catch( const beans::UnknownPropertyException& ) + { + // doesn't even have such a property? ignore + } + } + if (nIndex) + { + uno::Reference xRefreshable(xTextFieldsSupplier->getTextFields(), uno::UNO_QUERY); + xRefreshable->refresh(); + } + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "exception while updating indexes"); + } + } + + if ( rEvent.EventName == "OnFocus" && m_bControls) + { + + // Form design mode is enabled by default in Writer, not in Word. + uno::Reference xModel(rEvent.Source, uno::UNO_QUERY); + uno::Reference xFormLayerAccess(xModel->getCurrentController(), uno::UNO_QUERY); + xFormLayerAccess->setFormDesignMode(false); + } +} + + +void ModelEventListener::disposing( const lang::EventObject& rEvent ) +{ + try + { + uno::Reference(rEvent.Source, uno::UNO_QUERY_THROW )->removeEventListener( + uno::Reference(this)); + } + catch( const uno::Exception& ) + { + } +} + +} //namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/ModelEventListener.hxx b/writerfilter/source/dmapper/ModelEventListener.hxx new file mode 100644 index 000000000..3a5dab834 --- /dev/null +++ b/writerfilter/source/dmapper/ModelEventListener.hxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_MODELEVENTLISTENER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_MODELEVENTLISTENER_HXX + +#include +#include + +namespace writerfilter { +namespace dmapper{ + + +class ModelEventListener : public cppu::WeakImplHelper +{ + bool m_bIndexes; + bool m_bControls; +public: + ModelEventListener(bool bIndexes, bool bControls); + virtual ~ModelEventListener() override; + + virtual void SAL_CALL notifyEvent(const css::document::EventObject& Event) override; + virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override; + +}; +}//namespace writerfilter +}//namespace dmapper +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx new file mode 100644 index 000000000..805e95498 --- /dev/null +++ b/writerfilter/source/dmapper/NumberingManager.cxx @@ -0,0 +1,1166 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include "ConversionHelper.hxx" +#include "NumberingManager.hxx" +#include "StyleSheetTable.hxx" +#include "PropertyIds.hxx" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace com::sun::star; + +namespace writerfilter::dmapper { + +//--------------------------------------------------- Utility functions +template +static beans::PropertyValue lcl_makePropVal(PropertyIds nNameID, T const & aValue) +{ + return {getPropertyName(nNameID), 0, uno::makeAny(aValue), beans::PropertyState_DIRECT_VALUE}; +} + +static sal_Int32 lcl_findProperty( const uno::Sequence< beans::PropertyValue >& aProps, const OUString& sName ) +{ + sal_Int32 i = 0; + sal_Int32 nLen = aProps.getLength( ); + sal_Int32 nPos = -1; + + while ( nPos == -1 && i < nLen ) + { + if ( aProps[i].Name == sName ) + nPos = i; + else + i++; + } + + return nPos; +} + +static void lcl_mergeProperties( const uno::Sequence< beans::PropertyValue >& aSrc, + uno::Sequence< beans::PropertyValue >& aDst ) +{ + for ( const auto& rProp : aSrc ) + { + // Look for the same property in aDst + sal_Int32 nPos = lcl_findProperty( aDst, rProp.Name ); + if ( nPos >= 0 ) + { + // Replace the property value by the one in aSrc + aDst[nPos] = rProp; + } + else + { + // Simply add the new value + aDst.realloc( aDst.getLength( ) + 1 ); + aDst[ aDst.getLength( ) - 1 ] = rProp; + } + } +} + +//-------------------------------------------- ListLevel implementation +void ListLevel::SetValue( Id nId, sal_Int32 nValue ) +{ + switch( nId ) + { + case NS_ooxml::LN_CT_Lvl_start: + m_nIStartAt = nValue; + break; + case NS_ooxml::LN_CT_NumLvl_startOverride: + m_nStartOverride = nValue; + break; + case NS_ooxml::LN_CT_NumFmt_val: + m_nNFC = nValue; + break; + case NS_ooxml::LN_CT_Lvl_isLgl: + break; + case NS_ooxml::LN_CT_Lvl_legacy: + break; + case NS_ooxml::LN_CT_Lvl_suff: + m_nXChFollow = nValue; + break; + case NS_ooxml::LN_CT_TabStop_pos: + if (nValue < 0) + { + SAL_INFO("writerfilter", + "unsupported list tab stop position " << nValue); + } + else + m_nTabstop = nValue; + break; + default: + OSL_FAIL( "this line should never be reached"); + } + m_bHasValues = true; +} + +void ListLevel::SetCustomNumberFormat(const OUString& rValue) { m_aCustomNumberFormat = rValue; } + +bool ListLevel::HasValues() const +{ + return m_bHasValues; +} + +void ListLevel::SetParaStyle( const tools::SvRef< StyleSheetEntry >& pStyle ) +{ + if (!pStyle) + return; + m_pParaStyle = pStyle; + // AFAICT .docx spec does not identify which numberings or paragraph + // styles are actually the ones to be used for outlines (chapter numbering), + // it only kind of says somewhere that they should be named Heading1 to Heading9. + const OUString styleId= pStyle->sConvertedStyleName; + m_outline = ( styleId.getLength() == RTL_CONSTASCII_LENGTH( "Heading 1" ) + && styleId.match( "Heading ", 0 ) + && styleId[ RTL_CONSTASCII_LENGTH( "Heading " ) ] >= '1' + && styleId[ RTL_CONSTASCII_LENGTH( "Heading " ) ] <= '9' ); +} + +uno::Sequence ListLevel::GetProperties(bool bDefaults) +{ + uno::Sequence aLevelProps = GetLevelProperties(bDefaults); + if (m_pParaStyle) + AddParaProperties( &aLevelProps ); + return aLevelProps; +} + +static bool IgnoreForCharStyle(const OUString& aStr, const bool bIsSymbol) +{ + //Names found in PropertyIds.cxx, Lines 56-396 + return (aStr=="Adjust" || aStr=="IndentAt" || aStr=="FirstLineIndent" + || aStr=="FirstLineOffset" || aStr=="LeftMargin" + || aStr=="CharInteropGrabBag" || aStr=="ParaInteropGrabBag" || + // We need font names when they are different for the bullet and for the text. + // But leave symbols alone, we only want to keep the font style for letters and numbers. + (bIsSymbol && aStr=="CharFontName") + ); +} +uno::Sequence< beans::PropertyValue > ListLevel::GetCharStyleProperties( ) +{ + PropertyValueVector_t rProperties; + + uno::Sequence< beans::PropertyValue > vPropVals = PropertyMap::GetPropertyValues(); + beans::PropertyValue* aValIter = vPropVals.begin(); + beans::PropertyValue* aEndIter = vPropVals.end(); + const bool bIsSymbol(m_sBulletChar.getLength() <= 1); + for( ; aValIter != aEndIter; ++aValIter ) + if (! IgnoreForCharStyle(aValIter->Name, bIsSymbol)) + rProperties.emplace_back(aValIter->Name, 0, aValIter->Value, beans::PropertyState_DIRECT_VALUE); + + return comphelper::containerToSequence(rProperties); +} + +uno::Sequence ListLevel::GetLevelProperties(bool bDefaults) +{ + std::vector aNumberingProperties; + + if (m_nIStartAt >= 0) + aNumberingProperties.push_back(lcl_makePropVal(PROP_START_WITH, m_nIStartAt) ); + else if (bDefaults) + aNumberingProperties.push_back(lcl_makePropVal(PROP_START_WITH, 0)); + + sal_Int16 nNumberFormat = -1; + if (m_nNFC == NS_ooxml::LN_Value_ST_NumberFormat_custom) + { + nNumberFormat = ConversionHelper::ConvertCustomNumberFormat(m_aCustomNumberFormat); + } + else + { + nNumberFormat = ConversionHelper::ConvertNumberingType(m_nNFC); + } + if( m_nNFC >= 0) + { + if (m_xGraphicBitmap.is()) + nNumberFormat = style::NumberingType::BITMAP; + aNumberingProperties.push_back(lcl_makePropVal(PROP_NUMBERING_TYPE, nNumberFormat)); + } + + // todo: this is not the bullet char + if( nNumberFormat == style::NumberingType::CHAR_SPECIAL ) + { + if (!m_sBulletChar.isEmpty()) + { + aNumberingProperties.push_back(lcl_makePropVal(PROP_BULLET_CHAR, m_sBulletChar.copy(0, 1))); + } + else + { + // If w:lvlText's value is null - set bullet char to zero. + aNumberingProperties.push_back(lcl_makePropVal(PROP_BULLET_CHAR, 0)); + } + } + if (m_xGraphicBitmap.is()) + { + aNumberingProperties.push_back(lcl_makePropVal(PROP_GRAPHIC_BITMAP, m_xGraphicBitmap)); + aNumberingProperties.push_back(lcl_makePropVal(PROP_GRAPHIC_SIZE, m_aGraphicSize)); + } + + if (m_nTabstop.has_value()) + aNumberingProperties.push_back(lcl_makePropVal(PROP_LISTTAB_STOP_POSITION, *m_nTabstop)); + else if (bDefaults) + aNumberingProperties.push_back(lcl_makePropVal(PROP_LISTTAB_STOP_POSITION, 0)); + + //TODO: handling of nFLegal? + //TODO: nFNoRestart lower levels do not restart when higher levels are incremented, like: + //1. + //1.1 + //2.2 + //2.3 + //3.4 + +// TODO: sRGBXchNums; array of inherited numbers + +// nXChFollow; following character 0 - tab, 1 - space, 2 - nothing + if (bDefaults || m_nXChFollow != SvxNumberFormat::LISTTAB) + aNumberingProperties.push_back(lcl_makePropVal(PROP_LEVEL_FOLLOW, m_nXChFollow)); + + PropertyIds const aReadIds[] = + { + PROP_ADJUST, PROP_INDENT_AT, PROP_FIRST_LINE_INDENT, + PROP_FIRST_LINE_OFFSET, PROP_LEFT_MARGIN + }; + for(PropertyIds const & rReadId : aReadIds) { + std::optional aProp = getProperty(rReadId); + if (aProp) + aNumberingProperties.emplace_back( getPropertyName(aProp->first), 0, aProp->second, beans::PropertyState_DIRECT_VALUE ); + else if (rReadId == PROP_FIRST_LINE_INDENT && bDefaults) + // Writer default is -360 twips, Word default seems to be 0. + aNumberingProperties.emplace_back("FirstLineIndent", 0, uno::makeAny(static_cast(0)), beans::PropertyState_DIRECT_VALUE); + else if (rReadId == PROP_INDENT_AT && bDefaults) + // Writer default is 720 twips, Word default seems to be 0. + aNumberingProperties.emplace_back("IndentAt", 0, + uno::makeAny(static_cast(0)), + beans::PropertyState_DIRECT_VALUE); + } + + std::optional aPropFont = getProperty(PROP_CHAR_FONT_NAME); + if(aPropFont && !isOutlineNumbering()) + aNumberingProperties.emplace_back( getPropertyName(PROP_BULLET_FONT_NAME), 0, aPropFont->second, beans::PropertyState_DIRECT_VALUE ); + + return comphelper::containerToSequence(aNumberingProperties); +} + +// Add the properties only if they do not already exist in the sequence. +void ListLevel::AddParaProperties( uno::Sequence< beans::PropertyValue >* props ) +{ + uno::Sequence< beans::PropertyValue >& aProps = *props; + + OUString sFirstLineIndent = getPropertyName( + PROP_FIRST_LINE_INDENT ); + OUString sIndentAt = getPropertyName( + PROP_INDENT_AT ); + + bool hasFirstLineIndent = lcl_findProperty( aProps, sFirstLineIndent ); + bool hasIndentAt = lcl_findProperty( aProps, sIndentAt ); + + if( hasFirstLineIndent && hasIndentAt ) + return; // has them all, nothing to add + + const uno::Sequence< beans::PropertyValue > aParaProps = m_pParaStyle->pProperties->GetPropertyValues( ); + + // ParaFirstLineIndent -> FirstLineIndent + // ParaLeftMargin -> IndentAt + + OUString sParaIndent = getPropertyName( + PROP_PARA_FIRST_LINE_INDENT ); + OUString sParaLeftMargin = getPropertyName( + PROP_PARA_LEFT_MARGIN ); + + for ( const auto& rParaProp : aParaProps ) + { + if ( !hasFirstLineIndent && rParaProp.Name == sParaIndent ) + { + aProps.realloc( aProps.getLength() + 1 ); + aProps[aProps.getLength( ) - 1] = rParaProp; + aProps[aProps.getLength( ) - 1].Name = sFirstLineIndent; + } + else if ( !hasIndentAt && rParaProp.Name == sParaLeftMargin ) + { + aProps.realloc( aProps.getLength() + 1 ); + aProps[aProps.getLength( ) - 1] = rParaProp; + aProps[aProps.getLength( ) - 1].Name = sIndentAt; + } + + } +} + +NumPicBullet::NumPicBullet() + : m_nId(0) +{ +} + +NumPicBullet::~NumPicBullet() +{ +} + +void NumPicBullet::SetId(sal_Int32 nId) +{ + m_nId = nId; +} + +void NumPicBullet::SetShape(uno::Reference const& xShape) +{ + m_xShape = xShape; +} + + +//--------------------------------------- AbstractListDef implementation + +AbstractListDef::AbstractListDef( ) : + m_nId( -1 ) +{ +} + +AbstractListDef::~AbstractListDef( ) +{ +} + +void AbstractListDef::SetValue( sal_uInt32 nSprmId ) +{ + switch( nSprmId ) + { + case NS_ooxml::LN_CT_AbstractNum_tmpl: + break; + default: + OSL_FAIL( "this line should never be reached"); + } +} + +ListLevel::Pointer AbstractListDef::GetLevel( sal_uInt16 nLvl ) +{ + ListLevel::Pointer pLevel; + if ( m_aLevels.size( ) > nLvl ) + pLevel = m_aLevels[ nLvl ]; + return pLevel; +} + +void AbstractListDef::AddLevel( sal_uInt16 nLvl ) +{ + if ( nLvl >= m_aLevels.size() ) + m_aLevels.resize( nLvl+1 ); + + ListLevel::Pointer pLevel( new ListLevel ); + m_pCurrentLevel = pLevel; + m_aLevels[nLvl] = pLevel; +} + +uno::Sequence> AbstractListDef::GetPropertyValues(bool bDefaults) +{ + uno::Sequence< uno::Sequence< beans::PropertyValue > > result( sal_Int32( m_aLevels.size( ) ) ); + uno::Sequence< beans::PropertyValue >* aResult = result.getArray( ); + + int nLevels = m_aLevels.size( ); + for ( int i = 0; i < nLevels; i++ ) + { + if (m_aLevels[i]) + aResult[i] = m_aLevels[i]->GetProperties(bDefaults); + } + + return result; +} + +const OUString& AbstractListDef::MapListId(OUString const& rId) +{ + if (!m_oListId) + { + m_oListId = rId; + } + return *m_oListId; +} + +//---------------------------------------------- ListDef implementation + +ListDef::ListDef( ) : AbstractListDef( ) +{ + m_nDefaultParentLevels = WW_OUTLINE_MAX + 1; +} + +ListDef::~ListDef( ) +{ +} + +OUString ListDef::GetStyleName(sal_Int32 const nId, + uno::Reference const& xStyles) +{ + if (xStyles.is()) + { + OUString sStyleName = "WWNum" + OUString::number( nId ); + + while (xStyles->hasByName(sStyleName)) // unique + { + sStyleName += "a"; + } + + m_StyleName = sStyleName; + } + else + { +// fails in rtftok test assert(!m_StyleName.isEmpty()); // must be inited first + } + + return m_StyleName; +} + +uno::Sequence> ListDef::GetMergedPropertyValues() +{ + if (!m_pAbstractDef) + return uno::Sequence< uno::Sequence< beans::PropertyValue > >(); + + // [1] Call the same method on the abstract list + uno::Sequence> aAbstract + = m_pAbstractDef->GetPropertyValues(/*bDefaults=*/true); + + // [2] Call the upper class method + uno::Sequence> aThis + = AbstractListDef::GetPropertyValues(/*bDefaults=*/false); + + // Merge the results of [2] in [1] + sal_Int32 nThisCount = aThis.getLength( ); + sal_Int32 nAbstractCount = aAbstract.getLength( ); + for ( sal_Int32 i = 0; i < nThisCount && i < nAbstractCount; i++ ) + { + uno::Sequence< beans::PropertyValue > level = aThis[i]; + if (level.hasElements() && GetLevel(i)->HasValues()) + { + // If the element contains something, merge it, but ignore stub overrides. + lcl_mergeProperties( level, aAbstract[i] ); + } + } + + return aAbstract; +} + +static uno::Reference< container::XNameContainer > lcl_getUnoNumberingStyles( + uno::Reference const& xFactory) +{ + uno::Reference< container::XNameContainer > xStyles; + + try + { + uno::Reference< style::XStyleFamiliesSupplier > xFamilies( xFactory, uno::UNO_QUERY_THROW ); + uno::Any oFamily = xFamilies->getStyleFamilies( )->getByName("NumberingStyles"); + + oFamily >>= xStyles; + } + catch ( const uno::Exception & ) + { + } + + return xStyles; +} + +void ListDef::CreateNumberingRules( DomainMapper& rDMapper, + uno::Reference const& xFactory) +{ + // Get the UNO Numbering styles + uno::Reference< container::XNameContainer > xStyles = lcl_getUnoNumberingStyles( xFactory ); + + // Do the whole thing + if( !m_xNumRules.is() && xFactory.is() && xStyles.is( ) ) + { + try + { + // Create the numbering style + uno::Reference< beans::XPropertySet > xStyle ( + xFactory->createInstance("com.sun.star.style.NumberingStyle"), + uno::UNO_QUERY_THROW ); + + OUString sStyleName = GetStyleName(GetId(), xStyles); + + xStyles->insertByName( sStyleName, makeAny( xStyle ) ); + + uno::Any oStyle = xStyles->getByName( sStyleName ); + xStyle.set( oStyle, uno::UNO_QUERY_THROW ); + + // Get the default OOo Numbering style rules + uno::Any aRules = xStyle->getPropertyValue( getPropertyName( PROP_NUMBERING_RULES ) ); + aRules >>= m_xNumRules; + + uno::Sequence> aProps = GetMergedPropertyValues(); + + sal_Int32 nAbstLevels = m_pAbstractDef ? m_pAbstractDef->Size() : 0; + sal_Int32 nLevel = 0; + while ( nLevel < nAbstLevels ) + { + ListLevel::Pointer pAbsLevel = m_pAbstractDef->GetLevel( nLevel ); + ListLevel::Pointer pLevel = GetLevel( nLevel ); + + // Get the merged level properties + auto aLvlProps = comphelper::sequenceToContainer< std::vector >(aProps[nLevel]); + + // Get the char style + uno::Sequence< beans::PropertyValue > aAbsCharStyleProps = pAbsLevel->GetCharStyleProperties( ); + if ( pLevel ) + { + uno::Sequence< beans::PropertyValue >& rAbsCharStyleProps = aAbsCharStyleProps; + uno::Sequence< beans::PropertyValue > aCharStyleProps = + pLevel->GetCharStyleProperties( ); + uno::Sequence< beans::PropertyValue >& rCharStyleProps = aCharStyleProps; + lcl_mergeProperties( rAbsCharStyleProps, rCharStyleProps ); + } + + if( aAbsCharStyleProps.hasElements() ) + { + // Change the sequence into a vector + auto aStyleProps = comphelper::sequenceToContainer(aAbsCharStyleProps); + + //create (or find) a character style containing the character + // attributes of the symbol and apply it to the numbering level + OUString sStyle = rDMapper.getOrCreateCharStyle( aStyleProps, /*bAlwaysCreate=*/true ); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_CHAR_STYLE_NAME), sStyle)); + } + + // Get the prefix / suffix / Parent numbering + // and add them to the level properties + OUString sText = pAbsLevel->GetBulletChar( ); + // Inherit from the abstract level in case the override would be empty. + if (pLevel && !pLevel->GetBulletChar().isEmpty()) + sText = pLevel->GetBulletChar( ); + + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_PREFIX), OUString(""))); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_SUFFIX), OUString(""))); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_LIST_FORMAT), sText)); + + // Total count of replacement holders is determining amount of required parent numbering to include + // TODO: not sure how "%" symbol is escaped. This is not supported yet + sal_Int16 nParentNum = comphelper::string::getTokenCount(sText, '%'); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_PARENT_NUMBERING), nParentNum)); + + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_POSITION_AND_SPACE_MODE), sal_Int16(text::PositionAndSpaceMode::LABEL_ALIGNMENT))); + + // Replace the numbering rules for the level + m_xNumRules->replaceByIndex(nLevel, uno::makeAny(comphelper::containerToSequence(aLvlProps))); + + // Handle the outline level here + if ( pAbsLevel->isOutlineNumbering()) + { + uno::Reference< text::XChapterNumberingSupplier > xOutlines ( + xFactory, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexReplace > xOutlineRules = + xOutlines->getChapterNumberingRules( ); + + StyleSheetEntryPtr pParaStyle = pAbsLevel->GetParaStyle( ); + aLvlProps.push_back(comphelper::makePropertyValue(getPropertyName(PROP_HEADING_STYLE_NAME), pParaStyle->sConvertedStyleName)); + + xOutlineRules->replaceByIndex(nLevel, uno::makeAny(comphelper::containerToSequence(aLvlProps))); + } + + // first level without default outline paragraph style + const tools::SvRef< StyleSheetEntry >& aParaStyle = pAbsLevel->GetParaStyle(); + if ( WW_OUTLINE_MAX + 1 == m_nDefaultParentLevels && ( !aParaStyle || + aParaStyle->sConvertedStyleName.getLength() != RTL_CONSTASCII_LENGTH( "Heading 1" ) || + !aParaStyle->sConvertedStyleName.startsWith("Heading ") || + aParaStyle->sConvertedStyleName[ RTL_CONSTASCII_LENGTH( "Heading " ) ] - u'1' != nLevel ) ) + { + m_nDefaultParentLevels = nLevel; + } + + nLevel++; + } + + // Create the numbering style for these rules + OUString sNumRulesName = getPropertyName( PROP_NUMBERING_RULES ); + xStyle->setPropertyValue( sNumRulesName, uno::makeAny( m_xNumRules ) ); + } + catch( const lang::IllegalArgumentException& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter", "" ); + assert( !"Incorrect argument to UNO call" ); + } + catch( const uno::RuntimeException& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter", "" ); + assert( !"Incorrect argument to UNO call" ); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION( "writerfilter", "" ); + } + } + +} + +//------------------------------------- NumberingManager implementation + + +ListsManager::ListsManager(DomainMapper& rDMapper, + const uno::Reference & xFactory) + : LoggedProperties("ListsManager") + , LoggedTable("ListsManager") + , m_rDMapper(rDMapper) + , m_xFactory(xFactory) +{ +} + +ListsManager::~ListsManager( ) +{ + DisposeNumPicBullets(); +} + +void ListsManager::DisposeNumPicBullets( ) +{ + uno::Reference xShape; + for (const auto& rNumPicBullet : m_aNumPicBullets) + { + xShape = rNumPicBullet->GetShape(); + if (xShape.is()) + { + uno::Reference xShapeComponent(xShape, uno::UNO_QUERY); + xShapeComponent->dispose(); + } + } +} + +void ListsManager::lcl_attribute( Id nName, Value& rVal ) +{ + ListLevel::Pointer pCurrentLvl; + + if (nName != NS_ooxml::LN_CT_NumPicBullet_numPicBulletId) + { + OSL_ENSURE( m_pCurrentDefinition.get(), "current entry has to be set here"); + if(!m_pCurrentDefinition) + return ; + pCurrentLvl = m_pCurrentDefinition->GetCurrentLevel( ); + } + else + { + SAL_WARN_IF(!m_pCurrentNumPicBullet, "writerfilter", "current entry has to be set here"); + if (!m_pCurrentNumPicBullet) + return; + } + int nIntValue = rVal.getInt(); + + + switch(nName) + { + case NS_ooxml::LN_CT_LevelText_val: + { + //this strings contains the definition of the level + //the level number is marked as %n + //these numbers can be mixed randomly together with separators pre- and suffixes + //the Writer supports only a number of upper levels to show, separators is always a dot + //and each level can have a prefix and a suffix + if(pCurrentLvl) + { + //if the BulletChar is a soft-hyphen (0xad) + //replace it with a hard-hyphen (0x2d) + //-> this fixes missing hyphen export in PDF etc. + // see tdf#101626 + pCurrentLvl->SetBulletChar( rVal.getString().replace( 0xad, 0x2d ) ); + } + } + break; + case NS_ooxml::LN_CT_Lvl_start: + case NS_ooxml::LN_CT_Lvl_numFmt: + case NS_ooxml::LN_CT_NumFmt_format: + case NS_ooxml::LN_CT_NumFmt_val: + case NS_ooxml::LN_CT_Lvl_isLgl: + case NS_ooxml::LN_CT_Lvl_legacy: + if ( pCurrentLvl ) + { + if (nName == NS_ooxml::LN_CT_NumFmt_format) + { + pCurrentLvl->SetCustomNumberFormat(rVal.getString()); + } + else + { + pCurrentLvl->SetValue(nName, sal_Int32(nIntValue)); + } + } + break; + case NS_ooxml::LN_CT_Num_numId: + m_pCurrentDefinition->SetId( rVal.getString().toInt32( ) ); + break; + case NS_ooxml::LN_CT_AbstractNum_nsid: + m_pCurrentDefinition->SetId( nIntValue ); + break; + case NS_ooxml::LN_CT_AbstractNum_tmpl: + AbstractListDef::SetValue( nName ); + break; + case NS_ooxml::LN_CT_NumLvl_ilvl: + //add a new level to the level vector and make it the current one + m_pCurrentDefinition->AddLevel(rVal.getString().toUInt32()); + break; + case NS_ooxml::LN_CT_Lvl_ilvl: + m_pCurrentDefinition->AddLevel(rVal.getString().toUInt32()); + break; + case NS_ooxml::LN_CT_AbstractNum_abstractNumId: + { + // This one corresponds to the AbstractNum Id definition + // The reference to the abstract num is in the sprm method + sal_Int32 nVal = rVal.getString().toInt32(); + m_pCurrentDefinition->SetId( nVal ); + } + break; + case NS_ooxml::LN_CT_Ind_start: + case NS_ooxml::LN_CT_Ind_left: + if ( pCurrentLvl ) + pCurrentLvl->Insert( + PROP_INDENT_AT, uno::makeAny( ConversionHelper::convertTwipToMM100( nIntValue ) )); + break; + case NS_ooxml::LN_CT_Ind_hanging: + if ( pCurrentLvl ) + pCurrentLvl->Insert( + PROP_FIRST_LINE_INDENT, uno::makeAny( - ConversionHelper::convertTwipToMM100( nIntValue ) )); + break; + case NS_ooxml::LN_CT_Ind_firstLine: + if ( pCurrentLvl ) + pCurrentLvl->Insert( + PROP_FIRST_LINE_INDENT, uno::makeAny( ConversionHelper::convertTwipToMM100( nIntValue ) )); + break; + case NS_ooxml::LN_CT_Lvl_tplc: //template code - unsupported + case NS_ooxml::LN_CT_Lvl_tentative: //marks level as unused in the document - unsupported + break; + case NS_ooxml::LN_CT_TabStop_pos: + { + //no paragraph attributes in ListTable char style sheets + if ( pCurrentLvl ) + pCurrentLvl->SetValue( nName, + ConversionHelper::convertTwipToMM100( nIntValue ) ); + } + break; + case NS_ooxml::LN_CT_TabStop_val: + { + // TODO Do something of that + } + break; + case NS_ooxml::LN_CT_NumPicBullet_numPicBulletId: + m_pCurrentNumPicBullet->SetId(rVal.getString().toInt32()); + break; + default: + SAL_WARN("writerfilter", "ListsManager::lcl_attribute: unhandled token: " << nName); + } +} + +void ListsManager::lcl_sprm( Sprm& rSprm ) +{ + //fill the attributes of the style sheet + sal_uInt32 nSprmId = rSprm.getId(); + if( m_pCurrentDefinition || + nSprmId == NS_ooxml::LN_CT_Numbering_abstractNum || + nSprmId == NS_ooxml::LN_CT_Numbering_num || + (nSprmId == NS_ooxml::LN_CT_NumPicBullet_pict && m_pCurrentNumPicBullet) || + nSprmId == NS_ooxml::LN_CT_Numbering_numPicBullet) + { + static bool bIsStartVisited = false; + sal_Int32 nIntValue = rSprm.getValue()->getInt(); + switch( nSprmId ) + { + case NS_ooxml::LN_CT_Numbering_abstractNum: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + { + //create a new Abstract list entry + OSL_ENSURE( !m_pCurrentDefinition, "current entry has to be NULL here"); + m_pCurrentDefinition = new AbstractListDef; + pProperties->resolve( *this ); + //append it to the table + m_aAbstractLists.push_back( m_pCurrentDefinition ); + m_pCurrentDefinition = AbstractListDef::Pointer(); + } + } + break; + case NS_ooxml::LN_CT_Numbering_num: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + { + // Create a new list entry + OSL_ENSURE( !m_pCurrentDefinition, "current entry has to be NULL here"); + ListDef::Pointer listDef( new ListDef ); + m_pCurrentDefinition = listDef.get(); + pProperties->resolve( *this ); + //append it to the table + m_aLists.push_back( listDef ); + + m_pCurrentDefinition = AbstractListDef::Pointer(); + } + } + break; + case NS_ooxml::LN_CT_Numbering_numPicBullet: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + NumPicBullet::Pointer numPicBullet(new NumPicBullet()); + m_pCurrentNumPicBullet = numPicBullet; + pProperties->resolve(*this); + m_aNumPicBullets.push_back(numPicBullet); + m_pCurrentNumPicBullet = NumPicBullet::Pointer(); + } + } + break; + case NS_ooxml::LN_CT_NumPicBullet_pict: + { + uno::Reference xShape = m_rDMapper.PopPendingShape(); + + m_pCurrentNumPicBullet->SetShape(xShape); + } + break; + case NS_ooxml::LN_CT_Lvl_lvlPicBulletId: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + uno::Reference xShape; + for (const auto& rNumPicBullet : m_aNumPicBullets) + { + if (rNumPicBullet->GetId() == nIntValue) + { + xShape = rNumPicBullet->GetShape(); + break; + } + } + if (xShape.is()) + { + uno::Reference xPropertySet(xShape, uno::UNO_QUERY); + try + { + uno::Any aAny = xPropertySet->getPropertyValue("Graphic"); + if (aAny.has>() && pCurrentLevel) + { + auto xGraphic = aAny.get>(); + if (xGraphic.is()) + { + uno::Reference xBitmap(xGraphic, uno::UNO_QUERY); + pCurrentLevel->SetGraphicBitmap(xBitmap); + } + } + } + catch (const beans::UnknownPropertyException&) + {} + + // Respect only the aspect ratio of the picture, not its size. + awt::Size aPrefSize = xShape->getSize(); + // See SwDefBulletConfig::InitFont(), default height is 14. + const int nFontHeight = 14; + // Point -> mm100. + const int nHeight = nFontHeight * 35; + if ( aPrefSize.Height * aPrefSize.Width != 0 ) + { + int nWidth = (nHeight * aPrefSize.Width) / aPrefSize.Height; + + awt::Size aSize( convertMm100ToTwip(nWidth), convertMm100ToTwip(nHeight) ); + pCurrentLevel->SetGraphicSize( aSize ); + } + else + { + awt::Size aSize( convertMm100ToTwip(aPrefSize.Width), convertMm100ToTwip(aPrefSize.Height) ); + pCurrentLevel->SetGraphicSize( aSize ); + } + } + } + break; + case NS_ooxml::LN_CT_Num_abstractNumId: + { + sal_Int32 nAbstractNumId = rSprm.getValue()->getInt(); + ListDef* pListDef = dynamic_cast< ListDef* >( m_pCurrentDefinition.get( ) ); + if ( pListDef != nullptr ) + { + // The current def should be a ListDef + pListDef->SetAbstractDefinition( + GetAbstractList( nAbstractNumId ) ); + } + } + break; + case NS_ooxml::LN_CT_AbstractNum_multiLevelType: + break; + case NS_ooxml::LN_CT_AbstractNum_tmpl: + AbstractListDef::SetValue( nSprmId ); + break; + case NS_ooxml::LN_CT_AbstractNum_lvl: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_Lvl_start: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + pCurrentLevel->SetValue( nSprmId, nIntValue ); + bIsStartVisited = true; + break; + case NS_ooxml::LN_CT_Lvl_numFmt: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + pProperties->resolve(*this); + } + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + if( !bIsStartVisited ) + { + pCurrentLevel->SetValue( NS_ooxml::LN_CT_Lvl_start, 0 ); + bIsStartVisited = true; + } + } + } + break; + case NS_ooxml::LN_CT_Lvl_isLgl: + case NS_ooxml::LN_CT_Lvl_legacy: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + pCurrentLevel->SetValue(nSprmId, nIntValue); + } + break; + case NS_ooxml::LN_CT_Lvl_suff: + { + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + SvxNumberFormat::LabelFollowedBy value = SvxNumberFormat::LISTTAB; + if( rSprm.getValue()->getString() == "tab" ) + value = SvxNumberFormat::LISTTAB; + else if( rSprm.getValue()->getString() == "space" ) + value = SvxNumberFormat::SPACE; + else if( rSprm.getValue()->getString() == "nothing" ) + value = SvxNumberFormat::NOTHING; + else + SAL_WARN( "writerfilter", "Unknown ST_LevelSuffix value " + << rSprm.getValue()->getString()); + pCurrentLevel->SetValue( nSprmId, value ); + } + } + break; + case NS_ooxml::LN_CT_Lvl_lvlText: + case NS_ooxml::LN_CT_Lvl_rPr : //contains LN_EG_RPrBase_rFonts + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_NumLvl_lvl: + { + // overwrite level + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_Lvl_lvlJc: + { + sal_Int16 nValue = text::HoriOrientation::NONE; + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_Jc_left: + case NS_ooxml::LN_Value_ST_Jc_start: + nValue = text::HoriOrientation::LEFT; + break; + case NS_ooxml::LN_Value_ST_Jc_center: + nValue = text::HoriOrientation::CENTER; + break; + case NS_ooxml::LN_Value_ST_Jc_right: + case NS_ooxml::LN_Value_ST_Jc_end: + nValue = text::HoriOrientation::RIGHT; + break; + } + + if (nValue != text::HoriOrientation::NONE) + { + if (ListLevel::Pointer pLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + pLevel->Insert( + PROP_ADJUST, uno::makeAny( nValue ) ); + } + } + } + break; + case NS_ooxml::LN_CT_Lvl_pPr: + case NS_ooxml::LN_CT_PPrBase_ind: + { + //todo: how to handle paragraph properties within numbering levels (except LeftIndent and FirstLineIndent)? + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_PPrBase_tabs: + case NS_ooxml::LN_CT_Tabs_tab: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if(pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_Lvl_pStyle: + { + OUString sStyleName = rSprm.getValue( )->getString( ); + if (ListLevel::Pointer pLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + StyleSheetTablePtr pStylesTable = m_rDMapper.GetStyleSheetTable( ); + const StyleSheetEntryPtr pStyle = pStylesTable->FindStyleSheetByISTD( sStyleName ); + pLevel->SetParaStyle( pStyle ); + } + } + break; + case NS_ooxml::LN_CT_Num_lvlOverride: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_NumLvl_startOverride: + { + if(m_pCurrentDefinition) + { + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + pCurrentLevel->SetValue(NS_ooxml::LN_CT_NumLvl_startOverride, nIntValue); + } + } + } + break; + case NS_ooxml::LN_CT_AbstractNum_numStyleLink: + { + OUString sStyleName = rSprm.getValue( )->getString( ); + m_pCurrentDefinition->SetNumStyleLink(sStyleName); + } + break; + case NS_ooxml::LN_CT_AbstractNum_styleLink: + { + OUString sStyleName = rSprm.getValue()->getString(); + m_pCurrentDefinition->SetStyleLink(sStyleName); + } + break; + case NS_ooxml::LN_EG_RPrBase_rFonts: //contains font properties + case NS_ooxml::LN_EG_RPrBase_color: + case NS_ooxml::LN_EG_RPrBase_u: + case NS_ooxml::LN_EG_RPrBase_sz: + case NS_ooxml::LN_EG_RPrBase_lang: + case NS_ooxml::LN_EG_RPrBase_eastAsianLayout: + //no break! + default: + if (ListLevel::Pointer pCurrentLevel = m_pCurrentDefinition->GetCurrentLevel()) + { + m_rDMapper.PushListProperties(pCurrentLevel.get()); + m_rDMapper.sprm( rSprm ); + m_rDMapper.PopListProperties(); + } + } + } +} + +void ListsManager::lcl_entry(writerfilter::Reference::Pointer_t ref ) +{ + if( m_rDMapper.IsOOXMLImport() || m_rDMapper.IsRTFImport() ) + { + ref->resolve(*this); + } + else + { + // Create AbstractListDef's + OSL_ENSURE( !m_pCurrentDefinition, "current entry has to be NULL here"); + m_pCurrentDefinition = new AbstractListDef( ); + ref->resolve(*this); + //append it to the table + m_aAbstractLists.push_back( m_pCurrentDefinition ); + m_pCurrentDefinition = AbstractListDef::Pointer(); + } +} + +AbstractListDef::Pointer ListsManager::GetAbstractList( sal_Int32 nId ) +{ + for (const auto& listDef : m_aAbstractLists) + { + if (listDef->GetId( ) == nId) + { + if (listDef->GetNumStyleLink().getLength() > 0) + { + // If the abstract num has a style linked, check the linked style's number id. + StyleSheetTablePtr pStylesTable = m_rDMapper.GetStyleSheetTable( ); + + const StyleSheetEntryPtr pStyleSheetEntry = + pStylesTable->FindStyleSheetByISTD(listDef->GetNumStyleLink() ); + + const StyleSheetPropertyMap* pStyleSheetProperties = + dynamic_cast(pStyleSheetEntry ? pStyleSheetEntry->pProperties.get() : nullptr); + + if( pStyleSheetProperties && pStyleSheetProperties->GetListId() >= 0 ) + { + ListDef::Pointer pList = GetList( pStyleSheetProperties->GetListId() ); + if ( pList!=nullptr ) + return pList->GetAbstractDefinition(); + } + + // In stylesheet we did not found anything useful. Try to find base abstractnum having this stylelink + for (const auto & baseListDef : m_aAbstractLists) + { + if (baseListDef->GetStyleLink() == listDef->GetNumStyleLink()) + { + return baseListDef; + } + } + } + + // Standalone abstract list + return listDef; + } + } + + return nullptr; +} + +ListDef::Pointer ListsManager::GetList( sal_Int32 nId ) +{ + ListDef::Pointer pList; + + int nLen = m_aLists.size( ); + int i = 0; + while ( !pList && i < nLen ) + { + if ( m_aLists[i]->GetId( ) == nId ) + pList = m_aLists[i]; + i++; + } + + return pList; +} + +void ListsManager::CreateNumberingRules( ) +{ + // Loop over the definitions + for ( const auto& rList : m_aLists ) + { + rList->CreateNumberingRules( m_rDMapper, m_xFactory ); + } + m_rDMapper.GetStyleSheetTable()->ApplyNumberingStyleNameToParaStyles(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/NumberingManager.hxx b/writerfilter/source/dmapper/NumberingManager.hxx new file mode 100644 index 000000000..29f139082 --- /dev/null +++ b/writerfilter/source/dmapper/NumberingManager.hxx @@ -0,0 +1,260 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_NUMBERINGMANAGER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_NUMBERINGMANAGER_HXX + +#include "PropertyMap.hxx" + +#include "DomainMapper.hxx" +#include "LoggedResources.hxx" +#include "StyleSheetTable.hxx" + +#include + +#include +#include + +namespace writerfilter { +namespace dmapper { + +class DomainMapper; +class StyleSheetEntry; + + +/** Class representing the numbering level properties. + */ +class ListLevel : public PropertyMap +{ + sal_Int32 m_nIStartAt; //LN_CT_Lvl_start + sal_Int32 m_nStartOverride; + sal_Int32 m_nNFC; //LN_CT_Lvl_numFmt + /// LN_CT_NumFmt_format, in case m_nNFC is custom. + OUString m_aCustomNumberFormat; + sal_Int16 m_nXChFollow; //LN_IXCHFOLLOW + OUString m_sBulletChar; + css::awt::Size m_aGraphicSize; + css::uno::Reference m_xGraphicBitmap; + std::optional m_nTabstop; + tools::SvRef< StyleSheetEntry > m_pParaStyle; + bool m_outline; + bool m_bHasValues = false; + +public: + + typedef tools::SvRef< ListLevel > Pointer; + + ListLevel() : + m_nIStartAt(-1) + ,m_nStartOverride(-1) + ,m_nNFC(-1) + ,m_nXChFollow(SvxNumberFormat::LISTTAB) + ,m_outline(false) + {} + + // Setters for the import + void SetValue( Id nId, sal_Int32 nValue ); + void SetCustomNumberFormat(const OUString& rValue); + void SetBulletChar( const OUString& sValue ) { m_sBulletChar = sValue; }; + void SetGraphicSize( const css::awt::Size& aValue ) { m_aGraphicSize = aValue; }; + + void SetGraphicBitmap(css::uno::Reference const& xGraphicBitmap) + { m_xGraphicBitmap = xGraphicBitmap; } + void SetParaStyle( const tools::SvRef< StyleSheetEntry >& pStyle ); + + // Getters + const OUString& GetBulletChar( ) const { return m_sBulletChar; }; + const tools::SvRef< StyleSheetEntry >& GetParaStyle( ) const { return m_pParaStyle; }; + bool isOutlineNumbering() const { return m_outline; } + sal_Int32 GetStartOverride() const { return m_nStartOverride; }; + /// Determines if SetValue() was called at least once. + bool HasValues() const; + + // UNO mapping functions + css::uno::Sequence GetProperties(bool bDefaults); + + css::uno::Sequence GetCharStyleProperties(); +private: + + css::uno::Sequence GetLevelProperties(bool bDefaults); + + void AddParaProperties(css::uno::Sequence* pProps); +}; + +/// Represents a numbering picture bullet: an id and a graphic. +class NumPicBullet final : public virtual SvRefBase +{ +public: + typedef tools::SvRef Pointer; + NumPicBullet(); + ~NumPicBullet() override; + + void SetId(sal_Int32 nId); + sal_Int32 GetId() const { return m_nId;} + void SetShape(css::uno::Reference const& xShape); + const css::uno::Reference& GetShape() const { return m_xShape; } +private: + sal_Int32 m_nId; + css::uno::Reference m_xShape; +}; + +class AbstractListDef : public virtual SvRefBase +{ +private: + // The ID member reflects either the abstractNumId or the numId + // depending on the use of the class + sal_Int32 m_nId; + + // Properties of each level. This can also reflect the overridden + // levels of a numbering. + ::std::vector< ListLevel::Pointer > m_aLevels; + + // Only used during the numbering import + ListLevel::Pointer m_pCurrentLevel; + + // The style name linked to. + OUString m_sNumStyleLink; + + // This abstract numbering is a base definition for this style + OUString m_sStyleLink; + + /// list id to use for all derived numbering definitions + std::optional m_oListId; + +public: + typedef tools::SvRef< AbstractListDef > Pointer; + + AbstractListDef( ); + virtual ~AbstractListDef( ) override; + + // Setters using during the import + void SetId( sal_Int32 nId ) { m_nId = nId; }; + static void SetValue( sal_uInt32 nSprmId ); + + // Accessors + sal_Int32 GetId( ) const { return m_nId; }; + + sal_Int16 Size( ) { return sal_Int16( m_aLevels.size( ) ); }; + ListLevel::Pointer GetLevel( sal_uInt16 nLvl ); + void AddLevel( sal_uInt16 nLvl ); + + const ListLevel::Pointer& GetCurrentLevel( ) const { return m_pCurrentLevel; }; + + css::uno::Sequence< css::uno::Sequence > GetPropertyValues(bool bDefaults); + + void SetNumStyleLink(const OUString& sValue) { m_sNumStyleLink = sValue; }; + const OUString& GetNumStyleLink() const { return m_sNumStyleLink; }; + + void SetStyleLink(const OUString& sValue) { m_sStyleLink = sValue; }; + const OUString& GetStyleLink() const { return m_sStyleLink; }; + + const OUString& MapListId(OUString const& rId); + bool isOutlineNumbering( sal_uInt16 nLvl ) { return GetLevel(nLvl) && GetLevel(nLvl)->isOutlineNumbering(); } +}; + +class ListDef : public AbstractListDef +{ +private: + // Pointer to the abstract numbering + AbstractListDef::Pointer m_pAbstractDef; + + // Cache for the UNO numbering rules + css::uno::Reference< css::container::XIndexReplace > m_xNumRules; + + /// mapped list style name + OUString m_StyleName; + + /// not custom outline parent levels + sal_Int16 m_nDefaultParentLevels; + +public: + typedef tools::SvRef< ListDef > Pointer; + + ListDef( ); + virtual ~ListDef( ) override; + + // Accessors + void SetAbstractDefinition( AbstractListDef::Pointer pAbstract ) { m_pAbstractDef = pAbstract; }; + const AbstractListDef::Pointer& GetAbstractDefinition( ) const { return m_pAbstractDef; }; + + // Mapping functions + OUString GetStyleName() const { return m_StyleName; }; + OUString GetStyleName(sal_Int32 nId, css::uno::Reference const& xStyles); + + sal_Int16 GetDefaultParentLevels() const { return m_nDefaultParentLevels; }; + + css::uno::Sequence< css::uno::Sequence > GetMergedPropertyValues(); + + void CreateNumberingRules(DomainMapper& rDMapper, css::uno::Reference const& xFactory); + + const css::uno::Reference& GetNumberingRules() const { return m_xNumRules; } + +}; + +/** This class provides access to the defined numbering styles. + */ +class ListsManager : + public LoggedProperties, + public LoggedTable +{ +private: + + DomainMapper& m_rDMapper; + css::uno::Reference m_xFactory; + + // The numbering entries + std::vector< NumPicBullet::Pointer > m_aNumPicBullets; + std::vector< AbstractListDef::Pointer > m_aAbstractLists; + std::vector< ListDef::Pointer > m_aLists; + + + // These members are used for import only + AbstractListDef::Pointer m_pCurrentDefinition; + NumPicBullet::Pointer m_pCurrentNumPicBullet; + + AbstractListDef::Pointer GetAbstractList( sal_Int32 nId ); + + // Properties + virtual void lcl_attribute( Id nName, Value & rVal ) override; + virtual void lcl_sprm(Sprm & sprm) override; + + // Table + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) override; + +public: + + ListsManager(DomainMapper& rDMapper, const css::uno::Reference& xFactory); + virtual ~ListsManager() override; + + typedef tools::SvRef< ListsManager > Pointer; + + ListDef::Pointer GetList( sal_Int32 nId ); + + // Mapping methods + void CreateNumberingRules( ); + + // Dispose the NumPicBullets + void DisposeNumPicBullets( ); +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/OLEHandler.cxx b/writerfilter/source/dmapper/OLEHandler.cxx new file mode 100644 index 000000000..ae1967a4a --- /dev/null +++ b/writerfilter/source/dmapper/OLEHandler.cxx @@ -0,0 +1,316 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "OLEHandler.hxx" +#include "DomainMapper.hxx" +#include "GraphicHelpers.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + + +OLEHandler::OLEHandler(DomainMapper& rDomainMapper) : +LoggedProperties("OLEHandler"), + m_nWrapMode(text::WrapTextMode_THROUGHT), + m_rDomainMapper(rDomainMapper) +{ +} + + +OLEHandler::~OLEHandler() +{ +} + + +void OLEHandler::lcl_attribute(Id rName, Value & rVal) +{ + OUString sStringValue = rVal.getString(); + switch( rName ) + { + case NS_ooxml::LN_CT_OLEObject_Type: + break; + case NS_ooxml::LN_CT_OLEObject_ProgID: + m_sProgId = sStringValue; + break; + case NS_ooxml::LN_CT_OLEObject_ShapeID: + break; + case NS_ooxml::LN_CT_OLEObject_DrawAspect: + m_sDrawAspect = sStringValue; + break; + case NS_ooxml::LN_CT_OLEObject_ObjectID: + break; + case NS_ooxml::LN_CT_OLEObject_r_id: + break; + case NS_ooxml::LN_inputstream: + rVal.getAny() >>= m_xInputStream; + break; + case NS_ooxml::LN_CT_Object_dxaOrig: + m_sVisAreaWidth = sStringValue; + break; + case NS_ooxml::LN_CT_Object_dyaOrig: + m_sVisAreaHeight = sStringValue; + break; + case NS_ooxml::LN_shape: + { + uno::Reference< drawing::XShape > xTempShape; + rVal.getAny() >>= xTempShape; + + // Control shape is handled on a different code path + uno::Reference< lang::XServiceInfo > xSInfo( xTempShape, uno::UNO_QUERY_THROW ); + if(xSInfo->supportsService("com.sun.star.drawing.ControlShape")) + { + m_rDomainMapper.hasControls(true); + break; + } + + if( xTempShape.is() ) + { + m_xShape.set( xTempShape ); + uno::Reference< beans::XPropertySet > xShapeProps( xTempShape, uno::UNO_QUERY ); + + try + { + // Shapes in the header or footer should be in the background, since the default is WrapTextMode_THROUGH. + if (m_rDomainMapper.IsInHeaderFooter()) + xShapeProps->setPropertyValue("Opaque", uno::makeAny(false)); + + m_aShapeSize = xTempShape->getSize(); + + xShapeProps->getPropertyValue( getPropertyName( PROP_BITMAP ) ) >>= m_xReplacement; + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("writerfilter", "Exception in OLE Handler"); + } + // No need to set the wrapping here as it's either set in oox or will be set later + } + } + break; + default: + OSL_FAIL( "unknown attribute"); + } +} + + +void OLEHandler::lcl_sprm(Sprm & rSprm) +{ + sal_uInt32 nSprmId = rSprm.getId(); + switch( nSprmId ) + { + case NS_ooxml::LN_OLEObject_OLEObject: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + pProperties->resolve(*this); + } + } + break; + case NS_ooxml::LN_wrap_wrap: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if ( pProperties ) + { + tools::SvRef pHandler( new WrapHandler ); + pProperties->resolve( *pHandler ); + + m_nWrapMode = pHandler->getWrapMode( ); + + try + { + uno::Reference< beans::XPropertySet > xShapeProps( m_xShape, uno::UNO_QUERY_THROW ); + + xShapeProps->setPropertyValue( + getPropertyName( PROP_SURROUND ), + uno::makeAny( static_cast(m_nWrapMode) ) ); + + // Through shapes in the header or footer(that spill into the body) should be in the background. + // It is just assumed that all shapes will spill into the body. + if( m_rDomainMapper.IsInHeaderFooter() ) + xShapeProps->setPropertyValue("Opaque", uno::makeAny(m_nWrapMode != text::WrapTextMode_THROUGH)); + } + catch( const uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("writerfilter", "Exception in OLE Handler"); + } + } + } + break; + default: + { + OSL_FAIL( "unknown attribute"); + } + } +} + +void OLEHandler::importStream(const uno::Reference& xComponentContext, const uno::Reference& xTextDocument, const uno::Reference& xOLE) +{ + OUString aFilterService; + if (m_sProgId == "Word.Document.12") + aFilterService = "com.sun.star.comp.Writer.WriterFilter"; + else if (m_sProgId == "Excel.Sheet.12") + aFilterService = "com.sun.star.comp.oox.xls.ExcelFilter"; + else if (m_sProgId == "Equation.3") + aFilterService = "com.sun.star.comp.Math.MathTypeFilter"; + else + SAL_WARN("writerfilter", "OLEHandler::importStream: unhandled m_sProgId: " << m_sProgId); + + if (!m_xInputStream.is() || aFilterService.isEmpty()) + return; + + // Create the filter service. + uno::Reference xInterface = xComponentContext->getServiceManager()->createInstanceWithContext(aFilterService, xComponentContext); + + // Set target document. + uno::Reference xImporter(xInterface, uno::UNO_QUERY); + uno::Reference xSupplier(xOLE, uno::UNO_QUERY); + uno::Reference xEmbeddedObject = xSupplier->getEmbeddedObject(); + if (!xEmbeddedObject.is()) + return; + xImporter->setTargetDocument( xEmbeddedObject ); + + // Import the input stream. + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["InputStream"] <<= m_xInputStream; + uno::Reference xFilter(xInterface, uno::UNO_QUERY); + xFilter->filter(aMediaDescriptor.getAsConstPropertyValueList()); + + // Now that the data is imported, update the (typically) changed stream name. + uno::Reference xPropertySet(xOLE, uno::UNO_QUERY); + ::oox::ole::SaveInteropProperties(xTextDocument, + xPropertySet->getPropertyValue("StreamName").get(), &m_aURL, + m_sProgId); +} + +OUString OLEHandler::getCLSID(const uno::Reference& xComponentContext) const +{ + OUString aRet; + + // See officecfg/registry/data/org/openoffice/Office/Embedding.xcu. + if (m_sProgId == "Word.Document.12") + { + if (officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::get(xComponentContext)) + aRet = "8BC6B165-B1B2-4EDD-aa47-dae2ee689dd6"; + } + else if (m_sProgId == "Excel.Sheet.12") + { + if (officecfg::Office::Common::Filter::Microsoft::Import::ExcelToCalc::get(xComponentContext)) + aRet = "47BBB4CB-CE4C-4E80-A591-42D9AE74950F"; + } + else if (m_sProgId == "Equation.3") + { + if (officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::get(xComponentContext)) + aRet = "078B7ABA-54FC-457F-8551-6147E776A997"; + } + else + SAL_WARN("writerfilter", "OLEHandler::getCLSID: unhandled m_sProgId: " << m_sProgId); + + return aRet; +} + +OUString const & OLEHandler::GetDrawAspect() const +{ + return m_sDrawAspect; +} + +OUString const & OLEHandler::GetVisAreaWidth() const +{ + return m_sVisAreaWidth; +} + +OUString const & OLEHandler::GetVisAreaHeight() const +{ + return m_sVisAreaHeight; +} + +OUString OLEHandler::copyOLEOStream( + uno::Reference const& xTextDocument) +{ + OUString sRet; + if( !m_xInputStream.is( ) ) + return sRet; + try + { + uno::Reference < lang::XMultiServiceFactory > xFactory(xTextDocument, uno::UNO_QUERY_THROW); + uno::Reference< document::XEmbeddedObjectResolver > xEmbeddedResolver( + xFactory->createInstance("com.sun.star.document.ImportEmbeddedObjectResolver"), uno::UNO_QUERY_THROW ); + //hack to work with the ImportEmbeddedObjectResolver + static sal_Int32 nObjectCount = 100; + uno::Reference< container::XNameAccess > xNA( xEmbeddedResolver, uno::UNO_QUERY_THROW ); + OUString aURL = "Obj" + OUString::number( nObjectCount++ ); + uno::Reference < io::XOutputStream > xOLEStream; + if( (xNA->getByName( aURL ) >>= xOLEStream) && xOLEStream.is() ) + { + const sal_Int32 nReadRequest = 0x1000; + uno::Sequence< sal_Int8 > aData; + + while( true ) + { + sal_Int32 nRead = m_xInputStream->readBytes( aData, nReadRequest ); + xOLEStream->writeBytes( aData ); + if( nRead < nReadRequest ) + { + xOLEStream->closeOutput(); + break; + } + } + + ::oox::ole::SaveInteropProperties(xTextDocument, aURL, nullptr, m_sProgId); + + OUString aPersistName( xEmbeddedResolver->resolveEmbeddedObjectURL( aURL ) ); + sRet = aPersistName.copy( strlen("vnd.sun.star.EmbeddedObject:") ); + + } + uno::Reference< lang::XComponent > xComp( xEmbeddedResolver, uno::UNO_QUERY_THROW ); + xComp->dispose(); + m_aURL = aURL; + } + catch( const uno::Exception& ) + { + OSL_FAIL("exception in OLEHandler::createOLEObject"); + } + return sRet; +} + +} //namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/OLEHandler.hxx b/writerfilter/source/dmapper/OLEHandler.hxx new file mode 100644 index 000000000..e173ab40b --- /dev/null +++ b/writerfilter/source/dmapper/OLEHandler.hxx @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_OLEHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_OLEHANDLER_HXX + +#include "LoggedResources.hxx" +#include +#include +#include + +namespace com::sun::star{ + namespace graphic{ + class XGraphic; + } + namespace io{ + class XInputStream; + } + namespace text{ + class XTextContent; + class XTextDocument; + } + namespace uno { + class XComponentContext; + } +} +namespace writerfilter { +namespace dmapper +{ +class DomainMapper; +/** Handler for OLE objects + */ +class OLEHandler : public LoggedProperties +{ + OUString m_sProgId; + OUString m_sDrawAspect; + OUString m_sVisAreaWidth; + OUString m_sVisAreaHeight; + /// The stream URL right after the import of the raw data. + OUString m_aURL; + + css::text::WrapTextMode m_nWrapMode; + + css::uno::Reference m_xShape; + + css::awt::Size m_aShapeSize; + + css::uno::Reference m_xReplacement; + + css::uno::Reference m_xInputStream; + DomainMapper& m_rDomainMapper; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +public: + explicit OLEHandler(DomainMapper& rDomainMapper); + virtual ~OLEHandler() override; + + const css::uno::Reference& getShape() const { return m_xShape; }; + + bool isOLEObject() const { return m_xInputStream.is(); } + + /// In case of a valid CLSID, import the native data to the previously created empty OLE object. + void importStream(const css::uno::Reference& xComponentContext, + const css::uno::Reference& xTextDocument, + const css::uno::Reference& xOLE); + + /// Get the CLSID of the OLE object, in case we can find one based on m_sProgId. + OUString getCLSID(const css::uno::Reference& xComponentContext) const; + + OUString const & GetDrawAspect() const; + OUString const & GetVisAreaWidth() const; + OUString const & GetVisAreaHeight() const; + + OUString copyOLEOStream(css::uno::Reference const& xTextDocument); + + const css::awt::Size& getSize() const { return m_aShapeSize; } + const css::uno::Reference& getReplacement() const { return m_xReplacement; } + +}; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PageBordersHandler.cxx b/writerfilter/source/dmapper/PageBordersHandler.cxx new file mode 100644 index 000000000..d6a0fdd1f --- /dev/null +++ b/writerfilter/source/dmapper/PageBordersHandler.cxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "BorderHandler.hxx" +#include "PageBordersHandler.hxx" + +#include + +namespace writerfilter::dmapper { + +PgBorder::PgBorder( ) : + m_nDistance( 0 ), + m_ePos( BORDER_RIGHT ), + m_bShadow(false) +{ +} + +PageBordersHandler::PageBordersHandler( ) : +LoggedProperties("PageBordersHandler"), +m_eBorderApply(SectionPropertyMap::BorderApply::ToAllInSection), +m_eOffsetFrom(SectionPropertyMap::BorderOffsetFrom::Text) +{ +} + +PageBordersHandler::~PageBordersHandler( ) +{ +} + +void PageBordersHandler::lcl_attribute( Id eName, Value& rVal ) +{ + int nIntValue = rVal.getInt( ); + switch ( eName ) + { + case NS_ooxml::LN_CT_PageBorders_display: + { + switch ( nIntValue ) + { + default: + case NS_ooxml::LN_Value_doc_ST_PageBorderDisplay_allPages: + m_eBorderApply = SectionPropertyMap::BorderApply::ToAllInSection; + break; + case NS_ooxml::LN_Value_doc_ST_PageBorderDisplay_firstPage: + m_eBorderApply = SectionPropertyMap::BorderApply::ToFirstPageInSection; + break; + case NS_ooxml::LN_Value_doc_ST_PageBorderDisplay_notFirstPage: + m_eBorderApply = SectionPropertyMap::BorderApply::ToAllButFirstInSection; + break; + } + } + break; + case NS_ooxml::LN_CT_PageBorders_offsetFrom: + { + switch ( nIntValue ) + { + default: + case NS_ooxml::LN_Value_doc_ST_PageBorderOffset_page: + m_eOffsetFrom = SectionPropertyMap::BorderOffsetFrom::Edge; + break; + case NS_ooxml::LN_Value_doc_ST_PageBorderOffset_text: + m_eOffsetFrom = SectionPropertyMap::BorderOffsetFrom::Text; + break; + } + } + break; + default:; + } +} + +void PageBordersHandler::lcl_sprm( Sprm& rSprm ) +{ + switch ( rSprm.getId( ) ) + { + case NS_ooxml::LN_CT_PageBorders_top: + case NS_ooxml::LN_CT_PageBorders_left: + case NS_ooxml::LN_CT_PageBorders_bottom: + case NS_ooxml::LN_CT_PageBorders_right: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pBorderHandler = std::make_shared( true ); + pProperties->resolve(*pBorderHandler); + BorderPosition ePos = BorderPosition( 0 ); + switch( rSprm.getId( ) ) + { + case NS_ooxml::LN_CT_PageBorders_top: + ePos = BORDER_TOP; + break; + case NS_ooxml::LN_CT_PageBorders_left: + ePos = BORDER_LEFT; + break; + case NS_ooxml::LN_CT_PageBorders_bottom: + ePos = BORDER_BOTTOM; + break; + case NS_ooxml::LN_CT_PageBorders_right: + ePos = BORDER_RIGHT; + break; + default:; + } + + PgBorder aPgBorder; + aPgBorder.m_rLine = pBorderHandler->getBorderLine( ); + aPgBorder.m_nDistance = pBorderHandler->getLineDistance( ); + aPgBorder.m_ePos = ePos; + aPgBorder.m_bShadow = pBorderHandler->getShadow(); + m_aBorders.push_back( aPgBorder ); + } + } + break; + default:; + } +} + +void PageBordersHandler::SetBorders( SectionPropertyMap* pSectContext ) +{ + for (const PgBorder& rBorder : m_aBorders) + { + pSectContext->SetBorder( rBorder.m_ePos, rBorder.m_nDistance, rBorder.m_rLine, rBorder.m_bShadow ); + } + pSectContext->SetBorderApply(m_eBorderApply); + pSectContext->SetBorderOffsetFrom(m_eOffsetFrom); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PageBordersHandler.hxx b/writerfilter/source/dmapper/PageBordersHandler.hxx new file mode 100644 index 000000000..3bfe23ee6 --- /dev/null +++ b/writerfilter/source/dmapper/PageBordersHandler.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PAGEBORDERSHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PAGEBORDERSHANDLER_HXX + +#include "PropertyMap.hxx" + +#include "LoggedResources.hxx" + +#include + +#include + + +namespace writerfilter { +namespace dmapper { + +class PgBorder +{ +public: + css::table::BorderLine2 m_rLine; + sal_Int32 m_nDistance; + BorderPosition m_ePos; + bool m_bShadow; + + PgBorder( ); +}; + +class PageBordersHandler : public LoggedProperties +{ +private: + + // See implementation of SectionPropertyMap::ApplyBorderToPageStyles + SectionPropertyMap::BorderApply m_eBorderApply; + SectionPropertyMap::BorderOffsetFrom m_eOffsetFrom; + std::vector m_aBorders; + + // Properties + virtual void lcl_attribute( Id eName, Value& rVal ) override; + virtual void lcl_sprm( Sprm& rSprm ) override; + +public: + PageBordersHandler( ); + virtual ~PageBordersHandler( ) override; + + void SetBorders( SectionPropertyMap* pSectContext ); +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx new file mode 100644 index 000000000..3aafab2c9 --- /dev/null +++ b/writerfilter/source/dmapper/PropertyIds.cxx @@ -0,0 +1,377 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include +#include "PropertyIds.hxx" + +namespace writerfilter::dmapper{ + +OUString getPropertyName( PropertyIds eId ) +{ + OUString sName; + switch(eId) { + case PROP_CHAR_WEIGHT: sName = "CharWeight"; break; + case PROP_CHAR_POSTURE: sName = "CharPosture"; break; + case PROP_CHAR_STRIKEOUT: sName = "CharStrikeout"; break; + case PROP_CHAR_CONTOURED: sName = "CharContoured"; break; + case PROP_CHAR_SHADOWED: sName = "CharShadowed"; break; + case PROP_CHAR_CASE_MAP: sName = "CharCaseMap"; break; + case PROP_CHAR_COLOR: sName = "CharColor"; break; + case PROP_CHAR_RELIEF: sName = "CharRelief"; break; + case PROP_CHAR_UNDERLINE: sName = "CharUnderline"; break; + case PROP_CHAR_UNDERLINE_COLOR: sName = "CharUnderlineColor"; break; + case PROP_CHAR_UNDERLINE_HAS_COLOR: sName = "CharUnderlineHasColor"; break; + case PROP_CHAR_WORD_MODE: sName = "CharWordMode"; break; + case PROP_CHAR_ESCAPEMENT : sName = "CharEscapement"; break; + case PROP_CHAR_ESCAPEMENT_HEIGHT: sName = "CharEscapementHeight"; break; + case PROP_CHAR_HEIGHT: sName = "CharHeight"; break; + case PROP_CHAR_HEIGHT_COMPLEX: sName = "CharHeightComplex"; break; + case PROP_CHAR_LOCALE: sName = "CharLocale"; break; + case PROP_CHAR_LOCALE_ASIAN: sName = "CharLocaleAsian"; break; + case PROP_CHAR_LOCALE_COMPLEX: sName = "CharLocaleComplex"; break; + case PROP_CHAR_WEIGHT_COMPLEX : sName = "CharWeightComplex"; break; + case PROP_CHAR_POSTURE_COMPLEX: sName = "CharPostureComplex"; break; + case PROP_CHAR_CHAR_KERNING: sName = "CharKerning"; break; + case PROP_CHAR_AUTO_KERNING: sName = "CharAutoKerning"; break; + case PROP_CHAR_SCALE_WIDTH: sName = "CharScaleWidth"; break; + case PROP_CHAR_STYLE_NAME: sName = "CharStyleName"; break; + case PROP_CHAR_FONT_NAME: sName = "CharFontName"; break; + case PROP_CHAR_FONT_CHAR_SET: sName = "CharFontCharSet"; break; + case PROP_CHAR_FONT_NAME_ASIAN : sName = "CharFontNameAsian"; break; + case PROP_CHAR_HEIGHT_ASIAN : sName = "CharHeightAsian"; break; + case PROP_CHAR_FONT_NAME_COMPLEX : sName = "CharFontNameComplex"; break; + case PROP_CHAR_HIDDEN : sName = "CharHidden"; break; + case PROP_CHAR_WEIGHT_ASIAN : sName = "CharWeightAsian"; break; + case PROP_CHAR_POSTURE_ASIAN : sName = "CharPostureAsian"; break; + case PROP_CHAR_BACK_COLOR: sName = "CharBackColor"; break; + case PROP_CHAR_EMPHASIS: sName = "CharEmphasis"; break; + case PROP_CHAR_COMBINE_IS_ON: sName = "CharCombineIsOn"; break; + case PROP_CHAR_COMBINE_PREFIX: sName = "CharCombinePrefix"; break; + case PROP_CHAR_COMBINE_SUFFIX: sName = "CharCombineSuffix"; break; + case PROP_CHAR_ROTATION: sName = "CharRotation"; break; + case PROP_CHAR_ROTATION_IS_FIT_TO_LINE: sName = "CharRotationIsFitToLine"; break; + case PROP_CHAR_FLASH: sName = "CharFlash"; break; + case PROP_CHAR_LEFT_BORDER: sName = "CharLeftBorder";break; + case PROP_CHAR_RIGHT_BORDER: sName = "CharRightBorder";break; + case PROP_CHAR_TOP_BORDER: sName = "CharTopBorder";break; + case PROP_CHAR_BOTTOM_BORDER: sName = "CharBottomBorder";break; + case PROP_CHAR_LEFT_BORDER_DISTANCE: sName = "CharLeftBorderDistance"; break; + case PROP_CHAR_RIGHT_BORDER_DISTANCE: sName = "CharRightBorderDistance"; break; + case PROP_CHAR_TOP_BORDER_DISTANCE: sName = "CharTopBorderDistance";break; + case PROP_CHAR_BOTTOM_BORDER_DISTANCE: sName = "CharBottomBorderDistance"; break; + case PROP_CHAR_SHADOW_FORMAT: sName = "CharShadowFormat"; break; + case PROP_CHAR_HIGHLIGHT: sName = "CharHighlight"; break; + case PROP_PARA_STYLE_NAME: sName = "ParaStyleName"; break; + case PROP_PARA_ADJUST: sName = "ParaAdjust"; break; + case PROP_PARA_VERT_ALIGNMENT: sName = "ParaVertAlignment"; break; + case PROP_PARA_LAST_LINE_ADJUST: sName = "ParaLastLineAdjust"; break; + case PROP_PARA_RIGHT_MARGIN : sName = "ParaRightMargin"; break; + case PROP_PARA_LEFT_MARGIN : sName = "ParaLeftMargin"; break; + case PROP_PARA_FIRST_LINE_INDENT: sName = "ParaFirstLineIndent"; break; + case PROP_PARA_KEEP_TOGETHER: sName = "ParaKeepTogether"; break; + case PROP_PARA_TOP_MARGIN: sName = "ParaTopMargin"; break; + case PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING: sName = "ParaTopMarginBeforeAutoSpacing"; break; + case PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING: sName = "ParaBottomMarginAfterAutoSpacing"; break; + case PROP_PARA_CONTEXT_MARGIN: sName = "ParaContextMargin"; break; + case PROP_PARA_BOTTOM_MARGIN: sName = "ParaBottomMargin"; break; + case PROP_PARA_IS_HYPHENATION: sName = "ParaIsHyphenation"; break; + case PROP_PARA_HYPHENATION_NO_CAPS: sName = "ParaHyphenationNoCaps"; break; + case PROP_PARA_LINE_NUMBER_COUNT: sName = "ParaLineNumberCount"; break; + case PROP_PARA_IS_HANGING_PUNCTUATION: sName = "ParaIsHangingPunctuation"; break; + case PROP_PARA_LINE_SPACING: sName = "ParaLineSpacing"; break; + case PROP_PARA_TAB_STOPS: sName = "ParaTabStops"; break; + case PROP_PARA_WIDOWS: sName = "ParaWidows"; break; + case PROP_PARA_ORPHANS: sName = "ParaOrphans"; break; + case PROP_PARA_LINE_NUMBER_START_VALUE: sName = "ParaLineNumberStartValue"; break; + case PROP_NUMBERING_LEVEL: sName = "NumberingLevel"; break; + case PROP_NUMBERING_RULES: sName = "NumberingRules"; break; + case PROP_NUMBERING_TYPE: sName = "NumberingType"; break; + case PROP_START_WITH: sName = "StartWith"; break; + case PROP_ADJUST: sName = "Adjust"; break; + case PROP_PARENT_NUMBERING: sName = "ParentNumbering"; break; + case PROP_RIGHT_MARGIN : sName = "RightMargin"; break; + case PROP_LEFT_MARGIN : sName = "LeftMargin"; break; + case PROP_TOP_MARGIN : sName = "TopMargin"; break; + case PROP_BOTTOM_MARGIN : sName = "BottomMargin"; break; + case PROP_FIRST_LINE_OFFSET: sName = "FirstLineOffset"; break; + case PROP_LEFT_BORDER : sName = "LeftBorder";break; + case PROP_RIGHT_BORDER : sName = "RightBorder";break; + case PROP_TOP_BORDER : sName = "TopBorder";break; + case PROP_BOTTOM_BORDER : sName = "BottomBorder";break; + case PROP_TABLE_BORDER : sName = "TableBorder";break; + case PROP_TABLE_ROW_DELETE : sName = "TableRowDelete"; break; + case PROP_TABLE_ROW_INSERT : sName = "TableRowInsert"; break; + case PROP_TABLE_CELL_DELETE : sName = "TableCellDelete"; break; + case PROP_TABLE_CELL_INSERT : sName = "TableCellInsert"; break; + case PROP_LEFT_BORDER_DISTANCE : sName = "LeftBorderDistance"; break; + case PROP_RIGHT_BORDER_DISTANCE : sName = "RightBorderDistance"; break; + case PROP_TOP_BORDER_DISTANCE : sName = "TopBorderDistance";break; + case PROP_BOTTOM_BORDER_DISTANCE: sName = "BottomBorderDistance"; break; + case PROP_CURRENT_PRESENTATION : sName = "CurrentPresentation"; break; + case PROP_IS_FIXED : sName = "IsFixed"; break; + case PROP_SUB_TYPE : sName = "SubType"; break; + case PROP_FILE_FORMAT : sName = "FileFormat"; break; + case PROP_HYPER_LINK_U_R_L : sName = "HyperLinkURL"; break; + case PROP_NUMBER_FORMAT : sName = "NumberFormat"; break; + case PROP_NAME : sName = "Name"; break; + case PROP_IS_INPUT : sName = "IsInput"; break; + case PROP_HINT : sName = "Hint"; break; + case PROP_FULL_NAME : sName = "FullName"; break; + case PROP_DESCRIPTION : sName = "Description"; break; + case PROP_MACRO_NAME : sName = "MacroName"; break; + case PROP_TITLE : sName = "Title"; break; + case PROP_CONTENT : sName = "Content"; break; + case PROP_INPUT_STREAM : sName = "InputStream"; break; + case PROP_GRAPHIC : sName = "Graphic"; break; + case PROP_ANCHOR_TYPE : sName = "AnchorType"; break; + case PROP_SIZE : sName = "Size"; break; + case PROP_HORI_ORIENT : sName = "HoriOrient"; break; + case PROP_HORI_ORIENT_POSITION : sName = "HoriOrientPosition"; break; + case PROP_HORI_ORIENT_RELATION : sName = "HoriOrientRelation"; break; + case PROP_VERT_ORIENT : sName = "VertOrient"; break; + case PROP_VERT_ORIENT_POSITION : sName = "VertOrientPosition"; break; + case PROP_VERT_ORIENT_RELATION : sName = "VertOrientRelation"; break; + case PROP_SIZE100th_M_M : sName = "Size100thMM"; break; + case PROP_SIZE_PIXEL : sName = "SizePixel"; break; + case PROP_SURROUND : sName = "Surround"; break; + case PROP_SURROUND_CONTOUR : sName = "SurroundContour"; break; + case PROP_ADJUST_CONTRAST : sName = "AdjustContrast"; break; + case PROP_ADJUST_LUMINANCE : sName = "AdjustLuminance"; break; + case PROP_GRAPHIC_COLOR_MODE : sName = "GraphicColorMode"; break; + case PROP_CONTOUR_OUTSIDE : sName = "ContourOutside"; break; + case PROP_CONTOUR_POLY_POLYGON : sName = "ContourPolyPolygon"; break; + case PROP_PAGE_TOGGLE : sName = "PageToggle"; break; + case PROP_BACK_COLOR : sName = "BackColor"; break; + case PROP_BACK_COLOR_TRANSPARENCY: sName = "BackColorTransparency"; break; + case PROP_ALTERNATIVE_TEXT : sName = "AlternativeText"; break; + case PROP_HEADER_TEXT_LEFT : sName = "HeaderTextLeft"; break; + case PROP_HEADER_TEXT : sName = "HeaderText"; break; + case PROP_HEADER_IS_SHARED : sName = "HeaderIsShared"; break; + case PROP_HEADER_IS_ON : sName = "HeaderIsOn"; break; + case PROP_FOOTER_TEXT_LEFT : sName = "FooterTextLeft"; break; + case PROP_FOOTER_TEXT : sName = "FooterText"; break; + case PROP_FOOTER_IS_SHARED : sName = "FooterIsShared"; break; + case PROP_FOOTER_IS_ON : sName = "FooterIsOn"; break; + case PROP_FOOTNOTE_COUNTING : sName = "FootnoteCounting"; break; + case PROP_FOOTNOTE_LINE_ADJUST : sName = "FootnoteLineAdjust"; break; + case PROP_WIDTH : sName = "Width"; break; + case PROP_HEIGHT : sName = "Height"; break; + case PROP_TEXT_COLUMNS : sName = "TextColumns"; break; + case PROP_AUTOMATIC_DISTANCE : sName = "AutomaticDistance"; break; + case PROP_IS_LANDSCAPE : sName = "IsLandscape"; break; + case PROP_FIRST_PAGE : sName = "First Page"; break; + case PROP_PAGE_DESC_NAME : sName = "PageDescName"; break; + case PROP_PAGE_NUMBER_OFFSET: sName = "PageNumberOffset"; break; + case PROP_BREAK_TYPE : sName = "BreakType"; break; + case PROP_FOOTER_IS_DYNAMIC_HEIGHT: sName = "FooterIsDynamicHeight"; break; + case PROP_FOOTER_DYNAMIC_SPACING: sName = "FooterDynamicSpacing"; break; + case PROP_FOOTER_HEIGHT : sName = "FooterHeight"; break; + case PROP_FOOTER_BODY_DISTANCE : sName = "FooterBodyDistance"; break; + case PROP_HEADER_IS_DYNAMIC_HEIGHT: sName = "HeaderIsDynamicHeight"; break; + case PROP_HEADER_DYNAMIC_SPACING: sName = "HeaderDynamicSpacing"; break; + case PROP_HEADER_HEIGHT : sName = "HeaderHeight"; break; + case PROP_HEADER_BODY_DISTANCE : sName = "HeaderBodyDistance"; break; + case PROP_WRITING_MODE : sName = "WritingMode"; break; + case PROP_GRID_MODE : sName = "GridMode"; break; + case PROP_GRID_DISPLAY : sName = "GridDisplay"; break; + case PROP_GRID_PRINT : sName = "GridPrint"; break; + case PROP_GRID_LINES : sName = "GridLines"; break; + case PROP_GRID_BASE_HEIGHT : sName = "GridBaseHeight"; break; + case PROP_GRID_BASE_WIDTH : sName = "GridBaseWidth"; break; + case PROP_GRID_RUBY_HEIGHT : sName = "GridRubyHeight"; break; + case PROP_GRID_STANDARD_MODE : sName = "StandardPageMode"; break; + case PROP_IS_ON : sName = "IsOn"; break; + case PROP_RESTART_AT_EACH_PAGE : sName = "RestartAtEachPage"; break; + case PROP_COUNT_EMPTY_LINES : sName = "CountEmptyLines"; break; + case PROP_COUNT_LINES_IN_FRAMES : sName = "CountLinesInFrames"; break; + case PROP_INTERVAL : sName = "Interval"; break; + case PROP_DISTANCE : sName = "Distance"; break; + case PROP_NUMBER_POSITION : sName = "NumberPosition"; break; + case PROP_LEVEL : sName = "Level"; break; + case PROP_LEVEL_FOLLOW : sName = "LabelFollowedBy"; break; + case PROP_LEVEL_PARAGRAPH_STYLES : sName = "LevelParagraphStyles"; break; + case PROP_LEVEL_FORMAT : sName = "LevelFormat"; break; + case PROP_LIST_FORMAT : sName = "ListFormat"; break; + case PROP_TOKEN_TYPE : sName = "TokenType"; break; + case PROP_TOKEN_HYPERLINK_START : sName = "TokenHyperlinkStart"; break; + case PROP_TOKEN_HYPERLINK_END : sName = "TokenHyperlinkEnd"; break; + case PROP_TOKEN_CHAPTER_INFO : sName = "TokenChapterInfo"; break; + case PROP_CHAPTER_FORMAT : sName = "ChapterFormat"; break; + case PROP_TOKEN_TEXT : sName = "TokenText"; break; + case PROP_TEXT : sName = "Text"; break; + case PROP_CREATE_FROM_OUTLINE : sName = "CreateFromOutline"; break; + case PROP_CREATE_FROM_MARKS : sName = "CreateFromMarks"; break; + case PROP_STANDARD : sName = "Standard"; break; + case PROP_SPLIT : sName = "Split"; break; + case PROP_IS_SPLIT_ALLOWED : sName = "IsSplitAllowed"; break; + case META_PROP_VERTICAL_BORDER : sName = "VerticalBorder"; break; + case META_PROP_HORIZONTAL_BORDER : sName = "HorizontalBorder"; break; + case PROP_HEADER_ROW_COUNT : sName = "HeaderRowCount"; break; + case PROP_SIZE_TYPE : sName = "SizeType"; break; + case PROP_TABLE_COLUMN_SEPARATORS: sName = "TableColumnSeparators"; break; + case META_PROP_TABLE_STYLE_NAME : sName = "TableStyleName"; break; + case PROP_TABLE_REDLINE_PARAMS : sName = "TableRedlineParams"; break; + case PROP_REDLINE_AUTHOR : sName = "RedlineAuthor"; break; + case PROP_REDLINE_DATE_TIME : sName = "RedlineDateTime"; break; + case PROP_REDLINE_TYPE : sName = "RedlineType"; break; + case PROP_REDLINE_REVERT_PROPERTIES: sName = "RedlineRevertProperties"; break; + case PROP_IS_PROTECTED : sName = "IsProtected"; break; + case PROP_SIZE_PROTECTED : sName = "SizeProtected"; break; + case PROP_POSITION_PROTECTED : sName = "PositionProtected"; break; + case PROP_OPAQUE : sName = "Opaque"; break; + case PROP_VERTICAL_MERGE : sName = "VerticalMerge"; break; + case PROP_BULLET_CHAR : sName = "BulletChar"; break; + case PROP_BULLET_FONT_NAME : sName = "BulletFontName"; break; + case PROP_TABS_RELATIVE_TO_INDENT: sName = "TabsRelativeToIndent"; break; + case PROP_PREFIX : sName = "Prefix"; break; + case PROP_SUFFIX : sName = "Suffix"; break; + case PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES: sName = "CreateFromLevelParagraphStyles"; break; + case PROP_DROP_CAP_FORMAT : sName = "DropCapFormat"; break; + case PROP_REFERENCE_FIELD_PART : sName = "ReferenceFieldPart"; break; + case PROP_SOURCE_NAME: sName = "SourceName"; break; + case PROP_REFERENCE_FIELD_SOURCE : sName = "ReferenceFieldSource"; break; + case PROP_WIDTH_TYPE : sName = "WidthType"; break; + case PROP_TBL_LOOK : sName = "TblLook"; break; + case PROP_TEXT_RANGE: sName = "TextRange"; break; + case PROP_TEXT_VERTICAL_ADJUST : sName = "TextVerticalAdjust"; break; + case PROP_SERVICE_CHAR_STYLE : sName = "com.sun.star.style.CharacterStyle"; break; + case PROP_SERVICE_PARA_STYLE : sName = "com.sun.star.style.ParagraphStyle"; break; + case PROP_CHARACTER_STYLES : sName = "CharacterStyles"; break; + case PROP_PARAGRAPH_STYLES : sName = "ParagraphStyles"; break; + case PROP_TABLE_BORDER_DISTANCES: sName = "TableBorderDistances"; break; + case META_PROP_CELL_MAR_TOP : sName = "MetaPropCellMarTop"; break; + case META_PROP_CELL_MAR_BOTTOM : sName = "MetaPropCellMarBottom"; break; + case META_PROP_CELL_MAR_LEFT : sName = "MetaPropCellMarLeft"; break; + case META_PROP_CELL_MAR_RIGHT : sName = "MetaPropCellMarRight"; break; + case PROP_START_AT : sName = "StartAt"; break; + case PROP_CHAR_PROP_HEIGHT : sName = "CharPropHeight"; break; + case PROP_CHAR_PROP_HEIGHT_ASIAN : sName = "CharPropHeightAsian"; break; + case PROP_CHAR_PROP_HEIGHT_COMPLEX: sName = "CharPropHeightComplex"; break; + case PROP_FORMAT : sName = "Format"; break; + case PROP_INSERT : sName = "Insert"; break; + case PROP_DELETE : sName = "Delete"; break; + case PROP_PARAGRAPH_FORMAT : sName = "ParagraphFormat"; break; + case PROP_STREAM_NAME: sName = "StreamName"; break; + case PROP_BITMAP : sName = "Bitmap"; break; + case PROP_IS_DATE : sName = "IsDate"; break; + case PROP_TAB_STOP_DISTANCE : sName = "TabStopDistance"; break; + case PROP_INDENT_AT : sName = "IndentAt"; break; + case PROP_FIRST_LINE_INDENT : sName = "FirstLineIndent"; break; + case PROP_NUMBERING_STYLE_NAME : sName = "NumberingStyleName"; break; + case PROP_OUTLINE_LEVEL : sName = "OutlineLevel"; break; + case PROP_LISTTAB_STOP_POSITION : sName = "ListtabStopPosition"; break; + case PROP_POSITION_AND_SPACE_MODE : sName = "PositionAndSpaceMode"; break; + case PROP_PARA_SPLIT: sName = "ParaSplit"; break; + case PROP_HELP: sName = "Help"; break; + case PROP_HEADING_STYLE_NAME: sName = "HeadingStyleName"; break; + case PROP_FRM_DIRECTION: sName = "FRMDirection"; break; + case PROP_EMBEDDED_OBJECT : sName = "EmbeddedObject"; break; + case PROP_IS_VISIBLE: sName = "IsVisible"; break; + case PROP_PAGE_STYLE_LAYOUT: sName = "PageStyleLayout"; break; + case PROP_Z_ORDER: sName = "ZOrder"; break; + case PROP_EMBED_FONTS: sName = "EmbedFonts"; break; + case PROP_EMBED_SYSTEM_FONTS: sName = "EmbedSystemFonts"; break; + case PROP_SHADOW_FORMAT: sName = "ShadowFormat"; break; + case PROP_RELATIVE_WIDTH: sName = "RelativeWidth"; break; + case PROP_IS_WIDTH_RELATIVE: sName = "IsWidthRelative"; break; + case PROP_GRAPHIC_BITMAP: sName = "GraphicBitmap"; break; + case PROP_GRAPHIC_SIZE: sName = "GraphicSize"; break; + case PROP_CHAR_SHADING_VALUE: sName = "CharShadingValue"; break; + case PROP_CHAR_SHADING_MARKER: sName = "CharShadingMarker"; break; + case PROP_LABEL_CATEGORY: sName = "LabelCategory"; break; + case PROP_MIRROR_INDENTS : sName = "MirrorIndents"; break; + case PROP_SURROUND_TEXT_WRAP_SMALL: sName = "SurroundTextWrapSmall"; break; + case PROP_PARA_SHADOW_FORMAT: sName = "ParaShadowFormat"; break; + case PROP_FOOTNOTE_LINE_RELATIVE_WIDTH: sName = "FootnoteLineRelativeWidth"; break; + case PROP_TBL_HEADER: sName = "TblHeader"; break; + case PROP_CHAR_THEME_NAME_ASCII : sName = "CharThemeNameAscii"; break; + case PROP_CHAR_THEME_NAME_CS : sName = "CharThemeNameCs"; break; + case PROP_CHAR_THEME_NAME_H_ANSI : sName = "CharThemeNameHAnsi"; break; + case PROP_CHAR_THEME_NAME_EAST_ASIA : sName = "CharThemeNameEastAsia"; break; + case PROP_CHAR_THEME_FONT_NAME_ASCII : sName = "CharThemeFontNameAscii"; break; + case PROP_CHAR_THEME_FONT_NAME_CS : sName = "CharThemeFontNameCs"; break; + case PROP_CHAR_THEME_FONT_NAME_EAST_ASIA: sName = "CharThemeFontNameEastAsia"; break; + case PROP_CHAR_THEME_COLOR : sName = "CharThemeColor"; break; + case PROP_CHAR_THEME_ORIGINAL_COLOR : sName = "CharThemeOriginalColor"; break; + case PROP_CHAR_THEME_COLOR_SHADE : sName = "CharThemeColorShade"; break; + case PROP_CHAR_THEME_FILL : sName = "CharThemeFill"; break; + case PROP_HORIZONTAL_MERGE: sName = "HorizontalMerge"; break; + case PROP_HIDE_TAB_LEADER_AND_PAGE_NUMBERS : sName = "HideTabLeaderAndPageNumber" ; break ; + case PROP_TAB_IN_TOC : sName = "TabInTOC"; break ; + case PROP_TOC_BOOKMARK: sName = "TOCBookmark"; break; + case PROP_TOC_NEW_LINE: sName = "TOCNewLine"; break; + case PROP_TOC_PARAGRAPH_OUTLINE_LEVEL : sName = "TOCParagraphOutlineLevel"; break; + case PROP_CHAR_THEME_COLOR_TINT : sName = "CharThemeColorTint"; break; + case PROP_CHAR_GLOW_TEXT_EFFECT : sName = "CharGlowTextEffect"; break; + case PROP_CHAR_SHADOW_TEXT_EFFECT : sName = "CharShadowTextEffect"; break; + case PROP_CHAR_REFLECTION_TEXT_EFFECT : sName = "CharReflectionTextEffect"; break; + case PROP_CHAR_TEXTOUTLINE_TEXT_EFFECT : sName = "CharTextOutlineTextEffect"; break; + case PROP_CHAR_TEXTFILL_TEXT_EFFECT : sName = "CharTextFillTextEffect"; break; + case PROP_CHAR_SCENE3D_TEXT_EFFECT : sName = "CharScene3DTextEffect"; break; + case PROP_CHAR_PROPS3D_TEXT_EFFECT : sName = "CharProps3DTextEffect"; break; + case PROP_CHAR_LIGATURES_TEXT_EFFECT : sName = "CharLigaturesTextEffect"; break; + case PROP_CHAR_NUMFORM_TEXT_EFFECT : sName = "CharNumFormTextEffect"; break; + case PROP_CHAR_NUMSPACING_TEXT_EFFECT : sName = "CharNumSpacingTextEffect"; break; + case PROP_CHAR_STYLISTICSETS_TEXT_EFFECT : sName = "CharStylisticSetsTextEffect"; break; + case PROP_CHAR_CNTXTALTS_TEXT_EFFECT : sName = "CharCntxtAltsTextEffect"; break; + case PROP_SDTPR : sName = "SdtPr"; break; + case PROP_INDEX_ENTRY_TYPE : sName = "IndexEntryType"; break; + case PROP_CELL_INTEROP_GRAB_BAG : sName = "CellInteropGrabBag"; break; + case PROP_TABLE_INTEROP_GRAB_BAG : sName = "TableInteropGrabBag"; break; + case PROP_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING : sName = "ApplyParagraphMarkFormatToNumbering"; break; + case PROP_SDT_END_BEFORE: sName = "SdtEndBefore"; break; + case PROP_PARA_SDT_END_BEFORE: sName = "ParaSdtEndBefore"; break; + case META_PROP_TABLE_LOOK: sName = "TableStyleLook"; break; + case PROP_PARA_CNF_STYLE: sName = "ParaCnfStyle"; break; + case PROP_CELL_CNF_STYLE: sName = "CellCnfStyle"; break; + case PROP_ROW_CNF_STYLE: sName = "RowCnfStyle"; break; + case PROP_CELL_HIDE_MARK: sName = "CellHideMark"; break; + case PROP_FOLLOW_TEXT_FLOW: sName = "IsFollowingTextFlow"; break; + case PROP_FILL_STYLE: sName = "FillStyle"; break; + case PROP_FILL_COLOR: sName = "FillColor"; break; + case PROP_SNAP_TO_GRID: sName = "SnapToGrid"; break; + case PROP_GRID_SNAP_TO_CHARS: sName = "GridSnapToChars"; break; + case PROP_RUBY_STYLE: sName = "RubyCharStyleName"; break; + case PROP_RUBY_TEXT: sName = "RubyText"; break; + case PROP_RUBY_ADJUST: sName = "RubyAdjust"; break; + case PROP_RUBY_POSITION: sName = "RubyPosition"; break; + case PROP_DATABASE_NAME: sName = "DataBaseName"; break; + case PROP_COMMAND_TYPE: sName = "DataCommandType"; break; + case PROP_DATATABLE_NAME: sName = "DataTableName"; break; + case PROP_DATACOLUMN_NAME: sName = "DataColumnName"; break; + case PROP_CHAR_TRANSPARENCE: sName = "CharTransparence"; break; + case PROP_CELL_FORMULA: sName = "CellFormula"; break; + case PROP_CELL_FORMULA_CONVERTED: sName = "CellFormulaConverted"; break; + } + assert(sName.getLength()>0); + return sName; +} + +bool isCharacterProperty( const PropertyIds eId ) +{ + return eId > PROP_CHARACTER_STYLES && eId < PROP_CHARACTER_END; +} + +bool isParagraphProperty( const PropertyIds eId ) +{ + return (eId >= PROP_PARA_ADJUST && eId <= PROP_PARA_WIDOWS) || eId == PROP_FILL_COLOR; +} + +} //namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx new file mode 100644 index 000000000..aa95e5383 --- /dev/null +++ b/writerfilter/source/dmapper/PropertyIds.hxx @@ -0,0 +1,376 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYIDS_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYIDS_HXX + +#include + +namespace writerfilter { +namespace dmapper{ +// Ensure that Character Properties are placed between PROP_CHARACTER_STYLES and PROP_CHARACTER_END +enum PropertyIds + { + PROP_ID_START = 1 + ,META_PROP_CELL_MAR_BOTTOM = PROP_ID_START + ,META_PROP_CELL_MAR_LEFT + ,META_PROP_CELL_MAR_RIGHT + ,META_PROP_CELL_MAR_TOP + ,META_PROP_HORIZONTAL_BORDER + ,META_PROP_TABLE_STYLE_NAME + ,META_PROP_VERTICAL_BORDER + ,PROP_ADJUST + ,PROP_ADJUST_CONTRAST + ,PROP_ADJUST_LUMINANCE + ,PROP_ALTERNATIVE_TEXT + ,PROP_ANCHOR_TYPE + ,PROP_AUTOMATIC_DISTANCE + ,PROP_BACK_COLOR + ,PROP_BACK_COLOR_TRANSPARENCY + ,PROP_BITMAP + ,PROP_BOTTOM_BORDER + ,PROP_BOTTOM_BORDER_DISTANCE + ,PROP_BOTTOM_MARGIN + ,PROP_BREAK_TYPE + ,PROP_BULLET_CHAR + ,PROP_BULLET_FONT_NAME + ,PROP_CHAPTER_FORMAT + ,PROP_CHARACTER_STYLES + ,PROP_CHAR_AUTO_KERNING + ,PROP_CHAR_BACK_COLOR + ,PROP_CHAR_CASE_MAP + ,PROP_CHAR_CHAR_KERNING + ,PROP_CHAR_COLOR + ,PROP_CHAR_COMBINE_IS_ON + ,PROP_CHAR_COMBINE_PREFIX + ,PROP_CHAR_COMBINE_SUFFIX + ,PROP_CHAR_CONTOURED + ,PROP_CHAR_LEFT_BORDER + ,PROP_CHAR_RIGHT_BORDER + ,PROP_CHAR_TOP_BORDER + ,PROP_CHAR_BOTTOM_BORDER + ,PROP_CHAR_LEFT_BORDER_DISTANCE + ,PROP_CHAR_RIGHT_BORDER_DISTANCE + ,PROP_CHAR_TOP_BORDER_DISTANCE + ,PROP_CHAR_BOTTOM_BORDER_DISTANCE + ,PROP_CHAR_EMPHASIS + ,PROP_CHAR_ESCAPEMENT + ,PROP_CHAR_ESCAPEMENT_HEIGHT + ,PROP_CHAR_FLASH + ,PROP_CHAR_FONT_CHAR_SET + ,PROP_CHAR_FONT_NAME + ,PROP_CHAR_FONT_NAME_ASIAN + ,PROP_CHAR_FONT_NAME_COMPLEX + ,PROP_CHAR_HEIGHT + ,PROP_CHAR_HEIGHT_ASIAN + ,PROP_CHAR_HEIGHT_COMPLEX + ,PROP_CHAR_HIDDEN + ,PROP_CHAR_HIGHLIGHT + ,PROP_CHAR_LOCALE + ,PROP_CHAR_LOCALE_ASIAN + ,PROP_CHAR_LOCALE_COMPLEX + ,PROP_CHAR_POSTURE + ,PROP_CHAR_POSTURE_ASIAN + ,PROP_CHAR_POSTURE_COMPLEX + ,PROP_CHAR_PROP_HEIGHT + ,PROP_CHAR_PROP_HEIGHT_ASIAN + ,PROP_CHAR_PROP_HEIGHT_COMPLEX + ,PROP_CHAR_RELIEF + ,PROP_CHAR_ROTATION + ,PROP_CHAR_ROTATION_IS_FIT_TO_LINE + ,PROP_CHAR_SCALE_WIDTH + ,PROP_CHAR_SHADOW_FORMAT + ,PROP_CHAR_SHADING_MARKER + ,PROP_CHAR_SHADING_VALUE + ,PROP_CHAR_SHADOWED + ,PROP_CHAR_STRIKEOUT + ,PROP_CHAR_STYLE_NAME + ,PROP_CHAR_TEXTOUTLINE_TEXT_EFFECT + ,PROP_CHAR_TEXTFILL_TEXT_EFFECT + ,PROP_CHAR_THEME_NAME_ASCII + ,PROP_CHAR_THEME_NAME_CS + ,PROP_CHAR_THEME_NAME_H_ANSI + ,PROP_CHAR_THEME_NAME_EAST_ASIA + ,PROP_CHAR_THEME_FONT_NAME_ASCII + ,PROP_CHAR_THEME_FONT_NAME_CS + ,PROP_CHAR_THEME_FONT_NAME_EAST_ASIA + ,PROP_CHAR_THEME_COLOR + ,PROP_CHAR_THEME_ORIGINAL_COLOR + ,PROP_CHAR_THEME_COLOR_SHADE + ,PROP_CHAR_THEME_FILL + ,PROP_CHAR_THEME_COLOR_TINT + ,PROP_CHAR_UNDERLINE + ,PROP_CHAR_UNDERLINE_COLOR + ,PROP_CHAR_UNDERLINE_HAS_COLOR + ,PROP_CHAR_WEIGHT + ,PROP_CHAR_WEIGHT_ASIAN + ,PROP_CHAR_WEIGHT_COMPLEX + ,PROP_CHAR_WORD_MODE + ,PROP_CHAR_GLOW_TEXT_EFFECT + ,PROP_CHAR_SHADOW_TEXT_EFFECT + ,PROP_CHAR_REFLECTION_TEXT_EFFECT + ,PROP_CHAR_SCENE3D_TEXT_EFFECT + ,PROP_CHAR_PROPS3D_TEXT_EFFECT + ,PROP_CHAR_LIGATURES_TEXT_EFFECT + ,PROP_CHAR_NUMFORM_TEXT_EFFECT + ,PROP_CHAR_NUMSPACING_TEXT_EFFECT + ,PROP_CHAR_STYLISTICSETS_TEXT_EFFECT + ,PROP_CHAR_CNTXTALTS_TEXT_EFFECT + ,PROP_CHARACTER_END + ,PROP_CONTENT = PROP_CHARACTER_END + ,PROP_CONTOUR_OUTSIDE + ,PROP_CONTOUR_POLY_POLYGON + ,PROP_COUNT_EMPTY_LINES + ,PROP_COUNT_LINES_IN_FRAMES + ,PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES + ,PROP_CREATE_FROM_MARKS + ,PROP_CREATE_FROM_OUTLINE + ,PROP_CURRENT_PRESENTATION + ,PROP_DELETE + ,PROP_DESCRIPTION + ,PROP_DISTANCE + ,PROP_DROP_CAP_FORMAT + ,PROP_FILE_FORMAT + ,PROP_FIRST_LINE_INDENT + ,PROP_FIRST_LINE_OFFSET + ,PROP_FIRST_PAGE + ,PROP_FOOTER_BODY_DISTANCE + ,PROP_FOOTER_DYNAMIC_SPACING + ,PROP_FOOTER_HEIGHT + ,PROP_FOOTER_IS_DYNAMIC_HEIGHT + ,PROP_FOOTER_IS_ON + ,PROP_FOOTER_IS_SHARED + ,PROP_FOOTER_TEXT + ,PROP_FOOTER_TEXT_LEFT + ,PROP_FOOTNOTE_COUNTING + ,PROP_FOOTNOTE_LINE_ADJUST + ,PROP_FORMAT + ,PROP_FULL_NAME + ,PROP_GRAPHIC + ,PROP_GRAPHIC_COLOR_MODE + ,PROP_GRID_BASE_HEIGHT + ,PROP_GRID_BASE_WIDTH + ,PROP_GRID_DISPLAY + ,PROP_GRID_LINES + ,PROP_GRID_MODE + ,PROP_GRID_PRINT + ,PROP_GRID_RUBY_HEIGHT + ,PROP_HEADER_BODY_DISTANCE + ,PROP_HEADER_DYNAMIC_SPACING + ,PROP_HEADER_HEIGHT + ,PROP_HEADER_IS_DYNAMIC_HEIGHT + ,PROP_HEADER_IS_ON + ,PROP_HEADER_IS_SHARED + ,PROP_HEADER_ROW_COUNT + ,PROP_HEADER_TEXT + ,PROP_HEADER_TEXT_LEFT + ,PROP_HEADING_STYLE_NAME + ,PROP_HEIGHT + ,PROP_HELP + ,PROP_HINT + ,PROP_HORI_ORIENT + ,PROP_HORI_ORIENT_POSITION + ,PROP_HORI_ORIENT_RELATION + ,PROP_HYPER_LINK_U_R_L + ,PROP_INDENT_AT + ,PROP_INPUT_STREAM + ,PROP_INSERT + ,PROP_INTERVAL + ,PROP_IS_DATE + ,PROP_IS_FIXED + ,PROP_IS_INPUT + ,PROP_IS_LANDSCAPE + ,PROP_IS_ON + ,PROP_IS_SPLIT_ALLOWED + ,PROP_IS_VISIBLE + ,PROP_LABEL_CATEGORY + ,PROP_LEFT_BORDER + ,PROP_LEFT_BORDER_DISTANCE + ,PROP_LEFT_MARGIN + ,PROP_LEVEL + ,PROP_LEVEL_FOLLOW + ,PROP_LEVEL_FORMAT + ,PROP_LEVEL_PARAGRAPH_STYLES + ,PROP_LISTTAB_STOP_POSITION + ,PROP_LIST_FORMAT + ,PROP_MACRO_NAME + ,PROP_NAME + ,PROP_NUMBERING_LEVEL + ,PROP_NUMBERING_RULES + ,PROP_NUMBERING_STYLE_NAME + ,PROP_NUMBERING_TYPE + ,PROP_NUMBER_FORMAT + ,PROP_NUMBER_POSITION + ,PROP_OPAQUE + ,PROP_OUTLINE_LEVEL + ,PROP_PAGE_DESC_NAME + ,PROP_PAGE_NUMBER_OFFSET + ,PROP_PAGE_TOGGLE + ,PROP_PARAGRAPH_FORMAT + ,PROP_PARAGRAPH_STYLES + ,PROP_PARA_ADJUST + ,PROP_PARA_BOTTOM_MARGIN + ,PROP_PARA_FIRST_LINE_INDENT + ,PROP_PARA_IS_HANGING_PUNCTUATION + ,PROP_PARA_IS_HYPHENATION + ,PROP_PARA_HYPHENATION_NO_CAPS + ,PROP_PARA_KEEP_TOGETHER + ,PROP_PARA_LAST_LINE_ADJUST + ,PROP_PARA_LEFT_MARGIN + ,PROP_PARA_LINE_NUMBER_COUNT + ,PROP_PARA_LINE_NUMBER_START_VALUE + ,PROP_PARA_LINE_SPACING + ,PROP_PARA_ORPHANS + ,PROP_PARA_RIGHT_MARGIN + ,PROP_PARA_SPLIT + ,PROP_PARA_STYLE_NAME + ,PROP_PARA_TAB_STOPS + ,PROP_PARA_TOP_MARGIN + ,PROP_PARA_VERT_ALIGNMENT + ,PROP_PARA_WIDOWS + ,PROP_PARENT_NUMBERING + ,PROP_POSITION_AND_SPACE_MODE + ,PROP_POSITION_PROTECTED + ,PROP_IS_PROTECTED + ,PROP_PREFIX + ,PROP_REDLINE_AUTHOR + ,PROP_REDLINE_DATE_TIME + ,PROP_REDLINE_TYPE + ,PROP_REDLINE_REVERT_PROPERTIES + ,PROP_REFERENCE_FIELD_PART + ,PROP_REFERENCE_FIELD_SOURCE + ,PROP_RESTART_AT_EACH_PAGE + ,PROP_RIGHT_BORDER + ,PROP_RIGHT_BORDER_DISTANCE + ,PROP_RIGHT_MARGIN + ,PROP_SERVICE_CHAR_STYLE + ,PROP_SERVICE_PARA_STYLE + ,PROP_SIZE + ,PROP_SIZE100th_M_M + ,PROP_SIZE_PIXEL + ,PROP_SIZE_PROTECTED + ,PROP_SIZE_TYPE + ,PROP_SOURCE_NAME + ,PROP_SPLIT + ,PROP_STANDARD + ,PROP_START_AT + ,PROP_START_WITH + ,PROP_STREAM_NAME + ,PROP_SUB_TYPE + ,PROP_SUFFIX + ,PROP_SURROUND + ,PROP_SURROUND_CONTOUR + ,PROP_TABLE_BORDER + ,PROP_TABLE_BORDER_DISTANCES + ,PROP_TABLE_COLUMN_SEPARATORS + ,PROP_TABLE_REDLINE_PARAMS + ,PROP_TABLE_ROW_DELETE + ,PROP_TABLE_ROW_INSERT + ,PROP_TABLE_CELL_DELETE + ,PROP_TABLE_CELL_INSERT + ,PROP_TABS_RELATIVE_TO_INDENT + ,PROP_TAB_STOP_DISTANCE + ,PROP_TEXT + ,PROP_TEXT_COLUMNS + ,PROP_TEXT_RANGE + ,PROP_TEXT_VERTICAL_ADJUST + ,PROP_TITLE + ,PROP_TOKEN_CHAPTER_INFO + ,PROP_TOKEN_HYPERLINK_END + ,PROP_TOKEN_HYPERLINK_START + ,PROP_TOKEN_TEXT + ,PROP_TOKEN_TYPE + ,PROP_TOP_BORDER + ,PROP_TOP_BORDER_DISTANCE + ,PROP_TOP_MARGIN + ,PROP_VERTICAL_MERGE + ,PROP_GRID_STANDARD_MODE + ,PROP_VERT_ORIENT + ,PROP_VERT_ORIENT_POSITION + ,PROP_VERT_ORIENT_RELATION + ,PROP_WIDTH + ,PROP_WIDTH_TYPE + ,PROP_TBL_LOOK + ,PROP_WRITING_MODE + ,PROP_FRM_DIRECTION + ,PROP_EMBEDDED_OBJECT + ,PROP_PARA_CONTEXT_MARGIN + ,PROP_PAGE_STYLE_LAYOUT + ,PROP_Z_ORDER + ,PROP_EMBED_FONTS + ,PROP_EMBED_SYSTEM_FONTS + ,PROP_SHADOW_FORMAT + ,PROP_RELATIVE_WIDTH + ,PROP_IS_WIDTH_RELATIVE + ,PROP_GRAPHIC_BITMAP + ,PROP_GRAPHIC_SIZE + ,PROP_MIRROR_INDENTS + ,PROP_SURROUND_TEXT_WRAP_SMALL + ,PROP_PARA_SHADOW_FORMAT + ,PROP_FOOTNOTE_LINE_RELATIVE_WIDTH + ,PROP_PARA_TOP_MARGIN_BEFORE_AUTO_SPACING + ,PROP_PARA_BOTTOM_MARGIN_AFTER_AUTO_SPACING + ,PROP_TBL_HEADER + ,PROP_HORIZONTAL_MERGE + ,PROP_HIDE_TAB_LEADER_AND_PAGE_NUMBERS + ,PROP_TAB_IN_TOC + ,PROP_TOC_BOOKMARK + ,PROP_TOC_NEW_LINE + ,PROP_TOC_PARAGRAPH_OUTLINE_LEVEL + ,PROP_SDTPR + ,PROP_CELL_INTEROP_GRAB_BAG + ,PROP_TABLE_INTEROP_GRAB_BAG + ,PROP_INDEX_ENTRY_TYPE + ,PROP_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING + ,PROP_SDT_END_BEFORE + ,PROP_PARA_SDT_END_BEFORE + ,META_PROP_TABLE_LOOK + ,PROP_PARA_CNF_STYLE + ,PROP_CELL_CNF_STYLE + ,PROP_ROW_CNF_STYLE + ,PROP_CELL_HIDE_MARK + ,PROP_FOLLOW_TEXT_FLOW + ,PROP_FILL_STYLE + ,PROP_FILL_COLOR + ,PROP_SNAP_TO_GRID + ,PROP_GRID_SNAP_TO_CHARS + ,PROP_RUBY_STYLE + ,PROP_RUBY_TEXT + ,PROP_RUBY_ADJUST + ,PROP_RUBY_POSITION + ,PROP_DATABASE_NAME + ,PROP_COMMAND_TYPE + ,PROP_DATATABLE_NAME + ,PROP_DATACOLUMN_NAME + ,PROP_CHAR_TRANSPARENCE + ,PROP_CELL_FORMULA + ,PROP_CELL_FORMULA_CONVERTED + }; + +//Returns the UNO string equivalent to eId. +OUString getPropertyName(PropertyIds eId); + +bool isCharacterProperty(const PropertyIds eId); + +bool isParagraphProperty(const PropertyIds eId); + +} //namespace dmapper +} // namespace writerfilter +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx new file mode 100644 index 000000000..d510bfc8b --- /dev/null +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -0,0 +1,2039 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "PropertyMap.hxx" +#include "TagLogger.hxx" +#include +#include "DomainMapper_Impl.hxx" +#include "ConversionHelper.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "PropertyMapHelper.hxx" +#include + +using namespace com::sun::star; + +namespace writerfilter::dmapper { + +uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues( bool bCharGrabBag ) +{ + using comphelper::makePropertyValue; + + if ( m_aValues.empty() && !m_vMap.empty() ) + { + size_t nCharGrabBag = 0; + size_t nParaGrabBag = 0; + size_t nCellGrabBag = 0; + size_t nRowGrabBag = 0; + + const PropValue* pParaStyleProp = nullptr; + const PropValue* pCharStyleProp = nullptr; + const PropValue* pNumRuleProp = nullptr; + + for ( const auto& rPropPair : m_vMap ) + { + if ( rPropPair.second.getGrabBagType() == CHAR_GRAB_BAG ) + nCharGrabBag++; + else if ( rPropPair.second.getGrabBagType() == PARA_GRAB_BAG ) + nParaGrabBag++; + else if ( rPropPair.second.getGrabBagType() == CELL_GRAB_BAG ) + nCellGrabBag++; + else if ( rPropPair.first == PROP_CELL_INTEROP_GRAB_BAG ) + { + uno::Sequence< beans::PropertyValue > aSeq; + rPropPair.second.getValue() >>= aSeq; + nCellGrabBag += aSeq.getLength(); + } + else if ( rPropPair.second.getGrabBagType() == ROW_GRAB_BAG ) + nRowGrabBag++; + + if ( rPropPair.first == PROP_PARA_STYLE_NAME ) pParaStyleProp = &rPropPair.second; + if ( rPropPair.first == PROP_CHAR_STYLE_NAME ) pCharStyleProp = &rPropPair.second; + if ( rPropPair.first == PROP_NUMBERING_RULES ) pNumRuleProp = &rPropPair.second; + } + + // Style names have to be the first elements within the property sequence + // otherwise they will overwrite 'hard' attributes + if ( pParaStyleProp != nullptr ) + m_aValues.push_back( makePropertyValue( getPropertyName( PROP_PARA_STYLE_NAME ), pParaStyleProp->getValue() ) ); + if ( pCharStyleProp != nullptr ) + m_aValues.push_back( makePropertyValue( getPropertyName( PROP_CHAR_STYLE_NAME ), pCharStyleProp->getValue() ) ); + if ( pNumRuleProp != nullptr ) + m_aValues.push_back( makePropertyValue(getPropertyName( PROP_NUMBERING_RULES ), pNumRuleProp->getValue() ) ); + + // If there are any grab bag properties, we need one slot for them. + uno::Sequence< beans::PropertyValue > aCharGrabBagValues( nCharGrabBag ); + uno::Sequence< beans::PropertyValue > aParaGrabBagValues( nParaGrabBag ); + uno::Sequence< beans::PropertyValue > aCellGrabBagValues( nCellGrabBag ); + uno::Sequence< beans::PropertyValue > aRowGrabBagValues ( nRowGrabBag ); + beans::PropertyValue* pCharGrabBagValues = aCharGrabBagValues.getArray(); + beans::PropertyValue* pParaGrabBagValues = aParaGrabBagValues.getArray(); + beans::PropertyValue* pCellGrabBagValues = aCellGrabBagValues.getArray(); + beans::PropertyValue* pRowGrabBagValues = aRowGrabBagValues.getArray(); + // Record index for the next property to be added in each grab bag. + sal_Int32 nRowGrabBagValue = 0; + sal_Int32 nCellGrabBagValue = 0; + sal_Int32 nParaGrabBagValue = 0; + sal_Int32 nCharGrabBagValue = 0; + + for ( const auto& rPropPair : m_vMap ) + { + if ( rPropPair.first != PROP_PARA_STYLE_NAME && + rPropPair.first != PROP_CHAR_STYLE_NAME && + rPropPair.first != PROP_NUMBERING_RULES ) + { + if ( rPropPair.second.getGrabBagType() == CHAR_GRAB_BAG ) + { + if ( bCharGrabBag ) + { + pCharGrabBagValues[nCharGrabBagValue].Name = getPropertyName( rPropPair.first ); + pCharGrabBagValues[nCharGrabBagValue].Value = rPropPair.second.getValue(); + ++nCharGrabBagValue; + } + } + else if ( rPropPair.second.getGrabBagType() == PARA_GRAB_BAG ) + { + pParaGrabBagValues[nParaGrabBagValue].Name = getPropertyName( rPropPair.first ); + pParaGrabBagValues[nParaGrabBagValue].Value = rPropPair.second.getValue(); + ++nParaGrabBagValue; + } + else if ( rPropPair.second.getGrabBagType() == CELL_GRAB_BAG ) + { + pCellGrabBagValues[nCellGrabBagValue].Name = getPropertyName( rPropPair.first ); + pCellGrabBagValues[nCellGrabBagValue].Value = rPropPair.second.getValue(); + ++nCellGrabBagValue; + } + else if ( rPropPair.second.getGrabBagType() == ROW_GRAB_BAG ) + { + pRowGrabBagValues[nRowGrabBagValue].Name = getPropertyName( rPropPair.first ); + pRowGrabBagValues[nRowGrabBagValue].Value = rPropPair.second.getValue(); + ++nRowGrabBagValue; + } + else if ( rPropPair.first == PROP_CELL_INTEROP_GRAB_BAG ) + { + uno::Sequence< beans::PropertyValue > aSeq; + rPropPair.second.getValue() >>= aSeq; + std::copy(aSeq.begin(), aSeq.end(), pCellGrabBagValues + nCellGrabBagValue); + nCellGrabBagValue += aSeq.getLength(); + } + else + { + m_aValues.push_back( makePropertyValue( getPropertyName( rPropPair.first ), rPropPair.second.getValue() ) ); + } + } + } + + if ( nCharGrabBag && bCharGrabBag ) + m_aValues.push_back( makePropertyValue( "CharInteropGrabBag", uno::makeAny( aCharGrabBagValues ) ) ); + + if ( nParaGrabBag ) + m_aValues.push_back( makePropertyValue( "ParaInteropGrabBag", uno::makeAny( aParaGrabBagValues ) ) ); + + if ( nCellGrabBag ) + m_aValues.push_back( makePropertyValue( "CellInteropGrabBag", uno::makeAny( aCellGrabBagValues ) ) ); + + if ( nRowGrabBag ) + m_aValues.push_back( makePropertyValue( "RowInteropGrabBag", uno::makeAny( aRowGrabBagValues ) ) ); + } + + return comphelper::containerToSequence( m_aValues ); +} + +std::vector< PropertyIds > PropertyMap::GetPropertyIds() +{ + std::vector< PropertyIds > aRet; + for ( const auto& rPropPair : m_vMap ) + aRet.push_back( rPropPair.first ); + return aRet; +} + +#ifdef DBG_UTIL +static void lcl_AnyToTag( const uno::Any& rAny ) +{ + try { + sal_Int32 aInt = 0; + if ( rAny >>= aInt ) + { + TagLogger::getInstance().attribute( "value", rAny ); + } + else + { + TagLogger::getInstance().attribute( "unsignedValue", 0 ); + } + + sal_uInt32 auInt = 0; + rAny >>= auInt; + TagLogger::getInstance().attribute( "unsignedValue", auInt ); + + float aFloat = 0.0f; + if ( rAny >>= aFloat ) + { + TagLogger::getInstance().attribute( "floatValue", rAny ); + } + else + { + TagLogger::getInstance().attribute( "unsignedValue", 0 ); + } + + OUString aStr; + rAny >>= aStr; + TagLogger::getInstance().attribute( "stringValue", aStr ); + } + catch ( ... ) + { + } +} +#endif + +void PropertyMap::Insert( PropertyIds eId, const uno::Any& rAny, bool bOverwrite, GrabBagType i_GrabBagType, bool bDocDefault ) +{ +#ifdef DBG_UTIL + const OUString& rInsert = getPropertyName(eId); + + TagLogger::getInstance().startElement("propertyMap.insert"); + TagLogger::getInstance().attribute("name", rInsert); + lcl_AnyToTag(rAny); + TagLogger::getInstance().endElement(); +#endif + + if ( !bOverwrite ) + m_vMap.insert(std::make_pair(eId, PropValue(rAny, i_GrabBagType, bDocDefault))); + else + m_vMap[eId] = PropValue(rAny, i_GrabBagType); + + Invalidate(); +} + +void PropertyMap::Erase( PropertyIds eId ) +{ + // Safe call to erase, it throws no exceptions, even if eId is not in m_vMap + m_vMap.erase(eId); + + Invalidate(); +} + +std::optional< PropertyMap::Property > PropertyMap::getProperty( PropertyIds eId ) const +{ + std::map< PropertyIds, PropValue >::const_iterator aIter = m_vMap.find( eId ); + if ( aIter == m_vMap.end() ) + return std::optional(); + else + return std::make_pair( eId, aIter->second.getValue() ); +} + +bool PropertyMap::isSet( PropertyIds eId) const +{ + return m_vMap.find( eId ) != m_vMap.end(); +} + +bool PropertyMap::isDocDefault( PropertyIds eId ) const +{ + std::map< PropertyIds, PropValue >::const_iterator aIter = m_vMap.find( eId ); + if ( aIter == m_vMap.end() ) + return false; + else + return aIter->second.getIsDocDefault(); +} + +#ifdef DBG_UTIL +void PropertyMap::dumpXml() const +{ + TagLogger::getInstance().startElement( "PropertyMap" ); + + for ( const auto& rPropPair : m_vMap ) + { + TagLogger::getInstance().startElement( "property" ); + + TagLogger::getInstance().attribute( "name", getPropertyName( rPropPair.first ) ); + + switch ( rPropPair.first ) + { + case PROP_TABLE_COLUMN_SEPARATORS: + lcl_DumpTableColumnSeparators( rPropPair.second.getValue() ); + break; + default: + { + try + { + sal_Int32 aInt = 0; + rPropPair.second.getValue() >>= aInt; + TagLogger::getInstance().attribute( "value", aInt ); + + sal_uInt32 auInt = 0; + rPropPair.second.getValue() >>= auInt; + TagLogger::getInstance().attribute( "unsignedValue", auInt ); + + float aFloat = 0.0; + rPropPair.second.getValue() >>= aFloat; + TagLogger::getInstance().attribute( "floatValue", aFloat ); + + rPropPair.second.getValue() >>= auInt; + TagLogger::getInstance().attribute( "stringValue", OUString() ); + } + catch ( ... ) + { + } + } + break; + } + + TagLogger::getInstance().endElement(); + } + + TagLogger::getInstance().endElement(); +} +#endif + +void PropertyMap::InsertProps( const PropertyMapPtr& rMap, const bool bOverwrite ) +{ + if ( rMap ) + { + for ( const auto& rPropPair : rMap->m_vMap ) + { + if ( bOverwrite || !m_vMap.count(rPropPair.first) ) + { + if ( !bOverwrite && !rPropPair.second.getIsDocDefault() ) + m_vMap.insert(std::make_pair(rPropPair.first, PropValue(rPropPair.second.getValue(), rPropPair.second.getGrabBagType(), true))); + else + m_vMap[rPropPair.first] = rPropPair.second; + } + } + + insertTableProperties( rMap.get(), bOverwrite ); + + Invalidate(); + } +} + +void PropertyMap::insertTableProperties( const PropertyMap*, const bool ) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().element( "PropertyMap.insertTableProperties" ); +#endif +} + +void PropertyMap::printProperties() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement( "properties" ); + + for ( const auto& rPropPair : m_vMap ) + { + SAL_INFO( "writerfilter", getPropertyName( rPropPair.first ) ); + + table::BorderLine2 aLine; + sal_Int32 nColor; + if ( rPropPair.second.getValue() >>= aLine ) + { + TagLogger::getInstance().startElement( "borderline" ); + TagLogger::getInstance().attribute( "color", aLine.Color ); + TagLogger::getInstance().attribute( "inner", aLine.InnerLineWidth ); + TagLogger::getInstance().attribute( "outer", aLine.OuterLineWidth ); + TagLogger::getInstance().endElement(); + } + else if ( rPropPair.second.getValue() >>= nColor ) + { + TagLogger::getInstance().startElement( "color" ); + TagLogger::getInstance().attribute( "number", nColor ); + TagLogger::getInstance().endElement(); + } + } + + TagLogger::getInstance().endElement(); +#else + (void) this; // avoid loplugin:staticmethods +#endif +} + +SectionPropertyMap::SectionPropertyMap( bool bIsFirstSection ) + : m_bIsFirstSection( bIsFirstSection ) + , m_eBorderApply( BorderApply::ToAllInSection ) + , m_eBorderOffsetFrom( BorderOffsetFrom::Text ) + , m_bTitlePage( false ) + , m_nColumnCount( 0 ) + , m_nColumnDistance( 1249 ) + , m_bSeparatorLineIsOn( false ) + , m_bEvenlySpaced( false ) + , m_nPageNumber( -1 ) + , m_nPageNumberType( -1 ) + , m_nBreakType( -1 ) + , m_nLeftMargin( 2540 ) // page left margin, default 1 inch = 1440 twip -> 2540 1/100 mm + , m_nRightMargin( 2540 ) // page right margin, default 1 inch = 1440 twip -> 2540 1/100 mm + , m_nTopMargin( 2540 ) + , m_nBottomMargin( 2540 ) + , m_nHeaderTop( 1270 ) // 720 twip + , m_nHeaderBottom( 1270 ) // 720 twip + , m_nGridType( 0 ) + , m_nGridLinePitch( 1 ) + , m_nDxtCharSpace( 0 ) + , m_bGridSnapToChars( true ) + , m_nLnnMod( 0 ) + , m_nLnc(NS_ooxml::LN_Value_ST_LineNumberRestart_newPage) + , m_ndxaLnn( 0 ) + , m_nLnnMin( 0 ) + , m_bDefaultHeaderLinkToPrevious( true ) + , m_bEvenPageHeaderLinkToPrevious( true ) + , m_bFirstPageHeaderLinkToPrevious( true ) + , m_bDefaultFooterLinkToPrevious( true ) + , m_bEvenPageFooterLinkToPrevious( true ) + , m_bFirstPageFooterLinkToPrevious( true ) +{ +#ifdef DBG_UTIL + static sal_Int32 nNumber = 0; + m_nDebugSectionNumber = nNumber++; +#endif + + for ( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder ) + { + m_nBorderDistances[nBorder] = -1; + m_bBorderShadows[nBorder] = false; + } + // todo: set defaults in ApplyPropertiesToPageStyles + // initialize defaults + PaperInfo aLetter( PAPER_LETTER ); + // page height, 1/100mm + Insert( PROP_HEIGHT, uno::makeAny( static_cast(aLetter.getHeight()) ) ); + // page width, 1/100mm + Insert( PROP_WIDTH, uno::makeAny( static_cast(aLetter.getWidth()) ) ); + // page left margin, default 0x5a0 (1440) twip -> 2540 1/100 mm + Insert( PROP_LEFT_MARGIN, uno::makeAny( sal_Int32(2540) ) ); + // page right margin, default 0x5a0 (1440) twip -> 2540 1/100 mm + Insert( PROP_RIGHT_MARGIN, uno::makeAny( sal_Int32(2540) ) ); + // page top margin, default 0x5a0 (1440) twip -> 2540 1/100 mm + Insert( PROP_TOP_MARGIN, uno::makeAny( sal_Int32(2540) ) ); + // page bottom margin, default 0x5a0 (1440) twip -> 2540 1/100 mm + Insert( PROP_BOTTOM_MARGIN, uno::makeAny( sal_Int32(2540) ) ); + // page style layout + Insert( PROP_PAGE_STYLE_LAYOUT, uno::makeAny( style::PageStyleLayout_ALL ) ); + uno::Any aFalse( uno::makeAny( false ) ); + Insert( PROP_GRID_DISPLAY, aFalse ); + Insert( PROP_GRID_PRINT, aFalse ); + Insert( PROP_GRID_MODE, uno::makeAny( text::TextGridMode::NONE ) ); + + if ( m_bIsFirstSection ) + { + m_sFirstPageStyleName = getPropertyName( PROP_FIRST_PAGE ); + m_sFollowPageStyleName = getPropertyName( PROP_STANDARD ); + } +} + +uno::Reference< beans::XPropertySet > SectionPropertyMap::GetPageStyle( DomainMapper_Impl& rDM_Impl, + bool bFirst ) +{ + const uno::Reference< container::XNameContainer >& xPageStyles = rDM_Impl.GetPageStyles(); + const uno::Reference < lang::XMultiServiceFactory >& xTextFactory = rDM_Impl.GetTextFactory(); + uno::Reference< beans::XPropertySet > xRet; + try + { + if ( bFirst ) + { + if ( m_sFirstPageStyleName.isEmpty() && xPageStyles.is() ) + { + m_sFirstPageStyleName = rDM_Impl.GetUnusedPageStyleName(); + m_aFirstPageStyle.set( xTextFactory->createInstance( "com.sun.star.style.PageStyle" ), + uno::UNO_QUERY ); + + // Call insertByName() before GetPageStyle(), otherwise the + // first and the follow page style will have the same name, and + // insertByName() will fail. + if ( xPageStyles.is() ) + xPageStyles->insertByName( m_sFirstPageStyleName, uno::makeAny( m_aFirstPageStyle ) ); + + // Ensure that m_aFollowPageStyle has been created + GetPageStyle( rDM_Impl, false ); + // Chain m_aFollowPageStyle to be after m_aFirstPageStyle + m_aFirstPageStyle->setPropertyValue( "FollowStyle", + uno::makeAny( m_sFollowPageStyleName ) ); + } + else if ( !m_aFirstPageStyle.is() && xPageStyles.is() ) + { + xPageStyles->getByName( m_sFirstPageStyleName ) >>= m_aFirstPageStyle; + } + xRet = m_aFirstPageStyle; + } + else + { + if ( m_sFollowPageStyleName.isEmpty() && xPageStyles.is() ) + { + m_sFollowPageStyleName = rDM_Impl.GetUnusedPageStyleName(); + m_aFollowPageStyle.set( xTextFactory->createInstance( "com.sun.star.style.PageStyle" ), + uno::UNO_QUERY ); + xPageStyles->insertByName( m_sFollowPageStyleName, uno::makeAny( m_aFollowPageStyle ) ); + } + else if ( !m_aFollowPageStyle.is() && xPageStyles.is() ) + { + xPageStyles->getByName( m_sFollowPageStyleName ) >>= m_aFollowPageStyle; + } + xRet = m_aFollowPageStyle; + } + + } + catch ( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION( "writerfilter" ); + } + + return xRet; +} + +void SectionPropertyMap::SetBorder( BorderPosition ePos, sal_Int32 nLineDistance, const table::BorderLine2& rBorderLine, bool bShadow ) +{ + m_oBorderLines[ePos] = rBorderLine; + m_nBorderDistances[ePos] = nLineDistance; + m_bBorderShadows[ePos] = bShadow; +} + +void SectionPropertyMap::ApplyBorderToPageStyles( DomainMapper_Impl& rDM_Impl, + BorderApply eBorderApply, BorderOffsetFrom eOffsetFrom ) +{ + /* + page border applies to: + nIntValue & 0x07 -> + 0 all pages in this section + 1 first page in this section + 2 all pages in this section but first + 3 whole document (all sections) + nIntValue & 0x18 -> page border depth 0 - in front 1- in back + nIntValue & 0xe0 -> + page border offset from: + 0 offset from text + 1 offset from edge of page + */ + uno::Reference< beans::XPropertySet > xFirst; + uno::Reference< beans::XPropertySet > xSecond; + // todo: negative spacing (from ww8par6.cxx) + switch ( eBorderApply ) + { + case BorderApply::ToAllInSection: // all styles + if ( !m_sFollowPageStyleName.isEmpty() ) + xFirst = GetPageStyle( rDM_Impl, false ); + if ( !m_sFirstPageStyleName.isEmpty() ) + xSecond = GetPageStyle( rDM_Impl, true ); + break; + case BorderApply::ToFirstPageInSection: // first page + if ( !m_sFirstPageStyleName.isEmpty() ) + xFirst = GetPageStyle( rDM_Impl, true ); + break; + case BorderApply::ToAllButFirstInSection: // left and right + if ( !m_sFollowPageStyleName.isEmpty() ) + xFirst = GetPageStyle( rDM_Impl, false ); + break; + default: + return; + } + + // has to be sorted like enum BorderPosition: l-r-t-b + const PropertyIds aBorderIds[4] = + { + PROP_LEFT_BORDER, + PROP_RIGHT_BORDER, + PROP_TOP_BORDER, + PROP_BOTTOM_BORDER + }; + + const PropertyIds aBorderDistanceIds[4] = + { + PROP_LEFT_BORDER_DISTANCE, + PROP_RIGHT_BORDER_DISTANCE, + PROP_TOP_BORDER_DISTANCE, + PROP_BOTTOM_BORDER_DISTANCE + }; + + const PropertyIds aMarginIds[4] = + { + PROP_LEFT_MARGIN, + PROP_RIGHT_MARGIN, + PROP_TOP_MARGIN, + PROP_BOTTOM_MARGIN + }; + + for ( sal_Int32 nBorder = 0; nBorder < 4; ++nBorder ) + { + if ( m_oBorderLines[nBorder] ) + { + const OUString sBorderName = getPropertyName( aBorderIds[nBorder] ); + if ( xFirst.is() ) + xFirst->setPropertyValue( sBorderName, uno::makeAny( *m_oBorderLines[nBorder] ) ); + if ( xSecond.is() ) + xSecond->setPropertyValue( sBorderName, uno::makeAny( *m_oBorderLines[nBorder] ) ); + } + if ( m_nBorderDistances[nBorder] >= 0 ) + { + sal_uInt32 nLineWidth = 0; + if ( m_oBorderLines[nBorder] ) + nLineWidth = m_oBorderLines[nBorder]->LineWidth; + if ( xFirst.is() ) + SetBorderDistance( xFirst, aMarginIds[nBorder], aBorderDistanceIds[nBorder], + m_nBorderDistances[nBorder], eOffsetFrom, nLineWidth ); + if ( xSecond.is() ) + SetBorderDistance( xSecond, aMarginIds[nBorder], aBorderDistanceIds[nBorder], + m_nBorderDistances[nBorder], eOffsetFrom, nLineWidth ); + } + } + + if ( m_bBorderShadows[BORDER_RIGHT] ) + { + table::ShadowFormat aFormat = getShadowFromBorder( *m_oBorderLines[BORDER_RIGHT] ); + if ( xFirst.is() ) + xFirst->setPropertyValue( getPropertyName( PROP_SHADOW_FORMAT ), uno::makeAny( aFormat ) ); + if ( xSecond.is() ) + xSecond->setPropertyValue( getPropertyName( PROP_SHADOW_FORMAT ), uno::makeAny( aFormat ) ); + } +} + +table::ShadowFormat PropertyMap::getShadowFromBorder( const table::BorderLine2& rBorder ) +{ + // In Word UI, shadow is a boolean property, in OOXML, it's a boolean + // property of each 4 border type, finally in Writer the border is a + // property of the page style, with shadow location, distance and + // color. See SwWW8ImplReader::SetShadow(). + table::ShadowFormat aFormat; + aFormat.Color = sal_Int32(COL_BLACK); + aFormat.Location = table::ShadowLocation_BOTTOM_RIGHT; + aFormat.ShadowWidth = rBorder.LineWidth; + return aFormat; +} + +void SectionPropertyMap::SetBorderDistance( const uno::Reference< beans::XPropertySet >& xStyle, + PropertyIds eMarginId, + PropertyIds eDistId, + sal_Int32 nDistance, + BorderOffsetFrom eOffsetFrom, + sal_uInt32 nLineWidth ) +{ + if (!xStyle.is()) + return; + const OUString sMarginName = getPropertyName( eMarginId ); + const OUString sBorderDistanceName = getPropertyName( eDistId ); + uno::Any aMargin = xStyle->getPropertyValue( sMarginName ); + sal_Int32 nMargin = 0; + aMargin >>= nMargin; + editeng::BorderDistanceFromWord(eOffsetFrom == BorderOffsetFrom::Edge, nMargin, nDistance, + nLineWidth); + + // Change the margins with the border distance + uno::Reference< beans::XMultiPropertySet > xMultiSet( xStyle, uno::UNO_QUERY_THROW ); + uno::Sequence aProperties { sMarginName, sBorderDistanceName }; + uno::Sequence aValues { uno::makeAny( nMargin ), uno::makeAny( nDistance ) }; + xMultiSet->setPropertyValues( aProperties, aValues ); +} + +void SectionPropertyMap::DontBalanceTextColumns() +{ + try + { + if ( m_xColumnContainer.is() ) + m_xColumnContainer->setPropertyValue( "DontBalanceTextColumns", uno::makeAny( true ) ); + } + catch ( const uno::Exception& ) + { + OSL_FAIL( "Exception in SectionPropertyMap::DontBalanceTextColumns" ); + } +} + +void SectionPropertyMap::ApplySectionProperties( const uno::Reference< beans::XPropertySet >& xSection, DomainMapper_Impl& /*rDM_Impl*/ ) +{ + try + { + if ( xSection.is() ) + { + std::optional< PropertyMap::Property > pProp = getProperty( PROP_WRITING_MODE ); + if ( pProp ) + xSection->setPropertyValue( "WritingMode", pProp->second ); + } + } + catch ( uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "Exception in SectionPropertyMap::ApplySectionProperties"); + } +} + +void SectionPropertyMap::ApplyProtectionProperties( uno::Reference< beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl ) +{ + try + { + // Word implements section protection differently than LO. + // PROP_IS_PROTECTED only applies if global setting GetProtectForm is enabled. + bool bIsProtected = rDM_Impl.GetSettingsTable()->GetProtectForm(); + if ( bIsProtected ) + { + // If form protection is enabled then section protection is enabled, unless explicitly disabled + if ( isSet(PROP_IS_PROTECTED) ) + getProperty(PROP_IS_PROTECTED)->second >>= bIsProtected; + if ( !xSection.is() ) + xSection = rDM_Impl.appendTextSectionAfter( m_xStartingRange ); + if ( xSection.is() ) + xSection->setPropertyValue( getPropertyName(PROP_IS_PROTECTED), uno::makeAny(bIsProtected) ); + } + } + catch ( uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "ApplyProtectionProperties failed setting PROP_IS_PROTECTED"); + } +} + +uno::Reference< text::XTextColumns > SectionPropertyMap::ApplyColumnProperties( const uno::Reference< beans::XPropertySet >& xColumnContainer, + DomainMapper_Impl& rDM_Impl ) +{ + uno::Reference< text::XTextColumns > xColumns; + try + { + const OUString sTextColumns = getPropertyName( PROP_TEXT_COLUMNS ); + if ( xColumnContainer.is() ) + xColumnContainer->getPropertyValue( sTextColumns ) >>= xColumns; + uno::Reference< beans::XPropertySet > xColumnPropSet( xColumns, uno::UNO_QUERY_THROW ); + if ( !m_bEvenlySpaced && + ( sal_Int32(m_aColWidth.size()) == (m_nColumnCount + 1) ) && + ( (sal_Int32(m_aColDistance.size()) == m_nColumnCount) || (sal_Int32(m_aColDistance.size()) == m_nColumnCount + 1) ) ) + { + // the column width in word is an absolute value, in OOo it's relative + // the distances are both absolute + sal_Int32 nColSum = 0; + for ( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol ) + { + nColSum += m_aColWidth[nCol]; + if ( nCol ) + nColSum += m_aColDistance[nCol - 1]; + } + + sal_Int32 nRefValue = xColumns->getReferenceValue(); + double fRel = nColSum ? double( nRefValue ) / double( nColSum ) : 0.0; + uno::Sequence< text::TextColumn > aColumns( m_nColumnCount + 1 ); + text::TextColumn* pColumn = aColumns.getArray(); + + nColSum = 0; + for ( sal_Int32 nCol = 0; nCol <= m_nColumnCount; ++nCol ) + { + const double fLeft = nCol ? m_aColDistance[nCol - 1] / 2 : 0; + pColumn[nCol].LeftMargin = fLeft; + const double fRight = nCol == m_nColumnCount ? 0 : m_aColDistance[nCol] / 2; + pColumn[nCol].RightMargin = fRight; + const double fWidth = m_aColWidth[nCol]; + pColumn[nCol].Width = (fWidth + fLeft + fRight) * fRel; + nColSum += pColumn[nCol].Width; + } + if ( nColSum != nRefValue ) + pColumn[m_nColumnCount].Width += (nRefValue - nColSum); + assert( pColumn[m_nColumnCount].Width >= 0 ); + + xColumns->setColumns( aColumns ); + } + else + { + xColumns->setColumnCount( m_nColumnCount + 1 ); + xColumnPropSet->setPropertyValue( getPropertyName( PROP_AUTOMATIC_DISTANCE ), uno::makeAny( m_nColumnDistance ) ); + } + + if ( m_bSeparatorLineIsOn ) + { + xColumnPropSet->setPropertyValue( "SeparatorLineIsOn", uno::makeAny( true ) ); + xColumnPropSet->setPropertyValue( "SeparatorLineVerticalAlignment", uno::makeAny( style::VerticalAlignment_TOP ) ); + xColumnPropSet->setPropertyValue( "SeparatorLineRelativeHeight", uno::makeAny( static_cast(100) ) ); + xColumnPropSet->setPropertyValue( "SeparatorLineColor", uno::makeAny( static_cast(COL_BLACK) ) ); + // 1 twip -> 2 mm100. + xColumnPropSet->setPropertyValue( "SeparatorLineWidth", uno::makeAny( static_cast(2) ) ); + } + xColumnContainer->setPropertyValue( sTextColumns, uno::makeAny( xColumns ) ); + // Set the columns to be unbalanced if that compatibility option is set or this is the last section. + m_xColumnContainer = xColumnContainer; + if ( rDM_Impl.GetSettingsTable()->GetNoColumnBalance() || rDM_Impl.GetIsLastSectionGroup() ) + DontBalanceTextColumns(); + } + catch ( const uno::Exception& ) + { + OSL_FAIL( "Exception in SectionPropertyMap::ApplyColumnProperties" ); + } + return xColumns; +} + +bool SectionPropertyMap::HasHeader( bool bFirstPage ) const +{ + bool bRet = false; + if ( (bFirstPage && m_aFirstPageStyle.is()) || (!bFirstPage && m_aFollowPageStyle.is()) ) + { + if ( bFirstPage ) + m_aFirstPageStyle->getPropertyValue( + getPropertyName( PROP_HEADER_IS_ON ) ) >>= bRet; + else + m_aFollowPageStyle->getPropertyValue( + getPropertyName( PROP_HEADER_IS_ON ) ) >>= bRet; + } + return bRet; +} + +bool SectionPropertyMap::HasFooter( bool bFirstPage ) const +{ + bool bRet = false; + if ( (bFirstPage && m_aFirstPageStyle.is()) || (!bFirstPage && m_aFollowPageStyle.is()) ) + { + if ( bFirstPage ) + m_aFirstPageStyle->getPropertyValue( getPropertyName( PROP_FOOTER_IS_ON ) ) >>= bRet; + else + m_aFollowPageStyle->getPropertyValue( getPropertyName( PROP_FOOTER_IS_ON ) ) >>= bRet; + } + return bRet; +} + +#define MIN_HEAD_FOOT_HEIGHT 100 // minimum header/footer height + +void SectionPropertyMap::CopyHeaderFooterTextProperty( const uno::Reference< beans::XPropertySet >& xPrevStyle, + const uno::Reference< beans::XPropertySet >& xStyle, + PropertyIds ePropId ) +{ + try { + OUString sName = getPropertyName( ePropId ); + + SAL_INFO( "writerfilter", "Copying " << sName ); + uno::Reference< text::XTextCopy > xTxt; + if ( xStyle.is() ) + xTxt.set( xStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW ); + + uno::Reference< text::XTextCopy > xPrevTxt; + if ( xPrevStyle.is() ) + xPrevTxt.set( xPrevStyle->getPropertyValue( sName ), uno::UNO_QUERY_THROW ); + + xTxt->copyText( xPrevTxt ); + } + catch ( const uno::Exception& ) + { + TOOLS_INFO_EXCEPTION( "writerfilter", "An exception occurred in SectionPropertyMap::CopyHeaderFooterTextProperty( )" ); + } +} + +// Copy headers and footers from the previous page style. +void SectionPropertyMap::CopyHeaderFooter( const uno::Reference< beans::XPropertySet >& xPrevStyle, + const uno::Reference< beans::XPropertySet >& xStyle, + bool bOmitRightHeader, + bool bOmitLeftHeader, + bool bOmitRightFooter, + bool bOmitLeftFooter ) +{ + bool bHasPrevHeader = false; + bool bHeaderIsShared = true; + OUString sHeaderIsOn = getPropertyName( PROP_HEADER_IS_ON ); + OUString sHeaderIsShared = getPropertyName( PROP_HEADER_IS_SHARED ); + if ( xPrevStyle.is() ) + { + xPrevStyle->getPropertyValue( sHeaderIsOn ) >>= bHasPrevHeader; + xPrevStyle->getPropertyValue( sHeaderIsShared ) >>= bHeaderIsShared; + } + + if ( bHasPrevHeader ) + { + uno::Reference< beans::XMultiPropertySet > xMultiSet( xStyle, uno::UNO_QUERY_THROW ); + uno::Sequence aProperties { sHeaderIsOn, sHeaderIsShared }; + uno::Sequence aValues { uno::makeAny( true ), uno::makeAny( bHeaderIsShared ) }; + xMultiSet->setPropertyValues( aProperties, aValues ); + if ( !bOmitRightHeader ) + { + CopyHeaderFooterTextProperty( xPrevStyle, xStyle, + PROP_HEADER_TEXT ); + } + if ( !bHeaderIsShared && !bOmitLeftHeader ) + { + CopyHeaderFooterTextProperty( xPrevStyle, xStyle, + PROP_HEADER_TEXT_LEFT ); + } + } + + bool bHasPrevFooter = false; + bool bFooterIsShared = true; + OUString sFooterIsOn = getPropertyName( PROP_FOOTER_IS_ON ); + OUString sFooterIsShared = getPropertyName( PROP_FOOTER_IS_SHARED ); + if ( xPrevStyle.is() ) + { + xPrevStyle->getPropertyValue( sFooterIsOn ) >>= bHasPrevFooter; + xPrevStyle->getPropertyValue( sFooterIsShared ) >>= bFooterIsShared; + } + + if ( bHasPrevFooter ) + { + uno::Reference< beans::XMultiPropertySet > xMultiSet( xStyle, uno::UNO_QUERY_THROW ); + uno::Sequence aProperties { sFooterIsOn, sFooterIsShared }; + uno::Sequence aValues { uno::makeAny( true ), uno::makeAny( bFooterIsShared ) }; + xMultiSet->setPropertyValues( aProperties, aValues ); + if ( !bOmitRightFooter ) + { + CopyHeaderFooterTextProperty( xPrevStyle, xStyle, + PROP_FOOTER_TEXT ); + } + if ( !bFooterIsShared && !bOmitLeftFooter ) + { + CopyHeaderFooterTextProperty( xPrevStyle, xStyle, + PROP_FOOTER_TEXT_LEFT ); + } + } +} + +// Copy header and footer content from the previous docx section as needed. +// +// Any headers and footers which were not defined in this docx section +// should be "linked" with the corresponding header or footer from the +// previous section. LO does not support linking of header/footer content +// across page styles so we just copy the content from the previous section. +void SectionPropertyMap::CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Impl& rDM_Impl ) +{ + SAL_INFO( "writerfilter", "START>>> SectionPropertyMap::CopyLastHeaderFooter()" ); + SectionPropertyMap* pLastContext = rDM_Impl.GetLastSectionContext(); + if ( pLastContext ) + { + uno::Reference< beans::XPropertySet > xPrevStyle = pLastContext->GetPageStyle( rDM_Impl, + bFirstPage ); + uno::Reference< beans::XPropertySet > xStyle = GetPageStyle( rDM_Impl, + bFirstPage ); + + if ( bFirstPage ) + { + CopyHeaderFooter( xPrevStyle, xStyle, + !m_bFirstPageHeaderLinkToPrevious, true, + !m_bFirstPageFooterLinkToPrevious, true ); + } + else + { + CopyHeaderFooter( xPrevStyle, xStyle, + !m_bDefaultHeaderLinkToPrevious, + !m_bEvenPageHeaderLinkToPrevious, + !m_bDefaultFooterLinkToPrevious, + !m_bEvenPageFooterLinkToPrevious ); + } + } + SAL_INFO( "writerfilter", "END>>> SectionPropertyMap::CopyLastHeaderFooter()" ); +} + +void SectionPropertyMap::PrepareHeaderFooterProperties( bool bFirstPage ) +{ + bool bCopyFirstToFollow = bFirstPage && m_bTitlePage && m_aFollowPageStyle.is(); + + sal_Int32 nTopMargin = m_nTopMargin; + sal_Int32 nHeaderTop = m_nHeaderTop; + if ( HasHeader( bFirstPage ) ) + { + nTopMargin = nHeaderTop; + if ( m_nTopMargin > 0 && m_nTopMargin > nHeaderTop ) + nHeaderTop = m_nTopMargin - nHeaderTop; + else + nHeaderTop = 0; + + // minimum header height 1mm + if ( nHeaderTop < MIN_HEAD_FOOT_HEIGHT ) + nHeaderTop = MIN_HEAD_FOOT_HEIGHT; + } + + + if ( m_nTopMargin >= 0 ) //fixed height header -> see WW8Par6.hxx + { + Insert( PROP_HEADER_IS_DYNAMIC_HEIGHT, uno::makeAny( true ) ); + Insert( PROP_HEADER_DYNAMIC_SPACING, uno::makeAny( true ) ); + Insert( PROP_HEADER_BODY_DISTANCE, uno::makeAny( nHeaderTop - MIN_HEAD_FOOT_HEIGHT ) );// ULSpace.Top() + Insert( PROP_HEADER_HEIGHT, uno::makeAny( nHeaderTop ) ); + + if (bCopyFirstToFollow && HasHeader(/*bFirstPage=*/true)) + { + m_aFollowPageStyle->setPropertyValue("HeaderDynamicSpacing", + getProperty(PROP_HEADER_DYNAMIC_SPACING)->second); + m_aFollowPageStyle->setPropertyValue("HeaderHeight", + getProperty(PROP_HEADER_HEIGHT)->second); + } + } + else + { + //todo: old filter fakes a frame into the header/footer to support overlapping + //current setting is completely wrong! + Insert( PROP_HEADER_HEIGHT, uno::makeAny( nHeaderTop ) ); + Insert( PROP_HEADER_BODY_DISTANCE, uno::makeAny( m_nTopMargin - nHeaderTop ) ); + Insert( PROP_HEADER_IS_DYNAMIC_HEIGHT, uno::makeAny( false ) ); + Insert( PROP_HEADER_DYNAMIC_SPACING, uno::makeAny( false ) ); + } + + sal_Int32 nBottomMargin = m_nBottomMargin; + sal_Int32 nHeaderBottom = m_nHeaderBottom; + if ( HasFooter( bFirstPage ) ) + { + nBottomMargin = nHeaderBottom; + if ( m_nBottomMargin > 0 && m_nBottomMargin > nHeaderBottom ) + nHeaderBottom = m_nBottomMargin - nHeaderBottom; + else + nHeaderBottom = 0; + if ( nHeaderBottom < MIN_HEAD_FOOT_HEIGHT ) + nHeaderBottom = MIN_HEAD_FOOT_HEIGHT; + } + + if ( m_nBottomMargin >= 0 ) //fixed height footer -> see WW8Par6.hxx + { + Insert( PROP_FOOTER_IS_DYNAMIC_HEIGHT, uno::makeAny( true ) ); + Insert( PROP_FOOTER_DYNAMIC_SPACING, uno::makeAny( true ) ); + Insert( PROP_FOOTER_BODY_DISTANCE, uno::makeAny( nHeaderBottom - MIN_HEAD_FOOT_HEIGHT ) ); + Insert( PROP_FOOTER_HEIGHT, uno::makeAny( nHeaderBottom ) ); + + if (bCopyFirstToFollow && HasFooter(/*bFirstPage=*/true)) + { + m_aFollowPageStyle->setPropertyValue("FooterDynamicSpacing", + getProperty(PROP_FOOTER_DYNAMIC_SPACING)->second); + m_aFollowPageStyle->setPropertyValue("FooterHeight", + getProperty(PROP_FOOTER_HEIGHT)->second); + } + } + else + { + //todo: old filter fakes a frame into the header/footer to support overlapping + //current setting is completely wrong! + Insert( PROP_FOOTER_IS_DYNAMIC_HEIGHT, uno::makeAny( false ) ); + Insert( PROP_FOOTER_DYNAMIC_SPACING, uno::makeAny( false ) ); + Insert( PROP_FOOTER_HEIGHT, uno::makeAny( m_nBottomMargin - nHeaderBottom ) ); + Insert( PROP_FOOTER_BODY_DISTANCE, uno::makeAny( nHeaderBottom ) ); + } + + //now set the top/bottom margin for the follow page style + Insert( PROP_TOP_MARGIN, uno::makeAny( std::max(nTopMargin, 0) ) ); + Insert( PROP_BOTTOM_MARGIN, uno::makeAny( std::max(nBottomMargin, 0) ) ); + + if (bCopyFirstToFollow) + { + if (HasHeader(/*bFirstPage=*/true)) + m_aFollowPageStyle->setPropertyValue("TopMargin", getProperty(PROP_TOP_MARGIN)->second); + if (HasFooter(/*bFirstPage=*/true)) + m_aFollowPageStyle->setPropertyValue("BottomMargin", + getProperty(PROP_BOTTOM_MARGIN)->second); + } +} + +static uno::Reference< beans::XPropertySet > lcl_GetRangeProperties( bool bIsFirstSection, + DomainMapper_Impl& rDM_Impl, + const uno::Reference< text::XTextRange >& xStartingRange ) +{ + uno::Reference< beans::XPropertySet > xRangeProperties; + if ( bIsFirstSection && rDM_Impl.GetBodyText().is() ) + { + uno::Reference< container::XEnumerationAccess > xEnumAccess( rDM_Impl.GetBodyText(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration(); + xRangeProperties.set( xEnum->nextElement(), uno::UNO_QUERY_THROW ); + if ( rDM_Impl.GetIsDummyParaAddedForTableInSection() && xEnum->hasMoreElements() ) + xRangeProperties.set( xEnum->nextElement(), uno::UNO_QUERY_THROW ); + } + else if ( xStartingRange.is() ) + xRangeProperties.set( xStartingRange, uno::UNO_QUERY_THROW ); + return xRangeProperties; +} + +void SectionPropertyMap::HandleMarginsHeaderFooter( bool bFirstPage, DomainMapper_Impl& rDM_Impl ) +{ + Insert( PROP_LEFT_MARGIN, uno::makeAny( m_nLeftMargin ) ); + Insert( PROP_RIGHT_MARGIN, uno::makeAny( m_nRightMargin ) ); + + if ( rDM_Impl.m_oBackgroundColor ) + Insert( PROP_BACK_COLOR, uno::makeAny( *rDM_Impl.m_oBackgroundColor ) ); + + // Check for missing footnote separator only in case there is at least + // one footnote. + if (rDM_Impl.m_bHasFtn && !rDM_Impl.m_bHasFtnSep) + { + // Set footnote line width to zero, document has no footnote separator. + Insert(PROP_FOOTNOTE_LINE_RELATIVE_WIDTH, uno::makeAny(sal_Int32(0))); + } + if ( rDM_Impl.m_bHasFtnSep ) + { + //If default paragraph style is RTL, footnote separator should be right aligned + //and for RTL locales, LTR default paragraph style should present a left aligned footnote separator + try + { + uno::Reference xStylesSupplier(rDM_Impl.GetTextDocument(), uno::UNO_QUERY); + if ( xStylesSupplier.is() ) + { + uno::Reference xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xParagraphStyles; + if ( xStyleFamilies.is() ) + xStyleFamilies->getByName("ParagraphStyles") >>= xParagraphStyles; + uno::Reference xStandard; + if ( xParagraphStyles.is() ) + xParagraphStyles->getByName("Standard") >>= xStandard; + if ( xStandard.is() ) + { + sal_Int16 aWritingMode(0); + xStandard->getPropertyValue( getPropertyName(PROP_WRITING_MODE) ) >>= aWritingMode; + if( aWritingMode == text::WritingMode2::RL_TB ) + Insert( PROP_FOOTNOTE_LINE_ADJUST, uno::makeAny( sal_Int16(text::HorizontalAdjust_RIGHT) ), false ); + else + Insert( PROP_FOOTNOTE_LINE_ADJUST, uno::makeAny( sal_Int16(text::HorizontalAdjust_LEFT) ), false ); + } + } + } + catch ( const uno::Exception& ) {} + } + + /*** if headers/footers are available then the top/bottom margins of the + header/footer are copied to the top/bottom margin of the page + */ + CopyLastHeaderFooter( bFirstPage, rDM_Impl ); + PrepareHeaderFooterProperties( bFirstPage ); +} + +bool SectionPropertyMap::FloatingTableConversion( const DomainMapper_Impl& rDM_Impl, FloatingTableInfo& rInfo ) +{ + // This is OOXML version of the code deciding if the table needs to be + // in a floating frame. + // For ww8 code, see SwWW8ImplReader::FloatingTableConversion in + // sw/source/filter/ww8/ww8par.cxx + // The two should do the same, so if you make changes here, please check + // that the other is in sync. + + // Note that this is just a list of heuristics till sw core can have a + // table that is floating and can span over multiple pages at the same + // time. + + // If there is an explicit section break right after a table, then there + // will be no wrapping anyway. + if (rDM_Impl.m_bConvertedTable && !rDM_Impl.GetIsLastSectionGroup() && rInfo.m_nBreakType == NS_ooxml::LN_Value_ST_SectionMark_nextPage) + return false; + + sal_Int32 nPageWidth = GetPageWidth(); + sal_Int32 nTextAreaWidth = nPageWidth - GetLeftMargin() - GetRightMargin(); + // Count the layout width of the table. + sal_Int32 nTableWidth = rInfo.m_nTableWidth; + if (rInfo.m_nTableWidthType == text::SizeType::VARIABLE) + { + nTableWidth *= nTextAreaWidth / 100.0; + } + sal_Int32 nLeftMargin = 0; + if ( rInfo.getPropertyValue( "LeftMargin" ) >>= nLeftMargin ) + nTableWidth += nLeftMargin; + sal_Int32 nRightMargin = 0; + if ( rInfo.getPropertyValue( "RightMargin" ) >>= nRightMargin ) + nTableWidth += nRightMargin; + + sal_Int16 nHoriOrientRelation = rInfo.getPropertyValue( "HoriOrientRelation" ).get(); + sal_Int16 nVertOrientRelation = rInfo.getPropertyValue( "VertOrientRelation" ).get(); + if ( nHoriOrientRelation == text::RelOrientation::PAGE_FRAME && nVertOrientRelation == text::RelOrientation::PAGE_FRAME ) + { + sal_Int16 nHoriOrient = rInfo.getPropertyValue( "HoriOrient" ).get(); + sal_Int16 nVertOrient = rInfo.getPropertyValue( "VertOrient" ).get(); + if ( nHoriOrient == text::HoriOrientation::NONE && nVertOrient == text::VertOrientation::NONE ) + { + // Anchor position is relative to the page horizontally and vertically as well and is an absolute position. + // The more close we are to the left edge, the less likely there will be any wrapping. + // The more close we are to the bottom, the more likely the table will span over to the next page + // So if we're in the bottom left quarter, don't do any conversion. + sal_Int32 nHoriOrientPosition = rInfo.getPropertyValue( "HoriOrientPosition" ).get(); + sal_Int32 nVertOrientPosition = rInfo.getPropertyValue( "VertOrientPosition" ).get(); + sal_Int32 nPageHeight = getProperty( PROP_HEIGHT )->second.get(); + if ( nHoriOrientPosition < (nPageWidth / 2) && nVertOrientPosition >( nPageHeight / 2 ) ) + return false; + } + } + + // It seems Word has a limit here, so that in case the table width is quite + // close to the text area width, then it won't perform a wrapping, even in + // case the content (e.g. an empty paragraph) would fit. The magic constant + // here represents this limit. + const sal_Int32 nMagicNumber = 469; + + // If the table's width is smaller than the text area width, text might + // be next to the table and so it should behave as a floating table. + if ( (nTableWidth + nMagicNumber) < nTextAreaWidth ) + return true; + + // If the position is relative to the edge of the page, then we need to check the whole + // page width to see whether text can fit next to the table. + if ( nHoriOrientRelation == text::RelOrientation::PAGE_FRAME ) + { + // If the table is wide enough so that no text fits next to it, then don't create a fly + // for the table: no wrapping will be performed anyway, but multi-page + // tables will be broken. + if ((nTableWidth + nMagicNumber) < (nPageWidth - std::min(GetLeftMargin(), GetRightMargin()))) + return true; + } + + // If there are columns, always create the fly, otherwise the columns would + // restrict geometry of the table. + if ( ColumnCount() + 1 >= 2 ) + return true; + + return false; +} + +void SectionPropertyMap::InheritOrFinalizePageStyles( DomainMapper_Impl& rDM_Impl ) +{ + // if no new styles have been created for this section, inherit from the previous section, + // otherwise apply this section's settings to the new style. + // Ensure that FollowPage is inherited first - otherwise GetPageStyle may auto-create a follow when checking FirstPage. + SectionPropertyMap* pLastContext = rDM_Impl.GetLastSectionContext(); + //tdf124637 TODO: identify and skip special sections (like footnotes/endnotes) + if ( pLastContext && m_sFollowPageStyleName.isEmpty() ) + m_sFollowPageStyleName = pLastContext->GetPageStyleName(); + else + { + HandleMarginsHeaderFooter( /*bFirst=*/false, rDM_Impl ); + GetPageStyle( rDM_Impl, /*bFirst=*/false ); + if ( rDM_Impl.IsNewDoc() && m_aFollowPageStyle.is() ) + ApplyProperties_( m_aFollowPageStyle ); + } + + // FirstPageStyle may only be inherited if it will not be used or re-linked to a different follow + if ( !m_bTitlePage && pLastContext && m_sFirstPageStyleName.isEmpty() ) + m_sFirstPageStyleName = pLastContext->GetPageStyleName( /*bFirst=*/true ); + else + { + HandleMarginsHeaderFooter( /*bFirst=*/true, rDM_Impl ); + GetPageStyle( rDM_Impl, /*bFirst=*/true ); + if ( rDM_Impl.IsNewDoc() && m_aFirstPageStyle.is() ) + ApplyProperties_( m_aFirstPageStyle ); + + // Chain m_aFollowPageStyle to be after m_aFirstPageStyle + m_aFirstPageStyle->setPropertyValue( "FollowStyle", uno::makeAny( m_sFollowPageStyleName ) ); + } +} + +void SectionPropertyMap::HandleIncreasedAnchoredObjectSpacing(DomainMapper_Impl& rDM_Impl) +{ + // Ignore Word 2010 and older. + if (rDM_Impl.GetSettingsTable()->GetWordCompatibilityMode() < 15) + return; + + sal_Int32 nPageWidth = GetPageWidth(); + sal_Int32 nTextAreaWidth = nPageWidth - GetLeftMargin() - GetRightMargin(); + + std::vector& rAnchoredObjectAnchors = rDM_Impl.m_aAnchoredObjectAnchors; + for (const auto& rAnchor : rAnchoredObjectAnchors) + { + // Ignore this paragraph when there are not enough shapes to trigger the Word bug we + // emulate. + if (rAnchor.m_aAnchoredObjects.size() < 4) + continue; + + // Ignore this paragraph if none of the objects are wrapped in the background. + sal_Int32 nOpaqueCount = 0; + for (const auto& rAnchored : rAnchor.m_aAnchoredObjects) + { + uno::Reference xShape(rAnchored.m_xAnchoredObject, uno::UNO_QUERY); + if (!xShape.is()) + { + continue; + } + + bool bOpaque = true; + xShape->getPropertyValue("Opaque") >>= bOpaque; + if (!bOpaque) + { + ++nOpaqueCount; + } + } + if (nOpaqueCount < 1) + { + continue; + } + + // Analyze the anchored objects of this paragraph, now that we know the + // page width. + sal_Int32 nShapesWidth = 0; + for (const auto& rAnchored : rAnchor.m_aAnchoredObjects) + { + uno::Reference xShape(rAnchored.m_xAnchoredObject, uno::UNO_QUERY); + if (!xShape.is()) + continue; + + uno::Reference xPropertySet(xShape, uno::UNO_QUERY); + if (!xPropertySet.is()) + continue; + + // Ignore objects with no wrapping. + text::WrapTextMode eWrap = text::WrapTextMode_THROUGH; + xPropertySet->getPropertyValue("Surround") >>= eWrap; + if (eWrap == text::WrapTextMode_THROUGH) + continue; + + // Use the original left margin, in case GraphicImport::lcl_sprm() reduced the doc model + // one to 0. + sal_Int32 nLeftMargin = rAnchored.m_nLeftMargin; + sal_Int32 nRightMargin = 0; + xPropertySet->getPropertyValue("RightMargin") >>= nRightMargin; + nShapesWidth += xShape->getSize().Width + nLeftMargin + nRightMargin; + } + + // Ignore cases when we have enough horizontal space for the shapes. + if (nTextAreaWidth > nShapesWidth) + continue; + + sal_Int32 nHeight = 0; + for (const auto& rAnchored : rAnchor.m_aAnchoredObjects) + { + uno::Reference xShape(rAnchored.m_xAnchoredObject, uno::UNO_QUERY); + if (!xShape.is()) + continue; + + nHeight += xShape->getSize().Height; + } + + uno::Reference xParagraph(rAnchor.m_xParagraph, uno::UNO_QUERY); + if (xParagraph.is()) + { + sal_Int32 nTopMargin = 0; + xParagraph->getPropertyValue("ParaTopMargin") >>= nTopMargin; + // Increase top spacing of the paragraph to match Word layout + // behavior. + nTopMargin = std::max(nTopMargin, nHeight); + xParagraph->setPropertyValue("ParaTopMargin", uno::makeAny(nTopMargin)); + } + } + rAnchoredObjectAnchors.clear(); +} + +void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl ) +{ + // The default section type is nextPage. + if ( m_nBreakType == -1 ) + m_nBreakType = NS_ooxml::LN_Value_ST_SectionMark_nextPage; + // if page orientation differs from previous section, it can't be treated as continuous + else if ( m_nBreakType == NS_ooxml::LN_Value_ST_SectionMark_continuous ) + { + SectionPropertyMap* pLastContext = rDM_Impl.GetLastSectionContext(); + if ( pLastContext ) + { + bool bIsLandscape = false; + std::optional< PropertyMap::Property > pProp = getProperty( PROP_IS_LANDSCAPE ); + if ( pProp ) + pProp->second >>= bIsLandscape; + + bool bPrevIsLandscape = false; + pProp = pLastContext->getProperty( PROP_IS_LANDSCAPE ); + if ( pProp ) + pProp->second >>= bPrevIsLandscape; + + if ( bIsLandscape != bPrevIsLandscape ) + m_nBreakType = NS_ooxml::LN_Value_ST_SectionMark_nextPage; + } + } + + // Text area width is known at the end of a section: decide if tables should be converted or not. + std::vector& rPendingFloatingTables = rDM_Impl.m_aPendingFloatingTables; + uno::Reference xBodyText( rDM_Impl.GetBodyText(), uno::UNO_QUERY ); + for ( FloatingTableInfo & rInfo : rPendingFloatingTables ) + { + rInfo.m_nBreakType = m_nBreakType; + if ( FloatingTableConversion( rDM_Impl, rInfo ) ) + { + try + { + xBodyText->convertToTextFrame(rInfo.m_xStart, rInfo.m_xEnd, + rInfo.m_aFrameProperties); + } + catch (const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "convertToTextFrame() failed"); + } + } + } + rPendingFloatingTables.clear(); + + try + { + HandleIncreasedAnchoredObjectSpacing(rDM_Impl); + } + catch (const uno::Exception&) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "HandleIncreasedAnchoredObjectSpacing() failed"); + } + + if ( m_nLnnMod ) + { + bool bFirst = rDM_Impl.IsLineNumberingSet(); + rDM_Impl.SetLineNumbering( m_nLnnMod, m_nLnc, m_ndxaLnn ); + if ( m_nLnnMin > 0 || (bFirst && m_nLnc == NS_ooxml::LN_Value_ST_LineNumberRestart_newSection) ) + { + //set the starting value at the beginning of the section + try + { + uno::Reference< beans::XPropertySet > xRangeProperties; + if ( m_xStartingRange.is() ) + { + xRangeProperties.set( m_xStartingRange, uno::UNO_QUERY_THROW ); + } + else + { + //set the start value at the beginning of the document + xRangeProperties.set( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW ); + } + // Writer is 1-based, Word is 0-based. + xRangeProperties->setPropertyValue( + getPropertyName(PROP_PARA_LINE_NUMBER_START_VALUE), + uno::makeAny(m_nLnnMin + 1)); + } + catch ( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper", "Exception in SectionPropertyMap::CloseSectionGroup"); + } + } + } + + if (m_nBreakType == static_cast(NS_ooxml::LN_Value_ST_SectionMark_continuous) + && !rDM_Impl.IsInComments()) + { + //todo: insert a section or access the already inserted section + uno::Reference< beans::XPropertySet > xSection = + rDM_Impl.appendTextSectionAfter( m_xStartingRange ); + if ( xSection.is() ) + { + if ( m_nColumnCount > 0 ) + ApplyColumnProperties( xSection, rDM_Impl ); + + ApplyProtectionProperties( xSection, rDM_Impl ); + } + + try + { + InheritOrFinalizePageStyles( rDM_Impl ); + ApplySectionProperties( xSection, rDM_Impl ); //depends on InheritOrFinalizePageStyles + OUString aName = m_bTitlePage ? m_sFirstPageStyleName : m_sFollowPageStyleName; + uno::Reference< beans::XPropertySet > xRangeProperties( lcl_GetRangeProperties( m_bIsFirstSection, rDM_Impl, m_xStartingRange ) ); + if ( m_bIsFirstSection && !aName.isEmpty() && xRangeProperties.is() ) + { + xRangeProperties->setPropertyValue( getPropertyName( PROP_PAGE_DESC_NAME ), uno::makeAny( aName ) ); + } + else if ((!m_bFirstPageHeaderLinkToPrevious || + !m_bFirstPageFooterLinkToPrevious || + !m_bDefaultHeaderLinkToPrevious || + !m_bDefaultFooterLinkToPrevious || + !m_bEvenPageHeaderLinkToPrevious || + !m_bEvenPageFooterLinkToPrevious) + && rDM_Impl.GetCurrentXText()) + { // find a node in the section that has a page break and change + // it to apply the page style; see "nightmare scenario" in + // wwSectionManager::InsertSegments() + auto xTextAppend = rDM_Impl.GetCurrentXText(); + uno::Reference const xCursor( + xTextAppend->createTextCursorByRange( + uno::Reference(xSection, uno::UNO_QUERY_THROW)->getAnchor()), + uno::UNO_QUERY_THROW); + uno::Reference const xEnum( + xCursor->createEnumeration()); + bool isFound = false; + while (xEnum->hasMoreElements()) + { + uno::Reference xElem; + xEnum->nextElement() >>= xElem; + if (xElem->getPropertySetInfo()->hasPropertyByName("BreakType")) + { + style::BreakType bt; + if ((xElem->getPropertyValue("BreakType") >>= bt) + && bt == style::BreakType_PAGE_BEFORE) + { + // tdf#112201: do *not* use m_sFirstPageStyleName here! + xElem->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME), + uno::makeAny(m_sFollowPageStyleName)); + isFound = true; + break; + } + } + } + uno::Reference const xPCursor(xCursor, + uno::UNO_QUERY_THROW); + float fCharHeight = 0; + if (!isFound) + { // HACK: try the last paragraph of the previous section + xPCursor->gotoPreviousParagraph(false); + uno::Reference const xPSCursor(xCursor, uno::UNO_QUERY_THROW); + style::BreakType bt; + if ((xPSCursor->getPropertyValue("BreakType") >>= bt) + && bt == style::BreakType_PAGE_BEFORE) + { + xPSCursor->setPropertyValue(getPropertyName(PROP_PAGE_DESC_NAME), + uno::makeAny(m_sFollowPageStyleName)); + isFound = true; + } + else + { + xPSCursor->getPropertyValue("CharHeight") >>= fCharHeight; + } + } + if (!isFound && fCharHeight <= 1.0) + { + // If still not found, see if the last paragraph is ~invisible, and work with + // the last-in-practice paragraph. + xPCursor->gotoPreviousParagraph(false); + uno::Reference xPropertySet(xCursor, uno::UNO_QUERY_THROW); + OUString aPageDescName; + if ((xPropertySet->getPropertyValue("PageDescName") >>= aPageDescName) + && !aPageDescName.isEmpty()) + { + uno::Reference xPageStyle( + rDM_Impl.GetPageStyles()->getByName(aPageDescName), uno::UNO_QUERY); + xPageStyle->setPropertyValue("FollowStyle", + uno::makeAny(m_sFollowPageStyleName)); + } + } + } + } + catch ( const uno::Exception& ) + { + SAL_WARN( "writerfilter", "failed to set PageDescName!" ); + } + } + // If the section is of type "New column" (0x01), then simply insert a column break. + // But only if there actually are columns on the page, otherwise a column break + // seems to be handled like a page break by MSO. + else if (m_nBreakType == static_cast(NS_ooxml::LN_Value_ST_SectionMark_nextColumn) + && 0 < m_nColumnCount && !rDM_Impl.IsInComments()) + { + try + { + InheritOrFinalizePageStyles( rDM_Impl ); + uno::Reference< beans::XPropertySet > xRangeProperties; + if ( m_xStartingRange.is() ) + { + xRangeProperties.set( m_xStartingRange, uno::UNO_QUERY_THROW ); + } + else + { + //set the start value at the beginning of the document + xRangeProperties.set( rDM_Impl.GetTextDocument()->getText()->getStart(), uno::UNO_QUERY_THROW ); + } + xRangeProperties->setPropertyValue( getPropertyName( PROP_BREAK_TYPE ), uno::makeAny( style::BreakType_COLUMN_BEFORE ) ); + } + catch ( const uno::Exception& ) {} + } + else if (!rDM_Impl.IsInComments()) + { + uno::Reference< beans::XPropertySet > xSection; + ApplyProtectionProperties( xSection, rDM_Impl ); + + //get the properties and create appropriate page styles + uno::Reference< beans::XPropertySet > xFollowPageStyle = GetPageStyle( rDM_Impl, false ); + + HandleMarginsHeaderFooter(/*bFirstPage=*/false, rDM_Impl ); + + if ( rDM_Impl.GetSettingsTable()->GetMirrorMarginSettings() ) + { + Insert( PROP_PAGE_STYLE_LAYOUT, uno::makeAny( style::PageStyleLayout_MIRRORED ) ); + } + uno::Reference< text::XTextColumns > xColumns; + if ( m_nColumnCount > 0 ) + { + // prefer setting column properties into a section, not a page style if at all possible. + if ( !xSection.is() ) + xSection = rDM_Impl.appendTextSectionAfter( m_xStartingRange ); + if ( xSection.is() ) + ApplyColumnProperties( xSection, rDM_Impl ); + else + xColumns = ApplyColumnProperties( xFollowPageStyle, rDM_Impl ); + } + + // these BreakTypes are effectively page-breaks: don't evenly distribute text in columns before a page break; + SectionPropertyMap* pLastContext = rDM_Impl.GetLastSectionContext(); + if ( pLastContext && pLastContext->ColumnCount() ) + pLastContext->DontBalanceTextColumns(); + + //prepare text grid properties + sal_Int32 nHeight = 1; + std::optional< PropertyMap::Property > pProp = getProperty( PROP_HEIGHT ); + if ( pProp ) + pProp->second >>= nHeight; + + sal_Int32 nWidth = 1; + pProp = getProperty( PROP_WIDTH ); + if ( pProp ) + pProp->second >>= nWidth; + + text::WritingMode eWritingMode = text::WritingMode_LR_TB; + pProp = getProperty( PROP_WRITING_MODE ); + if ( pProp ) + pProp->second >>= eWritingMode; + + sal_Int32 nTextAreaHeight = eWritingMode == text::WritingMode_LR_TB ? + nHeight - m_nTopMargin - m_nBottomMargin : + nWidth - m_nLeftMargin - m_nRightMargin; + + sal_Int32 nGridLinePitch = m_nGridLinePitch; + //sep.dyaLinePitch + if ( nGridLinePitch < 1 || nGridLinePitch > 31680 ) + { + SAL_WARN( "writerfilter", "sep.dyaLinePitch outside legal range: " << nGridLinePitch ); + nGridLinePitch = 1; + } + + const sal_Int32 nGridLines = nTextAreaHeight / nGridLinePitch; + if ( nGridLines >= 0 && nGridLines <= SAL_MAX_INT16 ) + Insert( PROP_GRID_LINES, uno::makeAny( sal_Int16(nGridLines) ) ); + + // PROP_GRID_MODE + Insert( PROP_GRID_MODE, uno::makeAny( static_cast (m_nGridType) ) ); + if ( m_nGridType == text::TextGridMode::LINES_AND_CHARS ) + { + Insert( PROP_GRID_SNAP_TO_CHARS, uno::makeAny( m_bGridSnapToChars ) ); + } + + sal_Int32 nCharWidth = 423; //240 twip/ 12 pt + const StyleSheetEntryPtr pEntry = rDM_Impl.GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( "Standard" ); + if ( pEntry ) + { + std::optional< PropertyMap::Property > pPropHeight = pEntry->pProperties->getProperty( PROP_CHAR_HEIGHT_ASIAN ); + if ( pPropHeight ) + { + double fHeight = 0; + if ( pPropHeight->second >>= fHeight ) + nCharWidth = ConversionHelper::convertTwipToMM100( static_cast(fHeight * 20.0 + 0.5) ); + } + } + + //dxtCharSpace + if ( m_nDxtCharSpace ) + { + sal_Int32 nCharSpace = m_nDxtCharSpace; + //main lives in top 20 bits, and is signed. + sal_Int32 nMain = (nCharSpace & 0xFFFFF000); + nMain /= 0x1000; + nCharWidth += ConversionHelper::convertTwipToMM100( nMain * 20 ); + + sal_Int32 nFraction = (nCharSpace & 0x00000FFF); + nFraction = (nFraction * 20) / 0xFFF; + nCharWidth += ConversionHelper::convertTwipToMM100( nFraction ); + } + + if ( m_nPageNumberType >= 0 ) + Insert( PROP_NUMBERING_TYPE, uno::makeAny( m_nPageNumberType ) ); + + // #i119558#, force to set document as standard page mode, + // refer to ww8 import process function "SwWW8ImplReader::SetDocumentGrid" + try + { + uno::Reference< beans::XPropertySet > xDocProperties; + xDocProperties.set( rDM_Impl.GetTextDocument(), uno::UNO_QUERY_THROW ); + Insert(PROP_GRID_STANDARD_MODE, uno::makeAny(true)); + xDocProperties->setPropertyValue("DefaultPageMode", uno::makeAny(false)); + } + catch ( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter.dmapper", "Exception in SectionPropertyMap::CloseSectionGroup"); + } + + Insert( PROP_GRID_BASE_HEIGHT, uno::makeAny( nGridLinePitch ) ); + Insert( PROP_GRID_BASE_WIDTH, uno::makeAny( nCharWidth ) ); + Insert( PROP_GRID_RUBY_HEIGHT, uno::makeAny( sal_Int32( 0 ) ) ); + + if ( rDM_Impl.IsNewDoc() ) + ApplyProperties_( xFollowPageStyle ); + + //todo: creating a "First Page" style depends on HasTitlePage and _fFacingPage_ + if ( m_bTitlePage ) + { + CopyLastHeaderFooter( true, rDM_Impl ); + PrepareHeaderFooterProperties( true ); + uno::Reference< beans::XPropertySet > xFirstPageStyle = GetPageStyle( + rDM_Impl, true ); + if ( rDM_Impl.IsNewDoc() ) + ApplyProperties_( xFirstPageStyle ); + + if ( xColumns.is() ) + xFirstPageStyle->setPropertyValue( + getPropertyName( PROP_TEXT_COLUMNS ), uno::makeAny( xColumns ) ); + } + + ApplyBorderToPageStyles( rDM_Impl, m_eBorderApply, m_eBorderOffsetFrom ); + + try + { + //now apply this break at the first paragraph of this section + uno::Reference< beans::XPropertySet > xRangeProperties( lcl_GetRangeProperties( m_bIsFirstSection, rDM_Impl, m_xStartingRange ) ); + + // Handle page breaks with odd/even page numbering. We need to use an extra page style for setting the page style + // to left/right, because if we set it to the normal style, we'd set it to "First Page"/"Default Style", which would + // break them (all default pages would be only left or right). + if ( m_nBreakType == static_cast(NS_ooxml::LN_Value_ST_SectionMark_evenPage) || m_nBreakType == static_cast(NS_ooxml::LN_Value_ST_SectionMark_oddPage) ) + { + OUString* pageStyle = m_bTitlePage ? &m_sFirstPageStyleName : &m_sFollowPageStyleName; + OUString evenOddStyleName = rDM_Impl.GetUnusedPageStyleName(); + uno::Reference< beans::XPropertySet > evenOddStyle( + rDM_Impl.GetTextFactory()->createInstance( "com.sun.star.style.PageStyle" ), + uno::UNO_QUERY ); + // Unfortunately using setParent() does not work for page styles, so make a deep copy of the page style. + uno::Reference< beans::XPropertySet > pageProperties( m_bTitlePage ? m_aFirstPageStyle : m_aFollowPageStyle ); + uno::Reference< beans::XPropertySetInfo > pagePropertiesInfo( pageProperties->getPropertySetInfo() ); + const uno::Sequence< beans::Property > propertyList( pagePropertiesInfo->getProperties() ); + // Ignore write-only properties. + static const o3tl::sorted_vector aBlacklist + = { "FooterBackGraphicURL", "BackGraphicURL", "HeaderBackGraphicURL" }; + for ( const auto& rProperty : propertyList ) + { + if ( (rProperty.Attributes & beans::PropertyAttribute::READONLY) == 0 ) + { + if (aBlacklist.find(rProperty.Name) == aBlacklist.end()) + evenOddStyle->setPropertyValue( + rProperty.Name, + pageProperties->getPropertyValue(rProperty.Name)); + } + } + evenOddStyle->setPropertyValue( "FollowStyle", uno::makeAny( *pageStyle ) ); + rDM_Impl.GetPageStyles()->insertByName( evenOddStyleName, uno::makeAny( evenOddStyle ) ); + evenOddStyle->setPropertyValue( "HeaderIsOn", uno::makeAny( false ) ); + evenOddStyle->setPropertyValue( "FooterIsOn", uno::makeAny( false ) ); + CopyHeaderFooter( pageProperties, evenOddStyle ); + *pageStyle = evenOddStyleName; // And use it instead of the original one (which is set as follow of this one). + if ( m_nBreakType == static_cast(NS_ooxml::LN_Value_ST_SectionMark_evenPage) ) + evenOddStyle->setPropertyValue( getPropertyName( PROP_PAGE_STYLE_LAYOUT ), uno::makeAny( style::PageStyleLayout_LEFT ) ); + else if ( m_nBreakType == static_cast(NS_ooxml::LN_Value_ST_SectionMark_oddPage) ) + evenOddStyle->setPropertyValue( getPropertyName( PROP_PAGE_STYLE_LAYOUT ), uno::makeAny( style::PageStyleLayout_RIGHT ) ); + } + + if ( xRangeProperties.is() && rDM_Impl.IsNewDoc() ) + { + // Avoid setting page style in case of autotext: so inserting the autotext at the + // end of the document does not introduce an unwanted page break. + if (!rDM_Impl.IsReadGlossaries() && !rDM_Impl.IsInFootOrEndnote()) + { + xRangeProperties->setPropertyValue( + getPropertyName( PROP_PAGE_DESC_NAME ), + uno::makeAny( m_bTitlePage ? m_sFirstPageStyleName + : m_sFollowPageStyleName ) ); + } + + if (0 <= m_nPageNumber) + { + sal_Int16 nPageNumber = static_cast< sal_Int16 >(m_nPageNumber); + xRangeProperties->setPropertyValue(getPropertyName(PROP_PAGE_NUMBER_OFFSET), + uno::makeAny(nPageNumber)); + } + } + } + catch ( const uno::Exception& ) + { + OSL_FAIL( "Exception in SectionPropertyMap::CloseSectionGroup" ); + } + } + + // Now that the margins are known, resize relative width shapes because some shapes in LO do not support percentage-sizes + sal_Int32 nParagraphWidth = GetPageWidth() - m_nLeftMargin - m_nRightMargin; + if ( m_nColumnCount > 0 ) + { + // skip custom-width columns since we don't know what column the shape is in. + if ( !m_aColWidth.empty() ) + nParagraphWidth = 0; + else + nParagraphWidth = (nParagraphWidth - (m_nColumnDistance * m_nColumnCount)) / (m_nColumnCount + 1); + } + if ( nParagraphWidth > 0 ) + { + const OUString sPropRelativeWidth = getPropertyName(PROP_RELATIVE_WIDTH); + for ( const auto& xShape : m_xRelativeWidthShapes ) + { + const uno::Reference xShapePropertySet( xShape, uno::UNO_QUERY ); + if ( xShapePropertySet->getPropertySetInfo()->hasPropertyByName(sPropRelativeWidth) ) + { + sal_uInt16 nPercent = 0; + try + { + xShapePropertySet->getPropertyValue(sPropRelativeWidth) >>= nPercent; + } + catch (const css::uno::RuntimeException& e) + { + // May happen e.g. when text frame has no frame format + // See sw/qa/extras/ooxmlimport/data/n779627.docx + SAL_WARN("writerfilter", "Getting relative width failed. " << e.Message); + } + if ( nPercent ) + { + const sal_Int32 nWidth = nParagraphWidth * nPercent / 100; + xShape->setSize( awt::Size( nWidth, xShape->getSize().Height ) ); + } + } + } + } + m_xRelativeWidthShapes.clear(); + + rDM_Impl.SetIsLastSectionGroup( false ); + rDM_Impl.SetIsFirstParagraphInSection( true ); + + if ( !rDM_Impl.IsInFootOrEndnote() ) + { + rDM_Impl.m_bHasFtn = false; + rDM_Impl.m_bHasFtnSep = false; + } +} + +// Clear the flag that says we should take the header/footer content from +// the previous section. This should be called when we encounter a header +// or footer definition for this section. +void SectionPropertyMap::ClearHeaderFooterLinkToPrevious( bool bHeader, PageType eType ) +{ + if ( bHeader ) + { + switch ( eType ) + { + case PAGE_FIRST: m_bFirstPageHeaderLinkToPrevious = false; break; + case PAGE_LEFT: m_bEvenPageHeaderLinkToPrevious = false; break; + case PAGE_RIGHT: m_bDefaultHeaderLinkToPrevious = false; break; + // no default case as all enumeration values have been covered + } + } + else + { + switch ( eType ) + { + case PAGE_FIRST: m_bFirstPageFooterLinkToPrevious = false; break; + case PAGE_LEFT: m_bEvenPageFooterLinkToPrevious = false; break; + case PAGE_RIGHT: m_bDefaultFooterLinkToPrevious = false; break; + } + } +} + +namespace { + +class NamedPropertyValue +{ +private: + OUString m_aName; + +public: + explicit NamedPropertyValue( const OUString& i_aStr ) + : m_aName( i_aStr ) + { + } + + bool operator() ( beans::PropertyValue const & aVal ) + { + return aVal.Name == m_aName; + } +}; + +} + +void SectionPropertyMap::ApplyProperties_( const uno::Reference< beans::XPropertySet >& xStyle ) +{ + uno::Reference< beans::XMultiPropertySet > const xMultiSet( xStyle, uno::UNO_QUERY ); + + std::vector< OUString > vNames; + std::vector< uno::Any > vValues; + { + // Convert GetPropertyValues() value into something useful + uno::Sequence< beans::PropertyValue > vPropVals = GetPropertyValues(); + + //Temporarily store the items that are in grab bags + uno::Sequence< beans::PropertyValue > vCharVals; + uno::Sequence< beans::PropertyValue > vParaVals; + beans::PropertyValue* pCharGrabBag = std::find_if( vPropVals.begin(), vPropVals.end(), NamedPropertyValue( "CharInteropGrabBag" ) ); + if ( pCharGrabBag != vPropVals.end() ) + (pCharGrabBag->Value) >>= vCharVals; + beans::PropertyValue* pParaGrabBag = std::find_if( vPropVals.begin(), vPropVals.end(), NamedPropertyValue( "ParaInteropGrabBag" ) ); + if ( pParaGrabBag != vPropVals.end() ) + (pParaGrabBag->Value) >>= vParaVals; + + for ( beans::PropertyValue* pIter = vPropVals.begin(); pIter != vPropVals.end(); ++pIter ) + { + if ( pIter != pCharGrabBag && pIter != pParaGrabBag + && pIter->Name != "IsProtected" //section-only property + ) + { + vNames.push_back( pIter->Name ); + vValues.push_back( pIter->Value ); + } + } + for ( const beans::PropertyValue & v : std::as_const(vCharVals) ) + { + vNames.push_back( v.Name ); + vValues.push_back( v.Value ); + } + for ( const beans::PropertyValue & v : std::as_const(vParaVals) ) + { + vNames.push_back( v.Name ); + vValues.push_back( v.Value ); + } + } + if ( xMultiSet.is() ) + { + try + { + xMultiSet->setPropertyValues( comphelper::containerToSequence( vNames ), comphelper::containerToSequence( vValues ) ); + return; + } + catch ( const uno::Exception& ) + { + OSL_FAIL( "Exception in SectionPropertyMap::ApplyProperties_" ); + } + } + for ( size_t i = 0; i < vNames.size(); ++i ) + { + try + { + if ( xStyle.is() ) + xStyle->setPropertyValue( vNames[i], vValues[i] ); + } + catch ( const uno::Exception& ) + { + OSL_FAIL( "Exception in SectionPropertyMap::ApplyProperties_" ); + } + } +} + +sal_Int32 SectionPropertyMap::GetPageWidth() const +{ + return getProperty( PROP_WIDTH )->second.get(); +} + +StyleSheetPropertyMap::StyleSheetPropertyMap() + : mnListLevel( -1 ) + , mnOutlineLevel( -1 ) +{ +} + +ParagraphProperties::ParagraphProperties() + : m_bFrameMode( false ) + , m_nDropCap( NS_ooxml::LN_Value_doc_ST_DropCap_none ) + , m_nLines( 0 ) + , m_w( -1 ) + , m_h( -1 ) + , m_nWrap( text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE ) + , m_hAnchor( -1 ) + , m_vAnchor( -1 ) + , m_x( -1 ) + , m_bxValid( false ) + , m_y( -1 ) + , m_byValid( false ) + , m_hSpace( -1 ) + , m_vSpace( -1 ) + , m_hRule( -1 ) + , m_xAlign( -1 ) + , m_yAlign( -1 ) + , m_nDropCapLength( 0 ) +{ +} + +bool ParagraphProperties::operator==( const ParagraphProperties& rCompare ) +{ + return ( m_bFrameMode == rCompare.m_bFrameMode && + m_nDropCap == rCompare.m_nDropCap && + m_nLines == rCompare.m_nLines && + m_w == rCompare.m_w && + m_h == rCompare.m_h && + m_nWrap == rCompare.m_nWrap && + m_hAnchor == rCompare.m_hAnchor && + m_vAnchor == rCompare.m_vAnchor && + m_x == rCompare.m_x && + m_bxValid == rCompare.m_bxValid && + m_y == rCompare.m_y && + m_byValid == rCompare.m_byValid && + m_hSpace == rCompare.m_hSpace && + m_vSpace == rCompare.m_vSpace && + m_hRule == rCompare.m_hRule && + m_xAlign == rCompare.m_xAlign && + m_yAlign == rCompare.m_yAlign ); +} + +void ParagraphProperties::ResetFrameProperties() +{ + m_bFrameMode = false; + m_nDropCap = NS_ooxml::LN_Value_doc_ST_DropCap_none; + m_nLines = 0; + m_w = -1; + m_h = -1; + m_nWrap = text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE; + m_hAnchor = -1; + m_vAnchor = -1; + m_x = -1; + m_bxValid = false; + m_y = -1; + m_byValid = false; + m_hSpace = -1; + m_vSpace = -1; + m_hRule = -1; + m_xAlign = -1; + m_yAlign = -1; + m_nDropCapLength = 0; +} + +bool TablePropertyMap::getValue( TablePropertyMapTarget eWhich, sal_Int32& nFill ) +{ + if ( eWhich < TablePropertyMapTarget_MAX ) + { + if ( m_aValidValues[eWhich].bValid ) + nFill = m_aValidValues[eWhich].nValue; + return m_aValidValues[eWhich].bValid; + } + else + { + OSL_FAIL( "invalid TablePropertyMapTarget" ); + return false; + } +} + +void TablePropertyMap::setValue( TablePropertyMapTarget eWhich, sal_Int32 nSet ) +{ + if ( eWhich < TablePropertyMapTarget_MAX ) + { + m_aValidValues[eWhich].bValid = true; + m_aValidValues[eWhich].nValue = nSet; + } + else + OSL_FAIL( "invalid TablePropertyMapTarget" ); +} + +void TablePropertyMap::insertTableProperties( const PropertyMap* pMap, const bool bOverwrite ) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement( "TablePropertyMap.insertTableProperties" ); + pMap->dumpXml(); +#endif + + const TablePropertyMap* pSource = dynamic_cast< const TablePropertyMap* >(pMap); + if ( pSource ) + { + for ( sal_Int32 eTarget = TablePropertyMapTarget_START; + eTarget < TablePropertyMapTarget_MAX; ++eTarget ) + { + if ( pSource->m_aValidValues[eTarget].bValid && (bOverwrite || !m_aValidValues[eTarget].bValid) ) + { + m_aValidValues[eTarget].bValid = true; + m_aValidValues[eTarget].nValue = pSource->m_aValidValues[eTarget].nValue; + } + } + } + +#ifdef DBG_UTIL + dumpXml(); + TagLogger::getInstance().endElement(); +#endif +} + +} // namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx new file mode 100644 index 000000000..2408b3fc0 --- /dev/null +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -0,0 +1,607 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAP_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAP_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "PropertyIds.hxx" +#include +#include +#include +#include + +namespace com::sun::star { + namespace beans { + struct PropertyValue; + } + namespace container { + class XNameContainer; + } + namespace lang { + class XMultiServiceFactory; + } + namespace text { + class XTextRange; + class XTextColumns; + class XFootnote; + } + namespace table { + struct BorderLine2; + struct ShadowFormat; + } +} + +namespace writerfilter { +namespace dmapper { + +class DomainMapper_Impl; +struct FloatingTableInfo; +struct AnchoredObjectInfo; + +enum BorderPosition +{ + BORDER_LEFT, + BORDER_RIGHT, + BORDER_TOP, + BORDER_BOTTOM +}; + +enum GrabBagType +{ + NO_GRAB_BAG, + ROW_GRAB_BAG, + CELL_GRAB_BAG, + PARA_GRAB_BAG, + CHAR_GRAB_BAG +}; + +struct RedlineParams : public virtual SvRefBase +{ + OUString m_sAuthor; + OUString m_sDate; + sal_Int32 m_nToken; + + // This can hold properties of runs that had formatted 'track changes' properties + css::uno::Sequence< css::beans::PropertyValue > m_aRevertProperties; +}; + +typedef tools::SvRef< RedlineParams > RedlineParamsPtr; + +class PropValue +{ +private: + css::uno::Any m_aValue; + GrabBagType m_GrabBagType; + bool m_bIsDocDefault; + +public: + PropValue( const css::uno::Any& rValue, GrabBagType i_GrabBagType, bool bDocDefault ) + : m_aValue( rValue ) + , m_GrabBagType( i_GrabBagType ) + , m_bIsDocDefault( bDocDefault ) + { + } + + PropValue( const css::uno::Any& rValue, GrabBagType i_GrabBagType ) + : m_aValue( rValue ) + , m_GrabBagType( i_GrabBagType ) + , m_bIsDocDefault( false ) + { + } + + PropValue() + : m_aValue() + , m_GrabBagType( NO_GRAB_BAG ) + , m_bIsDocDefault( false ) + { + } + + const css::uno::Any& getValue() const { return m_aValue; } + + GrabBagType getGrabBagType() const { return m_GrabBagType; } + + bool getIsDocDefault() const { return m_bIsDocDefault; } +}; + +class PropertyMap; +typedef tools::SvRef< PropertyMap > PropertyMapPtr; + +class PropertyMap : public virtual SvRefBase +{ +private: + // Cache the property values for the GetPropertyValues() call(s). + std::vector< css::beans::PropertyValue > m_aValues; + + // marks context as footnote context - ::text( ) events contain either the footnote character or can be ignored + // depending on sprmCSymbol + css::uno::Reference< css::text::XFootnote > m_xFootnote; + OUString m_sFootnoteCharStyleName; + std::map< PropertyIds, PropValue > m_vMap; + std::vector< RedlineParamsPtr > m_aRedlines; + +public: + typedef std::pair< PropertyIds, css::uno::Any > Property; + + PropertyMap() {} + + // Sequence: Grab Bags: The CHAR_GRAB_BAG has Name "CharInteropGrabBag" and the PARA_GRAB_BAG has Name "ParaInteropGrabBag" + // the contained properties are their Value. + css::uno::Sequence< css::beans::PropertyValue > GetPropertyValues( bool bCharGrabBag = true ); + + std::vector< PropertyIds > GetPropertyIds(); + + // Add property, optionally overwriting existing attributes + void Insert( PropertyIds eId, const css::uno::Any& rAny, bool bOverwrite = true, GrabBagType i_GrabBagType = NO_GRAB_BAG, bool bDocDefault = false ); + + // Remove a named property from *this, does nothing if the property id has not been set + void Erase( PropertyIds eId); + + // Imports properties from pMap (bOverwrite==false means m_bIsDocDefault=true setting) + void InsertProps( const PropertyMapPtr& rMap, const bool bOverwrite = true ); + + // Returns a copy of the property if it exists, .first is its PropertyIds and .second is its Value (type css::uno::Any) + std::optional< Property > getProperty( PropertyIds eId ) const; + + // Has the property named been set (via Insert)? + bool isSet( PropertyIds eId ) const; + bool isDocDefault( PropertyIds eId ) const; + + const css::uno::Reference< css::text::XFootnote >& GetFootnote() const { return m_xFootnote; } + const OUString& GetFootnoteStyle() const { return m_sFootnoteCharStyleName; } + + void SetFootnote(const css::uno::Reference< css::text::XFootnote >& xFootnote, const OUString& sStyleName) + { + m_xFootnote = xFootnote; + m_sFootnoteCharStyleName = sStyleName; + } + + virtual void insertTableProperties( const PropertyMap*, const bool bOverwrite = true ); + + const std::vector< RedlineParamsPtr >& Redlines() const { return m_aRedlines; } + + std::vector< RedlineParamsPtr >& Redlines() { return m_aRedlines; } + + void printProperties(); + +#ifdef DBG_UTIL + void dumpXml() const; +#endif + + static css::table::ShadowFormat getShadowFromBorder( const css::table::BorderLine2& rBorder ); + +protected: + void Invalidate() + { + if ( m_aValues.size() ) + m_aValues.clear(); + } +}; + +class SectionPropertyMap : public PropertyMap +{ +public: + enum class BorderApply + { + ToAllInSection = 0, + ToFirstPageInSection = 1, + ToAllButFirstInSection = 2 + }; + enum class BorderOffsetFrom + { + Text = 0, + Edge = 1, + }; +private: +#ifdef DBG_UTIL + sal_Int32 m_nDebugSectionNumber; +#endif + + // 'temporarily' the section page settings are imported as page styles + // empty strings mark page settings as not yet imported + + bool m_bIsFirstSection; + css::uno::Reference< css::text::XTextRange > m_xStartingRange; + + OUString m_sFirstPageStyleName; + OUString m_sFollowPageStyleName; + css::uno::Reference< css::beans::XPropertySet > m_aFirstPageStyle; + css::uno::Reference< css::beans::XPropertySet > m_aFollowPageStyle; + + std::optional< css::table::BorderLine2 > m_oBorderLines[4]; + sal_Int32 m_nBorderDistances[4]; + BorderApply m_eBorderApply; + BorderOffsetFrom m_eBorderOffsetFrom; + bool m_bBorderShadows[4]; + + bool m_bTitlePage; + sal_Int16 m_nColumnCount; + sal_Int32 m_nColumnDistance; + css::uno::Reference< css::beans::XPropertySet > m_xColumnContainer; + std::vector< sal_Int32 > m_aColWidth; + std::vector< sal_Int32 > m_aColDistance; + + bool m_bSeparatorLineIsOn; + bool m_bEvenlySpaced; + + sal_Int32 m_nPageNumber; + // Page number type is a value from css::style::NumberingType. + sal_Int16 m_nPageNumberType; + sal_Int32 m_nBreakType; + + sal_Int32 m_nLeftMargin; + sal_Int32 m_nRightMargin; + sal_Int32 m_nTopMargin; + sal_Int32 m_nBottomMargin; + sal_Int32 m_nHeaderTop; + sal_Int32 m_nHeaderBottom; + + sal_Int32 m_nGridType; + sal_Int32 m_nGridLinePitch; + sal_Int32 m_nDxtCharSpace; + bool m_bGridSnapToChars; + + // line numbering + sal_Int32 m_nLnnMod; + sal_uInt32 m_nLnc; + sal_Int32 m_ndxaLnn; + sal_Int32 m_nLnnMin; + + std::vector> m_xRelativeWidthShapes; + + // The "Link To Previous" flag indicates whether the header/footer + // content should be taken from the previous section + bool m_bDefaultHeaderLinkToPrevious; + bool m_bEvenPageHeaderLinkToPrevious; + bool m_bFirstPageHeaderLinkToPrevious; + bool m_bDefaultFooterLinkToPrevious; + bool m_bEvenPageFooterLinkToPrevious; + bool m_bFirstPageFooterLinkToPrevious; + + void ApplyProperties_( const css::uno::Reference< css::beans::XPropertySet >& xStyle ); + + void DontBalanceTextColumns(); + + /// Apply section-specific properties: only valid to use after PageStyle has been determined by InheritOrFinalizePageStyles + void ApplySectionProperties( const css::uno::Reference< css::beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl ); + + /// Check if document is protected. If so, ensure a section exists, and apply its protected value. + void ApplyProtectionProperties( css::uno::Reference< css::beans::XPropertySet >& xSection, DomainMapper_Impl& rDM_Impl ); + + css::uno::Reference< css::text::XTextColumns > ApplyColumnProperties( const css::uno::Reference< css::beans::XPropertySet >& xFollowPageStyle, + DomainMapper_Impl& rDM_Impl); + + void CopyLastHeaderFooter( bool bFirstPage, DomainMapper_Impl& rDM_Impl ); + + static void CopyHeaderFooter( const css::uno::Reference< css::beans::XPropertySet >& xPrevStyle, + const css::uno::Reference< css::beans::XPropertySet >& xStyle, + bool bOmitRightHeader = false, bool bOmitLeftHeader = false, + bool bOmitRightFooter = false, bool bOmitLeftFooter = false ); + + static void CopyHeaderFooterTextProperty( const css::uno::Reference< css::beans::XPropertySet >& xPrevStyle, + const css::uno::Reference< css::beans::XPropertySet >& xStyle, + PropertyIds ePropId ); + + void PrepareHeaderFooterProperties( bool bFirstPage ); + + bool HasHeader( bool bFirstPage ) const; + bool HasFooter( bool bFirstPage ) const; + + static void SetBorderDistance( const css::uno::Reference< css::beans::XPropertySet >& xStyle, + PropertyIds eMarginId, + PropertyIds eDistId, + sal_Int32 nDistance, + BorderOffsetFrom eOffsetFrom, + sal_uInt32 nLineWidth ); + + // Determines if conversion of a given floating table is wanted or not. + bool FloatingTableConversion( const DomainMapper_Impl& rDM_Impl, FloatingTableInfo& rInfo ); + + /// Increases paragraph spacing according to Word 2013+ needs if necessary. + void HandleIncreasedAnchoredObjectSpacing(DomainMapper_Impl& rDM_Impl); + +public: + enum PageType + { + PAGE_FIRST, + PAGE_LEFT, + PAGE_RIGHT + }; + + explicit SectionPropertyMap( bool bIsFirstSection ); + + bool IsFirstSection() const { return m_bIsFirstSection; } + + void SetStart( const css::uno::Reference< css::text::XTextRange >& xRange ) { m_xStartingRange = xRange; } + + const css::uno::Reference< css::text::XTextRange >& GetStartingRange() const { return m_xStartingRange; } + + css::uno::Reference< css::beans::XPropertySet > GetPageStyle( DomainMapper_Impl& rDM_Impl, bool bFirst ); + + const OUString& GetPageStyleName( bool bFirstPage = false ) + { + return bFirstPage ? m_sFirstPageStyleName : m_sFollowPageStyleName; + } + + // @throws css::beans::UnknownPropertyException + // @throws css::beans::PropertyVetoException + // @throws css::lang::IllegalArgumentException + // @throws css::lang::WrappedTargetException + // @throws css::uno::RuntimeException + void InheritOrFinalizePageStyles( DomainMapper_Impl& rDM_Impl ); + + void SetBorder( BorderPosition ePos, sal_Int32 nLineDistance, const css::table::BorderLine2& rBorderLine, bool bShadow ); + void SetBorderApply( BorderApply nSet ) { m_eBorderApply = nSet; } + void SetBorderOffsetFrom( BorderOffsetFrom nSet ) { m_eBorderOffsetFrom = nSet; } + + void SetColumnCount( sal_Int16 nCount ) { m_nColumnCount = nCount; } + sal_Int16 ColumnCount() const { return m_nColumnCount; } + + void SetColumnDistance( sal_Int32 nDist ) { m_nColumnDistance = nDist; } + void AppendColumnWidth( sal_Int32 nWidth ) { m_aColWidth.push_back( nWidth ); } + void AppendColumnSpacing( sal_Int32 nDist ) { m_aColDistance.push_back( nDist ); } + + void SetTitlePage( bool bSet ) { m_bTitlePage = bSet; } + void SetSeparatorLine( bool bSet ) { m_bSeparatorLineIsOn = bSet; } + void SetEvenlySpaced( bool bSet ) { m_bEvenlySpaced = bSet; } + void SetPageNumber( sal_Int32 nSet ) { m_nPageNumber = nSet; } + void SetPageNumberType( sal_Int32 nSet ) { m_nPageNumberType = nSet; } + void SetBreakType( sal_Int32 nSet ) { m_nBreakType = nSet; } + // GetBreakType returns -1 if the breakType has not yet been identified for the section + sal_Int32 GetBreakType() const { return m_nBreakType; } + + void SetLeftMargin( sal_Int32 nSet ) { m_nLeftMargin = nSet; } + sal_Int32 GetLeftMargin() const { return m_nLeftMargin; } + void SetRightMargin( sal_Int32 nSet ) { m_nRightMargin = nSet; } + sal_Int32 GetRightMargin() const { return m_nRightMargin; } + void SetTopMargin( sal_Int32 nSet ) { m_nTopMargin = nSet; } + void SetBottomMargin( sal_Int32 nSet ) { m_nBottomMargin = nSet; } + void SetHeaderTop( sal_Int32 nSet ) { m_nHeaderTop = nSet; } + void SetHeaderBottom( sal_Int32 nSet ) { m_nHeaderBottom = nSet; } + sal_Int32 GetPageWidth() const; + + void SetGridType( sal_Int32 nSet ) { m_nGridType = nSet; } + void SetGridLinePitch( sal_Int32 nSet ) { m_nGridLinePitch = nSet; } + void SetGridSnapToChars( bool bSet ) { m_bGridSnapToChars = bSet; } + void SetDxtCharSpace( sal_Int32 nSet ) { m_nDxtCharSpace = nSet; } + + void SetLnnMod( sal_Int32 nValue ) { m_nLnnMod = nValue; } + void SetLnc( sal_Int32 nValue ) { m_nLnc = nValue; } + void SetdxaLnn( sal_Int32 nValue ) { m_ndxaLnn = nValue; } + void SetLnnMin( sal_Int32 nValue ) { m_nLnnMin = nValue; } + + void addRelativeWidthShape( css::uno::Reference xShape ) { m_xRelativeWidthShapes.push_back( xShape ); } + + // determine which style gets the borders + void ApplyBorderToPageStyles( DomainMapper_Impl &rDM_Impl, + BorderApply eBorderApply, BorderOffsetFrom eOffsetFrom ); + + void CloseSectionGroup( DomainMapper_Impl& rDM_Impl ); + // Handling of margins, header and footer for any kind of sections breaks. + void HandleMarginsHeaderFooter( bool bFirstPage, DomainMapper_Impl& rDM_Impl ); + void ClearHeaderFooterLinkToPrevious( bool bHeader, PageType eType ); +}; + +class ParagraphProperties : public virtual SvRefBase +{ +private: + bool m_bFrameMode; + sal_Int32 m_nDropCap; // drop, margin ST_DropCap + sal_Int32 m_nLines; // number of lines of the drop cap + sal_Int32 m_w; // width + sal_Int32 m_h; // height + css::text::WrapTextMode m_nWrap; // from ST_Wrap around, auto, none, notBeside, through, tight + sal_Int32 m_hAnchor; // page, from ST_HAnchor margin, page, text + sal_Int32 m_vAnchor; // around from ST_VAnchor margin, page, text + sal_Int32 m_x; // x-position + bool m_bxValid; + sal_Int32 m_y; // y-position + bool m_byValid; + sal_Int32 m_hSpace; // frame padding h + sal_Int32 m_vSpace; // frame padding v + sal_Int32 m_hRule; // from ST_HeightRule exact, atLeast, auto + sal_Int32 m_xAlign; // from ST_XAlign center, inside, left, outside, right + sal_Int32 m_yAlign; // from ST_YAlign bottom, center, inline, inside, outside, top + sal_Int8 m_nDropCapLength; // number of characters + OUString m_sParaStyleName; + + css::uno::Reference< css::text::XTextRange > m_xStartingRange; // start of a frame + css::uno::Reference< css::text::XTextRange > m_xEndingRange; // end of the frame + sal_Int32 m_nListId = -1; + +public: + ParagraphProperties(); + + ParagraphProperties(ParagraphProperties const &) = default; + ParagraphProperties(ParagraphProperties &&) = default; + ParagraphProperties & operator =(ParagraphProperties const &) = default; + ParagraphProperties & operator =(ParagraphProperties &&) = default; + + // Does not compare the starting/ending range, m_sParaStyleName and m_nDropCapLength + bool operator==( const ParagraphProperties& ); + + sal_Int32 GetListId() const { return m_nListId; } + void SetListId( sal_Int32 nId ) { m_nListId = nId; } + + bool IsFrameMode() const { return m_bFrameMode; } + void SetFrameMode( bool set = true ) { m_bFrameMode = set; } + + sal_Int32 GetDropCap() const { return m_nDropCap; } + void SetDropCap( sal_Int32 nSet ) { m_nDropCap = nSet; } + + sal_Int32 GetLines() const { return m_nLines; } + void SetLines( sal_Int32 nSet ) { m_nLines = nSet; } + + sal_Int32 Getw() const { return m_w; } + void Setw( sal_Int32 nSet ) { m_w = nSet; } + + sal_Int32 Geth() const { return m_h; } + void Seth( sal_Int32 nSet ) { m_h = nSet; } + + css::text::WrapTextMode GetWrap() const { return m_nWrap; } + void SetWrap( css::text::WrapTextMode nSet ) { m_nWrap = nSet; } + + sal_Int32 GethAnchor() const { return m_hAnchor; } + void SethAnchor( sal_Int32 nSet ) { m_hAnchor = nSet; } + + sal_Int32 GetvAnchor() const { return m_vAnchor; } + void SetvAnchor( sal_Int32 nSet ) { m_vAnchor = nSet; } + + sal_Int32 Getx() const { return m_x; } + void Setx( sal_Int32 nSet ) { m_x = nSet; m_bxValid = true; } + bool IsxValid() const { return m_bxValid; } + + sal_Int32 Gety() const { return m_y; } + void Sety( sal_Int32 nSet ) { m_y = nSet; m_byValid = true; } + bool IsyValid() const { return m_byValid; } + + void SethSpace( sal_Int32 nSet ) { m_hSpace = nSet; } + sal_Int32 GethSpace() const { return m_hSpace; } + + sal_Int32 GetvSpace() const { return m_vSpace; } + void SetvSpace( sal_Int32 nSet ) { m_vSpace = nSet; } + + sal_Int32 GethRule() const { return m_hRule; } + void SethRule( sal_Int32 nSet ) { m_hRule = nSet; } + + sal_Int32 GetxAlign() const { return m_xAlign; } + void SetxAlign( sal_Int32 nSet ) { m_xAlign = nSet; } + + sal_Int32 GetyAlign() const { return m_yAlign; } + void SetyAlign( sal_Int32 nSet ) { m_yAlign = nSet; } + + sal_Int8 GetDropCapLength() const { return m_nDropCapLength; } + void SetDropCapLength( sal_Int8 nSet ) { m_nDropCapLength = nSet; } + + const css::uno::Reference< css::text::XTextRange >& GetStartingRange() const { return m_xStartingRange; } + void SetStartingRange( const css::uno::Reference< css::text::XTextRange >& xSet ) { m_xStartingRange = xSet; } + + const css::uno::Reference< css::text::XTextRange >& GetEndingRange() const { return m_xEndingRange; } + void SetEndingRange( const css::uno::Reference< css::text::XTextRange >& xSet ) { m_xEndingRange = xSet; } + + const OUString& GetParaStyleName() const { return m_sParaStyleName; } + void SetParaStyleName( const OUString& rSet ) { m_sParaStyleName = rSet; } + + void ResetFrameProperties(); +}; + +typedef tools::SvRef< ParagraphProperties > ParagraphPropertiesPtr; + +/*------------------------------------------------------------------------- + property map of a stylesheet + -----------------------------------------------------------------------*/ + +#define WW_OUTLINE_MAX sal_Int16( 9 ) +#define WW_OUTLINE_MIN sal_Int16( 0 ) + +class StyleSheetPropertyMap + : public PropertyMap + , public ParagraphProperties +{ +private: + sal_Int16 mnListLevel; + sal_Int16 mnOutlineLevel; + +public: + explicit StyleSheetPropertyMap(); + + sal_Int16 GetListLevel() const { return mnListLevel; } + void SetListLevel( sal_Int16 nLevel ) { mnListLevel = nLevel; } + + sal_Int16 GetOutlineLevel() const { return mnOutlineLevel; } + void SetOutlineLevel( sal_Int16 nLevel ) { if ( nLevel < WW_OUTLINE_MAX ) mnOutlineLevel = nLevel; } +}; + +class ParagraphPropertyMap + : public PropertyMap + , public ParagraphProperties +{ +public: + explicit ParagraphPropertyMap() {} +}; + +class TablePropertyMap + : public PropertyMap +{ +public: + enum TablePropertyMapTarget + { + TablePropertyMapTarget_START, + CELL_MAR_LEFT = TablePropertyMapTarget_START, + CELL_MAR_RIGHT, + CELL_MAR_TOP, + CELL_MAR_BOTTOM, + TABLE_WIDTH, + TABLE_WIDTH_TYPE, + GAP_HALF, + LEFT_MARGIN, + HORI_ORIENT, + TablePropertyMapTarget_MAX + }; + +private: + struct ValidValue + { + sal_Int32 nValue; + bool bValid; + + ValidValue() + : nValue( 0 ) + , bValid( false ) + { + } + }; + + ValidValue m_aValidValues[TablePropertyMapTarget_MAX]; + +public: + explicit TablePropertyMap() {} + + bool getValue( TablePropertyMapTarget eWhich, sal_Int32& nFill ); + void setValue( TablePropertyMapTarget eWhich, sal_Int32 nSet ); + + virtual void insertTableProperties( const PropertyMap*, const bool bOverwrite = true ) override; +}; + +typedef tools::SvRef< TablePropertyMap > TablePropertyMapPtr; + +/// Information about a paragraph to be finished after a table end. +struct TableParagraph +{ + css::uno::Reference m_rStartParagraph; + css::uno::Reference m_rEndParagraph; + PropertyMapPtr m_pPropertyMap; + css::uno::Reference m_rPropertySet; +}; + +typedef std::shared_ptr< std::vector > TableParagraphVectorPtr; + +} // namespace dmapper +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAP_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyMapHelper.cxx b/writerfilter/source/dmapper/PropertyMapHelper.cxx new file mode 100644 index 000000000..59f59b1b2 --- /dev/null +++ b/writerfilter/source/dmapper/PropertyMapHelper.cxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "TagLogger.hxx" +#include "PropertyMapHelper.hxx" + +namespace writerfilter::dmapper +{ + +using namespace ::com::sun::star; + +void lcl_DumpTableColumnSeparators(const uno::Any & rTableColumnSeparators) +{ +#ifdef DBG_UTIL + uno::Sequence aSeq; + rTableColumnSeparators >>= aSeq; + + TagLogger::getInstance().startElement("property.TableColumnSeparators"); + + sal_uInt32 nLength = aSeq.getLength(); + for (sal_uInt32 n = 0; n < nLength; ++n) + { + TagLogger::getInstance().startElement("separator"); + + TagLogger::getInstance().attribute("position", aSeq[n].Position); + TagLogger::getInstance().attribute("visible", sal_uInt32(aSeq[n].IsVisible)); + + TagLogger::getInstance().endElement(); + } + + TagLogger::getInstance().endElement(); +#else + (void) rTableColumnSeparators; +#endif // DBG_UTIL +} + +#ifdef DBG_UTIL +void lcl_DumpPropertyValues(beans::PropertyValues const & rValues) +{ + TagLogger::getInstance().startElement("propertyValues"); + + for (beans::PropertyValue const & propVal : rValues) + { + TagLogger::getInstance().startElement("propertyValue"); + + TagLogger::getInstance().attribute("name", propVal.Name); + + try + { + sal_Int32 aInt = 0; + propVal.Value >>= aInt; + TagLogger::getInstance().attribute("value", aInt); + } + catch (...) + { + } + + if ( propVal.Name == "TableColumnSeparators" ) + { + lcl_DumpTableColumnSeparators(propVal.Value); + } + + TagLogger::getInstance().endElement(); + } + TagLogger::getInstance().endElement(); +} + +void lcl_DumpPropertyValueSeq(css::uno::Sequence const & rPropValSeq) +{ + TagLogger::getInstance().startElement("PropertyValueSeq"); + + for (auto const & propVal : rPropValSeq) + { + lcl_DumpPropertyValues(propVal); + } + + TagLogger::getInstance().endElement(); +} +#endif // DBG_UTIL + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyMapHelper.hxx b/writerfilter/source/dmapper/PropertyMapHelper.hxx new file mode 100644 index 000000000..4b7bee2d7 --- /dev/null +++ b/writerfilter/source/dmapper/PropertyMapHelper.hxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAPHELPER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAPHELPER_HXX + +#include + +namespace writerfilter +{ +namespace dmapper +{ + +void lcl_DumpTableColumnSeparators(const css::uno::Any & rTableColumnSeparators); +#ifdef DBG_UTIL +void lcl_DumpPropertyValues(css::beans::PropertyValues const & rValues); + +void lcl_DumpPropertyValueSeq(css::uno::Sequence const & rPropValSeq); +#endif // DBG_UTIL +} +} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_PROPERTYMAPHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx new file mode 100644 index 000000000..60153d4c6 --- /dev/null +++ b/writerfilter/source/dmapper/SdtHelper.cxx @@ -0,0 +1,253 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "SdtHelper.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "DomainMapper_Impl.hxx" +#include "StyleSheetTable.hxx" +#include + +namespace writerfilter::dmapper +{ +using namespace ::com::sun::star; + +/// w:sdt's w:dropDownList doesn't have width, so guess the size based on the longest string. +static awt::Size lcl_getOptimalWidth(const StyleSheetTablePtr& pStyleSheet, + OUString const& rDefault, std::vector& rItems) +{ + OUString aLongest = rDefault; + sal_Int32 nHeight = 0; + for (const OUString& rItem : rItems) + if (rItem.getLength() > aLongest.getLength()) + aLongest = rItem; + + MapMode aMap(MapUnit::Map100thMM); + OutputDevice* pOut = Application::GetDefaultDevice(); + pOut->Push(PushFlags::FONT | PushFlags::MAPMODE); + + PropertyMapPtr pDefaultCharProps = pStyleSheet->GetDefaultCharProps(); + vcl::Font aFont(pOut->GetFont()); + std::optional aFontName + = pDefaultCharProps->getProperty(PROP_CHAR_FONT_NAME); + if (aFontName) + aFont.SetFamilyName(aFontName->second.get()); + std::optional aHeight = pDefaultCharProps->getProperty(PROP_CHAR_HEIGHT); + if (aHeight) + { + nHeight = aHeight->second.get() * 35; // points -> mm100 + aFont.SetFontSize(Size(0, nHeight)); + } + pOut->SetFont(aFont); + pOut->SetMapMode(aMap); + sal_Int32 nWidth = pOut->GetTextWidth(aLongest); + + pOut->Pop(); + + // Border: see PDFWriterImpl::drawFieldBorder(), border size is font height / 4, + // so additional width / height needed is height / 2. + sal_Int32 nBorder = nHeight / 2; + + // Width: space for the text + the square having the dropdown arrow. + return { nWidth + nBorder + nHeight, nHeight + nBorder }; +} + +SdtHelper::SdtHelper(DomainMapper_Impl& rDM_Impl) + : m_rDM_Impl(rDM_Impl) + , m_bInsideDropDownControl(false) + , m_bHasElements(false) + , m_bOutsideAParagraph(false) +{ +} + +SdtHelper::~SdtHelper() = default; + +void SdtHelper::createDropDownControl() +{ + assert(m_bInsideDropDownControl); + + const bool bDropDown + = officecfg::Office::Writer::Filter::Import::DOCX::ImportComboBoxAsDropDown::get(); + const OUString aDefaultText = m_aSdtTexts.makeStringAndClear(); + + if (bDropDown) + { + // create field + uno::Reference xControlModel( + m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.text.TextField.DropDown"), + uno::UNO_QUERY); + + const auto it = std::find_if( + m_aDropDownItems.begin(), m_aDropDownItems.end(), + [aDefaultText](const OUString& item) -> bool { return !item.compareTo(aDefaultText); }); + + if (m_aDropDownItems.end() == it) + { + m_aDropDownItems.push_back(aDefaultText); + } + + // set properties + uno::Reference xPropertySet(xControlModel, uno::UNO_QUERY); + xPropertySet->setPropertyValue("SelectedItem", uno::makeAny(aDefaultText)); + xPropertySet->setPropertyValue( + "Items", uno::makeAny(comphelper::containerToSequence(m_aDropDownItems))); + + // add it into document + m_rDM_Impl.appendTextContent(xControlModel, uno::Sequence()); + + m_bHasElements = true; + } + else + { + // create control + uno::Reference xControlModel( + m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.form.component.ComboBox"), + uno::UNO_QUERY); + + // set properties + uno::Reference xPropertySet(xControlModel, uno::UNO_QUERY); + xPropertySet->setPropertyValue("DefaultText", uno::makeAny(aDefaultText)); + xPropertySet->setPropertyValue("Dropdown", uno::makeAny(true)); + xPropertySet->setPropertyValue( + "StringItemList", uno::makeAny(comphelper::containerToSequence(m_aDropDownItems))); + + // add it into document + createControlShape( + lcl_getOptimalWidth(m_rDM_Impl.GetStyleSheetTable(), aDefaultText, m_aDropDownItems), + xControlModel, uno::Sequence()); + } + + // clean up + m_aDropDownItems.clear(); + m_bInsideDropDownControl = false; +} + +bool SdtHelper::validateDateFormat() +{ + return !m_sDateFormat.toString().isEmpty() && !m_sLocale.toString().isEmpty(); +} + +void SdtHelper::createDateContentControl() +{ + if (!m_xDateFieldStartRange.is()) + return; + + uno::Reference xCrsr; + if (m_rDM_Impl.HasTopText()) + { + uno::Reference xTextAppend = m_rDM_Impl.GetTopTextAppend(); + if (xTextAppend.is()) + { + xCrsr = xTextAppend->createTextCursorByRange(xTextAppend); + } + } + if (xCrsr.is()) + { + try + { + xCrsr->gotoRange(m_xDateFieldStartRange, false); + bool bIsInTable + = (m_rDM_Impl.hasTableManager() && m_rDM_Impl.getTableManager().isInTable()) + || (m_rDM_Impl.m_nTableDepth > 0); + if (bIsInTable) + xCrsr->goRight(1, false); + xCrsr->gotoEnd(true); + } + catch (uno::Exception&) + { + OSL_ENSURE(false, "Cannot get the right text range for date field"); + return; + } + + uno::Reference xFieldInterface + = m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.text.Fieldmark"); + uno::Reference xFormField(xFieldInterface, uno::UNO_QUERY); + uno::Reference xToInsert(xFormField, uno::UNO_QUERY); + if (xFormField.is() && xToInsert.is()) + { + xToInsert->attach(uno::Reference(xCrsr, uno::UNO_QUERY_THROW)); + xFormField->setFieldType(ODF_FORMDATE); + uno::Reference xNameCont = xFormField->getParameters(); + if (xNameCont.is()) + { + OUString sDateFormat = m_sDateFormat.makeStringAndClear(); + // Replace quotation mark used for marking static strings in date format + sDateFormat = sDateFormat.replaceAll("'", "\""); + xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT, uno::makeAny(sDateFormat)); + xNameCont->insertByName(ODF_FORMDATE_DATEFORMAT_LANGUAGE, + uno::makeAny(m_sLocale.makeStringAndClear())); + } + OUString sFullDate = m_sDate.makeStringAndClear(); + if (!sFullDate.isEmpty()) + { + sal_Int32 nTimeSep = sFullDate.indexOf("T"); + if (nTimeSep != -1) + sFullDate = sFullDate.copy(0, nTimeSep); + xNameCont->insertByName(ODF_FORMDATE_CURRENTDATE, uno::makeAny(sFullDate)); + } + } + } +} + +void SdtHelper::createControlShape(awt::Size aSize, + uno::Reference const& xControlModel, + const uno::Sequence& rGrabBag) +{ + uno::Reference xControlShape( + m_rDM_Impl.GetTextFactory()->createInstance("com.sun.star.drawing.ControlShape"), + uno::UNO_QUERY); + xControlShape->setSize(aSize); + xControlShape->setControl(xControlModel); + + uno::Reference xPropertySet(xControlShape, uno::UNO_QUERY); + xPropertySet->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::CENTER)); + + if (rGrabBag.hasElements()) + xPropertySet->setPropertyValue(UNO_NAME_MISC_OBJ_INTEROPGRABBAG, uno::makeAny(rGrabBag)); + + uno::Reference xTextContent(xControlShape, uno::UNO_QUERY); + m_rDM_Impl.appendTextContent(xTextContent, uno::Sequence()); + m_bHasElements = true; +} + +void SdtHelper::appendToInteropGrabBag(const beans::PropertyValue& rValue) +{ + m_aGrabBag.push_back(rValue); +} + +uno::Sequence SdtHelper::getInteropGrabBagAndClear() +{ + uno::Sequence aRet = comphelper::containerToSequence(m_aGrabBag); + m_aGrabBag.clear(); + return aRet; +} + +bool SdtHelper::isInteropGrabBagEmpty() const { return m_aGrabBag.empty(); } + +sal_Int32 SdtHelper::getInteropGrabBagSize() const { return m_aGrabBag.size(); } + +bool SdtHelper::containedInInteropGrabBag(const OUString& rValueName) +{ + for (const beans::PropertyValue& i : m_aGrabBag) + if (i.Name == rValueName) + return true; + + return false; +} + +} // namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx new file mode 100644 index 000000000..3cce8e365 --- /dev/null +++ b/writerfilter/source/dmapper/SdtHelper.hxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SDTHELPER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SDTHELPER_HXX + +#include + +#include +#include + +#include +#include + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace awt +{ +struct Size; +class XControlModel; +} +} +} +} + +namespace writerfilter +{ +namespace dmapper +{ +class DomainMapper_Impl; + +/** + * Helper to create form controls from w:sdt tokens. + * + * w:sdt tokens can't be imported as form fields, as w:sdt supports + * e.g. date picking as well. + */ +class SdtHelper final : public virtual SvRefBase +{ + DomainMapper_Impl& m_rDM_Impl; + + /// Items of the drop-down control. + std::vector m_aDropDownItems; + /// Indicator of a drop-down control + bool m_bInsideDropDownControl; + /// Pieces of the default text -- currently used only by the dropdown control. + OUStringBuffer m_aSdtTexts; + /// Date ISO string contained in the w:date element, used by the date control. + OUStringBuffer m_sDate; + /// Date format string as it comes from the ooxml document. + OUStringBuffer m_sDateFormat; + /// Start range of the date field + css::uno::Reference m_xDateFieldStartRange; + /// Locale string as it comes from the ooxml document. + OUStringBuffer m_sLocale; + /// Grab bag to store unsupported SDTs, aiming to save them back on export. + std::vector m_aGrabBag; + + bool m_bHasElements; + /// The last stored SDT element is outside paragraphs. + bool m_bOutsideAParagraph; + + /// Create and append the drawing::XControlShape, containing the various models. + void createControlShape(css::awt::Size aSize, + css::uno::Reference const& xControlModel, + const css::uno::Sequence& rGrabBag); + +public: + explicit SdtHelper(DomainMapper_Impl& rDM_Impl); + ~SdtHelper() override; + + std::vector& getDropDownItems() { return m_aDropDownItems; } + OUStringBuffer& getSdtTexts() { return m_aSdtTexts; } + + OUStringBuffer& getDate() { return m_sDate; } + + OUStringBuffer& getDateFormat() { return m_sDateFormat; } + + void setDateFieldStartRange(const css::uno::Reference& xStartRange) + { + m_xDateFieldStartRange = xStartRange; + } + + /// Decides if we have enough information to create a date control. + bool validateDateFormat(); + + OUStringBuffer& getLocale() { return m_sLocale; } + /// If createControlShape() was ever called. + bool hasElements() const { return m_bHasElements; } + + void setOutsideAParagraph(bool bOutsideAParagraph) + { + m_bOutsideAParagraph = bOutsideAParagraph; + } + + bool isOutsideAParagraph() const { return m_bOutsideAParagraph; } + + bool isInsideDropDownControl() const { return m_bInsideDropDownControl; } + void setInsideDropDownControl(bool bInside) { m_bInsideDropDownControl = bInside; } + + /// Create drop-down control from w:sdt's w:dropDownList. + void createDropDownControl(); + /// Create date control from w:sdt's w:date. + void createDateContentControl(); + + void appendToInteropGrabBag(const css::beans::PropertyValue& rValue); + css::uno::Sequence getInteropGrabBagAndClear(); + bool isInteropGrabBagEmpty() const; + bool containedInInteropGrabBag(const OUString& rValueName); + sal_Int32 getInteropGrabBagSize() const; +}; + +} // namespace dmapper +} // namespace writerfilter + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SectionColumnHandler.cxx b/writerfilter/source/dmapper/SectionColumnHandler.cxx new file mode 100644 index 000000000..9ce0cdc85 --- /dev/null +++ b/writerfilter/source/dmapper/SectionColumnHandler.cxx @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "SectionColumnHandler.hxx" +#include "ConversionHelper.hxx" +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + + +SectionColumnHandler::SectionColumnHandler() + : LoggedProperties("SectionColumnHandler") + , m_bEqualWidth(false) + , m_nSpace(1270) // 720 twips + , m_nNum(0) + , m_bSep(false) +{ + m_aTempColumn.nWidth = m_aTempColumn.nSpace = 0; +} + +SectionColumnHandler::~SectionColumnHandler() +{ +} + +void SectionColumnHandler::lcl_attribute(Id rName, Value & rVal) +{ + sal_Int32 nIntValue = rVal.getInt(); + switch( rName ) + { + case NS_ooxml::LN_CT_Columns_equalWidth: + m_bEqualWidth = (nIntValue != 0); + break; + case NS_ooxml::LN_CT_Columns_space: + m_nSpace = ConversionHelper::convertTwipToMM100( nIntValue ); + break; + case NS_ooxml::LN_CT_Columns_num: + m_nNum = nIntValue; + break; + case NS_ooxml::LN_CT_Columns_sep: + m_bSep = (nIntValue != 0); + break; + + case NS_ooxml::LN_CT_Column_w: + m_aTempColumn.nWidth = ConversionHelper::convertTwipToMM100( nIntValue ); + break; + case NS_ooxml::LN_CT_Column_space: + m_aTempColumn.nSpace = ConversionHelper::convertTwipToMM100( nIntValue ); + break; + default: + OSL_FAIL( "SectionColumnHandler: unknown attribute"); + } +} + +void SectionColumnHandler::lcl_sprm(Sprm & rSprm) +{ + switch( rSprm.getId()) + { + case NS_ooxml::LN_CT_Columns_col: + { + m_aTempColumn.nWidth = m_aTempColumn.nSpace = 0; + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + pProperties->resolve(*this); + m_aCols.push_back(m_aTempColumn); + } + } + break; + default: + OSL_FAIL( "SectionColumnHandler: unknown sprm"); + } +} +} //namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SectionColumnHandler.hxx b/writerfilter/source/dmapper/SectionColumnHandler.hxx new file mode 100644 index 000000000..e05d54b80 --- /dev/null +++ b/writerfilter/source/dmapper/SectionColumnHandler.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SECTIONCOLUMNHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SECTIONCOLUMNHANDLER_HXX + +#include "LoggedResources.hxx" +#include + +namespace writerfilter { +namespace dmapper +{ +struct Column_ +{ + sal_Int32 nWidth; + sal_Int32 nSpace; +}; + + +class SectionColumnHandler : public LoggedProperties +{ + bool m_bEqualWidth; + sal_Int32 m_nSpace; + sal_Int32 m_nNum; + bool m_bSep; + std::vector m_aCols; + + Column_ m_aTempColumn; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +public: + SectionColumnHandler(); + virtual ~SectionColumnHandler() override; + + bool IsEqualWidth() const { return m_bEqualWidth; } + sal_Int32 GetSpace() const { return m_nSpace; } + sal_Int32 GetNum() const { return m_nNum; } + bool IsSeparator() const { return m_bSep; } + + const std::vector& GetColumns() const { return m_aCols;} + +}; + +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx new file mode 100644 index 000000000..412826d6a --- /dev/null +++ b/writerfilter/source/dmapper/SettingsTable.cxx @@ -0,0 +1,891 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "SettingsTable.hxx" +#include "TagLogger.hxx" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ConversionHelper.hxx" +#include "DomainMapper.hxx" +#include "util.hxx" + +using namespace com::sun::star; + +namespace writerfilter { +namespace +{ +/// Maps OOXML to SvxZoomType. +sal_Int16 lcl_GetZoomType(Id nType) +{ + switch (nType) + { + case NS_ooxml::LN_Value_doc_ST_Zoom_fullPage: + return sal_Int16(SvxZoomType::WHOLEPAGE); + case NS_ooxml::LN_Value_doc_ST_Zoom_bestFit: + return sal_Int16(SvxZoomType::PAGEWIDTH); + case NS_ooxml::LN_Value_doc_ST_Zoom_textFit: + return sal_Int16(SvxZoomType::OPTIMAL); + } + + return sal_Int16(SvxZoomType::PERCENT); +} +} + +namespace dmapper +{ + namespace { + + /** Document protection restrictions + * + * This element specifies the set of document protection restrictions which have been applied to the contents of a + * WordprocessingML document.These restrictions should be enforced by applications editing this document + * when the enforcement attribute is turned on, and ignored(but persisted) otherwise.Document protection is a + * set of restrictions used to prevent unintentional changes to all or part of a WordprocessingML document. + */ + struct DocumentProtection_Impl + { + /** Document Editing Restrictions + * + * Possible values: + * - NS_ooxml::LN_Value_doc_ST_DocProtect_none + * - NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly + * - NS_ooxml::LN_Value_doc_ST_DocProtect_comments + * - NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges + * - NS_ooxml::LN_Value_doc_ST_DocProtect_forms + */ + sal_Int32 m_nEdit; + bool m_bEnforcement; + bool m_bFormatting; + + /** Provider type + * + * Possible values: + * "rsaAES" - NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES + * "rsaFull" - NS_ooxml::LN_Value_doc_ST_CryptProv_rsaFull + */ + sal_Int32 m_nCryptProviderType; + OUString m_sCryptAlgorithmClass; + OUString m_sCryptAlgorithmType; + OUString m_sCryptAlgorithmSid; + sal_Int32 m_CryptSpinCount; + OUString m_sHash; + OUString m_sSalt; + + DocumentProtection_Impl() + : m_nEdit(NS_ooxml::LN_Value_doc_ST_DocProtect_none) // Specifies that no editing restrictions have been applied to the document + , m_bEnforcement(false) + , m_bFormatting(false) + , m_nCryptProviderType(NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES) + , m_sCryptAlgorithmClass("hash") + , m_sCryptAlgorithmType("typeAny") + , m_CryptSpinCount(0) + { + } + + css::uno::Sequence toSequence() const; + + bool enabled() const + { + return ! isNone(); + } + + bool isNone() const { return m_nEdit == NS_ooxml::LN_Value_doc_ST_DocProtect_none; }; + }; + + } + + css::uno::Sequence DocumentProtection_Impl::toSequence() const + { + std::vector documentProtection; + + if (enabled()) + { + // w:edit + { + beans::PropertyValue aValue; + aValue.Name = "edit"; + + switch (m_nEdit) + { + case NS_ooxml::LN_Value_doc_ST_DocProtect_none: aValue.Value <<= OUString("none"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly: aValue.Value <<= OUString("readOnly"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_comments: aValue.Value <<= OUString("comments"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges: aValue.Value <<= OUString("trackedChanges"); break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_forms: aValue.Value <<= OUString("forms"); break; + default: + { +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + } + } + + documentProtection.push_back(aValue); + } + + // w:enforcement + if (m_bEnforcement) + { + beans::PropertyValue aValue; + aValue.Name = "enforcement"; + aValue.Value <<= OUString("1"); + documentProtection.push_back(aValue); + } + + // w:formatting + if (m_bFormatting) + { + beans::PropertyValue aValue; + aValue.Name = "formatting"; + aValue.Value <<= OUString("1"); + documentProtection.push_back(aValue); + } + + // w:cryptProviderType + { + beans::PropertyValue aValue; + aValue.Name = "cryptProviderType"; + if (m_nCryptProviderType == NS_ooxml::LN_Value_doc_ST_CryptProv_rsaAES) + aValue.Value <<= OUString("rsaAES"); + else if (m_nCryptProviderType == NS_ooxml::LN_Value_doc_ST_CryptProv_rsaFull) + aValue.Value <<= OUString("rsaFull"); + documentProtection.push_back(aValue); + } + + // w:cryptAlgorithmClass + { + beans::PropertyValue aValue; + aValue.Name = "cryptAlgorithmClass"; + aValue.Value <<= m_sCryptAlgorithmClass; + documentProtection.push_back(aValue); + } + + // w:cryptAlgorithmType + { + beans::PropertyValue aValue; + aValue.Name = "cryptAlgorithmType"; + aValue.Value <<= m_sCryptAlgorithmType; + documentProtection.push_back(aValue); + } + + // w:cryptAlgorithmSid + { + beans::PropertyValue aValue; + aValue.Name = "cryptAlgorithmSid"; + aValue.Value <<= m_sCryptAlgorithmSid; + documentProtection.push_back(aValue); + } + + // w:cryptSpinCount + { + beans::PropertyValue aValue; + aValue.Name = "cryptSpinCount"; + aValue.Value <<= OUString::number(m_CryptSpinCount); + documentProtection.push_back(aValue); + } + + // w:hash + { + beans::PropertyValue aValue; + aValue.Name = "hash"; + aValue.Value <<= m_sHash; + documentProtection.push_back(aValue); + } + + // w:salt + { + beans::PropertyValue aValue; + aValue.Name = "salt"; + aValue.Value <<= m_sSalt; + documentProtection.push_back(aValue); + } + } + + return comphelper::containerToSequence(documentProtection); + } + +struct SettingsTable_Impl +{ + int m_nDefaultTabStop; + + bool m_bRecordChanges; + bool m_bShowInsDelChanges; + bool m_bShowFormattingChanges; + bool m_bShowMarkupChanges; + bool m_bLinkStyles; + sal_Int16 m_nZoomFactor; + sal_Int16 m_nZoomType = 0; + sal_Int32 m_nWordCompatibilityMode; + Id m_nView; + bool m_bEvenAndOddHeaders; + bool m_bUsePrinterMetrics; + bool embedTrueTypeFonts; + bool embedSystemFonts; + bool m_bDoNotUseHTMLParagraphAutoSpacing; + bool m_bNoColumnBalance; + bool m_bAutoHyphenation; + bool m_bNoHyphenateCaps; + sal_Int16 m_nHyphenationZone; + bool m_bWidowControl; + bool m_bLongerSpaceSequence; + bool m_bSplitPgBreakAndParaMark; + bool m_bMirrorMargin; + bool m_bDoNotExpandShiftReturn; + bool m_bProtectForm; + bool m_bRedlineProtection; + OUString m_sRedlineProtectionKey; + bool m_bReadOnly; + bool m_bDisplayBackgroundShape; + bool m_bNoLeading = false; + OUString m_sDecimalSymbol; + OUString m_sListSeparator; + + uno::Sequence m_pThemeFontLangProps; + + std::vector m_aCompatSettings; + uno::Sequence m_pCurrentCompatSetting; + OUString m_sCurrentDatabaseDataSource; + + DocumentProtection_Impl m_DocumentProtection; + + SettingsTable_Impl() : + m_nDefaultTabStop( 720 ) //default is 1/2 in + , m_bRecordChanges(false) + , m_bShowInsDelChanges(true) + , m_bShowFormattingChanges(false) + , m_bShowMarkupChanges(true) + , m_bLinkStyles(false) + , m_nZoomFactor(0) + , m_nWordCompatibilityMode(-1) + , m_nView(0) + , m_bEvenAndOddHeaders(false) + , m_bUsePrinterMetrics(false) + , embedTrueTypeFonts(false) + , embedSystemFonts(false) + , m_bDoNotUseHTMLParagraphAutoSpacing(false) + , m_bNoColumnBalance(false) + , m_bAutoHyphenation(false) + , m_bNoHyphenateCaps(false) + , m_nHyphenationZone(0) + , m_bWidowControl(false) + , m_bLongerSpaceSequence(false) + , m_bSplitPgBreakAndParaMark(false) + , m_bMirrorMargin(false) + , m_bDoNotExpandShiftReturn(false) + , m_bProtectForm(false) + , m_bRedlineProtection(false) + , m_sRedlineProtectionKey() + , m_bReadOnly(false) + , m_bDisplayBackgroundShape(false) + , m_sDecimalSymbol(".") + , m_sListSeparator(",") + , m_pThemeFontLangProps(3) + , m_pCurrentCompatSetting(3) + {} + +}; + +SettingsTable::SettingsTable(const DomainMapper& rDomainMapper) +: LoggedProperties("SettingsTable") +, LoggedTable("SettingsTable") +, m_pImpl( new SettingsTable_Impl ) +{ + if (rDomainMapper.IsRTFImport()) + { + // HTML paragraph auto-spacing is opt-in for RTF, opt-out for OOXML. + m_pImpl->m_bDoNotUseHTMLParagraphAutoSpacing = true; + // Longer space sequence is opt-in for RTF, and not in OOXML. + m_pImpl->m_bLongerSpaceSequence = true; + } +} + +SettingsTable::~SettingsTable() +{ +} + +void SettingsTable::lcl_attribute(Id nName, Value & val) +{ + int nIntValue = val.getInt(); + OUString sStringValue = val.getString(); + + switch(nName) + { + case NS_ooxml::LN_CT_Zoom_percent: + m_pImpl->m_nZoomFactor = nIntValue; + break; + case NS_ooxml::LN_CT_Zoom_val: + m_pImpl->m_nZoomType = lcl_GetZoomType(nIntValue); + break; + case NS_ooxml::LN_CT_Language_val: + m_pImpl->m_pThemeFontLangProps[0].Name = "val"; + m_pImpl->m_pThemeFontLangProps[0].Value <<= sStringValue; + break; + case NS_ooxml::LN_CT_Language_eastAsia: + m_pImpl->m_pThemeFontLangProps[1].Name = "eastAsia"; + m_pImpl->m_pThemeFontLangProps[1].Value <<= sStringValue; + break; + case NS_ooxml::LN_CT_Language_bidi: + m_pImpl->m_pThemeFontLangProps[2].Name = "bidi"; + m_pImpl->m_pThemeFontLangProps[2].Value <<= sStringValue; + break; + case NS_ooxml::LN_CT_View_val: + m_pImpl->m_nView = nIntValue; + break; + case NS_ooxml::LN_CT_CompatSetting_name: + m_pImpl->m_pCurrentCompatSetting[0].Name = "name"; + m_pImpl->m_pCurrentCompatSetting[0].Value <<= sStringValue; + break; + case NS_ooxml::LN_CT_CompatSetting_uri: + m_pImpl->m_pCurrentCompatSetting[1].Name = "uri"; + m_pImpl->m_pCurrentCompatSetting[1].Value <<= sStringValue; + break; + case NS_ooxml::LN_CT_CompatSetting_val: + m_pImpl->m_pCurrentCompatSetting[2].Name = "val"; + m_pImpl->m_pCurrentCompatSetting[2].Value <<= sStringValue; + break; + case NS_ooxml::LN_CT_DocProtect_edit: // 92037 + m_pImpl->m_DocumentProtection.m_nEdit = nIntValue; + // multiple DocProtect_edits should not exist. If they do, last one wins + m_pImpl->m_bRedlineProtection = false; + m_pImpl->m_bProtectForm = false; + m_pImpl->m_bReadOnly = false; + switch (nIntValue) + { + case NS_ooxml::LN_Value_doc_ST_DocProtect_trackedChanges: + { + m_pImpl->m_bRedlineProtection = true; + m_pImpl->m_sRedlineProtectionKey = m_pImpl->m_DocumentProtection.m_sHash; + break; + } + case NS_ooxml::LN_Value_doc_ST_DocProtect_forms: + m_pImpl->m_bProtectForm = true; + break; + case NS_ooxml::LN_Value_doc_ST_DocProtect_readOnly: + m_pImpl->m_bReadOnly = true; + break; + } + break; + case NS_ooxml::LN_CT_DocProtect_enforcement: // 92039 + m_pImpl->m_DocumentProtection.m_bEnforcement = (nIntValue != 0); + break; + case NS_ooxml::LN_CT_DocProtect_formatting: // 92038 + m_pImpl->m_DocumentProtection.m_bFormatting = (nIntValue != 0); + break; + case NS_ooxml::LN_AG_Password_cryptProviderType: // 92025 + m_pImpl->m_DocumentProtection.m_nCryptProviderType = nIntValue; + break; + case NS_ooxml::LN_AG_Password_cryptAlgorithmClass: // 92026 + if (nIntValue == NS_ooxml::LN_Value_doc_ST_AlgClass_hash) // 92023 + m_pImpl->m_DocumentProtection.m_sCryptAlgorithmClass = "hash"; + break; + case NS_ooxml::LN_AG_Password_cryptAlgorithmType: // 92027 + if (nIntValue == NS_ooxml::LN_Value_doc_ST_AlgType_typeAny) // 92024 + m_pImpl->m_DocumentProtection.m_sCryptAlgorithmType = "typeAny"; + break; + case NS_ooxml::LN_AG_Password_cryptAlgorithmSid: // 92028 + m_pImpl->m_DocumentProtection.m_sCryptAlgorithmSid = sStringValue; + break; + case NS_ooxml::LN_AG_Password_cryptSpinCount: // 92029 + m_pImpl->m_DocumentProtection.m_CryptSpinCount = nIntValue; + break; + case NS_ooxml::LN_AG_Password_hash: // 92035 + m_pImpl->m_DocumentProtection.m_sHash = sStringValue; + break; + case NS_ooxml::LN_AG_Password_salt: // 92036 + m_pImpl->m_DocumentProtection.m_sSalt = sStringValue; + break; + case NS_ooxml::LN_CT_TrackChangesView_insDel: + m_pImpl->m_bShowInsDelChanges = (nIntValue != 0); + break; + case NS_ooxml::LN_CT_TrackChangesView_formatting: + m_pImpl->m_bShowFormattingChanges = (nIntValue != 0); + break; + case NS_ooxml::LN_CT_TrackChangesView_markup: + m_pImpl->m_bShowMarkupChanges = (nIntValue != 0); + break; + default: + { +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + } + } +} + +void SettingsTable::lcl_sprm(Sprm& rSprm) +{ + sal_uInt32 nSprmId = rSprm.getId(); + + Value::Pointer_t pValue = rSprm.getValue(); + sal_Int32 nIntValue = pValue->getInt(); + + switch(nSprmId) + { + case NS_ooxml::LN_CT_Settings_zoom: // 92469; + case NS_ooxml::LN_CT_Settings_proofState: // 92489; + case NS_ooxml::LN_CT_Settings_attachedTemplate: // 92491; + case NS_ooxml::LN_CT_Settings_hdrShapeDefaults: // 92544; + case NS_ooxml::LN_CT_Settings_footnotePr: // 92545; + case NS_ooxml::LN_CT_Settings_endnotePr: // 92546; + case NS_ooxml::LN_CT_Settings_compat: // 92547; + case NS_ooxml::LN_CT_Settings_themeFontLang: // 92552; + case NS_ooxml::LN_CT_Settings_shapeDefaults: // 92560; + case NS_ooxml::LN_CT_Settings_view: + //PropertySetValues - need to be resolved + { + resolveSprmProps(*this, rSprm); + } + break; + case NS_ooxml::LN_CT_Settings_stylePaneFormatFilter: // 92493; + break; + case NS_ooxml::LN_CT_Settings_defaultTabStop: // 92505; + m_pImpl->m_nDefaultTabStop = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_linkStyles: // 92663; + m_pImpl->m_bLinkStyles = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_evenAndOddHeaders: + m_pImpl->m_bEvenAndOddHeaders = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_noPunctuationKerning: // 92526; + break; + case NS_ooxml::LN_CT_Settings_characterSpacingControl: // 92527; + // doNotCompress, compressPunctuation, compressPunctuationAndJapaneseKana + break; + case NS_ooxml::LN_CT_Settings_doNotIncludeSubdocsInStats: // 92554; // Do Not Include Content in Text Boxes, Footnotes, and Endnotes in Document Statistics) + break; + case NS_ooxml::LN_CT_Settings_decimalSymbol: // 92562; + m_pImpl->m_sDecimalSymbol = pValue->getString(); + break; + case NS_ooxml::LN_CT_Settings_listSeparator: // 92563; + m_pImpl->m_sListSeparator = pValue->getString(); + break; + case NS_ooxml::LN_CT_Settings_rsids: // 92549; revision save Ids - probably not necessary + break; + case NS_ooxml::LN_CT_Settings_hyphenationZone: // 92508; + m_pImpl->m_nHyphenationZone = nIntValue; + break; + case NS_ooxml::LN_CT_Compat_useFELayout: // 92422; + // useFELayout (Do Not Bypass East Asian/Complex Script Layout Code - support of old versions of Word - ignored) + break; + case NS_ooxml::LN_CT_Settings_trackRevisions: + { + m_pImpl->m_bRecordChanges = bool(rSprm.getValue( )->getInt( ) ); + } + break; + case NS_ooxml::LN_CT_Settings_revisionView: + resolveSprmProps(*this, rSprm); + break; + case NS_ooxml::LN_CT_Settings_documentProtection: + resolveSprmProps(*this, rSprm); + break; + case NS_ooxml::LN_CT_Compat_usePrinterMetrics: + m_pImpl->m_bUsePrinterMetrics = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_embedTrueTypeFonts: + m_pImpl->embedTrueTypeFonts = nIntValue != 0; + break; + case NS_ooxml::LN_CT_Settings_embedSystemFonts: + m_pImpl->embedSystemFonts = nIntValue != 0; + break; + case NS_ooxml::LN_CT_Compat_doNotUseHTMLParagraphAutoSpacing: + m_pImpl->m_bDoNotUseHTMLParagraphAutoSpacing = nIntValue; + break; + case NS_ooxml::LN_CT_Compat_splitPgBreakAndParaMark: + m_pImpl->m_bSplitPgBreakAndParaMark = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_mirrorMargins: + m_pImpl->m_bMirrorMargin = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_mailMerge: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_MailMerge_query: + { + // try to get the "database.table" name from the query saved previously + OUString sVal = pValue->getString(); + if ( sVal.endsWith("$") && sVal.indexOf(".dbo.") > 0 ) + { + sal_Int32 nSpace = sVal.lastIndexOf(' '); + sal_Int32 nDbo = sVal.lastIndexOf(".dbo."); + if ( nSpace > 0 && nSpace < nDbo - 1 ) + { + m_pImpl->m_sCurrentDatabaseDataSource = sVal.copy(nSpace + 1, nDbo - nSpace - 1) + + sVal.copy(nDbo + 4, sVal.getLength() - nDbo - 5); + } + } + } + break; + case NS_ooxml::LN_CT_Compat_compatSetting: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + pProperties->resolve(*this); + + beans::PropertyValue aValue; + aValue.Name = "compatSetting"; + aValue.Value <<= m_pImpl->m_pCurrentCompatSetting; + m_pImpl->m_aCompatSettings.push_back(aValue); + } + } + break; + case NS_ooxml::LN_CT_Compat_noColumnBalance: + m_pImpl->m_bNoColumnBalance = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_autoHyphenation: + m_pImpl->m_bAutoHyphenation = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_doNotHyphenateCaps: + m_pImpl->m_bNoHyphenateCaps = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_widowControl: + m_pImpl->m_bWidowControl = nIntValue; + break; + case NS_ooxml::LN_CT_Settings_longerSpaceSequence: + m_pImpl->m_bLongerSpaceSequence = nIntValue; + break; + case NS_ooxml::LN_CT_Compat_doNotExpandShiftReturn: + m_pImpl->m_bDoNotExpandShiftReturn = true; + break; + case NS_ooxml::LN_CT_Settings_displayBackgroundShape: + m_pImpl->m_bDisplayBackgroundShape = nIntValue; + break; + case NS_ooxml::LN_CT_Compat_noLeading: + m_pImpl->m_bNoLeading = nIntValue != 0; + break; + default: + { +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + } + } +} + +void SettingsTable::lcl_entry(writerfilter::Reference::Pointer_t ref) +{ + ref->resolve(*this); +} + +//returns default TabStop in 1/100th mm +int SettingsTable::GetDefaultTabStop() const +{ + return ConversionHelper::convertTwipToMM100( m_pImpl->m_nDefaultTabStop ); +} + +bool SettingsTable::GetLinkStyles() const +{ + return m_pImpl->m_bLinkStyles; +} + +sal_Int16 SettingsTable::GetZoomFactor() const +{ + return m_pImpl->m_nZoomFactor; +} + +sal_Int16 SettingsTable::GetZoomType() const { return m_pImpl->m_nZoomType; } + +Id SettingsTable::GetView() const +{ + return m_pImpl->m_nView; +} + +bool SettingsTable::GetUsePrinterMetrics() const +{ + return m_pImpl->m_bUsePrinterMetrics; +} + +bool SettingsTable::GetEvenAndOddHeaders() const +{ + return m_pImpl->m_bEvenAndOddHeaders; +} + +bool SettingsTable::GetEmbedTrueTypeFonts() const +{ + return m_pImpl->embedTrueTypeFonts; +} + +bool SettingsTable::GetEmbedSystemFonts() const +{ + return m_pImpl->embedSystemFonts; +} + +bool SettingsTable::GetDoNotUseHTMLParagraphAutoSpacing() const +{ + return m_pImpl->m_bDoNotUseHTMLParagraphAutoSpacing; +} + +bool SettingsTable::GetNoColumnBalance() const +{ + return m_pImpl->m_bNoColumnBalance; +} + +bool SettingsTable::GetSplitPgBreakAndParaMark() const +{ + return m_pImpl->m_bSplitPgBreakAndParaMark; +} + +bool SettingsTable::GetMirrorMarginSettings() const +{ + return m_pImpl->m_bMirrorMargin; +} + +bool SettingsTable::GetDisplayBackgroundShape() const +{ + return m_pImpl->m_bDisplayBackgroundShape; +} + +bool SettingsTable::GetDoNotExpandShiftReturn() const +{ + return m_pImpl->m_bDoNotExpandShiftReturn; +} + +bool SettingsTable::GetProtectForm() const +{ + return m_pImpl->m_bProtectForm && m_pImpl->m_DocumentProtection.m_bEnforcement; +} + +bool SettingsTable::GetReadOnly() const +{ + return m_pImpl->m_bReadOnly && m_pImpl->m_DocumentProtection.m_bEnforcement; +} + +bool SettingsTable::GetNoHyphenateCaps() const +{ + return m_pImpl->m_bNoHyphenateCaps; +} + +sal_Int16 SettingsTable::GetHypenationZone() const +{ + return m_pImpl->m_nHyphenationZone; +} + +OUString SettingsTable::GetDecimalSymbol() const +{ + return m_pImpl->m_sDecimalSymbol; +} + +OUString SettingsTable::GetListSeparator() const +{ + return m_pImpl->m_sListSeparator; +} + + +uno::Sequence const & SettingsTable::GetThemeFontLangProperties() const +{ + return m_pImpl->m_pThemeFontLangProps; +} + +uno::Sequence SettingsTable::GetCompatSettings() const +{ + if ( GetWordCompatibilityMode() == -1 ) + { + // the default value for an undefined compatibilityMode is 12 (Word 2007) + uno::Sequence aCompatSetting( comphelper::InitPropertySequence({ + { "name", uno::Any(OUString("compatibilityMode")) }, + { "uri", uno::Any(OUString("http://schemas.microsoft.com/office/word")) }, + { "val", uno::Any(OUString("12")) } //12: Use word processing features specified in ECMA-376. This is the default. + })); + + beans::PropertyValue aValue; + aValue.Name = "compatSetting"; + aValue.Value <<= aCompatSetting; + + m_pImpl->m_aCompatSettings.push_back(aValue); + } + + return comphelper::containerToSequence(m_pImpl->m_aCompatSettings); +} + +css::uno::Sequence SettingsTable::GetDocumentProtectionSettings() const +{ + return m_pImpl->m_DocumentProtection.toSequence(); +} + +const OUString & SettingsTable::GetCurrentDatabaseDataSource() const +{ + return m_pImpl->m_sCurrentDatabaseDataSource; +} + +static bool lcl_isDefault(const uno::Reference& xPropertyState, const OUString& rPropertyName) +{ + return xPropertyState->getPropertyState(rPropertyName) == beans::PropertyState_DEFAULT_VALUE; +} + +void SettingsTable::ApplyProperties(uno::Reference const& xDoc) +{ + uno::Reference< beans::XPropertySet> xDocProps( xDoc, uno::UNO_QUERY ); + + if (GetWordCompatibilityMode() <= 14) + { + uno::Reference xTextFactory(xDoc, uno::UNO_QUERY_THROW); + uno::Reference xDocumentSettings(xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY_THROW); + xDocumentSettings->setPropertyValue("MsWordCompMinLineHeightByFly", uno::makeAny(true)); + } + + // Show changes value + if (xDocProps.is()) + { + bool bHideChanges = !m_pImpl->m_bShowInsDelChanges || !m_pImpl->m_bShowMarkupChanges; + xDocProps->setPropertyValue("ShowChanges", uno::makeAny( !bHideChanges || m_pImpl->m_bShowFormattingChanges ) ); + } + + // Record changes value + if (xDocProps.is()) + { + xDocProps->setPropertyValue("RecordChanges", uno::makeAny( m_pImpl->m_bRecordChanges ) ); + // Password protected Record changes + if ( m_pImpl->m_bRecordChanges && m_pImpl->m_bRedlineProtection && m_pImpl->m_DocumentProtection.m_bEnforcement ) + { + // use dummy protection key to forbid disabling of Record changes without a notice + // (extending the recent GrabBag support) TODO support password verification... + css::uno::Sequence aDummyKey(1); + aDummyKey[0] = 1; + xDocProps->setPropertyValue("RedlineProtectionKey", uno::makeAny( aDummyKey )); + } + } + + // Auto hyphenation: turns on hyphenation by default, may still disable it at a paragraph level. + // Situation is similar for RTF_WIDOWCTRL, which turns on widow / orphan control by default. + if (m_pImpl->m_bAutoHyphenation || m_pImpl->m_bNoHyphenateCaps || m_pImpl->m_bWidowControl) + { + uno::Reference xStyleFamiliesSupplier(xDoc, uno::UNO_QUERY); + if (!xStyleFamiliesSupplier.is()) + return; + + uno::Reference xStyleFamilies = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference xParagraphStyles = xStyleFamilies->getByName("ParagraphStyles").get< uno::Reference >(); + uno::Reference xDefault = xParagraphStyles->getByName("Standard").get< uno::Reference >(); + uno::Reference xPropertyState(xDefault, uno::UNO_QUERY); + if (m_pImpl->m_bAutoHyphenation && lcl_isDefault(xPropertyState, "ParaIsHyphenation")) + { + uno::Reference xPropertySet(xDefault, uno::UNO_QUERY); + xPropertySet->setPropertyValue("ParaIsHyphenation", uno::makeAny(true)); + } + if (m_pImpl->m_bNoHyphenateCaps) + { + uno::Reference xPropertySet(xDefault, uno::UNO_QUERY); + xPropertySet->setPropertyValue("ParaHyphenationNoCaps", uno::makeAny(true)); + } + if (m_pImpl->m_bWidowControl && lcl_isDefault(xPropertyState, "ParaWidows") && lcl_isDefault(xPropertyState, "ParaOrphans")) + { + uno::Reference xPropertySet(xDefault, uno::UNO_QUERY); + uno::Any aAny = uno::makeAny(static_cast(2)); + xPropertySet->setPropertyValue("ParaWidows", aAny); + xPropertySet->setPropertyValue("ParaOrphans", aAny); + } + } +} + +bool SettingsTable::GetCompatSettingValue( const OUString& sCompatName ) const +{ + bool bRet = false; + for (const auto& rProp : m_pImpl->m_aCompatSettings) + { + if (rProp.Name == "compatSetting") //always true + { + css::uno::Sequence aCurrentCompatSettings; + rProp.Value >>= aCurrentCompatSettings; + + OUString sName; + aCurrentCompatSettings[0].Value >>= sName; + if ( sName != sCompatName ) + continue; + + OUString sUri; + aCurrentCompatSettings[1].Value >>= sUri; + if ( sUri != "http://schemas.microsoft.com/office/word" ) + continue; + + OUString sVal; + aCurrentCompatSettings[2].Value >>= sVal; + // if repeated, what happens? Last one wins + bRet = sVal.toBoolean(); + } + } + + return bRet; +} + +//Keep this function in-sync with the one in sw/.../docxattributeoutput.cxx +sal_Int32 SettingsTable::GetWordCompatibilityMode() const +{ + if ( m_pImpl->m_nWordCompatibilityMode != -1 ) + return m_pImpl->m_nWordCompatibilityMode; + + for (const auto& rProp : m_pImpl->m_aCompatSettings) + { + if (rProp.Name == "compatSetting") //always true + { + css::uno::Sequence aCurrentCompatSettings; + rProp.Value >>= aCurrentCompatSettings; + + OUString sName; + aCurrentCompatSettings[0].Value >>= sName; + if ( sName != "compatibilityMode" ) + continue; + + OUString sUri; + aCurrentCompatSettings[1].Value >>= sUri; + if ( sUri != "http://schemas.microsoft.com/office/word" ) + continue; + + OUString sVal; + aCurrentCompatSettings[2].Value >>= sVal; + const sal_Int32 nValidMode = sVal.toInt32(); + // if repeated, highest mode wins in MS Word. 11 is the first valid mode. + if ( nValidMode > 10 && nValidMode > m_pImpl->m_nWordCompatibilityMode ) + m_pImpl->m_nWordCompatibilityMode = nValidMode; + } + } + + return m_pImpl->m_nWordCompatibilityMode; +} + +bool SettingsTable::GetLongerSpaceSequence() const +{ + return m_pImpl->m_bLongerSpaceSequence; +} + +bool SettingsTable::GetNoLeading() const +{ + return m_pImpl->m_bNoLeading; +} + +}//namespace dmapper +} //namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SettingsTable.hxx b/writerfilter/source/dmapper/SettingsTable.hxx new file mode 100644 index 000000000..6dd0545ad --- /dev/null +++ b/writerfilter/source/dmapper/SettingsTable.hxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SETTINGSTABLE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SETTINGSTABLE_HXX + +#include "LoggedResources.hxx" +#include +#include + +namespace com::sun::star::lang { + class XMultiServiceFactory; + struct Locale; +} + +namespace writerfilter { +namespace dmapper +{ +class DomainMapper; + +struct SettingsTable_Impl; + +class SettingsTable : public LoggedProperties, public LoggedTable +{ + std::unique_ptr m_pImpl; + + public: + SettingsTable(const DomainMapper& rDomainMapper); + virtual ~SettingsTable() override; + + //returns default TabStop in 1/100th mm + int GetDefaultTabStop() const; + + /// Automatically update styles from document template? + bool GetLinkStyles() const; + + /// What's the zoom factor set in percents? + sal_Int16 GetZoomFactor() const; + + /// Gets the type of the zoom. + sal_Int16 GetZoomType() const; + + /// What's the requested view? E.g. "web". + Id GetView() const; + + bool GetEvenAndOddHeaders() const; + + bool GetUsePrinterMetrics() const; + + bool GetEmbedTrueTypeFonts() const; + bool GetEmbedSystemFonts() const; + + bool GetDoNotUseHTMLParagraphAutoSpacing() const; + bool GetSplitPgBreakAndParaMark() const; + bool GetMirrorMarginSettings() const; + bool GetDisplayBackgroundShape() const; + bool GetDoNotExpandShiftReturn() const; + bool GetNoColumnBalance() const; + bool GetProtectForm() const; + bool GetReadOnly() const; + bool GetLongerSpaceSequence() const; + bool GetNoLeading() const; + bool GetNoHyphenateCaps() const; + sal_Int16 GetHypenationZone() const; + + OUString GetDecimalSymbol() const; + OUString GetListSeparator() const; + + css::uno::Sequence const & GetThemeFontLangProperties() const; + + css::uno::Sequence GetCompatSettings() const; + + css::uno::Sequence GetDocumentProtectionSettings() const; + + void ApplyProperties(css::uno::Reference const& xDoc); + + bool GetCompatSettingValue( const OUString& sCompatName ) const; + sal_Int32 GetWordCompatibilityMode() const; + + const OUString & GetCurrentDatabaseDataSource() const; + + private: + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + + // Table + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) override; + +}; +typedef tools::SvRef< SettingsTable > SettingsTablePtr; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SmartTagHandler.cxx b/writerfilter/source/dmapper/SmartTagHandler.cxx new file mode 100644 index 000000000..2ea94a963 --- /dev/null +++ b/writerfilter/source/dmapper/SmartTagHandler.cxx @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "SmartTagHandler.hxx" + +#include +#include +#include +#include +#include + +#include + +#include + +namespace +{ +OUString lcl_getTypePath(OUString& rType) +{ + OUString aRet; + if (rType.startsWith("urn:bails")) + { + rType = "urn:bails"; + aRet = "tscp/bails.rdf"; + } + return aRet; +} +} + +namespace writerfilter::dmapper +{ +using namespace ::com::sun::star; + +SmartTagHandler::SmartTagHandler(uno::Reference xComponentContext, + const uno::Reference& xTextDocument) + : LoggedProperties("SmartTagHandler") + , m_xComponentContext(std::move(xComponentContext)) + , m_xDocumentMetadataAccess(xTextDocument, uno::UNO_QUERY) +{ +} + +SmartTagHandler::~SmartTagHandler() = default; + +void SmartTagHandler::lcl_attribute(Id nId, Value& rValue) +{ + switch (nId) + { + case NS_ooxml::LN_CT_Attr_name: + m_aAttributes.emplace_back(rValue.getString(), OUString()); + break; + case NS_ooxml::LN_CT_Attr_val: + if (!m_aAttributes.empty()) + m_aAttributes.back().second = rValue.getString(); + break; + default: + SAL_WARN("writerfilter", "SmartTagHandler::lcl_attribute: unhandled attribute " + << nId << " (string value: '" << rValue.getString() + << "')"); + break; + } +} + +void SmartTagHandler::lcl_sprm(Sprm& rSprm) +{ + switch (rSprm.getId()) + { + case NS_ooxml::LN_CT_SmartTagPr_attr: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + pProperties->resolve(*this); + break; + } + } +} + +void SmartTagHandler::setURI(const OUString& rURI) { m_aURI = rURI; } + +void SmartTagHandler::setElement(const OUString& rElement) { m_aElement = rElement; } + +void SmartTagHandler::handle(const uno::Reference& xParagraph) +{ + if (!m_aURI.isEmpty() && !m_aElement.isEmpty() && !m_aAttributes.empty()) + { + uno::Reference xSubject(xParagraph, uno::UNO_QUERY); + + for (const std::pair& rAttribute : m_aAttributes) + { + OUString aTypeNS = rAttribute.first; + OUString aMetadataFilePath = lcl_getTypePath(aTypeNS); + if (aMetadataFilePath.isEmpty()) + continue; + + uno::Reference xType = rdf::URI::create(m_xComponentContext, aTypeNS); + uno::Sequence> aGraphNames + = m_xDocumentMetadataAccess->getMetadataGraphsWithType(xType); + uno::Reference xGraphName; + if (aGraphNames.hasElements()) + xGraphName = aGraphNames[0]; + else + { + uno::Sequence> xTypes = { xType }; + xGraphName = m_xDocumentMetadataAccess->addMetadataFile(aMetadataFilePath, xTypes); + } + uno::Reference xGraph + = m_xDocumentMetadataAccess->getRDFRepository()->getGraph(xGraphName); + uno::Reference xKey + = rdf::URI::create(m_xComponentContext, rAttribute.first); + uno::Reference xValue + = rdf::Literal::create(m_xComponentContext, rAttribute.second); + xGraph->addStatement(xSubject, xKey, xValue); + } + + m_aURI.clear(); + m_aElement.clear(); + m_aAttributes.clear(); + } +} + +} // namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/SmartTagHandler.hxx b/writerfilter/source/dmapper/SmartTagHandler.hxx new file mode 100644 index 000000000..29dbeeb3b --- /dev/null +++ b/writerfilter/source/dmapper/SmartTagHandler.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SMARTTAGHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_SMARTTAGHANDLER_HXX + +#include + +#include "LoggedResources.hxx" + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace rdf +{ +class XDocumentMetadataAccess; +} +namespace text +{ +class XTextDocument; +class XTextRange; +} +namespace uno +{ +class XComponentContext; +} +} +} +} + +namespace writerfilter +{ +namespace dmapper +{ +/// Handler for smart tags, i.e. and below. +class SmartTagHandler : public LoggedProperties +{ + css::uno::Reference m_xComponentContext; + css::uno::Reference m_xDocumentMetadataAccess; + OUString m_aURI; + OUString m_aElement; + std::vector> m_aAttributes; + +public: + SmartTagHandler(css::uno::Reference xComponentContext, + const css::uno::Reference& xTextDocument); + ~SmartTagHandler() override; + + void lcl_attribute(Id nId, Value& rValue) override; + void lcl_sprm(Sprm& rSprm) override; + + void setURI(const OUString& rURI); + void setElement(const OUString& rElement); + + /// Set m_aAttributes as RDF statements on xParagraph. + void handle(const css::uno::Reference& xParagraph); +}; + +} // namespace dmapper +} // namespace writerfilter + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx new file mode 100644 index 000000000..d03be9cba --- /dev/null +++ b/writerfilter/source/dmapper/StyleSheetTable.cxx @@ -0,0 +1,1645 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "StyleSheetTable.hxx" +#include "util.hxx" +#include "ConversionHelper.hxx" +#include "TblStylePrHandler.hxx" +#include "TagLogger.hxx" +#include "BorderHandler.hxx" +#include "LatentStyleHandler.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +namespace writerfilter::dmapper +{ + +StyleSheetEntry::StyleSheetEntry() : + sStyleIdentifierD() + ,bIsDefaultStyle(false) + ,bInvalidHeight(false) + ,bHasUPE(false) + ,nStyleTypeCode(STYLE_TYPE_UNKNOWN) + ,sBaseStyleIdentifier() + ,sNextStyleIdentifier() + ,pProperties(new StyleSheetPropertyMap) + ,bAutoRedefine(false) +{ +} + +StyleSheetEntry::~StyleSheetEntry() +{ +} + +TableStyleSheetEntry::TableStyleSheetEntry( StyleSheetEntry const & rEntry ): + StyleSheetEntry( ) +{ + bIsDefaultStyle = rEntry.bIsDefaultStyle; + bInvalidHeight = rEntry.bInvalidHeight; + bHasUPE = rEntry.bHasUPE; + nStyleTypeCode = STYLE_TYPE_TABLE; + sBaseStyleIdentifier = rEntry.sBaseStyleIdentifier; + sNextStyleIdentifier = rEntry.sNextStyleIdentifier; + sStyleName = rEntry.sStyleName; + sStyleIdentifierD = rEntry.sStyleIdentifierD; +} + +TableStyleSheetEntry::~TableStyleSheetEntry( ) +{ +} + +void TableStyleSheetEntry::AddTblStylePr( TblStyleType nType, const PropertyMapPtr& pProps ) +{ + static const int nTypesProps = 4; + static const TblStyleType pTypesToFix[nTypesProps] = + { + TBL_STYLE_FIRSTROW, + TBL_STYLE_LASTROW, + TBL_STYLE_FIRSTCOL, + TBL_STYLE_LASTCOL + }; + + static const PropertyIds pPropsToCheck[nTypesProps] = + { + PROP_BOTTOM_BORDER, + PROP_TOP_BORDER, + PROP_RIGHT_BORDER, + PROP_LEFT_BORDER + }; + + for (int i=0; i < nTypesProps; ++i ) + { + if ( nType == pTypesToFix[i] ) + { + PropertyIds nChecked = pPropsToCheck[i]; + std::optional pChecked = pProps->getProperty(nChecked); + + PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER; + std::optional pInside = pProps->getProperty(nInsideProp); + + if ( pChecked && pInside ) + { + // In this case, remove the inside border + pProps->Erase( nInsideProp ); + } + + break; + } + } + + // Append the tblStylePr + m_aStyles[nType] = pProps; +} + +PropertyMapPtr TableStyleSheetEntry::GetProperties( sal_Int32 nMask ) +{ + PropertyMapPtr pProps( new PropertyMap ); + + // And finally get the mask ones + pProps->InsertProps(GetLocalPropertiesFromMask(nMask)); + + return pProps; +} + +beans::PropertyValues StyleSheetEntry::GetInteropGrabBagSeq() const +{ + return comphelper::containerToSequence(m_aInteropGrabBag); +} + +beans::PropertyValue StyleSheetEntry::GetInteropGrabBag() +{ + beans::PropertyValue aRet; + aRet.Name = sStyleIdentifierD; + + beans::PropertyValues aSeq = GetInteropGrabBagSeq(); + aRet.Value <<= aSeq; + return aRet; +} + +void StyleSheetEntry::AppendInteropGrabBag(const beans::PropertyValue& rValue) +{ + m_aInteropGrabBag.push_back(rValue); +} + +PropertyMapPtr StyleSheetEntry::GetMergedInheritedProperties(const StyleSheetTablePtr& pStyleSheetTable) +{ + PropertyMapPtr pRet; + if ( pStyleSheetTable && !sBaseStyleIdentifier.isEmpty() && sBaseStyleIdentifier != sStyleIdentifierD ) + { + const StyleSheetEntryPtr pParentStyleSheet = pStyleSheetTable->FindStyleSheetByISTD(sBaseStyleIdentifier); + if ( pParentStyleSheet ) + pRet = pParentStyleSheet->GetMergedInheritedProperties(pStyleSheetTable); + } + + if ( !pRet ) + pRet = new PropertyMap; + + pRet->InsertProps(pProperties); + + return pRet; +} + +static void lcl_mergeProps( const PropertyMapPtr& pToFill, const PropertyMapPtr& pToAdd, TblStyleType nStyleId ) +{ + static const PropertyIds pPropsToCheck[] = + { + PROP_BOTTOM_BORDER, + PROP_TOP_BORDER, + PROP_RIGHT_BORDER, + PROP_LEFT_BORDER, + }; + + bool pRemoveInside[] = + { + ( nStyleId == TBL_STYLE_FIRSTROW ), + ( nStyleId == TBL_STYLE_LASTROW ), + ( nStyleId == TBL_STYLE_LASTCOL ), + ( nStyleId == TBL_STYLE_FIRSTCOL ) + }; + + for ( unsigned i = 0 ; i != SAL_N_ELEMENTS(pPropsToCheck); i++ ) + { + PropertyIds nId = pPropsToCheck[i]; + std::optional pProp = pToAdd->getProperty(nId); + + if ( pProp ) + { + if ( pRemoveInside[i] ) + { + // Remove the insideH and insideV depending on the cell pos + PropertyIds nInsideProp = ( i < 2 ) ? META_PROP_HORIZONTAL_BORDER : META_PROP_VERTICAL_BORDER; + pToFill->Erase(nInsideProp); + } + } + } + + pToFill->InsertProps(pToAdd); +} + +PropertyMapPtr TableStyleSheetEntry::GetLocalPropertiesFromMask( sal_Int32 nMask ) +{ + // Order from right to left + struct TblStyleTypeAndMask { + sal_Int32 mask; + TblStyleType type; + }; + + static const TblStyleTypeAndMask aOrderedStyleTable[] = + { + { 0x010, TBL_STYLE_BAND2HORZ }, + { 0x020, TBL_STYLE_BAND1HORZ }, + { 0x040, TBL_STYLE_BAND2VERT }, + { 0x080, TBL_STYLE_BAND1VERT }, + { 0x100, TBL_STYLE_LASTCOL }, + { 0x200, TBL_STYLE_FIRSTCOL }, + { 0x400, TBL_STYLE_LASTROW }, + { 0x800, TBL_STYLE_FIRSTROW }, + { 0x001, TBL_STYLE_SWCELL }, + { 0x002, TBL_STYLE_SECELL }, + { 0x004, TBL_STYLE_NWCELL }, + { 0x008, TBL_STYLE_NECELL } + }; + + // Get the properties applying according to the mask + PropertyMapPtr pProps( new PropertyMap( ) ); + for (const TblStyleTypeAndMask & i : aOrderedStyleTable) + { + TblStylePrs::iterator pIt = m_aStyles.find( i.type ); + if ( ( nMask & i.mask ) && ( pIt != m_aStyles.end( ) ) ) + lcl_mergeProps( pProps, pIt->second, i.type ); + } + return pProps; +} + +namespace { + +struct ListCharStylePropertyMap_t +{ + OUString sCharStyleName; + PropertyValueVector_t aPropertyValues; + + ListCharStylePropertyMap_t(const OUString& rCharStyleName, const PropertyValueVector_t& rPropertyValues): + sCharStyleName( rCharStyleName ), + aPropertyValues( rPropertyValues ) + {} +}; + +} + +typedef std::vector< ListCharStylePropertyMap_t > ListCharStylePropertyVector_t; + + +struct StyleSheetTable_Impl +{ + DomainMapper& m_rDMapper; + uno::Reference< text::XTextDocument> m_xTextDocument; + uno::Reference< beans::XPropertySet> m_xTextDefaults; + std::vector< StyleSheetEntryPtr > m_aStyleSheetEntries; + StyleSheetEntryPtr m_pCurrentEntry; + PropertyMapPtr m_pDefaultParaProps, m_pDefaultCharProps; + OUString m_sDefaultParaStyleName; //WW8 name + ListCharStylePropertyVector_t m_aListCharStylePropertyVector; + bool m_bHasImportedDefaultParaProps; + bool m_bIsNewDoc; + + StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> const& xTextDocument, bool bIsNewDoc); + + OUString HasListCharStyle( const PropertyValueVector_t& rCharProperties ); + + /// Appends the given key-value pair to the list of latent style properties of the current entry. + void AppendLatentStyleProperty(const OUString& aName, Value const & rValue); + /// Sets all properties of xStyle back to default. + static void SetPropertiesToDefault(const uno::Reference& xStyle); +}; + + +StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper, + uno::Reference< text::XTextDocument> const& xTextDocument, + bool const bIsNewDoc) + : + m_rDMapper( rDMapper ), + m_xTextDocument( xTextDocument ), + m_pCurrentEntry(), + m_pDefaultParaProps(new PropertyMap), + m_pDefaultCharProps(new PropertyMap), + m_sDefaultParaStyleName("Normal"), + m_bHasImportedDefaultParaProps(false), + m_bIsNewDoc(bIsNewDoc) +{ + //set font height default to 10pt + uno::Any aVal = uno::makeAny( 10.0 ); + m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT, aVal ); + m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_ASIAN, aVal ); + m_pDefaultCharProps->Insert( PROP_CHAR_HEIGHT_COMPLEX, aVal ); + + // See SwDoc::RemoveAllFormatLanguageDependencies(), internal filters + // disable kerning by default, do the same here. + m_pDefaultCharProps->Insert(PROP_CHAR_AUTO_KERNING, uno::Any(false)); +} + + +OUString StyleSheetTable_Impl::HasListCharStyle( const PropertyValueVector_t& rPropValues ) +{ + for( const auto& rListVector : m_aListCharStylePropertyVector ) + { + const auto& rPropertyValues = rListVector.aPropertyValues; + //if size is identical + if( rPropertyValues.size() == rPropValues.size() ) + { + bool bBreak = false; + //then search for all contained properties + for( const auto& rPropVal1 : rPropValues) + { + //find the property + auto aListIter = std::find_if(rPropertyValues.begin(), rPropertyValues.end(), + [&rPropVal1](const css::beans::PropertyValue& rPropVal2) { return rPropVal2.Name == rPropVal1.Name; }); + //set break flag if property hasn't been found + bBreak = (aListIter == rPropertyValues.end()) || (aListIter->Value != rPropVal1.Value); + if( bBreak ) + break; + } + if( !bBreak ) + return rListVector.sCharStyleName; + } + } + return OUString(); +} + +void StyleSheetTable_Impl::AppendLatentStyleProperty(const OUString& aName, Value const & rValue) +{ + beans::PropertyValue aValue; + aValue.Name = aName; + aValue.Value <<= rValue.getString(); + m_pCurrentEntry->aLatentStyles.push_back(aValue); +} + +void StyleSheetTable_Impl::SetPropertiesToDefault(const uno::Reference& xStyle) +{ + // See if the existing style has any non-default properties. If so, reset them back to default. + uno::Reference xPropertySet(xStyle, uno::UNO_QUERY); + uno::Reference xPropertySetInfo = xPropertySet->getPropertySetInfo(); + uno::Sequence aProperties = xPropertySetInfo->getProperties(); + std::vector aPropertyNames; + aPropertyNames.reserve(aProperties.getLength()); + std::transform(aProperties.begin(), aProperties.end(), std::back_inserter(aPropertyNames), + [](const beans::Property& rProp) { return rProp.Name; }); + + uno::Reference xPropertyState(xStyle, uno::UNO_QUERY); + uno::Sequence aStates = xPropertyState->getPropertyStates(comphelper::containerToSequence(aPropertyNames)); + for (sal_Int32 i = 0; i < aStates.getLength(); ++i) + { + if (aStates[i] == beans::PropertyState_DIRECT_VALUE) + { + try + { + xPropertyState->setPropertyToDefault(aPropertyNames[i]); + } + catch(const uno::Exception&) + { + TOOLS_INFO_EXCEPTION("writerfilter", "setPropertyToDefault(" << aPropertyNames[i] << ") failed"); + } + } + } +} + +StyleSheetTable::StyleSheetTable(DomainMapper& rDMapper, + uno::Reference< text::XTextDocument> const& xTextDocument, + bool const bIsNewDoc) +: LoggedProperties("StyleSheetTable") +, LoggedTable("StyleSheetTable") +, m_pImpl( new StyleSheetTable_Impl(rDMapper, xTextDocument, bIsNewDoc) ) +{ +} + + +StyleSheetTable::~StyleSheetTable() +{ +} + +void StyleSheetTable::SetDefaultParaProps(PropertyIds eId, const css::uno::Any& rAny) +{ + m_pImpl->m_pDefaultParaProps->Insert(eId, rAny, /*bOverwrite=*/false, NO_GRAB_BAG, /*bDocDefault=*/true); +} + +PropertyMapPtr const & StyleSheetTable::GetDefaultParaProps() const +{ + return m_pImpl->m_pDefaultParaProps; +} + +PropertyMapPtr const & StyleSheetTable::GetDefaultCharProps() const +{ + return m_pImpl->m_pDefaultCharProps; +} + +void StyleSheetTable::lcl_attribute(Id Name, Value & val) +{ + OSL_ENSURE( m_pImpl->m_pCurrentEntry, "current entry has to be set here"); + if(!m_pImpl->m_pCurrentEntry) + return ; + int nIntValue = val.getInt(); + OUString sValue = val.getString(); + + // The default type is paragraph, and it needs to be processed first, + // because the NS_ooxml::LN_CT_Style_type handling may set m_pImpl->m_pCurrentEntry + // to point to a different object. + if( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_UNKNOWN ) + { + if( Name != NS_ooxml::LN_CT_Style_type ) + m_pImpl->m_pCurrentEntry->nStyleTypeCode = STYLE_TYPE_PARA; + } + switch(Name) + { + case NS_ooxml::LN_CT_Style_type: + { + SAL_WARN_IF( m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN, + "writerfilter", "Style type needs to be processed first" ); + StyleType nType(STYLE_TYPE_UNKNOWN); + switch (nIntValue) + { + case NS_ooxml::LN_Value_ST_StyleType_paragraph: + nType = STYLE_TYPE_PARA; + break; + case NS_ooxml::LN_Value_ST_StyleType_character: + nType = STYLE_TYPE_CHAR; + break; + case NS_ooxml::LN_Value_ST_StyleType_table: + nType = STYLE_TYPE_TABLE; + break; + case NS_ooxml::LN_Value_ST_StyleType_numbering: + nType = STYLE_TYPE_LIST; + break; + default: + SAL_WARN("writerfilter", "unknown LN_CT_Style_type " << nType); + [[fallthrough]]; + case 0: // explicit unknown set by tokenizer + break; + + } + if ( nType == STYLE_TYPE_TABLE ) + { + StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry; + tools::SvRef pTableEntry( new TableStyleSheetEntry( *pEntry ) ); + m_pImpl->m_pCurrentEntry = pTableEntry.get(); + } + else + m_pImpl->m_pCurrentEntry->nStyleTypeCode = nType; + } + break; + case NS_ooxml::LN_CT_Style_default: + m_pImpl->m_pCurrentEntry->bIsDefaultStyle = (nIntValue != 0); + + if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN) + { + // "If this attribute is specified by multiple styles, then the last instance shall be used." + if ( m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_PARA && !m_pImpl->m_pCurrentEntry->sStyleIdentifierD.isEmpty() ) + m_pImpl->m_sDefaultParaStyleName = m_pImpl->m_pCurrentEntry->sStyleIdentifierD; + + beans::PropertyValue aValue; + aValue.Name = "default"; + aValue.Value <<= m_pImpl->m_pCurrentEntry->bIsDefaultStyle; + m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue); + } + break; + case NS_ooxml::LN_CT_Style_customStyle: + if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN) + { + beans::PropertyValue aValue; + aValue.Name = "customStyle"; + aValue.Value <<= (nIntValue != 0); + m_pImpl->m_pCurrentEntry->AppendInteropGrabBag(aValue); + } + break; + case NS_ooxml::LN_CT_Style_styleId: + m_pImpl->m_pCurrentEntry->sStyleIdentifierD = sValue; + if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE) + { + TableStyleSheetEntry* pTableEntry = static_cast(m_pImpl->m_pCurrentEntry.get()); + beans::PropertyValue aValue; + aValue.Name = "styleId"; + aValue.Value <<= sValue; + pTableEntry->AppendInteropGrabBag(aValue); + } + break; + case NS_ooxml::LN_CT_TblWidth_w: + break; + case NS_ooxml::LN_CT_TblWidth_type: + break; + case NS_ooxml::LN_CT_LatentStyles_defQFormat: + m_pImpl->AppendLatentStyleProperty("defQFormat", val); + break; + case NS_ooxml::LN_CT_LatentStyles_defUnhideWhenUsed: + m_pImpl->AppendLatentStyleProperty("defUnhideWhenUsed", val); + break; + case NS_ooxml::LN_CT_LatentStyles_defSemiHidden: + m_pImpl->AppendLatentStyleProperty("defSemiHidden", val); + break; + case NS_ooxml::LN_CT_LatentStyles_count: + m_pImpl->AppendLatentStyleProperty("count", val); + break; + case NS_ooxml::LN_CT_LatentStyles_defUIPriority: + m_pImpl->AppendLatentStyleProperty("defUIPriority", val); + break; + case NS_ooxml::LN_CT_LatentStyles_defLockedState: + m_pImpl->AppendLatentStyleProperty("defLockedState", val); + break; + default: + { +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + } + break; + } +} + + +void StyleSheetTable::lcl_sprm(Sprm & rSprm) +{ + sal_uInt32 nSprmId = rSprm.getId(); + Value::Pointer_t pValue = rSprm.getValue(); + sal_Int32 nIntValue = pValue ? pValue->getInt() : 0; + OUString sStringValue = pValue ? pValue->getString() : OUString(); + + switch(nSprmId) + { + case NS_ooxml::LN_CT_Style_name: + //this is only a UI name! + m_pImpl->m_pCurrentEntry->sStyleName = sStringValue; + if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE) + { + TableStyleSheetEntry* pTableEntry = static_cast(m_pImpl->m_pCurrentEntry.get()); + beans::PropertyValue aValue; + aValue.Name = "name"; + aValue.Value <<= sStringValue; + pTableEntry->AppendInteropGrabBag(aValue); + } + break; + case NS_ooxml::LN_CT_Style_basedOn: + m_pImpl->m_pCurrentEntry->sBaseStyleIdentifier = sStringValue; + if(m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE) + { + TableStyleSheetEntry* pTableEntry = static_cast(m_pImpl->m_pCurrentEntry.get()); + beans::PropertyValue aValue; + aValue.Name = "basedOn"; + aValue.Value <<= sStringValue; + pTableEntry->AppendInteropGrabBag(aValue); + } + break; + case NS_ooxml::LN_CT_Style_next: + m_pImpl->m_pCurrentEntry->sNextStyleIdentifier = sStringValue; + break; + case NS_ooxml::LN_CT_Style_aliases: + case NS_ooxml::LN_CT_Style_hidden: + case NS_ooxml::LN_CT_Style_personal: + case NS_ooxml::LN_CT_Style_personalCompose: + case NS_ooxml::LN_CT_Style_personalReply: + break; + case NS_ooxml::LN_CT_Style_autoRedefine: + m_pImpl->m_pCurrentEntry->bAutoRedefine = nIntValue; + break; + case NS_ooxml::LN_CT_Style_tcPr: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties && m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE) + { + auto pTblStylePrHandler = std::make_shared(m_pImpl->m_rDMapper); + pProperties->resolve(*pTblStylePrHandler); + StyleSheetEntry* pEntry = m_pImpl->m_pCurrentEntry.get(); + TableStyleSheetEntry& rTableEntry = dynamic_cast(*pEntry); + rTableEntry.AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tcPr")); + + // This is a directly under , so it affects the whole table. + rTableEntry.pProperties->InsertProps(pTblStylePrHandler->getProperties()); + } + } + break; + case NS_ooxml::LN_CT_Style_trPr: + break; + case NS_ooxml::LN_CT_Style_rsid: + case NS_ooxml::LN_CT_Style_qFormat: + case NS_ooxml::LN_CT_Style_semiHidden: + case NS_ooxml::LN_CT_Style_unhideWhenUsed: + case NS_ooxml::LN_CT_Style_uiPriority: + case NS_ooxml::LN_CT_Style_link: + case NS_ooxml::LN_CT_Style_locked: + if (m_pImpl->m_pCurrentEntry->nStyleTypeCode != STYLE_TYPE_UNKNOWN) + { + StyleSheetEntryPtr pEntry = m_pImpl->m_pCurrentEntry; + beans::PropertyValue aValue; + switch (nSprmId) + { + case NS_ooxml::LN_CT_Style_rsid: + { + // We want the rsid as a hex string, but always with the length of 8. + OUStringBuffer aBuf = OUString::number(nIntValue, 16); + OUStringBuffer aStr; + comphelper::string::padToLength(aStr, 8 - aBuf.getLength(), '0'); + aStr.append(aBuf.getStr()); + + aValue.Name = "rsid"; + aValue.Value <<= aStr.makeStringAndClear(); + } + break; + case NS_ooxml::LN_CT_Style_qFormat: + aValue.Name = "qFormat"; + break; + case NS_ooxml::LN_CT_Style_semiHidden: + aValue.Name = "semiHidden"; + break; + case NS_ooxml::LN_CT_Style_unhideWhenUsed: + aValue.Name = "unhideWhenUsed"; + break; + case NS_ooxml::LN_CT_Style_uiPriority: + { + aValue.Name = "uiPriority"; + aValue.Value <<= OUString::number(nIntValue); + } + break; + case NS_ooxml::LN_CT_Style_link: + { + aValue.Name = "link"; + aValue.Value <<= sStringValue; + } + break; + case NS_ooxml::LN_CT_Style_locked: + aValue.Name = "locked"; + break; + } + pEntry->AppendInteropGrabBag(aValue); + } + break; + case NS_ooxml::LN_CT_Style_tblPr: //contains table properties + case NS_ooxml::LN_CT_Style_tblStylePr: //contains to table properties + case NS_ooxml::LN_CT_TblPrBase_tblInd: //table properties - at least width value and type + case NS_ooxml::LN_EG_RPrBase_rFonts: //table fonts + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pTblStylePrHandler = std::make_shared( m_pImpl->m_rDMapper ); + pProperties->resolve( *pTblStylePrHandler ); + + // Add the properties to the table style + TblStyleType nType = pTblStylePrHandler->getType( ); + PropertyMapPtr pProps = pTblStylePrHandler->getProperties( ); + StyleSheetEntry * pEntry = m_pImpl->m_pCurrentEntry.get(); + + TableStyleSheetEntry * pTableEntry = dynamic_cast( pEntry ); + if (nType == TBL_STYLE_UNKNOWN) + { + pEntry->pProperties->InsertProps(pProps); + } + else + { + if (pTableEntry != nullptr) + pTableEntry->AddTblStylePr( nType, pProps ); + } + + if (nSprmId == NS_ooxml::LN_CT_Style_tblPr) + { + if (pTableEntry != nullptr) + pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblPr")); + } + else if (nSprmId == NS_ooxml::LN_CT_Style_tblStylePr) + { + pTblStylePrHandler->appendInteropGrabBag("type", pTblStylePrHandler->getTypeString()); + if (pTableEntry != nullptr) + pTableEntry->AppendInteropGrabBag(pTblStylePrHandler->getInteropGrabBag("tblStylePr")); + } + } + break; + } + case NS_ooxml::LN_CT_PPrDefault_pPr: + case NS_ooxml::LN_CT_DocDefaults_pPrDefault: + m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultParaProps ); + resolveSprmProps( m_pImpl->m_rDMapper, rSprm ); + if ( nSprmId == NS_ooxml::LN_CT_DocDefaults_pPrDefault && m_pImpl->m_pDefaultParaProps && + !m_pImpl->m_pDefaultParaProps->isSet( PROP_PARA_TOP_MARGIN ) ) + { + SetDefaultParaProps( PROP_PARA_TOP_MARGIN, uno::makeAny( sal_Int32(0) ) ); + } + m_pImpl->m_rDMapper.PopStyleSheetProperties(); + applyDefaults( true ); + m_pImpl->m_bHasImportedDefaultParaProps = true; + break; + case NS_ooxml::LN_CT_RPrDefault_rPr: + case NS_ooxml::LN_CT_DocDefaults_rPrDefault: + m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pDefaultCharProps ); + resolveSprmProps( m_pImpl->m_rDMapper, rSprm ); + m_pImpl->m_rDMapper.PopStyleSheetProperties(); + applyDefaults( false ); + break; + case NS_ooxml::LN_CT_TblPrBase_jc: //table alignment - row properties! + m_pImpl->m_pCurrentEntry->pProperties->Insert( PROP_HORI_ORIENT, + uno::makeAny( ConversionHelper::convertTableJustification( nIntValue ))); + break; + case NS_ooxml::LN_CT_TrPrBase_jc: //table alignment - row properties! + break; + case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pBorderHandler = std::make_shared(m_pImpl->m_rDMapper.IsOOXMLImport()); + pProperties->resolve(*pBorderHandler); + m_pImpl->m_pCurrentEntry->pProperties->InsertProps( + pBorderHandler->getProperties()); + } + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize: + case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize: + break; + case NS_ooxml::LN_CT_TblPrBase_tblCellMar: + //no cell margins in styles + break; + case NS_ooxml::LN_CT_LatentStyles_lsdException: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + tools::SvRef pLatentStyleHandler(new LatentStyleHandler()); + pProperties->resolve(*pLatentStyleHandler); + beans::PropertyValue aValue; + aValue.Name = "lsdException"; + aValue.Value <<= comphelper::containerToSequence(pLatentStyleHandler->getAttributes()); + m_pImpl->m_pCurrentEntry->aLsdExceptions.push_back(aValue); + } + } + break; + case NS_ooxml::LN_CT_Style_pPr: + // no break + case NS_ooxml::LN_CT_Style_rPr: + // no break + default: + { + if (!m_pImpl->m_pCurrentEntry) + break; + + tools::SvRef pTblHandler(new TablePropertiesHandler()); + pTblHandler->SetProperties( m_pImpl->m_pCurrentEntry->pProperties ); + if ( !pTblHandler->sprm( rSprm ) ) + { + m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties ); + + PropertyMapPtr pProps(new PropertyMap()); + if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE) + { + if (nSprmId == NS_ooxml::LN_CT_Style_pPr) + m_pImpl->m_rDMapper.enableInteropGrabBag("pPr"); + else if (nSprmId == NS_ooxml::LN_CT_Style_rPr) + m_pImpl->m_rDMapper.enableInteropGrabBag("rPr"); + } + m_pImpl->m_rDMapper.sprmWithProps( rSprm, pProps ); + if (m_pImpl->m_pCurrentEntry->nStyleTypeCode == STYLE_TYPE_TABLE) + { + if (nSprmId == NS_ooxml::LN_CT_Style_pPr || nSprmId == NS_ooxml::LN_CT_Style_rPr) + { + TableStyleSheetEntry* pTableEntry = static_cast(m_pImpl->m_pCurrentEntry.get()); + pTableEntry->AppendInteropGrabBag(m_pImpl->m_rDMapper.getInteropGrabBag()); + } + } + + m_pImpl->m_pCurrentEntry->pProperties->InsertProps(pProps); + + m_pImpl->m_rDMapper.PopStyleSheetProperties( ); + } + } + break; +} +} + + +void StyleSheetTable::lcl_entry(writerfilter::Reference::Pointer_t ref) +{ + //create a new style entry + OSL_ENSURE( !m_pImpl->m_pCurrentEntry, "current entry has to be NULL here"); + StyleSheetEntryPtr pNewEntry( new StyleSheetEntry ); + m_pImpl->m_pCurrentEntry = pNewEntry; + m_pImpl->m_rDMapper.PushStyleSheetProperties( m_pImpl->m_pCurrentEntry->pProperties ); + ref->resolve(*this); + //append it to the table + m_pImpl->m_rDMapper.PopStyleSheetProperties(); + if( !m_pImpl->m_rDMapper.IsOOXMLImport() || !m_pImpl->m_pCurrentEntry->sStyleName.isEmpty()) + { + m_pImpl->m_pCurrentEntry->sConvertedStyleName = ConvertStyleName( m_pImpl->m_pCurrentEntry->sStyleName ); + m_pImpl->m_aStyleSheetEntries.push_back( m_pImpl->m_pCurrentEntry ); + } + else + { + //TODO: this entry contains the default settings - they have to be added to the settings + } + + if (!m_pImpl->m_pCurrentEntry->aLatentStyles.empty()) + { + // We have latent styles for this entry, then process them. + std::vector& rLatentStyles = m_pImpl->m_pCurrentEntry->aLatentStyles; + + if (!m_pImpl->m_pCurrentEntry->aLsdExceptions.empty()) + { + std::vector& rLsdExceptions = m_pImpl->m_pCurrentEntry->aLsdExceptions; + beans::PropertyValue aValue; + aValue.Name = "lsdExceptions"; + aValue.Value <<= comphelper::containerToSequence(rLsdExceptions); + rLatentStyles.push_back(aValue); + } + + uno::Sequence aLatentStyles( comphelper::containerToSequence(rLatentStyles) ); + + // We can put all latent style info directly to the document interop + // grab bag, as we can be sure that only a single style entry has + // latent style info. + uno::Reference xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY); + auto aGrabBag = comphelper::sequenceToContainer< std::vector >(xPropertySet->getPropertyValue("InteropGrabBag").get< uno::Sequence >()); + beans::PropertyValue aValue; + aValue.Name = "latentStyles"; + aValue.Value <<= aLatentStyles; + aGrabBag.push_back(aValue); + xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(comphelper::containerToSequence(aGrabBag))); + } + + StyleSheetEntryPtr pEmptyEntry; + m_pImpl->m_pCurrentEntry = pEmptyEntry; +} +/*------------------------------------------------------------------------- + sorting helper + -----------------------------------------------------------------------*/ +namespace { + +class PropValVector +{ + std::vector m_aValues; +public: + PropValVector(){} + + void Insert(const beans::PropertyValue& rVal); + uno::Sequence< uno::Any > getValues(); + uno::Sequence< OUString > getNames(); + const std::vector& getProperties() const { return m_aValues; }; +}; + +} + +void PropValVector::Insert(const beans::PropertyValue& rVal) +{ + auto aIt = std::find_if(m_aValues.begin(), m_aValues.end(), + [&rVal](beans::PropertyValue& rPropVal) { return rPropVal.Name > rVal.Name; }); + if (aIt != m_aValues.end()) + { + m_aValues.insert( aIt, rVal ); + return; + } + m_aValues.push_back(rVal); +} + +uno::Sequence< uno::Any > PropValVector::getValues() +{ + std::vector aRet; + std::transform(m_aValues.begin(), m_aValues.end(), std::back_inserter(aRet), [](const beans::PropertyValue& rValue) { return rValue.Value; }); + return comphelper::containerToSequence(aRet); +} + +uno::Sequence< OUString > PropValVector::getNames() +{ + std::vector aRet; + std::transform(m_aValues.begin(), m_aValues.end(), std::back_inserter(aRet), [](const beans::PropertyValue& rValue) { return rValue.Name; }); + return comphelper::containerToSequence(aRet); +} + +void StyleSheetTable::ApplyNumberingStyleNameToParaStyles() +{ + try + { + uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xParaStyles; + xStyleFamilies->getByName(getPropertyName( PROP_PARAGRAPH_STYLES )) >>= xParaStyles; + + if ( !xParaStyles.is() ) + return; + + for ( auto& pEntry : m_pImpl->m_aStyleSheetEntries ) + { + StyleSheetPropertyMap* pStyleSheetProperties = nullptr; + if ( pEntry->nStyleTypeCode == STYLE_TYPE_PARA && (pStyleSheetProperties = dynamic_cast(pEntry->pProperties.get())) ) + { + // ListId 0 means turn off numbering - to cancel inheritance - so make sure that can be set. + // Ignore the special "chapter numbering" outline styles as they are handled internally. + if ( pStyleSheetProperties->GetListId() > -1 && pStyleSheetProperties->GetOutlineLevel() == -1 ) + { + uno::Reference< style::XStyle > xStyle; + xParaStyles->getByName( ConvertStyleName(pEntry->sStyleName) ) >>= xStyle; + + if ( !xStyle.is() ) + break; + + uno::Reference xPropertySet( xStyle, uno::UNO_QUERY_THROW ); + const OUString sNumberingStyleName = m_pImpl->m_rDMapper.GetListStyleName( pStyleSheetProperties->GetListId() ); + if ( !sNumberingStyleName.isEmpty() || !pStyleSheetProperties->GetListId() ) + xPropertySet->setPropertyValue( getPropertyName(PROP_NUMBERING_STYLE_NAME), uno::makeAny(sNumberingStyleName) ); + } + } + } + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "Failed applying numbering style name to Paragraph styles"); + } +} + +void StyleSheetTable::ApplyStyleSheets( const FontTablePtr& rFontTable ) +{ + try + { + uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xCharStyles; + uno::Reference xParaStyles; + uno::Reference xNumberingStyles; + + xStyleFamilies->getByName(getPropertyName( PROP_CHARACTER_STYLES )) >>= xCharStyles; + xStyleFamilies->getByName(getPropertyName( PROP_PARAGRAPH_STYLES )) >>= xParaStyles; + xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles; + if(xCharStyles.is() && xParaStyles.is()) + { + std::vector< ::std::pair> > aMissingParent; + std::vector< ::std::pair> > aMissingFollow; + std::vector aTableStylesVec; + for( auto& pEntry : m_pImpl->m_aStyleSheetEntries ) + { + if( pEntry->nStyleTypeCode == STYLE_TYPE_CHAR || pEntry->nStyleTypeCode == STYLE_TYPE_PARA || pEntry->nStyleTypeCode == STYLE_TYPE_LIST ) + { + bool bParaStyle = pEntry->nStyleTypeCode == STYLE_TYPE_PARA; + bool bListStyle = pEntry->nStyleTypeCode == STYLE_TYPE_LIST; + bool bInsert = false; + uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : (bListStyle ? xNumberingStyles : xCharStyles); + uno::Reference< style::XStyle > xStyle; + const OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName ); + + if(xStyles->hasByName( sConvertedStyleName )) + { + // When pasting, don't update existing styles. + if (!m_pImpl->m_bIsNewDoc) + { + continue; + } + xStyles->getByName( sConvertedStyleName ) >>= xStyle; + + { + StyleSheetTable_Impl::SetPropertiesToDefault(xStyle); + + // resolve import conflicts with built-in styles (only if defaults have been defined) + if ( m_pImpl->m_bHasImportedDefaultParaProps + && pEntry->sBaseStyleIdentifier.isEmpty() //imported style has no inheritance + && !xStyle->getParentStyle().isEmpty() ) //built-in style has a default inheritance + { + xStyle->setParentStyle( "" ); + } + } + } + else + { + bInsert = true; + xStyle.set(xDocFactory->createInstance( + bParaStyle ? + getPropertyName( PROP_SERVICE_PARA_STYLE ) : + (bListStyle ? OUString("com.sun.star.style.NumberingStyle") : getPropertyName( PROP_SERVICE_CHAR_STYLE ))), + uno::UNO_QUERY_THROW); + + // Numbering styles have to be inserted early, as e.g. the NumberingRules property is only available after insertion. + if (bListStyle) + { + xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle ) ); + xStyle.set(xStyles->getByName(sConvertedStyleName), uno::UNO_QUERY_THROW); + + StyleSheetPropertyMap* pPropertyMap = dynamic_cast(pEntry->pProperties.get()); + if (pPropertyMap && pPropertyMap->GetListId() == -1) + { + // No properties? Word default is 'none', Writer one is 'arabic', handle this. + uno::Reference xPropertySet(xStyle, uno::UNO_QUERY_THROW); + uno::Reference xNumberingRules; + xPropertySet->getPropertyValue("NumberingRules") >>= xNumberingRules; + uno::Reference xIndexAccess(xNumberingRules, uno::UNO_QUERY_THROW); + for (sal_Int32 i = 0; i < xIndexAccess->getCount(); ++i) + { + uno::Sequence< beans::PropertyValue > aLvlProps(1); + aLvlProps[0].Name = "NumberingType"; + aLvlProps[0].Value <<= style::NumberingType::NUMBER_NONE; + xNumberingRules->replaceByIndex(i, uno::makeAny(aLvlProps)); + xPropertySet->setPropertyValue("NumberingRules", uno::makeAny(xNumberingRules)); + } + } + } + } + if( !pEntry->sBaseStyleIdentifier.isEmpty() ) + { + try + { + //TODO: Handle cases where a paragraph <> character style relation is needed + StyleSheetEntryPtr pParent = FindStyleSheetByISTD( pEntry->sBaseStyleIdentifier ); + // Writer core doesn't support numbering styles having a parent style, it seems + if (pParent.get() != nullptr && !bListStyle) + { + const OUString sParentStyleName = ConvertStyleName( pParent->sStyleName ); + if ( !sParentStyleName.isEmpty() && !xStyles->hasByName( sParentStyleName ) ) + aMissingParent.emplace_back( sParentStyleName, xStyle ); + else + xStyle->setParentStyle( sParentStyleName ); + } + } + catch( const uno::RuntimeException& ) + { + OSL_FAIL( "Styles parent could not be set"); + } + } + else if( bParaStyle ) + { + // Paragraph styles that don't inherit from some parent need to apply the DocDefaults + pEntry->pProperties->InsertProps( m_pImpl->m_pDefaultParaProps, /*bOverwrite=*/false ); + + //now it's time to set the default parameters - for paragraph styles + //Fonts: Western first entry in font table + //CJK: second entry + //CTL: third entry, if it exists + + sal_uInt32 nFontCount = rFontTable->size(); + if( !m_pImpl->m_rDMapper.IsOOXMLImport() && nFontCount > 2 ) + { + uno::Any aTwoHundredFortyTwip = uno::makeAny(12.); + + // font size to 240 twip (12 pts) for all if not set + pEntry->pProperties->Insert(PROP_CHAR_HEIGHT, aTwoHundredFortyTwip, false); + + // western font not already set -> apply first font + const FontEntry::Pointer_t pWesternFontEntry(rFontTable->getFontEntry( 0 )); + OUString sWesternFontName = pWesternFontEntry->sFontName; + pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( sWesternFontName ), false); + + // CJK ... apply second font + const FontEntry::Pointer_t pCJKFontEntry(rFontTable->getFontEntry( 2 )); + pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_ASIAN, uno::makeAny( pCJKFontEntry->sFontName ), false); + pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_ASIAN, aTwoHundredFortyTwip, false); + + // CTL ... apply third font, if available + if( nFontCount > 3 ) + { + const FontEntry::Pointer_t pCTLFontEntry(rFontTable->getFontEntry( 3 )); + pEntry->pProperties->Insert(PROP_CHAR_FONT_NAME_COMPLEX, uno::makeAny( pCTLFontEntry->sFontName ), false); + pEntry->pProperties->Insert(PROP_CHAR_HEIGHT_COMPLEX, aTwoHundredFortyTwip, false); + } + } + } + + auto aPropValues = comphelper::sequenceToContainer< std::vector >(pEntry->pProperties->GetPropertyValues()); + + if( bParaStyle ) + { + // delay adding FollowStyle property: all styles need to be created first + if ( !pEntry->sNextStyleIdentifier.isEmpty() ) + { + StyleSheetEntryPtr pFollowStyle = FindStyleSheetByISTD( pEntry->sNextStyleIdentifier ); + if ( pFollowStyle && !pFollowStyle->sStyleName.isEmpty() ) + aMissingFollow.emplace_back( ConvertStyleName( pFollowStyle->sStyleName ), xStyle ); + } + + // Set the outline levels + StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast(pEntry ? pEntry->pProperties.get() : nullptr); + + if ( pStyleSheetProperties ) + { + beans::PropertyValue aLvlVal( getPropertyName( PROP_OUTLINE_LEVEL ), 0, + uno::makeAny( sal_Int16( pStyleSheetProperties->GetOutlineLevel( ) + 1 ) ), + beans::PropertyState_DIRECT_VALUE ); + aPropValues.push_back(aLvlVal); + + // tdf#95495 missing list level settings in custom styles in old DOCX: apply settings of the parent style + if (pStyleSheetProperties->GetListLevel() == -1 && pStyleSheetProperties->GetOutlineLevel() == -1) + { + const beans::PropertyValues aPropGrabBag = pEntry->GetInteropGrabBagSeq(); + for (const auto& rVal : aPropGrabBag) + { + if (rVal.Name == "customStyle" && rVal.Value == true) + { + OUString sBaseId = pEntry->sBaseStyleIdentifier; + for (const auto& aSheetProps : m_pImpl->m_aStyleSheetEntries) + { + if (aSheetProps->sStyleIdentifierD == sBaseId) + { + StyleSheetPropertyMap& rStyleSheetProps + = dynamic_cast(*aSheetProps->pProperties); + pStyleSheetProperties->SetListLevel(rStyleSheetProps.GetListLevel()); + pStyleSheetProperties->SetOutlineLevel(rStyleSheetProps.GetOutlineLevel()); + break; + } + } + } + } + } + } + + uno::Reference< beans::XPropertyState >xState( xStyle, uno::UNO_QUERY_THROW ); + if( sConvertedStyleName == "Contents Heading" || + sConvertedStyleName == "User Index Heading" || + sConvertedStyleName == "Index Heading" ) + { + // remove Left/RightMargin values from TOX heading styles + //left margin is set to NULL by default + xState->setPropertyToDefault(getPropertyName( PROP_PARA_LEFT_MARGIN )); + } + else if ( sConvertedStyleName == "Text body" ) + xState->setPropertyToDefault(getPropertyName( PROP_PARA_BOTTOM_MARGIN )); + else if ( sConvertedStyleName == "Heading 1" || + sConvertedStyleName == "Heading 2" || + sConvertedStyleName == "Heading 3" || + sConvertedStyleName == "Heading 4" || + sConvertedStyleName == "Heading 5" || + sConvertedStyleName == "Heading 6" || + sConvertedStyleName == "Heading 7" || + sConvertedStyleName == "Heading 8" || + sConvertedStyleName == "Heading 9" ) + { + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT_ASIAN )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_WEIGHT_COMPLEX )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE_ASIAN )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_POSTURE_COMPLEX )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT_ASIAN )); + xState->setPropertyToDefault(getPropertyName( PROP_CHAR_PROP_HEIGHT_COMPLEX)); + + } + } + + if ( !aPropValues.empty() ) + { + PropValVector aSortedPropVals; + for (const beans::PropertyValue& rValue : aPropValues) + { + // Don't add the style name properties + bool bIsParaStyleName = rValue.Name == "ParaStyleName"; + bool bIsCharStyleName = rValue.Name == "CharStyleName"; + if ( !bIsParaStyleName && !bIsCharStyleName ) + { + aSortedPropVals.Insert(rValue); + } + } + + try + { + uno::Reference< beans::XMultiPropertySet > xMultiPropertySet( xStyle, uno::UNO_QUERY_THROW); + try + { + xMultiPropertySet->setPropertyValues( aSortedPropVals.getNames(), aSortedPropVals.getValues() ); + } + catch ( const uno::Exception& ) + { + uno::Reference xPropertySet(xStyle, uno::UNO_QUERY_THROW); + for ( const beans::PropertyValue& rValue : aSortedPropVals.getProperties() ) + { + try + { + xPropertySet->setPropertyValue( rValue.Name, rValue.Value ); + } + catch ( const uno::Exception& ) + { + SAL_WARN( "writerfilter", "StyleSheetTable::ApplyStyleSheets could not set property " << rValue.Name ); + } + } + } + // Duplicate MSWord's single footnote reference into Footnote Characters and Footnote anchor + if( pEntry->sStyleName.equalsIgnoreAsciiCase("footnote reference") + || pEntry->sStyleName.equalsIgnoreAsciiCase("endnote reference") ) + { + uno::Reference< style::XStyle > xCopyStyle; + if( pEntry->sStyleName.equalsIgnoreAsciiCase("footnote reference") ) + xStyles->getByName( "Footnote anchor" ) >>= xCopyStyle; + else + xStyles->getByName( "Endnote anchor" ) >>= xCopyStyle; + + xMultiPropertySet.set( xCopyStyle, uno::UNO_QUERY_THROW); + xMultiPropertySet->setPropertyValues( aSortedPropVals.getNames(), aSortedPropVals.getValues() ); + } + } + catch( const lang::WrappedTargetException& rWrapped) + { +#ifdef DBG_UTIL + OUString aMessage("StyleSheetTable::ApplyStyleSheets: Some style properties could not be set"); + beans::UnknownPropertyException aUnknownPropertyException; + + if (rWrapped.TargetException >>= aUnknownPropertyException) + aMessage += ": " + aUnknownPropertyException.Message; + + SAL_WARN("writerfilter", aMessage); +#else + (void) rWrapped; +#endif + } + catch( const uno::Exception& ) + { + OSL_FAIL( "Some style properties could not be set"); + } + } + // Numbering style got inserted earlier. + if(bInsert && !bListStyle) + { + const OUString sParentStyle = xStyle->getParentStyle(); + if( !sParentStyle.isEmpty() && !xStyles->hasByName( sParentStyle ) ) + aMissingParent.emplace_back( sParentStyle, xStyle ); + + xStyles->insertByName( sConvertedStyleName, uno::makeAny( xStyle) ); + } + + beans::PropertyValues aGrabBag = pEntry->GetInteropGrabBagSeq(); + uno::Reference xPropertySet(xStyle, uno::UNO_QUERY); + if (aGrabBag.hasElements()) + { + xPropertySet->setPropertyValue("StyleInteropGrabBag", uno::makeAny(aGrabBag)); + } + + // Only paragraph styles support automatic updates. + if (pEntry->bAutoRedefine && bParaStyle) + xPropertySet->setPropertyValue("IsAutoUpdate", uno::makeAny(true)); + } + else if(pEntry->nStyleTypeCode == STYLE_TYPE_TABLE) + { + // If this is a table style, save its contents as-is for roundtrip purposes. + TableStyleSheetEntry* pTableEntry = static_cast(pEntry.get()); + aTableStylesVec.push_back(pTableEntry->GetInteropGrabBag()); + + // if DocDefaults exist, MS Word includes these in the table style definition. + pEntry->pProperties->InsertProps( m_pImpl->m_pDefaultCharProps, /*bOverwrite=*/false ); + pEntry->pProperties->InsertProps( m_pImpl->m_pDefaultParaProps, /*bOverwrite=*/false ); + } + } + + // Update the styles that were created before their parents or next-styles + for( auto const & iter : aMissingParent ) + { + iter.second->setParentStyle( iter.first ); + } + + for( auto const & iter : aMissingFollow ) + { + try + { + uno::Reference xPropertySet(iter.second, uno::UNO_QUERY); + xPropertySet->setPropertyValue( "FollowStyle", uno::makeAny(iter.first) ); + } + catch( uno::Exception & ) {} + } + + if (!aTableStylesVec.empty()) + { + // If we had any table styles, add a new document-level InteropGrabBag entry for them. + uno::Reference xPropertySet(m_pImpl->m_xTextDocument, uno::UNO_QUERY); + uno::Any aAny = xPropertySet->getPropertyValue("InteropGrabBag"); + auto aGrabBag = comphelper::sequenceToContainer< std::vector >(aAny.get< uno::Sequence >()); + beans::PropertyValue aValue; + aValue.Name = "tableStyles"; + aValue.Value <<= comphelper::containerToSequence(aTableStylesVec); + aGrabBag.push_back(aValue); + xPropertySet->setPropertyValue("InteropGrabBag", uno::makeAny(comphelper::containerToSequence(aGrabBag))); + } + } + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION("writerfilter", "Styles could not be imported completely"); + } +} + + +StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByISTD(const OUString& sIndex) +{ + StyleSheetEntryPtr pRet; + for(const StyleSheetEntryPtr & rpEntry : m_pImpl->m_aStyleSheetEntries) + { + if( rpEntry->sStyleIdentifierD == sIndex) + { + pRet = rpEntry; + break; + } + } + return pRet; +} + + +StyleSheetEntryPtr StyleSheetTable::FindStyleSheetByConvertedStyleName(const OUString& sIndex) +{ + StyleSheetEntryPtr pRet; + for(const StyleSheetEntryPtr & rpEntry : m_pImpl->m_aStyleSheetEntries) + { + if( rpEntry->sConvertedStyleName == sIndex) + { + pRet = rpEntry; + break; + } + } + return pRet; +} + + +StyleSheetEntryPtr StyleSheetTable::FindDefaultParaStyle() +{ + return FindStyleSheetByISTD( m_pImpl->m_sDefaultParaStyleName ); +} + +const StyleSheetEntryPtr & StyleSheetTable::GetCurrentEntry() const +{ + return m_pImpl->m_pCurrentEntry; +} + +OUString StyleSheetTable::ConvertStyleName( const OUString& rWWName, bool bExtendedSearch) +{ + OUString sRet( rWWName ); + if( bExtendedSearch ) + { + //search for the rWWName in the IdentifierD of the existing styles and convert the sStyleName member + //TODO: performance issue - put styles list into a map sorted by its sStyleIdentifierD members + for( const auto& rStyleSheetEntryPtr : m_pImpl->m_aStyleSheetEntries ) + { + if( rWWName == rStyleSheetEntryPtr->sStyleIdentifierD ) + sRet = rStyleSheetEntryPtr->sStyleName; + } + } + + // create a map only once + static const std::map< OUString, OUString> StyleNameMap { + { "Normal", "Standard" }, + { "heading 1", "Heading 1" }, + { "heading 2", "Heading 2" }, + { "heading 3", "Heading 3" }, + { "heading 4", "Heading 4" }, + { "heading 5", "Heading 5" }, + { "heading 6", "Heading 6" }, + { "heading 7", "Heading 7" }, + { "heading 8", "Heading 8" }, + { "heading 9", "Heading 9" }, + { "Heading 1", "Heading 1" }, + { "Heading 2", "Heading 2" }, + { "Heading 3", "Heading 3" }, + { "Heading 4", "Heading 4" }, + { "Heading 5", "Heading 5" }, + { "Heading 6", "Heading 6" }, + { "Heading 7", "Heading 7" }, + { "Heading 8", "Heading 8" }, + { "Heading 9", "Heading 9" }, + { "Index 1", "Index 1" }, + { "Index 2", "Index 2" }, + { "Index 3", "Index 3" }, +// { "Index 4", "" }, +// { "Index 5", "" }, +// { "Index 6", "" }, +// { "Index 7", "" }, +// { "Index 8", "" }, +// { "Index 9", "" }, + { "TOC 1", "Contents 1" }, + { "TOC 2", "Contents 2" }, + { "TOC 3", "Contents 3" }, + { "TOC 4", "Contents 4" }, + { "TOC 5", "Contents 5" }, + { "TOC 6", "Contents 6" }, + { "TOC 7", "Contents 7" }, + { "TOC 8", "Contents 8" }, + { "TOC 9", "Contents 9" }, + { "TOCHeading", "Contents Heading" }, + { "toc 1", "Contents 1" }, + { "toc 2", "Contents 2" }, + { "toc 3", "Contents 3" }, + { "toc 4", "Contents 4" }, + { "toc 5", "Contents 5" }, + { "toc 6", "Contents 6" }, + { "toc 7", "Contents 7" }, + { "toc 8", "Contents 8" }, + { "toc 9", "Contents 9" }, + { "TOC1", "Contents 1" }, + { "TOC2", "Contents 2" }, + { "TOC3", "Contents 3" }, + { "TOC4", "Contents 4" }, + { "TOC5", "Contents 5" }, + { "TOC6", "Contents 6" }, + { "TOC7", "Contents 7" }, + { "TOC8", "Contents 8" }, + { "TOC9", "Contents 9" }, +// { "Normal Indent", "" }, + { "footnote text", "Footnote" }, + { "Footnote Text", "Footnote" }, +// { "Annotation Text", "" }, + { "Header", "Header" }, + { "header", "Header" }, + { "Footer", "Footer" }, + { "footer", "Footer" }, + { "Index Heading", "Index Heading" }, +// { "Caption", "" }, +// { "Table of Figures", "" }, + { "Envelope Address", "Addressee" }, + { "Envelope Return", "Sender" }, + { "footnote reference", "Footnote Characters" }, + { "Footnote Reference", "Footnote Characters" }, +// { "Annotation Reference", "" }, + { "Line Number", "Line numbering" }, + { "Page Number", "Page Number" }, + { "endnote reference", "Endnote Characters" }, + { "Endnote Reference", "Endnote Characters" }, + { "endnote text", "Endnote" }, + { "Endnote Text", "Endnote" }, +// { "Table of Authorities", "" }, +// { "Macro Text", "" }, +// { "TOA Heading", "" }, + { "List", "List" }, +// { "List 2", "" }, +// { "List 3", "" }, +// { "List 4", "" }, +// { "List 5", "" }, +// { "List Bullet", "" }, +// { "List Bullet 2", "" }, +// { "List Bullet 3", "" }, +// { "List Bullet 4", "" }, +// { "List Bullet 5", "" }, +// { "List Number", "" }, +// { "List Number 2", "" }, +// { "List Number 3", "" }, +// { "List Number 4", "" }, +// { "List Number 5", "" }, + { "Title", "Title" }, +// { "Closing", "" }, + { "Signature", "Signature" }, +// { "Default Paragraph Font", "" }, + { "DefaultParagraphFont", "Default Paragraph Font" }, + { "Body Text", "Text body" }, + { "BodyText", "Text body" }, + { "BodyTextIndentItalic", "Text body indent italic" }, + { "Body Text Indent", "Text body indent" }, + { "BodyTextIndent", "Text body indent" }, + { "BodyTextIndent2", "Text body indent2" }, +// { "List Continue", "" }, +// { "List Continue 2", "" }, +// { "List Continue 3", "" }, +// { "List Continue 4", "" }, +// { "List Continue 5", "" }, +// { "Message Header", "" }, + { "Subtitle", "Subtitle" }, +// { "Salutation", "" }, +// { "Date", "" }, + { "Body Text First Indent", "Body Text Indent" }, +// { "Body Text First Indent 2", "" }, +// { "Note Heading", "" }, +// { "Body Text 2", "" }, +// { "Body Text 3", "" }, +// { "Body Text Indent 2", "" }, +// { "Body Text Indent 3", "" }, +// { "Block Text", "" }, + { "Hyperlink", "Internet link" }, + { "FollowedHyperlink", "Visited Internet Link" }, + { "Emphasis", "Emphasis" }, +// { "Document Map", "" }, +// { "Plain Text", "" }, + { "NoList", "No List" }, + { "AbstractHeading", "Abstract Heading" }, + { "AbstractBody", "Abstract Body" }, + { "PageNumber", "page number" }, + { "TableNormal", "Normal Table" }, + { "DocumentMap", "Document Map" }, + }; + + // find style-name using map + if (const auto aIt = StyleNameMap.find(sRet); aIt != StyleNameMap.end()) + { + sRet = aIt->second; + } + else + { + // Style names which should not be used without a " (user)" suffix + static const o3tl::sorted_vector ReservedStyleNames = [] { + o3tl::sorted_vector set; + for (const auto& pair : StyleNameMap) + set.insert(pair.second); + return set; + }(); + // SwStyleNameMapper doc says: If the UI style name equals a + // programmatic name, then it must append " (user)" to the end. + if (ReservedStyleNames.find(sRet) != ReservedStyleNames.end()) + sRet += " (user)"; + } + + return sRet; +} + +void StyleSheetTable::applyDefaults(bool bParaProperties) +{ + try{ + + if (!m_pImpl->m_bIsNewDoc) + { + // tdf#72942: do not corrupts original styles in master document + // during inserting of text from second document + return; + } + + if(!m_pImpl->m_xTextDefaults.is()) + { + m_pImpl->m_xTextDefaults.set( + m_pImpl->m_rDMapper.GetTextFactory()->createInstance("com.sun.star.text.Defaults"), + uno::UNO_QUERY_THROW ); + } + + // WARNING: these defaults only take effect IF there is a DocDefaults style section. Normally there is, but not always. + if( bParaProperties && m_pImpl->m_pDefaultParaProps) + { + // tdf#87533 LO will have different defaults here, depending on the locale. Import with documented defaults + SetDefaultParaProps(PROP_WRITING_MODE, uno::makeAny(sal_Int16(text::WritingMode_LR_TB))); + SetDefaultParaProps(PROP_PARA_ADJUST, uno::makeAny(sal_Int16(style::ParagraphAdjust_LEFT))); + + // Widow/Orphan -> set both to two if not already set + uno::Any aTwo = uno::makeAny(sal_Int8(2)); + SetDefaultParaProps(PROP_PARA_WIDOWS, aTwo); + SetDefaultParaProps(PROP_PARA_ORPHANS, aTwo); + + uno::Reference xStylesSupplier(m_pImpl->m_xTextDocument, uno::UNO_QUERY); + uno::Reference xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xParagraphStyles; + xStyleFamilies->getByName("ParagraphStyles") >>= xParagraphStyles; + uno::Reference xDefault; + // This is the built-in default style that every style inherits from + xParagraphStyles->getByName("Paragraph style") >>= xDefault; + + const uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultParaProps->GetPropertyValues(); + for( const auto& rPropValue : aPropValues ) + { + try + { + xDefault->setPropertyValue(rPropValue.Name, rPropValue.Value); + } + catch( const uno::Exception& ) + { + OSL_FAIL( "setPropertyValue exception"); + } + } + } + if( !bParaProperties && m_pImpl->m_pDefaultCharProps ) + { + // tdf#108350: Earlier in DomainMapper for DOCX, Calibri/11pt was set to match MSWord 2007+, + // but that is valid only if DocDefaults_rPrDefault is omitted. + // Now that DocDefaults_rPrDefault is known, the defaults should be reset to Times New Roman/10pt. + if ( m_pImpl->m_rDMapper.IsOOXMLImport() ) + m_pImpl->m_xTextDefaults->setPropertyValue( getPropertyName(PROP_CHAR_FONT_NAME), css::uno::Any(OUString("Times New Roman")) ); + + const uno::Sequence< beans::PropertyValue > aPropValues = m_pImpl->m_pDefaultCharProps->GetPropertyValues(); + for( const auto& rPropValue : aPropValues ) + { + try + { + m_pImpl->m_xTextDefaults->setPropertyValue( rPropValue.Name, rPropValue.Value ); + } + catch( const uno::Exception& ) + { + OSL_FAIL( "setPropertyValue exception"); + } + } + } + } + catch( const uno::Exception& ) + { + } +} + + +OUString StyleSheetTable::getOrCreateCharStyle( PropertyValueVector_t& rCharProperties, bool bAlwaysCreate ) +{ + //find out if any of the styles already has the required properties then return its name + OUString sListLabel = m_pImpl->HasListCharStyle(rCharProperties); + // Don't try to reuse an existing character style if requested. + if( !sListLabel.isEmpty() && !bAlwaysCreate) + return sListLabel; + const char cListLabel[] = "ListLabel "; + uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies(); + uno::Reference xCharStyles; + xStyleFamilies->getByName("CharacterStyles") >>= xCharStyles; + //search for all character styles with the name sListLabel + + sal_Int32 nStyleFound = 0; + const uno::Sequence< OUString > aStyleNames = xCharStyles->getElementNames(); + for( const auto& rStyleName : aStyleNames ) + { + OUString sSuffix; + if( rStyleName.startsWith( cListLabel, &sSuffix ) ) + { + sal_Int32 nSuffix = sSuffix.toInt32(); + if( nSuffix > 0 && nSuffix > nStyleFound ) + nStyleFound = nSuffix; + } + } + sListLabel = cListLabel + OUString::number( ++nStyleFound ); + //create a new one otherwise + uno::Reference< lang::XMultiServiceFactory > xDocFactory( m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW ); + try + { + uno::Reference< style::XStyle > xStyle( xDocFactory->createInstance( + getPropertyName( PROP_SERVICE_CHAR_STYLE )), uno::UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xStyleProps(xStyle, uno::UNO_QUERY_THROW ); + for( const auto& rCharProp : rCharProperties) + { + try + { + xStyleProps->setPropertyValue( rCharProp.Name, rCharProp.Value ); + } + catch( const uno::Exception& ) + { + OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue"); + } + } + xCharStyles->insertByName( sListLabel, uno::makeAny( xStyle) ); + m_pImpl->m_aListCharStylePropertyVector.emplace_back( sListLabel, rCharProperties ); + } + catch( const uno::Exception& ) + { + OSL_FAIL( "Exception in StyleSheetTable::getOrCreateCharStyle"); + } + + return sListLabel; +} + +}//namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/StyleSheetTable.hxx b/writerfilter/source/dmapper/StyleSheetTable.hxx new file mode 100644 index 000000000..9381b90ea --- /dev/null +++ b/writerfilter/source/dmapper/StyleSheetTable.hxx @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_STYLESHEETTABLE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_STYLESHEETTABLE_HXX + +#include +#include "TblStylePrHandler.hxx" + +#include "DomainMapper.hxx" +#include +#include "PropertyMap.hxx" +#include "FontTable.hxx" +#include "LoggedResources.hxx" + +namespace com::sun::star::text { class XTextDocument; } + + +namespace writerfilter { +namespace dmapper +{ + + +enum StyleType +{ + STYLE_TYPE_UNKNOWN, + STYLE_TYPE_PARA, + STYLE_TYPE_CHAR, + STYLE_TYPE_TABLE, + STYLE_TYPE_LIST +}; +class StyleSheetTable; +typedef tools::SvRef StyleSheetTablePtr; + +struct StyleSheetTable_Impl; +class StyleSheetEntry : public virtual SvRefBase +{ + std::vector m_aInteropGrabBag; +public: + OUString sStyleIdentifierD; // WW8 name + bool bIsDefaultStyle; + bool bInvalidHeight; + bool bHasUPE; //universal property expansion + StyleType nStyleTypeCode; //sgc + OUString sBaseStyleIdentifier; + OUString sNextStyleIdentifier; + OUString sStyleName; + const PropertyMapPtr pProperties; ///< always StyleSheetPropertyMap + OUString sConvertedStyleName; + std::vector aLatentStyles; ///< Attributes of latentStyles + std::vector aLsdExceptions; ///< List of lsdException attribute lists + bool bAutoRedefine; ///< Writer calls this auto-update. + + void AppendInteropGrabBag(const css::beans::PropertyValue& rValue); + css::beans::PropertyValue GetInteropGrabBag(); ///< Used for table styles, has a name. + css::beans::PropertyValues GetInteropGrabBagSeq() const; ///< Used for existing styles, just a list of properties. + + // Get all properties, merged with the all of the parent's properties + PropertyMapPtr GetMergedInheritedProperties(const StyleSheetTablePtr& pStyleSheetTable); + + StyleSheetEntry(); + virtual ~StyleSheetEntry() override; +}; + +typedef tools::SvRef StyleSheetEntryPtr; + +class DomainMapper; +class StyleSheetTable : + public LoggedProperties, + public LoggedTable +{ + std::unique_ptr m_pImpl; + +public: + StyleSheetTable(DomainMapper& rDMapper, css::uno::Reference const& xTextDocument, bool bIsNewDoc); + virtual ~StyleSheetTable() override; + + void ApplyNumberingStyleNameToParaStyles(); + void ApplyStyleSheets( const FontTablePtr& rFontTable ); + StyleSheetEntryPtr FindStyleSheetByISTD(const OUString& sIndex); + StyleSheetEntryPtr FindStyleSheetByConvertedStyleName(const OUString& rIndex); + StyleSheetEntryPtr FindDefaultParaStyle(); + + OUString ConvertStyleName( const OUString& rWWName, bool bExtendedSearch = false ); + + OUString getOrCreateCharStyle( PropertyValueVector_t& rCharProperties, bool bAlwaysCreate ); + + void SetDefaultParaProps(PropertyIds eId, const css::uno::Any& rAny); + PropertyMapPtr const & GetDefaultParaProps() const; + /// Returns the default character properties. + PropertyMapPtr const & GetDefaultCharProps() const; + + const StyleSheetEntryPtr & GetCurrentEntry() const; + +private: + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + + // Table + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) override; + + void applyDefaults(bool bParaProperties); +}; + + +class TableStyleSheetEntry : + public StyleSheetEntry +{ +public: + // Adds a new tblStylePr to the table style entry. This method + // fixes some possible properties conflicts, like borders ones. + void AddTblStylePr( TblStyleType nType, const PropertyMapPtr& pProps ); + + // Gets all the properties + // + corresponding to the mask, + // + from the parent styles + + // @param mask mask describing which properties to return + PropertyMapPtr GetProperties( sal_Int32 nMask); + + TableStyleSheetEntry( StyleSheetEntry const & aEntry ); + virtual ~TableStyleSheetEntry( ) override; + +private: + typedef std::map TblStylePrs; + TblStylePrs m_aStyles; + PropertyMapPtr GetLocalPropertiesFromMask( sal_Int32 nMask ); +}; + + +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TDefTableHandler.cxx b/writerfilter/source/dmapper/TDefTableHandler.cxx new file mode 100644 index 000000000..acd29d5ac --- /dev/null +++ b/writerfilter/source/dmapper/TDefTableHandler.cxx @@ -0,0 +1,458 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "TDefTableHandler.hxx" +#include "PropertyMap.hxx" +#include "ConversionHelper.hxx" +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; + + +TDefTableHandler::TDefTableHandler() : +LoggedProperties("TDefTableHandler"), +m_nLineWidth(0), +m_nLineType(0), +m_nLineColor(0) +{ +} + + +TDefTableHandler::~TDefTableHandler() +{ +} + +OUString TDefTableHandler::getBorderTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_Value_ST_Border_nil: return "nil"; + case NS_ooxml::LN_Value_ST_Border_none: return "none"; + case NS_ooxml::LN_Value_ST_Border_single: return "single"; + case NS_ooxml::LN_Value_ST_Border_thick: return "thick"; + case NS_ooxml::LN_Value_ST_Border_double: return "double"; + case NS_ooxml::LN_Value_ST_Border_dotted: return "dotted"; + case NS_ooxml::LN_Value_ST_Border_dashed: return "dashed"; + case NS_ooxml::LN_Value_ST_Border_dotDash: return "dotDash"; + case NS_ooxml::LN_Value_ST_Border_dotDotDash: return "dotDotDash"; + case NS_ooxml::LN_Value_ST_Border_triple: return "triple"; + case NS_ooxml::LN_Value_ST_Border_thinThickSmallGap: return "thinThickSmallGap"; + case NS_ooxml::LN_Value_ST_Border_thickThinSmallGap: return "thickThinSmallGap"; + case NS_ooxml::LN_Value_ST_Border_thinThickThinSmallGap: return "thinThickThinSmallGap"; + case NS_ooxml::LN_Value_ST_Border_thinThickMediumGap: return "thinThickMediumGap"; + case NS_ooxml::LN_Value_ST_Border_thickThinMediumGap: return "thickThinMediumGap"; + case NS_ooxml::LN_Value_ST_Border_thinThickThinMediumGap: return "thinThickThinMediumGap"; + case NS_ooxml::LN_Value_ST_Border_thinThickLargeGap: return "thinThickLargeGap"; + case NS_ooxml::LN_Value_ST_Border_thickThinLargeGap: return "thickThinLargeGap"; + case NS_ooxml::LN_Value_ST_Border_thinThickThinLargeGap: return "thinThickThinLargeGap"; + case NS_ooxml::LN_Value_ST_Border_wave: return "wave"; + case NS_ooxml::LN_Value_ST_Border_doubleWave: return "doubleWave"; + case NS_ooxml::LN_Value_ST_Border_dashSmallGap: return "dashSmallGap"; + case NS_ooxml::LN_Value_ST_Border_dashDotStroked: return "dashDotStroked"; + case NS_ooxml::LN_Value_ST_Border_threeDEmboss: return "threeDEmboss"; + case NS_ooxml::LN_Value_ST_Border_threeDEngrave: return "threeDEngrave"; + case NS_ooxml::LN_Value_ST_Border_outset: return "outset"; + case NS_ooxml::LN_Value_ST_Border_inset: return "inset"; + case NS_ooxml::LN_Value_ST_Border_apples: return "apples"; + case NS_ooxml::LN_Value_ST_Border_archedScallops: return "archedScallops"; + case NS_ooxml::LN_Value_ST_Border_babyPacifier: return "babyPacifier"; + case NS_ooxml::LN_Value_ST_Border_babyRattle: return "babyRattle"; + case NS_ooxml::LN_Value_ST_Border_balloons3Colors: return "balloons3Colors"; + case NS_ooxml::LN_Value_ST_Border_balloonsHotAir: return "balloonsHotAir"; + case NS_ooxml::LN_Value_ST_Border_basicBlackDashes: return "basicBlackDashes"; + case NS_ooxml::LN_Value_ST_Border_basicBlackDots: return "basicBlackDots"; + case NS_ooxml::LN_Value_ST_Border_basicBlackSquares: return "basicBlackSquares"; + case NS_ooxml::LN_Value_ST_Border_basicThinLines: return "basicThinLines"; + case NS_ooxml::LN_Value_ST_Border_basicWhiteDashes: return "basicWhiteDashes"; + case NS_ooxml::LN_Value_ST_Border_basicWhiteDots: return "basicWhiteDots"; + case NS_ooxml::LN_Value_ST_Border_basicWhiteSquares: return "basicWhiteSquares"; + case NS_ooxml::LN_Value_ST_Border_basicWideInline: return "basicWideInline"; + case NS_ooxml::LN_Value_ST_Border_basicWideMidline: return "basicWideMidline"; + case NS_ooxml::LN_Value_ST_Border_basicWideOutline: return "basicWideOutline"; + case NS_ooxml::LN_Value_ST_Border_bats: return "bats"; + case NS_ooxml::LN_Value_ST_Border_birds: return "birds"; + case NS_ooxml::LN_Value_ST_Border_birdsFlight: return "birdsFlight"; + case NS_ooxml::LN_Value_ST_Border_cabins: return "cabins"; + case NS_ooxml::LN_Value_ST_Border_cakeSlice: return "cakeSlice"; + case NS_ooxml::LN_Value_ST_Border_candyCorn: return "candyCorn"; + case NS_ooxml::LN_Value_ST_Border_celticKnotwork: return "celticKnotwork"; + case NS_ooxml::LN_Value_ST_Border_certificateBanner: return "certificateBanner"; + case NS_ooxml::LN_Value_ST_Border_chainLink: return "chainLink"; + case NS_ooxml::LN_Value_ST_Border_champagneBottle: return "champagneBottle"; + case NS_ooxml::LN_Value_ST_Border_checkedBarBlack: return "checkedBarBlack"; + case NS_ooxml::LN_Value_ST_Border_checkedBarColor: return "checkedBarColor"; + case NS_ooxml::LN_Value_ST_Border_checkered: return "checkered"; + case NS_ooxml::LN_Value_ST_Border_christmasTree: return "christmasTree"; + case NS_ooxml::LN_Value_ST_Border_circlesLines: return "circlesLines"; + case NS_ooxml::LN_Value_ST_Border_circlesRectangles: return "circlesRectangles"; + case NS_ooxml::LN_Value_ST_Border_classicalWave: return "classicalWave"; + case NS_ooxml::LN_Value_ST_Border_clocks: return "clocks"; + case NS_ooxml::LN_Value_ST_Border_compass: return "compass"; + case NS_ooxml::LN_Value_ST_Border_confetti: return "confetti"; + case NS_ooxml::LN_Value_ST_Border_confettiGrays: return "confettiGrays"; + case NS_ooxml::LN_Value_ST_Border_confettiOutline: return "confettiOutline"; + case NS_ooxml::LN_Value_ST_Border_confettiStreamers: return "confettiStreamers"; + case NS_ooxml::LN_Value_ST_Border_confettiWhite: return "confettiWhite"; + case NS_ooxml::LN_Value_ST_Border_cornerTriangles: return "cornerTriangles"; + case NS_ooxml::LN_Value_ST_Border_couponCutoutDashes: return "couponCutoutDashes"; + case NS_ooxml::LN_Value_ST_Border_couponCutoutDots: return "couponCutoutDots"; + case NS_ooxml::LN_Value_ST_Border_crazyMaze: return "crazyMaze"; + case NS_ooxml::LN_Value_ST_Border_creaturesButterfly: return "creaturesButterfly"; + case NS_ooxml::LN_Value_ST_Border_creaturesFish: return "creaturesFish"; + case NS_ooxml::LN_Value_ST_Border_creaturesInsects: return "creaturesInsects"; + case NS_ooxml::LN_Value_ST_Border_creaturesLadyBug: return "creaturesLadyBug"; + case NS_ooxml::LN_Value_ST_Border_crossStitch: return "crossStitch"; + case NS_ooxml::LN_Value_ST_Border_cup: return "cup"; + case NS_ooxml::LN_Value_ST_Border_decoArch: return "decoArch"; + case NS_ooxml::LN_Value_ST_Border_decoArchColor: return "decoArchColor"; + case NS_ooxml::LN_Value_ST_Border_decoBlocks: return "decoBlocks"; + case NS_ooxml::LN_Value_ST_Border_diamondsGray: return "diamondsGray"; + case NS_ooxml::LN_Value_ST_Border_doubleD: return "doubleD"; + case NS_ooxml::LN_Value_ST_Border_doubleDiamonds: return "doubleDiamonds"; + case NS_ooxml::LN_Value_ST_Border_earth1: return "earth1"; + case NS_ooxml::LN_Value_ST_Border_earth2: return "earth2"; + case NS_ooxml::LN_Value_ST_Border_eclipsingSquares1: return "eclipsingSquares1"; + case NS_ooxml::LN_Value_ST_Border_eclipsingSquares2: return "eclipsingSquares2"; + case NS_ooxml::LN_Value_ST_Border_eggsBlack: return "eggsBlack"; + case NS_ooxml::LN_Value_ST_Border_fans: return "fans"; + case NS_ooxml::LN_Value_ST_Border_film: return "film"; + case NS_ooxml::LN_Value_ST_Border_firecrackers: return "firecrackers"; + case NS_ooxml::LN_Value_ST_Border_flowersBlockPrint: return "flowersBlockPrint"; + case NS_ooxml::LN_Value_ST_Border_flowersDaisies: return "flowersDaisies"; + case NS_ooxml::LN_Value_ST_Border_flowersModern1: return "flowersModern1"; + case NS_ooxml::LN_Value_ST_Border_flowersModern2: return "flowersModern2"; + case NS_ooxml::LN_Value_ST_Border_flowersPansy: return "flowersPansy"; + case NS_ooxml::LN_Value_ST_Border_flowersRedRose: return "flowersRedRose"; + case NS_ooxml::LN_Value_ST_Border_flowersRoses: return "flowersRoses"; + case NS_ooxml::LN_Value_ST_Border_flowersTeacup: return "flowersTeacup"; + case NS_ooxml::LN_Value_ST_Border_flowersTiny: return "flowersTiny"; + case NS_ooxml::LN_Value_ST_Border_gems: return "gems"; + case NS_ooxml::LN_Value_ST_Border_gingerbreadMan: return "gingerbreadMan"; + case NS_ooxml::LN_Value_ST_Border_gradient: return "gradient"; + case NS_ooxml::LN_Value_ST_Border_handmade1: return "handmade1"; + case NS_ooxml::LN_Value_ST_Border_handmade2: return "handmade2"; + case NS_ooxml::LN_Value_ST_Border_heartBalloon: return "heartBalloon"; + case NS_ooxml::LN_Value_ST_Border_heartGray: return "heartGray"; + case NS_ooxml::LN_Value_ST_Border_hearts: return "hearts"; + case NS_ooxml::LN_Value_ST_Border_heebieJeebies: return "heebieJeebies"; + case NS_ooxml::LN_Value_ST_Border_holly: return "holly"; + case NS_ooxml::LN_Value_ST_Border_houseFunky: return "houseFunky"; + case NS_ooxml::LN_Value_ST_Border_hypnotic: return "hypnotic"; + case NS_ooxml::LN_Value_ST_Border_iceCreamCones: return "iceCreamCones"; + case NS_ooxml::LN_Value_ST_Border_lightBulb: return "lightBulb"; + case NS_ooxml::LN_Value_ST_Border_lightning1: return "lightning1"; + case NS_ooxml::LN_Value_ST_Border_lightning2: return "lightning2"; + case NS_ooxml::LN_Value_ST_Border_mapPins: return "mapPins"; + case NS_ooxml::LN_Value_ST_Border_mapleLeaf: return "mapleLeaf"; + case NS_ooxml::LN_Value_ST_Border_mapleMuffins: return "mapleMuffins"; + case NS_ooxml::LN_Value_ST_Border_marquee: return "marquee"; + case NS_ooxml::LN_Value_ST_Border_marqueeToothed: return "marqueeToothed"; + case NS_ooxml::LN_Value_ST_Border_moons: return "moons"; + case NS_ooxml::LN_Value_ST_Border_mosaic: return "mosaic"; + case NS_ooxml::LN_Value_ST_Border_musicNotes: return "musicNotes"; + case NS_ooxml::LN_Value_ST_Border_northwest: return "northwest"; + case NS_ooxml::LN_Value_ST_Border_ovals: return "ovals"; + case NS_ooxml::LN_Value_ST_Border_packages: return "packages"; + case NS_ooxml::LN_Value_ST_Border_palmsBlack: return "palmsBlack"; + case NS_ooxml::LN_Value_ST_Border_palmsColor: return "palmsColor"; + case NS_ooxml::LN_Value_ST_Border_paperClips: return "paperClips"; + case NS_ooxml::LN_Value_ST_Border_papyrus: return "papyrus"; + case NS_ooxml::LN_Value_ST_Border_partyFavor: return "partyFavor"; + case NS_ooxml::LN_Value_ST_Border_partyGlass: return "partyGlass"; + case NS_ooxml::LN_Value_ST_Border_pencils: return "pencils"; + case NS_ooxml::LN_Value_ST_Border_people: return "people"; + case NS_ooxml::LN_Value_ST_Border_peopleWaving: return "peopleWaving"; + case NS_ooxml::LN_Value_ST_Border_peopleHats: return "peopleHats"; + case NS_ooxml::LN_Value_ST_Border_poinsettias: return "poinsettias"; + case NS_ooxml::LN_Value_ST_Border_postageStamp: return "postageStamp"; + case NS_ooxml::LN_Value_ST_Border_pumpkin1: return "pumpkin1"; + case NS_ooxml::LN_Value_ST_Border_pushPinNote2: return "pushPinNote2"; + case NS_ooxml::LN_Value_ST_Border_pushPinNote1: return "pushPinNote1"; + case NS_ooxml::LN_Value_ST_Border_pyramids: return "pyramids"; + case NS_ooxml::LN_Value_ST_Border_pyramidsAbove: return "pyramidsAbove"; + case NS_ooxml::LN_Value_ST_Border_quadrants: return "quadrants"; + case NS_ooxml::LN_Value_ST_Border_rings: return "rings"; + case NS_ooxml::LN_Value_ST_Border_safari: return "safari"; + case NS_ooxml::LN_Value_ST_Border_sawtooth: return "sawtooth"; + case NS_ooxml::LN_Value_ST_Border_sawtoothGray: return "sawtoothGray"; + case NS_ooxml::LN_Value_ST_Border_scaredCat: return "scaredCat"; + case NS_ooxml::LN_Value_ST_Border_seattle: return "seattle"; + case NS_ooxml::LN_Value_ST_Border_shadowedSquares: return "shadowedSquares"; + case NS_ooxml::LN_Value_ST_Border_sharksTeeth: return "sharksTeeth"; + case NS_ooxml::LN_Value_ST_Border_shorebirdTracks: return "shorebirdTracks"; + case NS_ooxml::LN_Value_ST_Border_skyrocket: return "skyrocket"; + case NS_ooxml::LN_Value_ST_Border_snowflakeFancy: return "snowflakeFancy"; + case NS_ooxml::LN_Value_ST_Border_snowflakes: return "snowflakes"; + case NS_ooxml::LN_Value_ST_Border_sombrero: return "sombrero"; + case NS_ooxml::LN_Value_ST_Border_southwest: return "southwest"; + case NS_ooxml::LN_Value_ST_Border_stars: return "stars"; + case NS_ooxml::LN_Value_ST_Border_starsTop: return "starsTop"; + case NS_ooxml::LN_Value_ST_Border_stars3d: return "stars3d"; + case NS_ooxml::LN_Value_ST_Border_starsBlack: return "starsBlack"; + case NS_ooxml::LN_Value_ST_Border_starsShadowed: return "starsShadowed"; + case NS_ooxml::LN_Value_ST_Border_sun: return "sun"; + case NS_ooxml::LN_Value_ST_Border_swirligig: return "swirligig"; + case NS_ooxml::LN_Value_ST_Border_tornPaper: return "tornPaper"; + case NS_ooxml::LN_Value_ST_Border_tornPaperBlack: return "tornPaperBlack"; + case NS_ooxml::LN_Value_ST_Border_trees: return "trees"; + case NS_ooxml::LN_Value_ST_Border_triangleParty: return "triangleParty"; + case NS_ooxml::LN_Value_ST_Border_triangles: return "triangles"; + case NS_ooxml::LN_Value_ST_Border_tribal1: return "tribal1"; + case NS_ooxml::LN_Value_ST_Border_tribal2: return "tribal2"; + case NS_ooxml::LN_Value_ST_Border_tribal3: return "tribal3"; + case NS_ooxml::LN_Value_ST_Border_tribal4: return "tribal4"; + case NS_ooxml::LN_Value_ST_Border_tribal5: return "tribal5"; + case NS_ooxml::LN_Value_ST_Border_tribal6: return "tribal6"; + case NS_ooxml::LN_Value_ST_Border_twistedLines1: return "twistedLines1"; + case NS_ooxml::LN_Value_ST_Border_twistedLines2: return "twistedLines2"; + case NS_ooxml::LN_Value_ST_Border_vine: return "vine"; + case NS_ooxml::LN_Value_ST_Border_waveline: return "waveline"; + case NS_ooxml::LN_Value_ST_Border_weavingAngles: return "weavingAngles"; + case NS_ooxml::LN_Value_ST_Border_weavingBraid: return "weavingBraid"; + case NS_ooxml::LN_Value_ST_Border_weavingRibbon: return "weavingRibbon"; + case NS_ooxml::LN_Value_ST_Border_weavingStrips: return "weavingStrips"; + case NS_ooxml::LN_Value_ST_Border_whiteFlowers: return "whiteFlowers"; + case NS_ooxml::LN_Value_ST_Border_woodwork: return "woodwork"; + case NS_ooxml::LN_Value_ST_Border_xIllusions: return "xIllusions"; + case NS_ooxml::LN_Value_ST_Border_zanyTriangles: return "zanyTriangles"; + case NS_ooxml::LN_Value_ST_Border_zigZag: return "zigZag"; + case NS_ooxml::LN_Value_ST_Border_zigZagStitch: return "zigZagStitch"; + default: break; + } + return OUString(); +} + +OUString TDefTableHandler::getThemeColorTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_Value_St_ThemeColor_dark1: return "dark1"; + case NS_ooxml::LN_Value_St_ThemeColor_light1: return "light1"; + case NS_ooxml::LN_Value_St_ThemeColor_dark2: return "dark2"; + case NS_ooxml::LN_Value_St_ThemeColor_light2: return "light2"; + case NS_ooxml::LN_Value_St_ThemeColor_accent1: return "accent1"; + case NS_ooxml::LN_Value_St_ThemeColor_accent2: return "accent2"; + case NS_ooxml::LN_Value_St_ThemeColor_accent3: return "accent3"; + case NS_ooxml::LN_Value_St_ThemeColor_accent4: return "accent4"; + case NS_ooxml::LN_Value_St_ThemeColor_accent5: return "accent5"; + case NS_ooxml::LN_Value_St_ThemeColor_accent6: return "accent6"; + case NS_ooxml::LN_Value_St_ThemeColor_hyperlink: return "hyperlink"; + case NS_ooxml::LN_Value_St_ThemeColor_followedHyperlink: return "followedHyperlink"; + case NS_ooxml::LN_Value_St_ThemeColor_none: return "none"; + case NS_ooxml::LN_Value_St_ThemeColor_background1: return "background1"; + case NS_ooxml::LN_Value_St_ThemeColor_text1: return "text1"; + case NS_ooxml::LN_Value_St_ThemeColor_background2: return "background2"; + case NS_ooxml::LN_Value_St_ThemeColor_text2: return "text2"; + default: break; + } + return OUString(); +} + +void TDefTableHandler::lcl_attribute(Id rName, Value & rVal) +{ + sal_Int32 nIntValue = rVal.getInt(); + switch( rName ) + { + case NS_ooxml::LN_CT_Border_sz: + // width of a single line in 1/8 pt, max of 32 pt -> twip * 5 / 2. + m_nLineWidth = nIntValue * 5 / 2; + appendGrabBag("sz", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Border_val: + m_nLineType = nIntValue; + appendGrabBag("val", TDefTableHandler::getBorderTypeString(nIntValue)); + break; + case NS_ooxml::LN_CT_Border_color: + appendGrabBag("color", OUString::fromUtf8(msfilter::util::ConvertColor(nIntValue))); + m_nLineColor = nIntValue; + break; + case NS_ooxml::LN_CT_Border_space: + appendGrabBag("space", OUString::number(nIntValue)); + break; + case NS_ooxml::LN_CT_Border_shadow: + //if 1 then line has shadow - unsupported + case NS_ooxml::LN_CT_Border_frame: + // ignored + break; + case NS_ooxml::LN_CT_Border_themeColor: + appendGrabBag("themeColor", TDefTableHandler::getThemeColorTypeString(nIntValue)); + break; + case NS_ooxml::LN_CT_Border_themeTint: + case NS_ooxml::LN_CT_Border_themeShade: + // ignored + break; + default: + OSL_FAIL("unknown attribute"); + } +} + + +void TDefTableHandler::localResolve(Id rName, const writerfilter::Reference::Pointer_t& pProperties) +{ + if( pProperties ) + { + m_nLineWidth = m_nLineType = m_nLineColor = 0; + std::vector aSavedGrabBag; + if (!m_aInteropGrabBagName.isEmpty()) + { + aSavedGrabBag = m_aInteropGrabBag; + m_aInteropGrabBag.clear(); + } + pProperties->resolve( *this ); + table::BorderLine2 aBorderLine; + ConversionHelper::MakeBorderLine(m_nLineWidth, m_nLineType, m_nLineColor, aBorderLine, /*bIsOOXML=*/true); + const bool rtl = false; // TODO + switch( rName ) + { + case NS_ooxml::LN_CT_TcBorders_top: + m_aTopBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("top")); + break; + case NS_ooxml::LN_CT_TcBorders_start: + if( rtl ) + m_aRightBorderLines.push_back(aBorderLine); + else + m_aLeftBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("start")); + break; + case NS_ooxml::LN_CT_TcBorders_left: + m_aLeftBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("left")); + break; + case NS_ooxml::LN_CT_TcBorders_bottom: + m_aBottomBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("bottom")); + break; + case NS_ooxml::LN_CT_TcBorders_end: + if( rtl ) + m_aLeftBorderLines.push_back(aBorderLine); + else + m_aRightBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("end")); + break; + case NS_ooxml::LN_CT_TcBorders_right: + m_aRightBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("right")); + break; + case NS_ooxml::LN_CT_TcBorders_insideH: + m_aInsideHBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("insideH")); + break; + case NS_ooxml::LN_CT_TcBorders_insideV: + m_aInsideVBorderLines.push_back(aBorderLine); + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("insideV")); + break; + case NS_ooxml::LN_CT_TcBorders_tl2br: + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("tl2br")); + break; + case NS_ooxml::LN_CT_TcBorders_tr2bl: + if (!m_aInteropGrabBagName.isEmpty()) + aSavedGrabBag.push_back(getInteropGrabBag("tr2bl")); + break; + default:; + } + if (!m_aInteropGrabBagName.isEmpty()) + m_aInteropGrabBag = aSavedGrabBag; + } +} + + +void TDefTableHandler::lcl_sprm(Sprm & rSprm) +{ + switch( rSprm.getId() ) + { + case NS_ooxml::LN_CT_TcBorders_top: + case NS_ooxml::LN_CT_TcBorders_left: + case NS_ooxml::LN_CT_TcBorders_start: + case NS_ooxml::LN_CT_TcBorders_bottom: + case NS_ooxml::LN_CT_TcBorders_right: + case NS_ooxml::LN_CT_TcBorders_end: + case NS_ooxml::LN_CT_TcBorders_insideH: + case NS_ooxml::LN_CT_TcBorders_insideV: + case NS_ooxml::LN_CT_TcBorders_tl2br: + case NS_ooxml::LN_CT_TcBorders_tr2bl: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + localResolve( rSprm.getId(), pProperties ); + } + break; + default:; + } +} + +void TDefTableHandler::fillCellProperties( const ::tools::SvRef< TablePropertyMap >& pCellProperties ) const +{ + if( !m_aTopBorderLines.empty() ) + pCellProperties->Insert( PROP_TOP_BORDER, uno::makeAny( m_aTopBorderLines[0] ) ); + if( !m_aLeftBorderLines.empty() ) + pCellProperties->Insert( PROP_LEFT_BORDER, uno::makeAny( m_aLeftBorderLines[0] ) ); + if( !m_aBottomBorderLines.empty() ) + pCellProperties->Insert( PROP_BOTTOM_BORDER, uno::makeAny( m_aBottomBorderLines[0] ) ); + if( !m_aRightBorderLines.empty() ) + pCellProperties->Insert( PROP_RIGHT_BORDER, uno::makeAny( m_aRightBorderLines[0] ) ); + if( !m_aInsideHBorderLines.empty() ) + pCellProperties->Insert( META_PROP_HORIZONTAL_BORDER, uno::makeAny( m_aInsideHBorderLines[0] ) ); + if( !m_aInsideVBorderLines.empty() ) + pCellProperties->Insert( META_PROP_VERTICAL_BORDER, uno::makeAny( m_aInsideVBorderLines[0] ) ); +} + + +void TDefTableHandler::enableInteropGrabBag(const OUString& aName) +{ + m_aInteropGrabBagName = aName; +} + +beans::PropertyValue TDefTableHandler::getInteropGrabBag(const OUString& aName) +{ + beans::PropertyValue aRet; + if (aName.isEmpty()) + aRet.Name = m_aInteropGrabBagName; + else + aRet.Name = aName; + + aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag); + m_aInteropGrabBag.clear(); + return aRet; +} + +void TDefTableHandler::appendGrabBag(const OUString& aKey, const OUString& aValue) +{ + beans::PropertyValue aProperty; + aProperty.Name = aKey; + aProperty.Value <<= aValue; + m_aInteropGrabBag.push_back(aProperty); +} + +} //namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TDefTableHandler.hxx b/writerfilter/source/dmapper/TDefTableHandler.hxx new file mode 100644 index 000000000..c7e74263f --- /dev/null +++ b/writerfilter/source/dmapper/TDefTableHandler.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TDEFTABLEHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TDEFTABLEHANDLER_HXX + +#include "LoggedResources.hxx" +#include +namespace com::sun::star{ + namespace table { + struct BorderLine2; + } + namespace beans { + struct PropertyValue; + } +} + +namespace writerfilter { +namespace dmapper +{ +class PropertyMap; +class TablePropertyMap; +class TDefTableHandler : public LoggedProperties +{ + std::vector m_aLeftBorderLines; + std::vector m_aRightBorderLines; + std::vector m_aTopBorderLines; + std::vector m_aBottomBorderLines; + std::vector m_aInsideHBorderLines; + std::vector m_aInsideVBorderLines; + + //values of the current border + sal_Int32 m_nLineWidth; + sal_Int32 m_nLineType; + sal_Int32 m_nLineColor; + + OUString m_aInteropGrabBagName; + std::vector m_aInteropGrabBag; + void appendGrabBag(const OUString& aKey, const OUString& aValue); + + void localResolve(Id Name, const writerfilter::Reference::Pointer_t& pProperties); + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +public: + TDefTableHandler(); + virtual ~TDefTableHandler() override; + + void fillCellProperties( const ::tools::SvRef< TablePropertyMap >& pCellProperties) const; + void enableInteropGrabBag(const OUString& aName); + css::beans::PropertyValue getInteropGrabBag(const OUString& aName = OUString()); + static OUString getBorderTypeString(sal_Int32 nType); + static OUString getThemeColorTypeString(sal_Int32 nType); +}; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TableData.hxx b/writerfilter/source/dmapper/TableData.hxx new file mode 100644 index 000000000..3140a00d7 --- /dev/null +++ b/writerfilter/source/dmapper/TableData.hxx @@ -0,0 +1,357 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEDATA_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEDATA_HXX + +#include + +#include "PropertyMap.hxx" + +#include + +namespace writerfilter +{ +namespace dmapper +{ + +/** + Class containing the data to describe a table cell. + */ +class CellData final : public virtual SvRefBase +{ + /** + Handle to start of cell. + */ + css::uno::Reference mStart; + + /** + Handle to end of cell. + */ + css::uno::Reference mEnd; + + /** + Pointer to properties of cell. + */ + TablePropertyMapPtr mpProps; + + bool mbOpen; + +public: + typedef tools::SvRef Pointer_t; + + CellData(css::uno::Reference const & start, TablePropertyMapPtr pProps) + : mStart(start), mEnd(start), mpProps(pProps), mbOpen(true) + { + } + + /** + Set the end handle of a cell. + + @param end the end handle of the cell + */ + void setEnd(css::uno::Reference const & end) { mEnd = end; mbOpen = false; } + + /** + Adds properties to the cell. + + @param pProps the properties to add + */ + void insertProperties(TablePropertyMapPtr pProps) + { + if( mpProps ) + mpProps->InsertProps(pProps.get()); + else + mpProps = pProps; + } + + /** + Return start handle of the cell. + */ + const css::uno::Reference& getStart() const { return mStart; } + + /** + Return end handle of the cell. + */ + const css::uno::Reference& getEnd() const { return mEnd; } + + /** + Return properties of the cell. + */ + const TablePropertyMapPtr& getProperties() const { return mpProps; } + + bool isOpen() const { return mbOpen; } +}; + +/** + Class to handle data of a table row. + */ +class RowData final : public virtual SvRefBase +{ + typedef ::std::vector Cells; + + /** + the cell data of the row + */ + Cells mCells; + + /** + the properties of the row + */ + mutable TablePropertyMapPtr mpProperties; + +public: + typedef tools::SvRef Pointer_t; + + RowData() {} + + RowData(const RowData& rRowData) + : SvRefBase(), mCells(rRowData.mCells), mpProperties(rRowData.mpProperties) + { + } + + /** + Add a cell to the row. + + @param start the start handle of the cell + @param end the end handle of the cell + @param pProps the properties of the cell + @param bAddBefore true: add an empty cell at beginning of the row for gridBefore + */ + void addCell(const css::uno::Reference& start, TablePropertyMapPtr pProps, bool bAddBefore = false) + { + CellData::Pointer_t pCellData(new CellData(start, pProps)); + if (bAddBefore) + { + mCells.insert(mCells.begin(), pCellData); + mCells[0]->setEnd(start); + } + else + mCells.push_back(pCellData); + } + + void endCell(const css::uno::Reference& end) + { + if (mCells.size() > 0) + mCells.back()->setEnd(end); + } + + bool isCellOpen() const + { + return mCells.size() > 0 && mCells.back()->isOpen(); + } + + /** + Add properties to the row. + + @param pProperties the properties to set + */ + void insertProperties(TablePropertyMapPtr pProperties) + { + if( pProperties ) + { + if( !mpProperties ) + mpProperties = pProperties; + else + mpProperties->InsertProps(pProperties.get()); + } + } + + /** + Add properties to the last cell of the row. + */ + void insertCellProperties(TablePropertyMapPtr pProps) + { + if (!mCells.empty()) + mCells.back()->insertProperties(pProps); + } + + /** + Return number of cells in the row. + */ + unsigned int getCellCount() const + { + return mCells.size(); + } + + /** + Return start handle of a cell in the row. + + @param i index of the cell + */ + const css::uno::Reference& getCellStart(unsigned int i) const + { + return mCells[i]->getStart(); + } + + /** + Return end handle of a cell in the row. + + @param i index of the cell + */ + const css::uno::Reference& getCellEnd(unsigned int i) const + { + return mCells[i]->getEnd(); + } + + /** + Return the properties of a cell in the row. + + @param i index of the cell + */ + TablePropertyMapPtr const & getCellProperties(unsigned int i) const + { + return mCells[i]->getProperties(); + } + + /** + Return properties of the row. + */ + const TablePropertyMapPtr& getProperties() const + { + return mpProperties; + } +}; + +/** + Class that holds the data of a table. + */ +class TableData : public virtual SvRefBase +{ + typedef RowData::Pointer_t RowPointer_t; + typedef ::std::vector Rows; + + /** + the data of the rows of the table + */ + Rows mRows; + + /** + pointer to the data of the current row (while building up the table data). + */ + RowPointer_t mpRow; + + /** + depth of the current table in a hierarchy of tables + */ + unsigned int mnDepth; + + /** + initialize mpRow + */ + void newRow() { mpRow = RowPointer_t(new RowData()); } + +public: + typedef tools::SvRef Pointer_t; + + explicit TableData(unsigned int nDepth) : mnDepth(nDepth) { newRow(); } + + /** + End the current row. + + Sets properties of the current row and pushes the row to the + back of the rows currently contained in the table. + + @param pProperties properties of the row to be ended + */ + void endRow(TablePropertyMapPtr pProperties) + { + mpRow->insertProperties(pProperties); + mRows.push_back(mpRow); + newRow(); + } + + /** + Add a cell to the current row. + + @param start start handle of the cell + @param end end handle of the cell + @param pProps properties of the cell + */ + void addCell(const css::uno::Reference& start, TablePropertyMapPtr pProps) + { + mpRow->addCell(start, pProps); + } + + /** + End the current cell of the current row. + + @parm end end handle of the cell + */ + void endCell(const css::uno::Reference& end) + { + mpRow->endCell(end); + } + + /** + Return if the current cell of the current row is open. + */ + bool isCellOpen() const + { + return mpRow->isCellOpen(); + } + + /** + Insert properties to the current cell of the current row. + + @param pProps the properties to add + */ + void insertCellProperties(TablePropertyMapPtr pProps) + { + mpRow->insertCellProperties(pProps); + } + + /** + Return number of rows in the table. + */ + unsigned int getRowCount() const + { + return mRows.size(); + } + + /** + Return depth of table in surrounding table hierarchy. + */ + unsigned int getDepth() const + { + return mnDepth; + } + + /** + Return row data of a certain row. + + @param i index of the row + */ + RowPointer_t const & getRow(unsigned int i) const + { + return mRows[i]; + } + + const RowPointer_t& getCurrentRow() const + { + return mpRow; + } +}; + +} +} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_RESOURCEMODEL_TABLEDATA_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TableManager.cxx b/writerfilter/source/dmapper/TableManager.cxx new file mode 100644 index 000000000..50e948b00 --- /dev/null +++ b/writerfilter/source/dmapper/TableManager.cxx @@ -0,0 +1,501 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "TableManager.hxx" +#include +#include "TagLogger.hxx" +#include "DomainMapperTableHandler.hxx" +#include "DomainMapper_Impl.hxx" +#include "util.hxx" + +#include + +namespace writerfilter::dmapper +{ +void TableManager::clearData() {} + +void TableManager::openCell(const css::uno::Reference& rHandle, + const TablePropertyMapPtr& pProps) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.openCell"); + TagLogger::getInstance().chars(XTextRangeToString(rHandle)); + TagLogger::getInstance().endElement(); +#endif + + if (!mTableDataStack.empty()) + { + TableData::Pointer_t pTableData = mTableDataStack.top(); + + pTableData->addCell(rHandle, pProps); + } +} + +bool TableManager::isIgnore() const { return isRowEnd(); } + +void TableManager::endOfRowAction() {} + +void TableManager::endOfCellAction() {} + +void TableManager::insertTableProps(const TablePropertyMapPtr& pProps) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.insertTableProps"); +#endif + + if (getTableProps() && getTableProps() != pProps) + getTableProps()->InsertProps(pProps.get()); + else + mState.setTableProps(pProps); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void TableManager::insertRowProps(const TablePropertyMapPtr& pProps) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.insertRowProps"); +#endif + + if (getRowProps()) + getRowProps()->InsertProps(pProps.get()); + else + mState.setRowProps(pProps); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void TableManager::cellProps(const TablePropertyMapPtr& pProps) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.cellProps"); +#endif + + if (getCellProps()) + getCellProps()->InsertProps(pProps.get()); + else + mState.setCellProps(pProps); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void TableManager::tableExceptionProps(const TablePropertyMapPtr& pProps) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.tableExceptionProps"); +#endif + + if (getTableExceptionProps()) + getTableExceptionProps()->InsertProps(pProps.get()); + else + mState.setTableExceptionProps(pProps); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void TableManager::utext(const sal_uInt8* data, std::size_t len) +{ + // optimization: cell/row end characters are the last characters in a run + + if (len > 0) + { + sal_Unicode nChar = data[(len - 1) * 2] + (data[(len - 1) * 2 + 1] << 8); + if (nChar == 0x7) + handle0x7(); + } +} + +void TableManager::text(const sal_uInt8* data, std::size_t len) +{ + // optimization: cell/row end characters are the last characters in a run + if (len > 0 && data[len - 1] == 0x7) + handle0x7(); +} + +void TableManager::handle0x7() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.handle0x7"); +#endif + + if (mnTableDepthNew < 1) + mnTableDepthNew = 1; + + if (isInCell()) + endCell(); + else + endRow(); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +bool TableManager::sprm(Sprm& rSprm) +{ + bool bRet = true; + switch (rSprm.getId()) + { + case NS_ooxml::LN_tblDepth: + { + Value::Pointer_t pValue = rSprm.getValue(); + + cellDepth(pValue->getInt()); + } + break; + case NS_ooxml::LN_inTbl: + inCell(); + break; + case NS_ooxml::LN_tblCell: + endCell(); + break; + case NS_ooxml::LN_tblRow: + endRow(); + break; + default: + bRet = false; + } + return bRet; +} + +void TableManager::closeCell(const css::uno::Reference& rHandle) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.closeCell"); + TagLogger::getInstance().chars(XTextRangeToString(rHandle)); + TagLogger::getInstance().endElement(); +#endif + + if (!mTableDataStack.empty()) + { + TableData::Pointer_t pTableData = mTableDataStack.top(); + + pTableData->endCell(rHandle); + + if (mpTableDataHandler) + mpTableDataHandler->getDomainMapperImpl().ClearPreviousParagraph(); + } +} + +void TableManager::ensureOpenCell(const TablePropertyMapPtr& pProps) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.ensureOpenCell"); +#endif + + if (!mTableDataStack.empty()) + { + TableData::Pointer_t pTableData = mTableDataStack.top(); + + if (pTableData != nullptr) + { + if (!pTableData->isCellOpen()) + openCell(getHandle(), pProps); + else + pTableData->insertCellProperties(pProps); + } + } +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void TableManager::endParagraphGroup() +{ + sal_Int32 nTableDepthDifference = mnTableDepthNew - mnTableDepth; + + TablePropertyMapPtr pEmptyProps; + + while (nTableDepthDifference > 0) + { + ensureOpenCell(pEmptyProps); + startLevel(); + + --nTableDepthDifference; + } + while (nTableDepthDifference < 0) + { + endLevel(); + + ++nTableDepthDifference; + } + + mnTableDepth = mnTableDepthNew; + + if (mnTableDepth > 0) + { + if (isRowEnd()) + { + endOfRowAction(); + mTableDataStack.top()->endRow(getRowProps()); + mState.resetRowProps(); + } + + else if (isInCell()) + { + ensureOpenCell(getCellProps()); + + if (mState.isCellEnd()) + { + endOfCellAction(); + closeCell(getHandle()); + } + } + mState.resetCellProps(); + } +} + +void TableManager::startParagraphGroup() +{ + mState.resetCellSpecifics(); + mnTableDepthNew = 0; +} + +void TableManager::resolveCurrentTable() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.resolveCurrentTable"); +#endif + + if (mpTableDataHandler != nullptr) + { + try + { + TableData::Pointer_t pTableData = mTableDataStack.top(); + + unsigned int nRows = pTableData->getRowCount(); + + mpTableDataHandler->startTable(getTableProps()); + + for (unsigned int nRow = 0; nRow < nRows; ++nRow) + { + RowData::Pointer_t pRowData = pTableData->getRow(nRow); + + unsigned int nCells = pRowData->getCellCount(); + + mpTableDataHandler->startRow(pRowData->getProperties()); + + for (unsigned int nCell = 0; nCell < nCells; ++nCell) + { + mpTableDataHandler->startCell(pRowData->getCellStart(nCell), + pRowData->getCellProperties(nCell)); + + mpTableDataHandler->endCell(pRowData->getCellEnd(nCell)); + } + + mpTableDataHandler->endRow(); + } + + mpTableDataHandler->endTable(mTableDataStack.size() - 1, m_bTableStartsAtCellStart); + } + catch (css::uno::Exception const&) + { + TOOLS_WARN_EXCEPTION("writerfilter", "resolving of current table failed"); + } + } + mState.resetTableProps(); + clearData(); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void TableManager::endLevel() +{ + if (mpTableDataHandler != nullptr) + resolveCurrentTable(); + + // Store the unfinished row as it will be used for the next table + if (mbKeepUnfinishedRow) + mpUnfinishedRow = mTableDataStack.top()->getCurrentRow(); + mState.endLevel(); + mTableDataStack.pop(); + +#ifdef DBG_UTIL + TableData::Pointer_t pTableData; + + if (!mTableDataStack.empty()) + pTableData = mTableDataStack.top(); + + TagLogger::getInstance().startElement("tablemanager.endLevel"); + TagLogger::getInstance().attribute("level", mTableDataStack.size()); + + if (pTableData != nullptr) + TagLogger::getInstance().attribute("openCell", pTableData->isCellOpen() ? "yes" : "no"); + + TagLogger::getInstance().endElement(); +#endif +} + +void TableManager::startLevel() +{ +#ifdef DBG_UTIL + TableData::Pointer_t pTableData; + + if (!mTableDataStack.empty()) + pTableData = mTableDataStack.top(); + + TagLogger::getInstance().startElement("tablemanager.startLevel"); + TagLogger::getInstance().attribute("level", mTableDataStack.size()); + + if (pTableData != nullptr) + TagLogger::getInstance().attribute("openCell", pTableData->isCellOpen() ? "yes" : "no"); + + TagLogger::getInstance().endElement(); +#endif + + TableData::Pointer_t pTableData2(new TableData(mTableDataStack.size())); + + // If we have an unfinished row stored here, then push it to the new TableData + if (mpUnfinishedRow) + { + for (unsigned int i = 0; i < mpUnfinishedRow->getCellCount(); ++i) + { + pTableData2->addCell(mpUnfinishedRow->getCellStart(i), + mpUnfinishedRow->getCellProperties(i)); + pTableData2->endCell(mpUnfinishedRow->getCellEnd(i)); + } + mpUnfinishedRow.clear(); + } + + mTableDataStack.push(pTableData2); + mState.startLevel(); +} + +bool TableManager::isInTable() +{ + bool bInTable = false; + if (!mTableDataStack.empty()) + bInTable = mTableDataStack.top()->getDepth() > 0; + return bInTable; +} + +void TableManager::handle(const css::uno::Reference& rHandle) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.handle"); + TagLogger::getInstance().chars(XTextRangeToString(rHandle)); + TagLogger::getInstance().endElement(); +#endif + + setHandle(rHandle); +} + +void TableManager::setHandler(const tools::SvRef& pTableDataHandler) +{ + mpTableDataHandler = pTableDataHandler; +} + +void TableManager::endRow() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().element("tablemanager.endRow"); +#endif + TableData::Pointer_t pTableData = mTableDataStack.top(); + + // Add borderless w:gridBefore cell(s) to the row + if (pTableData) + { + sal_uInt32 nGridBefore + = mpTableDataHandler->getDomainMapperImpl().getTableManager().getCurrentGridBefore(); + for (unsigned int i = 0; i < nGridBefore; ++i) + { + css::table::BorderLine2 aBorderLine; + aBorderLine.Color = 0; + aBorderLine.InnerLineWidth = 0; + aBorderLine.OuterLineWidth = 0; + TablePropertyMapPtr pCellProperties(new TablePropertyMap); + pCellProperties->Insert(PROP_TOP_BORDER, css::uno::makeAny(aBorderLine)); + pCellProperties->Insert(PROP_LEFT_BORDER, css::uno::makeAny(aBorderLine)); + pCellProperties->Insert(PROP_BOTTOM_BORDER, css::uno::makeAny(aBorderLine)); + pCellProperties->Insert(PROP_RIGHT_BORDER, css::uno::makeAny(aBorderLine)); + pTableData->getCurrentRow()->addCell(pTableData->getCurrentRow()->getCellStart(0), + pCellProperties, /*bAddBefore=*/true); + } + } + + setRowEnd(true); +} + +void TableManager::endCell() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().element("tablemanager.endCell"); +#endif + + setCellEnd(true); +} + +void TableManager::inCell() +{ +#ifdef DBG_UTIL + TagLogger::getInstance().element("tablemanager.inCell"); +#endif + setInCell(true); + + if (mnTableDepthNew < 1) + mnTableDepthNew = 1; +} + +void TableManager::cellDepth(sal_uInt32 nDepth) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("tablemanager.cellDepth"); + TagLogger::getInstance().attribute("depth", nDepth); + TagLogger::getInstance().endElement(); +#endif + + mnTableDepthNew = nDepth; +} + +void TableManager::setTableStartsAtCellStart(bool bTableStartsAtCellStart) +{ + m_bTableStartsAtCellStart = bTableStartsAtCellStart; +} + +void TableManager::setCellLastParaAfterAutospacing(bool bIsAfterAutospacing) +{ + m_bCellLastParaAfterAutospacing = bIsAfterAutospacing; +} + +TableManager::TableManager() + : mnTableDepthNew(0) + , mnTableDepth(0) + , mbKeepUnfinishedRow(false) + , m_bTableStartsAtCellStart(false) +{ + setRowEnd(false); + setInCell(false); + setCellEnd(false); + m_bCellLastParaAfterAutospacing = false; +} + +TableManager::~TableManager() = default; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TableManager.hxx b/writerfilter/source/dmapper/TableManager.hxx new file mode 100644 index 000000000..5e18becab --- /dev/null +++ b/writerfilter/source/dmapper/TableManager.hxx @@ -0,0 +1,515 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEMANAGER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEMANAGER_HXX + +#include +#include + +#include "PropertyMap.hxx" +#include "TableData.hxx" + +#include + +namespace writerfilter +{ +namespace dmapper +{ + +class DomainMapperTableHandler; + +/** + The table manager. + + This class gets forwarded events from the tokenizer. It gathers the + table data and after ending the table generates events for the + table structure. The events have to be handles by a TableDataHandler. + + */ +class TableManager : public virtual SvRefBase +{ + class TableManagerState final + { + /** + properties of the current cell + */ + TablePropertyMapPtr mpCellProps; + + /** + properties of the current row + */ + TablePropertyMapPtr mpRowProps; + + /** + table exception properties of the current row + */ + TablePropertyMapPtr mpTableExceptionProps; + + /** + properties of the current table + */ + std::stack mTableProps; + + /** + true if at the end of a row + */ + bool mbRowEnd; + + /** + true when in a cell + */ + bool mbInCell; + + /** + true when at the end of a cell + */ + bool mbCellEnd; + + public: + /** + Constructor + */ + TableManagerState() + : mbRowEnd(false), mbInCell(false), mbCellEnd(false) + { + } + + void startLevel() + { + TablePropertyMapPtr pProps; + mTableProps.push(pProps); + } + + void endLevel() + { + mTableProps.pop(); + } + + /** + Reset to initial state at beginning of row. + */ + void resetCellSpecifics() + { + mbRowEnd = false; + mbInCell = false; + mbCellEnd = false; + } + + void resetCellProps() + { + mpCellProps = getTableExceptionProps(); + } + + void setCellProps(TablePropertyMapPtr pProps) + { + mpCellProps = pProps; + } + + const TablePropertyMapPtr& getCellProps() const + { + return mpCellProps; + } + + void resetRowProps() + { + // reset also table exception and + // its copy set by the previous resetCellProps() + mpTableExceptionProps.clear(); + resetCellProps(); + mpRowProps.clear(); + } + + void setRowProps(TablePropertyMapPtr pProps) + { + mpRowProps = pProps; + } + + const TablePropertyMapPtr& getRowProps() const + { + return mpRowProps; + } + + void setTableExceptionProps(TablePropertyMapPtr pProps) + { + mpTableExceptionProps = pProps; + } + + const TablePropertyMapPtr& getTableExceptionProps() const + { + return mpTableExceptionProps; + } + + void resetTableProps() + { + if (mTableProps.size() > 0) + mTableProps.top().clear(); + } + + void setTableProps(TablePropertyMapPtr pProps) + { + if (mTableProps.size() > 0) + mTableProps.top() = pProps; + } + + TablePropertyMapPtr getTableProps() + { + TablePropertyMapPtr pResult; + + if (mTableProps.size() > 0) + pResult = mTableProps.top(); + + return pResult; + } + + void setInCell(bool bInCell) + { + mbInCell = bInCell; + } + + bool isInCell() const + { + return mbInCell; + } + + void setCellEnd(bool bCellEnd) + { + mbCellEnd = bCellEnd; + } + + bool isCellEnd() const + { + return mbCellEnd; + } + + void setRowEnd(bool bRowEnd) + { + mbRowEnd = bRowEnd; + } + + bool isRowEnd() const + { + return mbRowEnd; + } + }; + + /** + handle for the current position in document + */ + css::uno::Reference mCurHandle; + + TableManagerState mState; + +protected: + TablePropertyMapPtr const & getCellProps() const + { + return mState.getCellProps(); + } + +public: + TablePropertyMapPtr const & getRowProps() const + { + return mState.getRowProps(); + } + + TablePropertyMapPtr const & getTableExceptionProps() const + { + return mState.getTableExceptionProps(); + } + +protected: + void setInCell(bool bInCell) + { + mState.setInCell(bInCell); + } + + bool isInCell() const + { + return mState.isInCell(); + } + + void setCellEnd(bool bCellEnd) + { + mState.setCellEnd(bCellEnd); + } + + void setRowEnd(bool bRowEnd) + { + mState.setRowEnd(bRowEnd); + } + + bool isRowEnd() const + { + return mState.isRowEnd(); + } + + TablePropertyMapPtr getTableProps() + { + return mState.getTableProps(); + } + + const css::uno::Reference& getHandle() const + { + return mCurHandle; + } + + void setHandle(const css::uno::Reference& rHandle) + { + mCurHandle = rHandle; + } + +private: + typedef tools::SvRef< css::uno::Reference > T_p; + + /** + depth of the current cell + */ + sal_uInt32 mnTableDepthNew; + + /** + depth of the previous cell + */ + sal_uInt32 mnTableDepth; + + /** + stack of table data + + for each level of nested tables there is one frame in the stack + */ + std::stack mTableDataStack; + RowData::Pointer_t mpUnfinishedRow; + bool mbKeepUnfinishedRow; + /// If this is a nested table, does it start at cell start? + bool m_bTableStartsAtCellStart; + + bool m_bCellLastParaAfterAutospacing; + + /** + handler for resolveCurrentTable + */ + tools::SvRef mpTableDataHandler; + + /** + Set flag which indicates the current handle is in a cell. + */ + void inCell(); + + /** + Set flag which indicate the current handle is at the end of a cell. + */ + void endCell(); + + /** + Set the table depth of the current cell. + + @param nDepth the cell depth + */ + void cellDepth(sal_uInt32 nDepth); + + /** + Set flag indication the current handle is at the end of a row. + */ + void endRow(); + + /** + Resolve the current table to the TableDataHandler. + */ + void resolveCurrentTable(); + + /** + Open a cell at current level. + */ + + void openCell(const css::uno::Reference& rHandle, const TablePropertyMapPtr& pProps); + + /** + Close a cell at current level. + */ + void closeCell(const css::uno::Reference& rHandle); + + /** + Ensure a cell is open at the current level. + */ + void ensureOpenCell(const TablePropertyMapPtr& pProps); + +protected: + /** + Return the current table difference, i.e. 1 if we are in the first cell of a new table, etc. + */ + sal_uInt32 getTableDepthDifference() const { return mnTableDepthNew - mnTableDepth; } + + sal_uInt32 getTableDepth() const { return mnTableDepthNew; } + + /** + Action to be carried out at the end of the last paragraph of a + cell. + */ + virtual void endOfCellAction(); + + /** + Action to be carried out at the end of the "table row" + paragraph. + */ + virtual void endOfRowAction(); + /** let the derived class clear their table related data + */ + virtual void clearData(); + + /** Should we keep the unfinished row in endLevel to initialize the table + data in the following startLevel. + */ + void setKeepUnfinishedRow(bool bKeep) + { + mbKeepUnfinishedRow = bKeep; + } + + +public: + TableManager(); + ~TableManager(); + + /** + Set handler for resolveCurrentTable. + + @param pTableDataHandler the handler + */ + void setHandler(const tools::SvRef& pTableDataHandler); + + /** + Set the current handle. + + @param rHandle the handle + */ + void handle(const css::uno::Reference& rHandle); + + /** + Start a new table level. + + A new context is pushed onto the table data stack, + */ + virtual void startLevel(); + + /** + End a table level. + + The current table is resolved and the context is popped from + the stack. + */ + virtual void endLevel(); + + /** + * Signal that the next paragraph definitely won't be part of any table. + */ + void endTable() + { + setRowEnd(false); + } + + /** + Tells whether a table has been started or not + */ + bool isInTable(); + + /** + Handle the start of a paragraph group. + */ + void startParagraphGroup(); + + /** + Handle the end of a paragraph group. + */ + void endParagraphGroup(); + + /** + Handle an SPRM at current handle. + + @param rSprm the SPRM + */ + virtual bool sprm(Sprm & rSprm); + + /** + Handle occurrence of character 0x7. + */ + void handle0x7(); + + /** + Handle 8 bit text at current handle. + + @param data array of characters + @param len number of characters to handle + */ + void text(const sal_uInt8 * data, size_t len); + + /** + Handle 16 bit text at current handle. + + @param data array of characters + @param len number of characters to handle + */ + void utext(const sal_uInt8 * data, size_t len); + + /** + Handle properties of the current cell. + + @param pProps the properties + */ + virtual void cellProps(const TablePropertyMapPtr& pProps); + + /** + Handle properties of the current row. + + @param pProps the properties + */ + virtual void insertRowProps(const TablePropertyMapPtr& pProps); + + /** + Handle table exception properties of the current row. + + @param pProps the properties + */ + virtual void tableExceptionProps(const TablePropertyMapPtr& pProps); + + /** + Handle properties of the current table. + + @param pProps the properties + */ + virtual void insertTableProps(const TablePropertyMapPtr& pProps); + + /** + Return if table manager has detected paragraph to ignore. + + If this function returns true the current paragraph contains + only control information, e.g. end of row. + */ + bool isIgnore() const; + + + void setTableStartsAtCellStart(bool bTableStartsAtCellStart); + void setCellLastParaAfterAutospacing(bool bIsAfterAutospacing); + bool isCellLastParaAfterAutospacing() const {return m_bCellLastParaAfterAutospacing;} +}; + +} + +} + +#endif // INCLUDED_WRITERFILTER_INC_RESOURCEMODEL_TABLEMANAGER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TablePositionHandler.cxx b/writerfilter/source/dmapper/TablePositionHandler.cxx new file mode 100644 index 000000000..2bea7876a --- /dev/null +++ b/writerfilter/source/dmapper/TablePositionHandler.cxx @@ -0,0 +1,156 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include "TablePositionHandler.hxx" +#include "ConversionHelper.hxx" +#include "TagLogger.hxx" +#include +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper +{ +using namespace ::com::sun::star; + +TablePositionHandler::TablePositionHandler() + : LoggedProperties("TablePositionHandler") + , m_aVertAnchor("margin") + , m_aHorzAnchor("text") +{ +} + +TablePositionHandler::~TablePositionHandler() = default; + +void TablePositionHandler::lcl_attribute(Id nId, Value& rVal) +{ + switch (nId) + { + case NS_ooxml::LN_CT_TblPPr_vertAnchor: + m_aVertAnchor = rVal.getString(); + break; + case NS_ooxml::LN_CT_TblPPr_tblpYSpec: + m_aYSpec = rVal.getString(); + break; + case NS_ooxml::LN_CT_TblPPr_horzAnchor: + m_aHorzAnchor = rVal.getString(); + break; + case NS_ooxml::LN_CT_TblPPr_tblpXSpec: + m_aXSpec = rVal.getString(); + break; + case NS_ooxml::LN_CT_TblPPr_tblpY: + m_nY = rVal.getInt(); + break; + case NS_ooxml::LN_CT_TblPPr_tblpX: + m_nX = rVal.getInt(); + break; + case NS_ooxml::LN_CT_TblPPr_leftFromText: + m_nLeftFromText = rVal.getInt(); + break; + case NS_ooxml::LN_CT_TblPPr_rightFromText: + m_nRightFromText = rVal.getInt(); + break; + case NS_ooxml::LN_CT_TblPPr_topFromText: + m_nTopFromText = rVal.getInt(); + break; + case NS_ooxml::LN_CT_TblPPr_bottomFromText: + m_nBottomFromText = rVal.getInt(); + break; + default: +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + break; + } +} + +void TablePositionHandler::lcl_sprm(Sprm& /*rSprm*/) {} + +uno::Sequence TablePositionHandler::getTablePosition() const +{ + comphelper::SequenceAsHashMap aFrameProperties; + + aFrameProperties["LeftBorderDistance"] <<= sal_Int32(0); + aFrameProperties["RightBorderDistance"] <<= sal_Int32(0); + aFrameProperties["TopBorderDistance"] <<= sal_Int32(0); + aFrameProperties["BottomBorderDistance"] <<= sal_Int32(0); + + aFrameProperties["LeftMargin"] <<= ConversionHelper::convertTwipToMM100(m_nLeftFromText); + aFrameProperties["RightMargin"] <<= ConversionHelper::convertTwipToMM100(m_nRightFromText); + aFrameProperties["TopMargin"] <<= ConversionHelper::convertTwipToMM100(m_nTopFromText); + aFrameProperties["BottomMargin"] <<= ConversionHelper::convertTwipToMM100(m_nBottomFromText); + + table::BorderLine2 aEmptyBorder; + aFrameProperties["TopBorder"] <<= aEmptyBorder; + aFrameProperties["BottomBorder"] <<= aEmptyBorder; + aFrameProperties["LeftBorder"] <<= aEmptyBorder; + aFrameProperties["RightBorder"] <<= aEmptyBorder; + + // Horizontal positioning + sal_Int16 nHoriOrient = text::HoriOrientation::NONE; + if (m_aXSpec == "center") + nHoriOrient = text::HoriOrientation::CENTER; + else if (m_aXSpec == "inside") + nHoriOrient = text::HoriOrientation::INSIDE; + else if (m_aXSpec == "left") + nHoriOrient = text::HoriOrientation::LEFT; + else if (m_aXSpec == "outside") + nHoriOrient = text::HoriOrientation::OUTSIDE; + else if (m_aXSpec == "right") + nHoriOrient = text::HoriOrientation::RIGHT; + + sal_Int16 nHoriOrientRelation; + if (m_aHorzAnchor == "margin") + nHoriOrientRelation = text::RelOrientation::PAGE_PRINT_AREA; + else if (m_aHorzAnchor == "page") + nHoriOrientRelation = text::RelOrientation::PAGE_FRAME; + else if (m_aHorzAnchor == "text") + nHoriOrientRelation = text::RelOrientation::FRAME; + + aFrameProperties["HoriOrient"] <<= nHoriOrient; + aFrameProperties["HoriOrientRelation"] <<= nHoriOrientRelation; + aFrameProperties["HoriOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nX); + + // Vertical positioning + sal_Int16 nVertOrient = text::VertOrientation::NONE; + if (m_aYSpec == "bottom") + nVertOrient = text::VertOrientation::BOTTOM; + else if (m_aYSpec == "center") + nVertOrient = text::VertOrientation::CENTER; + else if (m_aYSpec == "top") + nVertOrient = text::VertOrientation::TOP; + // TODO There are a few cases we can't map ATM. + + sal_Int16 nVertOrientRelation; + if (m_aVertAnchor == "margin") + nVertOrientRelation = text::RelOrientation::PAGE_PRINT_AREA; + else if (m_aVertAnchor == "page") + nVertOrientRelation = text::RelOrientation::PAGE_FRAME; + else if (m_aVertAnchor == "text") + nVertOrientRelation = text::RelOrientation::FRAME; + + aFrameProperties["VertOrient"] <<= nVertOrient; + aFrameProperties["VertOrientRelation"] <<= nVertOrientRelation; + aFrameProperties["VertOrientPosition"] <<= ConversionHelper::convertTwipToMM100(m_nY); + aFrameProperties["FillTransparence"] <<= sal_Int32(100); + + return aFrameProperties.getAsConstPropertyValueList(); +} + +bool TablePositionHandler::operator==(const TablePositionHandler& rHandler) const +{ + return m_aVertAnchor == rHandler.m_aVertAnchor && m_aYSpec == rHandler.m_aYSpec + && m_aHorzAnchor == rHandler.m_aHorzAnchor && m_aXSpec == rHandler.m_aXSpec + && m_nY == rHandler.m_nY && m_nX == rHandler.m_nX; +} + +} // namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TablePositionHandler.hxx b/writerfilter/source/dmapper/TablePositionHandler.hxx new file mode 100644 index 000000000..1a7ab58d2 --- /dev/null +++ b/writerfilter/source/dmapper/TablePositionHandler.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEPOSITIONHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEPOSITIONHANDLER_HXX + +#include "LoggedResources.hxx" + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace beans +{ +struct PropertyValue; +} +} +} +} + +namespace writerfilter +{ +namespace dmapper +{ +/// Handler for floating table positioning +class TablePositionHandler : public LoggedProperties +{ + OUString m_aVertAnchor; + OUString m_aYSpec; + OUString m_aHorzAnchor; + OUString m_aXSpec; + sal_Int32 m_nY = 0; + sal_Int32 m_nX = 0; + sal_Int32 m_nLeftFromText = 0; + sal_Int32 m_nRightFromText = 0; + sal_Int32 m_nTopFromText = 0; + sal_Int32 m_nBottomFromText = 0; + + // Properties + void lcl_attribute(Id nId, Value& rVal) override; + void lcl_sprm(Sprm& sprm) override; + +public: + sal_Int32 getY() const { return m_nY; } + sal_Int32 getX() const { return m_nX; } + sal_Int32 getLeftFromText() const { return m_nLeftFromText; } + sal_Int32 getRightFromText() const { return m_nRightFromText; } + sal_Int32 getTopFromText() const { return m_nTopFromText; } + sal_Int32 getBottomFromText() const { return m_nBottomFromText; } + + const OUString& getVertAnchor() const { return m_aVertAnchor; } + const OUString& getYSpec() const { return m_aYSpec; } + const OUString& getHorzAnchor() const { return m_aHorzAnchor; } + const OUString& getXSpec() const { return m_aXSpec; } + + TablePositionHandler(); + ~TablePositionHandler() override; + + /** Compute the UNO properties for the frame containing the table based + on the received tokens. + + Note that the properties will need to be adjusted with the table + properties before actually using them. + */ + css::uno::Sequence getTablePosition() const; + + bool operator==(const TablePositionHandler& rHandler) const; +}; + +using TablePositionHandlerPtr = tools::SvRef; +} // namespace dmapper +} // namespace writerfilter + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.cxx b/writerfilter/source/dmapper/TablePropertiesHandler.cxx new file mode 100644 index 000000000..8b5563669 --- /dev/null +++ b/writerfilter/source/dmapper/TablePropertiesHandler.cxx @@ -0,0 +1,394 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "BorderHandler.hxx" +#include "CellColorHandler.hxx" +#include "CellMarginHandler.hxx" +#include "ConversionHelper.hxx" +#include "MeasureHandler.hxx" +#include "TrackChangesHandler.hxx" +#include "TablePropertiesHandler.hxx" +#include "TagLogger.hxx" +#include "TDefTableHandler.hxx" +#include "DomainMapperTableManager.hxx" + +#include + +#include +#include + +using namespace com::sun::star; +using namespace oox; + +namespace writerfilter::dmapper { + + TablePropertiesHandler::TablePropertiesHandler() : + m_pCurrentInteropGrabBag(nullptr), + m_pTableManager( nullptr ) + { + } + + bool TablePropertiesHandler::sprm(Sprm & rSprm) + { +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("TablePropertiesHandler.sprm"); + TagLogger::getInstance().attribute("sprm", rSprm.toString()); +#endif + + bool bRet = true; + sal_uInt32 nSprmId = rSprm.getId(); + Value::Pointer_t pValue = rSprm.getValue(); + sal_Int32 nIntValue = ((pValue.get() != nullptr) ? pValue->getInt() : 0); + switch( nSprmId ) + { + case NS_ooxml::LN_CT_TrPrBase_jc: + case NS_ooxml::LN_CT_TblPrBase_jc: + { + sal_Int16 nOrient = ConversionHelper::convertTableJustification( nIntValue ); + TablePropertyMapPtr pTableMap( new TablePropertyMap ); + pTableMap->setValue( TablePropertyMap::HORI_ORIENT, nOrient ); + insertTableProps( pTableMap ); + } + break; + case NS_ooxml::LN_CT_TrPrBase_trHeight: + { + //contains unit and value + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { //contains attributes x2902 (LN_unit) and x17e2 (LN_trleft) + MeasureHandlerPtr pMeasureHandler( new MeasureHandler ); + pProperties->resolve(*pMeasureHandler); + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + + pPropMap->Insert( PROP_SIZE_TYPE, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ), false); + pPropMap->Insert( PROP_HEIGHT, uno::makeAny(pMeasureHandler->getMeasureValue() )); + + insertRowProps(pPropMap); + } + } + break; + case NS_ooxml::LN_CT_TrPr_ins: + case NS_ooxml::LN_CT_TrPr_del: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + sal_Int32 nToken = sal_Int32(); + switch( nSprmId ) + { + case NS_ooxml::LN_CT_TrPr_ins: + nToken = XML_tableRowInsert; + break; + case NS_ooxml::LN_CT_TrPr_del: + nToken = XML_tableRowDelete; + break; + } + auto pTrackChangesHandler = std::make_shared( nToken ); + pProperties->resolve(*pTrackChangesHandler); + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + + // Add the 'track changes' properties to the 'table row' via UNO. + // This way - in the SW core - when it receives this - it will create a new 'Table Redline' object for that row + uno::Sequence aTableRedlineProperties = pTrackChangesHandler->getRedlineProperties(); + pPropMap->Insert( PROP_TABLE_REDLINE_PARAMS , uno::makeAny( aTableRedlineProperties )); + insertRowProps(pPropMap); + } + } + break; + case NS_ooxml::LN_CT_TcPrBase_cellIns: + case NS_ooxml::LN_CT_TcPrBase_cellDel: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + sal_Int32 nToken; + switch( nSprmId ) + { + case NS_ooxml::LN_CT_TcPrBase_cellIns: + nToken = XML_tableCellInsert; + break; + case NS_ooxml::LN_CT_TcPrBase_cellDel: + nToken = XML_tableCellDelete; + break; + default: + throw lang::IllegalArgumentException("illegal redline token type", nullptr, 0); + break; + } + auto pTrackChangesHandler = std::make_shared( nToken ); + pProperties->resolve(*pTrackChangesHandler); + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + + // Add the 'track changes' properties to the 'table row' via UNO. + // This way - in the SW core - when it receives this - it will create a new 'Table Redline' object for that row + uno::Sequence aTableRedlineProperties = pTrackChangesHandler->getRedlineProperties(); + pPropMap->Insert( PROP_TABLE_REDLINE_PARAMS , uno::makeAny( aTableRedlineProperties )); + cellProps(pPropMap); + } + } + break; + case NS_ooxml::LN_CT_TrPrBase_cantSplit: + { + //row can't break across pages if nIntValue == 1 + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->Insert( PROP_IS_SPLIT_ALLOWED, uno::makeAny( nIntValue != 1 ) ); + insertRowProps(pPropMap); + } + break; + case NS_ooxml::LN_CT_TcPrBase_vAlign: + { + sal_Int16 nVertOrient = text::VertOrientation::NONE; + switch( nIntValue ) + { + case NS_ooxml::LN_Value_ST_VerticalJc_center: nVertOrient = text::VertOrientation::CENTER; break; + case NS_ooxml::LN_Value_ST_VerticalJc_bottom: nVertOrient = text::VertOrientation::BOTTOM; break; + default:; + } + TablePropertyMapPtr pCellPropMap( new TablePropertyMap() ); + pCellPropMap->Insert( PROP_VERT_ORIENT, uno::makeAny( nVertOrient ) ); + //todo: in ooxml import the value of m_ncell is wrong + cellProps( pCellPropMap ); + if (m_pCurrentInteropGrabBag) + { + OUString aVertOrient; + switch( nIntValue ) + { + case NS_ooxml::LN_Value_ST_VerticalJc_top: aVertOrient = "top"; break; + case NS_ooxml::LN_Value_ST_VerticalJc_center: aVertOrient = "center"; break; + case NS_ooxml::LN_Value_ST_VerticalJc_both: aVertOrient = "both"; break; + case NS_ooxml::LN_Value_ST_VerticalJc_bottom: aVertOrient = "bottom"; break; + } + if (!aVertOrient.isEmpty()) + { + beans::PropertyValue aValue; + aValue.Name = "vAlign"; + aValue.Value <<= aVertOrient; + m_pCurrentInteropGrabBag->push_back(aValue); + } + } + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblBorders: //table borders, might be defined in table style + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pBorderHandler = std::make_shared(true); + if (m_pCurrentInteropGrabBag) + pBorderHandler->enableInteropGrabBag("tblBorders"); + pProperties->resolve(*pBorderHandler); + if (m_pCurrentInteropGrabBag) + m_pCurrentInteropGrabBag->push_back(pBorderHandler->getInteropGrabBag()); + TablePropertyMapPtr pTablePropMap( new TablePropertyMap ); + pTablePropMap->InsertProps(pBorderHandler->getProperties()); + +#ifdef DBG_UTIL + pTablePropMap->dumpXml(); +#endif + insertTableProps( pTablePropMap ); + } + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblLayout: + { + DomainMapperTableManager* pManager = dynamic_cast(m_pTableManager); + if (pManager) + pManager->SetLayoutType(static_cast(nIntValue)); + } + break; + case NS_ooxml::LN_CT_TblPrEx_tblBorders: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties) + { + auto pBorderHandler = std::make_shared(true); + pProperties->resolve(*pBorderHandler); + TablePropertyMapPtr pTablePropMap( new TablePropertyMap ); + pTablePropMap->InsertProps(pBorderHandler->getProperties()); + +#ifdef DBG_UTIL + pTablePropMap->dumpXml(); +#endif + tableExceptionProps( pTablePropMap ); + } + } + break; + case NS_ooxml::LN_CT_TcPrBase_tcBorders ://cell borders + //contains CT_TcBorders_left, right, top, bottom + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + //in OOXML there's one set of borders at each cell (if there is any) + tools::SvRef< TDefTableHandler > pTDefTableHandler( new TDefTableHandler()); + if (m_pCurrentInteropGrabBag) + pTDefTableHandler->enableInteropGrabBag("tcBorders"); + pProperties->resolve( *pTDefTableHandler ); + if (m_pCurrentInteropGrabBag) + m_pCurrentInteropGrabBag->push_back(pTDefTableHandler->getInteropGrabBag()); + TablePropertyMapPtr pCellPropMap( new TablePropertyMap ); + pTDefTableHandler->fillCellProperties( pCellPropMap ); + cellProps( pCellPropMap ); + } + } + break; + case NS_ooxml::LN_CT_TcPrBase_tcMar: + + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + auto pCellMarginHandler = std::make_shared(); + if (m_pCurrentInteropGrabBag) + pCellMarginHandler->enableInteropGrabBag("tcMar"); + pProperties->resolve(*pCellMarginHandler); + if (m_pCurrentInteropGrabBag) + m_pCurrentInteropGrabBag->push_back(pCellMarginHandler->getInteropGrabBag()); + TablePropertyMapPtr pCellProperties(new TablePropertyMap); + if (pCellMarginHandler->m_bTopMarginValid) + pCellProperties->Insert(PROP_TOP_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nTopMargin)); + if (pCellMarginHandler->m_bLeftMarginValid) + pCellProperties->Insert(PROP_LEFT_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nLeftMargin)); + if (pCellMarginHandler->m_bBottomMarginValid) + pCellProperties->Insert(PROP_BOTTOM_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nBottomMargin)); + if (pCellMarginHandler->m_bRightMarginValid) + pCellProperties->Insert(PROP_RIGHT_BORDER_DISTANCE, uno::makeAny(pCellMarginHandler->m_nRightMargin)); + cellProps(pCellProperties); + } + } + break; +/* // tdf#123189 skip to keep MSO interoperability + case NS_ooxml::LN_CT_TblPrBase_shd: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties.get()) + { + std::shared_ptr pCellColorHandler( new CellColorHandler); + pProperties->resolve( *pCellColorHandler ); + TablePropertyMapPtr pTablePropMap( new TablePropertyMap ); + insertTableProps( pCellColorHandler->getProperties() ); + } + } +*/ + break; + case NS_ooxml::LN_CT_TcPrBase_shd: + { + // each color sprm contains as much colors as cells are in a row + //LN_CT_TcPrBase_shd: cell shading contains: LN_CT_Shd_val, LN_CT_Shd_fill, LN_CT_Shd_color + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pCellColorHandler = std::make_shared(); + pCellColorHandler->enableInteropGrabBag("shd"); //enable to store shd unsupported props in grab bag + pProperties->resolve( *pCellColorHandler ); + TablePropertyMapPtr pPropertyMap = pCellColorHandler->getProperties(); + beans::PropertyValue aGrabBag = pCellColorHandler->getInteropGrabBag(); + if (m_pCurrentInteropGrabBag) + m_pCurrentInteropGrabBag->push_back(aGrabBag); + pPropertyMap->Insert( PROP_CELL_INTEROP_GRAB_BAG, aGrabBag.Value ); + cellProps( pPropertyMap ); + } + } + break; +//OOXML table properties + case NS_ooxml::LN_CT_TblPrBase_tblCellMar: //cell margins + { + //contains LN_CT_TblCellMar_top, LN_CT_TblCellMar_left, LN_CT_TblCellMar_bottom, LN_CT_TblCellMar_right + // LN_CT_TblCellMar_start, LN_CT_TblCellMar_end + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + auto pCellMarginHandler = std::make_shared(); + if (m_pCurrentInteropGrabBag) + pCellMarginHandler->enableInteropGrabBag("tblCellMar"); + pProperties->resolve( *pCellMarginHandler ); + if (m_pCurrentInteropGrabBag) + m_pCurrentInteropGrabBag->push_back(pCellMarginHandler->getInteropGrabBag()); + TablePropertyMapPtr pMarginProps( new TablePropertyMap ); + if( pCellMarginHandler->m_bTopMarginValid ) + pMarginProps->setValue( TablePropertyMap::CELL_MAR_TOP, pCellMarginHandler->m_nTopMargin ); + if( pCellMarginHandler->m_bBottomMarginValid ) + pMarginProps->setValue( TablePropertyMap::CELL_MAR_BOTTOM, pCellMarginHandler->m_nBottomMargin ); + if( pCellMarginHandler->m_bLeftMarginValid ) + pMarginProps->setValue( TablePropertyMap::CELL_MAR_LEFT, pCellMarginHandler->m_nLeftMargin ); + if( pCellMarginHandler->m_bRightMarginValid ) + pMarginProps->setValue( TablePropertyMap::CELL_MAR_RIGHT, pCellMarginHandler->m_nRightMargin ); + insertTableProps(pMarginProps); + } + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblInd: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties) + { + MeasureHandlerPtr pHandler(new MeasureHandler); + if (m_pCurrentInteropGrabBag) + pHandler->enableInteropGrabBag("tblInd"); + pProperties->resolve( *pHandler ); + if (m_pCurrentInteropGrabBag) + m_pCurrentInteropGrabBag->push_back(pHandler->getInteropGrabBag()); + TablePropertyMapPtr pTblIndMap(new TablePropertyMap); + sal_uInt32 nTblInd = pHandler->getMeasureValue(); + pTblIndMap->setValue( TablePropertyMap::LEFT_MARGIN, nTblInd); + insertTableProps(pTblIndMap); + } + } + break; + case NS_ooxml::LN_CT_TcPrBase_hideMark: + if (nIntValue) + { + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(PROP_CELL_HIDE_MARK, uno::makeAny(nIntValue)); + cellProps(pPropMap); + } + break; + default: + // Not handled here, give the next handler a chance. + bRet = false; + // However, these logically belong here, so save the value if necessary. + switch (nSprmId) + { + case NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize: + case NS_ooxml::LN_CT_TblPrBase_tblStyleColBandSize: + if (m_pCurrentInteropGrabBag) + { + beans::PropertyValue aValue; + aValue.Name = (nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize ? OUStringLiteral("tblStyleRowBandSize") : OUStringLiteral("tblStyleColBandSize")); + aValue.Value <<= nIntValue; + m_pCurrentInteropGrabBag->push_back(aValue); + } + break; + } + break; + } + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif + + return bRet; + } + + void TablePropertiesHandler::SetInteropGrabBag(std::vector& rValue) + { + m_pCurrentInteropGrabBag = &rValue; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.hxx b/writerfilter/source/dmapper/TablePropertiesHandler.hxx new file mode 100644 index 000000000..514adbe12 --- /dev/null +++ b/writerfilter/source/dmapper/TablePropertiesHandler.hxx @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEPROPERTIESHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TABLEPROPERTIESHANDLER_HXX + +#include "PropertyMap.hxx" + +#include "TableManager.hxx" +#include + +#include + +namespace writerfilter { +namespace dmapper { + +class DomainMapper; + +class TablePropertiesHandler final : public virtual SvRefBase +{ +private: + PropertyMapPtr m_pCurrentProperties; + std::vector* m_pCurrentInteropGrabBag; + TableManager* m_pTableManager; + +public: + TablePropertiesHandler(); + + bool sprm(Sprm & sprm); + + void SetTableManager( TableManager* pTableManager ) + { + m_pTableManager = pTableManager; + }; + + void SetProperties( PropertyMapPtr pProperties ) + { + m_pCurrentProperties = pProperties; + }; + + void SetInteropGrabBag(std::vector& rValue); + +private: + + void cellProps( TablePropertyMapPtr pProps ) + { + if ( m_pTableManager ) + m_pTableManager->cellProps( pProps ); + else + m_pCurrentProperties->InsertProps(pProps.get()); + }; + + void insertRowProps( TablePropertyMapPtr pProps ) + { + if ( m_pTableManager ) + m_pTableManager->insertRowProps( pProps ); + else + m_pCurrentProperties->InsertProps(pProps.get()); + }; + + void tableExceptionProps( TablePropertyMapPtr pProps ) + { + if ( m_pTableManager ) + m_pTableManager->tableExceptionProps( pProps ); + else + m_pCurrentProperties->InsertProps(pProps.get()); + }; + + void insertTableProps( TablePropertyMapPtr pProps ) + { + if ( m_pTableManager ) + m_pTableManager->insertTableProps( pProps ); + else + m_pCurrentProperties->InsertProps(pProps.get()); + }; +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TagLogger.cxx b/writerfilter/source/dmapper/TagLogger.cxx new file mode 100644 index 000000000..6c655589d --- /dev/null +++ b/writerfilter/source/dmapper/TagLogger.cxx @@ -0,0 +1,237 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "TagLogger.hxx" +#ifdef DBG_UTIL +#include +#endif + +using namespace css; + +namespace writerfilter +{ + TagLogger::TagLogger() + : pWriter( nullptr ), pName( "DOMAINMAPPER" ) + { + } + + TagLogger::~TagLogger() + { + pWriter = nullptr; + pName = nullptr; + } + +#ifdef DBG_UTIL + void TagLogger::setFileName( const std::string & filename ) + { + if ( pWriter ) + endDocument(); + + std::string fileName; + char * temp = getenv("TAGLOGGERTMP"); + + if (temp != nullptr) + fileName += temp; + else + fileName += SvtPathOptions().GetTempPath().toUtf8().getStr(); + + std::string sPrefix = filename; + size_t nLastSlash = sPrefix.find_last_of('/'); + size_t nLastBackslash = sPrefix.find_last_of('\\'); + size_t nCutPos = nLastSlash; + if (nLastBackslash < nCutPos) + nCutPos = nLastBackslash; + if (nCutPos < sPrefix.size()) + sPrefix = sPrefix.substr(nCutPos + 1); + + fileName += "/"; + fileName += sPrefix; + fileName += "."; + fileName += pName; + fileName += ".xml"; + + pWriter = xmlNewTextWriterFilename( fileName.c_str(), 0 ); + xmlTextWriterSetIndent(pWriter,1); + xmlTextWriterSetIndentString(pWriter, BAD_CAST(" ")); + xmlTextWriterSetIndent( pWriter, 4 ); + } + + void TagLogger::startDocument() + { + if (!pWriter) + return; + xmlTextWriterStartDocument( pWriter, nullptr, nullptr, nullptr ); + xmlTextWriterStartElement( pWriter, BAD_CAST( "root" ) ); + } + + void TagLogger::endDocument() + { + if (!pWriter) + return; + xmlTextWriterEndDocument( pWriter ); + xmlFreeTextWriter( pWriter ); + pWriter = nullptr; + } + +#endif + +namespace { + +struct TheTagLogger: + public rtl::Static +{}; + +} + + TagLogger& TagLogger::getInstance() + { + return TheTagLogger::get(); + } + +#ifdef DBG_UTIL + void TagLogger::element(const std::string & name) + { + startElement(name); + endElement(); + } + + void TagLogger::unoPropertySet(const uno::Reference& rPropSet) + { + uno::Reference xPropSetInfo(rPropSet->getPropertySetInfo()); + const uno::Sequence aProps(xPropSetInfo->getProperties()); + + startElement( "unoPropertySet" ); + + for (beans::Property const & prop : aProps) + { + startElement( "property" ); + OUString sName(prop.Name); + + attribute( "name", sName ); + try + { + attribute( "value", rPropSet->getPropertyValue( sName ) ); + } + catch (const uno::Exception &) + { + startElement( "exception" ); + + chars(std::string("getPropertyValue(\"")); + chars(sName); + chars(std::string("\")")); + + endElement( ); + } + endElement( ); + } + endElement( ); + } + + void TagLogger::startElement(const std::string & name) + { + if (!pWriter) + return; + xmlChar* xmlName = xmlCharStrdup( name.c_str() ); + xmlTextWriterStartElement( pWriter, xmlName ); + xmlFree( xmlName ); + } +#endif + + void TagLogger::attribute(const std::string & name, const std::string & value) + { + if (!pWriter) + return; + xmlChar* xmlName = xmlCharStrdup( name.c_str() ); + xmlChar* xmlValue = xmlCharStrdup( value.c_str() ); + xmlTextWriterWriteAttribute( pWriter, xmlName, xmlValue ); + + xmlFree( xmlValue ); + xmlFree( xmlName ); + } + +#ifdef DBG_UTIL + void TagLogger::attribute(const std::string & name, const OUString & value) + { + attribute( name, OUStringToOString( value, RTL_TEXTENCODING_ASCII_US ).getStr() ); + } + + void TagLogger::attribute(const std::string & name, sal_uInt32 value) + { + if (!pWriter) + return; + xmlChar* xmlName = xmlCharStrdup( name.c_str() ); + xmlTextWriterWriteFormatAttribute( pWriter, xmlName, + "%" SAL_PRIuUINT32, value ); + xmlFree( xmlName ); + } + + void TagLogger::attribute(const std::string & name, const uno::Any& aAny) + { + if (!pWriter) + return; + + sal_Int32 nInt = 0; + float nFloat = 0.0; + OUString aStr; + + xmlChar* xmlName = xmlCharStrdup( name.c_str() ); + if ( aAny >>= nInt ) + { + xmlTextWriterWriteFormatAttribute( pWriter, xmlName, + "%" SAL_PRIdINT32, nInt ); + } + else if ( aAny >>= nFloat ) + { + xmlTextWriterWriteFormatAttribute( pWriter, xmlName, + "%f", nFloat ); + } + else if ( aAny >>= aStr ) + { + attribute( name, aStr ); + } + xmlFree( xmlName ); + } + + void TagLogger::chars(const std::string & rChars) + { + if (!pWriter) + return; + xmlChar* xmlChars = xmlCharStrdup( rChars.c_str() ); + xmlTextWriterWriteString( pWriter, xmlChars ); + xmlFree( xmlChars ); + } + + void TagLogger::chars(const OUString & rChars) + { + chars(OUStringToOString(rChars, RTL_TEXTENCODING_ASCII_US).getStr()); + } + + void TagLogger::endElement() + { + if (!pWriter) + return; + xmlTextWriterEndElement( pWriter ); + } + +#endif + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TagLogger.hxx b/writerfilter/source/dmapper/TagLogger.hxx new file mode 100644 index 000000000..e61895a30 --- /dev/null +++ b/writerfilter/source/dmapper/TagLogger.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TAGLOGGER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TAGLOGGER_HXX + +#include +#include +#include +#include +#include + +namespace writerfilter +{ + + class TagLogger + { + private: + static tools::SvRef instance; + + xmlTextWriterPtr pWriter; + const char* pName; + + public: + explicit TagLogger(); + ~TagLogger(); + + static TagLogger& getInstance(); + +#ifdef DBG_UTIL + void setFileName(const std::string & filename); + void startDocument(); + void endDocument(); + + void element(const std::string & name); + void unoPropertySet(const css::uno::Reference& rPropSet); + void startElement(const std::string & name); +#endif + void attribute(const std::string & name, const std::string & value); +#ifdef DBG_UTIL + void attribute(const std::string & name, const OUString & value); + void attribute(const std::string & name, sal_uInt32 value); + void attribute(const std::string & name, const css::uno::Any& aAny); + void chars(const std::string & chars); + void chars(const OUString & chars); + void endElement(); +#endif + }; +} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TAGLOGGER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TblStylePrHandler.cxx b/writerfilter/source/dmapper/TblStylePrHandler.cxx new file mode 100644 index 000000000..001cecbd9 --- /dev/null +++ b/writerfilter/source/dmapper/TblStylePrHandler.cxx @@ -0,0 +1,259 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "TblStylePrHandler.hxx" +#include "TagLogger.hxx" +#include "CellMarginHandler.hxx" +#include "PropertyMap.hxx" +#include "MeasureHandler.hxx" +#include +#include + + +using namespace css; + +namespace writerfilter::dmapper { + +TblStylePrHandler::TblStylePrHandler( DomainMapper & rDMapper ) : +LoggedProperties("TblStylePrHandler"), +m_rDMapper( rDMapper ), +m_pTablePropsHandler(new TablePropertiesHandler()), +m_nType( TBL_STYLE_UNKNOWN ), +m_pProperties( new PropertyMap ) +{ +} + +TblStylePrHandler::~TblStylePrHandler( ) +{ +} + +OUString TblStylePrHandler::getTypeString() const +{ + switch (m_nType) + { + case TBL_STYLE_WHOLETABLE: return "wholeTable"; + case TBL_STYLE_FIRSTROW: return "firstRow"; + case TBL_STYLE_LASTROW: return "lastRow"; + case TBL_STYLE_FIRSTCOL: return "firstCol"; + case TBL_STYLE_LASTCOL: return "lastCol"; + case TBL_STYLE_BAND1VERT: return "band1Vert"; + case TBL_STYLE_BAND2VERT: return "band2Vert"; + case TBL_STYLE_BAND1HORZ: return "band1Horz"; + case TBL_STYLE_BAND2HORZ: return "band2Horz"; + case TBL_STYLE_NECELL: return "neCell"; + case TBL_STYLE_NWCELL: return "nwCell"; + case TBL_STYLE_SECELL: return "seCell"; + case TBL_STYLE_SWCELL: return "swCell"; + default: break; + } + return OUString(); +} + +void TblStylePrHandler::lcl_attribute(Id rName, Value & rVal) +{ + + switch ( rName ) + { + case NS_ooxml::LN_CT_TblStyleOverrideType: + { + switch (rVal.getInt()) + { + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_wholeTable: + m_nType = TBL_STYLE_WHOLETABLE; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstRow: + m_nType = TBL_STYLE_FIRSTROW; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastRow: + m_nType = TBL_STYLE_LASTROW; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstCol: + m_nType = TBL_STYLE_FIRSTCOL; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastCol: + m_nType = TBL_STYLE_LASTCOL; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Vert: + m_nType = TBL_STYLE_BAND1VERT; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Vert: + m_nType = TBL_STYLE_BAND2VERT; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Horz: + m_nType = TBL_STYLE_BAND1HORZ; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Horz: + m_nType = TBL_STYLE_BAND2HORZ; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_neCell: + m_nType = TBL_STYLE_NECELL; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_nwCell: + m_nType = TBL_STYLE_NWCELL; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_seCell: + m_nType = TBL_STYLE_SECELL; + break; + case NS_ooxml::LN_Value_ST_TblStyleOverrideType_swCell: + m_nType = TBL_STYLE_SWCELL; + break; + } + } + break; + } +} + +void TblStylePrHandler::lcl_sprm(Sprm & rSprm) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("TblStylePrHandler.sprm"); + TagLogger::getInstance().attribute("sprm", rSprm.toString()); +#endif + + switch ( rSprm.getId( ) ) + { + case NS_ooxml::LN_CT_PPrBase: + case NS_ooxml::LN_EG_RPrBase: + case NS_ooxml::LN_CT_TblPrBase: + case NS_ooxml::LN_CT_TrPrBase: + case NS_ooxml::LN_CT_TcPrBase: + { + std::vector aSavedGrabBag; + bool bGrabBag = rSprm.getId() == NS_ooxml::LN_CT_PPrBase || + rSprm.getId() == NS_ooxml::LN_EG_RPrBase || + rSprm.getId() == NS_ooxml::LN_CT_TblPrBase || + rSprm.getId() == NS_ooxml::LN_CT_TrPrBase || + rSprm.getId() == NS_ooxml::LN_CT_TcPrBase; + if (bGrabBag) + { + std::swap(aSavedGrabBag, m_aInteropGrabBag); + } + resolveSprmProps( rSprm ); + if (bGrabBag) + { + if (rSprm.getId() == NS_ooxml::LN_CT_PPrBase) + aSavedGrabBag.push_back(getInteropGrabBag("pPr")); + else if (rSprm.getId() == NS_ooxml::LN_EG_RPrBase) + aSavedGrabBag.push_back(getInteropGrabBag("rPr")); + else if (rSprm.getId() == NS_ooxml::LN_CT_TblPrBase) + aSavedGrabBag.push_back(getInteropGrabBag("tblPr")); + else if (rSprm.getId() == NS_ooxml::LN_CT_TrPrBase) + aSavedGrabBag.push_back(getInteropGrabBag("trPr")); + else if (rSprm.getId() == NS_ooxml::LN_CT_TcPrBase) + aSavedGrabBag.push_back(getInteropGrabBag("tcPr")); + std::swap(m_aInteropGrabBag, aSavedGrabBag); + } + } + break; + case NS_ooxml::LN_CT_TrPrBase_tblHeader: + { + m_pProperties->Insert( PROP_HEADER_ROW_COUNT, uno::makeAny(sal_Int32(1))); + beans::PropertyValue aValue; + aValue.Name = "tblHeader"; + aValue.Value <<= true; + m_aInteropGrabBag.push_back(aValue); + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblInd: + { + //contains unit and value + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + { + MeasureHandlerPtr pMeasureHandler( new MeasureHandler ); + pProperties->resolve(*pMeasureHandler); + TablePropertyMapPtr pPropMap( new TablePropertyMap ); + pPropMap->setValue( TablePropertyMap::LEFT_MARGIN, pMeasureHandler->getMeasureValue() ); + m_pProperties->Insert( PROP_LEFT_MARGIN, uno::makeAny(pMeasureHandler->getMeasureValue()) ); + } + } + break; + case NS_ooxml::LN_CT_TblPrBase_tblCellMar: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if ( pProperties ) + { + auto pCellMarginHandler = std::make_shared(); + pCellMarginHandler->enableInteropGrabBag("tblCellMar"); + pProperties->resolve( *pCellMarginHandler ); + m_aInteropGrabBag.push_back(pCellMarginHandler->getInteropGrabBag()); + + if( pCellMarginHandler->m_bTopMarginValid ) + m_pProperties->Insert( META_PROP_CELL_MAR_TOP, uno::makeAny(pCellMarginHandler->m_nTopMargin) ); + if( pCellMarginHandler->m_bBottomMarginValid ) + m_pProperties->Insert( META_PROP_CELL_MAR_BOTTOM, uno::makeAny(pCellMarginHandler->m_nBottomMargin) ); + if( pCellMarginHandler->m_bLeftMarginValid ) + m_pProperties->Insert( META_PROP_CELL_MAR_LEFT, uno::makeAny(pCellMarginHandler->m_nLeftMargin) ); + if( pCellMarginHandler->m_bRightMarginValid ) + m_pProperties->Insert( META_PROP_CELL_MAR_RIGHT, uno::makeAny(pCellMarginHandler->m_nRightMargin) ); + } + } + break; + default: + // Tables specific properties have to handled here + m_pTablePropsHandler->SetProperties( m_pProperties ); + m_pTablePropsHandler->SetInteropGrabBag(m_aInteropGrabBag); + bool bRet = m_pTablePropsHandler->sprm( rSprm ); + + if ( !bRet ) + { + // The DomainMapper can handle some of the properties + m_rDMapper.PushStyleSheetProperties( m_pProperties, true ); + // Just pass a non-empty string, the array will have a single element anyway. + m_rDMapper.enableInteropGrabBag("TblStylePrHandler"); + m_rDMapper.sprm( rSprm ); + uno::Sequence aGrabBag = m_rDMapper.getInteropGrabBag().Value.get< uno::Sequence >(); + if (aGrabBag.hasElements()) + m_aInteropGrabBag.push_back(aGrabBag[0]); + m_rDMapper.PopStyleSheetProperties( true ); + } + } + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void TblStylePrHandler::resolveSprmProps(Sprm & rSprm) +{ + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + pProperties->resolve(*this); +} + +void TblStylePrHandler::appendInteropGrabBag(const OUString& aKey, const OUString& aValue) +{ + beans::PropertyValue aProperty; + aProperty.Name = aKey; + aProperty.Value <<= aValue; + m_aInteropGrabBag.push_back(aProperty); +} + +beans::PropertyValue TblStylePrHandler::getInteropGrabBag(const OUString& aName) +{ + beans::PropertyValue aRet; + aRet.Name = aName; + + aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag); + return aRet; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TblStylePrHandler.hxx b/writerfilter/source/dmapper/TblStylePrHandler.hxx new file mode 100644 index 000000000..578b3a98a --- /dev/null +++ b/writerfilter/source/dmapper/TblStylePrHandler.hxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TBLSTYLEPRHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TBLSTYLEPRHANDLER_HXX + +#include "TablePropertiesHandler.hxx" + +#include "DomainMapper.hxx" +#include "LoggedResources.hxx" +#include +#include + +namespace writerfilter { +namespace dmapper { + +class DomainMapper; + +enum TblStyleType +{ + TBL_STYLE_UNKNOWN, + TBL_STYLE_WHOLETABLE, + TBL_STYLE_FIRSTROW, + TBL_STYLE_LASTROW, + TBL_STYLE_FIRSTCOL, + TBL_STYLE_LASTCOL, + TBL_STYLE_BAND1VERT, + TBL_STYLE_BAND2VERT, + TBL_STYLE_BAND1HORZ, + TBL_STYLE_BAND2HORZ, + TBL_STYLE_NECELL, + TBL_STYLE_NWCELL, + TBL_STYLE_SECELL, + TBL_STYLE_SWCELL +}; + +class TblStylePrHandler : public LoggedProperties +{ +private: + DomainMapper & m_rDMapper; + std::unique_ptr m_pTablePropsHandler; + + TblStyleType m_nType; + PropertyMapPtr m_pProperties; + std::vector m_aInteropGrabBag; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +public: + explicit TblStylePrHandler( DomainMapper & rDMapper ); + virtual ~TblStylePrHandler( ) override; + + const PropertyMapPtr& getProperties() const { return m_pProperties; }; + TblStyleType getType() const { return m_nType; }; + OUString getTypeString() const; + void appendInteropGrabBag(const OUString& aKey, const OUString& aValue); + css::beans::PropertyValue getInteropGrabBag(const OUString& aName); + +private: + + void resolveSprmProps(Sprm & rSprm); +}; + +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TextEffectsHandler.cxx b/writerfilter/source/dmapper/TextEffectsHandler.cxx new file mode 100644 index 000000000..13fed5237 --- /dev/null +++ b/writerfilter/source/dmapper/TextEffectsHandler.cxx @@ -0,0 +1,803 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include + +#include + +#include "TextEffectsHandler.hxx" + +#include +#include +#include +#include +#include + +namespace writerfilter::dmapper +{ + +using namespace com::sun::star; + +namespace +{ + +OUString lclGetNameForElementId(sal_uInt32 aId) +{ + static std::map aIdMap; + if(aIdMap.empty()) + { + aIdMap[NS_ooxml::LN_EG_ColorChoice_srgbClr] = "srgbClr"; + aIdMap[NS_ooxml::LN_EG_ColorChoice_schemeClr] = "schemeClr"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_tint] = "tint"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_shade] = "shade"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_alpha] = "alpha"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_hueMod] = "hueMod"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_sat] = "sat"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_satOff] = "satOff"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_satMod] = "satMod"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_lum] = "lum"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_lumOff] = "lumOff"; + aIdMap[NS_ooxml::LN_EG_ColorTransform_lumMod] = "lumMod"; + aIdMap[NS_ooxml::LN_EG_FillProperties_noFill] = "noFill"; + aIdMap[NS_ooxml::LN_EG_FillProperties_solidFill] = "solidFill"; + aIdMap[NS_ooxml::LN_EG_FillProperties_gradFill] = "gradFill"; + aIdMap[NS_ooxml::LN_CT_GradientFillProperties_gsLst] = "gsLst"; + aIdMap[NS_ooxml::LN_CT_GradientStopList_gs] = "gs"; + aIdMap[NS_ooxml::LN_CT_GradientStop_pos] = "pos"; + aIdMap[NS_ooxml::LN_EG_ShadeProperties_lin] = "lin"; + aIdMap[NS_ooxml::LN_EG_ShadeProperties_path] = "path"; + aIdMap[NS_ooxml::LN_CT_PathShadeProperties_fillToRect] = "fillToRect"; + aIdMap[NS_ooxml::LN_EG_LineDashProperties_prstDash] = "prstDash"; + aIdMap[NS_ooxml::LN_EG_LineJoinProperties_round] = "round"; + aIdMap[NS_ooxml::LN_EG_LineJoinProperties_bevel] = "bevel"; + aIdMap[NS_ooxml::LN_EG_LineJoinProperties_miter] = "miter"; + aIdMap[NS_ooxml::LN_CT_Scene3D_camera] = "camera"; + aIdMap[NS_ooxml::LN_CT_Scene3D_lightRig] = "lightRig"; + aIdMap[NS_ooxml::LN_CT_LightRig_rot] = "rot"; + aIdMap[NS_ooxml::LN_CT_Props3D_bevelT] = "bevelT"; + aIdMap[NS_ooxml::LN_CT_Props3D_bevelB] = "bevelB"; + aIdMap[NS_ooxml::LN_CT_Props3D_extrusionClr] = "extrusionClr"; + aIdMap[NS_ooxml::LN_CT_Props3D_contourClr] = "contourClr"; + aIdMap[NS_ooxml::LN_CT_StylisticSets_styleSet] = "styleSet"; + } + return aIdMap[aId]; +} + +const char constAttributesSequenceName[] = "attributes"; + +} + +OUString TextEffectsHandler::getSchemeColorValTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_SchemeColorVal_bg1: return "bg1"; + case NS_ooxml::LN_ST_SchemeColorVal_tx1: return "tx1"; + case NS_ooxml::LN_ST_SchemeColorVal_bg2: return "bg2"; + case NS_ooxml::LN_ST_SchemeColorVal_tx2: return "tx2"; + case NS_ooxml::LN_ST_SchemeColorVal_accent1: return "accent1"; + case NS_ooxml::LN_ST_SchemeColorVal_accent2: return "accent2"; + case NS_ooxml::LN_ST_SchemeColorVal_accent3: return "accent3"; + case NS_ooxml::LN_ST_SchemeColorVal_accent4: return "accent4"; + case NS_ooxml::LN_ST_SchemeColorVal_accent5: return "accent5"; + case NS_ooxml::LN_ST_SchemeColorVal_accent6: return "accent6"; + case NS_ooxml::LN_ST_SchemeColorVal_hlink: return "hlink"; + case NS_ooxml::LN_ST_SchemeColorVal_folHlink: return "folHlink"; + case NS_ooxml::LN_ST_SchemeColorVal_dk1: return "dk1"; + case NS_ooxml::LN_ST_SchemeColorVal_lt1: return "lt1"; + case NS_ooxml::LN_ST_SchemeColorVal_dk2: return "dk2"; + case NS_ooxml::LN_ST_SchemeColorVal_lt2: return "lt2"; + case NS_ooxml::LN_ST_SchemeColorVal_phClr: return "phClr"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getRectAlignmentString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_RectAlignment_none: return "none"; + case NS_ooxml::LN_ST_RectAlignment_tl: return "tl"; + case NS_ooxml::LN_ST_RectAlignment_t: return "t"; + case NS_ooxml::LN_ST_RectAlignment_tr: return "tr"; + case NS_ooxml::LN_ST_RectAlignment_l: return "l"; + case NS_ooxml::LN_ST_RectAlignment_ctr: return "ctr"; + case NS_ooxml::LN_ST_RectAlignment_r: return "r"; + case NS_ooxml::LN_ST_RectAlignment_bl: return "bl"; + case NS_ooxml::LN_ST_RectAlignment_b: return "b"; + case NS_ooxml::LN_ST_RectAlignment_br: return "br"; + + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getLineCapString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_LineCap_rnd: return "rnd"; + case NS_ooxml::LN_ST_LineCap_sq: return "sq"; + case NS_ooxml::LN_ST_LineCap_flat: return "flat"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getCompoundLineString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_CompoundLine_sng: return "sng"; + case NS_ooxml::LN_ST_CompoundLine_dbl: return "dbl"; + case NS_ooxml::LN_ST_CompoundLine_thickThin: return "thickThin"; + case NS_ooxml::LN_ST_CompoundLine_thinThick: return "thinThick"; + case NS_ooxml::LN_ST_CompoundLine_tri: return "tri"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getPenAlignmentString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_PenAlignment_ctr: return "ctr"; + case NS_ooxml::LN_ST_PenAlignment_in: return "in"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getOnOffString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_OnOff_true: return "true"; + case NS_ooxml::LN_ST_OnOff_false: return "false"; + case NS_ooxml::LN_ST_OnOff_1: return "1"; + case NS_ooxml::LN_ST_OnOff_0: return "0"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getPathShadeTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_PathShadeType_shape: return "shape"; + case NS_ooxml::LN_ST_PathShadeType_circle: return "circle"; + case NS_ooxml::LN_ST_PathShadeType_rect: return "rect"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getPresetLineDashValString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_PresetLineDashVal_solid: return "solid"; + case NS_ooxml::LN_ST_PresetLineDashVal_dot: return "dot"; + case NS_ooxml::LN_ST_PresetLineDashVal_sysDot: return "sysDot"; + case NS_ooxml::LN_ST_PresetLineDashVal_dash: return "dash"; + case NS_ooxml::LN_ST_PresetLineDashVal_sysDash: return "sysDash"; + case NS_ooxml::LN_ST_PresetLineDashVal_lgDash: return "lgDash"; + case NS_ooxml::LN_ST_PresetLineDashVal_dashDot: return "dashDot"; + case NS_ooxml::LN_ST_PresetLineDashVal_sysDashDot: return "sysDashDot"; + case NS_ooxml::LN_ST_PresetLineDashVal_lgDashDot: return "lgDashDot"; + case NS_ooxml::LN_ST_PresetLineDashVal_lgDashDotDot: return "lgDashDotDot"; + case NS_ooxml::LN_ST_PresetLineDashVal_sysDashDotDot: return "sysDashDotDot"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getPresetCameraTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueTopLeft: return "legacyObliqueTopLeft"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueTop: return "legacyObliqueTop"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueTopRight: return "legacyObliqueTopRight"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueLeft: return "legacyObliqueLeft"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueFront: return "legacyObliqueFront"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueRight: return "legacyObliqueRight"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueBottomLeft: return "legacyObliqueBottomLeft"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueBottom: return "legacyObliqueBottom"; + case NS_ooxml::LN_ST_PresetCameraType_legacyObliqueBottomRight: return "legacyObliqueBottomRight"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveTopLeft: return "legacyPerspectiveTopLeft"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveTop: return "legacyPerspectiveTop"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveTopRight: return "legacyPerspectiveTopRight"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveLeft: return "legacyPerspectiveLeft"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveFront: return "legacyPerspectiveFront"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveRight: return "legacyPerspectiveRight"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveBottomLeft: return "legacyPerspectiveBottomLeft"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveBottom: return "legacyPerspectiveBottom"; + case NS_ooxml::LN_ST_PresetCameraType_legacyPerspectiveBottomRight: return "legacyPerspectiveBottomRight"; + case NS_ooxml::LN_ST_PresetCameraType_orthographicFront: return "orthographicFront"; + case NS_ooxml::LN_ST_PresetCameraType_isometricTopUp: return "isometricTopUp"; + case NS_ooxml::LN_ST_PresetCameraType_isometricTopDown: return "isometricTopDown"; + case NS_ooxml::LN_ST_PresetCameraType_isometricBottomUp: return "isometricBottomUp"; + case NS_ooxml::LN_ST_PresetCameraType_isometricBottomDown: return "isometricBottomDown"; + case NS_ooxml::LN_ST_PresetCameraType_isometricLeftUp: return "isometricLeftUp"; + case NS_ooxml::LN_ST_PresetCameraType_isometricLeftDown: return "isometricLeftDown"; + case NS_ooxml::LN_ST_PresetCameraType_isometricRightUp: return "isometricRightUp"; + case NS_ooxml::LN_ST_PresetCameraType_isometricRightDown: return "isometricRightDown"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis1Left: return "isometricOffAxis1Left"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis1Right: return "isometricOffAxis1Right"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis1Top: return "isometricOffAxis1Top"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis2Left: return "isometricOffAxis2Left"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis2Right: return "isometricOffAxis2Right"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis2Top: return "isometricOffAxis2Top"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis3Left: return "isometricOffAxis3Left"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis3Right: return "isometricOffAxis3Right"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis3Bottom: return "isometricOffAxis3Bottom"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis4Left: return "isometricOffAxis4Left"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis4Right: return "isometricOffAxis4Right"; + case NS_ooxml::LN_ST_PresetCameraType_isometricOffAxis4Bottom: return "isometricOffAxis4Bottom"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueTopLeft: return "obliqueTopLeft"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueTop: return "obliqueTop"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueTopRight: return "obliqueTopRight"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueLeft: return "obliqueLeft"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueRight: return "obliqueRight"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueBottomLeft: return "obliqueBottomLeft"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueBottom: return "obliqueBottom"; + case NS_ooxml::LN_ST_PresetCameraType_obliqueBottomRight: return "obliqueBottomRight"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveFront: return "perspectiveFront"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveLeft: return "perspectiveLeft"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveRight: return "perspectiveRight"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveAbove: return "perspectiveAbove"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveBelow: return "perspectiveBelow"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveAboveLeftFacing: return "perspectiveAboveLeftFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveAboveRightFacing: return "perspectiveAboveRightFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveContrastingLeftFacing: return "perspectiveContrastingLeftFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveContrastingRightFacing: return "perspectiveContrastingRightFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveHeroicLeftFacing: return "perspectiveHeroicLeftFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveHeroicRightFacing: return "perspectiveHeroicRightFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveHeroicExtremeLeftFacing: return "perspectiveHeroicExtremeLeftFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveHeroicExtremeRightFacing: return "perspectiveHeroicExtremeRightFacing"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveRelaxed: return "perspectiveRelaxed"; + case NS_ooxml::LN_ST_PresetCameraType_perspectiveRelaxedModerately: return "perspectiveRelaxedModerately"; + default: break; + } + return OUString(); +} + + +OUString TextEffectsHandler::getLightRigTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_LightRigType_legacyFlat1: return "legacyFlat1"; + case NS_ooxml::LN_ST_LightRigType_legacyFlat2: return "legacyFlat2"; + case NS_ooxml::LN_ST_LightRigType_legacyFlat3: return "legacyFlat3"; + case NS_ooxml::LN_ST_LightRigType_legacyFlat4: return "legacyFlat4"; + case NS_ooxml::LN_ST_LightRigType_legacyNormal1: return "legacyNormal1"; + case NS_ooxml::LN_ST_LightRigType_legacyNormal2: return "legacyNormal2"; + case NS_ooxml::LN_ST_LightRigType_legacyNormal3: return "legacyNormal3"; + case NS_ooxml::LN_ST_LightRigType_legacyNormal4: return "legacyNormal4"; + case NS_ooxml::LN_ST_LightRigType_legacyHarsh1: return "legacyHarsh1"; + case NS_ooxml::LN_ST_LightRigType_legacyHarsh2: return "legacyHarsh2"; + case NS_ooxml::LN_ST_LightRigType_legacyHarsh3: return "legacyHarsh3"; + case NS_ooxml::LN_ST_LightRigType_legacyHarsh4: return "legacyHarsh4"; + case NS_ooxml::LN_ST_LightRigType_threePt: return "threePt"; + case NS_ooxml::LN_ST_LightRigType_balanced: return "balanced"; + case NS_ooxml::LN_ST_LightRigType_soft: return "soft"; + case NS_ooxml::LN_ST_LightRigType_harsh: return "harsh"; + case NS_ooxml::LN_ST_LightRigType_flood: return "flood"; + case NS_ooxml::LN_ST_LightRigType_contrasting: return "contrasting"; + case NS_ooxml::LN_ST_LightRigType_morning: return "morning"; + case NS_ooxml::LN_ST_LightRigType_sunrise: return "sunrise"; + case NS_ooxml::LN_ST_LightRigType_sunset: return "sunset"; + case NS_ooxml::LN_ST_LightRigType_chilly: return "chilly"; + case NS_ooxml::LN_ST_LightRigType_freezing: return "freezing"; + case NS_ooxml::LN_ST_LightRigType_flat: return "flat"; + case NS_ooxml::LN_ST_LightRigType_twoPt: return "twoPt"; + case NS_ooxml::LN_ST_LightRigType_glow: return "glow"; + case NS_ooxml::LN_ST_LightRigType_brightRoom: return "brightRoom"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getLightRigDirectionString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_LightRigDirection_tl: return "tl"; + case NS_ooxml::LN_ST_LightRigDirection_t: return "t"; + case NS_ooxml::LN_ST_LightRigDirection_tr: return "tr"; + case NS_ooxml::LN_ST_LightRigDirection_l: return "l"; + case NS_ooxml::LN_ST_LightRigDirection_r: return "r"; + case NS_ooxml::LN_ST_LightRigDirection_bl: return "bl"; + case NS_ooxml::LN_ST_LightRigDirection_b: return "b"; + case NS_ooxml::LN_ST_LightRigDirection_br: return "br"; + + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getBevelPresetTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_BevelPresetType_relaxedInset: return "relaxedInset"; + case NS_ooxml::LN_ST_BevelPresetType_circle: return "circle"; + case NS_ooxml::LN_ST_BevelPresetType_slope: return "slope"; + case NS_ooxml::LN_ST_BevelPresetType_cross: return "cross"; + case NS_ooxml::LN_ST_BevelPresetType_angle: return "angle"; + case NS_ooxml::LN_ST_BevelPresetType_softRound: return "softRound"; + case NS_ooxml::LN_ST_BevelPresetType_convex: return "convex"; + case NS_ooxml::LN_ST_BevelPresetType_coolSlant: return "coolSlant"; + case NS_ooxml::LN_ST_BevelPresetType_divot: return "divot"; + case NS_ooxml::LN_ST_BevelPresetType_riblet: return "riblet"; + case NS_ooxml::LN_ST_BevelPresetType_hardEdge: return "hardEdge"; + case NS_ooxml::LN_ST_BevelPresetType_artDeco: return "artDeco"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getPresetMaterialTypeString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_PresetMaterialType_legacyMatte: return "legacyMatte"; + case NS_ooxml::LN_ST_PresetMaterialType_legacyPlastic: return "legacyPlastic"; + case NS_ooxml::LN_ST_PresetMaterialType_legacyMetal: return "legacyMetal"; + case NS_ooxml::LN_ST_PresetMaterialType_legacyWireframe: return "legacyWireframe"; + case NS_ooxml::LN_ST_PresetMaterialType_matte: return "matte"; + case NS_ooxml::LN_ST_PresetMaterialType_plastic: return "plastic"; + case NS_ooxml::LN_ST_PresetMaterialType_metal: return "metal"; + case NS_ooxml::LN_ST_PresetMaterialType_warmMatte: return "warmMatte"; + case NS_ooxml::LN_ST_PresetMaterialType_translucentPowder: return "translucentPowder"; + case NS_ooxml::LN_ST_PresetMaterialType_powder: return "powder"; + case NS_ooxml::LN_ST_PresetMaterialType_dkEdge: return "dkEdge"; + case NS_ooxml::LN_ST_PresetMaterialType_softEdge: return "softEdge"; + case NS_ooxml::LN_ST_PresetMaterialType_clear: return "clear"; + case NS_ooxml::LN_ST_PresetMaterialType_flat: return "flat"; + case NS_ooxml::LN_ST_PresetMaterialType_softmetal: return "softmetal"; + case NS_ooxml::LN_ST_PresetMaterialType_none: return "none"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getLigaturesString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_Ligatures_none: return "none"; + case NS_ooxml::LN_ST_Ligatures_standard: return "standard"; + case NS_ooxml::LN_ST_Ligatures_contextual: return "contextual"; + case NS_ooxml::LN_ST_Ligatures_historical: return "historical"; + case NS_ooxml::LN_ST_Ligatures_discretional: return "discretional"; + case NS_ooxml::LN_ST_Ligatures_standardContextual: return "standardContextual"; + case NS_ooxml::LN_ST_Ligatures_standardHistorical: return "standardHistorical"; + case NS_ooxml::LN_ST_Ligatures_contextualHistorical: return "contextualHistorical"; + case NS_ooxml::LN_ST_Ligatures_standardDiscretional: return "standardDiscretional"; + case NS_ooxml::LN_ST_Ligatures_contextualDiscretional: return "contextualDiscretional"; + case NS_ooxml::LN_ST_Ligatures_historicalDiscretional: return "historicalDiscretional"; + case NS_ooxml::LN_ST_Ligatures_standardContextualHistorical: return "standardContextualHistorical"; + case NS_ooxml::LN_ST_Ligatures_standardContextualDiscretional: return "standardContextualDiscretional"; + case NS_ooxml::LN_ST_Ligatures_standardHistoricalDiscretional: return "standardHistoricalDiscretional"; + case NS_ooxml::LN_ST_Ligatures_contextualHistoricalDiscretional: return "contextualHistoricalDiscretional"; + case NS_ooxml::LN_ST_Ligatures_all: return "all"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getNumFormString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_NumForm_default: return "default"; + case NS_ooxml::LN_ST_NumForm_lining: return "lining"; + case NS_ooxml::LN_ST_NumForm_oldStyle: return "oldStyle"; + default: break; + } + return OUString(); +} + +OUString TextEffectsHandler::getNumSpacingString(sal_Int32 nType) +{ + switch (nType) + { + case NS_ooxml::LN_ST_NumSpacing_default: return "default"; + case NS_ooxml::LN_ST_NumSpacing_proportional: return "proportional"; + case NS_ooxml::LN_ST_NumSpacing_tabular: return "tabular"; + default: break; + } + return OUString(); +} + +void TextEffectsHandler::convertElementIdToPropertyId(sal_Int32 aElementId) +{ + switch(aElementId) + { + case NS_ooxml::LN_glow_glow: + maPropertyId = PROP_CHAR_GLOW_TEXT_EFFECT; + maElementName = "glow"; + break; + case NS_ooxml::LN_shadow_shadow: + maPropertyId = PROP_CHAR_SHADOW_TEXT_EFFECT; + maElementName = "shadow"; + break; + case NS_ooxml::LN_reflection_reflection: + maPropertyId = PROP_CHAR_REFLECTION_TEXT_EFFECT; + maElementName = "reflection"; + break; + case NS_ooxml::LN_textOutline_textOutline: + maPropertyId = PROP_CHAR_TEXTOUTLINE_TEXT_EFFECT; + maElementName = "textOutline"; + break; + case NS_ooxml::LN_textFill_textFill: + maPropertyId = PROP_CHAR_TEXTFILL_TEXT_EFFECT; + maElementName = "textFill"; + break; + case NS_ooxml::LN_scene3d_scene3d: + maPropertyId = PROP_CHAR_SCENE3D_TEXT_EFFECT; + maElementName = "scene3d"; + break; + case NS_ooxml::LN_props3d_props3d: + maPropertyId = PROP_CHAR_PROPS3D_TEXT_EFFECT; + maElementName = "props3d"; + break; + case NS_ooxml::LN_ligatures_ligatures: + maPropertyId = PROP_CHAR_LIGATURES_TEXT_EFFECT; + maElementName = "ligatures"; + break; + case NS_ooxml::LN_numForm_numForm: + maPropertyId = PROP_CHAR_NUMFORM_TEXT_EFFECT; + maElementName = "numForm"; + break; + case NS_ooxml::LN_numSpacing_numSpacing: + maPropertyId = PROP_CHAR_NUMSPACING_TEXT_EFFECT; + maElementName = "numSpacing"; + break; + case NS_ooxml::LN_stylisticSets_stylisticSets: + maPropertyId = PROP_CHAR_STYLISTICSETS_TEXT_EFFECT; + maElementName = "stylisticSets"; + break; + case NS_ooxml::LN_cntxtAlts_cntxtAlts: + maPropertyId = PROP_CHAR_CNTXTALTS_TEXT_EFFECT; + maElementName = "cntxtAlts"; + break; + default: + break; + } +} + +TextEffectsHandler::TextEffectsHandler(sal_uInt32 aElementId) : + LoggedProperties("TextEffectsHandler") +{ + convertElementIdToPropertyId(aElementId); + mpGrabBagStack.reset(new oox::GrabBagStack(maElementName)); +} + +TextEffectsHandler::~TextEffectsHandler() +{ +} + + +void TextEffectsHandler::lcl_attribute(Id aName, Value& aValue) +{ + if (mpGrabBagStack->getCurrentName() != constAttributesSequenceName) + mpGrabBagStack->push(constAttributesSequenceName); + + switch(aName) + { + case NS_ooxml::LN_CT_Percentage_val: + case NS_ooxml::LN_CT_PositiveFixedPercentage_val: + case NS_ooxml::LN_CT_PositivePercentage_val: + mpGrabBagStack->addInt32("val", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Glow_rad: + mpGrabBagStack->addInt32("rad", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_SchemeColor_val: + { + OUString aString = getSchemeColorValTypeString(sal_Int32(aValue.getInt())); + mpGrabBagStack->addString("val", aString); + } + break; + case NS_ooxml::LN_CT_SRgbColor_val: + { + OUString aBuffer = OUString::number(aValue.getInt(), 16); + OUStringBuffer aString; + comphelper::string::padToLength(aString, 6 - aBuffer.getLength(), '0'); + aString.append(aBuffer.getStr()); + mpGrabBagStack->addString("val", aString.makeStringAndClear().toAsciiUpperCase()); + } + break; + case NS_ooxml::LN_CT_Shadow_blurRad: + case NS_ooxml::LN_CT_Reflection_blurRad: + mpGrabBagStack->addInt32("blurRad", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Reflection_stA: + mpGrabBagStack->addInt32("stA", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Reflection_stPos: + mpGrabBagStack->addInt32("stPos", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Reflection_endA: + mpGrabBagStack->addInt32("endA", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Reflection_endPos: + mpGrabBagStack->addInt32("endPos", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Shadow_dist: + case NS_ooxml::LN_CT_Reflection_dist: + mpGrabBagStack->addInt32("dist", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Shadow_dir: + case NS_ooxml::LN_CT_Reflection_dir: + mpGrabBagStack->addInt32("dir", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Reflection_fadeDir: + mpGrabBagStack->addInt32("fadeDir", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Shadow_sx: + case NS_ooxml::LN_CT_Reflection_sx: + mpGrabBagStack->addInt32("sx", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Shadow_sy: + case NS_ooxml::LN_CT_Reflection_sy: + mpGrabBagStack->addInt32("sy", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Shadow_kx: + case NS_ooxml::LN_CT_Reflection_kx: + mpGrabBagStack->addInt32("kx", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Shadow_ky: + case NS_ooxml::LN_CT_Reflection_ky: + mpGrabBagStack->addInt32("ky", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Shadow_algn: + case NS_ooxml::LN_CT_Reflection_algn: + { + uno::Any aAny = uno::makeAny(getRectAlignmentString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("algn", aAny); + } + break; + case NS_ooxml::LN_CT_TextOutlineEffect_w: + mpGrabBagStack->addInt32("w", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_TextOutlineEffect_cap: + { + uno::Any aAny = uno::makeAny(getLineCapString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("cap", aAny); + } + break; + case NS_ooxml::LN_CT_TextOutlineEffect_cmpd: + { + uno::Any aAny = uno::makeAny(getCompoundLineString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("cmpd", aAny); + } + break; + case NS_ooxml::LN_CT_TextOutlineEffect_algn: + { + uno::Any aAny = uno::makeAny(getPenAlignmentString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("algn", aAny); + } + break; + case NS_ooxml::LN_CT_GradientStop_pos: + mpGrabBagStack->addInt32("pos", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_LinearShadeProperties_ang: + mpGrabBagStack->addInt32("ang", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_LinearShadeProperties_scaled: + { + uno::Any aAny = uno::makeAny(getOnOffString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("scaled", aAny); + } + break; + case NS_ooxml::LN_CT_PathShadeProperties_path: + { + uno::Any aAny = uno::makeAny(getPathShadeTypeString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("path", aAny); + } + break; + case NS_ooxml::LN_CT_RelativeRect_l: + mpGrabBagStack->addInt32("l", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_RelativeRect_t: + mpGrabBagStack->addInt32("t", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_RelativeRect_r: + mpGrabBagStack->addInt32("r", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_RelativeRect_b: + mpGrabBagStack->addInt32("b", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_PresetLineDashProperties_val: + { + uno::Any aAny = uno::makeAny(getPresetLineDashValString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("val", aAny); + } + break; + case NS_ooxml::LN_CT_LineJoinMiterProperties_lim: + mpGrabBagStack->addInt32("lim", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Camera_prst: + { + uno::Any aAny = uno::makeAny(getPresetCameraTypeString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("prst", aAny); + } + break; + case NS_ooxml::LN_CT_LightRig_rig: + { + uno::Any aAny = uno::makeAny(getLightRigTypeString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("rig", aAny); + } + break; + case NS_ooxml::LN_CT_LightRig_dir: + { + uno::Any aAny = uno::makeAny(getLightRigDirectionString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("dir", aAny); + } + break; + case NS_ooxml::LN_CT_SphereCoords_lat: + mpGrabBagStack->addInt32("lat", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_SphereCoords_lon: + mpGrabBagStack->addInt32("lon", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_SphereCoords_rev: + mpGrabBagStack->addInt32("rev", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Props3D_extrusionH: + mpGrabBagStack->addInt32("extrusionH", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Props3D_contourW: + mpGrabBagStack->addInt32("contourW", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Props3D_prstMaterial: + { + uno::Any aAny = uno::makeAny(getPresetMaterialTypeString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("prstMaterial", aAny); + } + break; + case NS_ooxml::LN_CT_Bevel_w: + mpGrabBagStack->addInt32("w", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Bevel_h: + mpGrabBagStack->addInt32("h", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_Bevel_prst: + { + uno::Any aAny = uno::makeAny(getBevelPresetTypeString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("prst", aAny); + } + break; + case NS_ooxml::LN_CT_Ligatures_val: + { + uno::Any aAny = uno::makeAny(getLigaturesString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("val", aAny); + } + break; + case NS_ooxml::LN_CT_NumForm_val: + { + uno::Any aAny = uno::makeAny(getNumFormString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("val", aAny); + } + break; + case NS_ooxml::LN_CT_NumSpacing_val: + { + uno::Any aAny = uno::makeAny(getNumSpacingString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("val", aAny); + } + break; + case NS_ooxml::LN_CT_StyleSet_id: + mpGrabBagStack->addInt32("id", sal_Int32(aValue.getInt())); + break; + case NS_ooxml::LN_CT_StyleSet_val: + case NS_ooxml::LN_CT_OnOff_val: + { + uno::Any aAny = uno::makeAny(getOnOffString(sal_Int32(aValue.getInt()))); + mpGrabBagStack->appendElement("val", aAny); + } + break; + default: + break; + } +} + +void TextEffectsHandler::lcl_sprm(Sprm& rSprm) +{ + if (mpGrabBagStack->getCurrentName() == constAttributesSequenceName) + mpGrabBagStack->pop(); + + sal_uInt32 nSprmId = rSprm.getId(); + OUString aElementName = lclGetNameForElementId(nSprmId); + if(aElementName.isEmpty()) + { + // Element is unknown -> leave. + return; + } + + mpGrabBagStack->push(aElementName); + + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( !pProperties ) + return; + + pProperties->resolve( *this ); + + if (mpGrabBagStack->getCurrentName() == constAttributesSequenceName) + mpGrabBagStack->pop(); + + mpGrabBagStack->pop(); +} + +beans::PropertyValue TextEffectsHandler::getInteropGrabBag() +{ + beans::PropertyValue aReturn = mpGrabBagStack->getRootProperty(); + mpGrabBagStack.reset(); + return aReturn; +} + +sal_uInt8 TextEffectsHandler::GetTextFillSolidFillAlpha(const css::beans::PropertyValue& rValue) +{ + if (rValue.Name != "textFill") + { + return 0; + } + + uno::Sequence aPropertyValues; + rValue.Value >>= aPropertyValues; + comphelper::SequenceAsHashMap aMap(aPropertyValues); + auto it = aMap.find("solidFill"); + if (it == aMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aSolidFillMap(it->second); + it = aSolidFillMap.find("srgbClr"); + if (it == aSolidFillMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aSrgbClrMap(it->second); + it = aSrgbClrMap.find("alpha"); + if (it == aSrgbClrMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aAlphaMap(it->second); + it = aAlphaMap.find("attributes"); + if (it == aAlphaMap.end()) + { + return 0; + } + + comphelper::SequenceAsHashMap aAttributesMap(it->second); + it = aAttributesMap.find("val"); + if (it == aAttributesMap.end()) + { + return 0; + } + sal_Int32 nVal = 0; + it->second >>= nVal; + return nVal / oox::drawingml::PER_PERCENT; +} + +} // namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TextEffectsHandler.hxx b/writerfilter/source/dmapper/TextEffectsHandler.hxx new file mode 100644 index 000000000..60e98d64b --- /dev/null +++ b/writerfilter/source/dmapper/TextEffectsHandler.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TEXTEFFECTSHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TEXTEFFECTSHANDLER_HXX + +#include "LoggedResources.hxx" + +#include + +#include "PropertyIds.hxx" + +#include + +#include +#include + +namespace writerfilter { +namespace dmapper +{ + +/// Class to process all text effects like glow, textOutline, ... +class TextEffectsHandler : public LoggedProperties +{ +private: + std::optional maPropertyId; + OUString maElementName; + std::unique_ptr mpGrabBagStack; + + void convertElementIdToPropertyId(sal_Int32 aElementId); + + // LoggedProperties + virtual void lcl_attribute(Id aName, Value& aValue) override; + virtual void lcl_sprm(Sprm& sprm) override; + +public: + explicit TextEffectsHandler(sal_uInt32 aElementId); + virtual ~TextEffectsHandler() override; + + const std::optional& getGrabBagPropertyId() const { return maPropertyId;} + + css::beans::PropertyValue getInteropGrabBag(); + + static OUString getSchemeColorValTypeString(sal_Int32 nType); + static OUString getRectAlignmentString(sal_Int32 nType); + static OUString getLineCapString(sal_Int32 nType); + static OUString getCompoundLineString(sal_Int32 nType); + static OUString getPenAlignmentString(sal_Int32 nType); + static OUString getOnOffString(sal_Int32 nType); + static OUString getPathShadeTypeString(sal_Int32 nType); + static OUString getPresetLineDashValString(sal_Int32 nType); + static OUString getPresetCameraTypeString(sal_Int32 nType); + static OUString getLightRigTypeString(sal_Int32 nType); + static OUString getLightRigDirectionString(sal_Int32 nType); + static OUString getBevelPresetTypeString(sal_Int32 nType); + static OUString getPresetMaterialTypeString(sal_Int32 nType); + static OUString getLigaturesString(sal_Int32 nType); + static OUString getNumFormString(sal_Int32 nType); + static OUString getNumSpacingString(sal_Int32 nType); + + static sal_uInt8 GetTextFillSolidFillAlpha(const css::beans::PropertyValue& rValue); + +}; + +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TEXTEFFECTSHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/ThemeTable.cxx b/writerfilter/source/dmapper/ThemeTable.cxx new file mode 100644 index 000000000..ffa2262cd --- /dev/null +++ b/writerfilter/source/dmapper/ThemeTable.cxx @@ -0,0 +1,564 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "TagLogger.hxx" +#include "ThemeTable.hxx" +#include +#include + +#include + +using namespace com::sun::star; + +namespace writerfilter::dmapper +{ + +struct ThemeTable_Impl +{ + ThemeTable_Impl() : + m_currentThemeFontId(0), + m_currentFontThemeEntry(), + m_supplementalFontId(0) + {} + std::map > m_themeFontMap; + sal_uInt32 m_currentThemeFontId; + std::map m_currentFontThemeEntry; + OUString m_supplementalFontName; + sal_uInt32 m_supplementalFontId; + OUString m_themeFontLangEastAsia; + OUString m_themeFontLangBidi; +}; + +ThemeTable::ThemeTable() +: LoggedProperties("ThemeTable") +, LoggedTable("ThemeTable") +, m_pImpl( new ThemeTable_Impl ) +{ + +} + +ThemeTable::~ThemeTable() +{ +} + +void ThemeTable::lcl_attribute(Id Name, Value & val) +{ + OUString sValue = val.getString(); + switch(Name) + { + case NS_ooxml::LN_CT_TextFont_typeface: + if (!sValue.isEmpty()) + m_pImpl->m_currentFontThemeEntry[m_pImpl->m_currentThemeFontId] = sValue; + break; + case NS_ooxml::LN_CT_SupplementalFont_script: + if (!sValue.isEmpty()) + { + if (sValue == m_pImpl->m_themeFontLangBidi) + m_pImpl->m_supplementalFontId = NS_ooxml::LN_CT_FontCollection_cs; + else if (sValue == m_pImpl->m_themeFontLangEastAsia) + m_pImpl->m_supplementalFontId = NS_ooxml::LN_CT_FontCollection_ea; + } + break; + case NS_ooxml::LN_CT_SupplementalFont_typeface: + if (!sValue.isEmpty()) + m_pImpl->m_supplementalFontName = sValue; + break; + default: + { +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + } + } + if(m_pImpl->m_supplementalFontId && m_pImpl->m_supplementalFontName.getLength() > 0) + { + m_pImpl->m_currentFontThemeEntry[m_pImpl->m_supplementalFontId] = m_pImpl->m_supplementalFontName; + m_pImpl->m_supplementalFontName.clear(); + m_pImpl->m_supplementalFontId = 0; + } +} + +void ThemeTable::lcl_sprm(Sprm& rSprm) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("ThemeTable.sprm"); + TagLogger::getInstance().chars(rSprm.toString()); +#endif + + m_pImpl->m_supplementalFontName.clear(); + m_pImpl->m_supplementalFontId = 0; + + sal_uInt32 nSprmId = rSprm.getId(); + switch(nSprmId) + { + case NS_ooxml::LN_CT_BaseStyles_fontScheme: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_FontScheme_majorFont: + case NS_ooxml::LN_CT_FontScheme_minorFont: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + m_pImpl->m_currentFontThemeEntry = std::map(); + if( pProperties ) + pProperties->resolve(*this); + m_pImpl->m_themeFontMap[nSprmId] = m_pImpl->m_currentFontThemeEntry; + } + break; + case NS_ooxml::LN_CT_FontCollection_latin: + case NS_ooxml::LN_CT_FontCollection_ea: + case NS_ooxml::LN_CT_FontCollection_cs: + { + m_pImpl->m_currentThemeFontId = nSprmId; + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties ) + pProperties->resolve(*this); + } + break; + case NS_ooxml::LN_CT_FontCollection_font: + { + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if (pProperties ) + pProperties->resolve(*this); + } + break; + default: + { +#ifdef DBG_UTIL + TagLogger::getInstance().element("unhandled"); +#endif + } + } +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +void ThemeTable::lcl_entry(writerfilter::Reference::Pointer_t ref) +{ +#ifdef DBG_UTIL + TagLogger::getInstance().startElement("ThemeTable.entry"); +#endif + + ref->resolve(*this); + +#ifdef DBG_UTIL + TagLogger::getInstance().endElement(); +#endif +} + +OUString ThemeTable::getStringForTheme(const Id id) +{ + switch (id) + { + case NS_ooxml::LN_Value_ST_Theme_majorEastAsia: + return "majorEastAsia"; + case NS_ooxml::LN_Value_ST_Theme_majorBidi: + return "majorBidi"; + case NS_ooxml::LN_Value_ST_Theme_majorAscii: + return "majorAscii"; + case NS_ooxml::LN_Value_ST_Theme_majorHAnsi: + return "majorHAnsi"; + case NS_ooxml::LN_Value_ST_Theme_minorEastAsia: + return "minorEastAsia"; + case NS_ooxml::LN_Value_ST_Theme_minorBidi: + return "minorBidi"; + case NS_ooxml::LN_Value_ST_Theme_minorAscii: + return "minorAscii"; + case NS_ooxml::LN_Value_ST_Theme_minorHAnsi: + return "minorHAnsi"; + } + return OUString(); +} +OUString ThemeTable::getFontNameForTheme(const Id id) const +{ + std::map tmpThemeFontMap; + switch (id) + { + case NS_ooxml::LN_Value_ST_Theme_majorEastAsia: + case NS_ooxml::LN_Value_ST_Theme_majorBidi: + case NS_ooxml::LN_Value_ST_Theme_majorAscii: + case NS_ooxml::LN_Value_ST_Theme_majorHAnsi: + tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_majorFont]; + break; + case NS_ooxml::LN_Value_ST_Theme_minorEastAsia: + case NS_ooxml::LN_Value_ST_Theme_minorBidi: + case NS_ooxml::LN_Value_ST_Theme_minorAscii: + case NS_ooxml::LN_Value_ST_Theme_minorHAnsi: + tmpThemeFontMap = m_pImpl->m_themeFontMap[NS_ooxml::LN_CT_FontScheme_minorFont]; + break; + default: + return OUString(); + } + + switch (id) + { + case NS_ooxml::LN_Value_ST_Theme_majorAscii: + case NS_ooxml::LN_Value_ST_Theme_majorHAnsi: + case NS_ooxml::LN_Value_ST_Theme_minorAscii: + case NS_ooxml::LN_Value_ST_Theme_minorHAnsi: + { + std::map::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_latin); + if (Iter != tmpThemeFontMap.end()) + return Iter->second; + return OUString(); + } + case NS_ooxml::LN_Value_ST_Theme_majorBidi: + case NS_ooxml::LN_Value_ST_Theme_minorBidi: + { + std::map::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_cs); + if (Iter != tmpThemeFontMap.end()) + return Iter->second; + return OUString(); + } + case NS_ooxml::LN_Value_ST_Theme_majorEastAsia: + case NS_ooxml::LN_Value_ST_Theme_minorEastAsia: + { + std::map::const_iterator Iter = tmpThemeFontMap.find(NS_ooxml::LN_CT_FontCollection_ea); + if (Iter != tmpThemeFontMap.end()) + return Iter->second; + return OUString(); + } + default: + return OUString(); + } +} + +void ThemeTable::setThemeFontLangProperties(const uno::Sequence& aPropSeq) +{ + for (const auto& rProp : aPropSeq) + { + OUString sLocaleName; + rProp.Value >>= sLocaleName; + if (rProp.Name == "eastAsia") + m_pImpl->m_themeFontLangEastAsia = fromLocaleToScriptTag(sLocaleName); + if (rProp.Name == "bidi") + m_pImpl->m_themeFontLangBidi = fromLocaleToScriptTag(sLocaleName); + + } +} + +OUString ThemeTable::fromLocaleToScriptTag(const OUString& sLocale) +{ + return fromLCIDToScriptTag(LanguageTag::convertToLanguageType(sLocale)); +} + +OUString ThemeTable::fromLCIDToScriptTag(LanguageType lang) +{ + // conversion list from: + // http://blogs.msdn.com/b/officeinteroperability/archive/2013/04/22/office-open-xml-themes-schemes-and-fonts.aspx + switch (static_cast(lang)) + { + case 0x429 : // lidFarsi + case 0x401 : // lidArabic + case 0x801 : // lidIraq + case 0xc01 : // lidEgyptian + case 0x1001 : // lidLibya + case 0x1401 : // lidAlgerian + case 0x1801 : // lidMorocco + case 0x1c01 : // lidTunisia + case 0x2001 : // lidOman + case 0x2401 : // lidYemen + case 0x2801 : // lidSyria + case 0x2c01 : // lidJordan + case 0x3001 : // lidLebanon + case 0x3401 : // lidKuwait + case 0x3801 : // lidUAE + case 0x3c01 : // lidBahrain + case 0x4001 : // lidQatar + case 0x420 : // lidUrdu + case 0x846 : // lidPunjabiPakistan + case 0x859 : // lidSindhiPakistan + case 0x45f : // lidTamazight + case 0x460 : // lidKashmiri + case 0x463 : // lidPashto + case 0x48c : // lidDari + return "Arab"; + case 0x42b : // lidArmenian + return "Armn"; + case 0x445 : // lidBengali + case 0x845 : // lidBengaliBangladesh + case 0x44d : // lidAssamese + case 0x458 : // lidManipuri + return "Beng"; + case 0x45d : // lidInuktitut + return "Cans"; + case 0x45c : // lidCherokee + return "Cher"; + case 0x419 : // lidRussian + case 0x402 : // lidBulgarian + case 0x281a : // lidSerbianCyrillic + case 0x422 : // lidUkranian + case 0x819 : // lidRussianMoldavia + case 0xc1a : // lidSerbianCyrillicSerbMont + case 0x1c1a : // lidSerbianBosniaHerzegovinaCyrillic + case 0x201a : // lidBosnianBosniaHerzegovinaCyrillic + case 0x301a : // lidSerbianMontenegroCyrillic + case 0x423 : // lidByelorussian + case 0x428 : // lidTajik + case 0x82c : // lidAzeriCyrillic + case 0x42f : // lidMacedonian + case 0x43f : // lidKazakh + case 0x440 : // lidKyrgyz + case 0x843 : // lidUzbekCyrillic + case 0x444 : // lidTatar + case 0x450 : // lidMongolian + case 0x46d : // lidBashkir + case 0x485 : // lidSakha + return "Cyrl"; + case 0x439 : // lidHindi + case 0x44e : // lidMarathi + case 0x44f : // lidSanskrit + case 0x457 : // lidKonkani + case 0x459 : // lidSindhi + case 0x860 : // lidKashmiriIndia + case 0x461 : // lidNepali + case 0x861 : // lidNepaliIndia + return "Deva"; + case 0x45e : // lidAmharic + case 0x473 : // lidTigrignaEthiopic + case 0x873 : // lidTigrignaEritrea + return "Ethi"; + case 0x437 : // lidGeorgian + return "Geor"; + case 0x408 : // lidGreek + return "Grek"; + case 0x447 : // lidGujarati + return "Gujr"; + case 0x446 : // lidPunjabi + return "Guru"; + case 0x412 : // lidKoreanExtWansung + return "Hang"; + case 0x804 : // lidChineseSimp + case 0x1004 : // lidSingapore + return "Hans"; + case 0x404 : // lidChineseTrad + case 0xc04 : // lidHongkong + case 0x1404 : // lidMacau + return "Hant"; + case 0x40d : // lidHebrew + case 0x43d : // lidYiddish + return "Hebr"; + case 0x411 : // lidJapanese + return "Jpan"; + case 0x453 : // lidKhmer + return "Khmr"; + case 0x44b : // lidKannada + return "Knda"; + case 0x454 : // lidLao + return "Laoo"; + case 0x409 : // lidAmerican + case 0xc09 : // lidAustralian + case 0x809 : // lidBritish + case 0x1009 : // lidEnglishCanadian + case 0x403 : // lidCatalan + case 0x406 : // lidDanish + case 0x413 : // lidDutch + case 0x813 : // lidDutchBelgian + case 0x479 : // lidPapiamentu + case 0x40b : // lidFinnish + case 0x40c : // lidFrench + case 0xc0c : // lidFrenchCanadian + case 0x407 : // lidGerman + case 0x807 : // lidSwissGerman + case 0xc07 : // lidAustrianGerman + case 0x1007 : // lidGermanLuxembourg + case 0x1407 : // lidGermanLiechtenstein + case 0x410 : // lidItalian + case 0x414 : // lidNorskBokmal + case 0x814 : // lidNorskNynorsk + case 0x416 : // lidPortBrazil + case 0x816 : // lidPortIberian + case 0x40a : // lidSpanish + case 0x41d : // lidSwedish + case 0x405 : // lidCzech + case 0x40e : // lidHungarian + case 0x415 : // lidPolish + case 0x41f : // lidTurkish + case 0x42d : // lidBasque + case 0x424 : // lidSlovenian + case 0x426 : // lidLatvian + case 0x427 : // lidLithuanian + case 0x418 : // lidRomanian + case 0x818 : // lidRomanianMoldavia + case 0x241a : // lidSerbianLatin + case 0x41a : // lidCroatian, lidCroat + case 0x491 : // lidGaelicScots + case 0x83c : // lidGaelicIrish + case 0x430 : // lidSutu + case 0x431 : // lidTsonga + case 0x432 : // lidTswana + case 0x433 : // lidVenda + case 0x434 : // lidXhosa + case 0x435 : // lidZulu + case 0x436 : // lidAfrikaans + case 0x425 : // lidEstonian + case 0x456 : // lidGalician + case 0x41b : // lidSlovak + case 0x1409 : // lidEnglishNewZealand + case 0x1809 : // lidEnglishIreland + case 0x1c09 : // lidEnglishSouthAfrica + case 0x2009 : // lidEnglishJamaica + case 0x2409 : // lidEnglishCaribbean + case 0x2809 : // lidEnglishBelize + case 0x2c09 : // lidEnglishTrinidad + case 0x3009 : // lidEnglishZimbabwe + case 0x3409 : // lidEnglishPhilippines + case 0x3809 : // lidEnglishIndonesia + case 0x3c09 : // lidEnglishHongKong + case 0x4009 : // lidEnglishIndia + case 0x4409 : // lidEnglishMalaysia + case 0x4809 : // lidEnglishSingapore + case 0x80a : // lidSpanishMexican, lidMexican + case 0xc0a : // lidSpanishModern + case 0x100a : // lidGuatemala + case 0x140a : // lidCostaRica + case 0x180a : // lidPanama + case 0x1c0a : // lidDominicanRepublic + case 0x200a : // lidSpanishSA, lidVenezuela + case 0x240a : // lidColombia + case 0x280a : // lidPeru + case 0x2c0a : // lidArgentina + case 0x300a : // lidEcuador + case 0x340a : // lidChile + case 0x380a : // lidUruguay + case 0x3c0a : // lidParguay + case 0x400a : // lidBolivia + case 0x440a : // lidElSalvador + case 0x480a : // lidHonduras + case 0x4c0a : // lidNicaragua + case 0x500a : // lidPuertoRico + case 0x540a : // lidSpanishUS + case 0x80c : // lidFrenchBelgian + case 0x100c : // lidFrenchSwiss + case 0x140c : // lidFrenchLuxembourg + case 0x180c : // lidFrenchMonaco + case 0x1c0c : // lidFrenchWestIndies + case 0x200c : // lidFrenchReunion + case 0x240c : // lidFrenchCongoDRC, lidFrenchZaire + case 0x280c : // lidFrenchSenegal + case 0x2c0c : // lidFrenchCameroon + case 0x300c : // lidFrenchCotedIvoire + case 0x340c : // lidFrenchMali + case 0x3c0c : // lidFrenchHaiti + case 0x380c : // lidFrenchMorocco + case 0x40f : // lidIcelandic + case 0x810 : // lidItalianSwiss + case 0x417 : // lidRhaetoRomanic, lidRomanic + case 0x81a : // lidSerbianLatinSerbMont, lidCroatSerbo + case 0x101a : // lidBosniaHerzegovina + case 0x141a : // lidBosnianBosniaHerzegovinaLatin + case 0x181a : // lidSerbianBosniaHerzegovinaLatin + case 0x2c1a : // lidSerbianMontenegroLatin + case 0x41c : // lidAlbanian + case 0x81d : // lidSwedishFinland + case 0x421 : // lidBahasa, lidIndonesian + case 0x42c : // lidAzeriLatin + case 0x42e : // lidSorbian + case 0x82e : // lidLowerSorbian + case 0x438 : // lidFaeroese + case 0x43a : // lidMaltese + case 0x43b : // lidSamiLappish + case 0x83b : // lidNorthSamiSwe + case 0xc3b : // lidNorthernSamiFi + case 0x103b : // lidLuleSamiNor + case 0x143b : // lidLuleSamiSwe + case 0x183b : // lidSouthSamiNor + case 0x1c3b : // lidSouthSamiSwe + case 0x203b : // lidSkoltSami + case 0x243b : // lidInariSami + case 0x43e : // lidMalaysian + case 0x83e : // lidMalayBrunei + case 0x441 : // lidSwahili + case 0x442 : // lidTurkmen + case 0x443 : // lidUzbekLatin + case 0x452 : // lidWelsh + case 0x85d : // lidInuktitutLatin + case 0x85f : // lidTamazightLatin + case 0x462 : // lidFrisian + case 0x464 : // lidFilipino + case 0x466 : // lidEdo + case 0x467 : // lidFulfulde + case 0x468 : // lidHausa + case 0x469 : // lidIbibio + case 0x46a : // lidYoruba + case 0x46b : // lidQuechuaBol + case 0x86b : // lidQuechuaEcu + case 0xc6b : // lidQuechuaPe + case 0x46c : // lidSesothoSaLeboa + case 0x46e : // lidLuxembourgish + case 0x46f : // lidGreenlandic + case 0x470 : // lidIgbo + case 0x471 : // lidKanuri + case 0x472 : // lidOromo + case 0x474 : // lidGuarani + case 0x475 : // lidHawaiian + case 0x476 : // lidLatin + case 0x477 : // lidSomali + case 0x47a : // lidMapudungun + case 0x47c : // lidMohawk + case 0x47e : // lidBreton + case 0x481 : // lidMaori + case 0x482 : // lidOccitan + case 0x483 : // lidCorsican + case 0x484 : // lidAlsatian + case 0x486 : // lidKiche + case 0x487 : // lidKinyarwanda + case 0x488 : // lidWolof + return "Latn"; + case 0x44c : // lidMalayalam + return "Mlym"; + case 0x850 : // lidMongolianMongo + return "Mong"; + case 0x455 : // lidBurmese + return "Mymr"; + case 0x448 : // lidOriya + return "Orya"; + case 0x45b : // lidSinhalese + return "Sinh"; + case 0x45a : // lidSyriac + return "Syrc"; + case 0x449 : // lidTamil + return "Taml"; + case 0x44a : // lidTelugu + return "Telu"; + case 0x465 : // lidMaldivian + return "Thaa"; + case 0x41e : // lidThai + return "Thai"; + case 0x451 : // lidTibetan + case 0x851 : // lidBhutanese + return "Tibt"; + case 0x480 : // lidUighur + return "Uigh"; + case 0x42a : // lidVietnamese + return "Viet"; + case 0x478 : // lidYi + return "Yiii"; + default: + return OUString(); + } +} + +} //namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/ThemeTable.hxx b/writerfilter/source/dmapper/ThemeTable.hxx new file mode 100644 index 000000000..c72c53c9a --- /dev/null +++ b/writerfilter/source/dmapper/ThemeTable.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_THEMETABLE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_THEMETABLE_HXX + +#include "LoggedResources.hxx" +#include +#include +#include + +namespace writerfilter { +namespace dmapper +{ + +struct ThemeTable_Impl; + +class ThemeTable : public LoggedProperties, public LoggedTable +{ + std::unique_ptr m_pImpl; + +public: + ThemeTable(); + virtual ~ThemeTable() override; + + OUString getFontNameForTheme(const Id id) const; + static OUString getStringForTheme(const Id id); + void setThemeFontLangProperties(const css::uno::Sequence& aPropSeq); + + private: + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + + // Table + virtual void lcl_entry(writerfilter::Reference::Pointer_t ref) override; + + // Helper methods + static OUString fromLocaleToScriptTag(const OUString& sLocale); + static OUString fromLCIDToScriptTag(LanguageType lang); +}; +typedef tools::SvRef< ThemeTable > ThemeTablePtr; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TrackChangesHandler.cxx b/writerfilter/source/dmapper/TrackChangesHandler.cxx new file mode 100644 index 000000000..212f88261 --- /dev/null +++ b/writerfilter/source/dmapper/TrackChangesHandler.cxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#include "TrackChangesHandler.hxx" +#include "PropertyMap.hxx" +#include "ConversionHelper.hxx" +#include +#include +#include + +namespace writerfilter::dmapper { + +using namespace ::com::sun::star; +using namespace oox; + + +TrackChangesHandler::TrackChangesHandler( sal_Int32 nToken ) : + LoggedProperties("TrackChangesHandler"), + m_pRedlineParams(new RedlineParams) +{ + m_pRedlineParams->m_nToken = nToken; +} + + +TrackChangesHandler::~TrackChangesHandler() +{ +} + + +void TrackChangesHandler::lcl_attribute(Id rName, Value & rVal) +{ + OUString sStringValue = rVal.getString(); + switch( rName ) + { + case NS_ooxml::LN_CT_TrackChange_author: + { + m_pRedlineParams->m_sAuthor = sStringValue; + } + break; + case NS_ooxml::LN_CT_TrackChange_date: + { + m_pRedlineParams->m_sDate = sStringValue; + } + break; + case NS_ooxml::LN_CT_Markup_id: + break; + default: + OSL_FAIL( "unknown attribute"); + } +} + +uno::Sequence TrackChangesHandler::getRedlineProperties() const +{ + uno::Sequence< beans::PropertyValue > aRedlineProperties(3); + beans::PropertyValue* pRedlineProperties = aRedlineProperties.getArray(); + + OUString sType; + switch ( m_pRedlineParams->m_nToken & 0xffff ) + { + case XML_tableRowInsert: + sType = getPropertyName( PROP_TABLE_ROW_INSERT ); + break; + case XML_tableRowDelete: + sType = getPropertyName( PROP_TABLE_ROW_DELETE ); + break; + case XML_tableCellInsert: + sType = getPropertyName( PROP_TABLE_CELL_INSERT ); + break; + case XML_tableCellDelete: + sType = getPropertyName( PROP_TABLE_CELL_DELETE ); + break; + } + + pRedlineProperties[0].Name = getPropertyName( PROP_REDLINE_TYPE ); + pRedlineProperties[0].Value <<= sType; + pRedlineProperties[1].Name = getPropertyName( PROP_REDLINE_AUTHOR ); + pRedlineProperties[1].Value <<= m_pRedlineParams->m_sAuthor; + pRedlineProperties[2].Name = getPropertyName( PROP_REDLINE_DATE_TIME ); + pRedlineProperties[2].Value <<= ConversionHelper::ConvertDateStringToDateTime( m_pRedlineParams->m_sDate ); + //pRedlineProperties[3].Name = getPropertyName( PROP_REDLINE_REVERT_PROPERTIES ); + //pRedlineProperties[3].Value <<= pRedline->m_aRevertProperties; + + return aRedlineProperties; +} + +void TrackChangesHandler::lcl_sprm(Sprm &) {} + +} //namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/TrackChangesHandler.hxx b/writerfilter/source/dmapper/TrackChangesHandler.hxx new file mode 100644 index 000000000..e57a1ac65 --- /dev/null +++ b/writerfilter/source/dmapper/TrackChangesHandler.hxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TRACKCHANGESHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_TRACKCHANGESHANDLER_HXX + +#include "LoggedResources.hxx" +#include +#include + +namespace writerfilter { +namespace dmapper +{ +/** Handler for sprms that contain 'track changes' attributes + - Author + - Date + - ID + (This class is based on work done in 'MeasureHandler') + */ +class TrackChangesHandler : public LoggedProperties +{ + RedlineParamsPtr m_pRedlineParams; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +public: + explicit TrackChangesHandler( sal_Int32 nToken ); + virtual ~TrackChangesHandler() override; + + /// Compute the UNO properties for the track changes object based on the received tokens. + css::uno::Sequence getRedlineProperties() const; +}; +}} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.cxx b/writerfilter/source/dmapper/WrapPolygonHandler.cxx new file mode 100644 index 000000000..0eec61089 --- /dev/null +++ b/writerfilter/source/dmapper/WrapPolygonHandler.cxx @@ -0,0 +1,217 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include + +#include + +#include "WrapPolygonHandler.hxx" +#include "util.hxx" + +#include + +namespace writerfilter { + +using namespace com::sun::star; + +namespace dmapper { + +WrapPolygon::WrapPolygon() +{ +} + +WrapPolygon::~WrapPolygon() +{ +} + +void WrapPolygon::addPoint(const awt::Point & rPoint) +{ + mPoints.push_back(rPoint); +} + +WrapPolygon::Points_t::iterator WrapPolygon::begin() +{ + return mPoints.begin(); +} + +WrapPolygon::Points_t::iterator WrapPolygon::end() +{ + return mPoints.end(); +} + +WrapPolygon::Pointer_t WrapPolygon::move(const awt::Point & rPoint) +{ + WrapPolygon::Pointer_t pResult(new WrapPolygon); + + Points_t::iterator aIt = begin(); + Points_t::iterator aItEnd = end(); + + while (aIt != aItEnd) + { + awt::Point aPoint(aIt->X + rPoint.X, aIt->Y + rPoint.Y); + pResult->addPoint(aPoint); + ++aIt; + } + + return pResult; +} + +WrapPolygon::Pointer_t WrapPolygon::scale(const Fraction & rFractionX, const Fraction & rFractionY) +{ + WrapPolygon::Pointer_t pResult(new WrapPolygon); + + Points_t::iterator aIt = begin(); + Points_t::iterator aItEnd = end(); + + while (aIt != aItEnd) + { + awt::Point aPoint((Fraction(long(aIt->X)) * rFractionX).operator long(), (Fraction(long(aIt->Y)) * rFractionY).operator long()); + pResult->addPoint(aPoint); + ++aIt; + } + + return pResult; +} + +WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSrcSize) +{ + WrapPolygon::Pointer_t pResult; + + const long nWrap100Percent = 21600; + + Fraction aMove(nWrap100Percent, rSrcSize.Width); + aMove = aMove * Fraction(convertTwipToMm100(15), 1); + awt::Point aMovePoint(aMove.operator long(), 0); + pResult = move(aMovePoint); + + Fraction aScaleX = nWrap100Percent / (nWrap100Percent + aMove); + Fraction aScaleY = nWrap100Percent / (nWrap100Percent - aMove); + pResult = pResult->scale(aScaleX, aScaleY); + + Fraction aScaleSrcX(rSrcSize.Width, nWrap100Percent); + Fraction aScaleSrcY(rSrcSize.Height, nWrap100Percent); + pResult = pResult->scale(aScaleSrcX, aScaleSrcY); + + return pResult; +} + +WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygonPixel(const awt::Size & rSrcSize) +{ + WrapPolygon::Pointer_t pResult; + + /* + * https://msdn.microsoft.com/en-us/library/ee342530.aspx + * + * Image wrapping polygons in Microsoft Word use a fixed coordinate space + * that is 21600 units x 21600 units. Coordinate (0,0) is the upper left + * corner of the image and coordinate (21600,21600) is the lower right + * corner of the image. Microsoft Word scales the size of the wrapping + * polygon units to fit the size of the image. The 21600 value is a legacy + * artifact from the drawing layer of early versions of Microsoft Office. + */ + const long nWrap100Percent = 21600; + + Fraction aScaleX(rSrcSize.Width, nWrap100Percent); + Fraction aScaleY(rSrcSize.Height, nWrap100Percent); + pResult = scale(aScaleX, aScaleY); + + return pResult; +} + +WrapPolygon::Pointer_t WrapPolygon::correctCrop(const awt::Size& rGraphicSize, + const text::GraphicCrop& rGraphicCrop) +{ + WrapPolygon::Pointer_t pResult; + + Fraction aScaleX(rGraphicSize.Width - rGraphicCrop.Left - rGraphicCrop.Right, + rGraphicSize.Width); + Fraction aScaleY(rGraphicSize.Height - rGraphicCrop.Top - rGraphicCrop.Bottom, + rGraphicSize.Height); + pResult = scale(aScaleX, aScaleY); + + awt::Point aMove(rGraphicCrop.Left, rGraphicCrop.Top); + pResult = pResult->move(aMove); + + return pResult; +} + +drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const +{ + drawing::PointSequenceSequence aPolyPolygon(1); + drawing::PointSequence aPolygon = comphelper::containerToSequence(mPoints); + aPolyPolygon[0] = aPolygon; + return aPolyPolygon; +} + +WrapPolygonHandler::WrapPolygonHandler() + : LoggedProperties("WrapPolygonHandler") + , mpPolygon(new WrapPolygon) + , mnX(0) + , mnY(0) +{ +} + +WrapPolygonHandler::~WrapPolygonHandler() +{ +} + +void WrapPolygonHandler::lcl_attribute(Id Name, Value & val) +{ + sal_Int32 nIntValue = val.getInt(); + + switch(Name) + { + case NS_ooxml::LN_CT_Point2D_x: + mnX = nIntValue; + break; + case NS_ooxml::LN_CT_Point2D_y: + mnY = nIntValue; + break; + default: + SAL_WARN("writerfilter", "WrapPolygonHandler::lcl_attribute: unhandled token: " << Name); + break; + } +} + +void WrapPolygonHandler::lcl_sprm(Sprm & _sprm) +{ + switch (_sprm.getId()) + { + case NS_ooxml::LN_CT_WrapPath_lineTo: + case NS_ooxml::LN_CT_WrapPath_start: + { + resolveSprmProps(*this, _sprm); + + awt::Point aPoint(mnX, mnY); + mpPolygon->addPoint(aPoint); + } + break; + default: + SAL_WARN("writerfilter", "WrapPolygonHandler::lcl_sprm: unhandled token: " << _sprm.getId()); + break; + } +} + + +}} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/WrapPolygonHandler.hxx b/writerfilter/source/dmapper/WrapPolygonHandler.hxx new file mode 100644 index 000000000..e9e58dc09 --- /dev/null +++ b/writerfilter/source/dmapper/WrapPolygonHandler.hxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_WRAPPOLYGONHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_WRAPPOLYGONHANDLER_HXX + +#include +#include "LoggedResources.hxx" +#include +#include + +namespace com::sun::star::text +{ +struct GraphicCrop; +} + +namespace writerfilter { +namespace dmapper { + +/// Handles from DOCX and the pWrapPolygonVertices shape property from RTF. +class WrapPolygon final : public virtual SvRefBase +{ +public: + typedef std::vector Points_t; + typedef ::tools::SvRef Pointer_t; + +private: + Points_t mPoints; + +public: + WrapPolygon(); + ~WrapPolygon() override; + + void addPoint(const css::awt::Point & rPoint); + + Points_t::iterator begin(); + Points_t::iterator end(); + + WrapPolygon::Pointer_t move(const css::awt::Point & rMove); + WrapPolygon::Pointer_t scale(const Fraction & rFractionX, const Fraction & rFractionY); + WrapPolygon::Pointer_t correctWordWrapPolygon(const css::awt::Size & rSrcSize); + WrapPolygon::Pointer_t correctWordWrapPolygonPixel(const css::awt::Size & rSrcSize); + WrapPolygon::Pointer_t correctCrop(const css::awt::Size& rGraphicSize, + const css::text::GraphicCrop& rGraphicCrop); + css::drawing::PointSequenceSequence getPointSequenceSequence() const; +}; + +class WrapPolygonHandler : public LoggedProperties +{ +public: + WrapPolygonHandler(); + virtual ~WrapPolygonHandler() override; + + const WrapPolygon::Pointer_t& getPolygon() const { return mpPolygon;} + +private: + WrapPolygon::Pointer_t mpPolygon; + + sal_Int32 mnX; + sal_Int32 mnY; + + // Properties + virtual void lcl_attribute(Id Name, Value & val) override; + virtual void lcl_sprm(Sprm & sprm) override; + +}; + +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_WRAPPOLYGONHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/domainmapperfactory.cxx b/writerfilter/source/dmapper/domainmapperfactory.cxx new file mode 100644 index 000000000..1e52cfc36 --- /dev/null +++ b/writerfilter/source/dmapper/domainmapperfactory.cxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "DomainMapper.hxx" +#include "TagLogger.hxx" +#include + +namespace writerfilter::dmapper +{ +Stream::Pointer_t +DomainMapperFactory::createMapper(css::uno::Reference const& xContext, + css::uno::Reference const& xInputStream, + css::uno::Reference const& xModel, + bool bRepairStorage, SourceDocumentType eDocumentType, + utl::MediaDescriptor const& rMediaDesc) +{ +#ifdef DBG_UTIL + OUString sURL + = rMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_URL(), OUString()); + ::std::string sURLc = OUStringToOString(sURL, RTL_TEXTENCODING_ASCII_US).getStr(); + + if (getenv("SW_DEBUG_WRITERFILTER")) + TagLogger::getInstance().setFileName(sURLc); + TagLogger::getInstance().startDocument(); +#endif + + return Stream::Pointer_t(new DomainMapper(xContext, xInputStream, xModel, bRepairStorage, + eDocumentType, rMediaDesc)); +} + +} // namespace writerfilter::dmapper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/util.cxx b/writerfilter/source/dmapper/util.cxx new file mode 100644 index 000000000..d4389fce7 --- /dev/null +++ b/writerfilter/source/dmapper/util.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "util.hxx" + +namespace writerfilter::dmapper +{ +using namespace com::sun::star; + +std::string XTextRangeToString(uno::Reference< text::XTextRange > const & textRange) +{ + std::string result; + +#ifdef DBG_UTIL + if (textRange) + { + OUString aOUStr; + + try + { + aOUStr = textRange->getString(); + } + catch (const uno::Exception& rException) + { + result += "(exception: "; + result += rException.Message.toUtf8().getStr(); + result += ")"; + } + + OString aOStr(aOUStr.getStr(), aOUStr.getLength(), RTL_TEXTENCODING_ASCII_US ); + + result = aOStr.getStr(); + } + else + { + result="(nil)"; + } +#else + (void) textRange; +#endif + + return result; +} + +void resolveSprmProps(Properties & rHandler, Sprm & rSprm) +{ + writerfilter::Reference::Pointer_t pProperties = rSprm.getProps(); + if( pProperties) + pProperties->resolve(rHandler); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/util.hxx b/writerfilter/source/dmapper/util.hxx new file mode 100644 index 000000000..e7adfdade --- /dev/null +++ b/writerfilter/source/dmapper/util.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_DMAPPER_UTIL_HXX +#define INCLUDED_WRITERFILTER_SOURCE_DMAPPER_UTIL_HXX + +#include +#include +#include + +namespace writerfilter +{ +namespace dmapper +{ + std::string XTextRangeToString(css::uno::Reference< css::text::XTextRange > const & textRange); + void resolveSprmProps(Properties & rHandler, Sprm & rSprm); +} +} + +#endif // INCLUDED_WRITERFILTER_SOURCE_DMAPPER_UTIL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx new file mode 100644 index 000000000..bfa9a2087 --- /dev/null +++ b/writerfilter/source/filter/RtfFilter.cxx @@ -0,0 +1,220 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace ::com::sun::star; + +namespace +{ +/// Invokes the RTF tokenizer + dmapper or RtfExportFilter in sw via UNO. +class RtfFilter + : public cppu::WeakImplHelper +{ + uno::Reference m_xContext; + uno::Reference m_xSrcDoc, m_xDstDoc; + +public: + explicit RtfFilter(uno::Reference xContext); + + // XFilter + sal_Bool SAL_CALL filter(const uno::Sequence& rDescriptor) override; + void SAL_CALL cancel() override; + + // XImporter + void SAL_CALL setTargetDocument(const uno::Reference& xDoc) override; + + // XExporter + void SAL_CALL setSourceDocument(const uno::Reference& xDoc) override; + + // XInitialization + void SAL_CALL initialize(const uno::Sequence& rArguments) override; + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override; + uno::Sequence SAL_CALL getSupportedServiceNames() override; +}; +} + +RtfFilter::RtfFilter(uno::Reference xContext) + : m_xContext(std::move(xContext)) +{ +} + +sal_Bool RtfFilter::filter(const uno::Sequence& rDescriptor) +{ + if (m_xSrcDoc.is()) + { + uno::Reference xMSF(m_xContext->getServiceManager(), + uno::UNO_QUERY_THROW); + uno::Reference xIfc( + xMSF->createInstance("com.sun.star.comp.Writer.RtfExport"), uno::UNO_SET_THROW); + uno::Reference xExporter(xIfc, uno::UNO_QUERY_THROW); + uno::Reference xFilter(xIfc, uno::UNO_QUERY_THROW); + xExporter->setSourceDocument(m_xSrcDoc); + return xFilter->filter(rDescriptor); + } + + bool bResult(false); + uno::Reference xStatusIndicator; + + uno::Reference xDocProps; + if (m_xDstDoc.is()) // not in cppunittest? + { + xDocProps.set(m_xDstDoc, uno::UNO_QUERY); + xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(true)); + } + comphelper::ScopeGuard g([xDocProps] { + if (xDocProps.is()) // not in cppunittest? + { + // note: pStream.clear calls RemoveLastParagraph() + xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(false)); + } + }); + + try + { + utl::MediaDescriptor aMediaDesc(rDescriptor); + bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault("RepairPackage", false); + bool bIsNewDoc = !aMediaDesc.getUnpackedValueOrDefault("InsertMode", false); + uno::Reference xInputStream; + + aMediaDesc.addInputStream(); + aMediaDesc[utl::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream; + + // If this is set, write to this file, instead of the real document during paste. + char* pEnv = getenv("SW_DEBUG_RTF_PASTE_TO"); + OUString aOutStr; + if (!bIsNewDoc && pEnv + && osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(pEnv), aOutStr) + == osl::FileBase::E_None) + { + std::unique_ptr pOut( + utl::UcbStreamHelper::CreateStream(aOutStr, StreamMode::WRITE)); + std::unique_ptr pIn(utl::UcbStreamHelper::CreateStream(xInputStream)); + pOut->WriteStream(*pIn); + return true; + } + + // If this is set, read from this file, instead of the real clipboard during paste. + pEnv = getenv("SW_DEBUG_RTF_PASTE_FROM"); + if (!bIsNewDoc && pEnv) + { + OUString aInStr; + osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(pEnv), aInStr); + std::unique_ptr pStream + = utl::UcbStreamHelper::CreateStream(aInStr, StreamMode::READ); + uno::Reference xStream(new utl::OStreamWrapper(std::move(pStream))); + xInputStream.set(xStream, uno::UNO_QUERY); + } + + uno::Reference xFrame = aMediaDesc.getUnpackedValueOrDefault( + utl::MediaDescriptor::PROP_FRAME(), uno::Reference()); + + xStatusIndicator = aMediaDesc.getUnpackedValueOrDefault( + utl::MediaDescriptor::PROP_STATUSINDICATOR(), uno::Reference()); + + writerfilter::Stream::Pointer_t pStream( + writerfilter::dmapper::DomainMapperFactory::createMapper( + m_xContext, xInputStream, m_xDstDoc, bRepairStorage, + writerfilter::dmapper::SourceDocumentType::RTF, aMediaDesc)); + writerfilter::rtftok::RTFDocument::Pointer_t pDocument( + writerfilter::rtftok::RTFDocumentFactory::createDocument( + m_xContext, xInputStream, m_xDstDoc, xFrame, xStatusIndicator, aMediaDesc)); + pDocument->resolve(*pStream); + bResult = true; + } + catch (const io::WrongFormatException&) + { + css::uno::Any anyEx = cppu::getCaughtException(); + // cannot throw WrongFormatException directly :( + throw lang::WrappedTargetRuntimeException("", static_cast(this), anyEx); + } + catch (const uno::Exception&) + { + TOOLS_INFO_EXCEPTION("writerfilter", "Exception caught"); + } + + if (xStatusIndicator.is()) + xStatusIndicator->end(); + return bResult; +} + +void RtfFilter::cancel() {} + +void RtfFilter::setSourceDocument(const uno::Reference& xDoc) +{ + m_xSrcDoc = xDoc; +} + +void RtfFilter::setTargetDocument(const uno::Reference& xDoc) +{ + m_xDstDoc = xDoc; +} + +void RtfFilter::initialize(const uno::Sequence& /*aArguments*/) +{ + // The DOCX exporter here extracts 'type' of the filter, ie 'Word' or + // 'Word Template' but we don't need it for RTF. +} + +OUString RtfFilter::getImplementationName() { return "com.sun.star.comp.Writer.RtfFilter"; } + +sal_Bool RtfFilter::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +uno::Sequence RtfFilter::getSupportedServiceNames() +{ + uno::Sequence aRet = { OUString("com.sun.star.document.ImportFilter"), + OUString("com.sun.star.document.ExportFilter") }; + return aRet; +} + +extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* +com_sun_star_comp_Writer_RtfFilter_get_implementation(uno::XComponentContext* pComponent, + uno::Sequence const& /*rSequence*/) +{ + return cppu::acquire(new RtfFilter(pComponent)); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx new file mode 100644 index 000000000..0f0fcdb63 --- /dev/null +++ b/writerfilter/source/filter/WriterFilter.cxx @@ -0,0 +1,366 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef DBG_UTIL +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; + +static OUString lcl_GetExceptionMessageRec(xml::sax::SAXException const& e); + +static OUString lcl_GetExceptionMessage(xml::sax::SAXException const& e) +{ + OUString const thisMessage("SAXParseException: \"" + e.Message + "\""); + OUString const restMessage(lcl_GetExceptionMessageRec(e)); + return restMessage + "\n" + thisMessage; +} +static OUString lcl_GetExceptionMessage(xml::sax::SAXParseException const& e) +{ + OUString const thisMessage("SAXParseException: '" + e.Message + "', Stream '" + e.SystemId + + "', Line " + OUString::number(e.LineNumber) + ", Column " + + OUString::number(e.ColumnNumber)); + OUString const restMessage(lcl_GetExceptionMessageRec(e)); + return restMessage + "\n" + thisMessage; +} + +static OUString lcl_GetExceptionMessageRec(xml::sax::SAXException const& e) +{ + xml::sax::SAXParseException saxpe; + if (e.WrappedException >>= saxpe) + { + return lcl_GetExceptionMessage(saxpe); + } + xml::sax::SAXException saxe; + if (e.WrappedException >>= saxe) + { + return lcl_GetExceptionMessage(saxe); + } + uno::Exception ue; + if (e.WrappedException >>= ue) + { + return ue.Message; + } + return OUString(); +} + +namespace +{ +/// Common DOCX filter, calls DocxExportFilter via UNO or does the DOCX import. +class WriterFilter + : public cppu::WeakImplHelper +{ + uno::Reference m_xContext; + uno::Reference m_xSrcDoc, m_xDstDoc; + uno::Sequence m_xInitializationArguments; + +public: + explicit WriterFilter(uno::Reference xContext) + : m_xContext(std::move(xContext)) + { + } + + // XFilter + sal_Bool SAL_CALL filter(const uno::Sequence& rDescriptor) override; + void SAL_CALL cancel() override; + + // XImporter + void SAL_CALL setTargetDocument(const uno::Reference& xDoc) override; + + // XExporter + void SAL_CALL setSourceDocument(const uno::Reference& xDoc) override; + + // XInitialization + void SAL_CALL initialize(const uno::Sequence& rArguments) override; + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override; + uno::Sequence SAL_CALL getSupportedServiceNames() override; +}; +} + +sal_Bool WriterFilter::filter(const uno::Sequence& rDescriptor) +{ + if (m_xSrcDoc.is()) + { + uno::Reference xMSF(m_xContext->getServiceManager(), + uno::UNO_QUERY_THROW); + uno::Reference xIfc; + try + { + xIfc.set(xMSF->createInstance("com.sun.star.comp.Writer.DocxExport"), + uno::UNO_SET_THROW); + } + catch (uno::RuntimeException&) + { + throw; + } + catch (uno::Exception& e) + { + uno::Any a(cppu::getCaughtException()); + throw lang::WrappedTargetRuntimeException("wrapped " + a.getValueTypeName() + ": " + + e.Message, + uno::Reference(), a); + } + + uno::Reference xInit(xIfc, uno::UNO_QUERY_THROW); + xInit->initialize(m_xInitializationArguments); + + uno::Reference xExprtr(xIfc, uno::UNO_QUERY_THROW); + uno::Reference xFltr(xIfc, uno::UNO_QUERY_THROW); + xExprtr->setSourceDocument(m_xSrcDoc); + return xFltr->filter(rDescriptor); + } + if (m_xDstDoc.is()) + { + uno::Reference const xDocProps(m_xDstDoc, uno::UNO_QUERY); + xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(true)); + comphelper::ScopeGuard g([xDocProps] { + xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(false)); + }); + utl::MediaDescriptor aMediaDesc(rDescriptor); + bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault("RepairPackage", false); + bool bSkipImages + = aMediaDesc.getUnpackedValueOrDefault("FilterOptions", OUString()) == "SkipImages"; + + uno::Reference xInputStream; + try + { + // use the oox.core.FilterDetect implementation to extract the decrypted ZIP package + rtl::Reference<::oox::core::FilterDetect> xDetector( + new ::oox::core::FilterDetect(m_xContext)); + xInputStream = xDetector->extractUnencryptedPackage(aMediaDesc); + } + catch (uno::Exception&) + { + } + + if (!xInputStream.is()) + return false; + + writerfilter::Stream::Pointer_t pStream( + writerfilter::dmapper::DomainMapperFactory::createMapper( + m_xContext, xInputStream, m_xDstDoc, bRepairStorage, + writerfilter::dmapper::SourceDocumentType::OOXML, aMediaDesc)); + //create the tokenizer and domain mapper + writerfilter::ooxml::OOXMLStream::Pointer_t pDocStream + = writerfilter::ooxml::OOXMLDocumentFactory::createStream(m_xContext, xInputStream, + bRepairStorage); + uno::Reference xStatusIndicator + = aMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), + uno::Reference()); + writerfilter::ooxml::OOXMLDocument::Pointer_t pDocument( + writerfilter::ooxml::OOXMLDocumentFactory::createDocument(pDocStream, xStatusIndicator, + bSkipImages, rDescriptor)); + + uno::Reference xModel(m_xDstDoc, uno::UNO_QUERY_THROW); + pDocument->setModel(xModel); + + uno::Reference xDrawings(m_xDstDoc, uno::UNO_QUERY_THROW); + uno::Reference xDrawPage(xDrawings->getDrawPage(), uno::UNO_SET_THROW); + pDocument->setDrawPage(xDrawPage); + + try + { + pDocument->resolve(*pStream); + } + catch (xml::sax::SAXParseException const& e) + { + // note: SfxObjectShell checks for WrongFormatException + io::WrongFormatException wfe(lcl_GetExceptionMessage(e)); + throw lang::WrappedTargetRuntimeException("", static_cast(this), + uno::makeAny(wfe)); + } + catch (xml::sax::SAXException const& e) + { + // note: SfxObjectShell checks for WrongFormatException + io::WrongFormatException wfe(lcl_GetExceptionMessage(e)); + throw lang::WrappedTargetRuntimeException("", static_cast(this), + uno::makeAny(wfe)); + } + catch (uno::RuntimeException const&) + { + throw; + } + catch (uno::Exception const&) + { + css::uno::Any anyEx = cppu::getCaughtException(); + SAL_WARN("writerfilter", + "WriterFilter::filter(): failed with " << exceptionToString(anyEx)); + throw lang::WrappedTargetRuntimeException("", static_cast(this), anyEx); + } + + // Adding some properties to the document's grab bag for interoperability purposes: + comphelper::SequenceAsHashMap aGrabBagProperties; + + // Adding the saved Theme DOM + aGrabBagProperties["OOXTheme"] <<= pDocument->getThemeDom(); + + // Adding the saved custom xml DOM + aGrabBagProperties["OOXCustomXml"] <<= pDocument->getCustomXmlDomList(); + aGrabBagProperties["OOXCustomXmlProps"] <<= pDocument->getCustomXmlDomPropsList(); + + // Adding the saved Glossary Document DOM to the document's grab bag + aGrabBagProperties["OOXGlossary"] <<= pDocument->getGlossaryDocDom(); + aGrabBagProperties["OOXGlossaryDom"] <<= pDocument->getGlossaryDomList(); + + // Adding the saved embedding document to document's grab bag + aGrabBagProperties["OOXEmbeddings"] <<= pDocument->getEmbeddingsList(); + + oox::core::XmlFilterBase::putPropertiesToDocumentGrabBag(m_xDstDoc, aGrabBagProperties); + + writerfilter::ooxml::OOXMLStream::Pointer_t pVBAProjectStream( + writerfilter::ooxml::OOXMLDocumentFactory::createStream( + pDocStream, writerfilter::ooxml::OOXMLStream::VBAPROJECT)); + oox::StorageRef xVbaPrjStrg = std::make_shared<::oox::ole::OleStorage>( + m_xContext, pVBAProjectStream->getDocumentStream(), false); + if (xVbaPrjStrg && xVbaPrjStrg->isStorage()) + { + ::oox::ole::VbaProject aVbaProject(m_xContext, xModel, "Writer"); + uno::Reference xFrame = aMediaDesc.getUnpackedValueOrDefault( + utl::MediaDescriptor::PROP_FRAME(), uno::Reference()); + + // if no XFrame try fallback to what we can glean from the Model + if (!xFrame.is()) + { + uno::Reference xController = xModel->getCurrentController(); + xFrame = xController.is() ? xController->getFrame() : nullptr; + } + + oox::GraphicHelper gHelper(m_xContext, xFrame, xVbaPrjStrg); + aVbaProject.importVbaProject(*xVbaPrjStrg, gHelper); + + writerfilter::ooxml::OOXMLStream::Pointer_t pVBADataStream( + writerfilter::ooxml::OOXMLDocumentFactory::createStream( + pDocStream, writerfilter::ooxml::OOXMLStream::VBADATA)); + if (pVBADataStream) + { + uno::Reference xDataStream = pVBADataStream->getDocumentStream(); + if (xDataStream.is()) + aVbaProject.importVbaData(xDataStream); + } + } + + pStream.clear(); + + // note: pStream.clear calls RemoveLastParagraph() + + return true; + } + return false; +} + +void WriterFilter::cancel() {} + +void WriterFilter::setTargetDocument(const uno::Reference& xDoc) +{ + m_xDstDoc = xDoc; + + // Set some compatibility options that are valid for all the formats + uno::Reference xFactory(xDoc, uno::UNO_QUERY); + uno::Reference xSettings( + xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + + xSettings->setPropertyValue("AddFrameOffsets", uno::makeAny(true)); + xSettings->setPropertyValue("AddVerticalFrameOffsets", uno::makeAny(true)); + xSettings->setPropertyValue("UseOldNumbering", uno::makeAny(false)); + xSettings->setPropertyValue("IgnoreFirstLineIndentInNumbering", uno::makeAny(false)); + xSettings->setPropertyValue("DoNotResetParaAttrsForNumFont", uno::makeAny(false)); + xSettings->setPropertyValue("UseFormerLineSpacing", uno::makeAny(false)); + xSettings->setPropertyValue("AddParaSpacingToTableCells", uno::makeAny(true)); + xSettings->setPropertyValue("AddParaLineSpacingToTableCells", uno::makeAny(true)); + xSettings->setPropertyValue("UseFormerObjectPositioning", uno::makeAny(false)); + xSettings->setPropertyValue("ConsiderTextWrapOnObjPos", uno::makeAny(true)); + xSettings->setPropertyValue("UseFormerTextWrapping", uno::makeAny(false)); + xSettings->setPropertyValue("TableRowKeep", uno::makeAny(true)); + xSettings->setPropertyValue("IgnoreTabsAndBlanksForLineCalculation", uno::makeAny(true)); + xSettings->setPropertyValue("InvertBorderSpacing", uno::makeAny(true)); + xSettings->setPropertyValue("CollapseEmptyCellPara", uno::makeAny(true)); + xSettings->setPropertyValue("TabOverflow", uno::makeAny(true)); + xSettings->setPropertyValue("UnbreakableNumberings", uno::makeAny(true)); + + xSettings->setPropertyValue("FloattableNomargins", uno::makeAny(true)); + xSettings->setPropertyValue("ClippedPictures", uno::makeAny(true)); + xSettings->setPropertyValue("BackgroundParaOverDrawings", uno::makeAny(true)); + xSettings->setPropertyValue("TabOverMargin", uno::makeAny(true)); + xSettings->setPropertyValue("TreatSingleColumnBreakAsPageBreak", uno::makeAny(true)); + xSettings->setPropertyValue("PropLineSpacingShrinksFirstLine", uno::makeAny(true)); + xSettings->setPropertyValue("DoNotCaptureDrawObjsOnPage", uno::makeAny(true)); + xSettings->setPropertyValue("DisableOffPagePositioning", uno::makeAny(true)); +} + +void WriterFilter::setSourceDocument(const uno::Reference& xDoc) +{ + m_xSrcDoc = xDoc; +} + +void WriterFilter::initialize(const uno::Sequence& rArguments) +{ + m_xInitializationArguments = rArguments; +} + +OUString WriterFilter::getImplementationName() { return "com.sun.star.comp.Writer.WriterFilter"; } + +sal_Bool WriterFilter::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +uno::Sequence WriterFilter::getSupportedServiceNames() +{ + uno::Sequence aRet = { OUString("com.sun.star.document.ImportFilter"), + OUString("com.sun.star.document.ExportFilter") }; + return aRet; +} + +extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* +com_sun_star_comp_Writer_WriterFilter_get_implementation( + uno::XComponentContext* component, uno::Sequence const& /*rSequence*/) +{ + return cppu::acquire(new WriterFilter(component)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/Handler.cxx b/writerfilter/source/ooxml/Handler.cxx new file mode 100644 index 000000000..c582b71ab --- /dev/null +++ b/writerfilter/source/ooxml/Handler.cxx @@ -0,0 +1,403 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "Handler.hxx" + +#include + +namespace writerfilter::ooxml +{ + +/* + class OOXMLFootnoteHandler + */ +OOXMLFootnoteHandler::OOXMLFootnoteHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLFootnoteHandler::~OOXMLFootnoteHandler() +{ +} + +void OOXMLFootnoteHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_FtnEdnRef_id: + mpFastContext->resolveFootnote(sal_Int32(val.getInt())); + break; + default: + break; + } +} + +void OOXMLFootnoteHandler::sprm(Sprm & /*sprm*/) +{ +} + +/* + class OOXMLEndnoteHandler + */ +OOXMLEndnoteHandler::OOXMLEndnoteHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLEndnoteHandler::~OOXMLEndnoteHandler() +{ +} + +void OOXMLEndnoteHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_FtnEdnRef_id: + mpFastContext->resolveEndnote(sal_Int32(val.getInt())); + break; + default: + break; + } +} + +void OOXMLEndnoteHandler::sprm(Sprm & /*sprm*/) +{ +} + +/* + class OOXMLCommentHandler +*/ +OOXMLCommentHandler::OOXMLCommentHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLCommentHandler::~OOXMLCommentHandler() +{ +} + +void OOXMLCommentHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_Markup_id: + mpFastContext->resolveComment(val.getInt()); + break; + default: + ; + } +} + +void OOXMLCommentHandler::sprm(Sprm & /*sprm*/) +{ +} + +/* + class OOXMLOLEHandler +*/ +OOXMLOLEHandler::OOXMLOLEHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLOLEHandler::~OOXMLOLEHandler() +{ +} + +void OOXMLOLEHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_OLEObject_r_id: + try { + mpFastContext->resolveData(val.getString()); + } + catch (const ::css::uno::Exception&) + { + // Can't resolve OLE stream + SAL_WARN("writerfilter.ooxml", "Failed to open OLE stream!"); + } + break; + default: + ; + } +} + +void OOXMLOLEHandler::sprm(Sprm & /*sprm*/) +{ +} + +OOXMLEmbeddedFontHandler::OOXMLEmbeddedFontHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLEmbeddedFontHandler::~OOXMLEmbeddedFontHandler() +{ +} + +void OOXMLEmbeddedFontHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_Rel_id: + mpFastContext->resolveData(val.getString()); + break; + default: + break; + } +} + +void OOXMLEmbeddedFontHandler::sprm(Sprm & /*sprm*/) +{ +} + +/* + class OOXMLFooterHandler + */ +OOXMLFooterHandler::OOXMLFooterHandler(OOXMLFastContextHandler * pContext) + : mpFastContext(pContext), msStreamId(), mnType(0) +{ +} + +void OOXMLFooterHandler::finalize() +{ + mpFastContext->resolveFooter(mnType, msStreamId); +} + +void OOXMLFooterHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_HdrFtrRef_id: + msStreamId = val.getString(); + break; + case NS_ooxml::LN_CT_HdrFtrRef_type: + mnType = val.getInt(); + break; + default: + break; + } +} + +void OOXMLFooterHandler::sprm(Sprm & /*sprm*/) +{ +} + +/* + class OOXMLHeaderHandler + */ +OOXMLHeaderHandler::OOXMLHeaderHandler(OOXMLFastContextHandler * pContext) + : mpFastContext(pContext), msStreamId(), mnType(0) +{ +} + +void OOXMLHeaderHandler::finalize() +{ + mpFastContext->resolveHeader(mnType, msStreamId); +} + +void OOXMLHeaderHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_HdrFtrRef_id: + msStreamId = val.getString(); + break; + case NS_ooxml::LN_CT_HdrFtrRef_type: + mnType = val.getInt(); + break; + default: + break; + } +} + +void OOXMLHeaderHandler::sprm(Sprm & /*sprm*/) +{ +} + +/* + class OOXMLBreakHandler + */ +OOXMLBreakHandler::OOXMLBreakHandler(Stream &rStream) +: mnType(0), + mrStream(rStream) +{ +} + +OOXMLBreakHandler::~OOXMLBreakHandler() +{ + sal_uInt8 tmpBreak[1]; + switch (mnType) + { + case NS_ooxml::LN_Value_ST_BrType_column: + tmpBreak[0] = 0x0E; + break; + case NS_ooxml::LN_Value_ST_BrType_page: + tmpBreak[0] = 0x0C; + break; + case NS_ooxml::LN_Value_ST_BrType_textWrapping: + default: // when no attribute type is present, the spec assume textWrapping + tmpBreak[0] = 0x0A; + break; + } + mrStream.text(&tmpBreak[0], 1); +} + +void OOXMLBreakHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_Br_type: + mnType = val.getInt(); + break; + case NS_ooxml::LN_CT_Br_clear: + break; + default: + break; + } +} + +void OOXMLBreakHandler::sprm(Sprm & /*sprm*/) +{ +} + +/* + class OOXMLPictureHandler + */ +OOXMLPictureHandler::OOXMLPictureHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLPictureHandler::~OOXMLPictureHandler() +{ +} + +void OOXMLPictureHandler::attribute(Id name, Value & val) +{ + if (name == NS_ooxml::LN_AG_Blob_r_embed) + mpFastContext->resolvePicture(val.getString()); + else + { + writerfilter::Reference::Pointer_t pProps + (val.getProperties()); + if (pProps.get() != nullptr) + pProps->resolve(*this); + } +} + +void OOXMLPictureHandler::sprm(Sprm & rSprm) +{ + writerfilter::Reference::Pointer_t pProps + (rSprm.getProps()); + + if (pProps.get() != nullptr) + pProps->resolve(*this); +} + +/** + class OOXMLHyperlinkHandler + */ + +OOXMLHyperlinkHandler::OOXMLHyperlinkHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLHyperlinkHandler::~OOXMLHyperlinkHandler() +{ +} + +void OOXMLHyperlinkHandler::writetext() +{ + OUString sReturn = " HYPERLINK \"" + mURL + "\"" + mFieldCode; + mpFastContext->text(sReturn); +} + +void OOXMLHyperlinkHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_Hyperlink_tgtFrame: + mFieldCode += " \\t \""; + mFieldCode += val.getString(); + mFieldCode += "\""; + break; + case NS_ooxml::LN_CT_Hyperlink_tooltip: + mFieldCode += " \\o \""; + mFieldCode += val.getString(); + mFieldCode += "\""; + break; + case NS_ooxml::LN_CT_Hyperlink_docLocation: + break; + case NS_ooxml::LN_CT_Hyperlink_history: + break; + case NS_ooxml::LN_CT_Hyperlink_anchor: + mFieldCode += " \\l \""; + mFieldCode += val.getString(); + mFieldCode += "\""; + break; + case NS_ooxml::LN_CT_Hyperlink_r_id: + mURL = mpFastContext->getTargetForId(val.getString()); + break; + default: + break; + } +} + +void OOXMLHyperlinkHandler::sprm(Sprm & /*rSprm*/) +{ +} + +/** + class OOXMLHyperlinkURLHandler + */ + +OOXMLHyperlinkURLHandler::OOXMLHyperlinkURLHandler(OOXMLFastContextHandler * pContext) +: mpFastContext(pContext) +{ +} + +OOXMLHyperlinkURLHandler::~OOXMLHyperlinkURLHandler() +{ + mpFastContext->clearProps(); + mpFastContext->newProperty(NS_ooxml::LN_CT_Hyperlink_URL, OOXMLValue::Pointer_t(new OOXMLStringValue(mURL))); +} + +void OOXMLHyperlinkURLHandler::attribute(Id name, Value & val) +{ + switch (name) + { + case NS_ooxml::LN_CT_Hyperlink_URL: + mURL = mpFastContext->getTargetForId(val.getString()); + break; + default: + break; + } +} + +void OOXMLHyperlinkURLHandler::sprm(Sprm & /*rSprm*/) +{ +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/Handler.hxx b/writerfilter/source/ooxml/Handler.hxx new file mode 100644 index 000000000..47ae7d562 --- /dev/null +++ b/writerfilter/source/ooxml/Handler.hxx @@ -0,0 +1,163 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_HANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_HANDLER_HXX + +#include +#include "OOXMLFastContextHandler.hxx" + +namespace writerfilter { +namespace ooxml +{ +class OOXMLFootnoteHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; + +public: + explicit OOXMLFootnoteHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFootnoteHandler() override; + + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLEndnoteHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; +public: + explicit OOXMLEndnoteHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLEndnoteHandler() override; + + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLFooterHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; + OUString msStreamId; + sal_Int32 mnType; +public: + explicit OOXMLFooterHandler(OOXMLFastContextHandler * pContext); + void finalize(); + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLHeaderHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; + OUString msStreamId; + sal_Int32 mnType; +public: + explicit OOXMLHeaderHandler(OOXMLFastContextHandler * pContext); + void finalize(); + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLCommentHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; +public: + explicit OOXMLCommentHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLCommentHandler() override; + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLOLEHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; + +public: + explicit OOXMLOLEHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLOLEHandler() override; + + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLEmbeddedFontHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; + +public: + explicit OOXMLEmbeddedFontHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLEmbeddedFontHandler() override; + + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLBreakHandler : public Properties +{ + sal_Int32 mnType; + Stream & mrStream; +public: + explicit OOXMLBreakHandler(Stream & rStream); + virtual ~OOXMLBreakHandler() override; + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLPictureHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; +public: + explicit OOXMLPictureHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLPictureHandler() override; + + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLHyperlinkHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; + OUString mFieldCode; + OUString mURL; + +public: + explicit OOXMLHyperlinkHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLHyperlinkHandler() override; + void writetext(); + + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + +class OOXMLHyperlinkURLHandler : public Properties +{ + OOXMLFastContextHandler * mpFastContext; + OUString mURL; + +public: + explicit OOXMLHyperlinkURLHandler(OOXMLFastContextHandler * pContext); + virtual ~OOXMLHyperlinkURLHandler() override; + + virtual void attribute(Id name, Value & val) override; + virtual void sprm(Sprm & sprm) override; +}; + + +}} +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_HANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLBinaryObjectReference.cxx b/writerfilter/source/ooxml/OOXMLBinaryObjectReference.cxx new file mode 100644 index 000000000..1cf7ba7d0 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLBinaryObjectReference.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include "OOXMLBinaryObjectReference.hxx" +#include + +namespace writerfilter::ooxml +{ + +using namespace ::com::sun::star; + +OOXMLBinaryObjectReference::OOXMLBinaryObjectReference +(OOXMLStream::Pointer_t const & pStream) +: mpStream(pStream), mbRead(false) +{ +} + +OOXMLBinaryObjectReference::~OOXMLBinaryObjectReference() +{ +} + +void OOXMLBinaryObjectReference::read() +{ + sal_uInt32 nMaxReadBytes = 1024*1024; + uno::Sequence aSeq(nMaxReadBytes); + uno::Reference xInputStream = + mpStream->getDocumentStream(); + + sal_uInt32 nSize = 0; + sal_uInt32 nOldSize = 0; + sal_uInt32 nBytesRead = 0; + + while ((nBytesRead = xInputStream->readSomeBytes(aSeq, nMaxReadBytes)) > 0) + { + nOldSize = nSize; + nSize += nBytesRead; + mSequence.resize(nSize); + + memcpy(&mSequence[nOldSize], aSeq.getArray(), nBytesRead); + } + + mbRead = true; +} + +void OOXMLBinaryObjectReference::resolve(BinaryObj & rHandler) +{ + if (! mbRead) + read(); + + rHandler.data(reinterpret_cast(mSequence.data()), + mSequence.size()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLBinaryObjectReference.hxx b/writerfilter/source/ooxml/OOXMLBinaryObjectReference.hxx new file mode 100644 index 000000000..979998fec --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLBinaryObjectReference.hxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLBINARYOBJECTREFERENCE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLBINARYOBJECTREFERENCE_HXX + +#include +#include +#include + +namespace writerfilter { +namespace ooxml +{ +class OOXMLBinaryObjectReference : + public writerfilter::Reference +{ + OOXMLStream::Pointer_t mpStream; + std::vector mSequence; + bool mbRead; + + void read(); + +public: + explicit OOXMLBinaryObjectReference(OOXMLStream::Pointer_t const & pStream); + virtual ~OOXMLBinaryObjectReference() override; + + virtual void resolve(BinaryObj & rHandler) override; +}; +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLBINARYOBJECTREFERENCE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx new file mode 100644 index 000000000..285028cc9 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx @@ -0,0 +1,879 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include "OOXMLStreamImpl.hxx" +#include "OOXMLDocumentImpl.hxx" +#include "OOXMLBinaryObjectReference.hxx" +#include "OOXMLFastDocumentHandler.hxx" +#include "OOXMLPropertySet.hxx" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +// this extern variable is declared in OOXMLStreamImpl.hxx +OUString customTarget; +OUString embeddingsTarget; +using namespace ::com::sun::star; +namespace writerfilter::ooxml +{ + +OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t const & pStream, const uno::Reference& xStatusIndicator, bool bSkipImages, const uno::Sequence& rDescriptor) + : mpStream(pStream) + , mxStatusIndicator(xStatusIndicator) + , mnXNoteId(0) + , mbIsSubstream(false) + , mbSkipImages(bSkipImages) + , mnPercentSize(0) + , mnProgressLastPos(0) + , mnProgressCurrentPos(0) + , mnProgressEndPos(0) + , m_rBaseURL(utl::MediaDescriptor(rDescriptor).getUnpackedValueOrDefault("DocumentBaseURL", OUString())) + , maMediaDescriptor(rDescriptor) +{ + pushShapeContext(); +} + +OOXMLDocumentImpl::~OOXMLDocumentImpl() +{ +} + +void OOXMLDocumentImpl::resolveFastSubStream(Stream & rStreamHandler, + OOXMLStream::StreamType_t nType) +{ + OOXMLStream::Pointer_t pStream; + try + { + pStream = OOXMLDocumentFactory::createStream(mpStream, nType); + } + catch (uno::Exception const&) + { + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "resolveFastSubStream: exception while " + "resolving stream " << nType); + return; + } + OOXMLStream::Pointer_t savedStream = mpStream; + mpStream = pStream; + + uno::Reference xParser(mpStream->getFastParser()); + + if (xParser.is()) + { + uno::Reference xContext(mpStream->getContext()); + OOXMLFastDocumentHandler * pDocHandler = + new OOXMLFastDocumentHandler(xContext, &rStreamHandler, this, mnXNoteId); + + uno::Reference xDocumentHandler(pDocHandler); + uno::Reference xTokenHandler(mpStream->getFastTokenHandler()); + + xParser->setFastDocumentHandler(xDocumentHandler); + xParser->setTokenHandler(xTokenHandler); + + uno::Reference xInputStream = pStream->getDocumentStream(); + + if (xInputStream.is()) + { + struct xml::sax::InputSource oInputSource; + oInputSource.aInputStream = xInputStream; + xParser->parseStream(oInputSource); + + xInputStream->closeInput(); + } + } + + mpStream = savedStream; +} + +void OOXMLDocumentImpl::resolveFastSubStreamWithId(Stream & rStream, + const writerfilter::Reference::Pointer_t& pStream, + sal_uInt32 nId) +{ + rStream.substream(nId, pStream); +} + +uno::Reference OOXMLDocumentImpl::importSubStream(OOXMLStream::StreamType_t nType) +{ + uno::Reference xRet; + + OOXMLStream::Pointer_t pStream; + try + { + pStream = OOXMLDocumentFactory::createStream(mpStream, nType); + } + catch (uno::Exception const&) + { + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " + "importing stream " << nType); + return xRet; + } + + uno::Reference xInputStream = pStream->getDocumentStream(); + if (xInputStream.is()) + { + try + { + uno::Reference xContext(mpStream->getContext()); + uno::Reference xDomBuilder(xml::dom::DocumentBuilder::create(xContext)); + xRet = xDomBuilder->parse(xInputStream); + } + catch (uno::Exception const&) + { + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " + "parsing stream " << nType); + return xRet; + } + } + + if (OOXMLStream::CUSTOMXML == nType) + { + importSubStreamRelations(pStream, OOXMLStream::CUSTOMXMLPROPS); + } + else if (OOXMLStream::CHARTS == nType) + { + importSubStreamRelations(pStream, OOXMLStream::EMBEDDINGS); + } + + return xRet; +} + + +void OOXMLDocumentImpl::importSubStreamRelations(const OOXMLStream::Pointer_t& pStream, OOXMLStream::StreamType_t nType) +{ + uno::Reference xRelation; + OOXMLStream::Pointer_t cStream; + try + { + cStream = OOXMLDocumentFactory::createStream(pStream, nType); + } + catch (uno::Exception const&) + { + TOOLS_WARN_EXCEPTION("writerfilter.ooxml", "importSubStreamRelations: exception while " + "importing stream " << nType); + return; + } + + uno::Reference xcpInputStream = cStream->getDocumentStream(); + + if (xcpInputStream.is()) + { + // importing itemprops files for item.xml from customXml. + if (OOXMLStream::CUSTOMXMLPROPS == nType) + { + try + { + uno::Reference xcpContext(pStream->getContext()); + uno::Reference xDomBuilder(xml::dom::DocumentBuilder::create(xcpContext)); + xRelation = xDomBuilder->parse(xcpInputStream); + } + catch (uno::Exception const&) + { + TOOLS_WARN_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " + "parsing stream " << nType); + mxCustomXmlProsDom = xRelation; + } + + if(xRelation.is()) + { + mxCustomXmlProsDom = xRelation; + } + } + else if(OOXMLStream::EMBEDDINGS == nType) + { + mxEmbeddings = xcpInputStream; + } + else if(OOXMLStream::CHARTS == nType) + { + importSubStreamRelations(cStream, OOXMLStream::EMBEDDINGS); + } + } + + +} + +void OOXMLDocumentImpl::setXNoteId(const sal_Int32 nId) +{ + mnXNoteId = nId; +} + +sal_Int32 OOXMLDocumentImpl::getXNoteId() const +{ + return mnXNoteId; +} + +const OUString & OOXMLDocumentImpl::getTarget() const +{ + return mpStream->getTarget(); +} + +writerfilter::Reference::Pointer_t +OOXMLDocumentImpl::getSubStream(const OUString & rId) +{ + OOXMLStream::Pointer_t pStream + (OOXMLDocumentFactory::createStream(mpStream, rId)); + + OOXMLDocumentImpl * pTemp; + // Do not pass status indicator to sub-streams: they are typically marginal in size, so we just track the main document for now. + writerfilter::Reference::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream, uno::Reference(), mbSkipImages, maMediaDescriptor)); + pTemp->setModel(mxModel); + pTemp->setDrawPage(mxDrawPage); + pTemp->mbIsSubstream = true; + return pRet; +} + +writerfilter::Reference::Pointer_t +OOXMLDocumentImpl::getXNoteStream(OOXMLStream::StreamType_t nType, const sal_Int32 nId) +{ + OOXMLStream::Pointer_t pStream = + OOXMLDocumentFactory::createStream(mpStream, nType); + // See above, no status indicator for the note stream, either. + OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream, uno::Reference(), mbSkipImages, maMediaDescriptor); + pDocument->setXNoteId(nId); + pDocument->setModel(getModel()); + pDocument->setDrawPage(getDrawPage()); + + return writerfilter::Reference::Pointer_t(pDocument); +} + +void OOXMLDocumentImpl::resolveFootnote(Stream & rStream, + Id aType, + const sal_Int32 nNoteId) +{ + writerfilter::Reference::Pointer_t pStream = + getXNoteStream(OOXMLStream::FOOTNOTES, nNoteId); + + Id nId; + switch (aType) + { + case NS_ooxml::LN_Value_doc_ST_FtnEdn_separator: + case NS_ooxml::LN_Value_doc_ST_FtnEdn_continuationSeparator: + nId = aType; + break; + default: + nId = NS_ooxml::LN_footnote; + break; + } + + resolveFastSubStreamWithId(rStream, pStream, nId); +} + +void OOXMLDocumentImpl::resolveEndnote(Stream & rStream, + Id aType, + const sal_Int32 nNoteId) +{ + writerfilter::Reference::Pointer_t pStream = + getXNoteStream(OOXMLStream::ENDNOTES, nNoteId); + + Id nId; + switch (aType) + { + case NS_ooxml::LN_Value_doc_ST_FtnEdn_separator: + case NS_ooxml::LN_Value_doc_ST_FtnEdn_continuationSeparator: + nId = aType; + break; + default: + nId = NS_ooxml::LN_endnote; + break; + } + + resolveFastSubStreamWithId(rStream, pStream, nId); +} + +void OOXMLDocumentImpl::resolveComment(Stream & rStream, + const sal_Int32 nId) +{ + writerfilter::Reference::Pointer_t pStream = + getXNoteStream(OOXMLStream::COMMENTS, nId); + + resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_annotation); +} + +OOXMLPropertySet * OOXMLDocumentImpl::getPicturePropSet +(const OUString & rId) +{ + OOXMLStream::Pointer_t pStream + (OOXMLDocumentFactory::createStream(mpStream, rId)); + + writerfilter::Reference::Pointer_t pPicture + (new OOXMLBinaryObjectReference(pStream)); + + OOXMLValue::Pointer_t pPayloadValue(new OOXMLBinaryValue(pPicture)); + + OOXMLPropertySet::Pointer_t pBlipSet(new OOXMLPropertySet); + + pBlipSet->add(NS_ooxml::LN_payload, pPayloadValue, OOXMLProperty::ATTRIBUTE); + + OOXMLValue::Pointer_t pBlipValue(new OOXMLPropertySetValue(pBlipSet)); + + OOXMLPropertySet * pProps = new OOXMLPropertySet; + + pProps->add(NS_ooxml::LN_blip, pBlipValue, OOXMLProperty::ATTRIBUTE); + + return pProps; +} + +void OOXMLDocumentImpl::resolvePicture(Stream & rStream, + const OUString & rId) +{ + OOXMLPropertySet::Pointer_t pProps(getPicturePropSet(rId)); + + rStream.props(pProps.get()); +} + +OUString OOXMLDocumentImpl::getTargetForId(const OUString & rId) +{ + return mpStream->getTargetForId(rId); +} + +void OOXMLDocumentImpl::resolveHeader(Stream & rStream, + const sal_Int32 type, + const OUString & rId) +{ + writerfilter::Reference::Pointer_t pStream = + getSubStream(rId); + switch (type) + { + case NS_ooxml::LN_Value_ST_HdrFtr_even: + resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_headerl); + break; + case NS_ooxml::LN_Value_ST_HdrFtr_default: // here we assume that default is right, but not necessarily true :-( + resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_headerr); + break; + case NS_ooxml::LN_Value_ST_HdrFtr_first: + resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_headerf); + break; + default: + break; + } +} + +void OOXMLDocumentImpl::resolveFooter(Stream & rStream, + const sal_Int32 type, + const OUString & rId) +{ + writerfilter::Reference::Pointer_t pStream = + getSubStream(rId); + + switch (type) + { + case NS_ooxml::LN_Value_ST_HdrFtr_even: + resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_footerl); + break; + case NS_ooxml::LN_Value_ST_HdrFtr_default: // here we assume that default is right, but not necessarily true :-( + resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_footerr); + break; + case NS_ooxml::LN_Value_ST_HdrFtr_first: + resolveFastSubStreamWithId(rStream, pStream, NS_ooxml::LN_footerf); + break; + default: + break; + } +} + +namespace { +// Ensures that the indicator is reset after exiting OOXMLDocumentImpl::resolve +class StatusIndicatorGuard{ +public: + explicit StatusIndicatorGuard(css::uno::Reference const & xStatusIndicator) + :mxStatusIndicator(xStatusIndicator) + { + } + + ~StatusIndicatorGuard() + { + if (mxStatusIndicator.is()) + mxStatusIndicator->end(); + } + +private: + css::uno::Reference mxStatusIndicator; +}; +} + +void OOXMLDocumentImpl::resolve(Stream & rStream) +{ + StatusIndicatorGuard aStatusIndicatorGuard(mxStatusIndicator); + + if (utl::MediaDescriptor(maMediaDescriptor).getUnpackedValueOrDefault("ReadGlossaries", false)) + { + resolveFastSubStream(rStream, OOXMLStream::GLOSSARY); + return; + } + + uno::Reference xParser(mpStream->getFastParser()); + + if (mxModel.is()) + { + uno::Reference xDocumentPropertiesSupplier(mxModel, uno::UNO_QUERY); + uno::Reference xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); + comphelper::SequenceAsHashMap aMap(xDocumentProperties->getDocumentStatistics()); + if (aMap.find("ParagraphCount") != aMap.end()) + { + sal_Int32 nValue; + if (aMap["ParagraphCount"] >>= nValue) + { + if (mxStatusIndicator.is()) + { + // We want to care about the progress if we know the estimated paragraph count and we have given a status indicator as well. + // Set the end position only here, so later it's enough to check if that is non-zero in incrementProgress(). + mnProgressEndPos = nValue; + OUString aDocLoad(SvxResId(RID_SVXSTR_DOC_LOAD)); + mxStatusIndicator->start(aDocLoad, mnProgressEndPos); + mnPercentSize = mnProgressEndPos / 100; + } + } + } + } + + if (xParser.is()) + { + uno::Reference xContext(mpStream->getContext()); + + OOXMLFastDocumentHandler * pDocHandler = + new OOXMLFastDocumentHandler(xContext, &rStream, this, mnXNoteId); + pDocHandler->setIsSubstream( mbIsSubstream ); + uno::Reference < xml::sax::XFastDocumentHandler > xDocumentHandler(pDocHandler); + uno::Reference < xml::sax::XFastTokenHandler > xTokenHandler(mpStream->getFastTokenHandler()); + + resolveFastSubStream(rStream, OOXMLStream::SETTINGS); + mxThemeDom = importSubStream(OOXMLStream::THEME); + resolveFastSubStream(rStream, OOXMLStream::THEME); + mxGlossaryDocDom = importSubStream(OOXMLStream::GLOSSARY); + if (mxGlossaryDocDom.is()) + resolveGlossaryStream(rStream); + + resolveEmbeddingsStream(mpStream); + + // Custom xml's are handled as part of grab bag. + resolveCustomXmlStream(rStream); + + resolveFastSubStream(rStream, OOXMLStream::FONTTABLE); + resolveFastSubStream(rStream, OOXMLStream::STYLES); + resolveFastSubStream(rStream, OOXMLStream::NUMBERING); + + xParser->setFastDocumentHandler( xDocumentHandler ); + xParser->setTokenHandler( xTokenHandler ); + + xml::sax::InputSource aParserInput; + aParserInput.sSystemId = mpStream->getTarget(); + aParserInput.aInputStream = mpStream->getDocumentStream(); + try + { + xParser->parseStream(aParserInput); + } + catch (xml::sax::SAXException const& rErr) + { + // don't silently swallow these - handlers may not have been executed, + // and the domain mapper is likely in an inconsistent state + // In case user chooses to try to continue loading, don't ask again for this file + SfxObjectShell* rShell = SfxObjectShell::GetShellFromComponent(mxModel); + if (!rShell || !rShell->IsContinueImportOnFilterExceptions("SAXException: " + rErr.Message)) + throw; + } + catch (uno::RuntimeException const&) + { + throw; + } + // note: cannot throw anything other than SAXException out of here? + catch (uno::Exception const&) + { + css::uno::Any anyEx = cppu::getCaughtException(); + SAL_WARN("writerfilter.ooxml", "OOXMLDocumentImpl::resolve(): " << exceptionToString(anyEx)); + throw lang::WrappedTargetRuntimeException("", nullptr, anyEx); + } + catch (...) + { + SAL_WARN("writerfilter.ooxml", + "OOXMLDocumentImpl::resolve(): non-UNO exception"); + } + } +} + +void OOXMLDocumentImpl::incrementProgress() +{ + mnProgressCurrentPos++; + // 1) If we know the end + // 2) We progressed enough that updating makes sense + // 3) We did not reach the end yet (possible in case the doc stat is misleading) + if (mnProgressEndPos && mnProgressCurrentPos > (mnProgressLastPos + mnPercentSize) && mnProgressLastPos < mnProgressEndPos) + { + mnProgressLastPos = mnProgressCurrentPos; + if (mxStatusIndicator.is()) + mxStatusIndicator->setValue(mnProgressLastPos); + } +} + +void OOXMLDocumentImpl::resolveCustomXmlStream(Stream & rStream) +{ + // Resolving all item[n].xml files from CustomXml folder. + uno::Reference xRelationshipAccess; + xRelationshipAccess.set(dynamic_cast(*mpStream).accessDocumentStream(), uno::UNO_QUERY); + if (xRelationshipAccess.is()) + { + static const char sCustomType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"; + static const char sCustomTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/customXml"; + bool bFound = false; + const uno::Sequence> aSeqs = xRelationshipAccess->getAllRelationships(); + std::vector> aCustomXmlDomList; + std::vector> aCustomXmlDomPropsList; + for (const uno::Sequence& aSeq : aSeqs) + { + for (const beans::StringPair& aPair : aSeq) + { + // Need to resolve only customxml files from document relationships. + // Skipping other files. + if (aPair.Second == sCustomType || + aPair.Second == sCustomTypeStrict) + bFound = true; + else if (aPair.First == "Target" && bFound) + { + // Adding value to extern variable customTarget. It will be used in ooxmlstreamimpl + // to ensure customxml target is visited in lcl_getTarget. + customTarget = aPair.Second; + } + } + + if (bFound) + { + uno::Reference customXmlTemp = importSubStream(OOXMLStream::CUSTOMXML); + // This will add all item[n].xml with its relationship file i.e itemprops.xml to + // grabbag list. + if (mxCustomXmlProsDom.is() && customXmlTemp.is()) + { + aCustomXmlDomList.push_back(customXmlTemp); + aCustomXmlDomPropsList.push_back(mxCustomXmlProsDom); + resolveFastSubStream(rStream, OOXMLStream::CUSTOMXML); + } + + bFound = false; + } + } + + mxCustomXmlDomList = comphelper::containerToSequence(aCustomXmlDomList); + mxCustomXmlDomPropsList = comphelper::containerToSequence(aCustomXmlDomPropsList); + } +} + +void OOXMLDocumentImpl::resolveGlossaryStream(Stream & /*rStream*/) +{ + static const char sSettingsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"; + static const char sStylesType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; + static const char sFonttableType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"; + static const char sWebSettings[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"; + static const char sSettingsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/settings"; + static const char sStylesTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/styles"; + static const char sFonttableTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable"; + static const char sWebSettingsStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings"; + + OOXMLStream::Pointer_t pStream; + try + { + pStream = OOXMLDocumentFactory::createStream(mpStream, OOXMLStream::GLOSSARY); + } + catch (uno::Exception const&) + { + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "resolveGlossaryStream: exception while " + "createStream for glossary" << OOXMLStream::GLOSSARY); + return; + } + uno::Reference xRelationshipAccess; + xRelationshipAccess.set(dynamic_cast(*pStream).accessDocumentStream(), uno::UNO_QUERY); + if (xRelationshipAccess.is()) + { + + const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships(); + std::vector< uno::Sequence > aGlossaryDomList; + for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs) + { + OOXMLStream::Pointer_t gStream; + //Follows following aSeq[0] is Id, aSeq[1] is Type, aSeq[2] is Target + if (aSeq.getLength() < 3) + { + SAL_WARN("writerfilter.ooxml", "too short sequence"); + continue; + } + + OUString gId(aSeq[0].Second); + OUString gType(aSeq[1].Second); + OUString gTarget(aSeq[2].Second); + OUString contentType; + + OOXMLStream::StreamType_t nType(OOXMLStream::UNKNOWN); + bool bFound = true; + if(gType == sSettingsType || + gType == sSettingsTypeStrict) + { + nType = OOXMLStream::SETTINGS; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"; + } + else if(gType == sStylesType || + gType == sStylesTypeStrict) + { + nType = OOXMLStream::STYLES; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"; + } + else if(gType == sWebSettings || + gType == sWebSettingsStrict) + { + nType = OOXMLStream::WEBSETTINGS; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml"; + } + else if(gType == sFonttableType || + gType == sFonttableTypeStrict) + { + nType = OOXMLStream::FONTTABLE; + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml"; + } + else + { + bFound = false; + //"Unhandled content-type while grab bagging Glossary Folder"); + } + + if (bFound) + { + uno::Reference xDom; + try + { + gStream = OOXMLDocumentFactory::createStream(pStream, nType); + uno::Reference xInputStream = gStream->getDocumentStream(); + uno::Reference xContext(pStream->getContext()); + uno::Reference xDomBuilder(xml::dom::DocumentBuilder::create(xContext)); + xDom = xDomBuilder->parse(xInputStream); + } + catch (uno::Exception const&) + { + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "importSubStream: exception while " + "parsing stream of Type" << nType); + return; + } + + if (xDom.is()) + { + uno::Sequence< uno::Any > glossaryTuple (5); + glossaryTuple[0] <<= xDom; + glossaryTuple[1] <<= gId; + glossaryTuple[2] <<= gType; + glossaryTuple[3] <<= gTarget; + glossaryTuple[4] <<= contentType; + aGlossaryDomList.push_back(glossaryTuple); + } + } + } + mxGlossaryDomList = comphelper::containerToSequence(aGlossaryDomList); + } +} + +void OOXMLDocumentImpl::resolveEmbeddingsStream(const OOXMLStream::Pointer_t& pStream) +{ + uno::Reference xRelationshipAccess; + xRelationshipAccess.set(dynamic_cast(*pStream).accessDocumentStream(), uno::UNO_QUERY); + if (xRelationshipAccess.is()) + { + OUString const sChartType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"); + OUString const sChartTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/chart"); + OUString const sFootersType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"); + OUString const sFootersTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/footer"); + OUString const sHeaderType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"); + OUString const sHeaderTypeStrict("http://purl.oclc.org/ooxml/officeDocument/relationships/header"); + + bool bFound = false; + bool bHeaderFooterFound = false; + OOXMLStream::StreamType_t streamType = OOXMLStream::UNKNOWN; + const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = xRelationshipAccess->getAllRelationships(); + for (const uno::Sequence< beans::StringPair >& aSeq : aSeqs) + { + for (const beans::StringPair& aPair : aSeq) + { + if (aPair.Second == sChartType || + aPair.Second == sChartTypeStrict) + { + bFound = true; + } + else if(aPair.Second == sFootersType || + aPair.Second == sFootersTypeStrict) + { + bHeaderFooterFound = true; + streamType = OOXMLStream::FOOTER; + } + else if(aPair.Second == sHeaderType || + aPair.Second == sHeaderTypeStrict) + { + bHeaderFooterFound = true; + streamType = OOXMLStream::HEADER; + } + else if(aPair.First == "Target" && ( bFound || bHeaderFooterFound )) + { + // Adding value to extern variable customTarget. It will be used in ooxmlstreamimpl + // to ensure chart.xml target is visited in lcl_getTarget. + customTarget = aPair.Second; + } + } + if( bFound || bHeaderFooterFound) + { + if(bFound) + { + importSubStreamRelations(pStream, OOXMLStream::CHARTS); + } + if(bHeaderFooterFound) + { + try + { + OOXMLStream::Pointer_t Stream = OOXMLDocumentFactory::createStream(pStream, streamType); + if (Stream) + resolveEmbeddingsStream(Stream); + } + catch (uno::Exception const&) + { + TOOLS_INFO_EXCEPTION("writerfilter.ooxml", "resolveEmbeddingsStream: can't find header/footer whilst " + "resolving stream " << streamType); + return; + } + } + + beans::PropertyValue embeddingsTemp; + // This will add all .xlsx and .bin to grabbag list. + if(bFound && mxEmbeddings.is()) + { + embeddingsTemp.Name = embeddingsTarget; + embeddingsTemp.Value <<= mxEmbeddings; + aEmbeddings.push_back(embeddingsTemp); + mxEmbeddings.clear(); + } + bFound = false; + bHeaderFooterFound = false; + } + } + } + if (!aEmbeddings.empty()) + mxEmbeddingsList = comphelper::containerToSequence(aEmbeddings); +} + +uno::Reference OOXMLDocumentImpl::getGlossaryDocDom( ) +{ + return mxGlossaryDocDom; +} + +uno::Sequence > OOXMLDocumentImpl::getGlossaryDomList() +{ + return mxGlossaryDomList; +} + +uno::Reference OOXMLDocumentImpl::getInputStreamForId(const OUString & rId) +{ + OOXMLStream::Pointer_t pStream(OOXMLDocumentFactory::createStream(mpStream, rId)); + + return pStream->getDocumentStream(); +} + +void OOXMLDocumentImpl::setModel(uno::Reference xModel) +{ + mxModel.set(xModel); +} + +uno::Reference OOXMLDocumentImpl::getModel() +{ + return mxModel; +} + +void OOXMLDocumentImpl::setDrawPage(uno::Reference xDrawPage) +{ + mxDrawPage.set(xDrawPage); +} + +uno::Reference OOXMLDocumentImpl::getDrawPage() +{ + return mxDrawPage; +} + +const uno::Sequence& OOXMLDocumentImpl::getMediaDescriptor() const +{ + return maMediaDescriptor; +} + +void OOXMLDocumentImpl::setShapeContext( uno::Reference xContext ) +{ + if (!maShapeContexts.empty()) + maShapeContexts.top() = xContext; +} + +uno::Reference OOXMLDocumentImpl::getShapeContext( ) +{ + if (!maShapeContexts.empty()) + return maShapeContexts.top(); + else + return uno::Reference(); +} + +void OOXMLDocumentImpl::pushShapeContext() +{ + maShapeContexts.push(uno::Reference()); +} + +void OOXMLDocumentImpl::popShapeContext() +{ + if (!maShapeContexts.empty()) + maShapeContexts.pop(); +} + +uno::Reference OOXMLDocumentImpl::getThemeDom( ) +{ + return mxThemeDom; +} + +uno::Sequence > OOXMLDocumentImpl::getCustomXmlDomList( ) +{ + return mxCustomXmlDomList; +} + +uno::Sequence > OOXMLDocumentImpl::getCustomXmlDomPropsList( ) +{ + return mxCustomXmlDomPropsList; +} + +uno::Sequence OOXMLDocumentImpl::getEmbeddingsList( ) +{ + return mxEmbeddingsList; +} + +OOXMLDocument * +OOXMLDocumentFactory::createDocument +(const OOXMLStream::Pointer_t& pStream, + const uno::Reference& xStatusIndicator, + bool mbSkipImages, const uno::Sequence& rDescriptor) +{ + return new OOXMLDocumentImpl(pStream, xStatusIndicator, mbSkipImages, rDescriptor); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx new file mode 100644 index 000000000..b68d524f0 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLDOCUMENTIMPL_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLDOCUMENTIMPL_HXX + +#include + +#include + +#include "OOXMLPropertySet.hxx" + +#include +#include + +namespace writerfilter { +namespace ooxml +{ + +class OOXMLDocumentImpl : public OOXMLDocument +{ + OOXMLStream::Pointer_t mpStream; + css::uno::Reference mxStatusIndicator; + sal_Int32 mnXNoteId; + + css::uno::Reference mxModel; + css::uno::Reference mxDrawPage; + css::uno::Reference mxGlossaryDocDom; + css::uno::Sequence < css::uno::Sequence< css::uno::Any > > mxGlossaryDomList; + /// Stack of shape contexts, 1 element for VML, 1 element / nesting level for drawingML. + std::stack< css::uno::Reference > maShapeContexts; + css::uno::Reference mxThemeDom; + css::uno::Sequence > mxCustomXmlDomList; + css::uno::Sequence > mxCustomXmlDomPropsList; + css::uno::Reference mxCustomXmlProsDom; + css::uno::Reference mxEmbeddings; + css::uno::Sequence < css::beans::PropertyValue > mxEmbeddingsList; + std::vector aEmbeddings; + bool mbIsSubstream; + bool mbSkipImages; + /// How many paragraphs equal to 1 percent? + sal_Int32 mnPercentSize; + /// Position progress when it was last updated, possibly not after every paragraph in case of large documents. + sal_Int32 mnProgressLastPos; + /// Current position progress, updated after every paragraph. + sal_Int32 mnProgressCurrentPos; + /// End position, i.e. the estimated number of paragraphs. + sal_Int32 mnProgressEndPos; + /// DocumentBaseURL + OUString m_rBaseURL; + css::uno::Sequence maMediaDescriptor; + +private: + void resolveFastSubStream(Stream & rStream, + OOXMLStream::StreamType_t nType); + + static void resolveFastSubStreamWithId(Stream & rStream, + const writerfilter::Reference::Pointer_t& pStream, + sal_uInt32 nId); + + css::uno::Reference importSubStream(OOXMLStream::StreamType_t nType); + + void importSubStreamRelations(const OOXMLStream::Pointer_t& pStream, OOXMLStream::StreamType_t nType); + + writerfilter::Reference::Pointer_t + getSubStream(const OUString & rId); + + writerfilter::Reference::Pointer_t + getXNoteStream(OOXMLStream::StreamType_t nType, const sal_Int32 nNoteId); + + void resolveCustomXmlStream(Stream & rStream); + void resolveGlossaryStream(Stream & rStream); + void resolveEmbeddingsStream(const OOXMLStream::Pointer_t& pStream); +public: + OOXMLDocumentImpl(OOXMLStream::Pointer_t const & pStream, const css::uno::Reference& xStatusIndicator, bool bSkipImages, const css::uno::Sequence& rDescriptor); + virtual ~OOXMLDocumentImpl() override; + + virtual void resolve(Stream & rStream) override; + + virtual void resolveFootnote(Stream & rStream, + Id aType, + const sal_Int32 nNoteId) override; + virtual void resolveEndnote(Stream & rStream, + Id aType, + const sal_Int32 nNoteId) override; + virtual void resolveHeader(Stream & rStream, + const sal_Int32 type, + const OUString & rId) override; + virtual void resolveFooter(Stream & rStream, + const sal_Int32 type, + const OUString & rId) override; + + virtual void resolveComment(Stream & rStream, const sal_Int32 nId) override; + + OOXMLPropertySet * getPicturePropSet(const OUString & rId); + virtual void resolvePicture(Stream & rStream, const OUString & rId) override; + + virtual OUString getTargetForId(const OUString & rId) override; + + virtual void setModel(css::uno::Reference xModel) override; + virtual css::uno::Reference getModel() override; + virtual void setDrawPage(css::uno::Reference xDrawPage) override; + virtual css::uno::Reference getDrawPage() override; + virtual css::uno::Reference getInputStreamForId(const OUString & rId) override; + virtual void setXNoteId(const sal_Int32 nId) override; + virtual sal_Int32 getXNoteId() const override; + virtual const OUString & getTarget() const override; + virtual css::uno::Reference getShapeContext( ) override; + virtual void setShapeContext( css::uno::Reference xContext ) override; + void pushShapeContext() override; + void popShapeContext() override; + virtual css::uno::Reference getThemeDom() override; + virtual css::uno::Sequence > getCustomXmlDomList() override; + virtual css::uno::Sequence > getCustomXmlDomPropsList() override; + virtual css::uno::Reference getGlossaryDocDom() override; + virtual css::uno::Sequence > getGlossaryDomList() override; + virtual css::uno::Sequence getEmbeddingsList() override; + + void incrementProgress(); + bool IsSkipImages() const { return mbSkipImages; }; + OUString const& GetDocumentBaseURL() const { return m_rBaseURL; }; + const css::uno::Sequence& getMediaDescriptor() const; +}; +}} +#endif // OOXML_DOCUMENT_IMPL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx new file mode 100644 index 000000000..6bc7a10e8 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -0,0 +1,216 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "OOXMLFactory.hxx" + +namespace writerfilter::ooxml { + +using namespace com::sun::star; + + +OOXMLFactory_ns::~OOXMLFactory_ns() +{ +} + + +void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, + const uno::Reference< xml::sax::XFastAttributeList > & xAttribs) +{ + Id nDefine = pHandler->getDefine(); + OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine); + + if (pFactory.get() == nullptr) + return; + + sax_fastparser::FastAttributeList& rAttribs = + sax_fastparser::castToFastAttributeList( xAttribs ); + + const AttributeInfo *pAttr = pFactory->getAttributeInfoArray(nDefine); + if (!pAttr) + return; + + for (; pAttr->m_nToken != -1; ++pAttr) + { + sal_Int32 nToken = pAttr->m_nToken; + sal_Int32 nAttrIndex = rAttribs.getAttributeIndex(nToken); + if (nAttrIndex == -1) + continue; + + Id nId = pFactory->getResourceId(nDefine, nToken); + + switch (pAttr->m_nResource) + { + case ResourceType::Boolean: + { + const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex); + OOXMLValue::Pointer_t xValue(OOXMLBooleanValue::Create(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::String: + { + OUString aValue(rAttribs.getValueByIndex(nAttrIndex)); + OOXMLValue::Pointer_t xValue(new OOXMLStringValue(aValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::Integer: + { + sal_Int32 nValue = rAttribs.getAsIntegerByIndex(nAttrIndex); + OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::Hex: + { + const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex); + OOXMLValue::Pointer_t xValue(new OOXMLHexValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::HexColor: + { + const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex); + OOXMLValue::Pointer_t xValue(new OOXMLHexColorValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::TwipsMeasure_asSigned: + case ResourceType::TwipsMeasure_asZero: + { + const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex); + OOXMLValue::Pointer_t xValue(new OOXMLTwipsMeasureValue(pValue)); + if ( xValue->getInt() < 0 ) + { + if ( pAttr->m_nResource == ResourceType::TwipsMeasure_asZero ) + xValue = OOXMLIntegerValue::Create(0); + } + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::HpsMeasure: + { + const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex); + OOXMLValue::Pointer_t xValue(new OOXMLHpsMeasureValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::MeasurementOrPercent: + { + const char *pValue = rAttribs.getAsCharByIndex(nAttrIndex); + OOXMLValue::Pointer_t xValue(new OOXMLMeasurementOrPercentValue(pValue)); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + break; + case ResourceType::List: + { + sal_uInt32 nValue; + if (pFactory->getListValue(pAttr->m_nRef, rAttribs.getValueByIndex(nAttrIndex), nValue)) + { + OOXMLValue::Pointer_t xValue = OOXMLIntegerValue::Create(nValue); + pHandler->newProperty(nId, xValue); + pFactory->attributeAction(pHandler, nToken, xValue); + } + } + break; + default: + break; + } + } +} + +uno::Reference< xml::sax::XFastContextHandler> +OOXMLFactory::createFastChildContext(OOXMLFastContextHandler * pHandler, + Token_t Element) +{ + Id nDefine = pHandler->getDefine(); + + OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine); + + uno::Reference< xml::sax::XFastContextHandler> ret; + + //Avoid handling unknown tokens and recursing to death + if ((Element & 0xffff) < oox::XML_TOKEN_COUNT) + ret = createFastChildContextFromFactory(pHandler, pFactory, Element); + + return ret; +} + +void OOXMLFactory::characters(OOXMLFastContextHandler * pHandler, + const OUString & rString) +{ + Id nDefine = pHandler->getDefine(); + OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine); + + if (pFactory.get() != nullptr) + { + pFactory->charactersAction(pHandler, rString); + } +} + +void OOXMLFactory::startAction(OOXMLFastContextHandler * pHandler) +{ + Id nDefine = pHandler->getDefine(); + OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine); + + if (pFactory.get() != nullptr) + { + pFactory->startAction(pHandler); + } +} + +void OOXMLFactory::endAction(OOXMLFastContextHandler * pHandler) +{ + Id nDefine = pHandler->getDefine(); + OOXMLFactory_ns::Pointer_t pFactory = getFactoryForNamespace(nDefine); + + if (pFactory.get() != nullptr) + { + pFactory->endAction(pHandler); + } +} + +void OOXMLFactory_ns::startAction(OOXMLFastContextHandler *) +{ +} + +void OOXMLFactory_ns::endAction(OOXMLFastContextHandler *) +{ +} + +void OOXMLFactory_ns::charactersAction(OOXMLFastContextHandler *, const OUString &) +{ +} + +void OOXMLFactory_ns::attributeAction(OOXMLFastContextHandler *, Token_t, const OOXMLValue::Pointer_t&) +{ +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx new file mode 100644 index 000000000..aa3c981c6 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLFactory.hxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFACTORY_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFACTORY_HXX + +#include + +#include "OOXMLFastContextHandler.hxx" + +namespace writerfilter { +namespace ooxml { + +enum class ResourceType { + NoResource, + Table, + Stream, + List, + Integer, + Properties, + Hex, + HexColor, + String, + Shape, + Boolean, + Value, + XNote, + TextTableCell, + TextTableRow, + TextTable, + PropertyTable, + Math, + Any, + TwipsMeasure_asSigned, + TwipsMeasure_asZero, + HpsMeasure, + MeasurementOrPercent +}; + +struct AttributeInfo +{ + Token_t m_nToken; + ResourceType m_nResource; + Id m_nRef; +}; + +class OOXMLFactory_ns : public virtual SvRefBase { +public: + typedef tools::SvRef Pointer_t; + + virtual void startAction(OOXMLFastContextHandler * pHandler); + virtual void charactersAction(OOXMLFastContextHandler * pHandler, const OUString & rString); + virtual void endAction(OOXMLFastContextHandler * pHandler); + virtual void attributeAction(OOXMLFastContextHandler * pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue); + +protected: + virtual ~OOXMLFactory_ns() override; + +public: + virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0; + virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0; + virtual const AttributeInfo* getAttributeInfoArray(Id nId) = 0; + virtual bool getElementId(Id nDefine, Id nId, ResourceType& rOutResource, Id& rOutElement) = 0; +}; + +class OOXMLFactory +{ +public: + + static css::uno::Reference< css::xml::sax::XFastContextHandler> createFastChildContext(OOXMLFastContextHandler * pHandler, Token_t Element); + + static css::uno::Reference< css::xml::sax::XFastContextHandler> createFastChildContextFromStart(OOXMLFastContextHandler * pHandler, Token_t Element); + + static void attributes(OOXMLFastContextHandler * pHandler, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs); + + static void characters(OOXMLFastContextHandler * pHandler, const OUString & rString); + + static void startAction(OOXMLFastContextHandler * pHandler); + static void endAction(OOXMLFastContextHandler * pHandler); + +private: + OOXMLFactory() = delete; + static OOXMLFactory_ns::Pointer_t getFactoryForNamespace(Id id); + + static css::uno::Reference< css::xml::sax::XFastContextHandler> createFastChildContextFromFactory(OOXMLFastContextHandler * pHandler, OOXMLFactory_ns::Pointer_t pFactory, Token_t Element); +}; + +} +} + +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFACTORY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx new file mode 100644 index 000000000..e425025fb --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -0,0 +1,2191 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "OOXMLFastContextHandler.hxx" +#include "OOXMLFactory.hxx" +#include "Handler.hxx" +#include +#include +#include + +static const sal_Unicode uCR = 0xd; +static const sal_Unicode uFtnEdnRef = 0x2; +static const sal_Unicode uFtnEdnSep = 0x3; +static const sal_Unicode uTab = 0x9; +static const sal_Unicode uPgNum = 0x0; +static const sal_Unicode uNoBreakHyphen = 0x2011; +static const sal_Unicode uSoftHyphen = 0xAD; + +static const sal_uInt8 cFtnEdnCont = 0x4; +static const sal_uInt8 cFieldLock = 0x8; + +namespace writerfilter::ooxml +{ +using namespace ::com::sun::star; +using namespace oox; +using namespace ::std; +using namespace ::com::sun::star::xml::sax; + +/* + class OOXMLFastContextHandler + */ + +OOXMLFastContextHandler::OOXMLFastContextHandler +(uno::Reference< uno::XComponentContext > const & context) +: mpParent(nullptr), + mId(0), + mnDefine(0), + mnToken(oox::XML_TOKEN_COUNT), + mnMathJcVal(0), + mbIsMathPara(false), + mpStream(nullptr), + mnTableDepth(0), + inPositionV(false), + mbAllowInCell(true), + mbIsVMLfound(false), + m_xContext(context), + m_bDiscardChildren(false), + m_bTookChoice(false) +{ + if (mpParserState.get() == nullptr) + mpParserState = new OOXMLParserState(); + + mpParserState->incContextCount(); +} + +OOXMLFastContextHandler::OOXMLFastContextHandler(OOXMLFastContextHandler * pContext) +: cppu::WeakImplHelper(), + mpParent(pContext), + mId(0), + mnDefine(0), + mnToken(oox::XML_TOKEN_COUNT), + mnMathJcVal(pContext->mnMathJcVal), + mbIsMathPara(pContext->mbIsMathPara), + mpStream(pContext->mpStream), + mpParserState(pContext->mpParserState), + mnTableDepth(pContext->mnTableDepth), + inPositionV(pContext->inPositionV), + mbAllowInCell(pContext->mbAllowInCell), + mbIsVMLfound(pContext->mbIsVMLfound), + m_xContext(pContext->m_xContext), + m_bDiscardChildren(pContext->m_bDiscardChildren), + m_bTookChoice(pContext->m_bTookChoice) +{ + if (mpParserState.get() == nullptr) + mpParserState = new OOXMLParserState(); + + mpParserState->incContextCount(); +} + +OOXMLFastContextHandler::~OOXMLFastContextHandler() +{ +} + +bool OOXMLFastContextHandler::prepareMceContext(Token_t nElement, const uno::Reference& rAttribs) +{ + switch (oox::getBaseToken(nElement)) + { + case XML_AlternateContent: + { + SavedAlternateState aState; + aState.m_bDiscardChildren = m_bDiscardChildren; + m_bDiscardChildren = false; + aState.m_bTookChoice = m_bTookChoice; + m_bTookChoice = false; + mpParserState->getSavedAlternateStates().push_back(aState); + } + break; + case XML_Choice: + { + OUString aRequires = rAttribs->getOptionalValue(XML_Requires); + static const char* aFeatures[] = { + "wps", + "wpg", + "w14", + }; + for (const char *p : aFeatures) + { + if (aRequires.equalsAscii(p)) + { + m_bTookChoice = true; + return false; + } + } + return true; + } + break; + case XML_Fallback: + // If Choice is already taken, then let's ignore the Fallback. + return m_bTookChoice; + break; + default: + SAL_WARN("writerfilter", "OOXMLFastContextHandler::prepareMceContext: unhandled element:" << oox::getBaseToken(nElement)); + break; + } + return false; +} + +// xml::sax::XFastContextHandler: +void SAL_CALL OOXMLFastContextHandler::startFastElement +(sal_Int32 Element, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + // Set xml:space value early, to allow child contexts use it when dealing with strings. + if (Attribs && Attribs->hasAttribute(oox::NMSP_xml | oox::XML_space)) + { + mbPreserveSpace = Attribs->getValue(oox::NMSP_xml | oox::XML_space) == "preserve"; + mbPreserveSpaceSet = true; + } + if (Element == (NMSP_officeMath | XML_oMathPara)) + { + mnMathJcVal = eMathParaJc::CENTER; + mbIsMathPara = true; + } + if (Element == (NMSP_officeMath | XML_jc) && mpParent && mpParent->mpParent ) + { + mbIsMathPara = true; + auto aAttrLst = Attribs->getFastAttributes(); + if (aAttrLst[0].Value == "center") mpParent->mpParent->mnMathJcVal = eMathParaJc::CENTER; + if (aAttrLst[0].Value == "left") mpParent->mpParent->mnMathJcVal = eMathParaJc::LEFT; + if (aAttrLst[0].Value == "right") mpParent->mpParent->mnMathJcVal = eMathParaJc::RIGHT; + } + + if (oox::getNamespace(Element) == NMSP_mce) + m_bDiscardChildren = prepareMceContext(Element, Attribs); + + else if (!m_bDiscardChildren) + { + attributes(Attribs); + lcl_startFastElement(Element, Attribs); + } +} + +void SAL_CALL OOXMLFastContextHandler::startUnknownElement +(const OUString & /*Namespace*/, const OUString & /*Name*/, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ +} + +void SAL_CALL OOXMLFastContextHandler::endFastElement(sal_Int32 Element) +{ + if (Element == (NMSP_mce | XML_Choice) || Element == (NMSP_mce | XML_Fallback)) + m_bDiscardChildren = false; + else if (Element == (NMSP_mce | XML_AlternateContent)) + { + SavedAlternateState aState(mpParserState->getSavedAlternateStates().back()); + mpParserState->getSavedAlternateStates().pop_back(); + m_bDiscardChildren = aState.m_bDiscardChildren; + m_bTookChoice = aState.m_bTookChoice; + } + else if (!m_bDiscardChildren) + lcl_endFastElement(Element); +} + +void OOXMLFastContextHandler::lcl_startFastElement +(Token_t Element, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ + OOXMLFactory::startAction(this); + if( Element == (NMSP_dmlWordDr|XML_positionV) ) + inPositionV = true; + else if( Element == (NMSP_dmlWordDr|XML_positionH) ) + inPositionV = false; + +} + +void OOXMLFastContextHandler::lcl_endFastElement +(Token_t /*Element*/) +{ + OOXMLFactory::endAction(this); +} + +void SAL_CALL OOXMLFastContextHandler::endUnknownElement +(const OUString & , const OUString & ) +{ +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL + OOXMLFastContextHandler::createFastChildContext +(sal_Int32 Element, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + uno::Reference< xml::sax::XFastContextHandler > xResult; + if (oox::getNamespace(Element) != NMSP_mce && !m_bDiscardChildren) + xResult.set(lcl_createFastChildContext(Element, Attribs)); + else if (oox::getNamespace(Element) == NMSP_mce) + xResult = this; + + return xResult; +} + +uno::Reference< xml::sax::XFastContextHandler > + OOXMLFastContextHandler::lcl_createFastChildContext +(Token_t Element, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ + return OOXMLFactory::createFastChildContext(this, Element); +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL +OOXMLFastContextHandler::createUnknownChildContext +(const OUString &, + const OUString &, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ + return uno::Reference< xml::sax::XFastContextHandler > + (new OOXMLFastContextHandler(*const_cast(this))); +} + +void SAL_CALL OOXMLFastContextHandler::characters +(const OUString & aChars) +{ + lcl_characters(aChars); +} + +void OOXMLFastContextHandler::lcl_characters +(const OUString & rString) +{ + if (!m_bDiscardChildren) + OOXMLFactory::characters(this, rString); +} + +void OOXMLFastContextHandler::setStream(Stream * pStream) +{ + mpStream = pStream; +} + +OOXMLValue::Pointer_t OOXMLFastContextHandler::getValue() const +{ + return OOXMLValue::Pointer_t(); +} + +void OOXMLFastContextHandler::attributes +(const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + OOXMLFactory::attributes(this, Attribs); +} + +void OOXMLFastContextHandler::startAction() +{ + OOXMLFactory::startAction(this); +} + +void OOXMLFastContextHandler::endAction() +{ + OOXMLFactory::endAction(this); +} + +void OOXMLFastContextHandler::setId(Id rId) +{ + mId = rId; +} + +Id OOXMLFastContextHandler::getId() const +{ + return mId; +} + +void OOXMLFastContextHandler::setDefine(Id nDefine) +{ + mnDefine = nDefine; +} + + +void OOXMLFastContextHandler::setToken(Token_t nToken) +{ + mnToken = nToken; +} + +Token_t OOXMLFastContextHandler::getToken() const +{ + return mnToken; +} + +void OOXMLFastContextHandler::sendTableDepth() const +{ + if (mnTableDepth > 0) + { + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); + } + + mpStream->props(pProps.get()); + } +} + +void OOXMLFastContextHandler::setHandle() +{ + mpParserState->setHandle(); + mpStream->info(mpParserState->getHandle()); +} + +void OOXMLFastContextHandler::startCharacterGroup() +{ + if (isForwardEvents()) + { + if (mpParserState->isInCharacterGroup()) + endCharacterGroup(); + + if (! mpParserState->isInParagraphGroup()) + startParagraphGroup(); + + if (! mpParserState->isInCharacterGroup()) + { + mpStream->startCharacterGroup(); + mpParserState->setInCharacterGroup(true); + mpParserState->resolveCharacterProperties(*mpStream); + } + + // tdf#108714 : if we have a postponed break information, + // then apply it now, before any other paragraph content. + mpParserState->resolvePostponedBreak(*mpStream); + } +} + +void OOXMLFastContextHandler::endCharacterGroup() +{ + if (isForwardEvents() && mpParserState->isInCharacterGroup()) + { + mpStream->endCharacterGroup(); + mpParserState->setInCharacterGroup(false); + } +} + +void OOXMLFastContextHandler::pushBiDiEmbedLevel() {} + +void OOXMLFastContextHandler::popBiDiEmbedLevel() {} + +void OOXMLFastContextHandler::startParagraphGroup() +{ + if (isForwardEvents()) + { + if (mpParserState->isInParagraphGroup()) + endParagraphGroup(); + + if (! mpParserState->isInSectionGroup()) + startSectionGroup(); + + if (! mpParserState->isInParagraphGroup()) + { + mpStream->startParagraphGroup(); + mpParserState->setInParagraphGroup(true); + } + } +} + +void OOXMLFastContextHandler::endParagraphGroup() +{ + if (isForwardEvents()) + { + if (mpParserState->isInCharacterGroup()) + endCharacterGroup(); + + if (mpParserState->isInParagraphGroup()) + { + mpStream->endParagraphGroup(); + mpParserState->setInParagraphGroup(false); + } + } +} + +void OOXMLFastContextHandler::startSdt() +{ + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_CT_SdtBlock_sdtContent, pVal, OOXMLProperty::ATTRIBUTE); + mpStream->props(pProps.get()); +} + +void OOXMLFastContextHandler::endSdt() +{ + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_CT_SdtBlock_sdtEndContent, pVal, OOXMLProperty::ATTRIBUTE); + mpStream->props(pProps.get()); +} + +void OOXMLFastContextHandler::startSectionGroup() +{ + if (isForwardEvents()) + { + if (mpParserState->isInSectionGroup()) + endSectionGroup(); + + if (! mpParserState->isInSectionGroup()) + { + mpStream->info(mpParserState->getHandle()); + mpStream->startSectionGroup(); + mpParserState->setInSectionGroup(true); + } + } +} + +void OOXMLFastContextHandler::endSectionGroup() +{ + if (isForwardEvents()) + { + if (mpParserState->isInParagraphGroup()) + endParagraphGroup(); + + if (mpParserState->isInSectionGroup()) + { + mpStream->endSectionGroup(); + mpParserState->setInSectionGroup(false); + } + } +} + +void OOXMLFastContextHandler::setLastParagraphInSection() +{ + mpParserState->setLastParagraphInSection(true); + mpStream->markLastParagraphInSection( ); +} + +void OOXMLFastContextHandler::setLastSectionGroup() +{ + mpStream->markLastSectionGroup( ); +} + +void OOXMLFastContextHandler::newProperty +(Id /*nId*/, const OOXMLValue::Pointer_t& /*pVal*/) +{ +} + +void OOXMLFastContextHandler::setPropertySet +(const OOXMLPropertySet::Pointer_t& /* pPropertySet */) +{ +} + +OOXMLPropertySet::Pointer_t OOXMLFastContextHandler::getPropertySet() const +{ + return OOXMLPropertySet::Pointer_t(); +} + +void OOXMLFastContextHandler::startField() +{ + startCharacterGroup(); + if (isForwardEvents()) + mpStream->text(&cFieldStart, 1); + endCharacterGroup(); +} + +void OOXMLFastContextHandler::fieldSeparator() +{ + startCharacterGroup(); + if (isForwardEvents()) + mpStream->text(&cFieldSep, 1); + endCharacterGroup(); +} + +void OOXMLFastContextHandler::endField() +{ + startCharacterGroup(); + if (isForwardEvents()) + mpStream->text(&cFieldEnd, 1); + endCharacterGroup(); +} + +void OOXMLFastContextHandler::lockField() +{ + startCharacterGroup(); + if (isForwardEvents()) + mpStream->text(&cFieldLock, 1); + endCharacterGroup(); +} + +void OOXMLFastContextHandler::ftnednref() +{ + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uFtnEdnRef), 1); +} + +void OOXMLFastContextHandler::ftnednsep() +{ + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uFtnEdnSep), 1); +} + +void OOXMLFastContextHandler::ftnedncont() +{ + if (isForwardEvents()) + mpStream->text(&cFtnEdnCont, 1); +} + +void OOXMLFastContextHandler::pgNum() +{ + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uPgNum), 1); +} + +void OOXMLFastContextHandler::tab() +{ + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uTab), 1); +} + +void OOXMLFastContextHandler::symbol() +{ + if (isForwardEvents()) + sendPropertiesWithId(NS_ooxml::LN_EG_RunInnerContent_sym); +} + +void OOXMLFastContextHandler::cr() +{ + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uCR), 1); +} + +void OOXMLFastContextHandler::noBreakHyphen() +{ + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uNoBreakHyphen), 1); +} + +void OOXMLFastContextHandler::softHyphen() +{ + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uSoftHyphen), 1); +} + +void OOXMLFastContextHandler::handleLastParagraphInSection() +{ + if (mpParserState->isLastParagraphInSection()) + { + mpParserState->setLastParagraphInSection(false); + startSectionGroup(); + } +} + +void OOXMLFastContextHandler::endOfParagraph() +{ + if (! mpParserState->isInCharacterGroup()) + startCharacterGroup(); + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uCR), 1); + + mpParserState->getDocument()->incrementProgress(); +} + +void OOXMLFastContextHandler::startTxbxContent() +{ +/* + This usually means there are recursive elements, and the ones + inside and outside of w:txbxContent should not interfere (e.g. + the lastParagraphInSection setting). So save the whole state + and possibly start new groups for the nested content (not section + group though, as that'd cause the txbxContent to be moved onto + another page, I'm not sure how that should work exactly). +*/ + mpParserState->startTxbxContent(); + startParagraphGroup(); +} + +void OOXMLFastContextHandler::endTxbxContent() +{ + endParagraphGroup(); + mpParserState->endTxbxContent(); +} + +namespace { +// XML schema defines white space as one of four characters: +// #x9 (tab), #xA (line feed), #xD (carriage return), and #x20 (space) +bool IsXMLWhitespace(sal_Unicode cChar) +{ + return cChar == 0x9 || cChar == 0xA || cChar == 0xD || cChar == 0x20; +} + +OUString TrimXMLWhitespace(const OUString & sText) +{ + sal_Int32 nTrimmedStart = 0; + const sal_Int32 nLen = sText.getLength(); + sal_Int32 nTrimmedEnd = nLen - 1; + while (nTrimmedStart < nLen && IsXMLWhitespace(sText[nTrimmedStart])) + ++nTrimmedStart; + while (nTrimmedStart <= nTrimmedEnd && IsXMLWhitespace(sText[nTrimmedEnd])) + --nTrimmedEnd; + if ((nTrimmedStart == 0) && (nTrimmedEnd == nLen - 1)) + return sText; + else if (nTrimmedStart > nTrimmedEnd) + return OUString(); + else + return sText.copy(nTrimmedStart, nTrimmedEnd-nTrimmedStart+1); +} +} + +void OOXMLFastContextHandler::text(const OUString & sText) +{ + if (isForwardEvents()) + { + // tdf#108806: CRLFs in XML were converted to \n before this point. + // These must be converted to spaces before further processing. + OUString sNormalizedText = sText.replaceAll("\n", " "); + // tdf#108995: by default, leading and trailing white space is ignored; + // tabs are converted to spaces + if (!IsPreserveSpace()) + { + sNormalizedText = TrimXMLWhitespace(sNormalizedText).replaceAll("\t", " "); + } + mpStream->utext(reinterpret_cast < const sal_uInt8 * > + (sNormalizedText.getStr()), + sNormalizedText.getLength()); + } +} + +void OOXMLFastContextHandler::positionOffset(const OUString& rText) +{ + if (isForwardEvents()) + mpStream->positionOffset(rText, inPositionV); +} + +void OOXMLFastContextHandler::ignore() +{ +} + +void OOXMLFastContextHandler::alignH(const OUString& rText) +{ + if (isForwardEvents()) + mpStream->align(rText, /*bVertical=*/false); +} + +void OOXMLFastContextHandler::alignV(const OUString& rText) +{ + if (isForwardEvents()) + mpStream->align(rText, /*bVertical=*/true); +} + +void OOXMLFastContextHandler::positivePercentage(const OUString& rText) +{ + if (isForwardEvents()) + mpStream->positivePercentage(rText); +} + +void OOXMLFastContextHandler::startGlossaryEntry() +{ + if (isForwardEvents()) + mpStream->startGlossaryEntry(); +} + +void OOXMLFastContextHandler::endGlossaryEntry() +{ + if (isForwardEvents()) + mpStream->endGlossaryEntry(); +} + +void OOXMLFastContextHandler::propagateCharacterProperties() +{ + mpParserState->setCharacterProperties(getPropertySet()); +} + +void OOXMLFastContextHandler::propagateCellProperties() +{ + mpParserState->setCellProperties(getPropertySet()); +} + +void OOXMLFastContextHandler::propagateRowProperties() +{ + mpParserState->setRowProperties(getPropertySet()); +} + +void OOXMLFastContextHandler::propagateTableProperties() +{ + OOXMLPropertySet::Pointer_t pProps = getPropertySet(); + + mpParserState->setTableProperties(pProps); +} + +void OOXMLFastContextHandler::sendCellProperties() +{ + mpParserState->resolveCellProperties(*mpStream); +} + +void OOXMLFastContextHandler::sendRowProperties() +{ + mpParserState->resolveRowProperties(*mpStream); +} + +void OOXMLFastContextHandler::sendTableProperties() +{ + mpParserState->resolveTableProperties(*mpStream); +} + +void OOXMLFastContextHandler::clearTableProps() +{ + mpParserState->setTableProperties(new OOXMLPropertySet()); +} + +void OOXMLFastContextHandler::sendPropertiesWithId(Id nId) +{ + OOXMLValue::Pointer_t pValue(new OOXMLPropertySetValue(getPropertySet())); + OOXMLPropertySet::Pointer_t pPropertySet(new OOXMLPropertySet); + + pPropertySet->add(nId, pValue, OOXMLProperty::SPRM); + mpStream->props(pPropertySet.get()); +} + +void OOXMLFastContextHandler::clearProps() +{ + setPropertySet(new OOXMLPropertySet()); +} + +void OOXMLFastContextHandler::setDefaultBooleanValue() +{ +} + +void OOXMLFastContextHandler::setDefaultIntegerValue() +{ +} + +void OOXMLFastContextHandler::setDefaultHexValue() +{ +} + +void OOXMLFastContextHandler::setDefaultStringValue() +{ +} + +void OOXMLFastContextHandler::setDocument(OOXMLDocumentImpl* pDocument) +{ + mpParserState->setDocument(pDocument); +} + +OOXMLDocumentImpl* OOXMLFastContextHandler::getDocument() +{ + return mpParserState->getDocument(); +} + +void OOXMLFastContextHandler::setForwardEvents(bool bForwardEvents) +{ + mpParserState->setForwardEvents(bForwardEvents); +} + +bool OOXMLFastContextHandler::isForwardEvents() const +{ + return mpParserState->isForwardEvents(); +} + +void OOXMLFastContextHandler::setXNoteId(const sal_Int32 nId) +{ + mpParserState->setXNoteId(nId); +} + +void OOXMLFastContextHandler::setXNoteId(const OOXMLValue::Pointer_t& pValue) +{ + mpParserState->setXNoteId(sal_Int32(pValue->getInt())); +} + +sal_Int32 OOXMLFastContextHandler::getXNoteId() const +{ + return mpParserState->getXNoteId(); +} + +void OOXMLFastContextHandler::resolveFootnote +(const sal_Int32 nId) +{ + mpParserState->getDocument()->resolveFootnote + (*mpStream, 0, nId); +} + +void OOXMLFastContextHandler::resolveEndnote(const sal_Int32 nId) +{ + mpParserState->getDocument()->resolveEndnote + (*mpStream, 0, nId); +} + +void OOXMLFastContextHandler::resolveComment(const sal_Int32 nId) +{ + mpParserState->getDocument()->resolveComment(*mpStream, nId); +} + +void OOXMLFastContextHandler::resolvePicture(const OUString & rId) +{ + mpParserState->getDocument()->resolvePicture(*mpStream, rId); +} + +void OOXMLFastContextHandler::resolveHeader +(const sal_Int32 type, const OUString & rId) +{ + mpParserState->getDocument()->resolveHeader(*mpStream, type, rId); +} + +void OOXMLFastContextHandler::resolveFooter +(const sal_Int32 type, const OUString & rId) +{ + mpParserState->getDocument()->resolveFooter(*mpStream, type, rId); +} + +// Add the data pointed to by the reference as another property. +void OOXMLFastContextHandler::resolveData(const OUString & rId) +{ + OOXMLDocument * objDocument = getDocument(); + SAL_WARN_IF(!objDocument, "writerfilter", "no document to resolveData"); + if (!objDocument) + return; + + uno::Reference xInputStream + (objDocument->getInputStreamForId(rId)); + + OOXMLValue::Pointer_t aValue(new OOXMLInputStreamValue(xInputStream)); + + newProperty(NS_ooxml::LN_inputstream, aValue); +} + +OUString OOXMLFastContextHandler::getTargetForId +(const OUString & rId) +{ + return mpParserState->getDocument()->getTargetForId(rId); +} + +void OOXMLFastContextHandler::sendPropertyToParent() +{ + if (mpParent != nullptr) + { + OOXMLPropertySet::Pointer_t pProps(mpParent->getPropertySet()); + + if (pProps.get() != nullptr) + { + pProps->add(mId, getValue(), OOXMLProperty::SPRM); + } + } +} + +void OOXMLFastContextHandler::sendPropertiesToParent() +{ + if (mpParent != nullptr) + { + OOXMLPropertySet::Pointer_t pParentProps(mpParent->getPropertySet()); + + if (pParentProps.get() != nullptr) + { + OOXMLPropertySet::Pointer_t pProps(getPropertySet()); + + if (pProps.get() != nullptr) + { + OOXMLValue::Pointer_t pValue + (new OOXMLPropertySetValue(getPropertySet())); + + pParentProps->add(getId(), pValue, OOXMLProperty::SPRM); + + } + } + } +} + +bool OOXMLFastContextHandler::IsPreserveSpace() const +{ + // xml:space attribute applies to all elements within the content of the element where it is specified, + // unless overridden with another instance of the xml:space attribute + if (mbPreserveSpaceSet) + return mbPreserveSpace; + if (mpParent) + return mpParent->IsPreserveSpace(); + return false; // default value +} + +/* + class OOXMLFastContextHandlerStream + */ + +OOXMLFastContextHandlerStream::OOXMLFastContextHandlerStream +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandler(pContext), + mpPropertySetAttrs(new OOXMLPropertySet) +{ +} + +OOXMLFastContextHandlerStream::~OOXMLFastContextHandlerStream() +{ +} + +void OOXMLFastContextHandlerStream::newProperty(Id nId, + const OOXMLValue::Pointer_t& pVal) +{ + if (nId != 0x0) + { + mpPropertySetAttrs->add(nId, pVal, OOXMLProperty::ATTRIBUTE); + } +} + +void OOXMLFastContextHandlerStream::sendProperty(Id nId) +{ + OOXMLPropertySetEntryToString aHandler(nId); + getPropertySetAttrs()->resolve(aHandler); + const OUString & sText = aHandler.getString(); + mpStream->utext(reinterpret_cast < const sal_uInt8 * > + (sText.getStr()), + sText.getLength()); +} + + +OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerStream::getPropertySet() + const +{ + return getPropertySetAttrs(); +} + +void OOXMLFastContextHandlerStream::handleHyperlink() +{ + OOXMLHyperlinkHandler aHyperlinkHandler(this); + getPropertySetAttrs()->resolve(aHyperlinkHandler); + aHyperlinkHandler.writetext(); +} + +/* + class OOXMLFastContextHandlerProperties + */ +OOXMLFastContextHandlerProperties::OOXMLFastContextHandlerProperties +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandler(pContext), mpPropertySet(new OOXMLPropertySet), + mbResolve(false) +{ + if (pContext->getResource() == STREAM) + mbResolve = true; +} + +OOXMLFastContextHandlerProperties::~OOXMLFastContextHandlerProperties() +{ +} + +void OOXMLFastContextHandlerProperties::lcl_endFastElement +(Token_t /*Element*/) +{ + try + { + endAction(); + + if (mbResolve) + { + if (isForwardEvents()) + { + mpStream->props(mpPropertySet.get()); + } + } + else + { + sendPropertiesToParent(); + } + } + catch (const uno::RuntimeException&) + { + throw; + } + catch (const xml::sax::SAXException&) + { + throw; + } + catch (const uno::Exception& e) + { + auto a = cppu::getCaughtException(); + throw lang::WrappedTargetRuntimeException(e.Message, e.Context, a); + } +} + +OOXMLValue::Pointer_t OOXMLFastContextHandlerProperties::getValue() const +{ + return OOXMLValue::Pointer_t(new OOXMLPropertySetValue(mpPropertySet)); +} + +void OOXMLFastContextHandlerProperties::newProperty +(Id nId, const OOXMLValue::Pointer_t& pVal) +{ + if (nId != 0x0) + { + mpPropertySet->add(nId, pVal, OOXMLProperty::ATTRIBUTE); + } +} + +void OOXMLFastContextHandlerProperties::handleXNotes() +{ + switch (mnToken) + { + case W_TOKEN(footnoteReference): + { + OOXMLFootnoteHandler aFootnoteHandler(this); + mpPropertySet->resolve(aFootnoteHandler); + } + break; + case W_TOKEN(endnoteReference): + { + OOXMLEndnoteHandler aEndnoteHandler(this); + mpPropertySet->resolve(aEndnoteHandler); + } + break; + default: + break; + } +} + +void OOXMLFastContextHandlerProperties::handleHdrFtr() +{ + switch (mnToken) + { + case W_TOKEN(footerReference): + { + OOXMLFooterHandler aFooterHandler(this); + mpPropertySet->resolve(aFooterHandler); + aFooterHandler.finalize(); + } + break; + case W_TOKEN(headerReference): + { + OOXMLHeaderHandler aHeaderHandler(this); + mpPropertySet->resolve(aHeaderHandler); + aHeaderHandler.finalize(); + } + break; + default: + break; + } +} + +void OOXMLFastContextHandlerProperties::handleComment() +{ + OOXMLCommentHandler aCommentHandler(this); + getPropertySet()->resolve(aCommentHandler); +} + +void OOXMLFastContextHandlerProperties::handlePicture() +{ + OOXMLPictureHandler aPictureHandler(this); + getPropertySet()->resolve(aPictureHandler); +} + +void OOXMLFastContextHandlerProperties::handleBreak() +{ + if(isForwardEvents()) + { + OOXMLBreakHandler aBreakHandler(*mpStream); + getPropertySet()->resolve(aBreakHandler); + } +} + +// tdf#108714 : allow at block level (despite this is illegal according to ECMA-376-1:2016) +void OOXMLFastContextHandlerProperties::handleOutOfOrderBreak() +{ + if(isForwardEvents()) + { + mpParserState->setPostponedBreak(getPropertySet()); + } +} + +void OOXMLFastContextHandlerProperties::handleOLE() +{ + OOXMLOLEHandler aOLEHandler(this); + getPropertySet()->resolve(aOLEHandler); +} + +void OOXMLFastContextHandlerProperties::handleFontRel() +{ + OOXMLEmbeddedFontHandler handler(this); + getPropertySet()->resolve(handler); +} + +void OOXMLFastContextHandlerProperties::handleHyperlinkURL() { + OOXMLHyperlinkURLHandler aHyperlinkURLHandler(this); + getPropertySet()->resolve(aHyperlinkURLHandler); +} + +void OOXMLFastContextHandlerProperties::setPropertySet +(const OOXMLPropertySet::Pointer_t& pPropertySet) +{ + if (pPropertySet.get() != nullptr) + mpPropertySet = pPropertySet; +} + +OOXMLPropertySet::Pointer_t +OOXMLFastContextHandlerProperties::getPropertySet() const +{ + return mpPropertySet; +} + +/* + * class OOXMLFasContextHandlerPropertyTable + */ + +OOXMLFastContextHandlerPropertyTable::OOXMLFastContextHandlerPropertyTable +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandlerProperties(pContext) +{ +} + +OOXMLFastContextHandlerPropertyTable::~OOXMLFastContextHandlerPropertyTable() +{ +} + +void OOXMLFastContextHandlerPropertyTable::lcl_endFastElement +(Token_t /*Element*/) +{ + OOXMLPropertySet::Pointer_t pPropSet(mpPropertySet->clone()); + OOXMLTable::ValuePointer_t pTmpVal + (new OOXMLPropertySetValue(pPropSet)); + + mTable.add(pTmpVal); + + writerfilter::Reference
::Pointer_t pTable(mTable.clone()); + + mpStream->table(mId, pTable); + + endAction(); +} + +/* + class OOXMLFastContextHandlerValue +*/ + +OOXMLFastContextHandlerValue::OOXMLFastContextHandlerValue +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandler(pContext) +{ +} + +OOXMLFastContextHandlerValue::~OOXMLFastContextHandlerValue() +{ +} + +void OOXMLFastContextHandlerValue::setValue(const OOXMLValue::Pointer_t& pValue) +{ + mpValue = pValue; +} + +OOXMLValue::Pointer_t OOXMLFastContextHandlerValue::getValue() const +{ + return mpValue; +} + +void OOXMLFastContextHandlerValue::lcl_endFastElement +(Token_t /*Element*/) +{ + sendPropertyToParent(); + + endAction(); +} + +void OOXMLFastContextHandlerValue::setDefaultBooleanValue() +{ + if (mpValue.get() == nullptr) + { + OOXMLValue::Pointer_t pValue = OOXMLBooleanValue::Create(true); + setValue(pValue); + } +} + +void OOXMLFastContextHandlerValue::setDefaultIntegerValue() +{ + if (mpValue.get() == nullptr) + { + OOXMLValue::Pointer_t pValue = OOXMLIntegerValue::Create(0); + setValue(pValue); + } +} + +void OOXMLFastContextHandlerValue::setDefaultHexValue() +{ + if (mpValue.get() == nullptr) + { + OOXMLValue::Pointer_t pValue(new OOXMLHexValue(sal_uInt32(0))); + setValue(pValue); + } +} + +void OOXMLFastContextHandlerValue::setDefaultStringValue() +{ + if (mpValue.get() == nullptr) + { + OOXMLValue::Pointer_t pValue(new OOXMLStringValue(OUString())); + setValue(pValue); + } +} + +// ECMA-376-1:2016 17.3.2.8; https://www.unicode.org/reports/tr9/#Explicit_Directional_Embeddings +void OOXMLFastContextHandlerValue::pushBiDiEmbedLevel() +{ + const bool bRtl + = mpValue && mpValue->getInt() == NS_ooxml::LN_Value_ST_Direction_rtl; + OOXMLFactory::characters(this, bRtl ? u"\u202B" : u"\u202A"); // RLE / LRE +} + +void OOXMLFastContextHandlerValue::popBiDiEmbedLevel() +{ + OOXMLFactory::characters(this, u"\u202C"); // PDF (POP DIRECTIONAL FORMATTING) +} + +/* + class OOXMLFastContextHandlerTable +*/ + +OOXMLFastContextHandlerTable::OOXMLFastContextHandlerTable +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandler(pContext) +{ +} + +OOXMLFastContextHandlerTable::~OOXMLFastContextHandlerTable() +{ +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL +OOXMLFastContextHandlerTable::createFastChildContext +(sal_Int32 Element, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + addCurrentChild(); + + mCurrentChild.set(OOXMLFastContextHandler::createFastChildContext(Element, Attribs)); + + return mCurrentChild; +} + +void OOXMLFastContextHandlerTable::lcl_endFastElement +(Token_t /*Element*/) +{ + addCurrentChild(); + + writerfilter::Reference
::Pointer_t pTable(mTable.clone()); + if (isForwardEvents() && mId != 0x0) + { + mpStream->table(mId, pTable); + } +} + +void OOXMLFastContextHandlerTable::addCurrentChild() +{ + OOXMLFastContextHandler * pHandler = dynamic_cast(mCurrentChild.get()); + if (pHandler != nullptr) + { + OOXMLValue::Pointer_t pValue(pHandler->getValue()); + + if (pValue.get() != nullptr) + { + OOXMLTable::ValuePointer_t pTmpVal(pValue->clone()); + mTable.add(pTmpVal); + } + } +} + +/* + class OOXMLFastContextHandlerXNote + */ + +OOXMLFastContextHandlerXNote::OOXMLFastContextHandlerXNote + (OOXMLFastContextHandler * pContext) + : OOXMLFastContextHandlerProperties(pContext) + , mbForwardEventsSaved(false) + , mnMyXNoteId(0) + , mnMyXNoteType(0) +{ +} + +OOXMLFastContextHandlerXNote::~OOXMLFastContextHandlerXNote() +{ +} + +void OOXMLFastContextHandlerXNote::lcl_startFastElement +(Token_t /*Element*/, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ + mbForwardEventsSaved = isForwardEvents(); + + // If this is the note we're looking for or this is the footnote separator one. + if (mnMyXNoteId == getXNoteId() || static_cast(mnMyXNoteType) == NS_ooxml::LN_Value_doc_ST_FtnEdn_separator) + setForwardEvents(true); + else + setForwardEvents(false); + + startAction(); +} + +void OOXMLFastContextHandlerXNote::lcl_endFastElement +(Token_t Element) +{ + endAction(); + + OOXMLFastContextHandlerProperties::lcl_endFastElement(Element); + + setForwardEvents(mbForwardEventsSaved); +} + +void OOXMLFastContextHandlerXNote::checkId(const OOXMLValue::Pointer_t& pValue) +{ + mnMyXNoteId = sal_Int32(pValue->getInt()); +} + +void OOXMLFastContextHandlerXNote::checkType(const OOXMLValue::Pointer_t& pValue) +{ + mnMyXNoteType = pValue->getInt(); +} + +/* + class OOXMLFastContextHandlerTextTableCell + */ + +OOXMLFastContextHandlerTextTableCell::OOXMLFastContextHandlerTextTableCell +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandler(pContext) +{ +} + +OOXMLFastContextHandlerTextTableCell::~OOXMLFastContextHandlerTextTableCell() +{ +} + +void OOXMLFastContextHandlerTextTableCell::startCell() +{ + if (isForwardEvents()) + { + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + { + OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + pProps->add(NS_ooxml::LN_tcStart, pVal, OOXMLProperty::SPRM); + } + + mpStream->props(pProps.get()); + } +} + +void OOXMLFastContextHandlerTextTableCell::endCell() +{ + if (isForwardEvents()) + { + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + pProps->add(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + pProps->add(NS_ooxml::LN_tcEnd, pVal, OOXMLProperty::SPRM); + } + + mpStream->props(pProps.get()); + } +} + +/* + class OOXMLFastContextHandlerTextTableRow + */ + +OOXMLFastContextHandlerTextTableRow::OOXMLFastContextHandlerTextTableRow +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandler(pContext) +{ +} + +OOXMLFastContextHandlerTextTableRow::~OOXMLFastContextHandlerTextTableRow() +{ +} + +void OOXMLFastContextHandlerTextTableRow::startRow() +{ +} + +void OOXMLFastContextHandlerTextTableRow::endRow() +{ + if (mpGridAfter) + { + // Grid after is the same as grid before, the empty cells are just + // inserted after the real ones, not before. + handleGridBefore(mpGridAfter); + mpGridAfter = nullptr; + } + + startParagraphGroup(); + + if (isForwardEvents()) + { + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_tblRow, pVal, OOXMLProperty::SPRM); + } + + mpStream->props(pProps.get()); + } + + startCharacterGroup(); + + if (isForwardEvents()) + mpStream->utext(reinterpret_cast(&uCR), 1); + + endCharacterGroup(); + endParagraphGroup(); +} + +void OOXMLFastContextHandlerTextTableRow::handleGridAfter(const OOXMLValue::Pointer_t& rValue) +{ + if (OOXMLFastContextHandler* pTableRowProperties = getParent()) + { + if (OOXMLFastContextHandler* pTableRow = pTableRowProperties->getParent()) + // Save the value into the table row context, so it can be handled + // right before the end of the row. + pTableRow->setGridAfter(rValue); + } +} + +namespace { +OOXMLValue::Pointer_t fakeNoBorder() +{ + OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySet ); + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(0); + pProps->add(NS_ooxml::LN_CT_Border_val, pVal, OOXMLProperty::ATTRIBUTE); + OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue( pProps )); + return pValue; +} +} + +// Handle w:gridBefore here by faking necessary input that'll fake cells. I'm apparently +// not insane enough to find out how to add cells in dmapper. +void OOXMLFastContextHandlerTextTableRow::handleGridBefore( const OOXMLValue::Pointer_t& val ) +{ + // start removing: disable for w:gridBefore + if (!mpGridAfter) + return; + + int count = val->getInt(); + for( int i = 0; + i < count; + ++i ) + { + endOfParagraph(); + + if (isForwardEvents()) + { + // This whole part is OOXMLFastContextHandlerTextTableCell::endCell() . + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblDepth, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(1); + pProps->add(NS_ooxml::LN_inTbl, pVal, OOXMLProperty::SPRM); + } + { + OOXMLValue::Pointer_t pVal = OOXMLBooleanValue::Create(mnTableDepth > 0); + pProps->add(NS_ooxml::LN_tblCell, pVal, OOXMLProperty::SPRM); + } + + mpStream->props(pProps.get()); + + // fake with no border + OOXMLPropertySet::Pointer_t pCellProps( new OOXMLPropertySet ); + { + OOXMLPropertySet::Pointer_t pBorderProps( new OOXMLPropertySet ); + static Id borders[] = { NS_ooxml::LN_CT_TcBorders_top, NS_ooxml::LN_CT_TcBorders_bottom, + NS_ooxml::LN_CT_TcBorders_start, NS_ooxml::LN_CT_TcBorders_end }; + for(sal_uInt32 border : borders) + pBorderProps->add(border, fakeNoBorder(), OOXMLProperty::SPRM); + OOXMLValue::Pointer_t pValue( new OOXMLPropertySetValue( pBorderProps )); + pCellProps->add(NS_ooxml::LN_CT_TcPrBase_tcBorders, pValue, OOXMLProperty::SPRM); + mpParserState->setCellProperties(pCellProps); + } + } + + sendCellProperties(); + endParagraphGroup(); + } +} + +/* + class OOXMLFastContextHandlerTextTable + */ + +OOXMLFastContextHandlerTextTable::OOXMLFastContextHandlerTextTable +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandler(pContext) +{ +} + +OOXMLFastContextHandlerTextTable::~OOXMLFastContextHandlerTextTable() +{ + clearTableProps(); +} + +void OOXMLFastContextHandlerTextTable::lcl_startFastElement +(Token_t /*Element*/, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ + mpParserState->startTable(); + mnTableDepth++; + + OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySet ); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblStart, pVal, OOXMLProperty::SPRM); + } + mpParserState->setCharacterProperties(pProps); + + startAction(); +} + +void OOXMLFastContextHandlerTextTable::lcl_endFastElement +(Token_t /*Element*/) +{ + endAction(); + + OOXMLPropertySet::Pointer_t pProps( new OOXMLPropertySet ); + { + OOXMLValue::Pointer_t pVal = OOXMLIntegerValue::Create(mnTableDepth); + pProps->add(NS_ooxml::LN_tblEnd, pVal, OOXMLProperty::SPRM); + } + mpParserState->setCharacterProperties(pProps); + + mnTableDepth--; + mpParserState->endTable(); +} + +// tdf#111550 +void OOXMLFastContextHandlerTextTable::start_P_Tbl() +{ + // Normally, when one paragraph ends, and another begins, + // in OOXMLFactory_wml::endAction handler for , + // pHandler->endOfParagraph() is called, which (among other things) + // calls TableManager::setHandle() to update current cell's starting point. + // Then, in OOXMLFactory_wml::startAction for next , + // pHandler->startParagraphGroup() is called, which ends previous group, + // and there, it pushes cells to row in TableManager::endParagraphGroup() + // (cells have correct bounds defined by mCurHandle). + // When a table is child of a , that paragraph doesn't end before nested + // paragraph begins. So, pHandler->endOfParagraph() was not (and should not be) + // called. But as next paragraph starts, is the previous group is closed, then + // cells will have wrong boundings. Here, we know that we *are* in paragraph + // group, but it should not be finished. + mpParserState->setInParagraphGroup(false); +} + +/* + class OOXMLFastContextHandlerShape + */ + +OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape +(OOXMLFastContextHandler * pContext) +: OOXMLFastContextHandlerProperties(pContext), m_bShapeSent( false ), + m_bShapeStarted(false), m_bShapeContextPushed(false) +{ +} + +OOXMLFastContextHandlerShape::~OOXMLFastContextHandlerShape() +{ + if (m_bShapeContextPushed) + getDocument()->popShapeContext(); +} + +void OOXMLFastContextHandlerShape::lcl_startFastElement +(Token_t Element, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + startAction(); + + if (mrShapeContext.is()) + { + mrShapeContext->startFastElement(Element, Attribs); + } +} + +void SAL_CALL OOXMLFastContextHandlerShape::startUnknownElement +(const OUString & Namespace, + const OUString & Name, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + if (mrShapeContext.is()) + mrShapeContext->startUnknownElement(Namespace, Name, Attribs); +} + +void OOXMLFastContextHandlerShape::setToken(Token_t nToken) +{ + if (nToken == Token_t(NMSP_wps | XML_wsp) || nToken == Token_t(NMSP_dmlPicture | XML_pic)) + { + // drawingML shapes are independent, is not parsed after + // shape contents without pushing/popping the stack. + m_bShapeContextPushed = true; + getDocument()->pushShapeContext(); + } + + mrShapeContext.set(getDocument()->getShapeContext()); + if (!mrShapeContext.is()) + { + // Define the shape context for the whole document + mrShapeContext = css::xml::sax::FastShapeContextHandler::create(getComponentContext()); + getDocument()->setShapeContext(mrShapeContext); + } + + mrShapeContext->setModel(getDocument()->getModel()); + uno::Reference xDocSupplier(getDocument()->getModel(), uno::UNO_QUERY_THROW); + mrShapeContext->setDocumentProperties(xDocSupplier->getDocumentProperties()); + mrShapeContext->setDrawPage(getDocument()->getDrawPage()); + mrShapeContext->setMediaDescriptor(getDocument()->getMediaDescriptor()); + + mrShapeContext->setRelationFragmentPath(mpParserState->getTarget()); + + OOXMLFastContextHandler::setToken(nToken); + + if (mrShapeContext.is()) + mrShapeContext->setStartToken(nToken); +} + +void OOXMLFastContextHandlerShape::sendShape( Token_t Element ) +{ + if ( mrShapeContext.is() && !m_bShapeSent ) + { + awt::Point aPosition = mpStream->getPositionOffset(); + mrShapeContext->setPosition(aPosition); + uno::Reference xShape(mrShapeContext->getShape()); + m_bShapeSent = true; + if (xShape.is()) + { + OOXMLValue::Pointer_t + pValue(new OOXMLShapeValue(xShape)); + newProperty(NS_ooxml::LN_shape, pValue); + + bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); + + //tdf#87569: Fix table layout with correcting anchoring + //If anchored object is in table, Word calculates its position from cell border + //instead of page (what is set in the sample document) + uno::Reference xShapePropSet(xShape, uno::UNO_QUERY); + if (mnTableDepth > 0 && xShapePropSet.is() && mbIsVMLfound) //if we had a table + { + xShapePropSet->setPropertyValue(dmapper::getPropertyName(dmapper::PROP_FOLLOW_TEXT_FLOW), + uno::makeAny(mbAllowInCell)); + } + // Notify the dmapper that the shape is ready to use + if ( !bIsPicture ) + { + mpStream->startShape( xShape ); + m_bShapeStarted = true; + } + } + } +} + +void OOXMLFastContextHandlerShape::lcl_endFastElement +(Token_t Element) +{ + if (isForwardEvents()) + { + + if (mrShapeContext.is()) + { + mrShapeContext->endFastElement(Element); + sendShape( Element ); + } + + OOXMLFastContextHandlerProperties::lcl_endFastElement(Element); + + // Ending the shape should be the last thing to do + bool bIsPicture = Element == ( NMSP_dmlPicture | XML_pic ); + if ( !bIsPicture && m_bShapeStarted) + mpStream->endShape( ); + + } +} + +void SAL_CALL OOXMLFastContextHandlerShape::endUnknownElement +(const OUString & Namespace, + const OUString & Name) +{ + if (mrShapeContext.is()) + mrShapeContext->endUnknownElement(Namespace, Name); +} + +uno::Reference< xml::sax::XFastContextHandler > +OOXMLFastContextHandlerShape::lcl_createFastChildContext +(Token_t Element, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + uno::Reference< xml::sax::XFastContextHandler > xContextHandler; + + bool bGroupShape = Element == Token_t(NMSP_vml | XML_group); + // drawingML version also counts as a group shape. + bGroupShape |= mrShapeContext->getStartToken() == Token_t(NMSP_wpg | XML_wgp); + mbIsVMLfound = (getNamespace(Element) == NMSP_vmlOffice) || (getNamespace(Element) == NMSP_vml); + switch (oox::getNamespace(Element)) + { + case NMSP_doc: + case NMSP_vmlWord: + case NMSP_vmlOffice: + if (!bGroupShape) + xContextHandler.set(OOXMLFactory::createFastChildContextFromStart(this, Element)); + [[fallthrough]]; + default: + if (!xContextHandler.is()) + { + if (mrShapeContext.is()) + { + uno::Reference pChildContext = + mrShapeContext->createFastChildContext(Element, Attribs); + + OOXMLFastContextHandlerWrapper * pWrapper = + new OOXMLFastContextHandlerWrapper(this, + pChildContext, + this); + + //tdf129888 store allowincell attribute of the VML shape + if (Attribs->hasAttribute(NMSP_vmlOffice | XML_allowincell)) + mbAllowInCell + = !(Attribs->getValue(NMSP_vmlOffice | XML_allowincell) == "f"); + + if (!bGroupShape) + { + pWrapper->addNamespace(NMSP_doc); + pWrapper->addNamespace(NMSP_vmlWord); + pWrapper->addNamespace(NMSP_vmlOffice); + pWrapper->addToken( NMSP_vml|XML_textbox ); + } + xContextHandler.set(pWrapper); + } + else + xContextHandler.set(this); + } + break; + } + + // VML import of shape text is already handled by + // OOXMLFastContextHandlerWrapper::lcl_createFastChildContext(), here we + // handle the WPS import of shape text, as there the parent context is a + // Shape one, so a different situation. + if (Element == static_cast(NMSP_wps | XML_txbx) || + Element == static_cast(NMSP_wps | XML_linkedTxbx) ) + sendShape(Element); + + return xContextHandler; +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL +OOXMLFastContextHandlerShape::createUnknownChildContext +(const OUString & Namespace, + const OUString & Name, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + uno::Reference< xml::sax::XFastContextHandler > xResult; + + if (mrShapeContext.is()) + xResult.set(mrShapeContext->createUnknownChildContext + (Namespace, Name, Attribs)); + + return xResult; +} + +void OOXMLFastContextHandlerShape::lcl_characters +(const OUString & aChars) +{ + if (mrShapeContext.is()) + mrShapeContext->characters(aChars); +} + +/* + class OOXMLFastContextHandlerWrapper +*/ + +OOXMLFastContextHandlerWrapper::OOXMLFastContextHandlerWrapper +(OOXMLFastContextHandler * pParent, + uno::Reference const & xContext, + rtl::Reference const & xShapeHandler) + : OOXMLFastContextHandler(pParent), + mxWrappedContext(xContext), + mxShapeHandler(xShapeHandler) +{ + setId(pParent->getId()); + setToken(pParent->getToken()); + setPropertySet(pParent->getPropertySet()); +} + +OOXMLFastContextHandlerWrapper::~OOXMLFastContextHandlerWrapper() +{ +} + +void SAL_CALL OOXMLFastContextHandlerWrapper::startUnknownElement +(const OUString & Namespace, + const OUString & Name, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + if (mxWrappedContext.is()) + mxWrappedContext->startUnknownElement(Namespace, Name, Attribs); +} + +void SAL_CALL OOXMLFastContextHandlerWrapper::endUnknownElement +(const OUString & Namespace, + const OUString & Name) +{ + if (mxWrappedContext.is()) + mxWrappedContext->endUnknownElement(Namespace, Name); +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL +OOXMLFastContextHandlerWrapper::createUnknownChildContext +(const OUString & Namespace, + const OUString & Name, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + uno::Reference< xml::sax::XFastContextHandler > xResult; + + if (mxWrappedContext.is()) + xResult = mxWrappedContext->createUnknownChildContext + (Namespace, Name, Attribs); + else + xResult.set(this); + + return xResult; +} + +void OOXMLFastContextHandlerWrapper::attributes +(const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + pHandler->attributes(Attribs); + } +} + +OOXMLFastContextHandler::ResourceEnum_t +OOXMLFastContextHandlerWrapper::getResource() const +{ + return UNKNOWN; +} + +void OOXMLFastContextHandlerWrapper::addNamespace(Id nId) +{ + mMyNamespaces.insert(nId); +} + +void OOXMLFastContextHandlerWrapper::addToken( Token_t Token ) +{ + mMyTokens.insert( Token ); +} + +void OOXMLFastContextHandlerWrapper::lcl_startFastElement +(Token_t Element, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + if (mxWrappedContext.is()) + mxWrappedContext->startFastElement(Element, Attribs); +} + +void OOXMLFastContextHandlerWrapper::lcl_endFastElement +(Token_t Element) +{ + if (mxWrappedContext.is()) + mxWrappedContext->endFastElement(Element); +} + +uno::Reference< xml::sax::XFastContextHandler > +OOXMLFastContextHandlerWrapper::lcl_createFastChildContext +(Token_t Element, + const uno::Reference< xml::sax::XFastAttributeList > & Attribs) +{ + uno::Reference< xml::sax::XFastContextHandler > xResult; + + bool bInNamespaces = mMyNamespaces.find(oox::getNamespace(Element)) != mMyNamespaces.end(); + bool bInTokens = mMyTokens.find( Element ) != mMyTokens.end( ); + + // We have methods to _add_ individual tokens or whole namespaces to be + // processed by writerfilter (instead of oox), but we have no method to + // filter out a single token. Just hardwire the 'wrap' and 'signatureline' tokens + // here until we need a more generic solution. + bool bIsWrap = Element == static_cast(NMSP_vmlWord | XML_wrap); + bool bIsSignatureLine = Element == static_cast(NMSP_vmlOffice | XML_signatureline); + bool bSkipImages = getDocument()->IsSkipImages() && oox::getNamespace(Element) == NMSP_dml && + !((oox::getBaseToken(Element) == XML_linkedTxbx) || (oox::getBaseToken(Element) == XML_txbx)); + + if ( bInNamespaces && ((!bIsWrap && !bIsSignatureLine) + || mxShapeHandler->isShapeSent()) ) + { + xResult.set(OOXMLFactory::createFastChildContextFromStart(this, Element)); + } + else if (mxWrappedContext.is() && !bSkipImages) + { + OOXMLFastContextHandlerWrapper * pWrapper = + new OOXMLFastContextHandlerWrapper + (this, mxWrappedContext->createFastChildContext(Element, Attribs), + mxShapeHandler); + pWrapper->mMyNamespaces = mMyNamespaces; + pWrapper->mMyTokens = mMyTokens; + pWrapper->setPropertySet(getPropertySet()); + xResult.set(pWrapper); + } + else + { + xResult.set(this); + } + + if ( bInTokens ) + mxShapeHandler->sendShape( Element ); + + return xResult; +} + +void OOXMLFastContextHandlerWrapper::lcl_characters +(const OUString & aChars) +{ + if (mxWrappedContext.is()) + mxWrappedContext->characters(aChars); +} + +OOXMLFastContextHandler * +OOXMLFastContextHandlerWrapper::getFastContextHandler() const +{ + if (mxWrappedContext.is()) + return dynamic_cast(mxWrappedContext.get()); + + return nullptr; +} + +void OOXMLFastContextHandlerWrapper::newProperty +(Id nId, const OOXMLValue::Pointer_t& pVal) +{ + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + pHandler->newProperty(nId, pVal); + } +} + +void OOXMLFastContextHandlerWrapper::setPropertySet +(const OOXMLPropertySet::Pointer_t& pPropertySet) +{ + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + pHandler->setPropertySet(pPropertySet); + } + + mpPropertySet = pPropertySet; +} + +OOXMLPropertySet::Pointer_t OOXMLFastContextHandlerWrapper::getPropertySet() + const +{ + OOXMLPropertySet::Pointer_t pResult(mpPropertySet); + + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + pResult = pHandler->getPropertySet(); + } + + return pResult; +} + +string OOXMLFastContextHandlerWrapper::getType() const +{ + string sResult = "Wrapper("; + + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + sResult += pHandler->getType(); + } + + sResult += ")"; + + return sResult; +} + +void OOXMLFastContextHandlerWrapper::setId(Id rId) +{ + OOXMLFastContextHandler::setId(rId); + + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + pHandler->setId(rId); + } +} + +Id OOXMLFastContextHandlerWrapper::getId() const +{ + Id nResult = OOXMLFastContextHandler::getId(); + + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr && pHandler->getId() != 0) + nResult = pHandler->getId(); + } + + return nResult; +} + +void OOXMLFastContextHandlerWrapper::setToken(Token_t nToken) +{ + OOXMLFastContextHandler::setToken(nToken); + + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + pHandler->setToken(nToken); + } +} + +Token_t OOXMLFastContextHandlerWrapper::getToken() const +{ + Token_t nResult = OOXMLFastContextHandler::getToken(); + + if (mxWrappedContext.is()) + { + OOXMLFastContextHandler * pHandler = getFastContextHandler(); + if (pHandler != nullptr) + nResult = pHandler->getToken(); + } + + return nResult; +} + + +/* + class OOXMLFastContextHandlerLinear + */ + +OOXMLFastContextHandlerLinear::OOXMLFastContextHandlerLinear(OOXMLFastContextHandler* pContext) + : OOXMLFastContextHandlerProperties(pContext) + , depthCount( 0 ) +{ +} + +void OOXMLFastContextHandlerLinear::lcl_startFastElement(Token_t Element, + const uno::Reference< xml::sax::XFastAttributeList >& Attribs) +{ + buffer.appendOpeningTag( Element, Attribs ); + ++depthCount; +} + +void OOXMLFastContextHandlerLinear::lcl_endFastElement(Token_t Element) +{ + buffer.appendClosingTag( Element ); + if( --depthCount == 0 ) + process(); +} + +uno::Reference< xml::sax::XFastContextHandler > +OOXMLFastContextHandlerLinear::lcl_createFastChildContext(Token_t, + const uno::Reference< xml::sax::XFastAttributeList >&) +{ + uno::Reference< xml::sax::XFastContextHandler > xContextHandler; + xContextHandler.set( this ); + return xContextHandler; +} + +void OOXMLFastContextHandlerLinear::lcl_characters(const OUString& aChars) +{ + buffer.appendCharacters( aChars ); +} + +/* + class OOXMLFastContextHandlerLinear + */ + +OOXMLFastContextHandlerMath::OOXMLFastContextHandlerMath(OOXMLFastContextHandler* pContext) + : OOXMLFastContextHandlerLinear(pContext) +{ +} + +void OOXMLFastContextHandlerMath::process() +{ + SvGlobalName name( SO3_SM_CLASSID ); + comphelper::EmbeddedObjectContainer container; + OUString aName; + uno::Sequence objArgs(1); + objArgs[0].Name = "DefaultParentBaseURL"; + objArgs[0].Value <<= getDocument()->GetDocumentBaseURL(); + uno::Reference ref = + container.CreateEmbeddedObject(name.GetByteSequence(), objArgs, aName); + assert(ref.is()); + if (!ref.is()) + return; + uno::Reference< uno::XInterface > component(ref->getComponent(), uno::UNO_QUERY_THROW); +// gcc4.4 (and 4.3 and possibly older) have a problem with dynamic_cast directly to the target class, +// so help it with an intermediate cast. I'm not sure what exactly the problem is, seems to be unrelated +// to RTLD_GLOBAL, so most probably a gcc bug. + oox::FormulaImportBase& import = dynamic_cast(dynamic_cast(*component)); + import.readFormulaOoxml(buffer); + if (isForwardEvents()) + { + OOXMLPropertySet::Pointer_t pProps(new OOXMLPropertySet); + OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref )); + if (mbIsMathPara) + { + switch (mnMathJcVal) + { + case eMathParaJc::CENTER: + pProps->add(NS_ooxml::LN_Value_math_ST_Jc_centerGroup, pVal, + OOXMLProperty::ATTRIBUTE); + break; + case eMathParaJc::LEFT: + pProps->add(NS_ooxml::LN_Value_math_ST_Jc_left, pVal, + OOXMLProperty::ATTRIBUTE); + break; + case eMathParaJc::RIGHT: + pProps->add(NS_ooxml::LN_Value_math_ST_Jc_right, pVal, + OOXMLProperty::ATTRIBUTE); + break; + default: + break; + } + } + else + pProps->add(NS_ooxml::LN_starmath, pVal, OOXMLProperty::ATTRIBUTE); + mpStream->props( pProps.get() ); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx new file mode 100644 index 000000000..ca6e6507e --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx @@ -0,0 +1,605 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTCONTEXTHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTCONTEXTHANDLER_HXX + +#include +#include +#include +#include +#include +#include +#include +#include "OOXMLParserState.hxx" +#include "OOXMLPropertySet.hxx" + +namespace writerfilter { +namespace ooxml +{ +class OOXMLDocumentImpl; + +class OOXMLFastContextHandler: public ::cppu::WeakImplHelper +{ +public: + typedef tools::SvRef Pointer_t; + + enum ResourceEnum_t { UNKNOWN, STREAM, PROPERTIES, TABLE, SHAPE }; + + explicit OOXMLFastContextHandler(css::uno::Reference< css::uno::XComponentContext > const & context); + + explicit OOXMLFastContextHandler(OOXMLFastContextHandler * pContext); + + OOXMLFastContextHandler(OOXMLFastContextHandler const &) = default; + + virtual ~OOXMLFastContextHandler() override; + + // css::xml::sax::XFastContextHandler: + virtual void SAL_CALL startFastElement (sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs) override final; + + virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void SAL_CALL endFastElement(sal_Int32 Element) override; + + virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name) override; + + virtual css::uno::Reference SAL_CALL createFastChildContext(sal_Int32 Element, + const css::uno::Reference& Attribs) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString & Namespace, const OUString & Name, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void SAL_CALL characters(const OUString & aChars) override; + + // local + + void setStream(Stream * pStream); + + /** + Return value of this context(element). + + @return the value + */ + virtual OOXMLValue::Pointer_t getValue() const; + + /** + Returns a string describing the type of the context. + + This is the name of the define normally. + + @return type string + */ + virtual std::string getType() const { return "??"; } + + virtual ResourceEnum_t getResource() const { return STREAM; } + + /// @throws css::uno::RuntimeException + /// @throws css::xml::sax::SAXException + virtual void attributes(const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs); + + virtual void newProperty(Id aId, const OOXMLValue::Pointer_t& pVal); + virtual void setPropertySet(const OOXMLPropertySet::Pointer_t& pPropertySet); + virtual OOXMLPropertySet::Pointer_t getPropertySet() const; + + virtual void setToken(Token_t nToken); + virtual Token_t getToken() const; + + void resolveFootnote(const sal_Int32 nId); + void resolveEndnote(const sal_Int32 nId); + void resolveComment(const sal_Int32 nId); + void resolvePicture(const OUString & rId); + void resolveHeader(const sal_Int32 type, + const OUString & rId); + void resolveFooter(const sal_Int32 type, + const OUString & rId); + void resolveData(const OUString & rId); + + OUString getTargetForId(const OUString & rId); + + void setDocument(OOXMLDocumentImpl* pDocument); + OOXMLDocumentImpl* getDocument(); + void setXNoteId(const OOXMLValue::Pointer_t& pValue); + void setXNoteId(const sal_Int32 nId); + sal_Int32 getXNoteId() const; + void setForwardEvents(bool bForwardEvents); + bool isForwardEvents() const; + virtual void setId(Id nId); + virtual Id getId() const; + + void setDefine(Id nDefine); + Id getDefine() const { return mnDefine;} + + const OOXMLParserState::Pointer_t& getParserState() const { return mpParserState;} + + void sendTableDepth() const; + void setHandle(); + + void startSectionGroup(); + void setLastParagraphInSection(); + void setLastSectionGroup(); + void endSectionGroup(); + void startParagraphGroup(); + void endParagraphGroup(); + void startCharacterGroup(); + void endCharacterGroup(); + virtual void pushBiDiEmbedLevel(); + virtual void popBiDiEmbedLevel(); + void startSdt(); + void endSdt(); + + void startField(); + void fieldSeparator(); + void endField(); + void lockField(); + void ftnednref(); + void ftnedncont(); + void ftnednsep(); + void pgNum(); + void tab(); + void symbol(); + void cr(); + void noBreakHyphen(); + void softHyphen(); + void handleLastParagraphInSection(); + void endOfParagraph(); + void text(const OUString & sText); + void positionOffset(const OUString & sText); + static void ignore(); + void alignH(const OUString & sText); + void alignV(const OUString & sText); + void positivePercentage(const OUString& rText); + void startGlossaryEntry(); + void endGlossaryEntry(); + void startTxbxContent(); + void endTxbxContent(); + void propagateCharacterProperties(); + void propagateTableProperties(); + void propagateRowProperties(); + void propagateCellProperties(); + void sendPropertiesWithId(Id nId); + void sendPropertiesToParent(); + void sendCellProperties(); + void sendRowProperties(); + void sendTableProperties(); + void clearTableProps(); + void clearProps(); + + virtual void setDefaultBooleanValue(); + virtual void setDefaultIntegerValue(); + virtual void setDefaultHexValue(); + virtual void setDefaultStringValue(); + + void sendPropertyToParent(); + OOXMLFastContextHandler* getParent() const { return mpParent; } + void setGridAfter(const OOXMLValue::Pointer_t& pGridAfter) { mpGridAfter = pGridAfter; } + +protected: + OOXMLFastContextHandler * mpParent; + Id mId; + Id mnDefine; + Token_t mnToken; + + // the formula insertion mode: inline/newline(left, center, right) + sal_Int8 mnMathJcVal; + bool mbIsMathPara; + enum eMathParaJc + { + INLINE, //The equation is anchored as inline to the text + CENTER, //The equation is center aligned + LEFT, //The equation is left aligned + RIGHT //The equation is right aligned + }; + // the stream to send the stream events to. + Stream * mpStream; + + // the current global parser state + OOXMLParserState::Pointer_t mpParserState; + + // the table depth of this context + unsigned int mnTableDepth; + + /// @throws css::uno::RuntimeException + /// @throws css::xml::sax::SAXException + virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs); + + /// @throws css::uno::RuntimeException + /// @throws css::xml::sax::SAXException + virtual void lcl_endFastElement(Token_t Element); + + /// @throws css::uno::RuntimeException + /// @throws css::xml::sax::SAXException + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs); + + /// @throws css::uno::RuntimeException + /// @throws css::xml::sax::SAXException + virtual void lcl_characters(const OUString & aChars); + + void startAction(); + void endAction(); + + const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const { return m_xContext;} + + bool inPositionV; + bool mbAllowInCell; // o:allowincell + bool mbIsVMLfound; + OOXMLValue::Pointer_t mpGridAfter; + +private: + void operator =(OOXMLFastContextHandler const &) = delete; + /// Handles AlternateContent. Returns true, if children of the current element should be ignored. + bool prepareMceContext(Token_t nElement, const css::uno::Reference& Attribs); + + // 2.10 of XML 1.0 specification + bool IsPreserveSpace() const; + + css::uno::Reference< css::uno::XComponentContext > m_xContext; + bool m_bDiscardChildren; + bool m_bTookChoice; ///< Did we take the Choice or want Fallback instead? + bool mbPreserveSpace = false; + bool mbPreserveSpaceSet = false; + +}; + +class OOXMLFastContextHandlerStream : public OOXMLFastContextHandler +{ +public: + explicit OOXMLFastContextHandlerStream(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerStream() override; + + virtual ResourceEnum_t getResource() const override { return STREAM; } + + const OOXMLPropertySet::Pointer_t& getPropertySetAttrs() const { return mpPropertySetAttrs;} + + virtual void newProperty(Id aId, const OOXMLValue::Pointer_t& pVal) override; + void sendProperty(Id nId); + virtual OOXMLPropertySet::Pointer_t getPropertySet() const override; + + void handleHyperlink(); + +private: + mutable OOXMLPropertySet::Pointer_t mpPropertySetAttrs; +}; + +class OOXMLFastContextHandlerProperties : public OOXMLFastContextHandler +{ +public: + explicit OOXMLFastContextHandlerProperties(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerProperties() override; + + virtual OOXMLValue::Pointer_t getValue() const override; + virtual ResourceEnum_t getResource() const override { return PROPERTIES; } + + virtual void newProperty(Id nId, const OOXMLValue::Pointer_t& pVal) override; + + void handleXNotes(); + void handleHdrFtr(); + void handleComment(); + void handlePicture(); + void handleBreak(); + void handleOutOfOrderBreak(); + void handleOLE(); + void handleFontRel(); + void handleHyperlinkURL(); + + virtual void setPropertySet(const OOXMLPropertySet::Pointer_t& pPropertySet) override; + virtual OOXMLPropertySet::Pointer_t getPropertySet() const override; + +protected: + /// the properties + OOXMLPropertySet::Pointer_t mpPropertySet; + + virtual void lcl_endFastElement(Token_t Element) override; + +private: + + bool mbResolve; +}; + +class OOXMLFastContextHandlerPropertyTable : + public OOXMLFastContextHandlerProperties +{ +public: + explicit OOXMLFastContextHandlerPropertyTable(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerPropertyTable() override; + +private: + OOXMLTable mTable; + + virtual void lcl_endFastElement(Token_t Element) override; +}; + +class OOXMLFastContextHandlerValue : + public OOXMLFastContextHandler +{ +public: + explicit OOXMLFastContextHandlerValue(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerValue() override; + + void setValue(const OOXMLValue::Pointer_t& pValue); + virtual OOXMLValue::Pointer_t getValue() const override; + + virtual void lcl_endFastElement(Token_t Element) override; + + virtual std::string getType() const override { return "Value"; } + + virtual void setDefaultBooleanValue() override; + virtual void setDefaultIntegerValue() override; + virtual void setDefaultHexValue() override; + virtual void setDefaultStringValue() override; + + virtual void pushBiDiEmbedLevel() override; + virtual void popBiDiEmbedLevel() override; + +private: + OOXMLValue::Pointer_t mpValue; +}; + +class OOXMLFastContextHandlerTable : public OOXMLFastContextHandler +{ +public: + explicit OOXMLFastContextHandlerTable(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerTable() override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext (sal_Int32 Element, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + +private: + OOXMLTable mTable; + + css::uno::Reference mCurrentChild; + + virtual void lcl_endFastElement(Token_t Element) override; + + virtual ResourceEnum_t getResource() const override { return TABLE; } + + virtual std::string getType() const override { return "Table"; } + + void addCurrentChild(); +}; + +class OOXMLFastContextHandlerXNote : public OOXMLFastContextHandlerProperties +{ +public: + explicit OOXMLFastContextHandlerXNote(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerXNote() override; + + void checkId(const OOXMLValue::Pointer_t& pValue); + + void checkType(const OOXMLValue::Pointer_t& pValue); + + virtual std::string getType() const override { return "XNote"; } + +private: + bool mbForwardEventsSaved; + sal_Int32 mnMyXNoteId; + sal_Int32 mnMyXNoteType; + + virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_endFastElement(Token_t Element) override; + + virtual ResourceEnum_t getResource() const override { return STREAM; } +}; + +class OOXMLFastContextHandlerTextTableCell : public OOXMLFastContextHandler +{ +public: + explicit OOXMLFastContextHandlerTextTableCell(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerTextTableCell() override; + + virtual std::string getType() const override { return "TextTableCell"; } + + void startCell(); + void endCell(); +}; + +class OOXMLFastContextHandlerTextTableRow : public OOXMLFastContextHandler +{ +public: + explicit OOXMLFastContextHandlerTextTableRow(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerTextTableRow() override; + + virtual std::string getType() const override { return "TextTableRow"; } + + static void startRow(); + void endRow(); + void handleGridBefore( const OOXMLValue::Pointer_t& val ); + void handleGridAfter(const OOXMLValue::Pointer_t& rValue); +}; + +class OOXMLFastContextHandlerTextTable : public OOXMLFastContextHandler +{ +public: + explicit OOXMLFastContextHandlerTextTable(OOXMLFastContextHandler * pContext); + + virtual ~OOXMLFastContextHandlerTextTable() override; + + virtual std::string getType() const override { return "TextTable"; } + + // tdf#111550 + // when appears as direct child of , we need to rearrange this paragraph + // to merge with the table's first paragraph (that's what Word does in this case) + void start_P_Tbl(); +protected: + virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_endFastElement(Token_t Element) override; +}; + +class OOXMLFastContextHandlerShape: public OOXMLFastContextHandlerProperties +{ + bool m_bShapeSent; + bool m_bShapeStarted; + /// Is it necessary to pop the stack in the dtor? + bool m_bShapeContextPushed; + css::uno::Reference mrShapeContext; + +public: + explicit OOXMLFastContextHandlerShape(OOXMLFastContextHandler * pContext); + virtual ~OOXMLFastContextHandlerShape() override; + + virtual std::string getType() const override { return "Shape"; } + + // css::xml::sax::XFastContextHandler: + virtual void SAL_CALL startUnknownElement (const OUString & Namespace, const OUString & Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString & Namespace, const OUString & Name, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void setToken(Token_t nToken) override; + + virtual ResourceEnum_t getResource() const override { return SHAPE; } + + void sendShape( Token_t Element ); + bool isShapeSent( ) const { return m_bShapeSent; } + +protected: + virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_endFastElement(Token_t Element) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext (Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_characters(const OUString & aChars) override; + +}; + +/** + OOXMLFastContextHandlerWrapper wraps an OOXMLFastContextHandler. + + The method calls for the interface css::xml::sax::XFastContextHandler are + forwarded to the wrapped OOXMLFastContextHandler. + */ +class OOXMLFastContextHandlerWrapper : public OOXMLFastContextHandler +{ +public: + OOXMLFastContextHandlerWrapper(OOXMLFastContextHandler * pParent, + css::uno::Reference const & xContext, + rtl::Reference const & xShapeHandler); + virtual ~OOXMLFastContextHandlerWrapper() override; + + // css::xml::sax::XFastContextHandler: + virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext (const OUString & Namespace, const OUString & Name, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void attributes(const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual ResourceEnum_t getResource() const override; + + void addNamespace(Id nId); + void addToken( Token_t Element ); + + virtual void newProperty(Id nId, const OOXMLValue::Pointer_t& pVal) override; + virtual void setPropertySet(const OOXMLPropertySet::Pointer_t& pPropertySet) override; + virtual OOXMLPropertySet::Pointer_t getPropertySet() const override; + + virtual std::string getType() const override; + +protected: + virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_endFastElement(Token_t Element) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_characters(const OUString & aChars) override; + + virtual void setId(Id nId) override; + virtual Id getId() const override; + + virtual void setToken(Token_t nToken) override; + virtual Token_t getToken() const override; + +private: + css::uno::Reference mxWrappedContext; + rtl::Reference mxShapeHandler; + std::set mMyNamespaces; + std::set mMyTokens; + OOXMLPropertySet::Pointer_t mpPropertySet; + + OOXMLFastContextHandler * getFastContextHandler() const; +}; + +/** + A class that converts from XFastParser/XFastContextHandler usage to a liner XML stream of data. + + The purpose of this class is to convert the rather complex XFastContextHandler-based XML + processing that requires context subclasses, callbacks, etc. into a linear stream of XML tokens + that can be handled simply by reading the tokens one by one and directly processing them. + See the oox::formulaimport::XmlStream class documentation for more information. + + Usage: Create a subclass of OOXMLFastContextHandlerLinear, reimplemented getType() to provide + type of the subclass and process() to actually process the XML stream. Also make sure to + add a line like the following to model.xml (for class OOXMLFastContextHandlerMath): + + + + @since 3.5 +*/ +class OOXMLFastContextHandlerLinear: public OOXMLFastContextHandlerProperties +{ +public: + explicit OOXMLFastContextHandlerLinear(OOXMLFastContextHandler * pContext); + /** + Return the type of the class, as written in model.xml . + */ + virtual std::string getType() const override = 0; + +protected: + /** + Called when the tokens for the element, its content and sub-elements have been linearized + and should be processed. The data member @ref buffer contains the converted data. + */ + virtual void process() = 0; + + virtual void lcl_startFastElement(Token_t Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_endFastElement(Token_t Element) override; + + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > lcl_createFastChildContext(Token_t Element, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + + virtual void lcl_characters(const OUString & aChars) override; + + // should be private, but not much point in making deep copies of it + oox::formulaimport::XmlStreamBuilder buffer; + +private: + int depthCount; +}; + +class OOXMLFastContextHandlerMath: public OOXMLFastContextHandlerLinear +{ +public: + explicit OOXMLFastContextHandlerMath(OOXMLFastContextHandler * pContext); + virtual std::string getType() const override { return "Math"; } +protected: + virtual void process() override; +}; + +}} +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTCONTEXTHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx new file mode 100644 index 000000000..3fc69670b --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.cxx @@ -0,0 +1,195 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include "OOXMLFastDocumentHandler.hxx" +#include "OOXMLFastContextHandler.hxx" +#include "OOXMLFactory.hxx" + +namespace writerfilter::ooxml +{ +using namespace ::com::sun::star; +using namespace ::std; + + +OOXMLFastDocumentHandler::OOXMLFastDocumentHandler( + uno::Reference< uno::XComponentContext > const & context, + Stream* pStream, + OOXMLDocumentImpl* pDocument, + sal_Int32 nXNoteId ) + : m_xContext(context) + , mpStream( pStream ) + , mpDocument( pDocument ) + , mnXNoteId( nXNoteId ) + , mxContextHandler() +{ +} + +OOXMLFastDocumentHandler::~OOXMLFastDocumentHandler() {} + +// css::xml::sax::XFastContextHandler: +void SAL_CALL OOXMLFastDocumentHandler::startFastElement +(::sal_Int32 +#ifdef DBG_UTIL +Element +#endif +, const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ +#ifdef DBG_UTIL + clog << this << ":start element:" + << fastTokenToId(Element) + << endl; +#endif +} + +void SAL_CALL OOXMLFastDocumentHandler::startUnknownElement +(const OUString & +#ifdef DBG_UTIL +Namespace +#endif +, const OUString & +#ifdef DBG_UTIL +Name +#endif +, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ +#ifdef DBG_UTIL + clog << this << ":start unknown element:" + << Namespace << ":" << Name << endl; +#endif +} + +void SAL_CALL OOXMLFastDocumentHandler::endFastElement(::sal_Int32 +#ifdef DBG_UTIL +Element +#endif +) +{ +#ifdef DBG_UTIL + clog << this << ":end element:" + << fastTokenToId(Element) + << endl; +#endif +} + +void SAL_CALL OOXMLFastDocumentHandler::endUnknownElement +(const OUString & +#ifdef DBG_UTIL +Namespace +#endif +, const OUString & +#ifdef DBG_UTIL +Name +#endif +) +{ +#ifdef DBG_UTIL + clog << this << ":end unknown element:" + << Namespace << ":" << Name + << endl; +#endif +} + +rtl::Reference< OOXMLFastContextHandler > const & +OOXMLFastDocumentHandler::getContextHandler() const +{ + if (!mxContextHandler.is()) + { + mxContextHandler = new OOXMLFastContextHandler(m_xContext); + mxContextHandler->setStream(mpStream); + mxContextHandler->setDocument(mpDocument); + mxContextHandler->setXNoteId(mnXNoteId); + mxContextHandler->setForwardEvents(true); + } + + return mxContextHandler; +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL + OOXMLFastDocumentHandler::createFastChildContext +(::sal_Int32 Element, + const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ + if ( mpStream == nullptr && mpDocument == nullptr ) + { + // document handler has been created as unknown child - see + // --> do not provide a child context + return nullptr; + } + + return OOXMLFactory::createFastChildContextFromStart(getContextHandler().get(), Element); +} + +uno::Reference< xml::sax::XFastContextHandler > SAL_CALL +OOXMLFastDocumentHandler::createUnknownChildContext +(const OUString & +#ifdef DBG_UTIL +Namespace +#endif +, + const OUString & +#ifdef DBG_UTIL +Name +#endif +, const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/) +{ +#ifdef DBG_UTIL + clog << this << ":createUnknownChildContext:" + << Namespace << ":"<< Name + << endl; +#endif + + return uno::Reference< xml::sax::XFastContextHandler > + ( new OOXMLFastDocumentHandler( m_xContext, nullptr, nullptr, 0 ) ); +} + +void SAL_CALL OOXMLFastDocumentHandler::characters(const OUString & /*aChars*/) +{ +} + +// css::xml::sax::XFastDocumentHandler: +void SAL_CALL OOXMLFastDocumentHandler::startDocument() +{ +} + +void SAL_CALL OOXMLFastDocumentHandler::endDocument() +{ +} + +void SAL_CALL OOXMLFastDocumentHandler::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ ) +{ +} + +void SAL_CALL OOXMLFastDocumentHandler::setDocumentLocator +(const uno::Reference< xml::sax::XLocator > & /*xLocator*/) +{ +} + +void OOXMLFastDocumentHandler::setIsSubstream( bool bSubstream ) +{ + if ( mpStream != nullptr && mpDocument != nullptr ) + { + getContextHandler( )->getParserState( )->setInSectionGroup( bSubstream ); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx new file mode 100644 index 000000000..b7839178f --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLFastDocumentHandler.hxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTDOCUMENTHANDLER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTDOCUMENTHANDLER_HXX + +#include +#include +#include +#include +#include +#include + +namespace writerfilter { +namespace ooxml +{ + +class OOXMLFastContextHandler; + +class OOXMLFastDocumentHandler : public cppu::WeakImplHelper +{ +public: + OOXMLFastDocumentHandler( + css::uno::Reference< css::uno::XComponentContext > const & context, + Stream* pStream, + OOXMLDocumentImpl* pDocument, + sal_Int32 nXNoteId ); + virtual ~OOXMLFastDocumentHandler() override; + + // css::xml::sax::XFastDocumentHandler: + virtual void SAL_CALL startDocument() override; + virtual void SAL_CALL endDocument() override; + virtual void SAL_CALL processingInstruction( const OUString& rTarget, const OUString& rData ) override; + virtual void SAL_CALL setDocumentLocator + (const css::uno::Reference< css::xml::sax::XLocator > & xLocator) override; + + // css::xml::sax::XFastContextHandler: + virtual void SAL_CALL startFastElement + (::sal_Int32 Element, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + virtual void SAL_CALL startUnknownElement + (const OUString & Namespace, + const OUString & Name, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + virtual void SAL_CALL endFastElement(::sal_Int32 Element) override; + virtual void SAL_CALL endUnknownElement + (const OUString & Namespace, + const OUString & Name) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL + createFastChildContext + (::sal_Int32 Element, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL + createUnknownChildContext + (const OUString & Namespace, + const OUString & Name, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; + virtual void SAL_CALL characters(const OUString & aChars) override; + + void setIsSubstream( bool bSubstream ); + +private: + OOXMLFastDocumentHandler(OOXMLFastDocumentHandler const &) = delete; + void operator =(OOXMLFastDocumentHandler const &) = delete; + + css::uno::Reference< css::uno::XComponentContext > m_xContext; + + Stream * mpStream; + OOXMLDocumentImpl* mpDocument; + sal_Int32 mnXNoteId; + mutable rtl::Reference mxContextHandler; + rtl::Reference const & getContextHandler() const; +}; +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTDOCUMENTHANDLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLFastHelper.hxx b/writerfilter/source/ooxml/OOXMLFastHelper.hxx new file mode 100644 index 000000000..fcf162f44 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLFastHelper.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTHELPER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTHELPER_HXX + +#include "OOXMLFastContextHandler.hxx" + +namespace writerfilter { + +namespace ooxml +{ + +template +class OOXMLFastHelper +{ +public: + static OOXMLFastContextHandler* createAndSetParentAndDefine + (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine); + + static void newProperty(OOXMLFastContextHandler * pHandler, + Id nId, sal_Int32 nValue); +}; + +template +OOXMLFastContextHandler* OOXMLFastHelper::createAndSetParentAndDefine (OOXMLFastContextHandler * pHandler, sal_uInt32 nToken, Id nId, Id nDefine) +{ + OOXMLFastContextHandler * pTmp = new T(pHandler); + + pTmp->setToken(nToken); + pTmp->setId(nId); + pTmp->setDefine(nDefine); + + return pTmp; +} + +template +void OOXMLFastHelper::newProperty(OOXMLFastContextHandler * pHandler, + Id nId, + sal_Int32 nVal) +{ + OOXMLValue::Pointer_t pVal(T::Create(nVal)); + + pHandler->newProperty(nId, pVal); +} + +}} +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLFASTHELPER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLParserState.cxx b/writerfilter/source/ooxml/OOXMLParserState.cxx new file mode 100644 index 000000000..576e97c8c --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLParserState.cxx @@ -0,0 +1,280 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "OOXMLParserState.hxx" +#include "Handler.hxx" + +#include + +namespace writerfilter::ooxml +{ +/* + class OOXMLParserState +*/ + +OOXMLParserState::OOXMLParserState() : + mbInSectionGroup(false), + mbInParagraphGroup(false), + mbInCharacterGroup(false), + mbLastParagraphInSection(false), + mbForwardEvents(true), + mnContexts(0), + mnHandle(0), + mpDocument(nullptr), + inTxbxContent(false), + savedInParagraphGroup(false), + savedInCharacterGroup(false), + savedLastParagraphInSection(false) +{ +} + +OOXMLParserState::~OOXMLParserState() +{ +} + +void OOXMLParserState::setLastParagraphInSection(bool bLastParagraphInSection) +{ + mbLastParagraphInSection = bLastParagraphInSection; +} + + +void OOXMLParserState::setInSectionGroup(bool bInSectionGroup) +{ + mbInSectionGroup = bInSectionGroup; +} + + +void OOXMLParserState::setInParagraphGroup(bool bInParagraphGroup) +{ + mbInParagraphGroup = bInParagraphGroup; +} + + +void OOXMLParserState::setInCharacterGroup(bool bInCharacterGroup) +{ + mbInCharacterGroup = bInCharacterGroup; +} + +void OOXMLParserState::setForwardEvents(bool bForwardEvents) +{ + mbForwardEvents = bForwardEvents; +} + + +std::string OOXMLParserState::getHandle() const +{ + return std::to_string(mnHandle); +} + +void OOXMLParserState::setHandle() +{ + mnHandle = mnContexts; +} + +void OOXMLParserState::setDocument(OOXMLDocumentImpl* pDocument) +{ + mpDocument = pDocument; +} + + +void OOXMLParserState::setXNoteId(const sal_Int32 nId) +{ + mpDocument->setXNoteId(nId); +} + +sal_Int32 OOXMLParserState::getXNoteId() const +{ + return mpDocument->getXNoteId(); +} + +const OUString & OOXMLParserState::getTarget() const +{ + return mpDocument->getTarget(); +} + +void OOXMLParserState::resolveCharacterProperties(Stream & rStream) +{ + if (mpCharacterProps.get() != nullptr) + { + rStream.props(mpCharacterProps.get()); + mpCharacterProps = new OOXMLPropertySet; + } +} + +void OOXMLParserState::setCharacterProperties(const OOXMLPropertySet::Pointer_t& pProps) +{ + if (mpCharacterProps.get() == nullptr) + mpCharacterProps = pProps; + else + mpCharacterProps->add(pProps); +} + +void OOXMLParserState::setCellProperties(const OOXMLPropertySet::Pointer_t& pProps) +{ + if (!mCellProps.empty()) + { + OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top(); + + if (rCellProps.get() == nullptr) + rCellProps = pProps; + else + rCellProps->add(pProps); + } +} + +void OOXMLParserState::setRowProperties(const OOXMLPropertySet::Pointer_t& pProps) +{ + if (!mRowProps.empty()) + { + OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top(); + + if (rRowProps.get() == nullptr) + rRowProps = pProps; + else + rRowProps->add(pProps); + } +} + +void OOXMLParserState::resolveCellProperties(Stream & rStream) +{ + if (!mCellProps.empty()) + { + OOXMLPropertySet::Pointer_t & rCellProps = mCellProps.top(); + + if (rCellProps.get() != nullptr) + { + rStream.props(rCellProps.get()); + rCellProps = new OOXMLPropertySet; + } + } +} + +void OOXMLParserState::resolveRowProperties(Stream & rStream) +{ + if (!mRowProps.empty()) + { + OOXMLPropertySet::Pointer_t & rRowProps = mRowProps.top(); + + if (rRowProps.get() != nullptr) + { + rStream.props(rRowProps.get()); + rRowProps = new OOXMLPropertySet; + } + } +} + +void OOXMLParserState::resolveTableProperties(Stream & rStream) +{ + if (!mTableProps.empty()) + { + OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top(); + + if (rTableProps.get() != nullptr) + { + rStream.props(rTableProps.get()); + // Don't clean the table props to send them again for each row + // This mimics the behaviour from RTF tokenizer. + } + } +} + +void OOXMLParserState::setTableProperties(const OOXMLPropertySet::Pointer_t& pProps) +{ + if (!mTableProps.empty()) + { + OOXMLPropertySet::Pointer_t & rTableProps = mTableProps.top(); + if (rTableProps.get() == nullptr) + rTableProps = pProps; + else + rTableProps->add(pProps); + } +} + +// tdf#108714 +void OOXMLParserState::resolvePostponedBreak(Stream & rStream) +{ + for (const auto & rBreak: mvPostponedBreaks) + { + OOXMLBreakHandler aBreakHandler(rStream); + rBreak->resolve(aBreakHandler); + } + mvPostponedBreaks.clear(); +} + +void OOXMLParserState::setPostponedBreak(const OOXMLPropertySet::Pointer_t & pProps) +{ + mvPostponedBreaks.push_back(pProps); +} + +void OOXMLParserState::startTable() +{ + OOXMLPropertySet::Pointer_t pCellProps; + OOXMLPropertySet::Pointer_t pRowProps; + OOXMLPropertySet::Pointer_t pTableProps; + + mCellProps.push(pCellProps); + mRowProps.push(pRowProps); + mTableProps.push(pTableProps); +} + +void OOXMLParserState::endTable() +{ + mCellProps.pop(); + mRowProps.pop(); + mTableProps.pop(); +} + +void OOXMLParserState::incContextCount() +{ + mnContexts++; +} + +void OOXMLParserState::startTxbxContent() +{ + SAL_WARN_IF(inTxbxContent, "writerfilter", "Nested w:txbxContent"); + + inTxbxContent = true; + // Do not save and reset section group state, it'd cause a new page. +// savedInSectionGroup = mbInSectionGroup; + savedInParagraphGroup = mbInParagraphGroup; + savedInCharacterGroup = mbInCharacterGroup; + savedLastParagraphInSection = mbLastParagraphInSection; +// mbInSectionGroup = false; + mbInParagraphGroup = false; + mbInCharacterGroup = false; + mbLastParagraphInSection = false; +} + +void OOXMLParserState::endTxbxContent() +{ + if( !inTxbxContent ) + { + SAL_WARN( "writerfilter", "Non-matching closing w:txbxContent" ); + return; + } +// mbInSectionGroup = savedInSectionGroup; + mbInParagraphGroup = savedInParagraphGroup; + mbInCharacterGroup = savedInCharacterGroup; + mbLastParagraphInSection = savedLastParagraphInSection; + inTxbxContent = false; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLParserState.hxx b/writerfilter/source/ooxml/OOXMLParserState.hxx new file mode 100644 index 000000000..5e9811e2a --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLParserState.hxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLPARSERSTATE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLPARSERSTATE_HXX + +#include +#include "OOXMLDocumentImpl.hxx" +#include "OOXMLPropertySet.hxx" + +namespace writerfilter { +namespace ooxml +{ + +/** + * Struct to store our 'alternate state'. If multiple mc:AlternateContent + * elements arrive, then while the inner ones are active, the original state is + * saved away, and once they inner goes out of scope, the original state is + * restored. + */ +struct SavedAlternateState +{ + bool m_bDiscardChildren; + bool m_bTookChoice; ///< Did we take the Choice or want Fallback instead? +}; + +class OOXMLParserState final : public virtual SvRefBase +{ + bool mbInSectionGroup; + bool mbInParagraphGroup; + bool mbInCharacterGroup; + bool mbLastParagraphInSection; + bool mbForwardEvents; + unsigned int mnContexts; + unsigned int mnHandle; + OOXMLDocumentImpl* mpDocument; + OOXMLPropertySet::Pointer_t mpCharacterProps; + std::stack mCellProps; + std::stack mRowProps; + std::stack mTableProps; + bool inTxbxContent; + // these 4 save when inTxbxContent + bool savedInParagraphGroup; + bool savedInCharacterGroup; + bool savedLastParagraphInSection; + std::vector maSavedAlternateStates; + std::vector mvPostponedBreaks; + +public: + typedef tools::SvRef Pointer_t; + + OOXMLParserState(); + ~OOXMLParserState() override; + + bool isInSectionGroup() const { return mbInSectionGroup;} + void setInSectionGroup(bool bInSectionGroup); + + void setLastParagraphInSection(bool bLastParagraphInSection); + bool isLastParagraphInSection() const { return mbLastParagraphInSection;} + + std::vector& getSavedAlternateStates() { return maSavedAlternateStates; } + + bool isInParagraphGroup() const { return mbInParagraphGroup;} + void setInParagraphGroup(bool bInParagraphGroup); + + bool isInCharacterGroup() const { return mbInCharacterGroup;} + void setInCharacterGroup(bool bInCharacterGroup); + + void setForwardEvents(bool bForwardEvents); + bool isForwardEvents() const { return mbForwardEvents;} + + std::string getHandle() const; + void setHandle(); + + void setDocument(OOXMLDocumentImpl* pDocument); + OOXMLDocumentImpl* getDocument() const { return mpDocument;} + + void setXNoteId(const sal_Int32 rId); + sal_Int32 getXNoteId() const; + + const OUString & getTarget() const; + + void resolveCharacterProperties(Stream & rStream); + void setCharacterProperties(const OOXMLPropertySet::Pointer_t& pProps); + void resolveCellProperties(Stream & rStream); + void setCellProperties(const OOXMLPropertySet::Pointer_t& pProps); + void resolveRowProperties(Stream & rStream); + void setRowProperties(const OOXMLPropertySet::Pointer_t& pProps); + void resolveTableProperties(Stream & rStream); + void setTableProperties(const OOXMLPropertySet::Pointer_t& pProps); + // tdf#108714 + void resolvePostponedBreak(Stream & rStream); + void setPostponedBreak(const OOXMLPropertySet::Pointer_t& pProps); + + void startTable(); + void endTable(); + + void incContextCount(); + + void startTxbxContent(); + void endTxbxContent(); + +}; + +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLPARSERSTATE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.cxx b/writerfilter/source/ooxml/OOXMLPropertySet.cxx new file mode 100644 index 000000000..b80710114 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLPropertySet.cxx @@ -0,0 +1,859 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "OOXMLPropertySet.hxx" +#include +#include +#include +#include +#include +#include + +namespace writerfilter::ooxml +{ +using namespace ::std; +using namespace com::sun::star; + +OOXMLProperty::OOXMLProperty(Id id, const OOXMLValue::Pointer_t& pValue, + OOXMLProperty::Type_t eType) + : mId(id), mpValue(pValue), meType(eType) +{ +} + +OOXMLProperty::~OOXMLProperty() +{ +} + +sal_uInt32 OOXMLProperty::getId() const +{ + return mId; +} + +Value::Pointer_t OOXMLProperty::getValue() +{ + Value::Pointer_t pResult; + + if (mpValue.get() != nullptr) + pResult = Value::Pointer_t(mpValue->clone()); + else + pResult = Value::Pointer_t(new OOXMLValue()); + + return pResult; +} + +writerfilter::Reference::Pointer_t OOXMLProperty::getProps() +{ + writerfilter::Reference::Pointer_t pResult; + + if (mpValue.get() != nullptr) + pResult = mpValue->getProperties(); + + return pResult; +} + +#ifdef DBG_UTIL +string OOXMLProperty::getName() const +{ + string sResult(QNameToString(mId)); + + if (sResult.length() == 0) + sResult = fastTokenToId(mId); + + if (sResult.length() == 0) + { + static char sBuffer[256]; + + snprintf(sBuffer, sizeof(sBuffer), "%" SAL_PRIxUINT32, mId); + sResult = sBuffer; + } + + return sResult; +} +#endif + +#ifdef DBG_UTIL +string OOXMLProperty::toString() const +{ + string sResult = "("; + + sResult += getName(); + sResult += ", "; + if (mpValue.get() != nullptr) + sResult += mpValue->toString(); + else + sResult +="(null)"; + sResult +=")"; + + return sResult; +} +#endif + +void OOXMLProperty::resolve(writerfilter::Properties & rProperties) +{ + switch (meType) + { + case SPRM: + if (mId != 0x0) + rProperties.sprm(*this); + break; + case ATTRIBUTE: + rProperties.attribute(mId, *getValue()); + break; + } +} + +/* + class OOXMLValue +*/ + +OOXMLValue::OOXMLValue() +{ +} + +OOXMLValue::~OOXMLValue() +{ +} + +int OOXMLValue::getInt() const +{ + return 0; +} + +OUString OOXMLValue::getString() const +{ + return OUString(); +} + +uno::Any OOXMLValue::getAny() const +{ + return uno::Any(); +} + +writerfilter::Reference::Pointer_t OOXMLValue::getProperties() +{ + return writerfilter::Reference::Pointer_t(); +} + +writerfilter::Reference::Pointer_t OOXMLValue::getBinary() +{ + return writerfilter::Reference::Pointer_t(); +} + +#ifdef DBG_UTIL +string OOXMLValue::toString() const +{ + return "OOXMLValue"; +} +#endif + +OOXMLValue * OOXMLValue::clone() const +{ + return new OOXMLValue(*this); +} + +/* + class OOXMLBinaryValue + */ + +OOXMLBinaryValue::OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t const & + pBinaryObj) +: mpBinaryObj(pBinaryObj) +{ +} + +OOXMLBinaryValue::~OOXMLBinaryValue() +{ +} + +writerfilter::Reference::Pointer_t OOXMLBinaryValue::getBinary() +{ + return mpBinaryObj; +} + +#ifdef DBG_UTIL +string OOXMLBinaryValue::toString() const +{ + return "BinaryObj"; +} +#endif + +OOXMLValue * OOXMLBinaryValue::clone() const +{ + return new OOXMLBinaryValue(mpBinaryObj); +} + +/* + class OOXMLBooleanValue +*/ + +static bool GetBooleanValue(const char *pValue) +{ + return !strcmp(pValue, "true") + || !strcmp(pValue, "True") + || !strcmp(pValue, "1") + || !strcmp(pValue, "on") + || !strcmp(pValue, "On"); +} + +OOXMLValue::Pointer_t const & OOXMLBooleanValue::Create(bool bValue) +{ + static OOXMLValue::Pointer_t False(new OOXMLBooleanValue (false)); + static OOXMLValue::Pointer_t True(new OOXMLBooleanValue (true)); + + return bValue ? True : False; +} + +OOXMLValue::Pointer_t const & OOXMLBooleanValue::Create(const char *pValue) +{ + return Create (GetBooleanValue(pValue)); +} + +OOXMLBooleanValue::OOXMLBooleanValue(bool bValue) +: mbValue(bValue) +{ +} + +OOXMLBooleanValue::~OOXMLBooleanValue() +{ +} + +int OOXMLBooleanValue::getInt() const +{ + return mbValue ? 1 : 0; +} + +uno::Any OOXMLBooleanValue::getAny() const +{ + return uno::Any(mbValue); +} + +#ifdef DBG_UTIL +string OOXMLBooleanValue::toString() const +{ + return mbValue ? "true" : "false"; +} +#endif + +OOXMLValue * OOXMLBooleanValue::clone() const +{ + return new OOXMLBooleanValue(*this); +} + +/* + class OOXMLStringValue +*/ + +OOXMLStringValue::OOXMLStringValue(const OUString & rStr) +: mStr(rStr) +{ +} + +OOXMLStringValue::~OOXMLStringValue() +{ +} + +uno::Any OOXMLStringValue::getAny() const +{ + return uno::Any(mStr); +} + +OUString OOXMLStringValue::getString() const +{ + return mStr; +} + +#ifdef DBG_UTIL +string OOXMLStringValue::toString() const +{ + return OUStringToOString(mStr, RTL_TEXTENCODING_ASCII_US).getStr(); +} +#endif + +OOXMLValue * OOXMLStringValue::clone() const +{ + return new OOXMLStringValue(*this); +} + +/* + class OOXMLInputStreamValue + */ +OOXMLInputStreamValue::OOXMLInputStreamValue(uno::Reference const & xInputStream) +: mxInputStream(xInputStream) +{ +} + +OOXMLInputStreamValue::~OOXMLInputStreamValue() +{ +} + +uno::Any OOXMLInputStreamValue::getAny() const +{ + return uno::Any(mxInputStream); +} + +#ifdef DBG_UTIL +string OOXMLInputStreamValue::toString() const +{ + return "InputStream"; +} +#endif + +OOXMLValue * OOXMLInputStreamValue::clone() const +{ + return new OOXMLInputStreamValue(mxInputStream); +} + +/** + class OOXMLPropertySet +*/ + +OOXMLPropertySet::OOXMLPropertySet() +{ +} + +OOXMLPropertySet::~OOXMLPropertySet() +{ +} + +void OOXMLPropertySet::resolve(Properties & rHandler) +{ + // The pProp->resolve(rHandler) call below can cause elements to + // be appended to mProperties. I don't think it can cause elements + // to be deleted. But let's check with < here just to be safe that + // the indexing below works. + for (size_t nIt = 0; nIt < mProperties.size(); ++nIt) + { + OOXMLProperty::Pointer_t pProp = mProperties[nIt]; + + if (pProp.get() != nullptr) + pProp->resolve(rHandler); + } +} + +OOXMLPropertySet::OOXMLProperties_t::iterator OOXMLPropertySet::begin() +{ + return mProperties.begin(); +} + +OOXMLPropertySet::OOXMLProperties_t::iterator OOXMLPropertySet::end() +{ + return mProperties.end(); +} + +OOXMLPropertySet::OOXMLProperties_t::const_iterator +OOXMLPropertySet::begin() const +{ + return mProperties.begin(); +} + +OOXMLPropertySet::OOXMLProperties_t::const_iterator +OOXMLPropertySet::end() const +{ + return mProperties.end(); +} + +void OOXMLPropertySet::add(const OOXMLProperty::Pointer_t& pProperty) +{ + if (pProperty.get() != nullptr && pProperty->getId() != 0x0) + { + mProperties.push_back(pProperty); + } +} + +void OOXMLPropertySet::add(Id id, const OOXMLValue::Pointer_t& pValue, OOXMLProperty::Type_t eType) +{ + OOXMLProperty::Pointer_t pProperty(new OOXMLProperty(id, pValue, eType)); + add(pProperty); +} + +void OOXMLPropertySet::add(const OOXMLPropertySet::Pointer_t& pPropertySet) +{ + const OOXMLPropertySet * pSet = pPropertySet.get(); + + if (pSet != nullptr) + { + int x = mProperties.size(); + mProperties.resize(mProperties.size() + pSet->mProperties.size()); + std::copy(pSet->mProperties.begin(), pSet->mProperties.end(), mProperties.begin() + x); + } +} + +OOXMLPropertySet * OOXMLPropertySet::clone() const +{ + return new OOXMLPropertySet(*this); +} + +#ifdef DBG_UTIL +string OOXMLPropertySet::toString() +{ + string sResult = "["; + char sBuffer[256]; + snprintf(sBuffer, sizeof(sBuffer), "%p", this); + sResult += sBuffer; + sResult += ":"; + + OOXMLProperties_t::iterator aItBegin = begin(); + OOXMLProperties_t::iterator aItEnd = end(); + + for (OOXMLProperties_t::iterator aIt = aItBegin; aIt != aItEnd; ++aIt) + { + if (aIt != aItBegin) + sResult += ", "; + + if ((*aIt).get() != nullptr) + sResult += (*aIt)->toString(); + else + sResult += "0x0"; + } + + sResult += "]"; + + return sResult; +} +#endif + +/* + class OOXMLPropertySetValue +*/ + +OOXMLPropertySetValue::OOXMLPropertySetValue(const OOXMLPropertySet::Pointer_t& pPropertySet) + : mpPropertySet(pPropertySet) +{ +} + +OOXMLPropertySetValue::~OOXMLPropertySetValue() +{ +} + +writerfilter::Reference::Pointer_t OOXMLPropertySetValue::getProperties() +{ + return writerfilter::Reference::Pointer_t + (mpPropertySet->clone()); +} + +#ifdef DBG_UTIL +string OOXMLPropertySetValue::toString() const +{ + char sBuffer[256]; + + snprintf(sBuffer, sizeof(sBuffer), "t:%p, m:%p", this, mpPropertySet.get()); + + return "OOXMLPropertySetValue(" + string(sBuffer) + ")"; +} +#endif + +OOXMLValue * OOXMLPropertySetValue::clone() const +{ + return new OOXMLPropertySetValue(*this); +} + +/* + class OOXMLIntegerValue +*/ + +OOXMLValue::Pointer_t OOXMLIntegerValue::Create(sal_Int32 nValue) +{ + static OOXMLValue::Pointer_t Zero(new OOXMLIntegerValue (0)); + static OOXMLValue::Pointer_t One(new OOXMLIntegerValue (1)); + static OOXMLValue::Pointer_t Two(new OOXMLIntegerValue (2)); + static OOXMLValue::Pointer_t Three(new OOXMLIntegerValue (3)); + static OOXMLValue::Pointer_t Four(new OOXMLIntegerValue (4)); + static OOXMLValue::Pointer_t Five(new OOXMLIntegerValue (5)); + static OOXMLValue::Pointer_t Six(new OOXMLIntegerValue (6)); + static OOXMLValue::Pointer_t Seven(new OOXMLIntegerValue (7)); + static OOXMLValue::Pointer_t Eight(new OOXMLIntegerValue (8)); + static OOXMLValue::Pointer_t Nine(new OOXMLIntegerValue (9)); + + switch (nValue) { + case 0: return Zero; + case 1: return One; + case 2: return Two; + case 3: return Three; + case 4: return Four; + case 5: return Five; + case 6: return Six; + case 7: return Seven; + case 8: return Eight; + case 9: return Nine; + default: break; + } + + OOXMLValue::Pointer_t value(new OOXMLIntegerValue(nValue)); + + return value; +} + +OOXMLIntegerValue::OOXMLIntegerValue(sal_Int32 nValue) +: mnValue(nValue) +{ +} + +OOXMLIntegerValue::~OOXMLIntegerValue() +{ +} + +int OOXMLIntegerValue::getInt() const +{ + return mnValue; +} + +uno::Any OOXMLIntegerValue::getAny() const +{ + return uno::Any(mnValue); +} + +OOXMLValue * OOXMLIntegerValue::clone() const +{ + return new OOXMLIntegerValue(*this); +} + +#ifdef DBG_UTIL +string OOXMLIntegerValue::toString() const +{ + char buffer[256]; + snprintf(buffer, sizeof(buffer), "%" SAL_PRIdINT32, mnValue); + + return buffer; +} +#endif + +/* + class OOXMLHexValue +*/ + +OOXMLHexValue::OOXMLHexValue(sal_uInt32 nValue) +: mnValue(nValue) +{ +} + +OOXMLHexValue::OOXMLHexValue(const char * pValue) +: mnValue(rtl_str_toUInt32(pValue, 16)) +{ +} + +OOXMLHexValue::~OOXMLHexValue() +{ +} + +int OOXMLHexValue::getInt() const +{ + return mnValue; +} + +OOXMLValue * OOXMLHexValue::clone() const +{ + return new OOXMLHexValue(*this); +} + +#ifdef DBG_UTIL +string OOXMLHexValue::toString() const +{ + char buffer[256]; + snprintf(buffer, sizeof(buffer), "0x%" SAL_PRIxUINT32, mnValue); + + return buffer; +} +#endif + +/* + class OOXMLHexColorValue +*/ +OOXMLHexColorValue::OOXMLHexColorValue(const char * pValue) + : OOXMLHexValue(sal_uInt32(COL_AUTO)) +{ + if (strcmp(pValue, "auto")) + { + mnValue = rtl_str_toUInt32(pValue, 16); + + // Convert hash-encoded values (like #FF0080) + const sal_Int32 nLen = strlen(pValue); + if ( !mnValue && nLen > 1 && pValue[0] == '#' ) + { + sal_Int32 nColor(COL_AUTO); + // Word appears to require strict 6 digit length, else it ignores it + if ( nLen == 7 ) + { + const OUString sHashColor(pValue, nLen, RTL_TEXTENCODING_ASCII_US); + sax::Converter::convertColor( nColor, sHashColor ); + } + mnValue = nColor; + } + } +} + +// OOXMLUniversalMeasureValue +// ECMA-376 5th ed. Part 1 , 22.9.2.15 +OOXMLUniversalMeasureValue::OOXMLUniversalMeasureValue(const char * pValue, sal_uInt32 npPt) +{ + double val = rtl_str_toDouble(pValue); // will ignore the trailing unit + + int nLen = strlen(pValue); + if (nLen > 2 && + pValue[nLen-2] == 'p' && + pValue[nLen-1] == 't') + { + mnValue = static_cast(val * npPt); + } + else if (nLen > 2 && + pValue[nLen - 2] == 'c' && + pValue[nLen - 1] == 'm') + { + mnValue = static_cast(val * npPt * 72 / 2.54); + } + else if (nLen > 2 && + pValue[nLen - 2] == 'm' && + pValue[nLen - 1] == 'm') + { + mnValue = static_cast(val * npPt * 72 / 25.4); + } + else if (nLen > 2 && + pValue[nLen - 2] == 'i' && + pValue[nLen - 1] == 'n') + { + mnValue = static_cast(val * npPt * 72); + } + else if (nLen > 2 && + pValue[nLen - 2] == 'p' && + ( pValue[nLen - 1] == 'c' || pValue[nLen - 1] == 'i' )) + { + mnValue = static_cast(val * npPt * 12); + } + else + { + mnValue = static_cast(val); + } +} + +OOXMLUniversalMeasureValue::~OOXMLUniversalMeasureValue() +{ +} + +int OOXMLUniversalMeasureValue::getInt() const +{ + return mnValue; +} + +#ifdef DBG_UTIL +string OOXMLUniversalMeasureValue::toString() const +{ + return OString::number(mnValue).getStr(); +} +#endif + +// OOXMLMeasurementOrPercentValue +// ECMA-376 5th ed. Part 1 , 17.18.107; 17.18.11 +OOXMLMeasurementOrPercentValue::OOXMLMeasurementOrPercentValue(const char * pValue) +{ + double val = rtl_str_toDouble(pValue); // will ignore the trailing unit + + int nLen = strlen(pValue); + if (nLen > 1 && + pValue[nLen - 1] == '%') + { + mnValue = static_cast(val * 50); + } + else + { + mnValue = OOXMLTwipsMeasureValue(pValue).getInt(); + } +} + +int OOXMLMeasurementOrPercentValue::getInt() const +{ + return mnValue; +} + +#ifdef DBG_UTIL +string OOXMLMeasurementOrPercentValue::toString() const +{ + return OString::number(mnValue).getStr(); +} +#endif + +/* + class OOXMLShapeValue + */ + + +OOXMLShapeValue::OOXMLShapeValue(uno::Reference const & rShape) +: mrShape(rShape) +{ +} + +OOXMLShapeValue::~OOXMLShapeValue() +{ +} + +uno::Any OOXMLShapeValue::getAny() const +{ + return uno::Any(mrShape); +} + +#ifdef DBG_UTIL +string OOXMLShapeValue::toString() const +{ + return "Shape"; +} +#endif + +OOXMLValue * OOXMLShapeValue::clone() const +{ + return new OOXMLShapeValue(mrShape); +} + +/* + class OOXMLStarMathValue + */ + + +OOXMLStarMathValue::OOXMLStarMathValue( uno::Reference< embed::XEmbeddedObject > const & c ) +: component(c) +{ +} + +OOXMLStarMathValue::~OOXMLStarMathValue() +{ +} + +uno::Any OOXMLStarMathValue::getAny() const +{ + return uno::Any(component); +} + +#ifdef DBG_UTIL +string OOXMLStarMathValue::toString() const +{ + return "StarMath"; +} +#endif + +OOXMLValue * OOXMLStarMathValue::clone() const +{ + return new OOXMLStarMathValue( component ); +} + +/* + class OOXMLTableImpl + */ + +OOXMLTable::OOXMLTable() +{ +} + +OOXMLTable::~OOXMLTable() +{ +} + + +void OOXMLTable::resolve(Table & rTable) +{ + Table * pTable = &rTable; + + int nPos = 0; + + for (const auto& rPropSet : mPropertySets) + { + writerfilter::Reference::Pointer_t pProperties + (rPropSet->getProperties()); + + if (pProperties.get() != nullptr) + pTable->entry(nPos, pProperties); + + ++nPos; + } +} + +void OOXMLTable::add(const ValuePointer_t& pPropertySet) +{ + if (pPropertySet.get() != nullptr) + mPropertySets.push_back(pPropertySet); +} + +OOXMLTable * OOXMLTable::clone() const +{ + return new OOXMLTable(*this); +} + +/* + class: OOXMLPropertySetEntryToString +*/ + +OOXMLPropertySetEntryToString::OOXMLPropertySetEntryToString(Id nId) +: mnId(nId) +{ +} + +OOXMLPropertySetEntryToString::~OOXMLPropertySetEntryToString() +{ +} + +void OOXMLPropertySetEntryToString::sprm(Sprm & /*rSprm*/) +{ +} + +void OOXMLPropertySetEntryToString::attribute(Id nId, Value & rValue) +{ + if (nId == mnId) + mStr = rValue.getString(); +} + +/* + class: OOXMLPropertySetEntryToInteger +*/ + +OOXMLPropertySetEntryToInteger::OOXMLPropertySetEntryToInteger(Id nId) +: mnId(nId), mnValue(0) +{ +} + +OOXMLPropertySetEntryToInteger::~OOXMLPropertySetEntryToInteger() +{ +} + +void OOXMLPropertySetEntryToInteger::sprm(Sprm & /*rSprm*/) +{ +} + +void OOXMLPropertySetEntryToInteger::attribute(Id nId, Value & rValue) +{ + if (nId == mnId) + mnValue = rValue.getInt(); +} + +/* + class: OOXMLPropertySetEntryToBool +*/ + +OOXMLPropertySetEntryToBool::OOXMLPropertySetEntryToBool(Id nId) + : mnId(nId), mValue(false) +{} + +OOXMLPropertySetEntryToBool::~OOXMLPropertySetEntryToBool() {} + +void OOXMLPropertySetEntryToBool::sprm(Sprm & /*rSprm*/) {} + +void OOXMLPropertySetEntryToBool::attribute(Id nId, Value & rValue) +{ + if (nId == mnId) + mValue = (rValue.getInt() != 0); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLPropertySet.hxx b/writerfilter/source/ooxml/OOXMLPropertySet.hxx new file mode 100644 index 000000000..f31d46fce --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLPropertySet.hxx @@ -0,0 +1,402 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLPROPERTYSET_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLPROPERTYSET_HXX + +#include +#include "OOXMLBinaryObjectReference.hxx" +#include +#include + +namespace writerfilter { +namespace ooxml +{ + +class OOXMLValue : public Value +{ +public: + typedef tools::SvRef Pointer_t; + OOXMLValue(); + virtual ~OOXMLValue() override; + + OOXMLValue(OOXMLValue const &) = default; + OOXMLValue(OOXMLValue &&) = default; + OOXMLValue & operator =(OOXMLValue const &) = default; + OOXMLValue & operator =(OOXMLValue &&) = default; + + virtual int getInt() const override; + ; + virtual OUString getString() const override; + virtual css::uno::Any getAny() const override; + virtual writerfilter::Reference::Pointer_t getProperties() override; + virtual writerfilter::Reference::Pointer_t getBinary() override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const; +}; + +class OOXMLProperty : public Sprm +{ +public: + typedef tools::SvRef Pointer_t; + enum Type_t { SPRM, ATTRIBUTE }; +private: + Id mId; + mutable OOXMLValue::Pointer_t mpValue; + Type_t meType; + +public: + OOXMLProperty(Id id, const OOXMLValue::Pointer_t& pValue, Type_t eType); + OOXMLProperty(const OOXMLProperty & rSprm) = delete; + virtual ~OOXMLProperty() override; + + sal_uInt32 getId() const override; + Value::Pointer_t getValue() override; + writerfilter::Reference::Pointer_t getProps() override; +#ifdef DBG_UTIL + std::string getName() const override; + std::string toString() const override; +#endif + void resolve(Properties & rProperties); +}; + +class OOXMLBinaryValue : public OOXMLValue +{ + mutable OOXMLBinaryObjectReference::Pointer_t mpBinaryObj; +public: + explicit OOXMLBinaryValue(OOXMLBinaryObjectReference::Pointer_t const & pBinaryObj); + virtual ~OOXMLBinaryValue() override; + + virtual writerfilter::Reference::Pointer_t getBinary() override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLBooleanValue : public OOXMLValue +{ + bool mbValue; + explicit OOXMLBooleanValue(bool bValue); +public: + static OOXMLValue::Pointer_t const & Create (bool bValue); + static OOXMLValue::Pointer_t const & Create (const char *pValue); + + virtual ~OOXMLBooleanValue() override; + + OOXMLBooleanValue(OOXMLBooleanValue const &) = default; + OOXMLBooleanValue(OOXMLBooleanValue &&) = default; + OOXMLBooleanValue & operator =(OOXMLBooleanValue const &) = delete; // due to const mbValue + OOXMLBooleanValue & operator =(OOXMLBooleanValue &&) = delete; // due to const mbValue + + virtual int getInt() const override; + virtual css::uno::Any getAny() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLStringValue : public OOXMLValue +{ + OUString mStr; +public: + explicit OOXMLStringValue(const OUString & rStr); + virtual ~OOXMLStringValue() override; + + OOXMLStringValue(OOXMLStringValue const &) = default; + OOXMLStringValue(OOXMLStringValue &&) = default; + OOXMLStringValue & operator =(OOXMLStringValue const &) = delete; // due to const mStr + OOXMLStringValue & operator =(OOXMLStringValue &&) = delete; // due to const mStr + + virtual css::uno::Any getAny() const override; + virtual OUString getString() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLInputStreamValue : public OOXMLValue +{ + css::uno::Reference mxInputStream; + +public: + explicit OOXMLInputStreamValue(css::uno::Reference const & xInputStream); + virtual ~OOXMLInputStreamValue() override; + + virtual css::uno::Any getAny() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLPropertySet : public writerfilter::Reference +{ +public: + typedef std::vector OOXMLProperties_t; + typedef tools::SvRef Pointer_t; +private: + OOXMLProperties_t mProperties; + void add(const OOXMLProperty::Pointer_t& pProperty); +public: + OOXMLPropertySet(); + virtual ~OOXMLPropertySet() override; + + OOXMLPropertySet(OOXMLPropertySet const &) = default; + OOXMLPropertySet(OOXMLPropertySet &&) = default; + OOXMLPropertySet & operator =(OOXMLPropertySet const &) = default; + OOXMLPropertySet & operator =(OOXMLPropertySet &&) = default; + + void resolve(Properties & rHandler) override; + void add(Id id, const OOXMLValue::Pointer_t& pValue, OOXMLProperty::Type_t eType); + void add(const OOXMLPropertySet::Pointer_t& pPropertySet); + OOXMLPropertySet * clone() const; + + OOXMLProperties_t::iterator begin(); + OOXMLProperties_t::iterator end(); + OOXMLProperties_t::const_iterator begin() const; + OOXMLProperties_t::const_iterator end() const; + +#ifdef DBG_UTIL + std::string toString(); +#endif +}; + +class OOXMLValue; + +class OOXMLTable : public writerfilter::Reference
+{ +public: + typedef tools::SvRef ValuePointer_t; + OOXMLTable(); + virtual ~OOXMLTable() override; + + OOXMLTable(OOXMLTable const &) = default; + OOXMLTable(OOXMLTable &&) = default; + OOXMLTable & operator =(OOXMLTable const &) = default; + OOXMLTable & operator =(OOXMLTable &&) = default; + + void resolve(Table & rTable) override; + void add(const ValuePointer_t& pPropertySet); + OOXMLTable * clone() const; +private: + typedef std::vector PropertySets_t; + PropertySets_t mPropertySets; +}; + +class OOXMLPropertySetValue : public OOXMLValue +{ + OOXMLPropertySet::Pointer_t mpPropertySet; +public: + explicit OOXMLPropertySetValue(const OOXMLPropertySet::Pointer_t& pPropertySet); + virtual ~OOXMLPropertySetValue() override; + + OOXMLPropertySetValue(OOXMLPropertySetValue const &) = default; + OOXMLPropertySetValue(OOXMLPropertySetValue &&) = default; + OOXMLPropertySetValue & operator =(OOXMLPropertySetValue const &) = delete; // due to const mpPropertySet + OOXMLPropertySetValue & operator =(OOXMLPropertySetValue &&) = delete; // due to const mpPropertySet + + virtual writerfilter::Reference::Pointer_t getProperties() override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLIntegerValue : public OOXMLValue +{ + sal_Int32 mnValue; + explicit OOXMLIntegerValue(sal_Int32 nValue); +public: + static OOXMLValue::Pointer_t Create (sal_Int32 nValue); + virtual ~OOXMLIntegerValue() override; + + OOXMLIntegerValue(OOXMLIntegerValue const &) = default; + OOXMLIntegerValue(OOXMLIntegerValue &&) = default; + OOXMLIntegerValue & operator =(OOXMLIntegerValue const &) = delete; // due to const mnValue + OOXMLIntegerValue & operator =(OOXMLIntegerValue &&) = delete; // due to const mnValue + + virtual int getInt() const override; + virtual css::uno::Any getAny() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLHexValue : public OOXMLValue +{ +protected: + sal_uInt32 mnValue; +public: + explicit OOXMLHexValue(sal_uInt32 nValue); + explicit OOXMLHexValue(const char * pValue); + virtual ~OOXMLHexValue() override; + + OOXMLHexValue(OOXMLHexValue const &) = default; + OOXMLHexValue(OOXMLHexValue &&) = default; + OOXMLHexValue & operator =(OOXMLHexValue const &) = default; + OOXMLHexValue & operator =(OOXMLHexValue &&) = default; + + virtual int getInt() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLHexColorValue : public OOXMLHexValue +{ +public: + explicit OOXMLHexColorValue(const char * pValue); +}; + +class OOXMLUniversalMeasureValue : public OOXMLValue +{ +private: + int mnValue; +public: + OOXMLUniversalMeasureValue(const char * pValue, sal_uInt32 npPt); + virtual ~OOXMLUniversalMeasureValue() override; + + OOXMLUniversalMeasureValue(OOXMLUniversalMeasureValue const &) = default; + OOXMLUniversalMeasureValue(OOXMLUniversalMeasureValue &&) = default; + OOXMLUniversalMeasureValue & operator =(OOXMLUniversalMeasureValue const &) = default; + OOXMLUniversalMeasureValue & operator =(OOXMLUniversalMeasureValue &&) = default; + + virtual int getInt() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif +}; + +/// npPt is quotient defining how much units are in 1 pt +template class OOXMLNthPtMeasureValue : public OOXMLUniversalMeasureValue +{ +public: + explicit OOXMLNthPtMeasureValue(const char * pValue) + : OOXMLUniversalMeasureValue(pValue, npPt) {} + virtual OOXMLValue* clone() const override + { + return new OOXMLNthPtMeasureValue(*this); + } +}; + +/// Handles OOXML's ST_TwipsMeasure value. +typedef OOXMLNthPtMeasureValue<20> OOXMLTwipsMeasureValue; + +/// Handles OOXML's ST_HpsMeasure value. +typedef OOXMLNthPtMeasureValue<2> OOXMLHpsMeasureValue; + +class OOXMLMeasurementOrPercentValue : public OOXMLValue +{ + int mnValue; +public: + explicit OOXMLMeasurementOrPercentValue(const char * pValue); + + virtual int getInt() const override; + virtual OOXMLValue* clone() const override + { + return new OOXMLMeasurementOrPercentValue(*this); + } +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif +}; + +class OOXMLShapeValue : public OOXMLValue +{ + css::uno::Reference mrShape; +public: + explicit OOXMLShapeValue(css::uno::Reference const & rShape); + virtual ~OOXMLShapeValue() override; + + virtual css::uno::Any getAny() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLStarMathValue : public OOXMLValue +{ + css::uno::Reference< css::embed::XEmbeddedObject > component; +public: + explicit OOXMLStarMathValue( css::uno::Reference< css::embed::XEmbeddedObject > const & component ); + virtual ~OOXMLStarMathValue() override; + + virtual css::uno::Any getAny() const override; +#ifdef DBG_UTIL + virtual std::string toString() const override; +#endif + virtual OOXMLValue * clone() const override; +}; + +class OOXMLPropertySetEntryToString : public Properties +{ + Id mnId; + OUString mStr; + +public: + explicit OOXMLPropertySetEntryToString(Id nId); + virtual ~OOXMLPropertySetEntryToString() override; + + virtual void sprm(Sprm & rSprm) override; + virtual void attribute(Id nId, Value & rValue) override; + + const OUString & getString() const { return mStr;} +}; + +class OOXMLPropertySetEntryToInteger : public Properties +{ + Id mnId; + int mnValue; +public: + explicit OOXMLPropertySetEntryToInteger(Id nId); + virtual ~OOXMLPropertySetEntryToInteger() override; + + virtual void sprm(Sprm & rSprm) override; + virtual void attribute(Id nId, Value & rValue) override; + + int getValue() const { return mnValue;} +}; + +class OOXMLPropertySetEntryToBool : public Properties +{ + Id mnId; + bool mValue; +public: + explicit OOXMLPropertySetEntryToBool(Id nId); + virtual ~OOXMLPropertySetEntryToBool() override; + + virtual void sprm(Sprm & rSprm) override; + virtual void attribute(Id nId, Value & rValue) override; + + bool getValue() const { return mValue; } +}; + + +}} + +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLPROPERTYSET_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLStreamImpl.cxx b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx new file mode 100644 index 000000000..73e527a55 --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLStreamImpl.cxx @@ -0,0 +1,443 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "OOXMLStreamImpl.hxx" +#include + +#include +#include +#include + +namespace writerfilter::ooxml +{ + +using namespace com::sun::star; + +OOXMLStreamImpl::OOXMLStreamImpl +(uno::Reference const & xContext, + uno::Reference const & xStorageStream, + StreamType_t nType, bool bRepairStorage) +: mxContext(xContext), mxStorageStream(xStorageStream), mnStreamType(nType) +{ + mxStorage.set + (comphelper::OStorageHelper::GetStorageOfFormatFromInputStream + (OFOPXML_STORAGE_FORMAT_STRING, mxStorageStream, xContext, bRepairStorage)); + mxRelationshipAccess.set(mxStorage, uno::UNO_QUERY_THROW); + + init(); +} + +OOXMLStreamImpl::OOXMLStreamImpl +(OOXMLStreamImpl const & rOOXMLStream, StreamType_t nStreamType) +: mxContext(rOOXMLStream.mxContext), + mxStorageStream(rOOXMLStream.mxStorageStream), + mxStorage(rOOXMLStream.mxStorage), + mnStreamType(nStreamType), + msPath(rOOXMLStream.msPath) +{ + mxRelationshipAccess.set(rOOXMLStream.mxDocumentStream, uno::UNO_QUERY_THROW); + + init(); +} + +OOXMLStreamImpl::OOXMLStreamImpl +(OOXMLStreamImpl const & rOOXMLStream, const OUString & rId) +: mxContext(rOOXMLStream.mxContext), + mxStorageStream(rOOXMLStream.mxStorageStream), + mxStorage(rOOXMLStream.mxStorage), + mnStreamType(UNKNOWN), + msId(rId), + msPath(rOOXMLStream.msPath) +{ + mxRelationshipAccess.set(rOOXMLStream.mxDocumentStream, uno::UNO_QUERY_THROW); + + init(); +} + +OOXMLStreamImpl::~OOXMLStreamImpl() +{ +} + +const OUString & OOXMLStreamImpl::getTarget() const +{ + return msTarget; +} + +bool OOXMLStreamImpl::lcl_getTarget(const uno::Reference& + xRelationshipAccess, + StreamType_t nStreamType, + const OUString & rId, + OUString & rDocumentTarget) +{ + static const char sId[] = "Id"; + static const char sTarget[] = "Target"; + static const char sTargetMode[] = "TargetMode"; + static const char sExternal[] = "External"; + if (maIdCache.empty()) + { + // Cache is empty? Then let's build it! + const uno::Sequence< uno::Sequence >aSeqs = xRelationshipAccess->getAllRelationships(); + for (const uno::Sequence& rSeq : aSeqs) + { + OUString aId; + OUString aTarget; + bool bExternal = false; + for (const beans::StringPair& rPair : rSeq) + { + if (rPair.First == sId) + aId = rPair.Second; + else if (rPair.First == sTarget) + aTarget = rPair.Second; + else if (rPair.First == sTargetMode && rPair.Second == sExternal) + bExternal = true; + } + // Only cache external targets, internal ones are more complex (see below) + if (bExternal || aTarget.startsWith("#")) + maIdCache[aId] = aTarget; + } + } + + if (maIdCache.find(rId) != maIdCache.end()) + { + rDocumentTarget = maIdCache[rId]; + return true; + } + + bool bFound = false; + static uno::Reference xFac = uri::UriReferenceFactory::create(mxContext); + // use '/' to representent the root of the zip package ( and provide a 'file' scheme to + // keep the XUriReference implementation happy ) + // add mspath to represent the 'source' of this stream + uno::Reference xBase = xFac->parse("file:///" + msPath); + + static const char sType[] = "Type"; + static const char sDocumentType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"; + static const char sStylesType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"; + static const char sNumberingType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering"; + static const char sFonttableType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"; + static const char sFootnotesType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes"; + static const char sEndnotesType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"; + static const char sCommentsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"; + static const char sThemeType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"; + static const char sCustomType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"; + static const char sCustomPropsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps"; + static const char sGlossaryType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument"; + static const char sWebSettings[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings"; + static const char sSettingsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"; + static const char sChartType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"; + static const char sEmbeddingsType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package"; + static const char sFooterType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer"; + static const char sHeaderType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header"; + static const char sOleObjectType[] = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"; + // OOXML strict + static const char sDocumentTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument"; + static const char sStylesTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/styles"; + static const char sNumberingTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/numbering"; + static const char sFonttableTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/fontTable"; + static const char sFootnotesTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/footnotes"; + static const char sEndnotesTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/endnotes"; + static const char sCommentsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/comments"; + static const char sThemeTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/theme"; + static const char sCustomTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/customXml"; + static const char sCustomPropsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/customXmlProps"; + static const char sGlossaryTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/glossaryDocument"; + static const char sWebSettingsStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/webSettings"; + static const char sSettingsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/settings"; + static const char sChartTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/chart"; + static const char sEmbeddingsTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/package"; + static const char sFootersTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/footer"; + static const char sHeaderTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/header"; + static const char sOleObjectTypeStrict[] = "http://purl.oclc.org/ooxml/officeDocument/relationships/oleObject"; + static const char sVBAProjectType[] = "http://schemas.microsoft.com/office/2006/relationships/vbaProject"; + static const char sVBADataType[] = "http://schemas.microsoft.com/office/2006/relationships/wordVbaData"; + + OUString sStreamType; + OUString sStreamTypeStrict; + + switch (nStreamType) + { + case VBAPROJECT: + sStreamType = sVBAProjectType; + sStreamTypeStrict = sVBAProjectType; + break; + case VBADATA: + sStreamType = sVBADataType; + sStreamTypeStrict = sVBADataType; + break; + case DOCUMENT: + sStreamType = sDocumentType; + sStreamTypeStrict = sDocumentTypeStrict; + break; + case STYLES: + sStreamType = sStylesType; + sStreamTypeStrict = sStylesTypeStrict; + break; + case NUMBERING: + sStreamType = sNumberingType; + sStreamTypeStrict = sNumberingTypeStrict; + break; + case FONTTABLE: + sStreamType = sFonttableType; + sStreamTypeStrict = sFonttableTypeStrict; + break; + case FOOTNOTES: + sStreamType = sFootnotesType; + sStreamTypeStrict = sFootnotesTypeStrict; + break; + case ENDNOTES: + sStreamType = sEndnotesType; + sStreamTypeStrict = sEndnotesTypeStrict; + break; + case COMMENTS: + sStreamType = sCommentsType; + sStreamTypeStrict = sCommentsTypeStrict; + break; + case THEME: + sStreamType = sThemeType; + sStreamTypeStrict = sThemeTypeStrict; + break; + case CUSTOMXML: + sStreamType = sCustomType; + sStreamTypeStrict = sCustomTypeStrict; + break; + case CUSTOMXMLPROPS: + sStreamType = sCustomPropsType; + sStreamTypeStrict = sCustomPropsTypeStrict; + break; + case SETTINGS: + sStreamType = sSettingsType; + sStreamTypeStrict = sSettingsTypeStrict; + break; + case GLOSSARY: + sStreamType = sGlossaryType; + sStreamTypeStrict = sGlossaryTypeStrict; + break; + case WEBSETTINGS: + sStreamType = sWebSettings; + sStreamTypeStrict = sWebSettingsStrict; + break; + case CHARTS: + sStreamType = sChartType; + sStreamTypeStrict = sChartTypeStrict; + break; + case EMBEDDINGS: + sStreamType = sEmbeddingsType; + sStreamTypeStrict = sEmbeddingsTypeStrict; + break; + case FOOTER: + sStreamType = sFooterType; + sStreamTypeStrict = sFootersTypeStrict; + break; + case HEADER: + sStreamType = sHeaderType; + sStreamTypeStrict = sHeaderTypeStrict; + break; + default: + break; + } + + if (xRelationshipAccess.is()) + { + const uno::Sequence< uno::Sequence< beans::StringPair > >aSeqs = + xRelationshipAccess->getAllRelationships(); + + for (const uno::Sequence< beans::StringPair > &rSeq : aSeqs) + { + bool bExternalTarget = false; + OUString sMyTarget; + for (const beans::StringPair &rPair : rSeq) + { + if (rPair.First == sType && + ( rPair.Second == sStreamType || + rPair.Second == sStreamTypeStrict )) + bFound = true; + else if(rPair.First == sType && + ((rPair.Second == sOleObjectType || + rPair.Second == sOleObjectTypeStrict) && + nStreamType == EMBEDDINGS)) + { + bFound = true; + } + else if (rPair.First == sId && + rPair.Second == rId) + bFound = true; + else if (rPair.First == sTarget) + { + // checking item[n].xml is not visited already. + if(customTarget != rPair.Second && (sStreamType == sCustomType || sStreamType == sChartType || sStreamType == sFooterType || sStreamType == sHeaderType)) + { + bFound = false; + } + else + { + sMyTarget = rPair.Second; + } + } + else if (rPair.First == sTargetMode && + rPair.Second == sExternal) + bExternalTarget = true; + } + + if (bFound) + { + if (bExternalTarget) + rDocumentTarget = sMyTarget; + else + { + // 'Target' is a relative Uri, so a 'Target=/path' + // with a base Uri of file://base/foo will resolve to + // file://base/word. We need something more than some + // simple string concatenation here to handle that. + uno::Reference xPart = xFac->parse(sMyTarget); + uno::Reference xAbs = xFac->makeAbsolute(xBase, xPart, true, uri::RelativeUriExcessParentSegments_RETAIN); + if (!xAbs) + { + //it was invalid gibberish + bFound = false; + } + else + { + rDocumentTarget = xAbs->getPath(); + // path will start with the fragment separator. need to + // remove that + rDocumentTarget = rDocumentTarget.copy( 1 ); + if(sStreamType == sEmbeddingsType) + embeddingsTarget = rDocumentTarget; + } + } + + break; + } + } + } + + return bFound; +} + +OUString OOXMLStreamImpl::getTargetForId(const OUString & rId) +{ + OUString sTarget; + + uno::Reference xRelationshipAccess + (mxDocumentStream, uno::UNO_QUERY_THROW); + + if (lcl_getTarget(xRelationshipAccess, UNKNOWN, rId, sTarget)) + return sTarget; + + return OUString(); +} + +void OOXMLStreamImpl::init() +{ + bool bFound = lcl_getTarget(mxRelationshipAccess, + mnStreamType, msId, msTarget); + + if (bFound) + { + sal_Int32 nLastIndex = msTarget.lastIndexOf('/'); + if (nLastIndex >= 0) + msPath = msTarget.copy(0, nLastIndex + 1); + + uno::Reference + xHierarchicalStorageAccess(mxStorage, uno::UNO_QUERY); + + if (xHierarchicalStorageAccess.is()) + { + uno::Any aAny(xHierarchicalStorageAccess-> + openStreamElementByHierarchicalName + (msTarget, embed::ElementModes::SEEKABLEREAD)); + aAny >>= mxDocumentStream; + // Non-cached ID lookup works by accessing mxDocumentStream as an embed::XRelationshipAccess. + // So when it changes, we should empty the cache. + maIdCache.clear(); + } + } +} + +uno::Reference OOXMLStreamImpl::getDocumentStream() +{ + uno::Reference xResult; + + if (mxDocumentStream.is()) + xResult = mxDocumentStream->getInputStream(); + + return xResult; +} + +uno::Reference OOXMLStreamImpl::getContext() +{ + return mxContext; +} + +uno::Reference OOXMLStreamImpl::getFastTokenHandler() +{ + if (! mxFastTokenHandler.is()) + mxFastTokenHandler.set(new oox::core::FastTokenHandler()); + + return mxFastTokenHandler; +} + +OOXMLStream::Pointer_t +OOXMLDocumentFactory::createStream +(const uno::Reference& xContext, + const uno::Reference& rStream, + bool bRepairStorage) +{ + OOXMLStreamImpl * pStream = new OOXMLStreamImpl(xContext, rStream, + OOXMLStream::DOCUMENT, bRepairStorage); + return OOXMLStream::Pointer_t(pStream); +} + +OOXMLStream::Pointer_t +OOXMLDocumentFactory::createStream +(const OOXMLStream::Pointer_t& pStream, OOXMLStream::StreamType_t nStreamType) +{ + OOXMLStream::Pointer_t pRet; + + if (nStreamType != OOXMLStream::VBADATA) + { + if (OOXMLStreamImpl* pImpl = dynamic_cast(pStream.get())) + pRet = new OOXMLStreamImpl(*pImpl, nStreamType); + } + else + { + // VBADATA is not a relation of the document, but of the VBAPROJECT stream. + if (OOXMLStreamImpl* pImpl = dynamic_cast(pStream.get())) + { + std::unique_ptr pProject(new OOXMLStreamImpl(*pImpl, OOXMLStream::VBAPROJECT)); + pRet = new OOXMLStreamImpl(*pProject, OOXMLStream::VBADATA); + } + } + + return pRet; +} + +OOXMLStream::Pointer_t +OOXMLDocumentFactory::createStream +(const OOXMLStream::Pointer_t& pStream, const OUString & rId) +{ + OOXMLStream::Pointer_t pRet; + if (OOXMLStreamImpl* pImpl = dynamic_cast(pStream.get())) + pRet = new OOXMLStreamImpl(*pImpl, rId); + return pRet; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/OOXMLStreamImpl.hxx b/writerfilter/source/ooxml/OOXMLStreamImpl.hxx new file mode 100644 index 000000000..b7d5b4aaa --- /dev/null +++ b/writerfilter/source/ooxml/OOXMLStreamImpl.hxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLSTREAMIMPL_HXX +#define INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLSTREAMIMPL_HXX + +#include + +#include +#include + +extern OUString customTarget; +extern OUString embeddingsTarget; + +namespace writerfilter { +namespace ooxml +{ + +class OOXMLStreamImpl : public OOXMLStream +{ + void init(); + + css::uno::Reference mxContext; + css::uno::Reference mxStorageStream; + css::uno::Reference mxStorage; + css::uno::Reference mxRelationshipAccess; + css::uno::Reference mxDocumentStream; + css::uno::Reference mxFastParser; + css::uno::Reference mxFastTokenHandler; + + StreamType_t mnStreamType; + + OUString msId; + OUString msPath; + OUString msTarget; + + /// Cache holding an Id <-> Target map of external relations. + std::map maIdCache; + + bool lcl_getTarget(const css::uno::Reference& xRelationshipAccess, + StreamType_t nStreamType, + const OUString & rId, + OUString & rDocumentTarget); +public: + typedef tools::SvRef Pointer_t; + + OOXMLStreamImpl + (OOXMLStreamImpl const & rStream, StreamType_t nType); + OOXMLStreamImpl + (css::uno::Reference const & xContext, + css::uno::Reference const & xStorageStream, + StreamType_t nType, bool bRepairStorage); + OOXMLStreamImpl(OOXMLStreamImpl const & rStream, const OUString & rId); + + virtual ~OOXMLStreamImpl() override; + + virtual css::uno::Reference getFastParser() override; + virtual css::uno::Reference getDocumentStream() override; + virtual css::uno::Reference getContext() override; + virtual OUString getTargetForId(const OUString & rId) override; + virtual const OUString & getTarget() const override; + + virtual css::uno::Reference getFastTokenHandler() override; + + // Giving access to mxDocumentStream. It is needed by resolving custom xml to get list of customxml's used in document. + const css::uno::Reference& accessDocumentStream() { return mxDocumentStream;} +}; +}} +#endif // INCLUDED_WRITERFILTER_SOURCE_OOXML_OOXMLSTREAMIMPL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/ooxml/README b/writerfilter/source/ooxml/README new file mode 100644 index 000000000..c72b341ae --- /dev/null +++ b/writerfilter/source/ooxml/README @@ -0,0 +1,13 @@ += DOCX tokenizer + +== Coding style + +This directory uses the PEP 8 (see +) coding style for Python files. +Please run + +---- +pycodestyle *.py +---- + +before committing. diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py new file mode 100644 index 000000000..1d9924e23 --- /dev/null +++ b/writerfilter/source/ooxml/factory_ns.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from xml.dom import minidom +import sys + + +def createHeader(model, ns): + nsToken = ns.replace('-', '_') + print(""" +#ifndef INCLUDED_OOXML_FACTORY_%s_HXX +#define INCLUDED_OOXML_FACTORY_%s_HXX +#include "ooxml/OOXMLFactory.hxx" +#include "OOXMLFactory_generated.hxx" +#include "oox/token/namespaces.hxx" +#include "ooxml/resourceids.hxx" +#include "tools/ref.hxx" + +namespace writerfilter { +namespace ooxml { + +/// @cond GENERATED +""" % (nsToken.upper(), nsToken.upper())) + + print("""class OOXMLFactory_%s : public OOXMLFactory_ns +{ +public: + typedef tools::SvRef Pointer_t; + + static Pointer_t getInstance(); + + virtual const AttributeInfo* getAttributeInfoArray(Id nId); + virtual bool getElementId(Id nDefine, Id nId, ResourceType& rOutResource, Id& rOutElement); + virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue); + virtual Id getResourceId(Id nDefine, sal_Int32 nToken); +""" % nsToken) + + actions = [] + for nsNode in [i for i in model.getElementsByTagName("namespace") if i.getAttribute("name") == ns]: + for resource in nsNode.getElementsByTagName("resource"): + for action in [i.getAttribute("name") for i in resource.childNodes if i.nodeType == minidom.Node.ELEMENT_NODE and i.tagName == "action"]: + if action != "characters" and action not in actions: + actions.append(action) + for action in actions: + print(" void %sAction(OOXMLFastContextHandler* pHandler);" % action) + + print("""virtual void charactersAction(OOXMLFastContextHandler* pHandler, const OUString & sText); + virtual void attributeAction(OOXMLFastContextHandler* pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue); + + virtual ~OOXMLFactory_%s(); + +protected: + static Pointer_t m_pInstance; + + OOXMLFactory_%s(); +}; +""" % (nsToken, nsToken)) + + print("""/// @endcond +}} +#endif //INCLUDED_OOXML_FACTORY_%s_HXX""" % nsToken.upper()) + + +modelPath = sys.argv[1] +filePath = sys.argv[2] +model = minidom.parse(modelPath) +ns = filePath.split('OOXMLFactory_')[1].split('.hxx')[0] +createHeader(model, ns) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/factoryimpl.py b/writerfilter/source/ooxml/factoryimpl.py new file mode 100644 index 000000000..4fdbfda2e --- /dev/null +++ b/writerfilter/source/ooxml/factoryimpl.py @@ -0,0 +1,215 @@ +#!/usr/bin/env python +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from xml.dom import minidom +import sys + + +def getElementsByTagNamesNS(parent, ns, names, ret=minidom.NodeList()): + for node in parent.childNodes: + if node.nodeType == minidom.Node.ELEMENT_NODE and node.namespaceURI == ns and node.tagName in names: + ret.append(node) + getElementsByTagNamesNS(node, ns, names, ret) + return ret + + +def createFastChildContextFromFactory(model): + print("""uno::Reference OOXMLFactory::createFastChildContextFromFactory +(OOXMLFastContextHandler* pHandler, OOXMLFactory_ns::Pointer_t pFactory, Token_t Element) +{ + uno::Reference aResult; + const Id nDefine = pHandler->getDefine(); + + if (pFactory.get() != NULL) + { + ResourceType nResource; + Id nElementId; + if (pFactory->getElementId(nDefine, Element, nResource, nElementId)) + { + const Id nId = pFactory->getResourceId(nDefine, Element); + + switch (nResource) + {""") + resources = [ + "List", "Integer", "Hex", "HexColor", "String", + "TwipsMeasure_asSigned", "TwipsMeasure_asZero", + "HpsMeasure", "Boolean", "MeasurementOrPercent", + ] + for resource in [r.getAttribute("resource") for r in model.getElementsByTagName("resource")]: + if resource not in resources: + resources.append(resource) + print(""" case ResourceType::%s: + aResult.set(OOXMLFastHelper::createAndSetParentAndDefine(pHandler, Element, nId, nElementId)); + break;""" % (resource, resource)) + print(""" case ResourceType::Any: + aResult.set(createFastChildContextFromStart(pHandler, Element)); + break; + default: + break; + } + + } + } + + return aResult; +} +""") + + +def getFactoryForNamespace(model): + print("""OOXMLFactory_ns::Pointer_t OOXMLFactory::getFactoryForNamespace(Id nId) +{ + OOXMLFactory_ns::Pointer_t pResult; + + switch (oox::getNamespace(nId)) + {""") + + for namespace in [ns.getAttribute("name") for ns in model.getElementsByTagName("namespace")]: + id = namespace.replace('-', '_') + print(""" case NN_%s: + pResult = OOXMLFactory_%s::getInstance(); + break;""" % (id, id)) + print(""" default: + break; + } + + return pResult; +} +""") + + +def createFastChildContextFromStart(model): + print("""uno::Reference OOXMLFactory::createFastChildContextFromStart +(OOXMLFastContextHandler* pHandler, Token_t Element) +{ + uno::Reference aResult; + OOXMLFactory_ns::Pointer_t pFactory; + +""") + + for namespace in [ns.getAttribute("name") for ns in model.getElementsByTagName("namespace")]: + id = namespace.replace('-', '_') + print(""" if (!aResult.is()) + { + pFactory = getFactoryForNamespace(NN_%s); + aResult.set(createFastChildContextFromFactory(pHandler, pFactory, Element)); + }""" % id) + + print(""" + return aResult; +} +""") + + +def fastTokenToId(model): + print(""" +std::string fastTokenToId(sal_uInt32 nToken) +{ + std::string sResult; +#ifdef DBG_UTIL + + switch (oox::getNamespace(nToken)) + {""") + + aliases = [] + for alias in sorted(ooxUrlAliases.values()): + if alias not in aliases: + aliases.append(alias) + print(""" case oox::NMSP_%s: + sResult += "%s:"; + break;""" % (alias, alias)) + print(""" } + + switch (nToken & 0xffff) + {""") + + tokens = [""] + for token in [t.getAttribute("localname") for t in getElementsByTagNamesNS(model, "http://relaxng.org/ns/structure/1.0", ["element", "attribute"])]: + if token not in tokens: + tokens.append(token) + print(""" case oox::XML_%s: + sResult += "%s"; + break;""" % (token, token)) + + print(""" } +#else + (void)nToken; +#endif + return sResult; +} +""") + + +def getFastParser(): + print("""uno::Reference OOXMLStreamImpl::getFastParser() +{ + if (!mxFastParser.is()) + { + mxFastParser = css::xml::sax::FastParser::create(mxContext); + // the threaded parser is about 20% slower loading writer documents + css::uno::Reference< css::lang::XInitialization > xInit( mxFastParser, css::uno::UNO_QUERY_THROW ); + css::uno::Sequence< css::uno::Any > args(1); + args[0] <<= OUString("DisableThreadedParser"); + xInit->initialize(args); +""") + for url in sorted(ooxUrlAliases.keys()): + print(""" mxFastParser->registerNamespace("%s", oox::NMSP_%s);""" % (url, ooxUrlAliases[url])) + print(""" } + + return mxFastParser; +} + +/// @endcond +}}""") + + +def createImpl(model): + print(""" +#include +#include +#include "ooxml/OOXMLFactory.hxx" +#include "ooxml/OOXMLFastHelper.hxx" +#include "ooxml/OOXMLStreamImpl.hxx" +""") + + for namespace in [ns.getAttribute("name") for ns in model.getElementsByTagName("namespace")]: + print('#include "OOXMLFactory_%s.hxx"' % namespace) + + print("""namespace writerfilter { +namespace ooxml { + +using namespace com::sun::star; + +/// @cond GENERATED +""") + + createFastChildContextFromFactory(model) + getFactoryForNamespace(model) + createFastChildContextFromStart(model) + fastTokenToId(model) + getFastParser() + + +def parseNamespaces(fro): + sock = open(fro) + for i in sock.readlines(): + line = i.strip() + alias, url = line.split(' ')[1:] # first column is ID, not interesting for us + ooxUrlAliases[url] = alias + sock.close() + + +namespacesPath = sys.argv[1] +ooxUrlAliases = {} +parseNamespaces(namespacesPath) +modelPath = sys.argv[2] +model = minidom.parse(modelPath) +createImpl(model) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py new file mode 100644 index 000000000..db06cf1c9 --- /dev/null +++ b/writerfilter/source/ooxml/factoryimpl_ns.py @@ -0,0 +1,759 @@ +#!/usr/bin/env python +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from xml.dom import minidom +import sys + + +# factoryMutexDecl + + +def factoryMutexDecl(nsLabel): + print("typedef rtl::Static OOXMLFactory_%s_Mutex;" % (nsLabel, nsLabel)) + print() + + +# factoryConstructor + + +def factoryConstructor(nsLabel): + print("""OOXMLFactory_%s::OOXMLFactory_%s() +{ + // multi-thread-safe mutex for all platforms + + osl::MutexGuard aGuard(OOXMLFactory_%s_Mutex::get()); +}""" % (nsLabel, nsLabel, nsLabel)) + print() + + +# factoryDestructor + + +def factoryDestructor(nsLabel): + print("""OOXMLFactory_%s::~OOXMLFactory_%s() +{ +}""" % (nsLabel, nsLabel)) + print() + + +# factoryGetInstance + + +def factoryGetInstance(nsLabel): + print("""OOXMLFactory_ns::Pointer_t OOXMLFactory_%s::m_pInstance; + +OOXMLFactory_ns::Pointer_t OOXMLFactory_%s::getInstance() +{ + if (!m_pInstance) + m_pInstance = new OOXMLFactory_%s(); + + return m_pInstance; +}""" % (nsLabel, nsLabel, nsLabel)) + print() + + +# factoryAttributeToResourceMap + + +def nsToLabel(nsNode): + return nsNode.getAttribute("name").replace('-', '_') + + +def getChildByName(parentNode, childName): + elementNodes = [i for i in parentNode.childNodes if i.localName == childName] + assert len(elementNodes) == 1 + return elementNodes[0] + + +def resourceForAttribute(nsNode, attrNode): + resourceName = "" + + for refNode in getChildrenByName(attrNode, "ref"): + refName = refNode.getAttribute("name") + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == refName]: + resourceName = resourceNode.getAttribute("resource") + break + if not len(resourceName): + for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: + resourceName = resourceForAttribute(nsNode, define) + break + if len(resourceName): + break + + if not len(resourceName): + if len([i for i in attrNode.getElementsByTagName("data") if i.getAttribute("type") in ("base64Binary", "string")]): + resourceName = "String" + elif len([i for i in attrNode.getElementsByTagName("data") if i.getAttribute("type") == "boolean"]): + resourceName = "Boolean" + elif len([i for i in attrNode.getElementsByTagName("data") if i.getAttribute("type") in ("unsignedInt", "integer", "int")]): + resourceName = "Integer" + else: + dataNodes = attrNode.getElementsByTagName("data") + if len(dataNodes): + t = dataNodes[0].getAttribute("type") + # Blacklist existing unexpected data types. + if t not in ("token", "long", "decimal", "float", "byte", "ST_DecimalNumber", "positiveInteger"): + raise Exception("unexpected data type: " + dataNodes[0].getAttribute("type")) + return resourceName + + +def idForNamespace(nsNode): + return "NN_%s" % nsNode.getAttribute("name").replace('-', '_') + + +def localIdForDefine(defineNode): + return "DEFINE_%s" % defineNode.getAttribute("name") + + +def idForDefine(nsNode, defineNode): + return "%s|%s" % (idForNamespace(nsNode), localIdForDefine(defineNode)) + + +def fastNamespace(attrNode): + return "oox::NMSP_%s" % attrNode.getAttribute("prefix") + + +def fastLocalName(attrNode): + if len(attrNode.getAttribute("localname")): + return "oox::XML_%s" % attrNode.getAttribute("localname") + else: + return "oox::XML_TOKEN_COUNT" + + +def fastToken(attrNode): + ret = [] + if len(attrNode.getAttribute("prefix")): + ret.append("%s|" % fastNamespace(attrNode)) + ret.append(fastLocalName(attrNode)) + return "".join(ret) + + +def collectAttributeToResource(nsNode, defineNode): + ret_dict = {} + ret_order = [] + for refNode in getChildrenByName(defineNode, "ref"): + refName = refNode.getAttribute("name") + parent = refNode.parentNode + if parent.localName in ("element", "attribute"): + continue + for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: + ret = collectAttributeToResource(nsNode, define) + ret_dict.update(ret[0]) + ret_order.extend(ret[1]) + + attrNodes = defineNode.getElementsByTagName("attribute") + for attrNode in attrNodes: + attrToken = fastToken(attrNode) + resourceName = resourceForAttribute(nsNode, attrNode) + refDefine = "0" + if len(resourceName): + for refNode in attrNode.getElementsByTagName("ref"): + refName = refNode.getAttribute("name") + for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: + refDefine = idForDefine(nsNode, define) + ret_dict[attrToken] = "ResourceType::%s, %s" % (resourceName, refDefine) + ret_order.append(attrToken) + + return [ret_dict, ret_order] + + +def factoryAttributeToResourceMapInner(nsNode, defineNode): + ret = [] + attributes = collectAttributeToResource(nsNode, defineNode) + already_used = set() + for k in attributes[1]: + if not (k in already_used): + ret.append(" { %s, %s }," % (k, attributes[0][k])) + already_used.add(k) + + return ret + + +def factoryAttributeToResourceMap(nsNode): + print("""const AttributeInfo* OOXMLFactory_%s::getAttributeInfoArray(Id nId) +{ + switch (nId) + {""" % nsToLabel(nsNode)) + for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"): + inner = "\n".join(factoryAttributeToResourceMapInner(nsNode, defineNode)) + if len(inner): + print(" case %s:" % idForDefine(nsNode, defineNode)) + print(" {") + print(" const static AttributeInfo info[] = {") + print(inner) + print(" { -1, ResourceType::NoResource, 0 }") + print(" };") + print(" return info;") + print(" }") + print(" break;") + + print(""" default: + break; + } + + return NULL; +}""") + print() + + +# factoryGetListValue + + +def idToLabel(idName): + ns, ln = idName.split(':') + return "NS_%s::LN_%s" % (ns, ln) + + +def appendValueData(values, name, value): + first = name[0:1] + + if not (first in values): + values[first] = [] + + values[first].append([name, value]) + + +def printValueData(values): + if "" in values: + output_else = "" + for i in values[""]: + print(" %sif (rValue == \"%s\") { rOutValue = %s; return true; }" % (output_else, i[0], i[1])) + output_else = "else " + print(" else switch (rValue[0])") + else: + print(" if (rValue.isEmpty())") + print(" return false;") + print(" switch (rValue[0])") + + print(" {") + for k in sorted(values.keys()): + if k != "": + print(" case '%s':" % k) + output_else = "" + for i in values[k]: + print(" %sif (rValue == \"%s\") { rOutValue = %s; }" % (output_else, i[0], i[1])) + output_else = "else " + print(" else { return false; }") + print(" return true;") + print(" }") + + +def factoryGetListValue(nsNode): + print("""bool OOXMLFactory_%s::getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) +{ + (void) rValue; + (void) rOutValue; + + switch (nId) + {""" % nsToLabel(nsNode)) + + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("resource") == "List"]: + print(" case %s:" % idForDefine(nsNode, resourceNode)) + values = {} + for valueNode in getChildrenByName(resourceNode, "value"): + valueData = "" + if len(valueNode.childNodes): + valueData = valueNode.childNodes[0].data + appendValueData(values, valueData, idToLabel(valueNode.getAttribute("tokenid"))) + printValueData(values) + print(" return false;") + + print(""" default: + break; + } + + return false; +} +""") + + +# factoryCreateElementMap + + +def contextResource(files, nsNode, refNode): + refName = refNode.getAttribute("name") + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == refName]: + return resourceNode.getAttribute("resource") + + for includeNode in getChildrenByName(getChildByName(nsNode, "grammar"), "include"): + namespaceNode = files[includeNode.getAttribute("href")] + for resourceNode in [i for i in getChildrenByName(namespaceNode, "resource") if i.getAttribute("name") == refName]: + return resourceNode.getAttribute("resource") + + if refName == "BUILT_IN_ANY_TYPE": + return "Any" + else: + for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"): + for resourceNode in [i for i in getChildrenByName(namespaceNode, "resource") if i.getAttribute("name") == refName]: + return resourceNode.getAttribute("resource") + return "" + + +def idForRef(nsNode, refNode): + refName = refNode.getAttribute("name") + result1 = "" + for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: + result1 = idForDefine(nsNode, define) + if refName == "BUILT_IN_ANY_TYPE": + return "0" + elif result1 == "": + for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"): + for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]: + return idForDefine(namespaceNode, define) + else: + return result1 + + +def factoryCreateElementMapInner(files, nsNode, defineNode, resourceNamespaceNode=None): + if not resourceNamespaceNode: + resourceNamespaceNode = nsNode + ret = {} + for refNode in defineNode.getElementsByTagName("ref"): + parent = refNode.parentNode + if parent.localName in ("element", "attribute"): + continue + refName = refNode.getAttribute("name") + + block = {} + for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: + block = factoryCreateElementMapInner(files, nsNode, define) + + if len(block) == 0: + block1 = {} + for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"): + for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]: + block1.update(factoryCreateElementMapInner(files, namespaceNode, define, nsNode)) + else: + block1 = block + + if len(block1): + ret.update(block1) + + for elementNode in defineNode.getElementsByTagName("element"): + resource = "" + for refNode in getChildrenByName(elementNode, "ref"): + refName = refNode.getAttribute("name") + resource = contextResource(files, resourceNamespaceNode, refNode) + if len(resource): + break + if len(resource): + ret[fastToken(elementNode)] = " case %s: rOutResource = ResourceType::%s; rOutElement = %s; break;" % (fastToken(elementNode), resource, idForRef(nsNode, getChildByName(elementNode, "ref"))) + + return ret + + +def factoryCreateElementMapFromStart(files, nsNode): + for startNode in getChildrenByName(nsNode, "start"): + startName = startNode.getAttribute("name") + block = None + for defineNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == startName]: + block = factoryCreateElementMapInner(files, nsNode, defineNode) + print(" /* start: %s*/" % startName) + if block: + for k in block.keys(): + print(block[k]) + + +def factoryCreateElementMap(files, nsNode): + print("""bool OOXMLFactory_%s::getElementId(Id nDefine, Id nId, ResourceType& rOutResource, Id& rOutElement) +{ + (void) rOutResource; + (void) rOutElement; + + switch (nDefine) + {""" % nsToLabel(nsNode)) + + for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"): + inner = factoryCreateElementMapInner(files, nsNode, defineNode) + if len(inner): + print(" case %s:" % idForDefine(nsNode, defineNode)) + print(" switch (nId)") + print(" {") + for k in sorted(inner.keys()): + print(inner[k]) + print(" default: return false;") + print(" }") + print(" return true;") + print(" default:") + print(" switch (nId)") + print(" {") + factoryCreateElementMapFromStart(files, nsNode) + print(""" default: return false; + } + return true; + } +} +""") + + +# factoryActions + + +def charactersActionForValues(nsNode, refNode): + ret = [] + + refName = refNode.getAttribute("name") + for defineNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: + ret.append(" {") + ret.append(" // %s" % defineNode.getAttribute("name")) + for dataNode in getChildrenByName(defineNode, "data"): + if dataNode.getAttribute("type") == "int": + ret.append(" OOXMLValue::Pointer_t pValue(new OOXMLIntegerValue(sText));") + ret.append(" pValueHandler->setValue(pValue);") + ret.append(" }") + + return ret + + +def factoryChooseAction(actionNode): + ret = [] + extra_space = "" + if actionNode.hasAttribute("tokenid"): + ret.append(" if (sal::static_int_cast(pHandler->getId()) == %s)" % idToLabel(actionNode.getAttribute("tokenid"))) + ret.append(" {") + extra_space = " " + for condNode in getChildrenByName(actionNode, "cond"): + ret.append(" {") + ret.append(" OOXMLPropertySetEntryToInteger aHandler(%s);" % idToLabel(condNode.getAttribute("tokenid"))) + ret.append(" if (OOXMLFastContextHandlerStream* pStream = dynamic_cast(pHandler))") + ret.append(" pStream->getPropertySetAttrs()->resolve(aHandler);") + ret.append("") + ret.append(" if (sal::static_int_cast(aHandler.getValue()) == %s)" % idToLabel(condNode.getAttribute("value"))) + ret.append(" {") + extra_space = " " + + if actionNode.getAttribute("action") in ("handleXNotes", "handleHdrFtr", "handleComment", "handlePicture", "handleBreak", "handleOutOfOrderBreak", "handleOLE", "handleFontRel", "handleHyperlinkURL"): + ret.append(" %sif (OOXMLFastContextHandlerProperties* pProperties = dynamic_cast(pHandler))" % extra_space) + ret.append(" %s pProperties->%s();" % (extra_space, actionNode.getAttribute("action"))) + elif actionNode.getAttribute("action") == "propagateCharacterPropertiesAsSet": + ret.append(" %spHandler->propagateCharacterPropertiesAsSet(%s);" % (extra_space, idToLabel(actionNode.getAttribute("sendtokenid")))) + elif actionNode.getAttribute("action") in ("startCell", "endCell"): + ret.append(" %sif (OOXMLFastContextHandlerTextTableCell* pTextTableCell = dynamic_cast(pHandler))" % extra_space) + ret.append(" %s pTextTableCell->%s();" % (extra_space, actionNode.getAttribute("action"))) + elif actionNode.getAttribute("action") in ("startRow", "endRow"): + ret.append(" %sif (OOXMLFastContextHandlerTextTableRow* pTextTableRow = dynamic_cast(pHandler))" % extra_space) + ret.append(" %s pTextTableRow->%s();" % (extra_space, actionNode.getAttribute("action"))) + elif actionNode.getAttribute("action") == "handleGridBefore" or actionNode.getAttribute("action") == "handleGridAfter": + ret.append(" %sif (OOXMLFastContextHandlerTextTableRow* pTextTableRow = dynamic_cast(pHandler))" % extra_space) + ret.append(" %s pTextTableRow->%s();" % (extra_space, actionNode.getAttribute("action"))) + # tdf#111550 + elif actionNode.getAttribute("action") in ("start_P_Tbl"): + ret.append(" %sif (OOXMLFastContextHandlerTextTable* pTextTable = dynamic_cast(pHandler))" % extra_space) + ret.append(" %s pTextTable->%s();" % (extra_space, actionNode.getAttribute("action"))) + elif actionNode.getAttribute("action") in ("sendProperty", "handleHyperlink"): + ret.append(" %sif (OOXMLFastContextHandlerStream* pStream = dynamic_cast(pHandler))" % extra_space) + ret.append(" %s pStream->%s();" % (extra_space, actionNode.getAttribute("action"))) + elif actionNode.getAttribute("action") == "fieldstart": + ret.append(" %spHandler->startField();" % (extra_space)) + elif actionNode.getAttribute("action") == "fieldsep": + ret.append(" %spHandler->fieldSeparator();" % (extra_space)) + elif actionNode.getAttribute("action") == "fieldend": + ret.append(" %spHandler->endField();" % (extra_space)) + elif actionNode.getAttribute("action") == "fieldlock": + ret.append(" %s{" % (extra_space)) + ret.append(" %sOOXMLPropertySetEntryToBool aHandler(NS_ooxml::LN_CT_FldChar_fldLock);" % (extra_space)) + ret.append(" %sif (OOXMLFastContextHandlerStream* pStream = dynamic_cast(pHandler))" % (extra_space)) + ret.append(" %spStream->getPropertySetAttrs()->resolve(aHandler);" % (extra_space)) + ret.append(" %sif (aHandler.getValue())" % (extra_space)) + ret.append(" %spHandler->lockField();" % (extra_space)) + ret.append(" %s}" % (extra_space)) + elif actionNode.getAttribute("action") == "printproperty": + ret.append(" %sif (OOXMLFastContextHandlerStream* pStream = dynamic_cast(pHandler))" % extra_space) + ret.append(" %s pStream->sendProperty(%s);" % (extra_space, idToLabel(actionNode.getAttribute("sendtokenid")))) + elif actionNode.getAttribute("action") == "sendPropertiesWithId": + ret.append(" %spHandler->sendPropertiesWithId(%s);" % (extra_space, idToLabel(actionNode.getAttribute("sendtokenid")))) + elif actionNode.getAttribute("action") == "text": + ret.append(" %spHandler->text(sText);" % (extra_space)) + elif actionNode.getAttribute("action") == "positionOffset": + ret.append(" %spHandler->positionOffset(sText);" % (extra_space)) + elif actionNode.getAttribute("action") == "positivePercentage": + ret.append(" %spHandler->positivePercentage(sText);" % (extra_space)) + elif actionNode.getAttribute("action") == "alignH": + ret.append(" %spHandler->alignH(sText);" % (extra_space)) + elif actionNode.getAttribute("action") == "alignV": + ret.append(" %spHandler->alignV(sText);" % (extra_space)) + elif actionNode.getAttribute("action") == "tokenproperty": + ret.append(" %sOOXMLFastHelper::newProperty(pHandler, %s, pHandler->getToken());" % (extra_space, idToLabel("ooxml:token"))) + else: + ret.append(" %spHandler->%s();" % (extra_space, actionNode.getAttribute("action"))) + + for condNode in getChildrenByName(actionNode, "cond"): + ret.append(" }") + ret.append(" }") + if actionNode.hasAttribute("tokenid"): + ret.append(" }") + + return ret + + +def factoryAction(nsNode, action): + switchblock1 = [] + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if len([j for j in getChildrenByName(i, "action") if j.getAttribute("name") == action])]: + switchblock1.append("case %s:" % idForDefine(nsNode, resourceNode)) + for actionNode in [i for i in getChildrenByName(resourceNode, "action") if i.getAttribute("name") == action]: + switchblock1.extend(factoryChooseAction(actionNode)) + switchblock1.append(" break;") + switchblock1.append("") + + switchblock2 = [] + if action == "characters": + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("resource") == "Value"]: + if not len(getChildrenByName(resourceNode, "attribute")): + resourceName = resourceNode.getAttribute("name") + switchblock2.append("case %s:" % idForDefine(nsNode, resourceNode)) + ret = [] + for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == resourceName]: + for refNode in getChildrenByName(define, "ref"): + ret.extend(charactersActionForValues(nsNode, refNode)) + switchblock2.extend(ret) + switchblock2.append(" break;") + + sys.stdout.write("void OOXMLFactory_%s::%sAction(OOXMLFastContextHandler*" % (nsToLabel(nsNode), action)) + if len(switchblock1) or len(switchblock2): + sys.stdout.write(" pHandler") + if action == "characters": + sys.stdout.write(", const OUString&") + if "sText" in "".join(switchblock1) or "sText" in "".join(switchblock2): + sys.stdout.write(" sText") + print(")") + print("{") + if len(switchblock1) or len(switchblock2): + print(" sal_uInt32 nDefine = pHandler->getDefine();") + if len(switchblock1): + print(" switch (nDefine)") + print(" {") + if switchblock1[-1] == "": + switchblock1 = switchblock1[:-1] + sys.stdout.write(" ") + print("\n ".join(switchblock1)) + print() + print(" default:") + print(" break;") + print(" }") + if len(switchblock2): + print(" switch (nDefine)") + print(" {") + print("\n ".join(switchblock2)) + print() + print(" default:") + print(" break;") + print(" }") + print("}") + + +def factoryActions(nsNode): + actions = [] + for resourceNode in getChildrenByName(nsNode, "resource"): + for actionNode in getChildrenByName(resourceNode, "action"): + actionName = actionNode.getAttribute("name") + if actionName != "characters" and actionName not in actions: + actions.append(actionName) + for action in sorted(actions): + factoryAction(nsNode, action) + print() + factoryAction(nsNode, "characters") + print() + + +# factoryGetResourceId + + +def collectTokenToId(nsNode, defineNode): + ret = {} + for refNode in defineNode.getElementsByTagName("ref"): + refName = refNode.getAttribute("name") + parent = refNode.parentNode + if parent.localName in ("element", "attribute"): + continue + refblock1 = {} + for define in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == refName]: + refblock1.update(collectTokenToId(nsNode, define)) + if not len(refblock1): + for namespaceNode in getChildrenByName(nsNode.parentNode, "namespace"): + for define in [i for i in getChildrenByName(getChildByName(namespaceNode, "grammar"), "define") if i.getAttribute("name") == refName]: + ret.update(collectTokenToId(namespaceNode, define)) + else: + ret.update(refblock1) + + defineName = defineNode.getAttribute("name") + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == defineName]: + for node in [i for i in resourceNode.childNodes if i.localName in ("element", "attribute")]: + if node.hasAttribute("tokenid"): + ret[fastToken(node)] = idToLabel(node.getAttribute("tokenid")) + + return ret + + +def factoryTokenToIdMapInner(nsNode, defineNode): + ids = collectTokenToId(nsNode, defineNode) + ret = [] + for i in sorted(ids.keys()): + ret.append(" case %s: return %s;" % (i, ids[i])) + + return ret + + +def factoryGetResourceId(nsNode): + print("""Id OOXMLFactory_%s::getResourceId(Id nDefine, sal_Int32 nToken) +{ + (void) nDefine; + (void) nToken; + + switch (nDefine) + {""" % nsToLabel(nsNode)) + for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"): + inner = "\n".join(factoryTokenToIdMapInner(nsNode, defineNode)) + if len(inner): + print(" case %s:" % idForDefine(nsNode, defineNode)) + print(" switch (nToken)") + print(" {") + print(inner) + print(" }") + print(" break;") + print(" default:") + print(" switch (nToken)") + print(" {") + for startNode in getChildrenByName(nsNode, "start"): + startName = startNode.getAttribute("name") + for defineNode in [i for i in getChildrenByName(getChildByName(nsNode, "grammar"), "define") if i.getAttribute("name") == startName]: + inner = factoryTokenToIdMapInner(nsNode, defineNode) + if len(inner): + print("\n".join(inner)) + print(""" } + break; + } + return 0; +} +""") + + +# factoryAttributeAction + + +def factoryAttributeActionDefineInner(nsNode, defineNode): + ret = [] + + defineName = defineNode.getAttribute("name") + block = [] + output_else = "" + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == defineName]: + for attributeNode in getChildrenByName(resourceNode, "attribute"): + if attributeNode.hasAttribute("action"): + block.append(" %sif (nToken == static_cast(%s))" % (output_else, fastToken(attributeNode))) + block.append(" pHandler->%s(pValue);" % attributeNode.getAttribute("action")) + output_else = "else " + if len(block): + resource = "" + for resourceNode in [i for i in getChildrenByName(nsNode, "resource") if i.getAttribute("name") == defineName]: + resource = resourceNode.getAttribute("resource") + break + ret.append(" if (OOXMLFastContextHandler%s* pHandler = dynamic_cast(_pHandler))" % (resource, resource)) + ret.append(" {") + ret.extend(block) + ret.append(" }") + + return ret + + +def factoryAttributeActionInner(nsNode): + ret = [] + + for defineNode in getChildrenByName(getChildByName(nsNode, "grammar"), "define"): + inner = factoryAttributeActionDefineInner(nsNode, defineNode) + if len(inner): + ret.append(" case %s:" % idForDefine(nsNode, defineNode)) + ret.extend(inner) + ret.append(" break;") + + return ret + + +def factoryAttributeAction(nsNode): + nsLabel = nsToLabel(nsNode) + inner = factoryAttributeActionInner(nsNode) + if len(inner): + print("""void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler* _pHandler, Token_t nToken, const OOXMLValue::Pointer_t& pValue) +{ + switch (_pHandler->getDefine()) + {""" % nsLabel) + print("\n".join(inner)) + print(" default:") + print(" break;") + print(" }") + print("}") + print() + else: + print("void OOXMLFactory_%s::attributeAction(OOXMLFastContextHandler*, Token_t, const OOXMLValue::Pointer_t&)" % nsLabel) + print("{") + print("}") + print() + + +# createImpl + + +def getChildrenByName(parentNode, childName): + return [i for i in parentNode.childNodes if i.localName == childName] + + +def createImpl(modelNode, nsName): + print(""" +#include "ooxml/resourceids.hxx" +#include "OOXMLFactory_%s.hxx" +#include "ooxml/OOXMLFastHelper.hxx" +#include "oox/token/tokens.hxx" + +#ifdef _MSC_VER +#pragma warning(disable:4060) // switch statement contains no 'case' or 'default' labels +#pragma warning(disable:4065) // switch statement contains 'default' but no 'case' labels +#pragma warning(disable:4702) // unreachable code +#endif + +namespace writerfilter { +namespace ooxml { + +using namespace com::sun::star; + +/// @cond GENERATED""" % nsName) + print() + + files = {} + for nsNode in getChildrenByName(modelNode, "namespace"): + files[nsNode.getAttribute("name")] = nsNode + + for nsNode in [i for i in getChildrenByName(modelNode, "namespace") if i.getAttribute("name") == nsName]: + nsLabel = nsToLabel(nsNode) + + factoryMutexDecl(nsLabel) + factoryConstructor(nsLabel) + factoryDestructor(nsLabel) + factoryGetInstance(nsLabel) + factoryAttributeToResourceMap(nsNode) + factoryGetListValue(nsNode) + factoryCreateElementMap(files, nsNode) + factoryActions(nsNode) + factoryGetResourceId(nsNode) + factoryAttributeAction(nsNode) + + print("""/// @endcond +}}""") + + +def main(): + modelPath = sys.argv[1] + filePath = sys.argv[2] + modelNode = getChildByName(minidom.parse(modelPath), "model") + nsName = filePath.split('OOXMLFactory_')[1].split('.cxx')[0] + createImpl(modelNode, nsName) + + +if __name__ == "__main__": + main() + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/factoryinc.py b/writerfilter/source/ooxml/factoryinc.py new file mode 100644 index 000000000..ec07f7fda --- /dev/null +++ b/writerfilter/source/ooxml/factoryinc.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from xml.dom import minidom +import sys + + +def createInclude(model): + print(""" +#ifndef INCLUDED_OOXML_FACTORY_GENERATED_HXX +#define INCLUDED_OOXML_FACTORY_GENERATED_HXX + +namespace writerfilter { +namespace ooxml { + +/// @cond GENERATED + """) + + # Create namespaces. + counter = 1 + for namespace in sorted([ns.getAttribute("name") for ns in model.getElementsByTagName("namespace")]): + print("const Id NN_%s = %s << 16;" % (namespace.replace('-', '_'), counter)) + counter += 1 + + # Create defines. + counter = 1 + defines = [] + for define in sorted([ns.getAttribute("name") for ns in model.getElementsByTagName("define")]): + if define not in defines: + print("const Id DEFINE_%s = %s;" % (define, counter)) + defines.append(define) + counter += 1 + print("""/// @endcond +}} + +#endif // INCLUDED_OOXML_FACTORY_GENERATED_HXX""") + + +modelPath = sys.argv[1] +model = minidom.parse(modelPath) +createInclude(model) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml new file mode 100644 index 000000000..380fc3f01 --- /dev/null +++ b/writerfilter/source/ooxml/model.xml @@ -0,0 +1,19197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tl + + t + + tr + + l + + r + + bl + + b + + br + + + + + + legacyFlat1 + + legacyFlat2 + + legacyFlat3 + + legacyFlat4 + + legacyNormal1 + + legacyNormal2 + + legacyNormal3 + + legacyNormal4 + + legacyHarsh1 + + legacyHarsh2 + + legacyHarsh3 + + legacyHarsh4 + + threePt + + balanced + + soft + + harsh + + flood + + contrasting + + morning + + sunrise + + sunset + + chilly + + freezing + + flat + + twoPt + + glow + + brightRoom + + + + + + + + + + + + + + + + tl + t + tr + l + r + bl + b + br + + + legacyFlat1 + legacyFlat2 + legacyFlat3 + legacyFlat4 + legacyNormal1 + legacyNormal2 + legacyNormal3 + legacyNormal4 + legacyHarsh1 + legacyHarsh2 + legacyHarsh3 + legacyHarsh4 + threePt + balanced + soft + harsh + flood + contrasting + morning + sunrise + sunset + chilly + freezing + flat + twoPt + glow + brightRoom + + + + + + + + + + + + + + + + + + + + + + + + + + relaxedInset + + circle + + slope + + cross + + angle + + softRound + + convex + + coolSlant + + divot + + riblet + + hardEdge + + artDeco + + + + + + + + + + + + + + + + + legacyMatte + + legacyPlastic + + legacyMetal + + legacyWireframe + + matte + + plastic + + metal + + warmMatte + + translucentPowder + + powder + + dkEdge + + softEdge + + clear + + flat + + softmetal + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + relaxedInset + circle + slope + cross + angle + softRound + convex + coolSlant + divot + riblet + hardEdge + artDeco + + + legacyMatte + legacyPlastic + legacyMetal + legacyWireframe + matte + plastic + metal + warmMatte + translucentPowder + powder + dkEdge + softEdge + clear + flat + softmetal + + + + + + + + legacyObliqueTopLeft + + legacyObliqueTop + + legacyObliqueTopRight + + legacyObliqueLeft + + legacyObliqueFront + + legacyObliqueRight + + legacyObliqueBottomLeft + + legacyObliqueBottom + + legacyObliqueBottomRight + + legacyPerspectiveTopLeft + + legacyPerspectiveTop + + legacyPerspectiveTopRight + + legacyPerspectiveLeft + + legacyPerspectiveFront + + legacyPerspectiveRight + + legacyPerspectiveBottomLeft + + legacyPerspectiveBottom + + legacyPerspectiveBottomRight + + orthographicFront + + isometricTopUp + + isometricTopDown + + isometricBottomUp + + isometricBottomDown + + isometricLeftUp + + isometricLeftDown + + isometricRightUp + + isometricRightDown + + isometricOffAxis1Left + + isometricOffAxis1Right + + isometricOffAxis1Top + + isometricOffAxis2Left + + isometricOffAxis2Right + + isometricOffAxis2Top + + isometricOffAxis3Left + + isometricOffAxis3Right + + isometricOffAxis3Bottom + + isometricOffAxis4Left + + isometricOffAxis4Right + + isometricOffAxis4Bottom + + obliqueTopLeft + + obliqueTop + + obliqueTopRight + + obliqueLeft + + obliqueRight + + obliqueBottomLeft + + obliqueBottom + + obliqueBottomRight + + perspectiveFront + + perspectiveLeft + + perspectiveRight + + perspectiveAbove + + perspectiveBelow + + perspectiveAboveLeftFacing + + perspectiveAboveRightFacing + + perspectiveContrastingLeftFacing + + perspectiveContrastingRightFacing + + perspectiveHeroicLeftFacing + + perspectiveHeroicRightFacing + + perspectiveHeroicExtremeLeftFacing + + perspectiveHeroicExtremeRightFacing + + perspectiveRelaxed + + perspectiveRelaxedModerately + + + + + + + + + + + + + + + + + + + + + legacyObliqueTopLeft + legacyObliqueTop + legacyObliqueTopRight + legacyObliqueLeft + legacyObliqueFront + legacyObliqueRight + legacyObliqueBottomLeft + legacyObliqueBottom + legacyObliqueBottomRight + legacyPerspectiveTopLeft + legacyPerspectiveTop + legacyPerspectiveTopRight + legacyPerspectiveLeft + legacyPerspectiveFront + legacyPerspectiveRight + legacyPerspectiveBottomLeft + legacyPerspectiveBottom + legacyPerspectiveBottomRight + orthographicFront + isometricTopUp + isometricTopDown + isometricBottomUp + isometricBottomDown + isometricLeftUp + isometricLeftDown + isometricRightUp + isometricRightDown + isometricOffAxis1Left + isometricOffAxis1Right + isometricOffAxis1Top + isometricOffAxis2Left + isometricOffAxis2Right + isometricOffAxis2Top + isometricOffAxis3Left + isometricOffAxis3Right + isometricOffAxis3Bottom + isometricOffAxis4Left + isometricOffAxis4Right + isometricOffAxis4Bottom + obliqueTopLeft + obliqueTop + obliqueTopRight + obliqueLeft + obliqueRight + obliqueBottomLeft + obliqueBottom + obliqueBottomRight + perspectiveFront + perspectiveLeft + perspectiveRight + perspectiveAbove + perspectiveBelow + perspectiveAboveLeftFacing + perspectiveAboveRightFacing + perspectiveContrastingLeftFacing + perspectiveContrastingRightFacing + perspectiveHeroicLeftFacing + perspectiveHeroicRightFacing + perspectiveHeroicExtremeLeftFacing + perspectiveHeroicExtremeRightFacing + perspectiveRelaxed + perspectiveRelaxedModerately + + + + + + + + + dk1 + + lt1 + + dk2 + + lt2 + + accent1 + + accent2 + + accent3 + + accent4 + + accent5 + + accent6 + + hlink + + folHlink + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dk1 + lt1 + dk2 + lt2 + accent1 + accent2 + accent3 + accent4 + accent5 + accent6 + hlink + folHlink + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + none + + words + + sng + + dbl + + heavy + + dotted + + dottedHeavy + + dash + + dashHeavy + + dashLong + + dashLongHeavy + + dotDash + + dotDashHeavy + + dotDotDash + + dotDotDashHeavy + + wavy + + wavyHeavy + + wavyDbl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + noStrike + + sngStrike + + dblStrike + + + + + + none + + small + + all + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + none + words + sng + dbl + heavy + dotted + dottedHeavy + dash + dashHeavy + dashLong + dashLongHeavy + dotDash + dotDashHeavy + dotDotDash + dotDotDashHeavy + wavy + wavyHeavy + wavyDbl + + + noStrike + sngStrike + dblStrike + + + none + small + all + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + shdw1 + + shdw2 + + shdw3 + + shdw4 + + shdw5 + + shdw6 + + shdw7 + + shdw8 + + shdw9 + + shdw10 + + shdw11 + + shdw12 + + shdw13 + + shdw14 + + shdw15 + + shdw16 + + shdw17 + + shdw18 + + shdw19 + + shdw20 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + shape + + circle + + rect + + + + + + + + + + + + + + + + + + + + + + + + none + + x + + y + + xy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + email + + screen + + print + + hqprint + + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pct5 + + pct10 + + pct20 + + pct25 + + pct30 + + pct40 + + pct50 + + pct60 + + pct70 + + pct75 + + pct80 + + pct90 + + horz + + vert + + ltHorz + + ltVert + + dkHorz + + dkVert + + narHorz + + narVert + + dashHorz + + dashVert + + cross + + dnDiag + + upDiag + + ltDnDiag + + ltUpDiag + + dkDnDiag + + dkUpDiag + + wdDnDiag + + wdUpDiag + + dashDnDiag + + dashUpDiag + + diagCross + + smCheck + + lgCheck + + smGrid + + lgGrid + + dotGrid + + smConfetti + + lgConfetti + + horzBrick + + diagBrick + + solidDmnd + + openDmnd + + dotDmnd + + plaid + + sphere + + weave + + divot + + shingle + + wave + + trellis + + zigZag + + dashDot + + dashdotUpDiag + + lsolidDoted + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + over + + mult + + screen + + darken + + lighten + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sib + + tree + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + shdw1 + shdw2 + shdw3 + shdw4 + shdw5 + shdw6 + shdw7 + shdw8 + shdw9 + shdw10 + shdw11 + shdw12 + shdw13 + shdw14 + shdw15 + shdw16 + shdw17 + shdw18 + shdw19 + shdw20 + + + + shape + circle + rect + + + none + x + y + xy + + + + + + + + + + + + + + + + + + + + + email + screen + print + hqprint + none + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pct5 + pct10 + pct20 + pct25 + pct30 + pct40 + pct50 + pct60 + pct70 + pct75 + pct80 + pct90 + horz + vert + ltHorz + ltVert + dkHorz + dkVert + narHorz + narVert + dashHorz + dashVert + cross + dnDiag + upDiag + ltDnDiag + ltUpDiag + dkDnDiag + dkUpDiag + wdDnDiag + wdUpDiag + dashDnDiag + dashUpDiag + diagCross + smCheck + lgCheck + smGrid + lgGrid + dotGrid + smConfetti + lgConfetti + horzBrick + diagBrick + solidDmnd + openDmnd + dotDmnd + plaid + sphere + weave + divot + shingle + wave + trellis + zigZag + + + over + mult + screen + darken + lighten + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sib + tree + + + + + + + + + + + + + none + + triangle + + stealth + + diamond + + oval + + arrow + + + + + + sm + + med + + lg + + + + + + sm + + med + + lg + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + solid + + dot + + dash + + lgDash + + dashDot + + lgDashDot + + lgDashDotDot + + sysDash + + sysDot + + sysDashDot + + sysDashDotDot + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + rnd + + sq + + flat + + + + + + + + ctr + + in + + + + + + sng + + dbl + + thickThin + + thinThick + + tri + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + none + triangle + stealth + diamond + oval + arrow + + + sm + med + lg + + + sm + med + lg + + + + + + + + + + + + + + solid + dot + dash + lgDash + dashDot + lgDashDot + lgDashDotDot + sysDash + sysDot + sysDashDot + sysDashDotDot + + + rnd + sq + flat + + + ctr + in + + + sng + dbl + thickThin + thinThick + tri + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + scrollBar + + background + + activeCaption + + inactiveCaption + + menu + + window + + windowFrame + + menuText + + windowText + + captionText + + activeBorder + + inactiveBorder + + appWorkspace + + highlight + + highlightText + + btnFace + + btnShadow + + grayText + + btnText + + inactiveCaptionText + + btnHighlight + + 3dDkShadow + + 3dLight + + infoText + + infoBk + + hotLight + + gradientActiveCaption + + gradientInactiveCaption + + menuHighlight + + menuBar + + + + + + + + + + + + + + + bg1 + + tx1 + + bg2 + + tx2 + + accent1 + + accent2 + + accent3 + + accent4 + + accent5 + + accent6 + + hlink + + folHlink + + phClr + + dk1 + + lt1 + + dk2 + + lt2 + + + + + + + + + + + + aliceBlue + + antiqueWhite + + aqua + + aquamarine + + azure + + beige + + bisque + + black + + blanchedAlmond + + blue + + blueViolet + + brown + + burlyWood + + cadetBlue + + chartreuse + + chocolate + + coral + + cornflowerBlue + + cornsilk + + crimson + + cyan + + dkBlue + + dkCyan + + dkGoldenrod + + dkGray + + dkGreen + + dkKhaki + + dkMagenta + + dkOliveGreen + + dkOrange + + dkOrchid + + dkRed + + dkSalmon + + dkSeaGreen + + dkSlateBlue + + dkSlateGray + + dkTurquoise + + dkViolet + + deepPink + + deepSkyBlue + + dimGray + + dodgerBlue + + firebrick + + floralWhite + + forestGreen + + fuchsia + + gainsboro + + ghostWhite + + gold + + goldenrod + + gray + + green + + greenYellow + + honeydew + + hotPink + + indianRed + + indigo + + ivory + + khaki + + lavender + + lavenderBlush + + lawnGreen + + lemonChiffon + + ltBlue + + ltCoral + + ltCyan + + ltGoldenrodYellow + + ltGray + + ltGreen + + ltPink + + ltSalmon + + ltSeaGreen + + ltSkyBlue + + ltSlateGray + + ltSteelBlue + + ltYellow + + lime + + limeGreen + + linen + + magenta + + maroon + + medAquamarine + + medBlue + + medOrchid + + medPurple + + medSeaGreen + + medSlateBlue + + medSpringGreen + + medTurquoise + + medVioletRed + + midnightBlue + + mintCream + + mistyRose + + moccasin + + navajoWhite + + navy + + oldLace + + olive + + oliveDrab + + orange + + orangeRed + + orchid + + paleGoldenrod + + paleGreen + + paleTurquoise + + paleVioletRed + + papayaWhip + + peachPuff + + peru + + pink + + plum + + powderBlue + + purple + + red + + rosyBrown + + royalBlue + + saddleBrown + + salmon + + sandyBrown + + seaGreen + + seaShell + + sienna + + silver + + skyBlue + + slateBlue + + slateGray + + snow + + springGreen + + steelBlue + + tan + + teal + + thistle + + tomato + + turquoise + + violet + + wheat + + white + + whiteSmoke + + yellow + + yellowGreen + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tl + + t + + tr + + l + + ctr + + r + + bl + + b + + br + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + clr + + auto + + gray + + ltGray + + invGray + + grayWhite + + blackGray + + blackWhite + + black + + white + + hidden + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + scrollBar + background + activeCaption + inactiveCaption + menu + window + windowFrame + menuText + windowText + captionText + activeBorder + inactiveBorder + appWorkspace + highlight + highlightText + btnFace + btnShadow + grayText + btnText + inactiveCaptionText + btnHighlight + 3dDkShadow + 3dLight + infoText + infoBk + hotLight + gradientActiveCaption + gradientInactiveCaption + menuHighlight + menuBar + + + + + + + bg1 + tx1 + bg2 + tx2 + accent1 + accent2 + accent3 + accent4 + accent5 + accent6 + hlink + folHlink + phClr + dk1 + lt1 + dk2 + lt2 + + + + + + aliceBlue + antiqueWhite + aqua + aquamarine + azure + beige + bisque + black + blanchedAlmond + blue + blueViolet + brown + burlyWood + cadetBlue + chartreuse + chocolate + coral + cornflowerBlue + cornsilk + crimson + cyan + deepPink + deepSkyBlue + dimGray + dkBlue + dkCyan + dkGoldenrod + dkGray + dkGreen + dkKhaki + dkMagenta + dkOliveGreen + dkOrange + dkOrchid + dkRed + dkSalmon + dkSeaGreen + dkSlateBlue + dkSlateGray + dkTurquoise + dkViolet + dodgerBlue + firebrick + floralWhite + forestGreen + fuchsia + gainsboro + ghostWhite + gold + goldenrod + gray + green + greenYellow + honeydew + hotPink + indianRed + indigo + ivory + khaki + lavender + lavenderBlush + lawnGreen + lemonChiffon + lime + limeGreen + linen + ltBlue + ltCoral + ltCyan + ltGoldenrodYellow + ltGray + ltGreen + ltPink + ltSalmon + ltSeaGreen + ltSkyBlue + ltSlateGray + ltSteelBlue + ltYellow + magenta + maroon + medAquamarine + medBlue + medOrchid + medPurple + medSeaGreen + medSlateBlue + medSpringGreen + medTurquoise + medVioletRed + midnightBlue + mintCream + mistyRose + moccasin + navajoWhite + navy + oldLace + olive + oliveDrab + orange + orangeRed + orchid + paleGoldenrod + paleGreen + paleTurquoise + paleVioletRed + papayaWhip + peachPuff + peru + pink + plum + powderBlue + purple + red + rosyBrown + royalBlue + saddleBrown + salmon + sandyBrown + seaGreen + seaShell + sienna + silver + skyBlue + slateBlue + slateGray + snow + springGreen + steelBlue + tan + teal + thistle + tomato + turquoise + violet + wheat + white + whiteSmoke + yellow + yellowGreen + + + + + + + + + + + + + tl + t + tr + l + ctr + r + bl + b + br + + + + + + + + + + + + + clr + auto + gray + ltGray + invGray + grayWhite + blackGray + blackWhite + black + white + hidden + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + margin + page + leftMargin + rightMargin + insideMargin + outsideMargin + + + + + margin + page + topMargin + bottomMargin + insideMargin + outsideMargin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + margin + page + leftMargin + rightMargin + insideMargin + outsideMargin + + + margin + page + topMargin + bottomMargin + insideMargin + outsideMargin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bg1 + tx1 + bg2 + tx2 + accent1 + accent2 + accent3 + accent4 + accent5 + accent6 + hlink + folHlink + dk1 + lt1 + dk2 + lt2 + phClr + + + + + none + tl + t + tr + l + ctr + r + bl + b + br + + + + + rnd + sq + flat + + + + + sng + dbl + thickThin + thinThick + tri + + + + + ctr + in + + + + + true + false + 0 + 1 + + + + + shape + circle + rect + + + + + solid + dot + sysDot + dash + sysDash + lgDash + dashDot + sysDashDot + lgDashDot + lgDashDotDot + sysDashDotDot + + + + + legacyObliqueTopLeft + legacyObliqueTop + legacyObliqueTopRight + legacyObliqueLeft + legacyObliqueFront + legacyObliqueRight + legacyObliqueBottomLeft + legacyObliqueBottom + legacyObliqueBottomRight + legacyPerspectiveTopLeft + legacyPerspectiveTop + legacyPerspectiveTopRight + legacyPerspectiveLeft + legacyPerspectiveFront + legacyPerspectiveRight + legacyPerspectiveBottomLeft + legacyPerspectiveBottom + legacyPerspectiveBottomRight + orthographicFront + isometricTopUp + isometricTopDown + isometricBottomUp + isometricBottomDown + isometricLeftUp + isometricLeftDown + isometricRightUp + isometricRightDown + isometricOffAxis1Left + isometricOffAxis1Right + isometricOffAxis1Top + isometricOffAxis2Left + isometricOffAxis2Right + isometricOffAxis2Top + isometricOffAxis3Left + isometricOffAxis3Right + isometricOffAxis3Bottom + isometricOffAxis4Left + isometricOffAxis4Right + isometricOffAxis4Bottom + obliqueTopLeft + obliqueTop + obliqueTopRight + obliqueLeft + obliqueRight + obliqueBottomLeft + obliqueBottom + obliqueBottomRight + perspectiveFront + perspectiveLeft + perspectiveRight + perspectiveAbove + perspectiveBelow + perspectiveAboveLeftFacing + perspectiveAboveRightFacing + perspectiveContrastingLeftFacing + perspectiveContrastingRightFacing + perspectiveHeroicLeftFacing + perspectiveHeroicRightFacing + perspectiveHeroicExtremeLeftFacing + perspectiveHeroicExtremeRightFacing + perspectiveRelaxed + perspectiveRelaxedModerately + + + + + legacyFlat1 + legacyFlat2 + legacyFlat3 + legacyFlat4 + legacyNormal1 + legacyNormal2 + legacyNormal3 + legacyNormal4 + legacyHarsh1 + legacyHarsh2 + legacyHarsh3 + legacyHarsh4 + threePt + balanced + soft + harsh + flood + contrasting + morning + sunrise + sunset + chilly + freezing + flat + twoPt + glow + brightRoom + + + + + tl + t + tr + l + r + bl + b + br + + + + + relaxedInset + circle + slope + cross + angle + softRound + convex + coolSlant + divot + riblet + hardEdge + artDeco + + + + + legacyMatte + legacyPlastic + legacyMetal + legacyWireframe + matte + plastic + metal + warmMatte + translucentPowder + powder + dkEdge + softEdge + clear + flat + softmetal + none + + + + + none + standard + contextual + historical + discretional + standardContextual + standardHistorical + contextualHistorical + standardDiscretional + contextualDiscretional + historicalDiscretional + standardContextualHistorical + standardContextualDiscretional + standardHistoricalDiscretional + contextualHistoricalDiscretional + all + + + + + default + lining + oldStyle + + + + + default + proportional + tabular + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bg1 + tx1 + bg2 + tx2 + accent1 + accent2 + accent3 + accent4 + accent5 + accent6 + hlink + folHlink + dk1 + lt1 + dk2 + lt2 + phClr + + + none + tl + t + tr + l + ctr + r + bl + b + br + + + rnd + sq + flat + + + sng + dbl + thickThin + thinThick + tri + + + ctr + in + + + true + false + 0 + 1 + + + shape + circle + rect + + + solid + dot + sysDot + dash + sysDash + lgDash + dashDot + sysDashDot + lgDashDot + lgDashDotDot + sysDashDotDot + + + legacyObliqueTopLeft + legacyObliqueTop + legacyObliqueTopRight + legacyObliqueLeft + legacyObliqueFront + legacyObliqueRight + legacyObliqueBottomLeft + legacyObliqueBottom + legacyObliqueBottomRight + legacyPerspectiveTopLeft + legacyPerspectiveTop + legacyPerspectiveTopRight + legacyPerspectiveLeft + legacyPerspectiveFront + legacyPerspectiveRight + legacyPerspectiveBottomLeft + legacyPerspectiveBottom + legacyPerspectiveBottomRight + orthographicFront + isometricTopUp + isometricTopDown + isometricBottomUp + isometricBottomDown + isometricLeftUp + isometricLeftDown + isometricRightUp + isometricRightDown + isometricOffAxis1Left + isometricOffAxis1Right + isometricOffAxis1Top + isometricOffAxis2Left + isometricOffAxis2Right + isometricOffAxis2Top + isometricOffAxis3Left + isometricOffAxis3Right + isometricOffAxis3Bottom + isometricOffAxis4Left + isometricOffAxis4Right + isometricOffAxis4Bottom + obliqueTopLeft + obliqueTop + obliqueTopRight + obliqueLeft + obliqueRight + obliqueBottomLeft + obliqueBottom + obliqueBottomRight + perspectiveFront + perspectiveLeft + perspectiveRight + perspectiveAbove + perspectiveBelow + perspectiveAboveLeftFacing + perspectiveAboveRightFacing + perspectiveContrastingLeftFacing + perspectiveContrastingRightFacing + perspectiveHeroicLeftFacing + perspectiveHeroicRightFacing + perspectiveHeroicExtremeLeftFacing + perspectiveHeroicExtremeRightFacing + perspectiveRelaxed + perspectiveRelaxedModerately + + + legacyFlat1 + legacyFlat2 + legacyFlat3 + legacyFlat4 + legacyNormal1 + legacyNormal2 + legacyNormal3 + legacyNormal4 + legacyHarsh1 + legacyHarsh2 + legacyHarsh3 + legacyHarsh4 + threePt + balanced + soft + harsh + flood + contrasting + morning + sunrise + sunset + chilly + freezing + flat + twoPt + glow + brightRoom + + + tl + t + tr + l + r + bl + b + br + + + relaxedInset + circle + slope + cross + angle + softRound + convex + coolSlant + divot + riblet + hardEdge + artDeco + + + legacyMatte + legacyPlastic + legacyMetal + legacyWireframe + matte + plastic + metal + warmMatte + translucentPowder + powder + dkEdge + softEdge + clear + flat + softmetal + none + + + none + standard + contextual + historical + discretional + standardContextual + standardHistorical + contextualHistorical + standardDiscretional + contextualDiscretional + historicalDiscretional + standardContextualHistorical + standardContextualDiscretional + standardHistoricalDiscretional + contextualHistoricalDiscretional + all + + + default + lining + oldStyle + + + default + proportional + tabular + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + line + + lineInv + + triangle + + rtTriangle + + rect + + diamond + + parallelogram + + trapezoid + + nonIsoscelesTrapezoid + + pentagon + + hexagon + + heptagon + + octagon + + decagon + + dodecagon + + star4 + + star5 + + star6 + + star7 + + star8 + + star10 + + star12 + + star16 + + star24 + + star32 + + roundRect + + round1Rect + + round2SameRect + + round2DiagRect + + snipRoundRect + + snip1Rect + + snip2SameRect + + snip2DiagRect + + plaque + + ellipse + + teardrop + + homePlate + + chevron + + pieWedge + + pie + + blockArc + + donut + + noSmoking + + rightArrow + + leftArrow + + upArrow + + downArrow + + stripedRightArrow + + notchedRightArrow + + bentUpArrow + + leftRightArrow + + upDownArrow + + leftUpArrow + + leftRightUpArrow + + quadArrow + + leftArrowCallout + + rightArrowCallout + + upArrowCallout + + downArrowCallout + + leftRightArrowCallout + + upDownArrowCallout + + quadArrowCallout + + bentArrow + + uturnArrow + + circularArrow + + leftCircularArrow + + leftRightCircularArrow + + curvedRightArrow + + curvedLeftArrow + + curvedUpArrow + + curvedDownArrow + + swooshArrow + + cube + + can + + lightningBolt + + heart + + sun + + moon + + smileyFace + + irregularSeal1 + + irregularSeal2 + + foldedCorner + + bevel + + frame + + halfFrame + + corner + + diagStripe + + chord + + arc + + leftBracket + + rightBracket + + leftBrace + + rightBrace + + bracketPair + + bracePair + + straightConnector1 + + bentConnector2 + + bentConnector3 + + bentConnector4 + + bentConnector5 + + curvedConnector2 + + curvedConnector3 + + curvedConnector4 + + curvedConnector5 + + callout1 + + callout2 + + callout3 + + accentCallout1 + + accentCallout2 + + accentCallout3 + + borderCallout1 + + borderCallout2 + + borderCallout3 + + accentBorderCallout1 + + accentBorderCallout2 + + accentBorderCallout3 + + wedgeRectCallout + + wedgeRoundRectCallout + + wedgeEllipseCallout + + cloudCallout + + cloud + + ribbon + + ribbon2 + + ellipseRibbon + + ellipseRibbon2 + + leftRightRibbon + + verticalScroll + + horizontalScroll + + wave + + doubleWave + + plus + + flowChartProcess + + flowChartDecision + + flowChartInputOutput + + flowChartPredefinedProcess + + flowChartInternalStorage + + flowChartDocument + + flowChartMultidocument + + flowChartTerminator + + flowChartPreparation + + flowChartManualInput + + flowChartManualOperation + + flowChartConnector + + flowChartPunchedCard + + flowChartPunchedTape + + flowChartSummingJunction + + flowChartOr + + flowChartCollate + + flowChartSort + + flowChartExtract + + flowChartMerge + + flowChartOfflineStorage + + flowChartOnlineStorage + + flowChartMagneticTape + + flowChartMagneticDisk + + flowChartMagneticDrum + + flowChartDisplay + + flowChartDelay + + flowChartAlternateProcess + + flowChartOffpageConnector + + actionButtonBlank + + actionButtonHome + + actionButtonHelp + + actionButtonInformation + + actionButtonForwardNext + + actionButtonBackPrevious + + actionButtonEnd + + actionButtonBeginning + + actionButtonReturn + + actionButtonDocument + + actionButtonSound + + actionButtonMovie + + gear6 + + gear9 + + funnel + + mathPlus + + mathMinus + + mathMultiply + + mathDivide + + mathEqual + + mathNotEqual + + cornerTabs + + squareTabs + + plaqueTabs + + chartX + + chartStar + + chartPlus + + + + + + textNoShape + + textPlain + + textStop + + textTriangle + + textTriangleInverted + + textChevron + + textChevronInverted + + textRingInside + + textRingOutside + + textArchUp + + textArchDown + + textCircle + + textButton + + textArchUpPour + + textArchDownPour + + textCirclePour + + textButtonPour + + textCurveUp + + textCurveDown + + textCanUp + + textCanDown + + textWave1 + + textWave2 + + textDoubleWave1 + + textWave4 + + textInflate + + textDeflate + + textInflateBottom + + textDeflateBottom + + textInflateTop + + textDeflateTop + + textDeflateInflate + + textDeflateInflateDeflate + + textFadeRight + + textFadeLeft + + textFadeUp + + textFadeDown + + textSlantUp + + textSlantDown + + textCascadeUp + + textCascadeDown + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + none + + norm + + lighten + + lightenLess + + darken + + darkenLess + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + line + lineInv + triangle + rtTriangle + rect + diamond + parallelogram + trapezoid + nonIsoscelesTrapezoid + pentagon + hexagon + heptagon + octagon + decagon + dodecagon + star4 + star5 + star6 + star7 + star8 + star10 + star12 + star16 + star24 + star32 + roundRect + round1Rect + round2SameRect + round2DiagRect + snipRoundRect + snip1Rect + snip2SameRect + snip2DiagRect + plaque + ellipse + teardrop + homePlate + chevron + pieWedge + pie + blockArc + donut + noSmoking + rightArrow + leftArrow + upArrow + downArrow + stripedRightArrow + notchedRightArrow + bentUpArrow + leftRightArrow + upDownArrow + leftUpArrow + leftRightUpArrow + quadArrow + leftArrowCallout + rightArrowCallout + upArrowCallout + downArrowCallout + leftRightArrowCallout + upDownArrowCallout + quadArrowCallout + bentArrow + uturnArrow + circularArrow + leftCircularArrow + leftRightCircularArrow + curvedRightArrow + curvedLeftArrow + curvedUpArrow + curvedDownArrow + swooshArrow + cube + can + lightningBolt + heart + sun + moon + smileyFace + irregularSeal1 + irregularSeal2 + foldedCorner + bevel + frame + halfFrame + corner + diagStripe + chord + arc + leftBracket + rightBracket + leftBrace + rightBrace + bracketPair + bracePair + straightConnector1 + bentConnector2 + bentConnector3 + bentConnector4 + bentConnector5 + curvedConnector2 + curvedConnector3 + curvedConnector4 + curvedConnector5 + callout1 + callout2 + callout3 + accentCallout1 + accentCallout2 + accentCallout3 + borderCallout1 + borderCallout2 + borderCallout3 + accentBorderCallout1 + accentBorderCallout2 + accentBorderCallout3 + wedgeRectCallout + wedgeRoundRectCallout + wedgeEllipseCallout + cloudCallout + cloud + ribbon + ribbon2 + ellipseRibbon + ellipseRibbon2 + leftRightRibbon + verticalScroll + horizontalScroll + wave + doubleWave + plus + flowChartProcess + flowChartDecision + flowChartInputOutput + flowChartPredefinedProcess + flowChartInternalStorage + flowChartDocument + flowChartMultidocument + flowChartTerminator + flowChartPreparation + flowChartManualInput + flowChartManualOperation + flowChartConnector + flowChartPunchedCard + flowChartPunchedTape + flowChartSummingJunction + flowChartOr + flowChartCollate + flowChartSort + flowChartExtract + flowChartMerge + flowChartOfflineStorage + flowChartOnlineStorage + flowChartMagneticTape + flowChartMagneticDisk + flowChartMagneticDrum + flowChartDisplay + flowChartDelay + flowChartAlternateProcess + flowChartOffpageConnector + actionButtonBlank + actionButtonHome + actionButtonHelp + actionButtonInformation + actionButtonForwardNext + actionButtonBackPrevious + actionButtonEnd + actionButtonBeginning + actionButtonReturn + actionButtonDocument + actionButtonSound + actionButtonMovie + gear6 + gear9 + funnel + mathPlus + mathMinus + mathMultiply + mathDivide + mathEqual + mathNotEqual + cornerTabs + squareTabs + plaqueTabs + chartX + chartStar + chartPlus + + + textNoShape + textPlain + textStop + textTriangle + textTriangleInverted + textChevron + textChevronInverted + textRingInside + textRingOutside + textArchUp + textArchDown + textCircle + textButton + textArchUpPour + textArchDownPour + textCirclePour + textButtonPour + textCurveUp + textCurveDown + textCanUp + textCanDown + textWave1 + textWave2 + textDoubleWave1 + textWave4 + textInflate + textDeflate + textInflateBottom + textDeflateBottom + textInflateTop + textDeflateTop + textDeflateInflate + textDeflateInflateDeflate + textFadeRight + textFadeLeft + textFadeUp + textFadeDown + textSlantUp + textSlantDown + textCascadeUp + textCascadeDown + + + + + + + + none + norm + lighten + lightenLess + darken + darkenLess + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bothSides + + left + + right + + largest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + left + + right + + center + + inside + + outside + + + + + + margin + + page + + column + + character + + leftMargin + + rightMargin + + insideMargin + + outsideMargin + + + + + + + + + + + + + + + + + + + top + + bottom + + center + + inside + + outside + + + + + + margin + + page + + paragraph + + line + + topMargin + + bottomMargin + + insideMargin + + outsideMargin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + bothSides + left + right + largest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + margin + page + column + character + leftMargin + rightMargin + insideMargin + outsideMargin + + + + + + + + + + + margin + page + paragraph + line + topMargin + bottomMargin + insideMargin + outsideMargin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on + + off + + + + + + + + + + + + + + + + + + + left + + center + + right + + + + + + + + + + + top + + center + + bot + + + + + + + + + + + centered + + match + + + + + + + + + + + bar + + skw + + lin + + noBar + + + + + + + + + + + undOvr + + subSup + + + + + + + + + + + top + + bot + + + + + + + + + + + roman + + script + + fraktur + + double-struck + + sans-serif + + monospace + + + + + + + + + + + p + + b + + i + + bi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + start + + end + + left + + right + + center + + centerGroup + + + + + + + + + + + + + + + + + + + + + + + + before + + after + + repeat + + + + + + + + + + + -- + + -+ + + +- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + on + off + + + + + + + + + + + + left + center + right + + + + + + top + center + bot + + + + + + centered + match + + + + + + bar + skw + lin + noBar + + + + + + undOvr + subSup + + + + + + top + bot + + + + + + roman + script + fraktur + double-struck + sans-serif + monospace + + + + + + b + bi + i + p + + + + + + left + right + left + right + center + centerGroup + + + + + + + + + + + before + after + repeat + + + + + + -- + -+ + +- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + solid + + gradient + + gradientRadial + + tile + + pattern + + frame + + + + + + single + + thinThin + + thinThick + + thickThin + + thickBetweenThin + + + + + + round + + bevel + + miter + + + + + + flat + + square + + round + + + + + + short + + medium + + long + + + + + + narrow + + medium + + wide + + + + + + none + + block + + classic + + oval + + diamond + + open + + + + + + ignore + + atMost + + atLeast + + + + + + t + + f + + true + + false + + + + + + + + + + + + + + + solid + gradient + gradientRadial + tile + pattern + frame + + + single + thinThin + thinThick + thickThin + thickBetweenThin + + + round + bevel + miter + + + flat + square + round + + + short + medium + long + + + narrow + medium + wide + + + none + block + classic + oval + diamond + open + + + ignore + atMost + atLeast + + + t + f + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + any + + 30 + + 45 + + 60 + + 90 + + auto + + + + + + Picture + + Bitmap + + EnhancedMetaFile + + + + + + + + t + + f + + true + + false + + + + + + gradientCenter + + solid + + pattern + + tile + + frame + + gradientUnscaled + + gradientRadial + + gradient + + background + + + + + + + + + + + + + + + + + + + + + + + + + + + + + any + 30 + 45 + 60 + 90 + auto + + + Picture + Bitmap + EnhancedMetaFile + + + + t + f + true + false + + + gradientCenter + solid + pattern + tile + frame + gradientUnscaled + gradientRadial + gradient + background + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + topAndBottom + + square + + none + + tight + + through + + + + + + both + + left + + right + + largest + + + + + + margin + + page + + text + + char + + + + + + margin + + page + + text + + line + + + + + + + + + + + + + + topAndBottom + square + none + tight + through + + + both + left + right + largest + + + margin + page + text + char + + + margin + page + text + line + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + false + + on + + off + + 0 + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + black + + blue + + cyan + + green + + magenta + + red + + yellow + + white + + darkBlue + + darkCyan + + darkGreen + + darkMagenta + + darkRed + + darkYellow + + darkGray + + lightGray + + none + + + + + + + + + + + auto + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + single + + words + + double + + thick + + dotted + + dottedHeavy + + dash + + dashedHeavy + + dashLong + + dashLongHeavy + + dotDash + + dashDotHeavy + + dotDotDash + + dashDotDotHeavy + + wave + + wavyHeavy + + wavyDouble + + none + + + + + + + + + + + + + + + + + + + + + + + blinkBackground + + lights + + antsBlack + + antsRed + + shimmer + + sparkle + + none + + + + + + + + + + + nil + + none + + single + + thick + + double + + dotted + + dashed + + dotDash + + dotDotDash + + triple + + thinThickSmallGap + + thickThinSmallGap + + thinThickThinSmallGap + + thinThickMediumGap + + thickThinMediumGap + + thinThickThinMediumGap + + thinThickLargeGap + + thickThinLargeGap + + thinThickThinLargeGap + + wave + + doubleWave + + dashSmallGap + + dashDotStroked + + threeDEmboss + + threeDEngrave + + outset + + inset + + apples + + archedScallops + + babyPacifier + + babyRattle + + balloons3Colors + + balloonsHotAir + + basicBlackDashes + + basicBlackDots + + basicBlackSquares + + basicThinLines + + basicWhiteDashes + + basicWhiteDots + + basicWhiteSquares + + basicWideInline + + basicWideMidline + + basicWideOutline + + bats + + birds + + birdsFlight + + cabins + + cakeSlice + + candyCorn + + celticKnotwork + + certificateBanner + + chainLink + + champagneBottle + + checkedBarBlack + + checkedBarColor + + checkered + + christmasTree + + circlesLines + + circlesRectangles + + classicalWave + + clocks + + compass + + confetti + + confettiGrays + + confettiOutline + + confettiStreamers + + confettiWhite + + cornerTriangles + + couponCutoutDashes + + couponCutoutDots + + crazyMaze + + creaturesButterfly + + creaturesFish + + creaturesInsects + + creaturesLadyBug + + crossStitch + + cup + + decoArch + + decoArchColor + + decoBlocks + + diamondsGray + + doubleD + + doubleDiamonds + + earth1 + + earth2 + + eclipsingSquares1 + + eclipsingSquares2 + + eggsBlack + + fans + + film + + firecrackers + + flowersBlockPrint + + flowersDaisies + + flowersModern1 + + flowersModern2 + + flowersPansy + + flowersRedRose + + flowersRoses + + flowersTeacup + + flowersTiny + + gems + + gingerbreadMan + + gradient + + handmade1 + + handmade2 + + heartBalloon + + heartGray + + hearts + + heebieJeebies + + holly + + houseFunky + + hypnotic + + iceCreamCones + + lightBulb + + lightning1 + + lightning2 + + mapPins + + mapleLeaf + + mapleMuffins + + marquee + + marqueeToothed + + moons + + mosaic + + musicNotes + + northwest + + ovals + + packages + + palmsBlack + + palmsColor + + paperClips + + papyrus + + partyFavor + + partyGlass + + pencils + + people + + peopleWaving + + peopleHats + + poinsettias + + postageStamp + + pumpkin1 + + pushPinNote2 + + pushPinNote1 + + pyramids + + pyramidsAbove + + quadrants + + rings + + safari + + sawtooth + + sawtoothGray + + scaredCat + + seattle + + shadowedSquares + + sharksTeeth + + shorebirdTracks + + skyrocket + + snowflakeFancy + + snowflakes + + sombrero + + southwest + + stars + + starsTop + + stars3d + + starsBlack + + starsShadowed + + sun + + swirligig + + tornPaper + + tornPaperBlack + + trees + + triangleParty + + triangles + + tribal1 + + tribal2 + + tribal3 + + tribal4 + + tribal5 + + tribal6 + + twistedLines1 + + twistedLines2 + + vine + + waveline + + weavingAngles + + weavingBraid + + weavingRibbon + + weavingStrips + + whiteFlowers + + woodwork + + xIllusions + + zanyTriangles + + zigZag + + zigZagStitch + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nil + + clear + + solid + + horzStripe + + vertStripe + + reverseDiagStripe + + diagStripe + + horzCross + + diagCross + + thinHorzStripe + + thinVertStripe + + thinReverseDiagStripe + + thinDiagStripe + + thinHorzCross + + thinDiagCross + + pct5 + + pct10 + + pct12 + + pct15 + + pct20 + + pct25 + + pct30 + + pct35 + + pct37 + + pct40 + + pct45 + + pct50 + + pct55 + + pct60 + + pct62 + + pct65 + + pct70 + + pct75 + + pct80 + + pct85 + + pct87 + + pct90 + + pct95 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + none + + dot + + comma + + circle + + underDot + + + + + + + + + + + + + + + + + + + + + + none + + round + + square + + angle + + curly + + + + + + + + + + + + + + + + + + + + + + + left + + center + + right + + inside + + outside + + + + + + inline + + top + + center + + bottom + + inside + + outside + + + + + + auto + + exact + + atLeast + + + + + + auto + + notBeside + + around + + tight + + through + + none + + + + + + text + + margin + + page + + + + + + text + + margin + + page + + + + + + none + + drop + + margin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + clear + + start + + left + + center + + end + + right + + decimal + + bar + + num + + + + + + none + + dot + + hyphen + + underscore + + heavy + + middleDot + + + + + + + + + + + + + + + + + auto + + exact + + atLeast + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + start + + end + + left + + center + + right + + both + + mediumKashida + + distribute + + numTab + + highKashida + + lowKashida + + thaiDistribute + + + + + + + + + + + none + + print + + outline + + masterPages + + normal + + web + + + + + + + + + + + none + + fullPage + + bestFit + + textFit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + notSpecified + + letter + + eMail + + + + + + + + + + + none + + readOnly + + comments + + trackedChanges + + forms + + + + + + rsaAES + + rsaFull + + + + + + hash + + + + + + typeAny + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lrTb + + tbRl + + btLr + + lrTbV + + tbRlV + + tbLrV + + + + + + + + + + + top + + center + + baseline + + bottom + + auto + + + + + + + + + + + next + + prev + + + + + + cont + + rest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + begin + + separate + + end + + + + + + text + + autoText + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nextPage + + nextColumn + + continuous + + evenPage + + oddPage + + + + + + + + + + + + + + + + + + + decimal + + upperRoman + + lowerRoman + + upperLetter + + lowerLetter + + ordinal + + cardinalText + + ordinalText + + hex + + chicago + + ideographDigital + + japaneseCounting + + aiueo + + iroha + + decimalFullWidth + + decimalHalfWidth + + japaneseLegal + + japaneseDigitalTenThousand + + decimalEnclosedCircle + + decimalFullWidth2 + + aiueoFullWidth + + irohaFullWidth + + decimalZero + + bullet + + ganada + + chosung + + decimalEnclosedFullstop + + decimalEnclosedParen + + decimalEnclosedCircleChinese + + ideographEnclosedCircle + + ideographTraditional + + ideographZodiac + + ideographZodiacTraditional + + taiwaneseCounting + + ideographLegalTraditional + + taiwaneseCountingThousand + + taiwaneseDigital + + chineseCounting + + chineseLegalSimplified + + chineseCountingThousand + + koreanDigital + + koreanCounting + + koreanLegal + + koreanDigital2 + + vietnameseCounting + + russianLower + + russianUpper + + none + + numberInDash + + hebrew1 + + hebrew2 + + arabicAlpha + + arabicAbjad + + hindiVowels + + hindiConsonants + + hindiNumbers + + hindiCounting + + thaiLetters + + thaiNumbers + + thaiCounting + custom + + + + + + portrait + + landscape + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + front + + back + + + + + + allPages + + firstPage + + notFirstPage + + + + + + page + + text + + + + + + + + + + + + + + + + + + + + + + + + + + + + + hyphen + + period + + colon + + emDash + + enDash + + + + + + newPage + + newSection + + continuous + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + top + + center + + both + + bottom + + + + + + + + + + + default + + lines + + linesAndChars + + snapToChars + + + + + + + + + + + + + + + + + even + + default + + first + + + + + + normal + + separator + + continuationSeparator + + continuationNotice + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + page + + column + + textWrapping + + + + + + none + + left + + right + + all + + + + + + + + + + + + + + + + + + + + + + left + + center + + right + + + + + + margin + + indent + + + + + + none + + dot + + hyphen + + underscore + + middleDot + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + default + + eastAsia + + cs + + + + + + majorEastAsia + + majorBidi + + majorAscii + + majorHAnsi + + minorEastAsia + + minorBidi + + minorAscii + + minorHAnsi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + center + distributeLetter + distributeSpace + left + right + rightVertical + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ltr + rtl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nil + + pct + + dxa + + auto + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + continue + + restart + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fixed + + autofit + + + + + + + + + + + never + + overlap + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pageBottom + + beneathText + + sectEnd + + docEnd + + + + + + + + + + + sectEnd + + docEnd + + + + + + + + + + + + + + + + + + + continuous + + eachSect + + eachPage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dark1 + + light1 + + dark2 + + light2 + + accent1 + + accent2 + + accent3 + + accent4 + + accent5 + + accent6 + + hyperlink + + followedHyperlink + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + singleLevel + + multilevel + + hybridMultilevel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wholeTable + + firstRow + + lastRow + + firstCol + + lastCol + + band1Vert + + band2Vert + + band1Horz + + band2Horz + + neCell + + nwCell + + seCell + + swCell + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + paragraph + + character + + table + + numbering + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + decorative + + modern + + roman + + script + + swiss + + auto + + + + + + + + + + + fixed + + variable + + default + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dark1 + + light1 + + dark2 + + light2 + + accent1 + + accent2 + + accent3 + + accent4 + + accent5 + + accent6 + + hyperlink + + followedHyperlink + + none + + background1 + + text1 + + background2 + + text2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + above + + below + + left + + right + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + black + blue + cyan + green + magenta + red + yellow + white + darkBlue + darkCyan + darkGreen + darkMagenta + darkRed + darkYellow + darkGray + lightGray + none + + + + + + auto + + + + + + + + + + + + + + + + + + + + + single + words + double + thick + dotted + dottedHeavy + dash + dashedHeavy + dashLong + dashLongHeavy + dotDash + dashDotHeavy + dotDotDash + dashDotDotHeavy + wave + wavyHeavy + wavyDouble + none + + + + + + + + + + none + lights + blinkBackground + sparkle + antsBlack + antsRed + shimmer + + + + + + nil + none + single + thick + double + dotted + dashed + dotDash + dotDotDash + triple + thinThickSmallGap + thickThinSmallGap + thinThickThinSmallGap + thinThickMediumGap + thickThinMediumGap + thinThickThinMediumGap + thinThickLargeGap + thickThinLargeGap + thinThickThinLargeGap + wave + doubleWave + dashSmallGap + dashDotStroked + threeDEmboss + threeDEngrave + outset + inset + apples + archedScallops + babyPacifier + babyRattle + balloons3Colors + balloonsHotAir + basicBlackDashes + basicBlackDots + basicBlackSquares + basicThinLines + basicWhiteDashes + basicWhiteDots + basicWhiteSquares + basicWideInline + basicWideMidline + basicWideOutline + bats + birds + birdsFlight + cabins + cakeSlice + candyCorn + celticKnotwork + certificateBanner + chainLink + champagneBottle + checkedBarBlack + checkedBarColor + checkered + christmasTree + circlesLines + circlesRectangles + classicalWave + clocks + compass + confetti + confettiGrays + confettiOutline + confettiStreamers + confettiWhite + cornerTriangles + couponCutoutDashes + couponCutoutDots + crazyMaze + creaturesButterfly + creaturesFish + creaturesInsects + creaturesLadyBug + crossStitch + cup + decoArch + decoArchColor + decoBlocks + diamondsGray + doubleD + doubleDiamonds + earth1 + earth2 + eclipsingSquares1 + eclipsingSquares2 + eggsBlack + fans + film + firecrackers + flowersBlockPrint + flowersDaisies + flowersModern1 + flowersModern2 + flowersPansy + flowersRedRose + flowersRoses + flowersTeacup + flowersTiny + gems + gingerbreadMan + gradient + handmade1 + handmade2 + heartBalloon + heartGray + hearts + heebieJeebies + holly + houseFunky + hypnotic + iceCreamCones + lightBulb + lightning1 + lightning2 + mapPins + mapleLeaf + mapleMuffins + marquee + marqueeToothed + moons + mosaic + musicNotes + northwest + ovals + packages + palmsBlack + palmsColor + paperClips + papyrus + partyFavor + partyGlass + pencils + people + peopleWaving + peopleHats + poinsettias + postageStamp + pumpkin1 + pushPinNote2 + pushPinNote1 + pyramids + pyramidsAbove + quadrants + rings + safari + sawtooth + sawtoothGray + scaredCat + seattle + shadowedSquares + sharksTeeth + shorebirdTracks + skyrocket + snowflakeFancy + snowflakes + sombrero + southwest + stars + starsTop + stars3d + starsBlack + starsShadowed + sun + swirligig + tornPaper + tornPaperBlack + trees + triangleParty + triangles + tribal1 + tribal2 + tribal3 + tribal4 + tribal5 + tribal6 + twistedLines1 + twistedLines2 + vine + waveline + weavingAngles + weavingBraid + weavingRibbon + weavingStrips + whiteFlowers + woodwork + xIllusions + zanyTriangles + zigZag + zigZagStitch + + + + + + + + + + + + + + + + clear + solid + pct5 + pct10 + pct20 + pct25 + pct30 + pct40 + pct50 + pct60 + pct70 + pct75 + pct80 + pct90 + horzStripe + vertStripe + reverseDiagStripe + diagStripe + horzCross + diagCross + thinHorzStripe + thinVertStripe + thinReverseDiagStripe + thinDiagStripe + thinHorzCross + thinDiagCross + pct12 + pct15 + pct35 + pct37 + pct45 + pct55 + pct62 + pct65 + pct85 + pct87 + pct95 + nil + + + + + + + + + + + + + + + + + + + + + + none + dot + comma + circle + underDot + + + + + + + + + + + none + round + square + angle + curly + + + + + + + + + + left + center + right + inside + outside + + + inline + top + center + bottom + inside + outside + + + auto + exact + atLeast + + + auto + notBeside + around + tight + through + none + + + text + margin + page + + + text + margin + page + + + none + drop + margin + + + + + + + + + + + + + + + + + + + + clear + start + left + center + end + right + decimal + bar + num + + + none + dot + hyphen + underscore + heavy + middleDot + + + + + + + + auto + exact + atLeast + + + + + + + + + + + + + + + + + + + + + + + + + + + + left + right + start + center + end + both + mediumKashida + distribute + numTab + highKashida + lowKashida + thaiDistribute + + + + + + none + print + outline + masterPages + normal + web + + + + + + none + fullPage + bestFit + textFit + + + + + + + + + + + + + + + + + + + + notSpecified + letter + eMail + + + + + + none + readOnly + comments + trackedChanges + forms + + + rsaAES + rsaFull + + + hash + + + typeAny + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lrTb + tbRl + btLr + lrTbV + tbRlV + tbLrV + + + + + + top + center + baseline + bottom + auto + + + + + + next + prev + + + cont + rest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + begin + separate + end + + + text + autoText + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + continuous + nextColumn + nextPage + evenPage + oddPage + + + + + + decimal + upperRoman + lowerRoman + upperLetter + lowerLetter + ordinal + cardinalText + ordinalText + hex + chicago + ideographDigital + japaneseCounting + aiueo + iroha + decimalFullWidth + decimalHalfWidth + japaneseLegal + japaneseDigitalTenThousand + decimalEnclosedCircle + decimalFullWidth2 + aiueoFullWidth + irohaFullWidth + decimalZero + bullet + ganada + chosung + decimalEnclosedFullstop + decimalEnclosedParen + decimalEnclosedCircleChinese + ideographEnclosedCircle + ideographTraditional + ideographZodiac + ideographZodiacTraditional + taiwaneseCounting + ideographLegalTraditional + taiwaneseCountingThousand + taiwaneseDigital + chineseCounting + chineseLegalSimplified + chineseCountingThousand + koreanDigital + koreanCounting + koreanLegal + koreanDigital2 + vietnameseCounting + russianLower + russianUpper + none + numberInDash + hebrew1 + hebrew2 + arabicAlpha + arabicAbjad + hindiVowels + hindiConsonants + hindiNumbers + hindiCounting + thaiLetters + thaiNumbers + thaiCounting + custom + + + portrait + landscape + + + + + + + + + + + + + + + + + + front + back + + + allPages + firstPage + notFirstPage + + + page + text + + + + + + + + + + + + hyphen + period + colon + emDash + enDash + + + newPage + newSection + continuous + + + + + + + + + + + + + + + + + + + + + + + + + + top + center + both + bottom + + + + + + default + lines + linesAndChars + snapToChars + + + + + + + + even + default + first + + + normal + separator + continuationSeparator + continuationNotice + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + column + page + textWrapping + + + none + left + right + all + + + + + + + + + + + + + left + center + right + + + margin + indent + + + none + dot + hyphen + underscore + middleDot + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + default + eastAsia + cs + + + majorEastAsia + majorBidi + majorAscii + majorHAnsi + minorEastAsia + minorBidi + minorAscii + minorHAnsi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + center + distributeLetter + distributeSpace + left + right + rightVertical + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ltr + rtl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nil + pct + dxa + auto + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + continue + restart + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fixed + autofit + + + + + + never + overlap + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pageBottom + beneathText + sectEnd + docEnd + + + + + + sectEnd + docEnd + + + + + + + + + + continuous + eachSect + eachPage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dark1 + light1 + dark2 + light2 + accent1 + accent2 + accent3 + accent4 + accent5 + accent6 + hyperlink + followedHyperlink + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + singleLevel + multilevel + hybridMultilevel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wholeTable + firstRow + lastRow + firstCol + lastCol + band1Vert + band2Vert + band1Horz + band2Horz + neCell + nwCell + seCell + swCell + + + + + + + + + + + paragraph + character + table + numbering + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + decorative + modern + roman + script + swiss + auto + + + + + + fixed + variable + default + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dark1 + light1 + dark2 + light2 + accent1 + accent2 + accent3 + accent4 + accent5 + accent6 + hyperlink + followedHyperlink + none + background1 + text1 + background2 + text2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + above + below + left + right + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/writerfilter/source/ooxml/modelpreprocess.py b/writerfilter/source/ooxml/modelpreprocess.py new file mode 100644 index 000000000..d6ef4c175 --- /dev/null +++ b/writerfilter/source/ooxml/modelpreprocess.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from xml.dom import minidom +import sys + + +def prefixForGrammar(namespace): + ns = namespace.getElementsByTagName("grammar")[0].getAttribute("ns") + return ooxUrlAliases[ns] + + +def parseNamespaceAliases(node): + ret = {} + for k, v in list(node.attributes.items()): + if k.startswith("xmlns:"): + ret[k.replace('xmlns:', '')] = v + return ret + + +def parseNamespaces(fro): + sock = open(fro) + for i in sock.readlines(): + line = i.strip() + alias, url = line.split(' ')[1:] + ooxUrlAliases[url] = alias + sock.close() + + +def check(model): + defines = [i.getAttribute("name") for i in model.getElementsByTagName("define")] + for reference in [i.getAttribute("name") for i in model.getElementsByTagName("ref")]: + if reference not in defines: + raise Exception("Unknown define element with name '%s'" % reference) + for start in [i.getAttribute("name") for i in model.getElementsByTagName("start")]: + if start not in defines: + raise Exception("Unknown start element with name '%s'" % start) + + +def preprocess(model): + modelNode = [i for i in model.childNodes if i.localName == "model"][0] + # Alias -> URL, based on "xmlns:" attributes. + modelNamespaceAliases = parseNamespaceAliases(modelNode) + for i in modelNode.getElementsByTagName("namespace"): + grammarprefix = prefixForGrammar(i) + + grammar = i.getElementsByTagName("grammar")[0] + + for j in i.getElementsByTagName("element") + i.getElementsByTagName("attribute"): + # prefix + prefix = "" + if ":" in j.getAttribute("name"): + nameprefix = j.getAttribute("name").split(':')[0] + prefix = ooxUrlAliases[modelNamespaceAliases[nameprefix]] + elif j.localName == "attribute": + if grammar.getAttribute("attributeFormDefault") == "qualified": + prefix = grammarprefix + else: + prefix = grammarprefix + + # localname + if ":" in j.getAttribute("name"): + localname = j.getAttribute("name").split(':')[1] + else: + localname = j.getAttribute("name") + + # set the attributes + j.setAttribute("prefix", prefix) + j.setAttribute("localname", localname) + + +namespacesPath = sys.argv[1] +modelPath = sys.argv[2] + +# URL -> alias, from oox +ooxUrlAliases = {} +parseNamespaces(namespacesPath) + +model = minidom.parse(modelPath) +check(model) +preprocess(model) +model.writexml(sys.stdout) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/qnametostr.py b/writerfilter/source/ooxml/qnametostr.py new file mode 100644 index 000000000..e09a98570 --- /dev/null +++ b/writerfilter/source/ooxml/qnametostr.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +import xml.sax +import sys + + +class ContentHandler(xml.sax.handler.ContentHandler): + def __init__(self): + self.tokens = [] + + def startDocument(self): + print(""" +#include "ooxml/resourceids.hxx" +#include "ooxml/QNameToString.hxx" +#include "unordered_map" + +namespace writerfilter +{ + +#ifdef DBG_UTIL + + /* ooxml */ + static const std::unordered_map g_QNameToStringMap { +""") + + def endDocument(self): + print(""" + }; + + std::string QNameToString(Id qName) + { + auto it = g_QNameToStringMap.find(qName); + if (it == g_QNameToStringMap.end()) + return std::string(); + + return it->second; + } + +#endif +} +""") + + def startElement(self, name, attrs): + for k, v in list(attrs.items()): + if k == "tokenid": + if v.startswith("ooxml:"): + token = v.replace('ooxml:', '') + if token not in self.tokens: + print(""" { NS_ooxml::LN_%s, "ooxml:%s" },""" % (token, token)) + self.tokens.append(token) + + +parser = xml.sax.make_parser() +parser.setContentHandler(ContentHandler()) +parser.parse(sys.argv[1]) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/resourceids.py b/writerfilter/source/ooxml/resourceids.py new file mode 100644 index 000000000..70325c9d3 --- /dev/null +++ b/writerfilter/source/ooxml/resourceids.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +import xml.sax +import sys + + +class ContentHandler(xml.sax.handler.ContentHandler): + def __init__(self): + self.tokens = [] + self.counter = 90001 + + def startDocument(self): + print(""" +/* + + THIS FILE IS GENERATED AUTOMATICALLY! DO NOT EDIT! + +*/ + + +#ifndef INCLUDED_OOXML_RESOURCEIDS_HXX +#define INCLUDED_OOXML_RESOURCEIDS_HXX + +#include + +namespace writerfilter { + +namespace NS_ooxml +{""") + + def endDocument(self): + print("""} + + +} +#endif // INCLUDED_OOXML_RESOURCEIDS_HXX""") + + def startElement(self, name, attrs): + for k, v in attrs.items(): + if k in ("tokenid", "sendtokenid"): + if v.startswith("ooxml:"): + token = v.replace('ooxml:', '') + if token not in self.tokens: + print(" const Id LN_%s = %s;" % (token, self.counter)) + self.tokens.append(token) + self.counter += 1 + + +parser = xml.sax.make_parser() +parser.setContentHandler(ContentHandler()) +parser.parse(sys.argv[1]) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/writerfilter/source/ooxml/tox.ini b/writerfilter/source/ooxml/tox.ini new file mode 100644 index 000000000..c1781905c --- /dev/null +++ b/writerfilter/source/ooxml/tox.ini @@ -0,0 +1,2 @@ +[pycodestyle] +ignore = E501 diff --git a/writerfilter/source/rtftok/README b/writerfilter/source/rtftok/README new file mode 100644 index 000000000..4adbb7563 --- /dev/null +++ b/writerfilter/source/rtftok/README @@ -0,0 +1,12 @@ += Writerfilter-based RTF tokenizer + +== Mathematics + +At the time of writing, all control words understood by SmOoxmlImport are +imported. To view the current status: + +---- +grep M_TOKEN starmath/source/ooxmlimport.cxx |sed 's/.*\(M_TOKEN(\) /\1/;s/ ).*/)/'|sort -u > ~/math-import-list +grep '[^_]M_TOKEN' writerfilter/source/rtftok/rtfdocumentimpl.cxx |sed 's/.*\(M_TOKEN(\)/\1/;s/).*/)/'|sort -u > ~/wf-export-list +diff -u ~/math-import-list ~/wf-export-list |grep ^-M_TOKEN +---- diff --git a/writerfilter/source/rtftok/rtfcharsets.cxx b/writerfilter/source/rtftok/rtfcharsets.cxx new file mode 100644 index 000000000..69e416ce8 --- /dev/null +++ b/writerfilter/source/rtftok/rtfcharsets.cxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfcharsets.hxx" +#include + +namespace writerfilter::rtftok +{ +// See RTF spec v1.9.1, page 19 +RTFEncoding const aRTFEncodings[] = { + // charset codepage Windows / Mac name + { 0, 1252 }, // ANSI + { 1, 0 }, // Default + { 2, 42 }, // Symbol + { 77, 10000 }, // Mac Roman + { 78, 10001 }, // Mac Shift Jis + { 79, 10003 }, // Mac Hangul + { 80, 10008 }, // Mac GB2312 + { 81, 10002 }, // Mac Big5 + { 83, 10005 }, // Mac Herbrew + { 84, 10004 }, // Mac Arabic + { 85, 10006 }, // Mac Greek + { 86, 10081 }, // Mac Turkish + { 87, 10021 }, // Mac Thai + { 88, 10029 }, // Mac East Europe + { 89, 10007 }, // Mac Russian + { 128, 932 }, // Shift JIS + { 129, 949 }, // Hangul + { 130, 1361 }, // Johab + { 134, 936 }, // GB2312 + { 136, 950 }, // Big5 + { 161, 1253 }, // Greek + { 162, 1254 }, // Turkish + { 163, 1258 }, // Vietnamese + { 177, 1255 }, // Herbrew + { 178, 1256 }, // Arabic + { 186, 1257 }, // Baltic + { 204, 1251 }, // Russian + { 222, 874 }, // Thai + { 238, 1250 }, // Eastern European + { 254, 437 }, // PC 437 + { 255, 850 }, // OEM +}; + +int nRTFEncodings = SAL_N_ELEMENTS(aRTFEncodings); + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfcharsets.hxx b/writerfilter/source/rtftok/rtfcharsets.hxx new file mode 100644 index 000000000..42ddccce2 --- /dev/null +++ b/writerfilter/source/rtftok/rtfcharsets.hxx @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFCHARSETS_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFCHARSETS_HXX + +namespace writerfilter +{ +namespace rtftok +{ +/// RTF legacy charsets +struct RTFEncoding +{ + int charset; + int codepage; +}; +extern RTFEncoding const aRTFEncodings[]; +extern int nRTFEncodings; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFCHARSETS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfcontrolwords.cxx b/writerfilter/source/rtftok/rtfcontrolwords.cxx new file mode 100644 index 000000000..38bc9d6dd --- /dev/null +++ b/writerfilter/source/rtftok/rtfcontrolwords.cxx @@ -0,0 +1,1900 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfcontrolwords.hxx" +#include + +namespace writerfilter::rtftok +{ +RTFSymbol const aRTFControlWords[] = { + // sKeyword nControlType nIndex + { "'", CONTROL_SYMBOL, RTF_HEXCHAR, 0 }, + { "-", CONTROL_SYMBOL, RTF_OPTHYPH, 0 }, + { "*", CONTROL_SYMBOL, RTF_IGNORE, 0 }, + { ":", CONTROL_SYMBOL, RTF_SUBENTRY, 0 }, + { "\\", CONTROL_SYMBOL, RTF_BACKSLASH, 0 }, + { "\n", CONTROL_SYMBOL, RTF_PAR, 0 }, + { "\r", CONTROL_SYMBOL, RTF_PAR, 0 }, + { "\r\n", CONTROL_SYMBOL, RTF_PAR, 0 }, + { "_", CONTROL_SYMBOL, RTF_NOBRKHYPH, 0 }, + { "{", CONTROL_SYMBOL, RTF_LBRACE, 0 }, + { "|", CONTROL_SYMBOL, RTF_FORMULA, 0 }, + { "}", CONTROL_SYMBOL, RTF_RBRACE, 0 }, + { "~", CONTROL_SYMBOL, RTF_NOBREAK, 0 }, + { "ab", CONTROL_TOGGLE, RTF_AB, 1 }, + { "absh", CONTROL_VALUE, RTF_ABSH, 0 }, + { "abslock", CONTROL_FLAG, RTF_ABSLOCK, 0 }, + { "absnoovrlp", CONTROL_TOGGLE, RTF_ABSNOOVRLP, 1 }, + { "absw", CONTROL_VALUE, RTF_ABSW, 0 }, + { "acaps", CONTROL_TOGGLE, RTF_ACAPS, 1 }, + { "acccircle", CONTROL_TOGGLE, RTF_ACCCIRCLE, 1 }, + { "acccomma", CONTROL_TOGGLE, RTF_ACCCOMMA, 1 }, + { "accdot", CONTROL_TOGGLE, RTF_ACCDOT, 1 }, + { "accnone", CONTROL_TOGGLE, RTF_ACCNONE, 1 }, + { "accunderdot", CONTROL_TOGGLE, RTF_ACCUNDERDOT, 1 }, + { "acf", CONTROL_VALUE, RTF_ACF, 0 }, + { "adeff", CONTROL_VALUE, RTF_ADEFF, 0 }, + { "additive", CONTROL_FLAG, RTF_ADDITIVE, 0 }, + { "adeflang", CONTROL_VALUE, RTF_ADEFLANG, 0 }, + { "adjustright", CONTROL_FLAG, RTF_ADJUSTRIGHT, 0 }, + { "adn", CONTROL_VALUE, RTF_ADN, 6 }, + { "aenddoc", CONTROL_FLAG, RTF_AENDDOC, 0 }, + { "aendnotes", CONTROL_FLAG, RTF_AENDNOTES, 0 }, + { "aexpnd", CONTROL_VALUE, RTF_AEXPND, 0 }, + { "af", CONTROL_VALUE, RTF_AF, 0 }, + { "afelev", CONTROL_FLAG, RTF_AFELEV, 0 }, + { "afs", CONTROL_VALUE, RTF_AFS, 24 }, + { "aftnbj", CONTROL_FLAG, RTF_AFTNBJ, 0 }, + { "aftncn", CONTROL_DESTINATION, RTF_AFTNCN, 0 }, + { "aftnnalc", CONTROL_FLAG, RTF_AFTNNALC, 0 }, + { "aftnnar", CONTROL_FLAG, RTF_AFTNNAR, 0 }, + { "aftnnauc", CONTROL_FLAG, RTF_AFTNNAUC, 0 }, + { "aftnnchi", CONTROL_FLAG, RTF_AFTNNCHI, 0 }, + { "aftnnchosung", CONTROL_FLAG, RTF_AFTNNCHOSUNG, 0 }, + { "aftnncnum", CONTROL_FLAG, RTF_AFTNNCNUM, 0 }, + { "aftnndbar", CONTROL_FLAG, RTF_AFTNNDBAR, 0 }, + { "aftnndbnum", CONTROL_FLAG, RTF_AFTNNDBNUM, 0 }, + { "aftnndbnumd", CONTROL_FLAG, RTF_AFTNNDBNUMD, 0 }, + { "aftnndbnumk", CONTROL_FLAG, RTF_AFTNNDBNUMK, 0 }, + { "aftnndbnumt", CONTROL_FLAG, RTF_AFTNNDBNUMT, 0 }, + { "aftnnganada", CONTROL_FLAG, RTF_AFTNNGANADA, 0 }, + { "aftnngbnum", CONTROL_FLAG, RTF_AFTNNGBNUM, 0 }, + { "aftnngbnumd", CONTROL_FLAG, RTF_AFTNNGBNUMD, 0 }, + { "aftnngbnumk", CONTROL_FLAG, RTF_AFTNNGBNUMK, 0 }, + { "aftnngbnuml", CONTROL_FLAG, RTF_AFTNNGBNUML, 0 }, + { "aftnnrlc", CONTROL_FLAG, RTF_AFTNNRLC, 0 }, + { "aftnnruc", CONTROL_FLAG, RTF_AFTNNRUC, 0 }, + { "aftnnzodiac", CONTROL_FLAG, RTF_AFTNNZODIAC, 0 }, + { "aftnnzodiacd", CONTROL_FLAG, RTF_AFTNNZODIACD, 0 }, + { "aftnnzodiacl", CONTROL_FLAG, RTF_AFTNNZODIACL, 0 }, + { "aftnrestart", CONTROL_FLAG, RTF_AFTNRESTART, 0 }, + { "aftnrstcont", CONTROL_FLAG, RTF_AFTNRSTCONT, 0 }, + { "aftnsep", CONTROL_DESTINATION, RTF_AFTNSEP, 0 }, + { "aftnsepc", CONTROL_DESTINATION, RTF_AFTNSEPC, 0 }, + { "aftnstart", CONTROL_VALUE, RTF_AFTNSTART, 1 }, + { "aftntj", CONTROL_FLAG, RTF_AFTNTJ, 0 }, + { "ai", CONTROL_TOGGLE, RTF_AI, 1 }, + { "alang", CONTROL_VALUE, RTF_ALANG, 0 }, + { "allowfieldendsel", CONTROL_FLAG, RTF_ALLOWFIELDENDSEL, 0 }, + { "allprot", CONTROL_FLAG, RTF_ALLPROT, 0 }, + { "alntblind", CONTROL_FLAG, RTF_ALNTBLIND, 0 }, + { "alt", CONTROL_FLAG, RTF_ALT, 0 }, + { "animtext", CONTROL_VALUE, RTF_ANIMTEXT, 0 }, + { "annotation", CONTROL_DESTINATION, RTF_ANNOTATION, 0 }, + { "annotprot", CONTROL_FLAG, RTF_ANNOTPROT, 0 }, + { "ansi", CONTROL_FLAG, RTF_ANSI, 0 }, + { "ansicpg", CONTROL_VALUE, RTF_ANSICPG, 0 }, + { "aoutl", CONTROL_TOGGLE, RTF_AOUTL, 1 }, + { "ApplyBrkRules", CONTROL_FLAG, RTF_APPLYBRKRULES, 0 }, + { "ascaps", CONTROL_TOGGLE, RTF_ASCAPS, 1 }, + { "ashad", CONTROL_TOGGLE, RTF_ASHAD, 1 }, + { "asianbrkrule", CONTROL_FLAG, RTF_ASIANBRKRULE, 0 }, + { "aspalpha", CONTROL_TOGGLE, RTF_ASPALPHA, 1 }, + { "aspnum", CONTROL_TOGGLE, RTF_ASPNUM, 1 }, + { "astrike", CONTROL_TOGGLE, RTF_ASTRIKE, 1 }, + { "atnauthor", CONTROL_DESTINATION, RTF_ATNAUTHOR, 0 }, + { "atndate", CONTROL_DESTINATION, RTF_ATNDATE, 0 }, + { "atnicn", CONTROL_DESTINATION, RTF_ATNICN, 0 }, + { "atnid", CONTROL_DESTINATION, RTF_ATNID, 0 }, + { "atnparent", CONTROL_DESTINATION, RTF_ATNPARENT, 0 }, + { "atnref", CONTROL_DESTINATION, RTF_ATNREF, 0 }, + { "atntime", CONTROL_DESTINATION, RTF_ATNTIME, 0 }, + { "atrfend", CONTROL_DESTINATION, RTF_ATRFEND, 0 }, + { "atrfstart", CONTROL_DESTINATION, RTF_ATRFSTART, 0 }, + { "aul", CONTROL_TOGGLE, RTF_AUL, 1 }, + { "auld", CONTROL_TOGGLE, RTF_AULD, 1 }, + { "auldb", CONTROL_TOGGLE, RTF_AULDB, 1 }, + { "aulnone", CONTROL_TOGGLE, RTF_AULNONE, 1 }, + { "aulw", CONTROL_TOGGLE, RTF_AULW, 1 }, + { "aup", CONTROL_VALUE, RTF_AUP, 6 }, + { "author", CONTROL_DESTINATION, RTF_AUTHOR, 0 }, + { "autofmtoverride", CONTROL_FLAG, RTF_AUTOFMTOVERRIDE, 0 }, + { "b", CONTROL_TOGGLE, RTF_B, 1 }, + { "background", CONTROL_DESTINATION, RTF_BACKGROUND, 0 }, + { "bdbfhdr", CONTROL_FLAG, RTF_BDBFHDR, 0 }, + { "bdrrlswsix", CONTROL_FLAG, RTF_BDRRLSWSIX, 0 }, + { "bgbdiag", CONTROL_FLAG, RTF_BGBDIAG, 0 }, + { "bgcross", CONTROL_FLAG, RTF_BGCROSS, 0 }, + { "bgdcross", CONTROL_FLAG, RTF_BGDCROSS, 0 }, + { "bgdkbdiag", CONTROL_FLAG, RTF_BGDKBDIAG, 0 }, + { "bgdkcross", CONTROL_FLAG, RTF_BGDKCROSS, 0 }, + { "bgdkdcross", CONTROL_FLAG, RTF_BGDKDCROSS, 0 }, + { "bgdkfdiag", CONTROL_FLAG, RTF_BGDKFDIAG, 0 }, + { "bgdkhoriz", CONTROL_FLAG, RTF_BGDKHORIZ, 0 }, + { "bgdkvert", CONTROL_FLAG, RTF_BGDKVERT, 0 }, + { "bgfdiag", CONTROL_FLAG, RTF_BGFDIAG, 0 }, + { "bghoriz", CONTROL_FLAG, RTF_BGHORIZ, 0 }, + { "bgvert", CONTROL_FLAG, RTF_BGVERT, 0 }, + { "bin", CONTROL_VALUE, RTF_BIN, 0 }, + { "binfsxn", CONTROL_VALUE, RTF_BINFSXN, 0 }, + { "binsxn", CONTROL_VALUE, RTF_BINSXN, 0 }, + { "bkmkcolf", CONTROL_VALUE, RTF_BKMKCOLF, 0 }, + { "bkmkcoll", CONTROL_VALUE, RTF_BKMKCOLL, 0 }, + { "bkmkend", CONTROL_DESTINATION, RTF_BKMKEND, 0 }, + { "bkmkpub", CONTROL_FLAG, RTF_BKMKPUB, 0 }, + { "bkmkstart", CONTROL_DESTINATION, RTF_BKMKSTART, 0 }, + { "bliptag", CONTROL_VALUE, RTF_BLIPTAG, 0 }, + { "blipuid", CONTROL_DESTINATION, RTF_BLIPUID, 0 }, + { "blipupi", CONTROL_VALUE, RTF_BLIPUPI, 0 }, + { "blue", CONTROL_VALUE, RTF_BLUE, 0 }, + { "bookfold", CONTROL_FLAG, RTF_BOOKFOLD, 0 }, + { "bookfoldrev", CONTROL_FLAG, RTF_BOOKFOLDREV, 0 }, + { "bookfoldsheets", CONTROL_VALUE, RTF_BOOKFOLDSHEETS, 0 }, + { "box", CONTROL_FLAG, RTF_BOX, 0 }, + { "brdrart", CONTROL_VALUE, RTF_BRDRART, 0 }, + { "brdrb", CONTROL_FLAG, RTF_BRDRB, 0 }, + { "brdrbar", CONTROL_FLAG, RTF_BRDRBAR, 0 }, + { "brdrbtw", CONTROL_FLAG, RTF_BRDRBTW, 0 }, + { "brdrcf", CONTROL_VALUE, RTF_BRDRCF, 0 }, + { "brdrdash", CONTROL_FLAG, RTF_BRDRDASH, 0 }, + { "brdrdashd", CONTROL_FLAG, RTF_BRDRDASHD, 0 }, + { "brdrdashdd", CONTROL_FLAG, RTF_BRDRDASHDD, 0 }, + { "brdrdashdotstr", CONTROL_FLAG, RTF_BRDRDASHDOTSTR, 0 }, + { "brdrdashsm", CONTROL_FLAG, RTF_BRDRDASHSM, 0 }, + { "brdrdb", CONTROL_FLAG, RTF_BRDRDB, 0 }, + { "brdrdot", CONTROL_FLAG, RTF_BRDRDOT, 0 }, + { "brdremboss", CONTROL_FLAG, RTF_BRDREMBOSS, 0 }, + { "brdrengrave", CONTROL_FLAG, RTF_BRDRENGRAVE, 0 }, + { "brdrframe", CONTROL_FLAG, RTF_BRDRFRAME, 0 }, + { "brdrhair", CONTROL_FLAG, RTF_BRDRHAIR, 0 }, + { "brdrinset", CONTROL_FLAG, RTF_BRDRINSET, 0 }, + { "brdrl", CONTROL_FLAG, RTF_BRDRL, 0 }, + { "brdrnil", CONTROL_FLAG, RTF_BRDRNIL, 0 }, + { "brdrnone", CONTROL_FLAG, RTF_BRDRNONE, 0 }, + { "brdroutset", CONTROL_FLAG, RTF_BRDROUTSET, 0 }, + { "brdrr", CONTROL_FLAG, RTF_BRDRR, 0 }, + { "brdrs", CONTROL_FLAG, RTF_BRDRS, 0 }, + { "brdrsh", CONTROL_FLAG, RTF_BRDRSH, 0 }, + { "brdrt", CONTROL_FLAG, RTF_BRDRT, 0 }, + { "brdrtbl", CONTROL_FLAG, RTF_BRDRTBL, 0 }, + { "brdrth", CONTROL_FLAG, RTF_BRDRTH, 0 }, + { "brdrthtnlg", CONTROL_FLAG, RTF_BRDRTHTNLG, 0 }, + { "brdrthtnmg", CONTROL_FLAG, RTF_BRDRTHTNMG, 0 }, + { "brdrthtnsg", CONTROL_FLAG, RTF_BRDRTHTNSG, 0 }, + { "brdrtnthlg", CONTROL_FLAG, RTF_BRDRTNTHLG, 0 }, + { "brdrtnthmg", CONTROL_FLAG, RTF_BRDRTNTHMG, 0 }, + { "brdrtnthsg", CONTROL_FLAG, RTF_BRDRTNTHSG, 0 }, + { "brdrtnthtnlg", CONTROL_FLAG, RTF_BRDRTNTHTNLG, 0 }, + { "brdrtnthtnmg", CONTROL_FLAG, RTF_BRDRTNTHTNMG, 0 }, + { "brdrtnthtnsg", CONTROL_FLAG, RTF_BRDRTNTHTNSG, 0 }, + { "brdrtriple", CONTROL_FLAG, RTF_BRDRTRIPLE, 0 }, + { "brdrw", CONTROL_VALUE, RTF_BRDRW, 0 }, + { "brdrwavy", CONTROL_FLAG, RTF_BRDRWAVY, 0 }, + { "brdrwavydb", CONTROL_FLAG, RTF_BRDRWAVYDB, 0 }, + { "brkfrm", CONTROL_FLAG, RTF_BRKFRM, 0 }, + { "brsp", CONTROL_VALUE, RTF_BRSP, 0 }, + { "bullet", CONTROL_SYMBOL, RTF_BULLET, 0 }, + { "buptim", CONTROL_DESTINATION, RTF_BUPTIM, 0 }, + { "bxe", CONTROL_FLAG, RTF_BXE, 0 }, + { "caccentfive", CONTROL_FLAG, RTF_CACCENTFIVE, 0 }, + { "caccentfour", CONTROL_FLAG, RTF_CACCENTFOUR, 0 }, + { "caccentone", CONTROL_FLAG, RTF_CACCENTONE, 0 }, + { "caccentsix", CONTROL_FLAG, RTF_CACCENTSIX, 0 }, + { "caccentthree", CONTROL_FLAG, RTF_CACCENTTHREE, 0 }, + { "caccenttwo", CONTROL_FLAG, RTF_CACCENTTWO, 0 }, + { "cachedcolbal", CONTROL_FLAG, RTF_CACHEDCOLBAL, 0 }, + { "caps", CONTROL_TOGGLE, RTF_CAPS, 1 }, + { "category", CONTROL_DESTINATION, RTF_CATEGORY, 0 }, + { "cb", CONTROL_VALUE, RTF_CB, 0 }, + { "cbackgroundone", CONTROL_FLAG, RTF_CBACKGROUNDONE, 0 }, + { "cbackgroundtwo", CONTROL_FLAG, RTF_CBACKGROUNDTWO, 0 }, + { "cbpat", CONTROL_VALUE, RTF_CBPAT, 0 }, + { "cchs", CONTROL_VALUE, RTF_CCHS, 0 }, + { "cell", CONTROL_SYMBOL, RTF_CELL, 0 }, + { "cellx", CONTROL_VALUE, RTF_CELLX, 0 }, + { "cf", CONTROL_VALUE, RTF_CF, 0 }, + { "cfollowedhyperlink", CONTROL_FLAG, RTF_CFOLLOWEDHYPERLINK, 0 }, + { "cfpat", CONTROL_VALUE, RTF_CFPAT, 0 }, + { "cgrid", CONTROL_VALUE, RTF_CGRID, 0 }, + { "charrsid", CONTROL_VALUE, RTF_CHARRSID, 0 }, + { "charscalex", CONTROL_VALUE, RTF_CHARSCALEX, 100 }, + { "chatn", CONTROL_SYMBOL, RTF_CHATN, 0 }, + { "chbgbdiag", CONTROL_FLAG, RTF_CHBGBDIAG, 0 }, + { "chbgcross", CONTROL_FLAG, RTF_CHBGCROSS, 0 }, + { "chbgdcross", CONTROL_FLAG, RTF_CHBGDCROSS, 0 }, + { "chbgdkbdiag", CONTROL_FLAG, RTF_CHBGDKBDIAG, 0 }, + { "chbgdkcross", CONTROL_FLAG, RTF_CHBGDKCROSS, 0 }, + { "chbgdkdcross", CONTROL_FLAG, RTF_CHBGDKDCROSS, 0 }, + { "chbgdkfdiag", CONTROL_FLAG, RTF_CHBGDKFDIAG, 0 }, + { "chbgdkhoriz", CONTROL_FLAG, RTF_CHBGDKHORIZ, 0 }, + { "chbgdkvert", CONTROL_FLAG, RTF_CHBGDKVERT, 0 }, + { "chbgfdiag", CONTROL_FLAG, RTF_CHBGFDIAG, 0 }, + { "chbghoriz", CONTROL_FLAG, RTF_CHBGHORIZ, 0 }, + { "chbgvert", CONTROL_FLAG, RTF_CHBGVERT, 0 }, + { "chbrdr", CONTROL_FLAG, RTF_CHBRDR, 0 }, + { "chcbpat", CONTROL_VALUE, RTF_CHCBPAT, 0 }, + { "chcfpat", CONTROL_VALUE, RTF_CHCFPAT, 0 }, + { "chdate", CONTROL_SYMBOL, RTF_CHDATE, 0 }, + { "chdpa", CONTROL_SYMBOL, RTF_CHDPA, 0 }, + { "chdpl", CONTROL_SYMBOL, RTF_CHDPL, 0 }, + { "chftn", CONTROL_SYMBOL, RTF_CHFTN, 0 }, + { "chftnsep", CONTROL_SYMBOL, RTF_CHFTNSEP, 0 }, + { "chftnsepc", CONTROL_SYMBOL, RTF_CHFTNSEPC, 0 }, + { "chpgn", CONTROL_SYMBOL, RTF_CHPGN, 0 }, + { "chhres", CONTROL_VALUE, RTF_CHHRES, 0 }, + { "chshdng", CONTROL_VALUE, RTF_CHSHDNG, 0 }, + { "chtime", CONTROL_SYMBOL, RTF_CHTIME, 0 }, + { "chyperlink", CONTROL_FLAG, RTF_CHYPERLINK, 0 }, + { "clbgbdiag", CONTROL_FLAG, RTF_CLBGBDIAG, 0 }, + { "clbgcross", CONTROL_FLAG, RTF_CLBGCROSS, 0 }, + { "clbgdcross", CONTROL_FLAG, RTF_CLBGDCROSS, 0 }, + { "clbgdkbdiag", CONTROL_FLAG, RTF_CLBGDKBDIAG, 0 }, + { "clbgdkcross", CONTROL_FLAG, RTF_CLBGDKCROSS, 0 }, + { "clbgdkdcross", CONTROL_FLAG, RTF_CLBGDKDCROSS, 0 }, + { "clbgdkfdiag", CONTROL_FLAG, RTF_CLBGDKFDIAG, 0 }, + { "clbgdkhor", CONTROL_FLAG, RTF_CLBGDKHOR, 0 }, + { "clbgdkvert", CONTROL_FLAG, RTF_CLBGDKVERT, 0 }, + { "clbgfdiag", CONTROL_FLAG, RTF_CLBGFDIAG, 0 }, + { "clbghoriz", CONTROL_FLAG, RTF_CLBGHORIZ, 0 }, + { "clbgvert", CONTROL_FLAG, RTF_CLBGVERT, 0 }, + { "clbrdrb", CONTROL_FLAG, RTF_CLBRDRB, 0 }, + { "clbrdrl", CONTROL_FLAG, RTF_CLBRDRL, 0 }, + { "clbrdrr", CONTROL_FLAG, RTF_CLBRDRR, 0 }, + { "clbrdrt", CONTROL_FLAG, RTF_CLBRDRT, 0 }, + { "clcbpat", CONTROL_VALUE, RTF_CLCBPAT, 0 }, + { "clcbpatraw", CONTROL_VALUE, RTF_CLCBPATRAW, 0 }, + { "clcfpat", CONTROL_VALUE, RTF_CLCFPAT, 0 }, + { "clcfpatraw", CONTROL_VALUE, RTF_CLCFPATRAW, 0 }, + { "cldel", CONTROL_FLAG, RTF_CLDEL, 0 }, + { "cldelauth", CONTROL_VALUE, RTF_CLDELAUTH, 0 }, + { "cldeldttm", CONTROL_VALUE, RTF_CLDELDTTM, 0 }, + { "cldgll", CONTROL_FLAG, RTF_CLDGLL, 0 }, + { "cldglu", CONTROL_FLAG, RTF_CLDGLU, 0 }, + { "clFitText", CONTROL_FLAG, RTF_CLFITTEXT, 0 }, + { "clftsWidth", CONTROL_VALUE, RTF_CLFTSWIDTH, 0 }, + { "clhidemark", CONTROL_FLAG, RTF_CLHIDEMARK, 0 }, + { "clins", CONTROL_FLAG, RTF_CLINS, 0 }, + { "clinsauth", CONTROL_VALUE, RTF_CLINSAUTH, 0 }, + { "clinsdttm", CONTROL_VALUE, RTF_CLINSDTTM, 0 }, + { "clmgf", CONTROL_FLAG, RTF_CLMGF, 0 }, + { "clmrg", CONTROL_FLAG, RTF_CLMRG, 0 }, + { "clmrgd", CONTROL_FLAG, RTF_CLMRGD, 0 }, + { "clmrgdauth", CONTROL_VALUE, RTF_CLMRGDAUTH, 0 }, + { "clmrgddttm", CONTROL_VALUE, RTF_CLMRGDDTTM, 0 }, + { "clmrgdr", CONTROL_FLAG, RTF_CLMRGDR, 0 }, + { "clNoWrap", CONTROL_FLAG, RTF_CLNOWRAP, 0 }, + { "clpadb", CONTROL_VALUE, RTF_CLPADB, 0 }, + { "clpadfb", CONTROL_VALUE, RTF_CLPADFB, 0 }, + { "clpadfl", CONTROL_VALUE, RTF_CLPADFL, 0 }, + { "clpadfr", CONTROL_VALUE, RTF_CLPADFR, 0 }, + { "clpadft", CONTROL_VALUE, RTF_CLPADFT, 0 }, + { "clpadl", CONTROL_VALUE, RTF_CLPADL, 0 }, + { "clpadr", CONTROL_VALUE, RTF_CLPADR, 0 }, + { "clpadt", CONTROL_VALUE, RTF_CLPADT, 0 }, + { "clspb", CONTROL_VALUE, RTF_CLSPB, 0 }, + { "clspfb", CONTROL_VALUE, RTF_CLSPFB, 0 }, + { "clspfl", CONTROL_VALUE, RTF_CLSPFL, 0 }, + { "clspfr", CONTROL_VALUE, RTF_CLSPFR, 0 }, + { "clspft", CONTROL_VALUE, RTF_CLSPFT, 0 }, + { "clspl", CONTROL_VALUE, RTF_CLSPL, 0 }, + { "clspr", CONTROL_VALUE, RTF_CLSPR, 0 }, + { "clspt", CONTROL_VALUE, RTF_CLSPT, 0 }, + { "clshdng", CONTROL_VALUE, RTF_CLSHDNG, 0 }, + { "clshdngraw", CONTROL_VALUE, RTF_CLSHDNGRAW, 0 }, + { "clshdrawnil", CONTROL_FLAG, RTF_CLSHDRAWNIL, 0 }, + { "clsplit", CONTROL_FLAG, RTF_CLSPLIT, 0 }, + { "clsplitr", CONTROL_FLAG, RTF_CLSPLITR, 0 }, + { "cltxbtlr", CONTROL_FLAG, RTF_CLTXBTLR, 0 }, + { "cltxlrtb", CONTROL_FLAG, RTF_CLTXLRTB, 0 }, + { "cltxlrtbv", CONTROL_FLAG, RTF_CLTXLRTBV, 0 }, + { "cltxtbrl", CONTROL_FLAG, RTF_CLTXTBRL, 0 }, + { "cltxtbrlv", CONTROL_FLAG, RTF_CLTXTBRLV, 0 }, + { "clvertalb", CONTROL_FLAG, RTF_CLVERTALB, 0 }, + { "clvertalc", CONTROL_FLAG, RTF_CLVERTALC, 0 }, + { "clvertalt", CONTROL_FLAG, RTF_CLVERTALT, 0 }, + { "clvmgf", CONTROL_FLAG, RTF_CLVMGF, 0 }, + { "clvmrg", CONTROL_FLAG, RTF_CLVMRG, 0 }, + { "clwWidth", CONTROL_VALUE, RTF_CLWWIDTH, 0 }, + { "cmaindarkone", CONTROL_FLAG, RTF_CMAINDARKONE, 0 }, + { "cmaindarktwo", CONTROL_FLAG, RTF_CMAINDARKTWO, 0 }, + { "cmainlightone", CONTROL_FLAG, RTF_CMAINLIGHTONE, 0 }, + { "cmainlighttwo", CONTROL_FLAG, RTF_CMAINLIGHTTWO, 0 }, + { "collapsed", CONTROL_FLAG, RTF_COLLAPSED, 0 }, + { "colno", CONTROL_VALUE, RTF_COLNO, 0 }, + { "colorschememapping", CONTROL_DESTINATION, RTF_COLORSCHEMEMAPPING, 0 }, + { "colortbl", CONTROL_DESTINATION, RTF_COLORTBL, 0 }, + { "cols", CONTROL_VALUE, RTF_COLS, 1 }, + { "colsr", CONTROL_VALUE, RTF_COLSR, 0 }, + { "colsx", CONTROL_VALUE, RTF_COLSX, 720 }, + { "column", CONTROL_SYMBOL, RTF_COLUMN, 0 }, + { "colw", CONTROL_VALUE, RTF_COLW, 0 }, + { "comment", CONTROL_DESTINATION, RTF_COMMENT, 0 }, + { "company", CONTROL_DESTINATION, RTF_COMPANY, 0 }, + { "contextualspace", CONTROL_FLAG, RTF_CONTEXTUALSPACE, 0 }, + { "cpg", CONTROL_VALUE, RTF_CPG, 0 }, + { "crauth", CONTROL_VALUE, RTF_CRAUTH, 0 }, + { "crdate", CONTROL_VALUE, RTF_CRDATE, 0 }, + { "creatim", CONTROL_DESTINATION, RTF_CREATIM, 0 }, + { "cs", CONTROL_VALUE, RTF_CS, 0 }, + { "cshade", CONTROL_VALUE, RTF_CSHADE, 0 }, + { "ctextone", CONTROL_FLAG, RTF_CTEXTONE, 0 }, + { "ctexttwo", CONTROL_FLAG, RTF_CTEXTTWO, 0 }, + { "ctint", CONTROL_VALUE, RTF_CTINT, 0 }, + { "ctrl", CONTROL_FLAG, RTF_CTRL, 0 }, + { "cts", CONTROL_VALUE, RTF_CTS, 0 }, + { "cufi", CONTROL_VALUE, RTF_CUFI, 0 }, + { "culi", CONTROL_VALUE, RTF_CULI, 0 }, + { "curi", CONTROL_VALUE, RTF_CURI, 0 }, + { "cvmme", CONTROL_FLAG, RTF_CVMME, 0 }, + { "datafield", CONTROL_DESTINATION, RTF_DATAFIELD, 0 }, + { "datastore", CONTROL_DESTINATION, RTF_DATASTORE, 0 }, + { "date", CONTROL_FLAG, RTF_DATE, 0 }, + { "dbch", CONTROL_FLAG, RTF_DBCH, 0 }, + { "defchp", CONTROL_DESTINATION, RTF_DEFCHP, 0 }, + { "deff", CONTROL_VALUE, RTF_DEFF, 0 }, + { "defformat", CONTROL_FLAG, RTF_DEFFORMAT, 0 }, + { "deflang", CONTROL_VALUE, RTF_DEFLANG, 0 }, + { "deflangfe", CONTROL_VALUE, RTF_DEFLANGFE, 0 }, + { "defpap", CONTROL_DESTINATION, RTF_DEFPAP, 0 }, + { "defshp", CONTROL_FLAG, RTF_DEFSHP, 0 }, + { "deftab", CONTROL_VALUE, RTF_DEFTAB, 720 }, + { "deleted", CONTROL_TOGGLE, RTF_DELETED, 1 }, + { "delrsid", CONTROL_VALUE, RTF_DELRSID, 0 }, + { "dfrauth", CONTROL_VALUE, RTF_DFRAUTH, 0 }, + { "dfrdate", CONTROL_VALUE, RTF_DFRDATE, 0 }, + { "dfrmtxtx", CONTROL_VALUE, RTF_DFRMTXTX, 0 }, + { "dfrmtxty", CONTROL_VALUE, RTF_DFRMTXTY, 0 }, + { "dfrstart", CONTROL_VALUE, RTF_DFRSTART, 0 }, + { "dfrstop", CONTROL_VALUE, RTF_DFRSTOP, 0 }, + { "dfrxst", CONTROL_VALUE, RTF_DFRXST, 0 }, + { "dghorigin", CONTROL_VALUE, RTF_DGHORIGIN, 1701 }, + { "dghshow", CONTROL_VALUE, RTF_DGHSHOW, 3 }, + { "dghspace", CONTROL_VALUE, RTF_DGHSPACE, 120 }, + { "dgmargin", CONTROL_FLAG, RTF_DGMARGIN, 0 }, + { "dgsnap", CONTROL_FLAG, RTF_DGSNAP, 0 }, + { "dgvorigin", CONTROL_VALUE, RTF_DGVORIGIN, 1984 }, + { "dgvshow", CONTROL_VALUE, RTF_DGVSHOW, 0 }, + { "dgvspace", CONTROL_VALUE, RTF_DGVSPACE, 120 }, + { "dibitmap", CONTROL_VALUE, RTF_DIBITMAP, 0 }, + { "disabled", CONTROL_TOGGLE, RTF_DISABLED, 1 }, + { "dn", CONTROL_VALUE, RTF_DN, 6 }, + { "dntblnsbdb", CONTROL_FLAG, RTF_DNTBLNSBDB, 0 }, + { "do", CONTROL_DESTINATION, RTF_DO, 0 }, + { "dobxcolumn", CONTROL_FLAG, RTF_DOBXCOLUMN, 0 }, + { "dobxmargin", CONTROL_FLAG, RTF_DOBXMARGIN, 0 }, + { "dobxpage", CONTROL_FLAG, RTF_DOBXPAGE, 0 }, + { "dobymargin", CONTROL_FLAG, RTF_DOBYMARGIN, 0 }, + { "dobypage", CONTROL_FLAG, RTF_DOBYPAGE, 0 }, + { "dobypara", CONTROL_FLAG, RTF_DOBYPARA, 0 }, + { "doccomm", CONTROL_DESTINATION, RTF_DOCCOMM, 0 }, + { "doctemp", CONTROL_FLAG, RTF_DOCTEMP, 0 }, + { "doctype", CONTROL_VALUE, RTF_DOCTYPE, 0 }, + { "docvar", CONTROL_DESTINATION, RTF_DOCVAR, 0 }, + { "dodhgt", CONTROL_VALUE, RTF_DODHGT, 0 }, + { "dolock", CONTROL_FLAG, RTF_DOLOCK, 0 }, + { "donotembedlingdata", CONTROL_VALUE, RTF_DONOTEMBEDLINGDATA, 0 }, + { "donotembedsysfont", CONTROL_VALUE, RTF_DONOTEMBEDSYSFONT, 0 }, + { "donotshowcomments", CONTROL_FLAG, RTF_DONOTSHOWCOMMENTS, 0 }, + { "donotshowinsdel", CONTROL_FLAG, RTF_DONOTSHOWINSDEL, 0 }, + { "donotshowmarkup", CONTROL_FLAG, RTF_DONOTSHOWMARKUP, 0 }, + { "donotshowprops", CONTROL_FLAG, RTF_DONOTSHOWPROPS, 0 }, + { "dpaendhol", CONTROL_FLAG, RTF_DPAENDHOL, 0 }, + { "dpaendl", CONTROL_VALUE, RTF_DPAENDL, 0 }, + { "dpaendsol", CONTROL_FLAG, RTF_DPAENDSOL, 0 }, + { "dpaendw", CONTROL_VALUE, RTF_DPAENDW, 0 }, + { "dparc", CONTROL_FLAG, RTF_DPARC, 0 }, + { "dparcflipx", CONTROL_FLAG, RTF_DPARCFLIPX, 0 }, + { "dparcflipy", CONTROL_FLAG, RTF_DPARCFLIPY, 0 }, + { "dpastarthol", CONTROL_FLAG, RTF_DPASTARTHOL, 0 }, + { "dpastartl", CONTROL_VALUE, RTF_DPASTARTL, 0 }, + { "dpastartsol", CONTROL_FLAG, RTF_DPASTARTSOL, 0 }, + { "dpastartw", CONTROL_VALUE, RTF_DPASTARTW, 0 }, + { "dpcallout", CONTROL_FLAG, RTF_DPCALLOUT, 0 }, + { "dpcoa", CONTROL_VALUE, RTF_DPCOA, 0 }, + { "dpcoaccent", CONTROL_FLAG, RTF_DPCOACCENT, 0 }, + { "dpcobestfit", CONTROL_FLAG, RTF_DPCOBESTFIT, 0 }, + { "dpcoborder", CONTROL_FLAG, RTF_DPCOBORDER, 0 }, + { "dpcodabs", CONTROL_FLAG, RTF_DPCODABS, 0 }, + { "dpcodbottom", CONTROL_FLAG, RTF_DPCODBOTTOM, 0 }, + { "dpcodcenter", CONTROL_FLAG, RTF_DPCODCENTER, 0 }, + { "dpcodescent", CONTROL_VALUE, RTF_DPCODESCENT, 0 }, + { "dpcodtop", CONTROL_FLAG, RTF_DPCODTOP, 0 }, + { "dpcolength", CONTROL_VALUE, RTF_DPCOLENGTH, 0 }, + { "dpcominusx", CONTROL_FLAG, RTF_DPCOMINUSX, 0 }, + { "dpcominusy", CONTROL_FLAG, RTF_DPCOMINUSY, 0 }, + { "dpcooffset", CONTROL_VALUE, RTF_DPCOOFFSET, 0 }, + { "dpcosmarta", CONTROL_FLAG, RTF_DPCOSMARTA, 0 }, + { "dpcotdouble", CONTROL_FLAG, RTF_DPCOTDOUBLE, 0 }, + { "dpcotright", CONTROL_FLAG, RTF_DPCOTRIGHT, 0 }, + { "dpcotsingle", CONTROL_FLAG, RTF_DPCOTSINGLE, 0 }, + { "dpcottriple", CONTROL_FLAG, RTF_DPCOTTRIPLE, 0 }, + { "dpcount", CONTROL_VALUE, RTF_DPCOUNT, 0 }, + { "dpellipse", CONTROL_FLAG, RTF_DPELLIPSE, 0 }, + { "dpendgroup", CONTROL_FLAG, RTF_DPENDGROUP, 0 }, + { "dpfillbgcb", CONTROL_VALUE, RTF_DPFILLBGCB, 0 }, + { "dpfillbgcg", CONTROL_VALUE, RTF_DPFILLBGCG, 0 }, + { "dpfillbgcr", CONTROL_VALUE, RTF_DPFILLBGCR, 0 }, + { "dpfillbggray", CONTROL_VALUE, RTF_DPFILLBGGRAY, 0 }, + { "dpfillbgpal", CONTROL_FLAG, RTF_DPFILLBGPAL, 0 }, + { "dpfillfgcb", CONTROL_VALUE, RTF_DPFILLFGCB, 0 }, + { "dpfillfgcg", CONTROL_VALUE, RTF_DPFILLFGCG, 0 }, + { "dpfillfgcr", CONTROL_VALUE, RTF_DPFILLFGCR, 0 }, + { "dpfillfggray", CONTROL_VALUE, RTF_DPFILLFGGRAY, 0 }, + { "dpfillfgpal", CONTROL_FLAG, RTF_DPFILLFGPAL, 0 }, + { "dpfillpat", CONTROL_VALUE, RTF_DPFILLPAT, 0 }, + { "dpgroup", CONTROL_FLAG, RTF_DPGROUP, 0 }, + { "dpline", CONTROL_FLAG, RTF_DPLINE, 0 }, + { "dplinecob", CONTROL_VALUE, RTF_DPLINECOB, 0 }, + { "dplinecog", CONTROL_VALUE, RTF_DPLINECOG, 0 }, + { "dplinecor", CONTROL_VALUE, RTF_DPLINECOR, 0 }, + { "dplinedado", CONTROL_FLAG, RTF_DPLINEDADO, 0 }, + { "dplinedadodo", CONTROL_FLAG, RTF_DPLINEDADODO, 0 }, + { "dplinedash", CONTROL_FLAG, RTF_DPLINEDASH, 0 }, + { "dplinedot", CONTROL_FLAG, RTF_DPLINEDOT, 0 }, + { "dplinegray", CONTROL_VALUE, RTF_DPLINEGRAY, 0 }, + { "dplinehollow", CONTROL_FLAG, RTF_DPLINEHOLLOW, 0 }, + { "dplinepal", CONTROL_FLAG, RTF_DPLINEPAL, 0 }, + { "dplinesolid", CONTROL_FLAG, RTF_DPLINESOLID, 0 }, + { "dplinew", CONTROL_VALUE, RTF_DPLINEW, 0 }, + { "dppolycount", CONTROL_VALUE, RTF_DPPOLYCOUNT, 0 }, + { "dppolygon", CONTROL_FLAG, RTF_DPPOLYGON, 0 }, + { "dppolyline", CONTROL_FLAG, RTF_DPPOLYLINE, 0 }, + { "dpptx", CONTROL_VALUE, RTF_DPPTX, 0 }, + { "dppty", CONTROL_VALUE, RTF_DPPTY, 0 }, + { "dprect", CONTROL_FLAG, RTF_DPRECT, 0 }, + { "dproundr", CONTROL_FLAG, RTF_DPROUNDR, 0 }, + { "dpshadow", CONTROL_FLAG, RTF_DPSHADOW, 0 }, + { "dpshadx", CONTROL_VALUE, RTF_DPSHADX, 0 }, + { "dpshady", CONTROL_VALUE, RTF_DPSHADY, 0 }, + { "dptxbtlr", CONTROL_FLAG, RTF_DPTXBTLR, 0 }, + { "dptxbx", CONTROL_FLAG, RTF_DPTXBX, 0 }, + { "dptxbxmar", CONTROL_VALUE, RTF_DPTXBXMAR, 0 }, + { "dptxbxtext", CONTROL_DESTINATION, RTF_DPTXBXTEXT, 0 }, + { "dptxlrtb", CONTROL_FLAG, RTF_DPTXLRTB, 0 }, + { "dptxlrtbv", CONTROL_FLAG, RTF_DPTXLRTBV, 0 }, + { "dptxtbrl", CONTROL_FLAG, RTF_DPTXTBRL, 0 }, + { "dptxtbrlv", CONTROL_FLAG, RTF_DPTXTBRLV, 0 }, + { "dpx", CONTROL_VALUE, RTF_DPX, 0 }, + { "dpxsize", CONTROL_VALUE, RTF_DPXSIZE, 0 }, + { "dpy", CONTROL_VALUE, RTF_DPY, 0 }, + { "dpysize", CONTROL_VALUE, RTF_DPYSIZE, 0 }, + { "dropcapli", CONTROL_VALUE, RTF_DROPCAPLI, 0 }, + { "dropcapt", CONTROL_VALUE, RTF_DROPCAPT, 0 }, + { "ds", CONTROL_VALUE, RTF_DS, 0 }, + { "dxfrtext", CONTROL_VALUE, RTF_DXFRTEXT, 0 }, + { "dy", CONTROL_VALUE, RTF_DY, 0 }, + { "ebcend", CONTROL_DESTINATION, RTF_EBCEND, 0 }, + { "ebcstart", CONTROL_DESTINATION, RTF_EBCSTART, 0 }, + { "edmins", CONTROL_VALUE, RTF_EDMINS, 0 }, + { "embo", CONTROL_TOGGLE, RTF_EMBO, 1 }, + { "emdash", CONTROL_SYMBOL, RTF_EMDASH, 0 }, + { "emfblip", CONTROL_FLAG, RTF_EMFBLIP, 0 }, + { "emspace", CONTROL_SYMBOL, RTF_EMSPACE, 0 }, + { "endash", CONTROL_SYMBOL, RTF_ENDASH, 0 }, + { "enddoc", CONTROL_FLAG, RTF_ENDDOC, 0 }, + { "endnhere", CONTROL_FLAG, RTF_ENDNHERE, 0 }, + { "endnotes", CONTROL_FLAG, RTF_ENDNOTES, 0 }, + { "enforceprot", CONTROL_VALUE, RTF_ENFORCEPROT, 0 }, + { "enspace", CONTROL_SYMBOL, RTF_ENSPACE, 0 }, + { "expnd", CONTROL_VALUE, RTF_EXPND, 0 }, + { "expndtw", CONTROL_VALUE, RTF_EXPNDTW, 0 }, + { "expshrtn", CONTROL_FLAG, RTF_EXPSHRTN, 0 }, + { "f", CONTROL_VALUE, RTF_F, 0 }, + { "faauto", CONTROL_FLAG, RTF_FAAUTO, 0 }, + { "facenter", CONTROL_FLAG, RTF_FACENTER, 0 }, + { "facingp", CONTROL_TOGGLE, RTF_FACINGP, 1 }, + { "factoidname", CONTROL_DESTINATION, RTF_FACTOIDNAME, 0 }, + { "fafixed", CONTROL_FLAG, RTF_FAFIXED, 0 }, + { "fahang", CONTROL_FLAG, RTF_FAHANG, 0 }, + { "falt", CONTROL_DESTINATION, RTF_FALT, 0 }, + { "faroman", CONTROL_FLAG, RTF_FAROMAN, 0 }, + { "favar", CONTROL_FLAG, RTF_FAVAR, 0 }, + { "fbias", CONTROL_VALUE, RTF_FBIAS, 0 }, + { "fbidi", CONTROL_FLAG, RTF_FBIDI, 0 }, + { "fbidis", CONTROL_FLAG, RTF_FBIDIS, 0 }, + { "fbimajor", CONTROL_FLAG, RTF_FBIMAJOR, 0 }, + { "fbiminor", CONTROL_FLAG, RTF_FBIMINOR, 0 }, + { "fchars", CONTROL_DESTINATION, RTF_FCHARS, 0 }, + { "fcharset", CONTROL_VALUE, RTF_FCHARSET, 0 }, + { "fcs", CONTROL_VALUE, RTF_FCS, 0 }, + { "fdbmajor", CONTROL_FLAG, RTF_FDBMAJOR, 0 }, + { "fdbminor", CONTROL_FLAG, RTF_FDBMINOR, 0 }, + { "fdecor", CONTROL_FLAG, RTF_FDECOR, 0 }, + { "felnbrelev", CONTROL_FLAG, RTF_FELNBRELEV, 0 }, + { "fet", CONTROL_VALUE, RTF_FET, 0 }, + { "fetch", CONTROL_FLAG, RTF_FETCH, 0 }, + { "ffdefres", CONTROL_VALUE, RTF_FFDEFRES, 0 }, + { "ffdeftext", CONTROL_DESTINATION, RTF_FFDEFTEXT, 0 }, + { "ffentrymcr", CONTROL_DESTINATION, RTF_FFENTRYMCR, 0 }, + { "ffexitmcr", CONTROL_DESTINATION, RTF_FFEXITMCR, 0 }, + { "ffformat", CONTROL_DESTINATION, RTF_FFFORMAT, 0 }, + { "ffhaslistbox", CONTROL_VALUE, RTF_FFHASLISTBOX, 0 }, + { "ffhelptext", CONTROL_DESTINATION, RTF_FFHELPTEXT, 0 }, + { "ffhps", CONTROL_VALUE, RTF_FFHPS, 0 }, + { "ffl", CONTROL_DESTINATION, RTF_FFL, 0 }, + { "ffmaxlen", CONTROL_VALUE, RTF_FFMAXLEN, 0 }, + { "ffname", CONTROL_DESTINATION, RTF_FFNAME, 0 }, + { "ffownhelp", CONTROL_VALUE, RTF_FFOWNHELP, 0 }, + { "ffownstat", CONTROL_VALUE, RTF_FFOWNSTAT, 0 }, + { "ffprot", CONTROL_VALUE, RTF_FFPROT, 0 }, + { "ffrecalc", CONTROL_VALUE, RTF_FFRECALC, 0 }, + { "ffres", CONTROL_VALUE, RTF_FFRES, 0 }, + { "ffsize", CONTROL_VALUE, RTF_FFSIZE, 0 }, + { "ffstattext", CONTROL_DESTINATION, RTF_FFSTATTEXT, 0 }, + { "fftype", CONTROL_VALUE, RTF_FFTYPE, 0 }, + { "fftypetxt", CONTROL_VALUE, RTF_FFTYPETXT, 0 }, + { "fhimajor", CONTROL_FLAG, RTF_FHIMAJOR, 0 }, + { "fhiminor", CONTROL_FLAG, RTF_FHIMINOR, 0 }, + { "fi", CONTROL_VALUE, RTF_FI, 0 }, + { "fid", CONTROL_VALUE, RTF_FID, 0 }, + { "field", CONTROL_DESTINATION, RTF_FIELD, 0 }, + { "file", CONTROL_DESTINATION, RTF_FILE, 0 }, + { "filetbl", CONTROL_DESTINATION, RTF_FILETBL, 0 }, + { "fittext", CONTROL_VALUE, RTF_FITTEXT, 0 }, + { "fjgothic", CONTROL_FLAG, RTF_FJGOTHIC, 0 }, + { "fjminchou", CONTROL_FLAG, RTF_FJMINCHOU, 0 }, + { "fldalt", CONTROL_FLAG, RTF_FLDALT, 0 }, + { "flddirty", CONTROL_FLAG, RTF_FLDDIRTY, 0 }, + { "fldedit", CONTROL_FLAG, RTF_FLDEDIT, 0 }, + { "fldinst", CONTROL_DESTINATION, RTF_FLDINST, 0 }, + { "fldlock", CONTROL_FLAG, RTF_FLDLOCK, 0 }, + { "fldpriv", CONTROL_FLAG, RTF_FLDPRIV, 0 }, + { "fldrslt", CONTROL_DESTINATION, RTF_FLDRSLT, 0 }, + { "fldtype", CONTROL_DESTINATION, RTF_FLDTYPE, 0 }, + { "flomajor", CONTROL_FLAG, RTF_FLOMAJOR, 0 }, + { "flominor", CONTROL_FLAG, RTF_FLOMINOR, 0 }, + { "fmodern", CONTROL_FLAG, RTF_FMODERN, 0 }, + { "fn", CONTROL_VALUE, RTF_FN, 0 }, + { "fname", CONTROL_DESTINATION, RTF_FNAME, 0 }, + { "fnetwork", CONTROL_FLAG, RTF_FNETWORK, 0 }, + { "fnil", CONTROL_FLAG, RTF_FNIL, 0 }, + { "fnonfilesys", CONTROL_FLAG, RTF_FNONFILESYS, 0 }, + { "fontemb", CONTROL_DESTINATION, RTF_FONTEMB, 0 }, + { "fontfile", CONTROL_DESTINATION, RTF_FONTFILE, 0 }, + { "fonttbl", CONTROL_DESTINATION, RTF_FONTTBL, 0 }, + { "footer", CONTROL_DESTINATION, RTF_FOOTER, 0 }, + { "footerf", CONTROL_DESTINATION, RTF_FOOTERF, 0 }, + { "footerl", CONTROL_DESTINATION, RTF_FOOTERL, 0 }, + { "footerr", CONTROL_DESTINATION, RTF_FOOTERR, 0 }, + { "footery", CONTROL_VALUE, RTF_FOOTERY, 720 }, + { "footnote", CONTROL_DESTINATION, RTF_FOOTNOTE, 0 }, + { "forceupgrade", CONTROL_FLAG, RTF_FORCEUPGRADE, 0 }, + { "formdisp", CONTROL_FLAG, RTF_FORMDISP, 0 }, + { "formfield", CONTROL_DESTINATION, RTF_FORMFIELD, 0 }, + { "formprot", CONTROL_FLAG, RTF_FORMPROT, 0 }, + { "formshade", CONTROL_FLAG, RTF_FORMSHADE, 0 }, + { "fosnum", CONTROL_VALUE, RTF_FOSNUM, 0 }, + { "fprq", CONTROL_VALUE, RTF_FPRQ, 0 }, + { "fracwidth", CONTROL_FLAG, RTF_FRACWIDTH, 0 }, + { "frelative", CONTROL_VALUE, RTF_FRELATIVE, 0 }, + { "frmtxbtlr", CONTROL_FLAG, RTF_FRMTXBTLR, 0 }, + { "frmtxlrtb", CONTROL_FLAG, RTF_FRMTXLRTB, 0 }, + { "frmtxlrtbv", CONTROL_FLAG, RTF_FRMTXLRTBV, 0 }, + { "frmtxtbrl", CONTROL_FLAG, RTF_FRMTXTBRL, 0 }, + { "frmtxtbrlv", CONTROL_FLAG, RTF_FRMTXTBRLV, 0 }, + { "froman", CONTROL_FLAG, RTF_FROMAN, 0 }, + { "fromhtml", CONTROL_VALUE, RTF_FROMHTML, 0 }, + { "fromtext", CONTROL_FLAG, RTF_FROMTEXT, 0 }, + { "fs", CONTROL_VALUE, RTF_FS, 24 }, + { "fscript", CONTROL_FLAG, RTF_FSCRIPT, 0 }, + { "fswiss", CONTROL_FLAG, RTF_FSWISS, 0 }, + { "ftech", CONTROL_FLAG, RTF_FTECH, 0 }, + { "ftnalt", CONTROL_FLAG, RTF_FTNALT, 0 }, + { "ftnbj", CONTROL_FLAG, RTF_FTNBJ, 0 }, + { "ftncn", CONTROL_DESTINATION, RTF_FTNCN, 0 }, + { "ftnil", CONTROL_FLAG, RTF_FTNIL, 0 }, + { "ftnlytwnine", CONTROL_FLAG, RTF_FTNLYTWNINE, 0 }, + { "ftnnalc", CONTROL_FLAG, RTF_FTNNALC, 0 }, + { "ftnnar", CONTROL_FLAG, RTF_FTNNAR, 0 }, + { "ftnnauc", CONTROL_FLAG, RTF_FTNNAUC, 0 }, + { "ftnnchi", CONTROL_FLAG, RTF_FTNNCHI, 0 }, + { "ftnnchosung", CONTROL_FLAG, RTF_FTNNCHOSUNG, 0 }, + { "ftnncnum", CONTROL_FLAG, RTF_FTNNCNUM, 0 }, + { "ftnndbar", CONTROL_FLAG, RTF_FTNNDBAR, 0 }, + { "ftnndbnum", CONTROL_FLAG, RTF_FTNNDBNUM, 0 }, + { "ftnndbnumd", CONTROL_FLAG, RTF_FTNNDBNUMD, 0 }, + { "ftnndbnumk", CONTROL_FLAG, RTF_FTNNDBNUMK, 0 }, + { "ftnndbnumt", CONTROL_FLAG, RTF_FTNNDBNUMT, 0 }, + { "ftnnganada", CONTROL_FLAG, RTF_FTNNGANADA, 0 }, + { "ftnngbnum", CONTROL_FLAG, RTF_FTNNGBNUM, 0 }, + { "ftnngbnumd", CONTROL_FLAG, RTF_FTNNGBNUMD, 0 }, + { "ftnngbnumk", CONTROL_FLAG, RTF_FTNNGBNUMK, 0 }, + { "ftnngbnuml", CONTROL_FLAG, RTF_FTNNGBNUML, 0 }, + { "ftnnrlc", CONTROL_FLAG, RTF_FTNNRLC, 0 }, + { "ftnnruc", CONTROL_FLAG, RTF_FTNNRUC, 0 }, + { "ftnnzodiac", CONTROL_FLAG, RTF_FTNNZODIAC, 0 }, + { "ftnnzodiacd", CONTROL_FLAG, RTF_FTNNZODIACD, 0 }, + { "ftnnzodiacl", CONTROL_FLAG, RTF_FTNNZODIACL, 0 }, + { "ftnrestart", CONTROL_FLAG, RTF_FTNRESTART, 0 }, + { "ftnrstcont", CONTROL_FLAG, RTF_FTNRSTCONT, 0 }, + { "ftnrstpg", CONTROL_FLAG, RTF_FTNRSTPG, 0 }, + { "ftnsep", CONTROL_DESTINATION, RTF_FTNSEP, 0 }, + { "ftnsepc", CONTROL_DESTINATION, RTF_FTNSEPC, 0 }, + { "ftnstart", CONTROL_VALUE, RTF_FTNSTART, 1 }, + { "ftntj", CONTROL_FLAG, RTF_FTNTJ, 0 }, + { "fttruetype", CONTROL_FLAG, RTF_FTTRUETYPE, 0 }, + { "fvaliddos", CONTROL_FLAG, RTF_FVALIDDOS, 0 }, + { "fvalidhpfs", CONTROL_FLAG, RTF_FVALIDHPFS, 0 }, + { "fvalidmac", CONTROL_FLAG, RTF_FVALIDMAC, 0 }, + { "fvalidntfs", CONTROL_FLAG, RTF_FVALIDNTFS, 0 }, + { "g", CONTROL_DESTINATION, RTF_G, 0 }, + { "gcw", CONTROL_VALUE, RTF_GCW, 0 }, + { "generator", CONTROL_DESTINATION, RTF_GENERATOR, 0 }, + { "green", CONTROL_VALUE, RTF_GREEN, 0 }, + { "grfdocevents", CONTROL_VALUE, RTF_GRFDOCEVENTS, 0 }, + { "gridtbl", CONTROL_DESTINATION, RTF_GRIDTBL, 0 }, + { "gutter", CONTROL_VALUE, RTF_GUTTER, 0 }, + { "gutterprl", CONTROL_FLAG, RTF_GUTTERPRL, 0 }, + { "guttersxn", CONTROL_VALUE, RTF_GUTTERSXN, 0 }, + { "header", CONTROL_DESTINATION, RTF_HEADER, 0 }, + { "headerf", CONTROL_DESTINATION, RTF_HEADERF, 0 }, + { "headerl", CONTROL_DESTINATION, RTF_HEADERL, 0 }, + { "headerr", CONTROL_DESTINATION, RTF_HEADERR, 0 }, + { "headery", CONTROL_VALUE, RTF_HEADERY, 720 }, + { "hich", CONTROL_FLAG, RTF_HICH, 0 }, + { "highlight", CONTROL_VALUE, RTF_HIGHLIGHT, 0 }, + { "hl", CONTROL_DESTINATION, RTF_HL, 0 }, + { "hlfr", CONTROL_DESTINATION, RTF_HLFR, 0 }, + { "hlinkbase", CONTROL_DESTINATION, RTF_HLINKBASE, 0 }, + { "hlloc", CONTROL_DESTINATION, RTF_HLLOC, 0 }, + { "hlsrc", CONTROL_DESTINATION, RTF_HLSRC, 0 }, + { "horzdoc", CONTROL_FLAG, RTF_HORZDOC, 0 }, + { "horzsect", CONTROL_FLAG, RTF_HORZSECT, 0 }, + { "horzvert", CONTROL_VALUE, RTF_HORZVERT, 0 }, + { "hr", CONTROL_VALUE, RTF_HR, 0 }, + { "hres", CONTROL_VALUE, RTF_HRES, 0 }, + { "hrule", CONTROL_FLAG, RTF_HRULE, 0 }, + { "hsv", CONTROL_DESTINATION, RTF_HSV, 0 }, + { "htmautsp", CONTROL_FLAG, RTF_HTMAUTSP, 0 }, + { "htmlbase", CONTROL_FLAG, RTF_HTMLBASE, 0 }, + { "htmlrtf", CONTROL_TOGGLE, RTF_HTMLRTF, 1 }, + { "htmltag", CONTROL_DESTINATION, RTF_HTMLTAG, 0 }, + { "hwelev", CONTROL_FLAG, RTF_HWELEV, 0 }, + { "hyphauto", CONTROL_TOGGLE, RTF_HYPHAUTO, 1 }, + { "hyphcaps", CONTROL_TOGGLE, RTF_HYPHCAPS, 1 }, + { "hyphconsec", CONTROL_VALUE, RTF_HYPHCONSEC, 0 }, + { "hyphhotz", CONTROL_VALUE, RTF_HYPHHOTZ, 0 }, + { "hyphpar", CONTROL_TOGGLE, RTF_HYPHPAR, 1 }, + { "i", CONTROL_TOGGLE, RTF_I, 1 }, + { "id", CONTROL_VALUE, RTF_ID, 0 }, + { "ignoremixedcontent", CONTROL_VALUE, RTF_IGNOREMIXEDCONTENT, 0 }, + { "ilfomacatclnup", CONTROL_VALUE, RTF_ILFOMACATCLNUP, 0 }, + { "ilvl", CONTROL_VALUE, RTF_ILVL, 0 }, + { "impr", CONTROL_TOGGLE, RTF_IMPR, 1 }, + { "indmirror", CONTROL_FLAG, RTF_INDMIRROR, 0 }, + { "indrlsweleven", CONTROL_FLAG, RTF_INDRLSWELEVEN, 0 }, + { "info", CONTROL_DESTINATION, RTF_INFO, 0 }, + { "insrsid", CONTROL_VALUE, RTF_INSRSID, 0 }, + { "intbl", CONTROL_FLAG, RTF_INTBL, 0 }, + { "ipgp", CONTROL_VALUE, RTF_IPGP, 0 }, + { "irowband", CONTROL_VALUE, RTF_IROWBAND, 0 }, + { "irow", CONTROL_VALUE, RTF_IROW, 0 }, + { "itap", CONTROL_VALUE, RTF_ITAP, 1 }, + { "ixe", CONTROL_FLAG, RTF_IXE, 0 }, + { "jcompress", CONTROL_FLAG, RTF_JCOMPRESS, 0 }, + { "jexpand", CONTROL_FLAG, RTF_JEXPAND, 0 }, + { "jis", CONTROL_FLAG, RTF_JIS, 0 }, + { "jpegblip", CONTROL_FLAG, RTF_JPEGBLIP, 0 }, + { "jsksu", CONTROL_FLAG, RTF_JSKSU, 0 }, + { "keep", CONTROL_FLAG, RTF_KEEP, 0 }, + { "keepn", CONTROL_FLAG, RTF_KEEPN, 0 }, + { "kerning", CONTROL_VALUE, RTF_KERNING, 0 }, + { "keycode", CONTROL_DESTINATION, RTF_KEYCODE, 0 }, + { "keywords", CONTROL_DESTINATION, RTF_KEYWORDS, 0 }, + { "krnprsnet", CONTROL_FLAG, RTF_KRNPRSNET, 0 }, + { "ksulang", CONTROL_VALUE, RTF_KSULANG, 0 }, + { "jclisttab", CONTROL_FLAG, RTF_JCLISTTAB, 0 }, + { "landscape", CONTROL_FLAG, RTF_LANDSCAPE, 0 }, + { "lang", CONTROL_VALUE, RTF_LANG, 0 }, + { "langfe", CONTROL_VALUE, RTF_LANGFE, 0 }, + { "langfenp", CONTROL_VALUE, RTF_LANGFENP, 0 }, + { "langnp", CONTROL_VALUE, RTF_LANGNP, 0 }, + { "lastrow", CONTROL_FLAG, RTF_LASTROW, 0 }, + { "latentstyles", CONTROL_DESTINATION, RTF_LATENTSTYLES, 0 }, + { "lbr", CONTROL_VALUE, RTF_LBR, 0 }, + { "lchars", CONTROL_DESTINATION, RTF_LCHARS, 0 }, + { "ldblquote", CONTROL_SYMBOL, RTF_LDBLQUOTE, 0 }, + { "level", CONTROL_VALUE, RTF_LEVEL, 0 }, + { "levelfollow", CONTROL_VALUE, RTF_LEVELFOLLOW, 0 }, + { "levelindent", CONTROL_VALUE, RTF_LEVELINDENT, 0 }, + { "leveljc", CONTROL_VALUE, RTF_LEVELJC, 0 }, + { "leveljcn", CONTROL_VALUE, RTF_LEVELJCN, 0 }, + { "levellegal", CONTROL_VALUE, RTF_LEVELLEGAL, 0 }, + { "levelnfc", CONTROL_VALUE, RTF_LEVELNFC, 0 }, + { "levelnfcn", CONTROL_VALUE, RTF_LEVELNFCN, 0 }, + { "levelnorestart", CONTROL_VALUE, RTF_LEVELNORESTART, 0 }, + { "levelnumbers", CONTROL_DESTINATION, RTF_LEVELNUMBERS, 0 }, + { "levelold", CONTROL_VALUE, RTF_LEVELOLD, 0 }, + { "levelpicture", CONTROL_VALUE, RTF_LEVELPICTURE, 0 }, + { "levelpicturenosize", CONTROL_FLAG, RTF_LEVELPICTURENOSIZE, 0 }, + { "levelprev", CONTROL_VALUE, RTF_LEVELPREV, 0 }, + { "levelprevspace", CONTROL_VALUE, RTF_LEVELPREVSPACE, 0 }, + { "levelspace", CONTROL_VALUE, RTF_LEVELSPACE, 0 }, + { "levelstartat", CONTROL_VALUE, RTF_LEVELSTARTAT, 0 }, + { "leveltemplateid", CONTROL_VALUE, RTF_LEVELTEMPLATEID, 0 }, + { "leveltext", CONTROL_DESTINATION, RTF_LEVELTEXT, 0 }, + { "lfolevel", CONTROL_DESTINATION, RTF_LFOLEVEL, 0 }, + { "li", CONTROL_VALUE, RTF_LI, 0 }, + { "line", CONTROL_SYMBOL, RTF_LINE, 0 }, + { "linebetcol", CONTROL_FLAG, RTF_LINEBETCOL, 0 }, + { "linecont", CONTROL_FLAG, RTF_LINECONT, 0 }, + { "linemod", CONTROL_VALUE, RTF_LINEMOD, 1 }, + { "lineppage", CONTROL_FLAG, RTF_LINEPPAGE, 0 }, + { "linerestart", CONTROL_FLAG, RTF_LINERESTART, 0 }, + { "linestart", CONTROL_VALUE, RTF_LINESTART, 1 }, + { "linestarts", CONTROL_VALUE, RTF_LINESTARTS, 1 }, + { "linex", CONTROL_VALUE, RTF_LINEX, 360 }, + { "linkself", CONTROL_FLAG, RTF_LINKSELF, 0 }, + { "linkstyles", CONTROL_FLAG, RTF_LINKSTYLES, 0 }, + { "linkval", CONTROL_DESTINATION, RTF_LINKVAL, 0 }, + { "lin", CONTROL_VALUE, RTF_LIN, 0 }, + { "lisa", CONTROL_VALUE, RTF_LISA, 0 }, + { "lisb", CONTROL_VALUE, RTF_LISB, 0 }, + { "list", CONTROL_DESTINATION, RTF_LIST, 0 }, + { "listhybrid", CONTROL_FLAG, RTF_LISTHYBRID, 0 }, + { "listid", CONTROL_VALUE, RTF_LISTID, 0 }, + { "listlevel", CONTROL_DESTINATION, RTF_LISTLEVEL, 0 }, + { "listname", CONTROL_DESTINATION, RTF_LISTNAME, 0 }, + { "listoverride", CONTROL_DESTINATION, RTF_LISTOVERRIDE, 0 }, + { "listoverridecount", CONTROL_VALUE, RTF_LISTOVERRIDECOUNT, 0 }, + { "listoverrideformat", CONTROL_VALUE, RTF_LISTOVERRIDEFORMAT, 0 }, + { "listoverridestartat", CONTROL_FLAG, RTF_LISTOVERRIDESTARTAT, 0 }, + { "listoverridetable", CONTROL_DESTINATION, RTF_LISTOVERRIDETABLE, 0 }, + { "listpicture", CONTROL_DESTINATION, RTF_LISTPICTURE, 0 }, + { "listrestarthdn", CONTROL_VALUE, RTF_LISTRESTARTHDN, 0 }, + { "listsimple", CONTROL_VALUE, RTF_LISTSIMPLE, 0 }, + { "liststyleid", CONTROL_VALUE, RTF_LISTSTYLEID, 0 }, + { "liststylename", CONTROL_DESTINATION, RTF_LISTSTYLENAME, 0 }, + { "listtable", CONTROL_DESTINATION, RTF_LISTTABLE, 0 }, + { "listtemplateid", CONTROL_VALUE, RTF_LISTTEMPLATEID, 0 }, + { "listtext", CONTROL_DESTINATION, RTF_LISTTEXT, 0 }, + { "lnbrkrule", CONTROL_FLAG, RTF_LNBRKRULE, 0 }, + { "lndscpsxn", CONTROL_FLAG, RTF_LNDSCPSXN, 0 }, + { "lnongrid", CONTROL_FLAG, RTF_LNONGRID, 0 }, + { "loch", CONTROL_FLAG, RTF_LOCH, 0 }, + { "lquote", CONTROL_SYMBOL, RTF_LQUOTE, 0 }, + { "ls", CONTROL_VALUE, RTF_LS, 0 }, + { "lsdlocked", CONTROL_VALUE, RTF_LSDLOCKED, 0 }, + { "lsdlockeddef", CONTROL_VALUE, RTF_LSDLOCKEDDEF, 0 }, + { "lsdlockedexcept", CONTROL_DESTINATION, RTF_LSDLOCKEDEXCEPT, 0 }, + { "lsdpriority", CONTROL_VALUE, RTF_LSDPRIORITY, 0 }, + { "lsdprioritydef", CONTROL_VALUE, RTF_LSDPRIORITYDEF, 0 }, + { "lsdqformat", CONTROL_VALUE, RTF_LSDQFORMAT, 0 }, + { "lsdqformatdef", CONTROL_VALUE, RTF_LSDQFORMATDEF, 0 }, + { "lsdsemihidden", CONTROL_VALUE, RTF_LSDSEMIHIDDEN, 0 }, + { "lsdsemihiddendef", CONTROL_VALUE, RTF_LSDSEMIHIDDENDEF, 0 }, + { "lsdstimax", CONTROL_VALUE, RTF_LSDSTIMAX, 0 }, + { "lsdunhideused", CONTROL_VALUE, RTF_LSDUNHIDEUSED, 0 }, + { "lsdunhideuseddef", CONTROL_VALUE, RTF_LSDUNHIDEUSEDDEF, 0 }, + { "ltrch", CONTROL_FLAG, RTF_LTRCH, 0 }, + { "ltrdoc", CONTROL_FLAG, RTF_LTRDOC, 0 }, + { "ltrmark", CONTROL_SYMBOL, RTF_LTRMARK, 0 }, + { "ltrpar", CONTROL_FLAG, RTF_LTRPAR, 0 }, + { "ltrrow", CONTROL_FLAG, RTF_LTRROW, 0 }, + { "ltrsect", CONTROL_FLAG, RTF_LTRSECT, 0 }, + { "lvltentative", CONTROL_FLAG, RTF_LVLTENTATIVE, 0 }, + { "lytcalctblwd", CONTROL_FLAG, RTF_LYTCALCTBLWD, 0 }, + { "lytexcttp", CONTROL_FLAG, RTF_LYTEXCTTP, 0 }, + { "lytprtmet", CONTROL_FLAG, RTF_LYTPRTMET, 0 }, + { "lyttblrtgr", CONTROL_FLAG, RTF_LYTTBLRTGR, 0 }, + { "mac", CONTROL_FLAG, RTF_MAC, 0 }, + { "macc", CONTROL_DESTINATION, RTF_MACC, 0 }, + { "maccPr", CONTROL_DESTINATION, RTF_MACCPR, 0 }, + { "macpict", CONTROL_FLAG, RTF_MACPICT, 0 }, + { "mailmerge", CONTROL_DESTINATION, RTF_MAILMERGE, 0 }, + { "makebackup", CONTROL_FLAG, RTF_MAKEBACKUP, 0 }, + { "maln", CONTROL_DESTINATION, RTF_MALN, 0 }, + { "malnScr", CONTROL_DESTINATION, RTF_MALNSCR, 0 }, + { "manager", CONTROL_DESTINATION, RTF_MANAGER, 0 }, + { "margb", CONTROL_VALUE, RTF_MARGB, 1440 }, + { "margbsxn", CONTROL_VALUE, RTF_MARGBSXN, 0 }, + { "margl", CONTROL_VALUE, RTF_MARGL, 1800 }, + { "marglsxn", CONTROL_VALUE, RTF_MARGLSXN, 0 }, + { "margmirror", CONTROL_FLAG, RTF_MARGMIRROR, 0 }, + { "margmirsxn", CONTROL_FLAG, RTF_MARGMIRSXN, 0 }, + { "margPr", CONTROL_DESTINATION, RTF_MARGPR, 0 }, + { "margr", CONTROL_VALUE, RTF_MARGR, 1800 }, + { "margrsxn", CONTROL_VALUE, RTF_MARGRSXN, 0 }, + { "margSz", CONTROL_VALUE, RTF_MARGSZ, 0 }, + { "margt", CONTROL_VALUE, RTF_MARGT, 1440 }, + { "margtsxn", CONTROL_VALUE, RTF_MARGTSXN, 0 }, + { "mbar", CONTROL_DESTINATION, RTF_MBAR, 0 }, + { "mbarPr", CONTROL_DESTINATION, RTF_MBARPR, 0 }, + { "mbaseJc", CONTROL_DESTINATION, RTF_MBASEJC, 0 }, + { "mbegChr", CONTROL_DESTINATION, RTF_MBEGCHR, 0 }, + { "mborderBox", CONTROL_DESTINATION, RTF_MBORDERBOX, 0 }, + { "mborderBoxPr", CONTROL_DESTINATION, RTF_MBORDERBOXPR, 0 }, + { "mbox", CONTROL_DESTINATION, RTF_MBOX, 0 }, + { "mboxPr", CONTROL_DESTINATION, RTF_MBOXPR, 0 }, + { "mbrk", CONTROL_VALUE, RTF_MBRK, 0 }, + { "mbrkBin", CONTROL_VALUE, RTF_MBRKBIN, 0 }, + { "mbrkBinSub", CONTROL_VALUE, RTF_MBRKBINSUB, 0 }, + { "mcGp", CONTROL_VALUE, RTF_MCGP, 0 }, + { "mcGpRule", CONTROL_VALUE, RTF_MCGPRULE, 0 }, + { "mchr", CONTROL_DESTINATION, RTF_MCHR, 0 }, + { "mcount", CONTROL_DESTINATION, RTF_MCOUNT, 0 }, + { "mcSp", CONTROL_VALUE, RTF_MCSP, 0 }, + { "mctrlPr", CONTROL_DESTINATION, RTF_MCTRLPR, 0 }, + { "md", CONTROL_DESTINATION, RTF_MD, 0 }, + { "mdefJc", CONTROL_VALUE, RTF_MDEFJC, 0 }, + { "mdeg", CONTROL_DESTINATION, RTF_MDEG, 0 }, + { "mdegHide", CONTROL_DESTINATION, RTF_MDEGHIDE, 0 }, + { "mden", CONTROL_DESTINATION, RTF_MDEN, 0 }, + { "mdiff", CONTROL_DESTINATION, RTF_MDIFF, 0 }, + { "mdiffSty", CONTROL_VALUE, RTF_MDIFFSTY, 0 }, + { "mdispdef", CONTROL_VALUE, RTF_MDISPDEF, 1 }, + { "mdPr", CONTROL_DESTINATION, RTF_MDPR, 0 }, + { "me", CONTROL_DESTINATION, RTF_ME, 0 }, + { "mendChr", CONTROL_DESTINATION, RTF_MENDCHR, 0 }, + { "meqArr", CONTROL_DESTINATION, RTF_MEQARR, 0 }, + { "meqArrPr", CONTROL_DESTINATION, RTF_MEQARRPR, 0 }, + { "mf", CONTROL_DESTINATION, RTF_MF, 0 }, + { "mfName", CONTROL_DESTINATION, RTF_MFNAME, 0 }, + { "mfPr", CONTROL_DESTINATION, RTF_MFPR, 0 }, + { "mfunc", CONTROL_DESTINATION, RTF_MFUNC, 0 }, + { "mfuncPr", CONTROL_DESTINATION, RTF_MFUNCPR, 0 }, + { "mgroupChr", CONTROL_DESTINATION, RTF_MGROUPCHR, 0 }, + { "mgroupChrPr", CONTROL_DESTINATION, RTF_MGROUPCHRPR, 0 }, + { "mgrow", CONTROL_DESTINATION, RTF_MGROW, 0 }, + { "mhideBot", CONTROL_DESTINATION, RTF_MHIDEBOT, 0 }, + { "mhideLeft", CONTROL_DESTINATION, RTF_MHIDELEFT, 0 }, + { "mhideRight", CONTROL_DESTINATION, RTF_MHIDERIGHT, 0 }, + { "mhideTop", CONTROL_DESTINATION, RTF_MHIDETOP, 0 }, + { "mhtmltag", CONTROL_DESTINATION, RTF_MHTMLTAG, 0 }, + { "min", CONTROL_VALUE, RTF_MIN, 0 }, + { "minterSp", CONTROL_VALUE, RTF_MINTERSP, 0 }, + { "mintLim", CONTROL_VALUE, RTF_MINTLIM, 0 }, + { "mintraSp", CONTROL_VALUE, RTF_MINTRASP, 0 }, + { "mjc", CONTROL_VALUE, RTF_MJC, 0 }, + { "mlim", CONTROL_DESTINATION, RTF_MLIM, 0 }, + { "mlimloc", CONTROL_DESTINATION, RTF_MLIMLOC, 0 }, + { "mlimLoc", CONTROL_DESTINATION, RTF_MLIMLOC, 0 }, + { "mlimlow", CONTROL_DESTINATION, RTF_MLIMLOW, 0 }, + { "mlimLow", CONTROL_DESTINATION, RTF_MLIMLOW, 0 }, + { "mlimlowPr", CONTROL_DESTINATION, RTF_MLIMLOWPR, 0 }, + { "mlimLowPr", CONTROL_DESTINATION, RTF_MLIMLOWPR, 0 }, + { "mlimupp", CONTROL_DESTINATION, RTF_MLIMUPP, 0 }, + { "mlimUpp", CONTROL_DESTINATION, RTF_MLIMUPP, 0 }, + { "mlimuppPr", CONTROL_DESTINATION, RTF_MLIMUPPPR, 0 }, + { "mlimUppPr", CONTROL_DESTINATION, RTF_MLIMUPPPR, 0 }, + { "mlit", CONTROL_FLAG, RTF_MLIT, 0 }, + { "mlMargin", CONTROL_VALUE, RTF_MLMARGIN, 0 }, + { "mm", CONTROL_DESTINATION, RTF_MM, 0 }, + { "mmaddfieldname", CONTROL_DESTINATION, RTF_MMADDFIELDNAME, 0 }, + { "mmath", CONTROL_DESTINATION, RTF_MMATH, 0 }, + { "mmathFont", CONTROL_VALUE, RTF_MMATHFONT, 0 }, + { "mmathPict", CONTROL_DESTINATION, RTF_MMATHPICT, 0 }, + { "mmathPr", CONTROL_DESTINATION, RTF_MMATHPR, 0 }, + { "mmattach", CONTROL_FLAG, RTF_MMATTACH, 0 }, + { "mmaxdist", CONTROL_DESTINATION, RTF_MMAXDIST, 0 }, + { "mmblanklines", CONTROL_FLAG, RTF_MMBLANKLINES, 0 }, + { "mmc", CONTROL_DESTINATION, RTF_MMC, 0 }, + { "mmcJc", CONTROL_DESTINATION, RTF_MMCJC, 0 }, + { "mmconnectstr", CONTROL_DESTINATION, RTF_MMCONNECTSTR, 0 }, + { "mmconnectstrdata", CONTROL_DESTINATION, RTF_MMCONNECTSTRDATA, 0 }, + { "mmcPr", CONTROL_DESTINATION, RTF_MMCPR, 0 }, + { "mmcs", CONTROL_DESTINATION, RTF_MMCS, 0 }, + { "mmdatasource", CONTROL_DESTINATION, RTF_MMDATASOURCE, 0 }, + { "mmdatatypeaccess", CONTROL_FLAG, RTF_MMDATATYPEACCESS, 0 }, + { "mmdatatypeexcel", CONTROL_FLAG, RTF_MMDATATYPEEXCEL, 0 }, + { "mmdatatypefile", CONTROL_FLAG, RTF_MMDATATYPEFILE, 0 }, + { "mmdatatypeodbc", CONTROL_FLAG, RTF_MMDATATYPEODBC, 0 }, + { "mmdatatypeodso", CONTROL_FLAG, RTF_MMDATATYPEODSO, 0 }, + { "mmdatatypeqt", CONTROL_FLAG, RTF_MMDATATYPEQT, 0 }, + { "mmdefaultsql", CONTROL_FLAG, RTF_MMDEFAULTSQL, 0 }, + { "mmdestemail", CONTROL_FLAG, RTF_MMDESTEMAIL, 0 }, + { "mmdestfax", CONTROL_FLAG, RTF_MMDESTFAX, 0 }, + { "mmdestnewdoc", CONTROL_FLAG, RTF_MMDESTNEWDOC, 0 }, + { "mmdestprinter", CONTROL_FLAG, RTF_MMDESTPRINTER, 0 }, + { "mmerrors", CONTROL_VALUE, RTF_MMERRORS, 0 }, + { "mmfttypeaddress", CONTROL_FLAG, RTF_MMFTTYPEADDRESS, 0 }, + { "mmfttypebarcode", CONTROL_FLAG, RTF_MMFTTYPEBARCODE, 0 }, + { "mmfttypedbcolumn", CONTROL_FLAG, RTF_MMFTTYPEDBCOLUMN, 0 }, + { "mmfttypemapped", CONTROL_FLAG, RTF_MMFTTYPEMAPPED, 0 }, + { "mmfttypenull", CONTROL_FLAG, RTF_MMFTTYPENULL, 0 }, + { "mmfttypesalutation", CONTROL_FLAG, RTF_MMFTTYPESALUTATION, 0 }, + { "mmheadersource", CONTROL_DESTINATION, RTF_MMHEADERSOURCE, 0 }, + { "mmjdsotype", CONTROL_VALUE, RTF_MMJDSOTYPE, 0 }, + { "mmlinktoquery", CONTROL_FLAG, RTF_MMLINKTOQUERY, 0 }, + { "mmmailsubject", CONTROL_DESTINATION, RTF_MMMAILSUBJECT, 0 }, + { "mmmaintypecatalog", CONTROL_FLAG, RTF_MMMAINTYPECATALOG, 0 }, + { "mmmaintypeemail", CONTROL_FLAG, RTF_MMMAINTYPEEMAIL, 0 }, + { "mmmaintypeenvelopes", CONTROL_FLAG, RTF_MMMAINTYPEENVELOPES, 0 }, + { "mmmaintypefax", CONTROL_FLAG, RTF_MMMAINTYPEFAX, 0 }, + { "mmmaintypelabels", CONTROL_FLAG, RTF_MMMAINTYPELABELS, 0 }, + { "mmmaintypeletters", CONTROL_FLAG, RTF_MMMAINTYPELETTERS, 0 }, + { "mmodso", CONTROL_DESTINATION, RTF_MMODSO, 0 }, + { "mmodsoactive", CONTROL_VALUE, RTF_MMODSOACTIVE, 0 }, + { "mmodsocoldelim", CONTROL_VALUE, RTF_MMODSOCOLDELIM, 0 }, + { "mmodsocolumn", CONTROL_VALUE, RTF_MMODSOCOLUMN, 0 }, + { "mmodsodynaddr", CONTROL_VALUE, RTF_MMODSODYNADDR, 0 }, + { "mmodsofhdr", CONTROL_VALUE, RTF_MMODSOFHDR, 0 }, + { "mmodsofilter", CONTROL_DESTINATION, RTF_MMODSOFILTER, 0 }, + { "mmodsofldmpdata", CONTROL_DESTINATION, RTF_MMODSOFLDMPDATA, 0 }, + { "mmodsofmcolumn", CONTROL_VALUE, RTF_MMODSOFMCOLUMN, 0 }, + { "mmodsohash", CONTROL_VALUE, RTF_MMODSOHASH, 0 }, + { "mmodsolid", CONTROL_VALUE, RTF_MMODSOLID, 0 }, + { "mmodsomappedname", CONTROL_DESTINATION, RTF_MMODSOMAPPEDNAME, 0 }, + { "mmodsoname", CONTROL_DESTINATION, RTF_MMODSONAME, 0 }, + { "mmodsorecipdata", CONTROL_DESTINATION, RTF_MMODSORECIPDATA, 0 }, + { "mmodsosort", CONTROL_DESTINATION, RTF_MMODSOSORT, 0 }, + { "mmodsosrc", CONTROL_DESTINATION, RTF_MMODSOSRC, 0 }, + { "mmodsotable", CONTROL_DESTINATION, RTF_MMODSOTABLE, 0 }, + { "mmodsoudl", CONTROL_DESTINATION, RTF_MMODSOUDL, 0 }, + { "mmodsoudldata", CONTROL_DESTINATION, RTF_MMODSOUDLDATA, 0 }, + { "mmodsouniquetag", CONTROL_DESTINATION, RTF_MMODSOUNIQUETAG, 0 }, + { "mmPr", CONTROL_DESTINATION, RTF_MMPR, 0 }, + { "mmquery", CONTROL_DESTINATION, RTF_MMQUERY, 0 }, + { "mmr", CONTROL_DESTINATION, RTF_MMR, 0 }, + { "mmreccur", CONTROL_VALUE, RTF_MMRECCUR, 0 }, + { "mmshowdata", CONTROL_FLAG, RTF_MMSHOWDATA, 0 }, + { "mnary", CONTROL_DESTINATION, RTF_MNARY, 0 }, + { "mnaryLim", CONTROL_VALUE, RTF_MNARYLIM, 0 }, + { "mnaryPr", CONTROL_DESTINATION, RTF_MNARYPR, 0 }, + { "mnoBreak", CONTROL_DESTINATION, RTF_MNOBREAK, 0 }, + { "mnor", CONTROL_FLAG, RTF_MNOR, 0 }, + { "mnum", CONTROL_DESTINATION, RTF_MNUM, 0 }, + { "mo", CONTROL_VALUE, RTF_MO, 0 }, + { "mobjDist", CONTROL_DESTINATION, RTF_MOBJDIST, 0 }, + { "moMath", CONTROL_DESTINATION, RTF_MOMATH, 0 }, + { "moMathPara", CONTROL_DESTINATION, RTF_MOMATHPARA, 0 }, + { "moMathParaPr", CONTROL_DESTINATION, RTF_MOMATHPARAPR, 0 }, + { "mopEmu", CONTROL_DESTINATION, RTF_MOPEMU, 0 }, + { "mphant", CONTROL_DESTINATION, RTF_MPHANT, 0 }, + { "mphantPr", CONTROL_DESTINATION, RTF_MPHANTPR, 0 }, + { "mplcHide", CONTROL_DESTINATION, RTF_MPLCHIDE, 0 }, + { "mpos", CONTROL_DESTINATION, RTF_MPOS, 0 }, + { "mpostSp", CONTROL_VALUE, RTF_MPOSTSP, 0 }, + { "mpreSp", CONTROL_VALUE, RTF_MPRESP, 0 }, + { "mr", CONTROL_DESTINATION, RTF_MR, 0 }, + { "mrad", CONTROL_DESTINATION, RTF_MRAD, 0 }, + { "mradPr", CONTROL_DESTINATION, RTF_MRADPR, 0 }, + { "mrMargin", CONTROL_VALUE, RTF_MRMARGIN, 0 }, + { "mrPr", CONTROL_DESTINATION, RTF_MRPR, 0 }, + { "mrSp", CONTROL_VALUE, RTF_MRSP, 0 }, + { "mrSpRule", CONTROL_VALUE, RTF_MRSPRULE, 0 }, + { "mscr", CONTROL_VALUE, RTF_MSCR, 0 }, + { "msepChr", CONTROL_DESTINATION, RTF_MSEPCHR, 0 }, + { "mshow", CONTROL_DESTINATION, RTF_MSHOW, 0 }, + { "mshp", CONTROL_DESTINATION, RTF_MSHP, 0 }, + { "msmallFrac", CONTROL_VALUE, RTF_MSMALLFRAC, 0 }, + { "msmcap", CONTROL_FLAG, RTF_MSMCAP, 0 }, + { "msPre", CONTROL_DESTINATION, RTF_MSPRE, 0 }, + { "msPrePr", CONTROL_DESTINATION, RTF_MSPREPR, 0 }, + { "msSub", CONTROL_DESTINATION, RTF_MSSUB, 0 }, + { "msSubPr", CONTROL_DESTINATION, RTF_MSSUBPR, 0 }, + { "msSubSup", CONTROL_DESTINATION, RTF_MSSUBSUP, 0 }, + { "msSubSupPr", CONTROL_DESTINATION, RTF_MSSUBSUPPR, 0 }, + { "msSup", CONTROL_DESTINATION, RTF_MSSUP, 0 }, + { "msSupPr", CONTROL_DESTINATION, RTF_MSSUPPR, 0 }, + { "mstrikeBLTR", CONTROL_DESTINATION, RTF_MSTRIKEBLTR, 0 }, + { "mstrikeH", CONTROL_DESTINATION, RTF_MSTRIKEH, 0 }, + { "mstrikeTLBR", CONTROL_DESTINATION, RTF_MSTRIKETLBR, 0 }, + { "mstrikeV", CONTROL_DESTINATION, RTF_MSTRIKEV, 0 }, + { "msty", CONTROL_VALUE, RTF_MSTY, 0 }, + { "msub", CONTROL_DESTINATION, RTF_MSUB, 0 }, + { "msubHide", CONTROL_DESTINATION, RTF_MSUBHIDE, 0 }, + { "msup", CONTROL_DESTINATION, RTF_MSUP, 0 }, + { "msupHide", CONTROL_DESTINATION, RTF_MSUPHIDE, 0 }, + { "mtransp", CONTROL_DESTINATION, RTF_MTRANSP, 0 }, + { "mtype", CONTROL_DESTINATION, RTF_MTYPE, 0 }, + { "muser", CONTROL_FLAG, RTF_MUSER, 0 }, + { "mvauth", CONTROL_VALUE, RTF_MVAUTH, 0 }, + { "mvdate", CONTROL_VALUE, RTF_MVDATE, 0 }, + { "mvertJc", CONTROL_DESTINATION, RTF_MVERTJC, 0 }, + { "mvf", CONTROL_FLAG, RTF_MVF, 0 }, + { "mvfmf", CONTROL_DESTINATION, RTF_MVFMF, 0 }, + { "mvfml", CONTROL_DESTINATION, RTF_MVFML, 0 }, + { "mvt", CONTROL_FLAG, RTF_MVT, 0 }, + { "mvtof", CONTROL_DESTINATION, RTF_MVTOF, 0 }, + { "mvtol", CONTROL_DESTINATION, RTF_MVTOL, 0 }, + { "mwrapIndent", CONTROL_VALUE, RTF_MWRAPINDENT, 1440 }, + { "mwrapRight", CONTROL_VALUE, RTF_MWRAPRIGHT, 0 }, + { "mzeroAsc", CONTROL_DESTINATION, RTF_MZEROASC, 0 }, + { "mzeroDesc", CONTROL_DESTINATION, RTF_MZERODESC, 0 }, + { "mzeroWid", CONTROL_DESTINATION, RTF_MZEROWID, 0 }, + { "nestcell", CONTROL_SYMBOL, RTF_NESTCELL, 0 }, + { "nestrow", CONTROL_SYMBOL, RTF_NESTROW, 0 }, + { "nesttableprops", CONTROL_DESTINATION, RTF_NESTTABLEPROPS, 0 }, + { "newtblstyruls", CONTROL_FLAG, RTF_NEWTBLSTYRULS, 0 }, + { "nextfile", CONTROL_DESTINATION, RTF_NEXTFILE, 0 }, + { "noafcnsttbl", CONTROL_FLAG, RTF_NOAFCNSTTBL, 0 }, + { "nobrkwrptbl", CONTROL_FLAG, RTF_NOBRKWRPTBL, 0 }, + { "nocolbal", CONTROL_FLAG, RTF_NOCOLBAL, 0 }, + { "nocompatoptions", CONTROL_FLAG, RTF_NOCOMPATOPTIONS, 0 }, + { "nocwrap", CONTROL_FLAG, RTF_NOCWRAP, 0 }, + { "nocxsptable", CONTROL_FLAG, RTF_NOCXSPTABLE, 0 }, + { "noextrasprl", CONTROL_FLAG, RTF_NOEXTRASPRL, 0 }, + { "nofchars", CONTROL_VALUE, RTF_NOFCHARS, 0 }, + { "nofcharsws", CONTROL_VALUE, RTF_NOFCHARSWS, 0 }, + { "nofeaturethrottle", CONTROL_FLAG, RTF_NOFEATURETHROTTLE, 0 }, + { "nofpages", CONTROL_VALUE, RTF_NOFPAGES, 0 }, + { "nofwords", CONTROL_VALUE, RTF_NOFWORDS, 0 }, + { "nogrowautofit", CONTROL_FLAG, RTF_NOGROWAUTOFIT, 0 }, + { "noindnmbrts", CONTROL_FLAG, RTF_NOINDNMBRTS, 0 }, + { "nojkernpunct", CONTROL_FLAG, RTF_NOJKERNPUNCT, 0 }, + { "nolead", CONTROL_FLAG, RTF_NOLEAD, 0 }, + { "noline", CONTROL_FLAG, RTF_NOLINE, 0 }, + { "nolnhtadjtbl", CONTROL_FLAG, RTF_NOLNHTADJTBL, 0 }, + { "nonesttables", CONTROL_DESTINATION, RTF_NONESTTABLES, 0 }, + { "nonshppict", CONTROL_FLAG, RTF_NONSHPPICT, 0 }, + { "nooverflow", CONTROL_FLAG, RTF_NOOVERFLOW, 0 }, + { "noproof", CONTROL_FLAG, RTF_NOPROOF, 0 }, + { "noqfpromote", CONTROL_FLAG, RTF_NOQFPROMOTE, 0 }, + { "nosectexpand", CONTROL_FLAG, RTF_NOSECTEXPAND, 0 }, + { "nosnaplinegrid", CONTROL_FLAG, RTF_NOSNAPLINEGRID, 0 }, + { "nospaceforul", CONTROL_FLAG, RTF_NOSPACEFORUL, 0 }, + { "nosupersub", CONTROL_FLAG, RTF_NOSUPERSUB, 0 }, + { "notabind", CONTROL_FLAG, RTF_NOTABIND, 0 }, + { "notbrkcnstfrctbl", CONTROL_FLAG, RTF_NOTBRKCNSTFRCTBL, 0 }, + { "notcvasp", CONTROL_FLAG, RTF_NOTCVASP, 0 }, + { "notvatxbx", CONTROL_FLAG, RTF_NOTVATXBX, 0 }, + { "nouicompat", CONTROL_FLAG, RTF_NOUICOMPAT, 0 }, + { "noultrlspc", CONTROL_FLAG, RTF_NOULTRLSPC, 0 }, + { "nowidctlpar", CONTROL_FLAG, RTF_NOWIDCTLPAR, 0 }, + { "nowrap", CONTROL_FLAG, RTF_NOWRAP, 0 }, + { "nowwrap", CONTROL_FLAG, RTF_NOWWRAP, 0 }, + { "noxlattoyen", CONTROL_FLAG, RTF_NOXLATTOYEN, 0 }, + { "objalias", CONTROL_DESTINATION, RTF_OBJALIAS, 0 }, + { "objalign", CONTROL_VALUE, RTF_OBJALIGN, 0 }, + { "objattph", CONTROL_FLAG, RTF_OBJATTPH, 0 }, + { "objautlink", CONTROL_FLAG, RTF_OBJAUTLINK, 0 }, + { "objclass", CONTROL_DESTINATION, RTF_OBJCLASS, 0 }, + { "objcropb", CONTROL_VALUE, RTF_OBJCROPB, 0 }, + { "objcropl", CONTROL_VALUE, RTF_OBJCROPL, 0 }, + { "objcropr", CONTROL_VALUE, RTF_OBJCROPR, 0 }, + { "objcropt", CONTROL_VALUE, RTF_OBJCROPT, 0 }, + { "objdata", CONTROL_DESTINATION, RTF_OBJDATA, 0 }, + { "object", CONTROL_DESTINATION, RTF_OBJECT, 0 }, + { "objemb", CONTROL_FLAG, RTF_OBJEMB, 0 }, + { "objh", CONTROL_VALUE, RTF_OBJH, 0 }, + { "objhtml", CONTROL_FLAG, RTF_OBJHTML, 0 }, + { "objicemb", CONTROL_FLAG, RTF_OBJICEMB, 0 }, + { "objlink", CONTROL_FLAG, RTF_OBJLINK, 0 }, + { "objlock", CONTROL_FLAG, RTF_OBJLOCK, 0 }, + { "objname", CONTROL_DESTINATION, RTF_OBJNAME, 0 }, + { "objocx", CONTROL_FLAG, RTF_OBJOCX, 0 }, + { "objpub", CONTROL_FLAG, RTF_OBJPUB, 0 }, + { "objscalex", CONTROL_VALUE, RTF_OBJSCALEX, 0 }, + { "objscaley", CONTROL_VALUE, RTF_OBJSCALEY, 0 }, + { "objsect", CONTROL_DESTINATION, RTF_OBJSECT, 0 }, + { "objsetsize", CONTROL_FLAG, RTF_OBJSETSIZE, 0 }, + { "objsub", CONTROL_FLAG, RTF_OBJSUB, 0 }, + { "objtime", CONTROL_DESTINATION, RTF_OBJTIME, 0 }, + { "objtransy", CONTROL_VALUE, RTF_OBJTRANSY, 0 }, + { "objupdate", CONTROL_FLAG, RTF_OBJUPDATE, 0 }, + { "objw", CONTROL_VALUE, RTF_OBJW, 0 }, + { "ogutter", CONTROL_VALUE, RTF_OGUTTER, 0 }, + { "oldas", CONTROL_FLAG, RTF_OLDAS, 0 }, + { "oldcprops", CONTROL_DESTINATION, RTF_OLDCPROPS, 0 }, + { "oldlinewrap", CONTROL_FLAG, RTF_OLDLINEWRAP, 0 }, + { "oldpprops", CONTROL_DESTINATION, RTF_OLDPPROPS, 0 }, + { "oldsprops", CONTROL_DESTINATION, RTF_OLDSPROPS, 0 }, + { "oldtprops", CONTROL_DESTINATION, RTF_OLDTPROPS, 0 }, + { "oleclsid", CONTROL_DESTINATION, RTF_OLECLSID, 0 }, + { "operator", CONTROL_DESTINATION, RTF_OPERATOR, 0 }, + { "otblrul", CONTROL_FLAG, RTF_OTBLRUL, 0 }, + { "outl", CONTROL_TOGGLE, RTF_OUTL, 1 }, + { "outlinelevel", CONTROL_VALUE, RTF_OUTLINELEVEL, 0 }, + { "overlay", CONTROL_FLAG, RTF_OVERLAY, 0 }, + { "page", CONTROL_SYMBOL, RTF_PAGE, 0 }, + { "pagebb", CONTROL_FLAG, RTF_PAGEBB, 0 }, + { "panose", CONTROL_DESTINATION, RTF_PANOSE, 0 }, + { "paperh", CONTROL_VALUE, RTF_PAPERH, 15840 }, + { "paperw", CONTROL_VALUE, RTF_PAPERW, 12240 }, + { "par", CONTROL_SYMBOL, RTF_PAR, 0 }, + { "pararsid", CONTROL_VALUE, RTF_PARARSID, 0 }, + { "pard", CONTROL_FLAG, RTF_PARD, 0 }, + { "password", CONTROL_DESTINATION, RTF_PASSWORD, 0 }, + { "passwordhash", CONTROL_DESTINATION, RTF_PASSWORDHASH, 0 }, + { "pc", CONTROL_FLAG, RTF_PC, 0 }, + { "pca", CONTROL_FLAG, RTF_PCA, 0 }, + { "pgbrdrb", CONTROL_FLAG, RTF_PGBRDRB, 0 }, + { "pgbrdrfoot", CONTROL_FLAG, RTF_PGBRDRFOOT, 0 }, + { "pgbrdrhead", CONTROL_FLAG, RTF_PGBRDRHEAD, 0 }, + { "pgbrdrl", CONTROL_FLAG, RTF_PGBRDRL, 0 }, + { "pgbrdropt", CONTROL_VALUE, RTF_PGBRDROPT, 0 }, + { "pgbrdrr", CONTROL_FLAG, RTF_PGBRDRR, 0 }, + { "pgbrdrsnap", CONTROL_FLAG, RTF_PGBRDRSNAP, 0 }, + { "pgbrdrt", CONTROL_FLAG, RTF_PGBRDRT, 0 }, + { "pghsxn", CONTROL_VALUE, RTF_PGHSXN, 0 }, + { "pgnbidia", CONTROL_FLAG, RTF_PGNBIDIA, 0 }, + { "pgnbidib", CONTROL_FLAG, RTF_PGNBIDIB, 0 }, + { "pgnchosung", CONTROL_FLAG, RTF_PGNCHOSUNG, 0 }, + { "pgncnum", CONTROL_FLAG, RTF_PGNCNUM, 0 }, + { "pgncont", CONTROL_FLAG, RTF_PGNCONT, 0 }, + { "pgndbnum", CONTROL_FLAG, RTF_PGNDBNUM, 0 }, + { "pgndbnumd", CONTROL_FLAG, RTF_PGNDBNUMD, 0 }, + { "pgndbnumk", CONTROL_FLAG, RTF_PGNDBNUMK, 0 }, + { "pgndbnumt", CONTROL_FLAG, RTF_PGNDBNUMT, 0 }, + { "pgndec", CONTROL_FLAG, RTF_PGNDEC, 0 }, + { "pgndecd", CONTROL_FLAG, RTF_PGNDECD, 0 }, + { "pgnganada", CONTROL_FLAG, RTF_PGNGANADA, 0 }, + { "pgngbnum", CONTROL_FLAG, RTF_PGNGBNUM, 0 }, + { "pgngbnumd", CONTROL_FLAG, RTF_PGNGBNUMD, 0 }, + { "pgngbnumk", CONTROL_FLAG, RTF_PGNGBNUMK, 0 }, + { "pgngbnuml", CONTROL_FLAG, RTF_PGNGBNUML, 0 }, + { "pgnhindia", CONTROL_FLAG, RTF_PGNHINDIA, 0 }, + { "pgnhindib", CONTROL_FLAG, RTF_PGNHINDIB, 0 }, + { "pgnhindic", CONTROL_FLAG, RTF_PGNHINDIC, 0 }, + { "pgnhindid", CONTROL_FLAG, RTF_PGNHINDID, 0 }, + { "pgnhn", CONTROL_VALUE, RTF_PGNHN, 0 }, + { "pgnhnsc", CONTROL_FLAG, RTF_PGNHNSC, 0 }, + { "pgnhnsh", CONTROL_FLAG, RTF_PGNHNSH, 0 }, + { "pgnhnsm", CONTROL_FLAG, RTF_PGNHNSM, 0 }, + { "pgnhnsn", CONTROL_FLAG, RTF_PGNHNSN, 0 }, + { "pgnhnsp", CONTROL_FLAG, RTF_PGNHNSP, 0 }, + { "pgnid", CONTROL_FLAG, RTF_PGNID, 0 }, + { "pgnlcltr", CONTROL_FLAG, RTF_PGNLCLTR, 0 }, + { "pgnlcrm", CONTROL_FLAG, RTF_PGNLCRM, 0 }, + { "pgnrestart", CONTROL_FLAG, RTF_PGNRESTART, 0 }, + { "pgnstart", CONTROL_VALUE, RTF_PGNSTART, 1 }, + { "pgnstarts", CONTROL_VALUE, RTF_PGNSTARTS, 1 }, + { "pgnthaia", CONTROL_FLAG, RTF_PGNTHAIA, 0 }, + { "pgnthaib", CONTROL_FLAG, RTF_PGNTHAIB, 0 }, + { "pgnthaic", CONTROL_FLAG, RTF_PGNTHAIC, 0 }, + { "pgnucltr", CONTROL_FLAG, RTF_PGNUCLTR, 0 }, + { "pgnucrm", CONTROL_FLAG, RTF_PGNUCRM, 0 }, + { "pgnvieta", CONTROL_FLAG, RTF_PGNVIETA, 0 }, + { "pgnx", CONTROL_VALUE, RTF_PGNX, 720 }, + { "pgny", CONTROL_VALUE, RTF_PGNY, 720 }, + { "pgnzodiac", CONTROL_FLAG, RTF_PGNZODIAC, 0 }, + { "pgnzodiacd", CONTROL_FLAG, RTF_PGNZODIACD, 0 }, + { "pgnzodiacl", CONTROL_FLAG, RTF_PGNZODIACL, 0 }, + { "pgp", CONTROL_DESTINATION, RTF_PGP, 0 }, + { "pgptbl", CONTROL_DESTINATION, RTF_PGPTBL, 0 }, + { "pgwsxn", CONTROL_VALUE, RTF_PGWSXN, 0 }, + { "phcol", CONTROL_FLAG, RTF_PHCOL, 0 }, + { "phmrg", CONTROL_FLAG, RTF_PHMRG, 0 }, + { "phpg", CONTROL_FLAG, RTF_PHPG, 0 }, + { "picbmp", CONTROL_FLAG, RTF_PICBMP, 0 }, + { "picbpp", CONTROL_VALUE, RTF_PICBPP, 0 }, + { "piccropb", CONTROL_VALUE, RTF_PICCROPB, 0 }, + { "piccropl", CONTROL_VALUE, RTF_PICCROPL, 0 }, + { "piccropr", CONTROL_VALUE, RTF_PICCROPR, 0 }, + { "piccropt", CONTROL_VALUE, RTF_PICCROPT, 0 }, + { "pich", CONTROL_VALUE, RTF_PICH, 0 }, + { "pichgoal", CONTROL_VALUE, RTF_PICHGOAL, 0 }, + { "pichGoal", CONTROL_VALUE, RTF_PICHGOAL, 0 }, + { "picprop", CONTROL_DESTINATION, RTF_PICPROP, 0 }, + { "picscaled", CONTROL_FLAG, RTF_PICSCALED, 0 }, + { "picscalex", CONTROL_VALUE, RTF_PICSCALEX, 100 }, + { "picscaley", CONTROL_VALUE, RTF_PICSCALEY, 100 }, + { "pict", CONTROL_DESTINATION, RTF_PICT, 0 }, + { "picw", CONTROL_VALUE, RTF_PICW, 0 }, + { "picwgoal", CONTROL_VALUE, RTF_PICWGOAL, 0 }, + { "picwGoal", CONTROL_VALUE, RTF_PICWGOAL, 0 }, + { "pindtabqc", CONTROL_FLAG, RTF_PINDTABQC, 0 }, + { "pindtabql", CONTROL_FLAG, RTF_PINDTABQL, 0 }, + { "pindtabqr", CONTROL_FLAG, RTF_PINDTABQR, 0 }, + { "plain", CONTROL_FLAG, RTF_PLAIN, 0 }, + { "pmartabqc", CONTROL_FLAG, RTF_PMARTABQC, 0 }, + { "pmartabql", CONTROL_FLAG, RTF_PMARTABQL, 0 }, + { "pmartabqr", CONTROL_FLAG, RTF_PMARTABQR, 0 }, + { "pmmetafile", CONTROL_VALUE, RTF_PMMETAFILE, 0 }, + { "pn", CONTROL_DESTINATION, RTF_PN, 0 }, + { "pnacross", CONTROL_FLAG, RTF_PNACROSS, 0 }, + { "pnaiu", CONTROL_FLAG, RTF_PNAIU, 0 }, + { "pnaiud", CONTROL_FLAG, RTF_PNAIUD, 0 }, + { "pnaiueo", CONTROL_FLAG, RTF_PNAIUEO, 0 }, + { "pnaiueod", CONTROL_FLAG, RTF_PNAIUEOD, 0 }, + { "pnb", CONTROL_TOGGLE, RTF_PNB, 1 }, + { "pnbidia", CONTROL_FLAG, RTF_PNBIDIA, 0 }, + { "pnbidib", CONTROL_FLAG, RTF_PNBIDIB, 0 }, + { "pncaps", CONTROL_TOGGLE, RTF_PNCAPS, 1 }, + { "pncard", CONTROL_FLAG, RTF_PNCARD, 0 }, + { "pncf", CONTROL_VALUE, RTF_PNCF, 0 }, + { "pnchosung", CONTROL_FLAG, RTF_PNCHOSUNG, 0 }, + { "pncnum", CONTROL_FLAG, RTF_PNCNUM, 0 }, + { "pndbnum", CONTROL_FLAG, RTF_PNDBNUM, 0 }, + { "pndbnumd", CONTROL_FLAG, RTF_PNDBNUMD, 0 }, + { "pndbnumk", CONTROL_FLAG, RTF_PNDBNUMK, 0 }, + { "pndbnuml", CONTROL_FLAG, RTF_PNDBNUML, 0 }, + { "pndbnumt", CONTROL_FLAG, RTF_PNDBNUMT, 0 }, + { "pndec", CONTROL_FLAG, RTF_PNDEC, 0 }, + { "pndecd", CONTROL_FLAG, RTF_PNDECD, 0 }, + { "pnf", CONTROL_VALUE, RTF_PNF, 0 }, + { "pnfs", CONTROL_VALUE, RTF_PNFS, 0 }, + { "pnganada", CONTROL_FLAG, RTF_PNGANADA, 0 }, + { "pngblip", CONTROL_FLAG, RTF_PNGBLIP, 0 }, + { "pngbnum", CONTROL_FLAG, RTF_PNGBNUM, 0 }, + { "pngbnumd", CONTROL_FLAG, RTF_PNGBNUMD, 0 }, + { "pngbnumk", CONTROL_FLAG, RTF_PNGBNUMK, 0 }, + { "pngbnuml", CONTROL_FLAG, RTF_PNGBNUML, 0 }, + { "pnhang", CONTROL_FLAG, RTF_PNHANG, 0 }, + { "pni", CONTROL_TOGGLE, RTF_PNI, 1 }, + { "pnindent", CONTROL_VALUE, RTF_PNINDENT, 0 }, + { "pniroha", CONTROL_FLAG, RTF_PNIROHA, 0 }, + { "pnirohad", CONTROL_FLAG, RTF_PNIROHAD, 0 }, + { "pnlcltr", CONTROL_FLAG, RTF_PNLCLTR, 0 }, + { "pnlcrm", CONTROL_FLAG, RTF_PNLCRM, 0 }, + { "pnlvl", CONTROL_VALUE, RTF_PNLVL, 0 }, + { "pnlvlblt", CONTROL_FLAG, RTF_PNLVLBLT, 0 }, + { "pnlvlbody", CONTROL_FLAG, RTF_PNLVLBODY, 0 }, + { "pnlvlcont", CONTROL_FLAG, RTF_PNLVLCONT, 0 }, + { "pnnumonce", CONTROL_FLAG, RTF_PNNUMONCE, 0 }, + { "pnord", CONTROL_FLAG, RTF_PNORD, 0 }, + { "pnordt", CONTROL_FLAG, RTF_PNORDT, 0 }, + { "pnprev", CONTROL_FLAG, RTF_PNPREV, 0 }, + { "pnqc", CONTROL_FLAG, RTF_PNQC, 0 }, + { "pnql", CONTROL_FLAG, RTF_PNQL, 0 }, + { "pnqr", CONTROL_FLAG, RTF_PNQR, 0 }, + { "pnrauth", CONTROL_VALUE, RTF_PNRAUTH, 0 }, + { "pnrdate", CONTROL_VALUE, RTF_PNRDATE, 0 }, + { "pnrestart", CONTROL_FLAG, RTF_PNRESTART, 0 }, + { "pnrnfc", CONTROL_VALUE, RTF_PNRNFC, 0 }, + { "pnrnot", CONTROL_FLAG, RTF_PNRNOT, 0 }, + { "pnrpnbr", CONTROL_VALUE, RTF_PNRPNBR, 0 }, + { "pnrrgb", CONTROL_VALUE, RTF_PNRRGB, 0 }, + { "pnrstart", CONTROL_VALUE, RTF_PNRSTART, 0 }, + { "pnrstop", CONTROL_VALUE, RTF_PNRSTOP, 0 }, + { "pnrxst", CONTROL_VALUE, RTF_PNRXST, 0 }, + { "pnscaps", CONTROL_TOGGLE, RTF_PNSCAPS, 1 }, + { "pnseclvl", CONTROL_DESTINATION, RTF_PNSECLVL, 0 }, + { "pnsp", CONTROL_VALUE, RTF_PNSP, 0 }, + { "pnstart", CONTROL_VALUE, RTF_PNSTART, 0 }, + { "pnstrike", CONTROL_TOGGLE, RTF_PNSTRIKE, 1 }, + { "pntext", CONTROL_DESTINATION, RTF_PNTEXT, 0 }, + { "pntxta", CONTROL_DESTINATION, RTF_PNTXTA, 0 }, + { "pntxtb", CONTROL_DESTINATION, RTF_PNTXTB, 0 }, + { "pnucltr", CONTROL_FLAG, RTF_PNUCLTR, 0 }, + { "pnucrm", CONTROL_FLAG, RTF_PNUCRM, 0 }, + { "pnul", CONTROL_TOGGLE, RTF_PNUL, 1 }, + { "pnuld", CONTROL_FLAG, RTF_PNULD, 0 }, + { "pnuldash", CONTROL_FLAG, RTF_PNULDASH, 0 }, + { "pnuldashd", CONTROL_FLAG, RTF_PNULDASHD, 0 }, + { "pnuldashdd", CONTROL_FLAG, RTF_PNULDASHDD, 0 }, + { "pnuldb", CONTROL_FLAG, RTF_PNULDB, 0 }, + { "pnulhair", CONTROL_FLAG, RTF_PNULHAIR, 0 }, + { "pnulnone", CONTROL_FLAG, RTF_PNULNONE, 0 }, + { "pnulth", CONTROL_FLAG, RTF_PNULTH, 0 }, + { "pnulw", CONTROL_FLAG, RTF_PNULW, 0 }, + { "pnulwave", CONTROL_FLAG, RTF_PNULWAVE, 0 }, + { "pnzodiac", CONTROL_FLAG, RTF_PNZODIAC, 0 }, + { "pnzodiacd", CONTROL_FLAG, RTF_PNZODIACD, 0 }, + { "pnzodiacl", CONTROL_FLAG, RTF_PNZODIACL, 0 }, + { "posnegx", CONTROL_VALUE, RTF_POSNEGX, 0 }, + { "posnegy", CONTROL_VALUE, RTF_POSNEGY, 0 }, + { "posx", CONTROL_VALUE, RTF_POSX, 0 }, + { "posxc", CONTROL_FLAG, RTF_POSXC, 0 }, + { "posxi", CONTROL_FLAG, RTF_POSXI, 0 }, + { "posxl", CONTROL_FLAG, RTF_POSXL, 0 }, + { "posxo", CONTROL_FLAG, RTF_POSXO, 0 }, + { "posxr", CONTROL_FLAG, RTF_POSXR, 0 }, + { "posy", CONTROL_VALUE, RTF_POSY, 0 }, + { "posyb", CONTROL_FLAG, RTF_POSYB, 0 }, + { "posyc", CONTROL_FLAG, RTF_POSYC, 0 }, + { "posyil", CONTROL_FLAG, RTF_POSYIL, 0 }, + { "posyin", CONTROL_FLAG, RTF_POSYIN, 0 }, + { "posyout", CONTROL_FLAG, RTF_POSYOUT, 0 }, + { "posyt", CONTROL_FLAG, RTF_POSYT, 0 }, + { "prauth", CONTROL_VALUE, RTF_PRAUTH, 0 }, + { "prcolbl", CONTROL_FLAG, RTF_PRCOLBL, 0 }, + { "prdate", CONTROL_VALUE, RTF_PRDATE, 0 }, + { "printdata", CONTROL_FLAG, RTF_PRINTDATA, 0 }, + { "printim", CONTROL_DESTINATION, RTF_PRINTIM, 0 }, + { "private", CONTROL_DESTINATION, RTF_PRIVATE, 0 }, + { "propname", CONTROL_DESTINATION, RTF_PROPNAME, 0 }, + { "proptype", CONTROL_VALUE, RTF_PROPTYPE, 0 }, + { "protect", CONTROL_TOGGLE, RTF_PROTECT, 1 }, + { "protend", CONTROL_DESTINATION, RTF_PROTEND, 0 }, + { "protlevel", CONTROL_VALUE, RTF_PROTLEVEL, 0 }, + { "protstart", CONTROL_DESTINATION, RTF_PROTSTART, 0 }, + { "protusertbl", CONTROL_DESTINATION, RTF_PROTUSERTBL, 0 }, + { "psover", CONTROL_FLAG, RTF_PSOVER, 0 }, + { "psz", CONTROL_VALUE, RTF_PSZ, 0 }, + { "ptabldot", CONTROL_FLAG, RTF_PTABLDOT, 0 }, + { "ptablmdot", CONTROL_FLAG, RTF_PTABLMDOT, 0 }, + { "ptablminus", CONTROL_FLAG, RTF_PTABLMINUS, 0 }, + { "ptablnone", CONTROL_FLAG, RTF_PTABLNONE, 0 }, + { "ptabluscore", CONTROL_FLAG, RTF_PTABLUSCORE, 0 }, + { "pubauto", CONTROL_FLAG, RTF_PUBAUTO, 0 }, + { "pvmrg", CONTROL_FLAG, RTF_PVMRG, 0 }, + { "pvpara", CONTROL_FLAG, RTF_PVPARA, 0 }, + { "pvpg", CONTROL_FLAG, RTF_PVPG, 0 }, + { "pwd", CONTROL_VALUE, RTF_PWD, 0 }, + { "pxe", CONTROL_DESTINATION, RTF_PXE, 0 }, + { "qc", CONTROL_FLAG, RTF_QC, 0 }, + { "qd", CONTROL_FLAG, RTF_QD, 0 }, + { "qj", CONTROL_FLAG, RTF_QJ, 0 }, + { "qk", CONTROL_VALUE, RTF_QK, 0 }, + { "ql", CONTROL_FLAG, RTF_QL, 0 }, + { "qmspace", CONTROL_SYMBOL, RTF_QMSPACE, 0 }, + { "qr", CONTROL_FLAG, RTF_QR, 0 }, + { "qt", CONTROL_FLAG, RTF_QT, 0 }, + { "rawclbgdkbdiag", CONTROL_FLAG, RTF_RAWCLBGDKBDIAG, 0 }, + { "rawclbgbdiag", CONTROL_FLAG, RTF_RAWCLBGBDIAG, 0 }, + { "rawclbgcross", CONTROL_FLAG, RTF_RAWCLBGCROSS, 0 }, + { "rawclbgdcross", CONTROL_FLAG, RTF_RAWCLBGDCROSS, 0 }, + { "rawclbgdkcross", CONTROL_FLAG, RTF_RAWCLBGDKCROSS, 0 }, + { "rawclbgdkdcross", CONTROL_FLAG, RTF_RAWCLBGDKDCROSS, 0 }, + { "rawclbgdkfdiag", CONTROL_FLAG, RTF_RAWCLBGDKFDIAG, 0 }, + { "rawclbgdkhor", CONTROL_FLAG, RTF_RAWCLBGDKHOR, 0 }, + { "rawclbgdkvert", CONTROL_FLAG, RTF_RAWCLBGDKVERT, 0 }, + { "rawclbgfdiag", CONTROL_FLAG, RTF_RAWCLBGFDIAG, 0 }, + { "rawclbghoriz", CONTROL_FLAG, RTF_RAWCLBGHORIZ, 0 }, + { "rawclbgvert", CONTROL_FLAG, RTF_RAWCLBGVERT, 0 }, + { "rdblquote", CONTROL_SYMBOL, RTF_RDBLQUOTE, 0 }, + { "readonlyrecommended", CONTROL_FLAG, RTF_READONLYRECOMMENDED, 0 }, + { "readprot", CONTROL_FLAG, RTF_READPROT, 0 }, + { "red", CONTROL_VALUE, RTF_RED, 0 }, + { "relyonvml", CONTROL_VALUE, RTF_RELYONVML, 0 }, + { "remdttm", CONTROL_FLAG, RTF_REMDTTM, 0 }, + { "rempersonalinfo", CONTROL_FLAG, RTF_REMPERSONALINFO, 0 }, + { "result", CONTROL_DESTINATION, RTF_RESULT, 0 }, + { "revauth", CONTROL_VALUE, RTF_REVAUTH, 0 }, + { "revauthdel", CONTROL_VALUE, RTF_REVAUTHDEL, 0 }, + { "revbar", CONTROL_VALUE, RTF_REVBAR, 3 }, + { "revdttm", CONTROL_VALUE, RTF_REVDTTM, 0 }, + { "revdttmdel", CONTROL_VALUE, RTF_REVDTTMDEL, 0 }, + { "revised", CONTROL_TOGGLE, RTF_REVISED, 1 }, + { "revisions", CONTROL_FLAG, RTF_REVISIONS, 0 }, + { "revprop", CONTROL_VALUE, RTF_REVPROP, 3 }, + { "revprot", CONTROL_FLAG, RTF_REVPROT, 0 }, + { "revtbl", CONTROL_DESTINATION, RTF_REVTBL, 0 }, + { "revtim", CONTROL_DESTINATION, RTF_REVTIM, 0 }, + { "ri", CONTROL_VALUE, RTF_RI, 0 }, + { "rin", CONTROL_VALUE, RTF_RIN, 0 }, + { "row", CONTROL_SYMBOL, RTF_ROW, 0 }, + { "rquote", CONTROL_SYMBOL, RTF_RQUOTE, 0 }, + { "rsid", CONTROL_VALUE, RTF_RSID, 0 }, + { "rsidroot", CONTROL_VALUE, RTF_RSIDROOT, 0 }, + { "rsidtbl", CONTROL_DESTINATION, RTF_RSIDTBL, 0 }, + { "rsltbmp", CONTROL_FLAG, RTF_RSLTBMP, 0 }, + { "rslthtml", CONTROL_FLAG, RTF_RSLTHTML, 0 }, + { "rsltmerge", CONTROL_FLAG, RTF_RSLTMERGE, 0 }, + { "rsltpict", CONTROL_FLAG, RTF_RSLTPICT, 0 }, + { "rsltrtf", CONTROL_FLAG, RTF_RSLTRTF, 0 }, + { "rslttxt", CONTROL_FLAG, RTF_RSLTTXT, 0 }, + { "rtf", CONTROL_DESTINATION, RTF_RTF, 0 }, + { "rtlch", CONTROL_FLAG, RTF_RTLCH, 0 }, + { "rtldoc", CONTROL_FLAG, RTF_RTLDOC, 0 }, + { "rtlgutter", CONTROL_FLAG, RTF_RTLGUTTER, 0 }, + { "rtlmark", CONTROL_SYMBOL, RTF_RTLMARK, 0 }, + { "rtlpar", CONTROL_FLAG, RTF_RTLPAR, 0 }, + { "rtlrow", CONTROL_FLAG, RTF_RTLROW, 0 }, + { "rtlsect", CONTROL_FLAG, RTF_RTLSECT, 0 }, + { "rxe", CONTROL_DESTINATION, RTF_RXE, 0 }, + { "s", CONTROL_VALUE, RTF_S, 0 }, + { "sa", CONTROL_VALUE, RTF_SA, 0 }, + { "saauto", CONTROL_TOGGLE, RTF_SAAUTO, 1 }, + { "saftnnalc", CONTROL_FLAG, RTF_SAFTNNALC, 0 }, + { "saftnnar", CONTROL_FLAG, RTF_SAFTNNAR, 0 }, + { "saftnnauc", CONTROL_FLAG, RTF_SAFTNNAUC, 0 }, + { "saftnnchi", CONTROL_FLAG, RTF_SAFTNNCHI, 0 }, + { "saftnnchosung", CONTROL_FLAG, RTF_SAFTNNCHOSUNG, 0 }, + { "saftnncnum", CONTROL_FLAG, RTF_SAFTNNCNUM, 0 }, + { "saftnndbar", CONTROL_FLAG, RTF_SAFTNNDBAR, 0 }, + { "saftnndbnum", CONTROL_FLAG, RTF_SAFTNNDBNUM, 0 }, + { "saftnndbnumd", CONTROL_FLAG, RTF_SAFTNNDBNUMD, 0 }, + { "saftnndbnumk", CONTROL_FLAG, RTF_SAFTNNDBNUMK, 0 }, + { "saftnndbnumt", CONTROL_FLAG, RTF_SAFTNNDBNUMT, 0 }, + { "saftnnganada", CONTROL_FLAG, RTF_SAFTNNGANADA, 0 }, + { "saftnngbnum", CONTROL_FLAG, RTF_SAFTNNGBNUM, 0 }, + { "saftnngbnumd", CONTROL_FLAG, RTF_SAFTNNGBNUMD, 0 }, + { "saftnngbnumk", CONTROL_FLAG, RTF_SAFTNNGBNUMK, 0 }, + { "saftnngbnuml", CONTROL_FLAG, RTF_SAFTNNGBNUML, 0 }, + { "saftnnrlc", CONTROL_FLAG, RTF_SAFTNNRLC, 0 }, + { "saftnnruc", CONTROL_FLAG, RTF_SAFTNNRUC, 0 }, + { "saftnnzodiac", CONTROL_FLAG, RTF_SAFTNNZODIAC, 0 }, + { "saftnnzodiacd", CONTROL_FLAG, RTF_SAFTNNZODIACD, 0 }, + { "saftnnzodiacl", CONTROL_FLAG, RTF_SAFTNNZODIACL, 0 }, + { "saftnrestart", CONTROL_FLAG, RTF_SAFTNRESTART, 0 }, + { "saftnrstcont", CONTROL_FLAG, RTF_SAFTNRSTCONT, 0 }, + { "saftnstart", CONTROL_VALUE, RTF_SAFTNSTART, 1 }, + { "sautoupd", CONTROL_FLAG, RTF_SAUTOUPD, 0 }, + { "saveinvalidxml", CONTROL_FLAG, RTF_SAVEINVALIDXML, 0 }, + { "saveprevpict", CONTROL_FLAG, RTF_SAVEPREVPICT, 0 }, + { "sb", CONTROL_VALUE, RTF_SB, 0 }, + { "sbasedon", CONTROL_VALUE, RTF_SBASEDON, 222 }, + { "sbauto", CONTROL_TOGGLE, RTF_SBAUTO, 1 }, + { "sbkcol", CONTROL_FLAG, RTF_SBKCOL, 0 }, + { "sbkeven", CONTROL_FLAG, RTF_SBKEVEN, 0 }, + { "sbknone", CONTROL_FLAG, RTF_SBKNONE, 0 }, + { "sbkodd", CONTROL_FLAG, RTF_SBKODD, 0 }, + { "sbkpage", CONTROL_FLAG, RTF_SBKPAGE, 0 }, + { "sbys", CONTROL_FLAG, RTF_SBYS, 0 }, + { "scaps", CONTROL_TOGGLE, RTF_SCAPS, 1 }, + { "scompose", CONTROL_FLAG, RTF_SCOMPOSE, 0 }, + { "sec", CONTROL_VALUE, RTF_SEC, 0 }, + { "sect", CONTROL_SYMBOL, RTF_SECT, 0 }, + { "sectd", CONTROL_FLAG, RTF_SECTD, 0 }, + { "sectdefaultcl", CONTROL_FLAG, RTF_SECTDEFAULTCL, 0 }, + { "sectexpand", CONTROL_VALUE, RTF_SECTEXPAND, 0 }, + { "sectlinegrid", CONTROL_VALUE, RTF_SECTLINEGRID, 0 }, + { "sectnum", CONTROL_SYMBOL, RTF_SECTNUM, 0 }, + { "sectrsid", CONTROL_VALUE, RTF_SECTRSID, 0 }, + { "sectspecifycl", CONTROL_FLAG, RTF_SECTSPECIFYCL, 0 }, + { "sectspecifygenN", CONTROL_FLAG, RTF_SECTSPECIFYGENN, 0 }, + { "sectspecifyl", CONTROL_FLAG, RTF_SECTSPECIFYL, 0 }, + { "sectunlocked", CONTROL_FLAG, RTF_SECTUNLOCKED, 0 }, + { "sftnbj", CONTROL_FLAG, RTF_SFTNBJ, 0 }, + { "sftnnalc", CONTROL_FLAG, RTF_SFTNNALC, 0 }, + { "sftnnar", CONTROL_FLAG, RTF_SFTNNAR, 0 }, + { "sftnnauc", CONTROL_FLAG, RTF_SFTNNAUC, 0 }, + { "sftnnchi", CONTROL_FLAG, RTF_SFTNNCHI, 0 }, + { "sftnnchosung", CONTROL_FLAG, RTF_SFTNNCHOSUNG, 0 }, + { "sftnncnum", CONTROL_FLAG, RTF_SFTNNCNUM, 0 }, + { "sftnndbar", CONTROL_FLAG, RTF_SFTNNDBAR, 0 }, + { "sftnndbnum", CONTROL_FLAG, RTF_SFTNNDBNUM, 0 }, + { "sftnndbnumd", CONTROL_FLAG, RTF_SFTNNDBNUMD, 0 }, + { "sftnndbnumk", CONTROL_FLAG, RTF_SFTNNDBNUMK, 0 }, + { "sftnndbnumt", CONTROL_FLAG, RTF_SFTNNDBNUMT, 0 }, + { "sftnnganada", CONTROL_FLAG, RTF_SFTNNGANADA, 0 }, + { "sftnngbnum", CONTROL_FLAG, RTF_SFTNNGBNUM, 0 }, + { "sftnngbnumd", CONTROL_FLAG, RTF_SFTNNGBNUMD, 0 }, + { "sftnngbnumk", CONTROL_FLAG, RTF_SFTNNGBNUMK, 0 }, + { "sftnngbnuml", CONTROL_FLAG, RTF_SFTNNGBNUML, 0 }, + { "sftnnrlc", CONTROL_FLAG, RTF_SFTNNRLC, 0 }, + { "sftnnruc", CONTROL_FLAG, RTF_SFTNNRUC, 0 }, + { "sftnnzodiac", CONTROL_FLAG, RTF_SFTNNZODIAC, 0 }, + { "sftnnzodiacd", CONTROL_FLAG, RTF_SFTNNZODIACD, 0 }, + { "sftnnzodiacl", CONTROL_FLAG, RTF_SFTNNZODIACL, 0 }, + { "sftnrestart", CONTROL_FLAG, RTF_SFTNRESTART, 0 }, + { "sftnrstcont", CONTROL_FLAG, RTF_SFTNRSTCONT, 0 }, + { "sftnrstpg", CONTROL_FLAG, RTF_SFTNRSTPG, 0 }, + { "sftnstart", CONTROL_VALUE, RTF_SFTNSTART, 1 }, + { "sftntj", CONTROL_FLAG, RTF_SFTNTJ, 0 }, + { "shad", CONTROL_TOGGLE, RTF_SHAD, 1 }, + { "shading", CONTROL_VALUE, RTF_SHADING, 0 }, + { "shidden", CONTROL_FLAG, RTF_SHIDDEN, 0 }, + { "shift", CONTROL_FLAG, RTF_SHIFT, 0 }, + { "showplaceholdtext", CONTROL_VALUE, RTF_SHOWPLACEHOLDTEXT, 0 }, + { "showxmlerrors", CONTROL_VALUE, RTF_SHOWXMLERRORS, 0 }, + { "shp", CONTROL_DESTINATION, RTF_SHP, 0 }, + { "shpbottom", CONTROL_VALUE, RTF_SHPBOTTOM, 0 }, + { "shpbxcolumn", CONTROL_FLAG, RTF_SHPBXCOLUMN, 0 }, + { "shpbxignore", CONTROL_FLAG, RTF_SHPBXIGNORE, 0 }, + { "shpbxmargin", CONTROL_FLAG, RTF_SHPBXMARGIN, 0 }, + { "shpbxpage", CONTROL_FLAG, RTF_SHPBXPAGE, 0 }, + { "shpbyignore", CONTROL_FLAG, RTF_SHPBYIGNORE, 0 }, + { "shpbymargin", CONTROL_FLAG, RTF_SHPBYMARGIN, 0 }, + { "shpbypage", CONTROL_FLAG, RTF_SHPBYPAGE, 0 }, + { "shpbypara", CONTROL_FLAG, RTF_SHPBYPARA, 0 }, + { "shpfblwtxt", CONTROL_VALUE, RTF_SHPFBLWTXT, 0 }, + { "shpfhdr", CONTROL_VALUE, RTF_SHPFHDR, 0 }, + { "shpgrp", CONTROL_DESTINATION, RTF_SHPGRP, 0 }, + { "shpinst", CONTROL_DESTINATION, RTF_SHPINST, 0 }, + { "shpleft", CONTROL_VALUE, RTF_SHPLEFT, 0 }, + { "shplid", CONTROL_VALUE, RTF_SHPLID, 0 }, + { "shplockanchor", CONTROL_FLAG, RTF_SHPLOCKANCHOR, 0 }, + { "shppict", CONTROL_DESTINATION, RTF_SHPPICT, 0 }, + { "shpright", CONTROL_VALUE, RTF_SHPRIGHT, 0 }, + { "shprslt", CONTROL_DESTINATION, RTF_SHPRSLT, 0 }, + { "shptop", CONTROL_VALUE, RTF_SHPTOP, 0 }, + { "shptxt", CONTROL_DESTINATION, RTF_SHPTXT, 0 }, + { "shpwrk", CONTROL_VALUE, RTF_SHPWRK, 0 }, + { "shpwr", CONTROL_VALUE, RTF_SHPWR, 0 }, + { "shpz", CONTROL_VALUE, RTF_SHPZ, 0 }, + { "sl", CONTROL_VALUE, RTF_SL, 0 }, + { "slink", CONTROL_VALUE, RTF_SLINK, 0 }, + { "slmult", CONTROL_VALUE, RTF_SLMULT, 0 }, + { "slocked", CONTROL_FLAG, RTF_SLOCKED, 0 }, + { "sn", CONTROL_DESTINATION, RTF_SN, 0 }, + { "snaptogridincell", CONTROL_FLAG, RTF_SNAPTOGRIDINCELL, 0 }, + { "snext", CONTROL_VALUE, RTF_SNEXT, 0 }, + { "softcol", CONTROL_FLAG, RTF_SOFTCOL, 0 }, + { "softlheight", CONTROL_VALUE, RTF_SOFTLHEIGHT, 0 }, + { "softline", CONTROL_FLAG, RTF_SOFTLINE, 0 }, + { "softpage", CONTROL_FLAG, RTF_SOFTPAGE, 0 }, + { "sp", CONTROL_DESTINATION, RTF_SP, 0 }, + { "spersonal", CONTROL_FLAG, RTF_SPERSONAL, 0 }, + { "spltpgpar", CONTROL_FLAG, RTF_SPLTPGPAR, 0 }, + { "splytwnine", CONTROL_FLAG, RTF_SPLYTWNINE, 0 }, + { "spriority", CONTROL_VALUE, RTF_SPRIORITY, 0 }, + { "sprsbsp", CONTROL_FLAG, RTF_SPRSBSP, 0 }, + { "sprslnsp", CONTROL_FLAG, RTF_SPRSLNSP, 0 }, + { "sprsspbf", CONTROL_FLAG, RTF_SPRSSPBF, 0 }, + { "sprstsm", CONTROL_FLAG, RTF_SPRSTSM, 0 }, + { "sprstsp", CONTROL_FLAG, RTF_SPRSTSP, 0 }, + { "spv", CONTROL_FLAG, RTF_SPV, 0 }, + { "sqformat", CONTROL_FLAG, RTF_SQFORMAT, 0 }, + { "srauth", CONTROL_VALUE, RTF_SRAUTH, 0 }, + { "srdate", CONTROL_VALUE, RTF_SRDATE, 0 }, + { "sreply", CONTROL_FLAG, RTF_SREPLY, 0 }, + { "ssemihidden", CONTROL_VALUE, RTF_SSEMIHIDDEN, 0 }, + { "staticval", CONTROL_DESTINATION, RTF_STATICVAL, 0 }, + { "stextflow", CONTROL_VALUE, RTF_STEXTFLOW, 0 }, + { "strike", CONTROL_TOGGLE, RTF_STRIKE, 1 }, + { "striked", CONTROL_TOGGLE, RTF_STRIKED, 1 }, + { "stshfbi", CONTROL_VALUE, RTF_STSHFBI, 0 }, + { "stshfdbch", CONTROL_VALUE, RTF_STSHFDBCH, 0 }, + { "stshfhich", CONTROL_VALUE, RTF_STSHFHICH, 0 }, + { "stshfloch", CONTROL_VALUE, RTF_STSHFLOCH, 0 }, + { "stylelock", CONTROL_FLAG, RTF_STYLELOCK, 0 }, + { "stylelockbackcomp", CONTROL_FLAG, RTF_STYLELOCKBACKCOMP, 0 }, + { "stylelockenforced", CONTROL_FLAG, RTF_STYLELOCKENFORCED, 0 }, + { "stylelockqfset", CONTROL_FLAG, RTF_STYLELOCKQFSET, 0 }, + { "stylelocktheme", CONTROL_FLAG, RTF_STYLELOCKTHEME, 0 }, + { "stylesheet", CONTROL_DESTINATION, RTF_STYLESHEET, 0 }, + { "stylesortmethod", CONTROL_VALUE, RTF_STYLESORTMETHOD, 1 }, + { "styrsid", CONTROL_VALUE, RTF_STYRSID, 0 }, + { "sub", CONTROL_FLAG, RTF_SUB, 0 }, + { "subdocument", CONTROL_VALUE, RTF_SUBDOCUMENT, 0 }, + { "subfontbysize", CONTROL_FLAG, RTF_SUBFONTBYSIZE, 0 }, + { "subject", CONTROL_DESTINATION, RTF_SUBJECT, 0 }, + { "sunhideused", CONTROL_VALUE, RTF_SUNHIDEUSED, 0 }, + { "super", CONTROL_FLAG, RTF_SUPER, 0 }, + { "sv", CONTROL_DESTINATION, RTF_SV, 0 }, + { "svb", CONTROL_DESTINATION, RTF_SVB, 0 }, + { "swpbdr", CONTROL_FLAG, RTF_SWPBDR, 0 }, + { "tab", CONTROL_SYMBOL, RTF_TAB, 0 }, + { "tabsnoovrlp", CONTROL_FLAG, RTF_TABSNOOVRLP, 0 }, + { "taprtl", CONTROL_FLAG, RTF_TAPRTL, 0 }, + { "tb", CONTROL_VALUE, RTF_TB, 0 }, + { "tblind", CONTROL_VALUE, RTF_TBLIND, 0 }, + { "tblindtype", CONTROL_VALUE, RTF_TBLINDTYPE, 0 }, + { "tbllkbestfit", CONTROL_FLAG, RTF_TBLLKBESTFIT, 0 }, + { "tbllkborder", CONTROL_FLAG, RTF_TBLLKBORDER, 0 }, + { "tbllkcolor", CONTROL_FLAG, RTF_TBLLKCOLOR, 0 }, + { "tbllkfont", CONTROL_FLAG, RTF_TBLLKFONT, 0 }, + { "tbllkhdrcols", CONTROL_FLAG, RTF_TBLLKHDRCOLS, 0 }, + { "tbllkhdrrows", CONTROL_FLAG, RTF_TBLLKHDRROWS, 0 }, + { "tbllklastcol", CONTROL_FLAG, RTF_TBLLKLASTCOL, 0 }, + { "tbllklastrow", CONTROL_FLAG, RTF_TBLLKLASTROW, 0 }, + { "tbllknocolband", CONTROL_FLAG, RTF_TBLLKNOCOLBAND, 0 }, + { "tbllknorowband", CONTROL_FLAG, RTF_TBLLKNOROWBAND, 0 }, + { "tbllkshading", CONTROL_FLAG, RTF_TBLLKSHADING, 0 }, + { "tblrsid", CONTROL_VALUE, RTF_TBLRSID, 0 }, + { "tc", CONTROL_DESTINATION, RTF_TC, 0 }, + { "tcelld", CONTROL_FLAG, RTF_TCELLD, 0 }, + { "tcf", CONTROL_VALUE, RTF_TCF, 67 }, + { "tcl", CONTROL_VALUE, RTF_TCL, 0 }, + { "tcn", CONTROL_FLAG, RTF_TCN, 0 }, + { "tdfrmtxtBottom", CONTROL_VALUE, RTF_TDFRMTXTBOTTOM, 0 }, + { "tdfrmtxtLeft", CONTROL_VALUE, RTF_TDFRMTXTLEFT, 0 }, + { "tdfrmtxtRight", CONTROL_VALUE, RTF_TDFRMTXTRIGHT, 0 }, + { "tdfrmtxtTop", CONTROL_VALUE, RTF_TDFRMTXTTOP, 0 }, + { "template", CONTROL_DESTINATION, RTF_TEMPLATE, 0 }, + { "themedata", CONTROL_DESTINATION, RTF_THEMEDATA, 0 }, + { "themelang", CONTROL_VALUE, RTF_THEMELANG, 0 }, + { "themelangcs", CONTROL_VALUE, RTF_THEMELANGCS, 0 }, + { "themelangfe", CONTROL_VALUE, RTF_THEMELANGFE, 0 }, + { "time", CONTROL_FLAG, RTF_TIME, 0 }, + { "title", CONTROL_DESTINATION, RTF_TITLE, 0 }, + { "titlepg", CONTROL_FLAG, RTF_TITLEPG, 0 }, + { "tldot", CONTROL_FLAG, RTF_TLDOT, 0 }, + { "tleq", CONTROL_FLAG, RTF_TLEQ, 0 }, + { "tlhyph", CONTROL_FLAG, RTF_TLHYPH, 0 }, + { "tlmdot", CONTROL_FLAG, RTF_TLMDOT, 0 }, + { "tlth", CONTROL_FLAG, RTF_TLTH, 0 }, + { "tlul", CONTROL_FLAG, RTF_TLUL, 0 }, + { "toplinepunct", CONTROL_FLAG, RTF_TOPLINEPUNCT, 0 }, + { "tphcol", CONTROL_FLAG, RTF_TPHCOL, 0 }, + { "tphmrg", CONTROL_FLAG, RTF_TPHMRG, 0 }, + { "tphpg", CONTROL_FLAG, RTF_TPHPG, 0 }, + { "tposnegx", CONTROL_VALUE, RTF_TPOSNEGX, 0 }, + { "tposnegy", CONTROL_VALUE, RTF_TPOSNEGY, 0 }, + { "tposxc", CONTROL_FLAG, RTF_TPOSXC, 0 }, + { "tposxi", CONTROL_FLAG, RTF_TPOSXI, 0 }, + { "tposxl", CONTROL_FLAG, RTF_TPOSXL, 0 }, + { "tposx", CONTROL_VALUE, RTF_TPOSX, 0 }, + { "tposxo", CONTROL_FLAG, RTF_TPOSXO, 0 }, + { "tposxr", CONTROL_FLAG, RTF_TPOSXR, 0 }, + { "tposy", CONTROL_VALUE, RTF_TPOSY, 0 }, + { "tposyb", CONTROL_FLAG, RTF_TPOSYB, 0 }, + { "tposyc", CONTROL_FLAG, RTF_TPOSYC, 0 }, + { "tposyil", CONTROL_FLAG, RTF_TPOSYIL, 0 }, + { "tposyin", CONTROL_FLAG, RTF_TPOSYIN, 0 }, + { "tposyout", CONTROL_FLAG, RTF_TPOSYOUT, 0 }, + { "tposyt", CONTROL_FLAG, RTF_TPOSYT, 0 }, + { "tpvmrg", CONTROL_FLAG, RTF_TPVMRG, 0 }, + { "tpvpara", CONTROL_FLAG, RTF_TPVPARA, 0 }, + { "tpvpg", CONTROL_FLAG, RTF_TPVPG, 0 }, + { "tqc", CONTROL_FLAG, RTF_TQC, 0 }, + { "tqdec", CONTROL_FLAG, RTF_TQDEC, 0 }, + { "tqr", CONTROL_FLAG, RTF_TQR, 0 }, + { "trackformatting", CONTROL_VALUE, RTF_TRACKFORMATTING, 0 }, + { "trackmoves", CONTROL_VALUE, RTF_TRACKMOVES, 0 }, + { "transmf", CONTROL_FLAG, RTF_TRANSMF, 0 }, + { "trauth", CONTROL_VALUE, RTF_TRAUTH, 0 }, + { "trautofit", CONTROL_TOGGLE, RTF_TRAUTOFIT, 1 }, + { "trbgbdiag", CONTROL_FLAG, RTF_TRBGBDIAG, 0 }, + { "trbgcross", CONTROL_FLAG, RTF_TRBGCROSS, 0 }, + { "trbgdcross", CONTROL_FLAG, RTF_TRBGDCROSS, 0 }, + { "trbgdkbdiag", CONTROL_FLAG, RTF_TRBGDKBDIAG, 0 }, + { "trbgdkcross", CONTROL_FLAG, RTF_TRBGDKCROSS, 0 }, + { "trbgdkdcross", CONTROL_FLAG, RTF_TRBGDKDCROSS, 0 }, + { "trbgdkfdiag", CONTROL_FLAG, RTF_TRBGDKFDIAG, 0 }, + { "trbgdkhor", CONTROL_FLAG, RTF_TRBGDKHOR, 0 }, + { "trbgdkvert", CONTROL_FLAG, RTF_TRBGDKVERT, 0 }, + { "trbgfdiag", CONTROL_FLAG, RTF_TRBGFDIAG, 0 }, + { "trbghoriz", CONTROL_FLAG, RTF_TRBGHORIZ, 0 }, + { "trbgvert", CONTROL_FLAG, RTF_TRBGVERT, 0 }, + { "trbrdrb", CONTROL_FLAG, RTF_TRBRDRB, 0 }, + { "trbrdrh", CONTROL_FLAG, RTF_TRBRDRH, 0 }, + { "trbrdrl", CONTROL_FLAG, RTF_TRBRDRL, 0 }, + { "trbrdrr", CONTROL_FLAG, RTF_TRBRDRR, 0 }, + { "trbrdrt", CONTROL_FLAG, RTF_TRBRDRT, 0 }, + { "trbrdrv", CONTROL_FLAG, RTF_TRBRDRV, 0 }, + { "trcbpat", CONTROL_VALUE, RTF_TRCBPAT, 0 }, + { "trcfpat", CONTROL_VALUE, RTF_TRCFPAT, 0 }, + { "trdate", CONTROL_VALUE, RTF_TRDATE, 0 }, + { "trftsWidthA", CONTROL_VALUE, RTF_TRFTSWIDTHA, 0 }, + { "trftsWidthB", CONTROL_VALUE, RTF_TRFTSWIDTHB, 0 }, + { "trftsWidth", CONTROL_VALUE, RTF_TRFTSWIDTH, 0 }, + { "trgaph", CONTROL_VALUE, RTF_TRGAPH, 0 }, + { "trhdr", CONTROL_FLAG, RTF_TRHDR, 0 }, + { "trkeep", CONTROL_FLAG, RTF_TRKEEP, 0 }, + { "trkeepfollow", CONTROL_FLAG, RTF_TRKEEPFOLLOW, 0 }, + { "trleft", CONTROL_VALUE, RTF_TRLEFT, 0 }, + { "trowd", CONTROL_FLAG, RTF_TROWD, 0 }, + { "trpaddb", CONTROL_VALUE, RTF_TRPADDB, 0 }, + { "trpaddfb", CONTROL_VALUE, RTF_TRPADDFB, 0 }, + { "trpaddfl", CONTROL_VALUE, RTF_TRPADDFL, 0 }, + { "trpaddfr", CONTROL_VALUE, RTF_TRPADDFR, 0 }, + { "trpaddft", CONTROL_VALUE, RTF_TRPADDFT, 0 }, + { "trpaddl", CONTROL_VALUE, RTF_TRPADDL, 0 }, + { "trpaddr", CONTROL_VALUE, RTF_TRPADDR, 0 }, + { "trpaddt", CONTROL_VALUE, RTF_TRPADDT, 0 }, + { "trpadob", CONTROL_VALUE, RTF_TRPADOB, 0 }, + { "trpadofb", CONTROL_VALUE, RTF_TRPADOFB, 0 }, + { "trpadofl", CONTROL_VALUE, RTF_TRPADOFL, 0 }, + { "trpadofr", CONTROL_VALUE, RTF_TRPADOFR, 0 }, + { "trpadoft", CONTROL_VALUE, RTF_TRPADOFT, 0 }, + { "trpadol", CONTROL_VALUE, RTF_TRPADOL, 0 }, + { "trpador", CONTROL_VALUE, RTF_TRPADOR, 0 }, + { "trpadot", CONTROL_VALUE, RTF_TRPADOT, 0 }, + { "trpat", CONTROL_VALUE, RTF_TRPAT, 0 }, + { "trqc", CONTROL_FLAG, RTF_TRQC, 0 }, + { "trql", CONTROL_FLAG, RTF_TRQL, 0 }, + { "trqr", CONTROL_FLAG, RTF_TRQR, 0 }, + { "trrh", CONTROL_VALUE, RTF_TRRH, 0 }, + { "trshdng", CONTROL_VALUE, RTF_TRSHDNG, 0 }, + { "trspdb", CONTROL_VALUE, RTF_TRSPDB, 0 }, + { "trspdfb", CONTROL_VALUE, RTF_TRSPDFB, 0 }, + { "trspdfl", CONTROL_VALUE, RTF_TRSPDFL, 0 }, + { "trspdfr", CONTROL_VALUE, RTF_TRSPDFR, 0 }, + { "trspdft", CONTROL_VALUE, RTF_TRSPDFT, 0 }, + { "trspdl", CONTROL_VALUE, RTF_TRSPDL, 0 }, + { "trspdr", CONTROL_VALUE, RTF_TRSPDR, 0 }, + { "trspdt", CONTROL_VALUE, RTF_TRSPDT, 0 }, + { "trspob", CONTROL_VALUE, RTF_TRSPOB, 0 }, + { "trspofb", CONTROL_VALUE, RTF_TRSPOFB, 0 }, + { "trspofl", CONTROL_VALUE, RTF_TRSPOFL, 0 }, + { "trspofr", CONTROL_VALUE, RTF_TRSPOFR, 0 }, + { "trspoft", CONTROL_VALUE, RTF_TRSPOFT, 0 }, + { "trspol", CONTROL_VALUE, RTF_TRSPOL, 0 }, + { "trspor", CONTROL_VALUE, RTF_TRSPOR, 0 }, + { "trspot", CONTROL_VALUE, RTF_TRSPOT, 0 }, + { "truncatefontheight", CONTROL_FLAG, RTF_TRUNCATEFONTHEIGHT, 0 }, + { "truncex", CONTROL_FLAG, RTF_TRUNCEX, 0 }, + { "trwWidthA", CONTROL_VALUE, RTF_TRWWIDTHA, 0 }, + { "trwWidthB", CONTROL_VALUE, RTF_TRWWIDTHB, 0 }, + { "trwWidth", CONTROL_VALUE, RTF_TRWWIDTH, 0 }, + { "ts", CONTROL_VALUE, RTF_TS, 0 }, + { "tsbgbdiag", CONTROL_FLAG, RTF_TSBGBDIAG, 0 }, + { "tsbgcross", CONTROL_FLAG, RTF_TSBGCROSS, 0 }, + { "tsbgdcross", CONTROL_FLAG, RTF_TSBGDCROSS, 0 }, + { "tsbgdkbdiag", CONTROL_FLAG, RTF_TSBGDKBDIAG, 0 }, + { "tsbgdkcross", CONTROL_FLAG, RTF_TSBGDKCROSS, 0 }, + { "tsbgdkdcross", CONTROL_FLAG, RTF_TSBGDKDCROSS, 0 }, + { "tsbgdkfdiag", CONTROL_FLAG, RTF_TSBGDKFDIAG, 0 }, + { "tsbgdkhor", CONTROL_FLAG, RTF_TSBGDKHOR, 0 }, + { "tsbgdkvert", CONTROL_FLAG, RTF_TSBGDKVERT, 0 }, + { "tsbgfdiag", CONTROL_FLAG, RTF_TSBGFDIAG, 0 }, + { "tsbghoriz", CONTROL_FLAG, RTF_TSBGHORIZ, 0 }, + { "tsbgvert", CONTROL_FLAG, RTF_TSBGVERT, 0 }, + { "tsbrdrb", CONTROL_FLAG, RTF_TSBRDRB, 0 }, + { "tsbrdrdgl", CONTROL_FLAG, RTF_TSBRDRDGL, 0 }, + { "tsbrdrdgr", CONTROL_FLAG, RTF_TSBRDRDGR, 0 }, + { "tsbrdrh", CONTROL_FLAG, RTF_TSBRDRH, 0 }, + { "tsbrdrl", CONTROL_FLAG, RTF_TSBRDRL, 0 }, + { "tsbrdrr", CONTROL_FLAG, RTF_TSBRDRR, 0 }, + { "tsbrdrt", CONTROL_FLAG, RTF_TSBRDRT, 0 }, + { "tsbrdrv", CONTROL_FLAG, RTF_TSBRDRV, 0 }, + { "tscbandhorzeven", CONTROL_FLAG, RTF_TSCBANDHORZEVEN, 0 }, + { "tscbandhorzodd", CONTROL_FLAG, RTF_TSCBANDHORZODD, 0 }, + { "tscbandsh", CONTROL_VALUE, RTF_TSCBANDSH, 0 }, + { "tscbandsv", CONTROL_VALUE, RTF_TSCBANDSV, 0 }, + { "tscbandverteven", CONTROL_FLAG, RTF_TSCBANDVERTEVEN, 0 }, + { "tscbandvertodd", CONTROL_FLAG, RTF_TSCBANDVERTODD, 0 }, + { "tscellcbpat", CONTROL_VALUE, RTF_TSCELLCBPAT, 0 }, + { "tscellcfpat", CONTROL_VALUE, RTF_TSCELLCFPAT, 0 }, + { "tscellpaddb", CONTROL_VALUE, RTF_TSCELLPADDB, 0 }, + { "tscellpaddfb", CONTROL_VALUE, RTF_TSCELLPADDFB, 0 }, + { "tscellpaddfl", CONTROL_VALUE, RTF_TSCELLPADDFL, 0 }, + { "tscellpaddfr", CONTROL_VALUE, RTF_TSCELLPADDFR, 0 }, + { "tscellpaddft", CONTROL_VALUE, RTF_TSCELLPADDFT, 0 }, + { "tscellpaddl", CONTROL_VALUE, RTF_TSCELLPADDL, 0 }, + { "tscellpaddr", CONTROL_VALUE, RTF_TSCELLPADDR, 0 }, + { "tscellpaddt", CONTROL_VALUE, RTF_TSCELLPADDT, 0 }, + { "tscellpct", CONTROL_VALUE, RTF_TSCELLPCT, 0 }, + { "tscellwidth", CONTROL_VALUE, RTF_TSCELLWIDTH, 0 }, + { "tscellwidthfts", CONTROL_VALUE, RTF_TSCELLWIDTHFTS, 0 }, + { "tscfirstcol", CONTROL_FLAG, RTF_TSCFIRSTCOL, 0 }, + { "tscfirstrow", CONTROL_FLAG, RTF_TSCFIRSTROW, 0 }, + { "tsclastcol", CONTROL_FLAG, RTF_TSCLASTCOL, 0 }, + { "tsclastrow", CONTROL_FLAG, RTF_TSCLASTROW, 0 }, + { "tscnecell", CONTROL_FLAG, RTF_TSCNECELL, 0 }, + { "tscnwcell", CONTROL_FLAG, RTF_TSCNWCELL, 0 }, + { "tscsecell", CONTROL_FLAG, RTF_TSCSECELL, 0 }, + { "tscswcell", CONTROL_FLAG, RTF_TSCSWCELL, 0 }, + { "tsd", CONTROL_FLAG, RTF_TSD, 0 }, + { "tsnowrap", CONTROL_FLAG, RTF_TSNOWRAP, 0 }, + { "tsrowd", CONTROL_FLAG, RTF_TSROWD, 0 }, + { "tsvertalb", CONTROL_FLAG, RTF_TSVERTALB, 0 }, + { "tsvertalc", CONTROL_FLAG, RTF_TSVERTALC, 0 }, + { "tsvertalt", CONTROL_FLAG, RTF_TSVERTALT, 0 }, + { "twoinone", CONTROL_VALUE, RTF_TWOINONE, 0 }, + { "twoonone", CONTROL_FLAG, RTF_TWOONONE, 0 }, + { "tx", CONTROL_VALUE, RTF_TX, 0 }, + { "txbxtwalways", CONTROL_FLAG, RTF_TXBXTWALWAYS, 0 }, + { "txbxtwfirst", CONTROL_FLAG, RTF_TXBXTWFIRST, 0 }, + { "txbxtwfirstlast", CONTROL_FLAG, RTF_TXBXTWFIRSTLAST, 0 }, + { "txbxtwlast", CONTROL_FLAG, RTF_TXBXTWLAST, 0 }, + { "txbxtwno", CONTROL_FLAG, RTF_TXBXTWNO, 0 }, + { "txe", CONTROL_DESTINATION, RTF_TXE, 0 }, + { "u", CONTROL_VALUE, RTF_U, 0 }, + { "uc", CONTROL_VALUE, RTF_UC, 1 }, + { "ud", CONTROL_DESTINATION, RTF_UD, 0 }, + { "ul", CONTROL_TOGGLE, RTF_UL, 1 }, + { "ulc", CONTROL_VALUE, RTF_ULC, 0 }, + { "uld", CONTROL_FLAG, RTF_ULD, 0 }, + { "uldash", CONTROL_TOGGLE, RTF_ULDASH, 1 }, + { "uldashd", CONTROL_TOGGLE, RTF_ULDASHD, 1 }, + { "uldashdd", CONTROL_TOGGLE, RTF_ULDASHDD, 1 }, + { "uldb", CONTROL_TOGGLE, RTF_ULDB, 1 }, + { "ulhair", CONTROL_TOGGLE, RTF_ULHAIR, 1 }, + { "ulhwave", CONTROL_TOGGLE, RTF_ULHWAVE, 1 }, + { "ulldash", CONTROL_TOGGLE, RTF_ULLDASH, 1 }, + { "ulnone", CONTROL_FLAG, RTF_ULNONE, 0 }, + { "ulth", CONTROL_TOGGLE, RTF_ULTH, 1 }, + { "ulthd", CONTROL_TOGGLE, RTF_ULTHD, 1 }, + { "ulthdash", CONTROL_TOGGLE, RTF_ULTHDASH, 1 }, + { "ulthdashd", CONTROL_TOGGLE, RTF_ULTHDASHD, 1 }, + { "ulthdashdd", CONTROL_TOGGLE, RTF_ULTHDASHDD, 1 }, + { "ulthldash", CONTROL_TOGGLE, RTF_ULTHLDASH, 1 }, + { "ululdbwave", CONTROL_TOGGLE, RTF_ULULDBWAVE, 1 }, + { "ulw", CONTROL_FLAG, RTF_ULW, 0 }, + { "ulwave", CONTROL_TOGGLE, RTF_ULWAVE, 1 }, + { "up", CONTROL_VALUE, RTF_UP, 6 }, + { "upr", CONTROL_DESTINATION, RTF_UPR, 0 }, + { "urtf", CONTROL_VALUE, RTF_URTF, 0 }, + { "useltbaln", CONTROL_FLAG, RTF_USELTBALN, 0 }, + { "usenormstyforlist", CONTROL_FLAG, RTF_USENORMSTYFORLIST, 0 }, + { "userprops", CONTROL_DESTINATION, RTF_USERPROPS, 0 }, + { "usexform", CONTROL_FLAG, RTF_USEXFORM, 0 }, + { "utinl", CONTROL_FLAG, RTF_UTINL, 0 }, + { "v", CONTROL_TOGGLE, RTF_V, 1 }, + { "validatexml", CONTROL_VALUE, RTF_VALIDATEXML, 0 }, + { "vern", CONTROL_VALUE, RTF_VERN, 0 }, + { "version", CONTROL_VALUE, RTF_VERSION, 0 }, + { "vertal", CONTROL_FLAG, RTF_VERTAL, 0 }, + { "vertalb", CONTROL_FLAG, RTF_VERTALB, 0 }, + { "vertalc", CONTROL_FLAG, RTF_VERTALC, 0 }, + { "vertalj", CONTROL_FLAG, RTF_VERTALJ, 0 }, + { "vertalt", CONTROL_FLAG, RTF_VERTALT, 0 }, + { "vertdoc", CONTROL_FLAG, RTF_VERTDOC, 0 }, + { "vertsect", CONTROL_FLAG, RTF_VERTSECT, 0 }, + { "viewbksp", CONTROL_VALUE, RTF_VIEWBKSP, 0 }, + { "viewkind", CONTROL_VALUE, RTF_VIEWKIND, 0 }, + { "viewnobound", CONTROL_FLAG, RTF_VIEWNOBOUND, 0 }, + { "viewscale", CONTROL_VALUE, RTF_VIEWSCALE, 100 }, + { "viewzk", CONTROL_VALUE, RTF_VIEWZK, 0 }, + { "wbitmap", CONTROL_VALUE, RTF_WBITMAP, 0 }, + { "wbmbitspixel", CONTROL_VALUE, RTF_WBMBITSPIXEL, 1 }, + { "wbmplanes", CONTROL_VALUE, RTF_WBMPLANES, 0 }, + { "wbmwidthbyte", CONTROL_VALUE, RTF_WBMWIDTHBYTE, 0 }, + { "webhidden", CONTROL_FLAG, RTF_WEBHIDDEN, 0 }, + { "wgrffmtfilter", CONTROL_DESTINATION, RTF_WGRFFMTFILTER, 0 }, + { "widctlpar", CONTROL_FLAG, RTF_WIDCTLPAR, 0 }, + { "widowctrl", CONTROL_FLAG, RTF_WIDOWCTRL, 0 }, + { "windowcaption", CONTROL_DESTINATION, RTF_WINDOWCAPTION, 0 }, + { "wmetafile", CONTROL_VALUE, RTF_WMETAFILE, 1 }, + { "wpeqn", CONTROL_FLAG, RTF_WPEQN, 0 }, + { "wpjst", CONTROL_FLAG, RTF_WPJST, 0 }, + { "wpsp", CONTROL_FLAG, RTF_WPSP, 0 }, + { "wraparound", CONTROL_FLAG, RTF_WRAPAROUND, 0 }, + { "wrapdefault", CONTROL_FLAG, RTF_WRAPDEFAULT, 0 }, + { "wrapthrough", CONTROL_FLAG, RTF_WRAPTHROUGH, 0 }, + { "wraptight", CONTROL_FLAG, RTF_WRAPTIGHT, 0 }, + { "wraptrsp", CONTROL_FLAG, RTF_WRAPTRSP, 0 }, + { "writereservation", CONTROL_DESTINATION, RTF_WRITERESERVATION, 0 }, + { "writereservhash", CONTROL_DESTINATION, RTF_WRITERESERVHASH, 0 }, + { "wrppunct", CONTROL_FLAG, RTF_WRPPUNCT, 0 }, + { "xe", CONTROL_DESTINATION, RTF_XE, 0 }, + { "xef", CONTROL_VALUE, RTF_XEF, 0 }, + { "xform", CONTROL_DESTINATION, RTF_XFORM, 0 }, + { "xmlattr", CONTROL_FLAG, RTF_XMLATTR, 0 }, + { "xmlattrname", CONTROL_DESTINATION, RTF_XMLATTRNAME, 0 }, + { "xmlattrns", CONTROL_VALUE, RTF_XMLATTRNS, 0 }, + { "xmlattrvalue", CONTROL_DESTINATION, RTF_XMLATTRVALUE, 0 }, + { "xmlclose", CONTROL_DESTINATION, RTF_XMLCLOSE, 0 }, + { "xmlname", CONTROL_DESTINATION, RTF_XMLNAME, 0 }, + { "xmlns", CONTROL_VALUE, RTF_XMLNS, 0 }, + { "xmlnstbl", CONTROL_DESTINATION, RTF_XMLNSTBL, 0 }, + { "xmlopen", CONTROL_DESTINATION, RTF_XMLOPEN, 0 }, + { "xmlsdttcell", CONTROL_FLAG, RTF_XMLSDTTCELL, 0 }, + { "xmlsdttpara", CONTROL_FLAG, RTF_XMLSDTTPARA, 0 }, + { "xmlsdttregular", CONTROL_FLAG, RTF_XMLSDTTREGULAR, 0 }, + { "xmlsdttrow", CONTROL_FLAG, RTF_XMLSDTTROW, 0 }, + { "xmlsdttunknown", CONTROL_FLAG, RTF_XMLSDTTUNKNOWN, 0 }, + { "yr", CONTROL_VALUE, RTF_YR, 0 }, + { "yts", CONTROL_VALUE, RTF_YTS, 0 }, + { "yxe", CONTROL_FLAG, RTF_YXE, 0 }, + { "zwbo", CONTROL_SYMBOL, RTF_ZWBO, 0 }, + { "zwj", CONTROL_SYMBOL, RTF_ZWJ, 0 }, + { "zwnbo", CONTROL_SYMBOL, RTF_ZWNBO, 0 }, + { "zwnj", CONTROL_SYMBOL, RTF_ZWNJ, 0 }, + { "flymaincnt", CONTROL_DESTINATION, RTF_FLYMAINCNT, 0 }, + { "flyvert", CONTROL_VALUE, RTF_FLYVERT, 0 }, + { "flyhorz", CONTROL_VALUE, RTF_FLYHORZ, 0 }, + { "flyanchor", CONTROL_VALUE, RTF_FLYANCHOR, 0 }, +}; +int nRTFControlWords = SAL_N_ELEMENTS(aRTFControlWords); + +RTFMathSymbol const aRTFMathControlWords[] = { + // eKeyword nToken eDestination + { RTF_MOMATH, M_TOKEN(oMath), Destination::MOMATH }, + { RTF_MF, M_TOKEN(f), Destination::MF }, + { RTF_MFPR, M_TOKEN(fPr), Destination::MFPR }, + { RTF_MCTRLPR, M_TOKEN(ctrlPr), Destination::MCTRLPR }, + { RTF_MNUM, M_TOKEN(num), Destination::MNUM }, + { RTF_MDEN, M_TOKEN(den), Destination::MDEN }, + { RTF_MACC, M_TOKEN(acc), Destination::MACC }, + { RTF_MACCPR, M_TOKEN(accPr), Destination::MACCPR }, + { RTF_MBAR, M_TOKEN(bar), Destination::MBAR }, + { RTF_MBARPR, M_TOKEN(barPr), Destination::MBARPR }, + { RTF_ME, M_TOKEN(e), Destination::ME }, + { RTF_MD, M_TOKEN(d), Destination::MD }, + { RTF_MDPR, M_TOKEN(dPr), Destination::MDPR }, + { RTF_MFUNC, M_TOKEN(func), Destination::MFUNC }, + { RTF_MFUNCPR, M_TOKEN(funcPr), Destination::MFUNCPR }, + { RTF_MFNAME, M_TOKEN(fName), Destination::MFNAME }, + { RTF_MLIMLOW, M_TOKEN(limLow), Destination::MLIMLOW }, + { RTF_MLIMLOWPR, M_TOKEN(limLowPr), Destination::MLIMLOWPR }, + { RTF_MLIM, M_TOKEN(lim), Destination::MLIM }, + { RTF_MM, M_TOKEN(m), Destination::MM }, + { RTF_MMPR, M_TOKEN(mPr), Destination::MMPR }, + { RTF_MMR, M_TOKEN(mr), Destination::MMR }, + { RTF_MNARY, M_TOKEN(nary), Destination::MNARY }, + { RTF_MNARYPR, M_TOKEN(naryPr), Destination::MNARYPR }, + { RTF_MSUB, M_TOKEN(sub), Destination::MSUB }, + { RTF_MSUP, M_TOKEN(sup), Destination::MSUP }, + { RTF_MLIMUPP, M_TOKEN(limUpp), Destination::MLIMUPP }, + { RTF_MLIMUPPPR, M_TOKEN(limUppPr), Destination::MLIMUPPPR }, + { RTF_MGROUPCHR, M_TOKEN(groupChr), Destination::MGROUPCHR }, + { RTF_MGROUPCHRPR, M_TOKEN(groupChrPr), Destination::MGROUPCHRPR }, + { RTF_MBORDERBOX, M_TOKEN(borderBox), Destination::MBORDERBOX }, + { RTF_MBORDERBOXPR, M_TOKEN(borderBoxPr), Destination::MBORDERBOXPR }, + { RTF_MRAD, M_TOKEN(rad), Destination::MRAD }, + { RTF_MRADPR, M_TOKEN(radPr), Destination::MRADPR }, + { RTF_MDEG, M_TOKEN(deg), Destination::MDEG }, + { RTF_MSSUB, M_TOKEN(sSub), Destination::MSSUB }, + { RTF_MSSUBPR, M_TOKEN(sSubPr), Destination::MSSUBPR }, + { RTF_MSSUP, M_TOKEN(sSup), Destination::MSSUP }, + { RTF_MSSUPPR, M_TOKEN(sSupPr), Destination::MSSUPPR }, + { RTF_MSSUBSUP, M_TOKEN(sSubSup), Destination::MSSUBSUP }, + { RTF_MSSUBSUPPR, M_TOKEN(sSubSupPr), Destination::MSSUBSUPPR }, + { RTF_MSPRE, M_TOKEN(sPre), Destination::MSPRE }, + { RTF_MSPREPR, M_TOKEN(sPrePr), Destination::MSPREPR }, + { RTF_MBOX, M_TOKEN(box), Destination::MBOX }, + { RTF_MEQARR, M_TOKEN(eqArr), Destination::MEQARR }, +}; +int nRTFMathControlWords = SAL_N_ELEMENTS(aRTFMathControlWords); + +bool RTFMathSymbol::operator<(const RTFMathSymbol& rOther) const +{ + return m_eKeyword < rOther.m_eKeyword; +} + +} // namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfcontrolwords.hxx b/writerfilter/source/rtftok/rtfcontrolwords.hxx new file mode 100644 index 000000000..2b350e552 --- /dev/null +++ b/writerfilter/source/rtftok/rtfcontrolwords.hxx @@ -0,0 +1,2056 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFCONTROLWORDS_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFCONTROLWORDS_HXX + +namespace writerfilter +{ +namespace rtftok +{ +/** + * An RTF destination state is the last open destination control word. + * + * Note that this is not a 1:1 mapping between destination control + * words, e.g. RTF_PICT gets mapped to Destination::PICT or + * Destination::SHAPEPROPERTYVALUEPICT. + */ +enum class Destination +{ + NORMAL, + SKIP, + FONTTABLE, + FONTENTRY, + COLORTABLE, + STYLESHEET, + STYLEENTRY, + FIELD, + FIELDINSTRUCTION, + FIELDRESULT, + LISTTABLE, + LISTPICTURE, + LISTENTRY, + LISTNAME, + LISTOVERRIDETABLE, + LISTOVERRIDEENTRY, + LISTLEVEL, + LEVELTEXT, + LEVELNUMBERS, + SHPPICT, + PICT, + PICPROP, + SHAPEPROPERTY, + SHAPEPROPERTYNAME, + SHAPEPROPERTYVALUE, + SHAPE, + SHAPEINSTRUCTION, + SHAPEPROPERTYVALUEPICT, + NESTEDTABLEPROPERTIES, + FOOTNOTE, + BOOKMARKSTART, + BOOKMARKEND, + REVISIONTABLE, + REVISIONENTRY, + SHAPETEXT, + FORMFIELD, + FORMFIELDNAME, + FORMFIELDLIST, + DATAFIELD, + INFO, + CREATIONTIME, + REVISIONTIME, + PRINTTIME, + AUTHOR, + KEYWORDS, + OPERATOR, + COMPANY, + COMMENT, + OBJECT, + OBJDATA, + OBJCLASS, + RESULT, + ANNOTATIONDATE, + ANNOTATIONAUTHOR, + ANNOTATIONREFERENCE, + FALT, + FLYMAINCONTENT, + DRAWINGOBJECT, + PARAGRAPHNUMBERING, + PARAGRAPHNUMBERING_TEXTBEFORE, + PARAGRAPHNUMBERING_TEXTAFTER, + TITLE, + SUBJECT, + DOCCOMM, + ATNID, + ANNOTATIONREFERENCESTART, + ANNOTATIONREFERENCEEND, + MOMATH, + MR, + MF, + MFPR, + MCTRLPR, + MNUM, + MDEN, + MACC, + MACCPR, + MCHR, + MPOS, + MVERTJC, + MSTRIKEH, + MDEGHIDE, + ME, + MBAR, + MBARPR, + MD, + MDPR, + MBEGCHR, + MSEPCHR, + MENDCHR, + MFUNC, + MFUNCPR, + MFNAME, + MLIMLOW, + MLIMLOWPR, + MLIM, + MM, + MMPR, + MMR, + MNARY, + MNARYPR, + MSUB, + MSUP, + MSUBHIDE, + MSUPHIDE, + MLIMUPP, + MLIMUPPPR, + MGROUPCHR, + MGROUPCHRPR, + MBORDERBOX, + MBORDERBOXPR, + MRAD, + MRADPR, + MDEG, + MSSUB, + MSSUBPR, + MSSUP, + MSSUPPR, + MSSUBSUP, + MSSUBSUPPR, + MSPRE, + MSPREPR, + MTYPE, + MGROW, + MBOX, + MEQARR, + UPR, + LFOLEVEL, + BACKGROUND, + SHAPEGROUP, + FOOTNOTESEPARATOR, + INDEXENTRY, + TOCENTRY, + USERPROPS, + PROPNAME, + STATICVAL, + GENERATOR, +}; + +enum RTFKeyword +{ + RTF_invalid = -1, + RTF_HEXCHAR, + RTF_OPTHYPH, + RTF_IGNORE, + RTF_SUBENTRY, + RTF_BACKSLASH, + RTF_NOBRKHYPH, + RTF_LBRACE, + RTF_FORMULA, + RTF_RBRACE, + RTF_NOBREAK, + RTF_AB, + RTF_ABSH, + RTF_ABSLOCK, + RTF_ABSNOOVRLP, + RTF_ABSW, + RTF_ACAPS, + RTF_ACCCIRCLE, + RTF_ACCCOMMA, + RTF_ACCDOT, + RTF_ACCNONE, + RTF_ACCUNDERDOT, + RTF_ACF, + RTF_ADEFF, + RTF_ADDITIVE, + RTF_ADEFLANG, + RTF_ADJUSTRIGHT, + RTF_ADN, + RTF_AENDDOC, + RTF_AENDNOTES, + RTF_AEXPND, + RTF_AF, + RTF_AFELEV, + RTF_AFS, + RTF_AFTNBJ, + RTF_AFTNCN, + RTF_AFTNNALC, + RTF_AFTNNAR, + RTF_AFTNNAUC, + RTF_AFTNNCHI, + RTF_AFTNNCHOSUNG, + RTF_AFTNNCNUM, + RTF_AFTNNDBAR, + RTF_AFTNNDBNUM, + RTF_AFTNNDBNUMD, + RTF_AFTNNDBNUMK, + RTF_AFTNNDBNUMT, + RTF_AFTNNGANADA, + RTF_AFTNNGBNUM, + RTF_AFTNNGBNUMD, + RTF_AFTNNGBNUMK, + RTF_AFTNNGBNUML, + RTF_AFTNNRLC, + RTF_AFTNNRUC, + RTF_AFTNNZODIAC, + RTF_AFTNNZODIACD, + RTF_AFTNNZODIACL, + RTF_AFTNRESTART, + RTF_AFTNRSTCONT, + RTF_AFTNSEP, + RTF_AFTNSEPC, + RTF_AFTNSTART, + RTF_AFTNTJ, + RTF_AI, + RTF_ALANG, + RTF_ALLOWFIELDENDSEL, + RTF_ALLPROT, + RTF_ALNTBLIND, + RTF_ALT, + RTF_ANIMTEXT, + RTF_ANNOTATION, + RTF_ANNOTPROT, + RTF_ANSI, + RTF_ANSICPG, + RTF_AOUTL, + RTF_APPLYBRKRULES, + RTF_ASCAPS, + RTF_ASHAD, + RTF_ASIANBRKRULE, + RTF_ASPALPHA, + RTF_ASPNUM, + RTF_ASTRIKE, + RTF_ATNAUTHOR, + RTF_ATNDATE, + RTF_ATNICN, + RTF_ATNID, + RTF_ATNPARENT, + RTF_ATNREF, + RTF_ATNTIME, + RTF_ATRFEND, + RTF_ATRFSTART, + RTF_AUL, + RTF_AULD, + RTF_AULDB, + RTF_AULNONE, + RTF_AULW, + RTF_AUP, + RTF_AUTHOR, + RTF_AUTOFMTOVERRIDE, + RTF_B, + RTF_BACKGROUND, + RTF_BDBFHDR, + RTF_BDRRLSWSIX, + RTF_BGBDIAG, + RTF_BGCROSS, + RTF_BGDCROSS, + RTF_BGDKBDIAG, + RTF_BGDKCROSS, + RTF_BGDKDCROSS, + RTF_BGDKFDIAG, + RTF_BGDKHORIZ, + RTF_BGDKVERT, + RTF_BGFDIAG, + RTF_BGHORIZ, + RTF_BGVERT, + RTF_BIN, + RTF_BINFSXN, + RTF_BINSXN, + RTF_BKMKCOLF, + RTF_BKMKCOLL, + RTF_BKMKEND, + RTF_BKMKPUB, + RTF_BKMKSTART, + RTF_BLIPTAG, + RTF_BLIPUID, + RTF_BLIPUPI, + RTF_BLUE, + RTF_BOOKFOLD, + RTF_BOOKFOLDREV, + RTF_BOOKFOLDSHEETS, + RTF_BOX, + RTF_BRDRART, + RTF_BRDRB, + RTF_BRDRBAR, + RTF_BRDRBTW, + RTF_BRDRCF, + RTF_BRDRDASH, + RTF_BRDRDASHD, + RTF_BRDRDASHDD, + RTF_BRDRDASHDOTSTR, + RTF_BRDRDASHSM, + RTF_BRDRDB, + RTF_BRDRDOT, + RTF_BRDREMBOSS, + RTF_BRDRENGRAVE, + RTF_BRDRFRAME, + RTF_BRDRHAIR, + RTF_BRDRINSET, + RTF_BRDRL, + RTF_BRDRNIL, + RTF_BRDRNONE, + RTF_BRDROUTSET, + RTF_BRDRR, + RTF_BRDRS, + RTF_BRDRSH, + RTF_BRDRT, + RTF_BRDRTBL, + RTF_BRDRTH, + RTF_BRDRTHTNLG, + RTF_BRDRTHTNMG, + RTF_BRDRTHTNSG, + RTF_BRDRTNTHLG, + RTF_BRDRTNTHMG, + RTF_BRDRTNTHSG, + RTF_BRDRTNTHTNLG, + RTF_BRDRTNTHTNMG, + RTF_BRDRTNTHTNSG, + RTF_BRDRTRIPLE, + RTF_BRDRW, + RTF_BRDRWAVY, + RTF_BRDRWAVYDB, + RTF_BRKFRM, + RTF_BRSP, + RTF_BULLET, + RTF_BUPTIM, + RTF_BXE, + RTF_CACCENTFIVE, + RTF_CACCENTFOUR, + RTF_CACCENTONE, + RTF_CACCENTSIX, + RTF_CACCENTTHREE, + RTF_CACCENTTWO, + RTF_CACHEDCOLBAL, + RTF_CAPS, + RTF_CATEGORY, + RTF_CB, + RTF_CBACKGROUNDONE, + RTF_CBACKGROUNDTWO, + RTF_CBPAT, + RTF_CCHS, + RTF_CELL, + RTF_CELLX, + RTF_CF, + RTF_CFOLLOWEDHYPERLINK, + RTF_CFPAT, + RTF_CGRID, + RTF_CHARRSID, + RTF_CHARSCALEX, + RTF_CHATN, + RTF_CHBGBDIAG, + RTF_CHBGCROSS, + RTF_CHBGDCROSS, + RTF_CHBGDKBDIAG, + RTF_CHBGDKCROSS, + RTF_CHBGDKDCROSS, + RTF_CHBGDKFDIAG, + RTF_CHBGDKHORIZ, + RTF_CHBGDKVERT, + RTF_CHBGFDIAG, + RTF_CHBGHORIZ, + RTF_CHBGVERT, + RTF_CHBRDR, + RTF_CHCBPAT, + RTF_CHCFPAT, + RTF_CHDATE, + RTF_CHDPA, + RTF_CHDPL, + RTF_CHFTN, + RTF_CHFTNSEP, + RTF_CHFTNSEPC, + RTF_CHPGN, + RTF_CHHRES, + RTF_CHSHDNG, + RTF_CHTIME, + RTF_CHYPERLINK, + RTF_CLBGBDIAG, + RTF_CLBGCROSS, + RTF_CLBGDCROSS, + RTF_CLBGDKBDIAG, + RTF_CLBGDKCROSS, + RTF_CLBGDKDCROSS, + RTF_CLBGDKFDIAG, + RTF_CLBGDKHOR, + RTF_CLBGDKVERT, + RTF_CLBGFDIAG, + RTF_CLBGHORIZ, + RTF_CLBGVERT, + RTF_CLBRDRB, + RTF_CLBRDRL, + RTF_CLBRDRR, + RTF_CLBRDRT, + RTF_CLCBPAT, + RTF_CLCBPATRAW, + RTF_CLCFPAT, + RTF_CLCFPATRAW, + RTF_CLDEL, + RTF_CLDELAUTH, + RTF_CLDELDTTM, + RTF_CLDGLL, + RTF_CLDGLU, + RTF_CLFITTEXT, + RTF_CLFTSWIDTH, + RTF_CLHIDEMARK, + RTF_CLINS, + RTF_CLINSAUTH, + RTF_CLINSDTTM, + RTF_CLMGF, + RTF_CLMRG, + RTF_CLMRGD, + RTF_CLMRGDAUTH, + RTF_CLMRGDDTTM, + RTF_CLMRGDR, + RTF_CLNOWRAP, + RTF_CLPADB, + RTF_CLPADFB, + RTF_CLPADFL, + RTF_CLPADFR, + RTF_CLPADFT, + RTF_CLPADL, + RTF_CLPADR, + RTF_CLPADT, + RTF_CLSPB, + RTF_CLSPFB, + RTF_CLSPFL, + RTF_CLSPFR, + RTF_CLSPFT, + RTF_CLSPL, + RTF_CLSPR, + RTF_CLSPT, + RTF_CLSHDNG, + RTF_CLSHDNGRAW, + RTF_CLSHDRAWNIL, + RTF_CLSPLIT, + RTF_CLSPLITR, + RTF_CLTXBTLR, + RTF_CLTXLRTB, + RTF_CLTXLRTBV, + RTF_CLTXTBRL, + RTF_CLTXTBRLV, + RTF_CLVERTALB, + RTF_CLVERTALC, + RTF_CLVERTALT, + RTF_CLVMGF, + RTF_CLVMRG, + RTF_CLWWIDTH, + RTF_CMAINDARKONE, + RTF_CMAINDARKTWO, + RTF_CMAINLIGHTONE, + RTF_CMAINLIGHTTWO, + RTF_COLLAPSED, + RTF_COLNO, + RTF_COLORSCHEMEMAPPING, + RTF_COLORTBL, + RTF_COLS, + RTF_COLSR, + RTF_COLSX, + RTF_COLUMN, + RTF_COLW, + RTF_COMMENT, + RTF_COMPANY, + RTF_CONTEXTUALSPACE, + RTF_CPG, + RTF_CRAUTH, + RTF_CRDATE, + RTF_CREATIM, + RTF_CS, + RTF_CSHADE, + RTF_CTEXTONE, + RTF_CTEXTTWO, + RTF_CTINT, + RTF_CTRL, + RTF_CTS, + RTF_CUFI, + RTF_CULI, + RTF_CURI, + RTF_CVMME, + RTF_DATAFIELD, + RTF_DATASTORE, + RTF_DATE, + RTF_DBCH, + RTF_DEFCHP, + RTF_DEFF, + RTF_DEFFORMAT, + RTF_DEFLANG, + RTF_DEFLANGFE, + RTF_DEFPAP, + RTF_DEFSHP, + RTF_DEFTAB, + RTF_DELETED, + RTF_DELRSID, + RTF_DFRAUTH, + RTF_DFRDATE, + RTF_DFRMTXTX, + RTF_DFRMTXTY, + RTF_DFRSTART, + RTF_DFRSTOP, + RTF_DFRXST, + RTF_DGHORIGIN, + RTF_DGHSHOW, + RTF_DGHSPACE, + RTF_DGMARGIN, + RTF_DGSNAP, + RTF_DGVORIGIN, + RTF_DGVSHOW, + RTF_DGVSPACE, + RTF_DIBITMAP, + RTF_DISABLED, + RTF_DN, + RTF_DNTBLNSBDB, + RTF_DO, + RTF_DOBXCOLUMN, + RTF_DOBXMARGIN, + RTF_DOBXPAGE, + RTF_DOBYMARGIN, + RTF_DOBYPAGE, + RTF_DOBYPARA, + RTF_DOCCOMM, + RTF_DOCTEMP, + RTF_DOCTYPE, + RTF_DOCVAR, + RTF_DODHGT, + RTF_DOLOCK, + RTF_DONOTEMBEDLINGDATA, + RTF_DONOTEMBEDSYSFONT, + RTF_DONOTSHOWCOMMENTS, + RTF_DONOTSHOWINSDEL, + RTF_DONOTSHOWMARKUP, + RTF_DONOTSHOWPROPS, + RTF_DPAENDHOL, + RTF_DPAENDL, + RTF_DPAENDSOL, + RTF_DPAENDW, + RTF_DPARC, + RTF_DPARCFLIPX, + RTF_DPARCFLIPY, + RTF_DPASTARTHOL, + RTF_DPASTARTL, + RTF_DPASTARTSOL, + RTF_DPASTARTW, + RTF_DPCALLOUT, + RTF_DPCOA, + RTF_DPCOACCENT, + RTF_DPCOBESTFIT, + RTF_DPCOBORDER, + RTF_DPCODABS, + RTF_DPCODBOTTOM, + RTF_DPCODCENTER, + RTF_DPCODESCENT, + RTF_DPCODTOP, + RTF_DPCOLENGTH, + RTF_DPCOMINUSX, + RTF_DPCOMINUSY, + RTF_DPCOOFFSET, + RTF_DPCOSMARTA, + RTF_DPCOTDOUBLE, + RTF_DPCOTRIGHT, + RTF_DPCOTSINGLE, + RTF_DPCOTTRIPLE, + RTF_DPCOUNT, + RTF_DPELLIPSE, + RTF_DPENDGROUP, + RTF_DPFILLBGCB, + RTF_DPFILLBGCG, + RTF_DPFILLBGCR, + RTF_DPFILLBGGRAY, + RTF_DPFILLBGPAL, + RTF_DPFILLFGCB, + RTF_DPFILLFGCG, + RTF_DPFILLFGCR, + RTF_DPFILLFGGRAY, + RTF_DPFILLFGPAL, + RTF_DPFILLPAT, + RTF_DPGROUP, + RTF_DPLINE, + RTF_DPLINECOB, + RTF_DPLINECOG, + RTF_DPLINECOR, + RTF_DPLINEDADO, + RTF_DPLINEDADODO, + RTF_DPLINEDASH, + RTF_DPLINEDOT, + RTF_DPLINEGRAY, + RTF_DPLINEHOLLOW, + RTF_DPLINEPAL, + RTF_DPLINESOLID, + RTF_DPLINEW, + RTF_DPPOLYCOUNT, + RTF_DPPOLYGON, + RTF_DPPOLYLINE, + RTF_DPPTX, + RTF_DPPTY, + RTF_DPRECT, + RTF_DPROUNDR, + RTF_DPSHADOW, + RTF_DPSHADX, + RTF_DPSHADY, + RTF_DPTXBTLR, + RTF_DPTXBX, + RTF_DPTXBXMAR, + RTF_DPTXBXTEXT, + RTF_DPTXLRTB, + RTF_DPTXLRTBV, + RTF_DPTXTBRL, + RTF_DPTXTBRLV, + RTF_DPX, + RTF_DPXSIZE, + RTF_DPY, + RTF_DPYSIZE, + RTF_DROPCAPLI, + RTF_DROPCAPT, + RTF_DS, + RTF_DXFRTEXT, + RTF_DY, + RTF_EBCEND, + RTF_EBCSTART, + RTF_EDMINS, + RTF_EMBO, + RTF_EMDASH, + RTF_EMFBLIP, + RTF_EMSPACE, + RTF_ENDASH, + RTF_ENDDOC, + RTF_ENDNHERE, + RTF_ENDNOTES, + RTF_ENFORCEPROT, + RTF_ENSPACE, + RTF_EXPND, + RTF_EXPNDTW, + RTF_EXPSHRTN, + RTF_F, + RTF_FAAUTO, + RTF_FACENTER, + RTF_FACINGP, + RTF_FACTOIDNAME, + RTF_FAFIXED, + RTF_FAHANG, + RTF_FALT, + RTF_FAROMAN, + RTF_FAVAR, + RTF_FBIAS, + RTF_FBIDI, + RTF_FBIDIS, + RTF_FBIMAJOR, + RTF_FBIMINOR, + RTF_FCHARS, + RTF_FCHARSET, + RTF_FCS, + RTF_FDBMAJOR, + RTF_FDBMINOR, + RTF_FDECOR, + RTF_FELNBRELEV, + RTF_FET, + RTF_FETCH, + RTF_FFDEFRES, + RTF_FFDEFTEXT, + RTF_FFENTRYMCR, + RTF_FFEXITMCR, + RTF_FFFORMAT, + RTF_FFHASLISTBOX, + RTF_FFHELPTEXT, + RTF_FFHPS, + RTF_FFL, + RTF_FFMAXLEN, + RTF_FFNAME, + RTF_FFOWNHELP, + RTF_FFOWNSTAT, + RTF_FFPROT, + RTF_FFRECALC, + RTF_FFRES, + RTF_FFSIZE, + RTF_FFSTATTEXT, + RTF_FFTYPE, + RTF_FFTYPETXT, + RTF_FHIMAJOR, + RTF_FHIMINOR, + RTF_FI, + RTF_FID, + RTF_FIELD, + RTF_FILE, + RTF_FILETBL, + RTF_FITTEXT, + RTF_FJGOTHIC, + RTF_FJMINCHOU, + RTF_FLDALT, + RTF_FLDDIRTY, + RTF_FLDEDIT, + RTF_FLDINST, + RTF_FLDLOCK, + RTF_FLDPRIV, + RTF_FLDRSLT, + RTF_FLDTYPE, + RTF_FLOMAJOR, + RTF_FLOMINOR, + RTF_FMODERN, + RTF_FN, + RTF_FNAME, + RTF_FNETWORK, + RTF_FNIL, + RTF_FNONFILESYS, + RTF_FONTEMB, + RTF_FONTFILE, + RTF_FONTTBL, + RTF_FOOTER, + RTF_FOOTERF, + RTF_FOOTERL, + RTF_FOOTERR, + RTF_FOOTERY, + RTF_FOOTNOTE, + RTF_FORCEUPGRADE, + RTF_FORMDISP, + RTF_FORMFIELD, + RTF_FORMPROT, + RTF_FORMSHADE, + RTF_FOSNUM, + RTF_FPRQ, + RTF_FRACWIDTH, + RTF_FRELATIVE, + RTF_FRMTXBTLR, + RTF_FRMTXLRTB, + RTF_FRMTXLRTBV, + RTF_FRMTXTBRL, + RTF_FRMTXTBRLV, + RTF_FROMAN, + RTF_FROMHTML, + RTF_FROMTEXT, + RTF_FS, + RTF_FSCRIPT, + RTF_FSWISS, + RTF_FTECH, + RTF_FTNALT, + RTF_FTNBJ, + RTF_FTNCN, + RTF_FTNIL, + RTF_FTNLYTWNINE, + RTF_FTNNALC, + RTF_FTNNAR, + RTF_FTNNAUC, + RTF_FTNNCHI, + RTF_FTNNCHOSUNG, + RTF_FTNNCNUM, + RTF_FTNNDBAR, + RTF_FTNNDBNUM, + RTF_FTNNDBNUMD, + RTF_FTNNDBNUMK, + RTF_FTNNDBNUMT, + RTF_FTNNGANADA, + RTF_FTNNGBNUM, + RTF_FTNNGBNUMD, + RTF_FTNNGBNUMK, + RTF_FTNNGBNUML, + RTF_FTNNRLC, + RTF_FTNNRUC, + RTF_FTNNZODIAC, + RTF_FTNNZODIACD, + RTF_FTNNZODIACL, + RTF_FTNRESTART, + RTF_FTNRSTCONT, + RTF_FTNRSTPG, + RTF_FTNSEP, + RTF_FTNSEPC, + RTF_FTNSTART, + RTF_FTNTJ, + RTF_FTTRUETYPE, + RTF_FVALIDDOS, + RTF_FVALIDHPFS, + RTF_FVALIDMAC, + RTF_FVALIDNTFS, + RTF_G, + RTF_GCW, + RTF_GENERATOR, + RTF_GREEN, + RTF_GRFDOCEVENTS, + RTF_GRIDTBL, + RTF_GUTTER, + RTF_GUTTERPRL, + RTF_GUTTERSXN, + RTF_HEADER, + RTF_HEADERF, + RTF_HEADERL, + RTF_HEADERR, + RTF_HEADERY, + RTF_HICH, + RTF_HIGHLIGHT, + RTF_HL, + RTF_HLFR, + RTF_HLINKBASE, + RTF_HLLOC, + RTF_HLSRC, + RTF_HORZDOC, + RTF_HORZSECT, + RTF_HORZVERT, + RTF_HR, + RTF_HRES, + RTF_HRULE, + RTF_HSV, + RTF_HTMAUTSP, + RTF_HTMLBASE, + RTF_HTMLRTF, + RTF_HTMLTAG, + RTF_HWELEV, + RTF_HYPHAUTO, + RTF_HYPHCAPS, + RTF_HYPHCONSEC, + RTF_HYPHHOTZ, + RTF_HYPHPAR, + RTF_I, + RTF_ID, + RTF_IGNOREMIXEDCONTENT, + RTF_ILFOMACATCLNUP, + RTF_ILVL, + RTF_IMPR, + RTF_INDMIRROR, + RTF_INDRLSWELEVEN, + RTF_INFO, + RTF_INSRSID, + RTF_INTBL, + RTF_IPGP, + RTF_IROWBAND, + RTF_IROW, + RTF_ITAP, + RTF_IXE, + RTF_JCOMPRESS, + RTF_JEXPAND, + RTF_JIS, + RTF_JPEGBLIP, + RTF_JSKSU, + RTF_KEEP, + RTF_KEEPN, + RTF_KERNING, + RTF_KEYCODE, + RTF_KEYWORDS, + RTF_KRNPRSNET, + RTF_KSULANG, + RTF_JCLISTTAB, + RTF_LANDSCAPE, + RTF_LANG, + RTF_LANGFE, + RTF_LANGFENP, + RTF_LANGNP, + RTF_LASTROW, + RTF_LATENTSTYLES, + RTF_LBR, + RTF_LCHARS, + RTF_LDBLQUOTE, + RTF_LEVEL, + RTF_LEVELFOLLOW, + RTF_LEVELINDENT, + RTF_LEVELJC, + RTF_LEVELJCN, + RTF_LEVELLEGAL, + RTF_LEVELNFC, + RTF_LEVELNFCN, + RTF_LEVELNORESTART, + RTF_LEVELNUMBERS, + RTF_LEVELOLD, + RTF_LEVELPICTURE, + RTF_LEVELPICTURENOSIZE, + RTF_LEVELPREV, + RTF_LEVELPREVSPACE, + RTF_LEVELSPACE, + RTF_LEVELSTARTAT, + RTF_LEVELTEMPLATEID, + RTF_LEVELTEXT, + RTF_LFOLEVEL, + RTF_LI, + RTF_LINE, + RTF_LINEBETCOL, + RTF_LINECONT, + RTF_LINEMOD, + RTF_LINEPPAGE, + RTF_LINERESTART, + RTF_LINESTART, + RTF_LINESTARTS, + RTF_LINEX, + RTF_LINKSELF, + RTF_LINKSTYLES, + RTF_LINKVAL, + RTF_LIN, + RTF_LISA, + RTF_LISB, + RTF_LIST, + RTF_LISTHYBRID, + RTF_LISTID, + RTF_LISTLEVEL, + RTF_LISTNAME, + RTF_LISTOVERRIDE, + RTF_LISTOVERRIDECOUNT, + RTF_LISTOVERRIDEFORMAT, + RTF_LISTOVERRIDESTARTAT, + RTF_LISTOVERRIDETABLE, + RTF_LISTPICTURE, + RTF_LISTRESTARTHDN, + RTF_LISTSIMPLE, + RTF_LISTSTYLEID, + RTF_LISTSTYLENAME, + RTF_LISTTABLE, + RTF_LISTTEMPLATEID, + RTF_LISTTEXT, + RTF_LNBRKRULE, + RTF_LNDSCPSXN, + RTF_LNONGRID, + RTF_LOCH, + RTF_LQUOTE, + RTF_LS, + RTF_LSDLOCKED, + RTF_LSDLOCKEDDEF, + RTF_LSDLOCKEDEXCEPT, + RTF_LSDPRIORITY, + RTF_LSDPRIORITYDEF, + RTF_LSDQFORMAT, + RTF_LSDQFORMATDEF, + RTF_LSDSEMIHIDDEN, + RTF_LSDSEMIHIDDENDEF, + RTF_LSDSTIMAX, + RTF_LSDUNHIDEUSED, + RTF_LSDUNHIDEUSEDDEF, + RTF_LTRCH, + RTF_LTRDOC, + RTF_LTRMARK, + RTF_LTRPAR, + RTF_LTRROW, + RTF_LTRSECT, + RTF_LVLTENTATIVE, + RTF_LYTCALCTBLWD, + RTF_LYTEXCTTP, + RTF_LYTPRTMET, + RTF_LYTTBLRTGR, + RTF_MAC, + RTF_MACC, + RTF_MACCPR, + RTF_MACPICT, + RTF_MAILMERGE, + RTF_MAKEBACKUP, + RTF_MALN, + RTF_MALNSCR, + RTF_MANAGER, + RTF_MARGB, + RTF_MARGBSXN, + RTF_MARGL, + RTF_MARGLSXN, + RTF_MARGMIRROR, + RTF_MARGMIRSXN, + RTF_MARGPR, + RTF_MARGR, + RTF_MARGRSXN, + RTF_MARGSZ, + RTF_MARGT, + RTF_MARGTSXN, + RTF_MBAR, + RTF_MBARPR, + RTF_MBASEJC, + RTF_MBEGCHR, + RTF_MBORDERBOX, + RTF_MBORDERBOXPR, + RTF_MBOX, + RTF_MBOXPR, + RTF_MBRK, + RTF_MBRKBIN, + RTF_MBRKBINSUB, + RTF_MCGP, + RTF_MCGPRULE, + RTF_MCHR, + RTF_MCOUNT, + RTF_MCSP, + RTF_MCTRLPR, + RTF_MD, + RTF_MDEFJC, + RTF_MDEG, + RTF_MDEGHIDE, + RTF_MDEN, + RTF_MDIFF, + RTF_MDIFFSTY, + RTF_MDISPDEF, + RTF_MDPR, + RTF_ME, + RTF_MENDCHR, + RTF_MEQARR, + RTF_MEQARRPR, + RTF_MF, + RTF_MFNAME, + RTF_MFPR, + RTF_MFUNC, + RTF_MFUNCPR, + RTF_MGROUPCHR, + RTF_MGROUPCHRPR, + RTF_MGROW, + RTF_MHIDEBOT, + RTF_MHIDELEFT, + RTF_MHIDERIGHT, + RTF_MHIDETOP, + RTF_MHTMLTAG, + RTF_MIN, + RTF_MINTERSP, + RTF_MINTLIM, + RTF_MINTRASP, + RTF_MJC, + RTF_MLIM, + RTF_MLIMLOC, + RTF_MLIMLOW, + RTF_MLIMLOWPR, + RTF_MLIMUPP, + RTF_MLIMUPPPR, + RTF_MLIT, + RTF_MLMARGIN, + RTF_MM, + RTF_MMADDFIELDNAME, + RTF_MMATH, + RTF_MMATHFONT, + RTF_MMATHPICT, + RTF_MMATHPR, + RTF_MMATTACH, + RTF_MMAXDIST, + RTF_MMBLANKLINES, + RTF_MMC, + RTF_MMCJC, + RTF_MMCONNECTSTR, + RTF_MMCONNECTSTRDATA, + RTF_MMCPR, + RTF_MMCS, + RTF_MMDATASOURCE, + RTF_MMDATATYPEACCESS, + RTF_MMDATATYPEEXCEL, + RTF_MMDATATYPEFILE, + RTF_MMDATATYPEODBC, + RTF_MMDATATYPEODSO, + RTF_MMDATATYPEQT, + RTF_MMDEFAULTSQL, + RTF_MMDESTEMAIL, + RTF_MMDESTFAX, + RTF_MMDESTNEWDOC, + RTF_MMDESTPRINTER, + RTF_MMERRORS, + RTF_MMFTTYPEADDRESS, + RTF_MMFTTYPEBARCODE, + RTF_MMFTTYPEDBCOLUMN, + RTF_MMFTTYPEMAPPED, + RTF_MMFTTYPENULL, + RTF_MMFTTYPESALUTATION, + RTF_MMHEADERSOURCE, + RTF_MMJDSOTYPE, + RTF_MMLINKTOQUERY, + RTF_MMMAILSUBJECT, + RTF_MMMAINTYPECATALOG, + RTF_MMMAINTYPEEMAIL, + RTF_MMMAINTYPEENVELOPES, + RTF_MMMAINTYPEFAX, + RTF_MMMAINTYPELABELS, + RTF_MMMAINTYPELETTERS, + RTF_MMODSO, + RTF_MMODSOACTIVE, + RTF_MMODSOCOLDELIM, + RTF_MMODSOCOLUMN, + RTF_MMODSODYNADDR, + RTF_MMODSOFHDR, + RTF_MMODSOFILTER, + RTF_MMODSOFLDMPDATA, + RTF_MMODSOFMCOLUMN, + RTF_MMODSOHASH, + RTF_MMODSOLID, + RTF_MMODSOMAPPEDNAME, + RTF_MMODSONAME, + RTF_MMODSORECIPDATA, + RTF_MMODSOSORT, + RTF_MMODSOSRC, + RTF_MMODSOTABLE, + RTF_MMODSOUDL, + RTF_MMODSOUDLDATA, + RTF_MMODSOUNIQUETAG, + RTF_MMPR, + RTF_MMQUERY, + RTF_MMR, + RTF_MMRECCUR, + RTF_MMSHOWDATA, + RTF_MNARY, + RTF_MNARYLIM, + RTF_MNARYPR, + RTF_MNOBREAK, + RTF_MNOR, + RTF_MNUM, + RTF_MO, + RTF_MOBJDIST, + RTF_MOMATH, + RTF_MOMATHPARA, + RTF_MOMATHPARAPR, + RTF_MOPEMU, + RTF_MPHANT, + RTF_MPHANTPR, + RTF_MPLCHIDE, + RTF_MPOS, + RTF_MPOSTSP, + RTF_MPRESP, + RTF_MR, + RTF_MRAD, + RTF_MRADPR, + RTF_MRMARGIN, + RTF_MRPR, + RTF_MRSP, + RTF_MRSPRULE, + RTF_MSCR, + RTF_MSEPCHR, + RTF_MSHOW, + RTF_MSHP, + RTF_MSMALLFRAC, + RTF_MSMCAP, + RTF_MSPRE, + RTF_MSPREPR, + RTF_MSSUB, + RTF_MSSUBPR, + RTF_MSSUBSUP, + RTF_MSSUBSUPPR, + RTF_MSSUP, + RTF_MSSUPPR, + RTF_MSTRIKEBLTR, + RTF_MSTRIKEH, + RTF_MSTRIKETLBR, + RTF_MSTRIKEV, + RTF_MSTY, + RTF_MSUB, + RTF_MSUBHIDE, + RTF_MSUP, + RTF_MSUPHIDE, + RTF_MTRANSP, + RTF_MTYPE, + RTF_MUSER, + RTF_MVAUTH, + RTF_MVDATE, + RTF_MVERTJC, + RTF_MVF, + RTF_MVFMF, + RTF_MVFML, + RTF_MVT, + RTF_MVTOF, + RTF_MVTOL, + RTF_MWRAPINDENT, + RTF_MWRAPRIGHT, + RTF_MZEROASC, + RTF_MZERODESC, + RTF_MZEROWID, + RTF_NESTCELL, + RTF_NESTROW, + RTF_NESTTABLEPROPS, + RTF_NEWTBLSTYRULS, + RTF_NEXTFILE, + RTF_NOAFCNSTTBL, + RTF_NOBRKWRPTBL, + RTF_NOCOLBAL, + RTF_NOCOMPATOPTIONS, + RTF_NOCWRAP, + RTF_NOCXSPTABLE, + RTF_NOEXTRASPRL, + RTF_NOFCHARS, + RTF_NOFCHARSWS, + RTF_NOFEATURETHROTTLE, + RTF_NOFPAGES, + RTF_NOFWORDS, + RTF_NOGROWAUTOFIT, + RTF_NOINDNMBRTS, + RTF_NOJKERNPUNCT, + RTF_NOLEAD, + RTF_NOLINE, + RTF_NOLNHTADJTBL, + RTF_NONESTTABLES, + RTF_NONSHPPICT, + RTF_NOOVERFLOW, + RTF_NOPROOF, + RTF_NOQFPROMOTE, + RTF_NOSECTEXPAND, + RTF_NOSNAPLINEGRID, + RTF_NOSPACEFORUL, + RTF_NOSUPERSUB, + RTF_NOTABIND, + RTF_NOTBRKCNSTFRCTBL, + RTF_NOTCVASP, + RTF_NOTVATXBX, + RTF_NOUICOMPAT, + RTF_NOULTRLSPC, + RTF_NOWIDCTLPAR, + RTF_NOWRAP, + RTF_NOWWRAP, + RTF_NOXLATTOYEN, + RTF_OBJALIAS, + RTF_OBJALIGN, + RTF_OBJATTPH, + RTF_OBJAUTLINK, + RTF_OBJCLASS, + RTF_OBJCROPB, + RTF_OBJCROPL, + RTF_OBJCROPR, + RTF_OBJCROPT, + RTF_OBJDATA, + RTF_OBJECT, + RTF_OBJEMB, + RTF_OBJH, + RTF_OBJHTML, + RTF_OBJICEMB, + RTF_OBJLINK, + RTF_OBJLOCK, + RTF_OBJNAME, + RTF_OBJOCX, + RTF_OBJPUB, + RTF_OBJSCALEX, + RTF_OBJSCALEY, + RTF_OBJSECT, + RTF_OBJSETSIZE, + RTF_OBJSUB, + RTF_OBJTIME, + RTF_OBJTRANSY, + RTF_OBJUPDATE, + RTF_OBJW, + RTF_OGUTTER, + RTF_OLDAS, + RTF_OLDCPROPS, + RTF_OLDLINEWRAP, + RTF_OLDPPROPS, + RTF_OLDSPROPS, + RTF_OLDTPROPS, + RTF_OLECLSID, + RTF_OPERATOR, + RTF_OTBLRUL, + RTF_OUTL, + RTF_OUTLINELEVEL, + RTF_OVERLAY, + RTF_PAGE, + RTF_PAGEBB, + RTF_PANOSE, + RTF_PAPERH, + RTF_PAPERW, + RTF_PAR, + RTF_PARARSID, + RTF_PARD, + RTF_PASSWORD, + RTF_PASSWORDHASH, + RTF_PC, + RTF_PCA, + RTF_PGBRDRB, + RTF_PGBRDRFOOT, + RTF_PGBRDRHEAD, + RTF_PGBRDRL, + RTF_PGBRDROPT, + RTF_PGBRDRR, + RTF_PGBRDRSNAP, + RTF_PGBRDRT, + RTF_PGHSXN, + RTF_PGNBIDIA, + RTF_PGNBIDIB, + RTF_PGNCHOSUNG, + RTF_PGNCNUM, + RTF_PGNCONT, + RTF_PGNDBNUM, + RTF_PGNDBNUMD, + RTF_PGNDBNUMK, + RTF_PGNDBNUMT, + RTF_PGNDEC, + RTF_PGNDECD, + RTF_PGNGANADA, + RTF_PGNGBNUM, + RTF_PGNGBNUMD, + RTF_PGNGBNUMK, + RTF_PGNGBNUML, + RTF_PGNHINDIA, + RTF_PGNHINDIB, + RTF_PGNHINDIC, + RTF_PGNHINDID, + RTF_PGNHN, + RTF_PGNHNSC, + RTF_PGNHNSH, + RTF_PGNHNSM, + RTF_PGNHNSN, + RTF_PGNHNSP, + RTF_PGNID, + RTF_PGNLCLTR, + RTF_PGNLCRM, + RTF_PGNRESTART, + RTF_PGNSTART, + RTF_PGNSTARTS, + RTF_PGNTHAIA, + RTF_PGNTHAIB, + RTF_PGNTHAIC, + RTF_PGNUCLTR, + RTF_PGNUCRM, + RTF_PGNVIETA, + RTF_PGNX, + RTF_PGNY, + RTF_PGNZODIAC, + RTF_PGNZODIACD, + RTF_PGNZODIACL, + RTF_PGP, + RTF_PGPTBL, + RTF_PGWSXN, + RTF_PHCOL, + RTF_PHMRG, + RTF_PHPG, + RTF_PICBMP, + RTF_PICBPP, + RTF_PICCROPB, + RTF_PICCROPL, + RTF_PICCROPR, + RTF_PICCROPT, + RTF_PICH, + RTF_PICHGOAL, + RTF_PICPROP, + RTF_PICSCALED, + RTF_PICSCALEX, + RTF_PICSCALEY, + RTF_PICT, + RTF_PICW, + RTF_PICWGOAL, + RTF_PINDTABQC, + RTF_PINDTABQL, + RTF_PINDTABQR, + RTF_PLAIN, + RTF_PMARTABQC, + RTF_PMARTABQL, + RTF_PMARTABQR, + RTF_PMMETAFILE, + RTF_PN, + RTF_PNACROSS, + RTF_PNAIU, + RTF_PNAIUD, + RTF_PNAIUEO, + RTF_PNAIUEOD, + RTF_PNB, + RTF_PNBIDIA, + RTF_PNBIDIB, + RTF_PNCAPS, + RTF_PNCARD, + RTF_PNCF, + RTF_PNCHOSUNG, + RTF_PNCNUM, + RTF_PNDBNUM, + RTF_PNDBNUMD, + RTF_PNDBNUMK, + RTF_PNDBNUML, + RTF_PNDBNUMT, + RTF_PNDEC, + RTF_PNDECD, + RTF_PNF, + RTF_PNFS, + RTF_PNGANADA, + RTF_PNGBLIP, + RTF_PNGBNUM, + RTF_PNGBNUMD, + RTF_PNGBNUMK, + RTF_PNGBNUML, + RTF_PNHANG, + RTF_PNI, + RTF_PNINDENT, + RTF_PNIROHA, + RTF_PNIROHAD, + RTF_PNLCLTR, + RTF_PNLCRM, + RTF_PNLVL, + RTF_PNLVLBLT, + RTF_PNLVLBODY, + RTF_PNLVLCONT, + RTF_PNNUMONCE, + RTF_PNORD, + RTF_PNORDT, + RTF_PNPREV, + RTF_PNQC, + RTF_PNQL, + RTF_PNQR, + RTF_PNRAUTH, + RTF_PNRDATE, + RTF_PNRESTART, + RTF_PNRNFC, + RTF_PNRNOT, + RTF_PNRPNBR, + RTF_PNRRGB, + RTF_PNRSTART, + RTF_PNRSTOP, + RTF_PNRXST, + RTF_PNSCAPS, + RTF_PNSECLVL, + RTF_PNSP, + RTF_PNSTART, + RTF_PNSTRIKE, + RTF_PNTEXT, + RTF_PNTXTA, + RTF_PNTXTB, + RTF_PNUCLTR, + RTF_PNUCRM, + RTF_PNUL, + RTF_PNULD, + RTF_PNULDASH, + RTF_PNULDASHD, + RTF_PNULDASHDD, + RTF_PNULDB, + RTF_PNULHAIR, + RTF_PNULNONE, + RTF_PNULTH, + RTF_PNULW, + RTF_PNULWAVE, + RTF_PNZODIAC, + RTF_PNZODIACD, + RTF_PNZODIACL, + RTF_POSNEGX, + RTF_POSNEGY, + RTF_POSX, + RTF_POSXC, + RTF_POSXI, + RTF_POSXL, + RTF_POSXO, + RTF_POSXR, + RTF_POSY, + RTF_POSYB, + RTF_POSYC, + RTF_POSYIL, + RTF_POSYIN, + RTF_POSYOUT, + RTF_POSYT, + RTF_PRAUTH, + RTF_PRCOLBL, + RTF_PRDATE, + RTF_PRINTDATA, + RTF_PRINTIM, + RTF_PRIVATE, + RTF_PROPNAME, + RTF_PROPTYPE, + RTF_PROTECT, + RTF_PROTEND, + RTF_PROTLEVEL, + RTF_PROTSTART, + RTF_PROTUSERTBL, + RTF_PSOVER, + RTF_PSZ, + RTF_PTABLDOT, + RTF_PTABLMDOT, + RTF_PTABLMINUS, + RTF_PTABLNONE, + RTF_PTABLUSCORE, + RTF_PUBAUTO, + RTF_PVMRG, + RTF_PVPARA, + RTF_PVPG, + RTF_PWD, + RTF_PXE, + RTF_QC, + RTF_QD, + RTF_QJ, + RTF_QK, + RTF_QL, + RTF_QMSPACE, + RTF_QR, + RTF_QT, + RTF_RAWCLBGDKBDIAG, + RTF_RAWCLBGBDIAG, + RTF_RAWCLBGCROSS, + RTF_RAWCLBGDCROSS, + RTF_RAWCLBGDKCROSS, + RTF_RAWCLBGDKDCROSS, + RTF_RAWCLBGDKFDIAG, + RTF_RAWCLBGDKHOR, + RTF_RAWCLBGDKVERT, + RTF_RAWCLBGFDIAG, + RTF_RAWCLBGHORIZ, + RTF_RAWCLBGVERT, + RTF_RDBLQUOTE, + RTF_READONLYRECOMMENDED, + RTF_READPROT, + RTF_RED, + RTF_RELYONVML, + RTF_REMDTTM, + RTF_REMPERSONALINFO, + RTF_RESULT, + RTF_REVAUTH, + RTF_REVAUTHDEL, + RTF_REVBAR, + RTF_REVDTTM, + RTF_REVDTTMDEL, + RTF_REVISED, + RTF_REVISIONS, + RTF_REVPROP, + RTF_REVPROT, + RTF_REVTBL, + RTF_REVTIM, + RTF_RI, + RTF_RIN, + RTF_ROW, + RTF_RQUOTE, + RTF_RSID, + RTF_RSIDROOT, + RTF_RSIDTBL, + RTF_RSLTBMP, + RTF_RSLTHTML, + RTF_RSLTMERGE, + RTF_RSLTPICT, + RTF_RSLTRTF, + RTF_RSLTTXT, + RTF_RTF, + RTF_RTLCH, + RTF_RTLDOC, + RTF_RTLGUTTER, + RTF_RTLMARK, + RTF_RTLPAR, + RTF_RTLROW, + RTF_RTLSECT, + RTF_RXE, + RTF_S, + RTF_SA, + RTF_SAAUTO, + RTF_SAFTNNALC, + RTF_SAFTNNAR, + RTF_SAFTNNAUC, + RTF_SAFTNNCHI, + RTF_SAFTNNCHOSUNG, + RTF_SAFTNNCNUM, + RTF_SAFTNNDBAR, + RTF_SAFTNNDBNUM, + RTF_SAFTNNDBNUMD, + RTF_SAFTNNDBNUMK, + RTF_SAFTNNDBNUMT, + RTF_SAFTNNGANADA, + RTF_SAFTNNGBNUM, + RTF_SAFTNNGBNUMD, + RTF_SAFTNNGBNUMK, + RTF_SAFTNNGBNUML, + RTF_SAFTNNRLC, + RTF_SAFTNNRUC, + RTF_SAFTNNZODIAC, + RTF_SAFTNNZODIACD, + RTF_SAFTNNZODIACL, + RTF_SAFTNRESTART, + RTF_SAFTNRSTCONT, + RTF_SAFTNSTART, + RTF_SAUTOUPD, + RTF_SAVEINVALIDXML, + RTF_SAVEPREVPICT, + RTF_SB, + RTF_SBASEDON, + RTF_SBAUTO, + RTF_SBKCOL, + RTF_SBKEVEN, + RTF_SBKNONE, + RTF_SBKODD, + RTF_SBKPAGE, + RTF_SBYS, + RTF_SCAPS, + RTF_SCOMPOSE, + RTF_SEC, + RTF_SECT, + RTF_SECTD, + RTF_SECTDEFAULTCL, + RTF_SECTEXPAND, + RTF_SECTLINEGRID, + RTF_SECTNUM, + RTF_SECTRSID, + RTF_SECTSPECIFYCL, + RTF_SECTSPECIFYGENN, + RTF_SECTSPECIFYL, + RTF_SECTUNLOCKED, + RTF_SFTNBJ, + RTF_SFTNNALC, + RTF_SFTNNAR, + RTF_SFTNNAUC, + RTF_SFTNNCHI, + RTF_SFTNNCHOSUNG, + RTF_SFTNNCNUM, + RTF_SFTNNDBAR, + RTF_SFTNNDBNUM, + RTF_SFTNNDBNUMD, + RTF_SFTNNDBNUMK, + RTF_SFTNNDBNUMT, + RTF_SFTNNGANADA, + RTF_SFTNNGBNUM, + RTF_SFTNNGBNUMD, + RTF_SFTNNGBNUMK, + RTF_SFTNNGBNUML, + RTF_SFTNNRLC, + RTF_SFTNNRUC, + RTF_SFTNNZODIAC, + RTF_SFTNNZODIACD, + RTF_SFTNNZODIACL, + RTF_SFTNRESTART, + RTF_SFTNRSTCONT, + RTF_SFTNRSTPG, + RTF_SFTNSTART, + RTF_SFTNTJ, + RTF_SHAD, + RTF_SHADING, + RTF_SHIDDEN, + RTF_SHIFT, + RTF_SHOWPLACEHOLDTEXT, + RTF_SHOWXMLERRORS, + RTF_SHP, + RTF_SHPBOTTOM, + RTF_SHPBXCOLUMN, + RTF_SHPBXIGNORE, + RTF_SHPBXMARGIN, + RTF_SHPBXPAGE, + RTF_SHPBYIGNORE, + RTF_SHPBYMARGIN, + RTF_SHPBYPAGE, + RTF_SHPBYPARA, + RTF_SHPFBLWTXT, + RTF_SHPFHDR, + RTF_SHPGRP, + RTF_SHPINST, + RTF_SHPLEFT, + RTF_SHPLID, + RTF_SHPLOCKANCHOR, + RTF_SHPPICT, + RTF_SHPRIGHT, + RTF_SHPRSLT, + RTF_SHPTOP, + RTF_SHPTXT, + RTF_SHPWRK, + RTF_SHPWR, + RTF_SHPZ, + RTF_SL, + RTF_SLINK, + RTF_SLMULT, + RTF_SLOCKED, + RTF_SN, + RTF_SNAPTOGRIDINCELL, + RTF_SNEXT, + RTF_SOFTCOL, + RTF_SOFTLHEIGHT, + RTF_SOFTLINE, + RTF_SOFTPAGE, + RTF_SP, + RTF_SPERSONAL, + RTF_SPLTPGPAR, + RTF_SPLYTWNINE, + RTF_SPRIORITY, + RTF_SPRSBSP, + RTF_SPRSLNSP, + RTF_SPRSSPBF, + RTF_SPRSTSM, + RTF_SPRSTSP, + RTF_SPV, + RTF_SQFORMAT, + RTF_SRAUTH, + RTF_SRDATE, + RTF_SREPLY, + RTF_SSEMIHIDDEN, + RTF_STATICVAL, + RTF_STEXTFLOW, + RTF_STRIKE, + RTF_STRIKED, + RTF_STSHFBI, + RTF_STSHFDBCH, + RTF_STSHFHICH, + RTF_STSHFLOCH, + RTF_STYLELOCK, + RTF_STYLELOCKBACKCOMP, + RTF_STYLELOCKENFORCED, + RTF_STYLELOCKQFSET, + RTF_STYLELOCKTHEME, + RTF_STYLESHEET, + RTF_STYLESORTMETHOD, + RTF_STYRSID, + RTF_SUB, + RTF_SUBDOCUMENT, + RTF_SUBFONTBYSIZE, + RTF_SUBJECT, + RTF_SUNHIDEUSED, + RTF_SUPER, + RTF_SV, + RTF_SVB, + RTF_SWPBDR, + RTF_TAB, + RTF_TABSNOOVRLP, + RTF_TAPRTL, + RTF_TB, + RTF_TBLIND, + RTF_TBLINDTYPE, + RTF_TBLLKBESTFIT, + RTF_TBLLKBORDER, + RTF_TBLLKCOLOR, + RTF_TBLLKFONT, + RTF_TBLLKHDRCOLS, + RTF_TBLLKHDRROWS, + RTF_TBLLKLASTCOL, + RTF_TBLLKLASTROW, + RTF_TBLLKNOCOLBAND, + RTF_TBLLKNOROWBAND, + RTF_TBLLKSHADING, + RTF_TBLRSID, + RTF_TC, + RTF_TCELLD, + RTF_TCF, + RTF_TCL, + RTF_TCN, + RTF_TDFRMTXTBOTTOM, + RTF_TDFRMTXTLEFT, + RTF_TDFRMTXTRIGHT, + RTF_TDFRMTXTTOP, + RTF_TEMPLATE, + RTF_THEMEDATA, + RTF_THEMELANG, + RTF_THEMELANGCS, + RTF_THEMELANGFE, + RTF_TIME, + RTF_TITLE, + RTF_TITLEPG, + RTF_TLDOT, + RTF_TLEQ, + RTF_TLHYPH, + RTF_TLMDOT, + RTF_TLTH, + RTF_TLUL, + RTF_TOPLINEPUNCT, + RTF_TPHCOL, + RTF_TPHMRG, + RTF_TPHPG, + RTF_TPOSNEGX, + RTF_TPOSNEGY, + RTF_TPOSXC, + RTF_TPOSXI, + RTF_TPOSXL, + RTF_TPOSX, + RTF_TPOSXO, + RTF_TPOSXR, + RTF_TPOSY, + RTF_TPOSYB, + RTF_TPOSYC, + RTF_TPOSYIL, + RTF_TPOSYIN, + RTF_TPOSYOUT, + RTF_TPOSYT, + RTF_TPVMRG, + RTF_TPVPARA, + RTF_TPVPG, + RTF_TQC, + RTF_TQDEC, + RTF_TQR, + RTF_TRACKFORMATTING, + RTF_TRACKMOVES, + RTF_TRANSMF, + RTF_TRAUTH, + RTF_TRAUTOFIT, + RTF_TRBGBDIAG, + RTF_TRBGCROSS, + RTF_TRBGDCROSS, + RTF_TRBGDKBDIAG, + RTF_TRBGDKCROSS, + RTF_TRBGDKDCROSS, + RTF_TRBGDKFDIAG, + RTF_TRBGDKHOR, + RTF_TRBGDKVERT, + RTF_TRBGFDIAG, + RTF_TRBGHORIZ, + RTF_TRBGVERT, + RTF_TRBRDRB, + RTF_TRBRDRH, + RTF_TRBRDRL, + RTF_TRBRDRR, + RTF_TRBRDRT, + RTF_TRBRDRV, + RTF_TRCBPAT, + RTF_TRCFPAT, + RTF_TRDATE, + RTF_TRFTSWIDTHA, + RTF_TRFTSWIDTHB, + RTF_TRFTSWIDTH, + RTF_TRGAPH, + RTF_TRHDR, + RTF_TRKEEP, + RTF_TRKEEPFOLLOW, + RTF_TRLEFT, + RTF_TROWD, + RTF_TRPADDB, + RTF_TRPADDFB, + RTF_TRPADDFL, + RTF_TRPADDFR, + RTF_TRPADDFT, + RTF_TRPADDL, + RTF_TRPADDR, + RTF_TRPADDT, + RTF_TRPADOB, + RTF_TRPADOFB, + RTF_TRPADOFL, + RTF_TRPADOFR, + RTF_TRPADOFT, + RTF_TRPADOL, + RTF_TRPADOR, + RTF_TRPADOT, + RTF_TRPAT, + RTF_TRQC, + RTF_TRQL, + RTF_TRQR, + RTF_TRRH, + RTF_TRSHDNG, + RTF_TRSPDB, + RTF_TRSPDFB, + RTF_TRSPDFL, + RTF_TRSPDFR, + RTF_TRSPDFT, + RTF_TRSPDL, + RTF_TRSPDR, + RTF_TRSPDT, + RTF_TRSPOB, + RTF_TRSPOFB, + RTF_TRSPOFL, + RTF_TRSPOFR, + RTF_TRSPOFT, + RTF_TRSPOL, + RTF_TRSPOR, + RTF_TRSPOT, + RTF_TRUNCATEFONTHEIGHT, + RTF_TRUNCEX, + RTF_TRWWIDTHA, + RTF_TRWWIDTHB, + RTF_TRWWIDTH, + RTF_TS, + RTF_TSBGBDIAG, + RTF_TSBGCROSS, + RTF_TSBGDCROSS, + RTF_TSBGDKBDIAG, + RTF_TSBGDKCROSS, + RTF_TSBGDKDCROSS, + RTF_TSBGDKFDIAG, + RTF_TSBGDKHOR, + RTF_TSBGDKVERT, + RTF_TSBGFDIAG, + RTF_TSBGHORIZ, + RTF_TSBGVERT, + RTF_TSBRDRB, + RTF_TSBRDRDGL, + RTF_TSBRDRDGR, + RTF_TSBRDRH, + RTF_TSBRDRL, + RTF_TSBRDRR, + RTF_TSBRDRT, + RTF_TSBRDRV, + RTF_TSCBANDHORZEVEN, + RTF_TSCBANDHORZODD, + RTF_TSCBANDSH, + RTF_TSCBANDSV, + RTF_TSCBANDVERTEVEN, + RTF_TSCBANDVERTODD, + RTF_TSCELLCBPAT, + RTF_TSCELLCFPAT, + RTF_TSCELLPADDB, + RTF_TSCELLPADDFB, + RTF_TSCELLPADDFL, + RTF_TSCELLPADDFR, + RTF_TSCELLPADDFT, + RTF_TSCELLPADDL, + RTF_TSCELLPADDR, + RTF_TSCELLPADDT, + RTF_TSCELLPCT, + RTF_TSCELLWIDTH, + RTF_TSCELLWIDTHFTS, + RTF_TSCFIRSTCOL, + RTF_TSCFIRSTROW, + RTF_TSCLASTCOL, + RTF_TSCLASTROW, + RTF_TSCNECELL, + RTF_TSCNWCELL, + RTF_TSCSECELL, + RTF_TSCSWCELL, + RTF_TSD, + RTF_TSNOWRAP, + RTF_TSROWD, + RTF_TSVERTALB, + RTF_TSVERTALC, + RTF_TSVERTALT, + RTF_TWOINONE, + RTF_TWOONONE, + RTF_TX, + RTF_TXBXTWALWAYS, + RTF_TXBXTWFIRST, + RTF_TXBXTWFIRSTLAST, + RTF_TXBXTWLAST, + RTF_TXBXTWNO, + RTF_TXE, + RTF_U, + RTF_UC, + RTF_UD, + RTF_UL, + RTF_ULC, + RTF_ULD, + RTF_ULDASH, + RTF_ULDASHD, + RTF_ULDASHDD, + RTF_ULDB, + RTF_ULHAIR, + RTF_ULHWAVE, + RTF_ULLDASH, + RTF_ULNONE, + RTF_ULTH, + RTF_ULTHD, + RTF_ULTHDASH, + RTF_ULTHDASHD, + RTF_ULTHDASHDD, + RTF_ULTHLDASH, + RTF_ULULDBWAVE, + RTF_ULW, + RTF_ULWAVE, + RTF_UP, + RTF_UPR, + RTF_URTF, + RTF_USELTBALN, + RTF_USENORMSTYFORLIST, + RTF_USERPROPS, + RTF_USEXFORM, + RTF_UTINL, + RTF_V, + RTF_VALIDATEXML, + RTF_VERN, + RTF_VERSION, + RTF_VERTAL, + RTF_VERTALB, + RTF_VERTALC, + RTF_VERTALJ, + RTF_VERTALT, + RTF_VERTDOC, + RTF_VERTSECT, + RTF_VIEWBKSP, + RTF_VIEWKIND, + RTF_VIEWNOBOUND, + RTF_VIEWSCALE, + RTF_VIEWZK, + RTF_WBITMAP, + RTF_WBMBITSPIXEL, + RTF_WBMPLANES, + RTF_WBMWIDTHBYTE, + RTF_WEBHIDDEN, + RTF_WGRFFMTFILTER, + RTF_WIDCTLPAR, + RTF_WIDOWCTRL, + RTF_WINDOWCAPTION, + RTF_WMETAFILE, + RTF_WPEQN, + RTF_WPJST, + RTF_WPSP, + RTF_WRAPAROUND, + RTF_WRAPDEFAULT, + RTF_WRAPTHROUGH, + RTF_WRAPTIGHT, + RTF_WRAPTRSP, + RTF_WRITERESERVATION, + RTF_WRITERESERVHASH, + RTF_WRPPUNCT, + RTF_XE, + RTF_XEF, + RTF_XFORM, + RTF_XMLATTR, + RTF_XMLATTRNAME, + RTF_XMLATTRNS, + RTF_XMLATTRVALUE, + RTF_XMLCLOSE, + RTF_XMLNAME, + RTF_XMLNS, + RTF_XMLNSTBL, + RTF_XMLOPEN, + RTF_XMLSDTTCELL, + RTF_XMLSDTTPARA, + RTF_XMLSDTTREGULAR, + RTF_XMLSDTTROW, + RTF_XMLSDTTUNKNOWN, + RTF_YR, + RTF_YTS, + RTF_YXE, + RTF_ZWBO, + RTF_ZWJ, + RTF_ZWNBO, + RTF_ZWNJ, + RTF_FLYMAINCNT, + RTF_FLYVERT, + RTF_FLYHORZ, + RTF_FLYANCHOR +}; +const char* keywordToString(RTFKeyword nKeyword); + +/// Types of an RTF Control Word +enum RTFControlTypes +{ + CONTROL_FLAG, // eg \sbknone takes no parameter + CONTROL_DESTINATION, // eg \fonttbl, if ignored, the whole group should be skipped + CONTROL_SYMBOL, // eg \tab + CONTROL_TOGGLE, // eg \b (between on and off) + CONTROL_VALUE // eg \fs (requires parameter) +}; + +/// Represents an RTF Control Word +class RTFSymbol +{ + const char* m_sKeyword; + int m_nControlType; + RTFKeyword m_nIndex; + + int m_nDefValue; ///< Most of the control words default to 0. + +public: + RTFSymbol() = default; + RTFSymbol(const char* sKeyword, int nControlType = 0, RTFKeyword nIndex = RTF_invalid, + int nDefValue = 0) + : m_sKeyword(sKeyword) + , m_nControlType(nControlType) + , m_nIndex(nIndex) + , m_nDefValue(nDefValue) + { + } + + const char* GetKeyword() const { return m_sKeyword; } + + int GetControlType() const { return m_nControlType; } + + RTFKeyword GetIndex() const { return m_nIndex; } + + int GetDefValue() const { return m_nDefValue; } +}; + +extern RTFSymbol const aRTFControlWords[]; +extern int nRTFControlWords; + +/// Represents an RTF Math Control Word +class RTFMathSymbol +{ + RTFKeyword m_eKeyword; + int m_nToken; ///< This is the OOXML token equivalent. + Destination m_eDestination; + +public: + RTFMathSymbol(RTFKeyword eKeyword, int nToken = 0, + Destination eDestination = Destination::NORMAL) + : m_eKeyword(eKeyword) + , m_nToken(nToken) + , m_eDestination(eDestination) + { + } + + int GetToken() const { return m_nToken; } + + Destination GetDestination() const { return m_eDestination; } + + bool operator<(const RTFMathSymbol& rOther) const; +}; + +extern RTFMathSymbol const aRTFMathControlWords[]; +extern int nRTFMathControlWords; + +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFCONTROLWORDS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdispatchdestination.cxx b/writerfilter/source/rtftok/rtfdispatchdestination.cxx new file mode 100644 index 000000000..68672bde9 --- /dev/null +++ b/writerfilter/source/rtftok/rtfdispatchdestination.cxx @@ -0,0 +1,676 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfdocumentimpl.hxx" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "rtflookahead.hxx" +#include "rtfreferenceproperties.hxx" +#include "rtfsdrimport.hxx" +#include "rtfskipdestination.hxx" +#include "rtftokenizer.hxx" + +using namespace com::sun::star; + +namespace writerfilter::rtftok +{ +RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) +{ + setNeedSect(true); + checkUnicode(/*bUnicode =*/true, /*bHex =*/true); + RTFSkipDestination aSkip(*this); + // special case \upr: ignore everything except nested \ud + if (Destination::UPR == m_aStates.top().getDestination() && RTF_UD != nKeyword) + { + m_aStates.top().setDestination(Destination::SKIP); + aSkip.setParsed(false); + } + else + switch (nKeyword) + { + case RTF_RTF: + break; + case RTF_FONTTBL: + m_aStates.top().setDestination(Destination::FONTTABLE); + break; + case RTF_COLORTBL: + m_aStates.top().setDestination(Destination::COLORTABLE); + break; + case RTF_STYLESHEET: + m_aStates.top().setDestination(Destination::STYLESHEET); + break; + case RTF_FIELD: + m_aStates.top().setDestination(Destination::FIELD); + break; + case RTF_FLDINST: + { + // Look for the field type + sal_uInt64 const nPos = Strm().Tell(); + OStringBuffer aBuf; + char ch = 0; + bool bFoundCode = false; + bool bInKeyword = false; + while (!bFoundCode && ch != '}') + { + Strm().ReadChar(ch); + if ('\\' == ch) + bInKeyword = true; + if (!bInKeyword && rtl::isAsciiAlphanumeric(static_cast(ch))) + aBuf.append(ch); + else if (bInKeyword && rtl::isAsciiWhiteSpace(static_cast(ch))) + bInKeyword = false; + if (!aBuf.isEmpty() + && !rtl::isAsciiAlphanumeric(static_cast(ch))) + bFoundCode = true; + } + + if (aBuf.toString() == "INCLUDEPICTURE") + { + // Extract the field argument of INCLUDEPICTURE: we handle that + // at a tokenizer level, as DOCX has no such field. + aBuf.append(ch); + while (true) + { + Strm().ReadChar(ch); + if (ch == '}') + break; + aBuf.append(ch); + } + OUString aFieldCommand + = OStringToOUString(aBuf.toString(), RTL_TEXTENCODING_UTF8); + std::tuple, std::vector> aResult + = writerfilter::dmapper::splitFieldCommand(aFieldCommand); + m_aPicturePath + = std::get<1>(aResult).empty() ? OUString() : std::get<1>(aResult).front(); + } + + Strm().Seek(nPos); + + // Form data should be handled only for form fields if any + if (aBuf.toString().indexOf("FORM") != -1) + m_bFormField = true; + + singleChar(cFieldStart); + m_aStates.top().setDestination(Destination::FIELDINSTRUCTION); + } + break; + case RTF_FLDRSLT: + m_aStates.top().setDestination(Destination::FIELDRESULT); + break; + case RTF_LISTTABLE: + m_aStates.top().setDestination(Destination::LISTTABLE); + break; + case RTF_LISTPICTURE: + m_aStates.top().setDestination(Destination::LISTPICTURE); + m_aStates.top().setInListpicture(true); + break; + case RTF_LIST: + m_aStates.top().setDestination(Destination::LISTENTRY); + break; + case RTF_LISTNAME: + m_aStates.top().setDestination(Destination::LISTNAME); + break; + case RTF_LFOLEVEL: + m_aStates.top().setDestination(Destination::LFOLEVEL); + m_aStates.top().getTableSprms().clear(); + break; + case RTF_LISTOVERRIDETABLE: + m_aStates.top().setDestination(Destination::LISTOVERRIDETABLE); + break; + case RTF_LISTOVERRIDE: + m_aStates.top().setDestination(Destination::LISTOVERRIDEENTRY); + break; + case RTF_LISTLEVEL: + m_aStates.top().setDestination(Destination::LISTLEVEL); + ++m_nListLevel; + break; + case RTF_LEVELTEXT: + m_aStates.top().setDestination(Destination::LEVELTEXT); + break; + case RTF_LEVELNUMBERS: + m_aStates.top().setDestination(Destination::LEVELNUMBERS); + break; + case RTF_SHPPICT: + resetFrame(); + m_aStates.top().setDestination(Destination::SHPPICT); + break; + case RTF_PICT: + if (m_aStates.top().getDestination() != Destination::SHAPEPROPERTYVALUE) + m_aStates.top().setDestination(Destination::PICT); // as character + else + m_aStates.top().setDestination( + Destination::SHAPEPROPERTYVALUEPICT); // anchored inside a shape + break; + case RTF_PICPROP: + m_aStates.top().setDestination(Destination::PICPROP); + break; + case RTF_SP: + m_aStates.top().setDestination(Destination::SHAPEPROPERTY); + break; + case RTF_SN: + m_aStates.top().setDestination(Destination::SHAPEPROPERTYNAME); + break; + case RTF_SV: + m_aStates.top().setDestination(Destination::SHAPEPROPERTYVALUE); + break; + case RTF_SHP: + m_bNeedCrOrig = m_bNeedCr; + m_aStates.top().setDestination(Destination::SHAPE); + m_aStates.top().setInShape(true); + break; + case RTF_SHPINST: + m_aStates.top().setDestination(Destination::SHAPEINSTRUCTION); + break; + case RTF_NESTTABLEPROPS: + // do not set any properties of outer table at nested table! + m_aStates.top().getTableCellSprms() = m_aDefaultState.getTableCellSprms(); + m_aStates.top().getTableCellAttributes() = m_aDefaultState.getTableCellAttributes(); + m_aNestedTableCellsSprms.clear(); + m_aNestedTableCellsAttributes.clear(); + m_nNestedCells = 0; + m_aStates.top().setDestination(Destination::NESTEDTABLEPROPERTIES); + break; + case RTF_HEADER: + case RTF_FOOTER: + case RTF_HEADERL: + case RTF_HEADERR: + case RTF_HEADERF: + case RTF_FOOTERL: + case RTF_FOOTERR: + case RTF_FOOTERF: + if (!m_pSuperstream) + { + Id nId = 0; + std::size_t nPos = m_nGroupStartPos - 1; + switch (nKeyword) + { + case RTF_HEADER: + if (!m_hasRHeader) + { + nId = NS_ooxml::LN_headerr; + m_hasRHeader = true; + } + break; + case RTF_FOOTER: + if (!m_hasRFooter) + { + nId = NS_ooxml::LN_footerr; + m_hasRFooter = true; + } + break; + case RTF_HEADERL: + nId = NS_ooxml::LN_headerl; + break; + case RTF_HEADERR: + nId = NS_ooxml::LN_headerr; + break; + case RTF_HEADERF: + if (!m_hasFHeader) + { + nId = NS_ooxml::LN_headerf; + m_hasFHeader = true; + } + break; + case RTF_FOOTERL: + nId = NS_ooxml::LN_footerl; + break; + case RTF_FOOTERR: + nId = NS_ooxml::LN_footerr; + break; + case RTF_FOOTERF: + if (!m_hasFFooter) + { + nId = NS_ooxml::LN_footerf; + m_hasFFooter = true; + } + break; + default: + break; + } + + if (nId != 0) + m_nHeaderFooterPositions.push(std::make_pair(nId, nPos)); + + m_aStates.top().setDestination(Destination::SKIP); + } + break; + case RTF_FOOTNOTE: + checkFirstRun(); + if (!m_pSuperstream) + { + Id nId = NS_ooxml::LN_footnote; + + // Check if this is an endnote. + OStringBuffer aBuf; + char ch; + sal_uInt64 const nCurrent = Strm().Tell(); + for (int i = 0; i < 7; ++i) + { + Strm().ReadChar(ch); + aBuf.append(ch); + } + Strm().Seek(nCurrent); + OString aKeyword = aBuf.makeStringAndClear(); + if (aKeyword == "\\ftnalt") + nId = NS_ooxml::LN_endnote; + + if (m_aStates.top().getCurrentBuffer() == &m_aSuperBuffer) + m_aStates.top().setCurrentBuffer(nullptr); + bool bCustomMark = false; + OUString aCustomMark; + for (auto const& elem : m_aSuperBuffer) + { + if (std::get<0>(elem) == BUFFER_UTEXT) + { + aCustomMark = std::get<1>(elem)->getString(); + bCustomMark = true; + } + } + m_aSuperBuffer.clear(); + m_aStates.top().setDestination(Destination::FOOTNOTE); + Mapper().startCharacterGroup(); + runProps(); + if (!m_aStates.top().getCurrentBuffer()) + resolveSubstream(m_nGroupStartPos - 1, nId, aCustomMark); + else + { + RTFSprms aAttributes; + aAttributes.set(Id(0), new RTFValue(m_nGroupStartPos - 1)); + aAttributes.set(Id(1), new RTFValue(nId)); + aAttributes.set(Id(2), new RTFValue(aCustomMark)); + m_aStates.top().getCurrentBuffer()->push_back( + Buf_t(BUFFER_RESOLVESUBSTREAM, new RTFValue(aAttributes), nullptr)); + } + if (bCustomMark) + { + m_aStates.top().getCharacterAttributes().clear(); + m_aStates.top().getCharacterSprms().clear(); + auto pValue = new RTFValue(1); + m_aStates.top().getCharacterAttributes().set( + NS_ooxml::LN_CT_FtnEdnRef_customMarkFollows, pValue); + text(aCustomMark); + } + Mapper().endCharacterGroup(); + m_aStates.top().setDestination(Destination::SKIP); + } + break; + case RTF_BKMKSTART: + m_aStates.top().setDestination(Destination::BOOKMARKSTART); + break; + case RTF_BKMKEND: + m_aStates.top().setDestination(Destination::BOOKMARKEND); + break; + case RTF_XE: + m_aStates.top().setDestination(Destination::INDEXENTRY); + break; + case RTF_TC: + case RTF_TCN: + m_aStates.top().setDestination(Destination::TOCENTRY); + break; + case RTF_REVTBL: + m_aStates.top().setDestination(Destination::REVISIONTABLE); + break; + case RTF_ANNOTATION: + if (!m_pSuperstream) + { + if (!m_aStates.top().getCurrentBuffer()) + { + resolveSubstream(m_nGroupStartPos - 1, NS_ooxml::LN_annotation); + } + else + { + RTFSprms aAttributes; + aAttributes.set(Id(0), new RTFValue(m_nGroupStartPos - 1)); + aAttributes.set(Id(1), new RTFValue(NS_ooxml::LN_annotation)); + aAttributes.set(Id(2), new RTFValue(OUString())); + m_aStates.top().getCurrentBuffer()->push_back( + Buf_t(BUFFER_RESOLVESUBSTREAM, new RTFValue(aAttributes), nullptr)); + } + m_aStates.top().setDestination(Destination::SKIP); + } + else + { + // If there is an author set, emit it now. + if (!m_aAuthor.isEmpty() || !m_aAuthorInitials.isEmpty()) + { + RTFSprms aAttributes; + if (!m_aAuthor.isEmpty()) + { + auto pValue = new RTFValue(m_aAuthor); + aAttributes.set(NS_ooxml::LN_CT_TrackChange_author, pValue); + } + if (!m_aAuthorInitials.isEmpty()) + { + auto pValue = new RTFValue(m_aAuthorInitials); + aAttributes.set(NS_ooxml::LN_CT_Comment_initials, pValue); + } + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aAttributes); + Mapper().props(pProperties); + } + } + break; + case RTF_SHPTXT: + case RTF_DPTXBXTEXT: + { + bool bPictureFrame = false; + for (const auto& rProperty : m_aStates.top().getShape().getProperties()) + { + if (rProperty.first == "shapeType" + && rProperty.second == OUString::number(ESCHER_ShpInst_PictureFrame)) + { + bPictureFrame = true; + break; + } + } + if (bPictureFrame) + // Skip text on picture frames. + m_aStates.top().setDestination(Destination::SKIP); + else + { + m_aStates.top().setDestination(Destination::SHAPETEXT); + checkFirstRun(); + dispatchFlag(RTF_PARD); + m_bNeedPap = true; + if (nKeyword == RTF_SHPTXT) + { + if (!m_aStates.top().getCurrentBuffer()) + m_pSdrImport->resolve(m_aStates.top().getShape(), false, + RTFSdrImport::SHAPE); + else + { + auto pValue = new RTFValue(m_aStates.top().getShape()); + m_aStates.top().getCurrentBuffer()->push_back( + Buf_t(BUFFER_STARTSHAPE, pValue, nullptr)); + } + } + } + } + break; + case RTF_FORMFIELD: + if (m_aStates.top().getDestination() == Destination::FIELDINSTRUCTION) + m_aStates.top().setDestination(Destination::FORMFIELD); + break; + case RTF_FFNAME: + m_aStates.top().setDestination(Destination::FORMFIELDNAME); + break; + case RTF_FFL: + m_aStates.top().setDestination(Destination::FORMFIELDLIST); + break; + case RTF_DATAFIELD: + m_aStates.top().setDestination(Destination::DATAFIELD); + break; + case RTF_INFO: + m_aStates.top().setDestination(Destination::INFO); + break; + case RTF_CREATIM: + m_aStates.top().setDestination(Destination::CREATIONTIME); + break; + case RTF_REVTIM: + m_aStates.top().setDestination(Destination::REVISIONTIME); + break; + case RTF_PRINTIM: + m_aStates.top().setDestination(Destination::PRINTTIME); + break; + case RTF_AUTHOR: + m_aStates.top().setDestination(Destination::AUTHOR); + break; + case RTF_KEYWORDS: + m_aStates.top().setDestination(Destination::KEYWORDS); + break; + case RTF_OPERATOR: + m_aStates.top().setDestination(Destination::OPERATOR); + break; + case RTF_COMPANY: + m_aStates.top().setDestination(Destination::COMPANY); + break; + case RTF_COMMENT: + m_aStates.top().setDestination(Destination::COMMENT); + break; + case RTF_OBJECT: + { + // beginning of an OLE Object + m_aStates.top().setDestination(Destination::OBJECT); + + // check if the object is in a special container (e.g. a table) + if (!m_aStates.top().getCurrentBuffer()) + { + // the object is in a table or another container. + // Don't try to treat it as an OLE object (fdo#53594). + // Use the \result (RTF_RESULT) element of the object instead, + // the result element contain picture representing the OLE Object. + m_bObject = true; + } + } + break; + case RTF_OBJDATA: + // check if the object is in a special container (e.g. a table) + if (m_aStates.top().getCurrentBuffer()) + { + // the object is in a table or another container. + // Use the \result (RTF_RESULT) element of the object instead, + // of the \objdata. + m_aStates.top().setDestination(Destination::SKIP); + } + else + { + m_aStates.top().setDestination(Destination::OBJDATA); + } + break; + case RTF_OBJCLASS: + m_aStates.top().setDestination(Destination::OBJCLASS); + break; + case RTF_RESULT: + m_aStates.top().setDestination(Destination::RESULT); + break; + case RTF_ATNDATE: + m_aStates.top().setDestination(Destination::ANNOTATIONDATE); + break; + case RTF_ATNAUTHOR: + m_aStates.top().setDestination(Destination::ANNOTATIONAUTHOR); + break; + case RTF_ATNREF: + m_aStates.top().setDestination(Destination::ANNOTATIONREFERENCE); + break; + case RTF_FALT: + m_aStates.top().setDestination(Destination::FALT); + break; + case RTF_FLYMAINCNT: + m_aStates.top().setDestination(Destination::FLYMAINCONTENT); + break; + case RTF_LISTTEXT: + // Should be ignored by any reader that understands Word 97 through Word 2007 numbering. + case RTF_NONESTTABLES: + // This destination should be ignored by readers that support nested tables. + m_aStates.top().setDestination(Destination::SKIP); + break; + case RTF_DO: + m_aStates.top().setDestination(Destination::DRAWINGOBJECT); + break; + case RTF_PN: + m_aStates.top().setDestination(Destination::PARAGRAPHNUMBERING); + break; + case RTF_PNTEXT: + // This destination should be ignored by readers that support paragraph numbering. + m_aStates.top().setDestination(Destination::SKIP); + break; + case RTF_PNTXTA: + m_aStates.top().setDestination(Destination::PARAGRAPHNUMBERING_TEXTAFTER); + break; + case RTF_PNTXTB: + m_aStates.top().setDestination(Destination::PARAGRAPHNUMBERING_TEXTBEFORE); + break; + case RTF_TITLE: + m_aStates.top().setDestination(Destination::TITLE); + break; + case RTF_SUBJECT: + m_aStates.top().setDestination(Destination::SUBJECT); + break; + case RTF_DOCCOMM: + m_aStates.top().setDestination(Destination::DOCCOMM); + break; + case RTF_ATRFSTART: + m_aStates.top().setDestination(Destination::ANNOTATIONREFERENCESTART); + break; + case RTF_ATRFEND: + m_aStates.top().setDestination(Destination::ANNOTATIONREFERENCEEND); + break; + case RTF_ATNID: + m_aStates.top().setDestination(Destination::ATNID); + break; + case RTF_MMATH: + case RTF_MOMATHPARA: + // Nothing to do here (just enter the destination) till RTF_MMATHPR is implemented. + break; + case RTF_MR: + m_aStates.top().setDestination(Destination::MR); + break; + case RTF_MCHR: + m_aStates.top().setDestination(Destination::MCHR); + break; + case RTF_MPOS: + m_aStates.top().setDestination(Destination::MPOS); + break; + case RTF_MVERTJC: + m_aStates.top().setDestination(Destination::MVERTJC); + break; + case RTF_MSTRIKEH: + m_aStates.top().setDestination(Destination::MSTRIKEH); + break; + case RTF_MDEGHIDE: + m_aStates.top().setDestination(Destination::MDEGHIDE); + break; + case RTF_MTYPE: + m_aStates.top().setDestination(Destination::MTYPE); + break; + case RTF_MGROW: + m_aStates.top().setDestination(Destination::MGROW); + break; + case RTF_MHIDETOP: + case RTF_MHIDEBOT: + case RTF_MHIDELEFT: + case RTF_MHIDERIGHT: + // SmOoxmlImport::handleBorderBox will ignore these anyway, so silently ignore for now. + m_aStates.top().setDestination(Destination::SKIP); + break; + case RTF_MSUBHIDE: + m_aStates.top().setDestination(Destination::MSUBHIDE); + break; + case RTF_MSUPHIDE: + m_aStates.top().setDestination(Destination::MSUPHIDE); + break; + case RTF_MBEGCHR: + m_aStates.top().setDestination(Destination::MBEGCHR); + break; + case RTF_MSEPCHR: + m_aStates.top().setDestination(Destination::MSEPCHR); + break; + case RTF_MENDCHR: + m_aStates.top().setDestination(Destination::MENDCHR); + break; + case RTF_UPR: + m_aStates.top().setDestination(Destination::UPR); + break; + case RTF_UD: + // Anything inside \ud is just normal Unicode content. + m_aStates.top().setDestination(Destination::NORMAL); + break; + case RTF_BACKGROUND: + m_aStates.top().setDestination(Destination::BACKGROUND); + m_aStates.top().setInBackground(true); + break; + case RTF_SHPGRP: + { + RTFLookahead aLookahead(Strm(), m_pTokenizer->getGroupStart()); + if (!aLookahead.hasTable()) + { + uno::Reference xGroupShape( + m_xModelFactory->createInstance("com.sun.star.drawing.GroupShape"), + uno::UNO_QUERY); + uno::Reference xDrawSupplier(m_xDstDoc, + uno::UNO_QUERY); + if (xDrawSupplier.is()) + { + uno::Reference xShape(xGroupShape, uno::UNO_QUERY); + // set default VertOrient before inserting + uno::Reference(xShape, uno::UNO_QUERY_THROW) + ->setPropertyValue("VertOrient", + uno::makeAny(text::VertOrientation::NONE)); + xDrawSupplier->getDrawPage()->add(xShape); + } + m_pSdrImport->pushParent(xGroupShape); + m_aStates.top().setCreatedShapeGroup(true); + } + m_aStates.top().setDestination(Destination::SHAPEGROUP); + m_aStates.top().setInShapeGroup(true); + } + break; + case RTF_FTNSEP: + m_aStates.top().setDestination(Destination::FOOTNOTESEPARATOR); + m_aStates.top().getCharacterAttributes().set( + NS_ooxml::LN_CT_FtnEdn_type, + new RTFValue(NS_ooxml::LN_Value_doc_ST_FtnEdn_separator)); + break; + case RTF_USERPROPS: + // Container of all user-defined properties. + m_aStates.top().setDestination(Destination::USERPROPS); + if (m_xDocumentProperties.is()) + // Create a custom document properties to be able to process them later all at once. + m_xDocumentProperties = document::DocumentProperties::create(m_xContext); + break; + case RTF_PROPNAME: + m_aStates.top().setDestination(Destination::PROPNAME); + break; + case RTF_STATICVAL: + m_aStates.top().setDestination(Destination::STATICVAL); + break; + case RTF_GENERATOR: + m_aStates.top().setDestination(Destination::GENERATOR); + break; + default: + { + // Check if it's a math token. + RTFMathSymbol aSymbol(nKeyword); + if (RTFTokenizer::lookupMathKeyword(aSymbol)) + { + m_aMathBuffer.appendOpeningTag(aSymbol.GetToken()); + m_aStates.top().setDestination(aSymbol.GetDestination()); + return RTFError::OK; + } + + SAL_INFO("writerfilter", + "TODO handle destination '" << keywordToString(nKeyword) << "'"); + // Make sure we skip destinations (even without \*) till we don't handle them + m_aStates.top().setDestination(Destination::SKIP); + aSkip.setParsed(false); + } + break; + } + + // new destination => use new destination text + m_aStates.top().setCurrentDestinationText(&m_aStates.top().getDestinationText()); + + return RTFError::OK; +} + +} // namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx new file mode 100644 index 000000000..7265d7c42 --- /dev/null +++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx @@ -0,0 +1,1239 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfdocumentimpl.hxx" + +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include "rtfsdrimport.hxx" +#include "rtfskipdestination.hxx" + +using namespace com::sun::star; + +namespace writerfilter::rtftok +{ +RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) +{ + setNeedSect(true); + checkUnicode(/*bUnicode =*/true, /*bHex =*/true); + RTFSkipDestination aSkip(*this); + int nParam = -1; + int nSprm = -1; + + // Underline flags. + switch (nKeyword) + { + case RTF_ULD: + nSprm = NS_ooxml::LN_Value_ST_Underline_dotted; + break; + case RTF_ULW: + nSprm = NS_ooxml::LN_Value_ST_Underline_words; + break; + default: + break; + } + if (nSprm >= 0) + { + auto pValue = new RTFValue(nSprm); + m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_Underline_val, pValue); + return RTFError::OK; + } + + // Indentation + switch (nKeyword) + { + case RTF_QC: + nParam = NS_ooxml::LN_Value_ST_Jc_center; + break; + case RTF_QJ: + nParam = NS_ooxml::LN_Value_ST_Jc_both; + break; + case RTF_QL: + nParam = NS_ooxml::LN_Value_ST_Jc_left; + break; + case RTF_QR: + nParam = NS_ooxml::LN_Value_ST_Jc_right; + break; + case RTF_QD: + nParam = NS_ooxml::LN_Value_ST_Jc_distribute; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_jc, pValue); + m_bNeedPap = true; + return RTFError::OK; + } + + // Font Alignment + switch (nKeyword) + { + case RTF_FAFIXED: + case RTF_FAAUTO: + nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_auto; + break; + case RTF_FAHANG: + nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_top; + break; + case RTF_FACENTER: + nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_center; + break; + case RTF_FAROMAN: + nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_baseline; + break; + case RTF_FAVAR: + nParam = NS_ooxml::LN_Value_doc_ST_TextAlignment_bottom; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_textAlignment, pValue); + return RTFError::OK; + } + + // Tab kind. + switch (nKeyword) + { + case RTF_TQR: + nParam = NS_ooxml::LN_Value_ST_TabJc_right; + break; + case RTF_TQC: + nParam = NS_ooxml::LN_Value_ST_TabJc_center; + break; + case RTF_TQDEC: + nParam = NS_ooxml::LN_Value_ST_TabJc_decimal; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + m_aStates.top().getTabAttributes().set(NS_ooxml::LN_CT_TabStop_val, pValue); + return RTFError::OK; + } + + // Tab lead. + switch (nKeyword) + { + case RTF_TLDOT: + nParam = NS_ooxml::LN_Value_ST_TabTlc_dot; + break; + case RTF_TLMDOT: + nParam = NS_ooxml::LN_Value_ST_TabTlc_middleDot; + break; + case RTF_TLHYPH: + nParam = NS_ooxml::LN_Value_ST_TabTlc_hyphen; + break; + case RTF_TLUL: + case RTF_TLTH: + nParam = NS_ooxml::LN_Value_ST_TabTlc_underscore; + break; + case RTF_TLEQ: + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + m_aStates.top().getTabAttributes().set(NS_ooxml::LN_CT_TabStop_leader, pValue); + return RTFError::OK; + } + + // Border types + { + switch (nKeyword) + { + // brdrhair and brdrs are the same, brdrw will make a difference + // map to values in ooxml/model.xml resource ST_Border + case RTF_BRDRHAIR: + case RTF_BRDRS: + nParam = NS_ooxml::LN_Value_ST_Border_single; + break; + case RTF_BRDRDOT: + nParam = NS_ooxml::LN_Value_ST_Border_dotted; + break; + case RTF_BRDRDASH: + nParam = NS_ooxml::LN_Value_ST_Border_dashed; + break; + case RTF_BRDRDB: + nParam = NS_ooxml::LN_Value_ST_Border_double; + break; + case RTF_BRDRTNTHSG: + nParam = NS_ooxml::LN_Value_ST_Border_thinThickSmallGap; + break; + case RTF_BRDRTNTHMG: + nParam = NS_ooxml::LN_Value_ST_Border_thinThickMediumGap; + break; + case RTF_BRDRTNTHLG: + nParam = NS_ooxml::LN_Value_ST_Border_thinThickLargeGap; + break; + case RTF_BRDRTHTNSG: + nParam = NS_ooxml::LN_Value_ST_Border_thickThinSmallGap; + break; + case RTF_BRDRTHTNMG: + nParam = NS_ooxml::LN_Value_ST_Border_thickThinMediumGap; + break; + case RTF_BRDRTHTNLG: + nParam = NS_ooxml::LN_Value_ST_Border_thickThinLargeGap; + break; + case RTF_BRDREMBOSS: + nParam = NS_ooxml::LN_Value_ST_Border_threeDEmboss; + break; + case RTF_BRDRENGRAVE: + nParam = NS_ooxml::LN_Value_ST_Border_threeDEngrave; + break; + case RTF_BRDROUTSET: + nParam = NS_ooxml::LN_Value_ST_Border_outset; + break; + case RTF_BRDRINSET: + nParam = NS_ooxml::LN_Value_ST_Border_inset; + break; + case RTF_BRDRDASHSM: + nParam = NS_ooxml::LN_Value_ST_Border_dashSmallGap; + break; + case RTF_BRDRDASHD: + nParam = NS_ooxml::LN_Value_ST_Border_dotDash; + break; + case RTF_BRDRDASHDD: + nParam = NS_ooxml::LN_Value_ST_Border_dotDotDash; + break; + case RTF_BRDRNONE: + nParam = NS_ooxml::LN_Value_ST_Border_none; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_val, pValue); + return RTFError::OK; + } + } + + // Section breaks + switch (nKeyword) + { + case RTF_SBKNONE: + nParam = NS_ooxml::LN_Value_ST_SectionMark_continuous; + break; + case RTF_SBKCOL: + nParam = NS_ooxml::LN_Value_ST_SectionMark_nextColumn; + break; + case RTF_SBKPAGE: + nParam = NS_ooxml::LN_Value_ST_SectionMark_nextPage; + break; + case RTF_SBKEVEN: + nParam = NS_ooxml::LN_Value_ST_SectionMark_evenPage; + break; + case RTF_SBKODD: + nParam = NS_ooxml::LN_Value_ST_SectionMark_oddPage; + break; + default: + break; + } + if (nParam >= 0) + { + if (m_nResetBreakOnSectBreak != RTF_invalid) + { + m_nResetBreakOnSectBreak = nKeyword; + } + auto pValue = new RTFValue(nParam); + m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_type, pValue); + return RTFError::OK; + } + + // Footnote numbering + switch (nKeyword) + { + case RTF_FTNNAR: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_decimal; + break; + case RTF_FTNNALC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter; + break; + case RTF_FTNNAUC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperLetter; + break; + case RTF_FTNNRLC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman; + break; + case RTF_FTNNRUC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperRoman; + break; + case RTF_FTNNCHI: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_chicago; + break; + default: + break; + } + if (nParam >= 0) + { + auto pInner = new RTFValue(nParam); + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_NumFmt_val, pInner); + auto pOuter = new RTFValue(aAttributes); + putNestedSprm(m_aDefaultState.getParagraphSprms(), + NS_ooxml::LN_EG_SectPrContents_footnotePr, NS_ooxml::LN_CT_FtnProps_numFmt, + pOuter); + return RTFError::OK; + } + + // Footnote restart type + switch (nKeyword) + { + case RTF_FTNRSTPG: + nParam = NS_ooxml::LN_Value_ST_RestartNumber_eachPage; + break; + case RTF_FTNRESTART: + nParam = NS_ooxml::LN_Value_ST_RestartNumber_eachSect; + break; + case RTF_FTNRSTCONT: + nParam = NS_ooxml::LN_Value_ST_RestartNumber_continuous; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + putNestedSprm(m_aDefaultState.getParagraphSprms(), + NS_ooxml::LN_EG_SectPrContents_footnotePr, + NS_ooxml::LN_EG_FtnEdnNumProps_numRestart, pValue); + return RTFError::OK; + } + + // Endnote numbering + switch (nKeyword) + { + case RTF_AFTNNAR: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_decimal; + break; + case RTF_AFTNNALC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter; + break; + case RTF_AFTNNAUC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperLetter; + break; + case RTF_AFTNNRLC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman; + break; + case RTF_AFTNNRUC: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_upperRoman; + break; + case RTF_AFTNNCHI: + nParam = NS_ooxml::LN_Value_ST_NumberFormat_chicago; + break; + default: + break; + } + if (nParam >= 0) + { + auto pInner = new RTFValue(nParam); + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_NumFmt_val, pInner); + auto pOuter = new RTFValue(aAttributes); + putNestedSprm(m_aDefaultState.getParagraphSprms(), NS_ooxml::LN_EG_SectPrContents_endnotePr, + NS_ooxml::LN_CT_EdnProps_numFmt, pOuter); + return RTFError::OK; + } + + switch (nKeyword) + { + case RTF_TRQL: + nParam = NS_ooxml::LN_Value_ST_Jc_left; + break; + case RTF_TRQC: + nParam = NS_ooxml::LN_Value_ST_Jc_center; + break; + case RTF_TRQR: + nParam = NS_ooxml::LN_Value_ST_Jc_right; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TrPrBase_jc, pValue); + return RTFError::OK; + } + + // Cell Text Flow + switch (nKeyword) + { + case RTF_CLTXLRTB: + nParam = NS_ooxml::LN_Value_ST_TextDirection_lrTb; + break; + case RTF_CLTXTBRL: + nParam = NS_ooxml::LN_Value_ST_TextDirection_tbRl; + break; + case RTF_CLTXBTLR: + nParam = NS_ooxml::LN_Value_ST_TextDirection_btLr; + break; + case RTF_CLTXLRTBV: + nParam = NS_ooxml::LN_Value_ST_TextDirection_lrTbV; + break; + case RTF_CLTXTBRLV: + nParam = NS_ooxml::LN_Value_ST_TextDirection_tbRlV; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(nParam); + m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_textDirection, pValue); + } + + // Trivial paragraph flags + switch (nKeyword) + { + case RTF_KEEP: + if (m_aStates.top().getCurrentBuffer() != &m_aTableBufferStack.back()) + nParam = NS_ooxml::LN_CT_PPrBase_keepLines; + break; + case RTF_KEEPN: + if (m_aStates.top().getCurrentBuffer() != &m_aTableBufferStack.back()) + nParam = NS_ooxml::LN_CT_PPrBase_keepNext; + break; + case RTF_INTBL: + { + m_aStates.top().setCurrentBuffer(&m_aTableBufferStack.back()); + nParam = NS_ooxml::LN_inTbl; + } + break; + case RTF_PAGEBB: + nParam = NS_ooxml::LN_CT_PPrBase_pageBreakBefore; + break; + default: + break; + } + if (nParam >= 0) + { + auto pValue = new RTFValue(1); + m_aStates.top().getParagraphSprms().set(nParam, pValue); + return RTFError::OK; + } + + switch (nKeyword) + { + case RTF_FNIL: + case RTF_FROMAN: + case RTF_FSWISS: + case RTF_FMODERN: + case RTF_FSCRIPT: + case RTF_FDECOR: + case RTF_FTECH: + case RTF_FBIDI: + // TODO ooxml:CT_Font_family seems to be ignored by the domain mapper + break; + case RTF_ANSI: + m_aStates.top().setCurrentEncoding(RTL_TEXTENCODING_MS_1252); + break; + case RTF_MAC: + m_aDefaultState.setCurrentEncoding(RTL_TEXTENCODING_APPLE_ROMAN); + m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding()); + break; + case RTF_PC: + m_aDefaultState.setCurrentEncoding(RTL_TEXTENCODING_IBM_437); + m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding()); + break; + case RTF_PCA: + m_aDefaultState.setCurrentEncoding(RTL_TEXTENCODING_IBM_850); + m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding()); + break; + case RTF_PLAIN: + { + m_aStates.top().getCharacterSprms() = getDefaultState().getCharacterSprms(); + m_aStates.top().setCurrentEncoding(getEncoding(getFontIndex(m_nDefaultFontIndex))); + m_aStates.top().getCharacterAttributes() = getDefaultState().getCharacterAttributes(); + m_aStates.top().setCurrentCharacterStyleIndex(-1); + m_aStates.top().setRunType(RTFParserState::RunType::NONE); + } + break; + case RTF_PARD: + { + if (m_bHadPicture) + dispatchSymbol(RTF_PAR); + // \pard is allowed between \cell and \row, but in that case it should not reset the fact that we're inside a table. + // It should not reset the paragraph style, either, so remember the old paragraph style. + RTFValue::Pointer_t pOldStyle + = m_aStates.top().getParagraphSprms().find(NS_ooxml::LN_CT_PPrBase_pStyle); + m_aStates.top().getParagraphSprms() = m_aDefaultState.getParagraphSprms(); + m_aStates.top().getParagraphAttributes() = m_aDefaultState.getParagraphAttributes(); + + if (m_nTopLevelCells == 0 && m_nNestedCells == 0) + { + // Reset that we're in a table. + m_aStates.top().setCurrentBuffer(nullptr); + } + else + { + // We are still in a table. + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_inTbl, new RTFValue(1)); + if (m_bAfterCellBeforeRow && pOldStyle) + // And we still have the same paragraph style. + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_pStyle, + pOldStyle); + // Ideally getDefaultSPRM() would take care of this, but it would not when we're buffering. + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_tabs, + new RTFValue()); + } + resetFrame(); + + // Reset currently selected paragraph style as well, unless we are in the special "after \cell, before \row" state. + // By default the style with index 0 is applied. + if (!m_bAfterCellBeforeRow) + { + OUString const aName = getStyleName(0); + // But only in case it's not a character style. + if (!aName.isEmpty() + && getStyleType(0) != NS_ooxml::LN_Value_ST_StyleType_character) + { + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_pStyle, + new RTFValue(aName)); + m_aStates.top().setCurrentStyleIndex(0); + } + else + { + m_aStates.top().setCurrentStyleIndex(-1); + } + } + // Need to send paragraph properties again, if there will be any. + m_bNeedPap = true; + break; + } + case RTF_SECTD: + { + m_aStates.top().getSectionSprms() = m_aDefaultState.getSectionSprms(); + m_aStates.top().getSectionAttributes() = m_aDefaultState.getSectionAttributes(); + } + break; + case RTF_TROWD: + { + // Back these up, in case later we still need this info. + backupTableRowProperties(); + resetTableRowProperties(); + // In case the table definition is in the middle of the row + // (invalid), make sure table definition is emitted. + m_bNeedPap = true; + } + break; + case RTF_WIDCTLPAR: + case RTF_NOWIDCTLPAR: + { + auto pValue = new RTFValue(int(nKeyword == RTF_WIDCTLPAR)); + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_widowControl, pValue); + } + break; + case RTF_BOX: + { + RTFSprms aAttributes; + auto pValue = new RTFValue(aAttributes); + for (int i = 0; i < 4; i++) + m_aStates.top().getParagraphSprms().set(getParagraphBorder(i), pValue); + m_aStates.top().setBorderState(RTFBorderState::PARAGRAPH_BOX); + } + break; + case RTF_LTRSECT: + case RTF_RTLSECT: + { + auto pValue = new RTFValue(nKeyword == RTF_LTRSECT ? 0 : 1); + m_aStates.top().setRunType(RTFParserState::RunType::NONE); + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_EG_SectPrContents_textDirection, + pValue); + } + break; + case RTF_LTRPAR: + case RTF_RTLPAR: + { + auto pValue = new RTFValue(nKeyword == RTF_LTRPAR ? 0 : 1); + m_aStates.top().setRunType(RTFParserState::RunType::NONE); + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_bidi, pValue); + } + break; + case RTF_LTRROW: + case RTF_RTLROW: + m_aStates.top().setRunType(RTFParserState::RunType::NONE); + m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TblPrBase_bidiVisual, + new RTFValue(int(nKeyword == RTF_RTLROW))); + break; + case RTF_LTRCH: + // dmapper does not support this. + if (m_aStates.top().getRunType() == RTFParserState::RunType::RTLCH_LTRCH_1) + m_aStates.top().setRunType(RTFParserState::RunType::RTLCH_LTRCH_2); + else + m_aStates.top().setRunType(RTFParserState::RunType::LTRCH_RTLCH_1); + break; + case RTF_RTLCH: + if (m_aStates.top().getRunType() == RTFParserState::RunType::LTRCH_RTLCH_1) + m_aStates.top().setRunType(RTFParserState::RunType::LTRCH_RTLCH_2); + else + m_aStates.top().setRunType(RTFParserState::RunType::RTLCH_LTRCH_1); + + if (m_aDefaultState.getCurrentEncoding() == RTL_TEXTENCODING_MS_1255) + m_aStates.top().setCurrentEncoding(m_aDefaultState.getCurrentEncoding()); + break; + case RTF_ULNONE: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Underline_none); + m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_Underline_val, pValue); + } + break; + case RTF_NONSHPPICT: + case RTF_MMATHPICT: // Picture group used by readers not understanding \moMath group + m_aStates.top().setDestination(Destination::SKIP); + break; + case RTF_CLBRDRT: + case RTF_CLBRDRL: + case RTF_CLBRDRB: + case RTF_CLBRDRR: + { + RTFSprms aAttributes; + RTFSprms aSprms; + auto pValue = new RTFValue(aAttributes, aSprms); + switch (nKeyword) + { + case RTF_CLBRDRT: + nParam = NS_ooxml::LN_CT_TcBorders_top; + break; + case RTF_CLBRDRL: + nParam = NS_ooxml::LN_CT_TcBorders_left; + break; + case RTF_CLBRDRB: + nParam = NS_ooxml::LN_CT_TcBorders_bottom; + break; + case RTF_CLBRDRR: + nParam = NS_ooxml::LN_CT_TcBorders_right; + break; + default: + break; + } + putNestedSprm(m_aStates.top().getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_tcBorders, + nParam, pValue); + m_aStates.top().setBorderState(RTFBorderState::CELL); + } + break; + case RTF_PGBRDRT: + case RTF_PGBRDRL: + case RTF_PGBRDRB: + case RTF_PGBRDRR: + { + RTFSprms aAttributes; + RTFSprms aSprms; + auto pValue = new RTFValue(aAttributes, aSprms); + switch (nKeyword) + { + case RTF_PGBRDRT: + nParam = NS_ooxml::LN_CT_PageBorders_top; + break; + case RTF_PGBRDRL: + nParam = NS_ooxml::LN_CT_PageBorders_left; + break; + case RTF_PGBRDRB: + nParam = NS_ooxml::LN_CT_PageBorders_bottom; + break; + case RTF_PGBRDRR: + nParam = NS_ooxml::LN_CT_PageBorders_right; + break; + default: + break; + } + putNestedSprm(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgBorders, nParam, pValue); + m_aStates.top().setBorderState(RTFBorderState::PAGE); + } + break; + case RTF_BRDRT: + case RTF_BRDRL: + case RTF_BRDRB: + case RTF_BRDRR: + { + RTFSprms aAttributes; + RTFSprms aSprms; + auto pValue = new RTFValue(aAttributes, aSprms); + switch (nKeyword) + { + case RTF_BRDRT: + nParam = getParagraphBorder(0); + break; + case RTF_BRDRL: + nParam = getParagraphBorder(1); + break; + case RTF_BRDRB: + nParam = getParagraphBorder(2); + break; + case RTF_BRDRR: + nParam = getParagraphBorder(3); + break; + default: + break; + } + putNestedSprm(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PrBase_pBdr, nParam, + pValue); + m_aStates.top().setBorderState(RTFBorderState::PARAGRAPH); + } + break; + case RTF_CHBRDR: + { + RTFSprms aAttributes; + auto pValue = new RTFValue(aAttributes); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_bdr, pValue); + m_aStates.top().setBorderState(RTFBorderState::CHARACTER); + } + break; + case RTF_CLMGF: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_restart); + m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_hMerge, pValue); + } + break; + case RTF_CLMRG: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_continue); + m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_hMerge, pValue); + } + break; + case RTF_CLVMGF: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_restart); + m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_vMerge, pValue); + } + break; + case RTF_CLVMRG: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_Merge_continue); + m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_vMerge, pValue); + } + break; + case RTF_CLVERTALT: + case RTF_CLVERTALC: + case RTF_CLVERTALB: + { + switch (nKeyword) + { + case RTF_CLVERTALT: + nParam = NS_ooxml::LN_Value_ST_VerticalJc_top; + break; + case RTF_CLVERTALC: + nParam = NS_ooxml::LN_Value_ST_VerticalJc_center; + break; + case RTF_CLVERTALB: + nParam = NS_ooxml::LN_Value_ST_VerticalJc_bottom; + break; + default: + break; + } + auto pValue = new RTFValue(nParam); + m_aStates.top().getTableCellSprms().set(NS_ooxml::LN_CT_TcPrBase_vAlign, pValue); + } + break; + case RTF_TRKEEP: + { + auto pValue = new RTFValue(1); + m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TrPrBase_cantSplit, pValue); + } + break; + case RTF_SECTUNLOCKED: + { + auto pValue = new RTFValue(0); + m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_formProt, pValue); + } + break; + case RTF_PGNBIDIA: + case RTF_PGNBIDIB: + // These should be mapped to NS_ooxml::LN_EG_SectPrContents_pgNumType, but dmapper has no API for that at the moment. + break; + case RTF_LOCH: + m_aStates.top().setRunType(RTFParserState::RunType::LOCH); + break; + case RTF_HICH: + m_aStates.top().setRunType(RTFParserState::RunType::HICH); + break; + case RTF_DBCH: + m_aStates.top().setRunType(RTFParserState::RunType::DBCH); + break; + case RTF_TITLEPG: + { + auto pValue = new RTFValue(1); + m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_titlePg, pValue); + } + break; + case RTF_SUPER: + { + // Make sure character properties are not lost if the document + // starts with a footnote. + if (!isStyleSheetImport()) + { + checkFirstRun(); + checkNeedPap(); + } + + if (!m_aStates.top().getCurrentBuffer()) + m_aStates.top().setCurrentBuffer(&m_aSuperBuffer); + + auto pValue = new RTFValue("superscript"); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_vertAlign, pValue); + } + break; + case RTF_SUB: + { + auto pValue = new RTFValue("subscript"); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_vertAlign, pValue); + } + break; + case RTF_NOSUPERSUB: + { + if (m_aStates.top().getCurrentBuffer() == &m_aSuperBuffer) + { + replayBuffer(m_aSuperBuffer, nullptr, nullptr); + m_aStates.top().setCurrentBuffer(nullptr); + } + m_aStates.top().getCharacterSprms().erase(NS_ooxml::LN_EG_RPrBase_vertAlign); + } + break; + case RTF_LINEPPAGE: + case RTF_LINECONT: + { + auto pValue = new RTFValue(nKeyword == RTF_LINEPPAGE + ? NS_ooxml::LN_Value_ST_LineNumberRestart_newPage + : NS_ooxml::LN_Value_ST_LineNumberRestart_continuous); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_lnNumType, + NS_ooxml::LN_CT_LineNumber_restart, pValue); + } + break; + case RTF_AENDDOC: + // Noop, this is the default in Writer. + case RTF_AENDNOTES: + // Noop + case RTF_AFTNRSTCONT: + // Noop, this is the default in Writer. + case RTF_AFTNRESTART: + // Noop + case RTF_FTNBJ: + // Noop, this is the default in Writer. + break; + case RTF_ENDDOC: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_RestartNumber_eachSect); + putNestedSprm(m_aDefaultState.getParagraphSprms(), + NS_ooxml::LN_EG_SectPrContents_footnotePr, + NS_ooxml::LN_EG_FtnEdnNumProps_numRestart, pValue); + } + break; + case RTF_NOLINE: + eraseNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_lnNumType, + NS_ooxml::LN_CT_LineNumber_distance); + break; + case RTF_FORMSHADE: + // Noop, this is the default in Writer. + break; + case RTF_PNGBLIP: + m_aStates.top().getPicture().eStyle = RTFBmpStyle::PNG; + break; + case RTF_JPEGBLIP: + m_aStates.top().getPicture().eStyle = RTFBmpStyle::JPEG; + break; + case RTF_POSYT: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, + NS_ooxml::LN_Value_doc_ST_YAlign_top); + break; + case RTF_POSYB: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, + NS_ooxml::LN_Value_doc_ST_YAlign_bottom); + break; + case RTF_POSYC: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, + NS_ooxml::LN_Value_doc_ST_YAlign_center); + break; + case RTF_POSYIN: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, + NS_ooxml::LN_Value_doc_ST_YAlign_inside); + break; + case RTF_POSYOUT: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, + NS_ooxml::LN_Value_doc_ST_YAlign_outside); + break; + case RTF_POSYIL: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, + NS_ooxml::LN_Value_doc_ST_YAlign_inline); + break; + + case RTF_PHMRG: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hAnchor, + NS_ooxml::LN_Value_doc_ST_HAnchor_margin); + break; + case RTF_PVMRG: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vAnchor, + NS_ooxml::LN_Value_doc_ST_VAnchor_margin); + break; + case RTF_PHPG: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hAnchor, + NS_ooxml::LN_Value_doc_ST_HAnchor_page); + break; + case RTF_PVPG: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vAnchor, + NS_ooxml::LN_Value_doc_ST_VAnchor_page); + break; + case RTF_PHCOL: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hAnchor, + NS_ooxml::LN_Value_doc_ST_HAnchor_text); + break; + case RTF_PVPARA: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vAnchor, + NS_ooxml::LN_Value_doc_ST_VAnchor_text); + break; + + case RTF_POSXC: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign, + NS_ooxml::LN_Value_doc_ST_XAlign_center); + break; + case RTF_POSXI: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign, + NS_ooxml::LN_Value_doc_ST_XAlign_inside); + break; + case RTF_POSXO: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign, + NS_ooxml::LN_Value_doc_ST_XAlign_outside); + break; + case RTF_POSXL: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign, + NS_ooxml::LN_Value_doc_ST_XAlign_left); + break; + case RTF_POSXR: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign, + NS_ooxml::LN_Value_doc_ST_XAlign_right); + break; + + case RTF_DPLINE: + case RTF_DPRECT: + case RTF_DPELLIPSE: + case RTF_DPTXBX: + case RTF_DPPOLYLINE: + case RTF_DPPOLYGON: + { + sal_Int32 nType = 0; + switch (nKeyword) + { + case RTF_DPLINE: + { + uno::Reference xShape( + getModelFactory()->createInstance("com.sun.star.drawing.LineShape"), + uno::UNO_QUERY); + m_aStates.top().getDrawingObject().setShape(xShape); + break; + } + case RTF_DPPOLYLINE: + { + // The reason this is not a simple CustomShape is that in the old syntax we have no ViewBox info. + uno::Reference xShape( + getModelFactory()->createInstance("com.sun.star.drawing.PolyLineShape"), + uno::UNO_QUERY); + m_aStates.top().getDrawingObject().setShape(xShape); + break; + } + case RTF_DPPOLYGON: + { + uno::Reference xShape( + getModelFactory()->createInstance("com.sun.star.drawing.PolyPolygonShape"), + uno::UNO_QUERY); + m_aStates.top().getDrawingObject().setShape(xShape); + break; + } + case RTF_DPRECT: + { + uno::Reference xShape( + getModelFactory()->createInstance("com.sun.star.drawing.RectangleShape"), + uno::UNO_QUERY); + m_aStates.top().getDrawingObject().setShape(xShape); + break; + } + case RTF_DPELLIPSE: + nType = ESCHER_ShpInst_Ellipse; + break; + case RTF_DPTXBX: + { + uno::Reference xShape( + getModelFactory()->createInstance("com.sun.star.text.TextFrame"), + uno::UNO_QUERY); + m_aStates.top().getDrawingObject().setShape(xShape); + std::vector aDefaults + = RTFSdrImport::getTextFrameDefaults(false); + for (const auto& rDefault : aDefaults) + { + if (!findPropertyName( + m_aStates.top().getDrawingObject().getPendingProperties(), + rDefault.Name)) + m_aStates.top().getDrawingObject().getPendingProperties().push_back( + rDefault); + } + checkFirstRun(); + Mapper().startShape(m_aStates.top().getDrawingObject().getShape()); + m_aStates.top().getDrawingObject().setHadShapeText(true); + } + break; + default: + break; + } + if (nType) + { + uno::Reference xShape( + getModelFactory()->createInstance("com.sun.star.drawing.CustomShape"), + uno::UNO_QUERY); + m_aStates.top().getDrawingObject().setShape(xShape); + } + uno::Reference xDrawSupplier(m_xDstDoc, uno::UNO_QUERY); + uno::Reference xPropertySet( + m_aStates.top().getDrawingObject().getShape(), uno::UNO_QUERY); + m_aStates.top().getDrawingObject().setPropertySet(xPropertySet); + if (xDrawSupplier.is()) + { + uno::Reference xShapes = xDrawSupplier->getDrawPage(); + if (xShapes.is() && nKeyword != RTF_DPTXBX) + { + // set default VertOrient before inserting + m_aStates.top().getDrawingObject().getPropertySet()->setPropertyValue( + "VertOrient", uno::makeAny(text::VertOrientation::NONE)); + xShapes->add(m_aStates.top().getDrawingObject().getShape()); + } + } + if (nType) + { + uno::Reference xDefaulter( + m_aStates.top().getDrawingObject().getShape(), uno::UNO_QUERY); + xDefaulter->createCustomShapeDefaults(OUString::number(nType)); + } + std::vector& rPendingProperties + = m_aStates.top().getDrawingObject().getPendingProperties(); + for (const auto& rPendingProperty : rPendingProperties) + m_aStates.top().getDrawingObject().getPropertySet()->setPropertyValue( + rPendingProperty.Name, rPendingProperty.Value); + m_pSdrImport->resolveDhgt(m_aStates.top().getDrawingObject().getPropertySet(), + m_aStates.top().getDrawingObject().getDhgt(), + /*bOldStyle=*/true); + } + break; + case RTF_DOBXMARGIN: + case RTF_DOBYMARGIN: + { + beans::PropertyValue aPropertyValue; + aPropertyValue.Name + = (nKeyword == RTF_DOBXMARGIN ? OUStringLiteral("HoriOrientRelation") + : OUStringLiteral("VertOrientRelation")); + aPropertyValue.Value <<= text::RelOrientation::PAGE_PRINT_AREA; + m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue); + } + break; + case RTF_DOBXPAGE: + case RTF_DOBYPAGE: + { + beans::PropertyValue aPropertyValue; + aPropertyValue.Name + = (nKeyword == RTF_DOBXPAGE ? OUStringLiteral("HoriOrientRelation") + : OUStringLiteral("VertOrientRelation")); + aPropertyValue.Value <<= text::RelOrientation::PAGE_FRAME; + m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue); + } + break; + case RTF_DOBYPARA: + { + beans::PropertyValue aPropertyValue; + aPropertyValue.Name = "VertOrientRelation"; + aPropertyValue.Value <<= text::RelOrientation::FRAME; + m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue); + } + break; + case RTF_CONTEXTUALSPACE: + { + auto pValue = new RTFValue(1); + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_contextualSpacing, + pValue); + } + break; + case RTF_LINKSTYLES: + { + auto pValue = new RTFValue(1); + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_linkStyles, pValue); + } + break; + case RTF_PNLVLBODY: + { + auto pValue = new RTFValue(2); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_AbstractNum_nsid, pValue); + } + break; + case RTF_PNDEC: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_decimal); + putNestedAttribute(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_Lvl_numFmt, + NS_ooxml::LN_CT_NumFmt_val, pValue); + } + break; + case RTF_PNLVLBLT: + { + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_AbstractNum_nsid, + new RTFValue(1)); + putNestedAttribute(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_Lvl_numFmt, + NS_ooxml::LN_CT_NumFmt_val, + new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_bullet)); + } + break; + case RTF_LANDSCAPE: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_PageOrientation_landscape); + putNestedAttribute(m_aDefaultState.getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_orient, + pValue); + [[fallthrough]]; // set the default + current value + } + case RTF_LNDSCPSXN: + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_PageOrientation_landscape); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_orient, + pValue); + } + break; + case RTF_SHPBXPAGE: + m_aStates.top().getShape().setHoriOrientRelation(text::RelOrientation::PAGE_FRAME); + m_aStates.top().getShape().setHoriOrientRelationToken( + NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromH_page); + break; + case RTF_SHPBYPAGE: + m_aStates.top().getShape().setVertOrientRelation(text::RelOrientation::PAGE_FRAME); + m_aStates.top().getShape().setVertOrientRelationToken( + NS_ooxml::LN_Value_wordprocessingDrawing_ST_RelFromV_page); + break; + case RTF_DPLINEHOLLOW: + m_aStates.top().getDrawingObject().setFLine(0); + break; + case RTF_DPROUNDR: + if (m_aStates.top().getDrawingObject().getPropertySet().is()) + // Seems this old syntax has no way to specify a custom radius, and this is the default + m_aStates.top().getDrawingObject().getPropertySet()->setPropertyValue( + "CornerRadius", uno::makeAny(sal_Int32(83))); + break; + case RTF_NOWRAP: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_wrap, + NS_ooxml::LN_Value_doc_ST_Wrap_notBeside); + break; + case RTF_MNOR: + m_bMathNor = true; + break; + case RTF_REVISIONS: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_trackRevisions, new RTFValue(1)); + break; + case RTF_BRDRSH: + putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_shadow, new RTFValue(1)); + break; + case RTF_NOCOLBAL: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Compat_noColumnBalance, new RTFValue(1)); + break; + case RTF_MARGMIRROR: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_mirrorMargins, new RTFValue(1)); + break; + case RTF_SAUTOUPD: + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Style_autoRedefine, + new RTFValue(1)); + break; + case RTF_WIDOWCTRL: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_widowControl, new RTFValue(1)); + break; + case RTF_LINEBETCOL: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_cols, NS_ooxml::LN_CT_Columns_sep, + new RTFValue(1)); + break; + case RTF_PGNRESTART: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgNumType, + NS_ooxml::LN_CT_PageNumber_start, new RTFValue(1)); + break; + case RTF_PGNUCLTR: + { + auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_upperLetter); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgNumType, + NS_ooxml::LN_CT_PageNumber_fmt, pIntValue); + } + break; + case RTF_PGNLCLTR: + { + auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgNumType, + NS_ooxml::LN_CT_PageNumber_fmt, pIntValue); + } + break; + case RTF_PGNUCRM: + { + auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_upperRoman); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgNumType, + NS_ooxml::LN_CT_PageNumber_fmt, pIntValue); + } + break; + case RTF_PGNLCRM: + { + auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgNumType, + NS_ooxml::LN_CT_PageNumber_fmt, pIntValue); + } + break; + case RTF_PGNDEC: + { + auto pIntValue = new RTFValue(NS_ooxml::LN_Value_ST_NumberFormat_decimal); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgNumType, + NS_ooxml::LN_CT_PageNumber_fmt, pIntValue); + } + break; + case RTF_HTMAUTSP: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Compat_doNotUseHTMLParagraphAutoSpacing, + new RTFValue(0)); + break; + case RTF_DNTBLNSBDB: + // tdf#128428 switch off longer space sequence + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_longerSpaceSequence, + new RTFValue(0)); + break; + default: + { + SAL_INFO("writerfilter", "TODO handle flag '" << keywordToString(nKeyword) << "'"); + aSkip.setParsed(false); + } + break; + } + return RTFError::OK; +} + +} // namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdispatchsymbol.cxx b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx new file mode 100644 index 000000000..ff13dedcf --- /dev/null +++ b/writerfilter/source/rtftok/rtfdispatchsymbol.cxx @@ -0,0 +1,432 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfdocumentimpl.hxx" + +#include +#include + +#include + +#include + +#include "rtfreferenceproperties.hxx" +#include "rtfskipdestination.hxx" + +using namespace com::sun::star; + +namespace writerfilter::rtftok +{ +RTFError RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) +{ + setNeedSect(true); + if (nKeyword != RTF_HEXCHAR) + checkUnicode(/*bUnicode =*/true, /*bHex =*/true); + else + checkUnicode(/*bUnicode =*/true, /*bHex =*/false); + RTFSkipDestination aSkip(*this); + + if (RTF_LINE == nKeyword) + { + // very special handling since text() will eat lone '\n' + singleChar('\n'); + return RTFError::OK; + } + // Trivial symbols + sal_uInt8 cCh = 0; + switch (nKeyword) + { + case RTF_TAB: + cCh = '\t'; + break; + case RTF_BACKSLASH: + cCh = '\\'; + break; + case RTF_LBRACE: + cCh = '{'; + break; + case RTF_RBRACE: + cCh = '}'; + break; + case RTF_EMDASH: + cCh = 151; + break; + case RTF_ENDASH: + cCh = 150; + break; + case RTF_BULLET: + cCh = 149; + break; + case RTF_LQUOTE: + cCh = 145; + break; + case RTF_RQUOTE: + cCh = 146; + break; + case RTF_LDBLQUOTE: + cCh = 147; + break; + case RTF_RDBLQUOTE: + cCh = 148; + break; + default: + break; + } + if (cCh > 0) + { + OUString aStr(OStringToOUString(OString(cCh), RTL_TEXTENCODING_MS_1252)); + text(aStr); + return RTFError::OK; + } + + switch (nKeyword) + { + case RTF_IGNORE: + { + m_bSkipUnknown = true; + aSkip.setReset(false); + return RTFError::OK; + } + break; + case RTF_PAR: + { + if (m_aStates.top().getDestination() == Destination::FOOTNOTESEPARATOR) + break; // just ignore it - only thing we read in here is CHFTNSEP + checkFirstRun(); + bool bNeedPap = m_bNeedPap; + checkNeedPap(); + if (bNeedPap) + runProps(); + if (!m_aStates.top().getCurrentBuffer()) + { + parBreak(); + // Not in table? Reset max width. + if (m_nCellxMax) + { + // Was in table, but not anymore -> tblEnd. + RTFSprms aAttributes; + RTFSprms aSprms; + aSprms.set(NS_ooxml::LN_tblEnd, new RTFValue(1)); + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aAttributes, aSprms); + Mapper().props(pProperties); + } + m_nCellxMax = 0; + } + else if (m_aStates.top().getDestination() != Destination::SHAPETEXT) + { + RTFValue::Pointer_t pValue; + m_aStates.top().getCurrentBuffer()->push_back(Buf_t(BUFFER_PAR, pValue, nullptr)); + } + // but don't emit properties yet, since they may change till the first text token arrives + m_bNeedPap = true; + if (!m_aStates.top().getFrame().inFrame()) + m_bNeedPar = false; + m_bNeedFinalPar = false; + } + break; + case RTF_SECT: + { + m_bHadSect = true; + if (m_bIgnoreNextContSectBreak) + m_bIgnoreNextContSectBreak = false; + else + { + sectBreak(); + if (m_nResetBreakOnSectBreak != RTF_invalid) + { + // this should run on _second_ \sect after \page + dispatchSymbol(m_nResetBreakOnSectBreak); // lazy reset + m_nResetBreakOnSectBreak = RTF_invalid; + m_bNeedSect = false; // dispatchSymbol set it + } + } + } + break; + case RTF_NOBREAK: + { + OUString aStr(SVT_HARD_SPACE); + text(aStr); + } + break; + case RTF_NOBRKHYPH: + { + OUString aStr(SVT_HARD_HYPHEN); + text(aStr); + } + break; + case RTF_OPTHYPH: + { + OUString aStr(SVT_SOFT_HYPHEN); + text(aStr); + } + break; + case RTF_HEXCHAR: + m_aStates.top().setInternalState(RTFInternalState::HEX); + break; + case RTF_CELL: + case RTF_NESTCELL: + { + if (nKeyword == RTF_CELL) + m_bAfterCellBeforeRow = true; + + checkFirstRun(); + if (m_bNeedPap) + { + // There were no runs in the cell, so we need to send paragraph and character properties here. + auto pPValue = new RTFValue(m_aStates.top().getParagraphAttributes(), + m_aStates.top().getParagraphSprms()); + bufferProperties(m_aTableBufferStack.back(), pPValue, nullptr); + auto pCValue = new RTFValue(m_aStates.top().getCharacterAttributes(), + m_aStates.top().getCharacterSprms()); + bufferProperties(m_aTableBufferStack.back(), pCValue, nullptr); + } + + RTFValue::Pointer_t pValue; + m_aTableBufferStack.back().emplace_back(Buf_t(BUFFER_CELLEND, pValue, nullptr)); + m_bNeedPap = true; + } + break; + case RTF_NESTROW: + { + tools::SvRef const pBuffer( + new TableRowBuffer(m_aTableBufferStack.back(), m_aNestedTableCellsSprms, + m_aNestedTableCellsAttributes, m_nNestedCells)); + prepareProperties(m_aStates.top(), pBuffer->GetParaProperties(), + pBuffer->GetFrameProperties(), pBuffer->GetRowProperties(), + m_nNestedCells, m_nNestedCurrentCellX - m_nNestedTRLeft); + + if (m_aTableBufferStack.size() == 1 || !m_aStates.top().getCurrentBuffer()) + { + throw io::WrongFormatException("mismatch between \\itap and number of \\nestrow", + nullptr); + } + assert(m_aStates.top().getCurrentBuffer() == &m_aTableBufferStack.back()); + // note: there may be several states pointing to table buffer! + for (std::size_t i = 0; i < m_aStates.size(); ++i) + { + if (m_aStates[i].getCurrentBuffer() == &m_aTableBufferStack.back()) + { + m_aStates[i].setCurrentBuffer( + &m_aTableBufferStack[m_aTableBufferStack.size() - 2]); + } + } + m_aTableBufferStack.pop_back(); + m_aTableBufferStack.back().emplace_back( + Buf_t(BUFFER_NESTROW, RTFValue::Pointer_t(), pBuffer)); + + m_aNestedTableCellsSprms.clear(); + m_aNestedTableCellsAttributes.clear(); + m_nNestedCells = 0; + m_bNeedPap = true; + } + break; + case RTF_ROW: + { + m_bAfterCellBeforeRow = false; + if (m_aStates.top().getTableRowWidthAfter() > 0) + { + // Add fake cellx / cell, RTF equivalent of + // OOXMLFastContextHandlerTextTableRow::handleGridAfter(). + auto pXValue = new RTFValue(m_aStates.top().getTableRowWidthAfter()); + m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, + RTFOverwrite::NO_APPEND); + dispatchSymbol(RTF_CELL); + + // Adjust total width, which is done in the \cellx handler for normal cells. + m_nTopLevelCurrentCellX += m_aStates.top().getTableRowWidthAfter(); + + m_aStates.top().setTableRowWidthAfter(0); + } + + bool bRestored = false; + // Ending a row, but no cells defined? + // See if there was an invalid table row reset, so we can restore cell infos to help invalid documents. + if (!m_nTopLevelCurrentCellX && m_nBackupTopLevelCurrentCellX) + { + restoreTableRowProperties(); + bRestored = true; + } + + // If the right edge of the last cell (row width) is smaller than the width of some other row, mimic WW8TabDesc::CalcDefaults(): resize the last cell + const int MINLAY = 23; // sw/inc/swtypes.hxx, minimal possible size of frames. + if ((m_nCellxMax - m_nTopLevelCurrentCellX) >= MINLAY) + { + auto pXValueLast = m_aStates.top().getTableRowSprms().find( + NS_ooxml::LN_CT_TblGridBase_gridCol, false); + const int nXValueLast = pXValueLast ? pXValueLast->getInt() : 0; + auto pXValue = new RTFValue(nXValueLast + m_nCellxMax - m_nTopLevelCurrentCellX); + m_aStates.top().getTableRowSprms().eraseLast(NS_ooxml::LN_CT_TblGridBase_gridCol); + m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, + RTFOverwrite::NO_APPEND); + m_nTopLevelCurrentCellX = m_nCellxMax; + } + + if (m_nTopLevelCells) + { + // Make a backup before we start popping elements + m_aTableInheritingCellsSprms = m_aTopLevelTableCellsSprms; + m_aTableInheritingCellsAttributes = m_aTopLevelTableCellsAttributes; + m_nInheritingCells = m_nTopLevelCells; + } + else + { + // No table definition? Then inherit from the previous row + m_aTopLevelTableCellsSprms = m_aTableInheritingCellsSprms; + m_aTopLevelTableCellsAttributes = m_aTableInheritingCellsAttributes; + m_nTopLevelCells = m_nInheritingCells; + } + + while (m_aTableBufferStack.size() > 1) + { + SAL_WARN("writerfilter.rtf", "dropping extra table buffer"); + // note: there may be several states pointing to table buffer! + for (std::size_t i = 0; i < m_aStates.size(); ++i) + { + if (m_aStates[i].getCurrentBuffer() == &m_aTableBufferStack.back()) + { + m_aStates[i].setCurrentBuffer(&m_aTableBufferStack.front()); + } + } + m_aTableBufferStack.pop_back(); + } + + replayRowBuffer(m_aTableBufferStack.back(), m_aTopLevelTableCellsSprms, + m_aTopLevelTableCellsAttributes, m_nTopLevelCells); + + // The scope of the table cell defaults is one row. + m_aDefaultState.getTableCellSprms().clear(); + m_aStates.top().getTableCellSprms() = m_aDefaultState.getTableCellSprms(); + m_aStates.top().getTableCellAttributes() = m_aDefaultState.getTableCellAttributes(); + + writerfilter::Reference::Pointer_t paraProperties; + writerfilter::Reference::Pointer_t frameProperties; + writerfilter::Reference::Pointer_t rowProperties; + prepareProperties(m_aStates.top(), paraProperties, frameProperties, rowProperties, + m_nTopLevelCells, m_nTopLevelCurrentCellX - m_nTopLevelTRLeft); + sendProperties(paraProperties, frameProperties, rowProperties); + + m_bNeedPap = true; + m_bNeedFinalPar = true; + m_aTableBufferStack.back().clear(); + m_nTopLevelCells = 0; + + if (bRestored) + // We restored cell definitions, clear these now. + // This is necessary, as later cell definitions want to overwrite the restored ones. + resetTableRowProperties(); + } + break; + case RTF_COLUMN: + { + bool bColumns = false; // If we have multiple columns + RTFValue::Pointer_t pCols + = m_aStates.top().getSectionSprms().find(NS_ooxml::LN_EG_SectPrContents_cols); + if (pCols) + { + RTFValue::Pointer_t pNum = pCols->getAttributes().find(NS_ooxml::LN_CT_Columns_num); + if (pNum && pNum->getInt() > 1) + bColumns = true; + } + checkFirstRun(); + if (bColumns) + { + sal_uInt8 const sBreak[] = { 0xe }; + Mapper().startCharacterGroup(); + Mapper().text(sBreak, 1); + Mapper().endCharacterGroup(); + } + else + dispatchSymbol(RTF_PAGE); + } + break; + case RTF_CHFTN: + { + if (m_aStates.top().getCurrentBuffer() == &m_aSuperBuffer) + // Stop buffering, there will be no custom mark for this footnote or endnote. + m_aStates.top().setCurrentBuffer(nullptr); + break; + } + case RTF_PAGE: + { + // Ignore page breaks inside tables. + if (m_aStates.top().getCurrentBuffer() == &m_aTableBufferStack.back()) + break; + + // If we're inside a continuous section, we should send a section break, not a page one. + RTFValue::Pointer_t pBreak + = m_aStates.top().getSectionSprms().find(NS_ooxml::LN_EG_SectPrContents_type); + // Unless we're on a title page. + RTFValue::Pointer_t pTitlePg + = m_aStates.top().getSectionSprms().find(NS_ooxml::LN_EG_SectPrContents_titlePg); + if (((pBreak + && pBreak->getInt() + == static_cast(NS_ooxml::LN_Value_ST_SectionMark_continuous)) + || m_nResetBreakOnSectBreak == RTF_SBKNONE) + && !(pTitlePg && pTitlePg->getInt())) + { + if (m_bWasInFrame) + { + dispatchSymbol(RTF_PAR); + m_bWasInFrame = false; + } + sectBreak(); + // note: this will not affect the following section break + // but the one just pushed + dispatchFlag(RTF_SBKPAGE); + if (m_bNeedPar) + dispatchSymbol(RTF_PAR); + m_bIgnoreNextContSectBreak = true; + // arrange to clean up the synthetic RTF_SBKPAGE + m_nResetBreakOnSectBreak = RTF_SBKNONE; + } + else + { + checkFirstRun(); + checkNeedPap(); + sal_uInt8 const sBreak[] = { 0xc }; + Mapper().text(sBreak, 1); + if (!m_bNeedPap) + { + parBreak(); + m_bNeedPap = true; + } + m_bNeedCr = true; + } + } + break; + case RTF_CHPGN: + { + OUString aStr("PAGE"); + singleChar(cFieldStart); + text(aStr); + singleChar(cFieldSep, true); + singleChar(cFieldEnd); + } + break; + case RTF_CHFTNSEP: + { + static const sal_Unicode uFtnEdnSep = 0x3; + Mapper().utext(reinterpret_cast(&uFtnEdnSep), 1); + } + break; + default: + { + SAL_INFO("writerfilter.rtf", + "TODO handle symbol '" << keywordToString(nKeyword) << "'"); + aSkip.setParsed(false); + } + break; + } + return RTFError::OK; +} + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx b/writerfilter/source/rtftok/rtfdispatchvalue.cxx new file mode 100644 index 000000000..b43e85a23 --- /dev/null +++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx @@ -0,0 +1,1801 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfdocumentimpl.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "rtfcharsets.hxx" +#include "rtffly.hxx" +#include "rtfreferenceproperties.hxx" +#include "rtfskipdestination.hxx" + +#include +#include + +using namespace com::sun::star; + +namespace writerfilter +{ +static int getNumberFormat(int nParam) +{ + static const int aMap[] + = { NS_ooxml::LN_Value_ST_NumberFormat_decimal, + NS_ooxml::LN_Value_ST_NumberFormat_upperRoman, + NS_ooxml::LN_Value_ST_NumberFormat_lowerRoman, + NS_ooxml::LN_Value_ST_NumberFormat_upperLetter, + NS_ooxml::LN_Value_ST_NumberFormat_lowerLetter, + NS_ooxml::LN_Value_ST_NumberFormat_ordinal, + NS_ooxml::LN_Value_ST_NumberFormat_cardinalText, + NS_ooxml::LN_Value_ST_NumberFormat_ordinalText, + NS_ooxml::LN_Value_ST_NumberFormat_none, // Undefined in RTF 1.8 spec. + NS_ooxml::LN_Value_ST_NumberFormat_none, // Undefined in RTF 1.8 spec. + NS_ooxml::LN_Value_ST_NumberFormat_ideographDigital, + NS_ooxml::LN_Value_ST_NumberFormat_japaneseCounting, + NS_ooxml::LN_Value_ST_NumberFormat_aiueo, + NS_ooxml::LN_Value_ST_NumberFormat_iroha, + NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth, + NS_ooxml::LN_Value_ST_NumberFormat_decimalHalfWidth, + NS_ooxml::LN_Value_ST_NumberFormat_japaneseLegal, + NS_ooxml::LN_Value_ST_NumberFormat_japaneseDigitalTenThousand, + NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedCircleChinese, + NS_ooxml::LN_Value_ST_NumberFormat_decimalFullWidth2, + NS_ooxml::LN_Value_ST_NumberFormat_aiueoFullWidth, + NS_ooxml::LN_Value_ST_NumberFormat_irohaFullWidth, + NS_ooxml::LN_Value_ST_NumberFormat_decimalZero, + NS_ooxml::LN_Value_ST_NumberFormat_bullet, + NS_ooxml::LN_Value_ST_NumberFormat_ganada, + NS_ooxml::LN_Value_ST_NumberFormat_chosung, + NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedFullstop, + NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedParen, + NS_ooxml::LN_Value_ST_NumberFormat_decimalEnclosedCircleChinese, + NS_ooxml::LN_Value_ST_NumberFormat_ideographEnclosedCircle, + NS_ooxml::LN_Value_ST_NumberFormat_ideographTraditional, + NS_ooxml::LN_Value_ST_NumberFormat_ideographZodiac, + NS_ooxml::LN_Value_ST_NumberFormat_ideographZodiacTraditional, + NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseCounting, + NS_ooxml::LN_Value_ST_NumberFormat_ideographLegalTraditional, + NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseCountingThousand, + NS_ooxml::LN_Value_ST_NumberFormat_taiwaneseDigital, + NS_ooxml::LN_Value_ST_NumberFormat_chineseCounting, + NS_ooxml::LN_Value_ST_NumberFormat_chineseLegalSimplified, + NS_ooxml::LN_Value_ST_NumberFormat_chineseCountingThousand, + NS_ooxml::LN_Value_ST_NumberFormat_decimal, + NS_ooxml::LN_Value_ST_NumberFormat_koreanDigital, + NS_ooxml::LN_Value_ST_NumberFormat_koreanCounting, + NS_ooxml::LN_Value_ST_NumberFormat_koreanLegal, + NS_ooxml::LN_Value_ST_NumberFormat_koreanDigital2, + NS_ooxml::LN_Value_ST_NumberFormat_hebrew1, + NS_ooxml::LN_Value_ST_NumberFormat_arabicAlpha, + NS_ooxml::LN_Value_ST_NumberFormat_hebrew2, + NS_ooxml::LN_Value_ST_NumberFormat_arabicAbjad }; + const int nLen = SAL_N_ELEMENTS(aMap); + int nValue = 0; + if (nParam >= 0 && nParam < nLen) + nValue = aMap[nParam]; + else // 255 and the other cases. + nValue = NS_ooxml::LN_Value_ST_NumberFormat_none; + return nValue; +} + +namespace rtftok +{ +bool RTFDocumentImpl::dispatchTableSprmValue(RTFKeyword nKeyword, int nParam) +{ + int nSprm = 0; + tools::SvRef pIntValue(new RTFValue(nParam)); + switch (nKeyword) + { + case RTF_LEVELJC: + { + nSprm = NS_ooxml::LN_CT_Lvl_lvlJc; + int nValue = 0; + switch (nParam) + { + case 0: + nValue = NS_ooxml::LN_Value_ST_Jc_left; + break; + case 1: + nValue = NS_ooxml::LN_Value_ST_Jc_center; + break; + case 2: + nValue = NS_ooxml::LN_Value_ST_Jc_right; + break; + } + pIntValue = new RTFValue(nValue); + break; + } + case RTF_LEVELSTARTAT: + nSprm = NS_ooxml::LN_CT_Lvl_start; + break; + case RTF_LEVELPICTURE: + nSprm = NS_ooxml::LN_CT_Lvl_lvlPicBulletId; + break; + case RTF_SBASEDON: + nSprm = NS_ooxml::LN_CT_Style_basedOn; + pIntValue = new RTFValue(getStyleName(nParam)); + break; + default: + break; + } + if (nSprm > 0) + { + m_aStates.top().getTableSprms().set(nSprm, pIntValue); + return true; + } + if (nKeyword == RTF_LEVELNFC) + { + pIntValue = new RTFValue(getNumberFormat(nParam)); + putNestedAttribute(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_Lvl_numFmt, + NS_ooxml::LN_CT_NumFmt_val, pIntValue); + return true; + } + + return false; +} + +bool RTFDocumentImpl::dispatchCharacterSprmValue(RTFKeyword nKeyword, int nParam) +{ + int nSprm = 0; + tools::SvRef pIntValue(new RTFValue(nParam)); + + switch (nKeyword) + { + case RTF_FS: + case RTF_AFS: + switch (m_aStates.top().getRunType()) + { + case RTFParserState::RunType::HICH: + case RTFParserState::RunType::RTLCH_LTRCH_1: + case RTFParserState::RunType::LTRCH_RTLCH_2: + case RTFParserState::RunType::DBCH: + nSprm = NS_ooxml::LN_EG_RPrBase_szCs; + break; + case RTFParserState::RunType::NONE: + case RTFParserState::RunType::LOCH: + case RTFParserState::RunType::LTRCH_RTLCH_1: + case RTFParserState::RunType::RTLCH_LTRCH_2: + default: + nSprm = NS_ooxml::LN_EG_RPrBase_sz; + break; + } + break; + case RTF_EXPNDTW: + nSprm = NS_ooxml::LN_EG_RPrBase_spacing; + break; + case RTF_KERNING: + nSprm = NS_ooxml::LN_EG_RPrBase_kern; + break; + case RTF_CHARSCALEX: + nSprm = NS_ooxml::LN_EG_RPrBase_w; + break; + default: + break; + } + if (nSprm > 0) + { + m_aStates.top().getCharacterSprms().set(nSprm, pIntValue); + return true; + } + + return false; +} + +bool RTFDocumentImpl::dispatchCharacterAttributeValue(RTFKeyword nKeyword, int nParam) +{ + int nSprm = 0; + + switch (nKeyword) + { + case RTF_LANG: + case RTF_ALANG: + switch (m_aStates.top().getRunType()) + { + case RTFParserState::RunType::HICH: + case RTFParserState::RunType::RTLCH_LTRCH_1: + case RTFParserState::RunType::LTRCH_RTLCH_2: + nSprm = NS_ooxml::LN_CT_Language_bidi; + break; + case RTFParserState::RunType::DBCH: + nSprm = NS_ooxml::LN_CT_Language_eastAsia; + break; + case RTFParserState::RunType::NONE: + case RTFParserState::RunType::LOCH: + case RTFParserState::RunType::LTRCH_RTLCH_1: + case RTFParserState::RunType::RTLCH_LTRCH_2: + default: + nSprm = NS_ooxml::LN_CT_Language_val; + break; + } + break; + case RTF_LANGFE: // this one is always CJK apparently + nSprm = NS_ooxml::LN_CT_Language_eastAsia; + break; + default: + break; + } + if (nSprm > 0) + { + LanguageTag aTag((LanguageType(static_cast(nParam)))); + auto pValue = new RTFValue(aTag.getBcp47()); + putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_lang, nSprm, + pValue); + // Language is a character property, but we should store it at a paragraph level as well for fields. + if (nKeyword == RTF_LANG && m_bNeedPap) + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_EG_RPrBase_lang, + nSprm, pValue); + return true; + } + + return false; +} + +bool RTFDocumentImpl::dispatchParagraphSprmValue(RTFKeyword nKeyword, int nParam) +{ + int nSprm = 0; + tools::SvRef pIntValue(new RTFValue(nParam)); + + switch (nKeyword) + { + case RTF_ITAP: + nSprm = NS_ooxml::LN_tblDepth; + // tdf#117268: If \itap0 is encountered inside tables (between \cellxN and \cell), then + // use the default value (1), as Word apparently does + if (nParam == 0 && (m_nTopLevelCells != 0 || m_nNestedCells != 0)) + { + nParam = 1; + pIntValue = new RTFValue(nParam); + } + break; + default: + break; + } + if (nSprm > 0) + { + m_aStates.top().getParagraphSprms().set(nSprm, pIntValue); + if (nKeyword == RTF_ITAP && nParam > 0) + { + while (m_aTableBufferStack.size() < sal::static_int_cast(nParam)) + { + m_aTableBufferStack.emplace_back(RTFBuffer_t()); + } + // Invalid tables may omit INTBL after ITAP + dispatchFlag(RTF_INTBL); // sets newly pushed buffer as current + assert(m_aStates.top().getCurrentBuffer() == &m_aTableBufferStack.back()); + } + return true; + } + + return false; +} + +bool RTFDocumentImpl::dispatchInfoValue(RTFKeyword nKeyword, int nParam) +{ + int nSprm = 0; + + switch (nKeyword) + { + case RTF_YR: + { + m_aStates.top().setYear(nParam); + nSprm = 1; + } + break; + case RTF_MO: + { + m_aStates.top().setMonth(nParam); + nSprm = 1; + } + break; + case RTF_DY: + { + m_aStates.top().setDay(nParam); + nSprm = 1; + } + break; + case RTF_HR: + { + m_aStates.top().setHour(nParam); + nSprm = 1; + } + break; + case RTF_MIN: + { + m_aStates.top().setMinute(nParam); + nSprm = 1; + } + break; + default: + break; + } + + return nSprm > 0; +} + +bool RTFDocumentImpl::dispatchFrameValue(RTFKeyword nKeyword, int nParam) +{ + Id nId = 0; + switch (nKeyword) + { + case RTF_ABSW: + nId = NS_ooxml::LN_CT_FramePr_w; + break; + case RTF_ABSH: + nId = NS_ooxml::LN_CT_FramePr_h; + break; + case RTF_POSX: + { + nId = NS_ooxml::LN_CT_FramePr_x; + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign, 0); + } + break; + case RTF_POSY: + { + nId = NS_ooxml::LN_CT_FramePr_y; + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, 0); + } + break; + default: + break; + } + + if (nId > 0) + { + m_bNeedPap = true; + // Don't try to support text frames inside tables for now. + if (m_aStates.top().getCurrentBuffer() != &m_aTableBufferStack.back()) + m_aStates.top().getFrame().setSprm(nId, nParam); + + return true; + } + + return false; +} + +bool RTFDocumentImpl::dispatchTableValue(RTFKeyword nKeyword, int nParam) +{ + int nSprm = 0; + tools::SvRef pIntValue(new RTFValue(nParam)); + + switch (nKeyword) + { + case RTF_CELLX: + { + int& rCurrentCellX( + (Destination::NESTEDTABLEPROPERTIES == m_aStates.top().getDestination()) + ? m_nNestedCurrentCellX + : m_nTopLevelCurrentCellX); + int nCellX = nParam - rCurrentCellX; + const int COL_DFLT_WIDTH + = 41; // sw/source/filter/inc/wrtswtbl.hxx, minimal possible width of cells. + if (!nCellX) + nCellX = COL_DFLT_WIDTH; + + // If there is a negative left margin, then the first cellx is relative to that. + RTFValue::Pointer_t pTblInd + = m_aStates.top().getTableRowSprms().find(NS_ooxml::LN_CT_TblPrBase_tblInd); + if (rCurrentCellX == 0 && pTblInd) + { + RTFValue::Pointer_t pWidth + = pTblInd->getAttributes().find(NS_ooxml::LN_CT_TblWidth_w); + if (pWidth && pWidth->getInt() < 0) + nCellX = -1 * (pWidth->getInt() - nParam); + } + + rCurrentCellX = nParam; + auto pXValue = new RTFValue(nCellX); + m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, + RTFOverwrite::NO_APPEND); + if (Destination::NESTEDTABLEPROPERTIES == m_aStates.top().getDestination()) + { + m_nNestedCells++; + // Push cell properties. + m_aNestedTableCellsSprms.push_back(m_aStates.top().getTableCellSprms()); + m_aNestedTableCellsAttributes.push_back(m_aStates.top().getTableCellAttributes()); + } + else + { + m_nTopLevelCells++; + // Push cell properties. + m_aTopLevelTableCellsSprms.push_back(m_aStates.top().getTableCellSprms()); + m_aTopLevelTableCellsAttributes.push_back(m_aStates.top().getTableCellAttributes()); + } + + m_aStates.top().getTableCellSprms() = m_aDefaultState.getTableCellSprms(); + m_aStates.top().getTableCellAttributes() = m_aDefaultState.getTableCellAttributes(); + // We assume text after a row definition always belongs to the table, to handle text before the real INTBL token + dispatchFlag(RTF_INTBL); + if (!m_nCellxMax) + { + // Wasn't in table, but now is -> tblStart. + RTFSprms aAttributes; + RTFSprms aSprms; + aSprms.set(NS_ooxml::LN_tblStart, new RTFValue(1)); + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aAttributes, aSprms); + Mapper().props(pProperties); + } + m_nCellxMax = std::max(m_nCellxMax, nParam); + return true; + } + break; + case RTF_TRRH: + { + OUString hRule("auto"); + if (nParam < 0) + { + tools::SvRef pAbsValue(new RTFValue(-nParam)); + std::swap(pIntValue, pAbsValue); + + hRule = "exact"; + } + else if (nParam > 0) + hRule = "atLeast"; + + putNestedAttribute(m_aStates.top().getTableRowSprms(), + NS_ooxml::LN_CT_TrPrBase_trHeight, NS_ooxml::LN_CT_Height_val, + pIntValue); + + auto pHRule = new RTFValue(hRule); + putNestedAttribute(m_aStates.top().getTableRowSprms(), + NS_ooxml::LN_CT_TrPrBase_trHeight, NS_ooxml::LN_CT_Height_hRule, + pHRule); + return true; + } + break; + case RTF_TRLEFT: + { + // the value is in twips + putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblInd, + NS_ooxml::LN_CT_TblWidth_type, + new RTFValue(NS_ooxml::LN_Value_ST_TblWidth_dxa)); + putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblInd, + NS_ooxml::LN_CT_TblWidth_w, new RTFValue(nParam)); + auto const aDestination = m_aStates.top().getDestination(); + int& rCurrentTRLeft((Destination::NESTEDTABLEPROPERTIES == aDestination) + ? m_nNestedTRLeft + : m_nTopLevelTRLeft); + int& rCurrentCellX((Destination::NESTEDTABLEPROPERTIES == aDestination) + ? m_nNestedCurrentCellX + : m_nTopLevelCurrentCellX); + rCurrentTRLeft = rCurrentCellX = nParam; + return true; + } + break; + case RTF_CLSHDNG: + { + int nValue = -1; + switch (nParam) + { + case 500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct5; + break; + case 1000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct10; + break; + case 1200: + nValue = NS_ooxml::LN_Value_ST_Shd_pct12; + break; + case 1500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct15; + break; + case 2000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct20; + break; + case 2500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct25; + break; + case 3000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct30; + break; + case 3500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct35; + break; + case 3700: + nValue = NS_ooxml::LN_Value_ST_Shd_pct37; + break; + case 4000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct40; + break; + case 4500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct45; + break; + case 5000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct50; + break; + case 5500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct55; + break; + case 6000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct60; + break; + case 6200: + nValue = NS_ooxml::LN_Value_ST_Shd_pct62; + break; + case 6500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct65; + break; + case 7000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct70; + break; + case 7500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct75; + break; + case 8000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct80; + break; + case 8500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct85; + break; + case 8700: + nValue = NS_ooxml::LN_Value_ST_Shd_pct87; + break; + case 9000: + nValue = NS_ooxml::LN_Value_ST_Shd_pct90; + break; + case 9500: + nValue = NS_ooxml::LN_Value_ST_Shd_pct95; + break; + default: + break; + } + if (nValue != -1) + putNestedAttribute(m_aStates.top().getTableCellSprms(), + NS_ooxml::LN_CT_TcPrBase_shd, NS_ooxml::LN_CT_Shd_val, + new RTFValue(nValue)); + return true; + } + break; + case RTF_CLPADB: + case RTF_CLPADL: + case RTF_CLPADR: + case RTF_CLPADT: + { + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_TblWidth_type, + new RTFValue(NS_ooxml::LN_Value_ST_TblWidth_dxa)); + aAttributes.set(NS_ooxml::LN_CT_TblWidth_w, new RTFValue(nParam)); + // Top and left is swapped, that's what Word does. + switch (nKeyword) + { + case RTF_CLPADB: + nSprm = NS_ooxml::LN_CT_TcMar_bottom; + break; + case RTF_CLPADL: + nSprm = NS_ooxml::LN_CT_TcMar_top; + break; + case RTF_CLPADR: + nSprm = NS_ooxml::LN_CT_TcMar_right; + break; + case RTF_CLPADT: + nSprm = NS_ooxml::LN_CT_TcMar_left; + break; + default: + break; + } + putNestedSprm(m_aStates.top().getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_tcMar, + nSprm, new RTFValue(aAttributes)); + return true; + } + break; + case RTF_TRPADDFB: + case RTF_TRPADDFL: + case RTF_TRPADDFR: + case RTF_TRPADDFT: + { + RTFSprms aAttributes; + switch (nParam) + { + case 3: + aAttributes.set(NS_ooxml::LN_CT_TblWidth_type, + new RTFValue(NS_ooxml::LN_Value_ST_TblWidth_dxa)); + break; + } + switch (nKeyword) + { + case RTF_TRPADDFB: + nSprm = NS_ooxml::LN_CT_TcMar_bottom; + break; + case RTF_TRPADDFL: + nSprm = NS_ooxml::LN_CT_TcMar_left; + break; + case RTF_TRPADDFR: + nSprm = NS_ooxml::LN_CT_TcMar_right; + break; + case RTF_TRPADDFT: + nSprm = NS_ooxml::LN_CT_TcMar_top; + break; + default: + break; + } + putNestedAttribute(m_aStates.top().getTableRowSprms(), + NS_ooxml::LN_CT_TblPrBase_tblCellMar, nSprm, + new RTFValue(aAttributes)); + // tdf#74795 also set on current cell, and as default for table cells + // (why isn't this done by domainmapper?) + putNestedAttribute(m_aStates.top().getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_tcMar, + nSprm, new RTFValue(aAttributes)); + putNestedAttribute(m_aDefaultState.getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_tcMar, + nSprm, new RTFValue(aAttributes)); + return true; + } + break; + case RTF_TRPADDB: + case RTF_TRPADDL: + case RTF_TRPADDR: + case RTF_TRPADDT: + { + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_TblWidth_w, new RTFValue(nParam)); + switch (nKeyword) + { + case RTF_TRPADDB: + nSprm = NS_ooxml::LN_CT_TcMar_bottom; + break; + case RTF_TRPADDL: + nSprm = NS_ooxml::LN_CT_TcMar_left; + break; + case RTF_TRPADDR: + nSprm = NS_ooxml::LN_CT_TcMar_right; + break; + case RTF_TRPADDT: + nSprm = NS_ooxml::LN_CT_TcMar_top; + break; + default: + break; + } + putNestedSprm(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblCellMar, + nSprm, new RTFValue(aAttributes)); + // tdf#74795 also set on current cell, and as default for table cells + // (why isn't this done by domainmapper?) + putNestedSprm(m_aStates.top().getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_tcMar, + nSprm, new RTFValue(aAttributes)); + putNestedSprm(m_aDefaultState.getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_tcMar, + nSprm, new RTFValue(aAttributes)); + return true; + } + break; + case RTF_TRGAPH: + // Half of the space between the cells of a table row: default left/right table cell margin. + if (nParam > 0) + { + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_TblWidth_type, + new RTFValue(NS_ooxml::LN_Value_ST_TblWidth_dxa)); + aAttributes.set(NS_ooxml::LN_CT_TblWidth_w, pIntValue); + // FIXME: this is wrong, it is half-gap, needs to be distinguished from margin! depending on TRPADDFL/TRPADDFR + putNestedSprm(m_aStates.top().getTableRowSprms(), + NS_ooxml::LN_CT_TblPrBase_tblCellMar, NS_ooxml::LN_CT_TblCellMar_left, + new RTFValue(aAttributes)); + putNestedSprm(m_aStates.top().getTableRowSprms(), + NS_ooxml::LN_CT_TblPrBase_tblCellMar, + NS_ooxml::LN_CT_TblCellMar_right, new RTFValue(aAttributes)); + } + return true; + break; + case RTF_TRFTSWIDTH: + putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblW, + NS_ooxml::LN_CT_TblWidth_type, pIntValue); + return true; + break; + case RTF_TRWWIDTH: + putNestedAttribute(m_aStates.top().getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblW, + NS_ooxml::LN_CT_TblWidth_w, pIntValue); + return true; + break; + default: + break; + } + + return false; +} + +RTFError RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) +{ + setNeedSect(true); + checkUnicode(/*bUnicode =*/nKeyword != RTF_U, /*bHex =*/true); + RTFSkipDestination aSkip(*this); + int nSprm = 0; + tools::SvRef pIntValue(new RTFValue(nParam)); + // Trivial table sprms. + if (dispatchTableSprmValue(nKeyword, nParam)) + { + return RTFError::OK; + } + + // Trivial character sprms. + if (dispatchCharacterSprmValue(nKeyword, nParam)) + { + return RTFError::OK; + } + + // Trivial character attributes. + if (dispatchCharacterAttributeValue(nKeyword, nParam)) + { + return RTFError::OK; + } + + // Trivial paragraph sprms. + if (dispatchParagraphSprmValue(nKeyword, nParam)) + { + return RTFError::OK; + } + + // Info group. + if (dispatchInfoValue(nKeyword, nParam)) + { + return RTFError::OK; + } + + // Frame size / position. + if (dispatchFrameValue(nKeyword, nParam)) + { + return RTFError::OK; + } + + // Table-related values. + if (dispatchTableValue(nKeyword, nParam)) + { + return RTFError::OK; + } + + // Then check for the more complex ones. + switch (nKeyword) + { + case RTF_F: + case RTF_AF: + switch (m_aStates.top().getRunType()) + { + case RTFParserState::RunType::HICH: + case RTFParserState::RunType::RTLCH_LTRCH_1: + case RTFParserState::RunType::LTRCH_RTLCH_2: + nSprm = NS_ooxml::LN_CT_Fonts_cs; + break; + case RTFParserState::RunType::DBCH: + nSprm = NS_ooxml::LN_CT_Fonts_eastAsia; + break; + case RTFParserState::RunType::NONE: + case RTFParserState::RunType::LOCH: + case RTFParserState::RunType::LTRCH_RTLCH_1: + case RTFParserState::RunType::RTLCH_LTRCH_2: + default: + nSprm = NS_ooxml::LN_CT_Fonts_ascii; + break; + } + + if (m_aStates.top().getDestination() == Destination::FONTTABLE + || m_aStates.top().getDestination() == Destination::FONTENTRY) + { + m_aFontIndexes.push_back(nParam); + m_nCurrentFontIndex = getFontIndex(nParam); + } + else if (m_aStates.top().getDestination() == Destination::LISTLEVEL) + { + RTFSprms aFontAttributes; + aFontAttributes.set(nSprm, new RTFValue(m_aFontNames[getFontIndex(nParam)])); + RTFSprms aRunPropsSprms; + aRunPropsSprms.set(NS_ooxml::LN_EG_RPrBase_rFonts, new RTFValue(aFontAttributes)); + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Lvl_rPr, + new RTFValue(RTFSprms(), aRunPropsSprms), + RTFOverwrite::NO_APPEND); + } + else + { + m_nCurrentFontIndex = getFontIndex(nParam); + auto pValue = new RTFValue(getFontName(m_nCurrentFontIndex)); + putNestedAttribute(m_aStates.top().getCharacterSprms(), + NS_ooxml::LN_EG_RPrBase_rFonts, nSprm, pValue); + if (nKeyword == RTF_F) + m_aStates.top().setCurrentEncoding(getEncoding(m_nCurrentFontIndex)); + } + break; + case RTF_RED: + m_aStates.top().getCurrentColor().SetRed(nParam); + break; + case RTF_GREEN: + m_aStates.top().getCurrentColor().SetGreen(nParam); + break; + case RTF_BLUE: + m_aStates.top().getCurrentColor().SetBlue(nParam); + break; + case RTF_FCHARSET: + { + // we always send text to the domain mapper in OUString, so no + // need to send encoding info + int i; + for (i = 0; i < nRTFEncodings; i++) + { + if (aRTFEncodings[i].charset == nParam) + break; + } + if (i == nRTFEncodings) + // not found + return RTFError::OK; + + m_nCurrentEncoding + = aRTFEncodings[i].codepage == 0 // Default (CP_ACP) + ? osl_getThreadTextEncoding() + : rtl_getTextEncodingFromWindowsCodePage(aRTFEncodings[i].codepage); + m_aStates.top().setCurrentEncoding(m_nCurrentEncoding); + } + break; + case RTF_ANSICPG: + case RTF_CPG: + { + rtl_TextEncoding nEncoding + = (nParam == 0) + ? utl_getWinTextEncodingFromLangStr(utl_getLocaleForGlobalDefaultEncoding()) + : rtl_getTextEncodingFromWindowsCodePage(nParam); + if (nKeyword == RTF_ANSICPG) + m_aDefaultState.setCurrentEncoding(nEncoding); + else + m_nCurrentEncoding = nEncoding; + m_aStates.top().setCurrentEncoding(nEncoding); + } + break; + case RTF_CF: + { + RTFSprms aAttributes; + auto pValue = new RTFValue(sal_uInt32(getColorTable(nParam))); + aAttributes.set(NS_ooxml::LN_CT_Color_val, pValue); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_color, + new RTFValue(aAttributes)); + } + break; + case RTF_S: + { + m_aStates.top().setCurrentStyleIndex(nParam); + + if (m_aStates.top().getDestination() == Destination::STYLESHEET + || m_aStates.top().getDestination() == Destination::STYLEENTRY) + { + m_nCurrentStyleIndex = nParam; + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_StyleType_paragraph); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_Style_type, + pValue); // paragraph style + } + else + { + OUString aName = getStyleName(nParam); + if (!aName.isEmpty()) + { + if (m_aStates.top().getDestination() == Destination::LISTLEVEL) + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Lvl_pStyle, + new RTFValue(aName)); + else + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_pStyle, + new RTFValue(aName)); + } + } + } + break; + case RTF_CS: + m_aStates.top().setCurrentCharacterStyleIndex(nParam); + if (m_aStates.top().getDestination() == Destination::STYLESHEET + || m_aStates.top().getDestination() == Destination::STYLEENTRY) + { + m_nCurrentStyleIndex = nParam; + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_StyleType_character); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_Style_type, + pValue); // character style + } + else + { + OUString aName = getStyleName(nParam); + if (!aName.isEmpty()) + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_rStyle, + new RTFValue(aName)); + } + break; + case RTF_DS: + if (m_aStates.top().getDestination() == Destination::STYLESHEET + || m_aStates.top().getDestination() == Destination::STYLEENTRY) + { + m_nCurrentStyleIndex = nParam; + auto pValue = new RTFValue(0); // TODO no value in enum StyleType? + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_Style_type, + pValue); // section style + } + break; + case RTF_TS: + if (m_aStates.top().getDestination() == Destination::STYLESHEET + || m_aStates.top().getDestination() == Destination::STYLEENTRY) + { + m_nCurrentStyleIndex = nParam; + // FIXME the correct value would be NS_ooxml::LN_Value_ST_StyleType_table but maybe table styles mess things up in dmapper, be cautious and disable them for now + auto pValue = new RTFValue(0); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_Style_type, + pValue); // table style + } + break; + case RTF_DEFF: + m_nDefaultFontIndex = nParam; + break; + case RTF_STSHFDBCH: + // tdf#123703 switch off longer space sequence except in the case of the fixed compatibility setting font id 31505 + if (nParam != 31505) + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_longerSpaceSequence, + new RTFValue(0)); + break; + case RTF_DEFLANG: + case RTF_ADEFLANG: + { + LanguageTag aTag((LanguageType(static_cast(nParam)))); + auto pValue = new RTFValue(aTag.getBcp47()); + putNestedAttribute(m_aStates.top().getCharacterSprms(), + (nKeyword == RTF_DEFLANG ? NS_ooxml::LN_EG_RPrBase_lang + : NS_ooxml::LN_CT_Language_bidi), + nSprm, pValue); + } + break; + case RTF_CHCBPAT: + { + auto pValue = new RTFValue(sal_uInt32(nParam ? getColorTable(nParam) : COL_AUTO)); + putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_shd, + NS_ooxml::LN_CT_Shd_fill, pValue); + } + break; + case RTF_CLCBPAT: + case RTF_CLCBPATRAW: + { + auto pValue = new RTFValue(sal_uInt32(getColorTable(nParam))); + putNestedAttribute(m_aStates.top().getTableCellSprms(), NS_ooxml::LN_CT_TcPrBase_shd, + NS_ooxml::LN_CT_Shd_fill, pValue); + } + break; + case RTF_CBPAT: + if (nParam) + { + auto pValue = new RTFValue(sal_uInt32(getColorTable(nParam))); + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PrBase_shd, + NS_ooxml::LN_CT_Shd_fill, pValue); + } + break; + case RTF_ULC: + { + auto pValue = new RTFValue(sal_uInt32(getColorTable(nParam))); + m_aStates.top().getCharacterSprms().set(0x6877, pValue); + } + break; + case RTF_HIGHLIGHT: + { + auto pValue = new RTFValue(sal_uInt32(nParam ? getColorTable(nParam) : COL_AUTO)); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_highlight, pValue); + } + break; + case RTF_UP: + case RTF_DN: + { + auto pValue = new RTFValue(nParam * (nKeyword == RTF_UP ? 1 : -1)); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_position, pValue); + } + break; + case RTF_HORZVERT: + { + auto pValue = new RTFValue(int(true)); + m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_EastAsianLayout_vert, + pValue); + if (nParam) + // rotate fits to a single line + m_aStates.top().getCharacterAttributes().set( + NS_ooxml::LN_CT_EastAsianLayout_vertCompress, pValue); + } + break; + case RTF_EXPND: + { + // Convert quarter-points to twentieths of a point + auto pValue = new RTFValue(nParam * 5); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_spacing, pValue); + } + break; + case RTF_TWOINONE: + { + auto pValue = new RTFValue(int(true)); + m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_EastAsianLayout_combine, + pValue); + Id nId = 0; + switch (nParam) + { + case 0: + nId = NS_ooxml::LN_Value_ST_CombineBrackets_none; + break; + case 1: + nId = NS_ooxml::LN_Value_ST_CombineBrackets_round; + break; + case 2: + nId = NS_ooxml::LN_Value_ST_CombineBrackets_square; + break; + case 3: + nId = NS_ooxml::LN_Value_ST_CombineBrackets_angle; + break; + case 4: + nId = NS_ooxml::LN_Value_ST_CombineBrackets_curly; + break; + } + if (nId > 0) + m_aStates.top().getCharacterAttributes().set( + NS_ooxml::LN_CT_EastAsianLayout_combineBrackets, new RTFValue(nId)); + } + break; + case RTF_SL: + { + // This is similar to RTF_ABSH, negative value means 'exact', positive means 'at least'. + tools::SvRef pValue( + new RTFValue(NS_ooxml::LN_Value_doc_ST_LineSpacingRule_atLeast)); + if (nParam < 0) + { + pValue = new RTFValue(NS_ooxml::LN_Value_doc_ST_LineSpacingRule_exact); + pIntValue = new RTFValue(-nParam); + } + m_aStates.top().getParagraphAttributes().set(NS_ooxml::LN_CT_Spacing_lineRule, pValue); + m_aStates.top().getParagraphAttributes().set(NS_ooxml::LN_CT_Spacing_line, pIntValue); + } + break; + case RTF_SLMULT: + if (nParam > 0) + { + auto pValue = new RTFValue(NS_ooxml::LN_Value_doc_ST_LineSpacingRule_auto); + m_aStates.top().getParagraphAttributes().set(NS_ooxml::LN_CT_Spacing_lineRule, + pValue); + } + break; + case RTF_BRDRW: + { + // dmapper expects it in 1/8 pt, we have it in twip - but avoid rounding 1 to 0 + if (nParam > 1) + nParam = nParam * 2 / 5; + auto pValue = new RTFValue(nParam); + putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_sz, pValue); + } + break; + case RTF_BRDRCF: + { + auto pValue = new RTFValue(sal_uInt32(getColorTable(nParam))); + putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_color, pValue); + } + break; + case RTF_BRSP: + { + // dmapper expects it in points, we have it in twip + auto pValue = new RTFValue(nParam / 20); + putBorderProperty(m_aStates, NS_ooxml::LN_CT_Border_space, pValue); + } + break; + case RTF_TX: + { + m_aStates.top().getTabAttributes().set(NS_ooxml::LN_CT_TabStop_pos, pIntValue); + auto pValue = new RTFValue(m_aStates.top().getTabAttributes()); + if (m_aStates.top().getDestination() == Destination::LISTLEVEL) + putNestedSprm(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_PPrBase_tabs, + NS_ooxml::LN_CT_Tabs_tab, pValue); + else + putNestedSprm(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_tabs, + NS_ooxml::LN_CT_Tabs_tab, pValue); + m_aStates.top().getTabAttributes().clear(); + } + break; + case RTF_ILVL: + putNestedSprm(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_numPr, + NS_ooxml::LN_CT_NumPr_ilvl, pIntValue); + break; + case RTF_LISTTEMPLATEID: + // This one is not referenced anywhere, so it's pointless to store it at the moment. + break; + case RTF_LISTID: + { + if (m_aStates.top().getDestination() == Destination::LISTENTRY) + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_AbstractNum_abstractNumId, + pIntValue); + else if (m_aStates.top().getDestination() == Destination::LISTOVERRIDEENTRY) + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Num_abstractNumId, pIntValue); + m_aStates.top().setCurrentListIndex(nParam); + } + break; + case RTF_LS: + { + if (m_aStates.top().getDestination() == Destination::LISTOVERRIDEENTRY) + { + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_AbstractNum_nsid, + pIntValue); + m_aStates.top().setCurrentListOverrideIndex(nParam); + } + else + { + // Insert at the start, so properties inherited from the list + // can be overridden by direct formatting. But still allow the + // case when old-style paragraph numbering is already + // tokenized. + putNestedSprm(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_numPr, + NS_ooxml::LN_CT_NumPr_numId, pIntValue, RTFOverwrite::YES_PREPEND); + } + } + break; + case RTF_UC: + if ((SAL_MIN_INT16 <= nParam) && (nParam <= SAL_MAX_INT16)) + m_aStates.top().setUc(nParam); + break; + case RTF_U: + // sal_Unicode is unsigned 16-bit, RTF may represent that as a + // signed SAL_MIN_INT16..SAL_MAX_INT16 or 0..SAL_MAX_UINT16. The + // static_cast() will do the right thing. + if ((SAL_MIN_INT16 <= nParam) && (nParam <= SAL_MAX_UINT16)) + { + if (m_aStates.top().getDestination() == Destination::LEVELNUMBERS) + { + if (nParam != ';') + m_aStates.top().getLevelNumbers().push_back(sal_Int32(nParam)); + else + // ';' in \u form is not considered valid. + m_aStates.top().setLevelNumbersValid(false); + } + else + m_aUnicodeBuffer.append(static_cast(nParam)); + m_aStates.top().getCharsToSkip() = m_aStates.top().getUc(); + } + break; + case RTF_LEVELFOLLOW: + { + OUString sValue; + switch (nParam) + { + case 0: + sValue = "tab"; + break; + case 1: + sValue = "space"; + break; + case 2: + sValue = "nothing"; + break; + } + if (!sValue.isEmpty()) + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Lvl_suff, new RTFValue(sValue)); + } + break; + case RTF_FPRQ: + { + sal_Int32 nValue = 0; + switch (nParam) + { + case 0: + nValue = NS_ooxml::LN_Value_ST_Pitch_default; + break; + case 1: + nValue = NS_ooxml::LN_Value_ST_Pitch_fixed; + break; + case 2: + nValue = NS_ooxml::LN_Value_ST_Pitch_variable; + break; + } + if (nValue) + { + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_Pitch_val, new RTFValue(nValue)); + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Font_pitch, + new RTFValue(aAttributes)); + } + } + break; + case RTF_LISTOVERRIDECOUNT: + // Ignore this for now, the exporter always emits it with a zero parameter. + break; + case RTF_PICSCALEX: + m_aStates.top().getPicture().nScaleX = nParam; + break; + case RTF_PICSCALEY: + m_aStates.top().getPicture().nScaleY = nParam; + break; + case RTF_PICW: + m_aStates.top().getPicture().nWidth = nParam; + break; + case RTF_PICH: + m_aStates.top().getPicture().nHeight = nParam; + break; + case RTF_PICWGOAL: + m_aStates.top().getPicture().nGoalWidth = convertTwipToMm100(nParam); + break; + case RTF_PICHGOAL: + m_aStates.top().getPicture().nGoalHeight = convertTwipToMm100(nParam); + break; + case RTF_PICCROPL: + m_aStates.top().getPicture().nCropL = convertTwipToMm100(nParam); + break; + case RTF_PICCROPR: + m_aStates.top().getPicture().nCropR = convertTwipToMm100(nParam); + break; + case RTF_PICCROPT: + m_aStates.top().getPicture().nCropT = convertTwipToMm100(nParam); + break; + case RTF_PICCROPB: + m_aStates.top().getPicture().nCropB = convertTwipToMm100(nParam); + break; + case RTF_SHPWRK: + { + int nValue = 0; + switch (nParam) + { + case 0: + nValue = NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_bothSides; + break; + case 1: + nValue = NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_left; + break; + case 2: + nValue = NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_right; + break; + case 3: + nValue = NS_ooxml::LN_Value_wordprocessingDrawing_ST_WrapText_largest; + break; + default: + break; + } + auto pValue = new RTFValue(nValue); + RTFValue::Pointer_t pTight + = m_aStates.top().getCharacterSprms().find(NS_ooxml::LN_EG_WrapType_wrapTight); + if (pTight) + pTight->getAttributes().set(NS_ooxml::LN_CT_WrapTight_wrapText, pValue); + else + m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_WrapSquare_wrapText, + pValue); + } + break; + case RTF_SHPWR: + { + switch (nParam) + { + case 1: + m_aStates.top().getShape().setWrap(text::WrapTextMode_NONE); + break; + case 2: + m_aStates.top().getShape().setWrap(text::WrapTextMode_PARALLEL); + break; + case 3: + m_aStates.top().getShape().setWrap(text::WrapTextMode_THROUGH); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_WrapType_wrapNone, + new RTFValue()); + break; + case 4: + m_aStates.top().getShape().setWrap(text::WrapTextMode_PARALLEL); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_WrapType_wrapTight, + new RTFValue()); + break; + case 5: + m_aStates.top().getShape().setWrap(text::WrapTextMode_THROUGH); + break; + } + } + break; + case RTF_COLS: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_cols, NS_ooxml::LN_CT_Columns_num, + pIntValue); + break; + case RTF_COLSX: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_cols, NS_ooxml::LN_CT_Columns_space, + pIntValue); + break; + case RTF_COLNO: + putNestedSprm(m_aStates.top().getSectionSprms(), NS_ooxml::LN_EG_SectPrContents_cols, + NS_ooxml::LN_CT_Columns_col, pIntValue); + break; + case RTF_COLW: + case RTF_COLSR: + { + RTFSprms& rAttributes = getLastAttributes(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_cols); + rAttributes.set( + (nKeyword == RTF_COLW ? NS_ooxml::LN_CT_Column_w : NS_ooxml::LN_CT_Column_space), + pIntValue); + } + break; + case RTF_PAPERH: + putNestedAttribute(m_aDefaultState.getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, + pIntValue); + [[fallthrough]]; // set the default + current value + case RTF_PGHSXN: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_h, + pIntValue); + break; + case RTF_PAPERW: + putNestedAttribute(m_aDefaultState.getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, + pIntValue); + [[fallthrough]]; // set the default + current value + case RTF_PGWSXN: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgSz, NS_ooxml::LN_CT_PageSz_w, + pIntValue); + break; + case RTF_MARGL: + putNestedAttribute(m_aDefaultState.getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, + pIntValue); + [[fallthrough]]; // set the default + current value + case RTF_MARGLSXN: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_left, + pIntValue); + break; + case RTF_MARGR: + putNestedAttribute(m_aDefaultState.getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, + pIntValue); + [[fallthrough]]; // set the default + current value + case RTF_MARGRSXN: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_right, + pIntValue); + break; + case RTF_MARGT: + putNestedAttribute(m_aDefaultState.getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, + pIntValue); + [[fallthrough]]; // set the default + current value + case RTF_MARGTSXN: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_top, + pIntValue); + break; + case RTF_MARGB: + putNestedAttribute(m_aDefaultState.getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, + pIntValue); + [[fallthrough]]; // set the default + current value + case RTF_MARGBSXN: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_bottom, + pIntValue); + break; + case RTF_HEADERY: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_header, + pIntValue); + break; + case RTF_FOOTERY: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgMar, NS_ooxml::LN_CT_PageMar_footer, + pIntValue); + break; + case RTF_DEFTAB: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_defaultTabStop, pIntValue); + break; + case RTF_LINEMOD: + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_lnNumType, + NS_ooxml::LN_CT_LineNumber_countBy, pIntValue); + break; + case RTF_LINEX: + if (nParam) + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_lnNumType, + NS_ooxml::LN_CT_LineNumber_distance, pIntValue); + break; + case RTF_LINESTARTS: + { + // OOXML is 0-based, RTF is 1-based. + auto pStart = tools::make_ref(nParam - 1); + putNestedAttribute(m_aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_lnNumType, + NS_ooxml::LN_CT_LineNumber_start, pStart); + } + break; + case RTF_REVAUTH: + case RTF_REVAUTHDEL: + { + auto pValue = new RTFValue(m_aAuthors[nParam]); + putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_trackchange, + NS_ooxml::LN_CT_TrackChange_author, pValue); + } + break; + case RTF_REVDTTM: + case RTF_REVDTTMDEL: + { + OUString aStr( + OStringToOUString(DTTM22OString(nParam), m_aStates.top().getCurrentEncoding())); + auto pValue = new RTFValue(aStr); + putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_trackchange, + NS_ooxml::LN_CT_TrackChange_date, pValue); + } + break; + case RTF_SHPLEFT: + m_aStates.top().getShape().setLeft(convertTwipToMm100(nParam)); + break; + case RTF_SHPTOP: + m_aStates.top().getShape().setTop(convertTwipToMm100(nParam)); + break; + case RTF_SHPRIGHT: + m_aStates.top().getShape().setRight(convertTwipToMm100(nParam)); + break; + case RTF_SHPBOTTOM: + m_aStates.top().getShape().setBottom(convertTwipToMm100(nParam)); + break; + case RTF_SHPZ: + m_aStates.top().getShape().setZ(nParam); + break; + case RTF_FFTYPE: + switch (nParam) + { + case 0: + m_nFormFieldType = RTFFormFieldType::TEXT; + break; + case 1: + m_nFormFieldType = RTFFormFieldType::CHECKBOX; + break; + case 2: + m_nFormFieldType = RTFFormFieldType::LIST; + break; + default: + m_nFormFieldType = RTFFormFieldType::NONE; + break; + } + break; + case RTF_FFDEFRES: + if (m_nFormFieldType == RTFFormFieldType::CHECKBOX) + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFCheckBox_default, pIntValue); + else if (m_nFormFieldType == RTFFormFieldType::LIST) + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFDDList_default, pIntValue); + break; + case RTF_FFRES: + // 25 means undefined, see [MS-DOC] 2.9.79, FFDataBits. + if (m_nFormFieldType == RTFFormFieldType::CHECKBOX && nParam != 25) + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFCheckBox_checked, pIntValue); + else if (m_nFormFieldType == RTFFormFieldType::LIST) + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFDDList_result, pIntValue); + break; + case RTF_EDMINS: + if (m_xDocumentProperties.is()) + { + // tdf#116851 some RTF may be malformed + if (nParam < 0) + nParam = -nParam; + m_xDocumentProperties->setEditingDuration(nParam); + } + break; + case RTF_NOFPAGES: + case RTF_NOFWORDS: + case RTF_NOFCHARS: + case RTF_NOFCHARSWS: + if (m_xDocumentProperties.is()) + { + comphelper::SequenceAsHashMap aSeq = m_xDocumentProperties->getDocumentStatistics(); + OUString aName; + switch (nKeyword) + { + case RTF_NOFPAGES: + aName = "PageCount"; + nParam = 99; + break; + case RTF_NOFWORDS: + aName = "WordCount"; + break; + case RTF_NOFCHARS: + aName = "CharacterCount"; + break; + case RTF_NOFCHARSWS: + aName = "NonWhitespaceCharacterCount"; + break; + default: + break; + } + if (!aName.isEmpty()) + { + aSeq[aName] <<= sal_Int32(nParam); + m_xDocumentProperties->setDocumentStatistics(aSeq.getAsConstNamedValueList()); + } + } + break; + case RTF_VERSION: + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setEditingCycles(nParam); + break; + case RTF_VERN: + // Ignore this for now, later the RTF writer version could be used to add hacks for older buggy writers. + break; + case RTF_FTNSTART: + putNestedSprm(m_aDefaultState.getParagraphSprms(), + NS_ooxml::LN_EG_SectPrContents_footnotePr, + NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue); + break; + case RTF_AFTNSTART: + putNestedSprm(m_aDefaultState.getParagraphSprms(), + NS_ooxml::LN_EG_SectPrContents_endnotePr, + NS_ooxml::LN_EG_FtnEdnNumProps_numStart, pIntValue); + break; + case RTF_DFRMTXTX: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hSpace, nParam); + break; + case RTF_DFRMTXTY: + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vSpace, nParam); + break; + case RTF_DXFRTEXT: + { + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hSpace, nParam); + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vSpace, nParam); + } + break; + case RTF_FLYVERT: + { + RTFVertOrient aVertOrient(nParam); + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_yAlign, + aVertOrient.GetAlign()); + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_vAnchor, + aVertOrient.GetAnchor()); + } + break; + case RTF_FLYHORZ: + { + RTFHoriOrient aHoriOrient(nParam); + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_xAlign, + aHoriOrient.GetAlign()); + m_aStates.top().getFrame().setSprm(NS_ooxml::LN_CT_FramePr_hAnchor, + aHoriOrient.GetAnchor()); + } + break; + case RTF_FLYANCHOR: + break; + case RTF_WMETAFILE: + m_aStates.top().getPicture().eWMetafile = nParam; + break; + case RTF_SB: + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_spacing, + NS_ooxml::LN_CT_Spacing_before, pIntValue); + break; + case RTF_SA: + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_spacing, + NS_ooxml::LN_CT_Spacing_after, pIntValue); + break; + case RTF_DPX: + m_aStates.top().getDrawingObject().setLeft(convertTwipToMm100(nParam)); + break; + case RTF_DPY: + m_aStates.top().getDrawingObject().setTop(convertTwipToMm100(nParam)); + break; + case RTF_DPXSIZE: + m_aStates.top().getDrawingObject().setRight(convertTwipToMm100(nParam)); + break; + case RTF_DPYSIZE: + m_aStates.top().getDrawingObject().setBottom(convertTwipToMm100(nParam)); + break; + case RTF_PNSTART: + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Lvl_start, pIntValue); + break; + case RTF_PNF: + { + auto pValue = new RTFValue(m_aFontNames[getFontIndex(nParam)]); + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_Fonts_ascii, pValue); + putNestedSprm(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_Lvl_rPr, + NS_ooxml::LN_EG_RPrBase_rFonts, new RTFValue(aAttributes)); + } + break; + case RTF_VIEWSCALE: + m_aSettingsTableAttributes.set(NS_ooxml::LN_CT_Zoom_percent, pIntValue); + break; + case RTF_BIN: + { + m_aStates.top().setInternalState(RTFInternalState::BIN); + m_aStates.top().setBinaryToRead(nParam); + } + break; + case RTF_DPLINECOR: + m_aStates.top().getDrawingObject().setLineColorR(nParam); + m_aStates.top().getDrawingObject().setHasLineColor(true); + break; + case RTF_DPLINECOG: + m_aStates.top().getDrawingObject().setLineColorG(nParam); + m_aStates.top().getDrawingObject().setHasLineColor(true); + break; + case RTF_DPLINECOB: + m_aStates.top().getDrawingObject().setLineColorB(nParam); + m_aStates.top().getDrawingObject().setHasLineColor(true); + break; + case RTF_DPFILLBGCR: + m_aStates.top().getDrawingObject().setFillColorR(nParam); + m_aStates.top().getDrawingObject().setHasFillColor(true); + break; + case RTF_DPFILLBGCG: + m_aStates.top().getDrawingObject().setFillColorG(nParam); + m_aStates.top().getDrawingObject().setHasFillColor(true); + break; + case RTF_DPFILLBGCB: + m_aStates.top().getDrawingObject().setFillColorB(nParam); + m_aStates.top().getDrawingObject().setHasFillColor(true); + break; + case RTF_DODHGT: + m_aStates.top().getDrawingObject().setDhgt(nParam); + break; + case RTF_DPPOLYCOUNT: + if (nParam >= 0) + { + m_aStates.top().getDrawingObject().setPolyLineCount(nParam); + } + break; + case RTF_DPPTX: + { + RTFDrawingObject& rDrawingObject = m_aStates.top().getDrawingObject(); + + if (rDrawingObject.getPolyLinePoints().empty()) + dispatchValue(RTF_DPPOLYCOUNT, 2); + + rDrawingObject.getPolyLinePoints().emplace_back( + awt::Point(convertTwipToMm100(nParam), 0)); + } + break; + case RTF_DPPTY: + { + RTFDrawingObject& rDrawingObject = m_aStates.top().getDrawingObject(); + if (!rDrawingObject.getPolyLinePoints().empty()) + { + rDrawingObject.getPolyLinePoints().back().Y = convertTwipToMm100(nParam); + rDrawingObject.setPolyLineCount(rDrawingObject.getPolyLineCount() - 1); + if (rDrawingObject.getPolyLineCount() == 0 && rDrawingObject.getPropertySet().is()) + { + uno::Sequence> aPointSequenceSequence + = { comphelper::containerToSequence(rDrawingObject.getPolyLinePoints()) }; + rDrawingObject.getPropertySet()->setPropertyValue( + "PolyPolygon", uno::Any(aPointSequenceSequence)); + } + } + } + break; + case RTF_SHPFBLWTXT: + // Shape is below text -> send it to the background. + m_aStates.top().getShape().setInBackground(nParam != 0); + break; + case RTF_FI: + { + if (m_aStates.top().getDestination() == Destination::LISTLEVEL) + { + if (m_aStates.top().getLevelNumbersValid()) + putNestedAttribute(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_firstLine, pIntValue); + else + m_aInvalidListLevelFirstIndents[m_nListLevel] = nParam; + } + else + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_firstLine, pIntValue); + break; + } + case RTF_LI: + { + if (m_aStates.top().getDestination() == Destination::LISTLEVEL) + { + if (m_aStates.top().getLevelNumbersValid()) + putNestedAttribute(m_aStates.top().getTableSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_left, pIntValue); + } + else + { + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_left, pIntValue); + } + // It turns out \li should reset the \fi inherited from the stylesheet. + // So set the direct formatting to zero, if we don't have such direct formatting yet. + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_firstLine, new RTFValue(0), + RTFOverwrite::NO_IGNORE); + } + break; + case RTF_RI: + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_right, pIntValue); + break; + case RTF_LIN: + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_start, pIntValue); + break; + case RTF_RIN: + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_ind, + NS_ooxml::LN_CT_Ind_end, pIntValue); + break; + case RTF_OUTLINELEVEL: + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_outlineLvl, pIntValue); + break; + case RTF_PROPTYPE: + { + switch (nParam) + { + case 3: + m_aStates.top().setPropType(cppu::UnoType::get()); + break; + case 5: + m_aStates.top().setPropType(cppu::UnoType::get()); + break; + case 11: + m_aStates.top().setPropType(cppu::UnoType::get()); + break; + case 30: + m_aStates.top().setPropType(cppu::UnoType::get()); + break; + case 64: + m_aStates.top().setPropType(cppu::UnoType::get()); + break; + } + } + break; + case RTF_DIBITMAP: + m_aStates.top().getPicture().eStyle = RTFBmpStyle::DIBITMAP; + break; + case RTF_TRWWIDTHA: + m_aStates.top().setTableRowWidthAfter(nParam); + break; + case RTF_ANIMTEXT: + { + Id nId = 0; + switch (nParam) + { + case 0: + nId = NS_ooxml::LN_Value_ST_TextEffect_none; + break; + case 2: + nId = NS_ooxml::LN_Value_ST_TextEffect_blinkBackground; + break; + } + + if (nId > 0) + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_effect, + new RTFValue(nId)); + break; + } + case RTF_VIEWBKSP: + { + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_displayBackgroundShape, pIntValue); + // Send this token immediately, if it only appears before the first + // run, it will be too late, we ignored the background shape already by then. + outputSettingsTable(); + break; + } + case RTF_STEXTFLOW: + { + Id nId = 0; + switch (nParam) + { + case 0: + nId = NS_ooxml::LN_Value_ST_TextDirection_lrTb; + break; + case 1: + nId = NS_ooxml::LN_Value_ST_TextDirection_tbRl; + break; + } + + if (nId > 0) + { + m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_textDirection, + new RTFValue(nId)); + } + } + break; + default: + { + SAL_INFO("writerfilter", "TODO handle value '" << keywordToString(nKeyword) << "'"); + aSkip.setParsed(false); + } + break; + } + return RTFError::OK; +} + +} // namespace rtftok +} // namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentfactory.cxx b/writerfilter/source/rtftok/rtfdocumentfactory.cxx new file mode 100644 index 000000000..75b109b68 --- /dev/null +++ b/writerfilter/source/rtftok/rtfdocumentfactory.cxx @@ -0,0 +1,28 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfdocumentimpl.hxx" + +namespace writerfilter::rtftok +{ +RTFDocument::Pointer_t RTFDocumentFactory::createDocument( + css::uno::Reference const& xContext, + css::uno::Reference const& xInputStream, + css::uno::Reference const& xDstDoc, + css::uno::Reference const& xFrame, + css::uno::Reference const& xStatusIndicator, + const utl::MediaDescriptor& rMediaDescriptor) +{ + return new RTFDocumentImpl(xContext, xInputStream, xDstDoc, xFrame, xStatusIndicator, + rMediaDescriptor); +} + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx new file mode 100644 index 000000000..f470ac552 --- /dev/null +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -0,0 +1,3853 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfdocumentimpl.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "rtfsdrimport.hxx" +#include "rtfreferenceproperties.hxx" +#include "rtfskipdestination.hxx" +#include "rtftokenizer.hxx" +#include "rtflookahead.hxx" + +using namespace com::sun::star; + +namespace +{ +/// Returns an util::DateTime from a 'YYYY. MM. DD.' string. +util::DateTime getDateTimeFromUserProp(const OUString& rString) +{ + util::DateTime aRet; + sal_Int32 nLen = rString.getLength(); + if (nLen >= 4) + { + aRet.Year = rString.copy(0, 4).toInt32(); + + if (nLen >= 8 && rString.match(". ", 4)) + { + aRet.Month = rString.copy(6, 2).toInt32(); + + if (nLen >= 12 && rString.match(". ", 8)) + aRet.Day = rString.copy(10, 2).toInt32(); + } + } + return aRet; +} +} // anonymous namespace + +namespace writerfilter::rtftok +{ +Id getParagraphBorder(sal_uInt32 nIndex) +{ + static const Id aBorderIds[] = { NS_ooxml::LN_CT_PBdr_top, NS_ooxml::LN_CT_PBdr_left, + NS_ooxml::LN_CT_PBdr_bottom, NS_ooxml::LN_CT_PBdr_right }; + + return aBorderIds[nIndex]; +} + +void putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue, + RTFOverwrite eOverwrite, bool bAttribute) +{ + RTFValue::Pointer_t pParent = rSprms.find(nParent, /*bFirst=*/true, /*bForWrite=*/true); + if (!pParent) + { + RTFSprms aAttributes; + if (nParent == NS_ooxml::LN_CT_TcPrBase_shd) + { + // RTF default is 'auto', see writerfilter::dmapper::CellColorHandler + aAttributes.set(NS_ooxml::LN_CT_Shd_color, new RTFValue(sal_uInt32(COL_AUTO))); + aAttributes.set(NS_ooxml::LN_CT_Shd_fill, new RTFValue(sal_uInt32(COL_AUTO))); + } + auto pParentValue = new RTFValue(aAttributes); + rSprms.set(nParent, pParentValue, eOverwrite); + pParent = pParentValue; + } + RTFSprms& rAttributes = (bAttribute ? pParent->getAttributes() : pParent->getSprms()); + rAttributes.set(nId, pValue, eOverwrite); +} + +void putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue, + RTFOverwrite eOverwrite) +{ + putNestedAttribute(rSprms, nParent, nId, pValue, eOverwrite, false); +} + +RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId) +{ + RTFValue::Pointer_t pParent = rSprms.find(nParent); + if (!pParent) + return RTFValue::Pointer_t(); + RTFSprms& rAttributes = pParent->getAttributes(); + return rAttributes.find(nId); +} + +RTFValue::Pointer_t getNestedSprm(RTFSprms& rSprms, Id nParent, Id nId) +{ + RTFValue::Pointer_t pParent = rSprms.find(nParent); + if (!pParent) + return RTFValue::Pointer_t(); + RTFSprms& rInner = pParent->getSprms(); + return rInner.find(nId); +} + +bool eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId) +{ + RTFValue::Pointer_t pParent = rSprms.find(nParent); + if (!pParent) + // It doesn't even have a parent, we're done. + return false; + RTFSprms& rAttributes = pParent->getAttributes(); + return rAttributes.erase(nId); +} + +RTFSprms& getLastAttributes(RTFSprms& rSprms, Id nId) +{ + RTFValue::Pointer_t p = rSprms.find(nId); + if (p && !p->getSprms().empty()) + return p->getSprms().back().second->getAttributes(); + + SAL_WARN("writerfilter.rtf", "trying to set property when no type is defined"); + return rSprms; +} + +void putBorderProperty(RTFStack& aStates, Id nId, const RTFValue::Pointer_t& pValue) +{ + RTFSprms* pAttributes = nullptr; + if (aStates.top().getBorderState() == RTFBorderState::PARAGRAPH_BOX) + for (int i = 0; i < 4; i++) + { + RTFValue::Pointer_t p = aStates.top().getParagraphSprms().find(getParagraphBorder(i)); + if (p) + { + RTFSprms& rAttributes = p->getAttributes(); + rAttributes.set(nId, pValue); + } + } + else if (aStates.top().getBorderState() == RTFBorderState::CHARACTER) + { + RTFValue::Pointer_t pPointer + = aStates.top().getCharacterSprms().find(NS_ooxml::LN_EG_RPrBase_bdr); + if (pPointer) + { + RTFSprms& rAttributes = pPointer->getAttributes(); + rAttributes.set(nId, pValue); + } + } + // Attributes of the last border type + else if (aStates.top().getBorderState() == RTFBorderState::PARAGRAPH) + pAttributes + = &getLastAttributes(aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PrBase_pBdr); + else if (aStates.top().getBorderState() == RTFBorderState::CELL) + pAttributes = &getLastAttributes(aStates.top().getTableCellSprms(), + NS_ooxml::LN_CT_TcPrBase_tcBorders); + else if (aStates.top().getBorderState() == RTFBorderState::PAGE) + pAttributes = &getLastAttributes(aStates.top().getSectionSprms(), + NS_ooxml::LN_EG_SectPrContents_pgBorders); + if (pAttributes) + pAttributes->set(nId, pValue); +} + +OString DTTM22OString(long nDTTM) +{ + return DateTimeToOString(msfilter::util::DTTM2DateTime(nDTTM)); +} + +static RTFSprms lcl_getBookmarkProperties(int nPos, const OUString& rString) +{ + RTFSprms aAttributes; + auto pPos = new RTFValue(nPos); + if (!rString.isEmpty()) + { + // If present, this should be sent first. + auto pString = new RTFValue(rString); + aAttributes.set(NS_ooxml::LN_CT_Bookmark_name, pString); + } + aAttributes.set(NS_ooxml::LN_CT_MarkupRangeBookmark_id, pPos); + return aAttributes; +} + +const char* keywordToString(RTFKeyword nKeyword) +{ + for (int i = 0; i < nRTFControlWords; i++) + { + if (nKeyword == aRTFControlWords[i].GetIndex()) + return aRTFControlWords[i].GetKeyword(); + } + return nullptr; +} + +static util::DateTime lcl_getDateTime(RTFParserState const& aState) +{ + return { 0 /*100sec*/, + 0 /*sec*/, + aState.getMinute(), + aState.getHour(), + aState.getDay(), + aState.getMonth(), + static_cast(aState.getYear()), + false }; +} + +static void lcl_DestinationToMath(OUStringBuffer* pDestinationText, + oox::formulaimport::XmlStreamBuilder& rMathBuffer, bool& rMathNor) +{ + if (!pDestinationText) + return; + OUString aStr = pDestinationText->makeStringAndClear(); + if (aStr.isEmpty()) + return; + rMathBuffer.appendOpeningTag(M_TOKEN(r)); + if (rMathNor) + { + rMathBuffer.appendOpeningTag(M_TOKEN(rPr)); + // Same as M_TOKEN(lit) + rMathBuffer.appendOpeningTag(M_TOKEN(nor)); + rMathBuffer.appendClosingTag(M_TOKEN(nor)); + rMathBuffer.appendClosingTag(M_TOKEN(rPr)); + rMathNor = false; + } + rMathBuffer.appendOpeningTag(M_TOKEN(t)); + rMathBuffer.appendCharacters(aStr); + rMathBuffer.appendClosingTag(M_TOKEN(t)); + rMathBuffer.appendClosingTag(M_TOKEN(r)); +} + +RTFDocumentImpl::RTFDocumentImpl(uno::Reference const& xContext, + uno::Reference const& xInputStream, + uno::Reference const& xDstDoc, + uno::Reference const& xFrame, + uno::Reference const& xStatusIndicator, + const utl::MediaDescriptor& rMediaDescriptor) + : m_xContext(xContext) + , m_xInputStream(xInputStream) + , m_xDstDoc(xDstDoc) + , m_xFrame(xFrame) + , m_xStatusIndicator(xStatusIndicator) + , m_pMapperStream(nullptr) + , m_aDefaultState(this) + , m_bSkipUnknown(false) + , m_bFirstRun(true) + , m_bFirstRunException(false) + , m_bNeedPap(true) + , m_bNeedCr(false) + , m_bNeedCrOrig(false) + , m_bNeedPar(true) + , m_bNeedFinalPar(false) + , m_nNestedCells(0) + , m_nTopLevelCells(0) + , m_nInheritingCells(0) + , m_nNestedTRLeft(0) + , m_nTopLevelTRLeft(0) + , m_nNestedCurrentCellX(0) + , m_nTopLevelCurrentCellX(0) + , m_nBackupTopLevelCurrentCellX(0) + , m_aTableBufferStack(1) // create top-level buffer already + , m_pSuperstream(nullptr) + , m_nStreamType(0) + , m_nGroupStartPos(0) + , m_nFormFieldType(RTFFormFieldType::NONE) + , m_bObject(false) + , m_nCurrentFontIndex(0) + , m_nCurrentEncoding(-1) + , m_nDefaultFontIndex(-1) + , m_nCurrentStyleIndex(0) + , m_bFormField(false) + , m_bMathNor(false) + , m_bIgnoreNextContSectBreak(false) + , m_nResetBreakOnSectBreak(RTF_invalid) + , m_bNeedSect(false) // done by checkFirstRun + , m_bWasInFrame(false) + , m_bHadPicture(false) + , m_bHadSect(false) + , m_nCellxMax(0) + , m_nListPictureId(0) + , m_bIsNewDoc(!rMediaDescriptor.getUnpackedValueOrDefault("InsertMode", false)) + , m_rMediaDescriptor(rMediaDescriptor) + , m_hasRHeader(false) + , m_hasFHeader(false) + , m_hasRFooter(false) + , m_hasFFooter(false) + , m_bAfterCellBeforeRow(false) +{ + OSL_ASSERT(xInputStream.is()); + m_pInStream = utl::UcbStreamHelper::CreateStream(xInputStream, true); + + m_xModelFactory.set(m_xDstDoc, uno::UNO_QUERY); + + uno::Reference xDocumentPropertiesSupplier( + m_xDstDoc, uno::UNO_QUERY); + if (xDocumentPropertiesSupplier.is()) + m_xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); + + m_pGraphicHelper = std::make_shared(m_xContext, xFrame, oox::StorageRef()); + + m_pTokenizer = new RTFTokenizer(*this, m_pInStream.get(), m_xStatusIndicator); + m_pSdrImport = new RTFSdrImport(*this, m_xDstDoc); +} + +RTFDocumentImpl::~RTFDocumentImpl() = default; + +SvStream& RTFDocumentImpl::Strm() { return *m_pInStream; } + +void RTFDocumentImpl::setSuperstream(RTFDocumentImpl* pSuperstream) +{ + m_pSuperstream = pSuperstream; +} + +bool RTFDocumentImpl::isSubstream() const { return m_pSuperstream != nullptr; } + +void RTFDocumentImpl::finishSubstream() { checkUnicode(/*bUnicode =*/true, /*bHex =*/true); } + +void RTFDocumentImpl::resolveSubstream(std::size_t nPos, Id nId) +{ + resolveSubstream(nPos, nId, OUString()); +} +void RTFDocumentImpl::resolveSubstream(std::size_t nPos, Id nId, OUString const& rIgnoreFirst) +{ + sal_uInt64 const nCurrent = Strm().Tell(); + // Seek to header position, parse, then seek back. + auto pImpl = new RTFDocumentImpl(m_xContext, m_xInputStream, m_xDstDoc, m_xFrame, + m_xStatusIndicator, m_rMediaDescriptor); + pImpl->setSuperstream(this); + pImpl->m_nStreamType = nId; + pImpl->m_aIgnoreFirst = rIgnoreFirst; + if (!m_aAuthor.isEmpty()) + { + pImpl->m_aAuthor = m_aAuthor; + m_aAuthor.clear(); + } + if (!m_aAuthorInitials.isEmpty()) + { + pImpl->m_aAuthorInitials = m_aAuthorInitials; + m_aAuthorInitials.clear(); + } + pImpl->m_nDefaultFontIndex = m_nDefaultFontIndex; + pImpl->Strm().Seek(nPos); + SAL_INFO("writerfilter.rtf", "substream start"); + Mapper().substream(nId, pImpl); + SAL_INFO("writerfilter.rtf", "substream end"); + Strm().Seek(nCurrent); +} + +void RTFDocumentImpl::outputSettingsTable() +{ + writerfilter::Reference::Pointer_t pProp + = new RTFReferenceProperties(m_aSettingsTableAttributes, m_aSettingsTableSprms); + RTFReferenceTable::Entries_t aSettingsTableEntries; + aSettingsTableEntries.insert(std::make_pair(0, pProp)); + writerfilter::Reference
::Pointer_t pTable = new RTFReferenceTable(aSettingsTableEntries); + Mapper().table(NS_ooxml::LN_settings_settings, pTable); +} + +void RTFDocumentImpl::checkFirstRun() +{ + if (m_bFirstRun) + { + outputSettingsTable(); + // start initial paragraph + m_bFirstRun = false; + assert(!m_bNeedSect || m_bFirstRunException); + setNeedSect(true); // first call that succeeds + + // set the requested default font, if there are none + RTFValue::Pointer_t pFont + = getNestedAttribute(m_aDefaultState.getCharacterSprms(), + NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); + RTFValue::Pointer_t pCurrentFont + = getNestedAttribute(m_aStates.top().getCharacterSprms(), + NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii); + if (pFont && !pCurrentFont) + putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_EG_RPrBase_rFonts, + NS_ooxml::LN_CT_Fonts_ascii, pFont); + } +} + +void RTFDocumentImpl::setNeedPar(bool bNeedPar) { m_bNeedPar = bNeedPar; } + +void RTFDocumentImpl::setNeedSect(bool bNeedSect) +{ + if (!m_bNeedSect && bNeedSect && m_bFirstRun) + { + RTFLookahead aLookahead(Strm(), m_pTokenizer->getGroupStart()); + if (aLookahead.hasTable() && aLookahead.hasColumns()) + { + m_bFirstRunException = true; + } + } + + // ignore setting before checkFirstRun - every keyword calls setNeedSect! + // except the case of a table in a multicolumn section + if (!m_bNeedSect && bNeedSect && (!m_bFirstRun || m_bFirstRunException)) + { + if (!m_pSuperstream) // no sections in header/footer! + { + Mapper().startSectionGroup(); + } + // set flag in substream too - otherwise multiple startParagraphGroup + m_bNeedSect = bNeedSect; + Mapper().startParagraphGroup(); + setNeedPar(true); + } + else if (m_bNeedSect && !bNeedSect) + { + m_bNeedSect = bNeedSect; + } +} + +/// Copy rProps to rStyleAttributes and rStyleSprms, but in case of nested sprms, copy their children as toplevel sprms/attributes. +static void lcl_copyFlatten(RTFReferenceProperties& rProps, RTFSprms& rStyleAttributes, + RTFSprms& rStyleSprms) +{ + for (auto& rSprm : rProps.getSprms()) + { + // createStyleProperties() puts properties to rPr, but here we need a flat list. + if (rSprm.first == NS_ooxml::LN_CT_Style_rPr) + { + // rPr can have both attributes and SPRMs, copy over both types. + RTFSprms& rRPrSprms = rSprm.second->getSprms(); + for (const auto& rRPrSprm : rRPrSprms) + rStyleSprms.set(rRPrSprm.first, rRPrSprm.second); + + RTFSprms& rRPrAttributes = rSprm.second->getAttributes(); + for (const auto& rRPrAttribute : rRPrAttributes) + rStyleAttributes.set(rRPrAttribute.first, rRPrAttribute.second); + } + else + rStyleSprms.set(rSprm.first, rSprm.second); + } + + RTFSprms& rAttributes = rProps.getAttributes(); + for (const auto& rAttribute : rAttributes) + rStyleAttributes.set(rAttribute.first, rAttribute.second); +} + +writerfilter::Reference::Pointer_t +RTFDocumentImpl::getProperties(const RTFSprms& rAttributes, RTFSprms const& rSprms, Id nStyleType) +{ + RTFSprms aSprms(rSprms); + RTFValue::Pointer_t pAbstractList; + int nAbstractListId = -1; + RTFValue::Pointer_t pNumId + = getNestedSprm(aSprms, NS_ooxml::LN_CT_PPrBase_numPr, NS_ooxml::LN_CT_NumPr_numId); + if (pNumId) + { + // We have a numbering, look up the abstract list for property + // deduplication and duplication. + auto itNumId = m_aListOverrideTable.find(pNumId->getInt()); + if (itNumId != m_aListOverrideTable.end()) + { + nAbstractListId = itNumId->second; + auto itAbstract = m_aListTable.find(nAbstractListId); + if (itAbstract != m_aListTable.end()) + pAbstractList = itAbstract->second; + } + } + + if (pAbstractList) + { + auto it = m_aInvalidListTableFirstIndents.find(nAbstractListId); + if (it != m_aInvalidListTableFirstIndents.end()) + aSprms.deduplicateList(it->second); + } + + int nStyle = 0; + if (!m_aStates.empty()) + nStyle = m_aStates.top().getCurrentStyleIndex(); + auto it = m_aStyleTableEntries.find(nStyle); + if (it != m_aStyleTableEntries.end()) + { + // cloneAndDeduplicate() wants to know about only a single "style", so + // let's merge paragraph and character style properties here. + auto itChar = m_aStyleTableEntries.end(); + if (!m_aStates.empty()) + { + int nCharStyle = m_aStates.top().getCurrentCharacterStyleIndex(); + itChar = m_aStyleTableEntries.find(nCharStyle); + } + + RTFSprms aStyleSprms; + RTFSprms aStyleAttributes; + // Ensure the paragraph style is a flat list. + // Take paragraph style into account for character properties as well, + // as paragraph style may contain character properties. + RTFReferenceProperties& rProps = *static_cast(it->second.get()); + lcl_copyFlatten(rProps, aStyleAttributes, aStyleSprms); + + if (itChar != m_aStyleTableEntries.end()) + { + // Found active character style, then update aStyleSprms/Attributes. + if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_character) + { + RTFReferenceProperties& rCharProps + = *static_cast(itChar->second.get()); + lcl_copyFlatten(rCharProps, aStyleAttributes, aStyleSprms); + } + } + + // Get rid of direct formatting what is already in the style. + RTFSprms const sprms(aSprms.cloneAndDeduplicate(aStyleSprms, nStyleType, true, &aSprms)); + RTFSprms const attributes( + rAttributes.cloneAndDeduplicate(aStyleAttributes, nStyleType, true)); + return new RTFReferenceProperties(attributes, sprms); + } + + if (pAbstractList) + aSprms.duplicateList(pAbstractList); + writerfilter::Reference::Pointer_t pRet + = new RTFReferenceProperties(rAttributes, aSprms); + return pRet; +} + +void RTFDocumentImpl::checkNeedPap() +{ + if (m_bNeedPap) + { + m_bNeedPap = false; // reset early, so we can avoid recursion when calling ourselves + + if (m_aStates.empty()) + return; + + if (!m_aStates.top().getCurrentBuffer()) + { + writerfilter::Reference::Pointer_t const pParagraphProperties(getProperties( + m_aStates.top().getParagraphAttributes(), m_aStates.top().getParagraphSprms(), + NS_ooxml::LN_Value_ST_StyleType_paragraph)); + + // Writer will ignore a page break before a text frame, so guard it with empty paragraphs + bool hasBreakBeforeFrame = m_aStates.top().getFrame().hasProperties() + && m_aStates.top().getParagraphSprms().find( + NS_ooxml::LN_CT_PPrBase_pageBreakBefore); + if (hasBreakBeforeFrame) + { + dispatchSymbol(RTF_PAR); + m_bNeedPap = false; + } + Mapper().props(pParagraphProperties); + if (hasBreakBeforeFrame) + dispatchSymbol(RTF_PAR); + + if (m_aStates.top().getFrame().hasProperties()) + { + writerfilter::Reference::Pointer_t const pFrameProperties( + new RTFReferenceProperties(RTFSprms(), m_aStates.top().getFrame().getSprms())); + Mapper().props(pFrameProperties); + } + } + else + { + auto pValue = new RTFValue(m_aStates.top().getParagraphAttributes(), + m_aStates.top().getParagraphSprms()); + bufferProperties(*m_aStates.top().getCurrentBuffer(), pValue, nullptr); + } + } +} + +void RTFDocumentImpl::runProps() +{ + if (!m_aStates.top().getCurrentBuffer()) + { + Reference::Pointer_t const pProperties = getProperties( + m_aStates.top().getCharacterAttributes(), m_aStates.top().getCharacterSprms(), + NS_ooxml::LN_Value_ST_StyleType_character); + Mapper().props(pProperties); + } + else + { + auto pValue = new RTFValue(m_aStates.top().getCharacterAttributes(), + m_aStates.top().getCharacterSprms()); + bufferProperties(*m_aStates.top().getCurrentBuffer(), pValue, nullptr); + } + + // Delete the sprm, so the trackchange range will be started only once. + // OTOH set a boolean flag, so we'll know we need to end the range later. + RTFValue::Pointer_t pTrackchange + = m_aStates.top().getCharacterSprms().find(NS_ooxml::LN_trackchange); + if (pTrackchange) + { + m_aStates.top().setStartedTrackchange(true); + m_aStates.top().getCharacterSprms().erase(NS_ooxml::LN_trackchange); + } +} + +void RTFDocumentImpl::runBreak() +{ + sal_uInt8 const sBreak[] = { 0xd }; + Mapper().text(sBreak, 1); + m_bNeedCr = false; +} + +void RTFDocumentImpl::tableBreak() +{ + runBreak(); + Mapper().endParagraphGroup(); + Mapper().startParagraphGroup(); +} + +void RTFDocumentImpl::parBreak() +{ + checkFirstRun(); + checkNeedPap(); + // end previous paragraph + Mapper().startCharacterGroup(); + runBreak(); + Mapper().endCharacterGroup(); + Mapper().endParagraphGroup(); + + m_bHadPicture = false; + + // start new one + Mapper().startParagraphGroup(); +} + +void RTFDocumentImpl::sectBreak(bool bFinal) +{ + SAL_INFO("writerfilter.rtf", + OSL_THIS_FUNC << ": final? " << bFinal << ", needed? " << m_bNeedSect); + bool bNeedSect = m_bNeedSect; + RTFValue::Pointer_t pBreak + = m_aStates.top().getSectionSprms().find(NS_ooxml::LN_EG_SectPrContents_type); + bool bContinuous + = pBreak + && pBreak->getInt() + == static_cast(NS_ooxml::LN_Value_ST_SectionMark_continuous); + // If there is no paragraph in this section, then insert a dummy one, as required by Writer, + // unless this is the end of the doc, we had nothing since the last section break and this is not a continuous one. + // Also, when pasting, it's fine to not have any paragraph inside the document at all. + if (m_bNeedPar && !(bFinal && !m_bNeedSect && !bContinuous) && !isSubstream() && m_bIsNewDoc) + dispatchSymbol(RTF_PAR); + // It's allowed to not have a non-table paragraph at the end of an RTF doc, add it now if required. + if (m_bNeedFinalPar && bFinal) + { + dispatchFlag(RTF_PARD); + dispatchSymbol(RTF_PAR); + m_bNeedSect = bNeedSect; + } + while (!m_nHeaderFooterPositions.empty()) + { + std::pair aPair = m_nHeaderFooterPositions.front(); + m_nHeaderFooterPositions.pop(); + resolveSubstream(aPair.second, aPair.first); + } + + // Normally a section break at the end of the doc is necessary. Unless the + // last control word in the document is a section break itself. + if (!bNeedSect || !m_bHadSect) + { + // In case the last section is a continuous one, we don't need to output a section break. + if (bFinal && bContinuous) + m_aStates.top().getSectionSprms().erase(NS_ooxml::LN_EG_SectPrContents_type); + } + + // Section properties are a paragraph sprm. + auto pValue + = new RTFValue(m_aStates.top().getSectionAttributes(), m_aStates.top().getSectionSprms()); + RTFSprms aAttributes; + RTFSprms aSprms; + aSprms.set(NS_ooxml::LN_CT_PPr_sectPr, pValue); + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aAttributes, aSprms); + + if (bFinal && !m_pSuperstream) + // This is the end of the document, not just the end of e.g. a header. + // This makes sure that dmapper can set DontBalanceTextColumns=true for this section if necessary. + Mapper().markLastSectionGroup(); + + // The trick is that we send properties of the previous section right now, which will be exactly what dmapper expects. + Mapper().props(pProperties); + Mapper().endParagraphGroup(); + + // End Section + if (!m_pSuperstream) + { + m_hasFHeader = false; + m_hasRHeader = false; + m_hasRFooter = false; + m_hasFFooter = false; + Mapper().endSectionGroup(); + } + m_bNeedPar = false; + m_bNeedSect = false; +} + +Color RTFDocumentImpl::getColorTable(sal_uInt32 nIndex) +{ + if (!m_pSuperstream) + { + if (nIndex < m_aColorTable.size()) + return m_aColorTable[nIndex]; + return 0; + } + + return m_pSuperstream->getColorTable(nIndex); +} + +rtl_TextEncoding RTFDocumentImpl::getEncoding(int nFontIndex) +{ + if (!m_pSuperstream) + { + auto it = m_aFontEncodings.find(nFontIndex); + if (it != m_aFontEncodings.end()) + // We have a font encoding associated to this font. + return it->second; + if (m_aDefaultState.getCurrentEncoding() != rtl_getTextEncodingFromWindowsCharset(0)) + // We have a default encoding. + return m_aDefaultState.getCurrentEncoding(); + // Guess based on locale. + return msfilter::util::getBestTextEncodingFromLocale( + Application::GetSettings().GetLanguageTag().getLocale()); + } + + return m_pSuperstream->getEncoding(nFontIndex); +} + +OUString RTFDocumentImpl::getFontName(int nIndex) +{ + if (!m_pSuperstream) + return m_aFontNames[nIndex]; + + return m_pSuperstream->getFontName(nIndex); +} + +int RTFDocumentImpl::getFontIndex(int nIndex) +{ + if (!m_pSuperstream) + return std::find(m_aFontIndexes.begin(), m_aFontIndexes.end(), nIndex) + - m_aFontIndexes.begin(); + + return m_pSuperstream->getFontIndex(nIndex); +} + +OUString RTFDocumentImpl::getStyleName(int nIndex) +{ + if (!m_pSuperstream) + { + OUString aRet; + if (m_aStyleNames.find(nIndex) != m_aStyleNames.end()) + aRet = m_aStyleNames[nIndex]; + return aRet; + } + + return m_pSuperstream->getStyleName(nIndex); +} + +Id RTFDocumentImpl::getStyleType(int nIndex) +{ + if (!m_pSuperstream) + { + Id nRet = 0; + if (m_aStyleTypes.find(nIndex) != m_aStyleTypes.end()) + nRet = m_aStyleTypes[nIndex]; + return nRet; + } + + return m_pSuperstream->getStyleType(nIndex); +} + +RTFParserState& RTFDocumentImpl::getDefaultState() +{ + if (!m_pSuperstream) + return m_aDefaultState; + + return m_pSuperstream->getDefaultState(); +} + +oox::GraphicHelper& RTFDocumentImpl::getGraphicHelper() { return *m_pGraphicHelper; } + +bool RTFDocumentImpl::isStyleSheetImport() +{ + if (m_aStates.empty()) + return false; + Destination eDestination = m_aStates.top().getDestination(); + return eDestination == Destination::STYLESHEET || eDestination == Destination::STYLEENTRY; +} + +void RTFDocumentImpl::resolve(Stream& rMapper) +{ + m_pMapperStream = &rMapper; + switch (m_pTokenizer->resolveParse()) + { + case RTFError::OK: + SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolve: finished without errors"); + break; + case RTFError::GROUP_UNDER: + SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolve: unmatched '}'"); + break; + case RTFError::GROUP_OVER: + SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolve: unmatched '{'"); + throw io::WrongFormatException(m_pTokenizer->getPosition()); + break; + case RTFError::UNEXPECTED_EOF: + SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolve: unexpected end of file"); + throw io::WrongFormatException(m_pTokenizer->getPosition()); + break; + case RTFError::HEX_INVALID: + SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolve: invalid hex char"); + throw io::WrongFormatException(m_pTokenizer->getPosition()); + break; + case RTFError::CHAR_OVER: + SAL_INFO("writerfilter.rtf", "RTFDocumentImpl::resolve: characters after last '}'"); + break; + case RTFError::CLASSIFICATION: + SAL_INFO("writerfilter.rtf", + "RTFDocumentImpl::resolve: classification prevented paste"); + break; + } +} + +void RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference const& rShape) +{ + SvMemoryStream aStream; + SvStream* pStream = nullptr; + if (!m_pBinaryData) + { + pStream = &aStream; + int b = 0; + int count = 2; + + // Feed the destination text to a stream. + OString aStr = OUStringToOString(m_aStates.top().getDestinationText().makeStringAndClear(), + RTL_TEXTENCODING_ASCII_US); + for (int i = 0; i < aStr.getLength(); ++i) + { + char ch = aStr[i]; + if (ch != 0x0d && ch != 0x0a && ch != 0x20) + { + b = b << 4; + sal_Int8 parsed = msfilter::rtfutil::AsHex(ch); + if (parsed == -1) + return; + b += parsed; + count--; + if (!count) + { + aStream.WriteChar(static_cast(b)); + count = 2; + b = 0; + } + } + } + } + else + pStream = m_pBinaryData.get(); + + if (!pStream->Tell()) + // No destination text? Then we'll get it later. + return; + + SvMemoryStream aDIBStream; + if (m_aStates.top().getPicture().eStyle == RTFBmpStyle::DIBITMAP) + { + // Construct a BITMAPFILEHEADER structure before the real data. + SvStream& rBodyStream = *pStream; + aDIBStream.WriteChar('B'); + aDIBStream.WriteChar('M'); + // The size of the real data. + aDIBStream.WriteUInt32(rBodyStream.Tell()); + // Reserved. + aDIBStream.WriteUInt32(0); + // The offset of the real data, i.e. the size of the header, including this number. + aDIBStream.WriteUInt32(14); + rBodyStream.Seek(0); + aDIBStream.WriteStream(rBodyStream); + pStream = &aDIBStream; + } + + // Store, and get its URL. + pStream->Seek(0); + uno::Reference xInputStream(new utl::OInputStreamWrapper(pStream)); + WmfExternal aExtHeader; + aExtHeader.mapMode = m_aStates.top().getPicture().eWMetafile; + aExtHeader.xExt = sal_uInt16( + std::clamp(m_aStates.top().getPicture().nWidth, 0, + SAL_MAX_UINT16)); //TODO: better way to handle out-of-bounds values? + aExtHeader.yExt = sal_uInt16( + std::clamp(m_aStates.top().getPicture().nHeight, 0, + SAL_MAX_UINT16)); //TODO: better way to handle out-of-bounds values? + WmfExternal* pExtHeader = &aExtHeader; + uno::Reference xServiceInfo(m_aStates.top().getDrawingObject().getShape(), + uno::UNO_QUERY); + if (xServiceInfo.is() && xServiceInfo->supportsService("com.sun.star.text.TextFrame")) + pExtHeader = nullptr; + + uno::Reference xGraphic + = m_pGraphicHelper->importGraphic(xInputStream, pExtHeader); + + if (m_aStates.top().getPicture().eStyle != RTFBmpStyle::NONE) + { + // In case of PNG/JPEG, the real size is known, don't use the values + // provided by picw and pich. + + Graphic aGraphic(xGraphic); + Size aSize(aGraphic.GetPrefSize()); + MapMode aMap(MapUnit::Map100thMM); + if (aGraphic.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel) + aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, aMap); + else + aSize = OutputDevice::LogicToLogic(aSize, aGraphic.GetPrefMapMode(), aMap); + m_aStates.top().getPicture().nWidth = aSize.Width(); + m_aStates.top().getPicture().nHeight = aSize.Height(); + } + + // Wrap it in an XShape. + uno::Reference xShape(rShape); + if (xShape.is()) + { + uno::Reference xSI(xShape, uno::UNO_QUERY_THROW); + if (!xSI->supportsService("com.sun.star.drawing.GraphicObjectShape")) + { + // it's sometimes an error to get here - but it's possible to have + // a \pict inside the \shptxt of a \shp of shapeType 202 "TextBox" + // and in that case xShape is the text frame; we actually need a + // new GraphicObject then (example: fdo37691-1.rtf) + SAL_INFO("writerfilter.rtf", + "cannot set graphic on existing shape, creating a new GraphicObjectShape"); + xShape.clear(); + } + } + if (!xShape.is()) + { + if (m_xModelFactory.is()) + xShape.set(m_xModelFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), + uno::UNO_QUERY); + uno::Reference const xDrawSupplier(m_xDstDoc, uno::UNO_QUERY); + if (xDrawSupplier.is()) + { + uno::Reference xShapes = xDrawSupplier->getDrawPage(); + if (xShapes.is()) + xShapes->add(xShape); + } + } + + uno::Reference xPropertySet(xShape, uno::UNO_QUERY); + + if (xPropertySet.is()) + xPropertySet->setPropertyValue("Graphic", uno::Any(xGraphic)); + + // check if the picture is in an OLE object and if the \objdata element is used + // (see RTF_OBJECT in RTFDocumentImpl::dispatchDestination) + if (m_bObject) + { + // Set the object size + awt::Size aSize; + aSize.Width + = (m_aStates.top().getPicture().nGoalWidth ? m_aStates.top().getPicture().nGoalWidth + : m_aStates.top().getPicture().nWidth); + aSize.Height + = (m_aStates.top().getPicture().nGoalHeight ? m_aStates.top().getPicture().nGoalHeight + : m_aStates.top().getPicture().nHeight); + xShape->setSize(aSize); + + // Replacement graphic is inline by default, see oox::vml::SimpleShape::implConvertAndInsert(). + xPropertySet->setPropertyValue("AnchorType", + uno::makeAny(text::TextContentAnchorType_AS_CHARACTER)); + + auto pShapeValue = new RTFValue(xShape); + m_aObjectAttributes.set(NS_ooxml::LN_shape, pShapeValue); + return; + } + + if (m_aStates.top().getInListpicture()) + { + // Send the shape directly, no section is started, to additional properties will be ignored anyway. + Mapper().startShape(xShape); + Mapper().endShape(); + return; + } + + // Send it to the dmapper. + RTFSprms aSprms; + RTFSprms aAttributes; + // shape attribute + RTFSprms aPicAttributes; + auto pShapeValue = new RTFValue(xShape); + aPicAttributes.set(NS_ooxml::LN_shape, pShapeValue); + // pic sprm + RTFSprms aGraphicDataAttributes; + RTFSprms aGraphicDataSprms; + auto pPicValue = new RTFValue(aPicAttributes); + aGraphicDataSprms.set(NS_ooxml::LN_pic_pic, pPicValue); + // graphicData sprm + RTFSprms aGraphicAttributes; + RTFSprms aGraphicSprms; + auto pGraphicDataValue = new RTFValue(aGraphicDataAttributes, aGraphicDataSprms); + aGraphicSprms.set(NS_ooxml::LN_CT_GraphicalObject_graphicData, pGraphicDataValue); + // graphic sprm + auto pGraphicValue = new RTFValue(aGraphicAttributes, aGraphicSprms); + // extent sprm + RTFSprms aExtentAttributes; + int nXExt = (m_aStates.top().getPicture().nGoalWidth ? m_aStates.top().getPicture().nGoalWidth + : m_aStates.top().getPicture().nWidth); + int nYExt = (m_aStates.top().getPicture().nGoalHeight ? m_aStates.top().getPicture().nGoalHeight + : m_aStates.top().getPicture().nHeight); + if (m_aStates.top().getPicture().nScaleX != 100) + nXExt = (static_cast(m_aStates.top().getPicture().nScaleX) + * (nXExt + - (m_aStates.top().getPicture().nCropL + m_aStates.top().getPicture().nCropR))) + / 100L; + if (m_aStates.top().getPicture().nScaleY != 100) + nYExt = (static_cast(m_aStates.top().getPicture().nScaleY) + * (nYExt + - (m_aStates.top().getPicture().nCropT + m_aStates.top().getPicture().nCropB))) + / 100L; + if (m_aStates.top().getInShape()) + { + // Picture in shape: it looks like pib picture, so we will stretch the picture to shape size (tdf#49893) + nXExt = m_aStates.top().getShape().getRight() - m_aStates.top().getShape().getLeft(); + nYExt = m_aStates.top().getShape().getBottom() - m_aStates.top().getShape().getTop(); + } + auto pXExtValue = new RTFValue(oox::drawingml::convertHmmToEmu(nXExt)); + auto pYExtValue = new RTFValue(oox::drawingml::convertHmmToEmu(nYExt)); + aExtentAttributes.set(NS_ooxml::LN_CT_PositiveSize2D_cx, pXExtValue); + aExtentAttributes.set(NS_ooxml::LN_CT_PositiveSize2D_cy, pYExtValue); + auto pExtentValue = new RTFValue(aExtentAttributes); + // docpr sprm + RTFSprms aDocprAttributes; + for (const auto& rCharacterAttribute : m_aStates.top().getCharacterAttributes()) + if (rCharacterAttribute.first == NS_ooxml::LN_CT_NonVisualDrawingProps_name + || rCharacterAttribute.first == NS_ooxml::LN_CT_NonVisualDrawingProps_descr) + aDocprAttributes.set(rCharacterAttribute.first, rCharacterAttribute.second); + auto pDocprValue = new RTFValue(aDocprAttributes); + if (bInline) + { + RTFSprms aInlineAttributes; + aInlineAttributes.set(NS_ooxml::LN_CT_Inline_distT, new RTFValue(0)); + aInlineAttributes.set(NS_ooxml::LN_CT_Inline_distB, new RTFValue(0)); + aInlineAttributes.set(NS_ooxml::LN_CT_Inline_distL, new RTFValue(0)); + aInlineAttributes.set(NS_ooxml::LN_CT_Inline_distR, new RTFValue(0)); + RTFSprms aInlineSprms; + aInlineSprms.set(NS_ooxml::LN_CT_Inline_extent, pExtentValue); + aInlineSprms.set(NS_ooxml::LN_CT_Inline_docPr, pDocprValue); + aInlineSprms.set(NS_ooxml::LN_graphic_graphic, pGraphicValue); + // inline sprm + auto pValue = new RTFValue(aInlineAttributes, aInlineSprms); + aSprms.set(NS_ooxml::LN_inline_inline, pValue); + } + else // anchored + { + // wrap sprm + RTFSprms aAnchorWrapAttributes; + m_aStates.top().getShape().getAnchorAttributes().set( + NS_ooxml::LN_CT_Anchor_behindDoc, + new RTFValue((m_aStates.top().getShape().getInBackground()) ? 1 : 0)); + RTFSprms aAnchorSprms; + for (const auto& rCharacterAttribute : m_aStates.top().getCharacterAttributes()) + { + if (rCharacterAttribute.first == NS_ooxml::LN_CT_WrapSquare_wrapText) + aAnchorWrapAttributes.set(rCharacterAttribute.first, rCharacterAttribute.second); + } + sal_Int32 nWrap = -1; + for (auto& rCharacterSprm : m_aStates.top().getCharacterSprms()) + { + if (rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapNone + || rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapTight) + { + nWrap = rCharacterSprm.first; + + // If there is a wrap polygon prepared by RTFSdrImport, pick it up here. + if (rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapTight + && !m_aStates.top().getShape().getWrapPolygonSprms().empty()) + rCharacterSprm.second->getSprms().set( + NS_ooxml::LN_CT_WrapTight_wrapPolygon, + new RTFValue(RTFSprms(), m_aStates.top().getShape().getWrapPolygonSprms())); + + aAnchorSprms.set(rCharacterSprm.first, rCharacterSprm.second); + } + } + + if (m_aStates.top().getShape().getWrapSprm().first != 0) + // Replay of a buffered shape, wrap sprm there has priority over + // character sprms of the current state. + aAnchorSprms.set(m_aStates.top().getShape().getWrapSprm().first, + m_aStates.top().getShape().getWrapSprm().second); + + aAnchorSprms.set(NS_ooxml::LN_CT_Anchor_extent, pExtentValue); + if (!aAnchorWrapAttributes.empty() && nWrap == -1) + aAnchorSprms.set(NS_ooxml::LN_EG_WrapType_wrapSquare, + new RTFValue(aAnchorWrapAttributes)); + + // See OOXMLFastContextHandler::positionOffset(), we can't just put offset values in an RTFValue. + RTFSprms aPoshAttributes; + RTFSprms aPoshSprms; + if (m_aStates.top().getShape().getHoriOrientRelationToken() > 0) + aPoshAttributes.set( + NS_ooxml::LN_CT_PosH_relativeFrom, + new RTFValue(m_aStates.top().getShape().getHoriOrientRelationToken())); + if (m_aStates.top().getShape().getLeft() != 0) + { + Mapper().positionOffset(OUString::number(oox::drawingml::convertHmmToEmu( + m_aStates.top().getShape().getLeft())), + /*bVertical=*/false); + aPoshSprms.set(NS_ooxml::LN_CT_PosH_posOffset, new RTFValue()); + } + aAnchorSprms.set(NS_ooxml::LN_CT_Anchor_positionH, + new RTFValue(aPoshAttributes, aPoshSprms)); + + RTFSprms aPosvAttributes; + RTFSprms aPosvSprms; + if (m_aStates.top().getShape().getVertOrientRelationToken() > 0) + aPosvAttributes.set( + NS_ooxml::LN_CT_PosV_relativeFrom, + new RTFValue(m_aStates.top().getShape().getVertOrientRelationToken())); + if (m_aStates.top().getShape().getTop() != 0) + { + Mapper().positionOffset(OUString::number(oox::drawingml::convertHmmToEmu( + m_aStates.top().getShape().getTop())), + /*bVertical=*/true); + aPosvSprms.set(NS_ooxml::LN_CT_PosV_posOffset, new RTFValue()); + } + aAnchorSprms.set(NS_ooxml::LN_CT_Anchor_positionV, + new RTFValue(aPosvAttributes, aPosvSprms)); + + aAnchorSprms.set(NS_ooxml::LN_CT_Anchor_docPr, pDocprValue); + aAnchorSprms.set(NS_ooxml::LN_graphic_graphic, pGraphicValue); + // anchor sprm + auto pValue = new RTFValue(m_aStates.top().getShape().getAnchorAttributes(), aAnchorSprms); + aSprms.set(NS_ooxml::LN_anchor_anchor, pValue); + } + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aAttributes, aSprms); + checkFirstRun(); + + if (!m_aStates.top().getCurrentBuffer()) + { + Mapper().props(pProperties); + // Make sure we don't lose these properties with a too early reset. + m_bHadPicture = true; + } + else + { + auto pValue = new RTFValue(aAttributes, aSprms); + bufferProperties(*m_aStates.top().getCurrentBuffer(), pValue, nullptr); + } +} + +RTFError RTFDocumentImpl::resolveChars(char ch) +{ + if (m_aStates.top().getInternalState() == RTFInternalState::BIN) + { + m_pBinaryData = std::make_shared(); + m_pBinaryData->WriteChar(ch); + for (int i = 0; i < m_aStates.top().getBinaryToRead() - 1; ++i) + { + Strm().ReadChar(ch); + m_pBinaryData->WriteChar(ch); + } + m_aStates.top().setInternalState(RTFInternalState::NORMAL); + return RTFError::OK; + } + + OStringBuffer aBuf(512); + + bool bUnicodeChecked = false; + bool bSkipped = false; + + while (!Strm().eof() + && (m_aStates.top().getInternalState() == RTFInternalState::HEX + || (ch != '{' && ch != '}' && ch != '\\'))) + { + if (m_aStates.top().getInternalState() == RTFInternalState::HEX + || (ch != 0x0d && ch != 0x0a)) + { + if (m_aStates.top().getCharsToSkip() == 0) + { + if (!bUnicodeChecked) + { + checkUnicode(/*bUnicode =*/true, /*bHex =*/false); + bUnicodeChecked = true; + } + aBuf.append(ch); + } + else + { + bSkipped = true; + m_aStates.top().getCharsToSkip()--; + } + } + + // read a single char if we're in hex mode + if (m_aStates.top().getInternalState() == RTFInternalState::HEX) + break; + + if (RTL_TEXTENCODING_MS_932 == m_aStates.top().getCurrentEncoding()) + { + unsigned char uch = ch; + if ((uch >= 0x80 && uch <= 0x9F) || uch >= 0xE0) + { + // read second byte of 2-byte Shift-JIS - may be \ { } + Strm().ReadChar(ch); + if (m_aStates.top().getCharsToSkip() == 0) + { + // fdo#79384: Word will reject Shift-JIS following \loch + // but apparently OOo could read and (worse) write such documents + SAL_INFO_IF(m_aStates.top().getRunType() != RTFParserState::RunType::DBCH, + "writerfilter.rtf", "invalid Shift-JIS without DBCH"); + assert(bUnicodeChecked); + aBuf.append(ch); + } + else + { + assert(bSkipped); + // anybody who uses \ucN with Shift-JIS is insane + m_aStates.top().getCharsToSkip()--; + } + } + } + + Strm().ReadChar(ch); + } + if (m_aStates.top().getInternalState() != RTFInternalState::HEX && !Strm().eof()) + Strm().SeekRel(-1); + + if (m_aStates.top().getInternalState() == RTFInternalState::HEX + && m_aStates.top().getDestination() != Destination::LEVELNUMBERS) + { + if (!bSkipped) + { + // note: apparently \'0d\'0a is interpreted as 2 breaks, not 1 + if ((ch == '\r' || ch == '\n') + && m_aStates.top().getDestination() != Destination::DOCCOMM + && m_aStates.top().getDestination() != Destination::LEVELNUMBERS + && m_aStates.top().getDestination() != Destination::LEVELTEXT) + { + checkUnicode(/*bUnicode =*/false, /*bHex =*/true); + dispatchSymbol(RTF_PAR); + } + else + { + m_aHexBuffer.append(ch); + } + } + return RTFError::OK; + } + + if (m_aStates.top().getDestination() == Destination::SKIP) + return RTFError::OK; + OString aStr = aBuf.makeStringAndClear(); + if (m_aStates.top().getDestination() == Destination::LEVELNUMBERS) + { + if (aStr.toChar() != ';') + m_aStates.top().getLevelNumbers().push_back(sal_Int32(ch)); + return RTFError::OK; + } + + SAL_INFO("writerfilter.rtf", + "RTFDocumentImpl::resolveChars: collected '" + << OStringToOUString(aStr, m_aStates.top().getCurrentEncoding()) << "'"); + + if (m_aStates.top().getDestination() == Destination::COLORTABLE) + { + // we hit a ';' at the end of each color entry + m_aColorTable.push_back(m_aStates.top().getCurrentColor().GetColor()); + // set components back to zero + m_aStates.top().getCurrentColor() = RTFColorTableEntry(); + } + else if (!aStr.isEmpty()) + m_aHexBuffer.append(aStr); + + checkUnicode(/*bUnicode =*/false, /*bHex =*/true); + return RTFError::OK; +} + +bool RTFFrame::inFrame() const { return m_nW > 0 || m_nH > 0 || m_nX > 0 || m_nY > 0; } + +void RTFDocumentImpl::singleChar(sal_uInt8 nValue, bool bRunProps) +{ + sal_uInt8 sValue[] = { nValue }; + RTFBuffer_t* pCurrentBuffer = m_aStates.top().getCurrentBuffer(); + + if (!pCurrentBuffer) + { + Mapper().startCharacterGroup(); + // Should we send run properties? + if (bRunProps) + runProps(); + Mapper().text(sValue, 1); + Mapper().endCharacterGroup(); + } + else + { + pCurrentBuffer->push_back(Buf_t(BUFFER_STARTRUN, nullptr, nullptr)); + auto pValue = new RTFValue(*sValue); + pCurrentBuffer->push_back(Buf_t(BUFFER_TEXT, pValue, nullptr)); + pCurrentBuffer->push_back(Buf_t(BUFFER_ENDRUN, nullptr, nullptr)); + } +} + +void RTFDocumentImpl::text(OUString& rString) +{ + if (rString.getLength() == 1 && m_aStates.top().getDestination() != Destination::DOCCOMM) + { + // No cheating! Tokenizer ignores bare \r and \n, their hex \'0d / \'0a form doesn't count, either. + sal_Unicode ch = rString[0]; + if (ch == 0x0d || ch == 0x0a) + return; + } + + bool bRet = true; + switch (m_aStates.top().getDestination()) + { + // Note: in fonttbl there may or may not be groups; in stylesheet + // and revtbl groups are mandatory + case Destination::FONTTABLE: + case Destination::FONTENTRY: + case Destination::STYLEENTRY: + case Destination::LISTNAME: + case Destination::REVISIONENTRY: + { + // ; is the end of the entry + bool bEnd = false; + if (rString.endsWith(";")) + { + rString = rString.copy(0, rString.getLength() - 1); + bEnd = true; + } + m_aStates.top().appendDestinationText(rString); + if (bEnd) + { + // always clear, necessary in case of group-less fonttable + OUString const aName + = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + switch (m_aStates.top().getDestination()) + { + case Destination::FONTTABLE: + case Destination::FONTENTRY: + { + m_aFontNames[m_nCurrentFontIndex] = aName; + if (m_nCurrentEncoding >= 0) + { + m_aFontEncodings[m_nCurrentFontIndex] = m_nCurrentEncoding; + m_nCurrentEncoding = -1; + } + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_Font_name, + new RTFValue(aName)); + + writerfilter::Reference::Pointer_t const pProp( + new RTFReferenceProperties(m_aStates.top().getTableAttributes(), + m_aStates.top().getTableSprms())); + + //See fdo#47347 initial invalid font entry properties are inserted first, + //so when we attempt to insert the correct ones, there's already an + //entry in the map for them, so the new ones aren't inserted. + auto lb = m_aFontTableEntries.lower_bound(m_nCurrentFontIndex); + if (lb != m_aFontTableEntries.end() + && !(m_aFontTableEntries.key_comp()(m_nCurrentFontIndex, lb->first))) + lb->second = pProp; + else + m_aFontTableEntries.insert(lb, + std::make_pair(m_nCurrentFontIndex, pProp)); + } + break; + case Destination::STYLEENTRY: + { + RTFValue::Pointer_t pType + = m_aStates.top().getTableAttributes().find(NS_ooxml::LN_CT_Style_type); + if (pType) + { + // Word strips whitespace around style names. + m_aStyleNames[m_nCurrentStyleIndex] = aName.trim(); + m_aStyleTypes[m_nCurrentStyleIndex] = pType->getInt(); + auto pValue = new RTFValue(aName.trim()); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_Style_styleId, + pValue); + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Style_name, pValue); + + writerfilter::Reference::Pointer_t const pProp( + createStyleProperties()); + m_aStyleTableEntries.insert( + std::make_pair(m_nCurrentStyleIndex, pProp)); + } + else + SAL_INFO("writerfilter.rtf", "no RTF style type defined, ignoring"); + break; + } + case Destination::LISTNAME: + // TODO: what can be done with a list name? + break; + case Destination::REVISIONENTRY: + m_aAuthors[m_aAuthors.size()] = aName; + break; + default: + break; + } + resetAttributes(); + resetSprms(); + } + } + break; + case Destination::LEVELTEXT: + case Destination::SHAPEPROPERTYNAME: + case Destination::SHAPEPROPERTYVALUE: + case Destination::BOOKMARKEND: + case Destination::PICT: + case Destination::SHAPEPROPERTYVALUEPICT: + case Destination::FORMFIELDNAME: + case Destination::FORMFIELDLIST: + case Destination::DATAFIELD: + case Destination::AUTHOR: + case Destination::KEYWORDS: + case Destination::OPERATOR: + case Destination::COMPANY: + case Destination::COMMENT: + case Destination::OBJDATA: + case Destination::OBJCLASS: + case Destination::ANNOTATIONDATE: + case Destination::ANNOTATIONAUTHOR: + case Destination::ANNOTATIONREFERENCE: + case Destination::FALT: + case Destination::PARAGRAPHNUMBERING_TEXTAFTER: + case Destination::PARAGRAPHNUMBERING_TEXTBEFORE: + case Destination::TITLE: + case Destination::SUBJECT: + case Destination::DOCCOMM: + case Destination::ATNID: + case Destination::ANNOTATIONREFERENCESTART: + case Destination::ANNOTATIONREFERENCEEND: + case Destination::MR: + case Destination::MCHR: + case Destination::MPOS: + case Destination::MVERTJC: + case Destination::MSTRIKEH: + case Destination::MDEGHIDE: + case Destination::MBEGCHR: + case Destination::MSEPCHR: + case Destination::MENDCHR: + case Destination::MSUBHIDE: + case Destination::MSUPHIDE: + case Destination::MTYPE: + case Destination::MGROW: + case Destination::INDEXENTRY: + case Destination::TOCENTRY: + case Destination::PROPNAME: + case Destination::STATICVAL: + m_aStates.top().appendDestinationText(rString); + break; + case Destination::GENERATOR: + // don't enlarge space sequences, eg. it was saved in LibreOffice + if (!rString.startsWithIgnoreAsciiCase("Microsoft")) + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_longerSpaceSequence, + new RTFValue(0)); + break; + default: + bRet = false; + break; + } + if (bRet) + return; + + if (!m_aIgnoreFirst.isEmpty() && m_aIgnoreFirst == rString) + { + m_aIgnoreFirst.clear(); + return; + } + + // Are we in the middle of the table definition? (No cell defs yet, but we already have some cell props.) + if (m_aStates.top().getTableCellSprms().find(NS_ooxml::LN_CT_TcPrBase_vAlign) + && m_nTopLevelCells == 0) + { + m_aTableBufferStack.back().emplace_back( + Buf_t(BUFFER_UTEXT, new RTFValue(rString), nullptr)); + return; + } + + checkFirstRun(); + checkNeedPap(); + + // Don't return earlier, a bookmark start has to be in a paragraph group. + if (m_aStates.top().getDestination() == Destination::BOOKMARKSTART) + { + m_aStates.top().appendDestinationText(rString); + return; + } + + RTFBuffer_t* pCurrentBuffer = m_aStates.top().getCurrentBuffer(); + + if (!pCurrentBuffer && m_aStates.top().getDestination() != Destination::FOOTNOTE) + Mapper().startCharacterGroup(); + else if (pCurrentBuffer) + { + RTFValue::Pointer_t pValue; + pCurrentBuffer->push_back(Buf_t(BUFFER_STARTRUN, pValue, nullptr)); + } + + if (m_aStates.top().getDestination() == Destination::NORMAL + || m_aStates.top().getDestination() == Destination::FIELDRESULT + || m_aStates.top().getDestination() == Destination::SHAPETEXT) + runProps(); + + if (!pCurrentBuffer) + Mapper().utext(reinterpret_cast(rString.getStr()), rString.getLength()); + else + { + auto pValue = new RTFValue(rString); + pCurrentBuffer->push_back(Buf_t(BUFFER_UTEXT, pValue, nullptr)); + } + + m_bNeedCr = true; + + if (!pCurrentBuffer && m_aStates.top().getDestination() != Destination::FOOTNOTE) + Mapper().endCharacterGroup(); + else if (pCurrentBuffer) + { + RTFValue::Pointer_t pValue; + pCurrentBuffer->push_back(Buf_t(BUFFER_ENDRUN, pValue, nullptr)); + } +} + +void RTFDocumentImpl::prepareProperties( + RTFParserState& rState, writerfilter::Reference::Pointer_t& o_rpParagraphProperties, + writerfilter::Reference::Pointer_t& o_rpFrameProperties, + writerfilter::Reference::Pointer_t& o_rpTableRowProperties, int const nCells, + int const nCurrentCellX) +{ + o_rpParagraphProperties + = getProperties(rState.getParagraphAttributes(), rState.getParagraphSprms(), + NS_ooxml::LN_Value_ST_StyleType_paragraph); + + if (rState.getFrame().hasProperties()) + { + o_rpFrameProperties = new RTFReferenceProperties(RTFSprms(), rState.getFrame().getSprms()); + } + + // Table width. + RTFValue::Pointer_t const pTableWidthProps + = rState.getTableRowSprms().find(NS_ooxml::LN_CT_TblPrBase_tblW); + if (!pTableWidthProps) + { + auto pUnitValue = new RTFValue(3); + putNestedAttribute(rState.getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblW, + NS_ooxml::LN_CT_TblWidth_type, pUnitValue); + auto pWValue = new RTFValue(nCurrentCellX); + putNestedAttribute(rState.getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblW, + NS_ooxml::LN_CT_TblWidth_w, pWValue); + } + + if (nCells > 0) + rState.getTableRowSprms().set(NS_ooxml::LN_tblRow, new RTFValue(1)); + + RTFValue::Pointer_t const pCellMar + = rState.getTableRowSprms().find(NS_ooxml::LN_CT_TblPrBase_tblCellMar); + if (!pCellMar) + { + // If no cell margins are defined, the default left/right margin is 0 in Word, but not in Writer. + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_TblWidth_type, + new RTFValue(NS_ooxml::LN_Value_ST_TblWidth_dxa)); + aAttributes.set(NS_ooxml::LN_CT_TblWidth_w, new RTFValue(0)); + putNestedSprm(rState.getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblCellMar, + NS_ooxml::LN_CT_TblCellMar_left, new RTFValue(aAttributes)); + putNestedSprm(rState.getTableRowSprms(), NS_ooxml::LN_CT_TblPrBase_tblCellMar, + NS_ooxml::LN_CT_TblCellMar_right, new RTFValue(aAttributes)); + } + + o_rpTableRowProperties + = new RTFReferenceProperties(rState.getTableRowAttributes(), rState.getTableRowSprms()); +} + +void RTFDocumentImpl::sendProperties( + writerfilter::Reference::Pointer_t const& pParagraphProperties, + writerfilter::Reference::Pointer_t const& pFrameProperties, + writerfilter::Reference::Pointer_t const& pTableRowProperties) +{ + Mapper().props(pParagraphProperties); + + if (pFrameProperties) + { + Mapper().props(pFrameProperties); + } + + Mapper().props(pTableRowProperties); + + tableBreak(); +} + +void RTFDocumentImpl::replayRowBuffer(RTFBuffer_t& rBuffer, ::std::deque& rCellsSrpms, + ::std::deque& rCellsAttributes, int const nCells) +{ + for (int i = 0; i < nCells; ++i) + { + replayBuffer(rBuffer, &rCellsSrpms.front(), &rCellsAttributes.front()); + rCellsSrpms.pop_front(); + rCellsAttributes.pop_front(); + } + for (Buf_t& i : rBuffer) + { + SAL_WARN_IF(BUFFER_CELLEND == std::get<0>(i), "writerfilter.rtf", "dropping table cell!"); + } + assert(rCellsSrpms.empty()); + assert(rCellsAttributes.empty()); +} + +void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer, RTFSprms* const pSprms, + RTFSprms const* const pAttributes) +{ + while (!rBuffer.empty()) + { + Buf_t aTuple(rBuffer.front()); + rBuffer.pop_front(); + if (std::get<0>(aTuple) == BUFFER_PROPS) + { + // Construct properties via getProperties() and not directly, to take care of deduplication. + writerfilter::Reference::Pointer_t const pProp(getProperties( + std::get<1>(aTuple)->getAttributes(), std::get<1>(aTuple)->getSprms(), 0)); + Mapper().props(pProp); + } + else if (std::get<0>(aTuple) == BUFFER_NESTROW) + { + TableRowBuffer& rRowBuffer(*std::get<2>(aTuple)); + + replayRowBuffer(rRowBuffer.GetBuffer(), rRowBuffer.GetCellsSprms(), + rRowBuffer.GetCellsAttributes(), rRowBuffer.GetCells()); + + sendProperties(rRowBuffer.GetParaProperties(), rRowBuffer.GetFrameProperties(), + rRowBuffer.GetRowProperties()); + } + else if (std::get<0>(aTuple) == BUFFER_CELLEND) + { + assert(pSprms && pAttributes); + auto pValue = new RTFValue(1); + pSprms->set(NS_ooxml::LN_tblCell, pValue); + writerfilter::Reference::Pointer_t const pTableCellProperties( + new RTFReferenceProperties(*pAttributes, *pSprms)); + Mapper().props(pTableCellProperties); + tableBreak(); + break; + } + else if (std::get<0>(aTuple) == BUFFER_STARTRUN) + Mapper().startCharacterGroup(); + else if (std::get<0>(aTuple) == BUFFER_TEXT) + { + sal_uInt8 const nValue = std::get<1>(aTuple)->getInt(); + Mapper().text(&nValue, 1); + } + else if (std::get<0>(aTuple) == BUFFER_UTEXT) + { + OUString const aString(std::get<1>(aTuple)->getString()); + Mapper().utext(reinterpret_cast(aString.getStr()), + aString.getLength()); + } + else if (std::get<0>(aTuple) == BUFFER_ENDRUN) + Mapper().endCharacterGroup(); + else if (std::get<0>(aTuple) == BUFFER_PAR) + parBreak(); + else if (std::get<0>(aTuple) == BUFFER_STARTSHAPE) + m_pSdrImport->resolve(std::get<1>(aTuple)->getShape(), false, RTFSdrImport::SHAPE); + else if (std::get<0>(aTuple) == BUFFER_RESOLVESHAPE) + { + // Make sure there is no current buffer while replaying the shape, + // otherwise it gets re-buffered. + RTFBuffer_t* pCurrentBuffer = m_aStates.top().getCurrentBuffer(); + m_aStates.top().setCurrentBuffer(nullptr); + + // Set current shape during replay, needed by e.g. wrap in + // background. + m_aStates.top().getShape() = std::get<1>(aTuple)->getShape(); + + m_pSdrImport->resolve(std::get<1>(aTuple)->getShape(), true, RTFSdrImport::SHAPE); + m_aStates.top().setCurrentBuffer(pCurrentBuffer); + } + else if (std::get<0>(aTuple) == BUFFER_ENDSHAPE) + m_pSdrImport->close(); + else if (std::get<0>(aTuple) == BUFFER_RESOLVESUBSTREAM) + { + RTFSprms& rAttributes = std::get<1>(aTuple)->getAttributes(); + std::size_t nPos = rAttributes.find(0)->getInt(); + Id nId = rAttributes.find(1)->getInt(); + OUString aCustomMark = rAttributes.find(2)->getString(); + resolveSubstream(nPos, nId, aCustomMark); + } + else if (std::get<0>(aTuple) == BUFFER_PICTURE) + m_aStates.top().getPicture() = std::get<1>(aTuple)->getPicture(); + else if (std::get<0>(aTuple) == BUFFER_SETSTYLE) + { + if (!m_aStates.empty()) + m_aStates.top().setCurrentStyleIndex(std::get<1>(aTuple)->getInt()); + } + else + assert(false); + } +} + +bool findPropertyName(const std::vector& rProperties, const OUString& rName) +{ + for (auto& rProperty : rProperties) + { + if (rProperty.Name == rName) + return true; + } + return false; +} + +void RTFDocumentImpl::backupTableRowProperties() +{ + if (m_nTopLevelCurrentCellX) + { + m_aBackupTableRowSprms = m_aStates.top().getTableRowSprms(); + m_aBackupTableRowAttributes = m_aStates.top().getTableRowAttributes(); + m_nBackupTopLevelCurrentCellX = m_nTopLevelCurrentCellX; + } +} + +void RTFDocumentImpl::restoreTableRowProperties() +{ + m_aStates.top().getTableRowSprms() = m_aBackupTableRowSprms; + m_aStates.top().getTableRowAttributes() = m_aBackupTableRowAttributes; + m_nTopLevelCurrentCellX = m_nBackupTopLevelCurrentCellX; +} + +void RTFDocumentImpl::resetTableRowProperties() +{ + m_aStates.top().getTableRowSprms() = m_aDefaultState.getTableRowSprms(); + m_aStates.top().getTableRowSprms().set(NS_ooxml::LN_CT_TblGridBase_gridCol, new RTFValue(-1), + RTFOverwrite::NO_APPEND); + m_aStates.top().getTableRowAttributes() = m_aDefaultState.getTableRowAttributes(); + if (Destination::NESTEDTABLEPROPERTIES == m_aStates.top().getDestination()) + { + m_nNestedTRLeft = 0; + m_nNestedCurrentCellX = 0; + } + else + { + m_nTopLevelTRLeft = 0; + m_nTopLevelCurrentCellX = 0; + } +} + +RTFError RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) +{ + setNeedSect(true); + checkUnicode(/*bUnicode =*/true, /*bHex =*/true); + RTFSkipDestination aSkip(*this); + int nSprm = -1; + tools::SvRef pBoolValue(new RTFValue(int(!bParam || nParam != 0))); + + // Underline toggles. + switch (nKeyword) + { + case RTF_UL: + nSprm = NS_ooxml::LN_Value_ST_Underline_single; + break; + case RTF_ULDASH: + nSprm = NS_ooxml::LN_Value_ST_Underline_dash; + break; + case RTF_ULDASHD: + nSprm = NS_ooxml::LN_Value_ST_Underline_dotDash; + break; + case RTF_ULDASHDD: + nSprm = NS_ooxml::LN_Value_ST_Underline_dotDotDash; + break; + case RTF_ULDB: + nSprm = NS_ooxml::LN_Value_ST_Underline_double; + break; + case RTF_ULHWAVE: + nSprm = NS_ooxml::LN_Value_ST_Underline_wavyHeavy; + break; + case RTF_ULLDASH: + nSprm = NS_ooxml::LN_Value_ST_Underline_dashLong; + break; + case RTF_ULTH: + nSprm = NS_ooxml::LN_Value_ST_Underline_thick; + break; + case RTF_ULTHD: + nSprm = NS_ooxml::LN_Value_ST_Underline_dottedHeavy; + break; + case RTF_ULTHDASH: + nSprm = NS_ooxml::LN_Value_ST_Underline_dashedHeavy; + break; + case RTF_ULTHDASHD: + nSprm = NS_ooxml::LN_Value_ST_Underline_dashDotHeavy; + break; + case RTF_ULTHDASHDD: + nSprm = NS_ooxml::LN_Value_ST_Underline_dashDotDotHeavy; + break; + case RTF_ULTHLDASH: + nSprm = NS_ooxml::LN_Value_ST_Underline_dashLongHeavy; + break; + case RTF_ULULDBWAVE: + nSprm = NS_ooxml::LN_Value_ST_Underline_wavyDouble; + break; + case RTF_ULWAVE: + nSprm = NS_ooxml::LN_Value_ST_Underline_wave; + break; + default: + break; + } + if (nSprm >= 0) + { + auto pValue + = new RTFValue((!bParam || nParam != 0) ? nSprm : NS_ooxml::LN_Value_ST_Underline_none); + m_aStates.top().getCharacterAttributes().set(NS_ooxml::LN_CT_Underline_val, pValue); + return RTFError::OK; + } + + // Accent characters (over dot / over comma). + switch (nKeyword) + { + case RTF_ACCNONE: + nSprm = NS_ooxml::LN_Value_ST_Em_none; + break; + case RTF_ACCDOT: + nSprm = NS_ooxml::LN_Value_ST_Em_dot; + break; + case RTF_ACCCOMMA: + nSprm = NS_ooxml::LN_Value_ST_Em_comma; + break; + case RTF_ACCCIRCLE: + nSprm = NS_ooxml::LN_Value_ST_Em_circle; + break; + case RTF_ACCUNDERDOT: + nSprm = NS_ooxml::LN_Value_ST_Em_underDot; + break; + default: + break; + } + if (nSprm >= 0) + { + auto pValue = new RTFValue((!bParam || nParam != 0) ? nSprm : 0); + m_aStates.top().getCharacterSprms().set(NS_ooxml::LN_EG_RPrBase_em, pValue); + return RTFError::OK; + } + + // Trivial character sprms. + switch (nKeyword) + { + case RTF_B: + case RTF_AB: + switch (m_aStates.top().getRunType()) + { + case RTFParserState::RunType::HICH: + case RTFParserState::RunType::RTLCH_LTRCH_1: + case RTFParserState::RunType::LTRCH_RTLCH_2: + case RTFParserState::RunType::DBCH: + nSprm = NS_ooxml::LN_EG_RPrBase_bCs; + break; + case RTFParserState::RunType::NONE: + case RTFParserState::RunType::LOCH: + case RTFParserState::RunType::LTRCH_RTLCH_1: + case RTFParserState::RunType::RTLCH_LTRCH_2: + default: + nSprm = NS_ooxml::LN_EG_RPrBase_b; + break; + } + break; + case RTF_I: + case RTF_AI: + switch (m_aStates.top().getRunType()) + { + case RTFParserState::RunType::HICH: + case RTFParserState::RunType::RTLCH_LTRCH_1: + case RTFParserState::RunType::LTRCH_RTLCH_2: + case RTFParserState::RunType::DBCH: + nSprm = NS_ooxml::LN_EG_RPrBase_iCs; + break; + case RTFParserState::RunType::NONE: + case RTFParserState::RunType::LOCH: + case RTFParserState::RunType::LTRCH_RTLCH_1: + case RTFParserState::RunType::RTLCH_LTRCH_2: + default: + nSprm = NS_ooxml::LN_EG_RPrBase_i; + break; + } + break; + case RTF_OUTL: + nSprm = NS_ooxml::LN_EG_RPrBase_outline; + break; + case RTF_SHAD: + nSprm = NS_ooxml::LN_EG_RPrBase_shadow; + break; + case RTF_V: + nSprm = NS_ooxml::LN_EG_RPrBase_vanish; + break; + case RTF_STRIKE: + nSprm = NS_ooxml::LN_EG_RPrBase_strike; + break; + case RTF_STRIKED: + nSprm = NS_ooxml::LN_EG_RPrBase_dstrike; + break; + case RTF_SCAPS: + nSprm = NS_ooxml::LN_EG_RPrBase_smallCaps; + break; + case RTF_IMPR: + nSprm = NS_ooxml::LN_EG_RPrBase_imprint; + break; + case RTF_CAPS: + nSprm = NS_ooxml::LN_EG_RPrBase_caps; + break; + default: + break; + } + if (nSprm >= 0) + { + m_aStates.top().getCharacterSprms().set(nSprm, pBoolValue); + return RTFError::OK; + } + + switch (nKeyword) + { + case RTF_ASPALPHA: + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_autoSpaceDE, + pBoolValue); + break; + case RTF_DELETED: + case RTF_REVISED: + { + auto pValue = new RTFValue(nKeyword == RTF_DELETED ? oox::XML_del : oox::XML_ins); + putNestedAttribute(m_aStates.top().getCharacterSprms(), NS_ooxml::LN_trackchange, + NS_ooxml::LN_token, pValue); + } + break; + case RTF_SBAUTO: + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_spacing, + NS_ooxml::LN_CT_Spacing_beforeAutospacing, pBoolValue); + break; + case RTF_SAAUTO: + putNestedAttribute(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_spacing, + NS_ooxml::LN_CT_Spacing_afterAutospacing, pBoolValue); + break; + case RTF_FACINGP: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_evenAndOddHeaders, pBoolValue); + break; + case RTF_HYPHAUTO: + m_aSettingsTableSprms.set(NS_ooxml::LN_CT_Settings_autoHyphenation, pBoolValue); + break; + case RTF_HYPHPAR: + m_aStates.top().getParagraphSprms().set(NS_ooxml::LN_CT_PPrBase_suppressAutoHyphens, + new RTFValue(int(bParam && nParam == 0))); + break; + default: + { + SAL_INFO("writerfilter.rtf", + "TODO handle toggle '" << keywordToString(nKeyword) << "'"); + aSkip.setParsed(false); + } + break; + } + return RTFError::OK; +} + +RTFError RTFDocumentImpl::pushState() +{ + //SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << " before push: " << m_pTokenizer->getGroup()); + + checkUnicode(/*bUnicode =*/true, /*bHex =*/true); + m_nGroupStartPos = Strm().Tell(); + + if (m_aStates.empty()) + m_aStates.push(m_aDefaultState); + else + { + // fdo#85812 group resets run type of _current_ and new state (but not RTL) + if (m_aStates.top().getRunType() != RTFParserState::RunType::LTRCH_RTLCH_2 + && m_aStates.top().getRunType() != RTFParserState::RunType::RTLCH_LTRCH_2) + { + m_aStates.top().setRunType(RTFParserState::RunType::NONE); + } + + if (m_aStates.top().getDestination() == Destination::MR) + lcl_DestinationToMath(m_aStates.top().getCurrentDestinationText(), m_aMathBuffer, + m_bMathNor); + m_aStates.push(m_aStates.top()); + } + m_aStates.top().getDestinationText().setLength(0); // was copied: always reset! + + m_pTokenizer->pushGroup(); + + switch (m_aStates.top().getDestination()) + { + case Destination::FONTTABLE: + // this is a "faked" destination for the font entry + m_aStates.top().setCurrentDestinationText(&m_aStates.top().getDestinationText()); + m_aStates.top().setDestination(Destination::FONTENTRY); + break; + case Destination::STYLESHEET: + // this is a "faked" destination for the style sheet entry + m_aStates.top().setCurrentDestinationText(&m_aStates.top().getDestinationText()); + m_aStates.top().setDestination(Destination::STYLEENTRY); + { + // the *default* is \s0 i.e. paragraph style default + // this will be overwritten by \sN \csN \dsN \tsN + m_nCurrentStyleIndex = 0; + auto pValue = new RTFValue(NS_ooxml::LN_Value_ST_StyleType_paragraph); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_Style_type, pValue); + } + break; + case Destination::FIELDRESULT: + case Destination::SHAPETEXT: + case Destination::FORMFIELD: + case Destination::FIELDINSTRUCTION: + case Destination::PICT: + m_aStates.top().setDestination(Destination::NORMAL); + break; + case Destination::MNUM: + case Destination::MDEN: + case Destination::ME: + case Destination::MFNAME: + case Destination::MLIM: + case Destination::MSUB: + case Destination::MSUP: + case Destination::MDEG: + case Destination::MOMATH: + m_aStates.top().setDestination(Destination::MR); + break; + case Destination::REVISIONTABLE: + // this is a "faked" destination for the revision table entry + m_aStates.top().setCurrentDestinationText(&m_aStates.top().getDestinationText()); + m_aStates.top().setDestination(Destination::REVISIONENTRY); + break; + default: + break; + } + + // If this is true, then ooxml:endtrackchange will be generated. Make sure + // we don't generate more ooxml:endtrackchange than ooxml:trackchange: new + // state does not inherit this flag. + m_aStates.top().setStartedTrackchange(false); + + return RTFError::OK; +} + +writerfilter::Reference::Pointer_t RTFDocumentImpl::createStyleProperties() +{ + int nBasedOn = 0; + RTFValue::Pointer_t pBasedOn + = m_aStates.top().getTableSprms().find(NS_ooxml::LN_CT_Style_basedOn); + if (pBasedOn) + nBasedOn = pBasedOn->getInt(); + if (nBasedOn == 0) + { + // No parent style, then mimic what Word does: ignore attributes which + // would set a margin as formatting, but with a default value. + for (const auto& nId : + { NS_ooxml::LN_CT_Ind_firstLine, NS_ooxml::LN_CT_Ind_left, NS_ooxml::LN_CT_Ind_right, + NS_ooxml::LN_CT_Ind_start, NS_ooxml::LN_CT_Ind_end }) + { + RTFValue::Pointer_t pValue = getNestedAttribute(m_aStates.top().getParagraphSprms(), + NS_ooxml::LN_CT_PPrBase_ind, nId); + if (pValue && pValue->getInt() == 0) + eraseNestedAttribute(m_aStates.top().getParagraphSprms(), + NS_ooxml::LN_CT_PPrBase_ind, nId); + } + } + + RTFValue::Pointer_t pParaProps = new RTFValue(m_aStates.top().getParagraphAttributes(), + m_aStates.top().getParagraphSprms()); + RTFValue::Pointer_t pCharProps = new RTFValue(m_aStates.top().getCharacterAttributes(), + m_aStates.top().getCharacterSprms()); + + // resetSprms will clean up this modification + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Style_pPr, pParaProps); + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Style_rPr, pCharProps); + + writerfilter::Reference::Pointer_t pProps(new RTFReferenceProperties( + m_aStates.top().getTableAttributes(), m_aStates.top().getTableSprms())); + return pProps; +} + +/** 2 different representations of the styles are needed: + + 1) flat content, as read from the input file: + stored in m_aStyleTableEntries, used as reference input for + deduplication both here and for hard formatting in getProperties() + + 2) real content, with proper override of sprms/attributes where it differs + from parent style; this is produced here and sent to domain mapper + */ +RTFReferenceTable::Entries_t RTFDocumentImpl::deduplicateStyleTable() +{ + RTFReferenceTable::Entries_t ret; + for (auto const& it : m_aStyleTableEntries) + { + auto pStyle = it.second; + // ugly downcasts here, but can't easily replace the members with + // RTFReferenceProperties because dmapper wants SvRef anyway + RTFValue::Pointer_t const pBasedOn( + static_cast(*pStyle).getSprms().find( + NS_ooxml::LN_CT_Style_basedOn)); + if (pBasedOn) + { + int const nBasedOn(pBasedOn->getInt()); + auto const itParent(m_aStyleTableEntries.find(nBasedOn)); // definition as read! + if (itParent != m_aStyleTableEntries.end()) + { + auto const pStyleType( + static_cast(*pStyle).getAttributes().find( + NS_ooxml::LN_CT_Style_type)); + assert(pStyleType); + int const nStyleType(pStyleType->getInt()); + RTFSprms const sprms( + static_cast(*pStyle).getSprms().cloneAndDeduplicate( + static_cast(*itParent->second).getSprms(), + nStyleType)); + RTFSprms const attributes( + static_cast(*pStyle) + .getAttributes() + .cloneAndDeduplicate( + static_cast(*itParent->second).getAttributes(), + nStyleType)); + + pStyle = new RTFReferenceProperties(attributes, sprms); + } + else + { + SAL_WARN("writerfilter.rtf", "parent style not found: " << nBasedOn); + } + } + ret[it.first] = pStyle; + } + assert(ret.size() == m_aStyleTableEntries.size()); + return ret; +} + +void RTFDocumentImpl::resetSprms() +{ + m_aStates.top().getTableSprms().clear(); + m_aStates.top().getCharacterSprms().clear(); + m_aStates.top().getParagraphSprms().clear(); +} + +void RTFDocumentImpl::resetAttributes() +{ + m_aStates.top().getTableAttributes().clear(); + m_aStates.top().getCharacterAttributes().clear(); + m_aStates.top().getParagraphAttributes().clear(); +} + +static bool lcl_containsProperty(const uno::Sequence& rProperties, + const OUString& rName) +{ + return std::any_of(rProperties.begin(), rProperties.end(), + [&](const beans::Property& rProperty) { return rProperty.Name == rName; }); +} + +RTFError RTFDocumentImpl::beforePopState(RTFParserState& rState) +{ + switch (rState.getDestination()) + { + case Destination::FONTTABLE: + { + writerfilter::Reference
::Pointer_t const pTable( + new RTFReferenceTable(m_aFontTableEntries)); + Mapper().table(NS_ooxml::LN_FONTTABLE, pTable); + if (m_nDefaultFontIndex >= 0) + { + auto pValue = new RTFValue(m_aFontNames[getFontIndex(m_nDefaultFontIndex)]); + putNestedAttribute(m_aDefaultState.getCharacterSprms(), + NS_ooxml::LN_EG_RPrBase_rFonts, NS_ooxml::LN_CT_Fonts_ascii, + pValue); + } + } + break; + case Destination::STYLESHEET: + { + RTFReferenceTable::Entries_t const pStyleTableDeduplicated(deduplicateStyleTable()); + writerfilter::Reference
::Pointer_t const pTable( + new RTFReferenceTable(pStyleTableDeduplicated)); + Mapper().table(NS_ooxml::LN_STYLESHEET, pTable); + } + break; + case Destination::LISTOVERRIDETABLE: + { + RTFSprms aListTableAttributes; + writerfilter::Reference::Pointer_t pProp + = new RTFReferenceProperties(aListTableAttributes, m_aListTableSprms); + RTFReferenceTable::Entries_t aListTableEntries; + aListTableEntries.insert(std::make_pair(0, pProp)); + writerfilter::Reference
::Pointer_t const pTable( + new RTFReferenceTable(aListTableEntries)); + Mapper().table(NS_ooxml::LN_NUMBERING, pTable); + } + break; + case Destination::LISTENTRY: + for (const auto& rListLevelEntry : rState.getListLevelEntries()) + rState.getTableSprms().set(rListLevelEntry.first, rListLevelEntry.second, + RTFOverwrite::NO_APPEND); + break; + case Destination::FIELDINSTRUCTION: + { + auto pValue = new RTFValue(m_aFormfieldAttributes, m_aFormfieldSprms); + RTFSprms aFFAttributes; + RTFSprms aFFSprms; + aFFSprms.set(NS_ooxml::LN_ffdata, pValue); + if (!m_aStates.top().getCurrentBuffer()) + { + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aFFAttributes, aFFSprms); + Mapper().props(pProperties); + } + else + { + auto pFFValue = new RTFValue(aFFAttributes, aFFSprms); + bufferProperties(*m_aStates.top().getCurrentBuffer(), pFFValue, nullptr); + } + m_aFormfieldAttributes.clear(); + m_aFormfieldSprms.clear(); + singleChar(cFieldSep); + } + break; + case Destination::FIELDRESULT: + singleChar(cFieldEnd); + + if (!m_aPicturePath.isEmpty()) + { + // Read the picture into m_aStates.top().aDestinationText. + pushState(); + dispatchDestination(RTF_PICT); + if (m_aPicturePath.endsWith(".png")) + dispatchFlag(RTF_PNGBLIP); + OUString aFileURL = m_rMediaDescriptor.getUnpackedValueOrDefault( + utl::MediaDescriptor::PROP_URL(), OUString()); + OUString aPictureURL; + try + { + aPictureURL = rtl::Uri::convertRelToAbs(aFileURL, m_aPicturePath); + } + catch (const rtl::MalformedUriException& rException) + { + SAL_WARN("writerfilter.rtf", + "rtl::Uri::convertRelToAbs() failed: " << rException.getMessage()); + } + + if (!aPictureURL.isEmpty()) + { + SvFileStream aStream(aPictureURL, StreamMode::READ); + if (aStream.IsOpen()) + { + OUStringBuffer aBuf; + while (aStream.good()) + { + unsigned char ch = 0; + aStream.ReadUChar(ch); + if (ch < 16) + aBuf.append("0"); + aBuf.append(OUString::number(ch, 16)); + } + m_aStates.top().getDestinationText() = aBuf; + } + } + popState(); + m_aPicturePath.clear(); + } + + break; + case Destination::LEVELTEXT: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aStr = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + + // The first character is the length of the string (the rest should be ignored). + sal_Int32 nLength(aStr.toChar()); + OUString aValue; + if (nLength < aStr.getLength()) + aValue = aStr.copy(1, nLength); + else + aValue = aStr; + auto pValue = new RTFValue(aValue, true); + rState.getTableAttributes().set(NS_ooxml::LN_CT_LevelText_val, pValue); + } + break; + case Destination::LEVELNUMBERS: + { + bool bNestedLevelNumbers = false; + if (m_aStates.size() > 1) + // Current destination is levelnumbers and parent destination is levelnumbers as well. + bNestedLevelNumbers + = m_aStates[m_aStates.size() - 2].getDestination() == Destination::LEVELNUMBERS; + if (!bNestedLevelNumbers && rState.getTableSprms().find(NS_ooxml::LN_CT_Lvl_lvlText)) + { + RTFSprms& rAttributes + = rState.getTableSprms().find(NS_ooxml::LN_CT_Lvl_lvlText)->getAttributes(); + RTFValue::Pointer_t pValue = rAttributes.find(NS_ooxml::LN_CT_LevelText_val); + if (pValue && rState.getLevelNumbersValid()) + { + OUString aOrig = pValue->getString(); + + OUStringBuffer aBuf(aOrig.getLength() * 2); + sal_Int32 nReplaces = 1; + for (int i = 0; i < aOrig.getLength(); i++) + { + if (std::find(rState.getLevelNumbers().begin(), + rState.getLevelNumbers().end(), i + 1) + != rState.getLevelNumbers().end()) + { + aBuf.append('%'); + // '1.1.1' -> '%1.%2.%3', but '1.' (with '2.' prefix omitted) is %2. + aBuf.append(sal_Int32(nReplaces++ + rState.getListLevelNum() + 1 + - rState.getLevelNumbers().size())); + } + else + aBuf.append(aOrig[i]); + } + + pValue->setString(aBuf.makeStringAndClear()); + } + else if (pValue) + // Have a value, but levelnumbers is not valid -> ignore it. + pValue->setString(OUString()); + } + break; + } + case Destination::SHAPEPROPERTYNAME: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + rState.getShape().getProperties().emplace_back( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear(), OUString()); + break; + case Destination::SHAPEPROPERTYVALUE: + if (!rState.getShape().getProperties().empty()) + { + rState.getShape().getProperties().back().second + = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + if (m_aStates.top().getHadShapeText()) + m_pSdrImport->append(rState.getShape().getProperties().back().first, + rState.getShape().getProperties().back().second); + else if (rState.getInShapeGroup() && !rState.getInShape() + && rState.getShape().getProperties().back().first == "rotation") + { + // Rotation should be applied on the groupshape itself, not on each shape. + rState.getShape().getGroupProperties().push_back( + rState.getShape().getProperties().back()); + rState.getShape().getProperties().pop_back(); + } + } + break; + case Destination::PICPROP: + case Destination::SHAPEINSTRUCTION: + if (m_aStates.size() > 1 + && m_aStates[m_aStates.size() - 2].getDestination() + == Destination::SHAPEINSTRUCTION) + { + // Do not resolve shape if shape instruction destination is inside other shape instruction + } + else if (!m_bObject && !rState.getInListpicture() && !rState.getHadShapeText() + && !(rState.getInShapeGroup() && !rState.getInShape())) + { + // Don't trigger a shape import in case we're only leaving the \shpinst of the groupshape itself. + RTFSdrImport::ShapeOrPict eType + = (rState.getDestination() == Destination::SHAPEINSTRUCTION) + ? RTFSdrImport::SHAPE + : RTFSdrImport::PICT; + if (!m_aStates.top().getCurrentBuffer() || eType != RTFSdrImport::SHAPE) + m_pSdrImport->resolve(m_aStates.top().getShape(), true, eType); + else + { + // Shape inside table: buffer the import to have correct anchor position. + // Also buffer the RTFPicture of the state stack as it contains + // the shape size. + auto pPictureValue = new RTFValue(m_aStates.top().getPicture()); + m_aStates.top().getCurrentBuffer()->push_back( + Buf_t(BUFFER_PICTURE, pPictureValue, nullptr)); + auto pValue = new RTFValue(m_aStates.top().getShape()); + + // Buffer wrap type. + for (const auto& rCharacterSprm : m_aStates.top().getCharacterSprms()) + { + if (rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapNone + || rCharacterSprm.first == NS_ooxml::LN_EG_WrapType_wrapTight) + { + m_aStates.top().getShape().getWrapSprm() = rCharacterSprm; + break; + } + } + + m_aStates.top().getCurrentBuffer()->push_back( + Buf_t(BUFFER_RESOLVESHAPE, pValue, nullptr)); + } + } + else if (rState.getInShapeGroup() && !rState.getInShape()) + { + // End of a groupshape, as we're in shapegroup, but not in a real shape. + for (const auto& rGroupProperty : rState.getShape().getGroupProperties()) + m_pSdrImport->appendGroupProperty(rGroupProperty.first, rGroupProperty.second); + rState.getShape().getGroupProperties().clear(); + } + break; + case Destination::BOOKMARKSTART: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aStr = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + int nPos = m_aBookmarks.size(); + m_aBookmarks[aStr] = nPos; + if (!m_aStates.top().getCurrentBuffer()) + Mapper().props(new RTFReferenceProperties(lcl_getBookmarkProperties(nPos, aStr))); + else + bufferProperties(*m_aStates.top().getCurrentBuffer(), + new RTFValue(lcl_getBookmarkProperties(nPos, aStr)), nullptr); + } + break; + case Destination::BOOKMARKEND: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aStr = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + if (!m_aStates.top().getCurrentBuffer()) + Mapper().props(new RTFReferenceProperties( + lcl_getBookmarkProperties(m_aBookmarks[aStr], aStr))); + else + bufferProperties(*m_aStates.top().getCurrentBuffer(), + new RTFValue(lcl_getBookmarkProperties(m_aBookmarks[aStr], aStr)), + nullptr); + } + break; + case Destination::INDEXENTRY: + case Destination::TOCENTRY: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString str(m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + // dmapper expects this as a field, so let's fake something... + OUString const field((Destination::INDEXENTRY == rState.getDestination()) + ? OUStringLiteral("XE") + : OUStringLiteral("TC")); + str = field + " \"" + str.replaceAll("\"", "\\\"") + "\""; + singleChar(cFieldStart); + Mapper().utext(reinterpret_cast(str.getStr()), str.getLength()); + singleChar(cFieldSep); + // no result + singleChar(cFieldEnd); + } + break; + case Destination::FORMFIELDNAME: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + auto pValue + = new RTFValue(m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFData_name, pValue); + } + break; + case Destination::FORMFIELDLIST: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + auto pValue + = new RTFValue(m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFDDList_listEntry, pValue); + } + break; + case Destination::DATAFIELD: + { + if (m_bFormField) + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OString aStr = OUStringToOString( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear(), + rState.getCurrentEncoding()); + // decode hex dump + OStringBuffer aBuf; + int b = 0; + int count = 2; + for (int i = 0; i < aStr.getLength(); ++i) + { + char ch = aStr[i]; + if (ch != 0x0d && ch != 0x0a) + { + b = b << 4; + sal_Int8 parsed = msfilter::rtfutil::AsHex(ch); + if (parsed == -1) + return RTFError::HEX_INVALID; + b += parsed; + count--; + if (!count) + { + aBuf.append(static_cast(b)); + count = 2; + b = 0; + } + } + } + aStr = aBuf.makeStringAndClear(); + + // ignore the first bytes + if (aStr.getLength() > 8) + aStr = aStr.copy(8); + // extract name + sal_Int32 nLength = aStr.toChar(); + if (!aStr.isEmpty()) + aStr = aStr.copy(1); + nLength = std::min(nLength, aStr.getLength()); + OString aName = aStr.copy(0, nLength); + if (aStr.getLength() > nLength) + aStr = aStr.copy(nLength + 1); // zero-terminated string + else + aStr.clear(); + // extract default text + nLength = aStr.toChar(); + if (!aStr.isEmpty()) + aStr = aStr.copy(1); + auto pNValue = new RTFValue(OStringToOUString(aName, rState.getCurrentEncoding())); + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFData_name, pNValue); + if (nLength > 0) + { + OString aDefaultText = aStr.copy(0, std::min(nLength, aStr.getLength())); + auto pDValue = new RTFValue( + OStringToOUString(aDefaultText, rState.getCurrentEncoding())); + m_aFormfieldSprms.set(NS_ooxml::LN_CT_FFTextInput_default, pDValue); + } + + m_bFormField = false; + } + } + break; + case Destination::CREATIONTIME: + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setCreationDate(lcl_getDateTime(rState)); + break; + case Destination::REVISIONTIME: + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setModificationDate(lcl_getDateTime(rState)); + break; + case Destination::PRINTTIME: + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setPrintDate(lcl_getDateTime(rState)); + break; + case Destination::AUTHOR: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setAuthor( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + break; + case Destination::KEYWORDS: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setKeywords(comphelper::string::convertCommaSeparated( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear())); + break; + case Destination::COMMENT: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setGenerator( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + break; + case Destination::SUBJECT: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setSubject( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + break; + case Destination::TITLE: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setTitle( + rState.getCurrentDestinationText()->makeStringAndClear()); + } + break; + + case Destination::DOCCOMM: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + if (m_xDocumentProperties.is()) + m_xDocumentProperties->setDescription( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + break; + case Destination::OPERATOR: + case Destination::COMPANY: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aName = rState.getDestination() == Destination::OPERATOR ? OUString("Operator") + : OUString("Company"); + uno::Any aValue + = uno::makeAny(m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + if (m_xDocumentProperties.is()) + { + uno::Reference xUserDefinedProperties + = m_xDocumentProperties->getUserDefinedProperties(); + uno::Reference xPropertySet(xUserDefinedProperties, + uno::UNO_QUERY); + uno::Reference xPropertySetInfo + = xPropertySet->getPropertySetInfo(); + if (xPropertySetInfo->hasPropertyByName(aName)) + xPropertySet->setPropertyValue(aName, aValue); + else + xUserDefinedProperties->addProperty(aName, beans::PropertyAttribute::REMOVABLE, + aValue); + } + } + break; + case Destination::OBJDATA: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + + RTFError eError = handleEmbeddedObject(); + if (eError != RTFError::OK) + return eError; + } + break; + case Destination::OBJCLASS: + { + auto pValue + = new RTFValue(m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + m_aOLEAttributes.set(NS_ooxml::LN_CT_OLEObject_ProgID, pValue); + break; + } + case Destination::OBJECT: + { + if (!m_bObject) + { + // if the object is in a special container we will use the \result + // element instead of the \objdata + // (see RTF_OBJECT in RTFDocumentImpl::dispatchDestination) + break; + } + + RTFSprms aObjectSprms; + auto pOLEValue = new RTFValue(m_aOLEAttributes); + aObjectSprms.set(NS_ooxml::LN_OLEObject_OLEObject, pOLEValue); + + RTFSprms aObjAttributes; + RTFSprms aObjSprms; + auto pValue = new RTFValue(m_aObjectAttributes, aObjectSprms); + aObjSprms.set(NS_ooxml::LN_object, pValue); + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aObjAttributes, aObjSprms); + uno::Reference xShape; + RTFValue::Pointer_t pShape = m_aObjectAttributes.find(NS_ooxml::LN_shape); + OSL_ASSERT(pShape.get()); + if (pShape) + pShape->getAny() >>= xShape; + if (xShape.is()) + { + Mapper().startShape(xShape); + Mapper().props(pProperties); + Mapper().endShape(); + } + m_aObjectAttributes.clear(); + m_aOLEAttributes.clear(); + m_bObject = false; + } + break; + case Destination::ANNOTATIONDATE: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aStr(OStringToOUString( + DTTM22OString( + m_aStates.top().getCurrentDestinationText()->makeStringAndClear().toInt32()), + rState.getCurrentEncoding())); + auto pValue = new RTFValue(aStr); + RTFSprms aAnnAttributes; + aAnnAttributes.set(NS_ooxml::LN_CT_TrackChange_date, pValue); + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aAnnAttributes); + Mapper().props(pProperties); + } + break; + case Destination::ANNOTATIONAUTHOR: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + m_aAuthor = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + break; + case Destination::ATNID: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + m_aAuthorInitials = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + break; + case Destination::ANNOTATIONREFERENCESTART: + case Destination::ANNOTATIONREFERENCEEND: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aStr = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + auto pValue = new RTFValue(aStr.toInt32()); + RTFSprms aAttributes; + if (rState.getDestination() == Destination::ANNOTATIONREFERENCESTART) + aAttributes.set(NS_ooxml::LN_EG_RangeMarkupElements_commentRangeStart, pValue); + else + aAttributes.set(NS_ooxml::LN_EG_RangeMarkupElements_commentRangeEnd, pValue); + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aAttributes); + if (!m_aStates.top().getCurrentBuffer()) + { + Mapper().props(pProperties); + } + else + { + auto const pValue2 = new RTFValue(aAttributes, RTFSprms()); + bufferProperties(*m_aStates.top().getCurrentBuffer(), pValue2, nullptr); + } + } + break; + case Destination::ANNOTATIONREFERENCE: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aStr = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + RTFSprms aAnnAttributes; + aAnnAttributes.set(NS_ooxml::LN_CT_Markup_id, new RTFValue(aStr.toInt32())); + Mapper().props(new RTFReferenceProperties(aAnnAttributes)); + } + break; + case Destination::FALT: + { + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + OUString aStr(m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + auto pValue = new RTFValue(aStr); + rState.getTableSprms().set(NS_ooxml::LN_CT_Font_altName, pValue); + } + break; + case Destination::DRAWINGOBJECT: + if (m_aStates.top().getDrawingObject().getShape().is()) + { + RTFDrawingObject& rDrawing = m_aStates.top().getDrawingObject(); + const uno::Reference& xShape(rDrawing.getShape()); + const uno::Reference& xPropertySet(rDrawing.getPropertySet()); + + uno::Reference xServiceInfo(xShape, uno::UNO_QUERY); + bool bTextFrame = xServiceInfo->supportsService("com.sun.star.text.TextFrame"); + + // The default is certainly not inline, but then what Word supports is just at-character. + xPropertySet->setPropertyValue( + "AnchorType", uno::makeAny(text::TextContentAnchorType_AT_CHARACTER)); + + if (bTextFrame) + { + xPropertySet->setPropertyValue("HoriOrientPosition", + uno::makeAny(rDrawing.getLeft())); + xPropertySet->setPropertyValue("VertOrientPosition", + uno::makeAny(rDrawing.getTop())); + } + else + { + xShape->setPosition(awt::Point(rDrawing.getLeft(), rDrawing.getTop())); + } + xShape->setSize(awt::Size(rDrawing.getRight(), rDrawing.getBottom())); + + if (rDrawing.getHasLineColor()) + { + uno::Any aLineColor = uno::makeAny(sal_uInt32((rDrawing.getLineColorR() << 16) + + (rDrawing.getLineColorG() << 8) + + rDrawing.getLineColorB())); + uno::Any aLineWidth; + RTFSdrImport::resolveLineColorAndWidth(bTextFrame, xPropertySet, aLineColor, + aLineWidth); + } + if (rDrawing.getHasFillColor()) + xPropertySet->setPropertyValue( + "FillColor", uno::makeAny(sal_uInt32((rDrawing.getFillColorR() << 16) + + (rDrawing.getFillColorG() << 8) + + rDrawing.getFillColorB()))); + else if (!bTextFrame) + // If there is no fill, the Word default is 100% transparency. + xPropertySet->setPropertyValue("FillTransparence", + uno::makeAny(sal_Int32(100))); + + RTFSdrImport::resolveFLine(xPropertySet, rDrawing.getFLine()); + + if (!m_aStates.top().getDrawingObject().getHadShapeText()) + { + Mapper().startShape(xShape); + } + Mapper().endShape(); + } + break; + case Destination::PICT: + // fdo#79319 ignore picture data if it's really a shape + if (!m_pSdrImport->isFakePict()) + { + resolvePict(true, m_pSdrImport->getCurrentShape()); + } + m_bNeedFinalPar = true; + break; + case Destination::SHAPE: + m_bNeedFinalPar = true; + m_bNeedCr = m_bNeedCrOrig; + if (rState.getFrame().inFrame()) + { + // parBreak() modifies m_aStates.top() so we can't apply resetFrame() directly on aState + resetFrame(); + parBreak(); + // Save this state for later use, so we only reset frame status only for the first shape inside a frame. + rState = m_aStates.top(); + m_bNeedPap = true; + } + break; + case Destination::MOMATH: + { + m_aMathBuffer.appendClosingTag(M_TOKEN(oMath)); + + SvGlobalName aGlobalName(SO3_SM_CLASSID); + comphelper::EmbeddedObjectContainer aContainer; + OUString aName; + uno::Reference xObject + = aContainer.CreateEmbeddedObject(aGlobalName.GetByteSequence(), aName); + if (xObject) // rhbz#1766990 starmath might not be available + { + uno::Reference xComponent(xObject->getComponent(), + uno::UNO_SET_THROW); + // gcc4.4 (and 4.3 and possibly older) have a problem with dynamic_cast directly to the target class, + // so help it with an intermediate cast. I'm not sure what exactly the problem is, seems to be unrelated + // to RTLD_GLOBAL, so most probably a gcc bug. + auto& rImport = dynamic_cast( + dynamic_cast(*xComponent)); + rImport.readFormulaOoxml(m_aMathBuffer); + + auto pValue = new RTFValue(xObject); + RTFSprms aMathAttributes; + aMathAttributes.set(NS_ooxml::LN_starmath, pValue); + writerfilter::Reference::Pointer_t pProperties + = new RTFReferenceProperties(aMathAttributes); + Mapper().props(pProperties); + } + + m_aMathBuffer = oox::formulaimport::XmlStreamBuilder(); + } + break; + case Destination::MR: + lcl_DestinationToMath(m_aStates.top().getCurrentDestinationText(), m_aMathBuffer, + m_bMathNor); + break; + case Destination::MF: + m_aMathBuffer.appendClosingTag(M_TOKEN(f)); + break; + case Destination::MFPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(fPr)); + break; + case Destination::MCTRLPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(ctrlPr)); + break; + case Destination::MNUM: + m_aMathBuffer.appendClosingTag(M_TOKEN(num)); + break; + case Destination::MDEN: + m_aMathBuffer.appendClosingTag(M_TOKEN(den)); + break; + case Destination::MACC: + m_aMathBuffer.appendClosingTag(M_TOKEN(acc)); + break; + case Destination::MACCPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(accPr)); + break; + case Destination::MCHR: + case Destination::MPOS: + case Destination::MVERTJC: + case Destination::MSTRIKEH: + case Destination::MDEGHIDE: + case Destination::MBEGCHR: + case Destination::MSEPCHR: + case Destination::MENDCHR: + case Destination::MSUBHIDE: + case Destination::MSUPHIDE: + case Destination::MTYPE: + case Destination::MGROW: + { + sal_Int32 nMathToken = 0; + switch (rState.getDestination()) + { + case Destination::MCHR: + nMathToken = M_TOKEN(chr); + break; + case Destination::MPOS: + nMathToken = M_TOKEN(pos); + break; + case Destination::MVERTJC: + nMathToken = M_TOKEN(vertJc); + break; + case Destination::MSTRIKEH: + nMathToken = M_TOKEN(strikeH); + break; + case Destination::MDEGHIDE: + nMathToken = M_TOKEN(degHide); + break; + case Destination::MBEGCHR: + nMathToken = M_TOKEN(begChr); + break; + case Destination::MSEPCHR: + nMathToken = M_TOKEN(sepChr); + break; + case Destination::MENDCHR: + nMathToken = M_TOKEN(endChr); + break; + case Destination::MSUBHIDE: + nMathToken = M_TOKEN(subHide); + break; + case Destination::MSUPHIDE: + nMathToken = M_TOKEN(supHide); + break; + case Destination::MTYPE: + nMathToken = M_TOKEN(type); + break; + case Destination::MGROW: + nMathToken = M_TOKEN(grow); + break; + default: + break; + } + + oox::formulaimport::XmlStream::AttributeList aAttribs; + aAttribs[M_TOKEN(val)] + = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + m_aMathBuffer.appendOpeningTag(nMathToken, aAttribs); + m_aMathBuffer.appendClosingTag(nMathToken); + } + break; + case Destination::ME: + m_aMathBuffer.appendClosingTag(M_TOKEN(e)); + break; + case Destination::MBAR: + m_aMathBuffer.appendClosingTag(M_TOKEN(bar)); + break; + case Destination::MBARPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(barPr)); + break; + case Destination::MD: + m_aMathBuffer.appendClosingTag(M_TOKEN(d)); + break; + case Destination::MDPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(dPr)); + break; + case Destination::MFUNC: + m_aMathBuffer.appendClosingTag(M_TOKEN(func)); + break; + case Destination::MFUNCPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(funcPr)); + break; + case Destination::MFNAME: + m_aMathBuffer.appendClosingTag(M_TOKEN(fName)); + break; + case Destination::MLIMLOW: + m_aMathBuffer.appendClosingTag(M_TOKEN(limLow)); + break; + case Destination::MLIMLOWPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(limLowPr)); + break; + case Destination::MLIM: + m_aMathBuffer.appendClosingTag(M_TOKEN(lim)); + break; + case Destination::MM: + m_aMathBuffer.appendClosingTag(M_TOKEN(m)); + break; + case Destination::MMPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(mPr)); + break; + case Destination::MMR: + m_aMathBuffer.appendClosingTag(M_TOKEN(mr)); + break; + case Destination::MNARY: + m_aMathBuffer.appendClosingTag(M_TOKEN(nary)); + break; + case Destination::MNARYPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(naryPr)); + break; + case Destination::MSUB: + m_aMathBuffer.appendClosingTag(M_TOKEN(sub)); + break; + case Destination::MSUP: + m_aMathBuffer.appendClosingTag(M_TOKEN(sup)); + break; + case Destination::MLIMUPP: + m_aMathBuffer.appendClosingTag(M_TOKEN(limUpp)); + break; + case Destination::MLIMUPPPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(limUppPr)); + break; + case Destination::MGROUPCHR: + m_aMathBuffer.appendClosingTag(M_TOKEN(groupChr)); + break; + case Destination::MGROUPCHRPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(groupChrPr)); + break; + case Destination::MBORDERBOX: + m_aMathBuffer.appendClosingTag(M_TOKEN(borderBox)); + break; + case Destination::MBORDERBOXPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(borderBoxPr)); + break; + case Destination::MRAD: + m_aMathBuffer.appendClosingTag(M_TOKEN(rad)); + break; + case Destination::MRADPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(radPr)); + break; + case Destination::MDEG: + m_aMathBuffer.appendClosingTag(M_TOKEN(deg)); + break; + case Destination::MSSUB: + m_aMathBuffer.appendClosingTag(M_TOKEN(sSub)); + break; + case Destination::MSSUBPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(sSubPr)); + break; + case Destination::MSSUP: + m_aMathBuffer.appendClosingTag(M_TOKEN(sSup)); + break; + case Destination::MSSUPPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(sSupPr)); + break; + case Destination::MSSUBSUP: + m_aMathBuffer.appendClosingTag(M_TOKEN(sSubSup)); + break; + case Destination::MSSUBSUPPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(sSubSupPr)); + break; + case Destination::MSPRE: + m_aMathBuffer.appendClosingTag(M_TOKEN(sPre)); + break; + case Destination::MSPREPR: + m_aMathBuffer.appendClosingTag(M_TOKEN(sPrePr)); + break; + case Destination::MBOX: + m_aMathBuffer.appendClosingTag(M_TOKEN(box)); + break; + case Destination::MEQARR: + m_aMathBuffer.appendClosingTag(M_TOKEN(eqArr)); + break; + case Destination::SHAPEGROUP: + if (rState.getCreatedShapeGroup()) + m_pSdrImport->popParent(); + break; + case Destination::PROPNAME: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + rState.setPropName(m_aStates.top().getCurrentDestinationText()->makeStringAndClear()); + break; + case Destination::STATICVAL: + if (&m_aStates.top().getDestinationText() + != m_aStates.top().getCurrentDestinationText()) + break; // not for nested group + if (m_xDocumentProperties.is()) + { + // Find out what is the key, value type and value we want to set. + uno::Reference xPropertyContainer + = m_xDocumentProperties->getUserDefinedProperties(); + const OUString& rKey = m_aStates.top().getPropName(); + OUString aStaticVal + = m_aStates.top().getCurrentDestinationText()->makeStringAndClear(); + uno::Any aAny; + if (m_aStates.top().getPropType() == cppu::UnoType::get()) + aAny <<= aStaticVal; + else if (m_aStates.top().getPropType() == cppu::UnoType::get()) + aAny <<= aStaticVal.toInt32(); + else if (m_aStates.top().getPropType() == cppu::UnoType::get()) + aAny <<= aStaticVal.toBoolean(); + else if (m_aStates.top().getPropType() == cppu::UnoType::get()) + aAny <<= getDateTimeFromUserProp(aStaticVal); + else if (m_aStates.top().getPropType() == cppu::UnoType::get()) + aAny <<= aStaticVal.toDouble(); + + xPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aAny); + } + break; + case Destination::USERPROPS: + { + // These are the imported properties. + uno::Reference xDocumentProperties + = m_xDocumentProperties; + + // These are the real document properties. + uno::Reference xDocumentPropertiesSupplier( + m_xDstDoc, uno::UNO_QUERY); + if (xDocumentPropertiesSupplier.is()) + m_xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); + + if (m_xDocumentProperties.is()) + { + if (!m_bIsNewDoc) + { + // Check classification. + if (!SfxClassificationHelper::ShowPasteInfo(SfxClassificationHelper::CheckPaste( + xDocumentProperties, m_xDocumentProperties))) + return RTFError::CLASSIFICATION; + } + + uno::Reference xClipboardPropertyContainer + = xDocumentProperties->getUserDefinedProperties(); + uno::Reference xDocumentPropertyContainer + = m_xDocumentProperties->getUserDefinedProperties(); + uno::Reference xClipboardPropertySet( + xClipboardPropertyContainer, uno::UNO_QUERY); + uno::Reference xDocumentPropertySet(xDocumentPropertyContainer, + uno::UNO_QUERY); + const uno::Sequence aClipboardProperties + = xClipboardPropertySet->getPropertySetInfo()->getProperties(); + uno::Sequence aDocumentProperties + = xDocumentPropertySet->getPropertySetInfo()->getProperties(); + + for (const beans::Property& rProperty : aClipboardProperties) + { + const OUString& rKey = rProperty.Name; + uno::Any aValue = xClipboardPropertySet->getPropertyValue(rKey); + + try + { + if (lcl_containsProperty(aDocumentProperties, rKey)) + { + // When pasting, don't update existing properties. + if (!m_bIsNewDoc) + xDocumentPropertySet->setPropertyValue(rKey, aValue); + } + else + xDocumentPropertyContainer->addProperty( + rKey, beans::PropertyAttribute::REMOVABLE, aValue); + } + catch (const uno::Exception&) + { + TOOLS_WARN_EXCEPTION("writerfilter.rtf", "failed to set property " << rKey); + } + } + } + } + break; + default: + break; + } + + return RTFError::OK; +} + +void RTFDocumentImpl::afterPopState(RTFParserState& rState) +{ + // list table + switch (rState.getDestination()) + { + case Destination::LISTENTRY: + { + auto pValue = new RTFValue(rState.getTableAttributes(), rState.getTableSprms()); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pValue, + RTFOverwrite::NO_APPEND); + m_aListTable[rState.getCurrentListIndex()] = pValue; + m_nListLevel = -1; + m_aInvalidListTableFirstIndents[rState.getCurrentListIndex()] + = m_aInvalidListLevelFirstIndents; + m_aInvalidListLevelFirstIndents.clear(); + } + break; + case Destination::PARAGRAPHNUMBERING: + { + RTFValue::Pointer_t pIdValue + = rState.getTableAttributes().find(NS_ooxml::LN_CT_AbstractNum_nsid); + if (pIdValue && !m_aStates.empty()) + { + // Abstract numbering + RTFSprms aLeveltextAttributes; + OUString aTextValue; + RTFValue::Pointer_t pTextBefore + = rState.getTableAttributes().find(NS_ooxml::LN_CT_LevelText_val); + if (pTextBefore) + aTextValue += pTextBefore->getString(); + aTextValue += "%1"; + RTFValue::Pointer_t pTextAfter + = rState.getTableAttributes().find(NS_ooxml::LN_CT_LevelSuffix_val); + if (pTextAfter) + aTextValue += pTextAfter->getString(); + auto pTextValue = new RTFValue(aTextValue); + aLeveltextAttributes.set(NS_ooxml::LN_CT_LevelText_val, pTextValue); + + RTFSprms aLevelAttributes; + RTFSprms aLevelSprms; + auto pIlvlValue = new RTFValue(0); + aLevelAttributes.set(NS_ooxml::LN_CT_Lvl_ilvl, pIlvlValue); + + RTFValue::Pointer_t pFmtValue + = rState.getTableSprms().find(NS_ooxml::LN_CT_Lvl_numFmt); + if (pFmtValue) + aLevelSprms.set(NS_ooxml::LN_CT_Lvl_numFmt, pFmtValue); + + RTFValue::Pointer_t pStartatValue + = rState.getTableSprms().find(NS_ooxml::LN_CT_Lvl_start); + if (pStartatValue) + aLevelSprms.set(NS_ooxml::LN_CT_Lvl_start, pStartatValue); + + auto pLeveltextValue = new RTFValue(aLeveltextAttributes); + aLevelSprms.set(NS_ooxml::LN_CT_Lvl_lvlText, pLeveltextValue); + RTFValue::Pointer_t pRunProps + = rState.getTableSprms().find(NS_ooxml::LN_CT_Lvl_rPr); + if (pRunProps) + aLevelSprms.set(NS_ooxml::LN_CT_Lvl_rPr, pRunProps); + + RTFSprms aAbstractAttributes; + RTFSprms aAbstractSprms; + aAbstractAttributes.set(NS_ooxml::LN_CT_AbstractNum_abstractNumId, pIdValue); + auto pLevelValue = new RTFValue(aLevelAttributes, aLevelSprms); + aAbstractSprms.set(NS_ooxml::LN_CT_AbstractNum_lvl, pLevelValue, + RTFOverwrite::NO_APPEND); + + RTFSprms aListTableSprms; + auto pAbstractValue = new RTFValue(aAbstractAttributes, aAbstractSprms); + // It's important that Numbering_abstractNum and Numbering_num never overwrites previous values. + aListTableSprms.set(NS_ooxml::LN_CT_Numbering_abstractNum, pAbstractValue, + RTFOverwrite::NO_APPEND); + + // Numbering + RTFSprms aNumberingAttributes; + RTFSprms aNumberingSprms; + aNumberingAttributes.set(NS_ooxml::LN_CT_AbstractNum_nsid, pIdValue); + aNumberingSprms.set(NS_ooxml::LN_CT_Num_abstractNumId, pIdValue); + auto pNumberingValue = new RTFValue(aNumberingAttributes, aNumberingSprms); + aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pNumberingValue, + RTFOverwrite::NO_APPEND); + + // Table + RTFSprms aListTableAttributes; + writerfilter::Reference::Pointer_t pProp + = new RTFReferenceProperties(aListTableAttributes, aListTableSprms); + + RTFReferenceTable::Entries_t aListTableEntries; + aListTableEntries.insert(std::make_pair(0, pProp)); + writerfilter::Reference
::Pointer_t const pTable( + new RTFReferenceTable(aListTableEntries)); + Mapper().table(NS_ooxml::LN_NUMBERING, pTable); + + // Use it + putNestedSprm(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_numPr, + NS_ooxml::LN_CT_NumPr_ilvl, pIlvlValue); + putNestedSprm(m_aStates.top().getParagraphSprms(), NS_ooxml::LN_CT_PPrBase_numPr, + NS_ooxml::LN_CT_NumPr_numId, pIdValue); + } + } + break; + case Destination::PARAGRAPHNUMBERING_TEXTAFTER: + if (!m_aStates.empty()) + { + // FIXME: don't use pDestinationText, points to popped state + auto pValue = new RTFValue(rState.getDestinationText().makeStringAndClear(), true); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_LevelSuffix_val, pValue); + } + break; + case Destination::PARAGRAPHNUMBERING_TEXTBEFORE: + if (!m_aStates.empty()) + { + // FIXME: don't use pDestinationText, points to popped state + auto pValue = new RTFValue(rState.getDestinationText().makeStringAndClear(), true); + m_aStates.top().getTableAttributes().set(NS_ooxml::LN_CT_LevelText_val, pValue); + } + break; + case Destination::LISTNAME: + break; + case Destination::LISTLEVEL: + if (!m_aStates.empty()) + { + auto pInnerValue = new RTFValue(m_aStates.top().getListLevelNum()++); + rState.getTableAttributes().set(NS_ooxml::LN_CT_Lvl_ilvl, pInnerValue); + + auto pValue = new RTFValue(rState.getTableAttributes(), rState.getTableSprms()); + if (m_aStates.top().getDestination() != Destination::LFOLEVEL) + m_aStates.top().getListLevelEntries().set(NS_ooxml::LN_CT_AbstractNum_lvl, + pValue, RTFOverwrite::NO_APPEND); + else + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_NumLvl_lvl, pValue); + } + break; + case Destination::LFOLEVEL: + if (!m_aStates.empty()) + { + auto pInnerValue = new RTFValue(m_aStates.top().getListLevelNum()++); + rState.getTableAttributes().set(NS_ooxml::LN_CT_NumLvl_ilvl, pInnerValue); + + auto pValue = new RTFValue(rState.getTableAttributes(), rState.getTableSprms()); + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Num_lvlOverride, pValue, + RTFOverwrite::NO_APPEND); + } + break; + // list override table + case Destination::LISTOVERRIDEENTRY: + if (!m_aStates.empty()) + { + if (m_aStates.top().getDestination() == Destination::LISTOVERRIDEENTRY) + { + // copy properties upwards so upper popState() inserts it + m_aStates.top().getTableAttributes() = rState.getTableAttributes(); + m_aStates.top().getTableSprms() = rState.getTableSprms(); + } + else + { + auto pValue = new RTFValue(rState.getTableAttributes(), rState.getTableSprms()); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_num, pValue, + RTFOverwrite::NO_APPEND); + m_aListOverrideTable[rState.getCurrentListOverrideIndex()] + = rState.getCurrentListIndex(); + } + } + break; + case Destination::LEVELTEXT: + if (!m_aStates.empty()) + { + auto pValue = new RTFValue(rState.getTableAttributes()); + m_aStates.top().getTableSprms().set(NS_ooxml::LN_CT_Lvl_lvlText, pValue); + } + break; + case Destination::LEVELNUMBERS: + if (!m_aStates.empty()) + { + m_aStates.top().getTableSprms() = rState.getTableSprms(); + if (m_aStates.top().getDestination() == Destination::LEVELNUMBERS + || m_aStates.top().getDestination() == Destination::LISTLEVEL) + // Parent state is level number or list level, current state is + // level numbers: mark parent as invalid as well if necessary. + m_aStates.top().setLevelNumbersValid(rState.getLevelNumbersValid()); + } + break; + case Destination::FIELDINSTRUCTION: + if (!m_aStates.empty()) + m_aStates.top().setFieldStatus(RTFFieldStatus::INSTRUCTION); + break; + case Destination::FIELDRESULT: + if (!m_aStates.empty()) + m_aStates.top().setFieldStatus(RTFFieldStatus::RESULT); + break; + case Destination::FIELD: + if (rState.getFieldStatus() == RTFFieldStatus::INSTRUCTION) + singleChar(cFieldEnd); + break; + case Destination::SHAPEPROPERTYVALUEPICT: + if (!m_aStates.empty()) + { + m_aStates.top().getPicture() = rState.getPicture(); + // both \sp and \sv are destinations, copy the text up-ward for later + m_aStates.top().getDestinationText() = rState.getDestinationText(); + } + break; + case Destination::FALT: + if (!m_aStates.empty()) + m_aStates.top().getTableSprms() = rState.getTableSprms(); + break; + case Destination::SHAPEPROPERTYNAME: + case Destination::SHAPEPROPERTYVALUE: + case Destination::SHAPEPROPERTY: + if (!m_aStates.empty()) + { + m_aStates.top().getShape() = rState.getShape(); + m_aStates.top().getPicture() = rState.getPicture(); + m_aStates.top().getCharacterAttributes() = rState.getCharacterAttributes(); + } + break; + case Destination::SHAPEINSTRUCTION: + if (!m_aStates.empty() + && m_aStates.top().getDestination() == Destination::SHAPEINSTRUCTION) + { + // Shape instruction inside other shape instruction: just copy new shape settings: + // it will be resolved on end of topmost shape instruction destination + m_aStates.top().getShape() = rState.getShape(); + m_aStates.top().getPicture() = rState.getPicture(); + m_aStates.top().getCharacterSprms() = rState.getCharacterSprms(); + m_aStates.top().getCharacterAttributes() = rState.getCharacterAttributes(); + } + break; + case Destination::FLYMAINCONTENT: + case Destination::SHPPICT: + case Destination::SHAPE: + if (!m_aStates.empty()) + { + m_aStates.top().getFrame() = rState.getFrame(); + if (rState.getDestination() == Destination::SHPPICT + && m_aStates.top().getDestination() == Destination::LISTPICTURE) + { + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_NumPicBullet_numPicBulletId, + new RTFValue(m_nListPictureId++)); + RTFSprms aSprms; + // Dummy value, real picture is already sent to dmapper. + aSprms.set(NS_ooxml::LN_CT_NumPicBullet_pict, new RTFValue(0)); + auto pValue = new RTFValue(aAttributes, aSprms); + m_aListTableSprms.set(NS_ooxml::LN_CT_Numbering_numPicBullet, pValue, + RTFOverwrite::NO_APPEND); + } + } + break; + case Destination::SHAPETEXT: + if (!m_aStates.empty()) + { + // If we're leaving the shapetext group (it may have nested ones) and this is a shape, not an old drawingobject. + if (m_aStates.top().getDestination() != Destination::SHAPETEXT + && !m_aStates.top().getDrawingObject().getHadShapeText()) + { + m_aStates.top().setHadShapeText(true); + if (!m_aStates.top().getCurrentBuffer()) + m_pSdrImport->close(); + else + m_aStates.top().getCurrentBuffer()->push_back( + Buf_t(BUFFER_ENDSHAPE, nullptr, nullptr)); + } + + // It's allowed to declare these inside the shape text, and they + // are expected to have an effect for the whole shape. + if (rState.getDrawingObject().getLeft()) + m_aStates.top().getDrawingObject().setLeft(rState.getDrawingObject().getLeft()); + if (rState.getDrawingObject().getTop()) + m_aStates.top().getDrawingObject().setTop(rState.getDrawingObject().getTop()); + if (rState.getDrawingObject().getRight()) + m_aStates.top().getDrawingObject().setRight( + rState.getDrawingObject().getRight()); + if (rState.getDrawingObject().getBottom()) + m_aStates.top().getDrawingObject().setBottom( + rState.getDrawingObject().getBottom()); + } + break; + case Destination::PROPNAME: + if (m_aStates.top().getDestination() == Destination::USERPROPS) + m_aStates.top().setPropName(rState.getPropName()); + break; + default: + { + if (!m_aStates.empty() && m_aStates.top().getDestination() == Destination::PICT) + m_aStates.top().getPicture() = rState.getPicture(); + } + break; + } +} + +RTFError RTFDocumentImpl::popState() +{ + //SAL_INFO("writerfilter", OSL_THIS_FUNC << " before pop: m_pTokenizer->getGroup() " << m_pTokenizer->getGroup() << + // ", dest state: " << m_aStates.top().eDestination); + + checkUnicode(/*bUnicode =*/true, /*bHex =*/true); + RTFParserState aState(m_aStates.top()); + m_bWasInFrame = aState.getFrame().inFrame(); + + // dmapper expects some content in header/footer, so if there would be nothing, add an empty paragraph. + if (m_pTokenizer->getGroup() == 1 && m_bFirstRun) + { + switch (m_nStreamType) + { + case NS_ooxml::LN_headerl: + case NS_ooxml::LN_headerr: + case NS_ooxml::LN_headerf: + case NS_ooxml::LN_footerl: + case NS_ooxml::LN_footerr: + case NS_ooxml::LN_footerf: + dispatchSymbol(RTF_PAR); + break; + } + } + + RTFError eError = beforePopState(aState); + if (eError != RTFError::OK) + return eError; + + // See if we need to end a track change + if (aState.getStartedTrackchange()) + { + RTFSprms aTCSprms; + auto pValue = new RTFValue(0); + aTCSprms.set(NS_ooxml::LN_endtrackchange, pValue); + if (!m_aStates.top().getCurrentBuffer()) + Mapper().props(new RTFReferenceProperties(RTFSprms(), aTCSprms)); + else + bufferProperties(*m_aStates.top().getCurrentBuffer(), + new RTFValue(RTFSprms(), aTCSprms), nullptr); + } + + // This is the end of the doc, see if we need to close the last section. + if (m_pTokenizer->getGroup() == 1 && !m_bFirstRun) + { + // \par means an empty paragraph at the end of footnotes/endnotes, but + // not in case of other substreams, like headers. + if (m_bNeedCr + && !(m_nStreamType == NS_ooxml::LN_footnote || m_nStreamType == NS_ooxml::LN_endnote) + && m_bIsNewDoc) + dispatchSymbol(RTF_PAR); + if (m_bNeedSect) // may be set by dispatchSymbol above! + sectBreak(true); + } + + m_aStates.pop(); + + m_pTokenizer->popGroup(); + + afterPopState(aState); + + if (aState.getCurrentBuffer() == &m_aSuperBuffer) + { + OSL_ASSERT(!m_aStates.empty() && m_aStates.top().getCurrentBuffer() == nullptr); + + if (!m_aSuperBuffer.empty()) + replayBuffer(m_aSuperBuffer, nullptr, nullptr); + } + + if (!m_aStates.empty() && m_aStates.top().getTableRowWidthAfter() > 0 + && aState.getTableRowWidthAfter() == 0) + // An RTF_ROW in the inner group already parsed nTableRowWidthAfter, + // don't do it again in the outer state later. + m_aStates.top().setTableRowWidthAfter(0); + + if (m_nResetBreakOnSectBreak != RTF_invalid && !m_aStates.empty()) + { + // Section break type created for \page still has an effect in the + // outer state as well. + RTFValue::Pointer_t pType + = aState.getSectionSprms().find(NS_ooxml::LN_EG_SectPrContents_type); + if (pType) + m_aStates.top().getSectionSprms().set(NS_ooxml::LN_EG_SectPrContents_type, pType); + } + + return RTFError::OK; +} + +RTFError RTFDocumentImpl::handleEmbeddedObject() +{ + OString aStr + = OUStringToOString(m_aStates.top().getCurrentDestinationText()->makeStringAndClear(), + RTL_TEXTENCODING_ASCII_US); + std::unique_ptr pStream(new SvMemoryStream()); + if (!msfilter::rtfutil::ExtractOLE2FromObjdata(aStr, *pStream)) + return RTFError::HEX_INVALID; + + uno::Reference xInputStream( + new utl::OSeekableInputStreamWrapper(pStream.release(), /*_bOwner=*/true)); + auto pStreamValue = new RTFValue(xInputStream); + m_aOLEAttributes.set(NS_ooxml::LN_inputstream, pStreamValue); + + return RTFError::OK; +} + +bool RTFDocumentImpl::isInBackground() { return m_aStates.top().getInBackground(); } + +RTFInternalState RTFDocumentImpl::getInternalState() { return m_aStates.top().getInternalState(); } + +void RTFDocumentImpl::setInternalState(RTFInternalState nInternalState) +{ + m_aStates.top().setInternalState(nInternalState); +} + +Destination RTFDocumentImpl::getDestination() { return m_aStates.top().getDestination(); } + +void RTFDocumentImpl::setDestination(Destination eDestination) +{ + m_aStates.top().setDestination(eDestination); +} + +// this is a questionably named method that is used only in a very special +// situation where it looks like the "current" buffer is needed? +void RTFDocumentImpl::setDestinationText(OUString const& rString) +{ + m_aStates.top().getDestinationText().setLength(0); + m_aStates.top().getDestinationText().append(rString); +} + +bool RTFDocumentImpl::getSkipUnknown() { return m_bSkipUnknown; } + +void RTFDocumentImpl::setSkipUnknown(bool bSkipUnknown) { m_bSkipUnknown = bSkipUnknown; } + +static auto FilterControlChars(Destination const destination, OUString const& rString) -> OUString +{ + if (destination == Destination::LEVELNUMBERS || destination == Destination::LEVELTEXT) + { // control characters are magic here! + return rString; + } + OUStringBuffer buf(rString.getLength()); + for (sal_Int32 i = 0; i < rString.getLength(); ++i) + { + sal_Unicode const ch(rString[i]); + if (!linguistic::IsControlChar(ch) || ch == '\r' || ch == '\n' || ch == '\t') + { + buf.append(ch); + } + else + { + SAL_INFO("writerfilter.rtf", "filtering control character"); + } + } + return buf.makeStringAndClear(); +} + +void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex) +{ + if (bUnicode && !m_aUnicodeBuffer.isEmpty()) + { + OUString aString = m_aUnicodeBuffer.toString(); + m_aUnicodeBuffer.setLength(0); + aString = FilterControlChars(m_aStates.top().getDestination(), aString); + text(aString); + } + if (bHex && !m_aHexBuffer.isEmpty()) + { + rtl_TextEncoding nEncoding = m_aStates.top().getCurrentEncoding(); + if (m_aStates.top().getDestination() == Destination::FONTENTRY + && m_aStates.top().getCurrentEncoding() == RTL_TEXTENCODING_SYMBOL) + nEncoding = RTL_TEXTENCODING_MS_1252; + OUString aString = OStringToOUString(m_aHexBuffer.toString(), nEncoding); + m_aHexBuffer.setLength(0); + aString = FilterControlChars(m_aStates.top().getDestination(), aString); + text(aString); + } +} + +RTFParserState::RTFParserState(RTFDocumentImpl* pDocumentImpl) + : m_pDocumentImpl(pDocumentImpl) + , m_nInternalState(RTFInternalState::NORMAL) + , m_eDestination(Destination::NORMAL) + , m_eFieldStatus(RTFFieldStatus::NONE) + , m_nBorderState(RTFBorderState::NONE) + , m_nCurrentEncoding(rtl_getTextEncodingFromWindowsCharset(0)) + , m_nUc(1) + , m_nCharsToSkip(0) + , m_nBinaryToRead(0) + , m_nListLevelNum(0) + , m_bLevelNumbersValid(true) + , m_aFrame(this) + , m_eRunType(RunType::NONE) + , m_nYear(0) + , m_nMonth(0) + , m_nDay(0) + , m_nHour(0) + , m_nMinute(0) + , m_pCurrentDestinationText(nullptr) + , m_nCurrentStyleIndex(-1) + , m_nCurrentCharacterStyleIndex(-1) + , m_pCurrentBuffer(nullptr) + , m_bInListpicture(false) + , m_bInBackground(false) + , m_bHadShapeText(false) + , m_bInShapeGroup(false) + , m_bInShape(false) + , m_bCreatedShapeGroup(false) + , m_bStartedTrackchange(false) + , m_nTableRowWidthAfter(0) +{ +} + +void RTFDocumentImpl::resetFrame() { m_aStates.top().getFrame() = RTFFrame(&m_aStates.top()); } + +void RTFDocumentImpl::bufferProperties(RTFBuffer_t& rBuffer, const RTFValue::Pointer_t& pValue, + const tools::SvRef& pTableProperties) +{ + rBuffer.emplace_back( + Buf_t(BUFFER_SETSTYLE, new RTFValue(m_aStates.top().getCurrentStyleIndex()), nullptr)); + rBuffer.emplace_back(Buf_t(BUFFER_PROPS, pValue, pTableProperties)); +} + +RTFShape::RTFShape() = default; + +RTFDrawingObject::RTFDrawingObject() = default; + +RTFFrame::RTFFrame(RTFParserState* pParserState) + : m_pDocumentImpl(pParserState->getDocumentImpl()) + , m_nX(0) + , m_nY(0) + , m_nW(0) + , m_nH(0) + , m_nHoriPadding(0) + , m_nVertPadding(0) + , m_nHoriAlign(0) + , m_nHoriAnchor(0) + , m_nVertAlign(0) + , m_nVertAnchor(0) + , m_nHRule(NS_ooxml::LN_Value_doc_ST_HeightRule_auto) +{ +} + +void RTFFrame::setSprm(Id nId, Id nValue) +{ + if (m_pDocumentImpl->getFirstRun() && !m_pDocumentImpl->isStyleSheetImport()) + { + m_pDocumentImpl->checkFirstRun(); + m_pDocumentImpl->setNeedPar(false); + } + switch (nId) + { + case NS_ooxml::LN_CT_FramePr_w: + m_nW = nValue; + break; + case NS_ooxml::LN_CT_FramePr_h: + m_nH = nValue; + break; + case NS_ooxml::LN_CT_FramePr_x: + m_nX = nValue; + break; + case NS_ooxml::LN_CT_FramePr_y: + m_nY = nValue; + break; + case NS_ooxml::LN_CT_FramePr_hSpace: + m_nHoriPadding = nValue; + break; + case NS_ooxml::LN_CT_FramePr_vSpace: + m_nVertPadding = nValue; + break; + case NS_ooxml::LN_CT_FramePr_xAlign: + m_nHoriAlign = nValue; + break; + case NS_ooxml::LN_CT_FramePr_hAnchor: + m_nHoriAnchor = nValue; + break; + case NS_ooxml::LN_CT_FramePr_yAlign: + m_nVertAlign = nValue; + break; + case NS_ooxml::LN_CT_FramePr_vAnchor: + m_nVertAnchor = nValue; + break; + case NS_ooxml::LN_CT_FramePr_wrap: + m_oWrap = nValue; + break; + default: + break; + } +} + +RTFSprms RTFFrame::getSprms() +{ + RTFSprms sprms; + + static const Id pNames[] + = { NS_ooxml::LN_CT_FramePr_x, NS_ooxml::LN_CT_FramePr_y, + NS_ooxml::LN_CT_FramePr_hRule, // Make sure nHRule is processed before nH + NS_ooxml::LN_CT_FramePr_h, NS_ooxml::LN_CT_FramePr_w, + NS_ooxml::LN_CT_FramePr_hSpace, NS_ooxml::LN_CT_FramePr_vSpace, + NS_ooxml::LN_CT_FramePr_hAnchor, NS_ooxml::LN_CT_FramePr_vAnchor, + NS_ooxml::LN_CT_FramePr_xAlign, NS_ooxml::LN_CT_FramePr_yAlign, + NS_ooxml::LN_CT_FramePr_wrap, NS_ooxml::LN_CT_FramePr_dropCap, + NS_ooxml::LN_CT_FramePr_lines }; + + for (Id nId : pNames) + { + RTFValue::Pointer_t pValue; + + switch (nId) + { + case NS_ooxml::LN_CT_FramePr_x: + if (m_nX != 0) + pValue = new RTFValue(m_nX); + break; + case NS_ooxml::LN_CT_FramePr_y: + if (m_nY != 0) + pValue = new RTFValue(m_nY); + break; + case NS_ooxml::LN_CT_FramePr_h: + if (m_nH != 0) + { + if (m_nHRule == NS_ooxml::LN_Value_doc_ST_HeightRule_exact) + pValue = new RTFValue(-m_nH); // The negative value just sets nHRule + else + pValue = new RTFValue(m_nH); + } + break; + case NS_ooxml::LN_CT_FramePr_w: + if (m_nW != 0) + pValue = new RTFValue(m_nW); + break; + case NS_ooxml::LN_CT_FramePr_hSpace: + if (m_nHoriPadding != 0) + pValue = new RTFValue(m_nHoriPadding); + break; + case NS_ooxml::LN_CT_FramePr_vSpace: + if (m_nVertPadding != 0) + pValue = new RTFValue(m_nVertPadding); + break; + case NS_ooxml::LN_CT_FramePr_hAnchor: + { + if (m_nHoriAnchor == 0) + m_nHoriAnchor = NS_ooxml::LN_Value_doc_ST_HAnchor_margin; + pValue = new RTFValue(m_nHoriAnchor); + } + break; + case NS_ooxml::LN_CT_FramePr_vAnchor: + { + if (m_nVertAnchor == 0) + m_nVertAnchor = NS_ooxml::LN_Value_doc_ST_VAnchor_margin; + pValue = new RTFValue(m_nVertAnchor); + } + break; + case NS_ooxml::LN_CT_FramePr_xAlign: + pValue = new RTFValue(m_nHoriAlign); + break; + case NS_ooxml::LN_CT_FramePr_yAlign: + pValue = new RTFValue(m_nVertAlign); + break; + case NS_ooxml::LN_CT_FramePr_hRule: + { + if (m_nH < 0) + m_nHRule = NS_ooxml::LN_Value_doc_ST_HeightRule_exact; + else if (m_nH > 0) + m_nHRule = NS_ooxml::LN_Value_doc_ST_HeightRule_atLeast; + pValue = new RTFValue(m_nHRule); + } + break; + case NS_ooxml::LN_CT_FramePr_wrap: + if (m_oWrap) + pValue = new RTFValue(*m_oWrap); + break; + default: + break; + } + + if (pValue) + sprms.set(nId, pValue); + } + + RTFSprms frameprSprms; + frameprSprms.set(NS_ooxml::LN_CT_PPrBase_framePr, new RTFValue(sprms)); + return frameprSprms; +} + +bool RTFFrame::hasProperties() const +{ + return m_nX != 0 || m_nY != 0 || m_nW != 0 || m_nH != 0 || m_nHoriPadding != 0 + || m_nVertPadding != 0 || m_nHoriAlign != 0 || m_nHoriAnchor != 0 || m_nVertAlign != 0 + || m_nVertAnchor != 0; +} + +} // namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx new file mode 100644 index 000000000..64bd15d76 --- /dev/null +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -0,0 +1,988 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFDOCUMENTIMPL_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFDOCUMENTIMPL_HXX + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include "rtfreferencetable.hxx" +#include "rtfsprm.hxx" +#include "rtflistener.hxx" + +class SvStream; +namespace oox +{ +class GraphicHelper; +} +namespace com +{ +namespace sun +{ +namespace star +{ +namespace beans +{ +class XPropertySet; +} +namespace document +{ +class XDocumentProperties; +} +namespace lang +{ +class XMultiServiceFactory; +} +} +} +} + +namespace writerfilter +{ +namespace rtftok +{ +class RTFParserState; +class RTFDocumentImpl; +class RTFTokenizer; +class RTFSdrImport; +class TableRowBuffer; + +enum class RTFBorderState +{ + NONE, + PARAGRAPH, + PARAGRAPH_BOX, + CELL, + PAGE, + CHARACTER +}; + +/// Different kind of buffers for table cell contents. +enum RTFBufferTypes +{ + BUFFER_SETSTYLE, + /// Stores properties, should be created only in bufferProperties(). + BUFFER_PROPS, + BUFFER_NESTROW, + BUFFER_CELLEND, + BUFFER_STARTRUN, + BUFFER_TEXT, + BUFFER_UTEXT, + BUFFER_ENDRUN, + BUFFER_PAR, + BUFFER_STARTSHAPE, + /// Imports a shape. + BUFFER_RESOLVESHAPE, + BUFFER_ENDSHAPE, + BUFFER_RESOLVESUBSTREAM, + /// Restores RTFParserState::aPicture. + BUFFER_PICTURE +}; + +/// Form field types +enum class RTFFormFieldType +{ + NONE, + TEXT, + CHECKBOX, + LIST +}; + +enum class RTFBmpStyle +{ + NONE, + PNG, + JPEG, + DIBITMAP +}; + +enum class RTFFieldStatus +{ + NONE, + INSTRUCTION, + RESULT +}; + +/// A buffer storing dmapper calls. +using Buf_t = std::tuple>; +using RTFBuffer_t = std::deque; + +/// holds one nested table row +class TableRowBuffer : public virtual SvRefBase +{ + RTFBuffer_t m_aBuffer; + ::std::deque m_aCellsSprms; + ::std::deque m_aCellsAttributes; + int m_nCells; + writerfilter::Reference::Pointer_t m_pParaProperties; + writerfilter::Reference::Pointer_t m_pFrameProperties; + writerfilter::Reference::Pointer_t m_pRowProperties; + +public: + TableRowBuffer(RTFBuffer_t aBuffer, std::deque aSprms, + std::deque aAttributes, int const nCells) + : m_aBuffer(std::move(aBuffer)) + , m_aCellsSprms(std::move(aSprms)) + , m_aCellsAttributes(std::move(aAttributes)) + , m_nCells(nCells) + { + } + + RTFBuffer_t& GetBuffer() { return m_aBuffer; } + std::deque& GetCellsSprms() { return m_aCellsSprms; } + std::deque& GetCellsAttributes() { return m_aCellsAttributes; } + int GetCells() const { return m_nCells; } + writerfilter::Reference::Pointer_t& GetParaProperties() + { + return m_pParaProperties; + } + writerfilter::Reference::Pointer_t& GetFrameProperties() + { + return m_pFrameProperties; + } + writerfilter::Reference::Pointer_t& GetRowProperties() { return m_pRowProperties; } +}; + +/// An entry in the color table. +class RTFColorTableEntry +{ +public: + void SetRed(sal_uInt8 nRed) + { + m_bAuto = false; + m_nR = nRed; + } + void SetGreen(sal_uInt8 nGreen) + { + m_bAuto = false; + m_nG = nGreen; + } + void SetBlue(sal_uInt8 nBlue) + { + m_bAuto = false; + m_nB = nBlue; + } + Color GetColor() const { return m_bAuto ? COL_AUTO : Color(m_nR, m_nG, m_nB); } + +private: + bool m_bAuto = true; + sal_uInt8 m_nR = 0; + sal_uInt8 m_nG = 0; + sal_uInt8 m_nB = 0; +}; + +/// Stores the properties of a shape. +class RTFShape : public virtual SvRefBase +{ +public: + RTFShape(); + + std::vector>& getProperties() { return m_aProperties; } + + const std::vector>& getProperties() const + { + return m_aProperties; + } + + std::vector>& getGroupProperties() { return m_aGroupProperties; } + + void setLeft(sal_Int32 nLeft) { m_nLeft = nLeft; } + + sal_Int32 getLeft() const { return m_nLeft; } + + void setTop(sal_Int32 nTop) { m_nTop = nTop; } + + sal_Int32 getTop() const { return m_nTop; } + + void setRight(sal_Int32 nRight) { m_nRight = nRight; } + + sal_Int32 getRight() const { return m_nRight; } + + void setBottom(sal_Int32 nBottom) { m_nBottom = nBottom; } + + sal_Int32 getBottom() const { return m_nBottom; } + + void setZ(sal_Int32 nZ) { m_oZ = nZ; } + + bool hasZ() const { return bool(m_oZ); } + + sal_Int32 getZ() const { return *m_oZ; } + + void setHoriOrientRelation(sal_Int16 nHoriOrientRelation) + { + m_nHoriOrientRelation = nHoriOrientRelation; + } + + sal_Int16 getHoriOrientRelation() const { return m_nHoriOrientRelation; } + + void setVertOrientRelation(sal_Int16 nVertOrientRelation) + { + m_nVertOrientRelation = nVertOrientRelation; + } + + sal_Int16 getVertOrientRelation() const { return m_nVertOrientRelation; } + + void setHoriOrientRelationToken(sal_uInt32 nHoriOrientRelationToken) + { + m_nHoriOrientRelationToken = nHoriOrientRelationToken; + } + + sal_uInt32 getHoriOrientRelationToken() const { return m_nHoriOrientRelationToken; } + + void setVertOrientRelationToken(sal_uInt32 nVertOrientRelationToken) + { + m_nVertOrientRelationToken = nVertOrientRelationToken; + } + + sal_uInt32 getVertOrientRelationToken() const { return m_nVertOrientRelationToken; } + + void setWrap(css::text::WrapTextMode nWrap) { m_nWrap = nWrap; } + + css::text::WrapTextMode getWrap() const { return m_nWrap; } + + void setInBackground(bool bInBackground) { m_bInBackground = bInBackground; } + + bool getInBackground() const { return m_bInBackground; } + + RTFSprms& getWrapPolygonSprms() { return m_aWrapPolygonSprms; } + + RTFSprms& getAnchorAttributes() { return m_aAnchorAttributes; } + + std::pair& getWrapSprm() { return m_aWrapSprm; } + +private: + std::vector> m_aProperties; ///< Properties of a single shape. + std::vector> + m_aGroupProperties; ///< Properties applied on the groupshape. + sal_Int32 m_nLeft = 0; + sal_Int32 m_nTop = 0; + sal_Int32 m_nRight = 0; + sal_Int32 m_nBottom = 0; + std::optional m_oZ; ///< Z-Order of the shape. + sal_Int16 m_nHoriOrientRelation + = 0; ///< Horizontal text::RelOrientation for drawinglayer shapes. + sal_Int16 m_nVertOrientRelation = 0; ///< Vertical text::RelOrientation for drawinglayer shapes. + sal_uInt32 m_nHoriOrientRelationToken = 0; ///< Horizontal dmapper token for Writer pictures. + sal_uInt32 m_nVertOrientRelationToken = 0; ///< Vertical dmapper token for Writer pictures. + css::text::WrapTextMode m_nWrap = css::text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE; + /// If shape is below text (true) or text is below shape (false). + bool m_bInBackground = false; + /// Wrap polygon, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict(). + RTFSprms m_aWrapPolygonSprms; + /// Anchor attributes like wrap distance, written by RTFSdrImport::resolve(), read by RTFDocumentImpl::resolvePict(). + RTFSprms m_aAnchorAttributes; + /// Wrap type, written by RTFDocumentImpl::popState(), read by RTFDocumentImpl::resolvePict(). + std::pair m_aWrapSprm{ 0, nullptr }; +}; + +/// Stores the properties of a drawing object. +class RTFDrawingObject : public RTFShape +{ +public: + RTFDrawingObject(); + + void setShape(const css::uno::Reference& xShape) { m_xShape = xShape; } + const css::uno::Reference& getShape() const { return m_xShape; } + void setPropertySet(const css::uno::Reference& xPropertySet) + { + m_xPropertySet = xPropertySet; + } + const css::uno::Reference& getPropertySet() const + { + return m_xPropertySet; + } + std::vector& getPendingProperties() { return m_aPendingProperties; } + void setLineColorR(sal_uInt8 nLineColorR) { m_nLineColorR = nLineColorR; } + sal_uInt8 getLineColorR() const { return m_nLineColorR; } + void setLineColorG(sal_uInt8 nLineColorG) { m_nLineColorG = nLineColorG; } + sal_uInt8 getLineColorG() const { return m_nLineColorG; } + void setLineColorB(sal_uInt8 nLineColorB) { m_nLineColorB = nLineColorB; } + sal_uInt8 getLineColorB() const { return m_nLineColorB; } + void setHasLineColor(bool bHasLineColor) { m_bHasLineColor = bHasLineColor; } + bool getHasLineColor() const { return m_bHasLineColor; } + void setFillColorR(sal_uInt8 nFillColorR) { m_nFillColorR = nFillColorR; } + sal_uInt8 getFillColorR() const { return m_nFillColorR; } + void setFillColorG(sal_uInt8 nFillColorG) { m_nFillColorG = nFillColorG; } + sal_uInt8 getFillColorG() const { return m_nFillColorG; } + void setFillColorB(sal_uInt8 nFillColorB) { m_nFillColorB = nFillColorB; } + sal_uInt8 getFillColorB() const { return m_nFillColorB; } + void setHasFillColor(bool bHasFillColor) { m_bHasFillColor = bHasFillColor; } + bool getHasFillColor() const { return m_bHasFillColor; } + void setDhgt(sal_Int32 nDhgt) { m_nDhgt = nDhgt; } + sal_Int32 getDhgt() const { return m_nDhgt; } + void setFLine(sal_Int32 nFLine) { m_nFLine = nFLine; } + sal_Int32 getFLine() const { return m_nFLine; } + void setPolyLineCount(sal_Int32 nPolyLineCount) { m_nPolyLineCount = nPolyLineCount; } + sal_Int32 getPolyLineCount() const { return m_nPolyLineCount; } + std::vector& getPolyLinePoints() { return m_aPolyLinePoints; } + void setHadShapeText(bool bHadShapeText) { m_bHadShapeText = bHadShapeText; } + bool getHadShapeText() const { return m_bHadShapeText; } + +private: + css::uno::Reference m_xShape; + css::uno::Reference m_xPropertySet; + std::vector m_aPendingProperties; + sal_uInt8 m_nLineColorR = 0; + sal_uInt8 m_nLineColorG = 0; + sal_uInt8 m_nLineColorB = 0; + bool m_bHasLineColor = false; + sal_uInt8 m_nFillColorR = 0; + sal_uInt8 m_nFillColorG = 0; + sal_uInt8 m_nFillColorB = 0; + bool m_bHasFillColor = false; + sal_Int32 m_nDhgt = 0; + sal_Int32 m_nFLine = -1; + sal_Int32 m_nPolyLineCount = 0; + std::vector m_aPolyLinePoints; + bool m_bHadShapeText = false; +}; + +/// Stores the properties of a picture. +class RTFPicture : public virtual SvRefBase +{ +public: + sal_Int32 nWidth = 0; + sal_Int32 nHeight = 0; + sal_Int32 nGoalWidth = 0; + sal_Int32 nGoalHeight = 0; + sal_uInt16 nScaleX = 100; + sal_uInt16 nScaleY = 100; + short nCropT = 0; + short nCropB = 0; + short nCropL = 0; + short nCropR = 0; + sal_uInt16 eWMetafile = 0; + RTFBmpStyle eStyle = RTFBmpStyle::NONE; +}; + +/// Stores the properties of a frame +class RTFFrame +{ +private: + RTFDocumentImpl* m_pDocumentImpl; + sal_Int32 m_nX, m_nY, m_nW, m_nH; + sal_Int32 m_nHoriPadding, m_nVertPadding; + sal_Int32 m_nHoriAlign, m_nHoriAnchor, m_nVertAlign, m_nVertAnchor; + Id m_nHRule; + std::optional m_oWrap; + +public: + explicit RTFFrame(RTFParserState* pParserState); + + /// Convert the stored properties to Sprms + RTFSprms getSprms(); + /// Store a property + void setSprm(Id nId, Id nValue); + bool hasProperties() const; + /// If we got tokens indicating we're in a frame. + bool inFrame() const; +}; + +/// State of the parser, which gets saved / restored when changing groups. +class RTFParserState +{ +public: + /// Maps to OOXML's ascii, cs or eastAsia. + enum class RunType + { + NONE, + LOCH, + HICH, + DBCH, + LTRCH_RTLCH_1, + LTRCH_RTLCH_2, + RTLCH_LTRCH_1, + RTLCH_LTRCH_2 + }; + + explicit RTFParserState(RTFDocumentImpl* pDocumentImpl); + + void appendDestinationText(const OUString& rString) + { + if (m_pCurrentDestinationText) + m_pCurrentDestinationText->append(rString); + } + + void setPropName(const OUString& rPropName) { m_aPropName = rPropName; } + OUString const& getPropName() const { return m_aPropName; } + void setPropType(const css::uno::Type& rPropType) { m_aPropType = rPropType; } + css::uno::Type const& getPropType() const { return m_aPropType; } + void setTableRowWidthAfter(int nTableRowWidthAfter) + { + m_nTableRowWidthAfter = nTableRowWidthAfter; + } + int getTableRowWidthAfter() const { return m_nTableRowWidthAfter; } + void setStartedTrackchange(bool bStartedTrackchange) + { + m_bStartedTrackchange = bStartedTrackchange; + } + bool getStartedTrackchange() const { return m_bStartedTrackchange; } + void setCreatedShapeGroup(bool bCreatedShapeGroup) + { + m_bCreatedShapeGroup = bCreatedShapeGroup; + } + bool getCreatedShapeGroup() const { return m_bCreatedShapeGroup; } + void setInShape(bool bInShape) { m_bInShape = bInShape; } + bool getInShape() const { return m_bInShape; } + void setInShapeGroup(bool bInShapeGroup) { m_bInShapeGroup = bInShapeGroup; } + bool getInShapeGroup() const { return m_bInShapeGroup; } + void setHadShapeText(bool bHadShapeText) { m_bHadShapeText = bHadShapeText; } + bool getHadShapeText() const { return m_bHadShapeText; } + void setInBackground(bool bInBackground) { m_bInBackground = bInBackground; } + bool getInBackground() const { return m_bInBackground; } + void setInListpicture(bool bInListpicture) { m_bInListpicture = bInListpicture; } + bool getInListpicture() const { return m_bInListpicture; } + void setCurrentBuffer(RTFBuffer_t* pCurrentBuffer) { m_pCurrentBuffer = pCurrentBuffer; } + RTFBuffer_t* getCurrentBuffer() const { return m_pCurrentBuffer; } + void setCurrentListOverrideIndex(int nCurrentListOverrideIndex) + { + m_nCurrentListOverrideIndex = nCurrentListOverrideIndex; + } + int getCurrentListOverrideIndex() const { return m_nCurrentListOverrideIndex; } + void setCurrentListIndex(int nCurrentListIndex) { m_nCurrentListIndex = nCurrentListIndex; } + int getCurrentListIndex() const { return m_nCurrentListIndex; } + void setCurrentCharacterStyleIndex(int nCurrentCharacterStyleIndex) + { + m_nCurrentCharacterStyleIndex = nCurrentCharacterStyleIndex; + } + int getCurrentCharacterStyleIndex() const { return m_nCurrentCharacterStyleIndex; } + void setCurrentStyleIndex(int nCurrentStyleIndex) { m_nCurrentStyleIndex = nCurrentStyleIndex; } + int getCurrentStyleIndex() const { return m_nCurrentStyleIndex; } + void setCurrentDestinationText(OUStringBuffer* pDestinationText) + { + m_pCurrentDestinationText = pDestinationText; + } + OUStringBuffer* getCurrentDestinationText() const { return m_pCurrentDestinationText; } + OUStringBuffer& getDestinationText() { return m_aDestinationText; } + void setMinute(sal_uInt16 nMinute) { m_nMinute = nMinute; } + sal_uInt16 getMinute() const { return m_nMinute; } + void setHour(sal_uInt16 nHour) { m_nHour = nHour; } + sal_uInt16 getHour() const { return m_nHour; } + void setDay(sal_uInt16 nDay) { m_nDay = nDay; } + sal_uInt16 getDay() const { return m_nDay; } + void setMonth(sal_uInt16 nMonth) { m_nMonth = nMonth; } + sal_uInt16 getMonth() const { return m_nMonth; } + void setYear(sal_uInt16 nYear) { m_nYear = nYear; } + sal_uInt16 getYear() const { return m_nYear; } + void setRunType(RunType eRunType) { m_eRunType = eRunType; } + RunType getRunType() const { return m_eRunType; } + RTFFrame& getFrame() { return m_aFrame; } + RTFDrawingObject& getDrawingObject() { return m_aDrawingObject; } + RTFShape& getShape() { return m_aShape; } + RTFPicture& getPicture() { return m_aPicture; } + void setLevelNumbersValid(bool bLevelNumbersValid) + { + m_bLevelNumbersValid = bLevelNumbersValid; + } + bool getLevelNumbersValid() const { return m_bLevelNumbersValid; } + std::vector& getLevelNumbers() { return m_aLevelNumbers; } + RTFSprms& getListLevelEntries() { return m_aListLevelEntries; } + int& getListLevelNum() { return m_nListLevelNum; } + void setBinaryToRead(int nBinaryToRead) { m_nBinaryToRead = nBinaryToRead; } + int getBinaryToRead() const { return m_nBinaryToRead; } + int& getCharsToSkip() { return m_nCharsToSkip; } + void setUc(int nUc) { m_nUc = nUc; } + int getUc() const { return m_nUc; } + void setCurrentEncoding(rtl_TextEncoding nCurrentEncoding) + { + m_nCurrentEncoding = nCurrentEncoding; + } + rtl_TextEncoding getCurrentEncoding() const { return m_nCurrentEncoding; } + RTFColorTableEntry& getCurrentColor() { return m_aCurrentColor; } + RTFSprms& getTabAttributes() { return m_aTabAttributes; } + RTFSprms& getTableCellAttributes() { return m_aTableCellAttributes; } + RTFSprms& getTableCellSprms() { return m_aTableCellSprms; } + RTFSprms& getTableRowAttributes() { return m_aTableRowAttributes; } + RTFSprms& getTableRowSprms() { return m_aTableRowSprms; } + RTFSprms& getSectionAttributes() { return m_aSectionAttributes; } + RTFSprms& getSectionSprms() { return m_aSectionSprms; } + RTFSprms& getParagraphAttributes() { return m_aParagraphAttributes; } + RTFSprms& getParagraphSprms() { return m_aParagraphSprms; } + RTFSprms& getCharacterAttributes() { return m_aCharacterAttributes; } + RTFSprms& getCharacterSprms() { return m_aCharacterSprms; } + RTFSprms& getTableAttributes() { return m_aTableAttributes; } + RTFSprms& getTableSprms() { return m_aTableSprms; } + void setBorderState(RTFBorderState nBorderState) { m_nBorderState = nBorderState; } + RTFBorderState getBorderState() const { return m_nBorderState; } + void setFieldStatus(RTFFieldStatus eFieldStatus) { m_eFieldStatus = eFieldStatus; } + RTFFieldStatus getFieldStatus() const { return m_eFieldStatus; } + void setDestination(Destination eDestination) { m_eDestination = eDestination; } + Destination getDestination() const { return m_eDestination; } + void setInternalState(RTFInternalState nInternalState) { m_nInternalState = nInternalState; } + RTFInternalState getInternalState() const { return m_nInternalState; } + RTFDocumentImpl* getDocumentImpl() { return m_pDocumentImpl; } + +private: + RTFDocumentImpl* m_pDocumentImpl; + RTFInternalState m_nInternalState; + Destination m_eDestination; + RTFFieldStatus m_eFieldStatus; + RTFBorderState m_nBorderState; + // font table, stylesheet table + RTFSprms m_aTableSprms; + RTFSprms m_aTableAttributes; + // reset by plain + RTFSprms m_aCharacterSprms; + RTFSprms m_aCharacterAttributes; + // reset by pard + RTFSprms m_aParagraphSprms; + RTFSprms m_aParagraphAttributes; + // reset by sectd + RTFSprms m_aSectionSprms; + RTFSprms m_aSectionAttributes; + // reset by trowd + RTFSprms m_aTableRowSprms; + RTFSprms m_aTableRowAttributes; + // reset by cellx + RTFSprms m_aTableCellSprms; + RTFSprms m_aTableCellAttributes; + // reset by tx + RTFSprms m_aTabAttributes; + + RTFColorTableEntry m_aCurrentColor; + + rtl_TextEncoding m_nCurrentEncoding; + + /// Current \uc value. + int m_nUc; + /// Characters to skip, set to nUc by \u. + int m_nCharsToSkip; + /// Characters to read, once in binary mode. + int m_nBinaryToRead; + + /// Next list level index to use when parsing list table. + int m_nListLevelNum; + /// List level entries, which will form a list entry later. + RTFSprms m_aListLevelEntries; + /// List of character positions in leveltext to replace. + std::vector m_aLevelNumbers; + /// If aLevelNumbers should be read at all. + bool m_bLevelNumbersValid; + + RTFPicture m_aPicture; + RTFShape m_aShape; + RTFDrawingObject m_aDrawingObject; + RTFFrame m_aFrame; + + RunType m_eRunType; + + // Info group. + sal_Int16 m_nYear; + sal_uInt16 m_nMonth; + sal_uInt16 m_nDay; + sal_uInt16 m_nHour; + sal_uInt16 m_nMinute; + + /// Text from special destinations. + OUStringBuffer m_aDestinationText{ 512 }; + /// point to the buffer of the current destination + OUStringBuffer* m_pCurrentDestinationText; + + /// Index of the current style. + int m_nCurrentStyleIndex; + /// Index of the current character style. + int m_nCurrentCharacterStyleIndex; + /// Current listid, points to a listtable entry. + int m_nCurrentListIndex = -1; + /// Current ls, points to a listoverridetable entry. + int m_nCurrentListOverrideIndex = -1; + + /// Points to the active buffer, if there is one. + RTFBuffer_t* m_pCurrentBuffer; + + /// If we're inside a \listpicture group. + bool m_bInListpicture; + + /// If we're inside a \background group. + bool m_bInBackground; + + bool m_bHadShapeText; + bool m_bInShapeGroup; ///< If we're inside a \shpgrp group. + bool m_bInShape; ///< If we're inside a \shp group. + bool m_bCreatedShapeGroup; ///< A GroupShape was created and pushed to the parent stack. + bool m_bStartedTrackchange; ///< Track change is started, need to end it before popping. + + /// User-defined property: key name. + OUString m_aPropName; + /// User-defined property: value type. + css::uno::Type m_aPropType; + + /// Width of invisible cell at the end of the row. + int m_nTableRowWidthAfter; +}; + +/// An RTF stack is similar to std::stack, except that it has an operator[]. +struct RTFStack +{ +private: + std::deque m_Impl; + +public: + RTFParserState& top() + { + if (m_Impl.empty()) + throw std::out_of_range("empty rtf state stack"); + return m_Impl.back(); + } + void pop() + { + if (m_Impl.empty()) + throw std::out_of_range("empty rtf state stack"); + return m_Impl.pop_back(); + } + void push(RTFParserState const& rState) { return m_Impl.push_back(rState); } + bool empty() const { return m_Impl.empty(); } + size_t size() const { return m_Impl.size(); } + const RTFParserState& operator[](size_t nIndex) const { return m_Impl[nIndex]; } + RTFParserState& operator[](size_t nIndex) { return m_Impl[nIndex]; } +}; + +void putBorderProperty(RTFStack& aStates, Id nId, const RTFValue::Pointer_t& pValue); +void putNestedSprm(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue, + RTFOverwrite eOverwrite = RTFOverwrite::NO_APPEND); +Id getParagraphBorder(sal_uInt32 nIndex); +void putNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId, const RTFValue::Pointer_t& pValue, + RTFOverwrite eOverwrite = RTFOverwrite::YES, bool bAttribute = true); +bool eraseNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId); + +/// Looks up the nParent then the nested nId attribute in rSprms. +RTFValue::Pointer_t getNestedAttribute(RTFSprms& rSprms, Id nParent, Id nId); + +/// Looks up the nParent then the nested nId sprm in rSprms. +RTFValue::Pointer_t getNestedSprm(RTFSprms& rSprms, Id nParent, Id nId); + +/// Checks if rName is contained at least once in rProperties as a key. +bool findPropertyName(const std::vector& rProperties, + const OUString& rName); +RTFSprms& getLastAttributes(RTFSprms& rSprms, Id nId); +OString DTTM22OString(long nDTTM); + +/// Implementation of the RTFDocument interface. +class RTFDocumentImpl : public RTFDocument, public RTFListener +{ +public: + using Pointer_t = tools::SvRef; + RTFDocumentImpl(css::uno::Reference const& xContext, + css::uno::Reference const& xInputStream, + css::uno::Reference const& xDstDoc, + css::uno::Reference const& xFrame, + css::uno::Reference const& xStatusIndicator, + const utl::MediaDescriptor& rMediaDescriptor); + ~RTFDocumentImpl() override; + + // RTFDocument + void resolve(Stream& rMapper) override; + + // RTFListener + RTFError dispatchDestination(RTFKeyword nKeyword) override; + RTFError dispatchFlag(RTFKeyword nKeyword) override; + RTFError dispatchSymbol(RTFKeyword nKeyword) override; + RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) override; + RTFError dispatchValue(RTFKeyword nKeyword, int nParam) override; + bool dispatchTableSprmValue(RTFKeyword nKeyword, int nParam); + bool dispatchCharacterSprmValue(RTFKeyword nKeyword, int nParam); + bool dispatchCharacterAttributeValue(RTFKeyword nKeyword, int nParam); + bool dispatchParagraphSprmValue(RTFKeyword nKeyword, int nParam); + bool dispatchInfoValue(RTFKeyword nKeyword, int nParam); + bool dispatchFrameValue(RTFKeyword nKeyword, int nParam); + bool dispatchTableValue(RTFKeyword nKeyword, int nParam); + RTFError resolveChars(char ch) override; + RTFError pushState() override; + RTFError beforePopState(RTFParserState& rState); + RTFError popState() override; + void afterPopState(RTFParserState& rState); + Destination getDestination() override; + void setDestination(Destination eDestination) override; + RTFInternalState getInternalState() override; + void setInternalState(RTFInternalState nInternalState) override; + bool getSkipUnknown() override; + void setSkipUnknown(bool bSkipUnknown) override; + void finishSubstream() override; + bool isSubstream() const override; + + Stream& Mapper() { return *m_pMapperStream; } + void setSuperstream(RTFDocumentImpl* pSuperstream); + const css::uno::Reference& getModelFactory() const + { + return m_xModelFactory; + } + bool isInBackground(); + void setDestinationText(OUString const& rString); + /// Resolve a picture: If not inline, then anchored. + void resolvePict(bool bInline, css::uno::Reference const& rShape); + + /// If this is the first run of the document, starts the initial paragraph. + void checkFirstRun(); + /// Send NS_ooxml::LN_settings_settings to dmapper. + void outputSettingsTable(); + /// If the initial paragraph is started. + bool getFirstRun() const { return m_bFirstRun; } + /// If we need to add a dummy paragraph before a section break. + void setNeedPar(bool bNeedPar); + /// Return the dmapper index of an RTF index for fonts. + int getFontIndex(int nIndex); + /// Return the name of the font, based on a dmapper index. + OUString getFontName(int nIndex); + /// Return the style name of an RTF style index. + OUString getStyleName(int nIndex); + /// Return the style type of an RTF style index. + Id getStyleType(int nIndex); + /// Return the encoding associated with a font index. + rtl_TextEncoding getEncoding(int nFontIndex); + /// Get the default parser state. + RTFParserState& getDefaultState(); + oox::GraphicHelper& getGraphicHelper(); + /// Are we inside the stylesheet table? + bool isStyleSheetImport(); + /// Resets m_aStates.top().aFrame. + void resetFrame(); + /// Buffers properties to be sent later. + void bufferProperties(RTFBuffer_t& rBuffer, const RTFValue::Pointer_t& pValue, + const tools::SvRef& pTableProperties); + /// implement non-obvious RTF specific style inheritance + RTFReferenceTable::Entries_t deduplicateStyleTable(); + +private: + SvStream& Strm(); + Color getColorTable(sal_uInt32 nIndex); + writerfilter::Reference::Pointer_t createStyleProperties(); + void resetSprms(); + void resetAttributes(); + void resolveSubstream(std::size_t nPos, Id nId); + void resolveSubstream(std::size_t nPos, Id nId, OUString const& rIgnoreFirst); + + void text(OUString& rString); + // Sends a single character to dmapper, taking care of buffering. + void singleChar(sal_uInt8 nValue, bool bRunProps = false); + // Sends run properties to dmapper, taking care of buffering. + void runProps(); + void runBreak(); + void parBreak(); + void tableBreak(); + writerfilter::Reference::Pointer_t + getProperties(const RTFSprms& rAttributes, RTFSprms const& rSprms, Id nStyleType); + void checkNeedPap(); + void sectBreak(bool bFinal = false); + void prepareProperties(RTFParserState& rState, + writerfilter::Reference::Pointer_t& o_rpParagraphProperties, + writerfilter::Reference::Pointer_t& o_rpFrameProperties, + writerfilter::Reference::Pointer_t& o_rpTableRowProperties, + int nCells, int nCurrentCellX); + /// Send the passed properties to dmapper. + void sendProperties(writerfilter::Reference::Pointer_t const& pParagraphProperties, + writerfilter::Reference::Pointer_t const& pFrameProperties, + writerfilter::Reference::Pointer_t const& pTableRowProperties); + void replayRowBuffer(RTFBuffer_t& rBuffer, ::std::deque& rCellsSrpms, + ::std::deque& rCellsAttributes, int nCells); + void replayBuffer(RTFBuffer_t& rBuffer, RTFSprms* pSprms, RTFSprms const* pAttributes); + /// If we have some unicode or hex characters to send. + void checkUnicode(bool bUnicode, bool bHex); + /// If we need a final section break at the end of the document. + void setNeedSect(bool bNeedSect); + void resetTableRowProperties(); + void backupTableRowProperties(); + void restoreTableRowProperties(); + /// Turns the destination text into an input stream of the current OLE attributes. + RTFError handleEmbeddedObject(); + + css::uno::Reference const& m_xContext; + css::uno::Reference const& m_xInputStream; + css::uno::Reference const& m_xDstDoc; + css::uno::Reference const& m_xFrame; + css::uno::Reference const& m_xStatusIndicator; + css::uno::Reference m_xModelFactory; + css::uno::Reference m_xDocumentProperties; + std::unique_ptr m_pInStream; + Stream* m_pMapperStream; + tools::SvRef m_pSdrImport; + tools::SvRef m_pTokenizer; + RTFStack m_aStates; + /// Read by RTF_PARD. + RTFParserState m_aDefaultState; + bool m_bSkipUnknown; + /// Font index <-> encoding map, *not* part of the parser state + std::map m_aFontEncodings; + /// Font index <-> name map. + std::map m_aFontNames; + /// Maps the non-continuous font indexes to the continuous dmapper indexes. + std::vector m_aFontIndexes; + /// Maps style indexes to style names. + std::map m_aStyleNames; + /// Maps style indexes to style types. + std::map m_aStyleTypes; + /// Color index <-> RGB color value map + std::vector m_aColorTable; + /// to start initial paragraph / section after font/style tables + bool m_bFirstRun; + /// except in the case of tables in initial multicolumn section (global for assertion) + bool m_bFirstRunException; + /// If paragraph properties should be emitted on next run. + bool m_bNeedPap; + /// If we need to emit a CR at the end of substream. + bool m_bNeedCr; + /// Original value of m_bNeedCr -- saved/restored before/after textframes. + bool m_bNeedCrOrig; + bool m_bNeedPar; + /// If set, an empty paragraph will be added at the end of the document. + bool m_bNeedFinalPar; + /// The list table and list override table combined. + RTFSprms m_aListTableSprms; + /// Maps between listoverridetable and listtable indexes. + std::map m_aListOverrideTable; + /// Maps listtable indexes to listtable entries. + std::map m_aListTable; + /// Index of the current list level in a list table entry. + int m_nListLevel = -1; + /// Maps List level indexes to removed values in the current list entry. + std::map m_aInvalidListLevelFirstIndents; + /// Maps list table indexes to levels (and their removed values). + std::map> m_aInvalidListTableFirstIndents; + /// The settings table attributes. + RTFSprms m_aSettingsTableAttributes; + /// The settings table sprms. + RTFSprms m_aSettingsTableSprms; + + std::shared_ptr m_pGraphicHelper; + + /// cell props buffer for nested tables, reset by \nestrow + /// the \nesttableprops is a destination and must follow the + /// nested cells, so it should be sufficient to store the + /// currently active one, no need for a stack of them + int m_nNestedCells; + std::deque m_aNestedTableCellsSprms; + std::deque m_aNestedTableCellsAttributes; + /// cell props buffer for top-level table, reset by \row + int m_nTopLevelCells; + std::deque m_aTopLevelTableCellsSprms; + std::deque m_aTopLevelTableCellsAttributes; + /// backup of top-level props, to support inheriting cell props + int m_nInheritingCells; + std::deque m_aTableInheritingCellsSprms; + std::deque m_aTableInheritingCellsAttributes; + + // Left row margin (for nested and top-level rows) + int m_nNestedTRLeft; + int m_nTopLevelTRLeft; + + /// Current cellx value (nested table) + int m_nNestedCurrentCellX; + /// Current cellx value (top-level table) + int m_nTopLevelCurrentCellX; + + // Backup of what \trowd clears, to work around invalid input. + RTFSprms m_aBackupTableRowSprms; + RTFSprms m_aBackupTableRowAttributes; + int m_nBackupTopLevelCurrentCellX; + + /// Buffered table cells, till cell definitions are not reached. + /// for nested table, one buffer per table level + std::deque m_aTableBufferStack; + /// Buffered superscript, till footnote is reached (or not). + RTFBuffer_t m_aSuperBuffer; + + /// Superstream of this substream. + RTFDocumentImpl* m_pSuperstream; + /// Type of the stream: header, footer, footnote, etc. + Id m_nStreamType; + std::queue> m_nHeaderFooterPositions; + std::size_t m_nGroupStartPos; + /// Ignore the first occurrence of this text. + OUString m_aIgnoreFirst; + /// Bookmark name <-> index map. + std::map m_aBookmarks; + /// Revision index <-> author map. + std::map m_aAuthors; + /// Annotation author of the next annotation. + OUString m_aAuthor; + /// Initials of author of the next annotation. + OUString m_aAuthorInitials; + + RTFSprms m_aFormfieldSprms; + RTFSprms m_aFormfieldAttributes; + RTFFormFieldType m_nFormFieldType; + + /// OLE attributes are attributes of the ooxml:OLEObject_OLEObject sprm. + RTFSprms m_aOLEAttributes; + RTFSprms m_aObjectAttributes; + /** If we are in an object group and if the we use its + * \objdata element. + * (if we don't use the \objdata we use the \result element)*/ + bool m_bObject; + /// If the data for a picture is a binary one, it's stored here. + std::shared_ptr m_pBinaryData; + + RTFReferenceTable::Entries_t m_aFontTableEntries; + int m_nCurrentFontIndex; + /// Used only during font table parsing till we don't know the font name. + int m_nCurrentEncoding; + /// Raw default font index, use getFont() on it to get a real one. + int m_nDefaultFontIndex; + + RTFReferenceTable::Entries_t m_aStyleTableEntries; + int m_nCurrentStyleIndex; + bool m_bFormField; + /// For the INCLUDEPICTURE field's argument. + OUString m_aPicturePath; + // Unicode characters are collected here so we don't have to send them one by one. + OUStringBuffer m_aUnicodeBuffer{ 512 }; + /// Same for hex characters. + OStringBuffer m_aHexBuffer{ 512 }; + /// Formula import. + oox::formulaimport::XmlStreamBuilder m_aMathBuffer; + /// Normal text property, that is math italic and math spacing are not applied to the current run. + bool m_bMathNor; + /// If the next continuous section break should be ignored. + bool m_bIgnoreNextContSectBreak; + /// clean up a synthetic page break, see RTF_PAGE + /// if inactive value is -1, otherwise the RTF_SKB* to restore + RTFKeyword m_nResetBreakOnSectBreak; + /// If a section break is needed before the end of the doc (false right after a section break). + bool m_bNeedSect; + /// If aFrame.inFrame() was true in the previous state. + bool m_bWasInFrame; + /// A picture was seen in the current paragraph. + bool m_bHadPicture; + /// The document has multiple sections. + bool m_bHadSect; + /// Max width of the rows in the current table. + int m_nCellxMax; + /// ID of the next \listlevel picture. + int m_nListPictureId; + + /// New document means not pasting into an existing one. + bool m_bIsNewDoc; + /// The media descriptor contains e.g. the base URL of the document. + const utl::MediaDescriptor& m_rMediaDescriptor; + + /// Flags for ensuring that only one header and footer is added per section + bool m_hasRHeader; + bool m_hasFHeader; + bool m_hasRFooter; + bool m_hasFFooter; + + /// Are we after a \cell, but before a \row? + bool m_bAfterCellBeforeRow; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFDOCUMENTIMPL_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtffly.hxx b/writerfilter/source/rtftok/rtffly.hxx new file mode 100644 index 000000000..9f94720d0 --- /dev/null +++ b/writerfilter/source/rtftok/rtffly.hxx @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFFLY_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFFLY_HXX + +#include +#include +#include + +#include +#include + +namespace writerfilter +{ +namespace rtftok +{ +/// Stores the vertical orientation properties of an RTF fly frame. +class RTFVertOrient +{ +public: + explicit RTFVertOrient(sal_uInt16 nValue) + : m_nVal(nValue) + { + } + + sal_uInt16 GetOrient() const { return OSL_LONIBBLE(OSL_LOBYTE(m_nVal)); } + + sal_uInt16 GetRelation() const { return OSL_HINIBBLE(OSL_LOBYTE(m_nVal)); } + + sal_Int32 GetAlign() const + { + sal_Int32 nAlign = 0; + switch (GetOrient()) + { + case css::text::VertOrientation::CENTER: + nAlign = NS_ooxml::LN_Value_doc_ST_YAlign_center; + break; + case css::text::VertOrientation::TOP: + nAlign = NS_ooxml::LN_Value_doc_ST_YAlign_top; + break; + case css::text::VertOrientation::BOTTOM: + nAlign = NS_ooxml::LN_Value_doc_ST_YAlign_bottom; + break; + } + + return nAlign; + } + + sal_Int32 GetAnchor() const + { + sal_Int32 nAnchor = 0; + switch (GetRelation()) + { + case css::text::RelOrientation::FRAME: + nAnchor = NS_ooxml::LN_Value_doc_ST_VAnchor_text; + break; + case css::text::RelOrientation::PAGE_FRAME: + nAnchor = NS_ooxml::LN_Value_doc_ST_VAnchor_page; + break; + case css::text::RelOrientation::PAGE_PRINT_AREA: + nAnchor = NS_ooxml::LN_Value_doc_ST_VAnchor_margin; + break; + } + + return nAnchor; + } + +private: + sal_uInt16 m_nVal; +}; + +/// Stores the horizontal orientation properties of an RTF fly frame. +class RTFHoriOrient +{ +public: + explicit RTFHoriOrient(sal_uInt16 nValue) + : m_nVal(nValue) + { + } + + sal_uInt16 GetOrient() const { return OSL_LONIBBLE(OSL_LOBYTE(m_nVal)); } + + sal_uInt16 GetRelation() const { return OSL_LONIBBLE(OSL_HIBYTE(m_nVal)); } + + sal_Int32 GetAlign() const + { + sal_Int32 nAlign = 0; + switch (GetOrient()) + { + case css::text::HoriOrientation::CENTER: + nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_center; + break; + case css::text::HoriOrientation::RIGHT: + nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_right; + break; + case css::text::HoriOrientation::LEFT: + nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_left; + break; + case css::text::HoriOrientation::INSIDE: + nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_inside; + break; + case css::text::HoriOrientation::OUTSIDE: + nAlign = NS_ooxml::LN_Value_doc_ST_XAlign_outside; + break; + } + + return nAlign; + } + + sal_Int32 GetAnchor() const + { + sal_Int32 nAnchor = 0; + switch (GetRelation()) + { + case css::text::RelOrientation::FRAME: + nAnchor = NS_ooxml::LN_Value_doc_ST_HAnchor_text; + break; + case css::text::RelOrientation::PAGE_FRAME: + nAnchor = NS_ooxml::LN_Value_doc_ST_HAnchor_page; + break; + case css::text::RelOrientation::PAGE_PRINT_AREA: + nAnchor = NS_ooxml::LN_Value_doc_ST_HAnchor_margin; + break; + } + + return nAnchor; + } + +private: + sal_uInt16 m_nVal; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFFLY_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtflistener.hxx b/writerfilter/source/rtftok/rtflistener.hxx new file mode 100644 index 000000000..e35c0cccf --- /dev/null +++ b/writerfilter/source/rtftok/rtflistener.hxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFLISTENER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFLISTENER_HXX + +#include "rtfcontrolwords.hxx" + +namespace writerfilter +{ +namespace rtftok +{ +enum class RTFInternalState +{ + NORMAL, + BIN, + HEX +}; + +enum class RTFError +{ + OK, + GROUP_UNDER, + GROUP_OVER, + UNEXPECTED_EOF, + HEX_INVALID, + CHAR_OVER, + CLASSIFICATION +}; + +/** + * RTFTokenizer needs a class implementing this interface. While + * RTFTokenizer separates control words (and their arguments) from + * text, the class implementing this interface is expected to map the + * raw RTF tokens to dmapper tokens. + */ +class RTFListener +{ +public: + virtual ~RTFListener() = default; + // Dispatching of control words and characters. + virtual RTFError dispatchDestination(RTFKeyword nKeyword) = 0; + virtual RTFError dispatchFlag(RTFKeyword nKeyword) = 0; + virtual RTFError dispatchSymbol(RTFKeyword nKeyword) = 0; + virtual RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) = 0; + virtual RTFError dispatchValue(RTFKeyword nKeyword, int nParam) = 0; + virtual RTFError resolveChars(char ch) = 0; + + // State handling. + virtual RTFError pushState() = 0; + virtual RTFError popState() = 0; + + virtual Destination getDestination() = 0; + virtual void setDestination(Destination eDestination) = 0; + virtual RTFInternalState getInternalState() = 0; + virtual void setInternalState(RTFInternalState nInternalState) = 0; + virtual bool getSkipUnknown() = 0; + virtual void setSkipUnknown(bool bSkipUnknown) = 0; + + // Substream handling. + virtual void finishSubstream() = 0; + virtual bool isSubstream() const = 0; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFLISTENER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtflookahead.cxx b/writerfilter/source/rtftok/rtflookahead.cxx new file mode 100644 index 000000000..d3a84683d --- /dev/null +++ b/writerfilter/source/rtftok/rtflookahead.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtflookahead.hxx" +#include +#include +#include "rtftokenizer.hxx" + +namespace com::sun::star::task +{ +class XStatusIndicator; +} + +using namespace com::sun::star; + +namespace writerfilter::rtftok +{ +RTFLookahead::RTFLookahead(SvStream& rStream, sal_uInt64 nGroupStart) + : m_rStream(rStream) + , m_bHasTable(false) + , m_bHasColumns(false) +{ + sal_uInt64 const nPos = m_rStream.Tell(); + m_rStream.Seek(nGroupStart); + uno::Reference xStatusIndicator; + m_pTokenizer = new RTFTokenizer(*this, &m_rStream, xStatusIndicator); + m_pTokenizer->resolveParse(); + m_rStream.Seek(nPos); +} + +RTFLookahead::~RTFLookahead() = default; + +RTFError RTFLookahead::dispatchDestination(RTFKeyword /*nKeyword*/) { return RTFError::OK; } + +RTFError RTFLookahead::dispatchFlag(RTFKeyword nKeyword) +{ + if (nKeyword == RTF_INTBL) + m_bHasTable = true; + return RTFError::OK; +} + +RTFError RTFLookahead::dispatchSymbol(RTFKeyword /*nKeyword*/) { return RTFError::OK; } + +RTFError RTFLookahead::dispatchToggle(RTFKeyword /*nKeyword*/, bool /*bParam*/, int /*nParam*/) +{ + return RTFError::OK; +} + +RTFError RTFLookahead::dispatchValue(RTFKeyword nKeyword, int nParam) +{ + if (nKeyword == RTF_COLS && nParam >= 2) + m_bHasColumns = true; + return RTFError::OK; +} + +RTFError RTFLookahead::resolveChars(char ch) +{ + while (!m_rStream.eof() && (ch != '{' && ch != '}' && ch != '\\')) + m_rStream.ReadChar(ch); + if (!m_rStream.eof()) + m_rStream.SeekRel(-1); + return RTFError::OK; +} + +RTFError RTFLookahead::pushState() +{ + m_pTokenizer->pushGroup(); + return RTFError::OK; +} + +RTFError RTFLookahead::popState() +{ + m_pTokenizer->popGroup(); + return RTFError::OK; +} + +Destination RTFLookahead::getDestination() { return Destination::NORMAL; } + +void RTFLookahead::setDestination(Destination /*eDestination*/) {} + +RTFInternalState RTFLookahead::getInternalState() { return RTFInternalState::NORMAL; } + +void RTFLookahead::setInternalState(RTFInternalState /*nInternalState*/) {} + +bool RTFLookahead::getSkipUnknown() { return false; } + +void RTFLookahead::setSkipUnknown(bool /*bSkipUnknown*/) {} + +void RTFLookahead::finishSubstream() {} + +bool RTFLookahead::isSubstream() const { return false; } + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtflookahead.hxx b/writerfilter/source/rtftok/rtflookahead.hxx new file mode 100644 index 000000000..52a4b3b14 --- /dev/null +++ b/writerfilter/source/rtftok/rtflookahead.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFLOOKAHEAD_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFLOOKAHEAD_HXX + +#include +#include +#include "rtflistener.hxx" + +class SvStream; + +namespace writerfilter +{ +namespace rtftok +{ +class RTFTokenizer; +/** + * This acts like an importer, but used for looking ahead, e.g. to + * determine if the current group contains a table, etc. + */ +class RTFLookahead : public RTFListener +{ +public: + RTFLookahead(SvStream& rStream, sal_uInt64 nGroupStart); + ~RTFLookahead() override; + RTFError dispatchDestination(RTFKeyword nKeyword) override; + RTFError dispatchFlag(RTFKeyword nKeyword) override; + RTFError dispatchSymbol(RTFKeyword nKeyword) override; + RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) override; + RTFError dispatchValue(RTFKeyword nKeyword, int nParam) override; + RTFError resolveChars(char ch) override; + RTFError pushState() override; + RTFError popState() override; + Destination getDestination() override; + void setDestination(Destination eDestination) override; + RTFInternalState getInternalState() override; + void setInternalState(RTFInternalState nInternalState) override; + bool getSkipUnknown() override; + void setSkipUnknown(bool bSkipUnknown) override; + void finishSubstream() override; + bool isSubstream() const override; + bool hasTable() const { return m_bHasTable; } + bool hasColumns() const { return m_bHasColumns; } + +private: + tools::SvRef m_pTokenizer; + SvStream& m_rStream; + bool m_bHasTable; + bool m_bHasColumns; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFLOOKAHEAD_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfreferenceproperties.cxx b/writerfilter/source/rtftok/rtfreferenceproperties.cxx new file mode 100644 index 000000000..d32557bc7 --- /dev/null +++ b/writerfilter/source/rtftok/rtfreferenceproperties.cxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfreferenceproperties.hxx" + +namespace writerfilter::rtftok +{ +RTFReferenceProperties::RTFReferenceProperties(RTFSprms aAttributes, RTFSprms aSprms) + : m_aAttributes(std::move(aAttributes)) + , m_aSprms(std::move(aSprms)) +{ +} + +RTFReferenceProperties::RTFReferenceProperties(RTFSprms aAttributes) + : m_aAttributes(std::move(aAttributes)) +{ +} + +RTFReferenceProperties::~RTFReferenceProperties() = default; + +void RTFReferenceProperties::resolve(Properties& rHandler) +{ + for (auto& rAttribute : m_aAttributes) + rHandler.attribute(rAttribute.first, *rAttribute.second); + for (auto& rSprm : m_aSprms) + { + RTFSprm aSprm(rSprm.first, rSprm.second); + rHandler.sprm(aSprm); + } +} + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfreferenceproperties.hxx b/writerfilter/source/rtftok/rtfreferenceproperties.hxx new file mode 100644 index 000000000..d5121b26a --- /dev/null +++ b/writerfilter/source/rtftok/rtfreferenceproperties.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFREFERENCEPROPERTIES_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFREFERENCEPROPERTIES_HXX + +#include "rtfsprm.hxx" + +namespace writerfilter +{ +namespace rtftok +{ +/// Sends RTFSprm instances to DomainMapper. +class RTFReferenceProperties : public writerfilter::Reference +{ +public: + RTFReferenceProperties(RTFSprms aAttributes, RTFSprms aSprms); + explicit RTFReferenceProperties(RTFSprms aAttributes); + ~RTFReferenceProperties() override; + void resolve(Properties& rHandler) override; + RTFSprms& getAttributes() { return m_aAttributes; } + RTFSprms& getSprms() { return m_aSprms; } + +private: + RTFSprms m_aAttributes; + RTFSprms m_aSprms; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFREFERENCEPROPERTIES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfreferencetable.cxx b/writerfilter/source/rtftok/rtfreferencetable.cxx new file mode 100644 index 000000000..ffa9eddae --- /dev/null +++ b/writerfilter/source/rtftok/rtfreferencetable.cxx @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfreferencetable.hxx" + +namespace writerfilter::rtftok +{ +RTFReferenceTable::RTFReferenceTable(Entries_t aEntries) + : m_aEntries(std::move(aEntries)) +{ +} + +RTFReferenceTable::~RTFReferenceTable() = default; + +void RTFReferenceTable::resolve(Table& rHandler) +{ + for (auto& rEntry : m_aEntries) + rHandler.entry(rEntry.first, rEntry.second); +} + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfreferencetable.hxx b/writerfilter/source/rtftok/rtfreferencetable.hxx new file mode 100644 index 000000000..8c9595493 --- /dev/null +++ b/writerfilter/source/rtftok/rtfreferencetable.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFREFERENCETABLE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFREFERENCETABLE_HXX + +#include +#include + +namespace writerfilter +{ +namespace rtftok +{ +/// Sends tables (e.g. font table) to the domain mapper. +class RTFReferenceTable : public writerfilter::Reference
+{ +public: + using Entries_t = std::map::Pointer_t>; + using Entry_t = std::pair::Pointer_t>; + explicit RTFReferenceTable(Entries_t aEntries); + ~RTFReferenceTable() override; + void resolve(Table& rHandler) override; + +private: + Entries_t m_aEntries; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFREFERENCETABLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx new file mode 100644 index 000000000..ef2c92afa --- /dev/null +++ b/writerfilter/source/rtftok/rtfsdrimport.cxx @@ -0,0 +1,1151 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfsdrimport.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "rtfreferenceproperties.hxx" +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "rtfdocumentimpl.hxx" + +using namespace com::sun::star; + +namespace writerfilter::rtftok +{ +RTFSdrImport::RTFSdrImport(RTFDocumentImpl& rDocument, + uno::Reference const& xDstDoc) + : m_rImport(rDocument) + , m_bTextFrame(false) + , m_bTextGraphicObject(false) + , m_bFakePict(false) +{ + uno::Reference xDrawings(xDstDoc, uno::UNO_QUERY); + if (xDrawings.is()) + m_aParents.push(xDrawings->getDrawPage()); + m_aGraphicZOrderHelpers.push(writerfilter::dmapper::GraphicZOrderHelper()); +} + +RTFSdrImport::~RTFSdrImport() +{ + if (!m_aGraphicZOrderHelpers.empty()) + m_aGraphicZOrderHelpers.pop(); + if (!m_aParents.empty()) + m_aParents.pop(); +} + +void RTFSdrImport::createShape(const OUString& rService, uno::Reference& xShape, + uno::Reference& xPropertySet) +{ + if (m_rImport.getModelFactory().is()) + xShape.set(m_rImport.getModelFactory()->createInstance(rService), uno::UNO_QUERY); + xPropertySet.set(xShape, uno::UNO_QUERY); +} + +std::vector RTFSdrImport::getTextFrameDefaults(bool bNew) +{ + std::vector aRet; + beans::PropertyValue aPropertyValue; + + aPropertyValue.Name = "HoriOrient"; + aPropertyValue.Value <<= text::HoriOrientation::NONE; + aRet.push_back(aPropertyValue); + aPropertyValue.Name = "HoriOrientRelation"; + aPropertyValue.Value <<= text::RelOrientation::FRAME; + aRet.push_back(aPropertyValue); + aPropertyValue.Name = "VertOrient"; + aPropertyValue.Value <<= text::VertOrientation::NONE; + aRet.push_back(aPropertyValue); + aPropertyValue.Name = "VertOrientRelation"; + aPropertyValue.Value <<= text::RelOrientation::FRAME; + aRet.push_back(aPropertyValue); + if (!bNew) + { + aPropertyValue.Name = "BackColorTransparency"; + aPropertyValue.Value <<= sal_Int32(100); + aRet.push_back(aPropertyValue); + } + // See the spec, new-style frame default margins are specified in EMUs. + aPropertyValue.Name = "LeftBorderDistance"; + aPropertyValue.Value <<= sal_Int32(bNew ? (91440 / 360) : 0); + aRet.push_back(aPropertyValue); + aPropertyValue.Name = "RightBorderDistance"; + aPropertyValue.Value <<= sal_Int32(bNew ? (91440 / 360) : 0); + aRet.push_back(aPropertyValue); + aPropertyValue.Name = "TopBorderDistance"; + aPropertyValue.Value <<= sal_Int32(bNew ? (45720 / 360) : 0); + aRet.push_back(aPropertyValue); + aPropertyValue.Name = "BottomBorderDistance"; + aPropertyValue.Value <<= sal_Int32(bNew ? (45720 / 360) : 0); + aRet.push_back(aPropertyValue); + aPropertyValue.Name = "SizeType"; + aPropertyValue.Value <<= text::SizeType::FIX; + aRet.push_back(aPropertyValue); + return aRet; +} + +void RTFSdrImport::pushParent(uno::Reference const& xParent) +{ + m_aParents.push(xParent); + m_aGraphicZOrderHelpers.push(writerfilter::dmapper::GraphicZOrderHelper()); +} + +void RTFSdrImport::popParent() +{ + if (!m_aGraphicZOrderHelpers.empty()) + m_aGraphicZOrderHelpers.pop(); + if (!m_aParents.empty()) + m_aParents.pop(); +} + +void RTFSdrImport::resolveDhgt(uno::Reference const& xPropertySet, + sal_Int32 const nZOrder, bool const bOldStyle) +{ + if (!m_aGraphicZOrderHelpers.empty()) + { + writerfilter::dmapper::GraphicZOrderHelper& rHelper = m_aGraphicZOrderHelpers.top(); + xPropertySet->setPropertyValue("ZOrder", + uno::makeAny(rHelper.findZOrder(nZOrder, bOldStyle))); + rHelper.addItem(xPropertySet, nZOrder); + } +} + +void RTFSdrImport::resolveLineColorAndWidth(bool bTextFrame, + const uno::Reference& xPropertySet, + uno::Any const& rLineColor, uno::Any const& rLineWidth) +{ + if (!bTextFrame) + { + xPropertySet->setPropertyValue("LineColor", rLineColor); + xPropertySet->setPropertyValue("LineWidth", rLineWidth); + } + else + { + static const char* aBorders[] + = { "TopBorder", "LeftBorder", "BottomBorder", "RightBorder" }; + for (const char* pBorder : aBorders) + { + auto aBorderLine = xPropertySet->getPropertyValue(OUString::createFromAscii(pBorder)) + .get(); + if (rLineColor.hasValue()) + aBorderLine.Color = rLineColor.get(); + if (rLineWidth.hasValue()) + aBorderLine.LineWidth = rLineWidth.get(); + xPropertySet->setPropertyValue(OUString::createFromAscii(pBorder), + uno::makeAny(aBorderLine)); + } + } +} + +void RTFSdrImport::resolveFLine(uno::Reference const& xPropertySet, + sal_Int32 const nFLine) +{ + if (nFLine == 0) + xPropertySet->setPropertyValue("LineStyle", uno::makeAny(drawing::LineStyle_NONE)); + else + xPropertySet->setPropertyValue("LineStyle", uno::makeAny(drawing::LineStyle_SOLID)); +} + +void RTFSdrImport::applyProperty(uno::Reference const& xShape, + const OUString& aKey, const OUString& aValue) const +{ + uno::Reference xPropertySet(xShape, uno::UNO_QUERY); + sal_Int16 nHoriOrient = 0; + sal_Int16 nVertOrient = 0; + boost::logic::tribool obFitShapeToText(boost::logic::indeterminate); + bool bFilled = true; + + if (aKey == "posh") + { + switch (aValue.toInt32()) + { + case 1: + nHoriOrient = text::HoriOrientation::LEFT; + break; + case 2: + nHoriOrient = text::HoriOrientation::CENTER; + break; + case 3: + nHoriOrient = text::HoriOrientation::RIGHT; + break; + case 4: + nHoriOrient = text::HoriOrientation::INSIDE; + break; + case 5: + nHoriOrient = text::HoriOrientation::OUTSIDE; + break; + default: + break; + } + } + else if (aKey == "posv") + { + switch (aValue.toInt32()) + { + case 1: + nVertOrient = text::VertOrientation::TOP; + break; + case 2: + nVertOrient = text::VertOrientation::CENTER; + break; + case 3: + nVertOrient = text::VertOrientation::BOTTOM; + break; + default: + break; + } + } + else if (aKey == "fFitShapeToText") + obFitShapeToText = aValue.toInt32() == 1; + else if (aKey == "fFilled") + bFilled = aValue.toInt32() == 1; + else if (aKey == "rotation") + { + // See DffPropertyReader::Fix16ToAngle(): in RTF, positive rotation angles are clockwise, we have them as counter-clockwise. + // Additionally, RTF type is 0..360*2^16, our is 0..360*100. + sal_Int32 nRotation = aValue.toInt32() * 100 / RTF_MULTIPLIER; + uno::Reference xServiceInfo(xShape, uno::UNO_QUERY); + if (!xServiceInfo->supportsService("com.sun.star.text.TextFrame")) + xPropertySet->setPropertyValue( + "RotateAngle", + uno::makeAny(sal_Int32(NormAngle36000(static_cast(nRotation) * -1)))); + } + + if (nHoriOrient != 0 && xPropertySet.is()) + xPropertySet->setPropertyValue("HoriOrient", uno::makeAny(nHoriOrient)); + if (nVertOrient != 0 && xPropertySet.is()) + xPropertySet->setPropertyValue("VertOrient", uno::makeAny(nVertOrient)); + if (!boost::logic::indeterminate(obFitShapeToText) && xPropertySet.is()) + { + xPropertySet->setPropertyValue( + "SizeType", uno::makeAny(obFitShapeToText ? text::SizeType::MIN : text::SizeType::FIX)); + xPropertySet->setPropertyValue("FrameIsAutomaticHeight", + uno::makeAny(static_cast(obFitShapeToText))); + } + if (!bFilled && xPropertySet.is()) + { + if (m_bTextFrame) + xPropertySet->setPropertyValue("BackColorTransparency", uno::makeAny(sal_Int32(100))); + else + xPropertySet->setPropertyValue("FillStyle", uno::makeAny(drawing::FillStyle_NONE)); + } +} + +int RTFSdrImport::initShape(uno::Reference& o_xShape, + uno::Reference& o_xPropSet, bool& o_rIsCustomShape, + RTFShape const& rShape, bool const bClose, + ShapeOrPict const shapeOrPict) +{ + assert(!o_xShape.is()); + assert(!o_xPropSet.is()); + o_rIsCustomShape = false; + m_bFakePict = false; + + // first, find the shape type + int nType = -1; + auto iter = std::find_if(rShape.getProperties().begin(), rShape.getProperties().end(), + [](const std::pair& rProperty) { + return rProperty.first == "shapeType"; + }); + + if (iter == rShape.getProperties().end()) + { + if (SHAPE == shapeOrPict) + { + // The spec doesn't state what is the default for shapeType, + // Word seems to implement it as a rectangle. + nType = ESCHER_ShpInst_Rectangle; + } + else + { + // pict is picture by default but can be a rectangle too fdo#79319 + nType = ESCHER_ShpInst_PictureFrame; + } + } + else + { + nType = iter->second.toInt32(); + if (PICT == shapeOrPict && ESCHER_ShpInst_PictureFrame != nType) + { + m_bFakePict = true; + } + } + + switch (nType) + { + case ESCHER_ShpInst_PictureFrame: + createShape("com.sun.star.drawing.GraphicObjectShape", o_xShape, o_xPropSet); + m_bTextGraphicObject = true; + break; + case ESCHER_ShpInst_Line: + createShape("com.sun.star.drawing.LineShape", o_xShape, o_xPropSet); + break; + case ESCHER_ShpInst_Rectangle: + case ESCHER_ShpInst_TextBox: + // If we're inside a groupshape, can't use text frames. + if (!bClose && m_aParents.size() == 1) + { + createShape("com.sun.star.text.TextFrame", o_xShape, o_xPropSet); + m_bTextFrame = true; + std::vector aDefaults = getTextFrameDefaults(true); + for (const beans::PropertyValue& i : aDefaults) + o_xPropSet->setPropertyValue(i.Name, i.Value); + break; + } + [[fallthrough]]; + default: + createShape("com.sun.star.drawing.CustomShape", o_xShape, o_xPropSet); + o_rIsCustomShape = true; + break; + } + + // Defaults + if (o_xPropSet.is() && !m_bTextFrame) + { + o_xPropSet->setPropertyValue( + "FillColor", + uno::makeAny(sal_uInt32(0xffffff))); // White in Word, kind of blue in Writer. + o_xPropSet->setPropertyValue("VertOrient", uno::makeAny(text::VertOrientation::NONE)); + } + + return nType; +} + +void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, ShapeOrPict const shapeOrPict) +{ + bool bPib = false; + m_bTextFrame = false; + m_bTextGraphicObject = false; + + uno::Reference xShape; + uno::Reference xPropertySet; + uno::Any aAny; + beans::PropertyValue aPropertyValue; + awt::Rectangle aViewBox; + std::vector aPath; + // Default line color is black in Word, blue in Writer. + uno::Any aLineColor = uno::makeAny(COL_BLACK); + // Default line width is 0.75 pt (26 mm100) in Word, 0 in Writer. + uno::Any aLineWidth = uno::makeAny(sal_Int32(26)); + sal_Int16 eWritingMode = text::WritingMode2::LR_TB; + // Groupshape support + std::optional oGroupLeft; + std::optional oGroupTop; + std::optional oGroupRight; + std::optional oGroupBottom; + std::optional oRelLeft; + std::optional oRelTop; + std::optional oRelRight; + std::optional oRelBottom; + + // Importing these are not trivial, let the VML import do the hard work. + oox::vml::FillModel aFillModel; // Gradient. + oox::vml::ShadowModel aShadowModel; // Shadow. + + bool bOpaque = true; + + std::optional oRelativeWidth; + std::optional oRelativeHeight; + sal_Int16 nRelativeWidthRelation = text::RelOrientation::PAGE_FRAME; + sal_Int16 nRelativeHeightRelation = text::RelOrientation::PAGE_FRAME; + boost::logic::tribool obRelFlipV(boost::logic::indeterminate); + boost::logic::tribool obFlipH(boost::logic::indeterminate); + boost::logic::tribool obFlipV(boost::logic::indeterminate); + + OUString aShapeText = ""; + OUString aFontFamily = ""; + float nFontSize = 1.0; + + bool bCustom(false); + int const nType = initShape(xShape, xPropertySet, bCustom, rShape, bClose, shapeOrPict); + + for (auto& rProperty : rShape.getProperties()) + { + if (rProperty.first == "shapeType") + { + continue; // ignore: already handled by initShape + } + if (rProperty.first == "wzName") + { + if (m_bTextFrame) + { + uno::Reference xNamed(xShape, uno::UNO_QUERY); + xNamed->setName(rProperty.second); + } + else + xPropertySet->setPropertyValue("Name", uno::makeAny(rProperty.second)); + } + else if (rProperty.first == "wzDescription") + xPropertySet->setPropertyValue("Description", uno::makeAny(rProperty.second)); + else if (rProperty.first == "gtextUNICODE") + aShapeText = rProperty.second; + else if (rProperty.first == "gtextFont") + aFontFamily = rProperty.second; + else if (rProperty.first == "gtextSize") + { + // RTF size is multiplied by 2^16 + nFontSize = static_cast(rProperty.second.toUInt32()) / RTF_MULTIPLIER; + } + else if (rProperty.first == "pib") + { + m_rImport.setDestinationText(rProperty.second); + bPib = true; + } + else if (rProperty.first == "fillColor" && xPropertySet.is()) + { + aAny <<= msfilter::util::BGRToRGB(rProperty.second.toUInt32()); + if (m_bTextFrame) + xPropertySet->setPropertyValue("BackColor", aAny); + else + xPropertySet->setPropertyValue("FillColor", aAny); + + // fillType will decide, possible it'll be the start color of a gradient. + aFillModel.moColor.set( + "#" + OUString::fromUtf8(msfilter::util::ConvertColor(aAny.get()))); + } + else if (rProperty.first == "fillBackColor") + // fillType will decide, possible it'll be the end color of a gradient. + aFillModel.moColor2.set("#" + + OUString::fromUtf8(msfilter::util::ConvertColor( + msfilter::util::BGRToRGB(rProperty.second.toInt32())))); + else if (rProperty.first == "lineColor") + aLineColor <<= msfilter::util::BGRToRGB(rProperty.second.toInt32()); + else if (rProperty.first == "lineBackColor") + ; // Ignore: complementer of lineColor + else if (rProperty.first == "txflTextFlow" && xPropertySet.is()) + { + switch (rProperty.second.toInt32()) + { + case 1: // Top to bottom ASCII font + case 3: // Top to bottom non-ASCII font + eWritingMode = text::WritingMode2::TB_RL; + break; + case 2: // Bottom to top non-ASCII font + eWritingMode = text::WritingMode2::BT_LR; + break; + } + } + else if (rProperty.first == "fLine" && xPropertySet.is()) + resolveFLine(xPropertySet, rProperty.second.toInt32()); + else if (rProperty.first == "fillOpacity" && xPropertySet.is()) + { + int opacity = 100 - (rProperty.second.toInt32()) * 100 / RTF_MULTIPLIER; + xPropertySet->setPropertyValue("FillTransparence", uno::Any(sal_uInt32(opacity))); + } + else if (rProperty.first == "lineWidth") + aLineWidth <<= rProperty.second.toInt32() / 360; + else if (rProperty.first == "pVerticies") + { + std::vector aCoordinates; + sal_Int32 nSize = 0; // Size of a token (its value is hardwired in the exporter) + sal_Int32 nCount = 0; // Number of tokens + sal_Int32 nCharIndex = 0; // Character index + do + { + OUString aToken = rProperty.second.getToken(0, ';', nCharIndex); + if (!nSize) + nSize = aToken.toInt32(); + else if (!nCount) + nCount = aToken.toInt32(); + else if (aToken.getLength()) + { + // The coordinates are in an (x,y) form. + aToken = aToken.copy(1, aToken.getLength() - 2); + sal_Int32 nI = 0; + sal_Int32 nX = aToken.getToken(0, ',', nI).toInt32(); + sal_Int32 nY = (nI >= 0) ? aToken.getToken(0, ',', nI).toInt32() : 0; + drawing::EnhancedCustomShapeParameterPair aPair; + aPair.First.Value <<= nX; + aPair.Second.Value <<= nY; + aCoordinates.push_back(aPair); + } + } while (nCharIndex >= 0); + aPropertyValue.Name = "Coordinates"; + aPropertyValue.Value <<= comphelper::containerToSequence(aCoordinates); + aPath.push_back(aPropertyValue); + } + else if (rProperty.first == "pSegmentInfo") + { + std::vector aSegments; + sal_Int32 nSize = 0; + sal_Int32 nCount = 0; + sal_Int32 nCharIndex = 0; + do + { + sal_Int32 nSeg = rProperty.second.getToken(0, ';', nCharIndex).toInt32(); + if (!nSize) + nSize = nSeg; + else if (!nCount) + nCount = nSeg; + else + { + sal_Int32 nPoints = 1; + if (nSeg >= 0x2000 && nSeg < 0x20FF) + { + nPoints = nSeg & 0x0FFF; + nSeg &= 0xFF00; + } + + drawing::EnhancedCustomShapeSegment aSegment; + switch (nSeg) + { + case 0x0001: // lineto + aSegment.Command = drawing::EnhancedCustomShapeSegmentCommand::LINETO; + aSegment.Count = sal_Int32(1); + aSegments.push_back(aSegment); + break; + case 0x4000: // moveto + aSegment.Command = drawing::EnhancedCustomShapeSegmentCommand::MOVETO; + aSegment.Count = sal_Int32(1); + aSegments.push_back(aSegment); + break; + case 0x2000: // curveto + aSegment.Command = drawing::EnhancedCustomShapeSegmentCommand::CURVETO; + aSegment.Count = nPoints; + aSegments.push_back(aSegment); + break; + case 0xb300: // arcto + aSegment.Command = drawing::EnhancedCustomShapeSegmentCommand::ARCTO; + aSegment.Count = sal_Int32(0); + aSegments.push_back(aSegment); + break; + case 0xac00: + case 0xaa00: // nofill + case 0xab00: // nostroke + case 0x6001: // close + break; + case 0x8000: // end + aSegment.Command + = drawing::EnhancedCustomShapeSegmentCommand::ENDSUBPATH; + aSegment.Count = sal_Int32(0); + aSegments.push_back(aSegment); + break; + default: // given number of lineto elements + aSegment.Command = drawing::EnhancedCustomShapeSegmentCommand::LINETO; + aSegment.Count = nSeg; + aSegments.push_back(aSegment); + break; + } + } + } while (nCharIndex >= 0); + aPropertyValue.Name = "Segments"; + aPropertyValue.Value <<= comphelper::containerToSequence(aSegments); + aPath.push_back(aPropertyValue); + } + else if (rProperty.first == "geoLeft") + aViewBox.X = rProperty.second.toInt32(); + else if (rProperty.first == "geoTop") + aViewBox.Y = rProperty.second.toInt32(); + else if (rProperty.first == "geoRight") + aViewBox.Width = rProperty.second.toInt32(); + else if (rProperty.first == "geoBottom") + aViewBox.Height = rProperty.second.toInt32(); + else if (rProperty.first == "dhgt") + { + // dhgt is Word 2007, \shpz is Word 97-2003, the later has priority. + if (!rShape.hasZ()) + resolveDhgt(xPropertySet, rProperty.second.toInt32(), /*bOldStyle=*/false); + } + // These are in EMU, convert to mm100. + else if (rProperty.first == "dxTextLeft") + { + if (xPropertySet.is()) + xPropertySet->setPropertyValue("LeftBorderDistance", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "dyTextTop") + { + if (xPropertySet.is()) + xPropertySet->setPropertyValue("TopBorderDistance", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "dxTextRight") + { + if (xPropertySet.is()) + xPropertySet->setPropertyValue("RightBorderDistance", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "dyTextBottom") + { + if (xPropertySet.is()) + xPropertySet->setPropertyValue("BottomBorderDistance", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "dxWrapDistLeft") + { + if (m_bTextGraphicObject) + rShape.getAnchorAttributes().set(NS_ooxml::LN_CT_Anchor_distL, + new RTFValue(rProperty.second.toInt32())); + else if (xPropertySet.is()) + xPropertySet->setPropertyValue("LeftMargin", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "dyWrapDistTop") + { + if (m_bTextGraphicObject) + rShape.getAnchorAttributes().set(NS_ooxml::LN_CT_Anchor_distT, + new RTFValue(rProperty.second.toInt32())); + else if (xPropertySet.is()) + xPropertySet->setPropertyValue("TopMargin", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "dxWrapDistRight") + { + if (m_bTextGraphicObject) + rShape.getAnchorAttributes().set(NS_ooxml::LN_CT_Anchor_distR, + new RTFValue(rProperty.second.toInt32())); + else if (xPropertySet.is()) + xPropertySet->setPropertyValue("RightMargin", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "dyWrapDistBottom") + { + if (m_bTextGraphicObject) + rShape.getAnchorAttributes().set(NS_ooxml::LN_CT_Anchor_distB, + new RTFValue(rProperty.second.toInt32())); + else if (xPropertySet.is()) + xPropertySet->setPropertyValue("BottomMargin", + uno::makeAny(rProperty.second.toInt32() / 360)); + } + else if (rProperty.first == "fillType") + { + switch (rProperty.second.toInt32()) + { + case 7: // Shade using the fillAngle + aFillModel.moType.set(oox::XML_gradient); + break; + default: + SAL_INFO("writerfilter", + "TODO handle fillType value '" << rProperty.second << "'"); + break; + } + } + else if (rProperty.first == "fillFocus") + aFillModel.moFocus.set(rProperty.second.toDouble() / 100); // percent + else if (rProperty.first == "fShadow" && xPropertySet.is()) + { + if (rProperty.second.toInt32() == 1) + aShadowModel.mbHasShadow = true; + } + else if (rProperty.first == "shadowColor") + aShadowModel.moColor.set("#" + + OUString::fromUtf8(msfilter::util::ConvertColor( + msfilter::util::BGRToRGB(rProperty.second.toInt32())))); + else if (rProperty.first == "shadowOffsetX") + // EMUs to points + aShadowModel.moOffset.set(OUString::number(rProperty.second.toDouble() / 12700) + "pt"); + else if (rProperty.first == "posh" || rProperty.first == "posv" + || rProperty.first == "fFitShapeToText" || rProperty.first == "fFilled" + || rProperty.first == "rotation") + applyProperty(xShape, rProperty.first, rProperty.second); + else if (rProperty.first == "posrelh") + { + switch (rProperty.second.toInt32()) + { + case 1: + rShape.setHoriOrientRelation(text::RelOrientation::PAGE_FRAME); + break; + default: + break; + } + } + else if (rProperty.first == "posrelv") + { + switch (rProperty.second.toInt32()) + { + case 1: + rShape.setVertOrientRelation(text::RelOrientation::PAGE_FRAME); + break; + default: + break; + } + } + else if (rProperty.first == "groupLeft") + oGroupLeft = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "groupTop") + oGroupTop = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "groupRight") + oGroupRight = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "groupBottom") + oGroupBottom = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "relLeft") + oRelLeft = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "relTop") + oRelTop = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "relRight") + oRelRight = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "relBottom") + oRelBottom = convertTwipToMm100(rProperty.second.toInt32()); + else if (rProperty.first == "fBehindDocument") + bOpaque = !rProperty.second.toInt32(); + else if (rProperty.first == "pctHoriz" || rProperty.first == "pctVert") + { + sal_Int16 nPercentage = rtl::math::round(rProperty.second.toDouble() / 10); + if (nPercentage) + { + std::optional& rPercentage + = rProperty.first == "pctHoriz" ? oRelativeWidth : oRelativeHeight; + rPercentage = nPercentage; + } + } + else if (rProperty.first == "sizerelh") + { + if (xPropertySet.is()) + { + switch (rProperty.second.toInt32()) + { + case 0: // margin + nRelativeWidthRelation = text::RelOrientation::FRAME; + break; + case 1: // page + nRelativeWidthRelation = text::RelOrientation::PAGE_FRAME; + break; + default: + SAL_WARN("writerfilter", "RTFSdrImport::resolve: unhandled sizerelh value: " + << rProperty.second); + break; + } + } + } + else if (rProperty.first == "sizerelv") + { + if (xPropertySet.is()) + { + switch (rProperty.second.toInt32()) + { + case 0: // margin + nRelativeHeightRelation = text::RelOrientation::FRAME; + break; + case 1: // page + nRelativeHeightRelation = text::RelOrientation::PAGE_FRAME; + break; + default: + SAL_WARN("writerfilter", "RTFSdrImport::resolve: unhandled sizerelv value: " + << rProperty.second); + break; + } + } + } + else if (rProperty.first == "fHorizRule") // TODO: what does "fStandardHR" do? + { + // horizontal rule: relative width defaults to 100% of paragraph + // TODO: does it have a default height? + if (!oRelativeWidth) + { + oRelativeWidth = 100; + } + nRelativeWidthRelation = text::RelOrientation::FRAME; + sal_Int16 const nVertOrient = text::VertOrientation::CENTER; + if (xPropertySet.is()) + { + xPropertySet->setPropertyValue("VertOrient", uno::makeAny(nVertOrient)); + } + } + else if (rProperty.first == "pctHR") + { + // horizontal rule relative width in permille + oRelativeWidth = rProperty.second.toInt32() / 10; + } + else if (rProperty.first == "dxHeightHR") + { + // horizontal rule height + sal_uInt32 const nHeight(convertTwipToMm100(rProperty.second.toInt32())); + rShape.setBottom(rShape.getTop() + nHeight); + } + else if (rProperty.first == "dxWidthHR") + { + // horizontal rule width + sal_uInt32 const nWidth(convertTwipToMm100(rProperty.second.toInt32())); + rShape.setRight(rShape.getLeft() + nWidth); + } + else if (rProperty.first == "alignHR") + { + // horizontal orientation *for horizontal rule* + sal_Int16 nHoriOrient = text::HoriOrientation::NONE; + switch (rProperty.second.toInt32()) + { + case 0: + nHoriOrient = text::HoriOrientation::LEFT; + break; + case 1: + nHoriOrient = text::HoriOrientation::CENTER; + break; + case 2: + nHoriOrient = text::HoriOrientation::RIGHT; + break; + } + if (xPropertySet.is() && text::HoriOrientation::NONE != nHoriOrient) + { + xPropertySet->setPropertyValue("HoriOrient", uno::makeAny(nHoriOrient)); + } + } + else if (rProperty.first == "pWrapPolygonVertices") + { + RTFSprms aPolygonSprms; + sal_Int32 nSize = 0; // Size of a token + sal_Int32 nCount = 0; // Number of tokens + sal_Int32 nCharIndex = 0; // Character index + do + { + OUString aToken = rProperty.second.getToken(0, ';', nCharIndex); + if (!nSize) + nSize = aToken.toInt32(); + else if (!nCount) + nCount = aToken.toInt32(); + else if (aToken.getLength()) + { + // The coordinates are in an (x,y) form. + aToken = aToken.copy(1, aToken.getLength() - 2); + sal_Int32 nI = 0; + sal_Int32 nX = aToken.getToken(0, ',', nI).toInt32(); + sal_Int32 nY = (nI >= 0) ? aToken.getToken(0, ',', nI).toInt32() : 0; + RTFSprms aPathAttributes; + aPathAttributes.set(NS_ooxml::LN_CT_Point2D_x, new RTFValue(nX)); + aPathAttributes.set(NS_ooxml::LN_CT_Point2D_y, new RTFValue(nY)); + aPolygonSprms.set(NS_ooxml::LN_CT_WrapPath_lineTo, + new RTFValue(aPathAttributes), RTFOverwrite::NO_APPEND); + } + } while (nCharIndex >= 0); + rShape.getWrapPolygonSprms() = aPolygonSprms; + } + else if (rProperty.first == "fRelFlipV") + obRelFlipV = rProperty.second.toInt32() == 1; + else if (rProperty.first == "fFlipH") + obFlipH = rProperty.second.toInt32() == 1; + else if (rProperty.first == "fFlipV") + obFlipV = rProperty.second.toInt32() == 1; + else + SAL_INFO("writerfilter", "TODO handle shape property '" << rProperty.first << "':'" + << rProperty.second << "'"); + } + + if (xPropertySet.is()) + { + resolveLineColorAndWidth(m_bTextFrame, xPropertySet, aLineColor, aLineWidth); + if (rShape.hasZ()) + { + bool bOldStyle = m_aParents.size() > 1; + resolveDhgt(xPropertySet, rShape.getZ(), bOldStyle); + } + if (m_bTextFrame) + xPropertySet->setPropertyValue("WritingMode", uno::makeAny(eWritingMode)); + else + // Only Writer textframes implement text::WritingMode2. + xPropertySet->setPropertyValue("TextWritingMode", + uno::makeAny(text::WritingMode(eWritingMode))); + } + + if (!m_aParents.empty() && m_aParents.top().is() && !m_bTextFrame) + m_aParents.top()->add(xShape); + + if (bPib) + { + m_rImport.resolvePict(false, xShape); + } + + if (nType == ESCHER_ShpInst_PictureFrame) // picture frame + { + assert(!m_bTextFrame); + if (!bPib) // ??? not sure if the early return should be removed on else? + { + m_xShape = xShape; // store it for later resolvePict call + } + + // Handle horizontal flip. + if (obFlipH == true && xPropertySet.is()) + xPropertySet->setPropertyValue("IsMirrored", uno::makeAny(true)); + return; + } + + if (bCustom && xShape.is() && !bPib) + { + uno::Reference xDefaulter(xShape, uno::UNO_QUERY); + xDefaulter->createCustomShapeDefaults(OUString::number(nType)); + } + + // Set shape text + if (bCustom && !aShapeText.isEmpty()) + { + uno::Reference xTextRange(xShape, uno::UNO_QUERY); + if (xTextRange.is()) + xTextRange->setString(aShapeText); + + xPropertySet->setPropertyValue("CharFontName", uno::makeAny(aFontFamily)); + xPropertySet->setPropertyValue("CharHeight", uno::makeAny(nFontSize)); + } + + // Creating CustomShapeGeometry property + if (bCustom && xPropertySet.is()) + { + bool bChanged = false; + comphelper::SequenceAsHashMap aCustomShapeGeometry( + xPropertySet->getPropertyValue("CustomShapeGeometry")); + + if (aViewBox.X || aViewBox.Y || aViewBox.Width || aViewBox.Height) + { + aViewBox.Width -= aViewBox.X; + aViewBox.Height -= aViewBox.Y; + aCustomShapeGeometry["ViewBox"] <<= aViewBox; + bChanged = true; + } + + if (!aPath.empty()) + { + aCustomShapeGeometry["Path"] <<= comphelper::containerToSequence(aPath); + bChanged = true; + } + + if (!aShapeText.isEmpty()) + { + uno::Sequence aSequence(comphelper::InitPropertySequence({ + { "TextPath", uno::makeAny(true) }, + })); + aCustomShapeGeometry["TextPath"] <<= aSequence; + xPropertySet->setPropertyValue("TextAutoGrowHeight", uno::makeAny(false)); + xPropertySet->setPropertyValue("TextAutoGrowWidth", uno::makeAny(false)); + bChanged = true; + } + + if (bChanged) + { + xPropertySet->setPropertyValue( + "CustomShapeGeometry", + uno::makeAny(aCustomShapeGeometry.getAsConstPropertyValueList())); + } + } + + if (!boost::logic::indeterminate(obRelFlipV) && xPropertySet.is()) + { + if (nType == ESCHER_ShpInst_Line) + { + // Line shape inside group shape: get the polygon sequence and transform it. + uno::Sequence> aPolyPolySequence; + if ((xPropertySet->getPropertyValue("PolyPolygon") >>= aPolyPolySequence) + && aPolyPolySequence.hasElements()) + { + uno::Sequence& rPolygon = aPolyPolySequence[0]; + basegfx::B2DPolygon aPoly; + for (const awt::Point& rPoint : std::as_const(rPolygon)) + { + aPoly.append(basegfx::B2DPoint(rPoint.X, rPoint.Y)); + } + basegfx::B2DHomMatrix aTransformation; + aTransformation.scale(1.0, obRelFlipV ? -1.0 : 1.0); + aPoly.transform(aTransformation); + for (sal_Int32 i = 0; i < rPolygon.getLength(); ++i) + { + basegfx::B2DPoint aPoint(aPoly.getB2DPoint(i)); + rPolygon[i] + = awt::Point(static_cast(convertMm100ToTwip(aPoint.getX())), + static_cast(convertMm100ToTwip(aPoint.getY()))); + } + xPropertySet->setPropertyValue("PolyPolygon", uno::makeAny(aPolyPolySequence)); + } + } + } + + // Set position and size + if (xShape.is()) + { + sal_Int32 nLeft = rShape.getLeft(); + sal_Int32 nTop = rShape.getTop(); + + bool bInShapeGroup = oGroupLeft && oGroupTop && oGroupRight && oGroupBottom && oRelLeft + && oRelTop && oRelRight && oRelBottom; + awt::Size aSize; + if (bInShapeGroup) + { + // See lclGetAbsPoint() in the VML import: rShape is the group shape, oGroup is its coordinate system, oRel is the relative child shape. + sal_Int32 nShapeWidth = rShape.getRight() - rShape.getLeft(); + sal_Int32 nShapeHeight = rShape.getBottom() - rShape.getTop(); + sal_Int32 nCoordSysWidth = *oGroupRight - *oGroupLeft; + sal_Int32 nCoordSysHeight = *oGroupBottom - *oGroupTop; + double fWidthRatio = static_cast(nShapeWidth) / nCoordSysWidth; + double fHeightRatio = static_cast(nShapeHeight) / nCoordSysHeight; + nLeft = static_cast(rShape.getLeft() + + fWidthRatio * (*oRelLeft - *oGroupLeft)); + nTop = static_cast(rShape.getTop() + fHeightRatio * (*oRelTop - *oGroupTop)); + + // See lclGetAbsRect() in the VML import. + aSize.Width = std::lround(fWidthRatio * (*oRelRight - *oRelLeft)); + aSize.Height = std::lround(fHeightRatio * (*oRelBottom - *oRelTop)); + } + + if (m_bTextFrame) + { + xPropertySet->setPropertyValue("HoriOrientPosition", uno::makeAny(nLeft)); + xPropertySet->setPropertyValue("VertOrientPosition", uno::makeAny(nTop)); + } + else + xShape->setPosition(awt::Point(nLeft, nTop)); + + if (bInShapeGroup) + xShape->setSize(aSize); + else + xShape->setSize(awt::Size(rShape.getRight() - rShape.getLeft(), + rShape.getBottom() - rShape.getTop())); + + if (obFlipH == true || obFlipV == true) + { + if (bCustom) + { + // This has to be set after position and size is set, otherwise flip will affect the position. + comphelper::SequenceAsHashMap aCustomShapeGeometry( + xPropertySet->getPropertyValue("CustomShapeGeometry")); + if (obFlipH == true) + aCustomShapeGeometry["MirroredX"] <<= true; + if (obFlipV == true) + aCustomShapeGeometry["MirroredY"] <<= true; + xPropertySet->setPropertyValue( + "CustomShapeGeometry", + uno::makeAny(aCustomShapeGeometry.getAsConstPropertyValueList())); + } + else if (SdrObject* pObject = GetSdrObjectFromXShape(xShape)) + { + Point aRef1 = pObject->GetSnapRect().Center(); + Point aRef2(aRef1); + if (obFlipH == true) + { + // Horizontal mirror means a vertical reference line. + aRef2.AdjustY(1); + } + if (obFlipV == true) + { + // Vertical mirror means a horizontal reference line. + aRef2.AdjustX(1); + } + pObject->Mirror(aRef1, aRef2); + } + } + + if (rShape.getHoriOrientRelation() != 0) + xPropertySet->setPropertyValue("HoriOrientRelation", + uno::makeAny(rShape.getHoriOrientRelation())); + if (rShape.getVertOrientRelation() != 0) + xPropertySet->setPropertyValue("VertOrientRelation", + uno::makeAny(rShape.getVertOrientRelation())); + if (rShape.getWrap() != text::WrapTextMode::WrapTextMode_MAKE_FIXED_SIZE) + xPropertySet->setPropertyValue("Surround", uno::makeAny(rShape.getWrap())); + oox::ModelObjectHelper aModelObjectHelper(m_rImport.getModelFactory()); + if (aFillModel.moType.has()) + { + oox::drawingml::ShapePropertyMap aPropMap(aModelObjectHelper); + aFillModel.pushToPropMap(aPropMap, m_rImport.getGraphicHelper()); + // Sets the FillStyle and FillGradient UNO properties. + oox::PropertySet(xShape).setProperties(aPropMap); + } + + if (aShadowModel.mbHasShadow) + { + oox::drawingml::ShapePropertyMap aPropMap(aModelObjectHelper); + aShadowModel.pushToPropMap(aPropMap, m_rImport.getGraphicHelper()); + // Sets the ShadowFormat UNO property. + oox::PropertySet(xShape).setProperties(aPropMap); + } + xPropertySet->setPropertyValue("AnchorType", + uno::makeAny(text::TextContentAnchorType_AT_CHARACTER)); + xPropertySet->setPropertyValue("Opaque", uno::makeAny(bOpaque)); + if (oRelativeWidth) + { + xPropertySet->setPropertyValue("RelativeWidth", uno::makeAny(*oRelativeWidth)); + xPropertySet->setPropertyValue("RelativeWidthRelation", + uno::makeAny(nRelativeWidthRelation)); + } + if (oRelativeHeight) + { + xPropertySet->setPropertyValue("RelativeHeight", uno::makeAny(*oRelativeHeight)); + xPropertySet->setPropertyValue("RelativeHeightRelation", + uno::makeAny(nRelativeHeightRelation)); + } + } + + if (m_rImport.isInBackground()) + { + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_Background_color, + new RTFValue(xPropertySet->getPropertyValue("FillColor").get())); + m_rImport.Mapper().props(new RTFReferenceProperties(aAttributes)); + + uno::Reference xComponent(xShape, uno::UNO_QUERY); + xComponent->dispose(); + return; + } + + // Send it to dmapper + if (xShape.is()) + { + m_rImport.Mapper().startShape(xShape); + if (bClose) + { + m_rImport.Mapper().endShape(); + } + } + + // If the shape has an inner shape, the inner object's properties should not be influenced by + // the outer one. + rShape.getProperties().clear(); + + m_xShape = xShape; +} + +void RTFSdrImport::close() { m_rImport.Mapper().endShape(); } + +void RTFSdrImport::append(const OUString& aKey, const OUString& aValue) +{ + applyProperty(m_xShape, aKey, aValue); +} + +void RTFSdrImport::appendGroupProperty(const OUString& aKey, const OUString& aValue) +{ + if (m_aParents.empty()) + return; + uno::Reference xShape(m_aParents.top(), uno::UNO_QUERY); + if (xShape.is()) + applyProperty(xShape, aKey, aValue); +} + +} // namespace writerfilter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx new file mode 100644 index 000000000..474966d28 --- /dev/null +++ b/writerfilter/source/rtftok/rtfsdrimport.hxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSDRIMPORT_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSDRIMPORT_HXX + +#include +#include + +#include +#include + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace beans +{ +class XPropertySet; +struct PropertyValue; +} +namespace drawing +{ +class XShape; +class XShapes; +} +namespace lang +{ +class XComponent; +} +} +} +} + +namespace writerfilter +{ +namespace rtftok +{ +class RTFDocumentImpl; +class RTFShape; + +/// Handles the import of drawings using RTF markup. +class RTFSdrImport final : public virtual SvRefBase +{ +public: + RTFSdrImport(RTFDocumentImpl& rDocument, + css::uno::Reference const& xDstDoc); + ~RTFSdrImport() override; + + enum ShapeOrPict + { + SHAPE, + PICT + }; + void resolve(RTFShape& rShape, bool bClose, ShapeOrPict shapeOrPict); + void close(); + void append(const OUString& aKey, const OUString& aValue); + /// Append property on the current parent. + void appendGroupProperty(const OUString& aKey, const OUString& aValue); + void resolveDhgt(css::uno::Reference const& xPropertySet, + sal_Int32 nZOrder, bool bOldStyle); + /// Set line color and line width on the shape, using the relevant API depending on if the shape is a text frame or not. + static void + resolveLineColorAndWidth(bool bTextFrame, + const css::uno::Reference& xPropertySet, + css::uno::Any const& rLineColor, css::uno::Any const& rLineWidth); + static void resolveFLine(css::uno::Reference const& xPropertySet, + sal_Int32 nFLine); + /** + * These are the default in Word, but not in Writer. + * + * @param bNew if the frame is new-style or old-style. + */ + static std::vector getTextFrameDefaults(bool bNew); + /// Push a new group shape to the parent stack. + void pushParent(css::uno::Reference const& xParent); + /// Pop the current group shape from the parent stack. + void popParent(); + css::uno::Reference const& getCurrentShape() const { return m_xShape; } + bool isFakePict() const { return m_bFakePict; } + +private: + void createShape(const OUString& rService, css::uno::Reference& xShape, + css::uno::Reference& xPropertySet); + void applyProperty(css::uno::Reference const& xShape, + const OUString& aKey, const OUString& aValue) const; + int initShape(css::uno::Reference& o_xShape, + css::uno::Reference& o_xPropSet, bool& o_rIsCustomShape, + RTFShape const& rShape, bool bClose, ShapeOrPict shapeOrPict); + + RTFDocumentImpl& m_rImport; + std::stack> m_aParents; + css::uno::Reference m_xShape; + /// If m_xShape is imported as a Writer text frame (instead of a drawinglayer rectangle). + bool m_bTextFrame; + /// If m_xShape is imported as a Writer text graphic object (instead of a drawinglayer shape). + bool m_bTextGraphicObject; + /// if inside \pict, but actually it's a shape (not a picture) + bool m_bFakePict; + std::stack m_aGraphicZOrderHelpers; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSDRIMPORT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfskipdestination.cxx b/writerfilter/source/rtftok/rtfskipdestination.cxx new file mode 100644 index 000000000..47ada340e --- /dev/null +++ b/writerfilter/source/rtftok/rtfskipdestination.cxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfskipdestination.hxx" +#include +#include +#include "rtflistener.hxx" + +namespace writerfilter::rtftok +{ +RTFSkipDestination::RTFSkipDestination(RTFListener& rImport) + : m_rImport(rImport) + , m_bParsed(true) + , m_bReset(true) +{ +} + +RTFSkipDestination::~RTFSkipDestination() +{ + if (m_rImport.getSkipUnknown() && m_bReset) + { + if (!m_bParsed) + { + SAL_INFO("writerfilter", OSL_THIS_FUNC << ": skipping destination"); + m_rImport.setDestination(Destination::SKIP); + } + m_rImport.setSkipUnknown(false); + } +} + +void RTFSkipDestination::setParsed(bool bParsed) { m_bParsed = bParsed; } + +void RTFSkipDestination::setReset(bool bReset) { m_bReset = bReset; } + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfskipdestination.hxx b/writerfilter/source/rtftok/rtfskipdestination.hxx new file mode 100644 index 000000000..8f8c6aa9d --- /dev/null +++ b/writerfilter/source/rtftok/rtfskipdestination.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSKIPDESTINATION_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSKIPDESTINATION_HXX + +namespace writerfilter +{ +namespace rtftok +{ +class RTFListener; + +/// Skips a destination after a not parsed control word if it was prefixed with \* +class RTFSkipDestination final +{ +public: + explicit RTFSkipDestination(RTFListener& rImport); + ~RTFSkipDestination(); + void setParsed(bool bParsed); + void setReset(bool bReset); + +private: + RTFListener& m_rImport; + bool m_bParsed; + /// If false, the destructor is a noop, required by the \* symbol itself. + bool m_bReset; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSKIPDESTINATION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfsprm.cxx b/writerfilter/source/rtftok/rtfsprm.cxx new file mode 100644 index 000000000..5c2edbb1c --- /dev/null +++ b/writerfilter/source/rtftok/rtfsprm.cxx @@ -0,0 +1,448 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfsprm.hxx" +#include +#include +#include +#include "rtfdocumentimpl.hxx" +#include + +namespace writerfilter::rtftok +{ +RTFSprm::RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue) + : m_nKeyword(nKeyword) + , m_pValue(pValue) +{ +} + +sal_uInt32 RTFSprm::getId() const { return m_nKeyword; } + +Value::Pointer_t RTFSprm::getValue() { return Value::Pointer_t(m_pValue->Clone()); } + +writerfilter::Reference::Pointer_t RTFSprm::getProps() +{ + return m_pValue->getProperties(); +} + +#ifdef DBG_UTIL +std::string RTFSprm::getName() const { return "RTFSprm"; } +#endif + +#ifdef DBG_UTIL +std::string RTFSprm::toString() const +{ + OStringBuffer aBuf("RTFSprm"); + + std::string sResult = QNameToString(m_nKeyword); + + aBuf.append(" ('"); + if (sResult.length() == 0) + aBuf.append(sal_Int32(m_nKeyword)); + else + aBuf.append(sResult.c_str()); + aBuf.append("', '"); + aBuf.append(m_pValue->toString().c_str()); + aBuf.append("')"); + + return aBuf.makeStringAndClear().getStr(); +} +#endif + +namespace +{ +class RTFSprms_compare +{ + Id keyword; + +public: + RTFSprms_compare(Id kw) + : keyword{ kw } + { + } + bool operator()(const std::pair& raPair) const + { + return raPair.first == keyword; + } +}; +} + +RTFValue::Pointer_t RTFSprms::find(Id nKeyword, bool bFirst, bool bForWrite) +{ + if (bForWrite) + ensureCopyBeforeWrite(); + + RTFSprms_compare cmp{ nKeyword }; + + if (bFirst) + { + auto it = std::find_if(m_pSprms->begin(), m_pSprms->end(), cmp); + if (it != m_pSprms->end()) + return it->second; + } + else + // find last + { + auto rit = std::find_if(m_pSprms->rbegin(), m_pSprms->rend(), cmp); + if (rit != m_pSprms->rend()) + return rit->second; + } + + return RTFValue::Pointer_t{}; +} + +void RTFSprms::set(Id nKeyword, const RTFValue::Pointer_t& pValue, RTFOverwrite eOverwrite) +{ + ensureCopyBeforeWrite(); + + switch (eOverwrite) + { + case RTFOverwrite::YES_PREPEND: + { + m_pSprms->erase( + std::remove_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword }), + m_pSprms->end()); + m_pSprms->emplace(m_pSprms->cbegin(), nKeyword, pValue); + break; + } + case RTFOverwrite::YES: + { + auto it + = std::find_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword }); + if (it != m_pSprms->end()) + it->second = pValue; + else + m_pSprms->emplace_back(nKeyword, pValue); + break; + } + case RTFOverwrite::NO_IGNORE: + { + if (std::none_of(m_pSprms->cbegin(), m_pSprms->cend(), RTFSprms_compare{ nKeyword })) + m_pSprms->emplace_back(nKeyword, pValue); + break; + } + case RTFOverwrite::NO_APPEND: + { + m_pSprms->emplace_back(nKeyword, pValue); + break; + } + } +} + +bool RTFSprms::erase(Id nKeyword) +{ + ensureCopyBeforeWrite(); + + auto i = std::find_if(m_pSprms->begin(), m_pSprms->end(), RTFSprms_compare{ nKeyword }); + if (i != m_pSprms->end()) + { + m_pSprms->erase(i); + return true; + } + return false; +} + +void RTFSprms::eraseLast(Id nKeyword) +{ + ensureCopyBeforeWrite(); + + auto i = std::find_if(m_pSprms->rbegin(), m_pSprms->rend(), RTFSprms_compare{ nKeyword }); + if (i != m_pSprms->rend()) + m_pSprms->erase(std::next(i).base()); +} + +static RTFValue::Pointer_t getDefaultSPRM(Id const id, Id nStyleType) +{ + if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_character) + { + switch (id) + { + case NS_ooxml::LN_EG_RPrBase_b: + return new RTFValue(0); + default: + break; + } + } + + if (!nStyleType || nStyleType == NS_ooxml::LN_Value_ST_StyleType_paragraph) + { + switch (id) + { + case NS_ooxml::LN_CT_Spacing_before: + case NS_ooxml::LN_CT_Spacing_after: + case NS_ooxml::LN_CT_Ind_left: + case NS_ooxml::LN_CT_Ind_right: + case NS_ooxml::LN_CT_Ind_firstLine: + return new RTFValue(0); + + case NS_ooxml::LN_CT_Spacing_lineRule: + return new RTFValue(NS_ooxml::LN_Value_doc_ST_LineSpacingRule_auto); + case NS_ooxml::LN_CT_Spacing_line: + // presumably this means 100%, cf. static const int nSingleLineSpacing = 240; + return new RTFValue(240); + + default: + break; + } + } + + return RTFValue::Pointer_t(); +} + +/// Is it problematic to deduplicate this SPRM? +static bool isSPRMDeduplicateBlacklist(Id nId, RTFSprms* pDirect) +{ + switch (nId) + { + // See the NS_ooxml::LN_CT_PPrBase_tabs handler in DomainMapper, + // deduplication is explicitly not wanted for these tokens. + case NS_ooxml::LN_CT_TabStop_val: + case NS_ooxml::LN_CT_TabStop_leader: + case NS_ooxml::LN_CT_TabStop_pos: + // \htmautsp arrives after the style table, so only the non-style value is + // correct, keep these. + case NS_ooxml::LN_CT_Spacing_beforeAutospacing: + case NS_ooxml::LN_CT_Spacing_afterAutospacing: + // \chbrdr requires *all* of the border settings to be present, + // otherwise a default (NONE) border is created from the removed + // attributes which then overrides the style-defined border. + // See BorderHandler.cxx and NS_ooxml::LN_EG_RPrBase_bdr in DomainMapper. + // This also is needed for NS_ooxml::LN_CT_PBdr_top etc. + case NS_ooxml::LN_CT_Border_sz: + case NS_ooxml::LN_CT_Border_val: + case NS_ooxml::LN_CT_Border_color: + case NS_ooxml::LN_CT_Border_space: + case NS_ooxml::LN_CT_Border_shadow: + case NS_ooxml::LN_CT_Border_frame: + case NS_ooxml::LN_CT_Border_themeTint: + case NS_ooxml::LN_CT_Border_themeColor: + return true; + // Removing \fi and \li if the style has the same value would mean taking these values from + // \ls, while deduplication would be done to take the values from the style. + case NS_ooxml::LN_CT_Ind_firstLine: + case NS_ooxml::LN_CT_Ind_left: + return pDirect && pDirect->find(NS_ooxml::LN_CT_PPrBase_numPr); + + default: + return false; + } +} + +/// Should this SPRM be removed if all its children are removed? +static bool isSPRMChildrenExpected(Id nId) +{ + switch (nId) + { + case NS_ooxml::LN_CT_PBdr_top: + case NS_ooxml::LN_CT_PBdr_left: + case NS_ooxml::LN_CT_PBdr_bottom: + case NS_ooxml::LN_CT_PBdr_right: + // Expected children are NS_ooxml::LN_CT_Border_*. + case NS_ooxml::LN_CT_PrBase_shd: + // Expected children are NS_ooxml::LN_CT_Shd_*. + case NS_ooxml::LN_CT_PPrBase_ind: + // Expected children are NS_ooxml::LN_CT_Ind_*. + return true; + + default: + return false; + } +} + +/// Does the clone / deduplication of a single sprm. +static void cloneAndDeduplicateSprm(std::pair const& rSprm, RTFSprms& ret, + Id nStyleType, RTFSprms* pDirect = nullptr) +{ + RTFValue::Pointer_t const pValue(ret.find(rSprm.first)); + if (pValue) + { + if (rSprm.second->equals(*pValue)) + { + if (!isSPRMDeduplicateBlacklist(rSprm.first, pDirect)) + { + ret.erase(rSprm.first); // duplicate to style + } + } + else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty()) + { + RTFSprms const sprms(pValue->getSprms().cloneAndDeduplicate( + rSprm.second->getSprms(), nStyleType, /*bImplicitPPr =*/false, pDirect)); + RTFSprms const attributes(pValue->getAttributes().cloneAndDeduplicate( + rSprm.second->getAttributes(), nStyleType, /*bImplicitPPr =*/false, pDirect)); + // Don't copy the sprm in case we expect it to have children but it doesn't have some. + if (!isSPRMChildrenExpected(rSprm.first) || !sprms.empty() || !attributes.empty()) + ret.set(rSprm.first, + RTFValue::Pointer_t(pValue->CloneWithSprms(attributes, sprms))); + } + } + else + { + // not found - try to override style with default + RTFValue::Pointer_t const pDefault(getDefaultSPRM(rSprm.first, nStyleType)); + if (pDefault) + { + ret.set(rSprm.first, pDefault); + } + else if (!rSprm.second->getSprms().empty() || !rSprm.second->getAttributes().empty()) + { + RTFSprms const sprms( + RTFSprms().cloneAndDeduplicate(rSprm.second->getSprms(), nStyleType)); + RTFSprms const attributes( + RTFSprms().cloneAndDeduplicate(rSprm.second->getAttributes(), nStyleType)); + if (!sprms.empty() || !attributes.empty()) + { + ret.set(rSprm.first, new RTFValue(attributes, sprms)); + } + } + } +} + +/// Extracts the list level matching nLevel from pAbstract. +static RTFValue::Pointer_t getListLevel(const RTFValue::Pointer_t& pAbstract, int nLevel) +{ + for (const auto& rPair : pAbstract->getSprms()) + { + if (rPair.first != NS_ooxml::LN_CT_AbstractNum_lvl) + continue; + + RTFValue::Pointer_t pLevel = rPair.second->getAttributes().find(NS_ooxml::LN_CT_Lvl_ilvl); + if (!pLevel) + continue; + + if (pLevel->getInt() != nLevel) + continue; + + return rPair.second; + } + + return RTFValue::Pointer_t(); +} + +void RTFSprms::deduplicateList(const std::map& rInvalidListLevelFirstIndents) +{ + int nLevel = 0; + RTFValue::Pointer_t pLevelId + = getNestedSprm(*this, NS_ooxml::LN_CT_PPrBase_numPr, NS_ooxml::LN_CT_NumPr_ilvl); + if (pLevelId) + nLevel = pLevelId->getInt(); + + auto it = rInvalidListLevelFirstIndents.find(nLevel); + if (it == rInvalidListLevelFirstIndents.end()) + return; + + int nListValue = it->second; + + RTFValue::Pointer_t pParagraphValue + = getNestedAttribute(*this, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine); + if (!pParagraphValue) + return; + + int nParagraphValue = pParagraphValue->getInt(); + + if (nParagraphValue == nListValue) + eraseNestedAttribute(*this, NS_ooxml::LN_CT_PPrBase_ind, NS_ooxml::LN_CT_Ind_firstLine); +} + +void RTFSprms::duplicateList(const RTFValue::Pointer_t& pAbstract) +{ + int nLevel = 0; + RTFValue::Pointer_t pLevelId + = getNestedSprm(*this, NS_ooxml::LN_CT_PPrBase_numPr, NS_ooxml::LN_CT_NumPr_ilvl); + if (pLevelId) + nLevel = pLevelId->getInt(); + + RTFValue::Pointer_t pLevel = getListLevel(pAbstract, nLevel); + if (!pLevel) + return; + + RTFValue::Pointer_t pLevelInd = pLevel->getSprms().find(NS_ooxml::LN_CT_PPrBase_ind); + if (!pLevelInd) + return; + + for (const auto& rListLevelPair : pLevelInd->getAttributes()) + { + switch (rListLevelPair.first) + { + case NS_ooxml::LN_CT_Ind_left: + case NS_ooxml::LN_CT_Ind_right: + case NS_ooxml::LN_CT_Ind_firstLine: + RTFValue::Pointer_t pParagraphValue + = getNestedAttribute(*this, NS_ooxml::LN_CT_PPrBase_ind, rListLevelPair.first); + if (!pParagraphValue) + putNestedAttribute(*this, NS_ooxml::LN_CT_PPrBase_ind, rListLevelPair.first, + getDefaultSPRM(rListLevelPair.first, 0)); + + break; + } + } +} + +RTFSprms RTFSprms::cloneAndDeduplicate(RTFSprms& rReference, Id const nStyleType, + bool const bImplicitPPr, RTFSprms* pDirect) const +{ + RTFSprms ret(*this); + ret.ensureCopyBeforeWrite(); + + // Note: apparently some attributes are set with OVERWRITE_NO_APPEND; + // it is probably a bad idea to mess with those in any way here? + for (auto& rSprm : rReference) + { + // Paragraph formatting sprms are directly contained in case of + // paragraphs, but they are below NS_ooxml::LN_CT_Style_pPr in case of + // styles. So handle those children directly, to avoid unexpected + // addition of direct formatting sprms at the paragraph level. + if (bImplicitPPr && rSprm.first == NS_ooxml::LN_CT_Style_pPr) + { + for (const auto& i : rSprm.second->getSprms()) + cloneAndDeduplicateSprm(i, ret, nStyleType, pDirect); + } + else + cloneAndDeduplicateSprm(rSprm, ret, nStyleType, pDirect); + } + return ret; +} + +bool RTFSprms::equals(const RTFValue& rOther) const +{ + return std::all_of(m_pSprms->cbegin(), m_pSprms->cend(), + [&](const std::pair& raPair) -> bool { + return raPair.second->equals(rOther); + }); +} + +void RTFSprms::ensureCopyBeforeWrite() +{ + if (m_pSprms->GetRefCount() > 1) + { + tools::SvRef pClone(new RTFSprmsImpl); + for (auto& rSprm : *m_pSprms) + pClone->push_back( + std::make_pair(rSprm.first, RTFValue::Pointer_t(rSprm.second->Clone()))); + m_pSprms = pClone; + } +} + +RTFSprms::RTFSprms() + : m_pSprms(new RTFSprmsImpl) +{ +} + +RTFSprms::~RTFSprms() = default; + +void RTFSprms::clear() +{ + if (m_pSprms->GetRefCount() == 1) + return m_pSprms->clear(); + + m_pSprms = tools::SvRef(new RTFSprmsImpl); +} + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfsprm.hxx b/writerfilter/source/rtftok/rtfsprm.hxx new file mode 100644 index 000000000..bb4f7c790 --- /dev/null +++ b/writerfilter/source/rtftok/rtfsprm.hxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX + +#include +#include +#include +#include + +#include +#include "rtfvalue.hxx" + +namespace writerfilter +{ +namespace rtftok +{ +using RTFSprmsImplBase = std::vector>; + +/// The payload of RTFSprms which is only copied on write. +class RTFSprmsImpl : public RTFSprmsImplBase, public virtual SvRefBase +{ +}; + +enum class RTFOverwrite +{ + YES, ///< Yes, if an existing key is found, overwrite it. + NO_APPEND, ///< No, always append the value to the end of the list. + NO_IGNORE, ///< No, if the key is already in the list, then ignore, otherwise append. + YES_PREPEND ///< Yes, always prepend the value to the start of the list and remove existing entries. +}; + +/// A list of RTFSprm with a copy constructor that performs a deep copy. +class RTFSprms : public virtual SvRefBase +{ +public: + using Pointer_t = tools::SvRef; + using Entry_t = std::pair; + using Iterator_t = std::vector::iterator; + using ReverseIterator_t = std::vector::reverse_iterator; + RTFSprms(); + ~RTFSprms() override; + + RTFSprms(RTFSprms const&) = default; + RTFSprms(RTFSprms&&) = default; + RTFSprms& operator=(RTFSprms const&) = default; + RTFSprms& operator=(RTFSprms&&) = default; + + RTFValue::Pointer_t find(Id nKeyword, bool bFirst = true, bool bForWrite = false); + /// Does the same as ->push_back(), except that it can overwrite or ignore existing entries. + void set(Id nKeyword, const RTFValue::Pointer_t& pValue, + RTFOverwrite eOverwrite = RTFOverwrite::YES); + bool erase(Id nKeyword); + void eraseLast(Id nKeyword); + /// Removes elements which are already in the reference set. + /// Also insert default values to override attributes of style + /// (yes, really; that's what Word does). + /// @param bImplicitPPr implicit dereference of top-level pPr SPRM + /// @param pDirect pointer to the root of the direct formatting SPRM tree, if any + RTFSprms cloneAndDeduplicate(RTFSprms& rReference, Id nStyleType, bool bImplicitPPr = false, + RTFSprms* pDirect = nullptr) const; + /// Inserts default values to override attributes of pAbstract. + void duplicateList(const RTFValue::Pointer_t& pAbstract); + /// Removes duplicated values based on in-list properties. + void deduplicateList(const std::map& rInvalidListLevelFirstIndents); + std::size_t size() const { return m_pSprms->size(); } + bool empty() const { return m_pSprms->empty(); } + Entry_t& back() { return m_pSprms->back(); } + Iterator_t begin() { return m_pSprms->begin(); } + Iterator_t end() { return m_pSprms->end(); } + void clear(); + bool equals(const RTFValue& rOther) const; + +private: + void ensureCopyBeforeWrite(); + tools::SvRef m_pSprms; +}; + +/// RTF keyword with a parameter +class RTFSprm : public Sprm +{ +public: + RTFSprm(Id nKeyword, RTFValue::Pointer_t& pValue); + sal_uInt32 getId() const override; + Value::Pointer_t getValue() override; + writerfilter::Reference::Pointer_t getProps() override; +#ifdef DBG_UTIL + std::string getName() const override; + std::string toString() const override; +#endif +private: + Id m_nKeyword; + RTFValue::Pointer_t& m_pValue; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFSPRM_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx new file mode 100644 index 000000000..5f5782cea --- /dev/null +++ b/writerfilter/source/rtftok/rtftokenizer.cxx @@ -0,0 +1,331 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtftokenizer.hxx" +#include +#include +#include +#include +#include +#include +#include +#include "rtfskipdestination.hxx" +#include +#include +#include +#include + +using namespace com::sun::star; + +namespace writerfilter::rtftok +{ +std::unordered_map RTFTokenizer::s_aRTFControlWords; +bool RTFTokenizer::s_bControlWordsInitialised; +std::vector RTFTokenizer::s_aRTFMathControlWords; +bool RTFTokenizer::s_bMathControlWordsSorted; + +RTFTokenizer::RTFTokenizer(RTFListener& rImport, SvStream* pInStream, + uno::Reference const& xStatusIndicator) + : m_rImport(rImport) + , m_pInStream(pInStream) + , m_xStatusIndicator(xStatusIndicator) + , m_nGroup(0) + , m_nLineNumber(0) + , m_nLineStartPos(0) + , m_nGroupStart(0) +{ + if (!RTFTokenizer::s_bControlWordsInitialised) + { + RTFTokenizer::s_bControlWordsInitialised = true; + for (int i = 0; i < nRTFControlWords; ++i) + s_aRTFControlWords.emplace(OString(aRTFControlWords[i].GetKeyword()), + aRTFControlWords[i]); + } + if (!RTFTokenizer::s_bMathControlWordsSorted) + { + RTFTokenizer::s_bMathControlWordsSorted = true; + s_aRTFMathControlWords = std::vector( + aRTFMathControlWords, aRTFMathControlWords + nRTFMathControlWords); + std::sort(s_aRTFMathControlWords.begin(), s_aRTFMathControlWords.end()); + } +} + +RTFTokenizer::~RTFTokenizer() = default; + +RTFError RTFTokenizer::resolveParse() +{ + SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC); + char ch; + RTFError ret; + // for hex chars + int b = 0; + int count = 2; + std::size_t nPercentSize = 0; + sal_uInt64 nLastPos = 0; + + if (m_xStatusIndicator.is()) + { + OUString sDocLoad(SvxResId(RID_SVXSTR_DOC_LOAD)); + + sal_uInt64 const nCurrentPos = Strm().Tell(); + sal_uInt64 const nEndPos = nCurrentPos + Strm().remainingSize(); + m_xStatusIndicator->start(sDocLoad, nEndPos); + nPercentSize = nEndPos / 100; + + nLastPos = nCurrentPos; + m_xStatusIndicator->setValue(nLastPos); + } + + while (Strm().ReadChar(ch), !Strm().eof()) + { + //SAL_INFO("writerfilter", OSL_THIS_FUNC << ": parsing character '" << ch << "'"); + + sal_uInt64 const nCurrentPos = Strm().Tell(); + if (m_xStatusIndicator.is() && nCurrentPos > (nLastPos + nPercentSize)) + { + nLastPos = nCurrentPos; + m_xStatusIndicator->setValue(nLastPos); + } + + if (m_nGroup < 0) + return RTFError::GROUP_UNDER; + if (m_nGroup > 0 && m_rImport.getInternalState() == RTFInternalState::BIN) + { + ret = m_rImport.resolveChars(ch); + if (ret != RTFError::OK) + return ret; + } + else + { + switch (ch) + { + case '{': + m_nGroupStart = Strm().Tell() - 1; + ret = m_rImport.pushState(); + if (ret != RTFError::OK) + return ret; + break; + case '}': + ret = m_rImport.popState(); + if (ret != RTFError::OK) + return ret; + if (m_nGroup == 0) + { + if (m_rImport.isSubstream()) + m_rImport.finishSubstream(); + return RTFError::OK; + } + break; + case '\\': + ret = resolveKeyword(); + if (ret != RTFError::OK) + return ret; + break; + case 0x0d: + break; // ignore this + case 0x0a: + m_nLineNumber++; + m_nLineStartPos = nCurrentPos; + break; + default: + if (m_nGroup == 0) + return RTFError::CHAR_OVER; + if (m_rImport.getInternalState() == RTFInternalState::NORMAL) + { + ret = m_rImport.resolveChars(ch); + if (ret != RTFError::OK) + return ret; + } + else + { + SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": hex internal state"); + b = b << 4; + sal_Int8 parsed = msfilter::rtfutil::AsHex(ch); + if (parsed == -1) + return RTFError::HEX_INVALID; + b += parsed; + count--; + if (!count) + { + ret = m_rImport.resolveChars(b); + if (ret != RTFError::OK) + return ret; + count = 2; + b = 0; + m_rImport.setInternalState(RTFInternalState::NORMAL); + } + } + break; + } + } + } + + if (m_nGroup < 0) + return RTFError::GROUP_UNDER; + if (m_nGroup > 0) + return RTFError::GROUP_OVER; + return RTFError::OK; +} + +void RTFTokenizer::pushGroup() { m_nGroup++; } + +void RTFTokenizer::popGroup() { m_nGroup--; } + +RTFError RTFTokenizer::resolveKeyword() +{ + char ch; + OStringBuffer aBuf(32); + bool bNeg = false; + bool bParam = false; + int nParam = 0; + + Strm().ReadChar(ch); + if (Strm().eof()) + return RTFError::UNEXPECTED_EOF; + + if (!rtl::isAsciiAlpha(static_cast(ch))) + { + aBuf.append(ch); + OString aKeyword = aBuf.makeStringAndClear(); + // control symbols aren't followed by a space, so we can return here + // without doing any SeekRel() + return dispatchKeyword(aKeyword, bParam, nParam); + } + while (rtl::isAsciiAlpha(static_cast(ch))) + { + aBuf.append(ch); + if (aBuf.getLength() > 32) + // See RTF spec v1.9.1, page 7 + // A control word's name cannot be longer than 32 letters. + throw io::BufferSizeExceededException(); + Strm().ReadChar(ch); + if (Strm().eof()) + { + ch = ' '; + break; + } + } + + if (ch == '-') + { + // in case we'll have a parameter, that will be negative + bNeg = true; + Strm().ReadChar(ch); + if (Strm().eof()) + return RTFError::UNEXPECTED_EOF; + } + if (rtl::isAsciiDigit(static_cast(ch))) + { + OStringBuffer aParameter; + + // we have a parameter + bParam = true; + while (rtl::isAsciiDigit(static_cast(ch))) + { + aParameter.append(ch); + Strm().ReadChar(ch); + if (Strm().eof()) + { + ch = ' '; + break; + } + } + nParam = aParameter.makeStringAndClear().toInt32(); + if (bNeg) + nParam = -nParam; + } + if (ch != ' ') + Strm().SeekRel(-1); + OString aKeyword = aBuf.makeStringAndClear(); + return dispatchKeyword(aKeyword, bParam, nParam); +} + +bool RTFTokenizer::lookupMathKeyword(RTFMathSymbol& rSymbol) +{ + auto low + = std::lower_bound(s_aRTFMathControlWords.begin(), s_aRTFMathControlWords.end(), rSymbol); + if (low == s_aRTFMathControlWords.end() || rSymbol < *low) + return false; + rSymbol = *low; + return true; +} + +RTFError RTFTokenizer::dispatchKeyword(OString const& rKeyword, bool bParam, int nParam) +{ + if (m_rImport.getDestination() == Destination::SKIP) + { + // skip binary data explicitly, to not trip over rtf markup + // control characters + if (rKeyword == "bin" && nParam > 0) + Strm().SeekRel(nParam); + return RTFError::OK; + } + SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": keyword '\\" << rKeyword << "' with param? " + << (bParam ? 1 : 0) << " param val: '" + << (bParam ? nParam : 0) << "'"); + auto findIt = s_aRTFControlWords.find(rKeyword); + if (findIt == s_aRTFControlWords.end()) + { + SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": unknown keyword '\\" << rKeyword << "'"); + RTFSkipDestination aSkip(m_rImport); + aSkip.setParsed(false); + return RTFError::OK; + } + + RTFError ret; + RTFSymbol const& rSymbol = findIt->second; + switch (rSymbol.GetControlType()) + { + case CONTROL_FLAG: + // flags ignore any parameter by definition + ret = m_rImport.dispatchFlag(rSymbol.GetIndex()); + if (ret != RTFError::OK) + return ret; + break; + case CONTROL_DESTINATION: + // same for destinations + ret = m_rImport.dispatchDestination(rSymbol.GetIndex()); + if (ret != RTFError::OK) + return ret; + break; + case CONTROL_SYMBOL: + // and symbols + ret = m_rImport.dispatchSymbol(rSymbol.GetIndex()); + if (ret != RTFError::OK) + return ret; + break; + case CONTROL_TOGGLE: + ret = m_rImport.dispatchToggle(rSymbol.GetIndex(), bParam, nParam); + if (ret != RTFError::OK) + return ret; + break; + case CONTROL_VALUE: + if (!bParam) + nParam = rSymbol.GetDefValue(); + ret = m_rImport.dispatchValue(rSymbol.GetIndex(), nParam); + if (ret != RTFError::OK) + return ret; + break; + } + + return RTFError::OK; +} + +OUString RTFTokenizer::getPosition() +{ + OUStringBuffer aRet; + aRet.append(m_nLineNumber + 1); + aRet.append(","); + aRet.append(sal_Int32(Strm().Tell() - m_nLineStartPos + 1)); + return aRet.makeStringAndClear(); +} + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtftokenizer.hxx b/writerfilter/source/rtftok/rtftokenizer.hxx new file mode 100644 index 000000000..5c1cd1949 --- /dev/null +++ b/writerfilter/source/rtftok/rtftokenizer.hxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX + +#include "rtflistener.hxx" + +#include +#include + +#include + +#include +#include + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace task +{ +class XStatusIndicator; +} +} +} +} +class SvStream; + +namespace writerfilter +{ +namespace rtftok +{ +/// RTF tokenizer that separates control words from text. +class RTFTokenizer final : public virtual SvRefBase +{ +public: + RTFTokenizer(RTFListener& rImport, SvStream* pInStream, + css::uno::Reference const& xStatusIndicator); + ~RTFTokenizer() override; + + RTFError resolveParse(); + /// Number of states on the stack. + int getGroup() const { return m_nGroup; } + /// To be invoked by the pushState() callback to signal when the importer enters a group. + void pushGroup(); + /// To be invoked by the popState() callback to signal when the importer leaves a group. + void popGroup(); + OUString getPosition(); + std::size_t getGroupStart() const { return m_nGroupStart; } + /// To look up additional properties of a math symbol. + static bool lookupMathKeyword(RTFMathSymbol& rSymbol); + +private: + SvStream& Strm() { return *m_pInStream; } + RTFError resolveKeyword(); + RTFError dispatchKeyword(OString const& rKeyword, bool bParam, int nParam); + + RTFListener& m_rImport; + SvStream* m_pInStream; + css::uno::Reference const& m_xStatusIndicator; + // This is the same as aRTFControlWords, but mapped by token name for fast lookup + static std::unordered_map s_aRTFControlWords; + static bool s_bControlWordsInitialised; + // This is the same as aRTFMathControlWords, but sorted + static std::vector s_aRTFMathControlWords; + static bool s_bMathControlWordsSorted; + /// Same as the size of the importer's states, except that this can be negative for invalid input. + int m_nGroup; + sal_Int32 m_nLineNumber; + std::size_t m_nLineStartPos; + std::size_t m_nGroupStart; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfvalue.cxx b/writerfilter/source/rtftok/rtfvalue.cxx new file mode 100644 index 000000000..e4b3a5a11 --- /dev/null +++ b/writerfilter/source/rtftok/rtfvalue.cxx @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "rtfreferenceproperties.hxx" +#include "rtfdocumentimpl.hxx" +#include + +using namespace com::sun::star; + +namespace writerfilter::rtftok +{ +RTFValue::RTFValue(int nValue, OUString sValue, const RTFSprms& rAttributes, const RTFSprms& rSprms, + uno::Reference xShape, uno::Reference xStream, + uno::Reference xObject, bool bForceString, + const RTFShape& aShape, const RTFPicture& rPicture) + : m_nValue(nValue) + , m_sValue(std::move(sValue)) + , m_pAttributes(new RTFSprms(rAttributes)) + , m_pSprms(new RTFSprms(rSprms)) + , m_xShape(std::move(xShape)) + , m_xStream(std::move(xStream)) + , m_xObject(std::move(xObject)) + , m_bForceString(bForceString) + , m_pShape(new RTFShape(aShape)) + , m_pPicture(new RTFPicture(rPicture)) +{ +} + +RTFValue::RTFValue() + : m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(int nValue) + : m_nValue(nValue) + , m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(OUString sValue, bool bForce) + : m_sValue(std::move(sValue)) + , m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_bForceString(bForce) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(const RTFSprms& rAttributes) + : m_pAttributes(new RTFSprms(rAttributes)) + , m_pSprms(new RTFSprms()) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(const RTFSprms& rAttributes, const RTFSprms& rSprms) + : m_pAttributes(new RTFSprms(rAttributes)) + , m_pSprms(new RTFSprms(rSprms)) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(uno::Reference xShape) + : m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_xShape(std::move(xShape)) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(uno::Reference xStream) + : m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_xStream(std::move(xStream)) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(uno::Reference xObject) + : m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_xObject(std::move(xObject)) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(const RTFShape& aShape) + : m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_pShape(new RTFShape(aShape)) + , m_pPicture(new RTFPicture) +{ +} + +RTFValue::RTFValue(const RTFPicture& rPicture) + : m_pAttributes(new RTFSprms()) + , m_pSprms(new RTFSprms()) + , m_pShape(new RTFShape()) + , m_pPicture(new RTFPicture(rPicture)) +{ +} + +RTFValue::~RTFValue() = default; + +int RTFValue::getInt() const { return m_nValue; } + +OUString RTFValue::getString() const +{ + if (!m_sValue.isEmpty() || m_bForceString) + return m_sValue; + + return OUString::number(m_nValue); +} + +void RTFValue::setString(const OUString& sValue) { m_sValue = sValue; } + +uno::Any RTFValue::getAny() const +{ + uno::Any ret; + if (!m_sValue.isEmpty() || m_bForceString) + ret <<= m_sValue; + else if (m_xShape.is()) + ret <<= m_xShape; + else if (m_xStream.is()) + ret <<= m_xStream; + else if (m_xObject.is()) + ret <<= m_xObject; + else + ret <<= static_cast(m_nValue); + return ret; +} + +RTFShape& RTFValue::getShape() const { return *m_pShape; } + +RTFPicture& RTFValue::getPicture() const { return *m_pPicture; } + +writerfilter::Reference::Pointer_t RTFValue::getProperties() +{ + return new RTFReferenceProperties(*m_pAttributes, *m_pSprms); +} + +writerfilter::Reference::Pointer_t RTFValue::getBinary() +{ + return writerfilter::Reference::Pointer_t(); +} + +#ifdef DBG_UTIL +std::string RTFValue::toString() const +{ + if (!m_sValue.isEmpty() || m_bForceString) + return OUStringToOString(m_sValue, RTL_TEXTENCODING_UTF8).getStr(); + + return OString::number(m_nValue).getStr(); +} +#endif + +RTFValue* RTFValue::Clone() +{ + return new RTFValue(m_nValue, m_sValue, *m_pAttributes, *m_pSprms, m_xShape, m_xStream, + m_xObject, m_bForceString, *m_pShape, *m_pPicture); +} + +RTFValue* RTFValue::CloneWithSprms(RTFSprms const& rAttributes, RTFSprms const& rSprms) +{ + return new RTFValue(m_nValue, m_sValue, rAttributes, rSprms, m_xShape, m_xStream, m_xObject, + m_bForceString, *m_pShape, *m_pPicture); +} + +bool RTFValue::equals(const RTFValue& rOther) const +{ + if (m_nValue != rOther.m_nValue) + return false; + if (m_sValue != rOther.m_sValue) + return false; + if (m_pAttributes->size() != rOther.m_pAttributes->size()) + return false; + if (!m_pAttributes->equals(rOther)) + return false; + if (m_pSprms->size() != rOther.m_pSprms->size()) + return false; + if (!m_pSprms->equals(rOther)) + return false; + return true; +} + +RTFSprms& RTFValue::getAttributes() { return *m_pAttributes; } + +RTFSprms& RTFValue::getSprms() { return *m_pSprms; } + +} // namespace writerfilter::rtftok + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfvalue.hxx b/writerfilter/source/rtftok/rtfvalue.hxx new file mode 100644 index 000000000..b1c22b0b9 --- /dev/null +++ b/writerfilter/source/rtftok/rtfvalue.hxx @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFVALUE_HXX +#define INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFVALUE_HXX + +#include + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace embed +{ +class XEmbeddedObject; +} +namespace io +{ +class XInputStream; +} +} +} +} + +namespace writerfilter +{ +namespace rtftok +{ +class RTFSprms; +class RTFShape; +class RTFPicture; +/// Value of an RTF keyword +class RTFValue : public Value +{ +public: + using Pointer_t = tools::SvRef; + RTFValue(int nValue, OUString sValue, const RTFSprms& rAttributes, const RTFSprms& rSprms, + css::uno::Reference xShape, + css::uno::Reference xStream, + css::uno::Reference xObject, bool bForceString, + const RTFShape& aShape, const RTFPicture& rPicture); + RTFValue(); + explicit RTFValue(int nValue); + RTFValue(OUString sValue, bool bForce = false); + explicit RTFValue(const RTFSprms& rAttributes); + RTFValue(const RTFSprms& rAttributes, const RTFSprms& rSprms); + explicit RTFValue(css::uno::Reference xShape); + explicit RTFValue(css::uno::Reference xStream); + explicit RTFValue(css::uno::Reference xObject); + explicit RTFValue(const RTFShape& aShape); + explicit RTFValue(const RTFPicture& rPicture); + ~RTFValue() override; + void setString(const OUString& sValue); + int getInt() const override; + OUString getString() const override; + css::uno::Any getAny() const override; + writerfilter::Reference::Pointer_t getProperties() override; + writerfilter::Reference::Pointer_t getBinary() override; +#ifdef DBG_UTIL + std::string toString() const override; +#endif + RTFValue* Clone(); + RTFValue* CloneWithSprms(RTFSprms const& rAttributes, RTFSprms const& rSprms); + RTFSprms& getAttributes(); + RTFSprms& getSprms(); + RTFShape& getShape() const; + RTFPicture& getPicture() const; + bool equals(const RTFValue& rOther) const; + RTFValue& operator=(RTFValue const& rOther) = delete; + +private: + int m_nValue = 0; + OUString m_sValue; + tools::SvRef m_pAttributes; + tools::SvRef m_pSprms; + css::uno::Reference m_xShape; + css::uno::Reference m_xStream; + css::uno::Reference m_xObject; + bool m_bForceString = false; + tools::SvRef m_pShape; + tools::SvRef m_pPicture; +}; +} // namespace rtftok +} // namespace writerfilter + +#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFVALUE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/util/writerfilter.component b/writerfilter/util/writerfilter.component new file mode 100644 index 000000000..63e5931e8 --- /dev/null +++ b/writerfilter/util/writerfilter.component @@ -0,0 +1,32 @@ + + + + + + + + + + + + + -- cgit v1.2.3