summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-07-21 15:40:58 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-07-22 14:55:05 +0200
commit12269c021e785b8dca7e57a378d02023f7863d62 (patch)
treed60a7c4c63bfd594bbfc261f698a2e2fd06544b3
parent385dac7edebeb391df740aa94752f14834827f8d (diff)
sw XHTML export: fix writing of section direction
The XHTML export behavior was the same as the HTML one for section text direction, the <div dir="..."> markup was used. This shares code with the HTML filter, but it's not valid in reqif-xhtml, while the CSS markup would be fine: <div style="dir: ...">. Fix the problem by keeping the behavior unchanged for HTML, but switch to inline CSS for XHTML. The other similar attribute was "id", but that's fine even in XHTML. (cherry picked from commit 3b7c18a579f3165c9d425d172d697f8978d6cd84) Conflicts: sw/qa/extras/htmlexport/htmlexport.cxx Change-Id: I5797c90f9cf957dec7fc4074dd6e79dce11fada7
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx24
-rw-r--r--sw/source/filter/html/css1atr.cxx11
-rw-r--r--sw/source/filter/html/css1kywd.cxx1
-rw-r--r--sw/source/filter/html/css1kywd.hxx1
-rw-r--r--sw/source/filter/html/wrthtml.cxx7
5 files changed, 42 insertions, 2 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index af92c6e1859c..7e674160c4f8 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1734,6 +1734,30 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testLeadingTabHTML)
assertXPathContent(pHtmlDoc, "/html/body/p", SAL_NEWLINE_STRING u"\xa0\xa0 test");
}
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSectionDir)
+{
+ // Given a document with a section:
+ loadURL("private:factory/swriter", nullptr);
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+ pWrtShell->Insert("test");
+ pWrtShell->SelAll();
+ SwSectionData aSectionData(SectionType::Content, "mysect");
+ pWrtShell->InsertSection(aSectionData);
+
+ // When exporting to (reqif-)xhtml:
+ ExportToReqif();
+
+ // Then make sure CSS is used to export the text direction of the section:
+ SvMemoryStream aStream;
+ HtmlExportTest::wrapFragment(maTempFile, aStream);
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - XPath '//reqif-xhtml:div[@id='mysect']' no attribute 'style' exist
+ // i.e. the dir="ltr" HTML attribute was used instead.
+ assertXPath(pXmlDoc, "//reqif-xhtml:div[@id='mysect']", "style", "dir: ltr");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/css1atr.cxx b/sw/source/filter/html/css1atr.cxx
index 18ee264324f6..8a0bc881e1c8 100644
--- a/sw/source/filter/html/css1atr.cxx
+++ b/sw/source/filter/html/css1atr.cxx
@@ -2143,6 +2143,17 @@ void SwHTMLWriter::OutCSS1_SectionFormatOptions( const SwFrameFormat& rFrameForm
if( SfxItemState::SET==rItemSet.GetItemState( RES_BACKGROUND, false, &pItem ) )
OutCSS1_SvxBrush( *this, *pItem, sw::Css1Background::Section, nullptr );
+ if (mbXHTML)
+ {
+ SvxFrameDirection nDir = GetHTMLDirection(rFrameFormat.GetAttrSet());
+ OString sConvertedDirection = convertDirection(nDir);
+ if (!sConvertedDirection.isEmpty())
+ {
+ OutCSS1_Property(sCSS1_P_dir, sConvertedDirection.getStr(), nullptr,
+ sw::Css1Background::Section);
+ }
+ }
+
if (pCol)
{
OString sColumnCount(OString::number(static_cast<sal_Int32>(pCol->GetNumCols())));
diff --git a/sw/source/filter/html/css1kywd.cxx b/sw/source/filter/html/css1kywd.cxx
index f8914dedb274..c0299e28c958 100644
--- a/sw/source/filter/html/css1kywd.cxx
+++ b/sw/source/filter/html/css1kywd.cxx
@@ -197,6 +197,7 @@ const char* const sCSS1_P_height = "height";
const char* const sCSS1_P_float = "float";
const char* const sCSS1_P_column_count = "column-count";
+const char* const sCSS1_P_dir = "dir";
// Strings for positioning
diff --git a/sw/source/filter/html/css1kywd.hxx b/sw/source/filter/html/css1kywd.hxx
index 7c0e326fd86a..c4609c5659b1 100644
--- a/sw/source/filter/html/css1kywd.hxx
+++ b/sw/source/filter/html/css1kywd.hxx
@@ -200,6 +200,7 @@ extern const char* const sCSS1_P_height;
extern const char* const sCSS1_P_float;
extern const char* const sCSS1_P_column_count;
+extern const char* const sCSS1_P_dir;
// Strings for positioning
diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index 995b1a291f3e..b8a48c2918f3 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -701,9 +701,12 @@ static void lcl_html_OutSectionStartTag( SwHTMLWriter& rHTMLWrt,
sOut.append('\"');
}
- SvxFrameDirection nDir = rHTMLWrt.GetHTMLDirection( rFormat.GetAttrSet() );
rHTMLWrt.Strm().WriteOString( sOut.makeStringAndClear() );
- rHTMLWrt.OutDirection( nDir );
+ if (!rHTMLWrt.mbXHTML)
+ {
+ SvxFrameDirection nDir = rHTMLWrt.GetHTMLDirection(rFormat.GetAttrSet());
+ rHTMLWrt.OutDirection(nDir);
+ }
if( SectionType::FileLink == rSection.GetType() )
{