diff --git a/comphelper/source/misc/graphicmimetype.cxx b/comphelper/source/misc/graphicmimetype.cxx index 2f8ba2efbae4..0c0ca8057549 100644 --- a/comphelper/source/misc/graphicmimetype.cxx +++ b/comphelper/source/misc/graphicmimetype.cxx @@ -88,5 +88,38 @@ OUString GraphicMimeTypeHelper::GetMimeTypeForImageStream(Reference #include +#include #include #include @@ -26,6 +27,7 @@ public: static OUString GetMimeTypeForXGraphic(css::uno::Reference xGraphic); static OUString GetMimeTypeForImageStream(css::uno::Reference xInputStream); + static OUString GetMimeTypeForConvertDataFormat(ConvertDataFormat convertDataFormat); }; } diff --git a/include/svx/xoutbmp.hxx b/include/svx/xoutbmp.hxx index ba33ed989746..5a02045da52f 100644 --- a/include/svx/xoutbmp.hxx +++ b/include/svx/xoutbmp.hxx @@ -25,6 +25,8 @@ #include #include #include +#include + enum class XOutFlags { NONE = 0x00000000, @@ -62,7 +64,9 @@ public: const OUString& rFilterName, const XOutFlags nFlags, const Size* pMtfSize_100TH_MM = nullptr, const css::uno::Sequence< css::beans::PropertyValue >* pFilterData = nullptr); - static bool GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, bool bAddPrefix=true); + static bool GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, + bool bAddPrefix = true, + ConvertDataFormat aTargetFormat = ConvertDataFormat::Unknown); static ErrCode ExportGraphic( const Graphic& rGraphic, const INetURLObject& rURL, GraphicFilter& rFilter, const sal_uInt16 nFormat, diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index 05998009e14a..2d187c7609b6 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -346,33 +347,33 @@ ErrCode XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileName, } } -bool XOutBitmap::GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, bool bAddPrefix) +bool XOutBitmap::GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, bool bAddPrefix, + ConvertDataFormat aTargetFormat) { SvMemoryStream aOStm; - OUString aMimeType; GfxLink aLink = rGraphic.GetGfxLink(); - ConvertDataFormat aCvtType; - switch( aLink.GetType() ) + + if (aTargetFormat == ConvertDataFormat::Unknown) { - case GfxLinkType::NativeJpg: - aCvtType = ConvertDataFormat::JPG; - aMimeType = "image/jpeg"; - break; - case GfxLinkType::NativePng: - aCvtType = ConvertDataFormat::PNG; - aMimeType = "image/png"; - break; - case GfxLinkType::NativeSvg: - aCvtType = ConvertDataFormat::SVG; - aMimeType = "image/svg+xml"; - break; - default: - // save everything else (including gif) into png - aCvtType = ConvertDataFormat::PNG; - aMimeType = "image/png"; - break; + switch (aLink.GetType()) + { + case GfxLinkType::NativeJpg: + aTargetFormat = ConvertDataFormat::JPG; + break; + case GfxLinkType::NativePng: + aTargetFormat = ConvertDataFormat::PNG; + break; + case GfxLinkType::NativeSvg: + aTargetFormat = ConvertDataFormat::SVG; + break; + default: + // save everything else (including gif) into png + aTargetFormat = ConvertDataFormat::PNG; + break; + } } - ErrCode nErr = GraphicConverter::Export(aOStm,rGraphic,aCvtType); + + ErrCode nErr = GraphicConverter::Export(aOStm,rGraphic,aTargetFormat); if ( nErr ) { SAL_WARN("svx", "XOutBitmap::GraphicToBase64() invalid Graphic? error: " << nErr ); @@ -385,7 +386,11 @@ bool XOutBitmap::GraphicToBase64(const Graphic& rGraphic, OUString& rOUString, b rOUString = aStrBuffer.makeStringAndClear(); if (bAddPrefix) + { + OUString aMimeType + = comphelper::GraphicMimeTypeHelper::GetMimeTypeForConvertDataFormat(aTargetFormat); rOUString = aMimeType + ";base64," + rOUString; + } return true; } diff --git a/xmlsecurity/source/helper/ooxmlsecexporter.cxx b/xmlsecurity/source/helper/ooxmlsecexporter.cxx index abb0a648b520..9ca95c5d755e 100644 --- a/xmlsecurity/source/helper/ooxmlsecexporter.cxx +++ b/xmlsecurity/source/helper/ooxmlsecexporter.cxx @@ -18,13 +18,16 @@ #include #include #include +#include #include +#include #include #include #include using namespace com::sun::star; +using namespace css::xml::sax; struct OOXMLSecExporter::Impl { @@ -68,6 +71,7 @@ struct OOXMLSecExporter::Impl /// Writes . void writeSignatureInfo(); void writePackageSignature(); + void writeSignatureLineImages(); }; bool OOXMLSecExporter::Impl::isOOXMLBlacklist(const OUString& rStreamName) @@ -417,6 +421,36 @@ void OOXMLSecExporter::Impl::writePackageSignature() m_xDocumentHandler->endElement("Object"); } +void OOXMLSecExporter::Impl::writeSignatureLineImages() +{ + if (m_rInformation.aValidSignatureImage.is()) + { + rtl::Reference pAttributeList(new SvXMLAttributeList()); + pAttributeList->AddAttribute("Id", "idValidSigLnImg"); + m_xDocumentHandler->startElement( + "Object", uno::Reference(pAttributeList.get())); + OUString aGraphicInBase64; + Graphic aGraphic(m_rInformation.aValidSignatureImage); + if (!XOutBitmap::GraphicToBase64(aGraphic, aGraphicInBase64, false, ConvertDataFormat::EMF)) + SAL_WARN("xmlsecurity.helper", "could not convert graphic to base64"); + m_xDocumentHandler->characters(aGraphicInBase64); + m_xDocumentHandler->endElement("Object"); + } + if (m_rInformation.aInvalidSignatureImage.is()) + { + rtl::Reference pAttributeList(new SvXMLAttributeList()); + pAttributeList->AddAttribute("Id", "idInvalidSigLnImg"); + m_xDocumentHandler->startElement( + "Object", uno::Reference(pAttributeList.get())); + OUString aGraphicInBase64; + Graphic aGraphic(m_rInformation.aInvalidSignatureImage); + if (!XOutBitmap::GraphicToBase64(aGraphic, aGraphicInBase64, false, ConvertDataFormat::EMF)) + SAL_WARN("xmlsecurity.helper", "could not convert graphic to base64"); + m_xDocumentHandler->characters(aGraphicInBase64); + m_xDocumentHandler->endElement("Object"); + } +} + OOXMLSecExporter::OOXMLSecExporter(const uno::Reference& xComponentContext, const uno::Reference& xRootStorage, const uno::Reference& xDocumentHandler, @@ -440,6 +474,7 @@ void OOXMLSecExporter::writeSignature() m_pImpl->writePackageObject(); m_pImpl->writeOfficeObject(); m_pImpl->writePackageSignature(); + m_pImpl->writeSignatureLineImages(); m_pImpl->m_xDocumentHandler->endElement("Signature"); }