Kaydet (Commit) 7d76bb25 authored tarafından Miklos Vajna's avatar Miklos Vajna

vcl: add graphic export-as-pdf filter

In case the metafile was imported from a PDF originally, then this
allows storing the PDF stream next to the graphic. This means that e.g.
in Writer choosing 'Save' from the context menu of the graphic can write
the original PDF stream, not the replacement metafile.

Change-Id: I4ab45d5af17fe46d7538df6d79d6b57ed163572a
Reviewed-on: https://gerrit.libreoffice.org/26628Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 47443d72
......@@ -839,6 +839,7 @@ $(eval $(call filter_Configuration_add_internal_filters,fcfg_langpack,fcfg_inter
pcd_Import_Base16 \
pct_Import \
pcx_Import \
pdf_Export \
pdf_Import \
pgm_Import \
png_Export \
......
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<node oor:name="pdf_Export" oor:op="replace" >
<prop oor:name="Type"><value>pdf_Portable_Document_Format</value></prop>
<prop oor:name="FormatName"><value>SVEPDF</value></prop>
<prop oor:name="RealFilterName"/>
<prop oor:name="UIComponent"><value>com.sun.star.svtools.SvFilterOptionsDialog</value></prop>
<prop oor:name="UIName">
<value xml:lang="en-US">PDF - Portable Document Format</value>
</prop>
<prop oor:name="Flags"><value>EXPORT</value></prop>
</node>
......@@ -42,11 +42,12 @@ enum class GfxLinkType
NativePct = 8, // Don't forget to update the following defines
NativeSvg = 9, // Don't forget to update the following defines
NativeMov = 10, // Don't forget to update the following defines
NativeBmp = 11 // Don't forget to update the following defines
NativeBmp = 11,
NativePdf = 12 // Don't forget to update the following defines
};
#define GFX_LINK_FIRST_NATIVE_ID GfxLinkType::NativeGif
#define GFX_LINK_LAST_NATIVE_ID GfxLinkType::NativeBmp
#define GFX_LINK_LAST_NATIVE_ID GfxLinkType::NativePdf
class Graphic;
......
......@@ -220,6 +220,9 @@ public:
const SvgDataPtr& getSvgData() const;
void setPdfData(const css::uno::Sequence<sal_Int8>& rPdfData);
const css::uno::Sequence<sal_Int8>& getPdfData() const;
static css::uno::Sequence<sal_Int8> getUnoTunnelId();
};
......
......@@ -82,6 +82,7 @@ namespace o3tl
#define EXP_EMF "SVEMF"
#define EXP_JPEG "SVEJPEG"
#define EXP_SVG "SVESVG"
#define EXP_PDF "SVEPDF"
#define EXP_PNG "SVEPNG"
#define BMP_SHORTNAME "BMP"
......
......@@ -87,6 +87,9 @@ void GraphicHelper::GetPreferredExtension( OUString& rExtension, const Graphic&
case GfxLinkType::NativeSvg:
aExtension = "svg";
break;
case GfxLinkType::NativePdf:
aExtension = "pdf";
break;
default:
break;
}
......
......@@ -39,6 +39,8 @@
#define FORMAT_JPG "jpg"
#define FORMAT_PNG "png"
using namespace com::sun::star;
GraphicFilter* XOutBitmap::pGrfFilter = nullptr;
Animation XOutBitmap::MirrorAnimation( const Animation& rAnimation, bool bHMirr, bool bVMirr )
......@@ -172,6 +174,24 @@ sal_uInt16 XOutBitmap::WriteGraphic( const Graphic& rGraphic, OUString& rFileNam
}
}
// Write PDF data in original form if possible.
if (rGraphic.getPdfData().hasElements() && rFilterName.equalsIgnoreAsciiCase("pdf"))
{
if (!(nFlags & XOutFlags::DontAddExtension))
aURL.setExtension(rFilterName);
rFileName = aURL.GetMainURL(INetURLObject::NO_DECODE);
SfxMedium aMedium(aURL.GetMainURL(INetURLObject::NO_DECODE), StreamMode::WRITE|StreamMode::SHARE_DENYNONE|StreamMode::TRUNC);
if (SvStream* pOutStream = aMedium.GetOutStream())
{
uno::Sequence<sal_Int8> aPdfData = rGraphic.getPdfData();
pOutStream->WriteBytes(aPdfData.getConstArray(), aPdfData.getLength());
aMedium.Commit();
if (!aMedium.GetError())
nErr = GRFILTER_OK;
}
}
if( GRFILTER_OK != nErr )
{
if( ( nFlags & XOutFlags::UseNativeIfPossible ) &&
......
......@@ -51,6 +51,7 @@ private:
bool mbSwapUnderway;
bool mbDummyContext;
SvgDataPtr maSvgData;
css::uno::Sequence<sal_Int8> maPdfData;
private:
......
......@@ -43,7 +43,7 @@ const char* FilterConfigCache::FilterConfigCacheEntry::InternalPixelFilterNameLi
const char* FilterConfigCache::FilterConfigCacheEntry::InternalVectorFilterNameList[] =
{
IMP_SVMETAFILE, IMP_WMF, IMP_EMF, IMP_SVSGF, IMP_SVSGV, IMP_SVG, IMP_PDF,
EXP_SVMETAFILE, EXP_WMF, EXP_EMF, EXP_SVG, nullptr
EXP_SVMETAFILE, EXP_WMF, EXP_EMF, EXP_SVG, EXP_PDF, nullptr
};
const char* FilterConfigCache::FilterConfigCacheEntry::ExternalPixelFilterNameList[] =
......
......@@ -1698,6 +1698,8 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat
{
if (!ImportPDF(rIStream, rGraphic))
nStatus = GRFILTER_FILTERERROR;
else
eLinkType = GfxLinkType::NativePdf;
}
else
nStatus = GRFILTER_FILTERERROR;
......
......@@ -101,6 +101,13 @@ VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
rGraphic = aMtf;
// Save the original PDF stream for later use.
rStream.Seek(STREAM_SEEK_TO_END);
uno::Sequence<sal_Int8> aPdfData(rStream.Tell());
rStream.Seek(STREAM_SEEK_TO_BEGIN);
rStream.ReadBytes(aPdfData.getArray(), aPdfData.getLength());
rGraphic.setPdfData(aPdfData);
return true;
}
......
......@@ -593,6 +593,17 @@ const SvgDataPtr& Graphic::getSvgData() const
return mpImpGraphic->getSvgData();
}
void Graphic::setPdfData(const uno::Sequence<sal_Int8>& rPdfData)
{
ImplTestRefCount();
mpImpGraphic->maPdfData = rPdfData;
}
const uno::Sequence<sal_Int8>& Graphic::getPdfData() const
{
return mpImpGraphic->maPdfData;
}
namespace {
struct Id: public rtl::Static<cppu::OImplementationId, Id> {};
......
......@@ -51,6 +51,8 @@
#define GRAPHIC_FORMAT_50 static_cast<sal_uInt32>(COMPAT_FORMAT( 'G', 'R', 'F', '5' ))
#define NATIVE_FORMAT_50 static_cast<sal_uInt32>(COMPAT_FORMAT( 'N', 'A', 'T', '5' ))
using namespace com::sun::star;
struct ImpSwapFile
{
INetURLObject aSwapURL;
......@@ -132,6 +134,7 @@ ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) :
mpAnimation = nullptr;
maSvgData = rImpGraphic.maSvgData;
maPdfData = rImpGraphic.maPdfData;
}
ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) :
......@@ -256,6 +259,7 @@ ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic )
mpGfxLink = nullptr;
maSvgData = rImpGraphic.maSvgData;
maPdfData = rImpGraphic.maPdfData;
}
return *this;
......@@ -304,6 +308,10 @@ bool ImpGraphic::operator==( const ImpGraphic& rImpGraphic ) const
}
}
}
else if (maPdfData.hasElements())
{
bRet = maPdfData == rImpGraphic.maPdfData;
}
else if( mpAnimation )
{
if( rImpGraphic.mpAnimation && ( *rImpGraphic.mpAnimation == *mpAnimation ) )
......@@ -349,6 +357,7 @@ void ImpGraphic::ImplClearGraphics( bool bCreateSwapInfo )
}
maSvgData.reset();
maPdfData = uno::Sequence<sal_Int8>();
}
void ImpGraphic::ImplClear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment