summaryrefslogtreecommitdiff
path: root/oox/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-06-26 09:21:17 +0200
committerMiklos Vajna <vmiklos@collabora.com>2024-06-26 11:20:47 +0200
commit6c09c85ec384e88c89bff0817e7fe9889d7ed68e (patch)
tree4d3d27b37989919b872fbb6c0906d4952f570ff6 /oox/source
parentccb557636ea87a40d5fcc370b7434029c0153588 (diff)
tdf#161779 DOCX import, drawingML: fix handling of translation for lines
Open the bugdoc, it has a line with a non-zero horizontal offset from the anchor paragraph, it shows up as a horizontal line, while it should be vertical. Checking how the ODT import and the DOCX import works for lines, one obvious difference is that the ODT import at SdXMLLineShapeContext::startFastElement() only considers the size / scaling for the individual points, everything else goes to the transform matrix of the containing shape, set in SdXMLShapeContext::SetTransformation(). The drawingML import is way more complex, but it effectively tries to not set any transformation on the shape and just transorms the points of the line instead. Fix the problem by changing Shape::createAndInsert() to also not put any scaling to the transform matrix, to not transform the points of the line and finally to apply the transform matrix to lines as well. Do this only for toplevel Writer lines, that's enough to fix the bugdoc and group shapes / Calc shapes need more investigation, so leave those unchanged for now. Tests which were failing while working on this change: - CppunitTest_sc_shapetest's testTdf144242_Line_noSwapWH: do this for Writer shapes only, for now - CppunitTest_sw_ooxmlimport's lineRotation: this is already broken partially, now looks perfect - CppunitTest_sw_ooxmlimport's testTdf85232 / group shape: this points out that lines in group shapes are some additional complexity, so leave that case unchanged, for now - CppunitTest_sw_ooxmlexport3's testArrowPosition: manual testing shows this is still OK - CppunitTest_sw_writerfilter_dmapper's testTdf141540GroupLinePosSize: manual testing shows this is still OK Change-Id: I246430148e3b3c927e010f360fa317e8429c82d2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169533 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'oox/source')
-rw-r--r--oox/source/drawingml/shape.cxx34
1 files changed, 28 insertions, 6 deletions
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index e2fed9eee281..9727688b25fe 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -1035,11 +1035,19 @@ Reference< XShape > const & Shape::createAndInsert(
aTransformation.translate(0.5, 0.5);
}
+ bool bLineShape = aServiceName == "com.sun.star.drawing.LineShape";
+ bool bTopWriterLine = !pParentGroupShape && mbWps && bLineShape;
// Build object matrix from shape size and position; corresponds to MSO ext and off
// Only LineShape and ConnectorShape may have zero width or height.
if (aServiceName == "com.sun.star.drawing.LineShape"
|| aServiceName == "com.sun.star.drawing.ConnectorShape")
- aTransformation.scale(maSize.Width, maSize.Height);
+ {
+ // For toplevel Writer lines, size is included in the point coordinates.
+ if (!bTopWriterLine)
+ {
+ aTransformation.scale(maSize.Width, maSize.Height);
+ }
+ }
else
{
aTransformation.scale(maSize.Width ? maSize.Width : 1.0,
@@ -1147,7 +1155,10 @@ Reference< XShape > const & Shape::createAndInsert(
aParentTransformation = aTransformation;
constexpr double fEmuToMm100 = o3tl::convert(1.0, o3tl::Length::emu, o3tl::Length::mm100);
- aTransformation.scale(fEmuToMm100, fEmuToMm100);
+ if (!bTopWriterLine)
+ {
+ aTransformation.scale(fEmuToMm100, fEmuToMm100);
+ }
// OOXML flips shapes before rotating them, so the rotation needs to be inverted
if( bIsCustomShape && mbFlipH != mbFlipV )
@@ -1171,8 +1182,19 @@ Reference< XShape > const & Shape::createAndInsert(
{
::basegfx::B2DPolygon aPoly;
aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
- aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
- aPoly.transform( aTransformation );
+ if (bTopWriterLine)
+ {
+ // No transform of individual points, everything apart from size is part of the
+ // transform matrix.
+ sal_Int32 nMM100Width = o3tl::convert(maSize.Width, o3tl::Length::emu, o3tl::Length::mm100);
+ sal_Int32 nMM100Height = o3tl::convert(maSize.Height, o3tl::Length::emu, o3tl::Length::mm100);
+ aPoly.insert(1, ::basegfx::B2DPoint(nMM100Width, nMM100Height));
+ }
+ else
+ {
+ aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
+ aPoly.transform( aTransformation );
+ }
// now creating the corresponding PolyPolygon
sal_Int32 i, nNumPoints = aPoly.count();
@@ -1199,7 +1221,7 @@ Reference< XShape > const & Shape::createAndInsert(
maShapeProperties.setProperty(PROP_PolyPolygon, aPolyPolySequence);
}
- else if ( aServiceName == "com.sun.star.drawing.ConnectorShape" )
+ if ( aServiceName == "com.sun.star.drawing.ConnectorShape" )
{
::basegfx::B2DPolygon aPoly;
aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
@@ -1214,7 +1236,7 @@ Reference< XShape > const & Shape::createAndInsert(
maShapeProperties.setProperty(PROP_StartPosition, aAWTStartPosition);
maShapeProperties.setProperty(PROP_EndPosition, aAWTEndPosition);
}
- else
+ else if (!bLineShape || bTopWriterLine)
{
// now set transformation for this object
HomogenMatrix3 aMatrix;