sw/qa/extras/htmlexport/htmlexport.cxx | 27 +++++++++++++++++++++++++++ sw/source/filter/html/wrthtml.cxx | 11 +++++------ 2 files changed, 32 insertions(+), 6 deletions(-)
New commits: commit 2bd52c78a707d4229543e3b00e706176f7ca2367 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 11:31:10 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. (cherry picked from commit 89667371e2c773760e7f7496590f55e7da062cb7) Change-Id: I89a8b266d9a0f543f6022d82cf043bda4e6e639f diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index ccb45601d738..f55002c04a3d 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -2139,6 +2139,33 @@ 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: + loadURL("private:factory/swriter", nullptr); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc(); + 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 b665bd7bb503..4f003dbdc115 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()); }