From a3103ef8a3ef9ca2d0603781d7a13ca906667076 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 18 Sep 2020 17:53:33 +0200 Subject: tdf#129685 PPTX import: fix unexpected centering of shape text Regression from commit 89f0af144c18efafe2573801641689a1432c0cae (tdf#113198 set default shape paragraph alignment.., 2019-11-19), the old bugdoc had this markup: (centered) The new bugdoc has 2 shapes with text: (aligned to left) (should be centered) "anchor" is about vertical, "anchorCtr" is about horizontal centering of text. Checking what the binary filter does, it maps horizontal centering to TextHorizontalAdjust, so fix the original bug differently, by leaving ParaAdjust alone, and tweaking TextHorizontalAdjust intead: this keeps the old bugdoc working but fixes the new one. This caused a number of "change detector" XML-based tests to fail: all of them are unchanged visually, so the XML files are adapted to the new state. The tdf#113198 fix itself was fixing a regression from tdf#104722, and that commit had no testcase, I tested that we don't regress there, manually. (cherry picked from commit 10bb02efd8afd42e633e370480104e2575546d8e) Change-Id: I81a7b3e8c76bfbce5c5569d16d5238958ac20f75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103136 Tested-by: Jenkins CollaboraOffice Reviewed-by: Miklos Vajna --- oox/qa/unit/data/shape-text-alignment.pptx | Bin 0 -> 30844 bytes oox/qa/unit/drawingml.cxx | 20 ++++++++++++++++++++ oox/source/drawingml/shape.cxx | 3 ++- oox/source/drawingml/textbodypropertiescontext.cxx | 5 +++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 oox/qa/unit/data/shape-text-alignment.pptx (limited to 'oox') diff --git a/oox/qa/unit/data/shape-text-alignment.pptx b/oox/qa/unit/data/shape-text-alignment.pptx new file mode 100644 index 000000000000..ff4ff06f2fdf Binary files /dev/null and b/oox/qa/unit/data/shape-text-alignment.pptx differ diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx index 6b53c1770304..cdc77c67a251 100644 --- a/oox/qa/unit/drawingml.cxx +++ b/oox/qa/unit/drawingml.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -235,6 +236,25 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testGradientMultiStepTransparency) CPPUNIT_ASSERT_EQUAL(static_cast(0xffffff), aTransparence.EndColor); } +CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAlignment) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-alignment.pptx"; + load(aURL); + + uno::Reference xDrawPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + sal_Int16 nParaAdjust = -1; + CPPUNIT_ASSERT(xShape->getPropertyValue("ParaAdjust") >>= nParaAdjust); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 3 + // i.e. text which is meant to be left-aligned was centered at a paragraph level. + CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_LEFT, + static_cast(nParaAdjust)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 84e59293b335..924b489d2641 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -215,7 +215,8 @@ void Shape::setDefaults(bool bHeight) if (bHeight) maDefaultShapeProperties.setProperty(PROP_CharHeight, static_cast< float >( 18.0 )); maDefaultShapeProperties.setProperty(PROP_TextVerticalAdjust, TextVerticalAdjust_TOP); - maDefaultShapeProperties.setProperty(PROP_ParaAdjust, static_cast< sal_Int16 >( ParagraphAdjust_CENTER )); + maDefaultShapeProperties.setProperty(PROP_ParaAdjust, + static_cast(ParagraphAdjust_LEFT)); } ::oox::vml::OleObjectInfo& Shape::setOleObjectType() diff --git a/oox/source/drawingml/textbodypropertiescontext.cxx b/oox/source/drawingml/textbodypropertiescontext.cxx index d696b4c3ac70..af02c6f981d8 100644 --- a/oox/source/drawingml/textbodypropertiescontext.cxx +++ b/oox/source/drawingml/textbodypropertiescontext.cxx @@ -123,6 +123,11 @@ TextBodyPropertiesContext::TextBodyPropertiesContext( ContextHandler2Helper cons { mrTextBodyProp.meVA = GetTextVerticalAdjust( rAttribs.getToken( XML_anchor, XML_t ) ); mrTextBodyProp.maPropertyMap.setProperty( PROP_TextVerticalAdjust, mrTextBodyProp.meVA); + if (mrTextBodyProp.meVA == drawing::TextVerticalAdjust_CENTER) + { + mrTextBodyProp.maPropertyMap.setProperty(PROP_TextHorizontalAdjust, + TextHorizontalAdjust_CENTER); + } } // Push defaults -- cgit