sw/qa/extras/ooxmlexport/data/tdf148380_usernameField.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport17.cxx | 13 +++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-)
New commits: commit f56f8be65b26cb3c8e83af05f10ba9f717ff76b2 Author: Justin Luth <justin_l...@sil.org> AuthorDate: Fri Apr 22 19:46:16 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Apr 29 12:25:01 2022 +0200 tdf#126636 writerfilter: import USERNAME field as fixed This depends on and mimics some of the fixes for tdf#148380. Microsoft Word doesn't immediately/automatically update field contents like LO does. Instead, the user needs to press F9 on each field. So, these USERNAME or USERINITIALS fields just show the when-last-updated text that was saved in the document instead of the actual current value of the field. Although LO doesn't have that ability, we can flag them as FIXED and achieve a very similar result. Doing so fixes this bug report which might be quite common since USERNAME might be mistaken for AUTHOR or LASTSAVEDBY by the user - since in practice they tend to be the same thing. We already did this for AUTHOR (which is extremely safe since that can never change). I almost hate to do it with this one because even this bug shows it is too often a case of mis-use, but that is the way it is, and this seems to be the best solution. Change-Id: I48dc6d45992aff740023e80f619b56ad01231782 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133346 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/data/tdf148380_usernameField.docx b/sw/qa/extras/ooxmlexport/data/tdf148380_usernameField.docx new file mode 100644 index 000000000000..241632bc80e9 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf148380_usernameField.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx index f03901f5180d..bbbc8e7cfb73 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx @@ -104,6 +104,19 @@ DECLARE_OOXMLEXPORT_TEST(testTdf148380_fldLocked, "tdf148380_fldLocked.docx") CPPUNIT_ASSERT_EQUAL(OUString("DocInformation:Last printed (fixed)"), xField->getPresentation(true)); } +DECLARE_OOXMLEXPORT_TEST(testTdf148380_usernameField, "tdf148380_usernameField.docx") +{ + // Verify that these are fields, and not just plain text + uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY); + auto xFieldsAccess(xTextFieldsSupplier->getTextFields()); + uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration()); + uno::Reference<text::XTextField> xField(xFields->nextElement(), uno::UNO_QUERY); + // These should match the as-last-seen-in-the-text name, and not the application's user name + CPPUNIT_ASSERT_EQUAL(OUString("Charlie Brown"), xField->getPresentation(false)); + xField.set(xFields->nextElement(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(OUString("CB"), xField->getPresentation(false)); +} + DECLARE_OOXMLEXPORT_TEST(testTdf148380_modifiedField, "tdf148380_modifiedField.docx") { getParagraph(2, "4/5/2022 3:29:00 PM"); // default (unspecified) date format diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 2d956b5ab09c..b59b9eac066f 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -5547,7 +5547,7 @@ void DomainMapper_Impl::handleAutoNum } void DomainMapper_Impl::handleAuthor - (std::u16string_view rFirstParam, + (std::u16string_view, uno::Reference< beans::XPropertySet > const& xFieldProperties, FieldId eFieldId ) { @@ -5555,7 +5555,9 @@ void DomainMapper_Impl::handleAuthor xFieldProperties->setPropertyValue ( getPropertyName(PROP_FULL_NAME), uno::makeAny( true )); - if (!rFirstParam.empty() || eFieldId == FIELD_AUTHOR) + // Always set as FIXED b/c MS Word only updates these fields via user intervention (F9) + // AUTHOR of course never changes and USERNAME is easily mis-used as an original author field. + // Additionally, this was forced as fixed if any special case-formatting was provided. { xFieldProperties->setPropertyValue( getPropertyName( PROP_IS_FIXED ),