From 713493c107e6a210ef9b87d033efd0614271483a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 23 Jan 2023 20:10:30 +0100 Subject: [PATCH] tdf#150806 ODT export: fix fallback svg:width/height for zero layout size The reported problem was that once tracked changes is enabled and an image is deleted, its aspect ratio changes on save. What happens here is that the image's frame is marked as a redline deletion, so when the ODT export writes the file, it'll have a zero size. But this zero size is nothing we should take into account on save, XMLTextParagraphExport::addTextFrameAttributes() expected to always have a valid layout size if the LayoutSize property is available. Fix the problem by adding one more condition where we ignore the layout size, which was already there since commit 80550ade305b9e68c6281a258d162bc2c413713a (tdf#150990 ODT export: fix zero layout size of scale/scale images, 2022-09-20). Note that this way the written side will be the original one, so only the aspect ratio will be correct, but that was accepted as a compromise earlier. Change-Id: I108dc2428ce0cb07a044bfef216575fdba19267b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146043 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- xmloff/qa/unit/data/scale-width-redline.fodt | 170 +++++++++++++++++++ xmloff/qa/unit/text.cxx | 21 +++ xmloff/source/text/txtparae.cxx | 5 + 3 files changed, 196 insertions(+) create mode 100644 xmloff/qa/unit/data/scale-width-redline.fodt diff --git a/xmloff/qa/unit/data/scale-width-redline.fodt b/xmloff/qa/unit/data/scale-width-redline.fodt new file mode 100644 index 000000000000..6b98c6e27a34 --- /dev/null +++ b/xmloff/qa/unit/data/scale-width-redline.fodt @@ -0,0 +1,170 @@ + + + LibreOfficeDev/7.6.0.0.alpha0$Linux_X86_64 LibreOffice_project/2e076661cf81225e390a3f5c86171eebb74ebbedGetting Started with LibreOffice 4.22010-01-04T08:31:18369P2DT11H48M52SJean Hollis Weber2023-01-23T16:28:26.015905461 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + before image + + + + iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAAEElEQVR4nGJgAQAAAP//AwAA + BgAFV7+r1AAAAABJRU5ErkJggg== + + + + Figure 1: caption + + + after image + + + diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index 1710f47fb25c..f7155f546df3 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -886,6 +886,27 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testDropdownContentControlAutostyleExport) xStorable->storeToURL(maTempFile.GetURL(), aStoreProps); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testScaleWidthRedline) +{ + // Given a document with change tracking enabled, one image is part of a delete redline: + loadFromURL(u"scale-width-redline.fodt"); + dispatchCommand(mxComponent, ".uno:TrackChanges", {}); + dispatchCommand(mxComponent, ".uno:GoToEndOfLine", {}); + dispatchCommand(mxComponent, ".uno:EndOfParaSel", {}); + dispatchCommand(mxComponent, ".uno:Delete", {}); + + // When saving to ODT: + save("writer8"); + + // Then make sure that a non-zero size is written to the output: + xmlDocUniquePtr pXmlDoc = parseExport("content.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 6.1728in + // - Actual : 0in + // i.e. the deleted image had zero size, which is incorrect. + assertXPath(pXmlDoc, "//draw:frame[@draw:name='Image45']", "width", "6.1728in"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index f0f6360b4904..59e755f0e676 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -2873,6 +2873,11 @@ XMLShapeExportFlags XMLTextParagraphExport::addTextFrameAttributes( // invalid layout size we got. bUseLayoutSize = false; } + if (aLayoutSize.Width <= 0 || aLayoutSize.Height <= 0) + { + // This is broken, Writer frames have a minimal size, see MINFLY. + bUseLayoutSize = false; + } // svg:width sal_Int16 nWidthType = SizeType::FIX;