summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-02-22 17:06:39 +0100
committerLuboš Luňák <l.lunak@collabora.com>2022-07-07 17:04:50 +0200
commit02516860272521f1bb83f4744d9ad5e2f6435f24 (patch)
tree0694c17a8270040e10ffec5c0a905315a07e2339
parentbafe6d1c933a6256a348e9a9d9c5b68cfd46887b (diff)
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 (cherry picked from commit 2bd52c78a707d4229543e3b00e706176f7ca2367)
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx27
-rw-r--r--sw/source/filter/html/wrthtml.cxx11
2 files changed, 32 insertions, 6 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 25583638aa44..af92c6e1859c 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1707,6 +1707,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 62e43946a49c..becaf51cbe83 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());
}