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 13:22:34 +0200
commit7a8665b51f911835a593cfe754c3e10b6cdab662 (patch)
tree0f33107e309b1a3c8ed9f5ea4c1072d374933b69
parenta6320fb1d157f94e3e1265e19a72de1022be98f7 (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) 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 1d03d107fd09..851d8409b549 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2286,6 +2286,30 @@ CPPUNIT_TEST_FIXTURE(HtmlExportTest, testImageKeepRatio)
assertXPath(pDoc, "/html/body/p/img", "height", "auto");
}
+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 238dbf36060a..8aeaf9c32fac 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -715,9 +715,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() )
{