summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-10-05 21:06:01 +0200
committerMiklos Vajna <vmiklos@collabora.com>2020-10-06 09:20:57 +0200
commitdfa1856cdb4c69985ef1e809d33055427b6fbd76 (patch)
treeacbfada663fa4369b33512a7d3b62d33756b6bed /oox
parente2a2165f27d2e5f9b6ac2d349e8b588921667ba4 (diff)
tdf#137023 PPTX import: fix unexpected center alignment of shape text, 2nd try
Regression from commit 10bb02efd8afd42e633e370480104e2575546d8e (tdf#129685 PPTX import: fix unexpected centering of shape text, 2020-09-18), now the problem was that some text should be left aligned, but was centered. Fix the problem by reverting most of the above commit: XML changes, changes to SdImportTest::testTdf113198() (manual testing show that this change is not needed after all) and changes to the TextBodyPropertiesContext ctor in oox/ (but not the testcase itself). Fix tdf#113198 again, this time in Shape::createAndInsert(), which is meant to be closer to what the binary PPT import does. With this, all cases from tdf#104722, tdf#113198, tdf#129685 and tdf#137023 are meant to be handled correctly at the same time. Change-Id: Id785252c26fc407cd74c9cfb55624091798d7773 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103996 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/qa/unit/data/shape-text-adjust-left.pptxbin0 -> 59199 bytes
-rw-r--r--oox/qa/unit/drawingml.cxx19
-rw-r--r--oox/source/drawingml/shape.cxx16
-rw-r--r--oox/source/drawingml/textbodypropertiescontext.cxx5
4 files changed, 35 insertions, 5 deletions
diff --git a/oox/qa/unit/data/shape-text-adjust-left.pptx b/oox/qa/unit/data/shape-text-adjust-left.pptx
new file mode 100644
index 000000000000..d197425b9703
--- /dev/null
+++ b/oox/qa/unit/data/shape-text-adjust-left.pptx
Binary files differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index 43609435c468..7fcee1756a6f 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
#include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
+#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
#include <unotools/mediadescriptor.hxx>
#include <unotools/tempfile.hxx>
@@ -246,6 +247,24 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAlignment)
static_cast<style::ParagraphAdjust>(nParaAdjust));
}
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testShapeTextAdjustLeft)
+{
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "shape-text-adjust-left.pptx";
+ load(aURL);
+
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(getComponent(), uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPagesSupplier->getDrawPages()->getByIndex(0),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+ drawing::TextHorizontalAdjust eAdjust;
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 3 (center)
+ // - Actual : 1 (block)
+ // i.e. text was center-adjusted, not default-adjusted (~left).
+ CPPUNIT_ASSERT(xShape->getPropertyValue("TextHorizontalAdjust") >>= eAdjust);
+ CPPUNIT_ASSERT_EQUAL(drawing::TextHorizontalAdjust_BLOCK, eAdjust);
+}
+
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 5af4d51cbfd4..f8f65d09f59f 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -1494,6 +1494,22 @@ Reference< XShape > const & Shape::createAndInsert(
xText->setString("");
Reference < XTextCursor > xAt = xText->createTextCursor();
getTextBody()->insertAt( rFilterBase, xText, xAt, aCharStyleProperties, mpMasterTextListStyle );
+
+ const TextParagraphVector& rParagraphs = getTextBody()->getParagraphs();
+ if (!rParagraphs.empty())
+ {
+ const std::shared_ptr<TextParagraph>& pParagraph = rParagraphs[0];
+ if (pParagraph->getProperties().getParaAdjust())
+ {
+ style::ParagraphAdjust eAdjust = *pParagraph->getProperties().getParaAdjust();
+ if (eAdjust == style::ParagraphAdjust_CENTER)
+ {
+ // If the first paragraph is centered, then set the para adjustment of
+ // the shape itself to centered as well.
+ aPropertySet.setAnyProperty(PROP_ParaAdjust, uno::makeAny(eAdjust));
+ }
+ }
+ }
}
}
else if (mbTextBox)
diff --git a/oox/source/drawingml/textbodypropertiescontext.cxx b/oox/source/drawingml/textbodypropertiescontext.cxx
index 6a6d9e90ef63..c84cf53f0b00 100644
--- a/oox/source/drawingml/textbodypropertiescontext.cxx
+++ b/oox/source/drawingml/textbodypropertiescontext.cxx
@@ -119,11 +119,6 @@ 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