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@cib.de>
This commit is contained in:
@@ -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: */
|
||||
|
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -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,
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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");
|
||||
}
|
||||
|
Reference in New Issue
Block a user