sw/qa/extras/htmlexport/htmlexport.cxx | 25 +++++++++++++++++++++++++ sw/source/filter/html/wrthtml.cxx | 11 +++++------ 2 files changed, 30 insertions(+), 6 deletions(-)
New commits: commit 89667371e2c773760e7f7496590f55e7da062cb7 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Feb 22 17:06:39 2022 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Feb 23 00:16:39 2022 +0100 sw HTML export: handle LeadingTabWidth without FilterOptions LeadingTabWidth is meant to be useful for plain HTML as well, but the old code only considered it when FilterOptions was set (typically to enable th XHTML mode). Thanks Stephan Bergmann for noticing that the u"" SAL_NEWLINE_STRING "\xa0\xa0 test" form would not work with MSVC. Change-Id: I89a8b266d9a0f543f6022d82cf043bda4e6e639f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130360 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index cf138cf56fd5..793e404e2dab 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -2155,6 +2155,31 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testLeadingTab) assertXPathContent(pXmlDoc, "//reqif-xhtml:p[3]", u"thi \t rd"); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testLeadingTabHTML) +{ + // Given a document with leading tabs: + SwDoc* pDoc = createSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert("\t test"); + + // When exporting to plain HTML, using LeadingTabWidth=2: + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("LeadingTabWidth", static_cast<sal_Int32>(2)), + }; + xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + + // Then make sure that leading tabs are replaced with 2 nbsps: + htmlDocUniquePtr pHtmlDoc = parseHtml(maTempFile); + CPPUNIT_ASSERT(pHtmlDoc); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: <newline><nbsp><nbsp><space>test + // - Actual : <newline><tab><space>test + // i.e. the leading tab was not replaced by 2 nbsps. + assertXPathContent(pHtmlDoc, "/html/body/p", SAL_NEWLINE_STRING u"\xa0\xa0 test"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index 2b0d8ca5ff7b..4d1be19b2fe7 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -187,12 +187,11 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium) return; const SfxPoolItem* pItem; - if (pSet->GetItemState( SID_FILE_FILTEROPTIONS, true, &pItem ) != SfxItemState::SET) - return; - - - const OUString sFilterOptions = static_cast<const SfxStringItem*>(pItem)->GetValue(); - SetupFilterOptions(sFilterOptions); + if (pSet->GetItemState(SID_FILE_FILTEROPTIONS, true, &pItem) == SfxItemState::SET) + { + const OUString sFilterOptions = static_cast<const SfxStringItem*>(pItem)->GetValue(); + SetupFilterOptions(sFilterOptions); + } SetupFilterFromPropertyValues(rMedium.GetArgs()); }