diff options
author | László Németh <nemeth@numbertext.org> | 2021-10-01 17:42:48 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2021-10-04 08:22:23 +0200 |
commit | 05f92eb1359c399c43d3bcbe8942034408fa23eb (patch) | |
tree | 84e4c5fcdd8f8fd84f25160db52b17dd64e0a50f /writerfilter | |
parent | f8e086f185b31f753074fd22ecc73c44b193a784 (diff) |
tdf#77051 DOCX: fix user index and index entry support
defined by field code \f.
E.g. INDEX \f "user-index" inserts only the entries
defined by XE "entry" \f "user-index" field codes.
Revert commit a7bc9c1e4977bd3430df69287fa0a8377a686c58
"fdo#77051: Preservation of Index field flag '\f'", which
added an undocumented UNO property only for round-trip
support of INDEX, but not for XE index entries, so the
DOCX export still resulted a broken index with lost
entries, not only the import was broken because of the
missing functionality in com.sun.star.text.DocumentIndex.
Now the import uses com.sun.star.text.UserIndex and
com.sun.star.text.UserIndexMark index and index entry
fields, which support the requested user index not
only during the DOCX and OpenDocument round-trip, but
its run-time functionality, the multiple user-defined
indices.
Note: for manual testing, update the user index (the
first index) of the left original unit test document
IndexFieldFlagF.docx: the updated index is not empty,
as before, but contains the user index entries.
Change-Id: Ia6139bba88907051fd050cfd40809f5544b9a89e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122930
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 46 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyIds.cxx | 1 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyIds.hxx | 1 |
3 files changed, 36 insertions, 12 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index f11add33d7ca..644beef21e06 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -4165,6 +4165,12 @@ static bool lcl_FindInCommand( return bRet; } +static OUString lcl_trim(OUString& sValue) +{ + // it seems, all kind of quotation marks are allowed around index type identifiers + // TODO apply this on bookmarks, too, if needed + return sValue.trim().replaceAll("\"","").replaceAll(u"“", "").replaceAll(u"”", ""); +} void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale) { @@ -5629,15 +5635,21 @@ void DomainMapper_Impl::handleIndex (const FieldContextPtr& pContext, const OUString & sTOCServiceName) { + // only UserIndex can handle user index defined by \f + // e.g. INDEX \f "user-index-id" + OUString sUserIndex; + if ( lcl_FindInCommand( pContext->GetCommand(), 'f', sUserIndex ) ) + sUserIndex = lcl_trim(sUserIndex); + // Create section before setting m_bStartTOC and m_bStartIndex: finishing paragraph // inside StartIndexSectionChecked could do the wrong thing otherwise - const auto xTOC = StartIndexSectionChecked(sTOCServiceName); + const auto xTOC = StartIndexSectionChecked( sUserIndex.isEmpty() + ? sTOCServiceName + : "com.sun.star.text.UserIndex"); 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())); @@ -5650,11 +5662,9 @@ void DomainMapper_Impl::handleIndex { xTOC->setPropertyValue("UseAlphabeticalSeparators", uno::makeAny(true)); } - if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue )) + if( !sUserIndex.isEmpty() ) { - if(!sValue.isEmpty()) - sIndexEntryType = sValue ; - xTOC->setPropertyValue(getPropertyName( PROP_INDEX_ENTRY_TYPE ), uno::makeAny(sIndexEntryType)); + xTOC->setPropertyValue("UserIndexName", uno::makeAny(sUserIndex)); } } pContext->SetTOC( xTOC ); @@ -6425,15 +6435,31 @@ void DomainMapper_Impl::CloseFieldCommand() if( !m_xTextFactory.is() ) break; + // only UserIndexMark can handle user index types defined by \f + // e.g. XE "text" \f "user-index-id" + OUString sUserIndex; + OUString sFieldServiceName = + lcl_FindInCommand( pContext->GetCommand(), 'f', sUserIndex ) + ? "com.sun.star.text.UserIndexMark" + : OUString::createFromAscii(aIt->second.cFieldServiceName); uno::Reference< beans::XPropertySet > xTC( - m_xTextFactory->createInstance( - OUString::createFromAscii(aIt->second.cFieldServiceName)), + m_xTextFactory->createInstance(sFieldServiceName), uno::UNO_QUERY_THROW); + if (!sFirstParam.isEmpty()) { - xTC->setPropertyValue("PrimaryKey", + xTC->setPropertyValue(sUserIndex.isEmpty() + ? OUString("PrimaryKey") + : OUString("AlternativeText"), uno::makeAny(sFirstParam)); } + + sUserIndex = lcl_trim(sUserIndex); + if (!sUserIndex.isEmpty()) + { + xTC->setPropertyValue("UserIndexName", + uno::makeAny(sUserIndex)); + } uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY ); uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend; if (xTextAppend.is()) diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx index 00d5b795b132..b339a83f8ae6 100644 --- a/writerfilter/source/dmapper/PropertyIds.cxx +++ b/writerfilter/source/dmapper/PropertyIds.cxx @@ -331,7 +331,6 @@ OUString getPropertyName( PropertyIds eId ) 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; diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx index 8e23533c57ba..b09170d2da36 100644 --- a/writerfilter/source/dmapper/PropertyIds.hxx +++ b/writerfilter/source/dmapper/PropertyIds.hxx @@ -334,7 +334,6 @@ enum PropertyIds ,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 |