diff options
author | Jean-Sebastien Bevilacqua <realitix@gmail.com> | 2017-02-16 10:54:33 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-03-30 17:39:00 +0000 |
commit | c568eb7d3bb4584867f0a1f0a7965f73097f009b (patch) | |
tree | ea7e6fb1e0d77369a90bc69dd8756f589bb352e4 | |
parent | 53c2507bf97867011fd2bfbbac6c86b7fc494338 (diff) |
tdf#105975 Add Formula field parsing (docx) in SWriter
Introduction
------------
In MSWord, you can create a formula field (starting with =).
When you save your file as `docx`, this `FORMULA` field is registered
in you file (a field starting with `=`). In its current state,
LibreOffice can't parse the `FORMULA` field in `docx` file.
Context of this fix
-------------------
This fix is entirely located in the `DomainMapper_Impl.cxx` file
because it's where the parsing is done.
How this fix works
------------------
First, we add `FORMULA` support by adding it to the `aFields[]` variable.
Next, to handle the `FORMULA` constant, we add a condition (swith case) in
`DomainMapper_Impl::CloseFieldCommand()` to call `handleFieldFormula`.
Note
----
In function `lcl_ExtractToken`, if command starts with `=`, it's a
`FORMULA` field.
Change-Id: If7d25de5413aa3133b22523d8a3f34ab6961adfc
Reviewed-on: https://gerrit.libreoffice.org/34334
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r-- | sw/qa/extras/ooxmlimport/data/tdf105975.docx | bin | 0 -> 12754 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 17 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 31 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 |
4 files changed, 49 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/tdf105975.docx b/sw/qa/extras/ooxmlimport/data/tdf105975.docx Binary files differnew file mode 100644 index 000000000000..f9407df8889d --- /dev/null +++ b/sw/qa/extras/ooxmlimport/data/tdf105975.docx diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 7fb3871f32ed..208ed6370e7b 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -722,6 +722,23 @@ DECLARE_OOXMLIMPORT_TEST(testfdo76583, "fdo76583.docx") lcl_countTextFrames( mxComponent, 1 ); } +DECLARE_OOXMLIMPORT_TEST(testTdf105975formula, "tdf105975.docx") +{ + // Make sure the field contains a formula with 10 + 15 + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + + if( !xFields->hasMoreElements() ) { + CPPUNIT_ASSERT(false); + return; + } + + uno::Reference<text::XTextField> xEnumerationAccess(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("10+15"), xEnumerationAccess->getPresentation(true).trim()); + CPPUNIT_ASSERT_EQUAL(OUString("25"), xEnumerationAccess->getPresentation(false).trim()); +} + DECLARE_OOXMLIMPORT_TEST(testTdf75573, "tdf75573_page1frame.docx") { // the problem was that the frame was discarded diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 6189f9f139ab..0238820a2e12 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -2307,6 +2307,14 @@ static OUString lcl_ExtractToken(OUString const& rCommand, } } break; + case '=': + if (token.isEmpty()) + { + rHaveToken = true; + ++rIndex; + return OUString("FORMULA"); + } + break; default: token.append(currentChar); break; @@ -2837,7 +2845,7 @@ if(!bFilled) {OUString("FILLIN"), "Input", FIELD_FILLIN }, {OUString("FILENAME"), "FileName", FIELD_FILENAME }, // {OUString("FILESIZE"), "", FIELD_FILESIZE }, -// {OUString("FORMULA"), "", FIELD_FORMULA }, + {OUString("FORMULA"), "TableFormula", FIELD_FORMULA }, {OUString("FORMCHECKBOX"), "", FIELD_FORMCHECKBOX}, {OUString("FORMDROPDOWN"), "DropDown", FIELD_FORMDROPDOWN}, {OUString("FORMTEXT"), "Input", FIELD_FORMTEXT}, @@ -3007,6 +3015,23 @@ void DomainMapper_Impl::handleFieldAsk } } +void DomainMapper_Impl::handleFieldFormula + (const FieldContextPtr& pContext, + uno::Reference< beans::XPropertySet > const& xFieldProperties) +{ + OUString command = pContext->GetCommand().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 = command.copy(1); + sal_Int32 standardFormat = 0; + + xFieldProperties->setPropertyValue(getPropertyName(PROP_CONTENT), uno::makeAny(formula)); + xFieldProperties->setPropertyValue(getPropertyName(PROP_NUMBER_FORMAT), uno::makeAny(standardFormat)); + xFieldProperties->setPropertyValue("IsShowFormula", uno::makeAny(false)); +} void DomainMapper_Impl::handleRubyEQField( const FieldContextPtr& pContext) { @@ -3853,7 +3878,9 @@ void DomainMapper_Impl::CloseFieldCommand() } break; case FIELD_FILESIZE : break; - case FIELD_FORMULA : break; + case FIELD_FORMULA : + handleFieldFormula(pContext, xFieldProperties); + break; case FIELD_FORMCHECKBOX : case FIELD_FORMDROPDOWN : case FIELD_FORMTEXT : diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index f8924f1e75f4..18ccb047d94e 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -659,6 +659,9 @@ public: (const FieldContextPtr& pContext, css::uno::Reference< css::uno::XInterface > & xFieldInterface, css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties); + static void handleFieldFormula + (const FieldContextPtr& pContext, + css::uno::Reference< css::beans::XPropertySet > const& xFieldProperties); void handleAutoNum (const FieldContextPtr& pContext, css::uno::Reference< css::uno::XInterface > & xFieldInterface, |