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-07 12:39:09 +0200
commiteaf51dc759c541c6e8bd786b5f394a87c110b177 (patch)
treeecf7ee5f15cae981af744679e3f3a57f9c6ab531 /oox
parent273ec24d802a896d13043c6235afcb6084341cf6 (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. (cherry picked from commit dfa1856cdb4c69985ef1e809d33055427b6fbd76) Change-Id: Id785252c26fc407cd74c9cfb55624091798d7773 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104050 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> 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 cdc77c67a251..dea8461d543f 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -27,6 +27,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 <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/processfactory.hxx>
@@ -255,6 +256,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 924b489d2641..2ccc1e20917f 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -1473,6 +1473,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 af02c6f981d8..d696b4c3ac70 100644
--- a/oox/source/drawingml/textbodypropertiescontext.cxx
+++ b/oox/source/drawingml/textbodypropertiescontext.cxx
@@ -123,11 +123,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