From 8af98ac8bf0ac8795999ecbf061d3c094f7c3be4 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 13 Feb 2019 14:01:57 +0100 Subject: sw btlr writing mode: implement ODF filter An easy way would be to just extend aXML_WritingDirection_Enum, but then we would write the new attribute value to a non-extension namespace. So special case the new attribute value during both import and export (and only for table cells as a start). Change-Id: I431bf99693c4a3452e91f241bd2f0fcfc72c68fd Reviewed-on: https://gerrit.libreoffice.org/67770 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- include/xmloff/xmltoken.hxx | 1 + .../OpenDocument-schema-v1.3+libreoffice.rng | 11 ++++++ sw/qa/extras/odfexport/data/btlr-cell.odt | Bin 0 -> 9174 bytes sw/qa/extras/odfexport/odfexport.cxx | 20 ++++++++++ sw/source/filter/xml/xmlexpit.cxx | 44 ++++++++++++++++----- sw/source/filter/xml/xmlimpit.cxx | 29 ++++++++++---- sw/source/filter/xml/xmlitemm.cxx | 1 + xmloff/source/core/xmltoken.cxx | 1 + xmloff/source/token/tokens.txt | 1 + 9 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 sw/qa/extras/odfexport/data/btlr-cell.odt diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index 01467992f3d2..69ef7e889455 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -2183,6 +2183,7 @@ namespace xmloff { namespace token { XML_RL_TB, XML_TB_LR, + XML_BT_LR, XML_LR, XML_RL, XML_TB, diff --git a/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng b/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng index d59314e99771..956ccc2f02e4 100644 --- a/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng +++ b/schema/libreoffice/OpenDocument-schema-v1.3+libreoffice.rng @@ -2323,6 +2323,17 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. + + + + + + bt-lr + + + + + diff --git a/sw/qa/extras/odfexport/data/btlr-cell.odt b/sw/qa/extras/odfexport/data/btlr-cell.odt new file mode 100644 index 000000000000..c010fa9f51b6 Binary files /dev/null and b/sw/qa/extras/odfexport/data/btlr-cell.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 337c64270a04..8ac8f1c81edd 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1391,6 +1392,25 @@ DECLARE_ODFEXPORT_TEST(testWhitespace, "whitespace.odt") CPPUNIT_ASSERT(!xPortions->hasMoreElements()); } +DECLARE_ODFEXPORT_TEST(testBtlrCell, "btlr-cell.odt") +{ + // Without the accompanying fix in place, this test would have failed, as + // the btlr text direction in the A1 cell was lost on ODF import and + // export. + uno::Reference xSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables = xSupplier->getTextTables(); + uno::Reference xTable(xTables->getByName("Table1"), uno::UNO_QUERY); + uno::Reference xA1(xTable->getCellByName("A1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(text::WritingMode2::BT_LR, getProperty(xA1, "WritingMode")); + + uno::Reference xB1(xTable->getCellByName("B1"), uno::UNO_QUERY); + auto nActual = getProperty(xB1, "WritingMode"); + CPPUNIT_ASSERT(nActual == text::WritingMode2::LR_TB || nActual == text::WritingMode2::CONTEXT); + + uno::Reference xC1(xTable->getCellByName("C1"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(text::WritingMode2::TB_RL, getProperty(xC1, "WritingMode")); +} + DECLARE_ODFEXPORT_TEST(testFdo86963, "fdo86963.odt") { // Export of this document failed with beans::UnknownPropertyException. diff --git a/sw/source/filter/xml/xmlexpit.cxx b/sw/source/filter/xml/xmlexpit.cxx index 989602e666b6..8b09189ba403 100644 --- a/sw/source/filter/xml/xmlexpit.cxx +++ b/sw/source/filter/xml/xmlexpit.cxx @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -197,16 +198,41 @@ void SvXMLExportItemMapper::exportXML( const SvXMLExport& rExport, } else if( 0 == (rEntry.nMemberId & MID_SW_FLAG_ELEMENT_ITEM_EXPORT) ) { - OUString aValue; - if( QueryXMLValue(rItem, aValue, - static_cast< sal_uInt16 >( - rEntry.nMemberId & MID_SW_FLAG_MASK ), - rUnitConverter ) ) + bool bDone = false; + switch (rItem.Which()) { - const OUString sName( - rNamespaceMap.GetQNameByKey( rEntry.nNameSpace, - GetXMLToken(rEntry.eLocalName))); - rAttrList.AddAttribute( sName, aValue ); + case RES_FRAMEDIR: + { + // Write bt-lr to the extension namespace, handle other values + // below. + auto pDirection = static_cast(&rItem); + if (rEntry.nNameSpace == XML_NAMESPACE_LO_EXT + && pDirection->GetValue() == SvxFrameDirection::Vertical_LR_BT) + { + const OUString sName(rNamespaceMap.GetQNameByKey( + XML_NAMESPACE_LO_EXT, GetXMLToken(XML_WRITING_MODE))); + rAttrList.AddAttribute(sName, GetXMLToken(XML_BT_LR)); + } + if (rEntry.nNameSpace == XML_NAMESPACE_LO_EXT + || pDirection->GetValue() == SvxFrameDirection::Vertical_LR_BT) + bDone = true; + break; + } + } + + if (!bDone) + { + OUString aValue; + if( QueryXMLValue(rItem, aValue, + static_cast< sal_uInt16 >( + rEntry.nMemberId & MID_SW_FLAG_MASK ), + rUnitConverter ) ) + { + const OUString sName( + rNamespaceMap.GetQNameByKey( rEntry.nNameSpace, + GetXMLToken(rEntry.eLocalName))); + rAttrList.AddAttribute( sName, aValue ); + } } } } diff --git a/sw/source/filter/xml/xmlimpit.cxx b/sw/source/filter/xml/xmlimpit.cxx index 1e921ac9dce6..0ba10f9cfd25 100644 --- a/sw/source/filter/xml/xmlimpit.cxx +++ b/sw/source/filter/xml/xmlimpit.cxx @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,7 @@ #include #include "xmlithlp.hxx" #include +#include using ::editeng::SvxBorderLine; using namespace ::com::sun::star; @@ -905,14 +907,25 @@ bool SvXMLImportItemMapper::PutXMLValue( case RES_FRAMEDIR: { - std::unique_ptr pWritingModeHandler = - XMLPropertyHandlerFactory::CreatePropertyHandler( - XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT ); - Any aAny; - bOk = pWritingModeHandler->importXML( rValue, aAny, - rUnitConverter ); - if( bOk ) - bOk = rItem.PutValue( aAny, 0 ); + if (IsXMLToken(rValue, XML_BT_LR)) + { + // Read bt-lr from the extension namespace, handle other values + // below. + Any aAny; + aAny <<= static_cast(SvxFrameDirection::Vertical_LR_BT); + bOk = rItem.PutValue(aAny, 0); + } + else + { + std::unique_ptr pWritingModeHandler = + XMLPropertyHandlerFactory::CreatePropertyHandler( + XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT ); + Any aAny; + bOk = pWritingModeHandler->importXML( rValue, aAny, + rUnitConverter ); + if( bOk ) + bOk = rItem.PutValue( aAny, 0 ); + } } break; diff --git a/sw/source/filter/xml/xmlitemm.cxx b/sw/source/filter/xml/xmlitemm.cxx index 417e0a5d96c1..0757bdd57604 100644 --- a/sw/source/filter/xml/xmlitemm.cxx +++ b/sw/source/filter/xml/xmlitemm.cxx @@ -282,6 +282,7 @@ SvXMLItemMapEntry const aXMLTableCellItemMap[] = // RES_FRAMEDIR MAP_ENTRY( STYLE, WRITING_MODE, RES_FRAMEDIR, 0 ), + MAP_ENTRY( LO_EXT, WRITING_MODE, RES_FRAMEDIR, 0 ), M_END }; diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index dc546397523c..1daa8897649d 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -2187,6 +2187,7 @@ namespace xmloff { namespace token { TOKEN( "rl-tb", XML_RL_TB ), TOKEN( "tb-lr", XML_TB_LR ), + TOKEN( "bt-lr", XML_BT_LR ), TOKEN( "lr", XML_LR ), TOKEN( "rl", XML_RL ), TOKEN( "tb", XML_TB ), diff --git a/xmloff/source/token/tokens.txt b/xmloff/source/token/tokens.txt index baef6b3a31a1..ce472bc62c7a 100644 --- a/xmloff/source/token/tokens.txt +++ b/xmloff/source/token/tokens.txt @@ -2089,6 +2089,7 @@ stock-gain-marker stock-range-line rl-tb tb-lr +bt-lr lr rl tb -- cgit