From 85818da3307a28b2d9c6fa5c1c97ca7833dfe24c Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Wed, 11 Jul 2018 22:37:00 +0300 Subject: tdf#106174 ww8import: bidi - prev adjust? prev bidi? Read_RTLJustify knows that it needs to swap in BiDi situations, but sometimes it is read before BiDi status is known. So Read_ParaBiDi needs to watch for this and do the swap afterwards. Three situations to handle: 1.) bidi same as previous setting: no adjust change 2.) no previous adjust: set appropriate default for this bidi 3.) previous adjust and bidi different from previous: swap adjusts (4. Unknown bidi treated like prev=LTR - one difference from DOCX) Unit tests cover both situations - where BiDi is already known, and where it is unknown. Change-Id: I0b4e2383a4909fe79317dd9772d0be63f749da68 Reviewed-on: https://gerrit.libreoffice.org/57294 Tested-by: Jenkins Reviewed-by: Justin Luth --- .../ww8export/data/tdf106174_rtlParaAlign.docx | Bin 0 -> 5266 bytes .../extras/ww8export/data/tdf98620_rtlJustify.doc | Bin 0 -> 9216 bytes sw/qa/extras/ww8export/ww8export2.cxx | 27 +++++++++++++++++++++ sw/source/filter/ww8/ww8par6.cxx | 27 +++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 sw/qa/extras/ww8export/data/tdf106174_rtlParaAlign.docx create mode 100644 sw/qa/extras/ww8export/data/tdf98620_rtlJustify.doc diff --git a/sw/qa/extras/ww8export/data/tdf106174_rtlParaAlign.docx b/sw/qa/extras/ww8export/data/tdf106174_rtlParaAlign.docx new file mode 100644 index 000000000000..a222f5881461 Binary files /dev/null and b/sw/qa/extras/ww8export/data/tdf106174_rtlParaAlign.docx differ diff --git a/sw/qa/extras/ww8export/data/tdf98620_rtlJustify.doc b/sw/qa/extras/ww8export/data/tdf98620_rtlJustify.doc new file mode 100644 index 000000000000..c643b96a4d3d Binary files /dev/null and b/sw/qa/extras/ww8export/data/tdf98620_rtlJustify.doc differ diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx index 91d1cdae23a3..d540cece3c6d 100644 --- a/sw/qa/extras/ww8export/ww8export2.cxx +++ b/sw/qa/extras/ww8export/ww8export2.cxx @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -253,6 +254,32 @@ DECLARE_WW8EXPORT_TEST(testTdf112074_RTLtableJustification, "tdf112074_RTLtableJ CPPUNIT_ASSERT_EQUAL_MESSAGE("Horizontal Orientation", text::HoriOrientation::LEFT_AND_WIDTH, getProperty(xTable, "HoriOrient")); CPPUNIT_ASSERT_MESSAGE("Table Indent", getProperty(xTable, "LeftMargin") > 3000); CPPUNIT_ASSERT_MESSAGE("Table Indent is 3750", getProperty(xTable, "LeftMargin") < 4000 ); + CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_RIGHT, static_cast(getProperty(getParagraphOrTable(2), "ParaAdjust")) ); +} + +DECLARE_WW8EXPORT_TEST(testTdf98620_rtlJustify, "tdf98620_rtlJustify.doc") +{ + CPPUNIT_ASSERT_EQUAL( style::ParagraphAdjust_RIGHT, static_cast(getProperty(getParagraph(1), "ParaAdjust")) ); +} + +DECLARE_WW8EXPORT_TEST(testTdf106174_rtlParaAlign, "tdf106174_rtlParaAlign.docx") +{ + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER), getProperty(getParagraph(1), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_CENTER), getProperty(getParagraph(2), "ParaAdjust")); + uno::Reference xPropertySet(getStyles("ParagraphStyles")->getByName("Another paragraph aligned to right"), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(xPropertySet, "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(getParagraph(3), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(getParagraph(4), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(getParagraph(5), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty(getParagraph(6), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(getParagraph(7), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(getParagraph(8), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty(getParagraph(9), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty(getParagraph(10), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(getParagraph(11), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty(getParagraph(12), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_LEFT), getProperty(getParagraph(13), "ParaAdjust")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(style::ParagraphAdjust_RIGHT), getProperty(getParagraph(14), "ParaAdjust")); } DECLARE_WW8EXPORT_TEST(testTdf104805, "tdf104805.doc") diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx index cfdef0182114..cc43a90d4077 100644 --- a/sw/source/filter/ww8/ww8par6.cxx +++ b/sw/source/filter/ww8/ww8par6.cxx @@ -318,6 +318,33 @@ void SwWW8ImplReader::Read_ParaBiDi(sal_uInt16, const sal_uInt8* pData, short nL { SvxFrameDirection eDir = *pData ? SvxFrameDirection::Horizontal_RL_TB : SvxFrameDirection::Horizontal_LR_TB; + + // Previous adjust or bidi values require changing paraAdjust. + // Only change if ParaBiDi doesn't match previous setting. + const bool bParentRTL = IsRightToLeft(); + if ( (eDir == SvxFrameDirection::Horizontal_RL_TB && !bParentRTL) || + (eDir == SvxFrameDirection::Horizontal_LR_TB && bParentRTL) ) + { + const SvxAdjustItem* pItem = static_cast(GetFormatAttr(RES_PARATR_ADJUST)); + if ( !pItem ) + { + // no previous adjust: set appropriate default + if ( eDir == SvxFrameDirection::Horizontal_LR_TB ) + NewAttr( SvxAdjustItem( SvxAdjust::Left, RES_PARATR_ADJUST ) ); + else + NewAttr( SvxAdjustItem( SvxAdjust::Right, RES_PARATR_ADJUST ) ); + } + else + { + // previous adjust and bidi has changed: swap Left/Right + const SvxAdjust eJustify = pItem->GetAdjust(); + if ( eJustify == SvxAdjust::Left ) + NewAttr( SvxAdjustItem( SvxAdjust::Right, RES_PARATR_ADJUST ) ); + else if ( eJustify == SvxAdjust::Right ) + NewAttr( SvxAdjustItem( SvxAdjust::Left, RES_PARATR_ADJUST ) ); + } + } + NewAttr(SvxFrameDirectionItem(eDir, RES_FRAMEDIR)); } } -- cgit v1.2.3