summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2022-10-15 01:25:49 +0200
committerRegina Henschel <rb.henschel@t-online.de>2022-10-18 16:22:58 +0200
commit2969900b75e288e8c626a34277250aa233dc944c (patch)
tree7a559df7a95c9caf32c799c1b4209c7f956fa90e /oox
parent179c9cbcb036717d7a5463591ffde7ff42146086 (diff)
tdf#151518 Do not tweak text area distances in Writer
The fix for tdf#148321 has introduced tweaks to the upper and lower text distances for the case, that their sum is larger than the text area height. That works well in import from PowerPoint but conflicts with import of SmartArt shapes from Word. Reason of the problem is not only the missing Twip to Hmm conversion in TextBodyProperties::readjustTextDistances(). But I have not found which detail in the tweak produces the wrong text location. For now I have disabled the tweak for import from Word. Maybe someone finds a better solution in future. Because the user cannot insert such large distances in Word and SmartArt shapes do not use such distances anyway, I think it does not harm to disable the method for text documents. Import from Excel cannot be tested because of tdf#83671. Change-Id: I2e133f6864bba4419ad96e94d88aec86fe97d0fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141414 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Jenkins
Diffstat (limited to 'oox')
-rw-r--r--oox/qa/unit/data/tdf151518_SmartArtTextLocation.docxbin0 -> 66839 bytes
-rw-r--r--oox/qa/unit/shape.cxx54
-rw-r--r--oox/source/drawingml/shape.cxx11
3 files changed, 63 insertions, 2 deletions
diff --git a/oox/qa/unit/data/tdf151518_SmartArtTextLocation.docx b/oox/qa/unit/data/tdf151518_SmartArtTextLocation.docx
new file mode 100644
index 000000000000..ec99be6bff09
--- /dev/null
+++ b/oox/qa/unit/data/tdf151518_SmartArtTextLocation.docx
Binary files differ
diff --git a/oox/qa/unit/shape.cxx b/oox/qa/unit/shape.cxx
index c741ff84d4da..ec3fa9453b2c 100644
--- a/oox/qa/unit/shape.cxx
+++ b/oox/qa/unit/shape.cxx
@@ -20,6 +20,8 @@
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
+
+#include <officecfg/Office/Common.hxx>
#include <rtl/math.hxx>
#include <svx/svdoashp.hxx>
@@ -233,6 +235,58 @@ CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf151008VertAnchor)
}
}
+CPPUNIT_TEST_FIXTURE(OoxShapeTest, testTdf151518VertAnchor)
+{
+ // Make sure SmartArt is loaded as group shape
+ bool bUseGroup = officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::get();
+ if (!bUseGroup)
+ {
+ std::shared_ptr<comphelper::ConfigurationChanges> pChange(
+ comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(true, pChange);
+ pChange->commit();
+ }
+
+ // The document contains SmartArt with shapes with not default text area. Without fix the
+ // text was shifted up because of wrong values in TextLowerDistance and TextUpperDistance.
+ load(u"tdf151518_SmartArtTextLocation.docx");
+
+ struct TextDistance
+ {
+ OUString sShapeName;
+ sal_Int16 nSubShapeIndex;
+ sal_Int32 nLowerDistance;
+ sal_Int32 nUpperDistance;
+ };
+ TextDistance aExpected[4] = { { u"Diagram Target List", 2, 2979, 201 },
+ { u"Diagram Nested Target", 1, 3203, 127 },
+ { u"Diagram Stacked Venn", 1, 3112, -302 },
+ { u"Diagram Grouped List", 1, 4106, 196 } };
+ // without the fix the observed distances were
+ // {4434, -464}, {4674, -751}, {4620, -1399}, {6152, -744}
+ for (size_t i = 0; i < 4; ++i)
+ {
+ uno::Reference<drawing::XShapes> xDiagramShape(getShapeByName(aExpected[i].sShapeName),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShapeProps(
+ xDiagramShape->getByIndex(aExpected[i].nSubShapeIndex), uno::UNO_QUERY);
+ sal_Int32 nLower;
+ sal_Int32 nUpper;
+ CPPUNIT_ASSERT(xShapeProps->getPropertyValue("TextLowerDistance") >>= nLower);
+ CPPUNIT_ASSERT(xShapeProps->getPropertyValue("TextUpperDistance") >>= nUpper);
+ CPPUNIT_ASSERT_EQUAL(aExpected[i].nLowerDistance, nLower);
+ CPPUNIT_ASSERT_EQUAL(aExpected[i].nUpperDistance, nUpper);
+ }
+
+ if (!bUseGroup)
+ {
+ std::shared_ptr<comphelper::ConfigurationChanges> pChange(
+ comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes::set(false, pChange);
+ pChange->commit();
+ }
+}
+
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 e1a81c99631c..e43b6b9ed5b0 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -99,6 +99,7 @@
#include <tools/stream.hxx>
#include <unotools/streamwrap.hxx>
#include <unotools/fltrcfg.hxx>
+#include <unotools/mediadescriptor.hxx>
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/svapp.hxx>
@@ -1892,9 +1893,15 @@ Reference< XShape > const & Shape::createAndInsert(
finalizeXShape( rFilterBase, rxShapes );
if (mpTextBody)
- mpTextBody->getTextProperties().readjustTextDistances(mxShape);
+ {
+ // tdf#151518. The method readjustTextDistances is fix for tdf#148321, but conflicts with
+ // text position in some of the SmartArt types in Writer. So exclude Writer here.
+ OUString sDocumentService;
+ rFilterBase.getMediaDescriptor()[utl::MediaDescriptor::PROP_DOCUMENTSERVICE] >>= sDocumentService;
+ if (sDocumentService != u"com.sun.star.text.TextDocument")
+ mpTextBody->getTextProperties().readjustTextDistances(mxShape);
+ }
}
-
return mxShape;
}