summaryrefslogtreecommitdiff
path: root/xmloff/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-03-16 15:35:50 +0100
committerMiklos Vajna <vmiklos@collabora.com>2022-03-16 16:44:24 +0100
commitb578fa08a25a83abccad2386e12b707586fffb26 (patch)
treeacb70ecfc039f18b5b1ccca7bd39dc0264a3c7e6 /xmloff/qa
parent3eecde27009b74a7f3bf75809109a2367e262b09 (diff)
ODT export: fix fallback svg:width/height for text frames with relative sizes
In case <draw:frame> has style:rel-width="..." and style:rel-height="...", then the ODF spec says that: > To support consumers that do not support relative width, producers > should also provide the width in a svg:width 19.575 attribute. If the motivation is to support simple consumers, then it's better if we write the up to date layout size as the fallback value, not what was the layout size at insert time. (But don't ignore this at import time: 80% width and "scale" for height is a valid combination, and then height/width is needed to know the ratio.) Change-Id: Iefeb43cdb141b01a732086c37186201a3fef0952 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131662 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'xmloff/qa')
-rw-r--r--xmloff/qa/unit/text.cxx43
1 files changed, 43 insertions, 0 deletions
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index c24e6855f543..3b067120eb7b 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -340,6 +340,49 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testClearingBreakImport)
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(3), eClear);
}
+CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testRelativeWidth)
+{
+ // Given a document with an 50% wide text frame:
+ getComponent() = loadFromDesktop("private:factory/swriter");
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(getComponent(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies
+ = xStyleFamiliesSupplier->getStyleFamilies();
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
+ // Body frame width is 6cm (2+2cm margin).
+ xStyle->setPropertyValue("Width", uno::makeAny(static_cast<sal_Int32>(10000)));
+ uno::Reference<lang::XMultiServiceFactory> xMSF(getComponent(), uno::UNO_QUERY);
+ uno::Reference<text::XTextDocument> xTextDocument(getComponent(), uno::UNO_QUERY);
+ uno::Reference<text::XTextContent> xTextFrame(
+ xMSF->createInstance("com.sun.star.text.TextFrame"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xTextFrameProps(xTextFrame, uno::UNO_QUERY);
+ xTextFrameProps->setPropertyValue("RelativeWidth", uno::makeAny(static_cast<sal_Int16>(50)));
+ uno::Reference<text::XText> xText = xTextDocument->getText();
+ uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+ xText->insertTextContent(xCursor, xTextFrame, /*bAbsorb=*/false);
+ // Body frame width is 16cm.
+ xStyle->setPropertyValue("Width", uno::makeAny(static_cast<sal_Int32>(20000)));
+
+ uno::Reference<frame::XStorable> xStorable(getComponent(), uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProps = comphelper::InitPropertySequence({
+ { "FilterName", uno::makeAny(OUString("writer8")) },
+ });
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ xStorable->storeToURL(aTempFile.GetURL(), aStoreProps);
+
+ std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, "content.xml");
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get());
+ // Without the accompanying fix in place, this failed with:
+ // - Expected: 3.1492in (8cm)
+ // - Actual : 0.0161in (0.04 cm)
+ // i.e. the fallback width value wasn't the expected half of the body frame width, but a smaller
+ // value.
+ assertXPath(pXmlDoc, "//draw:frame", "width", "3.1492in");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */