summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-11-30 01:17:14 +0500
committerMike Kaganski <mike.kaganski@collabora.com>2024-11-30 08:40:29 +0100
commit5a42e163cd5c6427fe46d19b43a57cb09b57cc14 (patch)
tree0579baf9fe450083be5feb9ba7f8234a5f469ebe /oox
parent44ccd392be12dad23e216fb3eb2c2e5b275eee75 (diff)
tdf#163483: implement export of Math formula's fallback image to PPTX
This was left as a TODO in commit cb890ae43bacd2be24bc74fad2e2e5cce8910995 (oox: export Math objects to PPTX files, 2016-01-15). Now after commit 7cfff4751befd678b3db4b6f16b020d38f4e9c32 (Related: tdf#129061 Avoid formula import and use fallback for now, 2024-09-11), that relied on the fallback being present, our exported documents lost the formulas completely on load. So the fallback export became a necessity. Change-Id: I52d4ef0400ce72ee10fda10a1131b4ba29ea56be Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177564 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'oox')
-rw-r--r--oox/source/export/shapes.cxx38
1 files changed, 34 insertions, 4 deletions
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index 38c76ef59952..0bb8d1ebeecc 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -77,6 +77,7 @@
#include <vcl/graph.hxx>
#include <vcl/outdev.hxx>
#include <filter/msfilter/escherex.hxx>
+#include <svtools/embedhlp.hxx>
#include <svx/svdoashp.hxx>
#include <svx/svdoole2.hxx>
#include <comphelper/diagnose_ex.hxx>
@@ -2657,6 +2658,8 @@ void ShapeExport::WriteMathShape(Reference<XShape> const& xShape)
assert(xMathModel.is());
assert(GetDocumentType() != DOCUMENT_DOCX); // should be written in DocxAttributeOutput
SAL_WARN_IF(GetDocumentType() == DOCUMENT_XLSX, "oox.shape", "Math export to XLSX isn't tested, should it happen here?");
+ const OString cNvPr_id = OString::number(GetNewShapeID(xShape));
+ const OUString shapeName = GetShapeName(xShape);
// ECMA standard does not actually allow oMath outside of
// WordProcessingML so write a MCE like PPT 2010 does
@@ -2666,9 +2669,7 @@ void ShapeExport::WriteMathShape(Reference<XShape> const& xShape)
XML_Requires, "a14");
mpFS->startElementNS(mnXmlNamespace, XML_sp);
mpFS->startElementNS(mnXmlNamespace, XML_nvSpPr);
- mpFS->startElementNS(mnXmlNamespace, XML_cNvPr,
- XML_id, OString::number(GetNewShapeID(xShape)),
- XML_name, GetShapeName(xShape));
+ mpFS->startElementNS(mnXmlNamespace, XML_cNvPr, XML_id, cNvPr_id, XML_name, shapeName);
AddExtLst(mpFS, xPropSet);
mpFS->endElementNS(mnXmlNamespace, XML_cNvPr);
mpFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr, XML_txBox, "1");
@@ -2696,7 +2697,36 @@ void ShapeExport::WriteMathShape(Reference<XShape> const& xShape)
mpFS->endElementNS(mnXmlNamespace, XML_sp);
mpFS->endElementNS(XML_mc, XML_Choice);
mpFS->startElementNS(XML_mc, XML_Fallback);
- // TODO: export bitmap shape as fallback
+
+ svt::EmbeddedObjectRef ref(
+ xPropSet->getPropertyValue(u"EmbeddedObject"_ustr).query<css::embed::XEmbeddedObject>(),
+ embed::Aspects::MSOLE_CONTENT);
+ if (auto* graphic = ref.GetGraphic(); graphic && graphic->GetType() != GraphicType::NONE)
+ {
+ if (OUString r_id = writeGraphicToStorage(*graphic); !r_id.isEmpty())
+ {
+ mpFS->startElementNS(mnXmlNamespace, XML_sp);
+ mpFS->startElementNS(mnXmlNamespace, XML_nvSpPr);
+ mpFS->startElementNS(mnXmlNamespace, XML_cNvPr, XML_id, cNvPr_id, XML_name, shapeName);
+ AddExtLst(mpFS, xPropSet);
+ mpFS->endElementNS(mnXmlNamespace, XML_cNvPr);
+ mpFS->singleElementNS(mnXmlNamespace, XML_cNvSpPr, XML_txBox, "1");
+ mpFS->singleElementNS(mnXmlNamespace, XML_nvPr);
+ mpFS->endElementNS(mnXmlNamespace, XML_nvSpPr);
+ mpFS->startElementNS(mnXmlNamespace, XML_spPr);
+ WriteShapeTransformation(xShape, XML_a);
+ WritePresetShape("rect"_ostr);
+ mpFS->startElementNS(XML_a, XML_blipFill);
+ mpFS->singleElementNS(XML_a, XML_blip, FSNS(XML_r, XML_embed), r_id);
+ mpFS->startElementNS(XML_a, XML_stretch);
+ mpFS->singleElementNS(XML_a, XML_fillRect);
+ mpFS->endElementNS(XML_a, XML_stretch);
+ mpFS->endElementNS(XML_a, XML_blipFill);
+ mpFS->endElementNS(mnXmlNamespace, XML_spPr);
+ mpFS->endElementNS(mnXmlNamespace, XML_sp);
+ }
+ }
+
mpFS->endElementNS(XML_mc, XML_Fallback);
mpFS->endElementNS(XML_mc, XML_AlternateContent);
}