sw/CppunitTest_sw_writerfilter_filter.mk | 59 ++++++++++ sw/Module_sw.mk | 1 sw/qa/writerfilter/cppunittests/filter/WriterFilter.cxx | 57 +++++++++ sw/qa/writerfilter/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx |binary sw/source/writerfilter/filter/WriterFilter.cxx | 1 5 files changed, 118 insertions(+)
New commits: commit 01dcc9a652ecfc65fb674b492afa6f58b0a846db Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu May 2 08:42:25 2024 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu May 2 12:08:31 2024 +0200 tdf#160833 DOCX import: use the DoNotMirrorRtlDrawObjs compat flag The bugdoc has a shape which should be on the right page margin, but it was on the left page margin. Use the new compat flag to have a layout that matches Word. This way we don't need to unmap the tweaked position at export time (a limitation that the DOC filter has). Change-Id: I38dfae370f275d9f0897198e7b0569f2d91dd352 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166993 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/CppunitTest_sw_writerfilter_filter.mk b/sw/CppunitTest_sw_writerfilter_filter.mk new file mode 100644 index 000000000000..ad61c66f1ed4 --- /dev/null +++ b/sw/CppunitTest_sw_writerfilter_filter.mk @@ -0,0 +1,59 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sw_writerfilter_filter)) + +$(eval $(call gb_CppunitTest_use_externals,sw_writerfilter_filter,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sw_writerfilter_filter, \ + sw/qa/writerfilter/cppunittests/filter/WriterFilter \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sw_writerfilter_filter, \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + oox \ + sal \ + subsequenttest \ + test \ + unotest \ + utl \ + tl \ + vcl \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,sw_writerfilter_filter)) + +$(eval $(call gb_CppunitTest_use_ure,sw_writerfilter_filter)) +$(eval $(call gb_CppunitTest_use_vcl,sw_writerfilter_filter)) + +$(eval $(call gb_CppunitTest_use_rdb,sw_writerfilter_filter,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,sw_writerfilter_filter,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sw_writerfilter_filter)) + +# we need to explicitly depend on library sw_writerfilter because it is not implied +# by a link relation +$(call gb_CppunitTest_get_target,sw_writerfilter_filter) : $(call gb_Library_get_target,sw_writerfilter) + +ifneq ($(filter MORE_FONTS,$(BUILD_TYPE)),) +$(eval $(call gb_CppunitTest_set_non_application_font_use,sw_writerfilter_filter,abort)) +endif + +# vim: set noet sw=4 ts=4: diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk index 3fcd0f85ed56..fc2afe9fb7d9 100644 --- a/sw/Module_sw.mk +++ b/sw/Module_sw.mk @@ -175,6 +175,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\ CppunitTest_sw_writerfilter_dmapper \ CppunitTest_sw_writerfilter_ooxml \ CppunitTest_sw_writerfilter_rtftok \ + CppunitTest_sw_writerfilter_filter \ )) ifneq ($(DISABLE_GUI),TRUE) diff --git a/sw/qa/writerfilter/cppunittests/filter/WriterFilter.cxx b/sw/qa/writerfilter/cppunittests/filter/WriterFilter.cxx new file mode 100644 index 000000000000..10b8cab57a45 --- /dev/null +++ b/sw/qa/writerfilter/cppunittests/filter/WriterFilter.cxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <test/unoapixml_test.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/drawing/ColorMode.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/qa/XDumper.hpp> + +using namespace ::com::sun::star; + +namespace +{ +/// Tests for sw/source/writerfilter/filter/WriterFilter.cxx. +class Test : public UnoApiXmlTest +{ +public: + Test() + : UnoApiXmlTest("/sw/qa/writerfilter/cppunittests/filter/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(Test, testDoNotMirrorRtlDrawObjs) +{ + // Given a document with a shape, anchored in an RTL paragraph: + // When loading that document: + loadFromFile(u"draw-obj-rtl-no-mirror.docx"); + + // Then make sure the shape is on the right margin: + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + css::uno::Reference<qa::XDumper> xDumper(xModel->getCurrentController(), uno::UNO_QUERY); + OString aDump = xDumper->dump("layout").toUtf8(); + auto pCharBuffer = reinterpret_cast<const xmlChar*>(aDump.getStr()); + xmlDocUniquePtr pXmlDoc(xmlParseDoc(pCharBuffer)); + sal_Int32 nBodyRight = getXPath(pXmlDoc, "//body/infos/bounds"_ostr, "right"_ostr).toInt32(); + sal_Int32 nShapeLeft + = getXPath(pXmlDoc, "//SwAnchoredDrawObject/bounds"_ostr, "left"_ostr).toInt32(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected greater than: 11083 + // - Actual : 722 + // i.e. the shape was on the left margin. + CPPUNIT_ASSERT_GREATER(nBodyRight, nShapeLeft); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/writerfilter/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx b/sw/qa/writerfilter/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx new file mode 100644 index 000000000000..7988384b2c90 Binary files /dev/null and b/sw/qa/writerfilter/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx differ diff --git a/sw/source/writerfilter/filter/WriterFilter.cxx b/sw/source/writerfilter/filter/WriterFilter.cxx index 413eb00c139c..742ae2bbeee2 100644 --- a/sw/source/writerfilter/filter/WriterFilter.cxx +++ b/sw/source/writerfilter/filter/WriterFilter.cxx @@ -332,6 +332,7 @@ void WriterFilter::setTargetDocument(const uno::Reference<lang::XComponent>& xDo xSettings->setPropertyValue("DropCapPunctuation", uno::Any(true)); // rely on default for HyphenateURLs=false // rely on default for APPLY_TEXT_ATTR_TO_EMPTY_LINE_AT_END_OF_PARAGRAPH=true + xSettings->setPropertyValue("DoNotMirrorRtlDrawObjs", uno::Any(true)); } void WriterFilter::setSourceDocument(const uno::Reference<lang::XComponent>& xDoc)