[Libreoffice-commits] core.git: comphelper/source include/comphelper include/svx svx/source xmlsecurity/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Thu Jul 5 06:06:04 UTC 2018


 comphelper/source/misc/graphicmimetype.cxx     |   33 ++++++++++++++++
 include/comphelper/graphicmimetype.hxx         |    2 +
 include/svx/xoutbmp.hxx                        |    6 ++-
 svx/source/xoutdev/_xoutbmp.cxx                |   49 +++++++++++++------------
 xmlsecurity/source/helper/ooxmlsecexporter.cxx |   35 +++++++++++++++++
 5 files changed, 102 insertions(+), 23 deletions(-)

New commits:
commit 7bafb7ca8ef9467f5c55766d2a38ba0d0a60837c
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Tue Jul 3 15:16:58 2018 +0200

    tdf#117901 Write signature line images as emf to ooxml
    
    Change-Id: Idbf60be3cef2d9dde454da0279d2810488b1e157
    Reviewed-on: https://gerrit.libreoffice.org/56871
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

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<XInputStream
 
     return GetMimeTypeForXGraphic(xGraphic);
 }
+
+OUString GraphicMimeTypeHelper::GetMimeTypeForConvertDataFormat(ConvertDataFormat convertDataFormat)
+{
+    switch (convertDataFormat)
+    {
+        case ConvertDataFormat::BMP:
+            return OUString("image/bmp");
+        case ConvertDataFormat::GIF:
+            return OUString("image/gif");
+        case ConvertDataFormat::JPG:
+            return OUString("image/jpeg");
+        case ConvertDataFormat::PCT:
+            return OUString("image/x-pict");
+        case ConvertDataFormat::PNG:
+            return OUString("image/png");
+        case ConvertDataFormat::SVM:
+            return OUString("image/x-svm");
+        case ConvertDataFormat::TIF:
+            return OUString("image/tiff");
+        case ConvertDataFormat::WMF:
+            return OUString("image/x-wmf");
+        case ConvertDataFormat::EMF:
+            return OUString("image/x-emf");
+        case ConvertDataFormat::SVG:
+            return OUString("image/svg+xml");
+        case ConvertDataFormat::PDF:
+            return OUString("application/pdf");
+        case ConvertDataFormat::MET: // What is this?
+        case ConvertDataFormat::Unknown:
+        default:
+            return OUString("");
+    }
+}
 }
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/graphicmimetype.hxx b/include/comphelper/graphicmimetype.hxx
index ad081c46e2e5..6b8ed4293805 100644
--- a/include/comphelper/graphicmimetype.hxx
+++ b/include/comphelper/graphicmimetype.hxx
@@ -12,6 +12,7 @@
 
 #include <comphelper/comphelperdllapi.h>
 #include <rtl/ustring.hxx>
+#include <vcl/salctype.hxx>
 
 #include <com/sun/star/graphic/XGraphic.hpp>
 #include <com/sun/star/io/XInputStream.hpp>
@@ -26,6 +27,7 @@ public:
     static OUString GetMimeTypeForXGraphic(css::uno::Reference<css::graphic::XGraphic> xGraphic);
     static OUString
     GetMimeTypeForImageStream(css::uno::Reference<css::io::XInputStream> 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 <com/sun/star/beans/PropertyValue.hpp>
 #include <svx/svxdllapi.h>
 #include <o3tl/typed_flags_set.hxx>
+#include <vcl/salctype.hxx>
+
 
 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 <sal/config.h>
 
 #include <comphelper/base64.hxx>
+#include <comphelper/graphicmimetype.hxx>
 #include <tools/poly.hxx>
 #include <vcl/bitmapaccess.hxx>
 #include <vcl/virdev.hxx>
@@ -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 <comphelper/ofopxmlhelper.hxx>
 #include <o3tl/make_unique.hxx>
 #include <rtl/ref.hxx>
+#include <svx/xoutbmp.hxx>
 #include <unotools/datetime.hxx>
+#include <vcl/salctype.hxx>
 #include <xmloff/attrlist.hxx>
 
 #include <documentsignaturehelper.hxx>
 #include <xsecctl.hxx>
 
 using namespace com::sun::star;
+using namespace css::xml::sax;
 
 struct OOXMLSecExporter::Impl
 {
@@ -68,6 +71,7 @@ struct OOXMLSecExporter::Impl
     /// Writes <SignatureInfoV1>.
     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<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
+        pAttributeList->AddAttribute("Id", "idValidSigLnImg");
+        m_xDocumentHandler->startElement(
+            "Object", uno::Reference<xml::sax::XAttributeList>(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<SvXMLAttributeList> pAttributeList(new SvXMLAttributeList());
+        pAttributeList->AddAttribute("Id", "idInvalidSigLnImg");
+        m_xDocumentHandler->startElement(
+            "Object", uno::Reference<xml::sax::XAttributeList>(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<uno::XComponentContext>& xComponentContext,
                                    const uno::Reference<embed::XStorage>& xRootStorage,
                                    const uno::Reference<xml::sax::XDocumentHandler>& 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");
 }


More information about the Libreoffice-commits mailing list