writerfilter/CppunitTest_writerfilter_filter.mk | 55 +++++++++ writerfilter/Module_writerfilter.mk | 1 writerfilter/qa/cppunittests/filter/WriterFilter.cxx | 57 ++++++++++ writerfilter/qa/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx |binary writerfilter/source/filter/WriterFilter.cxx | 1 5 files changed, 114 insertions(+)
New commits: commit ffcd1d52574e19ce45b47758d3ed445d2a9da943 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu May 2 08:42:25 2024 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Fri May 3 15:17:14 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). (cherry picked from commit 01dcc9a652ecfc65fb674b492afa6f58b0a846db) Conflicts: sw/Module_sw.mk Change-Id: I38dfae370f275d9f0897198e7b0569f2d91dd352 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167033 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/writerfilter/CppunitTest_writerfilter_filter.mk b/writerfilter/CppunitTest_writerfilter_filter.mk new file mode 100644 index 000000000000..8b719bba5713 --- /dev/null +++ b/writerfilter/CppunitTest_writerfilter_filter.mk @@ -0,0 +1,55 @@ +# -*- 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,writerfilter_filter)) + +$(eval $(call gb_CppunitTest_use_externals,writerfilter_filter,\ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_filter, \ + writerfilter/qa/cppunittests/filter/WriterFilter \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,writerfilter_filter, \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + oox \ + sal \ + subsequenttest \ + test \ + unotest \ + utl \ + tl \ + vcl \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,writerfilter_filter)) + +$(eval $(call gb_CppunitTest_use_ure,writerfilter_filter)) +$(eval $(call gb_CppunitTest_use_vcl,writerfilter_filter)) + +$(eval $(call gb_CppunitTest_use_rdb,writerfilter_filter,services)) + +$(eval $(call gb_CppunitTest_use_custom_headers,writerfilter_filter,\ + officecfg/registry \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,writerfilter_filter)) + +# we need to explicitly depend on library writerfilter because it is not implied +# by a link relation +$(call gb_CppunitTest_get_target,writerfilter_filter) : $(call gb_Library_get_target,writerfilter) + +# vim: set noet sw=4 ts=4: diff --git a/writerfilter/Module_writerfilter.mk b/writerfilter/Module_writerfilter.mk index 587bf4fa4dfc..08710edb23e6 100644 --- a/writerfilter/Module_writerfilter.mk +++ b/writerfilter/Module_writerfilter.mk @@ -20,6 +20,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,writerfilter,\ CppunitTest_writerfilter_dmapper \ CppunitTest_writerfilter_ooxml \ CppunitTest_writerfilter_rtftok \ + CppunitTest_writerfilter_filter \ )) # vim: set noet sw=4 ts=4: diff --git a/writerfilter/qa/cppunittests/filter/WriterFilter.cxx b/writerfilter/qa/cppunittests/filter/WriterFilter.cxx new file mode 100644 index 000000000000..ae741085277c --- /dev/null +++ b/writerfilter/qa/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 writerfilter/source/filter/WriterFilter.cxx. +class Test : public UnoApiXmlTest +{ +public: + Test() + : UnoApiXmlTest("/writerfilter/qa/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/writerfilter/qa/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx b/writerfilter/qa/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx new file mode 100644 index 000000000000..7988384b2c90 Binary files /dev/null and b/writerfilter/qa/cppunittests/filter/data/draw-obj-rtl-no-mirror.docx differ diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx index 8935f462636f..44efc0c42cfc 100644 --- a/writerfilter/source/filter/WriterFilter.cxx +++ b/writerfilter/source/filter/WriterFilter.cxx @@ -331,6 +331,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)