diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-04-23 17:55:34 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-04-23 20:19:52 +0200 |
commit | 9d38360e2ed06b2083d56b637f009411d41f36eb (patch) | |
tree | 5c545f03d4e81c7cb64344f2414c77c81f86ec89 | |
parent | 26ada4335a5804735ae37cf9a89f8145e0931fd7 (diff) |
sw html export: fix handling of paragraph alignment in XHTML mode
The problem was that the <p align="..."> markup was used, while XHTML
prefers the <p style="text-align: ..."> markup. Note that
OutHTML_SvxAdjust() is a special case: other paragraph-level pool items
would just call the equivalent of OutCSS1_SvxAdjust().
Fix the problem by bringing the paragraph alignment case close to e.g.
SvxULSpace handling, which is the m_bNoAlign == true case.
On top of this the reqif-xhtml output is then valid out of the box,
since IgnorePropertyForReqIF() already filters out not allowed CSS
properties.
Change-Id: I5fb4314bec172affcd03b1c49b986406a93c2b12
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92797
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 29 | ||||
-rw-r--r-- | sw/source/filter/html/htmlatr.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.cxx | 5 |
3 files changed, 40 insertions, 0 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index ab1aaf366818..4967975f1caa 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/frame/XDispatchHelper.hpp> #include <com/sun/star/frame/DispatchHelper.hpp> +#include <com/sun/star/style/ParagraphAdjust.hpp> #include <svtools/htmlcfg.hxx> #include <swmodule.hxx> @@ -854,6 +855,34 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifFontNameSize) assertXPath(pDoc, "//reqif-xhtml:span", 1); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifParagraphAlignment) +{ + // Create a document with an explicitly aligned paragraph. + loadURL("private:factory/swriter", nullptr); + uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), uno::UNO_QUERY); + xParagraph->setPropertyValue( + "ParaAdjust", uno::makeAny(static_cast<sal_Int16>(style::ParagraphAdjust_RIGHT))); + + // Export it. + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), + }; + xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + SvMemoryStream aStream; + HtmlExportTest::wrapFragment(maTempFile, aStream); + xmlDocPtr pDoc = parseXmlStream(&aStream); + + // Make sure the output is well-formed. + CPPUNIT_ASSERT(pDoc); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: + // - Actual : right + // i.e. the <reqif-xhtml:p align="..."> markup was used, which is invalid. + assertXPathNoAttribute(pDoc, "//reqif-xhtml:p", "align"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index f7dd8ac111e5..9bee7fc22157 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -438,6 +438,12 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, bool bNoEndTag = false; // don't output an end tag rHWrt.m_bNoAlign = false; // no ALIGN=... possible + + if (rHWrt.mbXHTML) + { + rHWrt.m_bNoAlign = true; + } + sal_uInt8 nBulletGrfLvl = 255; // The bullet graphic we want to output // Are we in a bulleted or numbered list? diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index f5c287644b39..a5cad5df2c57 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -163,6 +163,11 @@ SwHTMLWriter::SwHTMLWriter( const OUString& rBaseURL, const OUString& rFilterOpt } SetupFilterOptions(rFilterOptions); + + if (mbXHTML) + { + m_bNoAlign = true; + } } SwHTMLWriter::~SwHTMLWriter() |